@daogee/mdgraph 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README-ZH.md +13 -3
  3. package/README.md +13 -3
  4. package/agent-pack/README.md +2 -0
  5. package/agent-pack/mdgraph-agent-instructions.md +5 -1
  6. package/agent-pack/prompts/wiki-authoring.md +12 -0
  7. package/agent-pack/skills/wiki-authoring/SKILL.md +38 -0
  8. package/agent-pack/skills/wiki-authoring/agents/openai.yaml +4 -0
  9. package/dist/analysis/status-freshness.d.ts +8 -1
  10. package/dist/analysis/status-freshness.js +19 -6
  11. package/dist/bin/mdgraph.js +125 -6
  12. package/dist/db/connection.js +17 -1
  13. package/dist/db/repositories.d.ts +30 -5
  14. package/dist/db/repositories.js +171 -8
  15. package/dist/db/sqlite-adapter.js +8 -2
  16. package/dist/evaluation/retrieval-eval.d.ts +11 -0
  17. package/dist/evaluation/retrieval-eval.js +35 -1
  18. package/dist/index.d.ts +7 -0
  19. package/dist/index.js +3 -0
  20. package/dist/indexer.js +64 -6
  21. package/dist/mcp/server.js +5 -4
  22. package/dist/mcp/tools.js +26 -11
  23. package/dist/query/context-builder.d.ts +2 -0
  24. package/dist/query/context-builder.js +154 -24
  25. package/dist/query/knowledge-card.d.ts +90 -0
  26. package/dist/query/knowledge-card.js +676 -0
  27. package/dist/query/search.js +30 -8
  28. package/dist/scanner/file-scanner.js +7 -7
  29. package/dist/semantic/ollama-provider.js +6 -1
  30. package/dist/utils/fts.d.ts +1 -0
  31. package/dist/utils/fts.js +68 -13
  32. package/dist/utils/path-safety.d.ts +3 -0
  33. package/dist/utils/path-safety.js +27 -0
  34. package/dist/watcher/file-watcher.js +121 -17
  35. package/dist/wiki/wiki-dependencies.d.ts +20 -0
  36. package/dist/wiki/wiki-dependencies.js +45 -0
  37. package/dist/wiki/wiki-domains.d.ts +13 -0
  38. package/dist/wiki/wiki-domains.js +55 -0
  39. package/dist/wiki/wiki-evidence.d.ts +27 -0
  40. package/dist/wiki/wiki-evidence.js +112 -0
  41. package/dist/wiki/wiki-plan.d.ts +121 -0
  42. package/dist/wiki/wiki-plan.js +616 -0
  43. package/dist/wiki/wiki-status.d.ts +67 -0
  44. package/dist/wiki/wiki-status.js +451 -0
  45. package/docs/EN/Agent_Integration.md +16 -4
  46. package/docs/EN/Architecture.md +14 -2
  47. package/docs/EN/Evaluation_Questions.md +21 -1
  48. package/docs/EN/Knowledge_Cards_and_Wiki_Workflow.md +97 -0
  49. package/docs/EN/Operations.md +22 -0
  50. package/docs/EN/Output_Contracts.md +44 -3
  51. package/docs/EN/Public_Contracts.md +4 -2
  52. package/docs/EN/Public_Contracts_1.0.md +4 -0
  53. package/docs/EN/README.md +1 -0
  54. package/docs/EN/Release_Checklist.md +3 -2
  55. package/docs/EN/Retrieval_and_Context.md +20 -5
  56. package/docs/ZH/Agent_Integration.md +16 -4
  57. package/docs/ZH/Architecture.md +14 -4
  58. package/docs/ZH/Evaluation_Questions.md +21 -1
  59. package/docs/ZH/Knowledge_Cards_and_Wiki_Workflow.md +99 -0
  60. package/docs/ZH/Operations.md +22 -0
  61. package/docs/ZH/Output_Contracts.md +44 -3
  62. package/docs/ZH/Public_Contracts.md +4 -2
  63. package/docs/ZH/Public_Contracts_1.0.md +4 -0
  64. package/docs/ZH/README.md +1 -0
  65. package/docs/ZH/Release_Checklist.md +3 -2
  66. package/docs/ZH/Retrieval_and_Context.md +20 -5
  67. package/package.json +8 -3
