mdkg 0.0.2 → 0.0.4

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 (50) hide show
  1. package/README.md +171 -151
  2. package/dist/cli.js +920 -422
  3. package/dist/commands/checkpoint.js +17 -6
  4. package/dist/commands/doctor.js +156 -0
  5. package/dist/commands/event.js +46 -0
  6. package/dist/commands/event_support.js +146 -0
  7. package/dist/commands/format.js +6 -7
  8. package/dist/commands/index.js +10 -4
  9. package/dist/commands/init.js +202 -11
  10. package/dist/commands/list.js +18 -1
  11. package/dist/commands/new.js +30 -5
  12. package/dist/commands/pack.js +332 -10
  13. package/dist/commands/query_output.js +84 -0
  14. package/dist/commands/search.js +22 -5
  15. package/dist/commands/show.js +26 -11
  16. package/dist/commands/skill.js +359 -0
  17. package/dist/commands/skill_support.js +121 -0
  18. package/dist/commands/task.js +270 -0
  19. package/dist/commands/validate.js +104 -7
  20. package/dist/graph/edges.js +2 -2
  21. package/dist/graph/frontmatter.js +1 -0
  22. package/dist/graph/indexer.js +21 -0
  23. package/dist/graph/node.js +20 -4
  24. package/dist/graph/skills_index_cache.js +94 -0
  25. package/dist/graph/skills_indexer.js +160 -0
  26. package/dist/init/README.md +43 -0
  27. package/dist/init/core/rule-1-mdkg-conventions.md +9 -2
  28. package/dist/init/core/rule-3-cli-contract.md +73 -14
  29. package/dist/init/core/rule-4-repo-safety-and-ignores.md +9 -3
  30. package/dist/init/core/rule-6-templates-and-schemas.md +6 -2
  31. package/dist/init/skills/SKILL.md.example +41 -0
  32. package/dist/init/templates/default/bug.md +1 -0
  33. package/dist/init/templates/default/chk.md +1 -0
  34. package/dist/init/templates/default/epic.md +1 -0
  35. package/dist/init/templates/default/feat.md +1 -0
  36. package/dist/init/templates/default/task.md +1 -0
  37. package/dist/init/templates/default/test.md +1 -0
  38. package/dist/pack/budget.js +186 -0
  39. package/dist/pack/export_md.js +17 -1
  40. package/dist/pack/export_xml.js +15 -0
  41. package/dist/pack/metrics.js +66 -0
  42. package/dist/pack/pack.js +35 -0
  43. package/dist/pack/profile.js +222 -0
  44. package/dist/pack/stats.js +37 -0
  45. package/dist/templates/headings.js +34 -0
  46. package/dist/util/argparse.js +47 -1
  47. package/dist/util/filter.js +18 -0
  48. package/dist/util/id.js +23 -0
  49. package/dist/util/output.js +2 -2
  50. package/package.json +6 -2
package/README.md CHANGED
@@ -1,224 +1,244 @@
1
- # mdkg — Markdown Knowledge Graph
1
+ # mdkg
2
2
 
3
- mdkg is a **local-first CLI** that turns structured Markdown into a **searchable, linkable knowledge graph** for engineering work.
3
+ mdkg is a local-first CLI for turning structured Markdown into deterministic project memory.
4
4
 
5
- It’s designed for:
6
- - humans who want lightweight project documentation + task tracking **in git**
7
- - AI coding agents/LLMs that need **deterministic context bundles** for code generation
5
+ It is built for:
6
+ - human builders who want project truth and task state in git
7
+ - AI agents that need deterministic context instead of ad-hoc file reading
8
+ - human + agent pairs who want one shared source of truth
8
9
 
9
- mdkg is intentionally boring and portable:
10
- - **Node.js 18+**
11
- - written in **TypeScript**
12
- - **zero runtime dependencies** (no sqlite, no external indexers)
13
- - **dev dependencies only**: TypeScript (build-time) and Node 18+ (runtime)
14
- - works with npm / pnpm / bun
10
+ mdkg stays deliberately boring:
11
+ - repo-native under `.mdkg/`
12
+ - TypeScript + Node.js 18+
13
+ - zero runtime dependencies
14
+ - no sqlite, daemon, hosted index, or vector DB
15
15
 
