mdkg 0.4.2 → 0.5.0

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 +71 -15
  2. package/CLI_COMMAND_MATRIX.md +59 -2
  3. package/README.md +20 -2
  4. package/dist/cli.js +124 -2
  5. package/dist/command-contract.json +756 -2
  6. package/dist/commands/archive.js +31 -14
  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,66 @@ mdkg is pre-v1 public alpha software. Command, graph, cache, bundle, and DAL con
8
8
 
9
9
  ## Unreleased
10
10
 
11
+ ## 0.5.0 - 2026-07-11
12
+
13
+ ### Added
14
+
15
+ - Added `loop` as a first-class mdkg work node for reusable, durable agentic
16
+ processes that can coordinate goals, tasks, tests, spikes, proposals,
17
+ decisions, checkpoints, receipts, evidence, and repeated attempts.
18
+ - Added the semantic `mdkg loop list`, `show`, `fork`, `plan`, `next`, and
19
+ `runs` command family, plus deterministic `mdkg new loop` guidance for raw
20
+ loops versus bundled templates.
21
+ - Added identity-bound loop readiness metadata for pre-run questions, action
22
+ approvals, evidence lanes, and paired decision/approval waivers.
23
+ - Added immutable template provenance, content hashes, stale-fork warnings,
24
+ default child materialization, and an explicit planning-only fork mode.
25
+ - Added seven bundled read-only or planning loop templates for security,
26
+ frontend design, backend/API/CLI design, tech-stack practices, duplication
27
+ and linting, test/CI/skill infrastructure, and user-story audits.
28
+ - Added the reusable `pursue-mdkg-loop` agent skill to keep authorized child
29
+ lanes moving, recover blockers through grounded spikes and proposals, and
30
+ close only against the loop definition of done.
31
+ - Added a gated mdkg.dev announcement and top-level Loops documentation with a
32
+ purpose-built read-only security audit walkthrough. Public promotion remains
33
+ controlled by the shared source release manifest.
34
+
35
+ ### Changed
36
+
37
+ - Integrated loops into parser/template validation, generic discovery,
38
+ SQLite/JSON indexes, search/show/list output, deterministic pack traversal,
39
+ generated help, command contracts, init assets, and upgrade fallback paths.
40
+ - Made loop fork dry-runs observational across JSON and SQLite backends: no ID
41
+ reservation, event write, index persistence, or graph/filesystem mutation.
42
+ - Made read-only loop commands use non-persisting index projections and made
43
+ `loop next` exhaust authorized nested work and blocker-recovery lanes before
44
+ reporting the whole loop blocked.
45
+ - Kept loop templates, scoped forks, and run-bearing state under one `loop`
46
+ node type; mdkg preserves orchestration state while the coding-agent harness
47
+ remains responsible for executing agents and tools.
48
+ - Added installed-package smoke coverage for every bundled loop template and a
49
+ public-repository release-readiness workflow across the minimum supported
50
+ Node version and current Node line.
51
+ - Cleaned mdkg.dev/docs public copy and demo proof surfaces while preserving
52
+ the existing quickstart-first product journey and Pre-v1 public-alpha scope.
53
+
54
+ ### Fixed
55
+
56
+ - Fixed readiness projection so unrelated decisions, approvals, evidence, and
57
+ waivers cannot satisfy a different question, action, or evidence lane.
58
+ - Fixed loop routing so one blocked child does not halt other authorized work,
59
+ and whole-loop blocking occurs only after useful work and recovery paths are
60
+ exhausted.
61
+ - Fixed stale-template handling to warn from recorded template identity and
62
+ content hash without silently rewriting scoped forks.
63
+
64
+ ### Security
65
+
66
+ - Hardened graph target writes against symlink containment escapes before any
67
+ destination mutation.
68
+ - Bounded ZIP entry count, compressed size, declared output, total output, and
69
+ expansion ratio before bundle or subgraph inflation.
70
+
11
71
  ## 0.4.2 - 2026-07-05
12
72
 
13
73
  ### Added
@@ -63,33 +123,29 @@ mdkg is pre-v1 public alpha software. Command, graph, cache, bundle, and DAL con
63
123
  `resource_profile`, WORK `kind`, WORK_ORDER `artifact_policy`, RECEIPT
