compound-engineering-plugin icon indicating copy to clipboard operation
compound-engineering-plugin copied to clipboard

feat(ce-compound): add headless mode:autofix with depth selector

Open benwilson opened this issue 7 months ago • 6 comments

Summary

Adds a headless affordance to /ce-compound for programmatic callers such as post-merge hooks, CI jobs, and orchestrator pipelines.

  • mode:autofix enables unattended operation. It suppresses the mode-selection prompt, session-history opt-in, Discoverability consent, Phase 2.5 selective-refresh prompt, and the post-run "What's next?" menu.
  • depth:lightweight|standard|deep selects the unattended execution depth and defaults to lightweight.
    • depth:lightweight -> single-pass documentation, no subagents, no overlap check.
    • depth:standard -> Phase 1 parallel research, overlap-update behavior, and Phase 3 specialized reviewers. Session history is off.
    • depth:deep -> Standard path plus Session Historian dispatch.

depth: is parsed only when mode:autofix is present. Invalid autofix depth values halt before subagent dispatch with ce-compound failed. Reason: unknown depth:<value>. Valid values: lightweight, standard, deep.

Motivation

ce-compound previously required interactive prompts, which made subprocess invocation unreliable in unattended contexts. A call such as claude -p "/ce-compound ..." or codex exec "Run /ce-compound" --ephemeral could hang or degrade because there was no user available to answer the documented fallback prompt.

Sibling skills in this plugin already have explicit unattended modes (ce-compound-refresh uses mode:autofix; ce-code-review supports mode:autofix, mode:headless, and mode:report-only; ce-doc-review supports mode:headless). This PR brings ce-compound in line with that pattern.

Output Contract

The full parser-facing contract lives at plugins/compound-engineering/skills/ce-compound/references/autofix-output-parse-contract.md; it is not loaded by the skill at runtime.

Reliable anchors

Search anywhere in stdout — first-line discipline does not hold; the agent prepends narration before any template block.

Shape detector substrings:

Anchor Shape Meaning
✓ Documentation complete success-complete A doc was written. The (mode:autofix) suffix is unreliable on this line; see best-effort.
✓ No documentation written (mode:autofix) no-op Preconditions unmet; nothing written.

No-op block supporting anchors (present when the no-op detector substring appears):

Anchor Meaning
Depth: Execution path taken (lightweight|standard|deep).
Reason: One-line rationale; may continue on indented lines.
Context considered: Bulleted summary of available context.

Best-effort fields

Callers MUST NOT hard-fail when these are absent — they are emitted opportunistically and frequently drop in headless runs:

  • ✓ Documentation updated substring (success-updated path is unreachable in claude -p — demoted by construction)
  • (mode:autofix) suffix on success-shape lines (lightweight mode emits its own suffix variants)
  • File created: / File updated: paths
  • Track: / Category: / Overlap detected: fields
  • Refresh candidate: and Discoverability recommendation: blocks
  • Phase 1 subagents: / Phase 3 specialized reviewers: blocks

Testing

  • bun test tests/compound-support-files.test.ts tests/pipeline-review-contract.test.ts - 51 pass / 0 fail.
  • bun run release:validate - clean.
  • bun test overall - 896 pass / 9 fail. The 9 failures are all in tests/skills/ce-polish-beta-project-type.test.ts and predate this branch.

benwilson avatar Apr 23 '26 23:04 benwilson

Thanks for the review @tmchow — all five asks addressed in 19885940:

  1. Mode Detection collapsed (line 34) to 23 lines: one two-row table + depth:<preset> bullets + invalid-depth halt + four-bullet Autofix mode rules. Matches the ce-compound-refresh shape.
  2. Token grammar reworked (line 44) to orthogonal mode:autofix + optional depth:lightweight|full|thorough. No prefix trap, no tokenization rule, no conflicting-mode-flags clause.
  3. Output templates consolidated (line 520) to one parameterized success template + one short no-op template (~60 lines combined, stays in-body — 630 × 20% = 126-line extraction threshold).
  4. Runtime-neutral rationale cut (lines 57, 70, 522, 544): per-variant Use-when bullets gone with their parent subsections, subagent-safety paragraph gone, Note: inside the output template gone, parser-contract paragraph moved to references/autofix-output-parse-contract.md (not loaded at runtime; contract also appears in the refreshed PR body for caller authors). "Print the full block" directive survives in the Autofix mode rules block.
  5. Learning doc deleted — compound-skill-improvements.md is gone with no shrunken successor.

