@kaddo/cli 3.134.0 → 3.135.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.
Files changed (35) hide show
  1. package/dist/admin-dist/assets/{architectureDiagram-3BPJPVTR-CYNwLGE7.js → architectureDiagram-3BPJPVTR-DkdJ073y.js} +1 -1
  2. package/dist/admin-dist/assets/{chunk-727SXJPM-Cet603Hl.js → chunk-727SXJPM-DRof4aGT.js} +1 -1
  3. package/dist/admin-dist/assets/{chunk-AQP2D5EJ-8XEHPg3a.js → chunk-AQP2D5EJ-BOVZoYng.js} +1 -1
  4. package/dist/admin-dist/assets/{classDiagram-v2-Q7XG4LA2-Bhwb9850.js → classDiagram-4FO5ZUOK-cL_umCGu.js} +1 -1
  5. package/dist/admin-dist/assets/{classDiagram-4FO5ZUOK-Bhwb9850.js → classDiagram-v2-Q7XG4LA2-cL_umCGu.js} +1 -1
  6. package/dist/admin-dist/assets/{dagre-BM42HDAG-DqQXdP8F.js → dagre-BM42HDAG-Cvga2Wk-.js} +1 -1
  7. package/dist/admin-dist/assets/{diagram-2AECGRRQ-B1bysbNR.js → diagram-2AECGRRQ-C4H51In7.js} +1 -1
  8. package/dist/admin-dist/assets/{diagram-5GNKFQAL-DRifvijh.js → diagram-5GNKFQAL-BW2-XCqV.js} +1 -1
  9. package/dist/admin-dist/assets/{diagram-LMA3HP47-DajL2Tv-.js → diagram-LMA3HP47-CQnSrSZs.js} +1 -1
  10. package/dist/admin-dist/assets/{diagram-OG6HWLK6-WCJo9oL4.js → diagram-OG6HWLK6-BA6tBaOl.js} +1 -1
  11. package/dist/admin-dist/assets/{erDiagram-TEJ5UH35-DwgqKm6b.js → erDiagram-TEJ5UH35-DQK3b1Yu.js} +1 -1
  12. package/dist/admin-dist/assets/{flowDiagram-I6XJVG4X-M0kG8sQQ.js → flowDiagram-I6XJVG4X-BvtbwW59.js} +1 -1
  13. package/dist/admin-dist/assets/{ganttDiagram-6RSMTGT7-DtyZt9Ti.js → ganttDiagram-6RSMTGT7-Vb0T68-1.js} +1 -1
  14. package/dist/admin-dist/assets/index-F0fBD3Ys.js +96 -0
  15. package/dist/admin-dist/assets/{infoDiagram-5YYISTIA-Vwdw_1gf.js → infoDiagram-5YYISTIA-8oD9uPZj.js} +1 -1
  16. package/dist/admin-dist/assets/{ishikawaDiagram-YF4QCWOH-CIi6B5fy.js → ishikawaDiagram-YF4QCWOH-C32f84vy.js} +1 -1
  17. package/dist/admin-dist/assets/{kanban-definition-UN3LZRKU-5HNFMSQ7.js → kanban-definition-UN3LZRKU-cJc_snn8.js} +1 -1
  18. package/dist/admin-dist/assets/{linear-D3H69r3G.js → linear-XcP0Xi-K.js} +1 -1
  19. package/dist/admin-dist/assets/{mindmap-definition-RKZ34NQL-BI0w0H_c.js → mindmap-definition-RKZ34NQL-jhlLOmXd.js} +1 -1
  20. package/dist/admin-dist/assets/{pieDiagram-4H26LBE5-5oMGjRSP.js → pieDiagram-4H26LBE5-cEiC5w8m.js} +1 -1
  21. package/dist/admin-dist/assets/{quadrantDiagram-W4KKPZXB-Cf4_7xD4.js → quadrantDiagram-W4KKPZXB-xjpfY5PD.js} +1 -1
  22. package/dist/admin-dist/assets/{requirementDiagram-4Y6WPE33-tKyHvrMo.js → requirementDiagram-4Y6WPE33-C5KtzYhy.js} +1 -1
  23. package/dist/admin-dist/assets/{sequenceDiagram-3UESZ5HK-XJChOzcT.js → sequenceDiagram-3UESZ5HK-ByGOoS_6.js} +1 -1
  24. package/dist/admin-dist/assets/{stateDiagram-AJRCARHV-CG6QHhPz.js → stateDiagram-AJRCARHV-d9g3cuV4.js} +1 -1
  25. package/dist/admin-dist/assets/{stateDiagram-v2-BHNVJYJU-COU53r4o.js → stateDiagram-v2-BHNVJYJU-DJ9FtIdZ.js} +1 -1
  26. package/dist/admin-dist/assets/{timeline-definition-PNZ67QCA-CszwARJN.js → timeline-definition-PNZ67QCA-BB4Lz6CJ.js} +1 -1
  27. package/dist/admin-dist/assets/{vennDiagram-CIIHVFJN-kMR7sGYN.js → vennDiagram-CIIHVFJN-yj1GFfPu.js} +1 -1
  28. package/dist/admin-dist/assets/{wardleyDiagram-YWT4CUSO-Cu44stm7.js → wardleyDiagram-YWT4CUSO-5nw4MWMx.js} +1 -1
  29. package/dist/admin-dist/assets/{xychartDiagram-2RQKCTM6-DeU0-PgC.js → xychartDiagram-2RQKCTM6-C0iogx2l.js} +1 -1
  30. package/dist/admin-dist/index.html +1 -1
  31. package/dist/admin-server/index.js +157 -1
  32. package/dist/core.js +550 -96
  33. package/dist/index.js +742 -114
  34. package/package.json +1 -1
  35. package/dist/admin-dist/assets/index-CZVvIq5M.js +0 -96
package/dist/core.js CHANGED
@@ -1897,6 +1897,18 @@ var DELIVERY_PLANS_DIR = "knowledge/delivery/plans";
1897
1897
  var EPICS_DIR = "knowledge/delivery/epics";
1898
1898
  var PLAN_STATES = ["draft", "in-progress", "completed", "cancelled"];
1899
1899
  var EPIC_STATES = ["planned", "in-progress", "completed", "cancelled"];
1900
+ var PLAN_TRANSITIONS = {
1901
+ draft: ["in-progress", "cancelled"],
1902
+ "in-progress": ["completed", "cancelled"],
1903
+ completed: [],
1904
+ cancelled: []
1905
+ };
1906
+ var EPIC_TRANSITIONS = {
1907
+ planned: ["in-progress", "cancelled"],
1908
+ "in-progress": ["completed", "cancelled"],
1909
+ completed: [],
1910
+ cancelled: []
1911
+ };
1900
1912
  function toPosix3(p) {
1901
1913
  return p.replace(/\\/g, "/");
1902
1914
  }
@@ -2326,40 +2338,40 @@ function purposeFromBody(body) {
2326
2338
  }
2327
2339
  function toDetail(filePath, relPath, raw) {
2328
2340
  const parsed = matter5(raw);
2329
- const fm = parsed.data ?? {};
2341
+ const fm2 = parsed.data ?? {};
2330
2342
  const body = parsed.content.trim();
2331
- const id = str(fm.id) ?? "";
2343
+ const id = str(fm2.id) ?? "";
2332
2344
  return {
2333
2345
  id,
2334
- title: str(fm.title) ?? id,
2335
- resourceType: str(fm.resource_type),
2336
- provider: str(fm.provider),
2337
- environments: strArray(fm.environments),
2338
- scope: parseScope(fm.scope),
2339
- modules: strArray(fm.modules),
2346
+ title: str(fm2.title) ?? id,
2347
+ resourceType: str(fm2.resource_type),
2348
+ provider: str(fm2.provider),
2349
+ environments: strArray(fm2.environments),
2350
+ scope: parseScope(fm2.scope),
2351
+ modules: strArray(fm2.modules),
2340
2352
  path: relPath,
2341
- purpose: str(fm.purpose) ?? purposeFromBody(body),
2342
- interfaces: parseInterfaces(fm.access_interfaces),
2343
- boundaries: parseBoundaries(fm.access_boundaries),
2353
+ purpose: str(fm2.purpose) ?? purposeFromBody(body),
2354
+ interfaces: parseInterfaces(fm2.access_interfaces),
2355
+ boundaries: parseBoundaries(fm2.access_boundaries),
2344
2356
  ...(() => {
2345
- const a = parseAuth(fm.authentication);
2357
+ const a = parseAuth(fm2.authentication);
2346
2358
  return { authRefs: a.refs, authMode: a.mode };
2347
2359
  })(),
2348
- connectionProfiles: parseConnectionProfiles(fm.connection_profiles),
2360
+ connectionProfiles: parseConnectionProfiles(fm2.connection_profiles),
2349
2361
  markdownBody: body
2350
2362
  };
2351
2363
  }
