Skip to content

fix(cli): R10 — resolver respects HTML comment bounds (issue #102)#103

Merged
montfort merged 1 commit intomainfrom
fix/audit-resolver-html-comment-bounds
May 5, 2026
Merged

fix(cli): R10 — resolver respects HTML comment bounds (issue #102)#103
montfort merged 1 commit intomainfrom
fix/audit-resolver-html-comment-bounds

Conversation

@montfort
Copy link
Copy Markdown
Contributor

@montfort montfort commented May 5, 2026

Summary

First of 8 PRs implementing the integrated v1 audit-skills iteration described in Propuesta/devtrail-audit-cli-flow.md v0.2. Closes R10 of issue #102 — the resolver duplicated content by ignoring HTML comment boundaries.

What was wrong

auditor-primary.md template had a documentation header (lines 1-32) listing each placeholder with literal {{placeholder}} — description syntax for human reference. The resolver's global String::replace expanded those documentation lines, inflating ~32 lines into ~605 and duplicating ~30k tokens of payload (Charter content + AILOG + git diff) once inside the comment and once in the body proper. Sentinel observed a 1300-line resolved prompt where ~700 was expected.

What changed

In cli/src/commands/charter/audit.rs resolve_audit_template:

  1. Scan for <!-- ... --> ranges before replacement.
  2. Process the template as alternating segments — non-comment segments get the existing global-replace treatment, comment segments are appended verbatim.
  3. Unclosed comments (no matching -->) terminate the scan early and the tail is treated as comment-region (conservative, mirrors typical markdown rendering).

The fix is internal to the resolver and does not change the template format or the schema. Templates that don't use HTML comments behave identically to before.

Tests

  • 5 new unit tests in audit.rs covering: placeholder inside single HTML comment, multi-placeholder documentation header (the exact R10 trigger), multiple comment blocks, unclosed comment graceful handling, comment-free template backwards-compat.
  • 1 updated integration test (audit_prepare_writes_resolved_prompts): replaces the previous "no {{...}} anywhere" assertions with header-vs-body distinction. Explicitly verifies that {{charter_id}} and {{git_diff}} are preserved in the documentation header but replaced in the body, and that REAL_CHARTER_BODY / REAL_DIFF appear exactly once (the R10 dedup invariant).

Test plan

  • cargo test → 276 unit + 11 charter_audit (5 R10 new) + all integration suites green
  • cargo build → 2.84s
  • No version bump (lands together with PRs 2-8 in the integrated v1 release)
  • No CHANGELOG entry (consolidated section written at PR 8)

Phase v1 progress

PR Title Status
1 R10 resolver fix this PR
2 git_range default → origin/main..HEAD with fallback pending
3 Unified audit-prompt.md template based on Sentinel skill pending
4 CLI subcommand simplified (--prepare / --merge-reports) + canonical paths .devtrail/audits/ pending
5 New skill devtrail-audit-execute (3 platforms) pending
6 Updated audit-prompt and audit-review skills (review.md consolidated) pending
7 Adopter docs (3 langs) pending
8 Bump fw-4.9.0 / cli-3.10.0 + CHANGELOG + tag release pending

🤖 Generated with Claude Code

Sentinel reported in issue #102 that running `devtrail charter audit
CHARTER-07 --prepare` produced an `auditor-primary.prompt.md` of 1300
lines (vs ~700 expected) because the global `String::replace` in the
template resolver expanded `{{placeholder}}` occurrences inside the
template's HTML documentation header — duplicating ~30k tokens of
payload (Charter content + AILOG + git diff) once inside the comment
block and once in the prompt body proper.

Fix in cli/src/commands/charter/audit.rs (`resolve_audit_template`):
scan for `<!-- ... -->` ranges before replacement and process the
template as alternating segments — non-comment segments get the
existing global-replace treatment, comment segments are appended
verbatim. Unclosed comments terminate the scan early and treat the
tail as comment-region (conservative, mirrors typical markdown
rendering).

Tests:
- 5 new unit tests in audit.rs covering: placeholder inside single
  HTML comment, multi-placeholder documentation header (the exact
  R10 trigger), multiple comment blocks in one template, unclosed
  comment graceful handling, and backwards-compatibility check that
  a comment-free template still behaves like global replace.
- Updated audit_prepare_writes_resolved_prompts integration test in
  charter_audit_test.rs: replaces the previous assertions that
  required `{{charter_id}}` and `{{git_diff}}` to be entirely absent
  from the resolved prompt with assertions that distinguish header
  (preserved literal) from body (replaced) — matching the corrected
  behavior and explicitly exercising the R10 fix end-to-end.

Test plan:
- cargo test → 276 unit + 11 charter_audit + all integration green
- cargo build → 2.84s
- No version bump (lands together with PR 2-8 in the integrated v1
  release per Propuesta/devtrail-audit-cli-flow.md v0.2 §5)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@montfort montfort merged commit 99fc029 into main May 5, 2026
@montfort montfort deleted the fix/audit-resolver-html-comment-bounds branch May 5, 2026 04:58
montfort added a commit that referenced this pull request May 5, 2026
Closes the integrated v1 audit-skills iteration described in
Propuesta/devtrail-audit-cli-flow.md v0.2. Tags the previously-
merged PRs (#103-#109) into a coherent shipped release.

Bumps:
- cli/Cargo.toml: 3.9.0 → 3.10.0 (minor — new --prepare and
  --merge-reports flags, canonical path migration, deprecation
  shims for --calibrate / --finalize, R10 + R11(A) fixes; v0
  schemas evolve in place per their experimental $comment).
- dist/dist-manifest.yml: 4.8.0 → 4.9.0 (minor — new
  devtrail-audit-execute skill, unified prompt template
  replacing 3 v0 templates, AGENT-RULES §12 wording aligned to
  3-skill sequence).

Version refs updated in 22 docs (README + adopter docs +
governance footers, all 3 langs).

CHANGELOG.md gains a combined Framework 4.9.0 / CLI 3.10.0
section with Added (Framework, CLI), Changed, Removed,
Fixed (R10), Deprecated (--calibrate, --finalize), BREAKING
(deliberate within experimental v0.x — paths migration), Tests,
and explicit Credit to José Villaseñor Montfort for the audit
skills lifted from Sentinel via issue #102.

Test plan:
- cargo test → all suites green (276 unit + 17 charter_audit
  + 12 audit_skill + 9 audit_template + 4 checkpoint_guidance
  + all others).
- cargo check → version bumps propagate to Cargo.lock cleanly.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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