@isaacriehm/cairn-core 0.4.2 → 0.5.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 (211) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/align-undo/index.d.ts +6 -0
  3. package/dist/align-undo/index.js +6 -0
  4. package/dist/align-undo/index.js.map +1 -0
  5. package/dist/align-undo/log.d.ts +53 -0
  6. package/dist/align-undo/log.js +99 -0
  7. package/dist/align-undo/log.js.map +1 -0
  8. package/dist/align-undo/undo.d.ts +66 -0
  9. package/dist/align-undo/undo.js +187 -0
  10. package/dist/align-undo/undo.js.map +1 -0
  11. package/dist/attention/bulk-accept.js +1 -1
  12. package/dist/attention/bulk-accept.js.map +1 -1
  13. package/dist/attention/dedup.d.ts +2 -2
  14. package/dist/attention/dedup.js +16 -51
  15. package/dist/attention/dedup.js.map +1 -1
  16. package/dist/attention/index.d.ts +1 -0
  17. package/dist/attention/index.js +1 -0
  18. package/dist/attention/index.js.map +1 -1
  19. package/dist/attention/restore.js +1 -1
  20. package/dist/attention/restore.js.map +1 -1
  21. package/dist/attention/serve/api.d.ts +23 -0
  22. package/dist/attention/serve/api.js +344 -0
  23. package/dist/attention/serve/api.js.map +1 -0
  24. package/dist/attention/serve/index.d.ts +62 -0
  25. package/dist/attention/serve/index.js +205 -0
  26. package/dist/attention/serve/index.js.map +1 -0
  27. package/dist/decision-capture/id.d.ts +62 -25
  28. package/dist/decision-capture/id.js +78 -57
  29. package/dist/decision-capture/id.js.map +1 -1
  30. package/dist/decision-capture/index.d.ts +3 -3
  31. package/dist/decision-capture/index.js +3 -3
  32. package/dist/decision-capture/index.js.map +1 -1
  33. package/dist/drain/drain.d.ts +77 -0
  34. package/dist/drain/drain.js +464 -0
  35. package/dist/drain/drain.js.map +1 -0
  36. package/dist/drain/index.d.ts +5 -0
  37. package/dist/drain/index.js +5 -0
  38. package/dist/drain/index.js.map +1 -0
  39. package/dist/fix-align/index.d.ts +5 -0
  40. package/dist/fix-align/index.js +5 -0
  41. package/dist/fix-align/index.js.map +1 -0
  42. package/dist/fix-align/run.d.ts +99 -0
  43. package/dist/fix-align/run.js +258 -0
  44. package/dist/fix-align/run.js.map +1 -0
  45. package/dist/ground/alignment-pending.d.ts +28 -0
  46. package/dist/ground/alignment-pending.js +83 -0
  47. package/dist/ground/alignment-pending.js.map +1 -0
  48. package/dist/ground/anchor-map.d.ts +14 -0
  49. package/dist/ground/anchor-map.js +57 -0
  50. package/dist/ground/anchor-map.js.map +1 -0
  51. package/dist/ground/index.d.ts +9 -2
  52. package/dist/ground/index.js +8 -2
  53. package/dist/ground/index.js.map +1 -1
  54. package/dist/ground/paths.d.ts +21 -0
  55. package/dist/ground/paths.js +43 -0
  56. package/dist/ground/paths.js.map +1 -1
  57. package/dist/ground/schemas.d.ts +201 -0
  58. package/dist/ground/schemas.js +128 -3
  59. package/dist/ground/schemas.js.map +1 -1
  60. package/dist/ground/scope-index.js +2 -2
  61. package/dist/ground/scope-index.js.map +1 -1
  62. package/dist/ground/slug.d.ts +60 -0
  63. package/dist/ground/slug.js +103 -0
  64. package/dist/ground/slug.js.map +1 -0
  65. package/dist/ground/sot-bindings.d.ts +14 -0
  66. package/dist/ground/sot-bindings.js +80 -0
  67. package/dist/ground/sot-bindings.js.map +1 -0
  68. package/dist/ground/sot-cache.d.ts +18 -0
  69. package/dist/ground/sot-cache.js +63 -0
  70. package/dist/ground/sot-cache.js.map +1 -0
  71. package/dist/ground/topic-index.d.ts +20 -0
  72. package/dist/ground/topic-index.js +60 -0
  73. package/dist/ground/topic-index.js.map +1 -0
  74. package/dist/hooks/post-tool-use/citation-scanner.d.ts +1 -1
  75. package/dist/hooks/post-tool-use/citation-scanner.js +3 -3
  76. package/dist/hooks/post-tool-use/citation-scanner.js.map +1 -1
  77. package/dist/hooks/post-tool-use/copy-scanner.js +1 -1
  78. package/dist/hooks/post-tool-use/copy-scanner.js.map +1 -1
  79. package/dist/hooks/post-tool-use/index.d.ts +2 -0
  80. package/dist/hooks/post-tool-use/index.js +1 -0
  81. package/dist/hooks/post-tool-use/index.js.map +1 -1
  82. package/dist/hooks/post-tool-use/legend-builder.d.ts +1 -1
  83. package/dist/hooks/post-tool-use/legend-builder.js +2 -2
  84. package/dist/hooks/post-tool-use/legend-builder.js.map +1 -1
  85. package/dist/hooks/post-tool-use/sot-align.d.ts +166 -0
  86. package/dist/hooks/post-tool-use/sot-align.js +1311 -0
  87. package/dist/hooks/post-tool-use/sot-align.js.map +1 -0
  88. package/dist/hooks/pre-commit/index.d.ts +8 -0
  89. package/dist/hooks/pre-commit/index.js +8 -0
  90. package/dist/hooks/pre-commit/index.js.map +1 -0
  91. package/dist/hooks/pre-commit/sot-align-precommit.d.ts +60 -0
  92. package/dist/hooks/pre-commit/sot-align-precommit.js +221 -0
  93. package/dist/hooks/pre-commit/sot-align-precommit.js.map +1 -0
  94. package/dist/hooks/runners/session-start.js +41 -0
  95. package/dist/hooks/runners/session-start.js.map +1 -1
  96. package/dist/hooks/sot-align-common.d.ts +39 -0
  97. package/dist/hooks/sot-align-common.js +152 -0
  98. package/dist/hooks/sot-align-common.js.map +1 -0
  99. package/dist/index.d.ts +5 -0
  100. package/dist/index.js +5 -0
  101. package/dist/index.js.map +1 -1
  102. package/dist/init/index.d.ts +4 -2
  103. package/dist/init/index.js +2 -1
  104. package/dist/init/index.js.map +1 -1
  105. package/dist/init/ingest-docs.d.ts +30 -47
  106. package/dist/init/ingest-docs.js +113 -406
  107. package/dist/init/ingest-docs.js.map +1 -1
  108. package/dist/init/init.d.ts +8 -0
  109. package/dist/init/init.js +58 -29
  110. package/dist/init/init.js.map +1 -1
  111. package/dist/init/mapper-parallel.js +1 -1
  112. package/dist/init/mapper-parallel.js.map +1 -1
  113. package/dist/init/phases/5-brand.js +1 -1
  114. package/dist/init/phases/5-brand.js.map +1 -1
  115. package/dist/init/phases/5b-topic-index.d.ts +30 -0
  116. package/dist/init/phases/5b-topic-index.js +62 -0
  117. package/dist/init/phases/5b-topic-index.js.map +1 -0
  118. package/dist/init/phases/6-docs-ingest.d.ts +4 -5
  119. package/dist/init/phases/6-docs-ingest.js +5 -6
  120. package/dist/init/phases/6-docs-ingest.js.map +1 -1
  121. package/dist/init/phases/index.d.ts +2 -0
  122. package/dist/init/phases/index.js +1 -0
  123. package/dist/init/phases/index.js.map +1 -1
  124. package/dist/init/phases/parallel-678.d.ts +14 -17
  125. package/dist/init/phases/parallel-678.js +77 -98
  126. package/dist/init/phases/parallel-678.js.map +1 -1
  127. package/dist/init/phases/source-comments-output-io.d.ts +16 -10
  128. package/dist/init/phases/source-comments-output-io.js +7 -10
  129. package/dist/init/phases/source-comments-output-io.js.map +1 -1
  130. package/dist/init/phases/types.d.ts +1 -1
  131. package/dist/init/phases/types.js +1 -0
  132. package/dist/init/phases/types.js.map +1 -1
  133. package/dist/init/rules-merge/discover.d.ts +8 -3
  134. package/dist/init/rules-merge/discover.js +7 -3
  135. package/dist/init/rules-merge/discover.js.map +1 -1
  136. package/dist/init/rules-merge/ingest.d.ts +81 -28
  137. package/dist/init/rules-merge/ingest.js +456 -155
  138. package/dist/init/rules-merge/ingest.js.map +1 -1
  139. package/dist/init/sot-emit.d.ts +84 -0
  140. package/dist/init/sot-emit.js +218 -0
  141. package/dist/init/sot-emit.js.map +1 -0
  142. package/dist/init/source-comments/classify.d.ts +12 -10
  143. package/dist/init/source-comments/classify.js +13 -25
  144. package/dist/init/source-comments/classify.js.map +1 -1
  145. package/dist/init/source-comments/index.d.ts +1 -1
  146. package/dist/init/source-comments/index.js +1 -1
  147. package/dist/init/source-comments/index.js.map +1 -1
  148. package/dist/init/source-comments/ingest.d.ts +91 -67
  149. package/dist/init/source-comments/ingest.js +392 -349
  150. package/dist/init/source-comments/ingest.js.map +1 -1
  151. package/dist/init/topic-index/index.d.ts +36 -0
  152. package/dist/init/topic-index/index.js +46 -0
  153. package/dist/init/topic-index/index.js.map +1 -0
  154. package/dist/init/topic-index/judge.d.ts +20 -0
  155. package/dist/init/topic-index/judge.js +65 -0
  156. package/dist/init/topic-index/judge.js.map +1 -0
  157. package/dist/init/topic-index/resolve.d.ts +50 -0
  158. package/dist/init/topic-index/resolve.js +196 -0
  159. package/dist/init/topic-index/resolve.js.map +1 -0
  160. package/dist/init/topic-index/walk.d.ts +43 -0
  161. package/dist/init/topic-index/walk.js +293 -0
  162. package/dist/init/topic-index/walk.js.map +1 -0
  163. package/dist/mcp/history/summarizer.js +1 -1
  164. package/dist/mcp/history/summarizer.js.map +1 -1
  165. package/dist/mcp/schemas.d.ts +46 -9
  166. package/dist/mcp/schemas.js +48 -12
  167. package/dist/mcp/schemas.js.map +1 -1
  168. package/dist/mcp/tools/align-drain.d.ts +7 -0
  169. package/dist/mcp/tools/align-drain.js +26 -0
  170. package/dist/mcp/tools/align-drain.js.map +1 -0
  171. package/dist/mcp/tools/archive.js +1 -1
  172. package/dist/mcp/tools/archive.js.map +1 -1
  173. package/dist/mcp/tools/attention-restore.js +1 -1
  174. package/dist/mcp/tools/attention-restore.js.map +1 -1
  175. package/dist/mcp/tools/attention-serve.d.ts +23 -0
  176. package/dist/mcp/tools/attention-serve.js +78 -0
  177. package/dist/mcp/tools/attention-serve.js.map +1 -0
  178. package/dist/mcp/tools/attention-wait.d.ts +18 -0
  179. package/dist/mcp/tools/attention-wait.js +74 -0
  180. package/dist/mcp/tools/attention-wait.js.map +1 -0
  181. package/dist/mcp/tools/index.js +7 -0
  182. package/dist/mcp/tools/index.js.map +1 -1
  183. package/dist/mcp/tools/init-phases.js +4 -1
  184. package/dist/mcp/tools/init-phases.js.map +1 -1
  185. package/dist/mcp/tools/record-decision.js +14 -2
  186. package/dist/mcp/tools/record-decision.js.map +1 -1
  187. package/dist/mcp/tools/resolve-attention.d.ts +2 -2
  188. package/dist/mcp/tools/resolve-attention.js +830 -7
  189. package/dist/mcp/tools/resolve-attention.js.map +1 -1
  190. package/dist/status-line/event-queue.d.ts +40 -0
  191. package/dist/status-line/event-queue.js +195 -0
  192. package/dist/status-line/event-queue.js.map +1 -0
  193. package/dist/status-line/format.d.ts +1 -1
  194. package/dist/status-line/format.js +49 -6
  195. package/dist/status-line/format.js.map +1 -1
  196. package/dist/status-line/index.d.ts +41 -0
  197. package/dist/status-line/index.js +14 -0
  198. package/dist/status-line/index.js.map +1 -1
  199. package/dist/status-line/reader.js +23 -18
  200. package/dist/status-line/reader.js.map +1 -1
  201. package/dist/status-line/writer.d.ts +1 -1
  202. package/dist/status-line/writer.js +5 -0
  203. package/dist/status-line/writer.js.map +1 -1
  204. package/dist/text/jaccard.d.ts +19 -0
  205. package/dist/text/jaccard.js +68 -0
  206. package/dist/text/jaccard.js.map +1 -0
  207. package/package.json +1 -1
  208. package/templates/.cairn/git-hooks/pre-commit +16 -3
  209. package/templates/attention-ui/app.css +406 -0
  210. package/templates/attention-ui/app.js +384 -0
  211. package/templates/attention-ui/index.html +56 -0