16
- ---
16
+ Current package version in this repo: `0.0.4`
17
+ Publish status: cut prepared, not yet published
17
18
 
18
- ## Core idea
19
+ ## The product shape
19
20
 
20
- You store project knowledge as Markdown nodes with strict frontmatter (a small, stable schema). mdkg:
21
+ mdkg has one core job: make repo knowledge cheap to retrieve and safe to reuse.
21
22
 
22
- 1) indexes those nodes into a local JSON cache (`.mdkg/index/global.json`)
23
- 2) provides fast search/list/show tools
24
- 3) generates deterministic **context packs** for agents (Markdown/JSON/TOON/XML exports)
23
+ The primary loop is:
24
+ 1. initialize the repo
25
+ 2. create or select work
26
+ 3. inspect the current truth
27
+ 4. build a deterministic pack
28
+ 5. validate before closing the loop
25
29
 
26
- Everything stays in your repo. No servers. No surprises.
27
-
28
- ---
29
-
30
- ## Repository structure
31
-
32
- mdkg lives in a hidden directory at the repo root:
33
-
34
- - `.mdkg/core/` — rules + “pinned” docs
35
- - `.mdkg/design/` — decisions + architecture
36
- - `.mdkg/work/` — epics/tasks/bugs/tests/checkpoints
37
- - `.mdkg/templates/` — document templates used by `mdkg new`
38
- - `.mdkg/index/` — generated cache (gitignored)
39
-
40
- mdkg is root-only: you run commands from the repository root and mdkg indexes all registered workspaces without “discovering” nested repos.
41
-
42
- ---
30
+ If an agent is involved, the default handoff primitive is `mdkg pack <id>`.
31
+ If a repo needs repeatable procedures, author them as first-class skills under `.mdkg/skills/`.
43
32
 
44
33
  ## Install
45
34
 
46
- Pre-release note: this project is being actively developed and dogfooded.
47
-
48
35
  Once published:
49
- - `npm i -g mdkg`
50
- - `pnpm add -g mdkg`
51
- - `bun add -g mdkg`
52
36
 
53
- ---
37
+ ```bash
38
+ npm i -g mdkg
39
+ # or
40
+ pnpm add -g mdkg
41
+ # or
42
+ bun add -g mdkg
43
+ ```
54
44
 
55
45
  ## Quickstart
56
46
 
57
- 1) Initialize mdkg in your repo:
47
+ Initialize mdkg in a repo:
58
48
 
59
49
  ```bash
60
- mdkg init
50
+ mdkg init --llm
61
51
  ```
62
52
 
63
- This creates `.mdkg/` (rules, templates, work folders) and updates ignore rules so caches are not committed.
53
+ This is the generic OSS bootstrap path. It creates `.mdkg/` and updates `.gitignore` / `.npmignore` by default. Use `--no-update-ignores` to opt out.
64
54
 
65
- 2) Index your repo (cache is default behavior):
55
+ Optional agent-ready scaffold:
66
56
 
67
57
  ```bash
68
- mdkg index
58
+ mdkg init --omni
69
59
  ```
70
60
 
71
- 3) Create a task from a template:
61
+ This adds strict-node `SOUL.md` / `HUMAN.md`, a skills scaffold, seeded events JSONL, and core pin updates.
62
+
63
+ Create a task:
72
64
 
73
65
  ```bash
74
66
  mdkg new task "bootstrap cli" --status todo --priority 1 --tags cli,build
75
67
  ```
76
68
 
77
- 4) Search and list:
69
+ Inspect the current truth:
78
70
 
79
71
  ```bash
80
72
  mdkg search "pack"
81
- mdkg list --type task --status todo
82
73
  mdkg show task-1
74
+ mdkg next
83
75
  ```
84
76
 
85
- 5) Generate a deterministic context bundle for an agent:
77
+ Build deterministic context:
86
78
 
