@daogee/mdgraph 1.1.0 → 1.2.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 (64) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/README-ZH.md +12 -2
  3. package/README.md +12 -2
  4. package/agent-pack/README.md +2 -0
  5. package/agent-pack/mdgraph-agent-instructions.md +3 -1
  6. package/agent-pack/prompts/wiki-authoring.md +12 -0
  7. package/agent-pack/skills/wiki-authoring/SKILL.md +38 -0
  8. package/agent-pack/skills/wiki-authoring/agents/openai.yaml +4 -0
  9. package/dist/analysis/status-freshness.d.ts +8 -1
  10. package/dist/analysis/status-freshness.js +19 -6
  11. package/dist/bin/mdgraph.js +124 -6
  12. package/dist/db/connection.js +17 -1
  13. package/dist/db/repositories.d.ts +28 -4
  14. package/dist/db/repositories.js +148 -5
  15. package/dist/db/sqlite-adapter.js +8 -2
  16. package/dist/evaluation/retrieval-eval.d.ts +11 -0
  17. package/dist/evaluation/retrieval-eval.js +35 -1
  18. package/dist/index.d.ts +7 -0
  19. package/dist/index.js +3 -0
  20. package/dist/indexer.js +64 -6
  21. package/dist/mcp/server.js +5 -4
  22. package/dist/mcp/tools.js +23 -9
  23. package/dist/query/context-builder.d.ts +1 -0
  24. package/dist/query/context-builder.js +30 -1
  25. package/dist/query/knowledge-card.d.ts +90 -0
  26. package/dist/query/knowledge-card.js +676 -0
  27. package/dist/query/search.js +8 -3
  28. package/dist/semantic/ollama-provider.js +6 -1
  29. package/dist/utils/path-safety.d.ts +3 -0
  30. package/dist/utils/path-safety.js +27 -0
  31. package/dist/watcher/file-watcher.js +85 -16
  32. package/dist/wiki/wiki-dependencies.d.ts +20 -0
  33. package/dist/wiki/wiki-dependencies.js +45 -0
  34. package/dist/wiki/wiki-domains.d.ts +13 -0
  35. package/dist/wiki/wiki-domains.js +55 -0
  36. package/dist/wiki/wiki-evidence.d.ts +27 -0
  37. package/dist/wiki/wiki-evidence.js +112 -0
  38. package/dist/wiki/wiki-plan.d.ts +121 -0
  39. package/dist/wiki/wiki-plan.js +616 -0
  40. package/dist/wiki/wiki-status.d.ts +67 -0
  41. package/dist/wiki/wiki-status.js +451 -0
  42. package/docs/EN/Agent_Integration.md +14 -4
  43. package/docs/EN/Architecture.md +13 -0
  44. package/docs/EN/Evaluation_Questions.md +14 -0
  45. package/docs/EN/Knowledge_Cards_and_Wiki_Workflow.md +97 -0
  46. package/docs/EN/Operations.md +20 -0
  47. package/docs/EN/Output_Contracts.md +42 -3
  48. package/docs/EN/Public_Contracts.md +3 -1
  49. package/docs/EN/Public_Contracts_1.0.md +4 -0
  50. package/docs/EN/README.md +1 -0
  51. package/docs/EN/Release_Checklist.md +1 -0
  52. package/docs/EN/Retrieval_and_Context.md +6 -0
  53. package/docs/ZH/Agent_Integration.md +14 -4
  54. package/docs/ZH/Architecture.md +13 -2
  55. package/docs/ZH/Evaluation_Questions.md +14 -0
  56. package/docs/ZH/Knowledge_Cards_and_Wiki_Workflow.md +99 -0
  57. package/docs/ZH/Operations.md +20 -0
  58. package/docs/ZH/Output_Contracts.md +42 -3
  59. package/docs/ZH/Public_Contracts.md +3 -1
  60. package/docs/ZH/Public_Contracts_1.0.md +4 -0
  61. package/docs/ZH/README.md +1 -0
  62. package/docs/ZH/Release_Checklist.md +1 -0
  63. package/docs/ZH/Retrieval_and_Context.md +6 -0
  64. package/package.json +7 -2
@@ -0,0 +1,97 @@
1
+ ---
2
+ status: implemented
3
+ defines:
4
+ - KnowledgeCard
5
+ - WikiPlan
6
+ - WikiPageBrief
7
+ - WikiStatus
8
+ - WikiVerification
9
+ source_refs:
10
+ - src/query/knowledge-card.ts
11
+ - src/query/context-builder.ts
12
+ - src/query/search.ts
13
+ - src/query/trace.ts
14
+ - src/db/repositories.ts
15
+ - src/mcp/tools.ts
16
+ - src/bin/mdgraph.ts
17
+ - src/wiki/wiki-plan.ts
18
+ - src/wiki/wiki-status.ts
19
+ - src/wiki/wiki-evidence.ts
20
+ - src/wiki/wiki-dependencies.ts
21
+ - src/wiki/wiki-domains.ts
22
+ ---
23
+
24
+ # Knowledge Cards and Wiki Workflow
25
+
26
+ Knowledge Cards help locate and interpret graph evidence. Wiki commands prepare and maintain a project manual whose prose is written by the host agent or user. Neither capability requires a model, embeddings, a source-code graph, or another database.
27
+
28
+ ## Knowledge Cards
29
+
30
+ `node` and MCP `mdgraph_node` expose an experimental `card`. `context` adds a complete `cardSummary` only when packed Markdown leaves enough space. Search ranking, trace paths, and the five-tool MCP surface are unchanged.
31
+
32
+ A card retains `nodeId`, `kind`, `label`, `summary`, `definitions`, `sourceRefs`, `relatedDocuments`, `evidence`, and optional `truncated`. Additive `nextReads` entries supply graph-backed paths and reading reasons.
33
+
34
+ References carry `association` (`direct`, `inherited`, or `related`), `originNodeId`, and optional `viaNodeId`. A section's own evidence is direct; document-level declarations are inherited background. A document may aggregate its sections while retaining the originating node. An entity's source files reached through a defining document are related evidence, not a claim that the entity directly implements all of those files.
35
+
36
+ The deterministic summary emphasizes location and useful relationships. Next reads come from existing graph facts. The default complete serialized JSON budget is 4,000 characters, including ownership metadata, next reads, and omission counts. Direct evidence has priority over inherited/related background. Display text can end in an ellipsis; the stable node identity is retained. An impossible budget produces an explicit error. Cards are generated at query time and are not persisted or exposed through a separate command.
37
+
38
+ ## Create a Wiki plan
39
+
40
+ ```bash
41
+ mdgraph wiki plan --wiki-dir wiki --out .mdgraph/wiki-plan.json --path <project>
42
+ mdgraph wiki brief <page-id> --plan .mdgraph/wiki-plan.json --json --path <project>
43
+ ```
44
+
45
+ Plan v2 records the project-relative Wiki output directory and excludes it from source selection. Project-neutral candidate domains cover overview, architecture, usage, development, operations, and reference; indexed document evidence supplies project vocabulary. Sparse documentation produces limited suggestions and explicit gaps rather than invented project behavior.
46
+
47
+ Pages retain stable IDs, output paths, purpose, audience, outline, selected document IDs, selected source paths, evidence queries, and a dependency-local evidence hash. Dependency snapshots let maintenance reports identify changed files. Global graph hashes remain diagnostic data; changes to indexing metadata alone do not imply that every page needs rewriting.
48
+
49
+ ## Update an authored plan
50
+
51
+ ```bash
52
+ mdgraph wiki plan --from .mdgraph/wiki-plan.json --out .mdgraph/wiki-plan.next.json --path <project>
53
+ ```
54
+
55
+ Review the next plan before replacing the previous one. Existing page IDs, paths, hierarchy, titles, purposes, audiences, outlines, selected documents, source refs, and evidence queries are preserved. New pages and sources are suggestions rather than automatic edits. Missing selected dependencies remain visible instead of silently disappearing. Adopt suggestions by editing the selected page fields and refreshing the plan before writing from its brief.
56
+
57
+ Version 1 plans remain readable. When migrating with `--from`, supply `--wiki-dir wiki` explicitly; write the resulting version 2 plan to a new file. Future unknown formats are diagnosed without overwriting the input. Plan, brief, status, and verification never author or overwrite page prose.
58
+
59
+ ## Author one page
60
+
61
+ A brief identifies primary selected documents, supplementary retrieved material, source files to inspect, and unresolved evidence gaps. Knowledge Cards distinguish direct facts from background. The `maxChars`/`usedChars` budget covers packed context text and serialized cards; page instructions and the source manifest are separate recovery information, not a total JSON-size cap.
62
+
63
+ The shared evidence evaluation supplies freshness and recovery information to JSON, text, and writing requirements. A stale or unknown brief remains readable, but it does not instruct the author to finalize an old evidence hash. Refresh sources/index/plan as directed, inspect the cited files, then write or update the page.
64
+
65
+ Maintain these fields:
66
+
67
+ ```yaml
68
+ ---
69
+ wiki_id: architecture
70
+ evidence_hash: "<hash from the current brief>"
71
+ source_docs:
72
+ - docs/architecture.md
73
+ source_refs:
74
+ - src/main.ts
75
+ ---
76
+ ```
77
+
78
+ Both source fields must be arrays of non-empty project-relative paths; use `[]` for an empty list. Additional user-selected sources must be deliberately incorporated into the plan. A mismatch should be resolved by reviewing source selection, not by blindly removing the user's references.
79
+
80
+ Use [the authoring workflow](../../agent-pack/skills/wiki-authoring/SKILL.md) to preserve correct existing prose and update only affected pages.
81
+
82
+ ## Status, verification, and content acceptance
83
+
84
+ ```bash
85
+ mdgraph wiki status wiki --plan .mdgraph/wiki-plan.json --json --path <project>
86
+ mdgraph wiki verify wiki --plan .mdgraph/wiki-plan.json --json --path <project>
87
+ ```
88
+
89
+ `current` means no change was detected in the recorded dependencies and maintenance fields. `needs_update`, `missing`, and `orphaned` identify work to review. Reports include dependency changes and recovery actions. A new unrelated source can require plan review without forcing unrelated pages to be rewritten. Status and verification preserve user content.
90
+
91
+ Verification checks maintenance fields, safe existing sources, relative links, and evidence consistency. `valid: true` is not a judgment of prose accuracy. Content acceptance separately records the task performed, actual commands, observed results, the source revision, and any unverified claims.
92
+
93
+ ## Validation
94
+
95
+ Focused regression tests cover ownership, budgets, stale evidence, preserved author choices, plan compatibility, and the complete update workflow. `npm run baseline:knowledge-wiki` measures output behavior on a small orchard project; it is not an independent-agent A/B trial or evidence of improved prose quality. `npm run baseline:performance` measures synthetic 100/500-document workloads.
96
+
97
+ The maintained project Wiki in `wiki/` and its `wiki/acceptance.md` record document real workflow validation. Their acceptance is separate from unit-test success.
@@ -89,3 +89,23 @@ Derived `RELATED_TO` edges are disposable, non-authoritative state. Changes to a
89
89
  - Keep `.mdgraph/config.json` trackable when it contains no credentials; endpoint URLs with embedded credentials are rejected.
