Skip to content

fix: spec {{PREAMBLE}} duplication bug + factor shared conduct block out of every skill#2342

Open
agrawalparth08 wants to merge 1 commit into
garrytan:mainfrom
agrawalparth08:upstream-pr
Open

fix: spec {{PREAMBLE}} duplication bug + factor shared conduct block out of every skill#2342
agrawalparth08 wants to merge 1 commit into
garrytan:mainfrom
agrawalparth08:upstream-pr

Conversation

@agrawalparth08

Copy link
Copy Markdown

What

Two fixes found in a 2026-07-25 context-engineering audit of the generated skills:

1. Template-assembly bug: spec/SKILL.md ships with the entire preamble pasted twice

spec/SKILL.md.tmpl referenced {{PREAMBLE}} inline in prose ("emitted by {{PREAMBLE}}'s preamble bash"). The resolver expands every occurrence, so the generated spec/SKILL.md contained the full ~770-line preamble block a second time, spliced mid-sentence into the Phase 5 dispatch logic (2360 lines instead of ~1590).

  • Fixed the prose to reference the preamble without braces.
  • Added a guard in gen-skill-docs.ts: {{PREAMBLE}} appearing more than once in a template now throws at gen time with a clear message, instead of silently corrupting output.

2. Factor the identical behavioral block into one shared doc (Claude host)

Every Claude-host skill carried the same ~150-190 line block: "Model-Specific Behavioral Patch", "Voice", "Completion Status Protocol", "Operational Self-Improvement" — identical for a given build, duplicated ~49 times. Per Anthropic's Claude-5 context-engineering guidance this is generic behavioral prose that should be stated once.

  • The block is now generated once into docs/shared-conduct.md; each skill's preamble carries a short ## Shared Conduct pointer to it.
  • Operational parts (telemetry bash, plan-status footer) stay inline in every skill since they must execute even if the doc is never read.
  • External hosts (Codex/Factory) keep the full inline block — their install layouts don't ship the shared doc.
  • Net: ~45K tokens saved across the generated corpus (916K → 871K).

Tests

  • Updated the assertions that pinned the inline block (preamble composition order, escalation protocol, voice contract).
  • Recaptured the parity size baseline and refreshed the claude-ship golden for the deliberate uniform shrink.
  • bun test on the touched suites: 822 pass, 0 fail on top of current main.

🤖 Generated with Claude Code

…ck into docs/shared-conduct.md

Two fixes found in a context-engineering audit:

1. spec/SKILL.md.tmpl referenced {{PREAMBLE}} inline in prose ('emitted by
   `{{PREAMBLE}}`'s preamble bash'), which the resolver expanded, pasting the
   entire ~770-line preamble block a second time mid-sentence into the
   generated spec/SKILL.md (2360 lines instead of ~1590). Fixed the prose and
   added a generator guard: {{PREAMBLE}} appearing more than once per template
   now throws at gen time instead of silently corrupting output.

2. The identical behavioral block stamped into every Claude-host skill
   (Model-Specific Behavioral Patch, Voice, Completion Status Protocol,
   Operational Self-Improvement — ~150-190 lines x 49 skills) is factored
   into one generated docs/shared-conduct.md; each skill carries a short
   '## Shared Conduct' pointer instead. Operational parts (telemetry bash,
   plan-status footer) stay inline. External hosts (Codex/Factory) keep the
   full inline block since their installs don't ship the shared doc.
   Saves ~45K tokens across the generated corpus.

Tests updated for the factoring; parity baseline recaptured and claude-ship
golden refreshed (deliberate uniform shrink).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@trunk-io

trunk-io Bot commented Jul 24, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant