@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.
- package/CHANGELOG.md +42 -0
- package/README-ZH.md +13 -3
- package/README.md +13 -3
- package/agent-pack/README.md +2 -0
- package/agent-pack/mdgraph-agent-instructions.md +5 -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 +125 -6
- package/dist/db/connection.js +17 -1
- package/dist/db/repositories.d.ts +30 -5
- package/dist/db/repositories.js +171 -8
- 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 +26 -11
- package/dist/query/context-builder.d.ts +2 -0
- package/dist/query/context-builder.js +154 -24
- package/dist/query/knowledge-card.d.ts +90 -0
- package/dist/query/knowledge-card.js +676 -0
- package/dist/query/search.js +30 -8
- package/dist/scanner/file-scanner.js +7 -7
- package/dist/semantic/ollama-provider.js +6 -1
- package/dist/utils/fts.d.ts +1 -0
- package/dist/utils/fts.js +68 -13
- package/dist/utils/path-safety.d.ts +3 -0
- package/dist/utils/path-safety.js +27 -0
- package/dist/watcher/file-watcher.js +121 -17
- 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 +16 -4
- package/docs/EN/Architecture.md +14 -2
- package/docs/EN/Evaluation_Questions.md +21 -1
- package/docs/EN/Knowledge_Cards_and_Wiki_Workflow.md +97 -0
- package/docs/EN/Operations.md +22 -0
- package/docs/EN/Output_Contracts.md +44 -3
- package/docs/EN/Public_Contracts.md +4 -2
- package/docs/EN/Public_Contracts_1.0.md +4 -0
- package/docs/EN/README.md +1 -0
- package/docs/EN/Release_Checklist.md +3 -2
- package/docs/EN/Retrieval_and_Context.md +20 -5
- package/docs/ZH/Agent_Integration.md +16 -4
- package/docs/ZH/Architecture.md +14 -4
- package/docs/ZH/Evaluation_Questions.md +21 -1
- package/docs/ZH/Knowledge_Cards_and_Wiki_Workflow.md +99 -0
- package/docs/ZH/Operations.md +22 -0
- package/docs/ZH/Output_Contracts.md +44 -3
- package/docs/ZH/Public_Contracts.md +4 -2
- package/docs/ZH/Public_Contracts_1.0.md +4 -0
- package/docs/ZH/README.md +1 -0
- package/docs/ZH/Release_Checklist.md +3 -2
- package/docs/ZH/Retrieval_and_Context.md +20 -5
- package/package.json +8 -3
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { hashCanonical } from "../bundle/bundle.js";
|
|
4
|
+
import { buildGraphJsonExport } from "../export/graphjson.js";
|
|
5
|
+
import { buildContext } from "../query/context-builder.js";
|
|
6
|
+
import { createKnowledgeCardBuilder } from "../query/knowledge-card.js";
|
|
7
|
+
import { readBoundedJsonFile } from "../utils/bounded-json.js";
|
|
8
|
+
import { uniqueStrings } from "../utils/text.js";
|
|
9
|
+
import { calculateWikiPageEvidenceHash, safeProjectRelativePath, sourceRefFingerprint, wikiContentFreshness } from "./wiki-evidence.js";
|
|
10
|
+
import { WIKI_DOMAINS as DOMAIN_TEMPLATES } from "./wiki-domains.js";
|
|
11
|
+
import { assessWikiDependencies } from "./wiki-dependencies.js";
|
|
12
|
+
export { calculateWikiPageEvidenceHash, safeProjectRelativePath, sourceRefFingerprint } from "./wiki-evidence.js";
|
|
13
|
+
export const WIKI_PLAN_FORMAT = "mdgraph-wiki-plan";
|
|
14
|
+
export const WIKI_PLAN_FORMAT_VERSION = 2;
|
|
15
|
+
export const WIKI_PAGE_BRIEF_FORMAT = "mdgraph-wiki-page-brief";
|
|
16
|
+
export const WIKI_PAGE_BRIEF_FORMAT_VERSION = 1;
|
|
17
|
+
const MAX_DOMAIN_SEEDS = 8;
|
|
18
|
+
const MAX_PAGE_DOCUMENTS = 12;
|
|
19
|
+
const MAX_BRIEF_CARDS = 8;
|
|
20
|
+
export class WikiPlanError extends Error {
|
|
21
|
+
code;
|
|
22
|
+
recovery;
|
|
23
|
+
constructor(code, message, recovery) {
|
|
24
|
+
super(`${message} Recovery: ${recovery}`);
|
|
25
|
+
this.code = code;
|
|
26
|
+
this.recovery = recovery;
|
|
27
|
+
this.name = "WikiPlanError";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function buildWikiPlan(projectRoot, repository, options = {}) {
|
|
31
|
+
const graph = buildGraphJsonExport(projectRoot, repository);
|
|
32
|
+
const wikiDir = resolveWikiDir(projectRoot, options.wikiDir ?? options.from?.wikiDir ?? "wiki");
|
|
33
|
+
if (options.from?.formatVersion === 1 && !options.wikiDir) {
|
|
34
|
+
throw new WikiPlanError("wiki.plan_wiki_dir", "A v1 plan does not record wikiDir.", "Pass --wiki-dir <project-relative-directory> when updating this plan.");
|
|
35
|
+
}
|
|
36
|
+
const strictFreshness = wikiStrictFreshness(projectRoot, repository, wikiDir);
|
|
37
|
+
const documents = repository.allDocuments().filter((document) => !isUnderWikiDir(document.path, wikiDir));
|
|
38
|
+
const documentsById = new Map(documents.map((document) => [document.id, document]));
|
|
39
|
+
const relatedDocuments = relatedDocumentIdsByDocument(repository);
|
|
40
|
+
const sourceRefsByDocument = sourceRefsByDocumentId(repository);
|
|
41
|
+
const selectedByDomain = DOMAIN_TEMPLATES.map((domain) => ({
|
|
42
|
+
domain,
|
|
43
|
+
documents: expandDomainDocuments(rankedDomainDocuments(domain, documents), documentsById, relatedDocuments)
|
|
44
|
+
}));
|
|
45
|
+
if (documents.length && !selectedByDomain[0].documents.length) {
|
|
46
|
+
selectedByDomain[0].documents = [documents.slice().sort(compareDocuments)[0]];
|
|
47
|
+
}
|
|
48
|
+
const hasOverview = selectedByDomain[0].documents.length > 0;
|
|
49
|
+
const suggestedPages = [];
|
|
50
|
+
const suggestedSources = [];
|
|
51
|
+
const generated = selectedByDomain
|
|
52
|
+
.filter((entry) => entry.documents.length > 0)
|
|
53
|
+
.map(({ domain, documents: domainDocuments }) => {
|
|
54
|
+
const documentIds = domainDocuments.map((document) => document.id);
|
|
55
|
+
const sourceRefs = uniqueStrings(domainDocuments.flatMap((document) => sourceRefsByDocument.get(document.id) ?? [])).sort();
|
|
56
|
+
const seed = {
|
|
57
|
+
id: domain.id,
|
|
58
|
+
title: domain.title,
|
|
59
|
+
path: domain.path,
|
|
60
|
+
parentId: domain.id !== "project-overview" && hasOverview ? "project-overview" : undefined,
|
|
61
|
+
purpose: domain.purpose,
|
|
62
|
+
audience: domain.audience,
|
|
63
|
+
outline: uniqueStrings([...domain.outline, ...domainDocuments.slice(0, 2).map((document) => document.title)]),
|
|
64
|
+
documentIds,
|
|
65
|
+
sourceRefs,
|
|
66
|
+
evidenceQueries: uniqueStrings([...domain.evidenceQueries, ...domainDocuments.slice(0, 2).map((document) => document.title)])
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
...seed,
|
|
70
|
+
evidenceHash: calculateWikiPageEvidenceHash(projectRoot, repository, seed),
|
|
71
|
+
dependencySnapshot: dependencySnapshot(projectRoot, repository, seed),
|
|
72
|
+
gaps: pageGaps(projectRoot, repository, seed, wikiDir)
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
const pages = options.from ? mergePlanPages(projectRoot, repository, options.from, generated, suggestedPages, suggestedSources, wikiDir) : generated;
|
|
76
|
+
return {
|
|
77
|
+
format: WIKI_PLAN_FORMAT,
|
|
78
|
+
formatVersion: WIKI_PLAN_FORMAT_VERSION,
|
|
79
|
+
graphHash: graph.graphHash,
|
|
80
|
+
sourceHash: wikiSourceHash(repository, wikiDir),
|
|
81
|
+
wikiDir,
|
|
82
|
+
strictFreshness,
|
|
83
|
+
pages,
|
|
84
|
+
suggestions: { pages: suggestedPages, sources: suggestedSources },
|
|
85
|
+
gaps: [...pages.flatMap((page) => page.gaps ?? []), ...selectedByDomain.filter((entry) => !entry.documents.length).map(({ domain }) => ({ kind: "domain", reason: `No indexed evidence supports the ${domain.title} candidate.`, recovery: "Add relevant project documentation and refresh the plan when this page is needed." }))]
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export function buildWikiPageBrief(projectRoot, repository, config, plan, pageId, options = {}) {
|
|
89
|
+
const page = plan.pages.find((candidate) => candidate.id === pageId);
|
|
90
|
+
if (!page) {
|
|
91
|
+
throw new WikiPlanError("wiki.page_not_found", `Wiki page is not present in the plan: ${pageId}`, "Run `mdgraph wiki plan` again or choose a page ID listed in the current plan.");
|
|
92
|
+
}
|
|
93
|
+
const maxChars = positiveIntegerOr(options.maxChars, config.search.maxContextChars);
|
|
94
|
+
const documentsById = new Map(repository.allDocuments().map((document) => [document.id, document]));
|
|
95
|
+
const wikiDir = plan.wikiDir ?? "wiki";
|
|
96
|
+
const plannedDocuments = page.documentIds.flatMap((documentId) => {
|
|
97
|
+
const document = documentsById.get(documentId);
|
|
98
|
+
return document && !isUnderWikiDir(document.path, wikiDir) ? [document] : [];
|
|
99
|
+
});
|
|
100
|
+
const knownFiles = uniqueStrings([
|
|
101
|
+
...plannedDocuments.map((document) => document.path),
|
|
102
|
+
...page.sourceRefs
|
|
103
|
+
]);
|
|
104
|
+
const contextBudget = Math.max(1, Math.floor(maxChars * 0.65));
|
|
105
|
+
const query = [page.title, page.purpose, ...page.evidenceQueries].join(" ");
|
|
106
|
+
const context = buildContext(repository, config, query, {
|
|
107
|
+
knownFiles,
|
|
108
|
+
maxChars: contextBudget,
|
|
109
|
+
searchLimit: Math.max(config.search.defaultLimit * 2, 16),
|
|
110
|
+
maxDepth: config.search.maxDepth
|
|
111
|
+
});
|
|
112
|
+
const contextItems = context.items.filter((item) => !isUnderWikiDir(item.path, wikiDir));
|
|
113
|
+
const builder = createKnowledgeCardBuilder(repository);
|
|
114
|
+
const wikiDocumentIds = new Set(repository.allDocuments().filter((document) => isUnderWikiDir(document.path, wikiDir)).map((document) => document.id));
|
|
115
|
+
const cardNodeIds = uniqueStrings([
|
|
116
|
+
...page.documentIds,
|
|
117
|
+
...contextItems.map((item) => item.nodeId)
|
|
118
|
+
]).filter((nodeId) => !wikiDocumentIds.has(nodeId));
|
|
119
|
+
const knowledgeCards = [];
|
|
120
|
+
let usedChars = contextItems.reduce((sum, item) => sum + item.content.length + (item.cardSummary?.length ?? 0), 0);
|
|
121
|
+
for (const nodeId of cardNodeIds) {
|
|
122
|
+
if (knowledgeCards.length >= MAX_BRIEF_CARDS) {
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
const card = builder.build(nodeId);
|
|
126
|
+
if (!card) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const cardChars = JSON.stringify(card).length;
|
|
130
|
+
if (usedChars + cardChars > maxChars) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
knowledgeCards.push(card);
|
|
134
|
+
usedChars += cardChars;
|
|
135
|
+
}
|
|
136
|
+
const strictFreshness = wikiStrictFreshness(projectRoot, repository, wikiDir);
|
|
137
|
+
const dependencyEvidence = assessWikiDependencies(projectRoot, repository, page, strictFreshness, wikiDir);
|
|
138
|
+
const evidenceGaps = pageGaps(projectRoot, repository, page, wikiDir);
|
|
139
|
+
const plannedPaths = new Set(plannedDocuments.map((document) => document.path));
|
|
140
|
+
const supplementaryPaths = new Set(contextItems.filter((item) => !plannedPaths.has(item.path)).map((item) => item.path));
|
|
141
|
+
const supplementaryDocuments = [...documentsById.values()].filter((document) => supplementaryPaths.has(document.path));
|
|
142
|
+
const writingRequirements = [
|
|
143
|
+
`Write for this audience: ${page.audience}`,
|
|
144
|
+
`Make the page achieve this purpose: ${page.purpose}`,
|
|
145
|
+
"Use the outline as guidance, not as text to copy mechanically.",
|
|
146
|
+
"Read the listed source documents and inspect listed source refs before making behavioral claims.",
|
|
147
|
+
"Distinguish directly evidenced behavior from conclusions that still require source verification.",
|
|
148
|
+
"Keep project-relative source_docs and source_refs in front matter, and preserve wiki_id and evidence_hash.",
|
|
149
|
+
"Do not overwrite or rewrite unrelated Wiki pages.",
|
|
150
|
+
strictFreshness.state === "fresh" && dependencyEvidence.state === "fresh" && !evidenceGaps.length
|
|
151
|
+
? `Set evidence_hash to ${page.evidenceHash}.`
|
|
152
|
+
: `Index evidence: ${strictFreshness.state}; page dependencies: ${dependencyEvidence.state}. ${dependencyEvidence.recovery ?? "Run mdgraph index, review missing sources, and refresh the plan before finalizing this page."} Do not set evidence_hash from this unresolved evidence.`
|
|
153
|
+
];
|
|
154
|
+
const suggestedNextQueries = uniqueStrings([
|
|
155
|
+
...page.evidenceQueries.map((evidenceQuery) => `mdgraph context ${JSON.stringify(evidenceQuery)}`),
|
|
156
|
+
...plannedDocuments.slice(0, 4).map((document) => `mdgraph node ${JSON.stringify(document.path)}`),
|
|
157
|
+
...(context.suggestedNextQueries ?? [])
|
|
158
|
+
]);
|
|
159
|
+
return {
|
|
160
|
+
format: WIKI_PAGE_BRIEF_FORMAT,
|
|
161
|
+
formatVersion: WIKI_PAGE_BRIEF_FORMAT_VERSION,
|
|
162
|
+
page,
|
|
163
|
+
maxChars,
|
|
164
|
+
usedChars,
|
|
165
|
+
sourceDocuments: plannedDocuments.map((document) => ({
|
|
166
|
+
id: document.id,
|
|
167
|
+
path: document.path,
|
|
168
|
+
title: document.title,
|
|
169
|
+
type: document.type,
|
|
170
|
+
status: document.status,
|
|
171
|
+
trustTier: document.trustTier
|
|
172
|
+
})),
|
|
173
|
+
supplementaryDocuments: supplementaryDocuments.map((document) => ({ id: document.id, path: document.path, title: document.title, type: document.type, status: document.status, trustTier: document.trustTier })),
|
|
174
|
+
sourceInspections: page.sourceRefs.map((source) => ({ path: source, instruction: "Inspect this selected project file before making implementation claims; a reference alone does not prove behavior." })),
|
|
175
|
+
evidenceGaps,
|
|
176
|
+
dependencyEvidence,
|
|
177
|
+
contextItems,
|
|
178
|
+
knowledgeCards,
|
|
179
|
+
writingRequirements,
|
|
180
|
+
suggestedNextQueries,
|
|
181
|
+
strictFreshness
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
export function stableWikiPlan(plan) {
|
|
185
|
+
return `${JSON.stringify(plan, null, 2)}\n`;
|
|
186
|
+
}
|
|
187
|
+
function wikiStrictFreshness(projectRoot, repository, wikiDir) {
|
|
188
|
+
const freshness = wikiContentFreshness(projectRoot, repository, { wikiDir: path.resolve(projectRoot, wikiDir) });
|
|
189
|
+
return {
|
|
190
|
+
state: freshness.state,
|
|
191
|
+
recommendation: freshness.recommendation,
|
|
192
|
+
issues: freshness.issues
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
export function formatWikiPlan(plan) {
|
|
196
|
+
const lines = [
|
|
197
|
+
`Wiki plan: ${plan.pages.length} page(s)`,
|
|
198
|
+
`Format: v${plan.formatVersion}; Wiki directory: ${plan.wikiDir ?? "not recorded (v1)"}`,
|
|
199
|
+
`Evidence freshness: ${plan.strictFreshness?.state ?? "unknown"}`,
|
|
200
|
+
`Evidence guidance: ${plan.strictFreshness?.recommendation ?? "Refresh the index and plan before accepting its evidence."}`,
|
|
201
|
+
`Graph hash: ${plan.graphHash}`,
|
|
202
|
+
`Source hash: ${plan.sourceHash}`
|
|
203
|
+
];
|
|
204
|
+
for (const page of plan.pages) {
|
|
205
|
+
lines.push(`- ${page.id}: ${page.path} (${page.documentIds.length} document(s), ${page.sourceRefs.length} source ref(s))`);
|
|
206
|
+
}
|
|
207
|
+
for (const page of plan.suggestions?.pages ?? [])
|
|
208
|
+
lines.push(`Suggested page: ${page.id} (${page.title}) -> ${page.path}`);
|
|
209
|
+
for (const source of plan.suggestions?.sources ?? [])
|
|
210
|
+
lines.push(`Suggested evidence for ${source.pageId}: documents ${source.documentIds.join(", ") || "none"}; sources ${source.sourceRefs.join(", ") || "none"}`);
|
|
211
|
+
for (const gap of plan.gaps ?? [])
|
|
212
|
+
lines.push(`Gap: ${gap.path ?? gap.kind}: ${gap.reason} Recovery: ${gap.recovery}`);
|
|
213
|
+
return lines.join("\n");
|
|
214
|
+
}
|
|
215
|
+
export function formatWikiPageBrief(brief) {
|
|
216
|
+
const lines = [
|
|
217
|
+
`Wiki page brief: ${brief.page.id} (${brief.page.path})`,
|
|
218
|
+
`Purpose: ${brief.page.purpose}`,
|
|
219
|
+
`Audience: ${brief.page.audience}`,
|
|
220
|
+
`Budget: ${brief.usedChars}/${brief.maxChars} chars`,
|
|
221
|
+
`Source documents: ${brief.sourceDocuments.map((document) => document.path).join(", ") || "none"}`,
|
|
222
|
+
`Context items: ${brief.contextItems.length}; Knowledge Cards: ${brief.knowledgeCards.length}`,
|
|
223
|
+
`Evidence freshness: ${brief.strictFreshness.state}; page dependencies: ${brief.dependencyEvidence.state}`,
|
|
224
|
+
`Supplementary documents: ${brief.supplementaryDocuments.map((document) => document.path).join(", ") || "none"}`,
|
|
225
|
+
...brief.sourceInspections.map((source) => `Inspect source: ${source.path}. ${source.instruction}`),
|
|
226
|
+
...brief.evidenceGaps.map((gap) => `Evidence gap: ${gap.path ?? gap.kind}: ${gap.reason} Recovery: ${gap.recovery}`),
|
|
227
|
+
...brief.dependencyEvidence.changes.map((change) => `Dependency change: ${change.path}: ${change.reason}`),
|
|
228
|
+
"Writing requirements:",
|
|
229
|
+
...brief.writingRequirements.map((requirement) => `- ${requirement}`),
|
|
230
|
+
"Suggested next queries:",
|
|
231
|
+
...brief.suggestedNextQueries.map((query) => `- ${query}`)
|
|
232
|
+
];
|
|
233
|
+
return lines.join("\n");
|
|
234
|
+
}
|
|
235
|
+
export function writeWikiPlan(filePath, plan) {
|
|
236
|
+
const resolved = path.resolve(filePath);
|
|
237
|
+
fs.mkdirSync(path.dirname(resolved), { recursive: true });
|
|
238
|
+
const temporary = path.join(path.dirname(resolved), `.${path.basename(resolved)}.${process.pid}.tmp`);
|
|
239
|
+
try {
|
|
240
|
+
fs.writeFileSync(temporary, stableWikiPlan(plan), "utf8");
|
|
241
|
+
fs.renameSync(temporary, resolved);
|
|
242
|
+
}
|
|
243
|
+
finally {
|
|
244
|
+
if (fs.existsSync(temporary)) {
|
|
245
|
+
fs.rmSync(temporary);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
export function readWikiPlan(filePath) {
|
|
250
|
+
let value;
|
|
251
|
+
try {
|
|
252
|
+
value = readBoundedJsonFile(path.resolve(filePath), "Wiki plan");
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
throw new WikiPlanError("wiki.plan_unreadable", `Cannot read Wiki plan: ${error instanceof Error ? error.message : String(error)}`, "Run `mdgraph wiki plan --out <plan-file>` to create a readable plan.");
|
|
256
|
+
}
|
|
257
|
+
return validateWikiPlan(value);
|
|
258
|
+
}
|
|
259
|
+
export function validateWikiPlan(value) {
|
|
260
|
+
if (!isRecord(value)) {
|
|
261
|
+
throw invalidPlan("wiki.plan_shape", "Wiki plan must be a JSON object.");
|
|
262
|
+
}
|
|
263
|
+
if (value.format !== WIKI_PLAN_FORMAT) {
|
|
264
|
+
throw invalidPlan("wiki.plan_format", `Unsupported Wiki plan format: ${String(value.format)}.`);
|
|
265
|
+
}
|
|
266
|
+
if (value.formatVersion !== 1 && value.formatVersion !== WIKI_PLAN_FORMAT_VERSION) {
|
|
267
|
+
throw invalidPlan("wiki.plan_version", `Unsupported Wiki plan formatVersion: ${String(value.formatVersion)}.`);
|
|
268
|
+
}
|
|
269
|
+
if (!isSha256(value.graphHash) || !isSha256(value.sourceHash)) {
|
|
270
|
+
throw invalidPlan("wiki.plan_hash", "Wiki plan graphHash and sourceHash must be SHA-256 strings.");
|
|
271
|
+
}
|
|
272
|
+
if (!Array.isArray(value.pages)) {
|
|
273
|
+
throw invalidPlan("wiki.plan_pages", "Wiki plan pages must be an array.");
|
|
274
|
+
}
|
|
275
|
+
const pages = value.pages.map((page, index) => validateWikiPlanPage(page, index));
|
|
276
|
+
const ids = new Set();
|
|
277
|
+
const paths = new Set();
|
|
278
|
+
for (const page of pages) {
|
|
279
|
+
if (ids.has(page.id)) {
|
|
280
|
+
throw invalidPlan("wiki.plan_duplicate_id", `Duplicate Wiki page ID: ${page.id}.`);
|
|
281
|
+
}
|
|
282
|
+
if (paths.has(page.path.toLowerCase())) {
|
|
283
|
+
throw invalidPlan("wiki.plan_duplicate_path", `Duplicate Wiki page path: ${page.path}.`);
|
|
284
|
+
}
|
|
285
|
+
ids.add(page.id);
|
|
286
|
+
paths.add(page.path.toLowerCase());
|
|
287
|
+
}
|
|
288
|
+
assertNoParentCycles(pages);
|
|
289
|
+
for (const page of pages) {
|
|
290
|
+
if (page.parentId && (!ids.has(page.parentId) || page.parentId === page.id)) {
|
|
291
|
+
throw invalidPlan("wiki.plan_parent", `Invalid parentId for Wiki page ${page.id}: ${page.parentId}.`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const formatVersion = value.formatVersion;
|
|
295
|
+
if (formatVersion === 2 && pages.some((page) => !page.dependencySnapshot)) {
|
|
296
|
+
throw invalidPlan("wiki.plan_snapshot", "Every v2 page must contain its dependencySnapshot; refresh this plan from its previous version.");
|
|
297
|
+
}
|
|
298
|
+
const wikiDir = formatVersion === 2 ? safeProjectRelativePath(requiredString(value.wikiDir, "wikiDir")) : undefined;
|
|
299
|
+
if (formatVersion === 2 && !wikiDir) {
|
|
300
|
+
throw invalidPlan("wiki.plan_wiki_dir", "wikiDir must be a safe project-relative directory.");
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
format: WIKI_PLAN_FORMAT,
|
|
304
|
+
formatVersion,
|
|
305
|
+
graphHash: value.graphHash,
|
|
306
|
+
sourceHash: value.sourceHash,
|
|
307
|
+
strictFreshness: optionalWikiStrictFreshness(value.strictFreshness),
|
|
308
|
+
wikiDir,
|
|
309
|
+
pages,
|
|
310
|
+
suggestions: formatVersion === 2 ? validateSuggestions(value.suggestions) : undefined,
|
|
311
|
+
gaps: validateGaps(value.gaps)
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
function assertNoParentCycles(pages) {
|
|
315
|
+
const parentById = new Map(pages.map((page) => [page.id, page.parentId]));
|
|
316
|
+
for (const page of pages) {
|
|
317
|
+
const seen = new Set();
|
|
318
|
+
let current = page.id;
|
|
319
|
+
while (current) {
|
|
320
|
+
if (seen.has(current))
|
|
321
|
+
throw invalidPlan("wiki.plan_parent_cycle", `Wiki page parent cycle includes ${current}.`);
|
|
322
|
+
seen.add(current);
|
|
323
|
+
current = parentById.get(current);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function optionalWikiStrictFreshness(value) {
|
|
328
|
+
if (value === undefined) {
|
|
329
|
+
return undefined;
|
|
330
|
+
}
|
|
331
|
+
if (!isRecord(value) || (value.state !== "fresh" && value.state !== "stale" && value.state !== "unknown") || typeof value.recommendation !== "string") {
|
|
332
|
+
throw invalidPlan("wiki.plan_strict_freshness", "Wiki plan strictFreshness must contain a freshness state and recommendation.");
|
|
333
|
+
}
|
|
334
|
+
if (value.issues !== undefined && (!Array.isArray(value.issues) || value.issues.some((issue) => !isRecord(issue) || typeof issue.path !== "string" || (issue.reason !== "added" && issue.reason !== "deleted" && issue.reason !== "modified")))) {
|
|
335
|
+
throw invalidPlan("wiki.plan_strict_freshness", "Wiki plan strictFreshness issues must contain path and reason values.");
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
state: value.state,
|
|
339
|
+
recommendation: value.recommendation,
|
|
340
|
+
issues: value.issues
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
export function safeWikiPagePath(value) {
|
|
344
|
+
const normalized = safeProjectRelativePath(value);
|
|
345
|
+
return normalized && normalized.toLowerCase().endsWith(".md") ? normalized : undefined;
|
|
346
|
+
}
|
|
347
|
+
function rankedDomainDocuments(domain, documents) {
|
|
348
|
+
return documents
|
|
349
|
+
.map((document) => ({ document, score: domain.score(document) }))
|
|
350
|
+
.filter((entry) => entry.score > 0)
|
|
351
|
+
.sort((left, right) => right.score - left.score || compareDocuments(left.document, right.document))
|
|
352
|
+
.slice(0, MAX_DOMAIN_SEEDS)
|
|
353
|
+
.map((entry) => entry.document);
|
|
354
|
+
}
|
|
355
|
+
function expandDomainDocuments(seeds, documentsById, relatedDocuments) {
|
|
356
|
+
const selected = new Map(seeds.map((document) => [document.id, document]));
|
|
357
|
+
const neighbors = uniqueStrings(seeds.flatMap((document) => relatedDocuments.get(document.id) ?? []))
|
|
358
|
+
.flatMap((documentId) => {
|
|
359
|
+
const document = documentsById.get(documentId);
|
|
360
|
+
return document ? [document] : [];
|
|
361
|
+
})
|
|
362
|
+
.sort(compareDocuments);
|
|
363
|
+
for (const document of neighbors) {
|
|
364
|
+
if (selected.size >= MAX_PAGE_DOCUMENTS) {
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
selected.set(document.id, document);
|
|
368
|
+
}
|
|
369
|
+
return [...selected.values()];
|
|
370
|
+
}
|
|
371
|
+
function relatedDocumentIdsByDocument(repository) {
|
|
372
|
+
const documents = repository.allDocuments();
|
|
373
|
+
const documentIds = new Set(documents.map((document) => document.id));
|
|
374
|
+
const documentBySection = new Map(repository.allSections().map((section) => [section.id, section.documentId]));
|
|
375
|
+
const related = new Map(documents.map((document) => [document.id, []]));
|
|
376
|
+
const owningDocumentId = (nodeId) => documentIds.has(nodeId) ? nodeId : documentBySection.get(nodeId);
|
|
377
|
+
for (const edge of repository.allEdges()) {
|
|
378
|
+
if (edge.kind === "CONTAINS") {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const fromDocumentId = owningDocumentId(edge.fromId);
|
|
382
|
+
const toDocumentId = owningDocumentId(edge.toId);
|
|
383
|
+
if (!fromDocumentId || !toDocumentId || fromDocumentId === toDocumentId) {
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
related.set(fromDocumentId, [...(related.get(fromDocumentId) ?? []), toDocumentId]);
|
|
387
|
+
related.set(toDocumentId, [...(related.get(toDocumentId) ?? []), fromDocumentId]);
|
|
388
|
+
}
|
|
389
|
+
for (const [documentId, ids] of related) {
|
|
390
|
+
related.set(documentId, uniqueStrings(ids).sort());
|
|
391
|
+
}
|
|
392
|
+
return related;
|
|
393
|
+
}
|
|
394
|
+
function sourceRefsByDocumentId(repository) {
|
|
395
|
+
const documents = repository.allDocuments();
|
|
396
|
+
const sections = repository.allSections();
|
|
397
|
+
const sourceRefs = new Map(repository.allSourceRefs().map((sourceRef) => [sourceRef.id, sourceRef]));
|
|
398
|
+
const documentBySection = new Map(sections.map((section) => [section.id, section.documentId]));
|
|
399
|
+
const refs = new Map(documents.map((document) => [document.id, []]));
|
|
400
|
+
for (const edge of repository.allEdges()) {
|
|
401
|
+
if (edge.kind !== "IMPLEMENTS" && edge.kind !== "REFERENCES_SOURCE") {
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
const sourceRef = sourceRefs.get(edge.fromId) ?? sourceRefs.get(edge.toId);
|
|
405
|
+
if (!sourceRef) {
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
const ownerId = sourceRefs.has(edge.fromId) ? edge.toId : edge.fromId;
|
|
409
|
+
const documentId = refs.has(ownerId) ? ownerId : documentBySection.get(ownerId);
|
|
410
|
+
if (documentId) {
|
|
411
|
+
refs.set(documentId, [...(refs.get(documentId) ?? []), sourceRef.path]);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
for (const [documentId, paths] of refs) {
|
|
415
|
+
refs.set(documentId, uniqueStrings(paths).sort());
|
|
416
|
+
}
|
|
417
|
+
return refs;
|
|
418
|
+
}
|
|
419
|
+
export function wikiSourceHash(repository, wikiDir = "wiki") {
|
|
420
|
+
const normalizedWikiDir = safeProjectRelativePath(wikiDir) ?? "wiki";
|
|
421
|
+
return hashCanonical(repository.allDocuments()
|
|
422
|
+
.filter((document) => !isUnderWikiDir(document.path, normalizedWikiDir))
|
|
423
|
+
.map((document) => ({ id: document.id, path: document.path, hash: document.hash }))
|
|
424
|
+
.sort((left, right) => left.path.localeCompare(right.path) || left.id.localeCompare(right.id)));
|
|
425
|
+
}
|
|
426
|
+
function resolveWikiDir(projectRoot, wikiDir) {
|
|
427
|
+
const normalized = safeProjectRelativePath(wikiDir);
|
|
428
|
+
if (!normalized) {
|
|
429
|
+
throw new WikiPlanError("wiki.plan_wiki_dir", `Wiki directory must be project-relative: ${wikiDir}`, "Pass a safe project-relative --wiki-dir, for example wiki.");
|
|
430
|
+
}
|
|
431
|
+
return normalized;
|
|
432
|
+
}
|
|
433
|
+
function isUnderWikiDir(documentPath, wikiDir) {
|
|
434
|
+
return documentPath === wikiDir || documentPath.startsWith(`${wikiDir}/`);
|
|
435
|
+
}
|
|
436
|
+
function dependencySnapshot(projectRoot, repository, page) {
|
|
437
|
+
const documents = new Map(repository.allDocuments().map((document) => [document.id, document]));
|
|
438
|
+
const previous = page.dependencySnapshot;
|
|
439
|
+
const previousById = new Map(previous?.documents.map((document) => [document.id, document]) ?? []);
|
|
440
|
+
return {
|
|
441
|
+
documents: page.documentIds.map((id) => {
|
|
442
|
+
const document = documents.get(id);
|
|
443
|
+
return document ? { id: document.id, path: document.path, hash: document.hash } : { id, path: previousById.get(id)?.path, missing: true };
|
|
444
|
+
}),
|
|
445
|
+
sourceRefs: page.sourceRefs.map((sourceRef) => ({ path: sourceRef, fingerprint: sourceRefFingerprint(projectRoot, sourceRef) }))
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
function mergePlanPages(projectRoot, repository, from, generated, pageSuggestions, sourceSuggestions, wikiDir) {
|
|
449
|
+
const generatedById = new Map(generated.map((page) => [page.id, page]));
|
|
450
|
+
const fromIds = new Set(from.pages.map((page) => page.id));
|
|
451
|
+
const pages = from.pages.map((previous) => {
|
|
452
|
+
const candidate = generatedById.get(previous.id);
|
|
453
|
+
if (candidate) {
|
|
454
|
+
const addedDocuments = candidate.documentIds.filter((id) => !previous.documentIds.includes(id));
|
|
455
|
+
const addedSources = candidate.sourceRefs.filter((sourceRef) => !previous.sourceRefs.includes(sourceRef));
|
|
456
|
+
if (addedDocuments.length || addedSources.length)
|
|
457
|
+
sourceSuggestions.push({ pageId: previous.id, documentIds: addedDocuments, sourceRefs: addedSources });
|
|
458
|
+
}
|
|
459
|
+
const gaps = pageGaps(projectRoot, repository, previous, wikiDir);
|
|
460
|
+
return {
|
|
461
|
+
...previous,
|
|
462
|
+
evidenceHash: calculateWikiPageEvidenceHash(projectRoot, repository, previous),
|
|
463
|
+
dependencySnapshot: dependencySnapshot(projectRoot, repository, previous), gaps
|
|
464
|
+
};
|
|
465
|
+
});
|
|
466
|
+
for (const candidate of generated) {
|
|
467
|
+
if (!fromIds.has(candidate.id))
|
|
468
|
+
pageSuggestions.push(candidate);
|
|
469
|
+
}
|
|
470
|
+
return pages;
|
|
471
|
+
}
|
|
472
|
+
function validateSuggestions(value) {
|
|
473
|
+
if (!isRecord(value) || !Array.isArray(value.pages) || !Array.isArray(value.sources)) {
|
|
474
|
+
throw invalidPlan("wiki.plan_suggestions", "v2 suggestions must contain pages and sources arrays.");
|
|
475
|
+
}
|
|
476
|
+
return {
|
|
477
|
+
pages: value.pages.map((item, index) => {
|
|
478
|
+
if (!isRecord(item))
|
|
479
|
+
throw invalidPlan("wiki.plan_suggestions", `suggestions.pages[${index}] must be an object.`);
|
|
480
|
+
return validateWikiPlanPage(item, index);
|
|
481
|
+
}),
|
|
482
|
+
sources: value.sources.map((item, index) => {
|
|
483
|
+
if (!isRecord(item))
|
|
484
|
+
throw invalidPlan("wiki.plan_suggestions", `suggestions.sources[${index}] must be an object.`);
|
|
485
|
+
return { pageId: requiredString(item.pageId, `suggestions.sources[${index}].pageId`), documentIds: stringArray(item.documentIds, `suggestions.sources[${index}].documentIds`), sourceRefs: stringArray(item.sourceRefs, `suggestions.sources[${index}].sourceRefs`).map((source) => { const safe = safeProjectRelativePath(source); if (!safe)
|
|
486
|
+
throw invalidPlan("wiki.plan_suggestions", "Suggested sources must be project-relative."); return safe; }) };
|
|
487
|
+
})
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function optionalDependencySnapshot(value, index) {
|
|
491
|
+
if (value === undefined)
|
|
492
|
+
return undefined;
|
|
493
|
+
if (!isRecord(value) || !Array.isArray(value.documents) || !Array.isArray(value.sourceRefs)) {
|
|
494
|
+
throw invalidPlan("wiki.plan_snapshot", `pages[${index}].dependencySnapshot must contain documents and sourceRefs arrays.`);
|
|
495
|
+
}
|
|
496
|
+
return {
|
|
497
|
+
documents: value.documents.map((item, documentIndex) => {
|
|
498
|
+
if (!isRecord(item) || typeof item.id !== "string" || !item.id)
|
|
499
|
+
throw invalidPlan("wiki.plan_snapshot", `pages[${index}].dependencySnapshot.documents[${documentIndex}] must contain id.`);
|
|
500
|
+
if (item.path !== undefined && (typeof item.path !== "string" || !safeProjectRelativePath(item.path)))
|
|
501
|
+
throw invalidPlan("wiki.plan_snapshot", "Snapshot document paths must be project-relative.");
|
|
502
|
+
if (item.missing === true)
|
|
503
|
+
return { id: item.id, path: item.path, missing: true };
|
|
504
|
+
if (typeof item.path !== "string" || typeof item.hash !== "string" || !isSha256(item.hash))
|
|
505
|
+
throw invalidPlan("wiki.plan_snapshot", `pages[${index}].dependencySnapshot.documents[${documentIndex}] must contain path and hash.`);
|
|
506
|
+
return { id: item.id, path: item.path, hash: item.hash };
|
|
507
|
+
}),
|
|
508
|
+
sourceRefs: value.sourceRefs.map((item, sourceIndex) => {
|
|
509
|
+
if (!isRecord(item) || typeof item.path !== "string" || !safeProjectRelativePath(item.path) || typeof item.fingerprint !== "string")
|
|
510
|
+
throw invalidPlan("wiki.plan_snapshot", `pages[${index}].dependencySnapshot.sourceRefs[${sourceIndex}] must contain path and fingerprint.`);
|
|
511
|
+
return { path: item.path, fingerprint: item.fingerprint };
|
|
512
|
+
})
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
function validateWikiPlanPage(value, index) {
|
|
516
|
+
if (!isRecord(value)) {
|
|
517
|
+
throw invalidPlan("wiki.plan_page_shape", `Wiki plan pages[${index}] must be an object.`);
|
|
518
|
+
}
|
|
519
|
+
const id = requiredString(value.id, `pages[${index}].id`);
|
|
520
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(id)) {
|
|
521
|
+
throw invalidPlan("wiki.plan_page_id", `Wiki page ID must use lowercase letters, digits, and hyphens: ${id}.`);
|
|
522
|
+
}
|
|
523
|
+
const pagePath = safeWikiPagePath(requiredString(value.path, `pages[${index}].path`));
|
|
524
|
+
if (!pagePath) {
|
|
525
|
+
throw invalidPlan("wiki.plan_page_path", `Wiki page path must be a safe relative Markdown path: ${String(value.path)}.`);
|
|
526
|
+
}
|
|
527
|
+
const parentId = optionalString(value.parentId);
|
|
528
|
+
const page = {
|
|
529
|
+
id,
|
|
530
|
+
title: requiredString(value.title, `pages[${index}].title`),
|
|
531
|
+
path: pagePath,
|
|
532
|
+
parentId,
|
|
533
|
+
purpose: requiredString(value.purpose, `pages[${index}].purpose`),
|
|
534
|
+
audience: requiredString(value.audience, `pages[${index}].audience`),
|
|
535
|
+
outline: stringArray(value.outline, `pages[${index}].outline`),
|
|
536
|
+
documentIds: stringArray(value.documentIds, `pages[${index}].documentIds`),
|
|
537
|
+
sourceRefs: stringArray(value.sourceRefs, `pages[${index}].sourceRefs`).map((sourceRef) => {
|
|
538
|
+
const safe = safeProjectRelativePath(sourceRef);
|
|
539
|
+
if (!safe) {
|
|
540
|
+
throw invalidPlan("wiki.plan_source_ref", `Unsafe source ref in Wiki page ${id}: ${sourceRef}.`);
|
|
541
|
+
}
|
|
542
|
+
return safe;
|
|
543
|
+
}),
|
|
544
|
+
evidenceQueries: stringArray(value.evidenceQueries, `pages[${index}].evidenceQueries`),
|
|
545
|
+
evidenceHash: requiredString(value.evidenceHash, `pages[${index}].evidenceHash`),
|
|
546
|
+
dependencySnapshot: optionalDependencySnapshot(value.dependencySnapshot, index),
|
|
547
|
+
gaps: validateGaps(value.gaps)
|
|
548
|
+
};
|
|
549
|
+
if (!isSha256(page.evidenceHash)) {
|
|
550
|
+
throw invalidPlan("wiki.plan_evidence_hash", `Wiki page ${id} evidenceHash must be a SHA-256 string.`);
|
|
551
|
+
}
|
|
552
|
+
return page;
|
|
553
|
+
}
|
|
554
|
+
function pageGaps(projectRoot, repository, page, wikiDir) {
|
|
555
|
+
const documents = new Map(repository.allDocuments().map((document) => [document.id, document]));
|
|
556
|
+
const gaps = [];
|
|
557
|
+
for (const id of page.documentIds) {
|
|
558
|
+
const document = documents.get(id);
|
|
559
|
+
const previousPath = page.dependencySnapshot?.documents.find((item) => item.id === id)?.path;
|
|
560
|
+
if (!document || isUnderWikiDir(document.path, wikiDir))
|
|
561
|
+
gaps.push({ kind: "document", path: document?.path ?? previousPath,
|
|
562
|
+
reason: !document ? `Selected document ${id} is no longer indexed.` : "Wiki output cannot serve as its own source evidence.",
|
|
563
|
+
recovery: "Review the selected documentIds, restore or replace the source, and refresh the plan." });
|
|
564
|
+
}
|
|
565
|
+
for (const source of page.sourceRefs) {
|
|
566
|
+
const fingerprint = sourceRefFingerprint(projectRoot, source);
|
|
567
|
+
if (!/^[a-f0-9]{64}$/.test(fingerprint) || isUnderWikiDir(source, wikiDir))
|
|
568
|
+
gaps.push({ kind: "source_ref", path: source,
|
|
569
|
+
reason: isUnderWikiDir(source, wikiDir) ? "Wiki output cannot serve as its own source evidence." : `Source reference is ${fingerprint}.`,
|
|
570
|
+
recovery: "Inspect the source path and restore it or explicitly revise the selected sourceRefs before refreshing the plan." });
|
|
571
|
+
}
|
|
572
|
+
return gaps;
|
|
573
|
+
}
|
|
574
|
+
function validateGaps(value) {
|
|
575
|
+
if (value === undefined)
|
|
576
|
+
return undefined;
|
|
577
|
+
if (!Array.isArray(value))
|
|
578
|
+
throw invalidPlan("wiki.plan_gaps", "gaps must be an array.");
|
|
579
|
+
return value.map((gap) => {
|
|
580
|
+
if (!isRecord(gap) || !["document", "source_ref", "domain"].includes(String(gap.kind)))
|
|
581
|
+
throw invalidPlan("wiki.plan_gaps", "Gap kind must identify a document, source_ref, or domain.");
|
|
582
|
+
if (gap.path !== undefined && (typeof gap.path !== "string" || !safeProjectRelativePath(gap.path)))
|
|
583
|
+
throw invalidPlan("wiki.plan_gaps", "Gap paths must be project-relative.");
|
|
584
|
+
return { kind: gap.kind, path: gap.path, reason: requiredString(gap.reason, "gap.reason"), recovery: requiredString(gap.recovery, "gap.recovery") };
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
function compareDocuments(left, right) {
|
|
588
|
+
return left.path.localeCompare(right.path) || left.id.localeCompare(right.id);
|
|
589
|
+
}
|
|
590
|
+
function invalidPlan(code, message) {
|
|
591
|
+
return new WikiPlanError(code, message, "Regenerate the artifact with `mdgraph wiki plan --out <plan-file>`.");
|
|
592
|
+
}
|
|
593
|
+
function requiredString(value, field) {
|
|
594
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
595
|
+
throw invalidPlan("wiki.plan_field", `${field} must be a non-empty string.`);
|
|
596
|
+
}
|
|
597
|
+
return value.trim();
|
|
598
|
+
}
|
|
599
|
+
function optionalString(value) {
|
|
600
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
601
|
+
}
|
|
602
|
+
function stringArray(value, field) {
|
|
603
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string" || !item.trim())) {
|
|
604
|
+
throw invalidPlan("wiki.plan_field", `${field} must be an array of non-empty strings.`);
|
|
605
|
+
}
|
|
606
|
+
return value.map((item) => item.trim());
|
|
607
|
+
}
|
|
608
|
+
function isSha256(value) {
|
|
609
|
+
return typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
|
|
610
|
+
}
|
|
611
|
+
function isRecord(value) {
|
|
612
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
613
|
+
}
|
|
614
|
+
function positiveIntegerOr(value, fallback) {
|
|
615
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : fallback;
|
|
616
|
+
}
|