mdkg 0.3.0 → 0.3.2

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