@nexus-cortex/core 4.52.0 → 4.54.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 (37) hide show
  1. package/dist/adapters/node/GitHistoryStore.d.ts +80 -0
  2. package/dist/adapters/node/GitHistoryStore.d.ts.map +1 -0
  3. package/dist/adapters/node/GitHistoryStore.js +179 -0
  4. package/dist/adapters/node/GitHistoryStore.js.map +1 -0
  5. package/dist/adapters/node/index.d.ts +2 -0
  6. package/dist/adapters/node/index.d.ts.map +1 -1
  7. package/dist/adapters/node/index.js +1 -0
  8. package/dist/adapters/node/index.js.map +1 -1
  9. package/dist/canon/canonArtifacts.d.ts +14 -0
  10. package/dist/canon/canonArtifacts.d.ts.map +1 -0
  11. package/dist/canon/canonArtifacts.js +269 -0
  12. package/dist/canon/canonArtifacts.js.map +1 -0
  13. package/dist/canon/canonGraph.d.ts +30 -0
  14. package/dist/canon/canonGraph.d.ts.map +1 -0
  15. package/dist/canon/canonGraph.js +216 -0
  16. package/dist/canon/canonGraph.js.map +1 -0
  17. package/dist/canon/canonPull.d.ts +38 -0
  18. package/dist/canon/canonPull.d.ts.map +1 -0
  19. package/dist/canon/canonPull.js +133 -0
  20. package/dist/canon/canonPull.js.map +1 -0
  21. package/dist/canon/canonSync.d.ts +20 -0
  22. package/dist/canon/canonSync.d.ts.map +1 -0
  23. package/dist/canon/canonSync.js +243 -0
  24. package/dist/canon/canonSync.js.map +1 -0
  25. package/dist/canon/canonTranslate.d.ts +19 -0
  26. package/dist/canon/canonTranslate.d.ts.map +1 -0
  27. package/dist/canon/canonTranslate.js +719 -0
  28. package/dist/canon/canonTranslate.js.map +1 -0
  29. package/dist/canon/index.d.ts +19 -0
  30. package/dist/canon/index.d.ts.map +1 -0
  31. package/dist/canon/index.js +14 -0
  32. package/dist/canon/index.js.map +1 -0
  33. package/dist/index.d.ts +3 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +2 -1
  36. package/dist/index.js.map +1 -1
  37. package/package.json +17 -4
