mdkg 0.0.3 → 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 (42) hide show
  1. package/README.md +171 -169
  2. package/dist/cli.js +980 -624
  3. package/dist/commands/checkpoint.js +17 -6
  4. package/dist/commands/event.js +46 -0
  5. package/dist/commands/event_support.js +146 -0
  6. package/dist/commands/format.js +6 -7
  7. package/dist/commands/index.js +10 -4
  8. package/dist/commands/init.js +198 -16
  9. package/dist/commands/list.js +18 -1
  10. package/dist/commands/new.js +30 -5
  11. package/dist/commands/pack.js +194 -2
  12. package/dist/commands/query_output.js +84 -0
  13. package/dist/commands/search.js +22 -5
  14. package/dist/commands/show.js +26 -11
  15. package/dist/commands/skill.js +359 -0
  16. package/dist/commands/skill_support.js +121 -0
  17. package/dist/commands/task.js +270 -0
  18. package/dist/commands/validate.js +104 -7
  19. package/dist/graph/edges.js +2 -2
  20. package/dist/graph/frontmatter.js +1 -0
  21. package/dist/graph/indexer.js +21 -0
  22. package/dist/graph/node.js +20 -4
  23. package/dist/graph/skills_index_cache.js +94 -0
  24. package/dist/graph/skills_indexer.js +160 -0
  25. package/dist/init/core/rule-1-mdkg-conventions.md +9 -2
  26. package/dist/init/core/rule-3-cli-contract.md +73 -14
  27. package/dist/init/core/rule-4-repo-safety-and-ignores.md +9 -3
  28. package/dist/init/core/rule-6-templates-and-schemas.md +6 -2
  29. package/dist/init/skills/SKILL.md.example +41 -0
  30. package/dist/init/templates/default/bug.md +1 -0
  31. package/dist/init/templates/default/chk.md +1 -0
  32. package/dist/init/templates/default/epic.md +1 -0
  33. package/dist/init/templates/default/feat.md +1 -0
  34. package/dist/init/templates/default/task.md +1 -0
  35. package/dist/init/templates/default/test.md +1 -0
  36. package/dist/pack/export_md.js +6 -0
  37. package/dist/pack/export_xml.js +6 -0
  38. package/dist/pack/pack.js +35 -0
  39. package/dist/util/argparse.js +25 -0
  40. package/dist/util/filter.js +18 -0
  41. package/dist/util/id.js +23 -0
  42. package/package.json +5 -2
package/README.md CHANGED
@@ -1,242 +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 --llm --update-gitignore --update-npmignore
50
+ mdkg init --llm
61
51
  ```
62
52
 
63
- This creates `.mdkg/` (rules, templates, work folders). Use the ignore-update flags to append recommended mdkg ignore entries.
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
89
- mdkg pack task-1 --pack-profile concise --dry-run --stats
80
+ mdkg pack task-1
81
+ mdkg pack task-1 --profile concise --dry-run --stats
90
82
  ```
91
83
 
92
- ---
93
-
94
- ## Why this exists
84
+ Validate before handoff or commit:
95
85
 
96
- LLMs are great at writing code, but they need **high-quality, structured context**.
97
-
98
- mdkg makes that context:
99
- - easy to author
100
- - easy to query
101
- - easy to hand to an agent
102
- - reproducible across runs and contributors
103
-
104
- 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.
105
-
106
- ---
107
-
108
- ## Concepts
86
+ ```bash
87
+ mdkg validate
88
+ ```
109
89
 
110
- ### Nodes
90
+ Mutate a task-like node without manual markdown editing:
111
91
 
112
- 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
+ ```
113
97
 
114
- Each node must include:
115
- - `id` (unique per workspace; global uniqueness via qualified IDs)
116
- - `type` (rule, prd, edd, dec, prop, epic, feat, task, bug, checkpoint, test)
117
- - `title`
118
- - `created` / `updated` (`YYYY-MM-DD`)
98
+ Enable and append baseline event memory:
119
99
 
120
- Work items also typically include:
121
- - `status` (backlog, blocked, todo, progress, review, done)
122
- - `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
+ ```
123
104
 
124
- ### Graph links
105
+ Create a first-class skill:
125
106
 
126
- mdkg treats these frontmatter fields as explicit graph structure:
127
- - `epic`, `parent`
128
- - `relates: [...]`
129
- - `blocked_by: [...]`, `blocks: [...]`
130
- - `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
+ ```
131
113
 
132
- ### Searchable metadata
114
+ ## LLM-readable onboarding artifacts
133
115
 
134
- If you want something searchable, put it in frontmatter:
135
- - `links: [ref, ref]` (URLs or any searchable reference string)
136
- - `artifacts: [ref, ref]` (build outputs, PRs, commits, releases, tarballs, etc.)
137
- - `refs: [id, id]` (non-edge references)
138
- - `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)
139
123
 
