@kaddo/cli 3.89.0 → 3.90.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.js +221 -3
- package/dist/index.js +849 -0
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -6570,6 +6570,7 @@ var VALID_SOURCES = [
|
|
|
6570
6570
|
"csv",
|
|
6571
6571
|
"api",
|
|
6572
6572
|
"external",
|
|
6573
|
+
"chat",
|
|
6573
6574
|
"unknown"
|
|
6574
6575
|
];
|
|
6575
6576
|
function isValidSource(s) {
|
|
@@ -9395,8 +9396,219 @@ function buildRefinementHandoff(dir, workItemId) {
|
|
|
9395
9396
|
};
|
|
9396
9397
|
}
|
|
9397
9398
|
|
|
9398
|
-
// src/
|
|
9399
|
+
// src/core/work-item-import.ts
|
|
9400
|
+
import crypto3 from "crypto";
|
|
9399
9401
|
import matter8 from "gray-matter";
|
|
9402
|
+
var MAX_INPUT_BYTES = 102400;
|
|
9403
|
+
var LIFECYCLE_FIELDS = /* @__PURE__ */ new Set([
|
|
9404
|
+
"id",
|
|
9405
|
+
"status",
|
|
9406
|
+
"phase",
|
|
9407
|
+
"knowledge_level",
|
|
9408
|
+
"refined_by",
|
|
9409
|
+
"implemented_by",
|
|
9410
|
+
"closed_by",
|
|
9411
|
+
"ready_at",
|
|
9412
|
+
"generated_by",
|
|
9413
|
+
"template_version",
|
|
9414
|
+
"implementation_status",
|
|
9415
|
+
"validation_status",
|
|
9416
|
+
"release_status"
|
|
9417
|
+
]);
|
|
9418
|
+
function detectFormat(raw) {
|
|
9419
|
+
const trimmed = raw.trim();
|
|
9420
|
+
if (!trimmed) throw new ImportError("EMPTY_INPUT", "Import content is empty.");
|
|
9421
|
+
if (trimmed.startsWith("---")) {
|
|
9422
|
+
try {
|
|
9423
|
+
const { data } = matter8(trimmed);
|
|
9424
|
+
if (data && typeof data === "object" && Object.keys(data).length > 0) {
|
|
9425
|
+
const d = data;
|
|
9426
|
+
if (d.type === "work-item" || d.id && typeof d.id === "string" && /^WI-\d+/.test(d.id)) {
|
|
9427
|
+
return "kaddo-frontmatter";
|
|
9428
|
+
}
|
|
9429
|
+
return "markdown-frontmatter";
|
|
9430
|
+
}
|
|
9431
|
+
} catch {
|
|
9432
|
+
}
|
|
9433
|
+
}
|
|
9434
|
+
if (/^#{1,2}\s+/m.test(trimmed)) return "markdown";
|
|
9435
|
+
return "plain-text";
|
|
9436
|
+
}
|
|
9437
|
+
function parseContent(raw) {
|
|
9438
|
+
const trimmed = raw.trim();
|
|
9439
|
+
if (!trimmed) throw new ImportError("EMPTY_INPUT", "Import content is empty.");
|
|
9440
|
+
const format = detectFormat(trimmed);
|
|
9441
|
+
let frontmatterFields = {};
|
|
9442
|
+
let bodyText = trimmed;
|
|
9443
|
+
if (format === "kaddo-frontmatter" || format === "markdown-frontmatter") {
|
|
9444
|
+
try {
|
|
9445
|
+
const parsed = matter8(trimmed);
|
|
9446
|
+
frontmatterFields = parsed.data ?? {};
|
|
9447
|
+
bodyText = parsed.content.trim();
|
|
9448
|
+
} catch {
|
|
9449
|
+
}
|
|
9450
|
+
}
|
|
9451
|
+
const title = extractTitle(frontmatterFields, bodyText);
|
|
9452
|
+
const candidateType = extractType(frontmatterFields);
|
|
9453
|
+
const sections = extractSections(bodyText);
|
|
9454
|
+
const summary = bodyText || title;
|
|
9455
|
+
return {
|
|
9456
|
+
format,
|
|
9457
|
+
title,
|
|
9458
|
+
type: candidateType,
|
|
9459
|
+
summary,
|
|
9460
|
+
body: bodyText,
|
|
9461
|
+
candidateFields: frontmatterFields,
|
|
9462
|
+
sections
|
|
9463
|
+
};
|
|
9464
|
+
}
|
|
9465
|
+
function extractTitle(fields, body) {
|
|
9466
|
+
if (typeof fields.title === "string" && fields.title.trim()) {
|
|
9467
|
+
return fields.title.trim().slice(0, 120);
|
|
9468
|
+
}
|
|
9469
|
+
const h1Match = body.match(/^#\s+(.+)$/m);
|
|
9470
|
+
if (h1Match) return h1Match[1].trim().slice(0, 120);
|
|
9471
|
+
const firstLine = body.split(/\r?\n/).find((l) => l.trim());
|
|
9472
|
+
return (firstLine?.trim() ?? "Untitled Work Item").slice(0, 120);
|
|
9473
|
+
}
|
|
9474
|
+
function extractType(fields) {
|
|
9475
|
+
const raw = typeof fields.work_type === "string" && fields.work_type.trim() ? fields.work_type.trim() : typeof fields.type === "string" && fields.type.trim() && fields.type !== "work-item" ? fields.type.trim() : void 0;
|
|
9476
|
+
if (!raw) return void 0;
|
|
9477
|
+
return normalizeType(raw) ?? void 0;
|
|
9478
|
+
}
|
|
9479
|
+
function extractSections(body) {
|
|
9480
|
+
const sections = /* @__PURE__ */ new Map();
|
|
9481
|
+
const lines = body.split(/\r?\n/);
|
|
9482
|
+
let currentHeading = null;
|
|
9483
|
+
let buffer = [];
|
|
9484
|
+
const flush = () => {
|
|
9485
|
+
if (currentHeading) {
|
|
9486
|
+
sections.set(currentHeading.toLowerCase(), buffer.join("\n").trim());
|
|
9487
|
+
}
|
|
9488
|
+
buffer = [];
|
|
9489
|
+
};
|
|
9490
|
+
for (const line of lines) {
|
|
9491
|
+
const match = line.match(/^##\s+(.+)$/);
|
|
9492
|
+
if (match) {
|
|
9493
|
+
flush();
|
|
9494
|
+
currentHeading = match[1].trim();
|
|
9495
|
+
} else if (currentHeading) {
|
|
9496
|
+
buffer.push(line);
|
|
9497
|
+
}
|
|
9498
|
+
}
|
|
9499
|
+
flush();
|
|
9500
|
+
return sections;
|
|
9501
|
+
}
|
|
9502
|
+
function normalizeImportFields(parsed, opts) {
|
|
9503
|
+
const discardedFields = [];
|
|
9504
|
+
for (const key of Object.keys(parsed.candidateFields)) {
|
|
9505
|
+
if (LIFECYCLE_FIELDS.has(key)) discardedFields.push(key);
|
|
9506
|
+
}
|
|
9507
|
+
const type = opts.userType ? normalizeType(opts.userType) ?? "feature" : parsed.type ?? "feature";
|
|
9508
|
+
const intent = parsed.body && parsed.body !== parsed.title ? `${parsed.title}
|
|
9509
|
+
|
|
9510
|
+
${parsed.body}` : parsed.title;
|
|
9511
|
+
const source = {
|
|
9512
|
+
type: opts.importSource === "chat" ? "chat" : "external",
|
|
9513
|
+
imported_at: (/* @__PURE__ */ new Date()).toISOString().split("T")[0]
|
|
9514
|
+
};
|
|
9515
|
+
source.source_format = opts.sourceFormat;
|
|
9516
|
+
source.source_hash = opts.sourceHash;
|
|
9517
|
+
const snapshot = { title: parsed.title };
|
|
9518
|
+
if (parsed.summary !== parsed.title) snapshot.description = parsed.summary;
|
|
9519
|
+
if (typeof parsed.candidateFields.type === "string") snapshot.type = parsed.candidateFields.type;
|
|
9520
|
+
if (typeof parsed.candidateFields.status === "string") snapshot.status = parsed.candidateFields.status;
|
|
9521
|
+
if (Array.isArray(parsed.candidateFields.labels)) {
|
|
9522
|
+
const labels = parsed.candidateFields.labels.filter((l) => typeof l === "string");
|
|
9523
|
+
if (labels.length > 0) snapshot.labels = labels;
|
|
9524
|
+
}
|
|
9525
|
+
return { type, intent, source, snapshot, discardedFields };
|
|
9526
|
+
}
|
|
9527
|
+
function computeContentHash(raw) {
|
|
9528
|
+
return crypto3.createHash("sha256").update(raw.trim(), "utf-8").digest("hex");
|
|
9529
|
+
}
|
|
9530
|
+
function findDuplicateByHash(dir, hash) {
|
|
9531
|
+
const items = discoverWorkItems(dir);
|
|
9532
|
+
for (const item of items) {
|
|
9533
|
+
const raw = readFile(item.filePath);
|
|
9534
|
+
if (!raw) continue;
|
|
9535
|
+
try {
|
|
9536
|
+
const { data } = matter8(raw);
|
|
9537
|
+
const source = data?.source;
|
|
9538
|
+
if (source && typeof source === "object" && !Array.isArray(source)) {
|
|
9539
|
+
const s = source;
|
|
9540
|
+
if (s.source_hash === hash) {
|
|
9541
|
+
return { workItemId: data.id ?? item.id ?? item.title, path: item.relPath };
|
|
9542
|
+
}
|
|
9543
|
+
}
|
|
9544
|
+
} catch {
|
|
9545
|
+
}
|
|
9546
|
+
}
|
|
9547
|
+
return void 0;
|
|
9548
|
+
}
|
|
9549
|
+
function importWorkItem(dir, opts) {
|
|
9550
|
+
const content = opts.content;
|
|
9551
|
+
if (!content?.trim()) throw new ImportError("EMPTY_INPUT", "Import content is empty.");
|
|
9552
|
+
if (Buffer.byteLength(content, "utf-8") > MAX_INPUT_BYTES) {
|
|
9553
|
+
throw new ImportError("OVERSIZED_INPUT", `Import content exceeds the ${MAX_INPUT_BYTES / 1024}KB limit.`);
|
|
9554
|
+
}
|
|
9555
|
+
const parsed = parseContent(content);
|
|
9556
|
+
const sourceHash = computeContentHash(content);
|
|
9557
|
+
const duplicate = findDuplicateByHash(dir, sourceHash);
|
|
9558
|
+
if (duplicate) {
|
|
9559
|
+
return {
|
|
9560
|
+
created: false,
|
|
9561
|
+
workItemId: duplicate.workItemId,
|
|
9562
|
+
path: duplicate.path,
|
|
9563
|
+
status: "draft",
|
|
9564
|
+
source: opts.source,
|
|
9565
|
+
sourceFormat: parsed.format,
|
|
9566
|
+
sourceHash,
|
|
9567
|
+
duplicateOf: duplicate.workItemId,
|
|
9568
|
+
executed: false
|
|
9569
|
+
};
|
|
9570
|
+
}
|
|
9571
|
+
const normalized = normalizeImportFields(parsed, {
|
|
9572
|
+
userType: opts.type,
|
|
9573
|
+
importSource: opts.source,
|
|
9574
|
+
sourceHash,
|
|
9575
|
+
sourceFormat: parsed.format
|
|
9576
|
+
});
|
|
9577
|
+
const result = createWorkItem(dir, {
|
|
9578
|
+
intent: normalized.intent,
|
|
9579
|
+
type: normalized.type,
|
|
9580
|
+
source: normalized.source,
|
|
9581
|
+
originalSnapshot: normalized.snapshot
|
|
9582
|
+
});
|
|
9583
|
+
let refinementHandoff;
|
|
9584
|
+
try {
|
|
9585
|
+
refinementHandoff = buildRefinementHandoff(dir, result.id);
|
|
9586
|
+
} catch {
|
|
9587
|
+
}
|
|
9588
|
+
return {
|
|
9589
|
+
created: true,
|
|
9590
|
+
workItemId: result.id,
|
|
9591
|
+
path: result.path,
|
|
9592
|
+
status: "draft",
|
|
9593
|
+
source: opts.source,
|
|
9594
|
+
sourceFormat: parsed.format,
|
|
9595
|
+
sourceHash,
|
|
9596
|
+
executed: false,
|
|
9597
|
+
refinementHandoff,
|
|
9598
|
+
...normalized.discardedFields.length > 0 ? { discardedFields: normalized.discardedFields } : {}
|
|
9599
|
+
};
|
|
9600
|
+
}
|
|
9601
|
+
var ImportError = class extends Error {
|
|
9602
|
+
constructor(code, message) {
|
|
9603
|
+
super(message);
|
|
9604
|
+
this.code = code;
|
|
9605
|
+
this.name = "ImportError";
|
|
9606
|
+
}
|
|
9607
|
+
code;
|
|
9608
|
+
};
|
|
9609
|
+
|
|
9610
|
+
// src/services/integrations.ts
|
|
9611
|
+
import matter9 from "gray-matter";
|
|
9400
9612
|
import { parse as parseYaml9, stringify as stringifyYaml5 } from "yaml";
|
|
9401
9613
|
|
|
9402
9614
|
// ../integrations/src/errors.ts
|
|
@@ -10738,7 +10950,7 @@ function findLinkedWorkItem(dir, integrationId, externalId) {
|
|
|
10738
10950
|
for (const art of discoverWorkItems(dir)) {
|
|
10739
10951
|
let data;
|
|
10740
10952
|
try {
|
|
10741
|
-
data =
|
|
10953
|
+
data = matter9(readFile(art.filePath)).data;
|
|
10742
10954
|
} catch {
|
|
10743
10955
|
continue;
|
|
10744
10956
|
}
|
|
@@ -10754,7 +10966,7 @@ function buildImportIndex(dir) {
|
|
|
10754
10966
|
for (const art of discoverWorkItems(dir)) {
|
|
10755
10967
|
let data;
|
|
10756
10968
|
try {
|
|
10757
|
-
data =
|
|
10969
|
+
data = matter9(readFile(art.filePath)).data;
|
|
10758
10970
|
} catch {
|
|
10759
10971
|
continue;
|
|
10760
10972
|
}
|
|
@@ -10819,6 +11031,7 @@ ${item.description}` : item.title;
|
|
|
10819
11031
|
}
|
|
10820
11032
|
export {
|
|
10821
11033
|
INTEGRATIONS_FILE,
|
|
11034
|
+
ImportError,
|
|
10822
11035
|
IntegrationError,
|
|
10823
11036
|
IntegrationServiceError,
|
|
10824
11037
|
TOPOLOGY_FILE,
|
|
@@ -10834,17 +11047,20 @@ export {
|
|
|
10834
11047
|
buildReadinessReport,
|
|
10835
11048
|
buildRefinementHandoff,
|
|
10836
11049
|
buildTopologyEnrichmentHandoff,
|
|
11050
|
+
computeContentHash,
|
|
10837
11051
|
computeRefinementStatus,
|
|
10838
11052
|
createIntegration,
|
|
10839
11053
|
createWorkItem,
|
|
10840
11054
|
cwd,
|
|
10841
11055
|
deleteIntegration,
|
|
11056
|
+
detectFormat,
|
|
10842
11057
|
disableIntegration,
|
|
10843
11058
|
discoverExternalWorkItems,
|
|
10844
11059
|
discoverKnowledge,
|
|
10845
11060
|
discoverWorkItems,
|
|
10846
11061
|
enableIntegration,
|
|
10847
11062
|
exists,
|
|
11063
|
+
findDuplicateByHash,
|
|
10848
11064
|
findLinkedWorkItem,
|
|
10849
11065
|
findSystemPaths,
|
|
10850
11066
|
getAvailableIntegrationTypes,
|
|
@@ -10862,6 +11078,7 @@ export {
|
|
|
10862
11078
|
getWorkItems,
|
|
10863
11079
|
getWorkItemsSummary,
|
|
10864
11080
|
importExternalWorkItem,
|
|
11081
|
+
importWorkItem,
|
|
10865
11082
|
integrationRegistry,
|
|
10866
11083
|
isActiveState,
|
|
10867
11084
|
isModule,
|
|
@@ -10874,6 +11091,7 @@ export {
|
|
|
10874
11091
|
loadConfig,
|
|
10875
11092
|
loadMappedModules,
|
|
10876
11093
|
loadSystemTopology,
|
|
11094
|
+
parseContent,
|
|
10877
11095
|
previewImport,
|
|
10878
11096
|
readFile,
|
|
10879
11097
|
removeIntegrationSecret,
|
package/dist/index.js
CHANGED
|
@@ -12710,6 +12710,7 @@ var VALID_SOURCES = [
|
|
|
12710
12710
|
"csv",
|
|
12711
12711
|
"api",
|
|
12712
12712
|
"external",
|
|
12713
|
+
"chat",
|
|
12713
12714
|
"unknown"
|
|
12714
12715
|
];
|
|
12715
12716
|
function isValidSource(s) {
|
|
@@ -20288,6 +20289,850 @@ async function runAdmin(opts = {}) {
|
|
|
20288
20289
|
process.on("SIGTERM", shutdown);
|
|
20289
20290
|
}
|
|
20290
20291
|
|
|
20292
|
+
// src/core/work-item-import.ts
|
|
20293
|
+
import crypto3 from "crypto";
|
|
20294
|
+
import matter15 from "gray-matter";
|
|
20295
|
+
|
|
20296
|
+
// src/core/work-items.ts
|
|
20297
|
+
import matter14 from "gray-matter";
|
|
20298
|
+
function computeRefinementStatus(wi) {
|
|
20299
|
+
const aspects = {
|
|
20300
|
+
outcome: Boolean(wi.currentBehavior?.trim() || wi.targetBehavior?.trim()),
|
|
20301
|
+
journey: Boolean(wi.entryPoints?.trim() || wi.endToEndFlow?.trim()),
|
|
20302
|
+
modules: wi.affectedModules.length > 0 || wi.moduleCoverage.length > 0,
|
|
20303
|
+
impact: wi.impactAnalysis.length > 0,
|
|
20304
|
+
acceptance: wi.acceptanceCriteria.length > 0
|
|
20305
|
+
};
|
|
20306
|
+
const refined = aspects.outcome && aspects.modules && aspects.acceptance;
|
|
20307
|
+
return { status: refined ? "refined" : "needs-refinement", aspects };
|
|
20308
|
+
}
|
|
20309
|
+
var WorkItemNotFoundError = class extends Error {
|
|
20310
|
+
constructor(workItemId) {
|
|
20311
|
+
super(`Work Item "${workItemId}" was not found.`);
|
|
20312
|
+
this.workItemId = workItemId;
|
|
20313
|
+
this.name = "WorkItemNotFoundError";
|
|
20314
|
+
}
|
|
20315
|
+
workItemId;
|
|
20316
|
+
};
|
|
20317
|
+
function toListItem(a) {
|
|
20318
|
+
return {
|
|
20319
|
+
id: a.id || a.title,
|
|
20320
|
+
title: a.title || a.id,
|
|
20321
|
+
type: a.type,
|
|
20322
|
+
status: lifecycleStateOf({ status: a.status, filePath: a.filePath }),
|
|
20323
|
+
implementationStatus: a.implementationStatus || null,
|
|
20324
|
+
validationStatus: a.validationStatus || null,
|
|
20325
|
+
releaseStatus: a.releaseStatus || null,
|
|
20326
|
+
affectedModules: a.affectedModules,
|
|
20327
|
+
scopeConfidenceLevel: a.scopeConfidence?.level ?? null,
|
|
20328
|
+
initiative: a.initiative || null
|
|
20329
|
+
};
|
|
20330
|
+
}
|
|
20331
|
+
function getWorkItem(dir, workItemId) {
|
|
20332
|
+
const artifacts = discoverWorkItems(dir);
|
|
20333
|
+
const match = artifacts.find((a) => (a.id || a.title) === workItemId);
|
|
20334
|
+
if (!match) throw new WorkItemNotFoundError(workItemId);
|
|
20335
|
+
const base = toListItem(match);
|
|
20336
|
+
const body = readBody(match.filePath);
|
|
20337
|
+
const sections = splitSections(body);
|
|
20338
|
+
const fm2 = match.rawFrontmatter;
|
|
20339
|
+
const knowledge = discoverKnowledge(dir).filter((a) => !a.isWorkItem);
|
|
20340
|
+
const knowledgeById = new Map(knowledge.filter((k) => k.id).map((k) => [k.id, k]));
|
|
20341
|
+
const detail = {
|
|
20342
|
+
...base,
|
|
20343
|
+
summary: match.summary?.trim() || null,
|
|
20344
|
+
actor: sectionText(sections, ["actor"]),
|
|
20345
|
+
outcome: sectionText(sections, ["actor and outcome", "outcome", "expected result"]),
|
|
20346
|
+
currentBehavior: sectionText(sections, ["current behavior", "current behaviour"]),
|
|
20347
|
+
targetBehavior: sectionText(sections, ["target behavior", "target behaviour"]),
|
|
20348
|
+
entryPoints: sectionText(sections, ["entry points"]),
|
|
20349
|
+
endToEndFlow: sectionText(sections, ["end-to-end flow", "end to end flow", "flow"]),
|
|
20350
|
+
scopeConfidence: match.scopeConfidence,
|
|
20351
|
+
scopeUnknowns: sectionBullets(sections, ["scope unknowns", "open scope questions"]),
|
|
20352
|
+
moduleCoverage: normalizeCoverage(match.moduleCoverage),
|
|
20353
|
+
impactAnalysis: normalizeImpact(match.impactAnalysis),
|
|
20354
|
+
acceptanceCriteria: parseAcceptanceCriteria(sections),
|
|
20355
|
+
implementationEvidence: parseEvidence(fm2),
|
|
20356
|
+
releaseGates: parseReleaseGates(fm2),
|
|
20357
|
+
completionExceptions: parseExceptions(fm2),
|
|
20358
|
+
decisions: parseDecisions(match.decisions, knowledgeById),
|
|
20359
|
+
relatedKnowledge: parseRelatedKnowledge(fm2, knowledgeById),
|
|
20360
|
+
source: parseWorkItemSource(fm2),
|
|
20361
|
+
originalSnapshot: parseOriginalSnapshot(fm2),
|
|
20362
|
+
path: match.relPath,
|
|
20363
|
+
...parseSystemImpact(dir, fm2)
|
|
20364
|
+
};
|
|
20365
|
+
return { ...detail, refinement: computeRefinementStatus(detail) };
|
|
20366
|
+
}
|
|
20367
|
+
function parseGraphReason(v) {
|
|
20368
|
+
if (!v || typeof v !== "object") return null;
|
|
20369
|
+
const o = v;
|
|
20370
|
+
const relationship = typeof o.relationship === "string" && o.relationship.trim() ? o.relationship.trim() : null;
|
|
20371
|
+
const path11 = Array.isArray(o.path) ? o.path.map(String).filter(Boolean) : [];
|
|
20372
|
+
return relationship || path11.length ? { relationship, path: path11 } : null;
|
|
20373
|
+
}
|
|
20374
|
+
function parseExplain(o) {
|
|
20375
|
+
const refs = Array.isArray(o.evidence) ? o.evidence : Array.isArray(o.evidence_refs) ? o.evidence_refs : [];
|
|
20376
|
+
return {
|
|
20377
|
+
reason: typeof o.reason === "string" && o.reason.trim() ? o.reason.trim() : null,
|
|
20378
|
+
graphReason: parseGraphReason(o.graph_reason),
|
|
20379
|
+
evidenceRefs: refs.map(String).filter(Boolean),
|
|
20380
|
+
evidenceSummary: typeof o.evidence_summary === "string" && o.evidence_summary.trim() ? o.evidence_summary.trim() : null
|
|
20381
|
+
};
|
|
20382
|
+
}
|
|
20383
|
+
function emptyExplain() {
|
|
20384
|
+
return { reason: null, graphReason: null, evidenceRefs: [], evidenceSummary: null };
|
|
20385
|
+
}
|
|
20386
|
+
function parseSystemImpact(dir, fm2) {
|
|
20387
|
+
const topology = loadSystemTopology(dir);
|
|
20388
|
+
const byId = new Map(topology.entities.map((e) => [e.id, e]));
|
|
20389
|
+
const resolve = (id) => {
|
|
20390
|
+
const e = byId.get(id);
|
|
20391
|
+
return { id, nodeId: `sys:${id}`, label: e?.label ?? id, kind: e?.kind ?? "unknown", moduleId: e?.moduleId ?? null };
|
|
20392
|
+
};
|
|
20393
|
+
const affected = Array.isArray(fm2.affected_system_entities) ? fm2.affected_system_entities.map((raw) => {
|
|
20394
|
+
if (typeof raw === "string") return raw ? { ...resolve(raw), ...emptyExplain() } : null;
|
|
20395
|
+
if (raw && typeof raw === "object") {
|
|
20396
|
+
const o = raw;
|
|
20397
|
+
const id = String(o.id ?? "");
|
|
20398
|
+
return id ? { ...resolve(id), ...parseExplain(o) } : null;
|
|
20399
|
+
}
|
|
20400
|
+
return null;
|
|
20401
|
+
}).filter((e) => e != null) : [];
|
|
20402
|
+
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) : [];
|
|
20403
|
+
const graphRevision = typeof fm2.graph_revision === "string" && fm2.graph_revision.trim() ? fm2.graph_revision.trim() : null;
|
|
20404
|
+
const graphCoverage = topology.entities.length === 0 ? "unavailable" : topology.relationships.length > 0 ? "available" : "partial";
|
|
20405
|
+
return { affectedSystemEntities: affected, reviewedSystemEntities: reviewed, graphRevision, graphCoverage };
|
|
20406
|
+
}
|
|
20407
|
+
function parseOriginalSnapshot(fm2) {
|
|
20408
|
+
const raw = fm2.original_snapshot;
|
|
20409
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
20410
|
+
const o = raw;
|
|
20411
|
+
const title = typeof o.title === "string" ? o.title : void 0;
|
|
20412
|
+
if (!title) return null;
|
|
20413
|
+
return {
|
|
20414
|
+
title,
|
|
20415
|
+
description: typeof o.description === "string" ? o.description : void 0,
|
|
20416
|
+
type: typeof o.type === "string" ? o.type : void 0,
|
|
20417
|
+
status: typeof o.status === "string" ? o.status : void 0,
|
|
20418
|
+
labels: Array.isArray(o.labels) ? o.labels.map(String) : void 0,
|
|
20419
|
+
assignee: typeof o.assignee === "string" ? o.assignee : void 0,
|
|
20420
|
+
created_at: typeof o.created_at === "string" ? o.created_at : void 0,
|
|
20421
|
+
updated_at: typeof o.updated_at === "string" ? o.updated_at : void 0
|
|
20422
|
+
};
|
|
20423
|
+
}
|
|
20424
|
+
function readBody(filePath) {
|
|
20425
|
+
try {
|
|
20426
|
+
const raw = readFile(filePath);
|
|
20427
|
+
return matter14(raw).content;
|
|
20428
|
+
} catch {
|
|
20429
|
+
return "";
|
|
20430
|
+
}
|
|
20431
|
+
}
|
|
20432
|
+
function splitSections(body) {
|
|
20433
|
+
const sections = /* @__PURE__ */ new Map();
|
|
20434
|
+
const lines = body.split(/\r?\n/);
|
|
20435
|
+
let current = null;
|
|
20436
|
+
let buffer = [];
|
|
20437
|
+
const flush = () => {
|
|
20438
|
+
if (current !== null) sections.set(current, buffer.join("\n").trim());
|
|
20439
|
+
buffer = [];
|
|
20440
|
+
};
|
|
20441
|
+
for (const line of lines) {
|
|
20442
|
+
const m = line.match(/^#{1,6}\s+(.*?)\s*$/);
|
|
20443
|
+
if (m) {
|
|
20444
|
+
flush();
|
|
20445
|
+
current = m[1].toLowerCase().replace(/[`*_]/g, "").trim();
|
|
20446
|
+
} else if (current !== null) {
|
|
20447
|
+
buffer.push(line);
|
|
20448
|
+
}
|
|
20449
|
+
}
|
|
20450
|
+
flush();
|
|
20451
|
+
return sections;
|
|
20452
|
+
}
|
|
20453
|
+
function isPlaceholder(text3) {
|
|
20454
|
+
const t = text3.trim();
|
|
20455
|
+
if (!t) return true;
|
|
20456
|
+
if (/^tbd$/i.test(t)) return true;
|
|
20457
|
+
if (/^_[^_]*_$/.test(t) && !t.includes("\n")) return true;
|
|
20458
|
+
return false;
|
|
20459
|
+
}
|
|
20460
|
+
function sectionText(sections, headings2) {
|
|
20461
|
+
for (const h of headings2) {
|
|
20462
|
+
const body = sections.get(h);
|
|
20463
|
+
if (body != null && !isPlaceholder(body)) return body.trim();
|
|
20464
|
+
}
|
|
20465
|
+
return null;
|
|
20466
|
+
}
|
|
20467
|
+
function sectionBullets(sections, headings2) {
|
|
20468
|
+
for (const h of headings2) {
|
|
20469
|
+
const body = sections.get(h);
|
|
20470
|
+
if (body == null || isPlaceholder(body)) continue;
|
|
20471
|
+
const bullets = extractBullets(body);
|
|
20472
|
+
if (bullets.length > 0) return bullets.map((b) => b.text);
|
|
20473
|
+
}
|
|
20474
|
+
return [];
|
|
20475
|
+
}
|
|
20476
|
+
function extractBullets(body) {
|
|
20477
|
+
const out = [];
|
|
20478
|
+
for (const line of body.split(/\r?\n/)) {
|
|
20479
|
+
const m = line.match(/^\s*[-*+]\s+(.*)$/);
|
|
20480
|
+
if (!m) continue;
|
|
20481
|
+
let text3 = m[1].trim();
|
|
20482
|
+
let checked = null;
|
|
20483
|
+
const cb = text3.match(/^\[([ xX])\]\s*(.*)$/);
|
|
20484
|
+
if (cb) {
|
|
20485
|
+
checked = cb[1].toLowerCase() === "x";
|
|
20486
|
+
text3 = cb[2].trim();
|
|
20487
|
+
}
|
|
20488
|
+
if (!text3 || isPlaceholder(text3)) continue;
|
|
20489
|
+
out.push({ text: text3, checked });
|
|
20490
|
+
}
|
|
20491
|
+
return out;
|
|
20492
|
+
}
|
|
20493
|
+
function parseAcceptanceCriteria(sections) {
|
|
20494
|
+
const body = sections.get("acceptance criteria");
|
|
20495
|
+
if (body == null || isPlaceholder(body)) return [];
|
|
20496
|
+
return extractBullets(body).map((b) => ({ text: b.text, checked: b.checked }));
|
|
20497
|
+
}
|
|
20498
|
+
function normalizeCoverage(mc) {
|
|
20499
|
+
if (!mc) return [];
|
|
20500
|
+
return Object.entries(mc).map(([id, v]) => ({ id, status: v.status, ...v.reason ? { reason: v.reason } : {} }));
|
|
20501
|
+
}
|
|
20502
|
+
function normalizeImpact(ia) {
|
|
20503
|
+
if (!ia) return [];
|
|
20504
|
+
return Object.entries(ia).map(([surface, v]) => ({
|
|
20505
|
+
surface,
|
|
20506
|
+
status: v.status,
|
|
20507
|
+
...v.reason ? { reason: v.reason } : {},
|
|
20508
|
+
...v.question ? { question: v.question } : {}
|
|
20509
|
+
}));
|
|
20510
|
+
}
|
|
20511
|
+
function optStr2(v) {
|
|
20512
|
+
if (typeof v === "string" && v.trim()) return v.trim();
|
|
20513
|
+
return void 0;
|
|
20514
|
+
}
|
|
20515
|
+
function parseEvidence(fm2) {
|
|
20516
|
+
const evidence = fm2.implementation_evidence;
|
|
20517
|
+
const repos = evidence?.repositories;
|
|
20518
|
+
if (!repos || typeof repos !== "object" || Array.isArray(repos)) return [];
|
|
20519
|
+
const out = [];
|
|
20520
|
+
for (const [module, val] of Object.entries(repos)) {
|
|
20521
|
+
if (!val || typeof val !== "object" || Array.isArray(val)) continue;
|
|
20522
|
+
const d = val;
|
|
20523
|
+
const validations = Array.isArray(d.validations) ? d.validations.map((v) => ({
|
|
20524
|
+
command: String(v.command ?? ""),
|
|
20525
|
+
status: String(v.status ?? "unknown"),
|
|
20526
|
+
...optStr2(v.reason) ? { reason: optStr2(v.reason) } : {}
|
|
20527
|
+
})) : [];
|
|
20528
|
+
const migrations = Array.isArray(d.migrations) ? d.migrations.map((m) => ({
|
|
20529
|
+
id: String(m.id ?? ""),
|
|
20530
|
+
environment: String(m.environment ?? ""),
|
|
20531
|
+
status: String(m.status ?? "unknown"),
|
|
20532
|
+
...optStr2(m.reason) ? { reason: optStr2(m.reason) } : {}
|
|
20533
|
+
})) : [];
|
|
20534
|
+
out.push({
|
|
20535
|
+
module,
|
|
20536
|
+
role: String(d.role ?? (module === "core" ? "core" : "module")),
|
|
20537
|
+
status: String(d.status ?? "unknown"),
|
|
20538
|
+
changedPaths: Array.isArray(d.changed_paths) ? d.changed_paths.map(String).filter(Boolean) : [],
|
|
20539
|
+
validations,
|
|
20540
|
+
migrations
|
|
20541
|
+
});
|
|
20542
|
+
}
|
|
20543
|
+
return out;
|
|
20544
|
+
}
|
|
20545
|
+
function parseReleaseGates(fm2) {
|
|
20546
|
+
if (!Array.isArray(fm2.release_gates)) return [];
|
|
20547
|
+
return fm2.release_gates.filter((g) => g && typeof g === "object").map((g) => ({
|
|
20548
|
+
id: String(g.id ?? ""),
|
|
20549
|
+
status: String(g.status ?? "pending"),
|
|
20550
|
+
...optStr2(g.reason) ? { reason: optStr2(g.reason) } : {},
|
|
20551
|
+
...optStr2(g.required_for) ? { requiredFor: optStr2(g.required_for) } : {}
|
|
20552
|
+
}));
|
|
20553
|
+
}
|
|
20554
|
+
function parseExceptions(fm2) {
|
|
20555
|
+
if (!Array.isArray(fm2.completion_exceptions)) return [];
|
|
20556
|
+
return fm2.completion_exceptions.filter((e) => e && typeof e === "object").map((e) => ({
|
|
20557
|
+
id: String(e.id ?? ""),
|
|
20558
|
+
status: String(e.status ?? "proposed"),
|
|
20559
|
+
...optStr2(e.reason) ? { reason: optStr2(e.reason) } : {},
|
|
20560
|
+
...optStr2(e.category) ? { category: optStr2(e.category) } : {},
|
|
20561
|
+
...optStr2(e.impact) ? { impact: optStr2(e.impact) } : {}
|
|
20562
|
+
}));
|
|
20563
|
+
}
|
|
20564
|
+
function parseDecisions(decisions, knowledgeById) {
|
|
20565
|
+
return decisions.map((id) => {
|
|
20566
|
+
const k = knowledgeById.get(id);
|
|
20567
|
+
return {
|
|
20568
|
+
id,
|
|
20569
|
+
...k?.title ? { title: k.title } : {},
|
|
20570
|
+
...k ? { knowledgeId: k.id, knowledgeLayer: k.layer } : {}
|
|
20571
|
+
};
|
|
20572
|
+
});
|
|
20573
|
+
}
|
|
20574
|
+
function parseRelatedKnowledge(fm2, knowledgeById) {
|
|
20575
|
+
const refs = /* @__PURE__ */ new Set();
|
|
20576
|
+
for (const field of ["related_knowledge", "knowledge", "related"]) {
|
|
20577
|
+
const v = fm2[field];
|
|
20578
|
+
if (Array.isArray(v)) {
|
|
20579
|
+
for (const r of v) if (typeof r === "string" && r.trim()) refs.add(r.trim());
|
|
20580
|
+
}
|
|
20581
|
+
}
|
|
20582
|
+
const out = [];
|
|
20583
|
+
for (const ref of refs) {
|
|
20584
|
+
const k = knowledgeById.get(ref);
|
|
20585
|
+
if (k && k.id) out.push({ id: k.id, title: k.title || k.id, layer: k.layer });
|
|
20586
|
+
}
|
|
20587
|
+
return out;
|
|
20588
|
+
}
|
|
20589
|
+
|
|
20590
|
+
// src/core/system-map.ts
|
|
20591
|
+
function dimensionOf(type) {
|
|
20592
|
+
switch (type) {
|
|
20593
|
+
case "module":
|
|
20594
|
+
case "application":
|
|
20595
|
+
case "service":
|
|
20596
|
+
case "component":
|
|
20597
|
+
case "api":
|
|
20598
|
+
case "interface":
|
|
20599
|
+
case "database":
|
|
20600
|
+
case "queue":
|
|
20601
|
+
case "job":
|
|
20602
|
+
case "external-system":
|
|
20603
|
+
return "system";
|
|
20604
|
+
case "business":
|
|
20605
|
+
case "product":
|
|
20606
|
+
case "tech":
|
|
20607
|
+
case "delivery":
|
|
20608
|
+
case "capability":
|
|
20609
|
+
case "decision":
|
|
20610
|
+
case "project":
|
|
20611
|
+
case "knowledge-capsule":
|
|
20612
|
+
return "knowledge";
|
|
20613
|
+
case "work-item":
|
|
20614
|
+
case "initiative":
|
|
20615
|
+
case "roadmap-candidate":
|
|
20616
|
+
case "release":
|
|
20617
|
+
return "delivery";
|
|
20618
|
+
case "code-glob":
|
|
20619
|
+
case "file":
|
|
20620
|
+
case "directory":
|
|
20621
|
+
case "migration":
|
|
20622
|
+
case "configuration-artifact":
|
|
20623
|
+
return "implementation";
|
|
20624
|
+
default:
|
|
20625
|
+
return "unknown";
|
|
20626
|
+
}
|
|
20627
|
+
}
|
|
20628
|
+
var EDGE_LABELS = {
|
|
20629
|
+
informs: "informs",
|
|
20630
|
+
belongs_to: "belongs to",
|
|
20631
|
+
materialized_as: "materialized as",
|
|
20632
|
+
owns: "owns",
|
|
20633
|
+
implements: "implements",
|
|
20634
|
+
depends_on: "depends on",
|
|
20635
|
+
governs: "governs",
|
|
20636
|
+
provides_external_context: "provides external context",
|
|
20637
|
+
uses_external_knowledge: "uses external knowledge"
|
|
20638
|
+
};
|
|
20639
|
+
function emptyDimensions() {
|
|
20640
|
+
return { system: 0, knowledge: 0, delivery: 0, implementation: 0, unknown: 0 };
|
|
20641
|
+
}
|
|
20642
|
+
function emptyProjection(name, structure) {
|
|
20643
|
+
return {
|
|
20644
|
+
system: { name },
|
|
20645
|
+
nodes: [],
|
|
20646
|
+
relationships: [],
|
|
20647
|
+
groups: [],
|
|
20648
|
+
metadata: {
|
|
20649
|
+
projectName: name,
|
|
20650
|
+
structure,
|
|
20651
|
+
nodeCount: 0,
|
|
20652
|
+
relationshipCount: 0,
|
|
20653
|
+
coverage: "empty",
|
|
20654
|
+
available: false,
|
|
20655
|
+
dimensions: emptyDimensions(),
|
|
20656
|
+
topologyAvailable: false,
|
|
20657
|
+
topologyStatus: "unavailable",
|
|
20658
|
+
semanticEntityCount: 0,
|
|
20659
|
+
technicalRelationshipCount: 0,
|
|
20660
|
+
topologyFindings: []
|
|
20661
|
+
}
|
|
20662
|
+
};
|
|
20663
|
+
}
|
|
20664
|
+
function getSystemMapProjection(dir) {
|
|
20665
|
+
const config = loadConfig(dir);
|
|
20666
|
+
if (!config) return emptyProjection("unknown", "unknown");
|
|
20667
|
+
const graph = buildGraph(dir, config, { scope: "all" });
|
|
20668
|
+
const hints = buildGraphHints(dir, graph);
|
|
20669
|
+
const knowledgeByPath = /* @__PURE__ */ new Map();
|
|
20670
|
+
for (const a of discoverKnowledge(dir).filter((a2) => !a2.isWorkItem)) {
|
|
20671
|
+
const id = a.id || a.relPath.replace(/[/\\]/g, "-").replace(/\.md$/, "");
|
|
20672
|
+
const layer2 = a.layer === "module" ? "tech" : a.layer;
|
|
20673
|
+
knowledgeByPath.set(a.relPath, { id, layer: layer2 });
|
|
20674
|
+
}
|
|
20675
|
+
const wiModules = /* @__PURE__ */ new Map();
|
|
20676
|
+
for (const wi of discoverWorkItems(dir)) wiModules.set(wi.id || wi.title, wi.affectedModules);
|
|
20677
|
+
const mapped = loadMappedModules(dir);
|
|
20678
|
+
const groupIds = /* @__PURE__ */ new Set(["core", ...mapped.map((m) => m.id)]);
|
|
20679
|
+
const nodes = graph.nodes.map((n) => toNode(n, knowledgeByPath, wiModules, groupIds));
|
|
20680
|
+
const relationships = graph.edges.map((e) => ({
|
|
20681
|
+
id: `${e.from}~${e.type}~${e.to}`,
|
|
20682
|
+
source: e.from,
|
|
20683
|
+
target: e.to,
|
|
20684
|
+
type: e.type,
|
|
20685
|
+
label: EDGE_LABELS[e.type] ?? e.type.replace(/_/g, " ")
|
|
20686
|
+
}));
|
|
20687
|
+
const knowledgeById = /* @__PURE__ */ new Map();
|
|
20688
|
+
for (const ref of knowledgeByPath.values()) knowledgeById.set(ref.id, ref);
|
|
20689
|
+
const topology = loadSystemTopology(dir);
|
|
20690
|
+
const existingIds = new Set(nodes.map((n) => n.id));
|
|
20691
|
+
for (const e of topology.entities) {
|
|
20692
|
+
const nodeId = `sys:${e.id}`;
|
|
20693
|
+
const node = {
|
|
20694
|
+
id: nodeId,
|
|
20695
|
+
type: e.kind,
|
|
20696
|
+
label: e.label,
|
|
20697
|
+
dimension: "system",
|
|
20698
|
+
implementationRefs: e.implementationRefs,
|
|
20699
|
+
knowledgeRefs: e.knowledgeRefs.map((k) => knowledgeById.get(k)).filter(Boolean),
|
|
20700
|
+
evidence: e.evidence
|
|
20701
|
+
};
|
|
20702
|
+
if (e.purpose) node.purpose = e.purpose;
|
|
20703
|
+
if (e.moduleId) node.moduleId = e.moduleId;
|
|
20704
|
+
if (e.provenance) node.provenance = e.provenance;
|
|
20705
|
+
nodes.push(node);
|
|
20706
|
+
existingIds.add(nodeId);
|
|
20707
|
+
for (const ref of e.implementationRefs) {
|
|
20708
|
+
const fileId = `file:${ref}`;
|
|
20709
|
+
if (!existingIds.has(fileId)) {
|
|
20710
|
+
nodes.push({ id: fileId, type: "file", label: ref.split("/").pop() || ref, dimension: "implementation", path: ref });
|
|
20711
|
+
existingIds.add(fileId);
|
|
20712
|
+
}
|
|
20713
|
+
relationships.push({ id: `${nodeId}~implemented-by~${fileId}`, source: nodeId, target: fileId, type: "implemented-by", label: "implemented by" });
|
|
20714
|
+
}
|
|
20715
|
+
}
|
|
20716
|
+
for (const r of topology.relationships) {
|
|
20717
|
+
relationships.push({ id: `sys:${r.from}~${r.type}~sys:${r.to}`, source: `sys:${r.from}`, target: `sys:${r.to}`, type: r.type, label: r.type.replace(/-/g, " ") });
|
|
20718
|
+
}
|
|
20719
|
+
const usedGroups = new Set(nodes.map((n) => n.moduleId).filter(Boolean));
|
|
20720
|
+
const allGroups = [
|
|
20721
|
+
{ id: "core", label: "core", repositoryId: "core", available: true },
|
|
20722
|
+
// A mapped module is available when its repository path resolves relative to the project.
|
|
20723
|
+
...mapped.map((m) => ({ id: m.id, label: m.id, repositoryId: m.id, available: m.repoPath ? exists(join(dir, m.repoPath)) : false }))
|
|
20724
|
+
];
|
|
20725
|
+
const groups = allGroups.filter((g) => usedGroups.has(g.id) || g.available === false);
|
|
20726
|
+
const dimensions = emptyDimensions();
|
|
20727
|
+
for (const n of nodes) dimensions[n.dimension]++;
|
|
20728
|
+
const semanticEntityCount = topology.entities.length;
|
|
20729
|
+
const technicalRelationshipCount = relationships.filter((r) => TECHNICAL_RELATIONSHIP_TYPES.has(r.type)).length;
|
|
20730
|
+
const topologyStatus = semanticEntityCount === 0 ? "unavailable" : topology.relationships.length > 0 ? "available" : "partial";
|
|
20731
|
+
return {
|
|
20732
|
+
system: { name: config.project.name },
|
|
20733
|
+
nodes,
|
|
20734
|
+
relationships,
|
|
20735
|
+
groups,
|
|
20736
|
+
metadata: {
|
|
20737
|
+
projectName: config.project.name,
|
|
20738
|
+
structure: config.project.structure,
|
|
20739
|
+
nodeCount: nodes.length,
|
|
20740
|
+
relationshipCount: relationships.length,
|
|
20741
|
+
coverage: hints.quality,
|
|
20742
|
+
available: nodes.length > 0,
|
|
20743
|
+
dimensions,
|
|
20744
|
+
topologyAvailable: dimensions.system > 0,
|
|
20745
|
+
topologyStatus,
|
|
20746
|
+
semanticEntityCount,
|
|
20747
|
+
technicalRelationshipCount,
|
|
20748
|
+
topologyFindings: topology.findings
|
|
20749
|
+
}
|
|
20750
|
+
};
|
|
20751
|
+
}
|
|
20752
|
+
function toNode(n, knowledgeByPath, wiModules, groupIds) {
|
|
20753
|
+
const node = { id: n.id, type: n.type, label: n.label, dimension: dimensionOf(n.type) };
|
|
20754
|
+
if (n.status) node.status = n.status;
|
|
20755
|
+
if (n.path && !/^([a-zA-Z]:[\\/]|\/)/.test(n.path)) node.path = n.path;
|
|
20756
|
+
if (n.type === "work-item") {
|
|
20757
|
+
const wiId = n.id.startsWith("wi:") ? n.id.slice(3) : n.id;
|
|
20758
|
+
node.workItemRef = wiId;
|
|
20759
|
+
const affected = (wiModules.get(wiId) ?? []).filter((m) => groupIds.has(m));
|
|
20760
|
+
if (affected.length === 1) node.moduleId = affected[0];
|
|
20761
|
+
}
|
|
20762
|
+
if (n.path) {
|
|
20763
|
+
const ref = knowledgeByPath.get(n.path);
|
|
20764
|
+
if (ref) node.knowledgeRef = ref;
|
|
20765
|
+
}
|
|
20766
|
+
return node;
|
|
20767
|
+
}
|
|
20768
|
+
|
|
20769
|
+
// src/core/work-item-refinement.ts
|
|
20770
|
+
var RECOMMENDED_AGENT = "work-item-agent";
|
|
20771
|
+
var RECOMMENDED_SKILL = "work-item-refinement";
|
|
20772
|
+
function buildRefinementHandoff(dir, workItemId) {
|
|
20773
|
+
const wi = getWorkItem(dir, workItemId);
|
|
20774
|
+
const config = loadConfig(dir);
|
|
20775
|
+
const projectName = config?.project.name ?? "this project";
|
|
20776
|
+
const mappedModules = loadMappedModules(dir).map((m) => m.id);
|
|
20777
|
+
const multirepo = mappedModules.length > 0;
|
|
20778
|
+
const lines = [
|
|
20779
|
+
`Refine Work Item ${wi.id} \u2014 "${wi.title}" \u2014 in project "${projectName}" using Kaddo.`,
|
|
20780
|
+
"",
|
|
20781
|
+
`Use the canonical ${RECOMMENDED_AGENT} and the ${RECOMMENDED_SKILL} skill (via Kaddo MCP or skills),`,
|
|
20782
|
+
"with access to this repository.",
|
|
20783
|
+
"",
|
|
20784
|
+
"Inspect the actual implementation and the relevant mapped modules before defining the final scope \u2014",
|
|
20785
|
+
"do not guess affected modules from the Work Item title. Read the current behavior in the code first,",
|
|
20786
|
+
"then classify."
|
|
20787
|
+
];
|
|
20788
|
+
if (multirepo) {
|
|
20789
|
+
lines.push(
|
|
20790
|
+
"",
|
|
20791
|
+
`This is a multirepo project. Evaluate the scope across all relevant mapped modules (${mappedModules.join(", ")})`,
|
|
20792
|
+
"before finalizing affected_modules and module_coverage."
|
|
20793
|
+
);
|
|
20794
|
+
}
|
|
20795
|
+
const topology = getSystemMapProjection(dir).metadata.topologyStatus;
|
|
20796
|
+
if (topology !== "unavailable") {
|
|
20797
|
+
lines.push(
|
|
20798
|
+
"",
|
|
20799
|
+
`The semantic system Graph is ${topology}. When semantic system topology is available:`,
|
|
20800
|
+
"1. identify the relevant system entry points;",
|
|
20801
|
+
"2. query the Kaddo Graph (search / neighbors / paths) for connected entities;",
|
|
20802
|
+
"3. treat Graph results as IMPACT CANDIDATES, not confirmed scope;",
|
|
20803
|
+
"4. inspect the actual implementation in the repository for each relevant candidate;",
|
|
20804
|
+
"5. classify each candidate as affected, reviewed-not-affected or unknown;",
|
|
20805
|
+
"6. preserve the evidence and reasons behind each classification.",
|
|
20806
|
+
"",
|
|
20807
|
+
"A missing Graph relationship does not mean no impact, especially when Graph coverage is partial \u2014",
|
|
20808
|
+
"keep inspecting the repository beyond the Graph candidates when the task requires it."
|
|
20809
|
+
);
|
|
20810
|
+
} else {
|
|
20811
|
+
lines.push(
|
|
20812
|
+
"",
|
|
20813
|
+
"The semantic system Graph is unavailable. Continue repository-driven refinement normally, using the",
|
|
20814
|
+
"repository, Knowledge and mapped modules \u2014 the Graph is enrichment, not a prerequisite."
|
|
20815
|
+
);
|
|
20816
|
+
}
|
|
20817
|
+
lines.push(
|
|
20818
|
+
"",
|
|
20819
|
+
`Update the canonical Work Item ${wi.id} with:`,
|
|
20820
|
+
"- current and target behavior;",
|
|
20821
|
+
"- the end-to-end flow (journey);",
|
|
20822
|
+
"- affected modules;",
|
|
20823
|
+
"- affected system entities (affected_system_entities) and reviewed_system_entities;",
|
|
20824
|
+
"- module coverage;",
|
|
20825
|
+
"- impact analysis across the relevant surfaces;",
|
|
20826
|
+
"- scope confidence and open unknowns;",
|
|
20827
|
+
"- acceptance criteria;",
|
|
20828
|
+
"- relevant Knowledge / ADR relationships.",
|
|
20829
|
+
"",
|
|
20830
|
+
"Do not implement the Work Item. Do not run mutating Git operations."
|
|
20831
|
+
);
|
|
20832
|
+
return {
|
|
20833
|
+
workItemId: wi.id,
|
|
20834
|
+
title: wi.title,
|
|
20835
|
+
projectName,
|
|
20836
|
+
refinement: wi.refinement,
|
|
20837
|
+
recommendedAgent: RECOMMENDED_AGENT,
|
|
20838
|
+
recommendedSkill: RECOMMENDED_SKILL,
|
|
20839
|
+
text: lines.join("\n")
|
|
20840
|
+
};
|
|
20841
|
+
}
|
|
20842
|
+
|
|
20843
|
+
// src/core/work-item-import.ts
|
|
20844
|
+
var MAX_INPUT_BYTES = 102400;
|
|
20845
|
+
var LIFECYCLE_FIELDS = /* @__PURE__ */ new Set([
|
|
20846
|
+
"id",
|
|
20847
|
+
"status",
|
|
20848
|
+
"phase",
|
|
20849
|
+
"knowledge_level",
|
|
20850
|
+
"refined_by",
|
|
20851
|
+
"implemented_by",
|
|
20852
|
+
"closed_by",
|
|
20853
|
+
"ready_at",
|
|
20854
|
+
"generated_by",
|
|
20855
|
+
"template_version",
|
|
20856
|
+
"implementation_status",
|
|
20857
|
+
"validation_status",
|
|
20858
|
+
"release_status"
|
|
20859
|
+
]);
|
|
20860
|
+
function detectFormat(raw) {
|
|
20861
|
+
const trimmed = raw.trim();
|
|
20862
|
+
if (!trimmed) throw new ImportError("EMPTY_INPUT", "Import content is empty.");
|
|
20863
|
+
if (trimmed.startsWith("---")) {
|
|
20864
|
+
try {
|
|
20865
|
+
const { data } = matter15(trimmed);
|
|
20866
|
+
if (data && typeof data === "object" && Object.keys(data).length > 0) {
|
|
20867
|
+
const d = data;
|
|
20868
|
+
if (d.type === "work-item" || d.id && typeof d.id === "string" && /^WI-\d+/.test(d.id)) {
|
|
20869
|
+
return "kaddo-frontmatter";
|
|
20870
|
+
}
|
|
20871
|
+
return "markdown-frontmatter";
|
|
20872
|
+
}
|
|
20873
|
+
} catch {
|
|
20874
|
+
}
|
|
20875
|
+
}
|
|
20876
|
+
if (/^#{1,2}\s+/m.test(trimmed)) return "markdown";
|
|
20877
|
+
return "plain-text";
|
|
20878
|
+
}
|
|
20879
|
+
function parseContent(raw) {
|
|
20880
|
+
const trimmed = raw.trim();
|
|
20881
|
+
if (!trimmed) throw new ImportError("EMPTY_INPUT", "Import content is empty.");
|
|
20882
|
+
const format = detectFormat(trimmed);
|
|
20883
|
+
let frontmatterFields = {};
|
|
20884
|
+
let bodyText = trimmed;
|
|
20885
|
+
if (format === "kaddo-frontmatter" || format === "markdown-frontmatter") {
|
|
20886
|
+
try {
|
|
20887
|
+
const parsed = matter15(trimmed);
|
|
20888
|
+
frontmatterFields = parsed.data ?? {};
|
|
20889
|
+
bodyText = parsed.content.trim();
|
|
20890
|
+
} catch {
|
|
20891
|
+
}
|
|
20892
|
+
}
|
|
20893
|
+
const title = extractTitle(frontmatterFields, bodyText);
|
|
20894
|
+
const candidateType = extractType(frontmatterFields);
|
|
20895
|
+
const sections = extractSections(bodyText);
|
|
20896
|
+
const summary = bodyText || title;
|
|
20897
|
+
return {
|
|
20898
|
+
format,
|
|
20899
|
+
title,
|
|
20900
|
+
type: candidateType,
|
|
20901
|
+
summary,
|
|
20902
|
+
body: bodyText,
|
|
20903
|
+
candidateFields: frontmatterFields,
|
|
20904
|
+
sections
|
|
20905
|
+
};
|
|
20906
|
+
}
|
|
20907
|
+
function extractTitle(fields, body) {
|
|
20908
|
+
if (typeof fields.title === "string" && fields.title.trim()) {
|
|
20909
|
+
return fields.title.trim().slice(0, 120);
|
|
20910
|
+
}
|
|
20911
|
+
const h1Match = body.match(/^#\s+(.+)$/m);
|
|
20912
|
+
if (h1Match) return h1Match[1].trim().slice(0, 120);
|
|
20913
|
+
const firstLine = body.split(/\r?\n/).find((l) => l.trim());
|
|
20914
|
+
return (firstLine?.trim() ?? "Untitled Work Item").slice(0, 120);
|
|
20915
|
+
}
|
|
20916
|
+
function extractType(fields) {
|
|
20917
|
+
const raw = typeof fields.work_type === "string" && fields.work_type.trim() ? fields.work_type.trim() : typeof fields.type === "string" && fields.type.trim() && fields.type !== "work-item" ? fields.type.trim() : void 0;
|
|
20918
|
+
if (!raw) return void 0;
|
|
20919
|
+
return normalizeType(raw) ?? void 0;
|
|
20920
|
+
}
|
|
20921
|
+
function extractSections(body) {
|
|
20922
|
+
const sections = /* @__PURE__ */ new Map();
|
|
20923
|
+
const lines = body.split(/\r?\n/);
|
|
20924
|
+
let currentHeading = null;
|
|
20925
|
+
let buffer = [];
|
|
20926
|
+
const flush = () => {
|
|
20927
|
+
if (currentHeading) {
|
|
20928
|
+
sections.set(currentHeading.toLowerCase(), buffer.join("\n").trim());
|
|
20929
|
+
}
|
|
20930
|
+
buffer = [];
|
|
20931
|
+
};
|
|
20932
|
+
for (const line of lines) {
|
|
20933
|
+
const match = line.match(/^##\s+(.+)$/);
|
|
20934
|
+
if (match) {
|
|
20935
|
+
flush();
|
|
20936
|
+
currentHeading = match[1].trim();
|
|
20937
|
+
} else if (currentHeading) {
|
|
20938
|
+
buffer.push(line);
|
|
20939
|
+
}
|
|
20940
|
+
}
|
|
20941
|
+
flush();
|
|
20942
|
+
return sections;
|
|
20943
|
+
}
|
|
20944
|
+
function normalizeImportFields(parsed, opts) {
|
|
20945
|
+
const discardedFields = [];
|
|
20946
|
+
for (const key of Object.keys(parsed.candidateFields)) {
|
|
20947
|
+
if (LIFECYCLE_FIELDS.has(key)) discardedFields.push(key);
|
|
20948
|
+
}
|
|
20949
|
+
const type = opts.userType ? normalizeType(opts.userType) ?? "feature" : parsed.type ?? "feature";
|
|
20950
|
+
const intent = parsed.body && parsed.body !== parsed.title ? `${parsed.title}
|
|
20951
|
+
|
|
20952
|
+
${parsed.body}` : parsed.title;
|
|
20953
|
+
const source = {
|
|
20954
|
+
type: opts.importSource === "chat" ? "chat" : "external",
|
|
20955
|
+
imported_at: (/* @__PURE__ */ new Date()).toISOString().split("T")[0]
|
|
20956
|
+
};
|
|
20957
|
+
source.source_format = opts.sourceFormat;
|
|
20958
|
+
source.source_hash = opts.sourceHash;
|
|
20959
|
+
const snapshot = { title: parsed.title };
|
|
20960
|
+
if (parsed.summary !== parsed.title) snapshot.description = parsed.summary;
|
|
20961
|
+
if (typeof parsed.candidateFields.type === "string") snapshot.type = parsed.candidateFields.type;
|
|
20962
|
+
if (typeof parsed.candidateFields.status === "string") snapshot.status = parsed.candidateFields.status;
|
|
20963
|
+
if (Array.isArray(parsed.candidateFields.labels)) {
|
|
20964
|
+
const labels = parsed.candidateFields.labels.filter((l) => typeof l === "string");
|
|
20965
|
+
if (labels.length > 0) snapshot.labels = labels;
|
|
20966
|
+
}
|
|
20967
|
+
return { type, intent, source, snapshot, discardedFields };
|
|
20968
|
+
}
|
|
20969
|
+
function computeContentHash(raw) {
|
|
20970
|
+
return crypto3.createHash("sha256").update(raw.trim(), "utf-8").digest("hex");
|
|
20971
|
+
}
|
|
20972
|
+
function findDuplicateByHash(dir, hash) {
|
|
20973
|
+
const items = discoverWorkItems(dir);
|
|
20974
|
+
for (const item of items) {
|
|
20975
|
+
const raw = readFile(item.filePath);
|
|
20976
|
+
if (!raw) continue;
|
|
20977
|
+
try {
|
|
20978
|
+
const { data } = matter15(raw);
|
|
20979
|
+
const source = data?.source;
|
|
20980
|
+
if (source && typeof source === "object" && !Array.isArray(source)) {
|
|
20981
|
+
const s = source;
|
|
20982
|
+
if (s.source_hash === hash) {
|
|
20983
|
+
return { workItemId: data.id ?? item.id ?? item.title, path: item.relPath };
|
|
20984
|
+
}
|
|
20985
|
+
}
|
|
20986
|
+
} catch {
|
|
20987
|
+
}
|
|
20988
|
+
}
|
|
20989
|
+
return void 0;
|
|
20990
|
+
}
|
|
20991
|
+
function importWorkItem(dir, opts) {
|
|
20992
|
+
const content = opts.content;
|
|
20993
|
+
if (!content?.trim()) throw new ImportError("EMPTY_INPUT", "Import content is empty.");
|
|
20994
|
+
if (Buffer.byteLength(content, "utf-8") > MAX_INPUT_BYTES) {
|
|
20995
|
+
throw new ImportError("OVERSIZED_INPUT", `Import content exceeds the ${MAX_INPUT_BYTES / 1024}KB limit.`);
|
|
20996
|
+
}
|
|
20997
|
+
const parsed = parseContent(content);
|
|
20998
|
+
const sourceHash = computeContentHash(content);
|
|
20999
|
+
const duplicate = findDuplicateByHash(dir, sourceHash);
|
|
21000
|
+
if (duplicate) {
|
|
21001
|
+
return {
|
|
21002
|
+
created: false,
|
|
21003
|
+
workItemId: duplicate.workItemId,
|
|
21004
|
+
path: duplicate.path,
|
|
21005
|
+
status: "draft",
|
|
21006
|
+
source: opts.source,
|
|
21007
|
+
sourceFormat: parsed.format,
|
|
21008
|
+
sourceHash,
|
|
21009
|
+
duplicateOf: duplicate.workItemId,
|
|
21010
|
+
executed: false
|
|
21011
|
+
};
|
|
21012
|
+
}
|
|
21013
|
+
const normalized = normalizeImportFields(parsed, {
|
|
21014
|
+
userType: opts.type,
|
|
21015
|
+
importSource: opts.source,
|
|
21016
|
+
sourceHash,
|
|
21017
|
+
sourceFormat: parsed.format
|
|
21018
|
+
});
|
|
21019
|
+
const result = createWorkItem(dir, {
|
|
21020
|
+
intent: normalized.intent,
|
|
21021
|
+
type: normalized.type,
|
|
21022
|
+
source: normalized.source,
|
|
21023
|
+
originalSnapshot: normalized.snapshot
|
|
21024
|
+
});
|
|
21025
|
+
let refinementHandoff;
|
|
21026
|
+
try {
|
|
21027
|
+
refinementHandoff = buildRefinementHandoff(dir, result.id);
|
|
21028
|
+
} catch {
|
|
21029
|
+
}
|
|
21030
|
+
return {
|
|
21031
|
+
created: true,
|
|
21032
|
+
workItemId: result.id,
|
|
21033
|
+
path: result.path,
|
|
21034
|
+
status: "draft",
|
|
21035
|
+
source: opts.source,
|
|
21036
|
+
sourceFormat: parsed.format,
|
|
21037
|
+
sourceHash,
|
|
21038
|
+
executed: false,
|
|
21039
|
+
refinementHandoff,
|
|
21040
|
+
...normalized.discardedFields.length > 0 ? { discardedFields: normalized.discardedFields } : {}
|
|
21041
|
+
};
|
|
21042
|
+
}
|
|
21043
|
+
var ImportError = class extends Error {
|
|
21044
|
+
constructor(code, message) {
|
|
21045
|
+
super(message);
|
|
21046
|
+
this.code = code;
|
|
21047
|
+
this.name = "ImportError";
|
|
21048
|
+
}
|
|
21049
|
+
code;
|
|
21050
|
+
};
|
|
21051
|
+
|
|
21052
|
+
// src/commands/work-item.ts
|
|
21053
|
+
function requireProject3(dir) {
|
|
21054
|
+
if (!loadConfig(dir)) {
|
|
21055
|
+
log2.error("No Kaddo project was found in the current directory.");
|
|
21056
|
+
process.exit(1);
|
|
21057
|
+
}
|
|
21058
|
+
}
|
|
21059
|
+
async function runWorkItemImport(dir, fileOrText, opts) {
|
|
21060
|
+
requireProject3(dir);
|
|
21061
|
+
let content;
|
|
21062
|
+
if (opts.text) {
|
|
21063
|
+
content = opts.text;
|
|
21064
|
+
} else if (fileOrText) {
|
|
21065
|
+
if (!exists(fileOrText)) {
|
|
21066
|
+
log2.error(`File not found: ${fileOrText}`);
|
|
21067
|
+
process.exit(1);
|
|
21068
|
+
}
|
|
21069
|
+
content = readFile(fileOrText) ?? void 0;
|
|
21070
|
+
if (!content?.trim()) {
|
|
21071
|
+
log2.error(`File is empty: ${fileOrText}`);
|
|
21072
|
+
process.exit(1);
|
|
21073
|
+
}
|
|
21074
|
+
} else if (!process.stdin.isTTY) {
|
|
21075
|
+
const chunks = [];
|
|
21076
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
21077
|
+
content = Buffer.concat(chunks).toString("utf-8");
|
|
21078
|
+
}
|
|
21079
|
+
if (!content?.trim()) {
|
|
21080
|
+
log2.error("No content provided. Use a file path, --text, or pipe content via stdin.");
|
|
21081
|
+
process.exit(1);
|
|
21082
|
+
}
|
|
21083
|
+
try {
|
|
21084
|
+
intro2("Import external Work Item");
|
|
21085
|
+
const parsed = parseContent(content);
|
|
21086
|
+
const hash = computeContentHash(content);
|
|
21087
|
+
const duplicate = findDuplicateByHash(dir, hash);
|
|
21088
|
+
if (duplicate) {
|
|
21089
|
+
log2.warn(`Already imported as ${duplicate.workItemId}.`);
|
|
21090
|
+
outro2("No duplicate was created.");
|
|
21091
|
+
return;
|
|
21092
|
+
}
|
|
21093
|
+
log2.info(`Format: ${parsed.format}`);
|
|
21094
|
+
log2.info(`Title: ${parsed.title}`);
|
|
21095
|
+
log2.message(`Type: ${opts.type ?? parsed.type ?? "feature"}`);
|
|
21096
|
+
log2.message("Will create: a Draft Work Item (needs refinement).");
|
|
21097
|
+
log2.message("No project files have been modified yet.");
|
|
21098
|
+
if (!opts.yes) {
|
|
21099
|
+
const ok = await confirm2({ message: "Import this content as a Draft Work Item?" });
|
|
21100
|
+
if (ok !== true) {
|
|
21101
|
+
cancel2("Import cancelled. No files were changed.");
|
|
21102
|
+
process.exit(0);
|
|
21103
|
+
}
|
|
21104
|
+
}
|
|
21105
|
+
const result = importWorkItem(dir, {
|
|
21106
|
+
content,
|
|
21107
|
+
source: "cli",
|
|
21108
|
+
type: opts.type,
|
|
21109
|
+
filePath: fileOrText
|
|
21110
|
+
});
|
|
21111
|
+
if (!result.created) {
|
|
21112
|
+
log2.warn(`Already imported as ${result.duplicateOf}.`);
|
|
21113
|
+
outro2("No duplicate was created.");
|
|
21114
|
+
return;
|
|
21115
|
+
}
|
|
21116
|
+
log2.info(`Created ${result.workItemId} (Draft, needs refinement).`);
|
|
21117
|
+
log2.info(`Path: ${result.path}`);
|
|
21118
|
+
if (result.discardedFields?.length) {
|
|
21119
|
+
log2.warn(`Lifecycle fields discarded from import: ${result.discardedFields.join(", ")}`);
|
|
21120
|
+
log2.message("Kaddo always generates its own id and status \u2014 external values are ignored.");
|
|
21121
|
+
}
|
|
21122
|
+
log2.message("executed = false \u2014 the Work Item has NOT been implemented.");
|
|
21123
|
+
if (result.refinementHandoff) {
|
|
21124
|
+
log2.step("Refinement handoff");
|
|
21125
|
+
log2.message(`Agent: ${result.refinementHandoff.recommendedAgent}`);
|
|
21126
|
+
log2.message(`Skill: ${result.refinementHandoff.recommendedSkill}`);
|
|
21127
|
+
}
|
|
21128
|
+
outro2("Done. Refine it next with the Work Item refinement handoff.");
|
|
21129
|
+
} catch (err) {
|
|
21130
|
+
if (err instanceof ImportError) log2.error(`[${err.code}] ${err.message}`);
|
|
21131
|
+
else log2.error("The import operation failed.");
|
|
21132
|
+
process.exit(1);
|
|
21133
|
+
}
|
|
21134
|
+
}
|
|
21135
|
+
|
|
20291
21136
|
// src/index.ts
|
|
20292
21137
|
var require2 = createRequire(import.meta.url);
|
|
20293
21138
|
var { version } = require2("../package.json");
|
|
@@ -20343,6 +21188,10 @@ integrationsCmd.command("work-item <id> <external-id>").description("Read a sing
|
|
|
20343
21188
|
integrationsCmd.command("import <id> <external-id>").description("Preview and, after confirmation, import an external work item as a Draft Work Item").option("--type <type>", "Kaddo Work Item type (required to create; never inferred from the external type)").option("-y, --yes", "Skip the confirmation prompt (for already-approved automation)").action(async (id, externalId, opts) => {
|
|
20344
21189
|
await runIntegrationsImport(cwd(), id, externalId, opts);
|
|
20345
21190
|
});
|
|
21191
|
+
var workItemCmd = program.command("work-item").description("Work Item operations");
|
|
21192
|
+
workItemCmd.command("import [file]").description("Import a Work Item from text or file into Kaddo as a Draft (import \u2260 execute)").option("--text <content>", "Import from inline text instead of a file").option("--type <type>", "Kaddo Work Item type (feature/bugfix/hotfix/spike/chore)").option("-y, --yes", "Skip the confirmation prompt").action(async (file, opts) => {
|
|
21193
|
+
await runWorkItemImport(cwd(), file, opts);
|
|
21194
|
+
});
|
|
20346
21195
|
var reportCmd = program.command("report").description("Generate Kaddo reports");
|
|
20347
21196
|
reportCmd.command("impact").description("Knowledge Impact Report: knowledge health, coverage, traceability, readiness (deterministic, no LLM)").option("--json", "Output JSON instead of Markdown").option("--scope <scope>", "Scope: all (default \u2014 accumulated impact) or active").option("--output <path>", "Write the report to a file (e.g. .kaddo/reports/impact-report.md)").action((opts) => {
|
|
20348
21197
|
runReportImpact(opts);
|