mdkg 0.2.0 → 0.3.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 (41) hide show
  1. package/CHANGELOG.md +87 -1
  2. package/CLI_COMMAND_MATRIX.md +1176 -0
  3. package/README.md +58 -5
  4. package/dist/cli.js +267 -12
  5. package/dist/command-contract.json +7473 -0
  6. package/dist/commands/capability.js +13 -8
  7. package/dist/commands/doctor.js +370 -86
  8. package/dist/commands/fix.js +924 -0
  9. package/dist/commands/format.js +9 -3
  10. package/dist/commands/skill.js +13 -3
  11. package/dist/commands/skill_support.js +3 -3
  12. package/dist/commands/spec.js +101 -0
  13. package/dist/commands/status.js +270 -0
  14. package/dist/commands/subgraph.js +300 -0
  15. package/dist/commands/validate.js +1 -1
  16. package/dist/commands/work.js +569 -20
  17. package/dist/commands/workspace.js +19 -7
  18. package/dist/graph/agent_file_types.js +95 -7
  19. package/dist/graph/capabilities_indexer.js +89 -2
  20. package/dist/graph/frontmatter.js +6 -0
  21. package/dist/graph/node.js +8 -2
  22. package/dist/init/AGENT_START.md +5 -1
  23. package/dist/init/CLI_COMMAND_MATRIX.md +36 -0
  24. package/dist/init/README.md +41 -2
  25. package/dist/init/init-manifest.json +20 -20
  26. package/dist/init/templates/default/receipt.md +12 -1
  27. package/dist/init/templates/default/spec.md +8 -6
  28. package/dist/init/templates/default/work.md +5 -1
  29. package/dist/init/templates/default/work_order.md +11 -0
  30. package/dist/init/templates/specs/agent.SPEC.md +45 -4
  31. package/dist/init/templates/specs/api.SPEC.md +1 -0
  32. package/dist/init/templates/specs/base.SPEC.md +45 -12
  33. package/dist/init/templates/specs/capability.SPEC.md +16 -3
  34. package/dist/init/templates/specs/integration.SPEC.md +1 -0
  35. package/dist/init/templates/specs/model.SPEC.md +1 -0
  36. package/dist/init/templates/specs/project.SPEC.md +14 -1
  37. package/dist/init/templates/specs/{omniruntime-agent.SPEC.md → runtime-agent.SPEC.md} +13 -3
  38. package/dist/init/templates/specs/runtime-image.SPEC.md +1 -0
  39. package/dist/init/templates/specs/tool.SPEC.md +1 -0
  40. package/dist/util/argparse.js +9 -0
  41. package/package.json +12 -3
package/README.md CHANGED
@@ -133,6 +133,8 @@ mdkg show child_repo:work.example
133
133
  mdkg pack child_repo:work.example --dry-run --stats
134
134
  mdkg capability resolve "child capability" --json
135
135
  mdkg subgraph verify child_repo --json
136
+ mdkg subgraph audit child_repo --target .mdkg/subgraphs --json
137
+ mdkg subgraph upgrade-plan child_repo --json
136
138
  ```
137
139
 
138
140
  When the child repo is available under a configured root-relative `source_path`, refresh the root-owned bundle snapshot explicitly:
@@ -142,6 +144,8 @@ mdkg subgraph sync child_repo --dry-run --json
142
144
  mdkg subgraph sync child_repo --json
143
145
  ```
144
146
 
147
+ `audit` is read-only and reports source-path Git state, dirty tracked child files, bundle validity/freshness, root-owned bundle-path safety, optional materialized-target marker safety, and count-only capability summaries. `upgrade-plan` is also read-only, returns `apply_supported: false`, and proposes safe sync/verify/materialize next steps without writing bundles or child files.
148
+
145
149
  `sync` inspects the child Git repo, refuses dirty tracked changes by default, builds the configured private/public bundle into the root-owned source path, verifies it, and records `<branch>@<sha>` in `source_repo`. It never commits, pulls, pushes, checks out, resets, or mutates child mdkg Markdown. Use `--allow-dirty` only when the dirty state is intentional and must be recorded in the receipt.
146
150
 
147
151
  Generate a local read-only inspection tree when humans need to browse extracted child graph files:
@@ -167,8 +171,16 @@ mdkg index
167
171
  mdkg capability list --kind skill --json
168
172
  mdkg capability search "image worker" --kind work --json
169
173
  mdkg capability show <id-or-qid-or-slug> --json
174
+ mdkg spec list --json
175
+ mdkg spec show <id-or-qid-or-alias> --json
170
176
  ```
171
177
 
178
+ `SPEC.md` is optional. Repos with no SPEC files still validate; when present,
179
+ SPEC records describe reusable capability surfaces rather than general planning
180
+ notes. `mdkg spec list/show/validate` is the focused SPEC command family, while
181
+ `mdkg capability ...` remains the broader read-only discovery surface for
182
+ skills, SPECs, WORK contracts, core docs, and design docs.
183
+
172
184
  Register source and artifact files as committed archive sidecars:
173
185
 
174
186
  ```bash
@@ -181,11 +193,20 @@ Create semantic mirror work contracts, orders, receipts, and artifacts:
181
193
 
182
194
  ```bash
183
195
  mdkg work contract new "generate image" --id work.generate-image --agent-id agent.image-worker --kind image_generation --inputs prompt:text:required --outputs image_url:url:required
184
- mdkg work order new "generate image request" --id order.generate-image-1 --work-id work.generate-image --requester user://example --input-refs archive://archive.key-input-doc
196
+ mdkg work trigger work.generate-image --id order.generate-image-1 --requester user://example
197
+ mdkg work order status order.generate-image-1 --json
185
198
  mdkg work receipt new "generate image receipt" --id receipt.generate-image-1 --work-order-id order.generate-image-1 --outcome success --receipt-status recorded
199
+ mdkg work receipt verify receipt.generate-image-1 --json
186
200
  mdkg work artifact add receipt.generate-image-1 ./outputs/image.png --id archive.generated-image --kind artifact
187
201
  ```
