@kaddo/cli 3.124.5 → 3.126.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 +674 -92
- package/dist/index.js +3147 -2523
- 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,576 @@ 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
|
+
import matter19 from "gray-matter";
|
|
15653
|
+
var OKF_TYPE_TABLE = {
|
|
15654
|
+
"business-knowledge": "Business Knowledge",
|
|
15655
|
+
"product-knowledge": "Product Knowledge",
|
|
15656
|
+
"technical-knowledge": "Technical Knowledge",
|
|
15657
|
+
capability: "Capability",
|
|
15658
|
+
decision: "Architecture Decision",
|
|
15659
|
+
adr: "Architecture Decision",
|
|
15660
|
+
"project-resource": "Project Resource",
|
|
15661
|
+
"deprecation-plan": "Deprecation Plan",
|
|
15662
|
+
initiative: "Initiative",
|
|
15663
|
+
capsule: "Knowledge Reference",
|
|
15664
|
+
"knowledge-capsule": "Knowledge Reference",
|
|
15665
|
+
"current-state": "Technical Knowledge",
|
|
15666
|
+
roadmap: "Delivery Knowledge"
|
|
15667
|
+
};
|
|
15668
|
+
var WORK_ITEM_TYPES3 = /* @__PURE__ */ new Set(["feature", "bugfix", "hotfix", "spike", "chore"]);
|
|
15669
|
+
var REPORT_TYPES = /* @__PURE__ */ new Set(["impact-report", "drift-report", "savings-report", "poc-report"]);
|
|
15670
|
+
var AGENT_INSTRUCTION_TYPES = /* @__PURE__ */ new Set(["agent", "workflow", "prompt", "skill"]);
|
|
15671
|
+
function isAgentInstruction(a) {
|
|
15672
|
+
const t = (a.type || "").toLowerCase();
|
|
15673
|
+
if (AGENT_INSTRUCTION_TYPES.has(t)) return true;
|
|
15674
|
+
const p = a.relPath.toLowerCase();
|
|
15675
|
+
return p.includes("/agents/") || p.includes("/skills/") || p.includes("/workflows/");
|
|
15676
|
+
}
|
|
15677
|
+
function okfConceptType(a) {
|
|
15678
|
+
if (a.isWorkItem) return "Work Item";
|
|
15679
|
+
const t = (a.type || "").toLowerCase();
|
|
15680
|
+
if (OKF_TYPE_TABLE[t]) return OKF_TYPE_TABLE[t];
|
|
15681
|
+
if (REPORT_TYPES.has(t)) return "Report";
|
|
15682
|
+
if (WORK_ITEM_TYPES3.has(t)) return "Work Item";
|
|
15683
|
+
if (a.layer === "business") return "Business Knowledge";
|
|
15684
|
+
if (a.layer === "product") return "Product Knowledge";
|
|
15685
|
+
if (a.layer === "tech" || a.layer === "module") return "Technical Knowledge";
|
|
15686
|
+
if (a.layer === "delivery") return "Delivery Knowledge";
|
|
15687
|
+
return t ? t.replace(/(^|[-_ ])(\w)/g, (_, s, c) => (s ? " " : "") + c.toUpperCase()) : "Knowledge";
|
|
15688
|
+
}
|
|
15689
|
+
function str3(v) {
|
|
15690
|
+
return typeof v === "string" && v.trim() ? v.trim() : null;
|
|
15691
|
+
}
|
|
15692
|
+
function strArray3(v) {
|
|
15693
|
+
return Array.isArray(v) ? v.map((x) => String(x).trim()).filter(Boolean) : [];
|
|
15694
|
+
}
|
|
15695
|
+
function conceptBundlePath(a, id) {
|
|
15696
|
+
const file = `${id}.md`;
|
|
15697
|
+
if (a.isWorkItem) return `delivery/work-items/${file}`;
|
|
15698
|
+
const t = (a.type || "").toLowerCase();
|
|
15699
|
+
if (isAgentInstruction(a)) return `agents/${file}`;
|
|
15700
|
+
if (t === "deprecation-plan") return `delivery/deprecations/${file}`;
|
|
15701
|
+
if (t === "production-runbook") return `delivery/runbooks/${file}`;
|
|
15702
|
+
if (t === "project-resource") return `resources/${file}`;
|
|
15703
|
+
if (t === "knowledge-capsule" || t === "capsule") return `external/${file}`;
|
|
15704
|
+
switch (a.layer) {
|
|
15705
|
+
case "business":
|
|
15706
|
+
return `business/${file}`;
|
|
15707
|
+
case "product":
|
|
15708
|
+
return `product/${file}`;
|
|
15709
|
+
case "tech":
|
|
15710
|
+
return `tech/${file}`;
|
|
15711
|
+
case "module":
|
|
15712
|
+
return `tech/modules/${file}`;
|
|
15713
|
+
case "delivery":
|
|
15714
|
+
return `delivery/${file}`;
|
|
15715
|
+
default:
|
|
15716
|
+
return `misc/${file}`;
|
|
15717
|
+
}
|
|
15718
|
+
}
|
|
15719
|
+
function workItemRelations(fm) {
|
|
15720
|
+
const out = [];
|
|
15721
|
+
const resources = fm.resources;
|
|
15722
|
+
if (Array.isArray(resources)) {
|
|
15723
|
+
for (const r of resources) {
|
|
15724
|
+
if (r && typeof r === "object") {
|
|
15725
|
+
const id = str3(r.id);
|
|
15726
|
+
if (id) out.push({ id, role: str3(r.role) ?? "uses" });
|
|
15727
|
+
}
|
|
15728
|
+
}
|
|
15729
|
+
}
|
|
15730
|
+
const dep = fm.deprecation_targets;
|
|
15731
|
+
if (Array.isArray(dep)) {
|
|
15732
|
+
for (const d of dep) {
|
|
15733
|
+
const s = typeof d === "string" ? d : d && typeof d === "object" ? str3(d.plan) : null;
|
|
15734
|
+
if (s) out.push({ id: s.includes("/") ? s.split("/")[0] : s, role: "deprecates-via" });
|
|
15735
|
+
}
|
|
15736
|
+
}
|
|
15737
|
+
const parent = str3(fm.parent);
|
|
15738
|
+
if (parent) out.push({ id: parent, role: "child-of" });
|
|
15739
|
+
for (const dId of strArray3(fm.decisions)) out.push({ id: dId, role: "decided-by" });
|
|
15740
|
+
return out;
|
|
15741
|
+
}
|
|
15742
|
+
function slugify4(s) {
|
|
15743
|
+
return s.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
|
|
15744
|
+
}
|
|
15745
|
+
function conceptId(a) {
|
|
15746
|
+
if (a.id) return a.id;
|
|
15747
|
+
if (a.title) return slugify4(a.title);
|
|
15748
|
+
const base = a.relPath.split("/").pop() ?? "";
|
|
15749
|
+
return slugify4(base.replace(/\.md$/, "")) || slugify4(a.relPath);
|
|
15750
|
+
}
|
|
15751
|
+
function readBody2(a) {
|
|
15752
|
+
try {
|
|
15753
|
+
const body = matter19(readFile(a.filePath)).content.trim();
|
|
15754
|
+
return body || null;
|
|
15755
|
+
} catch {
|
|
15756
|
+
return null;
|
|
15757
|
+
}
|
|
15758
|
+
}
|
|
15759
|
+
function buildConcept(a) {
|
|
15760
|
+
const id = conceptId(a);
|
|
15761
|
+
if (!id) return null;
|
|
15762
|
+
const rawFm = a.rawFrontmatter ?? {};
|
|
15763
|
+
return {
|
|
15764
|
+
id,
|
|
15765
|
+
type: okfConceptType(a),
|
|
15766
|
+
title: a.title || id,
|
|
15767
|
+
description: str3(a.summary),
|
|
15768
|
+
tags: a.domains.map((d) => String(d).toLowerCase()),
|
|
15769
|
+
path: conceptBundlePath(a, id),
|
|
15770
|
+
sourcePath: a.relPath,
|
|
15771
|
+
related: a.isWorkItem ? workItemRelations(rawFm) : [],
|
|
15772
|
+
// Preserve the canonical Markdown body so the concept is consumable, not just discoverable (WI-066 P1).
|
|
15773
|
+
body: readBody2(a)
|
|
15774
|
+
};
|
|
15775
|
+
}
|
|
15776
|
+
|
|
15777
|
+
// src/core/okf/types.ts
|
|
15778
|
+
var OKF_VERSION = "0.2";
|
|
15779
|
+
var OKF_RESERVED_FILES = ["index.md", "log.md"];
|
|
15780
|
+
var OKF_EXPORT_PROCESS = "process:kaddo-okf-export";
|
|
15781
|
+
var OkfExportError = class extends Error {
|
|
15782
|
+
constructor(code, message) {
|
|
15783
|
+
super(message);
|
|
15784
|
+
this.code = code;
|
|
15785
|
+
this.name = "OkfExportError";
|
|
15786
|
+
}
|
|
15787
|
+
code;
|
|
15788
|
+
};
|
|
15789
|
+
|
|
15790
|
+
// src/core/okf/extras.ts
|
|
15791
|
+
function reportConcepts(dir, now = /* @__PURE__ */ new Date()) {
|
|
15792
|
+
const concepts = [];
|
|
15793
|
+
const warnings = [];
|
|
15794
|
+
const at = now.toISOString();
|
|
15795
|
+
const add = (id, title, description, build) => {
|
|
15796
|
+
try {
|
|
15797
|
+
const body = build();
|
|
15798
|
+
concepts.push({
|
|
15799
|
+
id,
|
|
15800
|
+
type: "Report",
|
|
15801
|
+
title,
|
|
15802
|
+
description,
|
|
15803
|
+
tags: ["report"],
|
|
15804
|
+
path: `reports/${id}.md`,
|
|
15805
|
+
sourcePath: null,
|
|
15806
|
+
generatedBy: OKF_EXPORT_PROCESS,
|
|
15807
|
+
generatedAt: at,
|
|
15808
|
+
related: [],
|
|
15809
|
+
body
|
|
15810
|
+
});
|
|
15811
|
+
} catch (e) {
|
|
15812
|
+
warnings.push(`Report "${id}" skipped: ${e instanceof Error ? e.message : String(e)}`);
|
|
15813
|
+
}
|
|
15814
|
+
};
|
|
15815
|
+
add(
|
|
15816
|
+
"report-impact",
|
|
15817
|
+
"Impact Report",
|
|
15818
|
+
"Knowledge-code impact, derived from evidence.",
|
|
15819
|
+
() => renderImpactMarkdown(buildImpactReport(dir, {}, now), { details: true })
|
|
15820
|
+
);
|
|
15821
|
+
add(
|
|
15822
|
+
"report-drift",
|
|
15823
|
+
"Drift Report",
|
|
15824
|
+
"Drift trend across code, knowledge, Work Items and architecture.",
|
|
15825
|
+
() => renderDriftMarkdown(buildDriftReport(dir, now))
|
|
15826
|
+
);
|
|
15827
|
+
add(
|
|
15828
|
+
"report-savings",
|
|
15829
|
+
"Savings Report",
|
|
15830
|
+
"Evidence-based savings estimates (not exact ROI).",
|
|
15831
|
+
() => renderSavingsMarkdown(buildSavingsReport(dir, {}, now))
|
|
15832
|
+
);
|
|
15833
|
+
return { concepts, warnings };
|
|
15834
|
+
}
|
|
15835
|
+
function externalCapsuleConcepts(dir) {
|
|
15836
|
+
return loadExternalRegistry(dir).map((e) => {
|
|
15837
|
+
const lines = [
|
|
15838
|
+
`# ${e.id}`,
|
|
15839
|
+
"",
|
|
15840
|
+
"External Knowledge Reference. Access is limited to its source system; its private sources are not",
|
|
15841
|
+
"included in this bundle and no operational access to the origin system is implied.",
|
|
15842
|
+
"",
|
|
15843
|
+
`- Source: \`${e.path}\``,
|
|
15844
|
+
...e.owner ? [`- Owner: ${e.owner}`] : [],
|
|
15845
|
+
...e.lastImportedAt ? [`- Last imported: ${e.lastImportedAt}`] : []
|
|
15846
|
+
];
|
|
15847
|
+
return {
|
|
15848
|
+
id: e.id,
|
|
15849
|
+
type: "Knowledge Reference",
|
|
15850
|
+
title: e.id,
|
|
15851
|
+
description: "External knowledge reference (capsule).",
|
|
15852
|
+
tags: ["reference", "external"],
|
|
15853
|
+
path: `external/${e.id}.md`,
|
|
15854
|
+
sourcePath: e.path,
|
|
15855
|
+
related: [],
|
|
15856
|
+
body: lines.join("\n")
|
|
15857
|
+
};
|
|
15858
|
+
});
|
|
15859
|
+
}
|
|
15860
|
+
|
|
15861
|
+
// src/core/okf/export.ts
|
|
15862
|
+
var OKF_DEFAULT_OUTPUT = ".kaddo/okf";
|
|
15863
|
+
function frontmatter(data) {
|
|
15864
|
+
const lines = ["---"];
|
|
15865
|
+
for (const [k, v] of Object.entries(data)) {
|
|
15866
|
+
if (v == null) continue;
|
|
15867
|
+
if (Array.isArray(v)) {
|
|
15868
|
+
if (v.length === 0) continue;
|
|
15869
|
+
lines.push(`${k}:`);
|
|
15870
|
+
for (const item of v) {
|
|
15871
|
+
if (item && typeof item === "object") {
|
|
15872
|
+
const entries = Object.entries(item).filter(([, x]) => x != null);
|
|
15873
|
+
if (entries.length === 0) continue;
|
|
15874
|
+
lines.push(` - ${entries.map(([ik, iv]) => `${ik}: ${JSON.stringify(iv)}`).join("\n ")}`);
|
|
15875
|
+
} else {
|
|
15876
|
+
lines.push(` - ${JSON.stringify(item)}`);
|
|
15877
|
+
}
|
|
15878
|
+
}
|
|
15879
|
+
} else if (v && typeof v === "object") {
|
|
15880
|
+
lines.push(`${k}:`);
|
|
15881
|
+
for (const [ik, iv] of Object.entries(v)) {
|
|
15882
|
+
if (iv != null) lines.push(` ${ik}: ${JSON.stringify(iv)}`);
|
|
15883
|
+
}
|
|
15884
|
+
} else {
|
|
15885
|
+
lines.push(`${k}: ${JSON.stringify(v)}`);
|
|
15886
|
+
}
|
|
15887
|
+
}
|
|
15888
|
+
lines.push("---");
|
|
15889
|
+
return lines.join("\n");
|
|
15890
|
+
}
|
|
15891
|
+
function relLink(fromPath, toPath) {
|
|
15892
|
+
const rel = path6.posix.relative(path6.posix.dirname(fromPath), toPath);
|
|
15893
|
+
return rel.startsWith(".") ? rel : `./${rel}`;
|
|
15894
|
+
}
|
|
15895
|
+
function rewriteBodyLinks(body, sourcePath, srcToBundle, selfBundlePath) {
|
|
15896
|
+
const srcDir = path6.posix.dirname(sourcePath);
|
|
15897
|
+
return body.replace(/\]\(([^)]+)\)/g, (whole, href) => {
|
|
15898
|
+
const raw = href.trim();
|
|
15899
|
+
const bare = raw.split("#")[0].split(" ")[0];
|
|
15900
|
+
if (!bare || /^(https?:|mailto:|#)/.test(bare)) return whole;
|
|
15901
|
+
const candidate = bare.startsWith("/") ? bare.replace(/^\/+/, "") : path6.posix.normalize(path6.posix.join(srcDir, bare));
|
|
15902
|
+
const target = srcToBundle.get(candidate);
|
|
15903
|
+
if (!target) return whole;
|
|
15904
|
+
const anchor = raw.includes("#") ? "#" + raw.split("#").slice(1).join("#") : "";
|
|
15905
|
+
return `](${relLink(selfBundlePath, target)}${anchor})`;
|
|
15906
|
+
});
|
|
15907
|
+
}
|
|
15908
|
+
function renderConcept(c, byId, srcToBundle) {
|
|
15909
|
+
const data = {
|
|
15910
|
+
type: c.type,
|
|
15911
|
+
title: c.title,
|
|
15912
|
+
description: c.description,
|
|
15913
|
+
tags: c.tags,
|
|
15914
|
+
kaddo_id: c.id
|
|
15915
|
+
};
|
|
15916
|
+
if (c.sourcePath) data.sources = [{ resource: c.sourcePath }];
|
|
15917
|
+
if (c.generatedBy || c.generatedAt) {
|
|
15918
|
+
data.generated = { ...c.generatedBy ? { by: c.generatedBy } : {}, ...c.generatedAt ? { at: c.generatedAt } : {} };
|
|
15919
|
+
}
|
|
15920
|
+
const parts = [frontmatter(data)];
|
|
15921
|
+
if (c.body) {
|
|
15922
|
+
const body = c.sourcePath ? rewriteBodyLinks(c.body, c.sourcePath, srcToBundle, c.path) : c.body;
|
|
15923
|
+
parts.push("", body.trim());
|
|
15924
|
+
} else {
|
|
15925
|
+
parts.push("", `# ${c.title}`);
|
|
15926
|
+
if (c.description) parts.push("", c.description);
|
|
15927
|
+
}
|
|
15928
|
+
const resolved = c.related.filter((r) => byId.has(r.id));
|
|
15929
|
+
if (resolved.length > 0) {
|
|
15930
|
+
parts.push("", "## Related");
|
|
15931
|
+
for (const r of resolved) {
|
|
15932
|
+
const target = byId.get(r.id);
|
|
15933
|
+
parts.push(`- [${target.title}](${relLink(c.path, target.path)}) \u2014 ${r.role}`);
|
|
15934
|
+
}
|
|
15935
|
+
}
|
|
15936
|
+
return parts.join("\n") + "\n";
|
|
15937
|
+
}
|
|
15938
|
+
function renderIndex(title, concepts, childDirs, fromPath, root) {
|
|
15939
|
+
const parts = [];
|
|
15940
|
+
if (root) parts.push(frontmatter({ okf_version: OKF_VERSION }), "");
|
|
15941
|
+
parts.push(`# ${title}`, "");
|
|
15942
|
+
if (root) parts.push(
|
|
15943
|
+
"Open Knowledge Format bundle \u2014 a portable projection of Kaddo knowledge.",
|
|
15944
|
+
"Kaddo remains the source of truth.",
|
|
15945
|
+
""
|
|
15946
|
+
);
|
|
15947
|
+
if (childDirs.length > 0) {
|
|
15948
|
+
parts.push("## Sections");
|
|
15949
|
+
for (const d of [...childDirs].sort()) parts.push(`- [${d}/](${relLink(fromPath, `${d}/index.md`)})`);
|
|
15950
|
+
parts.push("");
|
|
15951
|
+
}
|
|
15952
|
+
const byType = /* @__PURE__ */ new Map();
|
|
15953
|
+
for (const c of concepts) {
|
|
15954
|
+
const l = byType.get(c.type) ?? [];
|
|
15955
|
+
l.push(c);
|
|
15956
|
+
byType.set(c.type, l);
|
|
15957
|
+
}
|
|
15958
|
+
for (const type of [...byType.keys()].sort()) {
|
|
15959
|
+
parts.push(`## ${type}`);
|
|
15960
|
+
for (const c of byType.get(type).sort((a, b) => a.id.localeCompare(b.id))) {
|
|
15961
|
+
const d = c.description ? ` \u2014 ${c.description}` : "";
|
|
15962
|
+
parts.push(`- [${c.title}](${relLink(fromPath, c.path)})${d}`);
|
|
15963
|
+
}
|
|
15964
|
+
parts.push("");
|
|
15965
|
+
}
|
|
15966
|
+
return parts.join("\n");
|
|
15967
|
+
}
|
|
15968
|
+
var SENSITIVE_PATTERNS = [
|
|
15969
|
+
{ re: /-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/, label: "private key block" },
|
|
15970
|
+
{ re: /\bAKIA[0-9A-Z]{16}\b/, label: "AWS access key id" },
|
|
15971
|
+
{ re: /\bgh[pousr]_[A-Za-z0-9]{20,}\b/, label: "GitHub token" },
|
|
15972
|
+
{ re: /\b(?:password|secret|api[_-]?key|access[_-]?token)\b\s*[:=]\s*["']?[A-Za-z0-9+/_\-]{12,}/i, label: "inline credential" }
|
|
15973
|
+
];
|
|
15974
|
+
function sensitiveLabels(content) {
|
|
15975
|
+
return [...new Set(SENSITIVE_PATTERNS.filter((p) => p.re.test(content)).map((p) => p.label))];
|
|
15976
|
+
}
|
|
15977
|
+
function assertSafeDestination(dir, outputDir) {
|
|
15978
|
+
const root = path6.resolve(dir);
|
|
15979
|
+
const out = path6.resolve(outputDir);
|
|
15980
|
+
const within = (child, parent) => {
|
|
15981
|
+
const rel = path6.relative(parent, child);
|
|
15982
|
+
return rel === "" || !rel.startsWith("..") && !path6.isAbsolute(rel);
|
|
15983
|
+
};
|
|
15984
|
+
if (out === root) throw new OkfExportError("UNSAFE_DESTINATION", "Refusing to export onto the project root.");
|
|
15985
|
+
if (within(root, out)) throw new OkfExportError("UNSAFE_DESTINATION", "Refusing to export onto a parent of the project.");
|
|
15986
|
+
for (const protectedDir of ["knowledge", "packages", "apps", "src", "node_modules", ".git"]) {
|
|
15987
|
+
const p = path6.join(root, protectedDir);
|
|
15988
|
+
if (out === p || within(out, p)) throw new OkfExportError("UNSAFE_DESTINATION", `Refusing to export into a protected directory: ${protectedDir}/`);
|
|
15989
|
+
}
|
|
15990
|
+
if (fs7.existsSync(out)) {
|
|
15991
|
+
try {
|
|
15992
|
+
const entries = fs7.readdirSync(out);
|
|
15993
|
+
const looksOkf = entries.includes("index.md") && /okf_version/.test(fs7.readFileSync(path6.join(out, "index.md"), "utf-8"));
|
|
15994
|
+
if (entries.length > 0 && !looksOkf) {
|
|
15995
|
+
throw new OkfExportError("UNSAFE_DESTINATION", `Destination is not empty and is not an OKF bundle: ${outputDir}. Use an empty or dedicated directory.`);
|
|
15996
|
+
}
|
|
15997
|
+
} catch (e) {
|
|
15998
|
+
if (e instanceof OkfExportError) throw e;
|
|
15999
|
+
}
|
|
16000
|
+
}
|
|
16001
|
+
}
|
|
16002
|
+
function detectCollisions(concepts) {
|
|
16003
|
+
const byId = /* @__PURE__ */ new Map();
|
|
16004
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
16005
|
+
const errors = [];
|
|
16006
|
+
for (const c of concepts) {
|
|
16007
|
+
const prev = byId.get(c.id);
|
|
16008
|
+
if (prev && prev !== (c.sourcePath ?? "")) errors.push(`Concept id "${c.id}" is produced by two different sources: ${prev} and ${c.sourcePath}.`);
|
|
16009
|
+
else byId.set(c.id, c.sourcePath ?? "");
|
|
16010
|
+
const prevP = byPath.get(c.path);
|
|
16011
|
+
if (prevP && prevP !== c.id) errors.push(`Destination path "${c.path}" is claimed by two concepts: ${prevP} and ${c.id}.`);
|
|
16012
|
+
else byPath.set(c.path, c.id);
|
|
16013
|
+
}
|
|
16014
|
+
return errors;
|
|
16015
|
+
}
|
|
16016
|
+
function exportOkf(dir, opts = {}) {
|
|
16017
|
+
const outRel = opts.output ?? OKF_DEFAULT_OUTPUT;
|
|
16018
|
+
const outputDir = path6.isAbsolute(outRel) ? outRel : path6.join(dir, outRel);
|
|
16019
|
+
assertSafeDestination(dir, outputDir);
|
|
16020
|
+
const extraWarnings = [];
|
|
16021
|
+
const artifacts = discoverKnowledge(dir);
|
|
16022
|
+
const raw = [];
|
|
16023
|
+
const omittedCounts = /* @__PURE__ */ new Map();
|
|
16024
|
+
const omittedConcepts = [];
|
|
16025
|
+
const bump = (type) => omittedCounts.set(type, (omittedCounts.get(type) ?? 0) + 1);
|
|
16026
|
+
const sameSource = /* @__PURE__ */ new Set();
|
|
16027
|
+
for (const a of artifacts) {
|
|
16028
|
+
if (isAgentInstruction(a) && !opts.withAgents) {
|
|
16029
|
+
bump(a.type || "agent");
|
|
16030
|
+
continue;
|
|
16031
|
+
}
|
|
16032
|
+
const c = buildConcept(a);
|
|
16033
|
+
if (!c) {
|
|
16034
|
+
bump(a.type || "unknown");
|
|
16035
|
+
continue;
|
|
16036
|
+
}
|
|
16037
|
+
const key = `${c.id}\0${c.sourcePath ?? ""}`;
|
|
16038
|
+
if (sameSource.has(key)) continue;
|
|
16039
|
+
sameSource.add(key);
|
|
16040
|
+
raw.push(c);
|
|
16041
|
+
}
|
|
16042
|
+
for (const c of externalCapsuleConcepts(dir)) raw.push(c);
|
|
16043
|
+
if (opts.withReports) {
|
|
16044
|
+
const { concepts: reports, warnings } = reportConcepts(dir, opts.now ?? /* @__PURE__ */ new Date());
|
|
16045
|
+
raw.push(...reports);
|
|
16046
|
+
extraWarnings.push(...warnings);
|
|
16047
|
+
}
|
|
16048
|
+
const collisions = detectCollisions(raw);
|
|
16049
|
+
if (collisions.length > 0) {
|
|
16050
|
+
throw new OkfExportError("IDENTITY_COLLISION", `Cannot export: ${collisions.length} unresolved identity collision(s):
|
|
16051
|
+
- ${collisions.join("\n- ")}`);
|
|
16052
|
+
}
|
|
16053
|
+
const concepts = [];
|
|
16054
|
+
for (const c of raw) {
|
|
16055
|
+
const hay = `${c.title}
|
|
16056
|
+
${c.description ?? ""}
|
|
16057
|
+
${c.body ?? ""}`;
|
|
16058
|
+
const labels = sensitiveLabels(hay);
|
|
16059
|
+
if (labels.length > 0) {
|
|
16060
|
+
omittedConcepts.push({ id: c.id, reason: `potential ${labels.join(", ")}` });
|
|
16061
|
+
continue;
|
|
16062
|
+
}
|
|
16063
|
+
concepts.push(c);
|
|
16064
|
+
}
|
|
16065
|
+
concepts.sort((a, b) => a.id.localeCompare(b.id));
|
|
16066
|
+
const byId = new Map(concepts.map((c) => [c.id, c]));
|
|
16067
|
+
const srcToBundle = /* @__PURE__ */ new Map();
|
|
16068
|
+
for (const c of concepts) if (c.sourcePath) srcToBundle.set(c.sourcePath, c.path);
|
|
16069
|
+
const files = /* @__PURE__ */ new Map();
|
|
16070
|
+
for (const c of concepts) files.set(c.path, renderConcept(c, byId, srcToBundle));
|
|
16071
|
+
const dirs = /* @__PURE__ */ new Map();
|
|
16072
|
+
const childDirs = /* @__PURE__ */ new Map();
|
|
16073
|
+
for (const c of concepts) {
|
|
16074
|
+
const d = path6.posix.dirname(c.path);
|
|
16075
|
+
(dirs.get(d) ?? dirs.set(d, []).get(d)).push(c);
|
|
16076
|
+
const segs = d === "." ? [] : d.split("/");
|
|
16077
|
+
for (let i = 0; i < segs.length; i++) {
|
|
16078
|
+
const parent = segs.slice(0, i).join("/") || ".";
|
|
16079
|
+
const child = segs.slice(0, i + 1).join("/");
|
|
16080
|
+
(childDirs.get(parent) ?? childDirs.set(parent, /* @__PURE__ */ new Set()).get(parent)).add(child);
|
|
16081
|
+
}
|
|
16082
|
+
}
|
|
16083
|
+
let indexCount = 0;
|
|
16084
|
+
for (const [d, cs] of dirs) {
|
|
16085
|
+
if (d === ".") continue;
|
|
16086
|
+
const title = d.split("/").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(" / ");
|
|
16087
|
+
const kids = [...childDirs.get(d) ?? []].map((c) => c.split("/").pop());
|
|
16088
|
+
files.set(`${d}/index.md`, renderIndex(title, cs, kids, `${d}/index.md`, false));
|
|
16089
|
+
indexCount++;
|
|
16090
|
+
}
|
|
16091
|
+
const rootConcepts = dirs.get(".") ?? [];
|
|
16092
|
+
const rootKids = [...childDirs.get(".") ?? []];
|
|
16093
|
+
files.set("index.md", renderIndex("Knowledge bundle", rootConcepts, rootKids, "index.md", true));
|
|
16094
|
+
indexCount++;
|
|
16095
|
+
const staging = `${outputDir}.staging-${process.pid}-${Date.now()}`;
|
|
16096
|
+
try {
|
|
16097
|
+
fs7.rmSync(staging, { recursive: true, force: true });
|
|
16098
|
+
for (const [rel, content] of files) {
|
|
16099
|
+
const full = path6.join(staging, rel);
|
|
16100
|
+
fs7.mkdirSync(path6.dirname(full), { recursive: true });
|
|
16101
|
+
fs7.writeFileSync(full, content, "utf-8");
|
|
16102
|
+
}
|
|
16103
|
+
const backup = `${outputDir}.old-${process.pid}-${Date.now()}`;
|
|
16104
|
+
if (fs7.existsSync(outputDir)) fs7.renameSync(outputDir, backup);
|
|
16105
|
+
try {
|
|
16106
|
+
fs7.renameSync(staging, outputDir);
|
|
16107
|
+
} catch (e) {
|
|
16108
|
+
if (fs7.existsSync(backup)) fs7.renameSync(backup, outputDir);
|
|
16109
|
+
throw e;
|
|
16110
|
+
}
|
|
16111
|
+
fs7.rmSync(backup, { recursive: true, force: true });
|
|
16112
|
+
} finally {
|
|
16113
|
+
fs7.rmSync(staging, { recursive: true, force: true });
|
|
16114
|
+
}
|
|
16115
|
+
const written = [...files.keys()].sort();
|
|
16116
|
+
return {
|
|
16117
|
+
outputDir,
|
|
16118
|
+
conceptCount: concepts.length,
|
|
16119
|
+
indexCount,
|
|
16120
|
+
omitted: [...omittedCounts.entries()].map(([type, count]) => ({ type, count })).sort((a, b) => a.type.localeCompare(b.type)),
|
|
16121
|
+
omittedConcepts: omittedConcepts.sort((a, b) => a.id.localeCompare(b.id)),
|
|
16122
|
+
warnings: extraWarnings.sort(),
|
|
16123
|
+
files: written
|
|
16124
|
+
};
|
|
16125
|
+
}
|
|
16126
|
+
|
|
16127
|
+
// src/core/okf/validate.ts
|
|
16128
|
+
import fs8 from "fs";
|
|
16129
|
+
import path7 from "path";
|
|
16130
|
+
import matter20 from "gray-matter";
|
|
16131
|
+
function walk(root) {
|
|
16132
|
+
const out = [];
|
|
16133
|
+
const rec = (d) => {
|
|
16134
|
+
for (const entry of fs8.readdirSync(d)) {
|
|
16135
|
+
const full = path7.join(d, entry);
|
|
16136
|
+
const st = fs8.statSync(full);
|
|
16137
|
+
if (st.isDirectory()) rec(full);
|
|
16138
|
+
else if (entry.endsWith(".md")) out.push(full);
|
|
16139
|
+
}
|
|
16140
|
+
};
|
|
16141
|
+
if (fs8.existsSync(root)) rec(root);
|
|
16142
|
+
return out.sort();
|
|
16143
|
+
}
|
|
16144
|
+
function internalLinks(body) {
|
|
16145
|
+
const out = [];
|
|
16146
|
+
const re = /\]\(([^)]+)\)/g;
|
|
16147
|
+
let m;
|
|
16148
|
+
while (m = re.exec(body)) {
|
|
16149
|
+
const href = m[1].trim().split("#")[0].split(" ")[0];
|
|
16150
|
+
if (!href || /^(https?:|mailto:|\/)/.test(href)) continue;
|
|
16151
|
+
out.push(href);
|
|
16152
|
+
}
|
|
16153
|
+
return out;
|
|
16154
|
+
}
|
|
16155
|
+
function validateOkf(dir, opts = {}) {
|
|
16156
|
+
const loc = opts.location ?? OKF_DEFAULT_OUTPUT;
|
|
16157
|
+
const bundleDir = path7.isAbsolute(loc) ? loc : path7.join(dir, loc);
|
|
16158
|
+
const findings = [];
|
|
16159
|
+
if (!fs8.existsSync(bundleDir)) {
|
|
16160
|
+
findings.push({ level: "conformance", message: `OKF bundle directory not found: ${loc}. Run \`kaddo okf export\` first.` });
|
|
16161
|
+
return { dir: bundleDir, conformant: false, conceptCount: 0, findings, counts: { conformance: 1, warning: 0, info: 0 } };
|
|
16162
|
+
}
|
|
16163
|
+
const files = walk(bundleDir);
|
|
16164
|
+
const rel = (f) => path7.relative(bundleDir, f).split(path7.sep).join("/");
|
|
16165
|
+
const present = new Set(files.map(rel));
|
|
16166
|
+
const idToFile = /* @__PURE__ */ new Map();
|
|
16167
|
+
let conceptCount = 0;
|
|
16168
|
+
const rootIndex = path7.join(bundleDir, "index.md");
|
|
16169
|
+
if (!fs8.existsSync(rootIndex)) {
|
|
16170
|
+
findings.push({ level: "warning", message: "No root index.md \u2014 the bundle has no top-level navigation entry." });
|
|
16171
|
+
}
|
|
16172
|
+
for (const file of files) {
|
|
16173
|
+
const r = rel(file);
|
|
16174
|
+
const isIndex = path7.basename(file) === "index.md";
|
|
16175
|
+
let data = {};
|
|
16176
|
+
try {
|
|
16177
|
+
data = matter20(fs8.readFileSync(file, "utf-8")).data ?? {};
|
|
16178
|
+
} catch {
|
|
16179
|
+
findings.push({ level: "conformance", file: r, message: "Invalid YAML frontmatter." });
|
|
16180
|
+
continue;
|
|
16181
|
+
}
|
|
16182
|
+
const type = typeof data.type === "string" ? data.type.trim() : "";
|
|
16183
|
+
if (!isIndex) {
|
|
16184
|
+
if (!type) findings.push({ level: "conformance", file: r, message: "Concept has no non-empty `type`." });
|
|
16185
|
+
conceptCount++;
|
|
16186
|
+
}
|
|
16187
|
+
if (r === "index.md") {
|
|
16188
|
+
const v = typeof data.okf_version === "string" ? data.okf_version : data.okf_version != null ? String(data.okf_version) : "";
|
|
16189
|
+
if (!v) findings.push({ level: "warning", file: r, message: "Root index does not declare okf_version." });
|
|
16190
|
+
else if (v !== OKF_VERSION) findings.push({ level: "info", file: r, message: `Bundle declares okf_version "${v}" (validator targets ${OKF_VERSION}).` });
|
|
16191
|
+
}
|
|
16192
|
+
const kid = typeof data.kaddo_id === "string" ? data.kaddo_id : "";
|
|
16193
|
+
if (kid) {
|
|
16194
|
+
if (idToFile.has(kid)) findings.push({ level: "conformance", file: r, message: `Duplicate concept id "${kid}" (also in ${idToFile.get(kid)}).` });
|
|
16195
|
+
else idToFile.set(kid, r);
|
|
16196
|
+
}
|
|
16197
|
+
const body = (() => {
|
|
16198
|
+
try {
|
|
16199
|
+
return matter20(fs8.readFileSync(file, "utf-8")).content;
|
|
16200
|
+
} catch {
|
|
16201
|
+
return "";
|
|
16202
|
+
}
|
|
16203
|
+
})();
|
|
16204
|
+
for (const href of internalLinks(body)) {
|
|
16205
|
+
const resolved = path7.posix.normalize(path7.posix.join(path7.posix.dirname(r), href));
|
|
16206
|
+
if (!present.has(resolved)) findings.push({ level: "info", file: r, message: `Internal link not resolvable yet: ${href}` });
|
|
16207
|
+
}
|
|
16208
|
+
}
|
|
16209
|
+
const counts = {
|
|
16210
|
+
conformance: findings.filter((f) => f.level === "conformance").length,
|
|
16211
|
+
warning: findings.filter((f) => f.level === "warning").length,
|
|
16212
|
+
info: findings.filter((f) => f.level === "info").length
|
|
16213
|
+
};
|
|
16214
|
+
return { dir: bundleDir, conformant: counts.conformance === 0, conceptCount, findings, counts };
|
|
16215
|
+
}
|
|
15646
16216
|
export {
|
|
15647
16217
|
CANDIDATE_DISCOVERY_GUIDANCE,
|
|
15648
16218
|
CURRENT_CONSENT_VERSION,
|
|
@@ -15664,6 +16234,12 @@ export {
|
|
|
15664
16234
|
IntegrationServiceError,
|
|
15665
16235
|
LIFECYCLE_STATES2 as LIFECYCLE_STATES,
|
|
15666
16236
|
LIFECYCLE_TRANSITIONS,
|
|
16237
|
+
OKF_DEFAULT_OUTPUT,
|
|
16238
|
+
OKF_EXPORT_PROCESS,
|
|
16239
|
+
OKF_RESERVED_FILES,
|
|
16240
|
+
OKF_TYPE_TABLE,
|
|
16241
|
+
OKF_VERSION,
|
|
16242
|
+
OkfExportError,
|
|
15667
16243
|
POC_ARTIFACT_PATH,
|
|
15668
16244
|
POC_REPORT_PREFIX,
|
|
15669
16245
|
PRODUCTION_RUNBOOKS_DIR,
|
|
@@ -15691,6 +16267,7 @@ export {
|
|
|
15691
16267
|
analyzeScopeCoverage,
|
|
15692
16268
|
applyTopologyProposal,
|
|
15693
16269
|
associatedWorkItems,
|
|
16270
|
+
buildConcept,
|
|
15694
16271
|
buildDriftReport,
|
|
15695
16272
|
buildImpactReport,
|
|
15696
16273
|
buildImplementationHandoff,
|
|
@@ -15707,6 +16284,7 @@ export {
|
|
|
15707
16284
|
computeContentHash,
|
|
15708
16285
|
computeInitiativeProgress,
|
|
15709
16286
|
computeRefinementStatus,
|
|
16287
|
+
conceptBundlePath,
|
|
15710
16288
|
consentNotice,
|
|
15711
16289
|
createInitiative,
|
|
15712
16290
|
createIntegration,
|
|
@@ -15731,6 +16309,7 @@ export {
|
|
|
15731
16309
|
evaluateCompletion,
|
|
15732
16310
|
evaluateInitiativeCompletion,
|
|
15733
16311
|
exists,
|
|
16312
|
+
exportOkf,
|
|
15734
16313
|
filterSecretPaths,
|
|
15735
16314
|
findDuplicateByHash,
|
|
15736
16315
|
findExistingById,
|
|
@@ -15764,6 +16343,7 @@ export {
|
|
|
15764
16343
|
importWorkItem,
|
|
15765
16344
|
integrationRegistry,
|
|
15766
16345
|
isActiveState,
|
|
16346
|
+
isAgentInstruction,
|
|
15767
16347
|
isDeferralActive,
|
|
15768
16348
|
isInteractive,
|
|
15769
16349
|
isModule,
|
|
@@ -15791,6 +16371,7 @@ export {
|
|
|
15791
16371
|
nextPlanId,
|
|
15792
16372
|
nextTargetId,
|
|
15793
16373
|
observationStatus,
|
|
16374
|
+
okfConceptType,
|
|
15794
16375
|
parseContent,
|
|
15795
16376
|
parseInitiative,
|
|
15796
16377
|
parseScope,
|
|
@@ -15834,6 +16415,7 @@ export {
|
|
|
15834
16415
|
updateTarget,
|
|
15835
16416
|
updateWorkItem,
|
|
15836
16417
|
validateConfigAgainstSchema,
|
|
16418
|
+
validateOkf,
|
|
15837
16419
|
validatePlan,
|
|
15838
16420
|
validateProductionRunbook,
|
|
15839
16421
|
validateResource,
|