@@ -1,20 +1,40 @@
1
1
  /**
2
- * Phase 7b orchestrator — walker → classifier → persist.
2
+ * Phase 7b orchestrator (v0.5.0 SoT model) — walker → classifier →
3
+ * topic-index lookup → emit-or-cite → strip-replace.
3
4
  *
4
- * Output:
5
- * - DEC drafts (one per "rationale" classification with non-empty title)
6
- * written to `.cairn/ground/decisions/_inbox/<id>.draft.md`
7
- * - Invariant files (one per "constraint" classification with non-empty
8
- * suggestedInvariant) written directly to
9
- * `.cairn/ground/invariants/INV-<NNNN>.md` with `status: active`. Auto-
10
- * promote the operator can edit / supersede via cairn-attention or
11
- * direct edit. Invariants don't go through an `_inbox/` review queue
12
- * because the classifier emits hard rules, not policy decisions.
13
- * - Canonical-map citations appended to
14
- * `.cairn/baseline/canonical-citations-<ISO>.yaml`
15
- * - Full audit (every block + classification) at
16
- * `.cairn/baseline/source-comments-<ISO>.yaml` consumed by the
17
- * strip-replace stage so it doesn't have to re-walk.
5
+ * Plan §5.3 algorithm:
6
+ * 1. Walk source files for prose-bearing comments (existing logic).
7
+ * 2. Classify via Haiku, kind only — `rationale` / `constraint` /
8
+ * `citation` / `license` / `other`. No paraphrased title, no rewritten
9
+ * invariant body, no canonical-topic suggestion.
10
+ * 3. Build a content-fingerprint slug for every rationale + constraint
11
+ * block. Look it up in the existing topic-index:
12
+ * a. **Cite-existing** slug already owned by a docs/CLAUDE.md/
13
+ * AGENTS.md/rule entry that has been emitted. Strip-replace
14
+ * inserts `// §DEC-<existing>` (or `§INV-<existing>`) at the
15
+ * comment's offset. No new ground-state file is written.
16
+ * b. **Novel** slug not in the topic-index, or owned by an
17
+ * un-emitted entry. Add the block to the topic-index as a
18
+ * new source-comment SoT entry; emit a verbatim DEC/INV via
19
+ * `emitFromTopicIndex` with `sot_kind: "ledger"`. After emit,
20
+ * strip-replace inserts `§DEC-<new>` / `§INV-<new>`.
21
+ * 4. Auto-promote — every newly-emitted entity ships with
22
+ * `status: accepted` (no `_inbox/` draft queue). Plan §1's pivot:
23
+ * the inbox-as-blocker was the bug; verbatim bodies + auto-promote
24
+ * remove the manual review step.
25
+ * 5. License + citation + other classifications → no-op (no DEC, no
26
+ * strip-replace). License blocks stay verbatim in source.
27
+ *
28
+ * Output side-effects (all relative to repoRoot):
29
+ * - `.cairn/ground/decisions/<DEC-id>.md` (one per novel rationale)
30
+ * - `.cairn/ground/invariants/<INV-id>.md` (one per novel constraint)
31
+ * - `.cairn/ground/topic-index.yaml` (extended with source-comment SoT entries)
32
+ * - `.cairn/ground/anchor-map.yaml` (one anchor per novel slug)
33
+ * - `.cairn/ground/sot-bindings.yaml` (forward+reverse for new ids)
34
+ * - `.cairn/ground/sot-cache.yaml` (token cache for Layer A)
35
+ * - `.cairn/ground/scope-index.yaml` (file → ids that landed in source)
36
+ * - `.cairn/baseline/source-comments-<ISO>.yaml` (full audit — every block + verdict)
37
+ * - source files (stripped & cited per replacement)
18
38
  */