90
90
  - Use GraphJSON for the documented structural exchange format instead of depending on SQLite internals.
91
91
  - Before publishing MDGraph itself, run the [Release Checklist](Release_Checklist.md), inspect `npm pack --dry-run --json`, and verify the packed package rather than assuming repository contents equal npm contents.
92
+
93
+ ## Served roots and embedding deadlines
94
+
95
+ MCP checks the real filesystem targets of project roots, configuration, and SQLite storage. Links within the served root remain usable, including starting the server through a linked root. To access an external project, start a separate server with `--path` pointing to that project. A link inside the served root does not grant access to an external target.
96
+
97
+ `embedding.timeoutMs` covers response headers and the complete response body, including error responses. A timeout degrades search/context to lexical and graph retrieval; an indexing failure preserves the previous graph. Retry after the local service recovers.
98
+
99
+ ## Incremental consistency and watch configuration
100
+
101
+ Indexing records extraction settings and a generation in SQLite metadata. Changes to extraction settings rebuild the affected graph; query-only settings do not. Incremental updates reconcile deterministic relationships against all parsed documents so alias ambiguity changes are reflected even in untouched documents. Unchanged chunk vectors are reused for matching provider/model/dimensions and content. An explicit full rebuild clears derived relationships; automatic extraction rebuilds preserve unaffected derived relationships when their vector profile is unchanged.
102
+
103
+ Concurrent index commits detect a changed generation and rescan once; repeated contention reports an error and can be retried. Parser failures retain the previous document and its graph, report skipped files, and leave incomplete extraction rebuilds pending. Fix the reported Markdown and rerun indexing before relying on that content.
104
+
105
+ Watch reloads configuration and `.gitignore` rules, including the MDX switch. The replacement watcher becomes ready before the old one closes. Invalid configuration retains the old watch and reports degraded health; correcting the configuration triggers recovery.
106
+
107
+ ## Node.js build requirements
108
+
109
+ The runtime must provide `node:sqlite` with FTS5; a version number of 22.5.0 alone is insufficient. Node 22.23.2 and 26.5.0 pass the full local test suite. Tested stock 22.5.0 and 22.13.0 builds lack FTS5; adding the experimental SQLite flag alone does not supply it. MDGraph checks the actual capability before applying its persistent schema and reports `sqlite_fts5_unavailable` with upgrade guidance. A build that supplies FTS5 through an extension remains usable.
110
+
111
+ The early-runtime CI job exercises SQLite compatibility and missing-capability recovery; it is not a full-product support claim for stock Node 22.5.0. Windows validation is covered by CI and must be checked on the corresponding commit before a cross-platform release claim.
@@ -74,10 +74,12 @@ When semantic retrieval is requested but cannot run, `search` still returns FTS5
74
74
 
75
75
  - `query`: original query text.
76
76
  - `maxChars`: configured context budget.
77
- - `usedChars`: packed character count.
77
+ - `usedChars`: packed `content` plus optional `cardSummary` character count.
78
78
  - `packing`: additive packing metadata with `strategy`; opt-in MMR also reports `similarity`, `mmrLambda`, and optional `redundancySkippedItems`.
79
79
  - `semanticDiagnostic`: optional provider fallback details; absent when semantic retrieval was not requested or completed normally.
80
- - `items`: context items with `nodeId`, `documentId`, optional `sectionId`, optional `anchor`, `path`, `title`, optional `heading`, optional `lines`, `reason`, `matchedEntities`, optional `edgePath`, optional `sourceRefs`, optional `riskNotes`, and `content`.
80
+ - `items`: context items with `nodeId`, `documentId`, optional `sectionId`, optional `anchor`, `path`, `title`, optional `heading`, optional `lines`, `reason`, `matchedEntities`, optional `edgePath`, optional `sourceRefs`, optional `riskNotes`, optional `cardSummary`, and `content`.
81
+
82
+ `cardSummary` is an experimental deterministic Knowledge Card summary. It is added only to the highest-ranked packed items when the original document content leaves spare budget; it is omitted if the complete summary does not fit, preserving original content and recovery fields.
81
83
 
82
84
  `riskNotes` can include lifecycle/trust cautions and deterministic content-risk notes such as prompt-injection text, active HTML/data URIs, or hidden Unicode format characters.
83
85
 
@@ -119,11 +121,36 @@ The compatibility default is `mmr-style-document-round-robin`. `--packing mmr` i
119
121
 
120
122
  The command fails before mutation for stale indexes, lexical-hash providers, incomplete current-profile vector coverage, unsafe options, or exceeded computation budgets. A successful non-dry run atomically replaces `RELATED_TO/embedding_similarity` edges. This output is experimental and does not change stable index, search, GraphJSON, or MCP contracts.
121
123
 
124
+ ## Experimental `wiki` workflow
125
+
126
+ `mdgraph wiki plan --out <file> --json` writes a deterministic plan and returns `out` plus `plan`. The plan contains:
127
+
128
+ - `format: "mdgraph-wiki-plan"`, `formatVersion: 1`, `graphHash`, and `sourceHash`.
129
+ - `pages`: stable page records with `id`, `title`, safe Wiki-relative `path`, optional `parentId`, `purpose`, `audience`, `outline`, `documentIds`, project-relative `sourceRefs`, `evidenceQueries`, and page-local `evidenceHash`.
130
+
131
+ `mdgraph wiki brief <page-id> --plan <file> --json` returns:
132
+
133
+ - `format: "mdgraph-wiki-page-brief"`, `formatVersion: 1`, and the selected `page`.
134
+ - `maxChars` and `usedChars`, where the used budget covers `contextItems` content/Card summaries and serialized `knowledgeCards`.
135
+ - `sourceDocuments` with authoritative document IDs, paths, titles, lifecycle/type/trust metadata; plus `contextItems`, `knowledgeCards`, `writingRequirements`, and `suggestedNextQueries`.
136
+
137
+ `mdgraph wiki status <wiki-dir> --plan <file> --json` is read-only and returns:
138
+
139
+ - `format: "mdgraph-wiki-status"`, `formatVersion: 1`, `wikiDir`, and current/stale plan hashes.
140
+ - `pages` with `current | needs_update | missing | orphaned`; every non-current page includes `reason` and an executable or review-oriented `recovery` action.
141
+ - `summary` counts for all four states.
142
+
143
+ `mdgraph wiki verify <wiki-dir> --plan <file> --json` is read-only and returns `format: "mdgraph-wiki-verification"`, `formatVersion: 1`, `valid`, structured `errors`, `warnings`, and the same `status`. Issues include stable `code`, page/path evidence when available, and `recovery`. Invalid verification exits non-zero.
144
+
145
+ Plan and brief output is deterministic for the same graph and source state. Status and verification never overwrite Wiki prose, do not judge prose quality, and do not require embeddings or a generation provider.
146
+
122
147
  ## `node --json`
