mdkg 0.4.2 → 0.5.1

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 (70) hide show
  1. package/CHANGELOG.md +88 -15
  2. package/CLI_COMMAND_MATRIX.md +74 -5
  3. package/README.md +30 -2
  4. package/dist/cli.js +132 -5
  5. package/dist/command-contract.json +778 -16
  6. package/dist/commands/archive.js +196 -42
  7. package/dist/commands/bundle.js +180 -44
  8. package/dist/commands/capability.js +1 -0
  9. package/dist/commands/checkpoint.js +6 -5
  10. package/dist/commands/event_support.js +16 -7
  11. package/dist/commands/fix.js +11 -8
  12. package/dist/commands/git.js +41 -10
  13. package/dist/commands/goal.js +23 -23
  14. package/dist/commands/graph.js +64 -10
  15. package/dist/commands/handoff.js +4 -2
  16. package/dist/commands/init.js +28 -23
  17. package/dist/commands/loop.js +1668 -0
  18. package/dist/commands/loop_descriptors.js +219 -0
  19. package/dist/commands/mcp.js +101 -11
  20. package/dist/commands/new.js +49 -3
  21. package/dist/commands/pack.js +14 -7
  22. package/dist/commands/search.js +10 -1
  23. package/dist/commands/skill.js +12 -9
  24. package/dist/commands/skill_mirror.js +39 -31
  25. package/dist/commands/subgraph.js +59 -26
  26. package/dist/commands/task.js +77 -4
  27. package/dist/commands/upgrade.js +13 -15
  28. package/dist/commands/validate.js +20 -7
  29. package/dist/commands/work.js +44 -26
  30. package/dist/commands/workspace.js +10 -4
  31. package/dist/core/config.js +45 -17
  32. package/dist/core/filesystem_authority.js +281 -0
  33. package/dist/core/project_db_events.js +4 -0
  34. package/dist/core/project_db_materializer.js +2 -0
  35. package/dist/core/project_db_migrations.js +238 -181
  36. package/dist/core/project_db_snapshot.js +64 -14
  37. package/dist/core/workspace_path.js +7 -0
  38. package/dist/graph/archive_integrity.js +1 -1
  39. package/dist/graph/capabilities_index_cache.js +4 -1
  40. package/dist/graph/frontmatter.js +38 -0
  41. package/dist/graph/goal_scope.js +4 -1
  42. package/dist/graph/index_cache.js +37 -7
  43. package/dist/graph/loop_bindings.js +39 -0
  44. package/dist/graph/node.js +209 -1
  45. package/dist/graph/node_body.js +52 -6
  46. package/dist/graph/skills_index_cache.js +41 -6
  47. package/dist/graph/skills_indexer.js +5 -2
  48. package/dist/graph/sqlite_index.js +118 -105
  49. package/dist/graph/subgraphs.js +142 -5
  50. package/dist/graph/validate_graph.js +109 -13
  51. package/dist/graph/workspace_files.js +39 -9
  52. package/dist/init/AGENT_START.md +16 -0
  53. package/dist/init/CLI_COMMAND_MATRIX.md +14 -0
  54. package/dist/init/config.json +7 -1
  55. package/dist/init/init-manifest.json +49 -4
  56. package/dist/init/skills/default/pursue-mdkg-loop/SKILL.md +150 -0
  57. package/dist/init/templates/default/loop.md +160 -0
  58. package/dist/init/templates/loops/backend-api-cli-bloat-audit.loop.md +117 -0
  59. package/dist/init/templates/loops/design-frontend-ux-audit.loop.md +117 -0
  60. package/dist/init/templates/loops/duplicate-code-and-linting-audit.loop.md +114 -0
  61. package/dist/init/templates/loops/security-audit.loop.md +140 -0
  62. package/dist/init/templates/loops/tech-stack-best-practices-audit.loop.md +116 -0
  63. package/dist/init/templates/loops/test-ci-skill-infrastructure-audit.loop.md +116 -0
  64. package/dist/init/templates/loops/user-story-audit-and-recommendations.loop.md +116 -0
  65. package/dist/pack/order.js +3 -1
  66. package/dist/pack/pack.js +139 -6
  67. package/dist/templates/loader.js +9 -3
  68. package/dist/util/lock.js +10 -9
  69. package/dist/util/zip.js +163 -9
  70. package/package.json +8 -4
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.runInitCommand = runInitCommand;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
+ const filesystem_authority_1 = require("../core/filesystem_authority");
9
10
  const config_1 = require("../core/config");
10
11
  const migrate_1 = require("../core/migrate");
11
12
  const errors_1 = require("../util/errors");
