@daogee/mdgraph 1.0.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 +25 -0
- package/LICENSE +21 -0
- package/README-ZH.md +203 -0
- package/README.md +203 -0
- package/agent-pack/README.md +26 -0
- package/agent-pack/host-examples.md +71 -0
- package/agent-pack/mcp-config.example.json +14 -0
- package/agent-pack/mdgraph-agent-instructions.md +21 -0
- package/agent-pack/prompts/relationship-trace.md +12 -0
- package/agent-pack/prompts/status-doctor.md +13 -0
- package/agent-pack/prompts/task-start-context.md +15 -0
- package/dist/analysis/doctor-scope.d.ts +8 -0
- package/dist/analysis/doctor-scope.js +109 -0
- package/dist/analysis/doctor.d.ts +148 -0
- package/dist/analysis/doctor.js +919 -0
- package/dist/analysis/status-freshness.d.ts +13 -0
- package/dist/analysis/status-freshness.js +55 -0
- package/dist/benchmark/benchmark.d.ts +118 -0
- package/dist/benchmark/benchmark.js +357 -0
- package/dist/bin/mdgraph.d.ts +2 -0
- package/dist/bin/mdgraph.js +877 -0
- package/dist/bundle/bundle.d.ts +66 -0
- package/dist/bundle/bundle.js +320 -0
- package/dist/config/limits.d.ts +24 -0
- package/dist/config/limits.js +24 -0
- package/dist/config/load-config.d.ts +14 -0
- package/dist/config/load-config.js +177 -0
- package/dist/db/connection.d.ts +15 -0
- package/dist/db/connection.js +145 -0
- package/dist/db/repositories.d.ts +159 -0
- package/dist/db/repositories.js +929 -0
- package/dist/db/schema.sql +110 -0
- package/dist/db/sqlite-adapter.d.ts +18 -0
- package/dist/db/sqlite-adapter.js +60 -0
- package/dist/diff/graph-diff.d.ts +41 -0
- package/dist/diff/graph-diff.js +334 -0
- package/dist/evaluation/retrieval-eval.d.ts +115 -0
- package/dist/evaluation/retrieval-eval.js +399 -0
- package/dist/export/diagram.d.ts +11 -0
- package/dist/export/diagram.js +41 -0
- package/dist/export/graphjson.d.ts +89 -0
- package/dist/export/graphjson.js +299 -0
- package/dist/export/markdown-index.d.ts +21 -0
- package/dist/export/markdown-index.js +89 -0
- package/dist/export/source-bridge.d.ts +22 -0
- package/dist/export/source-bridge.js +83 -0
- package/dist/extraction/entity-extractor.d.ts +12 -0
- package/dist/extraction/entity-extractor.js +153 -0
- package/dist/extraction/graph-builder.d.ts +2 -0
- package/dist/extraction/graph-builder.js +168 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +28 -0
- package/dist/indexer.d.ts +19 -0
- package/dist/indexer.js +100 -0
- package/dist/mcp/debug.d.ts +7 -0
- package/dist/mcp/debug.js +41 -0
- package/dist/mcp/server-instructions.d.ts +2 -0
- package/dist/mcp/server-instructions.js +40 -0
- package/dist/mcp/server.d.ts +28 -0
- package/dist/mcp/server.js +232 -0
- package/dist/mcp/tools.d.ts +31 -0
- package/dist/mcp/tools.js +506 -0
- package/dist/mcp/transport.d.ts +50 -0
- package/dist/mcp/transport.js +88 -0
- package/dist/parser/frontmatter.d.ts +10 -0
- package/dist/parser/frontmatter.js +191 -0
- package/dist/parser/links.d.ts +6 -0
- package/dist/parser/links.js +9 -0
- package/dist/parser/markdown-parser.d.ts +2 -0
- package/dist/parser/markdown-parser.js +267 -0
- package/dist/query/context-builder.d.ts +85 -0
- package/dist/query/context-builder.js +413 -0
- package/dist/query/search.d.ts +32 -0
- package/dist/query/search.js +237 -0
- package/dist/query/trace.d.ts +10 -0
- package/dist/query/trace.js +55 -0
- package/dist/reporting/report.d.ts +49 -0
- package/dist/reporting/report.js +143 -0
- package/dist/resolution/link-resolver.d.ts +17 -0
- package/dist/resolution/link-resolver.js +113 -0
- package/dist/scanner/file-scanner.d.ts +4 -0
- package/dist/scanner/file-scanner.js +144 -0
- package/dist/semantic/local-embedding.d.ts +4 -0
- package/dist/semantic/local-embedding.js +30 -0
- package/dist/semantic/status.d.ts +19 -0
- package/dist/semantic/status.js +70 -0
- package/dist/semantic/vector-codec.d.ts +3 -0
- package/dist/semantic/vector-codec.js +35 -0
- package/dist/types.d.ts +198 -0
- package/dist/types.js +15 -0
- package/dist/utils/bounded-json.d.ts +9 -0
- package/dist/utils/bounded-json.js +57 -0
- package/dist/utils/content-risk.d.ts +5 -0
- package/dist/utils/content-risk.js +20 -0
- package/dist/utils/fts.d.ts +3 -0
- package/dist/utils/fts.js +52 -0
- package/dist/utils/id.d.ts +2 -0
- package/dist/utils/id.js +8 -0
- package/dist/utils/path-safety.d.ts +4 -0
- package/dist/utils/path-safety.js +25 -0
- package/dist/utils/text.d.ts +7 -0
- package/dist/utils/text.js +36 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +11 -0
- package/dist/watcher/file-watcher.d.ts +11 -0
- package/dist/watcher/file-watcher.js +127 -0
- package/docs/EN/Agent_Integration.md +129 -0
- package/docs/EN/Architecture.md +135 -0
- package/docs/EN/Evaluation_Questions.md +68 -0
- package/docs/EN/Output_Contracts.md +274 -0
- package/docs/EN/Public_Contracts.md +88 -0
- package/docs/EN/Public_Contracts_1.0.md +234 -0
- package/docs/EN/Release_Checklist.md +82 -0
- package/docs/ZH/Agent_Integration.md +105 -0
- package/docs/ZH/Architecture.md +124 -0
- package/docs/ZH/Evaluation_Questions.md +66 -0
- package/docs/ZH/Output_Contracts.md +269 -0
- package/docs/ZH/Public_Contracts.md +81 -0
- package/docs/ZH/Public_Contracts_1.0.md +202 -0
- package/docs/ZH/Release_Checklist.md +83 -0
- package/package.json +94 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
---
|
|
2
|
+
source_refs:
|
|
3
|
+
- src/bin/mdgraph.ts
|
|
4
|
+
- src/types.ts
|
|
5
|
+
- src/db/schema.sql
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# MDGraph Public Contracts
|
|
9
|
+
|
|
10
|
+
This document records the public contract boundary for the current `1.0.0` public surface. 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
|
+
|
|
12
|
+
## Stability Labels
|
|
13
|
+
|
|
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
|
+
- `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 before 1.0, but semantics may be adjusted with changelog notes and focused tests.
|
|
17
|
+
- `reserved`: named for future use, but not active until an emitter or workflow is documented and tested.
|
|
18
|
+
- `internal`: implementation detail. It may change without compatibility guarantees.
|
|
19
|
+
|
|
20
|
+
## Contract Ledger
|
|
21
|
+
|
|
22
|
+
| Surface | Status | Owner | Contract |
|
|
23
|
+
|---|---|---|---|
|
|
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. `serve --mcp` keeps the graph fresh by default and supports additive optional `--watch`, `--no-watch`, `--semantic`, and `--debounce <ms>` flags for integrated watch-based freshness. `status --freshness` adds optional freshness diagnostics without changing the default `status --json` shape. |
|
|
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
|
+
| `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
|
+
| `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`, and `--debounce <ms>` remain additive flags for integrated watch-based freshness. |
|
|
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
|
+
| 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
|
+
| 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`. |
|
|
33
|
+
| MCP text output wording | experimental | `src/mcp/tools.ts` | Text is human-facing guidance; `structuredContent` is the preferred machine contract. |
|
|
34
|
+
| 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. |
|
|
36
|
+
| `.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
|
+
| 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
|
+
| 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
|
+
| 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` | Active edge kinds are stable. `SAME_AS`, `RELATED_TO`, and `CONTRADICTS` are reserved until emitters are documented and tested. |
|
|
41
|
+
| 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
|
+
| GraphJSON export and verify | stable format v1 | `src/export/graphjson.ts` | `format: "mdgraph-graphjson"`, `formatVersion: 1`, structural profile, deterministic ordering, and `graphHash` verification. |
|
|
43
|
+
| 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 before 1.0. |
|
|
45
|
+
| Semantic vector provider behavior | experimental | `src/semantic/*` | Optional local provider behavior must degrade to FTS5/graph search when unavailable or unsupported. |
|
|
46
|
+
|
|
47
|
+
## Compatibility Policy
|
|
48
|
+
|
|
49
|
+
- Additive JSON fields are allowed when existing documented fields keep their meaning.
|
|
50
|
+
- Removing, renaming, or changing the type of a documented stable field is breaking after 1.0.
|
|
51
|
+
- Optional CLI flags may be added when default behavior is unchanged.
|
|
52
|
+
- MCP tool names and required inputs are stable; optional inputs may be added when old clients continue to work.
|
|
53
|
+
- Unknown future GraphJSON fields may be ignored when required v1 fields are valid.
|
|
54
|
+
- Unsupported future `formatVersion` values must fail with actionable upgrade guidance.
|
|
55
|
+
- Error payloads should include a stable `code` and remediation when the command already returns structured errors.
|
|
56
|
+
- Non-zero exit behavior is part of the contract for failed verification, invalid bundle verification, strict doctor gates, and invalid command usage.
|
|
57
|
+
|
|
58
|
+
## Schema And Config Strategy
|
|
59
|
+
|
|
60
|
+
- Existing databases with no metadata are treated as `legacy` after metadata tables are created.
|
|
61
|
+
- Databases with a future `schema_version` fail before local schema SQL is applied.
|
|
62
|
+
- Existing migration helpers may update storage internals when the resulting public graph records stay compatible.
|
|
63
|
+
- Schema changes that cannot be safely migrated must fail with rebuild or upgrade guidance.
|
|
64
|
+
- New config fields must have defaults and must not make existing config files invalid unless the change is explicitly documented as breaking.
|
|
65
|
+
- Config numeric and path-related limits are part of the safety contract, not optional tuning hints.
|
|
66
|
+
|
|
67
|
+
## Release Matrix
|
|
68
|
+
|
|
69
|
+
For the `1.0.0` release baseline, preserve the stable 1.0 surfaces and validate the additive 0.9 surfaces (`usage`, project-wide `--path`, `status --freshness`, MCP freshness metadata, context recovery fields, and default fresh MCP serving) alongside the 0.7-0.8 contract surfaces.
|
|
70
|
+
|
|
71
|
+
Before a release that changes public surfaces:
|
|
72
|
+
|
|
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`.
|
|
74
|
+
- Run `npm pack --dry-run` when package metadata or included public docs change.
|
|
75
|
+
- 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 before 1.0.
|
|
77
|
+
- Use release maintainer smoke, not CI, for platform-specific long-running surfaces such as `serve --mcp` and `watch`.
|
|
78
|
+
- Keep any external-corpus evaluation data outside the public repository unless it is independently licensed and intentionally adopted as a public fixture.
|
|
79
|
+
|
|
80
|
+
## 1.0 Readiness
|
|
81
|
+
|
|
82
|
+
MDGraph should move from 0.9 to 1.0 only after:
|
|
83
|
+
|
|
84
|
+
- The ledger above is complete for every public surface.
|
|
85
|
+
- Critical public shapes are protected by focused tests or smoke gates.
|
|
86
|
+
- Experimental and internal surfaces are explicitly labeled in docs.
|
|
87
|
+
- Known output-shape inconsistencies are either normalized or intentionally documented.
|
|
88
|
+
- The release checklist can catch accidental public contract drift.
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# MDGraph 1.0 Contract Freeze Appendix
|
|
2
|
+
|
|
3
|
+
Status: active
|
|
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
|
|
7
|
+
|
|
8
|
+
This appendix is the authoritative inventory of the MDGraph public surface
|
|
9
|
+
frozen for the `1.0.0` release. It supplements the [Public Contracts](Public_Contracts.md)
|
|
10
|
+
ledger with the full per-command, per-format, per-config, per-schema
|
|
11
|
+
details that the ledger summarizes.
|
|
12
|
+
|
|
13
|
+
The local implementation context lives in
|
|
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
|
|
18
|
+
|
|
19
|
+
- Package version: `1.0.0`
|
|
20
|
+
- SQLite `schemaVersion`: `1`
|
|
21
|
+
- MCP tool surface: exactly the five tools listed below
|
|
22
|
+
- New 0.9 additive public surfaces are explicitly labeled `stable-additive`
|
|
23
|
+
in the Public Contracts ledger and validated alongside the 0.7-0.8
|
|
24
|
+
surfaces.
|
|
25
|
+
|
|
26
|
+
## Stability Labels
|
|
27
|
+
|
|
28
|
+
Reuse the labels in [Public_Contracts.md](Public_Contracts.md):
|
|
29
|
+
|
|
30
|
+
- `stable`: required name, required fields, and semantics are frozen.
|
|
31
|
+
- `stable-additive`: existing fields and behavior are frozen; new optional
|
|
32
|
+
fields, metrics, or commands may appear when old consumers stay valid.
|
|
33
|
+
- `experimental`: visible but not guaranteed for 1.0 compatibility; may
|
|
34
|
+
change with changelog notes and targeted migration guidance.
|
|
35
|
+
- `reserved`: named for future use; not active until an emitter or workflow
|
|
36
|
+
is documented and tested.
|
|
37
|
+
- `internal`: implementation detail; no compatibility guarantees.
|
|
38
|
+
|
|
39
|
+
## CLI Freeze Inventory
|
|
40
|
+
|
|
41
|
+
Each top-level command is frozen at its command path. Required arguments,
|
|
42
|
+
options, JSON shape, text shape, and exit behavior are part of the contract.
|
|
43
|
+
Human-readable text remains `stable-additive`; JSON shape and exit
|
|
44
|
+
semantics are stricter.
|
|
45
|
+
|
|
46
|
+
| Command | Required args | JSON contract | Text contract | Notes |
|
|
47
|
+
|---|---|---|---|---|
|
|
48
|
+
| `usage` | none | `usage --json` returns `projectRoot`, `commonOptions`, `workflows` | agent-friendly workflow guide | `stable-additive` |
|
|
49
|
+
| `init` | `--docs <glob...>` (or default) | none | init summary | initial graph index by default; `--no-index` is `stable-additive` |
|
|
50
|
+
| `index` | none | `index --json` returns `files`, `changed`, `deleted`, `unchanged`, `skipped`, `skippedFiles`, `mode`, `counts` | progress summary | `--semantic` and `--full` are `stable-additive` |
|
|
51
|
+
| `status` | none | `status --json` returns graph counts; `--storage` adds `storage`; `--freshness` adds `freshness` | counts summary | `--freshness` is `stable-additive` |
|
|
52
|
+
| `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` |
|
|
54
|
+
| `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
|
+
| `trace` | `<from>`, `<to>` | `trace --json` returns `from`, `to`, `found`, `steps` | text trace summary | `--depth` is `stable-additive` |
|
|
56
|
+
| `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 |
|
|
57
|
+
| `semantic status` | none | `semantic status --json` returns `state` (closed enum `disabled | not_indexed | ready | unsupported_provider | needs_reindex`), `enabled`, `provider`, `model`, `dimensions`, `providerSupported`, `indexed`, `chunks`, `vectors`, `vectorStorageFormat` (closed enum `float32_blob`), `indexedProviders`, `guidance` | text status | `experimental` |
|
|
58
|
+
| `bundle create` | none | `bundle create --json` returns `bundleDir`, `manifestPath`, `manifest` | summary | `--profile` is `experimental`; only `private` is supported; `--path` is `stable-additive` |
|
|
59
|
+
| `bundle verify` | `<dir>` | `bundle verify --json` returns `bundleDir`, `valid`, `errors`, `manifest`, `counts`, `schemaVersion`, `sourceHash`, `configHash`, `freshness` | summary | exit non-zero on `valid: false`; `--path` is `stable-additive` for freshness comparison |
|
|
60
|
+
| `export graphjson` | none | `export graphjson --json` returns `format: "mdgraph-graphjson"`, `formatVersion: 1`, `schemaVersion`, `mdgraphVersion`, `exportProfile: "structural"`, `graphHash`, `sourceHash`, `counts`, `exportedCounts`, `nodes`, `edges` | structural JSON | `stable` for required v1 fields and privacy exclusions; `--path` is `stable-additive` |
|
|
61
|
+
| `export mermaid trace` | `<from>`, `<to>` | `export mermaid trace <from> <to> --json` returns `format: "mdgraph-mermaid"`, `formatVersion: 1`, `diagramType: "trace"`, `found`, `diagram`, `trace` | Mermaid text | `stable-additive` for wrapper fields; `--depth` is `stable-additive` |
|
|
62
|
+
| `export markdown-index` | none | none | WikiLink-based Markdown | `stable-additive` for per-document facts; `--path` is `stable-additive` |
|
|
63
|
+
| `export docs-site` | none | `export docs-site --json` returns `format: "mdgraph-docsite-index"`, `formatVersion: 1`, `sourceFormat`, `graphHash`, `documents` | summary | `stable-additive` for per-document facts; `--path` is `stable-additive` |
|
|
64
|
+
| `export source-bridge` | none | `export source-bridge --json` returns `format: "mdgraph-source-bridge"`, `formatVersion: 1`, `provider`, `status` (closed enum `ready | unsupported`), `reason`, `sourceRefs`, `matched`, `unmatched` | summary | `experimental` for provider semantics; wrapper is `stable-additive`; `--provider` accepts `json`; `--artifact <file>` is required for `status: "ready"` |
|
|
65
|
+
| `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
|
+
| `diff` | none | `diff --base <ref> --json` returns `mode`, `base`, `head`, `summary`, `documents`, `impact` | summary | base index is created in a temp directory |
|
|
67
|
+
| `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` and `--debounce <ms>` are `stable-additive` |
|
|
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
|
+
Project-related commands accept an additive `--path <project>` flag so
|
|
73
|
+
agents and scripts can target a repository without changing the shell cwd.
|
|
74
|
+
|
|
75
|
+
## Config Defaults
|
|
76
|
+
|
|
77
|
+
| Key | Default | Notes |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| `docs.include` | `["**/*.md", "**/*.mdx"]` | `**/node_modules/**`, `**/dist/**`, `**/build/**`, `**/.next/**`, `**/coverage/**`, `**/temp/**`, `**/.git/**`, `**/.mdgraph/**` are excluded by default. |
|
|
80
|
+
| `docs.exclude` | `[]` (additive on top of built-in excludes) | |
|
|
81
|
+
| `index.parseMdx` | `false` | |
|
|
82
|
+
| `index.followGitignore` | `true` | |
|
|
83
|
+
| `index.maxFileBytes` | `524288` | upper bound `10 MiB` |
|
|
84
|
+
| `search.defaultLimit` | `8` | upper bound `100` |
|
|
85
|
+
| `search.maxDepth` | `2` | upper bound `12` |
|
|
86
|
+
| `search.maxContextChars` | `28000` | upper bound `200000` |
|
|
87
|
+
| `search.highFrequencyEntityThreshold` | `50` | upper bound `100000` |
|
|
88
|
+
| `entities.enabledKinds` | `["symbol", "api_route", "error_code", "config_key", "file_path", "command", "package", "concept"]` | |
|
|
89
|
+
| `entities.stopEntities` | `["Config", "Error", "Service", "API", "User", "Data"]` | noise-suppression list |
|
|
90
|
+
| `embedding.enabled` | `false` | optional local semantic vectors |
|
|
91
|
+
| `embedding.provider` | `"local-hash"` | `local-hash` is the only fully supported provider |
|
|
92
|
+
| `embedding.model` | `"mdgraph-local-hash-v1"` | |
|
|
93
|
+
| `embedding.dimensions` | `128` | upper bound `4096` |
|
|
94
|
+
|
|
95
|
+
Unknown keys are currently ignored by the merge logic. Rejecting unknown
|
|
96
|
+
keys is intentionally not a 1.0 breaking change; the conservative default
|
|
97
|
+
stays "ignored but not guaranteed" so existing config files keep loading.
|
|
98
|
+
Numeric and path-related limits remain part of the safety contract.
|
|
99
|
+
|
|
100
|
+
## MCP Freeze
|
|
101
|
+
|
|
102
|
+
The MCP surface stays at exactly five tools:
|
|
103
|
+
|
|
104
|
+
- `mdgraph_search`
|
|
105
|
+
- `mdgraph_context`
|
|
106
|
+
- `mdgraph_node`
|
|
107
|
+
- `mdgraph_trace`
|
|
108
|
+
- `mdgraph_status`
|
|
109
|
+
|
|
110
|
+
Tool order returned by `tools/list` is part of the contract. Each tool
|
|
111
|
+
schema sets `additionalProperties: false`. The initialize root and
|
|
112
|
+
per-tool `projectPath` are confined to the served project root.
|
|
113
|
+
Text-first content is human-facing; `structuredContent` is the machine
|
|
114
|
+
contract.
|
|
115
|
+
|
|
116
|
+
The frozen MCP input shapes are:
|
|
117
|
+
|
|
118
|
+
- `mdgraph_search` — required `query`; optional `limit` (positive integer,
|
|
119
|
+
bounded by the `search.defaultLimit` upper bound `100`), `projectPath`.
|
|
120
|
+
- `mdgraph_context` — required `query`; optional `knownFiles`
|
|
121
|
+
(string array), `maxChars` (positive integer, bounded by the
|
|
122
|
+
`search.maxContextChars` upper bound `200000`), `projectPath`.
|
|
123
|
+
- `mdgraph_node` — required `query`; optional `projectPath`.
|
|
124
|
+
- `mdgraph_trace` — required `from`, `to`; optional `depth` (positive
|
|
125
|
+
integer, bounded by the `search.maxDepth` upper bound `12`),
|
|
126
|
+
`projectPath`.
|
|
127
|
+
- `mdgraph_status` — optional `projectPath`.
|
|
128
|
+
|
|
129
|
+
Future optional inputs may be added when old clients remain valid, per
|
|
130
|
+
the compatibility policy.
|
|
131
|
+
|
|
132
|
+
Freshness behavior is part of the 0.9 contract: `mdgraph_status` reports
|
|
133
|
+
freshness when indexed, and query tools may prepend a non-blocking
|
|
134
|
+
freshness warning plus additive freshness metadata when the index is
|
|
135
|
+
stale or unknown. MCP text wording is `experimental`; representative
|
|
136
|
+
`structuredContent` fields are `stable-additive`.
|
|
137
|
+
|
|
138
|
+
Do not add 0.7 export/import surfaces to MCP during the freeze. If agents
|
|
139
|
+
later need `mdgraph_export_graphjson`, that should be a separate
|
|
140
|
+
public-surface decision.
|
|
141
|
+
|
|
142
|
+
## JSON Format Freeze
|
|
143
|
+
|
|
144
|
+
Required top-level fields are frozen; new optional fields are allowed only
|
|
145
|
+
where the compatibility policy says `stable-additive`.
|
|
146
|
+
|
|
147
|
+
- `mdgraph-graphjson`, `formatVersion: 1`, `schemaVersion`,
|
|
148
|
+
`mdgraphVersion`, `exportProfile: "structural"`, `graphHash`,
|
|
149
|
+
`sourceHash`, `counts`, `exportedCounts`, `nodes`, `edges`.
|
|
150
|
+
- GraphJSON verify result: `valid`, `errors`, `warnings`, readable
|
|
151
|
+
metadata fields, error `code`, `message`, optional `evidence`, and
|
|
152
|
+
`remediation`.
|
|
153
|
+
- `mdgraph-mermaid`, `formatVersion: 1`, `diagramType: "trace"`, `found`,
|
|
154
|
+
`diagram`, `trace`.
|
|
155
|
+
- `mdgraph-docsite-index`, `formatVersion: 1`, `sourceFormat`,
|
|
156
|
+
`graphHash`, `documents`.
|
|
157
|
+
- `mdgraph-source-bridge`, `formatVersion: 1`, `provider`, `status`
|
|
158
|
+
(closed enum `ready | unsupported`), `reason`, `sourceRefs`, `matched`,
|
|
159
|
+
`unmatched`.
|
|
160
|
+
|
|
161
|
+
Also freeze the existing core JSON outputs enough for scripts and agents:
|
|
162
|
+
`usage`, `status`, `status --freshness`, `search`, `context`, `node`,
|
|
163
|
+
`trace`, `doctor`, `semantic status`, `eval`, `diff`, `report`, and
|
|
164
|
+
bundle create/verify.
|
|
165
|
+
|
|
166
|
+
Compatibility rules:
|
|
167
|
+
|
|
168
|
+
- Removing or renaming a required field is breaking.
|
|
169
|
+
- Changing `format` or `formatVersion` semantics requires a new versioned
|
|
170
|
+
contract.
|
|
171
|
+
- Adding optional fields is allowed for `stable-additive` objects.
|
|
172
|
+
- Unknown future fields in imported JSON may be ignored only when
|
|
173
|
+
required v1 fields remain valid.
|
|
174
|
+
- Deterministic exports must keep stable ordering and privacy exclusions.
|
|
175
|
+
- `graphHash` changes require either unchanged canonical semantics or an
|
|
176
|
+
explicit version bump.
|
|
177
|
+
|
|
178
|
+
## Schema Freeze
|
|
179
|
+
|
|
180
|
+
Schema stability covers MDGraph-owned index compatibility, not third-party
|
|
181
|
+
SQL access. The 1.0 contract defines:
|
|
182
|
+
|
|
183
|
+
- current `schemaVersion: 1` (see `CURRENT_SCHEMA_VERSION` in
|
|
184
|
+
`src/db/connection.ts`)
|
|
185
|
+
- required `schema_metadata` keys
|
|
186
|
+
- how `schema_migrations` is used
|
|
187
|
+
- future-schema refusal before local schema SQL is applied
|
|
188
|
+
- migration rules for additive table/column changes
|
|
189
|
+
- when a full reindex is required instead of an in-place migration
|
|
190
|
+
- the legacy database fallback (`legacy` baseline) for databases created
|
|
191
|
+
before metadata was recorded
|
|
192
|
+
- which storage fields are internal and not exported
|
|
193
|
+
|
|
194
|
+
SQLite table names and columns are stable enough for MDGraph upgrades,
|
|
195
|
+
but external tools should consume GraphJSON instead of reading
|
|
196
|
+
`.mdgraph/graph.db`.
|
|
197
|
+
|
|
198
|
+
## Compatibility Policy
|
|
199
|
+
|
|
200
|
+
- Additive JSON fields are allowed when existing documented fields keep
|
|
201
|
+
their meaning.
|
|
202
|
+
- Removing, renaming, or changing the type of a documented stable field
|
|
203
|
+
is breaking after 1.0.
|
|
204
|
+
- Optional CLI flags may be added when default behavior is unchanged.
|
|
205
|
+
- MCP tool names and required inputs are stable; optional inputs may be
|
|
206
|
+
added when old clients continue to work.
|
|
207
|
+
- Unknown future GraphJSON fields may be ignored when required v1 fields
|
|
208
|
+
are valid.
|
|
209
|
+
- Unsupported future `formatVersion` values must fail with actionable
|
|
210
|
+
upgrade guidance.
|
|
211
|
+
- Error payloads should include a stable `code` and remediation when the
|
|
212
|
+
command already returns structured errors.
|
|
213
|
+
- Non-zero exit behavior is part of the contract for failed verification,
|
|
214
|
+
invalid bundle verification, strict doctor gates, and invalid command
|
|
215
|
+
usage.
|
|
216
|
+
|
|
217
|
+
## Risk Mitigations
|
|
218
|
+
|
|
219
|
+
- Freezing too much can block necessary 1.x fixes. Mitigation: classify
|
|
220
|
+
exact ranking scores, prose text, and physical SQLite internals as
|
|
221
|
+
non-contractual.
|
|
222
|
+
- Freezing too little keeps GraphJSON/MCP consumers exposed to drift.
|
|
223
|
+
Mitigation: protect required JSON fields, MCP tool schemas, and CLI
|
|
224
|
+
command paths with focused contract tests.
|
|
225
|
+
- Golden fixtures can become noisy. Mitigation: keep them small,
|
|
226
|
+
fixture-driven, and focused on stable fields instead of whole large
|
|
227
|
+
outputs.
|
|
228
|
+
- Schema migration promises can exceed the MVP. Mitigation: freeze
|
|
229
|
+
version/refusal/reindex policy, not arbitrary external SQL compatibility.
|
|
230
|
+
- The source bridge is experimental. Mitigation: freeze only the report
|
|
231
|
+
wrapper and unsupported/ready states, not arbitrary third-party schemas.
|
|
232
|
+
- Pack or release smoke can be slow in this environment. Mitigation: keep
|
|
233
|
+
pack smoke as release closeout and record exact residual risk when it
|
|
234
|
+
cannot complete.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# MDGraph Release Checklist
|
|
2
|
+
|
|
3
|
+
Use this checklist before publishing an MDGraph release or asking a maintainer to cut one. It complements [CHANGELOG.md](../../CHANGELOG.md), [Output_Contracts.md](Output_Contracts.md), [Public_Contracts.md](Public_Contracts.md), and the task public check.
|
|
4
|
+
|
|
5
|
+
## Public checks
|
|
6
|
+
|
|
7
|
+
- Confirm the public package is `@daogee/mdgraph`, the installed binary remains `mdgraph`, and `package.json` / CLI versions match the release tag.
|
|
8
|
+
- Confirm [CHANGELOG.md](../../CHANGELOG.md) has an entry for the release.
|
|
9
|
+
- Review README quick start, requirements, MCP setup, output contracts, public contract labels, and known tradeoffs when public CLI/MCP behavior changed.
|
|
10
|
+
|
|
11
|
+
## 0.8 contract gate
|
|
12
|
+
|
|
13
|
+
- Confirm [Public_Contracts.md](Public_Contracts.md) labels every touched public surface as `stable`, `stable-additive`, `experimental`, `reserved`, or `internal`.
|
|
14
|
+
- Confirm focused contract tests cover MCP tool definitions, representative JSON fields, edge kinds, doctor warning shape, config defaults, and schema compatibility guidance.
|
|
15
|
+
- Confirm structured error outputs include a stable `code` and remediation where the command already returns structured errors.
|
|
16
|
+
|
|
17
|
+
## 0.9 evidence gate
|
|
18
|
+
|
|
19
|
+
- Confirm [Public_Contracts.md](Public_Contracts.md) labels context recovery fields as `stable-additive`.
|
|
20
|
+
- Confirm context, MCP, and contract tests cover `nodeId`, `documentId`, optional `sectionId`, optional `anchor`, and graph-expansion `edgePath`.
|
|
21
|
+
- Confirm `smoke:cli` exercises a multi-question structured benchmark using repository-owned fixtures.
|
|
22
|
+
- Confirm optional semantic behavior remains experimental unless a separate release explicitly freezes it.
|
|
23
|
+
|
|
24
|
+
## 1.0 readiness gate
|
|
25
|
+
|
|
26
|
+
- Confirm known output-shape inconsistencies are either normalized or intentionally documented.
|
|
27
|
+
- 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
|
+
- 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 before 1.0.
|
|
30
|
+
- 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 the 1.0 release notes call out compatibility promises separately from feature additions.
|
|
32
|
+
|
|
33
|
+
## Command gate
|
|
34
|
+
|
|
35
|
+
Run from the repository root after dependencies are installed:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm run typecheck
|
|
39
|
+
npm run build
|
|
40
|
+
npm run test:run
|
|
41
|
+
npm run smoke:cli
|
|
42
|
+
npm run smoke:eval
|
|
43
|
+
npm run smoke:pack
|
|
44
|
+
npm run smoke:clean
|
|
45
|
+
node dist/bin/mdgraph.js index --json
|
|
46
|
+
node dist/bin/mdgraph.js doctor --strict --json
|
|
47
|
+
node dist/bin/mdgraph.js status --storage --json
|
|
48
|
+
node dist/bin/mdgraph.js bundle create --profile private --json
|
|
49
|
+
node dist/bin/mdgraph.js bundle verify BUNDLE_DIR_FROM_CREATE_OUTPUT --json
|
|
50
|
+
node dist/bin/mdgraph.js report --json --eval --bundle BUNDLE_DIR_FROM_CREATE_OUTPUT
|
|
51
|
+
node dist/bin/mdgraph.js diff --base HEAD --json
|
|
52
|
+
node dist/bin/mdgraph.js report --json --base HEAD
|
|
53
|
+
node dist/bin/mdgraph.js report --json --benchmark PATH_TO_BENCHMARK_RUN_RECORDS
|
|
54
|
+
npm run task:public-check
|
|
55
|
+
git diff --check
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Expected results:
|
|
59
|
+
|
|
60
|
+
- Typecheck, tests, build, CLI smoke, and pack smoke exit 0.
|
|
61
|
+
- `doctor --strict --json` reports `staleIndex: 0` and no issue counts for the MDGraph repository.
|
|
62
|
+
- `status --storage --json` returns `{ counts, storage }` with database, object, path group, edge kind, high-degree node, and vector sections.
|
|
63
|
+
- `bundle create`, `bundle verify`, and `report --json --eval --bundle` return valid private workflow artifacts for the current repository index.
|
|
64
|
+
- `diff --base` and `report --base` return a documentation graph impact summary without replacing the current index.
|
|
65
|
+
- `report --benchmark` returns paired run-record deltas for a multi-question smoke set, reports incomplete pairs as skipped, and does not require transcripts or agent/model execution.
|
|
66
|
+
- `task:public-check` does not find tracked task artifacts under `docs/tasks/` except the allowed public files.
|
|
67
|
+
- `git diff --check` is clean. On Windows CRLF files, set repository-local `core.whitespace=cr-at-eol` if needed to avoid false positives on unchanged CRLF endings.
|
|
68
|
+
- Keep private or third-party evaluation corpora outside release artifacts and public fixtures.
|
|
69
|
+
- 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
|
+
|
|
71
|
+
## Package gate
|
|
72
|
+
|
|
73
|
+
- Inspect the tarball contents if package metadata or included public docs changed: `npm pack --dry-run`.
|
|
74
|
+
- Confirm the package includes `dist`, `README.md`, `README-ZH.md`, `CHANGELOG.md`, and `LICENSE`.
|
|
75
|
+
- Install the packed tarball globally under a clean temporary prefix and verify `mdgraph --version`, `init`, and one representative query before publishing.
|
|
76
|
+
- Confirm no `.mdgraph/`, task artifact directory, temp output, local database, or external workspace content is included.
|
|
77
|
+
|
|
78
|
+
## Note text
|
|
79
|
+
|
|
80
|
+
- Summarize user-visible CLI/MCP behavior changes.
|
|
81
|
+
- Call out output contract changes explicitly.
|
|
82
|
+
- Mention known `node:sqlite` experimental warnings only as non-failing runtime warnings.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# MDGraph Agent 集成指南
|
|
2
|
+
|
|
3
|
+
本文是 0.3 阶段面向 coding agent 的共享集成契约。不同宿主的适配应保持很薄:启动同一个 MCP server,暴露同一组五个工具,并教 agent 在直接读取 Markdown 文件前先查询 MDGraph。
|
|
4
|
+
|
|
5
|
+
## 核心行为
|
|
6
|
+
|
|
7
|
+
把 MDGraph 当作被显式邀请的文档上下文层,而不是隐藏记忆,也不是源码图谱。
|
|
8
|
+
|
|
9
|
+
1. 如果不确定工作区是否已有索引,先调用 `mdgraph_status`。
|
|
10
|
+
2. 跨文档问题优先用 `mdgraph_context`,例如设计文档、ADR、runbook、API 文档、source reference、incident 或 feature chain。如果任务已经给出项目相对文档路径或源码路径,通过 MCP `knownFiles` 传入;如果宿主上下文预算较紧,通过 `maxChars` 控制返回字符数。
|
|
11
|
+
3. 快速查关键字、实体、路径、命令、配置键、API route 或错误码时,用 `mdgraph_search`。
|
|
12
|
+
4. 已经知道文档路径、章节锚点、实体名、源码路径或 graph id 时,用 `mdgraph_node`。
|
|
13
|
+
5. 需要回答两个文档、实体或 source reference 之间如何关联时,用 `mdgraph_trace`。
|
|
14
|
+
6. 只有在索引不可用、返回上下文不足、需要精确相邻原文,或用户明确要求读文件时,才回退到 raw file reads。
|
|
15
|
+
|
|
16
|
+
对于 coding task,把任务描述写进 `mdgraph_context` 查询,并通过 `knownFiles` 传入已知文件路径。这样 MDGraph 可以返回更像 task-start documentation brief 的结果:相关文档、source refs、risk notes、provenance、确定性的 auto-mode metadata 和 `suggestedNextQueries`。
|
|
17
|
+
|
|
18
|
+
## 共享 Instruction Template
|
|
19
|
+
|
|
20
|
+
```text
|
|
21
|
+
Use MDGraph before reading multiple Markdown files manually.
|
|
22
|
+
|
|
23
|
+
- Start with mdgraph_status if index availability is unclear.
|
|
24
|
+
- Use mdgraph_context for cross-document design, ADR, runbook, API, incident, source-ref, or feature-chain questions. Include knownFiles and maxChars when the host supports MCP arguments.
|
|
25
|
+
- Use mdgraph_search for quick keyword/entity/path lookup.
|
|
26
|
+
- Use mdgraph_node for known document paths, section anchors, entities, source paths, or graph ids.
|
|
27
|
+
- Use mdgraph_trace for relationship questions between two known documents, entities, or source references.
|
|
28
|
+
- Prefer returned context when it includes enough content, reasons, provenance, source refs, and risk notes.
|
|
29
|
+
- Fall back to normal file reads when MDGraph is inactive, stale for the task, too sparse, or when exact source text is required.
|
|
30
|
+
|
|
31
|
+
Do not treat MDGraph as hidden memory, a source AST index, or an authority beyond the indexed Markdown corpus.
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## MCP 配置
|
|
35
|
+
|
|
36
|
+
先安装公开 CLI 包,所有支持 MCP 的 client 再使用相同的 stdio command:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install -g @daogee/mdgraph
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
同一套 instructions、宿主示例、配置示例和 prompt templates 也会随 [`agent-pack/`](../../agent-pack/) 发布。
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"mcpServers": {
|
|
47
|
+
"mdgraph": {
|
|
48
|
+
"type": "stdio",
|
|
49
|
+
"command": "mdgraph",
|
|
50
|
+
"args": [
|
|
51
|
+
"serve",
|
|
52
|
+
"--mcp",
|
|
53
|
+
"--path",
|
|
54
|
+
"/absolute/path/to/project"
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
依赖 MCP server 前,先在目标项目执行一次:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
mdgraph init --path /absolute/path/to/project --docs "docs/**/*.md"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
如果宿主没有继承终端的 `PATH`,请用 `which mdgraph`(macOS/Linux)或 `where mdgraph`(Windows)返回的绝对路径替换 `mdgraph`。开发场景仍可使用源码 checkout 构建出的 `dist/bin/mdgraph.js`。
|
|
68
|
+
|
|
69
|
+
## 宿主说明
|
|
70
|
+
|
|
71
|
+
| 宿主 | 配置形态 | 回退指南 |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| Claude Code | 把 MCP server 加到 project 或 user MCP config,并把共享 instruction template 放进项目指令。 | 如果 `mdgraph_status` inactive,继续使用普通文件工具,除非用户要求创建索引。 |
|
|
74
|
+
| Cursor | 在 Cursor 的 MCP settings 中添加同一个 stdio server,并把共享 instruction 放进 project rules。 | 用 MDGraph 获取 Markdown 上下文;实现细节仍用编辑器搜索或源码读取。 |
|
|
75
|
+
| Copilot Chat | 在支持 MCP 的位置添加 server,并把共享 instruction 放进 `.github/copilot-instructions.md` 或等价 workspace guidance。 | 如果 MCP tools 不可用,只有在用户要求时才手动使用 `mdgraph` CLI。 |
|
|
76
|
+
| Codex CLI | 把 stdio MCP server 加到 Codex MCP configuration,并在 repo instructions 中保留本指南。 | 大范围读文档前先查 MDGraph;未索引时回退到 shell/file tools。 |
|
|
77
|
+
| Generic MCP client | 使用上面的 JSON 配置。 | 把工具结果当作带 provenance 的文档上下文,不要当作代码执行证据。 |
|
|
78
|
+
|
|
79
|
+
## 推荐工作流
|
|
80
|
+
|
|
81
|
+
Task-start documentation brief:
|
|
82
|
+
|
|
83
|
+
1. `mdgraph_status`
|
|
84
|
+
2. 使用任务描述、`knownFiles` 和必要时的 `maxChars` 调用 `mdgraph_context`
|
|
85
|
+
3. 只对仍需确认的具体文档调用 `mdgraph_node` 或 raw file reads
|
|
86
|
+
|
|
87
|
+
关系问题:
|
|
88
|
+
|
|
89
|
+
1. 如果名称不明确,先分别用 `mdgraph_search` 定位两端
|
|
90
|
+
2. 对解析出的节点调用 `mdgraph_trace`
|
|
91
|
+
3. 如果 trace 路径还需要上下文,再调用 `mdgraph_context`
|
|
92
|
+
|
|
93
|
+
文档健康检查:
|
|
94
|
+
|
|
95
|
+
1. `mdgraph_status`
|
|
96
|
+
2. 当用户要求 docs health 或 CI gate 时,使用 CLI `mdgraph doctor --json`
|
|
97
|
+
3. 只有在 doctor 输出点名 affected documents 后才编辑原文件
|
|
98
|
+
|
|
99
|
+
## 当前限制
|
|
100
|
+
|
|
101
|
+
- MDGraph 索引 Markdown 文档,不索引源码 AST 或任意文件。
|
|
102
|
+
- MCP surface 故意保持五个工具:search、context、node、trace、status。
|
|
103
|
+
- Agent auto mode 是确定性且很窄的策略:MCP search/context 会根据 query 形态、索引规模、`knownFiles` 和 `maxChars` 选择默认 limit、depth 和字符预算;宿主侧 token budget 仍应由 agent 或 client 处理。
|
|
104
|
+
- `mdgraph_status` 会做轻量 Markdown 路径和 mtime freshness 检查;完整 stale-index hash 检查和文档健康结论仍应使用 `mdgraph doctor --json`。
|
|
105
|
+
- 结构化 with/without-MDGraph run-record delta 使用 `mdgraph report --benchmark <file>`;完整 transcript 和私有评估语料应保留在公开仓库之外。
|