@qmilab/lodestar-core 0.1.5 → 0.2.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 (56) hide show
  1. package/dist/index.d.ts +6 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +12 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/schemas/action.d.ts +31 -13
  6. package/dist/schemas/action.d.ts.map +1 -1
  7. package/dist/schemas/action.js +20 -1
  8. package/dist/schemas/action.js.map +1 -1
  9. package/dist/schemas/approval.d.ts +271 -0
  10. package/dist/schemas/approval.d.ts.map +1 -0
  11. package/dist/schemas/approval.js +119 -0
  12. package/dist/schemas/approval.js.map +1 -0
  13. package/dist/schemas/belief.d.ts.map +1 -1
  14. package/dist/schemas/belief.js +7 -1
  15. package/dist/schemas/belief.js.map +1 -1
  16. package/dist/schemas/calibration.d.ts +977 -0
  17. package/dist/schemas/calibration.d.ts.map +1 -0
  18. package/dist/schemas/calibration.js +187 -0
  19. package/dist/schemas/calibration.js.map +1 -0
  20. package/dist/schemas/claim.d.ts.map +1 -1
  21. package/dist/schemas/claim.js +4 -2
  22. package/dist/schemas/claim.js.map +1 -1
  23. package/dist/schemas/common.d.ts.map +1 -1
  24. package/dist/schemas/common.js +11 -5
  25. package/dist/schemas/common.js.map +1 -1
  26. package/dist/schemas/policy.d.ts +768 -0
  27. package/dist/schemas/policy.d.ts.map +1 -0
  28. package/dist/schemas/policy.js +200 -0
  29. package/dist/schemas/policy.js.map +1 -0
  30. package/dist/schemas/probe-pack.d.ts +152 -0
  31. package/dist/schemas/probe-pack.d.ts.map +1 -0
  32. package/dist/schemas/probe-pack.js +140 -0
  33. package/dist/schemas/probe-pack.js.map +1 -0
  34. package/dist/schemas/reflection.d.ts +405 -0
  35. package/dist/schemas/reflection.d.ts.map +1 -0
  36. package/dist/schemas/reflection.js +154 -0
  37. package/dist/schemas/reflection.js.map +1 -0
  38. package/dist/schemas/revision.d.ts.map +1 -1
  39. package/dist/schemas/revision.js.map +1 -1
  40. package/dist/schemas/sentinel.d.ts +134 -0
  41. package/dist/schemas/sentinel.d.ts.map +1 -0
  42. package/dist/schemas/sentinel.js +97 -0
  43. package/dist/schemas/sentinel.js.map +1 -0
  44. package/package.json +2 -7
  45. package/src/index.ts +18 -0
  46. package/src/schemas/action.ts +20 -1
  47. package/src/schemas/approval.ts +136 -0
  48. package/src/schemas/belief.ts +7 -1
  49. package/src/schemas/calibration.ts +212 -0
  50. package/src/schemas/claim.ts +15 -8
  51. package/src/schemas/common.ts +16 -10
  52. package/src/schemas/policy.ts +231 -0
  53. package/src/schemas/probe-pack.ts +169 -0
  54. package/src/schemas/reflection.ts +166 -0
  55. package/src/schemas/revision.ts +7 -5
  56. package/src/schemas/sentinel.ts +104 -0
