mneme-cli 0.4.0__tar.gz

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 (48) hide show
  1. mneme_cli-0.4.0/AGENTS.md +706 -0
  2. mneme_cli-0.4.0/CHANGELOG.md +164 -0
  3. mneme_cli-0.4.0/CLAUDE.md +342 -0
  4. mneme_cli-0.4.0/CODER.md +506 -0
  5. mneme_cli-0.4.0/EXAMPLES.md +1058 -0
  6. mneme_cli-0.4.0/FEATURES.md +267 -0
  7. mneme_cli-0.4.0/LICENSE +21 -0
  8. mneme_cli-0.4.0/MANIFEST.in +51 -0
  9. mneme_cli-0.4.0/PKG-INFO +499 -0
  10. mneme_cli-0.4.0/README.md +458 -0
  11. mneme_cli-0.4.0/mneme/__init__.py +8 -0
  12. mneme_cli-0.4.0/mneme/__main__.py +5 -0
  13. mneme_cli-0.4.0/mneme/config.py +103 -0
  14. mneme_cli-0.4.0/mneme/core.py +6526 -0
  15. mneme_cli-0.4.0/mneme/profiles/eu-mdr.md +196 -0
  16. mneme_cli-0.4.0/mneme/profiles/iso-13485.md +182 -0
  17. mneme_cli-0.4.0/mneme/profiles/mappings/dds.json +21 -0
  18. mneme_cli-0.4.0/mneme/profiles/mappings/requirements.json +22 -0
  19. mneme_cli-0.4.0/mneme/profiles/mappings/risk-register.json +24 -0
  20. mneme_cli-0.4.0/mneme/profiles/mappings/test-cases.json +21 -0
  21. mneme_cli-0.4.0/mneme/profiles/mappings/user-needs.json +19 -0
  22. mneme_cli-0.4.0/mneme/server.py +312 -0
  23. mneme_cli-0.4.0/mneme/templates/workspace/.gitignore +9 -0
  24. mneme_cli-0.4.0/mneme/templates/workspace/AGENTS.md +706 -0
  25. mneme_cli-0.4.0/mneme/templates/workspace/README.md +33 -0
  26. mneme_cli-0.4.0/mneme/templates/workspace/inbox/.gitkeep +0 -0
  27. mneme_cli-0.4.0/mneme/templates/workspace/index.md +18 -0
  28. mneme_cli-0.4.0/mneme/templates/workspace/log.md +6 -0
  29. mneme_cli-0.4.0/mneme/templates/workspace/profiles/README.md +109 -0
  30. mneme_cli-0.4.0/mneme/templates/workspace/profiles/mappings/.gitkeep +0 -0
  31. mneme_cli-0.4.0/mneme/templates/workspace/schema/entities.json +5 -0
  32. mneme_cli-0.4.0/mneme/templates/workspace/schema/graph.json +6 -0
  33. mneme_cli-0.4.0/mneme/templates/workspace/schema/tags.json +5 -0
  34. mneme_cli-0.4.0/mneme/templates/workspace/sources/.gitkeep +0 -0
  35. mneme_cli-0.4.0/mneme/templates/workspace/wiki/_templates/page.md +31 -0
  36. mneme_cli-0.4.0/mneme/ui.html +1520 -0
  37. mneme_cli-0.4.0/mneme_cli.egg-info/SOURCES.txt +45 -0
  38. mneme_cli-0.4.0/pyproject.toml +72 -0
  39. mneme_cli-0.4.0/setup.cfg +4 -0
  40. mneme_cli-0.4.0/tests/__init__.py +0 -0
  41. mneme_cli-0.4.0/tests/test_agent_loop.py +376 -0
  42. mneme_cli-0.4.0/tests/test_bug_regressions.py +357 -0
  43. mneme_cli-0.4.0/tests/test_core.py +1038 -0
  44. mneme_cli-0.4.0/tests/test_ingest_csv.py +249 -0
  45. mneme_cli-0.4.0/tests/test_profile.py +673 -0
  46. mneme_cli-0.4.0/tests/test_schema_search.py +409 -0
  47. mneme_cli-0.4.0/tests/test_tornado_lint.py +385 -0
  48. mneme_cli-0.4.0/tests/test_trace.py +403 -0
