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
@@ -0,0 +1,1176 @@
1
+ # CLI Command Matrix
2
+
3
+ as_of: 2026-06-06
4
+ package_version_in_source: 0.2.0
5
+ source: live help from `src/cli.ts`, runtime command handlers, and `dec-15`..`dec-18`
6
+ status: canonical single-source command and flag reference for mdkg
7
+
8
+ ## Purpose
9
+
10
+ This file is the one place humans and LLMs should check for the live mdkg command surface.
11
+
12
+ Verification commands:
13
+ - `npm run cli:snapshot`
14
+ - `npm run cli:check`
15
+
16
+ ## Teaching model
17
+
18
+ Primary commands:
19
+ - `init`
20
+ - `upgrade`
21
+ - `new`
22
+ - `show`
23
+ - `list`
24
+ - `search`
25
+ - `pack`
26
+ - `skill`
27
+ - `capability`
28
+ - `spec`
29
+ - `archive`
30
+ - `bundle`
31
+ - `subgraph`
32
+ - `work`
33
+ - `goal`
34
+ - `task`
35
+ - `next`
36
+ - `validate`
37
+ - `status`
38
+ - `fix`
39
+
40
+ Advanced / maintenance commands:
41
+ - `db`
42
+ - `event`
43
+ - `checkpoint`
44
+ - `index`
45
+ - `guide`
46
+ - `format`
47
+ - `status`
48
+ - `fix`
49
+ - `doctor`
50
+ - `workspace`
51
+
52
+ Skills are first-class and are accessed only through `mdkg skill ...`.
53
+ Generic `list/show/search` do not expose skills.
54
+ Capability cache discovery is read-only and accessed through `mdkg capability ...`.
55
+ Optional reusable SPEC capability records are accessed through `mdkg spec ...`.
56
+ Archive sidecars are accessed through `mdkg archive ...`.
57
+ Full graph snapshot bundles are accessed through `mdkg bundle ...`.
58
+ Read-only child graph orchestration is accessed through `mdkg subgraph ...`.
59
+ Work contract/order/receipt semantic mirrors are accessed through `mdkg work ...`.
60
+ Recursive long-running objective contracts are accessed through `mdkg goal ...`.
61
+ Fresh init workspaces default to the SQLite access cache backend; existing migrated configs stay on JSON until opted in.
62
+ Project application database foundation commands are accessed through `mdkg db ...`; `mdkg index` remains the compatibility shortcut for graph index rebuilds.
63
+ Operator health summaries are accessed through read-only `mdkg status ...`; deeper diagnostics remain under `mdkg doctor ...`.
64
+ Repair planning is accessed through read-only `mdkg fix plan ...`; apply behavior is intentionally deferred.
65
+
66
+ ## Global usage
67
+
68
+ Usage:
69
+ - `mdkg <command> [options]`
70
+
71
+ Global flags:
72
+ - `--root`, `-r <path>`
73
+ - `--help`, `-h`
74
+ - `--version`, `-V`
75
+
76
+ Hidden but supported runtime flags used by selected commands:
77
+ - `--no-cache`
78
+ - `--no-reindex`
79
+
80
+ ## Primary commands
81
+
82
+ ### `mdkg init`
83
+
84
+ When to use:
85
+ - bootstrap a repo with mdkg
86
+ - add the complete agent bootstrap when coding agents will use the repo
87
+
88
+ Usage:
89
+ - `mdkg init [options]`
90
+
91
+ Flags:
92
+ - `--force`
93
+ - `--agent`
94
+ - `--no-update-ignores`
95
+ - `--update-gitignore`
96
+ - `--update-npmignore`
97
+ - `--update-dockerignore`
98
+
99
+ Notes:
100
+ - `--agent` is the canonical complete AI-agent bootstrap path
101
+ - removed flags `--llm`, `--agents`, `--claude`, and `--omni` fail before mutation with guidance to use `mdkg init --agent`
102
+ - published bootstrap config is root-only by default
103
+ - `--agent` creates `AGENT_START.md`, `AGENTS.md`, `CLAUDE.md`, `llms.txt`, `CLI_COMMAND_MATRIX.md`, strict-node core docs, default mdkg usage skills, `events.jsonl`, registry, and skill mirrors
104
+
105
+ ### `mdkg upgrade`
106
+
107
+ When to use:
108
+ - preview or apply safe mdkg scaffold upgrades in an existing workspace
109
+ - refresh managed init docs, templates, and default skills without overwriting local edits
110
+
111
+ Usage:
112
+ - `mdkg upgrade [--dry-run] [--apply] [--json]`
113
+
114
+ Flags:
115
+ - `--dry-run`
116
+ - `--apply`
117
+ - `--json`
118
+
119
+ Notes:
120
+ - `mdkg upgrade` defaults to dry-run and writes nothing
121
+ - `--apply` is the only mutating upgrade path
122
+ - JSON receipts include `safe_to_apply`, `will_write_paths`, `preserved_customizations`, `blocking_conflicts`, and `apply_side_effects`
123
+ - customized docs, templates, skills, and core files are preserved and reported as preserved customizations
124
+ - agent-enabled workspaces include safe default skill upgrades and skill mirror sync
125
+ - ignored event logs are skipped with guidance to run `mdkg event enable`
126
+ - non-agent workspaces do not gain skills, events, or mirrors implicitly
127
+
128
+ ### `mdkg new`
129
+
130
+ When to use:
131
+ - create a new node in the mdkg graph
132
+ - optionally emit a baseline event when event logging is enabled
133
+
134
+ Usage:
135
+ - `mdkg new <type> "<title>" [options] [--json]`
136
+
137
+ Types:
138
+ - `rule`
139
+ - `prd`
140
+ - `edd`
141
+ - `dec`
142
+ - `prop`
143
+ - `goal`
144
+ - `epic`
145
+ - `feat`
146
+ - `task`
147
+ - `bug`
148
+ - `checkpoint`
149
+ - `test`
150
+
151
+ Agent workflow file types:
152
+ - `spec`
153
+ - `work`
154
+ - `work_order`
155
+ - `receipt`
156
+ - `feedback`
157
+ - `dispute`
158
+ - `proposal`
159
+
160
+ Agent workflow file type creation:
161
+ - `mdkg new spec "<title>" [options] [--json]`
162
+ - `mdkg new work "<title>" [options] [--json]`
163
+ - `mdkg new work_order "<title>" [options] [--json]`
164
+ - `mdkg new receipt "<title>" [options] [--json]`
165
+ - `mdkg new feedback "<title>" [options] [--json]`
166
+ - `mdkg new dispute "<title>" [options] [--json]`
167
+ - `mdkg new proposal "<title>" [options] [--json]`
168
+
169
+ Goal node creation:
170
+ - `mdkg new goal "<title>" [options] [--json]`
171
+
172
+ Primary flags:
173
+ - `--id <portable-id>` agent workflow file types only
174
+ - `--ws <alias>`
175
+ - `--status <status>`
176
+ - `--priority <0..9>`
177
+ - `--epic <id>`
178
+ - `--tags <tag,tag,...>`
179
+ - `--skills <slug,slug,...>`
180
+ - `--template <set>`
181
+ - `--run-id <id>`
182
+ - `--json`
183
+
184
+ Advanced metadata flags:
185
+ - `--parent <id>`
186
+ - `--prev <id>`
187
+ - `--next <id>`
188
+ - `--relates <id,id,...>`
189
+ - `--blocked-by <id,id,...>`
190
+ - `--blocks <id,id,...>`
191
+ - `--links <value,value,...>`
192
+ - `--artifacts <value,value,...>`
193
+ - `--refs <value,value,...>`
194
+ - `--aliases <value,value,...>`
195
+ - `--owners <value,value,...>`
196
+ - `--cases <value,value,...>`
197
+ - `--supersedes <id,id,...>`
198
+
199
+ JSON receipt:
200
+ - `{ action: "created", node: { workspace, id, qid, path, type, title, status, priority } }`
201
+ - `status` and `priority` are included only when present on the created node.
202
+
203
+ Notes:
204
+ - `--id` lets agent workflow files use semantic portable ids such as `agent.image-worker`, `work.generate-image`, or `proposal.review-loop-1`.
205
+ - `goal` nodes capture recursive objective state and required checks, but normal `mdkg next` does not select them.
206
+ - `spec` and `work` scaffold as validation-clean standalone docs. `work_order`, `receipt`, `feedback`, `dispute`, and `proposal` templates contain editable placeholder refs and need real graph or `skill.<slug>` refs before strict validation passes.
207
+
208
+ ### `mdkg show`
209
+
210
+ When to use:
211
+ - inspect one mdkg node exactly
212
+ - use `mdkg skill show <slug>` for skills
213
+
214
+ Usage:
215
+ - `mdkg show <id-or-qid> [--ws <alias>] [--meta] [--json|--xml|--toon|--md]`
216
+
217
+ Flags:
218
+ - `--ws <alias>`
219
+ - `--meta`
220
+ - `--json`
221
+ - `--xml`
222
+ - `--toon`
223
+ - `--md`
224
+
225
+ Notes:
226
+ - default behavior prints full body content
227
+ - `--meta` omits the body
228
+ - structured outputs are mutually exclusive
229
+ - `--json`, `--xml`, `--toon`, and `--md` all return the same `show` envelope shape
230
+
231
+ Removed surface:
232
+ - `mdkg show skill:<slug>`
233
+
234
+ ### `mdkg list`
235
+
236
+ When to use:
237
+ - list mdkg nodes with deterministic filters
238
+ - use `mdkg skill list` for skills
239
+
240
+ Usage:
241
+ - `mdkg list [--type <type>] [--status <status>] [--ws <alias>] [--epic <id>]`
242
+ - ` [--priority <n>] [--blocked] [--tags <tag,tag,...>] [--tags-mode any|all] [--json|--xml|--toon|--md]`
243
+
244
+ Flags:
245
+ - `--type <type>`
246
+ - `--status <status>`
247
+ - `--ws <alias>`
248
+ - `--epic <id>`
249
+ - `--priority <n>`
250
+ - `--blocked`
251
+ - `--tags <tag,tag,...>`
252
+ - `--tags-mode any|all`
253
+ - `--json`
254
+ - `--xml`
255
+ - `--toon`
256
+ - `--md`
257
+
258
+ Notes:
259
+ - text mode prints cards on stdout and `count:` / `note:` on stderr
260
+ - structured outputs are mutually exclusive
261
+ - `--json`, `--xml`, `--toon`, and `--md` all return the same `list` envelope shape
262
+
263
+ Removed surface:
264
+ - `mdkg list --type skill`
265
+
266
+ ### `mdkg search`
267
+
268
+ When to use:
269
+ - search node metadata and linked identifiers
270
+ - use `mdkg skill search` for skills
271
+
272
+ Usage:
273
+ - `mdkg search "<query>" [--type <type>] [--status <status>] [--ws <alias>]`
274
+ - ` [--tags <tag,tag,...>] [--tags-mode any|all] [--json|--xml|--toon|--md]`
275
+
276
+ Flags:
277
+ - `--type <type>`
278
+ - `--status <status>`
279
+ - `--ws <alias>`
280
+ - `--tags <tag,tag,...>`
281
+ - `--tags-mode any|all`
282
+ - `--json`
283
+ - `--xml`
284
+ - `--toon`
285
+ - `--md`
286
+
287
+ Notes:
288
+ - search returns nodes only
289
+ - text mode prints cards on stdout and `count:` / `note:` on stderr
290
+ - structured outputs are mutually exclusive
291
+ - `--json`, `--xml`, `--toon`, and `--md` all return the same `search` envelope shape
292
+
293
+ Removed surfaces:
294
+ - `mdkg search --type skill`
295
+ - generic `mdkg search` returning skills
296
+
297
+ ### `mdkg pack`
298
+
299
+ When to use:
300
+ - build the deterministic handoff context for humans and agents
301
+
302
+ Usage:
303
+ - `mdkg pack <id-or-qid> [options]`
304
+ - `mdkg pack --list-profiles`
305
+
306
+ Primary flags:
307
+ - `--ws <alias>` / `-w`
308
+ - `--verbose` / `-v`
309
+ - `--format <fmt>` / `-f`
310
+ - `--out <path>` / `-o`
311
+ - `--profile <name>`
312
+ - `--visibility public|internal|private`
313
+ - `--skills <mode>`
314
+ - `--skills-depth <mode>`
315
+ - `--dry-run`
316
+ - `--stats`
317
+ - `--list-profiles`
318
+
319
+ Advanced flags:
320
+ - `--depth <n>`
321
+ - `--edges <edge,edge,...>`
322
+ - `--strip-code`
323
+ - `--max-code-lines <n>`
324
+ - `--max-chars <n>`
325
+ - `--max-lines <n>`
326
+ - `--max-tokens <n>`
327
+ - `--truncation-report <path>`
328
+ - `--stats-out <path>`
329
+
330
+ Allowed formats:
331
+ - `md`
332
+ - `json`
333
+ - `toon`
334
+ - `xml`
335
+
336
+ Profiles:
337
+ - `standard`
338
+ - `concise`
339
+ - `headers`
340
+
341
+ Compatibility alias still supported:
342
+ - `--pack-profile`
343
+
344
+ Visibility:
345
+ - no visibility flag preserves existing private-capable local pack behavior
346
+ - `--visibility public` includes only public mdkg records and fails when included records reference internal/private graph, archive, or imported records
347
+ - `--visibility internal` includes public/internal records and fails when included records reference private records
348
+ - `--visibility private` records explicit private intent and may include all records
349
+ - visibility filtering does not inspect or redact arbitrary Markdown body text
350
+
351
+ ### `mdkg skill`
352
+
353
+ When to use:
354
+ - create, discover, inspect, and validate skills
355
+ - orchestrators should use this namespace for stage-tagged skill lookup
356
+
357
+ #### `mdkg skill new`
358
+
359
+ Usage:
360
+ - `mdkg skill new <slug> "<name>" --description "<description>" [options] [--json]`
361
+
362
+ Flags:
363
+ - `--description <text>`
364
+ - `--tags <tag,tag,...>`
365
+ - `--authors <name,name,...>`
366
+ - `--links <url,url,...>`
367
+ - `--run-id <id>`
368
+ - `--json`
369
+ - `--with-scripts`
370
+ - `--force`
371
+
372
+ JSON receipt:
373
+ - `{ action: "created", skill: { workspace, id, qid, slug, name, path, with_scripts } }`
374
+
375
+ #### `mdkg skill sync`
376
+
377
+ Usage:
378
+ - `mdkg skill sync [--force] [--json]`
379
+
380
+ Flags:
381
+ - `--force`
382
+ - `--json`
383
+
384
+ JSON receipt:
385
+ - `{ action: "synced", sync: { synced, pruned, targets } }`
386
+
387
+ Notes:
388
+ - syncs canonical `.mdkg/skills/` into `.agents/skills/` and `.claude/skills/`
389
+ - preserves unrelated existing folders
390
+ - same-slug collisions fail unless forced
391
+
392
+ Scaffold behavior:
393
+ - writes `.mdkg/skills/<slug>/SKILL.md`
394
+ - creates `references/`
395
+ - creates `assets/`
396
+ - creates `scripts/` only with `--with-scripts`
397
+ - updates `.mdkg/skills/registry.md`
398
+
399
+ #### `mdkg skill list`
400
+
401
+ Usage:
402
+ - `mdkg skill list [--tags <tag,tag,...>] [--tags-mode any|all] [--json|--xml|--toon|--md]`
403
+
404
+ Flags:
405
+ - `--tags <tag,tag,...>`
406
+ - `--tags-mode any|all`
407
+ - `--json`
408
+ - `--xml`
409
+ - `--toon`
410
+ - `--md`
411
+
412
+ Notes:
413
+ - text mode prints cards on stdout and `count:` / `note:` on stderr
414
+ - structured outputs are mutually exclusive
415
+ - `--json`, `--xml`, `--toon`, and `--md` all return the same `list` envelope shape
416
+ - preferred orchestrator lookup pattern: `mdkg skill list --tags stage:plan --json`
417
+
418
+ #### `mdkg skill show`
419
+
420
+ Usage:
421
+ - `mdkg skill show <slug> [--meta] [--json|--xml|--toon|--md]`
422
+
423
+ Flags:
424
+ - `--meta`
425
+ - `--json`
426
+ - `--xml`
427
+ - `--toon`
428
+ - `--md`
429
+
430
+ Notes:
431
+ - default behavior prints full skill body
432
+ - `--meta` omits the body
433
+ - structured outputs are mutually exclusive
434
+ - `--json`, `--xml`, `--toon`, and `--md` all return the same `show` envelope shape
435
+
436
+ #### `mdkg skill search`
437
+
438
+ Usage:
439
+ - `mdkg skill search "<query>" [--tags <tag,tag,...>] [--tags-mode any|all] [--json|--xml|--toon|--md]`
440
+
441
+ Flags:
442
+ - `--tags <tag,tag,...>`
443
+ - `--tags-mode any|all`
444
+ - `--json`
445
+ - `--xml`
446
+ - `--toon`
447
+ - `--md`
448
+
449
+ Notes:
450
+ - text mode prints cards on stdout and `count:` / `note:` on stderr
451
+ - structured outputs are mutually exclusive
452
+ - `--json`, `--xml`, `--toon`, and `--md` all return the same `search` envelope shape
453
+ - preferred orchestrator lookup pattern: `mdkg skill search "checkpoint" --tags stage:review --json`
454
+
455
+ #### `mdkg skill validate`
456
+
457
+ Usage:
458
+ - `mdkg skill validate [<slug>] [--json]`
459
+
460
+ Flags:
461
+ - `--json`
462
+
463
+ JSON receipt:
464
+ - `{ action: "validated", ok, checked_count, warning_count, error_count, warnings, errors, target }`
465
+ - `target` is included only when a slug is passed.
466
+
467
+ Notes:
468
+ - validates all skills when no slug is passed
469
+ - validates one skill when a slug is passed
470
+ - reuses the repo skill validation rules
471
+
472
+ ### `mdkg capability`
473
+
474
+ When to use:
475
+ - discover deterministic capability surfaces across enabled workspaces
476
+ - query skills, `SPEC.md`, `WORK.md`, core docs, and design docs without loading the whole graph body set
477
+
478
+ Usage:
479
+ - `mdkg capability list [--kind <kind>] [--visibility <level>] [--json]`
480
+ - `mdkg capability search "<query>" [--kind <kind>] [--visibility <level>] [--json]`
481
+ - `mdkg capability show <id-or-qid-or-slug> [--json]`
482
+ - `mdkg capability resolve [query] [--requires <capability>] [--fresh-only] [--json]`
483
+
484
+ Kinds:
485
+ - `skill`
486
+ - `spec`
487
+ - `work`
488
+ - `core`
489
+ - `design`
490
+
491
+ Visibility levels:
492
+ - `private`
493
+ - `internal`
494
+ - `public`
495
+
496
+ Notes:
497
+ - capability records are derived cache projections from Markdown
498
+ - `capability resolve` ranks local and subgraph capabilities deterministically for orchestration planning
499
+ - stale subgraphs remain visible with degraded ranking unless `--fresh-only` is supplied
500
+ - records include deterministic source metadata such as workspace, visibility, kind, id/qid/slug, path, headings, refs, source hash, and `indexed_at`
501
+ - SPEC and WORK capability records include read-only `linkage` arrays for related SPECs, work contracts, work orders, and receipts when those graph mirrors exist
502
+ - `.mdkg/index/capabilities.json` is rebuilt by `mdkg index` and by capability commands when stale
503
+ - normal task, epic, feat, bug, test, and checkpoint nodes are intentionally excluded
504
+ - visibility is mdkg export metadata used by capability filters, `pack --visibility`, public bundle checks, validation, and doctor diagnostics; it is not secret scanning or body redaction
505
+
506
+ ### `mdkg spec`
507
+
508
+ When to use:
509
+ - list optional `SPEC.md` reusable capability surfaces
510
+ - show one SPEC capability record by id, qid, path, or alias
511
+ - validate the graph while ensuring a named SPEC capability exists
512
+
513
+ Usage:
514
+ - `mdkg spec list [--json]`
515
+ - `mdkg spec show <id-or-qid-or-alias> [--json]`
516
+ - `mdkg spec validate [<id-or-qid-or-alias>] [--json]`
517
+
518
+ Flags:
519
+ - `--json`
520
+
521
+ Notes:
522
+ - `SPEC.md` is optional; repos with no SPEC files remain valid
523
+ - SPEC records are reusable-capability oriented, not documentation-only planning notes
524
+ - `mdkg spec validate` with no ref validates the graph and all optional SPEC records
525
+ - `mdkg spec validate <ref>` also checks that the target SPEC reference exists
526
+ - use `mdkg capability ...` for broader skill, SPEC, WORK, core-doc, and design-doc capability discovery
527
+
528
+ ### `mdkg archive`
529
+
530
+ When to use:
531
+ - register source documents and produced artifacts as mdkg sidecars
532
+ - verify deterministic compressed cache integrity
533
+ - keep raw local archive source copies out of git while committing sidecar metadata and ZIP caches
534
+
535
+ Usage:
536
+ - `mdkg archive add <file> [--id <archive.id>] [--kind source|artifact] [--visibility private|internal|public] [--json]`
537
+ - `mdkg archive add <file> [--id <archive.id>] [--kind source|artifact] [--visibility private|internal|public] [--title <title>] [--refs <...>] [--relates <...>] [--json]`
538
+ - `mdkg archive list [--kind source|artifact] [--visibility private|internal|public] [--json]`
539
+ - `mdkg archive list [--kind source|artifact] [--visibility private|internal|public] [--ws <alias>] [--json]`
540
+ - `mdkg archive show <id-or-archive-uri> [--json]`
541
+ - `mdkg archive show <id-or-archive-uri> [--ws <alias>] [--json]`
542
+ - `mdkg archive verify [id-or-archive-uri] [--json]`
543
+ - `mdkg archive verify [id-or-archive-uri] [--ws <alias>] [--json]`
544
+ - `mdkg archive compress <id-or-archive-uri|--all> [--json]`
545
+ - `mdkg archive compress <id-or-archive-uri> [--ws <alias>] [--json]`
546
+ - `mdkg archive compress --all [--json]`
547
+
548
+ Fields:
549
+ - archive sidecars use `type: archive`
550
+ - ids are portable archive ids such as `archive.key-input-doc`
551
+ - refs use `archive://archive.key-input-doc`
552
+ - sidecars record `archive_kind`, `source_path`, `stored_path`, `compressed_path`, MIME, byte size, SHA-256 hashes, visibility, provenance, and ingest status
553
+
554
+ Notes:
555
+ - `archive add` copies the source, writes a sidecar, and writes a deterministic zip cache
556
+ - in-repo `source_path` values are repo-relative; outside-repo source paths are redacted as `external:<basename>`
557
+ - archive visibility defaults to `private`
558
+ - `archive://<archive.id>` refs are validated against local archive sidecars
559
+ - `archive verify` and `validate` both check the ZIP hash, ZIP readability, payload SHA-256, and payload byte size
560
+ - `archive verify` passes when the raw local source file is missing but the committed sidecar and ZIP cache are valid
561
+ - generated raw source copies live under `.mdkg/archive/**/source/` and are ignored by default
562
+ - `doctor` warns when archive ZIP caches exceed `archive.large_cache_warning_bytes` (default `26214400`; `0` disables)
563
+
564
+ JSON receipts:
565
+ - `add`: `{ action: "created", archive: { workspace, id, qid, path, archive_uri, stored_path, compressed_path, sha256, compressed_sha256, visibility } }`
566
+ - `list`: `{ kind: "archive", count, items }`
567
+ - `show`: `{ kind: "archive", item, attributes }`
568
+ - `verify`: `{ ok, count, results }`
569
+ - `compress`: `{ action: "compressed", count, archives }`
570
+
571
+ ### `mdkg bundle`
572
+
573
+ When to use:
574
+ - create deterministic compressed read-only `.mdkg` graph snapshots
575
+ - give root orchestrators a low-I/O graph transport artifact for child repos
576
+ - verify committed private/public bundle freshness before handoff
577
+
578
+ Usage:
579
+ - `mdkg bundle create [--profile private|public] [--ws <alias|all>] [--output <path>] [--json]`
580
+ - `mdkg bundle verify [bundle-path] [--json]`
581
+ - `mdkg bundle show <bundle-path> [--json]`
582
+ - `mdkg bundle list [--json]`
583
+
584
+ Flags:
585
+ - `--profile private|public`
586
+ - `--ws <alias|all>`
587
+ - `--output <path>`
588
+ - `--json`
589
+
590
+ Notes:
591
+ - default output is `.mdkg/bundles/<profile>/<workspace-or-all>.mdkg.zip`
592
+ - bundle refresh is explicit; `mdkg index` does not rewrite bundles
593
+ - recommended pre-commit order for repos that track archive caches or bundles is `mdkg archive compress --all`, `mdkg archive verify --json`, `mdkg bundle create --profile private`, then `mdkg bundle verify .mdkg/bundles/private/all.mdkg.zip`
594
+ - private bundles include selected authored `.mdkg` content, archive sidecars, archive ZIP caches, and generated bundle-local indexes
595
+ - public bundles include only public workspace content and public archive sidecars
596
+ - public bundles require at least one selected workspace with `visibility: public`
597
+ - public bundle creation fails if public records reference private graph nodes, private archive refs, or private/internal subgraph qids
598
+ - bundles exclude `.mdkg/pack/`, `.mdkg/bundles/`, existing `.mdkg/index/`, and raw `.mdkg/archive/**/source/` files
599
+
600
+ JSON receipts:
601
+ - `create`: `{ action: "created", path, profile, selected_workspaces, file_count, source_tree_hash, bundle_hash, zip_sha256, source }`
602
+ - `verify`: `{ action: "verified", ok, path, profile, selected_workspaces, file_count, stale, errors, stale_paths, bundle_hash, zip_sha256 }`
603
+ - `show`: `{ action: "show", bundle, manifest }`
604
+ - `list`: `{ action: "list", count, items }`
605
+
606
+ ### `mdkg subgraph`
607
+
608
+ When to use:
609
+ - register child graph snapshot bundles as read-only planning context
610
+ - inspect, verify, enable, disable, refresh, audit, upgrade-plan, sync, and materialize configured subgraphs
611
+ - keep root orchestration graph state separate from child repo mutations
612
+
613
+ Usage:
614
+ - `mdkg subgraph add/list/show/rm/enable/disable/verify/refresh/audit/upgrade-plan/sync/materialize ...`
615
+ - `mdkg subgraph add <alias> <bundle-path> [--visibility private|internal|public] [--profile private|public] [--source-path <path>] [--source-repo <ref>] [--max-stale-seconds <seconds>] [--json]`
616
+ - `mdkg subgraph list [--json]`
617
+ - `mdkg subgraph show <alias> [--json]`
618
+ - `mdkg subgraph rm <alias> [--json]`
619
+ - `mdkg subgraph enable <alias> [--json]`
620
+ - `mdkg subgraph disable <alias> [--json]`
621
+ - `mdkg subgraph verify [alias|--all] [--json]`
622
+ - `mdkg subgraph refresh [alias|--all] [--json]`
623
+ - `mdkg subgraph audit [alias|--all] [--target <path>] [--json]`
624
+ - `mdkg subgraph upgrade-plan [alias|--all] [--json]`
625
+ - `mdkg subgraph sync [alias|--all] [--dry-run] [--allow-dirty] [--json]`
626
+ - `mdkg subgraph materialize [alias|--all] --target <path> [--clean] [--gitignore] [--json]`
627
+
628
+ Flags:
629
+ - `--visibility private|internal|public`
630
+ - `--profile private|public`
631
+ - `--source-path <path>`
632
+ - `--source-repo <ref>`
633
+ - `--max-stale-seconds <seconds>`
634
+ - `--target <path>` for audit materialize-target safety checks and materialize output
635
+ - `--dry-run`
636
+ - `--allow-dirty`
637
+ - `--clean`
638
+ - `--gitignore`
639
+ - `--json`
640
+
641
+ Notes:
642
+ - subgraph config lives in `.mdkg/config.json` under `subgraphs`
643
+ - each subgraph defaults to `enabled: true`, `visibility: private`, `permissions: ["read"]`, and `max_stale_seconds: 3600`
644
+ - each subgraph may contain multiple configured sources, but CLI add creates one initial source in this release
645
+ - `mdkg subgraph refresh` reloads configured bundle sources only; it never builds or mutates child repos
646
+ - `mdkg subgraph audit` is read-only and reports typed checks for source_path Git state, bundle validity/freshness, root-owned bundle paths, dirty tracked child files, and optional materialize target marker safety
647
+ - `mdkg subgraph upgrade-plan` is read-only and returns `apply_supported: false`; it proposes safe sync/verify/materialize next steps and blocks on dirty child repos, invalid bundles, unsafe bundle paths, or unusable source paths
648
+ - `mdkg subgraph sync` uses configured `source_path`, requires a contained root-relative clean child Git repo by default, builds the configured root-owned bundle path, verifies it, and records `source_repo` as `<branch>@<sha>`
649
+ - `mdkg subgraph sync --dry-run` writes no bundles, config, or indexes; `--allow-dirty` permits dirty tracked child changes and records them visibly
650
+ - `mdkg subgraph materialize` extracts bundles into generated read-only inspection trees under `<target>/<alias>` and protects clean replacement with `.mdkg-materialized.json`
651
+ - `.mdkg/subgraphs/` materialized views are ignored by local graph indexing, search, validation, packing, bundle creation, and SQLite hydration
652
+ - root-authored `refs`, `relates`, blockers, `scope_refs`, and workflow/archive refs may point at configured subgraph qids such as `child_repo:work.example`; ownership fields such as `epic`, `parent`, `prev`, and `next` remain local-only
653
+ - subgraphs are read-only graph views projected under subgraph-alias qids such as `child_repo:task-1`
654
+ - enabled subgraphs are visible to `list`, `search`, `show`, `pack`, `capability`, and `capability resolve`
655
+ - public/internal subgraphs require public bundle profiles; private bundle profiles cannot be promoted to public/internal visibility
656
+ - stale subgraphs warn during planning reads; `mdkg subgraph verify` exits nonzero for stale or invalid subgraphs
657
+ - mutating commands reject subgraph qids with a read-only subgraph error
658
+ - `mdkg index` writes `.mdkg/index/subgraphs.json` in addition to local indexes
659
+ - legacy `mdkg bundle import ...` exits with guidance to run `mdkg upgrade --apply` and use `mdkg subgraph ...`
660
+
661
+ JSON receipts:
662
+ - `add/enable/disable/refresh`: `{ action, subgraph: { alias, enabled, visibility, permissions, sources, stale, warnings, errors } }`
663
+ - `list`: `{ action: "list", count, subgraphs }`
664
+ - `show`: `{ action: "show", subgraph }`
665
+ - `rm`: `{ action: "removed", subgraph: { alias } }`
666
+ - `verify`: `{ action: "verified", ok, count, subgraphs }`
667
+ - `audit`: `{ action: "audited", ok, count, target?, errors, warnings, subgraphs: [{ alias, capability_summary, checks, dirty_tracked, source_repo_current, ok }] }`
668
+ - `upgrade-plan`: `{ action: "upgrade_plan", ok, count, apply_supported: false, mutation_policy: "read_only_plan", blockers, subgraphs: [{ alias, capability_summary, actions, blockers }] }`
669
+ - `sync`: `{ action: "sync_dry_run"|"synced", ok, count, updated, skipped, errors, warnings, subgraphs }`
670
+ - `materialize`: `{ action: "materialized", ok, count, target, results, errors, warnings }`
671
+
672
+ ### `mdkg work`
673
+
674
+ When to use:
675
+ - create and update `WORK.md`, `WORK_ORDER.md`, and `RECEIPT.md` semantic mirror files
676
+ - attach archived source/artifact sidecars to orders and receipts
677
+
678
+ Usage:
679
+ - `mdkg work contract new ...`
680
+ - `mdkg work trigger <work-or-capability-ref> ...`
681
+ - `mdkg work order new|status|update ...`
682
+ - `mdkg work receipt new|verify|update ...`
683
+ - `mdkg work artifact add ...`
684
+ - `mdkg work contract new "<title>" --id <work.id> --agent-id <agent.id> --kind <kind> --inputs <...> --outputs <...> [--required-capabilities <...>] [--pricing-model <...>] [--json]`
685
+ - `mdkg work trigger <work-or-capability-ref> [--id <order.id>] [--title "<title>"] [--requester <ref>] [--enqueue <queue>] [--json]`
686
+ - `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]`
687
+ - `mdkg work order status <id-or-qid> [--json]`
688
+ - `mdkg work order update <id-or-qid> [--status <status>] [--add-input-refs <...>] [--add-queue-refs <...>] [--add-artifacts <...>] [--json]`
689
+ - `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]`
690
+ - `mdkg work receipt verify <id-or-qid> [--json]`
691
+ - `mdkg work receipt update <id-or-qid> [--receipt-status <status>] [--add-artifacts <...>] [--add-proof-refs <...>] [--add-attestation-refs <...>] [--add-evidence-hashes <sha256:...>] [--json]`
692
+ - `mdkg work artifact add <order-or-receipt-id-or-qid> <file> [--id <archive.id>] [--kind source|artifact] [--json]`
693
+
694
+ Notes:
695
+ - work commands mutate semantic mirror files only
696
+ - production order, receipt, feedback, dispute, payment, ledger, marketplace inventory, fulfillment, and execution state remains canonical outside mdkg
697
+ - do not store raw secrets, credentials, live payment state, ledger mutations, or canonical marketplace state in work mirrors
698
+ - `artifact://...` refs identify external/runtime-managed artifacts; `archive://...` refs identify committed mdkg archive sidecars
699
+ - `work trigger` accepts a `WORK.md` ref directly or a `SPEC.md` capability ref with exactly one resolvable work contract; it creates a submitted order mirror and never executes work
700
+ - example: `mdkg work trigger work.example --id order.example-1 --requester user://example --json`
701
+ - `work trigger --enqueue <queue>` requires a valid project DB plus an explicitly created active queue, creates a submitted order mirror, and enqueues a local delivery message without executing work
702
+ - `work order new` accepts URI-style requester/request/trigger refs, archive input refs, optional queue refs, and stable payload hashes
703
+ - `work order status` is read-only and reports deterministic order state plus linked receipts
704
+ - `work receipt new` accepts URI-style cost/proof/attestation refs, explicit redaction policy, and SHA-256 evidence/input/output hash refs
705
+ - `work receipt verify` is read-only and reports linkage, evidence, archive ref, hash, outcome, and redaction-policy checks; invalid receipts print JSON before exiting nonzero
706
+ - `work artifact add` calls `mdkg archive add`, then attaches the resulting `archive://...` ref to the target order or receipt
707
+ - `work order update`, `work receipt update`, and `work artifact add` accept local ids or local qids; subgraph qids are read-only and must be changed in their source workspace
708
+
709
+ JSON receipts:
710
+ - `contract new`, `order new`, `order update`, `receipt new`, and `receipt update`: `{ action, node }`
711
+ - `trigger`: `{ action: "triggered", node, trigger: { target_ref, source_qid?, work_qid, payload_hash, executed, enqueue, event_appended } }`
712
+ - `order status`: `{ kind: "work_order_status", order, receipt_count, receipts }`
713
+ - `receipt verify`: `{ kind: "work_receipt_verify", ok, receipt, work_order?, checks, errors, warnings }`
714
+ - `artifact add`: `{ action: "artifact_registered", target, archive }`
715
+
716
+ ### `mdkg goal`
717
+
718
+ When to use:
719
+ - inspect and guide a recursive long-running objective
720
+ - select the next concrete local work item inside a goal
721
+ - update goal state after human or agent review
722
+
723
+ Usage:
724
+ - `mdkg goal show <goal-id-or-qid> [--json]`
725
+ - `mdkg goal select <goal-id-or-qid> [--json]`
726
+ - `mdkg goal current [--json]`
727
+ - `mdkg goal clear [--json]`
728
+ - `mdkg goal next [goal-id-or-qid] [--json]`
729
+ - `mdkg goal claim [goal-id-or-qid] <work-id-or-qid> [--json]`
730
+ - `mdkg goal evaluate <goal-id-or-qid> [--json]`
731
+ - `mdkg goal pause|resume|done <goal-id-or-qid> [--json]`
732
+ - `mdkg goal show <goal-id-or-qid> [--ws <alias>] [--json]`
733
+ - `mdkg goal select <goal-id-or-qid> [--ws <alias>] [--json]`
734
+ - `mdkg goal current [--ws <alias>] [--json]`
735
+ - `mdkg goal next [goal-id-or-qid] [--ws <alias>] [--json]`
736
+ - `mdkg goal claim <work-id-or-qid> [--ws <alias>] [--json]`
737
+ - `mdkg goal claim <goal-id-or-qid> <work-id-or-qid> [--ws <alias>] [--json]`
738
+ - `mdkg goal evaluate <goal-id-or-qid> [--ws <alias>] [--json]`
739
+ - `mdkg goal pause <goal-id-or-qid> [--ws <alias>] [--json]`
740
+ - `mdkg goal resume <goal-id-or-qid> [--ws <alias>] [--json]`
741
+ - `mdkg goal done <goal-id-or-qid> [--ws <alias>] [--json]`
742
+
743
+ Behavior:
744
+ - `goal show` reports goal condition, goal state, scope refs, active node, required skills, required checks, and source path.
745
+ - `goal select` writes local ignored selected-goal state so `goal next` can omit the goal id.
746
+ - `goal current` shows the selected goal or unique active goal fallback.
747
+ - `goal clear` removes local selected-goal state.
748
+ - `goal next` is read-only and selects feature, task, bug, or test work inside explicit `scope_refs`; epics are recursive containers, not executable returns.
749
+ - `goal claim` mutates only `active_node` after the work item is confirmed inside the goal scope.
750
+ - `goal evaluate` is report-only and never runs commands from `required_checks`.
751
+ - `goal pause`, `goal resume`, and `goal done` update `goal_state`, compatible work status, and `updated`.
752
+ - subgraph goal qids are read-only; update the source workspace instead.
753
+
754
+ JSON receipts:
755
+ - `show`: `{ action: "showed", goal }`
756
+ - `select`: `{ action: "selected_goal", goal, selection }`
757
+ - `current`: `{ action: "current", goal, source, warnings }`
758
+ - `clear`: `{ action: "cleared_goal", path, cleared }`
759
+ - `next`: `{ action: "selected", goal, goal_source, node, warnings }`
760
+ - `claim`: `{ action: "claimed", goal, node }`
761
+ - `evaluate`: `{ action: "evaluated", goal, report_only, runs_scripts, checks, completion_evidence_present }`
762
+ - `pause|resume|done`: `{ action, goal }`
763
+
764
+ ### `mdkg task`
765
+
766
+ When to use:
767
+ - mutate structured task-like fields and capture routine lifecycle evidence
768
+ - keep narrative/body edits and manual parent summaries in markdown
769
+ - optionally append baseline task events when event logging is enabled
770
+
771
+ Usage:
772
+ - `mdkg task start <id-or-qid> [--ws <alias>] [--run-id <id>] [--note "<text>"] [--json]`
773
+ - `mdkg task update <id-or-qid> [options] [--json]`
774
+ - `mdkg task done <id-or-qid> [--checkpoint "<title>"] [options] [--json]`
775
+
776
+ #### `mdkg task start`
777
+
778
+ Usage:
779
+ - `mdkg task start <id-or-qid> [--ws <alias>] [--run-id <id>] [--note "<text>"] [--json]`
780
+
781
+ Behavior:
782
+ - supports `task`, `bug`, and `test` only
783
+ - sets `status: progress`
784
+ - if `events.jsonl` is missing for the workspace, prints a short `stderr` reminder about `mdkg event enable`
785
+
786
+ JSON receipt:
787
+ - `{ action: "started", task: { workspace, id, qid, path, type, status, priority } }`
788
+
789
+ #### `mdkg task update`
790
+
791
+ Usage:
792
+ - `mdkg task update <id-or-qid> [--ws <alias>] [--status <status>] [--priority <n>]`
793
+ - ` [--add-artifacts <a,...>] [--add-links <l,...>] [--add-refs <id,...>]`
794
+ - ` [--add-skills <slug,...>] [--add-tags <tag,...>] [--add-blocked-by <id,...>]`
795
+ - ` [--clear-blocked-by] [--run-id <id>] [--note "<text>"] [--json]`
796
+
797
+ Behavior:
798
+ - supports `task`, `bug`, and `test` only
799
+ - list mutations are additive and unique
800
+ - scalar fields replace existing values
801
+ - `--clear-blocked-by` clears blockers before optional re-add
802
+
803
+ JSON receipt:
804
+ - `{ action: "updated", task: { workspace, id, qid, path, type, status, priority } }`
805
+
806
+ #### `mdkg task done`
807
+
808
+ Usage:
809
+ - `mdkg task done <id-or-qid> [--ws <alias>] [--add-artifacts <a,...>] [--add-links <l,...>]`
810
+ - ` [--add-refs <id,...>] [--checkpoint "<title>"] [--run-id <id>] [--note "<text>"] [--json]`
811
+
812
+ Behavior:
813
+ - supports `task`, `bug`, and `test` only
814
+ - sets `status: done`
815
+ - `--checkpoint` creates a related checkpoint
816
+ - if `events.jsonl` is missing for the workspace, prints a short `stderr` reminder about `mdkg event enable`
817
+
818
+ JSON receipt:
819
+ - without checkpoint: `{ action: "done", task: { workspace, id, qid, path, type, status, priority } }`
820
+ - with checkpoint: `{ action: "done", task: { workspace, id, qid, path, type, status, priority }, checkpoint: { workspace, id, qid, path } }`
821
+
822
+ Closeout guidance:
823
+ - use `--checkpoint` for milestone compression and parent closeout summaries
824
+ - do not create a checkpoint for every routine task completion
825
+ - feat/epic status edits remain manual; use checkpoints as the durable narrative layer
826
+
827
+ ### `mdkg next`
828
+
829
+ When to use:
830
+ - ask mdkg for the next work item to pull forward
831
+
832
+ Usage:
833
+ - `mdkg next [<id-or-qid>] [--ws <alias>]`
834
+
835
+ Flags:
836
+ - `--ws <alias>`
837
+
838
+ ### `mdkg validate`
839
+
840
+ When to use:
841
+ - run the repo trust gate before calling work done
842
+
843
+ Usage:
844
+ - `mdkg validate [--out <path>] [--quiet] [--json]`
845
+
846
+ Flags:
847
+ - `--out <path>`
848
+ - `--quiet`
849
+ - `--json`
850
+
851
+ JSON receipt:
852
+ - `{ action: "validated", ok, warning_count, error_count, warnings, errors, report_path }`
853
+ - `report_path` is included only when `--out` is used.
854
+
855
+ Notes:
856
+ - validates nodes, graph integrity, skills, and event log contracts
857
+
858
+ ## Advanced / maintenance commands
859
+
860
+ ### `mdkg event`
861
+
862
+ When to use:
863
+ - ensure or append append-only episodic logs
864
+ - keep a durable provenance trail for mutating workflows
865
+
866
+ #### `mdkg event enable`
867
+
868
+ Usage:
869
+ - `mdkg event enable [--ws <alias>] [--json]`
870
+
871
+ Behavior:
872
+ - creates `.mdkg/work/events/events.jsonl` if missing
873
+ - leaves `.gitignore` unchanged
874
+ - automatic command-level events happen when the file exists
875
+ - task start/done reminders point here when `events.jsonl` is missing
876
+
877
+ JSON receipt:
878
+ - `{ action: "enabled", workspace, created }`
879
+
880
+ #### `mdkg event append`
881
+
882
+ Usage:
883
+ - `mdkg event append --kind <kind> --status <ok|error|retry|skipped> --refs <id,...> [options] [--json]`
884
+
885
+ Flags:
886
+ - `--ws <alias>`
887
+ - `--artifacts <a,...>`
888
+ - `--notes "<text>"`
889
+ - `--run-id <id>`
890
+ - `--agent <name>`
891
+ - `--skill <slug>`
892
+ - `--tool <id>`
893
+ - `--json`
894
+
895
+ JSON receipt:
896
+ - `{ action: "appended", event }`
897
+
898
+ ### `mdkg checkpoint`
899
+
900
+ Usage:
901
+ - `mdkg checkpoint new <title> [--ws <alias>] [--json]`
902
+ - ` [--relates <id,id,...>] [--scope <id,id,...>] [--run-id <id>] [--note "<text>"]`
903
+
904
+ JSON receipt:
905
+ - `{ action: "created", checkpoint: { workspace, id, qid, path } }`
906
+
907
+ ### `mdkg index`
908
+
909
+ Usage:
910
+ - `mdkg index [--tolerant]`
911
+
912
+ Notes:
913
+ - writes `.mdkg/index/global.json`
914
+ - writes `.mdkg/index/skills.json`
915
+ - writes `.mdkg/index/capabilities.json`
916
+ - writes `.mdkg/index/subgraphs.json`
917
+ - writes `.mdkg/index/mdkg.sqlite` when `index.backend` is `sqlite`
918
+
919
+ ### `mdkg db`
920
+
921
+ Usage:
922
+ - `mdkg db index rebuild [--tolerant] [--json]`
923
+ - `mdkg db index status [--json]`
924
+ - `mdkg db index verify [--json]`
925
+ - `mdkg db init [--json]`
926
+ - `mdkg db migrate [--json]`
927
+ - `mdkg db verify [--json]`
928
+ - `mdkg db stats [--json]`
929
+ - `mdkg db queue create <queue> [--paused] [--reason <text>] [--json]`
930
+ - `mdkg db queue pause <queue> [--reason <text>] [--json]`
931
+ - `mdkg db queue resume <queue> [--json]`
932
+ - `mdkg db queue enqueue <queue> <message-id> --payload-json <json>|--payload-file <path> [--dedupe-key <key>] [--available-at-ms <ms>] [--max-attempts <n>] [--json]`
933
+ - `mdkg db queue enqueue <queue> <message-id> --payload-json <json>|--payload-file <path> [--json]`
934
+ - `mdkg db queue claim <queue> --lease-owner <owner> --lease-ms <ms> [--json]`
935
+ - `mdkg db queue ack <queue> <message-id> --lease-owner <owner> [--json]`
936
+ - `mdkg db queue fail <queue> <message-id> --lease-owner <owner> --error <text> [--retry-after-ms <ms>] [--json]`
937
+ - `mdkg db queue dead-letter <queue> <message-id> --lease-owner <owner> --error <text> [--json]`
938
+ - `mdkg db queue ack|fail|dead-letter <queue> <message-id> --lease-owner <owner> [--json]`
939
+ - `mdkg db queue release-expired [queue] [--json]`
940
+ - `mdkg db queue pause|resume <queue> [--json]`
941
+ - `mdkg db queue stats [queue] [--json]`
942
+ - `mdkg db queue list <queue> [--status ready|leased|acked|dead_letter|all] [--limit <n>] [--json]`
943
+ - `mdkg db queue show <queue> <message-id> [--json]`
944
+ - `mdkg db queue stats|list|show ... [--json]`
945
+ - `mdkg db snapshot seal [--queue-policy drain|paused] [--json]`
946
+ - `mdkg db snapshot verify [--json]`
947
+ - `mdkg db snapshot status [--json]`
948
+ - `mdkg db snapshot dump [--snapshot <path>] [--output <path>] [--json]`
949
+ - `mdkg db snapshot diff <left-snapshot> <right-snapshot> [--json]`
950
+
951
+ Boundaries:
952
+ - `.mdkg/index` is the rebuildable graph access cache
953
+ - `.mdkg/db` is project application state
954
+ - `mdkg db init` creates the generic `.mdkg/db` scaffold, writes
955
+ `.mdkg/db/project-db.json`, and enables `db.enabled`
956
+ - `mdkg db init` does not create an active runtime SQLite database
957
+ - `mdkg db migrate` creates or updates the active runtime SQLite database at
958
+ `db.runtime_path` and applies mdkg-owned foundation plus internal local
959
+ node:sqlite queue, event/receipt/reducer, and writer lease/CAS foundation
960
+ migrations
961
+ - `mdkg db migrate` records migration order, checksums, and applied timestamps
962
+ in the configured migration table
963
+ - `mdkg db queue ...` exposes durable local delivery operations backed by
964
+ node:sqlite; queue rows are delivery state, not canonical event history
965
+ - paused queues reject enqueue and claim, but ack/fail/dead-letter and
966
+ release-expired remain available so leased work can settle
967
+ - event tables are durable local history for project DB state transitions;
968
+ receipts, typed reducers, writer leases, and materializers remain internal
969
+ helper surfaces in this release, with no public `mdkg db event`,
970
+ `mdkg db reducer`, `mdkg db lease`, or `mdkg db materializer` CLI yet
971
+ - `mdkg db verify` checks config, layout, runtime SQLite integrity, migration
972
+ metadata, receipt directory policy, and transient runtime files
973
+ - `mdkg db stats` reports table counts, database size, migration state,
974
+ transient runtime files, receipt-file count, and state snapshot presence
975
+ - `mdkg db snapshot seal` creates an opt-in sealed checkpoint under
976
+ `.mdkg/db/state` with a deterministic manifest and content hash; default
977
+ `--queue-policy drain` requires no ready or leased messages, while
978
+ `--queue-policy paused` allows ready messages only in paused queues
979
+ - `mdkg db snapshot verify` and `mdkg db snapshot status` inspect sealed
980
+ snapshot integrity, manifest drift, runtime freshness, and WAL/transient
981
+ warning state
982
+ - `mdkg db snapshot dump` and `mdkg db snapshot diff` provide deterministic
983
+ review aids for SQLite snapshots; they are not a new source of truth
984
+ - `mdkg index` remains the compatibility shortcut for index rebuilds
985
+ - no raw SQL, hosted queue/event store, profile, public
986
+ event/reducer/lease/materializer command, or publish behavior is exposed here
987
+ - active `.mdkg/db/runtime/` files and `.mdkg/db` WAL/SHM/journal/lock/temp
988
+ files are ignored by default; schema, receipts, manifests, and sealed state
989
+ snapshots are commit-eligible only by explicit repo policy
990
+
991
+ Index behavior:
992
+ - `mdkg db index rebuild` writes the same derived caches as `mdkg index`
993
+ - `mdkg db index status` reports cache health without mutating files
994
+ - `mdkg db index verify` fails on missing, stale, corrupt, schema-mismatched,
995
+ or SQLite source-fingerprint-mismatched cache state
996
+
997
+ ### `mdkg guide`
998
+
999
+ Usage:
1000
+ - `mdkg guide`
1001
+
1002
+ ### `mdkg format`
1003
+
1004
+ Usage:
1005
+ - `mdkg format`
1006
+
1007
+ ### `mdkg status`
1008
+
1009
+ Usage:
1010
+ - `mdkg status [--json]`
1011
+
1012
+ When to use:
1013
+ - get a read-only operator summary for scripts and agents
1014
+ - inspect release/package, git, graph, selected-goal, project DB, and generated-cache health before mutating work
1015
+
1016
+ Boundaries:
1017
+ - does not rebuild indexes, repair files, run migrations, write graph nodes, mutate selected-goal state, or change project DB state
1018
+ - dirty git state and stale generated caches are warnings, not automatic repair instructions
1019
+ - use `mdkg doctor` for diagnostic detail and future strict typed checks
1020
+
1021
+ JSON receipt shape:
1022
+ - `{ action: "status", ok, level, root, mdkg, git, release, graph, goal, db, generated, summary }`
1023
+ - `level` is `ok`, `warn`, or `fail`
1024
+ - `git` includes `inside`, `branch`, `dirty`, `dirty_count`, `untracked_count`, `ahead`, and `behind`
1025
+ - `graph` includes `ok`, `node_count`, `workspace_count`, `stale`, `warning_count`, and `error_count`
1026
+ - `goal` includes selected-goal state, existence, achieved-state, active node, goal state, and work status
1027
+ - `db` reports disabled state or project DB verification summary
1028
+ - `generated` reports index, skills, capabilities, and subgraph cache existence/staleness
1029
+ - `summary` includes machine-readable warning and error counts plus messages
1030
+
1031
+ ### `mdkg fix`
1032
+
1033
+ When to use:
1034
+ - plan reviewable graph/index repairs before any apply command exists
1035
+ - get a receipt-shaped JSON plan for automation and agent review
1036
+
1037
+ Usage:
1038
+ - `mdkg fix plan [--family index|refs|ids|all] [--target <id-or-qid>] [--json]`
1039
+
1040
+ Flags:
1041
+ - `--family <family>`
1042
+ - `--target <id-or-qid>`
1043
+ - `--json`
1044
+
1045
+ Boundaries:
1046
+ - dry-run only and writes nothing
1047
+ - does not rebuild indexes, edit graph files, rename ids, or update references
1048
+ - `fix apply` is intentionally not available in the first repair-planning slice
1049
+ - initial families are index/cache, graph refs, and duplicate ids
1050
+
1051
+ JSON receipt:
1052
+ - `{ action: "fix.plan", ok, schema_version, plan_id, plan_hash, generated_at, root, family, target, dirty, families, risk_counts, proposed_changes, blocked_changes, summary }`
1053
+ - each proposed change includes family, risk, status, reason, paths, refs, optional before/after values, command hint, and `apply_supported: false`
1054
+ - `summary.apply_deferred` remains true until a future apply design is approved
1055
+
1056
+ ### `mdkg doctor`
1057
+
1058
+ Usage:
1059
+ - `mdkg doctor [--strict] [--json]`
1060
+
1061
+ Checks:
1062
+ - Node.js version compatibility
1063
+ - config and template availability
1064
+ - selected-goal stale, missing, or achieved state
1065
+ - project DB verification when project DB is enabled
1066
+ - global node index health
1067
+ - capability cache health
1068
+ - SQLite cache health when enabled
1069
+ - archive sidecar storage hygiene
1070
+ - archive large-cache warning threshold
1071
+ - bundle snapshot storage guidance
1072
+
1073
+ Flags:
1074
+ - `--strict`
1075
+ - `--json`
1076
+
1077
+ Strict mode:
1078
+ - keeps the command read-only
1079
+ - fails on invalid graph/index load, stale achieved selected goal, enabled
1080
+ project DB verification failure, and generated cache failures
1081
+ - reports dirty/runtime/storage concerns as typed warnings unless their
1082
+ underlying check already fails
1083
+
1084
+ JSON receipt shape:
1085
+ - `{ action: "doctor", ok, strict, checks, summary, failure_count }`
1086
+ - each check keeps compatibility fields `name`, `ok`, `level`, and `detail`
1087
+ - each check also includes typed fields `id`, `status`, `severity`,
1088
+ `message`, `remediation`, and optional `refs`
1089
+ - `status` is `pass`, `warn`, `fail`, or `info`
1090
+ - `severity` is `info`, `warning`, or `error`
1091
+
1092
+ ### `mdkg workspace`
1093
+
1094
+ Usage:
1095
+ - `mdkg workspace ls [--json]`
1096
+ - `mdkg workspace add <alias> <path> [--mdkg-dir <dir>] [--visibility <level>] [--json]`
1097
+ - `mdkg workspace rm <alias> [--json]`
1098
+ - `mdkg workspace enable <alias> [--json]`
1099
+ - `mdkg workspace disable <alias> [--json]`
1100
+
1101
+ JSON mutation receipts:
1102
+ - `add`: `{ action: "added", workspace: { alias, path, enabled, mdkg_dir, visibility } }`
1103
+ - `rm`: `{ action: "removed", workspace: { alias, path, enabled, mdkg_dir, visibility } }`
1104
+ - `enable`: `{ action: "enabled", workspace: { alias, path, enabled, mdkg_dir, visibility } }`
1105
+ - `disable`: `{ action: "disabled", workspace: { alias, path, enabled, mdkg_dir, visibility } }`
1106
+
1107
+ ## Structured output contract
1108
+
1109
+ Current structured output surface:
1110
+ - `--json`
1111
+ - `--xml`
1112
+ - `--toon`
1113
+ - `--md`
1114
+
1115
+ Current JSON envelopes:
1116
+ - `list` / `search`
1117
+ - `{ command, kind, count, items }`
1118
+ - `show`
1119
+ - `{ command, kind, item }`
1120
+ - `skill list` / `skill search`
1121
+ - `{ command, kind, count, items }`
1122
+ - `skill show`
1123
+ - `{ command, kind, item }`
1124
+ - `capability list` / `capability search`
1125
+ - `{ kind: "capability", query?, count, items }`
1126
+ - `capability show`
1127
+ - `{ kind: "capability", item }`
1128
+ - `capability resolve`
1129
+ - `{ kind: "capability_resolve", query?, requires?, fresh_only, count, items, warnings }`
1130
+ - `spec list`
1131
+ - `{ kind: "spec", count, items }`
1132
+ - `spec show`
1133
+ - `{ kind: "spec", item }`
1134
+ - `spec validate`
1135
+ - `{ action: "validated", ok, warning_count, error_count, warnings, errors, report_path? }`
1136
+ - `archive add` / `archive list` / `archive show` / `archive verify` / `archive compress`
1137
+ - archive-specific JSON receipts documented in the `mdkg archive` section
1138
+ - `work ...`
1139
+ - semantic mirror mutation receipts documented in the `mdkg work` section
1140
+
1141
+ Kind values in this wave:
1142
+ - node commands: `node`
1143
+ - skill commands: `skill`
1144
+ - capability commands: `capability`
1145
+ - spec commands: `spec`
1146
+ - archive commands: `archive`
1147
+
1148
+ JSON behavior rules:
1149
+ - full bodies are returned only by `show` and `skill show` without `--meta`
1150
+ - list/search summaries never include bodies
1151
+ - skill summaries include generic `extensions`; `ochatr_*` metadata is exposed as `extensions.ochatr` and retained as top-level `ochatr` compatibility data in 0.0.9
1152
+ - text notes and counts go to `stderr`
1153
+ - JSON payloads go to `stdout`
1154
+
1155
+ ## Event logging contract
1156
+
1157
+ Explicit commands:
1158
+ - `mdkg event enable`
1159
+ - `mdkg event append`
1160
+
1161
+ Automatic baseline events append only when `events.jsonl` exists for the workspace.
1162
+ Current automatic mutation events:
1163
+ - `NODE_CREATED`
1164
+ - `SKILL_CREATED`
1165
+ - `CHECKPOINT_CREATED`
1166
+ - `TASK_STARTED`
1167
+ - `TASK_UPDATED`
1168
+ - `TASK_DONE`
1169
+
1170
+ ## Deferred follow-up work
1171
+
1172
+ Tracked separately:
1173
+ - XML discovery/show output
1174
+ - TOON discovery/show output
1175
+ - Markdown discovery/show output
1176
+ - additional coverage hardening beyond the current release wave