instar 0.28.95 → 0.28.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dashboard/index.html +249 -2
  2. package/dist/commands/server.d.ts.map +1 -1
  3. package/dist/commands/server.js +90 -1
  4. package/dist/commands/server.js.map +1 -1
  5. package/dist/core/MachineHeartbeat.d.ts +94 -0
  6. package/dist/core/MachineHeartbeat.d.ts.map +1 -0
  7. package/dist/core/MachineHeartbeat.js +155 -0
  8. package/dist/core/MachineHeartbeat.js.map +1 -0
  9. package/dist/core/ProjectAutoAdvancePoller.d.ts +107 -0
  10. package/dist/core/ProjectAutoAdvancePoller.d.ts.map +1 -0
  11. package/dist/core/ProjectAutoAdvancePoller.js +176 -0
  12. package/dist/core/ProjectAutoAdvancePoller.js.map +1 -0
  13. package/dist/core/ProjectRoundCompleteMessage.d.ts +158 -0
  14. package/dist/core/ProjectRoundCompleteMessage.d.ts.map +1 -0
  15. package/dist/core/ProjectRoundCompleteMessage.js +253 -0
  16. package/dist/core/ProjectRoundCompleteMessage.js.map +1 -0
  17. package/dist/core/ProjectRoundExecution.d.ts +111 -0
  18. package/dist/core/ProjectRoundExecution.d.ts.map +1 -0
  19. package/dist/core/ProjectRoundExecution.js +359 -0
  20. package/dist/core/ProjectRoundExecution.js.map +1 -0
  21. package/dist/core/ProjectRoundLock.d.ts +67 -0
  22. package/dist/core/ProjectRoundLock.d.ts.map +1 -0
  23. package/dist/core/ProjectRoundLock.js +161 -0
  24. package/dist/core/ProjectRoundLock.js.map +1 -0
  25. package/dist/core/ProjectRoundRunner.d.ts +146 -0
  26. package/dist/core/ProjectRoundRunner.d.ts.map +1 -0
  27. package/dist/core/ProjectRoundRunner.js +371 -0
  28. package/dist/core/ProjectRoundRunner.js.map +1 -0
  29. package/dist/core/ProjectRoundWorktrees.d.ts +57 -0
  30. package/dist/core/ProjectRoundWorktrees.d.ts.map +1 -0
  31. package/dist/core/ProjectRoundWorktrees.js +111 -0
  32. package/dist/core/ProjectRoundWorktrees.js.map +1 -0
  33. package/dist/server/AgentServer.d.ts +12 -0
  34. package/dist/server/AgentServer.d.ts.map +1 -1
  35. package/dist/server/AgentServer.js +3 -0
  36. package/dist/server/AgentServer.js.map +1 -1
  37. package/dist/server/routes.d.ts +19 -0
  38. package/dist/server/routes.d.ts.map +1 -1
  39. package/dist/server/routes.js +590 -7
  40. package/dist/server/routes.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/data/builtin-manifest.json +47 -47
  43. package/upgrades/0.28.96.md +347 -0
  44. package/upgrades/side-effects/project-scope-phase1b-connect-the-dots.md +184 -0
  45. package/upgrades/side-effects/project-scope-phase1b-pr3.md +228 -0
  46. package/upgrades/side-effects/project-scope-phase1b-pr4.md +198 -0
  47. package/upgrades/side-effects/project-scope-phase1b-pr5.md +150 -0
  48. package/upgrades/side-effects/project-scope-phase1b-pr6.md +136 -0
  49. package/upgrades/side-effects/project-scope-phase1b-pr7.md +175 -0
