Skip to content

refactor(setup): simplify agent setup and stop blocking on strictness - #82

Open
cooper (czxtm) wants to merge 1 commit into
fix/setup-agent-stale-pending-replyfrom
refactor/simplify-setup-agent
Open

cooper (czxtm) wants to merge 1 commit into
fix/setup-agent-stale-pending-replyfrom
refactor/simplify-setup-agent

Conversation

@czxtm

Copy link
Copy Markdown
Member

Stacked on #81.

Why

Every reported stack setup --experimental-agent run failed. None of them failed because the setup itself was broken. They stopped on host-side strictness: protected user files, fixed reply formats, permission denials, and saved-reply recovery loops. Because the user asked for the setup and can revert anything from Git, this PR removes those blockers. Doctor is kept as the check.

What changed

Removed

  • Git guard (~350 lines). Setup no longer protects dirty or untracked files and no longer aborts when the agent changes the index, HEAD, or a preexisting edit. The agent may edit any repository file, including .stack/config.nix and flake.nix. Setup still never commits, stages content, or reverts anything.
  • Saved malformed-reply recovery (setup_agent_reply.go): pending replies, formatting retries, and their manifest fields.
  • Strict reply and plan validation: DisallowUnknownFields, exact-one-object parsing, the 1–8 question rule, and plan or prepare validation that rejected a whole reply.
  • Fatal provider events: non-JSON stdout lines, Codex error events (also sent for reconnects), and Claude permission denials for any tool. These are now warnings.
  • The separate host nix flake lock step and --no-update-lock-file on setup shells. Entering the devshell locks normally.
  • Required checks retained during repair, the doctor reconciler-presence gate, and 15-minute stage limits (now a one-hour hang guard).
  • The Probe help-text flag matching, replaced by --version.

Lenient instead

  • ParseReply takes the first usable JSON object in a reply. This covers prose and Markdown fences, cut-off JSON (it closes strings, brackets, and braces), bare plan objects, and status synonyms. It drops unusable entries, such as paths outside the repository or duplicate IDs, instead of rejecting the reply. A mistyped value, for example "exists":"yes", is not decoded partially.
  • An inspection reply with no JSON becomes the plan summary for the user to review. A write turn's reply is informational, and blocked is shown as a warning before the changes are checked.
  • Noninteractive runs answer a question that has no default with an empty answer, which leaves the choice to the agent.
  • Changing --template, --flake, --agent-model, or addon flags on a rerun starts a new plan instead of erroring. A manifest that can't be read starts a new setup.
  • Doctor still runs, with one repair turn. Checks that doctor reports as skipped are not treated as failures. Problems that remain after the repair turn are listed, and setup continues to runtime and Studio. A failing step before doctor, such as entering the devshell, still stops setup.

Kept

  • Inspection → review → apply → verify → runtime, plus questions, resume, the Pi backend, prepare commands, and doctor --onboarding.
  • Intent-to-add for files the setup created, files the plan lists, and untracked Nix inputs. The untracked files that predate the setup are recorded once per manifest so reruns behave the same. Generated and key directories are never added.

Net change: −1,232 lines across 23 files. The setup docs (apps/docs/content/docs/cli/setup.mdx) were rewritten to match.

Test plan

  • go vet ./cmd/... ./internal/... and go test ./cmd/... ./internal/... pass.
  • tests/test-agent-setup.sh passes all 18 scenarios against the real CLI and doctor. New scenarios: the agent editing dirty and tracked user files, prose replies, a devshell failure followed by a repair turn, and Claude Bash/Glob denials.
  • pkg/nixdata TestSetKey also fails on the base branch. pkg/nixeval TestNixEval requires STACKPANEL_ROOT from the devshell. Neither package is touched here.

The agent may now edit any repository file the setup needs; the user reviews
the result in Git. Removed: the Git guard that protected dirty files and
aborted on index/HEAD changes, saved malformed-reply recovery, strict reply
and plan validation, fatal permission denials and provider warnings, the
separate flake-lock step, retained required checks, and 15-minute stage
limits.

Replies are parsed leniently (first usable JSON object, truncated or fenced
JSON, unusable entries dropped); prose becomes the plan summary or a completed
turn. Doctor still checks the result with one repair turn, skipped checks are
not failures, and remaining problems are reported instead of blocking runtime
setup. New files and Nix inputs are still exposed to flakes with
intent-to-add.
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Preview deployed to pr-82 — https://pr-82.stackpanel.com

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Docs preview deployed to pr-82: https://stackpanel-docs-pr-82.drkmttr.workers.dev

This branch was successfully deployed

2 active deployments
pr-82 — 8cde9898 Deployed Nov 9, 2026 by czxtm via deploy #278
docs-preview — 8cde9898 Deployed Nov 9, 2026 by czxtm via deploy #267
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant