Checks judged against main — Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: A check that cannot pass in Jarvis's check environment never strands a task: the engine refreshes a frozen list from main, tells a pre-existing failure from one the task caused, and lets the agent skip a red check that CI will judge.
Architecture: All of it lives in the OpenPr use case (engine/src/application/tasks/open-pr.ts) and the engine's own git (BranchPublisher port, GitBranchPublisher adapter). Three new journal events (check_preexisting, check_skipped, check_base_result) and a new checks_fixed.source value (base_refresh) carry every decision; the PR body and the thread show them. No owner question is added anywhere.
Tech Stack: TypeScript, Vitest, git CLI via run-git.ts, Zod (shared/src/mcp.ts).
Spec: docs/specs/generic-engine-and-project-knowledge.md, section 6 "Checks that can actually pass". This plan is phase 1 of that spec. Out of scope here and planned separately: the pre-run of candidate commands on base while in Context (it writes into the project record, which does not exist yet — phase 2), project records, discovered environments and containers (phase 3).
Global Constraints
- The worker never chooses which commands run: the list still comes only from
checks_fixedrows the engine writes;base_refreshreadsAGENTS.mdfrom the base branch on the remote, never from the task's worktree or branch. - A refreshed list is never applied when the frozen one has
source: 'worker'(the worker found those commands;AGENTS.mdhad none). - Nothing the worker can write (the clone's config, hooks, refs) is read by a network operation:
baseFilefetches in a throwaway bare repository with the engine's config, aspushdoes. - Base checkouts in the worktree run with the
READ_ONLYgit flags (hooks off) and always restorejarvis/<taskId>in afinally. - No owner question is added. Every decision is a journal event plus, where the owner should know, a
systemmessage in the thread. - English in code, docs and messages. Conventional commits. Stage explicit paths only (parallel sessions share the tree).
Review Focus
- The base checkout fails or is interrupted (run aborted mid-base-run,
checkoutrefused) → the worktree must end onjarvis/<taskId>with the task's head, and the red result is treated as the task's own (no free pass). Test in Task 3. - Every red command is also red on base → the PR opens, no retry is counted, and the PR body says plainly these fail on main too. Test in Task 3.
- A skip names a command that never ran red on this head, or one not in the frozen list → refused with a reason, nothing published. Test in Task 4.
- The base
AGENTS.mdcannot be fetched (network, no file, no table) → no refresh, no error; the frozen list runs as before. Test in Task 2. - A refreshed list equal to the frozen one → no new
checks_fixed, no thread message on every call. Test in Task 2.
Task 1: The engine's git reads the base
Files:
- Modify:
engine/src/application/ports/branch-publisher.ts - Modify:
engine/src/infrastructure/git/git-branch-publisher.ts - Modify:
engine/src/application/testing/fakes.ts(FakeBranchPublisher,FakeCheckRunner) - Test:
engine/src/infrastructure/git/git-branch-publisher.int.test.ts(uses the existinggit-branch-publisher.fixture.tsbare-repo fixture; needs git only, no Docker)
Interfaces:
Produces, on
BranchPublisher:baseFile(input: { taskId: string; repo: RepoTarget; path: string }): Promise<string | null>— the file's content at the tip of the remote base branch, fetched now;nullwhen the file does not exist or the fetch fails (never throws; failures are not the task's problem).mergeBase(taskId: string): Promise<string>—git merge-base HEAD <baseRef>in the worktree, read-only, no network (samebaseRefrule asstatus).onBase<T>(taskId: string, sha: string, run: () => Promise<T>): Promise<T>— detaches the worktree atsha, runsrun, and infinallychecks outjarvis/<taskId>again. Throws if the tree is dirty before the switch.
Produces, on the fakes:
FakeBranchPublisher.baseFiles: Map<string, string>(path → content) and.onBaseCalls: string[];FakeBranchPublishertakes an optionalFakeCheckRunnerand sets itsonBase = truewhilerunexecutes.FakeCheckRunner.scriptOnBase(command, outcome)answers whileonBaseis true (default on base: green).[ ] Step 1: Write the failing integration tests in
git-branch-publisher.int.test.ts:baseFile returns AGENTS.md from the remote base tip, not from the task branch— commit a differentAGENTS.mdonjarvis/T-1and a newer one on the remotemain; expect the remote one.baseFile returns null for a missing file and for an unreachable remote.baseFile does not read the clone's config— seturl.<bare>.insteadOfto a bogus URL in the clone; expect the real content.onBase runs on the merge base and restores the task branch, even when run throws— insiderun,git rev-parse HEADequalsmergeBase('T-1'); after a throwingrun, HEAD isjarvis/T-1at its old sha.onBase does not run a post-checkout hook— install a hook that writes a marker file; expect no marker.
[ ] Step 2: Run them, expect FAIL —
pnpm --filter @jarvis/engine exec vitest run --project int src/infrastructure/git/git-branch-publisher.int.test.ts[ ] Step 3: Implement the three methods.
baseFile: scratchmkdtemp+git init --bare --template=exactly likepush, thenfetch --depth=1 --no-tags <url> <baseBranch>withpushEnv(url)andHARDENING, thenshow FETCH_HEAD:<path>; validatepathwith no..and no leading/; redact errors;rmthe scratch infinally.mergeBaseviaread.onBaseviaREAD_ONLYcheckout --detach --quiet <sha>/checkout --quiet jarvis/<taskId>; validateshawithSHA.[ ] Step 4: Extend the fakes as in Interfaces; existing tests stay green.
[ ] Step 5: Run the int file and
pnpm --filter @jarvis/engine test:unit— PASS;pnpm --filter @jarvis/engine typecheck— clean.[ ] Step 6: Commit
feat(engine): let the engine's git read the base branch and run on it
Task 2: A frozen list refreshes itself from main
Files:
- Modify:
engine/src/application/tasks/open-pr.ts(commandsFor) - Modify:
engine/src/application/queries/journal-text.ts(checks_fixedwithbase_refresh) - Test:
engine/src/application/tasks/open-pr.test.ts(newdescribe('OpenPr — the list follows main'))
Interfaces:
Consumes:
BranchPublisher.baseFile,RepoInfoparsing — addparseCommands(markdown: string): string[]to theRepoInfoport (implemented inAgentsMdRepoInfobyparseAgentsMd(markdown).checkCommands;FakeRepoInforeturnsfound.checkCommandsunlessparsedis set).Produces: journal
checks_fixed { commands, source: 'base_refresh', cardId: null, previous }with actorsystem; threadsystemmessageChecks updated from main's AGENTS.md: <old> → <new>.[ ] Step 1: Write the failing tests:
refreshes a frozen agents_md list when main's AGENTS.md lists different commands— freeze['pnpm test'],baseFiles.set('AGENTS.md', …)parsing to['pnpm test:unit']; expect the gate ran['pnpm test:unit'], achecks_fixedwithsource: 'base_refresh'andprevious: ['pnpm test'], and one thread message containingpnpm test:unit.leaves a worker-found list alone— freeze withsource: 'worker'; gate runs the frozen list, no newchecks_fixed.does nothing when main's list is the same— no new row, no message, on two calls.runs the frozen list when main's AGENTS.md is missing or names no commands.treats a frozen row with source null (approved before sources existed) like agents_md.
[ ] Step 2: Run, expect FAIL —
pnpm --filter @jarvis/engine exec vitest run src/application/tasks/open-pr.test.ts[ ] Step 3: Implement in
commandsFor: afterfrozenCommands, if the latestchecks_fixedsource is not'worker',baseFile({taskId, repo, path: 'AGENTS.md'})→parseCommands→ if non-empty and not equal (order-sensitive) to the frozen list, journal the refresh, post the message, return the new list.journal-text.ts:base_refreshreadsChecks updated from main: <list>.[ ] Step 4: Run the file — PASS; whole engine unit suite — PASS.
[ ] Step 5: Commit
feat(engine): refresh a task's frozen checks when main's AGENTS.md changes
Task 3: A failure main shares is not the task's
Files:
- Modify:
engine/src/application/tasks/open-pr.ts(gate,pullRequestBody) - Modify:
engine/src/application/queries/journal-text.ts - Test:
engine/src/application/tasks/open-pr.test.ts(newdescribe('OpenPr — red on main too'))
Interfaces:
Consumes:
BranchPublisher.mergeBase,BranchPublisher.onBase,CheckRunner.run.Produces: journal
check_base_result { command, baseSha, red: boolean }(cache, one per command and base sha) andcheck_preexisting { command, baseSha, headSha };checks_passedgainspreexisting: string[];OpenPrResultchecks_failedgainspreexisting: string[](red on both — told to the worker as not its to fix). PR body section:## Fails on main too+ per command- ✗ \<cmd>` — red on <baseSha7> as well; CI decides.and the last 20 lines of its tail in a<details>` block.[ ] Step 1: Write the failing tests:
opens the PR when every red command is also red on main, counting no retry— scriptpnpm testred on head andscriptOnBasered; expectok: true,checkRetriesunchanged, onecheck_preexisting, PR body contains## Fails on main tooandpnpm test.counts a retry when the command is green on main— red on head, green on base → today'schecks_failedwithpreexisting: [].mixed: one red on both, one red only on head→checks_failedwithpreexisting: ['<both>'], retry counted, nothing published.runs only the red commands on base, and only once per base sha— twoopen_prcalls on new head shas with the same merge base →onBaseCallshas one entry; the second call readscheck_base_result.a base run that throws or is aborted counts as green on base—onBaserejects → the red is the task's (retry counted) and the nextbranchPublisher.headShais unchanged.a command that could not be started on base is green on base(no free pass from exit 127).on a task that already has a PR, a preexisting failure is told in the thread— the PR body is not rewritten; onesystemmessageFails on main too: pnpm test.
[ ] Step 2: Run, expect FAIL.
[ ] Step 3: Implement in
gate, between phase 2 and phase 3: collect red commands; if any,mergeBase, look up cachedcheck_base_results in the journal, run the uncached ones in onecheckRunner.runinsideonBase(log tochecks/<attempt>-<sha7>-base.log), treat throw / abort /unavailableas green-on-base. In phase 3: if every red is preexisting → record pass withpreexisting, else today's red path withpreexistingattached. Thread thepreexistingresults throughpublishintopullRequestBody.[ ] Step 4: Run the file and the engine unit suite — PASS.
[ ] Step 5: Commit
feat(engine): judge a red check against main before blaming the task
Task 4: The agent may skip a check CI will judge
Files:
- Modify:
shared/src/mcp.ts(open_prschema) - Modify:
engine/src/application/tasks/open-pr.ts(OpenPrInput,execute,gate,pullRequestBody, refusals) - Modify:
engine/src/presentation/mcp/server.ts(open_prdescription) - Modify:
engine/src/application/queries/journal-text.ts - Test:
shared/src/mcp.test.ts,engine/src/application/tasks/open-pr.test.ts(newdescribe('OpenPr — skipping a check'))
Interfaces:
Produces:
open_prinputskip?: { command: string (1..500); reason: string (10..500) }[](max 20);OpenPrInput.skip; refusal reason'skip_not_allowed'withdetailnaming the command and why; journalcheck_skipped { command, reason, headSha }; PR body section## Checks skipped locally — CI decideswith- \<cmd>` — <reason>` and its last red tail.[ ] Step 1: Write the failing tests:
- mcp:
open_pr accepts skip entries and rejects a reason under 10 characters. skips a command that ran red on this head and opens the PR— redpnpm teston SHA (onechecks_failedin the journal), thenopen_pr({ skip: [{ command: 'pnpm test', reason: 'needs Postgres; CI runs it' }] }); expect the gate ran only the other commands,ok: true, acheck_skipped, PR body section with the reason.refuses to skip a command that never ran red on this head(new commit since) →skip_not_allowed, nothing published, no retry.refuses to skip a command not in the frozen list→skip_not_allowed.a skip on a task that already has a PR pushes, leaves the PR body alone and tells the thread— fromFixingwith a PR:ok: true,codeHost.pullRequestsunchanged, one threadsystemmessageSkipped locally: pnpm test — <reason>.
- mcp:
[ ] Step 2: Run, expect FAIL.
[ ] Step 3: Implement: validate before the gate (frozen list membership; a
checks_failedrow with thisheadShawhoseresultshas the command red); run the gate on the remaining commands (all skipped → no gate, treat as green); journal each skip; carry skips topullRequestBody/ thread message. Description inserver.ts: one sentence onskipandskip_not_allowed.[ ] Step 4: Run
pnpm --filter @jarvis/shared test, the engine file and suite — PASS; both typechecks clean.[ ] Step 5: Commit
feat(engine): let the worker skip a red check that CI will judge
Task 5: Tell the agent and record the decision
Files:
Modify:
agent/prompts/worker.md(section "6. PR", step 2, and "Fix rounds")Modify:
docs/decisions/architecture/0022-engine-runs-the-checks-and-opens-the-pull-request.mdModify:
STATUS.mdTest:
engine/src/application/runs/run-prompt.test.tsonly if it snapshotsworker.md(update the snapshot; no new test)[ ] Step 1: Worker prompt — add to "6. PR" step 2: a
checks_failedlistspreexistingcommands: those fail on main too and are not yours to fix — do not chase them. If a command keeps failing for a reason outside your diff (a service, credentials, ports, the environment) callopen_pragain withskip: [{command, reason}]; CI runs it. Never skip a failure your own diff caused that you can fix within the retries; neverask_ownerabout the check environment.[ ] Step 2: ADR-0022 — add a section "Amendment 2026-11-10: judged against main" stating the three rules (refresh from the remote base's
AGENTS.mdunlesssource: worker; red on both is not the task's and does not block; the worker may skip a command that ran red on the current head) and their Confirmation RULE lines; adjust the RULE "open_pr pushes nothing … while any frozen check command exits non-zero" to "… exits non-zero, unless it is red on the merge base too or the worker skipped it after it ran red on that commit".[ ] Step 3: STATUS.md — one Done bullet with the three behaviours and the commit range.
[ ] Step 4: Run
pnpm typecheck,pnpm lint,pnpm --filter @jarvis/engine test:unit,pnpm --filter @jarvis/shared test,pnpm --filter @jarvis/web test— all PASS.[ ] Step 5: Commit
docs: tell the worker how checks are judged and amend ADR-0022
Task 6: Ship
- [ ] Step 1: Check no run is live on the server (
select count(*) from runs where status='running'= 0), thenpnpm run deploy:remote; expectdeploy: done, now at <sha>. - [ ] Step 2: In T-3's thread, the next
open_prshould journalchecks_fixed (base_refresh)withtest:unitand open the PR. Report the outcome to the owner.