@@ -0,0 +1,136 @@
1
+ # Side-Effects Review — project-scope Phase 1b PR 6 (Tone-gated round-complete message + delivery)
2
+
3
+ **Version / slug:** `project-scope-phase1b-pr6`
4
+ **Date:** `2026-05-11`
5
+ **Author:** `echo`
6
+ **Second-pass reviewer:** `required (new outbound-message template + new disk-backed idempotency surface)`
7
+
8
+ ## Summary of the change
9
+
10
+ Sixth PR of project-scope Phase 1b. Ships the two final primitives the
11
+ autonomous run loop will need to emit round-complete digests safely:
12
+
13
+ - `formatRoundCompleteMessage(input)` — pure template function. Enforces
14
+ required-field PRESENCE (not non-emptiness, per spec § Phase 1.8 —
15
+ the gate "never silently rejects on a legitimate halt"). Returns
16
+ `{ok:true, message, idempotencyKey}` or `{ok:false, missingFields}`.
17
+ - `RoundCompleteDeliveryHelper` — retry + idempotency wrapper around
18
+ a caller-provided send function. 3-attempt exponential backoff
19
+ (1s, 2s, 4s defaults). Records the `(projectId, roundIndex,
20
+ eventKind, projectVersion)` key in `.instar/local/round-complete-sent.json`
21
+ after the first successful send so tone-gate retries don't produce
22
+ duplicates. On permanent failure (all retries exhausted, or first
23
+ non-transient response), the caller's `onPermanentFail` runs.
24
+
25
+ Nothing wires these up to an actual round-complete event yet — the
26
+ autonomous run loop is the consumer. PR 6 ships the primitives so the
27
+ run loop in a follow-up PR doesn't fork either of them.
28
+
29
+ Spec source: `docs/specs/PROJECT-SCOPE-SPEC.md` § Phase 1.8.
30
+
31
+ New files:
32
+ - `src/core/ProjectRoundCompleteMessage.ts` (~290 lines) — the
33
+ template + delivery helper described above. Pure ESM, no extra deps.
34
+ - `tests/unit/ProjectRoundCompleteMessage.test.ts` (20 cases) —
35
+ template required-field gate (all 9 required + halt-flavor whatHalted),
36
+ empty-string accepted, root-cause-default omitted, override link
37
+ rendered, evidence-cap honoured, idempotency-key permutations,
38
+ delivery first-attempt success, dedup short-circuit, transient retry
39
+ to success, non-transient bail with fallback, all-transient exhaust
40
+ with fallback, on-disk persistence across instances, no-record on
41
+ total failure, template-reject suppresses send.
42
+
43
+ ## Decision-point inventory
44
+
45
+ - **Template required-field gate** (`formatRoundCompleteMessage`) —
46
+ **add** — rejects with `{ok:false, missingFields}` when any of the
47
+ 9 required fields is undefined / null / non-array (for `evidenceCited`)
48
+ / non-integer (for `roundIndex`/`projectVersion`). Halt-flavor events
49
+ additionally require `whatHalted` to be a string. Empty strings are
50
+ ACCEPTED — the spec explicitly says presence is what matters.
51
+ - **Idempotency-key dedup** (`RoundCompleteDeliveryHelper.sendOnce`) —
52
+ **add** — recorded only after a confirmed send. If all attempts
53
+ failed, the key is NOT recorded, so a subsequent retry with the
54
+ same input will be allowed to call `send` again. Bounded to 1000
55
+ recent keys so the dedup file doesn't grow unbounded.
56
+ - **Fallback firing** (`onPermanentFail`) — **add** — fires once when
57
+ all retries are exhausted OR a non-transient failure is reported.
58
+ Caller decides whether the fallback path is attention-queue,
59
+ audit-log, `awaitingUser` population, or all three. The PR 6
60
+ delivery helper just signals "we couldn't deliver — your turn."
61
+
62
+ ## Over-block vs under-block analysis
63
+
64
+ ### Template gate
65
+ Over-block: an `evidenceCited: []` (empty array) is accepted —
66
+ required-field PRESENCE includes "array exists, possibly empty." The
67
+ gate would reject `evidenceCited: undefined`. Matches spec.
68
+
69
+ Under-block: there's no length cap on individual string fields. A
70
+ 30,000-char `whatLanded` would render in full. Acceptable: outbound
71
+ content quality is the tone-gate's job (MessagingToneGate already
72
+ flags excessive verbosity). The template just builds the string.
73
+
74
+ ### Delivery helper
75
+ Over-block: a non-transient failure bails immediately rather than
76
+ retrying. Matches the spec's implicit "permanent failure → fallback"
77
+ semantics — retrying a 401 / 400 won't help.
78
+
79
+ Under-block: dedup is keyed on `projectVersion`. If the project record
80
+ is mutated between send attempts (which it normally is — the
81
+ post-send tracker.update bumps version), a second attempt would have
82
+ a different key and re-send. This is intentional — the version bump
83
+ is what makes "same round, different state" distinguishable from
84
+ "same round, same state, duplicate send."
85
+
86
+ ## Signal vs authority audit
87
+
88
+ The template is a pure function — no signal/authority overlap. The
89
+ delivery helper has authority only over its own idempotency ring; it
90
+ delegates transport entirely to the caller's `send` function.
91
+
92
+ ## Interactions with existing systems
93
+
94
+ - **`MessagingToneGate`.** The caller (the autonomous run loop, not
95
+ shipped yet) is responsible for routing the formatted message
96
+ through the tone gate before calling `helper.sendOnce`. The helper
97
+ does NOT call the tone gate directly — keeps the boundary clean
98
+ and the helper unit-testable.
99
+ - **TelegramAdapter / Slack / WhatsApp.** None used here. The caller
100
+ supplies the `send` function.
101
+ - **`.instar/local/`.** The dedup file lives at
102
+ `.instar/local/round-complete-sent.json` — machine-local, NOT
103
+ git-synced (same convention as the round-runner lock and the drift
104
+ ledger lock). Two machines won't dedupe each other's sends, which
105
+ is correct: each machine should make its own send decision and the
106
+ recipient platforms (Telegram, Slack) handle their own dedup.
107
+ - **`SafeFsExecutor`.** Used for test cleanup; the in-class
108
+ persistence uses tmp+rename atomic writes (matches the pattern in
109
+ `MachineHeartbeat`).
110
+
111
+ ## Rollback cost
112
+
113
+ Revert deletes `src/core/ProjectRoundCompleteMessage.ts` and the
114
+ test file. The on-disk dedup file becomes orphaned but harmless.
115
+ No schema migrations.
116
+
117
+ ## What this PR explicitly defers (to PR 7+)
118
+
119
+ - **Wiring into the autonomous run loop.** The run loop is the
120
+ intended consumer; it ships separately. Until then, no caller
121
+ invokes `formatRoundCompleteMessage` or `sendOnce`.
122
+ - **Attention queue / audit log / `awaitingUser` integration.** The
123
+ fallback callback is caller-provided; PR 6 only fires it. The
124
+ concrete callback that wires those three downstream channels
125
+ ships with the run loop.
126
+ - **MessagingToneGate routing.** Same — the caller threads the
127
+ message through the gate; the helper accepts the formatted text
128
+ as-is.
129
+
130
+ ## Verification
131
+
132
+ - `npm run lint` — passes (tsc + lint-no-direct-destructive).
133
+ - `npx vitest run tests/unit/ProjectRoundCompleteMessage.test.ts` —
134
+ 20/20 pass.
135
+ - Existing PR 1-5 invariants unaffected (no shared code touched
136
+ outside the new file).
@@ -0,0 +1,175 @@
1
+ # Side-Effects Review — project-scope Phase 1b PR 7 (Autonomous run loop)
2
+
3
+ **Version / slug:** `project-scope-phase1b-pr7`
4
+ **Date:** `2026-05-11`
5
+ **Author:** `echo`
6
+ **Second-pass reviewer:** `required (new subprocess management + process-group signaling + filesystem allocation under target repo)`
7
+
8
+ ## Summary of the change
9
+
10
+ Final PR of project-scope Phase 1b. Ships the autonomous run loop the
11
+ spec § Phase 1.5 names (steps 1-11), wired against the lock + preflight
12
+ + runner primitives that landed in PRs 3-6:
13
+
14
+ - `ProjectRoundWorktrees` — lazy worktree allocator under
15
+ `<targetRepoPath>/.worktrees/<projectId>/<roundIndex>/<itemId>`.
16
+ Appends `.worktrees/` to `.git/info/exclude` on first call so the
17
+ namespace doesn't pollute `git status`.
18
+ - `runRound(input, deps)` — the run loop. Acquires the lock, lazily
19
+ allocates the first worktree, spawns the autonomous child in a
20
+ detached process group, polls the project record every 60 seconds.
21
+ On mid-round mutation to `round.itemIds`, SIGTERMs the child's
22
+ process group (5s grace, then SIGKILL) and relaunches with the
23
+ new stop condition. On the child's natural exit, verifies per-item
24
+ artifacts via the caller-injected `verifyMergedItems` and sets
25
+ `round.status` to `complete` | `partially-complete`. On
26
+ `haltedAt` set mid-run, kills the child and returns `halted`.
27
+ Three-attempt resume cap on transient non-zero exits before
28
+ `failed`.
29
+
30
+ Spec source: `docs/specs/PROJECT-SCOPE-SPEC.md` § Phase 1.5.
31
+
32
+ New files:
33
+ - `src/core/ProjectRoundWorktrees.ts` (~140 lines) — pathFor,
34
+ allocate, prune, remove, ensureExcludeEntry helpers. `SafeGitExecutor`
35
+ for all git invocations.
36
+ - `src/core/ProjectRoundExecution.ts` (~340 lines) — the run loop
37
+ itself, plus `verifyMergedItemsViaGit` helper for callers that want
38
+ the real `git merge-base --is-ancestor` verifier instead of a stub.
39
+ - `tests/unit/ProjectRoundWorktrees.test.ts` (8 cases) —
40
+ path-shape, allocate-creates, refuse-on-existing, idempotent
41
+ exclude entry, prune-on-empty, remove-on-missing,
42
+ remove-cleans-up, allocate-with-refuseExisting-false.
43
+ - `tests/unit/ProjectRoundExecution.test.ts` (8 cases) —
44
+ lock-held-failure, first-pass-complete (no spawn), natural-exit
45
+ full-verification, natural-exit subset → partially-complete,
46
+ halt-mid-run, dynamic stop revalidation (itemIds mutation
47
+ triggers relaunch), worktree allocated, exclude entry written.
48
+
49
+ ## Decision-point inventory
50
+
51
+ - **Spawn in detached process group** (`spawnAutonomousChild`) —
52
+ **add** — `detached: true` per Node `child_process.spawn`. The
53
+ child gets its own process group; the runner is NOT a member.
54
+ `process.kill(-pid, signal)` (negative PID = group target) reaps
55
+ the child's entire process tree (compilers, test runners spawned
56
+ by the autonomous skill) without reaping the runner. Spec § Phase
57
+ 1.5 step 5 calls this out explicitly.
58
+ - **Worktree allocation** — **add** — lazy on first use. Refuses
59
+ by default if path exists (spec semantics); callers can pass
60
+ `refuseExisting: false` to override (used on resume paths).
61
+ - **Per-step halt checkpoint** — **add** — before every iteration of
62
+ the inner relaunch loop, re-reads `round.haltedAt` from the tracker.
63
+ Set → SIGTERM the child, return `halted`.
64
+ - **Stop-condition verifier dependency injection** — **add** —
65
+ `verifyMergedItems` is required input. Default (used when no
66
+ override) is a no-op set (returns empty set), so production callers
67
+ MUST pass a real verifier. Tests pass stubs. The real production
68
+ verifier is `verifyMergedItemsViaGit`, exported alongside the run
69
+ loop.
70
+ - **Resume cap** — **add** — 3 transient non-zero exits before
71
+ `failed`. Spec § Phase 1.5 step 11.
72
+
73
+ ## Over-block vs under-block analysis
74
+
75
+ ### Process group signaling
76
+ Over-block: SIGTERM-grace-then-SIGKILL of the WHOLE process group
77
+ will reap any descendant process the autonomous skill spawned —
78
+ compilers, test runners, lockfile holders. This is intentional and
79
+ matches the spec.
80
+
81
+ Under-block: if the autonomous child somehow detaches FURTHER
82
+ (creates its own grandchild group), that group escapes. Acceptable
83
+ edge case — the autonomous skill is in-house and doesn't do that;
84
+ we'd notice in observability before it becomes a leak.
85
+
86
+ ### Worktree allocation
87
+ Over-block: a stale worktree directory under `.worktrees/` from a
88
+ crashed previous run causes `allocate()` to throw. Callers (the
89
+ runner's first-item path) pass `refuseExisting: false` so the
90
+ allocator returns the existing path instead. Trade-off: a crashed
91
+ run's stale worktree is silently reused. Acceptable: `prune()` runs
92
+ on every successful round completion, and `git worktree add` would
93
+ itself complain if the worktree is corrupt.
94
+
95
+ Under-block: `prune()` runs `git worktree prune` against the whole
96
+ repo, not just our namespace. Worktrees registered by OTHER tools
97
+ (unrelated to project-scope) that have become stale will ALSO be
98
+ pruned. Acceptable: `git worktree prune` only removes administrative
99
+ entries pointing at missing paths — it does not delete live worktree
100
+ directories.
101
+
102
+ ### Run loop
103
+ Over-block: a long-running autonomous child that takes 4 hours to
104
+ complete isn't capped here. Acceptable — the autonomous skill has
105
+ its own duration cap (stop hook); the run loop just watches for exit.
106
+
107
+ Under-block: a child that hangs without exiting AND without itemIds
108
+ changing AND without `haltedAt` being set sits forever. Acceptable
109
+ for this PR — the auto-advance poller's `LOCK_HELD` rejection will
110
+ eventually surface the stuck round in telemetry, and the user can
111
+ `POST /halt`.
112
+
113
+ ## Signal vs authority audit
114
+
115
+ The run loop is **authority** for round-state transitions
116
+ (`complete` / `partially-complete` / `failed`). The decision is
117
+ deterministic: the caller-provided `verifyMergedItems` (a signal
118
+ source) returns a set; the run loop counts matched/unmatched and
119
+ sets `round.status` accordingly. The runner never sets a verdict
120
+ the verifier didn't support.
121
+
122
+ ## Interactions with existing systems
123
+
124
+ - **`ProjectRoundLock`** — acquired at step 1, released at step 8 in
125
+ the finally block (always releases even on throws).
126
+ - **`InitiativeTracker`** — single source of truth for `round.itemIds`,
127
+ `round.haltedAt`, `round.status`. Polled every `pollIntervalMs`;
128
+ mutated on outcome via `tracker.update(...)` with `ifMatch`. OCC
129
+ races are silently ignored at outcome-recording time (next read
130
+ will see the conflicting writer's state).
131
+ - **`SafeGitExecutor`** — every git invocation (worktree add / prune /
132
+ remove, merge-base --is-ancestor) routes through the safe executor.
133
+ No raw `execFileSync('git', ...)` anywhere.
134
+ - **`ProjectRoundRunner.preflight`** (PR 3) — the run loop assumes
135
+ preflight has passed. It does NOT re-run preflight at step 1; the
136
+ caller is expected to do it (auto-advance poller does; /project
137
+ run-round skill does).
138
+ - **`ProjectAutoAdvancePoller`** (PR 4) — the poller calls
139
+ `preflight` and then in PR 7+ can call `runRound` directly. PR 4
140
+ bookkeeps unacked count + clears autoAdvanceAt; the run loop is
141
+ the actual work-doer that follows.
142
+ - **`RoundCompleteDeliveryHelper`** (PR 6) — the run loop does NOT
143
+ invoke the delivery helper. That's a caller concern (the poller
144
+ or the skill consumes the run-loop result and constructs the
145
+ message). Keeps the run loop's responsibilities tight.
146
+
147
+ ## Rollback cost
148
+
149
+ Revert deletes `src/core/ProjectRoundWorktrees.ts`,
150
+ `src/core/ProjectRoundExecution.ts`, the two test files. Existing
151
+ worktree directories under `<targetRepoPath>/.worktrees/...` become
152
+ orphaned but harmless. `git worktree prune` from a subsequent
153
+ unrelated run cleans up the administrative entries. No schema
154
+ changes.
155
+
156
+ ## What this PR explicitly defers
157
+
158
+ - **Wiring the poller / skill to call `runRound`.** PR 4's poller
159
+ currently only bookkeeps; calling `runRound` is a small wiring
160
+ task in a follow-up PR (the runner instance is already in the
161
+ ctx; the poller just needs to invoke it).
162
+ - **`GET /projects/:id/next` real implementation.** Still 501.
163
+ - **Lazy merged-state reconciler on `GET /projects/:id`.** Spec
164
+ Phase 1.5 — the read-may-mutate behavior with the ≤3-children-per-GET
165
+ cap. Not implemented in PR 7; the
166
+ `verifyMergedItemsViaGit` helper here is the building block the
167
+ reconciler can call into in a follow-up.
168
+
169
+ ## Verification
170
+
171
+ - `npm run lint` — passes (tsc + lint-no-direct-destructive).
172
+ - `npx vitest run tests/unit/ProjectRoundExecution.test.ts
173
+ tests/unit/ProjectRoundWorktrees.test.ts` — 16/16 pass.
174
+ - Existing PR 1-6 invariants unaffected (the run loop is a new
175
+ module; no shared-code mutations).