mdkg 0.4.2 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +88 -15
  2. package/CLI_COMMAND_MATRIX.md +74 -5
  3. package/README.md +30 -2
  4. package/dist/cli.js +132 -5
  5. package/dist/command-contract.json +778 -16
  6. package/dist/commands/archive.js +196 -42
  7. package/dist/commands/bundle.js +180 -44
  8. package/dist/commands/capability.js +1 -0
  9. package/dist/commands/checkpoint.js +6 -5
  10. package/dist/commands/event_support.js +16 -7
  11. package/dist/commands/fix.js +11 -8
  12. package/dist/commands/git.js +41 -10
  13. package/dist/commands/goal.js +23 -23
  14. package/dist/commands/graph.js +64 -10
  15. package/dist/commands/handoff.js +4 -2
  16. package/dist/commands/init.js +28 -23
  17. package/dist/commands/loop.js +1668 -0
  18. package/dist/commands/loop_descriptors.js +219 -0
  19. package/dist/commands/mcp.js +101 -11
  20. package/dist/commands/new.js +49 -3
  21. package/dist/commands/pack.js +14 -7
  22. package/dist/commands/search.js +10 -1
  23. package/dist/commands/skill.js +12 -9
  24. package/dist/commands/skill_mirror.js +39 -31
  25. package/dist/commands/subgraph.js +59 -26
  26. package/dist/commands/task.js +77 -4
  27. package/dist/commands/upgrade.js +13 -15
  28. package/dist/commands/validate.js +20 -7
  29. package/dist/commands/work.js +44 -26
  30. package/dist/commands/workspace.js +10 -4
  31. package/dist/core/config.js +45 -17
  32. package/dist/core/filesystem_authority.js +281 -0
  33. package/dist/core/project_db_events.js +4 -0
  34. package/dist/core/project_db_materializer.js +2 -0
  35. package/dist/core/project_db_migrations.js +238 -181
  36. package/dist/core/project_db_snapshot.js +64 -14
  37. package/dist/core/workspace_path.js +7 -0
  38. package/dist/graph/archive_integrity.js +1 -1
  39. package/dist/graph/capabilities_index_cache.js +4 -1
  40. package/dist/graph/frontmatter.js +38 -0
  41. package/dist/graph/goal_scope.js +4 -1
  42. package/dist/graph/index_cache.js +37 -7
  43. package/dist/graph/loop_bindings.js +39 -0
  44. package/dist/graph/node.js +209 -1
  45. package/dist/graph/node_body.js +52 -6
  46. package/dist/graph/skills_index_cache.js +41 -6
  47. package/dist/graph/skills_indexer.js +5 -2
  48. package/dist/graph/sqlite_index.js +118 -105
  49. package/dist/graph/subgraphs.js +142 -5
  50. package/dist/graph/validate_graph.js +109 -13
  51. package/dist/graph/workspace_files.js +39 -9
  52. package/dist/init/AGENT_START.md +16 -0
  53. package/dist/init/CLI_COMMAND_MATRIX.md +14 -0
  54. package/dist/init/config.json +7 -1
  55. package/dist/init/init-manifest.json +49 -4
  56. package/dist/init/skills/default/pursue-mdkg-loop/SKILL.md +150 -0
  57. package/dist/init/templates/default/loop.md +160 -0
  58. package/dist/init/templates/loops/backend-api-cli-bloat-audit.loop.md +117 -0
  59. package/dist/init/templates/loops/design-frontend-ux-audit.loop.md +117 -0
  60. package/dist/init/templates/loops/duplicate-code-and-linting-audit.loop.md +114 -0
  61. package/dist/init/templates/loops/security-audit.loop.md +140 -0
  62. package/dist/init/templates/loops/tech-stack-best-practices-audit.loop.md +116 -0
  63. package/dist/init/templates/loops/test-ci-skill-infrastructure-audit.loop.md +116 -0
  64. package/dist/init/templates/loops/user-story-audit-and-recommendations.loop.md +116 -0
  65. package/dist/pack/order.js +3 -1
  66. package/dist/pack/pack.js +139 -6
  67. package/dist/templates/loader.js +9 -3
  68. package/dist/util/lock.js +10 -9
  69. package/dist/util/zip.js +163 -9
  70. package/package.json +8 -4
package/CHANGELOG.md CHANGED
@@ -8,6 +8,83 @@ mdkg is pre-v1 public alpha software. Command, graph, cache, bundle, and DAL con
8
8
 
9
9
  ## Unreleased
10
10
 
