@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.
Files changed (121) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +21 -0
  3. package/README-ZH.md +203 -0
  4. package/README.md +203 -0
  5. package/agent-pack/README.md +26 -0
  6. package/agent-pack/host-examples.md +71 -0
  7. package/agent-pack/mcp-config.example.json +14 -0
  8. package/agent-pack/mdgraph-agent-instructions.md +21 -0
  9. package/agent-pack/prompts/relationship-trace.md +12 -0
  10. package/agent-pack/prompts/status-doctor.md +13 -0
  11. package/agent-pack/prompts/task-start-context.md +15 -0
  12. package/dist/analysis/doctor-scope.d.ts +8 -0
  13. package/dist/analysis/doctor-scope.js +109 -0
  14. package/dist/analysis/doctor.d.ts +148 -0
  15. package/dist/analysis/doctor.js +919 -0
  16. package/dist/analysis/status-freshness.d.ts +13 -0
  17. package/dist/analysis/status-freshness.js +55 -0
  18. package/dist/benchmark/benchmark.d.ts +118 -0
  19. package/dist/benchmark/benchmark.js +357 -0
  20. package/dist/bin/mdgraph.d.ts +2 -0
  21. package/dist/bin/mdgraph.js +877 -0
  22. package/dist/bundle/bundle.d.ts +66 -0
  23. package/dist/bundle/bundle.js +320 -0
  24. package/dist/config/limits.d.ts +24 -0
  25. package/dist/config/limits.js +24 -0
  26. package/dist/config/load-config.d.ts +14 -0
  27. package/dist/config/load-config.js +177 -0
  28. package/dist/db/connection.d.ts +15 -0
  29. package/dist/db/connection.js +145 -0
  30. package/dist/db/repositories.d.ts +159 -0
  31. package/dist/db/repositories.js +929 -0
  32. package/dist/db/schema.sql +110 -0
  33. package/dist/db/sqlite-adapter.d.ts +18 -0
  34. package/dist/db/sqlite-adapter.js +60 -0
  35. package/dist/diff/graph-diff.d.ts +41 -0
  36. package/dist/diff/graph-diff.js +334 -0
  37. package/dist/evaluation/retrieval-eval.d.ts +115 -0
  38. package/dist/evaluation/retrieval-eval.js +399 -0
  39. package/dist/export/diagram.d.ts +11 -0
  40. package/dist/export/diagram.js +41 -0
  41. package/dist/export/graphjson.d.ts +89 -0
  42. package/dist/export/graphjson.js +299 -0
  43. package/dist/export/markdown-index.d.ts +21 -0
  44. package/dist/export/markdown-index.js +89 -0
  45. package/dist/export/source-bridge.d.ts +22 -0
  46. package/dist/export/source-bridge.js +83 -0
  47. package/dist/extraction/entity-extractor.d.ts +12 -0
  48. package/dist/extraction/entity-extractor.js +153 -0
  49. package/dist/extraction/graph-builder.d.ts +2 -0
  50. package/dist/extraction/graph-builder.js +168 -0
  51. package/dist/index.d.ts +28 -0
  52. package/dist/index.js +28 -0
  53. package/dist/indexer.d.ts +19 -0
  54. package/dist/indexer.js +100 -0
  55. package/dist/mcp/debug.d.ts +7 -0
  56. package/dist/mcp/debug.js +41 -0
  57. package/dist/mcp/server-instructions.d.ts +2 -0
  58. package/dist/mcp/server-instructions.js +40 -0
  59. package/dist/mcp/server.d.ts +28 -0
  60. package/dist/mcp/server.js +232 -0
  61. package/dist/mcp/tools.d.ts +31 -0
  62. package/dist/mcp/tools.js +506 -0
  63. package/dist/mcp/transport.d.ts +50 -0
  64. package/dist/mcp/transport.js +88 -0
  65. package/dist/parser/frontmatter.d.ts +10 -0
  66. package/dist/parser/frontmatter.js +191 -0
  67. package/dist/parser/links.d.ts +6 -0
  68. package/dist/parser/links.js +9 -0
  69. package/dist/parser/markdown-parser.d.ts +2 -0
  70. package/dist/parser/markdown-parser.js +267 -0
  71. package/dist/query/context-builder.d.ts +85 -0
  72. package/dist/query/context-builder.js +413 -0
  73. package/dist/query/search.d.ts +32 -0
  74. package/dist/query/search.js +237 -0
  75. package/dist/query/trace.d.ts +10 -0
  76. package/dist/query/trace.js +55 -0
  77. package/dist/reporting/report.d.ts +49 -0
  78. package/dist/reporting/report.js +143 -0
  79. package/dist/resolution/link-resolver.d.ts +17 -0
  80. package/dist/resolution/link-resolver.js +113 -0
  81. package/dist/scanner/file-scanner.d.ts +4 -0
  82. package/dist/scanner/file-scanner.js +144 -0
  83. package/dist/semantic/local-embedding.d.ts +4 -0
  84. package/dist/semantic/local-embedding.js +30 -0
  85. package/dist/semantic/status.d.ts +19 -0
  86. package/dist/semantic/status.js +70 -0
  87. package/dist/semantic/vector-codec.d.ts +3 -0
  88. package/dist/semantic/vector-codec.js +35 -0
  89. package/dist/types.d.ts +198 -0
  90. package/dist/types.js +15 -0
  91. package/dist/utils/bounded-json.d.ts +9 -0
  92. package/dist/utils/bounded-json.js +57 -0
  93. package/dist/utils/content-risk.d.ts +5 -0
  94. package/dist/utils/content-risk.js +20 -0
  95. package/dist/utils/fts.d.ts +3 -0
  96. package/dist/utils/fts.js +52 -0
  97. package/dist/utils/id.d.ts +2 -0
  98. package/dist/utils/id.js +8 -0
  99. package/dist/utils/path-safety.d.ts +4 -0
  100. package/dist/utils/path-safety.js +25 -0
  101. package/dist/utils/text.d.ts +7 -0
  102. package/dist/utils/text.js +36 -0
  103. package/dist/version.d.ts +1 -0
  104. package/dist/version.js +11 -0
  105. package/dist/watcher/file-watcher.d.ts +11 -0
  106. package/dist/watcher/file-watcher.js +127 -0
  107. package/docs/EN/Agent_Integration.md +129 -0
  108. package/docs/EN/Architecture.md +135 -0
  109. package/docs/EN/Evaluation_Questions.md +68 -0
  110. package/docs/EN/Output_Contracts.md +274 -0
  111. package/docs/EN/Public_Contracts.md +88 -0
  112. package/docs/EN/Public_Contracts_1.0.md +234 -0
  113. package/docs/EN/Release_Checklist.md +82 -0
  114. package/docs/ZH/Agent_Integration.md +105 -0
  115. package/docs/ZH/Architecture.md +124 -0
  116. package/docs/ZH/Evaluation_Questions.md +66 -0
  117. package/docs/ZH/Output_Contracts.md +269 -0
  118. package/docs/ZH/Public_Contracts.md +81 -0
  119. package/docs/ZH/Public_Contracts_1.0.md +202 -0
  120. package/docs/ZH/Release_Checklist.md +83 -0
  121. package/package.json +94 -0
