@kaddo/cli 3.115.0 → 3.116.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin-dist/assets/{architectureDiagram-3BPJPVTR-YcMJYo0g.js → architectureDiagram-3BPJPVTR-DP6srEcc.js} +1 -1
- package/dist/admin-dist/assets/{chunk-727SXJPM-BVnKaPXl.js → chunk-727SXJPM-DnQC9siX.js} +1 -1
- package/dist/admin-dist/assets/{chunk-AQP2D5EJ-D_Hcj3zm.js → chunk-AQP2D5EJ-BpyJpCJ-.js} +1 -1
- package/dist/admin-dist/assets/{classDiagram-v2-Q7XG4LA2-C1j2IJF8.js → classDiagram-4FO5ZUOK-CGoPFtaR.js} +1 -1
- package/dist/admin-dist/assets/{classDiagram-4FO5ZUOK-C1j2IJF8.js → classDiagram-v2-Q7XG4LA2-CGoPFtaR.js} +1 -1
- package/dist/admin-dist/assets/{dagre-BM42HDAG-ADdKf6j1.js → dagre-BM42HDAG-CRZz5h6U.js} +1 -1
- package/dist/admin-dist/assets/{diagram-2AECGRRQ-Z_xeHBlY.js → diagram-2AECGRRQ-2IUax-pn.js} +1 -1
- package/dist/admin-dist/assets/{diagram-5GNKFQAL-Wgzw55l3.js → diagram-5GNKFQAL-Dbar3g31.js} +1 -1
- package/dist/admin-dist/assets/{diagram-LMA3HP47-Dj6c7SSM.js → diagram-LMA3HP47-CDpppwwZ.js} +1 -1
- package/dist/admin-dist/assets/{diagram-OG6HWLK6-hHqRSSZr.js → diagram-OG6HWLK6-CxJNrhOa.js} +1 -1
- package/dist/admin-dist/assets/{erDiagram-TEJ5UH35-BTGBIaZr.js → erDiagram-TEJ5UH35-CqGkUDrY.js} +1 -1
- package/dist/admin-dist/assets/{flowDiagram-I6XJVG4X-RZJDjzR6.js → flowDiagram-I6XJVG4X-Dj-jj3Xs.js} +1 -1
- package/dist/admin-dist/assets/{ganttDiagram-6RSMTGT7-DI5Lr-xB.js → ganttDiagram-6RSMTGT7-BsslcFFi.js} +1 -1
- package/dist/admin-dist/assets/{index-RwMAZcWr.js → index-DVXcBuvj.js} +5 -5
- package/dist/admin-dist/assets/{infoDiagram-5YYISTIA-T5KZWjTy.js → infoDiagram-5YYISTIA-Bm8y-W5K.js} +1 -1
- package/dist/admin-dist/assets/{ishikawaDiagram-YF4QCWOH-C6Gyb7TQ.js → ishikawaDiagram-YF4QCWOH-B1q-JfoS.js} +1 -1
- package/dist/admin-dist/assets/{kanban-definition-UN3LZRKU-Dg8kSuqH.js → kanban-definition-UN3LZRKU-iEF70R2u.js} +1 -1
- package/dist/admin-dist/assets/{linear-NG3wfuct.js → linear-Cp_M7piX.js} +1 -1
- package/dist/admin-dist/assets/{mindmap-definition-RKZ34NQL-B1dMo93T.js → mindmap-definition-RKZ34NQL-IS3zSxy4.js} +1 -1
- package/dist/admin-dist/assets/{pieDiagram-4H26LBE5-iIbw9aCq.js → pieDiagram-4H26LBE5-FRW3jbwa.js} +1 -1
- package/dist/admin-dist/assets/{quadrantDiagram-W4KKPZXB-CBsaVubF.js → quadrantDiagram-W4KKPZXB-BWvrA0U2.js} +1 -1
- package/dist/admin-dist/assets/{requirementDiagram-4Y6WPE33-CobNACNF.js → requirementDiagram-4Y6WPE33-BDo5C4-W.js} +1 -1
- package/dist/admin-dist/assets/{sequenceDiagram-3UESZ5HK-CpE56jux.js → sequenceDiagram-3UESZ5HK-BqkNcdXk.js} +1 -1
- package/dist/admin-dist/assets/{stateDiagram-AJRCARHV-pSzN5IAu.js → stateDiagram-AJRCARHV-BPRhmY_L.js} +1 -1
- package/dist/admin-dist/assets/{stateDiagram-v2-BHNVJYJU-LhQFrdKp.js → stateDiagram-v2-BHNVJYJU-DqC9KnuP.js} +1 -1
- package/dist/admin-dist/assets/{timeline-definition-PNZ67QCA-q4yUdZjI.js → timeline-definition-PNZ67QCA-BKU6Xg5t.js} +1 -1
- package/dist/admin-dist/assets/{vennDiagram-CIIHVFJN-D5DxPuNK.js → vennDiagram-CIIHVFJN-BRePJms1.js} +1 -1
- package/dist/admin-dist/assets/{wardleyDiagram-YWT4CUSO-451b1uEN.js → wardleyDiagram-YWT4CUSO-BZP5Do-p.js} +1 -1
- package/dist/admin-dist/assets/{xychartDiagram-2RQKCTM6-DnOwq6Mk.js → xychartDiagram-2RQKCTM6-Cf0SjuRr.js} +1 -1
- package/dist/admin-dist/index.html +1 -1
- package/dist/admin-server/index.js +88 -0
- package/dist/core.js +284 -85
- package/dist/index.js +431 -99
- package/package.json +1 -1
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 path13 = i.path.join(".");
|
|
1394
|
+
return path13 ? ` - ${path13}: ${i.message}` : ` - ${i.message}`;
|
|
1395
1395
|
}).join("\n");
|
|
1396
1396
|
throw new ConfigError(`Invalid .kaddo/config.yml:
|
|
1397
1397
|
${issues}`);
|
|
@@ -3685,6 +3685,16 @@ supporting notes as \`knowledge/tech/discovery/architecture-notes.md\` and decis
|
|
|
3685
3685
|
under \`knowledge/tech/decisions/\`. Kaddo still reads the legacy root locations for backward
|
|
3686
3686
|
compatibility, but new output should use \`discovery/\`.
|
|
3687
3687
|
|
|
3688
|
+
## Project Resource candidates
|
|
3689
|
+
|
|
3690
|
+
When the knowledge describes an external system the project depends on (a database, cloud account,
|
|
3691
|
+
API, queue, storage, service\u2026), you may propose it as a **candidate** Project Resource \u2014 never create
|
|
3692
|
+
it silently. Discovery \u2260 creation: present candidates for human review and materialize only through
|
|
3693
|
+
\`kaddo_create_resource\` / \`kaddo resources create\` with explicit confirmation. Ground every
|
|
3694
|
+
candidate in the knowledge (no guessing from ambiguous names). Model the stable system, not its access
|
|
3695
|
+
interface (CLI/MCP/SQL/API are interfaces); keep \`resources\` separate from \`affected_modules\`; and
|
|
3696
|
+
never include secret values \u2014 only reference names.
|
|
3697
|
+
|
|
3688
3698
|
## Quality Checklist
|
|
3689
3699
|
|
|
3690
3700
|
- Every component is backed by evidence from the context pack.
|
|
@@ -6449,8 +6459,8 @@ async function runCreate(type, opts = {}) {
|
|
|
6449
6459
|
answers[question.frontMatterField] = answer.trim();
|
|
6450
6460
|
}
|
|
6451
6461
|
const id = nextWorkItemId(dir);
|
|
6452
|
-
const
|
|
6453
|
-
const fileName = `${id}-${
|
|
6462
|
+
const slug5 = slugify(title);
|
|
6463
|
+
const fileName = `${id}-${slug5}.md`;
|
|
6454
6464
|
const filePath = join(dir, DRAFT_DIR, fileName);
|
|
6455
6465
|
const frontMatter2 = buildFrontMatter(id, workItemType, level, title.trim(), answers);
|
|
6456
6466
|
const body = buildBody(workItemType, level, title.trim(), answers, levelDef.qualityGate);
|
|
@@ -6483,8 +6493,8 @@ async function runCreateModule(dir, modType) {
|
|
|
6483
6493
|
answers[q.frontMatterField] = answer.trim();
|
|
6484
6494
|
}
|
|
6485
6495
|
const id = nextWorkItemId(dir);
|
|
6486
|
-
const
|
|
6487
|
-
const fileName = `${id}-${
|
|
6496
|
+
const slug5 = slugify(title);
|
|
6497
|
+
const fileName = `${id}-${slug5}.md`;
|
|
6488
6498
|
const filePath = join(dir, DRAFT_DIR, fileName);
|
|
6489
6499
|
const frontMatter2 = buildModuleFrontMatter(id, modType, title.trim(), answers);
|
|
6490
6500
|
const body = buildModuleBody(modType, title.trim(), answers);
|
|
@@ -6649,8 +6659,8 @@ function buildRoadmapWorkItem(opts) {
|
|
|
6649
6659
|
const { id, type, level, candidate } = opts;
|
|
6650
6660
|
const answers = opts.answers ?? {};
|
|
6651
6661
|
const title = candidate.title.trim();
|
|
6652
|
-
const
|
|
6653
|
-
const fileName = `${id}-${
|
|
6662
|
+
const slug5 = slugify(title);
|
|
6663
|
+
const fileName = `${id}-${slug5}.md`;
|
|
6654
6664
|
const qualityGate = getLevel(level).qualityGate;
|
|
6655
6665
|
const frontMatter2 = buildRoadmapFrontMatter(id, type, level, title, candidate, answers);
|
|
6656
6666
|
const body = buildRoadmapBody(type, level, title, candidate, answers, qualityGate);
|
|
@@ -7051,10 +7061,10 @@ function analyzeGuard(touchedFiles, artifacts, silentWithoutOwnership) {
|
|
|
7051
7061
|
import { parse as parseYaml5, stringify as stringifyYaml3 } from "yaml";
|
|
7052
7062
|
var IGNORE_FILE = ".kaddo/ignores.yml";
|
|
7053
7063
|
function loadIgnores(dir) {
|
|
7054
|
-
const
|
|
7055
|
-
if (!exists(
|
|
7064
|
+
const path13 = join(dir, IGNORE_FILE);
|
|
7065
|
+
if (!exists(path13)) return [];
|
|
7056
7066
|
try {
|
|
7057
|
-
const raw = readFile(
|
|
7067
|
+
const raw = readFile(path13);
|
|
7058
7068
|
const parsed = parseYaml5(raw);
|
|
7059
7069
|
return Array.isArray(parsed) ? parsed : [];
|
|
7060
7070
|
} catch {
|
|
@@ -7062,7 +7072,7 @@ function loadIgnores(dir) {
|
|
|
7062
7072
|
}
|
|
7063
7073
|
}
|
|
7064
7074
|
function saveIgnore(dir, entry) {
|
|
7065
|
-
const
|
|
7075
|
+
const path13 = join(dir, IGNORE_FILE);
|
|
7066
7076
|
const existing = loadIgnores(dir);
|
|
7067
7077
|
const idx = existing.findIndex((e) => e.artifact_id === entry.artifact_id);
|
|
7068
7078
|
if (idx >= 0) {
|
|
@@ -7070,17 +7080,17 @@ function saveIgnore(dir, entry) {
|
|
|
7070
7080
|
} else {
|
|
7071
7081
|
existing.push(entry);
|
|
7072
7082
|
}
|
|
7073
|
-
writeFile(
|
|
7083
|
+
writeFile(path13, stringifyYaml3(existing));
|
|
7074
7084
|
}
|
|
7075
7085
|
function isIgnored(ignores, artifactId) {
|
|
7076
7086
|
return ignores.find((e) => e.artifact_id === artifactId);
|
|
7077
7087
|
}
|
|
7078
7088
|
function removeIgnore(dir, artifactId) {
|
|
7079
|
-
const
|
|
7089
|
+
const path13 = join(dir, IGNORE_FILE);
|
|
7080
7090
|
const existing = loadIgnores(dir);
|
|
7081
7091
|
const filtered = existing.filter((e) => e.artifact_id !== artifactId);
|
|
7082
7092
|
if (filtered.length === existing.length) return false;
|
|
7083
|
-
writeFile(
|
|
7093
|
+
writeFile(path13, stringifyYaml3(filtered));
|
|
7084
7094
|
return true;
|
|
7085
7095
|
}
|
|
7086
7096
|
|
|
@@ -7102,11 +7112,11 @@ function moduleArtifactCoverage(dir, id) {
|
|
|
7102
7112
|
};
|
|
7103
7113
|
}
|
|
7104
7114
|
function loadMappedModules(dir) {
|
|
7105
|
-
const
|
|
7106
|
-
if (!exists(
|
|
7115
|
+
const path13 = join(dir, DESCRIPTOR_PATH);
|
|
7116
|
+
if (!exists(path13)) return [];
|
|
7107
7117
|
let parsed;
|
|
7108
7118
|
try {
|
|
7109
|
-
parsed = parseYaml6(readFile(
|
|
7119
|
+
parsed = parseYaml6(readFile(path13));
|
|
7110
7120
|
} catch {
|
|
7111
7121
|
return [];
|
|
7112
7122
|
}
|
|
@@ -7850,7 +7860,7 @@ function buildGuardHistory(dir) {
|
|
|
7850
7860
|
const d = hotspotDir(t.code_path);
|
|
7851
7861
|
hotspotMap.set(d, (hotspotMap.get(d) ?? 0) + 1);
|
|
7852
7862
|
}
|
|
7853
|
-
const hotspots = [...hotspotMap.entries()].map(([
|
|
7863
|
+
const hotspots = [...hotspotMap.entries()].map(([path13, warnings]) => ({ path: path13, warnings })).sort((a, b) => b.warnings - a.warnings);
|
|
7854
7864
|
return {
|
|
7855
7865
|
available: true,
|
|
7856
7866
|
total_runs: sorted.length,
|
|
@@ -10488,10 +10498,10 @@ function slugify2(name) {
|
|
|
10488
10498
|
return name.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
10489
10499
|
}
|
|
10490
10500
|
function readModulesDescriptor(dir) {
|
|
10491
|
-
const
|
|
10492
|
-
if (!exists(
|
|
10501
|
+
const path13 = join(dir, DESCRIPTOR_PATH2);
|
|
10502
|
+
if (!exists(path13)) return { version: 1, modules: [] };
|
|
10493
10503
|
try {
|
|
10494
|
-
const parsed = parseYaml10(readFile(
|
|
10504
|
+
const parsed = parseYaml10(readFile(path13));
|
|
10495
10505
|
return { version: parsed.version ?? 1, modules: parsed.modules ?? [] };
|
|
10496
10506
|
} catch {
|
|
10497
10507
|
return { version: 1, modules: [] };
|
|
@@ -10871,7 +10881,7 @@ function sectionParagraph(md, title) {
|
|
|
10871
10881
|
}
|
|
10872
10882
|
return "";
|
|
10873
10883
|
}
|
|
10874
|
-
function parseCapsule(id,
|
|
10884
|
+
function parseCapsule(id, path13, md) {
|
|
10875
10885
|
const { data } = matter3(md);
|
|
10876
10886
|
const updatedAt = data.updated_at ? String(data.updated_at) : void 0;
|
|
10877
10887
|
let ageDays = null;
|
|
@@ -10881,7 +10891,7 @@ function parseCapsule(id, path12, md) {
|
|
|
10881
10891
|
}
|
|
10882
10892
|
return {
|
|
10883
10893
|
id,
|
|
10884
|
-
path:
|
|
10894
|
+
path: path13,
|
|
10885
10895
|
system: data.system ? String(data.system) : id,
|
|
10886
10896
|
owner: data.owner ? String(data.owner) : void 0,
|
|
10887
10897
|
updatedAt,
|
|
@@ -11107,6 +11117,18 @@ function computeInitiativeProgress(dir, ini) {
|
|
|
11107
11117
|
// src/core/resources.ts
|
|
11108
11118
|
import matter5 from "gray-matter";
|
|
11109
11119
|
var RESOURCE_ARTIFACT_TYPE = "project-resource";
|
|
11120
|
+
var RESOURCE_TYPES = [
|
|
11121
|
+
"database",
|
|
11122
|
+
"cloud",
|
|
11123
|
+
"api",
|
|
11124
|
+
"queue",
|
|
11125
|
+
"storage",
|
|
11126
|
+
"repository",
|
|
11127
|
+
"platform",
|
|
11128
|
+
"service",
|
|
11129
|
+
"other"
|
|
11130
|
+
];
|
|
11131
|
+
var INTERFACE_TYPES = ["cli", "mcp", "api", "sql", "sdk", "iac", "console", "other"];
|
|
11110
11132
|
function str(v) {
|
|
11111
11133
|
return typeof v === "string" && v.trim() ? v.trim() : null;
|
|
11112
11134
|
}
|
|
@@ -11150,6 +11172,18 @@ function parseAuth(v) {
|
|
|
11150
11172
|
const refs = strArray(o.refs).filter((r) => !r.includes("=") && /^[A-Za-z0-9_.-]+$/.test(r));
|
|
11151
11173
|
return { mode: str(o.mode), refs };
|
|
11152
11174
|
}
|
|
11175
|
+
function parseScope(v) {
|
|
11176
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return null;
|
|
11177
|
+
const o = v;
|
|
11178
|
+
const type = str(o.type);
|
|
11179
|
+
if (!type) return null;
|
|
11180
|
+
return { type, module: str(o.module) };
|
|
11181
|
+
}
|
|
11182
|
+
function purposeFromBody(body) {
|
|
11183
|
+
const m = body.match(/^#{1,2}\s+Purpose\s*\n+([\s\S]*?)(?=\n#{1,2}\s|\s*$)/m);
|
|
11184
|
+
const text2 = m ? m[1].trim() : "";
|
|
11185
|
+
return text2 || null;
|
|
11186
|
+
}
|
|
11153
11187
|
function toDetail(filePath, relPath, raw) {
|
|
11154
11188
|
const parsed = matter5(raw);
|
|
11155
11189
|
const fm2 = parsed.data ?? {};
|
|
@@ -11161,8 +11195,10 @@ function toDetail(filePath, relPath, raw) {
|
|
|
11161
11195
|
resourceType: str(fm2.resource_type),
|
|
11162
11196
|
provider: str(fm2.provider),
|
|
11163
11197
|
environments: strArray(fm2.environments),
|
|
11198
|
+
scope: parseScope(fm2.scope),
|
|
11199
|
+
modules: strArray(fm2.modules),
|
|
11164
11200
|
path: relPath,
|
|
11165
|
-
purpose: str(fm2.purpose),
|
|
11201
|
+
purpose: str(fm2.purpose) ?? purposeFromBody(body),
|
|
11166
11202
|
interfaces: parseInterfaces(fm2.access_interfaces),
|
|
11167
11203
|
boundaries: parseBoundaries(fm2.access_boundaries),
|
|
11168
11204
|
...(() => {
|
|
@@ -11181,6 +11217,8 @@ function getResources(dir) {
|
|
|
11181
11217
|
resourceType: str(fm2.resource_type),
|
|
11182
11218
|
provider: str(fm2.provider),
|
|
11183
11219
|
environments: strArray(fm2.environments),
|
|
11220
|
+
scope: parseScope(fm2.scope),
|
|
11221
|
+
modules: strArray(fm2.modules),
|
|
11184
11222
|
path: a.relPath
|
|
11185
11223
|
};
|
|
11186
11224
|
}).sort((x, y) => x.id.localeCompare(y.id));
|
|
@@ -11251,9 +11289,9 @@ function buildGraph(dir, config, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
11251
11289
|
];
|
|
11252
11290
|
const presentLayers = [];
|
|
11253
11291
|
for (const layer2 of layerDocs) {
|
|
11254
|
-
const
|
|
11255
|
-
if (
|
|
11256
|
-
addNode({ id: layer2.id, type: layer2.type, label: layer2.label, path:
|
|
11292
|
+
const path13 = layer2.files.map((f) => `${KNOWLEDGE3}/${f}`).find((rel) => exists(join(dir, rel)));
|
|
11293
|
+
if (path13) {
|
|
11294
|
+
addNode({ id: layer2.id, type: layer2.type, label: layer2.label, path: path13 });
|
|
11257
11295
|
presentLayers.push(layer2.id);
|
|
11258
11296
|
}
|
|
11259
11297
|
}
|
|
@@ -11296,12 +11334,20 @@ function buildGraph(dir, config, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
11296
11334
|
const resourceTitleById = /* @__PURE__ */ new Map();
|
|
11297
11335
|
for (const r of getResources(dir)) {
|
|
11298
11336
|
resourceTitleById.set(r.id, r.title);
|
|
11337
|
+
const resId = `resource:${r.id}`;
|
|
11299
11338
|
addNode({
|
|
11300
|
-
id:
|
|
11339
|
+
id: resId,
|
|
11301
11340
|
type: "project-resource",
|
|
11302
11341
|
label: r.title ? `${r.id} ${r.title}`.trim() : r.id,
|
|
11303
11342
|
path: r.path
|
|
11304
11343
|
});
|
|
11344
|
+
const depModules = new Set(r.modules);
|
|
11345
|
+
if (r.scope?.type === "module" && r.scope.module) depModules.add(r.scope.module);
|
|
11346
|
+
for (const mod of depModules) {
|
|
11347
|
+
const modId = `module:${mod}`;
|
|
11348
|
+
addNode({ id: modId, type: "module", label: mod });
|
|
11349
|
+
addEdge(modId, resId, "depends_on");
|
|
11350
|
+
}
|
|
11305
11351
|
}
|
|
11306
11352
|
for (const wi of selectedWIs) {
|
|
11307
11353
|
const id = wi.id || wi.title;
|
|
@@ -12832,10 +12878,10 @@ function resolveNextStep(dir, now = /* @__PURE__ */ new Date()) {
|
|
|
12832
12878
|
const q = (rel) => analyzeKnowledgeArtifact(dir, rel);
|
|
12833
12879
|
const resolveAgent = (agent) => {
|
|
12834
12880
|
const file = agent.endsWith(".md") ? agent : `${agent}.md`;
|
|
12835
|
-
const
|
|
12836
|
-
const installed = isFile(join(dir,
|
|
12881
|
+
const path13 = agentInstallPath(file);
|
|
12882
|
+
const installed = isFile(join(dir, path13));
|
|
12837
12883
|
const group = agentGroupOf(file);
|
|
12838
|
-
return { agentPath:
|
|
12884
|
+
return { agentPath: path13, agentInstalled: installed, installCommand: installed ? void 0 : `kaddo add agents --group ${group}` };
|
|
12839
12885
|
};
|
|
12840
12886
|
const moduleRepo = isModule(config);
|
|
12841
12887
|
const coreRepo = isCore(config);
|
|
@@ -18142,7 +18188,171 @@ async function runTopologyApply(file, opts = {}) {
|
|
|
18142
18188
|
}
|
|
18143
18189
|
}
|
|
18144
18190
|
|
|
18191
|
+
// src/core/resource-write.ts
|
|
18192
|
+
import fs5 from "fs";
|
|
18193
|
+
import path9 from "path";
|
|
18194
|
+
import matter12 from "gray-matter";
|
|
18195
|
+
var RESOURCES_DIR = "knowledge/tech/resources";
|
|
18196
|
+
var ResourceWriteError = class extends Error {
|
|
18197
|
+
constructor(code, message) {
|
|
18198
|
+
super(message);
|
|
18199
|
+
this.code = code;
|
|
18200
|
+
this.name = "ResourceWriteError";
|
|
18201
|
+
}
|
|
18202
|
+
code;
|
|
18203
|
+
};
|
|
18204
|
+
function slug4(s) {
|
|
18205
|
+
return s.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
|
|
18206
|
+
}
|
|
18207
|
+
function atomicWrite2(filePath, content) {
|
|
18208
|
+
const tmp = `${filePath}.tmp-${process.pid}-${Date.now()}`;
|
|
18209
|
+
fs5.writeFileSync(tmp, content, "utf-8");
|
|
18210
|
+
fs5.renameSync(tmp, filePath);
|
|
18211
|
+
}
|
|
18212
|
+
function sanitizeRefs(refs) {
|
|
18213
|
+
if (!Array.isArray(refs)) return [];
|
|
18214
|
+
return refs.map((r) => String(r).trim()).filter((r) => r && !r.includes("=") && /^[A-Za-z0-9_.-]+$/.test(r));
|
|
18215
|
+
}
|
|
18216
|
+
function allResourceArtifacts(dir) {
|
|
18217
|
+
return discoverKnowledge(dir).filter((a) => a.type === RESOURCE_ARTIFACT_TYPE);
|
|
18218
|
+
}
|
|
18219
|
+
function nextResourceId(dir, title, explicit) {
|
|
18220
|
+
const existing = new Set(allResourceArtifacts(dir).map((a) => (a.id || "").toUpperCase()));
|
|
18221
|
+
if (explicit && explicit.trim()) return explicit.trim();
|
|
18222
|
+
const base = `RES-${slug4(title) || "resource"}`;
|
|
18223
|
+
if (!existing.has(base.toUpperCase())) return base;
|
|
18224
|
+
for (let i = 2; i < 1e3; i++) {
|
|
18225
|
+
const candidate = `${base}-${i}`;
|
|
18226
|
+
if (!existing.has(candidate.toUpperCase())) return candidate;
|
|
18227
|
+
}
|
|
18228
|
+
throw new ResourceWriteError("ID_EXHAUSTED", `Could not derive a unique id for "${title}".`);
|
|
18229
|
+
}
|
|
18230
|
+
function validateResource(dir, input) {
|
|
18231
|
+
const findings = [];
|
|
18232
|
+
if (input.resourceType && !RESOURCE_TYPES.includes(input.resourceType)) {
|
|
18233
|
+
findings.push({ level: "warning", message: `Unknown resource_type "${input.resourceType}" (not in the known set).` });
|
|
18234
|
+
}
|
|
18235
|
+
for (const i of input.accessInterfaces ?? []) {
|
|
18236
|
+
if (i.type && !INTERFACE_TYPES.includes(i.type)) {
|
|
18237
|
+
findings.push({ level: "warning", message: `Unknown access interface type "${i.type}".` });
|
|
18238
|
+
}
|
|
18239
|
+
}
|
|
18240
|
+
const mapped = loadMappedModules(dir).map((m) => m.id);
|
|
18241
|
+
if (mapped.length > 0) {
|
|
18242
|
+
const refs = /* @__PURE__ */ new Set();
|
|
18243
|
+
if (input.scope?.type === "module" && input.scope.module) refs.add(input.scope.module);
|
|
18244
|
+
for (const m of input.modules ?? []) refs.add(m);
|
|
18245
|
+
for (const m of refs) {
|
|
18246
|
+
if (!mapped.includes(m)) findings.push({ level: "warning", message: `Module "${m}" is not in .kaddo/modules.yml.` });
|
|
18247
|
+
}
|
|
18248
|
+
}
|
|
18249
|
+
if (input.scope && input.scope.type === "module" && !input.scope.module) {
|
|
18250
|
+
findings.push({ level: "error", message: 'scope.type "module" requires a module id.' });
|
|
18251
|
+
}
|
|
18252
|
+
return findings;
|
|
18253
|
+
}
|
|
18254
|
+
function buildFrontmatter(id, input, base = {}) {
|
|
18255
|
+
const data = { ...base };
|
|
18256
|
+
data.type = RESOURCE_ARTIFACT_TYPE;
|
|
18257
|
+
data.id = id;
|
|
18258
|
+
if (input.title != null) data.title = input.title;
|
|
18259
|
+
if (input.resourceType != null) data.resource_type = input.resourceType;
|
|
18260
|
+
if (input.provider != null) data.provider = input.provider;
|
|
18261
|
+
if (input.environments != null) data.environments = input.environments;
|
|
18262
|
+
if (input.scope != null) data.scope = input.scope.module ? { type: input.scope.type, module: input.scope.module } : { type: input.scope.type };
|
|
18263
|
+
if (input.modules != null) data.modules = input.modules;
|
|
18264
|
+
if (input.accessInterfaces != null) data.access_interfaces = input.accessInterfaces;
|
|
18265
|
+
if (input.accessBoundaries != null) data.access_boundaries = input.accessBoundaries;
|
|
18266
|
+
if (input.authentication != null) {
|
|
18267
|
+
const mode = input.authentication.mode;
|
|
18268
|
+
const refs = sanitizeRefs(input.authentication.refs);
|
|
18269
|
+
data.authentication = { ...mode ? { mode } : {}, ...refs.length ? { refs } : {} };
|
|
18270
|
+
}
|
|
18271
|
+
return data;
|
|
18272
|
+
}
|
|
18273
|
+
function serialize(data, body) {
|
|
18274
|
+
return matter12.stringify(`
|
|
18275
|
+
${body.trim()}
|
|
18276
|
+
`, data);
|
|
18277
|
+
}
|
|
18278
|
+
function createResource(dir, input) {
|
|
18279
|
+
const title = (input.title ?? "").trim();
|
|
18280
|
+
if (!title) throw new ResourceWriteError("INVALID_INPUT", "A resource title is required.");
|
|
18281
|
+
const resourceType = (input.resourceType ?? "").trim();
|
|
18282
|
+
if (!resourceType) throw new ResourceWriteError("INVALID_INPUT", "A resource_type is required.");
|
|
18283
|
+
const findings = validateResource(dir, input);
|
|
18284
|
+
if (findings.some((f) => f.level === "error")) {
|
|
18285
|
+
throw new ResourceWriteError("VALIDATION_FAILED", findings.filter((f) => f.level === "error").map((f) => f.message).join("; "));
|
|
18286
|
+
}
|
|
18287
|
+
const existing = allResourceArtifacts(dir);
|
|
18288
|
+
if (input.id && existing.some((a) => (a.id || "").toUpperCase() === input.id.toUpperCase())) {
|
|
18289
|
+
throw new ResourceWriteError("DUPLICATE", `A resource with id "${input.id}" already exists.`);
|
|
18290
|
+
}
|
|
18291
|
+
if (existing.some((a) => (a.title || "").toLowerCase() === title.toLowerCase())) {
|
|
18292
|
+
throw new ResourceWriteError("DUPLICATE", `A resource titled "${title}" already exists.`);
|
|
18293
|
+
}
|
|
18294
|
+
const id = nextResourceId(dir, title, input.id);
|
|
18295
|
+
const data = buildFrontmatter(id, input);
|
|
18296
|
+
const body = `# Purpose
|
|
18297
|
+
|
|
18298
|
+
${(input.purpose ?? "").trim() || "TODO: describe what this resource is for."}`;
|
|
18299
|
+
const relPath = `${RESOURCES_DIR}/${slug4(title) || slug4(id)}.md`;
|
|
18300
|
+
const filePath = join(dir, relPath);
|
|
18301
|
+
if (exists(filePath)) throw new ResourceWriteError("DUPLICATE", `Resource file already exists: ${relPath}`);
|
|
18302
|
+
ensureDir(path9.dirname(filePath));
|
|
18303
|
+
atomicWrite2(filePath, serialize(data, body));
|
|
18304
|
+
return { id, path: relPath, findings };
|
|
18305
|
+
}
|
|
18306
|
+
function updateResource(dir, id, input) {
|
|
18307
|
+
const match = allResourceArtifacts(dir).find((a) => a.id === id || a.title === id);
|
|
18308
|
+
if (!match) throw new ResourceWriteError("NOT_FOUND", `Project Resource "${id}" not found.`);
|
|
18309
|
+
const findings = validateResource(dir, input);
|
|
18310
|
+
if (findings.some((f) => f.level === "error")) {
|
|
18311
|
+
throw new ResourceWriteError("VALIDATION_FAILED", findings.filter((f) => f.level === "error").map((f) => f.message).join("; "));
|
|
18312
|
+
}
|
|
18313
|
+
const raw = readFile(match.filePath);
|
|
18314
|
+
const parsed = matter12(raw);
|
|
18315
|
+
const base = parsed.data ?? {};
|
|
18316
|
+
const data = buildFrontmatter(match.id || id, input, base);
|
|
18317
|
+
let body = parsed.content.trim();
|
|
18318
|
+
if (input.purpose != null) {
|
|
18319
|
+
const purpose = `# Purpose
|
|
18320
|
+
|
|
18321
|
+
${input.purpose.trim()}`;
|
|
18322
|
+
body = /^#\s+Purpose/m.test(body) ? body.replace(/#\s+Purpose[\s\S]*?(?=\n#\s|\n*$)/, purpose + "\n") : `${purpose}
|
|
18323
|
+
|
|
18324
|
+
${body}`.trim();
|
|
18325
|
+
}
|
|
18326
|
+
atomicWrite2(match.filePath, serialize(data, body));
|
|
18327
|
+
return { id: match.id || id, path: match.relPath, findings };
|
|
18328
|
+
}
|
|
18329
|
+
function getResourceReferences(dir, id) {
|
|
18330
|
+
const refs = [];
|
|
18331
|
+
for (const wi of discoverWorkItems(dir)) {
|
|
18332
|
+
for (const rel of parseWorkItemResources(wi.rawFrontmatter)) {
|
|
18333
|
+
if (rel.id === id) refs.push({ kind: "work-item", id: wi.id || wi.title, role: rel.role, path: wi.relPath });
|
|
18334
|
+
}
|
|
18335
|
+
}
|
|
18336
|
+
return refs;
|
|
18337
|
+
}
|
|
18338
|
+
function deleteResource(dir, id, opts = {}) {
|
|
18339
|
+
const match = allResourceArtifacts(dir).find((a) => a.id === id || a.title === id);
|
|
18340
|
+
if (!match) throw new ResourceWriteError("NOT_FOUND", `Project Resource "${id}" not found.`);
|
|
18341
|
+
const references = getResourceReferences(dir, match.id || id);
|
|
18342
|
+
if (!opts.confirm) {
|
|
18343
|
+
return { deleted: false, preview: { id: match.id || id, references } };
|
|
18344
|
+
}
|
|
18345
|
+
fs5.rmSync(match.filePath, { force: true });
|
|
18346
|
+
return { deleted: true, path: match.relPath };
|
|
18347
|
+
}
|
|
18348
|
+
|
|
18145
18349
|
// src/commands/resources.ts
|
|
18350
|
+
function printFindings2(findings) {
|
|
18351
|
+
for (const f of findings) {
|
|
18352
|
+
if (f.level === "error") log.error(f.message);
|
|
18353
|
+
else log.warn(f.message);
|
|
18354
|
+
}
|
|
18355
|
+
}
|
|
18146
18356
|
function runResourcesList(dir = cwd(), opts = {}) {
|
|
18147
18357
|
const resources = getResources(dir);
|
|
18148
18358
|
if (opts.json) {
|
|
@@ -18219,16 +18429,131 @@ function runResourcesGet(id, dir = cwd(), opts = {}) {
|
|
|
18219
18429
|
}
|
|
18220
18430
|
console.log("");
|
|
18221
18431
|
}
|
|
18432
|
+
async function runResourcesCreate(opts = {}, dir = cwd()) {
|
|
18433
|
+
let title = opts.title?.trim();
|
|
18434
|
+
let type = opts.type?.trim();
|
|
18435
|
+
let provider = opts.provider?.trim();
|
|
18436
|
+
let scopeType = opts.scope?.trim() || (opts.module ? "module" : "system");
|
|
18437
|
+
let moduleId = opts.module?.trim();
|
|
18438
|
+
const interactive = !opts.json && process.stdin.isTTY && (!title || !type);
|
|
18439
|
+
if (interactive) {
|
|
18440
|
+
intro("kaddo resources create");
|
|
18441
|
+
if (!title) title = (await text({ message: "Resource name", placeholder: "Supabase Main" })).trim();
|
|
18442
|
+
if (!type) type = await select({
|
|
18443
|
+
message: "Resource type",
|
|
18444
|
+
options: ["database", "cloud", "api", "queue", "storage", "repository", "platform", "service", "other"].map((v) => ({ value: v, label: v }))
|
|
18445
|
+
});
|
|
18446
|
+
if (!provider) provider = (await text({ message: "Provider (optional)", placeholder: "supabase", defaultValue: "" })).trim() || void 0;
|
|
18447
|
+
scopeType = await select({ message: "Scope", options: [{ value: "system", label: "system" }, { value: "module", label: "module" }] });
|
|
18448
|
+
if (scopeType === "module") moduleId = (await text({ message: "Module id", placeholder: "orders-api" })).trim();
|
|
18449
|
+
}
|
|
18450
|
+
if (!title || !type) {
|
|
18451
|
+
console.error("A resource title and type are required. Use --title and --type (or run interactively).");
|
|
18452
|
+
process.exit(1);
|
|
18453
|
+
}
|
|
18454
|
+
const input = { title, resourceType: type };
|
|
18455
|
+
if (provider) input.provider = provider;
|
|
18456
|
+
input.scope = scopeType === "module" ? { type: "module", module: moduleId } : { type: "system" };
|
|
18457
|
+
try {
|
|
18458
|
+
const res = createResource(dir, input);
|
|
18459
|
+
if (opts.json) {
|
|
18460
|
+
console.log(JSON.stringify(res, null, 2));
|
|
18461
|
+
return;
|
|
18462
|
+
}
|
|
18463
|
+
printFindings2(res.findings);
|
|
18464
|
+
log.success(`Created ${res.id}`);
|
|
18465
|
+
if (interactive) outro(`Resource created at ${res.path}. Enrich it with \`kaddo resources update ${res.id}\`.`);
|
|
18466
|
+
else {
|
|
18467
|
+
console.log(` ${res.path}`);
|
|
18468
|
+
console.log(` Enrich it later with: kaddo resources update ${res.id}`);
|
|
18469
|
+
}
|
|
18470
|
+
} catch (err) {
|
|
18471
|
+
console.error(err instanceof ResourceWriteError ? err.message : String(err));
|
|
18472
|
+
process.exit(1);
|
|
18473
|
+
}
|
|
18474
|
+
}
|
|
18475
|
+
function runResourcesUpdate(id, opts = {}, dir = cwd()) {
|
|
18476
|
+
const input = {};
|
|
18477
|
+
if (opts.title != null) input.title = opts.title;
|
|
18478
|
+
if (opts.type != null) input.resourceType = opts.type;
|
|
18479
|
+
if (opts.provider != null) input.provider = opts.provider;
|
|
18480
|
+
if (opts.purpose != null) input.purpose = opts.purpose;
|
|
18481
|
+
if (opts.scope != null || opts.module != null) {
|
|
18482
|
+
const scopeType = opts.scope || (opts.module ? "module" : "system");
|
|
18483
|
+
input.scope = scopeType === "module" ? { type: "module", module: opts.module } : { type: "system" };
|
|
18484
|
+
}
|
|
18485
|
+
if (Object.keys(input).length === 0) {
|
|
18486
|
+
console.error("Nothing to update. Pass at least one field (e.g. --provider, --purpose, --module).");
|
|
18487
|
+
process.exit(1);
|
|
18488
|
+
}
|
|
18489
|
+
try {
|
|
18490
|
+
const res = updateResource(dir, id, input);
|
|
18491
|
+
if (opts.json) {
|
|
18492
|
+
console.log(JSON.stringify(res, null, 2));
|
|
18493
|
+
return;
|
|
18494
|
+
}
|
|
18495
|
+
printFindings2(res.findings);
|
|
18496
|
+
console.log(`Updated ${res.id} (${res.path}).`);
|
|
18497
|
+
} catch (err) {
|
|
18498
|
+
console.error(err instanceof ResourceWriteError ? err.message : String(err));
|
|
18499
|
+
process.exit(1);
|
|
18500
|
+
}
|
|
18501
|
+
}
|
|
18502
|
+
async function runResourcesDelete(id, opts = {}, dir = cwd()) {
|
|
18503
|
+
let preview;
|
|
18504
|
+
try {
|
|
18505
|
+
preview = deleteResource(dir, id);
|
|
18506
|
+
} catch (err) {
|
|
18507
|
+
console.error(err instanceof ResourceWriteError ? err.message : String(err));
|
|
18508
|
+
process.exit(1);
|
|
18509
|
+
}
|
|
18510
|
+
const refs = preview.preview?.references ?? [];
|
|
18511
|
+
if (opts.json && !opts.yes) {
|
|
18512
|
+
console.log(JSON.stringify(preview.preview, null, 2));
|
|
18513
|
+
return;
|
|
18514
|
+
}
|
|
18515
|
+
if (refs.length > 0) {
|
|
18516
|
+
console.log("");
|
|
18517
|
+
console.log(`Resource "${id}" is referenced by:`);
|
|
18518
|
+
for (const r of refs) console.log(` - ${r.id} (${r.kind}, role: ${r.role})`);
|
|
18519
|
+
console.log("");
|
|
18520
|
+
console.log("Deleting the resource will NOT remove these references.");
|
|
18521
|
+
}
|
|
18522
|
+
let proceed = opts.yes === true;
|
|
18523
|
+
if (!proceed) {
|
|
18524
|
+
if (process.stdin.isTTY) {
|
|
18525
|
+
proceed = await confirm({ message: `Delete resource "${id}"?`, initialValue: false });
|
|
18526
|
+
} else {
|
|
18527
|
+
console.error(`Refusing to delete without confirmation. Re-run with --yes to delete "${id}".`);
|
|
18528
|
+
process.exit(1);
|
|
18529
|
+
}
|
|
18530
|
+
}
|
|
18531
|
+
if (!proceed) {
|
|
18532
|
+
console.log("Aborted.");
|
|
18533
|
+
return;
|
|
18534
|
+
}
|
|
18535
|
+
try {
|
|
18536
|
+
const done = deleteResource(dir, id, { confirm: true });
|
|
18537
|
+
if (opts.json) {
|
|
18538
|
+
console.log(JSON.stringify(done, null, 2));
|
|
18539
|
+
return;
|
|
18540
|
+
}
|
|
18541
|
+
log.success(`Deleted ${id} (${done.path}).`);
|
|
18542
|
+
} catch (err) {
|
|
18543
|
+
console.error(err instanceof ResourceWriteError ? err.message : String(err));
|
|
18544
|
+
process.exit(1);
|
|
18545
|
+
}
|
|
18546
|
+
}
|
|
18222
18547
|
|
|
18223
18548
|
// src/services/integrations.ts
|
|
18224
|
-
import
|
|
18549
|
+
import matter14 from "gray-matter";
|
|
18225
18550
|
import { parse as parseYaml18, stringify as stringifyYaml9 } from "yaml";
|
|
18226
18551
|
|
|
18227
18552
|
// src/core/work-item-write.ts
|
|
18228
|
-
import
|
|
18229
|
-
import
|
|
18553
|
+
import fs6 from "fs";
|
|
18554
|
+
import path10 from "path";
|
|
18230
18555
|
import crypto2 from "crypto";
|
|
18231
|
-
import
|
|
18556
|
+
import matter13 from "gray-matter";
|
|
18232
18557
|
var WORK_ITEMS_DIR3 = "knowledge/delivery/work-items";
|
|
18233
18558
|
var WorkItemWriteError = class extends Error {
|
|
18234
18559
|
constructor(code, message) {
|
|
@@ -18249,7 +18574,7 @@ function nextWorkItemId2(dir) {
|
|
|
18249
18574
|
let max = 0;
|
|
18250
18575
|
const walk = (d) => {
|
|
18251
18576
|
if (!exists(d)) return;
|
|
18252
|
-
for (const entry of
|
|
18577
|
+
for (const entry of fs6.readdirSync(d)) {
|
|
18253
18578
|
const full = join(d, entry);
|
|
18254
18579
|
if (isFile(full)) {
|
|
18255
18580
|
const m = entry.match(/WI-(\d+)/);
|
|
@@ -18262,15 +18587,15 @@ function nextWorkItemId2(dir) {
|
|
|
18262
18587
|
walk(wiDir);
|
|
18263
18588
|
return `WI-${String(max + 1).padStart(3, "0")}`;
|
|
18264
18589
|
}
|
|
18265
|
-
function
|
|
18266
|
-
|
|
18590
|
+
function atomicWrite3(filePath, content) {
|
|
18591
|
+
fs6.mkdirSync(path10.dirname(filePath), { recursive: true });
|
|
18267
18592
|
const tmp = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
18268
|
-
|
|
18593
|
+
fs6.writeFileSync(tmp, content, "utf-8");
|
|
18269
18594
|
try {
|
|
18270
|
-
|
|
18595
|
+
fs6.renameSync(tmp, filePath);
|
|
18271
18596
|
} catch (err) {
|
|
18272
18597
|
try {
|
|
18273
|
-
|
|
18598
|
+
fs6.rmSync(tmp, { force: true });
|
|
18274
18599
|
} catch {
|
|
18275
18600
|
}
|
|
18276
18601
|
throw err;
|
|
@@ -18331,8 +18656,8 @@ function ensureH1(body, title) {
|
|
|
18331
18656
|
|
|
18332
18657
|
${trimmed}`;
|
|
18333
18658
|
}
|
|
18334
|
-
function
|
|
18335
|
-
return
|
|
18659
|
+
function serialize2(data, body) {
|
|
18660
|
+
return matter13.stringify(`
|
|
18336
18661
|
${body.trim()}
|
|
18337
18662
|
`, data);
|
|
18338
18663
|
}
|
|
@@ -18400,8 +18725,8 @@ function createWorkItem(dir, opts) {
|
|
|
18400
18725
|
const relPath = `${WORK_ITEMS_DIR3}/draft/${id}-${slugify5(title)}.md`;
|
|
18401
18726
|
const filePath = join(dir, relPath);
|
|
18402
18727
|
if (exists(filePath)) throw new WorkItemWriteError("INVALID_INPUT", `Work Item file already exists: ${relPath}`);
|
|
18403
|
-
const raw =
|
|
18404
|
-
|
|
18728
|
+
const raw = serialize2(data, body);
|
|
18729
|
+
atomicWrite3(filePath, raw);
|
|
18405
18730
|
return { id, path: relPath, revision: revisionOf(raw) };
|
|
18406
18731
|
}
|
|
18407
18732
|
|
|
@@ -19089,8 +19414,8 @@ async function handleJiraResponse(res) {
|
|
|
19089
19414
|
}
|
|
19090
19415
|
return await res.json();
|
|
19091
19416
|
}
|
|
19092
|
-
async function jiraFetch(baseUrl,
|
|
19093
|
-
const url = new URL(
|
|
19417
|
+
async function jiraFetch(baseUrl, path13, auth, timeoutMs, params) {
|
|
19418
|
+
const url = new URL(path13, baseUrl + "/");
|
|
19094
19419
|
if (params) for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
|
|
19095
19420
|
const controller = new AbortController();
|
|
19096
19421
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -19108,8 +19433,8 @@ async function jiraFetch(baseUrl, path12, auth, timeoutMs, params) {
|
|
|
19108
19433
|
clearTimeout(timer);
|
|
19109
19434
|
}
|
|
19110
19435
|
}
|
|
19111
|
-
async function jiraPost(baseUrl,
|
|
19112
|
-
const url = new URL(
|
|
19436
|
+
async function jiraPost(baseUrl, path13, auth, timeoutMs, body) {
|
|
19437
|
+
const url = new URL(path13, baseUrl + "/");
|
|
19113
19438
|
const controller = new AbortController();
|
|
19114
19439
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
19115
19440
|
try {
|
|
@@ -19409,7 +19734,7 @@ function findLinkedWorkItem(dir, integrationId, externalId) {
|
|
|
19409
19734
|
for (const art of discoverWorkItems(dir)) {
|
|
19410
19735
|
let data;
|
|
19411
19736
|
try {
|
|
19412
|
-
data =
|
|
19737
|
+
data = matter14(readFile(art.filePath)).data;
|
|
19413
19738
|
} catch {
|
|
19414
19739
|
continue;
|
|
19415
19740
|
}
|
|
@@ -19622,7 +19947,7 @@ async function runIntegrationsImport(dir, id, externalId, opts) {
|
|
|
19622
19947
|
}
|
|
19623
19948
|
|
|
19624
19949
|
// src/core/impact-report.ts
|
|
19625
|
-
import
|
|
19950
|
+
import matter15 from "gray-matter";
|
|
19626
19951
|
function isBroadGlob(glob) {
|
|
19627
19952
|
if (!glob.endsWith("/**")) return false;
|
|
19628
19953
|
const prefix = glob.slice(0, -3);
|
|
@@ -19691,7 +20016,7 @@ function buildImpactReport(dir, opts = {}, now = /* @__PURE__ */ new Date()) {
|
|
|
19691
20016
|
}
|
|
19692
20017
|
}
|
|
19693
20018
|
try {
|
|
19694
|
-
const body =
|
|
20019
|
+
const body = matter15(readFile(wi.filePath)).content;
|
|
19695
20020
|
if (hasSection(body, /acceptance|criterios de aceptaci/i)) withAcceptance++;
|
|
19696
20021
|
else gaps.missing_acceptance_criteria.push(gapItem(wi, "Add an `## Acceptance Criteria` section."));
|
|
19697
20022
|
if (hasSection(body, /definition of done|^#{1,6}\s*dod\b|definici[oó]n de (terminado|hecho)/i)) withDoD++;
|
|
@@ -20768,7 +21093,7 @@ function runAdr(opts = {}) {
|
|
|
20768
21093
|
}
|
|
20769
21094
|
|
|
20770
21095
|
// src/commands/tech.ts
|
|
20771
|
-
import
|
|
21096
|
+
import fs7 from "fs";
|
|
20772
21097
|
var DISCOVERY_FILES = ["architecture-notes.md", "decision-candidates.md"];
|
|
20773
21098
|
var DISCOVERY_DIR = "knowledge/tech/discovery";
|
|
20774
21099
|
function runTechOrganize(dir = cwd()) {
|
|
@@ -20785,7 +21110,7 @@ function runTechOrganize(dir = cwd()) {
|
|
|
20785
21110
|
continue;
|
|
20786
21111
|
}
|
|
20787
21112
|
ensureDir(join(dir, DISCOVERY_DIR));
|
|
20788
|
-
|
|
21113
|
+
fs7.renameSync(from, to);
|
|
20789
21114
|
moved.push(`knowledge/tech/${file} \u2192 ${DISCOVERY_DIR}/${file}`);
|
|
20790
21115
|
}
|
|
20791
21116
|
if (moved.length > 0) {
|
|
@@ -20867,9 +21192,9 @@ function runAssetsUpdate(kind, opts = {}) {
|
|
|
20867
21192
|
}
|
|
20868
21193
|
|
|
20869
21194
|
// src/commands/ready.ts
|
|
20870
|
-
import
|
|
20871
|
-
import
|
|
20872
|
-
import
|
|
21195
|
+
import fs8 from "fs";
|
|
21196
|
+
import path11 from "path";
|
|
21197
|
+
import matter16 from "gray-matter";
|
|
20873
21198
|
function validateReadiness(content, frontmatter) {
|
|
20874
21199
|
const warnings = [];
|
|
20875
21200
|
const body = content.replace(/^---[\s\S]*?---/, "").trim();
|
|
@@ -20923,18 +21248,18 @@ function isResolvedSection(text2) {
|
|
|
20923
21248
|
}
|
|
20924
21249
|
function transitionToReady(filePath) {
|
|
20925
21250
|
const raw = readFile(filePath);
|
|
20926
|
-
const { data, content } =
|
|
21251
|
+
const { data, content } = matter16(raw);
|
|
20927
21252
|
const today3 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
20928
21253
|
data.status = "ready";
|
|
20929
21254
|
data.ready_at = today3;
|
|
20930
|
-
const newContent =
|
|
21255
|
+
const newContent = matter16.stringify(content, data);
|
|
20931
21256
|
const posix = filePath.replace(/\\/g, "/");
|
|
20932
21257
|
let newPath = filePath;
|
|
20933
21258
|
if (posix.includes("/work-items/draft/")) {
|
|
20934
|
-
const readyDir =
|
|
21259
|
+
const readyDir = path11.dirname(filePath).replace(/[/\\]draft$/, path11.sep + "ready");
|
|
20935
21260
|
ensureDir(readyDir);
|
|
20936
|
-
const fileName =
|
|
20937
|
-
newPath =
|
|
21261
|
+
const fileName = path11.basename(filePath);
|
|
21262
|
+
newPath = path11.join(readyDir, fileName);
|
|
20938
21263
|
}
|
|
20939
21264
|
return { newPath, newContent };
|
|
20940
21265
|
}
|
|
@@ -20967,7 +21292,7 @@ async function runReady(id, opts = {}) {
|
|
|
20967
21292
|
process.exit(1);
|
|
20968
21293
|
}
|
|
20969
21294
|
const raw = readFile(wi.filePath);
|
|
20970
|
-
const { data } =
|
|
21295
|
+
const { data } = matter16(raw);
|
|
20971
21296
|
const source = parseWorkItemSource(data);
|
|
20972
21297
|
const warnings = validateReadiness(raw, data);
|
|
20973
21298
|
log.info(`Work Item found:`);
|
|
@@ -21002,11 +21327,11 @@ async function runReady(id, opts = {}) {
|
|
|
21002
21327
|
const { newPath, newContent } = transitionToReady(wi.filePath);
|
|
21003
21328
|
if (newPath !== wi.filePath) {
|
|
21004
21329
|
writeFile(newPath, newContent);
|
|
21005
|
-
|
|
21330
|
+
fs8.unlinkSync(wi.filePath);
|
|
21006
21331
|
log.success(`Updated status: ready`);
|
|
21007
21332
|
log.success(`Moved file:`);
|
|
21008
|
-
log.info(` ${
|
|
21009
|
-
log.info(` \u2192 ${
|
|
21333
|
+
log.info(` ${path11.relative(dir, wi.filePath)}`);
|
|
21334
|
+
log.info(` \u2192 ${path11.relative(dir, newPath)}`);
|
|
21010
21335
|
} else {
|
|
21011
21336
|
writeFile(wi.filePath, newContent);
|
|
21012
21337
|
log.success(`Updated status: ready`);
|
|
@@ -21017,7 +21342,7 @@ async function runReady(id, opts = {}) {
|
|
|
21017
21342
|
}
|
|
21018
21343
|
|
|
21019
21344
|
// src/commands/admin.ts
|
|
21020
|
-
import
|
|
21345
|
+
import path12 from "path";
|
|
21021
21346
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
21022
21347
|
import net from "net";
|
|
21023
21348
|
function isPortAvailable(port, host) {
|
|
@@ -21032,17 +21357,17 @@ function isPortAvailable(port, host) {
|
|
|
21032
21357
|
});
|
|
21033
21358
|
}
|
|
21034
21359
|
function resolveStaticDir() {
|
|
21035
|
-
const __dirname =
|
|
21360
|
+
const __dirname = path12.dirname(fileURLToPath2(import.meta.url));
|
|
21036
21361
|
const candidates = [
|
|
21037
21362
|
// Monorepo development: prefer the freshly built admin over the copy bundled into the CLI dist.
|
|
21038
21363
|
// The CLI build copies admin/dist into dist/admin-dist, but that copy can be stale when the admin
|
|
21039
21364
|
// was rebuilt after the CLI (build order is not guaranteed in `pnpm -r build`). Serving the admin
|
|
21040
21365
|
// package's own dist first ensures `kaddo admin` always shows the current frontend in dev. This
|
|
21041
21366
|
// path does not exist in a published npm install (admin is private), so it falls back below.
|
|
21042
|
-
|
|
21043
|
-
|
|
21367
|
+
path12.resolve(__dirname, "..", "..", "admin", "dist"),
|
|
21368
|
+
path12.resolve(__dirname, "..", "node_modules", "@kaddo", "admin", "dist"),
|
|
21044
21369
|
// Bundled inside CLI dist (npm install)
|
|
21045
|
-
|
|
21370
|
+
path12.resolve(__dirname, "admin-dist")
|
|
21046
21371
|
];
|
|
21047
21372
|
for (const c of candidates) {
|
|
21048
21373
|
if (exists(join(c, "index.html"))) return c;
|
|
@@ -21084,8 +21409,8 @@ async function runAdmin(opts = {}) {
|
|
|
21084
21409
|
}
|
|
21085
21410
|
let adminServer;
|
|
21086
21411
|
try {
|
|
21087
|
-
const __dirname =
|
|
21088
|
-
const bundled =
|
|
21412
|
+
const __dirname = path12.dirname(fileURLToPath2(import.meta.url));
|
|
21413
|
+
const bundled = path12.resolve(__dirname, "admin-server", "index.js");
|
|
21089
21414
|
if (exists(bundled)) {
|
|
21090
21415
|
const { pathToFileURL } = await import("url");
|
|
21091
21416
|
adminServer = await import(pathToFileURL(bundled).href);
|
|
@@ -21142,11 +21467,11 @@ async function runAdmin(opts = {}) {
|
|
|
21142
21467
|
|
|
21143
21468
|
// src/core/work-item-import.ts
|
|
21144
21469
|
import crypto3 from "crypto";
|
|
21145
|
-
import
|
|
21146
|
-
import
|
|
21470
|
+
import fs9 from "fs";
|
|
21471
|
+
import matter18 from "gray-matter";
|
|
21147
21472
|
|
|
21148
21473
|
// src/core/work-items.ts
|
|
21149
|
-
import
|
|
21474
|
+
import matter17 from "gray-matter";
|
|
21150
21475
|
function computeRefinementStatus(wi) {
|
|
21151
21476
|
const aspects = {
|
|
21152
21477
|
outcome: Boolean(wi.currentBehavior?.trim() || wi.targetBehavior?.trim()),
|
|
@@ -21224,8 +21549,8 @@ function parseGraphReason(v) {
|
|
|
21224
21549
|
if (!v || typeof v !== "object") return null;
|
|
21225
21550
|
const o = v;
|
|
21226
21551
|
const relationship = typeof o.relationship === "string" && o.relationship.trim() ? o.relationship.trim() : null;
|
|
21227
|
-
const
|
|
21228
|
-
return relationship ||
|
|
21552
|
+
const path13 = Array.isArray(o.path) ? o.path.map(String).filter(Boolean) : [];
|
|
21553
|
+
return relationship || path13.length ? { relationship, path: path13 } : null;
|
|
21229
21554
|
}
|
|
21230
21555
|
function parseExplain(o) {
|
|
21231
21556
|
const refs = Array.isArray(o.evidence) ? o.evidence : Array.isArray(o.evidence_refs) ? o.evidence_refs : [];
|
|
@@ -21280,7 +21605,7 @@ function parseOriginalSnapshot(fm2) {
|
|
|
21280
21605
|
function readBody(filePath) {
|
|
21281
21606
|
try {
|
|
21282
21607
|
const raw = readFile(filePath);
|
|
21283
|
-
return
|
|
21608
|
+
return matter17(raw).content;
|
|
21284
21609
|
} catch {
|
|
21285
21610
|
return "";
|
|
21286
21611
|
}
|
|
@@ -21739,7 +22064,7 @@ function detectFormat(raw) {
|
|
|
21739
22064
|
if (!trimmed) throw new ImportError("EMPTY_INPUT", "Import content is empty.");
|
|
21740
22065
|
if (trimmed.startsWith("---")) {
|
|
21741
22066
|
try {
|
|
21742
|
-
const { data } =
|
|
22067
|
+
const { data } = matter18(trimmed);
|
|
21743
22068
|
if (data && typeof data === "object" && Object.keys(data).length > 0) {
|
|
21744
22069
|
const d = data;
|
|
21745
22070
|
if (d.type === "work-item" || d.id && typeof d.id === "string" && /^WI-\d+/.test(d.id)) {
|
|
@@ -21761,7 +22086,7 @@ function parseContent(raw) {
|
|
|
21761
22086
|
let bodyText = trimmed;
|
|
21762
22087
|
if (format === "kaddo-frontmatter" || format === "markdown-frontmatter") {
|
|
21763
22088
|
try {
|
|
21764
|
-
const parsed =
|
|
22089
|
+
const parsed = matter18(trimmed);
|
|
21765
22090
|
frontmatterFields = parsed.data ?? {};
|
|
21766
22091
|
bodyText = parsed.content.trim();
|
|
21767
22092
|
} catch {
|
|
@@ -21858,7 +22183,7 @@ function findDuplicateByHash(dir, hash) {
|
|
|
21858
22183
|
const raw = readFile(item.filePath);
|
|
21859
22184
|
if (!raw) continue;
|
|
21860
22185
|
try {
|
|
21861
|
-
const { data } =
|
|
22186
|
+
const { data } = matter18(raw);
|
|
21862
22187
|
const source = data?.source;
|
|
21863
22188
|
if (source && typeof source === "object" && !Array.isArray(source)) {
|
|
21864
22189
|
const s = source;
|
|
@@ -21925,7 +22250,7 @@ function importWorkItem(dir, opts) {
|
|
|
21925
22250
|
};
|
|
21926
22251
|
}
|
|
21927
22252
|
if (opts.onConflict === "replace") {
|
|
21928
|
-
|
|
22253
|
+
fs9.rmSync(existing.filePath, { force: true });
|
|
21929
22254
|
replacedWorkItem = existing.workItemId;
|
|
21930
22255
|
}
|
|
21931
22256
|
}
|
|
@@ -22074,7 +22399,7 @@ async function runWorkItemImport(dir, fileOrText, opts) {
|
|
|
22074
22399
|
}
|
|
22075
22400
|
|
|
22076
22401
|
// src/commands/verify.ts
|
|
22077
|
-
import
|
|
22402
|
+
import matter19 from "gray-matter";
|
|
22078
22403
|
|
|
22079
22404
|
// src/core/implementation-evidence.ts
|
|
22080
22405
|
var WorkItemNotInProgressError = class extends Error {
|
|
@@ -22351,7 +22676,7 @@ async function runVerify(workItemId, opts = {}) {
|
|
|
22351
22676
|
}
|
|
22352
22677
|
const changedPaths = await getModifiedFiles("head");
|
|
22353
22678
|
const raw = readFile(match.filePath);
|
|
22354
|
-
const parsed =
|
|
22679
|
+
const parsed = matter19(raw);
|
|
22355
22680
|
const fm2 = parsed.data;
|
|
22356
22681
|
const acs = extractACsFromBody(parsed.content);
|
|
22357
22682
|
const existingEvidence = fm2.implementation_evidence;
|
|
@@ -22468,13 +22793,13 @@ async function runVerify(workItemId, opts = {}) {
|
|
|
22468
22793
|
if (shouldPersist) {
|
|
22469
22794
|
const filePath = match.filePath;
|
|
22470
22795
|
const wiRaw = readFile(filePath);
|
|
22471
|
-
const wiParsed =
|
|
22796
|
+
const wiParsed = matter19(wiRaw);
|
|
22472
22797
|
const data = wiParsed.data;
|
|
22473
22798
|
data.implementation_evidence = verification.implementationEvidence;
|
|
22474
22799
|
data.implementation_status = verification.implementationStatus;
|
|
22475
22800
|
data.validation_status = verification.validationStatus;
|
|
22476
22801
|
data.verified_at = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
22477
|
-
const newRaw =
|
|
22802
|
+
const newRaw = matter19.stringify(wiParsed.content, data);
|
|
22478
22803
|
writeFile(filePath, newRaw);
|
|
22479
22804
|
log.success("Work Item frontmatter updated with verification evidence.");
|
|
22480
22805
|
}
|
|
@@ -22524,9 +22849,9 @@ function markRegistered(dir, identity) {
|
|
|
22524
22849
|
ensureDir(join(dir, TELEMETRY_DIR));
|
|
22525
22850
|
writeFile(identityPath(dir), JSON.stringify(identity, null, 2));
|
|
22526
22851
|
}
|
|
22527
|
-
function signPayload(identity, method,
|
|
22852
|
+
function signPayload(identity, method, path13, timestamp, nonce, bodySha256) {
|
|
22528
22853
|
const canonical = `${method}
|
|
22529
|
-
${
|
|
22854
|
+
${path13}
|
|
22530
22855
|
${identity.installationId}
|
|
22531
22856
|
${timestamp}
|
|
22532
22857
|
${nonce}
|
|
@@ -22752,7 +23077,7 @@ function runTelemetryDisable() {
|
|
|
22752
23077
|
}
|
|
22753
23078
|
|
|
22754
23079
|
// src/core/initiative-write.ts
|
|
22755
|
-
import
|
|
23080
|
+
import matter20 from "gray-matter";
|
|
22756
23081
|
var WORK_ITEMS_DIR4 = "knowledge/delivery/work-items";
|
|
22757
23082
|
var DRAFT_DIR2 = `${WORK_ITEMS_DIR4}/draft`;
|
|
22758
23083
|
var InitiativeWriteError = class extends Error {
|
|
@@ -22864,7 +23189,7 @@ function buildInitiativeContent(id, input) {
|
|
|
22864
23189
|
if (input.priority) data.priority = input.priority;
|
|
22865
23190
|
if (input.source) data.source = input.source;
|
|
22866
23191
|
if (input.sourceId) data.source_id = input.sourceId;
|
|
22867
|
-
return
|
|
23192
|
+
return matter20.stringify("\n" + (input.body ?? defaultBody(input.title.trim())), data);
|
|
22868
23193
|
}
|
|
22869
23194
|
function createInitiative(dir, input) {
|
|
22870
23195
|
if (!input.title?.trim()) throw new InitiativeWriteError("Initiative title is required.");
|
|
@@ -22888,10 +23213,10 @@ function transitionInitiative(dir, id, to) {
|
|
|
22888
23213
|
throw new InitiativeWriteError(`Invalid transition ${ini.status} \u2192 ${to}.`);
|
|
22889
23214
|
}
|
|
22890
23215
|
const raw = readFile(ini.filePath);
|
|
22891
|
-
const { data, content } =
|
|
23216
|
+
const { data, content } = matter20(raw, {});
|
|
22892
23217
|
data.status = to;
|
|
22893
23218
|
if (to === "completed") data.completed_at = today2();
|
|
22894
|
-
const newContent =
|
|
23219
|
+
const newContent = matter20.stringify(content, data);
|
|
22895
23220
|
writeFile(ini.filePath, newContent);
|
|
22896
23221
|
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
22897
23222
|
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after transition.");
|
|
@@ -22960,7 +23285,7 @@ function buildWorkItemContent(wiId, iniId, candidate) {
|
|
|
22960
23285
|
"_What did we learn? Update after completion._",
|
|
22961
23286
|
""
|
|
22962
23287
|
].join("\n");
|
|
22963
|
-
return
|
|
23288
|
+
return matter20.stringify("\n" + body, data);
|
|
22964
23289
|
}
|
|
22965
23290
|
function materializeCandidate(dir, id, candidateId) {
|
|
22966
23291
|
const ini = getInitiative(dir, id);
|
|
@@ -22977,13 +23302,13 @@ function materializeCandidate(dir, id, candidateId) {
|
|
|
22977
23302
|
ensureDir(join(dir, DRAFT_DIR2));
|
|
22978
23303
|
writeFile(join(dir, DRAFT_DIR2, fileName), buildWorkItemContent(wiId, ini.id, candidate));
|
|
22979
23304
|
const raw = readFile(ini.filePath);
|
|
22980
|
-
const { data, content } =
|
|
23305
|
+
const { data, content } = matter20(raw, {});
|
|
22981
23306
|
const cands = Array.isArray(data.candidates) ? data.candidates : [];
|
|
22982
23307
|
for (const c of cands) {
|
|
22983
23308
|
if (c && typeof c === "object" && String(c.id) === candidateId) c.materialized_as = wiId;
|
|
22984
23309
|
}
|
|
22985
23310
|
data.candidates = cands;
|
|
22986
|
-
const newContent =
|
|
23311
|
+
const newContent = matter20.stringify(content, data);
|
|
22987
23312
|
writeFile(ini.filePath, newContent);
|
|
22988
23313
|
const updated = parseInitiative(dir, ini.filePath, newContent);
|
|
22989
23314
|
if (!updated) throw new InitiativeWriteError("Failed to parse the Initiative after materialization.");
|
|
@@ -23337,8 +23662,8 @@ var capsuleCmd = program.command("capsule").description("Export this project as
|
|
|
23337
23662
|
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) => {
|
|
23338
23663
|
runCapsuleExport(opts);
|
|
23339
23664
|
});
|
|
23340
|
-
capsuleCmd.command("add <path>").description("Register an external Knowledge Capsule as project context (.kaddo/external.yml)").action((
|
|
23341
|
-
runCapsuleAdd(
|
|
23665
|
+
capsuleCmd.command("add <path>").description("Register an external Knowledge Capsule as project context (.kaddo/external.yml)").action((path13) => {
|
|
23666
|
+
runCapsuleAdd(path13);
|
|
23342
23667
|
});
|
|
23343
23668
|
var graphCmd = program.command("graph").description("Export the lightweight, file-based knowledge graph of the project");
|
|
23344
23669
|
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) => {
|
|
@@ -23354,6 +23679,13 @@ topologyCmd.command("apply <file>").description("Apply a validated topology prop
|
|
|
23354
23679
|
var resourcesCmd = program.command("resources").description("List and inspect Project Resources \u2014 external systems the project uses (read-only, no secrets)");
|
|
23355
23680
|
resourcesCmd.command("list").description("List Project Resources defined under knowledge/tech/resources/").option("--json", "Output JSON").action((opts) => runResourcesList(cwd(), opts));
|
|
23356
23681
|
resourcesCmd.command("get <id>").description("Show one Project Resource: purpose, interfaces, boundaries and auth references").option("--json", "Output JSON").action((id, opts) => runResourcesGet(id, cwd(), opts));
|
|
23682
|
+
resourcesCmd.command("create").description("Create a Project Resource (interactive, or with --title/--type). Writes via Core.").option("--title <title>", "Resource name").option("--type <type>", "Resource type (database, cloud, api, queue, storage, repository, platform, service, other)").option("--provider <provider>", "Provider/platform").option("--scope <scope>", "Ownership scope: system | module").option("--module <id>", "Module id (implies module scope)").option("--json", "Output JSON").action(async (opts) => {
|
|
23683
|
+
await runResourcesCreate(opts, cwd());
|
|
23684
|
+
});
|
|
23685
|
+
resourcesCmd.command("update <id>").description("Update a Project Resource (no-lossy). Pass the fields to change.").option("--title <title>", "New title").option("--type <type>", "New resource type").option("--provider <provider>", "New provider").option("--purpose <purpose>", "New purpose").option("--scope <scope>", "Ownership scope: system | module").option("--module <id>", "Module id (implies module scope)").option("--json", "Output JSON").action((id, opts) => runResourcesUpdate(id, opts, cwd()));
|
|
23686
|
+
resourcesCmd.command("delete <id>").description("Delete a Project Resource after showing what references it (requires confirmation)").option("-y, --yes", "Skip the confirmation prompt").option("--json", "Output JSON").action(async (id, opts) => {
|
|
23687
|
+
await runResourcesDelete(id, opts, cwd());
|
|
23688
|
+
});
|
|
23357
23689
|
var integrationsCmd = program.command("integrations").description("Connect Kaddo to external work systems (read-first; import requires human confirmation)");
|
|
23358
23690
|
integrationsCmd.command("list").description("List configured integrations and their capabilities").option("--json", "Output JSON").action((opts) => runIntegrationsList(cwd(), opts));
|
|
23359
23691
|
integrationsCmd.command("status").description("Verify each enabled integration and report its connection status").option("--json", "Output JSON").action(async (opts) => {
|