@kaddo/cli 3.113.0 → 3.114.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +199 -452
- package/dist/core.js +26 -8
- package/dist/index.js +118 -84
- package/package.json +1 -1
package/dist/core.js
CHANGED
|
@@ -9253,6 +9253,14 @@ ${body}`);
|
|
|
9253
9253
|
${out.join("\n\n")}
|
|
9254
9254
|
`.replace(/\n{3,}/g, "\n\n");
|
|
9255
9255
|
}
|
|
9256
|
+
function ensureH1(body, title) {
|
|
9257
|
+
const trimmed = body.trim();
|
|
9258
|
+
const firstMeaningful = trimmed.split(/\r?\n/).find((l) => l.trim());
|
|
9259
|
+
if (firstMeaningful && /^#\s+/.test(firstMeaningful.trim())) return trimmed;
|
|
9260
|
+
return `# ${title}
|
|
9261
|
+
|
|
9262
|
+
${trimmed}`;
|
|
9263
|
+
}
|
|
9256
9264
|
function applyFrontmatter(data, input) {
|
|
9257
9265
|
const next = { ...data };
|
|
9258
9266
|
next.title = input.title;
|
|
@@ -9392,6 +9400,7 @@ function createWorkItem(dir, opts) {
|
|
|
9392
9400
|
const id = nextWorkItemId(dir);
|
|
9393
9401
|
const title = intent.split(/\r?\n/)[0].trim().slice(0, 120);
|
|
9394
9402
|
const today2 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
9403
|
+
const summary = opts.summary?.trim() || intent;
|
|
9395
9404
|
const source = opts.source ? { ...opts.source, inferred: false } : { type: "manual", inferred: false };
|
|
9396
9405
|
const data = {
|
|
9397
9406
|
type,
|
|
@@ -9403,15 +9412,16 @@ function createWorkItem(dir, opts) {
|
|
|
9403
9412
|
source,
|
|
9404
9413
|
generated_by: "kaddo-admin",
|
|
9405
9414
|
affected_modules: [],
|
|
9406
|
-
summary
|
|
9415
|
+
summary
|
|
9407
9416
|
};
|
|
9408
9417
|
if (opts.originalSnapshot) data.original_snapshot = opts.originalSnapshot;
|
|
9409
9418
|
const answers = opts.answers ?? {};
|
|
9410
9419
|
const hasAnswers = Object.values(answers).some((v) => v?.trim());
|
|
9411
|
-
const
|
|
9420
|
+
const providedBody = opts.body?.trim();
|
|
9421
|
+
const body = providedBody ? ensureH1(providedBody, title) : hasAnswers ? captureBody(title, type, answers) : freshBody({
|
|
9412
9422
|
title,
|
|
9413
9423
|
type,
|
|
9414
|
-
summary
|
|
9424
|
+
summary,
|
|
9415
9425
|
scopeUnknowns: [],
|
|
9416
9426
|
affectedModules: [],
|
|
9417
9427
|
moduleCoverage: [],
|
|
@@ -10449,15 +10459,21 @@ function extractSections(body) {
|
|
|
10449
10459
|
flush();
|
|
10450
10460
|
return sections;
|
|
10451
10461
|
}
|
|
10462
|
+
function deriveShortSummary(parsed) {
|
|
10463
|
+
const paragraph = parsed.body.split(/\n{2,}/).map((p) => p.trim()).find((p) => p && !/^#{1,6}\s/.test(p) && !/^>/.test(p) && p !== parsed.title);
|
|
10464
|
+
const base = paragraph ? paragraph.replace(/\s+/g, " ") : parsed.title;
|
|
10465
|
+
return base.length > 280 ? `${base.slice(0, 277).trimEnd()}\u2026` : base;
|
|
10466
|
+
}
|
|
10452
10467
|
function normalizeImportFields(parsed, opts) {
|
|
10453
10468
|
const discardedFields = [];
|
|
10454
10469
|
for (const key of Object.keys(parsed.candidateFields)) {
|
|
10455
10470
|
if (LIFECYCLE_FIELDS.has(key)) discardedFields.push(key);
|
|
10456
10471
|
}
|
|
10457
10472
|
const type = opts.userType ? normalizeType(opts.userType) ?? "feature" : parsed.type ?? "feature";
|
|
10458
|
-
const
|
|
10459
|
-
|
|
10460
|
-
|
|
10473
|
+
const hasRealBody = !!parsed.body && parsed.body !== parsed.title;
|
|
10474
|
+
const intent = parsed.title;
|
|
10475
|
+
const body = hasRealBody ? parsed.body : void 0;
|
|
10476
|
+
const summary = hasRealBody ? deriveShortSummary(parsed) : parsed.title;
|
|
10461
10477
|
const source = {
|
|
10462
10478
|
type: opts.importSource === "chat" ? "chat" : "external",
|
|
10463
10479
|
imported_at: (/* @__PURE__ */ new Date()).toISOString().split("T")[0]
|
|
@@ -10465,14 +10481,14 @@ ${parsed.body}` : parsed.title;
|
|
|
10465
10481
|
source.source_format = opts.sourceFormat;
|
|
10466
10482
|
source.source_hash = opts.sourceHash;
|
|
10467
10483
|
const snapshot = { title: parsed.title };
|
|
10468
|
-
if (
|
|
10484
|
+
if (summary !== parsed.title) snapshot.description = summary;
|
|
10469
10485
|
if (typeof parsed.candidateFields.type === "string") snapshot.type = parsed.candidateFields.type;
|
|
10470
10486
|
if (typeof parsed.candidateFields.status === "string") snapshot.status = parsed.candidateFields.status;
|
|
10471
10487
|
if (Array.isArray(parsed.candidateFields.labels)) {
|
|
10472
10488
|
const labels = parsed.candidateFields.labels.filter((l) => typeof l === "string");
|
|
10473
10489
|
if (labels.length > 0) snapshot.labels = labels;
|
|
10474
10490
|
}
|
|
10475
|
-
return { type, intent, source, snapshot, discardedFields };
|
|
10491
|
+
return { type, intent, summary, body, source, snapshot, discardedFields };
|
|
10476
10492
|
}
|
|
10477
10493
|
function computeContentHash(raw) {
|
|
10478
10494
|
return crypto3.createHash("sha256").update(raw.trim(), "utf-8").digest("hex");
|
|
@@ -10558,6 +10574,8 @@ function importWorkItem(dir, opts) {
|
|
|
10558
10574
|
const result = createWorkItem(dir, {
|
|
10559
10575
|
intent: normalized.intent,
|
|
10560
10576
|
type: normalized.type,
|
|
10577
|
+
summary: normalized.summary,
|
|
10578
|
+
body: normalized.body,
|
|
10561
10579
|
source: normalized.source,
|
|
10562
10580
|
originalSnapshot: normalized.snapshot
|
|
10563
10581
|
});
|
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 path12 = i.path.join(".");
|
|
1394
|
+
return path12 ? ` - ${path12}: ${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 path12 = join(dir, IGNORE_FILE);
|
|
7048
|
+
if (!exists(path12)) return [];
|
|
7049
7049
|
try {
|
|
7050
|
-
const raw = readFile(
|
|
7050
|
+
const raw = readFile(path12);
|
|
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 path12 = 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(path12, 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 path12 = 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(path12, 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 path12 = join(dir, DESCRIPTOR_PATH);
|
|
7099
|
+
if (!exists(path12)) return [];
|
|
7100
7100
|
let parsed;
|
|
7101
7101
|
try {
|
|
7102
|
-
parsed = parseYaml6(readFile(
|
|
7102
|
+
parsed = parseYaml6(readFile(path12));
|
|
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(([path12, warnings]) => ({ path: path12, 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 path12 = join(dir, DESCRIPTOR_PATH2);
|
|
10485
|
+
if (!exists(path12)) return { version: 1, modules: [] };
|
|
10486
10486
|
try {
|
|
10487
|
-
const parsed = parseYaml10(readFile(
|
|
10487
|
+
const parsed = parseYaml10(readFile(path12));
|
|
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, path12, 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, path11, md) {
|
|
|
10874
10874
|
}
|
|
10875
10875
|
return {
|
|
10876
10876
|
id,
|
|
10877
|
-
path:
|
|
10877
|
+
path: path12,
|
|
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 path12 = layer2.files.map((f) => `${KNOWLEDGE3}/${f}`).find((rel) => exists(join(dir, rel)));
|
|
11139
|
+
if (path12) {
|
|
11140
|
+
addNode({ id: layer2.id, type: layer2.type, label: layer2.label, path: path12 });
|
|
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 path12 = agentInstallPath(file);
|
|
12704
|
+
const installed = isFile(join(dir, path12));
|
|
12705
12705
|
const group = agentGroupOf(file);
|
|
12706
|
-
return { agentPath:
|
|
12706
|
+
return { agentPath: path12, 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,15 +16442,20 @@ function runStatus() {
|
|
|
16442
16442
|
}
|
|
16443
16443
|
|
|
16444
16444
|
// src/commands/learn.ts
|
|
16445
|
+
import fs3 from "fs";
|
|
16446
|
+
import path7 from "path";
|
|
16445
16447
|
import matter9 from "gray-matter";
|
|
16446
16448
|
var ARCH_DIR9 = "knowledge";
|
|
16447
16449
|
var WORK_ITEMS_DIR2 = "knowledge/delivery/work-items";
|
|
16448
|
-
function
|
|
16449
|
-
const
|
|
16450
|
-
|
|
16451
|
-
|
|
16452
|
-
const
|
|
16453
|
-
|
|
16450
|
+
function completedPathFor(filePath) {
|
|
16451
|
+
const posix = filePath.replace(/\\/g, "/");
|
|
16452
|
+
const m = posix.match(/\/work-items\/(draft|ready|in-progress|blocked)\//);
|
|
16453
|
+
if (!m) return filePath;
|
|
16454
|
+
const completedDir = path7.dirname(filePath).replace(
|
|
16455
|
+
new RegExp(`[/\\\\]${m[1]}$`),
|
|
16456
|
+
path7.sep + "completed"
|
|
16457
|
+
);
|
|
16458
|
+
return path7.join(completedDir, path7.basename(filePath));
|
|
16454
16459
|
}
|
|
16455
16460
|
function updateWorkItemFile(filePath, learning) {
|
|
16456
16461
|
const raw = readFile(filePath);
|
|
@@ -16480,7 +16485,15 @@ ${learning.trim()}
|
|
|
16480
16485
|
`;
|
|
16481
16486
|
}
|
|
16482
16487
|
const newRaw = matter9.stringify(updatedContent, data);
|
|
16483
|
-
|
|
16488
|
+
const newPath = completedPathFor(filePath);
|
|
16489
|
+
if (newPath !== filePath) {
|
|
16490
|
+
ensureDir(path7.dirname(newPath));
|
|
16491
|
+
writeFile(newPath, newRaw);
|
|
16492
|
+
fs3.unlinkSync(filePath);
|
|
16493
|
+
} else {
|
|
16494
|
+
writeFile(filePath, newRaw);
|
|
16495
|
+
}
|
|
16496
|
+
return newPath;
|
|
16484
16497
|
}
|
|
16485
16498
|
async function runLearn(artifactId, opts = {}) {
|
|
16486
16499
|
const dir = cwd();
|
|
@@ -16514,7 +16527,10 @@ async function runLearn(artifactId, opts = {}) {
|
|
|
16514
16527
|
});
|
|
16515
16528
|
targetId = chosen;
|
|
16516
16529
|
}
|
|
16517
|
-
const
|
|
16530
|
+
const targetArtifact = closable.find(
|
|
16531
|
+
(a) => (a.id || a.title) === targetId
|
|
16532
|
+
) ?? artifacts.find((a) => (a.id || a.title) === targetId);
|
|
16533
|
+
const filePath = targetArtifact?.filePath ?? null;
|
|
16518
16534
|
if (!filePath) {
|
|
16519
16535
|
log.error(`Work item "${targetId}" not found in ${WORK_ITEMS_DIR2}/`);
|
|
16520
16536
|
process.exit(1);
|
|
@@ -16563,9 +16579,9 @@ async function runLearn(artifactId, opts = {}) {
|
|
|
16563
16579
|
}
|
|
16564
16580
|
enrichedLearning += "\n\n> " + notes.join(" ");
|
|
16565
16581
|
}
|
|
16566
|
-
updateWorkItemFile(filePath, enrichedLearning);
|
|
16582
|
+
const finalPath = updateWorkItemFile(filePath, enrichedLearning);
|
|
16567
16583
|
log.success(`${targetId} marked as completed`);
|
|
16568
|
-
log.success(`Learning recorded in ${
|
|
16584
|
+
log.success(`Learning recorded in ${finalPath.replace(dir + path7.sep, "").replace(/\\/g, "/")}`);
|
|
16569
16585
|
if (hasExceptions) {
|
|
16570
16586
|
log.warn("Learning captured from a Work Item completed with validation exceptions.");
|
|
16571
16587
|
}
|
|
@@ -17713,8 +17729,8 @@ function runGraphExport(opts = {}) {
|
|
|
17713
17729
|
|
|
17714
17730
|
// src/core/system-topology.ts
|
|
17715
17731
|
import { parse as parseYaml17, stringify as stringifyYaml8 } from "yaml";
|
|
17716
|
-
import
|
|
17717
|
-
import
|
|
17732
|
+
import fs4 from "fs";
|
|
17733
|
+
import path8 from "path";
|
|
17718
17734
|
import crypto from "crypto";
|
|
17719
17735
|
var TOPOLOGY_FILE = "knowledge/tech/system-topology.yml";
|
|
17720
17736
|
var SYSTEM_ENTITY_KINDS = /* @__PURE__ */ new Set([
|
|
@@ -17880,14 +17896,14 @@ function serializeTopology(entities, relationships) {
|
|
|
17880
17896
|
return stringifyYaml8(doc);
|
|
17881
17897
|
}
|
|
17882
17898
|
function atomicWrite(filePath, content) {
|
|
17883
|
-
|
|
17899
|
+
fs4.mkdirSync(path8.dirname(filePath), { recursive: true });
|
|
17884
17900
|
const tmp = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
17885
|
-
|
|
17901
|
+
fs4.writeFileSync(tmp, content, "utf-8");
|
|
17886
17902
|
try {
|
|
17887
|
-
|
|
17903
|
+
fs4.renameSync(tmp, filePath);
|
|
17888
17904
|
} catch (err) {
|
|
17889
17905
|
try {
|
|
17890
|
-
|
|
17906
|
+
fs4.rmSync(tmp, { force: true });
|
|
17891
17907
|
} catch {
|
|
17892
17908
|
}
|
|
17893
17909
|
throw err;
|
|
@@ -17997,8 +18013,8 @@ import matter12 from "gray-matter";
|
|
|
17997
18013
|
import { parse as parseYaml18, stringify as stringifyYaml9 } from "yaml";
|
|
17998
18014
|
|
|
17999
18015
|
// src/core/work-item-write.ts
|
|
18000
|
-
import
|
|
18001
|
-
import
|
|
18016
|
+
import fs5 from "fs";
|
|
18017
|
+
import path9 from "path";
|
|
18002
18018
|
import crypto2 from "crypto";
|
|
18003
18019
|
import matter11 from "gray-matter";
|
|
18004
18020
|
var WORK_ITEMS_DIR3 = "knowledge/delivery/work-items";
|
|
@@ -18021,7 +18037,7 @@ function nextWorkItemId2(dir) {
|
|
|
18021
18037
|
let max = 0;
|
|
18022
18038
|
const walk = (d) => {
|
|
18023
18039
|
if (!exists(d)) return;
|
|
18024
|
-
for (const entry of
|
|
18040
|
+
for (const entry of fs5.readdirSync(d)) {
|
|
18025
18041
|
const full = join(d, entry);
|
|
18026
18042
|
if (isFile(full)) {
|
|
18027
18043
|
const m = entry.match(/WI-(\d+)/);
|
|
@@ -18035,14 +18051,14 @@ function nextWorkItemId2(dir) {
|
|
|
18035
18051
|
return `WI-${String(max + 1).padStart(3, "0")}`;
|
|
18036
18052
|
}
|
|
18037
18053
|
function atomicWrite2(filePath, content) {
|
|
18038
|
-
|
|
18054
|
+
fs5.mkdirSync(path9.dirname(filePath), { recursive: true });
|
|
18039
18055
|
const tmp = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
18040
|
-
|
|
18056
|
+
fs5.writeFileSync(tmp, content, "utf-8");
|
|
18041
18057
|
try {
|
|
18042
|
-
|
|
18058
|
+
fs5.renameSync(tmp, filePath);
|
|
18043
18059
|
} catch (err) {
|
|
18044
18060
|
try {
|
|
18045
|
-
|
|
18061
|
+
fs5.rmSync(tmp, { force: true });
|
|
18046
18062
|
} catch {
|
|
18047
18063
|
}
|
|
18048
18064
|
throw err;
|
|
@@ -18095,6 +18111,14 @@ ${body}`);
|
|
|
18095
18111
|
${out.join("\n\n")}
|
|
18096
18112
|
`.replace(/\n{3,}/g, "\n\n");
|
|
18097
18113
|
}
|
|
18114
|
+
function ensureH1(body, title) {
|
|
18115
|
+
const trimmed = body.trim();
|
|
18116
|
+
const firstMeaningful = trimmed.split(/\r?\n/).find((l) => l.trim());
|
|
18117
|
+
if (firstMeaningful && /^#\s+/.test(firstMeaningful.trim())) return trimmed;
|
|
18118
|
+
return `# ${title}
|
|
18119
|
+
|
|
18120
|
+
${trimmed}`;
|
|
18121
|
+
}
|
|
18098
18122
|
function serialize(data, body) {
|
|
18099
18123
|
return matter11.stringify(`
|
|
18100
18124
|
${body.trim()}
|
|
@@ -18130,6 +18154,7 @@ function createWorkItem(dir, opts) {
|
|
|
18130
18154
|
const id = nextWorkItemId2(dir);
|
|
18131
18155
|
const title = intent.split(/\r?\n/)[0].trim().slice(0, 120);
|
|
18132
18156
|
const today3 = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
18157
|
+
const summary = opts.summary?.trim() || intent;
|
|
18133
18158
|
const source = opts.source ? { ...opts.source, inferred: false } : { type: "manual", inferred: false };
|
|
18134
18159
|
const data = {
|
|
18135
18160
|
type,
|
|
@@ -18141,15 +18166,16 @@ function createWorkItem(dir, opts) {
|
|
|
18141
18166
|
source,
|
|
18142
18167
|
generated_by: "kaddo-admin",
|
|
18143
18168
|
affected_modules: [],
|
|
18144
|
-
summary
|
|
18169
|
+
summary
|
|
18145
18170
|
};
|
|
18146
18171
|
if (opts.originalSnapshot) data.original_snapshot = opts.originalSnapshot;
|
|
18147
18172
|
const answers = opts.answers ?? {};
|
|
18148
18173
|
const hasAnswers = Object.values(answers).some((v) => v?.trim());
|
|
18149
|
-
const
|
|
18174
|
+
const providedBody = opts.body?.trim();
|
|
18175
|
+
const body = providedBody ? ensureH1(providedBody, title) : hasAnswers ? captureBody(title, type, answers) : freshBody({
|
|
18150
18176
|
title,
|
|
18151
18177
|
type,
|
|
18152
|
-
summary
|
|
18178
|
+
summary,
|
|
18153
18179
|
scopeUnknowns: [],
|
|
18154
18180
|
affectedModules: [],
|
|
18155
18181
|
moduleCoverage: [],
|
|
@@ -18851,8 +18877,8 @@ async function handleJiraResponse(res) {
|
|
|
18851
18877
|
}
|
|
18852
18878
|
return await res.json();
|
|
18853
18879
|
}
|
|
18854
|
-
async function jiraFetch(baseUrl,
|
|
18855
|
-
const url = new URL(
|
|
18880
|
+
async function jiraFetch(baseUrl, path12, auth, timeoutMs, params) {
|
|
18881
|
+
const url = new URL(path12, baseUrl + "/");
|
|
18856
18882
|
if (params) for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
|
|
18857
18883
|
const controller = new AbortController();
|
|
18858
18884
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -18870,8 +18896,8 @@ async function jiraFetch(baseUrl, path11, auth, timeoutMs, params) {
|
|
|
18870
18896
|
clearTimeout(timer);
|
|
18871
18897
|
}
|
|
18872
18898
|
}
|
|
18873
|
-
async function jiraPost(baseUrl,
|
|
18874
|
-
const url = new URL(
|
|
18899
|
+
async function jiraPost(baseUrl, path12, auth, timeoutMs, body) {
|
|
18900
|
+
const url = new URL(path12, baseUrl + "/");
|
|
18875
18901
|
const controller = new AbortController();
|
|
18876
18902
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
18877
18903
|
try {
|
|
@@ -20530,7 +20556,7 @@ function runAdr(opts = {}) {
|
|
|
20530
20556
|
}
|
|
20531
20557
|
|
|
20532
20558
|
// src/commands/tech.ts
|
|
20533
|
-
import
|
|
20559
|
+
import fs6 from "fs";
|
|
20534
20560
|
var DISCOVERY_FILES = ["architecture-notes.md", "decision-candidates.md"];
|
|
20535
20561
|
var DISCOVERY_DIR = "knowledge/tech/discovery";
|
|
20536
20562
|
function runTechOrganize(dir = cwd()) {
|
|
@@ -20547,7 +20573,7 @@ function runTechOrganize(dir = cwd()) {
|
|
|
20547
20573
|
continue;
|
|
20548
20574
|
}
|
|
20549
20575
|
ensureDir(join(dir, DISCOVERY_DIR));
|
|
20550
|
-
|
|
20576
|
+
fs6.renameSync(from, to);
|
|
20551
20577
|
moved.push(`knowledge/tech/${file} \u2192 ${DISCOVERY_DIR}/${file}`);
|
|
20552
20578
|
}
|
|
20553
20579
|
if (moved.length > 0) {
|
|
@@ -20629,8 +20655,8 @@ function runAssetsUpdate(kind, opts = {}) {
|
|
|
20629
20655
|
}
|
|
20630
20656
|
|
|
20631
20657
|
// src/commands/ready.ts
|
|
20632
|
-
import
|
|
20633
|
-
import
|
|
20658
|
+
import fs7 from "fs";
|
|
20659
|
+
import path10 from "path";
|
|
20634
20660
|
import matter14 from "gray-matter";
|
|
20635
20661
|
function validateReadiness(content, frontmatter) {
|
|
20636
20662
|
const warnings = [];
|
|
@@ -20693,10 +20719,10 @@ function transitionToReady(filePath) {
|
|
|
20693
20719
|
const posix = filePath.replace(/\\/g, "/");
|
|
20694
20720
|
let newPath = filePath;
|
|
20695
20721
|
if (posix.includes("/work-items/draft/")) {
|
|
20696
|
-
const readyDir =
|
|
20722
|
+
const readyDir = path10.dirname(filePath).replace(/[/\\]draft$/, path10.sep + "ready");
|
|
20697
20723
|
ensureDir(readyDir);
|
|
20698
|
-
const fileName =
|
|
20699
|
-
newPath =
|
|
20724
|
+
const fileName = path10.basename(filePath);
|
|
20725
|
+
newPath = path10.join(readyDir, fileName);
|
|
20700
20726
|
}
|
|
20701
20727
|
return { newPath, newContent };
|
|
20702
20728
|
}
|
|
@@ -20764,11 +20790,11 @@ async function runReady(id, opts = {}) {
|
|
|
20764
20790
|
const { newPath, newContent } = transitionToReady(wi.filePath);
|
|
20765
20791
|
if (newPath !== wi.filePath) {
|
|
20766
20792
|
writeFile(newPath, newContent);
|
|
20767
|
-
|
|
20793
|
+
fs7.unlinkSync(wi.filePath);
|
|
20768
20794
|
log.success(`Updated status: ready`);
|
|
20769
20795
|
log.success(`Moved file:`);
|
|
20770
|
-
log.info(` ${
|
|
20771
|
-
log.info(` \u2192 ${
|
|
20796
|
+
log.info(` ${path10.relative(dir, wi.filePath)}`);
|
|
20797
|
+
log.info(` \u2192 ${path10.relative(dir, newPath)}`);
|
|
20772
20798
|
} else {
|
|
20773
20799
|
writeFile(wi.filePath, newContent);
|
|
20774
20800
|
log.success(`Updated status: ready`);
|
|
@@ -20779,7 +20805,7 @@ async function runReady(id, opts = {}) {
|
|
|
20779
20805
|
}
|
|
20780
20806
|
|
|
20781
20807
|
// src/commands/admin.ts
|
|
20782
|
-
import
|
|
20808
|
+
import path11 from "path";
|
|
20783
20809
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
20784
20810
|
import net from "net";
|
|
20785
20811
|
function isPortAvailable(port, host) {
|
|
@@ -20794,17 +20820,17 @@ function isPortAvailable(port, host) {
|
|
|
20794
20820
|
});
|
|
20795
20821
|
}
|
|
20796
20822
|
function resolveStaticDir() {
|
|
20797
|
-
const __dirname =
|
|
20823
|
+
const __dirname = path11.dirname(fileURLToPath2(import.meta.url));
|
|
20798
20824
|
const candidates = [
|
|
20799
20825
|
// Monorepo development: prefer the freshly built admin over the copy bundled into the CLI dist.
|
|
20800
20826
|
// The CLI build copies admin/dist into dist/admin-dist, but that copy can be stale when the admin
|
|
20801
20827
|
// was rebuilt after the CLI (build order is not guaranteed in `pnpm -r build`). Serving the admin
|
|
20802
20828
|
// package's own dist first ensures `kaddo admin` always shows the current frontend in dev. This
|
|
20803
20829
|
// path does not exist in a published npm install (admin is private), so it falls back below.
|
|
20804
|
-
|
|
20805
|
-
|
|
20830
|
+
path11.resolve(__dirname, "..", "..", "admin", "dist"),
|
|
20831
|
+
path11.resolve(__dirname, "..", "node_modules", "@kaddo", "admin", "dist"),
|
|
20806
20832
|
// Bundled inside CLI dist (npm install)
|
|
20807
|
-
|
|
20833
|
+
path11.resolve(__dirname, "admin-dist")
|
|
20808
20834
|
];
|
|
20809
20835
|
for (const c of candidates) {
|
|
20810
20836
|
if (exists(join(c, "index.html"))) return c;
|
|
@@ -20846,8 +20872,8 @@ async function runAdmin(opts = {}) {
|
|
|
20846
20872
|
}
|
|
20847
20873
|
let adminServer;
|
|
20848
20874
|
try {
|
|
20849
|
-
const __dirname =
|
|
20850
|
-
const bundled =
|
|
20875
|
+
const __dirname = path11.dirname(fileURLToPath2(import.meta.url));
|
|
20876
|
+
const bundled = path11.resolve(__dirname, "admin-server", "index.js");
|
|
20851
20877
|
if (exists(bundled)) {
|
|
20852
20878
|
const { pathToFileURL } = await import("url");
|
|
20853
20879
|
adminServer = await import(pathToFileURL(bundled).href);
|
|
@@ -20904,7 +20930,7 @@ async function runAdmin(opts = {}) {
|
|
|
20904
20930
|
|
|
20905
20931
|
// src/core/work-item-import.ts
|
|
20906
20932
|
import crypto3 from "crypto";
|
|
20907
|
-
import
|
|
20933
|
+
import fs8 from "fs";
|
|
20908
20934
|
import matter16 from "gray-matter";
|
|
20909
20935
|
|
|
20910
20936
|
// src/core/work-items.ts
|
|
@@ -20984,8 +21010,8 @@ function parseGraphReason(v) {
|
|
|
20984
21010
|
if (!v || typeof v !== "object") return null;
|
|
20985
21011
|
const o = v;
|
|
20986
21012
|
const relationship = typeof o.relationship === "string" && o.relationship.trim() ? o.relationship.trim() : null;
|
|
20987
|
-
const
|
|
20988
|
-
return relationship ||
|
|
21013
|
+
const path12 = Array.isArray(o.path) ? o.path.map(String).filter(Boolean) : [];
|
|
21014
|
+
return relationship || path12.length ? { relationship, path: path12 } : null;
|
|
20989
21015
|
}
|
|
20990
21016
|
function parseExplain(o) {
|
|
20991
21017
|
const refs = Array.isArray(o.evidence) ? o.evidence : Array.isArray(o.evidence_refs) ? o.evidence_refs : [];
|
|
@@ -21578,15 +21604,21 @@ function extractSections(body) {
|
|
|
21578
21604
|
flush2();
|
|
21579
21605
|
return sections;
|
|
21580
21606
|
}
|
|
21607
|
+
function deriveShortSummary(parsed) {
|
|
21608
|
+
const paragraph = parsed.body.split(/\n{2,}/).map((p) => p.trim()).find((p) => p && !/^#{1,6}\s/.test(p) && !/^>/.test(p) && p !== parsed.title);
|
|
21609
|
+
const base = paragraph ? paragraph.replace(/\s+/g, " ") : parsed.title;
|
|
21610
|
+
return base.length > 280 ? `${base.slice(0, 277).trimEnd()}\u2026` : base;
|
|
21611
|
+
}
|
|
21581
21612
|
function normalizeImportFields(parsed, opts) {
|
|
21582
21613
|
const discardedFields = [];
|
|
21583
21614
|
for (const key of Object.keys(parsed.candidateFields)) {
|
|
21584
21615
|
if (LIFECYCLE_FIELDS.has(key)) discardedFields.push(key);
|
|
21585
21616
|
}
|
|
21586
21617
|
const type = opts.userType ? normalizeType(opts.userType) ?? "feature" : parsed.type ?? "feature";
|
|
21587
|
-
const
|
|
21588
|
-
|
|
21589
|
-
|
|
21618
|
+
const hasRealBody = !!parsed.body && parsed.body !== parsed.title;
|
|
21619
|
+
const intent = parsed.title;
|
|
21620
|
+
const body = hasRealBody ? parsed.body : void 0;
|
|
21621
|
+
const summary = hasRealBody ? deriveShortSummary(parsed) : parsed.title;
|
|
21590
21622
|
const source = {
|
|
21591
21623
|
type: opts.importSource === "chat" ? "chat" : "external",
|
|
21592
21624
|
imported_at: (/* @__PURE__ */ new Date()).toISOString().split("T")[0]
|
|
@@ -21594,14 +21626,14 @@ ${parsed.body}` : parsed.title;
|
|
|
21594
21626
|
source.source_format = opts.sourceFormat;
|
|
21595
21627
|
source.source_hash = opts.sourceHash;
|
|
21596
21628
|
const snapshot = { title: parsed.title };
|
|
21597
|
-
if (
|
|
21629
|
+
if (summary !== parsed.title) snapshot.description = summary;
|
|
21598
21630
|
if (typeof parsed.candidateFields.type === "string") snapshot.type = parsed.candidateFields.type;
|
|
21599
21631
|
if (typeof parsed.candidateFields.status === "string") snapshot.status = parsed.candidateFields.status;
|
|
21600
21632
|
if (Array.isArray(parsed.candidateFields.labels)) {
|
|
21601
21633
|
const labels = parsed.candidateFields.labels.filter((l) => typeof l === "string");
|
|
21602
21634
|
if (labels.length > 0) snapshot.labels = labels;
|
|
21603
21635
|
}
|
|
21604
|
-
return { type, intent, source, snapshot, discardedFields };
|
|
21636
|
+
return { type, intent, summary, body, source, snapshot, discardedFields };
|
|
21605
21637
|
}
|
|
21606
21638
|
function computeContentHash(raw) {
|
|
21607
21639
|
return crypto3.createHash("sha256").update(raw.trim(), "utf-8").digest("hex");
|
|
@@ -21679,7 +21711,7 @@ function importWorkItem(dir, opts) {
|
|
|
21679
21711
|
};
|
|
21680
21712
|
}
|
|
21681
21713
|
if (opts.onConflict === "replace") {
|
|
21682
|
-
|
|
21714
|
+
fs8.rmSync(existing.filePath, { force: true });
|
|
21683
21715
|
replacedWorkItem = existing.workItemId;
|
|
21684
21716
|
}
|
|
21685
21717
|
}
|
|
@@ -21687,6 +21719,8 @@ function importWorkItem(dir, opts) {
|
|
|
21687
21719
|
const result = createWorkItem(dir, {
|
|
21688
21720
|
intent: normalized.intent,
|
|
21689
21721
|
type: normalized.type,
|
|
21722
|
+
summary: normalized.summary,
|
|
21723
|
+
body: normalized.body,
|
|
21690
21724
|
source: normalized.source,
|
|
21691
21725
|
originalSnapshot: normalized.snapshot
|
|
21692
21726
|
});
|
|
@@ -22276,9 +22310,9 @@ function markRegistered(dir, identity) {
|
|
|
22276
22310
|
ensureDir(join(dir, TELEMETRY_DIR));
|
|
22277
22311
|
writeFile(identityPath(dir), JSON.stringify(identity, null, 2));
|
|
22278
22312
|
}
|
|
22279
|
-
function signPayload(identity, method,
|
|
22313
|
+
function signPayload(identity, method, path12, timestamp, nonce, bodySha256) {
|
|
22280
22314
|
const canonical = `${method}
|
|
22281
|
-
${
|
|
22315
|
+
${path12}
|
|
22282
22316
|
${identity.installationId}
|
|
22283
22317
|
${timestamp}
|
|
22284
22318
|
${nonce}
|
|
@@ -23089,8 +23123,8 @@ var capsuleCmd = program.command("capsule").description("Export this project as
|
|
|
23089
23123
|
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) => {
|
|
23090
23124
|
runCapsuleExport(opts);
|
|
23091
23125
|
});
|
|
23092
|
-
capsuleCmd.command("add <path>").description("Register an external Knowledge Capsule as project context (.kaddo/external.yml)").action((
|
|
23093
|
-
runCapsuleAdd(
|
|
23126
|
+
capsuleCmd.command("add <path>").description("Register an external Knowledge Capsule as project context (.kaddo/external.yml)").action((path12) => {
|
|
23127
|
+
runCapsuleAdd(path12);
|
|
23094
23128
|
});
|
|
23095
23129
|
var graphCmd = program.command("graph").description("Export the lightweight, file-based knowledge graph of the project");
|
|
23096
23130
|
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) => {
|