123
148
 
124
149
  `mdgraph node <query> --json` returns the resolved node record when found:
125
150
 
126
- - `id`, `label`, `kind`, `data`.
151
+ - `id`, `label`, `kind`, `data`, and optional experimental `card` for document, section, entity, and source-ref nodes.
152
+
153
+ `card` is a deterministic, non-persisted query projection with `nodeId`, `kind`, `label`, `summary`, `definitions`, `sourceRefs`, `relatedDocuments`, `evidence`, and optional omission counts in `truncated`. Arrays are stably ordered and retain node IDs, paths, edge kinds, provenance, confidence, anchors, or line ranges where applicable. Chunk nodes retain their existing shape without a card.
127
154
 
128
155
  When a section query is ambiguous, it returns:
129
156
 
@@ -306,3 +333,15 @@ Diff only compares Markdown graph records, source refs, and doctor warning codes
306
333
  Initial warning codes cover the existing doctor checks, front matter diagnostics, lifecycle governance, graph health, storage health, parse failures, and conservative convention linting: `index.stale`, `link.dead`, `source_ref.missing`, `definition.missing`, `definition.duplicate`, `content.risk`, `document.orphan`, `document.deleted`, `document.weakly_linked`, `document.deprecated_referenced`, `document.superseded_referenced`, `document.parse_failed`, `graph.missing_decision_link`, `storage.generated_path_indexed`, `storage.database_oversized`, `storage.fts_shadow_large`, `storage.high_degree_node`, `storage.vector_anomaly`, `front_matter.invalid_yaml`, `front_matter.not_mapping`, `front_matter.unclosed`, `front_matter.invalid_field`, `tag.invalid_format`, and `link.non_posix_path`.
307
334
 
308
335
  `mdgraph doctor --strict` keeps the same output shape and exits with a non-zero status when any summary issue count other than `documents` is greater than zero. `mdgraph doctor --fail-on <severity>` adds a typed warning gate without changing `--strict`, and `--changed` / `--since <ref>` return scoped reports with explicit scope metadata. Scoped reports include scoped Markdown paths plus directly related one-hop graph documents; deleted Markdown paths are preserved in scope metadata and reported with `document.deleted` after the index is fresh. Global storage summaries may still be present for observability, but storage warnings are omitted when `globalHealthIncluded` is `false`.
336
+
337
+ ## Evaluation evidence additions
338
+
339
+ Evaluation cases add `retrievalEvidencePassed`; `metrics` add `retrievedEntityRecall`, `retrievedSourceRefRecall`, `retrievedEdgeKindCoverage`, and `contextIrrelevantRatio`. `observed` adds the corresponding returned-entity, returned-source-ref, and returned-edge-kind arrays. These report this query's exposed evidence. Legacy coverage metrics and `passed` retain their existing meaning. See [Evaluation Questions](Evaluation_Questions.md).
340
+
341
+ ## Knowledge Card ownership and Wiki maintenance
342
+
343
+ Card references add optional `association` (`direct | inherited | related`), `originNodeId`, and `viaNodeId`. Optional `nextReads` contains paths, graph identity, reading reasons, and ownership. These fields count toward the full 4,000-character default Card JSON budget.
344
+
345
+ New Wiki plans use formatVersion 2 and record `wikiDir`, dependency snapshots, source/page suggestions, and evidence gaps. Version 1 plans remain readable; upgrading through `wiki plan --from` requires `--wiki-dir` and a separate `--out` file. Page suggestions are complete page records; source suggestions contain `pageId`, `documentIds`, and `sourceRefs`.
346
+
347
+ Brief, status, and verification retain formatVersion 1 with additive fields. Brief adds `supplementaryDocuments`, `sourceInspections`, `evidenceGaps`, and `dependencyEvidence`. Status pages add `changes`, `selectionChanges`, and `evidenceState`. Verify adds `scope: "maintenance-and-evidence"` and `contentReview: "not-evaluated"`; `valid` does not certify prose accuracy.
@@ -27,9 +27,10 @@ This document records the public contract boundary for the current release line,
27
27
  | `mdgraph usage` command | stable-additive | `src/bin/mdgraph.ts` | `usage` prints an agent-friendly workflow guide and `usage --json` returns the same workflows as machine-readable JSON without reading or writing the graph index. |
28
28
  | Experimental structured `query` command | experimental | `src/query/structured-query.ts`, `src/query/structured-query-executor.ts`, `src/bin/mdgraph.ts` | `query <expression>` provides a bounded typed DSL over documented document fields, tags, outgoing edges, dates, sorting/limits, and doctor health. It supports `--json` and `--path`; it does not change stable `search` or the five-tool MCP surface. |
29
29
  | Experimental `relationships derive` command | experimental | `src/relationships/derive-related.ts`, `src/bin/mdgraph.ts` | Explicitly derives low-weight symmetric `RELATED_TO` edges from complete semantic-model vectors after freshness, capability, coverage, threshold, independent-evidence, reciprocal-top-K, and resource-budget checks. It supports dry-run and never runs automatically during index/watch. |
30
+ | Experimental Wiki workflow | experimental | `src/wiki/wiki-plan.ts`, `src/wiki/wiki-status.ts`, `src/bin/mdgraph.ts` | `wiki plan/brief/status/verify` adds deterministic planning, bounded evidence briefs, impact status, and read-only verification without adding MCP tools or generating/overwriting prose. WikiPlan and WikiPageBrief formatVersion 1, page-state names, structured verification issue fields, and non-zero invalid verification are experimental. |
30
31
  | `status --freshness` diagnostics | stable-additive | `src/bin/mdgraph.ts` | `status --freshness` adds optional freshness diagnostics (`state`, `recommendation`, `lastIndexedAt`, `checkedAt`, `issues`) without changing the default `status --json` shape; `--storage` and `--freshness` may be combined. |
31
32
  | `serve --mcp` default watch and `--no-watch` escape hatch | stable-additive | `src/bin/mdgraph.ts` | `serve --mcp` keeps the Markdown graph fresh by default and exposes `--no-watch` as the read-only escape hatch; `--watch`, `--semantic`, `--debounce <ms>`, and explicit `--watch-poll` are additive flags for integrated watch-based freshness. |
32
- | Top-level CLI JSON output shapes | stable | `docs/EN/Output_Contracts.md` | Required fields documented in Output Contracts are stable; command-specific nested graph records follow `src/types.ts` unless a section, such as experimental structured `query` or `relationships derive`, is explicitly marked otherwise. |
33
+ | Top-level CLI JSON output shapes | stable | `docs/EN/Output_Contracts.md` | Required fields documented in Output Contracts are stable; command-specific nested graph records follow `src/types.ts` unless a section, such as experimental structured `query`, `relationships derive`, or `wiki`, is explicitly marked otherwise. |
33
34
  | MCP tool names and input schemas | stable | `src/mcp/tools.ts` | Exactly five tools: `mdgraph_search`, `mdgraph_context`, `mdgraph_node`, `mdgraph_trace`, and `mdgraph_status`; schemas reject undeclared properties. |
34
35
  | MCP structured freshness metadata | stable-additive | `src/mcp/tools.ts` | `mdgraph_status` always returns `freshness` metadata in `structuredContent` when indexed, and `mdgraph_search`/`mdgraph_context`/`mdgraph_node`/`mdgraph_trace` may add the same `freshness` object plus a text warning banner when the index is `stale` or `unknown`. |