@@ -0,0 +1,405 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * What triggered a reflection pass.
4
+ *
5
+ * `cli` — invoked by `lodestar reflect` from a human operator.
6
+ * `programmatic` — invoked from host code (e.g. runGuarded, the MCP
7
+ * proxy) at a deliberate point.
8
+ * `tail_cascade` — a `belief.transitioned` event recorded a transition
9
+ * to `truth_status: contradicted`; the tail watcher dispatched a
10
+ * pass to look for dependent fall-out.
11
+ * `tail_batch` — N `belief.adopted` events have accrued since the
12
+ * last pass for the partition (configurable batch size).
13
+ * `sentinel` — a `sentinel.alerted` event named a `belief_id` as
14
+ * subject; the sentinel asked reflection to follow up.
15
+ */
16
+ export declare const ReflectionTriggerSchema: z.ZodEnum<["cli", "programmatic", "tail_cascade", "tail_batch", "sentinel"]>;
17
+ export type ReflectionTrigger = z.infer<typeof ReflectionTriggerSchema>;
18
+ /**
19
+ * The lifecycle axes a reflection proposal can target. Mirrors
20
+ * `LifecycleAxis` in `@qmilab/lodestar-memory-firewall` deliberately —
21
+ * the core package cannot import from downstream packages, so the
22
+ * literal union is duplicated here. Keep these in sync.
23
+ */
24
+ export declare const ReflectionLifecycleAxisSchema: z.ZodEnum<["truth_status", "retrieval_status", "security_status", "freshness_status"]>;
25
+ export type ReflectionLifecycleAxis = z.infer<typeof ReflectionLifecycleAxisSchema>;
26
+ /**
27
+ * Subject of a `no_op` proposal — reflection looked at this thing
28
+ * and decided no change. Recorded so the audit trail distinguishes
29
+ * "reflection considered X and did nothing" from "reflection did
30
+ * not consider X."
31
+ */
32
+ export declare const ReflectionSubjectSchema: z.ZodObject<{
33
+ kind: z.ZodEnum<["belief", "claim", "decision"]>;
34
+ id: z.ZodString;
35
+ }, "strip", z.ZodTypeAny, {
36
+ id: string;
37
+ kind: "belief" | "claim" | "decision";
38
+ }, {
39
+ id: string;
40
+ kind: "belief" | "claim" | "decision";
41
+ }>;
42
+ export type ReflectionSubject = z.infer<typeof ReflectionSubjectSchema>;
43
+ /**
44
+ * One typed proposal from a reflection pass.
45
+ *
46
+ * Proposals are *suggestions*. They do not mutate state. When a
47
+ * proposal is acted on, the runner calls the existing MemoryFirewall
48
+ * API with `by_authority: "reflection"`, and the firewall emits its
49
+ * own normal `belief.adopted` / `belief.transitioned` event whose
50
+ * `causal_parent_ids` includes the reflection pass's event id.
51
+ *
52
+ * The `rationale_id` on every variant points to an Explanation the
53
+ * runner generated alongside the proposal — same shape as the
54
+ * Explanations the firewall consumes for transitions.
55
+ */
56
+ export declare const ReflectionProposalSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
57
+ kind: z.ZodLiteral<"claim_promotion">;
58
+ claim_id: z.ZodString;
59
+ target_truth_status: z.ZodEnum<["unverified", "supported", "contradicted", "superseded"]>;
60
+ evidence_id: z.ZodString;
61
+ rationale_id: z.ZodString;
62
+ }, "strip", z.ZodTypeAny, {
63
+ kind: "claim_promotion";
64
+ claim_id: string;
65
+ rationale_id: string;
66
+ target_truth_status: "unverified" | "supported" | "contradicted" | "superseded";
67
+ evidence_id: string;
68
+ }, {
69
+ kind: "claim_promotion";
70
+ claim_id: string;
71
+ rationale_id: string;
72
+ target_truth_status: "unverified" | "supported" | "contradicted" | "superseded";
73
+ evidence_id: string;
74
+ }>, z.ZodObject<{
75
+ kind: z.ZodLiteral<"belief_transition">;
76
+ belief_id: z.ZodString;
77
+ axis: z.ZodEnum<["truth_status", "retrieval_status", "security_status", "freshness_status"]>;
78
+ from_value: z.ZodString;
79
+ to_value: z.ZodString;
80
+ evidence_id: z.ZodOptional<z.ZodString>;
81
+ rationale_id: z.ZodString;
82
+ }, "strip", z.ZodTypeAny, {
83
+ kind: "belief_transition";
84
+ rationale_id: string;
85
+ belief_id: string;
86
+ axis: "truth_status" | "retrieval_status" | "security_status" | "freshness_status";
87
+ from_value: string;
88
+ to_value: string;
89
+ evidence_id?: string | undefined;
90
+ }, {
91
+ kind: "belief_transition";
92
+ rationale_id: string;
93
+ belief_id: string;
94
+ axis: "truth_status" | "retrieval_status" | "security_status" | "freshness_status";
95
+ from_value: string;
96
+ to_value: string;
97
+ evidence_id?: string | undefined;
98
+ }>, z.ZodObject<{
99
+ kind: z.ZodLiteral<"belief_supersession">;
100
+ old_belief_id: z.ZodString;
101
+ new_belief_id: z.ZodString;
102
+ rationale_id: z.ZodString;
103
+ }, "strip", z.ZodTypeAny, {
104
+ kind: "belief_supersession";
105
+ rationale_id: string;
106
+ old_belief_id: string;
107
+ new_belief_id: string;
108
+ }, {
109
+ kind: "belief_supersession";
110
+ rationale_id: string;
111
+ old_belief_id: string;
112
+ new_belief_id: string;
113
+ }>, z.ZodObject<{
114
+ kind: z.ZodLiteral<"decision_dependency_flagged">;
115
+ decision_id: z.ZodString;
116
+ contradicted_belief_id: z.ZodString;
117
+ /**
118
+ * The contradicted belief's truth_status BEFORE the transition.
119
+ * Captured from the firing `belief.transitioned` payload's
120
+ * `from_value` (defensively a TruthStatus, but stored as the raw
121
+ * string the transition emitted). Used by the application step
122
+ * to record an accurate `old_value` in the dependent Decision's
123
+ * Revision — a belief can transition `unverified → contradicted`
124
+ * directly, not only from `supported`.
125
+ */
126
+ previous_truth_status: z.ZodEnum<["unverified", "supported", "contradicted", "superseded"]>;
127
+ rationale_id: z.ZodString;
128
+ }, "strip", z.ZodTypeAny, {
129
+ kind: "decision_dependency_flagged";
130
+ rationale_id: string;
131
+ decision_id: string;
132
+ contradicted_belief_id: string;
133
+ previous_truth_status: "unverified" | "supported" | "contradicted" | "superseded";
134
+ }, {
135
+ kind: "decision_dependency_flagged";
136
+ rationale_id: string;
137
+ decision_id: string;
138
+ contradicted_belief_id: string;
139
+ previous_truth_status: "unverified" | "supported" | "contradicted" | "superseded";
140
+ }>, z.ZodObject<{
141
+ kind: z.ZodLiteral<"no_op">;
142
+ subject: z.ZodObject<{
143
+ kind: z.ZodEnum<["belief", "claim", "decision"]>;
144
+ id: z.ZodString;
145
+ }, "strip", z.ZodTypeAny, {
146
+ id: string;
147
+ kind: "belief" | "claim" | "decision";
148
+ }, {
149
+ id: string;
150
+ kind: "belief" | "claim" | "decision";
151
+ }>;
152
+ rationale_id: z.ZodString;
153
+ }, "strip", z.ZodTypeAny, {
154
+ subject: {
155
+ id: string;
156
+ kind: "belief" | "claim" | "decision";
157
+ };
158
+ kind: "no_op";
159
+ rationale_id: string;
160
+ }, {
161
+ subject: {
162
+ id: string;
163
+ kind: "belief" | "claim" | "decision";
164
+ };
165
+ kind: "no_op";
166
+ rationale_id: string;
167
+ }>]>;
168
+ export type ReflectionProposal = z.infer<typeof ReflectionProposalSchema>;
169
+ /**
170
+ * The payload of a `reflection.completed@1` event.
171
+ *
172
+ * Idempotence is by cursor: a pass over events with `seq` strictly
173
+ * greater than `cursor.from_seq` and less than or equal to
174
+ * `cursor.to_seq` produces the same proposals on re-run. Re-running
175
+ * is safe — proposals are typed, no state has been mutated, and the
176
+ * harness can compare proposal sets across runs.
177
+ *
178
+ * `observed_event_ids` lists every event the pass actually read.
179
+ * `proposals` is non-empty in v0 — a pass that found nothing to act
180
+ * on emits a `no_op` proposal for at least one subject it inspected,
181
+ * so the harness can distinguish "ran and silent" from "did not run."
182
+ */
183
+ export declare const ReflectionCompletedPayloadSchema: z.ZodObject<{
184
+ pass_id: z.ZodString;
185
+ triggered_by: z.ZodEnum<["cli", "programmatic", "tail_cascade", "tail_batch", "sentinel"]>;
186
+ cursor: z.ZodObject<{
187
+ from_seq: z.ZodNumber;
188
+ to_seq: z.ZodNumber;
189
+ }, "strip", z.ZodTypeAny, {
190
+ from_seq: number;
191
+ to_seq: number;
192
+ }, {
193
+ from_seq: number;
194
+ to_seq: number;
195
+ }>;
196
+ observed_event_ids: z.ZodArray<z.ZodString, "many">;
197
+ proposals: z.ZodArray<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
198
+ kind: z.ZodLiteral<"claim_promotion">;
199
+ claim_id: z.ZodString;
200
+ target_truth_status: z.ZodEnum<["unverified", "supported", "contradicted", "superseded"]>;
201
+ evidence_id: z.ZodString;
202
+ rationale_id: z.ZodString;
203
+ }, "strip", z.ZodTypeAny, {
204
+ kind: "claim_promotion";
205
+ claim_id: string;
206
+ rationale_id: string;
207
+ target_truth_status: "unverified" | "supported" | "contradicted" | "superseded";
208
+ evidence_id: string;
209
+ }, {
210
+ kind: "claim_promotion";
211
+ claim_id: string;
212
+ rationale_id: string;
213
+ target_truth_status: "unverified" | "supported" | "contradicted" | "superseded";
214
+ evidence_id: string;
215
+ }>, z.ZodObject<{
216
+ kind: z.ZodLiteral<"belief_transition">;
217
+ belief_id: z.ZodString;
218
+ axis: z.ZodEnum<["truth_status", "retrieval_status", "security_status", "freshness_status"]>;
219
+ from_value: z.ZodString;
220
+ to_value: z.ZodString;
221
+ evidence_id: z.ZodOptional<z.ZodString>;
222
+ rationale_id: z.ZodString;
223
+ }, "strip", z.ZodTypeAny, {
224
+ kind: "belief_transition";
225
+ rationale_id: string;
226
+ belief_id: string;
227
+ axis: "truth_status" | "retrieval_status" | "security_status" | "freshness_status";
228
+ from_value: string;
229
+ to_value: string;
230
+ evidence_id?: string | undefined;
231
+ }, {
232
+ kind: "belief_transition";
233
+ rationale_id: string;
234
+ belief_id: string;
235
+ axis: "truth_status" | "retrieval_status" | "security_status" | "freshness_status";
236
+ from_value: string;
237
+ to_value: string;
238
+ evidence_id?: string | undefined;
239
+ }>, z.ZodObject<{
240
+ kind: z.ZodLiteral<"belief_supersession">;
241
+ old_belief_id: z.ZodString;
242
+ new_belief_id: z.ZodString;
243
+ rationale_id: z.ZodString;
244
+ }, "strip", z.ZodTypeAny, {
245
+ kind: "belief_supersession";
246
+ rationale_id: string;
247
+ old_belief_id: string;
248
+ new_belief_id: string;
249
+ }, {
250
+ kind: "belief_supersession";
251
+ rationale_id: string;
252
+ old_belief_id: string;
253
+ new_belief_id: string;
254
+ }>, z.ZodObject<{
255
+ kind: z.ZodLiteral<"decision_dependency_flagged">;
256
+ decision_id: z.ZodString;
257
+ contradicted_belief_id: z.ZodString;
258
+ /**
259
+ * The contradicted belief's truth_status BEFORE the transition.
260
+ * Captured from the firing `belief.transitioned` payload's
261
+ * `from_value` (defensively a TruthStatus, but stored as the raw
262
+ * string the transition emitted). Used by the application step
263
+ * to record an accurate `old_value` in the dependent Decision's
264
+ * Revision — a belief can transition `unverified → contradicted`
265
+ * directly, not only from `supported`.
266
+ */
267
+ previous_truth_status: z.ZodEnum<["unverified", "supported", "contradicted", "superseded"]>;
268
+ rationale_id: z.ZodString;
269
+ }, "strip", z.ZodTypeAny, {
270
+ kind: "decision_dependency_flagged";
271
+ rationale_id: string;
272
+ decision_id: string;
273
+ contradicted_belief_id: string;
274
+ previous_truth_status: "unverified" | "supported" | "contradicted" | "superseded";
275
+ }, {
276
+ kind: "decision_dependency_flagged";
277
+ rationale_id: string;
278
+ decision_id: string;
279
+ contradicted_belief_id: string;
280
+ previous_truth_status: "unverified" | "supported" | "contradicted" | "superseded";
281
+ }>, z.ZodObject<{
282
+ kind: z.ZodLiteral<"no_op">;
283
+ subject: z.ZodObject<{
284
+ kind: z.ZodEnum<["belief", "claim", "decision"]>;
285
+ id: z.ZodString;
286
+ }, "strip", z.ZodTypeAny, {
287
+ id: string;
288
+ kind: "belief" | "claim" | "decision";
289
+ }, {
290
+ id: string;
291
+ kind: "belief" | "claim" | "decision";
292
+ }>;
293
+ rationale_id: z.ZodString;
294
+ }, "strip", z.ZodTypeAny, {
295
+ subject: {
296
+ id: string;
297
+ kind: "belief" | "claim" | "decision";
298
+ };
299
+ kind: "no_op";
300
+ rationale_id: string;
301
+ }, {
302
+ subject: {
303
+ id: string;
304
+ kind: "belief" | "claim" | "decision";
305
+ };
306
+ kind: "no_op";
307
+ rationale_id: string;
308
+ }>]>, "many">;
309
+ started_at: z.ZodString;
310
+ finished_at: z.ZodString;
311
+ }, "strip", z.ZodTypeAny, {
312
+ triggered_by: "sentinel" | "cli" | "programmatic" | "tail_cascade" | "tail_batch";
313
+ pass_id: string;
314
+ cursor: {
315
+ from_seq: number;
316
+ to_seq: number;
317
+ };
318
+ observed_event_ids: string[];
319
+ proposals: ({
320
+ kind: "claim_promotion";
321
+ claim_id: string;
322
+ rationale_id: string;
323
+ target_truth_status: "unverified" | "supported" | "contradicted" | "superseded";
324
+ evidence_id: string;
325
+ } | {
326
+ kind: "belief_transition";
327
+ rationale_id: string;
328
+ belief_id: string;
329
+ axis: "truth_status" | "retrieval_status" | "security_status" | "freshness_status";
330
+ from_value: string;
331
+ to_value: string;
332
+ evidence_id?: string | undefined;
333
+ } | {
334
+ kind: "belief_supersession";
335
+ rationale_id: string;
336
+ old_belief_id: string;
337
+ new_belief_id: string;
338
+ } | {
339
+ kind: "decision_dependency_flagged";
340
+ rationale_id: string;
341
+ decision_id: string;
342
+ contradicted_belief_id: string;
343
+ previous_truth_status: "unverified" | "supported" | "contradicted" | "superseded";
344
+ } | {
345
+ subject: {
346
+ id: string;
347
+ kind: "belief" | "claim" | "decision";
348
+ };
349
+ kind: "no_op";
350
+ rationale_id: string;
351
+ })[];
352
+ started_at: string;
353
+ finished_at: string;
354
+ }, {
355
+ triggered_by: "sentinel" | "cli" | "programmatic" | "tail_cascade" | "tail_batch";
356
+ pass_id: string;
357
+ cursor: {
358
+ from_seq: number;
359
+ to_seq: number;
360
+ };
361
+ observed_event_ids: string[];
362
+ proposals: ({
363
+ kind: "claim_promotion";
364
+ claim_id: string;
365
+ rationale_id: string;
366
+ target_truth_status: "unverified" | "supported" | "contradicted" | "superseded";
367
+ evidence_id: string;
368
+ } | {
369
+ kind: "belief_transition";
370
+ rationale_id: string;
371
+ belief_id: string;
372
+ axis: "truth_status" | "retrieval_status" | "security_status" | "freshness_status";
373
+ from_value: string;
374
+ to_value: string;
375
+ evidence_id?: string | undefined;
376
+ } | {
377
+ kind: "belief_supersession";
378
+ rationale_id: string;
379
+ old_belief_id: string;
380
+ new_belief_id: string;
381
+ } | {
382
+ kind: "decision_dependency_flagged";
383
+ rationale_id: string;
384
+ decision_id: string;
385
+ contradicted_belief_id: string;
386
+ previous_truth_status: "unverified" | "supported" | "contradicted" | "superseded";
387
+ } | {
388
+ subject: {
389
+ id: string;
390
+ kind: "belief" | "claim" | "decision";
391
+ };
392
+ kind: "no_op";
393
+ rationale_id: string;
394
+ })[];
395
+ started_at: string;
396
+ finished_at: string;
397
+ }>;
398
+ export type ReflectionCompletedPayload = z.infer<typeof ReflectionCompletedPayloadSchema>;
399
+ /**
400
+ * Event-type literal. Use this constant rather than the bare string
401
+ * so a future rename is grep-safe.
402
+ */
403
+ export declare const REFLECTION_COMPLETED_EVENT_TYPE: "reflection.completed";
404
+ export declare const REFLECTION_COMPLETED_SCHEMA_VERSION: "1";
405
+ //# sourceMappingURL=reflection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflection.d.ts","sourceRoot":"","sources":["../../src/schemas/reflection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB,8EAMlC,CAAA;AACF,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AAEvE;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,wFAKxC,CAAA;AACF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAA;AAEnF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;EAGlC,CAAA;AACF,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AAEvE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAoCjC;;;;;;;;OAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IASL,CAAA;AACF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAEzE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAlCzC;;;;;;;;WAQG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+CL,CAAA;AACF,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAA;AAEzF;;;GAGG;AACH,eAAO,MAAM,+BAA+B,wBAAkC,CAAA;AAC9E,eAAO,MAAM,mCAAmC,KAAe,CAAA"}
@@ -0,0 +1,154 @@
1
+ import { z } from "zod";
2
+ import { TruthStatusSchema } from "./belief.js";
3
+ import { TimestampSchema } from "./common.js";
4
+ /**
5
+ * What triggered a reflection pass.
6
+ *
7
+ * `cli` — invoked by `lodestar reflect` from a human operator.
8
+ * `programmatic` — invoked from host code (e.g. runGuarded, the MCP
9
+ * proxy) at a deliberate point.
10
+ * `tail_cascade` — a `belief.transitioned` event recorded a transition
11
+ * to `truth_status: contradicted`; the tail watcher dispatched a
12
+ * pass to look for dependent fall-out.
13
+ * `tail_batch` — N `belief.adopted` events have accrued since the
14
+ * last pass for the partition (configurable batch size).
15
+ * `sentinel` — a `sentinel.alerted` event named a `belief_id` as
16
+ * subject; the sentinel asked reflection to follow up.
17
+ */
18
+ export const ReflectionTriggerSchema = z.enum([
19
+ "cli",
20
+ "programmatic",
21
+ "tail_cascade",
22
+ "tail_batch",
23
+ "sentinel",
24
+ ]);
25
+ /**
26
+ * The lifecycle axes a reflection proposal can target. Mirrors
27
+ * `LifecycleAxis` in `@qmilab/lodestar-memory-firewall` deliberately —
28
+ * the core package cannot import from downstream packages, so the
29
+ * literal union is duplicated here. Keep these in sync.
30
+ */
31
+ export const ReflectionLifecycleAxisSchema = z.enum([
32
+ "truth_status",
33
+ "retrieval_status",
34
+ "security_status",
35
+ "freshness_status",
36
+ ]);
37
+ /**
38
+ * Subject of a `no_op` proposal — reflection looked at this thing
39
+ * and decided no change. Recorded so the audit trail distinguishes
40
+ * "reflection considered X and did nothing" from "reflection did
41
+ * not consider X."
42
+ */
43
+ export const ReflectionSubjectSchema = z.object({
44
+ kind: z.enum(["belief", "claim", "decision"]),
45
+ id: z.string(),
46
+ });
47
+ /**
48
+ * One typed proposal from a reflection pass.
49
+ *
50
+ * Proposals are *suggestions*. They do not mutate state. When a
51
+ * proposal is acted on, the runner calls the existing MemoryFirewall
52
+ * API with `by_authority: "reflection"`, and the firewall emits its
53
+ * own normal `belief.adopted` / `belief.transitioned` event whose
54
+ * `causal_parent_ids` includes the reflection pass's event id.
55
+ *
56
+ * The `rationale_id` on every variant points to an Explanation the
57
+ * runner generated alongside the proposal — same shape as the
58
+ * Explanations the firewall consumes for transitions.
59
+ */
60
+ export const ReflectionProposalSchema = z.discriminatedUnion("kind", [
61
+ z.object({
62
+ kind: z.literal("claim_promotion"),
63
+ claim_id: z.string(),
64
+ target_truth_status: TruthStatusSchema,
65
+ evidence_id: z.string(),
66
+ rationale_id: z.string(),
67
+ }),
68
+ z.object({
69
+ kind: z.literal("belief_transition"),
70
+ belief_id: z.string(),
71
+ axis: ReflectionLifecycleAxisSchema,
72
+ from_value: z.string(),
73
+ to_value: z.string(),
74
+ evidence_id: z.string().optional(),
75
+ rationale_id: z.string(),
76
+ }),
77
+ z.object({
78
+ kind: z.literal("belief_supersession"),
79
+ old_belief_id: z.string(),
80
+ new_belief_id: z.string(),
81
+ rationale_id: z.string(),
82
+ }),
83
+ /**
84
+ * The decision-dependency cascade. When a belief that a past
85
+ * Decision depended on transitions to `truth_status: contradicted`,
86
+ * reflection proposes flagging that Decision as having a contradicted
87
+ * dependency. Applying the proposal emits a Revision event with
88
+ * `target_type: "decision"` so the decision's epistemic status
89
+ * change is recorded in the audit chain. (Closes the Batch-2-deferred
90
+ * "contradicted belief flags dependent decisions" invariant.)
91
+ */
92
+ z.object({
93
+ kind: z.literal("decision_dependency_flagged"),
94
+ decision_id: z.string(),
95
+ contradicted_belief_id: z.string(),
96
+ /**
97
+ * The contradicted belief's truth_status BEFORE the transition.
98
+ * Captured from the firing `belief.transitioned` payload's
99
+ * `from_value` (defensively a TruthStatus, but stored as the raw
100
+ * string the transition emitted). Used by the application step
101
+ * to record an accurate `old_value` in the dependent Decision's
102
+ * Revision — a belief can transition `unverified → contradicted`
103
+ * directly, not only from `supported`.
104
+ */
105
+ previous_truth_status: TruthStatusSchema,
106
+ rationale_id: z.string(),
107
+ }),
108
+ z.object({
109
+ kind: z.literal("no_op"),
110
+ subject: ReflectionSubjectSchema,
111
+ rationale_id: z.string(),
112
+ }),
113
+ ]);
114
+ /**
115
+ * The payload of a `reflection.completed@1` event.
116
+ *
117
+ * Idempotence is by cursor: a pass over events with `seq` strictly
118
+ * greater than `cursor.from_seq` and less than or equal to
119
+ * `cursor.to_seq` produces the same proposals on re-run. Re-running
120
+ * is safe — proposals are typed, no state has been mutated, and the
121
+ * harness can compare proposal sets across runs.
122
+ *
123
+ * `observed_event_ids` lists every event the pass actually read.
124
+ * `proposals` is non-empty in v0 — a pass that found nothing to act
125
+ * on emits a `no_op` proposal for at least one subject it inspected,
126
+ * so the harness can distinguish "ran and silent" from "did not run."
127
+ */
128
+ export const ReflectionCompletedPayloadSchema = z.object({
129
+ pass_id: z.string(),
130
+ triggered_by: ReflectionTriggerSchema,
131
+ cursor: z.object({
132
+ from_seq: z.number().int().min(-1).describe("-1 if this is the first pass for the partition"),
133
+ to_seq: z
134
+ .number()
135
+ .int()
136
+ .min(-1)
137
+ .describe("Equal to from_seq when the window is empty — the pass ran but observed no new events. " +
138
+ "Encoded explicitly (rather than skipping emission) so the audit chain can distinguish " +
139
+ "'reflection ran and was silent' from 'reflection did not run.'"),
140
+ }),
141
+ observed_event_ids: z.array(z.string()),
142
+ proposals: z
143
+ .array(ReflectionProposalSchema)
144
+ .min(1, "every reflection pass emits at least one proposal (no_op counts)"),
145
+ started_at: TimestampSchema,
146
+ finished_at: TimestampSchema,
147
+ });
148
+ /**
149
+ * Event-type literal. Use this constant rather than the bare string
150
+ * so a future rename is grep-safe.
151
+ */
152
+ export const REFLECTION_COMPLETED_EVENT_TYPE = "reflection.completed";
153
+ export const REFLECTION_COMPLETED_SCHEMA_VERSION = "1";
154
+ //# sourceMappingURL=reflection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflection.js","sourceRoot":"","sources":["../../src/schemas/reflection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,IAAI,CAAC;IAC5C,KAAK;IACL,cAAc;IACd,cAAc;IACd,YAAY;IACZ,UAA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kE,CAAC;IAC7E,UAAU,EAAE,eAAe;IAC3B,WAAW,EAAE,eAAe;CAC7B,CAAC,CAAA;AAGF;;;GAGG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,sBAA+B,CAAA;AAC9E,MAAM,CAAC,MAAM,mCAAmC,GAAG,GAAY,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"revision.d.ts","sourceRoot":"","sources":["../../src/schemas/revision.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYzB,CAAA;AACF,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAA;AAMrD;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,sMAUnC,CAAA;AACF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAEzE;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,oDAAkD,CAAA;AACxF,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAA;AAE3E;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAa5B,CAAA;AACF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA"}
1
+ {"version":3,"file":"revision.d.ts","sourceRoot":"","sources":["../../src/schemas/revision.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAczB,CAAA;AACF,MAAM,MAAM,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