@@ -0,0 +1,706 @@
1
+ # AGENTS.md
2
+
3
+ This document is the contract for any LLM agent driving the `mneme` CLI.
4
+ It complements `CLAUDE.md` (which describes the wiki-layer protocol) by
5
+ describing **the agent's job and how mneme helps you do it**. Read this
6
+ file once at the start of a session and keep it in context.
7
+
8
+ You are an agent driving mneme. Mneme is the substrate. You are the writer,
9
+ the reviewer, and the judge. Mneme gives you structure, evidence, vocabulary
10
+ rules, and a task graph. It does not call any LLM. Every intelligent action
11
+ is yours.
12
+
13
+ ---
14
+
15
+ ## tl;dr — the 30-second version
16
+
17
+ ```bash
18
+ # 1. Understand the workspace
19
+ mneme stats
20
+ mneme profile show
21
+
22
+ # 2. Turn the user's goal into a plan
23
+ mneme agent plan --goal "produce a DVR for the TDA algorithm" \
24
+ --doc-type design-validation-report --client tda
25
+
26
+ # 3. Walk the plan, one task at a time, until done
27
+ mneme agent next-task # read envelope, run next_command
28
+ mneme draft --doc-type ... --section ... # (or whatever next_command says)
29
+ # (do the intelligent work)
30
+ mneme agent task-done <task-id>
31
+ # repeat
32
+ ```
33
+
34
+ When `mneme agent next-task` returns `{done: true}`, you are finished.
35
+
36
+ ---
37
+
38
+ ## 1. What mneme is (and is not)
39
+
40
+ - **Mneme is a substrate.** It stores evidence (`sources/`), a structured
41
+ wiki (`wiki/`), and machine-readable schema (`schema/`). It knows how to
42
+ ingest, search, trace, harmonize, resync, draft, and plan. It does not
43
+ know how to write.
44
+ - **You are the writer.** Mneme assembles contracts — write packets, review
45
+ packets, task envelopes — and hands them to you. You produce the prose.
46
+ - **The wiki is the source of truth, not the source files.** Query the wiki.
47
+ Only fall through to `sources/` when the wiki is empty on a topic.
48
+ - **Profiles are the style contract.** A profile is a markdown file with
49
+ YAML frontmatter at `<package>/profiles/<name>.md` or
50
+ `<workspace>/profiles/<name>.md`. Workspace profiles shadow bundled ones.
51
+ - **Mneme does NOT call any LLM.** It builds prompts and packets; you act
52
+ on them. This is deliberate — mneme stays deterministic and cheap.
53
+ - **Sources are immutable.** Never modify anything under `sources/`.
54
+
55
+ ---
56
+
57
+ ## 2. The workspace shape you can rely on
58
+
59
+ A mneme workspace is a directory. Its shape is stable across versions:
60
+
61
+ ```
62
+ <workspace>/
63
+ sources/ immutable evidence, one subdir per client
64
+ wiki/ markdown pages, Obsidian-compatible
65
+ {client}/ one dir per client engagement
66
+ _shared/ cross-client knowledge
67
+ schema/
68
+ entities.json registered entities
69
+ graph.json relationship graph
70
+ tags.json tag registry
71
+ traceability.json trace links between pages
72
+ memvid/ optional .mv2 archives (semantic search)
73
+ profiles/ workspace-local profiles and CSV mappings
74
+ mappings/ JSON column mappings for ingest-csv
75
+ exports/ JSON / markdown exports
76
+ snapshots/ versioned zip archives
77
+ .mneme/
78
+ agent-plans/ agent plan state (gitignored)
79
+ index.md master catalog of wiki pages
80
+ log.md append-only activity timeline
81
+ ```
82
+
83
+ State discovery rituals — run these before doing anything destructive:
84
+
85
+ | Command | What it tells you |
86
+ |---|---|
87
+ | `mneme stats` | Source count, wiki count, entities, tags, drift |
88
+ | `mneme status` | What is pending (un-ingested sources, orphans) |
89
+ | `mneme recent -n 10` | What happened recently, who did it |
90
+ | `mneme profile show` | Active profile, vocabulary rules, doc types |
91
+
92
+ If `mneme profile show` prints "no active profile", **stop and set one
93
+ before writing any prose**. Prose without a profile has no style contract
94
+ and cannot be graded.
95
+
96
+ ---
97
+
98
+ ## 3. The five operations you'll do most
99
+
100
+ ### 3.1 INGEST — bringing evidence into the workspace
101
+
102
+ ```bash
103
+ mneme ingest <file> <client>
104
+ mneme ingest-dir <directory> <client>
105
+ mneme ingest-csv <file> <client> [--mapping <name>]
106
+ mneme tornado --client <client> # batch from inbox/
107
+ ```
108
+
109
+ `ingest` is atomic: it writes the wiki page, updates the schema, and
110
+ advances the Memvid archive in one operation. `ingest-csv` produces one
111
+ wiki page per row, with trace links derived from the mapping. `tornado`
112
+ is a bulk inbox processor — it auto-detects page type and routes CSVs
113
+ through `ingest-csv`, everything else through `ingest`.
114
+
115
+ Rule: never re-run `ingest` on a file that has a baseline. Use `resync`.
116
+
117
+ ### 3.2 SEARCH — finding what's already there
118
+
119
+ ```bash
120
+ mneme search "<query>"
121
+ mneme search "<query>" --client <client>
122
+ mneme trace show <client>/<page> --direction forward
123
+ mneme trace show <client>/<page> --direction backward
124
+ mneme trace gaps <client>
125
+ mneme trace matrix <client>
126
+ ```
127
+
128
+ Search the wiki first. Read source files only when wiki coverage is zero.
129
+ `trace gaps` is the fastest way to find holes in a V-model chain.
130
+
131
+ ### 3.3 DRAFT — writing new prose (NEW in v0.4.0)
132
+
133
+ ```bash
134
+ mneme draft --doc-type <type> --section <slug> --client <client> \
135
+ [--source <path>] [--query <text>] [-k N] \
136
+ [--json] [--out <file>]
137
+ ```
138
+
139
+ `mneme draft` builds a **write packet** and prints it as markdown (or
140
+ JSON with `--json`). The packet is everything you need to write one
141
+ section of a document:
142
+
143
+ | Field | Meaning |
144
+ |---|---|
145
+ | `profile_name` | Active profile that governs this section |
146
+ | `doc_type` | The document type, e.g. `design-validation-report` |
147
+ | `section` | The section slug, e.g. `purpose-and-scope` |
148
+ | `section_notes` | The normative notes for this section from the profile |
149
+ | `all_section_notes` | All sections of this doc type (for context) |
150
+ | `writing_style` | principles, general_rules, terminology_guidance, framing_examples |
151
+ | `submission_checklist` | Pre-submission go/no-go items |
152
+ | `evidence` | Candidate material: the explicit source (if given) plus wiki search hits |
153
+ | `write_prompt` | A ready-to-paste instruction telling you what to produce |
154
+
155
+ Evidence selection:
156
+ - If `--source <path>` is given, that file is included verbatim as
157
+ `kind: explicit-source`.
158
+ - If `--query <text>` is given, mneme runs a wiki text search and filters
159
+ to the requested client; hits are included as `kind: wiki-search-hit`.
160
+ - If neither is given, the section slug is used as an implicit query so
161
+ the packet always has something to work with.
162
+
163
+ Your contract when consuming a write packet:
164
+
165
+ 1. Use ONLY the evidence in the packet. Do not invent facts.
166
+ 2. Cite each non-trivial claim with the source path from the packet.
167
+ 3. For missing refs, insert the profile's
168
+ `placeholder_for_missing_refs` (default `[TO ADD REF]`) at the exact spot.
169
+ 4. Obey the writing style block: principles, general rules, terminology
170
+ guidance, and framing examples are all normative.
171
+ 5. Output a single markdown section starting with `## <section-slug>`.
172
+ No frontmatter. No surrounding prose.
173
+
174
+ ### 3.4 REVIEW — grading prose against the writing style
175
+
176
+ ```bash
177
+ mneme validate writing-style <client>/<page> # markdown packet
178
+ mneme validate writing-style <client>/<page> --json # raw dict
179
+ mneme validate consistency --client <client> # cross-doc checks
180
+ ```
181
+
182
+ `validate writing-style` builds a **review packet**: the page content,
183
+ its frontmatter, the active profile's `writing_style` block, the
184
+ `section_notes` resolved from the page's frontmatter `type:` field, the
185
+ submission checklist, and a ready-to-paste review prompt.
186
+
187
+ Your contract when consuming a review packet:
188
+
189
+ 1. For each issue, quote the offending text, explain the violation, and
190
+ propose a concrete rewrite.
191
+ 2. Walk the submission checklist and report pass/fail per item with a
192
+ one-line justification.
193
+ 3. Apply your own fixes to the page in place. Do not leave a report and
194
+ walk away — the user expects the document to improve.
195
+
196
+ ### 3.5 RESYNC — merging external edits without losing your work
197
+
198
+ ```bash
199
+ mneme resync <file> <client> # preview + apply
200
+ mneme resync <file> <client> --dry-run # preview only
201
+ mneme resync-resolve <client>/<page> # after manual fix
202
+ ```
203
+
204
+ When a colleague sends an updated source file, never re-ingest — that
205
+ would clobber hand edits. Use `resync`. It runs a 3-way merge between
206
+ baseline, your current wiki page, and a fresh ingest of the new source.
207
+ If there are conflicts, the page is left with merge markers. Edit them
208
+ out manually, then run `resync-resolve`.
209
+
210
+ ---
211
+
212
+ ## 4. Profiles and the writing-style contract
213
+
214
+ Profiles are markdown files with YAML frontmatter. The frontmatter carries
215
+ structured fields (`vocabulary`, `trace_types`, `tone`, `requirement_levels`,
216
+ etc.). The body carries the writing-style prose under recognised H1 headings
217
+ (`# Principles`, `# General Rules`, `# Terminology`, `# Framing: ...`,
218
+ `# Document Type: <slug>`, `## Section: <slug>`, `# Submission Checklist`).
219
+
220
+ Two things you must know before writing:
221
+
222
+ 1. **Active profile lookup.** `mneme profile show` prints the active
223
+ profile's name, doc types, vocabulary rule count, and submission
224
+ checklist length. Run it first. If you want the raw contract, read the
225
+ `.md` file directly — mneme resolves workspace profiles first, then
226
+ bundled profiles.
227
+ 2. **Section resolution.** When you write a wiki page whose frontmatter
228
+ says `type: design-validation-report`, `mneme validate writing-style`
229
+ will resolve the `section_notes` for `design-validation-report` from
230
+ the active profile and include them in the review packet. If the
231
+ `type:` does not match any doc type in the profile, `matched_section`
232
+ is empty and only the general writing style applies.
233
+
234
+ Harmonize vs validate:
235
+
236
+ | Command | What it does | When to run |
237
+ |---|---|---|
238
+ | `mneme harmonize --client <c>` | Mechanical vocabulary swap (find/replace against `vocabulary[]`) | After drafting, before review |
239
+ | `mneme harmonize --client <c> --fix` | Same, but writes fixes back | After drafting |
240
+ | `mneme validate writing-style <page>` | Build an LLM review packet for prose quality | After harmonize |
241
+ | `mneme validate consistency --client <c>` | Cross-document version/standard checks | Before submission |
242
+
243
+ Harmonize is deterministic and dumb. Validate writing-style is your job
244
+ and requires reasoning.
245
+
246
+ ---
247
+
248
+ ## 5. The agent loop (the headline feature)
249
+
250
+ The agent loop turns "produce a Design Validation Report" into a TODO list
251
+ you can walk one task at a time. Mneme generates the plan deterministically
252
+ from the active profile — it knows which sections exist and in what order.
253
+
254
+ Commands:
255
+
256
+ | Command | Purpose |
257
+ |---|---|
258
+ | `mneme agent plan --goal <text> --doc-type <type> --client <c> [--id <id>] [--json]` | Generate a new plan and persist it |
259
+ | `mneme agent show [--plan <id>] [--json]` | Show a plan and per-task statuses |
260
+ | `mneme agent next-task [--plan <id>] [--json]` | Return the next ready task (respects deps) |
261
+ | `mneme agent task-done <task-id> [--plan <id>]` | Mark a task complete |
262
+ | `mneme agent list [--json]` | List every plan in the workspace |
263
+
264
+ Plans live under `<workspace>/.mneme/agent-plans/<id>.json` (the plan
265
+ document) and `<id>.state.json` (task statuses). `.mneme/` is gitignored.
266
+ If you omit `--plan <id>`, mneme picks the most-recently-modified plan.
267
+
268
+ Task shape:
269
+
270
+ ```json
271
+ {
272
+ "id": "section-purpose-and-scope",
273
+ "kind": "draft-section",
274
+ "goal": "Draft the `purpose-and-scope` section of the design-validation-report",
275
+ "instructions": "Run the next_command, then write a single markdown block...",
276
+ "preconditions": ["Active profile must be \"EU MDR\""],
277
+ "deliverable": {
278
+ "kind": "markdown-section",
279
+ "target_page": "wiki/tda/design-validation-report.md",
280
+ "section_slug": "purpose-and-scope"
281
+ },
282
+ "next_command": "mneme draft --doc-type design-validation-report --section purpose-and-scope --client tda",
283
+ "after_done": "mneme agent task-done section-purpose-and-scope --plan design-validation-report-tda-2026-04-09",
284
+ "depends_on": [],
285
+ "blocks": ["assemble-document"],
286
+ "status": "pending"
287
+ }
288
+ ```
289
+
290
+ A plan for `design-validation-report` under the bundled `eu-mdr` profile
291
+ produces **15 tasks**: one `draft-section` (or `review-section` if the
292
+ page already exists) per section in the profile's `section_notes` (11
293
+ for `eu-mdr` DVR), then `assemble-document`, `harmonize`, `review-page`,
294
+ `submission-check`. Dependencies:
295
+
296
+ ```
297
+ section-* (x11) -> assemble-document -> harmonize -> review-page -> submission-check
298
+ ```
299
+
300
+ ### Worked transcript: produce a DVR for the TDA algorithm
301
+
302
+ ```bash
303
+ # Step 1: User says "I need a Design Validation Report for the TDA algorithm."
304
+
305
+ # Step 2: Verify the workspace is set up
306
+ mneme stats
307
+ mneme profile show
308
+ # Active profile: EU MDR
309
+ # Doc types: design-validation-report, risk-management, clinical-evaluation, ...
310
+ # Vocabulary rules: 15
311
+
312
+ # Step 3: Generate the plan
313
+ mneme agent plan \
314
+ --goal "produce a Design Validation Report for the TDA algorithm" \
315
+ --doc-type design-validation-report \
316
+ --client tda
317
+ # Plan: design-validation-report-tda-2026-04-09
318
+ # Tasks: 15
319
+ # section-purpose-and-scope
320
+ # section-context
321
+ # section-referenced-documents
322
+ # section-execution-metadata
323
+ # section-dataset-descriptions
324
+ # section-methodology-explanations
325
+ # section-test-equipment
326
+ # section-sample-size-justification
327
+ # section-acceptance-criteria
328
+ # section-test-results
329
+ # section-conclusion
330
+ # assemble-document
331
+ # harmonize
332
+ # review-page
333
+ # submission-check
334
+
335
+ # Step 4: Walk the plan
336
+ mneme agent next-task
337
+ # Task: section-purpose-and-scope
338
+ # next_command: mneme draft --doc-type design-validation-report \
339
+ # --section purpose-and-scope --client tda
340
+
341
+ # Agent runs the next_command to pull the write packet
342
+ mneme draft --doc-type design-validation-report \
343
+ --section purpose-and-scope --client tda \
344
+ --source sources/tda/design-input.md \
345
+ --out /tmp/packet.md
346
+
347
+ # Agent reads /tmp/packet.md, writes the section to
348
+ # wiki/tda/design-validation-report.md as a `## purpose-and-scope` block
349
+ # (or a separate section file, per the agent's own staging convention)
350
+
351
+ mneme agent task-done section-purpose-and-scope
352
+
353
+ # Repeat for each of the 10 remaining sections
354
+ mneme agent next-task
355
+ mneme draft --doc-type design-validation-report --section context --client tda \
356
+ --query "technical literature kinematic accelerometer"
357
+ mneme agent task-done section-context
358
+
359
+ # ... and so on for referenced-documents, execution-metadata,
360
+ # dataset-descriptions, methodology-explanations, test-equipment,
361
+ # sample-size-justification, acceptance-criteria, test-results, conclusion.
362
+
363
+ # After all 11 section tasks are done, assemble-document is ready
364
+ mneme agent next-task
365
+ # Task: assemble-document
366
+ # Combine section drafts into wiki/tda/design-validation-report.md with
367
+ # frontmatter (title, type: design-validation-report, client: tda,
368
+ # created, updated, sources, confidence: medium)
369
+
370
+ # Agent assembles the page, then
371
+ mneme agent task-done assemble-document
372
+
373
+ # Harmonize the vocabulary
374
+ mneme agent next-task
375
+ mneme harmonize --client tda --fix
376
+ mneme agent task-done harmonize
377
+
378
+ # Review the prose against the writing style
379
+ mneme agent next-task
380
+ mneme validate writing-style tda/design-validation-report > /tmp/review.md
381
+ # Agent reads /tmp/review.md, critiques every section against principles,
382
+ # general rules, terminology, and framing examples. Applies concrete fixes
383
+ # in place.
384
+ mneme agent task-done review-page
385
+
386
+ # Submission check
387
+ mneme agent next-task
388
+ mneme profile show
389
+ # Agent walks the submission_checklist item by item, reporting pass/fail
390
+ # with a one-line justification per item. Stops. Does NOT mark the
391
+ # document "validated" — that is the user's call.
392
+ mneme agent task-done submission-check
393
+
394
+ # Done
395
+ mneme agent next-task
396
+ # {done: true}
397
+ ```
398
+
399
+ That's the whole loop. Every task has a `next_command`, an `after_done`
400
+ command, and an `instructions` field. When in doubt, read the envelope
401
+ mneme gives you and do exactly what it says.
402
+
403
+ ---
404
+
405
+ ## 6. Standard task templates
406
+
407
+ When the user states one of these goals, follow the matching template.
408
+ Each template assumes an active profile is set and the workspace is
409
+ already scaffolded. Stop conditions are the trigger for "task complete".
410
+
411
+ ### 6.1 Produce a Design Validation Report from a code repo
412
+
413
+ ```
414
+ 1. mneme profile show # confirm EU MDR or equivalent
415
+ 2. mneme scan-repo <repo-path> <client> # find SOUP gaps, module gaps
416
+ 3. Ingest any reports the scan surfaces:
417
+ mneme ingest <file> <client>
418
+ 4. mneme agent plan --goal "produce a DVR" \
419
+ --doc-type design-validation-report --client <client>
420
+ 5. Loop: mneme agent next-task -> mneme draft -> write -> task-done
421
+ 6. After all sections done, assemble-document, then
422
+ mneme harmonize --client <client> --fix
423
+ 7. mneme validate writing-style <client>/design-validation-report
424
+ Apply fixes in place.
425
+ 8. Walk the submission checklist. Report pass/fail per item.
426
+ ```
427
+
428
+ Stop conditions: `mneme agent next-task` returns `{done: true}` AND
429
+ the submission checklist report is in hand.
430
+
431
+ ### 6.2 Produce a Clinical Evaluation Report (Part A) from existing literature
432
+
433
+ ```
434
+ 1. mneme profile show # expect EU MDR
435
+ 2. mneme search "clinical evaluation" --client <client>
436
+ 3. If coverage is thin:
437
+ mneme ingest <literature-pdf> <client> # for each source
438
+ 4. mneme agent plan --goal "produce CER Part A" \
439
+ --doc-type clinical-evaluation --client <client>
440
+ 5. Walk the plan. For each section, the write packet will include
441
+ any literature hits already in the wiki.
442
+ 6. assemble-document -> harmonize -> review-page -> submission-check
443
+ 7. mneme validate consistency --client <client> # catch version drift on
444
+ cited standards
445
+ ```
446
+
447
+ Stop conditions: plan is done AND `validate consistency` reports zero
448
+ conflicting standard versions.
449
+
450
+ ### 6.3 Build a Risk Management File from a hazard list and a code repo
451
+
452
+ ```
453
+ 1. mneme ingest-csv risk-register.csv <client> --mapping risk-register
454
+ 2. mneme scan-repo <repo-path> <client>
455
+ 3. mneme trace gaps <client> # find hazards without RMAs
456
+ 4. For each gap, mneme ingest or mneme trace add to close the link
457
+ 5. mneme agent plan --goal "produce risk management file" \
458
+ --doc-type risk-management --client <client>
459
+ 6. Walk the plan (same section/assemble/harmonize/review/submission shape)
460
+ 7. mneme trace matrix <client> # verify full coverage
461
+ ```
462
+
463
+ Stop conditions: plan is done AND `mneme trace gaps <client>` reports
464
+ zero unmitigated hazards.
465
+
466
+ ### 6.4 Update wiki pages after a teammate sent updated source files
467
+
468
+ ```
469
+ 1. Drop the new files into incoming/ (or any path outside sources/)
470
+ 2. For each file:
471
+ mneme resync <file> <client> --dry-run # preview
472
+ mneme resync <file> <client> # apply
473
+ 3. If conflicts are reported:
474
+ a. Open the affected wiki page
475
+ b. Edit merge markers by hand, preserving the correct content
476
+ c. mneme resync-resolve <client>/<page>
477
+ 4. mneme recent -n 10 # verify RESYNC entries
478
+ 5. mneme lint # catch any broken links
479
+ ```
480
+
481
+ Stop conditions: every new file is resynced, no merge markers remain,
482
+ and `mneme recent` shows a RESYNC (clean or RESYNC-RESOLVED) entry per
483
+ file.
484
+
485
+ ### 6.5 Migrate a project from another QMS into a fresh mneme workspace
486
+
487
+ ```
488
+ 1. mneme new <path> --name <project> --client <client> --profile <profile>
489
+ 2. cd <path>
490
+ 3. cp -r <old-qms>/* inbox/
491
+ 4. mneme tornado --client <client> --dry-run # preview
492
+ 5. mneme tornado --client <client> # apply
493
+ 6. mneme trace gaps <client> # find holes in the v-model
494
+ 7. mneme harmonize --client <client> --fix # normalise vocabulary
495
+ 8. mneme lint # orphans, dead links
496
+ 9. mneme stats # sanity check totals
497
+ ```
498
+
499
+ Stop conditions: inbox is empty, `mneme stats` shows a plausible page
500
+ count, and `mneme lint` reports no critical issues.
501
+
502
+ ### 6.6 Pre-submission readiness check before sending to a notified body
503
+
504
+ ```
505
+ 1. mneme profile show # confirm active profile
506
+ 2. mneme harmonize --client <client> # list (do not fix yet)
507
+ 3. mneme harmonize --client <client> --fix # apply, review diff
508
+ 4. mneme validate consistency --client <client> # standard versions
509
+ 5. mneme trace gaps <client> # open trace chains
510
+ 6. For each deliverable page (DVR, CER, RMF, etc.):
511
+ mneme validate writing-style <client>/<page>
512
+ Apply fixes in place.
513
+ 7. Walk the profile's submission_checklist per deliverable.
514
+ 8. mneme snapshot <client> # freeze an audit copy
515
+ ```
516
+
517
+ Stop conditions: zero gaps, zero consistency warnings, zero outstanding
518
+ writing-style issues, and a snapshot zip is on disk.
519
+
520
+ ---
521
+
522
+ ## 7. Sub-agent patterns (when to spawn parallel sub-agents)
523
+
524
+ A top-level agent driving mneme can spawn sub-agents to parallelise the
525
+ slow parts of a plan. Four patterns are expected.
526
+
527
+ ### 7.1 section-writer
528
+
529
+ **When to spawn:** during the `draft-section` phase of a plan. Section
530
+ tasks are independent (they all depend only on the empty state), so N
531
+ section-writer sub-agents can run in parallel.
532
+
533
+ **Input contract:**
534
+ - The task envelope from `mneme agent next-task`
535
+ - The write packet from `mneme draft --json` (or markdown)
536
+
537
+ **Output contract:** a single markdown block starting with
538
+ `## <section-slug>`, written to a staging area chosen by the parent. No
539
+ frontmatter. Citations in-line. `[TO ADD REF]` for gaps.
540
+
541
+ **Parallelism:** up to one per section in the plan. The parent collects
542
+ the drafts and runs `assemble-document` sequentially.
543
+
544
+ ### 7.2 reviewer
545
+
546
+ **When to spawn:** during `review-page`, or ad-hoc against any existing
547
+ page.
548
+
549
+ **Input contract:** the review packet from
550
+ `mneme validate writing-style <page> --json`.
551
+
552
+ **Output contract:** an issue list (quote, violation, rewrite) plus a
553
+ submission-checklist walk (pass/fail per item, one-line justification).
554
+ If authorised, apply fixes in place.
555
+
556
+ **Parallelism:** one per page. Multiple pages can be reviewed in
557
+ parallel.
558
+
559
+ ### 7.3 vocabulary-fixer
560
+
561
+ **When to spawn:** when `mneme harmonize` reports issues that the
562
+ mechanical swap cannot safely auto-fix (e.g. a term is used in two
563
+ different senses on the same page, only one of which should be rewritten).
564
+
565
+ **Input contract:** the harmonize report + the page path.
566
+
567
+ **Output contract:** a patched page that preserves meaning. Run
568
+ `mneme harmonize --client <c>` again after to confirm the count drops.
569
+
570
+ **Parallelism:** one per page.
571
+
572
+ ### 7.4 evidence-finder
573
+
574
+ **When to spawn:** when a section-writer's write packet has no evidence,
575
+ or the evidence is thin. The parent dispatches evidence-finder to locate
576
+ material in `sources/` (or external docs not yet ingested) and either
577
+ ingest it or cite what exists.
578
+
579
+ **Input contract:** the section_notes for the missing section + the
580
+ client slug.
581
+
582
+ **Output contract:** either (a) a list of new `mneme ingest` commands
583
+ the parent should run, or (b) a list of existing wiki paths the parent
584
+ should pass to `mneme draft --query`.
585
+
586
+ **Parallelism:** one per thin section.
587
+
588
+ ---
589
+
590
+ ## 8. The contracts you must read on every operation
591
+
592
+ Before you write anything, read:
593
+
594
+ 1. `mneme profile show` — confirm the style contract
595
+ 2. `mneme stats` — confirm the workspace is healthy
596
+ 3. `mneme status` — confirm nothing is pending that would invalidate
597
+ your work
598
+ 4. The active profile's `.md` file — the normative source of
599
+ principles, general rules, terminology, framing, and section notes
600
+
601
+ Before you mark a task done, read:
602
+
603
+ 1. The task envelope's `deliverable` field — did you actually produce
604
+ that artefact?
605
+ 2. The task envelope's `preconditions` — were they all satisfied?
606
+ 3. `mneme recent -n 5` — does the log reflect what you expected?
607
+
608
+ ---
609
+
610
+ ## 9. The contracts you must NEVER violate
611
+
612
+ These are absolute. Breaking any of them corrupts the workspace or
613
+ misleads the user.
614
+
615
+ 1. **Never modify `sources/`.** It is immutable evidence. If you need
616
+ to update a source, you replace it through `resync`, never by hand.
617
+ 2. **Never overwrite a wiki page that has a baseline without `resync`.**
618
+ A baseline means a teammate or a prior run owns state on that page;
619
+ blind overwrite destroys history.
620
+ 3. **Never claim "validated" beyond the profile's definition.** In
621
+ EU MDR, "design validated" means acceptance criteria passed against
622
+ pre-defined reference standards. "Clinically validated" requires a
623
+ separate clinical validation. Do not conflate them.
624
+ 4. **Never invent citations.** Every claim cites a real source path or
625
+ wiki page, or it is marked `[TO ADD REF]`. No fabricated DOIs, no
626
+ hallucinated standard numbers.
627
+ 5. **Never silently widen scope.** If the user asked for a DVR for the
628
+ TDA algorithm, do not draft a CER on the side. If the plan says 15
629
+ tasks, do not add a 16th without asking.
630
+ 6. **Never skip `harmonize` or `validate writing-style` before marking
631
+ a deliverable complete.** They are cheap and catch real issues.
632
+ 7. **Never mark `submission-check` done without walking the checklist
633
+ item by item.** Pass/fail per item is the whole point.
634
+ 8. **Never run `--fix` variants destructively without reviewing the
635
+ diff.** `mneme harmonize --fix` writes to disk; run it, then read
636
+ `mneme diff <page>` before committing.
637
+ 9. **Never call an LLM from inside mneme.** Mneme is deterministic
638
+ infrastructure. All reasoning happens in you, the agent.
639
+
640
+ ---
641
+
642
+ ## 10. Reference cards
643
+
644
+ ### 10.1 Document type to profile section table (bundled `eu-mdr`)
645
+
646
+ | Doc type | Purpose | Sections |
647
+ |---|---|---|
648
+ | `risk-management` | ISO 14971 risk management file | inherited from profile |
649
+ | `clinical-evaluation` | MEDDEV 2.7/1 rev 4 CER | inherited from profile |
650
+ | `design-history-file` | Design and development docs per Annex II | inherited from profile |
651
+ | `software-documentation` | IEC 62304 software lifecycle | inherited from profile |
652
+ | `post-market-surveillance` | PMS per Articles 83-86 | inherited from profile |
653
+ | `technical-documentation` | Technical documentation per Annex II and III | inherited from profile |
654
+ | `design-validation-report` | DVR under EU MDR CE marking | 11 sections, see below |
655
+
656
+ Sections for `design-validation-report` under `eu-mdr`:
657
+
658
+ 1. `purpose-and-scope`
659
+ 2. `context`
660
+ 3. `referenced-documents`
661
+ 4. `execution-metadata`
662
+ 5. `dataset-descriptions`
663
+ 6. `methodology-explanations`
664
+ 7. `test-equipment`
665
+ 8. `sample-size-justification`
666
+ 9. `acceptance-criteria`
667
+ 10. `test-results`
668
+ 11. `conclusion`
669
+
670
+ Plan total = 11 section tasks + `assemble-document` + `harmonize` +
671
+ `review-page` + `submission-check` = **15 tasks**.
672
+
673
+ ### 10.2 Common errors and what to do
674
+
675
+ | Error from mneme | What it means | What to do |
676
+ |---|---|---|
677
+ | `No active profile` | Profile is unset | `mneme profile set <name>` (e.g. `eu-mdr`) |
678
+ | `Unknown doc-type "X" for profile "Y"` | Typo or the profile has no `Document Type: X` block | `mneme profile show` then fix the `--doc-type` |
679
+ | `Unknown section "X" for doc-type "Y"` | Section slug typo | Read the profile `.md`, pick a real `## Section: <slug>` |
680
+ | `Page not found` from `validate writing-style` | Slug is wrong or page was never written | `ls wiki/<client>/` and try again |
681
+ | `No plans found in this workspace` | No agent plan has been generated | `mneme agent plan ...` first |
682
+ | `CONFLICT (N regions)` from `resync` | 3-way merge couldn't auto-resolve | Edit merge markers by hand, then `mneme resync-resolve <page>` |
683
+ | `Profile not found` after `profile set` | File not at `<workspace>/profiles/<name>.md` or bundled | Verify filename matches exactly |
684
+ | `Source not found: <path>` from `draft --source` | Path typo | Quote the path, check `ls` |
685
+
686
+ ### 10.3 Where to look for things in a workspace
687
+
688
+ | You need to... | Look at... |
689
+ |---|---|
690
+ | See every wiki page mneme knows about | `index.md` |
691
+ | See the activity timeline | `log.md` |
692
+ | See active profile contents | `mneme profile show`, then read `profiles/<name>.md` or the bundled file |
693
+ | See which plans exist | `mneme agent list` |
694
+ | See plan internals | `.mneme/agent-plans/<id>.json` and `<id>.state.json` |
695
+ | See the entity graph | `schema/graph.json` |
696
+ | See the tag taxonomy | `schema/tags.json` |
697
+ | See the trace links | `schema/traceability.json` |
698
+ | See what changed on a page | `mneme diff <client>/<page>` |
699
+ | See cross-doc version conflicts | `mneme validate consistency --client <client>` |
700
+ | See trace holes | `mneme trace gaps <client>` |
701
+ | Export a client for an external QMS app | `mneme export <client> --format json` |
702
+ | Freeze an audit snapshot | `mneme snapshot <client>` |
703
+
704
+ ---
705
+
706
+ *This document is the contract. When in doubt, re-read sections 5 and 9.*