35
36
  | MCP semantic fallback diagnostics | stable-additive | `src/mcp/tools.ts` | `mdgraph_search` and `mdgraph_context` use the async provider path. When semantic retrieval cannot run, they keep lexical/graph results and prepend a text warning. Search adds `structuredContent.semanticDiagnostic`; context adds `structuredContent.context.semanticDiagnostic`. Both contain `code`, `provider`, `message`, and `degraded: true`. |
@@ -38,6 +39,7 @@ This document records the public contract boundary for the current release line,
38
39
  | Structured query AST and execution | experimental | `src/query/structured-query.ts`, `src/query/structured-query-executor.ts`, `src/db/repositories.ts` | User values use bound SQL parameters. Field/operator/sort/edge enums are validated before whitelisted SQL assembly. Health predicates require a fresh doctor report and preserve the original boolean AST. No arbitrary front-matter or raw SQL escape is exposed. |
39
40
  | Derived relationship execution | experimental | `src/relationships/derive-related.ts`, `src/db/repositories.ts` | `RELATED_TO/embedding_similarity` edges are non-authoritative, low weight, atomically replaceable, and carry provider/model/algorithm/threshold/evidence/generation metadata. `local-hash` cannot emit them. GraphJSON retains its structural privacy profile and therefore omits this edge metadata. |
40
41
  | MCP text output wording | experimental | `src/mcp/tools.ts` | Text is human-facing guidance; `structuredContent` is the preferred machine contract. |
42
+ | Dynamic Knowledge Card projection | experimental / stable-additive | `src/query/knowledge-card.ts`, `src/query/context-builder.ts`, `src/bin/mdgraph.ts`, `src/mcp/tools.ts` | Found document, section, entity, and source-ref `node` results may add a deterministic non-persisted `card`; selected context items may add `cardSummary`, counted in `usedChars`, only from budget left after original content. Existing node fields, ranking, trace paths, SQLite counts, and the five-tool MCP surface remain unchanged. |
41
43
  | Context recovery fields | stable-additive | `src/query/context-builder.ts` | Context items expose `nodeId`, `documentId`, optional `sectionId`, optional `anchor`, line ranges, source refs, risk notes, and graph-expansion `edgePath` so agents can recover nodes and provenance without guessing from prose. |
42
44
  | `.mdgraph/config.json` fields | stable | `src/config/load-config.ts` | `docs`, `index`, `search`, `entities`, and `embedding` default fields are stable. The additive embedding fields are `endpoint`, `timeoutMs`, and `batchSize`; existing config files receive defaults. Unknown fields are currently ignored by merge logic. |
43
45
  | `.mdgraph` file governance | stable | `src/config/load-config.ts`, `src/bin/mdgraph.ts` | `mdgraph init` keeps `.mdgraph/config.json` trackable, protects local `.mdgraph` artifacts through the root `.gitignore` when no equivalent ignore rule exists, and builds the initial graph index by default. `.mdgraph/graph.db` and generated `.mdgraph` artifacts are local workflow state, not source files. Use `--no-index` for config-only initialization. |
@@ -74,6 +74,10 @@ the frozen 1.0 CLI inventory above. Its bounded DSL and JSON output are document
74
74
  `relationships derive` is experimental and is also outside the
75
75
  frozen inventory. Its provider/evidence gates and JSON output are documented in
