@north-light/api 0.3.755 → 0.3.757

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 (75) hide show
  1. package/dist/api/client.d.ts +1 -2
  2. package/dist/api/client.js +0 -3
  3. package/dist/api/contract.d.ts +1 -1
  4. package/dist/api/contract.js +1 -1
  5. package/dist/api/dto/health.d.ts +0 -54
  6. package/dist/api/routes.d.ts +0 -1
  7. package/dist/api/routes.js +0 -1
  8. package/dist/build-root.d.ts +0 -3
  9. package/dist/build-root.js +0 -9
  10. package/dist/commands/profile/new.js +2 -2
  11. package/dist/commands/profile/project.js +2 -1
  12. package/dist/commands/sys/branch.js +1 -1
  13. package/dist/commands/sys/daemon.js +1 -1
  14. package/dist/commands/sys.js +1 -2
  15. package/dist/core/canvas/executions.d.ts +0 -3
  16. package/dist/core/canvas/executions.js +1 -17
  17. package/dist/core/canvas/pid.d.ts +0 -10
  18. package/dist/core/canvas/pid.js +0 -16
  19. package/dist/core/directory/join.js +18 -1
  20. package/dist/core/grants/mirror.d.ts +0 -5
  21. package/dist/core/grants/mirror.js +0 -7
  22. package/dist/core/grants/sync.js +2 -2
  23. package/dist/core/human/page-schema.d.ts +1 -1
  24. package/dist/core/io.js +0 -5
  25. package/dist/core/layout.d.ts +0 -2
  26. package/dist/core/layout.js +2 -19
  27. package/dist/core/profiles/manifest.js +12 -18
  28. package/dist/core/profiles/project-dir.d.ts +3 -0
  29. package/dist/core/profiles/project-dir.js +20 -0
  30. package/dist/daemon/api/map.d.ts +1 -6
  31. package/dist/daemon/api/map.js +0 -16
  32. package/dist/daemon/api/operations.js +0 -1
  33. package/dist/daemon/control.d.ts +0 -8
  34. package/dist/daemon/manage.js +1 -1
  35. package/package.json +1 -1
  36. package/dist/commands/sys/migrate.d.ts +0 -1
  37. package/dist/commands/sys/migrate.js +0 -79
  38. package/dist/core/layout-migrate/index.d.ts +0 -38
  39. package/dist/core/layout-migrate/index.js +0 -523
  40. package/dist/core/layout-migrate/paths.d.ts +0 -30
  41. package/dist/core/layout-migrate/paths.js +0 -118
  42. package/dist/core/layout-migrate/stored-paths.d.ts +0 -9
  43. package/dist/core/layout-migrate/stored-paths.js +0 -424
  44. package/dist/core/layout-migrate/stores.d.ts +0 -30
  45. package/dist/core/layout-migrate/stores.js +0 -543
  46. package/dist/core/locked-file.d.ts +0 -27
  47. package/dist/core/locked-file.js +0 -121
  48. package/dist/core/scoped-state/db.d.ts +0 -17
  49. package/dist/core/scoped-state/db.js +0 -271
  50. package/dist/core/scoped-state/legacy-profiles.d.ts +0 -11
  51. package/dist/core/scoped-state/legacy-profiles.js +0 -65
  52. package/dist/core/scoped-state/migrate.d.ts +0 -15
  53. package/dist/core/scoped-state/migrate.js +0 -332
  54. package/dist/core/scoped-state/schema.d.ts +0 -14
  55. package/dist/core/scoped-state/schema.js +0 -52
  56. package/dist/migrations/004-canvas-documents/apply.d.ts +0 -8
  57. package/dist/migrations/004-canvas-documents/apply.js +0 -113
  58. package/dist/migrations/004-canvas-documents/index.d.ts +0 -16
  59. package/dist/migrations/004-canvas-documents/index.js +0 -89
  60. package/dist/migrations/004-canvas-documents/legacy/discover.d.ts +0 -16
  61. package/dist/migrations/004-canvas-documents/legacy/discover.js +0 -251
  62. package/dist/migrations/004-canvas-documents/legacy/history.d.ts +0 -5
  63. package/dist/migrations/004-canvas-documents/legacy/history.js +0 -37
  64. package/dist/migrations/004-canvas-documents/legacy/nested.d.ts +0 -7
  65. package/dist/migrations/004-canvas-documents/legacy/nested.js +0 -37
  66. package/dist/migrations/004-canvas-documents/legacy/parse.d.ts +0 -14
  67. package/dist/migrations/004-canvas-documents/legacy/parse.js +0 -24
  68. package/dist/migrations/004-canvas-documents/legacy/types.d.ts +0 -91
  69. package/dist/migrations/004-canvas-documents/legacy/types.js +0 -3
  70. package/dist/migrations/004-canvas-documents/plan.d.ts +0 -102
  71. package/dist/migrations/004-canvas-documents/plan.js +0 -410
  72. package/dist/migrations/004-canvas-documents/pointers.d.ts +0 -23
  73. package/dist/migrations/004-canvas-documents/pointers.js +0 -95
  74. package/dist/migrations/activation.d.ts +0 -17
  75. package/dist/migrations/activation.js +0 -46