@@ -0,0 +1,30 @@
1
+ import { type CanonSession } from './canonPull.js';
2
+ export interface ProjectEntry {
3
+ id: string;
4
+ /** Best-effort decoded root (claude-code encoding is lossy on dashes — encoded form is authoritative). */
5
+ root: string;
6
+ /** Store-relative canon session dir prefixes per harness. */
7
+ sessionPaths: Record<string, string[]>;
8
+ sessionCounts: Record<string, number>;
9
+ }
10
+ /** Derive the authoritative project ↔ session-path map from store paths. */
11
+ export declare function deriveProjectSessionMap(store: string): Record<string, ProjectEntry>;
12
+ /** Resolve which project a canon session belongs to (by path prefix). */
13
+ export declare function sessionProject(projects: Record<string, ProjectEntry>, s: CanonSession): string | undefined;
14
+ export interface CanonGraphOptions {
15
+ store?: string;
16
+ /** Limit to one project id (default: all mapped projects). */
17
+ project?: string;
18
+ /** Path to an external (graphify) node-link graph.json to fold into each project graph. */
19
+ mergeGraph?: string;
20
+ dryRun?: boolean;
21
+ }
22
+ export interface CanonGraphResult {
23
+ projects: string[];
24
+ nodes: number;
25
+ links: number;
26
+ pushed: boolean;
27
+ }
28
+ /** Generate /projects/<id>.json manifests + /projects/<id>/graph.json (node-link, 🔒 criteria). */
29
+ export declare function canonGraph(o?: CanonGraphOptions): Promise<CanonGraphResult>;
30
+ //# sourceMappingURL=canonGraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonGraph.d.ts","sourceRoot":"","sources":["../../src/canon/canonGraph.ts"],"names":[],"mappings":"AAgCA,OAAO,EAAyB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI1E,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,0GAA0G;IAC1G,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACvC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACvC;AAcD,4EAA4E;AAC5E,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAiCnF;AAED,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAO1G;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2FAA2F;IAC3F,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,mGAAmG;AACnG,wBAAsB,UAAU,CAAC,CAAC,GAAE,iBAAsB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAkGrF"}
@@ -0,0 +1,216 @@
1
+ /**
2
+ * canonGraph — the §27l knowledge-graph leg (Phase C part 2, leg 4) plus the
3
+ * project↔session normalization it requires.
4
+ *
5
+ * PROJECT MAP (the prerequisite): project identity in the store is implicit
6
+ * and split across two conventions — Claude Code's normalized-path dirs
7
+ * (`-home-runner-workspace-nexus-terminal`) and canonSync's CORTEX_ROOTS
8
+ * labels (`nexus-terminal`). `deriveProjectSessionMap` joins them, DERIVED
9
+ * entirely from store paths (never hand-maintained — §27l's rule): known
10
+ * roots match exactly by their encoded form; UNKNOWN claude-code dirs become
11
+ * their own project (closing the hand-listed-roots blind spot: new roots
12
+ * surface instead of vanishing). No `project` field is added to Message
13
+ * records — that would break the verbatim-superset rule; the map is a
14
+ * derived artifact written to /projects/<id>.json.
15
+ *
16
+ * GRAPH (🔒 v1 acceptance criteria, non-negotiable): the writer emits
17
+ * NetworkX node-link JSON ({directed, multigraph, graph, nodes, links}) and
18
+ * stamps EVERY edge with confidence ∈ {EXTRACTED, INFERRED, AMBIGUOUS} plus
19
+ * numeric confidence_score {1.0, 0.5, 0.2} — baked in at genesis, never
20
+ * retrofitted. Nodes carry graphify-compatible fields (id, label, file_type,
21
+ * source_file, source_location) and canon ids are NAMESPACED (sess:/art:/
22
+ * proj:) to dodge graphify's stem-id collisions. The HISTORY half consumes
23
+ * BOTH canonical record kinds (Message sessions + ArtifactManifests); the
24
+ * CODE half is graphify's job (adopted at arm's length, mode A): pass
25
+ * `mergeGraph` to fold a graphify graph.json into the same node-link
26
+ * structure, joined on source_file. graphify stays replaceable; never Penpax.
27
+ *
28
+ * @module canon/canonGraph
29
+ */
30
+ import * as fs from 'node:fs';
31
+ import * as path from 'node:path';
32
+ import { execFileSync } from 'node:child_process';
33
+ import { discoverCanonSessions } from './canonPull.js';
34
+ const CONFIDENCE_SCORE = { EXTRACTED: 1.0, INFERRED: 0.5, AMBIGUOUS: 0.2 };
35
+ /** Known roots: exact encoded-form matches. Everything else derives its own entry. */
36
+ const KNOWN_ROOTS = [
37
+ ['workspace', '/home/runner/workspace'],
38
+ ['omniclaude-v4', '/home/runner/workspace/omniclaude-v4'],
39
+ ['nexus-terminal', '/home/runner/workspace/nexus-terminal'],
40
+ ];
41
+ const encodeCC = (root) => root.replace(/[/.]/g, '-');
42
+ /** cortex label → project id (labels that are sub-roots of a project). */
43
+ const CORTEX_LABEL_PROJECT = {
44
+ workspace: 'workspace', 'omniclaude-v4': 'omniclaude-v4', server: 'omniclaude-v4', 'nexus-terminal': 'nexus-terminal',
45
+ };
46
+ /** Derive the authoritative project ↔ session-path map from store paths. */
47
+ export function deriveProjectSessionMap(store) {
48
+ const projects = {};
49
+ const entry = (id, root) => (projects[id] ??= { id, root, sessionPaths: {}, sessionCounts: {} });
50
+ const add = (id, root, harness, rel) => {
51
+ const e = entry(id, root);
52
+ (e.sessionPaths[harness] ??= []).push(rel);
53
+ e.sessionCounts[harness] = (e.sessionCounts[harness] ?? 0) + 0; // counts filled from sessions below
54
+ };
55
+ const ccByEncoding = new Map(KNOWN_ROOTS.map(([id, root]) => [encodeCC(root), { id, root }]));
56
+ const wsPrefix = encodeCC('/home/runner/workspace') + '-';
57
+ const ccRoot = path.join(store, 'canon', 'claude-code');
58
+ let ccDirs = [];
59
+ try {
60
+ ccDirs = fs.readdirSync(ccRoot).filter((d) => fs.statSync(path.join(ccRoot, d)).isDirectory());
61
+ }
62
+ catch { /* none */ }
63
+ for (const dir of ccDirs.sort()) {
64
+ const known = ccByEncoding.get(dir);
65
+ if (known)
66
+ add(known.id, known.root, 'claude-code', path.join('claude-code', dir));
67
+ else if (dir.startsWith(wsPrefix)) {
68
+ // Unknown root — surfaces as its OWN project (blind-spot closure).
69
+ const id = dir.slice(wsPrefix.length);
70
+ add(id, `/home/runner/workspace/${id}` /* best-effort decode */, 'claude-code', path.join('claude-code', dir));
71
+ }
72
+ else
73
+ add(dir, dir, 'claude-code', path.join('claude-code', dir));
74
+ }
75
+ const cxRoot = path.join(store, 'canon', 'nexus-cortex');
76
+ let cxDirs = [];
77
+ try {
78
+ cxDirs = fs.readdirSync(cxRoot).filter((d) => fs.statSync(path.join(cxRoot, d)).isDirectory());
79
+ }
80
+ catch { /* none */ }
81
+ for (const label of cxDirs.sort()) {
82
+ const id = CORTEX_LABEL_PROJECT[label] ?? label;
83
+ const root = projects[id]?.root ?? KNOWN_ROOTS.find(([k]) => k === id)?.[1] ?? label;
84
+ add(id, root, 'nexus-cortex', path.join('nexus-cortex', label));
85
+ }
86
+ return projects;
87
+ }
88
+ /** Resolve which project a canon session belongs to (by path prefix). */
89
+ export function sessionProject(projects, s) {
90
+ for (const p of Object.values(projects)) {
91
+ for (const prefixes of Object.values(p.sessionPaths)) {
92
+ if (prefixes.some((pre) => s.rel.startsWith(pre + path.sep)))
93
+ return p.id;
94
+ }
95
+ }
96
+ return undefined;
97
+ }
98
+ /** Generate /projects/<id>.json manifests + /projects/<id>/graph.json (node-link, 🔒 criteria). */
99
+ export async function canonGraph(o = {}) {
100
+ const STORE = o.store ?? '/tmp/canon-store';
101
+ const env = { ...process.env, GIT_TERMINAL_PROMPT: '0' };
102
+ const projects = deriveProjectSessionMap(STORE);
103
+ const sessions = discoverCanonSessions(STORE);
104
+ for (const s of sessions) {
105
+ const pid = sessionProject(projects, s);
106
+ if (pid)
107
+ projects[pid].sessionCounts[s.harness] = (projects[pid].sessionCounts[s.harness] ?? 0) + 1;
108
+ }
109
+ // Load artifact manifests (the second record kind).
110
+ const artRoot = path.join(STORE, 'canon', 'artifacts');
111
+ const artifacts = [];
112
+ const walkJson = (d) => {
113
+ let es = [];
114
+ try {
115
+ es = fs.readdirSync(d, { withFileTypes: true });
116
+ }
117
+ catch {
118
+ return;
119
+ }
120
+ for (const e of es) {
121
+ const p = path.join(d, e.name);
122
+ if (e.isDirectory())
123
+ walkJson(p);
124
+ else if (e.name.endsWith('.json')) {
125
+ try {
126
+ artifacts.push({ ...JSON.parse(fs.readFileSync(p, 'utf8')), _manifestPath: path.relative(STORE, p) });
127
+ }
128
+ catch { /* lint's job */ }
129
+ }
130
+ }
131
+ };
132
+ walkJson(artRoot);
133
+ let head = '';
134
+ try {
135
+ head = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: STORE, encoding: 'utf8', env }).trim();
136
+ }
137
+ catch { /* untracked */ }
138
+ const wanted = o.project ? [o.project] : Object.keys(projects).sort();
139
+ let totalNodes = 0, totalLinks = 0;
140
+ const built = [];
141
+ for (const pid of wanted) {
142
+ const proj = projects[pid];
143
+ if (!proj)
144
+ continue;
145
+ const nodes = [];
146
+ const links = [];
147
+ const edge = (source, target, relation, confidence, source_file) => links.push({ source, target, relation, confidence, confidence_score: CONFIDENCE_SCORE[confidence], source_file, source_location: '', weight: 1.0 });
148
+ const projNodeId = `proj:${pid}`;
149
+ nodes.push({ id: projNodeId, label: pid, file_type: 'concept', source_file: `projects/${pid}.json`, source_location: '', community: 0 });
150
+ for (const s of sessions) {
151
+ if (sessionProject(projects, s) !== pid)
152
+ continue;
153
+ const nid = `sess:${s.uuid}`;
154
+ nodes.push({ id: nid, label: s.title ?? s.uuid.slice(0, 8), file_type: 'document', source_file: path.join('canon', s.rel), source_location: '', harness: s.harness, bytes: s.bytes });
155
+ edge(projNodeId, nid, 'contains', 'EXTRACTED', path.join('canon', s.rel));
156
+ }
157
+ for (const a of artifacts) {
158
+ const nid = `art:${a.kind}:${a.id}`;
159
+ nodes.push({ id: nid, label: a.name ?? a.id, file_type: a.kind === 'plan' || a.kind === 'project' ? 'document' : 'concept', source_file: a._manifestPath, source_location: '', kind: a.kind, version: a.version });
160
+ // User-scope artifacts are AVAILABLE to every project (inferred), except
161
+ // project manifests which bind exactly to their project (extracted).
162
+ if (a.kind === 'project') {
163
+ if (a.id === pid)
164
+ edge(nid, projNodeId, 'describes', 'EXTRACTED', a._manifestPath);
165
+ }
166
+ else
167
+ edge(nid, projNodeId, 'available_to', 'INFERRED', a._manifestPath);
168
+ }
169
+ // Optional CODE half: fold an external graphify node-link graph (mode A join).
170
+ if (o.mergeGraph && fs.existsSync(o.mergeGraph)) {
171
+ try {
172
+ const g = JSON.parse(fs.readFileSync(o.mergeGraph, 'utf8'));
173
+ for (const n of g.nodes ?? [])
174
+ nodes.push(n); // graphify ids are un-namespaced; canon ids can't collide (namespaced)
175
+ for (const l of g.links ?? g.edges ?? []) {
176
+ if (l.confidence_score === undefined)
177
+ l.confidence_score = CONFIDENCE_SCORE[l.confidence ?? 'EXTRACTED'] ?? 1.0;
178
+ links.push(l);
179
+ }
180
+ }
181
+ catch { /* malformed external graph — skip, lint covers our own outputs */ }
182
+ }
183
+ const graph = { directed: true, multigraph: false, graph: {}, nodes, links };
184
+ if (head)
185
+ graph.built_at_commit = head;
186
+ totalNodes += nodes.length;
187
+ totalLinks += links.length;
188
+ built.push(pid);
189
+ if (!o.dryRun) {
190
+ const pj = path.join(STORE, 'projects', `${pid}.json`);
191
+ fs.mkdirSync(path.dirname(pj), { recursive: true });
192
+ fs.writeFileSync(pj, JSON.stringify(proj, null, 2) + '\n');
193
+ const gp = path.join(STORE, 'projects', pid, 'graph.json');
194
+ fs.mkdirSync(path.dirname(gp), { recursive: true });
195
+ fs.writeFileSync(gp, JSON.stringify(graph, null, 2) + '\n');
196
+ }
197
+ }
198
+ let pushed = false;
199
+ const summary = `${built.length} project graph(s), ${totalNodes} nodes, ${totalLinks} links`;
200
+ if (!o.dryRun) {
201
+ const git = (a) => execFileSync('git', a, { cwd: STORE, encoding: 'utf8', env });
202
+ git(['add', '-A']);
203
+ if (git(['status', '--porcelain']).trim()) {
204
+ git(['commit', '-q', '-m', `canon-graph: ${summary}`]);
205
+ git(['push', '-q', 'origin', 'main']);
206
+ console.log(`[canon-graph] pushed: ${summary}`);
207
+ pushed = true;
208
+ }
209
+ else
210
+ console.log(`[canon-graph] no changes (${summary})`);
211
+ }
212
+ else
213
+ console.log(`[canon-graph DRY] ${summary}`);
214
+ return { projects: built, nodes: totalNodes, links: totalLinks, pushed };
215
+ }
216
+ //# sourceMappingURL=canonGraph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonGraph.js","sourceRoot":"","sources":["../../src/canon/canonGraph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAqB,MAAM,gBAAgB,CAAC;AAE1E,MAAM,gBAAgB,GAA2B,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;AAWnG,sFAAsF;AACtF,MAAM,WAAW,GAAiC;IAChD,CAAC,WAAW,EAAE,wBAAwB,CAAC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C;YAChD,MAAM,GAAG,IAAI,CAAC;QAChB,CAAC;;YAAM,OAAO,CAAC,GAAG,CAAC,6BAA6B,OAAO,GAAG,CAAC,CAAC;IAC9D,CAAC;;QAAM,OAAO,CAAC,GAAG,CAAC,qBAAqB,OAAO,EAAE,CAAC,CAAC;IACnD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,38 @@
1
+ export interface CanonStoreOptions {
2
+ /** Canon store working clone (default /tmp/canon-store — off-quota; auto-cloned). */
3
+ store?: string;
4
+ /** Store remote for the auto-clone (default env CANON_REPO or the canonical repo). */
5
+ repoUrl?: string;
6
+ }
7
+ export interface CanonSession {
8
+ uuid: string;
9
+ rel: string;
10
+ parts: string[];
11
+ bytes: number;
12
+ harness: string;
13
+ title?: string;
14
+ }
15
+ export interface CanonPullOptions extends CanonStoreOptions {
16
+ /** Session uuid (or unique prefix) to materialize. */
17
+ session: string;
18
+ /** Destination directory (default {home}/omniclaude-v4/.cortex/sessions). */
19
+ to?: string;
20
+ /** Overwrite an existing local session file (default false — pull is a branch, never a clobber). */
21
+ force?: boolean;
22
+ home?: string;
23
+ }
24
+ export interface CanonPullResult {
25
+ /** 0 = materialized; 1 = not found / ambiguous / exists-without-force. */
26
+ code: 0 | 1;
27
+ dest?: string;
28
+ session?: CanonSession;
29
+ }
30
+ /** Discover canon sessions (part-aware; titles recovered from event sidecars). */
31
+ export declare function discoverCanonSessions(store: string): CanonSession[];
32
+ /** List canon sessions (prints rows; returns them). `all` includes <4KB sessions. */
33
+ export declare function canonList(o?: CanonStoreOptions & {
34
+ all?: boolean;
35
+ }): Promise<CanonSession[]>;
36
+ /** Materialize one canon session into a native session directory. */
37
+ export declare function canonPull(o: CanonPullOptions): Promise<CanonPullResult>;
38
+ //# sourceMappingURL=canonPull.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonPull.d.ts","sourceRoot":"","sources":["../../src/canon/canonPull.ts"],"names":[],"mappings":"AAoBA,MAAM,WAAW,iBAAiB;IAChC,qFAAqF;IACrF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sFAAsF;IACtF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB;IACzD,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,6EAA6E;IAC7E,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,oGAAoG;IACpG,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,eAAe;IAC9B,0EAA0E;IAC1E,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB;AAcD,kFAAkF;AAClF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,EAAE,CAoCnE;AAED,qFAAqF;AACrF,wBAAsB,SAAS,CAAC,CAAC,GAAE,iBAAiB,GAAG;IAAE,GAAG,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAWtG;AAED,qEAAqE;AACrE,wBAAsB,SAAS,CAAC,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CA8B7E"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * canonPull — the canon rehydration leg, graduated from
3
+ * `scripts/canon/canon-pull.ts` (Phase C part 2; the script is now a thin
4
+ * wrapper over this module).
5
+ *
6
+ * Materializes a canon session into the RECEIVING harness's native session
7
+ * directory, where that harness's own resume UI already looks — no proxy
8
+ * layer, the filesystem is the interface. For nexus-cortex the projection is
9
+ * identity (canon IS the cortex dialect): pull = freshen store + reassemble
10
+ * parts + copy. Pull refuses to overwrite an existing local session unless
11
+ * forced — resuming elsewhere is a BRANCH of the canonical line, never a
12
+ * clobber. Discovery/materialization bodies transplanted from the proven
13
+ * script; exit codes become return codes for library use.
14
+ *
15
+ * @module canon/canonPull
16
+ */
17
+ import * as fs from 'node:fs';
18
+ import * as path from 'node:path';
19
+ import { execFileSync } from 'node:child_process';
20
+ /** Clone the store if absent, else pull — rehydrate freshness on arrival. */
21
+ function ensureFreshStore(store, repoUrl, label = 'canon-pull') {
22
+ const repo = repoUrl ?? process.env.CANON_REPO ?? 'https://github.com/Spitfire-Products/nexus-canon-store';
23
+ const env = { ...process.env, GIT_TERMINAL_PROMPT: '0' };
24
+ if (!fs.existsSync(path.join(store, '.git'))) {
25
+ console.log(`[${label}] no store at ${store} — cloning ${repo}`);
26
+ execFileSync('git', ['clone', '-q', repo, store], { encoding: 'utf8', env });
27
+ }
28
+ else {
29
+ execFileSync('git', ['pull', '-q', 'origin', 'main'], { cwd: store, encoding: 'utf8', env });
30
+ }
31
+ }
32
+ /** Discover canon sessions (part-aware; titles recovered from event sidecars). */
33
+ export function discoverCanonSessions(store) {
34
+ const root = path.join(store, 'canon');
35
+ const groups = new Map();
36
+ const walk = (dir) => {
37
+ let entries = [];
38
+ try {
39
+ entries = fs.readdirSync(dir, { withFileTypes: true });
40
+ }
41
+ catch {
42
+ return;
43
+ }
44
+ for (const e of entries) {
45
+ const p = path.join(dir, e.name);
46
+ if (e.isDirectory()) {
47
+ walk(p);
48
+ continue;
49
+ }
50
+ if (!e.isFile())
51
+ continue;
52
+ const m = e.name.match(/^(.*\.jsonl)\.part-\d{4}$/);
53
+ const logical = m ? path.join(dir, m[1]) : p;
54
+ if (!logical.endsWith('.jsonl') || logical.endsWith('.events.jsonl'))
55
+ continue;
56
+ const g = groups.get(logical) ?? [];
57
+ g.push(p);
58
+ groups.set(logical, g);
59
+ }
60
+ };
61
+ walk(root);
62
+ const out = [];
63
+ for (const [logical, parts] of groups) {
64
+ parts.sort();
65
+ const rel = path.relative(root, logical);
66
+ const uuid = path.basename(rel, '.jsonl');
67
+ const bytes = parts.reduce((n, p) => n + fs.statSync(p).size, 0);
68
+ let title;
69
+ const eventsPath = logical.replace(/\.jsonl$/, '.events.jsonl');
70
+ if (fs.existsSync(eventsPath)) {
71
+ for (const line of fs.readFileSync(eventsPath, 'utf8').split('\n')) {
72
+ if (!line.trim())
73
+ continue;
74
+ try {
75
+ const r = JSON.parse(line);
76
+ if (r.type === 'ai-title' && r.aiTitle)
77
+ title = r.aiTitle;
78
+ }
79
+ catch { /* skip */ }
80
+ }
81
+ }
82
+ out.push({ uuid, rel, parts, bytes, harness: rel.split(path.sep)[0] ?? '?', title });
83
+ }
84
+ return out.sort((a, b) => a.rel.localeCompare(b.rel));
85
+ }
86
+ /** List canon sessions (prints rows; returns them). `all` includes <4KB sessions. */
87
+ export async function canonList(o = {}) {
88
+ const store = o.store ?? '/tmp/canon-store';
89
+ ensureFreshStore(store, o.repoUrl);
90
+ const sessions = discoverCanonSessions(store);
91
+ const rows = sessions.filter((s) => o.all || s.bytes > 4096);
92
+ for (const s of rows) {
93
+ const kb = (s.bytes / 1024).toFixed(0).padStart(7);
94
+ console.log(`${s.uuid} ${kb}KB ${s.harness.padEnd(12)} ${s.title ?? ''}`);
95
+ }
96
+ console.log(`\n[canon-pull] ${rows.length} session(s)${o.all ? '' : ' >4KB (--all for every one)'} in ${store}/canon`);
97
+ return rows;
98
+ }
99
+ /** Materialize one canon session into a native session directory. */
100
+ export async function canonPull(o) {
101
+ const store = o.store ?? '/tmp/canon-store';
102
+ const home = o.home ?? process.env.HOME ?? '/home/runner/workspace';
103
+ ensureFreshStore(store, o.repoUrl);
104
+ const sessions = discoverCanonSessions(store);
105
+ const matches = sessions.filter((s) => s.uuid === o.session || s.uuid.startsWith(o.session));
106
+ if (matches.length === 0) {
107
+ console.error(`[canon-pull] no canon session matches '${o.session}'`);
108
+ return { code: 1 };
109
+ }
110
+ if (matches.length > 1) {
111
+ console.error(`[canon-pull] ambiguous — ${matches.length} matches:`);
112
+ for (const m of matches)
113
+ console.error(` ${m.uuid} (${m.rel})`);
114
+ return { code: 1 };
115
+ }
116
+ const s = matches[0];
117
+ const destDir = o.to ?? path.join(home, 'omniclaude-v4', '.cortex', 'sessions');
118
+ const dest = path.join(destDir, `${s.uuid}.jsonl`);
119
+ if (fs.existsSync(dest) && !o.force) {
120
+ console.error(`[canon-pull] ${dest} already exists — resuming elsewhere is a BRANCH; use --force to overwrite the local copy`);
121
+ return { code: 1, dest, session: s };
122
+ }
123
+ fs.mkdirSync(destDir, { recursive: true });
124
+ fs.writeFileSync(dest, '');
125
+ for (const p of s.parts)
126
+ fs.appendFileSync(dest, fs.readFileSync(p));
127
+ const lines = fs.readFileSync(dest, 'utf8').split('\n').filter(Boolean).length;
128
+ console.log(`[canon-pull] materialized ${s.uuid} (${s.harness}${s.title ? ` — "${s.title}"` : ''})`);
129
+ console.log(`[canon-pull] ${lines} canonical message(s), ${(s.bytes / 1024).toFixed(0)}KB → ${dest}`);
130
+ console.log(`[canon-pull] resume with: cortex --resume ${s.uuid} "..."`);
131
+ return { code: 0, dest, session: s };
132
+ }
133
+ //# sourceMappingURL=canonPull.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonPull.js","sourceRoot":"","sources":["../../src/canon/canonPull.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAmClD,6EAA6E;AAC7E,SAAS,gBAAgB,CAA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ACD,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAC3B,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK;QAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,MAAM,KAAK,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAC/E,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACrG,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,0BAA0B,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IACxG,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC;IAC3E,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AACvC,CAAC"}
@@ -0,0 +1,20 @@
1
+ export interface CanonSyncOptions {
2
+ /** Canon store working clone (default /tmp/canon-store — off-quota; auto-cloned). */
3
+ store?: string;
4
+ /** Home dir for harness roots + the mtime/size manifest (default $HOME). */
5
+ home?: string;
6
+ /** Report what would copy; write nothing. */
7
+ dryRun?: boolean;
8
+ /** Store remote for the auto-clone (default env CANON_REPO or the canonical repo). */
9
+ repoUrl?: string;
10
+ }
11
+ export interface CanonSyncResult {
12
+ copied: number;
13
+ unchanged: number;
14
+ skipped: string[];
15
+ chunked: number;
16
+ scrubbedHits: number;
17
+ pushed: boolean;
18
+ }
19
+ export declare function canonSync(o?: CanonSyncOptions): Promise<CanonSyncResult>;
20
+ //# sourceMappingURL=canonSync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonSync.d.ts","sourceRoot":"","sources":["../../src/canon/canonSync.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,gBAAgB;IAC/B,qFAAqF;IACrF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,sFAAsF;IACtF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,wBAAsB,SAAS,CAAC,CAAC,GAAE,gBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,CA0LlF"}