@kaddo/cli 3.103.0 → 3.105.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/chunk-XCTQ5SFK.js +49 -0
- package/dist/core.js +696 -90
- package/dist/index.js +102 -90
- package/dist/ui-4AQHWUC4.js +20 -0
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
|
+
import "./chunk-XCTQ5SFK.js";
|
|
2
|
+
|
|
1
3
|
// src/utils/fs.ts
|
|
2
4
|
import fs from "fs";
|
|
3
5
|
import path from "path";
|
|
4
|
-
function exists(
|
|
5
|
-
return fs.existsSync(
|
|
6
|
+
function exists(p) {
|
|
7
|
+
return fs.existsSync(p);
|
|
6
8
|
}
|
|
7
|
-
function readFile(
|
|
8
|
-
return fs.readFileSync(
|
|
9
|
+
function readFile(p) {
|
|
10
|
+
return fs.readFileSync(p, "utf-8");
|
|
9
11
|
}
|
|
10
12
|
function writeFile(filePath, content) {
|
|
11
13
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
12
14
|
fs.writeFileSync(filePath, content, "utf-8");
|
|
13
15
|
}
|
|
16
|
+
function ensureDir(dirPath) {
|
|
17
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
18
|
+
}
|
|
14
19
|
function readDir(dirPath) {
|
|
15
20
|
if (!exists(dirPath)) return [];
|
|
16
21
|
return fs.readdirSync(dirPath);
|
|
17
22
|
}
|
|
18
|
-
function isFile(
|
|
19
|
-
return exists(
|
|
23
|
+
function isFile(p) {
|
|
24
|
+
return exists(p) && fs.statSync(p).isFile();
|
|
20
25
|
}
|
|
21
|
-
function isDir(
|
|
22
|
-
return exists(
|
|
26
|
+
function isDir(p) {
|
|
27
|
+
return exists(p) && fs.statSync(p).isDirectory();
|
|
23
28
|
}
|
|
24
29
|
function cwd() {
|
|
25
30
|
return process.cwd();
|
|
@@ -272,8 +277,8 @@ function isActiveState(s) {
|
|
|
272
277
|
return ACTIVE_STATES.includes(s);
|
|
273
278
|
}
|
|
274
279
|
function lifecycleFolderOf(filePath) {
|
|
275
|
-
const
|
|
276
|
-
const m =
|
|
280
|
+
const p = filePath.replace(/\\/g, "/");
|
|
281
|
+
const m = p.match(/\/delivery\/work-items\/([^/]+)\//);
|
|
277
282
|
if (m && isLifecycleState(m[1])) return m[1];
|
|
278
283
|
return null;
|
|
279
284
|
}
|
|
@@ -296,8 +301,8 @@ function lifecycleCounts(states) {
|
|
|
296
301
|
|
|
297
302
|
// src/services/knowledge-artifacts.ts
|
|
298
303
|
var ARCH_DIR = "knowledge";
|
|
299
|
-
function toPosix(
|
|
300
|
-
return
|
|
304
|
+
function toPosix(p) {
|
|
305
|
+
return p.replace(/\\/g, "/");
|
|
301
306
|
}
|
|
302
307
|
function relativeTo(dir, filePath) {
|
|
303
308
|
const base = toPosix(dir).replace(/\/+$/, "");
|
|
@@ -392,9 +397,6 @@ function loadMappedModules(dir) {
|
|
|
392
397
|
return modules;
|
|
393
398
|
}
|
|
394
399
|
|
|
395
|
-
// src/utils/ui.ts
|
|
396
|
-
import * as p from "@clack/prompts";
|
|
397
|
-
|
|
398
400
|
// src/commands/modules-map.ts
|
|
399
401
|
import { parse as parseYaml5, stringify as stringifyYaml2 } from "yaml";
|
|
400
402
|
|
|
@@ -1565,10 +1567,10 @@ import { parse as parseYaml4, stringify as stringifyYaml } from "yaml";
|
|
|
1565
1567
|
// src/core/capsule.ts
|
|
1566
1568
|
var EXTERNAL_PATH = ".kaddo/external.yml";
|
|
1567
1569
|
function loadExternalRegistry(dir) {
|
|
1568
|
-
const
|
|
1569
|
-
if (!exists(
|
|
1570
|
+
const p = join(dir, EXTERNAL_PATH);
|
|
1571
|
+
if (!exists(p)) return [];
|
|
1570
1572
|
try {
|
|
1571
|
-
const parsed = parseYaml6(readFile(
|
|
1573
|
+
const parsed = parseYaml6(readFile(p));
|
|
1572
1574
|
return Array.isArray(parsed?.external) ? parsed.external : [];
|
|
1573
1575
|
} catch {
|
|
1574
1576
|
return [];
|
|
@@ -1640,8 +1642,8 @@ var ALL_STATUSES = ["draft", "ready", "in-progress", "blocked", "completed"];
|
|
|
1640
1642
|
function scopeStatuses(scope) {
|
|
1641
1643
|
return scope === "all" ? { included: ALL_STATUSES, excluded: ["archived"] } : { included: ACTIVE_STATUSES, excluded: ["completed", "archived"] };
|
|
1642
1644
|
}
|
|
1643
|
-
function toPosix2(
|
|
1644
|
-
return
|
|
1645
|
+
function toPosix2(p) {
|
|
1646
|
+
return p.replace(/\\/g, "/");
|
|
1645
1647
|
}
|
|
1646
1648
|
function slug(s) {
|
|
1647
1649
|
return s.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -1780,10 +1782,10 @@ function buildGraph(dir, config, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
1780
1782
|
}
|
|
1781
1783
|
var ACTIVE_WI_STATES = /* @__PURE__ */ new Set(["draft", "ready", "in-progress", "blocked"]);
|
|
1782
1784
|
function loadGraphSummary(dir) {
|
|
1783
|
-
const
|
|
1784
|
-
if (!exists(
|
|
1785
|
+
const p = join(dir, ".kaddo", "graph.json");
|
|
1786
|
+
if (!exists(p)) return null;
|
|
1785
1787
|
try {
|
|
1786
|
-
const graph = JSON.parse(readFile(
|
|
1788
|
+
const graph = JSON.parse(readFile(p));
|
|
1787
1789
|
const nodes = Array.isArray(graph.nodes) ? graph.nodes : [];
|
|
1788
1790
|
const edges = Array.isArray(graph.edges) ? graph.edges : [];
|
|
1789
1791
|
const activeWiIds = new Set(
|
|
@@ -1810,8 +1812,8 @@ function loadGraphSummary(dir) {
|
|
|
1810
1812
|
|
|
1811
1813
|
// src/core/graph-hints.ts
|
|
1812
1814
|
var KNOWLEDGE3 = "knowledge";
|
|
1813
|
-
function toPosix3(
|
|
1814
|
-
return
|
|
1815
|
+
function toPosix3(p) {
|
|
1816
|
+
return p.replace(/\\/g, "/");
|
|
1815
1817
|
}
|
|
1816
1818
|
function slug2(s) {
|
|
1817
1819
|
return s.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -1820,9 +1822,9 @@ function isAdr2(a) {
|
|
|
1820
1822
|
return toPosix3(a.filePath).includes("/tech/decisions/") && Boolean(a.type);
|
|
1821
1823
|
}
|
|
1822
1824
|
function capabilityHeadings(dir) {
|
|
1823
|
-
const
|
|
1824
|
-
if (!exists(
|
|
1825
|
-
return readFile(
|
|
1825
|
+
const p = join(dir, KNOWLEDGE3, "product", "capabilities.md");
|
|
1826
|
+
if (!exists(p)) return [];
|
|
1827
|
+
return readFile(p).split(/\r?\n/).map((l) => l.match(/^#{2,3}\s+(.+?)\s*$/)).filter((m) => Boolean(m)).map((m) => m[1].trim()).filter((h) => !/^(summary|resumen|overview|capabilities|capacidades)$/i.test(h));
|
|
1826
1828
|
}
|
|
1827
1829
|
function humanMissing(field) {
|
|
1828
1830
|
switch (field) {
|
|
@@ -1965,10 +1967,10 @@ function assessQuality(nodes, relationshipEdges, hintCount) {
|
|
|
1965
1967
|
return "good";
|
|
1966
1968
|
}
|
|
1967
1969
|
function loadGraphHints(dir) {
|
|
1968
|
-
const
|
|
1969
|
-
if (!exists(
|
|
1970
|
+
const p = join(dir, ".kaddo", "graph-hints.json");
|
|
1971
|
+
if (!exists(p)) return null;
|
|
1970
1972
|
try {
|
|
1971
|
-
const report = JSON.parse(readFile(
|
|
1973
|
+
const report = JSON.parse(readFile(p));
|
|
1972
1974
|
const hints = Array.isArray(report.hints) ? report.hints : [];
|
|
1973
1975
|
return {
|
|
1974
1976
|
scope: String(report.scope ?? "active"),
|
|
@@ -2057,15 +2059,15 @@ function layerForType(type) {
|
|
|
2057
2059
|
return null;
|
|
2058
2060
|
}
|
|
2059
2061
|
function layerFromPath(filePath) {
|
|
2060
|
-
const
|
|
2061
|
-
if (
|
|
2062
|
-
if (
|
|
2063
|
-
if (
|
|
2064
|
-
if (
|
|
2062
|
+
const p = filePath.replace(/\\/g, "/");
|
|
2063
|
+
if (p.includes(`/${KNOWLEDGE4}/business/`)) return "Business";
|
|
2064
|
+
if (p.includes(`/${KNOWLEDGE4}/product/`)) return "Product";
|
|
2065
|
+
if (p.includes(`/${KNOWLEDGE4}/tech/`)) return "Tech";
|
|
2066
|
+
if (p.includes(`/${KNOWLEDGE4}/delivery/`)) return "Delivery";
|
|
2065
2067
|
return null;
|
|
2066
2068
|
}
|
|
2067
|
-
function basename(
|
|
2068
|
-
return
|
|
2069
|
+
function basename(p) {
|
|
2070
|
+
return p.replace(/\\/g, "/").split("/").pop() ?? p;
|
|
2069
2071
|
}
|
|
2070
2072
|
function discoverLayers(dir) {
|
|
2071
2073
|
const acc = {
|
|
@@ -2195,10 +2197,10 @@ function analyzeContent(md) {
|
|
|
2195
2197
|
return "weak";
|
|
2196
2198
|
}
|
|
2197
2199
|
function analyzeKnowledgeArtifact(dir, rel) {
|
|
2198
|
-
const
|
|
2199
|
-
if (!exists(
|
|
2200
|
+
const p = join(dir, rel);
|
|
2201
|
+
if (!exists(p)) return "missing";
|
|
2200
2202
|
try {
|
|
2201
|
-
return analyzeContent(readFile(
|
|
2203
|
+
return analyzeContent(readFile(p));
|
|
2202
2204
|
} catch {
|
|
2203
2205
|
return "missing";
|
|
2204
2206
|
}
|
|
@@ -2393,10 +2395,10 @@ function splitRow(line) {
|
|
|
2393
2395
|
function isSeparatorRow(cells) {
|
|
2394
2396
|
return cells.length > 0 && cells.every((c) => SEPARATOR_CELL_RE.test(c) || c === "");
|
|
2395
2397
|
}
|
|
2396
|
-
function initiativeFromHeading(
|
|
2397
|
-
const rm =
|
|
2398
|
+
function initiativeFromHeading(text2) {
|
|
2399
|
+
const rm = text2.match(/^(RM-[\w.-]+)\s*[:\-–]?\s*(.*)$/);
|
|
2398
2400
|
if (rm) return { id: rm[1], title: rm[2].trim() || void 0 };
|
|
2399
|
-
return { title:
|
|
2401
|
+
return { title: text2.trim() || void 0 };
|
|
2400
2402
|
}
|
|
2401
2403
|
function extractDeps(cell) {
|
|
2402
2404
|
if (!cell) return void 0;
|
|
@@ -2582,8 +2584,8 @@ var IMPORTANT = [
|
|
|
2582
2584
|
"permis",
|
|
2583
2585
|
"permission"
|
|
2584
2586
|
];
|
|
2585
|
-
function matchesAny(
|
|
2586
|
-
return keywords.some((k) =>
|
|
2587
|
+
function matchesAny(text2, keywords) {
|
|
2588
|
+
return keywords.some((k) => text2.includes(k));
|
|
2587
2589
|
}
|
|
2588
2590
|
function classifyQuestion(question) {
|
|
2589
2591
|
const t = question.toLowerCase();
|
|
@@ -2615,8 +2617,8 @@ function extractFromMarkdown(md) {
|
|
|
2615
2617
|
if (m) {
|
|
2616
2618
|
const bullet = m[1].trim();
|
|
2617
2619
|
if (!bullet || /^_.*_$/.test(bullet)) continue;
|
|
2618
|
-
const { text:
|
|
2619
|
-
if (
|
|
2620
|
+
const { text: text2, resolution_status } = parseResolution(bullet);
|
|
2621
|
+
if (text2) out.push({ text: text2, resolution_status, line: i + 1, raw: line.trim() });
|
|
2620
2622
|
}
|
|
2621
2623
|
}
|
|
2622
2624
|
return out;
|
|
@@ -2642,11 +2644,11 @@ function buildOpenQuestionsReport(dir, now = /* @__PURE__ */ new Date()) {
|
|
|
2642
2644
|
const questions = [];
|
|
2643
2645
|
let seq = 0;
|
|
2644
2646
|
for (const source of SOURCES) {
|
|
2645
|
-
const
|
|
2646
|
-
if (!exists(
|
|
2647
|
+
const p = join(dir, source);
|
|
2648
|
+
if (!exists(p)) continue;
|
|
2647
2649
|
let md;
|
|
2648
2650
|
try {
|
|
2649
|
-
md = readFile(
|
|
2651
|
+
md = readFile(p);
|
|
2650
2652
|
} catch {
|
|
2651
2653
|
continue;
|
|
2652
2654
|
}
|
|
@@ -2758,7 +2760,7 @@ function buildCodexAdapterContext(dir) {
|
|
|
2758
2760
|
hasSkills: skills.length > 0,
|
|
2759
2761
|
skills,
|
|
2760
2762
|
hasMcpHint: detectMcpHint(dir),
|
|
2761
|
-
knowledgePaths: KNOWLEDGE_PATHS.filter((
|
|
2763
|
+
knowledgePaths: KNOWLEDGE_PATHS.filter((p) => exists(join(dir, p))),
|
|
2762
2764
|
generatedPaths: GENERATED_PATHS
|
|
2763
2765
|
};
|
|
2764
2766
|
}
|
|
@@ -3019,19 +3021,19 @@ function hasRegisteredModules(modulesYmlPath) {
|
|
|
3019
3021
|
return false;
|
|
3020
3022
|
}
|
|
3021
3023
|
}
|
|
3022
|
-
function safeRead(
|
|
3024
|
+
function safeRead(p) {
|
|
3023
3025
|
try {
|
|
3024
|
-
return readFile(
|
|
3026
|
+
return readFile(p);
|
|
3025
3027
|
} catch {
|
|
3026
3028
|
return null;
|
|
3027
3029
|
}
|
|
3028
3030
|
}
|
|
3029
3031
|
function roadmapSignal(dir) {
|
|
3030
|
-
const
|
|
3031
|
-
if (!exists(
|
|
3032
|
+
const p = join(dir, "knowledge/delivery/roadmap.md");
|
|
3033
|
+
if (!exists(p)) return "missing";
|
|
3032
3034
|
let md;
|
|
3033
3035
|
try {
|
|
3034
|
-
md = readFile(
|
|
3036
|
+
md = readFile(p);
|
|
3035
3037
|
} catch {
|
|
3036
3038
|
return "missing";
|
|
3037
3039
|
}
|
|
@@ -6561,7 +6563,7 @@ var AGENT_PROMPTS = [
|
|
|
6561
6563
|
// Graph relationship quality (metadata hints → precise front matter — VS-056)
|
|
6562
6564
|
{ fileName: "graph-agent.md", content: GRAPH_AGENT }
|
|
6563
6565
|
// Every official prompt ends with its responsibility boundaries + Agent Trace footer.
|
|
6564
|
-
].map((
|
|
6566
|
+
].map((p) => ({ fileName: p.fileName, content: withResponsibilityTrace(p.fileName, p.content) }));
|
|
6565
6567
|
|
|
6566
6568
|
// src/modules/agents.ts
|
|
6567
6569
|
function withAgentFrontMatter(fileName, content) {
|
|
@@ -6813,10 +6815,10 @@ function parseRoadmapCandidateQuality(md) {
|
|
|
6813
6815
|
}
|
|
6814
6816
|
function buildRoadmapQuality(dir) {
|
|
6815
6817
|
let md = "";
|
|
6816
|
-
const
|
|
6817
|
-
if (exists(
|
|
6818
|
+
const p = join(dir, ROADMAP_PATH);
|
|
6819
|
+
if (exists(p)) {
|
|
6818
6820
|
try {
|
|
6819
|
-
md = readFile(
|
|
6821
|
+
md = readFile(p);
|
|
6820
6822
|
} catch {
|
|
6821
6823
|
md = "";
|
|
6822
6824
|
}
|
|
@@ -7417,11 +7419,11 @@ function analyzeMetadataHealth(dir) {
|
|
|
7417
7419
|
let healthy = 0;
|
|
7418
7420
|
let drifted = 0;
|
|
7419
7421
|
for (const rel of KNOWLEDGE_FILES2) {
|
|
7420
|
-
const
|
|
7421
|
-
if (!exists(
|
|
7422
|
+
const p = join(dir, rel);
|
|
7423
|
+
if (!exists(p)) continue;
|
|
7422
7424
|
let data;
|
|
7423
7425
|
try {
|
|
7424
|
-
const raw = readFile(
|
|
7426
|
+
const raw = readFile(p);
|
|
7425
7427
|
data = matter5(raw).data;
|
|
7426
7428
|
} catch {
|
|
7427
7429
|
continue;
|
|
@@ -7450,13 +7452,13 @@ function analyzeMetadataHealth(dir) {
|
|
|
7450
7452
|
if (exists(wiDir)) {
|
|
7451
7453
|
const walkWIs = (d) => {
|
|
7452
7454
|
for (const entry of readDir(d)) {
|
|
7453
|
-
const
|
|
7454
|
-
if (isFile(
|
|
7455
|
+
const p = join(d, entry);
|
|
7456
|
+
if (isFile(p) && entry.endsWith(".md")) {
|
|
7455
7457
|
try {
|
|
7456
|
-
const raw = readFile(
|
|
7458
|
+
const raw = readFile(p);
|
|
7457
7459
|
const fm = matter5(raw).data;
|
|
7458
7460
|
if (fm.status === "done") {
|
|
7459
|
-
const rel =
|
|
7461
|
+
const rel = p.replace(dir + "/", "").replace(dir + "\\", "").replace(/\\/g, "/");
|
|
7460
7462
|
findings.push({
|
|
7461
7463
|
file: rel,
|
|
7462
7464
|
field: "status",
|
|
@@ -7466,8 +7468,8 @@ function analyzeMetadataHealth(dir) {
|
|
|
7466
7468
|
}
|
|
7467
7469
|
} catch {
|
|
7468
7470
|
}
|
|
7469
|
-
} else if (!isFile(
|
|
7470
|
-
walkWIs(
|
|
7471
|
+
} else if (!isFile(p) && !entry.startsWith(".")) {
|
|
7472
|
+
walkWIs(p);
|
|
7471
7473
|
}
|
|
7472
7474
|
}
|
|
7473
7475
|
};
|
|
@@ -8086,8 +8088,8 @@ var TECHNICAL_RELATIONSHIP_TYPES = /* @__PURE__ */ new Set([
|
|
|
8086
8088
|
"implemented-by"
|
|
8087
8089
|
]);
|
|
8088
8090
|
var PROVENANCE = /* @__PURE__ */ new Set(["declared", "derived", "agent-reviewed"]);
|
|
8089
|
-
function isRelative(
|
|
8090
|
-
return typeof
|
|
8091
|
+
function isRelative(p) {
|
|
8092
|
+
return typeof p === "string" && p.trim() !== "" && !/^([a-zA-Z]:[\\/]|\/)/.test(p) && !p.includes("..");
|
|
8091
8093
|
}
|
|
8092
8094
|
function strList(v) {
|
|
8093
8095
|
return Array.isArray(v) ? v.map((x) => typeof x === "string" ? x.trim() : "").filter(Boolean) : [];
|
|
@@ -8130,9 +8132,9 @@ function parseTopologyContent(raw, dir) {
|
|
|
8130
8132
|
const moduleRaw = typeof e.module === "string" ? e.module.trim() : void 0;
|
|
8131
8133
|
if (moduleRaw && !validModules.has(moduleRaw)) findings.push({ level: "warning", message: `Entity "${id}" references unregistered module "${moduleRaw}".` });
|
|
8132
8134
|
const rawImpl = e.implementation ?? e.implementation_refs;
|
|
8133
|
-
const implementation = strList(rawImpl).filter((
|
|
8134
|
-
if (isRelative(
|
|
8135
|
-
findings.push({ level: "warning", message: `Entity "${id}" implementation ref "${
|
|
8135
|
+
const implementation = strList(rawImpl).filter((p) => {
|
|
8136
|
+
if (isRelative(p)) return true;
|
|
8137
|
+
findings.push({ level: "warning", message: `Entity "${id}" implementation ref "${p}" is not a safe relative path and was dropped.` });
|
|
8136
8138
|
return false;
|
|
8137
8139
|
});
|
|
8138
8140
|
const prov = e.provenance;
|
|
@@ -8509,8 +8511,8 @@ function splitSections(body) {
|
|
|
8509
8511
|
flush();
|
|
8510
8512
|
return sections;
|
|
8511
8513
|
}
|
|
8512
|
-
function isPlaceholder(
|
|
8513
|
-
const t =
|
|
8514
|
+
function isPlaceholder(text2) {
|
|
8515
|
+
const t = text2.trim();
|
|
8514
8516
|
if (!t) return true;
|
|
8515
8517
|
if (/^tbd$/i.test(t)) return true;
|
|
8516
8518
|
if (/^_[^_]*_$/.test(t) && !t.includes("\n")) return true;
|
|
@@ -8537,15 +8539,15 @@ function extractBullets(body) {
|
|
|
8537
8539
|
for (const line of body.split(/\r?\n/)) {
|
|
8538
8540
|
const m = line.match(/^\s*[-*+]\s+(.*)$/);
|
|
8539
8541
|
if (!m) continue;
|
|
8540
|
-
let
|
|
8542
|
+
let text2 = m[1].trim();
|
|
8541
8543
|
let checked = null;
|
|
8542
|
-
const cb =
|
|
8544
|
+
const cb = text2.match(/^\[([ xX])\]\s*(.*)$/);
|
|
8543
8545
|
if (cb) {
|
|
8544
8546
|
checked = cb[1].toLowerCase() === "x";
|
|
8545
|
-
|
|
8547
|
+
text2 = cb[2].trim();
|
|
8546
8548
|
}
|
|
8547
|
-
if (!
|
|
8548
|
-
out.push({ text:
|
|
8549
|
+
if (!text2 || isPlaceholder(text2)) continue;
|
|
8550
|
+
out.push({ text: text2, checked });
|
|
8549
8551
|
}
|
|
8550
8552
|
return out;
|
|
8551
8553
|
}
|
|
@@ -9071,14 +9073,14 @@ function toInput(data, content) {
|
|
|
9071
9073
|
for (const line of body.split(/\r?\n/)) {
|
|
9072
9074
|
const m = line.match(/^\s*[-*+]\s+(.*)$/);
|
|
9073
9075
|
if (!m) continue;
|
|
9074
|
-
let
|
|
9076
|
+
let text2 = m[1].trim();
|
|
9075
9077
|
let checked = null;
|
|
9076
|
-
const cb =
|
|
9078
|
+
const cb = text2.match(/^\[([ xX])\]\s*(.*)$/);
|
|
9077
9079
|
if (cb) {
|
|
9078
9080
|
checked = cb[1].toLowerCase() === "x";
|
|
9079
|
-
|
|
9081
|
+
text2 = cb[2].trim();
|
|
9080
9082
|
}
|
|
9081
|
-
if (
|
|
9083
|
+
if (text2) out.push({ text: text2, checked });
|
|
9082
9084
|
}
|
|
9083
9085
|
return out;
|
|
9084
9086
|
})();
|
|
@@ -9151,7 +9153,7 @@ function createWorkItem(dir, opts) {
|
|
|
9151
9153
|
if (!type) throw new WorkItemWriteError("INVALID_INPUT", `Unknown Work Item type "${opts.type}".`);
|
|
9152
9154
|
const id = nextWorkItemId(dir);
|
|
9153
9155
|
const title = intent.split(/\r?\n/)[0].trim().slice(0, 120);
|
|
9154
|
-
const
|
|
9156
|
+
const today2 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
9155
9157
|
const source = opts.source ? { ...opts.source, inferred: false } : { type: "manual", inferred: false };
|
|
9156
9158
|
const data = {
|
|
9157
9159
|
type,
|
|
@@ -9159,7 +9161,7 @@ function createWorkItem(dir, opts) {
|
|
|
9159
9161
|
title,
|
|
9160
9162
|
status: "draft",
|
|
9161
9163
|
work_type: type,
|
|
9162
|
-
created_at:
|
|
9164
|
+
created_at: today2,
|
|
9163
9165
|
source,
|
|
9164
9166
|
generated_by: "kaddo-admin",
|
|
9165
9167
|
affected_modules: [],
|
|
@@ -9903,7 +9905,7 @@ var SECRET_PATTERNS = [
|
|
|
9903
9905
|
/\.pfx$/i
|
|
9904
9906
|
];
|
|
9905
9907
|
function filterSecretPaths(paths) {
|
|
9906
|
-
return paths.filter((
|
|
9908
|
+
return paths.filter((p) => !SECRET_PATTERNS.some((re) => re.test(p)));
|
|
9907
9909
|
}
|
|
9908
9910
|
function collectImplementationEvidence(dir, workItemId, input) {
|
|
9909
9911
|
const artifacts = discoverWorkItems(dir);
|
|
@@ -11771,9 +11773,591 @@ ${item.description}` : item.title;
|
|
|
11771
11773
|
importLocks.delete(lockKey);
|
|
11772
11774
|
}
|
|
11773
11775
|
}
|
|
11776
|
+
|
|
11777
|
+
// src/core/telemetry-consent.ts
|
|
11778
|
+
import { parse as parseYaml10, stringify as stringifyYaml6 } from "yaml";
|
|
11779
|
+
var CURRENT_CONSENT_VERSION = 1;
|
|
11780
|
+
var DEFERRAL_DURATION_MS = 24 * 60 * 60 * 1e3;
|
|
11781
|
+
function getConsentState(config) {
|
|
11782
|
+
if (!config) return "unset";
|
|
11783
|
+
const t = config.telemetry;
|
|
11784
|
+
if (!t) return "unset";
|
|
11785
|
+
if (t.consent === "enabled") return "enabled";
|
|
11786
|
+
if (t.consent === "disabled") return "disabled";
|
|
11787
|
+
if (t.consent === void 0) {
|
|
11788
|
+
if (t.enabled === true) return "enabled";
|
|
11789
|
+
if (t.enabled === false) return "disabled";
|
|
11790
|
+
}
|
|
11791
|
+
return "unset";
|
|
11792
|
+
}
|
|
11793
|
+
function isInteractive() {
|
|
11794
|
+
if (process.env.CI) return false;
|
|
11795
|
+
if (!process.stdin.isTTY) return false;
|
|
11796
|
+
if (!process.stdout.isTTY) return false;
|
|
11797
|
+
return true;
|
|
11798
|
+
}
|
|
11799
|
+
function persistConsent(dir, consent) {
|
|
11800
|
+
const configPath = join(dir, ".kaddo", "config.yml");
|
|
11801
|
+
if (!exists(configPath)) return;
|
|
11802
|
+
const raw = readFile(configPath);
|
|
11803
|
+
const doc = parseYaml10(raw) ?? {};
|
|
11804
|
+
const prev = doc.telemetry ?? {};
|
|
11805
|
+
delete prev.enabled;
|
|
11806
|
+
doc.telemetry = { ...prev, consent, consentVersion: CURRENT_CONSENT_VERSION };
|
|
11807
|
+
writeFile(configPath, stringifyYaml6(doc));
|
|
11808
|
+
}
|
|
11809
|
+
function isDeferralActive(dir) {
|
|
11810
|
+
const p = join(dir, ".kaddo", "telemetry-deferred.json");
|
|
11811
|
+
if (!exists(p)) return false;
|
|
11812
|
+
try {
|
|
11813
|
+
const data = JSON.parse(readFile(p));
|
|
11814
|
+
return data.deferredUntil > Date.now();
|
|
11815
|
+
} catch {
|
|
11816
|
+
return false;
|
|
11817
|
+
}
|
|
11818
|
+
}
|
|
11819
|
+
function deferConsent(dir) {
|
|
11820
|
+
const p = join(dir, ".kaddo", "telemetry-deferred.json");
|
|
11821
|
+
writeFile(p, JSON.stringify({ deferredUntil: Date.now() + DEFERRAL_DURATION_MS }));
|
|
11822
|
+
}
|
|
11823
|
+
function consentNotice() {
|
|
11824
|
+
return '[Telemetry consent] Anonymous usage telemetry has not been configured.\n Collects: command usage, version, lifecycle events.\n Never collects: source code, knowledge, prompts or PII.\n Use kaddo_set_telemetry_consent to enable, disable, or defer ("not-now").';
|
|
11825
|
+
}
|
|
11826
|
+
|
|
11827
|
+
// src/core/telemetry.ts
|
|
11828
|
+
import crypto6 from "crypto";
|
|
11829
|
+
|
|
11830
|
+
// src/core/telemetry-identity.ts
|
|
11831
|
+
import crypto4 from "crypto";
|
|
11832
|
+
var TELEMETRY_DIR = ".kaddo/telemetry";
|
|
11833
|
+
var IDENTITY_FILE = "identity.json";
|
|
11834
|
+
function identityPath(dir) {
|
|
11835
|
+
return join(dir, TELEMETRY_DIR, IDENTITY_FILE);
|
|
11836
|
+
}
|
|
11837
|
+
function loadIdentity(dir) {
|
|
11838
|
+
const p = identityPath(dir);
|
|
11839
|
+
if (!exists(p)) return null;
|
|
11840
|
+
try {
|
|
11841
|
+
return JSON.parse(readFile(p));
|
|
11842
|
+
} catch {
|
|
11843
|
+
return null;
|
|
11844
|
+
}
|
|
11845
|
+
}
|
|
11846
|
+
|
|
11847
|
+
// src/core/telemetry-events.ts
|
|
11848
|
+
import crypto5 from "crypto";
|
|
11849
|
+
|
|
11850
|
+
// src/core/telemetry-buffer.ts
|
|
11851
|
+
var TELEMETRY_DIR2 = ".kaddo/telemetry";
|
|
11852
|
+
var BUFFER_FILE = "buffer.json";
|
|
11853
|
+
function bufferPath(dir) {
|
|
11854
|
+
return join(dir, TELEMETRY_DIR2, BUFFER_FILE);
|
|
11855
|
+
}
|
|
11856
|
+
function readBuffer(dir) {
|
|
11857
|
+
const p = bufferPath(dir);
|
|
11858
|
+
if (!exists(p)) return [];
|
|
11859
|
+
try {
|
|
11860
|
+
const data = JSON.parse(readFile(p));
|
|
11861
|
+
return Array.isArray(data) ? data : [];
|
|
11862
|
+
} catch {
|
|
11863
|
+
return [];
|
|
11864
|
+
}
|
|
11865
|
+
}
|
|
11866
|
+
function bufferSize(dir) {
|
|
11867
|
+
return readBuffer(dir).length;
|
|
11868
|
+
}
|
|
11869
|
+
|
|
11870
|
+
// src/core/telemetry.ts
|
|
11871
|
+
function isEnabled(config) {
|
|
11872
|
+
return getConsentState(config) === "enabled";
|
|
11873
|
+
}
|
|
11874
|
+
function getStatus(dir) {
|
|
11875
|
+
const config = loadConfig(dir);
|
|
11876
|
+
const consent = getConsentState(config);
|
|
11877
|
+
const enabled = consent === "enabled";
|
|
11878
|
+
const identity = loadIdentity(dir);
|
|
11879
|
+
return {
|
|
11880
|
+
consent,
|
|
11881
|
+
enabled,
|
|
11882
|
+
registered: identity?.registered ?? false,
|
|
11883
|
+
pendingEvents: enabled ? bufferSize(dir) : 0,
|
|
11884
|
+
lastError: null
|
|
11885
|
+
};
|
|
11886
|
+
}
|
|
11887
|
+
|
|
11888
|
+
// src/core/initiative.ts
|
|
11889
|
+
import matter10 from "gray-matter";
|
|
11890
|
+
var INITIATIVES_DIR = "knowledge/delivery/initiatives";
|
|
11891
|
+
var INITIATIVE_STATES = [
|
|
11892
|
+
"candidate",
|
|
11893
|
+
"planned",
|
|
11894
|
+
"in-progress",
|
|
11895
|
+
"completed",
|
|
11896
|
+
"deferred",
|
|
11897
|
+
"cancelled"
|
|
11898
|
+
];
|
|
11899
|
+
var INITIATIVE_TRANSITIONS = {
|
|
11900
|
+
candidate: ["planned", "cancelled"],
|
|
11901
|
+
planned: ["in-progress", "deferred", "cancelled"],
|
|
11902
|
+
"in-progress": ["completed", "deferred", "cancelled"],
|
|
11903
|
+
deferred: ["planned", "cancelled"],
|
|
11904
|
+
completed: [],
|
|
11905
|
+
cancelled: []
|
|
11906
|
+
};
|
|
11907
|
+
var STATUS_SET = new Set(INITIATIVE_STATES);
|
|
11908
|
+
function isValidInitiativeStatus(s) {
|
|
11909
|
+
return STATUS_SET.has(s);
|
|
11910
|
+
}
|
|
11911
|
+
function isValidInitiativeTransition(from, to) {
|
|
11912
|
+
return INITIATIVE_TRANSITIONS[from].includes(to);
|
|
11913
|
+
}
|
|
11914
|
+
function toPosix4(p) {
|
|
11915
|
+
return p.replace(/\\/g, "/");
|
|
11916
|
+
}
|
|
11917
|
+
function optStr3(v) {
|
|
11918
|
+
if (typeof v === "string" && v.trim()) return v.trim();
|
|
11919
|
+
if (typeof v === "number") return String(v);
|
|
11920
|
+
return void 0;
|
|
11921
|
+
}
|
|
11922
|
+
function strList2(v) {
|
|
11923
|
+
if (!Array.isArray(v)) return [];
|
|
11924
|
+
return v.map((x) => typeof x === "string" ? x.trim() : String(x)).filter(Boolean);
|
|
11925
|
+
}
|
|
11926
|
+
function parseCandidates(data) {
|
|
11927
|
+
const raw = data.candidates;
|
|
11928
|
+
if (!Array.isArray(raw)) return [];
|
|
11929
|
+
const out = [];
|
|
11930
|
+
for (const entry of raw) {
|
|
11931
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
11932
|
+
const o = entry;
|
|
11933
|
+
const id = optStr3(o.id);
|
|
11934
|
+
const title = optStr3(o.title);
|
|
11935
|
+
if (!id || !title) continue;
|
|
11936
|
+
out.push({
|
|
11937
|
+
id,
|
|
11938
|
+
title,
|
|
11939
|
+
type: optStr3(o.type),
|
|
11940
|
+
suggestedKnowledgeLevel: optStr3(o.suggested_knowledge_level ?? o.knowledge_level),
|
|
11941
|
+
expectedValue: optStr3(o.expected_value),
|
|
11942
|
+
notes: optStr3(o.notes),
|
|
11943
|
+
sourceSignals: strList2(o.source_signals),
|
|
11944
|
+
dependencies: strList2(o.dependencies),
|
|
11945
|
+
materializedAs: optStr3(o.materialized_as) ?? null
|
|
11946
|
+
});
|
|
11947
|
+
}
|
|
11948
|
+
return out;
|
|
11949
|
+
}
|
|
11950
|
+
function parseExternalLinks(data) {
|
|
11951
|
+
const raw = data.external_links;
|
|
11952
|
+
if (!Array.isArray(raw)) return [];
|
|
11953
|
+
const out = [];
|
|
11954
|
+
for (const entry of raw) {
|
|
11955
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
11956
|
+
const o = entry;
|
|
11957
|
+
const integration = optStr3(o.integration);
|
|
11958
|
+
const externalId = optStr3(o.external_id);
|
|
11959
|
+
if (!integration || !externalId) continue;
|
|
11960
|
+
out.push({
|
|
11961
|
+
integration,
|
|
11962
|
+
externalId,
|
|
11963
|
+
externalType: optStr3(o.external_type),
|
|
11964
|
+
url: optStr3(o.url)
|
|
11965
|
+
});
|
|
11966
|
+
}
|
|
11967
|
+
return out;
|
|
11968
|
+
}
|
|
11969
|
+
function parseInitiative(dir, filePath, raw) {
|
|
11970
|
+
let parsed;
|
|
11971
|
+
try {
|
|
11972
|
+
parsed = matter10(raw, {});
|
|
11973
|
+
} catch {
|
|
11974
|
+
return null;
|
|
11975
|
+
}
|
|
11976
|
+
const data = parsed.data;
|
|
11977
|
+
if (optStr3(data.type) !== "initiative") return null;
|
|
11978
|
+
const id = optStr3(data.id);
|
|
11979
|
+
if (!id) return null;
|
|
11980
|
+
const statusRaw = optStr3(data.status) ?? "planned";
|
|
11981
|
+
const status = isValidInitiativeStatus(statusRaw) ? statusRaw : "planned";
|
|
11982
|
+
return {
|
|
11983
|
+
id,
|
|
11984
|
+
title: optStr3(data.title) ?? id,
|
|
11985
|
+
status,
|
|
11986
|
+
horizon: optStr3(data.horizon) ?? null,
|
|
11987
|
+
priority: optStr3(data.priority) ?? null,
|
|
11988
|
+
knowledgeLevel: optStr3(data.knowledge_level) ?? null,
|
|
11989
|
+
domains: strList2(data.domains),
|
|
11990
|
+
relatedCapabilities: strList2(data.related_capabilities),
|
|
11991
|
+
source: optStr3(data.source) ?? null,
|
|
11992
|
+
sourceId: optStr3(data.source_id) ?? null,
|
|
11993
|
+
createdAt: optStr3(data.created_at) ?? null,
|
|
11994
|
+
externalLinks: parseExternalLinks(data),
|
|
11995
|
+
candidates: parseCandidates(data),
|
|
11996
|
+
filePath,
|
|
11997
|
+
relPath: toPosix4(filePath).startsWith(toPosix4(dir) + "/") ? toPosix4(filePath).slice(toPosix4(dir).length + 1) : toPosix4(filePath),
|
|
11998
|
+
body: parsed.content.trim(),
|
|
11999
|
+
rawFrontmatter: data
|
|
12000
|
+
};
|
|
12001
|
+
}
|
|
12002
|
+
function discoverInitiatives(dir) {
|
|
12003
|
+
const iniDir = join(dir, INITIATIVES_DIR);
|
|
12004
|
+
if (!exists(iniDir)) return [];
|
|
12005
|
+
const out = [];
|
|
12006
|
+
for (const entry of readDir(iniDir)) {
|
|
12007
|
+
if (!entry.endsWith(".md")) continue;
|
|
12008
|
+
const full = join(iniDir, entry);
|
|
12009
|
+
if (!isFile(full)) continue;
|
|
12010
|
+
const ini = parseInitiative(dir, full, readFile(full));
|
|
12011
|
+
if (ini) out.push(ini);
|
|
12012
|
+
}
|
|
12013
|
+
return out.sort((a, b) => a.id.localeCompare(b.id));
|
|
12014
|
+
}
|
|
12015
|
+
function getInitiative(dir, id) {
|
|
12016
|
+
const want = id.trim().toLowerCase();
|
|
12017
|
+
return discoverInitiatives(dir).find((i) => i.id.toLowerCase() === want) ?? null;
|
|
12018
|
+
}
|
|
12019
|
+
function nextInitiativeId(dir) {
|
|
12020
|
+
const iniDir = join(dir, INITIATIVES_DIR);
|
|
12021
|
+
let max = 0;
|
|
12022
|
+
if (exists(iniDir)) {
|
|
12023
|
+
for (const entry of readDir(iniDir)) {
|
|
12024
|
+
const m = entry.match(/INI-(\d+)/);
|
|
12025
|
+
if (m) max = Math.max(max, parseInt(m[1], 10));
|
|
12026
|
+
}
|
|
12027
|
+
}
|
|
12028
|
+
return `INI-${String(max + 1).padStart(3, "0")}`;
|
|
12029
|
+
}
|
|
12030
|
+
function workItemBelongsToInitiative(workItemInitiative, iniId) {
|
|
12031
|
+
const v = (workItemInitiative ?? "").trim().toLowerCase();
|
|
12032
|
+
return v !== "" && v === iniId.trim().toLowerCase();
|
|
12033
|
+
}
|
|
12034
|
+
function associatedWorkItems(dir, iniId) {
|
|
12035
|
+
return discoverWorkItems(dir).filter((wi) => workItemBelongsToInitiative(wi.initiative, iniId)).map((wi) => ({
|
|
12036
|
+
id: wi.id,
|
|
12037
|
+
title: wi.title,
|
|
12038
|
+
status: wi.lifecycle ?? "ready"
|
|
12039
|
+
})).sort((a, b) => a.id.localeCompare(b.id));
|
|
12040
|
+
}
|
|
12041
|
+
function computeInitiativeProgress(dir, ini) {
|
|
12042
|
+
const totalCandidates = ini.candidates.length;
|
|
12043
|
+
const materialized = ini.candidates.filter((c) => c.materializedAs).length;
|
|
12044
|
+
const byState = emptyLifecycleCounts();
|
|
12045
|
+
const associated = associatedWorkItems(dir, ini.id);
|
|
12046
|
+
for (const wi of associated) byState[wi.status]++;
|
|
12047
|
+
return {
|
|
12048
|
+
initiative: ini.id,
|
|
12049
|
+
status: ini.status,
|
|
12050
|
+
planning: {
|
|
12051
|
+
totalCandidates,
|
|
12052
|
+
materialized,
|
|
12053
|
+
remaining: Math.max(0, totalCandidates - materialized)
|
|
12054
|
+
},
|
|
12055
|
+
delivery: {
|
|
12056
|
+
total: associated.length,
|
|
12057
|
+
byState
|
|
12058
|
+
}
|
|
12059
|
+
};
|
|
12060
|
+
}
|
|
12061
|
+
|
|
12062
|
+
// src/core/initiative-write.ts
|
|
12063
|
+
import matter11 from "gray-matter";
|
|
12064
|
+
var WORK_ITEMS_DIR2 = "knowledge/delivery/work-items";
|
|
12065
|
+
var DRAFT_DIR = `${WORK_ITEMS_DIR2}/draft`;
|
|
12066
|
+
var ROADMAP_PATH2 = "knowledge/delivery/roadmap.md";
|
|
12067
|
+
var InitiativeWriteError = class extends Error {
|
|
12068
|
+
constructor(message) {
|
|
12069
|
+
super(message);
|
|
12070
|
+
this.name = "InitiativeWriteError";
|
|
12071
|
+
}
|
|
12072
|
+
};
|
|
12073
|
+
function slugify3(s) {
|
|
12074
|
+
return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 50);
|
|
12075
|
+
}
|
|
12076
|
+
function today() {
|
|
12077
|
+
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
12078
|
+
}
|
|
12079
|
+
function candidateToData(c) {
|
|
12080
|
+
const out = { id: c.id, title: c.title };
|
|
12081
|
+
if (c.type) out.type = c.type;
|
|
12082
|
+
if (c.suggestedKnowledgeLevel) out.suggested_knowledge_level = c.suggestedKnowledgeLevel;
|
|
12083
|
+
if (c.expectedValue) out.expected_value = c.expectedValue;
|
|
12084
|
+
if (c.notes) out.notes = c.notes;
|
|
12085
|
+
if (c.sourceSignals.length) out.source_signals = c.sourceSignals;
|
|
12086
|
+
if (c.dependencies.length) out.dependencies = c.dependencies;
|
|
12087
|
+
if (c.materializedAs) out.materialized_as = c.materializedAs;
|
|
12088
|
+
return out;
|
|
12089
|
+
}
|
|
12090
|
+
function externalLinkToData(l) {
|
|
12091
|
+
const out = { integration: l.integration, external_id: l.externalId };
|
|
12092
|
+
if (l.externalType) out.external_type = l.externalType;
|
|
12093
|
+
if (l.url) out.url = l.url;
|
|
12094
|
+
return out;
|
|
12095
|
+
}
|
|
12096
|
+
function normalizeCandidate(input, fallbackId) {
|
|
12097
|
+
return {
|
|
12098
|
+
id: input.id?.trim() || fallbackId,
|
|
12099
|
+
title: input.title.trim(),
|
|
12100
|
+
type: input.type?.trim() || void 0,
|
|
12101
|
+
suggestedKnowledgeLevel: input.suggestedKnowledgeLevel?.trim() || void 0,
|
|
12102
|
+
expectedValue: input.expectedValue?.trim() || void 0,
|
|
12103
|
+
notes: input.notes?.trim() || void 0,
|
|
12104
|
+
sourceSignals: input.sourceSignals ?? [],
|
|
12105
|
+
dependencies: input.dependencies ?? [],
|
|
12106
|
+
materializedAs: input.materializedAs ?? null
|
|
12107
|
+
};
|
|
12108
|
+
}
|
|
12109
|
+
function defaultBody(title) {
|
|
12110
|
+
return [
|
|
12111
|
+
`# ${title}`,
|
|
12112
|
+
"",
|
|
12113
|
+
"## Goal",
|
|
12114
|
+
"",
|
|
12115
|
+
"_What outcome does this Initiative pursue?_",
|
|
12116
|
+
"",
|
|
12117
|
+
"## Expected Value",
|
|
12118
|
+
"",
|
|
12119
|
+
"_Why it matters._",
|
|
12120
|
+
"",
|
|
12121
|
+
"## Scope",
|
|
12122
|
+
"",
|
|
12123
|
+
"_What this Initiative covers._",
|
|
12124
|
+
"",
|
|
12125
|
+
"## Out of Scope",
|
|
12126
|
+
"",
|
|
12127
|
+
"_What it explicitly does not cover._",
|
|
12128
|
+
"",
|
|
12129
|
+
"## Success Criteria",
|
|
12130
|
+
"",
|
|
12131
|
+
'_Observable outcomes that define completion (not just "all Work Items done")._',
|
|
12132
|
+
"",
|
|
12133
|
+
"## Dependencies",
|
|
12134
|
+
"",
|
|
12135
|
+
"_Other Initiatives, modules, or external work this depends on._",
|
|
12136
|
+
"",
|
|
12137
|
+
"## Work Item Candidates",
|
|
12138
|
+
"",
|
|
12139
|
+
"_Candidates live in frontmatter `candidates`; summarize them here as they evolve._",
|
|
12140
|
+
"",
|
|
12141
|
+
"## Open Questions",
|
|
12142
|
+
"",
|
|
12143
|
+
"_Unresolved questions for this Initiative._",
|
|
12144
|
+
"",
|
|
12145
|
+
"## Learning",
|
|
12146
|
+
"",
|
|
12147
|
+
"_Captured on completion: what was delivered, what stayed out of scope, outcome reached._",
|
|
12148
|
+
""
|
|
12149
|
+
].join("\n");
|
|
12150
|
+
}
|
|
12151
|
+
function buildInitiativeContent(id, input) {
|
|
12152
|
+
const status = input.status ?? "planned";
|
|
12153
|
+
if (!isValidInitiativeStatus(status)) {
|
|
12154
|
+
throw new InitiativeWriteError(`Invalid initiative status: ${status}.`);
|
|
12155
|
+
}
|
|
12156
|
+
const candidates = (input.candidates ?? []).map(
|
|
12157
|
+
(c, i) => normalizeCandidate(c, `WI-CANDIDATE-${String(i + 1).padStart(3, "0")}`)
|
|
12158
|
+
);
|
|
12159
|
+
const data = {
|
|
12160
|
+
type: "initiative",
|
|
12161
|
+
id,
|
|
12162
|
+
title: input.title.trim(),
|
|
12163
|
+
status,
|
|
12164
|
+
knowledge_level: input.knowledgeLevel ?? "K2",
|
|
12165
|
+
domains: input.domains ?? [],
|
|
12166
|
+
related_capabilities: input.relatedCapabilities ?? [],
|
|
12167
|
+
created_at: today(),
|
|
12168
|
+
external_links: (input.externalLinks ?? []).map(externalLinkToData),
|
|
12169
|
+
candidates: candidates.map(candidateToData)
|
|
12170
|
+
};
|
|
12171
|
+
if (input.horizon) data.horizon = input.horizon;
|
|
12172
|
+
if (input.priority) data.priority = input.priority;
|
|
12173
|
+
if (input.source) data.source = input.source;
|
|
12174
|
+
if (input.sourceId) data.source_id = input.sourceId;
|
|
12175
|
+
return matter11.stringify("\n" + (input.body ?? defaultBody(input.title.trim())), data);
|
|
12176
|
+
}
|
|
12177
|
+
function createInitiative(dir, input) {
|
|
12178
|
+
if (!input.title?.trim()) throw new InitiativeWriteError("Initiative title is required.");
|
|
12179
|
+
const id = nextInitiativeId(dir);
|
|
12180
|
+
const fileName = `${id}-${slugify3(input.title)}.md`;
|
|
12181
|
+
const iniDir = join(dir, INITIATIVES_DIR);
|
|
12182
|
+
ensureDir(iniDir);
|
|
12183
|
+
const filePath = join(iniDir, fileName);
|
|
12184
|
+
const content = buildInitiativeContent(id, input);
|
|
12185
|
+
writeFile(filePath, content);
|
|
12186
|
+
const ini = parseInitiative(dir, filePath, content);
|
|
12187
|
+
if (!ini) throw new InitiativeWriteError("Failed to parse the Initiative just written.");
|
|
12188
|
+
return ini;
|
|
12189
|
+
}
|
|
12190
|
+
function transitionInitiative(dir, id, to) {
|
|
12191
|
+
const ini = getInitiative(dir, id);
|
|
12192
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
12193
|
+
if (!isValidInitiativeStatus(to)) throw new InitiativeWriteError(`Invalid status: ${to}.`);
|
|
12194
|
+
if (ini.status === to) return ini;
|
|
12195
|
+
if (!isValidInitiativeTransition(ini.status, to)) {
|
|
12196
|
+
throw new InitiativeWriteError(`Invalid transition ${ini.status} \u2192 ${to}.`);
|
|
12197
|
+
}
|
|
12198
|
+
const raw = readFile(ini.filePath);
|
|
12199
|
+
const { data, content } = matter11(raw, {});
|
|
12200
|
+
data.status = to;
|
|
12201
|
+
if (to === "completed") data.completed_at = today();
|
|
12202
|
+
const newContent = matter11.stringify(content, data);
|
|
12203
|
+
writeFile(ini.filePath, newContent);
|
|
12204
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
12205
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after transition.");
|
|
12206
|
+
return updated;
|
|
12207
|
+
}
|
|
12208
|
+
function addCandidate(dir, id, candidate) {
|
|
12209
|
+
const ini = getInitiative(dir, id);
|
|
12210
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
12211
|
+
const raw = readFile(ini.filePath);
|
|
12212
|
+
const { data, content } = matter11(raw, {});
|
|
12213
|
+
const existing = Array.isArray(data.candidates) ? data.candidates : [];
|
|
12214
|
+
const fallbackId = `WI-CANDIDATE-${String(existing.length + 1).padStart(3, "0")}`;
|
|
12215
|
+
const normalized = normalizeCandidate(candidate, fallbackId);
|
|
12216
|
+
if (ini.candidates.some((c) => c.id === normalized.id)) {
|
|
12217
|
+
throw new InitiativeWriteError(`Candidate ${normalized.id} already exists in ${id}.`);
|
|
12218
|
+
}
|
|
12219
|
+
data.candidates = [...existing, candidateToData(normalized)];
|
|
12220
|
+
const newContent = matter11.stringify(content, data);
|
|
12221
|
+
writeFile(ini.filePath, newContent);
|
|
12222
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
12223
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after adding a candidate.");
|
|
12224
|
+
return updated;
|
|
12225
|
+
}
|
|
12226
|
+
function nextWorkItemId2(dir) {
|
|
12227
|
+
const wiDir = join(dir, WORK_ITEMS_DIR2);
|
|
12228
|
+
let max = 0;
|
|
12229
|
+
const walk = (d) => {
|
|
12230
|
+
if (!exists(d)) return;
|
|
12231
|
+
for (const entry of readDir(d)) {
|
|
12232
|
+
const full = join(d, entry);
|
|
12233
|
+
if (isFile(full)) {
|
|
12234
|
+
const m = entry.match(/WI-(\d+)/);
|
|
12235
|
+
if (m) max = Math.max(max, parseInt(m[1], 10));
|
|
12236
|
+
} else if (!entry.startsWith(".")) {
|
|
12237
|
+
walk(full);
|
|
12238
|
+
}
|
|
12239
|
+
}
|
|
12240
|
+
};
|
|
12241
|
+
walk(wiDir);
|
|
12242
|
+
return `WI-${String(max + 1).padStart(3, "0")}`;
|
|
12243
|
+
}
|
|
12244
|
+
function buildWorkItemContent(wiId, iniId, candidate) {
|
|
12245
|
+
const data = {
|
|
12246
|
+
type: candidate.type ?? "feature",
|
|
12247
|
+
id: wiId,
|
|
12248
|
+
title: candidate.title,
|
|
12249
|
+
knowledge_level: candidate.suggestedKnowledgeLevel ?? "K2",
|
|
12250
|
+
status: "draft",
|
|
12251
|
+
phase: "now",
|
|
12252
|
+
initiative: iniId,
|
|
12253
|
+
domains: [],
|
|
12254
|
+
code: [],
|
|
12255
|
+
created_at: today(),
|
|
12256
|
+
source: "initiative",
|
|
12257
|
+
source_id: candidate.id,
|
|
12258
|
+
source_initiative: iniId,
|
|
12259
|
+
affected_modules: []
|
|
12260
|
+
};
|
|
12261
|
+
if (candidate.sourceSignals.length) data.source_signals = candidate.sourceSignals;
|
|
12262
|
+
if (candidate.dependencies.length) data.dependencies = candidate.dependencies;
|
|
12263
|
+
const body = [
|
|
12264
|
+
`# ${candidate.title}`,
|
|
12265
|
+
"",
|
|
12266
|
+
`> Materialized from Initiative ${iniId}, candidate ${candidate.id}.`,
|
|
12267
|
+
"",
|
|
12268
|
+
"## Problem",
|
|
12269
|
+
"",
|
|
12270
|
+
candidate.expectedValue ? `_Expected value:_ ${candidate.expectedValue}` : "_Describe the problem._",
|
|
12271
|
+
"",
|
|
12272
|
+
"## Acceptance Criteria",
|
|
12273
|
+
"",
|
|
12274
|
+
"- [ ] _Define at least one testable criterion._",
|
|
12275
|
+
"",
|
|
12276
|
+
"## Out of scope",
|
|
12277
|
+
"",
|
|
12278
|
+
"_Not included in this Work Item._",
|
|
12279
|
+
"",
|
|
12280
|
+
"## Validation",
|
|
12281
|
+
"",
|
|
12282
|
+
"_How will this be validated?_",
|
|
12283
|
+
"",
|
|
12284
|
+
"## Learning",
|
|
12285
|
+
"",
|
|
12286
|
+
"_What did we learn? Update after completion._",
|
|
12287
|
+
""
|
|
12288
|
+
].join("\n");
|
|
12289
|
+
return matter11.stringify("\n" + body, data);
|
|
12290
|
+
}
|
|
12291
|
+
function materializeCandidate(dir, id, candidateId) {
|
|
12292
|
+
const ini = getInitiative(dir, id);
|
|
12293
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
12294
|
+
const candidate = ini.candidates.find((c) => c.id === candidateId);
|
|
12295
|
+
if (!candidate) throw new InitiativeWriteError(`Candidate ${candidateId} not found in ${id}.`);
|
|
12296
|
+
if (candidate.materializedAs) {
|
|
12297
|
+
throw new InitiativeWriteError(
|
|
12298
|
+
`Candidate ${candidateId} is already materialized as ${candidate.materializedAs}.`
|
|
12299
|
+
);
|
|
12300
|
+
}
|
|
12301
|
+
const wiId = nextWorkItemId2(dir);
|
|
12302
|
+
const fileName = `${wiId}-${slugify3(candidate.title)}.md`;
|
|
12303
|
+
ensureDir(join(dir, DRAFT_DIR));
|
|
12304
|
+
writeFile(join(dir, DRAFT_DIR, fileName), buildWorkItemContent(wiId, ini.id, candidate));
|
|
12305
|
+
const raw = readFile(ini.filePath);
|
|
12306
|
+
const { data, content } = matter11(raw, {});
|
|
12307
|
+
const cands = Array.isArray(data.candidates) ? data.candidates : [];
|
|
12308
|
+
for (const c of cands) {
|
|
12309
|
+
if (c && typeof c === "object" && String(c.id) === candidateId) c.materialized_as = wiId;
|
|
12310
|
+
}
|
|
12311
|
+
data.candidates = cands;
|
|
12312
|
+
const newContent = matter11.stringify(content, data);
|
|
12313
|
+
writeFile(ini.filePath, newContent);
|
|
12314
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
12315
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after materialization.");
|
|
12316
|
+
return { workItemId: wiId, fileName, initiative: updated };
|
|
12317
|
+
}
|
|
12318
|
+
function materializeRoadmapInitiative(dir, rmId) {
|
|
12319
|
+
const roadmapFull = join(dir, ROADMAP_PATH2);
|
|
12320
|
+
if (!exists(roadmapFull)) throw new InitiativeWriteError(`No roadmap found at ${ROADMAP_PATH2}.`);
|
|
12321
|
+
const all = parseRoadmapCandidates(readFile(roadmapFull));
|
|
12322
|
+
const want = rmId.trim().toLowerCase();
|
|
12323
|
+
const belonging = all.filter((c) => (c.initiative?.id ?? "").toLowerCase() === want);
|
|
12324
|
+
if (belonging.length === 0) {
|
|
12325
|
+
throw new InitiativeWriteError(`No roadmap initiative "${rmId}" with candidates found.`);
|
|
12326
|
+
}
|
|
12327
|
+
const title = belonging[0].initiative?.title?.trim() || rmId;
|
|
12328
|
+
const candidates = belonging.map((c) => ({
|
|
12329
|
+
id: c.id,
|
|
12330
|
+
title: c.title,
|
|
12331
|
+
type: c.type,
|
|
12332
|
+
suggestedKnowledgeLevel: c.suggestedKnowledgeLevel,
|
|
12333
|
+
expectedValue: c.expectedValue,
|
|
12334
|
+
notes: c.notes,
|
|
12335
|
+
sourceSignals: c.sourceSignals ?? [],
|
|
12336
|
+
dependencies: c.dependencies ?? [],
|
|
12337
|
+
materializedAs: null
|
|
12338
|
+
}));
|
|
12339
|
+
const domains = belonging[0].domain ? [belonging[0].domain] : [];
|
|
12340
|
+
const relatedCapabilities = Array.from(
|
|
12341
|
+
new Set(belonging.flatMap((c) => c.relatedCapabilities ?? []))
|
|
12342
|
+
);
|
|
12343
|
+
return createInitiative(dir, {
|
|
12344
|
+
title,
|
|
12345
|
+
status: "planned",
|
|
12346
|
+
domains,
|
|
12347
|
+
relatedCapabilities,
|
|
12348
|
+
source: "roadmap",
|
|
12349
|
+
sourceId: rmId,
|
|
12350
|
+
candidates
|
|
12351
|
+
});
|
|
12352
|
+
}
|
|
11774
12353
|
export {
|
|
12354
|
+
CURRENT_CONSENT_VERSION,
|
|
12355
|
+
INITIATIVES_DIR,
|
|
12356
|
+
INITIATIVE_STATES,
|
|
12357
|
+
INITIATIVE_TRANSITIONS,
|
|
11775
12358
|
INTEGRATIONS_FILE,
|
|
11776
12359
|
ImportError,
|
|
12360
|
+
InitiativeWriteError,
|
|
11777
12361
|
IntegrationError,
|
|
11778
12362
|
IntegrationServiceError,
|
|
11779
12363
|
TOPOLOGY_FILE,
|
|
@@ -11782,9 +12366,11 @@ export {
|
|
|
11782
12366
|
WorkItemNotInProgressError,
|
|
11783
12367
|
WorkItemNotReadyError,
|
|
11784
12368
|
WorkItemWriteError,
|
|
12369
|
+
addCandidate,
|
|
11785
12370
|
analyzeCrossRepoEvidence,
|
|
11786
12371
|
analyzeScopeCoverage,
|
|
11787
12372
|
applyTopologyProposal,
|
|
12373
|
+
associatedWorkItems,
|
|
11788
12374
|
buildImplementationHandoff,
|
|
11789
12375
|
buildImportIndex,
|
|
11790
12376
|
buildProjectExplanation,
|
|
@@ -11794,14 +12380,19 @@ export {
|
|
|
11794
12380
|
buildTopologyEnrichmentHandoff,
|
|
11795
12381
|
collectImplementationEvidence,
|
|
11796
12382
|
computeContentHash,
|
|
12383
|
+
computeInitiativeProgress,
|
|
11797
12384
|
computeRefinementStatus,
|
|
12385
|
+
consentNotice,
|
|
12386
|
+
createInitiative,
|
|
11798
12387
|
createIntegration,
|
|
11799
12388
|
createWorkItem,
|
|
11800
12389
|
cwd,
|
|
12390
|
+
deferConsent,
|
|
11801
12391
|
deleteIntegration,
|
|
11802
12392
|
detectFormat,
|
|
11803
12393
|
disableIntegration,
|
|
11804
12394
|
discoverExternalWorkItems,
|
|
12395
|
+
discoverInitiatives,
|
|
11805
12396
|
discoverKnowledge,
|
|
11806
12397
|
discoverWorkItems,
|
|
11807
12398
|
enableIntegration,
|
|
@@ -11813,14 +12404,17 @@ export {
|
|
|
11813
12404
|
findLinkedWorkItem,
|
|
11814
12405
|
findSystemPaths,
|
|
11815
12406
|
getAvailableIntegrationTypes,
|
|
12407
|
+
getConsentState,
|
|
11816
12408
|
getExternalWorkItem,
|
|
11817
12409
|
getImpactCandidates,
|
|
12410
|
+
getInitiative,
|
|
11818
12411
|
getIntegration,
|
|
11819
12412
|
getIntegrationFilters,
|
|
11820
12413
|
getIntegrationSecretStatus,
|
|
11821
12414
|
getSystemMapProjection,
|
|
11822
12415
|
getSystemNeighbors,
|
|
11823
12416
|
getSystemNodeContext,
|
|
12417
|
+
getStatus as getTelemetryStatus,
|
|
11824
12418
|
getWorkItem,
|
|
11825
12419
|
getWorkItemCaptureDefinition,
|
|
11826
12420
|
getWorkItemForEdit,
|
|
@@ -11830,7 +12424,12 @@ export {
|
|
|
11830
12424
|
importWorkItem,
|
|
11831
12425
|
integrationRegistry,
|
|
11832
12426
|
isActiveState,
|
|
12427
|
+
isDeferralActive,
|
|
12428
|
+
isInteractive,
|
|
11833
12429
|
isModule,
|
|
12430
|
+
isEnabled as isTelemetryEnabled,
|
|
12431
|
+
isValidInitiativeStatus,
|
|
12432
|
+
isValidInitiativeTransition,
|
|
11834
12433
|
join,
|
|
11835
12434
|
knowledgeLayers,
|
|
11836
12435
|
lifecycleCounts,
|
|
@@ -11840,13 +12439,19 @@ export {
|
|
|
11840
12439
|
loadConfig,
|
|
11841
12440
|
loadMappedModules,
|
|
11842
12441
|
loadSystemTopology,
|
|
12442
|
+
materializeCandidate,
|
|
12443
|
+
materializeRoadmapInitiative,
|
|
12444
|
+
nextInitiativeId,
|
|
11843
12445
|
parseContent,
|
|
12446
|
+
parseInitiative,
|
|
12447
|
+
persistConsent,
|
|
11844
12448
|
previewImport,
|
|
11845
12449
|
readFile,
|
|
11846
12450
|
removeIntegrationSecret,
|
|
11847
12451
|
searchSystemNodes,
|
|
11848
12452
|
setIntegrationSecret,
|
|
11849
12453
|
topologyRevision,
|
|
12454
|
+
transitionInitiative,
|
|
11850
12455
|
transitionWorkItem,
|
|
11851
12456
|
updateIntegration,
|
|
11852
12457
|
updateIntegrationFilters,
|
|
@@ -11856,5 +12461,6 @@ export {
|
|
|
11856
12461
|
validateTopologyProposal,
|
|
11857
12462
|
validateWorkItem,
|
|
11858
12463
|
verifyIntegration,
|
|
11859
|
-
verifyWorkItem
|
|
12464
|
+
verifyWorkItem,
|
|
12465
|
+
workItemBelongsToInitiative
|
|
11860
12466
|
};
|