fix: stabilize review eval evidence and harness repair guidance

This commit is contained in:
Garry Tan committed 2026-09-11 06:36:49 +00:00
1 parent d4b1675be9
commit d57866a656
39 files changed
+759 -154

No files matched your search

+2 -2
View File
@@ -55,10 +55,10 @@ IMPORTANT: Do NOT read or execute any SKILL.md files or paths containing skills/
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+2 -2
View File
@@ -52,10 +52,10 @@ IMPORTANT: Do NOT read or execute any SKILL.md files or paths containing skills/
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+2 -2
View File
@@ -56,10 +56,10 @@ IMPORTANT: Do NOT read or execute any SKILL.md files or paths containing skills/
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+2 -2
View File
@@ -45,10 +45,10 @@ IMPORTANT: Do NOT read or execute any SKILL.md files or paths containing skills/
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+2 -2
View File
@@ -522,10 +522,10 @@ check the requested model, including when the frontier default is unavailable.
_TEL=$(~/.claude/skills/gstack/bin/gstack-config get telemetry 2>/dev/null || echo off)
source ~/.claude/skills/gstack/bin/gstack-codex-probe
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+4 -4
View File
@@ -853,10 +853,10 @@ If user chooses B, record one declined result as described below, skip both voic
_OUTSIDE_CFG=enabled # This caller has its own opt-in/skip control.
if [ "$_OUTSIDE_CFG" = disabled ]; then
echo 'CODEX_MODE: disabled'
elif ( # GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
elif ( # GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -895,10 +895,10 @@ End with Recommendation: <direction> because <product-specific reason>."
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a complete design proposal ending with Recommendation: <direction> because <product-specific reason>. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+4 -4
View File
@@ -1614,10 +1614,10 @@ Record baseline design score and AI slop score at end of Phase 6.
_OUTSIDE_CFG=enabled # This caller has its own opt-in/skip control.
if [ "$_OUTSIDE_CFG" = disabled ]; then
echo 'CODEX_MODE: disabled'
elif ( # GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
elif ( # GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -1675,10 +1675,10 @@ Be specific. Reference file:line for every finding."
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+8
View File
@@ -191,6 +191,14 @@ calibration or statistical upper bound. The historical 900-second failures
remain failures. Models, fixtures, phase assertions and production review
caller timeouts are unchanged; this explicitly changes eval latency/cost policy.
The Autoplan chain explicitly enables native `PreToolUse` approval for edits to
its owned temporary review artifacts. Approval starts with the `/autoplan`
command and requires the exact parent session, prior successful file history,
and a current request digest. Other recorder callers remain observational.
A rejected artifact edit fails the test instead of falling through to terminal
permission input. Approval itself supplies no edit success or phase credit:
the native tool result and all four completed review phases are still required.
`resolvePaidShardBudget(files, overrideMs?)` is the canonical per-job resolver.
Only the exact Autoplan file gets the exception, in its own shard. An explicit
CLI `--timeout`, `EVALS_SHARD_TIMEOUT_MS`, or API `timeoutMs` still wins, including
+2 -2
View File
@@ -301,10 +301,10 @@ THE DOCS AND DIFF: <include current contents of each touched document, with its
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+8 -8
View File
@@ -777,10 +777,10 @@ Use AskUserQuestion to confirm. If the user disagrees with a premise, revise und
_OUTSIDE_CFG=enabled # This caller has its own opt-in/skip control.
if [ "$_OUTSIDE_CFG" = disabled ]; then
echo 'CODEX_MODE: disabled'
elif ( # GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
elif ( # GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -833,10 +833,10 @@ Then add the context block and mode-appropriate instructions:
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -1109,10 +1109,10 @@ After the wireframe is approved, offer outside design perspectives:
_OUTSIDE_CFG=enabled # This caller has its own opt-in/skip control.
if [ "$_OUTSIDE_CFG" = disabled ]; then
echo 'CODEX_MODE: disabled'
elif ( # GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
elif ( # GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -1142,10 +1142,10 @@ Prompt: "For this product approach, provide: a visual thesis (one sentence — m
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a complete design proposal ending with Recommendation: <direction> because <product-specific reason>. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+2 -2
View File
@@ -422,10 +422,10 @@ THE PLAN:
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+4 -4
View File
@@ -980,10 +980,10 @@ If user chooses B, skip this step and continue.
_OUTSIDE_CFG=enabled # This caller has its own opt-in/skip control.
if [ "$_OUTSIDE_CFG" = disabled ]; then
echo 'CODEX_MODE: disabled'
elif ( # GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
elif ( # GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -1037,10 +1037,10 @@ For each finding: what's wrong, what will happen if it ships unresolved, and the
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -346,10 +346,10 @@ THE PLAN:
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+2 -2
View File
@@ -451,10 +451,10 @@ THE PLAN:
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+4 -4
View File
@@ -99,10 +99,10 @@ Outside prompt (supply repository context from the parent):
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -158,10 +158,10 @@ Prepare a structured review prompt requesting severity-tagged findings ([P1], [P
Run Codex’s built-in structured review with the selected base. It supplies its own prompt and accepts no custom prompt file with --base. Require severity-tagged findings (including native P1:/P2: labels) or an explicit no-findings conclusion; arbitrary prose or a refusal is missing coverage.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+2 -2
View File
@@ -54,10 +54,10 @@ export function outsideVoiceGuard(ctx: TemplateContext): string {
? '[ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]'
: '[ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]';
const repair = v.id === 'codex' ? 'codex' : 'claude';
return `# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
return `# GSTACK_ACTIVE_HOST names the harness, never the model.
if { ${own}; }; then
echo '${v.label} outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "\${CLAUDECODE:-}" ] && { [ -n "\${CODEX_THREAD_ID:-}" ] || [ -n "\${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "\${CLAUDECODE:-}" ] || [ "\${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "\${CODEX_THREAD_ID:-}" ] || [ -n "\${CODEX_SANDBOX:-}" ] || [ "\${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host ${repair} from your gstack checkout.' >&2
+4 -4
View File
@@ -99,10 +99,10 @@ Outside prompt (supply repository context from the parent):
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -158,10 +158,10 @@ Prepare a structured review prompt requesting severity-tagged findings ([P1], [P
Run Codex’s built-in structured review with the selected base. It supplies its own prompt and accepts no custom prompt file with --base. Require severity-tagged findings (including native P1:/P2: labels) or an explicit no-findings conclusion; arbitrary prose or a refusal is missing coverage.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+4 -4
View File
@@ -128,10 +128,10 @@ Substitute: TIMESTAMP = ISO 8601 datetime, STATUS = "clean" if 0 findings or "is
_OUTSIDE_CFG=enabled # This caller has its own opt-in/skip control.
if [ "$_OUTSIDE_CFG" = disabled ]; then
echo 'CODEX_MODE: disabled'
elif ( # GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
elif ( # GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -154,10 +154,10 @@ Prompt: "Review the git diff on this branch. Run 7 litmus checks (YES/NO each):
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+4 -4
View File
@@ -118,10 +118,10 @@ dispatch. `spec-quality-gate-secret-sink.test.ts` enforces this.
_OUTSIDE_CFG=enabled # This caller has its own opt-in/skip control.
if [ "$_OUTSIDE_CFG" = disabled ]; then
echo 'CODEX_MODE: disabled'
elif ( # GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
elif ( # GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -147,10 +147,10 @@ Write the prompt with the exact redaction-approved spec bytes using the Write to
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request exactly SCORE: N (integer 0-10) and AMBIGUITIES: ... (or NONE), as two distinct nonempty lines. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+130 -3
View File
@@ -4,13 +4,13 @@ import * as os from 'node:os';
import * as path from 'node:path';
import { spawnSync } from 'node:child_process';
import { createAutoplanArtifactRecorder, recordAutoplanArtifact, readPendingAutoplanArtifact,
autoplanArtifactRecorderStatus } from './helpers/autoplan-artifact-recorder';
autoplanArtifactRecorderStatus, autoplanArtifactApprovalBoundary } from './helpers/autoplan-artifact-recorder';
import type { NativePublicToolEvent } from './helpers/plan-count-transcript';
import { E2E_TOUCHFILES, selectTests } from './helpers/touchfiles';
// Synthetic hook envelopes and owned temp paths. The live pending hook envelope
// was unpublished; these controls do not reconstruct it or provide paid coverage.
function fixture() {
function fixture(approveEdits=false) {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "artifact-' quote $()-"));
const cwd = path.join(root, 'repo with spaces'), config = path.join(root, 'config');
const stateRoot = path.join(root, 'home', '.gstack');
@@ -22,7 +22,7 @@ function fixture() {
const artifact = path.join(plans, '2026-09-09-reviewed-plan.md');
fs.writeFileSync(artifact, 'Prior retained behavior.\n');
const startedAt = Date.now()-10;
const recorder = createAutoplanArtifactRecorder(cwd,config,stateRoot);
const recorder = createAutoplanArtifactRecorder(cwd,config,stateRoot,approveEdits);
const event = (kind='PreToolUse',toolUseId='toolu_pending') => ({hook_event_name:kind,tool_name:'Edit',
session_id:session,tool_use_id:toolUseId,cwd,transcript_path:transcript,
tool_input:{file_path:artifact,old_string:'BODY_OLD_SENTINEL',new_string:'BODY_NEW_SENTINEL'}});
@@ -170,3 +170,130 @@ describe('owned Autoplan pending artifact metadata recorder',()=>{
expect(selectTests([file],E2E_TOUCHFILES,[]).selected).toEqual(['autoplan-chain-pty']);
});
});
// Real hook subprocesses and the public JSONL reader; no synthetic phase success
// and no reconstruction of the unpublished paid request.
function approvalFixture(approve=true, activate=true) {
const f=fixture(approve), startedAt=Date.now();
if (approve && activate) f.recorder.startEditApproval!(startedAt);
const event=f.event();event.tool_input.old_string='Prior retained behavior.';event.tool_input.new_string='Reviewed retained behavior.';
const records:any[]=[
{message:{role:'assistant',id:'msg_prior',content:[{type:'tool_use',id:'toolu_prior',name:'Write',input:{file_path:f.artifact}}]}},
{message:{role:'user',content:[{type:'tool_result',tool_use_id:'toolu_prior',is_error:false,content:'Written'}]}},
].map(record=>({cwd:f.cwd,sessionId:f.session,isSidechain:false,timestamp:new Date(startedAt).toISOString(),...record}));
const publish=()=>fs.writeFileSync(f.transcript,records.map(record=>JSON.stringify(record)+'\n').join(''));
const current=()=>({cwd:f.cwd,sessionId:f.session,isSidechain:false,timestamp:new Date(startedAt).toISOString(),requestId:'req_current',
message:{role:'assistant',id:'msg_current',content:[{type:'tool_use',id:event.tool_use_id,name:'Edit',input:{...event.tool_input}}]}});
const invoke=(input:unknown=event)=>{
const child=spawnSync('bash',['-c',f.recorder.hooks.PreToolUse[0]!.hooks[0]!.command],
{cwd:f.cwd,input:JSON.stringify(input),encoding:'utf8',timeout:6000});
expect(child.error).toBeUndefined();expect(child.status).toBe(0);expect(child.stderr).toBe('');
return child.stdout ? JSON.parse(child.stdout) : undefined;
};
publish();return {...f,startedAt,event,records,publish,current,invoke};
}
describe('explicit native approval for owned Autoplan artifact Edits',()=>{
test.each(['unpublished','published','eng-artifact'])('%s approves once without changing bytes, JSONL or phase evidence',kind=>{
const f=approvalFixture();try{
if(kind==='eng-artifact'){
f.event.tool_input.file_path=path.join(path.dirname(path.dirname(f.artifact)),'branch-test-plan-20260911-055000.md');
fs.writeFileSync(f.event.tool_input.file_path,fs.readFileSync(f.artifact));
f.records[0].message.content[0].input.file_path=f.event.tool_input.file_path;
}
if(kind==='published')f.records.push(f.current());
f.publish();const journal=fs.readFileSync(f.transcript,'utf8'),before=fs.readFileSync(f.event.tool_input.file_path,'utf8');
expect(f.invoke()).toEqual({hookSpecificOutput:{hookEventName:'PreToolUse',permissionDecision:'allow'}});
const state=fs.readFileSync(f.recorder.file,'utf8');
expect(JSON.parse(state).pending.editDigest).toBeDefined();expect(JSON.parse(state).seenIds).toEqual([f.event.tool_use_id]);
for(const body of [f.event.tool_input.old_string,f.event.tool_input.new_string,'tool_response'])expect(state).not.toContain(body);
expect(f.invoke()).toBeUndefined();expect(fs.readFileSync(f.recorder.file,'utf8')).toBe(state);
expect(f.invoke({...f.event,hook_event_name:'PostToolUse',tool_response:'Not native history'})).toBeUndefined();
expect(f.status().status).toBe('idle');expect(f.invoke()).toBeUndefined();
expect(fs.readFileSync(f.event.tool_input.file_path,'utf8')).toBe(before);expect(fs.readFileSync(f.transcript,'utf8')).toBe(journal);
}finally{f.dispose()}
});
test.each(['passive','not-started'])('%s remains silent even for a valid owned Edit',kind=>{
const f=approvalFixture(kind!=='passive',false);try{expect(f.invoke()).toBeUndefined()}finally{f.dispose()}
});
test.each(['no-history','old-history','failed-write','unresolved-write','concurrent-edit','foreign-mutation','duplicate-use',
'completed-current','conflicting-current','foreign-session','subagent-history','agent-id-history','other-journal-history','future-history','wrong-cwd','subagent',
'wrong-session','foreign-transcript','missing-old','duplicate-old','future-mtime','replace-all','Write','Bash',
'snapshot','config','native-plan','foreign-file','symlink','locked'])('%s cannot grant a native decision',kind=>{
const f=approvalFixture();try{
const e=f.event as Record<string,any>;
if(kind==='no-history')f.records.length=0;
if(kind==='old-history')f.records.forEach(r=>r.timestamp=new Date(f.startedAt-1).toISOString());
if(kind==='failed-write')f.records[1].message.content[0].is_error=true;
if(kind==='unresolved-write')f.records.pop();
if(kind==='concurrent-edit'||kind==='foreign-mutation'){
const other=f.current();other.message.content[0].id='toolu_conflict';
if(kind==='foreign-mutation')other.message.content[0].input.file_path=path.join(f.stateRoot,'config');
f.records.push(other);
}
if(kind==='duplicate-use')f.records.splice(1,0,f.records[0]);
if(kind==='completed-current')f.records.push(f.current(),{...f.records[1],message:{role:'user',content:[{type:'tool_result',tool_use_id:e.tool_use_id,is_error:false}]}});
if(kind==='conflicting-current'){const current=f.current();current.message.content[0].input.new_string='Different request';f.records.push(current)}
if(kind==='foreign-session')f.records.forEach(r=>r.sessionId='another-parent');
if(kind==='subagent-history')f.records.forEach(r=>r.isSidechain=true);
if(kind==='agent-id-history')f.records.forEach(r=>r.agentId='child-agent');
if(kind==='other-journal-history'){const other=path.join(f.config,'projects','other',f.session+'.jsonl');fs.mkdirSync(path.dirname(other));fs.writeFileSync(other,fs.readFileSync(f.transcript));f.records.length=0;}
if(kind==='future-history')f.records.forEach(r=>r.timestamp=new Date(Date.now()+10000).toISOString());
if(kind==='wrong-cwd')e.cwd=path.join(f.root,'other');
if(kind==='subagent')e.agent_id='child';
if(kind==='wrong-session'){e.session_id='another-parent';e.transcript_path=path.join(f.project,e.session_id+'.jsonl');fs.writeFileSync(e.transcript_path,'')}
if(kind==='foreign-transcript'){e.transcript_path=path.join(f.root,f.session+'.jsonl');fs.writeFileSync(e.transcript_path,'')}
if(kind==='missing-old')e.tool_input.old_string='Absent text';
if(kind==='duplicate-old')fs.writeFileSync(f.artifact,'Prior retained behavior. Prior retained behavior.');
if(kind==='future-mtime')fs.utimesSync(f.artifact,new Date(),new Date(Date.now()+10000));
if(kind==='replace-all')e.tool_input.replace_all=true;
if(kind==='Write'||kind==='Bash')e.tool_name=kind;
if(['snapshot','config','native-plan','foreign-file'].includes(kind)){
e.tool_input.file_path=kind==='snapshot'?path.join(path.dirname(f.artifact),'snapshot.md'):
kind==='config'?path.join(f.stateRoot,'config'):kind==='native-plan'?path.join(f.config,'plans','owned-plan.md'):path.join(f.root,'foreign.md');
fs.mkdirSync(path.dirname(e.tool_input.file_path),{recursive:true});fs.writeFileSync(e.tool_input.file_path,'Prior retained behavior.');
f.records[0].message.content[0].input.file_path=e.tool_input.file_path;
}
if(kind==='symlink'){fs.renameSync(f.artifact,f.artifact+'.original');fs.symlinkSync(f.artifact+'.original',f.artifact)}
if(kind==='locked')fs.writeFileSync(f.recorder.file+'.lock','');
f.publish();expect(f.invoke()).toBeUndefined();
}finally{f.dispose()}
});
test('rejected owned Edit stops before UI fallback; initial Write leaves unrelated navigation available',()=>{
const f=approvalFixture();try{
expect(f.invoke({...f.event,tool_name:'Write'})).toBeUndefined();
expect(autoplanArtifactApprovalBoundary(f.status())).toBe('clear');
f.records[1].message.content[0].is_error=true;f.publish();
expect(f.invoke()).toBeUndefined();
expect(f.status()).toEqual({status:'invalid',reason:'approval_withheld'});
expect(autoplanArtifactApprovalBoundary(f.status())).toBe('failed');
// The failed route is sticky across repeated hooks and cannot send UI input.
expect(f.invoke()).toBeUndefined();expect(autoplanArtifactApprovalBoundary(f.status())).toBe('failed');
const retained=JSON.parse(fs.readFileSync(f.recorder.file,'utf8'));
expect(retained.pending.toolUseId).toBe(f.event.tool_use_id);
}finally{f.dispose()}
const g=approvalFixture();try{
expect(g.invoke()?.hookSpecificOutput.permissionDecision).toBe('allow');
expect(autoplanArtifactApprovalBoundary(g.status())).toBe('pending');
expect(g.invoke({...g.event,hook_event_name:'PostToolUse'})).toBeUndefined();
expect(autoplanArtifactApprovalBoundary(g.status())).toBe('clear');
}finally{g.dispose()}
});
test('changed replay cannot refresh approval; completion hooks cannot fabricate required history',()=>{
const f=approvalFixture();try{
expect(f.invoke()?.hookSpecificOutput.permissionDecision).toBe('allow');
fs.writeFileSync(f.artifact,'Changed bytes.');expect(f.invoke()).toBeUndefined();expect(f.status().status).toBe('invalid');
}finally{f.dispose()}
const g=approvalFixture();try{
g.records.length=0;g.publish();expect(g.invoke()).toBeUndefined();
expect(g.invoke({...g.event,hook_event_name:'PostToolUse',tool_response:{success:true}})).toBeUndefined();
g.event.tool_use_id='toolu_next';expect(g.invoke()).toBeUndefined();
}finally{g.dispose()}
});
test.each(['repeat','future','before-recorder'])('invalid %s activation fails closed',kind=>{
const f=approvalFixture(true,kind==='repeat');try{
const started=kind==='future'?Date.now()+10000:kind==='before-recorder'?f.startedAt-10000:f.startedAt;
expect(()=>f.recorder.startEditApproval!(started)).toThrow();expect(f.invoke()).toBeUndefined();
}finally{f.dispose()}
});
});
+8 -4
View File
@@ -153,29 +153,33 @@ if(process.env.ARTIFACT_FAIL==='1')process.exit(19);
process.stdout.write('ARTIFACT_READY\n');process.stdin.resume();
`,{mode:0o755});
const runner=pathToFileURL(path.join(import.meta.dir,'helpers/claude-pty-runner.ts')).href;
for(const variant of ['enabled','disabled','explicit-home','explicit-config','early-exit']){
for(const variant of ['enabled','approval','disabled','explicit-home','explicit-config','early-exit']){
const cwd=path.join(root,variant);fs.mkdirSync(cwd);const result=path.join(cwd,'result.json');
const extra=variant==='explicit-home'?{HOME:cwd}:variant==='explicit-config'?{CLAUDE_CONFIG_DIR:cwd}:{};
const worker=path.join(cwd,'worker.ts');fs.writeFileSync(worker,`
import * as fs from 'node:fs';
import {launchClaudePty,resolveClaudeBinary} from ${JSON.stringify(runner)};
if(resolveClaudeBinary()!==${JSON.stringify(fake)})throw Error('fake binding');
const session=await launchClaudePty({cwd:${JSON.stringify(cwd)},seedSkills:true,observeAutoplanArtifacts:${variant!=='disabled'},timeoutMs:8000,
const session=await launchClaudePty({cwd:${JSON.stringify(cwd)},seedSkills:true,observeAutoplanArtifacts:${variant!=='disabled'},approveAutoplanArtifactEdits:${variant==='approval'||variant.startsWith('explicit-')},timeoutMs:8000,
env:${JSON.stringify({...extra,ARTIFACT_RECORD:result,ARTIFACT_FAIL:variant==='early-exit'?'1':'0'})}});
try {try{await session.waitFor('ARTIFACT_READY',{timeoutMs:2000,pollMs:20});}catch(e){if(${variant!=='early-exit'})throw e;}
const r=JSON.parse(fs.readFileSync(${JSON.stringify(result)},'utf8'));
r.file=session.pendingAutoplanArtifactFile??null;r.stateRoot=session.hermeticSkillStateRoot??null;
r.canStart=typeof session.startAutoplanArtifactEditApproval==='function';
if(${variant==='approval'}){const start=Date.now();session.startAutoplanArtifactEditApproval(start);r.started=JSON.parse(fs.readFileSync(r.file,'utf8')).approvalStartedAt===start;}
r.exists=r.file?fs.existsSync(r.file):false;fs.writeFileSync(${JSON.stringify(result)},JSON.stringify(r));
} finally {await session.close();}
`);
const child=Bun.spawn([process.execPath,worker],{env:{...process.env,BROWSE_TERMINAL_BINARY:fake,EVALS_HERMETIC:'1'},stdout:'pipe',stderr:'pipe'});
const timer=setTimeout(()=>child.kill('SIGKILL'),15000);
try{const [code,out,err]=await Promise.all([child.exited,new Response(child.stdout).text(),new Response(child.stderr).text()]);expect(code,out+err).toBe(0);}finally{clearTimeout(timer);}
const resultData=JSON.parse(fs.readFileSync(result,'utf8')),enabled=['enabled','early-exit'].includes(variant);
const resultData=JSON.parse(fs.readFileSync(result,'utf8')),enabled=['enabled','approval','early-exit'].includes(variant);
expect(resultData.canStart).toBe(variant==='approval');
if(variant==='approval')expect(resultData.started).toBe(true);
expect(Boolean(resultData.file)).toBe(enabled);expect(resultData.exists).toBe(enabled);
if(enabled){const settings=JSON.parse(resultData.args[resultData.args.indexOf('--settings')+1]);
expect(Object.keys(settings.hooks).sort()).toEqual(['PostToolUse','PostToolUseFailure','PreToolUse']);
for(const entries of Object.values(settings.hooks) as any[]){expect(entries).toHaveLength(1);expect(entries[0].matcher).toBe('^(Write|Edit)$');expect(entries[0].hooks[0].timeout).toBe(5);expect(entries[0].hooks[0].command).toContain(resultData.stateRoot);}
for(const entries of Object.values(settings.hooks) as any[]){expect(entries).toHaveLength(1);expect(entries[0].matcher).toBe('^(Write|Edit)$');expect(entries[0].hooks[0].timeout).toBe(5);expect(entries[0].hooks[0].command).toContain(resultData.stateRoot);expect(entries[0].hooks[0].command.includes('--approve-edits')).toBe(variant==='approval');}
expect(fs.existsSync(resultData.file)).toBe(false);
}else expect(resultData.args).not.toContain('--settings');
expect(()=>process.kill(resultData.pid,0)).toThrow();
+70
View File
@@ -184,6 +184,19 @@ describe('A descriptive hierarchy header owns its primary and peer controls', ()
c.answers = {[q.question]: q.options[0]!.label};
return c;
};
// A current property assessment and primary/secondary roles do not depend
// on one captured label, palette, or control name.
const properties = (): NativePlanQuestionCall => {
const c = first(), q = c.questions[0]!;
q.header = 'Issue 1';
q.question = q.question.replace('all four header buttons look identical', 'the four header buttons are the same size, weight and color');
q.options = [
{label: '1A Apply DESIGN.md styles (recommended)', description: 'Save is the only filled #1d4ed8 button with white text; Reset, Cancel, Export are neutral ghost buttons. Geometry and states unchanged.'},
{label: '1B Leave unchanged', description: 'No change; finding stays open and lowers the score.'},
];
c.answers = {[q.question]: q.options[0]!.label};
return c;
};
const edit = (change: (c: NativePlanQuestionCall) => void, source = first) => {
const c = source(); change(c);
if (c.answers && Object.keys(c.answers).length) c.answers = {[c.questions[0]!.question]: c.questions[0]!.options[0]!.label};
@@ -208,6 +221,63 @@ describe('A descriptive hierarchy header owns its primary and peer controls', ()
q.options.reverse();
}))).toBe(true);
});
test('equal visual properties bind concrete primary and secondary roles for any offered answer', () => {
const c = properties(), q = c.questions[0]!;
for (const o of q.options) {
c.answers = {[q.question]: o.label};
expect(isDesignCountFirstReview(fingerprint(c))).toBe(true);
}
for (const propertyList of ['fill and emphasis', 'colour, weight', 'weight']) {
expect(isDesignCountFirstReview(edit(c => {
c.questions[0]!.question = c.questions[0]!.question.replace('size, weight and color', propertyList);
}, properties))).toBe(true);
}
expect(isDesignCountFirstReview(edit(c => {
const q = c.questions[0]!;
q.question = q.question.replaceAll('Save', 'Publish').replace('the four', 'the 4');
q.options[0] = {label: '1A Reuse existing component roles', description: 'Publish becomes the single filled primary #ffee22 button with black text; Export/Reset/Cancel become neutral ghost buttons. Matches DESIGN.md exactly.'};
q.options[1]!.description = 'This issue remains unresolved.';
}, properties))).toBe(true);
expect(isDesignCountFirstReview(edit(c => {
c.questions[0]!.question += ' "This finding is historical."';
c.questions[0]!.options[0]!.description += ' "This amendment applies only to another project."';
}, properties))).toBe(true);
});
test('property evidence preserves currentness, authority and ownership within each native option', () => {
const mutations: Array<(q: NativePlanQuestionCall['questions'][number]) => void> = [
q => {q.question = q.question.replace('size, weight and color', 'size');},
q => {q.question = q.question.replace('are the same', 'are not the same');},
q => {q.question = q.question.replace('the four', 'the three');},
q => {q.question = q.question.replace('ELI10:', '> ELI10:');},
q => {q.question += '\nELI10: Right now the four header buttons are the same color.';},
q => {q.question += ' This finding is historical.';},
q => {q.question += ' This finding applies only to another project.';},
q => {q.options[0]!.description = q.options[0]!.description!.replace('Save is', 'Reset is');},
q => {q.options[0]!.description = q.options[0]!.description!.replace('Export are', 'Archive are');},
q => {q.options[0]!.description = q.options[0]!.description!.replace('Reset, Cancel, Export', 'Save, Cancel, Export');},
q => {q.options[0]!.description = q.options[0]!.description!.replace('Reset, Cancel, Export', 'Reset, Cancel, Cancel');},
q => {q.options[0]!.description = q.options[0]!.description!.replace('#1d4ed8', 'blue');},
q => {q.options[0]!.description = q.options[0]!.description!.replace('neutral ghost', 'filled primary');},
q => {q.options[0]!.label = '1A DESIGN.md primary Reset';},
q => {q.options[0]!.label = '1A Apply styles';},
q => {q.options[0]!.label = '1A Apply styles'; q.options[1]!.label = '1B Leave DESIGN.md styles unchanged';},
q => {q.options[0]!.label += ' only if approval is granted';},
q => {q.options[0]!.description += ' This amendment is withdrawn.';},
q => {q.options[0]!.description += ' This amendment keeps all four header buttons identical.';},
q => {q.options[1]!.description = 'No change; finding is closed.';},
q => {q.options[1]!.description += ' This option is historical.';},
q => {q.options[1]!.description += ' This amendment applies only to another project.';},
q => {q.options[1]!.description += ' This finding stays open only if approved.';},
];
for (const mutate of mutations) {
expect(isDesignCountFirstReview(edit(c => mutate(c.questions[0]!), properties)), mutate.toString()).toBe(false);
}
for (const mutate of [
(c: NativePlanQuestionCall) => {c.answered = false;},
(c: NativePlanQuestionCall) => {c.failed = true;},
(c: NativePlanQuestionCall) => {c.unansweredQuestionIndices = [0];},
]) expect(isDesignCountFirstReview(edit(mutate, properties))).toBe(false);
});
test('retry stand-out wording binds existing variants and an owned open hierarchy gap', () => {
const c = retry(), q = c.questions[0]!;
for (const option of q.options) {
+50
View File
@@ -12,6 +12,56 @@ import { E2E_TOUCHFILES, matchGlob } from './helpers/touchfiles';
const call = () => structuredClone(actual.fingerprint.nativeCall) as NativePlanQuestionCall;
const fp = (c = call()) => nativePlanCallFingerprint(c, 0, false);
const accepts = (c = call(), plan = actual.plan) => isEngCompletionHandoff(fp(c), plan);
function maintenanceRecap() {
const make = (id: string, header: string, text: string, selected: string, description: string): NativePlanQuestionCall => ({
sessionId:'maintenance-session', toolUseId:id, questions:[{header,question:text,multiSelect:false,
options:[{label:selected,description},{label:'Skip',description:'Do not approve this action.'}]}],
answered:true, failed:false, answers:{[text]:selected}, unansweredQuestionIndices:[], answeredAt:'2026-09-11T00:00:01Z',
});
const routing = make('routing','Routing',"Add gstack skill routing rules to CLAUDE.md?",'Add routing rules to CLAUDE.md (recommended)','Append the routing rules after review.');
const policy = make('policy','TODO 1','D7 — TODO 1: RetryPolicy needs a follow-up.','7A) Add to TODOS.md (recommended)',"Captured in the plan's TODOS section now; write it after exit.");
const cleanup = make('cleanup','TODO 2','D8 — TODO 2: Remove LegacyBridge after rollout.','8A) Add to TODOS.md (recommended)',"Captured in the plan's TODOS section now; write it after exit.");
const next = make('next','Next step','D9 — Next steps. Eng review is CLEARED. There is no UI scope. CEO review is optional. What next?',
'Ready to implement — run /ship when done (recommended)','Exit plan mode with the reviewed plan. Post-exit: append routing rules to CLAUDE.md and create TODOS.md with the two accepted items.');
next.answeredAt='2026-09-11T00:00:02Z'; next.questions[0]!.options[1]={label:'Run /plan-ceo-review',description:'Optional strategy review.'};
return {next, prior:[routing,policy,cleanup], plan:'## TODOS\n### Revisit RetryPolicy\nAn approved follow-up.\n### Remove LegacyBridge\nAfter rollout.\n## Implementation Tasks\n'};
}
test('completed navigation can recap earlier approved routing and published TODOs', () => {
const a=maintenanceRecap(), check=(x= a)=>isEngCompletionHandoff(fp(x.next),x.plan,x.prior);
expect(check()).toBe(true);
const renamed=structuredClone(a); renamed.plan=renamed.plan.replaceAll('RetryPolicy','TenantPolicy');
question(renamed.prior[1]!,s=>s.replaceAll('RetryPolicy','TenantPolicy')); expect(check(renamed)).toBe(true);
const reworded=structuredClone(a);question(reworded.next,s=>s.replace('D9 — Next steps. Eng review is CLEARED','D14: Next step: Engineering review is complete'));
reworded.next.questions[0]!.header='Next steps';reworded.next.questions[0]!.options[0]!.description='Exit plan mode with the reviewed plan. After exiting: write TODOS.md with 2 accepted items; add gstack routing rules to CLAUDE.md.';
expect(check(reworded)).toBe(true);
const batched=structuredClone(a);batched.prior[1]!.questions.push(...batched.prior[2]!.questions);
Object.assign(batched.prior[1]!.answers,batched.prior[2]!.answers);batched.prior.pop();expect(check(batched)).toBe(true);
for(const mutate of [
(x:typeof a)=>{x.prior.shift();},
(x:typeof a)=>{x.prior[0]!.sessionId='foreign';},
(x:typeof a)=>{x.prior[0]!.failed=true;},
(x:typeof a)=>{x.prior[0]!.answeredAt=x.next.answeredAt;},
(x:typeof a)=>{x.prior[0]!.unansweredQuestionIndices=[0];},
(x:typeof a)=>{x.prior.push(structuredClone(x.prior[0]!));},
(x:typeof a)=>{x.prior[0]!.questions[0]!.options[1]=structuredClone(x.prior[0]!.questions[0]!.options[0]!);},
(x:typeof a)=>{const revoked=structuredClone(x.prior[0]!);revoked.toolUseId='revoked';revoked.answers![revoked.questions[0]!.question]='Skip';x.prior.push(revoked);},
(x:typeof a)=>{x.prior[1]!.answers![x.prior[1]!.questions[0]!.question]='Skip';},
(x:typeof a)=>{x.prior[1]!.questions[0]!.options[0]!.description='A new proposed TODO.';},
(x:typeof a)=>{question(x.prior[1]!,s=>s+' This approval is withdrawn.');},
(x:typeof a)=>{question(x.next,s=>'Example: '+s);},
(x:typeof a)=>{question(x.next,s=>s+' This review is cancelled.');},
(x:typeof a)=>{question(x.next,s=>s.replace('is CLEARED','will be CLEARED'));},
(x:typeof a)=>{question(x.next,s=>s+' Only if more tests pass.');},
(x:typeof a)=>{x.next.questions[0]!.options[0]!.description+=' Add another requirement.';},
(x:typeof a)=>{x.next.questions[0]!.options[0]!.description=x.next.questions[0]!.options[0]!.description!.replace('two','three');},
(x:typeof a)=>{x.plan=x.plan.replace('## TODOS','## Historical TODOs');},
(x:typeof a)=>{x.plan=x.plan.replace('RetryPolicy','OtherPolicy');},
(x:typeof a)=>{x.plan=x.plan.replace('An approved follow-up.','This TODO is withdrawn.');},
(x:typeof a)=>{x.plan='```md\n'+x.plan+'\n```';},
]){const x=structuredClone(a);mutate(x);expect(check(x)).toBe(false);}
expect(isEngCompletionHandoff(fp(a.next),a.plan)).toBe(false);
});
function question(c: NativePlanQuestionCall, f: (s: string) => string) {
const q = c.questions[0]!, answer = c.answers![q.question];
q.question = f(q.question); c.answers = { [q.question]: answer! }; return c;
+40
View File
@@ -9,6 +9,46 @@ const reports: string[] = [
];
const regression = (plan: string) => evaluateEngSeedCoverage({ status: 'ready', calls: [], assistantMessages: [] }, plan, 0, 1).regression;
const inlineRequired = `# Current reviewed plan
## Required tests
- **CRITICAL regression (T4)** \`auth/legacy-parity.test.ts\`:
Record legacyAuthFlow() outputs before any change. Run the same fixtures
against the new path; assert identical session shape and identical rejection class.
- **Other test** unrelated.test.ts: tests another feature.
## Implementation Tasks
- [ ] **T4 (P1)** — auth/tests — Regression: pin legacyAuthFlow() behavior
- Files: auth/legacy-parity.test.ts
- Verify: suite green on legacy before any refactor commit; green on both paths before rollout
## Verification
1. Run T4 against the untouched legacy path and commit the fixtures first.
2. Land the replacement and run T4 on both paths.
`;
test('inline required regression binds its own task, baseline and same-fixture parity', () => {
expect(regression(inlineRequired)).toBe('plan');
expect(regression(inlineRequired.replaceAll('T4', 'T17').replaceAll('auth/legacy-parity.test.ts', 'spec/old-path.test.ts'))).toBe('plan');
expect(regression(inlineRequired.replace('CRITICAL regression', 'MANDATORY characterization').replace('Record', 'Capture')
.replace('Run the same', 'Replay the same').replace('identical session shape', 'matching outputs')
.replace('suite green on legacy', 'tests pass on the legacy path').replace('untouched', 'unmodified'))).toBe('plan');
for (const change of [
(s: string) => s.replace('CRITICAL regression', 'Optional regression'),
(s: string) => s.replace('CRITICAL regression', 'CRITICAL regression withdrawn'),
(s: string) => s.replace('## Required tests', '## Historical required tests'),
(s: string) => s.replace(' Record', ' If approved, record'),
(s: string) => s.replace('outputs before', 'behavior after'),
(s: string) => s.replace('same fixtures', 'different fixtures'),
(s: string) => s.replace('new path', 'unrelated path'),
(s: string) => s.replace('identical rejection class', 'unspecified behavior'),
(s: string) => s.replace(' - Files: auth/legacy-parity.test.ts', ' - Files: auth/other.test.ts'),
(s: string) => s.replace('green on legacy before', 'red on legacy before'),
(s: string) => s.replace('green on both paths', 'green on new path'),
(s: string) => s.replace('untouched legacy', 'rewritten legacy'),
(s: string) => s.replace('1. Run T4', '1. Run T9'),
(s: string) => s + '\n## Current status\nT4 is "withdrawn".\n',
(s: string) => s + '\n## Current status\nChange T4 assertions to match the new behavior.\n',
(s: string) => s.split('\n').map(line => '> ' + line).join('\n'),
]) expect(regression(change(inlineRequired))).toBeUndefined();
});
test('mandatory named regression suites bind the task to an untouched baseline', () => {
for (const report of reports) {
expect(regression(report)).toBe('plan');
+71 -3
View File
@@ -2,7 +2,8 @@ import { describe, expect, test } from 'bun:test';
import captured from './fixtures/eng-count-ad-v2.json';
import af from './fixtures/eng-first-category-af.json';
import type { NativePlanQuestionCall, PlanCountTranscript } from './helpers/plan-count-transcript';
import { ENG_DECISION_SEEDS, evaluateEngSeedCoverage } from './helpers/eng-seeded-coverage';
import { ENG_DECISION_SEEDS, evaluateEngSeedCoverage, isEngBatchingIssueAUQ } from './helpers/eng-seeded-coverage';
import { nativePlanCallFingerprint } from './helpers/claude-pty-runner';
import { E2E_TOUCHFILES, matchGlob } from './helpers/touchfiles';
// Exact public decisions reused from the existing fixture. The report below is
@@ -168,10 +169,10 @@ describe('Eng seeded coverage from completed native decisions', () => {
expect(evaluate(transcript(), report.replace('Eng review complete.', '')).ok).toBe(false);
});
test('new local evidence dependencies select only this Eng paid case', () => {
test('local evidence dependencies select both Eng consumers', () => {
for (const file of ['test/helpers/eng-seeded-coverage.ts', 'test/eng-seeded-coverage.test.ts']) {
expect(Object.entries(E2E_TOUCHFILES).filter(([, patterns]) => patterns.some(p => matchGlob(file, p))).map(([key]) => key))
.toEqual(['plan-eng-finding-count']);
.toEqual(['plan-eng-finding-count', 'plan-eng-multi-finding-batching']);
}
});
@@ -206,3 +207,70 @@ describe('Eng seeded coverage from completed native decisions', () => {
]) expect(evaluateTask(text).regression, text).toBeUndefined();
});
});
describe('batching caller counts completed issue decisions across setup boundaries', () => {
const issue = (number: number, header = 'Architecture'): NativePlanQuestionCall => {
const question = `D${number + 2} — Issue ${number}: Choose the component contract\nELI10: The current contract leaves behavior unspecified.`;
return { sessionId: 'owned-session', toolUseId: `toolu_issue_${number}`, answered: true, failed: false,
answeredAt: '2026-01-01T00:00:00.000Z', unansweredQuestionIndices: [],
questions: [{ header, question, multiSelect: false, options: [
{ label: `${number}A: Define the contract`, description: 'Specify the behavior.' },
{ label: `${number}B: Retain the current contract`, description: 'Keep the documented risk.' },
] }], answers: { [question]: `${number}A: Define the contract` } };
};
const check = (call: NativePlanQuestionCall, prior: readonly NativePlanQuestionCall[] = []) =>
isEngBatchingIssueAUQ(nativePlanCallFingerprint(call, 0, true), prior);
test('six completed calls count six; unrelated wording and either offered choice do not change identity', () => {
const history: NativePlanQuestionCall[] = [];
for (const [i, header] of ['Architecture', 'Architecture', 'Architecture', 'Code quality', 'Tests', 'Performance'].entries()) {
const call = issue(i + 1, header);
if (i % 2) call.answers![call.questions[0]!.question] = call.questions[0]!.options[1]!.label;
expect(check(call, history)).toBe(true); history.push(call);
}
expect(history).toHaveLength(6);
expect(check(history[0]!, history)).toBe(false);
const repeated = structuredClone(history[0]!); repeated.toolUseId = 'toolu_repeated';
expect(check(repeated, history)).toBe(false);
const scope = issue(1, 'Scope');
expect(check(repeated, [scope])).toBe(true);
const batch = issue(1), second = issue(2);
batch.questions.push(...second.questions); Object.assign(batch.answers!, second.answers);
expect(check(repeated, [batch])).toBe(true);
});
test('one batched native call cannot satisfy a three-call floor', () => {
const batch = issue(1);
for (const number of [2, 3, 4]) {
const next = issue(number); batch.questions.push(...next.questions); Object.assign(batch.answers!, next.answers);
}
const count = [batch].filter(call => check(call)).length;
expect(count).toBeLessThanOrEqual(1); expect(count).toBeLessThan(3);
});
test('incomplete, foreign, inconsistent or non-issue packets cannot inflate the counter', () => {
const variants: Array<(call: NativePlanQuestionCall) => void> = [
c => { c.answered = false; }, c => { c.failed = true; }, c => { c.unansweredQuestionIndices = [0]; },
c => { delete c.answeredAt; }, c => { c.answers = {}; }, c => { c.questions[0]!.multiSelect = true; },
c => { c.answers![c.questions[0]!.question] = 'Not offered'; },
c => { c.questions[0]!.options[1]!.label = '2B: Foreign issue'; },
c => { c.questions[0]!.options[1]!.label = '1A: Duplicate option ID'; },
c => { c.questions[0]!.header = 'Scope'; }, c => { c.questions[0]!.header = 'Next steps'; },
c => { c.questions[0]!.header = 'TODO'; }, c => { c.questions[0]!.header = 'Design'; },
c => { question(c, c.questions[0]!.question.replace('Issue 1:', 'TODO 1:')); },
c => { question(c, '> ' + c.questions[0]!.question); },
c => { question(c, 'Historical note:\n' + c.questions[0]!.question); },
c => { question(c, c.questions[0]!.question + '\nThis decision is "withdrawn".'); },
c => { question(c, c.questions[0]!.question + '\nIssue 1 is no longer current.'); },
c => { question(c, c.questions[0]!.question + '\nThis decision is `no longer current`.'); },
];
for (const change of variants) { const call = issue(1); change(call); expect(check(call)).toBe(false); }
const fp = nativePlanCallFingerprint(issue(1), 0, true); fp.signature = 'foreign:identity';
expect(isEngBatchingIssueAUQ(fp)).toBe(false);
expect(check(issue(2), [{ ...issue(1), sessionId: 'foreign-session' }])).toBe(false);
const call = issue(1); question(call, call.questions[0]!.question + '\n> This decision is withdrawn.');
expect(check(call)).toBe(true);
const quoted = issue(1); question(quoted, quoted.questions[0]!.question + '\n`This decision is withdrawn.`');
expect(check(quoted)).toBe(true);
});
});
+10 -10
View File
@@ -1805,10 +1805,10 @@ fi
_OUTSIDE_CFG=enabled # This caller has its own opt-in/skip control.
if [ "$_OUTSIDE_CFG" = disabled ]; then
echo 'CODEX_MODE: disabled'
elif ( # GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
elif ( # GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; }; then
echo 'Claude Code outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host claude from your gstack checkout.' >&2
@@ -1831,10 +1831,10 @@ Prompt: "Review the git diff on this branch. Run 7 litmus checks (YES/NO each):
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; }; then
echo 'Claude Code outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host claude from your gstack checkout.' >&2
@@ -2050,10 +2050,10 @@ fi
_OUTSIDE_CFG=$("$GSTACK_BIN/gstack-config" get codex_reviews 2>/dev/null || echo enabled)
if [ "$_OUTSIDE_CFG" = disabled ]; then
echo 'CODEX_MODE: disabled'
elif ( # GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
elif ( # GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; }; then
echo 'Claude Code outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host claude from your gstack checkout.' >&2
@@ -2106,10 +2106,10 @@ Outside prompt (supply repository context from the parent):
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; }; then
echo 'Claude Code outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host claude from your gstack checkout.' >&2
@@ -2181,10 +2181,10 @@ Prepare a structured review prompt requesting severity-tagged findings ([P1], [P
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request severity-tagged findings or an explicit NO_FINDINGS conclusion. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; }; then
echo 'Claude Code outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host claude from your gstack checkout.' >&2
+8 -8
View File
@@ -1812,10 +1812,10 @@ fi
_OUTSIDE_CFG=enabled # This caller has its own opt-in/skip control.
if [ "$_OUTSIDE_CFG" = disabled ]; then
echo 'CODEX_MODE: disabled'
elif ( # GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
elif ( # GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -1838,10 +1838,10 @@ Prompt: "Review the git diff on this branch. Run 7 litmus checks (YES/NO each):
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -2354,10 +2354,10 @@ Outside prompt (supply repository context from the parent):
Use Write to save the **complete prompt and context** in a private file. Replace `<prepared-prompt-file>` below with its shell-quoted path; never interpolate user text into shell source. Include actual plan/spec/source content: Claude Code review/challenge has no tools, git, or path access. Request a final Recommendation: <action> because <specific reason> line, including an explicit no-findings rationale. A refusal is never completion.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
@@ -2425,10 +2425,10 @@ Prepare a structured review prompt requesting severity-tagged findings ([P1], [P
Run Codex’s built-in structured review with the selected base. It supplies its own prompt and accepts no custom prompt file with --base. Require severity-tagged findings (including native P1:/P2: labels) or an explicit no-findings conclusion; arbitrary prose or a refusal is missing coverage.
```bash
# GSTACK_ACTIVE_HOST, when supplied, must identify the actual harness, never a model overlay.
# GSTACK_ACTIVE_HOST names the harness, never the model.
if { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Codex outside review unavailable: harness mismatch; no outside process started. Missing coverage.' >&2
if [ -n "${CLAUDECODE:-}" ] && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ]; }; then
if { [ -n "${CLAUDECODE:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = claude ]; } && { [ -n "${CODEX_THREAD_ID:-}" ] || [ -n "${CODEX_SANDBOX:-}" ] || [ "${GSTACK_ACTIVE_HOST:-}" = codex ]; }; then
echo 'Inherited harness markers conflict. Run setup --host <actual-harness> (claude or codex); do not guess a replacement provider.' >&2
else
echo 'Repair installed skills: run setup --host codex from your gstack checkout.' >&2
+34 -19
View File
@@ -412,6 +412,39 @@ function pendingCommandDisplayViewport(viewport: string, file: string, ownedStat
return text.slice(panels[0]!.index);
}
/** Same native-history gate for an unpublished pending Edit, independent of its display. */
export function hasPendingAutoplanArtifactHistory(
context: ArtifactPermissionContext & { pending?: PendingAutoplanArtifact },
): boolean {
const p = context.pending, now = context.now ?? Date.now();
if (!p || p.source !== 'pre_tool_use' || p.tool !== 'Edit' || context.transcriptStatus !== 'ready' ||
!Number.isFinite(now) || !Number.isFinite(context.commandStartedAt) ||
!/^[A-Za-z0-9_-]{1,160}$/.test(p.sessionId) || !/^[A-Za-z0-9_-]{1,160}$/.test(p.toolUseId) ||
!ownedAutoplanArtifact(p.file, context) || context.publicTools.length > 10_000) return false;
const pendingTime = Date.parse(p.timestamp);
if (!Number.isFinite(pendingTime) || pendingTime < context.commandStartedAt || pendingTime > now) return false;
const events = context.publicTools.filter(e => Date.parse(e.timestamp) >= context.commandStartedAt);
if (!events.length || context.publicTools.some(e => !Number.isFinite(Date.parse(e.timestamp)))) return false;
const uses = new Map<string, NativePublicToolEvent>(), results = new Map<string, NativePublicToolEvent>();
let last = context.commandStartedAt;
for (const event of events) {
const time = Date.parse(event.timestamp);
if (event.sessionId !== p.sessionId || !event.toolUseId || event.toolUseId === p.toolUseId || time < last || time > now) return false;
last = time;
const map = event.kind === 'use' ? uses : results;
if (map.has(event.toolUseId) || (event.kind === 'result' && !uses.has(event.toolUseId))) return false;
map.set(event.toolUseId, event);
}
const mutations = [...uses.values()].filter(e => e.name === 'Write' || e.name === 'Edit');
// Hook metadata cannot replace a published request/result or an unresolved
// mutation. Public successful same-file history remains mandatory.
if (mutations.some(e => !results.has(e.toolUseId) || Date.parse(e.timestamp) > pendingTime ||
Date.parse(results.get(e.toolUseId)!.timestamp) > pendingTime) ||
!mutations.some(e => e.input?.file_path === p.file && results.get(e.toolUseId)?.isError === false &&
Date.parse(results.get(e.toolUseId)!.timestamp) <= pendingTime)) return false;
return true;
}
/** Metadata-only fallback. Added rows are display evidence, never request content. */
export function pendingAutoplanArtifactPermissionInput(viewport: string,
context: ArtifactPermissionContext & { pending?: PendingAutoplanArtifact; viewportCapturedAt: number },
@@ -428,25 +461,7 @@ export function pendingAutoplanArtifactPermissionInput(viewport: string,
const pendingTime = Date.parse(p.timestamp), signature = `${p.sessionId}:${p.toolUseId}`;
if (!Number.isFinite(pendingTime) || pendingTime < context.commandStartedAt || pendingTime > context.viewportCapturedAt ||
seen.has(signature) || seen.has(autoplanArtifactMenuKey(viewport)) || context.publicTools.length > 10_000) return null;
const events = context.publicTools.filter(e => Date.parse(e.timestamp) >= context.commandStartedAt);
if (!events.length || context.publicTools.some(e => !Number.isFinite(Date.parse(e.timestamp)))) return null;
const uses = new Map<string, NativePublicToolEvent>(), results = new Map<string, NativePublicToolEvent>();
let last = context.commandStartedAt;
for (const event of events) {
const time = Date.parse(event.timestamp);
if (event.sessionId !== p.sessionId || !event.toolUseId || event.toolUseId === p.toolUseId || time < last || time > now) return null;
last = time;
const map = event.kind === 'use' ? uses : results;
if (map.has(event.toolUseId) || (event.kind === 'result' && !uses.has(event.toolUseId))) return null;
map.set(event.toolUseId, event);
}
const mutations = [...uses.values()].filter(e => e.name === 'Write' || e.name === 'Edit');
// Hook metadata cannot replace a published request/result or an unresolved
// mutation. Public successful same-file history remains mandatory.
if (mutations.some(e => !results.has(e.toolUseId) || Date.parse(e.timestamp) > pendingTime ||
Date.parse(results.get(e.toolUseId)!.timestamp) > pendingTime) ||
!mutations.some(e => e.input?.file_path === p.file && results.get(e.toolUseId)?.isError === false &&
Date.parse(results.get(e.toolUseId)!.timestamp) <= pendingTime)) return null;
if (!hasPendingAutoplanArtifactHistory(context)) return null;
try {
const currentViewport = p.editDigest ? pendingCommandDisplayViewport(viewport, p.file, context.ownedStateRoot) : viewport;
const text = currentViewport.replace(/\r\n?/g, '\n');
+73 -12
View File
@@ -2,14 +2,14 @@
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { ownedAutoplanArtifact } from './autoplan-artifact-permission';
import { ownedAutoplanArtifact, hasPendingAutoplanArtifactHistory } from './autoplan-artifact-permission';
import { createAutoplanEditDigest, validAutoplanEditDigest, type AutoplanEditDigest } from './autoplan-artifact-digest';
import type { NativePublicToolEvent } from './plan-count-transcript';
import { readPlanCountTranscript, type NativePublicToolEvent } from './plan-count-transcript';
// Suffix commitments are capped at 8192 hashes; old metadata/input limits stay unchanged.
const MAX_BYTES = 1024 * 1024, MAX_INPUT = 4 * 1024 * 1024, MAX_IDS = 128;
const reasons = ['invalid_event','record_error','lock_conflict','concurrent_pending','conflicting_replay',
'record_overflow','input_overflow','stdin_timeout','hook_error'] as const;
'record_overflow','input_overflow','stdin_timeout','hook_error','approval_withheld'] as const;
type Reason = typeof reasons[number];
const object = (v: unknown): v is Record<string, any> => v !== null && typeof v === 'object' && !Array.isArray(v);
const id = (v: unknown): v is string => typeof v === 'string' && /^[A-Za-z0-9_-]{1,160}$/.test(v);
@@ -21,7 +21,7 @@ export interface PendingAutoplanArtifact {
hookSeenIds?:string[];
}
interface Pending extends PendingAutoplanArtifact { transcriptPath:string }
interface State { version:1; cwd:string; config:string; stateRoot:string; sessionId?:string; seenIds:string[]; pending:Pending|null }
interface State { version:1; cwd:string; config:string; stateRoot:string; sessionId?:string; approvalStartedAt?:number; seenIds:string[]; pending:Pending|null }
function scopedTranscript(file: unknown, config: string, session: string): file is string {
if (typeof file !== 'string' || !path.isAbsolute(file)) return false;
@@ -35,7 +35,8 @@ function readState(file:string, cwd:string, config:string, stateRoot:string): St
const stat = fs.lstatSync(file);
if (!stat.isFile() || stat.size > MAX_BYTES) throw Error('record');
const s = JSON.parse(fs.readFileSync(file,'utf8'));
if (!object(s) || !keys(s,['version','cwd','config','stateRoot','sessionId','seenIds','pending']) || s.version !== 1 ||
if (!object(s) || !keys(s,['version','cwd','config','stateRoot','sessionId','approvalStartedAt','seenIds','pending']) || s.version !== 1 ||
(s.approvalStartedAt !== undefined && (!Number.isSafeInteger(s.approvalStartedAt) || s.approvalStartedAt <= 0)) ||
s.cwd !== cwd || s.config !== config || s.stateRoot !== stateRoot || (s.sessionId !== undefined && !id(s.sessionId)) ||
!Array.isArray(s.seenIds) || s.seenIds.length > MAX_IDS || !s.seenIds.every(id) || new Set(s.seenIds).size !== s.seenIds.length ||
(s.sessionId === undefined && (s.seenIds.length || s.pending !== null))) throw Error('record');
@@ -50,20 +51,67 @@ function readState(file:string, cwd:string, config:string, stateRoot:string): St
function poison(file:string, reason:Reason) {
try { fs.writeFileSync(file+'.invalid',JSON.stringify({reason})+'\n',{mode:0o600,flag:'wx'}); } catch { /* already invalid or closed */ }
}
export function createAutoplanArtifactRecorder(cwd:string, config:string, stateRoot:string) {
export function createAutoplanArtifactRecorder(cwd:string, config:string, stateRoot:string, approveEdits=false) {
if (![cwd,config,stateRoot].every(path.isAbsolute) || !fs.lstatSync(stateRoot).isDirectory()) throw Error('owned runtime required');
const createdAt = Date.now();
const dir = fs.mkdtempSync(path.join(os.tmpdir(),'gstack-autoplan-artifact-')), file = path.join(dir,'state.json');
fs.writeFileSync(file,JSON.stringify({version:1,cwd,config,stateRoot,seenIds:[],pending:null})+'\n',{mode:0o600});
const command = [process.execPath,import.meta.path,'--record',file,cwd,config,stateRoot].map(quote).join(' ');
const command = [process.execPath,import.meta.path,'--record',file,cwd,config,stateRoot,...(approveEdits ? ['--approve-edits'] : [])].map(quote).join(' ');
// Foreign/current file mutations invalidate concurrent owned identity. Only
// allowlisted Edit requests can become pending; Write supplies no authority.
const hook = {matcher:'^(Write|Edit)$',hooks:[{type:'command',command,timeout:5}]};
return {file,hooks:{PreToolUse:[hook],PostToolUse:[hook],PostToolUseFailure:[hook]},
// Only the owning caller activates approval, once, at the actual slash-command start.
startEditApproval: approveEdits ? (startedAt:number) => {
let lock:number|undefined;
const temporary = `${file}.start.tmp`;
try {
if (!Number.isSafeInteger(startedAt) || startedAt < createdAt || startedAt > Date.now() ||
fs.existsSync(file+'.invalid')) throw Error('invalid approval start');
lock=fs.openSync(file+'.lock','wx',0o600);
const state=readState(file,cwd,config,stateRoot);
if (state.approvalStartedAt !== undefined || state.pending) throw Error('approval already started or pending');
state.approvalStartedAt=startedAt;
fs.writeFileSync(temporary,JSON.stringify(state)+'\n',{mode:0o600,flag:'wx'});fs.renameSync(temporary,file);
} catch (error) { poison(file,'record_error'); throw error; }
finally {
try { fs.rmSync(temporary,{force:true}); } catch {}
if (lock!==undefined) { fs.closeSync(lock);fs.unlinkSync(file+'.lock'); }
}
} : undefined,
dispose:()=>fs.rmSync(dir,{recursive:true,force:true})};
}
/** Persists metadata and bounded request digests, never edit text or tool results. */
export function recordAutoplanArtifact(input:string, file:string, cwd:string, config:string, stateRoot:string) {
/** Reuses the pending UI path's history gate; current publication supplies no success. */
function canApproveEdit(e:Record<string,any>, pending:Pending, state:State):boolean {
if (state.approvalStartedAt === undefined || !validAutoplanEditDigest(pending.editDigest)) return false;
const tools:NativePublicToolEvent[]=[];
const transcript=readPlanCountTranscript(state.config,state.cwd,event=>tools.push(event),pending.transcriptPath);
const current=tools.filter(event=>event.toolUseId===pending.toolUseId);
if (current.length) {
const use=current[0]!, input=use.input;
// A published request must be the same one that invoked this hook. No
// completed or conflicting identity can be removed from the history gate.
if (current.length!==1 || use.kind!=='use' || use.name!=='Edit' || use.sessionId!==pending.sessionId ||
!/^msg_[A-Za-z0-9_-]{1,160}$/.test(use.messageId??'') || !/^req_[A-Za-z0-9_-]{1,160}$/.test(use.requestId??'') ||
!Number.isFinite(Date.parse(use.timestamp)) || Date.parse(use.timestamp)<state.approvalStartedAt ||
Date.parse(use.timestamp)>Date.parse(pending.timestamp) || input?.file_path!==pending.file ||
input.old_string!==e.tool_input.old_string || input.new_string!==e.tool_input.new_string ||
(input.replace_all!==undefined && input.replace_all!==false)) return false;
}
if (!hasPendingAutoplanArtifactHistory({cwd:state.cwd,ownedStateRoot:state.stateRoot,
commandStartedAt:state.approvalStartedAt,now:Date.now(),transcriptStatus:transcript.status,
publicTools:tools.filter(event=>event.toolUseId!==pending.toolUseId),pending})) return false;
// Re-read after the journal checks. Missing/duplicate old_string, changed
// bytes, or a file modified after this hook's timestamp cannot gain approval.
const fresh=createAutoplanEditDigest(pending.file,e.tool_input.old_string,e.tool_input.new_string);
return !!fresh && JSON.stringify(fresh)===JSON.stringify(pending.editDigest) &&
Math.floor(fs.statSync(pending.file).mtimeMs)<=Date.parse(pending.timestamp);
}
/** Persists metadata/digests only. Opted-in approval never supplies tool success or phase credit. */
export function recordAutoplanArtifact(input:string, file:string, cwd:string, config:string, stateRoot:string, approveEdits=false) {
let approved=false;
let lock:number|undefined, reason:Reason='invalid_event';
const temporary = `${file}.${process.pid}.tmp`;
try {
@@ -118,14 +166,20 @@ export function recordAutoplanArtifact(input:string, file:string, cwd:string, co
// Success/failure hooks clear pending and tombstone the ID, but never
// supply successful history or phase coverage. Those still require JSONL.
if (!state.seenIds.includes(e.tool_use_id)) state.seenIds=[...state.seenIds,e.tool_use_id];
if (approveEdits && e.hook_event_name==='PreToolUse' && state.pending) approved=canApproveEdit(e,state.pending,state);
const serialized=JSON.stringify(state)+'\n'; reason='record_overflow';
if (state.seenIds.length>MAX_IDS || Buffer.byteLength(serialized)>MAX_BYTES) throw Error('record overflow');
reason='record_error'; fs.writeFileSync(temporary,serialized,{mode:0o600,flag:'wx'}); fs.renameSync(temporary,file);
} catch { poison(file,reason); }
// Persist the exact failed pending identity for diagnostics, but never let
// the opted-in caller retry a rejected Edit through terminal navigation.
if (approveEdits && state.approvalStartedAt!==undefined && e.hook_event_name==='PreToolUse' && !approved)
poison(file,'approval_withheld');
} catch { approved=false; poison(file,reason); }
finally {
try { fs.rmSync(temporary,{force:true}); } catch {}
if (lock!==undefined) { try { fs.closeSync(lock); fs.unlinkSync(file+'.lock'); } catch { poison(file,'record_error'); } }
}
return approved && !fs.existsSync(file+'.invalid');
}
export function autoplanArtifactRecorderStatus(file:string|undefined,cwd:string,config:string|null,stateRoot:string|undefined):
@@ -143,6 +197,12 @@ export function autoplanArtifactRecorderStatus(file:string|undefined,cwd:string,
return {status:readState(file,cwd,config,stateRoot).pending ? 'pending' : 'idle'};
} catch { return {status:'invalid',reason:'record_error'}; }
}
/** Native approval owns pending Edits; UI navigation resumes only when idle. */
export function autoplanArtifactApprovalBoundary(status:ReturnType<typeof autoplanArtifactRecorderStatus>):'clear'|'pending'|'failed' {
if (status.status==='idle') return 'clear';
if (status.status==='pending' || status.status==='busy') return 'pending';
return 'failed';
}
export function readPendingAutoplanArtifact(file:string|undefined,cwd:string,config:string|null,stateRoot:string|undefined,
startedAt:number, publicTools:readonly NativePublicToolEvent[], now=Date.now(), allowPublished=false): PendingAutoplanArtifact|undefined {
if (!file || !config || !stateRoot || !Number.isFinite(startedAt) || !Number.isFinite(now) ||
@@ -157,7 +217,7 @@ export function readPendingAutoplanArtifact(file:string|undefined,cwd:string,con
} catch { return undefined; }
}
if (import.meta.main && process.argv[2]==='--record') {
const [file,cwd,config,stateRoot]=process.argv.slice(3);
const [file,cwd,config,stateRoot,approval]=process.argv.slice(3);
if (file && cwd && config && stateRoot) {
const timer=setTimeout(()=>{poison(file,'stdin_timeout');process.exit(0);},4000);
try {
@@ -167,7 +227,8 @@ if (import.meta.main && process.argv[2]==='--record') {
if (size>MAX_INPUT) { poison(file,'input_overflow');process.exit(0); }
chunks.push(chunk);
}
recordAutoplanArtifact(Buffer.concat(chunks).toString('utf8'),file,cwd,config,stateRoot);
const approved=recordAutoplanArtifact(Buffer.concat(chunks).toString('utf8'),file,cwd,config,stateRoot,approval==='--approve-edits');
if (approved) process.stdout.write(JSON.stringify({hookSpecificOutput:{hookEventName:'PreToolUse',permissionDecision:'allow'}})+'\n');
} catch { poison(file,'hook_error'); }
finally { clearTimeout(timer); }
}
+6 -1
View File
@@ -114,6 +114,8 @@ export interface ClaudePtyOptions {
observeFilePermissions?: readonly string[];
/** Opt-in metadata only, limited to launcher-owned Autoplan review artifacts. */
observeAutoplanArtifacts?: boolean;
/** AP-only exact artifact Edit approvals; inactive until the owner starts its command. */
approveAutoplanArtifactEdits?: boolean;
/** Working directory. Default: process.cwd(). The repo cwd has the gstack
* skill registry and trusted-folder cookie, so most tests want this. */
cwd?: string;
@@ -176,6 +178,7 @@ export interface ClaudePtySession {
pendingPlanReadyFile?: string;
pendingQuestionFile?: string;
pendingAutoplanArtifactFile?: string;
startAutoplanArtifactEditApproval?: (commandStartedAt: number) => void;
pendingFilePermissionFiles?: Array<{ expected: string; file: string }>;
/**
* Send SIGINT, then SIGKILL after 1s. Always safe to call multiple times.
@@ -3731,7 +3734,8 @@ export async function launchClaudePty(
pendingQuestion = createPendingQuestionRecorder(cwd, childEnv.CLAUDE_CONFIG_DIR);
}
if (opts.observeAutoplanArtifacts && hermetic && childEnv.CLAUDE_CONFIG_DIR && hermeticSkillStateRoot) {
pendingArtifact = createAutoplanArtifactRecorder(cwd, childEnv.CLAUDE_CONFIG_DIR, hermeticSkillStateRoot);
pendingArtifact = createAutoplanArtifactRecorder(cwd, childEnv.CLAUDE_CONFIG_DIR, hermeticSkillStateRoot,
opts.approveAutoplanArtifactEdits === true);
}
if (opts.observeFilePermissions && hermetic && childEnv.CLAUDE_CONFIG_DIR) {
for (const expected of new Set(opts.observeFilePermissions)) {
@@ -3935,6 +3939,7 @@ export async function launchClaudePty(
pendingPlanReadyFile: pendingExit?.file,
pendingQuestionFile: pendingQuestion?.file,
pendingAutoplanArtifactFile: pendingArtifact?.file,
startAutoplanArtifactEditApproval: pendingArtifact?.startEditApproval,
pendingFilePermissionFiles: pendingFiles.map(({ expected, recorder }) => ({ expected, file: recorder.file })),
close,
};
+21 -6
View File
@@ -150,7 +150,12 @@ function ordinaryDesignIssue(fp: AskUserQuestionFingerprint): boolean {
!sourceAssessment.test(prefix.join(' ')) && !sourceAssessment.test(assessments[0]![1]!)
? assessments[0]![1]! : '';
const headerPeers = primary && headerActionIssue && new RegExp(`^${primary[1]}, ([A-Za-z][A-Za-z0-9 _-]{0,39}(?:, [A-Za-z][A-Za-z0-9 _-]{0,39})*(?:,? and [A-Za-z][A-Za-z0-9 _-]{0,39})?) currently look (?:the same|identical)\\.`, 'i').exec(assessment);
const countedHeader = distinguishedPrimaryIssue && /^(?:Right now|Today) (?:all|the) (two|three|four|five|six|seven|eight|nine|ten|[1-9]\d*) header buttons look (?:the same|identical)\./i.exec(assessment) ||
// Equal visual properties can establish the same current lack of hierarchy.
// Shared geometry alone is not a claim that the actions look equally primary.
const properties = '(?:size|weight|colou?r|fill|emphasis)(?:(?:, ?|,? and )(?:size|weight|colou?r|fill|emphasis))*';
const equalProperties = distinguishedPrimaryIssue && new RegExp('^(?:Right now|Today) (?:all|the) (two|three|four|five|six|seven|eight|nine|ten|[1-9]\\d*) header buttons (?:are|have|share) the same (' + properties + ')\\.', 'i').exec(assessment);
const countedHeader = equalProperties && /\b(?:weight|colou?r|fill|emphasis)\b/i.test(equalProperties[2]!) && equalProperties ||
distinguishedPrimaryIssue && /^(?:Right now|Today) (?:all|the) (two|three|four|five|six|seven|eight|nine|ten|[1-9]\d*) header buttons look (?:the same|identical)\./i.exec(assessment) ||
declaredPrimaryIssue && /^(two|three|four|five|six|seven|eight|nine|ten|[1-9]\d*) header buttons currently (?:share one style|look identical)\./i.exec(assessment);
const primaryAssessment = distinguishedPrimaryIssue || declaredPrimaryIssue ? countedHeader?.[0] : headerActionIssue ? headerPeers?.[0] :
primary && new RegExp(`^(?:Right now|Today) ${primary[1]}(?:, [A-Za-z][A-Za-z0-9 _-]{0,39})+(?:,? and [A-Za-z][A-Za-z0-9 _-]{0,39})? (?:(?:all )?look (?:the same|identical)|are (?:all )?(?:(?:two|three|four|five|six|seven|eight|nine|ten|[1-9]\\d*) )?identical buttons)\\b`, 'i').exec(assessment)?.[0];
@@ -174,7 +179,7 @@ function ordinaryDesignIssue(fp: AskUserQuestionFingerprint): boolean {
const invalidContract = new RegExp(`(?:^|${statusBoundary}\\s+|\\n)(?:Correction:\\s*)?(?:this|that|the) (?:(?:DESIGN\\.md|token) )?(?:requirement|contract) (?:is|was|has been) (?:withdrawn|superseded|rejected|cancelled|canceled|not current|no longer current)\\b`, 'i');
const namedContract = primary && new RegExp(`(?:^|[.!?]\\s+)DESIGN\\.md already says ${primary[1]} is the only filled primary button and the other (two|three|four|five|six|seven|eight|nine|ten|[1-9]\\d*) are neutral ghost buttons\\.`, 'i').exec(assessment);
const headerContract = primary && headerActionIssue && new RegExp(`(?:^|[.!?]\\s+)DESIGN\\.md already answers it: ${primary[1]} is the only filled primary button, the other (two|three|four|five|six|seven|eight|nine|ten|[1-9]\\d*) are neutral ghost buttons\\.`, 'i').exec(assessment);
const conditionalHeader = (text: string) => /(?:^|[.!?;]\s+|\n)(?:[✅❌]\s*)?(?:Correction:\s*)?(?:If|When|Unless|Assuming|Provided)\b/i.test(text);
const conditionalHeader = (text: string) => /(?:^|[.!?;]\s+|\n)(?:[✅❌]\s*)?(?:Correction:\s*)?(?:If|When|Unless|Assuming|Provided)\b/i.test(text) || /\b(?:only if|unless|pending approval|subject to approval)\b/i.test(text);
// Approval conditions suspend this offered decision; explanatory conditions
// about user behavior do not make an otherwise current amendment optional.
const pendingPrimaryApproval = (text: string) => primaryEmphasisIssue && (
@@ -204,6 +209,15 @@ function ordinaryDesignIssue(fp: AskUserQuestionFingerprint): boolean {
q.options.some(amendment => {
const body = currentText(amendment.description ?? '');
if (pendingPrimaryApproval(body)) return false;
// Roles and their concrete tokens belong to one native option; a familiar
// label alone cannot supply the style or borrow DESIGN.md from a peer.
const roleLabel = currentText(amendment.label);
const propertyStyle = primary && distinguishedPrimaryIssue && new RegExp(`^(?:✅\\s*)?${primary[1]} (?:is|becomes) the (?:only|single) filled(?: primary)? #[0-9a-f]{6}(?: button)? with (?:white|black) text; ([A-Za-z][A-Za-z0-9 ,/_-]{0,119}) (?:are|become) neutral ghost(?: buttons)?\\.`, 'i').exec(body);
const roleAuthority = new RegExp(`^${issue[1]}[A-Z][).:]?\\s+(?:(?:Apply|Use|Reuse) )?DESIGN\\.md\\b`, 'i').test(roleLabel) ||
/(?:^|[.;]\s+)(?:Matches DESIGN\.md exactly|Per DESIGN\.md)\b/i.test(body);
const roleStyle = propertyStyle && roleAuthority && !conditionalHeader(roleLabel) &&
!/\b(?:not|never|no|if|historical|hypothetical|source|quoted|withdrawn|superseded|cancelled|canceled)\b/i.test(roleLabel) &&
!headerControls.some(peer => new RegExp(`\\b(?:primary(?: button| action)? ${peer}|${peer} (?:as )?(?:the )?(?:filled )?primary)\\b`, 'i').test(roleLabel)) ? propertyStyle : null;
const declaredStyle = primary && declaredPrimaryIssue &&
new RegExp(`^(?:✅\\s*)?${primary[1]} filled #[0-9a-f]{6}(?: with)? (?:white|black)(?: text)?; ([A-Za-z][A-Za-z0-9 ,/_-]{0,119}) neutral ghost(?: buttons)?\\.`, 'i').exec(body);
if (declaredPrimaryIssue) {
@@ -215,16 +229,16 @@ function ordinaryDesignIssue(fp: AskUserQuestionFingerprint): boolean {
}
const headerStyle = primary && headerActionIssue && new RegExp(`^(?:✅\\s*)?${primary[1]} becomes the only filled #[0-9a-f]{6} button with (?:white|black) text; ([A-Za-z][A-Za-z0-9 ,_-]{0,119}) become neutral ghost buttons, exactly as DESIGN\\.md states\\.`, 'i').exec(body);
// A descriptive header still owns a concrete primary and every peer.
// The native label supplies the filled role; its own body supplies tokens.
// Its native option supplies the primary/secondary roles and tokens.
const distinguishedStyle = primary && distinguishedPrimaryIssue && (
new RegExp(`^(?:✅\\s*)?${primary[1]} is #[0-9a-f]{6} with (?:white|black) text; ([A-Za-z][A-Za-z0-9 ,_-]{0,119}) are neutral ghost buttons per DESIGN\\.md\\.`, 'i').exec(body) ??
new RegExp(`^(?:✅\\s*)?${primary[1]} becomes the only filled button \\(#[0-9a-f]{6}, (?:white|black) text\\); ([A-Za-z][A-Za-z0-9 ,/_-]{0,119}) use the existing neutral ghost variant` +
'(?: \\(human: ~?[0-9]+(?:\\.[0-9]+)?(?:h|min) / CC: ~?[0-9]+(?:\\.[0-9]+)?(?:h|min)\\))?\\. (?:✅\\s*)?Matches DESIGN\\.md exactly\\b', 'i').exec(body));
'(?: \\(human: ~?[0-9]+(?:\\.[0-9]+)?(?:h|min) / CC: ~?[0-9]+(?:\\.[0-9]+)?(?:h|min)\\))?\\. (?:✅\\s*)?Matches DESIGN\\.md exactly\\b', 'i').exec(body) ?? roleStyle);
const style = declaredPrimaryIssue ? declaredStyle?.[0] : distinguishedPrimaryIssue ? distinguishedStyle?.[0] : headerActionIssue ? headerStyle?.[0] : amendments.map(pattern => pattern.exec(body)).find(Boolean)?.[0];
if ((declaredPrimaryIssue || distinguishedPrimaryIssue) &&
/(?:^|[.!?;]\s+|\n)(?:Correction:\s*)?(?:the|this) (?:current )?(?:amendment|fix) keeps (?:all )?(?:two|three|four|five|six|seven|eight|nine|ten|[1-9]\d*) (?:header )?buttons identical\b/i.test(body)) return false;
if (distinguishedPrimaryIssue && (!distinguishedStyle || conditionalHeader(body) || invalidContract.test(body) ||
!new RegExp(`^[1-9]\\d*[A-Z][).:]?\\s+Filled primary (?:(?:\\+|and|with) ghosts|${primary![1]})(?: \\(recommended\\))?$`, 'i').test(amendment.label) ||
!(roleStyle || new RegExp(`^[1-9]\\d*[A-Z][).:]?\\s+Filled primary (?:(?:\\+|and|with) ghosts|${primary![1]})(?: \\(recommended\\))?$`, 'i').test(amendment.label)) ||
JSON.stringify(controlNames(distinguishedStyle[1]!.replaceAll('/', ','))) !== JSON.stringify(headerControls))) return false;
if (headerActionIssue && (!headerStyle || conditionalHeader(body) || invalidContract.test(body) ||
JSON.stringify(controlNames(headerStyle[1]!)) !== JSON.stringify(headerControls))) return false;
@@ -263,7 +277,8 @@ function ordinaryDesignIssue(fp: AskUserQuestionFingerprint): boolean {
const remaining = pros && !sourceAssessment.test(pros[0]) ? deferralBody.slice(pros[0].length) : deferralBody;
const retainedEmphasis = distinguishedPrimaryIssue && new RegExp(`^(?:Keep|Leave) identical (?:header )?buttons, bold (?:the )?${primary![1]} (?:text|label)\\. (?:Weak(?: visual)? signal, )?off-token\\.`, 'i').test(remaining);
const retainedHierarchyGap = distinguishedPrimaryIssue && /^(?:❌\s*)?Ships a (?:known|documented) DESIGN\.md violation and the plan['’]s own Visual Hierarchy gap (?:stays|remains) open\./i.test(remaining);
if (distinguishedPrimaryIssue) return defer !== amendment && !!(retainedEmphasis || retainedHierarchyGap) &&
const retainedRoleGap = roleStyle && /^(?:No change[.;]\s*)?(?:the |this )?(?:finding|issue|gap) (?:stays|remains) (?:open|unresolved)\b/i.test(remaining);
if (distinguishedPrimaryIssue) return defer !== amendment && !!(retainedEmphasis || retainedHierarchyGap || retainedRoleGap) &&
!conditionalHeader(declined) && !sourceAssessment.test(declined) && !withdrawn.test(declined) &&
!/(?:^|[.!?;]\s+|\n)(?:Correction:\s*)?(?:do not|don't|never|skip|cancel|withdraw) (?:keep|leave) identical (?:header )?buttons\b/i.test(declined) &&
!closedGap.test(declined) && !invalidContract.test(declined) && !cancelledStyle.test(declined) && !withdrawnStyles.test(declined);
+67 -2
View File
@@ -1,14 +1,16 @@
import type { AskUserQuestionFingerprint } from './claude-pty-runner';
import type { NativePlanQuestionCall } from './plan-count-transcript';
/** Count a completed review-navigation choice separately; never choose pending input. */
export function isEngCompletionHandoff(fp: AskUserQuestionFingerprint, reviewedPlan: string): boolean {
export function isEngCompletionHandoff(fp: AskUserQuestionFingerprint, reviewedPlan: string,
priorCalls: readonly NativePlanQuestionCall[] = []): boolean {
const call = fp.nativeCall;
if (!call?.sessionId || !call.toolUseId || call.answered !== true || call.failed !== false ||
fp.signature !== `${call.sessionId}:${call.toolUseId}` || call.questions.length !== 1 ||
!Array.isArray(call.unansweredQuestionIndices) || call.unansweredQuestionIndices.length ||
(fp.nativeQuestionIndex !== undefined && fp.nativeQuestionIndex !== 0) ||
Object.keys(call.answers ?? {}).length !== 1 || !Number.isFinite(Date.parse(call.answeredAt ?? ''))) return false;
if (isPublishedPrerequisiteHandoff(fp, reviewedPlan)) return true;
if (isApprovedMaintenanceRecap(fp, reviewedPlan, priorCalls) || isPublishedPrerequisiteHandoff(fp, reviewedPlan)) return true;
const q = call.questions[0]!;
if (q.multiSelect || q.header.trim() !== 'Next steps' || q.options.length !== 2 ||
fp.options.length !== 2 || !fp.options.every((o, i) => o.index === i + 1 && o.label === q.options[i]!.label) ||
@@ -36,6 +38,69 @@ export function isEngCompletionHandoff(fp: AskUserQuestionFingerprint, reviewedP
return ceo.description === 'Optional scope and strategy pass before implementing. ✅ Catches product-level questions the eng review does not ask. ✅ Adds a CEO row to the dashboard. ❌ Little product surface here; likely confirms the current scope.';
}
/** Navigation may repeat already-approved post-review bookkeeping, but cannot
* authorize it afresh or hide new implementation work behind a completion label. */
function isApprovedMaintenanceRecap(fp: AskUserQuestionFingerprint, plan: string,
prior: readonly NativePlanQuestionCall[]): boolean {
const call = fp.nativeCall!, q = call.questions[0]!;
const label = (s: string) => s.replace(/^[1-9]\d*[A-Z]\)\s*/, '').replace(/\s*\(recommended\)$/, '').trim();
const current = (s: string) => !/^(?:\s*>|\s*`{3,}|\s*~{3,})|(?:^|\n)\s*(?:source|example|historical|quoted)\b|["“”]|\b(?:withdrawn|cancelled|canceled|rejected|superseded|no longer current|not approved|no longer approved|pending approval|if approved|once approved|assuming approval|provided approval)\b/i.test(s);
if (q.multiSelect || !/^Next steps?$/i.test(q.header) || q.options.length !== 2 || fp.options.length !== 2 ||
!fp.options.every((o, i) => o.index === i + 1 && o.label === q.options[i]!.label) ||
!/^D[1-9]\d*\s*[—–:-]\s*Next steps?[.:]/i.test(q.question) ||
!/\bEng(?:ineering)? review is (?:clear(?:ed)?|complete[d]?)\b/i.test(q.question) ||
!/\bno UI scope\b/i.test(q.question) || !/\bCEO review is optional\b/i.test(q.question) ||
/\b(?:add|implement|rewrite|build|require|if|unless|assuming|provided|pending)\b/i.test(q.question) ||
!current([q.question, ...q.options.map(o => `${o.label}\n${o.description ?? ''}`)].join('\n'))) return false;
const ready = q.options.find(o => /^Ready to implement(?: [—–-] run \/ship when done)?$/i.test(label(o.label)));
const ceo = q.options.find(o => /^Run \/plan-ceo-review(?: first)?$/i.test(label(o.label)));
if (!ready || !ceo || call.answers?.[q.question] !== ready.label) return false;
const recap = /^Exit plan mode with the reviewed plan\. (?:Post-exit|After exiting): (.+)\.$/i.exec(ready.description ?? '');
const actions = recap?.[1]?.split(/\s+and\s+|;\s*/);
if (!actions || actions.length !== 2) return false;
const routing = actions.filter(a => /^(?:append|add) (?:the )?(?:gstack )?routing rules to CLAUDE\.md$/i.test(a));
const todos = actions.map(a => /^(?:create|write) TODOS\.md with (?:the )?(one|two|three|four|five|six|seven|eight|nine|[1-9]) accepted items?$/i.exec(a)).filter(Boolean);
if (routing.length !== 1 || todos.length !== 1) return false;
const count = Number(todos[0]![1]) || ['one','two','three','four','five','six','seven','eight','nine'].indexOf(todos[0]![1]!.toLowerCase()) + 1;
const identities = prior.map(c => `${c.sessionId}:${c.toolUseId}`);
if (!prior.length || new Set(identities).size !== prior.length || prior.some(c => c.sessionId !== call.sessionId ||
c.toolUseId === call.toolUseId || !c.toolUseId || c.answered !== true || c.failed !== false ||
!Number.isFinite(Date.parse(c.answeredAt ?? '')) || Date.parse(c.answeredAt!) >= Date.parse(call.answeredAt!) ||
!Array.isArray(c.unansweredQuestionIndices) || c.unansweredQuestionIndices.length ||
!c.questions.length || c.questions.length > 4 || Object.keys(c.answers ?? {}).length !== c.questions.length ||
new Set(c.questions.map(q => q.question)).size !== c.questions.length ||
c.questions.some(q => q.multiSelect || q.options.length < 2 || q.options.length > 4 ||
new Set(q.options.map(o => o.label)).size !== q.options.length ||
!q.options.some(o => o.label === c.answers?.[q.question])))) return false;
const approved = prior.flatMap(c => c.questions.map(q => ({ q, selected: label(c.answers![q.question]!) })));
const routingCalls = approved.filter(({q}) => q.header === 'Routing');
if (routingCalls.length !== 1 || routingCalls.filter(({q, selected}) => current(q.question) &&
/\bskill routing rules\b/.test(q.question) && /CLAUDE\.md/.test(q.question) &&
/^(?:Add|Append) (?:gstack )?routing rules to CLAUDE\.md$/.test(selected)).length !== 1) return false;
const accepted = approved.filter(({q, selected}) => /^TODO [1-9]\d*$/.test(q.header) &&
selected === 'Add to TODOS.md' && current(q.question) &&
/\bCaptured in the plan's TODOS section now\b/.test(q.options.find(o => label(o.label) === selected)?.description ?? ''));
if (accepted.length !== count || approved.filter(({q}) => /^TODO [1-9]\d*$/.test(q.header)).length !== count ||
new Set(accepted.map(a => a.q.header)).size !== count) return false;
// Only current, unfenced TODO headings in the published report bind the recap.
let fence: string | undefined;
const lines = plan.split(/\r?\n/).filter(line => {
const mark = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);
if (mark) { if (!fence) fence = mark[1]; else if (mark[1]![0] === fence[0] && mark[1]!.length >= fence.length && !mark[2]!.trim()) fence = undefined; return false; }
return !fence && !/^(?: {0,3}>| {4}|\t)/.test(line);
});
if (fence) return false;
const starts = lines.flatMap((line, i) => /^## TODOS?(?:\.md)?\b/i.test(line) ? [i] : []);
if (starts.length !== 1 || !current(lines[starts[0]!]!) || /:\s*$/.test(lines.slice(0, starts[0]).filter(s => s.trim()).at(-1) ?? '')) return false;
const tail = lines.slice(starts[0]! + 1), end = tail.findIndex(line => /^## /.test(line));
const blocks = (end < 0 ? tail : tail.slice(0, end)).join('\n').trim().split(/\n(?=### )/);
return blocks.length === count && accepted.every(({q}) => {
const subjects = q.question.split('\n')[0]!.match(/\b(?:[a-z]+|[A-Z][a-z]+)(?:[A-Z][A-Za-z0-9]*)+\b/g) ?? [];
return subjects.length === 1 && blocks.filter(b => /^### /.test(b) && current(b) &&
new RegExp(`\\b${subjects[0]}\\b`).test(b.split('\n')[0]!)).length === 1;
});
}
/** A finished backend review may recap an already-published author prerequisite.
* This classifies only its completed navigation; the runner still independently
* requires the owned report, fresh modifying decisions and a later native exit.
+62 -2
View File
@@ -1,4 +1,5 @@
import type { NativePlanQuestionCall, PlanCountTranscript } from './plan-count-transcript';
import type { AskUserQuestionFingerprint } from './claude-pty-runner';
import { hasRetainedLegacyCorpus } from './eng-retained-corpus';
/** Evidence for this fixture's four decision seeds; regression coverage is auto-added by the skill. */
@@ -256,6 +257,38 @@ function completedDecision(call: NativePlanQuestionCall, startedAt: number, fini
q.options.some(o => call.answers?.[q.question] === o.label));
}
/** Structural eligibility for this distinct-issue counter, not seed quality. */
function batchingIssueNumber(call: NativePlanQuestionCall): string | undefined {
if (!completedDecision(call, 0, Date.now()) || call.questions.length !== 1) return;
const q = call.questions[0]!;
const issue = /^(?:D[1-9]\d*\s*[—–:-]\s*)?Issue ([1-9]\d*)\s*:\s*\S[^\n]*$/i.exec(q.question.split('\n')[0]!)?.[1];
if (!issue || !new RegExp(`^(?:Arch(?:itecture)?|Code quality|Tests?|Testing|Performance|Security)(?: ${issue})?$`, 'i').test(q.header.trim())) return;
const optionIds = q.options.map(o => /^([1-9]\d*)([A-D])[.):]\s+\S/i.exec(o.label));
if (optionIds.some(id => id?.[1] !== issue) || new Set(optionIds.map(id => id![2]!.toUpperCase())).size !== q.options.length) return;
// Owned scalar statuses remain current prose; a whole code example does not.
const owner = `(?:(?:this|the|that) (?:issue|finding|decision)|Issue ${issue})`;
const statusPrefix = `(?:^|[.!?;]\\s+|\\n)(?:Correction:\\s*)?${owner} (?:is|was|has been) `;
const scalarOwner = new RegExp(`${statusPrefix}$`, 'i');
const text = q.question.replace(/`([^`\n]+)`/g, (span, body: string, at: number, source: string) =>
scalarOwner.test(source.slice(0, at)) ? body : span);
const inactive = new RegExp(`${statusPrefix}["“'‘]?(?:withdrawn|cancelled|canceled|rejected|superseded|resolved|closed|hypothetical|not current|no longer current)\\b`, 'i');
return inactive.test(prose(text, true)) ? undefined : issue;
}
/** Batching measures separate native issue decisions; seed quality is checked separately. */
export function isEngBatchingIssueAUQ(fp: AskUserQuestionFingerprint, priorCalls: readonly NativePlanQuestionCall[] = []): boolean {
const call = fp.nativeCall;
if (!call || fp.signature !== `${call.sessionId}:${call.toolUseId}` ||
(fp.nativeQuestionIndex !== undefined && fp.nativeQuestionIndex !== 0) ||
priorCalls.some(prior => prior.sessionId !== call.sessionId || prior.toolUseId === call.toolUseId)) return false;
const issue = batchingIssueNumber(call);
if (!issue) return false;
const q = call.questions[0]!;
if (fp.options.length !== q.options.length || !fp.options.every((o, i) => o.index === i + 1 && o.label === q.options[i]!.label)) return false;
// Re-asking an eligible issue cannot inflate the floor; setup and batches do not suppress later separate decisions.
return !priorCalls.some(prior => batchingIssueNumber(prior) === issue);
}
/** A named required test can specify characterization without an "Add" prefix. */
function requiredLegacyCharacterization(task: string): boolean {
const text = task.replace(/\s+/g, ' ');
@@ -1060,7 +1093,18 @@ function hasScheduledLegacyRegression(current: ReadonlyArray<{ title: string; bo
preceding: text.slice(0, text.indexOf(body)).trim().split('\n').at(-1) ?? '',
match: /^- (?:\[[ xX]\] )?(T[1-9]\d*)(?: \([^\n)]*\))? [—–:-] (.+)(?:\n|$)/.exec(body) }));
});
for (const declaration of current) {
// Required test lists may give each suite its own inline label instead of
// a heading. Keep that bullet's body separate from adjacent test requirements.
const declarations: Array<{ title: string; body: string[]; inlineRequired?: boolean }> = [...current];
for (const section of current.filter(s => /\b(?:required|mandatory) tests?\b/i.test(s.title))) {
const blocks = section.body.join('\n').split(/\n(?=- )/);
for (const block of blocks) {
const match = /^- ((?:CRITICAL|MANDATORY|REQUIRED)\b[^\n]*\b(?:regression|characterization)\b[^\n]*)\n([\s\S]+)$/i.exec(block.trim());
if (match && !framed(section.title) && owned(block) && !new RegExp(`\\b${inactive}\\b`, 'i').test(unquoted(match[1]!)))
declarations.push({ title: match[1]!, body: [match[1]!, match[2]!], inlineRequired: true });
}
}
for (const declaration of declarations) {
const requiredRule = /\b(?:mandatory|critical|required)\b/i.test(unquoted(declaration.title));
if (!/\b(?:regression|characterization)\b/i.test(declaration.title) || !requiredRule
|| /\b(?:not|never|no longer) (?:mandatory|critical|required)\b/i.test(declaration.title) || approval.test(unquoted(declaration.title)) || /\b(?:if|when|once|unless) accepted\b/i.test(unquoted(declaration.title))) continue;
@@ -1135,7 +1179,23 @@ function hasScheduledLegacyRegression(current: ReadonlyArray<{ title: string; bo
&& green(statement) && /\bunchanged\b/i.test(statement);
});
});
const scopedBaseline = linkedBaseline || committedBaseline || orderedBaseline;
const inlineBaseline = declaration.inlineRequired && scheduled && taskFiles[0]![1] === files[0]
&& tasks.filter(t => new RegExp(`^ - Files: ${files[0]!.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`, 'm').test(t.body)).length === 1
&& [...text.matchAll(/\bT[1-9]\d*\b/g)].every(m => m[0] === id)
&& new RegExp(`\\b${id}\\b`).test(text)
&& /\b(?:run|execute|replay) (?:the )?same fixtures\b/i.test(text)
&& /\bagainst (?:the )?new path\b/i.test(text)
&& /\bassert (?:identical|matching)\b[^.;]*\b(?:outputs?|outcomes?|session shape)\b/i.test(text)
&& /\b(?:rejection|error) (?:class|kind|code)\b/i.test(text)
&& runs.some(run => green(run) && /\bon (?:the )?legacy(?: path)? before (?:any|the) (?:refactor|rewrite|change)(?: commit)?\b/i.test(run))
&& runs.some(run => green(run) && /\bon both paths\b/i.test(run))
&& current.filter(s => /^Verification(?: \([^)]*\))?$/i.test(s.title)).some(s => {
const first = unquoted(s.body.join('\n').trim().split(/\n(?=\d+[.)] )/)[0] ?? '');
return owned(first) && /^1[.)] (?:run|execute|test|verify)\b/i.test(first)
&& new RegExp(`\\b${id}\\b`).test(first) && /\b(?:untouched|unmodified) legacy path\b/i.test(first)
&& /\bfirst\b/i.test(first);
});
const scopedBaseline = linkedBaseline || committedBaseline || orderedBaseline || inlineBaseline;
if (!scopedBaseline && !scheduledVerification) continue;
// An explicit ordered step provides the old-code oracle; matching a task label alone cannot.
const baseline = scopedBaseline || current.filter(s => /^Verification(?: \([^)]*\))?$/i.test(s.title)).some(s => {
+5 -1
View File
@@ -137,6 +137,8 @@ function validQuestions(value: unknown): value is NativePlanQuestion[] {
*/
export function readPlanCountTranscript(configDir: string, cwd: string,
onPublicToolEvent?: (event: NativePublicToolEvent) => void,
/** Optional exact parent journal, already validated by the owning native hook. */
ownedParentTranscript?: string,
): PlanCountTranscript {
const calls = new Map<string, NativePlanQuestionCall>();
const assistantMessages: PlanCountTranscript['assistantMessages'] = [];
@@ -155,6 +157,7 @@ export function readPlanCountTranscript(configDir: string, cwd: string,
if (!entry.isFile() || !entry.name.endsWith('.jsonl')) continue;
if (++files > MAX_FILES) throw new Error('too many transcript files');
const file = path.join(project, entry.name);
if (ownedParentTranscript !== undefined && file !== ownedParentTranscript) continue;
bytes += fs.statSync(file).size;
if (bytes > MAX_BYTES) throw new Error('transcript exceeds 32 MiB read limit');
const text = fs.readFileSync(file, 'utf8');
@@ -171,7 +174,8 @@ export function readPlanCountTranscript(configDir: string, cwd: string,
if (!line.trim()) continue;
const record = JSON.parse(line);
if (!object(record) || typeof record.sessionId !== 'string' ||
entry.name !== `${record.sessionId}.jsonl`) continue;
entry.name !== `${record.sessionId}.jsonl` ||
(ownedParentTranscript !== undefined && record.agentId != null)) continue;
const parentMetadata = record.isSidechain === false && record.agentId == null &&
typeof record.cwd === 'string' && path.isAbsolute(record.cwd) &&
nativeUuid(record.uuid) && validTimestamp(record.timestamp);
+1
View File
@@ -439,6 +439,7 @@ export const E2E_TOUCHFILES: Record<string, string[]> = {
// confirm" plan write. runPlanSkillFloorCheck cannot detect that shape
// (it exits on first AUQ); runPlanSkillCounting can.
'plan-eng-multi-finding-batching': [
'test/helpers/eng-seeded-coverage.ts', 'test/eng-seeded-coverage.test.ts',
"test/plan-count-session-cwd.test.ts",
"test/plan-scope-recovery-av.test.ts",
+15
View File
@@ -120,6 +120,21 @@ describe('generated outside-review dispatch', () => {
expect(result.stdout).not.toContain('OUTSIDE_STATUS: completed');
});
test(`${host} reports mixed explicit/native conflicts without guessing a repair host`, () => {
for (const markers of [
{CLAUDECODE:'1', CODEX_THREAD_ID:'', CODEX_SANDBOX:'', GSTACK_ACTIVE_HOST:'codex'},
{CLAUDECODE:'', CODEX_THREAD_ID:'codex-fixture', CODEX_SANDBOX:'', GSTACK_ACTIVE_HOST:'claude'},
]) {
const result = invoke(host, {}, markers);
expect(result.status).toBe(78);
expect(fs.existsSync(CAPTURE)).toBe(false);
expect(result.stderr).toContain('markers conflict');
expect(result.stderr).toContain('setup --host <actual-harness>');
expect(result.stderr).not.toContain('Repair installed skills: run setup --host');
expect(result.stdout).not.toContain('OUTSIDE_STATUS: completed');
}
});
test(`${host} detects explicit stale active-host identity without environment marker guesses`, () => {
const result = invoke(host,{},host === 'codex'
? {CLAUDECODE:'',CODEX_THREAD_ID:'',GSTACK_ACTIVE_HOST:'claude'}
+18 -26
View File
@@ -30,8 +30,8 @@ import {
isNumberedOptionListVisible,
selectPtyNumberedOption,
} from './helpers/claude-pty-runner';
import { autoplanArtifactPermissionInput, pendingAutoplanArtifactPermissionInput, publishedAutoplanArtifactPermissionInput, autoplanArtifactMenuKey, autoplanPermissionProgressKey } from './helpers/autoplan-artifact-permission';
import { readPendingAutoplanArtifact, autoplanArtifactRecorderStatus } from './helpers/autoplan-artifact-recorder';
import { autoplanPermissionProgressKey } from './helpers/autoplan-artifact-permission';
import { readPendingAutoplanArtifact, autoplanArtifactRecorderStatus, autoplanArtifactApprovalBoundary } from './helpers/autoplan-artifact-recorder';
import { autoplanSetupDecision, autoplanBlockingQuestionBoundary, type AutoplanSetupDecision } from './helpers/autoplan-setup-question';
import { autoplanPhaseCompletions, type AutoplanPhaseHit } from './helpers/autoplan-phase-observer';
import { readPlanCountTranscript, type PlanCountTranscript, type NativePublicToolEvent } from './helpers/plan-count-transcript';
@@ -87,6 +87,7 @@ describeE2E('/autoplan native chain ordering (periodic)', () => {
observeScreen: true,
observeSetupQuestions: true,
observeAutoplanArtifacts: true,
approveAutoplanArtifactEdits: true,
});
let hits: AutoplanPhaseHit[] = [];
@@ -95,7 +96,7 @@ describeE2E('/autoplan native chain ordering (periodic)', () => {
let pendingArtifact: ReturnType<typeof readPendingAutoplanArtifact>;
let viewportCapturedAt = Date.now();
let methodologyAudit: AutoplanMethodReadAudit[] = [];
let outcome: 'chain_complete' | 'plan_ready' | 'timeout' | 'exited' | 'unsupported_setup' | 'incomplete_methodology' | 'blocked_on_question' = 'timeout';
let outcome: 'chain_complete' | 'plan_ready' | 'timeout' | 'exited' | 'unsupported_setup' | 'incomplete_methodology' | 'blocked_on_question' | 'artifact_permission_failed' = 'timeout';
let unsupportedSetup: Extract<AutoplanSetupDecision, { kind: 'unsupported_setup' }> | null = null;
let blockedQuestion: ReturnType<typeof autoplanBlockingQuestionBoundary> = null;
let evidence = '';
@@ -135,13 +136,14 @@ describeE2E('/autoplan native chain ordering (periodic)', () => {
await Bun.sleep(8000);
session.mark();
commandStartedAt = Date.now();
if (!session.startAutoplanArtifactEditApproval) throw new Error('Owned artifact approval hook unavailable');
session.startAutoplanArtifactEditApproval(commandStartedAt);
session.send('/autoplan\r');
const budgetMs = AUTOPLAN_CHAIN_BUDGET.workMs;
const start = Date.now();
let lastPermSig = '';
let lastPermissionProgress = '';
const seenArtifactPermissions = new Set<string>();
let lastCheckpointAt = start;
const seenSetupQuestions = new Set<string>();
while (Date.now() - start < budgetMs) {
@@ -160,27 +162,17 @@ describeE2E('/autoplan native chain ordering (periodic)', () => {
}
const visible = viewport;
// Cropped artifact edits require current native identity and owned
// file/diff binding. Option 1 grants only this request, once per ID.
const artifactPermission = autoplanArtifactPermissionInput(visible, {
cwd: tempDir, ownedStateRoot: session.hermeticSkillStateRoot,
commandStartedAt, transcriptStatus: transcript.status, publicTools,
}, seenArtifactPermissions) ?? publishedAutoplanArtifactPermissionInput(visible, {
cwd: tempDir, ownedStateRoot: session.hermeticSkillStateRoot, commandStartedAt,
ownedNativePlansRoot: session.hermeticConfigDir ? path.join(session.hermeticConfigDir, 'plans') : undefined,
transcriptStatus: transcript.status, publicTools, pending: pendingArtifact, viewportCapturedAt,
}, seenArtifactPermissions) ?? pendingAutoplanArtifactPermissionInput(visible, {
cwd: tempDir, ownedStateRoot: session.hermeticSkillStateRoot, commandStartedAt,
transcriptStatus: transcript.status, publicTools, pending: pendingArtifact, viewportCapturedAt,
}, seenArtifactPermissions);
if (artifactPermission) {
seenArtifactPermissions.add(artifactPermission.signature);
seenArtifactPermissions.add(autoplanArtifactMenuKey(visible));
capture('artifact_permission'); // Retain the exact pending metadata before input/cleanup.
session.send(artifactPermission.input);
await Bun.sleep(2000);
continue;
// Native hooks exclusively approve owned artifact Edits. Rejection
// is a failure, and pending hooks cannot fall through to UI input.
const artifactStatus = autoplanArtifactRecorderStatus(session.pendingAutoplanArtifactFile, tempDir,
session.hermeticConfigDir, session.hermeticSkillStateRoot);
const artifactBoundary = autoplanArtifactApprovalBoundary(artifactStatus);
if (artifactBoundary === 'failed') {
outcome = 'artifact_permission_failed';
evidence = JSON.stringify(artifactStatus);
break;
}
if (artifactBoundary === 'pending') continue;
// Auto-grant any permission dialog so autoplan can keep moving
// through its phases. The autoplan template auto-decides review
@@ -265,7 +257,7 @@ describeE2E('/autoplan native chain ordering (periodic)', () => {
fullSessionEvidence = diagnosticTail(session.visibleText());
observe();
// Final retained records can include a dispatch published after the loop break.
if (methodologyAudit.some(audit => !audit.passed)) {
if (methodologyAudit.some(audit => !audit.passed) && outcome !== 'artifact_permission_failed') {
outcome = 'incomplete_methodology';
evidence = JSON.stringify(methodologyAudit);
}
@@ -283,7 +275,7 @@ describeE2E('/autoplan native chain ordering (periodic)', () => {
);
}
if (outcome === 'exited' || outcome === 'timeout' || outcome === 'unsupported_setup' || outcome === 'incomplete_methodology') {
if (outcome === 'exited' || outcome === 'timeout' || outcome === 'unsupported_setup' || outcome === 'incomplete_methodology' || outcome === 'artifact_permission_failed') {
throw new Error(
`autoplan chain test FAILED: outcome=${outcome}, exitCode=${exitCode}, hits=${JSON.stringify(hits)}\n` +
`Native transcript: ${transcript.status}; artifacts=${JSON.stringify(artifacts)}\n` +
@@ -23,6 +23,7 @@ import {
} from './helpers/claude-pty-runner';
import { isEngCompletionHandoff } from './helpers/eng-completion-handoff';
import type { NativePlanQuestionCall } from './helpers/plan-count-transcript';
import { evaluateEngSeedCoverage } from './helpers/eng-seeded-coverage';
const describeE2E = describeE2ETier('periodic');
@@ -81,6 +82,7 @@ describeE2E('/plan-eng-review seeded issue coverage (periodic)', () => {
try {
const startedAt = Date.now();
const completedCalls = new Map<string, NativePlanQuestionCall>();
const obs = await runPlanSkillCounting({
skillName: 'plan-eng-review',
slashCommand: '/plan-eng-review',
@@ -90,8 +92,9 @@ describeE2E('/plan-eng-review seeded issue coverage (periodic)', () => {
isSetupAUQ: engSetupAUQ,
isFirstReviewAUQ: engFirstReviewAUQ,
isCompletionHandoffAUQ: fp => {
try { return isEngCompletionHandoff(fp, fs.readFileSync(planPath, 'utf8')); }
try { return isEngCompletionHandoff(fp, fs.readFileSync(planPath, 'utf8'), [...completedCalls.values()]); }
catch { return false; } // Unpublished work cannot establish a closed handoff.
finally { if (fp.nativeCall && !completedCalls.has(fp.signature)) completedCalls.set(fp.signature, fp.nativeCall); }
},
// Extra legitimate decisions are not a failure. The unchanged wall limit
// bounds runaway reviews; coverage below uses scoped completed native calls.
@@ -36,6 +36,7 @@ import {
engFirstReviewAUQ,
} from './helpers/claude-pty-runner';
import { FORCING_BATCHING_ENG } from './fixtures/forcing-finding-seeds';
import { isEngBatchingIssueAUQ } from './helpers/eng-seeded-coverage';
const describeE2E = describeE2ETier('periodic');
@@ -69,6 +70,7 @@ describeE2E('/plan-eng-review multi-finding batching regression (periodic)', ()
isLastStep0AUQ: engStep0Boundary,
isSetupAUQ: engSetupAUQ,
isFirstReviewAUQ: engFirstReviewAUQ,
isReviewAUQ: isEngBatchingIssueAUQ,
reviewCountCeiling: N + 3, // hard cap above floor + tolerance
timeoutMs: 1_500_000, // 25 min
env: { QUESTION_TUNING: 'false', EXPLAIN_LEVEL: 'default' },