188
202
 
203
+ Create a manual order instead of a trigger-created order when you need to supply
204
+ input refs at order creation time:
205
+
206
+ ```bash
207
+ mdkg work order new "generate image request" --id order.generate-image-manual --work-id work.generate-image --requester user://example --input-refs archive://archive.key-input-doc
208
+ ```
209
+
189
210
  Receipt statuses are `recorded`, `verified`, `rejected`, and `superseded`.
190
211
  Update and artifact commands accept local ids or local qids; subgraph qids are read-only and must be changed in their source workspace.
191
212
 
@@ -254,11 +275,14 @@ These are the commands new users and agents should learn first:
254
275
  - `mdkg pack`
255
276
  - `mdkg skill`
256
277
  - `mdkg capability`
278
+ - `mdkg spec`
257
279
  - `mdkg archive`
258
280
  - `mdkg work`
259
281
  - `mdkg goal`
260
282
  - `mdkg task`
261
283
  - `mdkg validate`
284
+ - `mdkg status`
285
+ - `mdkg fix`
262
286
 
263
287
  Advanced / maintenance commands still exist, but they are not the first-run story:
264
288
  - `mdkg event`
@@ -266,9 +290,34 @@ Advanced / maintenance commands still exist, but they are not the first-run stor
266
290
  - `mdkg index`
267
291
  - `mdkg guide`
268
292
  - `mdkg format`
269
- - `mdkg doctor`
293
+ - `mdkg doctor --strict --json`
294
+ - `mdkg fix plan --json`
270
295
  - `mdkg workspace`
271
296
 
297
+ ## Operator health
298
+
299
+ Use `mdkg status --json` for a read-only operator summary before mutating a
300
+ repo. It reports package/release state, Git cleanliness, graph validity,
301
+ selected-goal state, project DB verification state, and generated cache
302
+ freshness without rebuilding indexes, running migrations, repairing files, or
303
+ changing selected-goal state.
304
+
305
+ Use `mdkg doctor --strict --json` when a CI job or agent needs actionable
306
+ typed checks. Strict doctor keeps the existing diagnostic command read-only and
307
+ adds stable check fields: `id`, `status`, `severity`, `message`,
308
+ `remediation`, and optional `refs`. Strict mode fails on invalid graph state,
309
+ stale generated graph/capability cache state, stale or achieved selected-goal
310
+ state, and enabled project DB verification failures. Warnings such as dirty
311
+ runtime DB files, archive size guidance, and bundle handoff guidance remain
312
+ warnings unless their underlying check fails.
313
+
314
+ Use `mdkg fix plan --json` when you want repair guidance without mutation. It
315
+ emits a receipt-shaped plan for generated index/cache repair, missing graph
316
+ references, and duplicate local ids. Planned changes include affected paths,
317
+ risk, reason codes, command hints, and `apply_supported: false`. `fix apply` is
318
+ not exposed; apply behavior is deferred until the dry-run plan contract has
319
+ enough evidence.
320
+
272
321
  ## Skills
273
322
 
274
323
  mdkg supports Agent Skills as procedural memory.
@@ -326,7 +375,7 @@ mdkg maintains `.mdkg/index/capabilities.json` as a derived access cache for det
326
375
 
327
376
  The capability cache is not the full graph and is not source of truth. Normal tasks, epics, bugs, tests, feats, and checkpoints remain in the standard graph index. Markdown remains authoritative; deleting the cache is recoverable with `mdkg index` or by running a capability command when auto-reindex is enabled.
328
377
 
329
- Capability records aggregate enabled registered workspaces and include deterministic source metadata such as `workspace`, `visibility`, `kind`, `id`, `qid`, `path`, headings, refs, source hash, and `indexed_at`. Workspace `visibility` also feeds mdkg's export safety checks for public/internal packs and public bundles. This is a CLI safety layer, not secret scanning, body redaction, or a replacement for private git hosting.
378
+ Capability records aggregate enabled registered workspaces and include deterministic source metadata such as `workspace`, `visibility`, `kind`, `id`, `qid`, `path`, headings, refs, source hash, and `indexed_at`. SPEC and WORK records also expose read-only `linkage` arrays when related work contracts, work orders, and receipts exist, so an orchestrator can discover a capability from reusable surface to invocation evidence without loading the full graph. Workspace `visibility` also feeds mdkg's export safety checks for public/internal packs and public bundles. This is a CLI safety layer, not secret scanning, body redaction, or a replacement for private git hosting.
330
379
 
331
380
  ## Index backends and parallel safety
332
381
 
@@ -360,6 +409,9 @@ rows are durable local project DB history; receipts, reducers, writer leases,
360
409
  and materializers remain internal helper surfaces in this release, with no
361
410
  public `mdkg db event`, `mdkg db reducer`, `mdkg db lease`, or
362
411
  `mdkg db materializer` CLI yet.
412
+ `mdkg work trigger --enqueue <queue>` can bridge a submitted work order mirror
413
+ into an explicitly created active project DB queue; it writes local delivery
414
+ state only and never executes work.
363
415
  Use `mdkg db verify` for non-mutating health checks over config, layout,
364
416
  runtime SQLite integrity, migration metadata, and transient runtime files. Use
365
417
  `mdkg db stats` for deterministic table counts, DB size, migration state,
@@ -401,7 +453,7 @@ Use `mdkg new spec|work|work_order|receipt|feedback|dispute|proposal "<title>"`
401
453
 
