@kaddo/cli 3.100.0 → 3.102.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 +1 -1
- package/dist/core.js +6 -3
- package/dist/index.js +346 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -427,7 +427,7 @@ without mapping it as multirepo or reading its source.
|
|
|
427
427
|
|
|
428
428
|
```bash
|
|
429
429
|
kaddo capsule export # → .kaddo/exports/<project>.capsule.md / .json
|
|
430
|
-
kaddo capsule add <path> # import an external capsule → external/<id>.capsule.md
|
|
430
|
+
kaddo capsule add <path> # import an external capsule → knowledge/external/<id>.capsule.md
|
|
431
431
|
```
|
|
432
432
|
|
|
433
433
|
`export` builds a deterministic draft from `knowledge/` (purpose, capabilities, public
|
package/dist/core.js
CHANGED
|
@@ -31,7 +31,7 @@ function join(...parts) {
|
|
|
31
31
|
// src/core/config.ts
|
|
32
32
|
import { z } from "zod";
|
|
33
33
|
import { parse as parseYaml } from "yaml";
|
|
34
|
-
var PROJECT_STATES = ["new", "pre-ai", "legacy"];
|
|
34
|
+
var PROJECT_STATES = ["new", "pre-ai", "legacy", "ai-assisted"];
|
|
35
35
|
var TEAM_SIZES = ["indie", "small", "medium", "enterprise"];
|
|
36
36
|
var REPOSITORY_STRUCTURES = ["monorepo", "multirepo"];
|
|
37
37
|
var PROJECT_LANGUAGES = ["en", "es"];
|
|
@@ -54,7 +54,7 @@ var ConfigError = class extends Error {
|
|
|
54
54
|
this.name = "ConfigError";
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
var projectStateSchema = z.enum(["new", "pre-ai", "legacy"], {
|
|
57
|
+
var projectStateSchema = z.enum(["new", "pre-ai", "legacy", "ai-assisted"], {
|
|
58
58
|
errorMap: () => ({
|
|
59
59
|
message: `project.state must be one of: ${PROJECT_STATES.join(", ")}`
|
|
60
60
|
})
|
|
@@ -102,7 +102,10 @@ var configSchema = z.object({
|
|
|
102
102
|
}).passthrough().optional(),
|
|
103
103
|
knowledge: z.unknown().optional(),
|
|
104
104
|
guard: z.unknown().optional(),
|
|
105
|
-
scan: z.unknown().optional()
|
|
105
|
+
scan: z.unknown().optional(),
|
|
106
|
+
telemetry: z.object({
|
|
107
|
+
enabled: z.boolean().default(false)
|
|
108
|
+
}).passthrough().optional()
|
|
106
109
|
}).passthrough();
|
|
107
110
|
function configPathFor(dir) {
|
|
108
111
|
return join(dir, ".kaddo", "config.yml");
|
package/dist/index.js
CHANGED
|
@@ -1272,7 +1272,7 @@ function renderInventory(baseline) {
|
|
|
1272
1272
|
// src/core/config.ts
|
|
1273
1273
|
import { z } from "zod";
|
|
1274
1274
|
import { parse as parseYaml2 } from "yaml";
|
|
1275
|
-
var PROJECT_STATES = ["new", "pre-ai", "legacy"];
|
|
1275
|
+
var PROJECT_STATES = ["new", "pre-ai", "legacy", "ai-assisted"];
|
|
1276
1276
|
var TEAM_SIZES = ["indie", "small", "medium", "enterprise"];
|
|
1277
1277
|
var REPOSITORY_STRUCTURES = ["monorepo", "multirepo"];
|
|
1278
1278
|
var PROJECT_LANGUAGES = ["en", "es"];
|
|
@@ -1295,7 +1295,7 @@ var ConfigError = class extends Error {
|
|
|
1295
1295
|
this.name = "ConfigError";
|
|
1296
1296
|
}
|
|
1297
1297
|
};
|
|
1298
|
-
var projectStateSchema = z.enum(["new", "pre-ai", "legacy"], {
|
|
1298
|
+
var projectStateSchema = z.enum(["new", "pre-ai", "legacy", "ai-assisted"], {
|
|
1299
1299
|
errorMap: () => ({
|
|
1300
1300
|
message: `project.state must be one of: ${PROJECT_STATES.join(", ")}`
|
|
1301
1301
|
})
|
|
@@ -1343,7 +1343,10 @@ var configSchema = z.object({
|
|
|
1343
1343
|
}).passthrough().optional(),
|
|
1344
1344
|
knowledge: z.unknown().optional(),
|
|
1345
1345
|
guard: z.unknown().optional(),
|
|
1346
|
-
scan: z.unknown().optional()
|
|
1346
|
+
scan: z.unknown().optional(),
|
|
1347
|
+
telemetry: z.object({
|
|
1348
|
+
enabled: z.boolean().default(false)
|
|
1349
|
+
}).passthrough().optional()
|
|
1347
1350
|
}).passthrough();
|
|
1348
1351
|
function configPathFor(dir) {
|
|
1349
1352
|
return join(dir, ".kaddo", "config.yml");
|
|
@@ -5909,7 +5912,7 @@ function parseBlock(block) {
|
|
|
5909
5912
|
let listField = null;
|
|
5910
5913
|
let inCandidateSection = false;
|
|
5911
5914
|
let current = null;
|
|
5912
|
-
const
|
|
5915
|
+
const flush2 = () => {
|
|
5913
5916
|
if (current) {
|
|
5914
5917
|
current.rawMarkdown = current.rawMarkdown.trimEnd();
|
|
5915
5918
|
rawCandidates.push(current);
|
|
@@ -5919,7 +5922,7 @@ function parseBlock(block) {
|
|
|
5919
5922
|
for (const line of block.lines) {
|
|
5920
5923
|
const candMatch = line.match(CANDIDATE_RE);
|
|
5921
5924
|
if (candMatch && inCandidateSection) {
|
|
5922
|
-
|
|
5925
|
+
flush2();
|
|
5923
5926
|
current = { id: candMatch[1], title: candMatch[2].trim(), rawMarkdown: line.trim() + "\n" };
|
|
5924
5927
|
listField = null;
|
|
5925
5928
|
continue;
|
|
@@ -5938,7 +5941,7 @@ function parseBlock(block) {
|
|
|
5938
5941
|
continue;
|
|
5939
5942
|
}
|
|
5940
5943
|
if (line.trim() === "") {
|
|
5941
|
-
|
|
5944
|
+
flush2();
|
|
5942
5945
|
continue;
|
|
5943
5946
|
}
|
|
5944
5947
|
}
|
|
@@ -5984,7 +5987,7 @@ function parseBlock(block) {
|
|
|
5984
5987
|
}
|
|
5985
5988
|
}
|
|
5986
5989
|
}
|
|
5987
|
-
|
|
5990
|
+
flush2();
|
|
5988
5991
|
const decisionCandidates = decisionCandidatesFromSignals(meta.sourceSignals);
|
|
5989
5992
|
return rawCandidates.map((c) => ({
|
|
5990
5993
|
...c,
|
|
@@ -10866,7 +10869,7 @@ function addExternalCapsule(dir, sourceFile) {
|
|
|
10866
10869
|
const isCapsuleType = data.type === "knowledge-capsule";
|
|
10867
10870
|
const fallbackName = sourceFile.split(/[\\/]/).pop()?.replace(/\.capsule\.md$/, "") ?? "external";
|
|
10868
10871
|
const id = slugId(String(data.system ?? fallbackName));
|
|
10869
|
-
const destRel = join("external", `${id}.capsule.md`).replace(/\\/g, "/");
|
|
10872
|
+
const destRel = join("knowledge", "external", `${id}.capsule.md`).replace(/\\/g, "/");
|
|
10870
10873
|
writeFile(join(dir, destRel), raw);
|
|
10871
10874
|
const entry = {
|
|
10872
10875
|
id,
|
|
@@ -12988,7 +12991,7 @@ function parseRoadmapCandidateQuality(md) {
|
|
|
12988
12991
|
const lines = md.split(/\r?\n/);
|
|
12989
12992
|
const items = [];
|
|
12990
12993
|
let cur = null;
|
|
12991
|
-
const
|
|
12994
|
+
const flush2 = () => {
|
|
12992
12995
|
if (!cur) return;
|
|
12993
12996
|
const hasRelatedDomain = fieldPresent(cur.lines, /related domain/);
|
|
12994
12997
|
const hasRelatedCapability = fieldPresent(cur.lines, /related capabilit(?:y|ies)/);
|
|
@@ -13006,13 +13009,13 @@ function parseRoadmapCandidateQuality(md) {
|
|
|
13006
13009
|
for (const line of lines) {
|
|
13007
13010
|
const m = line.match(INITIATIVE_RE2);
|
|
13008
13011
|
if (m) {
|
|
13009
|
-
|
|
13012
|
+
flush2();
|
|
13010
13013
|
cur = { id: m[1], title: m[2].trim(), lines: [] };
|
|
13011
13014
|
continue;
|
|
13012
13015
|
}
|
|
13013
13016
|
if (cur) cur.lines.push(line);
|
|
13014
13017
|
}
|
|
13015
|
-
|
|
13018
|
+
flush2();
|
|
13016
13019
|
return items;
|
|
13017
13020
|
}
|
|
13018
13021
|
function buildRoadmapQuality(dir) {
|
|
@@ -20810,20 +20813,20 @@ function splitSections(body) {
|
|
|
20810
20813
|
const lines = body.split(/\r?\n/);
|
|
20811
20814
|
let current = null;
|
|
20812
20815
|
let buffer = [];
|
|
20813
|
-
const
|
|
20816
|
+
const flush2 = () => {
|
|
20814
20817
|
if (current !== null) sections.set(current, buffer.join("\n").trim());
|
|
20815
20818
|
buffer = [];
|
|
20816
20819
|
};
|
|
20817
20820
|
for (const line of lines) {
|
|
20818
20821
|
const m = line.match(/^#{1,6}\s+(.*?)\s*$/);
|
|
20819
20822
|
if (m) {
|
|
20820
|
-
|
|
20823
|
+
flush2();
|
|
20821
20824
|
current = m[1].toLowerCase().replace(/[`*_]/g, "").trim();
|
|
20822
20825
|
} else if (current !== null) {
|
|
20823
20826
|
buffer.push(line);
|
|
20824
20827
|
}
|
|
20825
20828
|
}
|
|
20826
|
-
|
|
20829
|
+
flush2();
|
|
20827
20830
|
return sections;
|
|
20828
20831
|
}
|
|
20829
20832
|
function isPlaceholder(text3) {
|
|
@@ -21320,7 +21323,7 @@ function extractSections(body) {
|
|
|
21320
21323
|
const lines = body.split(/\r?\n/);
|
|
21321
21324
|
let currentHeading = null;
|
|
21322
21325
|
let buffer = [];
|
|
21323
|
-
const
|
|
21326
|
+
const flush2 = () => {
|
|
21324
21327
|
if (currentHeading) {
|
|
21325
21328
|
sections.set(currentHeading.toLowerCase(), buffer.join("\n").trim());
|
|
21326
21329
|
}
|
|
@@ -21329,13 +21332,13 @@ function extractSections(body) {
|
|
|
21329
21332
|
for (const line of lines) {
|
|
21330
21333
|
const match = line.match(/^##\s+(.+)$/);
|
|
21331
21334
|
if (match) {
|
|
21332
|
-
|
|
21335
|
+
flush2();
|
|
21333
21336
|
currentHeading = match[1].trim();
|
|
21334
21337
|
} else if (currentHeading) {
|
|
21335
21338
|
buffer.push(line);
|
|
21336
21339
|
}
|
|
21337
21340
|
}
|
|
21338
|
-
|
|
21341
|
+
flush2();
|
|
21339
21342
|
return sections;
|
|
21340
21343
|
}
|
|
21341
21344
|
function normalizeImportFields(parsed, opts) {
|
|
@@ -21993,6 +21996,288 @@ async function runVerify(workItemId, opts = {}) {
|
|
|
21993
21996
|
if (!opts.json) outro2("Verification complete.");
|
|
21994
21997
|
}
|
|
21995
21998
|
|
|
21999
|
+
// src/core/telemetry.ts
|
|
22000
|
+
import crypto6 from "crypto";
|
|
22001
|
+
|
|
22002
|
+
// src/core/telemetry-identity.ts
|
|
22003
|
+
import crypto4 from "crypto";
|
|
22004
|
+
var TELEMETRY_DIR = ".kaddo/telemetry";
|
|
22005
|
+
var IDENTITY_FILE = "identity.json";
|
|
22006
|
+
function identityPath(dir) {
|
|
22007
|
+
return join(dir, TELEMETRY_DIR, IDENTITY_FILE);
|
|
22008
|
+
}
|
|
22009
|
+
function loadIdentity(dir) {
|
|
22010
|
+
const p2 = identityPath(dir);
|
|
22011
|
+
if (!exists(p2)) return null;
|
|
22012
|
+
try {
|
|
22013
|
+
return JSON.parse(readFile(p2));
|
|
22014
|
+
} catch {
|
|
22015
|
+
return null;
|
|
22016
|
+
}
|
|
22017
|
+
}
|
|
22018
|
+
function ensureIdentity(dir) {
|
|
22019
|
+
const existing = loadIdentity(dir);
|
|
22020
|
+
if (existing) return existing;
|
|
22021
|
+
const installationId = crypto4.randomUUID();
|
|
22022
|
+
const { publicKey, privateKey } = crypto4.generateKeyPairSync("ed25519");
|
|
22023
|
+
const pubSpki = publicKey.export({ type: "spki", format: "der" });
|
|
22024
|
+
const privPkcs8 = privateKey.export({ type: "pkcs8", format: "der" });
|
|
22025
|
+
const identity = {
|
|
22026
|
+
installationId,
|
|
22027
|
+
publicKey: pubSpki.toString("base64url"),
|
|
22028
|
+
privateKey: privPkcs8.toString("base64url"),
|
|
22029
|
+
keyAlgorithm: "Ed25519",
|
|
22030
|
+
registrationVersion: "1.0",
|
|
22031
|
+
registered: false
|
|
22032
|
+
};
|
|
22033
|
+
ensureDir(join(dir, TELEMETRY_DIR));
|
|
22034
|
+
writeFile(identityPath(dir), JSON.stringify(identity, null, 2));
|
|
22035
|
+
return identity;
|
|
22036
|
+
}
|
|
22037
|
+
function markRegistered(dir, identity) {
|
|
22038
|
+
identity.registered = true;
|
|
22039
|
+
ensureDir(join(dir, TELEMETRY_DIR));
|
|
22040
|
+
writeFile(identityPath(dir), JSON.stringify(identity, null, 2));
|
|
22041
|
+
}
|
|
22042
|
+
function signPayload(identity, method, path11, timestamp, nonce, bodySha256) {
|
|
22043
|
+
const canonical = `${method}
|
|
22044
|
+
${path11}
|
|
22045
|
+
${identity.installationId}
|
|
22046
|
+
${timestamp}
|
|
22047
|
+
${nonce}
|
|
22048
|
+
${bodySha256}`;
|
|
22049
|
+
const privKeyDer = Buffer.from(identity.privateKey, "base64url");
|
|
22050
|
+
const privKey = crypto4.createPrivateKey({ key: privKeyDer, format: "der", type: "pkcs8" });
|
|
22051
|
+
const sig2 = crypto4.sign(null, Buffer.from(canonical), privKey);
|
|
22052
|
+
return sig2.toString("base64url");
|
|
22053
|
+
}
|
|
22054
|
+
|
|
22055
|
+
// src/core/telemetry-events.ts
|
|
22056
|
+
import crypto5 from "crypto";
|
|
22057
|
+
function createEvent(name, installationId, source, properties) {
|
|
22058
|
+
return {
|
|
22059
|
+
schemaVersion: "1.0",
|
|
22060
|
+
id: crypto5.randomUUID(),
|
|
22061
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
22062
|
+
event: name,
|
|
22063
|
+
installationId,
|
|
22064
|
+
source,
|
|
22065
|
+
properties
|
|
22066
|
+
};
|
|
22067
|
+
}
|
|
22068
|
+
|
|
22069
|
+
// src/core/telemetry-buffer.ts
|
|
22070
|
+
var TELEMETRY_DIR2 = ".kaddo/telemetry";
|
|
22071
|
+
var BUFFER_FILE = "buffer.json";
|
|
22072
|
+
var MAX_BUFFERED = 100;
|
|
22073
|
+
function bufferPath(dir) {
|
|
22074
|
+
return join(dir, TELEMETRY_DIR2, BUFFER_FILE);
|
|
22075
|
+
}
|
|
22076
|
+
function readBuffer(dir) {
|
|
22077
|
+
const p2 = bufferPath(dir);
|
|
22078
|
+
if (!exists(p2)) return [];
|
|
22079
|
+
try {
|
|
22080
|
+
const data = JSON.parse(readFile(p2));
|
|
22081
|
+
return Array.isArray(data) ? data : [];
|
|
22082
|
+
} catch {
|
|
22083
|
+
return [];
|
|
22084
|
+
}
|
|
22085
|
+
}
|
|
22086
|
+
function enqueue(dir, events) {
|
|
22087
|
+
const current = readBuffer(dir);
|
|
22088
|
+
const combined = [...current, ...events].slice(-MAX_BUFFERED);
|
|
22089
|
+
ensureDir(join(dir, TELEMETRY_DIR2));
|
|
22090
|
+
writeFile(bufferPath(dir), JSON.stringify(combined, null, 2));
|
|
22091
|
+
}
|
|
22092
|
+
function clearBuffer(dir) {
|
|
22093
|
+
const p2 = bufferPath(dir);
|
|
22094
|
+
if (exists(p2)) writeFile(p2, "[]");
|
|
22095
|
+
}
|
|
22096
|
+
function bufferSize(dir) {
|
|
22097
|
+
return readBuffer(dir).length;
|
|
22098
|
+
}
|
|
22099
|
+
|
|
22100
|
+
// src/core/telemetry.ts
|
|
22101
|
+
var TELEMETRY_ENDPOINT = "https://telemetry.kaddo.org";
|
|
22102
|
+
var EVENTS_PATH = "/v1/events";
|
|
22103
|
+
var REGISTRATION_PATH = "/v1/installations";
|
|
22104
|
+
var REQUEST_TIMEOUT_MS = 5e3;
|
|
22105
|
+
var MAX_BATCH_SIZE = 25;
|
|
22106
|
+
function isEnabled(config) {
|
|
22107
|
+
if (!config) return false;
|
|
22108
|
+
const t = config.telemetry;
|
|
22109
|
+
return t?.enabled === true;
|
|
22110
|
+
}
|
|
22111
|
+
function getStatus(dir) {
|
|
22112
|
+
const config = loadConfig(dir);
|
|
22113
|
+
const enabled = isEnabled(config);
|
|
22114
|
+
const identity = loadIdentity(dir);
|
|
22115
|
+
return {
|
|
22116
|
+
enabled,
|
|
22117
|
+
registered: identity?.registered ?? false,
|
|
22118
|
+
pendingEvents: enabled ? bufferSize(dir) : 0,
|
|
22119
|
+
lastError: null
|
|
22120
|
+
};
|
|
22121
|
+
}
|
|
22122
|
+
async function httpPost(url, body, headers) {
|
|
22123
|
+
const controller = new AbortController();
|
|
22124
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
22125
|
+
try {
|
|
22126
|
+
const res = await fetch(url, {
|
|
22127
|
+
method: "POST",
|
|
22128
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
22129
|
+
body,
|
|
22130
|
+
signal: controller.signal
|
|
22131
|
+
});
|
|
22132
|
+
const text3 = await res.text();
|
|
22133
|
+
return { status: res.status, body: text3 };
|
|
22134
|
+
} finally {
|
|
22135
|
+
clearTimeout(timeout);
|
|
22136
|
+
}
|
|
22137
|
+
}
|
|
22138
|
+
async function registerInstallation(identity) {
|
|
22139
|
+
const payload = JSON.stringify({
|
|
22140
|
+
installationId: identity.installationId,
|
|
22141
|
+
publicKey: identity.publicKey,
|
|
22142
|
+
keyAlgorithm: identity.keyAlgorithm,
|
|
22143
|
+
registrationVersion: identity.registrationVersion
|
|
22144
|
+
});
|
|
22145
|
+
try {
|
|
22146
|
+
const res = await httpPost(`${TELEMETRY_ENDPOINT}${REGISTRATION_PATH}`, payload, {});
|
|
22147
|
+
return res.status === 201 || res.status === 200;
|
|
22148
|
+
} catch {
|
|
22149
|
+
return false;
|
|
22150
|
+
}
|
|
22151
|
+
}
|
|
22152
|
+
function buildSignedHeaders(identity, bodyStr) {
|
|
22153
|
+
const timestamp = Math.floor(Date.now() / 1e3).toString();
|
|
22154
|
+
const nonce = crypto6.randomBytes(16).toString("hex");
|
|
22155
|
+
const bodyHash = crypto6.createHash("sha256").update(bodyStr).digest("hex");
|
|
22156
|
+
const signature = signPayload(identity, "POST", EVENTS_PATH, timestamp, nonce, bodyHash);
|
|
22157
|
+
return {
|
|
22158
|
+
"X-Kaddo-Installation-Id": identity.installationId,
|
|
22159
|
+
"X-Kaddo-Timestamp": timestamp,
|
|
22160
|
+
"X-Kaddo-Nonce": nonce,
|
|
22161
|
+
"X-Kaddo-Signature-Version": "1",
|
|
22162
|
+
"X-Kaddo-Signature": signature
|
|
22163
|
+
};
|
|
22164
|
+
}
|
|
22165
|
+
async function deliverBatch(identity, events) {
|
|
22166
|
+
const bodyStr = JSON.stringify({ events });
|
|
22167
|
+
const headers = buildSignedHeaders(identity, bodyStr);
|
|
22168
|
+
try {
|
|
22169
|
+
const res = await httpPost(`${TELEMETRY_ENDPOINT}${EVENTS_PATH}`, bodyStr, headers);
|
|
22170
|
+
return res.status === 202;
|
|
22171
|
+
} catch {
|
|
22172
|
+
return false;
|
|
22173
|
+
}
|
|
22174
|
+
}
|
|
22175
|
+
async function emit(dir, name, source, properties) {
|
|
22176
|
+
try {
|
|
22177
|
+
const config = loadConfig(dir);
|
|
22178
|
+
if (!isEnabled(config)) return;
|
|
22179
|
+
const identity = ensureIdentity(dir);
|
|
22180
|
+
if (!identity.registered) {
|
|
22181
|
+
const ok2 = await registerInstallation(identity);
|
|
22182
|
+
if (ok2) markRegistered(dir, identity);
|
|
22183
|
+
else {
|
|
22184
|
+
const event2 = createEvent(name, identity.installationId, source, properties);
|
|
22185
|
+
enqueue(dir, [event2]);
|
|
22186
|
+
return;
|
|
22187
|
+
}
|
|
22188
|
+
}
|
|
22189
|
+
const event = createEvent(name, identity.installationId, source, properties);
|
|
22190
|
+
const buffered = readBuffer(dir);
|
|
22191
|
+
const batch = [...buffered, event].slice(0, MAX_BATCH_SIZE);
|
|
22192
|
+
const ok = await deliverBatch(identity, batch);
|
|
22193
|
+
if (ok) {
|
|
22194
|
+
if (buffered.length > 0) clearBuffer(dir);
|
|
22195
|
+
const remaining = [...buffered, event].slice(MAX_BATCH_SIZE);
|
|
22196
|
+
if (remaining.length > 0) enqueue(dir, remaining);
|
|
22197
|
+
else if (buffered.length > 0) clearBuffer(dir);
|
|
22198
|
+
} else {
|
|
22199
|
+
enqueue(dir, [event]);
|
|
22200
|
+
}
|
|
22201
|
+
} catch {
|
|
22202
|
+
}
|
|
22203
|
+
}
|
|
22204
|
+
async function flush(dir) {
|
|
22205
|
+
try {
|
|
22206
|
+
const config = loadConfig(dir);
|
|
22207
|
+
if (!isEnabled(config)) return 0;
|
|
22208
|
+
const identity = loadIdentity(dir);
|
|
22209
|
+
if (!identity?.registered) return 0;
|
|
22210
|
+
const buffered = readBuffer(dir);
|
|
22211
|
+
if (buffered.length === 0) return 0;
|
|
22212
|
+
let delivered = 0;
|
|
22213
|
+
for (let i = 0; i < buffered.length; i += MAX_BATCH_SIZE) {
|
|
22214
|
+
const batch = buffered.slice(i, i + MAX_BATCH_SIZE);
|
|
22215
|
+
const ok = await deliverBatch(identity, batch);
|
|
22216
|
+
if (ok) delivered += batch.length;
|
|
22217
|
+
else break;
|
|
22218
|
+
}
|
|
22219
|
+
if (delivered >= buffered.length) {
|
|
22220
|
+
clearBuffer(dir);
|
|
22221
|
+
} else if (delivered > 0) {
|
|
22222
|
+
const remaining = buffered.slice(delivered);
|
|
22223
|
+
clearBuffer(dir);
|
|
22224
|
+
enqueue(dir, remaining);
|
|
22225
|
+
}
|
|
22226
|
+
return delivered;
|
|
22227
|
+
} catch {
|
|
22228
|
+
return 0;
|
|
22229
|
+
}
|
|
22230
|
+
}
|
|
22231
|
+
|
|
22232
|
+
// src/commands/telemetry.ts
|
|
22233
|
+
import { parse as parseYaml19, stringify as stringifyYaml9 } from "yaml";
|
|
22234
|
+
function runTelemetryStatus() {
|
|
22235
|
+
const dir = process.cwd();
|
|
22236
|
+
intro2("kaddo telemetry status");
|
|
22237
|
+
const config = loadConfig(dir);
|
|
22238
|
+
if (!config) {
|
|
22239
|
+
log2.error("Kaddo is not initialized. Run `kaddo init` first.");
|
|
22240
|
+
process.exit(1);
|
|
22241
|
+
}
|
|
22242
|
+
const status = getStatus(dir);
|
|
22243
|
+
log2.info(` Enabled: ${status.enabled}`);
|
|
22244
|
+
log2.info(` Registered: ${status.registered}`);
|
|
22245
|
+
log2.info(` Pending events: ${status.pendingEvents}`);
|
|
22246
|
+
if (!status.enabled) {
|
|
22247
|
+
log2.info("");
|
|
22248
|
+
log2.info("Enable with: kaddo telemetry enable");
|
|
22249
|
+
}
|
|
22250
|
+
outro2("Telemetry status.");
|
|
22251
|
+
}
|
|
22252
|
+
function runTelemetryEnable() {
|
|
22253
|
+
const dir = process.cwd();
|
|
22254
|
+
intro2("kaddo telemetry enable");
|
|
22255
|
+
setTelemetryEnabled(dir, true);
|
|
22256
|
+
log2.success("Telemetry enabled.");
|
|
22257
|
+
log2.info("Kaddo will send anonymous usage metadata to telemetry.kaddo.org.");
|
|
22258
|
+
log2.info("No project content, source code, prompts or PII is ever transmitted.");
|
|
22259
|
+
outro2("Run `kaddo telemetry status` to check the current state.");
|
|
22260
|
+
}
|
|
22261
|
+
function runTelemetryDisable() {
|
|
22262
|
+
const dir = process.cwd();
|
|
22263
|
+
intro2("kaddo telemetry disable");
|
|
22264
|
+
setTelemetryEnabled(dir, false);
|
|
22265
|
+
log2.success("Telemetry disabled.");
|
|
22266
|
+
log2.info("No telemetry requests will be made.");
|
|
22267
|
+
outro2("Run `kaddo telemetry enable` to re-enable.");
|
|
22268
|
+
}
|
|
22269
|
+
function setTelemetryEnabled(dir, enabled) {
|
|
22270
|
+
const configPath = join(dir, ".kaddo", "config.yml");
|
|
22271
|
+
if (!exists(configPath)) {
|
|
22272
|
+
log2.error("Kaddo is not initialized. Run `kaddo init` first.");
|
|
22273
|
+
process.exit(1);
|
|
22274
|
+
}
|
|
22275
|
+
const raw = readFile(configPath);
|
|
22276
|
+
const doc = parseYaml19(raw) ?? {};
|
|
22277
|
+
doc.telemetry = { ...doc.telemetry ?? {}, enabled };
|
|
22278
|
+
writeFile(configPath, stringifyYaml9(doc));
|
|
22279
|
+
}
|
|
22280
|
+
|
|
21996
22281
|
// src/index.ts
|
|
21997
22282
|
var require2 = createRequire(import.meta.url);
|
|
21998
22283
|
var { version } = require2("../package.json");
|
|
@@ -22170,6 +22455,50 @@ program.command("add [module]").description("Install an optional Kaddo module (a
|
|
|
22170
22455
|
program.command("admin").description("Start Kaddo Admin \u2014 a local web interface for the project knowledge").option("--port <port>", "Server port (default: 4173)", parseInt).option("--host <host>", "Server host (default: 127.0.0.1)").option("--no-open", "Do not open the browser automatically").action(async (opts) => {
|
|
22171
22456
|
await runAdmin({ port: opts.port, host: opts.host, noOpen: opts.open === false });
|
|
22172
22457
|
});
|
|
22458
|
+
var telemetryCmd = program.command("telemetry").description("Manage anonymous usage telemetry");
|
|
22459
|
+
telemetryCmd.command("status").description("Show telemetry status (enabled, registered, pending events)").action(() => {
|
|
22460
|
+
runTelemetryStatus();
|
|
22461
|
+
});
|
|
22462
|
+
telemetryCmd.command("enable").description("Enable anonymous usage telemetry").action(() => {
|
|
22463
|
+
runTelemetryEnable();
|
|
22464
|
+
});
|
|
22465
|
+
telemetryCmd.command("disable").description("Disable anonymous usage telemetry").action(() => {
|
|
22466
|
+
runTelemetryDisable();
|
|
22467
|
+
});
|
|
22468
|
+
var LIFECYCLE_EVENTS = {
|
|
22469
|
+
create: "work_item_created",
|
|
22470
|
+
ready: "work_item_ready",
|
|
22471
|
+
learn: "work_item_completed",
|
|
22472
|
+
verify: "verification_completed",
|
|
22473
|
+
context: "knowledge_generated",
|
|
22474
|
+
explain: "knowledge_generated",
|
|
22475
|
+
understand: "knowledge_generated"
|
|
22476
|
+
};
|
|
22477
|
+
var CAPSULE_EVENTS = {
|
|
22478
|
+
export: "capsule_exported",
|
|
22479
|
+
add: "capsule_imported"
|
|
22480
|
+
};
|
|
22481
|
+
var commandStart = Date.now();
|
|
22482
|
+
program.hook("postAction", (_thisCommand, actionCommand) => {
|
|
22483
|
+
const name = actionCommand.name();
|
|
22484
|
+
const parent = actionCommand.parent?.name();
|
|
22485
|
+
const iface = "cli";
|
|
22486
|
+
const durationMs = Date.now() - commandStart;
|
|
22487
|
+
if (name === "status" || name === "enable" || name === "disable") return;
|
|
22488
|
+
const lifecycleEvent = LIFECYCLE_EVENTS[name];
|
|
22489
|
+
if (lifecycleEvent) {
|
|
22490
|
+
void emit(cwd(), lifecycleEvent, iface, { interface: iface }).catch(() => {
|
|
22491
|
+
});
|
|
22492
|
+
}
|
|
22493
|
+
if (parent === "capsule" && CAPSULE_EVENTS[name]) {
|
|
22494
|
+
void emit(cwd(), CAPSULE_EVENTS[name], iface, { interface: iface }).catch(() => {
|
|
22495
|
+
});
|
|
22496
|
+
}
|
|
22497
|
+
void emit(cwd(), "command_executed", iface, { command: parent ? `${parent} ${name}` : name, durationMs, interface: iface }).catch(() => {
|
|
22498
|
+
});
|
|
22499
|
+
void flush(cwd()).catch(() => {
|
|
22500
|
+
});
|
|
22501
|
+
});
|
|
22173
22502
|
program.parseAsync(process.argv).catch((err) => {
|
|
22174
22503
|
console.error(err);
|
|
22175
22504
|
process.exit(1);
|