140
- ---
124
+ ## Repository shape
141
125
 
142
- ## 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
143
133
 
144
- ### Project setup
134
+ ## Primary commands
145
135
 
136
+ These are the commands new users and agents should learn first:
146
137
  - `mdkg init`
147
- - create `.mdkg/` structure
148
- - add ignore rules for caches
149
-
150
- ### 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`
151
146
 
147
+ Advanced / maintenance commands still exist, but they are not the first-run story:
148
+ - `mdkg event`
149
+ - `mdkg checkpoint`
152
150
  - `mdkg index`
153
- - builds `.mdkg/index/global.json`
154
- - cache is the default; mdkg will reindex automatically if stale
155
-
156
- ### Query
157
-
158
- - `mdkg show <id-or-qid>`
159
- - `mdkg list [--type <type>] [--status <status>] [--ws <alias>] [--epic <id>] [--priority <n>]`
160
- - `mdkg search "<query>"`
161
-
162
- ### Packs (agent context)
163
-
164
- - `mdkg pack <id> [--format md|json|toon|xml] [--verbose] [--depth <n>] [--edges <keys>]`
165
- - `mdkg pack <id> [--pack-profile standard|concise|headers] [--max-chars <n>] [--max-lines <n>] [--max-tokens <n>]`
166
- - `mdkg pack <id> [--stats] [--stats-out <path>] [--truncation-report <path>]`
167
- - `mdkg pack <id> [--dry-run]`
168
- - `mdkg pack --list-profiles`
169
-
170
- `--verbose` includes pinned core docs listed in `.mdkg/core/core.md`.
171
- `--pack-profile concise` uses summary-oriented body shaping and strips code blocks by default.
172
- If `--out` is omitted, packs are written to `.mdkg/pack/pack_<kind>_<id>_<timestamp>.<ext>`.
173
-
174
- `--max-tokens` uses a heuristic estimate: `~tokens = chars / 4`.
175
-
176
- ### Quickstart (CLI only)
177
-
178
- ```bash
179
- mdkg init --llm
180
- mdkg index
181
- mdkg new task "..." --status todo --priority 1
182
- mdkg list --status todo
183
- mdkg pack <id> --verbose
184
- mdkg pack <id> --pack-profile concise --dry-run --stats
185
- mdkg validate
186
- ```
187
-
188
- ### Workflow helpers
189
-
190
- - `mdkg next [<id>] [--ws <alias>]`
191
- - follows `next` chain if present; otherwise picks highest priority work item
192
-
193
- - `mdkg checkpoint new "<title>"`
194
- - creates a checkpoint node (a compression summary)
195
-
151
+ - `mdkg guide`
152
+ - `mdkg format`
196
153
  - `mdkg doctor`
197
- - runs consumer diagnostics (node version, config, templates, index)
198
- - `mdkg doctor --json`
199
- - emits machine-readable diagnostics for scripts/CI
154
+ - `mdkg workspace`
200
155
 
201
- - `mdkg --version`
202
- - prints installed CLI version
156
+ ## Skills
203
157
 
204
- ### Quality gates
158
+ mdkg supports Agent Skills as procedural memory.
205
159
 
206
- - `mdkg validate`
207
- - strict frontmatter validation
208
- - missing required fields, invalid enums, dangling edges, cycles, duplicates
209
- - supports `--out <path>` and `--quiet` for CI workflows
160
+ Canonical layout:
210
161
 
211
- - `mdkg format`
212
- - conservative frontmatter normalizer (idempotent)
162
+ ```text
163
+ .mdkg/skills/<slug>/SKILL.md
164
+ ```
213
165
 
214
- ---
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/`.
215
213
 
216
214
  ## Safety
217
215
 
218
- mdkg is designed to avoid accidental leaks:
219
- - cache files live under `.mdkg/index/` and must be gitignored
220
- - publishing should use a strict `package.json.files` whitelist
221
- - `.mdkg/` content should never ship to production builds
216
+ mdkg is not a secret store.
222
217
 
223
- ---
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
224
225
 
225
226
  ## Contributing
226
227
 
227
- This repo dogfoods mdkg. The source of truth for behavior is:
228
- - `.mdkg/core/rule-*.md`
229
- - `.mdkg/core/guide.md`
230
- - `.mdkg/core/rule-2-context-pack-rules.md`
231
-
232
- Suggested workflow:
233
- 1) create or update a task in `.mdkg/work/`
234
- 2) run `mdkg validate`
235
- 3) generate a pack for the task and use it as agent context
236
- 4) run `npm run smoke:consumer` before publishing to verify tarball install + onboarding flow
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/`
237
232
 
238
- ---
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`
239
241
 
240
242
  ## License
241
243
 
242
- MIT (recommended). Add a `LICENSE` file to confirm.
244
+ MIT