402
454
  Relational templates contain editable placeholder refs. `spec` and `work` scaffold as validation-clean standalone docs; `work_order`, `receipt`, `feedback`, `dispute`, and `proposal` need real refs before strict `mdkg validate` passes.
403
455
 
404
- For executable or purchasable capability mirrors, prefer the lifecycle helpers under `mdkg work ...`. They create and update `WORK.md`, `WORK_ORDER.md`, and `RECEIPT.md` semantic mirror files only. Production order state, receipt state, feedback, disputes, payments, ledgers, marketplace inventory, fulfillment records, and execution state remain canonical outside mdkg, such as in Postgres or another application database. Do not store raw secrets, credentials, live payment state, ledger mutations, canonical marketplace state, or bulky raw payloads in these mirrors.
456
+ For executable or purchasable capability mirrors, prefer the lifecycle helpers under `mdkg work ...`. They create and update `WORK.md`, `WORK_ORDER.md`, and `RECEIPT.md` semantic mirror files only. `mdkg work trigger` creates a deterministic submitted `WORK_ORDER.md` from a WORK contract or a SPEC with exactly one resolvable work contract. `mdkg work order status` and `mdkg work receipt verify` are read-only review helpers for deterministic closeout. `mdkg work trigger --enqueue <queue>` optionally writes a local project DB queue delivery message after the queue has been explicitly created and is active; it still does not execute work. Production order state, receipt state, feedback, disputes, payments, ledgers, marketplace inventory, fulfillment records, and execution state remain canonical outside mdkg, such as in Postgres or another application database. Do not store raw secrets, credentials, live payment state, ledger mutations, canonical marketplace state, or bulky raw payloads in these mirrors.
405
457
 
406
458
  ## Archive sidecars
407
459
 
@@ -423,6 +475,7 @@ This release includes:
423
475
  - root-only published init seed config
424
476
  - skills indexing and search/show/list support
425
477
  - JSON capability cache for skills, `SPEC.md`, `WORK.md`, core docs, and design docs
478
+ - optional `mdkg spec list/show/validate` for reusable SPEC capability records
426
479
  - SQLite index backend for fresh workspaces using built-in `node:sqlite`
427
480
  - mutation locking and atomic writes for parallel mdkg calls
428
481
  - first-class `goal` nodes and `mdkg goal show/next/evaluate/pause/resume/done`
@@ -436,7 +489,7 @@ This release includes:
436
489
  - shared `AGENT_START.md` startup guidance
437
490
  - conservative `mdkg upgrade` with mode-aware init manifests
438
491
  - archive sidecars with deterministic ZIP caches
439
- - semantic mirror helpers under `mdkg work ...`
492
+ - semantic mirror helpers under `mdkg work ...`, including trigger/order status/receipt verification
440
493
  - explicit public/internal/private visibility enforcement for packs, bundles, archives, imports, validation, and doctor diagnostics
441
494
  - strict archive ZIP payload integrity checks during validation
442
495
 
package/dist/cli.js CHANGED
@@ -18,8 +18,11 @@ const next_1 = require("./commands/next");
18
18
  const validate_1 = require("./commands/validate");
19
19
  const format_1 = require("./commands/format");
20
20
  const doctor_1 = require("./commands/doctor");
21
+ const status_1 = require("./commands/status");
22
+ const fix_1 = require("./commands/fix");
21
23
  const db_1 = require("./commands/db");
22
24
  const capability_1 = require("./commands/capability");
25
+ const spec_1 = require("./commands/spec");
23
26
  const archive_1 = require("./commands/archive");
24
27
  const bundle_1 = require("./commands/bundle");
25
28
  const subgraph_1 = require("./commands/subgraph");
@@ -63,14 +66,17 @@ function printUsage(log) {
63
66
  log(" pack Generate a context pack");
64
67
  log(" skill Create, list, show, search, and validate skills");
65
68
  log(" capability List, search, show, and resolve cached capability surfaces");
69
+ log(" spec List, show, and validate optional SPEC.md capability records");
66
70
  log(" archive Add, list, show, verify, and compress archive sidecars");
67
71
  log(" bundle Create, list, show, and verify full graph snapshot bundles");
68
- log(" subgraph Register, sync, materialize, and verify read-only child graph snapshots");
72
+ log(" subgraph Register, audit, plan, sync, materialize, and verify read-only child graph snapshots");
69
73
  log(" work Create and update work contracts, orders, receipts, and artifacts");
70
74
  log(" goal Inspect and advance recursive goal nodes");
71
75
  log(" task Start, update, and complete task-like nodes");
72
76
  log(" next Suggest the next work item");
73
77
  log(" validate Validate frontmatter + graph");
78
+ log(" status Show read-only operator health summary");
79
+ log(" fix Plan read-only repairs with receipt-shaped JSON");
74
80
  log("\nAdvanced / maintenance commands:");
75
81
  log(" db Project database and index-cache commands");
76
82
  log(" event Enable or append episodic event logs");
@@ -435,6 +441,41 @@ function printCapabilityHelp(log, subcommand) {
435
441
  printGlobalOptions(log);
436
442
  }
437
443
  }
