@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.
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/alignment-pending.d.ts +28 -0
- package/dist/alignment-pending.js +83 -0
- package/dist/alignment-pending.js.map +1 -0
- package/dist/anchor-map.d.ts +14 -0
- package/dist/anchor-map.js +56 -0
- package/dist/anchor-map.js.map +1 -0
- package/dist/archive.d.ts +48 -0
- package/dist/archive.js +96 -0
- package/dist/archive.js.map +1 -0
- package/dist/cache.d.ts +48 -0
- package/dist/cache.js +241 -0
- package/dist/cache.js.map +1 -0
- package/dist/component-registry.d.ts +93 -0
- package/dist/component-registry.js +0 -0
- package/dist/component-registry.js.map +1 -0
- package/dist/components.d.ts +192 -0
- package/dist/components.js +603 -0
- package/dist/components.js.map +1 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.js +26 -0
- package/dist/config.js.map +1 -0
- package/dist/drift.d.ts +8 -0
- package/dist/drift.js +23 -0
- package/dist/drift.js.map +1 -0
- package/dist/file-candidates-map.d.ts +23 -0
- package/dist/file-candidates-map.js +76 -0
- package/dist/file-candidates-map.js.map +1 -0
- package/dist/frontmatter.d.ts +32 -0
- package/dist/frontmatter.js +77 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/fs.d.ts +36 -0
- package/dist/fs.js +47 -0
- package/dist/fs.js.map +1 -0
- package/dist/glob.d.ts +10 -0
- package/dist/glob.js +46 -0
- package/dist/glob.js.map +1 -0
- package/dist/home.d.ts +69 -0
- package/dist/home.js +168 -0
- package/dist/home.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/languages.d.ts +113 -0
- package/dist/languages.js +512 -0
- package/dist/languages.js.map +1 -0
- package/dist/ledgers.d.ts +14 -0
- package/dist/ledgers.js +105 -0
- package/dist/ledgers.js.map +1 -0
- package/dist/logger.d.ts +13 -0
- package/dist/logger.js +17 -0
- package/dist/logger.js.map +1 -0
- package/dist/manifest.d.ts +10 -0
- package/dist/manifest.js +84 -0
- package/dist/manifest.js.map +1 -0
- package/dist/missions.d.ts +119 -0
- package/dist/missions.js +414 -0
- package/dist/missions.js.map +1 -0
- package/dist/paths.d.ts +117 -0
- package/dist/paths.js +241 -0
- package/dist/paths.js.map +1 -0
- package/dist/quality-grades.d.ts +11 -0
- package/dist/quality-grades.js +100 -0
- package/dist/quality-grades.js.map +1 -0
- package/dist/rejected.d.ts +42 -0
- package/dist/rejected.js +100 -0
- package/dist/rejected.js.map +1 -0
- package/dist/schemas.d.ts +789 -0
- package/dist/schemas.js +506 -0
- package/dist/schemas.js.map +1 -0
- package/dist/scope-index.d.ts +96 -0
- package/dist/scope-index.js +299 -0
- package/dist/scope-index.js.map +1 -0
- package/dist/slug.d.ts +81 -0
- package/dist/slug.js +138 -0
- package/dist/slug.js.map +1 -0
- package/dist/sot-bindings.d.ts +14 -0
- package/dist/sot-bindings.js +79 -0
- package/dist/sot-bindings.js.map +1 -0
- package/dist/sot-cache.d.ts +18 -0
- package/dist/sot-cache.js +62 -0
- package/dist/sot-cache.js.map +1 -0
- package/dist/text.d.ts +27 -0
- package/dist/text.js +63 -0
- package/dist/text.js.map +1 -0
- package/dist/topic-index.d.ts +27 -0
- package/dist/topic-index.js +82 -0
- package/dist/topic-index.js.map +1 -0
- package/dist/walk.d.ts +7 -0
- package/dist/walk.js +34 -0
- package/dist/walk.js.map +1 -0
- package/package.json +35 -0
package/dist/rejected.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `.cairn/ground/_rejected.yaml` — slug-keyed ledger of topic-index
|
|
3
|
+
* entries the operator (or AI curator) has marked as not-a-decision.
|
|
4
|
+
*
|
|
5
|
+
* Phase 6 / `cairn ingest` skip any slug present here. The PR 2
|
|
6
|
+
* `cairn_propose_decision` MCP tool refuses rejected slugs with
|
|
7
|
+
* `{ ok: false, reason: "rejected" }`. Phase 5b's GC pass at the end
|
|
8
|
+
* of `buildTopicIndex` drops any entry whose slug is no longer in the
|
|
9
|
+
* freshly-built topic-index — so rotating docs / deleted markdown
|
|
10
|
+
* files don't accumulate dead rejection records.
|
|
11
|
+
*
|
|
12
|
+
* Dedup: first writer wins the `reason`; subsequent writes for the
|
|
13
|
+
* same slug only refresh `rejected_at`.
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
16
|
+
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
17
|
+
import { writeFileSafe } from "./fs.js";
|
|
18
|
+
import { getLogger } from "./logger.js";
|
|
19
|
+
import { rejectedYamlPath } from "./paths.js";
|
|
20
|
+
import { RejectedYaml } from "./schemas.js";
|
|
21
|
+
const log = getLogger();
|
|
22
|
+
export function emptyRejectedYaml() {
|
|
23
|
+
return { version: 1, generated: new Date().toISOString(), rejected: [] };
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Read `_rejected.yaml` and return a slug-keyed Map for O(1) lookups.
|
|
27
|
+
* Missing file → empty Map. Malformed file → empty Map + warn (the
|
|
28
|
+
* sensor surface treats this as a deliberate clean slate rather than
|
|
29
|
+
* an error so the operator can recover by deleting the file).
|
|
30
|
+
*/
|
|
31
|
+
export function readRejectedYaml(repoRoot) {
|
|
32
|
+
const path = rejectedYamlPath(repoRoot);
|
|
33
|
+
if (!existsSync(path))
|
|
34
|
+
return new Map();
|
|
35
|
+
let parsed;
|
|
36
|
+
try {
|
|
37
|
+
parsed = parseYaml(readFileSync(path, "utf8"));
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
log.warn({ path, err }, "_rejected.yaml read failed; treating as empty");
|
|
41
|
+
return new Map();
|
|
42
|
+
}
|
|
43
|
+
const result = RejectedYaml.safeParse(parsed);
|
|
44
|
+
if (!result.success) {
|
|
45
|
+
log.warn({ path, error: result.error.message }, "_rejected.yaml invalid; treating as empty");
|
|
46
|
+
return new Map();
|
|
47
|
+
}
|
|
48
|
+
const out = new Map();
|
|
49
|
+
for (const entry of result.data.rejected)
|
|
50
|
+
out.set(entry.slug, entry);
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Persist a slug-keyed Map to `_rejected.yaml`. Rebuilds `generated`.
|
|
55
|
+
* Sorted by slug for stable diffs.
|
|
56
|
+
*/
|
|
57
|
+
export function writeRejectedYaml(repoRoot, rejected) {
|
|
58
|
+
const path = rejectedYamlPath(repoRoot);
|
|
59
|
+
const sortedSlugs = [...rejected.keys()].sort();
|
|
60
|
+
const next = {
|
|
61
|
+
version: 1,
|
|
62
|
+
generated: new Date().toISOString(),
|
|
63
|
+
rejected: sortedSlugs.map((s) => rejected.get(s)),
|
|
64
|
+
};
|
|
65
|
+
writeFileSafe(path, stringifyYaml(next));
|
|
66
|
+
log.debug({ path, count: next.rejected.length }, "wrote _rejected.yaml");
|
|
67
|
+
return path;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Append (or refresh) a rejection record. Dedup by slug — first writer
|
|
71
|
+
* wins the `reason` string; subsequent writes update `rejected_at`
|
|
72
|
+
* only. Returns the merged Map without persisting; callers handle the
|
|
73
|
+
* write so concurrent paths can batch under a single lock.
|
|
74
|
+
*/
|
|
75
|
+
export function appendRejected(current, entry) {
|
|
76
|
+
const next = new Map(current);
|
|
77
|
+
const existing = next.get(entry.slug);
|
|
78
|
+
if (existing === undefined) {
|
|
79
|
+
next.set(entry.slug, entry);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
next.set(entry.slug, { ...existing, rejected_at: entry.rejected_at });
|
|
83
|
+
}
|
|
84
|
+
return next;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Garbage-collect rejection records whose slug is no longer present in
|
|
88
|
+
* the freshly-built topic-index. Phase 5b runs this at the end of
|
|
89
|
+
* `buildTopicIndex` so the index-builder owns rejection lifecycle —
|
|
90
|
+
* keeps the sensor surface clean as docs rotate.
|
|
91
|
+
*/
|
|
92
|
+
export function gcRejectedYaml(rejected, liveSlugs) {
|
|
93
|
+
const next = new Map();
|
|
94
|
+
for (const [slug, entry] of rejected.entries()) {
|
|
95
|
+
if (liveSlugs.has(slug))
|
|
96
|
+
next.set(slug, entry);
|
|
97
|
+
}
|
|
98
|
+
return next;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=rejected.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rejected.js","sourceRoot":"","sources":["../src/rejected.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,MAAM,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAsB,MAAM,cAAc,CAAC;AAEhE,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC;AAExB,MAAM,UAAU,iBAAiB;IAC/B,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;AAC3E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,MAAM,IAAI,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACxC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,GAAG,EAAE,CAAC;IACxC,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,SA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