@kevin0181/memoc 1.4.0 → 1.4.2
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/bin/cli.js +89 -2
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -263,6 +263,23 @@ function archiveLegacySystems(dir, mark) {
|
|
|
263
263
|
mark('move', `${path.relative(dir, systemsPath)} -> ${path.relative(dir, archivePath)}`);
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
+
function isDefaultLegacyWikiDirectory(dirPath) {
|
|
267
|
+
let entries = [];
|
|
268
|
+
try {
|
|
269
|
+
entries = fs.readdirSync(dirPath).filter(name => !name.startsWith('.'));
|
|
270
|
+
} catch {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
if (entries.length !== 1 || entries[0] !== 'README.md') return false;
|
|
274
|
+
|
|
275
|
+
const src = safeRead(path.join(dirPath, 'README.md'));
|
|
276
|
+
const name = path.basename(dirPath);
|
|
277
|
+
if (name === 'sources') return src.includes('# Sources') && src.includes('Provenance records');
|
|
278
|
+
if (name === 'topics') return src.includes('# Topics') && src.includes('Synthesized topic pages');
|
|
279
|
+
if (name === 'global') return src.includes('# Global') && src.includes('Project-wide principles');
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
|
|
266
283
|
function migrateKnowledgeWiki(dir, mark) {
|
|
267
284
|
const wikiDir = path.join(dir, '.memoc', 'wiki');
|
|
268
285
|
const knowledgeDir = path.join(wikiDir, 'knowledge');
|
|
@@ -283,6 +300,16 @@ function migrateKnowledgeWiki(dir, mark) {
|
|
|
283
300
|
try {
|
|
284
301
|
const st = fs.statSync(dest);
|
|
285
302
|
if (st.isFile() && isDefaultKnowledgeScaffold(dest)) fs.unlinkSync(dest);
|
|
303
|
+
else if (st.isDirectory() && fs.statSync(src).isDirectory()) {
|
|
304
|
+
if (isDefaultLegacyWikiDirectory(src)) {
|
|
305
|
+
fs.rmSync(src, { recursive: true, force: true });
|
|
306
|
+
mark('remove', `${path.relative(dir, src)} (legacy wiki scaffold)`);
|
|
307
|
+
} else {
|
|
308
|
+
const archived = movePathUnique(src, path.join(dir, '.memoc', 'raw', 'legacy-wiki-root', from));
|
|
309
|
+
mark('move', `${path.relative(dir, src)} -> ${path.relative(dir, archived)} (legacy wiki dir)`);
|
|
310
|
+
}
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
286
313
|
else continue;
|
|
287
314
|
} catch {
|
|
288
315
|
continue;
|
|
@@ -293,10 +320,48 @@ function migrateKnowledgeWiki(dir, mark) {
|
|
|
293
320
|
}
|
|
294
321
|
}
|
|
295
322
|
|
|
323
|
+
function migrateKnowledgeLayerLinks(filePath) {
|
|
324
|
+
if (!fs.existsSync(filePath)) return false;
|
|
325
|
+
const before = safeRead(filePath);
|
|
326
|
+
if (!before) return false;
|
|
327
|
+
|
|
328
|
+
let after = before;
|
|
329
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
330
|
+
|
|
331
|
+
if (/\/wiki\/knowledge\/(sources|glossary|questions|lint)\.md$/.test(normalized)) {
|
|
332
|
+
after = after
|
|
333
|
+
.replace(/\]\(index\.md\)/g, '](../index.md)')
|
|
334
|
+
.replace(/\]\(\.\.\/raw\/README\.md\)/g, '](../../raw/README.md)');
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (/\/wiki\/knowledge\/global\/README\.md$/.test(normalized)) {
|
|
338
|
+
after = after
|
|
339
|
+
.replace(/\]\(\.\.\/index\.md\)/g, '](../../index.md)')
|
|
340
|
+
.replace(/\]\(\.\.\/\.\.\/00-project-brief\.md\)/g, '](../../../00-project-brief.md)')
|
|
341
|
+
.replace(/\]\(\.\.\/\.\.\/06-project-rules\.md\)/g, '](../../../06-project-rules.md)');
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if (after === before) return false;
|
|
345
|
+
write(filePath, after);
|
|
346
|
+
return true;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function migrateRawKnowledgeLinks(filePath) {
|
|
350
|
+
if (!fs.existsSync(filePath)) return false;
|
|
351
|
+
const before = safeRead(filePath);
|
|
352
|
+
if (!before) return false;
|
|
353
|
+
const after = before
|
|
354
|
+
.replace(/\]\(\.\.\/wiki\/sources\/README\.md\)/g, '](../wiki/knowledge/sources/README.md)')
|
|
355
|
+
.replace(/\]\(\.\.\/\.\.\/wiki\/sources\/README\.md\)/g, '](../../wiki/knowledge/sources/README.md)');
|
|
356
|
+
if (after === before) return false;
|
|
357
|
+
write(filePath, after);
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
|
|
296
361
|
function isDefaultKnowledgeScaffold(filePath) {
|
|
297
362
|
const src = safeRead(filePath);
|
|
298
363
|
const name = path.basename(filePath);
|
|
299
|
-
if (name === 'sources.md') return src.includes('# Sources') && src.includes('_No sources recorded yet.
|
|
364
|
+
if (name === 'sources.md') return src.includes('# Sources') && src.includes('_No sources recorded yet.');
|
|
300
365
|
if (name === 'glossary.md') return src.includes('# Glossary') && src.includes('_No terms defined yet.');
|
|
301
366
|
if (name === 'questions.md') return src.includes('# Open Questions') && src.includes('_No open questions yet._');
|
|
302
367
|
if (name === 'lint.md') return src.includes('# Wiki Lint') && src.includes('_No issues found._');
|
|
@@ -2539,6 +2604,28 @@ function run(dir, forceUpdate, action = 'update') {
|
|
|
2539
2604
|
}
|
|
2540
2605
|
ensureWikiScaffoldLinks(memDir, mark);
|
|
2541
2606
|
|
|
2607
|
+
const knowledgeLayerFiles = [
|
|
2608
|
+
path.join(memDir, 'wiki/knowledge/sources.md'),
|
|
2609
|
+
path.join(memDir, 'wiki/knowledge/glossary.md'),
|
|
2610
|
+
path.join(memDir, 'wiki/knowledge/questions.md'),
|
|
2611
|
+
path.join(memDir, 'wiki/knowledge/lint.md'),
|
|
2612
|
+
path.join(memDir, 'wiki/knowledge/global/README.md'),
|
|
2613
|
+
];
|
|
2614
|
+
for (const fp of knowledgeLayerFiles) {
|
|
2615
|
+
if (migrateKnowledgeLayerLinks(fp)) mark('update', `${path.relative(dir, fp)} (wiki links)`);
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
const rawLinkFiles = [
|
|
2619
|
+
path.join(memDir, 'raw/README.md'),
|
|
2620
|
+
path.join(memDir, 'raw/files/README.md'),
|
|
2621
|
+
path.join(memDir, 'raw/urls/README.md'),
|
|
2622
|
+
path.join(memDir, 'raw/conversations/README.md'),
|
|
2623
|
+
path.join(memDir, 'raw/docs/README.md'),
|
|
2624
|
+
];
|
|
2625
|
+
for (const fp of rawLinkFiles) {
|
|
2626
|
+
if (migrateRawKnowledgeLinks(fp)) mark('update', `${path.relative(dir, fp)} (raw links)`);
|
|
2627
|
+
}
|
|
2628
|
+
|
|
2542
2629
|
const legacyReferenceFiles = [
|
|
2543
2630
|
path.join(memDir, '02-current-project-state.md'),
|
|
2544
2631
|
path.join(memDir, '04-handoff.md'),
|
|
@@ -2943,7 +3030,7 @@ ${warnings.length ? warnings.map(x => `- ${x}`).join('\n') : '_None._'}
|
|
|
2943
3030
|
|
|
2944
3031
|
## Related
|
|
2945
3032
|
|
|
2946
|
-
- [Wiki Index](index.md)
|
|
3033
|
+
- [Wiki Index](../index.md)
|
|
2947
3034
|
- [Sources](sources.md)
|
|
2948
3035
|
- [Topics](topics/README.md)
|
|
2949
3036
|
- [Open Questions](questions.md)
|