@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,129 @@
|
|
|
1
|
+
---
|
|
2
|
+
implements:
|
|
3
|
+
- src/mcp/server.ts
|
|
4
|
+
- src/mcp/tools.ts
|
|
5
|
+
source_refs:
|
|
6
|
+
- src/query/context-builder.ts
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# MDGraph Agent Integration
|
|
10
|
+
|
|
11
|
+
This guide is the shared 0.3 integration contract for coding agents. Host-specific setup should stay thin: start the same MCP server, expose the same five tools, and teach the agent when to query MDGraph before reading Markdown files directly.
|
|
12
|
+
|
|
13
|
+
For active documentation editing sessions, use `serve --mcp`; the same MCP process keeps the local graph fresh by default.
|
|
14
|
+
|
|
15
|
+
## Core Behavior
|
|
16
|
+
|
|
17
|
+
Use MDGraph as an invited documentation context layer, not as hidden memory and not as a source-code graph.
|
|
18
|
+
|
|
19
|
+
1. Check `mdgraph_status` when you are not sure whether the workspace is indexed.
|
|
20
|
+
2. Use `mdgraph_context` for cross-document questions about designs, ADRs, runbooks, API docs, source references, incidents, or feature chains. Pass MCP `knownFiles` when the task already names relevant project-relative docs or source paths, and `maxChars` when the agent has a tight context budget.
|
|
21
|
+
3. Use `mdgraph_search` for quick keyword, entity, path, command, config key, API route, or error-code lookup.
|
|
22
|
+
4. Use `mdgraph_node` when you already know a document path, section anchor, entity name, source path, or graph id.
|
|
23
|
+
5. Use `mdgraph_trace` for relationship questions such as how a design depends on an ADR or how a source path connects to a runbook.
|
|
24
|
+
6. Read raw files only when the index is unavailable, the returned context is insufficient, exact neighboring prose is required, or the user explicitly asks for file-level inspection.
|
|
25
|
+
|
|
26
|
+
When MDGraph detects a stale or unknown-freshness index, query tools may prepend a `⚠️ MDGraph freshness warning` banner and include additive `freshness` metadata in `structuredContent`. Treat that as a targeted warning about result freshness — refresh the index or read the named files directly — not as evidence that the MCP server itself is broken.
|
|
27
|
+
|
|
28
|
+
For coding tasks, include the task text in the `mdgraph_context` query and pass any known file paths through `knownFiles`. This gives MDGraph enough signal to return a task-start documentation brief with relevant docs, source refs, risk notes, provenance, deterministic auto-mode metadata, and `suggestedNextQueries`.
|
|
29
|
+
|
|
30
|
+
## Shared Instruction Template
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
Use MDGraph before reading multiple Markdown files manually.
|
|
34
|
+
|
|
35
|
+
- Start with mdgraph_status if index availability is unclear.
|
|
36
|
+
- 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.
|
|
37
|
+
- Use mdgraph_search for quick keyword/entity/path lookup.
|
|
38
|
+
- Use mdgraph_node for known document paths, section anchors, entities, source paths, or graph ids.
|
|
39
|
+
- Use mdgraph_trace for relationship questions between two known documents, entities, or source references.
|
|
40
|
+
- Prefer returned context when it includes enough content, reasons, provenance, source refs, and risk notes.
|
|
41
|
+
- Fall back to normal file reads when MDGraph is inactive, stale for the task, too sparse, or when exact source text is required.
|
|
42
|
+
|
|
43
|
+
Do not treat MDGraph as hidden memory, a source AST index, or an authority beyond the indexed Markdown corpus.
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## MCP Configuration
|
|
47
|
+
|
|
48
|
+
Install the public CLI package and use the same stdio command in MCP-capable clients:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm install -g @daogee/mdgraph
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The same instructions, host examples, config example, and prompt templates are also shipped in [`agent-pack/`](../../agent-pack/).
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"mcpServers": {
|
|
59
|
+
"mdgraph": {
|
|
60
|
+
"type": "stdio",
|
|
61
|
+
"command": "mdgraph",
|
|
62
|
+
"args": [
|
|
63
|
+
"serve",
|
|
64
|
+
"--mcp",
|
|
65
|
+
"--path",
|
|
66
|
+
"/absolute/path/to/project"
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Run these once for the target project before relying on the server:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
mdgraph init --path /absolute/path/to/project --docs "docs/**/*.md"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
If the host does not inherit the shell `PATH`, replace `mdgraph` with the absolute executable path reported by `which mdgraph` (macOS/Linux) or `where mdgraph` (Windows). A source checkout and its built `dist/bin/mdgraph.js` remain valid for development.
|
|
80
|
+
|
|
81
|
+
If you prefer separate supervision, `mdgraph serve --mcp --no-watch --path /absolute/path/to/project` and `mdgraph watch --path /absolute/path/to/project` remain valid as a two-process workflow.
|
|
82
|
+
|
|
83
|
+
## Host Notes
|
|
84
|
+
|
|
85
|
+
| Host | Setup shape | Fallback guidance |
|
|
86
|
+
|---|---|---|
|
|
87
|
+
| Claude Code | Add the MCP server to the project or user MCP config with `serve --mcp`, then add the shared instruction template to project instructions. | If `mdgraph_status` is inactive, continue with normal file tools unless the user asks to index. |
|
|
88
|
+
| Cursor | Add the same stdio server in Cursor's MCP settings and keep the shared instruction in project rules. | Use MDGraph for Markdown context; use editor search/source reads for implementation details. |
|
|
89
|
+
| Copilot Chat | Add the MCP server where MCP is available and keep the shared instruction in `.github/copilot-instructions.md` or equivalent workspace guidance. | If MCP tools are unavailable, use `mdgraph` CLI manually only when the user asks. |
|
|
90
|
+
| Codex CLI | Add the stdio MCP server to the Codex MCP configuration and keep this guide in repo instructions. | Query MDGraph before broad documentation reads; fall back to shell/file tools when unindexed. |
|
|
91
|
+
| Generic MCP client | Use the JSON block above. | Treat tool results as documentation context with explicit provenance, not as code execution evidence. |
|
|
92
|
+
|
|
93
|
+
## Suggested Workflows
|
|
94
|
+
|
|
95
|
+
Task-start documentation brief:
|
|
96
|
+
|
|
97
|
+
1. Start MCP with `serve --mcp` for default live documentation freshness
|
|
98
|
+
2. `mdgraph_status`
|
|
99
|
+
3. `mdgraph_context` with the task text, `knownFiles`, and `maxChars` when the host budget is tight
|
|
100
|
+
4. `mdgraph_node` or raw file reads only for the exact documents that still need inspection
|
|
101
|
+
|
|
102
|
+
Two-process alternative:
|
|
103
|
+
|
|
104
|
+
1. Start `serve --mcp --no-watch`
|
|
105
|
+
2. Start `watch`
|
|
106
|
+
3. `mdgraph_status`
|
|
107
|
+
4. `mdgraph_context` with the task text, `knownFiles`, and `maxChars` when the host budget is tight
|
|
108
|
+
5. `mdgraph_node` or raw file reads only for the exact documents that still need inspection
|
|
109
|
+
|
|
110
|
+
Relationship question:
|
|
111
|
+
|
|
112
|
+
1. `mdgraph_search` for each side if names are fuzzy
|
|
113
|
+
2. `mdgraph_trace` between the resolved nodes
|
|
114
|
+
3. `mdgraph_context` for surrounding sections if the trace path needs explanation
|
|
115
|
+
|
|
116
|
+
Documentation health check:
|
|
117
|
+
|
|
118
|
+
1. `mdgraph_status`
|
|
119
|
+
2. CLI `mdgraph doctor --json` when the user asks for docs health or CI gating
|
|
120
|
+
3. Raw file edits only after the doctor output names affected documents
|
|
121
|
+
|
|
122
|
+
## Current Limits
|
|
123
|
+
|
|
124
|
+
- MDGraph indexes Markdown documents, not source ASTs or arbitrary files.
|
|
125
|
+
- The MCP surface intentionally stays at five tools: search, context, node, trace, and status.
|
|
126
|
+
- Agent auto mode is deterministic and narrow: MCP search/context choose default limit, depth, and character budget from query shape, index size, `knownFiles`, and `maxChars`. Token-specific host budgets should still be handled by the agent or client.
|
|
127
|
+
- `mdgraph_status` performs a lightweight Markdown path and mtime freshness check. Use `mdgraph doctor --json` for full stale-index hashing and documentation health conclusions.
|
|
128
|
+
- If a host reports an MCP/runtime failure before a tool result is returned, retry `mdgraph_status` once to distinguish a host-side tool-bridge issue from an MDGraph project issue. For server-side diagnosis, launch with `MDGRAPH_MCP_DEBUG=1` and inspect stderr for initialize / transport / tools-call boundaries.
|
|
129
|
+
- Use `mdgraph report --benchmark <file>` for structured with/without-MDGraph run-record deltas; keep full transcripts and private evaluation corpora outside the public repository.
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
---
|
|
2
|
+
implements:
|
|
3
|
+
- src/indexer.ts
|
|
4
|
+
- src/db/repositories.ts
|
|
5
|
+
- src/query/context-builder.ts
|
|
6
|
+
source_refs:
|
|
7
|
+
- src/db/schema.sql
|
|
8
|
+
- src/types.ts
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# MDGraph Architecture
|
|
12
|
+
|
|
13
|
+
MDGraph uses this implemented pipeline: scanner -> parser -> extractor/resolver -> SQLite storage -> query engine -> CLI/MCP.
|
|
14
|
+
|
|
15
|
+
## Module Map
|
|
16
|
+
|
|
17
|
+
| Area | Path | Responsibility |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| CLI | `src/bin/mdgraph.ts` | Commands for init, index, status, search, context, node, trace, eval, diff, bundle, report, export, import, semantic status, serve, watch, and doctor; doctor supports `--strict`, `--fail-on`, `--changed`, and `--since`. |
|
|
20
|
+
| Config | `src/config/load-config.ts` | Default config, `.mdgraph/config.json` creation, and safe config merging. |
|
|
21
|
+
| Scanner | `src/scanner/file-scanner.ts` | Finds Markdown files using include/exclude globs and max file size limits. |
|
|
22
|
+
| Parser | `src/parser/*` | Front matter, Markdown AST, headings, code blocks, inline code, Markdown links, and WikiLinks. |
|
|
23
|
+
| Extraction | `src/extraction/*` | Converts parsed documents into graph records and deterministic entity/edge signals. |
|
|
24
|
+
| Resolution | `src/resolution/link-resolver.ts` | Resolves Markdown and WikiLink targets to indexed documents or sections. |
|
|
25
|
+
| Storage | `src/db/*` | SQLite connection, schema, record replacement, incremental updates, graph queries, and storage diagnostics. |
|
|
26
|
+
| Query | `src/query/*` | Search ranking, context packing, and graph trace. |
|
|
27
|
+
| Evaluation | `src/evaluation/*` | Retrieval evaluation cases, expected records, and lightweight metrics for search/context/trace quality. |
|
|
28
|
+
| Benchmark | `src/benchmark/*` | Structured with/without-MDGraph agent run record parsing and paired delta aggregation. |
|
|
29
|
+
| Bundle | `src/bundle/*` | Private directory graph bundle creation and verification using schema/source/config/document hashes. |
|
|
30
|
+
| Reporting | `src/reporting/*` | CI-friendly graph workflow reports that aggregate counts, storage, doctor, eval, bundle, diff, and benchmark summaries. |
|
|
31
|
+
| Diff | `src/diff/*` | Git base-ref documentation graph diff and PR impact summary generation. |
|
|
32
|
+
| Export/Import | `src/export/*` | Deterministic GraphJSON, Mermaid, Markdown/docs-site, and read-only source bridge adapters. |
|
|
33
|
+
| Semantic | `src/semantic/*` | Deterministic local vector generation, Float32 vector codec, provider status, and cosine scoring. |
|
|
34
|
+
| MCP | `src/mcp/*` | Newline-delimited JSON-RPC MCP server and tool handlers. |
|
|
35
|
+
| Watch | `src/watcher/file-watcher.ts` | Debounced incremental reindexing via chokidar. |
|
|
36
|
+
| Analysis | `src/analysis/doctor.ts` | Documentation health and governance report. |
|
|
37
|
+
|
|
38
|
+
## Public Contract Boundary
|
|
39
|
+
|
|
40
|
+
The public contract boundary is tracked in [Public_Contracts.md](Public_Contracts.md). In short, CLI command names and documented flags, top-level CLI JSON fields, MCP tool names and input schemas, documented config fields, GraphJSON format v1, public graph record types, active edge kinds, and doctor warning shape are public surfaces. SQLite rowids, FTS shadow tables, private bundle database internals, temporary paths, and implementation helper APIs are internal.
|
|
41
|
+
|
|
42
|
+
## Data Model
|
|
43
|
+
|
|
44
|
+
The SQLite database is stored at `.mdgraph/graph.db` and created from `src/db/schema.sql`.
|
|
45
|
+
|
|
46
|
+
Primary records:
|
|
47
|
+
|
|
48
|
+
- `documents`: one row per Markdown document, with path, hash, status, type, trust tier, and metadata.
|
|
49
|
+
- `schema_metadata`: key/value metadata for current schema version, MDGraph version provenance, update time, and `current`/`legacy` baseline.
|
|
50
|
+
- `schema_migrations`: reserved audit table for future real schema migrations.
|
|
51
|
+
- `sections`: heading-bounded document regions with anchors and source line ranges. A section's content stops before the next heading at any depth; parent/child context is recovered through graph relationships rather than duplicated chunk text.
|
|
52
|
+
- `entities`: symbols, API routes, error codes, config keys, file paths, commands, packages, and concepts.
|
|
53
|
+
- `source_refs`: source/config/script paths referenced by documents.
|
|
54
|
+
- `edges`: graph relationships with kind, confidence, weight, provenance, and metadata.
|
|
55
|
+
- `chunks`: text chunks derived from section content and used by search and context packing.
|
|
56
|
+
- `chunks_fts`: external-content FTS5 index for keyword search, keyed by `chunks.rowid` so the source chunk text is not stored a second time inside FTS shadow content tables. CJK text is augmented with lightweight n-gram tokens only in the FTS index content.
|
|
57
|
+
- `chunk_vectors`: optional local semantic vectors keyed by chunk and stored as Float32 BLOB rows.
|
|
58
|
+
|
|
59
|
+
## Indexing Flow
|
|
60
|
+
|
|
61
|
+
1. `scanMarkdownFiles` selects candidate Markdown files from config.
|
|
62
|
+
2. `parseMarkdownDocument` reads front matter and Markdown structure.
|
|
63
|
+
3. `buildGraphRecords` creates documents, sections, entities, source refs, chunks, vectors, and edges.
|
|
64
|
+
4. `GraphRepository.replaceAll` writes a full rebuild, or `replaceDocuments` updates changed/deleted documents.
|
|
65
|
+
5. `indexProject` compares stored hashes to parsed hashes and chooses full or incremental mode.
|
|
66
|
+
|
|
67
|
+
Incremental mode deletes document-derived records for changed and removed files, removes their FTS terms, reinserts changed records, and prunes unreferenced global entities/source refs after cleanup. Full rebuilds optimize and vacuum the SQLite database so old FTS pages and deleted rows do not keep inflating the on-disk file.
|
|
68
|
+
|
|
69
|
+
## Storage Diagnostics
|
|
70
|
+
|
|
71
|
+
`GraphRepository.storageDiagnostics` powers `mdgraph status --storage` and the storage portion of `mdgraph doctor`. It reports SQLite page counts, freelist state, journal/WAL checkpoint state, table/index/FTS shadow object sizes when `dbstat` is available, path-group content contribution, edge-kind distribution, high-degree nodes, vector storage format, and vector provider counts.
|
|
72
|
+
|
|
73
|
+
The full storage report is read-oriented observability. `doctor` promotes only a small actionable subset into storage health warnings; it does not create graph edges from storage facts. When storage growth is unexpected, users should first check include/exclude globs and generated/dependency/temp directories, then run `mdgraph index --full` when they need a rebuild plus `VACUUM` compaction.
|
|
74
|
+
|
|
75
|
+
## Schema Metadata And Workflow Artifacts
|
|
76
|
+
|
|
77
|
+
`openDatabase` applies the current schema and records schema metadata. Databases created by the current CLI are marked with a `current` baseline. Existing databases that predate metadata are marked `legacy` after the schema table is created. If a database already declares a future schema version, MDGraph refuses to open it before applying local schema SQL, which avoids silently downgrading a newer graph.
|
|
78
|
+
|
|
79
|
+
`createGraphBundle` writes a private directory bundle under `.mdgraph/bundles/private/`. The bundle contains the SQLite graph, config snapshot, manifest, and a storage/status report. The manifest records schema version, MDGraph version, graph counts, Git provenance when available, a canonical config hash, and a source hash built from sorted document path/hash records. It deliberately omits Markdown body content and the absolute project root.
|
|
80
|
+
|
|
81
|
+
`verifyGraphBundle` is read-only. It checks manifest shape, bundled database readability, schema version, counts, source/config/document hashes, report hashes, and freshness against the current workspace when a project root is available.
|
|
82
|
+
|
|
83
|
+
`generateReport` produces a CI-friendly JSON report from the current index. It aggregates schema metadata, counts, storage diagnostics, source hashes, doctor summaries, optional eval metrics, optional bundle verification, optional graph diff, optional paired benchmark summaries, and explicit previous-report state. It does not persist hidden report history.
|
|
84
|
+
|
|
85
|
+
## Graph Diff
|
|
86
|
+
|
|
87
|
+
`generateGraphDiff` supports the PR-oriented `diff --base <ref>` path. It resolves the base Git revision, copies tracked files into a temporary directory, writes the current MDGraph config there, indexes that temporary base project, and compares the resulting graph snapshot with the current graph index.
|
|
88
|
+
|
|
89
|
+
The diff report includes Markdown document additions, modifications, deletions, renames detected by Git, section/source-ref/edge count deltas, doctor warning-code deltas, changed source refs, affected document paths, and short PR summary lines. The base index is isolated in the OS temp directory and removed after the report. Diff does not inspect source-code ASTs, does not infer runtime code impact, and does not replace the current `.mdgraph/graph.db`.
|
|
90
|
+
|
|
91
|
+
## Interoperability
|
|
92
|
+
|
|
93
|
+
`buildGraphJsonExport` produces the versioned `mdgraph-graphjson` structural export from the current index. It includes documents, sections, entities, source refs, and edges whose endpoints are present in that structural node set. It preserves the full repository `counts` for status parity and adds `exportedCounts` for the omitted chunk/vector/content boundary. The export deliberately excludes chunk content, section content, vectors, SQLite internals, and the absolute project root.
|
|
94
|
+
|
|
95
|
+
`verifyGraphJsonExport` validates GraphJSON shape, supported format version, counts, edge endpoints, and `graphHash` without opening or writing the local project database. `import graphjson --verify` is therefore an inspection path, not a merge import.
|
|
96
|
+
|
|
97
|
+
`formatTraceMermaid` renders existing `traceNodes` results as deterministic Mermaid. Markdown/docs-site exports are derived from GraphJSON facts and produce adapter data only; they do not run a site generator. The generic JSON source bridge reads an explicit MDGraph artifact and returns source-ref match summaries, but it does not create graph edges or affect indexing, query ranking, context packing, or MCP tools.
|
|
98
|
+
|
|
99
|
+
## Query Flow
|
|
100
|
+
|
|
101
|
+
`searchGraph` combines and deduplicates:
|
|
102
|
+
|
|
103
|
+
- FTS5 chunk hits, including lightweight CJK n-gram matches for continuous Chinese/Japanese/Korean text.
|
|
104
|
+
- Exact entity matches.
|
|
105
|
+
- Optional local semantic vector matches.
|
|
106
|
+
- Graph neighbors around matching entities.
|
|
107
|
+
|
|
108
|
+
When the same document or section is reached by multiple paths, search applies reciprocal rank fusion (RRF) across definition, FTS, and optional semantic channels, then keeps the highest base score while merging the main reasons and matched entities so provenance is not lost. Each fused result keeps an explainable `RRF fusion (...)` reason.
|
|
109
|
+
|
|
110
|
+
`buildContext` then starts from ranked search sections, performs bounded graph expansion through non-containment edges, orders candidates to preserve cross-document diversity before repeating sections from one document, packages selected sections under a character budget, and includes reasons such as FTS hit, semantic hit, exact entity match, or the graph edge traversal path.
|
|
111
|
+
|
|
112
|
+
When requested through `context --debug`, context building also reports seed nodes, visited nodes, expanded edges, skipped expansion reasons, candidate counts, MMR-style document-diverse packing diagnostics, and budget truncation counts. These diagnostics are not graph facts; they exist to explain context packing and evaluate retrieval quality.
|
|
113
|
+
|
|
114
|
+
`traceNodes` performs bounded graph traversal between resolved nodes and returns each step with edge kind, provenance, and confidence.
|
|
115
|
+
|
|
116
|
+
`evaluateRetrieval` runs the repository-owned alpha or CJK evaluation cases against an indexed project. It reuses `searchGraph`, `buildContext`, and `traceNodes`, then reports expected-document recall, expected-section recall, context precision, trace success, latency, returned character budget, context diversity, reason coverage, RRF channels, query mode, and optional semantic reranker status. The evaluation output is a measurement aid, not a learned ranking model and not a replacement for focused regression tests.
|
|
117
|
+
|
|
118
|
+
`generateBenchmarkReport` consumes structured `AgentRunRecord` JSON only. It pairs one `with_mdgraph` and one `without_mdgraph` record by `questionId`, reports incomplete or duplicate pairs as skipped, and calculates deltas for file reads, searches, tool calls, MDGraph calls, character/token budgets, latency, raw-file fallback, and citation correctness. It does not parse transcripts, invoke models, or host agent runs.
|
|
119
|
+
|
|
120
|
+
## MCP Boundary
|
|
121
|
+
|
|
122
|
+
The MCP server intentionally exposes only five tools. Tool output is text-first and JSON-compatible so agents can use it without needing to inspect the SQLite database or read raw files first. The server is project-bound: initialize roots and tool `projectPath` values must stay inside the served root.
|
|
123
|
+
|
|
124
|
+
## Current Tradeoffs
|
|
125
|
+
|
|
126
|
+
- The semantic provider is deterministic and local, but it is a lightweight hash embedding rather than a high-quality language model embedding. Unsupported configured providers degrade to FTS5 and graph search; `semantic status` reports provider support, vector coverage, storage format, and reindex guidance.
|
|
127
|
+
- Watch mode updates SQLite on file changes; long-running MCP freshness is achieved by default through `serve --mcp`, or by a separate `watch` process with `serve --mcp --no-watch`, with tools opening current database state on each call.
|
|
128
|
+
- Doctor checks are rule-based warnings. They first compare current files with indexed document hashes and IDs; stale indexes produce a read-only freshness diagnostic instead of mixed-time health conclusions.
|
|
129
|
+
- `doctor --changed` and `doctor --since <ref>` are Git-scoped views over the same health model; they report scope metadata, scoped graph issues, directly related one-hop graph documents, deleted-document warnings, and freshness diagnostics.
|
|
130
|
+
- Storage diagnostics are exposed through `status --storage` and reused by doctor for storage health summaries; they are not graph facts and do not expand the MCP tool surface.
|
|
131
|
+
- Private bundle artifacts are local workflow artifacts, not public exports. Public-safe sanitization and zip packaging are outside the current implementation.
|
|
132
|
+
- Benchmark reports are aggregate-only measurements from explicit structured records; full transcripts, hosted analytics, and agent runtime capture stay outside MDGraph.
|
|
133
|
+
- Interoperability adapters are read-oriented. GraphJSON verify, Mermaid/Markdown/docs-site exports, and source bridge reports do not merge external graphs into the main SQLite index.
|
|
134
|
+
- `SAME_AS`, `RELATED_TO`, and `CONTRADICTS` are reserved edge kinds in the public model. The deterministic MVP does not emit them during indexing; contradiction-like signals are currently reported by `doctor` rather than inserted as graph edges.
|
|
135
|
+
- The current implementation favors a compact MVP over broad Markdown/MDX dialect support.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# MDGraph Evaluation Questions
|
|
2
|
+
|
|
3
|
+
These questions turn the plan's agent evaluation guidance into a reusable smoke set. Use them against a realistic project documentation corpus after indexing.
|
|
4
|
+
|
|
5
|
+
The built-in CLI entry is:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
mdgraph eval --json
|
|
9
|
+
mdgraph eval --path /path/to/project --json
|
|
10
|
+
mdgraph eval --query-set cjk --path /path/to/project --json
|
|
11
|
+
mdgraph eval --query-mode semantic --json
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`mdgraph eval` runs the repository-owned alpha query set by default and reports pass/fail plus lightweight retrieval metrics. It also reports deterministic ranking diagnostics: query mode, RRF search fusion channels, MMR-style document-diverse context packing, and optional semantic reranking status. `--query-set cjk` selects a small Chinese/Japanese retrieval baseline covered by lightweight CJK n-gram preprocessing. It is a deterministic engineering smoke check, not a completed IR benchmark or real agent A/B benchmark.
|
|
15
|
+
|
|
16
|
+
1. Why does a specific error code affect a specific user flow?
|
|
17
|
+
2. Which older decisions does a given design document depend on?
|
|
18
|
+
3. Where is a specific API route defined and where is it referenced?
|
|
19
|
+
4. Which runbooks or operational notes are affected by changing a specific config key?
|
|
20
|
+
5. Which documents have been superseded by newer designs?
|
|
21
|
+
6. Which design assumptions are related to a specific incident report?
|
|
22
|
+
7. Which documents correspond to a specific source path?
|
|
23
|
+
8. Which documents mention the same entity but do not link to each other?
|
|
24
|
+
9. Which design documents are missing `source_refs`?
|
|
25
|
+
10. What is the complete documentation chain for a specific feature from requirement to implementation?
|
|
26
|
+
|
|
27
|
+
## Reference Corpus Expected Records
|
|
28
|
+
|
|
29
|
+
The repository test fixture `createAlphaFixtureDocs` defines a small reference corpus for these questions. These expected records are deterministic smoke expectations, not a completed real-agent A/B benchmark.
|
|
30
|
+
|
|
31
|
+
| ID | Query focus | Expected documents | Expected sections | Expected entities | Expected edges | Expected source refs |
|
|
32
|
+
|---|---|---|---|---|---|---|
|
|
33
|
+
| 1 | `RedisTimeoutError` impact on `LoginFlow` | `docs/redis-cache-design.md`, `docs/login-flow.md`, `docs/runbooks/auth-retry-runbook.md` | `Timeout Handling`, `Login Flow`, `Auth Retry Runbook` | `RedisTimeoutError`, `LoginFlow`, `AuthRetryRunbook` | `REFERENCES`, `DEPENDS_ON` | `src/cache/redis.ts`, `scripts/restart-auth.ps1` |
|
|
34
|
+
| 2 | Older decisions for `Auth v2 Design` | `docs/auth-v2-design.md`, `docs/adr/adr-001-cache-failure-policy.md`, `docs/redis-cache-design.md` | `Session Refresh`, `Decision`, `Timeout Handling` | `AuthService`, `CacheFailurePolicy`, `RedisTimeoutError` | `DEPENDS_ON`, `DEFINES` | `src/auth/AuthService.ts`, `src/cache/redis.ts` |
|
|
35
|
+
| 3 | Definition and references for `GET /api/auth/login` | `docs/api/login-api.md`, `docs/login-flow.md`, `docs/auth-v2-design.md` | `Login API`, `Login Flow`, `Session Refresh` | `GET /api/auth/login`, `AuthService`, `RedisTimeoutError` | `DEFINES`, `IMPLEMENTS`, `DEPENDS_ON` | `src/routes/auth.ts` |
|
|
36
|
+
| 4 | Operational impact of `AUTH_RETRY_LIMIT` | `docs/runbooks/auth-retry-runbook.md`, `docs/redis-cache-design.md`, `docs/login-flow.md` | `Auth Retry Runbook`, `Timeout Handling`, `Login Flow` | `AUTH_RETRY_LIMIT`, `AuthRetryRunbook`, `LoginFlow` | `REFERENCES`, `DEPENDS_ON` | `scripts/restart-auth.ps1` |
|
|
37
|
+
| 5 | Superseded design documents | `docs/auth-v2-design.md`, `docs/auth-v3-design.md` | `Session Refresh` in both auth design docs | `AuthService`, `AuthServiceV3` | `SUPERSEDES`, `DEPRECATED_BY` | `src/auth/AuthService.ts`, `src/auth/AuthServiceV3.ts` |
|
|
38
|
+
| 6 | Incident-related design assumptions | `docs/incidents/redis-timeout-incident.md`, `docs/redis-cache-design.md`, `docs/runbooks/auth-retry-runbook.md` | `Redis Timeout Incident`, `Timeout Handling`, `Auth Retry Runbook` | `RedisTimeoutError`, `LoginFlow`, `AuthRetryRunbook` | `DEPENDS_ON`, `REFERENCES` | `src/cache/redis.ts`, `scripts/restart-auth.ps1` |
|
|
39
|
+
| 7 | Documents for `src/routes/auth.ts` | `docs/api/login-api.md`, `docs/login-flow.md` | `Login API`, `Login Flow` | `GET /api/auth/login`, `LoginFlow` | `IMPLEMENTS`, `DEPENDS_ON` | `src/routes/auth.ts` |
|
|
40
|
+
| 8 | Same entity mentions without direct links | `docs/redis-cache-design.md`, `docs/incidents/redis-timeout-incident.md`, `docs/runbooks/auth-retry-runbook.md` | `Timeout Handling`, `Redis Timeout Incident`, `Auth Retry Runbook` | `RedisTimeoutError`, `LoginFlow` | `REFERENCES`, graph-neighbor expansion | `src/cache/redis.ts`, `scripts/restart-auth.ps1` |
|
|
41
|
+
| 9 | Designs missing `source_refs` | `docs/auth-v3-design.md` is expected to have `IMPLEMENTS`; no clean-corpus design is expected to have a stale source ref | `Session Refresh` | `AuthServiceV3` | `IMPLEMENTS` | `src/auth/AuthServiceV3.ts` |
|
|
42
|
+
| 10 | Requirement-to-implementation chain for login | `docs/login-flow.md`, `docs/api/login-api.md`, `docs/auth-v2-design.md`, `docs/redis-cache-design.md`, `docs/adr/adr-001-cache-failure-policy.md` | `Login Flow`, `Login API`, `Session Refresh`, `Timeout Handling`, `Decision` | `LoginFlow`, `GET /api/auth/login`, `AuthService`, `RedisTimeoutError`, `CacheFailurePolicy` | `DEPENDS_ON`, `IMPLEMENTS`, `DEFINES` | `src/routes/auth.ts`, `src/auth/AuthService.ts`, `src/cache/redis.ts` |
|
|
43
|
+
|
|
44
|
+
The machine-readable expected records live in `src/evaluation/retrieval-eval.ts` and are covered by `__tests__/evaluation.test.ts`.
|
|
45
|
+
|
|
46
|
+
## CJK Expected Records
|
|
47
|
+
|
|
48
|
+
The `cjk` query set is a v0.5 retrieval baseline for Chinese and Japanese Markdown. It uses expected records from the repository test fixture `createCjkFixtureDocs`, including Chinese design/API/runbook/spec documents and a Japanese design document. Its cases cover:
|
|
49
|
+
|
|
50
|
+
- Chinese spaced keyword queries such as `登录流程 缓存超时 认证重试`.
|
|
51
|
+
- Continuous Chinese natural-language phrasing such as `缓存超时影响登录流程的处理`, covered by the lightweight CJK n-gram preprocessing baseline.
|
|
52
|
+
- Mixed Latin/CJK queries for config keys, API routes, source refs, and Japanese symbols.
|
|
53
|
+
|
|
54
|
+
This query set should be used to compare future CJK tokenizer, RRF/MMR, or reranking changes against the current baseline without making remote models mandatory for indexing or search.
|
|
55
|
+
|
|
56
|
+
## Measurement Notes
|
|
57
|
+
|
|
58
|
+
For each question, compare agent behavior with and without MDGraph attached:
|
|
59
|
+
|
|
60
|
+
- Whether the final answer cites the correct documents.
|
|
61
|
+
- Number of direct file reads or text searches avoided.
|
|
62
|
+
- Whether the answer includes an explainable graph path.
|
|
63
|
+
- Whether the context returned by MDGraph is sufficient without follow-up file inspection.
|
|
64
|
+
- Time and tool-call count for the full agent run.
|
|
65
|
+
- `mdgraph eval` metrics: top-K document recall, expected-section recall, context precision, trace success, latency, returned character count, budget fit, fanout, context diversity, reason coverage, and ranking reason coverage.
|
|
66
|
+
- `mdgraph eval` ranking report: query mode, RRF search fusion channels, MMR-style context packing strategy, optional reranker status, and semantic-active case count.
|
|
67
|
+
|
|
68
|
+
Use `mdgraph report --benchmark benchmark-runs.json --json` for v0.6 A/B reporting on these questions. It consumes structured run records and reports aggregate deltas; full transcripts should remain outside public docs.
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# MDGraph Output Contracts
|
|
2
|
+
|
|
3
|
+
This document records the stable top-level JSON shapes for the current CLI surface. Nested record fields follow the public TypeScript model in `src/types.ts` unless noted otherwise. Stability labels, compatibility rules, and 1.0 readiness criteria are tracked in [Public_Contracts.md](Public_Contracts.md).
|
|
4
|
+
|
|
5
|
+
## `index --json`
|
|
6
|
+
|
|
7
|
+
`mdgraph index --json` returns an object with:
|
|
8
|
+
|
|
9
|
+
- `files`, `changed`, `deleted`, `unchanged`, `skipped`: numeric indexing counters.
|
|
10
|
+
- `skippedFiles`: skipped Markdown files with project-relative `path` and `reason` when a file cannot be parsed inside resource budgets.
|
|
11
|
+
- `mode`: `full` or `incremental`.
|
|
12
|
+
- `counts`: graph counts with `documents`, `sections`, `entities`, `sourceRefs`, `edges`, `chunks`, and `vectors`.
|
|
13
|
+
|
|
14
|
+
## `status --json`
|
|
15
|
+
|
|
16
|
+
`mdgraph status --json` returns graph counts directly:
|
|
17
|
+
|
|
18
|
+
- `documents`, `sections`, `entities`, `sourceRefs`, `edges`, `chunks`, `vectors`.
|
|
19
|
+
|
|
20
|
+
If no index exists, it returns:
|
|
21
|
+
|
|
22
|
+
- `indexed: false`, `projectRoot`, `database`.
|
|
23
|
+
|
|
24
|
+
`mdgraph status --freshness --json` keeps the default status shape additive by returning:
|
|
25
|
+
|
|
26
|
+
- `counts`: the same graph counts as `status --json`.
|
|
27
|
+
- `freshness`: lightweight freshness diagnostics with `state` (`fresh`, `stale`, or `unknown`), `recommendation`, optional `lastIndexedAt`, optional `checkedAt`, and optional `issues` entries with `path` and reason (`added`, `modified`, or `deleted`).
|
|
28
|
+
`mdgraph status --storage --json` returns:
|
|
29
|
+
|
|
30
|
+
- `counts`: the same graph counts as `status --json`.
|
|
31
|
+
- `storage.database`: `pageSize`, `pageCount`, `freelistCount`, `estimatedBytes`, `journalMode`, and `walCheckpoint`.
|
|
32
|
+
- `storage.objects`: `dbstatAvailable` plus table/index/FTS shadow object entries.
|
|
33
|
+
- `storage.pathGroups`: document and chunk content contribution grouped by top-level path.
|
|
34
|
+
- `storage.edgeKinds`: edge count and average score data by edge kind.
|
|
35
|
+
- `storage.highDegreeNodes`: highest non-containment graph degree nodes.
|
|
36
|
+
- `storage.vectors`: `total`, compact storage `format`, and provider/model/dimension breakdown.
|
|
37
|
+
|
|
38
|
+
When `--storage` and `--freshness` are combined, the JSON object includes `counts`, `storage`, and `freshness`.
|
|
39
|
+
|
|
40
|
+
## `usage --json`
|
|
41
|
+
|
|
42
|
+
`mdgraph usage --json` returns an agent-friendly workflow guide:
|
|
43
|
+
|
|
44
|
+
- `projectRoot`: resolved project root used in examples.
|
|
45
|
+
- `commonOptions`: CLI options that are broadly useful to agents and scripts.
|
|
46
|
+
- `workflows`: named workflow entries with `name`, `purpose`, `commands`, and optional `notes`.
|
|
47
|
+
|
|
48
|
+
The text form prints the same workflow groups for humans. `usage` does not read or write the graph index.
|
|
49
|
+
## `search --json`
|
|
50
|
+
|
|
51
|
+
`mdgraph search <query> --json` returns an array of search results. Each result has:
|
|
52
|
+
|
|
53
|
+
- `document`: graph document record.
|
|
54
|
+
- `section`: optional graph section record.
|
|
55
|
+
- `score`: numeric ranking score.
|
|
56
|
+
- `reason`: explanation for why the result matched.
|
|
57
|
+
- `content`: selected chunk or section content.
|
|
58
|
+
- `matchedEntities`: graph entity records that contributed to the match.
|
|
59
|
+
- `semantic`: optional semantic match metadata with `source`, `provider`, `model`, and `confidence`.
|
|
60
|
+
|
|
61
|
+
`mdgraph search <query> --explain --json` returns:
|
|
62
|
+
|
|
63
|
+
- `query`, `limit`, `queryMode`, `entityCandidates`, `ftsQuery`, `semanticEnabled`, and `semanticActive`.
|
|
64
|
+
- `ranking`: `fusion`, `fusionK`, `channels`, and `optionalReranker`.
|
|
65
|
+
- `matchedEntities`: entity names, kinds, and document frequencies used by ranking diagnostics.
|
|
66
|
+
- `results`: the same search result records returned by `search --json`.
|
|
67
|
+
|
|
68
|
+
## `context --json`
|
|
69
|
+
|
|
70
|
+
`mdgraph context <query> --json` returns:
|
|
71
|
+
|
|
72
|
+
- `query`: original query text.
|
|
73
|
+
- `maxChars`: configured context budget.
|
|
74
|
+
- `usedChars`: packed character count.
|
|
75
|
+
- `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
|
+
|
|
77
|
+
`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.
|
|
78
|
+
|
|
79
|
+
`nodeId`, `documentId`, `sectionId`, `anchor`, and `lines` are recovery fields for moving from a packed context item to `node`, `trace`, or raw Markdown. `edgePath` is present when graph expansion contributes the item; each step includes `fromId`, `fromLabel`, `edgeFromId`, `edgeToId`, `edgeKind`, `toId`, `toLabel`, `traversalDirection`, `confidence`, and `provenance`.
|
|
80
|
+
|
|
81
|
+
`mdgraph context <query> --debug --json` keeps the same fields and adds `debug` with:
|
|
82
|
+
|
|
83
|
+
- `seedNodes`, `visitedNodes`, and `expandedEdges`.
|
|
84
|
+
- `skippedVisitedNodes`, `skippedByNodeLimit`, and `skippedByDepth`.
|
|
85
|
+
- `candidateCount`, `directCandidates`, and `expandedCandidates`.
|
|
86
|
+
- `packingStrategy`, `packedItems`, `packedUniqueDocuments`, and `packingDiversityRatio`.
|
|
87
|
+
- `budgetTruncatedItems` and `budgetSkippedItems`.
|
|
88
|
+
|
|
89
|
+
## `node --json`
|
|
90
|
+
|
|
91
|
+
`mdgraph node <query> --json` returns the resolved node record when found:
|
|
92
|
+
|
|
93
|
+
- `id`, `label`, `kind`, `data`.
|
|
94
|
+
|
|
95
|
+
When a section query is ambiguous, it returns:
|
|
96
|
+
|
|
97
|
+
- `error: "ambiguous_section"`, `query`, `candidates`.
|
|
98
|
+
|
|
99
|
+
When no node is found, it returns:
|
|
100
|
+
|
|
101
|
+
- `error: "not_found"`, `query`.
|
|
102
|
+
|
|
103
|
+
## `trace --json`
|
|
104
|
+
|
|
105
|
+
`mdgraph trace <from> <to> --json` returns:
|
|
106
|
+
|
|
107
|
+
- `from`, `to`, `found`, `steps`, optional `message`.
|
|
108
|
+
- Each step includes `fromId`, `fromLabel`, `edgeFromId`, `edgeToId`, `edgeKind`, `toId`, `toLabel`, `traversalDirection`, `confidence`, and `provenance`.
|
|
109
|
+
|
|
110
|
+
## `eval --json`
|
|
111
|
+
|
|
112
|
+
`mdgraph eval --json` runs the built-in alpha retrieval evaluation cases against an indexed project and returns:
|
|
113
|
+
|
|
114
|
+
- `querySet`: `alpha` by default or `cjk` when `--query-set cjk` is provided.
|
|
115
|
+
- `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, and average context diversity.
|
|
117
|
+
- `generatedAt`: ISO timestamp for the evaluation run.
|
|
118
|
+
- `summary`: `cases`, `passed`, `failed`, `averageTopKDocumentRecall`, `averageExpectedSectionRecall`, `averageContextPrecision`, `averageContextDiversity`, `averageLatencyMs`, and `averageReturnedChars`.
|
|
119
|
+
- `cases`: per-case results with `id`, `query`, `passed`, `expected`, `observed`, and `metrics`.
|
|
120
|
+
|
|
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. 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
|
+
|
|
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 local semantic reranker was active.
|
|
124
|
+
|
|
125
|
+
## `export graphjson --json`
|
|
126
|
+
|
|
127
|
+
`mdgraph export graphjson --json` returns a deterministic structural interoperability export:
|
|
128
|
+
|
|
129
|
+
- `format: "mdgraph-graphjson"` and `formatVersion: 1`.
|
|
130
|
+
- `schemaVersion`, `mdgraphVersion`, `exportProfile: "structural"`, `graphHash`, and `sourceHash`.
|
|
131
|
+
- `counts`: the full repository counts returned by `status --json`.
|
|
132
|
+
- `exportedCounts`: exported document, section, entity, source-ref, node, and edge counts.
|
|
133
|
+
- `nodes`: document, section, entity, and source-ref nodes.
|
|
134
|
+
- `edges`: structural edges whose endpoints are included in `nodes`.
|
|
135
|
+
|
|
136
|
+
The structural profile excludes chunks, chunk content, section content, vectors, SQLite rowids, SQLite database paths, and the absolute project root. `counts.edges` can be larger than `exportedCounts.edges` because chunk endpoint edges are omitted.
|
|
137
|
+
|
|
138
|
+
## `import graphjson --verify --json`
|
|
139
|
+
|
|
140
|
+
`mdgraph import graphjson graph.json --verify --json` verifies a GraphJSON file without writing `.mdgraph/graph.db` and returns:
|
|
141
|
+
|
|
142
|
+
- `valid`: boolean result.
|
|
143
|
+
- `errors`: structured validation errors with `code`, `message`, optional `evidence`, and `remediation`.
|
|
144
|
+
- `warnings`: non-fatal compatibility notes.
|
|
145
|
+
- `format`, `formatVersion`, `schemaVersion`, `graphHash`, `counts`, and `exportedCounts` when readable.
|
|
146
|
+
|
|
147
|
+
The command exits non-zero when `valid` is `false`. GraphJSON merge import is not supported in 0.7. Oversized or deeply nested GraphJSON files are rejected before verification.
|
|
148
|
+
|
|
149
|
+
## `export mermaid trace --json`
|
|
150
|
+
|
|
151
|
+
`mdgraph export mermaid trace <from> <to> --json` returns:
|
|
152
|
+
|
|
153
|
+
- `format: "mdgraph-mermaid"` and `formatVersion: 1`.
|
|
154
|
+
- `diagramType: "trace"`.
|
|
155
|
+
- `found`: whether the graph trace was found.
|
|
156
|
+
- `diagram`: Mermaid flowchart text.
|
|
157
|
+
- `trace`: the same trace result shape returned by `trace --json`.
|
|
158
|
+
|
|
159
|
+
Without `--json`, the command prints only Mermaid text. The diagram renders existing graph trace facts; it does not generate an LLM summary.
|
|
160
|
+
|
|
161
|
+
## `export docs-site --json`
|
|
162
|
+
|
|
163
|
+
`mdgraph export docs-site --json` returns:
|
|
164
|
+
|
|
165
|
+
- `format: "mdgraph-docsite-index"` and `formatVersion: 1`.
|
|
166
|
+
- `sourceFormat: "mdgraph-graphjson"` and `graphHash`.
|
|
167
|
+
- `documents`: per-document path, title, status, document type, trust tier, defined entities, source refs, outbound links, and inbound links.
|
|
168
|
+
|
|
169
|
+
`mdgraph export markdown-index` prints a WikiLink-based Markdown view over the same graph facts.
|
|
170
|
+
|
|
171
|
+
## `export source-bridge --json`
|
|
172
|
+
|
|
173
|
+
`mdgraph export source-bridge --provider json --artifact source-bridge.json --json` returns a read-only source bridge report:
|
|
174
|
+
|
|
175
|
+
- `format: "mdgraph-source-bridge"` and `formatVersion: 1`.
|
|
176
|
+
- `provider: "json"`.
|
|
177
|
+
- `status`: `ready` or `unsupported`.
|
|
178
|
+
- `reason`: unsupported/skipped reason when available.
|
|
179
|
+
- `sourceRefs`, `matched`, and `unmatched`.
|
|
180
|
+
|
|
181
|
+
The bridge reads only an explicit MDGraph JSON artifact with a `files` array containing project-relative paths and optional symbol summaries. It rejects oversized or deeply nested JSON before matching, does not create graph edges, and does not affect indexing, search, context, or MCP tools.
|
|
182
|
+
|
|
183
|
+
## `bundle create --json`
|
|
184
|
+
|
|
185
|
+
`mdgraph bundle create --profile private --json` creates a private directory artifact under `.mdgraph/bundles/private/` and returns:
|
|
186
|
+
|
|
187
|
+
- `bundleDir`: absolute path to the created bundle directory.
|
|
188
|
+
- `manifestPath`: absolute path to `manifest.json`.
|
|
189
|
+
- `manifest`: bundle manifest with `format`, `formatVersion`, `schemaVersion`, `mdgraphVersion`, `createdAt`, `visibility`, `sourceHash`, `configHash`, `provenance`, `counts`, `documents`, and optional `reports`.
|
|
190
|
+
|
|
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 in 0.6.
|
|
192
|
+
|
|
193
|
+
## `bundle verify --json`
|
|
194
|
+
|
|
195
|
+
`mdgraph bundle verify <dir> --json` returns:
|
|
196
|
+
|
|
197
|
+
- `bundleDir`: absolute path to the checked bundle directory.
|
|
198
|
+
- `valid`: boolean result.
|
|
199
|
+
- `errors`: validation failures.
|
|
200
|
+
- `manifest`: parsed manifest when readable.
|
|
201
|
+
- `counts`: graph counts read from bundled `graph.db` when available.
|
|
202
|
+
- `schemaVersion`, `sourceHash`, and `configHash`: recomputed bundled values when available.
|
|
203
|
+
- `freshness`: `state` (`fresh`, `stale`, or `unknown`) plus `reason`, comparing the bundle source hash to the current workspace when possible.
|
|
204
|
+
|
|
205
|
+
The command exits non-zero when `valid` is `false`.
|
|
206
|
+
|
|
207
|
+
## `report --json`
|
|
208
|
+
|
|
209
|
+
`mdgraph report --json` returns a CI-friendly graph workflow report:
|
|
210
|
+
|
|
211
|
+
- `projectRoot`, `generatedAt`, `mdgraphVersion`, and `indexed`.
|
|
212
|
+
- `schema`: schema metadata with `schemaVersion`, `createdByVersion`, `updatedAt`, and `baseline` when indexed.
|
|
213
|
+
- `counts`, `storage`, and `source`: graph counts, storage diagnostics, and source/config/document hashes when indexed.
|
|
214
|
+
- `doctor`: doctor summary, warning counts, and top warning codes when indexed.
|
|
215
|
+
- `eval`: evaluation query set, summary, and ranking metadata when `--eval` is supplied.
|
|
216
|
+
- `bundle`: bundle verification result when `--bundle <dir>` is supplied.
|
|
217
|
+
- `diff`: graph diff result when `--base <ref>` is supplied.
|
|
218
|
+
- `benchmark`: paired benchmark result when `--benchmark <file>` is supplied.
|
|
219
|
+
- `trend`: `first_run`, `previous_report_loaded`, or `previous_report_missing`. Trend state only reflects an explicit `--previous-report <file>` input; MDGraph does not write hidden report history.
|
|
220
|
+
|
|
221
|
+
## `report --benchmark <file> --json`
|
|
222
|
+
|
|
223
|
+
`mdgraph report --benchmark benchmark-runs.json --json` reads structured agent run records and embeds a `benchmark` object in the report. The input must be either a JSON array of run records or an object with a `runs` array. MDGraph does not parse full transcripts, call models, or run an agent.
|
|
224
|
+
|
|
225
|
+
Each `AgentRunRecord` includes `id`, `questionId`, `question`, `mode` (`with_mdgraph` or `without_mdgraph`), timestamps, `toolCalls`, `directFileReads`, `textSearches`, `mdgraphCalls`, `finalCitations`, `rawFileFallback`, optional `tokenEstimate`, optional `characterBudget`, and `latencyMs`.
|
|
226
|
+
|
|
227
|
+
The embedded `benchmark` object returns:
|
|
228
|
+
|
|
229
|
+
- `format: "mdgraph-benchmark"` and `formatVersion: 1`.
|
|
230
|
+
- `records`: number of parsed run records.
|
|
231
|
+
- `summary`: question count, complete pair count, skipped pair count, and aggregate deltas. Deltas are `with_mdgraph - without_mdgraph`.
|
|
232
|
+
- `pairs`: one entry per complete pair, each with `withMdgraph`, `withoutMdgraph`, and `delta` metrics for file reads, text searches, tool calls, MDGraph calls, character/token budgets, latency, raw-file fallback, and citation correctness.
|
|
233
|
+
- `skipped`: incomplete, duplicate, or question-text-mismatched pairs. Exactly one `with_mdgraph` and one `without_mdgraph` record are required for a complete pair.
|
|
234
|
+
|
|
235
|
+
Citation correctness is automatic when `questionId` matches a built-in evaluation case: cited paths are compared with expected document/section paths. For non-evaluation questions, citations use explicit `correct: true`, `correct: false`, or `correct: "unknown"` markers from the run record. `unknown` citations are counted separately and excluded from correctness percentages.
|
|
236
|
+
|
|
237
|
+
## `diff --json`
|
|
238
|
+
|
|
239
|
+
`mdgraph diff --base <ref> --json` compares the current indexed graph to an isolated temporary index built from a Git base revision and returns:
|
|
240
|
+
|
|
241
|
+
- `mode`: currently `base_ref`.
|
|
242
|
+
- `base`: requested `ref`, resolved Git `revision`, and base `sourceHash`.
|
|
243
|
+
- `head`: current graph `sourceHash`.
|
|
244
|
+
- `summary`: `documentsAdded`, `documentsModified`, `documentsDeleted`, `documentsRenamed`, `sectionsChanged`, `sourceRefsChanged`, `edgesChanged`, and `warningDelta`.
|
|
245
|
+
- `documents`: changed Markdown document entries with `path`, optional `previousPath`, `change`, `hashChanged`, optional `statusChanged`, `sectionDelta`, `sourceRefDelta`, and optional `warningCodes`.
|
|
246
|
+
- `impact`: `changedSourceRefs`, `affectedDocs`, and concise `prSummary` lines.
|
|
247
|
+
|
|
248
|
+
Diff only compares Markdown graph records, source refs, and doctor warning codes. It does not parse source ASTs or infer runtime code impact. The base index is created in a temporary directory and does not replace the current `.mdgraph/graph.db`.
|
|
249
|
+
|
|
250
|
+
## `semantic status --json`
|
|
251
|
+
|
|
252
|
+
`mdgraph semantic status --json` returns:
|
|
253
|
+
|
|
254
|
+
- `projectRoot`.
|
|
255
|
+
- `state`: `disabled`, `not_indexed`, `ready`, `unsupported_provider`, or `needs_reindex`.
|
|
256
|
+
- `enabled`, `provider`, `model`, `dimensions`, and `providerSupported` for the configured embedding provider.
|
|
257
|
+
- `indexed`, `chunks`, `vectors`, `vectorStorageFormat`, and `indexedProviders`.
|
|
258
|
+
- `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
|
+
|
|
260
|
+
## `doctor --json`
|
|
261
|
+
|
|
262
|
+
`mdgraph doctor --json` returns:
|
|
263
|
+
|
|
264
|
+
- `projectRoot`.
|
|
265
|
+
- `scope`: `mode`, `baseRef`, `changedPaths`, `deletedPaths`, `renamedPaths`, `untrackedPaths`, and `globalHealthIncluded`.
|
|
266
|
+
- `summary`: `documents`, `orphanDocs`, `deadLinks`, `staleSourceRefs`, `missingDefinitions`, `weaklyLinkedDocs`, `possibleContradictions`, `contentRisks`, and `staleIndex`.
|
|
267
|
+
- `staleIndex`: `stale`, `recommendation`, and `issues`.
|
|
268
|
+
- Issue arrays: `orphanDocs`, `deadLinks`, `staleSourceRefs`, `missingDefinitions`, `weaklyLinkedDocs`, `possibleContradictions`, `contentRisks`, and `frontmatterDiagnostics`.
|
|
269
|
+
- `warnings`: typed, action-oriented doctor warnings. Each warning includes `code`, `severity`, `message`, `evidence`, `affectedNodes`, and `remediation`.
|
|
270
|
+
- `health`: `graph` and `storage` summaries. Graph health includes `mostConnectedDocs`, `weaklyLinkedDocs`, `duplicateDefinitions`, `missingDefinitions`, and `missingDecisionLinks`. Storage health includes database size, path groups, FTS shadow sizing, high-degree nodes, vector counts, and storage warnings.
|
|
271
|
+
|
|
272
|
+
Initial warning codes cover the existing doctor checks, front matter diagnostics, lifecycle governance, graph health, storage health, parse failures, and conservative convention linting: `index.stale`, `link.dead`, `source_ref.missing`, `definition.missing`, `definition.duplicate`, `content.risk`, `document.orphan`, `document.deleted`, `document.weakly_linked`, `document.deprecated_referenced`, `document.superseded_referenced`, `document.parse_failed`, `graph.missing_decision_link`, `storage.generated_path_indexed`, `storage.database_oversized`, `storage.fts_shadow_large`, `storage.high_degree_node`, `storage.vector_anomaly`, `front_matter.invalid_yaml`, `front_matter.not_mapping`, `front_matter.unclosed`, `front_matter.invalid_field`, `tag.invalid_format`, and `link.non_posix_path`.
|
|
273
|
+
|
|
274
|
+
`mdgraph doctor --strict` keeps the same output shape and exits with a non-zero status when any summary issue count other than `documents` is greater than zero. `mdgraph doctor --fail-on <severity>` adds a typed warning gate without changing `--strict`, and `--changed` / `--since <ref>` return scoped reports with explicit scope metadata. Scoped reports include scoped Markdown paths plus directly related one-hop graph documents; deleted Markdown paths are preserved in scope metadata and reported with `document.deleted` after the index is fresh. Global storage summaries may still be present for observability, but storage warnings are omitted when `globalHealthIncluded` is `false`.
|