@kaddo/cli 3.135.0 → 3.136.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/admin-dist/assets/{architectureDiagram-3BPJPVTR-DkdJ073y.js → architectureDiagram-3BPJPVTR-LjksP4qj.js} +1 -1
- package/dist/admin-dist/assets/{chunk-727SXJPM-DRof4aGT.js → chunk-727SXJPM-B9bbDh_M.js} +1 -1
- package/dist/admin-dist/assets/{chunk-AQP2D5EJ-BOVZoYng.js → chunk-AQP2D5EJ-BD776tm_.js} +1 -1
- package/dist/admin-dist/assets/{classDiagram-v2-Q7XG4LA2-cL_umCGu.js → classDiagram-4FO5ZUOK-D_59IJDh.js} +1 -1
- package/dist/admin-dist/assets/{classDiagram-4FO5ZUOK-cL_umCGu.js → classDiagram-v2-Q7XG4LA2-D_59IJDh.js} +1 -1
- package/dist/admin-dist/assets/{dagre-BM42HDAG-Cvga2Wk-.js → dagre-BM42HDAG-Bz-INcCu.js} +1 -1
- package/dist/admin-dist/assets/{diagram-2AECGRRQ-C4H51In7.js → diagram-2AECGRRQ-uWqqhcHf.js} +1 -1
- package/dist/admin-dist/assets/{diagram-5GNKFQAL-BW2-XCqV.js → diagram-5GNKFQAL-BanaZANB.js} +1 -1
- package/dist/admin-dist/assets/{diagram-LMA3HP47-CQnSrSZs.js → diagram-LMA3HP47-DNXl16UE.js} +1 -1
- package/dist/admin-dist/assets/{diagram-OG6HWLK6-BA6tBaOl.js → diagram-OG6HWLK6-BPuwqdOA.js} +1 -1
- package/dist/admin-dist/assets/{erDiagram-TEJ5UH35-DQK3b1Yu.js → erDiagram-TEJ5UH35-CjHdHiPN.js} +1 -1
- package/dist/admin-dist/assets/{flowDiagram-I6XJVG4X-BvtbwW59.js → flowDiagram-I6XJVG4X-8LugweYq.js} +1 -1
- package/dist/admin-dist/assets/{ganttDiagram-6RSMTGT7-Vb0T68-1.js → ganttDiagram-6RSMTGT7-T1r39UBo.js} +1 -1
- package/dist/admin-dist/assets/{index-F0fBD3Ys.js → index-Cm0J_POl.js} +7 -6
- package/dist/admin-dist/assets/{infoDiagram-5YYISTIA-8oD9uPZj.js → infoDiagram-5YYISTIA-Bt5lkett.js} +1 -1
- package/dist/admin-dist/assets/{ishikawaDiagram-YF4QCWOH-C32f84vy.js → ishikawaDiagram-YF4QCWOH-BAEvG6rZ.js} +1 -1
- package/dist/admin-dist/assets/{kanban-definition-UN3LZRKU-cJc_snn8.js → kanban-definition-UN3LZRKU-BXlgj75s.js} +1 -1
- package/dist/admin-dist/assets/{linear-XcP0Xi-K.js → linear-CcJpsi8a.js} +1 -1
- package/dist/admin-dist/assets/{mindmap-definition-RKZ34NQL-jhlLOmXd.js → mindmap-definition-RKZ34NQL-BDUe2xi4.js} +1 -1
- package/dist/admin-dist/assets/{pieDiagram-4H26LBE5-cEiC5w8m.js → pieDiagram-4H26LBE5-Cw_a1v5z.js} +1 -1
- package/dist/admin-dist/assets/{quadrantDiagram-W4KKPZXB-xjpfY5PD.js → quadrantDiagram-W4KKPZXB-CJvWU8a3.js} +1 -1
- package/dist/admin-dist/assets/{requirementDiagram-4Y6WPE33-C5KtzYhy.js → requirementDiagram-4Y6WPE33-D-vDruTz.js} +1 -1
- package/dist/admin-dist/assets/{sequenceDiagram-3UESZ5HK-ByGOoS_6.js → sequenceDiagram-3UESZ5HK-B4PJZymc.js} +1 -1
- package/dist/admin-dist/assets/{stateDiagram-AJRCARHV-d9g3cuV4.js → stateDiagram-AJRCARHV-B8K87k9v.js} +1 -1
- package/dist/admin-dist/assets/{stateDiagram-v2-BHNVJYJU-DJ9FtIdZ.js → stateDiagram-v2-BHNVJYJU-C5Q0Gwxn.js} +1 -1
- package/dist/admin-dist/assets/{timeline-definition-PNZ67QCA-BB4Lz6CJ.js → timeline-definition-PNZ67QCA-BHQwwDwf.js} +1 -1
- package/dist/admin-dist/assets/{vennDiagram-CIIHVFJN-yj1GFfPu.js → vennDiagram-CIIHVFJN-k_l2q31S.js} +1 -1
- package/dist/admin-dist/assets/{wardleyDiagram-YWT4CUSO-5nw4MWMx.js → wardleyDiagram-YWT4CUSO-CYNfnm_M.js} +1 -1
- package/dist/admin-dist/assets/{xychartDiagram-2RQKCTM6-C0iogx2l.js → xychartDiagram-2RQKCTM6-JF9I5EAO.js} +1 -1
- package/dist/admin-dist/index.html +1 -1
- package/dist/admin-server/index.js +158 -5
- package/dist/core.js +947 -634
- package/dist/index.js +673 -460
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -10789,15 +10789,497 @@ import matter13 from "gray-matter";
|
|
|
10789
10789
|
|
|
10790
10790
|
// src/core/initiative-write.ts
|
|
10791
10791
|
import matter12 from "gray-matter";
|
|
10792
|
+
|
|
10793
|
+
// src/core/initiative-analysis.ts
|
|
10794
|
+
var SUCCESS_HEADING_RE = /^#{1,6}\s*(success criteria|criterios de[ét]xito|criterios de éxito)\s*$/i;
|
|
10795
|
+
var HEADING_RE2 = /^#{1,6}\s+/;
|
|
10796
|
+
var CHECK_ITEM_RE = /^\s*[-*]\s+\[([ xX])\]\s+(.*)$/;
|
|
10797
|
+
var BULLET_RE2 = /^\s*[-*]\s+(.*)$/;
|
|
10798
|
+
var PLACEHOLDER_RE = /^_.*_$/;
|
|
10799
|
+
function parseSuccessCriteria(body) {
|
|
10800
|
+
const lines = body.split(/\r?\n/);
|
|
10801
|
+
const out = [];
|
|
10802
|
+
let capture = false;
|
|
10803
|
+
for (const line of lines) {
|
|
10804
|
+
if (capture && HEADING_RE2.test(line)) break;
|
|
10805
|
+
if (!capture) {
|
|
10806
|
+
if (SUCCESS_HEADING_RE.test(line.trim())) capture = true;
|
|
10807
|
+
continue;
|
|
10808
|
+
}
|
|
10809
|
+
const check = line.match(CHECK_ITEM_RE);
|
|
10810
|
+
if (check) {
|
|
10811
|
+
const text2 = check[2].trim();
|
|
10812
|
+
if (text2 && !PLACEHOLDER_RE.test(text2)) {
|
|
10813
|
+
out.push({ text: text2, checked: check[1].toLowerCase() === "x" });
|
|
10814
|
+
}
|
|
10815
|
+
continue;
|
|
10816
|
+
}
|
|
10817
|
+
const bullet = line.match(BULLET_RE2);
|
|
10818
|
+
if (bullet) {
|
|
10819
|
+
const text2 = bullet[1].trim();
|
|
10820
|
+
if (text2 && !PLACEHOLDER_RE.test(text2)) out.push({ text: text2, checked: null });
|
|
10821
|
+
}
|
|
10822
|
+
}
|
|
10823
|
+
return out;
|
|
10824
|
+
}
|
|
10825
|
+
function analyzeInitiative(dir, ini) {
|
|
10826
|
+
const progress = computeInitiativeProgress(dir, ini);
|
|
10827
|
+
const successCriteria = parseSuccessCriteria(ini.body);
|
|
10828
|
+
const pendingCandidates = ini.candidates.filter((c) => !c.materializedAs);
|
|
10829
|
+
const associated = associatedWorkItems(dir, ini.id);
|
|
10830
|
+
const findings = [];
|
|
10831
|
+
if (successCriteria.length === 0) {
|
|
10832
|
+
findings.push({
|
|
10833
|
+
code: "no-success-criteria",
|
|
10834
|
+
severity: "warning",
|
|
10835
|
+
message: "The Initiative has no explicit Success Criteria; completion cannot be judged by outcome, only by delivery."
|
|
10836
|
+
});
|
|
10837
|
+
} else {
|
|
10838
|
+
const uncovered = successCriteria.filter((c) => c.checked === false);
|
|
10839
|
+
if (uncovered.length > 0) {
|
|
10840
|
+
findings.push({
|
|
10841
|
+
code: "uncovered-success-criteria",
|
|
10842
|
+
severity: "blocking",
|
|
10843
|
+
message: `${uncovered.length} success criterion/criteria remain uncovered.`,
|
|
10844
|
+
items: uncovered.map((c) => c.text)
|
|
10845
|
+
});
|
|
10846
|
+
}
|
|
10847
|
+
}
|
|
10848
|
+
if (pendingCandidates.length > 0) {
|
|
10849
|
+
findings.push({
|
|
10850
|
+
code: "pending-candidates",
|
|
10851
|
+
severity: "blocking",
|
|
10852
|
+
message: `${pendingCandidates.length} committed candidate(s) not yet materialized into Work Items.`,
|
|
10853
|
+
items: pendingCandidates.map((c) => `${c.id}: ${c.title}`)
|
|
10854
|
+
});
|
|
10855
|
+
}
|
|
10856
|
+
const notCompleted = associated.filter((w) => w.status !== "completed" && w.status !== "archived");
|
|
10857
|
+
if (associated.length === 0) {
|
|
10858
|
+
findings.push({
|
|
10859
|
+
code: "no-delivery",
|
|
10860
|
+
severity: "info",
|
|
10861
|
+
message: "No Work Items are associated with this Initiative yet."
|
|
10862
|
+
});
|
|
10863
|
+
} else if (notCompleted.length > 0) {
|
|
10864
|
+
findings.push({
|
|
10865
|
+
code: "incomplete-delivery",
|
|
10866
|
+
severity: "blocking",
|
|
10867
|
+
message: `${notCompleted.length} associated Work Item(s) are not completed.`,
|
|
10868
|
+
items: notCompleted.map((w) => `${w.id} (${w.status})`)
|
|
10869
|
+
});
|
|
10870
|
+
}
|
|
10871
|
+
return {
|
|
10872
|
+
initiative: ini.id,
|
|
10873
|
+
status: ini.status,
|
|
10874
|
+
progress,
|
|
10875
|
+
successCriteria,
|
|
10876
|
+
pendingCandidates,
|
|
10877
|
+
findings,
|
|
10878
|
+
suggestedCandidates: pendingCandidates
|
|
10879
|
+
};
|
|
10880
|
+
}
|
|
10881
|
+
|
|
10882
|
+
// src/core/delivery-verification.ts
|
|
10883
|
+
function normalizeCriterion(text2) {
|
|
10884
|
+
return text2.trim().toLowerCase().replace(/\s+/g, " ");
|
|
10885
|
+
}
|
|
10886
|
+
var STATUSES = ["passed", "failed", "not-verified", "manual-review-required"];
|
|
10887
|
+
function optStr4(v) {
|
|
10888
|
+
if (typeof v === "string" && v.trim()) return v.trim();
|
|
10889
|
+
if (typeof v === "number") return String(v);
|
|
10890
|
+
return void 0;
|
|
10891
|
+
}
|
|
10892
|
+
function parseEvidenceList(raw) {
|
|
10893
|
+
if (!Array.isArray(raw)) return [];
|
|
10894
|
+
const out = [];
|
|
10895
|
+
for (const entry of raw) {
|
|
10896
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
10897
|
+
const o = entry;
|
|
10898
|
+
const criterion = optStr4(o.criterion);
|
|
10899
|
+
if (!criterion) continue;
|
|
10900
|
+
const statusRaw = optStr4(o.status);
|
|
10901
|
+
const status = STATUSES.includes(statusRaw ?? "") ? statusRaw : "not-verified";
|
|
10902
|
+
const method = optStr4(o.method);
|
|
10903
|
+
out.push({
|
|
10904
|
+
criterion,
|
|
10905
|
+
status,
|
|
10906
|
+
...optStr4(o.evidence) ? { evidence: optStr4(o.evidence) } : {},
|
|
10907
|
+
...optStr4(o.reference) ? { reference: optStr4(o.reference) } : {},
|
|
10908
|
+
...method === "automated" || method === "manual" ? { method } : {},
|
|
10909
|
+
...optStr4(o.verified_at) ? { verified_at: optStr4(o.verified_at) } : {},
|
|
10910
|
+
...optStr4(o.verified_by) ? { verified_by: optStr4(o.verified_by) } : {}
|
|
10911
|
+
});
|
|
10912
|
+
}
|
|
10913
|
+
return out;
|
|
10914
|
+
}
|
|
10915
|
+
function parseExceptions(raw) {
|
|
10916
|
+
if (!Array.isArray(raw)) return [];
|
|
10917
|
+
const out = [];
|
|
10918
|
+
for (const entry of raw) {
|
|
10919
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
10920
|
+
const o = entry;
|
|
10921
|
+
const id = optStr4(o.id);
|
|
10922
|
+
if (!id) continue;
|
|
10923
|
+
const st = optStr4(o.status);
|
|
10924
|
+
const status = st === "accepted" || st === "rejected" ? st : "proposed";
|
|
10925
|
+
out.push({
|
|
10926
|
+
id,
|
|
10927
|
+
status,
|
|
10928
|
+
...optStr4(o.criterion) ? { criterion: optStr4(o.criterion) } : {},
|
|
10929
|
+
...optStr4(o.reason) ? { reason: optStr4(o.reason) } : {}
|
|
10930
|
+
});
|
|
10931
|
+
}
|
|
10932
|
+
return out;
|
|
10933
|
+
}
|
|
10934
|
+
function buildOutcomeVerification(declared, evidence, exceptions = []) {
|
|
10935
|
+
const byCriterion = /* @__PURE__ */ new Map();
|
|
10936
|
+
for (const e of evidence) byCriterion.set(normalizeCriterion(e.criterion), e);
|
|
10937
|
+
const declaredKeys = new Set(declared.map(normalizeCriterion));
|
|
10938
|
+
const counts = /* @__PURE__ */ new Map();
|
|
10939
|
+
for (const c of declared) counts.set(normalizeCriterion(c), (counts.get(normalizeCriterion(c)) ?? 0) + 1);
|
|
10940
|
+
const ambiguousKeys = new Set([...counts.entries()].filter(([, n]) => n > 1).map(([k]) => k));
|
|
10941
|
+
const waived = new Set(
|
|
10942
|
+
exceptions.filter((x) => x.status === "accepted" && x.reason?.trim() && x.criterion && declaredKeys.has(normalizeCriterion(x.criterion)) && !ambiguousKeys.has(normalizeCriterion(x.criterion))).map((x) => normalizeCriterion(x.criterion))
|
|
10943
|
+
);
|
|
10944
|
+
const criteria = declared.map((criterion) => {
|
|
10945
|
+
const key = normalizeCriterion(criterion);
|
|
10946
|
+
const ambiguous = ambiguousKeys.has(key);
|
|
10947
|
+
const e = ambiguous ? void 0 : byCriterion.get(key);
|
|
10948
|
+
return {
|
|
10949
|
+
criterion,
|
|
10950
|
+
status: e?.status ?? "not-verified",
|
|
10951
|
+
...e?.evidence ? { evidence: e.evidence } : {},
|
|
10952
|
+
...e?.reference ? { reference: e.reference } : {},
|
|
10953
|
+
...e?.method ? { method: e.method } : {},
|
|
10954
|
+
...e?.verified_at ? { verifiedAt: e.verified_at } : {},
|
|
10955
|
+
...e?.verified_by ? { verifiedBy: e.verified_by } : {},
|
|
10956
|
+
...!ambiguous && waived.has(key) ? { waived: true } : {},
|
|
10957
|
+
...ambiguous ? { ambiguous: true } : {}
|
|
10958
|
+
};
|
|
10959
|
+
});
|
|
10960
|
+
const stale = evidence.filter((e) => !declaredKeys.has(normalizeCriterion(e.criterion)));
|
|
10961
|
+
return {
|
|
10962
|
+
total: criteria.length,
|
|
10963
|
+
// An ambiguous criterion is never counted as passed/waived; it counts as unverified until disambiguated.
|
|
10964
|
+
passed: criteria.filter((c) => !c.ambiguous && (c.status === "passed" || c.waived)).length,
|
|
10965
|
+
failed: criteria.filter((c) => !c.ambiguous && c.status === "failed" && !c.waived).length,
|
|
10966
|
+
notVerified: criteria.filter((c) => c.ambiguous || c.status === "not-verified" && !c.waived).length,
|
|
10967
|
+
manualReview: criteria.filter((c) => !c.ambiguous && c.status === "manual-review-required" && !c.waived).length,
|
|
10968
|
+
ambiguous: criteria.filter((c) => c.ambiguous).length,
|
|
10969
|
+
criteria,
|
|
10970
|
+
stale
|
|
10971
|
+
};
|
|
10972
|
+
}
|
|
10973
|
+
function fm(entity, key) {
|
|
10974
|
+
return entity.rawFrontmatter?.[key];
|
|
10975
|
+
}
|
|
10976
|
+
function epicOutcomeVerification(epic) {
|
|
10977
|
+
return buildOutcomeVerification(
|
|
10978
|
+
epic.successCriteria,
|
|
10979
|
+
parseEvidenceList(fm(epic, "outcome_verifications")),
|
|
10980
|
+
parseExceptions(fm(epic, "completion_exceptions"))
|
|
10981
|
+
);
|
|
10982
|
+
}
|
|
10983
|
+
function planOutcomeVerification(plan) {
|
|
10984
|
+
return buildOutcomeVerification(
|
|
10985
|
+
plan.successCriteria,
|
|
10986
|
+
parseEvidenceList(fm(plan, "outcome_verifications")),
|
|
10987
|
+
parseExceptions(fm(plan, "completion_exceptions"))
|
|
10988
|
+
);
|
|
10989
|
+
}
|
|
10990
|
+
function planMilestoneVerifications(plan) {
|
|
10991
|
+
const rawMs = Array.isArray(fm(plan, "milestones")) ? fm(plan, "milestones") : [];
|
|
10992
|
+
return plan.milestones.map((m) => {
|
|
10993
|
+
const rawEntry = rawMs.find((r) => r && typeof r === "object" && optStr4(r.id)?.toLowerCase() === m.id.toLowerCase());
|
|
10994
|
+
const evidence = parseEvidenceList(rawEntry?.exit_verifications);
|
|
10995
|
+
return { id: m.id, title: m.title, outcome: buildOutcomeVerification(m.exitCriteria, evidence) };
|
|
10996
|
+
});
|
|
10997
|
+
}
|
|
10998
|
+
function decide(blockers, softBlocks, hasAcceptedExceptions) {
|
|
10999
|
+
if (blockers.length > 0) return "BLOCKED";
|
|
11000
|
+
if (softBlocks.length > 0) return "NEEDS_WORK";
|
|
11001
|
+
return hasAcceptedExceptions ? "READY_WITH_EXCEPTIONS" : "READY_TO_COMPLETE";
|
|
11002
|
+
}
|
|
11003
|
+
function evaluateEpicCompletion(dir, epic) {
|
|
11004
|
+
const prog = computeEpicProgress(dir, epic);
|
|
11005
|
+
const exceptions = parseExceptions(fm(epic, "completion_exceptions"));
|
|
11006
|
+
const outcome = epicOutcomeVerification(epic);
|
|
11007
|
+
const blockers = [];
|
|
11008
|
+
const softBlocks = [];
|
|
11009
|
+
const reasons = [];
|
|
11010
|
+
const warnings = [];
|
|
11011
|
+
for (const d of prog.readiness.blockingDependencies) blockers.push(`Blocked by unfinished dependency ${d}.`);
|
|
11012
|
+
for (const f of integrityBlockers(dir, epic.id)) blockers.push(f);
|
|
11013
|
+
evaluateOutcomeInto(epic.outcome, true, outcome, blockers, softBlocks, reasons, warnings);
|
|
11014
|
+
if (prog.delivery.total > 0 && prog.delivery.completed < prog.delivery.total) {
|
|
11015
|
+
softBlocks.push("committed-work-incomplete");
|
|
11016
|
+
reasons.push(`Committed work is incomplete (${prog.delivery.completed}/${prog.delivery.total} Work Items completed).`);
|
|
11017
|
+
}
|
|
11018
|
+
const readiness = decide(blockers, softBlocks, exceptions.some((x) => x.status === "accepted"));
|
|
11019
|
+
pushReadinessReason(readiness, reasons);
|
|
11020
|
+
return {
|
|
11021
|
+
id: epic.id,
|
|
11022
|
+
kind: "epic",
|
|
11023
|
+
status: epic.status,
|
|
11024
|
+
readiness,
|
|
11025
|
+
reasons,
|
|
11026
|
+
blockers,
|
|
11027
|
+
warnings,
|
|
11028
|
+
outcome,
|
|
11029
|
+
delivery: { total: prog.delivery.total, completed: prog.delivery.completed, blocked: prog.delivery.blocked },
|
|
11030
|
+
blockingDependencies: prog.readiness.blockingDependencies,
|
|
11031
|
+
exceptions
|
|
11032
|
+
};
|
|
11033
|
+
}
|
|
11034
|
+
function evaluatePlanCompletion(dir, plan) {
|
|
11035
|
+
const prog = computePlanProgress(dir, plan);
|
|
11036
|
+
const exceptions = parseExceptions(fm(plan, "completion_exceptions"));
|
|
11037
|
+
const outcome = planOutcomeVerification(plan);
|
|
11038
|
+
const milestones = planMilestoneVerifications(plan);
|
|
11039
|
+
const epics = epicsInPlan(dir, plan.id).map((e) => ({ id: e.id, status: e.status }));
|
|
11040
|
+
const blockers = [];
|
|
11041
|
+
const softBlocks = [];
|
|
11042
|
+
const reasons = [];
|
|
11043
|
+
const warnings = [];
|
|
11044
|
+
for (const d of prog.readiness.blockingDependencies) blockers.push(`Blocked by unfinished dependency ${d}.`);
|
|
11045
|
+
for (const f of integrityBlockers(dir, plan.id)) blockers.push(f);
|
|
11046
|
+
evaluateOutcomeInto(plan.objective, false, outcome, blockers, softBlocks, reasons, warnings);
|
|
11047
|
+
if (!plan.objective) warnings.push("No objective is declared for this Plan (optional, but recommended for completion review).");
|
|
11048
|
+
if (prog.delivery.total > 0 && prog.delivery.completed < prog.delivery.total) {
|
|
11049
|
+
softBlocks.push("committed-work-incomplete");
|
|
11050
|
+
reasons.push(`Committed work is incomplete (${prog.delivery.completed}/${prog.delivery.total} Work Items completed).`);
|
|
11051
|
+
}
|
|
11052
|
+
if (epics.length === 0 && prog.delivery.total === 0) {
|
|
11053
|
+
softBlocks.push("no-committed-work");
|
|
11054
|
+
reasons.push("No Epics and no committed Work Items \u2014 the Plan has no verifiable deliverables yet.");
|
|
11055
|
+
}
|
|
11056
|
+
const openEpics = epics.filter((e) => e.status !== "completed" && e.status !== "cancelled");
|
|
11057
|
+
if (openEpics.length > 0) {
|
|
11058
|
+
softBlocks.push("epics-open");
|
|
11059
|
+
reasons.push(`${openEpics.length} Epic(s) not yet completed: ${openEpics.map((e) => e.id).join(", ")}.`);
|
|
11060
|
+
}
|
|
11061
|
+
for (const m of milestones) {
|
|
11062
|
+
if (m.outcome.failed > 0) {
|
|
11063
|
+
blockers.push(`Milestone ${m.id} has a failed exit criterion.`);
|
|
11064
|
+
}
|
|
11065
|
+
const pending = m.outcome.notVerified + m.outcome.manualReview;
|
|
11066
|
+
if (pending > 0) {
|
|
11067
|
+
softBlocks.push(`milestone-${m.id}-pending`);
|
|
11068
|
+
reasons.push(`Milestone ${m.id}: ${pending} exit criterion(s) not verified.`);
|
|
11069
|
+
}
|
|
11070
|
+
if (m.outcome.stale.length > 0) warnings.push(`Milestone ${m.id} has stale exit-criteria evidence.`);
|
|
11071
|
+
}
|
|
11072
|
+
const readiness = decide(blockers, softBlocks, exceptions.some((x) => x.status === "accepted"));
|
|
11073
|
+
pushReadinessReason(readiness, reasons);
|
|
11074
|
+
return {
|
|
11075
|
+
id: plan.id,
|
|
11076
|
+
kind: "plan",
|
|
11077
|
+
status: plan.status,
|
|
11078
|
+
readiness,
|
|
11079
|
+
reasons,
|
|
11080
|
+
blockers,
|
|
11081
|
+
warnings,
|
|
11082
|
+
outcome,
|
|
11083
|
+
delivery: { total: prog.delivery.total, completed: prog.delivery.completed, blocked: prog.delivery.blocked },
|
|
11084
|
+
blockingDependencies: prog.readiness.blockingDependencies,
|
|
11085
|
+
milestones,
|
|
11086
|
+
epics,
|
|
11087
|
+
exceptions
|
|
11088
|
+
};
|
|
11089
|
+
}
|
|
11090
|
+
function integrityBlockers(dir, subjectId) {
|
|
11091
|
+
return validatePlanningGraph(dir).filter((f) => f.level === "error" && f.subject.toLowerCase() === subjectId.toLowerCase()).map((f) => f.message);
|
|
11092
|
+
}
|
|
11093
|
+
function evaluateOutcomeInto(declaredOutcome, requireDeclaredOutcome, outcome, blockers, softBlocks, reasons, warnings) {
|
|
11094
|
+
if (requireDeclaredOutcome && !declaredOutcome) {
|
|
11095
|
+
softBlocks.push("no-outcome");
|
|
11096
|
+
reasons.push("No expected outcome is declared.");
|
|
11097
|
+
}
|
|
11098
|
+
if (outcome.total === 0) {
|
|
11099
|
+
softBlocks.push("no-success-criteria");
|
|
11100
|
+
reasons.push("No success criteria to verify \u2014 completion cannot be judged by outcome.");
|
|
11101
|
+
}
|
|
11102
|
+
if (outcome.ambiguous > 0) {
|
|
11103
|
+
softBlocks.push("criteria-ambiguous");
|
|
11104
|
+
reasons.push(`${outcome.ambiguous} success criterion(s) collide in text \u2014 rename to disambiguate before verifying.`);
|
|
11105
|
+
}
|
|
11106
|
+
if (outcome.failed > 0) {
|
|
11107
|
+
softBlocks.push("criteria-failed");
|
|
11108
|
+
reasons.push(`${outcome.failed} success criterion(s) failed verification.`);
|
|
11109
|
+
}
|
|
11110
|
+
const pending = outcome.notVerified + outcome.manualReview - outcome.ambiguous;
|
|
11111
|
+
if (pending > 0) {
|
|
11112
|
+
softBlocks.push("criteria-unverified");
|
|
11113
|
+
reasons.push(`${pending} success criterion(s) not verified (no or insufficient evidence).`);
|
|
11114
|
+
}
|
|
11115
|
+
if (outcome.stale.length > 0) warnings.push(`${outcome.stale.length} evidence record(s) no longer match a declared criterion (stale).`);
|
|
11116
|
+
}
|
|
11117
|
+
function pushReadinessReason(readiness, reasons) {
|
|
11118
|
+
if (readiness === "READY_TO_COMPLETE") reasons.unshift("All success criteria are verified and committed work is complete. Human approval is still required to close.");
|
|
11119
|
+
else if (readiness === "READY_WITH_EXCEPTIONS") reasons.unshift("Remaining gaps are covered by accepted exceptions. Human approval is still required to close.");
|
|
11120
|
+
}
|
|
11121
|
+
function evaluateEpicById(dir, id) {
|
|
11122
|
+
const e = getEpic(dir, id);
|
|
11123
|
+
return e ? evaluateEpicCompletion(dir, e) : null;
|
|
11124
|
+
}
|
|
11125
|
+
function evaluatePlanById(dir, id) {
|
|
11126
|
+
const p = getPlan(dir, id);
|
|
11127
|
+
return p ? evaluatePlanCompletion(dir, p) : null;
|
|
11128
|
+
}
|
|
11129
|
+
|
|
11130
|
+
// src/core/initiative-verification.ts
|
|
11131
|
+
function optStr5(v) {
|
|
11132
|
+
return typeof v === "string" && v.trim() ? v.trim() : void 0;
|
|
11133
|
+
}
|
|
11134
|
+
function parseCompletionExceptions(raw) {
|
|
11135
|
+
if (!Array.isArray(raw)) return [];
|
|
11136
|
+
const out = [];
|
|
11137
|
+
for (const entry of raw) {
|
|
11138
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
11139
|
+
const o = entry;
|
|
11140
|
+
const id = optStr5(o.id);
|
|
11141
|
+
if (!id) continue;
|
|
11142
|
+
const st = optStr5(o.status);
|
|
11143
|
+
out.push({
|
|
11144
|
+
id,
|
|
11145
|
+
status: st === "accepted" || st === "rejected" ? st : "proposed",
|
|
11146
|
+
...optStr5(o.criterion) ? { criterion: optStr5(o.criterion) } : {},
|
|
11147
|
+
...optStr5(o.reason) ? { reason: optStr5(o.reason) } : {}
|
|
11148
|
+
});
|
|
11149
|
+
}
|
|
11150
|
+
return out;
|
|
11151
|
+
}
|
|
11152
|
+
function initiativeOutcomeVerification(ini) {
|
|
11153
|
+
const declared = parseSuccessCriteria(ini.body).map((c) => c.text);
|
|
11154
|
+
const evidence = parseEvidenceList(ini.rawFrontmatter?.outcome_verifications);
|
|
11155
|
+
const exceptions = parseCompletionExceptions(ini.rawFrontmatter?.completion_exceptions);
|
|
11156
|
+
return buildOutcomeVerification(declared, evidence, exceptions);
|
|
11157
|
+
}
|
|
11158
|
+
function initiativeProvenanceIssues(dir, ini) {
|
|
11159
|
+
const issues = [];
|
|
11160
|
+
const wis = discoverWorkItems(dir);
|
|
11161
|
+
for (const c of ini.candidates) {
|
|
11162
|
+
if (!c.materializedAs) continue;
|
|
11163
|
+
const wi = wis.find((w) => w.id.toLowerCase() === c.materializedAs.toLowerCase());
|
|
11164
|
+
if (!wi) {
|
|
11165
|
+
issues.push(`Candidate ${c.id} points at missing Work Item ${c.materializedAs}.`);
|
|
11166
|
+
continue;
|
|
11167
|
+
}
|
|
11168
|
+
const owner = typeof wi.rawFrontmatter?.initiative === "string" ? wi.rawFrontmatter.initiative : void 0;
|
|
11169
|
+
if (owner && owner.toLowerCase() !== ini.id.toLowerCase()) {
|
|
11170
|
+
issues.push(`Work Item ${wi.id} (materialized from ${c.id}) is associated with ${owner}, not ${ini.id}.`);
|
|
11171
|
+
}
|
|
11172
|
+
}
|
|
11173
|
+
return issues;
|
|
11174
|
+
}
|
|
11175
|
+
function decide2(blockers, softBlocks, hasAcceptedExceptions) {
|
|
11176
|
+
if (blockers.length > 0) return "BLOCKED";
|
|
11177
|
+
if (softBlocks.length > 0) return "NEEDS_WORK";
|
|
11178
|
+
return hasAcceptedExceptions ? "READY_WITH_EXCEPTIONS" : "READY_TO_COMPLETE";
|
|
11179
|
+
}
|
|
11180
|
+
function evaluateInitiativeCompletion(dir, ini) {
|
|
11181
|
+
const progress = computeInitiativeProgress(dir, ini);
|
|
11182
|
+
const outcome = initiativeOutcomeVerification(ini);
|
|
11183
|
+
const exceptions = parseCompletionExceptions(ini.rawFrontmatter?.completion_exceptions);
|
|
11184
|
+
const pending = ini.candidates.filter((c) => !c.materializedAs);
|
|
11185
|
+
const associated = associatedWorkItems(dir, ini.id);
|
|
11186
|
+
const incomplete = associated.filter((w) => w.status !== "completed" && w.status !== "archived");
|
|
11187
|
+
const provenanceIssues = initiativeProvenanceIssues(dir, ini);
|
|
11188
|
+
const blockers = [];
|
|
11189
|
+
const softBlocks = [];
|
|
11190
|
+
const reasons = [];
|
|
11191
|
+
const warnings = [];
|
|
11192
|
+
for (const p of provenanceIssues) blockers.push(p);
|
|
11193
|
+
if (outcome.total === 0) {
|
|
11194
|
+
softBlocks.push("no-success-criteria");
|
|
11195
|
+
reasons.push("No success criteria to verify \u2014 completion cannot be judged by outcome.");
|
|
11196
|
+
}
|
|
11197
|
+
if (outcome.ambiguous > 0) {
|
|
11198
|
+
softBlocks.push("criteria-ambiguous");
|
|
11199
|
+
reasons.push(`${outcome.ambiguous} success criterion(s) collide in text \u2014 disambiguate before verifying.`);
|
|
11200
|
+
}
|
|
11201
|
+
if (outcome.failed > 0) {
|
|
11202
|
+
softBlocks.push("criteria-failed");
|
|
11203
|
+
reasons.push(`${outcome.failed} success criterion(s) failed verification.`);
|
|
11204
|
+
}
|
|
11205
|
+
const unverified = outcome.notVerified + outcome.manualReview - outcome.ambiguous;
|
|
11206
|
+
if (unverified > 0) {
|
|
11207
|
+
softBlocks.push("criteria-unverified");
|
|
11208
|
+
reasons.push(`${unverified} success criterion(s) not verified (no or insufficient evidence).`);
|
|
11209
|
+
}
|
|
11210
|
+
if (outcome.stale.length > 0) warnings.push(`${outcome.stale.length} evidence record(s) no longer match a declared criterion (stale).`);
|
|
11211
|
+
if (pending.length > 0) {
|
|
11212
|
+
softBlocks.push("pending-candidates");
|
|
11213
|
+
reasons.push(`${pending.length} committed candidate(s) not yet materialized.`);
|
|
11214
|
+
}
|
|
11215
|
+
if (incomplete.length > 0) {
|
|
11216
|
+
softBlocks.push("incomplete-delivery");
|
|
11217
|
+
reasons.push(`${incomplete.length} associated Work Item(s) are not completed.`);
|
|
11218
|
+
}
|
|
11219
|
+
if (associated.length === 0 && pending.length === 0) {
|
|
11220
|
+
softBlocks.push("no-deliverables");
|
|
11221
|
+
reasons.push("Nothing has been delivered or committed under this Initiative.");
|
|
11222
|
+
}
|
|
11223
|
+
const readiness = decide2(blockers, softBlocks, exceptions.some((x) => x.status === "accepted"));
|
|
11224
|
+
if (readiness === "READY_TO_COMPLETE") reasons.unshift("All success criteria are verified and committed scope is delivered. Human approval is still required to close.");
|
|
11225
|
+
else if (readiness === "READY_WITH_EXCEPTIONS") reasons.unshift("Remaining gaps are covered by accepted exceptions. Human approval is still required to close.");
|
|
11226
|
+
const completed = progress.delivery.byState?.completed ?? 0;
|
|
11227
|
+
return {
|
|
11228
|
+
id: ini.id,
|
|
11229
|
+
kind: "initiative",
|
|
11230
|
+
status: ini.status,
|
|
11231
|
+
readiness,
|
|
11232
|
+
ready: readiness === "READY_TO_COMPLETE" || readiness === "READY_WITH_EXCEPTIONS",
|
|
11233
|
+
reasons,
|
|
11234
|
+
blockers,
|
|
11235
|
+
warnings,
|
|
11236
|
+
outcome,
|
|
11237
|
+
delivery: { total: progress.delivery.total, completed, incomplete: incomplete.length },
|
|
11238
|
+
pendingCandidates: pending.map((c) => c.id),
|
|
11239
|
+
provenanceIssues,
|
|
11240
|
+
exceptions
|
|
11241
|
+
};
|
|
11242
|
+
}
|
|
11243
|
+
function evaluateInitiativeById(dir, id) {
|
|
11244
|
+
const ini = getInitiative(dir, id);
|
|
11245
|
+
return ini ? evaluateInitiativeCompletion(dir, ini) : null;
|
|
11246
|
+
}
|
|
11247
|
+
|
|
11248
|
+
// src/core/initiative-write.ts
|
|
10792
11249
|
var WORK_ITEMS_DIR = "knowledge/delivery/work-items";
|
|
10793
11250
|
var DRAFT_DIR = `${WORK_ITEMS_DIR}/draft`;
|
|
10794
11251
|
var ROADMAP_PATH2 = "knowledge/delivery/roadmap.md";
|
|
11252
|
+
function assertFreshInitiative(id, currentContent, opts) {
|
|
11253
|
+
if (!opts?.expectedRevision) return;
|
|
11254
|
+
const actual = revisionOf(currentContent);
|
|
11255
|
+
if (actual !== opts.expectedRevision) throw new InitiativeConflictError(id, opts.expectedRevision, actual);
|
|
11256
|
+
}
|
|
11257
|
+
function nextCandidateId(existing) {
|
|
11258
|
+
let max = 0;
|
|
11259
|
+
for (const c of existing) {
|
|
11260
|
+
const m = typeof c?.id === "string" ? c.id.match(/^WI-CANDIDATE-(\d+)$/i) : null;
|
|
11261
|
+
if (m) max = Math.max(max, Number.parseInt(m[1], 10));
|
|
11262
|
+
}
|
|
11263
|
+
return `WI-CANDIDATE-${String(max + 1).padStart(3, "0")}`;
|
|
11264
|
+
}
|
|
10795
11265
|
var InitiativeWriteError = class extends Error {
|
|
10796
11266
|
constructor(message) {
|
|
10797
11267
|
super(message);
|
|
10798
11268
|
this.name = "InitiativeWriteError";
|
|
10799
11269
|
}
|
|
10800
11270
|
};
|
|
11271
|
+
var InitiativeConflictError = class extends InitiativeWriteError {
|
|
11272
|
+
constructor(id, expectedRevision, actualRevision) {
|
|
11273
|
+
super(`Initiative "${id}" was modified since it was loaded (expected revision ${expectedRevision}, found ${actualRevision}). Reload and try again.`);
|
|
11274
|
+
this.id = id;
|
|
11275
|
+
this.expectedRevision = expectedRevision;
|
|
11276
|
+
this.actualRevision = actualRevision;
|
|
11277
|
+
this.name = "InitiativeConflictError";
|
|
11278
|
+
}
|
|
11279
|
+
id;
|
|
11280
|
+
expectedRevision;
|
|
11281
|
+
actualRevision;
|
|
11282
|
+
};
|
|
10801
11283
|
function slugify2(s) {
|
|
10802
11284
|
return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 50);
|
|
10803
11285
|
}
|
|
@@ -10819,563 +11301,490 @@ function externalLinkToData(l) {
|
|
|
10819
11301
|
const out = { integration: l.integration, external_id: l.externalId };
|
|
10820
11302
|
if (l.externalType) out.external_type = l.externalType;
|
|
10821
11303
|
if (l.url) out.url = l.url;
|
|
10822
|
-
if (l.externalStatus) out.external_status = l.externalStatus;
|
|
10823
|
-
return out;
|
|
10824
|
-
}
|
|
10825
|
-
function normalizeCandidate(input, fallbackId) {
|
|
10826
|
-
return {
|
|
10827
|
-
id: input.id?.trim() || fallbackId,
|
|
10828
|
-
title: input.title.trim(),
|
|
10829
|
-
type: input.type?.trim() || void 0,
|
|
10830
|
-
suggestedKnowledgeLevel: input.suggestedKnowledgeLevel?.trim() || void 0,
|
|
10831
|
-
expectedValue: input.expectedValue?.trim() || void 0,
|
|
10832
|
-
notes: input.notes?.trim() || void 0,
|
|
10833
|
-
sourceSignals: input.sourceSignals ?? [],
|
|
10834
|
-
dependencies: input.dependencies ?? [],
|
|
10835
|
-
materializedAs: input.materializedAs ?? null
|
|
10836
|
-
};
|
|
10837
|
-
}
|
|
10838
|
-
function defaultBody(title) {
|
|
10839
|
-
return [
|
|
10840
|
-
`# ${title}`,
|
|
10841
|
-
"",
|
|
10842
|
-
"## Goal",
|
|
10843
|
-
"",
|
|
10844
|
-
"_What outcome does this Initiative pursue?_",
|
|
10845
|
-
"",
|
|
10846
|
-
"## Expected Value",
|
|
10847
|
-
"",
|
|
10848
|
-
"_Why it matters._",
|
|
10849
|
-
"",
|
|
10850
|
-
"## Scope",
|
|
10851
|
-
"",
|
|
10852
|
-
"_What this Initiative covers._",
|
|
10853
|
-
"",
|
|
10854
|
-
"## Out of Scope",
|
|
10855
|
-
"",
|
|
10856
|
-
"_What it explicitly does not cover._",
|
|
10857
|
-
"",
|
|
10858
|
-
"## Success Criteria",
|
|
10859
|
-
"",
|
|
10860
|
-
'_Observable outcomes that define completion (not just "all Work Items done")._',
|
|
10861
|
-
"",
|
|
10862
|
-
"## Dependencies",
|
|
10863
|
-
"",
|
|
10864
|
-
"_Other Initiatives, modules, or external work this depends on._",
|
|
10865
|
-
"",
|
|
10866
|
-
"## Work Item Candidates",
|
|
10867
|
-
"",
|
|
10868
|
-
"_Candidates live in frontmatter `candidates`; summarize them here as they evolve._",
|
|
10869
|
-
"",
|
|
10870
|
-
"## Open Questions",
|
|
10871
|
-
"",
|
|
10872
|
-
"_Unresolved questions for this Initiative._",
|
|
10873
|
-
"",
|
|
10874
|
-
"## Learning",
|
|
10875
|
-
"",
|
|
10876
|
-
"_Captured on completion: what was delivered, what stayed out of scope, outcome reached._",
|
|
10877
|
-
""
|
|
10878
|
-
].join("\n");
|
|
10879
|
-
}
|
|
10880
|
-
function buildInitiativeContent(id, input) {
|
|
10881
|
-
const status = input.status ?? "planned";
|
|
10882
|
-
if (!isValidInitiativeStatus(status)) {
|
|
10883
|
-
throw new InitiativeWriteError(`Invalid initiative status: ${status}.`);
|
|
10884
|
-
}
|
|
10885
|
-
const candidates = (input.candidates ?? []).map(
|
|
10886
|
-
(c, i) => normalizeCandidate(c, `WI-CANDIDATE-${String(i + 1).padStart(3, "0")}`)
|
|
10887
|
-
);
|
|
10888
|
-
const data = {
|
|
10889
|
-
type: "initiative",
|
|
10890
|
-
id,
|
|
10891
|
-
title: input.title.trim(),
|
|
10892
|
-
status,
|
|
10893
|
-
knowledge_level: input.knowledgeLevel ?? "K2",
|
|
10894
|
-
domains: input.domains ?? [],
|
|
10895
|
-
related_capabilities: input.relatedCapabilities ?? [],
|
|
10896
|
-
created_at: today(),
|
|
10897
|
-
external_links: (input.externalLinks ?? []).map(externalLinkToData),
|
|
10898
|
-
candidates: candidates.map(candidateToData)
|
|
10899
|
-
};
|
|
10900
|
-
if (input.horizon) data.horizon = input.horizon;
|
|
10901
|
-
if (input.priority) data.priority = input.priority;
|
|
10902
|
-
if (input.source) data.source = input.source;
|
|
10903
|
-
if (input.sourceId) data.source_id = input.sourceId;
|
|
10904
|
-
if (input.epic) data.epic = input.epic.trim();
|
|
10905
|
-
if (input.owners?.length) data.owners = input.owners.map((o) => o.trim()).filter(Boolean);
|
|
10906
|
-
if (input.contributors?.length) data.contributors = input.contributors.map((c) => c.trim()).filter(Boolean);
|
|
10907
|
-
return matter12.stringify("\n" + (input.body ?? defaultBody(input.title.trim())), data);
|
|
10908
|
-
}
|
|
10909
|
-
function createInitiative(dir, input) {
|
|
10910
|
-
if (!input.title?.trim()) throw new InitiativeWriteError("Initiative title is required.");
|
|
10911
|
-
const id = nextInitiativeId(dir);
|
|
10912
|
-
const fileName = `${id}-${slugify2(input.title)}.md`;
|
|
10913
|
-
const iniDir = join(dir, INITIATIVES_DIR);
|
|
10914
|
-
ensureDir(iniDir);
|
|
10915
|
-
const filePath = join(iniDir, fileName);
|
|
10916
|
-
const content = buildInitiativeContent(id, input);
|
|
10917
|
-
writeFile(filePath, content);
|
|
10918
|
-
const ini = parseInitiative(dir, filePath, content);
|
|
10919
|
-
if (!ini) throw new InitiativeWriteError("Failed to parse the Initiative just written.");
|
|
10920
|
-
return ini;
|
|
10921
|
-
}
|
|
10922
|
-
function transitionInitiative(dir, id, to) {
|
|
10923
|
-
const ini = getInitiative(dir, id);
|
|
10924
|
-
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
10925
|
-
if (!isValidInitiativeStatus(to)) throw new InitiativeWriteError(`Invalid status: ${to}.`);
|
|
10926
|
-
if (ini.status === to) return ini;
|
|
10927
|
-
if (!isValidInitiativeTransition(ini.status, to)) {
|
|
10928
|
-
throw new InitiativeWriteError(`Invalid transition ${ini.status} \u2192 ${to}.`);
|
|
10929
|
-
}
|
|
10930
|
-
const raw = readFile(ini.filePath);
|
|
10931
|
-
const { data, content } = matter12(raw, {});
|
|
10932
|
-
data.status = to;
|
|
10933
|
-
if (to === "completed") data.completed_at = today();
|
|
10934
|
-
const newContent = matter12.stringify(content, data);
|
|
10935
|
-
writeFile(ini.filePath, newContent);
|
|
10936
|
-
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
10937
|
-
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after transition.");
|
|
10938
|
-
return updated;
|
|
10939
|
-
}
|
|
10940
|
-
function addCandidate(dir, id, candidate) {
|
|
10941
|
-
const ini = getInitiative(dir, id);
|
|
10942
|
-
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
10943
|
-
const raw = readFile(ini.filePath);
|
|
10944
|
-
const { data, content } = matter12(raw, {});
|
|
10945
|
-
const existing = Array.isArray(data.candidates) ? data.candidates : [];
|
|
10946
|
-
const fallbackId = `WI-CANDIDATE-${String(existing.length + 1).padStart(3, "0")}`;
|
|
10947
|
-
const normalized = normalizeCandidate(candidate, fallbackId);
|
|
10948
|
-
if (ini.candidates.some((c) => c.id === normalized.id)) {
|
|
10949
|
-
throw new InitiativeWriteError(`Candidate ${normalized.id} already exists in ${id}.`);
|
|
10950
|
-
}
|
|
10951
|
-
data.candidates = [...existing, candidateToData(normalized)];
|
|
10952
|
-
const newContent = matter12.stringify(content, data);
|
|
10953
|
-
writeFile(ini.filePath, newContent);
|
|
10954
|
-
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
10955
|
-
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after adding a candidate.");
|
|
10956
|
-
return updated;
|
|
10957
|
-
}
|
|
10958
|
-
function updateInitiative(dir, id, patch) {
|
|
10959
|
-
const ini = getInitiative(dir, id);
|
|
10960
|
-
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
10961
|
-
const raw = readFile(ini.filePath);
|
|
10962
|
-
const { data, content } = matter12(raw, {});
|
|
10963
|
-
if (patch.title !== void 0) {
|
|
10964
|
-
if (!patch.title.trim()) throw new InitiativeWriteError("Initiative title cannot be empty.");
|
|
10965
|
-
data.title = patch.title.trim();
|
|
10966
|
-
}
|
|
10967
|
-
if (patch.horizon !== void 0) data.horizon = patch.horizon;
|
|
10968
|
-
if (patch.priority !== void 0) data.priority = patch.priority;
|
|
10969
|
-
if (patch.knowledgeLevel !== void 0) data.knowledge_level = patch.knowledgeLevel;
|
|
10970
|
-
if (patch.domains !== void 0) data.domains = patch.domains;
|
|
10971
|
-
if (patch.relatedCapabilities !== void 0) data.related_capabilities = patch.relatedCapabilities;
|
|
10972
|
-
if (patch.epic !== void 0) {
|
|
10973
|
-
if (patch.epic === null || patch.epic.trim() === "") delete data.epic;
|
|
10974
|
-
else data.epic = patch.epic.trim();
|
|
10975
|
-
}
|
|
10976
|
-
if (patch.owners !== void 0) data.owners = patch.owners.map((o) => o.trim()).filter(Boolean);
|
|
10977
|
-
if (patch.contributors !== void 0) data.contributors = patch.contributors.map((c) => c.trim()).filter(Boolean);
|
|
10978
|
-
const newContent = matter12.stringify(content, data);
|
|
10979
|
-
writeFile(ini.filePath, newContent);
|
|
10980
|
-
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
10981
|
-
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after update.");
|
|
10982
|
-
return updated;
|
|
10983
|
-
}
|
|
10984
|
-
function addExternalLink(dir, id, link) {
|
|
10985
|
-
const ini = getInitiative(dir, id);
|
|
10986
|
-
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
10987
|
-
if (!link.integration?.trim() || !link.externalId?.trim()) {
|
|
10988
|
-
throw new InitiativeWriteError("External link requires integration and externalId.");
|
|
10989
|
-
}
|
|
10990
|
-
if (ini.externalLinks.some(
|
|
10991
|
-
(l) => l.integration.trim().toLowerCase() === link.integration.trim().toLowerCase() && l.externalId.trim().toLowerCase() === link.externalId.trim().toLowerCase()
|
|
10992
|
-
)) {
|
|
10993
|
-
throw new InitiativeWriteError(`External link ${link.integration}:${link.externalId} already exists on ${id}.`);
|
|
10994
|
-
}
|
|
10995
|
-
const raw = readFile(ini.filePath);
|
|
10996
|
-
const { data, content } = matter12(raw, {});
|
|
10997
|
-
const existing = Array.isArray(data.external_links) ? data.external_links : [];
|
|
10998
|
-
data.external_links = [...existing, externalLinkToData(link)];
|
|
10999
|
-
const newContent = matter12.stringify(content, data);
|
|
11000
|
-
writeFile(ini.filePath, newContent);
|
|
11001
|
-
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
11002
|
-
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after adding an external link.");
|
|
11003
|
-
return updated;
|
|
11304
|
+
if (l.externalStatus) out.external_status = l.externalStatus;
|
|
11305
|
+
return out;
|
|
11004
11306
|
}
|
|
11005
|
-
function
|
|
11006
|
-
|
|
11007
|
-
|
|
11008
|
-
|
|
11009
|
-
|
|
11010
|
-
|
|
11011
|
-
|
|
11012
|
-
|
|
11013
|
-
|
|
11014
|
-
|
|
11015
|
-
|
|
11016
|
-
walk2(full);
|
|
11017
|
-
}
|
|
11018
|
-
}
|
|
11307
|
+
function normalizeCandidate(input, fallbackId) {
|
|
11308
|
+
return {
|
|
11309
|
+
id: input.id?.trim() || fallbackId,
|
|
11310
|
+
title: input.title.trim(),
|
|
11311
|
+
type: input.type?.trim() || void 0,
|
|
11312
|
+
suggestedKnowledgeLevel: input.suggestedKnowledgeLevel?.trim() || void 0,
|
|
11313
|
+
expectedValue: input.expectedValue?.trim() || void 0,
|
|
11314
|
+
notes: input.notes?.trim() || void 0,
|
|
11315
|
+
sourceSignals: input.sourceSignals ?? [],
|
|
11316
|
+
dependencies: input.dependencies ?? [],
|
|
11317
|
+
materializedAs: input.materializedAs ?? null
|
|
11019
11318
|
};
|
|
11020
|
-
walk2(wiDir);
|
|
11021
|
-
return `WI-${String(max + 1).padStart(3, "0")}`;
|
|
11022
11319
|
}
|
|
11023
|
-
function
|
|
11024
|
-
|
|
11025
|
-
|
|
11026
|
-
id: wiId,
|
|
11027
|
-
title: candidate.title,
|
|
11028
|
-
knowledge_level: candidate.suggestedKnowledgeLevel ?? "K2",
|
|
11029
|
-
status: "draft",
|
|
11030
|
-
phase: "now",
|
|
11031
|
-
initiative: iniId,
|
|
11032
|
-
domains: [],
|
|
11033
|
-
code: [],
|
|
11034
|
-
created_at: today(),
|
|
11035
|
-
source: "initiative",
|
|
11036
|
-
source_id: candidate.id,
|
|
11037
|
-
source_initiative: iniId,
|
|
11038
|
-
affected_modules: []
|
|
11039
|
-
};
|
|
11040
|
-
if (candidate.sourceSignals.length) data.source_signals = candidate.sourceSignals;
|
|
11041
|
-
if (candidate.dependencies.length) data.dependencies = candidate.dependencies;
|
|
11042
|
-
const body = [
|
|
11043
|
-
`# ${candidate.title}`,
|
|
11320
|
+
function defaultBody(title) {
|
|
11321
|
+
return [
|
|
11322
|
+
`# ${title}`,
|
|
11044
11323
|
"",
|
|
11045
|
-
|
|
11324
|
+
"## Goal",
|
|
11046
11325
|
"",
|
|
11047
|
-
"
|
|
11326
|
+
"_What outcome does this Initiative pursue?_",
|
|
11048
11327
|
"",
|
|
11049
|
-
|
|
11328
|
+
"## Expected Value",
|
|
11050
11329
|
"",
|
|
11051
|
-
"
|
|
11330
|
+
"_Why it matters._",
|
|
11052
11331
|
"",
|
|
11053
|
-
"
|
|
11332
|
+
"## Scope",
|
|
11054
11333
|
"",
|
|
11055
|
-
"
|
|
11334
|
+
"_What this Initiative covers._",
|
|
11056
11335
|
"",
|
|
11057
|
-
"
|
|
11336
|
+
"## Out of Scope",
|
|
11058
11337
|
"",
|
|
11059
|
-
"
|
|
11338
|
+
"_What it explicitly does not cover._",
|
|
11060
11339
|
"",
|
|
11061
|
-
"
|
|
11340
|
+
"## Success Criteria",
|
|
11341
|
+
"",
|
|
11342
|
+
'_Observable outcomes that define completion (not just "all Work Items done")._',
|
|
11343
|
+
"",
|
|
11344
|
+
"## Dependencies",
|
|
11345
|
+
"",
|
|
11346
|
+
"_Other Initiatives, modules, or external work this depends on._",
|
|
11347
|
+
"",
|
|
11348
|
+
"## Work Item Candidates",
|
|
11349
|
+
"",
|
|
11350
|
+
"_Candidates live in frontmatter `candidates`; summarize them here as they evolve._",
|
|
11351
|
+
"",
|
|
11352
|
+
"## Open Questions",
|
|
11353
|
+
"",
|
|
11354
|
+
"_Unresolved questions for this Initiative._",
|
|
11062
11355
|
"",
|
|
11063
11356
|
"## Learning",
|
|
11064
11357
|
"",
|
|
11065
|
-
"
|
|
11358
|
+
"_Captured on completion: what was delivered, what stayed out of scope, outcome reached._",
|
|
11066
11359
|
""
|
|
11067
11360
|
].join("\n");
|
|
11068
|
-
return matter12.stringify("\n" + body, data);
|
|
11069
|
-
}
|
|
11070
|
-
function materializeCandidate(dir, id, candidateId) {
|
|
11071
|
-
const ini = getInitiative(dir, id);
|
|
11072
|
-
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
11073
|
-
const candidate = ini.candidates.find((c) => c.id === candidateId);
|
|
11074
|
-
if (!candidate) throw new InitiativeWriteError(`Candidate ${candidateId} not found in ${id}.`);
|
|
11075
|
-
if (candidate.materializedAs) {
|
|
11076
|
-
throw new InitiativeWriteError(
|
|
11077
|
-
`Candidate ${candidateId} is already materialized as ${candidate.materializedAs}.`
|
|
11078
|
-
);
|
|
11079
|
-
}
|
|
11080
|
-
const wiId = nextWorkItemId(dir);
|
|
11081
|
-
const fileName = `${wiId}-${slugify2(candidate.title)}.md`;
|
|
11082
|
-
ensureDir(join(dir, DRAFT_DIR));
|
|
11083
|
-
writeFile(join(dir, DRAFT_DIR, fileName), buildWorkItemContent(wiId, ini.id, candidate));
|
|
11084
|
-
const raw = readFile(ini.filePath);
|
|
11085
|
-
const { data, content } = matter12(raw, {});
|
|
11086
|
-
const cands = Array.isArray(data.candidates) ? data.candidates : [];
|
|
11087
|
-
for (const c of cands) {
|
|
11088
|
-
if (c && typeof c === "object" && String(c.id) === candidateId) c.materialized_as = wiId;
|
|
11089
|
-
}
|
|
11090
|
-
data.candidates = cands;
|
|
11091
|
-
const newContent = matter12.stringify(content, data);
|
|
11092
|
-
writeFile(ini.filePath, newContent);
|
|
11093
|
-
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
11094
|
-
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after materialization.");
|
|
11095
|
-
return { workItemId: wiId, fileName, initiative: updated };
|
|
11096
|
-
}
|
|
11097
|
-
function materializeRoadmapInitiative(dir, rmId) {
|
|
11098
|
-
const roadmapFull = join(dir, ROADMAP_PATH2);
|
|
11099
|
-
if (!exists(roadmapFull)) throw new InitiativeWriteError(`No roadmap found at ${ROADMAP_PATH2}.`);
|
|
11100
|
-
const all = parseRoadmapCandidates(readFile(roadmapFull));
|
|
11101
|
-
const want = rmId.trim().toLowerCase();
|
|
11102
|
-
const belonging = all.filter((c) => (c.initiative?.id ?? "").toLowerCase() === want);
|
|
11103
|
-
if (belonging.length === 0) {
|
|
11104
|
-
throw new InitiativeWriteError(`No roadmap initiative "${rmId}" with candidates found.`);
|
|
11105
|
-
}
|
|
11106
|
-
const title = belonging[0].initiative?.title?.trim() || rmId;
|
|
11107
|
-
const candidates = belonging.map((c) => ({
|
|
11108
|
-
id: c.id,
|
|
11109
|
-
title: c.title,
|
|
11110
|
-
type: c.type,
|
|
11111
|
-
suggestedKnowledgeLevel: c.suggestedKnowledgeLevel,
|
|
11112
|
-
expectedValue: c.expectedValue,
|
|
11113
|
-
notes: c.notes,
|
|
11114
|
-
sourceSignals: c.sourceSignals ?? [],
|
|
11115
|
-
dependencies: c.dependencies ?? [],
|
|
11116
|
-
materializedAs: null
|
|
11117
|
-
}));
|
|
11118
|
-
const domains = belonging[0].domain ? [belonging[0].domain] : [];
|
|
11119
|
-
const relatedCapabilities = Array.from(
|
|
11120
|
-
new Set(belonging.flatMap((c) => c.relatedCapabilities ?? []))
|
|
11121
|
-
);
|
|
11122
|
-
return createInitiative(dir, {
|
|
11123
|
-
title,
|
|
11124
|
-
status: "planned",
|
|
11125
|
-
domains,
|
|
11126
|
-
relatedCapabilities,
|
|
11127
|
-
source: "roadmap",
|
|
11128
|
-
sourceId: rmId,
|
|
11129
|
-
candidates
|
|
11130
|
-
});
|
|
11131
|
-
}
|
|
11132
|
-
|
|
11133
|
-
// src/core/delivery-verification.ts
|
|
11134
|
-
function normalizeCriterion(text2) {
|
|
11135
|
-
return text2.trim().toLowerCase().replace(/\s+/g, " ");
|
|
11136
|
-
}
|
|
11137
|
-
var STATUSES = ["passed", "failed", "not-verified", "manual-review-required"];
|
|
11138
|
-
function optStr4(v) {
|
|
11139
|
-
if (typeof v === "string" && v.trim()) return v.trim();
|
|
11140
|
-
if (typeof v === "number") return String(v);
|
|
11141
|
-
return void 0;
|
|
11142
|
-
}
|
|
11143
|
-
function parseEvidenceList(raw) {
|
|
11144
|
-
if (!Array.isArray(raw)) return [];
|
|
11145
|
-
const out = [];
|
|
11146
|
-
for (const entry of raw) {
|
|
11147
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
11148
|
-
const o = entry;
|
|
11149
|
-
const criterion = optStr4(o.criterion);
|
|
11150
|
-
if (!criterion) continue;
|
|
11151
|
-
const statusRaw = optStr4(o.status);
|
|
11152
|
-
const status = STATUSES.includes(statusRaw ?? "") ? statusRaw : "not-verified";
|
|
11153
|
-
const method = optStr4(o.method);
|
|
11154
|
-
out.push({
|
|
11155
|
-
criterion,
|
|
11156
|
-
status,
|
|
11157
|
-
...optStr4(o.evidence) ? { evidence: optStr4(o.evidence) } : {},
|
|
11158
|
-
...optStr4(o.reference) ? { reference: optStr4(o.reference) } : {},
|
|
11159
|
-
...method === "automated" || method === "manual" ? { method } : {},
|
|
11160
|
-
...optStr4(o.verified_at) ? { verified_at: optStr4(o.verified_at) } : {},
|
|
11161
|
-
...optStr4(o.verified_by) ? { verified_by: optStr4(o.verified_by) } : {}
|
|
11162
|
-
});
|
|
11163
|
-
}
|
|
11164
|
-
return out;
|
|
11165
11361
|
}
|
|
11166
|
-
function
|
|
11167
|
-
|
|
11168
|
-
|
|
11169
|
-
|
|
11170
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
11171
|
-
const o = entry;
|
|
11172
|
-
const id = optStr4(o.id);
|
|
11173
|
-
if (!id) continue;
|
|
11174
|
-
const st = optStr4(o.status);
|
|
11175
|
-
const status = st === "accepted" || st === "rejected" ? st : "proposed";
|
|
11176
|
-
out.push({
|
|
11177
|
-
id,
|
|
11178
|
-
status,
|
|
11179
|
-
...optStr4(o.criterion) ? { criterion: optStr4(o.criterion) } : {},
|
|
11180
|
-
...optStr4(o.reason) ? { reason: optStr4(o.reason) } : {}
|
|
11181
|
-
});
|
|
11362
|
+
function buildInitiativeContent(id, input) {
|
|
11363
|
+
const status = input.status ?? "planned";
|
|
11364
|
+
if (!isValidInitiativeStatus(status)) {
|
|
11365
|
+
throw new InitiativeWriteError(`Invalid initiative status: ${status}.`);
|
|
11182
11366
|
}
|
|
11183
|
-
|
|
11184
|
-
}
|
|
11185
|
-
function buildOutcomeVerification(declared, evidence, exceptions = []) {
|
|
11186
|
-
const byCriterion = /* @__PURE__ */ new Map();
|
|
11187
|
-
for (const e of evidence) byCriterion.set(normalizeCriterion(e.criterion), e);
|
|
11188
|
-
const declaredKeys = new Set(declared.map(normalizeCriterion));
|
|
11189
|
-
const counts = /* @__PURE__ */ new Map();
|
|
11190
|
-
for (const c of declared) counts.set(normalizeCriterion(c), (counts.get(normalizeCriterion(c)) ?? 0) + 1);
|
|
11191
|
-
const ambiguousKeys = new Set([...counts.entries()].filter(([, n]) => n > 1).map(([k]) => k));
|
|
11192
|
-
const waived = new Set(
|
|
11193
|
-
exceptions.filter((x) => x.status === "accepted" && x.reason?.trim() && x.criterion && declaredKeys.has(normalizeCriterion(x.criterion)) && !ambiguousKeys.has(normalizeCriterion(x.criterion))).map((x) => normalizeCriterion(x.criterion))
|
|
11367
|
+
const candidates = (input.candidates ?? []).map(
|
|
11368
|
+
(c, i) => normalizeCandidate(c, `WI-CANDIDATE-${String(i + 1).padStart(3, "0")}`)
|
|
11194
11369
|
);
|
|
11195
|
-
const
|
|
11196
|
-
|
|
11197
|
-
|
|
11198
|
-
|
|
11199
|
-
|
|
11200
|
-
|
|
11201
|
-
|
|
11202
|
-
|
|
11203
|
-
|
|
11204
|
-
|
|
11205
|
-
|
|
11206
|
-
...e?.verified_by ? { verifiedBy: e.verified_by } : {},
|
|
11207
|
-
...!ambiguous && waived.has(key) ? { waived: true } : {},
|
|
11208
|
-
...ambiguous ? { ambiguous: true } : {}
|
|
11209
|
-
};
|
|
11210
|
-
});
|
|
11211
|
-
const stale = evidence.filter((e) => !declaredKeys.has(normalizeCriterion(e.criterion)));
|
|
11212
|
-
return {
|
|
11213
|
-
total: criteria.length,
|
|
11214
|
-
// An ambiguous criterion is never counted as passed/waived; it counts as unverified until disambiguated.
|
|
11215
|
-
passed: criteria.filter((c) => !c.ambiguous && (c.status === "passed" || c.waived)).length,
|
|
11216
|
-
failed: criteria.filter((c) => !c.ambiguous && c.status === "failed" && !c.waived).length,
|
|
11217
|
-
notVerified: criteria.filter((c) => c.ambiguous || c.status === "not-verified" && !c.waived).length,
|
|
11218
|
-
manualReview: criteria.filter((c) => !c.ambiguous && c.status === "manual-review-required" && !c.waived).length,
|
|
11219
|
-
ambiguous: criteria.filter((c) => c.ambiguous).length,
|
|
11220
|
-
criteria,
|
|
11221
|
-
stale
|
|
11370
|
+
const data = {
|
|
11371
|
+
type: "initiative",
|
|
11372
|
+
id,
|
|
11373
|
+
title: input.title.trim(),
|
|
11374
|
+
status,
|
|
11375
|
+
knowledge_level: input.knowledgeLevel ?? "K2",
|
|
11376
|
+
domains: input.domains ?? [],
|
|
11377
|
+
related_capabilities: input.relatedCapabilities ?? [],
|
|
11378
|
+
created_at: today(),
|
|
11379
|
+
external_links: (input.externalLinks ?? []).map(externalLinkToData),
|
|
11380
|
+
candidates: candidates.map(candidateToData)
|
|
11222
11381
|
};
|
|
11382
|
+
if (input.horizon) data.horizon = input.horizon;
|
|
11383
|
+
if (input.priority) data.priority = input.priority;
|
|
11384
|
+
if (input.source) data.source = input.source;
|
|
11385
|
+
if (input.sourceId) data.source_id = input.sourceId;
|
|
11386
|
+
if (input.epic) data.epic = input.epic.trim();
|
|
11387
|
+
if (input.owners?.length) data.owners = input.owners.map((o) => o.trim()).filter(Boolean);
|
|
11388
|
+
if (input.contributors?.length) data.contributors = input.contributors.map((c) => c.trim()).filter(Boolean);
|
|
11389
|
+
return matter12.stringify("\n" + (input.body ?? defaultBody(input.title.trim())), data);
|
|
11223
11390
|
}
|
|
11224
|
-
function
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11228
|
-
|
|
11229
|
-
|
|
11230
|
-
|
|
11231
|
-
|
|
11232
|
-
);
|
|
11391
|
+
function createInitiative(dir, input) {
|
|
11392
|
+
if (!input.title?.trim()) throw new InitiativeWriteError("Initiative title is required.");
|
|
11393
|
+
const id = nextInitiativeId(dir);
|
|
11394
|
+
const fileName = `${id}-${slugify2(input.title)}.md`;
|
|
11395
|
+
const iniDir = join(dir, INITIATIVES_DIR);
|
|
11396
|
+
ensureDir(iniDir);
|
|
11397
|
+
const filePath = join(iniDir, fileName);
|
|
11398
|
+
const content = buildInitiativeContent(id, input);
|
|
11399
|
+
writeFile(filePath, content);
|
|
11400
|
+
const ini = parseInitiative(dir, filePath, content);
|
|
11401
|
+
if (!ini) throw new InitiativeWriteError("Failed to parse the Initiative just written.");
|
|
11402
|
+
return ini;
|
|
11233
11403
|
}
|
|
11234
|
-
function
|
|
11235
|
-
|
|
11236
|
-
|
|
11237
|
-
|
|
11238
|
-
|
|
11239
|
-
);
|
|
11404
|
+
function transitionInitiative(dir, id, to, opts) {
|
|
11405
|
+
const ini = getInitiative(dir, id);
|
|
11406
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
11407
|
+
if (!isValidInitiativeStatus(to)) throw new InitiativeWriteError(`Invalid status: ${to}.`);
|
|
11408
|
+
if (to === "completed") throw new InitiativeWriteError(`Completing Initiative ${id} requires evidence-based review \u2014 use completeInitiative.`);
|
|
11409
|
+
if (ini.status === to) return ini;
|
|
11410
|
+
if (!isValidInitiativeTransition(ini.status, to)) {
|
|
11411
|
+
throw new InitiativeWriteError(`Invalid transition ${ini.status} \u2192 ${to}.`);
|
|
11412
|
+
}
|
|
11413
|
+
const raw = readFile(ini.filePath);
|
|
11414
|
+
assertFreshInitiative(ini.id, raw, opts);
|
|
11415
|
+
const { data, content } = matter12(raw, {});
|
|
11416
|
+
data.status = to;
|
|
11417
|
+
const newContent = matter12.stringify(content, data);
|
|
11418
|
+
writeFile(ini.filePath, newContent);
|
|
11419
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
11420
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after transition.");
|
|
11421
|
+
return updated;
|
|
11240
11422
|
}
|
|
11241
|
-
function
|
|
11242
|
-
const
|
|
11243
|
-
|
|
11244
|
-
const
|
|
11245
|
-
const
|
|
11246
|
-
|
|
11247
|
-
|
|
11423
|
+
function findMaterializedWorkItem(dir, initiativeId, candidateId) {
|
|
11424
|
+
for (const wi of discoverWorkItems(dir)) {
|
|
11425
|
+
const fm2 = wi.rawFrontmatter ?? {};
|
|
11426
|
+
const si = typeof fm2.source_initiative === "string" ? fm2.source_initiative : void 0;
|
|
11427
|
+
const sid = typeof fm2.source_id === "string" ? fm2.source_id : void 0;
|
|
11428
|
+
if (si?.toLowerCase() === initiativeId.toLowerCase() && sid === candidateId) {
|
|
11429
|
+
return { id: wi.id, initiative: typeof fm2.initiative === "string" ? fm2.initiative : void 0 };
|
|
11430
|
+
}
|
|
11431
|
+
}
|
|
11432
|
+
return null;
|
|
11248
11433
|
}
|
|
11249
|
-
function
|
|
11250
|
-
|
|
11251
|
-
if (
|
|
11252
|
-
|
|
11434
|
+
function addCandidate(dir, id, candidate, opts) {
|
|
11435
|
+
const ini = getInitiative(dir, id);
|
|
11436
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
11437
|
+
const raw = readFile(ini.filePath);
|
|
11438
|
+
assertFreshInitiative(ini.id, raw, opts);
|
|
11439
|
+
const { data, content } = matter12(raw, {});
|
|
11440
|
+
const existing = Array.isArray(data.candidates) ? data.candidates : [];
|
|
11441
|
+
const removed = Array.isArray(data.removed_candidates) ? data.removed_candidates : [];
|
|
11442
|
+
const fallbackId = nextCandidateId([...existing, ...removed]);
|
|
11443
|
+
const normalized = normalizeCandidate(candidate, fallbackId);
|
|
11444
|
+
normalized.materializedAs = null;
|
|
11445
|
+
if (ini.candidates.some((c) => c.id === normalized.id)) {
|
|
11446
|
+
throw new InitiativeWriteError(`Candidate ${normalized.id} already exists in ${id}.`);
|
|
11447
|
+
}
|
|
11448
|
+
data.candidates = [...existing, candidateToData(normalized)];
|
|
11449
|
+
const newContent = matter12.stringify(content, data);
|
|
11450
|
+
writeFile(ini.filePath, newContent);
|
|
11451
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
11452
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after adding a candidate.");
|
|
11453
|
+
return updated;
|
|
11253
11454
|
}
|
|
11254
|
-
function
|
|
11255
|
-
const
|
|
11256
|
-
const
|
|
11257
|
-
|
|
11258
|
-
|
|
11259
|
-
|
|
11260
|
-
|
|
11261
|
-
|
|
11262
|
-
|
|
11263
|
-
|
|
11264
|
-
|
|
11265
|
-
|
|
11266
|
-
softBlocks.push("committed-work-incomplete");
|
|
11267
|
-
reasons.push(`Committed work is incomplete (${prog.delivery.completed}/${prog.delivery.total} Work Items completed).`);
|
|
11455
|
+
function replaceBodySection(body, heading, newContent) {
|
|
11456
|
+
const lines = body.split(/\r?\n/);
|
|
11457
|
+
const want = heading.trim().toLowerCase();
|
|
11458
|
+
let start = -1;
|
|
11459
|
+
let level = 0;
|
|
11460
|
+
for (let i = 0; i < lines.length; i++) {
|
|
11461
|
+
const h = lines[i].match(/^(#{1,6})\s+(.*)$/);
|
|
11462
|
+
if (h && h[2].trim().toLowerCase() === want) {
|
|
11463
|
+
start = i;
|
|
11464
|
+
level = h[1].length;
|
|
11465
|
+
break;
|
|
11466
|
+
}
|
|
11268
11467
|
}
|
|
11269
|
-
const
|
|
11270
|
-
|
|
11271
|
-
|
|
11272
|
-
|
|
11273
|
-
|
|
11274
|
-
|
|
11275
|
-
|
|
11276
|
-
|
|
11277
|
-
|
|
11278
|
-
|
|
11279
|
-
|
|
11280
|
-
|
|
11281
|
-
|
|
11282
|
-
|
|
11283
|
-
|
|
11468
|
+
const block = `${"#".repeat(level || 2)} ${heading.trim()}
|
|
11469
|
+
|
|
11470
|
+
${newContent.trim()}
|
|
11471
|
+
`;
|
|
11472
|
+
if (start === -1) {
|
|
11473
|
+
return `${body.trimEnd()}
|
|
11474
|
+
|
|
11475
|
+
${block}`;
|
|
11476
|
+
}
|
|
11477
|
+
let end = lines.length;
|
|
11478
|
+
for (let i = start + 1; i < lines.length; i++) {
|
|
11479
|
+
const h = lines[i].match(/^(#{1,6})\s+/);
|
|
11480
|
+
if (h && h[1].length <= level) {
|
|
11481
|
+
end = i;
|
|
11482
|
+
break;
|
|
11483
|
+
}
|
|
11484
|
+
}
|
|
11485
|
+
const before = lines.slice(0, start).join("\n").replace(/\s+$/, "");
|
|
11486
|
+
const after = lines.slice(end).join("\n").replace(/^\s+/, "");
|
|
11487
|
+
return [before, before ? "" : null, block.trimEnd(), after ? "" : null, after].filter((x) => x !== null).join("\n").replace(/\n{3,}/g, "\n\n");
|
|
11284
11488
|
}
|
|
11285
|
-
function
|
|
11286
|
-
const
|
|
11287
|
-
|
|
11288
|
-
const
|
|
11289
|
-
|
|
11290
|
-
|
|
11291
|
-
|
|
11292
|
-
|
|
11293
|
-
|
|
11294
|
-
const warnings = [];
|
|
11295
|
-
for (const d of prog.readiness.blockingDependencies) blockers.push(`Blocked by unfinished dependency ${d}.`);
|
|
11296
|
-
for (const f of integrityBlockers(dir, plan.id)) blockers.push(f);
|
|
11297
|
-
evaluateOutcomeInto(plan.objective, false, outcome, blockers, softBlocks, reasons, warnings);
|
|
11298
|
-
if (!plan.objective) warnings.push("No objective is declared for this Plan (optional, but recommended for completion review).");
|
|
11299
|
-
if (prog.delivery.total > 0 && prog.delivery.completed < prog.delivery.total) {
|
|
11300
|
-
softBlocks.push("committed-work-incomplete");
|
|
11301
|
-
reasons.push(`Committed work is incomplete (${prog.delivery.completed}/${prog.delivery.total} Work Items completed).`);
|
|
11489
|
+
function updateInitiative(dir, id, patch, opts) {
|
|
11490
|
+
const ini = getInitiative(dir, id);
|
|
11491
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
11492
|
+
const raw = readFile(ini.filePath);
|
|
11493
|
+
assertFreshInitiative(ini.id, raw, opts);
|
|
11494
|
+
let { data, content } = matter12(raw, {});
|
|
11495
|
+
if (patch.title !== void 0) {
|
|
11496
|
+
if (!patch.title.trim()) throw new InitiativeWriteError("Initiative title cannot be empty.");
|
|
11497
|
+
data.title = patch.title.trim();
|
|
11302
11498
|
}
|
|
11303
|
-
if (
|
|
11304
|
-
|
|
11305
|
-
|
|
11499
|
+
if (patch.horizon !== void 0) data.horizon = patch.horizon;
|
|
11500
|
+
if (patch.priority !== void 0) data.priority = patch.priority;
|
|
11501
|
+
if (patch.knowledgeLevel !== void 0) data.knowledge_level = patch.knowledgeLevel;
|
|
11502
|
+
if (patch.domains !== void 0) data.domains = patch.domains;
|
|
11503
|
+
if (patch.relatedCapabilities !== void 0) data.related_capabilities = patch.relatedCapabilities;
|
|
11504
|
+
if (patch.epic !== void 0) {
|
|
11505
|
+
if (patch.epic === null || patch.epic.trim() === "") delete data.epic;
|
|
11506
|
+
else data.epic = patch.epic.trim();
|
|
11306
11507
|
}
|
|
11307
|
-
|
|
11308
|
-
if (
|
|
11309
|
-
|
|
11310
|
-
|
|
11508
|
+
if (patch.owners !== void 0) data.owners = patch.owners.map((o) => o.trim()).filter(Boolean);
|
|
11509
|
+
if (patch.contributors !== void 0) data.contributors = patch.contributors.map((c) => c.trim()).filter(Boolean);
|
|
11510
|
+
if (patch.sections) {
|
|
11511
|
+
for (const [heading, value] of Object.entries(patch.sections)) content = replaceBodySection(content, heading, value);
|
|
11311
11512
|
}
|
|
11312
|
-
|
|
11313
|
-
|
|
11314
|
-
|
|
11315
|
-
|
|
11316
|
-
|
|
11317
|
-
|
|
11318
|
-
|
|
11319
|
-
|
|
11320
|
-
|
|
11321
|
-
|
|
11513
|
+
const newContent = matter12.stringify(content, data);
|
|
11514
|
+
writeFile(ini.filePath, newContent);
|
|
11515
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
11516
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after update.");
|
|
11517
|
+
return updated;
|
|
11518
|
+
}
|
|
11519
|
+
function updateCandidate(dir, id, candidateId, patch, opts) {
|
|
11520
|
+
const ini = getInitiative(dir, id);
|
|
11521
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
11522
|
+
const current = ini.candidates.find((c) => c.id === candidateId);
|
|
11523
|
+
if (!current) throw new InitiativeWriteError(`Candidate ${candidateId} not found in ${id}.`);
|
|
11524
|
+
if (current.materializedAs) throw new InitiativeWriteError(`Candidate ${candidateId} is materialized as ${current.materializedAs}; edit the Work Item instead.`);
|
|
11525
|
+
const raw = readFile(ini.filePath);
|
|
11526
|
+
assertFreshInitiative(ini.id, raw, opts);
|
|
11527
|
+
const { data, content } = matter12(raw, {});
|
|
11528
|
+
const cands = Array.isArray(data.candidates) ? data.candidates : [];
|
|
11529
|
+
const entry = cands.find((c) => c && typeof c === "object" && String(c.id) === candidateId);
|
|
11530
|
+
if (!entry) throw new InitiativeWriteError(`Candidate ${candidateId} entry not found in ${id} frontmatter.`);
|
|
11531
|
+
if (patch.title !== void 0) entry.title = patch.title.trim();
|
|
11532
|
+
if (patch.type !== void 0) entry.type = patch.type?.trim() || void 0;
|
|
11533
|
+
if (patch.suggestedKnowledgeLevel !== void 0) entry.suggested_knowledge_level = patch.suggestedKnowledgeLevel?.trim() || void 0;
|
|
11534
|
+
if (patch.expectedValue !== void 0) entry.expected_value = patch.expectedValue?.trim() || void 0;
|
|
11535
|
+
if (patch.notes !== void 0) entry.notes = patch.notes?.trim() || void 0;
|
|
11536
|
+
if (patch.sourceSignals !== void 0) entry.source_signals = patch.sourceSignals;
|
|
11537
|
+
if (patch.dependencies !== void 0) entry.dependencies = patch.dependencies;
|
|
11538
|
+
for (const k of Object.keys(entry)) if (entry[k] === void 0) delete entry[k];
|
|
11539
|
+
data.candidates = cands;
|
|
11540
|
+
const newContent = matter12.stringify(content, data);
|
|
11541
|
+
writeFile(ini.filePath, newContent);
|
|
11542
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
11543
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after editing a candidate.");
|
|
11544
|
+
return updated;
|
|
11545
|
+
}
|
|
11546
|
+
function removeCandidate(dir, id, candidateId, reason, opts) {
|
|
11547
|
+
if (!reason?.trim()) throw new InitiativeWriteError("A justification is required to remove a candidate.");
|
|
11548
|
+
const ini = getInitiative(dir, id);
|
|
11549
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
11550
|
+
const current = ini.candidates.find((c) => c.id === candidateId);
|
|
11551
|
+
if (!current) throw new InitiativeWriteError(`Candidate ${candidateId} not found in ${id}.`);
|
|
11552
|
+
if (current.materializedAs) throw new InitiativeWriteError(`Candidate ${candidateId} is materialized as ${current.materializedAs}; it cannot be removed from scope.`);
|
|
11553
|
+
const raw = readFile(ini.filePath);
|
|
11554
|
+
assertFreshInitiative(ini.id, raw, opts);
|
|
11555
|
+
const { data, content } = matter12(raw, {});
|
|
11556
|
+
const cands = Array.isArray(data.candidates) ? data.candidates : [];
|
|
11557
|
+
data.candidates = cands.filter((c) => !(c && typeof c === "object" && String(c.id) === candidateId));
|
|
11558
|
+
const log2 = Array.isArray(data.removed_candidates) ? data.removed_candidates : [];
|
|
11559
|
+
log2.push({ id: candidateId, title: current.title, reason: reason.trim(), removed_at: today() });
|
|
11560
|
+
data.removed_candidates = log2;
|
|
11561
|
+
const newContent = matter12.stringify(content, data);
|
|
11562
|
+
writeFile(ini.filePath, newContent);
|
|
11563
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
11564
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after removing a candidate.");
|
|
11565
|
+
return updated;
|
|
11566
|
+
}
|
|
11567
|
+
function addExternalLink(dir, id, link) {
|
|
11568
|
+
const ini = getInitiative(dir, id);
|
|
11569
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
11570
|
+
if (!link.integration?.trim() || !link.externalId?.trim()) {
|
|
11571
|
+
throw new InitiativeWriteError("External link requires integration and externalId.");
|
|
11322
11572
|
}
|
|
11323
|
-
|
|
11324
|
-
|
|
11325
|
-
|
|
11326
|
-
|
|
11327
|
-
|
|
11328
|
-
|
|
11329
|
-
|
|
11330
|
-
|
|
11331
|
-
|
|
11332
|
-
|
|
11333
|
-
|
|
11334
|
-
|
|
11335
|
-
|
|
11336
|
-
|
|
11337
|
-
|
|
11338
|
-
|
|
11573
|
+
if (ini.externalLinks.some(
|
|
11574
|
+
(l) => l.integration.trim().toLowerCase() === link.integration.trim().toLowerCase() && l.externalId.trim().toLowerCase() === link.externalId.trim().toLowerCase()
|
|
11575
|
+
)) {
|
|
11576
|
+
throw new InitiativeWriteError(`External link ${link.integration}:${link.externalId} already exists on ${id}.`);
|
|
11577
|
+
}
|
|
11578
|
+
const raw = readFile(ini.filePath);
|
|
11579
|
+
const { data, content } = matter12(raw, {});
|
|
11580
|
+
const existing = Array.isArray(data.external_links) ? data.external_links : [];
|
|
11581
|
+
data.external_links = [...existing, externalLinkToData(link)];
|
|
11582
|
+
const newContent = matter12.stringify(content, data);
|
|
11583
|
+
writeFile(ini.filePath, newContent);
|
|
11584
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
11585
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after adding an external link.");
|
|
11586
|
+
return updated;
|
|
11587
|
+
}
|
|
11588
|
+
function nextWorkItemId(dir) {
|
|
11589
|
+
const wiDir = join(dir, WORK_ITEMS_DIR);
|
|
11590
|
+
let max = 0;
|
|
11591
|
+
const walk2 = (d) => {
|
|
11592
|
+
if (!exists(d)) return;
|
|
11593
|
+
for (const entry of readDir(d)) {
|
|
11594
|
+
const full = join(d, entry);
|
|
11595
|
+
if (isFile(full)) {
|
|
11596
|
+
const m = entry.match(/WI-(\d+)/);
|
|
11597
|
+
if (m) max = Math.max(max, parseInt(m[1], 10));
|
|
11598
|
+
} else if (!entry.startsWith(".")) {
|
|
11599
|
+
walk2(full);
|
|
11600
|
+
}
|
|
11601
|
+
}
|
|
11602
|
+
};
|
|
11603
|
+
walk2(wiDir);
|
|
11604
|
+
return `WI-${String(max + 1).padStart(3, "0")}`;
|
|
11605
|
+
}
|
|
11606
|
+
function buildWorkItemContent(wiId, iniId, candidate) {
|
|
11607
|
+
const data = {
|
|
11608
|
+
type: candidate.type ?? "feature",
|
|
11609
|
+
id: wiId,
|
|
11610
|
+
title: candidate.title,
|
|
11611
|
+
knowledge_level: candidate.suggestedKnowledgeLevel ?? "K2",
|
|
11612
|
+
status: "draft",
|
|
11613
|
+
phase: "now",
|
|
11614
|
+
initiative: iniId,
|
|
11615
|
+
domains: [],
|
|
11616
|
+
code: [],
|
|
11617
|
+
created_at: today(),
|
|
11618
|
+
source: "initiative",
|
|
11619
|
+
source_id: candidate.id,
|
|
11620
|
+
source_initiative: iniId,
|
|
11621
|
+
affected_modules: []
|
|
11339
11622
|
};
|
|
11623
|
+
if (candidate.sourceSignals.length) data.source_signals = candidate.sourceSignals;
|
|
11624
|
+
if (candidate.dependencies.length) data.dependencies = candidate.dependencies;
|
|
11625
|
+
const body = [
|
|
11626
|
+
`# ${candidate.title}`,
|
|
11627
|
+
"",
|
|
11628
|
+
`> Materialized from Initiative ${iniId}, candidate ${candidate.id}.`,
|
|
11629
|
+
"",
|
|
11630
|
+
"## Problem",
|
|
11631
|
+
"",
|
|
11632
|
+
candidate.expectedValue ? `_Expected value:_ ${candidate.expectedValue}` : "_Describe the problem._",
|
|
11633
|
+
"",
|
|
11634
|
+
"## Acceptance Criteria",
|
|
11635
|
+
"",
|
|
11636
|
+
"- [ ] _Define at least one testable criterion._",
|
|
11637
|
+
"",
|
|
11638
|
+
"## Out of scope",
|
|
11639
|
+
"",
|
|
11640
|
+
"_Not included in this Work Item._",
|
|
11641
|
+
"",
|
|
11642
|
+
"## Validation",
|
|
11643
|
+
"",
|
|
11644
|
+
"_How will this be validated?_",
|
|
11645
|
+
"",
|
|
11646
|
+
"## Learning",
|
|
11647
|
+
"",
|
|
11648
|
+
"_What did we learn? Update after completion._",
|
|
11649
|
+
""
|
|
11650
|
+
].join("\n");
|
|
11651
|
+
return matter12.stringify("\n" + body, data);
|
|
11340
11652
|
}
|
|
11341
|
-
function
|
|
11342
|
-
|
|
11653
|
+
function setCandidateMaterialized(dir, ini, candidateId, wiId) {
|
|
11654
|
+
const raw = readFile(ini.filePath);
|
|
11655
|
+
const { data, content } = matter12(raw, {});
|
|
11656
|
+
const cands = Array.isArray(data.candidates) ? data.candidates : [];
|
|
11657
|
+
for (const c of cands) if (c && typeof c === "object" && String(c.id) === candidateId) c.materialized_as = wiId;
|
|
11658
|
+
data.candidates = cands;
|
|
11659
|
+
const newContent = matter12.stringify(content, data);
|
|
11660
|
+
writeFile(ini.filePath, newContent);
|
|
11661
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
11662
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after materialization.");
|
|
11663
|
+
return updated;
|
|
11343
11664
|
}
|
|
11344
|
-
function
|
|
11345
|
-
|
|
11346
|
-
|
|
11347
|
-
|
|
11348
|
-
|
|
11349
|
-
if (
|
|
11350
|
-
|
|
11351
|
-
|
|
11352
|
-
|
|
11353
|
-
|
|
11354
|
-
softBlocks.push("criteria-ambiguous");
|
|
11355
|
-
reasons.push(`${outcome.ambiguous} success criterion(s) collide in text \u2014 rename to disambiguate before verifying.`);
|
|
11665
|
+
function materializeCandidate(dir, id, candidateId, opts) {
|
|
11666
|
+
const ini = getInitiative(dir, id);
|
|
11667
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
11668
|
+
assertFreshInitiative(ini.id, readFile(ini.filePath), opts);
|
|
11669
|
+
const candidate = ini.candidates.find((c) => c.id === candidateId);
|
|
11670
|
+
if (!candidate) throw new InitiativeWriteError(`Candidate ${candidateId} not found in ${id}.`);
|
|
11671
|
+
if (candidate.materializedAs) {
|
|
11672
|
+
const exists2 = discoverWorkItems(dir).some((w) => w.id.toLowerCase() === candidate.materializedAs.toLowerCase());
|
|
11673
|
+
if (!exists2) throw new InitiativeWriteError(`Candidate ${candidateId} points at missing Work Item ${candidate.materializedAs} (broken relation). Resolve it before materializing.`);
|
|
11674
|
+
return { workItemId: candidate.materializedAs, fileName: null, initiative: ini, alreadyMaterialized: true };
|
|
11356
11675
|
}
|
|
11357
|
-
|
|
11358
|
-
|
|
11359
|
-
|
|
11676
|
+
const existing = findMaterializedWorkItem(dir, ini.id, candidateId);
|
|
11677
|
+
if (existing) {
|
|
11678
|
+
if (existing.initiative && existing.initiative.toLowerCase() !== ini.id.toLowerCase()) {
|
|
11679
|
+
throw new InitiativeWriteError(`A Work Item for candidate ${candidateId} already belongs to ${existing.initiative} (conflicting provenance).`);
|
|
11680
|
+
}
|
|
11681
|
+
const repaired = setCandidateMaterialized(dir, ini, candidateId, existing.id);
|
|
11682
|
+
return { workItemId: existing.id, fileName: null, initiative: repaired, alreadyMaterialized: true };
|
|
11360
11683
|
}
|
|
11361
|
-
const
|
|
11362
|
-
|
|
11363
|
-
|
|
11364
|
-
|
|
11684
|
+
const wiId = nextWorkItemId(dir);
|
|
11685
|
+
const fileName = `${wiId}-${slugify2(candidate.title)}.md`;
|
|
11686
|
+
ensureDir(join(dir, DRAFT_DIR));
|
|
11687
|
+
writeFile(join(dir, DRAFT_DIR, fileName), buildWorkItemContent(wiId, ini.id, candidate));
|
|
11688
|
+
const updated = setCandidateMaterialized(dir, ini, candidateId, wiId);
|
|
11689
|
+
return { workItemId: wiId, fileName, initiative: updated, alreadyMaterialized: false };
|
|
11690
|
+
}
|
|
11691
|
+
function materializeRoadmapInitiative(dir, rmId) {
|
|
11692
|
+
const roadmapFull = join(dir, ROADMAP_PATH2);
|
|
11693
|
+
if (!exists(roadmapFull)) throw new InitiativeWriteError(`No roadmap found at ${ROADMAP_PATH2}.`);
|
|
11694
|
+
const all = parseRoadmapCandidates(readFile(roadmapFull));
|
|
11695
|
+
const want = rmId.trim().toLowerCase();
|
|
11696
|
+
const belonging = all.filter((c) => (c.initiative?.id ?? "").toLowerCase() === want);
|
|
11697
|
+
if (belonging.length === 0) {
|
|
11698
|
+
throw new InitiativeWriteError(`No roadmap initiative "${rmId}" with candidates found.`);
|
|
11365
11699
|
}
|
|
11366
|
-
|
|
11700
|
+
const title = belonging[0].initiative?.title?.trim() || rmId;
|
|
11701
|
+
const candidates = belonging.map((c) => ({
|
|
11702
|
+
id: c.id,
|
|
11703
|
+
title: c.title,
|
|
11704
|
+
type: c.type,
|
|
11705
|
+
suggestedKnowledgeLevel: c.suggestedKnowledgeLevel,
|
|
11706
|
+
expectedValue: c.expectedValue,
|
|
11707
|
+
notes: c.notes,
|
|
11708
|
+
sourceSignals: c.sourceSignals ?? [],
|
|
11709
|
+
dependencies: c.dependencies ?? [],
|
|
11710
|
+
materializedAs: null
|
|
11711
|
+
}));
|
|
11712
|
+
const domains = belonging[0].domain ? [belonging[0].domain] : [];
|
|
11713
|
+
const relatedCapabilities = Array.from(
|
|
11714
|
+
new Set(belonging.flatMap((c) => c.relatedCapabilities ?? []))
|
|
11715
|
+
);
|
|
11716
|
+
return createInitiative(dir, {
|
|
11717
|
+
title,
|
|
11718
|
+
status: "planned",
|
|
11719
|
+
domains,
|
|
11720
|
+
relatedCapabilities,
|
|
11721
|
+
source: "roadmap",
|
|
11722
|
+
sourceId: rmId,
|
|
11723
|
+
candidates
|
|
11724
|
+
});
|
|
11367
11725
|
}
|
|
11368
|
-
function
|
|
11369
|
-
|
|
11370
|
-
|
|
11726
|
+
function assertDeclaredCriterion(declared, criterion) {
|
|
11727
|
+
const key = normalizeCriterion(criterion);
|
|
11728
|
+
const matches = declared.filter((c) => normalizeCriterion(c) === key).length;
|
|
11729
|
+
if (matches === 0) throw new InitiativeWriteError(`"${criterion}" is not a declared success criterion.`);
|
|
11730
|
+
if (matches > 1) throw new InitiativeWriteError(`"${criterion}" matches more than one declared criterion \u2014 disambiguate before recording evidence.`);
|
|
11371
11731
|
}
|
|
11372
|
-
function
|
|
11373
|
-
const
|
|
11374
|
-
|
|
11732
|
+
function upsertEvidence(existing, input) {
|
|
11733
|
+
const list2 = (Array.isArray(existing) ? existing : []).filter((e) => e && typeof e === "object" && !Array.isArray(e));
|
|
11734
|
+
const key = normalizeCriterion(input.criterion);
|
|
11735
|
+
const kept = list2.filter((e) => normalizeCriterion(String(e.criterion ?? "")) !== key);
|
|
11736
|
+
const obj = { criterion: input.criterion.trim(), status: input.status };
|
|
11737
|
+
if (input.evidence?.trim()) obj.evidence = input.evidence.trim();
|
|
11738
|
+
if (input.reference?.trim()) obj.reference = input.reference.trim();
|
|
11739
|
+
if (input.method) obj.method = input.method;
|
|
11740
|
+
obj.verified_at = today();
|
|
11741
|
+
if (input.verifiedBy?.trim()) obj.verified_by = input.verifiedBy.trim();
|
|
11742
|
+
return [...kept, obj];
|
|
11375
11743
|
}
|
|
11376
|
-
function
|
|
11377
|
-
const
|
|
11378
|
-
|
|
11744
|
+
function recordInitiativeOutcomeVerification(dir, id, input, opts) {
|
|
11745
|
+
const ini = getInitiative(dir, id);
|
|
11746
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
11747
|
+
assertDeclaredCriterion(parseSuccessCriteria(ini.body).map((c) => c.text), input.criterion);
|
|
11748
|
+
const raw = readFile(ini.filePath);
|
|
11749
|
+
assertFreshInitiative(ini.id, raw, opts);
|
|
11750
|
+
const { data, content } = matter12(raw, {});
|
|
11751
|
+
data.outcome_verifications = upsertEvidence(data.outcome_verifications, input);
|
|
11752
|
+
const newContent = matter12.stringify(content, data);
|
|
11753
|
+
writeFile(ini.filePath, newContent);
|
|
11754
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
11755
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after recording evidence.");
|
|
11756
|
+
return updated;
|
|
11757
|
+
}
|
|
11758
|
+
var InitiativeNotReadyError = class extends InitiativeWriteError {
|
|
11759
|
+
constructor(evaluation) {
|
|
11760
|
+
super(`Initiative ${evaluation.id} is not ready to complete (${evaluation.readiness}).`);
|
|
11761
|
+
this.evaluation = evaluation;
|
|
11762
|
+
this.name = "InitiativeNotReadyError";
|
|
11763
|
+
}
|
|
11764
|
+
evaluation;
|
|
11765
|
+
};
|
|
11766
|
+
function completeInitiative(dir, id, input = {}, opts) {
|
|
11767
|
+
const ini = getInitiative(dir, id);
|
|
11768
|
+
if (!ini) throw new InitiativeWriteError(`Initiative ${id} not found.`);
|
|
11769
|
+
const evaluation = evaluateInitiativeCompletion(dir, ini);
|
|
11770
|
+
if (evaluation.readiness !== "READY_TO_COMPLETE" && evaluation.readiness !== "READY_WITH_EXCEPTIONS") throw new InitiativeNotReadyError(evaluation);
|
|
11771
|
+
if (!isValidInitiativeTransition(ini.status, "completed")) throw new InitiativeWriteError(`Initiative ${id} cannot move from ${ini.status} to completed.`);
|
|
11772
|
+
const raw = readFile(ini.filePath);
|
|
11773
|
+
assertFreshInitiative(ini.id, raw, opts);
|
|
11774
|
+
const { data, content } = matter12(raw, {});
|
|
11775
|
+
data.status = "completed";
|
|
11776
|
+
data.completed_at = today();
|
|
11777
|
+
const decision = { readiness: evaluation.readiness, decided_at: today(), reasons: evaluation.reasons };
|
|
11778
|
+
if (input.decidedBy?.trim()) decision.decided_by = input.decidedBy.trim();
|
|
11779
|
+
if (input.note?.trim()) decision.note = input.note.trim();
|
|
11780
|
+
const accepted = evaluation.exceptions.filter((x) => x.status === "accepted");
|
|
11781
|
+
if (accepted.length > 0) decision.exceptions = accepted;
|
|
11782
|
+
data.completion_decision = decision;
|
|
11783
|
+
const newContent = matter12.stringify(content, data);
|
|
11784
|
+
writeFile(ini.filePath, newContent);
|
|
11785
|
+
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
11786
|
+
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after completion.");
|
|
11787
|
+
return updated;
|
|
11379
11788
|
}
|
|
11380
11789
|
|
|
11381
11790
|
// src/core/delivery-planning-write.ts
|
|
@@ -11668,7 +12077,7 @@ function assertCriterionDeclared(declared, criterion, kind) {
|
|
|
11668
12077
|
if (matches === 0) throw new DeliveryPlanningWriteError(`"${criterion}" is not a declared ${kind} criterion.`);
|
|
11669
12078
|
if (matches > 1) throw new DeliveryPlanningWriteError(`"${criterion}" matches more than one declared ${kind} criterion \u2014 rename them to disambiguate before recording evidence.`);
|
|
11670
12079
|
}
|
|
11671
|
-
function
|
|
12080
|
+
function upsertEvidence2(existing, input) {
|
|
11672
12081
|
const list2 = Array.isArray(existing) ? existing.filter((e) => e && typeof e === "object" && !Array.isArray(e)) : [];
|
|
11673
12082
|
const key = normalizeCriterion(input.criterion);
|
|
11674
12083
|
const kept = list2.filter((e) => normalizeCriterion(String(e.criterion ?? "")) !== key);
|
|
@@ -11687,7 +12096,7 @@ function recordEpicOutcomeVerification(dir, id, input, opts) {
|
|
|
11687
12096
|
const raw = readFile(epic.filePath);
|
|
11688
12097
|
assertFreshRevision(epic.id, raw, opts);
|
|
11689
12098
|
const { data, content } = matter13(raw, {});
|
|
11690
|
-
data.outcome_verifications =
|
|
12099
|
+
data.outcome_verifications = upsertEvidence2(data.outcome_verifications, input);
|
|
11691
12100
|
const newContent = matter13.stringify(content, data);
|
|
11692
12101
|
writeFile(epic.filePath, newContent);
|
|
11693
12102
|
const updated = parseEpic(dir, epic.filePath, newContent);
|
|
@@ -11701,7 +12110,7 @@ function recordPlanOutcomeVerification(dir, id, input, opts) {
|
|
|
11701
12110
|
const raw = readFile(plan.filePath);
|
|
11702
12111
|
assertFreshRevision(plan.id, raw, opts);
|
|
11703
12112
|
const { data, content } = matter13(raw, {});
|
|
11704
|
-
data.outcome_verifications =
|
|
12113
|
+
data.outcome_verifications = upsertEvidence2(data.outcome_verifications, input);
|
|
11705
12114
|
const newContent = matter13.stringify(content, data);
|
|
11706
12115
|
writeFile(plan.filePath, newContent);
|
|
11707
12116
|
const updated = parseDeliveryPlan(dir, plan.filePath, newContent);
|
|
@@ -11720,7 +12129,7 @@ function recordMilestoneExitVerification(dir, planId, milestoneId, input, opts)
|
|
|
11720
12129
|
const rawMs = Array.isArray(data.milestones) ? data.milestones : [];
|
|
11721
12130
|
const entry = rawMs.find((m) => m && typeof m === "object" && String(m.id ?? "").toLowerCase() === milestoneId.toLowerCase());
|
|
11722
12131
|
if (!entry) throw new DeliveryPlanningWriteError(`Milestone ${milestoneId} entry not found in ${planId} frontmatter.`);
|
|
11723
|
-
entry.exit_verifications =
|
|
12132
|
+
entry.exit_verifications = upsertEvidence2(entry.exit_verifications, input);
|
|
11724
12133
|
data.milestones = rawMs;
|
|
11725
12134
|
const newContent = matter13.stringify(content, data);
|
|
11726
12135
|
writeFile(plan.filePath, newContent);
|
|
@@ -13243,7 +13652,7 @@ function normalizeImpact(ia) {
|
|
|
13243
13652
|
...v.question ? { question: v.question } : {}
|
|
13244
13653
|
}));
|
|
13245
13654
|
}
|
|
13246
|
-
function
|
|
13655
|
+
function optStr6(v) {
|
|
13247
13656
|
if (typeof v === "string" && v.trim()) return v.trim();
|
|
13248
13657
|
return void 0;
|
|
13249
13658
|
}
|
|
@@ -13258,13 +13667,13 @@ function parseEvidence(fm2) {
|
|
|
13258
13667
|
const validations = Array.isArray(d.validations) ? d.validations.map((v) => ({
|
|
13259
13668
|
command: String(v.command ?? ""),
|
|
13260
13669
|
status: String(v.status ?? "unknown"),
|
|
13261
|
-
...
|
|
13670
|
+
...optStr6(v.reason) ? { reason: optStr6(v.reason) } : {}
|
|
13262
13671
|
})) : [];
|
|
13263
13672
|
const migrations = Array.isArray(d.migrations) ? d.migrations.map((m) => ({
|
|
13264
13673
|
id: String(m.id ?? ""),
|
|
13265
13674
|
environment: String(m.environment ?? ""),
|
|
13266
13675
|
status: String(m.status ?? "unknown"),
|
|
13267
|
-
...
|
|
13676
|
+
...optStr6(m.reason) ? { reason: optStr6(m.reason) } : {}
|
|
13268
13677
|
})) : [];
|
|
13269
13678
|
out.push({
|
|
13270
13679
|
module,
|
|
@@ -13282,8 +13691,8 @@ function parseReleaseGates(fm2) {
|
|
|
13282
13691
|
return fm2.release_gates.filter((g) => g && typeof g === "object").map((g) => ({
|
|
13283
13692
|
id: String(g.id ?? ""),
|
|
13284
13693
|
status: String(g.status ?? "pending"),
|
|
13285
|
-
...
|
|
13286
|
-
...
|
|
13694
|
+
...optStr6(g.reason) ? { reason: optStr6(g.reason) } : {},
|
|
13695
|
+
...optStr6(g.required_for) ? { requiredFor: optStr6(g.required_for) } : {}
|
|
13287
13696
|
}));
|
|
13288
13697
|
}
|
|
13289
13698
|
function parseExceptions2(fm2) {
|
|
@@ -13291,9 +13700,9 @@ function parseExceptions2(fm2) {
|
|
|
13291
13700
|
return fm2.completion_exceptions.filter((e) => e && typeof e === "object").map((e) => ({
|
|
13292
13701
|
id: String(e.id ?? ""),
|
|
13293
13702
|
status: String(e.status ?? "proposed"),
|
|
13294
|
-
...
|
|
13295
|
-
...
|
|
13296
|
-
...
|
|
13703
|
+
...optStr6(e.reason) ? { reason: optStr6(e.reason) } : {},
|
|
13704
|
+
...optStr6(e.category) ? { category: optStr6(e.category) } : {},
|
|
13705
|
+
...optStr6(e.impact) ? { impact: optStr6(e.impact) } : {}
|
|
13297
13706
|
}));
|
|
13298
13707
|
}
|
|
13299
13708
|
function parseDecisions(decisions, knowledgeById) {
|
|
@@ -17093,112 +17502,6 @@ function getStatus(dir) {
|
|
|
17093
17502
|
};
|
|
17094
17503
|
}
|
|
17095
17504
|
|
|
17096
|
-
// src/core/initiative-analysis.ts
|
|
17097
|
-
var SUCCESS_HEADING_RE = /^#{1,6}\s*(success criteria|criterios de[ét]xito|criterios de éxito)\s*$/i;
|
|
17098
|
-
var HEADING_RE2 = /^#{1,6}\s+/;
|
|
17099
|
-
var CHECK_ITEM_RE = /^\s*[-*]\s+\[([ xX])\]\s+(.*)$/;
|
|
17100
|
-
var BULLET_RE2 = /^\s*[-*]\s+(.*)$/;
|
|
17101
|
-
var PLACEHOLDER_RE = /^_.*_$/;
|
|
17102
|
-
function parseSuccessCriteria(body) {
|
|
17103
|
-
const lines = body.split(/\r?\n/);
|
|
17104
|
-
const out = [];
|
|
17105
|
-
let capture = false;
|
|
17106
|
-
for (const line of lines) {
|
|
17107
|
-
if (capture && HEADING_RE2.test(line)) break;
|
|
17108
|
-
if (!capture) {
|
|
17109
|
-
if (SUCCESS_HEADING_RE.test(line.trim())) capture = true;
|
|
17110
|
-
continue;
|
|
17111
|
-
}
|
|
17112
|
-
const check = line.match(CHECK_ITEM_RE);
|
|
17113
|
-
if (check) {
|
|
17114
|
-
const text2 = check[2].trim();
|
|
17115
|
-
if (text2 && !PLACEHOLDER_RE.test(text2)) {
|
|
17116
|
-
out.push({ text: text2, checked: check[1].toLowerCase() === "x" });
|
|
17117
|
-
}
|
|
17118
|
-
continue;
|
|
17119
|
-
}
|
|
17120
|
-
const bullet = line.match(BULLET_RE2);
|
|
17121
|
-
if (bullet) {
|
|
17122
|
-
const text2 = bullet[1].trim();
|
|
17123
|
-
if (text2 && !PLACEHOLDER_RE.test(text2)) out.push({ text: text2, checked: null });
|
|
17124
|
-
}
|
|
17125
|
-
}
|
|
17126
|
-
return out;
|
|
17127
|
-
}
|
|
17128
|
-
function analyzeInitiative(dir, ini) {
|
|
17129
|
-
const progress = computeInitiativeProgress(dir, ini);
|
|
17130
|
-
const successCriteria = parseSuccessCriteria(ini.body);
|
|
17131
|
-
const pendingCandidates = ini.candidates.filter((c) => !c.materializedAs);
|
|
17132
|
-
const associated = associatedWorkItems(dir, ini.id);
|
|
17133
|
-
const findings = [];
|
|
17134
|
-
if (successCriteria.length === 0) {
|
|
17135
|
-
findings.push({
|
|
17136
|
-
code: "no-success-criteria",
|
|
17137
|
-
severity: "warning",
|
|
17138
|
-
message: "The Initiative has no explicit Success Criteria; completion cannot be judged by outcome, only by delivery."
|
|
17139
|
-
});
|
|
17140
|
-
} else {
|
|
17141
|
-
const uncovered = successCriteria.filter((c) => c.checked === false);
|
|
17142
|
-
if (uncovered.length > 0) {
|
|
17143
|
-
findings.push({
|
|
17144
|
-
code: "uncovered-success-criteria",
|
|
17145
|
-
severity: "blocking",
|
|
17146
|
-
message: `${uncovered.length} success criterion/criteria remain uncovered.`,
|
|
17147
|
-
items: uncovered.map((c) => c.text)
|
|
17148
|
-
});
|
|
17149
|
-
}
|
|
17150
|
-
}
|
|
17151
|
-
if (pendingCandidates.length > 0) {
|
|
17152
|
-
findings.push({
|
|
17153
|
-
code: "pending-candidates",
|
|
17154
|
-
severity: "blocking",
|
|
17155
|
-
message: `${pendingCandidates.length} committed candidate(s) not yet materialized into Work Items.`,
|
|
17156
|
-
items: pendingCandidates.map((c) => `${c.id}: ${c.title}`)
|
|
17157
|
-
});
|
|
17158
|
-
}
|
|
17159
|
-
const notCompleted = associated.filter((w) => w.status !== "completed" && w.status !== "archived");
|
|
17160
|
-
if (associated.length === 0) {
|
|
17161
|
-
findings.push({
|
|
17162
|
-
code: "no-delivery",
|
|
17163
|
-
severity: "info",
|
|
17164
|
-
message: "No Work Items are associated with this Initiative yet."
|
|
17165
|
-
});
|
|
17166
|
-
} else if (notCompleted.length > 0) {
|
|
17167
|
-
findings.push({
|
|
17168
|
-
code: "incomplete-delivery",
|
|
17169
|
-
severity: "blocking",
|
|
17170
|
-
message: `${notCompleted.length} associated Work Item(s) are not completed.`,
|
|
17171
|
-
items: notCompleted.map((w) => `${w.id} (${w.status})`)
|
|
17172
|
-
});
|
|
17173
|
-
}
|
|
17174
|
-
return {
|
|
17175
|
-
initiative: ini.id,
|
|
17176
|
-
status: ini.status,
|
|
17177
|
-
progress,
|
|
17178
|
-
successCriteria,
|
|
17179
|
-
pendingCandidates,
|
|
17180
|
-
findings,
|
|
17181
|
-
suggestedCandidates: pendingCandidates
|
|
17182
|
-
};
|
|
17183
|
-
}
|
|
17184
|
-
function evaluateInitiativeCompletion(dir, ini) {
|
|
17185
|
-
const analysis = analyzeInitiative(dir, ini);
|
|
17186
|
-
const reasons = [];
|
|
17187
|
-
for (const f of analysis.findings) {
|
|
17188
|
-
if (f.severity === "blocking") reasons.push(f.message);
|
|
17189
|
-
}
|
|
17190
|
-
if (analysis.progress.delivery.total === 0 && analysis.pendingCandidates.length === 0) {
|
|
17191
|
-
reasons.push("Nothing has been delivered or committed under this Initiative.");
|
|
17192
|
-
}
|
|
17193
|
-
const ready = reasons.length === 0;
|
|
17194
|
-
return {
|
|
17195
|
-
initiative: ini.id,
|
|
17196
|
-
ready,
|
|
17197
|
-
readiness: ready ? "ready" : "not-ready",
|
|
17198
|
-
reasons
|
|
17199
|
-
};
|
|
17200
|
-
}
|
|
17201
|
-
|
|
17202
17505
|
// src/core/deprecation-write.ts
|
|
17203
17506
|
import fs6 from "fs";
|
|
17204
17507
|
import path7 from "path";
|
|
@@ -18198,6 +18501,8 @@ export {
|
|
|
18198
18501
|
INTEGRATIONS_FILE,
|
|
18199
18502
|
INTERFACE_TYPES,
|
|
18200
18503
|
ImportError,
|
|
18504
|
+
InitiativeConflictError,
|
|
18505
|
+
InitiativeNotReadyError,
|
|
18201
18506
|
InitiativeWriteError,
|
|
18202
18507
|
IntegrationError,
|
|
18203
18508
|
IntegrationServiceError,
|
|
@@ -18259,6 +18564,7 @@ export {
|
|
|
18259
18564
|
collectImplementationEvidence,
|
|
18260
18565
|
completeDeliveryPlan,
|
|
18261
18566
|
completeEpic,
|
|
18567
|
+
completeInitiative,
|
|
18262
18568
|
computeContentHash,
|
|
18263
18569
|
computeEpicProgress,
|
|
18264
18570
|
computeInitiativeProgress,
|
|
@@ -18297,6 +18603,7 @@ export {
|
|
|
18297
18603
|
evaluateCompletion,
|
|
18298
18604
|
evaluateEpicById,
|
|
18299
18605
|
evaluateEpicCompletion,
|
|
18606
|
+
evaluateInitiativeById,
|
|
18300
18607
|
evaluateInitiativeCompletion,
|
|
18301
18608
|
evaluatePlanById,
|
|
18302
18609
|
evaluatePlanCompletion,
|
|
@@ -18340,6 +18647,8 @@ export {
|
|
|
18340
18647
|
getWorkItemsSummary,
|
|
18341
18648
|
importExternalWorkItem,
|
|
18342
18649
|
importWorkItem,
|
|
18650
|
+
initiativeOutcomeVerification,
|
|
18651
|
+
initiativeProvenanceIssues,
|
|
18343
18652
|
initiativesInEpic,
|
|
18344
18653
|
integrationRegistry,
|
|
18345
18654
|
isActiveState,
|
|
@@ -18399,15 +18708,18 @@ export {
|
|
|
18399
18708
|
readFile,
|
|
18400
18709
|
readPocSummary,
|
|
18401
18710
|
recordEpicOutcomeVerification,
|
|
18711
|
+
recordInitiativeOutcomeVerification,
|
|
18402
18712
|
recordMilestoneExitVerification,
|
|
18403
18713
|
recordPlanOutcomeVerification,
|
|
18404
18714
|
redactSecrets,
|
|
18715
|
+
removeCandidate,
|
|
18405
18716
|
removeIntegrationSecret,
|
|
18406
18717
|
removeTarget,
|
|
18407
18718
|
renderConsolidationMarkdown,
|
|
18408
18719
|
renderDriftMarkdown,
|
|
18409
18720
|
renderImpactMarkdown,
|
|
18410
18721
|
renderSavingsMarkdown,
|
|
18722
|
+
replaceBodySection,
|
|
18411
18723
|
revisionOf,
|
|
18412
18724
|
searchSystemNodes,
|
|
18413
18725
|
serializeConsolidationJson,
|
|
@@ -18424,6 +18736,7 @@ export {
|
|
|
18424
18736
|
transitionEpic,
|
|
18425
18737
|
transitionInitiative,
|
|
18426
18738
|
transitionWorkItem,
|
|
18739
|
+
updateCandidate,
|
|
18427
18740
|
updateDeliveryPlan,
|
|
18428
18741
|
updateEpic,
|
|
18429
18742
|
updateInitiative,
|