11
+ ## 0.5.1 - 2026-07-14
12
+
13
+ ### Changed
14
+
15
+ - Archive compression now derives writable ownership from enabled local
16
+ workspaces. `archive compress --all --ws <local-alias>` limits bulk selection,
17
+ and exact workspace-qualified archive qids are supported for direct targets.
18
+ - Archive compression JSON receipts preserve existing fields and add selected
19
+ workspace and read-only imported-projection exclusion evidence.
20
+
21
+ ### Fixed
22
+
23
+ - Fixed `archive compress --all` traversing imported subgraph ZIP-fragment paths
24
+ and potentially mutating earlier local archives before a later invalid target
25
+ failed. Imported archives remain discoverable but fail closed for direct
26
+ compression, and the complete local selection is preflighted before writes.
27
+
28
+ ## 0.5.0 - 2026-07-11
29
+
30
+ ### Added
31
+
32
+ - Added `loop` as a first-class mdkg work node for reusable, durable agentic
33
+ processes that can coordinate goals, tasks, tests, spikes, proposals,
34
+ decisions, checkpoints, receipts, evidence, and repeated attempts.
35
+ - Added the semantic `mdkg loop list`, `show`, `fork`, `plan`, `next`, and
36
+ `runs` command family, plus deterministic `mdkg new loop` guidance for raw
37
+ loops versus bundled templates.
38
+ - Added identity-bound loop readiness metadata for pre-run questions, action
39
+ approvals, evidence lanes, and paired decision/approval waivers.
40
+ - Added immutable template provenance, content hashes, stale-fork warnings,
41
+ default child materialization, and an explicit planning-only fork mode.
42
+ - Added seven bundled read-only or planning loop templates for security,
43
+ frontend design, backend/API/CLI design, tech-stack practices, duplication
44
+ and linting, test/CI/skill infrastructure, and user-story audits.
45
+ - Added the reusable `pursue-mdkg-loop` agent skill to keep authorized child
46
+ lanes moving, recover blockers through grounded spikes and proposals, and
47
+ close only against the loop definition of done.
48
+ - Added a gated mdkg.dev announcement and top-level Loops documentation with a
49
+ purpose-built read-only security audit walkthrough. Public promotion remains
50
+ controlled by the shared source release manifest.
51
+
52
+ ### Changed
53
+
54
+ - Integrated loops into parser/template validation, generic discovery,
55
+ SQLite/JSON indexes, search/show/list output, deterministic pack traversal,
56
+ generated help, command contracts, init assets, and upgrade fallback paths.
57
+ - Made loop fork dry-runs observational across JSON and SQLite backends: no ID
58
+ reservation, event write, index persistence, or graph/filesystem mutation.
59
+ - Made read-only loop commands use non-persisting index projections and made
60
+ `loop next` exhaust authorized nested work and blocker-recovery lanes before
61
+ reporting the whole loop blocked.
62
+ - Kept loop templates, scoped forks, and run-bearing state under one `loop`
63
+ node type; mdkg preserves orchestration state while the coding-agent harness
64
+ remains responsible for executing agents and tools.
65
+ - Added installed-package smoke coverage for every bundled loop template and a
66
+ public-repository release-readiness workflow across the minimum supported
67
+ Node version and current Node line.
68
+ - Cleaned mdkg.dev/docs public copy and demo proof surfaces while preserving
69
+ the existing quickstart-first product journey and Pre-v1 public-alpha scope.
70
+
71
+ ### Fixed
72
+
73
+ - Fixed readiness projection so unrelated decisions, approvals, evidence, and
74
+ waivers cannot satisfy a different question, action, or evidence lane.
75
+ - Fixed loop routing so one blocked child does not halt other authorized work,
76
+ and whole-loop blocking occurs only after useful work and recovery paths are
77
+ exhausted.
78
+ - Fixed stale-template handling to warn from recorded template identity and
79
+ content hash without silently rewriting scoped forks.
80
+
81
+ ### Security
82
+
83
+ - Hardened graph target writes against symlink containment escapes before any
84
+ destination mutation.
85
+ - Bounded ZIP entry count, compressed size, declared output, total output, and
86
+ expansion ratio before bundle or subgraph inflation.
87
+
11
88
  ## 0.4.2 - 2026-07-05
12
89
 
13
90
  ### Added
@@ -63,33 +140,29 @@ mdkg is pre-v1 public alpha software. Command, graph, cache, bundle, and DAL con
63
140
  `resource_profile`, WORK `kind`, WORK_ORDER `artifact_policy`, RECEIPT
64
141
  `redaction_policy`, `receipt_kind`, `redaction_class`, and pack/bundle
65
142
  `--profile` flags.
66
- - Expanded release-readiness documentation and checks for `0.4.1` so the
67
- implementation can hand off to a separate approval-gated publish goal.
143
+ - Expanded documentation and validation checks for `0.4.1` so package readiness
144
+ can be verified before publication.
68
145
 
69
146
  ## 0.4.0 - 2026-06-27
70
147
 
71
148
  ### Added
72
149
 
73
- - Added the `0.4.0` public launch-readiness lane for mdkg.dev and
74
- docs.mdkg.dev with explicit source metadata, changelog, generated-doc,
75
- npm prepublish, npm postpublish, Vercel production, and Chrome live-validation
76
- blockers.
77
- - Added public release-note and docs coverage for the `0.4.0` launch surface,
78
- including per-release changelog cards, launch-track copy, and source-backed
79
- currentness requirements.
80
- - Added Vercel production currentness and Chrome postpublish validation as
81
- required evidence before mdkg.dev or docs.mdkg.dev can claim the `0.4.0`
82
- launch is live.
150
+ - Added public release cards and changelog detail pages for recent public-alpha
151
+ versions.
152
+ - Added docs coverage for config overlays, custom skill mirrors,
153
+ `COLLABORATION.md`, MANIFEST naming, and public-alpha customization guidance.
154
+ - Added mdkg.dev and docs.mdkg.dev copy updates that keep public claims bounded
155
+ to documented capabilities.
83
156
 