76
76
  [Structured Query and Relationships](Structured_Query_and_Relationships.md#derived-related-document-relationships) and Output Contracts.
77
+
78
+ `wiki plan/brief/status/verify` is an experimental post-freeze CLI group. It adds no
79
+ MCP tools, does not generate prose, and is documented in
80
+ [Knowledge Cards and Wiki Workflow](Knowledge_Cards_and_Wiki_Workflow.md) and Output Contracts.
77
81
  The stable `search` command and five-tool MCP surface are unchanged.
78
82
 
79
83
  Project-related commands accept an additive `--path <project>` flag so
package/docs/EN/README.md CHANGED
@@ -10,6 +10,7 @@ MDGraph documentation is organized by user task. Start with the repository [READ
10
10
  - [Retrieval and Context](Retrieval_and_Context.md) — understand search channels, optional semantic providers, entity extraction, CJK handling, and context packing.
11
11
  - [Structured Query and Relationships](Structured_Query_and_Relationships.md) — run governance queries and explicitly derive non-authoritative related-document edges.
12
12
  - [Operations](Operations.md) — keep indexes fresh, interpret watcher health, use polling safely, and recover from provider or file-watcher failures.
13
+ - [Knowledge Cards and Wiki Workflow](Knowledge_Cards_and_Wiki_Workflow.md) — plan and maintain an evidence-backed user Wiki without in-process prose generation.
13
14
 
14
15
  ## Integrate and Maintain MDGraph
15
16
 
@@ -15,6 +15,7 @@ Use this checklist before publishing an MDGraph release or asking a maintainer t
15
15
  - Confirm focused contract tests cover MCP tool definitions, representative JSON fields, edge kinds, doctor warning shape, config defaults, and schema compatibility guidance.
16
16
  - Confirm structured error outputs include a stable `code` and remediation where the command already returns structured errors.
17
17
  - Confirm experimental commands remain explicitly labeled in the guides, public ledger, output contracts, and release notes.
18
+ - Confirm `wiki status` and `wiki verify` remain read-only, every non-current page/issue has recovery guidance, and the five-tool MCP surface is unchanged.
18
19
 
19
20
  ## Evidence gate
20
21
 
@@ -110,3 +110,9 @@ Every result includes `packing` metadata. `--debug` additionally reports candida
110
110
  - MMR reduces measured redundancy on the repository fixture, but its best lambda and similarity threshold remain corpus-dependent.
111
111
 
112
112
  See [Evaluation](Evaluation_Questions.md) for public `eval` commands, regression suites, and the limits of the recorded evidence. See [Operations](Operations.md) for index freshness and provider failure recovery.
113
+
114
+ ## Exact entity queries and Knowledge Cards
115
+
116
+ Search first checks the normalized complete query against indexed entities, including Chinese names and lowercase configuration keys. Definitions declared only in front matter still return their matched entity even when the section text does not repeat it.
117
+
118
+ `node` responses include a deterministic Knowledge Card with stable node identity, definitions, source references, relationships, and evidence. The card's `maxChars` budget measures serialized JSON characters (default 4,000). Optional lists and display text are shortened with omission counts or `…`; node identity is preserved. A budget too small for the required structure and truncation diagnostics produces an explicit error. Context adds complete card summaries only when its remaining text budget can accommodate them; Markdown content already packed is preserved.
@@ -90,13 +90,23 @@ Task-start documentation brief:
90
90
  2. 对解析出的节点调用 `mdgraph_trace`
91
91
  3. 如果 trace 路径还需要上下文,再调用 `mdgraph_context`
92
92
 
93
- 文档健康检查:
93
+ 文档健康检查:
94
94
 
95
95
  1. `mdgraph_status`
96
96
  2. 当用户要求 docs health 或 CI gate 时,使用 CLI `mdgraph doctor --json`
97
- 3. 只有在 doctor 输出点名 affected documents 后才编辑原文件
98
-
99
- ## 当前限制
97
+ 3. 只有在 doctor 输出点名 affected documents 后才编辑原文件
98
+
99
+ 项目 Wiki authoring:
100
+
101
+ 1. 针对当前图运行一次 CLI `mdgraph wiki plan --out <plan-file>`。
102
+ 2. 运行 `mdgraph wiki status <wiki-dir> --plan <plan-file> --json`,只选择 missing 或 needs-update 页面。
103
+ 3. 每次获取一个 `mdgraph wiki brief <page-id> --plan <plan-file> --json`,阅读其 document/source-ref evidence 后再编写。
104
+ 4. 保留用户正文与维护 front matter,然后运行 `mdgraph wiki verify`。
105
+ 5. 人工评审 orphaned 页面;工作流永不自动删除它们。
106
+
107
+ 支持 reusable skill 的宿主可使用 [`agent-pack/skills/wiki-authoring`](../../agent-pack/skills/wiki-authoring/SKILL.md),其他宿主可使用对应 prompt template。
108
+
109
+ ## 当前限制
100
110
 
101
111
  - MDGraph 索引 Markdown 文档,不索引源码 AST 或任意文件。
102
112
  - MCP surface 故意保持五个工具:search、context、node、trace、status。
@@ -14,6 +14,7 @@ MDGraph 采用以下已实现的流水线:扫描器 → 解析器 → 提取/
14
14
  | 解析 | `src/resolution/link-resolver.ts` | 将 Markdown 和 WikiLink 目标解析为已索引的文档或章节。 |
15
15
  | 存储 | `src/db/*` | SQLite 连接、模式、记录替换、增量更新、图查询和存储诊断。 |
16
16
  | 查询 | `src/query/*` | 搜索排序、上下文打包、图追踪,以及实验性结构化查询 tokenizer/AST/executor。 |
17
+ | Wiki | `src/wiki/*` | 实验性的确定性 Wiki 规划、证据 brief、影响状态和只读验证;正文继续由宿主 Agent/用户维护。 |
17
18
  | 评估 | `src/evaluation/*` | 检索评估 case、期望记录,以及 search/context/trace 质量的轻量指标。 |
18
19
  | Benchmark | `src/benchmark/*` | 结构化 with/without-MDGraph agent run record 解析和 paired delta 聚合。 |
19
20
  | Bundle | `src/bundle/*` | 基于 schema/source/config/document hashes 的私有目录图 bundle 创建和校验。 |
@@ -125,8 +126,14 @@ Diff report 包含 Markdown 文档新增、修改、删除、Git 识别的 renam
125
126
  `generateBenchmarkReport` 只消费结构化 `AgentRunRecord` JSON。它按 `questionId` 配对一个 `with_mdgraph` 和一个 `without_mdgraph` record,将不完整或重复 pair 报告为 skipped,并计算 file reads、searches、tool calls、MDGraph calls、字符/token 预算、延迟、raw-file fallback 和引用正确率 delta。它不解析 transcript、不调用模型,也不托管 agent run。
126
127
 
127
128
  `traceNodes` 在执行节点之间的有界图遍历,并返回每一步的边类型、来源和置信度。
128
-
129
- ## MCP 边界
129
+
130
+ ## Wiki 工作流
131
+
132
+ 实验性 Wiki 路径与 indexing 和自然语言 query ranking 分离。`buildWikiPlan` 只根据已索引文档 metadata 与显式图关系选择有证据的页面域,记录 graph/source hash,并为每页生成依赖局部 `evidenceHash`;该 hash 也会指纹化安全的项目 source ref。`buildWikiPageBrief` 复用 context packing、known files、Knowledge Card 和共享字符预算。
133
+
134
+ `buildWikiStatus` 将用户维护页面的 front matter 与 plan 及当前依赖证据比较,只报告 `current`、`needs_update`、`missing` 或 `orphaned`,不修改文件。`verifyWiki` 增加有界检查,覆盖 plan 形状、已索引 source document、安全且存在的 source ref、evidence freshness 和可解析的相对 Markdown link。它不评判正文质量、不删除 orphaned 页面、不调用模型,也不增加 MCP 工具。
135
+
136
+ ## MCP 边界
130
137
 
131
138
  MCP 服务器有意仅暴露五个工具。Search/context 通过 provider-aware 异步 handler 调度,node/trace/status 保留同步行为。工具输出以文本为主且兼容 JSON,以便代理可以直接使用,无需先检查 SQLite 数据库或读取原始文件。semantic 降级会增加文本提示和结构化诊断,但不会把仍然可用的 lexical/graph 结果变成 MCP error。服务器会绑定到项目根:initialize root 和工具 `projectPath` 必须位于服务根之内。
132
139
 
@@ -142,3 +149,7 @@ MCP 服务器有意仅暴露五个工具。Search/context 通过 provider-aware
142
149
  - 互操作 adapter 是只读导向的。GraphJSON verify、Mermaid/Markdown/docs-site export 和 source bridge report 不会把外部 graph 合并进主 SQLite index。
143
150
  - `RELATED_TO` 是实验性派生 edge,只能由显式、provider-gated 的流程发射,普通确定性 indexing 永远不会发射它。`SAME_AS` 和 `CONTRADICTS` 继续保留;类似矛盾的信号仍由 `doctor` 报告,而不是作为 graph edge 插入。
144
151
  - 当前实现优先考虑紧凑、确定性的核心,而非广泛的 Markdown/MDX 方言支持。
152
+
153
+ ## Knowledge 与 Wiki 的证据归属
154
+
155
+ Card 将直接边、文档或章节的继承背景、关联源码依据分开表达,引用和阅读建议保留稳定来源信息。`src/wiki/wiki-evidence.ts` 负责 Wiki 证据哈希与严格内容检查,`src/wiki/wiki-dependencies.ts` 的依赖评估同时驱动 Brief 写作指引和页面状态。Plan v2 保留人工选择,将新建议单独列出;文档来源哈希排除 Wiki 输出及变化的索引时间。数据库结构和检索排名保持不变。
@@ -80,3 +80,17 @@ A/B 报告入口是 `mdgraph report --benchmark benchmark-runs.json --json`。
80
80
  - 混合 Latin/CJK 的 config key、API route、source ref 和日文 symbol 查询。
81
81
 
82
82
  后续 CJK tokenizer、RRF/MMR 或 reranking 改动应和这个基线对比,但远程模型仍不应成为索引或搜索的必需路径。
83
+
84
+ ## 返回证据与兼容指标
85
+
86
+ 原有 `entityRecall`、`sourceRefRecall`、`edgeKindCoverage` 衡量实体、来源和关系类型是否存在于索引中(关系类型也包含 trace)。保留这些指标和原有 `passed` 的含义,它们不代表本次查询返回了对应证据。
87
+
88
+ 新增 `retrievedEntityRecall`、`retrievedSourceRefRecall`、`retrievedEdgeKindCoverage` 仅统计 search、context 和本次 trace 实际暴露的证据;对应名称记录在 `observed.retrievedEntities`、`retrievedSourceRefs`、`retrievedEdgeKinds`。`retrievalEvidencePassed` 要求原有检查和返回证据覆盖同时通过。`contextIrrelevantRatio` 是返回上下文中不属于预期文档的项目占比;空结果占比为零,但不代表召回成功。
89
+
90
+ ## 可重复的性能样本
91
+
92
+ 安装依赖后运行 `npm run baseline:performance -- 100,500`。脚本生成独立的合成文档集,索引 local-hash 向量、修改一个文档,测量全量/增量索引以及卡片、context、语义查询耗时。查询先预热一次,再报告五次采样的中位数。内存是操作后的进程 heap/RSS,不是峰值分配。JSON 包含运行时、平台、文档规模、记录计数和保留的样本路径。这些结果用于工程比较,不代表真实代理效果或生产大规模性能。
93
+
94
+ ## Knowledge/Wiki 输出基线
95
+
96
+ 运行 `npm run baseline:knowledge-wiki`,在固定的果园调度项目上测量 Card JSON 字符数、缺少归属标签的引用数量,以及已知文件在阅读建议中的位置。位置为 null 表示没有匹配的阅读建议,不表示搜索失败。Plan/Brief 输出用于检查项目通用规划和材料定位。这是输出行为比较,不是独立 Agent 的完成耗时或正文质量提升实验。
@@ -0,0 +1,99 @@
1
+ ---
2
+ status: implemented
3
+ defines:
4
+ - KnowledgeCard
5
+ - WikiPlan
6
+ - WikiPageBrief
7
+ - WikiStatus
8
+ - WikiVerification
9
+ source_refs:
10
+ - src/query/knowledge-card.ts
11
+ - src/query/context-builder.ts
12
+ - src/query/search.ts
13
+ - src/query/trace.ts
14
+ - src/db/repositories.ts
15
+ - src/mcp/tools.ts
16
+ - src/bin/mdgraph.ts
17
+ - src/wiki/wiki-plan.ts
18
+ - src/wiki/wiki-status.ts
19
+ - src/wiki/wiki-evidence.ts
20
+ - src/wiki/wiki-dependencies.ts
21
+ - src/wiki/wiki-domains.ts
22
+ ---
23
+
24
+ # Knowledge Card 与 Wiki 工作流
25
+
26
+ Knowledge Card 帮助定位和理解图证据。Wiki 命令负责规划、准备材料和检查维护状态,正文由宿主 Agent 或用户编写。两项功能均不依赖生成模型、向量模型、源码图或第二套数据库。
27
+
28
+ ## Knowledge Card
29
+
30
+ CLI `node` 与 MCP `mdgraph_node` 返回实验性的 `card`。`context` 仅在原始 Markdown 装入后仍有空间时,加入完整的 `cardSummary`。搜索排名、trace 路径和五个 MCP 工具保持不变。
31
+
32
+ 卡片保留 `nodeId`、`kind`、`label`、`summary`、`definitions`、`sourceRefs`、`relatedDocuments`、`evidence` 与可选的 `truncated`。新增的可选 `nextReads` 提供有数量上限的阅读位置和理由。
33
+
34
+ 引用通过 `association` 区分 `direct`(直接)、`inherited`(继承)和 `related`(关联背景),同时保留 `originNodeId` 及可选的 `viaNodeId`。章节自身的事实为直接证据,所属文档的声明为继承背景。文档汇总章节事实时保留其来源节点。经实体定义或引用文档找到的源码属于关联背景,不代表实体直接实现了所有这些文件。
35
+
36
+ 确定性摘要突出位置和关键关系,阅读建议来自实际图节点。默认整张卡片的 JSON 字符预算为 4,000,归属字段、阅读建议和截断说明均计入其中。裁剪时优先保留直接证据,展示文字可以用省略号结尾,但稳定节点身份保留。预算小到无法表示必需结构时明确报错。卡片不落库,也没有独立命令。
37
+
38
+ ## 创建 Wiki 计划
39
+
40
+ ```bash
41
+ mdgraph wiki plan --wiki-dir wiki --out .mdgraph/wiki-plan.json --path <project>
42
+ mdgraph wiki brief <page-id> --plan .mdgraph/wiki-plan.json --json --path <project>
43
+ ```
44
+
45
+ Plan v2 记录项目相对的 Wiki 输出目录,并将该目录排除在来源选择之外。概览、架构、使用、开发、运维、参考是通用候选方向;项目文档提供实际标题和领域词汇。材料稀少时只提出有证据支持的页面,并报告缺口。
46
+
47
+ 每页保留稳定 ID、输出路径、目的、读者、提纲、选定文档 ID、源码路径、证据查询和页面证据哈希。`dependencySnapshot` 保存文档与源码指纹,使维护检查能够指出具体变更文件。全局图哈希保留为诊断信息;索引时间等元数据变化不会要求全部页面重写。
48
+
49
+ ## 更新已有计划
50
+
51
+ ```bash
52
+ mdgraph wiki plan --from .mdgraph/wiki-plan.json --out .mdgraph/wiki-plan.next.json --path <project>
53
+ ```
54
+
55
+ 先审视新计划,再替换旧计划。更新会保留已有页面 ID、路径、层级、标题、目的、读者、提纲、文档、源码引用和查询。新增页面放入 `suggestions.pages`,既有页的新增文档与源码放入 `suggestions.sources`,不会自动改写人工选择。采纳建议时编辑对应页面字段,再刷新计划,然后按新 Brief 编写正文。已丢失的依赖仍然保留,并提供缺口说明。
56
+
57
+ v1 计划继续可读。用 `--from` 迁移时明确提供 `--wiki-dir wiki`,把 v2 结果写到新文件。未知的未来格式会得到诊断,输入文件保持原样。四个 Wiki 命令均不生成或覆盖正文。
58
+
59
+ ## 编写一个页面
60
+
61
+ Brief 的 `sourceDocuments` 是计划选定的主要材料;`supplementaryDocuments` 是检索补充材料;`sourceInspections` 列出需要检查的源码;`evidenceGaps` 说明尚未解决的缺口。Knowledge Card 标记直接依据和背景信息。
62
+
63
+ `maxChars`/`usedChars` 计算装入的上下文文字及序列化卡片。页面指引和来源清单是单独的定位、恢复信息,因此这一预算不是整个 Brief JSON 的大小上限。
64
+
65
+ 共享证据检查同时驱动 JSON、文本和写作要求。`strictFreshness` 表示索引与磁盘文档的状态,`dependencyEvidence` 表示本页选定依赖的状态。过期或未知的 Brief 仍可查看,但不会要求作者把旧哈希当成当前依据。按恢复指引刷新来源、索引和计划,再检查文件、编写正文。
66
+
67
+ 维护字段示例:
68
+
69
+ ```yaml
70
+ ---
71
+ wiki_id: architecture
72
+ evidence_hash: "<当前 Brief 的哈希>"
73
+ source_docs:
74
+ - docs/architecture.md
75
+ source_refs:
76
+ - src/main.ts
77
+ ---
78
+ ```
79
+
80
+ 两个来源字段必须是由非空项目相对路径组成的数组;没有来源时使用 `[]`。人工新增的来源应审视后纳入计划,不能仅为通过校验而删除引用。
81
+
82
+ 详细操作见 [Wiki 编写工作流](../../agent-pack/skills/wiki-authoring/SKILL.md)。
83
+
84
+ ## 状态、验证与正文验收
85
+
86
+ ```bash
87
+ mdgraph wiki status wiki --plan .mdgraph/wiki-plan.json --json --path <project>
88
+ mdgraph wiki verify wiki --plan .mdgraph/wiki-plan.json --json --path <project>
89
+ ```
90
+
91
+ `current` 表示记录的依赖和维护字段未发现变化。`needs_update`、`missing` 和 `orphaned` 分别提示需要更新、缺页和需要审视的额外页面。状态结果通过 `changes` 列出依赖变化,通过 `selectionChanges` 列出页面来源字段与计划的差异。增加无关文档可以使计划需要重新审视,但不会强迫无关页面重写。状态和验证均保留用户正文。
92
+
93
+ Verify 检查维护字段、来源、相对链接及证据一致性。`scope: maintenance-and-evidence` 和 `contentReview: not-evaluated` 明确检查范围。`valid: true` 不证明正文正确。正文验收应另外记录执行的任务、命令、结果、对应代码版本和未验证部分。
94
+
95
+ ## 验证方法
96
+
97
+ 回归测试覆盖归属、预算、过期证据、人工选择保留、格式兼容和完整更新流程。`npm run baseline:knowledge-wiki` 在果园调度示例上测量输出行为,不是独立 Agent A/B 实验,也不证明正文质量提升。`npm run baseline:performance` 测量 100/500 文档合成数据。
98
+
99
+ 仓库中的 `wiki/` 手册与 `wiki/acceptance.md` 分别记录真实使用说明和验收结果;它们的验收与单元测试通过分开报告。
@@ -89,3 +89,23 @@ mdgraph semantic status --path /path/to/project
89
89
  - `.mdgraph/config.json` 不含凭据时可以跟踪;MDGraph 会拒绝 endpoint URL 中嵌入的凭据。
90
90
  - 结构化交换应使用已记录的 GraphJSON,不要依赖 SQLite 内部结构。
91
91
  - 发布 MDGraph 本身前,运行[发布清单](Release_Checklist.md),检查 `npm pack --dry-run --json`,并实际验证 packed package,不要假设仓库内容等同于 npm 内容。
92
+
93
+ ## 服务目录与嵌入请求超时
94
+
95
+ MCP 按项目目录、配置和 SQLite 存储的实际文件目标检查访问范围。指向服务目录内部的链接仍可使用,也可以通过目录链接启动服务。访问外部项目时,请使用该项目的 `--path` 单独启动服务;服务目录内的链接不会自动授权访问外部目标。
96
+
97
+ `embedding.timeoutMs` 覆盖响应头与完整正文读取,包括错误响应。超时后 search/context 回退到全文与图谱检索;索引失败保留原有图谱。服务恢复后可以重试。
98
+
99
+ ## 增量一致性与监听配置
100
+
101
+ 索引在 SQLite 元数据中记录提取配置和提交版本。提取设置变化会重建相关图谱,纯查询设置不触发重建。增量更新根据全部已解析文档协调确定性关系,因此未修改文档的别名歧义也会更新。内容与 provider/model/dimensions 匹配的向量会复用。显式全量重建清除派生关系;提取配置引发的自动重建在向量配置不变时保留未受影响的派生关系。
102
+
103
+ 并发提交发现索引版本变化时重新扫描一次,持续冲突会明确报错,可稍后重试。解析失败保留该文档原有图谱,报告跳过文件,并将未完成的配置重建留待重试。修复对应 Markdown 并重新索引后再依赖其内容。
104
+
105
+ Watch 会重载配置和 `.gitignore` 规则,包括 MDX 开关。新监听器就绪后再关闭旧监听器。配置暂时无效时保留原监听并报告 degraded;修复配置后自动重试恢复。
106
+
107
+ ## Node.js 构建要求
108
+
109
+ 运行时需要具备启用 FTS5 的 `node:sqlite`,仅满足 22.5.0 版本号不够。Node 22.23.2 和 26.5.0 已通过本地完整测试。实测 22.5.0 和 22.13.0 标准构建缺少 FTS5,单独增加实验 SQLite 开关无法补足。MDGraph 在应用持久化 schema 之前检查实际能力,缺少时报告 `sqlite_fts5_unavailable` 并提示升级。通过扩展提供 FTS5 的构建仍可使用。
110
+
111
+ 早期运行时 CI 只验证 SQLite 兼容行为与缺失能力的恢复提示,不代表标准 Node 22.5.0 可运行全部产品功能。Windows 由 CI 验证,跨平台发布前应检查对应提交的运行结果。
@@ -74,10 +74,12 @@
74
74
 
75
75
  - `query`:原始查询文本。
76
76
  - `maxChars`:配置的上下文预算。
77
- - `usedChars`:已打包字符数。
77
+ - `usedChars`:已打包 `content` 与可选 `cardSummary` 的字符总数。
78
78
  - `packing`:additive 打包 metadata,包含 `strategy`;可选 MMR 还会报告 `similarity`、`mmrLambda` 和可选 `redundancySkippedItems`。
79
79
  - `semanticDiagnostic`:可选 provider 降级详情;未请求 semantic retrieval 或正常完成时不出现。
80
- - `items`:上下文条目,包含 `nodeId`、`documentId`、可选 `sectionId`、可选 `anchor`、`path`、`title`、可选 `heading`、可选 `lines`、`reason`、`matchedEntities`、可选 `edgePath`、可选 `sourceRefs`、可选 `riskNotes` 和 `content`。
80
+ - `items`:上下文条目,包含 `nodeId`、`documentId`、可选 `sectionId`、可选 `anchor`、`path`、`title`、可选 `heading`、可选 `lines`、`reason`、`matchedEntities`、可选 `edgePath`、可选 `sourceRefs`、可选 `riskNotes`、可选 `cardSummary` 和 `content`。
81
+
82
+ `cardSummary` 是实验性的确定性 Knowledge Card 摘要。只有原始文档内容装入后仍有剩余预算时,才会为排名最高的已选条目增加该字段;预算不足以容纳完整摘要时省略它,不会挤掉原始内容或恢复字段。
81
83
 
82
84
  `riskNotes` 可包含生命周期/trust 提醒,以及确定性的内容风险提示,例如 prompt-injection 文本、active HTML/data URI 或隐藏 Unicode 格式字符。
83
85
 
@@ -119,11 +121,36 @@
119
121
 
120
122
  Stale index、lexical-hash provider、当前 profile vector coverage 不完整、不安全 option 或计算预算超限都会在 mutation 前失败。成功的非 dry-run 会原子替换 `RELATED_TO/embedding_similarity` edge。该输出是 experimental,不改变稳定的 index、search、GraphJSON 或 MCP 契约。
121
123
 
124
+ ## 实验性 `wiki` 工作流
125
+
126
+ `mdgraph wiki plan --out <file> --json` 写入确定性 plan,并返回 `out` 与 `plan`。Plan 包含:
127
+
128
+ - `format: "mdgraph-wiki-plan"`、`formatVersion: 1`、`graphHash` 和 `sourceHash`。
129
+ - `pages`:稳定页面记录,包含 `id`、`title`、相对于 Wiki 的安全 `path`、可选 `parentId`、`purpose`、`audience`、`outline`、`documentIds`、项目相对 `sourceRefs`、`evidenceQueries` 和页面局部 `evidenceHash`。
130
+
131
+ `mdgraph wiki brief <page-id> --plan <file> --json` 返回:
132
+
133
+ - `format: "mdgraph-wiki-page-brief"`、`formatVersion: 1` 和选中的 `page`。
134
+ - `maxChars` 与 `usedChars`;已用预算覆盖 `contextItems` 的内容/Card 摘要以及序列化的 `knowledgeCards`。
135
+ - `sourceDocuments`(包含权威文档 ID、path、title、lifecycle/type/trust metadata),以及 `contextItems`、`knowledgeCards`、`writingRequirements` 和 `suggestedNextQueries`。
136
+
137
+ `mdgraph wiki status <wiki-dir> --plan <file> --json` 是只读命令,返回:
138
+
139
+ - `format: "mdgraph-wiki-status"`、`formatVersion: 1`、`wikiDir`,以及 current/stale plan hash 状态。
140
+ - `pages` 状态为 `current | needs_update | missing | orphaned`;每个非 current 页面都包含 `reason` 和可执行或面向人工评审的 `recovery` 动作。
141
+ - 四种状态的 `summary` 计数。
142
+
143
+ `mdgraph wiki verify <wiki-dir> --plan <file> --json` 是只读命令,返回 `format: "mdgraph-wiki-verification"`、`formatVersion: 1`、`valid`、结构化 `errors`、`warnings` 和同一 `status`。Issue 包含稳定 `code`、可用时的页面/path evidence,以及 `recovery`。验证无效时进程以非零状态退出。
144
+
145
+ 同一 graph/source 状态产生确定性的 Plan 与 Brief。Status 和 verification 不覆盖 Wiki 正文、不评判自然语言质量,也不要求 embedding 或 generation provider。
146
+
122
147
  ## `node --json`
123
148
 
124
149
  `mdgraph node <query> --json` 在找到节点时返回:
125
150
 
126
- - `id`、`label`、`kind`、`data`。
151
+ - `id`、`label`、`kind`、`data`,以及 document、section、entity、source-ref 节点可选的实验性 `card`。
152
+
153
+ `card` 是确定性、非持久化的查询投影,包含 `nodeId`、`kind`、`label`、`summary`、`definitions`、`sourceRefs`、`relatedDocuments`、`evidence`,以及可选的 `truncated` 省略计数。数组采用稳定顺序,并在适用处保留 node ID、path、edge kind、provenance、confidence、anchor 或 line range。Chunk 节点保持原有形状,不附加 Card。
127
154
 
128
155
  当章节查询有歧义时,返回:
129
156
 
@@ -301,3 +328,15 @@ Diff 只比较 Markdown 图记录、source refs 和 doctor warning codes。它
301
328
  - 问题数组:`orphanDocs`、`deadLinks`、`staleSourceRefs`、`missingDefinitions`、`weaklyLinkedDocs`、`possibleContradictions` 和 `contentRisks`。
302
329
 
303
330
  `mdgraph doctor --strict` 保持相同输出形状。当 `summary` 中除 `documents` 外的任一问题计数大于零时,以非零状态退出。
331
+
332
+ ## 评估证据补充字段
333
+
334
+ 评估 case 新增 `retrievalEvidencePassed`;`metrics` 新增 `retrievedEntityRecall`、`retrievedSourceRefRecall`、`retrievedEdgeKindCoverage`、`contextIrrelevantRatio`;`observed` 增加对应的实际返回实体、来源与关系类型数组。这些字段统计本次查询暴露的证据,旧覆盖指标及 `passed` 保持原有含义。详见[评估问题](Evaluation_Questions.md)。
335
+
336
+ ## Knowledge Card 归属与 Wiki 维护
337
+
338
+ Card 引用新增可选的 `association`(`direct | inherited | related`)、`originNodeId` 和 `viaNodeId`。`nextReads` 为可选字段,包含实际路径、节点身份、阅读理由及归属。这些信息都计入默认 4,000 字符的完整 Card JSON 预算。
339
+
340
+ 新 Wiki 计划使用 formatVersion 2,记录 `wikiDir`、依赖快照、页面与来源建议、证据缺口。v1 继续可读;通过 `wiki plan --from` 升级时,需要明确 `--wiki-dir`,并写到另一个 `--out` 文件。页面建议包含完整页面记录;来源建议包含 `pageId`、`documentIds` 和 `sourceRefs`。
341
+
342
+ Brief、Status、Verification 继续使用 formatVersion 1,通过新增字段扩展。Brief 增加 `supplementaryDocuments`、`sourceInspections`、`evidenceGaps` 和 `dependencyEvidence`。Status 页面增加 `changes`、`selectionChanges` 和 `evidenceState`。Verify 增加 `scope: "maintenance-and-evidence"` 与 `contentReview: "not-evaluated"`;`valid` 不代表正文正确性已获认证。
@@ -20,9 +20,10 @@
20
20
  | `mdgraph usage` 命令 | stable-additive | `src/bin/mdgraph.ts` | `usage` 打印面向 agent 的 workflow guide;`usage --json` 返回同一组 workflows 的机器可读 JSON,且不读写 graph index。 |
21
21
  | 实验性结构化 `query` 命令 | experimental | `src/query/structured-query.ts`、`src/query/structured-query-executor.ts`、`src/bin/mdgraph.ts` | `query <expression>` 提供有界 typed DSL,覆盖已记录的文档字段、tag、出边、日期、排序/limit 与 doctor health。它支持 `--json` 和 `--path`;不会改变稳定的 `search` 或五工具 MCP surface。 |
22
22
  | 实验性 `relationships derive` 命令 | experimental | `src/relationships/derive-related.ts`、`src/bin/mdgraph.ts` | 在 freshness、capability、coverage、threshold、独立 evidence、reciprocal top-K 和资源预算全部通过后,基于完整 semantic-model vector 显式派生低权重对称 `RELATED_TO` edge。支持 dry-run,且不会在 index/watch 中自动运行。 |
23
+ | 实验性 Wiki 工作流 | experimental | `src/wiki/wiki-plan.ts`、`src/wiki/wiki-status.ts`、`src/bin/mdgraph.ts` | `wiki plan/brief/status/verify` 增加确定性规划、有界证据 brief、影响状态和只读验证;不新增 MCP 工具,也不生成或覆盖正文。WikiPlan/WikiPageBrief formatVersion 1、页面状态名、结构化 verification issue 字段以及 invalid verification 的非零退出均为 experimental。 |
23
24
  | `status --freshness` diagnostics | stable-additive | `src/bin/mdgraph.ts` | `status --freshness` 增加可选 freshness diagnostics(`state`、`recommendation`、`lastIndexedAt`、`checkedAt`、`issues`),不改变默认 `status --json` 形状;`--storage` 与 `--freshness` 可组合。 |
24
25
  | `serve --mcp` 默认 watch 与 `--no-watch` 退路 | stable-additive | `src/bin/mdgraph.ts` | `serve --mcp` 默认保持 Markdown graph fresh,并暴露 `--no-watch` 作为只读退路;`--watch`、`--semantic`、`--debounce <ms>` 和显式 `--watch-poll` 是集成 watch-based freshness 的 additive flag。 |
25
- | 顶层 CLI JSON output shapes | stable | `docs/ZH/Output_Contracts.md` | Output Contracts 中记录的必需字段稳定;命令内嵌 graph record 遵循 `src/types.ts`,除非某一 section(例如实验性结构化 `query` 或 `relationships derive`)另有明确标记。 |
26
+ | 顶层 CLI JSON output shapes | stable | `docs/ZH/Output_Contracts.md` | Output Contracts 中记录的必需字段稳定;命令内嵌 graph record 遵循 `src/types.ts`,除非某一 section(例如实验性结构化 `query`、`relationships derive` 或 `wiki`)另有明确标记。 |
26
27
  | MCP tool names 和 input schemas | stable | `src/mcp/tools.ts` | 固定五个工具:`mdgraph_search`、`mdgraph_context`、`mdgraph_node`、`mdgraph_trace` 和 `mdgraph_status`;schema 拒绝未声明属性。 |
27
28
  | MCP structured freshness metadata | stable-additive | `src/mcp/tools.ts` | 当已建立索引时,`mdgraph_status` 会在 `structuredContent` 中返回 `freshness` metadata;当索引 `stale` 或 `unknown` 时,`mdgraph_search` / `mdgraph_context` / `mdgraph_node` / `mdgraph_trace` 也可能追加同一 `freshness` object,并在文本结果前加 warning banner。 |
28
29
  | MCP semantic fallback diagnostics | stable-additive | `src/mcp/tools.ts` | `mdgraph_search` 和 `mdgraph_context` 使用异步 provider 路径。semantic retrieval 无法运行时继续返回 lexical/graph 结果并在文本前增加 warning。Search 追加 `structuredContent.semanticDiagnostic`;context 追加 `structuredContent.context.semanticDiagnostic`。两者都包含 `code`、`provider`、`message` 和 `degraded: true`。 |
@@ -31,6 +32,7 @@
31
32
  | Structured query AST 与执行 | experimental | `src/query/structured-query.ts`、`src/query/structured-query-executor.ts`、`src/db/repositories.ts` | 用户值使用 SQL bound parameter。字段、operator、sort 与 edge enum 在白名单 SQL 组装前完成验证。Health predicate 要求 fresh doctor report,并保留原始 boolean AST。不会暴露任意 front matter 或 raw SQL 逃生口。 |
32
33
  | 派生关系执行 | experimental | `src/relationships/derive-related.ts`、`src/db/repositories.ts` | `RELATED_TO/embedding_similarity` edge 非权威、低权重且可原子替换,并携带 provider/model/algorithm/threshold/evidence/generation metadata。`local-hash` 无权发射。GraphJSON 保持结构化隐私 profile,因此不导出这些 edge metadata。 |
33
34
  | MCP text output wording | experimental | `src/mcp/tools.ts` | 文本是面向人的提示;机器契约优先使用 `structuredContent`。 |
35
+ | 动态 Knowledge Card 投影 | experimental / stable-additive | `src/query/knowledge-card.ts`、`src/query/context-builder.ts`、`src/bin/mdgraph.ts`、`src/mcp/tools.ts` | 找到 document、section、entity 或 source-ref 时,`node` 结果可增量返回确定性、非持久化的 `card`;已选 context item 只会使用原始内容装入后的剩余预算增加 `cardSummary`,且字符计入 `usedChars`。既有 node 字段、ranking、trace path、SQLite counts 和五工具 MCP surface 均不改变。 |
34
36
  | Context recovery fields | stable-additive | `src/query/context-builder.ts` | Context item 暴露 `nodeId`、`documentId`、可选 `sectionId`、可选 `anchor`、line range、source refs、risk notes 和 graph-expansion `edgePath`,让 agent 无需从 prose 猜测即可恢复节点和 provenance。 |
35
37
  | `.mdgraph/config.json` fields | stable | `src/config/load-config.ts` | `docs`、`index`、`search`、`entities` 和 `embedding` 默认字段稳定。Additive embedding 字段为 `endpoint`、`timeoutMs` 和 `batchSize`,既有配置文件会取得默认值。当前 merge 逻辑会忽略未知字段。 |
36
38
  | `.mdgraph` file governance | stable | `src/config/load-config.ts`、`src/bin/mdgraph.ts` | `mdgraph init` 保持 `.mdgraph/config.json` 可跟踪,在没有等价 ignore 规则时通过根 `.gitignore` 保护本地 `.mdgraph` artifacts,并默认构建初始 graph index。`.mdgraph/graph.db` 和生成的 `.mdgraph` artifacts 属于本地 workflow state,不是 source files。需要只生成配置时使用 `--no-index`。 |
@@ -70,6 +70,10 @@ provider/evidence 门禁和 JSON 输出记录在
70
70
  [结构化查询与派生关系](Structured_Query_and_Relationships.md#派生相关文档关系)与输出契约中。稳定的 `search`
71
71
  命令与五工具 MCP surface 均未改变。
72
72
 
73
+ `wiki plan/brief/status/verify` 是冻结后新增的实验性 CLI group。它不增加 MCP 工具、
74
+ 不生成正文,记录在 [Knowledge Card 与 Wiki 工作流](Knowledge_Cards_and_Wiki_Workflow.md)
75
+ 和输出契约中。
76
+
73
77
  项目相关命令接受 additive `--path <project>` flag,让 agent 和脚本不必切换
74
78
  shell cwd 即可定位仓库。
75
79
 
package/docs/ZH/README.md CHANGED
@@ -10,6 +10,7 @@ MDGraph 文档按用户任务组织。安装和首次查询请从仓库的 [中
10
10
  - [检索与上下文](Retrieval_and_Context.md) — 理解搜索通道、可选语义 provider、实体抽取、CJK 处理和上下文打包。
11
11
  - [结构化查询与派生关系](Structured_Query_and_Relationships.md) — 执行治理查询,并显式派生非权威的相关文档边。
12
12
  - [运行与故障处理](Operations.md) — 保持索引新鲜、解释 watcher 健康状态、安全使用 polling,并处理 provider 或文件监听故障。
13
+ - [Knowledge Card 与 Wiki 工作流](Knowledge_Cards_and_Wiki_Workflow.md) — 在不内置正文生成模型的前提下规划并维护有证据的用户 Wiki。
13
14
 
14
15
  ## 集成与维护 MDGraph
15
16
 
@@ -15,6 +15,7 @@
15
15
  - 确认 focused contract tests 覆盖 MCP tool definitions、代表性 JSON fields、edge kinds、doctor warning shape、config defaults 和 schema compatibility guidance。
16
16
  - 已经返回结构化错误的命令,应确认错误输出包含稳定 `code` 和 remediation。
17
17
  - 确认实验性命令在使用指南、公开 ledger、输出契约和 release notes 中保持明确标记。
18
+ - 确认 `wiki status` 与 `wiki verify` 保持只读,每个非 current 页面/issue 都有 recovery 指引,且五工具 MCP surface 不变。
18
19
 
19
20
  ## 证据门槛
20
21