[ai] Don't add BOM to UTF-8 files.

This commit is contained in:
John Preston
2026-03-31 23:16:09 +07:00
parent 96f23bf006
commit fe199447d5
3 changed files with 18 additions and 8 deletions
+6 -3
View File
@@ -470,14 +470,14 @@ After all changes are made:
When finished, report what changes were made and which files you touched.
```
## Phase 7: Windows Line Ending Normalization
## Phase 7: Windows Text Normalization
Run this phase only on Windows hosts and only after the review loop has finished.
Use the current task's result logs as the source of truth for what Codex touched. Do not sweep the whole repo and do not rewrite unrelated files from a dirty worktree.
```text
You are performing the final Windows-only line ending normalization phase for task-think.
You are performing the final Windows-only text normalization phase for task-think.
Read these files:
- .ai/<PROJECT>/<LETTER>/plan.md
@@ -490,12 +490,14 @@ Your job:
- Keep only files inside the repository that currently exist and are textual project files: source, headers, build/config files, localization files, style files, and similar text assets.
- Exclude `.ai/`, `out/`, binary files, and unrelated user files that were not touched by Codex in this task.
- Rewrite each kept file so all line endings are CRLF.
- If a kept file is UTF-8 or ASCII text, write it back as UTF-8 without BOM. Never add a UTF-8 BOM to source/config/project text files.
- Preserve file content otherwise. Preserve whether the file ended with a trailing newline.
Rules:
- Run this phase in the main session on Windows.
- Do not modify files outside the touched-file set for the current task.
- Do not rewrite binary files.
- When scripting this phase, do not use writer APIs or defaults that emit UTF-8 with BOM.
- If a file cannot be normalized safely, record it as a failure instead of silently skipping it.
When finished:
@@ -504,6 +506,7 @@ When finished:
- whether the phase completed
- which files were normalized
- which files were skipped and why
- whether any UTF-8 BOMs were removed or verified absent
- any failures that need to be mentioned in the final summary
```
@@ -514,7 +517,7 @@ When all phases, including build verification, code review, and Windows line end
2. Show which files were modified or created.
3. Note any issues encountered during implementation.
4. Summarize the code review iterations: how many rounds, what was found and fixed, or whether it was approved on the first pass.
5. On Windows, mention the line-ending normalization result briefly: which project files were normalized or whether nothing needed changes.
5. On Windows, mention the text-normalization result briefly: which project files were normalized, whether any BOMs were removed, or whether nothing needed changes.
6. Calculate and display the total elapsed time since `$START_TIME` (format as `Xh Ym Zs`, omitting zero components).
7. Remind the user of the project name so they can request follow-up tasks within the same project.
+5 -4
View File
@@ -73,7 +73,7 @@ Run these phases sequentially:
5. Phase 4: Implementation - Execute one implementation unit per plan phase.
6. Phase 5: Build Verification - Build the project, fix any build errors. Skip if no source code was modified.
7. Phase 6: Code Review Loop - Run review and fix iterations until approved or the iteration limit is reached.
8. Phase 7: Windows Line Ending Normalization - On Windows only, after review passes and before the final summary, normalize LF to CRLF for the text source/config files Codex edited in this task.
8. Phase 7: Windows Text Normalization - On Windows only, after review passes and before the final summary, normalize LF to CRLF for the text source/config files Codex edited in this task and ensure rewritten UTF-8 project files are saved without BOM.
Use the phase prompt templates in `PROMPTS.md`.
@@ -83,6 +83,7 @@ Use Codex subagents as the primary orchestration mechanism.
- When delegation is available, Phase 1, Phase 2, Phase 3, each Phase 4 implementation unit, and each Phase 6 review or review-fix pass must run in fresh subagents. Do not rerun those phases in the main session midstream just because a wait timed out or an artifact is missing.
- Run Phase 7 in the main session on Windows because it depends on the final local file state and the exact touched-file set for the current task.
- When any same-session helper rewrites Windows project text files, preserve CRLF and write UTF-8 without BOM. Avoid writer APIs or defaults that silently inject a UTF-8 BOM.
- The main session may read `context.md` once after Phase 1 and `plan.md` once after Phase 3. After that, prefer narrow shell checks, file existence checks, and status-line reads instead of rereading full documents or diffs.
- Prefer `worker` for phases that write files. Use `explorer` only for narrow read-only questions that unblock your next local step.
- Keep `fork_context` off by default. Pass the phase prompt and explicit file paths instead of the whole thread unless the phase truly needs prior conversational context or thread-only attachments.
@@ -111,7 +112,7 @@ Use Codex subagents as the primary orchestration mechanism.
- implemented code changes present
- build attempt results recorded
- review pass documented with any follow-up fixes
- on Windows, if the task edited project source/config text files, a line-ending normalization pass recorded after review
- on Windows, if the task edited project source/config text files, a CRLF / no-BOM normalization pass recorded after review
## Completion Criteria
@@ -119,7 +120,7 @@ Mark complete only when:
- All plan phases are done
- Build verification is recorded
- Review issues are addressed or explicitly deferred with rationale
- On Windows, Codex-edited project source/config text files have been normalized to CRLF and the result is logged
- On Windows, Codex-edited project source/config text files have been normalized to CRLF, any UTF-8 rewrites were saved without BOM, and the result is logged
- Display total elapsed time since start (format: `Xh Ym Zs`, omitting zero components)
- Remind the user of the project name so they can request follow-up tasks within the same project
@@ -129,7 +130,7 @@ Mark complete only when:
- If `context.md` or `plan.md` is not written properly by a phase, rerun that phase in a fresh subagent with more specific instructions. Do not repair it locally before build unless delegation was unavailable from the start.
- If build errors persist after the build phase's attempts, report the remaining errors to the user.
- If a review-fix phase introduces new build errors that it cannot resolve, report to the user.
- If Phase 7 cannot safely normalize a touched file on Windows, record the failure in the result log and report it in the final summary instead of silently skipping it.
- If Phase 7 cannot safely normalize a touched file on Windows or remove an introduced UTF-8 BOM from a touched project text file, record the failure in the result log and report it in the final summary instead of silently skipping it.
## User Invocation
+7 -1
View File
@@ -1,4 +1,4 @@
# Agent Guide for Telegram Desktop
# Agent Guide for Telegram Desktop
This guide defines repository-wide instructions for coding agents working with the Telegram Desktop codebase.
@@ -96,6 +96,12 @@ Retrying builds wastes time and context. The ONLY fix is for the user to close t
1. **Always use Debug builds** - Release builds are extremely heavy
2. **Don't build Release configuration** - it's too heavy for testing
## Text File Format
- On Windows, keep project text files with CRLF line endings.
- Do not save source, header, build/config, style, or localization files as UTF-8 with BOM. Use UTF-8 without BOM.
- When rewriting project text files for normalization, preserve file content otherwise and do not introduce a BOM.
## Local Storage Serialization
Both app-level (`Core::Settings`) and session-level (`Main::SessionSettings`) use sequential binary serialization via `QDataStream`. Key rules: