wicked-crew 0.7.28 → 0.7.30

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 (146) hide show
  1. package/README.md +12 -1
  2. package/dist/api/chat-scope.d.ts +210 -0
  3. package/dist/api/chat-scope.d.ts.map +1 -0
  4. package/dist/api/chat-scope.js +728 -0
  5. package/dist/api/chat-scope.js.map +1 -0
  6. package/dist/api/diagnostics.d.ts +30 -2
  7. package/dist/api/diagnostics.d.ts.map +1 -1
  8. package/dist/api/diagnostics.js +73 -5
  9. package/dist/api/diagnostics.js.map +1 -1
  10. package/dist/api/governance-health.d.ts +171 -0
  11. package/dist/api/governance-health.d.ts.map +1 -0
  12. package/dist/api/governance-health.js +379 -0
  13. package/dist/api/governance-health.js.map +1 -0
  14. package/dist/api/open-path.d.ts.map +1 -1
  15. package/dist/api/open-path.js +2 -1
  16. package/dist/api/open-path.js.map +1 -1
  17. package/dist/api/post-hoc-deliver.d.ts +9 -5
  18. package/dist/api/post-hoc-deliver.d.ts.map +1 -1
  19. package/dist/api/post-hoc-deliver.js +21 -7
  20. package/dist/api/post-hoc-deliver.js.map +1 -1
  21. package/dist/api/routes.d.ts +70 -12
  22. package/dist/api/routes.d.ts.map +1 -1
  23. package/dist/api/routes.js +375 -60
  24. package/dist/api/routes.js.map +1 -1
  25. package/dist/api/seat-health.d.ts +38 -0
  26. package/dist/api/seat-health.d.ts.map +1 -1
  27. package/dist/api/seat-health.js +88 -5
  28. package/dist/api/seat-health.js.map +1 -1
  29. package/dist/api/seat-signin.d.ts.map +1 -1
  30. package/dist/api/seat-signin.js +49 -23
  31. package/dist/api/seat-signin.js.map +1 -1
  32. package/dist/api/seat-standing.d.ts +101 -0
  33. package/dist/api/seat-standing.d.ts.map +1 -0
  34. package/dist/api/seat-standing.js +138 -0
  35. package/dist/api/seat-standing.js.map +1 -0
  36. package/dist/api/server.d.ts.map +1 -1
  37. package/dist/api/server.js +37 -0
  38. package/dist/api/server.js.map +1 -1
  39. package/dist/campaigns/routes.d.ts +4 -4
  40. package/dist/cli/governance.d.ts +131 -0
  41. package/dist/cli/governance.d.ts.map +1 -0
  42. package/dist/cli/governance.js +354 -0
  43. package/dist/cli/governance.js.map +1 -0
  44. package/dist/cli/index.js +102 -3
  45. package/dist/cli/index.js.map +1 -1
  46. package/dist/core/adapter.d.ts +99 -1
  47. package/dist/core/adapter.d.ts.map +1 -1
  48. package/dist/core/adapter.js +149 -8
  49. package/dist/core/adapter.js.map +1 -1
  50. package/dist/core/bridge-path.d.ts +21 -0
  51. package/dist/core/bridge-path.d.ts.map +1 -1
  52. package/dist/core/bridge-path.js +37 -0
  53. package/dist/core/bridge-path.js.map +1 -1
  54. package/dist/core/bridge-reaper.d.ts.map +1 -1
  55. package/dist/core/bridge-reaper.js +11 -4
  56. package/dist/core/bridge-reaper.js.map +1 -1
  57. package/dist/core/deliver-text.d.ts +184 -0
  58. package/dist/core/deliver-text.d.ts.map +1 -0
  59. package/dist/core/deliver-text.js +434 -0
  60. package/dist/core/deliver-text.js.map +1 -0
  61. package/dist/core/deliver-triage.d.ts +90 -0
  62. package/dist/core/deliver-triage.d.ts.map +1 -0
  63. package/dist/core/deliver-triage.js +106 -0
  64. package/dist/core/deliver-triage.js.map +1 -0
  65. package/dist/core/deliver.d.ts +103 -9
  66. package/dist/core/deliver.d.ts.map +1 -1
  67. package/dist/core/deliver.js +244 -46
  68. package/dist/core/deliver.js.map +1 -1
  69. package/dist/core/estate-mcp-client.d.ts.map +1 -1
  70. package/dist/core/estate-mcp-client.js +7 -2
  71. package/dist/core/estate-mcp-client.js.map +1 -1
  72. package/dist/core/exec.d.ts.map +1 -1
  73. package/dist/core/exec.js +11 -1
  74. package/dist/core/exec.js.map +1 -1
  75. package/dist/core/governance-store.d.ts +219 -0
  76. package/dist/core/governance-store.d.ts.map +1 -0
  77. package/dist/core/governance-store.js +290 -0
  78. package/dist/core/governance-store.js.map +1 -0
  79. package/dist/core/repoPaths.d.ts +36 -5
  80. package/dist/core/repoPaths.d.ts.map +1 -1
  81. package/dist/core/repoPaths.js +46 -4
  82. package/dist/core/repoPaths.js.map +1 -1
  83. package/dist/interactive/bridge-pool.d.ts +29 -24
  84. package/dist/interactive/bridge-pool.d.ts.map +1 -1
  85. package/dist/interactive/bridge-pool.js +74 -7
  86. package/dist/interactive/bridge-pool.js.map +1 -1
  87. package/dist/interactive/chat-events.d.ts.map +1 -1
  88. package/dist/interactive/chat-events.js +5 -2
  89. package/dist/interactive/chat-events.js.map +1 -1
  90. package/dist/interactive/council-outcome.d.ts +28 -0
  91. package/dist/interactive/council-outcome.d.ts.map +1 -0
  92. package/dist/interactive/council-outcome.js +57 -0
  93. package/dist/interactive/council-outcome.js.map +1 -0
  94. package/dist/interactive/demo-events.d.ts.map +1 -1
  95. package/dist/interactive/demo-events.js +5 -2
  96. package/dist/interactive/demo-events.js.map +1 -1
  97. package/dist/interactive/doc-delete-routes.d.ts.map +1 -1
  98. package/dist/interactive/doc-delete-routes.js +3 -2
  99. package/dist/interactive/doc-delete-routes.js.map +1 -1
  100. package/dist/interactive/draft-events.d.ts.map +1 -1
  101. package/dist/interactive/draft-events.js +5 -2
  102. package/dist/interactive/draft-events.js.map +1 -1
  103. package/dist/interactive/edit-events.d.ts.map +1 -1
  104. package/dist/interactive/edit-events.js +5 -2
  105. package/dist/interactive/edit-events.js.map +1 -1
  106. package/dist/projects/auto-refresh.d.ts +54 -0
  107. package/dist/projects/auto-refresh.d.ts.map +1 -0
  108. package/dist/projects/auto-refresh.js +76 -0
  109. package/dist/projects/auto-refresh.js.map +1 -0
  110. package/dist/projects/graph-paths.d.ts +4 -2
  111. package/dist/projects/graph-paths.d.ts.map +1 -1
  112. package/dist/projects/graph-paths.js +4 -2
  113. package/dist/projects/graph-paths.js.map +1 -1
  114. package/dist/projects/graph.d.ts +20 -6
  115. package/dist/projects/graph.d.ts.map +1 -1
  116. package/dist/projects/graph.js +40 -13
  117. package/dist/projects/graph.js.map +1 -1
  118. package/dist/projects/routes.d.ts.map +1 -1
  119. package/dist/projects/routes.js +30 -11
  120. package/dist/projects/routes.js.map +1 -1
  121. package/dist/projects/state-home.d.ts +6 -0
  122. package/dist/projects/state-home.d.ts.map +1 -1
  123. package/dist/projects/state-home.js +9 -1
  124. package/dist/projects/state-home.js.map +1 -1
  125. package/dist/skills/guards.d.ts +17 -6
  126. package/dist/skills/guards.d.ts.map +1 -1
  127. package/dist/skills/guards.js +42 -15
  128. package/dist/skills/guards.js.map +1 -1
  129. package/dist/skills/plugin-source.d.ts.map +1 -1
  130. package/dist/skills/plugin-source.js +3 -0
  131. package/dist/skills/plugin-source.js.map +1 -1
  132. package/dist/skills/refs.d.ts +181 -17
  133. package/dist/skills/refs.d.ts.map +1 -1
  134. package/dist/skills/refs.js +345 -26
  135. package/dist/skills/refs.js.map +1 -1
  136. package/dist/skills/store.d.ts +22 -1
  137. package/dist/skills/store.d.ts.map +1 -1
  138. package/dist/skills/store.js +161 -23
  139. package/dist/skills/store.js.map +1 -1
  140. package/dist/studio/assets/index-CWUS9Ump.js +542 -0
  141. package/dist/studio/assets/{index-CK1uJWs2.css → index-_ydd-jKd.css} +1 -1
  142. package/dist/studio/index.html +2 -2
  143. package/dist/studio/testid-inventory.json +567 -6
  144. package/endpoint-manifest.json +67 -14
  145. package/package.json +4 -4
  146. package/dist/studio/assets/index-CdmCMh2f.js +0 -539
@@ -0,0 +1,379 @@
1
+ /**
2
+ * `GET /diagnostics` → `governance`: is the engine's governance evidence actually LANDING?
3
+ * (crew#495, acceptance finding F-022.)
4
+ *
5
+ * The engine's emit seam either writes an event onto the shared store (`WICKED_ESTATE_DB`) or
6
+ * spools it to the dead-letter outbox (`WICKED_APPS_EMIT_DEADLETTER`) with a loud stderr line
7
+ * nobody reads. Until this module existed, neither outcome reached `/diagnostics`, so a daemon
8
+ * that had dead-lettered every governance event for a week reported `recentErrors: []` while the
9
+ * home board said "Governed 100%". This is the daemon's read-only answer, assembled from records
10
+ * it already owns, under the surface's honesty rule: a number it cannot derive is `null`, never 0.
11
+ *
12
+ * - `store` — the resolved store and which rule chose it (`core/governance-store.ts`);
13
+ * `null` when this process never resolved one (a library boot) — then every emit
14
+ * dead-letters, and a `governance.store` finding says so.
15
+ * - `records` — EVENT nodes on the store now, and how many landed since this daemon booted.
16
+ * Counted through the engine binding (`Core.eventStoreCount`, wicked-core-ts ≥ the
17
+ * release carrying crew#495's companion); on an older addon both are `null`.
18
+ * - `deadletters` — a streamed fold of the outbox: count, per-type and per-reason buckets, the
19
+ * timestamp range where entries carry the engine's `ts` (older engines wrote none —
20
+ * those are counted as `untimestamped`, never given an invented time), plus the
21
+ * legacy HOME outbox a pre-fix engine wrote, if one exists.
22
+ * - `findings` — `governance.deadletter` (error) whenever the outbox holds an entry;
23
+ * `governance.store` (error) when no store is resolved; `governance.legacy-outbox`
24
+ * when the pre-fix HOME outbox exists — a WARNING naming the replay command when it
25
+ * is this daemon's own prior outbox (default state home under that HOME), an INFO
26
+ * with only the read-only `--dry-run` inspect recipe when the state home is isolated
27
+ * and the file cannot be attributed to this daemon (F-2R2-006: a fresh rig must not
28
+ * be told to import another daemon's dead letters).
29
+ */
30
+ import { createReadStream } from 'node:fs';
31
+ import { promises as fsp } from 'node:fs';
32
+ import { dirname } from 'node:path';
33
+ import { createInterface } from 'node:readline';
34
+ import { governanceSidecarDb, legacyOutboxScope, } from '../core/governance-store.js';
35
+ // ── The dead-letter fold ─────────────────────────────────────────────────────
36
+ /** Bounds on the fold's work: it runs inside a request handler, and a runaway outbox (227 MB of
37
+ * test junk was once observed under HOME) must not turn a diagnostics GET into a file crawl. Past
38
+ * the byte cap the fold stops and says so (`truncated`) — the count is then a floor, honestly
39
+ * labelled, never a guess at the rest. */
40
+ export const DEADLETTER_FOLD_MAX_BYTES = 256 * 1024 * 1024;
41
+ const DEADLETTER_FOLD_MAX_LINE_BYTES = 1024 * 1024;
42
+ /** Distinct event types are few (a dozen `wicked.*` names); anything past this many keys folds into `other`. */
43
+ const MAX_TYPE_KEYS = 64;
44
+ export function emptyDeadletterFold(path) {
45
+ return {
46
+ path,
47
+ count: 0,
48
+ byType: {},
49
+ byReason: {},
50
+ timestamped: 0,
51
+ untimestamped: 0,
52
+ oldestTs: null,
53
+ newestTs: null,
54
+ truncated: false,
55
+ };
56
+ }
57
+ /** The bucket a reason folds into: its text before the first `:` — the engine's three shapes are
58
+ * `no shared store (…)`, `open shared store failed: <path + error>` and `store write failed:
59
+ * <error>`, and only the prefix is stable across entries. */
60
+ export function reasonBucket(reason) {
61
+ const idx = reason.indexOf(':');
62
+ return (idx >= 0 ? reason.slice(0, idx) : reason).trim();
63
+ }
64
+ /** ECMAScript `Date`'s valid range: ±8.64e15 ms around the epoch (`toISOString` THROWS outside it). */
65
+ const MAX_EPOCH_MS = 8.64e15;
66
+ /** A usable `ts`: a finite, non-negative epoch-millisecond number inside `Date`'s range. Anything
67
+ * else on a spool line (a torn `1e20`, a negative, a string) is counted as untimestamped — never
68
+ * a `RangeError` that turns `/diagnostics` into a 500. */
69
+ export function isEpochMs(value) {
70
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= MAX_EPOCH_MS;
71
+ }
72
+ /** Buckets are `Map`s while folding — the keys come from file content, and a plain object keyed by
73
+ * `constructor`, `toString` or `__proto__` (a torn or hostile line) would either inherit a value or
74
+ * drop the bucket. Serialized to a plain object once, at the end. */
75
+ function bump(counts, key, cap) {
76
+ const k = counts.has(key) || counts.size < cap ? key : 'other';
77
+ counts.set(k, (counts.get(k) ?? 0) + 1);
78
+ }
79
+ /**
80
+ * Stream-fold one outbox file. A missing file is an EMPTY fold (no dead letters — the good case),
81
+ * an unreadable one folds what it could; a malformed line still COUNTS (it is an entry the engine
82
+ * appended; a torn tail from a crashed daemon is exactly what a replay must not lose sight of) but
83
+ * contributes no type or timestamp.
84
+ */
85
+ export async function foldDeadletters(path) {
86
+ const fold = emptyDeadletterFold(path);
87
+ let size;
88
+ try {
89
+ size = (await fsp.stat(path)).size;
90
+ }
91
+ catch {
92
+ return fold; // no outbox — nothing dead-lettered, honestly empty
93
+ }
94
+ if (size === 0)
95
+ return fold;
96
+ const end = Math.min(size, DEADLETTER_FOLD_MAX_BYTES) - 1;
97
+ fold.truncated = size > DEADLETTER_FOLD_MAX_BYTES;
98
+ let stream;
99
+ let rl;
100
+ try {
101
+ stream = createReadStream(path, { encoding: 'utf8', end });
102
+ rl = createInterface({ input: stream, crlfDelay: Infinity });
103
+ }
104
+ catch {
105
+ return fold;
106
+ }
107
+ const byType = new Map();
108
+ const byReason = new Map();
109
+ try {
110
+ for await (const line of rl) {
111
+ if (line.trim() === '')
112
+ continue;
113
+ fold.count += 1;
114
+ if (line.length > DEADLETTER_FOLD_MAX_LINE_BYTES) {
115
+ fold.untimestamped += 1;
116
+ continue;
117
+ }
118
+ let record;
119
+ try {
120
+ record = JSON.parse(line);
121
+ }
122
+ catch {
123
+ fold.untimestamped += 1;
124
+ continue;
125
+ }
126
+ bump(byType, typeof record.type === 'string' ? record.type : 'unknown', MAX_TYPE_KEYS);
127
+ bump(byReason, typeof record.deadletter_reason === 'string' ? reasonBucket(record.deadletter_reason) : 'unknown', MAX_TYPE_KEYS);
128
+ if (isEpochMs(record.ts)) {
129
+ fold.timestamped += 1;
130
+ if (fold.oldestTs === null || record.ts < fold.oldestTs)
131
+ fold.oldestTs = record.ts;
132
+ if (fold.newestTs === null || record.ts > fold.newestTs)
133
+ fold.newestTs = record.ts;
134
+ }
135
+ else {
136
+ fold.untimestamped += 1;
137
+ }
138
+ }
139
+ }
140
+ catch {
141
+ /* a read error mid-stream: keep what folded so far */
142
+ }
143
+ finally {
144
+ rl.close();
145
+ stream.destroy();
146
+ }
147
+ fold.byType = Object.fromEntries(byType);
148
+ fold.byReason = Object.fromEntries(byReason);
149
+ return fold;
150
+ }
151
+ /**
152
+ * The fold, re-run only when the outbox CHANGES (size or mtime) — one `stat` per request, never a
153
+ * re-read for a dashboard that polls, and never a stale answer once the engine appends.
154
+ */
155
+ export class DeadletterFoldCache {
156
+ value = null;
157
+ inFlight = null;
158
+ async get(path) {
159
+ let key;
160
+ try {
161
+ const st = await fsp.stat(path);
162
+ key = `${st.size}:${st.mtimeMs}`;
163
+ }
164
+ catch {
165
+ key = 'absent';
166
+ }
167
+ if (this.value !== null && this.value.key === key)
168
+ return this.value.fold;
169
+ if (this.inFlight !== null)
170
+ return this.inFlight;
171
+ this.inFlight = foldDeadletters(path)
172
+ .then((fold) => {
173
+ this.value = { key, fold };
174
+ return fold;
175
+ })
176
+ .finally(() => {
177
+ this.inFlight = null;
178
+ });
179
+ return this.inFlight;
180
+ }
181
+ }
182
+ /**
183
+ * Baseline-at-boot plus a short-TTL live count. `sinceBoot` is `total − baseline`; either side
184
+ * unknown (no binding, or a read that failed) folds to `null` rather than a fabricated delta.
185
+ */
186
+ export class GovernanceRecordCounter {
187
+ dbPath;
188
+ counter;
189
+ ttlMs;
190
+ baseline = null;
191
+ live = null;
192
+ inFlight = null;
193
+ baselinePromise;
194
+ constructor(dbPath, counter, ttlMs = 15_000) {
195
+ this.dbPath = dbPath;
196
+ this.counter = counter;
197
+ this.ttlMs = ttlMs;
198
+ this.baselinePromise = this.read().then((n) => {
199
+ this.baseline = n;
200
+ });
201
+ }
202
+ /** Test seam: the boot baseline has been taken. */
203
+ ready() {
204
+ return this.baselinePromise;
205
+ }
206
+ async read() {
207
+ if (this.dbPath === null || this.counter === null)
208
+ return null;
209
+ try {
210
+ return await this.counter(this.dbPath);
211
+ }
212
+ catch {
213
+ return null;
214
+ }
215
+ }
216
+ async total() {
217
+ const now = Date.now();
218
+ if (this.live !== null && now - this.live.at < this.ttlMs)
219
+ return this.live.total;
220
+ if (this.inFlight !== null)
221
+ return this.inFlight;
222
+ this.inFlight = this.read()
223
+ .then((total) => {
224
+ this.live = { at: Date.now(), total };
225
+ return total;
226
+ })
227
+ .finally(() => {
228
+ this.inFlight = null;
229
+ });
230
+ return this.inFlight;
231
+ }
232
+ async records() {
233
+ await this.baselinePromise;
234
+ const total = await this.total();
235
+ const sinceBoot = total !== null && this.baseline !== null ? Math.max(0, total - this.baseline) : null;
236
+ return { total, sinceBoot };
237
+ }
238
+ }
239
+ // ── Assembly ─────────────────────────────────────────────────────────────────
240
+ /** Quote one argument for the operator's shell: bare when it needs no quoting, otherwise
241
+ * single-quoted on POSIX and double-quoted on Windows (JSON quoting is not shell quoting there). */
242
+ export function shellQuote(arg) {
243
+ if (/^[A-Za-z0-9_./:@%+=,-]+$/.test(arg))
244
+ return arg; // `<` `>` are redirections — never bare
245
+ return process.platform === 'win32' ? `"${arg.replace(/"/g, '\\"')}"` : `'${arg.replace(/'/g, `'\\''`)}'`;
246
+ }
247
+ /**
248
+ * The replay recipe every finding points at — one spelling, so the console and the log agree — and
249
+ * TARGET-SPECIFIC: a bare recipe followed on a daemon booted with a custom `--db` or
250
+ * `--governance-db` would replay into a different store than the one that dead-lettered. The target
251
+ * is ALWAYS an explicit, DURABLE `--governance-db`: the flag outranks the env rungs of
252
+ * `replayTarget()`'s ladder (a `WICKED_CREW_GOVERNANCE_DB` / `WICKED_ESTATE_DB` exported in the
253
+ * operator's shell would otherwise win over `--db`), and a `:memory:` daemon's dead letters are
254
+ * pointed at its durable sidecar store rather than at a target a real replay refuses. `null` target
255
+ * = no daemon store known: the bare recipe, for a `--dry-run` inspection.
256
+ */
257
+ export function replayCommand(outboxPath, target) {
258
+ const base = `wicked-crew governance replay ${shellQuote(outboxPath)}`;
259
+ if (target === null)
260
+ return base;
261
+ const durable = target.dbPath === ':memory:' ? governanceSidecarDb(target.coreDbPath) : target.displayPath;
262
+ return `${base} --governance-db ${shellQuote(durable)}`;
263
+ }
264
+ export function governanceHealth(input) {
265
+ const findings = [];
266
+ // `displayPath`, never `dbPath`: a URL spec's credentials are for the engine, not the wire.
267
+ const store = input.location !== null ? { path: input.location.displayPath, source: input.location.source } : null;
268
+ if (store === null) {
269
+ findings.push({
270
+ kind: 'governance.store',
271
+ severity: 'error',
272
+ message: 'this daemon resolved no governance store — WICKED_ESTATE_DB is not exported to the engine, so every ' +
273
+ 'governance event (conformance claims, phase transitions, rule lifecycle) dead-letters instead of landing; ' +
274
+ 'boot through `wicked-crew serve` (which resolves <core db>.governance/governance.db) or pass --governance-db; ' +
275
+ `inspect any outbox meanwhile with ${replayCommand('<outbox.ndjson>', null)} --dry-run`,
276
+ });
277
+ }
278
+ if (input.fold.count > 0) {
279
+ const path = input.fold.path ?? '(unknown outbox)';
280
+ const newest = input.fold.newestTs !== null ? `, newest ${new Date(input.fold.newestTs).toISOString()}` : '';
281
+ const floor = input.fold.truncated ? ' (at least — the fold stopped at its size cap)' : '';
282
+ findings.push({
283
+ kind: 'governance.deadletter',
284
+ severity: 'error',
285
+ message: `${input.fold.count} governance event(s) dead-lettered to ${path}${floor}${newest} — the store refused or was ` +
286
+ `unset when they were emitted (${Object.keys(input.fold.byReason).join('; ') || 'reason unknown'}); ` +
287
+ `replay them with ${replayCommand(path, input.location)}`,
288
+ });
289
+ }
290
+ if (input.legacyOutbox !== null && input.legacyOutbox.scope === 'host') {
291
+ // CANNOT be attributed to this daemon (F-2R2-006; wording per the #533 review, F-3): an isolated
292
+ // state home shares HOME with every daemon on the host, so the file may hold any of theirs —
293
+ // including, for a daemon that ran since before the fix, its own. Said at `info`, with the
294
+ // read-only inspect recipe (a `--dry-run` writes nothing) and the REPLAY withheld: replaying
295
+ // into this store would import events another daemon spooled.
296
+ const inspect = `${replayCommand(input.legacyOutbox.path, null)} --dry-run`;
297
+ findings.push({
298
+ kind: 'governance.legacy-outbox',
299
+ severity: 'info',
300
+ message: `a pre-fix dead-letter outbox exists at ${input.legacyOutbox.path} (${input.legacyOutbox.bytes} bytes) — ` +
301
+ 'found under HOME — shared across daemons on this host; cannot be attributed to this daemon' +
302
+ (input.location !== null
303
+ ? ` (its state home is ${dirname(input.location.coreDbPath)} and its own outbox is ${input.location.outboxPath})`
304
+ : '') +
305
+ `. Inspect it read-only with ${inspect}; a replay into this daemon's store is withheld — it would import ` +
306
+ 'events another daemon spooled. The daemon that runs in that home\'s default state home reports and repairs it',
307
+ });
308
+ }
309
+ else if (input.legacyOutbox !== null) {
310
+ const recipe = replayCommand(input.legacyOutbox.path, input.location);
311
+ findings.push({
312
+ kind: 'governance.legacy-outbox',
313
+ severity: 'warning',
314
+ message: `a pre-fix dead-letter outbox exists under HOME at ${input.legacyOutbox.path} (${input.legacyOutbox.bytes} bytes) — ` +
315
+ `events this daemon's earlier versions spooled there instead of storing; inspect it with ` +
316
+ `${recipe} --dry-run, then ` +
317
+ (input.location !== null
318
+ ? `replay it into this daemon's store with ${recipe}`
319
+ : 'replay it once this daemon resolves a store') +
320
+ ' (a replay appends the lines that fail to land back onto that same file, so this warning persists until they are repaired)',
321
+ });
322
+ }
323
+ return {
324
+ store,
325
+ records: input.records,
326
+ deadletters: { ...input.fold, legacyOutbox: input.legacyOutbox },
327
+ findings,
328
+ };
329
+ }
330
+ /**
331
+ * `{ path, bytes, scope }` when the legacy HOME outbox exists and is non-empty (a `stat`, never a
332
+ * read), else `null`. `scope` is {@link legacyOutboxScope} against `coreDbPath` — the daemon's core
333
+ * db, `null` when no store resolved (then `host`: nothing to attribute the file to).
334
+ */
335
+ export async function probeLegacyOutbox(path, coreDbPath = null) {
336
+ if (path === null)
337
+ return null;
338
+ try {
339
+ const st = await fsp.stat(path);
340
+ return st.isFile() && st.size > 0
341
+ ? { path, bytes: st.size, scope: legacyOutboxScope(coreDbPath, path) }
342
+ : null;
343
+ }
344
+ catch {
345
+ return null;
346
+ }
347
+ }
348
+ /**
349
+ * The per-daemon diagnostics assembly the route calls: one fold cache, one record counter, one
350
+ * legacy probe. `legacyOutboxPath` is injectable so a test never has to `stat` the developer's real
351
+ * HOME to reason about the block.
352
+ */
353
+ export class GovernanceDiagnostics {
354
+ location;
355
+ legacyOutboxPath;
356
+ folds = new DeadletterFoldCache();
357
+ counter;
358
+ constructor(location, eventCounter, legacyOutboxPath) {
359
+ this.location = location;
360
+ this.legacyOutboxPath = legacyOutboxPath;
361
+ this.counter = new GovernanceRecordCounter(location?.dbPath ?? null, eventCounter);
362
+ }
363
+ /** Test seam: the boot baseline has been taken. */
364
+ ready() {
365
+ return this.counter.ready();
366
+ }
367
+ async health() {
368
+ const outbox = this.location?.outboxPath ?? null;
369
+ const [records, fold, legacyOutbox] = await Promise.all([
370
+ this.counter.records(),
371
+ outbox !== null ? this.folds.get(outbox) : Promise.resolve(emptyDeadletterFold(null)),
372
+ // The legacy pointer is only meaningful when it is NOT this daemon's own outbox; whose it is
373
+ // (`scope`) decides warning-with-recipe vs info-without (F-2R2-006).
374
+ probeLegacyOutbox(this.legacyOutboxPath !== null && this.legacyOutboxPath !== outbox ? this.legacyOutboxPath : null, this.location?.coreDbPath ?? null),
375
+ ]);
376
+ return governanceHealth({ location: this.location, records, fold, legacyOutbox });
377
+ }
378
+ }
379
+ //# sourceMappingURL=governance-health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"governance-health.js","sourceRoot":"","sources":["../../src/api/governance-health.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,QAAQ,IAAI,GAAG,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAIlB,MAAM,6BAA6B,CAAC;AAsDrC,gFAAgF;AAEhF;;;2CAG2C;AAC3C,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAC3D,MAAM,8BAA8B,GAAG,IAAI,GAAG,IAAI,CAAC;AACnD,gHAAgH;AAChH,MAAM,aAAa,GAAG,EAAE,CAAC;AAKzB,MAAM,UAAU,mBAAmB,CAAC,IAAmB;IACrD,OAAO;QACL,IAAI;QACJ,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;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnE"}
@@ -8,6 +8,7 @@
8
8
  import { spawn } from 'node:child_process';
9
9
  import { realpathSync } from 'node:fs';
10
10
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
11
+ import { childEnvWithBootEstateDb } from '../core/governance-store.js';
11
12
  /**
12
13
  * Is `target` inside `root` (or `root` itself), after normalization? Traversal-safe: the check is
13
14
  * on the RESOLVED relative path's first segment, so `/root/../evil` never passes, and a sibling
@@ -90,7 +91,7 @@ export function platformOpenCommand(target) {
90
91
  export function openWithSystemDefault(target) {
91
92
  const { cmd, args } = platformOpenCommand(target);
92
93
  return new Promise((resolvePromise, rejectPromise) => {
93
- const child = spawn(cmd, args, { detached: true, stdio: 'ignore' });
94
+ const child = spawn(cmd, args, { detached: true, stdio: 'ignore', env: childEnvWithBootEstateDb() });
94
95
  child.once('error', rejectPromise);
95
96
  child.once('spawn', () => {
96
97
  child.unref();
@@ -1 +1 @@
1
- {"version":3,"file":"open-path.js","sourceRoot":"","sources":["../../src/api/open-path.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,EAAE;AACF,kGAAkG;AAClG,+FAA+F;AAC/F,kGAAkG;AAClG,gGAAgG;AAChG,6CAA6C;AAE7C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAExF;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,MAAc;IACvD,4EAA4E;IAC5E,qFAAqF;IACrF,sFAAsF;IACtF,uFAAuF;IACvF,qFAAqF;IACrF,wFAAwF;IACxF,2FAA2F;IAC3F,MAAM,IAAI,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KAAK,EAAE,CAAC;YACd,cAAc,EAAE,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -15,6 +15,7 @@
15
15
  * (non-zero ⇒ a loud 4xx carrying the script's own words; zero ⇒ the PR URL is re-extracted
16
16
  * crew-side via `prUrlFrom`, the same grep the script itself ends with).
17
17
  */
18
+ import { type DeliverScriptOptions } from '../core/deliver.js';
18
19
  /** What one spawn of the deliver script produced: its exit status and merged output. */
19
20
  export interface DeliverScriptResult {
20
21
  /** 0 = the script itself reported a delivery; anything else is the script's loud refusal. */
@@ -26,8 +27,10 @@ export interface DeliverScriptResult {
26
27
  spawnFailure?: boolean;
27
28
  }
28
29
  /** The exec seam the deliver route runs the script through — injectable so route tests can
29
- * point HOME/PATH at a fixture (a stub `gh`, a temp home) without touching the daemon env. */
30
- export type DeliverExec = (workdir: string, intent?: string) => Promise<DeliverScriptResult>;
30
+ * point HOME/PATH at a fixture (a stub `gh`, a temp home) without touching the daemon env.
31
+ * `opts` is the script's PR/commit text context (crew#524): the run id, the facts the route
32
+ * already holds for the fallback text, and this daemon's own origin for the run-record fetch. */
33
+ export type DeliverExec = (workdir: string, intent?: string, opts?: DeliverScriptOptions) => Promise<DeliverScriptResult>;
31
34
  /** A worktree stood back up from a run's `wicked/<id>` branch, plus its teardown (crew#418). */
32
35
  export interface ReprovisionedWorktree {
33
36
  /** The path to deliver in — a throwaway checkout of `wicked/<runId>`. */
@@ -58,8 +61,9 @@ export declare const gitReprovisionWorktree: WorktreeReprovisioner;
58
61
  /**
59
62
  * The production {@link DeliverExec}: `bash -lc <script>` in the run's worktree — the exact
60
63
  * invocation core's `run_tool_cmd` uses for the deliver phase (login shell, so the operator's
61
- * PATH — where `gh` lives — is loaded). `env` overlays the daemon's own environment; tests use
62
- * it to substitute HOME (whose `.bash_profile` prepends a stub `gh`), production passes none.
64
+ * PATH — where `gh` lives — is loaded). `opts` is the PR/commit text context (crew#524). `env`
65
+ * overlays the daemon's own environment; tests use it to substitute HOME (whose `.bash_profile`
66
+ * prepends a stub `gh`), production passes none.
63
67
  */
64
- export declare function runDeliverScript(workdir: string, intent?: string, env?: Record<string, string>): Promise<DeliverScriptResult>;
68
+ export declare function runDeliverScript(workdir: string, intent?: string, opts?: DeliverScriptOptions, env?: Record<string, string>): Promise<DeliverScriptResult>;
65
69
  //# sourceMappingURL=post-hoc-deliver.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"post-hoc-deliver.d.ts","sourceRoot":"","sources":["../../src/api/post-hoc-deliver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AASH,wFAAwF;AACxF,MAAM,WAAW,mBAAmB;IAClC,6FAA6F;IAC7F,MAAM,EAAE,MAAM,CAAC;IACf,gGAAgG;IAChG,MAAM,EAAE,MAAM,CAAC;IACf;+FAC2F;IAC3F,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;+FAC+F;AAC/F,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAE7F,gGAAgG;AAChG,MAAM,WAAW,qBAAqB;IACpC,yEAAyE;IACzE,OAAO,EAAE,MAAM,CAAC;IAChB,wFAAwF;IACxF,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;kGACkG;AAClG,MAAM,MAAM,qBAAqB,GAAG,CAClC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAAC;AAE3C;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,sBAAsB,EAAE,qBAmCpC,CAAC;AAQF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,EACf,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,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execFile } from 'node:child_process';
19
19
  import { mkdtemp, rm } from 'node:fs/promises';
20
20
  import { tmpdir } from 'node:os';
21
21
  import { join } from 'node:path';
22
- import { deliverPrScript } from '../core/deliver.js';
22
+ import { DELIVER_POSTHOC_ENV, DELIVER_VERIFIED_BASE_ENV, deliverPrScript, } from '../core/deliver.js';
23
+ import { childEnvWithBootEstateDb } from '../core/governance-store.js';
23
24
  /**
24
25
  * Stand a run's committed work back up from its `wicked/<runId>` branch (crew#418).
25
26
  *
@@ -39,7 +40,7 @@ import { deliverPrScript } from '../core/deliver.js';
39
40
  export const gitReprovisionWorktree = async (repoRoot, runId) => {
40
41
  const branch = `wicked/${runId}`;
41
42
  const run = (args) => new Promise((resolve, reject) => {
42
- execFile('git', ['-C', repoRoot, ...args], { windowsHide: true }, (err) => err === null ? resolve() : reject(err));
43
+ execFile('git', ['-C', repoRoot, ...args], { windowsHide: true, env: childEnvWithBootEstateDb() }, (err) => err === null ? resolve() : reject(err));
43
44
  });
44
45
  const dir = await mkdtemp(join(tmpdir(), `wicked-deliver-${runId.replace(/[^\w.-]/g, '_')}-`));
45
46
  // Is the run's branch even there? Absent ⇒ the work is genuinely GONE → null (the route answers
@@ -78,14 +79,27 @@ const SCRIPT_TIMEOUT_MS = 5 * 60_000;
78
79
  /**
79
80
  * The production {@link DeliverExec}: `bash -lc <script>` in the run's worktree — the exact
80
81
  * invocation core's `run_tool_cmd` uses for the deliver phase (login shell, so the operator's
81
- * PATH — where `gh` lives — is loaded). `env` overlays the daemon's own environment; tests use
82
- * it to substitute HOME (whose `.bash_profile` prepends a stub `gh`), production passes none.
82
+ * PATH — where `gh` lives — is loaded). `opts` is the PR/commit text context (crew#524). `env`
83
+ * overlays the daemon's own environment; tests use it to substitute HOME (whose `.bash_profile`
84
+ * prepends a stub `gh`), production passes none.
83
85
  */
84
- export function runDeliverScript(workdir, intent, env) {
86
+ export function runDeliverScript(workdir, intent, opts, env) {
87
+ // The daemon's governance-store variables never ride into the deliver shell: the helper is
88
+ // applied LAST, so a caller overlay that spreads `process.env` cannot put them back.
89
+ const shellEnv = childEnvWithBootEstateDb({ ...process.env, ...env });
90
+ // A post-hoc lift has NO engine verification to pin to — the daemon runs the script itself, no
91
+ // deliver lift preceded it — so the script's verified-base refusal (wicked-core#431,
92
+ // `WICKED_DELIVER_VERIFIED_BASE`) must not fire off a stray pin in the daemon's own environment:
93
+ // it would refuse a base that merely differs from something nobody verified THIS work against.
94
+ delete shellEnv[DELIVER_VERIFIED_BASE_ENV];
95
+ // …and the script is told this IS a post-hoc lift, so the crew#426 preflight may regenerate
96
+ // tracked files and deliver them (disclosed) instead of refusing as an engine-driven Tool unit
97
+ // must (wicked-core#433 review addendum — there is no verified tree here to weaken).
98
+ shellEnv[DELIVER_POSTHOC_ENV] = '1';
85
99
  return new Promise((resolve) => {
86
- execFile('bash', ['-lc', deliverPrScript(intent)], {
100
+ execFile('bash', ['-lc', deliverPrScript(intent, opts)], {
87
101
  cwd: workdir,
88
- env: { ...process.env, ...env },
102
+ env: shellEnv,
89
103
  maxBuffer: OUTPUT_CAP_BYTES,
90
104
  timeout: SCRIPT_TIMEOUT_MS,
91
105
  }, (err, stdout, stderr) => {
@@ -1 +1 @@
1
- {"version":3,"file":"post-hoc-deliver.js","sourceRoot":"","sources":["../../src/api/post-hoc-deliver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAgCrD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAA0B,KAAK,EAAE,QAAQ,EAAE,KAAK,EAA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