mdkg 0.3.6 → 0.3.8

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 (68) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/CLI_COMMAND_MATRIX.md +132 -24
  3. package/README.md +80 -25
  4. package/dist/cli.js +193 -36
  5. package/dist/command-contract.json +882 -122
  6. package/dist/commands/bundle.js +2 -0
  7. package/dist/commands/capability.js +1 -0
  8. package/dist/commands/checkpoint.js +139 -1
  9. package/dist/commands/db.js +8 -0
  10. package/dist/commands/doctor.js +7 -7
  11. package/dist/commands/format.js +155 -0
  12. package/dist/commands/goal.js +60 -0
  13. package/dist/commands/graph.js +148 -0
  14. package/dist/commands/handoff.js +301 -0
  15. package/dist/commands/mcp.js +9 -0
  16. package/dist/commands/new.js +12 -3
  17. package/dist/commands/pack.js +3 -1
  18. package/dist/commands/query_output.js +2 -0
  19. package/dist/commands/show.js +8 -0
  20. package/dist/commands/spec.js +76 -17
  21. package/dist/commands/status.js +1 -0
  22. package/dist/commands/subgraph.js +7 -4
  23. package/dist/commands/task.js +2 -0
  24. package/dist/commands/upgrade.js +128 -3
  25. package/dist/commands/validate.js +268 -6
  26. package/dist/commands/work.js +176 -5
  27. package/dist/core/project_db_queue_contract.js +101 -0
  28. package/dist/graph/agent_file_types.js +59 -20
  29. package/dist/graph/capabilities_indexer.js +45 -3
  30. package/dist/graph/edges.js +15 -0
  31. package/dist/graph/frontmatter.js +4 -1
  32. package/dist/graph/indexer.js +13 -0
  33. package/dist/graph/node.js +12 -1
  34. package/dist/graph/sqlite_index.js +2 -0
  35. package/dist/graph/subgraphs.js +2 -0
  36. package/dist/graph/template_schema.js +37 -17
  37. package/dist/graph/validate_graph.js +16 -5
  38. package/dist/graph/visibility.js +6 -0
  39. package/dist/init/AGENT_START.md +9 -6
  40. package/dist/init/CLI_COMMAND_MATRIX.md +50 -16
  41. package/dist/init/README.md +26 -9
  42. package/dist/init/init-manifest.json +67 -12
  43. package/dist/init/templates/default/bug.md +2 -0
  44. package/dist/init/templates/default/chk.md +3 -0
  45. package/dist/init/templates/default/epic.md +2 -0
  46. package/dist/init/templates/default/feat.md +2 -0
  47. package/dist/init/templates/default/goal.md +3 -0
  48. package/dist/init/templates/default/manifest.md +45 -0
  49. package/dist/init/templates/default/spike.md +2 -0
  50. package/dist/init/templates/default/task.md +2 -0
  51. package/dist/init/templates/default/test.md +2 -0
  52. package/dist/init/templates/specs/agent.MANIFEST.md +80 -0
  53. package/dist/init/templates/specs/api.MANIFEST.md +33 -0
  54. package/dist/init/templates/specs/base.MANIFEST.md +120 -0
  55. package/dist/init/templates/specs/capability.MANIFEST.md +45 -0
  56. package/dist/init/templates/specs/integration.MANIFEST.md +25 -0
  57. package/dist/init/templates/specs/model.MANIFEST.md +21 -0
  58. package/dist/init/templates/specs/project.MANIFEST.md +39 -0
  59. package/dist/init/templates/specs/runtime-agent.MANIFEST.md +49 -0
  60. package/dist/init/templates/specs/runtime-image.MANIFEST.md +21 -0
  61. package/dist/init/templates/specs/tool.MANIFEST.md +25 -0
  62. package/dist/pack/export_json.js +20 -8
  63. package/dist/pack/export_md.js +15 -4
  64. package/dist/pack/export_xml.js +9 -4
  65. package/dist/pack/metrics.js +12 -4
  66. package/dist/pack/pack.js +9 -1
  67. package/dist/util/argparse.js +3 -0
  68. package/package.json +21 -3
package/dist/cli.js CHANGED
@@ -15,6 +15,7 @@ const list_1 = require("./commands/list");
15
15
  const search_1 = require("./commands/search");
16
16
  const show_1 = require("./commands/show");
17
17
  const pack_1 = require("./commands/pack");
18
+ const handoff_1 = require("./commands/handoff");
18
19
  const next_1 = require("./commands/next");
19
20
  const validate_1 = require("./commands/validate");
20
21
  const format_1 = require("./commands/format");