64
124
  `redaction_policy`, `receipt_kind`, `redaction_class`, and pack/bundle
65
125
  `--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.
126
+ - Expanded documentation and validation checks for `0.4.1` so package readiness
127
+ can be verified before publication.
68
128
 
69
129
  ## 0.4.0 - 2026-06-27
70
130
 
71
131
  ### Added
72
132
 
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.
133
+ - Added public release cards and changelog detail pages for recent public-alpha
134
+ versions.
135
+ - Added docs coverage for config overlays, custom skill mirrors,
136
+ `COLLABORATION.md`, MANIFEST naming, and public-alpha customization guidance.
137
+ - Added mdkg.dev and docs.mdkg.dev copy updates that keep public claims bounded
138
+ to documented capabilities.
83
139
 
84
140
  ### Changed
85
141
 
86
- - Updated mdkg.dev and docs.mdkg.dev source copy for the `0.4.0` release target,
142
+ - Updated mdkg.dev and docs.mdkg.dev source copy for the `0.4.0` public alpha,
87
143
  including config overlays, custom skill mirrors, `COLLABORATION.md`,
88
- MANIFEST/SPEC compatibility, and Plan -> Work -> Evidence launch messaging.
144
+ MANIFEST/SPEC compatibility, and Plan -> Work -> Evidence messaging.
89
145
  - Updated public docs and examples to use the current `mdkg pack --profile
90
146
  concise` syntax instead of stale `--pack-profile concise` examples.
91
147
  - Aligned source-visible package references, generated release-note data, and
92
- generated CLI docs with the `0.4.0` release target.
148
+ generated CLI docs with `0.4.0`.
93
149
 
94
150
  ### Fixed
95
151
 
@@ -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-11
4
+ package_version_in_source: 0.5.0
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`
@@ -967,6 +982,48 @@ JSON receipts:
967
982
  - `evaluate`: `{ action: "evaluated", goal, report_only, runs_scripts, checks, completion_evidence_present }`
968
983
  - `pause|resume|done|archive`: `{ action, goal }`
969
984
 
985
+ ### `mdkg loop`
986
+
987
+ When to use:
988
+ - inspect reusable loop templates and scoped loop nodes
989
+ - fork a reusable loop template for a concrete project scope
990
+ - inspect loop planning state, child refs, run refs, and evidence refs without executing agents
991
+
992
+ Usage:
993
+ - `mdkg loop list [--ws <alias>] [--json]`
994
+ - `mdkg loop show <loop-or-template> [--meta] [--ws <alias>] [--json]`
995
+ - `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]`
996
+ - `mdkg loop plan <loop> [--ws <alias>] [--json]`
997
+ - `mdkg loop next <loop> [--ws <alias>] [--json]`
998
+ - `mdkg loop runs <loop> [--ws <alias>] [--json]`
999
+ - `mdkg loop list [--ws <alias>] [--no-cache] [--no-reindex] [--json]`
1000
+ - `mdkg loop show <loop-or-template> [--meta] [--ws <alias>] [--no-cache] [--no-reindex] [--json]`
1001
+ - `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]`
1002
+ - `mdkg loop plan <loop> [--ws <alias>] [--no-cache] [--no-reindex] [--json]`
1003
+ - `mdkg loop next <loop> [--ws <alias>] [--no-cache] [--no-reindex] [--json]`
1004
+ - `mdkg loop runs <loop> [--ws <alias>] [--no-cache] [--no-reindex] [--json]`
1005
+
1006
+ Behavior:
1007
+ - `loop` is one first-class node type; template, scoped fork, and run-bearing behavior is represented through metadata and links, not separate node types.
1008
+ - seed templates resolve from `.mdkg/templates/loops/<name>.loop.md`.
1009
+ - `loop list` reports indexed loop nodes plus reusable seed templates.
1010
+ - `loop show` reports either an indexed loop node or a seed template body/frontmatter.
1011
+ - `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.
1012
+ - `loop fork --dry-run` is observational: it writes no nodes, indexes, events, or SQLite reservations, and the next real fork reuses the previewed ids.
1013
+ - forked loops retain template identity and content hash; list/show/plan report current, stale, missing-template, or unknown provenance without rewriting forks.
1014
+ - `loop plan` reports readiness state, materialization state, child/run/output refs, evidence lanes, blockers, closeout readiness, and blocker-continuation guidance without executing agents.
1015
+ - `loop next` is read-only and routes to the next actionable child, readiness lane, or blocker recovery step without claiming work.
1016
+ - `loop runs` reports linked `run_refs` and graph `evidence_refs` without executing runtime jobs.
1017
+ - mdkg defines reusable process state and graph context; omni-room-runtime or other runtimes execute agents, tools, sandboxes, traces, and model routing.
1018
+
1019
+ JSON receipts:
1020
+ - `list`: `{ action: "listed", loops, templates, warnings }`
1021
+ - `show`: `{ action: "showed", loop, warnings }` or `{ action: "showed", template, warnings }`
1022
+ - `fork`: `{ action: "forked"|"planned", loop, template, materialization_mode, materialized_children, pending_materialization, blocker_continuation, warnings }`
1023
+ - `plan`: `{ action: "planned", loop, materialization_mode, child_refs, pending_materialization, readiness, blocker_continuation, warnings }`
1024
+ - `next`: `{ action: "selected", loop, selected, rationale, skipped, readiness, warnings }`
1025
+ - `runs`: `{ action: "listed", loop, run_refs, evidence_refs, warnings }`
1026
+
970
1027
  ### `mdkg task`
971
1028
 
972
1029
  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.0`
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
@@ -650,6 +667,7 @@ This release includes:
650
667
  - SQLite index backend for fresh workspaces using built-in `node:sqlite`
