@kaddo/cli 3.105.0 → 3.106.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 +46 -0
- package/dist/index.js +593 -10
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -12058,6 +12058,30 @@ function computeInitiativeProgress(dir, ini) {
|
|
|
12058
12058
|
}
|
|
12059
12059
|
};
|
|
12060
12060
|
}
|
|
12061
|
+
function getInitiativeContext(dir, ini) {
|
|
12062
|
+
return {
|
|
12063
|
+
initiative: {
|
|
12064
|
+
id: ini.id,
|
|
12065
|
+
title: ini.title,
|
|
12066
|
+
status: ini.status,
|
|
12067
|
+
horizon: ini.horizon,
|
|
12068
|
+
priority: ini.priority,
|
|
12069
|
+
knowledgeLevel: ini.knowledgeLevel,
|
|
12070
|
+
domains: ini.domains,
|
|
12071
|
+
relatedCapabilities: ini.relatedCapabilities,
|
|
12072
|
+
source: ini.source,
|
|
12073
|
+
sourceId: ini.sourceId
|
|
12074
|
+
},
|
|
12075
|
+
progress: computeInitiativeProgress(dir, ini),
|
|
12076
|
+
candidates: {
|
|
12077
|
+
total: ini.candidates.length,
|
|
12078
|
+
materialized: ini.candidates.filter((c) => c.materializedAs),
|
|
12079
|
+
pending: ini.candidates.filter((c) => !c.materializedAs)
|
|
12080
|
+
},
|
|
12081
|
+
workItems: associatedWorkItems(dir, ini.id),
|
|
12082
|
+
externalLinks: ini.externalLinks
|
|
12083
|
+
};
|
|
12084
|
+
}
|
|
12061
12085
|
|
|
12062
12086
|
// src/core/initiative-write.ts
|
|
12063
12087
|
import matter11 from "gray-matter";
|
|
@@ -12223,6 +12247,26 @@ function addCandidate(dir, id, candidate) {
|
|
|
12223
12247
|
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after adding a candidate.");
|
|
12224
12248
|
return updated;
|
|
12225
12249
|
}
|
|
12250
|
+
function updateInitiative(dir, id, patch) {
|
|
12251
|
+
const ini = getInitiative(dir, id);
|
|
12252
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
12253
|
+
const raw = readFile(ini.filePath);
|
|
12254
|
+
const { data, content } = matter11(raw, {});
|
|
12255
|
+
if (patch.title !== void 0) {
|
|
12256
|
+
if (!patch.title.trim()) throw new InitiativeWriteError("Initiative title cannot be empty.");
|
|
12257
|
+
data.title = patch.title.trim();
|
|
12258
|
+
}
|
|
12259
|
+
if (patch.horizon !== void 0) data.horizon = patch.horizon;
|
|
12260
|
+
if (patch.priority !== void 0) data.priority = patch.priority;
|
|
12261
|
+
if (patch.knowledgeLevel !== void 0) data.knowledge_level = patch.knowledgeLevel;
|
|
12262
|
+
if (patch.domains !== void 0) data.domains = patch.domains;
|
|
12263
|
+
if (patch.relatedCapabilities !== void 0) data.related_capabilities = patch.relatedCapabilities;
|
|
12264
|
+
const newContent = matter11.stringify(content, data);
|
|
12265
|
+
writeFile(ini.filePath, newContent);
|
|
12266
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
12267
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after update.");
|
|
12268
|
+
return updated;
|
|
12269
|
+
}
|
|
12226
12270
|
function nextWorkItemId2(dir) {
|
|
12227
12271
|
const wiDir = join(dir, WORK_ITEMS_DIR2);
|
|
12228
12272
|
let max = 0;
|
|
@@ -12408,6 +12452,7 @@ export {
|
|
|
12408
12452
|
getExternalWorkItem,
|
|
12409
12453
|
getImpactCandidates,
|
|
12410
12454
|
getInitiative,
|
|
12455
|
+
getInitiativeContext,
|
|
12411
12456
|
getIntegration,
|
|
12412
12457
|
getIntegrationFilters,
|
|
12413
12458
|
getIntegrationSecretStatus,
|
|
@@ -12453,6 +12498,7 @@ export {
|
|
|
12453
12498
|
topologyRevision,
|
|
12454
12499
|
transitionInitiative,
|
|
12455
12500
|
transitionWorkItem,
|
|
12501
|
+
updateInitiative,
|
|
12456
12502
|
updateIntegration,
|
|
12457
12503
|
updateIntegrationFilters,
|
|
12458
12504
|
updateWorkItem,
|
package/dist/index.js
CHANGED
|
@@ -6247,7 +6247,7 @@ function formatList(items) {
|
|
|
6247
6247
|
return items.map((i) => `- ${i.trim()}`).join("\n");
|
|
6248
6248
|
}
|
|
6249
6249
|
function buildFrontMatter(id, type, level, title, answers) {
|
|
6250
|
-
const
|
|
6250
|
+
const today3 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
6251
6251
|
const lines = [
|
|
6252
6252
|
"---",
|
|
6253
6253
|
`type: ${type}`,
|
|
@@ -6260,7 +6260,7 @@ function buildFrontMatter(id, type, level, title, answers) {
|
|
|
6260
6260
|
`initiative:`,
|
|
6261
6261
|
`domains: []`,
|
|
6262
6262
|
`code: []`,
|
|
6263
|
-
`created_at: ${
|
|
6263
|
+
`created_at: ${today3}`,
|
|
6264
6264
|
`source:`,
|
|
6265
6265
|
` type: manual`,
|
|
6266
6266
|
` inferred: false`,
|
|
@@ -6335,7 +6335,7 @@ _What did we learn from this change? Update after completion._
|
|
|
6335
6335
|
return sections.join("\n");
|
|
6336
6336
|
}
|
|
6337
6337
|
function buildModuleFrontMatter(id, modType, title, answers) {
|
|
6338
|
-
const
|
|
6338
|
+
const today3 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
6339
6339
|
const extra = modType.extraFrontMatter ?? {};
|
|
6340
6340
|
const extraLines = Object.entries(extra).map(
|
|
6341
6341
|
([k, v]) => `${k}: ${JSON.stringify(v)}`
|
|
@@ -6351,7 +6351,7 @@ function buildModuleFrontMatter(id, modType, title, answers) {
|
|
|
6351
6351
|
`initiative:`,
|
|
6352
6352
|
`domains: []`,
|
|
6353
6353
|
`code: []`,
|
|
6354
|
-
`created_at: ${
|
|
6354
|
+
`created_at: ${today3}`,
|
|
6355
6355
|
`source: manual`,
|
|
6356
6356
|
`summary: "${title}"`,
|
|
6357
6357
|
...extraLines,
|
|
@@ -6499,7 +6499,7 @@ function resolveCandidateLevel(candidate, type) {
|
|
|
6499
6499
|
return getLevelForType(type);
|
|
6500
6500
|
}
|
|
6501
6501
|
function buildRoadmapFrontMatter(id, type, level, title, candidate, answers) {
|
|
6502
|
-
const
|
|
6502
|
+
const today3 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
6503
6503
|
const summary = (answers.problem?.split(".")[0] ?? candidate.expectedValue ?? title).trim();
|
|
6504
6504
|
const initiative = candidate.initiative?.title ?? candidate.initiative?.id ?? "";
|
|
6505
6505
|
const q = (s) => s.replace(/"/g, "'");
|
|
@@ -6522,7 +6522,7 @@ function buildRoadmapFrontMatter(id, type, level, title, candidate, answers) {
|
|
|
6522
6522
|
...yamlList2("domains", domains),
|
|
6523
6523
|
...domains.length === 0 ? ["domains: []"] : [],
|
|
6524
6524
|
`code: []`,
|
|
6525
|
-
`created_at: ${
|
|
6525
|
+
`created_at: ${today3}`,
|
|
6526
6526
|
`source: roadmap`,
|
|
6527
6527
|
`source_id: ${candidate.id}`,
|
|
6528
6528
|
`source_initiative: ${candidate.initiative?.id ?? "unknown"}`,
|
|
@@ -17924,7 +17924,7 @@ function createWorkItem(dir, opts) {
|
|
|
17924
17924
|
if (!type) throw new WorkItemWriteError("INVALID_INPUT", `Unknown Work Item type "${opts.type}".`);
|
|
17925
17925
|
const id = nextWorkItemId2(dir);
|
|
17926
17926
|
const title = intent.split(/\r?\n/)[0].trim().slice(0, 120);
|
|
17927
|
-
const
|
|
17927
|
+
const today3 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
17928
17928
|
const source = opts.source ? { ...opts.source, inferred: false } : { type: "manual", inferred: false };
|
|
17929
17929
|
const data = {
|
|
17930
17930
|
type,
|
|
@@ -17932,7 +17932,7 @@ function createWorkItem(dir, opts) {
|
|
|
17932
17932
|
title,
|
|
17933
17933
|
status: "draft",
|
|
17934
17934
|
work_type: type,
|
|
17935
|
-
created_at:
|
|
17935
|
+
created_at: today3,
|
|
17936
17936
|
source,
|
|
17937
17937
|
generated_by: "kaddo-admin",
|
|
17938
17938
|
affected_modules: [],
|
|
@@ -20481,9 +20481,9 @@ function isResolvedSection(text2) {
|
|
|
20481
20481
|
function transitionToReady(filePath) {
|
|
20482
20482
|
const raw = readFile(filePath);
|
|
20483
20483
|
const { data, content } = matter13(raw);
|
|
20484
|
-
const
|
|
20484
|
+
const today3 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
20485
20485
|
data.status = "ready";
|
|
20486
|
-
data.ready_at =
|
|
20486
|
+
data.ready_at = today3;
|
|
20487
20487
|
const newContent = matter13.stringify(content, data);
|
|
20488
20488
|
const posix = filePath.replace(/\\/g, "/");
|
|
20489
20489
|
let newPath = filePath;
|
|
@@ -22292,6 +22292,567 @@ function runTelemetryDisable() {
|
|
|
22292
22292
|
outro("Run `kaddo telemetry enable` to re-enable.");
|
|
22293
22293
|
}
|
|
22294
22294
|
|
|
22295
|
+
// src/core/initiative.ts
|
|
22296
|
+
import matter17 from "gray-matter";
|
|
22297
|
+
var INITIATIVES_DIR = "knowledge/delivery/initiatives";
|
|
22298
|
+
var INITIATIVE_STATES = [
|
|
22299
|
+
"candidate",
|
|
22300
|
+
"planned",
|
|
22301
|
+
"in-progress",
|
|
22302
|
+
"completed",
|
|
22303
|
+
"deferred",
|
|
22304
|
+
"cancelled"
|
|
22305
|
+
];
|
|
22306
|
+
var INITIATIVE_TRANSITIONS = {
|
|
22307
|
+
candidate: ["planned", "cancelled"],
|
|
22308
|
+
planned: ["in-progress", "deferred", "cancelled"],
|
|
22309
|
+
"in-progress": ["completed", "deferred", "cancelled"],
|
|
22310
|
+
deferred: ["planned", "cancelled"],
|
|
22311
|
+
completed: [],
|
|
22312
|
+
cancelled: []
|
|
22313
|
+
};
|
|
22314
|
+
var STATUS_SET = new Set(INITIATIVE_STATES);
|
|
22315
|
+
function isValidInitiativeStatus(s) {
|
|
22316
|
+
return STATUS_SET.has(s);
|
|
22317
|
+
}
|
|
22318
|
+
function isValidInitiativeTransition(from, to) {
|
|
22319
|
+
return INITIATIVE_TRANSITIONS[from].includes(to);
|
|
22320
|
+
}
|
|
22321
|
+
function toPosix6(p) {
|
|
22322
|
+
return p.replace(/\\/g, "/");
|
|
22323
|
+
}
|
|
22324
|
+
function optStr3(v) {
|
|
22325
|
+
if (typeof v === "string" && v.trim()) return v.trim();
|
|
22326
|
+
if (typeof v === "number") return String(v);
|
|
22327
|
+
return void 0;
|
|
22328
|
+
}
|
|
22329
|
+
function strList2(v) {
|
|
22330
|
+
if (!Array.isArray(v)) return [];
|
|
22331
|
+
return v.map((x) => typeof x === "string" ? x.trim() : String(x)).filter(Boolean);
|
|
22332
|
+
}
|
|
22333
|
+
function parseCandidates(data) {
|
|
22334
|
+
const raw = data.candidates;
|
|
22335
|
+
if (!Array.isArray(raw)) return [];
|
|
22336
|
+
const out = [];
|
|
22337
|
+
for (const entry of raw) {
|
|
22338
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
22339
|
+
const o = entry;
|
|
22340
|
+
const id = optStr3(o.id);
|
|
22341
|
+
const title = optStr3(o.title);
|
|
22342
|
+
if (!id || !title) continue;
|
|
22343
|
+
out.push({
|
|
22344
|
+
id,
|
|
22345
|
+
title,
|
|
22346
|
+
type: optStr3(o.type),
|
|
22347
|
+
suggestedKnowledgeLevel: optStr3(o.suggested_knowledge_level ?? o.knowledge_level),
|
|
22348
|
+
expectedValue: optStr3(o.expected_value),
|
|
22349
|
+
notes: optStr3(o.notes),
|
|
22350
|
+
sourceSignals: strList2(o.source_signals),
|
|
22351
|
+
dependencies: strList2(o.dependencies),
|
|
22352
|
+
materializedAs: optStr3(o.materialized_as) ?? null
|
|
22353
|
+
});
|
|
22354
|
+
}
|
|
22355
|
+
return out;
|
|
22356
|
+
}
|
|
22357
|
+
function parseExternalLinks(data) {
|
|
22358
|
+
const raw = data.external_links;
|
|
22359
|
+
if (!Array.isArray(raw)) return [];
|
|
22360
|
+
const out = [];
|
|
22361
|
+
for (const entry of raw) {
|
|
22362
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
22363
|
+
const o = entry;
|
|
22364
|
+
const integration = optStr3(o.integration);
|
|
22365
|
+
const externalId = optStr3(o.external_id);
|
|
22366
|
+
if (!integration || !externalId) continue;
|
|
22367
|
+
out.push({
|
|
22368
|
+
integration,
|
|
22369
|
+
externalId,
|
|
22370
|
+
externalType: optStr3(o.external_type),
|
|
22371
|
+
url: optStr3(o.url)
|
|
22372
|
+
});
|
|
22373
|
+
}
|
|
22374
|
+
return out;
|
|
22375
|
+
}
|
|
22376
|
+
function parseInitiative(dir, filePath, raw) {
|
|
22377
|
+
let parsed;
|
|
22378
|
+
try {
|
|
22379
|
+
parsed = matter17(raw, {});
|
|
22380
|
+
} catch {
|
|
22381
|
+
return null;
|
|
22382
|
+
}
|
|
22383
|
+
const data = parsed.data;
|
|
22384
|
+
if (optStr3(data.type) !== "initiative") return null;
|
|
22385
|
+
const id = optStr3(data.id);
|
|
22386
|
+
if (!id) return null;
|
|
22387
|
+
const statusRaw = optStr3(data.status) ?? "planned";
|
|
22388
|
+
const status = isValidInitiativeStatus(statusRaw) ? statusRaw : "planned";
|
|
22389
|
+
return {
|
|
22390
|
+
id,
|
|
22391
|
+
title: optStr3(data.title) ?? id,
|
|
22392
|
+
status,
|
|
22393
|
+
horizon: optStr3(data.horizon) ?? null,
|
|
22394
|
+
priority: optStr3(data.priority) ?? null,
|
|
22395
|
+
knowledgeLevel: optStr3(data.knowledge_level) ?? null,
|
|
22396
|
+
domains: strList2(data.domains),
|
|
22397
|
+
relatedCapabilities: strList2(data.related_capabilities),
|
|
22398
|
+
source: optStr3(data.source) ?? null,
|
|
22399
|
+
sourceId: optStr3(data.source_id) ?? null,
|
|
22400
|
+
createdAt: optStr3(data.created_at) ?? null,
|
|
22401
|
+
externalLinks: parseExternalLinks(data),
|
|
22402
|
+
candidates: parseCandidates(data),
|
|
22403
|
+
filePath,
|
|
22404
|
+
relPath: toPosix6(filePath).startsWith(toPosix6(dir) + "/") ? toPosix6(filePath).slice(toPosix6(dir).length + 1) : toPosix6(filePath),
|
|
22405
|
+
body: parsed.content.trim(),
|
|
22406
|
+
rawFrontmatter: data
|
|
22407
|
+
};
|
|
22408
|
+
}
|
|
22409
|
+
function discoverInitiatives(dir) {
|
|
22410
|
+
const iniDir = join(dir, INITIATIVES_DIR);
|
|
22411
|
+
if (!exists(iniDir)) return [];
|
|
22412
|
+
const out = [];
|
|
22413
|
+
for (const entry of readDir(iniDir)) {
|
|
22414
|
+
if (!entry.endsWith(".md")) continue;
|
|
22415
|
+
const full = join(iniDir, entry);
|
|
22416
|
+
if (!isFile(full)) continue;
|
|
22417
|
+
const ini = parseInitiative(dir, full, readFile(full));
|
|
22418
|
+
if (ini) out.push(ini);
|
|
22419
|
+
}
|
|
22420
|
+
return out.sort((a, b) => a.id.localeCompare(b.id));
|
|
22421
|
+
}
|
|
22422
|
+
function getInitiative(dir, id) {
|
|
22423
|
+
const want = id.trim().toLowerCase();
|
|
22424
|
+
return discoverInitiatives(dir).find((i) => i.id.toLowerCase() === want) ?? null;
|
|
22425
|
+
}
|
|
22426
|
+
function nextInitiativeId(dir) {
|
|
22427
|
+
const iniDir = join(dir, INITIATIVES_DIR);
|
|
22428
|
+
let max = 0;
|
|
22429
|
+
if (exists(iniDir)) {
|
|
22430
|
+
for (const entry of readDir(iniDir)) {
|
|
22431
|
+
const m = entry.match(/INI-(\d+)/);
|
|
22432
|
+
if (m) max = Math.max(max, parseInt(m[1], 10));
|
|
22433
|
+
}
|
|
22434
|
+
}
|
|
22435
|
+
return `INI-${String(max + 1).padStart(3, "0")}`;
|
|
22436
|
+
}
|
|
22437
|
+
function workItemBelongsToInitiative(workItemInitiative, iniId) {
|
|
22438
|
+
const v = (workItemInitiative ?? "").trim().toLowerCase();
|
|
22439
|
+
return v !== "" && v === iniId.trim().toLowerCase();
|
|
22440
|
+
}
|
|
22441
|
+
function associatedWorkItems(dir, iniId) {
|
|
22442
|
+
return discoverWorkItems(dir).filter((wi) => workItemBelongsToInitiative(wi.initiative, iniId)).map((wi) => ({
|
|
22443
|
+
id: wi.id,
|
|
22444
|
+
title: wi.title,
|
|
22445
|
+
status: wi.lifecycle ?? "ready"
|
|
22446
|
+
})).sort((a, b) => a.id.localeCompare(b.id));
|
|
22447
|
+
}
|
|
22448
|
+
function computeInitiativeProgress(dir, ini) {
|
|
22449
|
+
const totalCandidates = ini.candidates.length;
|
|
22450
|
+
const materialized = ini.candidates.filter((c) => c.materializedAs).length;
|
|
22451
|
+
const byState = emptyLifecycleCounts();
|
|
22452
|
+
const associated = associatedWorkItems(dir, ini.id);
|
|
22453
|
+
for (const wi of associated) byState[wi.status]++;
|
|
22454
|
+
return {
|
|
22455
|
+
initiative: ini.id,
|
|
22456
|
+
status: ini.status,
|
|
22457
|
+
planning: {
|
|
22458
|
+
totalCandidates,
|
|
22459
|
+
materialized,
|
|
22460
|
+
remaining: Math.max(0, totalCandidates - materialized)
|
|
22461
|
+
},
|
|
22462
|
+
delivery: {
|
|
22463
|
+
total: associated.length,
|
|
22464
|
+
byState
|
|
22465
|
+
}
|
|
22466
|
+
};
|
|
22467
|
+
}
|
|
22468
|
+
|
|
22469
|
+
// src/core/initiative-write.ts
|
|
22470
|
+
import matter18 from "gray-matter";
|
|
22471
|
+
var WORK_ITEMS_DIR4 = "knowledge/delivery/work-items";
|
|
22472
|
+
var DRAFT_DIR2 = `${WORK_ITEMS_DIR4}/draft`;
|
|
22473
|
+
var InitiativeWriteError = class extends Error {
|
|
22474
|
+
constructor(message) {
|
|
22475
|
+
super(message);
|
|
22476
|
+
this.name = "InitiativeWriteError";
|
|
22477
|
+
}
|
|
22478
|
+
};
|
|
22479
|
+
function slugify6(s) {
|
|
22480
|
+
return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 50);
|
|
22481
|
+
}
|
|
22482
|
+
function today2() {
|
|
22483
|
+
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
22484
|
+
}
|
|
22485
|
+
function candidateToData(c) {
|
|
22486
|
+
const out = { id: c.id, title: c.title };
|
|
22487
|
+
if (c.type) out.type = c.type;
|
|
22488
|
+
if (c.suggestedKnowledgeLevel) out.suggested_knowledge_level = c.suggestedKnowledgeLevel;
|
|
22489
|
+
if (c.expectedValue) out.expected_value = c.expectedValue;
|
|
22490
|
+
if (c.notes) out.notes = c.notes;
|
|
22491
|
+
if (c.sourceSignals.length) out.source_signals = c.sourceSignals;
|
|
22492
|
+
if (c.dependencies.length) out.dependencies = c.dependencies;
|
|
22493
|
+
if (c.materializedAs) out.materialized_as = c.materializedAs;
|
|
22494
|
+
return out;
|
|
22495
|
+
}
|
|
22496
|
+
function externalLinkToData(l) {
|
|
22497
|
+
const out = { integration: l.integration, external_id: l.externalId };
|
|
22498
|
+
if (l.externalType) out.external_type = l.externalType;
|
|
22499
|
+
if (l.url) out.url = l.url;
|
|
22500
|
+
return out;
|
|
22501
|
+
}
|
|
22502
|
+
function normalizeCandidate(input, fallbackId) {
|
|
22503
|
+
return {
|
|
22504
|
+
id: input.id?.trim() || fallbackId,
|
|
22505
|
+
title: input.title.trim(),
|
|
22506
|
+
type: input.type?.trim() || void 0,
|
|
22507
|
+
suggestedKnowledgeLevel: input.suggestedKnowledgeLevel?.trim() || void 0,
|
|
22508
|
+
expectedValue: input.expectedValue?.trim() || void 0,
|
|
22509
|
+
notes: input.notes?.trim() || void 0,
|
|
22510
|
+
sourceSignals: input.sourceSignals ?? [],
|
|
22511
|
+
dependencies: input.dependencies ?? [],
|
|
22512
|
+
materializedAs: input.materializedAs ?? null
|
|
22513
|
+
};
|
|
22514
|
+
}
|
|
22515
|
+
function defaultBody(title) {
|
|
22516
|
+
return [
|
|
22517
|
+
`# ${title}`,
|
|
22518
|
+
"",
|
|
22519
|
+
"## Goal",
|
|
22520
|
+
"",
|
|
22521
|
+
"_What outcome does this Initiative pursue?_",
|
|
22522
|
+
"",
|
|
22523
|
+
"## Expected Value",
|
|
22524
|
+
"",
|
|
22525
|
+
"_Why it matters._",
|
|
22526
|
+
"",
|
|
22527
|
+
"## Scope",
|
|
22528
|
+
"",
|
|
22529
|
+
"_What this Initiative covers._",
|
|
22530
|
+
"",
|
|
22531
|
+
"## Out of Scope",
|
|
22532
|
+
"",
|
|
22533
|
+
"_What it explicitly does not cover._",
|
|
22534
|
+
"",
|
|
22535
|
+
"## Success Criteria",
|
|
22536
|
+
"",
|
|
22537
|
+
'_Observable outcomes that define completion (not just "all Work Items done")._',
|
|
22538
|
+
"",
|
|
22539
|
+
"## Dependencies",
|
|
22540
|
+
"",
|
|
22541
|
+
"_Other Initiatives, modules, or external work this depends on._",
|
|
22542
|
+
"",
|
|
22543
|
+
"## Work Item Candidates",
|
|
22544
|
+
"",
|
|
22545
|
+
"_Candidates live in frontmatter `candidates`; summarize them here as they evolve._",
|
|
22546
|
+
"",
|
|
22547
|
+
"## Open Questions",
|
|
22548
|
+
"",
|
|
22549
|
+
"_Unresolved questions for this Initiative._",
|
|
22550
|
+
"",
|
|
22551
|
+
"## Learning",
|
|
22552
|
+
"",
|
|
22553
|
+
"_Captured on completion: what was delivered, what stayed out of scope, outcome reached._",
|
|
22554
|
+
""
|
|
22555
|
+
].join("\n");
|
|
22556
|
+
}
|
|
22557
|
+
function buildInitiativeContent(id, input) {
|
|
22558
|
+
const status = input.status ?? "planned";
|
|
22559
|
+
if (!isValidInitiativeStatus(status)) {
|
|
22560
|
+
throw new InitiativeWriteError(`Invalid initiative status: ${status}.`);
|
|
22561
|
+
}
|
|
22562
|
+
const candidates = (input.candidates ?? []).map(
|
|
22563
|
+
(c, i) => normalizeCandidate(c, `WI-CANDIDATE-${String(i + 1).padStart(3, "0")}`)
|
|
22564
|
+
);
|
|
22565
|
+
const data = {
|
|
22566
|
+
type: "initiative",
|
|
22567
|
+
id,
|
|
22568
|
+
title: input.title.trim(),
|
|
22569
|
+
status,
|
|
22570
|
+
knowledge_level: input.knowledgeLevel ?? "K2",
|
|
22571
|
+
domains: input.domains ?? [],
|
|
22572
|
+
related_capabilities: input.relatedCapabilities ?? [],
|
|
22573
|
+
created_at: today2(),
|
|
22574
|
+
external_links: (input.externalLinks ?? []).map(externalLinkToData),
|
|
22575
|
+
candidates: candidates.map(candidateToData)
|
|
22576
|
+
};
|
|
22577
|
+
if (input.horizon) data.horizon = input.horizon;
|
|
22578
|
+
if (input.priority) data.priority = input.priority;
|
|
22579
|
+
if (input.source) data.source = input.source;
|
|
22580
|
+
if (input.sourceId) data.source_id = input.sourceId;
|
|
22581
|
+
return matter18.stringify("\n" + (input.body ?? defaultBody(input.title.trim())), data);
|
|
22582
|
+
}
|
|
22583
|
+
function createInitiative(dir, input) {
|
|
22584
|
+
if (!input.title?.trim()) throw new InitiativeWriteError("Initiative title is required.");
|
|
22585
|
+
const id = nextInitiativeId(dir);
|
|
22586
|
+
const fileName = `${id}-${slugify6(input.title)}.md`;
|
|
22587
|
+
const iniDir = join(dir, INITIATIVES_DIR);
|
|
22588
|
+
ensureDir(iniDir);
|
|
22589
|
+
const filePath = join(iniDir, fileName);
|
|
22590
|
+
const content = buildInitiativeContent(id, input);
|
|
22591
|
+
writeFile(filePath, content);
|
|
22592
|
+
const ini = parseInitiative(dir, filePath, content);
|
|
22593
|
+
if (!ini) throw new InitiativeWriteError("Failed to parse the Initiative just written.");
|
|
22594
|
+
return ini;
|
|
22595
|
+
}
|
|
22596
|
+
function transitionInitiative(dir, id, to) {
|
|
22597
|
+
const ini = getInitiative(dir, id);
|
|
22598
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
22599
|
+
if (!isValidInitiativeStatus(to)) throw new InitiativeWriteError(`Invalid status: ${to}.`);
|
|
22600
|
+
if (ini.status === to) return ini;
|
|
22601
|
+
if (!isValidInitiativeTransition(ini.status, to)) {
|
|
22602
|
+
throw new InitiativeWriteError(`Invalid transition ${ini.status} \u2192 ${to}.`);
|
|
22603
|
+
}
|
|
22604
|
+
const raw = readFile(ini.filePath);
|
|
22605
|
+
const { data, content } = matter18(raw, {});
|
|
22606
|
+
data.status = to;
|
|
22607
|
+
if (to === "completed") data.completed_at = today2();
|
|
22608
|
+
const newContent = matter18.stringify(content, data);
|
|
22609
|
+
writeFile(ini.filePath, newContent);
|
|
22610
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
22611
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after transition.");
|
|
22612
|
+
return updated;
|
|
22613
|
+
}
|
|
22614
|
+
function nextWorkItemId3(dir) {
|
|
22615
|
+
const wiDir = join(dir, WORK_ITEMS_DIR4);
|
|
22616
|
+
let max = 0;
|
|
22617
|
+
const walk = (d) => {
|
|
22618
|
+
if (!exists(d)) return;
|
|
22619
|
+
for (const entry of readDir(d)) {
|
|
22620
|
+
const full = join(d, entry);
|
|
22621
|
+
if (isFile(full)) {
|
|
22622
|
+
const m = entry.match(/WI-(\d+)/);
|
|
22623
|
+
if (m) max = Math.max(max, parseInt(m[1], 10));
|
|
22624
|
+
} else if (!entry.startsWith(".")) {
|
|
22625
|
+
walk(full);
|
|
22626
|
+
}
|
|
22627
|
+
}
|
|
22628
|
+
};
|
|
22629
|
+
walk(wiDir);
|
|
22630
|
+
return `WI-${String(max + 1).padStart(3, "0")}`;
|
|
22631
|
+
}
|
|
22632
|
+
function buildWorkItemContent(wiId, iniId, candidate) {
|
|
22633
|
+
const data = {
|
|
22634
|
+
type: candidate.type ?? "feature",
|
|
22635
|
+
id: wiId,
|
|
22636
|
+
title: candidate.title,
|
|
22637
|
+
knowledge_level: candidate.suggestedKnowledgeLevel ?? "K2",
|
|
22638
|
+
status: "draft",
|
|
22639
|
+
phase: "now",
|
|
22640
|
+
initiative: iniId,
|
|
22641
|
+
domains: [],
|
|
22642
|
+
code: [],
|
|
22643
|
+
created_at: today2(),
|
|
22644
|
+
source: "initiative",
|
|
22645
|
+
source_id: candidate.id,
|
|
22646
|
+
source_initiative: iniId,
|
|
22647
|
+
affected_modules: []
|
|
22648
|
+
};
|
|
22649
|
+
if (candidate.sourceSignals.length) data.source_signals = candidate.sourceSignals;
|
|
22650
|
+
if (candidate.dependencies.length) data.dependencies = candidate.dependencies;
|
|
22651
|
+
const body = [
|
|
22652
|
+
`# ${candidate.title}`,
|
|
22653
|
+
"",
|
|
22654
|
+
`> Materialized from Initiative ${iniId}, candidate ${candidate.id}.`,
|
|
22655
|
+
"",
|
|
22656
|
+
"## Problem",
|
|
22657
|
+
"",
|
|
22658
|
+
candidate.expectedValue ? `_Expected value:_ ${candidate.expectedValue}` : "_Describe the problem._",
|
|
22659
|
+
"",
|
|
22660
|
+
"## Acceptance Criteria",
|
|
22661
|
+
"",
|
|
22662
|
+
"- [ ] _Define at least one testable criterion._",
|
|
22663
|
+
"",
|
|
22664
|
+
"## Out of scope",
|
|
22665
|
+
"",
|
|
22666
|
+
"_Not included in this Work Item._",
|
|
22667
|
+
"",
|
|
22668
|
+
"## Validation",
|
|
22669
|
+
"",
|
|
22670
|
+
"_How will this be validated?_",
|
|
22671
|
+
"",
|
|
22672
|
+
"## Learning",
|
|
22673
|
+
"",
|
|
22674
|
+
"_What did we learn? Update after completion._",
|
|
22675
|
+
""
|
|
22676
|
+
].join("\n");
|
|
22677
|
+
return matter18.stringify("\n" + body, data);
|
|
22678
|
+
}
|
|
22679
|
+
function materializeCandidate(dir, id, candidateId) {
|
|
22680
|
+
const ini = getInitiative(dir, id);
|
|
22681
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
22682
|
+
const candidate = ini.candidates.find((c) => c.id === candidateId);
|
|
22683
|
+
if (!candidate) throw new InitiativeWriteError(`Candidate ${candidateId} not found in ${id}.`);
|
|
22684
|
+
if (candidate.materializedAs) {
|
|
22685
|
+
throw new InitiativeWriteError(
|
|
22686
|
+
`Candidate ${candidateId} is already materialized as ${candidate.materializedAs}.`
|
|
22687
|
+
);
|
|
22688
|
+
}
|
|
22689
|
+
const wiId = nextWorkItemId3(dir);
|
|
22690
|
+
const fileName = `${wiId}-${slugify6(candidate.title)}.md`;
|
|
22691
|
+
ensureDir(join(dir, DRAFT_DIR2));
|
|
22692
|
+
writeFile(join(dir, DRAFT_DIR2, fileName), buildWorkItemContent(wiId, ini.id, candidate));
|
|
22693
|
+
const raw = readFile(ini.filePath);
|
|
22694
|
+
const { data, content } = matter18(raw, {});
|
|
22695
|
+
const cands = Array.isArray(data.candidates) ? data.candidates : [];
|
|
22696
|
+
for (const c of cands) {
|
|
22697
|
+
if (c && typeof c === "object" && String(c.id) === candidateId) c.materialized_as = wiId;
|
|
22698
|
+
}
|
|
22699
|
+
data.candidates = cands;
|
|
22700
|
+
const newContent = matter18.stringify(content, data);
|
|
22701
|
+
writeFile(ini.filePath, newContent);
|
|
22702
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
22703
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after materialization.");
|
|
22704
|
+
return { workItemId: wiId, fileName, initiative: updated };
|
|
22705
|
+
}
|
|
22706
|
+
|
|
22707
|
+
// src/commands/initiative.ts
|
|
22708
|
+
function requireInit(dir) {
|
|
22709
|
+
if (!loadConfig(dir)) {
|
|
22710
|
+
log.error("Kaddo is not initialized. Run `kaddo init` first.");
|
|
22711
|
+
process.exit(1);
|
|
22712
|
+
}
|
|
22713
|
+
}
|
|
22714
|
+
function runInitiativeList() {
|
|
22715
|
+
const dir = cwd();
|
|
22716
|
+
requireInit(dir);
|
|
22717
|
+
intro("kaddo initiative list");
|
|
22718
|
+
const all = discoverInitiatives(dir);
|
|
22719
|
+
if (all.length === 0) {
|
|
22720
|
+
log.info("No initiatives yet. Create one with `kaddo initiative create`.");
|
|
22721
|
+
outro("Nothing to show.");
|
|
22722
|
+
return;
|
|
22723
|
+
}
|
|
22724
|
+
for (const ini of all) {
|
|
22725
|
+
const p = computeInitiativeProgress(dir, ini);
|
|
22726
|
+
log.info(
|
|
22727
|
+
`${ini.id} \u2014 ${ini.title} [${ini.status}] planning ${p.planning.materialized}/${p.planning.totalCandidates} \xB7 delivery ${p.delivery.byState.completed}/${p.delivery.total} completed`
|
|
22728
|
+
);
|
|
22729
|
+
}
|
|
22730
|
+
outro(`${all.length} initiative(s).`);
|
|
22731
|
+
}
|
|
22732
|
+
function runInitiativeShow(id) {
|
|
22733
|
+
const dir = cwd();
|
|
22734
|
+
requireInit(dir);
|
|
22735
|
+
intro(`kaddo initiative show ${id}`);
|
|
22736
|
+
const ini = getInitiative(dir, id);
|
|
22737
|
+
if (!ini) {
|
|
22738
|
+
log.error(`Initiative ${id} not found.`);
|
|
22739
|
+
process.exit(1);
|
|
22740
|
+
}
|
|
22741
|
+
log.info(` ${ini.id} \u2014 ${ini.title}`);
|
|
22742
|
+
log.info(` Status: ${ini.status}`);
|
|
22743
|
+
if (ini.horizon) log.info(` Horizon: ${ini.horizon}`);
|
|
22744
|
+
if (ini.priority) log.info(` Priority: ${ini.priority}`);
|
|
22745
|
+
if (ini.domains.length) log.info(` Domains: ${ini.domains.join(", ")}`);
|
|
22746
|
+
if (ini.relatedCapabilities.length) log.info(` Capabilities: ${ini.relatedCapabilities.join(", ")}`);
|
|
22747
|
+
if (ini.source) log.info(` Source: ${ini.source}${ini.sourceId ? ` (${ini.sourceId})` : ""}`);
|
|
22748
|
+
log.info(` Candidates: ${ini.candidates.length}`);
|
|
22749
|
+
for (const c of ini.candidates) {
|
|
22750
|
+
log.info(` - ${c.id}: ${c.title}${c.materializedAs ? ` \u2192 ${c.materializedAs}` : " (pending)"}`);
|
|
22751
|
+
}
|
|
22752
|
+
outro(`Initiative ${ini.id}.`);
|
|
22753
|
+
}
|
|
22754
|
+
function runInitiativeProgress(id) {
|
|
22755
|
+
const dir = cwd();
|
|
22756
|
+
requireInit(dir);
|
|
22757
|
+
intro(`kaddo initiative progress ${id}`);
|
|
22758
|
+
const ini = getInitiative(dir, id);
|
|
22759
|
+
if (!ini) {
|
|
22760
|
+
log.error(`Initiative ${id} not found.`);
|
|
22761
|
+
process.exit(1);
|
|
22762
|
+
}
|
|
22763
|
+
const p = computeInitiativeProgress(dir, ini);
|
|
22764
|
+
log.info(` Status: ${p.status}`);
|
|
22765
|
+
log.info("");
|
|
22766
|
+
log.info(` Planning: ${p.planning.materialized}/${p.planning.totalCandidates} candidates materialized (${p.planning.remaining} remaining)`);
|
|
22767
|
+
log.info("");
|
|
22768
|
+
log.info(` Delivery: ${p.delivery.total} associated Work Items`);
|
|
22769
|
+
for (const [state, n] of Object.entries(p.delivery.byState)) {
|
|
22770
|
+
if (n > 0) log.info(` ${state}: ${n}`);
|
|
22771
|
+
}
|
|
22772
|
+
outro(`Progress for ${ini.id}.`);
|
|
22773
|
+
}
|
|
22774
|
+
function runInitiativeCandidates(id) {
|
|
22775
|
+
const dir = cwd();
|
|
22776
|
+
requireInit(dir);
|
|
22777
|
+
intro(`kaddo initiative candidates ${id}`);
|
|
22778
|
+
const ini = getInitiative(dir, id);
|
|
22779
|
+
if (!ini) {
|
|
22780
|
+
log.error(`Initiative ${id} not found.`);
|
|
22781
|
+
process.exit(1);
|
|
22782
|
+
}
|
|
22783
|
+
if (ini.candidates.length === 0) {
|
|
22784
|
+
log.info("No candidates on this initiative.");
|
|
22785
|
+
outro("Nothing to show.");
|
|
22786
|
+
return;
|
|
22787
|
+
}
|
|
22788
|
+
for (const c of ini.candidates) {
|
|
22789
|
+
log.info(` ${c.id}: ${c.title}${c.materializedAs ? ` \u2192 ${c.materializedAs}` : " (pending)"}`);
|
|
22790
|
+
if (c.expectedValue) log.info(` value: ${c.expectedValue}`);
|
|
22791
|
+
}
|
|
22792
|
+
outro(`${ini.candidates.length} candidate(s).`);
|
|
22793
|
+
}
|
|
22794
|
+
async function runInitiativeCreate(opts) {
|
|
22795
|
+
const dir = cwd();
|
|
22796
|
+
requireInit(dir);
|
|
22797
|
+
intro("kaddo initiative create");
|
|
22798
|
+
const title = opts.title?.trim() || (await text({
|
|
22799
|
+
message: "Initiative title",
|
|
22800
|
+
validate: (v) => v.trim().length === 0 ? "Title is required." : void 0
|
|
22801
|
+
})).trim();
|
|
22802
|
+
try {
|
|
22803
|
+
const ini = createInitiative(dir, { title });
|
|
22804
|
+
log.success(`Created ${ini.id} \u2014 ${ini.title}`);
|
|
22805
|
+
log.info(` knowledge/delivery/initiatives/`);
|
|
22806
|
+
outro(`Initiative ${ini.id} created.`);
|
|
22807
|
+
} catch (err) {
|
|
22808
|
+
log.error(err instanceof InitiativeWriteError ? err.message : String(err));
|
|
22809
|
+
process.exit(1);
|
|
22810
|
+
}
|
|
22811
|
+
}
|
|
22812
|
+
async function runInitiativeUpdate(id, opts) {
|
|
22813
|
+
const dir = cwd();
|
|
22814
|
+
requireInit(dir);
|
|
22815
|
+
intro(`kaddo initiative update ${id}`);
|
|
22816
|
+
const ini = getInitiative(dir, id);
|
|
22817
|
+
if (!ini) {
|
|
22818
|
+
log.error(`Initiative ${id} not found.`);
|
|
22819
|
+
process.exit(1);
|
|
22820
|
+
}
|
|
22821
|
+
const to = opts.status ?? await select({
|
|
22822
|
+
message: "New status",
|
|
22823
|
+
options: [
|
|
22824
|
+
{ value: "planned", label: "planned" },
|
|
22825
|
+
{ value: "in-progress", label: "in-progress" },
|
|
22826
|
+
{ value: "completed", label: "completed" },
|
|
22827
|
+
{ value: "deferred", label: "deferred" },
|
|
22828
|
+
{ value: "cancelled", label: "cancelled" }
|
|
22829
|
+
]
|
|
22830
|
+
});
|
|
22831
|
+
try {
|
|
22832
|
+
const updated = transitionInitiative(dir, id, to);
|
|
22833
|
+
log.success(`Status: ${updated.status}`);
|
|
22834
|
+
outro(`Initiative ${updated.id} updated.`);
|
|
22835
|
+
} catch (err) {
|
|
22836
|
+
log.error(err instanceof InitiativeWriteError ? err.message : String(err));
|
|
22837
|
+
process.exit(1);
|
|
22838
|
+
}
|
|
22839
|
+
}
|
|
22840
|
+
function runInitiativeMaterialize(id, candidateId) {
|
|
22841
|
+
const dir = cwd();
|
|
22842
|
+
requireInit(dir);
|
|
22843
|
+
intro(`kaddo initiative materialize ${id} ${candidateId}`);
|
|
22844
|
+
try {
|
|
22845
|
+
const result = materializeCandidate(dir, id, candidateId);
|
|
22846
|
+
log.success(`Materialized ${candidateId} \u2192 ${result.workItemId}`);
|
|
22847
|
+
log.info(` knowledge/delivery/work-items/draft/${result.fileName}`);
|
|
22848
|
+
log.info(` Associated to ${id} via \`initiative: ${id}\`.`);
|
|
22849
|
+
outro(`Work Item ${result.workItemId} created from candidate.`);
|
|
22850
|
+
} catch (err) {
|
|
22851
|
+
log.error(err instanceof InitiativeWriteError ? err.message : String(err));
|
|
22852
|
+
process.exit(1);
|
|
22853
|
+
}
|
|
22854
|
+
}
|
|
22855
|
+
|
|
22295
22856
|
// src/index.ts
|
|
22296
22857
|
var require2 = createRequire(import.meta.url);
|
|
22297
22858
|
var { version } = require2("../package.json");
|
|
@@ -22469,6 +23030,28 @@ program.command("add [module]").description("Install an optional Kaddo module (a
|
|
|
22469
23030
|
program.command("admin").description("Start Kaddo Admin \u2014 a local web interface for the project knowledge").option("--port <port>", "Server port (default: 4173)", parseInt).option("--host <host>", "Server host (default: 127.0.0.1)").option("--no-open", "Do not open the browser automatically").action(async (opts) => {
|
|
22470
23031
|
await runAdmin({ port: opts.port, host: opts.host, noOpen: opts.open === false });
|
|
22471
23032
|
});
|
|
23033
|
+
var initiativeCmd = program.command("initiative").description("Manage initiatives \u2014 the optional outcome layer over Work Items");
|
|
23034
|
+
initiativeCmd.command("list").description("List initiatives with planning and delivery progress").action(() => {
|
|
23035
|
+
runInitiativeList();
|
|
23036
|
+
});
|
|
23037
|
+
initiativeCmd.command("show <id>").description("Show an initiative, its metadata and candidates").action((id) => {
|
|
23038
|
+
runInitiativeShow(id);
|
|
23039
|
+
});
|
|
23040
|
+
initiativeCmd.command("progress <id>").description("Show planning coverage and delivery progress for an initiative").action((id) => {
|
|
23041
|
+
runInitiativeProgress(id);
|
|
23042
|
+
});
|
|
23043
|
+
initiativeCmd.command("candidates <id>").description("List the Work Item candidates of an initiative").action((id) => {
|
|
23044
|
+
runInitiativeCandidates(id);
|
|
23045
|
+
});
|
|
23046
|
+
initiativeCmd.command("create").description("Create a new initiative").option("--title <title>", "Initiative title (prompts if omitted)").action(async (opts) => {
|
|
23047
|
+
await runInitiativeCreate(opts);
|
|
23048
|
+
});
|
|
23049
|
+
initiativeCmd.command("update <id>").description("Update an initiative status (valid lifecycle transitions only)").option("--status <status>", "New status: planned, in-progress, completed, deferred, cancelled").action(async (id, opts) => {
|
|
23050
|
+
await runInitiativeUpdate(id, opts);
|
|
23051
|
+
});
|
|
23052
|
+
initiativeCmd.command("materialize <id> <candidateId>").description("Materialize an initiative candidate into a draft Work Item").action((id, candidateId) => {
|
|
23053
|
+
runInitiativeMaterialize(id, candidateId);
|
|
23054
|
+
});
|
|
22472
23055
|
var telemetryCmd = program.command("telemetry").description("Manage anonymous usage telemetry");
|
|
22473
23056
|
telemetryCmd.command("status").description("Show telemetry status (enabled, registered, pending events)").action(() => {
|
|
22474
23057
|
runTelemetryStatus();
|