@@ -1,16 +0,0 @@
1
- import type { LegacyCorpus, LegacyProfile, LegacyRoots } from './types.js';
2
- export type { LegacyCorpus, LegacyDoc, LegacyOwnerRef, LegacyProfile, LegacyRoots, LegacyStoreRoot, LegacyHistoryRecord } from './types.js';
3
- /** Every stored profile manifest, read as raw JSON (the current manifest reader
4
- * is not used). `memoryFor(app, id)` resolves the profile's store path. */
5
- export declare function readLegacyProfiles(profilesRoot: string, memoryFor: (app: string, id: string) => string): {
6
- profiles: LegacyProfile[];
7
- skipped: Array<{
8
- path: string;
9
- reason: string;
10
- }>;
11
- };
12
- /** Ids listed in `<canvas home>/on-disk-migrations.json`, or null when the marker is absent. */
13
- export declare function readMarkerIds(markerPath: string): string[] | null;
14
- export declare function readLegacyCorpus(roots: LegacyRoots): LegacyCorpus;
15
- /** Cheap probe: is there any legacy document to import? */
16
- export declare function hasLegacyContent(roots: LegacyRoots): boolean;
@@ -1,251 +0,0 @@
1
- // Frozen legacy reader: finds every pre-canvas store, node context folder and
2
- // report file on the discovery frontier and reads them as data for the import
3
- // plan. fs-only; never opens canvas.db, never writes.
4
- import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'node:fs';
5
- import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
6
- import { walkFiles } from '../../../core/fs-utils.js';
7
- import { historyLogPath, HISTORY_DIR, readHistory } from './history.js';
8
- import { walkNestedStores } from './nested.js';
9
- import { contextDocName, parseFile, rawFile, storeDocName } from './parse.js';
10
- const PROFILE_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*-[0-9a-f]{8}$/;
11
- function real(p) {
12
- try {
13
- return realpathSync(p);
14
- }
15
- catch {
16
- return resolve(p);
17
- }
18
- }
19
- const isDir = (p) => {
20
- try {
21
- return statSync(p).isDirectory();
22
- }
23
- catch {
24
- return false;
25
- }
26
- };
27
- /** A `.crouter` folder that is a crouter home (the old user scope beside its canvas,
28
- * runtime, or profiles), not a project scope: legacy crouter never treated it as a
29
- * project, and taking its parent (a home directory) as a project root would walk
30
- * the whole home folder. */
31
- const isCrouterHome = (dotCrouter) => ['canvas', 'canvas.db', 'runtime', 'profiles'].some((n) => existsSync(join(dotCrouter, n)));
32
- const markdownIn = (root) => walkFiles(root, (n) => n.toLowerCase().endsWith('.md'), (n) => n.startsWith('.')).sort();
33
- /** Every stored profile manifest, read as raw JSON (the current manifest reader
34
- * is not used). `memoryFor(app, id)` resolves the profile's store path. */
35
- export function readLegacyProfiles(profilesRoot, memoryFor) {
36
- const profiles = [];
37
- const skipped = [];
38
- if (!isDir(profilesRoot))
39
- return { profiles, skipped };
40
- for (const id of readdirSync(profilesRoot).sort()) {
41
- const manifestPath = join(profilesRoot, id, 'profile.json');
42
- if (!PROFILE_ID.test(id) || !existsSync(manifestPath))
43
- continue;
44
- let raw;
45
- try {
46
- const parsed = JSON.parse(readFileSync(manifestPath, 'utf8'));
47
- if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed))
48
- throw new Error('not a JSON object');
49
- raw = parsed;
50
- }
51
- catch (e) {
52
- skipped.push({ path: manifestPath, reason: `invalid-manifest: ${e.message}` });
53
- continue;
54
- }
55
- const app = typeof raw['grantee'] === 'string' ? raw['grantee'] : 'app:terminal';
56
- const projects = Array.isArray(raw['projects'])
57
- ? raw['projects'].flatMap((p) => (typeof p === 'string' ? [p] : p !== null && typeof p === 'object' && typeof p.path === 'string' ? [p.path] : []))
58
- : [];
59
- profiles.push({ id, name: typeof raw['name'] === 'string' ? raw['name'] : id, app, memory: memoryFor(app, id), projects, raw, manifestPath });
60
- }
61
- return { profiles, skipped };
62
- }
63
- /** Ids listed in `<canvas home>/on-disk-migrations.json`, or null when the marker is absent. */
64
- export function readMarkerIds(markerPath) {
65
- if (!existsSync(markerPath))
66
- return null;
67
- const parsed = JSON.parse(readFileSync(markerPath, 'utf8'));
68
- if (!Array.isArray(parsed))
69
- throw new Error(`${markerPath}: not a JSON array`);
70
- return parsed.map((e) => (typeof e === 'string' ? e : String(e.id)));
71
- }
72
- /** The git common dir of a checkout (`.git` dir, or a linked worktree's `gitdir` → `commondir`), or null. */
73
- function gitCommonDir(root) {
74
- const dotGit = join(root, '.git');
75
- if (isDir(dotGit))
76
- return real(dotGit);
77
- if (!existsSync(dotGit))
78
- return null;
79
- const m = /^gitdir:\s*(.+)$/m.exec(readFileSync(dotGit, 'utf8'));
80
- if (!m)
81
- return null;
82
- const gitdir = isAbsolute(m[1].trim()) ? m[1].trim() : resolve(root, m[1].trim());
83
- const commondirFile = join(gitdir, 'commondir');
84
- if (!existsSync(commondirFile))
85
- return real(gitdir);
86
- const c = readFileSync(commondirFile, 'utf8').trim();
87
- return real(isAbsolute(c) ? c : resolve(gitdir, c));
88
- }
89
- export function readLegacyCorpus(roots) {
90
- const corpus = { docs: [], storeRoots: [], skipped: [], orphanHistory: 0, orphanNodeDirs: 0, nonMarkdown: 0, injectedDocs: 0 };
91
- const personalStores = new Set([roots.userMemory, ...roots.profiles.map((p) => p.memory)].map(real));
92
- const readStore = (storeRoot, owner, prefix) => {
93
- const files = markdownIn(storeRoot);
94
- const live = new Set(files.map((f) => historyLogPath(storeRoot, f)));
95
- corpus.orphanHistory += walkFiles(join(storeRoot, HISTORY_DIR), (n) => n.endsWith('.jsonl')).filter((f) => !live.has(f)).length;
96
- let count = 0;
97
- for (const path of files) {
98
- const name = prefix + storeDocName(relative(storeRoot, path));
99
- let parsed;
100
- try {
101
- parsed = parseFile(path);
102
- }
103
- catch (e) {
104
- corpus.docs.push({ path, owner, name, source: 'store', ...rawFile(path), history: [], invalid: { kind: 'invalid-source', reason: `invalid frontmatter: ${e.message}` } });
105
- count += 1;
106
- continue;
107
- }
108
- let history;
109
- try {
110
- history = readHistory(historyLogPath(storeRoot, path));
111
- }
112
- catch (e) {
113
- corpus.docs.push({ path, owner, name, source: 'store', ...parsed, history: [], invalid: { kind: 'invalid-history', reason: `unreadable history log: ${e.message}` } });
114
- count += 1;
115
- continue;
116
- }
117
- corpus.docs.push({ path, owner, name, source: 'store', ...parsed, history });
118
- count += 1;
119
- }
120
- corpus.storeRoots.push({ root: storeRoot, owner, docs: count });
121
- };
122
- if (isDir(roots.userMemory))
123
- readStore(roots.userMemory, { type: 'person' }, '');
124
- for (const p of roots.profiles)
125
- if (isDir(p.memory))
126
- readStore(p.memory, { type: 'profile', id: p.id }, '');
127
- // Repositories: walk each frontier path up to its project root.
128
- const projectRoot = (start) => {
129
- let firstStore = null;
130
- for (let dir = real(start);; dir = dirname(dir)) {
131
- if (existsSync(join(dir, '.git')))
132
- return dir;
133
- const store = join(dir, '.crouter', 'memory');
134
- if (firstStore === null && isDir(store) && !personalStores.has(real(store)) && !isCrouterHome(join(dir, '.crouter')))
135
- firstStore = dir;
136
- if (dirname(dir) === dir)
137
- return firstStore;
138
- }
139
- };
140
- const queue = [];
141
- for (const start of [...roots.profiles.flatMap((p) => p.projects), ...roots.nodeCwds]) {
142
- if (!isDir(start))
143
- continue;
144
- const root = projectRoot(start);
145
- if (root !== null)
146
- queue.push(root);
147
- }
148
- const byCommon = new Map();
149
- const seen = new Set();
150
- const repos = [];
151
- while (queue.length > 0) {
152
- const root = queue.shift();
153
- if (seen.has(root))
154
- continue;
155
- seen.add(root);
156
- const commonDir = gitCommonDir(root);
157
- repos.push({ root, commonDir });
158
- if (commonDir !== null) {
159
- byCommon.set(commonDir, [...(byCommon.get(commonDir) ?? []), root]);
160
- // Linked worktrees import from the main worktree, so bring it in.
161
- const main = dirname(commonDir);
162
- if (basename(commonDir) === '.git' && isDir(join(main, '.git')))
163
- queue.push(main);
164
- }
165
- queue.push(...walkNestedStores(root).embeddedRepos);
166
- }
167
- for (const { root, commonDir } of repos.sort((a, b) => a.root.localeCompare(b.root))) {
168
- const group = commonDir === null ? [root] : byCommon.get(commonDir);
169
- const chosen = group.find((r) => isDir(join(r, '.git'))) ?? [...group].sort()[0];
170
- const rootStore = join(root, '.crouter', 'memory');
171
- const hasRootStore = isDir(rootStore) && !personalStores.has(real(rootStore));
172
- const nested = walkNestedStores(root).nested.filter((rel) => !personalStores.has(real(join(root, rel, '.crouter', 'memory'))));
173
- let namespace = null;
174
- if (hasRootStore && existsSync(join(rootStore, 'INDEX.md'))) {
175
- try {
176
- const ns = parseFile(join(rootStore, 'INDEX.md')).frontmatter?.['namespace'];
177
- if (typeof ns === 'string' && ns !== '')
178
- namespace = ns;
179
- }
180
- catch {
181
- // imported by readStore below as a whole-file body
182
- }
183
- }
184
- const owner = { type: 'repo', root, commonDir, namespace };
185
- if (root !== chosen) {
186
- if (hasRootStore)
187
- corpus.storeRoots.push({ root: rootStore, owner, docs: 0, skipped: 'duplicate-worktree' });
188
- for (const rel of nested)
189
- corpus.storeRoots.push({ root: join(root, rel, '.crouter', 'memory'), owner, docs: 0, skipped: 'duplicate-worktree' });
190
- continue;
191
- }
192
- if (hasRootStore)
193
- readStore(rootStore, owner, '');
194
- for (const rel of nested)
195
- readStore(join(root, rel, '.crouter', 'memory'), owner, rel.split(/[\\/]/).join('/') + '/');
196
- }
197
- // Node folders.
198
- const nodeIds = new Set(roots.nodes.map((n) => n.id));
199
- for (const parent of new Set(roots.nodes.map((n) => dirname(n.dir)))) {
200
- for (const e of readdirSync(parent, { withFileTypes: true }))
201
- if (e.isDirectory() && !nodeIds.has(e.name))
202
- corpus.orphanNodeDirs += 1;
203
- }
204
- for (const { id, dir } of roots.nodes) {
205
- const owner = { type: 'node', id };
206
- if (existsSync(join(dir, 'injected-docs.json')))
207
- corpus.injectedDocs += 1;
208
- const context = join(dir, 'context');
209
- if (isDir(join(context, 'memory')))
210
- readStore(join(context, 'memory'), owner, '');
211
- const readPlain = (path, name, source) => {
212
- try {
213
- corpus.docs.push({ path, owner, name, source, ...parseFile(path), history: [] });
214
- }
215
- catch (e) {
216
- corpus.docs.push({ path, owner, name, source, ...rawFile(path), history: [], invalid: { kind: 'invalid-source', reason: `invalid frontmatter: ${e.message}` } });
217
- }
218
- };
219
- for (const path of walkFiles(context, () => true, (n) => n.startsWith('.')).sort()) {
220
- const rel = relative(context, path);
221
- const top = rel.split(/[\\/]/)[0];
222
- if (top === 'memory' || top === 'jobs')
223
- continue;
224
- if (!path.toLowerCase().endsWith('.md'))
225
- corpus.nonMarkdown += 1;
226
- else
227
- readPlain(path, contextDocName(rel), 'context');
228
- }
229
- const reports = join(dir, 'reports');
230
- if (isDir(reports)) {
231
- for (const e of readdirSync(reports, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
232
- if (!e.isFile())
233
- continue;
234
- if (!e.name.toLowerCase().endsWith('.md'))
235
- corpus.nonMarkdown += 1;
236
- else
237
- readPlain(join(reports, e.name), `reports/${e.name.replace(/\.md$/i, '')}`, 'report');
238
- }
239
- }
240
- }
241
- return corpus;
242
- }
243
- /** Cheap probe: is there any legacy document to import? */
244
- export function hasLegacyContent(roots) {
245
- const anyMd = (dir) => isDir(dir) && markdownIn(dir).length > 0;
246
- if (anyMd(roots.userMemory) || roots.profiles.some((p) => anyMd(p.memory)))
247
- return true;
248
- if (roots.nodes.some((n) => anyMd(join(n.dir, 'context')) || anyMd(join(n.dir, 'reports'))))
249
- return true;
250
- return readLegacyCorpus({ ...roots, nodes: [] }).docs.length > 0;
251
- }
@@ -1,5 +0,0 @@
1
- import type { LegacyHistoryRecord } from './types.js';
2
- export declare const HISTORY_DIR = ".history";
3
- export declare function historyLogPath(storeRoot: string, docPath: string): string;
4
- /** Records of the current life, or throws naming the bad line. */
5
- export declare function readHistory(logPath: string): LegacyHistoryRecord[];
@@ -1,37 +0,0 @@
1
- // Frozen reader of `<store>/memory/.history/<physical path>.jsonl`. The log
2
- // mirrors the document's physical path and travels with it on a move, so the
3
- // current file's log holds its whole history; a prior deleted life of the same
4
- // path precedes the last `delete` record and is not this document's history.
5
- import { existsSync, readFileSync } from 'node:fs';
6
- import { join, relative } from 'node:path';
7
- export const HISTORY_DIR = '.history';
8
- export function historyLogPath(storeRoot, docPath) {
9
- return join(storeRoot, HISTORY_DIR, relative(storeRoot, docPath).replace(/\.md$/i, '') + '.jsonl');
10
- }
11
- /** Records of the current life, or throws naming the bad line. */
12
- export function readHistory(logPath) {
13
- if (!existsSync(logPath))
14
- return [];
15
- const records = [];
16
- const lines = readFileSync(logPath, 'utf8').split('\n');
17
- lines.forEach((line, i) => {
18
- if (line.trim() === '')
19
- return;
20
- let parsed;
21
- try {
22
- parsed = JSON.parse(line);
23
- }
24
- catch (e) {
25
- throw new Error(`line ${i + 1}: ${e.message}`);
26
- }
27
- const r = parsed;
28
- if (r === null || typeof r !== 'object' || typeof r.op !== 'string' || typeof r.at !== 'string' || typeof r.after !== 'string') {
29
- throw new Error(`line ${i + 1}: not a history record`);
30
- }
31
- if (r.op === 'delete')
32
- records.length = 0;
33
- else
34
- records.push(r);
35
- });
36
- return records;
37
- }
@@ -1,7 +0,0 @@
1
- export interface NestedWalk {
2
- /** `<rel>` of each `<root>/<rel>/.crouter/memory`, rel non-empty. */
3
- nested: string[];
4
- /** Folders below the root holding their own `.git`. */
5
- embeddedRepos: string[];
6
- }
7
- export declare function walkNestedStores(root: string): NestedWalk;
@@ -1,37 +0,0 @@
1
- // Exhaustive walk for `.crouter/memory` stores below a project root, frozen from
2
- // the retired runtime nested-store walk with the migration's rules: no time or
3
- // depth budget; skip `.git`, `node_modules` and every other dot-dir; stop at an
4
- // embedded repository (it is its own repo and is returned separately so the
5
- // caller imports it under its own owner).
6
- import { existsSync, readdirSync } from 'node:fs';
7
- import { join, relative } from 'node:path';
8
- export function walkNestedStores(root) {
9
- const out = { nested: [], embeddedRepos: [] };
10
- const stack = [root];
11
- while (stack.length > 0) {
12
- const dir = stack.pop();
13
- if (dir !== root) {
14
- if (existsSync(join(dir, '.git'))) {
15
- out.embeddedRepos.push(dir);
16
- continue;
17
- }
18
- if (existsSync(join(dir, '.crouter', 'memory')))
19
- out.nested.push(relative(root, dir));
20
- }
21
- let entries;
22
- try {
23
- entries = readdirSync(dir, { withFileTypes: true });
24
- }
25
- catch {
26
- continue;
27
- }
28
- for (const e of entries) {
29
- if (!e.isDirectory() || e.name.startsWith('.') || e.name === 'node_modules')
30
- continue;
31
- stack.push(join(dir, e.name));
32
- }
33
- }
34
- out.nested.sort();
35
- out.embeddedRepos.sort();
36
- return out;
37
- }
@@ -1,14 +0,0 @@
1
- export interface ParsedFile {
2
- frontmatter: Record<string, unknown> | null;
3
- body: string;
4
- mtime: string;
5
- }
6
- /** Throws when the frontmatter is not valid YAML. */
7
- export declare function parseFile(path: string): ParsedFile;
8
- /** A file whose frontmatter does not parse: the whole text is the body. */
9
- export declare function rawFile(path: string): ParsedFile;
10
- /** Frozen store naming: drop `.md`, strip each segment's `NN-` ordering prefix,
11
- * fold `a/INDEX` to `a`; the store's root `INDEX.md` is `index`. */
12
- export declare function storeDocName(relPath: string): string;
13
- /** A node context file's name: its folder-relative path without `.md`. */
14
- export declare function contextDocName(relPath: string): string;
@@ -1,24 +0,0 @@
1
- // Per-file parsing: frontmatter split, name derivation, mtime.
2
- import { readFileSync, statSync } from 'node:fs';
3
- import { parseFrontmatterGeneric } from '../../../core/frontmatter.js';
4
- /** Throws when the frontmatter is not valid YAML. */
5
- export function parseFile(path) {
6
- const parsed = parseFrontmatterGeneric(readFileSync(path, 'utf8'));
7
- return { frontmatter: parsed.data, body: parsed.body, mtime: statSync(path).mtime.toISOString() };
8
- }
9
- /** A file whose frontmatter does not parse: the whole text is the body. */
10
- export function rawFile(path) {
11
- return { frontmatter: null, body: readFileSync(path, 'utf8'), mtime: statSync(path).mtime.toISOString() };
12
- }
13
- /** Frozen store naming: drop `.md`, strip each segment's `NN-` ordering prefix,
14
- * fold `a/INDEX` to `a`; the store's root `INDEX.md` is `index`. */
15
- export function storeDocName(relPath) {
16
- const segments = relPath.replace(/\\/g, '/').replace(/\.md$/i, '').split('/').map((s) => s.replace(/^\d{2}-/, ''));
17
- if (segments[segments.length - 1] === 'INDEX')
18
- segments.pop();
19
- return segments.length === 0 ? 'index' : segments.join('/');
20
- }
21
- /** A node context file's name: its folder-relative path without `.md`. */
22
- export function contextDocName(relPath) {
23
- return relPath.replace(/\\/g, '/').replace(/\.md$/i, '');
24
- }
@@ -1,91 +0,0 @@
1
- /** Frozen copy of the history record shape the retired store-file history wrote. */
2
- export interface LegacyHistoryRecord {
3
- op: 'create' | 'edit' | 'delete' | 'move';
4
- at: string;
5
- node?: string;
6
- cwd: string;
7
- from?: string;
8
- rationale?: string;
9
- verbatim?: boolean;
10
- before: string;
11
- after: string;
12
- }
13
- export interface LegacyProfile {
14
- id: string;
15
- name: string;
16
- /** The owning app (`grantee`), `app:terminal` for older manifests without one. */
17
- app: string;
18
- /** The profile's store (`<app space>/profiles/<id>`), resolved by the caller. */
19
- memory: string;
20
- /** Every `projects[].path` in the manifest. */
21
- projects: string[];
22
- /** The manifest as parsed JSON, for fields the plan converts (`projects[].memory`). */
23
- raw?: Record<string, unknown>;
24
- manifestPath?: string;
25
- }
26
- export interface LegacyRoots {
27
- userMemory: string;
28
- profiles: LegacyProfile[];
29
- nodeCwds: string[];
30
- /** Node rows that exist in canvas.db and their folders (`<nodes>/<id>`). */
31
- nodes: Array<{
32
- id: string;
33
- dir: string;
34
- }>;
35
- }
36
- export type LegacyOwnerRef = {
37
- type: 'person';
38
- } | {
39
- type: 'profile';
40
- id: string;
41
- } | {
42
- type: 'repo';
43
- root: string;
44
- commonDir: string | null;
45
- namespace: string | null;
46
- } | {
47
- type: 'node';
48
- id: string;
49
- };
50
- export interface LegacyDoc {
51
- path: string;
52
- owner: LegacyOwnerRef;
53
- /** The document name under its owner (INDEX folding, nested prefix, `reports/<stem>`, root `INDEX.md` → `index`). */
54
- name: string;
55
- source: 'store' | 'context' | 'report';
56
- frontmatter: Record<string, unknown> | null;
57
- body: string;
58
- mtime: string;
59
- /** Records of the file's current life (after its last `delete`), in file order; store documents only. */
60
- history: LegacyHistoryRecord[];
61
- /** Set when the file could not be read as written: `invalid-source` (unparseable
62
- * frontmatter; `body` is the whole file and `frontmatter` null) or `invalid-history`
63
- * (its history log is unreadable; `history` is empty). */
64
- invalid?: {
65
- kind: 'invalid-source' | 'invalid-history';
66
- reason: string;
67
- };
68
- }
69
- export interface LegacyStoreRoot {
70
- root: string;
71
- owner: LegacyOwnerRef;
72
- docs: number;
73
- skipped?: 'duplicate-worktree';
74
- }
75
- export interface LegacyCorpus {
76
- docs: LegacyDoc[];
77
- storeRoots: LegacyStoreRoot[];
78
- /** Files or roots not read, with the reason; informational. */
79
- skipped: Array<{
80
- path: string;
81
- reason: string;
82
- }>;
83
- /** History logs whose document file no longer exists. */
84
- orphanHistory: number;
85
- /** Folders beside the given node folders with no node row. */
86
- orphanNodeDirs: number;
87
- /** Non-markdown files under node `context/` and `reports/` folders (not imported). */
88
- nonMarkdown: number;
89
- /** `injected-docs.json` ledgers found in node folders (not imported; the roll ends their sessions). */
90
- injectedDocs: number;
91
- }
@@ -1,3 +0,0 @@
1
- // Shapes of the frozen legacy reader. The reader turns every pre-canvas store
2
- // file into data for the import plan; it never opens canvas.db and never writes.
3
- export {};
@@ -1,102 +0,0 @@
1
- import { type CheckoutIdentity } from '../../core/graph/repo-sync/identity.js';
2
- import type { Privacy, RuleSpec } from '../../core/graph/types.js';
3
- import { type DocumentKind } from './fields.js';
4
- import type { LegacyCorpus, LegacyRoots } from './legacy/types.js';
5
- /** The store migrations every plan assumes already ran (the previous release's lanes). */
6
- export declare const CONVERGED_MARKER_IDS: readonly ["001-surfaces-frontmatter", "002-profile-project-memory", "003-repository-root-memory-identity"];
7
- export type OwnerType = 'person' | 'app' | 'profile' | 'repo' | 'node';
8
- export interface PlannedOwner {
9
- /** Stable key documents point at: `person`, `app:<handle>`, `profile:<id>`, `repo:<externalId>`, `node:<id>`. */
10
- key: string;
11
- type: OwnerType;
12
- handle: string;
13
- /** Repo identity (`ensureRepo`). */
14
- scheme?: 'git' | 'local-path';
15
- externalId?: string;
16
- /** A profile's owning app, as an owner key (`app:<handle>`). */
17
- ownerKey?: string;
18
- }
19
- export interface PlannedRevision {
20
- body: string;
21
- authorNodeId: string | null;
22
- rationale: string | null;
23
- createdAt: string;
24
- }
25
- export interface PlannedDocument {
26
- ownerKey: string;
27
- name: string;
28
- kind: DocumentKind;
29
- privacy: Privacy;
30
- preview: string;
31
- summary: string | null;
32
- whyItExists: string | null;
33
- unlisted: boolean;
34
- lintIgnore: unknown;
35
- extensions: unknown;
36
- rules: RuleSpec[];
37
- /** Oldest first; the last one is the head, whose body carries the pointer rewrite. */
38
- revisions: PlannedRevision[];
39
- sourcePath: string;
40
- }
41
- /** A stored-profile update (scoped-state `profiles.delivery_limits_json`): the legacy
42
- * profile.json `projects[].memory` caps, keyed by repo handle, merged over the row's limits. */
43
- export interface PlannedProfileLimits {
44
- profileId: string;
45
- deliveryLimits: Record<string, string>;
46
- }
47
- /** Something that stops the import. Only a runtime that skipped the previous
48
- * release's store migrations blocks; every other finding resolves itself. */
49
- export interface ImportBlocker {
50
- kind: 'marker';
51
- message: string;
52
- paths: string[];
53
- }
54
- /** One finding the plan resolved on its own, with what it did. */
55
- export interface ImportResolution {
56
- kind: 'invalid-source' | 'invalid-history' | 'name-clash' | 'repo-handle' | 'profile-handle' | 'repo-identity' | 'delivery-limit' | 'empty-preview';
57
- message: string;
58
- paths: string[];
59
- }
60
- export interface ImportReport {
61
- stores: LegacyCorpus['storeRoots'];
62
- counts: Record<string, number>;
63
- rewrites: Array<{
64
- path: string;
65
- from: string;
66
- to: string;
67
- }>;
68
- droppedFields: Array<{
69
- path: string;
70
- field: string;
71
- }>;
72
- skipped: LegacyCorpus['skipped'];
73
- /** Every clash or unreadable source the plan resolved, one line each. */
74
- resolutions: ImportResolution[];
75
- }
76
- export interface ImportPlan {
77
- owners: PlannedOwner[];
78
- documents: PlannedDocument[];
79
- profileLimits: PlannedProfileLimits[];
80
- blockers: ImportBlocker[];
81
- report: ImportReport;
82
- }
83
- export interface PlanContext {
84
- roots: LegacyRoots;
85
- /** Ids in `on-disk-migrations.json`, or null when it is absent. */
86
- markerIds: string[] | null;
87
- /** Repo identity of a git checkout root (repo-sync `identifyCheckout`). */
88
- repoIdentity: (root: string) => CheckoutIdentity;
89
- /** Owner objects already in canvas.db; a new handle must not take one of theirs. */
90
- existingOwners: Array<{
91
- type: string;
92
- handle: string;
93
- externalId: string | null;
94
- }>;
95
- /** Stored profile rows (scoped-state) with their current `delivery_limits`. */
96
- storedProfiles: Array<{
97
- id: string;
98
- deliveryLimits: Record<string, string>;
99
- }>;
100
- home?: string;
101
- }
102
- export declare function planImport(corpus: LegacyCorpus, ctx: PlanContext): ImportPlan;