84
157
  ### Changed
85
158
 
86
- - Updated mdkg.dev and docs.mdkg.dev source copy for the `0.4.0` release target,
159
+ - Updated mdkg.dev and docs.mdkg.dev source copy for the `0.4.0` public alpha,
87
160
  including config overlays, custom skill mirrors, `COLLABORATION.md`,
88
- MANIFEST/SPEC compatibility, and Plan -> Work -> Evidence launch messaging.
161
+ MANIFEST/SPEC compatibility, and Plan -> Work -> Evidence messaging.
89
162
  - Updated public docs and examples to use the current `mdkg pack --profile
90
163
  concise` syntax instead of stale `--pack-profile concise` examples.
91
164
  - Aligned source-visible package references, generated release-note data, and
92
- generated CLI docs with the `0.4.0` release target.
165
+ generated CLI docs with `0.4.0`.
93
166
 
94
167
  ### Fixed
95
168
 
@@ -1,7 +1,7 @@
1
1
  # CLI Command Matrix
2
2
 
3
- as_of: 2026-07-05
4
- package_version_in_source: 0.4.2
3
+ as_of: 2026-07-14
4
+ package_version_in_source: 0.5.1
5
5
  source: live help from `src/cli.ts`, runtime command handlers, and `dec-15`..`dec-18`
6
6
  status: canonical single-source command and flag reference for mdkg
7
7
 
@@ -46,6 +46,7 @@ Primary commands:
46
46
  - `subgraph`
47
47
  - `work`
48
48
  - `goal`
49
+ - `loop`
49
50
  - `task`
50
51
  - `next`
51
52
  - `validate`
@@ -77,7 +78,12 @@ Low-level Git remote lifecycle primitives are accessed through `mdkg git ...`.
77
78
  Read-only child graph orchestration is accessed through `mdkg subgraph ...`.
78
79
  Work contract/order/receipt semantic mirrors are accessed through `mdkg work ...`.
79
80
  Recursive long-running objective contracts are accessed through `mdkg goal ...`.
81
+ Reusable process-state loops are accessed through `mdkg loop ...`; mdkg stores loop graph state while runtimes execute agents and tools.
80
82
  Fresh init workspaces default to the SQLite access cache backend; existing migrated configs stay on JSON until opted in.
83
+ Graph discovery enforces configurable `index.limits` for file count, per-file
84
+ bytes, total bytes, and directory depth before reading Markdown. ZIP, pack, and
85
+ local MCP surfaces apply additional fixed protocol-safe ceilings and return
86
+ deterministic errors when a request or graph exceeds them.
81
87
  Project application database foundation commands are accessed through `mdkg db ...`; `mdkg index` remains the compatibility shortcut for graph index rebuilds.
82
88
  Operator health summaries are accessed through read-only `mdkg status ...`; deeper diagnostics remain under `mdkg doctor ...`.
83
89
  Repair planning is accessed through read-only `mdkg fix plan ...`; duplicate-ID graph repairs can be applied through `mdkg fix apply --family ids ...` or the convenience `mdkg fix ids --apply ...`. Index/cache and graph-reference findings remain plan/manual-review only.
@@ -162,6 +168,7 @@ Types:
162
168
  - `dec`
163
169
  - `prop`
164
170
  - `goal`
171
+ - `loop`
165
172
  - `epic`
166
173
  - `feat`
167
174
  - `task`
@@ -195,6 +202,13 @@ Agent workflow file type creation:
195
202
  Goal node creation:
196
203
  - `mdkg new goal "<title>" [options] [--json]`
197
204
 
205
+ Loop node creation:
206
+ - `mdkg new loop "<title>" [options] [--json]`
207
+ - loops are durable declarative graph process state, not runtime execution jobs
208
+ - a loop may be a reusable template, scoped fork, or run-bearing loop through metadata and links
209
+ - loop metadata records mode, scope, lineage, materialization, child refs, evidence/run refs, definition of done, and blocker-continuation policy
210
+ - default seeded loops are read-only or planning-oriented audit/recommendation templates
211
+
198
212
  Spike node creation:
199
213
  - `mdkg new spike "<research question>" [options] [--json]`
200
214
  - spikes are actionable research/planning work nodes under `.mdkg/work/`
@@ -244,6 +258,7 @@ JSON receipt:
244
258
  Notes:
245
259
  - `--id` lets agent workflow files use semantic portable ids such as `agent.image-worker`, `work.generate-image`, or `proposal.review-loop-1`.
246
260
  - `goal` nodes capture recursive objective state and required checks, but normal `mdkg next` does not select them.
