@daogee/mdgraph 1.1.0 → 1.2.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 +30 -1
- package/README-ZH.md +12 -2
- package/README.md +12 -2
- package/agent-pack/README.md +2 -0
- package/agent-pack/mdgraph-agent-instructions.md +3 -1
- package/agent-pack/prompts/wiki-authoring.md +12 -0
- package/agent-pack/skills/wiki-authoring/SKILL.md +38 -0
- package/agent-pack/skills/wiki-authoring/agents/openai.yaml +4 -0
- package/dist/analysis/status-freshness.d.ts +8 -1
- package/dist/analysis/status-freshness.js +19 -6
- package/dist/bin/mdgraph.js +124 -6
- package/dist/db/connection.js +17 -1
- package/dist/db/repositories.d.ts +28 -4
- package/dist/db/repositories.js +148 -5
- package/dist/db/sqlite-adapter.js +8 -2
- package/dist/evaluation/retrieval-eval.d.ts +11 -0
- package/dist/evaluation/retrieval-eval.js +35 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.js +3 -0
- package/dist/indexer.js +64 -6
- package/dist/mcp/server.js +5 -4
- package/dist/mcp/tools.js +23 -9
- package/dist/query/context-builder.d.ts +1 -0
- package/dist/query/context-builder.js +30 -1
- package/dist/query/knowledge-card.d.ts +90 -0
- package/dist/query/knowledge-card.js +676 -0
- package/dist/query/search.js +8 -3
- package/dist/semantic/ollama-provider.js +6 -1
- package/dist/utils/path-safety.d.ts +3 -0
- package/dist/utils/path-safety.js +27 -0
- package/dist/watcher/file-watcher.js +85 -16
- package/dist/wiki/wiki-dependencies.d.ts +20 -0
- package/dist/wiki/wiki-dependencies.js +45 -0
- package/dist/wiki/wiki-domains.d.ts +13 -0
- package/dist/wiki/wiki-domains.js +55 -0
- package/dist/wiki/wiki-evidence.d.ts +27 -0
- package/dist/wiki/wiki-evidence.js +112 -0
- package/dist/wiki/wiki-plan.d.ts +121 -0
- package/dist/wiki/wiki-plan.js +616 -0
- package/dist/wiki/wiki-status.d.ts +67 -0
- package/dist/wiki/wiki-status.js +451 -0
- package/docs/EN/Agent_Integration.md +14 -4
- package/docs/EN/Architecture.md +13 -0
- package/docs/EN/Evaluation_Questions.md +14 -0
- package/docs/EN/Knowledge_Cards_and_Wiki_Workflow.md +97 -0
- package/docs/EN/Operations.md +20 -0
- package/docs/EN/Output_Contracts.md +42 -3
- package/docs/EN/Public_Contracts.md +3 -1
- package/docs/EN/Public_Contracts_1.0.md +4 -0
- package/docs/EN/README.md +1 -0
- package/docs/EN/Release_Checklist.md +1 -0
- package/docs/EN/Retrieval_and_Context.md +6 -0
- package/docs/ZH/Agent_Integration.md +14 -4
- package/docs/ZH/Architecture.md +13 -2
- package/docs/ZH/Evaluation_Questions.md +14 -0
- package/docs/ZH/Knowledge_Cards_and_Wiki_Workflow.md +99 -0
- package/docs/ZH/Operations.md +20 -0
- package/docs/ZH/Output_Contracts.md +42 -3
- package/docs/ZH/Public_Contracts.md +3 -1
- package/docs/ZH/Public_Contracts_1.0.md +4 -0
- package/docs/ZH/README.md +1 -0
- package/docs/ZH/Release_Checklist.md +1 -0
- package/docs/ZH/Retrieval_and_Context.md +6 -0
- package/package.json +7 -2
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { explainSearchGraphAsync, searchGraph } from "./search.js";
|
|
2
2
|
import { scanContentRiskLines } from "../utils/content-risk.js";
|
|
3
3
|
import { normalizePath, uniqueStrings } from "../utils/text.js";
|
|
4
|
+
import { createKnowledgeCardBuilder } from "./knowledge-card.js";
|
|
4
5
|
const DEFAULT_MAX_CONTEXT_NODES = 16;
|
|
6
|
+
const DEFAULT_MAX_CONTEXT_CARD_SUMMARIES = 4;
|
|
5
7
|
export const CONTEXT_PACKING_STRATEGY = "mmr-style-document-round-robin";
|
|
6
8
|
export const CONTEXT_PACKING_STRATEGIES = [CONTEXT_PACKING_STRATEGY, "mmr"];
|
|
7
9
|
export const DEFAULT_MMR_LAMBDA = 0.65;
|
|
@@ -354,13 +356,15 @@ function packContext(repository, config, query, candidates, maxChars, mode, pack
|
|
|
354
356
|
content
|
|
355
357
|
});
|
|
356
358
|
}
|
|
359
|
+
const withCardSummaries = addContextCardSummaries(repository, items, maxChars - usedChars);
|
|
360
|
+
usedChars += withCardSummaries.usedChars;
|
|
357
361
|
return {
|
|
358
362
|
result: {
|
|
359
363
|
query,
|
|
360
364
|
maxChars,
|
|
361
365
|
usedChars,
|
|
362
366
|
mode,
|
|
363
|
-
items,
|
|
367
|
+
items: withCardSummaries.items,
|
|
364
368
|
packing: {
|
|
365
369
|
strategy: packingStrategy,
|
|
366
370
|
similarity: ranking.packingSimilarity,
|
|
@@ -377,6 +381,31 @@ function packContext(repository, config, query, candidates, maxChars, mode, pack
|
|
|
377
381
|
redundancySkippedItems: ranking.redundancySkippedItems
|
|
378
382
|
};
|
|
379
383
|
}
|
|
384
|
+
function addContextCardSummaries(repository, items, availableChars) {
|
|
385
|
+
if (availableChars < 32 || !items.length) {
|
|
386
|
+
return { items, usedChars: 0 };
|
|
387
|
+
}
|
|
388
|
+
const builder = createKnowledgeCardBuilder(repository);
|
|
389
|
+
let remaining = availableChars;
|
|
390
|
+
let added = 0;
|
|
391
|
+
const enriched = items.map((item) => {
|
|
392
|
+
if (added >= DEFAULT_MAX_CONTEXT_CARD_SUMMARIES || remaining < 32) {
|
|
393
|
+
return item;
|
|
394
|
+
}
|
|
395
|
+
const card = builder.build(item.nodeId);
|
|
396
|
+
if (!card) {
|
|
397
|
+
return item;
|
|
398
|
+
}
|
|
399
|
+
const cardSummary = card.summary;
|
|
400
|
+
if (cardSummary.length < 32 || cardSummary.length > remaining || cardSummary.endsWith("…")) {
|
|
401
|
+
return item;
|
|
402
|
+
}
|
|
403
|
+
remaining -= cardSummary.length;
|
|
404
|
+
added += 1;
|
|
405
|
+
return { ...item, cardSummary };
|
|
406
|
+
});
|
|
407
|
+
return { items: enriched, usedChars: availableChars - remaining };
|
|
408
|
+
}
|
|
380
409
|
function rankCandidatesWithMmr(repository, config, candidates, lambda) {
|
|
381
410
|
if (!candidates.length) {
|
|
382
411
|
return {
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { GraphRepository, type NodeRecord } from "../db/repositories.js";
|
|
2
|
+
import type { EdgeKind, Provenance } from "../types.js";
|
|
3
|
+
export declare const DEFAULT_KNOWLEDGE_CARD_LIMITS: {
|
|
4
|
+
readonly definitions: 8;
|
|
5
|
+
readonly sourceRefs: 8;
|
|
6
|
+
readonly relatedDocuments: 8;
|
|
7
|
+
readonly evidence: 12;
|
|
8
|
+
readonly nextReads: 6;
|
|
9
|
+
readonly maxChars: 4000;
|
|
10
|
+
};
|
|
11
|
+
export type KnowledgeCardNodeKind = Exclude<NodeRecord["kind"], "chunk">;
|
|
12
|
+
export type CardAssociation = "direct" | "inherited" | "related";
|
|
13
|
+
export interface CardReference {
|
|
14
|
+
nodeId: string;
|
|
15
|
+
kind: KnowledgeCardNodeKind;
|
|
16
|
+
label: string;
|
|
17
|
+
path?: string;
|
|
18
|
+
anchor?: string;
|
|
19
|
+
lines?: {
|
|
20
|
+
start: number;
|
|
21
|
+
end: number;
|
|
22
|
+
};
|
|
23
|
+
edgeKind?: EdgeKind;
|
|
24
|
+
provenance?: Provenance;
|
|
25
|
+
confidence?: number;
|
|
26
|
+
/** Whether this card owns the edge, inherited it from containment, or reaches it through another graph node. */
|
|
27
|
+
association?: CardAssociation;
|
|
28
|
+
/** The graph node that owns the displayed fact when it is not this card's node. */
|
|
29
|
+
originNodeId?: string;
|
|
30
|
+
/** The graph node used to reach a related fact. */
|
|
31
|
+
viaNodeId?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface CardSourceReference {
|
|
34
|
+
nodeId: string;
|
|
35
|
+
path: string;
|
|
36
|
+
edgeKind: Extract<EdgeKind, "IMPLEMENTS" | "REFERENCES_SOURCE">;
|
|
37
|
+
provenance: Provenance;
|
|
38
|
+
confidence: number;
|
|
39
|
+
association?: CardAssociation;
|
|
40
|
+
originNodeId?: string;
|
|
41
|
+
viaNodeId?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface CardEvidence {
|
|
44
|
+
edgeId: string;
|
|
45
|
+
fromId: string;
|
|
46
|
+
fromLabel: string;
|
|
47
|
+
toId: string;
|
|
48
|
+
toLabel: string;
|
|
49
|
+
edgeKind: EdgeKind;
|
|
50
|
+
provenance: Provenance;
|
|
51
|
+
confidence: number;
|
|
52
|
+
association?: CardAssociation;
|
|
53
|
+
originNodeId?: string;
|
|
54
|
+
viaNodeId?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface CardNextRead extends CardReference {
|
|
57
|
+
reason: string;
|
|
58
|
+
}
|
|
59
|
+
export interface KnowledgeCard {
|
|
60
|
+
nodeId: string;
|
|
61
|
+
kind: KnowledgeCardNodeKind;
|
|
62
|
+
label: string;
|
|
63
|
+
summary: string;
|
|
64
|
+
definitions: CardReference[];
|
|
65
|
+
sourceRefs: CardSourceReference[];
|
|
66
|
+
relatedDocuments: CardReference[];
|
|
67
|
+
evidence: CardEvidence[];
|
|
68
|
+
nextReads?: CardNextRead[];
|
|
69
|
+
truncated?: {
|
|
70
|
+
definitions?: number;
|
|
71
|
+
sourceRefs?: number;
|
|
72
|
+
relatedDocuments?: number;
|
|
73
|
+
evidence?: number;
|
|
74
|
+
nextReads?: number;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export interface KnowledgeCardOptions {
|
|
78
|
+
maxDefinitions?: number;
|
|
79
|
+
maxSourceRefs?: number;
|
|
80
|
+
maxRelatedDocuments?: number;
|
|
81
|
+
maxEvidence?: number;
|
|
82
|
+
maxNextReads?: number;
|
|
83
|
+
maxChars?: number;
|
|
84
|
+
}
|
|
85
|
+
export interface KnowledgeCardBuilder {
|
|
86
|
+
build(nodeOrId: NodeRecord | string): KnowledgeCard | undefined;
|
|
87
|
+
}
|
|
88
|
+
export declare function createKnowledgeCardBuilder(repository: GraphRepository, options?: KnowledgeCardOptions): KnowledgeCardBuilder;
|
|
89
|
+
export declare function buildKnowledgeCard(repository: GraphRepository, nodeOrId: NodeRecord | string, options?: KnowledgeCardOptions): KnowledgeCard | undefined;
|
|
90
|
+
export declare function formatKnowledgeCard(card: KnowledgeCard): string;
|