wicked-crew 0.7.47 → 0.7.48

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 (96) hide show
  1. package/dist/api/chat-citations.d.ts +10 -1
  2. package/dist/api/chat-citations.d.ts.map +1 -1
  3. package/dist/api/chat-citations.js +28 -0
  4. package/dist/api/chat-citations.js.map +1 -1
  5. package/dist/api/chat-scope.d.ts +4 -2
  6. package/dist/api/chat-scope.d.ts.map +1 -1
  7. package/dist/api/chat-scope.js +35 -3
  8. package/dist/api/chat-scope.js.map +1 -1
  9. package/dist/api/chat-transcripts.d.ts +23 -1
  10. package/dist/api/chat-transcripts.d.ts.map +1 -1
  11. package/dist/api/chat-transcripts.js +61 -6
  12. package/dist/api/chat-transcripts.js.map +1 -1
  13. package/dist/api/eval-sample.d.ts +6 -6
  14. package/dist/api/routes.d.ts +11 -0
  15. package/dist/api/routes.d.ts.map +1 -1
  16. package/dist/api/routes.js +99 -4
  17. package/dist/api/routes.js.map +1 -1
  18. package/dist/api/server.d.ts +15 -0
  19. package/dist/api/server.d.ts.map +1 -1
  20. package/dist/api/server.js +94 -3
  21. package/dist/api/server.js.map +1 -1
  22. package/dist/cli/index.d.ts.map +1 -1
  23. package/dist/cli/index.js +16 -1
  24. package/dist/cli/index.js.map +1 -1
  25. package/dist/core/adapter.d.ts +16 -1
  26. package/dist/core/adapter.d.ts.map +1 -1
  27. package/dist/core/adapter.js +16 -0
  28. package/dist/core/adapter.js.map +1 -1
  29. package/dist/decisions/chat-recorder.d.ts +129 -0
  30. package/dist/decisions/chat-recorder.d.ts.map +1 -0
  31. package/dist/decisions/chat-recorder.js +367 -0
  32. package/dist/decisions/chat-recorder.js.map +1 -0
  33. package/dist/decisions/consider.d.ts +102 -0
  34. package/dist/decisions/consider.d.ts.map +1 -0
  35. package/dist/decisions/consider.js +207 -0
  36. package/dist/decisions/consider.js.map +1 -0
  37. package/dist/decisions/events.d.ts +2 -0
  38. package/dist/decisions/events.d.ts.map +1 -1
  39. package/dist/decisions/events.js +2 -0
  40. package/dist/decisions/events.js.map +1 -1
  41. package/dist/decisions/ingest.d.ts +28 -5
  42. package/dist/decisions/ingest.d.ts.map +1 -1
  43. package/dist/decisions/ingest.js +14 -6
  44. package/dist/decisions/ingest.js.map +1 -1
  45. package/dist/decisions/rules-text.d.ts +21 -0
  46. package/dist/decisions/rules-text.d.ts.map +1 -0
  47. package/dist/decisions/rules-text.js +50 -0
  48. package/dist/decisions/rules-text.js.map +1 -0
  49. package/dist/editors/csp.d.ts +31 -0
  50. package/dist/editors/csp.d.ts.map +1 -0
  51. package/dist/editors/csp.js +46 -0
  52. package/dist/editors/csp.js.map +1 -0
  53. package/dist/editors/pack-install.d.ts +28 -0
  54. package/dist/editors/pack-install.d.ts.map +1 -0
  55. package/dist/editors/pack-install.js +153 -0
  56. package/dist/editors/pack-install.js.map +1 -0
  57. package/dist/editors/registry.d.ts +142 -0
  58. package/dist/editors/registry.d.ts.map +1 -0
  59. package/dist/editors/registry.js +255 -0
  60. package/dist/editors/registry.js.map +1 -0
  61. package/dist/editors/routes.d.ts +46 -0
  62. package/dist/editors/routes.d.ts.map +1 -0
  63. package/dist/editors/routes.js +166 -0
  64. package/dist/editors/routes.js.map +1 -0
  65. package/dist/interactive/bridge-pool.d.ts +7 -2
  66. package/dist/interactive/bridge-pool.d.ts.map +1 -1
  67. package/dist/interactive/bridge-pool.js +6 -1
  68. package/dist/interactive/bridge-pool.js.map +1 -1
  69. package/dist/interactive/theme-events.d.ts +119 -0
  70. package/dist/interactive/theme-events.d.ts.map +1 -0
  71. package/dist/interactive/theme-events.js +606 -0
  72. package/dist/interactive/theme-events.js.map +1 -0
  73. package/dist/projects/routes.d.ts +2 -2
  74. package/dist/standing-orders/routes.d.ts +21 -21
  75. package/dist/standing-orders/store.d.ts +9 -9
  76. package/dist/watch/checks/claim-vs-evidence.d.ts +30 -0
  77. package/dist/watch/checks/claim-vs-evidence.d.ts.map +1 -0
  78. package/dist/watch/checks/claim-vs-evidence.js +152 -0
  79. package/dist/watch/checks/claim-vs-evidence.js.map +1 -0
  80. package/dist/watch/checks/index.d.ts.map +1 -1
  81. package/dist/watch/checks/index.js +5 -0
  82. package/dist/watch/checks/index.js.map +1 -1
  83. package/dist/watch/checks/warned-rule.d.ts +26 -0
  84. package/dist/watch/checks/warned-rule.d.ts.map +1 -0
  85. package/dist/watch/checks/warned-rule.js +126 -0
  86. package/dist/watch/checks/warned-rule.js.map +1 -0
  87. package/dist/watch/registry.d.ts +29 -0
  88. package/dist/watch/registry.d.ts.map +1 -1
  89. package/dist/watch/registry.js +60 -1
  90. package/dist/watch/registry.js.map +1 -1
  91. package/dist/watch/types.d.ts +19 -0
  92. package/dist/watch/types.d.ts.map +1 -1
  93. package/endpoint-manifest.json +95 -1
  94. package/package.json +1 -1
  95. package/watch/entries/claim-vs-evidence.json +13 -0
  96. package/watch/entries/risky-call.json +12 -0