19
39
  import type { ProjectGlobs } from "../../sensors/types.js";
20
40
  import type { ClassifyArgs, CommentClassification, CommentClassKind } from "./classify.js";
@@ -32,77 +52,81 @@ export interface IngestSourceCommentsArgs {
32
52
  /** When set, override `Date.now()` for deterministic test outputs. */
33
53
  nowIso?: string;
34
54
  /**
35
- * Project globs from `.cairn/config.yaml` (or the mapper output). When
36
- * provided, every DEC draft + invariant gets `capture_confidence` scored
37
- * and stamped at write time so `cairn attention bulk-accept` becomes an
38
- * O(1) file move instead of re-scoring every draft on disk.
55
+ * Project globs from `.cairn/config.yaml`. Carried through for
56
+ * compatibility with the parallel-678 caller; phase 7b under v0.5.0
57
+ * doesn't gate behavior on these (every novel rationale/constraint
58
+ * auto-promotes without scoring).
39
59
  */
40
60
  globs?: ProjectGlobs;
41
- /** Pilot module path (workflow.md `pilot_module`) for scoring bias. */
61
+ /** Pilot module path (workflow.md `pilot_module`). Same compat note. */
42
62
  pilotModule?: string;
43
63
  /**
44
- * Caller-supplied DEC id Set, threaded by the parallel orchestrator
45
- * across phases 6 / 7b / 7c so concurrent allocations don't collide.
64
+ * Caller-supplied DEC id Set kept for symmetry with phases 6 / 7c.
65
+ * Plan §3.2.1 derives content-addressed ids; collisions across phases
66
+ * are vanishingly unlikely so the Set is informational.
46
67
  */
47
68
  existingDecIds?: Set<string>;
48
- /**
49
- * Caller-supplied INV id Set. Only 7b allocates invariant ids today,
50
- * but the optional arg matches the DEC pattern for symmetry and lets
51
- * future phases share the allocator.
52
- */
69
+ /** Caller-supplied INV id Set. Same compat note. */
53
70
  existingInvIds?: Set<string>;
54
71
  }
72
+ interface IngestEmittedRecord {
73
+ id: string;
74
+ path: string;
75
+ sourceFile: string;
76
+ slug: string;
77
+ status: "accepted";
78
+ }
79
+ interface IngestCiteRecord {
80
+ /** Pre-existing DEC/INV id the source comment was bound to. */
81
+ id: string;
82
+ /** Source file the cite landed in. */
83
+ sourceFile: string;
84
+ /** 1-indexed inclusive line range of the original source comment. */
85
+ lineRange: [number, number];
86
+ /** Slug that resolved the topic-index lookup. */
87
+ slug: string;
88
+ }
89
+ interface IngestSkipRecord {
90
+ blockId: string;
91
+ reason: string;
92
+ }
93
+ interface StripOutcomePersisted {
94
+ file: string;
95
+ applied: number;
96
+ skipped: {
97
+ blockId: string;
98
+ reason: string;
99
+ }[];
100
+ fileSkipReason: string | null;
101
+ }
55
102
  export interface IngestSourceCommentsResult {
56
103
  walk: WalkResult;
57
104
  classifications: CommentClassification[];
58
- decDraftsWritten: {
59
- id: string;
60
- path: string;
61
- sourceFile: string;
62
- }[];
63
- /**
64
- * INV-<NNNN>.md files written directly to `.cairn/ground/invariants/`
65
- * with `status: active`. The cairn-adopt summary surfaces the count.
66
- */
67
- invariantsWritten: {
68
- id: string;
69
- path: string;
70
- sourceFile: string;
71
- }[];
72
- /** Files where the source comment was successfully replaced with `// §INV-NNNN`. */
73
- invariantStripFilesModified: number;
74
- /** Number of strip items that landed (one per invariant comment). */
75
- invariantStripItemsApplied: number;
76
- /** Number of strip items that skipped (range-mismatch, dirty, missing, etc.). */
77
- invariantStripItemsSkipped: number;
78
- /** Per-file strip outcomes — debug surface for "wrote ground state but not source". */
79
- invariantStripOutcomes: {
80
- file: string;
81
- applied: number;
82
- skipped: {
83
- blockId: string;
84
- reason: string;
85
- }[];
86
- fileSkipReason: string | null;
87
- }[];
88
- /** Set when applyStripReplace threw — null on the happy path. */
89
- invariantStripError: string | null;
105
+ /** Verbatim DEC files written under `.cairn/ground/decisions/`. */
106
+ decsWritten: IngestEmittedRecord[];
107
+ /** Verbatim INV files written under `.cairn/ground/invariants/`. */
108
+ invsWritten: IngestEmittedRecord[];
90
109
  /**
91
- * Count of "constraint" classifications regardless of whether they
92
- * produced a non-empty suggestedInvariant. Always equals
93
- * invariantsWritten.length when no proposals had empty bodies.
110
+ * Source comments that resolved to an already-emitted DEC/INV via the
111
+ * topic-index lookup. Strip-replace still fires for these — the source
112
+ * file gets the existing `§DEC-<hash>` / `§INV-<hash>` token.
94
113
  */
95
- invariantProposalsAdded: number;
96
- canonicalCitationsAdded: number;
114
+ citesEmitted: IngestCiteRecord[];
115
+ /** Blocks the ingest stage skipped (license, citation, other, errors). */
116
+ skipped: IngestSkipRecord[];
117
+ stripFilesModified: number;
118
+ stripItemsApplied: number;
119
+ stripItemsSkipped: number;
120
+ stripOutcomes: StripOutcomePersisted[];
121
+ stripError: string | null;
97
122
  auditPath: string;
98
123
  auditRelPath: string;
99
- invariantProposalsPath: string | null;
100
- canonicalCitationsPath: string | null;
101
124
  inputTokens: number;
102
125
  outputTokens: number;
103
126
  batchesRun: number;
104
127
  batchesFailed: number;
105
- /** Distribution by classifier kind. */
128
+ /** Distribution by classifier kind (rationale / constraint / etc.). */
106
129
  kindCounts: Record<CommentClassKind, number>;
107
130
  }
108
131
  export declare function runSourceCommentsIngestion(args: IngestSourceCommentsArgs): Promise<IngestSourceCommentsResult>;
132
+ export {};