@wildorder/nightshift 0.1.0

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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +90 -0
  3. package/dist/agent-runner.d.ts +64 -0
  4. package/dist/agent-runner.d.ts.map +1 -0
  5. package/dist/agent-runner.js +128 -0
  6. package/dist/agent-runner.js.map +1 -0
  7. package/dist/agent-summary.d.ts +35 -0
  8. package/dist/agent-summary.d.ts.map +1 -0
  9. package/dist/agent-summary.js +95 -0
  10. package/dist/agent-summary.js.map +1 -0
  11. package/dist/cli.d.ts +3 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +18 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/config.d.ts +74 -0
  16. package/dist/config.d.ts.map +1 -0
  17. package/dist/config.js +62 -0
  18. package/dist/config.js.map +1 -0
  19. package/dist/detect-package-manager.d.ts +15 -0
  20. package/dist/detect-package-manager.d.ts.map +1 -0
  21. package/dist/detect-package-manager.js +78 -0
  22. package/dist/detect-package-manager.js.map +1 -0
  23. package/dist/findings.d.ts +106 -0
  24. package/dist/findings.d.ts.map +1 -0
  25. package/dist/findings.js +107 -0
  26. package/dist/findings.js.map +1 -0
  27. package/dist/graph.d.ts +30 -0
  28. package/dist/graph.d.ts.map +1 -0
  29. package/dist/graph.js +87 -0
  30. package/dist/graph.js.map +1 -0
  31. package/dist/index.d.ts +10 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +10 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/program-memory.d.ts +252 -0
  36. package/dist/program-memory.d.ts.map +1 -0
  37. package/dist/program-memory.js +385 -0
  38. package/dist/program-memory.js.map +1 -0
  39. package/dist/project-manifest.d.ts +23 -0
  40. package/dist/project-manifest.d.ts.map +1 -0
  41. package/dist/project-manifest.js +78 -0
  42. package/dist/project-manifest.js.map +1 -0
  43. package/dist/prompt.d.ts +70 -0
  44. package/dist/prompt.d.ts.map +1 -0
  45. package/dist/prompt.js +237 -0
  46. package/dist/prompt.js.map +1 -0
  47. package/dist/worktree-guard.d.ts +40 -0
  48. package/dist/worktree-guard.d.ts.map +1 -0
  49. package/dist/worktree-guard.js +91 -0
  50. package/dist/worktree-guard.js.map +1 -0
  51. package/package.json +63 -0
