@kaddo/cli 3.112.1 → 3.112.2
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 +38 -5
- package/dist/index.js +114 -99
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -9253,6 +9253,25 @@ ${body}`);
|
|
|
9253
9253
|
${out.join("\n\n")}
|
|
9254
9254
|
`.replace(/\n{3,}/g, "\n\n");
|
|
9255
9255
|
}
|
|
9256
|
+
function importedBody(title, type, sourceBody) {
|
|
9257
|
+
const lines = sourceBody.split(/\r?\n/);
|
|
9258
|
+
let i = 0;
|
|
9259
|
+
while (i < lines.length && !lines[i].trim()) i++;
|
|
9260
|
+
if (i < lines.length && /^#\s+/.test(lines[i])) {
|
|
9261
|
+
i++;
|
|
9262
|
+
while (i < lines.length && !lines[i].trim()) i++;
|
|
9263
|
+
if (i < lines.length && /^>\s*Type:/i.test(lines[i])) i++;
|
|
9264
|
+
}
|
|
9265
|
+
const rest = lines.slice(i).join("\n").trim();
|
|
9266
|
+
const preamble = `# ${title}
|
|
9267
|
+
|
|
9268
|
+
> Type: ${type}`;
|
|
9269
|
+
return rest ? `${preamble}
|
|
9270
|
+
|
|
9271
|
+
${rest}
|
|
9272
|
+
` : `${preamble}
|
|
9273
|
+
`;
|
|
9274
|
+
}
|
|
9256
9275
|
function applyFrontmatter(data, input) {
|
|
9257
9276
|
const next = { ...data };
|
|
9258
9277
|
next.title = input.title;
|
|
@@ -9391,6 +9410,7 @@ function createWorkItem(dir, opts) {
|
|
|
9391
9410
|
if (!type) throw new WorkItemWriteError("INVALID_INPUT", `Unknown Work Item type "${opts.type}".`);
|
|
9392
9411
|
const id = nextWorkItemId(dir);
|
|
9393
9412
|
const title = intent.split(/\r?\n/)[0].trim().slice(0, 120);
|
|
9413
|
+
const summary = opts.summary?.trim() ? opts.summary.trim() : intent;
|
|
9394
9414
|
const today2 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
9395
9415
|
const source = opts.source ? { ...opts.source, inferred: false } : { type: "manual", inferred: false };
|
|
9396
9416
|
const data = {
|
|
@@ -9403,12 +9423,12 @@ function createWorkItem(dir, opts) {
|
|
|
9403
9423
|
source,
|
|
9404
9424
|
generated_by: "kaddo-admin",
|
|
9405
9425
|
affected_modules: [],
|
|
9406
|
-
summary
|
|
9426
|
+
summary
|
|
9407
9427
|
};
|
|
9408
9428
|
if (opts.originalSnapshot) data.original_snapshot = opts.originalSnapshot;
|
|
9409
9429
|
const answers = opts.answers ?? {};
|
|
9410
9430
|
const hasAnswers = Object.values(answers).some((v) => v?.trim());
|
|
9411
|
-
const body = hasAnswers ? captureBody(title, type, answers) : freshBody({
|
|
9431
|
+
const body = opts.body?.trim() ? importedBody(title, type, opts.body) : hasAnswers ? captureBody(title, type, answers) : freshBody({
|
|
9412
9432
|
title,
|
|
9413
9433
|
type,
|
|
9414
9434
|
summary: intent,
|
|
@@ -10401,7 +10421,7 @@ function parseContent(raw) {
|
|
|
10401
10421
|
const title = extractTitle(frontmatterFields, bodyText);
|
|
10402
10422
|
const candidateType = extractType(frontmatterFields);
|
|
10403
10423
|
const sections = extractSections(bodyText);
|
|
10404
|
-
const summary = bodyText
|
|
10424
|
+
const summary = deriveSummary(bodyText, title);
|
|
10405
10425
|
return {
|
|
10406
10426
|
format,
|
|
10407
10427
|
title,
|
|
@@ -10421,6 +10441,16 @@ function extractTitle(fields, body) {
|
|
|
10421
10441
|
const firstLine = body.split(/\r?\n/).find((l) => l.trim());
|
|
10422
10442
|
return (firstLine?.trim() ?? "Untitled Work Item").slice(0, 120);
|
|
10423
10443
|
}
|
|
10444
|
+
function deriveSummary(body, title) {
|
|
10445
|
+
for (const line of body.split(/\r?\n/)) {
|
|
10446
|
+
const t = line.trim();
|
|
10447
|
+
if (!t) continue;
|
|
10448
|
+
if (/^#{1,6}\s/.test(t)) continue;
|
|
10449
|
+
if (/^>/.test(t)) continue;
|
|
10450
|
+
return t.slice(0, 280);
|
|
10451
|
+
}
|
|
10452
|
+
return title;
|
|
10453
|
+
}
|
|
10424
10454
|
function extractType(fields) {
|
|
10425
10455
|
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;
|
|
10426
10456
|
if (!raw) return void 0;
|
|
@@ -10458,6 +10488,7 @@ function normalizeImportFields(parsed, opts) {
|
|
|
10458
10488
|
const intent = parsed.body && parsed.body !== parsed.title ? `${parsed.title}
|
|
10459
10489
|
|
|
10460
10490
|
${parsed.body}` : parsed.title;
|
|
10491
|
+
const body = parsed.body && parsed.body.trim() !== parsed.title.trim() ? parsed.body : void 0;
|
|
10461
10492
|
const source = {
|
|
10462
10493
|
type: opts.importSource === "chat" ? "chat" : "external",
|
|
10463
10494
|
imported_at: (/* @__PURE__ */ new Date()).toISOString().split("T")[0]
|
|
@@ -10472,7 +10503,7 @@ ${parsed.body}` : parsed.title;
|
|
|
10472
10503
|
const labels = parsed.candidateFields.labels.filter((l) => typeof l === "string");
|
|
10473
10504
|
if (labels.length > 0) snapshot.labels = labels;
|
|
10474
10505
|
}
|
|
10475
|
-
return { type, intent, source, snapshot, discardedFields };
|
|
10506
|
+
return { type, intent, summary: parsed.summary, body, source, snapshot, discardedFields };
|
|
10476
10507
|
}
|
|
10477
10508
|
function computeContentHash(raw) {
|
|
10478
10509
|
return crypto3.createHash("sha256").update(raw.trim(), "utf-8").digest("hex");
|
|
@@ -10559,7 +10590,9 @@ function importWorkItem(dir, opts) {
|
|
|
10559
10590
|
intent: normalized.intent,
|
|
10560
10591
|
type: normalized.type,
|
|
10561
10592
|
source: normalized.source,
|
|
10562
|
-
originalSnapshot: normalized.snapshot
|
|
10593
|
+
originalSnapshot: normalized.snapshot,
|
|
10594
|
+
summary: normalized.summary,
|
|
10595
|
+
body: normalized.body
|
|
10563
10596
|
});
|
|
10564
10597
|
let refinementHandoff;
|
|
10565
10598
|
try {
|
package/dist/index.js
CHANGED
|
@@ -1390,8 +1390,8 @@ function loadConfig(dir) {
|
|
|
1390
1390
|
const parsed = configSchema.safeParse(raw ?? {});
|
|
1391
1391
|
if (!parsed.success) {
|
|
1392
1392
|
const issues = parsed.error.issues.map((i) => {
|
|
1393
|
-
const
|
|
1394
|
-
return
|
|
1393
|
+
const path11 = i.path.join(".");
|
|
1394
|
+
return path11 ? ` - ${path11}: ${i.message}` : ` - ${i.message}`;
|
|
1395
1395
|
}).join("\n");
|
|
1396
1396
|
throw new ConfigError(`Invalid .kaddo/config.yml:
|
|
1397
1397
|
${issues}`);
|
|
@@ -7044,10 +7044,10 @@ function analyzeGuard(touchedFiles, artifacts, silentWithoutOwnership) {
|
|
|
7044
7044
|
import { parse as parseYaml5, stringify as stringifyYaml3 } from "yaml";
|
|
7045
7045
|
var IGNORE_FILE = ".kaddo/ignores.yml";
|
|
7046
7046
|
function loadIgnores(dir) {
|
|
7047
|
-
const
|
|
7048
|
-
if (!exists(
|
|
7047
|
+
const path11 = join(dir, IGNORE_FILE);
|
|
7048
|
+
if (!exists(path11)) return [];
|
|
7049
7049
|
try {
|
|
7050
|
-
const raw = readFile(
|
|
7050
|
+
const raw = readFile(path11);
|
|
7051
7051
|
const parsed = parseYaml5(raw);
|
|
7052
7052
|
return Array.isArray(parsed) ? parsed : [];
|
|
7053
7053
|
} catch {
|
|
@@ -7055,7 +7055,7 @@ function loadIgnores(dir) {
|
|
|
7055
7055
|
}
|
|
7056
7056
|
}
|
|
7057
7057
|
function saveIgnore(dir, entry) {
|
|
7058
|
-
const
|
|
7058
|
+
const path11 = join(dir, IGNORE_FILE);
|
|
7059
7059
|
const existing = loadIgnores(dir);
|
|
7060
7060
|
const idx = existing.findIndex((e) => e.artifact_id === entry.artifact_id);
|
|
7061
7061
|
if (idx >= 0) {
|
|
@@ -7063,17 +7063,17 @@ function saveIgnore(dir, entry) {
|
|
|
7063
7063
|
} else {
|
|
7064
7064
|
existing.push(entry);
|
|
7065
7065
|
}
|
|
7066
|
-
writeFile(
|
|
7066
|
+
writeFile(path11, stringifyYaml3(existing));
|
|
7067
7067
|
}
|
|
7068
7068
|
function isIgnored(ignores, artifactId) {
|
|
7069
7069
|
return ignores.find((e) => e.artifact_id === artifactId);
|
|
7070
7070
|
}
|
|
7071
7071
|
function removeIgnore(dir, artifactId) {
|
|
7072
|
-
const
|
|
7072
|
+
const path11 = join(dir, IGNORE_FILE);
|
|
7073
7073
|
const existing = loadIgnores(dir);
|
|
7074
7074
|
const filtered = existing.filter((e) => e.artifact_id !== artifactId);
|
|
7075
7075
|
if (filtered.length === existing.length) return false;
|
|
7076
|
-
writeFile(
|
|
7076
|
+
writeFile(path11, stringifyYaml3(filtered));
|
|
7077
7077
|
return true;
|
|
7078
7078
|
}
|
|
7079
7079
|
|
|
@@ -7095,11 +7095,11 @@ function moduleArtifactCoverage(dir, id) {
|
|
|
7095
7095
|
};
|
|
7096
7096
|
}
|
|
7097
7097
|
function loadMappedModules(dir) {
|
|
7098
|
-
const
|
|
7099
|
-
if (!exists(
|
|
7098
|
+
const path11 = join(dir, DESCRIPTOR_PATH);
|
|
7099
|
+
if (!exists(path11)) return [];
|
|
7100
7100
|
let parsed;
|
|
7101
7101
|
try {
|
|
7102
|
-
parsed = parseYaml6(readFile(
|
|
7102
|
+
parsed = parseYaml6(readFile(path11));
|
|
7103
7103
|
} catch {
|
|
7104
7104
|
return [];
|
|
7105
7105
|
}
|
|
@@ -7843,7 +7843,7 @@ function buildGuardHistory(dir) {
|
|
|
7843
7843
|
const d = hotspotDir(t.code_path);
|
|
7844
7844
|
hotspotMap.set(d, (hotspotMap.get(d) ?? 0) + 1);
|
|
7845
7845
|
}
|
|
7846
|
-
const hotspots = [...hotspotMap.entries()].map(([
|
|
7846
|
+
const hotspots = [...hotspotMap.entries()].map(([path11, warnings]) => ({ path: path11, warnings })).sort((a, b) => b.warnings - a.warnings);
|
|
7847
7847
|
return {
|
|
7848
7848
|
available: true,
|
|
7849
7849
|
total_runs: sorted.length,
|
|
@@ -10481,10 +10481,10 @@ function slugify2(name) {
|
|
|
10481
10481
|
return name.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
10482
10482
|
}
|
|
10483
10483
|
function readModulesDescriptor(dir) {
|
|
10484
|
-
const
|
|
10485
|
-
if (!exists(
|
|
10484
|
+
const path11 = join(dir, DESCRIPTOR_PATH2);
|
|
10485
|
+
if (!exists(path11)) return { version: 1, modules: [] };
|
|
10486
10486
|
try {
|
|
10487
|
-
const parsed = parseYaml10(readFile(
|
|
10487
|
+
const parsed = parseYaml10(readFile(path11));
|
|
10488
10488
|
return { version: parsed.version ?? 1, modules: parsed.modules ?? [] };
|
|
10489
10489
|
} catch {
|
|
10490
10490
|
return { version: 1, modules: [] };
|
|
@@ -10864,7 +10864,7 @@ function sectionParagraph(md, title) {
|
|
|
10864
10864
|
}
|
|
10865
10865
|
return "";
|
|
10866
10866
|
}
|
|
10867
|
-
function parseCapsule(id,
|
|
10867
|
+
function parseCapsule(id, path11, md) {
|
|
10868
10868
|
const { data } = matter3(md);
|
|
10869
10869
|
const updatedAt = data.updated_at ? String(data.updated_at) : void 0;
|
|
10870
10870
|
let ageDays = null;
|
|
@@ -10874,7 +10874,7 @@ function parseCapsule(id, path12, md) {
|
|
|
10874
10874
|
}
|
|
10875
10875
|
return {
|
|
10876
10876
|
id,
|
|
10877
|
-
path:
|
|
10877
|
+
path: path11,
|
|
10878
10878
|
system: data.system ? String(data.system) : id,
|
|
10879
10879
|
owner: data.owner ? String(data.owner) : void 0,
|
|
10880
10880
|
updatedAt,
|
|
@@ -11135,9 +11135,9 @@ function buildGraph(dir, config, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
11135
11135
|
];
|
|
11136
11136
|
const presentLayers = [];
|
|
11137
11137
|
for (const layer2 of layerDocs) {
|
|
11138
|
-
const
|
|
11139
|
-
if (
|
|
11140
|
-
addNode({ id: layer2.id, type: layer2.type, label: layer2.label, path:
|
|
11138
|
+
const path11 = layer2.files.map((f) => `${KNOWLEDGE3}/${f}`).find((rel) => exists(join(dir, rel)));
|
|
11139
|
+
if (path11) {
|
|
11140
|
+
addNode({ id: layer2.id, type: layer2.type, label: layer2.label, path: path11 });
|
|
11141
11141
|
presentLayers.push(layer2.id);
|
|
11142
11142
|
}
|
|
11143
11143
|
}
|
|
@@ -12700,10 +12700,10 @@ function resolveNextStep(dir, now = /* @__PURE__ */ new Date()) {
|
|
|
12700
12700
|
const q = (rel) => analyzeKnowledgeArtifact(dir, rel);
|
|
12701
12701
|
const resolveAgent = (agent) => {
|
|
12702
12702
|
const file = agent.endsWith(".md") ? agent : `${agent}.md`;
|
|
12703
|
-
const
|
|
12704
|
-
const installed = isFile(join(dir,
|
|
12703
|
+
const path11 = agentInstallPath(file);
|
|
12704
|
+
const installed = isFile(join(dir, path11));
|
|
12705
12705
|
const group = agentGroupOf(file);
|
|
12706
|
-
return { agentPath:
|
|
12706
|
+
return { agentPath: path11, agentInstalled: installed, installCommand: installed ? void 0 : `kaddo add agents --group ${group}` };
|
|
12707
12707
|
};
|
|
12708
12708
|
const moduleRepo = isModule(config);
|
|
12709
12709
|
const coreRepo = isCore(config);
|
|
@@ -16442,21 +16442,15 @@ function runStatus() {
|
|
|
16442
16442
|
}
|
|
16443
16443
|
|
|
16444
16444
|
// src/commands/learn.ts
|
|
16445
|
-
import fs3 from "fs";
|
|
16446
|
-
import path7 from "path";
|
|
16447
16445
|
import matter9 from "gray-matter";
|
|
16448
16446
|
var ARCH_DIR9 = "knowledge";
|
|
16449
16447
|
var WORK_ITEMS_DIR2 = "knowledge/delivery/work-items";
|
|
16450
16448
|
function findWorkItemFile(dir, id) {
|
|
16451
|
-
const
|
|
16452
|
-
|
|
16453
|
-
|
|
16454
|
-
|
|
16455
|
-
|
|
16456
|
-
const folder = lifecycleFolderOf(filePath);
|
|
16457
|
-
if (!folder || folder === "completed") return filePath;
|
|
16458
|
-
const completedDir = path7.dirname(filePath).replace(new RegExp(`[/\\\\]${folder}$`), path7.sep + "completed");
|
|
16459
|
-
return path7.join(completedDir, path7.basename(filePath));
|
|
16449
|
+
const wiDir = join(dir, WORK_ITEMS_DIR2);
|
|
16450
|
+
if (!exists(wiDir)) return null;
|
|
16451
|
+
const files = readDir(wiDir).filter((f) => f.endsWith(".md"));
|
|
16452
|
+
const match = files.find((f) => f.includes(id.toUpperCase()) || f.includes(id.toLowerCase()));
|
|
16453
|
+
return match ? join(wiDir, match) : null;
|
|
16460
16454
|
}
|
|
16461
16455
|
function updateWorkItemFile(filePath, learning) {
|
|
16462
16456
|
const raw = readFile(filePath);
|
|
@@ -16486,15 +16480,7 @@ ${learning.trim()}
|
|
|
16486
16480
|
`;
|
|
16487
16481
|
}
|
|
16488
16482
|
const newRaw = matter9.stringify(updatedContent, data);
|
|
16489
|
-
const targetPath = completedPathFor(filePath);
|
|
16490
|
-
if (targetPath !== filePath) {
|
|
16491
|
-
ensureDir(path7.dirname(targetPath));
|
|
16492
|
-
writeFile(targetPath, newRaw);
|
|
16493
|
-
fs3.unlinkSync(filePath);
|
|
16494
|
-
return targetPath;
|
|
16495
|
-
}
|
|
16496
16483
|
writeFile(filePath, newRaw);
|
|
16497
|
-
return filePath;
|
|
16498
16484
|
}
|
|
16499
16485
|
async function runLearn(artifactId, opts = {}) {
|
|
16500
16486
|
const dir = cwd();
|
|
@@ -16503,8 +16489,9 @@ async function runLearn(artifactId, opts = {}) {
|
|
|
16503
16489
|
process.exit(1);
|
|
16504
16490
|
}
|
|
16505
16491
|
intro("kaddo learn");
|
|
16506
|
-
const
|
|
16507
|
-
|
|
16492
|
+
const artifacts = readArtifacts(join(dir, ARCH_DIR9));
|
|
16493
|
+
const closable = artifacts.filter(
|
|
16494
|
+
(a) => (a.status === "in-progress" || a.status === "completed" || a.status === "done") && a.type !== "current-state" && a.type !== "roadmap"
|
|
16508
16495
|
);
|
|
16509
16496
|
if (closable.length === 0) {
|
|
16510
16497
|
log.warn("No in-progress or completed work items found.");
|
|
@@ -16576,14 +16563,9 @@ async function runLearn(artifactId, opts = {}) {
|
|
|
16576
16563
|
}
|
|
16577
16564
|
enrichedLearning += "\n\n> " + notes.join(" ");
|
|
16578
16565
|
}
|
|
16579
|
-
|
|
16566
|
+
updateWorkItemFile(filePath, enrichedLearning);
|
|
16580
16567
|
log.success(`${targetId} marked as completed`);
|
|
16581
|
-
|
|
16582
|
-
log.success(`Moved file:`);
|
|
16583
|
-
log.info(` ${path7.relative(dir, filePath)}`);
|
|
16584
|
-
log.info(` \u2192 ${path7.relative(dir, finalPath)}`);
|
|
16585
|
-
}
|
|
16586
|
-
log.success(`Learning recorded in ${path7.relative(dir, finalPath)}`);
|
|
16568
|
+
log.success(`Learning recorded in ${filePath.replace(dir + "/", "")}`);
|
|
16587
16569
|
if (hasExceptions) {
|
|
16588
16570
|
log.warn("Learning captured from a Work Item completed with validation exceptions.");
|
|
16589
16571
|
}
|
|
@@ -17731,8 +17713,8 @@ function runGraphExport(opts = {}) {
|
|
|
17731
17713
|
|
|
17732
17714
|
// src/core/system-topology.ts
|
|
17733
17715
|
import { parse as parseYaml17, stringify as stringifyYaml8 } from "yaml";
|
|
17734
|
-
import
|
|
17735
|
-
import
|
|
17716
|
+
import fs3 from "fs";
|
|
17717
|
+
import path7 from "path";
|
|
17736
17718
|
import crypto from "crypto";
|
|
17737
17719
|
var TOPOLOGY_FILE = "knowledge/tech/system-topology.yml";
|
|
17738
17720
|
var SYSTEM_ENTITY_KINDS = /* @__PURE__ */ new Set([
|
|
@@ -17898,14 +17880,14 @@ function serializeTopology(entities, relationships) {
|
|
|
17898
17880
|
return stringifyYaml8(doc);
|
|
17899
17881
|
}
|
|
17900
17882
|
function atomicWrite(filePath, content) {
|
|
17901
|
-
|
|
17883
|
+
fs3.mkdirSync(path7.dirname(filePath), { recursive: true });
|
|
17902
17884
|
const tmp = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
17903
|
-
|
|
17885
|
+
fs3.writeFileSync(tmp, content, "utf-8");
|
|
17904
17886
|
try {
|
|
17905
|
-
|
|
17887
|
+
fs3.renameSync(tmp, filePath);
|
|
17906
17888
|
} catch (err) {
|
|
17907
17889
|
try {
|
|
17908
|
-
|
|
17890
|
+
fs3.rmSync(tmp, { force: true });
|
|
17909
17891
|
} catch {
|
|
17910
17892
|
}
|
|
17911
17893
|
throw err;
|
|
@@ -18015,8 +17997,8 @@ import matter12 from "gray-matter";
|
|
|
18015
17997
|
import { parse as parseYaml18, stringify as stringifyYaml9 } from "yaml";
|
|
18016
17998
|
|
|
18017
17999
|
// src/core/work-item-write.ts
|
|
18018
|
-
import
|
|
18019
|
-
import
|
|
18000
|
+
import fs4 from "fs";
|
|
18001
|
+
import path8 from "path";
|
|
18020
18002
|
import crypto2 from "crypto";
|
|
18021
18003
|
import matter11 from "gray-matter";
|
|
18022
18004
|
var WORK_ITEMS_DIR3 = "knowledge/delivery/work-items";
|
|
@@ -18039,7 +18021,7 @@ function nextWorkItemId2(dir) {
|
|
|
18039
18021
|
let max = 0;
|
|
18040
18022
|
const walk = (d) => {
|
|
18041
18023
|
if (!exists(d)) return;
|
|
18042
|
-
for (const entry of
|
|
18024
|
+
for (const entry of fs4.readdirSync(d)) {
|
|
18043
18025
|
const full = join(d, entry);
|
|
18044
18026
|
if (isFile(full)) {
|
|
18045
18027
|
const m = entry.match(/WI-(\d+)/);
|
|
@@ -18053,14 +18035,14 @@ function nextWorkItemId2(dir) {
|
|
|
18053
18035
|
return `WI-${String(max + 1).padStart(3, "0")}`;
|
|
18054
18036
|
}
|
|
18055
18037
|
function atomicWrite2(filePath, content) {
|
|
18056
|
-
|
|
18038
|
+
fs4.mkdirSync(path8.dirname(filePath), { recursive: true });
|
|
18057
18039
|
const tmp = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
18058
|
-
|
|
18040
|
+
fs4.writeFileSync(tmp, content, "utf-8");
|
|
18059
18041
|
try {
|
|
18060
|
-
|
|
18042
|
+
fs4.renameSync(tmp, filePath);
|
|
18061
18043
|
} catch (err) {
|
|
18062
18044
|
try {
|
|
18063
|
-
|
|
18045
|
+
fs4.rmSync(tmp, { force: true });
|
|
18064
18046
|
} catch {
|
|
18065
18047
|
}
|
|
18066
18048
|
throw err;
|
|
@@ -18113,6 +18095,25 @@ ${body}`);
|
|
|
18113
18095
|
${out.join("\n\n")}
|
|
18114
18096
|
`.replace(/\n{3,}/g, "\n\n");
|
|
18115
18097
|
}
|
|
18098
|
+
function importedBody(title, type, sourceBody) {
|
|
18099
|
+
const lines = sourceBody.split(/\r?\n/);
|
|
18100
|
+
let i = 0;
|
|
18101
|
+
while (i < lines.length && !lines[i].trim()) i++;
|
|
18102
|
+
if (i < lines.length && /^#\s+/.test(lines[i])) {
|
|
18103
|
+
i++;
|
|
18104
|
+
while (i < lines.length && !lines[i].trim()) i++;
|
|
18105
|
+
if (i < lines.length && /^>\s*Type:/i.test(lines[i])) i++;
|
|
18106
|
+
}
|
|
18107
|
+
const rest = lines.slice(i).join("\n").trim();
|
|
18108
|
+
const preamble = `# ${title}
|
|
18109
|
+
|
|
18110
|
+
> Type: ${type}`;
|
|
18111
|
+
return rest ? `${preamble}
|
|
18112
|
+
|
|
18113
|
+
${rest}
|
|
18114
|
+
` : `${preamble}
|
|
18115
|
+
`;
|
|
18116
|
+
}
|
|
18116
18117
|
function serialize(data, body) {
|
|
18117
18118
|
return matter11.stringify(`
|
|
18118
18119
|
${body.trim()}
|
|
@@ -18147,6 +18148,7 @@ function createWorkItem(dir, opts) {
|
|
|
18147
18148
|
if (!type) throw new WorkItemWriteError("INVALID_INPUT", `Unknown Work Item type "${opts.type}".`);
|
|
18148
18149
|
const id = nextWorkItemId2(dir);
|
|
18149
18150
|
const title = intent.split(/\r?\n/)[0].trim().slice(0, 120);
|
|
18151
|
+
const summary = opts.summary?.trim() ? opts.summary.trim() : intent;
|
|
18150
18152
|
const today3 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
18151
18153
|
const source = opts.source ? { ...opts.source, inferred: false } : { type: "manual", inferred: false };
|
|
18152
18154
|
const data = {
|
|
@@ -18159,12 +18161,12 @@ function createWorkItem(dir, opts) {
|
|
|
18159
18161
|
source,
|
|
18160
18162
|
generated_by: "kaddo-admin",
|
|
18161
18163
|
affected_modules: [],
|
|
18162
|
-
summary
|
|
18164
|
+
summary
|
|
18163
18165
|
};
|
|
18164
18166
|
if (opts.originalSnapshot) data.original_snapshot = opts.originalSnapshot;
|
|
18165
18167
|
const answers = opts.answers ?? {};
|
|
18166
18168
|
const hasAnswers = Object.values(answers).some((v) => v?.trim());
|
|
18167
|
-
const body = hasAnswers ? captureBody(title, type, answers) : freshBody({
|
|
18169
|
+
const body = opts.body?.trim() ? importedBody(title, type, opts.body) : hasAnswers ? captureBody(title, type, answers) : freshBody({
|
|
18168
18170
|
title,
|
|
18169
18171
|
type,
|
|
18170
18172
|
summary: intent,
|
|
@@ -18869,8 +18871,8 @@ async function handleJiraResponse(res) {
|
|
|
18869
18871
|
}
|
|
18870
18872
|
return await res.json();
|
|
18871
18873
|
}
|
|
18872
|
-
async function jiraFetch(baseUrl,
|
|
18873
|
-
const url = new URL(
|
|
18874
|
+
async function jiraFetch(baseUrl, path11, auth, timeoutMs, params) {
|
|
18875
|
+
const url = new URL(path11, baseUrl + "/");
|
|
18874
18876
|
if (params) for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
|
|
18875
18877
|
const controller = new AbortController();
|
|
18876
18878
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -18888,8 +18890,8 @@ async function jiraFetch(baseUrl, path12, auth, timeoutMs, params) {
|
|
|
18888
18890
|
clearTimeout(timer);
|
|
18889
18891
|
}
|
|
18890
18892
|
}
|
|
18891
|
-
async function jiraPost(baseUrl,
|
|
18892
|
-
const url = new URL(
|
|
18893
|
+
async function jiraPost(baseUrl, path11, auth, timeoutMs, body) {
|
|
18894
|
+
const url = new URL(path11, baseUrl + "/");
|
|
18893
18895
|
const controller = new AbortController();
|
|
18894
18896
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
18895
18897
|
try {
|
|
@@ -20548,7 +20550,7 @@ function runAdr(opts = {}) {
|
|
|
20548
20550
|
}
|
|
20549
20551
|
|
|
20550
20552
|
// src/commands/tech.ts
|
|
20551
|
-
import
|
|
20553
|
+
import fs5 from "fs";
|
|
20552
20554
|
var DISCOVERY_FILES = ["architecture-notes.md", "decision-candidates.md"];
|
|
20553
20555
|
var DISCOVERY_DIR = "knowledge/tech/discovery";
|
|
20554
20556
|
function runTechOrganize(dir = cwd()) {
|
|
@@ -20565,7 +20567,7 @@ function runTechOrganize(dir = cwd()) {
|
|
|
20565
20567
|
continue;
|
|
20566
20568
|
}
|
|
20567
20569
|
ensureDir(join(dir, DISCOVERY_DIR));
|
|
20568
|
-
|
|
20570
|
+
fs5.renameSync(from, to);
|
|
20569
20571
|
moved.push(`knowledge/tech/${file} \u2192 ${DISCOVERY_DIR}/${file}`);
|
|
20570
20572
|
}
|
|
20571
20573
|
if (moved.length > 0) {
|
|
@@ -20647,8 +20649,8 @@ function runAssetsUpdate(kind, opts = {}) {
|
|
|
20647
20649
|
}
|
|
20648
20650
|
|
|
20649
20651
|
// src/commands/ready.ts
|
|
20650
|
-
import
|
|
20651
|
-
import
|
|
20652
|
+
import fs6 from "fs";
|
|
20653
|
+
import path9 from "path";
|
|
20652
20654
|
import matter14 from "gray-matter";
|
|
20653
20655
|
function validateReadiness(content, frontmatter) {
|
|
20654
20656
|
const warnings = [];
|
|
@@ -20711,10 +20713,10 @@ function transitionToReady(filePath) {
|
|
|
20711
20713
|
const posix = filePath.replace(/\\/g, "/");
|
|
20712
20714
|
let newPath = filePath;
|
|
20713
20715
|
if (posix.includes("/work-items/draft/")) {
|
|
20714
|
-
const readyDir =
|
|
20716
|
+
const readyDir = path9.dirname(filePath).replace(/[/\\]draft$/, path9.sep + "ready");
|
|
20715
20717
|
ensureDir(readyDir);
|
|
20716
|
-
const fileName =
|
|
20717
|
-
newPath =
|
|
20718
|
+
const fileName = path9.basename(filePath);
|
|
20719
|
+
newPath = path9.join(readyDir, fileName);
|
|
20718
20720
|
}
|
|
20719
20721
|
return { newPath, newContent };
|
|
20720
20722
|
}
|
|
@@ -20782,11 +20784,11 @@ async function runReady(id, opts = {}) {
|
|
|
20782
20784
|
const { newPath, newContent } = transitionToReady(wi.filePath);
|
|
20783
20785
|
if (newPath !== wi.filePath) {
|
|
20784
20786
|
writeFile(newPath, newContent);
|
|
20785
|
-
|
|
20787
|
+
fs6.unlinkSync(wi.filePath);
|
|
20786
20788
|
log.success(`Updated status: ready`);
|
|
20787
20789
|
log.success(`Moved file:`);
|
|
20788
|
-
log.info(` ${
|
|
20789
|
-
log.info(` \u2192 ${
|
|
20790
|
+
log.info(` ${path9.relative(dir, wi.filePath)}`);
|
|
20791
|
+
log.info(` \u2192 ${path9.relative(dir, newPath)}`);
|
|
20790
20792
|
} else {
|
|
20791
20793
|
writeFile(wi.filePath, newContent);
|
|
20792
20794
|
log.success(`Updated status: ready`);
|
|
@@ -20797,7 +20799,7 @@ async function runReady(id, opts = {}) {
|
|
|
20797
20799
|
}
|
|
20798
20800
|
|
|
20799
20801
|
// src/commands/admin.ts
|
|
20800
|
-
import
|
|
20802
|
+
import path10 from "path";
|
|
20801
20803
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
20802
20804
|
import net from "net";
|
|
20803
20805
|
function isPortAvailable(port, host) {
|
|
@@ -20812,17 +20814,17 @@ function isPortAvailable(port, host) {
|
|
|
20812
20814
|
});
|
|
20813
20815
|
}
|
|
20814
20816
|
function resolveStaticDir() {
|
|
20815
|
-
const __dirname =
|
|
20817
|
+
const __dirname = path10.dirname(fileURLToPath2(import.meta.url));
|
|
20816
20818
|
const candidates = [
|
|
20817
20819
|
// Monorepo development: prefer the freshly built admin over the copy bundled into the CLI dist.
|
|
20818
20820
|
// The CLI build copies admin/dist into dist/admin-dist, but that copy can be stale when the admin
|
|
20819
20821
|
// was rebuilt after the CLI (build order is not guaranteed in `pnpm -r build`). Serving the admin
|
|
20820
20822
|
// package's own dist first ensures `kaddo admin` always shows the current frontend in dev. This
|
|
20821
20823
|
// path does not exist in a published npm install (admin is private), so it falls back below.
|
|
20822
|
-
|
|
20823
|
-
|
|
20824
|
+
path10.resolve(__dirname, "..", "..", "admin", "dist"),
|
|
20825
|
+
path10.resolve(__dirname, "..", "node_modules", "@kaddo", "admin", "dist"),
|
|
20824
20826
|
// Bundled inside CLI dist (npm install)
|
|
20825
|
-
|
|
20827
|
+
path10.resolve(__dirname, "admin-dist")
|
|
20826
20828
|
];
|
|
20827
20829
|
for (const c of candidates) {
|
|
20828
20830
|
if (exists(join(c, "index.html"))) return c;
|
|
@@ -20864,8 +20866,8 @@ async function runAdmin(opts = {}) {
|
|
|
20864
20866
|
}
|
|
20865
20867
|
let adminServer;
|
|
20866
20868
|
try {
|
|
20867
|
-
const __dirname =
|
|
20868
|
-
const bundled =
|
|
20869
|
+
const __dirname = path10.dirname(fileURLToPath2(import.meta.url));
|
|
20870
|
+
const bundled = path10.resolve(__dirname, "admin-server", "index.js");
|
|
20869
20871
|
if (exists(bundled)) {
|
|
20870
20872
|
const { pathToFileURL } = await import("url");
|
|
20871
20873
|
adminServer = await import(pathToFileURL(bundled).href);
|
|
@@ -20922,7 +20924,7 @@ async function runAdmin(opts = {}) {
|
|
|
20922
20924
|
|
|
20923
20925
|
// src/core/work-item-import.ts
|
|
20924
20926
|
import crypto3 from "crypto";
|
|
20925
|
-
import
|
|
20927
|
+
import fs7 from "fs";
|
|
20926
20928
|
import matter16 from "gray-matter";
|
|
20927
20929
|
|
|
20928
20930
|
// src/core/work-items.ts
|
|
@@ -21002,8 +21004,8 @@ function parseGraphReason(v) {
|
|
|
21002
21004
|
if (!v || typeof v !== "object") return null;
|
|
21003
21005
|
const o = v;
|
|
21004
21006
|
const relationship = typeof o.relationship === "string" && o.relationship.trim() ? o.relationship.trim() : null;
|
|
21005
|
-
const
|
|
21006
|
-
return relationship ||
|
|
21007
|
+
const path11 = Array.isArray(o.path) ? o.path.map(String).filter(Boolean) : [];
|
|
21008
|
+
return relationship || path11.length ? { relationship, path: path11 } : null;
|
|
21007
21009
|
}
|
|
21008
21010
|
function parseExplain(o) {
|
|
21009
21011
|
const refs = Array.isArray(o.evidence) ? o.evidence : Array.isArray(o.evidence_refs) ? o.evidence_refs : [];
|
|
@@ -21548,7 +21550,7 @@ function parseContent(raw) {
|
|
|
21548
21550
|
const title = extractTitle(frontmatterFields, bodyText);
|
|
21549
21551
|
const candidateType = extractType(frontmatterFields);
|
|
21550
21552
|
const sections = extractSections(bodyText);
|
|
21551
|
-
const summary = bodyText
|
|
21553
|
+
const summary = deriveSummary(bodyText, title);
|
|
21552
21554
|
return {
|
|
21553
21555
|
format,
|
|
21554
21556
|
title,
|
|
@@ -21568,6 +21570,16 @@ function extractTitle(fields, body) {
|
|
|
21568
21570
|
const firstLine = body.split(/\r?\n/).find((l) => l.trim());
|
|
21569
21571
|
return (firstLine?.trim() ?? "Untitled Work Item").slice(0, 120);
|
|
21570
21572
|
}
|
|
21573
|
+
function deriveSummary(body, title) {
|
|
21574
|
+
for (const line of body.split(/\r?\n/)) {
|
|
21575
|
+
const t = line.trim();
|
|
21576
|
+
if (!t) continue;
|
|
21577
|
+
if (/^#{1,6}\s/.test(t)) continue;
|
|
21578
|
+
if (/^>/.test(t)) continue;
|
|
21579
|
+
return t.slice(0, 280);
|
|
21580
|
+
}
|
|
21581
|
+
return title;
|
|
21582
|
+
}
|
|
21571
21583
|
function extractType(fields) {
|
|
21572
21584
|
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;
|
|
21573
21585
|
if (!raw) return void 0;
|
|
@@ -21605,6 +21617,7 @@ function normalizeImportFields(parsed, opts) {
|
|
|
21605
21617
|
const intent = parsed.body && parsed.body !== parsed.title ? `${parsed.title}
|
|
21606
21618
|
|
|
21607
21619
|
${parsed.body}` : parsed.title;
|
|
21620
|
+
const body = parsed.body && parsed.body.trim() !== parsed.title.trim() ? parsed.body : void 0;
|
|
21608
21621
|
const source = {
|
|
21609
21622
|
type: opts.importSource === "chat" ? "chat" : "external",
|
|
21610
21623
|
imported_at: (/* @__PURE__ */ new Date()).toISOString().split("T")[0]
|
|
@@ -21619,7 +21632,7 @@ ${parsed.body}` : parsed.title;
|
|
|
21619
21632
|
const labels = parsed.candidateFields.labels.filter((l) => typeof l === "string");
|
|
21620
21633
|
if (labels.length > 0) snapshot.labels = labels;
|
|
21621
21634
|
}
|
|
21622
|
-
return { type, intent, source, snapshot, discardedFields };
|
|
21635
|
+
return { type, intent, summary: parsed.summary, body, source, snapshot, discardedFields };
|
|
21623
21636
|
}
|
|
21624
21637
|
function computeContentHash(raw) {
|
|
21625
21638
|
return crypto3.createHash("sha256").update(raw.trim(), "utf-8").digest("hex");
|
|
@@ -21697,7 +21710,7 @@ function importWorkItem(dir, opts) {
|
|
|
21697
21710
|
};
|
|
21698
21711
|
}
|
|
21699
21712
|
if (opts.onConflict === "replace") {
|
|
21700
|
-
|
|
21713
|
+
fs7.rmSync(existing.filePath, { force: true });
|
|
21701
21714
|
replacedWorkItem = existing.workItemId;
|
|
21702
21715
|
}
|
|
21703
21716
|
}
|
|
@@ -21706,7 +21719,9 @@ function importWorkItem(dir, opts) {
|
|
|
21706
21719
|
intent: normalized.intent,
|
|
21707
21720
|
type: normalized.type,
|
|
21708
21721
|
source: normalized.source,
|
|
21709
|
-
originalSnapshot: normalized.snapshot
|
|
21722
|
+
originalSnapshot: normalized.snapshot,
|
|
21723
|
+
summary: normalized.summary,
|
|
21724
|
+
body: normalized.body
|
|
21710
21725
|
});
|
|
21711
21726
|
let refinementHandoff;
|
|
21712
21727
|
try {
|
|
@@ -22294,9 +22309,9 @@ function markRegistered(dir, identity) {
|
|
|
22294
22309
|
ensureDir(join(dir, TELEMETRY_DIR));
|
|
22295
22310
|
writeFile(identityPath(dir), JSON.stringify(identity, null, 2));
|
|
22296
22311
|
}
|
|
22297
|
-
function signPayload(identity, method,
|
|
22312
|
+
function signPayload(identity, method, path11, timestamp, nonce, bodySha256) {
|
|
22298
22313
|
const canonical = `${method}
|
|
22299
|
-
${
|
|
22314
|
+
${path11}
|
|
22300
22315
|
${identity.installationId}
|
|
22301
22316
|
${timestamp}
|
|
22302
22317
|
${nonce}
|
|
@@ -23107,8 +23122,8 @@ var capsuleCmd = program.command("capsule").description("Export this project as
|
|
|
23107
23122
|
capsuleCmd.command("export").description("Write a Knowledge Capsule about this project to .kaddo/exports/").option("--scope <scope>", 'Export scope: "system" includes all mapped modules').option("--module <id>", "Export a capsule for a specific mapped module").action((opts) => {
|
|
23108
23123
|
runCapsuleExport(opts);
|
|
23109
23124
|
});
|
|
23110
|
-
capsuleCmd.command("add <path>").description("Register an external Knowledge Capsule as project context (.kaddo/external.yml)").action((
|
|
23111
|
-
runCapsuleAdd(
|
|
23125
|
+
capsuleCmd.command("add <path>").description("Register an external Knowledge Capsule as project context (.kaddo/external.yml)").action((path11) => {
|
|
23126
|
+
runCapsuleAdd(path11);
|
|
23112
23127
|
});
|
|
23113
23128
|
var graphCmd = program.command("graph").description("Export the lightweight, file-based knowledge graph of the project");
|
|
23114
23129
|
graphCmd.command("export").description("Write the knowledge graph to .kaddo/graph.json and .kaddo/graph.mmd").option("--scope <scope>", "Graph scope: active (default) or all").option("--format <format>", "Output format: json, mermaid (default: both)").action((opts) => {
|