651
668
  - mutation locking and atomic writes for parallel mdkg calls
652
669
  - first-class `goal` nodes and `mdkg goal show/next/evaluate/pause/resume/done`
670
+ - first-class `loop` nodes and `mdkg loop list/show/fork/plan/runs`
653
671
  - optional `skills: [...]` on work items
654
672
  - pack-time skill inclusion
655
673
  - 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) {
@@ -1254,6 +1286,9 @@ function printCommandHelp(log, command, subcommand) {
1254
1286
  case "work":
1255
1287
  printWorkHelp(log, subcommand);
1256
1288
  return;
1289
+ case "loop":
1290
+ printLoopHelp(log, subcommand);
1291
+ return;
1257
1292
  case "task":
1258
1293
  printTaskHelp(log, subcommand);
1259
1294
  return;
@@ -2508,6 +2543,89 @@ function runSkillSubcommand(parsed, root) {
2508
2543
  throw new errors_1.UsageError("skill requires new/list/show/search/validate/sync");
2509
2544
  }
2510
2545
  }
2546
+ function runLoopSubcommand(parsed, root) {
2547
+ const subcommand = (parsed.positionals[1] ?? "").toLowerCase();
2548
+ const ws = requireFlagValue("--ws", parsed.flags["--ws"]);
2549
+ const json = parseBooleanFlag("--json", parsed.flags["--json"]);
2550
+ const noCache = parseBooleanFlag("--no-cache", parsed.flags["--no-cache"]);
2551
+ const noReindex = parseBooleanFlag("--no-reindex", parsed.flags["--no-reindex"]);
2552
+ switch (subcommand) {
2553
+ case "list": {
2554
+ if (parsed.positionals.length > 2) {
2555
+ throw new errors_1.UsageError("loop list does not accept positional arguments");
2556
+ }
2557
+ (0, loop_1.runLoopListCommand)({ root, ws, json, noCache, noReindex });
2558
+ return 0;
2559
+ }
2560
+ case "show": {
2561
+ const id = parsed.positionals[2];
2562
+ if (!id || parsed.positionals.length > 3) {
2563
+ throw new errors_1.UsageError("loop show requires <loop-or-template>");
2564
+ }
2565
+ const metaOnly = parseBooleanFlag("--meta", parsed.flags["--meta"]);
2566
+ (0, loop_1.runLoopShowCommand)({ root, id, ws, metaOnly, json, noCache, noReindex });
2567
+ return 0;
2568
+ }
2569
+ case "fork": {
2570
+ const template = parsed.positionals[2];
2571
+ if (!template || parsed.positionals.length > 3) {
2572
+ throw new errors_1.UsageError("loop fork requires <template>");
2573
+ }
2574
+ const scope = requireFlagValue("--scope", parsed.flags["--scope"]);
2575
+ if (!scope) {
2576
+ throw new errors_1.UsageError("loop fork requires --scope");
2577
+ }
2578
+ const title = requireFlagValue("--title", parsed.flags["--title"]);
2579
+ const materializationMode = requireFlagValue("--materialization", parsed.flags["--materialization"]);
2580
+ const planningOnly = parseBooleanFlag("--planning-only", parsed.flags["--planning-only"]);
2581
+ const noChildren = parseBooleanFlag("--no-children", parsed.flags["--no-children"]);
2582
+ const dryRun = parseBooleanFlag("--dry-run", parsed.flags["--dry-run"]);
2583
+ const runId = requireFlagValue("--run-id", parsed.flags["--run-id"]);
2584
+ (0, loop_1.runLoopForkCommand)({
2585
+ root,
2586
+ template,
2587
+ scope,
2588
+ title,
2589
+ ws,
2590
+ materializationMode: materializationMode,
2591
+ planningOnly,
2592
+ noChildren,
2593
+ dryRun,
2594
+ runId,
2595
+ json,
2596
+ noCache,
2597
+ noReindex,
2598
+ });
2599
+ return 0;
2600
+ }
2601
+ case "plan": {
2602
+ const id = parsed.positionals[2];
2603
+ if (!id || parsed.positionals.length > 3) {
2604
+ throw new errors_1.UsageError("loop plan requires <loop>");
2605
+ }
2606
+ (0, loop_1.runLoopPlanCommand)({ root, id, ws, json, noCache, noReindex });
2607
+ return 0;
2608
+ }
2609
+ case "next": {
2610
+ const id = parsed.positionals[2];
2611
+ if (!id || parsed.positionals.length > 3) {
2612
+ throw new errors_1.UsageError("loop next requires <loop>");
2613
+ }
2614
+ (0, loop_1.runLoopNextCommand)({ root, id, ws, json, noCache, noReindex });
2615
+ return 0;
2616
+ }
2617
+ case "runs": {
2618
+ const id = parsed.positionals[2];
2619
+ if (!id || parsed.positionals.length > 3) {
2620
+ throw new errors_1.UsageError("loop runs requires <loop>");
2621
+ }
2622
+ (0, loop_1.runLoopRunsCommand)({ root, id, ws, json, noCache, noReindex });
2623
+ return 0;
2624
+ }
2625
+ default:
2626
+ throw new errors_1.UsageError("loop requires list/show/fork/plan/next/runs");
2627
+ }
2628
+ }
2511
2629
  function runGoalSubcommand(parsed, root) {
2512
2630
  const subcommand = (parsed.positionals[1] ?? "").toLowerCase();
2513
2631
  const ws = requireFlagValue("--ws", parsed.flags["--ws"]);
@@ -2889,6 +3007,8 @@ function runCommand(parsed, root, runtime) {
2889
3007
  return runSubgraphSubcommand(parsed, root);
2890
3008
  case "work":
2891
3009
  return runWorkSubcommand(parsed, root);
3010
+ case "loop":
3011
+ return runLoopSubcommand(parsed, root);
2892
3012
  case "goal":
2893
3013
  return runGoalSubcommand(parsed, root);
2894
3014
  case "task":
@@ -2957,6 +3077,7 @@ function runCommand(parsed, root, runtime) {
2957
3077
  const status = requireFlagValue("--status", parsed.flags["--status"]);
2958
3078
  const tags = parseCsvFlag("--tags", parsed.flags["--tags"]);
2959
3079
  const tagsMode = parseTagsModeFlag(parsed.flags["--tags-mode"]);
3080
+ const limit = parseNumberFlag("--limit", parsed.flags["--limit"]);
2960
3081
  const format = parseQueryOutputFormat(parsed);
2961
3082
  const noCache = parseBooleanFlag("--no-cache", parsed.flags["--no-cache"]);
2962
3083
  const noReindex = parseBooleanFlag("--no-reindex", parsed.flags["--no-reindex"]);
@@ -2968,6 +3089,7 @@ function runCommand(parsed, root, runtime) {
2968
3089
  status,
2969
3090
  tags,
2970
3091
  tagsMode,
3092
+ limit,
2971
3093
  format,
2972
3094
  noCache,
2973
3095
  noReindex,