87
79
  ```bash
88
- mdkg pack task-1 --format md --verbose
80
+ mdkg pack task-1
81
+ mdkg pack task-1 --profile concise --dry-run --stats
89
82
  ```
90
83
 
91
- ---
84
+ Validate before handoff or commit:
92
85
 
93
- ## Why this exists
94
-
95
- LLMs are great at writing code, but they need **high-quality, structured context**.
96
-
97
- mdkg makes that context:
98
- - easy to author
99
- - easy to query
100
- - easy to hand to an agent
101
- - reproducible across runs and contributors
102
-
103
- This is also intended to be a compatible building block for “life git”-style productivity systems (which may later add richer databases like SQLite/Postgres). mdkg stays minimal and local.
104
-
105
- ---
106
-
107
- ## Concepts
86
+ ```bash
87
+ mdkg validate
88
+ ```
108
89
 
109
- ### Nodes
90
+ Mutate a task-like node without manual markdown editing:
110
91
 
111
- A node is a Markdown file with strict YAML-like frontmatter fenced by `---`.
92
+ ```bash
93
+ mdkg task start task-1 --run-id run_local_1
94
+ mdkg task update task-1 --add-artifacts tests://unit.txt --add-tags release
95
+ mdkg task done task-1 --checkpoint "release readiness milestone"
96
+ ```
112
97
 
113
- Each node must include:
114
- - `id` (unique per workspace; global uniqueness via qualified IDs)
115
- - `type` (rule, prd, edd, dec, prop, epic, feat, task, bug, checkpoint, test)
116
- - `title`
117
- - `created` / `updated` (`YYYY-MM-DD`)
98
+ Enable and append baseline event memory:
118
99
 
119
- Work items also typically include:
120
- - `status` (backlog, blocked, todo, progress, review, done)
121
- - `priority` (0..9, where 0 is most urgent)
100
+ ```bash
101
+ mdkg event enable
102
+ mdkg event append --kind RUN_COMPLETED --status ok --refs task-1 --notes "manual closeout"
103
+ ```
122
104
 
123
- ### Graph links
105
+ Create a first-class skill:
124
106
 
125
- mdkg treats these frontmatter fields as explicit graph structure:
126
- - `epic`, `parent`
127
- - `relates: [...]`
128
- - `blocked_by: [...]`, `blocks: [...]`
129
- - `prev`, `next` (chain navigation)
107
+ ```bash
108
+ mdkg skill new release-readiness "release readiness audit" --description "use when preparing a release"
109
+ mdkg skill list
110
+ mdkg skill show release-readiness
111
+ mdkg skill validate release-readiness
112
+ ```
130
113
 
131
- ### Searchable metadata
114
+ ## LLM-readable onboarding artifacts
132
115
 
133
- If you want something searchable, put it in frontmatter:
134
- - `links: [ref, ref]` (URLs or any searchable reference string)
135
- - `artifacts: [ref, ref]` (build outputs, PRs, commits, releases, tarballs, etc.)
136
- - `refs: [id, id]` (non-edge references)
137
- - `aliases: [text, text]`
116
+ The root docs below are the canonical fast-start set for humans and agents:
117
+ - [`llms.txt`](/Users/nicholasreames/Git/mdkg/llms.txt)
118
+ - [`AGENT_PROMPT_SNIPPET.md`](/Users/nicholasreames/Git/mdkg/AGENT_PROMPT_SNIPPET.md)
119
+ - [`PACK_EXAMPLES.md`](/Users/nicholasreames/Git/mdkg/PACK_EXAMPLES.md)
120
+ - [`MANUAL_BEHAVIOR_AUDIT.md`](/Users/nicholasreames/Git/mdkg/MANUAL_BEHAVIOR_AUDIT.md)
121
+ - [`CLI_COMMAND_MATRIX.md`](/Users/nicholasreames/Git/mdkg/CLI_COMMAND_MATRIX.md)
122
+ - [`COVERAGE_HARDENING_MATRIX.md`](/Users/nicholasreames/Git/mdkg/COVERAGE_HARDENING_MATRIX.md)
138
123
 