@@ -0,0 +1,27 @@
1
+ import { type StatusFreshness } from "../analysis/status-freshness.js";
2
+ import type { GraphRepository } from "../db/repositories.js";
3
+ export interface WikiEvidencePage {
4
+ id: string;
5
+ title: string;
6
+ path: string;
7
+ parentId?: string;
8
+ purpose: string;
9
+ audience: string;
10
+ outline: string[];
11
+ documentIds: string[];
12
+ sourceRefs: string[];
13
+ evidenceQueries: string[];
14
+ }
15
+ export interface WikiContentFreshnessOptions {
16
+ wikiDir?: string;
17
+ }
18
+ export interface WikiPageEvidenceStatus {
19
+ currentEvidenceHash: string;
20
+ staleDocumentPaths: string[];
21
+ }
22
+ /** Returns the strict on-disk Markdown evidence used by Wiki plan, brief, and status. */
23
+ export declare function wikiContentFreshness(projectRoot: string, repository: GraphRepository, options?: WikiContentFreshnessOptions): StatusFreshness;
24
+ export declare function calculateWikiPageEvidenceHash(projectRoot: string, repository: GraphRepository, page: WikiEvidencePage): string;
25
+ export declare function wikiPageEvidenceStatus(projectRoot: string, repository: GraphRepository, page: WikiEvidencePage, freshness: StatusFreshness): WikiPageEvidenceStatus;
26
+ export declare function sourceRefFingerprint(projectRoot: string, sourceRef: string): string;
27
+ export declare function safeProjectRelativePath(value: string): string | undefined;
@@ -0,0 +1,112 @@
1
+ import { createHash } from "node:crypto";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { computeStatusFreshness } from "../analysis/status-freshness.js";
5
+ import { hashCanonical } from "../bundle/bundle.js";
6
+ import { loadConfig } from "../config/load-config.js";
7
+ import { isPathInsideOrEqual, resolveInsideRoot } from "../utils/path-safety.js";
8
+ import { normalizePath } from "../utils/text.js";
9
+ /** Returns the strict on-disk Markdown evidence used by Wiki plan, brief, and status. */
10
+ export function wikiContentFreshness(projectRoot, repository, options = {}) {
11
+ const wikiRelativePath = options.wikiDir && isPathInsideOrEqual(projectRoot, options.wikiDir)
12
+ ? normalizePath(path.relative(projectRoot, options.wikiDir))
13
+ : undefined;
14
+ return computeStatusFreshness(projectRoot, loadConfig(projectRoot), repository, {
15
+ strictContentHash: true,
16
+ ignorePaths: wikiRelativePath && wikiRelativePath !== "." ? [wikiRelativePath] : undefined
17
+ });
18
+ }
19
+ export function calculateWikiPageEvidenceHash(projectRoot, repository, page) {
20
+ const documentsById = new Map(repository.allDocuments().map((document) => [document.id, document]));
21
+ const documents = page.documentIds.map((documentId) => {
22
+ const document = documentsById.get(documentId);
23
+ return document
24
+ ? { id: document.id, path: document.path, hash: document.hash }
25
+ : { id: documentId, missing: true };
26
+ });
27
+ const sourceRefs = page.sourceRefs.map((sourceRef) => ({
28
+ path: sourceRef,
29
+ fingerprint: sourceRefFingerprint(projectRoot, sourceRef)
30
+ }));
31
+ return hashCanonical({
32
+ page: {
33
+ id: page.id,
34
+ title: page.title,
35
+ path: page.path,
36
+ parentId: page.parentId,
37
+ purpose: page.purpose,
38
+ audience: page.audience,
39
+ outline: page.outline,
40
+ documentIds: page.documentIds,
41
+ sourceRefs: page.sourceRefs,
42
+ evidenceQueries: page.evidenceQueries
43
+ },
44
+ documents,
45
+ sourceRefs
46
+ });
47
+ }
48
+ export function wikiPageEvidenceStatus(projectRoot, repository, page, freshness) {
49
+ const documentsById = new Map(repository.allDocuments().map((document) => [document.id, document.path]));
50
+ const stalePaths = new Set(freshness.issues
51
+ ?.filter((issue) => issue.reason === "modified" || issue.reason === "deleted")
52
+ .map((issue) => issue.path) ?? []);
53
+ return {
54
+ currentEvidenceHash: calculateWikiPageEvidenceHash(projectRoot, repository, page),
55
+ staleDocumentPaths: page.documentIds.flatMap((documentId) => {
56
+ const documentPath = documentsById.get(documentId);
57
+ return documentPath && stalePaths.has(documentPath) ? [documentPath] : [];
58
+ })
59
+ };
60
+ }
61
+ export function sourceRefFingerprint(projectRoot, sourceRef) {
62
+ const normalized = safeProjectRelativePath(sourceRef);
63
+ if (!normalized)
64
+ return "unsafe";
65
+ try {
66
+ const resolved = resolveInsideRoot(projectRoot, normalized);
67
+ if (!resolved || !fs.existsSync(resolved))
68
+ return "missing";
69
+ const stat = fs.lstatSync(resolved);
70
+ if (stat.isSymbolicLink()) {
71
+ let realPath;
72
+ try {
73
+ realPath = fs.realpathSync(resolved);
74
+ }
75
+ catch {
76
+ return "broken-symlink";
77
+ }
78
+ if (!isPathInsideOrEqual(projectRoot, realPath))
79
+ return "unsafe-symlink";
80
+ }
81
+ if (!stat.isFile() && !stat.isSymbolicLink())
82
+ return "not-file";
83
+ return hashFile(resolved);
84
+ }
85
+ catch {
86
+ return "unreadable";
87
+ }
88
+ }
89
+ export function safeProjectRelativePath(value) {
90
+ const normalized = normalizePath(value.trim()).replace(/^\.\//, "");
91
+ const segments = normalized.split("/");
92
+ return !normalized || normalized.includes("\0") || path.isAbsolute(normalized) || path.posix.isAbsolute(normalized) || /^[a-z]:\//i.test(normalized) || segments.some((segment) => !segment || segment === "." || segment === "..")
93
+ ? undefined
94
+ : normalized;
95
+ }
96
+ function hashFile(filePath) {
97
+ const hash = createHash("sha256");
98
+ const buffer = Buffer.allocUnsafe(64 * 1024);
99
+ const descriptor = fs.openSync(filePath, "r");
100
+ try {
101
+ let bytesRead = 0;
102
+ do {
103
+ bytesRead = fs.readSync(descriptor, buffer, 0, buffer.length, null);
104
+ if (bytesRead > 0)
105
+ hash.update(buffer.subarray(0, bytesRead));
106
+ } while (bytesRead > 0);
107
+ }
108
+ finally {
109
+ fs.closeSync(descriptor);
110
+ }
111
+ return hash.digest("hex");
112
+ }
@@ -0,0 +1,121 @@
1
+ import { GraphRepository } from "../db/repositories.js";
2
+ import { type StatusFreshness } from "../analysis/status-freshness.js";
3
+ import { type ContextItem } from "../query/context-builder.js";
4
+ import { type KnowledgeCard } from "../query/knowledge-card.js";
5
+ import type { GraphDocument, MDGraphConfig } from "../types.js";
6
+ import { type WikiDependencyAssessment } from "./wiki-dependencies.js";
7
+ export { calculateWikiPageEvidenceHash, safeProjectRelativePath, sourceRefFingerprint } from "./wiki-evidence.js";
8
+ export declare const WIKI_PLAN_FORMAT: "mdgraph-wiki-plan";
9
+ export declare const WIKI_PLAN_FORMAT_VERSION: 2;
10
+ export declare const WIKI_PAGE_BRIEF_FORMAT: "mdgraph-wiki-page-brief";
11
+ export declare const WIKI_PAGE_BRIEF_FORMAT_VERSION: 1;
12
+ export interface WikiPlan {
13
+ format: typeof WIKI_PLAN_FORMAT;
14
+ formatVersion: 1 | typeof WIKI_PLAN_FORMAT_VERSION;
15
+ graphHash: string;
16
+ sourceHash: string;
17
+ /** v2 records the project-relative generated Wiki root. */
18
+ wikiDir?: string;
19
+ /** Additive strict Markdown content evidence for deciding whether to use this plan. */
20
+ strictFreshness?: WikiStrictFreshness;
21
+ pages: WikiPlanPage[];
22
+ suggestions?: WikiPlanSuggestions;
23
+ gaps?: WikiPlanGap[];
24
+ }
25
+ export interface WikiPlanSuggestions {
26
+ pages: WikiPlanPage[];
27
+ sources: Array<{
28
+ pageId: string;
29
+ documentIds: string[];
30
+ sourceRefs: string[];
31
+ }>;
32
+ }
33
+ export interface WikiPlanGap {
34
+ kind: "document" | "source_ref" | "domain";
35
+ path?: string;
36
+ reason: string;
37
+ recovery: string;
38
+ }
39
+ export interface WikiPlanOptions {
40
+ from?: WikiPlan;
41
+ wikiDir?: string;
42
+ }
43
+ export interface WikiStrictFreshness {
44
+ state: StatusFreshness["state"];
45
+ recommendation: string;
46
+ issues?: NonNullable<StatusFreshness["issues"]>;
47
+ }
48
+ export interface WikiPlanPage {
49
+ id: string;
50
+ title: string;
51
+ path: string;
52
+ parentId?: string;
53
+ purpose: string;
54
+ audience: string;
55
+ outline: string[];
56
+ documentIds: string[];
57
+ sourceRefs: string[];
58
+ evidenceQueries: string[];
59
+ evidenceHash: string;
60
+ dependencySnapshot?: WikiDependencySnapshot;
61
+ gaps?: WikiPlanGap[];
62
+ }
63
+ export interface WikiDependencySnapshot {
64
+ documents: Array<{
65
+ id: string;
66
+ path?: string;
67
+ hash?: string;
68
+ missing?: true;
69
+ }>;
70
+ sourceRefs: Array<{
71
+ path: string;
72
+ fingerprint: string;
73
+ }>;
74
+ }
75
+ export interface WikiPageBrief {
76
+ format: typeof WIKI_PAGE_BRIEF_FORMAT;
77
+ formatVersion: typeof WIKI_PAGE_BRIEF_FORMAT_VERSION;
78
+ page: WikiPlanPage;
79
+ maxChars: number;
80
+ usedChars: number;
81
+ sourceDocuments: WikiBriefSourceDocument[];
82
+ supplementaryDocuments: WikiBriefSourceDocument[];
83
+ sourceInspections: Array<{
84
+ path: string;
85
+ instruction: string;
86
+ }>;
87
+ evidenceGaps: WikiPlanGap[];
88
+ dependencyEvidence: WikiDependencyAssessment;
89
+ contextItems: ContextItem[];
90
+ knowledgeCards: KnowledgeCard[];
91
+ writingRequirements: string[];
92
+ suggestedNextQueries: string[];
93
+ /** Strict Markdown content evidence available when the brief was prepared. */
94
+ strictFreshness: WikiStrictFreshness;
95
+ }
96
+ export interface WikiBriefSourceDocument {
97
+ id: string;
98
+ path: string;
99
+ title: string;
100
+ type: GraphDocument["type"];
101
+ status: string;
102
+ trustTier: GraphDocument["trustTier"];
103
+ }
104
+ export interface WikiBriefOptions {
105
+ maxChars?: number;
106
+ }
107
+ export declare class WikiPlanError extends Error {
108
+ readonly code: string;
109
+ readonly recovery: string;
110
+ constructor(code: string, message: string, recovery: string);
111
+ }
112
+ export declare function buildWikiPlan(projectRoot: string, repository: GraphRepository, options?: WikiPlanOptions): WikiPlan;
113
+ export declare function buildWikiPageBrief(projectRoot: string, repository: GraphRepository, config: MDGraphConfig, plan: WikiPlan, pageId: string, options?: WikiBriefOptions): WikiPageBrief;
114
+ export declare function stableWikiPlan(plan: WikiPlan): string;
115
+ export declare function formatWikiPlan(plan: WikiPlan): string;
116
+ export declare function formatWikiPageBrief(brief: WikiPageBrief): string;
117
+ export declare function writeWikiPlan(filePath: string, plan: WikiPlan): void;
118
+ export declare function readWikiPlan(filePath: string): WikiPlan;
119
+ export declare function validateWikiPlan(value: unknown): WikiPlan;
120
+ export declare function safeWikiPagePath(value: string): string | undefined;
121
+ export declare function wikiSourceHash(repository: GraphRepository, wikiDir?: string): string;