@songsid/agend 2.4.0-beta.20 → 2.4.0-beta.22
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/agent-cli-instructions.md +1 -1
- package/dist/backend/claude-carry.d.ts +11 -0
- package/dist/backend/claude-carry.js +88 -6
- package/dist/backend/claude-carry.js.map +1 -1
- package/dist/backend/claude-code.js +3 -0
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/cache-ledger.d.ts +23 -21
- package/dist/cache-ledger.js +70 -6
- package/dist/cache-ledger.js.map +1 -1
- package/dist/cache-prices.d.ts +8 -6
- package/dist/cache-prices.js +12 -5
- package/dist/cache-prices.js.map +1 -1
- package/dist/cache-service.d.ts +9 -5
- package/dist/cache-service.js +202 -50
- package/dist/cache-service.js.map +1 -1
- package/dist/channel/mcp-tools.js +6 -4
- package/dist/channel/mcp-tools.js.map +1 -1
- package/dist/cli-audited.js +2 -1
- package/dist/cli-audited.js.map +1 -1
- package/dist/cli.js +4 -1
- package/dist/cli.js.map +1 -1
- package/dist/contact-auth-policy.js +1 -1
- package/dist/contact-auth-policy.js.map +1 -1
- package/dist/contact-auth-service.js +8 -2
- package/dist/contact-auth-service.js.map +1 -1
- package/dist/contact-auth-store.d.ts +3 -0
- package/dist/contact-auth-store.js +34 -8
- package/dist/contact-auth-store.js.map +1 -1
- package/dist/contact-auth-types.d.ts +3 -2
- package/dist/contact-auth-types.js.map +1 -1
- package/dist/contact-change-proposals.d.ts +47 -0
- package/dist/contact-change-proposals.js +132 -0
- package/dist/contact-change-proposals.js.map +1 -0
- package/dist/daemon.d.ts +31 -0
- package/dist/daemon.js +149 -2
- package/dist/daemon.js.map +1 -1
- package/dist/delivery-outbox.d.ts +10 -0
- package/dist/delivery-outbox.js +21 -0
- package/dist/delivery-outbox.js.map +1 -1
- package/dist/fleet-manager.d.ts +65 -1
- package/dist/fleet-manager.js +338 -20
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/concepts/SKILL.md +2 -1
- package/dist/general-knowledge/skills/hub/SKILL.md +45 -5
- package/dist/general-knowledge/skills/task-board/SKILL.md +4 -0
- package/dist/general-knowledge/skills/web-appearance/SKILL.md +1 -1
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +16 -6
- package/dist/hub/agent-pictures-model.d.ts +275 -0
- package/dist/hub/agent-pictures-model.js +103 -0
- package/dist/hub/agent-pictures-model.js.map +1 -0
- package/dist/hub/agent-pictures.d.ts +64 -0
- package/dist/hub/agent-pictures.js +255 -0
- package/dist/hub/agent-pictures.js.map +1 -0
- package/dist/hub/client.d.ts +4 -0
- package/dist/hub/client.js +23 -2
- package/dist/hub/client.js.map +1 -1
- package/dist/hub/compose/member.d.ts +14 -3
- package/dist/hub/compose/member.js +46 -10
- package/dist/hub/compose/member.js.map +1 -1
- package/dist/hub/compose/server.d.ts +6 -5
- package/dist/hub/compose/server.js +7 -3
- package/dist/hub/compose/server.js.map +1 -1
- package/dist/hub/direct-posts-model.d.ts +1 -0
- package/dist/hub/direct-posts-model.js +2 -0
- package/dist/hub/direct-posts-model.js.map +1 -0
- package/dist/hub/direct-posts.d.ts +36 -0
- package/dist/hub/direct-posts.js +145 -0
- package/dist/hub/direct-posts.js.map +1 -0
- package/dist/hub/http/compose.d.ts +5 -0
- package/dist/hub/http/compose.js +158 -20
- package/dist/hub/http/compose.js.map +1 -1
- package/dist/hub/http/core.d.ts +9 -1
- package/dist/hub/http/core.js +21 -1
- package/dist/hub/http/core.js.map +1 -1
- package/dist/hub/http/deps.d.ts +1 -0
- package/dist/hub/http/schema.js +7 -0
- package/dist/hub/http/schema.js.map +1 -1
- package/dist/hub/init/text.js +1 -1
- package/dist/hub/join/service.d.ts +2 -0
- package/dist/hub/join/service.js +7 -3
- package/dist/hub/join/service.js.map +1 -1
- package/dist/hub/member/agent-pictures.d.ts +76 -0
- package/dist/hub/member/agent-pictures.js +196 -0
- package/dist/hub/member/agent-pictures.js.map +1 -0
- package/dist/hub/member/direct-rooms.d.ts +9 -0
- package/dist/hub/member/direct-rooms.js +14 -0
- package/dist/hub/member/direct-rooms.js.map +1 -0
- package/dist/hub/member/room-ask.d.ts +22 -1
- package/dist/hub/member/room-ask.js +99 -5
- package/dist/hub/member/room-ask.js.map +1 -1
- package/dist/hub/member/room-asker-store.d.ts +48 -0
- package/dist/hub/member/room-asker-store.js +181 -0
- package/dist/hub/member/room-asker-store.js.map +1 -0
- package/dist/hub/member/room-post.d.ts +11 -10
- package/dist/hub/member/room-post.js +51 -7
- package/dist/hub/member/room-post.js.map +1 -1
- package/dist/hub/policy.d.ts +11 -2
- package/dist/hub/policy.js +60 -7
- package/dist/hub/policy.js.map +1 -1
- package/dist/hub/protocol.d.ts +254 -1
- package/dist/hub/protocol.js +20 -8
- package/dist/hub/protocol.js.map +1 -1
- package/dist/hub/representative.d.ts +38 -0
- package/dist/hub/representative.js +140 -12
- package/dist/hub/representative.js.map +1 -1
- package/dist/hub/room-asker-identity-model.d.ts +53 -0
- package/dist/hub/room-asker-identity-model.js +14 -0
- package/dist/hub/room-asker-identity-model.js.map +1 -0
- package/dist/hub/room-asker-identity.d.ts +22 -0
- package/dist/hub/room-asker-identity.js +43 -0
- package/dist/hub/room-asker-identity.js.map +1 -0
- package/dist/hub/rooms/agents.d.ts +2 -0
- package/dist/hub/rooms/agents.js +30 -3
- package/dist/hub/rooms/agents.js.map +1 -1
- package/dist/hub/rooms/asker-identity.d.ts +21 -0
- package/dist/hub/rooms/asker-identity.js +86 -0
- package/dist/hub/rooms/asker-identity.js.map +1 -0
- package/dist/hub/rooms/direct-view.d.ts +3 -2
- package/dist/hub/rooms/direct-view.js +23 -8
- package/dist/hub/rooms/direct-view.js.map +1 -1
- package/dist/hub/rooms/office.d.ts +27 -0
- package/dist/hub/rooms/office.js +12 -2
- package/dist/hub/rooms/office.js.map +1 -1
- package/dist/hub/rooms/service.d.ts +38 -1
- package/dist/hub/rooms/service.js +56 -3
- package/dist/hub/rooms/service.js.map +1 -1
- package/dist/hub/rooms/types.d.ts +5 -2
- package/dist/hub/rooms.d.ts +9 -0
- package/dist/hub/rooms.js +97 -26
- package/dist/hub/rooms.js.map +1 -1
- package/dist/hub/runtime.d.ts +1 -1
- package/dist/hub/server.js +24 -2
- package/dist/hub/server.js.map +1 -1
- package/dist/hub/session-directory-transition.d.ts +1 -0
- package/dist/hub/session-directory-transition.js +15 -9
- package/dist/hub/session-directory-transition.js.map +1 -1
- package/dist/hub/session-limits.d.ts +58 -0
- package/dist/hub/session-limits.js +121 -0
- package/dist/hub/session-limits.js.map +1 -0
- package/dist/hub/sessions.d.ts +1 -1
- package/dist/hub/sessions.js +13 -7
- package/dist/hub/sessions.js.map +1 -1
- package/dist/hub/settings-directory-decision.js +1 -1
- package/dist/hub/settings-directory-decision.js.map +1 -1
- package/dist/hub/types.d.ts +9 -2
- package/dist/hub-character-plan.d.ts +47 -0
- package/dist/hub-character-plan.js +70 -0
- package/dist/hub-character-plan.js.map +1 -0
- package/dist/hub-contact-windows.d.ts +13 -1
- package/dist/hub-contact-windows.js +35 -2
- package/dist/hub-contact-windows.js.map +1 -1
- package/dist/hub-picture-reduce.d.ts +34 -0
- package/dist/hub-picture-reduce.js +101 -0
- package/dist/hub-picture-reduce.js.map +1 -0
- package/dist/hub-picture-worker.d.ts +1 -0
- package/dist/hub-picture-worker.js +19 -0
- package/dist/hub-picture-worker.js.map +1 -0
- package/dist/hub-report-target.d.ts +6 -0
- package/dist/hub-report-target.js +6 -0
- package/dist/hub-report-target.js.map +1 -1
- package/dist/locale.js +357 -265
- package/dist/locale.js.map +1 -1
- package/dist/ls-rows.d.ts +2 -0
- package/dist/ls-rows.js.map +1 -1
- package/dist/needs-you.d.ts +6 -0
- package/dist/needs-you.js +3 -1
- package/dist/needs-you.js.map +1 -1
- package/dist/outbound-handlers.d.ts +8 -0
- package/dist/outbound-handlers.js +53 -6
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/outbound-schemas.d.ts +2 -0
- package/dist/outbound-schemas.js +6 -4
- package/dist/outbound-schemas.js.map +1 -1
- package/dist/runtime-cli-install.js +4 -4
- package/dist/runtime-cli-install.js.map +1 -1
- package/dist/task-board-tool.d.ts +17 -0
- package/dist/task-board-tool.js +58 -6
- package/dist/task-board-tool.js.map +1 -1
- package/dist/tips.js +3 -3
- package/dist/tool-permissions.js +2 -2
- package/dist/tool-permissions.js.map +1 -1
- package/dist/ui/agent-export-strings.js +1 -1
- package/dist/ui/agent-page-strings.js +5 -5
- package/dist/ui/contact-auth-client.js +2 -2
- package/dist/ui/contact-tool-groups.js +1 -1
- package/dist/ui/fleet-cache.js +5 -5
- package/dist/ui/fleet-canvas.js +3 -2
- package/dist/ui/fleet-office-card.js +46 -7
- package/dist/ui/fleet-office-dialogue.d.ts +6 -3
- package/dist/ui/fleet-office-dialogue.js +13 -3
- package/dist/ui/fleet-office-layout.js +15 -15
- package/dist/ui/fleet-office-model.js +3 -2
- package/dist/ui/fleet-office-overview.js +1 -1
- package/dist/ui/fleet-office-pack.d.ts +17 -7
- package/dist/ui/fleet-office-pack.js +106 -38
- package/dist/ui/fleet-office-play.js +11 -4
- package/dist/ui/fleet-office-skin.js +41 -11
- package/dist/ui/fleet-office-store.js +10 -1
- package/dist/ui/fleet-office-talk.js +423 -0
- package/dist/ui/fleet-office-view.js +58 -17
- package/dist/ui/fleet-office-zones.js +20 -12
- package/dist/ui/fleet-office.js +250 -65
- package/dist/ui/fleet-org.js +3 -3
- package/dist/ui/fleet-task-common.js +3 -3
- package/dist/ui/fleet-task-sort.js +88 -0
- package/dist/ui/fleet-task-view.js +38 -9
- package/dist/ui/fleet-tasks.js +47 -15
- package/dist/ui/fleet-usage.js +6 -6
- package/dist/ui/hub-admin-overview.js +1 -1
- package/dist/ui/hub-chat-store.js +4 -3
- package/dist/ui/hub-chat-strings.js +3 -1
- package/dist/ui/hub-client.js +3 -0
- package/dist/ui/hub-my-agents-strings.js +2 -2
- package/dist/ui/hub-my-agents.js +3 -0
- package/dist/ui/hub-room-composer.js +24 -4
- package/dist/ui/hub-room-members.js +7 -3
- package/dist/ui/hub-room-office.js +71 -2
- package/dist/ui/hub-room-presence.js +14 -0
- package/dist/ui/hub-room-strings.js +18 -2
- package/dist/ui/hub-room-thread.js +82 -13
- package/dist/ui/hub-room-working.js +37 -0
- package/dist/ui/hub-session-limits.js +79 -0
- package/dist/ui/panel-fleet.js +5 -5
- package/dist/ui/panel-hub.js +41 -6
- package/dist/ui/panel-log.js +3 -3
- package/dist/ui/panel-needs.js +28 -2
- package/dist/ui/panel-runtimes.js +2 -2
- package/dist/ui/runtime-cli-install.js +1 -1
- package/dist/ui/runtime-update-status.js +1 -1
- package/dist/ui/settings-access-strings.js +1 -1
- package/dist/ui/settings-hub-setup-strings.js +1 -1
- package/dist/ui/settings-layout.js +2 -2
- package/dist/ui/settings-named-test.js +16 -16
- package/dist/ui/settings-public-session-strings.js +2 -2
- package/dist/ui/settings-revoke-strings.js +1 -1
- package/dist/ui/settings-shared-strings.js +2 -2
- package/dist/ui/settings-strings.js +40 -40
- package/dist/ui/shared/app-shell.js +1 -1
- package/dist/ui/shared/app.css +106 -6
- package/dist/ui/shared/chat-strings.js +9 -9
- package/dist/ui/shared/hub-owner.css +5 -0
- package/dist/ui/shared/hub-rooms-u2.css +3 -0
- package/dist/ui/shared/instance-nav.js +36 -2
- package/dist/ui/shared/office-dialogue.css +110 -0
- package/dist/ui/shared/task-board.css +103 -7
- package/dist/ui/shared/view-strings.js +27 -9
- package/dist/web-api.d.ts +5 -0
- package/dist/web-api.js +29 -0
- package/dist/web-api.js.map +1 -1
- package/dist/web-office-skins.d.ts +8 -2
- package/dist/web-office-skins.js +33 -14
- package/dist/web-office-skins.js.map +1 -1
- package/dist/web-office-store.js +5 -3
- package/dist/web-office-store.js.map +1 -1
- package/package.json +1 -1
package/dist/cache-service.js
CHANGED
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* thread (kiro-usage-run.ts) — for the usage report only; the cache analysis leaves Kiro out.
|
|
18
18
|
*/
|
|
19
19
|
import { mkdir, open, readdir, readFile, realpath, rename, stat, writeFile } from "node:fs/promises";
|
|
20
|
-
import { dirname, join, resolve } from "node:path";
|
|
20
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
21
21
|
import { scanJsonl } from "./cache-scan.js";
|
|
22
|
-
import { addSpeed, addTurn, claudeLine, codexLine, emptyLedger, grokLine, museLine, KEEP_DAYS, pruneLedger, reviveLedger } from "./cache-ledger.js";
|
|
22
|
+
import { addSpeed, addTurn, claudeLine, codexLine, codexRebuild, emptyLedger, grokLine, museLine, KEEP_DAYS, pruneLedger, reviveLedger } from "./cache-ledger.js";
|
|
23
23
|
import { analyzeLedger } from "./cache-analysis.js";
|
|
24
24
|
import { PRICES_CHECKED, PRICE_SOURCES } from "./cache-prices.js";
|
|
25
25
|
import { addCoverage, carryPruned, foldHours, pruneDays, readDays, readLifetime, writeDays } from "./usage-rollup.js";
|
|
@@ -30,6 +30,10 @@ import { profileAt, readProfileTimeline } from "./usage/profile-timeline.js";
|
|
|
30
30
|
export const WINDOWS = { "24h": 86_400_000, "7d": 7 * 86_400_000, "30d": 30 * 86_400_000 };
|
|
31
31
|
/** A window name as asked (a query string, a tool argument); anything unknown is the default, 7 days. */
|
|
32
32
|
export const cacheWindow = (w) => (Object.prototype.hasOwnProperty.call(WINDOWS, w) ? w : "7d");
|
|
33
|
+
const rolloutSessionId = (path) => {
|
|
34
|
+
const stem = basename(path, ".jsonl");
|
|
35
|
+
return /^rollout-.*-([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})$/i.exec(stem)?.[1] ?? stem;
|
|
36
|
+
};
|
|
33
37
|
const DAY = 86_400_000;
|
|
34
38
|
const META_MAX_BYTES = 256 * 1024; // session_meta carries the instructions (~22 KB in real rollouts)
|
|
35
39
|
const kindOf = (backend) => (backend === "claude-code" ? "claude" : backend === "codex" ? "codex" : backend === "kiro-cli" ? "kiro" : backend === "grok" ? "grok" : backend === "muse" ? "muse" : backend === "opencode" ? "opencode" : backend === "antigravity" ? "antigravity" : null);
|
|
@@ -125,7 +129,7 @@ export class CacheService {
|
|
|
125
129
|
for (;;) {
|
|
126
130
|
const left = await this.pass();
|
|
127
131
|
if (left === 0) {
|
|
128
|
-
this.caughtUp =
|
|
132
|
+
this.caughtUp = ![...this.ledgers.values()].some(l => l.codexRebuild);
|
|
129
133
|
await this.recordCoverage();
|
|
130
134
|
}
|
|
131
135
|
// Stop looping when: all caught up, explicitly stopped, or closing (stop()
|
|
@@ -286,17 +290,48 @@ export class CacheService {
|
|
|
286
290
|
await this.keepHistory(inst, cutoff);
|
|
287
291
|
continue;
|
|
288
292
|
}
|
|
289
|
-
const
|
|
293
|
+
const published = await this.ledgerFor(inst);
|
|
294
|
+
// A bounded, restartable replacement generation repairs already inflated recent hours. Do not publish a
|
|
295
|
+
// partially read replacement, nor tag old totals as repaired merely because new dedupe was enabled.
|
|
296
|
+
let ledger = kind === "codex" && (published.codexMethod !== 1 || published.codexRebuild)
|
|
297
|
+
? (published.codexRebuild ??= codexRebuild(published, cutoff)) : published;
|
|
290
298
|
if (kind === "kiro" || kind === "opencode" || kind === "antigravity") {
|
|
291
299
|
pruneLedger(ledger, cutoff, await this.foldBeforePrune(inst, ledger, cutoff));
|
|
292
300
|
continue;
|
|
293
301
|
}
|
|
294
302
|
const files = kind === "claude" ? await this.claudeFiles(inst, cutoff) : kind === "grok" ? await this.grokFiles(inst, cutoff)
|
|
295
303
|
: kind === "muse" ? muse.get(inst.name) ?? [] : codex.get(inst.name) ?? [];
|
|
304
|
+
const listed = new Set(files.map((f) => f.path));
|
|
305
|
+
if (kind === "codex")
|
|
306
|
+
for (const generation of new Set([published, ledger])) {
|
|
307
|
+
for (const f of files) {
|
|
308
|
+
if (generation.files[f.path])
|
|
309
|
+
continue;
|
|
310
|
+
const id = "sessionId" in f && typeof f.sessionId === "string" ? f.sessionId : rolloutSessionId(f.path);
|
|
311
|
+
const moved = Object.entries(generation.files).find(([path, cur]) => !listed.has(path) && cur.kind === "codex" && cur.ino === f.ino && (cur.sessionId ?? rolloutSessionId(path)) === id);
|
|
312
|
+
if (!moved)
|
|
313
|
+
continue;
|
|
314
|
+
const [before, cur] = moved;
|
|
315
|
+
generation.files[f.path] = cur;
|
|
316
|
+
delete generation.files[before];
|
|
317
|
+
for (const event of Object.values(generation.codexEvents ?? {}))
|
|
318
|
+
if (event.path === before)
|
|
319
|
+
event.path = f.path;
|
|
320
|
+
this.dirty.add(inst.name);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (kind === "codex" && ledger === published && files.some(f => "parentPath" in f && f.parentPath && published.files[f.path]?.orphaned)) {
|
|
324
|
+
ledger = published.codexRebuild = codexRebuild(published, cutoff);
|
|
325
|
+
}
|
|
296
326
|
// A listing that could not read everything is no inventory: a cursor it missed stays, or the file would be counted
|
|
297
327
|
// again from its start once it is listed (Prism #2605). An instance whose store stays unreadable keeps its cursors
|
|
298
328
|
// until it is readable again — bounded by its own files.
|
|
299
|
-
const
|
|
329
|
+
const terminalParents = new Set(files.flatMap(f => "missingParent" in f && typeof f.missingParent === "string" ? [f.missingParent] : []));
|
|
330
|
+
if (ledger !== published && Object.entries(published.files).some(([path, f]) => f.kind === "codex" && (f.last?.t ?? 0) >= cutoff && !listed.has(path) && !terminalParents.has(f.sessionId ?? rolloutSessionId(path)))) {
|
|
331
|
+
// A repair cannot turn unavailable recent source data into a measured zero. Keep the published generation;
|
|
332
|
+
// a later complete inventory can resume the candidate without erasing the only surviving accounting.
|
|
333
|
+
this.unread.add(inst.name);
|
|
334
|
+
}
|
|
300
335
|
// #3066 §1d: a Codex turn's profile is the one its run was launched under (read once a pass, off the thread).
|
|
301
336
|
const spans = kind === "codex" && inst.profileTimelinePath ? await readProfileTimeline(inst.profileTimelinePath) : null;
|
|
302
337
|
const profileOf = spans && spans.length ? (t) => profileAt(spans, t) : inst.profile;
|
|
@@ -306,6 +341,7 @@ export class CacheService {
|
|
|
306
341
|
delete ledger.files[path];
|
|
307
342
|
this.dirty.add(inst.name);
|
|
308
343
|
}
|
|
344
|
+
let instanceBehind = false;
|
|
309
345
|
for (const f of files) {
|
|
310
346
|
let cur = ledger.files[f.path];
|
|
311
347
|
if (!cur) {
|
|
@@ -316,17 +352,32 @@ export class CacheService {
|
|
|
316
352
|
cur = this.followFromEnd(ledger, f.path, cur, f.ino, f.size);
|
|
317
353
|
this.dirty.add(inst.name);
|
|
318
354
|
}
|
|
355
|
+
if ("sessionId" in f && typeof f.sessionId === "string" && cur.sessionId !== f.sessionId) {
|
|
356
|
+
cur.sessionId = f.sessionId;
|
|
357
|
+
this.dirty.add(inst.name);
|
|
358
|
+
}
|
|
359
|
+
if ("orphaned" in f && f.orphaned)
|
|
360
|
+
cur.orphaned = true;
|
|
361
|
+
else
|
|
362
|
+
delete cur.orphaned;
|
|
319
363
|
if (cur.offset >= f.size)
|
|
320
364
|
continue;
|
|
321
365
|
// Only an unfinished line was left, and the file has not grown since: nothing new to read.
|
|
322
366
|
if (cur.stalled === f.size)
|
|
323
367
|
continue;
|
|
324
|
-
|
|
368
|
+
const parentPath = "parentPath" in f ? f.parentPath : undefined;
|
|
369
|
+
const parent = parentPath ? files.find(p => p.path === parentPath) : undefined;
|
|
370
|
+
const parentCursor = parent ? ledger.files[parent.path] : undefined;
|
|
371
|
+
const waitingForParent = parent && (parentCursor?.offset ?? 0) < parent.size && parentCursor?.stalled !== parent.size;
|
|
372
|
+
if (waitingForParent && this.unread.has(inst.name))
|
|
373
|
+
continue;
|
|
374
|
+
if (budget <= 0 || waitingForParent) {
|
|
325
375
|
behindBytes += f.size - cur.offset;
|
|
326
376
|
behindFiles++;
|
|
377
|
+
instanceBehind = true;
|
|
327
378
|
continue;
|
|
328
379
|
}
|
|
329
|
-
const done = await this.read(ledger, cur, f.path, budget, cutoff, profileOf);
|
|
380
|
+
const done = await this.read(ledger, cur, f.path, budget, cutoff, profileOf, "identityOnly" in f && f.identityOnly === true);
|
|
330
381
|
if (done.failed)
|
|
331
382
|
this.unread.add(inst.name);
|
|
332
383
|
this.dirty.add(inst.name);
|
|
@@ -334,8 +385,22 @@ export class CacheService {
|
|
|
334
385
|
if (done.behind > 0) {
|
|
335
386
|
behindBytes += done.behind;
|
|
336
387
|
behindFiles++;
|
|
388
|
+
instanceBehind = true;
|
|
337
389
|
}
|
|
338
390
|
}
|
|
391
|
+
if (kind === "codex" && !this.unread.has(inst.name)) {
|
|
392
|
+
// Retain old fingerprints as long as an inventoried descendant still references them, including ancient
|
|
393
|
+
// inherited prefixes. Pruning by event date would recount an old prefix when a new fork appears today.
|
|
394
|
+
for (const [key, event] of Object.entries(ledger.codexEvents ?? {}))
|
|
395
|
+
if (!ledger.files[event.path])
|
|
396
|
+
delete ledger.codexEvents[key];
|
|
397
|
+
}
|
|
398
|
+
if (ledger !== published) {
|
|
399
|
+
this.dirty.add(inst.name);
|
|
400
|
+
if (instanceBehind || this.unread.has(inst.name))
|
|
401
|
+
continue;
|
|
402
|
+
this.ledgers.set(inst.name, ledger);
|
|
403
|
+
}
|
|
339
404
|
// #2122: fold, then prune — the ledger never drops an hour the rollup does not durably hold.
|
|
340
405
|
pruneLedger(ledger, cutoff, await this.foldBeforePrune(inst, ledger, cutoff));
|
|
341
406
|
}
|
|
@@ -640,7 +705,7 @@ export class CacheService {
|
|
|
640
705
|
next.ttl = cur.ttl;
|
|
641
706
|
return ledger.files[path] = next;
|
|
642
707
|
}
|
|
643
|
-
async read(ledger, cur, path, budget, cutoff, profile) {
|
|
708
|
+
async read(ledger, cur, path, budget, cutoff, profile, identityOnly = false) {
|
|
644
709
|
const pf = (t) => (typeof profile === "function" ? profile(t) : profile);
|
|
645
710
|
try {
|
|
646
711
|
const res = await scanJsonl(path, cur.offset, { maxBytes: budget, ino: cur.ino }, (line) => {
|
|
@@ -650,13 +715,30 @@ export class CacheService {
|
|
|
650
715
|
return;
|
|
651
716
|
}
|
|
652
717
|
const turn = cur.kind === "claude" ? claudeLine(line, cur) : cur.kind === "muse" ? museLine(line, cur) : codexLine(line, cur);
|
|
718
|
+
let replay = identityOnly;
|
|
719
|
+
if (turn?.eventKey) {
|
|
720
|
+
const events = ledger.codexEvents ??= dict();
|
|
721
|
+
const original = events[turn.eventKey];
|
|
722
|
+
if (original !== undefined) {
|
|
723
|
+
replay = true;
|
|
724
|
+
turn.t = original.t;
|
|
725
|
+
if (!ledger.files[original.path])
|
|
726
|
+
original.path = path;
|
|
727
|
+
}
|
|
728
|
+
else
|
|
729
|
+
events[turn.eventKey] = { t: turn.t, path };
|
|
730
|
+
}
|
|
731
|
+
// Mark only the response matched by this count, not other responses sharing its timestamp.
|
|
732
|
+
if (replay && turn?.codexPending)
|
|
733
|
+
turn.codexPending.replay = true;
|
|
653
734
|
if (turn)
|
|
654
|
-
addTurn(ledger, cur, turn, cutoff, pf(turn.t));
|
|
735
|
+
addTurn(ledger, cur, turn, cutoff, pf(turn.t), !replay);
|
|
655
736
|
// #3066 §2: responses timed by these lines (their last block seen) — counted into their hour, under the profile in
|
|
656
737
|
// effect at their time (§1d), then dropped.
|
|
657
738
|
if (cur.speeds?.length) {
|
|
658
|
-
|
|
659
|
-
|
|
739
|
+
if (!identityOnly)
|
|
740
|
+
for (const s of cur.speeds)
|
|
741
|
+
addSpeed(ledger, cur, s, cutoff, pf(s.t));
|
|
660
742
|
delete cur.speeds;
|
|
661
743
|
}
|
|
662
744
|
});
|
|
@@ -823,10 +905,10 @@ export class CacheService {
|
|
|
823
905
|
this.museWorkspace.delete(p);
|
|
824
906
|
return out;
|
|
825
907
|
}
|
|
826
|
-
/** Codex rollouts
|
|
908
|
+
/** Recent Codex rollouts, with their ancestors first even when those ancestors have old mtimes. */
|
|
827
909
|
async codexFilesByInstance(insts, cutoff) {
|
|
828
910
|
const out = new Map();
|
|
829
|
-
const codexInsts = insts.filter(
|
|
911
|
+
const codexInsts = insts.filter(i => kindOf(i.backend) === "codex");
|
|
830
912
|
if (!codexInsts.length)
|
|
831
913
|
return out;
|
|
832
914
|
const byCwd = new Map();
|
|
@@ -839,63 +921,132 @@ export class CacheService {
|
|
|
839
921
|
for (const [p, v] of Object.entries(JSON.parse(await readFile(this.o.metaPath, "utf8")))) {
|
|
840
922
|
const e = v;
|
|
841
923
|
if (e && typeof e.ino === "number" && (typeof e.cwd === "string" || e.cwd === null))
|
|
842
|
-
this.meta[p] = {
|
|
924
|
+
this.meta[p] = {
|
|
925
|
+
ino: e.ino, cwd: e.cwd,
|
|
926
|
+
...(typeof e.id === "string" || e.id === null ? { id: e.id } : {}),
|
|
927
|
+
...(typeof e.parent === "string" || e.parent === null ? { parent: e.parent } : {}),
|
|
928
|
+
};
|
|
843
929
|
}
|
|
844
930
|
}
|
|
845
931
|
catch { /* none yet */ }
|
|
846
932
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
const unlisted = () => { for (const i of codexInsts)
|
|
933
|
+
const rollouts = new Map();
|
|
934
|
+
let complete = true;
|
|
935
|
+
const unlisted = () => { complete = false; for (const i of codexInsts)
|
|
850
936
|
this.unread.add(i.name); };
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
937
|
+
const root = this.o.codexSessionsDir();
|
|
938
|
+
for (const dir of new Set([root, join(dirname(root), "archived_sessions")])) {
|
|
939
|
+
try {
|
|
940
|
+
for (const r of this.o.listRollouts(dir))
|
|
941
|
+
if (!rollouts.has(r.path))
|
|
942
|
+
rollouts.set(r.path, { ...r, archived: dir !== root });
|
|
943
|
+
if ((this.o.rolloutsUnreadable?.(dir) ?? 0) > 0)
|
|
944
|
+
unlisted();
|
|
945
|
+
}
|
|
946
|
+
catch (err) {
|
|
947
|
+
if (!gone(err))
|
|
948
|
+
unlisted();
|
|
949
|
+
}
|
|
856
950
|
}
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
951
|
+
const live = new Set(rollouts.keys());
|
|
952
|
+
const inventory = new Map();
|
|
953
|
+
const sessions = new Map();
|
|
954
|
+
// Codex filenames carry the session ID. Cached header IDs support older/custom names. Only recent files and
|
|
955
|
+
// ancestors they reference are stat'ed/read here; the shared listing already maintains the historical inventory.
|
|
956
|
+
for (const r of rollouts.values()) {
|
|
957
|
+
const id = rolloutSessionId(r.path);
|
|
958
|
+
sessions.set(id, r.path);
|
|
959
|
+
if (this.meta[r.path]?.id)
|
|
960
|
+
sessions.set(this.meta[r.path].id, r.path);
|
|
860
961
|
}
|
|
861
|
-
const
|
|
862
|
-
|
|
863
|
-
|
|
962
|
+
const load = async (path) => {
|
|
963
|
+
const existing = inventory.get(path);
|
|
964
|
+
if (existing)
|
|
965
|
+
return existing;
|
|
966
|
+
const r = rollouts.get(path);
|
|
967
|
+
if (!r)
|
|
968
|
+
return;
|
|
864
969
|
let st;
|
|
865
970
|
try {
|
|
866
|
-
st = await stat(
|
|
971
|
+
st = await stat(path);
|
|
867
972
|
}
|
|
868
973
|
catch (err) {
|
|
869
974
|
if (!gone(err))
|
|
870
975
|
unlisted();
|
|
871
|
-
|
|
976
|
+
return;
|
|
872
977
|
}
|
|
873
|
-
let m = this.meta[
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
const read = await rolloutMeta(r.path);
|
|
877
|
-
// Unreadable (not gone, not just unfinished): whose it is cannot be known, so no codex instance is covered.
|
|
978
|
+
let m = this.meta[path];
|
|
979
|
+
if (!m || m.ino !== st.ino || m.id === undefined || m.parent === undefined) {
|
|
980
|
+
const read = await rolloutMeta(path);
|
|
878
981
|
if (read === "unreadable") {
|
|
879
982
|
unlisted();
|
|
880
|
-
delete this.meta[
|
|
881
|
-
|
|
983
|
+
delete this.meta[path];
|
|
984
|
+
return;
|
|
882
985
|
}
|
|
883
986
|
if (read) {
|
|
884
|
-
m = this.meta[
|
|
987
|
+
m = this.meta[path] = read;
|
|
885
988
|
this.metaDirty = true;
|
|
886
989
|
}
|
|
887
990
|
else {
|
|
888
|
-
delete this.meta[
|
|
889
|
-
|
|
991
|
+
delete this.meta[path];
|
|
992
|
+
return;
|
|
890
993
|
}
|
|
891
994
|
}
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
995
|
+
if (m.ino !== st.ino)
|
|
996
|
+
return;
|
|
997
|
+
const f = { path, ino: st.ino, size: st.size, meta: m, recent: r.mtimeMs >= cutoff, archived: r.archived };
|
|
998
|
+
inventory.set(path, f);
|
|
999
|
+
if (m.id)
|
|
1000
|
+
sessions.set(m.id, path);
|
|
1001
|
+
return f;
|
|
1002
|
+
};
|
|
1003
|
+
for (const r of rollouts.values())
|
|
1004
|
+
if (r.mtimeMs >= cutoff)
|
|
1005
|
+
await load(r.path);
|
|
1006
|
+
for (const inst of codexInsts) {
|
|
1007
|
+
const selected = new Map();
|
|
1008
|
+
const visiting = new Set();
|
|
1009
|
+
const visit = async (path) => {
|
|
1010
|
+
if (selected.has(path))
|
|
1011
|
+
return true;
|
|
1012
|
+
if (visiting.has(path)) {
|
|
1013
|
+
this.unread.add(inst.name);
|
|
1014
|
+
return false;
|
|
1015
|
+
}
|
|
1016
|
+
const f = await load(path);
|
|
1017
|
+
if (!f) {
|
|
1018
|
+
this.unread.add(inst.name);
|
|
1019
|
+
return false;
|
|
1020
|
+
}
|
|
1021
|
+
visiting.add(path);
|
|
1022
|
+
let parentPath = f.meta.parent ? sessions.get(f.meta.parent) : undefined;
|
|
1023
|
+
if (parentPath && (await load(parentPath))?.meta.id !== f.meta.parent)
|
|
1024
|
+
parentPath = undefined;
|
|
1025
|
+
let orphaned;
|
|
1026
|
+
if (f.meta.parent) {
|
|
1027
|
+
if (parentPath) {
|
|
1028
|
+
if (!await visit(parentPath)) {
|
|
1029
|
+
visiting.delete(path);
|
|
1030
|
+
return false;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
else if (complete)
|
|
1034
|
+
orphaned = true;
|
|
1035
|
+
else {
|
|
1036
|
+
visiting.delete(path);
|
|
1037
|
+
this.unread.add(inst.name);
|
|
1038
|
+
return false;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
visiting.delete(path);
|
|
1042
|
+
const owner = f.meta.cwd ? byCwd.get(resolve(f.meta.cwd)) : undefined;
|
|
1043
|
+
selected.set(path, { path, ino: f.ino, size: f.size, ...(f.meta.id ? { sessionId: f.meta.id } : {}), ...(parentPath ? { parentPath } : {}), ...(orphaned ? { orphaned, missingParent: f.meta.parent } : {}), ...(owner !== inst.name || (f.archived && !f.recent) ? { identityOnly: true } : {}) });
|
|
1044
|
+
return true;
|
|
1045
|
+
};
|
|
1046
|
+
for (const f of [...inventory.values()])
|
|
1047
|
+
if (f.recent && f.meta.cwd && byCwd.get(resolve(f.meta.cwd)) === inst.name)
|
|
1048
|
+
await visit(f.path);
|
|
1049
|
+
out.set(inst.name, [...selected.values()]);
|
|
899
1050
|
}
|
|
900
1051
|
for (const p of Object.keys(this.meta))
|
|
901
1052
|
if (!live.has(p)) {
|
|
@@ -1055,13 +1206,14 @@ export async function rolloutMeta(path) {
|
|
|
1055
1206
|
const { bytesRead } = await fh.read(buf, 0, META_MAX_BYTES, 0);
|
|
1056
1207
|
const nl = buf.subarray(0, bytesRead).indexOf(10);
|
|
1057
1208
|
if (nl === -1)
|
|
1058
|
-
return bytesRead >= META_MAX_BYTES ? { ino, cwd: null } : null;
|
|
1209
|
+
return bytesRead >= META_MAX_BYTES ? { ino, cwd: null, id: null, parent: null } : null;
|
|
1059
1210
|
try {
|
|
1060
1211
|
const d = JSON.parse(buf.toString("utf8", 0, nl));
|
|
1061
|
-
|
|
1212
|
+
const p = d.type === "session_meta" ? d.payload : undefined;
|
|
1213
|
+
return { ino, cwd: typeof p?.cwd === "string" ? p.cwd : null, id: typeof p?.id === "string" ? p.id : null, parent: typeof p?.forked_from_id === "string" ? p.forked_from_id : null };
|
|
1062
1214
|
}
|
|
1063
1215
|
catch {
|
|
1064
|
-
return { ino, cwd: null };
|
|
1216
|
+
return { ino, cwd: null, id: null, parent: null };
|
|
1065
1217
|
}
|
|
1066
1218
|
}
|
|
1067
1219
|
catch (err) {
|