261
+ - `loop` nodes capture reusable process state, fork lineage, child refs, run/evidence refs, blocker-continuation policy, and a high-bar definition of done; runtime execution remains outside mdkg.
247
262
  - `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.
248
263
 
249
264
  ### `mdkg show`
@@ -642,9 +657,9 @@ Usage:
642
657
  - `mdkg archive show <id-or-archive-uri> [--ws <alias>] [--json]`
643
658
  - `mdkg archive verify [id-or-archive-uri] [--json]`
644
659
  - `mdkg archive verify [id-or-archive-uri] [--ws <alias>] [--json]`
645
- - `mdkg archive compress <id-or-archive-uri|--all> [--json]`
646
- - `mdkg archive compress <id-or-archive-uri> [--ws <alias>] [--json]`
647
- - `mdkg archive compress --all [--json]`
660
+ - `mdkg archive compress <id-or-archive-uri-or-qid|--all> [--ws <local-alias>] [--json]`
661
+ - `mdkg archive compress <id-or-archive-uri-or-qid> [--ws <local-alias>] [--json]`
662
+ - `mdkg archive compress --all [--ws <local-alias>] [--json]`
648
663
 
649
664
  Fields:
650
665
  - archive sidecars use `type: archive`
@@ -658,6 +673,18 @@ Notes:
658
673
  - archive visibility defaults to `private`
659
674
  - `archive://<archive.id>` refs are validated against local archive sidecars
660
675
  - `archive verify` and `validate` both check the ZIP hash, ZIP readability, payload SHA-256, and payload byte size
676
+ - archive compression is owned exclusively by enabled local workspaces; imported
677
+ archive projections remain visible to list/show/search but are read-only
678
+ - `archive compress --all` selects every locally writable archive, while
679
+ `--all --ws <local-alias>` limits selection to one enabled local workspace
680
+ - direct workspace-qualified qids such as `root:archive.example` are supported;
681
+ imported qids and `--ws <imported-alias>` fail before filesystem path
682
+ construction with source-workspace and bundle-refresh guidance
683
+ - compression preflights ownership, identity, containment, symlinks, raw input,
684
+ and destinations for the complete selected set before the first write
685
+ - JSON keeps `action`, `count`, and `archives`, and adds
686
+ `selection: { requested_workspace, selected_workspaces,
687
+ excluded_read_only: [{ workspace, qid, reason }] }`
661
688
  - `archive verify` passes when the raw local source file is missing but the committed sidecar and ZIP cache are valid
662
689
  - generated raw source copies live under `.mdkg/archive/**/source/` and are ignored by default
663
690
  - `doctor` warns when archive ZIP caches exceed `archive.large_cache_warning_bytes` (default `26214400`; `0` disables)
@@ -967,6 +994,48 @@ JSON receipts:
967
994
  - `evaluate`: `{ action: "evaluated", goal, report_only, runs_scripts, checks, completion_evidence_present }`
968
995
  - `pause|resume|done|archive`: `{ action, goal }`
969
996
 
997
+ ### `mdkg loop`
998
+
999
+ When to use:
1000
+ - inspect reusable loop templates and scoped loop nodes
1001
+ - fork a reusable loop template for a concrete project scope
1002
+ - inspect loop planning state, child refs, run refs, and evidence refs without executing agents
1003
+
1004
+ Usage:
1005
+ - `mdkg loop list [--ws <alias>] [--json]`
1006
+ - `mdkg loop show <loop-or-template> [--meta] [--ws <alias>] [--json]`
1007
+ - `mdkg loop fork <template> --scope <scope> [--title <title>] [--materialization default_children|planning_only|manual] [--planning-only] [--no-children] [--dry-run] [--run-id <id>] [--ws <alias>] [--json]`
1008
+ - `mdkg loop plan <loop> [--ws <alias>] [--json]`
1009
+ - `mdkg loop next <loop> [--ws <alias>] [--json]`
1010
+ - `mdkg loop runs <loop> [--ws <alias>] [--json]`
1011
+ - `mdkg loop list [--ws <alias>] [--no-cache] [--no-reindex] [--json]`
1012
+ - `mdkg loop show <loop-or-template> [--meta] [--ws <alias>] [--no-cache] [--no-reindex] [--json]`
1013
+ - `mdkg loop fork <template> --scope <scope> [--title <title>] [--materialization <mode>] [--planning-only] [--no-children] [--dry-run] [--run-id <id>] [--ws <alias>] [--no-cache] [--no-reindex] [--json]`
1014
+ - `mdkg loop plan <loop> [--ws <alias>] [--no-cache] [--no-reindex] [--json]`
1015
+ - `mdkg loop next <loop> [--ws <alias>] [--no-cache] [--no-reindex] [--json]`
1016
+ - `mdkg loop runs <loop> [--ws <alias>] [--no-cache] [--no-reindex] [--json]`
1017
+
1018
+ Behavior:
1019
+ - `loop` is one first-class node type; template, scoped fork, and run-bearing behavior is represented through metadata and links, not separate node types.
1020
+ - seed templates resolve from `.mdkg/templates/loops/<name>.loop.md`.
1021
+ - `loop list` reports indexed loop nodes plus reusable seed templates.
1022
+ - `loop show` reports either an indexed loop node or a seed template body/frontmatter.
1023
+ - `loop fork` creates a scoped loop; default materialization creates linked spike/task/test child nodes, while `planning_only` or `--no-children` creates only the scoped loop shell.
1024
+ - `loop fork --dry-run` is observational: it writes no nodes, indexes, events, or SQLite reservations, and the next real fork reuses the previewed ids.
1025
+ - forked loops retain template identity and content hash; list/show/plan report current, stale, missing-template, or unknown provenance without rewriting forks.
1026
+ - `loop plan` reports readiness state, materialization state, child/run/output refs, evidence lanes, blockers, closeout readiness, and blocker-continuation guidance without executing agents.
1027
+ - `loop next` is read-only and routes to the next actionable child, readiness lane, or blocker recovery step without claiming work.
1028
+ - `loop runs` reports linked `run_refs` and graph `evidence_refs` without executing runtime jobs.
1029
+ - mdkg defines reusable process state and graph context; omni-room-runtime or other runtimes execute agents, tools, sandboxes, traces, and model routing.
1030
+
1031
+ JSON receipts:
1032
+ - `list`: `{ action: "listed", loops, templates, warnings }`
1033
+ - `show`: `{ action: "showed", loop, warnings }` or `{ action: "showed", template, warnings }`
1034
+ - `fork`: `{ action: "forked"|"planned", loop, template, materialization_mode, materialized_children, pending_materialization, blocker_continuation, warnings }`
1035
+ - `plan`: `{ action: "planned", loop, materialization_mode, child_refs, pending_materialization, readiness, blocker_continuation, warnings }`
1036
+ - `next`: `{ action: "selected", loop, selected, rationale, skipped, readiness, warnings }`
1037
+ - `runs`: `{ action: "listed", loop, run_refs, evidence_refs, warnings }`
1038
+
970
1039
  ### `mdkg task`
