@songsid/agend 2.3.2-beta.1 → 2.3.2-beta.11
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/THIRD_PARTY_NOTICES.md +40 -0
- package/dist/agent-cli.js +69 -2
- package/dist/agent-cli.js.map +1 -1
- package/dist/agent-endpoint.js +11 -0
- package/dist/agent-endpoint.js.map +1 -1
- package/dist/agent-whats-new.js +3 -0
- package/dist/agent-whats-new.js.map +1 -1
- package/dist/antigravity-usage-scan.d.ts +58 -0
- package/dist/antigravity-usage-scan.js +257 -0
- package/dist/antigravity-usage-scan.js.map +1 -0
- package/dist/antigravity-usage-worker.d.ts +1 -0
- package/dist/antigravity-usage-worker.js +10 -0
- package/dist/antigravity-usage-worker.js.map +1 -0
- package/dist/auth-api.js +4 -0
- package/dist/auth-api.js.map +1 -1
- package/dist/backend/kiro-classic-archive.d.ts +52 -0
- package/dist/backend/kiro-classic-archive.js +444 -0
- package/dist/backend/kiro-classic-archive.js.map +1 -0
- package/dist/backend/kiro-identity.d.ts +83 -0
- package/dist/backend/kiro-identity.js +144 -0
- package/dist/backend/kiro-identity.js.map +1 -1
- package/dist/backend/kiro-migration-verify.d.ts +10 -0
- package/dist/backend/kiro-migration-verify.js +52 -0
- package/dist/backend/kiro-migration-verify.js.map +1 -0
- package/dist/backend/kiro-retired-model.d.ts +62 -0
- package/dist/backend/kiro-retired-model.js +160 -0
- package/dist/backend/kiro-retired-model.js.map +1 -0
- package/dist/backend/kiro-v2-store-worker.js +21 -1
- package/dist/backend/kiro-v2-store-worker.js.map +1 -1
- package/dist/backend/kiro-v2-store.d.ts +8 -0
- package/dist/backend/kiro-v2-store.js.map +1 -1
- package/dist/backend/kiro.d.ts +169 -2
- package/dist/backend/kiro.js +703 -28
- package/dist/backend/kiro.js.map +1 -1
- package/dist/backend/types.d.ts +108 -0
- package/dist/backend/types.js +9 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/backend-signin-guide.d.ts +1 -0
- package/dist/backend-signin-guide.js +9 -0
- package/dist/backend-signin-guide.js.map +1 -0
- package/dist/backend-signin-pending.d.ts +10 -0
- package/dist/backend-signin-pending.js +44 -0
- package/dist/backend-signin-pending.js.map +1 -0
- package/dist/browser-backend-signins.d.ts +56 -0
- package/dist/browser-backend-signins.js +189 -0
- package/dist/browser-backend-signins.js.map +1 -0
- package/dist/cache-ledger.d.ts +38 -2
- package/dist/cache-ledger.js +133 -8
- package/dist/cache-ledger.js.map +1 -1
- package/dist/cache-prices.d.ts +2 -1
- package/dist/cache-prices.js +5 -2
- package/dist/cache-prices.js.map +1 -1
- package/dist/cache-service.d.ts +68 -0
- package/dist/cache-service.js +355 -13
- package/dist/cache-service.js.map +1 -1
- package/dist/channel/adapters/discord.d.ts +11 -0
- package/dist/channel/adapters/discord.js +71 -14
- package/dist/channel/adapters/discord.js.map +1 -1
- package/dist/channel/ipc-timeouts.js +3 -0
- package/dist/channel/ipc-timeouts.js.map +1 -1
- package/dist/channel/mcp-tools.js +41 -2
- package/dist/channel/mcp-tools.js.map +1 -1
- package/dist/channel/tool-router.js +2 -1
- package/dist/channel/tool-router.js.map +1 -1
- package/dist/classic-channel-manager.d.ts +11 -0
- package/dist/classic-channel-manager.js +39 -1
- package/dist/classic-channel-manager.js.map +1 -1
- package/dist/cli.js +54 -2
- package/dist/cli.js.map +1 -1
- package/dist/config-validator.d.ts +7 -1
- package/dist/config-validator.js +55 -10
- package/dist/config-validator.js.map +1 -1
- package/dist/config.d.ts +19 -0
- package/dist/config.js +33 -1
- package/dist/config.js.map +1 -1
- package/dist/cpu-quota.d.ts +23 -0
- package/dist/cpu-quota.js +86 -0
- package/dist/cpu-quota.js.map +1 -0
- package/dist/daemon.d.ts +68 -0
- package/dist/daemon.js +448 -26
- package/dist/daemon.js.map +1 -1
- package/dist/dashboard-permissions.d.ts +31 -6
- package/dist/dashboard-permissions.js +84 -9
- package/dist/dashboard-permissions.js.map +1 -1
- package/dist/doctor.js +2 -1
- package/dist/doctor.js.map +1 -1
- package/dist/fleet-control-audit.d.ts +1 -1
- package/dist/fleet-control-audit.js +3 -0
- package/dist/fleet-control-audit.js.map +1 -1
- package/dist/fleet-manager.d.ts +133 -2
- package/dist/fleet-manager.js +905 -94
- package/dist/fleet-manager.js.map +1 -1
- package/dist/forged-envelope-scan.d.ts +9 -0
- package/dist/forged-envelope-scan.js +30 -5
- package/dist/forged-envelope-scan.js.map +1 -1
- package/dist/general-knowledge/skills/credential-profiles/SKILL.md +5 -2
- package/dist/general-knowledge/skills/kiro-engine-migration/SKILL.md +24 -1
- package/dist/general-knowledge/skills/web-appearance/SKILL.canvas-worker-off.md +49 -1
- package/dist/general-knowledge/skills/web-appearance/SKILL.md +49 -1
- package/dist/general-knowledge/skills/web-dashboard/SKILL.canvas-worker-off.md +47 -9
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +54 -11
- package/dist/instance-config-impact.js +10 -5
- package/dist/instance-config-impact.js.map +1 -1
- package/dist/instance-lifecycle.d.ts +23 -0
- package/dist/instance-lifecycle.js +62 -12
- package/dist/instance-lifecycle.js.map +1 -1
- package/dist/kiro-db-reader.d.ts +5 -0
- package/dist/kiro-db-reader.js +18 -0
- package/dist/kiro-db-reader.js.map +1 -1
- package/dist/kiro-engine-status.d.ts +2 -0
- package/dist/kiro-engine-status.js +9 -0
- package/dist/kiro-engine-status.js.map +1 -1
- package/dist/kiro-migrate.d.ts +60 -0
- package/dist/kiro-migrate.js +160 -0
- package/dist/kiro-migrate.js.map +1 -0
- package/dist/kiro-session-proof.d.ts +41 -0
- package/dist/kiro-session-proof.js +89 -0
- package/dist/kiro-session-proof.js.map +1 -0
- package/dist/kiro-transcript-lane.d.ts +2 -0
- package/dist/kiro-transcript-lane.js.map +1 -1
- package/dist/kiro-transcript-worker.js +1 -0
- package/dist/kiro-transcript-worker.js.map +1 -1
- package/dist/kiro-tui-forensic.d.ts +12 -0
- package/dist/kiro-tui-forensic.js +110 -0
- package/dist/kiro-tui-forensic.js.map +1 -0
- package/dist/kiro-usage-run.d.ts +7 -0
- package/dist/kiro-usage-run.js +39 -0
- package/dist/kiro-usage-run.js.map +1 -0
- package/dist/kiro-usage-scan.d.ts +49 -0
- package/dist/kiro-usage-scan.js +223 -0
- package/dist/kiro-usage-scan.js.map +1 -0
- package/dist/kiro-usage-worker.d.ts +1 -0
- package/dist/kiro-usage-worker.js +10 -0
- package/dist/kiro-usage-worker.js.map +1 -0
- package/dist/kiro-usage.d.ts +58 -0
- package/dist/kiro-usage.js +310 -0
- package/dist/kiro-usage.js.map +1 -0
- package/dist/locale.js +230 -8
- package/dist/locale.js.map +1 -1
- package/dist/log-service.js +1 -1
- package/dist/log-service.js.map +1 -1
- package/dist/login-url.d.ts +4 -0
- package/dist/login-url.js +22 -0
- package/dist/login-url.js.map +1 -0
- package/dist/needs-you-hub.d.ts +2 -1
- package/dist/needs-you-hub.js +1 -1
- package/dist/needs-you-hub.js.map +1 -1
- package/dist/needs-you.d.ts +10 -2
- package/dist/needs-you.js +10 -2
- package/dist/needs-you.js.map +1 -1
- package/dist/notice-delivery.d.ts +16 -0
- package/dist/notice-delivery.js +35 -0
- package/dist/notice-delivery.js.map +1 -0
- package/dist/office-share-page.d.ts +16 -0
- package/dist/office-share-page.js +85 -0
- package/dist/office-share-page.js.map +1 -0
- package/dist/office-share-service.d.ts +91 -0
- package/dist/office-share-service.js +176 -0
- package/dist/office-share-service.js.map +1 -0
- package/dist/office-share.d.ts +268 -0
- package/dist/office-share.js +574 -0
- package/dist/office-share.js.map +1 -0
- package/dist/opencode-usage-scan.d.ts +28 -0
- package/dist/opencode-usage-scan.js +92 -0
- package/dist/opencode-usage-scan.js.map +1 -0
- package/dist/opencode-usage-worker.d.ts +1 -0
- package/dist/opencode-usage-worker.js +10 -0
- package/dist/opencode-usage-worker.js.map +1 -0
- package/dist/outbound-handlers.js +22 -2
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/outbound-schemas.d.ts +65 -2
- package/dist/outbound-schemas.js +56 -2
- package/dist/outbound-schemas.js.map +1 -1
- package/dist/public-web-gateway.js +7 -1
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/quickstart-api.js +13 -2
- package/dist/quickstart-api.js.map +1 -1
- package/dist/quickstart.js +2 -1
- package/dist/quickstart.js.map +1 -1
- package/dist/remote-card-answer.d.ts +83 -0
- package/dist/remote-card-answer.js +208 -0
- package/dist/remote-card-answer.js.map +1 -0
- package/dist/remote-card-prompt.d.ts +38 -0
- package/dist/remote-card-prompt.js +86 -0
- package/dist/remote-card-prompt.js.map +1 -0
- package/dist/reply-triggers.d.ts +2 -0
- package/dist/reply-triggers.js +3 -0
- package/dist/reply-triggers.js.map +1 -0
- package/dist/settings-api.d.ts +2 -0
- package/dist/settings-api.js +41 -16
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.js +20 -14
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-effect.js +7 -1
- package/dist/settings-effect.js.map +1 -1
- package/dist/settings-instance-patch.js +4 -1
- package/dist/settings-instance-patch.js.map +1 -1
- package/dist/setup-form.d.ts +1 -1
- package/dist/setup-form.js +55 -6
- package/dist/setup-form.js.map +1 -1
- package/dist/setup-host.d.ts +9 -0
- package/dist/setup-host.js +127 -6
- package/dist/setup-host.js.map +1 -1
- package/dist/setup-signin-assets.d.ts +2 -0
- package/dist/setup-signin-assets.js +6 -0
- package/dist/setup-signin-assets.js.map +1 -0
- package/dist/setup-wizard.js +2 -0
- package/dist/setup-wizard.js.map +1 -1
- package/dist/structured-signin-transport.d.ts +8 -0
- package/dist/structured-signin-transport.js +79 -0
- package/dist/structured-signin-transport.js.map +1 -0
- package/dist/structured-signin.d.ts +131 -0
- package/dist/structured-signin.js +388 -0
- package/dist/structured-signin.js.map +1 -0
- package/dist/tool-permissions.js +29 -0
- package/dist/tool-permissions.js.map +1 -1
- package/dist/topic-commands.js +6 -2
- package/dist/topic-commands.js.map +1 -1
- package/dist/transcript-sources.d.ts +27 -2
- package/dist/transcript-sources.js +104 -40
- package/dist/transcript-sources.js.map +1 -1
- package/dist/turn-reply-guard.d.ts +1 -1
- package/dist/turn-reply-guard.js +1 -1
- package/dist/turn-reply-guard.js.map +1 -1
- package/dist/types.d.ts +33 -8
- package/dist/ui/backend-signin.js +63 -10
- package/dist/ui/chat-store.js +3 -2
- package/dist/ui/chat-strings.js +4 -4
- package/dist/ui/fleet-office-editor.js +68 -11
- package/dist/ui/fleet-office-layout.js +110 -35
- package/dist/ui/fleet-office-model.js +6 -3
- package/dist/ui/fleet-office-overview.js +167 -0
- package/dist/ui/fleet-office-pack.d.ts +13 -3
- package/dist/ui/fleet-office-pack.js +214 -24
- package/dist/ui/fleet-office-skin.js +98 -23
- package/dist/ui/fleet-office-store.js +82 -5
- package/dist/ui/fleet-office-view.js +5 -4
- package/dist/ui/fleet-office-zones.js +232 -21
- package/dist/ui/fleet-office.js +549 -186
- package/dist/ui/fleet-usage.js +19 -15
- package/dist/ui/office-share-dialog.js +145 -0
- package/dist/ui/office-share-page.js +164 -0
- package/dist/ui/panel-chat.js +22 -3
- package/dist/ui/panel-log.js +4 -4
- package/dist/ui/panel-needs.js +5 -5
- package/dist/ui/panel-settings.js +38 -12
- package/dist/ui/settings-dialogs.js +8 -1
- package/dist/ui/settings-guests.js +17 -7
- package/dist/ui/settings-model.js +22 -6
- package/dist/ui/settings-registry.js +4 -0
- package/dist/ui/settings-strings.js +18 -2
- package/dist/ui/shared/app-i18n.js +4 -2
- package/dist/ui/shared/app-shell.js +14 -6
- package/dist/ui/shared/app-stream.js +2 -1
- package/dist/ui/shared/app.css +85 -4
- package/dist/ui/shared/office/cozy.png +0 -0
- package/dist/ui/shared/side-panel.js +95 -0
- package/dist/ui/structured-signin.js +115 -0
- package/dist/usage-report.d.ts +20 -0
- package/dist/usage-report.js +54 -17
- package/dist/usage-report.js.map +1 -1
- package/dist/usage-rollup.d.ts +9 -1
- package/dist/usage-rollup.js +20 -4
- package/dist/usage-rollup.js.map +1 -1
- package/dist/web-api.d.ts +23 -1
- package/dist/web-api.js +292 -3
- package/dist/web-api.js.map +1 -1
- package/dist/web-auth.js +1 -1
- package/dist/web-auth.js.map +1 -1
- package/dist/web-backend-login.d.ts +1 -7
- package/dist/web-backend-login.js +2 -24
- package/dist/web-backend-login.js.map +1 -1
- package/dist/web-office-acts.d.ts +173 -0
- package/dist/web-office-acts.js +285 -0
- package/dist/web-office-acts.js.map +1 -0
- package/dist/web-office-pack-read.d.ts +35 -0
- package/dist/web-office-pack-read.js +252 -0
- package/dist/web-office-pack-read.js.map +1 -0
- package/dist/web-office-pack-tools.d.ts +232 -0
- package/dist/web-office-pack-tools.js +754 -0
- package/dist/web-office-pack-tools.js.map +1 -0
- package/dist/web-office-skins.d.ts +71 -6
- package/dist/web-office-skins.js +321 -35
- package/dist/web-office-skins.js.map +1 -1
- package/dist/web-office-store.d.ts +5 -2
- package/dist/web-office-store.js +69 -10
- package/dist/web-office-store.js.map +1 -1
- package/dist/web-settings-patch.d.ts +2 -1
- package/dist/web-settings-patch.js +4 -1
- package/dist/web-settings-patch.js.map +1 -1
- package/dist/working-recovery.d.ts +2 -2
- package/dist/working-recovery.js +43 -8
- package/dist/working-recovery.js.map +1 -1
- package/dist/working-state-journal.d.ts +2 -0
- package/dist/working-state-journal.js +16 -1
- package/dist/working-state-journal.js.map +1 -1
- package/package.json +3 -2
- package/templates/windows-shortcuts.ps1 +155 -140
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #2122: run one usage scan on a worker thread — Kiro's (kiro-usage-scan.ts: a classic conversation's JSON is tens of MB)
|
|
3
|
+
* OpenCode's (opencode-usage-scan.ts) or Antigravity's (antigravity-usage-scan.ts: SQLite reads) — so it never runs on the
|
|
4
|
+
* fleet loop. A scan that has not
|
|
5
|
+
* answered in `timeoutMs` is terminated and reads as failed; nothing it read is kept, and the next pass reads again from
|
|
6
|
+
* the same cursors.
|
|
7
|
+
*/
|
|
8
|
+
import { Worker } from "node:worker_threads";
|
|
9
|
+
export const KIRO_SCAN_TIMEOUT_MS = 120_000;
|
|
10
|
+
function worker(entry, input) {
|
|
11
|
+
const limits = { maxOldGenerationSizeMb: 768 };
|
|
12
|
+
return import.meta.url.endsWith(".ts")
|
|
13
|
+
? new Worker(`const { workerData } = require("node:worker_threads"); import("tsx/esm/api").then(({ tsImport }) => tsImport(workerData.entry, workerData.entry));`, { eval: true, execArgv: [], resourceLimits: limits, workerData: { ...input, entry: new URL(`./${entry}.ts`, import.meta.url).href } })
|
|
14
|
+
: new Worker(new URL(`./${entry}.js`, import.meta.url), { execArgv: [], resourceLimits: limits, workerData: input });
|
|
15
|
+
}
|
|
16
|
+
function run(entry, input, timeoutMs, what) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
let w;
|
|
19
|
+
try {
|
|
20
|
+
w = worker(entry, input);
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
reject(err);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
let done = false;
|
|
27
|
+
const finish = (fn) => { if (done)
|
|
28
|
+
return; done = true; clearTimeout(timer); void w.terminate().catch(() => { }); fn(); };
|
|
29
|
+
const timer = setTimeout(() => finish(() => reject(new Error(`${what} timed out`))), timeoutMs);
|
|
30
|
+
timer.unref?.();
|
|
31
|
+
w.on("message", (m) => finish(() => (m.ok ? resolve(m.out) : reject(new Error(m.error ?? `${what} failed`)))));
|
|
32
|
+
w.on("error", (err) => finish(() => reject(err)));
|
|
33
|
+
w.on("exit", (code) => finish(() => reject(new Error(`${what} exited (${code})`))));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export const runKiroUsageScan = (input, timeoutMs = KIRO_SCAN_TIMEOUT_MS) => run("kiro-usage-worker", input, timeoutMs, "kiro usage scan");
|
|
37
|
+
export const runOpencodeUsageScan = (input, timeoutMs = KIRO_SCAN_TIMEOUT_MS) => run("opencode-usage-worker", input, timeoutMs, "opencode usage scan");
|
|
38
|
+
export const runAntigravityUsageScan = (input, timeoutMs = KIRO_SCAN_TIMEOUT_MS) => run("antigravity-usage-worker", input, timeoutMs, "antigravity usage scan");
|
|
39
|
+
//# sourceMappingURL=kiro-usage-run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kiro-usage-run.js","sourceRoot":"","sources":["../src/kiro-usage-run.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAK7C,MAAM,CAAC,MAAM,oBAAoB,GAAG,OAAO,CAAC;AAG5C,SAAS,MAAM,CAAC,KAAY,EAAE,KAAa;IACzC,MAAM,MAAM,GAAG,EAAE,sBAAsB,EAAE,GAAG,EAAE,CAAC;IAC/C,OAAO,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;QACpC,CAAC,CAAC,IAAI,MAAM,CAAC,oJAAoJ,EAC/J,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,IAAI,GAAG,CAAC,KAAK,KAAK,KAAK,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACxI,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,KAAK,KAAK,KAAK,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;AACzH,CAAC;AAED,SAAS,GAAG,CAAI,KAAY,EAAE,KAAa,EAAE,SAAiB,EAAE,IAAY;IAC1E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,CAAS,CAAC;QACd,IAAI,CAAC;YAAC,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KA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,GAAG,IAAI,YAAY,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACtF,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAoB,EAAE,SAAS,GAAG,oBAAoB,EAA2B,EAAE,CAClH,GAAG,CAAiB,mBAAmB,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC;AAChF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAwB,EAAE,SAAS,GAAG,oBAAoB,EAA+B,EAAE,CAC9H,GAAG,CAAqB,uBAAuB,EAAE,KAAK,EAAE,SAAS,EAAE,qBAAqB,CAAC,CAAC;AAC5F,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAA2B,EAAE,SAAS,GAAG,oBAAoB,EAAkC,EAAE,CACvI,GAAG,CAAwB,0BAA0B,EAAE,KAAK,EAAE,SAAS,EAAE,wBAAwB,CAAC,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Turn } from "./cache-ledger.js";
|
|
2
|
+
/** Where reading a source stopped: what it looked like then, and the time of the last turn counted. */
|
|
3
|
+
export interface KiroCursor {
|
|
4
|
+
sig: string;
|
|
5
|
+
after: number;
|
|
6
|
+
}
|
|
7
|
+
export interface KiroScanInstance {
|
|
8
|
+
name: string;
|
|
9
|
+
/** Its working directory as configured and as resolved (a store records either). */
|
|
10
|
+
cwds: string[];
|
|
11
|
+
/** The classic store it writes: its credential profile's, else the shared one. */
|
|
12
|
+
dbPath: string;
|
|
13
|
+
/** Keyed `classic:<conversation id>`, `tui:<file>`, `kas:<session dir>`. */
|
|
14
|
+
cursors: Record<string, KiroCursor>;
|
|
15
|
+
}
|
|
16
|
+
export interface KiroScanInput {
|
|
17
|
+
/** KIRO_HOME (default ~/.kiro): the TUI and V3 stores, shared by every login. */
|
|
18
|
+
kiroHome: string;
|
|
19
|
+
cutoff: number;
|
|
20
|
+
maxBytes: number;
|
|
21
|
+
instances: KiroScanInstance[];
|
|
22
|
+
/** TUI session file → its signature and cwd, from earlier scans (only a changed file is parsed to learn its cwd). */
|
|
23
|
+
tuiIndex: Record<string, {
|
|
24
|
+
sig: string;
|
|
25
|
+
cwd: string | null;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
export interface KiroScanUpdate {
|
|
29
|
+
key: string;
|
|
30
|
+
sig: string;
|
|
31
|
+
after: number;
|
|
32
|
+
turns: Turn[];
|
|
33
|
+
}
|
|
34
|
+
export interface KiroScanResult {
|
|
35
|
+
name: string;
|
|
36
|
+
updates: KiroScanUpdate[];
|
|
37
|
+
/** Every source of this instance seen now (a cursor for anything else is stale). */
|
|
38
|
+
live: string[];
|
|
39
|
+
/** A store was there and could not be read: this scan proves nothing about the instance (no coverage). */
|
|
40
|
+
failed: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface KiroScanOutput {
|
|
43
|
+
instances: KiroScanResult[];
|
|
44
|
+
tuiIndex: KiroScanInput["tuiIndex"];
|
|
45
|
+
readBytes: number;
|
|
46
|
+
behindBytes: number;
|
|
47
|
+
behindSources: number;
|
|
48
|
+
}
|
|
49
|
+
export declare function scanKiroUsage(input: KiroScanInput): KiroScanOutput;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #2122 §10 step 2: one bounded read of Kiro's three stores for the usage ledger, run in a worker thread
|
|
3
|
+
* (kiro-usage-worker.ts) so the fleet loop never parses a conversation (a classic row holds the whole history: tens of
|
|
4
|
+
* MB). Synchronous and self-contained so a test can run it in-process.
|
|
5
|
+
*
|
|
6
|
+
* - Which sources: each Kiro instance's conversations — classic rows whose `key` is its working directory, TUI sessions
|
|
7
|
+
* whose `cwd` is, and V3 sessions in its working directory's bucket. Only sources changed since the cutoff.
|
|
8
|
+
* - Incremental: a source is read again only when it changed (its signature: the row's `updated_at`, a file's
|
|
9
|
+
* inode:size:mtime), and only turns after the last one counted (`after`) come back.
|
|
10
|
+
* - Never: a write to Kiro's stores (the database is opened read-only; each read is one statement, so Kiro's own writer
|
|
11
|
+
* waits at most for that), a child process, a network call.
|
|
12
|
+
* - Bounded: past `maxBytes` read, a changed source is left for the next pass (counted as behind).
|
|
13
|
+
*/
|
|
14
|
+
import Database from "better-sqlite3";
|
|
15
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { kasBucket } from "./backend/kiro-kas-store.js";
|
|
18
|
+
import { kiroClassicRequestTimes, kiroClassicTurns, kiroKasTurns, kiroTuiTurns } from "./kiro-usage.js";
|
|
19
|
+
const gone = (err) => err?.code === "ENOENT";
|
|
20
|
+
const sigOf = (path) => {
|
|
21
|
+
const st = statSync(path);
|
|
22
|
+
return { sig: `${st.ino}:${st.size}:${st.mtimeMs}`, size: st.size, mtimeMs: st.mtimeMs };
|
|
23
|
+
};
|
|
24
|
+
const lines = (path) => { try {
|
|
25
|
+
return readFileSync(path, "utf8").split("\n");
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
if (gone(err))
|
|
29
|
+
return [];
|
|
30
|
+
throw err;
|
|
31
|
+
} };
|
|
32
|
+
export function scanKiroUsage(input) {
|
|
33
|
+
let budget = input.maxBytes, behindBytes = 0, behindSources = 0;
|
|
34
|
+
const dbs = new Map();
|
|
35
|
+
const tuiIndex = Object.create(null);
|
|
36
|
+
const out = [];
|
|
37
|
+
const openDb = (path) => {
|
|
38
|
+
if (dbs.has(path))
|
|
39
|
+
return dbs.get(path);
|
|
40
|
+
let db = null;
|
|
41
|
+
// Not there (no classic conversation yet, or no Kiro at all): nothing to read. There and unopenable: a failure.
|
|
42
|
+
if (existsSync(path)) {
|
|
43
|
+
db = new Database(path, { readonly: true, fileMustExist: true });
|
|
44
|
+
db.pragma("query_only = ON");
|
|
45
|
+
}
|
|
46
|
+
dbs.set(path, db);
|
|
47
|
+
return db;
|
|
48
|
+
};
|
|
49
|
+
// A classic conversation's request times, for the dedup of a session that carried it into another engine.
|
|
50
|
+
const classicTimes = (db, id) => {
|
|
51
|
+
if (!db)
|
|
52
|
+
return [];
|
|
53
|
+
const row = db.prepare("SELECT value FROM conversations_v2 WHERE conversation_id = ?").get(id);
|
|
54
|
+
if (!row?.value)
|
|
55
|
+
return [];
|
|
56
|
+
try {
|
|
57
|
+
return kiroClassicRequestTimes(JSON.parse(row.value));
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
/** Read one changed source within the budget, or count it as behind. */
|
|
64
|
+
const within = (bytes) => {
|
|
65
|
+
if (budget <= 0) {
|
|
66
|
+
behindBytes += bytes;
|
|
67
|
+
behindSources++;
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
budget -= Math.max(bytes, 1);
|
|
71
|
+
return true;
|
|
72
|
+
};
|
|
73
|
+
// TUI sessions: one listing for everyone; a file's cwd is learned once per version of it.
|
|
74
|
+
let tuiNames = [];
|
|
75
|
+
let tuiFailed = false;
|
|
76
|
+
const tuiDir = join(input.kiroHome, "sessions", "cli");
|
|
77
|
+
try {
|
|
78
|
+
tuiNames = readdirSync(tuiDir).filter(n => n.endsWith(".json"));
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (!gone(err))
|
|
82
|
+
tuiFailed = true;
|
|
83
|
+
}
|
|
84
|
+
const tuiFiles = [];
|
|
85
|
+
for (const n of tuiNames) {
|
|
86
|
+
const path = join(tuiDir, n);
|
|
87
|
+
try {
|
|
88
|
+
const s = sigOf(path);
|
|
89
|
+
if (s.mtimeMs < input.cutoff)
|
|
90
|
+
continue;
|
|
91
|
+
const known = input.tuiIndex[path];
|
|
92
|
+
let cwd = known?.sig === s.sig ? known.cwd : undefined;
|
|
93
|
+
if (cwd === undefined) {
|
|
94
|
+
const text = readFileSync(path, "utf8"); // a read that fails is a failure (below), not an empty store
|
|
95
|
+
try {
|
|
96
|
+
const v = JSON.parse(text);
|
|
97
|
+
cwd = typeof v.cwd === "string" ? v.cwd : null;
|
|
98
|
+
}
|
|
99
|
+
// Being rewritten: read again next pass. Until then whose it is can't be known, so no instance's scan is
|
|
100
|
+
// complete (no coverage, and no cursor is pruned — Prism #2605).
|
|
101
|
+
catch {
|
|
102
|
+
tuiFailed = true;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
tuiIndex[path] = { sig: s.sig, cwd };
|
|
107
|
+
tuiFiles.push({ path, sig: s.sig, size: s.size, cwd });
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
if (!gone(err))
|
|
111
|
+
tuiFailed = true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
for (const inst of input.instances) {
|
|
116
|
+
const res = { name: inst.name, updates: [], live: [], failed: tuiFailed };
|
|
117
|
+
const cwds = new Set(inst.cwds);
|
|
118
|
+
const afterOf = (key) => Math.max(inst.cursors[key]?.after ?? -Infinity, input.cutoff);
|
|
119
|
+
const push = (key, sig, turns) => res.updates.push({ key, sig, after: turns.reduce((m, t) => Math.max(m, t.t), afterOf(key)), turns });
|
|
120
|
+
// Classic: its working directory's rows.
|
|
121
|
+
let db = null;
|
|
122
|
+
try {
|
|
123
|
+
db = openDb(inst.dbPath);
|
|
124
|
+
const rows = db ? db.prepare("SELECT conversation_id AS id, key, updated_at AS u, octet_length(value) AS n FROM conversations_v2 WHERE updated_at >= ?").all(input.cutoff) : [];
|
|
125
|
+
for (const r of rows) {
|
|
126
|
+
if (!cwds.has(r.key))
|
|
127
|
+
continue;
|
|
128
|
+
const key = `classic:${r.id}`, sig = String(r.u);
|
|
129
|
+
res.live.push(key);
|
|
130
|
+
if (inst.cursors[key]?.sig === sig || !within(r.n))
|
|
131
|
+
continue;
|
|
132
|
+
const row = db.prepare("SELECT value FROM conversations_v2 WHERE key = ? AND conversation_id = ?").get(r.key, r.id);
|
|
133
|
+
if (!row?.value)
|
|
134
|
+
continue;
|
|
135
|
+
let v;
|
|
136
|
+
try {
|
|
137
|
+
v = JSON.parse(row.value);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
push(key, sig, kiroClassicTurns(v, afterOf(key)));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
res.failed = true;
|
|
147
|
+
}
|
|
148
|
+
// TUI: the sessions whose cwd is its working directory.
|
|
149
|
+
for (const f of tuiFiles) {
|
|
150
|
+
if (f.cwd === null || !cwds.has(f.cwd))
|
|
151
|
+
continue;
|
|
152
|
+
const key = `tui:${f.path}`;
|
|
153
|
+
res.live.push(key);
|
|
154
|
+
if (inst.cursors[key]?.sig === f.sig)
|
|
155
|
+
continue;
|
|
156
|
+
const sidecar = f.path.replace(/\.json$/, ".jsonl");
|
|
157
|
+
let size = f.size;
|
|
158
|
+
try {
|
|
159
|
+
size += statSync(sidecar).size;
|
|
160
|
+
}
|
|
161
|
+
catch { /* none yet */ }
|
|
162
|
+
if (!within(size))
|
|
163
|
+
continue;
|
|
164
|
+
try {
|
|
165
|
+
const session = JSON.parse(readFileSync(f.path, "utf8"));
|
|
166
|
+
const id = typeof session.session_id === "string" ? session.session_id : "";
|
|
167
|
+
push(key, f.sig, kiroTuiTurns(session, lines(sidecar), afterOf(key), id ? classicTimes(db, id) : []));
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
if (!gone(err))
|
|
171
|
+
res.failed = true;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// V3: its working directory's bucket.
|
|
175
|
+
for (const dir of new Set(inst.cwds.map(c => join(input.kiroHome, "sessions", kasBucket(c))))) {
|
|
176
|
+
let names = [];
|
|
177
|
+
try {
|
|
178
|
+
names = readdirSync(dir).filter(n => !n.startsWith("."));
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
if (!gone(err))
|
|
182
|
+
res.failed = true;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
for (const n of names) {
|
|
186
|
+
const sessionPath = join(dir, n, "session.json"), messagesPath = join(dir, n, "messages.jsonl");
|
|
187
|
+
try {
|
|
188
|
+
const a = sigOf(sessionPath);
|
|
189
|
+
let m = { sig: "-", size: 0, mtimeMs: 0 };
|
|
190
|
+
try {
|
|
191
|
+
m = sigOf(messagesPath);
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
if (!gone(err))
|
|
195
|
+
throw err;
|
|
196
|
+
}
|
|
197
|
+
if (Math.max(a.mtimeMs, m.mtimeMs) < input.cutoff)
|
|
198
|
+
continue;
|
|
199
|
+
const key = `kas:${join(dir, n)}`, sig = `${a.sig}|${m.sig}`;
|
|
200
|
+
res.live.push(key);
|
|
201
|
+
if (inst.cursors[key]?.sig === sig || !within(a.size + m.size))
|
|
202
|
+
continue;
|
|
203
|
+
const session = JSON.parse(readFileSync(sessionPath, "utf8"));
|
|
204
|
+
// A converted session's id is `cli_<classic id>_<suffix>`: its source's requests are counted there.
|
|
205
|
+
const source = /^cli_(.+)_[^_]+$/.exec(n)?.[1];
|
|
206
|
+
push(key, sig, kiroKasTurns(session, lines(messagesPath), afterOf(key), source ? classicTimes(db, source) : []));
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
if (!gone(err))
|
|
210
|
+
res.failed = true;
|
|
211
|
+
} // being rewritten (SyntaxError) included: next pass
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
out.push(res);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
finally {
|
|
218
|
+
for (const db of dbs.values())
|
|
219
|
+
db?.close();
|
|
220
|
+
}
|
|
221
|
+
return { instances: out, tuiIndex, readBytes: input.maxBytes - budget, behindBytes, behindSources };
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=kiro-usage-scan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ki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AM,MAAM,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;wBAC/C,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oBACnH,CAAC;oBAAC,OAAO,GAAG,EAAE,CAAC;wBAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;4BAAE,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC;oBAAC,CAAC,CAAG,oDAAoD;gBAC7G,CAAC;YACH,CAAC;YACD,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;YAAS,CAAC;QACT,KAAK,MAAM,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE;YAAE,EAAE,EAAE,KAAK,EAAE,CAAC;IAC7C,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,QAAQ,GAAG,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC;AACtG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** #2122: the Kiro usage scan's thread (kiro-usage-scan.ts): one scan per worker, its answer posted back. */
|
|
2
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
3
|
+
import { scanKiroUsage } from "./kiro-usage-scan.js";
|
|
4
|
+
try {
|
|
5
|
+
parentPort?.postMessage({ ok: true, out: scanKiroUsage(workerData) });
|
|
6
|
+
}
|
|
7
|
+
catch (err) {
|
|
8
|
+
parentPort?.postMessage({ ok: false, error: String(err) });
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=kiro-usage-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kiro-usage-worker.js","sourceRoot":"","sources":["../src/kiro-usage-worker.ts"],"names":[],"mappings":"AAAA,6GAA6G;AAC7G,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAsB,MAAM,sBAAsB,CAAC;AAEzE,IAAI,CAAC;IAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,aAAa,CAAC,UAA2B,CAAC,EAAE,CAAC,CAAC;AAAC,CAAC;AAC/F,OAAO,GAAG,EAAE,CAAC;IAAC,UAAU,EAAE,WAAW,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAAC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #2122 §10 step 2: Kiro's usage, ESTIMATED. Kiro records no token counts (design §10.1: every `request_metadata` token
|
|
3
|
+
* field is null in the classic store, every `*_token_count` 0 in the TUI one, and V3 has no such field), so each turn is
|
|
4
|
+
* estimated from its text size the way tokscale does — the same basis as the user's tokscale-based reports (the user's
|
|
5
|
+
* decision, option B). Kiro keeps a conversation in one of three stores, by engine:
|
|
6
|
+
* - classic (legacy UI, engine v1): `<XDG_DATA_HOME>/kiro-cli/data.sqlite3`, table `conversations_v2` — kiroClassicTurns;
|
|
7
|
+
* - TUI (engine v2): `<KIRO_HOME>/sessions/cli/<id>.json` with its `<id>.jsonl` — kiroTuiTurns;
|
|
8
|
+
* - V3 (KAS): `<KIRO_HOME>/sessions/<bucket>/sess_<id>/{session.json, messages.jsonl}` — kiroKasTurns.
|
|
9
|
+
* The estimate:
|
|
10
|
+
* - fresh input: ceil(bytes / 4) of the prompt (its recorded `user_prompt_length`, else the prompt text) plus the tool
|
|
11
|
+
* results the turn sent;
|
|
12
|
+
* - output: ceil(bytes / 4) of the response (`response_size`, TUI `assistant_response_length`, else its text);
|
|
13
|
+
* - cache read: the context the turn resent, `floor(window × context_usage_percentage / 100) − fresh input` (never below
|
|
14
|
+
* 0); the window is the conversation's `context_window_tokens` (classic: none → no cache read; TUI: none → 200,000;
|
|
15
|
+
* V3 records none: 200,000);
|
|
16
|
+
* - cache write and reasoning: 0. A real count, should Kiro ever record one above 0, is taken instead.
|
|
17
|
+
* Credits are not read: the user's plan is not billed in them (design §10.2).
|
|
18
|
+
*
|
|
19
|
+
* The estimation formula and field mapping follow tokscale (github.com/junhoyeo/tokscale,
|
|
20
|
+
* crates/tokscale-core/src/sessions/kiro.rs at 669fdaeec54502a30468adbfa97789bb7ee2b762), MIT License,
|
|
21
|
+
* Copyright (c) 2025 Junho Yeo — see THIRD_PARTY_NOTICES.md. The code is AgEnD's own. Pure: no I/O.
|
|
22
|
+
*/
|
|
23
|
+
import type { Turn } from "./cache-ledger.js";
|
|
24
|
+
/** The window when a TUI or V3 session records none (tokscale's DEFAULT_CONTEXT_WINDOW). */
|
|
25
|
+
export declare const KIRO_DEFAULT_WINDOW = 200000;
|
|
26
|
+
export interface KiroClassicTurn extends Turn {
|
|
27
|
+
index: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The estimated turns of one classic conversation (`conversations_v2.value`, parsed) whose request started after
|
|
31
|
+
* `after` (ms). One turn per `history[]` entry with `request_metadata`; an entry estimated at nothing is skipped.
|
|
32
|
+
*/
|
|
33
|
+
export declare function kiroClassicTurns(conversation: unknown, after: number): KiroClassicTurn[];
|
|
34
|
+
/** The request start times a classic conversation recorded (for the cross-store dedup below). */
|
|
35
|
+
export declare function kiroClassicRequestTimes(conversation: unknown): number[];
|
|
36
|
+
export interface KiroTuiTurn extends Turn {
|
|
37
|
+
index: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The estimated turns of one TUI session — its `<id>.json` (parsed) and the lines of its `<id>.jsonl` — that started
|
|
41
|
+
* after `after` (ms). Only the messages a turn's `message_ids` name count toward it: the sidecar also carries the
|
|
42
|
+
* messages a conversation brought over from the classic engine.
|
|
43
|
+
*
|
|
44
|
+
* Dedup across stores (design §10.1): a conversation can have turns in both engines under one id. A TUI turn whose
|
|
45
|
+
* window [end − turn_duration, end] holds a request of the same conversation's classic record (`classicTimes`) is that
|
|
46
|
+
* request's, counted from the classic store: it is dropped here.
|
|
47
|
+
*/
|
|
48
|
+
export declare function kiroTuiTurns(session: unknown, jsonlLines: Iterable<string>, after: number, classicTimes?: readonly number[]): KiroTuiTurn[];
|
|
49
|
+
/**
|
|
50
|
+
* The estimated turns of one V3 (KAS) session — its `session.json` (parsed) and the lines of its `messages.jsonl` — that
|
|
51
|
+
* started after `after` (ms). A turn runs to its `turn_end`: its `user` text and `tool_result` text are its fresh input,
|
|
52
|
+
* its `assistant` text its output, and its last `contextUsage` its context. The window is 200,000 (V3 records none).
|
|
53
|
+
*
|
|
54
|
+
* A session converted from another engine (`ensure-session`: a new id, the history copied in) holds turns that store
|
|
55
|
+
* already counted: a turn that ended before the session was created (`createdAt`) is not counted again, nor one whose
|
|
56
|
+
* window holds a request of its source's classic record (`classicTimes`).
|
|
57
|
+
*/
|
|
58
|
+
export declare function kiroKasTurns(session: unknown, jsonlLines: Iterable<string>, after: number, classicTimes?: readonly number[]): Turn[];
|