@kaddo/cli 3.104.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/core.js +490 -3
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -13,6 +13,9 @@ function writeFile(filePath, content) {
|
|
|
13
13
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
14
14
|
fs.writeFileSync(filePath, content, "utf-8");
|
|
15
15
|
}
|
|
16
|
+
function ensureDir(dirPath) {
|
|
17
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
18
|
+
}
|
|
16
19
|
function readDir(dirPath) {
|
|
17
20
|
if (!exists(dirPath)) return [];
|
|
18
21
|
return fs.readdirSync(dirPath);
|
|
@@ -9150,7 +9153,7 @@ function createWorkItem(dir, opts) {
|
|
|
9150
9153
|
if (!type) throw new WorkItemWriteError("INVALID_INPUT", `Unknown Work Item type "${opts.type}".`);
|
|
9151
9154
|
const id = nextWorkItemId(dir);
|
|
9152
9155
|
const title = intent.split(/\r?\n/)[0].trim().slice(0, 120);
|
|
9153
|
-
const
|
|
9156
|
+
const today2 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
9154
9157
|
const source = opts.source ? { ...opts.source, inferred: false } : { type: "manual", inferred: false };
|
|
9155
9158
|
const data = {
|
|
9156
9159
|
type,
|
|
@@ -9158,7 +9161,7 @@ function createWorkItem(dir, opts) {
|
|
|
9158
9161
|
title,
|
|
9159
9162
|
status: "draft",
|
|
9160
9163
|
work_type: type,
|
|
9161
|
-
created_at:
|
|
9164
|
+
created_at: today2,
|
|
9162
9165
|
source,
|
|
9163
9166
|
generated_by: "kaddo-admin",
|
|
9164
9167
|
affected_modules: [],
|
|
@@ -11881,10 +11884,480 @@ function getStatus(dir) {
|
|
|
11881
11884
|
lastError: null
|
|
11882
11885
|
};
|
|
11883
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
|
+
}
|
|
11884
12353
|
export {
|
|
11885
12354
|
CURRENT_CONSENT_VERSION,
|
|
12355
|
+
INITIATIVES_DIR,
|
|
12356
|
+
INITIATIVE_STATES,
|
|
12357
|
+
INITIATIVE_TRANSITIONS,
|
|
11886
12358
|
INTEGRATIONS_FILE,
|
|
11887
12359
|
ImportError,
|
|
12360
|
+
InitiativeWriteError,
|
|
11888
12361
|
IntegrationError,
|
|
11889
12362
|
IntegrationServiceError,
|
|
11890
12363
|
TOPOLOGY_FILE,
|
|
@@ -11893,9 +12366,11 @@ export {
|
|
|
11893
12366
|
WorkItemNotInProgressError,
|
|
11894
12367
|
WorkItemNotReadyError,
|
|
11895
12368
|
WorkItemWriteError,
|
|
12369
|
+
addCandidate,
|
|
11896
12370
|
analyzeCrossRepoEvidence,
|
|
11897
12371
|
analyzeScopeCoverage,
|
|
11898
12372
|
applyTopologyProposal,
|
|
12373
|
+
associatedWorkItems,
|
|
11899
12374
|
buildImplementationHandoff,
|
|
11900
12375
|
buildImportIndex,
|
|
11901
12376
|
buildProjectExplanation,
|
|
@@ -11905,8 +12380,10 @@ export {
|
|
|
11905
12380
|
buildTopologyEnrichmentHandoff,
|
|
11906
12381
|
collectImplementationEvidence,
|
|
11907
12382
|
computeContentHash,
|
|
12383
|
+
computeInitiativeProgress,
|
|
11908
12384
|
computeRefinementStatus,
|
|
11909
12385
|
consentNotice,
|
|
12386
|
+
createInitiative,
|
|
11910
12387
|
createIntegration,
|
|
11911
12388
|
createWorkItem,
|
|
11912
12389
|
cwd,
|
|
@@ -11915,6 +12392,7 @@ export {
|
|
|
11915
12392
|
detectFormat,
|
|
11916
12393
|
disableIntegration,
|
|
11917
12394
|
discoverExternalWorkItems,
|
|
12395
|
+
discoverInitiatives,
|
|
11918
12396
|
discoverKnowledge,
|
|
11919
12397
|
discoverWorkItems,
|
|
11920
12398
|
enableIntegration,
|
|
@@ -11929,6 +12407,7 @@ export {
|
|
|
11929
12407
|
getConsentState,
|
|
11930
12408
|
getExternalWorkItem,
|
|
11931
12409
|
getImpactCandidates,
|
|
12410
|
+
getInitiative,
|
|
11932
12411
|
getIntegration,
|
|
11933
12412
|
getIntegrationFilters,
|
|
11934
12413
|
getIntegrationSecretStatus,
|
|
@@ -11949,6 +12428,8 @@ export {
|
|
|
11949
12428
|
isInteractive,
|
|
11950
12429
|
isModule,
|
|
11951
12430
|
isEnabled as isTelemetryEnabled,
|
|
12431
|
+
isValidInitiativeStatus,
|
|
12432
|
+
isValidInitiativeTransition,
|
|
11952
12433
|
join,
|
|
11953
12434
|
knowledgeLayers,
|
|
11954
12435
|
lifecycleCounts,
|
|
@@ -11958,7 +12439,11 @@ export {
|
|
|
11958
12439
|
loadConfig,
|
|
11959
12440
|
loadMappedModules,
|
|
11960
12441
|
loadSystemTopology,
|
|
12442
|
+
materializeCandidate,
|
|
12443
|
+
materializeRoadmapInitiative,
|
|
12444
|
+
nextInitiativeId,
|
|
11961
12445
|
parseContent,
|
|
12446
|
+
parseInitiative,
|
|
11962
12447
|
persistConsent,
|
|
11963
12448
|
previewImport,
|
|
11964
12449
|
readFile,
|
|
@@ -11966,6 +12451,7 @@ export {
|
|
|
11966
12451
|
searchSystemNodes,
|
|
11967
12452
|
setIntegrationSecret,
|
|
11968
12453
|
topologyRevision,
|
|
12454
|
+
transitionInitiative,
|
|
11969
12455
|
transitionWorkItem,
|
|
11970
12456
|
updateIntegration,
|
|
11971
12457
|
updateIntegrationFilters,
|
|
@@ -11975,5 +12461,6 @@ export {
|
|
|
11975
12461
|
validateTopologyProposal,
|
|
11976
12462
|
validateWorkItem,
|
|
11977
12463
|
verifyIntegration,
|
|
11978
|
-
verifyWorkItem
|
|
12464
|
+
verifyWorkItem,
|
|
12465
|
+
workItemBelongsToInitiative
|
|
11979
12466
|
};
|