@kaddo/cli 3.124.5 → 3.125.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/dist/core.js +533 -92
- package/dist/index.js +3005 -2530
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -141,8 +141,8 @@ function loadConfig(dir) {
|
|
|
141
141
|
const parsed = configSchema.safeParse(raw ?? {});
|
|
142
142
|
if (!parsed.success) {
|
|
143
143
|
const issues = parsed.error.issues.map((i) => {
|
|
144
|
-
const
|
|
145
|
-
return
|
|
144
|
+
const path8 = i.path.join(".");
|
|
145
|
+
return path8 ? ` - ${path8}: ${i.message}` : ` - ${i.message}`;
|
|
146
146
|
}).join("\n");
|
|
147
147
|
throw new ConfigError(`Invalid .kaddo/config.yml:
|
|
148
148
|
${issues}`);
|
|
@@ -394,11 +394,11 @@ function moduleArtifactCoverage(dir, id) {
|
|
|
394
394
|
};
|
|
395
395
|
}
|
|
396
396
|
function loadMappedModules(dir) {
|
|
397
|
-
const
|
|
398
|
-
if (!exists(
|
|
397
|
+
const path8 = join(dir, DESCRIPTOR_PATH);
|
|
398
|
+
if (!exists(path8)) return [];
|
|
399
399
|
let parsed;
|
|
400
400
|
try {
|
|
401
|
-
parsed = parseYaml3(readFile(
|
|
401
|
+
parsed = parseYaml3(readFile(path8));
|
|
402
402
|
} catch {
|
|
403
403
|
return [];
|
|
404
404
|
}
|
|
@@ -1629,7 +1629,7 @@ function sectionParagraph(md, title) {
|
|
|
1629
1629
|
}
|
|
1630
1630
|
return "";
|
|
1631
1631
|
}
|
|
1632
|
-
function parseCapsule(id,
|
|
1632
|
+
function parseCapsule(id, path8, md) {
|
|
1633
1633
|
const { data } = matter2(md);
|
|
1634
1634
|
const updatedAt = data.updated_at ? String(data.updated_at) : void 0;
|
|
1635
1635
|
let ageDays = null;
|
|
@@ -1639,7 +1639,7 @@ function parseCapsule(id, path6, md) {
|
|
|
1639
1639
|
}
|
|
1640
1640
|
return {
|
|
1641
1641
|
id,
|
|
1642
|
-
path:
|
|
1642
|
+
path: path8,
|
|
1643
1643
|
system: data.system ? String(data.system) : id,
|
|
1644
1644
|
owner: data.owner ? String(data.owner) : void 0,
|
|
1645
1645
|
updatedAt,
|
|
@@ -2344,9 +2344,9 @@ function buildGraph(dir, config, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
2344
2344
|
];
|
|
2345
2345
|
const presentLayers = [];
|
|
2346
2346
|
for (const layer of layerDocs) {
|
|
2347
|
-
const
|
|
2348
|
-
if (
|
|
2349
|
-
addNode({ id: layer.id, type: layer.type, label: layer.label, path:
|
|
2347
|
+
const path8 = layer.files.map((f) => `${KNOWLEDGE2}/${f}`).find((rel) => exists(join(dir, rel)));
|
|
2348
|
+
if (path8) {
|
|
2349
|
+
addNode({ id: layer.id, type: layer.type, label: layer.label, path: path8 });
|
|
2350
2350
|
presentLayers.push(layer.id);
|
|
2351
2351
|
}
|
|
2352
2352
|
}
|
|
@@ -3490,14 +3490,14 @@ function discoverAgents(dir) {
|
|
|
3490
3490
|
const base = join(dir, "knowledge", "agents");
|
|
3491
3491
|
if (!exists(base) || !isDir(base)) return [];
|
|
3492
3492
|
const out = /* @__PURE__ */ new Set();
|
|
3493
|
-
const
|
|
3493
|
+
const walk2 = (d) => {
|
|
3494
3494
|
for (const e of readDir(d)) {
|
|
3495
3495
|
const full = join(d, e);
|
|
3496
|
-
if (isDir(full))
|
|
3496
|
+
if (isDir(full)) walk2(full);
|
|
3497
3497
|
else if (e.endsWith("-agent.md")) out.add(e.replace(/\.md$/, ""));
|
|
3498
3498
|
}
|
|
3499
3499
|
};
|
|
3500
|
-
|
|
3500
|
+
walk2(base);
|
|
3501
3501
|
return [...out].sort();
|
|
3502
3502
|
}
|
|
3503
3503
|
function buildCodexAdapterContext(dir) {
|
|
@@ -3752,13 +3752,13 @@ function meaningful(text2) {
|
|
|
3752
3752
|
});
|
|
3753
3753
|
}
|
|
3754
3754
|
function readPocSummary(dir) {
|
|
3755
|
-
const
|
|
3756
|
-
if (!exists(
|
|
3755
|
+
const path8 = join(dir, POC_ARTIFACT_PATH);
|
|
3756
|
+
if (!exists(path8)) {
|
|
3757
3757
|
return { exists: false, hypothesisDefined: false, successCriteriaCount: 0, constraintsDefined: false, nonGoalsDefined: false, conclusion: "pending" };
|
|
3758
3758
|
}
|
|
3759
3759
|
let markdown = "";
|
|
3760
3760
|
try {
|
|
3761
|
-
markdown = readFile(
|
|
3761
|
+
markdown = readFile(path8);
|
|
3762
3762
|
} catch {
|
|
3763
3763
|
return { exists: false, hypothesisDefined: false, successCriteriaCount: 0, constraintsDefined: false, nonGoalsDefined: false, conclusion: "pending" };
|
|
3764
3764
|
}
|
|
@@ -3793,11 +3793,11 @@ function redactSecrets(value) {
|
|
|
3793
3793
|
return line.replace(/([:=]\s*)\S+.*/, "$1[redacted]");
|
|
3794
3794
|
}).join("\n");
|
|
3795
3795
|
}
|
|
3796
|
-
function source(dir,
|
|
3797
|
-
const absolute = join(dir,
|
|
3796
|
+
function source(dir, path8, kind) {
|
|
3797
|
+
const absolute = join(dir, path8);
|
|
3798
3798
|
if (!exists(absolute)) return null;
|
|
3799
3799
|
const raw = readFile(absolute);
|
|
3800
|
-
return { path: posix(
|
|
3800
|
+
return { path: posix(path8), kind, digest: sha(raw), content: redactSecrets(raw) };
|
|
3801
3801
|
}
|
|
3802
3802
|
function reportFiles(dir) {
|
|
3803
3803
|
const delivery = join(dir, "knowledge", "delivery");
|
|
@@ -3837,9 +3837,9 @@ function buildPocReportContext(dir) {
|
|
|
3837
3837
|
};
|
|
3838
3838
|
}
|
|
3839
3839
|
const sources = [];
|
|
3840
|
-
const add = (
|
|
3841
|
-
if (sources.some((item2) => item2.path === posix(
|
|
3842
|
-
const item = source(dir,
|
|
3840
|
+
const add = (path8, kind) => {
|
|
3841
|
+
if (sources.some((item2) => item2.path === posix(path8))) return;
|
|
3842
|
+
const item = source(dir, path8, kind);
|
|
3843
3843
|
if (item) sources.push(item);
|
|
3844
3844
|
};
|
|
3845
3845
|
add(POC_ARTIFACT_PATH, "poc");
|
|
@@ -3867,7 +3867,7 @@ function buildPocReportContext(dir) {
|
|
|
3867
3867
|
const sourceFingerprint = sha(sources.map((item) => `${item.path}\0${item.digest}`).join("\n"));
|
|
3868
3868
|
const status = !latestReport ? "missing" : latestReport.sourceFingerprint === sourceFingerprint ? "current" : "stale";
|
|
3869
3869
|
const currentManifest = Object.fromEntries(sources.map((item) => [item.path, item.digest]));
|
|
3870
|
-
const changesSinceLatest = status === "stale" ? [.../* @__PURE__ */ new Set([...Object.keys(currentManifest), ...Object.keys(latestReport?.sourceManifest ?? {})])].filter((
|
|
3870
|
+
const changesSinceLatest = status === "stale" ? [.../* @__PURE__ */ new Set([...Object.keys(currentManifest), ...Object.keys(latestReport?.sourceManifest ?? {})])].filter((path8) => currentManifest[path8] !== latestReport?.sourceManifest[path8]).sort() : [];
|
|
3871
3871
|
const sourceList = sources.map((item) => `- ${item.path} (${item.kind})`).join("\n") || "- No sources selected.";
|
|
3872
3872
|
return {
|
|
3873
3873
|
eligible: true,
|
|
@@ -4043,10 +4043,10 @@ function resolveNextStep(dir, now = /* @__PURE__ */ new Date()) {
|
|
|
4043
4043
|
const q = (rel) => analyzeKnowledgeArtifact(dir, rel);
|
|
4044
4044
|
const resolveAgent = (agent) => {
|
|
4045
4045
|
const file = agent.endsWith(".md") ? agent : `${agent}.md`;
|
|
4046
|
-
const
|
|
4047
|
-
const installed = isFile(join(dir,
|
|
4046
|
+
const path8 = agentInstallPath(file);
|
|
4047
|
+
const installed = isFile(join(dir, path8));
|
|
4048
4048
|
const group = agentGroupOf(file);
|
|
4049
|
-
return { agentPath:
|
|
4049
|
+
return { agentPath: path8, agentInstalled: installed, installCommand: installed ? void 0 : `kaddo add agents --group ${group}` };
|
|
4050
4050
|
};
|
|
4051
4051
|
const moduleRepo = isModule(config);
|
|
4052
4052
|
const coreRepo = isCore(config);
|
|
@@ -5592,8 +5592,8 @@ function withResponsibilityTrace(fileName, content) {
|
|
|
5592
5592
|
const skills = renderSkillsSection(agent);
|
|
5593
5593
|
const skillsBlock = skills ? `${skills}
|
|
5594
5594
|
` : "";
|
|
5595
|
-
const
|
|
5596
|
-
const frontmatterBlock =
|
|
5595
|
+
const frontmatter2 = renderFrontmatterRules(agent);
|
|
5596
|
+
const frontmatterBlock = frontmatter2 ? `${frontmatter2}
|
|
5597
5597
|
` : "";
|
|
5598
5598
|
return `${content.trimEnd()}
|
|
5599
5599
|
|
|
@@ -7943,23 +7943,23 @@ var VALID_SOURCES = [
|
|
|
7943
7943
|
function isValidSource(s) {
|
|
7944
7944
|
return VALID_SOURCES.includes(s);
|
|
7945
7945
|
}
|
|
7946
|
-
function parseWorkItemSource(
|
|
7947
|
-
const rawSource =
|
|
7946
|
+
function parseWorkItemSource(frontmatter2) {
|
|
7947
|
+
const rawSource = frontmatter2.source;
|
|
7948
7948
|
if (rawSource != null && typeof rawSource === "object" && !Array.isArray(rawSource)) {
|
|
7949
7949
|
const obj = rawSource;
|
|
7950
7950
|
const t = optStr2(obj.type);
|
|
7951
7951
|
const type = t && isValidSource(t) ? t : "unknown";
|
|
7952
7952
|
return {
|
|
7953
7953
|
type,
|
|
7954
|
-
id: optStr2(obj.id) ?? optStr2(
|
|
7955
|
-
title: optStr2(obj.title) ?? optStr2(
|
|
7956
|
-
context: optStr2(obj.context) ?? optStr2(
|
|
7957
|
-
provider: optStr2(obj.provider) ?? optStr2(
|
|
7958
|
-
integration: optStr2(obj.integration) ?? optStr2(
|
|
7959
|
-
url: optStr2(obj.url) ?? optStr2(
|
|
7960
|
-
imported_at: optStr2(obj.imported_at) ?? optStr2(
|
|
7961
|
-
external_updated_at: optStr2(obj.external_updated_at) ?? optStr2(
|
|
7962
|
-
synced_at: optStr2(obj.synced_at) ?? optStr2(
|
|
7954
|
+
id: optStr2(obj.id) ?? optStr2(frontmatter2.source_id),
|
|
7955
|
+
title: optStr2(obj.title) ?? optStr2(frontmatter2.source_title),
|
|
7956
|
+
context: optStr2(obj.context) ?? optStr2(frontmatter2.source_context),
|
|
7957
|
+
provider: optStr2(obj.provider) ?? optStr2(frontmatter2.source_provider),
|
|
7958
|
+
integration: optStr2(obj.integration) ?? optStr2(frontmatter2.source_integration),
|
|
7959
|
+
url: optStr2(obj.url) ?? optStr2(frontmatter2.source_url),
|
|
7960
|
+
imported_at: optStr2(obj.imported_at) ?? optStr2(frontmatter2.source_imported_at),
|
|
7961
|
+
external_updated_at: optStr2(obj.external_updated_at) ?? optStr2(frontmatter2.source_external_updated_at),
|
|
7962
|
+
synced_at: optStr2(obj.synced_at) ?? optStr2(frontmatter2.source_synced_at),
|
|
7963
7963
|
inferred: obj.inferred === true || obj.inferred === "true",
|
|
7964
7964
|
reason: t && !isValidSource(t) ? `Invalid source type in object: "${t}".` : void 0
|
|
7965
7965
|
};
|
|
@@ -7968,45 +7968,45 @@ function parseWorkItemSource(frontmatter) {
|
|
|
7968
7968
|
if (raw && isValidSource(raw)) {
|
|
7969
7969
|
return {
|
|
7970
7970
|
type: raw,
|
|
7971
|
-
id: optStr2(
|
|
7972
|
-
title: optStr2(
|
|
7973
|
-
context: optStr2(
|
|
7974
|
-
provider: optStr2(
|
|
7975
|
-
url: optStr2(
|
|
7976
|
-
imported_at: optStr2(
|
|
7977
|
-
external_updated_at: optStr2(
|
|
7978
|
-
synced_at: optStr2(
|
|
7971
|
+
id: optStr2(frontmatter2.source_id),
|
|
7972
|
+
title: optStr2(frontmatter2.source_title),
|
|
7973
|
+
context: optStr2(frontmatter2.source_context),
|
|
7974
|
+
provider: optStr2(frontmatter2.source_provider),
|
|
7975
|
+
url: optStr2(frontmatter2.source_url),
|
|
7976
|
+
imported_at: optStr2(frontmatter2.source_imported_at),
|
|
7977
|
+
external_updated_at: optStr2(frontmatter2.source_external_updated_at),
|
|
7978
|
+
synced_at: optStr2(frontmatter2.source_synced_at),
|
|
7979
7979
|
inferred: false
|
|
7980
7980
|
};
|
|
7981
7981
|
}
|
|
7982
7982
|
if (raw && !isValidSource(raw)) {
|
|
7983
7983
|
return {
|
|
7984
7984
|
type: "unknown",
|
|
7985
|
-
id: optStr2(
|
|
7986
|
-
title: optStr2(
|
|
7987
|
-
context: optStr2(
|
|
7988
|
-
provider: optStr2(
|
|
7989
|
-
url: optStr2(
|
|
7990
|
-
imported_at: optStr2(
|
|
7991
|
-
external_updated_at: optStr2(
|
|
7992
|
-
synced_at: optStr2(
|
|
7985
|
+
id: optStr2(frontmatter2.source_id),
|
|
7986
|
+
title: optStr2(frontmatter2.source_title),
|
|
7987
|
+
context: optStr2(frontmatter2.source_context),
|
|
7988
|
+
provider: optStr2(frontmatter2.source_provider),
|
|
7989
|
+
url: optStr2(frontmatter2.source_url),
|
|
7990
|
+
imported_at: optStr2(frontmatter2.source_imported_at),
|
|
7991
|
+
external_updated_at: optStr2(frontmatter2.source_external_updated_at),
|
|
7992
|
+
synced_at: optStr2(frontmatter2.source_synced_at),
|
|
7993
7993
|
inferred: true,
|
|
7994
7994
|
reason: `Invalid source value: "${raw}".`
|
|
7995
7995
|
};
|
|
7996
7996
|
}
|
|
7997
|
-
if (
|
|
7997
|
+
if (frontmatter2.source_work_item_candidate || frontmatter2.source_roadmap_initiative) {
|
|
7998
7998
|
return {
|
|
7999
7999
|
type: "roadmap",
|
|
8000
|
-
id: optStr2(
|
|
8001
|
-
title: optStr2(
|
|
8000
|
+
id: optStr2(frontmatter2.source_id) ?? optStr2(frontmatter2.source_work_item_candidate),
|
|
8001
|
+
title: optStr2(frontmatter2.source_initiative_title),
|
|
8002
8002
|
inferred: true,
|
|
8003
8003
|
reason: "Inferred from legacy roadmap fields."
|
|
8004
8004
|
};
|
|
8005
8005
|
}
|
|
8006
|
-
if (
|
|
8006
|
+
if (frontmatter2.source_id) {
|
|
8007
8007
|
return {
|
|
8008
8008
|
type: "unknown",
|
|
8009
|
-
id: optStr2(
|
|
8009
|
+
id: optStr2(frontmatter2.source_id),
|
|
8010
8010
|
inferred: true,
|
|
8011
8011
|
reason: "Has source_id but no source type."
|
|
8012
8012
|
};
|
|
@@ -9067,7 +9067,7 @@ function buildGuardHistory(dir) {
|
|
|
9067
9067
|
const d = hotspotDir(t.code_path);
|
|
9068
9068
|
hotspotMap.set(d, (hotspotMap.get(d) ?? 0) + 1);
|
|
9069
9069
|
}
|
|
9070
|
-
const hotspots = [...hotspotMap.entries()].map(([
|
|
9070
|
+
const hotspots = [...hotspotMap.entries()].map(([path8, warnings]) => ({ path: path8, warnings })).sort((a, b) => b.warnings - a.warnings);
|
|
9071
9071
|
return {
|
|
9072
9072
|
available: true,
|
|
9073
9073
|
total_runs: sorted.length,
|
|
@@ -10988,8 +10988,8 @@ function parseGraphReason(v) {
|
|
|
10988
10988
|
if (!v || typeof v !== "object") return null;
|
|
10989
10989
|
const o = v;
|
|
10990
10990
|
const relationship = typeof o.relationship === "string" && o.relationship.trim() ? o.relationship.trim() : null;
|
|
10991
|
-
const
|
|
10992
|
-
return relationship ||
|
|
10991
|
+
const path8 = Array.isArray(o.path) ? o.path.map(String).filter(Boolean) : [];
|
|
10992
|
+
return relationship || path8.length ? { relationship, path: path8 } : null;
|
|
10993
10993
|
}
|
|
10994
10994
|
function parseExplain(o) {
|
|
10995
10995
|
const refs = Array.isArray(o.evidence) ? o.evidence : Array.isArray(o.evidence_refs) ? o.evidence_refs : [];
|
|
@@ -11421,7 +11421,7 @@ function slugify2(s) {
|
|
|
11421
11421
|
function nextWorkItemId(dir) {
|
|
11422
11422
|
const wiDir = join(dir, WORK_ITEMS_DIR);
|
|
11423
11423
|
let max = 0;
|
|
11424
|
-
const
|
|
11424
|
+
const walk2 = (d) => {
|
|
11425
11425
|
if (!exists(d)) return;
|
|
11426
11426
|
for (const entry of fs4.readdirSync(d)) {
|
|
11427
11427
|
const full = join(d, entry);
|
|
@@ -11429,11 +11429,11 @@ function nextWorkItemId(dir) {
|
|
|
11429
11429
|
const m = entry.match(/WI-(\d+)/);
|
|
11430
11430
|
if (m) max = Math.max(max, parseInt(m[1], 10));
|
|
11431
11431
|
} else if (!entry.startsWith(".")) {
|
|
11432
|
-
|
|
11432
|
+
walk2(full);
|
|
11433
11433
|
}
|
|
11434
11434
|
}
|
|
11435
11435
|
};
|
|
11436
|
-
|
|
11436
|
+
walk2(wiDir);
|
|
11437
11437
|
return `WI-${String(max + 1).padStart(3, "0")}`;
|
|
11438
11438
|
}
|
|
11439
11439
|
function atomicWrite3(filePath, content) {
|
|
@@ -12103,19 +12103,19 @@ function findSystemPaths(dir, source2, target, opts = {}) {
|
|
|
12103
12103
|
out.get(r.source).push(r.target);
|
|
12104
12104
|
}
|
|
12105
12105
|
const paths = [];
|
|
12106
|
-
const
|
|
12106
|
+
const walk2 = (node, path8) => {
|
|
12107
12107
|
if (paths.length >= 20) return;
|
|
12108
|
-
if (node === target &&
|
|
12109
|
-
paths.push([...
|
|
12108
|
+
if (node === target && path8.length > 1) {
|
|
12109
|
+
paths.push([...path8]);
|
|
12110
12110
|
return;
|
|
12111
12111
|
}
|
|
12112
|
-
if (
|
|
12112
|
+
if (path8.length > maxDepth) return;
|
|
12113
12113
|
for (const nxt of out.get(node) ?? []) {
|
|
12114
|
-
if (
|
|
12115
|
-
|
|
12114
|
+
if (path8.includes(nxt)) continue;
|
|
12115
|
+
walk2(nxt, [...path8, nxt]);
|
|
12116
12116
|
}
|
|
12117
12117
|
};
|
|
12118
|
-
|
|
12118
|
+
walk2(source2, [source2]);
|
|
12119
12119
|
return paths;
|
|
12120
12120
|
}
|
|
12121
12121
|
function getImpactCandidates(dir, seedIds, opts = {}) {
|
|
@@ -12137,14 +12137,14 @@ function getImpactCandidates(dir, seedIds, opts = {}) {
|
|
|
12137
12137
|
existing.reason.push(reason);
|
|
12138
12138
|
continue;
|
|
12139
12139
|
}
|
|
12140
|
-
const
|
|
12140
|
+
const path8 = findSystemPaths(dir, seed, n.id, { maxDepth: opts.maxDepth ?? DEFAULT_MAX_DEPTH })[0];
|
|
12141
12141
|
candidates.set(n.id, {
|
|
12142
12142
|
nodeId: n.id,
|
|
12143
12143
|
label: n.label,
|
|
12144
12144
|
kind: n.type,
|
|
12145
12145
|
...n.moduleId ? { moduleId: n.moduleId } : {},
|
|
12146
12146
|
reason: [reason],
|
|
12147
|
-
...
|
|
12147
|
+
...path8 ? { graphPath: path8.map((id) => byId.get(id)?.label ?? id) } : {},
|
|
12148
12148
|
...n.implementationRefs?.length ? { implementationRefs: n.implementationRefs } : {},
|
|
12149
12149
|
...n.knowledgeRefs?.length ? { knowledgeRefs: n.knowledgeRefs } : {},
|
|
12150
12150
|
status: "candidate",
|
|
@@ -14032,8 +14032,8 @@ async function handleJiraResponse(res) {
|
|
|
14032
14032
|
}
|
|
14033
14033
|
return await res.json();
|
|
14034
14034
|
}
|
|
14035
|
-
async function jiraFetch(baseUrl,
|
|
14036
|
-
const url = new URL(
|
|
14035
|
+
async function jiraFetch(baseUrl, path8, auth, timeoutMs, params) {
|
|
14036
|
+
const url = new URL(path8, baseUrl + "/");
|
|
14037
14037
|
if (params) for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
|
|
14038
14038
|
const controller = new AbortController();
|
|
14039
14039
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -14051,8 +14051,8 @@ async function jiraFetch(baseUrl, path6, auth, timeoutMs, params) {
|
|
|
14051
14051
|
clearTimeout(timer);
|
|
14052
14052
|
}
|
|
14053
14053
|
}
|
|
14054
|
-
async function jiraPost(baseUrl,
|
|
14055
|
-
const url = new URL(
|
|
14054
|
+
async function jiraPost(baseUrl, path8, auth, timeoutMs, body) {
|
|
14055
|
+
const url = new URL(path8, baseUrl + "/");
|
|
14056
14056
|
const controller = new AbortController();
|
|
14057
14057
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
14058
14058
|
try {
|
|
@@ -15005,7 +15005,7 @@ function addExternalLink(dir, id, link) {
|
|
|
15005
15005
|
function nextWorkItemId2(dir) {
|
|
15006
15006
|
const wiDir = join(dir, WORK_ITEMS_DIR2);
|
|
15007
15007
|
let max = 0;
|
|
15008
|
-
const
|
|
15008
|
+
const walk2 = (d) => {
|
|
15009
15009
|
if (!exists(d)) return;
|
|
15010
15010
|
for (const entry of readDir(d)) {
|
|
15011
15011
|
const full = join(d, entry);
|
|
@@ -15013,11 +15013,11 @@ function nextWorkItemId2(dir) {
|
|
|
15013
15013
|
const m = entry.match(/WI-(\d+)/);
|
|
15014
15014
|
if (m) max = Math.max(max, parseInt(m[1], 10));
|
|
15015
15015
|
} else if (!entry.startsWith(".")) {
|
|
15016
|
-
|
|
15016
|
+
walk2(full);
|
|
15017
15017
|
}
|
|
15018
15018
|
}
|
|
15019
15019
|
};
|
|
15020
|
-
|
|
15020
|
+
walk2(wiDir);
|
|
15021
15021
|
return `WI-${String(max + 1).padStart(3, "0")}`;
|
|
15022
15022
|
}
|
|
15023
15023
|
function buildWorkItemContent(wiId, iniId, candidate) {
|
|
@@ -15485,7 +15485,7 @@ function buildProductionRunbookContext(dir, planId, targetId) {
|
|
|
15485
15485
|
blockers.push(`Dependency ${dependency.id} is not retired (current: ${dependency.lifecycle}).`);
|
|
15486
15486
|
}
|
|
15487
15487
|
}
|
|
15488
|
-
const
|
|
15488
|
+
const path8 = runbookPath(dir, target);
|
|
15489
15489
|
return {
|
|
15490
15490
|
eligible: blockers.length === 0,
|
|
15491
15491
|
plan: { id: plan.id, title: plan.title, purpose: plan.purpose },
|
|
@@ -15493,7 +15493,7 @@ function buildProductionRunbookContext(dir, planId, targetId) {
|
|
|
15493
15493
|
resource: target.resource ? getResource(dir, target.resource) : null,
|
|
15494
15494
|
dependencies,
|
|
15495
15495
|
blockers,
|
|
15496
|
-
nextPath:
|
|
15496
|
+
nextPath: path8,
|
|
15497
15497
|
nextStep: blockers.length > 0 ? "Resolve the listed safeguards; no production proposal can be persisted yet." : "Review the generated proposal, obtain human approval, execute manually, then record evidence and validate the observation window."
|
|
15498
15498
|
};
|
|
15499
15499
|
}
|
|
@@ -15586,8 +15586,8 @@ function renderRunbook(context) {
|
|
|
15586
15586
|
function createProductionRunbook(dir, planId, targetId) {
|
|
15587
15587
|
const context = buildProductionRunbookContext(dir, planId, targetId);
|
|
15588
15588
|
if (!context.eligible) throw new ProductionRunbookError(context.blockers.join(" "));
|
|
15589
|
-
const
|
|
15590
|
-
const id =
|
|
15589
|
+
const path8 = context.nextPath;
|
|
15590
|
+
const id = path8.split("/").pop()?.match(/^(RB-\d+)-/)?.[1] ?? "";
|
|
15591
15591
|
const content = matter18.stringify(renderRunbook(context), {
|
|
15592
15592
|
id,
|
|
15593
15593
|
type: PRODUCTION_RUNBOOK_ARTIFACT_TYPE,
|
|
@@ -15597,13 +15597,13 @@ function createProductionRunbook(dir, planId, targetId) {
|
|
|
15597
15597
|
resource: context.target.resource,
|
|
15598
15598
|
approval: { required: true, status: "pending", approved_by: null, approved_at: null }
|
|
15599
15599
|
});
|
|
15600
|
-
const absolute = join(dir,
|
|
15601
|
-
if (exists(absolute)) throw new ProductionRunbookError(`Runbook already exists: ${
|
|
15600
|
+
const absolute = join(dir, path8);
|
|
15601
|
+
if (exists(absolute)) throw new ProductionRunbookError(`Runbook already exists: ${path8}`);
|
|
15602
15602
|
writeFile(absolute, content);
|
|
15603
15603
|
return {
|
|
15604
15604
|
id,
|
|
15605
15605
|
title: `Production runbook \u2014 ${context.target.title ?? context.target.id}`,
|
|
15606
|
-
path:
|
|
15606
|
+
path: path8,
|
|
15607
15607
|
planId: context.plan.id,
|
|
15608
15608
|
targetId: context.target.id,
|
|
15609
15609
|
approval: { required: true, status: "pending", approvedBy: null, approvedAt: null },
|
|
@@ -15614,14 +15614,14 @@ function getProductionRunbook(dir, id) {
|
|
|
15614
15614
|
const root = join(dir, PRODUCTION_RUNBOOKS_DIR);
|
|
15615
15615
|
for (const name of readDir(root)) {
|
|
15616
15616
|
if (!name.toLowerCase().startsWith(`${id.toLowerCase()}-`) || !name.endsWith(".md")) continue;
|
|
15617
|
-
const
|
|
15618
|
-
const parsed = matter18(readFile(join(dir,
|
|
15617
|
+
const path8 = `${PRODUCTION_RUNBOOKS_DIR}/${name}`;
|
|
15618
|
+
const parsed = matter18(readFile(join(dir, path8)));
|
|
15619
15619
|
const data = parsed.data;
|
|
15620
15620
|
if (data.type !== PRODUCTION_RUNBOOK_ARTIFACT_TYPE) continue;
|
|
15621
15621
|
return {
|
|
15622
15622
|
id: stringValue(data.id) ?? id,
|
|
15623
15623
|
title: stringValue(data.title) ?? id,
|
|
15624
|
-
path:
|
|
15624
|
+
path: path8,
|
|
15625
15625
|
planId: stringValue(data.deprecation_plan) ?? "",
|
|
15626
15626
|
targetId: stringValue(data.deprecation_target) ?? "",
|
|
15627
15627
|
approval: parseApproval(data.approval),
|
|
@@ -15643,6 +15643,438 @@ function validateProductionRunbook(runbook) {
|
|
|
15643
15643
|
if (destructive.length > 0) findings.push({ level: "warning", message: "Destructive commands are documentation only; Kaddo will never execute them." });
|
|
15644
15644
|
return findings;
|
|
15645
15645
|
}
|
|
15646
|
+
|
|
15647
|
+
// src/core/okf/export.ts
|
|
15648
|
+
import fs7 from "fs";
|
|
15649
|
+
import path6 from "path";
|
|
15650
|
+
|
|
15651
|
+
// src/core/okf/mapping.ts
|
|
15652
|
+
var OKF_TYPE_TABLE = {
|
|
15653
|
+
"business-knowledge": "Business Knowledge",
|
|
15654
|
+
"product-knowledge": "Product Knowledge",
|
|
15655
|
+
"technical-knowledge": "Technical Knowledge",
|
|
15656
|
+
capability: "Capability",
|
|
15657
|
+
decision: "Architecture Decision",
|
|
15658
|
+
adr: "Architecture Decision",
|
|
15659
|
+
"project-resource": "Project Resource",
|
|
15660
|
+
"deprecation-plan": "Deprecation Plan",
|
|
15661
|
+
initiative: "Initiative",
|
|
15662
|
+
capsule: "Knowledge Reference",
|
|
15663
|
+
"knowledge-capsule": "Knowledge Reference",
|
|
15664
|
+
"current-state": "Technical Knowledge",
|
|
15665
|
+
roadmap: "Delivery Knowledge"
|
|
15666
|
+
};
|
|
15667
|
+
var WORK_ITEM_TYPES3 = /* @__PURE__ */ new Set(["feature", "bugfix", "hotfix", "spike", "chore"]);
|
|
15668
|
+
var REPORT_TYPES = /* @__PURE__ */ new Set(["impact-report", "drift-report", "savings-report", "poc-report"]);
|
|
15669
|
+
function okfConceptType(a) {
|
|
15670
|
+
if (a.isWorkItem) return "Work Item";
|
|
15671
|
+
const t = (a.type || "").toLowerCase();
|
|
15672
|
+
if (OKF_TYPE_TABLE[t]) return OKF_TYPE_TABLE[t];
|
|
15673
|
+
if (REPORT_TYPES.has(t)) return "Report";
|
|
15674
|
+
if (WORK_ITEM_TYPES3.has(t)) return "Work Item";
|
|
15675
|
+
if (a.layer === "business") return "Business Knowledge";
|
|
15676
|
+
if (a.layer === "product") return "Product Knowledge";
|
|
15677
|
+
if (a.layer === "tech" || a.layer === "module") return "Technical Knowledge";
|
|
15678
|
+
if (a.layer === "delivery") return "Delivery Knowledge";
|
|
15679
|
+
return t ? t.replace(/(^|[-_ ])(\w)/g, (_, s, c) => (s ? " " : "") + c.toUpperCase()) : "Knowledge";
|
|
15680
|
+
}
|
|
15681
|
+
function str3(v) {
|
|
15682
|
+
return typeof v === "string" && v.trim() ? v.trim() : null;
|
|
15683
|
+
}
|
|
15684
|
+
function strArray3(v) {
|
|
15685
|
+
return Array.isArray(v) ? v.map((x) => String(x).trim()).filter(Boolean) : [];
|
|
15686
|
+
}
|
|
15687
|
+
function conceptBundlePath(a, id) {
|
|
15688
|
+
const file = `${id}.md`;
|
|
15689
|
+
if (a.isWorkItem) return `delivery/work-items/${file}`;
|
|
15690
|
+
const t = (a.type || "").toLowerCase();
|
|
15691
|
+
if (t === "deprecation-plan") return `delivery/deprecations/${file}`;
|
|
15692
|
+
if (t === "production-runbook") return `delivery/runbooks/${file}`;
|
|
15693
|
+
if (t === "project-resource") return `resources/${file}`;
|
|
15694
|
+
if (t === "knowledge-capsule" || t === "capsule") return `external/${file}`;
|
|
15695
|
+
switch (a.layer) {
|
|
15696
|
+
case "business":
|
|
15697
|
+
return `business/${file}`;
|
|
15698
|
+
case "product":
|
|
15699
|
+
return `product/${file}`;
|
|
15700
|
+
case "tech":
|
|
15701
|
+
return `tech/${file}`;
|
|
15702
|
+
case "module":
|
|
15703
|
+
return `tech/modules/${file}`;
|
|
15704
|
+
case "delivery":
|
|
15705
|
+
return `delivery/${file}`;
|
|
15706
|
+
default:
|
|
15707
|
+
return `misc/${file}`;
|
|
15708
|
+
}
|
|
15709
|
+
}
|
|
15710
|
+
function workItemRelations(fm) {
|
|
15711
|
+
const out = [];
|
|
15712
|
+
const resources = fm.resources;
|
|
15713
|
+
if (Array.isArray(resources)) {
|
|
15714
|
+
for (const r of resources) {
|
|
15715
|
+
if (r && typeof r === "object") {
|
|
15716
|
+
const id = str3(r.id);
|
|
15717
|
+
if (id) out.push({ id, role: str3(r.role) ?? "uses" });
|
|
15718
|
+
}
|
|
15719
|
+
}
|
|
15720
|
+
}
|
|
15721
|
+
const dep = fm.deprecation_targets;
|
|
15722
|
+
if (Array.isArray(dep)) {
|
|
15723
|
+
for (const d of dep) {
|
|
15724
|
+
const s = typeof d === "string" ? d : d && typeof d === "object" ? str3(d.plan) : null;
|
|
15725
|
+
if (s) out.push({ id: s.includes("/") ? s.split("/")[0] : s, role: "deprecates-via" });
|
|
15726
|
+
}
|
|
15727
|
+
}
|
|
15728
|
+
const parent = str3(fm.parent);
|
|
15729
|
+
if (parent) out.push({ id: parent, role: "child-of" });
|
|
15730
|
+
for (const dId of strArray3(fm.decisions)) out.push({ id: dId, role: "decided-by" });
|
|
15731
|
+
return out;
|
|
15732
|
+
}
|
|
15733
|
+
function slugify4(s) {
|
|
15734
|
+
return s.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
|
|
15735
|
+
}
|
|
15736
|
+
function conceptId(a) {
|
|
15737
|
+
if (a.id) return a.id;
|
|
15738
|
+
if (a.title) return slugify4(a.title);
|
|
15739
|
+
const base = a.relPath.split("/").pop() ?? "";
|
|
15740
|
+
return slugify4(base.replace(/\.md$/, "")) || slugify4(a.relPath);
|
|
15741
|
+
}
|
|
15742
|
+
function buildConcept(a) {
|
|
15743
|
+
const id = conceptId(a);
|
|
15744
|
+
if (!id) return null;
|
|
15745
|
+
const rawFm = a.rawFrontmatter ?? {};
|
|
15746
|
+
return {
|
|
15747
|
+
id,
|
|
15748
|
+
type: okfConceptType(a),
|
|
15749
|
+
title: a.title || id,
|
|
15750
|
+
description: str3(a.summary),
|
|
15751
|
+
tags: a.domains.map((d) => String(d).toLowerCase()),
|
|
15752
|
+
path: conceptBundlePath(a, id),
|
|
15753
|
+
sourcePath: a.relPath,
|
|
15754
|
+
related: a.isWorkItem ? workItemRelations(rawFm) : [],
|
|
15755
|
+
body: null
|
|
15756
|
+
};
|
|
15757
|
+
}
|
|
15758
|
+
|
|
15759
|
+
// src/core/okf/extras.ts
|
|
15760
|
+
function reportConcepts(dir, now = /* @__PURE__ */ new Date()) {
|
|
15761
|
+
const concepts = [];
|
|
15762
|
+
const warnings = [];
|
|
15763
|
+
const at = now.toISOString();
|
|
15764
|
+
const add = (id, title, description, build) => {
|
|
15765
|
+
try {
|
|
15766
|
+
const body = build();
|
|
15767
|
+
concepts.push({
|
|
15768
|
+
id,
|
|
15769
|
+
type: "Report",
|
|
15770
|
+
title,
|
|
15771
|
+
description,
|
|
15772
|
+
tags: ["report"],
|
|
15773
|
+
path: `reports/${id}.md`,
|
|
15774
|
+
sourcePath: null,
|
|
15775
|
+
generatedAt: at,
|
|
15776
|
+
related: [],
|
|
15777
|
+
body
|
|
15778
|
+
});
|
|
15779
|
+
} catch (e) {
|
|
15780
|
+
warnings.push(`Report "${id}" skipped: ${e instanceof Error ? e.message : String(e)}`);
|
|
15781
|
+
}
|
|
15782
|
+
};
|
|
15783
|
+
add(
|
|
15784
|
+
"report-impact",
|
|
15785
|
+
"Impact Report",
|
|
15786
|
+
"Knowledge-code impact, derived from evidence.",
|
|
15787
|
+
() => renderImpactMarkdown(buildImpactReport(dir, {}, now), { details: true })
|
|
15788
|
+
);
|
|
15789
|
+
add(
|
|
15790
|
+
"report-drift",
|
|
15791
|
+
"Drift Report",
|
|
15792
|
+
"Drift trend across code, knowledge, Work Items and architecture.",
|
|
15793
|
+
() => renderDriftMarkdown(buildDriftReport(dir, now))
|
|
15794
|
+
);
|
|
15795
|
+
add(
|
|
15796
|
+
"report-savings",
|
|
15797
|
+
"Savings Report",
|
|
15798
|
+
"Evidence-based savings estimates (not exact ROI).",
|
|
15799
|
+
() => renderSavingsMarkdown(buildSavingsReport(dir, {}, now))
|
|
15800
|
+
);
|
|
15801
|
+
return { concepts, warnings };
|
|
15802
|
+
}
|
|
15803
|
+
function externalCapsuleConcepts(dir) {
|
|
15804
|
+
return loadExternalRegistry(dir).map((e) => {
|
|
15805
|
+
const lines = [
|
|
15806
|
+
`# ${e.id}`,
|
|
15807
|
+
"",
|
|
15808
|
+
"External Knowledge Reference. Access is limited to its source system; its private sources are not",
|
|
15809
|
+
"included in this bundle and no operational access to the origin system is implied.",
|
|
15810
|
+
"",
|
|
15811
|
+
`- Source: \`${e.path}\``,
|
|
15812
|
+
...e.owner ? [`- Owner: ${e.owner}`] : [],
|
|
15813
|
+
...e.lastImportedAt ? [`- Last imported: ${e.lastImportedAt}`] : []
|
|
15814
|
+
];
|
|
15815
|
+
return {
|
|
15816
|
+
id: e.id,
|
|
15817
|
+
type: "Knowledge Reference",
|
|
15818
|
+
title: e.id,
|
|
15819
|
+
description: "External knowledge reference (capsule).",
|
|
15820
|
+
tags: ["reference", "external"],
|
|
15821
|
+
path: `external/${e.id}.md`,
|
|
15822
|
+
sourcePath: e.path,
|
|
15823
|
+
related: [],
|
|
15824
|
+
body: lines.join("\n")
|
|
15825
|
+
};
|
|
15826
|
+
});
|
|
15827
|
+
}
|
|
15828
|
+
|
|
15829
|
+
// src/core/okf/types.ts
|
|
15830
|
+
var OKF_VERSION = "0.2";
|
|
15831
|
+
var OKF_RESERVED_FILES = ["index.md", "log.md"];
|
|
15832
|
+
|
|
15833
|
+
// src/core/okf/export.ts
|
|
15834
|
+
var OKF_DEFAULT_OUTPUT = ".kaddo/okf";
|
|
15835
|
+
function frontmatter(data) {
|
|
15836
|
+
const lines = ["---"];
|
|
15837
|
+
for (const [k, v] of Object.entries(data)) {
|
|
15838
|
+
if (v == null) continue;
|
|
15839
|
+
if (Array.isArray(v)) {
|
|
15840
|
+
if (v.length === 0) continue;
|
|
15841
|
+
lines.push(`${k}:`);
|
|
15842
|
+
for (const item of v) {
|
|
15843
|
+
if (item && typeof item === "object") {
|
|
15844
|
+
const entries = Object.entries(item).filter(([, x]) => x != null);
|
|
15845
|
+
if (entries.length === 0) continue;
|
|
15846
|
+
lines.push(` - ${entries.map(([ik, iv]) => `${ik}: ${JSON.stringify(iv)}`).join("\n ")}`);
|
|
15847
|
+
} else {
|
|
15848
|
+
lines.push(` - ${JSON.stringify(item)}`);
|
|
15849
|
+
}
|
|
15850
|
+
}
|
|
15851
|
+
} else {
|
|
15852
|
+
lines.push(`${k}: ${JSON.stringify(v)}`);
|
|
15853
|
+
}
|
|
15854
|
+
}
|
|
15855
|
+
lines.push("---");
|
|
15856
|
+
return lines.join("\n");
|
|
15857
|
+
}
|
|
15858
|
+
function relLink(fromPath, toPath) {
|
|
15859
|
+
const rel = path6.posix.relative(path6.posix.dirname(fromPath), toPath);
|
|
15860
|
+
return rel.startsWith(".") ? rel : `./${rel}`;
|
|
15861
|
+
}
|
|
15862
|
+
function renderConcept(c, byId) {
|
|
15863
|
+
const data = {
|
|
15864
|
+
type: c.type,
|
|
15865
|
+
title: c.title,
|
|
15866
|
+
description: c.description,
|
|
15867
|
+
tags: c.tags,
|
|
15868
|
+
kaddo_id: c.id
|
|
15869
|
+
};
|
|
15870
|
+
if (c.sourcePath) data.sources = [{ resource: c.sourcePath }];
|
|
15871
|
+
if (c.generatedAt) data.generated = { at: c.generatedAt };
|
|
15872
|
+
const parts = [frontmatter(data)];
|
|
15873
|
+
if (c.body) {
|
|
15874
|
+
parts.push("", c.body.trim());
|
|
15875
|
+
} else {
|
|
15876
|
+
parts.push("", `# ${c.title}`);
|
|
15877
|
+
if (c.description) parts.push("", c.description);
|
|
15878
|
+
}
|
|
15879
|
+
const resolved = c.related.filter((r) => byId.has(r.id));
|
|
15880
|
+
if (resolved.length > 0) {
|
|
15881
|
+
parts.push("", "## Related");
|
|
15882
|
+
for (const r of resolved) {
|
|
15883
|
+
const target = byId.get(r.id);
|
|
15884
|
+
parts.push(`- [${target.title}](${relLink(c.path, target.path)}) \u2014 ${r.role}`);
|
|
15885
|
+
}
|
|
15886
|
+
}
|
|
15887
|
+
return parts.join("\n") + "\n";
|
|
15888
|
+
}
|
|
15889
|
+
function renderIndex(title, concepts, fromPath, root) {
|
|
15890
|
+
const data = { type: "Index", title };
|
|
15891
|
+
if (root) data.okf_version = OKF_VERSION;
|
|
15892
|
+
const parts = [frontmatter(data), "", `# ${title}`, ""];
|
|
15893
|
+
if (root) parts.push(
|
|
15894
|
+
`Open Knowledge Format bundle \u2014 version ${OKF_VERSION}. A portable projection of`,
|
|
15895
|
+
"Kaddo knowledge. Kaddo remains the source of truth.",
|
|
15896
|
+
""
|
|
15897
|
+
);
|
|
15898
|
+
const byType = /* @__PURE__ */ new Map();
|
|
15899
|
+
for (const c of concepts) {
|
|
15900
|
+
const l = byType.get(c.type) ?? [];
|
|
15901
|
+
l.push(c);
|
|
15902
|
+
byType.set(c.type, l);
|
|
15903
|
+
}
|
|
15904
|
+
for (const type of [...byType.keys()].sort()) {
|
|
15905
|
+
parts.push(`## ${type}`);
|
|
15906
|
+
for (const c of byType.get(type).sort((a, b) => a.id.localeCompare(b.id))) {
|
|
15907
|
+
parts.push(`- [${c.title}](${relLink(fromPath, c.path)})`);
|
|
15908
|
+
}
|
|
15909
|
+
parts.push("");
|
|
15910
|
+
}
|
|
15911
|
+
return parts.join("\n");
|
|
15912
|
+
}
|
|
15913
|
+
function atomicWrite5(file, content) {
|
|
15914
|
+
fs7.mkdirSync(path6.dirname(file), { recursive: true });
|
|
15915
|
+
fs7.writeFileSync(file, content, "utf-8");
|
|
15916
|
+
}
|
|
15917
|
+
var SENSITIVE_PATTERNS = [
|
|
15918
|
+
{ re: /-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/, label: "private key block" },
|
|
15919
|
+
{ re: /\bAKIA[0-9A-Z]{16}\b/, label: "AWS access key id" },
|
|
15920
|
+
{ re: /\bgh[pousr]_[A-Za-z0-9]{20,}\b/, label: "GitHub token" },
|
|
15921
|
+
{ re: /\b(?:password|secret|api[_-]?key|access[_-]?token)\b\s*[:=]\s*["']?[A-Za-z0-9+/_\-]{12,}/i, label: "inline credential" }
|
|
15922
|
+
];
|
|
15923
|
+
function scanSensitive(renderedPath, content) {
|
|
15924
|
+
const hits = SENSITIVE_PATTERNS.filter((p) => p.re.test(content)).map((p) => p.label);
|
|
15925
|
+
return hits.length > 0 ? [`${renderedPath}: possible ${[...new Set(hits)].join(", ")} \u2014 review before sharing.`] : [];
|
|
15926
|
+
}
|
|
15927
|
+
function exportOkf(dir, opts = {}) {
|
|
15928
|
+
const outRel = opts.output ?? OKF_DEFAULT_OUTPUT;
|
|
15929
|
+
const outputDir = path6.isAbsolute(outRel) ? outRel : path6.join(dir, outRel);
|
|
15930
|
+
const extraWarnings = [];
|
|
15931
|
+
const artifacts = discoverKnowledge(dir);
|
|
15932
|
+
const concepts = [];
|
|
15933
|
+
const seen = /* @__PURE__ */ new Set();
|
|
15934
|
+
const omittedCounts = /* @__PURE__ */ new Map();
|
|
15935
|
+
const addConcept = (c) => {
|
|
15936
|
+
if (!c || seen.has(c.id)) return;
|
|
15937
|
+
seen.add(c.id);
|
|
15938
|
+
concepts.push(c);
|
|
15939
|
+
};
|
|
15940
|
+
for (const a of artifacts) {
|
|
15941
|
+
const c = buildConcept(a);
|
|
15942
|
+
if (!c) {
|
|
15943
|
+
omittedCounts.set(a.type || "unknown", (omittedCounts.get(a.type || "unknown") ?? 0) + 1);
|
|
15944
|
+
continue;
|
|
15945
|
+
}
|
|
15946
|
+
addConcept(c);
|
|
15947
|
+
}
|
|
15948
|
+
for (const c of externalCapsuleConcepts(dir)) addConcept(c);
|
|
15949
|
+
if (opts.withReports) {
|
|
15950
|
+
const { concepts: reports, warnings: warnings2 } = reportConcepts(dir, opts.now ?? /* @__PURE__ */ new Date());
|
|
15951
|
+
for (const c of reports) addConcept(c);
|
|
15952
|
+
extraWarnings.push(...warnings2);
|
|
15953
|
+
}
|
|
15954
|
+
concepts.sort((a, b) => a.id.localeCompare(b.id));
|
|
15955
|
+
const byId = new Map(concepts.map((c) => [c.id, c]));
|
|
15956
|
+
const layerOf = (p) => p.split("/")[0];
|
|
15957
|
+
const byLayer = /* @__PURE__ */ new Map();
|
|
15958
|
+
for (const c of concepts) {
|
|
15959
|
+
const l = byLayer.get(layerOf(c.path)) ?? [];
|
|
15960
|
+
l.push(c);
|
|
15961
|
+
byLayer.set(layerOf(c.path), l);
|
|
15962
|
+
}
|
|
15963
|
+
fs7.rmSync(outputDir, { recursive: true, force: true });
|
|
15964
|
+
fs7.mkdirSync(outputDir, { recursive: true });
|
|
15965
|
+
const written = [];
|
|
15966
|
+
const warnings = [];
|
|
15967
|
+
const write = (bundlePath, content) => {
|
|
15968
|
+
atomicWrite5(path6.join(outputDir, bundlePath), content);
|
|
15969
|
+
written.push(bundlePath);
|
|
15970
|
+
warnings.push(...scanSensitive(bundlePath, content));
|
|
15971
|
+
};
|
|
15972
|
+
for (const c of concepts) write(c.path, renderConcept(c, byId));
|
|
15973
|
+
for (const layer of [...byLayer.keys()].sort()) {
|
|
15974
|
+
const title = layer.charAt(0).toUpperCase() + layer.slice(1);
|
|
15975
|
+
write(`${layer}/index.md`, renderIndex(`${title} Knowledge`, byLayer.get(layer), `${layer}/index.md`, false));
|
|
15976
|
+
}
|
|
15977
|
+
write("index.md", renderIndex("Knowledge bundle", concepts, "index.md", true));
|
|
15978
|
+
written.sort();
|
|
15979
|
+
return {
|
|
15980
|
+
outputDir,
|
|
15981
|
+
conceptCount: concepts.length,
|
|
15982
|
+
indexCount: byLayer.size + 1,
|
|
15983
|
+
omitted: [...omittedCounts.entries()].map(([type, count]) => ({ type, count })).sort((a, b) => a.type.localeCompare(b.type)),
|
|
15984
|
+
warnings: [...warnings, ...extraWarnings].sort(),
|
|
15985
|
+
files: written
|
|
15986
|
+
};
|
|
15987
|
+
}
|
|
15988
|
+
|
|
15989
|
+
// src/core/okf/validate.ts
|
|
15990
|
+
import fs8 from "fs";
|
|
15991
|
+
import path7 from "path";
|
|
15992
|
+
import matter19 from "gray-matter";
|
|
15993
|
+
function walk(root) {
|
|
15994
|
+
const out = [];
|
|
15995
|
+
const rec = (d) => {
|
|
15996
|
+
for (const entry of fs8.readdirSync(d)) {
|
|
15997
|
+
const full = path7.join(d, entry);
|
|
15998
|
+
const st = fs8.statSync(full);
|
|
15999
|
+
if (st.isDirectory()) rec(full);
|
|
16000
|
+
else if (entry.endsWith(".md")) out.push(full);
|
|
16001
|
+
}
|
|
16002
|
+
};
|
|
16003
|
+
if (fs8.existsSync(root)) rec(root);
|
|
16004
|
+
return out.sort();
|
|
16005
|
+
}
|
|
16006
|
+
function internalLinks(body) {
|
|
16007
|
+
const out = [];
|
|
16008
|
+
const re = /\]\(([^)]+)\)/g;
|
|
16009
|
+
let m;
|
|
16010
|
+
while (m = re.exec(body)) {
|
|
16011
|
+
const href = m[1].trim().split("#")[0].split(" ")[0];
|
|
16012
|
+
if (!href || /^(https?:|mailto:|\/)/.test(href)) continue;
|
|
16013
|
+
out.push(href);
|
|
16014
|
+
}
|
|
16015
|
+
return out;
|
|
16016
|
+
}
|
|
16017
|
+
function validateOkf(dir, opts = {}) {
|
|
16018
|
+
const loc = opts.location ?? OKF_DEFAULT_OUTPUT;
|
|
16019
|
+
const bundleDir = path7.isAbsolute(loc) ? loc : path7.join(dir, loc);
|
|
16020
|
+
const findings = [];
|
|
16021
|
+
if (!fs8.existsSync(bundleDir)) {
|
|
16022
|
+
findings.push({ level: "conformance", message: `OKF bundle directory not found: ${loc}. Run \`kaddo okf export\` first.` });
|
|
16023
|
+
return { dir: bundleDir, conformant: false, conceptCount: 0, findings, counts: { conformance: 1, warning: 0, info: 0 } };
|
|
16024
|
+
}
|
|
16025
|
+
const files = walk(bundleDir);
|
|
16026
|
+
const rel = (f) => path7.relative(bundleDir, f).split(path7.sep).join("/");
|
|
16027
|
+
const present = new Set(files.map(rel));
|
|
16028
|
+
const idToFile = /* @__PURE__ */ new Map();
|
|
16029
|
+
let conceptCount = 0;
|
|
16030
|
+
const rootIndex = path7.join(bundleDir, "index.md");
|
|
16031
|
+
if (!fs8.existsSync(rootIndex)) {
|
|
16032
|
+
findings.push({ level: "warning", message: "No root index.md \u2014 the bundle has no top-level navigation entry." });
|
|
16033
|
+
}
|
|
16034
|
+
for (const file of files) {
|
|
16035
|
+
const r = rel(file);
|
|
16036
|
+
const isIndex = path7.basename(file) === "index.md";
|
|
16037
|
+
let data = {};
|
|
16038
|
+
try {
|
|
16039
|
+
data = matter19(fs8.readFileSync(file, "utf-8")).data ?? {};
|
|
16040
|
+
} catch {
|
|
16041
|
+
findings.push({ level: "conformance", file: r, message: "Invalid YAML frontmatter." });
|
|
16042
|
+
continue;
|
|
16043
|
+
}
|
|
16044
|
+
const type = typeof data.type === "string" ? data.type.trim() : "";
|
|
16045
|
+
if (!type) {
|
|
16046
|
+
findings.push(isIndex ? { level: "warning", file: r, message: "Index has no type." } : { level: "conformance", file: r, message: "Concept has no non-empty `type`." });
|
|
16047
|
+
}
|
|
16048
|
+
if (!isIndex) conceptCount++;
|
|
16049
|
+
if (r === "index.md") {
|
|
16050
|
+
const v = typeof data.okf_version === "string" ? data.okf_version : data.okf_version != null ? String(data.okf_version) : "";
|
|
16051
|
+
if (!v) findings.push({ level: "warning", file: r, message: "Root index does not declare okf_version." });
|
|
16052
|
+
else if (v !== OKF_VERSION) findings.push({ level: "info", file: r, message: `Bundle declares okf_version "${v}" (validator targets ${OKF_VERSION}).` });
|
|
16053
|
+
}
|
|
16054
|
+
const kid = typeof data.kaddo_id === "string" ? data.kaddo_id : "";
|
|
16055
|
+
if (kid) {
|
|
16056
|
+
if (idToFile.has(kid)) findings.push({ level: "conformance", file: r, message: `Duplicate concept id "${kid}" (also in ${idToFile.get(kid)}).` });
|
|
16057
|
+
else idToFile.set(kid, r);
|
|
16058
|
+
}
|
|
16059
|
+
const body = (() => {
|
|
16060
|
+
try {
|
|
16061
|
+
return matter19(fs8.readFileSync(file, "utf-8")).content;
|
|
16062
|
+
} catch {
|
|
16063
|
+
return "";
|
|
16064
|
+
}
|
|
16065
|
+
})();
|
|
16066
|
+
for (const href of internalLinks(body)) {
|
|
16067
|
+
const resolved = path7.posix.normalize(path7.posix.join(path7.posix.dirname(r), href));
|
|
16068
|
+
if (!present.has(resolved)) findings.push({ level: "info", file: r, message: `Internal link not resolvable yet: ${href}` });
|
|
16069
|
+
}
|
|
16070
|
+
}
|
|
16071
|
+
const counts = {
|
|
16072
|
+
conformance: findings.filter((f) => f.level === "conformance").length,
|
|
16073
|
+
warning: findings.filter((f) => f.level === "warning").length,
|
|
16074
|
+
info: findings.filter((f) => f.level === "info").length
|
|
16075
|
+
};
|
|
16076
|
+
return { dir: bundleDir, conformant: counts.conformance === 0, conceptCount, findings, counts };
|
|
16077
|
+
}
|
|
15646
16078
|
export {
|
|
15647
16079
|
CANDIDATE_DISCOVERY_GUIDANCE,
|
|
15648
16080
|
CURRENT_CONSENT_VERSION,
|
|
@@ -15664,6 +16096,10 @@ export {
|
|
|
15664
16096
|
IntegrationServiceError,
|
|
15665
16097
|
LIFECYCLE_STATES2 as LIFECYCLE_STATES,
|
|
15666
16098
|
LIFECYCLE_TRANSITIONS,
|
|
16099
|
+
OKF_DEFAULT_OUTPUT,
|
|
16100
|
+
OKF_RESERVED_FILES,
|
|
16101
|
+
OKF_TYPE_TABLE,
|
|
16102
|
+
OKF_VERSION,
|
|
15667
16103
|
POC_ARTIFACT_PATH,
|
|
15668
16104
|
POC_REPORT_PREFIX,
|
|
15669
16105
|
PRODUCTION_RUNBOOKS_DIR,
|
|
@@ -15691,6 +16127,7 @@ export {
|
|
|
15691
16127
|
analyzeScopeCoverage,
|
|
15692
16128
|
applyTopologyProposal,
|
|
15693
16129
|
associatedWorkItems,
|
|
16130
|
+
buildConcept,
|
|
15694
16131
|
buildDriftReport,
|
|
15695
16132
|
buildImpactReport,
|
|
15696
16133
|
buildImplementationHandoff,
|
|
@@ -15707,6 +16144,7 @@ export {
|
|
|
15707
16144
|
computeContentHash,
|
|
15708
16145
|
computeInitiativeProgress,
|
|
15709
16146
|
computeRefinementStatus,
|
|
16147
|
+
conceptBundlePath,
|
|
15710
16148
|
consentNotice,
|
|
15711
16149
|
createInitiative,
|
|
15712
16150
|
createIntegration,
|
|
@@ -15731,6 +16169,7 @@ export {
|
|
|
15731
16169
|
evaluateCompletion,
|
|
15732
16170
|
evaluateInitiativeCompletion,
|
|
15733
16171
|
exists,
|
|
16172
|
+
exportOkf,
|
|
15734
16173
|
filterSecretPaths,
|
|
15735
16174
|
findDuplicateByHash,
|
|
15736
16175
|
findExistingById,
|
|
@@ -15791,6 +16230,7 @@ export {
|
|
|
15791
16230
|
nextPlanId,
|
|
15792
16231
|
nextTargetId,
|
|
15793
16232
|
observationStatus,
|
|
16233
|
+
okfConceptType,
|
|
15794
16234
|
parseContent,
|
|
15795
16235
|
parseInitiative,
|
|
15796
16236
|
parseScope,
|
|
@@ -15834,6 +16274,7 @@ export {
|
|
|
15834
16274
|
updateTarget,
|
|
15835
16275
|
updateWorkItem,
|
|
15836
16276
|
validateConfigAgainstSchema,
|
|
16277
|
+
validateOkf,
|
|
15837
16278
|
validatePlan,
|
|
15838
16279
|
validateProductionRunbook,
|
|
15839
16280
|
validateResource,
|