@daogee/mdgraph 1.0.0 → 1.1.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.
- package/CHANGELOG.md +22 -0
- package/README-ZH.md +54 -2
- package/README.md +73 -21
- package/dist/bin/mdgraph.js +136 -19
- package/dist/config/limits.d.ts +2 -0
- package/dist/config/limits.js +3 -1
- package/dist/config/load-config.js +8 -2
- package/dist/db/repositories.d.ts +27 -0
- package/dist/db/repositories.js +310 -6
- package/dist/evaluation/context-packing-evaluation.d.ts +29 -0
- package/dist/evaluation/context-packing-evaluation.js +134 -0
- package/dist/evaluation/entity-extraction-evaluation.d.ts +38 -0
- package/dist/evaluation/entity-extraction-evaluation.js +118 -0
- package/dist/evaluation/historical-baseline.d.ts +70 -0
- package/dist/evaluation/historical-baseline.js +278 -0
- package/dist/evaluation/related-documents-evaluation.d.ts +26 -0
- package/dist/evaluation/related-documents-evaluation.js +163 -0
- package/dist/evaluation/retrieval-eval.d.ts +14 -5
- package/dist/evaluation/retrieval-eval.js +44 -6
- package/dist/evaluation/structured-query-evaluation.d.ts +27 -0
- package/dist/evaluation/structured-query-evaluation.js +156 -0
- package/dist/extraction/entity-extractor.js +42 -22
- package/dist/extraction/graph-builder.js +2 -18
- package/dist/index.d.ts +17 -4
- package/dist/index.js +9 -4
- package/dist/indexer.js +20 -2
- package/dist/mcp/server.d.ts +4 -0
- package/dist/mcp/server.js +16 -7
- package/dist/mcp/tools.d.ts +5 -1
- package/dist/mcp/tools.js +93 -9
- package/dist/parser/markdown-parser.js +2 -0
- package/dist/query/context-builder.d.ts +31 -2
- package/dist/query/context-builder.js +162 -12
- package/dist/query/search.d.ts +5 -1
- package/dist/query/search.js +77 -13
- package/dist/query/structured-query-executor.d.ts +28 -0
- package/dist/query/structured-query-executor.js +138 -0
- package/dist/query/structured-query.d.ts +50 -0
- package/dist/query/structured-query.js +390 -0
- package/dist/relationships/derive-related.d.ts +86 -0
- package/dist/relationships/derive-related.js +322 -0
- package/dist/reporting/report.js +2 -2
- package/dist/semantic/embed-chunks.d.ts +2 -0
- package/dist/semantic/embed-chunks.js +31 -0
- package/dist/semantic/ollama-provider.d.ts +6 -0
- package/dist/semantic/ollama-provider.js +131 -0
- package/dist/semantic/provider-registry.d.ts +8 -0
- package/dist/semantic/provider-registry.js +66 -0
- package/dist/semantic/provider.d.ts +35 -0
- package/dist/semantic/provider.js +29 -0
- package/dist/semantic/status.d.ts +6 -1
- package/dist/semantic/status.js +49 -3
- package/dist/types.d.ts +7 -2
- package/dist/types.js +2 -1
- package/dist/watcher/file-watcher.d.ts +4 -0
- package/dist/watcher/file-watcher.js +75 -10
- package/dist/watcher/watch-health.d.ts +34 -0
- package/dist/watcher/watch-health.js +75 -0
- package/docs/EN/Agent_Integration.md +1 -1
- package/docs/EN/Architecture.md +39 -16
- package/docs/EN/Evaluation_Questions.md +21 -5
- package/docs/EN/Operations.md +91 -0
- package/docs/EN/Output_Contracts.md +41 -7
- package/docs/EN/Public_Contracts.md +23 -16
- package/docs/EN/Public_Contracts_1.0.md +28 -18
- package/docs/EN/README.md +23 -0
- package/docs/EN/Release_Checklist.md +26 -13
- package/docs/EN/Retrieval_and_Context.md +112 -0
- package/docs/EN/Structured_Query_and_Relationships.md +111 -0
- package/docs/ZH/Agent_Integration.md +1 -1
- package/docs/ZH/Architecture.md +39 -19
- package/docs/ZH/Evaluation_Questions.md +22 -6
- package/docs/ZH/Operations.md +91 -0
- package/docs/ZH/Output_Contracts.md +41 -7
- package/docs/ZH/Public_Contracts.md +22 -15
- package/docs/ZH/Public_Contracts_1.0.md +27 -17
- package/docs/ZH/README.md +23 -0
- package/docs/ZH/Release_Checklist.md +26 -13
- package/docs/ZH/Retrieval_and_Context.md +112 -0
- package/docs/ZH/Structured_Query_and_Relationships.md +111 -0
- package/package.json +44 -18
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Operations
|
|
3
|
+
type: runbook
|
|
4
|
+
status: active
|
|
5
|
+
defines:
|
|
6
|
+
- MDGraphOperations
|
|
7
|
+
source_refs:
|
|
8
|
+
- src/indexer.ts
|
|
9
|
+
- src/watcher/file-watcher.ts
|
|
10
|
+
- src/watcher/watch-health.ts
|
|
11
|
+
- src/semantic/status.ts
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# Operations
|
|
15
|
+
|
|
16
|
+
This guide covers index freshness, watch coverage, semantic-provider recovery, and local artifact safety for long-running MDGraph use.
|
|
17
|
+
|
|
18
|
+
## Index and Freshness Checks
|
|
19
|
+
|
|
20
|
+
Use explicit status checks before relying on an unfamiliar or long-running project index:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
mdgraph status --freshness --path /path/to/project
|
|
24
|
+
mdgraph status --storage --path /path/to/project
|
|
25
|
+
mdgraph doctor --path /path/to/project
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`status --freshness` compares current Markdown files with indexed paths and hashes. A `stale` result means query results may reflect older graph state; run `mdgraph index`. Doctor health predicates and derived-relationship generation require a fresh index and refuse mixed-time conclusions.
|
|
29
|
+
|
|
30
|
+
Incremental indexing updates changed and deleted documents, their FTS records, vectors, and connected derived edges. Use `index --full` when the embedding profile changes, when storage needs rebuild/compaction, or when a clean reconstruction is operationally preferable.
|
|
31
|
+
|
|
32
|
+
## Watch Modes
|
|
33
|
+
|
|
34
|
+
Standalone watch mode and integrated MCP serving keep the index current:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
mdgraph watch --path /path/to/project
|
|
38
|
+
mdgraph serve --mcp --path /path/to/project
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The watcher exposes an in-process health snapshot through `WatchHandle.getHealth()`. Integrated MCP serving adds it to `mdgraph_status.structuredContent.watchHealth`.
|
|
42
|
+
|
|
43
|
+
| State | Meaning | Operator action |
|
|
44
|
+
|---|---|---|
|
|
45
|
+
| `starting` | Watch registration or initial setup is in progress. | Wait for healthy state or startup failure. |
|
|
46
|
+
| `healthy` | Registration is active and the latest index attempt succeeded. | No action. |
|
|
47
|
+
| `degraded` | Indexing failed, or native watch coverage is no longer reliable. | Inspect the last error; reindex or restart after fixing the cause. |
|
|
48
|
+
| `failed` | Startup could not establish reliable watch coverage. | Fix the reported error before relying on watch mode. |
|
|
49
|
+
|
|
50
|
+
The snapshot includes last successful index time, last error, failure phase and normalized code, consecutive indexing failures, coverage reliability, polling state, and closure state. It lasts for the watcher process; restart creates a new health lifecycle.
|
|
51
|
+
|
|
52
|
+
Startup registration errors are fatal. A later successful index can recover an indexing failure. Runtime watch errors such as `ENOSPC` or `EMFILE` set `coverageReliable: false`; a successful manual or triggered index does not prove missed native events are recovered, so health remains degraded until restart.
|
|
53
|
+
|
|
54
|
+
## Polling Fallback
|
|
55
|
+
|
|
56
|
+
Native filesystem events are the default. If operating-system watch limits cannot be raised or native events are unreliable, explicitly enable polling:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
mdgraph watch --poll --path /path/to/project
|
|
60
|
+
mdgraph serve --mcp --watch-poll --path /path/to/project
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Polling is never activated automatically because it can increase I/O and CPU use. Prefer fixing the operating-system resource limit for large, long-running repositories when possible; use polling when that is not under your control.
|
|
64
|
+
|
|
65
|
+
## Semantic Provider Recovery
|
|
66
|
+
|
|
67
|
+
Check provider and vector state with:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
mdgraph semantic status --path /path/to/project
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
| Condition | Query behavior | Recovery |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| Provider unavailable, timeout, or invalid response | Search/context fall back to FTS5/entity/graph and report `semanticDiagnostic`. | Restore the service/model, then retry; the lexical result remains usable. |
|
|
76
|
+
| Provider/model/dimensions changed | Status reports that reindexing is needed. | Run `mdgraph index --full --semantic`. |
|
|
77
|
+
| Semantic indexing fails | The existing graph remains intact because embedding completes before mutation. | Fix the provider and rerun indexing. |
|
|
78
|
+
| Vector coverage is incomplete | Semantic queries degrade; relationship derivation refuses mutation. | Rebuild a complete semantic index. |
|
|
79
|
+
|
|
80
|
+
`local-hash` does not require an external service, but it is only a lexical feature hash. It cannot satisfy semantic-model gates for derived relationships.
|
|
81
|
+
|
|
82
|
+
## Derived Relationship Refresh
|
|
83
|
+
|
|
84
|
+
Derived `RELATED_TO` edges are disposable, non-authoritative state. Changes to a document remove touching derived edges; a full rebuild removes all of them. After a successful full semantic index, run a dry derivation and then explicitly refresh the layer if desired. See [Structured Query and Relationships](Structured_Query_and_Relationships.md#derived-related-document-relationships).
|
|
85
|
+
|
|
86
|
+
## Local and Release Artifacts
|
|
87
|
+
|
|
88
|
+
- Keep `.mdgraph/graph.db`, bundles, reports containing local paths, and private evaluation corpora out of source control and release archives.
|
|
89
|
+
- Keep `.mdgraph/config.json` trackable when it contains no credentials; endpoint URLs with embedded credentials are rejected.
|
|
90
|
+
- Use GraphJSON for the documented structural exchange format instead of depending on SQLite internals.
|
|
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.
|
|
@@ -62,9 +62,12 @@ The text form prints the same workflow groups for humans. `usage` does not read
|
|
|
62
62
|
|
|
63
63
|
- `query`, `limit`, `queryMode`, `entityCandidates`, `ftsQuery`, `semanticEnabled`, and `semanticActive`.
|
|
64
64
|
- `ranking`: `fusion`, `fusionK`, `channels`, and `optionalReranker`.
|
|
65
|
+
- `semanticDiagnostic`: optional provider fallback details with `code`, `provider`, `message`, and `degraded: true`.
|
|
65
66
|
- `matchedEntities`: entity names, kinds, and document frequencies used by ranking diagnostics.
|
|
66
67
|
- `results`: the same search result records returned by `search --json`.
|
|
67
68
|
|
|
69
|
+
When semantic retrieval is requested but cannot run, `search` still returns FTS5/entity/graph results. The CLI writes the fallback diagnostic to stderr so the non-explain `search --json` array remains compatible.
|
|
70
|
+
|
|
68
71
|
## `context --json`
|
|
69
72
|
|
|
70
73
|
`mdgraph context <query> --json` returns:
|
|
@@ -72,6 +75,8 @@ The text form prints the same workflow groups for humans. `usage` does not read
|
|
|
72
75
|
- `query`: original query text.
|
|
73
76
|
- `maxChars`: configured context budget.
|
|
74
77
|
- `usedChars`: packed character count.
|
|
78
|
+
- `packing`: additive packing metadata with `strategy`; opt-in MMR also reports `similarity`, `mmrLambda`, and optional `redundancySkippedItems`.
|
|
79
|
+
- `semanticDiagnostic`: optional provider fallback details; absent when semantic retrieval was not requested or completed normally.
|
|
75
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`.
|
|
76
81
|
|
|
77
82
|
`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,8 +88,36 @@ The text form prints the same workflow groups for humans. `usage` does not read
|
|
|
83
88
|
- `seedNodes`, `visitedNodes`, and `expandedEdges`.
|
|
84
89
|
- `skippedVisitedNodes`, `skippedByNodeLimit`, and `skippedByDepth`.
|
|
85
90
|
- `candidateCount`, `directCandidates`, and `expandedCandidates`.
|
|
86
|
-
- `packingStrategy`, `packedItems`, `packedUniqueDocuments`, and `packingDiversityRatio`.
|
|
87
|
-
- `budgetTruncatedItems` and `
|
|
91
|
+
- `packingStrategy`, optional `packingSimilarity`, optional `mmrLambda`, optional per-item `packingSelections`, `packedItems`, `packedUniqueDocuments`, and `packingDiversityRatio`. Each MMR selection reports `nodeId`, `path`, `queryRelevance`, `redundancyPenalty`, `mmrScore`, and `similaritySource`.
|
|
92
|
+
- `budgetTruncatedItems`, `budgetSkippedItems`, and optional `redundancySkippedItems`.
|
|
93
|
+
|
|
94
|
+
The compatibility default is `mmr-style-document-round-robin`. `--packing mmr` is opt-in and may be tuned with `--mmr-lambda <0..1>`; missing stored vectors fall back to deterministic lexical Jaccard similarity.
|
|
95
|
+
|
|
96
|
+
## `query --json` (experimental)
|
|
97
|
+
|
|
98
|
+
`mdgraph query <expression> --json` returns:
|
|
99
|
+
|
|
100
|
+
- `query`: original structured expression.
|
|
101
|
+
- `ast`: validated expression tree plus `orderBy` and `limit`.
|
|
102
|
+
- `execution`: `strategy` (`parameterized-sql` or `parameterized-hybrid-doctor`), ordered `stages`, `parameterCount`, and `doctorHealthEvaluated`.
|
|
103
|
+
- `total`, `returned`, and `truncated`: match and limit diagnostics.
|
|
104
|
+
- `items`: entries with `document`, `reason`, `predicateFields`, and execution `provenance`.
|
|
105
|
+
|
|
106
|
+
`document` follows `GraphDocument`, including optional `updatedAt`, which is the source Markdown mtime captured during indexing. Health predicates fail when the index is stale. This output is experimental and may evolve without changing the stable `search` contract.
|
|
107
|
+
|
|
108
|
+
## `relationships derive --json` (experimental)
|
|
109
|
+
|
|
110
|
+
`mdgraph relationships derive --json` returns:
|
|
111
|
+
|
|
112
|
+
- `algorithmVersion`, `generatedAt`, `provider`, `model`, and `dimensions`.
|
|
113
|
+
- `options`: effective `threshold`, `maxNeighbors`, `minEvidence`, and `dryRun`.
|
|
114
|
+
- `qualityGate`: gate ID, `passed`, and named runtime checks.
|
|
115
|
+
- `corpus`: document/chunk/vector coverage, sampling, pair-evaluation, and vector-comparison diagnostics.
|
|
116
|
+
- `relationships`: canonical document pairs with confidence and independent chunk/section evidence.
|
|
117
|
+
- `relationshipPairs` and `directedEdges`.
|
|
118
|
+
- `mutation`: `dryRun`, `removed`, and `inserted` counts.
|
|
119
|
+
|
|
120
|
+
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.
|
|
88
121
|
|
|
89
122
|
## `node --json`
|
|
90
123
|
|
|
@@ -113,14 +146,14 @@ When no node is found, it returns:
|
|
|
113
146
|
|
|
114
147
|
- `querySet`: `alpha` by default or `cjk` when `--query-set cjk` is provided.
|
|
115
148
|
- `limit`: search result limit used per case.
|
|
116
|
-
- `ranking`: query mode, RRF search fusion, context packing strategy, optional reranker status, semantic-active case count, search channels, ranking reason coverage,
|
|
149
|
+
- `ranking`: query mode, RRF search fusion, context packing strategy, optional reranker status, semantic-active case count, search channels, ranking reason coverage, average context diversity, and optional deduplicated `semanticDiagnostics`.
|
|
117
150
|
- `generatedAt`: ISO timestamp for the evaluation run.
|
|
118
151
|
- `summary`: `cases`, `passed`, `failed`, `averageTopKDocumentRecall`, `averageExpectedSectionRecall`, `averageContextPrecision`, `averageContextDiversity`, `averageLatencyMs`, and `averageReturnedChars`.
|
|
119
152
|
- `cases`: per-case results with `id`, `query`, `passed`, `expected`, `observed`, and `metrics`.
|
|
120
153
|
|
|
121
|
-
Per-case `expected` includes expected documents, sections, entities, edge kinds, and source refs. Per-case `observed` includes ranked search document paths, context item paths/headings/reasons, matched entities, resolved entities, resolved source refs, observed edge kinds, optional trace results, and ranking diagnostics
|
|
154
|
+
Per-case `expected` includes expected documents, sections, entities, edge kinds, and source refs. Per-case `observed` includes ranked search document paths, context item paths/headings/reasons, matched entities, resolved entities, resolved source refs, observed edge kinds, optional trace results, and ranking diagnostics with an optional `semanticDiagnostic`. Per-case `metrics` includes top-K document recall, expected-section recall, context precision, entity recall, source-ref recall, edge-kind coverage, trace success, latency, returned characters, budget fit, fanout, reason coverage, ranking reason coverage, and context diversity.
|
|
122
155
|
|
|
123
|
-
`mdgraph eval --path <project> --json` evaluates an explicit local project path. It does not add MCP tools and does not index automatically; run `mdgraph index` first for the target project. `mdgraph eval --query-set cjk --path <project> --json` uses repository-owned Chinese/Japanese expected records to measure CJK retrieval quality with the lightweight CJK n-gram preprocessing baseline. `mdgraph eval --query-mode semantic --json` requests optional semantic search and reports whether the
|
|
156
|
+
`mdgraph eval --path <project> --json` evaluates an explicit local project path. It does not add MCP tools and does not index automatically; run `mdgraph index` first for the target project. `mdgraph eval --query-set cjk --path <project> --json` uses repository-owned Chinese/Japanese expected records to measure CJK retrieval quality with the lightweight CJK n-gram preprocessing baseline. `mdgraph eval --query-mode semantic --json` requests optional semantic search and reports whether the configured semantic provider was active.
|
|
124
157
|
|
|
125
158
|
## `export graphjson --json`
|
|
126
159
|
|
|
@@ -144,7 +177,7 @@ The structural profile excludes chunks, chunk content, section content, vectors,
|
|
|
144
177
|
- `warnings`: non-fatal compatibility notes.
|
|
145
178
|
- `format`, `formatVersion`, `schemaVersion`, `graphHash`, `counts`, and `exportedCounts` when readable.
|
|
146
179
|
|
|
147
|
-
The command exits non-zero when `valid` is `false`. GraphJSON merge import is not supported
|
|
180
|
+
The command exits non-zero when `valid` is `false`. GraphJSON merge import is not supported. Oversized or deeply nested GraphJSON files are rejected before verification.
|
|
148
181
|
|
|
149
182
|
## `export mermaid trace --json`
|
|
150
183
|
|
|
@@ -188,7 +221,7 @@ The bridge reads only an explicit MDGraph JSON artifact with a `files` array con
|
|
|
188
221
|
- `manifestPath`: absolute path to `manifest.json`.
|
|
189
222
|
- `manifest`: bundle manifest with `format`, `formatVersion`, `schemaVersion`, `mdgraphVersion`, `createdAt`, `visibility`, `sourceHash`, `configHash`, `provenance`, `counts`, `documents`, and optional `reports`.
|
|
190
223
|
|
|
191
|
-
The private bundle contains `manifest.json`, `graph.db`, `config.json`, and a `reports/status-storage.json` snapshot. `sourceHash` is derived from canonical config plus sorted document path/hash records; it does not include Markdown body content or the absolute project root. Public or sanitized bundle profiles are not supported
|
|
224
|
+
The private bundle contains `manifest.json`, `graph.db`, `config.json`, and a `reports/status-storage.json` snapshot. `sourceHash` is derived from canonical config plus sorted document path/hash records; it does not include Markdown body content or the absolute project root. Public or sanitized bundle profiles are not supported.
|
|
192
225
|
|
|
193
226
|
## `bundle verify --json`
|
|
194
227
|
|
|
@@ -254,6 +287,7 @@ Diff only compares Markdown graph records, source refs, and doctor warning codes
|
|
|
254
287
|
- `projectRoot`.
|
|
255
288
|
- `state`: `disabled`, `not_indexed`, `ready`, `unsupported_provider`, or `needs_reindex`.
|
|
256
289
|
- `enabled`, `provider`, `model`, `dimensions`, and `providerSupported` for the configured embedding provider.
|
|
290
|
+
- `capability`: `lexical-hash`, `semantic-model`, or `unknown`; `runtimeStatus`: `available`, `unavailable`, `model_missing`, `unchecked`, or `disabled`; optional `runtimeReason` when a runtime check fails.
|
|
257
291
|
- `indexed`, `chunks`, `vectors`, `vectorStorageFormat`, and `indexedProviders`.
|
|
258
292
|
- `guidance`: actionable next steps such as running `mdgraph index --semantic`, re-embedding after provider changes, or falling back to FTS5 and graph search for unsupported providers.
|
|
259
293
|
|
|
@@ -7,13 +7,13 @@ source_refs:
|
|
|
7
7
|
|
|
8
8
|
# MDGraph Public Contracts
|
|
9
9
|
|
|
10
|
-
This document records the public contract boundary for the current `1.0.0`
|
|
10
|
+
This document records the public contract boundary for the current release line, anchored to the frozen `1.0.0` compatibility baseline. It complements [Output_Contracts.md](Output_Contracts.md), [Architecture.md](Architecture.md), and [Release_Checklist.md](Release_Checklist.md). The full per-command, per-format, per-config, and per-schema inventory lives in the [1.0 Contract Freeze Appendix](Public_Contracts_1.0.md).
|
|
11
11
|
|
|
12
12
|
## Stability Labels
|
|
13
13
|
|
|
14
14
|
- `stable`: users and agents may rely on this shape. Additive fields are allowed; removing or renaming documented fields is a breaking change after 1.0.
|
|
15
15
|
- `stable-additive`: existing fields and semantics are stable, and the surface may gain optional fields or metrics when old consumers remain valid.
|
|
16
|
-
- `experimental`: available
|
|
16
|
+
- `experimental`: available without a stable compatibility promise; semantics may be adjusted with changelog notes, migration guidance where needed, and focused tests.
|
|
17
17
|
- `reserved`: named for future use, but not active until an emitter or workflow is documented and tested.
|
|
18
18
|
- `internal`: implementation detail. It may change without compatibility guarantees.
|
|
19
19
|
|
|
@@ -22,27 +22,34 @@ This document records the public contract boundary for the current `1.0.0` publi
|
|
|
22
22
|
| Surface | Status | Owner | Contract |
|
|
23
23
|
|---|---|---|---|
|
|
24
24
|
| Package root JavaScript/TypeScript exports | experimental | `src/index.ts`, `package.json` | The package root exposes the documented ESM entry point and matching TypeScript declarations. Individual helper exports remain experimental unless another row explicitly freezes their behavior or record shape. |
|
|
25
|
-
| CLI command names and documented flags | stable | `src/bin/mdgraph.ts` | `usage`, `init`, `index`, `status`, `search`, `context`, `node`, `trace`, `eval`, `semantic status`, `bundle create/verify`, `export`, `import graphjson --verify`, `diff`, `report`, `serve --mcp`, `watch`, and `doctor`. Project-related commands support additive `--path <project>` where applicable. `
|
|
25
|
+
| CLI command names and documented flags | stable | `src/bin/mdgraph.ts` | `usage`, `init`, `index`, `status`, `search`, `context`, `node`, `trace`, `eval`, `semantic status`, `bundle create/verify`, `export`, `import graphjson --verify`, `diff`, `report`, `serve --mcp`, `watch`, and `doctor`. Project-related commands support additive `--path <project>` where applicable. `context` adds optional `--packing` and `--mmr-lambda`; `serve --mcp` adds explicit `--watch-poll`; `watch` adds explicit `--poll`. `status --freshness` remains additive without changing the default `status --json` shape. |
|
|
26
26
|
| Project-wide `--path` for project-related commands | stable-additive | `src/bin/mdgraph.ts` | Project-related commands (`init`, `index`, `status`, `search`, `context`, `node`, `trace`, `eval`, `semantic status`, `bundle create/verify`, `export`, `import graphjson --verify`, `diff`, `report`, `serve --mcp`, `watch`, `doctor`, and `usage`) accept an additive `--path <project>` flag so agents and scripts can target a repository without changing the shell cwd. |
|
|
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
|
+
| 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
|
+
| 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. |
|
|
28
30
|
| `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. |
|
|
29
|
-
| `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`,
|
|
30
|
-
| 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 marked otherwise. |
|
|
31
|
+
| `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. |
|
|
31
33
|
| 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. |
|
|
32
34
|
| 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
|
+
| 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`. |
|
|
36
|
+
| Context packing selection | stable-additive | `src/query/context-builder.ts`, `src/mcp/tools.ts` | Existing callers retain `mmr-style-document-round-robin`. CLI `--packing mmr`, MCP `mdgraph_context.packingStrategy`, and library options select true MMR. Context output adds `packing`; debug output adds similarity, lambda, selection scores, and redundancy skip diagnostics. |
|
|
37
|
+
| Watch health and polling | stable-additive | `src/watcher/file-watcher.ts`, `src/watcher/watch-health.ts`, `src/mcp/tools.ts` | `WatchHandle.getHealth()` exposes in-process state, timestamps, last error, coverage reliability, polling, and closure. Integrated MCP status may add `structuredContent.watchHealth`. Polling is enabled only by `watch --poll`, `serve --mcp --watch-poll`, or `usePolling: true`. |
|
|
38
|
+
| 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
|
+
| 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. |
|
|
33
40
|
| MCP text output wording | experimental | `src/mcp/tools.ts` | Text is human-facing guidance; `structuredContent` is the preferred machine contract. |
|
|
34
41
|
| 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. |
|
|
35
|
-
| `.mdgraph/config.json` fields | stable | `src/config/load-config.ts` | `docs`, `index`, `search`, `entities`, and `embedding` default fields are stable. Unknown fields are currently ignored by merge logic. |
|
|
42
|
+
| `.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. |
|
|
36
43
|
| `.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. |
|
|
37
44
|
| 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. |
|
|
38
45
|
| SQLite table internals | internal | `src/db/schema.sql` | Rowids, FTS shadow tables, vector blob representation internals, and private bundle database contents are not public API. |
|
|
39
46
|
| Public graph record types | stable | `src/types.ts` | `GraphDocument`, `GraphSection`, `GraphEntity`, `SourceRef`, `GraphEdge`, `GraphChunk`, `ChunkVector`, `SearchResult`, and `TraceStep`. |
|
|
40
|
-
| Edge kinds | stable/reserved | `src/types.ts` |
|
|
47
|
+
| Edge kinds | stable/experimental/reserved | `src/types.ts` | Existing explicit edge kinds are stable. `RELATED_TO` is an experimental opt-in derived kind identified by `DERIVED_EDGE_KINDS`; `SAME_AS` and `CONTRADICTS` remain reserved until separate emitters are documented and tested. |
|
|
41
48
|
| Doctor warning shape | stable | `src/analysis/doctor.ts` | Warnings include `code`, `severity`, `message`, `evidence`, `affectedNodes`, and `remediation`. Warning codes are versioned by changelog and tests. |
|
|
42
49
|
| GraphJSON export and verify | stable format v1 | `src/export/graphjson.ts` | `format: "mdgraph-graphjson"`, `formatVersion: 1`, structural profile, deterministic ordering, and `graphHash` verification. |
|
|
43
50
|
| Bundle manifest | experimental | `src/bundle/bundle.ts` | `formatVersion: 1` private workflow artifact. It is not a public sanitized exchange format. |
|
|
44
|
-
| Report, diff, and benchmark JSON | experimental | `src/reporting`, `src/diff`, `src/benchmark` | CI-facing workflow outputs; required top-level fields are documented, but detailed metrics may expand
|
|
45
|
-
| Semantic vector provider behavior | experimental | `src/semantic/*` |
|
|
51
|
+
| Report, diff, and benchmark JSON | experimental | `src/reporting`, `src/diff`, `src/benchmark` | CI-facing workflow outputs; required top-level fields are documented, but detailed metrics may expand while the surface remains experimental. |
|
|
52
|
+
| Semantic vector provider behavior | experimental | `src/semantic/*` | `local-hash` remains a `lexical-hash` compatibility provider; Ollama is the first opt-in `semantic-model` provider. External providers run only through async indexing/query APIs and must degrade queries to FTS5/graph search with diagnostics when unavailable or unsupported. Explicit indexing failures must not commit partial graph/vector updates. |
|
|
46
53
|
|
|
47
54
|
## Compatibility Policy
|
|
48
55
|
|
|
@@ -66,23 +73,23 @@ This document records the public contract boundary for the current `1.0.0` publi
|
|
|
66
73
|
|
|
67
74
|
## Release Matrix
|
|
68
75
|
|
|
69
|
-
|
|
76
|
+
Every release must preserve the stable 1.0 baseline and validate all `stable-additive` surfaces, including `usage`, project-wide `--path`, `status --freshness`, MCP freshness metadata, context recovery fields, optional context packing, watch health, and default fresh MCP serving. Experimental structured query, semantic-provider, and derived-relationship behavior must remain explicitly labeled and covered by focused tests.
|
|
70
77
|
|
|
71
78
|
Before a release that changes public surfaces:
|
|
72
79
|
|
|
73
|
-
- Run `npm run typecheck`, focused contract tests, `npm test`, `npm run build`, `npm run smoke:cli`, `npm run smoke:eval`, `npm run smoke:pack`, `npm run task:public-check`, and `git diff --check`.
|
|
80
|
+
- Run `npm run docs:check`, `npm run typecheck`, focused contract tests, `npm test`, `npm run build`, `npm run smoke:cli`, `npm run smoke:eval`, `npm run smoke:pack`, `npm run task:public-check`, and `git diff --check`.
|
|
74
81
|
- Run `npm pack --dry-run` when package metadata or included public docs change.
|
|
75
82
|
- Validate on Node.js `>=22.5.0`; the regular development baseline is the current Node 22.x line.
|
|
76
|
-
- Treat Linux and Windows full CI as the release-gate baseline, and keep macOS covered by CI smoke for build-output CLI and packed-artifact behavior
|
|
83
|
+
- Treat Linux and Windows full CI as the release-gate baseline, and keep macOS covered by CI smoke for build-output CLI and packed-artifact behavior.
|
|
77
84
|
- Use release maintainer smoke, not CI, for platform-specific long-running surfaces such as `serve --mcp` and `watch`.
|
|
78
85
|
- Keep any external-corpus evaluation data outside the public repository unless it is independently licensed and intentionally adopted as a public fixture.
|
|
79
86
|
|
|
80
|
-
##
|
|
87
|
+
## Release Readiness
|
|
81
88
|
|
|
82
|
-
|
|
89
|
+
A release is ready only after:
|
|
83
90
|
|
|
84
|
-
- The ledger above is
|
|
91
|
+
- The ledger above is current for every touched public surface.
|
|
85
92
|
- Critical public shapes are protected by focused tests or smoke gates.
|
|
86
93
|
- Experimental and internal surfaces are explicitly labeled in docs.
|
|
87
|
-
- Known output-shape inconsistencies are either normalized or intentionally documented.
|
|
94
|
+
- Known output-shape inconsistencies are either normalized or intentionally documented in the release.
|
|
88
95
|
- The release checklist can catch accidental public contract drift.
|
|
@@ -2,19 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Status: active
|
|
4
4
|
Created: 2026-07-09
|
|
5
|
-
Companion to: [Public_Contracts.md](Public_Contracts.md) and [Output_Contracts.md](Output_Contracts.md)
|
|
6
|
-
Task: 2026-06-27-roadmap-1-0-contract-freeze
|
|
5
|
+
Companion to: [Public_Contracts.md](Public_Contracts.md) and [Output_Contracts.md](Output_Contracts.md)
|
|
7
6
|
|
|
8
7
|
This appendix is the authoritative inventory of the MDGraph public surface
|
|
9
8
|
frozen for the `1.0.0` release. It supplements the [Public Contracts](Public_Contracts.md)
|
|
10
9
|
ledger with the full per-command, per-format, per-config, per-schema
|
|
11
10
|
details that the ledger summarizes.
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
`docs/tasks/2026-06-27-roadmap-1-0-contract-freeze/`, which stays ignored
|
|
15
|
-
and is not a GitHub deliverable.
|
|
16
|
-
|
|
17
|
-
## Freeze Baseline
|
|
12
|
+
## Freeze Baseline
|
|
18
13
|
|
|
19
14
|
- Package version: `1.0.0`
|
|
20
15
|
- SQLite `schemaVersion`: `1`
|
|
@@ -50,7 +45,7 @@ semantics are stricter.
|
|
|
50
45
|
| `index` | none | `index --json` returns `files`, `changed`, `deleted`, `unchanged`, `skipped`, `skippedFiles`, `mode`, `counts` | progress summary | `--semantic` and `--full` are `stable-additive` |
|
|
51
46
|
| `status` | none | `status --json` returns graph counts; `--storage` adds `storage`; `--freshness` adds `freshness` | counts summary | `--freshness` is `stable-additive` |
|
|
52
47
|
| `search` | `<query>` | `search --json` returns `document`, optional `section`, `score`, `reason`, `content`, `matchedEntities`, optional `semantic`; `--explain` adds `query`, `limit`, `queryMode`, `entityCandidates`, `ftsQuery`, `semanticEnabled`, `semanticActive`, `ranking`, `matchedEntities`, `results` | text list | `--explain`, `--semantic`, `--limit` are `stable-additive` |
|
|
53
|
-
| `context` | `<query>` | `context --json` returns `query`, `maxChars`, `usedChars`, `items`; each item carries `nodeId`, `documentId`, optional `sectionId`, optional `anchor`, `path`, `title`, optional `heading`, optional `lines`, `reason`, `matchedEntities`, optional `edgePath` (with `fromId`, `fromLabel`, `edgeFromId`, `edgeToId`, `edgeKind`, `toId`, `toLabel`, `traversalDirection`, `confidence`, `provenance`), optional `sourceRefs`, optional `riskNotes`, and `content`; `--debug` adds `debug` | text context summary | recovery fields are `stable-additive` |
|
|
48
|
+
| `context` | `<query>` | `context --json` returns `query`, `maxChars`, `usedChars`, additive `packing`, and `items`; each item carries `nodeId`, `documentId`, optional `sectionId`, optional `anchor`, `path`, `title`, optional `heading`, optional `lines`, `reason`, `matchedEntities`, optional `edgePath` (with `fromId`, `fromLabel`, `edgeFromId`, `edgeToId`, `edgeKind`, `toId`, `toLabel`, `traversalDirection`, `confidence`, `provenance`), optional `sourceRefs`, optional `riskNotes`, and `content`; `--debug` adds `debug` | text context summary | recovery and packing fields are `stable-additive`; `--packing mmr` and `--mmr-lambda` are opt-in |
|
|
54
49
|
| `node` | `<query>` | `node --json` returns `id`, `label`, `kind`, `data`; `error: "ambiguous_section"` or `error: "not_found"` when unresolved | text node summary | section lookup with anchor is `stable-additive` |
|
|
55
50
|
| `trace` | `<from>`, `<to>` | `trace --json` returns `from`, `to`, `found`, `steps` | text trace summary | `--depth` is `stable-additive` |
|
|
56
51
|
| `eval` | none | `eval --json` returns `querySet`, `limit`, `ranking`, `generatedAt`, `summary`, `cases` | summary | `--path`, `--query-set`, `--query-mode`, `--limit` are `stable-additive`; `--query-set` accepts the closed enum `alpha | cjk`; `--limit` accepts a positive integer |
|
|
@@ -65,12 +60,24 @@ semantics are stricter.
|
|
|
65
60
|
| `import graphjson` | `<file>` | `import graphjson <file> --verify --json` returns `valid`, `errors`, `warnings`, plus readable `format`, `formatVersion`, `schemaVersion`, `graphHash`, `counts`, `exportedCounts` | summary | `--verify` is required; exit non-zero on `valid: false`; project root is implicit from the file argument |
|
|
66
61
|
| `diff` | none | `diff --base <ref> --json` returns `mode`, `base`, `head`, `summary`, `documents`, `impact` | summary | base index is created in a temp directory |
|
|
67
62
|
| `report` | none | `report --json` returns `projectRoot`, `generatedAt`, `mdgraphVersion`, `indexed`, `schema`, `counts`, `storage`, `source`, `doctor`, `eval`, `bundle`, `diff`, `benchmark`, `trend` | summary | optional flags are `experimental` |
|
|
68
|
-
| `serve --mcp` | none | not applicable; emits MCP JSON-RPC over stdio | stdio JSON-RPC; stderr logs when watch or MCP debug is enabled | default watch is `stable-additive`; `--no-watch` is the read-only escape hatch |
|
|
69
|
-
| `watch` | none | none | progress log | `--semantic
|
|
70
|
-
| `doctor` | none | `doctor --json` returns `staleIndex`, `summary` (with `documents`, `orphanDocs`, `deadLinks`, `staleSourceRefs`, `missingDefinitions`, `weaklyLinkedDocs`, `possibleContradictions`, `contentRisks`, `staleIndex`), `issues`, optional `scope` (with `mode`, `baseRef`, `changedPaths`, `deletedPaths`, `renamedPaths`, `untrackedPaths`, `globalHealthIncluded`), optional `health` (with `graph`, `storage`), optional `frontmatterDiagnostics` | summary | `--changed` and `--since <ref>` are `stable-additive`; `--fail-on <severity>` (closed enum `error | warn | info`) exits non-zero at or above severity; `--strict` is the legacy strict mode |
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
| `serve --mcp` | none | not applicable; emits MCP JSON-RPC over stdio | stdio JSON-RPC; stderr logs when watch or MCP debug is enabled | default watch is `stable-additive`; `--no-watch` is the read-only escape hatch; `--watch-poll` is an explicit `stable-additive` fallback |
|
|
64
|
+
| `watch` | none | none | progress and health log | `--semantic`, `--debounce <ms>`, and explicit `--poll` are `stable-additive` |
|
|
65
|
+
| `doctor` | none | `doctor --json` returns `staleIndex`, `summary` (with `documents`, `orphanDocs`, `deadLinks`, `staleSourceRefs`, `missingDefinitions`, `weaklyLinkedDocs`, `possibleContradictions`, `contentRisks`, `staleIndex`), `issues`, optional `scope` (with `mode`, `baseRef`, `changedPaths`, `deletedPaths`, `renamedPaths`, `untrackedPaths`, `globalHealthIncluded`), optional `health` (with `graph`, `storage`), optional `frontmatterDiagnostics` | summary | `--changed` and `--since <ref>` are `stable-additive`; `--fail-on <severity>` (closed enum `error | warn | info`) exits non-zero at or above severity; `--strict` is the legacy strict mode |
|
|
66
|
+
|
|
67
|
+
### Post-freeze Experimental Addition
|
|
68
|
+
|
|
69
|
+
`query <expression>` is an experimental post-freeze command and is not part of
|
|
70
|
+
the frozen 1.0 CLI inventory above. Its bounded DSL and JSON output are documented in
|
|
71
|
+
[Structured Query and Relationships](Structured_Query_and_Relationships.md#structured-query) and
|
|
72
|
+
[Output Contracts](Output_Contracts.md).
|
|
73
|
+
|
|
74
|
+
`relationships derive` is experimental and is also outside the
|
|
75
|
+
frozen inventory. Its provider/evidence gates and JSON output are documented in
|
|
76
|
+
[Structured Query and Relationships](Structured_Query_and_Relationships.md#derived-related-document-relationships) and Output Contracts.
|
|
77
|
+
The stable `search` command and five-tool MCP surface are unchanged.
|
|
78
|
+
|
|
79
|
+
Project-related commands accept an additive `--path <project>` flag so
|
|
80
|
+
agents and scripts can target a repository without changing the shell cwd.
|
|
74
81
|
|
|
75
82
|
## Config Defaults
|
|
76
83
|
|
|
@@ -87,10 +94,13 @@ agents and scripts can target a repository without changing the shell cwd.
|
|
|
87
94
|
| `search.highFrequencyEntityThreshold` | `50` | upper bound `100000` |
|
|
88
95
|
| `entities.enabledKinds` | `["symbol", "api_route", "error_code", "config_key", "file_path", "command", "package", "concept"]` | |
|
|
89
96
|
| `entities.stopEntities` | `["Config", "Error", "Service", "API", "User", "Data"]` | noise-suppression list |
|
|
90
|
-
| `embedding.enabled` | `false` | optional local semantic vectors |
|
|
91
|
-
| `embedding.provider` | `"local-hash"` | `
|
|
92
|
-
| `embedding.model` | `"mdgraph-local-hash-v1"` | |
|
|
93
|
-
| `embedding.dimensions` | `128` | upper bound `4096` |
|
|
97
|
+
| `embedding.enabled` | `false` | optional local semantic vectors |
|
|
98
|
+
| `embedding.provider` | `"local-hash"` | compatibility `lexical-hash`; `ollama` is supported as an opt-in async provider |
|
|
99
|
+
| `embedding.model` | `"mdgraph-local-hash-v1"` | |
|
|
100
|
+
| `embedding.dimensions` | `128` | upper bound `4096` |
|
|
101
|
+
| `embedding.endpoint` | `"http://127.0.0.1:11434"` | additive Ollama endpoint; credentials in the URL are rejected |
|
|
102
|
+
| `embedding.timeoutMs` | `30000` | upper bound `120000` |
|
|
103
|
+
| `embedding.batchSize` | `16` | upper bound `256` |
|
|
94
104
|
|
|
95
105
|
Unknown keys are currently ignored by the merge logic. Rejecting unknown
|
|
96
106
|
keys is intentionally not a 1.0 breaking change; the conservative default
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# MDGraph Documentation
|
|
2
|
+
|
|
3
|
+
[简体中文](../ZH/README.md)
|
|
4
|
+
|
|
5
|
+
MDGraph documentation is organized by user task. Start with the repository [README](https://github.com/daoGEE/mdgraph#readme) for installation and a first query, then use the guide that matches what you are trying to do.
|
|
6
|
+
|
|
7
|
+
## Use MDGraph
|
|
8
|
+
|
|
9
|
+
- [Agent Integration](Agent_Integration.md) — connect MDGraph to an MCP host and give coding agents a reliable documentation workflow.
|
|
10
|
+
- [Retrieval and Context](Retrieval_and_Context.md) — understand search channels, optional semantic providers, entity extraction, CJK handling, and context packing.
|
|
11
|
+
- [Structured Query and Relationships](Structured_Query_and_Relationships.md) — run governance queries and explicitly derive non-authoritative related-document edges.
|
|
12
|
+
- [Operations](Operations.md) — keep indexes fresh, interpret watcher health, use polling safely, and recover from provider or file-watcher failures.
|
|
13
|
+
|
|
14
|
+
## Integrate and Maintain MDGraph
|
|
15
|
+
|
|
16
|
+
- [Architecture](Architecture.md) — implemented pipeline, module boundaries, data model, and tradeoffs.
|
|
17
|
+
- [Output Contracts](Output_Contracts.md) — machine-readable CLI and MCP result shapes.
|
|
18
|
+
- [Public Contracts](Public_Contracts.md) — compatibility labels and the current public boundary.
|
|
19
|
+
- [1.0 Contract Freeze](Public_Contracts_1.0.md) — versioned inventory of the stable 1.0 baseline.
|
|
20
|
+
- [Evaluation](Evaluation_Questions.md) — public evaluation commands, reference questions, and repository regression suites.
|
|
21
|
+
- [Release Checklist](Release_Checklist.md) — maintainer checks for GitHub and npm releases.
|
|
22
|
+
|
|
23
|
+
Experimental commands are labeled in their guides and output contracts. Their presence does not change the deterministic default indexing pipeline, the stable `search` command, or the five-tool MCP surface.
|
|
@@ -5,30 +5,34 @@ Use this checklist before publishing an MDGraph release or asking a maintainer t
|
|
|
5
5
|
## Public checks
|
|
6
6
|
|
|
7
7
|
- Confirm the public package is `@daogee/mdgraph`, the installed binary remains `mdgraph`, and `package.json` / CLI versions 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
|
+
- 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.
|
|
10
11
|
|
|
11
|
-
##
|
|
12
|
+
## Contract gate
|
|
12
13
|
|
|
13
14
|
- Confirm [Public_Contracts.md](Public_Contracts.md) labels every touched public surface as `stable`, `stable-additive`, `experimental`, `reserved`, or `internal`.
|
|
14
15
|
- Confirm focused contract tests cover MCP tool definitions, representative JSON fields, edge kinds, doctor warning shape, config defaults, and schema compatibility guidance.
|
|
15
16
|
- Confirm structured error outputs include a stable `code` and remediation where the command already returns structured errors.
|
|
17
|
+
- Confirm experimental commands remain explicitly labeled in the guides, public ledger, output contracts, and release notes.
|
|
16
18
|
|
|
17
|
-
##
|
|
19
|
+
## Evidence gate
|
|
18
20
|
|
|
19
21
|
- Confirm [Public_Contracts.md](Public_Contracts.md) labels context recovery fields as `stable-additive`.
|
|
20
22
|
- Confirm context, MCP, and contract tests cover `nodeId`, `documentId`, optional `sectionId`, optional `anchor`, and graph-expansion `edgePath`.
|
|
21
23
|
- Confirm `smoke:cli` exercises a multi-question structured benchmark using repository-owned fixtures.
|
|
22
24
|
- Confirm optional semantic behavior remains experimental unless a separate release explicitly freezes it.
|
|
25
|
+
- Run the focused lexical-history, entity, context, structured-query, and derived-relationship regression suites. Treat recorded historical values as immutable comparison evidence, not current product targets.
|
|
23
26
|
|
|
24
|
-
##
|
|
27
|
+
## Compatibility gate
|
|
25
28
|
|
|
26
29
|
- Confirm known output-shape inconsistencies are either normalized or intentionally documented.
|
|
27
30
|
- Confirm `context --json` and MCP `mdgraph_context.structuredContent` expose recovery fields (`nodeId`, `documentId`, optional `sectionId`, optional `anchor`, and graph-expansion `edgePath`) for agent handoff to `node`, `trace`, and raw Markdown.
|
|
28
31
|
- Confirm Node.js `>=22.5.0` remains the supported floor and the active release was tested on the current Node 22.x line.
|
|
29
|
-
- Confirm Linux and Windows full CI rows pass. Confirm the macOS CI smoke row passes build-output CLI and packed-artifact smoke
|
|
32
|
+
- Confirm Linux and Windows full CI rows pass. Confirm the macOS CI smoke row passes build-output CLI and packed-artifact smoke.
|
|
30
33
|
- Run maintainer smoke for platform-specific long-running surfaces that CI intentionally does not automate: `serve --mcp` and `watch` on each target OS where those paths matter.
|
|
31
|
-
- Confirm
|
|
34
|
+
- Confirm release notes call out compatibility promises separately from feature additions.
|
|
35
|
+
- Confirm new behavior does not silently change the frozen 1.0 defaults, five-tool MCP surface, schema version, or `alpha | cjk` evaluation enum.
|
|
32
36
|
|
|
33
37
|
## Command gate
|
|
34
38
|
|
|
@@ -36,8 +40,14 @@ Run from the repository root after dependencies are installed:
|
|
|
36
40
|
|
|
37
41
|
```bash
|
|
38
42
|
npm run typecheck
|
|
43
|
+
npm run docs:check
|
|
39
44
|
npm run build
|
|
40
45
|
npm run test:run
|
|
46
|
+
npm run baseline:historical
|
|
47
|
+
npm run baseline:entity-extraction
|
|
48
|
+
npm run baseline:context-packing
|
|
49
|
+
npm run baseline:structured-query
|
|
50
|
+
npm run baseline:related-documents
|
|
41
51
|
npm run smoke:cli
|
|
42
52
|
npm run smoke:eval
|
|
43
53
|
npm run smoke:pack
|
|
@@ -57,7 +67,7 @@ git diff --check
|
|
|
57
67
|
|
|
58
68
|
Expected results:
|
|
59
69
|
|
|
60
|
-
-
|
|
70
|
+
- Documentation links, typecheck, tests, build, focused regression suites, CLI smoke, and pack smoke exit 0.
|
|
61
71
|
- `doctor --strict --json` reports `staleIndex: 0` and no issue counts for the MDGraph repository.
|
|
62
72
|
- `status --storage --json` returns `{ counts, storage }` with database, object, path group, edge kind, high-degree node, and vector sections.
|
|
63
73
|
- `bundle create`, `bundle verify`, and `report --json --eval --bundle` return valid private workflow artifacts for the current repository index.
|
|
@@ -68,12 +78,15 @@ Expected results:
|
|
|
68
78
|
- Keep private or third-party evaluation corpora outside release artifacts and public fixtures.
|
|
69
79
|
- The macOS CI row is smoke-only. It does not replace the full command gate or maintainer checks for MCP server, watcher, and external-corpus behavior.
|
|
70
80
|
|
|
71
|
-
## Package gate
|
|
72
|
-
|
|
73
|
-
- Inspect the tarball contents
|
|
74
|
-
- Confirm
|
|
75
|
-
-
|
|
76
|
-
- Confirm
|
|
81
|
+
## Package gate
|
|
82
|
+
|
|
83
|
+
- Inspect the machine-readable tarball contents whenever package metadata or public docs change: `npm pack --dry-run --json`.
|
|
84
|
+
- Confirm npm Trusted Publishing is bound to `daoGEE/mdgraph` and the exact workflow filename `publish.yml`, with the `npm publish` action allowed.
|
|
85
|
+
- Publish by pushing a `v*` tag whose version matches `package.json`; `.github/workflows/publish.yml` uses GitHub Actions OIDC and does not require a long-lived npm token.
|
|
86
|
+
- Confirm the package includes `dist`, the agent pack, both README files, `CHANGELOG.md`, `LICENSE`, and the explicitly allowlisted English/Chinese guides.
|
|
87
|
+
- 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
|
+
- 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.
|
|
77
90
|
|
|
78
91
|
## Note text
|
|
79
92
|
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Retrieval and Context
|
|
3
|
+
type: guide
|
|
4
|
+
status: active
|
|
5
|
+
source_refs:
|
|
6
|
+
- src/query/search.ts
|
|
7
|
+
- src/query/context-builder.ts
|
|
8
|
+
- src/extraction/entity-extractor.ts
|
|
9
|
+
- src/semantic/provider.ts
|
|
10
|
+
- src/semantic/ollama-provider.ts
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Retrieval and Context
|
|
14
|
+
|
|
15
|
+
MDGraph combines deterministic full-text, entity, and graph retrieval by default. A real embedding provider and true Maximal Marginal Relevance (MMR) context packing are available as explicit options; neither is required to index or query a project.
|
|
16
|
+
|
|
17
|
+
## Search Channels
|
|
18
|
+
|
|
19
|
+
`search` combines and deduplicates four explainable channels:
|
|
20
|
+
|
|
21
|
+
- FTS5 chunk matches, with lightweight CJK n-gram augmentation for continuous Chinese, Japanese, and Korean text.
|
|
22
|
+
- Exact technical-entity matches.
|
|
23
|
+
- Graph neighbors around matching entities and documents.
|
|
24
|
+
- Optional embedding-vector matches when a supported provider is enabled, indexed, and requested.
|
|
25
|
+
|
|
26
|
+
Reciprocal rank fusion (RRF) combines the active channels. Results retain reasons, matched entities, edge provenance, and optional semantic provider/model metadata. Semantic results are an additional signal; they do not replace the deterministic channels.
|
|
27
|
+
|
|
28
|
+
## Semantic Providers
|
|
29
|
+
|
|
30
|
+
Embedding support is provider-based. The default configuration keeps embeddings disabled.
|
|
31
|
+
|
|
32
|
+
| Provider | Capability | Intended use |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| `local-hash` | `lexical-hash` | Compatibility and deterministic lexical projection. It is not a language-model embedding and should not be treated as synonym understanding. |
|
|
35
|
+
| `ollama` | `semantic-model` | Opt-in local semantic retrieval through a separately running Ollama service and embedding model. |
|
|
36
|
+
|
|
37
|
+
Example Ollama configuration:
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"embedding": {
|
|
42
|
+
"enabled": true,
|
|
43
|
+
"provider": "ollama",
|
|
44
|
+
"model": "nomic-embed-text",
|
|
45
|
+
"dimensions": 768,
|
|
46
|
+
"endpoint": "http://127.0.0.1:11434",
|
|
47
|
+
"timeoutMs": 30000,
|
|
48
|
+
"batchSize": 16
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Build a complete provider-backed index before semantic queries:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
mdgraph index --full --semantic --path /path/to/project
|
|
57
|
+
mdgraph semantic status --path /path/to/project
|
|
58
|
+
mdgraph search --semantic --path /path/to/project "authentication login"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Provider identity, model, dimensions, and vector coverage are stored with the index. Changing that profile requires a full semantic reindex. Embedding finishes before a repository write begins, so provider failure cannot commit partial graph or vector coverage.
|
|
62
|
+
|
|
63
|
+
At query time, an unavailable provider, timeout, invalid response, missing model, or incomplete vector profile falls back to FTS5/entity/graph retrieval. CLI and MCP outputs include an additive `semanticDiagnostic`; a usable lexical result is not converted into an error.
|
|
64
|
+
|
|
65
|
+
## Deterministic Entity Extraction
|
|
66
|
+
|
|
67
|
+
Entity extraction is source-aware and favors precision. It is an interpretable heuristic, not general-purpose named-entity recognition and not a programming-language AST.
|
|
68
|
+
|
|
69
|
+
| Source | Inferred technical signals |
|
|
70
|
+
|---|---|
|
|
71
|
+
| Front matter and `Defines` / `定义` sections | Explicit definitions, including names otherwise suppressed by the stop list. |
|
|
72
|
+
| Technical headings | API routes, Latin symbols, shaped configuration keys, and empty-call function forms. |
|
|
73
|
+
| Ordinary prose | API routes, error codes, shaped uppercase or dotted configuration keys, and segmented CJK configuration keys. |
|
|
74
|
+
| Standalone inline code | Structured signals plus a complete Latin or CJK symbol value. |
|
|
75
|
+
| Fenced code | Structured signals, empty-call functions, declaration names, and bounded type-reference contexts. |
|
|
76
|
+
| Markdown and WikiLinks | Structured link signals; WikiLink labels must look like a complete entity. |
|
|
77
|
+
|
|
78
|
+
Broad PascalCase scanning is intentionally absent from prose and code blocks. This avoids promoting words such as “The”, “When”, and “Note” to graph nodes. `entities.stopEntities` suppresses every inferred reference kind; author-declared definitions remain authoritative.
|
|
79
|
+
|
|
80
|
+
Unicode-aware rules recognize CJK API paths such as `POST /接口/登录`, segmented keys such as `登录.认证.重试`, and empty-call identifiers such as `验证登录()` or `認証を確認()`. Route boundaries prevent a file path such as `src/auth/session.ts` from also emitting the truncated route `/auth/session.ts`. Bare CJK prose is not inferred as an entity without explicit structural evidence.
|
|
81
|
+
|
|
82
|
+
## Context Packing
|
|
83
|
+
|
|
84
|
+
`context` starts from ranked search sections, performs bounded graph expansion through non-containment edges, and packs selected sections under a character budget.
|
|
85
|
+
|
|
86
|
+
The compatibility default, `mmr-style-document-round-robin`, introduces documents in round-robin order. It is deterministic and preserves existing behavior, but it does not calculate pairwise relevance and redundancy.
|
|
87
|
+
|
|
88
|
+
True MMR is opt-in:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
mdgraph context --packing mmr --mmr-lambda 0.65 --debug --json \
|
|
92
|
+
--path /path/to/project "session recovery"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
MCP callers select the same behavior with `packingStrategy: "mmr"` and may provide `mmrLambda`. At each selection step, MMR maximizes:
|
|
96
|
+
|
|
97
|
+
```text
|
|
98
|
+
lambda * queryRelevance - (1 - lambda) * maximumSimilarityToSelected
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Candidate similarity uses stored vectors for the configured provider/model when both chunks have them. Otherwise it uses deterministic Unicode-token Jaccard similarity. Same-document candidates at least `0.8` similar to an already selected section are pruned, while the first candidate from another document is preserved as cross-document evidence.
|
|
102
|
+
|
|
103
|
+
Every result includes `packing` metadata. `--debug` additionally reports candidate and graph-expansion counts, similarity source, lambda, per-item relevance and redundancy scores, pruned duplicates, and budget truncation.
|
|
104
|
+
|
|
105
|
+
## Limits and Evaluation
|
|
106
|
+
|
|
107
|
+
- CJK n-grams improve lexical matching but do not provide morphology, word segmentation, translation, or synonym understanding.
|
|
108
|
+
- Entity rules recognize bounded technical shapes; projects should use explicit front matter for authoritative domain entities.
|
|
109
|
+
- Embedding quality depends on the chosen model and target corpus. Repository fixtures verify integration behavior, not universal model quality.
|
|
110
|
+
- MMR reduces measured redundancy on the repository fixture, but its best lambda and similarity threshold remain corpus-dependent.
|
|
111
|
+
|
|
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.
|