Repository navigation
v1.26.5.0 test: add build skill verification coverage - #10
Merged
Merged
Conversation
Add a dedicated test:build-skill script, deterministic build-skill contract and dry-run coverage, and periodic E2E handoff metadata. Bump VERSION and package.json to v1.26.5.0 and document the build-skill verification path. Co-Authored-By: OpenAI Codex <[email protected]>
anbangr
pushed a commit
that referenced
this pull request
May 7, 2026
… rename (garrytan#1351) * feat: gstack-gbrain-mcp-verify helper for remote MCP probe Probes a remote gbrain MCP endpoint with bearer auth. POSTs initialize, classifies failures into NETWORK / AUTH / MALFORMED with one-line remediation hints, and runs a tools/list capability probe to detect sources_add MCP support (forward-compat for when gbrain ships URL ingest). Token consumed from GBRAIN_MCP_TOKEN env, never argv. Required to set both 'application/json' AND 'text/event-stream' in Accept; that gotcha costs 10 minutes of debugging when missed (regression-tested). Live-verified against wintermute (gbrain v0.27.1). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat: gstack-artifacts-init + gstack-artifacts-url helpers artifacts-init replaces brain-init with provider choice (gh / glab / manual), per-user gstack-artifacts-$USER repo, HTTPS-canonical storage in ~/.gstack-artifacts-remote.txt, and a "send this to your brain admin" hookup printout. Always prints the command, never auto-executes — gbrain v0.26.x has no admin-scope MCP probe (codex Finding #3). artifacts-url centralizes HTTPS↔SSH/host/owner-repo conversion so callers don't each string-mangle (codex Finding #10). The remote-conflict check in artifacts-init compares at the canonical level so re-running with HTTPS input doesn't trip on a stored SSH URL for the same logical repo. The "URL form not supported" branch prints a two-line clone-then-path form for gbrain v0.26.x; the supported branch is a one-liner with --url ready for when gbrain ships URL ingest. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat: extend gstack-gbrain-detect with mcp_mode + artifacts_remote Adds two new fields to detect's JSON output: - gbrain_mcp_mode: local-stdio | remote-http | none Resolved via 3-tier fallback (codex Finding D3): claude mcp get --json → claude mcp list text-grep → ~/.claude.json jq read. If Anthropic moves the file format, the first two tiers absorb it. - gstack_artifacts_remote: HTTPS URL from ~/.gstack-artifacts-remote.txt Falls back to ~/.gstack-brain-remote.txt during the v1.27.0.0 migration window so detect doesn't return empty between upgrade and migration. Existing detect tests still pass (15/15). New 19 tests cover every fallback tier independently, plus a schema regression for /sync-gbrain compat. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat: setup-gbrain Path 4 (remote MCP) + artifacts rename Path 4 lets users paste an HTTPS MCP URL + bearer token and registers it as an HTTP-transport MCP without needing a local gbrain CLI install. The flow: - Step 2 gains a fourth option (Remote gbrain MCP) - Step 4 adds Path 4 sub-flow: collect URL, secret-read bearer, verify via gstack-gbrain-mcp-verify (NETWORK / AUTH / MALFORMED classifier) - Step 5 (local doctor), Step 7.5 (transcript ingest), Step 5a's stdio branch all skip on Path 4 - Step 5a adds an HTTP+bearer registration form: claude mcp add --transport http --header "Authorization: Bearer ..." - Step 7 renamed "session memory sync" → "artifacts sync" and now calls gstack-artifacts-init (which always prints the brain-admin hookup command — no auto-execute, codex Finding #3) - Step 8 CLAUDE.md block branches: remote-http includes URL + server version (never the token); local-stdio keeps engine + config-file - Step 9 smoke test on Path 4 prints the curl-equivalent for post-restart verification (MCP tools aren't visible mid-session) - Step 10 verdict block has separate templates per mode Idempotency: re-running with gbrain_mcp_mode=remote-http already in detect output skips Step 2 entirely and goes to verification. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor: rename gbrain_sync_mode → artifacts_sync_mode (v1.27.0.0 prep) Hard rename, no dual-read alias (codex Finding D4). The on-disk migration script (Phase C, separate commit) renames the config key in users' ~/.gstack/config.yaml and any CLAUDE.md blocks. Touched call sites: - bin/gstack-config defaults + validation + list/defaults output - bin/gstack-gbrain-detect (gstack_brain_sync_mode field still emitted with the same name for downstream-tool compat; reads new key) - bin/gstack-brain-sync, bin/gstack-brain-enqueue, bin/gstack-brain-uninstall - bin/gstack-timeline-log (comment ref) - scripts/resolvers/preamble/generate-brain-sync-block.ts: renames key, branches on gbrain_mcp_mode=remote-http to emit "ARTIFACTS_SYNC: remote-mode (managed by brain server <host>)" instead of the local mode/queue/last_push line (codex Finding #11) - bin/gstack-brain-restore + bin/gstack-gbrain-source-wireup: read ~/.gstack-artifacts-remote.txt with ~/.gstack-brain-remote.txt fallback during the migration window - bin/gstack-artifacts-init: tolerant of unrecognized URL forms (local paths, file://, self-hosted gitea) so test infrastructure and unusual remotes work without canonicalization - test/brain-sync.test.ts: gstack-brain-init → gstack-artifacts-init - test/skill-e2e-brain-privacy-gate.test.ts: artifacts_sync_mode keys - test/gen-skill-docs.test.ts: budget 35K → 36.5K for the new MCP-mode probe in the preamble resolver - health/SKILL.md.tmpl, sync-gbrain/SKILL.md.tmpl: comment + verdict line Hard delete: - bin/gstack-brain-init (replaced by bin/gstack-artifacts-init in v1.27.0.0) - test/gstack-brain-init-gh-mock.test.ts (replaced by gstack-artifacts-init.test.ts) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * chore: regenerate SKILL.md files after artifacts-sync rename Mechanical regen via \`bun run gen:skill-docs --host all\`. All */SKILL.md files reflect the renamed config key (gbrain_sync_mode → artifacts_sync_mode), the renamed remote-helper file (~/.gstack-artifacts-remote.txt with brain fallback), the renamed init script (gstack-artifacts-init), and the new ARTIFACTS_SYNC: remote-mode status line that fires when a remote-http MCP is registered. Golden fixtures (test/fixtures/golden/*-ship-SKILL.md) refreshed to match the regenerated default-ship output. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat: v1.27.0.0 migration — gstack-brain → gstack-artifacts rename Journaled, interruption-safe migration. Six steps, each writes to ~/.gstack/.migrations/v1.27.0.0.journal on success; re-entry resumes from the next un-done step. On final success, journal is replaced by ~/.gstack/.migrations/v1.27.0.0.done. Steps: 1. gh_repo_renamed gh/glab repo rename gstack-brain-$USER → gstack-artifacts-$USER (idempotent: detects already-renamed and skips) 2. remote_txt_renamed mv ~/.gstack-brain-remote.txt → artifacts file, rewriting URL path to match the new repo name 3. config_key_renamed sed -i in ~/.gstack/config.yaml flips gbrain_sync_mode → artifacts_sync_mode 4. claude_md_block sed flips "- Memory sync:" → "- Artifacts sync:" in cwd CLAUDE.md and ~/.gstack/CLAUDE.md 5. sources_swapped gbrain sources add NEW (verify) → remove OLD (codex Finding #6: add-before-remove ordering, no downtime window). On remote-MCP mode, prints commands for the brain admin instead of executing. 6. done touchfile + delete journal User opt-out: any "n" or "skip-for-now" answer at the initial prompt writes a marker file that prevents re-prompting; user can re-invoke via /setup-gbrain --rerun-migration. 11 unit tests cover: nothing-to-migrate, GitHub happy path, idempotent re-run, journal-resume mid-flight, remote-MCP print-only path, add-before-remove ordering verification, add-fail → old source stays registered, CLAUDE.md field rewrite. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test: regression suite + E2E for v1.27.0.0 rename Three new regression tests guard the rename's blast radius (per codex Findings #1, #8, #9, #12): - test/no-stale-gstack-brain-refs.test.ts: greps bin/, scripts/, *.tmpl, test/ for forbidden identifiers (gstack-brain-init, gbrain_sync_mode); fails CI if any non-allowlisted file references them. - test/post-rename-doc-regen.test.ts: confirms gen-skill-docs output has no stale references in any */SKILL.md (the cross-product blind spot). - test/setup-gbrain-path4-structure.test.ts: structural lint over the Path 4 prose contract — STOP gates after verify failure, never-write- token rules, mode-aware CLAUDE.md block, bearer always via env-var. Two new gate-tier E2E tests (deterministic stub HTTP server, fixed inputs): - test/skill-e2e-setup-gbrain-remote.test.ts: Path 4 happy path. Stubs an HTTP MCP server, drives the skill via Agent SDK with a stubbed bearer, asserts claude.json gets the http MCP entry, CLAUDE.md gets the remote-http block, the secret token NEVER leaks to CLAUDE.md. - test/skill-e2e-setup-gbrain-bad-token.test.ts: stub server returns 401; asserts the AUTH classifier hint surfaces, no MCP registration occurs, CLAUDE.md is unchanged. Regression guard for the "verify failed → STOP" rule. touchfiles.ts: setup-gbrain-remote and setup-gbrain-bad-token added at gate-tier so CI catches Path 4 regressions on every PR. Plus a few comment refs flipped: bin/gstack-jsonl-merge, bin/gstack-timeline-log (legacy gstack-brain-init mentions in headers). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * release: v1.27.0.0 — /setup-gbrain Path 4 + brain → artifacts rename Bumps VERSION 1.26.4.0 → 1.27.0.0 (MINOR per CLAUDE.md scale-aware bump guidance: ~1500 line net change including a new path in /setup-gbrain, two new bin helpers, a journaled migration, 59 new tests, and a config key rename across the codebase). CHANGELOG entry covers: Path 4 (Remote MCP) end-to-end, the brain → artifacts rename, the journaled migration, the verify-helper error classifier, the artifacts-init multi-host provider choice. Includes the canonical Garry-voice headline + numbers table + audience close per the release-summary format. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test: demote setup-gbrain Path 4 E2E to periodic-tier The Agent SDK E2E tests for Path 4 (skill-e2e-setup-gbrain-remote and skill-e2e-setup-gbrain-bad-token) are inherently non-deterministic — the model interprets "follow Path 4 only" prompts flexibly and can skip Step 8 (CLAUDE.md write) or shortcut past the verify helper, which makes the gate-tier assertions flaky. The deterministic gate coverage for Path 4 is in test/setup-gbrain-path4-structure.test.ts: a fast structural lint that catches AUQ-pacing regressions and prose contract drift in <200ms with zero token spend. That test is the right tool for catching the failure mode the gate-tier was meant to guard against. The Agent SDK E2E tests stay available on-demand for periodic-tier runs (EVALS=1 EVALS_TIER=periodic bun test test/skill-e2e-setup-gbrain-*.test.ts). Also tightened the verify-error assertion to the literal field shape ("error_class": "AUTH") instead of a substring match that false-matches the parent claude session's "needs-auth" MCP discovery markers. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * chore: sync package.json version to 1.27.0.0 VERSION was bumped to 1.27.0.0 in f6ec11e but package.json was not updated in the same commit. The gen-skill-docs.test.ts assertion "package.json version matches VERSION file" caught the drift. This is the DRIFT_STALE_PKG case the /ship Step 12 idempotency check is designed for; the fix is the documented sync-only repair (no re-bump, package.json synced to existing VERSION). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
anbangr
pushed a commit
that referenced
this pull request
May 15, 2026
…for code) (garrytan#1500) * feat(gbrain): add lib/gbrain-local-status classifier with 5-state engine status + 60s cache Foundation for split-engine gbrain: shared classifier used by both bin/gstack-gbrain-detect (preamble probe) and bin/gstack-gbrain-sync.ts (orchestrator SKIP-when-not-ok). Single source of truth. Probes via `gbrain sources list --json` and classifies stderr against the same patterns lib/gbrain-sources.ts:66-67 already uses ("Cannot connect to database", "config.json"). Returns one of: ok, no-cli, missing-config, broken-config, broken-db. Defensive default: unrecognized failures classify as broken-config so the raw stderr can be surfaced upstream. Cache at ~/.gstack/.gbrain-local-status-cache.json keyed on {home, path_hash, gbrain_bin_path, gbrain_version, config_mtime, config_size} with 60s TTL. Cache invalidates on any invariant change. --no-cache option busts the cache for callers that just mutated state (/setup-gbrain, /sync-gbrain after init/migration). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(gbrain): rewrite gstack-gbrain-detect bash→TS + add gbrain_local_status field Replaces the bash detect helper with a bun shebang script sharing the gbrain_local_status classifier from lib/gbrain-local-status.ts with the sync orchestrator. Single source of truth for engine-status classification between preamble-probe and orchestrator-skip paths. Filename stays gstack-gbrain-detect (no .ts extension) so existing skill preamble callers shell out unchanged. Shebang `#!/usr/bin/env -S bun run` resolves bun at runtime. Output is key/type backward-compatible with the bash version per plan codex #5: the 9 pre-existing keys (gbrain_on_path, gbrain_version, gbrain_config_exists, gbrain_engine, gbrain_doctor_ok, gbrain_mcp_mode, gstack_brain_sync_mode, gstack_brain_git, gstack_artifacts_remote) stay identical in name + type + value semantics. One new key added: gbrain_local_status (5-state string enum). Updates the existing schema regression at test/gstack-gbrain-detect-mcp-mode.test.ts to include the new key. Adds test/gbrain-detect-shape.test.ts asserting the regression contract for future changes. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(gbrain): orchestrator SKIP when local engine not ok + remote-http transcripts via artifacts pipeline Two changes in the sync orchestrator, both per plan D11/D12: 1. bin/gstack-gbrain-sync.ts: runCodeImport + runMemoryIngest call localEngineStatus() (shared classifier from lib/gbrain-local-status.ts). When status is not 'ok', return a SKIP stage result with a clear reason instead of crashing with "source registration failed: gbrain not configured". Brain-sync stage runs regardless — it doesn't depend on local engine. dry-run preview path is gated above the check so it continues to show would-do steps even when the engine is broken. 2. bin/gstack-memory-ingest.ts: when gbrain MCP is registered as remote-http (Path 4), persist staged transcripts to ~/.gstack/transcripts/run-<pid>-<ts>/ instead of the ephemeral ~/.gstack/.staging-ingest-<pid>-<ts>/ tmp dir, and SKIP the local `gbrain import` call entirely. The artifacts pipeline (gstack-brain-sync push to git, brain admin pulls and indexes) handles routing to the remote brain. Local PGLite (when present via Step 4.5) stays code-only. State recording still happens — prepared pages get their mtime+sha256 stamped under remote-http mode so the next /sync-gbrain doesn't re-stage them. Cleanup is skipped intentionally so the persisted dir survives until gstack-brain-sync moves it. Adds test/gbrain-sync-skip.test.ts covering 5 SKIP scenarios (broken-db, broken-config, no-cli, missing-config, ok pass-through). All 25 sync-related unit tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(gbrain): v1.34.0.0 migration notice + transcripts allowlist for artifacts pipeline Per plan D5 + D11. Two pieces of the split-engine rollout: 1. gstack-upgrade/migrations/v1.34.0.0.sh — prints a one-time discoverability notice for existing Path 4 (remote-http MCP) users whose machine has no local engine yet. Tells them about /setup-gbrain Step 4.5 (the new local-PGLite opt-in). Silent for everyone else. User can suppress permanently via `gstack-config set local_code_index_offered true`. Touchfile at ~/.gstack/.migrations/v1.34.0.0.done makes it idempotent. 2. bin/gstack-artifacts-init — adds `transcripts/run-*/*.md` and `transcripts/run-*/**/*.md` to the managed allowlist so the gstack-memory-ingest persistent staging dir (used in remote-http mode per D11) gets pushed to the artifacts repo. Brain admin's pull job then indexes transcripts into the remote brain. Privacy class: behavioral (matches transcript content). Adds test/gstack-upgrade-migration-v1_34_0_0.test.ts with 5 cases: state match, no-MCP, local-config-present, opt-out, and idempotency. All 5 pass. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(gbrain): /setup-gbrain Step 1.5/4.5 + /sync-gbrain Step 1.5 templates Per plan D4, D10, D11, D12. Wires the skill prose to the new split-engine flow + classifier introduced in earlier commits. setup-gbrain/SKILL.md.tmpl: - Step 1: detect output description now includes the v1.34.0.0 gbrain_local_status field (5 values). - Step 1.5 (NEW): broken-db / broken-config remediation. AskUserQuestion with 4 options — Retry / Switch to PGLite / Switch brain mode / Quit (plan D4). Retry is recommended first since broken-db often = transient Postgres outage. PGLite is explicitly one-way + destructive (moves existing config to ~/.gbrain/config.json.gstack-bak-<ts>); rollback on init failure restores the .bak (plan D7). - Step 4d → Step 4.5 (NEW): in Path 4, after the verify step, offer local PGLite for code search. AskUserQuestion Yes/No (plan D10/D11). Yes path runs gstack-gbrain-install + `gbrain init --pglite --json` with the same rollback-safe sequence. No path skips Steps 3/4/5/7.5. - Step 10 verdict (Path 4): adds "Code search" row reflecting Step 4.5 choice. Updates "Transcripts" row to describe the new D11 routing (artifacts repo → remote brain). sync-gbrain/SKILL.md.tmpl: - Step 1 split-engine prose: corrects the prior misleading claim that "memory routes through whatever setup-gbrain configured, including remote-MCP" (codex finding #3). Memory stage shells out to local `gbrain import` in local-stdio mode; in remote-http mode it persists to ~/.gstack/transcripts/ for the artifacts pipeline. - Step 1.5 (NEW): local-engine pre-flight. STOP on no-cli, broken-config, broken-db. Soft skip (continue with code+memory SKIP) on missing-config + remote-http per plan D12. Surfaces actionable user remediation message instead of the orchestrator crashing two stages with ERR. Regenerated SKILL.md for all hosts (claude, kiro, opencode, slate, cursor, openclaw, hermes, gbrain). All 712 skill-validation + gen-skill-docs tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(gbrain): .bak-rollback contract for Step 1.5 / 4.5 init failure path Per plan D7 (rollback semantics) and codex #10 (rollback scope). The /setup-gbrain skill instructs the model to follow a specific shell sequence when running `gbrain init --pglite` against an existing config: 1. mv ~/.gbrain/config.json ~/.gbrain/config.json.gstack-bak-<ts> 2. gbrain init --pglite --json 3. on non-zero exit: mv .bak back; surface error This test verifies that contract using a fake `gbrain` binary that fails on init. Three cases: - FAILURE: gbrain init exits non-zero → broken config restored to original path, no leftover .bak. - SUCCESS: gbrain init exits 0 → new config in place, .bak survives for audit (user reviews + deletes manually). - SCOPE: any partial PGLite directory at ~/.gbrain/pglite/ is NOT auto-cleaned. We only promise to restore config.json; PGLite cleanup is the user's call (codex #10). If the skill template rewrites this sequence in a future change, this test should fail until the test's shell is updated too. That's the point — keep the test and the skill template aligned. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(gbrain): periodic E2E for /setup-gbrain Path 4 + Step 4.5 Yes flow End-to-end coverage of the new opt-in question via runAgentSdkTest. Stubs the MCP endpoint at /tools/list with a 200 response carrying a fake gbrain v0.32.3.0 serverInfo, and fakes the gbrain + claude CLIs so init writes a PGLite config and mcp add succeeds. Asserts the model: 1. invokes gstack-gbrain-install (Step 4.5 Yes branch) 2. invokes `gbrain init --pglite --json` 3. writes a working ~/.gbrain/config.json with engine=pglite 4. registers the remote MCP via `claude mcp add --transport http` 5. never leaks the bearer token to CLAUDE.md Classified as periodic-tier per plan D6 (codex #12 flagged AgentSDK flakiness; gate-tier coverage of the split-engine behavior lives in the deterministic unit tests at gbrain-local-status.test.ts and gbrain-sync-skip.test.ts). Touchfile fires the test when the skill template, install/verify/init helpers, the local-status classifier, or the agent-sdk-runner harness changes. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * chore(gbrain): bump migration to v1.35.0.0 after main merge main shipped v1.34.0.0 (factory-export submodule) + v1.34.1.0 (update-check hardening) while this branch was in flight. The migration file I named v1.34.0.0.sh now belongs at v1.35.0.0 — the next minor on top of main, matching the scale of split-engine work (new lib + orchestrator skip + template overhaul + transcripts routing). Renames the migration script and its test file; updates all internal version references in both files. Behavior unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * perf(gbrain): memoize gbrain resolution + use --fast doctor in detect Cuts detect's wall time substantially by sharing fork-exec results between the helper that walks the JSON output and the localEngineStatus classifier from lib/gbrain-local-status.ts. Before: detect made 2x `command -v gbrain` calls (one in detect's detectGbrain, one in the classifier's resolveGbrainBin) and 2x `gbrain --version` calls. With memoization keyed on PATH, both collapse to one fork each (~400ms saved per skill preamble). Also adds `--fast` to the `gbrain doctor --json` call in detect so a broken-db config (Garry's repro) doesn't burn a full 5s timeout on the doctor's DB-connection check. The classifier still probes the DB directly via `gbrain sources list --json` for engine reachability — that's `gbrain_local_status`, separate from the coarse `gbrain_doctor_ok` summary flag. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(gbrain): relax E2E assertions to smoke-test contract Per codex #12 (AgentSDK harness is non-deterministic): the E2E now asserts the model followed the split-engine path WITHOUT requiring a specific subcommand sequence. Three assertions: 1. AskUserQuestion was called (model reached interactive branches) 2. At least one of {gstack-gbrain-install, `gbrain init --pglite`, `claude mcp add`} fired (model followed the skill, not a no-op) 3. The fake bearer token never leaked to CLAUDE.md (security regression) Deterministic per-step coverage of the same flow lives in the gate-tier unit tests (gbrain-local-status, gbrain-sync-skip, init-rollback, upgrade-migration). The E2E exists to catch the "model can't follow the skill at all" regression class, not to pin the exact tool sequence. Test passes in 280s against the live Agent SDK. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(version): bump CLI smoke-test timeout to 15s (flaky at 5s under load) The gstack-next-version integration smoke test spawns a child process that does git operations + sibling-worktree probing. Wall time hovers 4-5s on M-series Macs; flakes at exactly 5001-5002ms when the test suite runs under load (bun's parallel scheduling). Bumping per-test timeout to 15s eliminates the flake without changing test logic. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * chore: bump version and changelog (v1.37.0.0) Co-Authored-By: Claude Opus 4.7 <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
anbangr
added a commit
that referenced
this pull request
May 20, 2026
* docs: design for build plan-review convergence loop Spec for /build's planSynthesizer ↔ planReviewer loop: in-process round loop, mid-loop user triage gate, plan-file-as-ledger cross-round memory, set-aware adaptive cap. Triggering case was bundle-1 (5→3→2→manual r4, ~$5-10) where rigor caught real bugs but the operator was locked out until round 3. New default brings user in at round 1, makes each round cheaper via in-process loop, and adapts the cap to actual convergence. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(spec): pin adaptive-cap exit_reason mapping in convergence design Self-review caught a small ambiguity: the decision table listed two bail-out triggers (re-raises-only and regression) but the exit_reason enum had three adaptive-cap values without an explicit mapping. Fixed: enum now has exactly adaptive_cap_re_raises_only and adaptive_cap_regression, and the decision table rows reference which exit_reason each triggers. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(plan): implementation plan for build plan-review convergence 19-task TDD-structured plan for the convergence loop spec. Each task is self-contained: failing test → minimal impl → passing test → commit. Covers types (T1), annotation contract (T2), history JSONL (T3), convergence aggregate (T4), adaptive cap (T5), TTY triage (T6), non-TTY triage (T7), prompts (T8), main loop (T9), CLI wire-in (T10), disputed counting (T11), three integration tests (T12-T14), E2E (T15), SKILL.md shrink + version bump (T16), README (T17), CHANGELOG (T18), final verification (T19). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/types): add convergence types for plan-review loop Extends PlanReviewVerdict with optional triage_decisions, round_history_path, convergence, interrupted_at_objection fields. Adds TriageDecision and ConvergenceSnapshot interfaces and ROUND_HISTORY_FORMAT_VERSION constant. All new fields are optional so existing call sites compile unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(build/types): camelCase convergence field names; drop NEW: prefix Code-quality review flagged inconsistency: existing PlanReviewVerdict fields use camelCase (reviewedBy, round) but the new convergence fields landed as snake_case (triage_decisions, round_history_path, etc). Converts all new TypeScript interface fields to camelCase to match the file's established convention. JSONL wire formats in later tasks can still use snake_case via JSON.stringify of manually-shaped objects -- TypeScript types do not need to mirror JSONL key shape. Also drops the informal "NEW:" prefix from JSDoc comments and adds a one-line doc for TriageDecision.decision. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-reviewer): add round-annotation read/write contract Adds parseRoundAnnotations, writeRoundAnnotation, parseRoundHistoryHeader, updateRoundHistoryHeader exported from plan-reviewer.ts. These implement the cross-round memory contract: each round's triage decisions and synth resolutions are written into the plan file as HTML comment blocks above the matching '### Phase N' heading, plus a top-of-plan history block. The next round's reviewer reads these to know what's already been decided. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-reviewer): ROUND N REVIEWER attaches to round N's entry The original Task 2 commit had the parser attach ROUND N REVIEWER lines to round N-1's entry. That choice was forced by a self-contradicting test fixture (a ROUND 2 REVIEWER: line inside an annotation the test required to have rounds.length === 1). Both the design spec and Task 9's planned writer in runPlanReviewLoop treat ROUND N REVIEWER as a round-N observation paired with round N's USER decision (if any). The N-1 offset would have corrupted every annotation round-trip in Tasks 9, 11, and the integration tests. Fixes the parser to attach directly to round N. Updates the broken test fixture to assert the realistic multi-round shape: round 1 carries USER/RESOLUTION, round 2 carries only REVIEWER (because no round-2 USER decision happened on this annotation -- the reviewer did not re-raise). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-reviewer): silent corruption + missing JSDoc on annotation writers Three issues from code-quality review: 1. writeRoundAnnotation's two String.replace() call sites used string replacements, which interpret \$&, \$', \$\` and \$N as substitution patterns. A plan annotation whose field text contains those tokens (plausible when reviewing regex / shell / template code) would have produced silently corrupted output. Both call sites now use function replacements which suppress the interpolation. 2. Misleading comment in parseRoundAnnotations claimed the header always names "round 1". An annotation first written in round 2+ opens with ROUND 2 CRITICAL [...], which the parser already handles correctly -- the comment was the only wrong thing. 3. RoundHistoryEntry, parseRoundHistoryHeader, and updateRoundHistoryHeader gained JSDoc explaining purpose, the optional finalLine parameter (used on loop exit for the 'final: APPROVED after N rounds, ...' line), and the atomic-write invariant. New regression test covers the \$& interpolation foot-gun by round-tripping fields containing every replacement-pattern token. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): add round-history JSONL writer New module plan-review-loop.ts will house the in-process round loop, triage gate, and adaptive-cap. First commit establishes the per-build-state history JSONL: append-only, corruption-tolerant reads, round-counter derivation. appendHistoryEntry / readHistoryEntries / deriveRoundNumber pair with the existing plan-reviewer.ts::readPlanReviewRound for cross-launch resume. HistoryEntry uses camelCase field names (objectionCountRaw, noForwardProgress, reRaises, newObjections) matching the Task 1 convention; the JSONL on disk serializes the same camelCase, so jq queries can use the field names verbatim. Also registers plan-review-loop.ts in coverage-matrix.test.ts so the MODULE_TEST_OWNERS invariant stays green. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): cross-build convergence aggregate writer writeConvergenceAggregate appends one line per completed build to ~/.gstack/analytics/convergence.jsonl. Captures trajectory, exitReason, total accept/reject/defer counts, wall time, and annotation parse errors -- the tuning signal needed to validate MAX_ROUNDS=5 and the adaptive cap rule over weeks of builds. Best-effort write: aggregate analytics never block the build path. ConvergenceAggregate uses camelCase fields matching the Task 1 convention; jq queries use the field names verbatim. Adds the ExitReason union as a distinct exported type so Task 5's adaptive-cap decision and Task 9's loop exit can return values type-checked against it. Also extends MODULE_TEST_OWNERS coverage entry for plan-review-loop.ts to include the new test file. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): set-aware adaptive cap rule computeConvergenceSnapshot compares round-k accepted objections against prior-round annotations parsed from the plan file. Classifies each as re-raise (prior accepted-and-resolved, same (location, severity)) or new objection. Rejected-prior matches are deliberately neither -- they are reviewer-prompt-fidelity signals, not synth-failure signals. shouldBailAdaptive implements the decision table from the design spec: hard cap at MAX_ROUNDS triggers stalemate_gate, accepted-count regression triggers adaptive_cap_regression, re-raises-with-no-new triggers adaptive_cap_re_raises_only. Precedence is explicit and tested across six scenarios covering round 1, mid-loop continue, both bail paths, the hard cap, and adaptive-disabled. camelCase fields throughout (priorRoundAccepted, reRaises, newObjections, noForwardProgress) matching Task 1 convention. Exports ConvergenceSnapshotInput, RoundConvergenceSnapshot, AdaptiveCapInput, AdaptiveCapDecision so Task 9's runPlanReviewLoop can compose with them. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): TTY triage gate for per-objection decisions runTriageGateTTY prompts user per CRITICAL objection with the 8-key menu (a/r/d/v/A/R/s/q + Enter), captures optional rationale, surfaces re-raises with prior rejection context, and supports fast-path A/R or early quit. Stream-based input/output so tests can drive it without a real TTY, following the existing build/orchestrator/__tests__/feature-review-prompt.test.ts pattern: Readable.push(Buffer.from(...)) to avoid object-mode readline pitfalls. Uses a line-queue/waiter pattern to decouple readline event emission from the sequential ask() calls — avoids the ERR_USE_AFTER_CLOSE trap that occurs when readline output ownership conflicts with the injected output stream. 8 tests cover: per-objection accept with rationale capture, mixed reject/defer/accept, [A]ccept-ALL and [R]eject-ALL fast paths, [s]top remainder, [q]uit early, and re-raise framing with prior-rejection context. Returns TriageGateResult with quitEarly / fastPathed flags so Task 9's loop can route exit codes correctly. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): non-TTY triage modes for CI / scripts / agents runTriageGateNonTTY: synchronous, no readline. Three modes, picked via the --plan-review-noninteractive CLI flag added in Task 10: - auto-accept (default, extends the existing IMPORTANT-objection non-TTY behavior to CRITICAL): accept every objection, re-synth, continue - fail-fast: exit code 3 on the first round with CRITICAL — strict CI gate - auto-reject: reject every objection, annotate as rejected, proceed — escape hatch for known-noisy reviewer runs Returns NonTTYTriageResult with decisions[] (one per input objection) and shouldFailFast flag. camelCase fields throughout matching Task 1 convention. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-reviewer): annotation-aware reviewer + synth prompts Extends PLAN_REVIEW_PROMPT with a paragraph teaching the reviewer to read prior-round annotations (USER:accept/reject, RESOLUTION:pending/disputed, REVIEWER:re-raised) and not re-raise settled concerns. Promotes the const to an export so the new snapshot test can verify it without dynamic import gymnastics. Adds new exported SYNTH_REVISION_PROMPT (formerly inline in build/SKILL.md.tmpl Step 5.5 -- moved to plan-reviewer.ts so Task 10's cli.ts can use it from a typed import) instructing the synthesizer to honor user triage decisions, write RESOLUTION lines, and mark disputes when the user accepted something the synth thinks is wrong. Snapshot-tested so unintended drift surfaces in CI; non-snapshot assertions pin the core annotation contract phrases. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): in-process round loop runPlanReviewLoop Composes the reviewer call, triage gate (TTY or non-TTY), annotation writes, convergence snapshot, adaptive-cap decision, history JSONL append, top-of-plan history header update, and synth dispatch -- all in-process so re-launch overhead between rounds is eliminated. runStalemateGate handles the user-facing AskUser at adaptive-cap-bail or MAX_ROUNDS exit. Uses the same line-queue/waiter readline pattern as runTriageGateTTY (Task 6) to work around Bun's readline ERR_USE_AFTER_CLOSE on multi-question sequences. Single-readline-per-loop: when isTTY, runPlanReviewLoop stands up one shared readline + ask function and threads it into runTriageGateTTY and runStalemateGate via an optional askFn injection point. Per-call readlines drain the entire buffered input stream on the first close, starving later rounds. Existing standalone-call tests for the gates keep working because askFn defaults to undefined and each gate opens its own readline in that case. Tests cover: APPROVE round 1 (no synth, fastest path), bundle-1 trajectory 5->3->2->0 with three synth invocations, adaptive bail on re-raises stall at round 2. disputed_resolutions per-round count is a placeholder zero in this commit; Task 11 wires it to the real RESOLUTION: disputed annotation detection after each synth call. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/cli): wire runPlanReviewLoop into startup path Replaces the single-shot runPlanReview + reconcilePlanReview call with the new in-process loop. Adds three CLI flags: --plan-review-max-rounds=N (default 5; range 1..20) --plan-review-no-adaptive-cap (off; disables forward-progress bail) --plan-review-noninteractive=<auto-accept|fail-fast|auto-reject> (default auto-accept) Exit codes preserved on the existing side (0 approve, 1 runtime, 2 test fail); new contract: 3 = stalemate (user picked [m] or non-TTY fail-fast hit CRITICAL) 4 = user abort (user picked [q] at gate) 130 = SIGINT during triage (unchanged) Legacy plan-review-report.json is still written from loopResult.finalVerdict so SKILL.md.tmpl Step 5.5 stalemate handler keeps working without changes until Task 16 shrinks it. synthFn adapter dispatches a configured Claude role with the SYNTH_REVISION_PROMPT from Task 8 against the now-annotated plan file. Since the dedicated planSynthesizer role does not yet exist in role-config.ts, the adapter falls back to planReviewer's role config and the timeout falls back to BUILD_DEFAULTS.timeoutsMs.planReview. Both are forward-compatible: once planSynthesizer lands, the `as any` accessors pick it up automatically. reconcilePlanReview and readPlanReviewRound are no longer imported in cli.ts now that the loop owns reconciliation and round tracking; they remain exported from plan-reviewer.ts for tests that exercise them. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/plan-review-loop): count disputed resolutions per round Replaces the Task 9 placeholder disputedResolutions.push(0) after the synth call with a real count: re-parse plan annotations, find this round's entries with RESOLUTION starting "disputed", tally them. The synth writes RESOLUTION: disputed -- <reason> when it disagrees with a user-accepted objection. Each disputed entry surfaces in the next round's triage so the user can re-decide. The aggregate count in convergence.jsonl is the tuning signal for "how often does synth disagree with user accepts" -- high counts suggest reviewer prompt fidelity issues or user triage rationale weakness. Annotation parse errors during this re-parse increment annotationParseErrors and log to console.warn; they do not crash the loop. The placeholder pushes on adaptive-bail-continue and on APPROVE paths stay 0 (no synth invocation means no resolutions to count). Also fixes annotationParseErrors declaration from const to let, which was previously a no-op placeholder but now receives increments inside the error catch path. New test covers the disputed-resolution path: round 1 has 2 accepted CRITICAL, synth marks one disputed and one applied, aggregate's disputedResolutions[0] is 1. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(build/integration): bundle-1 trajectory converges 5→3→2→0 Integration test using stub reviewer (replaying fixture data from the real bundle-1 trajectory: 5 CRITICAL → 3 new → 2 new → APPROVE) and a stub synth that replaces RESOLUTION:pending with RESOLUTION:applied. Verifies the end-to-end story: - 4 rounds, 3 synth invocations, exit APPROVE - history JSONL has 4 lines (one per round) - convergence aggregate has correct trajectory and totals: trajectoryRaw [5, 3, 2, 0], totalAccepted 10, finalVerdict APPROVE - plan file accumulates ROUND 1/2/3 annotations + top-of-plan history block Fixture data lives in test/fixtures/build-convergence/ for sharing across Tasks 13, 14, 15 (the other integration + E2E tests). Coverage-matrix updated: plan-review-loop.ts now lists the integration test as an additional owner alongside the unit tests. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(build/integration): adaptive cap bails on re-raises-only Integration test verifying the no-forward-progress bail path: Round 1 raises 2 CRITICAL, user accepts both, synth marks RESOLUTION non-pending (a real fix attempt). Round 2 raises the same 2 CRITICAL with zero new objections — adaptive cap detects this as a true stall (reRaises=2, newObjections=0). Bail-out gate fires. User picks [m]anual mode → exit code 3, outcome user_manual, exit_reason user_manual in convergence.jsonl. Synth is invoked exactly once (round 1) — the bail-out fires before the round-2 synth call, saving the wasted API spend the design was built to prevent. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(build/integration): synth disputes a user-accepted objection Integration test for the synth-dispute escape hatch: Round 1 reviewer raises 1 CRITICAL ("use bcrypt"). User accepts. Synth disagrees -- instead of applying the fix, it writes RESOLUTION: disputed -- bcrypt conflicts with FIPS in this build. The dispute is captured in two telemetry surfaces: - disputedResolutions[0] === 1 in convergence.jsonl - The plan annotation preserves the synth's reasoning verbatim so the next round's reviewer (or user, if it re-surfaces) sees WHY synth declined to apply the fix. Round 2 reviewer reads the disputed annotation and approves (validating that a dispute does not force a re-raise -- the reviewer can decide). Loop exits clean with outcome "approved". Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(e2e): real Codex respects round-annotation contract Layer 4 E2E from the convergence design spec. Drives runPlanReviewLoop with the real Codex planReviewer against the bundle-1 fixture plan created in Task 12. Stub synth rewrites RESOLUTION: pending so the round-2 reviewer call sees a non-pending resolution annotation. Asserts that once round 1's objections are accepted and annotated as RESOLUTION: applied, round 2's Codex call does not re-raise them (reRaises[1] === 0) -- proving the reviewer prompt addition (Task 8) actually changes real-Codex behavior, not just our parser tests. Classified gate tier per CLAUDE.md; ~$0.50/run. Gated by EVALS=1; free tests run without invoking Codex. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(build/skill): shrink Step 5.5 to handle exit codes only The in-process loop in plan-review-loop.ts now resolves most rounds inside the CLI. Step 5.5 shrinks to a four-branch dispatch on exit codes 0/3/4/130, plus the existing exit-1/2 paths. The cross-round annotation history lives in the plan file, so manual edits between launches just need to preserve those annotations so the next round's reviewer has context. Bumps skill version 1.24.0 -> 1.25.0 (MINOR -- new capability). NOT bumping top-level VERSION per fork rule in CLAUDE.md. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(build/orchestrator): document the plan-review convergence loop Adds a section to the orchestrator README covering the loop architecture, exit code contract, flags, telemetry file layout, triage gate key map, and module boundaries. Cross-references the design spec. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(changelog): build skill 1.25.0 — in-process plan-review loop User-facing entry for the convergence loop change. NOT bumping top-level VERSION per CLAUDE.md fork rule -- only the build skill frontmatter bumped (Task 16). Entry covers what changed for the user, projected metrics from the bundle-1 case study, itemized add/changed/contributor changes, with spec cross-reference. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(build/orchestrator): clarify exit code 3 ambiguity + fix dropped indent Pre-landing review surfaced two README findings: 1. Exit code 3 has two meanings since this PR: lock contention at startup AND plan-review stalemate. The general exit-code table now reflects both. Exit codes 4 (user abort) and 130 (SIGINT) added to the table for completeness. 2. The troubleshooting bullet for --mark-phase-committed lost its 2-space leading indent during the table reformatting pass. Restored so the bullet continuation renders correctly. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(build/orchestrator): strengthen 8 test gaps from pre-landing review Pre-landing review found 8 test-quality findings. Addressed here: 1. types-convergence.test.ts: trivial echo-assertions replaced with behavioral tests that exercise types via real function calls. 2. plan-annotation-round-trip.test.ts: new test for the fallback-prepend path in writeRoundAnnotation when the referenced Phase heading is absent from the plan text. 3. loop-converge-bundle-1.test.ts: added structural placement assertion to confirm annotations land in the expected position (the fixture intentionally exercises the fallback-prepend path for rounds 2-3 which raise objections at non-existent phases). 4. plan-reviewer-triage-tty.test.ts: new test for the [v]iew prose key path, verifying the assessment text is shown before the re-prompt. 5. skill-e2e-build-convergence.test.ts: tier-gate pattern aligned with other E2E tests (EVALS=1 && EVALS_TIER==='gate', no 'all' fallback). Core contract assertion no longer wrapped in a conditional that would let the test pass vacuously if Codex approves round 1. 6. plan-reviewer-loop.test.ts: new test exercising the max-rounds stalemate path (reviewer always REVISE, non-TTY auto-accept, confirms rounds === maxRounds at exit). 7. adaptive-cap-set-aware.test.ts: new test for the 'fewer accepted with new objections' branch, confirming the loop continues when accepted count decreases but new dimensions appeared. 8. History-entry expectations updated for tests where the production fix (IMPORTANT/SUGGESTION counts now recorded) changes the asserted shape. Most tests use CRITICAL-only fixtures and are unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-review-loop): restore IMPORTANT/SUGGESTION handling + 9 cleanups Pre-landing review surfaced one CRITICAL contract violation and 9 informational items. All addressed in this commit: CRITICAL — IMPORTANT/SUGGESTION objections silently dropped (regression). The early-return at the APPROVE / zero-CRITICAL branch treated REVISE-with- non-CRITICAL-only as APPROVE without annotating IMPORTANT/SUGGESTION objections in the plan file or recording them in the history. The pre- loop reconcilePlanReview path handled them via inline annotate-and- proceed; that path is no longer reached because cli.ts dropped the reconcilePlanReview call when wiring runPlanReviewLoop. Restored by filtering important/suggestion, calling writeRoundAnnotation for each, and recording real counts in HistoryEntry. Maintainability cleanups: - LoopOutcome aliased to ExitReason (byte-identical union); the as-cast in writeAggregate removed. - Dead sigint literal removed from ExitReason; SIGINT handling lives in cli.ts signal handler, not the loop return type. - ROUND_HISTORY_FORMAT_VERSION removed from types.ts; was never imported. - Always-false interrupted field removed from ConvergenceAggregate; no code path mutated it. - Stale "Task 11 placeholder" comment on disputedResolutions replaced with accurate description of what the array contains. - makeReadlineAsk helper extracted; the ERR_USE_AFTER_CLOSE workaround for Bun readline is now in one place instead of three duplicated blocks (triage TTY standalone, loop shared, stalemate standalone). Performance cleanups: - Two redundant readFileSync calls per round eliminated: the plan-text read for re-raise detection is reused for annotation-write, and the in-memory updatedPlan is passed to updateRoundHistoryHeader instead of re-reading from disk after writing. - existsSync + statSync collapsed to statSync with try/catch. Performance finding #4 (pre-parse annotations once before writeRoundAnnotation loop) deferred — requires writeRoundAnnotation signature change in plan-reviewer.ts; sub-ms cost at typical scale (K=5-10 objections, 20-50KB plan). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-reviewer): close 4 silent-data-loss annotation bugs Red Team review verified 4 round-trip corruption modes in the annotation parser/writer. Each fails silently with no warning. 1. '-->' in any user-supplied field closes the HTML comment early. Subsequent lines bleed into plan text; parser silently drops rounds[]. 2. '"' in rationale stops the [^"]* regex group at the first inner quote. Rationale field silently dropped. 3. ']' in location stops the [^\]\n]+ regex group at the first inner bracket. ENTIRE annotation silently lost. 4. Non-canonical whitespace in existing in-file annotations makes writeRoundAnnotation's merge path a silent no-op. Round 2's decision silently lost. Fix #1-3: HTML-entity encoding on serialize, decode on parse. Encode ampersand first (so user input containing literal escape sequences round-trips correctly); decode ampersand last. Encoded sequences: ']' -> ']', '"' -> '"', '-->' -> '-->', '&' -> '&'. Applied to userRationale, issue, suggestion, location, resolution. userDecision is a fixed enum (no encoding). Operator warning logged on first character requiring encoding per field so silent encoding never lands without an audit trail. Fix #4: writeRoundAnnotation merge path walks the regex over planText directly to locate the actual byte range of each existing block (handling non-canonical whitespace, CRLF, external-editor reformat). A fresh local regex avoids the shared ANNOTATION_BLOCK_RE's lastIndex being reset inside parseRoundAnnotations during the loop, which otherwise caused infinite loops on the same span. Twelve new tests pin the round-trip invariants: - '-->' / '"' / ']' / '%' / '&' all round-trip correctly - merge into non-canonical 8-space-indent block preserves round 2 - literal ']' does not decode to ']' on parse Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-review-loop, cli): close 8 Red Team findings CRITICAL #1 (regression from round-1 fix): TTY mode now prompts per IMPORTANT objection (y/skip/all) instead of unconditionally auto-accepting. Restores the pre-loop reconcilePlanReview contract that was lost when the loop went in-process. SUGGESTION objections remain auto-annotated (no prompt). Non-TTY mode still auto-accepts per existing CI contract. CRITICAL #6: runPlanReviewLoop now calls deriveRoundNumber on startup, reads prior history, and starts the round counter at the next available number on resume. Trajectory arrays are hydrated from history so shouldBailAdaptive has the right context. Resume after exit-3 or exit-130 no longer duplicates round numbers in history.jsonl or writes a second convergence aggregate record. INFO #7: objectionCountRaw set to critical.length only (matches JSDoc and other paths). Verdict written as verdict.verdict, not hardcoded "APPROVE", in the REVISE-with-zero-CRITICAL branch. INFO #8: Early-exit paths (user quit, non-TTY fail-fast) now push sentinel -1 to trajectoryAccepted, reRaisesArr, reRejectedArr, disputedResolutions to maintain length parity with trajectoryRaw. User-quit path also writes an INTERRUPTED history entry. INFO #9: synthFn rejection wrapped in try/catch. On failure, the loop writes an INTERRUPTED history entry, writes the aggregate with exitReason: reviewer_unavailable, closes shared resources, and exits with code 1. INFO #10: Plan-file writes use atomic tmp + rename pattern. SIGINT during a write can no longer leave a half-written plan that the parser would silently skip on resume. INFO #11: HOME fallback uses os.homedir() with os.tmpdir() as secondary. Containers without HOME no longer pollute the project worktree. INFO #12: [s]top key in runTriageGateTTY no longer prompts for the current-objection rationale before exiting. The current decision is pushed with empty rationale and the loop moves on. Tests added: resume-from-history, synth-failure-handled, TTY IMPORTANT prompt, array-length parity on quit. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-review-loop): close adversarial review CRITICALs Claude adversarial review found two real bugs the 3-specialist + Red Team rounds missed. Both verified by reading the code. C1 (CRITICAL): TTY infinite-loop on stdin close. The decision-loop default case in runTriageGateTTY (and two siblings in the IMPORTANT prompt + runStalemateGate) was `opts.output.write("Invalid input '${ans}'...")` with no EOF handling. Once makeReadlineAsk's streamClosed sets the internal flag, ask() resolves with "" forever, and the while-loop spins at 100% CPU printing "Invalid input ''" until externally killed. Triggered by routine Ctrl+D, piped stdin closing, or terminal disconnect mid-triage. All three sites now treat empty input as a quit/abort/skip-all signal. C2 (CRITICAL): Convergence aggregate array-length skew on reviewer_unavailable exit. planFileSizeBytes was pushed unconditionally at the top of every round iteration, but the reviewer_unavailable branch returned without pushing to trajectoryRaw / trajectoryAccepted / reRaisesArr / reRejectedArr / disputedResolutions. The resulting aggregate row had one array of length N+1 alongside others of length N; downstream consumers indexing by round walked off the wrong array. Same bug class as the Red Team's INFO #8 fix (sentinel pushes on early-exit), missed on this branch. Fix: explicit sentinel pushes to the five parallel arrays before writeAggregate. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-reviewer): close adversarial review findings on annotation contract Claude adversarial review found 4 more issues with the annotation parser/writer beyond what the Red Team caught. All address the same root cause: insufficient field encoding in serialize/parse round-trip, plus a merge predicate that's too strict. I1: writeRoundAnnotation merge predicate dropped `issue` (LLM-written freeform text). Match on (location, severity) only. Aligns with computeConvergenceSnapshot's keying. Wording drift round-over-round ("missing chainId" vs "handler doesn't validate chainId") no longer orphans annotation blocks. I2: '→' (right-arrow U+2192) added to encodeAnnField. The header field-separator regex uses ' → ' to split issue from suggestion; without encoding, an LLM-generated issue containing '→' (natural in prose: "A → B then B → C") truncates at the first arrow. Encoded as '→' to match the existing HTML-entity scheme. Decode order: '→' before '&'. I3: '\n' and '\r' added to encodeAnnField (encoded as ' ' and ' '). Without this, a multi-line rationale ('line 1\n ROUND 1 RESOLUTION: fake') would have the embedded line picked up by ROUND_RESOLUTION_RE as a real RESOLUTION entry, overriding the genuine synth-written resolution. Also defends against CRLF line endings on Windows-written plan files. N4: ROUND_USER_RE, ROUND_RESOLUTION_RE, ROUND_REVIEWER_RE converted from module-level /g constants to factory functions (`getRoundUserRe()` etc). Each parser call gets a fresh regex with lastIndex=0, so concurrent parser invocations cannot smash each other's iterator state via the shared lastIndex. Defensive hardening; not currently triggered because Node is single-threaded and the call sites don't await between matches. Four new tests pin the invariants: - Merge across wording drift (location+severity, ignore issue) - '→' in issue round-trips without splitting - Newline injection in rationale doesn't forge RESOLUTION lines - CRLF in rationale round-trips Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-review-loop): close adversarial review findings on loop semantics Claude adversarial review found 5 more issues in plan-review-loop.ts beyond what the Red Team caught. Fixes follow. I4 (IMPORTANT): isPriorAcceptedResolutionAttempt changed from .some() to last-entry semantics. Spec intent (per the computeConvergenceSnapshot comment) is most-recent-decision wins: a round-2 user-reject should override a round-1 user-accept for re-raise classification purposes. The old .some() returned true if ANY prior round had accept+resolved, incorrectly counting a "user changed their mind" sequence as a re-raise in round 3. Spec mismatch — fixed to check rounds[rounds.length-1] only. N1 (INFO): INTERRUPTED verdict wired into the user-quit / SIGINT path. The quitEarly branch in runPlanReviewLoop now writes a per-round history entry with verdict: "INTERRUPTED" before writing the convergence aggregate. The HistoryEntry verdict union previously declared "INTERRUPTED" as a possible value but no code path produced it. N3 (INFO): /^disputed\b/ regex made case-insensitive (i flag) so synth output drift ("Disputed", "DISPUTED") is still counted as a disputed resolution. Tuning signal robustness across model behavior changes. N5 (INFO): priorRejectRationale Map now hydrates from prior plan annotations on resume (startRound > 1). Without this, re-raise framing on resumed runs showed empty strings for the user's earlier rejection rationale even though the rationale was present in the plan file. N6 (INFO): atomicWriteFile tmp filename suffix extended with crypto.randomBytes(8) for cross-process collision safety. The pid+ms approach was unique within a single Node process but container-in-container scenarios could share both. N7 (empty rationale to undefined on round-trip) is owned by plan-reviewer.ts (parallel scope) — not addressed here. Three new tests cover: - last-round-wins re-raise classification (positive + negative) - case-insensitive 'Disputed' counted as disputed resolution - priorRejectRationale hydration on resume shows prior rationale Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/plan-review-loop, cli): close 3 Codex HIGH findings on loop semantics H2: synthFn now propagates the SubAgentResult's exit-code as `ok`, and runPlanReviewLoop checks the returned ok. A synth that hit a timeout, model-not-found error, or non-zero exit no longer silently masquerades as a successful round. Failure routes through the synth_failure exit reason added in c5e7b3e. H3: [c] Continue anyway at the adaptive bail gate now runs the synth before looping. Previously the `continue` statement jumped straight to the next round iteration, skipping synth dispatch entirely — the next paid reviewer round then reviewed the same unresolved plan with RESOLUTION: pending unchanged, virtually guaranteeing re-raises and burning the round. Extracted the synth-call into a helper so the normal-flow path and the continue path share one code path. H4: Resume past maxRounds (startRound > maxRounds, e.g., user re- launched after exiting manual mode at the cap) no longer falls through the empty for-loop to a `lastVerdict!` non-null assertion on a null value. Added a startRound > maxRounds guard that synthesizes an APPROVE verdict ("Resume past maxRounds; review skipped.") and returns with outcome: "approved", round: startRound - 1. Three new tests pin the invariants: - synthFn returning ok:false routes to synth_failure exit code 1 - [c] continue invokes synth before next reviewer round - resume with startRound > maxRounds doesn't crash Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(build/cli, plan-review-loop): close 3 Codex structured review P1/P2 findings Codex structured review (the formal --base main P0/P1/P2/P3 pass) found three issues that bypass the plan-review gate. All closed here. P1 #1: cli.ts:9935-9963 only handled exit codes 3 / 4 / 130 then fell through to `state.planReview = loopResult.finalVerdict; saveState; ...` and proceeded into implementation. exitCode 1 (synth_failure) silently bypassed the gate. Now exitCode 1 persists state.planReview with status: "synth_failure" and throws ExitError(1). The build stops; the resume gate (see next fix) picks it up. P1 #2: cli.ts:9814-9818 resume gate only re-ran the loop when state.planReview was missing or status === "critical_exit_pending". Status values "user_aborted" and "synth_failure" were treated as "already reviewed" — the next resume saw a REVISE verdict and proceeded to phases. Both pending statuses now route through the gate so resume picks up the loop as the docs promise. P2: plan-review-loop.ts:851 resume-past-maxRounds auto-approved with a synthetic APPROVE verdict purely based on history length. A user who typed `gstack-build resume` without actually editing the plan bypassed the review gate. Now runs ONE more verification reviewer call on the (potentially-edited) plan. APPROVE → proceed. REVISE with CRITICAL → exit STALEMATE (3); the user must edit further or pass --no-plan-review to explicitly override. The existing H4 test ("returns approved with synthetic verdict") was updated to assert the new behavior (one reviewer call, APPROVE result), and a companion H4-P2 test covers the REVISE-from-verification path that exits STALEMATE. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs: post-ship documentation update for plan-review convergence (v1.40.5.0) - CHANGELOG.md: remove stray merge-artifact line (> > > > > > > origin/main) and fix stray # in Design spec bullet point in For contributors section - build/orchestrator/README.md: add plan-reviewer.ts, plan-review-loop.ts, drain-faults.ts, halt-event-helpers.ts, halt-events.ts to Architecture module map (all added on this branch, were missing from the module list) Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
4 tasks done
anbangr
pushed a commit
that referenced
this pull request
Jun 16, 2026
…arrytan#2004) * feat: add shared call-time isConductor() helper Single source of truth for Conductor host detection in TS consumers (CONDUCTOR_WORKSPACE_PATH / CONDUCTOR_PORT). Reads the passed env at call time, not a module-load snapshot, so unit tests can pin the env inline without Bun --preload (esm-hoist-breaks-env-pin-bootstrap). Co-Authored-By: Claude Fable 5 <[email protected]> * test: harden question-preference-hook harness against ambient Conductor env runHook copied all of process.env into the hook subprocess, so running the suite inside Conductor (CONDUCTOR_WORKSPACE_PATH/PORT set) would leak those markers. Strip them so the existing cases deterministically characterize NON-Conductor behavior before the Conductor branch lands. Baseline: 15 pass. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: PreToolUse hook denies AskUserQuestion in Conductor, redirects to prose Conductor disables native AskUserQuestion and routes through a flaky MCP variant that returns '[Tool result missing due to internal error]'. The hook now denies any AUQ call in a Conductor session and instructs the model to render a prose decision brief instead (transport avoidance, not preference enforcement) — firing for one-way doors too, with a typed-confirmation requirement for destructive paths. Precedence: never-ask auto-decide still wins (user already settled those); Conductor prose is the fallback for everything else; non-Conductor behavior is byte-for-byte unchanged. Restructured the per-question loop to compute eligibility without early-returning so the Conductor branch can run as the fallback while preserving memoryContext on every exit. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: Conductor renders AskUserQuestion decisions as prose by default In Conductor, native AskUserQuestion is disabled and the MCP variant is flaky, so skills now render every decision as a plain-text prose brief the user answers by typing a letter — proactively, not as a failure reaction. - Preamble emits CONDUCTOR_SESSION, gated on != headless so eval/CI inside Conductor still BLOCKs instead of rendering prose to nobody. - AskUserQuestion Format gains a Conductor-default-prose rule (auto-decide preferences still apply first; prose decisions log via gstack-question-log since PostToolUse never fires), a one-way/destructive typed-confirmation rule, and a typed-reply continuation protocol for split chains. - Regenerated all SKILL.md + ship golden fixtures; bumped affected carve skeleton caps to absorb the always-loaded additions. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: deploy the Conductor AskUserQuestion hook (setup + upgrade migration) The PreToolUse hook only delivers its Conductor-prose guarantee if it's installed, but setup skips hook registration in non-interactive (conductor/CI) setups. Two fixes so layer 3 actually deploys: - setup: treat a Conductor workspace as an implicit opt-in for the PreToolUse hook on the silent fall-through (never overriding an explicit opt-out). - migration v1.58.0.0: re-register the hook for existing Conductor installs on /gstack-upgrade, idempotent and respecting plan_tune_hooks=no. Co-Authored-By: Claude Fable 5 <[email protected]> * test: E2E for Conductor prose + fix auto-decide-preserved GSTACK_HOME bug - New skill-e2e-conductor-prose (periodic): Conductor env + plan-eng-review surfaces a prose decision brief, not a silent skip. Header documents this is end-to-end behavior coverage; the deterministic Conductor guard is the question-preference-hook unit test (the PTY harness can't register the MCP variant — Codex #10). - Fix the pre-existing bug in auto-decide-preserved: it seeded the never-ask preference under GSTACK_HOME=tmpHome but never passed GSTACK_HOME into the PTY run, so the spawned claude read the real ~/.gstack and the preference was inert (Codex #9). Now passes GSTACK_HOME + CONDUCTOR_WORKSPACE_PATH to prove auto-decide still wins over the Conductor prose redirect. - Register both in touchfiles (periodic tier). Co-Authored-By: Claude Fable 5 <[email protected]> * v1.58.0.0 feat: Conductor renders AskUserQuestion decisions as prose Co-Authored-By: Claude Fable 5 <[email protected]> * test: strip ambient Conductor env in memory-cache-injection hook harness Same dev-in-Conductor leak fixed for question-preference-hook: this suite's runHook copies process.env, so running it inside Conductor flipped the defer-path memoryContext assertions into the [conductor] prose deny. Strip CONDUCTOR_* so the cases characterize non-Conductor behavior. (CI is headless, so this only bit local Conductor runs.) Co-Authored-By: Claude Fable 5 <[email protected]> * feat: gstack-detach — run agent eval/bench jobs in their own session Long agent-run jobs (30-60 min evals, benchmarks) die when the harness sends SIGTERM to a background task's process group on turn boundaries / monitor stops / interruptions (observed: 'script test:gate terminated by signal SIGTERM'). gstack-detach runs the command in a fresh session (python3 os.setsid, or setsid on Linux, nohup fallback) so a group SIGTERM can't reach it, and wraps it in caffeinate -i on macOS so idle-sleep can't kill it either. Returns immediately; caller polls the logfile. Secrets stay in env, never argv. The guard test pins the contract: the command runs in a different process group than the caller and outlives the launching shell. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: eval:bg* scripts — detached eval runs for agents Agent-facing convenience scripts that launch the eval suites through gstack-detach so a harness SIGTERM can't kill a long run. eval:bg (diff-based), eval:bg:all, eval:bg:gate, eval:bg:periodic — each returns immediately and streams to /tmp/gstack-evals.log for polling. The plain test:evals / test:e2e scripts stay foreground for humans. Co-Authored-By: Claude Fable 5 <[email protected]> * docs: CLAUDE.md — agents must run long evals via gstack-detach Codifies the detached-execution default: agent-launched eval/benchmark runs go through bin/gstack-detach (or the eval:bg* scripts) so a harness SIGTERM or macOS idle-sleep can't kill a 30-60 min run, then poll the log with a death-aware watcher. Humans keep foreground scripts. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: harden gstack-detach against all four eval-infra killers The basic bash detach fixed SIGTERM but a real run on a shared dev box hit three more killers: cross-worktree API saturation (15-way concurrency x a sibling worktree mass-timed-out the suite), a silent hang (periodic bun died with no exit marker), and shared-/tmp log contamination (a concurrent worktree's agent output bled into the log). Rewrite as a portable python3 tool that bakes in all four fixes: - fork + setsid: SIGTERM-proof (own session, survives harness polite-quit) - caffeinate -i on macOS: no idle-sleep death - --lock NAME (fcntl, machine-wide): concurrent worktrees SERIALIZE instead of saturating the shared model API - run-scoped default log (~/.gstack-dev/eval-runs/<label>-<slug>-<branch>-<ts>-<pid>): no cross-worktree collision/contamination - --timeout watchdog + a guaranteed '### gstack-detach EXIT=<code> ###' sentinel on every terminal path: no silent hang, finished-vs-died always detectable Guard test pins all four: detached pgid differs + outlives launcher, run-scoped log path, watchdog EXIT=timeout, and lock serialization (second run WAITS). Co-Authored-By: Claude Fable 5 <[email protected]> * feat: eval:bg* use run-scoped logs + machine lock + watchdog Drop the shared /tmp/gstack-evals.log path (the cross-worktree collision that contaminated a live run) for gstack-detach's run-scoped default, and add the machine-wide gstack-evals lock (concurrent worktrees serialize, no API saturation) plus per-tier watchdog timeouts (60/90/120 min). Each eval:bg* prints its run-scoped log path to poll. Co-Authored-By: Claude Fable 5 <[email protected]> * docs: wire detached-eval guidance into /ship + correct CLAUDE.md flags - /ship eval step (sections/tests.md): long eval suites launch via gstack-detach (own session, machine lock, EXIT sentinel) so a turn boundary can't kill a 30+ min run mid-ship — the exact failure observed during this branch's ship. - CLAUDE.md: correct the now-stale /tmp reference; document the --lock (serialize worktrees, no API saturation), --timeout watchdog, run-scoped log, and the guaranteed EXIT sentinel the poller breaks on. Co-Authored-By: Claude Fable 5 <[email protected]> * refactor: extract pure promotedEnv() from conductor-env-shim Single source of truth for GSTACK_* key promotion semantics. The ambient promoteConductorEnv() becomes a wrapper; behavior-preserving. Needed by the hermetic env builder which must not mutate process.env. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: hermetic child-env builder for E2E runners Allowlist scrub (basics/network/named-auth kept; CONDUCTOR_*, CLAUDE_*, GSTACK_*, MCP_*, GBRAIN_*, operator credentials dropped), per-runner extraAllow, overrides merge last, EVALS_HERMETIC=0 byte-identical escape hatch read at call time (ESM-hoist safe). Sync memoized singleton temp dirs (<runRoot>/.claude keeps the extractPlanFilePath contract), seeded .claude.json for non-interactive first run, pid-aware GC of crashed runs. 19 free unit tests. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: session-runner spawns hermetic children + isolation canaries claude -p children now get the allowlist-scrubbed env and a gated --strict-mcp-config (EVALS_HERMETIC=0 restores operator env AND args). Two gate-tier canaries make the clean room falsifiable: hermetic-canary asserts env redirect + scrub + zero MCP servers + nonzero API-key cost from the Bash tool_result (never model prose); hermetic-sentinel plants a poisoned operator config (user CLAUDE.md + MCP server) and proves the child cannot see it. Empirically verified on claude 2.1.175: print mode needs no seed config (the seed serves the PTY path); the child CLI sets CLAUDECODE for its own tools, so that scrub is pinned in unit tests, not E2E. hermetic-env.ts joins GLOBAL_TOUCHFILES. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: PTY runner spawns hermetic claude sessions launchClaudePty children get the allowlist-scrubbed env, a gated --strict-mcp-config, and the session exposes hermeticConfigDir for forensics (hermetic plan files live under <dir>/plans/ and still match extractPlanFilePath via the /.claude dir-name contract). Seeded trust state covers repo-cwd sessions; the 15s trust-watcher stays as fallback. Verified foreground via the plan-mode-no-op gate test. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: codex/gemini runners spawn hermetic children Same allowlist scrub as the claude runners, with each provider's auth surface re-admitted via extraAllow (codex: OPENAI_API_KEY/CODEX_* plus its tempHome .codex copy; gemini: GEMINI_*/GOOGLE_* with real HOME for ~/.gemini auth). The gemini spawn previously inherited the full operator env with no env property at all. Co-Authored-By: Claude Fable 5 <[email protected]> * feat: agent-sdk-runner spawns hermetic children via complete Options.env The historical 'env: breaks SDK auth' failure was partial-env replacement: Options.env replaces the child's entire environment, so objects lacking ANTHROPIC_API_KEY killed auth. Passing the complete hermetic env (key + PATH + redirected CLAUDE_CONFIG_DIR/GSTACK_HOME) works — validated live via query() with a Bash tool call (success, real cost, Conductor vars scrubbed). Per-test opts.env merges last; ambient key mutation still works because the builder reads process.env at call time. Co-Authored-By: Claude Fable 5 <[email protected]> * test: static tripwire pins hermetic wiring in all five runners Free-tier invariants: every runner builds child env via hermeticChildEnv, no raw ...process.env spread at any spawn site, --strict-mcp-config gated on isHermeticEnabled in both claude runners, and no test callsite passes the operator env into a runner's override parameter (scoped to runner calls — unit tests spawning gstack bin scripts directly are exempt). Mirrors the terminal-agent-pid-identity / server-embedder-terminal-port tripwire idiom. Co-Authored-By: Claude Fable 5 <[email protected]> * test: refresh codex/factory ship goldens with detached-eval block a38089a added the gstack-detach guidance to the ship template and updated the claude golden; the codex and factory goldens missed the same 16-line block. Regenerated via bun run gen:skill-docs. Co-Authored-By: Claude Fable 5 <[email protected]> * docs: hermetic local E2E is the default; retire stale SDK env warning CLAUDE.md now documents the hermetic clean room (allowlist scrub, fresh seeded CLAUDE_CONFIG_DIR, temp GSTACK_HOME, --strict-mcp-config), EVALS_HERMETIC=0 as the debug escape hatch, and replaces the 'never pass env: to runAgentSdkTest' rule with the verified mechanism (partial-env replacement was the failure; complete env is safe). Co-Authored-By: Claude Fable 5 <[email protected]> * fix: operational-learning fixture copies lib/jsonl-store.ts with the bin gstack-learnings-log imports $SCRIPT_DIR/../lib/jsonl-store.ts (hasInjection, v1.57.5.0) — copying only the bin scripts into the temp fixture broke the script with exit 1 since then. Latent because diff-based selection rarely runs this test; surfaced when hermetic-env.ts joined GLOBAL_TOUCHFILES and selected everything. Reproduced outside the hermetic env to confirm blame. Co-Authored-By: Claude Fable 5 <[email protected]> * fix: ios-qa daemon scenarios use unique pidfiles under --concurrent All scenarios shared join(workDir, 'daemon.pid') through a module-scope workDir binding that beforeEach reassigns mid-flight under bun --concurrent. First daemon claims; siblings get already_running against the test process's own always-alive pid and fail in milliseconds — the failure mode seen at 15-way gate concurrency. Per-claim unique pidfiles keep the single-instance semantics under test. Co-Authored-By: Claude Fable 5 <[email protected]> * fix: workflow judge re-appends body-carved sections after the marker slice runWorkflowJudge appended sections/*.md before slicing startMarker..endMarker. That handles skills that moved their MARKERS into sections (plan-eng, plan-design) but not document-release, which keeps its markers in the skeleton and carved the workflow BODY (Steps 2-9 -> sections/release-body.md) AFTER the endMarker — so the slice dropped it and the judge scored completeness 2 ('Steps 2-9 are in an external file'). Now any carved section the marker window excluded is re-appended, so the judge sees the full workflow the agent executes. document-release: completeness 2->5, clarity 3->4. ship/plan-ceo/plan-eng/plan-design judges unchanged (their section content is already inside the slice, so the head-dedup skips re-append). Pre-existing since the v1.57.0.0 carve (garrytan#1907); surfaced now because hermetic-env.ts is a global touchfile that selects every llm-judge test. Co-Authored-By: Claude Fable 5 <[email protected]> * harden: hermetic temp-dir GC grace window + half-seed cleanup Codex adversarial review (ship) flagged two temp-dir lifecycle edges: - GC deleted any dead-pid dir; PID reuse could delete a freshly-created dir whose original pid exited and was recycled to a live process. Now requires BOTH a dead pid AND mtime older than a 1h floor. - A seed-write failure after mkdir left an unseeded dir named with our live pid that this process's GC skips, leaking until exit. Now the partial dir is torn down before the (still loud) rethrow. Two findings left as-is by design: HOME stays allowlisted (CLAUDE_CONFIG_DIR wins for claude; codex/gemini need ~/.codex|~/.gemini auth; FS sandbox is TODOS.md:454 scope; the hermetic-sentinel canary proves config isolation), and PTY extraArgs --mcp-config is a deliberate caller opt-in like env overrides. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs: document hermetic-by-default E2E + eval:bg detached runs in CONTRIBUTING The Testing & evals section now tells contributors that local E2E runners spawn children through a sealed clean room (allowlist-scrubbed env, seeded CLAUDE_CONFIG_DIR, temp GSTACK_HOME, --strict-mcp-config) so local signal matches CI, with EVALS_HERMETIC=0 as the escape hatch. The eval-tools list gains the eval:bg* detached-run scripts (gstack-detach: SIGTERM-proof, caffeinate-wrapped, machine-locked, run-scoped logs, EXIT= sentinel). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * chore: sync package.json to 1.58.1.0 The merge took main's package.json (1.58.0.0); gstack-version-bump repair fixed the working tree but the change was left uncommitted. Without this the committed tree disagrees with VERSION and CI's version-match test fails. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs: regenerate diagram SKILL.md with Conductor prose preamble The diagram skill (new from main) was missing the Conductor-session prose AskUserQuestion blocks that gen-skill-docs propagates to every SKILL.md. Pure generated output; reproduced by bun run gen:skill-docs. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
anbangr
pushed a commit
that referenced
this pull request
Jun 29, 2026
* feat: Layer C stealth — chrome.*, Notification, per-install hardware, toString Proxy (gbrowser T1+T3+D6)
Three additions stacked into the existing applyStealth() init script
to close the visible automation tells that today push GBrowser users
into Google's /sorry/index captcha and similar:
T1 — Strip Playwright's automation default args:
--enable-automation (kills "Chrome is being
controlled" infobar)
--disable-popup-blocking, --disable-component-update,
--disable-default-apps (Patchright's list — each
is a documented tell)
Now centralized in STEALTH_IGNORE_DEFAULT_ARGS export, used by BOTH
launchHeaded() and handoff() (the headless → headed re-launch path).
D6 — Drop "GStackBrowser" UA branding suffix:
Real Chrome's UA ends `Safari/537.36`, not `Safari/537.36 GStackBrowser`.
The branded suffix was a high-entropy classifier for any vendor that
grep'd UA for known automation/test-browser strings. Branding still
lives in the wrapper .app name + Dock icon + tray — does not need
to leak via the UA string for the product to be "GBrowser." Resolves
the "looks like Chrome but identifies as GStackBrowser" contradiction
codex review #18 flagged.
T3 — Layer C init-script additions in stealth.ts:
1. Function.prototype.toString Proxy (must run first). Wraps every
patched getter / function in a WeakSet so they report
`function NAME() { [native code] }` at every recursion depth,
defeating the depth-3+ integrity check
(fn.toString.toString.toString().includes('[native code]')).
2. window.chrome.runtime / chrome.app / chrome.csi / chrome.loadTimes
restoration with full enum shape (OnInstalledReason, PlatformArch,
PlatformOs, etc.) + method bodies. Real Chrome ships these; their
absence is universally checked. Vendor research (gbrowser plan
deep-dive on Cloudflare + DataDome) confirmed both vendors probe
this shape directly.
3. Notification.permission aligned to 'default'. The existing inline
addInitScript already spoofs permissions.query({name:'notifications'})
to return 'prompt' — Notification.permission being 'denied' while
Permissions returns 'prompt' is a cross-source inconsistency that
detectors flag specifically.
4. Per-install hardware values via GSTACK_HW_CONCURRENCY /
GSTACK_DEVICE_MEMORY env vars (set by gbd's host_profile.go from
system_profiler + sysctl). Reporting real host values within the
Chrome shape avoids the cross-user GBrowser fingerprint cluster
that hardcoded defaults would create. Codex review #10 flagged
hardcoding as creating contradictions across Apple Silicon / Intel
/ UA-CH architecture.
5. Selenium 25-global cleanup + PhantomJS + NightmareJS + Watir +
Playwright (__pwInitScripts, __playwright__binding__) static-name
deletion. The inline block continues to handle the dynamic
cdc_/__webdriver/__selenium/__driver prefixes.
D7 (codex correction) kept: still do NOT fake navigator.plugins or
navigator.languages. Synthesizing those triggers MORE consistency
flags from modern fingerprinters than letting Chromium surface them
natively.
Test coverage:
- 15 new tests in stealth-layer-c.test.ts covering: launch-flag
exports, script structure, toString-Proxy installs first, every
spoof present, hardware values interpolated from input (not
hardcoded), Selenium global cleanup spot-check, no GStackBrowser
leak in stealth payload, backwards-compat exports preserved.
- All 8 existing stealth-webdriver tests still pass.
- All 2 existing browser-manager-unit tests still pass.
For GBrowser specifically: this is the gstack-side half of Phase 1 / T1
+ T3 + D6 in the anti-detection plan. The gbrowser repo's submodule
pointer bump will land alongside this.
* feat: buildGStackLaunchArgs — Pack 1 cmdline-switch construction for gbrowser
New stealth.ts export that turns the GSTACK_* env vars (already populated
by gbrowser's gbd from host_profile.go) into the --gstack-* cmdline
switches the Pack 1 Chromium patches read at WebGL getParameter,
NavigatorUA::userAgentData, NavigatorConcurrentHardware::hardwareConcurrency,
and NavigatorDeviceMemory::deviceMemory time.
Wired into all three launchArgs sites: launch() (headless), launchHeaded()
(real product path), and handoff() (headless → headed re-launch).
Mapping:
GSTACK_GPU_VENDOR → --gstack-gpu-vendor
GSTACK_GPU_RENDERER → --gstack-gpu-renderer
GSTACK_PLATFORM → --gstack-ua-platform (with mapping:
MacARM/MacIntel → macOS, Win32 → Windows,
Linux x86_64 → Linux)
GSTACK_GPU_CHIPSET → --gstack-ua-model
GSTACK_HW_CONCURRENCY → --gstack-hw-concurrency
GSTACK_DEVICE_MEMORY → --gstack-device-memory
Each switch is emitted only when its env var is non-empty — empty
values fall through to the patch's "no override" path, which returns
the real Chromium native value. Safe to ship on Chromium builds
without the Pack 1 patches applied (zero behavior change).
The patches themselves live in the gbrowser repo at chromium/patches/
{webgl-vendor-spoof,ua-client-hints-stealth,worker-navigator-stealth}.patch.
Both halves (gstack arg construction + gbrowser C++ patches) must
land + Chromium rebuild before the spoof reaches the WebGL/UA-CH/
hardware accessors. Currently dormant until then.
Tests (browse/test/stealth-layer-c.test.ts):
7 new buildGStackLaunchArgs cases — empty env, all-populated, partial,
platform mapping (MacARM/MacIntel/Win32/Linux), unrecognized platform
fallthrough, vendor-with-spaces escape-safety.
All 32 stealth/browser-manager tests pass.
For GBrowser specifically: gstack-side half of the Pack 1 flag plumbing.
gbrowser repo will bump the submodule pointer to this commit, then re-run
bun run test/anti-bot/evidence-run.ts to verify creepjs's "33% headless"
score drops after Pack 1 + Chromium rebuild.
* feat: buildGStackLaunchArgs adds --gstack-suppress-prepare-stack-trace
Pack 2 / B11 flag plumbing for the new
error-preparestacktrace-stealth.patch in gbrowser/chromium/patches/.
Always emit --gstack-suppress-prepare-stack-trace unless the caller
explicitly sets GSTACK_CDP_STEALTH=off in the environment. Off by
default in patch behavior (no-op without the C++ patch), so this is
safe on stock Playwright Chromium too.
Closes the Cloudflare canary trick where a page sets
Error.prepareStackTrace and watches for it to fire during CDP
serialization of a logged Error object.
Tests:
All 33 stealth/browser-manager tests pass. New cases:
- GSTACK_CDP_STEALTH=off disables suppression
- empty env still emits the always-on flag (count=1)
- all-populated env now emits 7 flags (was 6)
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* fix(browse): enable Chromium sandbox on headed launchPersistentContext
Mirrors v1.40.0.1 from main lineage (PR garrytan#1617). Cherry-picked onto
gbrowser-anti-detection so the GBrowser submodule can consume the fix
without waiting for main to merge.
Playwright auto-adds --no-sandbox whenever chromiumSandbox !== true
(playwright-core/lib/server/chromium/chromium.js:291-292). The headless
chromium.launch() site set the option; the two headed sites
(launchHeaded() and handoff()) did not. Every headed launch on macOS
and Linux showed Chromium's yellow "unsupported command-line flag:
--no-sandbox" infobar.
shouldEnableChromiumSandbox() centralizes the Win32 / CI / CONTAINER /
root heuristic that previously lived only in the headless path's
explicit --no-sandbox push at :225. All three launch sites now use the
helper, and six unit tests pin the policy across darwin, linux, win32,
CI, CONTAINER, and root.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* v1.40.0.2 fix(browse): Cmd+Q on managed Chromium stops triggering supervisor respawn
Three browser.on('disconnected') handlers in browse/src/browser-manager.ts
(launch, launchHeaded, handoff) each exited with a non-zero code on every
disconnect, regardless of cause. Process supervisors that consume our exit
code (gbrowser's gbd HealthMonitor in cmd/gbd/health.go) treated user
Cmd+Q identical to a Chromium crash and respawned with exponential
backoff, so the visible browser kept reappearing after the user closed it.
Add resolveDisconnectCause(browser) that reads the underlying ChildProcess
exitCode + signalCode (waiting up to 1s for the exit event if the
disconnected event fired first). Exit code 0 + no signal = clean user
quit; anything else = crash, signal-kill, or OOM.
Wire the resolver into all three disconnect handlers:
- launch() (headless): clean → exit 0, crash → exit 1 (was always 1)
- launchHeaded() (headed): clean → exit 0, crash → exit 2 (was always 2)
onDisconnect() cleanup callback still runs in both cases.
- handoff() (re-launch): same as launch() via the helper.
Preserve the per-path crash codes (1 vs 2) so any supervisor that
differentiated headed vs headless crashes keeps working.
Seven new unit tests in browse-manager-unit.test.ts cover the resolver
across already-exited, signal-killed (SIGSEGV / SIGKILL), async exits,
and null-browser inputs.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* fix(browse): apply stealth on every launch path + share automation-artifact cleanup
handoff() built cmdline args but never called applyStealth, so a handed-off
browser had no JS stealth (no webdriver mask, no chrome.* shape, no toString
proxy). And the cdc_/Permissions cleanup shim lived inline in launchHeaded()
only, so headless launch() reported Notification.permission='default' without
the matching permissions.query='prompt' answer — the exact cross-source
inconsistency the shim exists to prevent.
Move the cleanup into AUTOMATION_ARTIFACT_CLEANUP_SCRIPT inside applyStealth so
all three launch paths (launch, launchHeaded, handoff) get identical stealth,
and call applyStealth(newContext) in handoff() before restoreState() navigates.
A static tripwire in browser-manager-unit.test.ts fails CI if any launch path
drops the applyStealth call again.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* fix(browse): make --gstack-suppress-prepare-stack-trace opt-in, not default-on
buildGStackLaunchArgs() pushed the flag unless GSTACK_CDP_STEALTH=off, i.e.
on-by-default — contradicting its own comment ("off by default, only for
gbrowser builds"). The switch is read by a C++ patch that only exists in
gbrowser; on stock Playwright Chromium it is an unknown switch.
Flip to opt-in: emit only when GSTACK_CDP_STEALTH is on/1/true. gbd opts in by
exporting GSTACK_CDP_STEALTH=on; stock installs leave it unset so the flag
never reaches a Chromium that wouldn't understand it. Comment now matches code.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* docs(browse): correct stale stealth comments
The file-level stealth.ts docstring claimed "we DON'T fake navigator.plugins"
while the same file now ships EXTENDED_STEALTH_SCRIPT, which does fake plugins
when GSTACK_STEALTH=extended. Clarify that Layer C (the always-on default)
doesn't fake plugins and the opt-in extended mode does, as the documented
"actively lies, may break sites" escape hatch.
Also fix the launch()/launchHeaded() comments that said "mask navigator.webdriver
only" — applyStealth (Layer C) also restores window.chrome.*, aligns
Notification.permission, and sets per-install hardware.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* test(browse): runtime + extended-mode coverage for the stealth blend
The stealth tests were all static string-shape assertions; nothing executed
the script in a real page. Add real-Chromium runtime checks via applyStealth +
page.evaluate:
- Layer C runtime: window.chrome.* rich shape, Notification.permission='default'
paired with permissions.query notifications='prompt' (guards the shim now
running on every path), and patched getters reporting [native code].
- Per-install hardware: navigator.hardwareConcurrency/deviceMemory reflect the
GSTACK_* env profile.
- Extended-mode blend: navigator.plugins is faked when GSTACK_STEALTH=extended,
Layer C still wins window.chrome.runtime, and navigator.webdriver stays false
(own-prop getter survives extended's prototype delete).
- Persistent-context (launchHeaded/handoff) parity now uses a page created
AFTER applyStealth — the old test checked pages()[0], which predates the init
script, so webdriver was false only via the launch arg, not Layer C.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* fix(browse): handoff() + launchHeaded() spread the shared STEALTH_LAUNCH_ARGS
handoff() built its launch args from only ['--hide-crash-restore-bubble',
...buildGStackLaunchArgs()], omitting STEALTH_LAUNCH_ARGS — so a handed-off
browser kept the --disable-blink-features=AutomationControlled tell that
launch() and launchHeaded() strip. launchHeaded() also hardcoded the flag as a
literal. Both now spread the shared constant, so the AutomationControlled flag
lives in one place across all three launch paths.
Tripwires: STEALTH_LAUNCH_ARGS spread into >= 3 sites (no inline literal) and
STEALTH_IGNORE_DEFAULT_ARGS wired into both persistent-context paths.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* refactor(browse): drop dead HostProfile.platform, export test internals
HostProfile.platform was set by readHostProfile but never read by
buildStealthScript — the platform spoof is owned by the UA-CH cmdline switch in
buildGStackLaunchArgs (which reads GSTACK_PLATFORM directly). Remove the dead
field. Export readHostProfile and AUTOMATION_ARTIFACT_CLEANUP_SCRIPT so their
clamp/shape invariants can be unit-tested. Correct the stale "25 Selenium
globals" count comment and note the extended cdc_ scan is redundant-but-retained
for standalone use.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* test(browse): cover readHostProfile clamp, toString depth-3, chrome.* calls
Pre-landing review coverage gaps:
- readHostProfile clamps 0/negative/NaN/missing env to 8 (a deviceMemory=0 or
NaN would be a glaring bot tell) — now asserted.
- toString proxy survives the depth-3 recursion trick
(fn.toString.toString.toString().includes('[native code]')), the headline
claim that was only tested at depth-1.
- chrome.csi() and chrome.loadTimes() are invoked (not just typeof-checked) and
runtime.connect() throws the native-shaped "No matching signature" error.
- AUTOMATION_ARTIFACT_CLEANUP_SCRIPT static shape (cdc_/__webdriver strip +
notifications->prompt) as a hermetic backup for the live-Chromium pairing test.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* fix(browse): recreateContext() re-applies stealth (closes 4th un-stealth path)
useragent and viewport --scale route through recreateContext(), which rebuilds
the BrowserContext via newContext() — a fresh context with no init scripts. It
never called applyStealth, so a routine useragent/viewport-scale command
silently dropped webdriver masking, window.chrome.* shape, hardware spoof, and
the cdc/Permissions cleanup on every restored page. Caught by the cross-model
adversarial review (Codex) after the Claude pass and eng review missed it.
Both the main and fallback paths now call applyStealth before any page is
created. The launch-path tripwire is raised to >= 4 sites and now asserts the
recreateContext() body specifically, so the regression class can't recur.
Also documents the load-bearing trust assumption on buildGStackLaunchArgs /
readHostProfile (GSTACK_* must be gbd-sourced, never page/remote data — the
injection-safety argument depends on it) and the notifications-permission
spoof tradeoff.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* chore: bump version and changelog (v1.58.3.0)
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* docs: sync browser stealth docs to Layer C (v1.58.3.0)
BROWSER.md "Stealth scope" still described the default as navigator.webdriver
masking only; Layer C is now the always-on default across all four
context-creation paths. Update the stealth-scope prose, the "What GStack
Browser means" blurb (stock-Chrome UA, no GStackBrowser suffix, captchas can
still get through at the CDP layer), the stealth.ts source-map line, and the
env-vars table (GSTACK_STEALTH, GSTACK_CDP_STEALTH, GSTACK_GPU_*, GSTACK_PLATFORM,
GSTACK_HW_CONCURRENCY/GSTACK_DEVICE_MEMORY + the explicit --gstack-* switches and
ignoreDefaultArgs stripping). Correct the stale "narrows to navigator.webdriver
masking only" premise on the open CDP-patch TODO (the TODO itself stays open —
the CDP-protocol layer is still unaddressed).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.
Summary
Adds a focused verification path for
/buildchanges:bun run test:build-skillfor deterministic build-skill checks.bin/gstack-build --help.build-skill-cli-handofftest that verifies/buildhands off toGSTACK_BUILD_CLIwith the plan path and--project-root.AGENTS.mdand bumps tov1.26.5.0.Test Coverage
This PR is test and workflow coverage only. New coverage added:
build/orchestrator/__tests__/skill-md.test.tschecks CLI resolver contracts and wrapper help output.build/orchestrator/__tests__/integration.test.tsadds deterministic dry-run coverage.test/skill-e2e-build.test.tsadds the optional live handoff check.test/helpers/touchfiles.tsmetadata coverage is validated bytest/touchfiles.test.ts.Coverage gate: not applicable to application code changes.
Pre-Landing Review
Pre-Landing Review: No issues found.
Design Review
No frontend files changed — design review skipped.
Eval Results
No prompt-related runtime behavior changed — paid evals skipped. The optional live E2E is periodic/on-demand and was syntax/metadata checked without
EVALS=1.Scope Drift
Scope Check: CLEAN
Intent: add repeatable test-run coverage for
/buildskill updates.Delivered: focused deterministic gate, dry-run cases, optional live CLI handoff E2E, E2E touchfile metadata, and command docs.
Plan Completion
All requested plan items addressed except the optional paid live E2E execution, which remains on-demand by design.
Verification Results
bun run test:build-skill— 467 pass, 0 fail.bun test test/touchfiles.test.ts test/skill-e2e-build.test.ts— 23 pass, 3 skipped, 0 fail.git diff --check— pass.bun testwas also run before the version/docs amend; output showed passing tests through the free suite, with paid/live E2E tests skipped.TODOS
No TODO items completed in this PR.
Documentation
bun run test:build-skillto theAGENTS.mdbuild commands list.v1.26.5.0CHANGELOG entry.Test plan
1.26.5.0.🤖 Generated with Claude Code