@kaddo/cli 3.139.0 → 3.140.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-server/index.js +2 -2
- package/dist/core.js +423 -121
- package/dist/index.js +5060 -4947
- package/package.json +1 -1
|
@@ -653,7 +653,7 @@ function getRefinementHandoff(dir, workItemId) {
|
|
|
653
653
|
}
|
|
654
654
|
function createWorkItemAdmin(dir, body) {
|
|
655
655
|
try {
|
|
656
|
-
const res = coreCreateWorkItem(dir, { intent: body.intent, type: body.type, answers: body.answers });
|
|
656
|
+
const res = coreCreateWorkItem(dir, { intent: body.intent, type: body.type, answers: body.answers, telemetrySource: "adapter" });
|
|
657
657
|
return { id: res.id, path: res.path, revision: res.revision, status: "draft" };
|
|
658
658
|
} catch (err) {
|
|
659
659
|
mapWriteError(err);
|
|
@@ -670,7 +670,7 @@ function getWorkItemEdit(dir, workItemId) {
|
|
|
670
670
|
function updateWorkItemAdmin(dir, workItemId, body) {
|
|
671
671
|
assertValidWorkItemId(workItemId);
|
|
672
672
|
try {
|
|
673
|
-
const res = coreUpdateWorkItem(dir, workItemId, body.model, body.expectedRevision);
|
|
673
|
+
const res = coreUpdateWorkItem(dir, workItemId, body.model, body.expectedRevision, "adapter");
|
|
674
674
|
return { id: workItemId, path: res.path, revision: res.revision };
|
|
675
675
|
} catch (err) {
|
|
676
676
|
mapWriteError(err);
|
package/dist/core.js
CHANGED
|
@@ -13767,7 +13767,7 @@ function parseRelatedKnowledge(fm2, knowledgeById) {
|
|
|
13767
13767
|
// src/core/work-item-write.ts
|
|
13768
13768
|
import fs4 from "fs";
|
|
13769
13769
|
import path4 from "path";
|
|
13770
|
-
import
|
|
13770
|
+
import crypto5 from "crypto";
|
|
13771
13771
|
import matter17 from "gray-matter";
|
|
13772
13772
|
|
|
13773
13773
|
// src/core/knowledge-levels.ts
|
|
@@ -13956,6 +13956,367 @@ function normalizeType(raw) {
|
|
|
13956
13956
|
return TYPE_ALIASES[t] ?? null;
|
|
13957
13957
|
}
|
|
13958
13958
|
|
|
13959
|
+
// src/core/telemetry.ts
|
|
13960
|
+
import crypto4 from "crypto";
|
|
13961
|
+
|
|
13962
|
+
// src/core/telemetry-identity.ts
|
|
13963
|
+
import crypto2 from "crypto";
|
|
13964
|
+
import { parse as parseYaml10, stringify as stringifyYaml6 } from "yaml";
|
|
13965
|
+
var TELEMETRY_DIR = ".kaddo/telemetry";
|
|
13966
|
+
var IDENTITY_FILE = "identity.json";
|
|
13967
|
+
function ensureProjectId(dir) {
|
|
13968
|
+
const configPath = join(dir, ".kaddo", "config.yml");
|
|
13969
|
+
if (!exists(configPath)) return null;
|
|
13970
|
+
try {
|
|
13971
|
+
const raw = parseYaml10(readFile(configPath)) ?? {};
|
|
13972
|
+
const telemetry = raw.telemetry && typeof raw.telemetry === "object" && !Array.isArray(raw.telemetry) ? raw.telemetry : {};
|
|
13973
|
+
if (typeof telemetry.projectId === "string" && /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(telemetry.projectId)) {
|
|
13974
|
+
return telemetry.projectId;
|
|
13975
|
+
}
|
|
13976
|
+
const projectId = crypto2.randomUUID();
|
|
13977
|
+
raw.telemetry = { ...telemetry, projectId };
|
|
13978
|
+
writeFile(configPath, stringifyYaml6(raw));
|
|
13979
|
+
return projectId;
|
|
13980
|
+
} catch {
|
|
13981
|
+
return null;
|
|
13982
|
+
}
|
|
13983
|
+
}
|
|
13984
|
+
function identityPath(dir) {
|
|
13985
|
+
return join(dir, TELEMETRY_DIR, IDENTITY_FILE);
|
|
13986
|
+
}
|
|
13987
|
+
function loadIdentity(dir) {
|
|
13988
|
+
const p = identityPath(dir);
|
|
13989
|
+
if (!exists(p)) return null;
|
|
13990
|
+
try {
|
|
13991
|
+
return JSON.parse(readFile(p));
|
|
13992
|
+
} catch {
|
|
13993
|
+
return null;
|
|
13994
|
+
}
|
|
13995
|
+
}
|
|
13996
|
+
function ensureIdentity(dir) {
|
|
13997
|
+
const existing = loadIdentity(dir);
|
|
13998
|
+
if (existing) return existing;
|
|
13999
|
+
const installationId = crypto2.randomUUID();
|
|
14000
|
+
const { publicKey, privateKey } = crypto2.generateKeyPairSync("ed25519");
|
|
14001
|
+
const pubSpki = publicKey.export({ type: "spki", format: "der" });
|
|
14002
|
+
const privPkcs8 = privateKey.export({ type: "pkcs8", format: "der" });
|
|
14003
|
+
const identity = {
|
|
14004
|
+
installationId,
|
|
14005
|
+
publicKey: pubSpki.toString("base64url"),
|
|
14006
|
+
privateKey: privPkcs8.toString("base64url"),
|
|
14007
|
+
keyAlgorithm: "Ed25519",
|
|
14008
|
+
registrationVersion: "1.0",
|
|
14009
|
+
registered: false
|
|
14010
|
+
};
|
|
14011
|
+
ensureDir(join(dir, TELEMETRY_DIR));
|
|
14012
|
+
writeFile(identityPath(dir), JSON.stringify(identity, null, 2));
|
|
14013
|
+
return identity;
|
|
14014
|
+
}
|
|
14015
|
+
function markRegistered(dir, identity) {
|
|
14016
|
+
identity.registered = true;
|
|
14017
|
+
ensureDir(join(dir, TELEMETRY_DIR));
|
|
14018
|
+
writeFile(identityPath(dir), JSON.stringify(identity, null, 2));
|
|
14019
|
+
}
|
|
14020
|
+
function signPayload(identity, method, path10, timestamp, nonce, bodySha256) {
|
|
14021
|
+
const canonical = `${method}
|
|
14022
|
+
${path10}
|
|
14023
|
+
${identity.installationId}
|
|
14024
|
+
${timestamp}
|
|
14025
|
+
${nonce}
|
|
14026
|
+
${bodySha256}`;
|
|
14027
|
+
const privKeyDer = Buffer.from(identity.privateKey, "base64url");
|
|
14028
|
+
const privKey = crypto2.createPrivateKey({ key: privKeyDer, format: "der", type: "pkcs8" });
|
|
14029
|
+
const sig = crypto2.sign(null, Buffer.from(canonical), privKey);
|
|
14030
|
+
return sig.toString("base64url");
|
|
14031
|
+
}
|
|
14032
|
+
|
|
14033
|
+
// src/core/telemetry-events.ts
|
|
14034
|
+
import crypto3 from "crypto";
|
|
14035
|
+
var COMMANDS = /* @__PURE__ */ new Set([
|
|
14036
|
+
"init",
|
|
14037
|
+
"scan",
|
|
14038
|
+
"bootstrap",
|
|
14039
|
+
"create",
|
|
14040
|
+
"ready",
|
|
14041
|
+
"start",
|
|
14042
|
+
"learn",
|
|
14043
|
+
"verify",
|
|
14044
|
+
"context",
|
|
14045
|
+
"explain",
|
|
14046
|
+
"understand",
|
|
14047
|
+
"guard",
|
|
14048
|
+
"report",
|
|
14049
|
+
"impact",
|
|
14050
|
+
"drift",
|
|
14051
|
+
"savings",
|
|
14052
|
+
"questions",
|
|
14053
|
+
"knowledge",
|
|
14054
|
+
"capsule",
|
|
14055
|
+
"work-item",
|
|
14056
|
+
"plan",
|
|
14057
|
+
"epic",
|
|
14058
|
+
"initiative",
|
|
14059
|
+
"resources",
|
|
14060
|
+
"deprecation",
|
|
14061
|
+
"topology",
|
|
14062
|
+
"modules",
|
|
14063
|
+
"collaboration"
|
|
14064
|
+
]);
|
|
14065
|
+
var LABEL = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
14066
|
+
function validLabel(value) {
|
|
14067
|
+
return typeof value === "string" && LABEL.test(value);
|
|
14068
|
+
}
|
|
14069
|
+
function validateEvent(event) {
|
|
14070
|
+
if (event.schemaVersion === "1.0") return null;
|
|
14071
|
+
if (!validLabel(event.kaddoVersion)) return "kaddoVersion must be a public version label.";
|
|
14072
|
+
if (event.properties.command !== void 0 && !COMMANDS.has(event.properties.command)) return "command must be catalogued and argument-free.";
|
|
14073
|
+
for (const key of ["languages", "frameworks", "runtimes", "clouds"]) {
|
|
14074
|
+
const values = event.properties[key];
|
|
14075
|
+
if (values !== void 0 && (!Array.isArray(values) || !values.every(validLabel))) return `${key} contains an unallowlisted label.`;
|
|
14076
|
+
}
|
|
14077
|
+
for (const key of ["provider", "model", "workItemType"]) {
|
|
14078
|
+
const value = event.properties[key];
|
|
14079
|
+
if (value !== void 0 && !validLabel(value)) return `${key} contains an unallowlisted value.`;
|
|
14080
|
+
}
|
|
14081
|
+
if (event.properties.knowledgeLevel !== void 0 && !/^K[0-4]$/.test(event.properties.knowledgeLevel)) return "knowledgeLevel is invalid.";
|
|
14082
|
+
for (const key of ["durationMs", "inputTokens", "outputTokens", "totalTokens"]) {
|
|
14083
|
+
const value = event.properties[key];
|
|
14084
|
+
if (value !== void 0 && (!Number.isFinite(value) || value < 0)) return `${key} must be a non-negative number.`;
|
|
14085
|
+
}
|
|
14086
|
+
return null;
|
|
14087
|
+
}
|
|
14088
|
+
function createEvent(name, installationId, source2, properties, options = {}) {
|
|
14089
|
+
const event = {
|
|
14090
|
+
schemaVersion: "1.1",
|
|
14091
|
+
id: crypto3.randomUUID(),
|
|
14092
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
14093
|
+
event: name,
|
|
14094
|
+
installationId,
|
|
14095
|
+
source: source2,
|
|
14096
|
+
kaddoVersion: options.kaddoVersion ?? KADDO_VERSION,
|
|
14097
|
+
...options.projectId ? { projectId: options.projectId } : {},
|
|
14098
|
+
properties
|
|
14099
|
+
};
|
|
14100
|
+
const error = validateEvent(event);
|
|
14101
|
+
if (error) throw new Error(`Invalid telemetry event: ${error}`);
|
|
14102
|
+
return event;
|
|
14103
|
+
}
|
|
14104
|
+
|
|
14105
|
+
// src/core/telemetry-buffer.ts
|
|
14106
|
+
var TELEMETRY_DIR2 = ".kaddo/telemetry";
|
|
14107
|
+
var BUFFER_FILE = "buffer.json";
|
|
14108
|
+
var MAX_BUFFERED = 100;
|
|
14109
|
+
function bufferPath(dir) {
|
|
14110
|
+
return join(dir, TELEMETRY_DIR2, BUFFER_FILE);
|
|
14111
|
+
}
|
|
14112
|
+
function readBuffer(dir) {
|
|
14113
|
+
const p = bufferPath(dir);
|
|
14114
|
+
if (!exists(p)) return [];
|
|
14115
|
+
try {
|
|
14116
|
+
const data = JSON.parse(readFile(p));
|
|
14117
|
+
return Array.isArray(data) ? data : [];
|
|
14118
|
+
} catch {
|
|
14119
|
+
return [];
|
|
14120
|
+
}
|
|
14121
|
+
}
|
|
14122
|
+
function enqueue(dir, events) {
|
|
14123
|
+
const current = readBuffer(dir);
|
|
14124
|
+
const combined = [...current, ...events].slice(-MAX_BUFFERED);
|
|
14125
|
+
ensureDir(join(dir, TELEMETRY_DIR2));
|
|
14126
|
+
writeFile(bufferPath(dir), JSON.stringify(combined, null, 2));
|
|
14127
|
+
}
|
|
14128
|
+
function clearBuffer(dir) {
|
|
14129
|
+
const p = bufferPath(dir);
|
|
14130
|
+
if (exists(p)) writeFile(p, "[]");
|
|
14131
|
+
}
|
|
14132
|
+
function bufferSize(dir) {
|
|
14133
|
+
return readBuffer(dir).length;
|
|
14134
|
+
}
|
|
14135
|
+
|
|
14136
|
+
// src/core/telemetry-consent.ts
|
|
14137
|
+
import { parse as parseYaml11, stringify as stringifyYaml7 } from "yaml";
|
|
14138
|
+
var CURRENT_CONSENT_VERSION = 1;
|
|
14139
|
+
var DEFERRAL_DURATION_MS = 24 * 60 * 60 * 1e3;
|
|
14140
|
+
function getConsentState(config) {
|
|
14141
|
+
if (!config) return "unset";
|
|
14142
|
+
const t = config.telemetry;
|
|
14143
|
+
if (!t) return "unset";
|
|
14144
|
+
if (t.consent === "enabled") return "enabled";
|
|
14145
|
+
if (t.consent === "disabled") return "disabled";
|
|
14146
|
+
if (t.consent === void 0) {
|
|
14147
|
+
if (t.enabled === true) return "enabled";
|
|
14148
|
+
if (t.enabled === false) return "disabled";
|
|
14149
|
+
}
|
|
14150
|
+
return "unset";
|
|
14151
|
+
}
|
|
14152
|
+
function isInteractive() {
|
|
14153
|
+
if (process.env.CI) return false;
|
|
14154
|
+
if (!process.stdin.isTTY) return false;
|
|
14155
|
+
if (!process.stdout.isTTY) return false;
|
|
14156
|
+
return true;
|
|
14157
|
+
}
|
|
14158
|
+
function persistConsent(dir, consent) {
|
|
14159
|
+
const configPath = join(dir, ".kaddo", "config.yml");
|
|
14160
|
+
if (!exists(configPath)) return;
|
|
14161
|
+
const raw = readFile(configPath);
|
|
14162
|
+
const doc = parseYaml11(raw) ?? {};
|
|
14163
|
+
const prev = doc.telemetry ?? {};
|
|
14164
|
+
delete prev.enabled;
|
|
14165
|
+
doc.telemetry = { ...prev, consent, consentVersion: CURRENT_CONSENT_VERSION };
|
|
14166
|
+
writeFile(configPath, stringifyYaml7(doc));
|
|
14167
|
+
}
|
|
14168
|
+
function isDeferralActive(dir) {
|
|
14169
|
+
const p = join(dir, ".kaddo", "telemetry-deferred.json");
|
|
14170
|
+
if (!exists(p)) return false;
|
|
14171
|
+
try {
|
|
14172
|
+
const data = JSON.parse(readFile(p));
|
|
14173
|
+
return data.deferredUntil > Date.now();
|
|
14174
|
+
} catch {
|
|
14175
|
+
return false;
|
|
14176
|
+
}
|
|
14177
|
+
}
|
|
14178
|
+
function deferConsent(dir) {
|
|
14179
|
+
const p = join(dir, ".kaddo", "telemetry-deferred.json");
|
|
14180
|
+
writeFile(p, JSON.stringify({ deferredUntil: Date.now() + DEFERRAL_DURATION_MS }));
|
|
14181
|
+
}
|
|
14182
|
+
function consentNotice() {
|
|
14183
|
+
return '[Telemetry consent] Anonymous usage telemetry has not been configured.\n Collects: command usage, version, lifecycle events.\n Never collects: source code, knowledge, prompts or PII.\n Use kaddo_set_telemetry_consent to enable, disable, or defer ("not-now").';
|
|
14184
|
+
}
|
|
14185
|
+
|
|
14186
|
+
// src/core/telemetry.ts
|
|
14187
|
+
var TELEMETRY_ENDPOINT = "https://telemetry.kaddo.org";
|
|
14188
|
+
var EVENTS_PATH = "/v1/events";
|
|
14189
|
+
var REGISTRATION_PATH = "/v1/installations";
|
|
14190
|
+
var REQUEST_TIMEOUT_MS = 5e3;
|
|
14191
|
+
var MAX_BATCH_SIZE = 25;
|
|
14192
|
+
var eventObserver;
|
|
14193
|
+
var diagnosticObserver;
|
|
14194
|
+
var endpointOverride;
|
|
14195
|
+
var pendingEmissions = /* @__PURE__ */ new Set();
|
|
14196
|
+
function diagnose(result) {
|
|
14197
|
+
try {
|
|
14198
|
+
diagnosticObserver?.(result);
|
|
14199
|
+
} catch {
|
|
14200
|
+
}
|
|
14201
|
+
}
|
|
14202
|
+
function telemetryEndpoint() {
|
|
14203
|
+
return endpointOverride ?? TELEMETRY_ENDPOINT;
|
|
14204
|
+
}
|
|
14205
|
+
function isEnabled(config) {
|
|
14206
|
+
return getConsentState(config) === "enabled";
|
|
14207
|
+
}
|
|
14208
|
+
function getStatus(dir) {
|
|
14209
|
+
const config = loadConfig(dir);
|
|
14210
|
+
const consent = getConsentState(config);
|
|
14211
|
+
const enabled = consent === "enabled";
|
|
14212
|
+
const identity = loadIdentity(dir);
|
|
14213
|
+
return {
|
|
14214
|
+
consent,
|
|
14215
|
+
enabled,
|
|
14216
|
+
registered: identity?.registered ?? false,
|
|
14217
|
+
pendingEvents: enabled ? bufferSize(dir) : 0,
|
|
14218
|
+
lastError: null
|
|
14219
|
+
};
|
|
14220
|
+
}
|
|
14221
|
+
async function httpPost(url, body, headers) {
|
|
14222
|
+
const controller = new AbortController();
|
|
14223
|
+
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
14224
|
+
try {
|
|
14225
|
+
const res = await fetch(url, {
|
|
14226
|
+
method: "POST",
|
|
14227
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
14228
|
+
body,
|
|
14229
|
+
signal: controller.signal
|
|
14230
|
+
});
|
|
14231
|
+
const text2 = await res.text();
|
|
14232
|
+
return { status: res.status, body: text2 };
|
|
14233
|
+
} finally {
|
|
14234
|
+
clearTimeout(timeout);
|
|
14235
|
+
}
|
|
14236
|
+
}
|
|
14237
|
+
async function registerInstallation(identity) {
|
|
14238
|
+
const payload = JSON.stringify({
|
|
14239
|
+
installationId: identity.installationId,
|
|
14240
|
+
publicKey: identity.publicKey,
|
|
14241
|
+
keyAlgorithm: identity.keyAlgorithm,
|
|
14242
|
+
registrationVersion: identity.registrationVersion
|
|
14243
|
+
});
|
|
14244
|
+
try {
|
|
14245
|
+
const res = await httpPost(`${telemetryEndpoint()}${REGISTRATION_PATH}`, payload, {});
|
|
14246
|
+
return res.status === 201 || res.status === 200;
|
|
14247
|
+
} catch {
|
|
14248
|
+
return false;
|
|
14249
|
+
}
|
|
14250
|
+
}
|
|
14251
|
+
function buildSignedHeaders(identity, bodyStr) {
|
|
14252
|
+
const timestamp = Math.floor(Date.now() / 1e3).toString();
|
|
14253
|
+
const nonce = crypto4.randomBytes(16).toString("hex");
|
|
14254
|
+
const bodyHash = crypto4.createHash("sha256").update(bodyStr).digest("hex");
|
|
14255
|
+
const signature = signPayload(identity, "POST", EVENTS_PATH, timestamp, nonce, bodyHash);
|
|
14256
|
+
return {
|
|
14257
|
+
"X-Kaddo-Installation-Id": identity.installationId,
|
|
14258
|
+
"X-Kaddo-Timestamp": timestamp,
|
|
14259
|
+
"X-Kaddo-Nonce": nonce,
|
|
14260
|
+
"X-Kaddo-Signature-Version": "1",
|
|
14261
|
+
"X-Kaddo-Signature": signature
|
|
14262
|
+
};
|
|
14263
|
+
}
|
|
14264
|
+
async function deliverBatch(identity, events) {
|
|
14265
|
+
const deliverable = events.filter((event) => validateEvent(event) === null);
|
|
14266
|
+
if (deliverable.length === 0) return true;
|
|
14267
|
+
const bodyStr = JSON.stringify({ events: deliverable });
|
|
14268
|
+
const headers = buildSignedHeaders(identity, bodyStr);
|
|
14269
|
+
try {
|
|
14270
|
+
const res = await httpPost(`${telemetryEndpoint()}${EVENTS_PATH}`, bodyStr, headers);
|
|
14271
|
+
return res.status === 202;
|
|
14272
|
+
} catch {
|
|
14273
|
+
return false;
|
|
14274
|
+
}
|
|
14275
|
+
}
|
|
14276
|
+
async function emitInternal(dir, name, source2, properties) {
|
|
14277
|
+
try {
|
|
14278
|
+
const config = loadConfig(dir);
|
|
14279
|
+
if (!isEnabled(config)) {
|
|
14280
|
+
diagnose("skipped");
|
|
14281
|
+
return;
|
|
14282
|
+
}
|
|
14283
|
+
const identity = ensureIdentity(dir);
|
|
14284
|
+
const event = createEvent(name, identity.installationId, source2, properties, { projectId: ensureProjectId(dir) ?? void 0 });
|
|
14285
|
+
try {
|
|
14286
|
+
eventObserver?.(event);
|
|
14287
|
+
} catch {
|
|
14288
|
+
}
|
|
14289
|
+
diagnose("accepted");
|
|
14290
|
+
if (!identity.registered) {
|
|
14291
|
+
const ok2 = await registerInstallation(identity);
|
|
14292
|
+
if (ok2) markRegistered(dir, identity);
|
|
14293
|
+
else {
|
|
14294
|
+
enqueue(dir, [event]);
|
|
14295
|
+
return;
|
|
14296
|
+
}
|
|
14297
|
+
}
|
|
14298
|
+
const buffered = readBuffer(dir);
|
|
14299
|
+
const batch = [...buffered, event].slice(0, MAX_BATCH_SIZE);
|
|
14300
|
+
const ok = await deliverBatch(identity, batch);
|
|
14301
|
+
if (ok) {
|
|
14302
|
+
if (buffered.length > 0) clearBuffer(dir);
|
|
14303
|
+
const remaining = [...buffered, event].slice(MAX_BATCH_SIZE);
|
|
14304
|
+
if (remaining.length > 0) enqueue(dir, remaining);
|
|
14305
|
+
else if (buffered.length > 0) clearBuffer(dir);
|
|
14306
|
+
} else {
|
|
14307
|
+
enqueue(dir, [event]);
|
|
14308
|
+
}
|
|
14309
|
+
} catch {
|
|
14310
|
+
diagnose("error");
|
|
14311
|
+
}
|
|
14312
|
+
}
|
|
14313
|
+
function emit(dir, name, source2, properties) {
|
|
14314
|
+
const task = emitInternal(dir, name, source2, properties);
|
|
14315
|
+
pendingEmissions.add(task);
|
|
14316
|
+
void task.then(() => pendingEmissions.delete(task), () => pendingEmissions.delete(task));
|
|
14317
|
+
return task;
|
|
14318
|
+
}
|
|
14319
|
+
|
|
13959
14320
|
// src/core/work-item-write.ts
|
|
13960
14321
|
var WORK_ITEMS_DIR2 = "knowledge/delivery/work-items";
|
|
13961
14322
|
var WorkItemWriteError = class extends Error {
|
|
@@ -13970,7 +14331,7 @@ var VALID_COVERAGE = /* @__PURE__ */ new Set(["affected", "reviewed-not-affected
|
|
|
13970
14331
|
var VALID_CONFIDENCE = /* @__PURE__ */ new Set(["high", "medium", "low"]);
|
|
13971
14332
|
var EDITABLE_STATES = ["draft"];
|
|
13972
14333
|
function revisionOf2(raw) {
|
|
13973
|
-
return
|
|
14334
|
+
return crypto5.createHash("sha256").update(raw, "utf-8").digest("hex");
|
|
13974
14335
|
}
|
|
13975
14336
|
function slugify4(s) {
|
|
13976
14337
|
return s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 50);
|
|
@@ -14290,11 +14651,13 @@ function createWorkItem(dir, opts) {
|
|
|
14290
14651
|
title,
|
|
14291
14652
|
status: "draft",
|
|
14292
14653
|
work_type: type,
|
|
14654
|
+
knowledge_level: getLevelForType(type),
|
|
14293
14655
|
created_at: today3,
|
|
14294
14656
|
source: source2,
|
|
14295
14657
|
generated_by: "kaddo-admin",
|
|
14296
14658
|
affected_modules: [],
|
|
14297
|
-
summary
|
|
14659
|
+
summary,
|
|
14660
|
+
telemetry_work_item_id: crypto5.randomUUID()
|
|
14298
14661
|
};
|
|
14299
14662
|
if (opts.originalSnapshot) data.original_snapshot = opts.originalSnapshot;
|
|
14300
14663
|
const answers = opts.answers ?? {};
|
|
@@ -14318,13 +14681,57 @@ function createWorkItem(dir, opts) {
|
|
|
14318
14681
|
if (exists(filePath)) throw new WorkItemWriteError("INVALID_INPUT", `Work Item file already exists: ${relPath}`);
|
|
14319
14682
|
const raw = serialize2(data, body);
|
|
14320
14683
|
atomicWrite3(filePath, raw);
|
|
14684
|
+
void emit(dir, "work_item_created", opts.telemetrySource ?? "cli", {
|
|
14685
|
+
workItemIdAnon: String(data.telemetry_work_item_id),
|
|
14686
|
+
workItemType: type,
|
|
14687
|
+
knowledgeLevel: getLevelForType(type)
|
|
14688
|
+
});
|
|
14321
14689
|
return { id, path: relPath, revision: revisionOf2(raw) };
|
|
14322
14690
|
}
|
|
14691
|
+
function ensureWorkItemTelemetryId(dir, id) {
|
|
14692
|
+
const { filePath } = findArtifact(dir, id);
|
|
14693
|
+
const raw = readFile(filePath);
|
|
14694
|
+
const { data, content } = matter17(raw);
|
|
14695
|
+
const current = data.telemetry_work_item_id;
|
|
14696
|
+
if (typeof current === "string" && /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(current)) return current;
|
|
14697
|
+
const next = { ...data, telemetry_work_item_id: crypto5.randomUUID() };
|
|
14698
|
+
const nextRaw = serialize2(next, content);
|
|
14699
|
+
atomicWrite3(filePath, nextRaw);
|
|
14700
|
+
return String(next.telemetry_work_item_id);
|
|
14701
|
+
}
|
|
14702
|
+
function completeWorkItem(dir, id, learning, telemetrySource = "cli") {
|
|
14703
|
+
const { filePath } = findArtifact(dir, id);
|
|
14704
|
+
const raw = readFile(filePath);
|
|
14705
|
+
const { data, content } = matter17(raw);
|
|
14706
|
+
const status = lifecycleStateOf({ status: String(data.status ?? ""), filePath });
|
|
14707
|
+
if (status !== "in-progress") throw new WorkItemWriteError("INVALID_TRANSITION", `Cannot complete a ${status} Work Item.`);
|
|
14708
|
+
const nextData = { ...data, status: "completed", completed_at: (/* @__PURE__ */ new Date()).toISOString().split("T")[0] };
|
|
14709
|
+
let nextContent = content;
|
|
14710
|
+
if (content.includes("_What did we learn from this change? Update after completion._")) nextContent = content.replace("_What did we learn from this change? Update after completion._", learning.trim());
|
|
14711
|
+
else if (content.includes("## Learning")) nextContent = content.replace(/## Learning[\s\S]*$/, `## Learning
|
|
14712
|
+
|
|
14713
|
+
${learning.trim()}
|
|
14714
|
+
`);
|
|
14715
|
+
else nextContent = content.trimEnd() + `
|
|
14716
|
+
|
|
14717
|
+
## Learning
|
|
14718
|
+
|
|
14719
|
+
${learning.trim()}
|
|
14720
|
+
`;
|
|
14721
|
+
const nextRaw = serialize2(nextData, nextContent);
|
|
14722
|
+
const targetPath = join(dir, `${WORK_ITEMS_DIR2}/completed/${path4.basename(filePath)}`);
|
|
14723
|
+
atomicWrite3(targetPath, nextRaw);
|
|
14724
|
+
if (path4.resolve(targetPath) !== path4.resolve(filePath)) fs4.rmSync(filePath, { force: true });
|
|
14725
|
+
const type = typeof nextData.work_type === "string" ? nextData.work_type : typeof nextData.type === "string" ? nextData.type : void 0;
|
|
14726
|
+
const level = typeof nextData.knowledge_level === "string" ? nextData.knowledge_level : void 0;
|
|
14727
|
+
if (type && level) void emit(dir, "work_item_completed", telemetrySource, { workItemIdAnon: ensureWorkItemTelemetryId(dir, id), workItemType: type, knowledgeLevel: level });
|
|
14728
|
+
return { path: targetPath };
|
|
14729
|
+
}
|
|
14323
14730
|
function validateInput(input) {
|
|
14324
14731
|
if (!input.title.trim()) throw new WorkItemWriteError("INVALID_INPUT", "Title is required.");
|
|
14325
14732
|
if (!isValidType(input.type)) throw new WorkItemWriteError("INVALID_INPUT", `Unknown Work Item type "${input.type}".`);
|
|
14326
14733
|
}
|
|
14327
|
-
function updateWorkItem(dir, id, input, expectedRevision) {
|
|
14734
|
+
function updateWorkItem(dir, id, input, expectedRevision, telemetrySource = "adapter") {
|
|
14328
14735
|
validateInput(input);
|
|
14329
14736
|
const { filePath, relPath } = findArtifact(dir, id);
|
|
14330
14737
|
const raw = readFile(filePath);
|
|
@@ -14340,6 +14747,10 @@ function updateWorkItem(dir, id, input, expectedRevision) {
|
|
|
14340
14747
|
const nextBody = mergeBody(content, input);
|
|
14341
14748
|
const nextRaw = serialize2(nextData, nextBody);
|
|
14342
14749
|
atomicWrite3(filePath, nextRaw);
|
|
14750
|
+
if (nextRaw !== raw) {
|
|
14751
|
+
const telemetryId = ensureWorkItemTelemetryId(dir, id);
|
|
14752
|
+
void emit(dir, "work_item_refined", telemetrySource, { workItemIdAnon: telemetryId, workItemType: input.type, knowledgeLevel: getLevelForType(input.type) });
|
|
14753
|
+
}
|
|
14343
14754
|
return { revision: revisionOf2(nextRaw), path: relPath };
|
|
14344
14755
|
}
|
|
14345
14756
|
function updateWorkItemAssignments(dir, id, assignments, expectedRevision) {
|
|
@@ -15750,7 +16161,7 @@ async function getPlanCollaboration(dir, id) {
|
|
|
15750
16161
|
}
|
|
15751
16162
|
|
|
15752
16163
|
// src/core/work-item-import.ts
|
|
15753
|
-
import
|
|
16164
|
+
import crypto6 from "crypto";
|
|
15754
16165
|
import fs5 from "fs";
|
|
15755
16166
|
import matter18 from "gray-matter";
|
|
15756
16167
|
var MAX_INPUT_BYTES = 102400;
|
|
@@ -15885,7 +16296,7 @@ function normalizeImportFields(parsed, opts) {
|
|
|
15885
16296
|
return { type, intent, summary, body, source: source2, snapshot, discardedFields };
|
|
15886
16297
|
}
|
|
15887
16298
|
function computeContentHash(raw) {
|
|
15888
|
-
return
|
|
16299
|
+
return crypto6.createHash("sha256").update(raw.trim(), "utf-8").digest("hex");
|
|
15889
16300
|
}
|
|
15890
16301
|
function findDuplicateByHash(dir, hash) {
|
|
15891
16302
|
const items = discoverWorkItems(dir);
|
|
@@ -15971,7 +16382,8 @@ function importWorkItem(dir, opts) {
|
|
|
15971
16382
|
summary: normalized.summary,
|
|
15972
16383
|
body: normalized.body,
|
|
15973
16384
|
source: normalized.source,
|
|
15974
|
-
originalSnapshot: normalized.snapshot
|
|
16385
|
+
originalSnapshot: normalized.snapshot,
|
|
16386
|
+
telemetrySource: opts.telemetrySource
|
|
15975
16387
|
});
|
|
15976
16388
|
let refinementHandoff;
|
|
15977
16389
|
try {
|
|
@@ -16003,7 +16415,7 @@ var ImportError = class extends Error {
|
|
|
16003
16415
|
|
|
16004
16416
|
// src/services/integrations.ts
|
|
16005
16417
|
import matter19 from "gray-matter";
|
|
16006
|
-
import { parse as
|
|
16418
|
+
import { parse as parseYaml12, stringify as stringifyYaml8 } from "yaml";
|
|
16007
16419
|
|
|
16008
16420
|
// ../integrations/src/errors.ts
|
|
16009
16421
|
var RETRYABLE = /* @__PURE__ */ new Set([
|
|
@@ -16981,7 +17393,7 @@ function loadRaw(dir) {
|
|
|
16981
17393
|
const abs = join(dir, INTEGRATIONS_FILE);
|
|
16982
17394
|
if (!exists(abs)) return { integrations: [] };
|
|
16983
17395
|
try {
|
|
16984
|
-
return
|
|
17396
|
+
return parseYaml12(readFile(abs)) ?? { integrations: [] };
|
|
16985
17397
|
} catch {
|
|
16986
17398
|
return { integrations: [] };
|
|
16987
17399
|
}
|
|
@@ -16992,7 +17404,7 @@ function loadIntegrations(dir) {
|
|
|
16992
17404
|
function saveIntegrations(dir, integrations) {
|
|
16993
17405
|
const abs = join(dir, INTEGRATIONS_FILE);
|
|
16994
17406
|
const data = serializeIntegrationsConfig(integrations);
|
|
16995
|
-
writeFile(abs,
|
|
17407
|
+
writeFile(abs, stringifyYaml8(data, { lineWidth: 120 }));
|
|
16996
17408
|
}
|
|
16997
17409
|
function configStatus(integration, findings) {
|
|
16998
17410
|
if (!integration.enabled) return "disabled";
|
|
@@ -17424,117 +17836,6 @@ ${item.description}` : item.title;
|
|
|
17424
17836
|
}
|
|
17425
17837
|
}
|
|
17426
17838
|
|
|
17427
|
-
// src/core/telemetry-consent.ts
|
|
17428
|
-
import { parse as parseYaml11, stringify as stringifyYaml7 } from "yaml";
|
|
17429
|
-
var CURRENT_CONSENT_VERSION = 1;
|
|
17430
|
-
var DEFERRAL_DURATION_MS = 24 * 60 * 60 * 1e3;
|
|
17431
|
-
function getConsentState(config) {
|
|
17432
|
-
if (!config) return "unset";
|
|
17433
|
-
const t = config.telemetry;
|
|
17434
|
-
if (!t) return "unset";
|
|
17435
|
-
if (t.consent === "enabled") return "enabled";
|
|
17436
|
-
if (t.consent === "disabled") return "disabled";
|
|
17437
|
-
if (t.consent === void 0) {
|
|
17438
|
-
if (t.enabled === true) return "enabled";
|
|
17439
|
-
if (t.enabled === false) return "disabled";
|
|
17440
|
-
}
|
|
17441
|
-
return "unset";
|
|
17442
|
-
}
|
|
17443
|
-
function isInteractive() {
|
|
17444
|
-
if (process.env.CI) return false;
|
|
17445
|
-
if (!process.stdin.isTTY) return false;
|
|
17446
|
-
if (!process.stdout.isTTY) return false;
|
|
17447
|
-
return true;
|
|
17448
|
-
}
|
|
17449
|
-
function persistConsent(dir, consent) {
|
|
17450
|
-
const configPath = join(dir, ".kaddo", "config.yml");
|
|
17451
|
-
if (!exists(configPath)) return;
|
|
17452
|
-
const raw = readFile(configPath);
|
|
17453
|
-
const doc = parseYaml11(raw) ?? {};
|
|
17454
|
-
const prev = doc.telemetry ?? {};
|
|
17455
|
-
delete prev.enabled;
|
|
17456
|
-
doc.telemetry = { ...prev, consent, consentVersion: CURRENT_CONSENT_VERSION };
|
|
17457
|
-
writeFile(configPath, stringifyYaml7(doc));
|
|
17458
|
-
}
|
|
17459
|
-
function isDeferralActive(dir) {
|
|
17460
|
-
const p = join(dir, ".kaddo", "telemetry-deferred.json");
|
|
17461
|
-
if (!exists(p)) return false;
|
|
17462
|
-
try {
|
|
17463
|
-
const data = JSON.parse(readFile(p));
|
|
17464
|
-
return data.deferredUntil > Date.now();
|
|
17465
|
-
} catch {
|
|
17466
|
-
return false;
|
|
17467
|
-
}
|
|
17468
|
-
}
|
|
17469
|
-
function deferConsent(dir) {
|
|
17470
|
-
const p = join(dir, ".kaddo", "telemetry-deferred.json");
|
|
17471
|
-
writeFile(p, JSON.stringify({ deferredUntil: Date.now() + DEFERRAL_DURATION_MS }));
|
|
17472
|
-
}
|
|
17473
|
-
function consentNotice() {
|
|
17474
|
-
return '[Telemetry consent] Anonymous usage telemetry has not been configured.\n Collects: command usage, version, lifecycle events.\n Never collects: source code, knowledge, prompts or PII.\n Use kaddo_set_telemetry_consent to enable, disable, or defer ("not-now").';
|
|
17475
|
-
}
|
|
17476
|
-
|
|
17477
|
-
// src/core/telemetry.ts
|
|
17478
|
-
import crypto6 from "crypto";
|
|
17479
|
-
|
|
17480
|
-
// src/core/telemetry-identity.ts
|
|
17481
|
-
import crypto4 from "crypto";
|
|
17482
|
-
var TELEMETRY_DIR = ".kaddo/telemetry";
|
|
17483
|
-
var IDENTITY_FILE = "identity.json";
|
|
17484
|
-
function identityPath(dir) {
|
|
17485
|
-
return join(dir, TELEMETRY_DIR, IDENTITY_FILE);
|
|
17486
|
-
}
|
|
17487
|
-
function loadIdentity(dir) {
|
|
17488
|
-
const p = identityPath(dir);
|
|
17489
|
-
if (!exists(p)) return null;
|
|
17490
|
-
try {
|
|
17491
|
-
return JSON.parse(readFile(p));
|
|
17492
|
-
} catch {
|
|
17493
|
-
return null;
|
|
17494
|
-
}
|
|
17495
|
-
}
|
|
17496
|
-
|
|
17497
|
-
// src/core/telemetry-events.ts
|
|
17498
|
-
import crypto5 from "crypto";
|
|
17499
|
-
|
|
17500
|
-
// src/core/telemetry-buffer.ts
|
|
17501
|
-
var TELEMETRY_DIR2 = ".kaddo/telemetry";
|
|
17502
|
-
var BUFFER_FILE = "buffer.json";
|
|
17503
|
-
function bufferPath(dir) {
|
|
17504
|
-
return join(dir, TELEMETRY_DIR2, BUFFER_FILE);
|
|
17505
|
-
}
|
|
17506
|
-
function readBuffer(dir) {
|
|
17507
|
-
const p = bufferPath(dir);
|
|
17508
|
-
if (!exists(p)) return [];
|
|
17509
|
-
try {
|
|
17510
|
-
const data = JSON.parse(readFile(p));
|
|
17511
|
-
return Array.isArray(data) ? data : [];
|
|
17512
|
-
} catch {
|
|
17513
|
-
return [];
|
|
17514
|
-
}
|
|
17515
|
-
}
|
|
17516
|
-
function bufferSize(dir) {
|
|
17517
|
-
return readBuffer(dir).length;
|
|
17518
|
-
}
|
|
17519
|
-
|
|
17520
|
-
// src/core/telemetry.ts
|
|
17521
|
-
function isEnabled(config) {
|
|
17522
|
-
return getConsentState(config) === "enabled";
|
|
17523
|
-
}
|
|
17524
|
-
function getStatus(dir) {
|
|
17525
|
-
const config = loadConfig(dir);
|
|
17526
|
-
const consent = getConsentState(config);
|
|
17527
|
-
const enabled = consent === "enabled";
|
|
17528
|
-
const identity = loadIdentity(dir);
|
|
17529
|
-
return {
|
|
17530
|
-
consent,
|
|
17531
|
-
enabled,
|
|
17532
|
-
registered: identity?.registered ?? false,
|
|
17533
|
-
pendingEvents: enabled ? bufferSize(dir) : 0,
|
|
17534
|
-
lastError: null
|
|
17535
|
-
};
|
|
17536
|
-
}
|
|
17537
|
-
|
|
17538
17839
|
// src/core/planning-insights.ts
|
|
17539
17840
|
function optStr7(v) {
|
|
17540
17841
|
return typeof v === "string" && v.trim() ? v.trim() : void 0;
|
|
@@ -18777,6 +19078,7 @@ export {
|
|
|
18777
19078
|
completeDeliveryPlan,
|
|
18778
19079
|
completeEpic,
|
|
18779
19080
|
completeInitiative,
|
|
19081
|
+
completeWorkItem,
|
|
18780
19082
|
computeContentHash,
|
|
18781
19083
|
computeEpicProgress,
|
|
18782
19084
|
computeInitiativeProgress,
|