@@ -67,12 +68,14 @@ function printUsage(log) {
67
68
  log(" list List nodes with filters");
68
69
  log(" search Search nodes by query");
69
70
  log(" pack Generate a context pack");
71
+ log(" handoff Create sanitized agent handoff prompts from graph context");
70
72
  log(" skill Create, list, show, search, and validate skills");
71
73
  log(" capability List, search, show, and resolve cached capability surfaces");
72
- log(" spec List, show, and validate optional SPEC.md capability records");
74
+ log(" manifest List, show, and validate MANIFEST.md/SPEC.md capability records");
75
+ log(" spec Legacy alias for `mdkg manifest` during the compatibility bridge");
73
76
  log(" archive Add, list, show, verify, and compress archive sidecars");
74
77
  log(" bundle Create, list, show, and verify full graph snapshot bundles");
75
- log(" graph Clone and fork whole mdkg graphs");
78
+ log(" graph Clone, fork, import, and inspect mdkg graph references");
76
79
  log(" subgraph Register, audit, plan, sync, materialize, and verify read-only child graph snapshots");
77
80
  log(" work Create and update work contracts, orders, receipts, and artifacts");
78
81
  log(" goal Inspect and advance recursive goal nodes");
@@ -143,7 +146,8 @@ function printNewHelp(log) {
143
146
  log("\nTypes:");
144
147
  log(" rule prd edd dec prop goal epic feat task bug spike checkpoint test");
145
148
  log("\nAgent workflow file types:");
146
- log(" spec work work_order receipt feedback dispute proposal");
149
+ log(" manifest work work_order receipt feedback dispute proposal");
150
+ log(" spec is a legacy alias for manifest and emits MANIFEST.md during the compatibility bridge.");
147
151
  log(" Use --id <portable-id> with these types for semantic ids like agent.image-worker.");
148
152
  log(" Use `mdkg archive add` for archive sidecars instead of `mdkg new archive`.");
149
153
  log("\nOptions:");
@@ -161,7 +165,8 @@ function printNewHelp(log) {
161
165
  log(" --links --artifacts --refs --aliases --owners --cases --supersedes");
162
166
  log(" --owners <owner,owner,...> Owners");
163
167
  log("\nNotes:");
164
- log(" spec/work scaffold as validation-clean docs; relational workflow docs need real refs.");
168
+ log(" manifest/work scaffold as validation-clean docs; relational workflow docs need real refs.");
169
+ log(" mdkg new spec is deprecated; use mdkg new manifest for new reusable capability manifests.");
165
170
  log(" spike creates actionable research/planning work; use `mdkg task ...` for lifecycle.");
166
171
  log(" record spike research evidence by editing the Markdown body sections.");
167
172
  log(" spikes do not run web search, create follow-up nodes, generate SKILL.md, or expose `mdkg spike ...`.");
@@ -236,8 +241,10 @@ function printDbHelp(log, subcommand) {
236
241
  log(" mdkg db queue stats [queue] [--json]");
237
242
  log(" mdkg db queue list <queue> [--status ready|leased|acked|dead_letter|all] [--limit <n>] [--json]");
238
243
  log(" mdkg db queue show <queue> <message-id> [--json]");
244
+ log(" mdkg db queue contract [--json]");
239
245
  log("\nSemantics:");
240
246
  log(" - queues are durable local delivery state, not canonical event history");
247
+ log(" - contract is read-only adapter metadata and does not require an initialized project DB");
241
248
  log(" - paused queues reject enqueue and claim");
242
249
  log(" - ack, fail, dead-letter, and release-expired are allowed while paused so leased work can settle");
243
250
  log(" - no raw SQL or hosted queue dependency is exposed");
@@ -258,6 +265,7 @@ function printDbHelp(log, subcommand) {
258
265
  log(" mdkg db queue ack|fail|dead-letter <queue> <message-id> --lease-owner <owner> [--json]");
259
266
  log(" mdkg db queue pause|resume <queue> [--json]");
260
267
  log(" mdkg db queue stats|list|show ... [--json]");
268
+ log(" mdkg db queue contract [--json]");
261
269
  log(" mdkg db snapshot seal [--queue-policy drain|paused] [--json]");
262
270
  log(" mdkg db snapshot verify [--json]");
263
271
  log(" mdkg db snapshot status [--json]");
@@ -326,12 +334,14 @@ function printPackHelp(log) {
326
334
  log(" --list-profiles List built-in pack profiles and exit");
327
335
  log("\nAdvanced shaping / debug flags:");
328
336
  log(" --depth --edges --strip-code --max-code-lines --max-chars --max-lines --max-tokens");
337
+ log(" --edges accepts parent, epic, relates, blocked_by, blocks, prev, next, context_refs, evidence_refs");
329
338
  log(" --truncation-report --stats-out");
330
339
  log("\nExamples:");
331
340
  log(" mdkg pack --list-profiles");
332
341
  log(" mdkg pack task-1");
333
342
  log(" mdkg pack task-1 --profile concise --dry-run --stats");
334
343
  log(" mdkg pack task-1 --visibility public --dry-run");
344
+ log(" mdkg pack task-1 --edges context_refs,evidence_refs --format json");
335
345
  log(" mdkg pack task-1 --skills auto --skills-depth full");
336
346
  log(" mdkg pack epic-2 --format json --profile headers");
337
347
  printGlobalOptions(log);
@@ -347,6 +357,19 @@ function printPackProfiles(log) {
347
357
  }
348
358
  }
349
359
  }
360
+ function printHandoffHelp(log) {
361
+ log("Usage:");
362
+ log(" mdkg handoff create <id-or-qid> [--ws <alias>] [--depth <n>] [--out <path>] [--json]");
363
+ log("\nPurpose:");
364
+ log(" - create a sanitized, copy-ready agent handoff from mdkg graph context");
365
+ log(" - summarize goal/work state, included pack nodes, latest checkpoint, boundaries, required checks, and next actions");
366
+ log(" - include raw secret, prompt, token, or payload marker warnings without copying raw node bodies into the handoff");
367
+ log(" - use pack traversal with context_refs and evidence_refs for background and proof nodes");
368
+ log("\nBoundaries:");
369
+ log(" - handoff create does not execute work, mutate graph nodes, or generate detailed node content");
370
+ log(" - --out must stay inside the repo root");
371
+ printGlobalOptions(log);
372
+ }
350
373
  function printSkillHelp(log, subcommand) {
351
374
  switch ((subcommand ?? "").toLowerCase()) {
352
375
  case "new":
@@ -449,38 +472,54 @@ function printCapabilityHelp(log, subcommand) {
449
472
  printGlobalOptions(log);
450
473
  }
451
474
  }
452
- function printSpecHelp(log, subcommand) {
475
+ function printSpecHelp(log, subcommand, surface = "spec") {
476
+ const command = surface === "manifest" ? "manifest" : "spec";
477
+ const legacyNote = surface === "spec"
478
+ ? " `mdkg spec` is the legacy alias for `mdkg manifest` during the compatibility bridge."
479
+ : undefined;
453
480
  switch ((subcommand ?? "").toLowerCase()) {
454
481
  case "list":
455
482
  log("Usage:");
456
- log(" mdkg spec list [--json]");
483
+ log(` mdkg ${command} list [--json]`);
457
484
  log("\nNotes:");
458
- log(" SPEC.md is optional and declares reusable capability surfaces.");
485
+ log(" MANIFEST.md is canonical; SPEC.md remains a legacy alias for reusable capability surfaces.");
486
+ if (legacyNote) {
487
+ log(legacyNote);
488
+ }
459
489
  printGlobalOptions(log);
460
490
  return;
461
491
  case "show":
462
492
  log("Usage:");
463
- log(" mdkg spec show <id-or-qid-or-alias> [--json]");
493
+ log(` mdkg ${command} show <id-or-qid-or-alias> [--json]`);
464
494
  log("\nNotes:");
465
- log(" Shows one optional SPEC.md capability record from the capability index.");
495
+ log(" Shows one MANIFEST.md/SPEC.md capability record from the capability index.");
496
+ if (legacyNote) {
497
+ log(legacyNote);
498
+ }
466
499
  printGlobalOptions(log);
467
500
  return;
468
501
  case "validate":
469
502
  log("Usage:");
470
- log(" mdkg spec validate [<id-or-qid-or-alias>] [--json]");
503
+ log(` mdkg ${command} validate [<id-or-qid-or-alias>] [--json]`);
471
504
  log("\nNotes:");
472
- log(" With no reference, validates the graph and all optional SPEC.md capability records.");
473
- log(" With a reference, also ensures that specific SPEC.md capability exists.");
505
+ log(" With no reference, validates the graph and all MANIFEST.md/SPEC.md capability records.");
506
+ log(" With a reference, also ensures that the specific manifest capability exists.");
507
+ if (legacyNote) {
508
+ log(legacyNote);
509
+ }
474
510
  printGlobalOptions(log);
475
511
  return;
476
512
  default:
477
513
  log("Usage:");
478
- log(" mdkg spec list [--json]");
479
- log(" mdkg spec show <id-or-qid-or-alias> [--json]");
480
- log(" mdkg spec validate [<id-or-qid-or-alias>] [--json]");
514
+ log(` mdkg ${command} list [--json]`);
515
+ log(` mdkg ${command} show <id-or-qid-or-alias> [--json]`);
516
+ log(` mdkg ${command} validate [<id-or-qid-or-alias>] [--json]`);
481
517
  log("\nNotes:");
482
- log(" SPEC.md is optional and reusable-capability oriented.");
483
- log(" Use `mdkg capability ...` for broader skill, SPEC.md, WORK.md, core-doc, and design-doc discovery.");
518
+ log(" MANIFEST.md is canonical and reusable-capability oriented; SPEC.md remains a legacy alias.");
519
+ if (legacyNote) {
520
+ log(legacyNote);
521
+ }
522
+ log(" Use `mdkg capability ...` for broader skill, MANIFEST.md/SPEC.md, WORK.md, core-doc, and design-doc discovery.");
484
523
  printGlobalOptions(log);
485
524
  }
486
525
  }
@@ -586,14 +625,24 @@ function printGraphHelp(log, subcommand) {
586
625
  log(" - rewrites canonical numeric IDs and structured graph links deterministically");
587
626
  log(" - --select-goal requires --start-goal; on apply it activates the imported start goal, pauses competing active root goals, validates, then writes selected-goal state");
588
627
  break;
628
+ case "refs":
629
+ log("Usage:");
630
+ log(" mdkg graph refs <id-or-qid> [--ws <alias>] [--json]");
631
+ log("\nNotes:");
632
+ log(" - read-only summary of inbound and outbound graph references");
633
+ log(" - reports scope_refs, context_refs, evidence_refs, blockers, related refs, and structural links");
634
+ log(" - subgraph qids are inspectable but remain read-only");
635
+ break;
589
636
  default:
590
637
  log("Usage:");
591
638
  log(" mdkg graph clone <source-bundle-or-mdkg-dir> --target <path> [--json]");
592
639
  log(" mdkg graph fork <source-bundle-or-mdkg-dir> --target <path> [--start-goal <goal-id>] [--json]");
593
640
  log(" mdkg graph import-template <source-bundle-or-mdkg-dir> [--start-goal <goal-id>] [--select-goal] [--id-prefix <prefix>] [--dry-run] [--apply] [--json]");
641
+ log(" mdkg graph refs <id-or-qid> [--ws <alias>] [--json]");
594
642
  log("\nNotes:");
595
643
  log(" - graph clone/fork create authored graph state in separate target directories and preserve IDs");
596
644
  log(" - graph import-template imports template work nodes into the current graph with rewritten IDs");
645
+ log(" - graph refs is read-only and explains local plus subgraph graph relationships");
597
646
  log(" - subgraphs remain read-only bundle projections for orchestration context");
598
647
  }
599
648
  printGlobalOptions(log);
@@ -691,7 +740,7 @@ function printWorkHelp(log, subcommand) {
691
740
  log("\nExample:");
692
741
  log(" mdkg work trigger work.example --id order.example-1 --requester user://example --json");
693
742
  log("\nNotes:");
694
- log(" Accepted targets: direct WORK.md ref, or SPEC.md ref with exactly one resolvable work contract.");
743
+ log(" Accepted targets: direct WORK.md ref, or MANIFEST.md/SPEC.md ref with exactly one resolvable work contract.");
695
744
  log(" Creates a deterministic WORK_ORDER.md semantic mirror and does not execute work.");
696
745
  log(" Queue enqueue requires a valid project DB plus an explicitly created active queue and never executes work.");
697
746
  break;
@@ -715,6 +764,14 @@ function printWorkHelp(log, subcommand) {
715
764
  log("Usage:");
716
765
  log(" mdkg work artifact add <order-or-receipt-id-or-qid> <file> [--id <archive.id>] [--kind source|artifact] [--json]");
717
766
  break;
767
+ case "validate":
768
+ log("Usage:");
769
+ log(" mdkg work validate [<id-or-qid>] [--type manifest|spec|work|work_order|receipt|feedback|dispute|proposal] [--json]");
770
+ log("\nNotes:");
771
+ log(" Read-only focused validation for agent workflow mirrors.");
772
+ log(" Reports typed diagnostics for MANIFEST.md, legacy SPEC.md, WORK.md, WORK_ORDER.md, RECEIPT.md, FEEDBACK.md, DISPUTE.md, and PROPOSAL.md files.");
773
+ log(" Obvious raw secret, prompt, token, or payload markers are warnings so humans and agents can review boundaries.");
774
+ break;
718
775
  default:
719
776
  log("Usage:");
720
777
  log(" mdkg work contract new ...");
@@ -722,8 +779,10 @@ function printWorkHelp(log, subcommand) {
722
779
  log(" mdkg work order new|status|update ...");
723
780
  log(" mdkg work receipt new|verify|update ...");
724
781
  log(" mdkg work artifact add ...");
782
+ log(" mdkg work validate [<id-or-qid>] [--type <workflow-type>] [--json]");
725
783
  log("\nNotes:");
726
784
  log(" - work commands mutate semantic mirror files only");
785
+ log(" - work validate is read-only and reports typed workflow diagnostics");
727
786
  log(" - production order, receipt, feedback, dispute, payment, ledger, marketplace inventory, fulfillment, and execution state remains canonical outside mdkg");
728
787
  log(" - do not store raw secrets, credentials, live payment state, ledger mutations, or canonical marketplace state in work mirrors");
729
788
  log(" - artifact:// refs identify external/runtime-managed artifacts; archive:// refs identify committed mdkg archive sidecars");
@@ -754,7 +813,7 @@ function printTaskHelp(log, subcommand) {
754
813
  case "done":
755
814
  log("Usage:");
756
815
  log(' mdkg task done <id-or-qid> [--ws <alias>] [--add-artifacts <a,...>] [--add-links <l,...>]');
757
- log(' [--add-refs <id,...>] [--checkpoint "<title>"] [--run-id <id>] [--note "<text>"] [--json]');
816
+ log(' [--add-refs <id,...>] [--checkpoint "<title>"] [--checkpoint-kind implementation|test-proof|goal-closeout|audit|handoff] [--run-id <id>] [--note "<text>"] [--json]');
758
817
  log("\nWhen to use:");
759
818
  log(" Mark a task-like node done, optionally create a checkpoint, and emit a completion event when enabled.");
760
819
  log(" Use `--checkpoint` for milestone compression, not every routine task completion.");
@@ -764,7 +823,7 @@ function printTaskHelp(log, subcommand) {
764
823
  log("Usage:");
765
824
  log(' mdkg task start <id-or-qid> [--ws <alias>] [--run-id <id>] [--note "<text>"] [--json]');
766
825
  log(" mdkg task update <id-or-qid> [options] [--json]");
767
- log(' mdkg task done <id-or-qid> [--checkpoint "<title>"] [options] [--json]');
826
+ log(' mdkg task done <id-or-qid> [--checkpoint "<title>"] [--checkpoint-kind implementation|test-proof|goal-closeout|audit|handoff] [options] [--json]');
768
827
  log("\nNotes:");
769
828
  log(" `mdkg task ...` only supports feat, task, bug, test, and spike nodes.");
770
829
  log(" Spikes use this lifecycle; there is no separate `mdkg spike ...` command family.");
@@ -778,7 +837,7 @@ function printGoalHelp(log, subcommand) {
778
837
  log("Usage:");
779
838
  log(" mdkg goal show <goal-id-or-qid> [--ws <alias>] [--json]");
780
839
  log("\nWhen to use:");
781
- log(" Inspect a goal condition, current goal state, active node, required skills, and required checks.");
840
+ log(" Inspect a goal condition, current goal state, active node, last active node, required skills, and required checks.");
782
841
  printGlobalOptions(log);
783
842
  return;
784
843
  case "next":
@@ -847,6 +906,9 @@ function printGoalHelp(log, subcommand) {
847
906
  log(` mdkg goal ${subcommand} <goal-id-or-qid> [--ws <alias>] [--json]`);
848
907
  log("\nWhen to use:");
849
908
  log(" Update durable goal state after agent or human review.");
909
+ if (subcommand === "done") {
910
+ log(" Done goals preserve the final active_node as last_active_node and stop routing actionable work.");
911
+ }
850
912
  printGlobalOptions(log);
851
913
  return;
852
914
  default:
@@ -863,6 +925,7 @@ function printGoalHelp(log, subcommand) {
863
925
  log("\nNotes:");
864
926
  log(" - goals orchestrate recursive progress; features, tasks, bugs, tests, and spikes are iterable work units");
865
927
  log(" - `mdkg goal next` is read-only; use `mdkg goal claim` to update active_node");
928
+ log(" - `mdkg goal done` moves active_node to last_active_node so completed goals keep history without staying actionable");
866
929
  log(" - `mdkg goal activate` enforces one active local root goal and pauses competing active goals");
867
930
  log(" - goal evaluation is report-only and never executes required_checks");
868
931
  log(" - subgraph goal qids are read-only; update the source workspace instead");
@@ -901,13 +964,20 @@ function printNextHelp(log) {
901
964
  }
902
965
  function printCheckpointHelp(log) {
903
966
  log("Usage:");
904
- log(" mdkg checkpoint new <title> [--ws <alias>] [--json]");
967
+ log(" mdkg checkpoint new <title> [--kind implementation|test-proof|goal-closeout|audit|handoff] [--ws <alias>] [--json]");
968
+ log(" Checkpoint bodies include command evidence, pass/fail status, warnings, changed surfaces, boundaries, and follow-up refs.");
905
969
  log(' [--relates <id,id,...>] [--scope <id,id,...>] [--run-id <id>] [--note "<text>"]');
906
970
  printGlobalOptions(log);
907
971
  }
908
972
  function printValidateHelp(log) {
909
973
  log("Usage:");
910
- log(" mdkg validate [--out <path>] [--quiet] [--json]");
974
+ log(" mdkg validate [--out <path>] [--json-out <path>] [--quiet] [--changed-only] [--summary] [--limit <n>] [--json]");
975
+ log("\nNotes:");
976
+ log(" Validates frontmatter schemas, graph references, visibility, skills, and events.");
977
+ log(" --changed-only filters warning presentation to changed .mdkg files while full graph errors still run.");
978
+ log(" JSON output includes warning_summary plus warning_diagnostics with warning ids, categories, severity, paths, refs, and remediation text.");
979
+ log(" --summary emits bounded warning samples for agent/CI logs; --limit controls the sample size.");
980
+ log(" --out writes the compatibility text report; --json-out writes a clean full JSON receipt.");
911
981
  printGlobalOptions(log);
912
982
  }
913
983
  function printStatusHelp(log) {
@@ -1011,6 +1081,11 @@ function printFixHelp(log, subcommand) {
1011
1081
  function printFormatHelp(log) {
1012
1082
  log("Usage:");
1013
1083
  log(" mdkg format");
1084
+ log(" mdkg format --headings [--dry-run|--apply] [--summary] [--limit <n>] [--json]");
1085
+ log("\nNotes:");
1086
+ log(" Default format normalizes frontmatter in place.");
1087
+ log(" --headings adds missing recommended body headings; it defaults to dry-run and requires --apply to write files.");
1088
+ log(" --summary emits bounded heading-change samples for agent/CI logs; --limit controls the sample size.");
1014
1089
  printGlobalOptions(log);
1015
1090
  }
1016
1091
  function printDoctorHelp(log) {
@@ -1072,12 +1147,18 @@ function printCommandHelp(log, command, subcommand) {
1072
1147
  case "pack":
1073
1148
  printPackHelp(log);
1074
1149
  return;
1150
+ case "handoff":
1151
+ printHandoffHelp(log);
1152
+ return;
1075
1153
  case "skill":
1076
1154
  printSkillHelp(log, subcommand);
1077
1155
  return;
1078
1156
  case "capability":
1079
1157
  printCapabilityHelp(log, subcommand);
1080
1158
  return;
1159
+ case "manifest":
1160
+ printSpecHelp(log, subcommand, "manifest");
1161
+ return;
1081
1162
  case "spec":
1082
1163
  printSpecHelp(log, subcommand);
1083
1164
  return;
@@ -1436,6 +1517,12 @@ function runDbSubcommand(parsed, root) {
1436
1517
  }
1437
1518
  (0, db_1.runDbQueueCreateCommand)(common);
1438
1519
  return 0;
1520
+ case "contract":
1521
+ if (parsed.positionals.length > 3) {
1522
+ throw new errors_1.UsageError("mdkg db queue contract accepts no positional arguments");
1523
+ }
1524
+ (0, db_1.runDbQueueContractCommand)(common);
1525
+ return 0;
1439
1526
  case "pause":
1440
1527
  if (!queueName || parsed.positionals.length > 4) {
1441
1528
  throw new errors_1.UsageError("mdkg db queue pause requires <queue>");
@@ -1503,7 +1590,7 @@ function runDbSubcommand(parsed, root) {
1503
1590
  (0, db_1.runDbQueueShowCommand)(common);
1504
1591
  return 0;
1505
1592
  default:
1506
- throw new errors_1.UsageError("mdkg db queue requires create/pause/resume/enqueue/claim/ack/fail/dead-letter/release-expired/stats/list/show");
1593
+ throw new errors_1.UsageError("mdkg db queue requires create/contract/pause/resume/enqueue/claim/ack/fail/dead-letter/release-expired/stats/list/show");
1507
1594
  }
1508
1595
  }
1509
1596
  case "snapshot": {
@@ -1609,43 +1696,47 @@ function runCapabilitySubcommand(parsed, root) {
1609
1696
  throw new errors_1.UsageError("capability requires list/search/show/resolve");
1610
1697
  }
1611
1698
  }
1612
- function runSpecSubcommand(parsed, root) {
1699
+ function runSpecSubcommand(parsed, root, surface = "spec") {
1613
1700
  const subcommand = (parsed.positionals[1] ?? "").toLowerCase();
1701
+ const command = surface === "manifest" ? "manifest" : "spec";
1614
1702
  switch (subcommand) {
1615
1703
  case "list": {
1616
1704
  if (parsed.positionals.length > 2) {
1617
- throw new errors_1.UsageError("spec list does not accept positional arguments");
1705
+ throw new errors_1.UsageError(`${command} list does not accept positional arguments`);
1618
1706
  }
1619
1707
  const json = parseBooleanFlag("--json", parsed.flags["--json"]);
1620
1708
  const noCache = parseBooleanFlag("--no-cache", parsed.flags["--no-cache"]);
1621
1709
  const noReindex = parseBooleanFlag("--no-reindex", parsed.flags["--no-reindex"]);
1622
- (0, spec_1.runSpecListCommand)({ root, json, noCache, noReindex });
1710
+ const runList = surface === "manifest" ? spec_1.runManifestListCommand : spec_1.runSpecListCommand;
1711
+ runList({ root, json, noCache, noReindex });
1623
1712
  return 0;
1624
1713
  }
1625
1714
  case "show": {
1626
1715
  const id = parsed.positionals[2];
1627
1716
  if (!id || parsed.positionals.length > 3) {
1628
- throw new errors_1.UsageError("spec show requires <id-or-qid-or-alias>");
1717
+ throw new errors_1.UsageError(`${command} show requires <id-or-qid-or-alias>`);
1629
1718
  }
1630
1719
  const json = parseBooleanFlag("--json", parsed.flags["--json"]);
1631
1720
  const noCache = parseBooleanFlag("--no-cache", parsed.flags["--no-cache"]);
1632
1721
  const noReindex = parseBooleanFlag("--no-reindex", parsed.flags["--no-reindex"]);
1633
- (0, spec_1.runSpecShowCommand)({ root, id, json, noCache, noReindex });
1722
+ const runShow = surface === "manifest" ? spec_1.runManifestShowCommand : spec_1.runSpecShowCommand;
1723
+ runShow({ root, id, json, noCache, noReindex });
1634
1724
  return 0;
1635
1725
  }
1636
1726
  case "validate": {
1637
1727
  const id = parsed.positionals[2];
1638
1728
  if (parsed.positionals.length > 3) {
1639
- throw new errors_1.UsageError("spec validate accepts at most one SPEC reference");
1729
+ throw new errors_1.UsageError(`${command} validate accepts at most one manifest reference`);
1640
1730
  }
1641
1731
  const json = parseBooleanFlag("--json", parsed.flags["--json"]);
1642
1732
  const noCache = parseBooleanFlag("--no-cache", parsed.flags["--no-cache"]);
1643
1733
  const noReindex = parseBooleanFlag("--no-reindex", parsed.flags["--no-reindex"]);
1644
- (0, spec_1.runSpecValidateCommand)({ root, id, json, noCache, noReindex });
1734
+ const runValidate = surface === "manifest" ? spec_1.runManifestValidateCommand : spec_1.runSpecValidateCommand;
1735
+ runValidate({ root, id, json, noCache, noReindex });
1645
1736
  return 0;
1646
1737
  }
1647
1738
  default:
1648
- throw new errors_1.UsageError("spec requires list/show/validate");
1739
+ throw new errors_1.UsageError(`${command} requires list/show/validate`);
1649
1740
  }
1650
1741
  }
1651
1742
  function runArchiveSubcommand(parsed, root) {
@@ -1799,8 +1890,17 @@ function runGraphSubcommand(parsed, root) {
1799
1890
  (0, graph_1.runGraphImportTemplateCommand)({ root, source, startGoal, idPrefix, dryRun, apply, selectGoal, json });
1800
1891
  return 0;
1801
1892
  }
1893
+ case "refs": {
1894
+ const id = parsed.positionals[2];
1895
+ if (!id || parsed.positionals.length > 3) {
1896
+ throw new errors_1.UsageError("graph refs requires <id-or-qid>");
1897
+ }
1898
+ const ws = requireFlagValue("--ws", parsed.flags["--ws"]);
1899
+ (0, graph_1.runGraphRefsCommand)({ root, id, ws, json });
1900
+ return 0;
1901
+ }
1802
1902
  default:
1803
- throw new errors_1.UsageError("graph requires clone/fork/import-template");
1903
+ throw new errors_1.UsageError("graph requires clone/fork/import-template/refs");
1804
1904
  }
1805
1905
  }
1806
1906
  function runSubgraphSubcommand(parsed, root) {
@@ -1956,6 +2056,15 @@ function runWorkSubcommand(parsed, root) {
1956
2056
  (0, work_1.runWorkTriggerCommand)({ root, ws, targetRef, id, title, requester, enqueue, json });
1957
2057
  return 0;
1958
2058
  }
2059
+ if (domain === "validate") {
2060
+ const id = parsed.positionals[2];
2061
+ if (parsed.positionals.length > 3) {
2062
+ throw new errors_1.UsageError("work validate accepts at most one workflow reference");
2063
+ }
2064
+ const type = requireFlagValue("--type", parsed.flags["--type"]);
2065
+ (0, work_1.runWorkValidateCommand)({ root, ws, id, type, json });
2066
+ return 0;
2067
+ }
1959
2068
  if (domain === "contract" && action === "new") {
1960
2069
  const title = parsed.positionals.slice(3).join(" ");
1961
2070
  const id = requireFlagValue("--id", parsed.flags["--id"]);
@@ -2115,7 +2224,7 @@ function runWorkSubcommand(parsed, root) {
2115
2224
  (0, work_1.runWorkArtifactAddCommand)({ root, ws, targetId, file, id, kind, json });
2116
2225
  return 0;
2117
2226
  }
2118
- throw new errors_1.UsageError("work requires contract new, order new/update, receipt new/update, or artifact add");
2227
+ throw new errors_1.UsageError("work requires contract new, trigger, order new/update/status, receipt new/update/verify, artifact add, or validate");
2119
2228
  }
2120
2229
  function runSkillSubcommand(parsed, root) {
2121
2230
  const subcommand = (parsed.positionals[1] ?? "").toLowerCase();
@@ -2400,6 +2509,7 @@ function runTaskSubcommand(parsed, root) {
2400
2509
  const addLinks = requireFlagValue("--add-links", parsed.flags["--add-links"]);
2401
2510
  const addRefs = requireFlagValue("--add-refs", parsed.flags["--add-refs"]);
2402
2511
  const checkpoint = requireFlagValue("--checkpoint", parsed.flags["--checkpoint"]);
2512
+ const checkpointKind = requireFlagValue("--checkpoint-kind", parsed.flags["--checkpoint-kind"]);
2403
2513
  const runId = requireFlagValue("--run-id", parsed.flags["--run-id"]);
2404
2514
  const note = requireFlagValue("--note", parsed.flags["--note"]);
2405
2515
  const json = parseBooleanFlag("--json", parsed.flags["--json"]);
@@ -2411,6 +2521,7 @@ function runTaskSubcommand(parsed, root) {
2411
2521
  addLinks,
2412
2522
  addRefs,
2413
2523
  checkpoint,
2524
+ checkpointKind,
2414
2525
  runId,
2415
2526
  note,
2416
2527
  json,
@@ -2589,6 +2700,8 @@ function runCommand(parsed, root, runtime) {
2589
2700
  return runSkillSubcommand(parsed, root);
2590
2701
  case "capability":
2591
2702
  return runCapabilitySubcommand(parsed, root);
2703
+ case "manifest":
2704
+ return runSpecSubcommand(parsed, root, "manifest");
2592
2705
  case "spec":
2593
2706
  return runSpecSubcommand(parsed, root);
2594
2707
  case "archive":
@@ -2749,6 +2862,32 @@ function runCommand(parsed, root, runtime) {
2749
2862
  });
2750
2863
  return 0;
2751
2864
  }
2865
+ case "handoff": {
2866
+ const sub = (parsed.positionals[1] ?? "").toLowerCase();
2867
+ if (!sub) {
2868
+ throw new errors_1.UsageError("handoff requires a subcommand");
2869
+ }
2870
+ if (sub !== "create") {
2871
+ throw new errors_1.UsageError(`unknown handoff subcommand: ${sub}`);
2872
+ }
2873
+ const id = parsed.positionals[2];
2874
+ if (!id || parsed.positionals.length > 3) {
2875
+ throw new errors_1.UsageError("mdkg handoff create requires <id-or-qid>");
2876
+ }
2877
+ const ws = requireFlagValue("--ws", parsed.flags["--ws"]);
2878
+ const out = requireFlagValue("--out", parsed.flags["--out"]);
2879
+ const depth = parseNumberFlag("--depth", parsed.flags["--depth"]);
2880
+ const json = parseBooleanFlag("--json", parsed.flags["--json"]);
2881
+ (0, handoff_1.runHandoffCreateCommand)({
2882
+ root,
2883
+ id,
2884
+ ws,
2885
+ out,
2886
+ depth,
2887
+ json,
2888
+ });
2889
+ return 0;
2890
+ }
2752
2891
  case "next": {
2753
2892
  if (parsed.positionals.length > 2) {
2754
2893
  throw new errors_1.UsageError("next accepts at most one id");
@@ -2778,6 +2917,7 @@ function runCommand(parsed, root, runtime) {
2778
2917
  const ws = requireFlagValue("--ws", parsed.flags["--ws"]);
2779
2918
  const relates = requireFlagValue("--relates", parsed.flags["--relates"]);
2780
2919
  const scope = requireFlagValue("--scope", parsed.flags["--scope"]);
2920
+ const kind = requireFlagValue("--kind", parsed.flags["--kind"]);
2781
2921
  const status = requireFlagValue("--status", parsed.flags["--status"]);
2782
2922
  const priority = parseNumberFlag("--priority", parsed.flags["--priority"]);
2783
2923
  const template = requireFlagValue("--template", parsed.flags["--template"]);
@@ -2790,6 +2930,7 @@ function runCommand(parsed, root, runtime) {
2790
2930
  ws,
2791
2931
  relates,
2792
2932
  scope,
2933
+ kind,
2793
2934
  status,
2794
2935
  priority,
2795
2936
  template,
@@ -2804,9 +2945,13 @@ function runCommand(parsed, root, runtime) {
2804
2945
  throw new errors_1.UsageError("validate does not accept positional arguments");
2805
2946
  }
2806
2947
  const out = requireFlagValue("--out", parsed.flags["--out"]);
2948
+ const jsonOut = requireFlagValue("--json-out", parsed.flags["--json-out"]);
2807
2949
  const quiet = parseBooleanFlag("--quiet", parsed.flags["--quiet"]);
2950
+ const changedOnly = parseBooleanFlag("--changed-only", parsed.flags["--changed-only"]);
2951
+ const summary = parseBooleanFlag("--summary", parsed.flags["--summary"]);
2952
+ const limit = parseNumberFlag("--limit", parsed.flags["--limit"]);
2808
2953
  const json = parseBooleanFlag("--json", parsed.flags["--json"]);
2809
- (0, validate_1.runValidateCommand)({ root, out, quiet, json });
2954
+ (0, validate_1.runValidateCommand)({ root, out, jsonOut, quiet, json, changedOnly, summary, limit });
2810
2955
  return 0;
2811
2956
  }
2812
2957
  case "status": {
@@ -2850,7 +2995,19 @@ function runCommand(parsed, root, runtime) {
2850
2995
  if (parsed.positionals.length > 1) {
2851
2996
  throw new errors_1.UsageError("format does not accept positional arguments");
2852
2997
  }
2853
- (0, format_1.runFormatCommand)({ root });
2998
+ const headings = parseBooleanFlag("--headings", parsed.flags["--headings"]);
2999
+ const dryRun = parseBooleanFlag("--dry-run", parsed.flags["--dry-run"]);
3000
+ const apply = parseBooleanFlag("--apply", parsed.flags["--apply"]);
3001
+ const summary = parseBooleanFlag("--summary", parsed.flags["--summary"]);
3002
+ const limit = parseNumberFlag("--limit", parsed.flags["--limit"]);
3003
+ const json = parseBooleanFlag("--json", parsed.flags["--json"]);
3004
+ if (!headings && (dryRun || apply || json || summary || limit !== undefined)) {
3005
+ throw new errors_1.UsageError("format --dry-run, --apply, --summary, --limit, and --json require --headings");
3006
+ }
3007
+ if (dryRun && apply) {
3008
+ throw new errors_1.UsageError("format --headings cannot use --dry-run and --apply together");
3009
+ }
3010
+ (0, format_1.runFormatCommand)({ root, headings, dryRun, apply, json, summary, limit });
2854
3011
  return 0;
2855
3012
  case "doctor": {
2856
3013
  if (parsed.positionals.length > 1) {