@isaacriehm/cairn-state 0.22.5

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 (94) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/alignment-pending.d.ts +28 -0
  5. package/dist/alignment-pending.js +83 -0
  6. package/dist/alignment-pending.js.map +1 -0
  7. package/dist/anchor-map.d.ts +14 -0
  8. package/dist/anchor-map.js +56 -0
  9. package/dist/anchor-map.js.map +1 -0
  10. package/dist/archive.d.ts +48 -0
  11. package/dist/archive.js +96 -0
  12. package/dist/archive.js.map +1 -0
  13. package/dist/cache.d.ts +48 -0
  14. package/dist/cache.js +241 -0
  15. package/dist/cache.js.map +1 -0
  16. package/dist/component-registry.d.ts +93 -0
  17. package/dist/component-registry.js +0 -0
  18. package/dist/component-registry.js.map +1 -0
  19. package/dist/components.d.ts +192 -0
  20. package/dist/components.js +603 -0
  21. package/dist/components.js.map +1 -0
  22. package/dist/config.d.ts +9 -0
  23. package/dist/config.js +26 -0
  24. package/dist/config.js.map +1 -0
  25. package/dist/drift.d.ts +8 -0
  26. package/dist/drift.js +23 -0
  27. package/dist/drift.js.map +1 -0
  28. package/dist/file-candidates-map.d.ts +23 -0
  29. package/dist/file-candidates-map.js +76 -0
  30. package/dist/file-candidates-map.js.map +1 -0
  31. package/dist/frontmatter.d.ts +32 -0
  32. package/dist/frontmatter.js +77 -0
  33. package/dist/frontmatter.js.map +1 -0
  34. package/dist/fs.d.ts +36 -0
  35. package/dist/fs.js +47 -0
  36. package/dist/fs.js.map +1 -0
  37. package/dist/glob.d.ts +10 -0
  38. package/dist/glob.js +46 -0
  39. package/dist/glob.js.map +1 -0
  40. package/dist/home.d.ts +69 -0
  41. package/dist/home.js +168 -0
  42. package/dist/home.js.map +1 -0
  43. package/dist/index.d.ts +29 -0
  44. package/dist/index.js +30 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/languages.d.ts +113 -0
  47. package/dist/languages.js +512 -0
  48. package/dist/languages.js.map +1 -0
  49. package/dist/ledgers.d.ts +14 -0
  50. package/dist/ledgers.js +105 -0
  51. package/dist/ledgers.js.map +1 -0
  52. package/dist/logger.d.ts +13 -0
  53. package/dist/logger.js +17 -0
  54. package/dist/logger.js.map +1 -0
  55. package/dist/manifest.d.ts +10 -0
  56. package/dist/manifest.js +84 -0
  57. package/dist/manifest.js.map +1 -0
  58. package/dist/missions.d.ts +119 -0
  59. package/dist/missions.js +414 -0
  60. package/dist/missions.js.map +1 -0
  61. package/dist/paths.d.ts +117 -0
  62. package/dist/paths.js +241 -0
  63. package/dist/paths.js.map +1 -0
  64. package/dist/quality-grades.d.ts +11 -0
  65. package/dist/quality-grades.js +100 -0
  66. package/dist/quality-grades.js.map +1 -0
  67. package/dist/rejected.d.ts +42 -0
  68. package/dist/rejected.js +100 -0
  69. package/dist/rejected.js.map +1 -0
  70. package/dist/schemas.d.ts +789 -0
  71. package/dist/schemas.js +506 -0
  72. package/dist/schemas.js.map +1 -0
  73. package/dist/scope-index.d.ts +96 -0
  74. package/dist/scope-index.js +299 -0
  75. package/dist/scope-index.js.map +1 -0
  76. package/dist/slug.d.ts +81 -0
  77. package/dist/slug.js +138 -0
  78. package/dist/slug.js.map +1 -0
  79. package/dist/sot-bindings.d.ts +14 -0
  80. package/dist/sot-bindings.js +79 -0
  81. package/dist/sot-bindings.js.map +1 -0
  82. package/dist/sot-cache.d.ts +18 -0
  83. package/dist/sot-cache.js +62 -0
  84. package/dist/sot-cache.js.map +1 -0
  85. package/dist/text.d.ts +27 -0
  86. package/dist/text.js +63 -0
  87. package/dist/text.js.map +1 -0
  88. package/dist/topic-index.d.ts +27 -0
  89. package/dist/topic-index.js +82 -0
  90. package/dist/topic-index.js.map +1 -0
  91. package/dist/walk.d.ts +7 -0
  92. package/dist/walk.js +34 -0
  93. package/dist/walk.js.map +1 -0
  94. package/package.json +35 -0