139
- ---
124
+ ## Repository shape
140
125
 
141
- ## CLI commands (v1)
126
+ mdkg lives under a hidden root directory:
127
+ - `.mdkg/core/` rules and pinned docs
128
+ - `.mdkg/design/` product, design, and decision docs
129
+ - `.mdkg/work/` tasks, bugs, tests, epics, checkpoints
130
+ - `.mdkg/templates/` templates used by `mdkg new`
131
+ - `.mdkg/skills/` Agent Skills packages
132
+ - `.mdkg/index/` generated cache files
142
133
 
143
- ### Project setup
134
+ ## Primary commands
144
135
 
136
+ These are the commands new users and agents should learn first:
145
137
  - `mdkg init`
146
- - create `.mdkg/` structure
147
- - add ignore rules for caches
148
-
149
- ### Indexing
138
+ - `mdkg new`
139
+ - `mdkg search`
140
+ - `mdkg show`
141
+ - `mdkg next`
142
+ - `mdkg pack`
143
+ - `mdkg skill`
144
+ - `mdkg task`
145
+ - `mdkg validate`
150
146
 
147
+ Advanced / maintenance commands still exist, but they are not the first-run story:
148
+ - `mdkg event`
149
+ - `mdkg checkpoint`
151
150
  - `mdkg index`
152
- - builds `.mdkg/index/global.json`
153
- - cache is the default; mdkg will reindex automatically if stale
154
-
155
- ### Query
156
-
157
- - `mdkg show <id-or-qid>`
158
- - `mdkg list [--type <type>] [--status <status>] [--ws <alias>] [--epic <id>] [--priority <n>]`
159
- - `mdkg search "<query>"`
160
-
161
- ### Packs (agent context)
151
+ - `mdkg guide`
152
+ - `mdkg format`
153
+ - `mdkg doctor`
154
+ - `mdkg workspace`
162
155
 
163
- - `mdkg pack <id> [--format md|json|toon|xml] [--verbose] [--depth <n>] [--edges <keys>]`
156
+ ## Skills
164
157
 
165
- `--verbose` includes pinned core docs listed in `.mdkg/core/core.md`.
166
- If `--out` is omitted, packs are written to `.mdkg/pack/pack_<kind>_<id>_<timestamp>.<ext>`.
158
+ mdkg supports Agent Skills as procedural memory.
167
159
 
168
- ### Quickstart (CLI only)
160
+ Canonical layout:
169
161
 