971
1040
 
972
1041
  When to use:
package/README.md CHANGED
@@ -14,7 +14,7 @@ mdkg stays deliberately boring:
14
14
  - first-class rebuildable SQLite cache through built-in `node:sqlite`
15
15
  - no daemon, hosted index, or vector DB
16
16
 
17
- Current package version in source: `0.4.2`
17
+ Current package version in source: `0.5.1`
18
18
 
19
19
  mdkg is still pre-v1 public alpha software. The public package is usable, but graph, cache, bundle, and DAL contracts may continue to change quickly while the project converges on a stable v1 surface.
20
20
 
@@ -494,10 +494,12 @@ Current source behavior:
494
494
  - `mdkg skill sync` refreshes the product-specific mirrors from canonical `.mdkg/skills/`
495
495
  - mirrored skill folders are append-focused outputs; preserve unrelated existing folders and fail on same-slug collisions unless explicitly forced
496
496
 
497
- This repo now dogfoods three internal skills:
497
+ This repo now dogfoods mdkg-authored internal skills:
498
498
  - `author-mdkg-skill`
499
499
  - `select-work-and-ground-context`
500
500
  - `build-pack-and-execute-task`
501
+ - `pursue-mdkg-goal`
502
+ - `pursue-mdkg-loop`
501
503
  - `verify-close-and-checkpoint`
502
504
 
503
505
  Optional skill metadata with prefixes such as `ochatr_*` is treated as vendor extension data. Structured skill output exposes it under `extensions.ochatr` while keeping the top-level `ochatr` field as a compatibility alias introduced in 0.0.9. ochatr.ai is a pioneering adopter of this extension pattern, not the name of the base mdkg standard.
