@north-light/cli 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.
- package/dist/api/client.d.ts +1 -2
- package/dist/api/client.js +3 -3
- package/dist/api/contract.d.ts +1 -1
- package/dist/api/contract.js +1 -1
- package/dist/api/dto/health.d.ts +0 -54
- package/dist/api/routes.d.ts +0 -1
- package/dist/api/routes.js +1 -1
- package/dist/build-root.d.ts +0 -3
- package/dist/build-root.js +1 -1
- package/dist/builtin-memory/internal/storage-tiers.md +3 -3
- package/dist/cli.js +8 -9
- package/dist/clients/attach/viewer.js +474 -474
- package/dist/commands/profile/new.js +1 -1
- package/dist/commands/profile/project.js +1 -1
- package/dist/commands/sys/branch.js +1 -1
- package/dist/commands/sys/daemon.js +1 -1
- package/dist/commands/sys.js +1 -1
- package/dist/core/bootstrap.js +1 -1
- package/dist/core/canvas/boot.d.ts +0 -25
- package/dist/core/canvas/boot.js +1 -1
- package/dist/core/canvas/executions.d.ts +0 -3
- package/dist/core/canvas/executions.js +1 -1
- package/dist/core/canvas/pid.d.ts +0 -10
- package/dist/core/canvas/pid.js +5 -5
- package/dist/core/directory/join.js +1 -1
- package/dist/core/grants/mirror.d.ts +0 -5
- package/dist/core/grants/mirror.js +6 -6
- package/dist/core/grants/sync.js +1 -1
- package/dist/core/human/page-schema.d.ts +1 -1
- package/dist/core/io.js +4 -4
- package/dist/core/layout.d.ts +0 -2
- package/dist/core/layout.js +2 -2
- package/dist/core/profiles/manifest.js +1 -1
- package/dist/core/profiles/project-dir.d.ts +3 -0
- package/dist/core/profiles/project-dir.js +1 -0
- package/dist/core/scoped-state/db.js +2 -2
- package/dist/daemon/api/handlers/daemon.js +1 -1
- package/dist/daemon/api/handlers/profiles.js +1 -1
- package/dist/daemon/api/map.d.ts +1 -6
- package/dist/daemon/api/map.js +2 -2
- package/dist/daemon/api/operations.js +1 -1
- package/dist/daemon/api/server.js +1 -1
- package/dist/daemon/control.d.ts +0 -8
- package/dist/daemon/crtrd.js +18 -20
- package/dist/daemon/manage.js +3 -3
- package/package.json +3 -3
- package/packages/crouter-api/dist/api/client.js +0 -3
- package/packages/crouter-api/dist/api/contract.js +1 -1
- package/packages/crouter-api/dist/api/routes.js +0 -1
- package/packages/crouter-api/dist/build-root.js +0 -9
- package/packages/crouter-api/dist/commands/profile/new.js +2 -2
- package/packages/crouter-api/dist/commands/profile/project.js +2 -1
- package/packages/crouter-api/dist/commands/sys/branch.js +1 -1
- package/packages/crouter-api/dist/commands/sys/daemon.js +1 -1
- package/packages/crouter-api/dist/commands/sys.js +1 -2
- package/packages/crouter-api/dist/core/canvas/executions.js +1 -17
- package/packages/crouter-api/dist/core/canvas/pid.js +0 -16
- package/packages/crouter-api/dist/core/directory/join.js +18 -1
- package/packages/crouter-api/dist/core/grants/mirror.js +0 -7
- package/packages/crouter-api/dist/core/grants/sync.js +2 -2
- package/packages/crouter-api/dist/core/io.js +0 -5
- package/packages/crouter-api/dist/core/layout.js +2 -19
- package/packages/crouter-api/dist/core/profiles/manifest.js +12 -18
- package/packages/crouter-api/dist/core/profiles/project-dir.js +20 -0
- package/packages/crouter-api/dist/daemon/api/map.js +0 -16
- package/packages/crouter-api/dist/daemon/api/operations.js +0 -1
- package/packages/crouter-api/dist/daemon/manage.js +1 -1
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +14 -14
- package/scripts/install-runtime.mjs +1 -30
- package/dist/commands/sys/migrate.d.ts +0 -1
- package/dist/commands/sys/migrate.js +0 -1
- package/dist/core/canvas/import-sqlite.d.ts +0 -46
- package/dist/core/canvas/import-sqlite.js +0 -19
- package/dist/core/canvas/migrations.d.ts +0 -16
- package/dist/core/canvas/migrations.js +0 -1073
- package/dist/core/feed/inbox-migrate.d.ts +0 -11
- package/dist/core/feed/inbox-migrate.js +0 -3
- package/dist/core/graph/bodies-boot-copy.d.ts +0 -28
- package/dist/core/graph/bodies-boot-copy.js +0 -1
- package/dist/core/layout-migrate/index.d.ts +0 -38
- package/dist/core/layout-migrate/index.js +0 -4
- package/dist/core/layout-migrate/loose-keys.d.ts +0 -2
- package/dist/core/layout-migrate/loose-keys.js +0 -1
- package/dist/core/layout-migrate/paths.d.ts +0 -30
- package/dist/core/layout-migrate/paths.js +0 -1
- package/dist/core/layout-migrate/stored-paths.d.ts +0 -9
- package/dist/core/layout-migrate/stored-paths.js +0 -11
- package/dist/core/layout-migrate/stores.d.ts +0 -30
- package/dist/core/layout-migrate/stores.js +0 -3
- package/dist/core/scoped-state/migrate.d.ts +0 -15
- package/dist/core/scoped-state/migrate.js +0 -3
- package/dist/daemon/boot-migrations.d.ts +0 -14
- package/dist/daemon/boot-migrations.js +0 -1
- package/dist/migrations/004-canvas-documents/apply.d.ts +0 -8
- package/dist/migrations/004-canvas-documents/apply.js +0 -1
- package/dist/migrations/004-canvas-documents/index.d.ts +0 -16
- package/dist/migrations/004-canvas-documents/index.js +0 -2
- package/dist/migrations/004-canvas-documents/legacy/discover.d.ts +0 -16
- package/dist/migrations/004-canvas-documents/legacy/discover.js +0 -1
- package/dist/migrations/004-canvas-documents/legacy/history.d.ts +0 -5
- package/dist/migrations/004-canvas-documents/legacy/history.js +0 -2
- package/dist/migrations/004-canvas-documents/legacy/nested.d.ts +0 -7
- package/dist/migrations/004-canvas-documents/legacy/nested.js +0 -1
- package/dist/migrations/004-canvas-documents/legacy/parse.d.ts +0 -14
- package/dist/migrations/004-canvas-documents/legacy/parse.js +0 -1
- package/dist/migrations/004-canvas-documents/legacy/types.d.ts +0 -91
- package/dist/migrations/004-canvas-documents/legacy/types.js +0 -0
- package/dist/migrations/004-canvas-documents/legacy-edges.d.ts +0 -6
- package/dist/migrations/004-canvas-documents/legacy-edges.js +0 -18
- package/dist/migrations/004-canvas-documents/plan.d.ts +0 -102
- package/dist/migrations/004-canvas-documents/plan.js +0 -3
- package/dist/migrations/004-canvas-documents/pointers.d.ts +0 -23
- package/dist/migrations/004-canvas-documents/pointers.js +0 -4
- package/dist/migrations/activation.d.ts +0 -17
- package/dist/migrations/activation.js +0 -2
- package/packages/crouter-api/dist/commands/sys/migrate.js +0 -79
- package/packages/crouter-api/dist/core/layout-migrate/index.js +0 -523
- package/packages/crouter-api/dist/core/layout-migrate/paths.js +0 -118
- package/packages/crouter-api/dist/core/layout-migrate/stored-paths.js +0 -424
- package/packages/crouter-api/dist/core/layout-migrate/stores.js +0 -543
- package/packages/crouter-api/dist/core/locked-file.js +0 -121
- package/packages/crouter-api/dist/core/scoped-state/db.js +0 -271
- package/packages/crouter-api/dist/core/scoped-state/legacy-profiles.js +0 -65
- package/packages/crouter-api/dist/core/scoped-state/migrate.js +0 -332
- package/packages/crouter-api/dist/core/scoped-state/schema.js +0 -52
- package/packages/crouter-api/dist/migrations/004-canvas-documents/apply.js +0 -113
- package/packages/crouter-api/dist/migrations/004-canvas-documents/index.js +0 -89
- package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/discover.js +0 -251
- package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/history.js +0 -37
- package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/nested.js +0 -37
- package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/parse.js +0 -24
- package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/types.js +0 -3
- package/packages/crouter-api/dist/migrations/004-canvas-documents/plan.js +0 -410
- package/packages/crouter-api/dist/migrations/004-canvas-documents/pointers.js +0 -95
- package/packages/crouter-api/dist/migrations/activation.js +0 -46
|
@@ -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,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,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,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
|
-
}
|