Implementation Plan: watch sources (ADR-0024)
Goal: the pull-request watcher becomes the first WatchSource. A source reads a snapshot, a pure diff turns the stored state and the snapshot into keyed events, and a rule says what an event does. Later, a schedule, a GitHub issue feed and a default-branch CI feed are further sources that can start tasks, each behind caps and the owner's go/no-go. Exactly-once (CI-09) and "no model call while nothing changed" (CI-02, NFR-03) hold for every source because the runner and the types enforce them.
Decision: docs/decisions/architecture/0024-watch-sources-one-mechanism-for-every-status-source.md (proposed). It is binding for this plan once the owner accepts it; where this plan and the ADR disagree, the ADR wins and the task reports the disagreement instead of guessing. Extends ADR-0007, ADR-0017; constrains ADR-0013 and ADR-0012.
Out of this plan: the long-running job source (the seam is the WatchType union and nothing else); a cron syntax; commenting on or labelling issues; folding summary / last_green / rerun_head_sha into state; any new web screen or change to web/; edits to the spec, STATUS.md and the ADR index (the owner does those when a phase is accepted).
Prerequisites (not tasks of this plan)
Three things land before any phase is implemented. Steps that need them say so.
| Prerequisite | Needed by | If it lands differently |
|---|---|---|
Agent memory (docs/plans/agent-memory.md, ADR-0021) | phase 2+ edit run-prompt.ts, start-run.ts, shared/src/config.ts, update-config.ts — files memory also touches | rebase on the memory change; do not start phase 2 while those files carry uncommitted memory edits |
ADR-0022 engine-side checks and PR (no worker has GH_TOKEN) | step 3.6 (Closes line in the PR body), step 4.4 (the engine fetches CI logs) | the two steps move to wherever the engine composes the PR body / fetches logs |
ADR-0023 workflow registry (WorkflowId, one definition per task kind) | steps 2.2, 2.6, 4.5 | phase 1 does not depend on it. Until it exists, WorkflowId is TaskKind (build | ui_check) and "startable from a watch" is a constant in application/watch/workflows.ts that 0023's registry replaces |
Phase 1 depends on none of the three and can ship alone and first.
Global constraints
- No new dependency in any
package.json. No cron parser. - Onion rule (ADR-0002): pure
difffunctions and the event/action types live indomain/; ports inapplication/ports/; the runner, reactions and rules inapplication/watch/; Drizzle only ininfrastructure/db/; Octokit only ininfrastructure/github/(ADR-0007). SnapshotReaderandWatchDiffersignatures take no repository, outbox or scheduler (ADR-0024).- Every string an outsider wrote reaches a prompt only through
untrustedContent()(ADR-0017) and never reaches atitleordescriptionfield. - No test runs the real
claude(ADR-0011). - Do not commit, stage or stash. Other sessions work in this tree and several files this plan touches may carry uncommitted changes. Edit on top of what is there; do not revert or reformat unrelated lines.
- Each task ends with its module's tests and typecheck green (commands in
AGENTS.md) andpnpm exec prettier --checkclean on the files it touched. - Integration tests need Docker (real Postgres, ADR-0011). Tasks that need it say so. The plain
pnpm --filter @jarvis/engine testruns the int project as well, so run it with Docker up.
Contracts (fixed here so the tasks agree)
Types are the sketches in ADR-0024 ("The three parts"); names and file locations below are binding.
| What | Where |
|---|---|
WatchType, WatchEvent, IgnoredInput, DiffResult, WatchDiffer | engine/src/domain/watch-source.ts |
diffPullRequest and its types | stay in engine/src/domain/watch.ts, unchanged; wrapped as a WatchDiffer |
WatchTarget, SnapshotReader | engine/src/application/ports/watch-source.ts |
WatchEventRepository, WatchEventRecord, WatchEventStatus | engine/src/application/ports/watch-event-repository.ts |
Watch (generic row), WatchRepository | engine/src/application/ports/watch-repository.ts |
WatchAction, ExternalText, StartLimits, RuleResolver | engine/src/application/watch/rules.ts |
RunWatches (the runner), source registry | engine/src/application/watch/run-watches.ts, .../registry.ts |
| conformance suite | engine/src/domain/watch-source.contract.test.ts (helper describeWatchDiffer(...)) |
The generic Watch
export interface Watch {
readonly id: string; // 'pr:<taskId>' for pull requests; the config id for a declared source
readonly type: WatchType;
readonly taskId: string | null; // null for a declared source
readonly prNumber: number | null; // pull_request only
readonly state: unknown | null; // the source's cursor; WatchState for pull_request
readonly lastCheckedAt: IsoTime | null;
readonly status: 'active' | 'inactive';
readonly threadId: string | null; // where this source's notices go
// pull_request only, unchanged meaning:
readonly summary: WatchSummary | null;
readonly lastGreen: GreenRun | null;
readonly rerunHeadSha: string | null;
}
export interface WatchRepository {
get(id: string): Promise<Watch | null>;
getByTask(taskId: string): Promise<Watch | null>; // replaces today's get(taskId)
save(watch: Watch): Promise<void>;
listActive(): Promise<readonly Watch[]>; // task-bound, task not terminal — the Overview's meaning
listDue(): Promise<readonly Watch[]>; // every active row; the runner applies each source's interval
}newWatch(taskId, prNumber) returns id: 'pr:' + taskId, type: 'pull_request', status: 'active', threadId: null.
Event keys (deterministic, from the snapshot)
| Event | Key |
|---|---|
ci_completed | ci:<headSha>:<check run ids joined by ","> (re-runs add higher ids, so a re-run is a new key — as diffPullRequest reports it again today) |
review | review:<reviewId>:<state> |
comment | comment:<commentId> (already namespaced issue:/review:) |
| ignored comment | ignored:<commentId> |
schedule_due | schedule:<sourceId>:<slot as YYYY-MM-DDTHH:mm local> |
issue_labelled | issue:<owner/name>#<number> |
default_branch_red | main-red:<owner/name>:<workflow run id> |
Config (phase 2 and later; strict, no credentials)
watch: {
pollSeconds: number; // existing; also the runner's tick
maxStartsPerDay: number; // default 5, all sources together
deferHours: number; // default 24
sources: Array<ScheduleSource | GithubIssuesSource | DefaultBranchCiSource>; // default []
}
// every source: { id: string /^[a-z0-9][a-z0-9-]{0,39}$/, enabled?: boolean (default true),
// intervalSeconds?: number (default watch.pollSeconds),
// start: { workflow: string, repo?: 'owner/name', title?: string, description?: string,
// maxStartsPerDay: number, maxOpenTasks: number } }
// ScheduleSource: { type: 'schedule', at?: 'HH:mm', days?: ('mon'..'sun')[], everyMinutes?: number }
// exactly one of `at` / `everyMinutes`; `start.repo`, `start.title`, `start.description` required
// GithubIssuesSource: { type: 'github_issues', repo: 'owner/name', label: string (default 'jarvis') }
// DefaultBranchCiSource:{ type: 'default_branch_ci', repo: 'owner/name' }id is unique across sources; duplicate ids are a config error.
Ledger statuses
applied (the action ran), deferred (over a cap; will be retried, data kept), dropped (deferred past deferHours), ignored (seen and not acted on, e.g. an unlisted commenter).
Phase 1 — Refactor: the pull-request watcher becomes the first source (ships alone)
Behaviour change: none. CI-01..09 and every existing test are the safety net. The existing tests call app.pollPullRequests.execute(); keep that property as an alias of the new runner so code-host.test.ts, tasks.test.ts and pr-open-flow.ts stay byte-identical.
Task 1A — schema, ports, repositories, fakes, the contract suite (needs Docker)
Owns: engine/src/domain/watch-source.ts (new) + engine/src/domain/watch-source.contract.test.ts (new), engine/src/domain/index.ts, engine/src/application/ports/watch-repository.ts, engine/src/application/ports/watch-event-repository.ts (new), engine/src/application/ports/watch-source.ts (new), engine/src/application/ports/unit-of-work.ts, engine/src/application/code-host/new-watch.ts, engine/src/infrastructure/db/schema.ts, engine/src/infrastructure/db/watch-repository.ts, engine/src/infrastructure/db/watch-event-repository.ts (new), engine/src/infrastructure/db/unit-of-work.ts, engine/src/infrastructure/db/repositories.contract.int.test.ts, engine/drizzle/0005_*.sql + engine/drizzle/meta/**, engine/src/application/testing/in-memory-database.ts, engine/src/application/testing/in-memory-repositories.ts.
- [ ] 1A1.
domain/watch-source.ts: the types of ADR-0024 "The three parts" for the domain half (WatchType,WatchEvent,IgnoredInput,DiffResult,WatchDiffer). Export fromdomain/index.ts. No IO, no imports fromapplication/. - [ ] 1A2.
application/ports/watch-source.ts:WatchTarget,SnapshotReader.application/ports/watch-event-repository.ts: the interface and record types from the ADR.application/ports/watch-repository.ts: the genericWatchandWatchRepositoryabove (keepWatchSummary,GreenRun,WatchedCheck,WatchedCommentwhere they are). AddwatchEvents: WatchEventRepositorytoRepositoriesinunit-of-work.ts. - [ ] 1A3.
newWatchreturns the new shape (id: 'pr:'+taskId, the defaults above). - [ ] 1A4.
schema.ts:watchesgetsid(primary key),type,status,threadId(FKthreads);taskIdandprNumberbecome nullable;watchEventstable; the check constraints and the partial unique index ontask_idfrom ADR-0024 (uniqueIndex(...).where(sql\task_id is not null`)`). - [ ] 1A5. Migration. Run
pnpm --filter @jarvis/engine db:generate, then edit the generated0005_*.sqlso the data survives, in this order: addidnullable →UPDATE watches SET id = 'pr:' || task_id→DROP CONSTRAINT watches_pkey(the name Postgres gave the column-level key in0000_black_gideon.sql; confirm with\d watcheson a migrated database) →SET NOT NULL→ADD PRIMARY KEY (id)→ dropNOT NULLontask_idandpr_number→ addtype,status,thread_id→ the unique index → the checks →CREATE TABLE watch_eventsand its two indexes. Keep--> statement-breakpointbetween statements as the earlier migrations do. Do not hand-edit themeta/*_snapshot.json; ifdb:generateand the edited SQL disagree about the end state, the snapshot is the generator's and the SQL must reach the same schema. - [ ] 1A6.
PgWatchRepository:get(id),getByTask,save(conflict targetid),listActive()(join on tasks, as now, restricted totask_id is not null),listDue()(every row withstatus = 'active'; each source's own interval is applied by the runner, because the interval lives in config, not in the row — so the port takes no arguments).PgWatchEventRepository: every method of the port;recordisINSERT ... ON CONFLICT DO NOTHINGand returns whether a row was inserted;startedSincecountsappliedrows whose type belongs to astart_taskaction — store that asdata-independent by recordingtaskIdnon-null for a started task and countingtask_id is not null and status = 'applied' and at >= since. - [ ] 1A7. In-memory fakes:
InMemoryWatchRepositorykeyed byid,getByTaskscanning; anInMemoryWatchEventRepositorywith the same semantics as the Postgres one (the contract test below runs against both). AddwatchEventsto the in-memory database tables and its reset. - [ ] 1A8.
watch-source.contract.test.ts:describeWatchDiffer({ name, differ, baseline, changed, context })registers the generic cases — same snapshot twice yields no second event; keys are stable across two evaluations; every key is non-empty and unique within one result;diff(null, baseline)per the source's declaredstartsTasksflag (a task-starting source emits no event for the baseline). Nothing runs it yet except 1B. - [ ] 1A9. Extend
repositories.contract.int.test.tsfor both watch repositories on real Postgres and the fakes: save/get/getByTask round trip including a task-less row;recordtwice returnstruethenfalse;releasethenrecordreturnstrueagain;listActiveomits task-less rows and rows of terminal tasks. Add a migration test: apply migrations up to 0004, insert a watch row, apply 0005, assert the row survives withid = 'pr:' || task_id,type = 'pull_request', its state intact (use the existing int-test database helper inengine/test/db.ts; if it only applies all migrations, write the 0004 fixture row through raw SQL against a database migrated to 0004 withdrizzle-kit's migrator and amigrationsFoldercopy that stops at 0004).
Done when: pnpm --filter @jarvis/engine test (Docker up) and pnpm --filter @jarvis/engine typecheck pass. Code in 1B/1C does not exist yet, so call sites of tx.watches.get(...) that still take a task id (report-pr.ts, the four queries, poll-pull-requests.ts) are updated by 1B — until 1B lands the engine does not typecheck, so run 1A and 1B in one working session and check the typecheck after 1B.
Task 1B — the runner and the pull-request source (after 1A)
Owns: engine/src/application/watch/** (new: run-watches.ts, registry.ts, pull-request-source.ts, rules.ts, run-watches.test.ts, pull-request-source.test.ts), engine/src/application/code-host/poll-pull-requests.ts (deleted, content moved), engine/src/application/code-host/handle-code-host-change.ts (touched only for the return type if needed), engine/src/application/create-application.ts, engine/src/application/index.ts, engine/src/application/tasks/report-pr.ts, engine/src/application/queries/{get-overview,get-tasks,get-task}.ts, engine/src/application/conversation/list-tasks.ts.
- [ ] 1B1.
rules.ts:WatchAction(all three variants),ExternalText,StartLimits,RuleResolver, as in the ADR. Types only in this phase; onlyresume_taskis applied. - [ ] 1B2.
pull-request-source.ts: (a)pullRequestDiffer: WatchDiffer<WatchState, PullRequestSnapshot, WatchContext>that callsdiffPullRequestand maps eachCodeHostChangeto aWatchEventwith the key table above (datacarries whatHandleCodeHostChangeneeds: the original change objects are kept in an in-memory side list returned alongside, so no comment body is stored in the ledger); (b) aSnapshotReaderover the existingCodeHost.snapshot(prNumber, repo)— the repo comes from the task'stargetRepo(ADR-0012); (c) the reaction: it calls the unchangedHandleCodeHostChange.handlewith the samePullRequestDiffit always received.HandleCodeHostChangeandbuildSummaryare not rewritten. - [ ] 1B3.
run-watches.ts:RunWatches.execute()implements ADR-0024 "The runner owns the guarantees" for the pull-request source: list due watches; for apull_requestwatch skip unless the task is inPR Open(the current guard, checked before the snapshot and again inside the transaction); read the snapshot outside the transaction; inside one transaction re-read the watch, diff,recordeach event, drop events already recorded, call the reaction with only the new ones,savethe state / summary /lastGreen/rerunHeadSha/lastCheckedAt; calloutbox.taskChangedwhen the summary changed (as now); return the samererunrequest. One watch failing does not stop the others; a quiet tick writes nothing and logs nothing at info level. Bot-login read stays once per tick, only when a due pull-request watch exists. - [ ] 1B4. The flaky-CI compensation: when
codeHost.rerunFailedChecksthrows, the existing code clearsstate.checksso the red result is reported on the next tick. Alsoledger.release(watch.id, <the ci key>)in the same transaction, otherwise the ledger swallows the second report. Test: the re-run call throws, the next tick reports the failure once and moves the task toFixing. - [ ] 1B5.
registry.ts: a mapWatchType → { differ, reader, startsTasks }; onlypull_requestis registered. An unknowntypein a stored row is logged and skipped, never thrown. - [ ] 1B6. Move the body of
PollPullRequestsintoRunWatches; deletepoll-pull-requests.ts.create-application.tsbuildsrunWatchesand exposes it asrunWatchesand aspollPullRequests(same instance, a comment marking the alias as temporary).index.tsexports. - [ ] 1B7. Mechanical call-site changes for the new
WatchRepository:report-pr.ts(getByTask,newWatch, keep the "same PR number keeps its state" rule),get-overview.ts(listActive()unchanged in meaning; map only watches with ataskId),get-tasks.ts,get-task.ts,list-tasks.ts(getByTask). No change to any DTO or toshared/. - [ ] 1B8. Tests.
run-watches.test.ts: a quiet tick requests zero runs and writes zero messages and zero ledger rows; a repeated event from a deliberately broken differ is applied once; two overlappingexecute()calls apply a change once; a failing snapshot for one watch does not stop the next.pull-request-source.test.ts: rundescribeWatchDifferoverpullRequestDifferwith the fixturesdomain/watch.test.tsalready builds. Run the whole existingcode-host.test.ts,tasks.test.tsand the flow tests unchanged — they are the acceptance test of this phase.
Done when: pnpm --filter @jarvis/engine test and pnpm --filter @jarvis/engine typecheck pass with Docker up; git diff --stat shows no change to code-host.test.ts, watch.test.ts, tasks.test.ts or testing/pr-open-flow.ts; grep -rn "PollPullRequests" engine/src finds nothing but the alias comment.
Task 1C — the timer (parallel with 1B once 1A's ports exist)
Owns: engine/src/presentation/watcher/**, engine/src/presentation/timers/index.ts, engine/src/container.ts.
- [ ] 1C1.
watcher.ts: renamecreatePrWatcher→createWatcher(name: 'watcher'in logs), callingrunWatches.execute(). Sameimmediate: truecatch-up and the samewatch.pollSecondsre-read each tick. Updatewatcher.test.tsfor the rename only. - [ ] 1C2.
timers/index.ts: usecreateWatcherwithapp.runWatches. The header comment says "watcher", not "PR watcher". - [ ] 1C3.
container.ts: no new wiring is expected in phase 1 beyond whatcreate-application.tsbuilds; verify the app still starts (pnpm --filter @jarvis/engine testflow tests) and change the file only if the composition root namespollPullRequests.
Done when: pnpm --filter @jarvis/engine test && pnpm --filter @jarvis/engine typecheck pass.
Task 1D — docs after merge (owner or the orchestrating session)
Owns: docs/architecture/README.md, STATUS.md, docs/decisions/architecture/README.md.
- [ ] 1D1. The watcher paragraph of the architecture README describes sources, the runner and the ledger.
- [ ] 1D2.
STATUS.md: Done entry for phase 1; "No scheduling" stays a known gap until phase 2. - [ ] 1D3. ADR index row for 0024.
Phase 1 go/no-go (owner): the refactor ships when every existing test is green and the owner has run one real pull request through CI red → fix → green → approval on the laptop.
Phase 2 — Task-less watches, start_task, caps, and the schedule source
Owner go/no-go #1: the first source. Recommendation: the schedule, because nothing an outsider wrote reaches it (ADR-0024 open question 3). Needs prerequisites: memory landed, and — for steps 2.2 and 2.6 — ADR-0023 (or the TaskKind stopgap in the table above).
Task 2A — config contract and the lock-down
Owns: shared/src/config.ts, shared/src/config.test.ts, jarvis.config.example.json, engine/src/application/config/update-config.ts, engine/src/application/config/update-config.test.ts.
- [ ] 2A1.
shared/src/config.ts: thewatchblock from "Contracts → Config":maxStartsPerDay,deferHours,sources(strict discriminated union ontype; onlyscheduleis accepted in this phase — the other two types are added by their phases, so a config naming them fails with a readable error). Refinements: uniqueid; a schedule has exactly one ofat(HH:mm, 24h) oreveryMinutes(1–1440);daysonly withat;start.repomatchesowner/name. - [ ] 2A2. Example config: one disabled example schedule, commented in prose in the field names only (JSON has no comments):
"enabled": false. - [ ] 2A3.
update-config.ts: add'watch.sources','watch.maxStartsPerDay','watch.deferHours'toFORBIDDEN_PATHSwith a comment citing ADR-0024. Tests: a patch touching any of the three is rejected whole, alongside a valid key;watch.pollSecondsis still accepted. - [ ] 2A4. Config tests: valid and invalid examples for every refinement; an unknown source type; a stray
tokenkey is rejected (strictness).
Done when: pnpm --filter @jarvis/shared test && pnpm --filter @jarvis/shared typecheck and pnpm --filter @jarvis/engine test -- update-config plus engine typecheck pass.
Task 2B — the schedule differ (parallel with 2A)
Owns: engine/src/domain/watch-schedule.ts (new) + engine/src/domain/watch-schedule.test.ts (new), engine/src/domain/index.ts.
- [ ] 2B1.
diffSchedule(previous: { lastSlot: string | null } | null, snapshot: { now: IsoTime }, spec: ScheduleSpec): pure. A slot is a localYYYY-MM-DDTHH:mm. Forat+days, the due slot is the latest slot ≤nowthat matches a listed day (default all days); foreveryMinutesit isfloor(now / every)aligned to the local day start. Statenullis a baseline: it stores the latest due slot and emits nothing. Later: if the latest due slot is newer thanlastSlot, emit oneschedule_dueevent with keyschedule:<id>:<slot>anddata: { slot, missedSlots }, wheremissedSlotscounts the matching slots strictly betweenlastSlotand the new one; never more than one event per call. - [ ] 2B2. Local time uses the same notion as
application/runs/local-day.ts(process-local zone viaDate). DST: a slot that does not exist on a spring-forward day fires at the next valid time; a repeated hour fires once (the slot key is the local wall-clock string, so the repeated hour is the same key). Tests withTZfixed in the test file. - [ ] 2B3. Tests: baseline emits nothing; fires once at the slot; same
nowtwice → one event; the laptop slept three days → one event withmissedSlots: 2; weekend skipped;everyMinutesalignment; restart with the same stored state → nothing. Register the differ withdescribeWatchDiffer(startsTasks: true).
Done when: pnpm --filter @jarvis/engine test && pnpm --filter @jarvis/engine typecheck.
Task 2C — starting a task from a watch (after 1B, 2A, 2B)
Owns: engine/src/application/watch/start-task.ts (new) + test, .../caps.ts (new) + test, .../reconcile.ts (new) + test, .../schedule-source.ts (new) + test, .../workflows.ts (new), .../run-watches.ts and .../registry.ts (extended), .../rules.ts, engine/src/application/tasks/create-task.ts (extract only), engine/src/application/create-application.ts, engine/src/application/index.ts.
- [ ] 2C1.
create-task.ts: extract the part ofCreateTask.executethat, inside a transaction, creates the worktree, builds the task, writes thetask_createdjournal entry and requests the start run intocreateTaskWithin(tx, outbox, input);CreateTaskkeepsrequireDispatcher, repo resolution and the thread lookup and calls it. The existingcreate-tasktests must pass unchanged. The extracted function takes anactor: 'agent' | 'system'for the journal and an optionalorigin: { watchId: string; eventKey: string }that is written intotask_created's data. - [ ] 2C2.
workflows.ts:isStartableFromWatch(workflow)— until ADR-0023 exists,buildis allowed andui_checkis not; after 0023 this reads the registry's flag.reconcile.tsand config validation call it. - [ ] 2C3.
start-task.ts—StartTaskFromWatch.execute(tx, outbox, { watch, event, action }): resolveaction.repothrough the ADR-0012RepoResolver(rejects anything off the allow-list, and Jarvis's own repository unlessrepos.allowSelf; a rejection settles the eventdroppedwith a notice, not an exception that stalls the tick); open a new thread titled with the action'stitle; post asystemmessage ("Started by schedule<id>for slot <slot>") — never anownermessage; callcreateTaskWithinwith the action'sdescriptionandexternal; settle the ledger rowappliedwith the newtaskId. No dispatcher run is requested. - [ ] 2C4.
caps.ts:checkCaps(tx, watch, source, now)→ok | { reason, scope }usingstartedSince,startedSinceAllandopenTasks, local-day window. Over a cap the runnerrecords the event asdeferredwith itsdataand posts one notice per source per day into the watch's notice thread (create it on first use, titleWatch: <id>, storethread_idon the watch). Tests: the N+1th start is deferred; global cap counts across sources; an open task blocks the next start; a terminal task frees the slot. - [ ] 2C5.
run-watches.ts: at the start of each tick, for each active declared watch, retry itsdeferredrows oldest first through the same caps andStartTaskFromWatch; rows older thandeferHoursbecomedroppedwith one notice. A tick with nothing due and nothing deferred still starts nothing. Declared watches are polled only whenlastCheckedAt + intervalSeconds <= now. - [ ] 2C6.
schedule-source.ts: theSnapshotReader({ now: clock.now() }, no IO), the differ from 2B, andRuleResolverbuilding thestart_taskaction from the source'sstartblock:title,descriptionandrepocome from config (trusted),externalis empty. - [ ] 2C7.
reconcile.ts:reconcileWatchSources(config, repo)— insert a row for each declared id, keepstatefor an existing id, setstatus = 'inactive'for an id that vanished or hasenabled: false, set it back toactivefor a returning id without clearingstate. Fail with a readable error (the LIM-02 style) for an unknown or non-startableworkflow. Called once at startup and from the existing config-change listener; add the wiring increate-application.ts(the listener lives in the timers'onConfigChange; the runner calls reconcile at the beginning of each tick instead, which needs no new listener — prefer that). - [ ] 2C8. Tests, runner level, on the in-memory database and a fake clock: a schedule fires once at its slot and starts one task with a
systemfirst message; the same tick twice → one task; the engine "restarts" (a new runner over the same database) → no second task; a 3-day sleep → one task withmissedSlots: 2; over the daily cap →deferred, retried the next day,droppedafterdeferHours; an unknown workflow in config → startup error; a quiet tick requests zero runs.
Done when: pnpm --filter @jarvis/engine test (Docker up) and pnpm --filter @jarvis/engine typecheck, and pnpm lint is clean for the engine.
Task 2D — agent definition for a task nobody typed (parallel with 2C)
Owns: agent/prompts/worker.md.
- [ ] 2D1.
worker.md: the run context may carryorigin: schedule(and laterissue,ci). Say what it changes: nobody is waiting in the thread yet, so the first thing the worker does is post onepost_updatesaying what it understood and, when the description is not enough to write a spec,ask_owner; the owner is not assumed to be at the keyboard. It changes nothing about the permission rules, the Spec Review gate or the memory rules. - [ ] 2D2. The run context rendering (
origin:line) is added by 2C3's journal data and read inengine/src/application/runs/run-prompt.ts— this file is memory's (task B4); coordinate: the one-line addition is made by whoever holds the file, after memory landed. If that is not possible, 2D2 is dropped andoriginis mentioned in the description text instead.
Done when: pnpm exec prettier --check agent/prompts/worker.md is clean and the prompt's field names match the run context the engine renders.
Phase 2 order: 2A and 2B and 2D start together; 2C starts when 1B is done and 2A, 2B report green. Phase 2 go/no-go (owner): one real schedule, enabled: true, fired on the laptop for two days including one sleep, produced exactly the expected tasks and no model run on any quiet tick.
Phase 3 — GitHub issue as task input
Owner go/no-go #2, after phase 2. Recommendation in ADR-0024: label applied by an allowlist.githubReviewers login, repo resolvable, no comment back on the issue. Needs prerequisites: ADR-0022 for step 3.6.
Task 3A — GitHub issue reader (infrastructure)
Owns: engine/src/application/ports/issue-host.ts (new), engine/src/infrastructure/github/** (new github-issue-host.ts + test; index.ts), engine/src/container.ts.
- [ ] 3A1. Port
IssueHost:labelledIssues(repo: RepoTarget, label: string): Promise<readonly IssueView[]>whereIssueView = { number, title, body, author, url, state, labels: string[], labelledBy: string | null, labelledAt: IsoTime | null }.labelledBy/labelledAtcome from the issue'slabeledevent for that label — the latest such event;nullif the events cannot be read (the differ then does not fire). - [ ] 3A2.
GitHubIssueHostover Octokit using the engine's existing client andguard()error mapping. Only open issues, only issues (not pull requests — the API lists PRs as issues; filter on thepull_requestfield). Use a conditional request (If-None-Match) per source if the existing client wrapper makes it cheap; otherwise leave it and rely onintervalSeconds(default 120). Mark in the report which was done. - [ ] 3A3. Tests with the project's existing GitHub test doubles (see
github-code-host.test.ts): PRs excluded; the latest label event wins; a missing events response yieldslabelledBy: null.
Task 3B — the issue differ (parallel with 3A)
Owns: engine/src/domain/watch-issues.ts (new) + test, engine/src/domain/index.ts.
- [ ] 3B1.
diffIssues(previous: { seen: number[] } | null, snapshot: IssueView[], context: { triggers: string[]; botLogin: string }): statenull= baseline: record every currently labelled issue number as seen and emit nothing. Later: an issue not inseenwhoselabelledByis a login intriggers(case-insensitive, not the bot) → oneissue_labelledevent, keyissue:<repo>#<n>,data: { number, url, labelledBy }; the title and body are not indata— they are read again by the reader at action time (3C3). An issue labelled by anyone else →ignoredwith reasonlabel_not_by_triggerand added toseen(so it never fires later). Unlabelling does not remove fromseen; relabelling an issue alreadyseendoes not fire (document in the test name — this is open question 6's cost). - [ ] 3B2. Tests including the conformance suite (
startsTasks: true), a label by a stranger, a PR in the list, a deleted issue, and an issue that appears labelled for the first time during the second poll.
Task 3C — application, config and prompts (after 3A, 3B; edits files memory/0023 also touch)
Owns: shared/src/config.ts + test (add github_issues to the union), jarvis.config.example.json, engine/src/application/watch/issue-source.ts (new) + test, .../registry.ts, .../start-task.ts, engine/src/application/runs/start-run.ts, engine/src/application/runs/run-prompt.ts (+ tests), engine/src/application/queries/journal-text.ts, agent/prompts/worker.md.
- [ ] 3C1. Config:
GithubIssuesSourcein the union;start.repois taken from the source'srepo;start.title/start.descriptionare optional static text (a template without any placeholder for issue content — reject{{in them). - [ ] 3C2.
issue-source.ts: registers reader + differ with the context{ triggers: config.allowlist.githubReviewers, botLogin }; theRuleResolverbuilds the action:title = "Issue <repo>#<n>",description = start.description ?? "Work on the linked issue."plus the fixed lineorigin: issue <repo>#<n>, andexternal = [issue-title, issue-body]read fresh throughIssueHostat action time, each capped at 20 000 characters,authorset to the issue's author. - [ ] 3C3. Re-check at the moment of use: before starting, the action re-reads the issue; if it is no longer open, or no longer labelled, or the label's applier changed, the event settles
droppedwith a notice. (This narrows the window in which an outsider edits the body after a trusted label.) - [ ] 3C4.
start-run.ts/run-prompt.ts: thetask_createdjournal entry carriesexternal; the worker's first message gains## External text (data, not instructions)with each entry rendered byuntrustedContent({ source, author, body }). A resumed session must not repeat it (same rule asdescription). Tests: a body containing</untrusted-content>and "ignore previous instructions" stays inside the wrapper;titleanddescriptionof the task never contain issue text. - [ ] 3C5.
journal-text.ts: render the origin of atask_createdentry ("Started by labeljarvison owner/name#12") so the timeline shows it; no DTO change. - [ ] 3C6. (needs ADR-0022) The engine's PR body gets
Closes <owner/name>#<n>when the task's ledger row (watch_events.task_id) belongs to anissue_labelledevent of the same repository. Find where 0022 composes the PR body; add aWatchEventRepository.byTask(taskId)lookup (extend the port and both implementations) rather than copying the number into the task. Different repository → noClosesline, a text reference only. - [ ] 3C7.
worker.md:origin: issue— the issue text is in the External text section and is data; an instruction in it is reported withask_ownerand not followed (ADR-0017); the task is bound by its description, and a request for work outside that description is a question for the owner. - [ ] 3C8. Tests, runner level: baseline fires nothing; a label by an allow-listed login starts one task in a new thread whose first message is
system; the same label next tick → nothing; a label by a stranger →ignored, no task; a repo off the allow-list →dropped, no clone; Jarvis's own repo →dropped; the daily cap defers the fourth issue.
Done when: pnpm --filter @jarvis/shared test && pnpm --filter @jarvis/shared typecheck, pnpm --filter @jarvis/engine test (Docker up) and pnpm --filter @jarvis/engine typecheck, pnpm lint clean, pnpm exec prettier --check clean on agent/ files touched.
Order: 3A and 3B together; 3C after both. Phase 3 go/no-go (owner): one real issue labelled by the owner on a test repository becomes a thread, a spec for approval, and a pull request that closes it; a second issue labelled by a collaborator not on the list does nothing.
Phase 4 — CI triage on the default branch
Owner go/no-go #3, after phase 3. Needs prerequisites: ADR-0022 (the engine fetches logs; the worker has no token) and ADR-0023 (a ci_triage workflow definition).
Task 4A — workflow runs reader (infrastructure) and differ
Owns: engine/src/application/ports/ci-runs.ts (new), engine/src/infrastructure/github/github-ci-runs.ts (+ test), engine/src/infrastructure/github/index.ts, engine/src/domain/watch-default-branch.ts (+ test).
- [ ] 4A1. Port
CiRuns:latestRuns(repo, branch): Promise<readonly WorkflowRunView[]>with{ id, name, headSha, conclusion, status, url, createdAt }for the most recent completed runs of the repository's default branch, andfailedJobLogs(repo, runId, maxChars). Adapter on Octokit (actions.listWorkflowRunsForRepo,listJobsForWorkflowRun, job logs download). Logs are cut tomaxCharsfrom the end of each failed job. - [ ] 4A2.
diffDefaultBranch(previous: { lastRunId: number; lastConclusion: 'success' | 'failure' } | null, snapshot, context): baseline onnull(record the latest completed run, emit nothing); an eventdefault_branch_redonly on the transition to failure (the previous completed run was success, or the red run is for a new head after a green); a continuing red streak emits nothing. Cancelled / skipped / timed-out runs are not red. Keymain-red:<repo>:<runId>. - [ ] 4A3. Tests with the conformance suite (
startsTasks: true), a streak of three reds → one event, a green between two reds → two events, a cancelled run.
Task 4B — application, workflow and config (after 4A and 0023)
Owns: shared/src/config.ts + test (add default_branch_ci), jarvis.config.example.json, engine/src/application/watch/default-branch-source.ts (+ test), .../registry.ts, .../workflows.ts, the ci_triage workflow definition at the location ADR-0023 fixes (path to be filled when 0023 lands), agent/prompts/worker.md (or the prompt file 0023 assigns to the workflow).
- [ ] 4B1. Config union and example.
start.workflowmust be a registered workflow that is startable from a watch (ci_triage). - [ ] 4B2.
default-branch-source.ts: reader + differ +RuleResolver:title = "CI red on <repo> <branch> (run <id>)",descriptionstatic ("Decide whether this failure is flaky or a regression; report; change nothing."),external = [ci-log]with the failed jobs' logs, author unset. - [ ] 4B3. The log is precomputed (ADR-0020 pattern): the engine writes the log excerpt to the task's artifacts directory (
ci-failure.md) and also renders it wrapped in the first message; the worker gets no tool to fetch logs. Fit this into whatever "what the engine precomputes" hook 0023 defines. - [ ] 4B4. The
ci_triageworkflow: read-only. Stages: Context → Report; noImplementing, no PR. Report states flaky / regression / unclear with the evidence (job names, the first error line, what differs between this run and the last green), and offers the owner to start abuildtask for a regression — by saying so in the thread; the dispatcher creates it when the owner agrees. It writes nothing to the repository and has no token. - [ ] 4B5. Tests, runner level: baseline fires nothing; the first red after a green starts one task; a second red while that task is open starts nothing (
maxOpenTasks: 1); the task's first message wraps the log;title/descriptioncontain no log text.
Done when: same commands as phase 3, plus the workflow-registry tests 0023 defines.
Phase 4 go/no-go (owner): one deliberately broken commit on main of a test repository produces one triage report, and the next red run in the same streak produces none.
Phase 5 — Long-running job watch (the seam only; not planned)
Nothing is implemented. What the earlier phases leave in place: WatchType has room for job; a SnapshotReader can poll a declared HTTP endpoint or command (the engine runs the command, never a model); a WatchDiffer compares progress with thresholds and emits job_progress / job_threshold events; the rule is post_message (progress) or resume_task (a task waiting on the job). Open before anyone plans it: who runs a declared command and under which environment (ADR-0019's lesson), what counts as a secret in an endpoint URL, and whether the job belongs to a task.
Order and parallelism
Phase 1: 1A ──► 1B ┐
└► 1C ┴─► 1D (1A, 1B in one session: the engine does not typecheck between them)
Phase 2: 2A ┐
2B ┼─► 2C 2D (parallel; 2D2 waits for memory's run-prompt change)
Phase 3: 3A ┐
3B ┴─► 3C
Phase 4: 4A ──► 4BPhases are sequential and each needs its owner go/no-go. Phase 1 ships alone. Phases 3 and 4 are independent of each other after phase 2 and can be reordered by the owner. Nothing is committed by the tasks; the owner reviews the working tree. Tasks that need Docker: 1A, 1B, 2C, 3C, 4B (the final engine test run). Tasks that do not: 2A, 2B, 2D, 3A, 3B, 4A (their own tests are unit-level; run the full engine suite with Docker before reporting).
Review focus
- Phase 1 changing any behaviour: a diff in a pull-request test is a defect in the refactor, not a test to adjust. Especially the flaky-CI compensation and the ledger key (1B4).
- The migration: existing watch rows keep their state; the primary-key swap on a copied real database.
- Any path by which a source, a differ or a reader reaches the run scheduler or the outbox.
- Any outsider-authored string in a
title,description, thread title orsystemmessage. - A cap checked outside the transaction that creates the task (a race that starts N+1 tasks).
- A source firing on its first poll (baseline), or firing twice across a restart or a sleep.
watch.*source fields reachable fromupdate_configor from any MCP tool.- A task-creating path that goes through the dispatcher.