@@ -0,0 +1,367 @@
1
+ /**
2
+ * The studio chat recorder (DES-decision-capture §4.3.3, DC-S4b; DOC-4: the pair framing).
3
+ *
4
+ * A chat seat is asked (the scope statement's `## Decisions` section, `chat-scope.ts`) to end every
5
+ * reply with a fenced `wicked-decisions` JSON block labelling the OPERATOR'S words of the turn it is
6
+ * answering. This module is the whole host:
7
+ *
8
+ * - {@link splitDecisionsBlock} / {@link DecisionFenceFilter}: the block never reaches a reader. The
9
+ * `chatReply` text is cut before persist and broadcast (`ChatTranscriptStore.rewriteEvent`), and the
10
+ * streamed `chatDelta` frames hold back a tail that could still become the fence, then drop
11
+ * everything from the fence on until the turn's reply (review S4 / N8).
12
+ * - {@link ChatDecisionRecorder}: the recorder is chosen deterministically from the turn's audience
13
+ * (the first `claude` seat, else the first seat in roster order — review N3); its items become
14
+ * records when their quote is found, whitespace-normalised, in the SAME turn's operator message
15
+ * (the model may label words, never invent them); every other seat's items are `labels.votes`.
16
+ * - It fails OPEN with no regex fallback: a missing or malformed block leaves the turn
17
+ * "unclassified" (a counter on `/diagnostics`) and the operator's words are STILL recorded, so the
18
+ * deterministic derivation (`derive.ts`) runs with no model at all. The model only adds offers.
19
+ * - DOC-4: an item that `approves_proposal` carries `decision_text` written from the seat's approved
20
+ * proposal; that text becomes the record's statement and the record names the proposal (the
21
+ * previous turn, the recorder seat). A bare "lets do it" therefore yields a decision whose text is
22
+ * the proposal's, never auto (`derive.ts` refuses auto for an approval).
23
+ *
24
+ * Words enter the ledger only through `ingestDecision` (§4.3.1): the actor is the one who SENT the
25
+ * message (`noteSend`, from the route), so an agent token's chat message records nothing.
26
+ */
27
+ import { z } from 'zod';
28
+ import { chatTurnStaleAfterMs } from '../api/chat-turns.js';
29
+ import { ingestDecision } from './ingest.js';
30
+ /** The opening fence, exactly as the codebook (`skills/mem/refs/decision-report.md`) spells it. */
31
+ export const DECISIONS_FENCE = '```wicked-decisions';
32
+ const STEERING_TYPES = [
33
+ 'architecture',
34
+ 'development',
35
+ 'security',
36
+ 'testing',
37
+ 'operations',
38
+ 'compliance',
39
+ 'design-ux',
40
+ ];
41
+ const ItemSchema = z.object({
42
+ quote: z.string().min(1).max(4000),
43
+ decision_text: z.string().max(600).nullish(),
44
+ type: z.enum(['rule', 'correction', 'scope', 'exception', 'choice', 'confirmation']),
45
+ codify: z.boolean().default(false),
46
+ ambiguous: z.boolean().default(false),
47
+ steering_type: z.enum(STEERING_TYPES).default('development'),
48
+ approves_proposal: z.boolean().default(false),
49
+ same_as: z.string().nullable().default(null),
50
+ });
51
+ const BlockSchema = z.object({ items: z.array(z.unknown()) });
52
+ /**
53
+ * Parse a block body. `null` when the JSON is malformed or the body is not `{items: [...]}`; an item
54
+ * that fails its own shape is dropped and counted, the rest survive.
55
+ */
56
+ export function parseDecisionsBlock(body) {
57
+ let raw;
58
+ try {
59
+ raw = JSON.parse(body);
60
+ }
61
+ catch {
62
+ return null;
63
+ }
64
+ const block = BlockSchema.safeParse(raw);
65
+ if (!block.success)
66
+ return null;
67
+ const items = [];
68
+ let dropped = 0;
69
+ for (const candidate of block.data.items) {
70
+ const item = ItemSchema.safeParse(candidate);
71
+ if (!item.success) {
72
+ dropped += 1;
73
+ continue;
74
+ }
75
+ const d = item.data;
76
+ items.push({
77
+ quote: d.quote,
78
+ ...(typeof d.decision_text === 'string' && d.decision_text.trim() !== '' ? { decision_text: d.decision_text.trim() } : {}),
79
+ type: d.type,
80
+ codify: d.codify,
81
+ ambiguous: d.ambiguous,
82
+ steering_type: d.steering_type,
83
+ approves_proposal: d.approves_proposal,
84
+ same_as: d.same_as,
85
+ });
86
+ }
87
+ return { items, dropped };
88
+ }
89
+ function trimEnd(text) {
90
+ return text.replace(/\s+$/u, '');
91
+ }
92
+ /**
93
+ * Cut the LAST fenced `wicked-decisions` block out of a reply. The opening fence must be a line of
94
+ * its own (leading indentation allowed — a list item or a quoted block is still a block; a mention of
95
+ * the fence inside a sentence is prose, codex r1). An opening fence with no closing fence — a reply
96
+ * cut off mid-block — is removed from its line on and reported `truncated`; nothing of a block ever
97
+ * reaches a reader.
98
+ */
99
+ export function splitDecisionsBlock(text) {
100
+ const openings = [...text.matchAll(/(^|\n)[ \t]*```wicked-decisions[ \t]*(?=\r?\n|$)/gu)];
101
+ const opening = openings[openings.length - 1];
102
+ if (opening === undefined || opening.index === undefined)
103
+ return { text, block: null, truncated: false };
104
+ const lineStart = opening.index + opening[1].length;
105
+ const afterOpen = text.indexOf('\n', lineStart);
106
+ if (afterOpen === -1)
107
+ return { text: trimEnd(text.slice(0, lineStart)), block: null, truncated: true };
108
+ const close = /\n[ \t]*```/u.exec(text.slice(afterOpen));
109
+ if (close === null)
110
+ return { text: trimEnd(text.slice(0, lineStart)), block: null, truncated: true };
111
+ const closeAt = afterOpen + close.index;
112
+ const body = text.slice(afterOpen + 1, closeAt).trim();
113
+ const rest = text.slice(closeAt + close[0].length).replace(/^[ \t]*\r?\n?/u, '');
114
+ return { text: trimEnd(text.slice(0, lineStart) + rest), block: body, truncated: false };
115
+ }
116
+ /**
117
+ * The `chatDelta` filter: per (chat, seat), hold back the longest tail that is still a prefix of the
118
+ * fence (so a fence split across frames is caught), and from the fence on drop every character
119
+ * until {@link reset} (the turn's `chatReply`, which carries the clean full text anyway).
120
+ */
121
+ export class DecisionFenceFilter {
122
+ state = new Map();
123
+ static key(chat, cliKey) {
124
+ return `${chat}\u0000${cliKey}`;
125
+ }
126
+ delta(chat, cliKey, text) {
127
+ const key = DecisionFenceFilter.key(chat, cliKey);
128
+ const s = this.state.get(key) ?? { held: '', dropping: false };
129
+ if (s.dropping) {
130
+ this.state.set(key, s);
131
+ return '';
132
+ }
133
+ const buf = s.held + text;
134
+ const at = buf.indexOf(DECISIONS_FENCE);
135
+ if (at !== -1) {
136
+ this.state.set(key, { held: '', dropping: true });
137
+ return buf.slice(0, at);
138
+ }
139
+ let hold = 0;
140
+ for (let n = Math.min(buf.length, DECISIONS_FENCE.length - 1); n > 0; n -= 1) {
141
+ if (DECISIONS_FENCE.startsWith(buf.slice(buf.length - n))) {
142
+ hold = n;
143
+ break;
144
+ }
145
+ }
146
+ if (hold === 0) {
147
+ this.state.delete(key);
148
+ return buf;
149
+ }
150
+ this.state.set(key, { held: buf.slice(buf.length - hold), dropping: false });
151
+ return buf.slice(0, buf.length - hold);
152
+ }
153
+ reset(chat, cliKey) {
154
+ this.state.delete(DecisionFenceFilter.key(chat, cliKey));
155
+ }
156
+ }
157
+ /** Whitespace-normalised: the only normalisation quote matching applies. */
158
+ function norm(text) {
159
+ return text.replace(/\s+/gu, ' ').trim();
160
+ }
161
+ /** The recorder of a turn: the first `claude` seat of its audience, else the first seat (review N3). */
162
+ export function pickRecorder(seats) {
163
+ return seats.find((s) => s === 'claude' || s.startsWith('claude')) ?? seats[0];
164
+ }
165
+ export class ChatDecisionRecorder {
166
+ deps;
167
+ turns = new Map();
168
+ lastTurn = new Map();
169
+ counters = new Map();
170
+ unclassified = 0;
171
+ recorded = 0;
172
+ now;
173
+ staleAfterMs;
174
+ inFlight = new Set();
175
+ constructor(deps) {
176
+ this.deps = deps;
177
+ this.now = deps.now ?? Date.now;
178
+ this.staleAfterMs = deps.staleAfterMs ?? chatTurnStaleAfterMs();
179
+ }
180
+ static key(chat, turnId) {
181
+ return `${chat}\u0000${turnId}`;
182
+ }
183
+ log(msg) {
184
+ this.deps.log?.(msg);
185
+ }
186
+ counter(cliKey) {
187
+ let c = this.counters.get(cliKey);
188
+ if (c === undefined) {
189
+ c = { replies: 0, blocks: 0, malformed: 0 };
190
+ this.counters.set(cliKey, c);
191
+ }
192
+ return c;
193
+ }
194
+ /** The route recorded a send: who said it (the actor), to whom (the audience the engine reached). */
195
+ noteSend(chat, turnId, actor, text, seats) {
196
+ // codex r1: a send sweeps too, so a chat whose seat went quiet does not keep its stale turns
197
+ // until some reply happens to arrive. Tracked, never awaited on the route.
198
+ this.track(this.sweep());
199
+ const prev = this.lastTurn.get(chat);
200
+ this.turns.set(ChatDecisionRecorder.key(chat, turnId), {
201
+ chat,
202
+ turnId,
203
+ at: this.now(),
204
+ actor,
205
+ text,
206
+ seats: [...new Set(seats)],
207
+ replies: new Map(),
208
+ ...(prev !== undefined ? { prevTurnId: prev } : {}),
209
+ });
210
+ this.lastTurn.set(chat, turnId);
211
+ }
212
+ /** A seat ended its part of a turn. Resolves once any recording it triggered has settled. */
213
+ async onReply(input) {
214
+ let parsed = null;
215
+ if (input.kind !== 'failed') {
216
+ const c = this.counter(input.cliKey);
217
+ c.replies += 1;
218
+ if (input.block !== null) {
219
+ parsed = parseDecisionsBlock(input.block);
220
+ if (parsed === null)
221
+ c.malformed += 1;
222
+ else
223
+ c.blocks += 1;
224
+ }
225
+ }
226
+ await this.sweep();
227
+ if (input.turnId === undefined)
228
+ return;
229
+ const turn = this.turns.get(ChatDecisionRecorder.key(input.chat, input.turnId));
230
+ if (turn === undefined)
231
+ return; // a turn this daemon never saw sent (a restart): nothing to record
232
+ turn.replies.set(input.cliKey, parsed);
233
+ if (turn.seats.every((s) => turn.replies.has(s)))
234
+ await this.finalize(turn);
235
+ }
236
+ /** The chat is gone: whatever its open turns gathered is recorded now. */
237
+ async closed(chat) {
238
+ for (const turn of [...this.turns.values()]) {
239
+ if (turn.chat === chat)
240
+ await this.finalize(turn);
241
+ }
242
+ this.lastTurn.delete(chat);
243
+ }
244
+ track(work) {
245
+ const tracked = work
246
+ .catch((err) => this.log(`[decisions] chat recorder: ${err instanceof Error ? err.message : String(err)}`))
247
+ .finally(() => this.inFlight.delete(tracked));
248
+ this.inFlight.add(tracked);
249
+ }
250
+ /** Resolves once every recording in flight has settled (tests, shutdown). */
251
+ async idle() {
252
+ while (this.inFlight.size > 0)
253
+ await Promise.all([...this.inFlight]);
254
+ }
255
+ diagnostics() {
256
+ const recorder = {};
257
+ for (const [k, v] of this.counters)
258
+ recorder[k] = { ...v };
259
+ return { mode: this.deps.service.mode, recorder, unclassified_turns: this.unclassified, recorded_turns: this.recorded };
260
+ }
261
+ async sweep() {
262
+ const now = this.now();
263
+ for (const turn of [...this.turns.values()]) {
264
+ if (now - turn.at >= this.staleAfterMs)
265
+ await this.finalize(turn);
266
+ }
267
+ }
268
+ async finalize(turn) {
269
+ this.turns.delete(ChatDecisionRecorder.key(turn.chat, turn.turnId));
270
+ const work = this.record(turn).catch((err) => this.log(`[decisions] chat ${turn.chat} turn ${turn.turnId}: ${err instanceof Error ? err.message : String(err)}`));
271
+ this.track(work);
272
+ await work;
273
+ }
274
+ async record(turn) {
275
+ // DC-S7: what the seats considered and cited this turn — whoever sent the message.
276
+ if (this.deps.onTurnRecorded !== undefined) {
277
+ await this.deps.onTurnRecorded(turn.chat, turn.turnId).catch((err) => this.log(`[decisions] considered for chat ${turn.chat} turn ${turn.turnId}: ${err instanceof Error ? err.message : String(err)}`));
278
+ }
279
+ // §4.3.1: an agent's words are not a decision source. The block was still stripped and counted.
280
+ if (turn.actor.kind !== 'human')
281
+ return;
282
+ const recorder = pickRecorder(turn.seats);
283
+ const own = recorder !== undefined ? (turn.replies.get(recorder) ?? null) : null;
284
+ if (own === null)
285
+ this.unclassified += 1;
286
+ const projectId = this.deps.projectOf(turn.chat) ?? null;
287
+ const haystack = norm(turn.text);
288
+ const records = [];
289
+ if (own !== null && recorder !== undefined) {
290
+ for (const item of own.items) {
291
+ const quote = norm(item.quote);
292
+ if (quote === '' || !haystack.includes(quote)) {
293
+ this.log(`[decisions] chat ${turn.chat} turn ${turn.turnId}: ${recorder} quote not found in the operator's message; dropped`);
294
+ continue;
295
+ }
296
+ const labels = {
297
+ is_decision: true,
298
+ type: item.type,
299
+ codify: item.codify,
300
+ ambiguous: item.ambiguous,
301
+ steering_type: item.steering_type,
302
+ same_as: item.same_as,
303
+ approves_proposal: item.approves_proposal,
304
+ recorder,
305
+ };
306
+ const votes = [];
307
+ for (const [cliKey, other] of turn.replies) {
308
+ if (cliKey === recorder || other === null)
309
+ continue;
310
+ const vote = other.items.find((o) => norm(o.quote) === quote);
311
+ if (vote !== undefined)
312
+ votes.push({ cli_key: cliKey, type: vote.type, codify: vote.codify });
313
+ }
314
+ const approved = item.approves_proposal && item.decision_text !== undefined;
315
+ const record = await ingestDecision(this.deps.service, {
316
+ host: 'studio-chat',
317
+ actor: turn.actor,
318
+ words: quote,
319
+ projectId,
320
+ chatId: turn.chat,
321
+ turnId: turn.turnId,
322
+ labels,
323
+ votes,
324
+ proposal: approved && turn.prevTurnId !== undefined
325
+ ? { turn_id: turn.prevTurnId, cli_key: recorder, excerpt: item.decision_text.slice(0, 300) }
326
+ : null,
327
+ ...(approved ? { statement: item.decision_text } : {}),
328
+ });
329
+ if (record !== null)
330
+ records.push(record);
331
+ }
332
+ }
333
+ if (records.length === 0) {
334
+ // No usable block, or no quote that matched: the words are recorded as typed, and the
335
+ // deterministic derivation alone decides the route (§4.3.3 fails open, no regex fallback).
336
+ const record = await ingestDecision(this.deps.service, {
337
+ host: 'studio-chat',
338
+ actor: turn.actor,
339
+ words: turn.text,
340
+ projectId,
341
+ chatId: turn.chat,
342
+ turnId: turn.turnId,
343
+ });
344
+ if (record !== null)
345
+ records.push(record);
346
+ }
347
+ if (records.length === 0)
348
+ return; // WICKED_DECISIONS=off, or nothing to record
349
+ this.recorded += 1;
350
+ const items = [];
351
+ for (const r of records) {
352
+ const view = this.deps.service.deps.ledger.view(r.id);
353
+ if (view !== null)
354
+ items.push(view);
355
+ }
356
+ const frame = {
357
+ type: 'chatDecisions',
358
+ chat: turn.chat,
359
+ turn_id: turn.turnId,
360
+ items,
361
+ ...(projectId !== null ? { project_id: projectId } : {}),
362
+ };
363
+ this.deps.broadcast(frame);
364
+ this.deps.transcripts.recordDecisions({ chat: turn.chat, turnId: turn.turnId, items });
365
+ }
366
+ }
367
+ //# sourceMappingURL=chat-recorder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-recorder.js","sourceRoot":"","sources":["../../src/decisions/chat-recorder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI7C,mGAAmG;AACnG,MAAM,CAAC,MAAM,eAAe,GAAG,qBAAqB,CAAC;AAErD,MAAM,cAAc,GAAG;IACrB,cAAc;IACd,aAAa;IACb,UAAU;IACV,SAAS;IACT,YAAY;IACZ,YAAY;IACZ,WAAW;CACmC,CAAC;AAoBjD,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;IAClC,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE;IAC5C,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,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CAAC;QACnB,MAAM,KAAK,GAAmB,EAAE,CAAC;QACjC,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;YACxB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACtD,IAAI,IAAI,KAAK,IAAI;gBAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtC,CAAC;QACD,MAAM,KAAK,GAAG;YACZ,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,MAAM;YACpB,KAAK;YACL,GAAG,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACzD,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAA6B,CAAC,CAAC;QACnD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACzF,CAAC;CACF"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * "Considered · set aside · cited (unchecked)" (DES-decision-capture §4.7, DC-S7).
3
+ *
4
+ * - **Considered** = the engine's `considerRules({projects:[project]}).in_force` for the turn's or
5
+ * unit's project (project rules + global ones). On an engine without the binding, the global
6
+ * rules alone, and the Consideration says so (`source: 'global-only'`).
7
+ * - **Set aside** = the engine's `set_aside` (out of scope / replaced / retired) plus crew's own
8
+ * pending candidates for that project — decisions `offered` but not yet confirmed.
9
+ * - **Cited (unchecked)** = every `[rule:<id>]` the persisted reply or step wrote. An id in the
10
+ * in-force set is "cited by the step — unchecked"; any other id is unverified. It is NEVER
11
+ * summed into a "followed" count (B4): advisory rules never decide, so nothing here can know
12
+ * whether a rule was followed — DES-rule-check supplies that verdict.
13
+ *
14
+ * The same object answers `GET /chats/:id/turns/:turnId/considered` and
15
+ * `GET /runs/:id/units/:unitKey/considered?attempt=`, and one `wicked.crew.rule.considered` fact
16
+ * (counts and ids, never words) is emitted when a turn or a unit attempt lands — keyed per turn
17
+ * and per (run, ord, attempt), so a re-dispatch is its own record (review N5).
18
+ */
19
+ import { RULE_CITED_LABEL, extractRuleCitations } from '../api/chat-citations.js';
20
+ import type { ChatTranscriptStore } from '../api/chat-transcripts.js';
21
+ import type { ConformanceRule, Consideration, SessionView } from '../core/types.js';
22
+ import { type DecisionBusEmit } from './events.js';
23
+ import type { DecisionLedger } from './ledger.js';
24
+ import { rulesPreface } from './rules-text.js';
25
+ export { RULE_CITED_LABEL, extractRuleCitations, rulesPreface };
26
+ /** What the service needs from the engine; every method optional so a partial stub never throws. */
27
+ export interface ConsiderAdapter {
28
+ projectRulesSupported?(): boolean;
29
+ listConformanceRules?(): Promise<ConformanceRule[]>;
30
+ considerRules?(query: {
31
+ projects?: string[];
32
+ steering_type?: string;
33
+ }): Promise<{
34
+ in_force: ConformanceRule[];
35
+ set_aside: Array<{
36
+ id: string;
37
+ statement: string;
38
+ reason: 'out_of_scope' | 'replaced' | 'retired';
39
+ }>;
40
+ }>;
41
+ sessionsDetail?(): Promise<SessionView[]>;
42
+ workOutput?(unitId: string): Promise<string | null>;
43
+ }
44
+ export interface InForceRead {
45
+ rules: ConformanceRule[];
46
+ setAside: Array<{
47
+ id: string;
48
+ statement: string;
49
+ reason: 'out_of_scope' | 'replaced' | 'retired';
50
+ }>;
51
+ source: Consideration['source'];
52
+ }
53
+ /**
54
+ * The in-force rules for a project. `considerRules` when the engine has it; else the global,
55
+ * non-retired rules; else (no engine read at all) nothing, said as `unavailable`. Never throws.
56
+ */
57
+ export declare function readInForce(adapter: ConsiderAdapter, projectId: string | null, log?: (m: string) => void): Promise<InForceRead>;
58
+ export interface ConsiderationDeps {
59
+ adapter: ConsiderAdapter;
60
+ /** Crew's own pending candidates (`offered`) become `not_confirmed` set-asides. Absent = none. */
61
+ ledger?: DecisionLedger;
62
+ /** The chat turn's persisted replies. Absent = no chat considerations. */
63
+ transcripts?: ChatTranscriptStore;
64
+ projectOf: (id: string) => string | undefined;
65
+ emit?: DecisionBusEmit | null;
66
+ log?: (msg: string) => void;
67
+ }
68
+ export declare class ConsiderationService {
69
+ private readonly deps;
70
+ /** chat → the rule ids its seats have been told about (the statement at open, then every preface). */
71
+ private readonly seen;
72
+ constructor(deps: ConsiderationDeps);
73
+ private log;
74
+ inForceFor(projectId: string | null): Promise<InForceRead>;
75
+ /** The in-force ids, or `null` when no engine read was possible (a citation then stays unchecked). */
76
+ inForceIds(projectId: string | null): Promise<ReadonlySet<string> | null>;
77
+ /** The chat opened with these rules in its statement. */
78
+ noteChatOpen(chat: string, rules: ReadonlyArray<ConformanceRule>): void;
79
+ /**
80
+ * The preface the next send carries, or `null`: the rules in force now that the seats have not
81
+ * been told about. A chat this daemon did not open (a restart) is SEEDED on its first send —
82
+ * nothing is known about what its seats were told, so the current set stands in for the open
83
+ * statement and that send carries no preface; a rule that lands after the seed is new to the
84
+ * seats and IS prefaced on the send after (codex r1, wording fixed: "seeded, then prefaced").
85
+ */
86
+ prefaceForSend(chat: string, opts?: {
87
+ inForce?: ReadonlyArray<ConformanceRule>;
88
+ }): Promise<string | null>;
89
+ chatClosed(chat: string): void;
90
+ private notConfirmed;
91
+ private build;
92
+ /** The Consideration of one chat turn, or `null` when the transcript holds no such turn. */
93
+ forChatTurn(chat: string, turnId: string): Promise<Consideration | null>;
94
+ /** The Consideration of one unit attempt (`unitKey` as `resolveUnit` accepts it), or `null`. */
95
+ forUnit(runId: string, unitKey: string, attempt?: number): Promise<Consideration | null>;
96
+ private emit;
97
+ /** A chat turn's replies all landed: compute and emit. Never throws. */
98
+ onChatTurn(chat: string, turnId: string): Promise<void>;
99
+ /** A unit attempt's output was captured: compute and emit. Never throws. */
100
+ onUnitCaptured(runId: string, ord: number, attempt: number): Promise<void>;
101
+ }
102
+ //# sourceMappingURL=consider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consider.d.ts","sourceRoot":"","sources":["../../src/decisions/consider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,gBAAgB,EAAsB,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACtG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGtE,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EAGb,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAiC,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAmB,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,YAAY,EAAE,CAAC;AAEhE,oGAAoG;AACpG,MAAM,WAAW,eAAe;IAC9B,qBAAqB,CAAC,IAAI,OAAO,CAAC;IAClC,oBAAoB,CAAC,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IACpD,aAAa,CAAC,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAC9E,QAAQ,EAAE,eAAe,EAAE,CAAC;QAC5B,SAAS,EAAE,KAAK,CAAC;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,cAAc,GAAG,UAAU,GAAG,SAAS,CAAA;SAAE,CAAC,CAAC;KACtG,CAAC,CAAC;IACH,cAAc,CAAC,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC1C,UAAU,CAAC,CAAC,MAAM,EAAE,M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