Repository navigation
fix(agents): render codex TOML with multi-line literal strings - #754
Merged
jeff-r2026 merged 3 commits intoSep 23, 2026
Merged
Conversation
`renderTomlAgent()` handed the whole spec to smol-toml's `stringify` with no options, and that always emits basic strings — so every newline in a prompt became a literal `\n` escape and a 16-line prompt collapsed into one ~700-character line. `git diff` on a rendered prompt was one huge `-`/`+` pair, and reading "what will the agent actually be told?" meant mentally un-escaping the string. Values containing newlines now render as multi-line literal strings (`'''`), which keep real newlines and do no escape processing — so the content round-trips byte-for-byte and the renderer needs no escaping logic. The newline after the opening delimiter is the delimiter's own (TOML trims it), so it must not be doubled; verified against smol-toml for values with and without a trailing newline. Falls back to the basic form when the value cannot be a literal: a body containing `'''`, a body ending in `'` (either would close the delimiter early), or control characters such as `\r`. Empty and single-line values keep the existing output. The same treatment covers strings arriving from `tool_extras.codex`, which are copied verbatim into the TOML root. Tests assert the round trip (`parseToml(renderForCodex(spec))` equals the original instructions) rather than the exact formatting, plus the fallback and single-line cases. Full suite: 4140 passed / 98 failed against a 4134 / 100 baseline — the 98 failures are pre-existing environment-dependent ones (hooks, doctor, init, push-pending-pr), unchanged by this diff. `tsc --noEmit` clean. Closes Tencent#749 Assisted-by: Claude Code:claude-sonnet-4-5
|
Findings
|
The delivery check compares the delivered copy byte for byte with what pullItem renders, so the fixture has to be the render. Since Tencent#749 a multi-line `instructions` renders as a TOML literal (```'''```) that keeps the real newline, rather than smol-toml's basic string with a ```\n``` escape — the codex agent check therefore reported a stale copy where the file was exactly what the CLI had just written.
The substitution passed the generated TOML as a *string* replacement, so JavaScript expanded `$&`, `$$`, `$'` and the backtick form inside the agent-authored value. A multi-line shell instruction carrying `$$` lost a dollar and no longer round-tripped. It now uses a function replacement, whose return value is used verbatim. `canUseTomlLiteral` also now refuses U+007F DEL. TOML 1.0 bans it from literal strings along with C0, and it sits outside the `\x00-\x1f` block the predicate already covered, so it needed its own alternative. Tests: a `$$`/`$&` prompt round-trips byte-for-byte, and a DEL-carrying value still renders a document that parses. The `$$` case is RED without the replacement callback.
ydflow
force-pushed
the
fix/codex-toml-multiline-literal
branch
from
September 23, 2026 13:42
5a1dfb1 to
8596077
Compare
|
Findings
Resolved
|
Merged
3 tasks done
Merged
4 of 8 tasks
Walternater
pushed a commit
to Walternater/teamai-cli
that referenced
this pull request
Nov 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #749
Summary
renderTomlAgent()insrc/resources/agent-format.tshanded the whole spec to smol-toml'sstringifywith no options. That always emits basic strings, so every newline in a prompt became a literal\nescape:A 16-line prompt (headings + bullet lists + a numbered output contract) collapses into one ~700-character line. Consequences, all from the issue:
git diffon the rendered file is one huge-/+pairsed 's/\n/\n/g'Fix
Values containing newlines now render as multi-line literal strings:
The literal form rather than the basic multi-line form (
""") because literals do no escape processing — content containing\or"round-trips byte-for-byte and the renderer needs no escaping logic at all.One detail worth flagging: the newline after the opening delimiter is the delimiter's own (TOML trims it), so
'''\nvalue\n'''appends a newline the value never had.'''\nvalue'''round-trips exactly. I verified this against smol-toml for values with and without a trailing newline rather than assuming it.Fallback
The basic form is kept when the value cannot be represented as a literal — a body containing
''', a body ending in'(either closes the delimiter early), control characters such as\r, or U+007F DEL (TOML 1.0 bans it from literal strings along with C0, and it sits outside the\x00-\x1fblock the predicate already covered). Empty and single-line values are unchanged, so existing single-line agents render byte-identically to before.The same treatment covers strings arriving from
tool_extras.codex, which are copied verbatim into the TOML root.Dollar signs stay verbatim
The substitution passes a function replacement rather than a string. The value is agent-authored content, and a string replacement would let JavaScript expand
$&,$$,$'and the backtick form inside it — a multi-line shell instruction carrying$$would silently lose a dollar and no longer round-trip.Tests
src/__tests__/agent-format.test.tsasserts the round trip (parseToml(renderForCodex(spec))equals the original instructions) rather than exact formatting:$$and$&round-trips byte-for-byteends with a quote',contains ''' inside,has a CR) round-trip on the basic formtool_extras.codexstrings get the same treatmentnpx tsc --noEmitexit 0.npm run buildexit 0.The RED is real: reverting only the replacement callback to a string replacement fails the
$$case, because the prompt no longer round-trips.End-to-end, real CLI
npm run build, then the compileddist/index.jsagainst a local git team repo (provider: git) holding.teamai/agents/shell-helper.mdwith a fencedbashblock containingecho "$$HOME",toolPaths.codexdeclared, and the.codexroot created so the tool counts as installed:Not verified
I did not exercise a live
teamai pullagainst a real remote, and I did not run the fullnpm run test:e2esuite — it needsTEAMAI_TEST_TOKENandTEAMAI_TEST_REPO_URL, which I do not have.The one e2e file this branch touches,
src/__tests__/e2e/doctor-delivery-cli.test.ts, was run directly and its expected codex fixture updated to the literal form. It reports 3 failed / 9 passed, but the same three failures occur on an unmodified checkout oforigin/main(verified by building and running that file in a clean worktree) — they are Windows shell/env-dependent and predate this change. This branch adds no new failures.The full agent/provider matrix from AGENTS.md (Claude, Codex, CodeBuddy, OpenCode × git, gitlab, github) is therefore not covered by this record.
Scope
Only the codex renderer.
renderTomlAgentis shared byrenderForCodexandrenderForCodexInternal, so both get the fix; no other tool format is touched. The unrelatedhook-handlerschange that had drifted into this branch was removed, so the diff is codex rendering plus its tests only.Assisted-by: Claude Code:claude-sonnet-4-5