@@ -55,12 +56,12 @@ function recordSkipped(root, dest, stats) {
55
56
  stats.skippedPaths.push(displayPath(root, dest));
56
57
  }
57
58
  function copySeedFile(root, src, dest, force, stats) {
58
- if (fs_1.default.existsSync(dest) && !force) {
59
+ const relativePath = displayPath(root, dest);
60
+ if ((0, filesystem_authority_1.containedPathExists)({ root, relativePath }) && !force) {
59
61
  recordSkipped(root, dest, stats);
60
62
  return;
61
63
  }
62
- fs_1.default.mkdirSync(path_1.default.dirname(dest), { recursive: true });
63
- fs_1.default.copyFileSync(src, dest);
64
+ (0, filesystem_authority_1.atomicReplaceContainedFile)({ root, relativePath }, fs_1.default.readFileSync(src));
64
65
  recordCreated(root, dest, stats);
65
66
  }
66
67
  function copySeedDir(root, srcDir, destDir, force, stats) {
@@ -74,8 +75,11 @@ function copySeedDir(root, srcDir, destDir, force, stats) {
74
75
  copySeedFile(root, filePath, destPath, force, stats);
75
76
  }
76
77
  }
77
- function appendIgnoreEntries(filePath, entries) {
78
- const raw = fs_1.default.existsSync(filePath) ? fs_1.default.readFileSync(filePath, "utf8") : "";
78
+ function appendIgnoreEntries(root, filePath, entries) {
79
+ const relativePath = displayPath(root, filePath);
80
+ const raw = (0, filesystem_authority_1.containedPathExists)({ root, relativePath })
81
+ ? (0, filesystem_authority_1.readContainedFile)({ root, relativePath })
82
+ : "";
79
83
  const lines = raw.split(/\r?\n/);
80
84
  const existing = new Set(lines.map((line) => line.trim()).filter(Boolean));
81
85
  const additions = entries.filter((entry) => !existing.has(entry));
@@ -84,17 +88,16 @@ function appendIgnoreEntries(filePath, entries) {
84
88
  }
85
89
  const suffix = raw.length === 0 || raw.endsWith("\n") ? "" : "\n";
86
90
  const updated = `${raw}${suffix}${additions.join("\n")}\n`;
87
- fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
88
- fs_1.default.writeFileSync(filePath, updated, "utf8");
91
+ (0, filesystem_authority_1.atomicReplaceContainedFile)({ root, relativePath }, updated);
89
92
  return true;
90
93
  }
91
94
  function writeFileIfMissing(root, filePath, content, force, stats) {
92
- if (fs_1.default.existsSync(filePath) && !force) {
95
+ const relativePath = displayPath(root, filePath);
96
+ if ((0, filesystem_authority_1.containedPathExists)({ root, relativePath }) && !force) {
93
97
  recordSkipped(root, filePath, stats);
94
98
  return;
95
99
  }
96
- fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
97
- fs_1.default.writeFileSync(filePath, content, "utf8");
100
+ (0, filesystem_authority_1.atomicReplaceContainedFile)({ root, relativePath }, content);
98
101
  recordCreated(root, filePath, stats);
99
102
  }
100
103
  function soulTemplate(created) {
@@ -300,8 +303,11 @@ function parseCoreList(raw) {
300
303
  }
301
304
  return { header, ids };
302
305
  }
303
- function ensureCorePins(coreListPath, requiredPins) {
304
- const raw = fs_1.default.existsSync(coreListPath) ? fs_1.default.readFileSync(coreListPath, "utf8") : "";
306
+ function ensureCorePins(root, coreListPath, requiredPins) {
307
+ const relativePath = displayPath(root, coreListPath);
308
+ const raw = (0, filesystem_authority_1.containedPathExists)({ root, relativePath })
309
+ ? (0, filesystem_authority_1.readContainedFile)({ root, relativePath })
310
+ : "";
305
311
  const { header, ids } = parseCoreList(raw);
306
312
  const seen = new Set();
307
313
  const dedupedExisting = [];
@@ -321,8 +327,7 @@ function ensureCorePins(coreListPath, requiredPins) {
321
327
  normalizedHeader.pop();
322
328
  }
323
329
  const output = [...normalizedHeader, "", ...finalIds, ""].join("\n");
324
- fs_1.default.mkdirSync(path_1.default.dirname(coreListPath), { recursive: true });
325
- fs_1.default.writeFileSync(coreListPath, output, "utf8");
330
+ (0, filesystem_authority_1.atomicReplaceContainedFile)({ root, relativePath }, output);
326
331
  }
327
332
  function refreshManifestHash(root, manifest, relPath) {
328
333
  const entry = manifest.files.find((file) => file.path === relPath);
@@ -419,9 +424,9 @@ function runInitCommand(options) {
419
424
  };
420
425
  const mdkgDir = path_1.default.join(root, ".mdkg");
421
426
  try {
422
- fs_1.default.mkdirSync(mdkgDir, { recursive: true });
423
- fs_1.default.mkdirSync(path_1.default.join(mdkgDir, "work"), { recursive: true });
424
- fs_1.default.mkdirSync(path_1.default.join(mdkgDir, "design"), { recursive: true });
427
+ (0, filesystem_authority_1.ensureContainedDirectory)({ root, relativePath: ".mdkg" });
428
+ (0, filesystem_authority_1.ensureContainedDirectory)({ root, relativePath: ".mdkg/work" });
429
+ (0, filesystem_authority_1.ensureContainedDirectory)({ root, relativePath: ".mdkg/design" });
425
430
  copySeedFile(root, seedConfig, path_1.default.join(mdkgDir, "config.json"), force, stats);
426
431
  copySeedFile(root, seedReadme, path_1.default.join(mdkgDir, "README.md"), force, stats);
427
432
  copySeedDir(root, seedCore, path_1.default.join(mdkgDir, "core"), force, stats);
@@ -446,8 +451,8 @@ function runInitCommand(options) {
446
451
  const registryPath = path_1.default.join(skillsDir, "registry.md");
447
452
  const eventsDir = path_1.default.join(mdkgDir, "work", "events");
448
453
  const eventsPath = path_1.default.join(eventsDir, "events.jsonl");
449
- fs_1.default.mkdirSync(skillsDir, { recursive: true });
450
- fs_1.default.mkdirSync(eventsDir, { recursive: true });
454
+ (0, filesystem_authority_1.ensureContainedDirectory)({ root, relativePath: ".mdkg/skills" });
455
+ (0, filesystem_authority_1.ensureContainedDirectory)({ root, relativePath: ".mdkg/work/events" });
451
456
  copySeedDir(root, seedDefaultSkills, skillsDir, force, stats);
452
457
  if (!fs_1.default.existsSync(seedSoul)) {
453
458
  writeFileIfMissing(root, soulPath, soulTemplate(today), force, stats);
@@ -463,7 +468,7 @@ function runInitCommand(options) {
463
468
  writeFileIfMissing(root, eventsPath, seededInitEvent(new Date().toISOString()), force, stats);
464
469
  }
465
470
  const coreListPath = path_1.default.join(mdkgDir, "core", "core.md");
466
- ensureCorePins(coreListPath, [SOUL_PIN_ID, COLLABORATION_PIN_ID, HUMAN_PIN_ID]);
471
+ ensureCorePins(root, coreListPath, [SOUL_PIN_ID, COLLABORATION_PIN_ID, HUMAN_PIN_ID]);
467
472
  refreshManifestHash(root, seedManifest, ".mdkg/core/core.md");
468
473
  ensureCreatedCoreManifestEntry(root, seedManifest, ".mdkg/core/SOUL.md", stats);
469
474
  ensureCreatedCoreManifestEntry(root, seedManifest, ".mdkg/core/COLLABORATION.md", stats);
@@ -490,7 +495,7 @@ function runInitCommand(options) {
490
495
  const shouldUpdateNpmignore = Boolean(options.updateNpmignore || !noUpdateIgnores);
491
496
  try {
492
497
  if (shouldUpdateGitignore) {
493
- if (appendIgnoreEntries(path_1.default.join(root, ".gitignore"), [
498
+ if (appendIgnoreEntries(root, path_1.default.join(root, ".gitignore"), [
494
499
  ".mdkg/index/*.json",
495
500
  ".mdkg/index/*.tmp",
496
501
  ".mdkg/index/*.lock",
@@ -508,12 +513,12 @@ function runInitCommand(options) {
508
513
  }
509
514
  }
510
515
  if (shouldUpdateNpmignore) {
511
- if (appendIgnoreEntries(path_1.default.join(root, ".npmignore"), [".mdkg/", ".mdkg/index/", ".mdkg/pack/"])) {
516
+ if (appendIgnoreEntries(root, path_1.default.join(root, ".npmignore"), [".mdkg/", ".mdkg/index/", ".mdkg/pack/"])) {
512
517
  stats.ignoreFilesUpdated.push(".npmignore");
513
518
  }
514
519
  }
515
520
  if (options.updateDockerignore) {
516
- if (appendIgnoreEntries(path_1.default.join(root, ".dockerignore"), [".mdkg/"])) {
521
+ if (appendIgnoreEntries(root, path_1.default.join(root, ".dockerignore"), [".mdkg/"])) {
517
522
  stats.ignoreFilesUpdated.push(".dockerignore");
518
523
  }
519
524
  }