Net: -209 / +91 lines in the commit; SKILL.md dropped from 686 to 630. bun test 896/9 (same 9 pre-existing ce-polish-beta-project-type failures); bun run release:validate clean.

One pre-authorized divergence from your line-44 suggestion (follow-up to #discussion_r3140321365): went with three depth presets (lightweight|full|thorough) rather than a binary depth:full. Rationale: depth:thorough is the only way to expose the session-history opt-in to a headless caller without prompting. If you'd rather this collapse to binary, say the word and I'll fold thorough into full (or drop it entirely). Not planning to defend the three-preset choice past one round.

PR body refreshed to match the new grammar and carries the output contract table.

benwilson avatar Apr 24 '26 22:04 benwilson

Follow-ups since 19885940:

  • 6f409f8b — dispatch Session Historian on depth:thorough in autofix. Caught by headless test: Phase 1 step 4 header still said "only if the user opted in," so the autofix dispatch branch never fired even though Mode Detection promised it would.
  • 77d9de66 — tighten the Session Historian dispatch rule per AGENTS.md rationale discipline. Collapses parenthetical restatements 6f409f8b had introduced.
  • a8cf13a4 — guard the "What's next?" prompt at the prompt site. Codex P1 #discussion_r3140572986. Mode Detection suppression alone was too weak to override the direct "present the options" imperative nearby.
  • 3d032e1d — scope depth: parsing and validation to autofix mode. Codex P2 #discussion_r3140572989. Interactive calls whose context happened to contain depth:... no longer hit the invalid-depth halt.

Known drift worth flagging before re-review: in headless claude -p --permission-mode bypassPermissions "/ce-compound mode:autofix depth:full|thorough ..." runs, agents reliably emit ✓ Documentation complete and File created: / File updated: anchors, but frequently drop the (mode:autofix) suffix, Depth:, Track:/Category:, and the structured Phase 1 subagents: / Phase 3 specialized reviewers: blocks — synthesizing their own summary with improvised section names instead. I tested six SKILL.md-text interventions (stronger imperatives, extraction to references/, explicit tool-call directives, structural marker changes) and none produced reliable contract compliance. Looks like a pattern that doesn't yield to modest text changes — a reliable fix would likely need subagent dispatch for the output step or a structured output format (YAML/JSON), both beyond this PR's review scope. Downstream parsers keying on the reliable anchors (first-line ✓ string + File created: / File updated:) will work; those depending on the unreliable anchors won't. Flagging so it isn't a surprise if you test headlessly — happy to address in a follow-up PR if it matters.

benwilson avatar Apr 24 '26 23:04 benwilson

@benwilson reconcile teh PR description to ensure it's accurate given the changes please

tmchow avatar May 05 '26 22:05 tmchow

Done — PR description reconciled with the current branch. It now uses depth:lightweight|standard|deep, updates the invalid-depth error text, and updates the output-contract table.

benwilson avatar May 05 '26 22:05 benwilson

Headless reliability sweep — empirical findings (PR 662)

Following #pullrequestreview-4231940863, I ran a formal sweep of every parser-anchor field in references/autofix-output-parse-contract.md (and the SKILL.md template anchors not currently in the contract) so the reliable/best-effort split is data-driven rather than asserted.

Bench

  • Branch: feat/ce-compound-autofix @ 7c8156d4
  • CWD: /Users/bwilson/Documents/Source/compound-engineering-plugin (repo root)
  • docs/solutions/ entry count at SHA: 26
  • claude CLI: 2.1.129
  • Sweep elapsed: 13 minutes (18 total runs, all exit 0)

Methodology

For each cell {intended-shape} × {depth}, I ran 3 invocations of:

claude -p --permission-mode bypassPermissions "/ce-compound mode:autofix depth:<preset> <prompt>"

The success-updated shape was skipped by construction — overlap-update needs the Solution Extractor to produce a "new fix" alongside Related Docs Finder finding "high overlap," and the Solution Extractor reads conversation history, which claude -p doesn't have. Overlap detected: and File updated: are demoted to best-effort by construction.

Two prompts:

  • success-complete: detailed Jest+Redis fix description with named file, root cause, verification evidence (50 reruns).
  • no-op: vague "Something seems off with how the build is sometimes slow. Looking into it."

After each run, untracked docs/solutions/ files were cleaned so subsequent runs started from the same bench state.

Intended-vs-actual shape map

Cell Run 1 Run 2 Run 3
complete, lightweight complete complete other (free-form refusal)
complete, standard noop noop noop
complete, deep noop noop noop
noop, lightweight other (free-form refusal) other other
noop, standard noop other other
noop, deep noop other noop

The standard/deep "complete" cells all flipped to no-op because Phase 1 verification caught that the claimed fix file (tests/setup/redis-pool.ts) doesn't exist in this checkout — the agent correctly refused to fabricate a learning doc. Lightweight mode skips that verification step and is more permissive.

First-line discipline (literal head -1)

Across all 18 runs, the documented ✓ ... first-line string is the literal first non-blank line in 0/18 runs. The agent always emits narration before the template block. Callers using head -1 will fail every time.

✓ line suffix observed when the shape was emitted

Run Suffix
complete-lightweight-1 (lightweight mode)
complete-lightweight-2 (lightweight + autofix mode)
complete-lightweight-3 (no ✓ line — free-form refusal)
complete-standard-1..3 (mode:autofix) (but on the ✓ No documentation written line, not complete)
complete-deep-1..3 (mode:autofix) (same as above)
noop-lightweight-1..3 (no ✓ line — free-form refusal)
noop-standard-1 (mode:autofix)
noop-standard-2..3 (no ✓ line — free-form refusal)
noop-deep-1, noop-deep-3 (mode:autofix)
noop-deep-2 (no ✓ line — free-form refusal)

The lightweight mode emits its own suffix variants ((lightweight mode) / (lightweight + autofix mode)), never (mode:autofix). The lightweight template at SKILL.md:385 ((lightweight mode) was added in #528, predates this PR) wasn't updated when this PR added the autofix grammar at SKILL.md:505 promising (mode:autofix). Autofix-lightweight runs fall through to the older lightweight template — a gap this PR introduced by promising a suffix the lightweight path doesn't produce.

Anchor presence (anywhere in stdout body)

Anchor complete-lw complete-std complete-deep noop-lw noop-std noop-deep
✓ Documentation complete 2/3 0/3 0/3 0/3 0/3 0/3
✓ Documentation updated 0/3 0/3 0/3 0/3 0/3 0/3
✓ No documentation written 0/3 3/3 3/3 0/3 1/3 2/3
(mode:autofix) on ✓ line 0/3 3/3 3/3 0/3 1/3 2/3
^Depth: 0/3 3/3 3/3 0/3 1/3 2/3
^File created: 2/3 0/3 0/3 0/3 0/3 0/3
^File updated: 0/3 0/3 0/3 0/3 0/3 0/3
^Track: 1/3 0/3 0/3 0/3 0/3 0/3
^Category: 0/3 0/3 0/3 0/3 0/3 0/3
^Overlap detected: 0/3 0/3 0/3 0/3 0/3 0/3
^Refresh candidate: 0/3 0/3 0/3 0/3 0/3 0/3
^Discoverability recommendation: 0/3 0/3 0/3 0/3 0/3 0/3
^Reason: 0/3 3/3 3/3 0/3 1/3 2/3
^Context considered: 0/3 3/3 3/3 0/3 1/3 2/3
^Phase 1 subagents: 0/3 0/3 0/3 0/3 0/3 0/3
^Phase 3 specialized reviewers: 0/3 0/3 0/3 0/3 0/3 0/3

Reliability classification

The data does not support keeping anything as "reliable" under a 100% / zero-drift bar. The pragmatic story:

  1. No first-line anchor is reliable. Callers must search anywhere in stdout, not at line 1.
  2. Phase 1 / Phase 3 subagent blocks are never emitted in headless mode (0/18 anywhere). They are template aspiration, not runtime reality.
  3. Lightweight mode has its own incompatible output surface — different ✓ suffix on success, free-form prose on refusal. The contract that nominally covers all three depths actually only fits standard/deep, and only on the no-op path.
  4. The no-op output is the only template that fires consistently when the shape is taken. When ✓ No documentation written (mode:autofix) appears, Depth:, Reason:, Context considered: co-occur 9/9 times. That is the strongest reliability signal in the data.
  5. Success-complete anchors (File created:, Track:, Category:) are inconsistent even within the lightweight cell that did emit the success-complete shape — File created: appeared 2/3, Track: 1/3, Category: 0/3.

Resulting contract trim

Reliable section keeps the shape-detector substrings (search anywhere, not first-line) plus the no-op block's supporting anchors:

  • ✓ Documentation complete — success-complete shape; (mode:autofix) suffix on this line is unreliable (see best-effort)
  • ✓ No documentation written (mode:autofix) — no-op shape
  • When the no-op substring is present: Depth:, Reason:, Context considered: co-occur 100% (9/9 in measured cells)

Best-effort section: ✓ Documentation updated (unreachable in -p, demoted by construction), (mode:autofix) suffix on success lines, File created:, File updated:, Track:, Category:, Overlap detected:, Refresh candidate:, Discoverability recommendation:, Phase 1 subagents:, Phase 3 specialized reviewers:. Callers must not hard-fail when these are missing.

Raw run logs are at ${TMPDIR}/compound-engineering/pr-662-headless-reliability/20260505-155532/runs/ on my machine; the methodology and prompts above are sufficient to reproduce from any checkout of the same SHA.

The structural fix to make the demoted anchors reliable (subagent dispatch for the output step, structured output format, or aligning the lightweight template's suffix with the autofix template) is deferred to a follow-up PR per the original review.

benwilson avatar May 06 '26 06:05 benwilson

Re: #pullrequestreview-4231940863

Took the empirical route on this — ran an 18-run headless sweep against the current branch so the demotion list is data-grounded rather than asserted. Full methodology and per-cell tallies in the empirical findings comment.

The data largely supports your reliable set, with two adjustments:

  • Substring matching, not first-line discipline. No ✓ ... anchor was the literal first non-blank line of stdout in any run (0/18). The agent always prepends narration before the template block. Reliable claims are scoped to substring presence anywhere in stdout.
  • Demoted ✓ Documentation updated, File created:, File updated: to best-effort. ✓ Documentation updated is unreachable from claude -p (success-updated needs the Solution Extractor to read conversation history, which -p doesn't have) and was 0/18. File created: was 2/3 only in complete-lightweight runs that actually wrote a doc, 0 elsewhere. File updated: is in the same demoted-by-construction bucket as ✓ Documentation updated.

Trimmed references/autofix-output-parse-contract.md and the PR body's Output Contract table accordingly:

  • Reliable: ✓ Documentation complete and ✓ No documentation written (mode:autofix) as shape-detector substrings; when the no-op substring is present, Depth:, Reason:, Context considered: co-occur 100% (9/9 in measured cells).
  • Best-effort: the demoted anchors above plus (mode:autofix) suffix on success lines, Track:, Category:, Overlap detected:, Refresh candidate:, Discoverability recommendation:, and the Phase 1 subagents: / Phase 3 specialized reviewers: blocks (0/18 anywhere).

One runtime finding worth flagging beyond the contract trim: autofix-lightweight invocations emit a different suffix than the autofix template promises. Successes use (lightweight mode) or (lightweight + autofix mode), never (mode:autofix). The lightweight template at SKILL.md:385 (predates this PR — (lightweight mode) was added in #528) wasn't updated when this PR added the autofix grammar at SKILL.md:505 promising (mode:autofix). Autofix-lightweight runs fall through to the older lightweight template. Reconciling the two is a follow-up PR scope item.

The structural fix to make best-effort anchors reliable (subagent dispatch for the output step or a structured output format) is held for a follow-up PR per your earlier guidance.

benwilson avatar May 06 '26 06:05 benwilson