2352
2364
  function getResources(dir) {
2353
2365
  return discoverKnowledge(dir).filter((a) => a.type === RESOURCE_ARTIFACT_TYPE).map((a) => {
2354
- const fm = a.rawFrontmatter;
2366
+ const fm2 = a.rawFrontmatter;
2355
2367
  return {
2356
- id: a.id || str(fm.id) || a.title,
2357
- title: a.title || str(fm.title) || a.id,
2358
- resourceType: str(fm.resource_type),
2359
- provider: str(fm.provider),
2360
- environments: strArray(fm.environments),
2361
- scope: parseScope(fm.scope),
2362
- modules: strArray(fm.modules),
2368
+ id: a.id || str(fm2.id) || a.title,
2369
+ title: a.title || str(fm2.title) || a.id,
2370
+ resourceType: str(fm2.resource_type),
2371
+ provider: str(fm2.provider),
2372
+ environments: strArray(fm2.environments),
2373
+ scope: parseScope(fm2.scope),
2374
+ modules: strArray(fm2.modules),
2363
2375
  path: a.relPath
2364
2376
  };
2365
2377
  }).sort((x, y) => x.id.localeCompare(y.id));
@@ -2372,8 +2384,8 @@ function getResource(dir, id) {
2372
2384
  const raw = readFile(match.filePath);
2373
2385
  return toDetail(match.filePath, match.relPath, raw);
2374
2386
  }
2375
- function parseWorkItemResources(fm) {
2376
- const v = fm.resources;
2387
+ function parseWorkItemResources(fm2) {
2388
+ const v = fm2.resources;
2377
2389
  if (!Array.isArray(v)) return [];
2378
2390
  const out = [];
2379
2391
  for (const raw of v) {
@@ -2451,8 +2463,8 @@ var SOFT_DEPRECATION_STRATEGIES = [
2451
2463
  function str2(v) {
2452
2464
  return typeof v === "string" && v.trim() ? v.trim() : null;
2453
2465
  }
2454
- function parseWorkItemDeprecationTargets(fm) {
2455
- const v = fm.deprecation_targets;
2466
+ function parseWorkItemDeprecationTargets(fm2) {
2467
+ const v = fm2.deprecation_targets;
2456
2468
  if (!Array.isArray(v)) return [];
2457
2469
  const out = [];
2458
2470
  for (const raw of v) {
@@ -2590,13 +2602,13 @@ function purposeFromBody2(body) {
2590
2602
  }
2591
2603
  function getDeprecationPlans(dir) {
2592
2604
  return discoverKnowledge(dir).filter((a) => a.type === DEPRECATION_ARTIFACT_TYPE).map((a) => {
2593
- const fm = a.rawFrontmatter;
2594
- const targets = parseTargets(fm.targets);
2605
+ const fm2 = a.rawFrontmatter;
2606
+ const targets = parseTargets(fm2.targets);
2595
2607
  return {
2596
- id: a.id || str2(fm.id) || a.title,
2597
- title: a.title || str2(fm.title) || a.id,
2608
+ id: a.id || str2(fm2.id) || a.title,
2609
+ title: a.title || str2(fm2.title) || a.id,
2598
2610
  path: a.relPath,
2599
- status: str2(fm.status),
2611
+ status: str2(fm2.status),
2600
2612
  targetCount: targets.length,
2601
2613
  lifecycleCounts: lifecycleCountsOf(targets)
2602
2614
  };
@@ -2609,17 +2621,17 @@ function getDeprecationPlan(dir, id) {
2609
2621
  if (!match) return null;
2610
2622
  const raw = readFile(match.filePath);
2611
2623
  const parsed = matter6(raw);
2612
- const fm = parsed.data ?? {};
2624
+ const fm2 = parsed.data ?? {};
2613
2625
  const body = parsed.content.trim();
2614
- const targets = parseTargets(fm.targets);
2626
+ const targets = parseTargets(fm2.targets);
2615
2627
  return {
2616
- id: str2(fm.id) ?? match.id,
2617
- title: str2(fm.title) ?? match.title,
2628
+ id: str2(fm2.id) ?? match.id,
2629
+ title: str2(fm2.title) ?? match.title,
2618
2630
  path: match.relPath,
2619
- status: str2(fm.status),
2631
+ status: str2(fm2.status),
2620
2632
  targetCount: targets.length,
2621
2633
  lifecycleCounts: lifecycleCountsOf(targets),
2622
- purpose: str2(fm.purpose) ?? purposeFromBody2(body),
2634
+ purpose: str2(fm2.purpose) ?? purposeFromBody2(body),
2623
2635
  targets,
2624
2636
  markdownBody: body
2625
2637
  };
@@ -8202,7 +8214,7 @@ var AGENT_PROMPTS = [
8202
8214
  // src/modules/agents.ts
8203
8215
  function withAgentFrontMatter(fileName, content) {
8204
8216
  const name = fileName.replace(/\.md$/, "");
8205
- const fm = [
8217
+ const fm2 = [
8206
8218
  "---",
8207
8219
  "type: agent",
8208
8220
  `name: ${name}`,
@@ -8211,7 +8223,7 @@ function withAgentFrontMatter(fileName, content) {
8211
8223
  "---",
8212
8224
  ""
8213
8225
  ].join("\n");
8214
- return fm + content.replace(/^\s+/, "");
8226
+ return fm2 + content.replace(/^\s+/, "");
8215
8227
  }
8216
8228
  var agentReadme = {
8217
8229
  path: "knowledge/agents/README.md",
@@ -9158,8 +9170,8 @@ function analyzeMetadataHealth(dir) {
9158
9170
  if (isFile(p) && entry.endsWith(".md")) {
9159
9171
  try {
9160
9172
  const raw = readFile(p);
9161
- const fm = matter10(raw).data;
9162
- if (fm.status === "done") {
9173
+ const fm2 = matter10(raw).data;
9174
+ if (fm2.status === "done") {
9163
9175
  const rel = p.replace(dir + "/", "").replace(dir + "\\", "").replace(/\\/g, "/");
9164
9176
  findings.push({
9165
9177
  file: rel,
@@ -9492,8 +9504,8 @@ function buildProjectExplanation(dir) {
9492
9504
  };
9493
9505
  }),
9494
9506
  implementationEvidence: workItemArtifacts.filter((a) => a.affectedModules.length > 0).map((a) => {
9495
- const fm = a.rawFrontmatter;
9496
- const evidence = fm.implementation_evidence;
9507
+ const fm2 = a.rawFrontmatter;
9508
+ const evidence = fm2.implementation_evidence;
9497
9509
  const repos = evidence?.repositories ?? {};
9498
9510
  const repoEvidence = {};
9499
9511
  for (const [repoId, data] of Object.entries(repos)) {
@@ -9511,8 +9523,8 @@ function buildProjectExplanation(dir) {
9511
9523
  validationStatus: a.validationStatus || historicalDefault,
9512
9524
  releaseStatus: a.releaseStatus || "not-assessed",
9513
9525
  affectedModules: a.affectedModules,
9514
- releaseGates: Array.isArray(fm.release_gates) ? fm.release_gates : [],
9515
- completionExceptions: Array.isArray(fm.completion_exceptions) ? fm.completion_exceptions : [],
9526
+ releaseGates: Array.isArray(fm2.release_gates) ? fm2.release_gates : [],
9527
+ completionExceptions: Array.isArray(fm2.completion_exceptions) ? fm2.completion_exceptions : [],
9516
9528
  repoEvidence
9517
9529
  };
9518
9530
  })
@@ -11118,6 +11130,254 @@ function materializeRoadmapInitiative(dir, rmId) {
11118
11130
  });
11119
11131
  }
11120
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
+ }
11166
+ function parseExceptions(raw) {
11167
+ if (!Array.isArray(raw)) return [];
11168
+ const out = [];
11169
+ for (const entry of raw) {
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
+ });
11182
+ }
11183
+ return out;
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))
11194
+ );
11195
+ const criteria = declared.map((criterion) => {
11196
+ const key = normalizeCriterion(criterion);
11197
+ const ambiguous = ambiguousKeys.has(key);
11198
+ const e = ambiguous ? void 0 : byCriterion.get(key);
11199
+ return {
11200
+ criterion,
11201
+ status: e?.status ?? "not-verified",
11202
+ ...e?.evidence ? { evidence: e.evidence } : {},
11203
+ ...e?.reference ? { reference: e.reference } : {},
11204
+ ...e?.method ? { method: e.method } : {},
11205
+ ...e?.verified_at ? { verifiedAt: e.verified_at } : {},
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
11222
+ };
11223
+ }
11224
+ function fm(entity, key) {
11225
+ return entity.rawFrontmatter?.[key];
11226
+ }
11227
+ function epicOutcomeVerification(epic) {
11228
+ return buildOutcomeVerification(
11229
+ epic.successCriteria,
11230
+ parseEvidenceList(fm(epic, "outcome_verifications")),
11231
+ parseExceptions(fm(epic, "completion_exceptions"))
11232
+ );
11233
+ }
11234
+ function planOutcomeVerification(plan) {
11235
+ return buildOutcomeVerification(
11236
+ plan.successCriteria,
11237
+ parseEvidenceList(fm(plan, "outcome_verifications")),
11238
+ parseExceptions(fm(plan, "completion_exceptions"))
11239
+ );
11240
+ }
11241
+ function planMilestoneVerifications(plan) {
11242
+ const rawMs = Array.isArray(fm(plan, "milestones")) ? fm(plan, "milestones") : [];
11243
+ return plan.milestones.map((m) => {
11244
+ const rawEntry = rawMs.find((r) => r && typeof r === "object" && optStr4(r.id)?.toLowerCase() === m.id.toLowerCase());
11245
+ const evidence = parseEvidenceList(rawEntry?.exit_verifications);
11246
+ return { id: m.id, title: m.title, outcome: buildOutcomeVerification(m.exitCriteria, evidence) };
11247
+ });
11248
+ }
11249
+ function decide(blockers, softBlocks, hasAcceptedExceptions) {
11250
+ if (blockers.length > 0) return "BLOCKED";
11251
+ if (softBlocks.length > 0) return "NEEDS_WORK";
11252
+ return hasAcceptedExceptions ? "READY_WITH_EXCEPTIONS" : "READY_TO_COMPLETE";
11253
+ }
11254
+ function evaluateEpicCompletion(dir, epic) {
11255
+ const prog = computeEpicProgress(dir, epic);
11256
+ const exceptions = parseExceptions(fm(epic, "completion_exceptions"));
11257
+ const outcome = epicOutcomeVerification(epic);
11258
+ const blockers = [];
11259
+ const softBlocks = [];
11260
+ const reasons = [];
11261
+ const warnings = [];
11262
+ for (const d of prog.readiness.blockingDependencies) blockers.push(`Blocked by unfinished dependency ${d}.`);
11263
+ for (const f of integrityBlockers(dir, epic.id)) blockers.push(f);
11264
+ evaluateOutcomeInto(epic.outcome, true, outcome, blockers, softBlocks, reasons, warnings);
11265
+ if (prog.delivery.total > 0 && prog.delivery.completed < prog.delivery.total) {
11266
+ softBlocks.push("committed-work-incomplete");
11267
+ reasons.push(`Committed work is incomplete (${prog.delivery.completed}/${prog.delivery.total} Work Items completed).`);
11268
+ }
11269
+ const readiness = decide(blockers, softBlocks, exceptions.some((x) => x.status === "accepted"));
11270
+ pushReadinessReason(readiness, reasons);
11271
+ return {
11272
+ id: epic.id,
11273
+ kind: "epic",
11274
+ status: epic.status,
11275
+ readiness,
11276
+ reasons,
11277
+ blockers,
11278
+ warnings,
11279
+ outcome,
11280
+ delivery: { total: prog.delivery.total, completed: prog.delivery.completed, blocked: prog.delivery.blocked },
11281
+ blockingDependencies: prog.readiness.blockingDependencies,
11282
+ exceptions
11283
+ };
11284
+ }
11285
+ function evaluatePlanCompletion(dir, plan) {
11286
+ const prog = computePlanProgress(dir, plan);
11287
+ const exceptions = parseExceptions(fm(plan, "completion_exceptions"));
11288
+ const outcome = planOutcomeVerification(plan);
11289
+ const milestones = planMilestoneVerifications(plan);
11290
+ const epics = epicsInPlan(dir, plan.id).map((e) => ({ id: e.id, status: e.status }));
11291
+ const blockers = [];
11292
+ const softBlocks = [];
11293
+ const reasons = [];
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).`);
11302
+ }
11303
+ if (epics.length === 0 && prog.delivery.total === 0) {
11304
+ softBlocks.push("no-committed-work");
11305
+ reasons.push("No Epics and no committed Work Items \u2014 the Plan has no verifiable deliverables yet.");
11306
+ }
11307
+ const openEpics = epics.filter((e) => e.status !== "completed" && e.status !== "cancelled");
11308
+ if (openEpics.length > 0) {
11309
+ softBlocks.push("epics-open");
11310
+ reasons.push(`${openEpics.length} Epic(s) not yet completed: ${openEpics.map((e) => e.id).join(", ")}.`);
11311
+ }
11312
+ for (const m of milestones) {
11313
+ if (m.outcome.failed > 0) {
11314
+ blockers.push(`Milestone ${m.id} has a failed exit criterion.`);
11315
+ }
11316
+ const pending = m.outcome.notVerified + m.outcome.manualReview;
11317
+ if (pending > 0) {
11318
+ softBlocks.push(`milestone-${m.id}-pending`);
11319
+ reasons.push(`Milestone ${m.id}: ${pending} exit criterion(s) not verified.`);
11320
+ }
11321
+ if (m.outcome.stale.length > 0) warnings.push(`Milestone ${m.id} has stale exit-criteria evidence.`);
11322
+ }
11323
+ const readiness = decide(blockers, softBlocks, exceptions.some((x) => x.status === "accepted"));
11324
+ pushReadinessReason(readiness, reasons);
11325
+ return {
11326
+ id: plan.id,
11327
+ kind: "plan",
11328
+ status: plan.status,
11329
+ readiness,
11330
+ reasons,
11331
+ blockers,
11332
+ warnings,
11333
+ outcome,
11334
+ delivery: { total: prog.delivery.total, completed: prog.delivery.completed, blocked: prog.delivery.blocked },
11335
+ blockingDependencies: prog.readiness.blockingDependencies,
11336
+ milestones,
11337
+ epics,
11338
+ exceptions
11339
+ };
11340
+ }
11341
+ function integrityBlockers(dir, subjectId) {
11342
+ return validatePlanningGraph(dir).filter((f) => f.level === "error" && f.subject.toLowerCase() === subjectId.toLowerCase()).map((f) => f.message);
11343
+ }
11344
+ function evaluateOutcomeInto(declaredOutcome, requireDeclaredOutcome, outcome, blockers, softBlocks, reasons, warnings) {
11345
+ if (requireDeclaredOutcome && !declaredOutcome) {
11346
+ softBlocks.push("no-outcome");
11347
+ reasons.push("No expected outcome is declared.");
11348
+ }
11349
+ if (outcome.total === 0) {
11350
+ softBlocks.push("no-success-criteria");
11351
+ reasons.push("No success criteria to verify \u2014 completion cannot be judged by outcome.");
11352
+ }
11353
+ if (outcome.ambiguous > 0) {
11354
+ softBlocks.push("criteria-ambiguous");
11355
+ reasons.push(`${outcome.ambiguous} success criterion(s) collide in text \u2014 rename to disambiguate before verifying.`);
11356
+ }
11357
+ if (outcome.failed > 0) {
11358
+ softBlocks.push("criteria-failed");
11359
+ reasons.push(`${outcome.failed} success criterion(s) failed verification.`);
11360
+ }
11361
+ const pending = outcome.notVerified + outcome.manualReview - outcome.ambiguous;
11362
+ if (pending > 0) {
11363
+ softBlocks.push("criteria-unverified");
11364
+ reasons.push(`${pending} success criterion(s) not verified (no or insufficient evidence).`);
11365
+ }
11366
+ if (outcome.stale.length > 0) warnings.push(`${outcome.stale.length} evidence record(s) no longer match a declared criterion (stale).`);
11367
+ }
11368
+ function pushReadinessReason(readiness, reasons) {
11369
+ if (readiness === "READY_TO_COMPLETE") reasons.unshift("All success criteria are verified and committed work is complete. Human approval is still required to close.");
11370
+ else if (readiness === "READY_WITH_EXCEPTIONS") reasons.unshift("Remaining gaps are covered by accepted exceptions. Human approval is still required to close.");
11371
+ }
11372
+ function evaluateEpicById(dir, id) {
11373
+ const e = getEpic(dir, id);
11374
+ return e ? evaluateEpicCompletion(dir, e) : null;
11375
+ }
11376
+ function evaluatePlanById(dir, id) {
11377
+ const p = getPlan(dir, id);
11378
+ return p ? evaluatePlanCompletion(dir, p) : null;
11379
+ }
11380
+
11121
11381
  // src/core/delivery-planning-write.ts
11122
11382
  var DeliveryPlanningWriteError = class extends Error {
11123
11383
  constructor(message) {
@@ -11216,7 +11476,14 @@ function disassociateInitiativeFromEpic(dir, initiativeId) {
11216
11476
  if (!ini.epic) return ini;
11217
11477
  return updateInitiative(dir, ini.id, { epic: null });
11218
11478
  }
11219
- function normalizeMilestones(planId, input) {
11479
+ function normalizeMilestones(planId, input, existing) {
11480
+ const byId = /* @__PURE__ */ new Map();
11481
+ for (const e of existing) {
11482
+ if (e && typeof e === "object" && !Array.isArray(e)) {
11483
+ const eid = typeof e.id === "string" ? e.id.trim().toLowerCase() : "";
11484
+ if (eid) byId.set(eid, e);
11485
+ }
11486
+ }
11220
11487
  const seen = /* @__PURE__ */ new Set();
11221
11488
  const data = [];
11222
11489
  const model = [];
@@ -11228,13 +11495,19 @@ function normalizeMilestones(planId, input) {
11228
11495
  seen.add(key);
11229
11496
  const title = m.title?.trim() || id;
11230
11497
  const exit = cleanList(m.exitCriteria ?? []);
11231
- const entry = { id, title };
11498
+ const entry = { ...byId.get(key) ?? {} };
11499
+ entry.id = id;
11500
+ entry.title = title;
11232
11501
  if (exit.length > 0) entry.exit_criteria = exit;
11502
+ else delete entry.exit_criteria;
11233
11503
  data.push(entry);
11234
11504
  model.push({ id, title, exitCriteria: exit });
11235
11505
  }
11236
11506
  return { data, model };
11237
11507
  }
11508
+ function hasExitEvidence(entry) {
11509
+ return !!entry && Array.isArray(entry.exit_verifications) && entry.exit_verifications.length > 0;
11510
+ }
11238
11511
  function updateDeliveryPlan(dir, id, patch, opts) {
11239
11512
  const plan = getPlan(dir, id);
11240
11513
  if (!plan) throw new DeliveryPlanningWriteError(`Plan ${id} does not exist.`);
@@ -11254,7 +11527,8 @@ function updateDeliveryPlan(dir, id, patch, opts) {
11254
11527
  if (patch.dependsOn !== void 0) setListOrDelete(data, "depends_on", patch.dependsOn);
11255
11528
  if (patch.references !== void 0) setListOrDelete(data, "references", patch.references);
11256
11529
  if (patch.milestones !== void 0) {
11257
- const { data: msData, model } = normalizeMilestones(plan.id, patch.milestones);
11530
+ const existingRaw = Array.isArray(data.milestones) ? data.milestones : [];
11531
+ const { data: msData, model } = normalizeMilestones(plan.id, patch.milestones, existingRaw);
11258
11532
  const newIds = new Set(model.map((m) => m.id.toLowerCase()));
11259
11533
  const referencedByEpic = /* @__PURE__ */ new Map();
11260
11534
  for (const e of epicsInPlan(dir, plan.id)) {
@@ -11270,6 +11544,12 @@ function updateDeliveryPlan(dir, id, patch, opts) {
11270
11544
  const detail = [...referencedByEpic.entries()].map(([ms, epics]) => `${ms} (used by ${epics.join(", ")})`).join("; ");
11271
11545
  throw new DeliveryPlanningWriteError(`Cannot remove or rename milestone(s) still referenced by an Epic: ${detail}. Reassign the Epic first.`);
11272
11546
  }
11547
+ if (!opts?.allowMilestoneEvidenceLoss) {
11548
+ const droppedWithEvidence = existingRaw.filter((e) => e && typeof e === "object" && typeof e.id === "string" && !newIds.has(e.id.trim().toLowerCase()) && hasExitEvidence(e)).map((e) => String(e.id));
11549
+ if (droppedWithEvidence.length > 0) {
11550
+ throw new DeliveryPlanningWriteError(`Milestone(s) ${droppedWithEvidence.join(", ")} still carry exit-criteria evidence. Removing them discards that evidence \u2014 pass allowMilestoneEvidenceLoss to confirm.`);
11551
+ }
11552
+ }
11273
11553
  data.milestones = msData;
11274
11554
  }
11275
11555
  const newContent = matter13.stringify(content, data);
@@ -11335,6 +11615,163 @@ function updateEpic(dir, id, patch, opts) {
11335
11615
  if (!updated) throw new DeliveryPlanningWriteError("Failed to parse the Epic after update.");
11336
11616
  return updated;
11337
11617
  }
11618
+ function today2() {
11619
+ return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
11620
+ }
11621
+ var PlanningNotReadyError = class extends DeliveryPlanningWriteError {
11622
+ constructor(evaluation) {
11623
+ super(`${evaluation.kind === "plan" ? "Plan" : "Epic"} ${evaluation.id} is not ready to complete (${evaluation.readiness}).`);
11624
+ this.evaluation = evaluation;
11625
+ this.name = "PlanningNotReadyError";
11626
+ }
11627
+ evaluation;
11628
+ };
11629
+ function transitionDeliveryPlan(dir, id, to, opts) {
11630
+ const plan = getPlan(dir, id);
11631
+ if (!plan) throw new DeliveryPlanningWriteError(`Plan ${id} does not exist.`);
11632
+ if (!PLAN_STATES.includes(to)) throw new DeliveryPlanningWriteError(`Invalid plan status: ${to}.`);
11633
+ if (to === "completed") throw new DeliveryPlanningWriteError(`Completing Plan ${id} requires evidence-based review \u2014 use completeDeliveryPlan.`);
11634
+ const raw = readFile(plan.filePath);
11635
+ assertFreshRevision(plan.id, raw, opts);
11636
+ if (plan.status === to) return plan;
11637
+ if (!PLAN_TRANSITIONS[plan.status].includes(to)) throw new DeliveryPlanningWriteError(`Invalid transition ${plan.status} \u2192 ${to} for Plan ${id}.`);
11638
+ const { data, content } = matter13(raw, {});
11639
+ data.status = to;
11640
+ if (to === "completed") data.completed_at = today2();
11641
+ const newContent = matter13.stringify(content, data);
11642
+ writeFile(plan.filePath, newContent);
11643
+ const updated = parseDeliveryPlan(dir, plan.filePath, newContent);
11644
+ if (!updated) throw new DeliveryPlanningWriteError("Failed to parse the Plan after transition.");
11645
+ return updated;
11646
+ }
11647
+ function transitionEpic(dir, id, to, opts) {
11648
+ const epic = getEpic(dir, id);
11649
+ if (!epic) throw new DeliveryPlanningWriteError(`Epic ${id} does not exist.`);
11650
+ if (!EPIC_STATES.includes(to)) throw new DeliveryPlanningWriteError(`Invalid epic status: ${to}.`);
11651
+ if (to === "completed") throw new DeliveryPlanningWriteError(`Completing Epic ${id} requires evidence-based review \u2014 use completeEpic.`);
11652
+ const raw = readFile(epic.filePath);
11653
+ assertFreshRevision(epic.id, raw, opts);
11654
+ if (epic.status === to) return epic;
11655
+ if (!EPIC_TRANSITIONS[epic.status].includes(to)) throw new DeliveryPlanningWriteError(`Invalid transition ${epic.status} \u2192 ${to} for Epic ${id}.`);
11656
+ const { data, content } = matter13(raw, {});
11657
+ data.status = to;
11658
+ if (to === "completed") data.completed_at = today2();
11659
+ const newContent = matter13.stringify(content, data);
11660
+ writeFile(epic.filePath, newContent);
11661
+ const updated = parseEpic(dir, epic.filePath, newContent);
11662
+ if (!updated) throw new DeliveryPlanningWriteError("Failed to parse the Epic after transition.");
11663
+ return updated;
11664
+ }
11665
+ function assertCriterionDeclared(declared, criterion, kind) {
11666
+ const key = normalizeCriterion(criterion);
11667
+ const matches = declared.filter((c) => normalizeCriterion(c) === key).length;
11668
+ if (matches === 0) throw new DeliveryPlanningWriteError(`"${criterion}" is not a declared ${kind} criterion.`);
11669
+ if (matches > 1) throw new DeliveryPlanningWriteError(`"${criterion}" matches more than one declared ${kind} criterion \u2014 rename them to disambiguate before recording evidence.`);
11670
+ }
11671
+ function upsertEvidence(existing, input) {
11672
+ const list2 = Array.isArray(existing) ? existing.filter((e) => e && typeof e === "object" && !Array.isArray(e)) : [];
11673
+ const key = normalizeCriterion(input.criterion);
11674
+ const kept = list2.filter((e) => normalizeCriterion(String(e.criterion ?? "")) !== key);
11675
+ const obj = { criterion: input.criterion.trim(), status: input.status };
11676
+ if (input.evidence?.trim()) obj.evidence = input.evidence.trim();
11677
+ if (input.reference?.trim()) obj.reference = input.reference.trim();
11678
+ if (input.method) obj.method = input.method;
11679
+ obj.verified_at = today2();
11680
+ if (input.verifiedBy?.trim()) obj.verified_by = input.verifiedBy.trim();
11681
+ return [...kept, obj];
11682
+ }
11683
+ function recordEpicOutcomeVerification(dir, id, input, opts) {
11684
+ const epic = getEpic(dir, id);
11685
+ if (!epic) throw new DeliveryPlanningWriteError(`Epic ${id} does not exist.`);
11686
+ assertCriterionDeclared(epic.successCriteria, input.criterion, "success");
11687
+ const raw = readFile(epic.filePath);
11688
+ assertFreshRevision(epic.id, raw, opts);
11689
+ const { data, content } = matter13(raw, {});
11690
+ data.outcome_verifications = upsertEvidence(data.outcome_verifications, input);
11691
+ const newContent = matter13.stringify(content, data);
11692
+ writeFile(epic.filePath, newContent);
11693
+ const updated = parseEpic(dir, epic.filePath, newContent);
11694
+ if (!updated) throw new DeliveryPlanningWriteError("Failed to parse the Epic after recording evidence.");
11695
+ return updated;
11696
+ }
11697
+ function recordPlanOutcomeVerification(dir, id, input, opts) {
11698
+ const plan = getPlan(dir, id);
11699
+ if (!plan) throw new DeliveryPlanningWriteError(`Plan ${id} does not exist.`);
11700
+ assertCriterionDeclared(plan.successCriteria, input.criterion, "success");
11701
+ const raw = readFile(plan.filePath);
11702
+ assertFreshRevision(plan.id, raw, opts);
11703
+ const { data, content } = matter13(raw, {});
11704
+ data.outcome_verifications = upsertEvidence(data.outcome_verifications, input);
11705
+ const newContent = matter13.stringify(content, data);
11706
+ writeFile(plan.filePath, newContent);
11707
+ const updated = parseDeliveryPlan(dir, plan.filePath, newContent);
11708
+ if (!updated) throw new DeliveryPlanningWriteError("Failed to parse the Plan after recording evidence.");
11709
+ return updated;
11710
+ }
11711
+ function recordMilestoneExitVerification(dir, planId, milestoneId, input, opts) {
11712
+ const plan = getPlan(dir, planId);
11713
+ if (!plan) throw new DeliveryPlanningWriteError(`Plan ${planId} does not exist.`);
11714
+ const milestone = plan.milestones.find((m) => m.id.toLowerCase() === milestoneId.toLowerCase());
11715
+ if (!milestone) throw new DeliveryPlanningWriteError(`Milestone ${milestoneId} is not defined in ${planId}.`);
11716
+ assertCriterionDeclared(milestone.exitCriteria, input.criterion, "exit");
11717
+ const raw = readFile(plan.filePath);
11718
+ assertFreshRevision(plan.id, raw, opts);
11719
+ const { data, content } = matter13(raw, {});
11720
+ const rawMs = Array.isArray(data.milestones) ? data.milestones : [];
11721
+ const entry = rawMs.find((m) => m && typeof m === "object" && String(m.id ?? "").toLowerCase() === milestoneId.toLowerCase());
11722
+ if (!entry) throw new DeliveryPlanningWriteError(`Milestone ${milestoneId} entry not found in ${planId} frontmatter.`);
11723
+ entry.exit_verifications = upsertEvidence(entry.exit_verifications, input);
11724
+ data.milestones = rawMs;
11725
+ const newContent = matter13.stringify(content, data);
11726
+ writeFile(plan.filePath, newContent);
11727
+ const updated = parseDeliveryPlan(dir, plan.filePath, newContent);
11728
+ if (!updated) throw new DeliveryPlanningWriteError("Failed to parse the Plan after recording milestone evidence.");
11729
+ return updated;
11730
+ }
11731
+ function completionDecisionRecord(evaluation, input) {
11732
+ const rec = { readiness: evaluation.readiness, decided_at: today2(), reasons: evaluation.reasons };
11733
+ if (input.decidedBy?.trim()) rec.decided_by = input.decidedBy.trim();
11734
+ if (input.note?.trim()) rec.note = input.note.trim();
11735
+ const acceptedExceptions = evaluation.exceptions.filter((x) => x.status === "accepted");
11736
+ if (acceptedExceptions.length > 0) rec.exceptions = acceptedExceptions;
11737
+ return rec;
11738
+ }
11739
+ function completeEpic(dir, id, input = {}, opts) {
11740
+ const epic = getEpic(dir, id);
11741
+ if (!epic) throw new DeliveryPlanningWriteError(`Epic ${id} does not exist.`);
11742
+ const evaluation = evaluateEpicCompletion(dir, epic);
11743
+ if (evaluation.readiness !== "READY_TO_COMPLETE" && evaluation.readiness !== "READY_WITH_EXCEPTIONS") throw new PlanningNotReadyError(evaluation);
11744
+ if (!EPIC_TRANSITIONS[epic.status].includes("completed")) throw new DeliveryPlanningWriteError(`Epic ${id} cannot move from ${epic.status} to completed.`);
11745
+ const raw = readFile(epic.filePath);
11746
+ assertFreshRevision(epic.id, raw, opts);
11747
+ const { data, content } = matter13(raw, {});
11748
+ data.status = "completed";
11749
+ data.completed_at = today2();
11750
+ data.completion_decision = completionDecisionRecord(evaluation, input);
11751
+ const newContent = matter13.stringify(content, data);
11752
+ writeFile(epic.filePath, newContent);
11753
+ const updated = parseEpic(dir, epic.filePath, newContent);
11754
+ if (!updated) throw new DeliveryPlanningWriteError("Failed to parse the Epic after completion.");
11755
+ return updated;
11756
+ }
11757
+ function completeDeliveryPlan(dir, id, input = {}, opts) {
11758
+ const plan = getPlan(dir, id);
11759
+ if (!plan) throw new DeliveryPlanningWriteError(`Plan ${id} does not exist.`);
11760
+ const evaluation = evaluatePlanCompletion(dir, plan);
11761
+ if (evaluation.readiness !== "READY_TO_COMPLETE" && evaluation.readiness !== "READY_WITH_EXCEPTIONS") throw new PlanningNotReadyError(evaluation);
11762
+ if (!PLAN_TRANSITIONS[plan.status].includes("completed")) throw new DeliveryPlanningWriteError(`Plan ${id} cannot move from ${plan.status} to completed.`);
11763
+ const raw = readFile(plan.filePath);
11764
+ assertFreshRevision(plan.id, raw, opts);
11765
+ const { data, content } = matter13(raw, {});
11766
+ data.status = "completed";
11767
+ data.completed_at = today2();
11768
+ data.completion_decision = completionDecisionRecord(evaluation, input);
11769
+ const newContent = matter13.stringify(content, data);
11770
+ writeFile(plan.filePath, newContent);
11771
+ const updated = parseDeliveryPlan(dir, plan.filePath, newContent);
11772
+ if (!updated) throw new DeliveryPlanningWriteError("Failed to parse the Plan after completion.");
11773
+ return updated;
11774
+ }
11338
11775
 
11339
11776
  // src/core/knowledge-consolidation.ts
11340
11777
  import { createHash as createHash3 } from "crypto";
@@ -12627,7 +13064,7 @@ function getWorkItem(dir, workItemId) {
12627
13064
  const base = toListItem(match);
12628
13065
  const body = readBody(match.filePath);
12629
13066
  const sections = splitSections(body);
12630
- const fm = match.rawFrontmatter;
13067
+ const fm2 = match.rawFrontmatter;
12631
13068
  const knowledge = discoverKnowledge(dir).filter((a) => !a.isWorkItem);
12632
13069
  const knowledgeById = new Map(knowledge.filter((k) => k.id).map((k) => [k.id, k]));
12633
13070
  const detail = {
@@ -12644,21 +13081,21 @@ function getWorkItem(dir, workItemId) {
12644
13081
  moduleCoverage: normalizeCoverage(match.moduleCoverage),
12645
13082
  impactAnalysis: normalizeImpact(match.impactAnalysis),
12646
13083
  acceptanceCriteria: parseAcceptanceCriteria(sections),
12647
- implementationEvidence: parseEvidence(fm),
12648
- releaseGates: parseReleaseGates(fm),
12649
- completionExceptions: parseExceptions(fm),
13084
+ implementationEvidence: parseEvidence(fm2),
13085
+ releaseGates: parseReleaseGates(fm2),
13086
+ completionExceptions: parseExceptions2(fm2),
12650
13087
  decisions: parseDecisions(match.decisions, knowledgeById),
12651
- relatedKnowledge: parseRelatedKnowledge(fm, knowledgeById),
12652
- source: parseWorkItemSource(fm),
12653
- originalSnapshot: parseOriginalSnapshot(fm),
13088
+ relatedKnowledge: parseRelatedKnowledge(fm2, knowledgeById),
13089
+ source: parseWorkItemSource(fm2),
13090
+ originalSnapshot: parseOriginalSnapshot(fm2),
12654
13091
  path: match.relPath,
12655
13092
  // Faithful source of truth: the artifact body already read above, not reconstructed (WI-025).
12656
13093
  markdownBody: body.trim(),
12657
13094
  // External systems this WI relates to (WI-030), separate from affectedModules (code).
12658
- resources: parseWorkItemResources(fm),
13095
+ resources: parseWorkItemResources(fm2),
12659
13096
  // Deprecation Targets this WI retires (WI-050), referenced not copied.
12660
- deprecationTargets: parseWorkItemDeprecationTargets(fm),
12661
- ...parseSystemImpact(dir, fm)
13097
+ deprecationTargets: parseWorkItemDeprecationTargets(fm2),
13098
+ ...parseSystemImpact(dir, fm2)
12662
13099
  };
12663
13100
  return { ...detail, refinement: computeRefinementStatus(detail) };
12664
13101
  }
@@ -12681,14 +13118,14 @@ function parseExplain(o) {
12681
13118
  function emptyExplain() {
12682
13119
  return { reason: null, graphReason: null, evidenceRefs: [], evidenceSummary: null };
12683
13120
  }
12684
- function parseSystemImpact(dir, fm) {
13121
+ function parseSystemImpact(dir, fm2) {
12685
13122
  const topology = loadSystemTopology(dir);
12686
13123
  const byId = new Map(topology.entities.map((e) => [e.id, e]));
12687
13124
  const resolve = (id) => {
12688
13125
  const e = byId.get(id);
12689
13126
  return { id, nodeId: `sys:${id}`, label: e?.label ?? id, kind: e?.kind ?? "unknown", moduleId: e?.moduleId ?? null };
12690
13127
  };
12691
- const affected = Array.isArray(fm.affected_system_entities) ? fm.affected_system_entities.map((raw) => {
13128
+ const affected = Array.isArray(fm2.affected_system_entities) ? fm2.affected_system_entities.map((raw) => {
12692
13129
  if (typeof raw === "string") return raw ? { ...resolve(raw), ...emptyExplain() } : null;
12693
13130
  if (raw && typeof raw === "object") {
12694
13131
  const o = raw;
@@ -12697,13 +13134,13 @@ function parseSystemImpact(dir, fm) {
12697
13134
  }
12698
13135
  return null;
12699
13136
  }).filter((e) => e != null) : [];
12700
- const reviewed = Array.isArray(fm.reviewed_system_entities) ? fm.reviewed_system_entities.filter((r) => Boolean(r) && typeof r === "object").map((r) => ({ ...resolve(String(r.id ?? "")), ...parseExplain(r), status: String(r.status ?? "unknown") })).filter((r) => r.id) : [];
12701
- const graphRevision = typeof fm.graph_revision === "string" && fm.graph_revision.trim() ? fm.graph_revision.trim() : null;
13137
+ const reviewed = Array.isArray(fm2.reviewed_system_entities) ? fm2.reviewed_system_entities.filter((r) => Boolean(r) && typeof r === "object").map((r) => ({ ...resolve(String(r.id ?? "")), ...parseExplain(r), status: String(r.status ?? "unknown") })).filter((r) => r.id) : [];
13138
+ const graphRevision = typeof fm2.graph_revision === "string" && fm2.graph_revision.trim() ? fm2.graph_revision.trim() : null;
12702
13139
  const graphCoverage = topology.entities.length === 0 ? "unavailable" : topology.relationships.length > 0 ? "available" : "partial";
12703
13140
  return { affectedSystemEntities: affected, reviewedSystemEntities: reviewed, graphRevision, graphCoverage };
12704
13141
  }
12705
- function parseOriginalSnapshot(fm) {
12706
- const raw = fm.original_snapshot;
13142
+ function parseOriginalSnapshot(fm2) {
13143
+ const raw = fm2.original_snapshot;
12707
13144
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
12708
13145
  const o = raw;
12709
13146
  const title = typeof o.title === "string" ? o.title : void 0;
@@ -12806,12 +13243,12 @@ function normalizeImpact(ia) {
12806
13243
  ...v.question ? { question: v.question } : {}
12807
13244
  }));
12808
13245
  }
12809
- function optStr4(v) {
13246
+ function optStr5(v) {
12810
13247
  if (typeof v === "string" && v.trim()) return v.trim();
12811
13248
  return void 0;
12812
13249
  }
12813
- function parseEvidence(fm) {
12814
- const evidence = fm.implementation_evidence;
13250
+ function parseEvidence(fm2) {
13251
+ const evidence = fm2.implementation_evidence;
12815
13252
  const repos = evidence?.repositories;
12816
13253
  if (!repos || typeof repos !== "object" || Array.isArray(repos)) return [];
12817
13254
  const out = [];
@@ -12821,13 +13258,13 @@ function parseEvidence(fm) {
12821
13258
  const validations = Array.isArray(d.validations) ? d.validations.map((v) => ({
12822
13259
  command: String(v.command ?? ""),
12823
13260
  status: String(v.status ?? "unknown"),
12824
- ...optStr4(v.reason) ? { reason: optStr4(v.reason) } : {}
13261
+ ...optStr5(v.reason) ? { reason: optStr5(v.reason) } : {}
12825
13262
  })) : [];
12826
13263
  const migrations = Array.isArray(d.migrations) ? d.migrations.map((m) => ({
12827
13264
  id: String(m.id ?? ""),
12828
13265
  environment: String(m.environment ?? ""),
12829
13266
  status: String(m.status ?? "unknown"),
12830
- ...optStr4(m.reason) ? { reason: optStr4(m.reason) } : {}
13267
+ ...optStr5(m.reason) ? { reason: optStr5(m.reason) } : {}
12831
13268
  })) : [];
12832
13269
  out.push({
12833
13270
  module,
@@ -12840,23 +13277,23 @@ function parseEvidence(fm) {
12840
13277
  }
12841
13278
  return out;
12842
13279
  }
12843
- function parseReleaseGates(fm) {
12844
- if (!Array.isArray(fm.release_gates)) return [];
12845
- return fm.release_gates.filter((g) => g && typeof g === "object").map((g) => ({
13280
+ function parseReleaseGates(fm2) {
13281
+ if (!Array.isArray(fm2.release_gates)) return [];
13282
+ return fm2.release_gates.filter((g) => g && typeof g === "object").map((g) => ({
12846
13283
  id: String(g.id ?? ""),
12847
13284
  status: String(g.status ?? "pending"),
12848
- ...optStr4(g.reason) ? { reason: optStr4(g.reason) } : {},
12849
- ...optStr4(g.required_for) ? { requiredFor: optStr4(g.required_for) } : {}
13285
+ ...optStr5(g.reason) ? { reason: optStr5(g.reason) } : {},
13286
+ ...optStr5(g.required_for) ? { requiredFor: optStr5(g.required_for) } : {}
12850
13287
  }));
12851
13288
  }
12852
- function parseExceptions(fm) {
12853
- if (!Array.isArray(fm.completion_exceptions)) return [];
12854
- return fm.completion_exceptions.filter((e) => e && typeof e === "object").map((e) => ({
13289
+ function parseExceptions2(fm2) {
13290
+ if (!Array.isArray(fm2.completion_exceptions)) return [];
13291
+ return fm2.completion_exceptions.filter((e) => e && typeof e === "object").map((e) => ({
12855
13292
  id: String(e.id ?? ""),
12856
13293
  status: String(e.status ?? "proposed"),
12857
- ...optStr4(e.reason) ? { reason: optStr4(e.reason) } : {},
12858
- ...optStr4(e.category) ? { category: optStr4(e.category) } : {},
12859
- ...optStr4(e.impact) ? { impact: optStr4(e.impact) } : {}
13294
+ ...optStr5(e.reason) ? { reason: optStr5(e.reason) } : {},
13295
+ ...optStr5(e.category) ? { category: optStr5(e.category) } : {},
13296
+ ...optStr5(e.impact) ? { impact: optStr5(e.impact) } : {}
12860
13297
  }));
12861
13298
  }
12862
13299
  function parseDecisions(decisions, knowledgeById) {
@@ -12869,10 +13306,10 @@ function parseDecisions(decisions, knowledgeById) {
12869
13306
  };
12870
13307
  });
12871
13308
  }
12872
- function parseRelatedKnowledge(fm, knowledgeById) {
13309
+ function parseRelatedKnowledge(fm2, knowledgeById) {
12873
13310
  const refs = /* @__PURE__ */ new Set();
12874
13311
  for (const field of ["related_knowledge", "knowledge", "related"]) {
12875
- const v = fm[field];
13312
+ const v = fm2[field];
12876
13313
  if (Array.isArray(v)) {
12877
13314
  for (const r of v) if (typeof r === "string" && r.trim()) refs.add(r.trim());
12878
13315
  }
@@ -13402,7 +13839,7 @@ function createWorkItem(dir, opts) {
13402
13839
  if (!type) throw new WorkItemWriteError("INVALID_INPUT", `Unknown Work Item type "${opts.type}".`);
13403
13840
  const id = nextWorkItemId2(dir);
13404
13841
  const title = intent.split(/\r?\n/)[0].trim().slice(0, 120);
13405
- const today2 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
13842
+ const today3 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
13406
13843
  const summary = opts.summary?.trim() || intent;
13407
13844
  const source2 = opts.source ? { ...opts.source, inferred: false } : { type: "manual", inferred: false };
13408
13845
  const data = {
@@ -13411,7 +13848,7 @@ function createWorkItem(dir, opts) {
13411
13848
  title,
13412
13849
  status: "draft",
13413
13850
  work_type: type,
13414
- created_at: today2,
13851
+ created_at: today3,
13415
13852
  source: source2,
13416
13853
  generated_by: "kaddo-admin",
13417
13854
  affected_modules: [],
@@ -13508,9 +13945,9 @@ function validateWorkItem(dir, id) {
13508
13945
  }
13509
13946
  const topology = loadSystemTopology(dir);
13510
13947
  const entityById = new Map(topology.entities.map((e) => [e.id, e]));
13511
- const fm = data;
13948
+ const fm2 = data;
13512
13949
  const idOf = (raw2) => typeof raw2 === "string" ? raw2 : raw2 && typeof raw2 === "object" ? String(raw2.id ?? "") : "";
13513
- const affectedEntities = Array.isArray(fm.affected_system_entities) ? fm.affected_system_entities.map(idOf).filter(Boolean) : [];
13950
+ const affectedEntities = Array.isArray(fm2.affected_system_entities) ? fm2.affected_system_entities.map(idOf).filter(Boolean) : [];
13514
13951
  for (const eid of affectedEntities) {
13515
13952
  const e = entityById.get(eid);
13516
13953
  if (!e) {
@@ -13521,8 +13958,8 @@ function validateWorkItem(dir, id) {
13521
13958
  findings.push({ level: "warning", message: `System entity "${e.label}" belongs to module "${e.moduleId}", which is not in affected_modules.` });
13522
13959
  }
13523
13960
  }
13524
- if (Array.isArray(fm.reviewed_system_entities)) {
13525
- for (const r of fm.reviewed_system_entities) {
13961
+ if (Array.isArray(fm2.reviewed_system_entities)) {
13962
+ for (const r of fm2.reviewed_system_entities) {
13526
13963
  const rid = r && typeof r === "object" ? String(r.id ?? "") : "";
13527
13964
  if (rid && !entityById.has(rid)) findings.push({ level: "warning", message: `Reviewed system entity "${rid}" does not exist in the semantic topology.` });
13528
13965
  }
@@ -14549,11 +14986,11 @@ function verifyWorkItem(dir, workItemId, input) {
14549
14986
  const artifacts = discoverWorkItems(dir);
14550
14987
  const match = artifacts.find((a) => (a.id || a.title) === workItemId);
14551
14988
  const lifecycle = lifecycleStateOf({ status: match.status, filePath: match.filePath });
14552
- const fm = match.rawFrontmatter;
14989
+ const fm2 = match.rawFrontmatter;
14553
14990
  const acVerifications = mapACVerifications(input.acVerifications);
14554
14991
  const acSummary = computeACSummary(acVerifications);
14555
- const releaseGates = Array.isArray(fm.release_gates) ? fm.release_gates : [];
14556
- const completionExceptions = Array.isArray(fm.completion_exceptions) ? fm.completion_exceptions : [];
14992
+ const releaseGates = Array.isArray(fm2.release_gates) ? fm2.release_gates : [];
14993
+ const completionExceptions = Array.isArray(fm2.completion_exceptions) ? fm2.completion_exceptions : [];
14557
14994
  const plannedVsActual = computePlannedVsActual(match.affectedModules, input.repos);
14558
14995
  const registeredModuleIds = loadMappedModules(dir).map((m) => m.id);
14559
14996
  const modifiedRepoIds = input.repos.map((r) => r.repoId);
@@ -14564,7 +15001,7 @@ function verifyWorkItem(dir, workItemId, input) {
14564
15001
  validationStatus: match.validationStatus || "not-started",
14565
15002
  releaseStatus: match.releaseStatus || "not-assessed",
14566
15003
  affectedModules: match.affectedModules,
14567
- rawFrontmatter: fm,
15004
+ rawFrontmatter: fm2,
14568
15005
  registeredModuleIds,
14569
15006
  modifiedRepoIds
14570
15007
  });
@@ -17242,9 +17679,9 @@ function conceptBundlePath(a, id) {
17242
17679
  return `misc/${file}`;
17243
17680
  }
17244
17681
  }
17245
- function workItemRelations(fm) {
17682
+ function workItemRelations(fm2) {
17246
17683
  const out = [];
17247
- const resources = fm.resources;
17684
+ const resources = fm2.resources;
17248
17685
  if (Array.isArray(resources)) {
17249
17686
  for (const r of resources) {
17250
17687
  if (r && typeof r === "object") {
@@ -17253,16 +17690,16 @@ function workItemRelations(fm) {
17253
17690
  }
17254
17691
  }
17255
17692
  }
17256
- const dep = fm.deprecation_targets;
17693
+ const dep = fm2.deprecation_targets;
17257
17694
  if (Array.isArray(dep)) {
17258
17695
  for (const d of dep) {
17259
17696
  const s = typeof d === "string" ? d : d && typeof d === "object" ? str3(d.plan) : null;
17260
17697
  if (s) out.push({ id: s.includes("/") ? s.split("/")[0] : s, role: "deprecates-via" });
17261
17698
  }
17262
17699
  }
17263
- const parent = str3(fm.parent);
17700
+ const parent = str3(fm2.parent);
17264
17701
  if (parent) out.push({ id: parent, role: "child-of" });
17265
- for (const dId of strArray3(fm.decisions)) out.push({ id: dId, role: "decided-by" });
17702
+ for (const dId of strArray3(fm2.decisions)) out.push({ id: dId, role: "decided-by" });
17266
17703
  return out;
17267
17704
  }
17268
17705
  function slugify5(s) {
@@ -17778,6 +18215,7 @@ export {
17778
18215
  PRODUCTION_RUNBOOKS_DIR,
17779
18216
  PRODUCTION_RUNBOOK_ARTIFACT_TYPE,
17780
18217
  PlanningConflictError,
18218
+ PlanningNotReadyError,
17781
18219
  ProductionRunbookError,
17782
18220
  REDACTED_COORDINATE,
17783
18221
  RESOURCE_ARTIFACT_TYPE,
@@ -17809,6 +18247,7 @@ export {
17809
18247
  buildImpactReport,
17810
18248
  buildImplementationHandoff,
17811
18249
  buildImportIndex,
18250
+ buildOutcomeVerification,
17812
18251
  buildPocReportContext,
17813
18252
  buildProductionRunbookContext,
17814
18253
  buildProjectExplanation,
@@ -17818,6 +18257,8 @@ export {
17818
18257
  buildSavingsReport,
17819
18258
  buildTopologyEnrichmentHandoff,
17820
18259
  collectImplementationEvidence,
18260
+ completeDeliveryPlan,
18261
+ completeEpic,
17821
18262
  computeContentHash,
17822
18263
  computeEpicProgress,
17823
18264
  computeInitiativeProgress,
@@ -17851,9 +18292,14 @@ export {
17851
18292
  discoverWorkItems,
17852
18293
  enableIntegration,
17853
18294
  environmentSummary,
18295
+ epicOutcomeVerification,
17854
18296
  epicsInPlan,
17855
18297
  evaluateCompletion,
18298
+ evaluateEpicById,
18299
+ evaluateEpicCompletion,
17856
18300
  evaluateInitiativeCompletion,
18301
+ evaluatePlanById,
18302
+ evaluatePlanCompletion,
17857
18303
  exists,
17858
18304
  exportOkf,
17859
18305
  filterSecretPaths,
@@ -17927,6 +18373,7 @@ export {
17927
18373
  nextInitiativeId,
17928
18374
  nextPlanId2 as nextPlanId,
17929
18375
  nextTargetId,
18376
+ normalizeCriterion,
17930
18377
  observationStatus,
17931
18378
  okfConceptType,
17932
18379
  parseContent,
@@ -17944,11 +18391,16 @@ export {
17944
18391
  persistConsent,
17945
18392
  persistPocReport,
17946
18393
  planIntelligence,
18394
+ planMilestoneVerifications,
18395
+ planOutcomeVerification,
17947
18396
  previewImport,
17948
18397
  projectMode,
17949
18398
  proposeWorkItemCandidates,
17950
18399
  readFile,
17951
18400
  readPocSummary,
18401
+ recordEpicOutcomeVerification,
18402
+ recordMilestoneExitVerification,
18403
+ recordPlanOutcomeVerification,
17952
18404
  redactSecrets,
17953
18405
  removeIntegrationSecret,
17954
18406
  removeTarget,
@@ -17968,6 +18420,8 @@ export {
17968
18420
  targetsEligibleForRemoval,
17969
18421
  targetsPastObservation,
17970
18422
  topologyRevision,
18423
+ transitionDeliveryPlan,
18424
+ transitionEpic,
17971
18425
  transitionInitiative,
17972
18426
  transitionWorkItem,
17973
18427
  updateDeliveryPlan,