@daogee/mdgraph 1.1.0 → 1.2.1
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.
- package/CHANGELOG.md +42 -0
- package/README-ZH.md +13 -3
- package/README.md +13 -3
- package/agent-pack/README.md +2 -0
- package/agent-pack/mdgraph-agent-instructions.md +5 -1
- package/agent-pack/prompts/wiki-authoring.md +12 -0
- package/agent-pack/skills/wiki-authoring/SKILL.md +38 -0
- package/agent-pack/skills/wiki-authoring/agents/openai.yaml +4 -0
- package/dist/analysis/status-freshness.d.ts +8 -1
- package/dist/analysis/status-freshness.js +19 -6
- package/dist/bin/mdgraph.js +125 -6
- package/dist/db/connection.js +17 -1
- package/dist/db/repositories.d.ts +30 -5
- package/dist/db/repositories.js +171 -8
- package/dist/db/sqlite-adapter.js +8 -2
- package/dist/evaluation/retrieval-eval.d.ts +11 -0
- package/dist/evaluation/retrieval-eval.js +35 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +3 -0
- package/dist/indexer.js +64 -6
- package/dist/mcp/server.js +5 -4
- package/dist/mcp/tools.js +26 -11
- package/dist/query/context-builder.d.ts +2 -0
- package/dist/query/context-builder.js +154 -24
- package/dist/query/knowledge-card.d.ts +90 -0
- package/dist/query/knowledge-card.js +676 -0
- package/dist/query/search.js +30 -8
- package/dist/scanner/file-scanner.js +7 -7
- package/dist/semantic/ollama-provider.js +6 -1
- package/dist/utils/fts.d.ts +1 -0
- package/dist/utils/fts.js +68 -13
- package/dist/utils/path-safety.d.ts +3 -0
- package/dist/utils/path-safety.js +27 -0
- package/dist/watcher/file-watcher.js +121 -17
- package/dist/wiki/wiki-dependencies.d.ts +20 -0
- package/dist/wiki/wiki-dependencies.js +45 -0
- package/dist/wiki/wiki-domains.d.ts +13 -0
- package/dist/wiki/wiki-domains.js +55 -0
- package/dist/wiki/wiki-evidence.d.ts +27 -0
- package/dist/wiki/wiki-evidence.js +112 -0
- package/dist/wiki/wiki-plan.d.ts +121 -0
- package/dist/wiki/wiki-plan.js +616 -0
- package/dist/wiki/wiki-status.d.ts +67 -0
- package/dist/wiki/wiki-status.js +451 -0
- package/docs/EN/Agent_Integration.md +16 -4
- package/docs/EN/Architecture.md +14 -2
- package/docs/EN/Evaluation_Questions.md +21 -1
- package/docs/EN/Knowledge_Cards_and_Wiki_Workflow.md +97 -0
- package/docs/EN/Operations.md +22 -0
- package/docs/EN/Output_Contracts.md +44 -3
- package/docs/EN/Public_Contracts.md +4 -2
- package/docs/EN/Public_Contracts_1.0.md +4 -0
- package/docs/EN/README.md +1 -0
- package/docs/EN/Release_Checklist.md +3 -2
- package/docs/EN/Retrieval_and_Context.md +20 -5
- package/docs/ZH/Agent_Integration.md +16 -4
- package/docs/ZH/Architecture.md +14 -4
- package/docs/ZH/Evaluation_Questions.md +21 -1
- package/docs/ZH/Knowledge_Cards_and_Wiki_Workflow.md +99 -0
- package/docs/ZH/Operations.md +22 -0
- package/docs/ZH/Output_Contracts.md +44 -3
- package/docs/ZH/Public_Contracts.md +4 -2
- package/docs/ZH/Public_Contracts_1.0.md +4 -0
- package/docs/ZH/README.md +1 -0
- package/docs/ZH/Release_Checklist.md +3 -2
- package/docs/ZH/Retrieval_and_Context.md +20 -5
- package/package.json +8 -3
|
@@ -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.
|
package/docs/EN/Operations.md
CHANGED
|
@@ -38,6 +38,8 @@ mdgraph watch --path /path/to/project
|
|
|
38
38
|
mdgraph serve --mcp --path /path/to/project
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
Native Markdown change events are compared with the last successfully indexed file-content hash. Unchanged content does not trigger another index callback; real edits, additions, removals, and configuration changes retain their update flow. Events arriving during indexing are checked after that attempt finishes.
|
|
42
|
+
|
|
41
43
|
The watcher exposes an in-process health snapshot through `WatchHandle.getHealth()`. Integrated MCP serving adds it to `mdgraph_status.structuredContent.watchHealth`.
|
|
42
44
|
|
|
43
45
|
| State | Meaning | Operator action |
|
|
@@ -89,3 +91,23 @@ Derived `RELATED_TO` edges are disposable, non-authoritative state. Changes to a
|
|
|
89
91
|
- Keep `.mdgraph/config.json` trackable when it contains no credentials; endpoint URLs with embedded credentials are rejected.
|
|
90
92
|
- Use GraphJSON for the documented structural exchange format instead of depending on SQLite internals.
|
|
91
93
|
- 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.
|
|
94
|
+
|
|
95
|
+
## Served roots and embedding deadlines
|
|
96
|
+
|
|
97
|
+
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.
|
|
98
|
+
|
|
99
|
+
`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.
|
|
100
|
+
|
|
101
|
+
## Incremental consistency and watch configuration
|
|
102
|
+
|
|
103
|
+
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.
|
|
104
|
+
|
|
105
|
+
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.
|
|
106
|
+
|
|
107
|
+
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.
|
|
108
|
+
|
|
109
|
+
## Node.js build requirements
|
|
110
|
+
|
|
111
|
+
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.
|
|
112
|
+
|
|
113
|
+
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,14 @@ 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
|
|
77
|
+
- `usedChars`: the sum of packed `content` and optional `cardSummary` lengths, measured in JavaScript UTF-16 code units.
|
|
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`, optional `truncated`, and `content`.
|
|
81
|
+
|
|
82
|
+
`truncated: true` identifies a partial section. Its `lines` cover the returned excerpt; the retained section identity and anchor resolve the complete source. Known-file evidence shares the same `maxChars` budget with ordinary search and graph evidence. The budget excludes JSON keys, reasons, paths, other metadata, and text-format headings; it is not a token budget or a limit on the serialized MCP response.
|
|
83
|
+
|
|
84
|
+
`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
85
|
|
|
82
86
|
`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
87
|
|
|
@@ -119,11 +123,36 @@ The compatibility default is `mmr-style-document-round-robin`. `--packing mmr` i
|
|
|
119
123
|
|
|
120
124
|
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
125
|
|
|
126
|
+
## Experimental `wiki` workflow
|
|
127
|
+
|
|
128
|
+
`mdgraph wiki plan --out <file> --json` writes a deterministic plan and returns `out` plus `plan`. The plan contains:
|
|
129
|
+
|
|
130
|
+
- `format: "mdgraph-wiki-plan"`, `formatVersion: 1`, `graphHash`, and `sourceHash`.
|
|
131
|
+
- `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`.
|
|
132
|
+
|
|
133
|
+
`mdgraph wiki brief <page-id> --plan <file> --json` returns:
|
|
134
|
+
|
|
135
|
+
- `format: "mdgraph-wiki-page-brief"`, `formatVersion: 1`, and the selected `page`.
|
|
136
|
+
- `maxChars` and `usedChars`, where the used budget covers `contextItems` content/Card summaries and serialized `knowledgeCards`.
|
|
137
|
+
- `sourceDocuments` with authoritative document IDs, paths, titles, lifecycle/type/trust metadata; plus `contextItems`, `knowledgeCards`, `writingRequirements`, and `suggestedNextQueries`.
|
|
138
|
+
|
|
139
|
+
`mdgraph wiki status <wiki-dir> --plan <file> --json` is read-only and returns:
|
|
140
|
+
|
|
141
|
+
- `format: "mdgraph-wiki-status"`, `formatVersion: 1`, `wikiDir`, and current/stale plan hashes.
|
|
142
|
+
- `pages` with `current | needs_update | missing | orphaned`; every non-current page includes `reason` and an executable or review-oriented `recovery` action.
|
|
143
|
+
- `summary` counts for all four states.
|
|
144
|
+
|
|
145
|
+
`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.
|
|
146
|
+
|
|
147
|
+
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.
|
|
148
|
+
|
|
122
149
|
## `node --json`
|
|
123
150
|
|
|
124
151
|
`mdgraph node <query> --json` returns the resolved node record when found:
|
|
125
152
|
|
|
126
|
-
- `id`, `label`, `kind`, `data
|
|
153
|
+
- `id`, `label`, `kind`, `data`, and optional experimental `card` for document, section, entity, and source-ref nodes.
|
|
154
|
+
|
|
155
|
+
`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
156
|
|
|
128
157
|
When a section query is ambiguous, it returns:
|
|
129
158
|
|
|
@@ -306,3 +335,15 @@ Diff only compares Markdown graph records, source refs, and doctor warning codes
|
|
|
306
335
|
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
336
|
|
|
308
337
|
`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`.
|
|
338
|
+
|
|
339
|
+
## Evaluation evidence additions
|
|
340
|
+
|
|
341
|
+
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).
|
|
342
|
+
|
|
343
|
+
## Knowledge Card ownership and Wiki maintenance
|
|
344
|
+
|
|
345
|
+
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.
|
|
346
|
+
|
|
347
|
+
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`.
|
|
348
|
+
|
|
349
|
+
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
|
|
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,7 +39,8 @@ 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. |
|
|
41
|
-
|
|
|
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. |
|
|
43
|
+
| Context recovery fields | stable-additive | `src/query/context-builder.ts` | Context items expose `nodeId`, `documentId`, optional `sectionId`, optional `anchor`, excerpt line ranges, optional `truncated: true`, 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. |
|
|
44
46
|
| SQLite schema metadata | stable | `src/db/schema.sql`, `src/db/connection.ts` | `schema_metadata.schema_version` gates compatibility. Future schema versions fail before local schema is applied. |
|
|
@@ -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
|
|
|
@@ -4,7 +4,7 @@ Use this checklist before publishing an MDGraph release or asking a maintainer t
|
|
|
4
4
|
|
|
5
5
|
## Public checks
|
|
6
6
|
|
|
7
|
-
- Confirm the public package is `@daogee/mdgraph`, the installed binary remains `mdgraph`, and `package.json`
|
|
7
|
+
- Confirm the public package is `@daogee/mdgraph`, the installed binary remains `mdgraph`, and `package.json`, the root `package-lock.json` version, and the CLI version match the release tag.
|
|
8
8
|
- Promote the relevant [CHANGELOG.md](../../CHANGELOG.md) `Unreleased` entries into a dated version whose number matches `package.json` before tagging.
|
|
9
9
|
- Review README quick start, requirements, MCP setup, output contracts, public contract labels, and known tradeoffs when public CLI/MCP behavior changed.
|
|
10
10
|
- Confirm the GitHub repository still exposes `README.md`, `LICENSE`, `CONTRIBUTING.md`, `SECURITY.md`, issue templates, and the pull-request template; review the GitHub community profile before a public launch.
|
|
@@ -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
|
|
|
@@ -86,7 +87,7 @@ Expected results:
|
|
|
86
87
|
- Confirm the package includes `dist`, the agent pack, both README files, `CHANGELOG.md`, `LICENSE`, and the explicitly allowlisted English/Chinese guides.
|
|
87
88
|
- Confirm the package does not contain numbered implementation-stage docs, internal implementation ADRs, `docs/tasks/`, `.mdgraph/`, local databases, `.DS_Store`, temporary output, or external workspace content.
|
|
88
89
|
- Install the packed tarball globally under a clean temporary prefix and verify `mdgraph --version`, `init`, and one representative query before publishing.
|
|
89
|
-
- Run `npm run smoke:pack`; it verifies runtime/type consumption and rejects implementation-stage documentation in the tarball.
|
|
90
|
+
- Run `npm run smoke:pack`; it verifies runtime/type consumption and rejects implementation-stage documentation in the tarball. This smoke copies packed files into a temporary consumer and links existing runtime dependencies; record the clean-prefix tarball installation above separately.
|
|
90
91
|
|
|
91
92
|
## Note text
|
|
92
93
|
|
|
@@ -16,14 +16,17 @@ MDGraph combines deterministic full-text, entity, and graph retrieval by default
|
|
|
16
16
|
|
|
17
17
|
## Search Channels
|
|
18
18
|
|
|
19
|
-
`search` combines and deduplicates
|
|
19
|
+
`search` combines and deduplicates three explainable channels:
|
|
20
20
|
|
|
21
21
|
- FTS5 chunk matches, with lightweight CJK n-gram augmentation for continuous Chinese, Japanese, and Korean text.
|
|
22
22
|
- Exact technical-entity matches.
|
|
23
|
-
- Graph neighbors around matching entities and documents.
|
|
24
23
|
- Optional embedding-vector matches when a supported provider is enabled, indexed, and requested.
|
|
25
24
|
|
|
26
|
-
Reciprocal rank fusion (RRF) combines the active channels.
|
|
25
|
+
Reciprocal rank fusion (RRF) combines the active channels. Search results retain reasons, matched entities, and optional semantic provider/model metadata. Context graph expansion also reports edge provenance. Semantic results are an additional signal; they do not replace the deterministic channels. Graph neighbors are added during context building after search.
|
|
26
|
+
|
|
27
|
+
FTS queries deduplicate terms and distribute at most 48 tokens across the beginning and end of query groups. Latin identifiers, complete numeric versions, and dates retain their own groups; CJK two- and three-character grams share the allocation. Retrieval takes a bounded candidate pool independently of the requested result limit, then ranks FTS candidates by query-group coverage with BM25 as a tie-breaker before RRF. Coverage measures the fraction of each group's tokens present in the source text.
|
|
28
|
+
|
|
29
|
+
For queries with a group containing more than 12 grams, the candidate pool also grows with the indexed document count up to 128; smaller indexes retain the existing limit-based pool. Coverage is divided by `sqrt(max(300, section characters) / 300)` and the FTS base score omits raw BM25. Short keyword queries retain the BM25 contribution to the base score. Entity/semantic fusion and document trust/lifecycle adjustments also contribute to final result order. This remains lexical matching, not synonym understanding.
|
|
27
30
|
|
|
28
31
|
## Semantic Providers
|
|
29
32
|
|
|
@@ -83,7 +86,13 @@ Unicode-aware rules recognize CJK API paths such as `POST /接口/登录`, segme
|
|
|
83
86
|
|
|
84
87
|
`context` starts from ranked search sections, performs bounded graph expansion through non-containment edges, and packs selected sections under a character budget.
|
|
85
88
|
|
|
86
|
-
The
|
|
89
|
+
The default retains the selector `mmr-style-document-round-robin`. Known-file evidence is introduced across documents first; other direct search hits keep their relevance order, followed by document-round-robin graph expansion. This prevents a highly ranked section from being delayed behind many lower-ranked documents. It remains deterministic and does not calculate pairwise relevance and redundancy.
|
|
90
|
+
|
|
91
|
+
MCP `knownFiles` and library options accept document paths, explicit `path#anchor` sections, and indexed source references. A short document contributes its complete sections when they fit its initial budget share. A longer document contributes up to four file-scoped FTS sections in BM25 order plus its overview. SQL applies the document restriction before the candidate limit. Source references use the same document selection through their existing graph edges; an explicit section keeps its identity.
|
|
92
|
+
|
|
93
|
+
Known documents share the character budget according to their actual candidate sizes: short documents release unused capacity to longer documents. For queries with a group containing more than 12 grams, direct candidates share the remaining budget by actual text length before graph expansion. Short keyword queries use an initial per-section share based on at most six direct candidates.
|
|
94
|
+
|
|
95
|
+
A partial section starts at a query-relevant paragraph, includes `truncated: true`, and reports the excerpt's actual line range. Use the retained path, section identity, or anchor to locate the complete source for a targeted Markdown read. Original content and optional card summaries together remain bounded by `maxChars`.
|
|
87
96
|
|
|
88
97
|
True MMR is opt-in:
|
|
89
98
|
|
|
@@ -92,7 +101,7 @@ mdgraph context --packing mmr --mmr-lambda 0.65 --debug --json \
|
|
|
92
101
|
--path /path/to/project "session recovery"
|
|
93
102
|
```
|
|
94
103
|
|
|
95
|
-
MCP callers select the same behavior with `packingStrategy: "mmr"
|
|
104
|
+
MCP callers select the same behavior with `packingStrategy: "mmr"`; CLI and library callers may also provide `mmrLambda`. Within the known-file, direct-search, and graph-expansion priority tiers, MMR maximizes:
|
|
96
105
|
|
|
97
106
|
```text
|
|
98
107
|
lambda * queryRelevance - (1 - lambda) * maximumSimilarityToSelected
|
|
@@ -110,3 +119,9 @@ Every result includes `packing` metadata. `--debug` additionally reports candida
|
|
|
110
119
|
- MMR reduces measured redundancy on the repository fixture, but its best lambda and similarity threshold remain corpus-dependent.
|
|
111
120
|
|
|
112
121
|
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.
|
|
122
|
+
|
|
123
|
+
## Exact entity queries and Knowledge Cards
|
|
124
|
+
|
|
125
|
+
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.
|
|
126
|
+
|
|
127
|
+
`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.
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
对于 coding task,把任务描述写进 `mdgraph_context` 查询,并通过 `knownFiles` 传入已知文件路径。这样 MDGraph 可以返回更像 task-start documentation brief 的结果:相关文档、source refs、risk notes、provenance、确定性的 auto-mode metadata 和 `suggestedNextQueries`。
|
|
17
17
|
|
|
18
|
+
文档路径会触发文件内部的正文章节检索;长文档同时保留概述。已经知道具体章节时,可传入 `path#anchor`。Context 自动模式的 `searchLimit` 是同一查询对应 MCP search 自动模式结果上限 `limit` 的两倍,仍遵守请求中的字符预算。部分章节通过 `truncated: true` 和实际片段行号,支持继续读取指定原文。
|
|
19
|
+
|
|
18
20
|
## 共享 Instruction Template
|
|
19
21
|
|
|
20
22
|
```text
|
|
@@ -90,13 +92,23 @@ Task-start documentation brief:
|
|
|
90
92
|
2. 对解析出的节点调用 `mdgraph_trace`
|
|
91
93
|
3. 如果 trace 路径还需要上下文,再调用 `mdgraph_context`
|
|
92
94
|
|
|
93
|
-
文档健康检查:
|
|
95
|
+
文档健康检查:
|
|
94
96
|
|
|
95
97
|
1. `mdgraph_status`
|
|
96
98
|
2. 当用户要求 docs health 或 CI gate 时,使用 CLI `mdgraph doctor --json`
|
|
97
|
-
3. 只有在 doctor 输出点名 affected documents 后才编辑原文件
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
3. 只有在 doctor 输出点名 affected documents 后才编辑原文件
|
|
100
|
+
|
|
101
|
+
项目 Wiki authoring:
|
|
102
|
+
|
|
103
|
+
1. 针对当前图运行一次 CLI `mdgraph wiki plan --out <plan-file>`。
|
|
104
|
+
2. 运行 `mdgraph wiki status <wiki-dir> --plan <plan-file> --json`,只选择 missing 或 needs-update 页面。
|
|
105
|
+
3. 每次获取一个 `mdgraph wiki brief <page-id> --plan <plan-file> --json`,阅读其 document/source-ref evidence 后再编写。
|
|
106
|
+
4. 保留用户正文与维护 front matter,然后运行 `mdgraph wiki verify`。
|
|
107
|
+
5. 人工评审 orphaned 页面;工作流永不自动删除它们。
|
|
108
|
+
|
|
109
|
+
支持 reusable skill 的宿主可使用 [`agent-pack/skills/wiki-authoring`](../../agent-pack/skills/wiki-authoring/SKILL.md),其他宿主可使用对应 prompt template。
|
|
110
|
+
|
|
111
|
+
## 当前限制
|
|
100
112
|
|
|
101
113
|
- MDGraph 索引 Markdown 文档,不索引源码 AST 或任意文件。
|
|
102
114
|
- MCP surface 故意保持五个工具:search、context、node、trace、status。
|
package/docs/ZH/Architecture.md
CHANGED
|
@@ -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 创建和校验。 |
|
|
@@ -108,13 +109,12 @@ Diff report 包含 Markdown 文档新增、修改、删除、Git 识别的 renam
|
|
|
108
109
|
- FTS5 块命中,包含连续中文/日文/韩文文本的轻量 CJK n-gram 命中。
|
|
109
110
|
- 精确实体匹配。
|
|
110
111
|
- 可选 embedding 向量匹配。
|
|
111
|
-
- 匹配实体周围的图邻居。
|
|
112
112
|
|
|
113
113
|
当同一文档或章节通过多条路径命中时,搜索会在 definition、FTS 和可选 semantic 通道之间应用 reciprocal rank fusion(RRF),再保留最高基础分,同时合并主要命中原因和匹配实体,避免丢失来源解释。每个融合结果都会保留可解释的 `RRF fusion (...)` reason。
|
|
114
114
|
|
|
115
115
|
同步 `searchGraph`、`buildContext` 和 `evaluateRetrieval` API 保留 1.0 行为,可在进程内执行 `local-hash`。对应的异步 API 会解析 Ollama 等外部 provider,CLI 与 MCP 查询路径使用异步版本。provider 不可用、超时、响应非法、模型缺失或 vector coverage 不完整时,会降级到 keyword/entity/graph retrieval,并返回 additive `semanticDiagnostic`;CLI 文本和非 explain JSON 命令还会把诊断写到 stderr。
|
|
116
116
|
|
|
117
|
-
然后 `buildContext` 从排序后的搜索章节开始,通过非包含边执行有界图扩展,在字符预算下打包选定的章节,并包含原因,如 FTS
|
|
117
|
+
然后 `buildContext` 从排序后的搜索章节开始,通过非包含边执行有界图扩展,在字符预算下打包选定的章节,并包含原因,如 FTS 命中、语义命中、精确实体匹配或图边遍历路径。默认策略保留原选择器名称,先引入已知文档正文和按相关度排序的直接命中,再按文档轮询引入图扩展候选;已知文档先在文件内检索章节,并共享现有字符预算。部分章节返回实际片段行号和截断标记。可选 `mmr` 在已知文件、直接命中和图扩展各自的优先级内最大化 query relevance 并惩罚冗余;两个候选都有当前 provider 已存向量时使用向量相似度,否则回退到确定性的 Unicode token Jaccard,并剪除同文档近重复项,同时保留每个文档的首个候选。
|
|
118
118
|
|
|
119
119
|
每个 context 结果都会包含 additive packing metadata。当请求 `context --debug` 时,上下文构建还会报告 seed nodes、visited nodes、expanded edges、跳过原因、候选数量、策略/相似度选择、逐项 query relevance、redundancy penalty 和 MMR score、冗余剪枝及预算截断计数。这些诊断不是图事实,只用于解释上下文打包和评估检索质量。
|
|
120
120
|
|
|
@@ -125,8 +125,14 @@ Diff report 包含 Markdown 文档新增、修改、删除、Git 识别的 renam
|
|
|
125
125
|
`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
126
|
|
|
127
127
|
`traceNodes` 在执行节点之间的有界图遍历,并返回每一步的边类型、来源和置信度。
|
|
128
|
-
|
|
129
|
-
##
|
|
128
|
+
|
|
129
|
+
## Wiki 工作流
|
|
130
|
+
|
|
131
|
+
实验性 Wiki 路径与 indexing 和自然语言 query ranking 分离。`buildWikiPlan` 只根据已索引文档 metadata 与显式图关系选择有证据的页面域,记录 graph/source hash,并为每页生成依赖局部 `evidenceHash`;该 hash 也会指纹化安全的项目 source ref。`buildWikiPageBrief` 复用 context packing、known files、Knowledge Card 和共享字符预算。
|
|
132
|
+
|
|
133
|
+
`buildWikiStatus` 将用户维护页面的 front matter 与 plan 及当前依赖证据比较,只报告 `current`、`needs_update`、`missing` 或 `orphaned`,不修改文件。`verifyWiki` 增加有界检查,覆盖 plan 形状、已索引 source document、安全且存在的 source ref、evidence freshness 和可解析的相对 Markdown link。它不评判正文质量、不删除 orphaned 页面、不调用模型,也不增加 MCP 工具。
|
|
134
|
+
|
|
135
|
+
## MCP 边界
|
|
130
136
|
|
|
131
137
|
MCP 服务器有意仅暴露五个工具。Search/context 通过 provider-aware 异步 handler 调度,node/trace/status 保留同步行为。工具输出以文本为主且兼容 JSON,以便代理可以直接使用,无需先检查 SQLite 数据库或读取原始文件。semantic 降级会增加文本提示和结构化诊断,但不会把仍然可用的 lexical/graph 结果变成 MCP error。服务器会绑定到项目根:initialize root 和工具 `projectPath` 必须位于服务根之内。
|
|
132
138
|
|
|
@@ -142,3 +148,7 @@ MCP 服务器有意仅暴露五个工具。Search/context 通过 provider-aware
|
|
|
142
148
|
- 互操作 adapter 是只读导向的。GraphJSON verify、Mermaid/Markdown/docs-site export 和 source bridge report 不会把外部 graph 合并进主 SQLite index。
|
|
143
149
|
- `RELATED_TO` 是实验性派生 edge,只能由显式、provider-gated 的流程发射,普通确定性 indexing 永远不会发射它。`SAME_AS` 和 `CONTRADICTS` 继续保留;类似矛盾的信号仍由 `doctor` 报告,而不是作为 graph edge 插入。
|
|
144
150
|
- 当前实现优先考虑紧凑、确定性的核心,而非广泛的 Markdown/MDX 方言支持。
|
|
151
|
+
|
|
152
|
+
## Knowledge 与 Wiki 的证据归属
|
|
153
|
+
|
|
154
|
+
Card 将直接边、文档或章节的继承背景、关联源码依据分开表达,引用和阅读建议保留稳定来源信息。`src/wiki/wiki-evidence.ts` 负责 Wiki 证据哈希与严格内容检查,`src/wiki/wiki-dependencies.ts` 的依赖评估同时驱动 Brief 写作指引和页面状态。Plan v2 保留人工选择,将新建议单独列出;文档来源哈希排除 Wiki 输出及变化的索引时间。数据库结构和检索排名保持不变。
|
|
@@ -67,7 +67,7 @@ Watcher tests 覆盖启动/运行期 `ENOSPC`、运行期 `EMFILE`、启动期 `
|
|
|
67
67
|
- MDGraph 返回的上下文是否足够,无需进一步检查文件。
|
|
68
68
|
- 整个代理运行的时间和工具调用次数。
|
|
69
69
|
- `mdgraph eval` 指标:top-K 文档召回、预期章节召回、上下文精度、trace 成功率、延迟、返回字符数、预算适配、fanout、上下文多样性、reason 覆盖率和 ranking reason 覆盖率。
|
|
70
|
-
- `mdgraph eval` 排序报告:query mode、RRF 搜索融合通道、兼容上下文打包策略、可选 reranker 状态和 semantic-active case 数量。使用聚焦 context 回归套件对比可选真 MMR
|
|
70
|
+
- `mdgraph eval` 排序报告:query mode、RRF 搜索融合通道、兼容上下文打包策略、可选 reranker 状态和 semantic-active case 数量。使用聚焦 context 回归套件对比可选真 MMR 和当前确定性默认策略,并记录代码版本与字符预算。
|
|
71
71
|
|
|
72
72
|
A/B 报告入口是 `mdgraph report --benchmark benchmark-runs.json --json`。它消费结构化 run records 并报告 aggregate deltas;完整 transcript 应保留在公开文档之外。
|
|
73
73
|
|
|
@@ -80,3 +80,23 @@ 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
|
+
检索变化应冻结源码版本或文件哈希、索引范围、问题集和字符预算。按预期文件逐条比较返回证据,同时对比最初基线和最近采用的版本;完整 MCP 返回保留在公开发布包之外。分别测量目标章节进入候选集的比例,以及打包后保留的证据。
|
|
93
|
+
|
|
94
|
+
新问题在实施前固定,仅用于验证,并说明来源。依据同一语料由维护者编写的新题,不能证明独立用户的使用效果。保留严格字符串评分;接受等价措辞时应明确列出。除完整命中题数外,还应逐条报告证据增加和丢失。固定集的证据分数不代表模型最终答案正确率。
|
|
95
|
+
|
|
96
|
+
## 可重复的性能样本
|
|
97
|
+
|
|
98
|
+
安装依赖后运行 `npm run baseline:performance -- 100,500`。脚本生成独立的合成文档集,索引 local-hash 向量、修改一个文档,测量全量/增量索引以及卡片、context、语义查询耗时。查询先预热一次,再报告五次采样的中位数。内存是操作后的进程 heap/RSS,不是峰值分配。JSON 包含运行时、平台、文档规模、记录计数和保留的样本路径。这些结果用于工程比较,不代表真实代理效果或生产大规模性能。
|
|
99
|
+
|
|
100
|
+
## Knowledge/Wiki 输出基线
|
|
101
|
+
|
|
102
|
+
运行 `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` 分别记录真实使用说明和验收结果;它们的验收与单元测试通过分开报告。
|
package/docs/ZH/Operations.md
CHANGED
|
@@ -38,6 +38,8 @@ mdgraph watch --path /path/to/project
|
|
|
38
38
|
mdgraph serve --mcp --path /path/to/project
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
原生 Markdown 变更事件会与最近一次成功索引保存的文件内容哈希比较。文件内容相同不会再次触发索引回调;真实修改、新增、删除和配置变更仍按原有流程更新。索引运行期间收到的事件会在本次索引结束后检查。
|
|
42
|
+
|
|
41
43
|
Watcher 通过 `WatchHandle.getHealth()` 暴露进程内 health snapshot。集成 MCP serving 会把它加入 `mdgraph_status.structuredContent.watchHealth`。
|
|
42
44
|
|
|
43
45
|
| 状态 | 含义 | 运维动作 |
|
|
@@ -89,3 +91,23 @@ mdgraph semantic status --path /path/to/project
|
|
|
89
91
|
- `.mdgraph/config.json` 不含凭据时可以跟踪;MDGraph 会拒绝 endpoint URL 中嵌入的凭据。
|
|
90
92
|
- 结构化交换应使用已记录的 GraphJSON,不要依赖 SQLite 内部结构。
|
|
91
93
|
- 发布 MDGraph 本身前,运行[发布清单](Release_Checklist.md),检查 `npm pack --dry-run --json`,并实际验证 packed package,不要假设仓库内容等同于 npm 内容。
|
|
94
|
+
|
|
95
|
+
## 服务目录与嵌入请求超时
|
|
96
|
+
|
|
97
|
+
MCP 按项目目录、配置和 SQLite 存储的实际文件目标检查访问范围。指向服务目录内部的链接仍可使用,也可以通过目录链接启动服务。访问外部项目时,请使用该项目的 `--path` 单独启动服务;服务目录内的链接不会自动授权访问外部目标。
|
|
98
|
+
|
|
99
|
+
`embedding.timeoutMs` 覆盖响应头与完整正文读取,包括错误响应。超时后 search/context 回退到全文与图谱检索;索引失败保留原有图谱。服务恢复后可以重试。
|
|
100
|
+
|
|
101
|
+
## 增量一致性与监听配置
|
|
102
|
+
|
|
103
|
+
索引在 SQLite 元数据中记录提取配置和提交版本。提取设置变化会重建相关图谱,纯查询设置不触发重建。增量更新根据全部已解析文档协调确定性关系,因此未修改文档的别名歧义也会更新。内容与 provider/model/dimensions 匹配的向量会复用。显式全量重建清除派生关系;提取配置引发的自动重建在向量配置不变时保留未受影响的派生关系。
|
|
104
|
+
|
|
105
|
+
并发提交发现索引版本变化时重新扫描一次,持续冲突会明确报错,可稍后重试。解析失败保留该文档原有图谱,报告跳过文件,并将未完成的配置重建留待重试。修复对应 Markdown 并重新索引后再依赖其内容。
|
|
106
|
+
|
|
107
|
+
Watch 会重载配置和 `.gitignore` 规则,包括 MDX 开关。新监听器就绪后再关闭旧监听器。配置暂时无效时保留原监听并报告 degraded;修复配置后自动重试恢复。
|
|
108
|
+
|
|
109
|
+
## Node.js 构建要求
|
|
110
|
+
|
|
111
|
+
运行时需要具备启用 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 的构建仍可使用。
|
|
112
|
+
|
|
113
|
+
早期运行时 CI 只验证 SQLite 兼容行为与缺失能力的恢复提示,不代表标准 Node 22.5.0 可运行全部产品功能。Windows 由 CI 验证,跨平台发布前应检查对应提交的运行结果。
|