@@ -521,6 +523,13 @@ Fresh `mdkg init` workspaces default to `index.backend: sqlite`, which writes `.
521
523
 
522
524
  `mdkg index` still writes JSON compatibility caches (`global.json`, `skills.json`, `capabilities.json`, and subgraph projections when configured). In SQLite mode it also rebuilds the SQLite cache with nodes, edges, skills, capabilities, archive metadata, subgraphs, source hashes, and schema metadata. Deleting the SQLite file is recoverable with `mdkg index`.
523
525
 
526
+ Graph ingestion is bounded before Markdown bodies are read. New workspaces expose
527
+ `index.limits.max_files`, `max_file_bytes`, `max_total_bytes`, and `max_depth` in
528
+ `.mdkg/config.json`; older configs receive the same conservative defaults in
529
+ memory. Pack traversal and body reads are bounded before construction, ZIP input
530
+ is bounded before allocation and inflation, and the local read-only MCP server
531
+ rejects oversized lines, batches, nesting, bodies, tool payloads, and responses.
532
+
524
533
  Mutating commands use a workspace mutation lock plus atomic writes. SQLite mode additionally reserves numeric ids in a SQLite transaction before writing Markdown so parallel `mdkg new` and checkpoint calls avoid naming conflicts. Skipped ids after failed writes are acceptable because Markdown remains canonical.
525
534
 
526
535
  ## Project DB Layout
@@ -584,6 +593,14 @@ Use `mdkg goal claim [goal-id] <work-id>` to durably set `active_node` after cho
584
593
 
585
594
  Required checks are stored as report-only guidance. Agents should run the checks themselves, record evidence in the goal or active work item, then use `mdkg goal evaluate` to summarize the current evidence state. During normal goal execution, skill improvements should be recorded as improvement candidates or proposal nodes; edit `SKILL.md` files only when the active node is explicit skill-maintenance work.
586
595
 
596
+ ## Loop nodes
597
+
598
+ Loop nodes are durable declarative process state for reusable agentic workflows. Use `mdkg new loop "<process>"` for a loop record, or `mdkg loop fork <template> --scope <scope>` to instantiate a seeded template for a concrete repo, folder, or goal.
599
+
600
+ `loop` is one first-class node type. A loop can act as a reusable template, scoped fork, or run-bearing loop through metadata and links; mdkg does not create separate `loop_template` or `loop_run` node types in this release. Loop metadata records mode, scope, lineage, materialization mode, child refs, run/evidence refs, definition of done, and blocker-continuation policy.
601
+
602
+ `mdkg loop list|show|plan|runs` inspect loop state without executing agents. `mdkg loop fork` creates graph state; by default it materializes linked spike/task/test child nodes, while `--planning-only` or `--no-children` creates only the scoped loop shell. mdkg defines reusable process state and graph context; omni-room-runtime or another runtime owns agent/tool execution, sandboxes, traces, and model routing.
603
+
587
604
  ## Research spikes
588
605
 
589
606
  Spikes are first-class actionable work nodes for research and planning. Use
@@ -636,6 +653,16 @@ When the source passed to `mdkg archive add` is inside the repo, `source_path` i
636
653
 
637
654
  Archive sidecar visibility defaults to `private`. Use `mdkg archive add --visibility public` only when the sidecar metadata and ZIP cache are safe for public packs or public bundles.
638
655
 
656
+ Archive compression follows workspace ownership. `mdkg archive compress --all`
657
+ compresses archives from enabled local workspaces and reports read-only imported
658
+ archive projections as exclusions; it never treats bundle ZIP fragments as
659
+ filesystem paths. Use `--all --ws <local-alias>` to limit bulk compression or a
660
+ workspace-qualified qid such as `root:archive.example` for an exact local
661
+ target. Direct imported qids and imported `--ws` aliases fail before writes with
662
+ guidance to compress in the source workspace and refresh its subgraph bundle.
663
+ The JSON receipt preserves `action`, `count`, and `archives` and adds the
664
+ requested workspace, selected local workspaces, and excluded read-only qids.
665
+
639
666
  By default, init/upgrade ignore generated raw archive source copies with `.mdkg/archive/**/source/`; sidecar `.md` files and compressed `.zip` caches remain commit-eligible. `mdkg doctor` warns when a committed archive ZIP cache exceeds `archive.large_cache_warning_bytes` in `.mdkg/config.json` (default `26214400`; set `0` to disable). Large-cache warnings do not block archive add or validation.
640
667
 
641
668
  ## Current direction
@@ -650,6 +677,7 @@ This release includes:
650
677
  - SQLite index backend for fresh workspaces using built-in `node:sqlite`
651
678
  - mutation locking and atomic writes for parallel mdkg calls
652
679
  - first-class `goal` nodes and `mdkg goal show/next/evaluate/pause/resume/done`
680
+ - first-class `loop` nodes and `mdkg loop list/show/fork/plan/runs`
653
681
  - optional `skills: [...]` on work items
654
682
  - pack-time skill inclusion
655
683
  - latest-checkpoint resolver + index hint
package/dist/cli.js CHANGED
@@ -36,6 +36,8 @@ const init_1 = require("./commands/init");
36
36
  const new_1 = require("./commands/new");
37
37
  const guide_1 = require("./commands/guide");
38
38
  const upgrade_1 = require("./commands/upgrade");
39
+ const loop_1 = require("./commands/loop");
40
+ const loop_descriptors_1 = require("./commands/loop_descriptors");
39
41
  const goal_1 = require("./commands/goal");
40
42
  const event_1 = require("./commands/event");
41
43
  const skill_1 = require("./commands/skill");
@@ -80,6 +82,7 @@ function printUsage(log) {
80
82
  log(" git Clone, fetch, inspect, close out, and push Git-backed mdkg projects");
81
83
  log(" subgraph Register, audit, plan, sync, materialize, and verify read-only child graph snapshots");
82
84
  log(" work Create and update work contracts, orders, receipts, and artifacts");
85
+ log(" loop List, show, fork, plan, and inspect first-class loop nodes");
83
86
  log(" goal Inspect and advance recursive goal nodes");
84
87
  log(" task Start, update, and complete task-like nodes");
85
88
  log(" next Suggest the next work item");
@@ -146,7 +149,7 @@ function printNewHelp(log) {
146
149
  log("Usage:");
147
150
  log(' mdkg new <type> "<title>" [options] [--json]');
148
151
  log("\nTypes:");
149
- log(" rule prd edd dec prop goal epic feat task bug spike checkpoint test");
152
+ log(" rule prd edd dec prop loop goal epic feat task bug spike checkpoint test");
150
153
  log("\nAgent workflow file types:");
151
154
  log(" manifest work work_order receipt feedback dispute proposal");
152
155
  log(" spec is a legacy alias for manifest and emits MANIFEST.md during the compatibility bridge.");
@@ -179,6 +182,34 @@ function printNewHelp(log) {
179
182
  log(" spikes do not run web search, create follow-up nodes, generate SKILL.md, or expose `mdkg spike ...`.");
180
183
  printGlobalOptions(log);
181
184
  }
185
+ function printLoopHelp(log, subcommand) {
186
+ printLoopDescriptorHelp(log, (0, loop_descriptors_1.loopDescriptorForSubcommand)(subcommand));
187
+ }
188
+ function printLoopDescriptorHelp(log, descriptor) {
189
+ log("Usage:");
190
+ for (const usage of descriptor.usage) {
191
+ log(` ${usage}`);
192
+ }
193
+ if (descriptor.key === "loop fork") {
194
+ log("\nMaterialization modes:");
195
+ log(" default_children planning_only manual");
196
+ }
197
+ const commandFlags = descriptor.flags.filter((flag) => flag.name !== "--root");
198
+ if (commandFlags.length > 0) {
199
+ log("\nOptions:");
200
+ for (const flag of commandFlags) {
201
+ const syntax = flag.value ? `${flag.name} ${flag.value}` : flag.name;
202
+ log(` ${syntax.padEnd(28)} ${flag.description}`);
203
+ }
204
+ }
205
+ if (descriptor.notes.length > 0) {
206
+ log("\nNotes:");
207
+ for (const note of descriptor.notes) {
208
+ log(` ${note}`);
209
+ }
210
+ }
211
+ printGlobalOptions(log);
212
+ }
182
213
  function printGuideHelp(log) {
183
214
  log("Usage:");
184
215
  log(" mdkg guide");
@@ -318,9 +349,10 @@ function printListHelp(log) {
318
349
  function printSearchHelp(log) {
319
350
  log("Usage:");
320
351
  log(' mdkg search "<query>" [--type <type>] [--status <status>] [--ws <alias>]');
321
- log(" [--tags <tag,tag,...>] [--tags-mode any|all] [--json|--xml|--toon|--md]");
352
+ log(" [--tags <tag,tag,...>] [--tags-mode any|all] [--limit <n>] [--json|--xml|--toon|--md]");
322
353
  log("\nWhen to use:");
323
354
  log(" Search mdkg nodes by metadata. Use `mdkg skill search` for skills.");
355
+ log(" Structured output defaults to a bounded page and reports count, returned_count, limit, and truncated.");
324
356
  printGlobalOptions(log);
325
357
  }
326
358
  function printPackHelp(log) {
@@ -551,8 +583,13 @@ function printArchiveHelp(log, subcommand) {
551
583
  break;
552
584
  case "compress":
553
585
  log("Usage:");
554
- log(" mdkg archive compress <id-or-archive-uri> [--ws <alias>] [--json]");
555
- log(" mdkg archive compress --all [--json]");
586
+ log(" mdkg archive compress <id-or-archive-uri-or-qid> [--ws <local-alias>] [--json]");
587
+ log(" mdkg archive compress --all [--ws <local-alias>] [--json]");
588
+ log("\nNotes:");
589
+ log(" - compression mutates archives owned by enabled local workspaces only");
590
+ log(" - --all excludes read-only imported archive projections and reports them in the receipt");
591
+ log(" - direct imported qids and --ws <imported-alias> fail with source-workspace guidance");
592
+ log(" - all selected archives pass ownership and path preflight before the first write");
556
593
  break;
557
594
  default:
558
595
  log("Usage:");
@@ -560,7 +597,7 @@ function printArchiveHelp(log, subcommand) {
560
597
  log(" mdkg archive list [--kind source|artifact] [--visibility private|internal|public] [--json]");
561
598
  log(" mdkg archive show <id-or-archive-uri> [--json]");
562
599
  log(" mdkg archive verify [id-or-archive-uri] [--json]");
563
- log(" mdkg archive compress <id-or-archive-uri|--all> [--json]");
600
+ log(" mdkg archive compress <id-or-archive-uri-or-qid|--all> [--ws <local-alias>] [--json]");
564
601
  log("\nNotes:");
565
602
  log(" - archive add copies the source, writes a sidecar, and writes a deterministic zip cache");
566
603
  log(" - archive visibility defaults to private");
@@ -1254,6 +1291,9 @@ function printCommandHelp(log, command, subcommand) {
1254
1291
  case "work":
1255
1292
  printWorkHelp(log, subcommand);
1256
1293
  return;
1294
+ case "loop":
1295
+ printLoopHelp(log, subcommand);
1296
+ return;
1257
1297
  case "task":
1258
1298
  printTaskHelp(log, subcommand);
1259
1299
  return;
@@ -2508,6 +2548,89 @@ function runSkillSubcommand(parsed, root) {
2508
2548
  throw new errors_1.UsageError("skill requires new/list/show/search/validate/sync");
2509
2549
  }
2510
2550
  }
2551
+ function runLoopSubcommand(parsed, root) {
2552
+ const subcommand = (parsed.positionals[1] ?? "").toLowerCase();
2553
+ const ws = requireFlagValue("--ws", parsed.flags["--ws"]);
2554
+ const json = parseBooleanFlag("--json", parsed.flags["--json"]);
2555
+ const noCache = parseBooleanFlag("--no-cache", parsed.flags["--no-cache"]);
2556
+ const noReindex = parseBooleanFlag("--no-reindex", parsed.flags["--no-reindex"]);
2557
+ switch (subcommand) {
2558
+ case "list": {
2559
+ if (parsed.positionals.length > 2) {
2560
+ throw new errors_1.UsageError("loop list does not accept positional arguments");
2561
+ }
2562
+ (0, loop_1.runLoopListCommand)({ root, ws, json, noCache, noReindex });
2563
+ return 0;
2564
+ }
2565
+ case "show": {
2566
+ const id = parsed.positionals[2];
2567
+ if (!id || parsed.positionals.length > 3) {
2568
+ throw new errors_1.UsageError("loop show requires <loop-or-template>");
2569
+ }
2570
+ const metaOnly = parseBooleanFlag("--meta", parsed.flags["--meta"]);
2571
+ (0, loop_1.runLoopShowCommand)({ root, id, ws, metaOnly, json, noCache, noReindex });
2572
+ return 0;
2573
+ }
2574
+ case "fork": {
2575
+ const template = parsed.positionals[2];
2576
+ if (!template || parsed.positionals.length > 3) {
2577
+ throw new errors_1.UsageError("loop fork requires <template>");
2578
+ }
2579
+ const scope = requireFlagValue("--scope", parsed.flags["--scope"]);
2580
+ if (!scope) {
2581
+ throw new errors_1.UsageError("loop fork requires --scope");
2582
+ }
2583
+ const title = requireFlagValue("--title", parsed.flags["--title"]);
2584
+ const materializationMode = requireFlagValue("--materialization", parsed.flags["--materialization"]);
2585
+ const planningOnly = parseBooleanFlag("--planning-only", parsed.flags["--planning-only"]);
2586
+ const noChildren = parseBooleanFlag("--no-children", parsed.flags["--no-children"]);
2587
+ const dryRun = parseBooleanFlag("--dry-run", parsed.flags["--dry-run"]);
2588
+ const runId = requireFlagValue("--run-id", parsed.flags["--run-id"]);
2589
+ (0, loop_1.runLoopForkCommand)({
2590
+ root,
2591
+ template,
2592
+ scope,
2593
+ title,
2594
+ ws,
2595
+ materializationMode: materializationMode,
2596
+ planningOnly,
2597
+ noChildren,
2598
+ dryRun,
2599
+ runId,
2600
+ json,
2601
+ noCache,
2602
+ noReindex,
2603
+ });
2604
+ return 0;
2605
+ }
2606
+ case "plan": {
2607
+ const id = parsed.positionals[2];
2608
+ if (!id || parsed.positionals.length > 3) {
2609
+ throw new errors_1.UsageError("loop plan requires <loop>");
2610
+ }
2611
+ (0, loop_1.runLoopPlanCommand)({ root, id, ws, json, noCache, noReindex });
2612
+ return 0;
2613
+ }
2614
+ case "next": {
2615
+ const id = parsed.positionals[2];
2616
+ if (!id || parsed.positionals.length > 3) {
2617
+ throw new errors_1.UsageError("loop next requires <loop>");
2618
+ }
2619
+ (0, loop_1.runLoopNextCommand)({ root, id, ws, json, noCache, noReindex });
2620
+ return 0;
2621
+ }
2622
+ case "runs": {
2623
+ const id = parsed.positionals[2];
2624
+ if (!id || parsed.positionals.length > 3) {
2625
+ throw new errors_1.UsageError("loop runs requires <loop>");
2626
+ }
2627
+ (0, loop_1.runLoopRunsCommand)({ root, id, ws, json, noCache, noReindex });
2628
+ return 0;
2629
+ }
2630
+ default:
2631
+ throw new errors_1.UsageError("loop requires list/show/fork/plan/next/runs");
2632
+ }
2633
+ }
2511
2634
  function runGoalSubcommand(parsed, root) {
2512
2635
  const subcommand = (parsed.positionals[1] ?? "").toLowerCase();
2513
2636
  const ws = requireFlagValue("--ws", parsed.flags["--ws"]);
@@ -2889,6 +3012,8 @@ function runCommand(parsed, root, runtime) {
2889
3012
  return runSubgraphSubcommand(parsed, root);
2890
3013
  case "work":
2891
3014
  return runWorkSubcommand(parsed, root);
3015
+ case "loop":
3016
+ return runLoopSubcommand(parsed, root);
2892
3017
  case "goal":
2893
3018
  return runGoalSubcommand(parsed, root);
2894
3019
  case "task":
@@ -2957,6 +3082,7 @@ function runCommand(parsed, root, runtime) {
2957
3082
  const status = requireFlagValue("--status", parsed.flags["--status"]);
2958
3083
  const tags = parseCsvFlag("--tags", parsed.flags["--tags"]);
2959
3084
  const tagsMode = parseTagsModeFlag(parsed.flags["--tags-mode"]);
3085
+ const limit = parseNumberFlag("--limit", parsed.flags["--limit"]);
2960
3086
  const format = parseQueryOutputFormat(parsed);
2961
3087
  const noCache = parseBooleanFlag("--no-cache", parsed.flags["--no-cache"]);
2962
3088
  const noReindex = parseBooleanFlag("--no-reindex", parsed.flags["--no-reindex"]);
@@ -2968,6 +3094,7 @@ function runCommand(parsed, root, runtime) {
2968
3094
  status,
2969
3095
  tags,
2970
3096
  tagsMode,
3097
+ limit,
2971
3098
  format,
2972
3099
  noCache,
2973
3100
  noReindex,