@@ -0,0 +1,109 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { normalizePath } from "../utils/text.js";
3
+ export function collectDoctorScope(projectRoot, request) {
4
+ ensureGitWorktree(projectRoot);
5
+ ensureGitHead(projectRoot);
6
+ if (request.mode === "changed") {
7
+ const unstaged = parseNameStatus(runGit(projectRoot, ["diff", "--name-status", "-M", "--", "."]));
8
+ const staged = parseNameStatus(runGit(projectRoot, ["diff", "--cached", "--name-status", "-M", "--", "."]));
9
+ const untrackedPaths = runGit(projectRoot, ["ls-files", "--others", "--exclude-standard"])
10
+ .split(/\r?\n/)
11
+ .map(markdownPath)
12
+ .filter((value) => Boolean(value));
13
+ return scopeFromParts("changed", undefined, mergeNameStatus(unstaged, staged), untrackedPaths);
14
+ }
15
+ const baseRef = validateBaseRef(request.baseRef);
16
+ const diff = parseNameStatus(runGit(projectRoot, ["diff", "--name-status", "-M", "--end-of-options", `${baseRef}...HEAD`, "--", "."]));
17
+ return scopeFromParts("since", baseRef, diff, []);
18
+ }
19
+ function scopeFromParts(mode, baseRef, parsed, untrackedPaths) {
20
+ return {
21
+ mode,
22
+ baseRef,
23
+ changedPaths: uniqueSorted(parsed.changedPaths),
24
+ deletedPaths: uniqueSorted(parsed.deletedPaths),
25
+ renamedPaths: uniqueRenames(parsed.renamedPaths),
26
+ untrackedPaths: uniqueSorted(untrackedPaths),
27
+ globalHealthIncluded: false
28
+ };
29
+ }
30
+ function mergeNameStatus(left, right) {
31
+ return {
32
+ changedPaths: [...left.changedPaths, ...right.changedPaths],
33
+ deletedPaths: [...left.deletedPaths, ...right.deletedPaths],
34
+ renamedPaths: [...left.renamedPaths, ...right.renamedPaths]
35
+ };
36
+ }
37
+ function parseNameStatus(output) {
38
+ const result = { changedPaths: [], deletedPaths: [], renamedPaths: [] };
39
+ for (const line of output.split(/\r?\n/)) {
40
+ if (!line.trim()) {
41
+ continue;
42
+ }
43
+ const [status, firstPath, secondPath] = line.split("\t");
44
+ if (!status || !firstPath) {
45
+ continue;
46
+ }
47
+ if (status.startsWith("R") && secondPath) {
48
+ const from = markdownPath(firstPath);
49
+ const to = markdownPath(secondPath);
50
+ if (from || to) {
51
+ result.renamedPaths.push({ from: from ?? normalizePath(firstPath), to: to ?? normalizePath(secondPath) });
52
+ if (to) {
53
+ result.changedPaths.push(to);
54
+ }
55
+ }
56
+ continue;
57
+ }
58
+ const normalized = markdownPath(firstPath);
59
+ if (!normalized) {
60
+ continue;
61
+ }
62
+ if (status.startsWith("D")) {
63
+ result.deletedPaths.push(normalized);
64
+ }
65
+ else {
66
+ result.changedPaths.push(normalized);
67
+ }
68
+ }
69
+ return result;
70
+ }
71
+ function markdownPath(value) {
72
+ const normalized = normalizePath(value).replace(/^\.\//, "");
73
+ return /\.mdx?$/i.test(normalized) ? normalized : undefined;
74
+ }
75
+ function ensureGitWorktree(projectRoot) {
76
+ const output = runGit(projectRoot, ["rev-parse", "--is-inside-work-tree"]).trim();
77
+ if (output !== "true") {
78
+ throw new Error("doctor scoped checks require a Git worktree.");
79
+ }
80
+ }
81
+ function ensureGitHead(projectRoot) {
82
+ runGit(projectRoot, ["rev-parse", "--verify", "HEAD"]);
83
+ }
84
+ function validateBaseRef(baseRef) {
85
+ const trimmed = baseRef.trim();
86
+ if (!trimmed || trimmed.startsWith("-") || /[\s\0]/u.test(trimmed)) {
87
+ throw new Error("doctor --since requires a non-option Git ref without whitespace.");
88
+ }
89
+ return trimmed;
90
+ }
91
+ function runGit(projectRoot, args) {
92
+ const result = spawnSync("git", args, { cwd: projectRoot, encoding: "utf8", windowsHide: true });
93
+ if (result.status !== 0) {
94
+ throw new Error([
95
+ `Git command failed: git ${args.join(" ")}`,
96
+ result.stderr.trim() || result.stdout.trim() || "No Git error output."
97
+ ].join("\n"));
98
+ }
99
+ return result.stdout;
100
+ }
101
+ function uniqueSorted(values) {
102
+ return [...new Set(values.map(normalizePath))].sort();
103
+ }
104
+ function uniqueRenames(values) {
105
+ return [...new Map(values.map((value) => [`${normalizePath(value.from)}\0${normalizePath(value.to)}`, {
106
+ from: normalizePath(value.from),
107
+ to: normalizePath(value.to)
108
+ }])).values()].sort((left, right) => left.from.localeCompare(right.from) || left.to.localeCompare(right.to));
109
+ }
@@ -0,0 +1,148 @@
1
+ import { type DefinitionCollision, type StorageDiagnostics } from "../db/repositories.js";
2
+ import type { FrontmatterDiagnostic, GraphDocument, SourceRef } from "../types.js";
3
+ export interface DeadLinkIssue {
4
+ documentPath: string;
5
+ line: number;
6
+ target: string;
7
+ kind: "markdown" | "wikilink";
8
+ }
9
+ export interface StaleSourceRefIssue {
10
+ sourceRef: SourceRef;
11
+ expectedPath: string;
12
+ documentPaths: string[];
13
+ }
14
+ export interface MissingDefinitionIssue {
15
+ document: GraphDocument;
16
+ }
17
+ export interface WeakLinkIssue {
18
+ document: GraphDocument;
19
+ nonContainmentEdges: number;
20
+ }
21
+ export interface ContentRiskIssue {
22
+ documentPath: string;
23
+ line: number;
24
+ reason: string;
25
+ }
26
+ export interface FrontmatterDiagnosticIssue {
27
+ documentPath: string;
28
+ diagnostic: FrontmatterDiagnostic;
29
+ }
30
+ interface StorageWarningIssue {
31
+ code: "storage.generated_path_indexed" | "storage.database_oversized" | "storage.fts_shadow_large" | "storage.high_degree_node" | "storage.vector_anomaly";
32
+ severity: DoctorWarningSeverity;
33
+ message: string;
34
+ evidence: Record<string, unknown>;
35
+ affectedNodes: DoctorWarningAffectedNode[];
36
+ remediation: string;
37
+ }
38
+ export type DoctorWarningSeverity = "error" | "warn" | "info";
39
+ export interface DoctorWarningAffectedNode {
40
+ kind: string;
41
+ id?: string;
42
+ path?: string;
43
+ line?: number;
44
+ label?: string;
45
+ }
46
+ export interface DoctorWarning {
47
+ code: string;
48
+ severity: DoctorWarningSeverity;
49
+ message: string;
50
+ evidence: Record<string, unknown>;
51
+ affectedNodes: DoctorWarningAffectedNode[];
52
+ remediation: string;
53
+ }
54
+ export declare const DOCTOR_WARNING_CODES: readonly ["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", "link.non_posix_path"];
55
+ export interface StaleIndexIssue {
56
+ path: string;
57
+ reason: "added" | "deleted" | "modified" | "id_changed";
58
+ indexedId?: string;
59
+ currentId?: string;
60
+ indexedHash?: string;
61
+ currentHash?: string;
62
+ }
63
+ export interface StaleIndexReport {
64
+ stale: boolean;
65
+ recommendation: string;
66
+ issues: StaleIndexIssue[];
67
+ }
68
+ export interface DoctorScopeRename {
69
+ from: string;
70
+ to: string;
71
+ }
72
+ export interface DoctorScope {
73
+ mode: "all" | "changed" | "since";
74
+ baseRef?: string;
75
+ changedPaths: string[];
76
+ deletedPaths: string[];
77
+ renamedPaths: DoctorScopeRename[];
78
+ untrackedPaths: string[];
79
+ globalHealthIncluded: boolean;
80
+ }
81
+ export interface DoctorHealthDocument {
82
+ path: string;
83
+ title: string;
84
+ type: string;
85
+ status: string;
86
+ nonContainmentEdges: number;
87
+ }
88
+ export interface DoctorHealthDefinition {
89
+ entityName: string;
90
+ documentPaths: string[];
91
+ }
92
+ export interface DoctorStorageHealth {
93
+ estimatedBytes: number;
94
+ pageCount: number;
95
+ freelistCount: number;
96
+ journalMode: string;
97
+ ftsShadowBytes?: number;
98
+ pathGroups: StorageDiagnostics["pathGroups"];
99
+ highDegreeNodes: StorageDiagnostics["highDegreeNodes"];
100
+ vectorSummary: StorageDiagnostics["vectors"] & {
101
+ expectedChunks: number;
102
+ };
103
+ warnings: StorageWarningIssue[];
104
+ }
105
+ export interface DoctorHealth {
106
+ graph: {
107
+ mostConnectedDocs: DoctorHealthDocument[];
108
+ weaklyLinkedDocs: DoctorHealthDocument[];
109
+ duplicateDefinitions: DoctorHealthDefinition[];
110
+ missingDefinitions: DoctorHealthDocument[];
111
+ missingDecisionLinks: DoctorHealthDocument[];
112
+ };
113
+ storage: DoctorStorageHealth;
114
+ }
115
+ export interface DoctorOptions {
116
+ scope?: DoctorScope;
117
+ applySchema?: boolean;
118
+ }
119
+ export interface DoctorReport {
120
+ projectRoot: string;
121
+ scope: DoctorScope;
122
+ summary: {
123
+ documents: number;
124
+ orphanDocs: number;
125
+ deadLinks: number;
126
+ staleSourceRefs: number;
127
+ missingDefinitions: number;
128
+ weaklyLinkedDocs: number;
129
+ possibleContradictions: number;
130
+ contentRisks: number;
131
+ staleIndex: number;
132
+ };
133
+ staleIndex: StaleIndexReport;
134
+ orphanDocs: GraphDocument[];
135
+ deadLinks: DeadLinkIssue[];
136
+ staleSourceRefs: StaleSourceRefIssue[];
137
+ missingDefinitions: MissingDefinitionIssue[];
138
+ weaklyLinkedDocs: WeakLinkIssue[];
139
+ possibleContradictions: DefinitionCollision[];
140
+ contentRisks: ContentRiskIssue[];
141
+ frontmatterDiagnostics: FrontmatterDiagnosticIssue[];
142
+ warnings: DoctorWarning[];
143
+ health: DoctorHealth;
144
+ }
145
+ export declare function allDoctorScope(): DoctorScope;
146
+ export declare function runDoctor(projectRoot: string, options?: DoctorOptions): Promise<DoctorReport>;
147
+ export declare function formatDoctorReport(report: DoctorReport): string;
148
+ export {};