@@ -0,0 +1,252 @@
1
+ import type { IdentifiedFinding, Severity } from "./findings.js";
2
+ /**
3
+ * Program memory: the durable record of what the pipeline concluded and why.
4
+ *
5
+ * Two layers with opposite growth behavior:
6
+ *
7
+ * - The **journal** (`docs/programs/{id}-memory.jsonl`) is append-only and is
8
+ * never placed in a prompt. It is the source of truth; every read reduces
9
+ * it from scratch, so a corrupted or hand-edited view file costs nothing.
10
+ * - The **view** (`docs/programs/{id}-memory.json`) is the derived current
11
+ * state — one entry per finding fingerprint regardless of how many runs
12
+ * re-raised it. It exists for humans and for agents that pull context on
13
+ * demand; the runner itself always reduces the journal.
14
+ *
15
+ * Both live under `docs/programs/` and are committed, deliberately: memory
16
+ * that dies with a machine or a gitignored directory is what made every run
17
+ * start blind. Only the runner writes here — agents receive projections in
18
+ * their briefs and read the view file, exactly the separation the runner
19
+ * already applies to commits and summaries.
20
+ *
21
+ * Model output recorded here is **context, never precedent**: a writer's
22
+ * decline is a position the next critic must engage, not a settlement.
23
+ * Only human decisions carry authority, and even those are revocable.
24
+ */
25
+ export declare const MEMORY_SCHEMA_VERSION = 1;
26
+ export type FindingStatus = "open" | "fix-applied" | "declined" | "resolved" | "waived" | "superseded";
27
+ export interface HumanDecision {
28
+ decision: "waived" | "upheld";
29
+ rationale: string;
30
+ at: string;
31
+ /**
32
+ * The convergence input hash at decision time. A waiver passes the gate
33
+ * mechanically only while this matches the current hash — any spec, plan,
34
+ * or config edit lapses it, exactly like criteria approval. Durable never
35
+ * means irreversible: a later decision replaces it.
36
+ */
37
+ scopeHash?: string;
38
+ }
39
+ /** One entry in a finding's raise/decline conversation, oldest first. */
40
+ export interface Exchange {
41
+ runId: string;
42
+ round?: number;
43
+ action: "raised" | "applied" | "declined" | "decline-accepted" | "downgraded" | "waived" | "human-decision";
44
+ severity?: Severity;
45
+ rationale?: string;
46
+ at: string;
47
+ }
48
+ export interface FindingMemory {
49
+ /** The latest version raised — re-raises update it, unlike the loop's first-wins ledger. */
50
+ finding: IdentifiedFinding;
51
+ status: FindingStatus;
52
+ firstRaised: {
53
+ runId: string;
54
+ round?: number;
55
+ at: string;
56
+ };
57
+ exchanges: Exchange[];
58
+ raiseCount: number;
59
+ declineCount: number;
60
+ lastDeclineReason?: string;
61
+ humanDecision?: HumanDecision;
62
+ /** The models deadlocked across runs; a human owns the next move. */
63
+ pendingDecision?: {
64
+ reason: string;
65
+ runId: string;
66
+ at: string;
67
+ };
68
+ }
69
+ export interface RunSummary {
70
+ runId: string;
71
+ stage: string;
72
+ startedAt: string;
73
+ outcome?: string;
74
+ result?: string;
75
+ reason?: string;
76
+ }
77
+ export interface CheckpointMemory {
78
+ status: "safe" | "unsafe";
79
+ reason: string;
80
+ runId: string;
81
+ at: string;
82
+ }
83
+ /** One attempt at a unit of work — `build:WS-03`, `replan`, `author:WS-07`. */
84
+ export interface AttemptRecord {
85
+ runId: string;
86
+ attempt: number;
87
+ outcome: "failed" | "succeeded";
88
+ reason?: string;
89
+ /** Bounded output excerpt — the evidence that mattered, never a log path. */
90
+ excerpt?: string;
91
+ failedCommand?: string;
92
+ at: string;
93
+ }
94
+ /** A stage-level structural diagnosis (cycle, unmet requirement, oversize). */
95
+ export interface DiagnosisRecord {
96
+ stage: string;
97
+ outcome: string;
98
+ reason: string;
99
+ detail?: string;
100
+ runId: string;
101
+ at: string;
102
+ }
103
+ export interface ProgramMemoryView {
104
+ schemaVersion: typeof MEMORY_SCHEMA_VERSION;
105
+ programId: string;
106
+ updatedAt: string;
107
+ runs: RunSummary[];
108
+ findings: Record<string, FindingMemory>;
109
+ checkpoints: Record<string, CheckpointMemory>;
110
+ attempts: Record<string, AttemptRecord[]>;
111
+ diagnoses: DiagnosisRecord[];
112
+ /** Latest plan-audit verdict per success criterion — kept even on PASS. */
113
+ criteria: Record<string, {
114
+ status: string;
115
+ reason: string;
116
+ runId: string;
117
+ at: string;
118
+ }>;
119
+ }
120
+ interface EventBase {
121
+ at: string;
122
+ runId: string;
123
+ }
124
+ export type MemoryEvent = (EventBase & {
125
+ kind: "run-started";
126
+ stage: string;
127
+ }) | (EventBase & {
128
+ kind: "finding-raised";
129
+ round?: number;
130
+ finding: IdentifiedFinding;
131
+ }) | (EventBase & {
132
+ kind: "finding-applied";
133
+ round?: number;
134
+ id: string;
135
+ }) | (EventBase & {
136
+ kind: "finding-declined";
137
+ round?: number;
138
+ id: string;
139
+ reason: string;
140
+ }) | (EventBase & {
141
+ kind: "decline-accepted";
142
+ round?: number;
143
+ id: string;
144
+ }) | (EventBase & {
145
+ kind: "severity-downgraded";
146
+ id: string;
147
+ from: Severity;
148
+ reason: string;
149
+ }) | (EventBase & {
150
+ kind: "checkpoint-assessed";
151
+ workstreamId: string;
152
+ status: "safe" | "unsafe";
153
+ reason: string;
154
+ }) | (EventBase & {
155
+ kind: "round-completed";
156
+ round: number;
157
+ critic: string;
158
+ writer?: string;
159
+ raised: number;
160
+ fresh: number;
161
+ applied: number;
162
+ rejected: number;
163
+ criticSummary?: string;
164
+ writerSummary?: string;
165
+ }) | (EventBase & {
166
+ kind: "loop-finished";
167
+ stage: string;
168
+ outcome: string;
169
+ result: string;
170
+ reason?: string;
171
+ waivedFindings?: string[];
172
+ }) | (EventBase & {
173
+ kind: "human-decision";
174
+ id: string;
175
+ decision: "waived" | "upheld";
176
+ rationale: string;
177
+ scopeHash?: string;
178
+ }) | (EventBase & {
179
+ kind: "decision-requested";
180
+ id: string;
181
+ reason: string;
182
+ }) | (EventBase & {
183
+ kind: "criterion-assessed";
184
+ criterionId: string;
185
+ status: string;
186
+ reason: string;
187
+ }) | (EventBase & {
188
+ kind: "attempt-recorded";
189
+ unit: string;
190
+ attempt: number;
191
+ outcome: "failed" | "succeeded";
192
+ reason?: string;
193
+ excerpt?: string;
194
+ failedCommand?: string;
195
+ }) | (EventBase & {
196
+ kind: "stage-diagnosis";
197
+ stage: string;
198
+ outcome: string;
199
+ reason: string;
200
+ detail?: string;
201
+ });
202
+ type DistributeInput<T> = T extends unknown ? Omit<T, "at" | "runId"> : never;
203
+ /** A memory event minus the envelope the recorder stamps on every entry. */
204
+ export type MemoryEventInput = DistributeInput<MemoryEvent>;
205
+ export declare function memoryJournalPath(root: string, programId: string): string;
206
+ export declare function memoryViewPath(root: string, programId: string): string;
207
+ /**
208
+ * Fold the journal into the current state. Deliberately dumb: status
209
+ * transitions only, no gate semantics — the loop decides what passes, memory
210
+ * records what the loop decided.
211
+ */
212
+ export declare function reduceMemoryEvents(programId: string, events: readonly MemoryEvent[]): ProgramMemoryView;
213
+ /** Parse the journal, skipping malformed lines rather than failing the read. */
214
+ export declare function readMemoryJournal(root: string, programId: string): Promise<MemoryEvent[]>;
215
+ /** The current state, reduced from the journal (the view file is never trusted). */
216
+ export declare function readProgramMemory(root: string, programId: string): Promise<ProgramMemoryView>;
217
+ /**
218
+ * Append events to the journal and refresh the derived view. The view write
219
+ * is best-effort — the journal is the record; the view can always be rebuilt.
220
+ */
221
+ export declare function appendMemoryEvents(root: string, programId: string, events: readonly MemoryEvent[]): Promise<ProgramMemoryView>;
222
+ /**
223
+ * The brief projection: findings from prior runs a critic must know about.
224
+ * Constraints are pushed, evidence is pulled — this carries the conclusion
225
+ * and rationale of each unsettled or human-decided finding, and the brief
226
+ * points at the view file for everything else.
227
+ */
228
+ export interface PriorRunFinding {
229
+ finding: IdentifiedFinding;
230
+ status: FindingStatus;
231
+ raiseCount: number;
232
+ declineCount: number;
233
+ lastDeclineReason?: string;
234
+ humanDecision?: HumanDecision;
235
+ }
236
+ export declare function priorRunFindings(view: ProgramMemoryView, options?: {
237
+ excludeRunId?: string;
238
+ }): PriorRunFinding[];
239
+ export interface PendingDecision {
240
+ id: string;
241
+ finding: IdentifiedFinding;
242
+ reason: string;
243
+ lastDeclineReason?: string;
244
+ }
245
+ /** Findings waiting on a human `decide` call. */
246
+ export declare function pendingDecisions(view: ProgramMemoryView): PendingDecision[];
247
+ /** The unit's most recent attempt, when that attempt failed — the state a
248
+ * resumed run must not rediscover from scratch. */
249
+ export declare function lastFailedAttempt(view: ProgramMemoryView, unit: string): AttemptRecord | undefined;
250
+ export declare function countByStatus(view: ProgramMemoryView): Record<FindingStatus, number>;
251
+ export {};
252
+ //# sourceMappingURL=program-memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program-memory.d.ts","sourceRoot":"","sources":["../src/program-memory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,aAAa,GACb,UAAU,GACV,UAAU,GACV,QAAQ,GACR,YAAY,CAAC;AAEjB,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,yEAAyE;AACzE,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EACF,QAAQ,GACR,SAAS,GACT,UAAU,GACV,kBAAkB,GAClB,YAAY,GACZ,QAAQ,GACR,gBAAgB,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;CACZ;AAID,MAAM,WAAW,aAAa;IAC5B,4FAA4F;IAC5F,OAAO,EAAE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AI,EAAE,iBAAiB,GAAG,eAAe,EAAE,CAe3E;AAED;mDACmD;AACnD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,iBAAiB,EACvB,IAAI,EAAE,MAAM,GACX,aAAa,GAAG,SAAS,CAG3B;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,iBAAiB,GACtB,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,CAW/B"}
@@ -0,0 +1,385 @@
1
+ import { appendFile, mkdir, readFile, writeFile } from "node:fs/promises";
2
+ import { join, resolve } from "node:path";
3
+ /**
4
+ * Program memory: the durable record of what the pipeline concluded and why.
5
+ *
6
+ * Two layers with opposite growth behavior:
7
+ *
8
+ * - The **journal** (`docs/programs/{id}-memory.jsonl`) is append-only and is
9
+ * never placed in a prompt. It is the source of truth; every read reduces
10
+ * it from scratch, so a corrupted or hand-edited view file costs nothing.
11
+ * - The **view** (`docs/programs/{id}-memory.json`) is the derived current
12
+ * state — one entry per finding fingerprint regardless of how many runs
13
+ * re-raised it. It exists for humans and for agents that pull context on
14
+ * demand; the runner itself always reduces the journal.
15
+ *
16
+ * Both live under `docs/programs/` and are committed, deliberately: memory
17
+ * that dies with a machine or a gitignored directory is what made every run
18
+ * start blind. Only the runner writes here — agents receive projections in
19
+ * their briefs and read the view file, exactly the separation the runner
20
+ * already applies to commits and summaries.
21
+ *
22
+ * Model output recorded here is **context, never precedent**: a writer's
23
+ * decline is a position the next critic must engage, not a settlement.
24
+ * Only human decisions carry authority, and even those are revocable.
25
+ */
26
+ export const MEMORY_SCHEMA_VERSION = 1;
27
+ const MAX_EXCHANGES = 12;
28
+ const MAX_ATTEMPTS_PER_UNIT = 8;
29
+ const MAX_DIAGNOSES = 20;
30
+ export function memoryJournalPath(root, programId) {
31
+ return join(resolve(root), "docs", "programs", `${programId}-memory.jsonl`);
32
+ }
33
+ export function memoryViewPath(root, programId) {
34
+ return join(resolve(root), "docs", "programs", `${programId}-memory.json`);
35
+ }
36
+ function emptyView(programId) {
37
+ return {
38
+ schemaVersion: MEMORY_SCHEMA_VERSION,
39
+ programId,
40
+ updatedAt: "",
41
+ runs: [],
42
+ findings: {},
43
+ checkpoints: {},
44
+ attempts: {},
45
+ diagnoses: [],
46
+ criteria: {},
47
+ };
48
+ }
49
+ function pushExchange(entry, exchange) {
50
+ entry.exchanges.push(exchange);
51
+ if (entry.exchanges.length > MAX_EXCHANGES) {
52
+ entry.exchanges.splice(0, entry.exchanges.length - MAX_EXCHANGES);
53
+ }
54
+ }
55
+ /**
56
+ * Fold the journal into the current state. Deliberately dumb: status
57
+ * transitions only, no gate semantics — the loop decides what passes, memory
58
+ * records what the loop decided.
59
+ */
60
+ export function reduceMemoryEvents(programId, events) {
61
+ const view = emptyView(programId);
62
+ const runsById = new Map();
63
+ for (const event of events) {
64
+ view.updatedAt = event.at;
65
+ if (event.kind === "run-started") {
66
+ if (!runsById.has(event.runId)) {
67
+ const run = {
68
+ runId: event.runId,
69
+ stage: event.stage,
70
+ startedAt: event.at,
71
+ };
72
+ runsById.set(event.runId, run);
73
+ view.runs.push(run);
74
+ }
75
+ continue;
76
+ }
77
+ if (event.kind === "loop-finished") {
78
+ let run = runsById.get(event.runId);
79
+ if (!run) {
80
+ run = { runId: event.runId, stage: event.stage, startedAt: event.at };
81
+ runsById.set(event.runId, run);
82
+ view.runs.push(run);
83
+ }
84
+ run.outcome = event.outcome;
85
+ run.result = event.result;
86
+ if (event.reason !== undefined)
87
+ run.reason = event.reason;
88
+ const waived = new Set(event.waivedFindings ?? []);
89
+ for (const [id, entry] of Object.entries(view.findings)) {
90
+ if (waived.has(id)) {
91
+ entry.status = "waived";
92
+ pushExchange(entry, {
93
+ runId: event.runId,
94
+ action: "waived",
95
+ at: event.at,
96
+ });
97
+ }
98
+ else if (event.outcome === "converged" &&
99
+ (entry.status === "open" || entry.status === "fix-applied")) {
100
+ // A clean confirming round covered the whole program; anything the
101
+ // critic no longer raises is resolved, not merely quiet.
102
+ entry.status = "resolved";
103
+ }
104
+ }
105
+ continue;
106
+ }
107
+ if (event.kind === "checkpoint-assessed") {
108
+ view.checkpoints[event.workstreamId] = {
109
+ status: event.status,
110
+ reason: event.reason,
111
+ runId: event.runId,
112
+ at: event.at,
113
+ };
114
+ continue;
115
+ }
116
+ if (event.kind === "round-completed")
117
+ continue;
118
+ if (event.kind === "attempt-recorded") {
119
+ const records = (view.attempts[event.unit] ??= []);
120
+ records.push({
121
+ runId: event.runId,
122
+ attempt: event.attempt,
123
+ outcome: event.outcome,
124
+ ...(event.reason === undefined ? {} : { reason: event.reason }),
125
+ ...(event.excerpt === undefined ? {} : { excerpt: event.excerpt }),
126
+ ...(event.failedCommand === undefined
127
+ ? {}
128
+ : { failedCommand: event.failedCommand }),
129
+ at: event.at,
130
+ });
131
+ if (records.length > MAX_ATTEMPTS_PER_UNIT) {
132
+ records.splice(0, records.length - MAX_ATTEMPTS_PER_UNIT);
133
+ }
134
+ continue;
135
+ }
136
+ if (event.kind === "criterion-assessed") {
137
+ view.criteria[event.criterionId] = {
138
+ status: event.status,
139
+ reason: event.reason,
140
+ runId: event.runId,
141
+ at: event.at,
142
+ };
143
+ continue;
144
+ }
145
+ if (event.kind === "stage-diagnosis") {
146
+ view.diagnoses.push({
147
+ stage: event.stage,
148
+ outcome: event.outcome,
149
+ reason: event.reason,
150
+ ...(event.detail === undefined ? {} : { detail: event.detail }),
151
+ runId: event.runId,
152
+ at: event.at,
153
+ });
154
+ if (view.diagnoses.length > MAX_DIAGNOSES) {
155
+ view.diagnoses.splice(0, view.diagnoses.length - MAX_DIAGNOSES);
156
+ }
157
+ continue;
158
+ }
159
+ if (event.kind === "finding-raised") {
160
+ const existing = view.findings[event.finding.id];
161
+ if (existing) {
162
+ // Latest version wins: a re-raise with sharper evidence or a new
163
+ // severity replaces the stale original instead of being discarded.
164
+ existing.finding = event.finding;
165
+ existing.status = "open";
166
+ existing.raiseCount += 1;
167
+ pushExchange(existing, {
168
+ runId: event.runId,
169
+ ...(event.round === undefined ? {} : { round: event.round }),
170
+ action: "raised",
171
+ severity: event.finding.severity,
172
+ ...(event.finding.message === ""
173
+ ? {}
174
+ : { rationale: event.finding.message }),
175
+ at: event.at,
176
+ });
177
+ }
178
+ else {
179
+ const entry = {
180
+ finding: event.finding,
181
+ status: "open",
182
+ firstRaised: {
183
+ runId: event.runId,
184
+ ...(event.round === undefined ? {} : { round: event.round }),
185
+ at: event.at,
186
+ },
187
+ exchanges: [],
188
+ raiseCount: 1,
189
+ declineCount: 0,
190
+ };
191
+ pushExchange(entry, {
192
+ runId: event.runId,
193
+ ...(event.round === undefined ? {} : { round: event.round }),
194
+ action: "raised",
195
+ severity: event.finding.severity,
196
+ ...(event.finding.message === ""
197
+ ? {}
198
+ : { rationale: event.finding.message }),
199
+ at: event.at,
200
+ });
201
+ view.findings[event.finding.id] = entry;
202
+ }
203
+ continue;
204
+ }
205
+ const entry = view.findings[event.id];
206
+ if (!entry)
207
+ continue;
208
+ switch (event.kind) {
209
+ case "finding-applied":
210
+ entry.status = "fix-applied";
211
+ pushExchange(entry, {
212
+ runId: event.runId,
213
+ ...(event.round === undefined ? {} : { round: event.round }),
214
+ action: "applied",
215
+ at: event.at,
216
+ });
217
+ break;
218
+ case "finding-declined":
219
+ entry.status = "declined";
220
+ entry.declineCount += 1;
221
+ entry.lastDeclineReason = event.reason;
222
+ pushExchange(entry, {
223
+ runId: event.runId,
224
+ ...(event.round === undefined ? {} : { round: event.round }),
225
+ action: "declined",
226
+ rationale: event.reason,
227
+ at: event.at,
228
+ });
229
+ break;
230
+ case "decline-accepted":
231
+ entry.status = "resolved";
232
+ pushExchange(entry, {
233
+ runId: event.runId,
234
+ ...(event.round === undefined ? {} : { round: event.round }),
235
+ action: "decline-accepted",
236
+ at: event.at,
237
+ });
238
+ break;
239
+ case "severity-downgraded":
240
+ pushExchange(entry, {
241
+ runId: event.runId,
242
+ action: "downgraded",
243
+ severity: event.from,
244
+ rationale: event.reason,
245
+ at: event.at,
246
+ });
247
+ break;
248
+ case "human-decision":
249
+ entry.humanDecision = {
250
+ decision: event.decision,
251
+ rationale: event.rationale,
252
+ at: event.at,
253
+ ...(event.scopeHash === undefined
254
+ ? {}
255
+ : { scopeHash: event.scopeHash }),
256
+ };
257
+ entry.status = event.decision === "waived" ? "waived" : "open";
258
+ delete entry.pendingDecision;
259
+ pushExchange(entry, {
260
+ runId: event.runId,
261
+ action: "human-decision",
262
+ rationale: `${event.decision}: ${event.rationale}`,
263
+ at: event.at,
264
+ });
265
+ break;
266
+ case "decision-requested":
267
+ entry.pendingDecision = {
268
+ reason: event.reason,
269
+ runId: event.runId,
270
+ at: event.at,
271
+ };
272
+ break;
273
+ }
274
+ }
275
+ return view;
276
+ }
277
+ /** Parse the journal, skipping malformed lines rather than failing the read. */
278
+ export async function readMemoryJournal(root, programId) {
279
+ let raw;
280
+ try {
281
+ raw = await readFile(memoryJournalPath(root, programId), "utf8");
282
+ }
283
+ catch {
284
+ return [];
285
+ }
286
+ const events = [];
287
+ for (const line of raw.split(/\r?\n/u)) {
288
+ const trimmed = line.trim();
289
+ if (trimmed === "")
290
+ continue;
291
+ try {
292
+ const parsed = JSON.parse(trimmed);
293
+ if (typeof parsed === "object" &&
294
+ parsed !== null &&
295
+ typeof parsed.kind === "string" &&
296
+ typeof parsed.at === "string" &&
297
+ typeof parsed.runId === "string") {
298
+ events.push(parsed);
299
+ }
300
+ }
301
+ catch {
302
+ // A damaged line loses one event, never the ledger.
303
+ }
304
+ }
305
+ return events;
306
+ }
307
+ /** The current state, reduced from the journal (the view file is never trusted). */
308
+ export async function readProgramMemory(root, programId) {
309
+ return reduceMemoryEvents(programId, await readMemoryJournal(root, programId));
310
+ }
311
+ /**
312
+ * Append events to the journal and refresh the derived view. The view write
313
+ * is best-effort — the journal is the record; the view can always be rebuilt.
314
+ */
315
+ export async function appendMemoryEvents(root, programId, events) {
316
+ if (events.length === 0)
317
+ return readProgramMemory(root, programId);
318
+ const journal = memoryJournalPath(root, programId);
319
+ await mkdir(join(resolve(root), "docs", "programs"), { recursive: true });
320
+ const lines = events.map((event) => `${JSON.stringify(event)}\n`).join("");
321
+ await appendFile(journal, lines, "utf8");
322
+ const view = await readProgramMemory(root, programId);
323
+ await writeFile(memoryViewPath(root, programId), `${JSON.stringify(view, null, 2)}\n`, "utf8");
324
+ return view;
325
+ }
326
+ export function priorRunFindings(view, options = {}) {
327
+ const entries = [];
328
+ for (const entry of Object.values(view.findings)) {
329
+ if (entry.status === "resolved" || entry.status === "superseded")
330
+ continue;
331
+ if (options.excludeRunId !== undefined &&
332
+ entry.firstRaised.runId === options.excludeRunId &&
333
+ entry.exchanges.every(({ runId }) => runId === options.excludeRunId)) {
334
+ continue;
335
+ }
336
+ entries.push({
337
+ finding: entry.finding,
338
+ status: entry.status,
339
+ raiseCount: entry.raiseCount,
340
+ declineCount: entry.declineCount,
341
+ ...(entry.lastDeclineReason === undefined
342
+ ? {}
343
+ : { lastDeclineReason: entry.lastDeclineReason }),
344
+ ...(entry.humanDecision === undefined
345
+ ? {}
346
+ : { humanDecision: entry.humanDecision }),
347
+ });
348
+ }
349
+ return entries;
350
+ }
351
+ /** Findings waiting on a human `decide` call. */
352
+ export function pendingDecisions(view) {
353
+ return Object.entries(view.findings).flatMap(([id, entry]) => entry.pendingDecision === undefined
354
+ ? []
355
+ : [
356
+ {
357
+ id,
358
+ finding: entry.finding,
359
+ reason: entry.pendingDecision.reason,
360
+ ...(entry.lastDeclineReason === undefined
361
+ ? {}
362
+ : { lastDeclineReason: entry.lastDeclineReason }),
363
+ },
364
+ ]);
365
+ }
366
+ /** The unit's most recent attempt, when that attempt failed — the state a
367
+ * resumed run must not rediscover from scratch. */
368
+ export function lastFailedAttempt(view, unit) {
369
+ const last = view.attempts[unit]?.at(-1);
370
+ return last?.outcome === "failed" ? last : undefined;
371
+ }
372
+ export function countByStatus(view) {
373
+ const counts = {
374
+ open: 0,
375
+ "fix-applied": 0,
376
+ declined: 0,
377
+ resolved: 0,
378
+ waived: 0,
379
+ superseded: 0,
380
+ };
381
+ for (const entry of Object.values(view.findings))
382
+ counts[entry.status] += 1;
383
+ return counts;
384
+ }
385
+ //# sourceMappingURL=program-memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program-memory.js","sourceRoot":"","sources":["../src/program-memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG1C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAwCvC,MAAM,aAAa,GAAG,EAAE,CAAC;AAsDzB,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,MAAM,aAAa,GAAG,EAAE,CAAC;AAyGzB,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,SAAiB;IAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,SAAS,eAAe,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,SAAiB;IAC5D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,SAAS,cAAc,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,SAAS,CAAC,SAAiB;IAClC,OAAO;QACL,aAAa,EAAE,qBAAqB;QACpC,SAAS;QACT,SAAS,EAAE,EAAE;QACb,IAAI,EAAE,EAAE;QACR,QAAQ,EAAE,EAAE;QACZ,WAAW,EAAE,EAAE;QACf,QAAQ,EAAE,EAAE;QACZ,SAAS,EAAE,EAAE;QACb,QAAQ,EAAE,EAAE;KACb,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,KAAoB,EAAE,QAAkB;IAC5D,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,QA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