170
- ```bash
171
- mdkg init --llm
172
- mdkg index
173
- mdkg new task "..." --status todo --priority 1
174
- mdkg list --status todo
175
- mdkg pack <id> --verbose
176
- mdkg validate
162
+ ```text
163
+ .mdkg/skills/<slug>/SKILL.md
177
164
  ```
178
165
 
179
- ### Workflow helpers
180
-
181
- - `mdkg next [<id>] [--ws <alias>]`
182
- - follows `next` chain if present; otherwise picks highest priority work item
183
-
184
- - `mdkg checkpoint new "<title>"`
185
- - creates a checkpoint node (a compression summary)
186
-
187
- ### Quality gates
188
-
189
- - `mdkg validate`
190
- - strict frontmatter validation
191
- - missing required fields, invalid enums, dangling edges, cycles, duplicates
192
- - supports `--out <path>` and `--quiet` for CI workflows
193
-
194
- - `mdkg format`
195
- - conservative frontmatter normalizer (idempotent)
196
-
197
- ---
166
+ Current source behavior:
167
+ - skills are indexed into `.mdkg/index/skills.json`
168
+ - skills have a focused command family:
169
+ - `mdkg skill new <slug> "<name>" --description "..."`
170
+ - `mdkg skill list`
171
+ - `mdkg skill search "<query>"`
172
+ - `mdkg skill show <slug>`
173
+ - `mdkg skill validate [<slug>]`
174
+ - machine-readable skill discovery is available through:
175
+ - `mdkg skill list --json`
176
+ - `mdkg skill search "<query>" --json`
177
+ - `mdkg skill show <slug> --json`
178
+ - work items may reference `skills: [slug,...]`
179
+ - packs may include skills with `--skills` and `--skills-depth`
180
+ - mdkg indexes and discovers skills but does not execute skill scripts
181
+ - `SKILL.md` is canonical
182
+ - `SKILLS.md` is tolerated on read for compatibility, but validation warns and canonical docs still use `SKILL.md`
183
+ - if both `SKILL.md` and `SKILLS.md` exist in one skill folder, validation fails
184
+ - `mdkg skill new` scaffolds `SKILL.md`, `references/`, `assets/`, and `scripts/` only when requested with `--with-scripts`
185
+
186
+ This repo now dogfoods three internal skills:
187
+ - `author-mdkg-skill`
188
+ - `select-work-and-ground-context`
189
+ - `build-pack-and-execute-task`
190
+ - `verify-close-and-checkpoint`
191
+
192
+ ## Current direction
193
+
194
+ Current `0.0.4` release polish already includes:
195
+ - `init --omni`
196
+ - default ignore updates with `--no-update-ignores`
197
+ - skills indexing and search/show/list support
198
+ - optional `skills: [...]` on work items
199
+ - pack-time skill inclusion
200
+ - latest-checkpoint resolver + index hint
201
+ - events JSONL validation
202
+
203
+ Current `0.0.4` polish direction is:
204
+ - keep the OSS story generic around `init --llm`
205
+ - keep `pack <id>` at the center of the human/agent loop
206
+ - make task mutation and event logging guided instead of purely manual
207
+ - dogfood real skills inside the repo
208
+ - make skill authoring first-class through `mdkg skill`
209
+ - make `CLI_COMMAND_MATRIX.md` the single source of truth for the live CLI surface
210
+ - run manual behavior audits before enforcing stronger coverage thresholds
211
+
212
+ Design and decision records live in the internal graph under `.mdkg/design/`.
198
213
 
199
214
  ## Safety
200
215
 
201
- mdkg is designed to avoid accidental leaks:
202
- - cache files live under `.mdkg/index/` and must be gitignored
203
- - publishing should use a strict `package.json.files` whitelist
204
- - `.mdkg/` content should never ship to production builds
216
+ mdkg is not a secret store.
205
217
 
206
- ---
218
+ Use these defaults:
219
+ - keep `.mdkg/index/` gitignored
220
+ - keep `.mdkg/pack/` gitignored
221
+ - keep `.mdkg/work/events/*.jsonl` gitignored unless you deliberately opt in
222
+ - do not ship `.mdkg/` into production builds or published packages
223
+ - if an external orchestrator is writing mdkg state, keep one durable writer per run and batch commits at end-of-run or checkpoint boundaries
224
+ - do not commit on every tool call
207
225
 
208
226
  ## Contributing
209
227
 
210
- This repo dogfoods mdkg. The source of truth for behavior is:
211
- - `.mdkg/core/rule-*.md`
212
- - `.mdkg/core/guide.md`
213
- - `.mdkg/core/rule-2-context-pack-rules.md`
214
-
215
- Suggested workflow:
216
- 1) create or update a task in `.mdkg/work/`
217
- 2) run `mdkg validate`
218
- 3) generate a pack for the task and use it as agent context
228
+ This repo dogfoods mdkg itself. The behavior source of truth is the combination of:
229
+ - source under `src/`
230
+ - tests under `tests/`
231
+ - internal rules and design docs under `.mdkg/`
219
232
 
220
- ---
233
+ Suggested local loop:
234
+ 1. create or select a work item
235
+ 2. inspect truth with `search`, `show`, or `next`
236
+ 3. build context with `pack <id>`
237
+ 4. mutate task state with `mdkg task ...` when durable state changes
238
+ 5. enable event logging if provenance should be captured in JSONL
239
+ 6. implement and test
240
+ 7. run `mdkg validate`
221
241
 
222
242
  ## License
223
243
 
224
- MIT (recommended). Add a `LICENSE` file to confirm.
244
+ MIT