@@ -0,0 +1,506 @@
1
+ import { z } from "zod";
2
+ export const Audience = z.enum(["ai-only", "dual", "human-only"]);
3
+ export const ProvenanceFrontmatter = z
4
+ .object({
5
+ type: z.string().optional(),
6
+ status: z.string().optional(),
7
+ audience: Audience.optional(),
8
+ generated: z.string().optional(),
9
+ "verified-at": z.string().optional(),
10
+ "source-commits": z.array(z.string()).optional(),
11
+ supersedes: z.string().nullish(),
12
+ })
13
+ .passthrough();
14
+ export const ManifestEntry = z.object({
15
+ path: z.string(),
16
+ sha256: z.string().length(64),
17
+ classification: z.string(),
18
+ audience: z.string().optional(),
19
+ verified_at: z.string().optional(),
20
+ generator: z.string().optional(),
21
+ source: z.string().optional(),
22
+ });
23
+ export const Manifest = z.object({
24
+ version: z.literal(1),
25
+ generated: z.string(),
26
+ generator: z.string().optional(),
27
+ files: z.array(ManifestEntry),
28
+ });
29
+ export const DecisionAssertion = z.discriminatedUnion("kind", [
30
+ z.object({
31
+ id: z.string(),
32
+ kind: z.literal("schema_must_contain"),
33
+ table: z.string(),
34
+ column: z.string(),
35
+ column_type: z.string().optional(),
36
+ nullable: z.boolean().optional(),
37
+ }),
38
+ z.object({
39
+ id: z.string(),
40
+ kind: z.literal("text_must_match"),
41
+ pattern: z.string(),
42
+ in_globs: z.array(z.string()),
43
+ }),
44
+ z.object({
45
+ id: z.string(),
46
+ kind: z.literal("text_must_not_match"),
47
+ pattern: z.string(),
48
+ in_globs: z.array(z.string()),
49
+ }),
50
+ z.object({
51
+ id: z.string(),
52
+ kind: z.literal("index_must_exist"),
53
+ table: z.string(),
54
+ columns: z.array(z.string()),
55
+ where: z.string().optional(),
56
+ }),
57
+ z.object({
58
+ id: z.string(),
59
+ kind: z.literal("ast_pattern"),
60
+ language: z.string(),
61
+ pattern: z.string(),
62
+ in_globs: z.array(z.string()),
63
+ }),
64
+ z.object({
65
+ id: z.string(),
66
+ kind: z.literal("file_must_not_be_modified"),
67
+ path: z.string(),
68
+ }),
69
+ z.object({
70
+ id: z.string(),
71
+ kind: z.literal("query_must_filter_by"),
72
+ orm: z.string(),
73
+ in_globs: z.array(z.string()),
74
+ table: z.string(),
75
+ columns: z.array(z.string()),
76
+ operator: z.enum(["eq", "in", "between", "is_not_null"]),
77
+ require_combination: z.enum(["and", "or"]),
78
+ }),
79
+ z.object({
80
+ id: z.string(),
81
+ kind: z.literal("route_must_have_guard"),
82
+ in_globs: z.array(z.string()),
83
+ guard: z.string(),
84
+ require_on: z.array(z.string()),
85
+ }),
86
+ z.object({
87
+ id: z.string(),
88
+ kind: z.literal("event_must_emit"),
89
+ in_globs: z.array(z.string()),
90
+ after_method: z.string(),
91
+ event_key: z.string(),
92
+ payload_must_include: z.array(z.string()).optional(),
93
+ }),
94
+ z.object({
95
+ id: z.string(),
96
+ kind: z.literal("service_method_must_call"),
97
+ in_globs: z.array(z.string()),
98
+ in_method: z.string(),
99
+ must_call: z.string(),
100
+ before_returning: z.boolean().optional(),
101
+ }),
102
+ z.object({
103
+ id: z.string(),
104
+ kind: z.literal("human_review_hint"),
105
+ description: z.string(),
106
+ }),
107
+ ]);
108
+ /**
109
+ * sot_kind = where the canonical prose lives for this DEC.
110
+ * "ledger" — body in this DEC file is canonical (source-comment essay,
111
+ * operator-recorded). Lens renders body verbatim.
112
+ * "path" — sot_path points at the canonical location (doc paragraph,
113
+ * CLAUDE.md section). Lens renders live content from there.
114
+ */
115
+ export const SotKind = z.enum(["ledger", "path"]);
116
+ export const DecisionFrontmatter = z
117
+ .object({
118
+ id: z.string().regex(/^DEC-[0-9a-f]{7,}$/, "decision id must match DEC-<hash7>"),
119
+ title: z.string(),
120
+ type: z.literal("adr").optional(),
121
+ status: z
122
+ .string()
123
+ .refine((s) => s === "accepted" ||
124
+ s === "superseded" ||
125
+ s === "archived" ||
126
+ /^draft(?:-from-[a-z-]+)?$/.test(s), "decision status must be draft | draft-from-<source> | accepted | superseded | archived"),
127
+ audience: Audience.optional(),
128
+ generated: z.string().optional(),
129
+ "verified-at": z.string().optional(),
130
+ "source-commits": z.array(z.string()).optional(),
131
+ decided_at: z.string().optional(),
132
+ decided_by: z.string().optional(),
133
+ scope_globs: z.array(z.string()).optional(),
134
+ supersedes: z.string().nullish(),
135
+ superseded_by: z.string().nullish(),
136
+ assertions: z.array(DecisionAssertion).optional(),
137
+ human_review_hint: z.string().optional(),
138
+ related_invariants: z.array(z.string()).optional(),
139
+ sot_kind: SotKind,
140
+ sot_path: z.string().min(1),
141
+ sot_content_hash: z.string().length(64),
142
+ related: z.string().nullish(),
143
+ derived_from: z.string().nullish(),
144
+ })
145
+ .passthrough();
146
+ export const InvariantFrontmatter = z
147
+ .object({
148
+ id: z.string().regex(/^INV-[0-9a-f]{7,}$/, "invariant id must match INV-<hash7>"),
149
+ title: z.string(),
150
+ type: z.literal("invariant").optional(),
151
+ status: z.enum(["active", "superseded", "archived"]).optional(),
152
+ audience: Audience.optional(),
153
+ generated: z.string().optional(),
154
+ "verified-at": z.string().optional(),
155
+ source_run: z.string().optional(),
156
+ source_decision: z.string().nullish(),
157
+ introduced_for_bug: z.string().optional(),
158
+ sensor: z.string().optional(),
159
+ e2e: z.string().optional(),
160
+ naming_convention: z.string().optional(),
161
+ superseded_by: z.string().nullish(),
162
+ sot_kind: SotKind,
163
+ sot_path: z.string().min(1),
164
+ sot_content_hash: z.string().length(64),
165
+ related: z.string().nullish(),
166
+ derived_from: z.string().nullish(),
167
+ })
168
+ .passthrough();
169
+ export const DecisionLedgerEntry = z.object({
170
+ id: z.string(),
171
+ title: z.string(),
172
+ status: z.string(),
173
+ scope_globs: z.array(z.string()).optional(),
174
+ supersedes: z.string().nullish(),
175
+ superseded_by: z.string().nullish(),
176
+ });
177
+ export const InvariantLedgerEntry = z.object({
178
+ id: z.string(),
179
+ title: z.string(),
180
+ status: z.string(),
181
+ source_decision: z.string().nullish(),
182
+ superseded_by: z.string().nullish(),
183
+ });
184
+ export const QualityGrade = z.object({
185
+ module: z.string(),
186
+ score: z.number().min(0).max(100),
187
+ pass_rate: z.number().min(0).max(1),
188
+ drift_count: z.number().int().nonnegative(),
189
+ last_updated: z.string(),
190
+ recent_run_count: z.number().int().nonnegative(),
191
+ });
192
+ export const QualityGrades = z.object({
193
+ version: z.literal(1),
194
+ generated: z.string(),
195
+ modules: z.array(QualityGrade),
196
+ });
197
+ /**
198
+ * Topic-index entry — one row per content-fingerprint slug across all
199
+ * scanned sources. `sot_source` is the canonical source path picked by
200
+ * priority order (docs/* > CLAUDE.md > AGENTS.md > source comments).
201
+ * `candidates` lists every place the same prose appears (one becomes the
202
+ * SoT, the rest become §DEC-<id> cites).
203
+ *
204
+ * `marker_kind` is stamped at walk-time when the SoT block sits under a
205
+ * `cairn:` frontmatter key (file-level) or has a `<!-- cairn:decision -->`
206
+ * / `<!-- cairn:rule -->` HTML comment within 3 lines of its heading
207
+ * (block-level). Phase 6 Stage 3 reads this field directly off the
208
+ * topic-index and bypasses Stages 1+2 (file-purpose + section batch
209
+ * classifiers) for marked entries — the operator has already declared
210
+ * the block authoritative, so Haiku adds no signal.
211
+ *
212
+ * `content_hash` mirrors the SoT block's body hash at walk-time. Used by
213
+ * `cairn_propose_decision` (PR 2) and the alignment hooks to detect
214
+ * source drift before promoting a candidate to a draft.
215
+ */
216
+ export const TopicIndexEntry = z.object({
217
+ slug: z.string(),
218
+ dec_id: z.string().optional(),
219
+ sot_source: z.string(),
220
+ candidates: z.array(z.object({
221
+ file: z.string(),
222
+ kind: z.enum(["doc", "claudemd", "agentsmd", "rule", "source-comment"]),
223
+ anchor: z.string().optional(),
224
+ line_range: z.tuple([z.number().int(), z.number().int()]).optional(),
225
+ })),
226
+ created_at: z.string(),
227
+ marker_kind: z.enum(["decision", "rule"]).optional(),
228
+ content_hash: z.string().length(64).optional(),
229
+ });
230
+ export const TopicIndex = z.object({
231
+ version: z.literal(1),
232
+ generated: z.string(),
233
+ topics: z.record(z.string(), TopicIndexEntry),
234
+ });
235
+ /**
236
+ * SoT bindings — bidirectional map between DEC ids and their canonical
237
+ * source paths. Forward index is one-to-one. Reverse index is one-to-many
238
+ * because supersedes chains keep the same sot_path across multiple DEC
239
+ * ids.
240
+ */
241
+ export const SotBindings = z.object({
242
+ version: z.literal(1),
243
+ generated: z.string(),
244
+ forward: z.record(z.string(), z.string()),
245
+ reverse: z.record(z.string(), z.array(z.string())),
246
+ });
247
+ /**
248
+ * Sot-cache — tokenized DEC body shingles for Jaccard pre-filter in the
249
+ * Layer A alignment hook. Mtime-keyed so the cache rebuilds incrementally
250
+ * on PostToolUse Write events.
251
+ */
252
+ export const SotCacheEntry = z.object({
253
+ dec_id: z.string(),
254
+ sot_path: z.string(),
255
+ body_hash: z.string().length(64),
256
+ tokens: z.array(z.string()),
257
+ shingles: z.array(z.string()),
258
+ mtime_ms: z.number(),
259
+ });
260
+ export const SotCache = z.object({
261
+ version: z.literal(1),
262
+ generated: z.string(),
263
+ entries: z.record(z.string(), SotCacheEntry),
264
+ });
265
+ /**
266
+ * Anchor-map — external map from topic slug to its current location in
267
+ * source. Allows operator's docs to stay pristine (no `<!-- cairn-anchor -->`
268
+ * injected) while drift detection reconciles via content_hash.
269
+ */
270
+ export const AnchorMapEntry = z.object({
271
+ file: z.string(),
272
+ current_anchor: z.string().optional(),
273
+ content_hash: z.string().length(64),
274
+ line_range: z.tuple([z.number().int(), z.number().int()]).optional(),
275
+ kind: z.enum(["doc", "claudemd", "agentsmd", "rule", "source-comment"]),
276
+ });
277
+ export const AnchorMap = z.object({
278
+ version: z.literal(1),
279
+ generated: z.string(),
280
+ anchors: z.record(z.string(), AnchorMapEntry),
281
+ });
282
+ export const DriftEvent = z.object({
283
+ ts: z.string(),
284
+ kind: z.enum([
285
+ "frontmatter_stale",
286
+ "generator_drift",
287
+ "broken_link",
288
+ "orphan_path",
289
+ "orphan_entity",
290
+ "manifest_hash_changed",
291
+ "doc-drift",
292
+ "paragraph-deleted",
293
+ "pre-commit-drift",
294
+ ]),
295
+ path: z.string(),
296
+ detail: z.string().optional(),
297
+ severity: z.enum(["soft", "hard"]).default("soft"),
298
+ dec_id: z.string().optional(),
299
+ });
300
+ /**
301
+ * Layer B pre-commit-drift log entry written by the git pre-commit
302
+ * hook (`cairn hook pre-commit-align`). SessionStart Drain SessionStart drain
303
+ * consumes this file, re-checks each entry against the (possibly
304
+ * changed) source location, and runs the Haiku judge for ambiguous
305
+ * candidates.
306
+ *
307
+ * Path: `.cairn/staleness/pre-commit-deferred.jsonl`.
308
+ *
309
+ * `tier: tier1` — deterministic match passed (Jaccard ≥ 0.85, shingle
310
+ * ≥ 0.6, length ratio 0.5–2.0). SessionStart Drain can auto-cite without Haiku
311
+ * if the block survives.
312
+ *
313
+ * `tier: tier2-3` — Jaccard pre-filter survivors only; Tier 1 didn't
314
+ * fire. SessionStart Drain invokes Haiku dedup judge.
315
+ */
316
+ export const PreCommitDriftCandidate = z.object({
317
+ id: z.string(),
318
+ similarity: z.number(),
319
+ body_hash: z.string(),
320
+ sot_path: z.string(),
321
+ });
322
+ export const PreCommitDriftLogEntry = z.object({
323
+ ts: z.string(),
324
+ file: z.string(),
325
+ block_start_line: z.number(),
326
+ block_end_line: z.number(),
327
+ block_content_hash: z.string(),
328
+ block_prose: z.string(),
329
+ tier: z.enum(["tier1", "tier2-3"]),
330
+ candidates: z.array(PreCommitDriftCandidate),
331
+ });
332
+ /**
333
+ * Rejected-candidate ledger entry (`.cairn/ground/_rejected.yaml`).
334
+ *
335
+ * Records topic-index slugs the operator (or `ai-curator`) decided are
336
+ * *not* canonical — false positives, research notes, planning prose,
337
+ * etc. The drift sensor reads this file and suppresses any candidate
338
+ * whose slug appears here; phase 6 / `cairn ingest` skip rejected slugs
339
+ * on the next pass instead of re-proposing them.
340
+ *
341
+ * Dedup is by slug. First writer wins the `reason` string; subsequent
342
+ * writes only refresh `rejected_at`. Phase 5b GC drops entries whose
343
+ * slug is no longer present in the freshly-built topic-index.
344
+ */
345
+ export const RejectedEntry = z.object({
346
+ slug: z.string(),
347
+ rejected_at: z.string(),
348
+ rejected_by: z.enum(["operator", "ai-curator", "cairn-init"]),
349
+ reason: z.string(),
350
+ sot_source: z.string(),
351
+ line_range: z.tuple([z.number().int(), z.number().int()]).optional(),
352
+ });
353
+ export const RejectedYaml = z.object({
354
+ version: z.literal(1),
355
+ generated: z.string(),
356
+ rejected: z.array(RejectedEntry),
357
+ });
358
+ /**
359
+ * `.cairn/ground/file-candidates-map.yaml` — per-file count of
360
+ * topic-index entries with `dec_id IS NULL`. Built at the end of phase
361
+ * 5b (and refreshed whenever `dec_id` is stamped — phase 6, the PR 2
362
+ * `cairn_propose_decision` tool, etc.). The read-enrich hook consults
363
+ * this map to inject a candidate-count warning when an AI agent reads a
364
+ * file with unpromoted candidates, without scanning the whole topic
365
+ * index per Read.
366
+ */
367
+ export const FileCandidatesMap = z.object({
368
+ version: z.literal(1),
369
+ generated: z.string(),
370
+ file_candidates: z.record(z.string(), z.number().int().nonnegative()),
371
+ });
372
+ /* -------------------------------------------------------------------------- */
373
+ /* Mission system — supra-task layer */
374
+ /* -------------------------------------------------------------------------- */
375
+ /**
376
+ * Per-mission default exit gate, with optional per-phase override in
377
+ * roadmap.md frontmatter.
378
+ * - `prompt` — Stop hook surfaces inline AskUserQuestion on phase complete.
379
+ * - `auto` — cursor advances silently when last phase task graduates.
380
+ * - `manual` — operator advances explicitly via cairn_mission_advance.
381
+ */
382
+ export const MissionExitGate = z.enum(["prompt", "auto", "manual"]);
383
+ export const MissionPhase = z.object({
384
+ id: z
385
+ .string()
386
+ .min(1)
387
+ .regex(/^[a-z0-9][a-z0-9-]*$/, "phase id must be kebab-case ([a-z0-9-]+)"),
388
+ title: z.string().min(1),
389
+ depends_on: z.array(z.string()).default([]),
390
+ exit_criteria: z.string().min(1),
391
+ exit_gate: MissionExitGate.optional(),
392
+ });
393
+ /**
394
+ * Roadmap frontmatter — `.cairn/ground/missions/<id>/roadmap.md`. Lives
395
+ * in committed ground state; multi-dev visible. Phase YAML is canonical;
396
+ * any prose body is operator notes ignored by Cairn parsing.
397
+ */
398
+ export const MissionRoadmapFrontmatter = z
399
+ .object({
400
+ mission_id: z.string().regex(/^MIS-[a-z0-9-]+-[0-9a-f]{7}$/, "mission id must match MIS-<slug>-<hash7>"),
401
+ title: z.string().min(1),
402
+ spec_path: z.string().min(1),
403
+ created_at: z.string(),
404
+ exit_gate: MissionExitGate,
405
+ phases: z.array(MissionPhase).min(1),
406
+ })
407
+ .passthrough();
408
+ export const MissionPhaseState = z.enum(["pending", "in_progress", "done"]);
409
+ export const MissionPhaseProgressEntry = z.object({
410
+ state: MissionPhaseState,
411
+ task_ids: z.array(z.string()).default([]),
412
+ graduated_at: z.string().optional(),
413
+ /**
414
+ * True once a `phase-ready-to-exit` invalidation event has been
415
+ * emitted for this phase. Suppresses re-emission on subsequent task
416
+ * completions within the same phase (prevents the prompt storm where
417
+ * every late task completion re-fires the operator-facing
418
+ * "phase ready to exit" surface). Cleared when the cursor advances
419
+ * past the phase or the phase is reopened.
420
+ */
421
+ ready_emitted: z.boolean().optional(),
422
+ /**
423
+ * Per-phase tightening state. Unset while the phase still needs a
424
+ * just-in-time brief; `drafted` once `cairn_mission_plan_phase` has
425
+ * written a brief the operator hasn't confirmed; `accepted` once the
426
+ * brief is locked and tasks may inherit it. The cursor landing on a
427
+ * phase with `brief_status` unset is the "brief-pending" signal the
428
+ * direction skill reads before creating phase-anchored tasks.
429
+ */
430
+ brief_status: z.enum(["drafted", "accepted"]).optional(),
431
+ });
432
+ /**
433
+ * One resolved fork captured during per-phase tightening — the question
434
+ * the brief closed plus the operator's (or, in autonomous mode, the
435
+ * model's) choice. Mirrors a lightweight DEC without graduating to the
436
+ * decision graph; phase-scoped and archived with the mission.
437
+ */
438
+ export const MissionPhaseBriefDecision = z.object({
439
+ question: z.string().min(1),
440
+ choice: z.string().min(1),
441
+ rationale: z.string().optional(),
442
+ });
443
+ /**
444
+ * Per-phase brief — `.cairn/ground/missions/<id>/briefs/<phase-id>.md`.
445
+ * The just-in-time tightening artifact for a single phase: the forks the
446
+ * operator resolved, the constraints tasks in this phase must honour,
447
+ * the phase acceptance bar, and the in-scope ground-state cites that
448
+ * pre-answered the rest. Committed alongside the roadmap (multi-dev
449
+ * visible). Frontmatter is canonical; prose body is operator notes.
450
+ */
451
+ export const MissionPhaseBrief = z
452
+ .object({
453
+ phase_id: z.string().min(1),
454
+ drafted_at: z.string(),
455
+ status: z.enum(["drafted", "accepted"]).default("drafted"),
456
+ autonomous: z.boolean().optional(),
457
+ decisions: z.array(MissionPhaseBriefDecision).default([]),
458
+ constraints: z.array(z.string()).default([]),
459
+ acceptance: z.array(z.string()).default([]),
460
+ cite_decisions: z.array(z.string()).default([]),
461
+ cite_invariants: z.array(z.string()).default([]),
462
+ })
463
+ .passthrough();
464
+ export const MissionCursor = z.object({
465
+ active_phase: z.string().nullable(),
466
+ active_phase_started_at: z.string().nullable(),
467
+ });
468
+ export const MissionOutcome = z.enum(["active", "done", "aborted"]);
469
+ /**
470
+ * Per-clone mission state — `.cairn/missions/<id>/state.json`.
471
+ * Tracks the cursor + phase progress. Never committed (gitignored under
472
+ * `.cairn/missions/`).
473
+ */
474
+ export const MissionState = z.object({
475
+ mission_id: z.string(),
476
+ started_at: z.string(),
477
+ cursor: MissionCursor,
478
+ phase_progress: z.record(z.string(), MissionPhaseProgressEntry),
479
+ outcome: MissionOutcome.default("active"),
480
+ closed_at: z.string().optional(),
481
+ abort_reason: z.string().optional(),
482
+ });
483
+ /**
484
+ * Mission journal entry — `.cairn/missions/<id>/journal.jsonl`. One
485
+ * record per mission-level event (start, advance, resync, close).
486
+ */
487
+ export const MissionJournalEntry = z.object({
488
+ ts: z.string(),
489
+ kind: z.enum([
490
+ "started",
491
+ "phase-advanced",
492
+ "phase-deferred",
493
+ "phase-brief-set",
494
+ "task-attached",
495
+ "resync-pending",
496
+ "resync-applied",
497
+ "drift-detected",
498
+ "closed",
499
+ "reopened",
500
+ "exit-gate-changed",
501
+ ]),
502
+ phase_id: z.string().optional(),
503
+ task_id: z.string().optional(),
504
+ detail: z.string().optional(),
505
+ });
506
+ //# sourceMappingURL=schemas.js.map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c,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAGpE;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,MAAM,EAAE,aAAa;IACrB,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,yBAAyB,CAAC;IAC/D,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC;IACzC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACpC,CAAC,CAAC;AAGH;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;QACX,SAAS;QACT,gBAAgB;QAChB,gBAAgB;QAChB,iBAAiB;QACjB,eAAe;QACf,gBAAgB;QAChB,gBAAgB;QAChB,gBAAgB;QAChB,QAAQ;QACR,UAAU;QACV,mBAAmB;KACpB,CAAC;IACF,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Scope index — forward map from every file path in the repo to the decisions
3
+ * and invariants that apply to that file.
4
+ *
5
+ * Built at init by the Tier-2 mapper LLM, maintained by the GC sweep + the
6
+ * MCP record-decision tool when scope edits land. Read by the read-enricher
7
+ * / write-guardian hooks (via cached accessor in
8
+ * `hooks/post-tool-use/ledger-cache.ts`) and by the GC scope-coverage pass.
9
+ *
10
+ * Spec: docs/FILESYSTEM_LAYOUT.md §2.1.
11
+ */
12
+ export interface ScopeIndexEntry {
13
+ decisions: string[];
14
+ invariants: string[];
15
+ unscoped?: true;
16
+ }
17
+ /**
18
+ * Mapper LLMs occasionally emit ledger-entry PROSE ("HTTP layer is the only
19
+ * public surface…") into `decisions[]` / `invariants[]` instead of bare IDs,
20
+ * because the user prompt lists them as `${id} — ${title}` and the JSON-mode
21
+ * schema only constrains the type to `string`. This coercer extracts the
22
+ * first ID-shaped token from each string and silently drops anything that
23
+ * doesn't match — IDs only, deduplicated, order preserved.
24
+ */
25
+ export declare function coerceDecisionIds(raw: readonly unknown[]): string[];
26
+ export declare function coerceInvariantIds(raw: readonly unknown[]): string[];
27
+ export interface ScopeIndex {
28
+ generated: string;
29
+ files: Record<string, ScopeIndexEntry>;
30
+ }
31
+ export declare function scopeIndexPath(repoRoot: string): string;
32
+ export declare function readScopeIndex(repoRoot: string): ScopeIndex | null;
33
+ export declare function lookupScope(index: ScopeIndex, repoRelativePath: string): ScopeIndexEntry | null;
34
+ export declare function writeScopeIndex(repoRoot: string, index: ScopeIndex): void;
35
+ export interface RescanScopeIndexResult {
36
+ filesScanned: number;
37
+ entriesAdded: number;
38
+ entriesUpdated: number;
39
+ entriesUnchanged: number;
40
+ /** True when scope-index.yaml was rewritten. */
41
+ dirty: boolean;
42
+ }
43
+ /**
44
+ * Deterministic regex sweep — walk every git-tracked source file, parse
45
+ * `§INV-<hash>` / `§DEC-<hash>` cite tokens, and sync the scope-index so the
46
+ * in-scope tools never lag behind source-cite reality. No LLM, no
47
+ * incremental tracking complexity. Cheap enough to run on every
48
+ * SessionStart (~100ms on 50k files).
49
+ *
50
+ * Honors `unscoped: true` entries — never touches them. Skips files with
51
+ * no citations and no prior entry to avoid polluting the index. When a
52
+ * file's cite set differs from its scope-index entry (added, removed, or
53
+ * stale ids), the entry is rewritten with the deterministically-sorted
54
+ * current set.
55
+ */
56
+ export declare function rescanScopeIndex(repoRoot: string): RescanScopeIndexResult;
57
+ /**
58
+ * Single-file scope-index sync from in-memory content. Called by the
59
+ * PostToolUse(Write/Edit) hook so an agent's writes don't leave the
60
+ * scope-index stale until the next SessionStart rescan. Same regex
61
+ * parser as `rescanScopeIndex`, but bounded to one file — O(1) cost,
62
+ * no walker.
63
+ *
64
+ * Honors `unscoped: true` entries (skips them). Honors the same skip
65
+ * rule the rescan does: file with no citations and no prior entry is
66
+ * a no-op so we don't pollute the index with empty rows.
67
+ */
68
+ export declare function syncFileScopeFromContent(repoRoot: string, repoRelPath: string, content: string): {
69
+ dirty: boolean;
70
+ };
71
+ export interface RebuildScopeIndexOptions {
72
+ repoRoot: string;
73
+ /** Hard timeout for the mapper LLM call (ms). Default 300000. */
74
+ timeoutMs?: number;
75
+ }
76
+ export interface RebuildScopeIndexResult {
77
+ /** Absolute path to the file written. */
78
+ path: string;
79
+ /** Total scope-index entries after the rescan (added + updated + unchanged). */
80
+ filesClassified: number;
81
+ /** Wall-clock ms for the rescan. */
82
+ durationMs: number;
83
+ }
84
+ /**
85
+ * `cairn scope rebuild` — full deterministic resync of `.cairn/ground/
86
+ * scope-index.yaml` from current source-cite reality. Used to be a
87
+ * Sonnet call (`runMapper`-style) that re-classified files via the
88
+ * Tier-2 mapper, but classification was always the wrong abstraction
89
+ * — bare-symbol citations in source are the canonical source of truth,
90
+ * `rescanScopeIndex` parses them deterministically, and the result
91
+ * matches what the read-enricher legend actually shows.
92
+ *
93
+ * No LLM. No tokens. No mapper. Just a regex sweep over git-tracked
94
+ * source files and an atomic write.
95
+ */
96
+ export declare function rebuildScopeIndex(opts: RebuildScopeIndexOptions): Promise<RebuildScopeIndexResult>;