444
+ function printSpecHelp(log, subcommand) {
445
+ switch ((subcommand ?? "").toLowerCase()) {
446
+ case "list":
447
+ log("Usage:");
448
+ log(" mdkg spec list [--json]");
449
+ log("\nNotes:");
450
+ log(" SPEC.md is optional and declares reusable capability surfaces.");
451
+ printGlobalOptions(log);
452
+ return;
453
+ case "show":
454
+ log("Usage:");
455
+ log(" mdkg spec show <id-or-qid-or-alias> [--json]");
456
+ log("\nNotes:");
457
+ log(" Shows one optional SPEC.md capability record from the capability index.");
458
+ printGlobalOptions(log);
459
+ return;
460
+ case "validate":
461
+ log("Usage:");
462
+ log(" mdkg spec validate [<id-or-qid-or-alias>] [--json]");
463
+ log("\nNotes:");
464
+ log(" With no reference, validates the graph and all optional SPEC.md capability records.");
465
+ log(" With a reference, also ensures that specific SPEC.md capability exists.");
466
+ printGlobalOptions(log);
467
+ return;
468
+ default:
469
+ log("Usage:");
470
+ log(" mdkg spec list [--json]");
471
+ log(" mdkg spec show <id-or-qid-or-alias> [--json]");
472
+ log(" mdkg spec validate [<id-or-qid-or-alias>] [--json]");
473
+ log("\nNotes:");
474
+ log(" SPEC.md is optional and reusable-capability oriented.");
475
+ log(" Use `mdkg capability ...` for broader skill, SPEC.md, WORK.md, core-doc, and design-doc discovery.");
476
+ printGlobalOptions(log);
477
+ }
478
+ }
438
479
  function printArchiveHelp(log, subcommand) {
439
480
  switch ((subcommand ?? "").toLowerCase()) {
440
481
  case "add":
@@ -477,7 +518,7 @@ function printBundleHelp(log, subcommand) {
477
518
  switch ((subcommand ?? "").toLowerCase()) {
478
519
  case "import":
479
520
  log("Usage:");
480
- log(" mdkg subgraph add/list/show/rm/enable/disable/verify/refresh/sync/materialize ...");
521
+ log(" mdkg subgraph add/list/show/rm/enable/disable/verify/refresh/audit/upgrade-plan/sync/materialize ...");
481
522
  log("\n`mdkg bundle import` has been replaced by `mdkg subgraph`.");
482
523
  break;
483
524
  case "create":
@@ -545,6 +586,20 @@ function printSubgraphHelp(log, subcommand) {
545
586
  log("Usage:");
546
587
  log(" mdkg subgraph refresh [alias|--all] [--json]");
547
588
  break;
589
+ case "audit":
590
+ log("Usage:");
591
+ log(" mdkg subgraph audit [alias|--all] [--target <path>] [--json]");
592
+ log("\nNotes:");
593
+ log(" - read-only audit for configured bundle health, source_path Git state, root-owned bundle paths, and optional materialize target safety");
594
+ log(" - exits nonzero only for error-level safety failures; warning-level drift stays in the receipt");
595
+ break;
596
+ case "upgrade-plan":
597
+ log("Usage:");
598
+ log(" mdkg subgraph upgrade-plan [alias|--all] [--json]");
599
+ log("\nNotes:");
600
+ log(" - read-only downstream upgrade planning receipt; apply_supported is false");
601
+ log(" - plans safe sync/verify/materialize next steps without mutating child repos or root bundles");
602
+ break;
548
603
  case "sync":
549
604
  log("Usage:");
550
605
  log(" mdkg subgraph sync [alias|--all] [--dry-run] [--allow-dirty] [--json]");
@@ -563,12 +618,15 @@ function printSubgraphHelp(log, subcommand) {
563
618
  log(" mdkg subgraph disable <alias> [--json]");
564
619
  log(" mdkg subgraph verify [alias|--all] [--json]");
565
620
  log(" mdkg subgraph refresh [alias|--all] [--json]");
621
+ log(" mdkg subgraph audit [alias|--all] [--target <path>] [--json]");
622
+ log(" mdkg subgraph upgrade-plan [alias|--all] [--json]");
566
623
  log(" mdkg subgraph sync [alias|--all] [--dry-run] [--allow-dirty] [--json]");
567
624
  log(" mdkg subgraph materialize [alias|--all] --target <path> [--clean] [--gitignore] [--json]");
568
625
  log("\nNotes:");
569
626
  log(" - subgraphs are read-only graph views backed by explicit bundle snapshots");
570
627
  log(" - default permissions are read-only and default freshness is 3600 seconds");
571
628
  log(" - refresh reloads configured bundle sources only; it does not build child bundles");
629
+ log(" - audit and upgrade-plan are read-only safety receipts for downstream orchestration");
572
630
  log(" - sync builds root-owned bundles from clean configured child source_path repos");
573
631
  log(" - materialize extracts bundle contents into generated inspection trees");
574
632
  }
@@ -580,15 +638,31 @@ function printWorkHelp(log, subcommand) {
580
638
  log("Usage:");
581
639
  log(' mdkg work contract new "<title>" --id <work.id> --agent-id <agent.id> --kind <kind> --inputs <...> --outputs <...> [--required-capabilities <...>] [--pricing-model <...>] [--json]');
582
640
  break;
641
+ case "trigger":
642
+ log("Usage:");
643
+ log(' mdkg work trigger <work-or-capability-ref> [--id <order.id>] [--title "<title>"] [--requester <ref>] [--enqueue <queue>] [--json]');
644
+ log("\nExample:");
645
+ log(" mdkg work trigger work.example --id order.example-1 --requester user://example --json");
646
+ log("\nNotes:");
647
+ log(" Accepted targets: direct WORK.md ref, or SPEC.md ref with exactly one resolvable work contract.");
648
+ log(" Creates a deterministic WORK_ORDER.md semantic mirror and does not execute work.");
649
+ log(" Queue enqueue requires a valid project DB plus an explicitly created active queue and never executes work.");
650
+ break;
583
651
  case "order":
584
652
  log("Usage:");
585
- log(' mdkg work order new "<title>" --id <order.id> --work-id <work.id> --requester <ref> [--request-ref <ref>] [--input-refs <...>] [--requested-outputs <...>] [--json]');
586
- log(" mdkg work order update <id-or-qid> [--status <status>] [--add-input-refs <...>] [--add-artifacts <...>] [--json]");
653
+ log(' mdkg work order new "<title>" --id <order.id> --work-id <work.id> --requester <ref> [--request-ref <ref>] [--trigger-ref <ref>] [--payload-hash <sha256:...>] [--input-refs <...>] [--queue-refs <...>] [--requested-outputs <...>] [--json]');
654
+ log(" mdkg work order status <id-or-qid> [--json]");
655
+ log(" mdkg work order update <id-or-qid> [--status <status>] [--add-input-refs <...>] [--add-queue-refs <...>] [--add-artifacts <...>] [--json]");
656
+ log("\nNotes:");
657
+ log(" work order status is read-only and reports deterministic JSON order state plus linked receipts.");
587
658
  break;
588
659
  case "receipt":
589
660
  log("Usage:");
590
- log(' mdkg work receipt new "<title>" --id <receipt.id> --work-order-id <order.id> --outcome success|partial|failure [--receipt-status recorded|verified|rejected|superseded] [--json]');
591
- log(" mdkg work receipt update <id-or-qid> [--receipt-status <status>] [--add-artifacts <...>] [--add-proof-refs <...>] [--add-attestation-refs <...>] [--json]");
661
+ log(' mdkg work receipt new "<title>" --id <receipt.id> --work-order-id <order.id> --outcome success|partial|failure [--receipt-status recorded|verified|rejected|superseded] [--redaction-policy refs_and_hashes_only|redacted_summary|external_private] [--evidence-hashes <sha256:...>] [--json]');
662
+ log(" mdkg work receipt verify <id-or-qid> [--json]");
663
+ log(" mdkg work receipt update <id-or-qid> [--receipt-status <status>] [--add-artifacts <...>] [--add-proof-refs <...>] [--add-attestation-refs <...>] [--add-evidence-hashes <sha256:...>] [--json]");
664
+ log("\nNotes:");
665
+ log(" work receipt verify is read-only and reports deterministic JSON linkage, evidence, hash, outcome, and redaction checks.");
592
666
  break;
593
667
  case "artifact":
594
668
  log("Usage:");
@@ -597,8 +671,9 @@ function printWorkHelp(log, subcommand) {
597
671
  default:
598
672
  log("Usage:");
599
673
  log(" mdkg work contract new ...");
600
- log(" mdkg work order new|update ...");
601
- log(" mdkg work receipt new|update ...");
674
+ log(" mdkg work trigger <work-or-capability-ref> ...");
675
+ log(" mdkg work order new|status|update ...");
676
+ log(" mdkg work receipt new|verify|update ...");
602
677
  log(" mdkg work artifact add ...");
603
678
  log("\nNotes:");
604
679
  log(" - work commands mutate semantic mirror files only");
@@ -770,6 +845,47 @@ function printValidateHelp(log) {
770
845
  log(" mdkg validate [--out <path>] [--quiet] [--json]");
771
846
  printGlobalOptions(log);
772
847
  }
848
+ function printStatusHelp(log) {
849
+ log("Usage:");
850
+ log(" mdkg status [--json]");
851
+ log("\nChecks:");
852
+ log(" - release/package and CHANGELOG summary");
853
+ log(" - git branch, dirty state, and upstream ahead/behind counts");
854
+ log(" - graph index load, validation errors, and generated cache freshness");
855
+ log(" - selected goal existence, achieved state, and active node");
856
+ log(" - project DB enabled/verify summary");
857
+ log("\nBoundaries:");
858
+ log(" - read-only operator summary; does not rebuild indexes or repair files");
859
+ log(" - use `mdkg doctor` for diagnostic detail and future strict check IDs");
860
+ log("\nOptions:");
861
+ log(" --json Emit machine-readable JSON output");
862
+ printGlobalOptions(log);
863
+ }
864
+ function printFixHelp(log, subcommand) {
865
+ switch ((subcommand ?? "").toLowerCase()) {
866
+ case "plan":
867
+ log("Usage:");
868
+ log(" mdkg fix plan [--family index|refs|ids|all] [--target <id-or-qid>] [--json]");
869
+ log("\nBoundaries:");
870
+ log(" - read-only repair planning; writes no files and does not rebuild indexes");
871
+ log(" - emits a deterministic receipt-shaped JSON plan with paths, risks, and reason codes");
872
+ log(" - initial families are index/cache, graph refs, and duplicate ids");
873
+ log(" - `fix apply` is intentionally not available in this release slice");
874
+ log("\nOptions:");
875
+ log(" --family <family> Select index, refs, ids, or all (default all)");
876
+ log(" --target <id-or-qid> Optional node target for family planners");
877
+ log(" --json Emit machine-readable JSON output");
878
+ printGlobalOptions(log);
879
+ return;
880
+ default:
881
+ log("Usage:");
882
+ log(" mdkg fix plan [--family index|refs|ids|all] [--target <id-or-qid>] [--json]");
883
+ log("\nNotes:");
884
+ log(" - fix planning is dry-run only and writes nothing");
885
+ log(" - apply behavior is deferred until the receipt contract is proven");
886
+ printGlobalOptions(log);
887
+ }
888
+ }
773
889
  function printFormatHelp(log) {
774
890
  log("Usage:");
775
891
  log(" mdkg format");
@@ -777,10 +893,12 @@ function printFormatHelp(log) {
777
893
  }
778
894
  function printDoctorHelp(log) {
779
895
  log("Usage:");
780
- log(" mdkg doctor [--json]");
896
+ log(" mdkg doctor [--strict] [--json]");
781
897
  log("\nChecks:");
782
898
  log(" - Node.js version compatibility");
783
899
  log(" - mdkg repo root + .mdkg/config.json");
900
+ log(" - Selected-goal stale or achieved state");
901
+ log(" - Project DB verification when enabled");
784
902
  log(" - Template schema availability");
785
903
  log(" - Archive sidecar storage hygiene");
786
904
  log(" - Bundle snapshot storage guidance");
@@ -789,6 +907,7 @@ function printDoctorHelp(log) {
789
907
  log(" - Capability cache load/rebuild health");
790
908
  log(" - SQLite cache health when enabled");
791
909
  log("\nOptions:");
910
+ log(" --strict Fail on stale selected-goal, DB, and generated cache health issues");
792
911
  log(" --json Emit machine-readable JSON output");
793
912
  printGlobalOptions(log);
794
913
  }
@@ -837,6 +956,9 @@ function printCommandHelp(log, command, subcommand) {
837
956
  case "capability":
838
957
  printCapabilityHelp(log, subcommand);
839
958
  return;
959
+ case "spec":
960
+ printSpecHelp(log, subcommand);
961
+ return;
840
962
  case "archive":
841
963
  printArchiveHelp(log, subcommand);
842
964
  return;
@@ -867,6 +989,12 @@ function printCommandHelp(log, command, subcommand) {
867
989
  case "validate":
868
990
  printValidateHelp(log);
869
991
  return;
992
+ case "status":
993
+ printStatusHelp(log);
994
+ return;
995
+ case "fix":
996
+ printFixHelp(log, subcommand);
997
+ return;
870
998
  case "format":
871
999
  printFormatHelp(log);
872
1000
  return;
@@ -1353,6 +1481,45 @@ function runCapabilitySubcommand(parsed, root) {
1353
1481
  throw new errors_1.UsageError("capability requires list/search/show/resolve");
1354
1482
  }
1355
1483
  }
1484
+ function runSpecSubcommand(parsed, root) {
1485
+ const subcommand = (parsed.positionals[1] ?? "").toLowerCase();
1486
+ switch (subcommand) {
1487
+ case "list": {
1488
+ if (parsed.positionals.length > 2) {
1489
+ throw new errors_1.UsageError("spec list does not accept positional arguments");
1490
+ }
1491
+ const json = parseBooleanFlag("--json", parsed.flags["--json"]);
1492
+ const noCache = parseBooleanFlag("--no-cache", parsed.flags["--no-cache"]);
1493
+ const noReindex = parseBooleanFlag("--no-reindex", parsed.flags["--no-reindex"]);
1494
+ (0, spec_1.runSpecListCommand)({ root, json, noCache, noReindex });
1495
+ return 0;
1496
+ }
1497
+ case "show": {
1498
+ const id = parsed.positionals[2];
1499
+ if (!id || parsed.positionals.length > 3) {
1500
+ throw new errors_1.UsageError("spec show requires <id-or-qid-or-alias>");
1501
+ }
1502
+ const json = parseBooleanFlag("--json", parsed.flags["--json"]);
1503
+ const noCache = parseBooleanFlag("--no-cache", parsed.flags["--no-cache"]);
1504
+ const noReindex = parseBooleanFlag("--no-reindex", parsed.flags["--no-reindex"]);
1505
+ (0, spec_1.runSpecShowCommand)({ root, id, json, noCache, noReindex });
1506
+ return 0;
1507
+ }
1508
+ case "validate": {
1509
+ const id = parsed.positionals[2];
1510
+ if (parsed.positionals.length > 3) {
1511
+ throw new errors_1.UsageError("spec validate accepts at most one SPEC reference");
1512
+ }
1513
+ const json = parseBooleanFlag("--json", parsed.flags["--json"]);
1514
+ const noCache = parseBooleanFlag("--no-cache", parsed.flags["--no-cache"]);
1515
+ const noReindex = parseBooleanFlag("--no-reindex", parsed.flags["--no-reindex"]);
1516
+ (0, spec_1.runSpecValidateCommand)({ root, id, json, noCache, noReindex });
1517
+ return 0;
1518
+ }
1519
+ default:
1520
+ throw new errors_1.UsageError("spec requires list/show/validate");
1521
+ }
1522
+ }
1356
1523
  function runArchiveSubcommand(parsed, root) {
1357
1524
  const subcommand = (parsed.positionals[1] ?? "").toLowerCase();
1358
1525
  switch (subcommand) {
@@ -1552,6 +1719,25 @@ function runSubgraphSubcommand(parsed, root) {
1552
1719
  (0, subgraph_1.runSubgraphRefreshCommand)({ root, alias, all, json });
1553
1720
  return 0;
1554
1721
  }
1722
+ case "audit": {
1723
+ if (parsed.positionals.length > 3) {
1724
+ throw new errors_1.UsageError("subgraph audit accepts at most one alias");
1725
+ }
1726
+ const alias = parsed.positionals[2];
1727
+ const all = parseBooleanFlag("--all", parsed.flags["--all"]);
1728
+ const target = requireFlagValue("--target", parsed.flags["--target"]);
1729
+ (0, subgraph_1.runSubgraphAuditCommand)({ root, alias, all, target, json });
1730
+ return 0;
1731
+ }
1732
+ case "upgrade-plan": {
1733
+ if (parsed.positionals.length > 3) {
1734
+ throw new errors_1.UsageError("subgraph upgrade-plan accepts at most one alias");
1735
+ }
1736
+ const alias = parsed.positionals[2];
1737
+ const all = parseBooleanFlag("--all", parsed.flags["--all"]);
1738
+ (0, subgraph_1.runSubgraphUpgradePlanCommand)({ root, alias, all, json });
1739
+ return 0;
1740
+ }
1555
1741
  case "sync": {
1556
1742
  if (parsed.positionals.length > 3) {
1557
1743
  throw new errors_1.UsageError("subgraph sync accepts at most one alias");
@@ -1579,7 +1765,7 @@ function runSubgraphSubcommand(parsed, root) {
1579
1765
  return 0;
1580
1766
  }
1581
1767
  default:
1582
- throw new errors_1.UsageError("subgraph requires add/list/show/rm/enable/disable/verify/refresh/sync/materialize");
1768
+ throw new errors_1.UsageError("subgraph requires add/list/show/rm/enable/disable/verify/refresh/audit/upgrade-plan/sync/materialize");
1583
1769
  }
1584
1770
  }
1585
1771
  function runWorkSubcommand(parsed, root) {
@@ -1587,6 +1773,18 @@ function runWorkSubcommand(parsed, root) {
1587
1773
  const action = (parsed.positionals[2] ?? "").toLowerCase();
1588
1774
  const ws = requireFlagValue("--ws", parsed.flags["--ws"]);
1589
1775
  const json = parseBooleanFlag("--json", parsed.flags["--json"]);
1776
+ if (domain === "trigger") {
1777
+ const targetRef = parsed.positionals[2];
1778
+ if (!targetRef || parsed.positionals.length > 3) {
1779
+ throw new errors_1.UsageError("work trigger requires <work-or-capability-ref>");
1780
+ }
1781
+ const id = requireFlagValue("--id", parsed.flags["--id"]);
1782
+ const title = requireFlagValue("--title", parsed.flags["--title"]);
1783
+ const requester = requireFlagValue("--requester", parsed.flags["--requester"]);
1784
+ const enqueue = requireFlagValue("--enqueue", parsed.flags["--enqueue"]);
1785
+ (0, work_1.runWorkTriggerCommand)({ root, ws, targetRef, id, title, requester, enqueue, json });
1786
+ return 0;
1787
+ }
1590
1788
  if (domain === "contract" && action === "new") {
1591
1789
  const title = parsed.positionals.slice(3).join(" ");
1592
1790
  const id = requireFlagValue("--id", parsed.flags["--id"]);
@@ -1623,7 +1821,10 @@ function runWorkSubcommand(parsed, root) {
1623
1821
  throw new errors_1.UsageError("work order new requires title, --id, --work-id, and --requester");
1624
1822
  }
1625
1823
  const requestRef = requireFlagValue("--request-ref", parsed.flags["--request-ref"]);
1824
+ const triggerRef = requireFlagValue("--trigger-ref", parsed.flags["--trigger-ref"]);
1825
+ const payloadHash = requireFlagValue("--payload-hash", parsed.flags["--payload-hash"]);
1626
1826
  const inputRefs = requireFlagValue("--input-refs", parsed.flags["--input-refs"]);
1827
+ const queueRefs = requireFlagValue("--queue-refs", parsed.flags["--queue-refs"]);
1627
1828
  const requestedOutputs = requireFlagValue("--requested-outputs", parsed.flags["--requested-outputs"]);
1628
1829
  const constraintRefs = requireFlagValue("--constraint-refs", parsed.flags["--constraint-refs"]);
1629
1830
  (0, work_1.runWorkOrderNewCommand)({
@@ -1634,7 +1835,10 @@ function runWorkSubcommand(parsed, root) {
1634
1835
  workId,
1635
1836
  requester,
1636
1837
  requestRef,
1838
+ triggerRef,
1839
+ payloadHash,
1637
1840
  inputRefs,
1841
+ queueRefs,
1638
1842
  requestedOutputs,
1639
1843
  constraintRefs,
1640
1844
  json,
@@ -1648,8 +1852,17 @@ function runWorkSubcommand(parsed, root) {
1648
1852
  }
1649
1853
  const status = requireFlagValue("--status", parsed.flags["--status"]);
1650
1854
  const addInputRefs = requireFlagValue("--add-input-refs", parsed.flags["--add-input-refs"]);
1855
+ const addQueueRefs = requireFlagValue("--add-queue-refs", parsed.flags["--add-queue-refs"]);
1651
1856
  const addArtifacts = requireFlagValue("--add-artifacts", parsed.flags["--add-artifacts"]);
1652
- (0, work_1.runWorkOrderUpdateCommand)({ root, ws, id, status, addInputRefs, addArtifacts, json });
1857
+ (0, work_1.runWorkOrderUpdateCommand)({ root, ws, id, status, addInputRefs, addQueueRefs, addArtifacts, json });
1858
+ return 0;
1859
+ }
1860
+ if (domain === "order" && action === "status") {
1861
+ const id = parsed.positionals[3];
1862
+ if (!id || parsed.positionals.length > 4) {
1863
+ throw new errors_1.UsageError("work order status requires <id-or-qid>");
1864
+ }
1865
+ (0, work_1.runWorkOrderStatusCommand)({ root, ws, id, json });
1653
1866
  return 0;
1654
1867
  }
1655
1868
  if (domain === "receipt" && action === "new") {
@@ -1662,9 +1875,11 @@ function runWorkSubcommand(parsed, root) {
1662
1875
  }
1663
1876
  const receiptStatus = requireFlagValue("--receipt-status", parsed.flags["--receipt-status"]);
1664
1877
  const costRef = requireFlagValue("--cost-ref", parsed.flags["--cost-ref"]);
1878
+ const redactionPolicy = requireFlagValue("--redaction-policy", parsed.flags["--redaction-policy"]);
1665
1879
  const artifacts = requireFlagValue("--artifacts", parsed.flags["--artifacts"]);
1666
1880
  const proofRefs = requireFlagValue("--proof-refs", parsed.flags["--proof-refs"]);
1667
1881
  const attestationRefs = requireFlagValue("--attestation-refs", parsed.flags["--attestation-refs"]);
1882
+ const evidenceHashes = requireFlagValue("--evidence-hashes", parsed.flags["--evidence-hashes"]);
1668
1883
  const inputHashes = requireFlagValue("--input-hashes", parsed.flags["--input-hashes"]);
1669
1884
  const outputHashes = requireFlagValue("--output-hashes", parsed.flags["--output-hashes"]);
1670
1885
  (0, work_1.runWorkReceiptNewCommand)({
@@ -1676,9 +1891,11 @@ function runWorkSubcommand(parsed, root) {
1676
1891
  outcome,
1677
1892
  receiptStatus,
1678
1893
  costRef,
1894
+ redactionPolicy,
1679
1895
  artifacts,
1680
1896
  proofRefs,
1681
1897
  attestationRefs,
1898
+ evidenceHashes,
1682
1899
  inputHashes,
1683
1900
  outputHashes,
1684
1901
  json,
@@ -1694,6 +1911,7 @@ function runWorkSubcommand(parsed, root) {
1694
1911
  const addArtifacts = requireFlagValue("--add-artifacts", parsed.flags["--add-artifacts"]);
1695
1912
  const addProofRefs = requireFlagValue("--add-proof-refs", parsed.flags["--add-proof-refs"]);
1696
1913
  const addAttestationRefs = requireFlagValue("--add-attestation-refs", parsed.flags["--add-attestation-refs"]);
1914
+ const addEvidenceHashes = requireFlagValue("--add-evidence-hashes", parsed.flags["--add-evidence-hashes"]);
1697
1915
  (0, work_1.runWorkReceiptUpdateCommand)({
1698
1916
  root,
1699
1917
  ws,
@@ -1702,10 +1920,19 @@ function runWorkSubcommand(parsed, root) {
1702
1920
  addArtifacts,
1703
1921
  addProofRefs,
1704
1922
  addAttestationRefs,
1923
+ addEvidenceHashes,
1705
1924
  json,
1706
1925
  });
1707
1926
  return 0;
1708
1927
  }
1928
+ if (domain === "receipt" && action === "verify") {
1929
+ const id = parsed.positionals[3];
1930
+ if (!id || parsed.positionals.length > 4) {
1931
+ throw new errors_1.UsageError("work receipt verify requires <id-or-qid>");
1932
+ }
1933
+ (0, work_1.runWorkReceiptVerifyCommand)({ root, ws, id, json });
1934
+ return 0;
1935
+ }
1709
1936
  if (domain === "artifact" && action === "add") {
1710
1937
  const targetId = parsed.positionals[3];
1711
1938
  const file = parsed.positionals[4];
@@ -2175,6 +2402,8 @@ function runCommand(parsed, root, runtime) {
2175
2402
  return runSkillSubcommand(parsed, root);
2176
2403
  case "capability":
2177
2404
  return runCapabilitySubcommand(parsed, root);
2405
+ case "spec":
2406
+ return runSpecSubcommand(parsed, root);
2178
2407
  case "archive":
2179
2408
  return runArchiveSubcommand(parsed, root);
2180
2409
  case "bundle":
@@ -2391,6 +2620,31 @@ function runCommand(parsed, root, runtime) {
2391
2620
  (0, validate_1.runValidateCommand)({ root, out, quiet, json });
2392
2621
  return 0;
2393
2622
  }
2623
+ case "status": {
2624
+ if (parsed.positionals.length > 1) {
2625
+ throw new errors_1.UsageError("status does not accept positional arguments");
2626
+ }
2627
+ const json = parseBooleanFlag("--json", parsed.flags["--json"]);
2628
+ (0, status_1.runStatusCommand)({ root, json });
2629
+ return 0;
2630
+ }
2631
+ case "fix": {
2632
+ const sub = (parsed.positionals[1] ?? "").toLowerCase();
2633
+ if (!sub) {
2634
+ throw new errors_1.UsageError("fix requires a subcommand");
2635
+ }
2636
+ if (sub !== "plan") {
2637
+ throw new errors_1.UsageError(`unknown fix subcommand: ${sub}`);
2638
+ }
2639
+ if (parsed.positionals.length > 2) {
2640
+ throw new errors_1.UsageError("fix plan does not accept positional arguments");
2641
+ }
2642
+ const family = requireFlagValue("--family", parsed.flags["--family"]);
2643
+ const target = requireFlagValue("--target", parsed.flags["--target"]);
2644
+ const json = parseBooleanFlag("--json", parsed.flags["--json"]);
2645
+ (0, fix_1.runFixPlanCommand)({ root, family, target, json });
2646
+ return 0;
2647
+ }
2394
2648
  case "format":
2395
2649
  if (parsed.positionals.length > 1) {
2396
2650
  throw new errors_1.UsageError("format does not accept positional arguments");
@@ -2404,7 +2658,8 @@ function runCommand(parsed, root, runtime) {
2404
2658
  const noCache = parseBooleanFlag("--no-cache", parsed.flags["--no-cache"]);
2405
2659
  const noReindex = parseBooleanFlag("--no-reindex", parsed.flags["--no-reindex"]);
2406
2660
  const json = parseBooleanFlag("--json", parsed.flags["--json"]);
2407
- (0, doctor_1.runDoctorCommand)({ root, noCache, noReindex, json });
2661
+ const strict = parseBooleanFlag("--strict", parsed.flags["--strict"]);
2662
+ (0, doctor_1.runDoctorCommand)({ root, noCache, noReindex, json, strict });
2408
2663
  return 0;
2409
2664
  }
2410
2665
  default: