ccdeck 3.82.3 → 4.0.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/LICENSING.md +42 -4
- package/README.md +183 -72
- package/THIRD_PARTY_NOTICES.md +243 -17
- package/bin/cli/login-item.js +5 -0
- package/bin/cli/tui.js +58 -4
- package/bin/deck.js +27 -1
- package/dist/web/assets/AccountBridge-OQHT5qmS.js +1 -0
- package/dist/web/assets/AccountSection-BpIHPhF3.js +1 -0
- package/dist/web/assets/BrowserWatchModal-DBdt52v7.js +1 -0
- package/dist/web/assets/FeedbackConversations-BJjgXI0-.js +1 -0
- package/dist/web/assets/IntegrationModal-DQ0vEz4X.js +7 -0
- package/dist/web/assets/IntegrationSkeleton-JCPbqp96.js +1 -0
- package/dist/web/assets/RadioPanel-Be6AkrKl.js +1 -0
- package/dist/web/assets/StageShell-Dq0JOQhd.js +4 -0
- package/dist/web/assets/TrafficRadar-7jqJbhaK.js +8 -0
- package/dist/web/assets/UsageHistoryModal-ckawZGoe.js +1 -0
- package/dist/web/assets/addon-unicode-graphemes-DW3WJwyh.js +18 -0
- package/dist/web/assets/addon-web-links-BWjmmSgS.js +12 -0
- package/dist/web/assets/addon-webgl-CLK4R-_u.js +75 -0
- package/dist/web/assets/app-40gNTTfq.js +361 -0
- package/dist/web/assets/app-BRjYF6oD.css +1 -0
- package/dist/web/assets/{index-B4c5MZCc.js → index-XIY3yFiN.js} +1 -1
- package/dist/web/assets/inspector-status-pane-BV_m7eBv.js +1 -0
- package/dist/web/assets/screens-9_ivqfcF.js +12 -0
- package/dist/web/assets/screens-DUniTTbC.css +1 -0
- package/dist/web/assets/stage-board-NF_wgGRA.js +2 -0
- package/dist/web/assets/use-account-BUmI-A8e.js +1 -0
- package/dist/web/assets/xterm-4jYizCpg.js +27 -0
- package/dist/web/assets/xterm-sheet-6GBZ9nXN.css +32 -0
- package/dist/web/index.html +16 -6
- package/package.json +13 -1
- package/release-notes.json +79 -0
- package/src/server/account-client.mjs +196 -0
- package/src/server/account-connect.mjs +238 -0
- package/src/server/account-flag.mjs +106 -0
- package/src/server/account-projects.mjs +1 -1
- package/src/server/account-service.mjs +532 -0
- package/src/server/account-status.mjs +293 -0
- package/src/server/account-store.mjs +137 -0
- package/src/server/account-sync.mjs +473 -0
- package/src/server/account-token-store.mjs +216 -0
- package/src/server/account-ui-fields.mjs +126 -0
- package/src/server/account-watch.mjs +1 -1
- package/src/server/browser-watch-log.mjs +1 -1
- package/src/server/browser-watch-store.mjs +1 -1
- package/src/server/ccdeck-account-routes.mjs +252 -0
- package/src/server/ccusage-install.mjs +2 -2
- package/src/server/ccusage-registry.mjs +4 -4
- package/src/server/ccusage-session.mjs +11 -0
- package/src/server/claude-accounts.mjs +1 -1
- package/src/server/claude-recovery.mjs +9 -4
- package/src/server/claude-settings-catalog.mjs +6 -6
- package/src/server/claude-settings.mjs +1 -1
- package/src/server/codex-auto.mjs +1 -1
- package/src/server/codex-cost-usage.mjs +7 -2
- package/src/server/codex-live-checkpoint.mjs +24 -9
- package/src/server/codex-live-engine.mjs +14 -4
- package/src/server/codex-live-handoff.mjs +53 -9
- package/src/server/codex-names.mjs +49 -0
- package/src/server/codex-translate.mjs +1 -1
- package/src/server/codex-ultrafast.d.mts +3 -0
- package/src/server/codex-ultrafast.mjs +5 -0
- package/src/server/codex-watch.mjs +25 -0
- package/src/server/command-panel-engine.mjs +300 -0
- package/src/server/command-panel-platform.mjs +99 -0
- package/src/server/cswap-auto-choice.mjs +1 -1
- package/src/server/cswap-auto-loop.mjs +1 -1
- package/src/server/cswap-install.mjs +21 -40
- package/src/server/deck-home.mjs +6 -0
- package/src/server/deck-prefs.mjs +53 -1
- package/src/server/detach.mjs +1 -1
- package/src/server/engine-download.mjs +277 -0
- package/src/server/engine-install.mjs +378 -0
- package/src/server/engine-package.mjs +267 -0
- package/src/server/event-log.mjs +7 -1
- package/src/server/event-pipeline.mjs +29 -1
- package/src/server/ghostty-handoff.mjs +81 -0
- package/src/server/index.mjs +143 -5
- package/src/server/installer.mjs +4 -1
- package/src/server/integrations/jira-write-guard.mjs +14 -208
- package/src/server/integrations/store.mjs +37 -19
- package/src/server/integrations/write-guard.mjs +223 -0
- package/src/server/intel-cpu-temperature.mjs +26 -0
- package/src/server/lifecycle.mjs +69 -6
- package/src/server/log-replay.mjs +4 -0
- package/src/server/login-service.mjs +116 -14
- package/src/server/macmon.mjs +1 -1
- package/src/server/npm-latest.mjs +1 -1
- package/src/server/org-telemetry.mjs +1 -1
- package/src/server/output-watch.mjs +4 -1
- package/src/server/panel-provenance.mjs +390 -0
- package/src/server/pinned-build.mjs +14 -0
- package/src/server/prefs-refusal.mjs +8 -1
- package/src/server/prefs-routes.mjs +60 -11
- package/src/server/pro-engine-client.mjs +339 -0
- package/src/server/pro-engine-install.mjs +294 -0
- package/src/server/pro-engine-terminal.mjs +308 -0
- package/src/server/project-discovery.mjs +139 -0
- package/src/server/provider-session-name.mjs +58 -0
- package/src/server/quota-closes.mjs +1 -1
- package/src/server/quota-history.mjs +1 -1
- package/src/server/reports.mjs +86 -21
- package/src/server/request-gates.mjs +34 -5
- package/src/server/restart-note.mjs +1 -1
- package/src/server/seed-boundary.mjs +489 -0
- package/src/server/session-counts.mjs +244 -0
- package/src/server/session-deck-names.mjs +143 -0
- package/src/server/session-enrichment.mjs +43 -6
- package/src/server/session-name-route.mjs +73 -0
- package/src/server/session-summary.mjs +12 -1
- package/src/server/session-transcript-routes.mjs +167 -0
- package/src/server/swap-log.mjs +1 -1
- package/src/server/system-metrics.mjs +57 -0
- package/src/server/terminal-bridge.mjs +485 -0
- package/src/server/terminal-folder.mjs +61 -0
- package/src/server/terminal-js-routes.mjs +752 -0
- package/src/server/terminal-routes.mjs +553 -0
- package/src/server/terminal-sessions.mjs +759 -0
- package/src/server/terminal-socket.mjs +403 -0
- package/src/server/terminal-target.mjs +928 -0
- package/src/server/thermal-metrics.mjs +13 -9
- package/src/server/tmux-control.mjs +1319 -0
- package/src/server/tmux-download.mjs +220 -0
- package/src/server/tmux.mjs +542 -0
- package/src/server/token-redact.mjs +42 -3
- package/src/server/tool-audit-report.mjs +44 -6
- package/src/server/tool-audit-routes.mjs +12 -1
- package/src/server/tool-audit.mjs +42 -8
- package/src/server/traffic-radar-monitor.mjs +1 -1
- package/src/server/traffic-radar-permission.mjs +1 -1
- package/src/server/transcript-gate.mjs +1 -1
- package/src/server/transcript-scan.mjs +15 -7
- package/src/server/transcript-turns.mjs +154 -0
- package/src/server/tui-network.mjs +1 -0
- package/src/server/tui-view.mjs +28 -0
- package/src/server/utf8-carry.mjs +159 -0
- package/src/server/uv-bootstrap.mjs +2 -2
- package/src/server/windows-acl.mjs +158 -0
- package/src/server/ws-frames.mjs +690 -0
- package/dist/web/assets/BrowserWatchModal-BmRTh_xT.js +0 -1
- package/dist/web/assets/IntegrationModal-C_f526aV.js +0 -7
- package/dist/web/assets/RadioPanel-D2rkf9cg.js +0 -1
- package/dist/web/assets/TrafficRadar-BOgVBLIN.js +0 -8
- package/dist/web/assets/UsageHistoryModal-BJPTFwM9.js +0 -1
- package/dist/web/assets/app-CbXmr9rC.css +0 -1
- package/dist/web/assets/app-DZdZoqJ6.js +0 -358
|
@@ -176,7 +176,7 @@ export function* tarEntries(buf) {
|
|
|
176
176
|
export async function unpack(tgz, dest) {
|
|
177
177
|
const tar = await gunzipAsync(tgz);
|
|
178
178
|
const root = path.resolve(dest);
|
|
179
|
-
await mkdir(root, { recursive: true });
|
|
179
|
+
await mkdir(root, { recursive: true, mode: 0o700 });
|
|
180
180
|
for (const entry of tarEntries(tar)) {
|
|
181
181
|
if (entry.type !== "0" && entry.type !== "5") continue;
|
|
182
182
|
const parts = entry.name.replace(/\\/g, "/").split("/").filter(p => p && p !== ".");
|
|
@@ -189,8 +189,8 @@ export async function unpack(tgz, dest) {
|
|
|
189
189
|
if (!target.startsWith(root + path.sep)) {
|
|
190
190
|
throw new Error(`the package archive names a path outside itself: ${entry.name}`);
|
|
191
191
|
}
|
|
192
|
-
if (entry.type === "5") { await mkdir(target, { recursive: true }); continue; }
|
|
193
|
-
await mkdir(path.dirname(target), { recursive: true });
|
|
192
|
+
if (entry.type === "5") { await mkdir(target, { recursive: true, mode: 0o700 }); continue; }
|
|
193
|
+
await mkdir(path.dirname(target), { recursive: true, mode: 0o700 });
|
|
194
194
|
// An executable bit is kept, as npm keeps it. ccusage's cli.js would set it
|
|
195
195
|
// on the native binary anyway before running it, but a copy that looks
|
|
196
196
|
// like npm's is one nothing downstream has to know about. Windows has no
|
|
@@ -245,7 +245,7 @@ export async function fetchCcusage({
|
|
|
245
245
|
try {
|
|
246
246
|
await unpack(mainTgz, staging);
|
|
247
247
|
await unpack(nativeTgz, path.join(staging, "node_modules", ...nativeName.split("/")));
|
|
248
|
-
await mkdir(path.dirname(pkgDir), { recursive: true });
|
|
248
|
+
await mkdir(path.dirname(pkgDir), { recursive: true, mode: 0o700 });
|
|
249
249
|
const hadOld = existsSync(pkgDir);
|
|
250
250
|
if (hadOld) await renameSoon(pkgDir, old);
|
|
251
251
|
try {
|
|
@@ -60,6 +60,17 @@ export function sessionDetail(raw, agent, sessionId, speed = "auto") {
|
|
|
60
60
|
if (at && (!firstActivity || Date.parse(at) < Date.parse(firstActivity))) firstActivity = at;
|
|
61
61
|
if (at && (!lastActivity || Date.parse(at) > Date.parse(lastActivity))) lastActivity = at;
|
|
62
62
|
}
|
|
63
|
+
if (Array.isArray(raw.modelBreakdowns)) {
|
|
64
|
+
for (const summary of raw.modelBreakdowns) {
|
|
65
|
+
const bucket = models.get(summary?.modelName);
|
|
66
|
+
if (!bucket) continue;
|
|
67
|
+
const oneHour = summary.cacheCreation1hTokens;
|
|
68
|
+
if (Number.isFinite(oneHour) && oneHour >= 0 && oneHour <= bucket.cacheCreationTokens) {
|
|
69
|
+
bucket.cacheCreation1hTokens = oneHour;
|
|
70
|
+
}
|
|
71
|
+
bucket.missingPricing = summary.missingPricing === true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
63
74
|
} else if (agent === "codex" && raw.models && typeof raw.models === "object" && !Array.isArray(raw.models)) {
|
|
64
75
|
for (const [model, value] of Object.entries(raw.models)) {
|
|
65
76
|
models.set(model, { model, ...counters(value), missingPricing: value?.missingPricing === true });
|
|
@@ -1078,7 +1078,7 @@ export async function seedFirstAccount() {
|
|
|
1078
1078
|
// Mark before running, not after: if `cswap add` half-succeeds or the process
|
|
1079
1079
|
// dies mid-way, the retry-forever loop is the worse outcome.
|
|
1080
1080
|
try {
|
|
1081
|
-
await mkdir(dirname(SEED_MARKER), { recursive: true });
|
|
1081
|
+
await mkdir(dirname(SEED_MARKER), { recursive: true, mode: 0o700 });
|
|
1082
1082
|
await writeFile(SEED_MARKER, new Date().toISOString());
|
|
1083
1083
|
} catch { /* best-effort — worst case it is attempted again */ }
|
|
1084
1084
|
|
|
@@ -8,12 +8,13 @@ import { run } from "./exec.mjs";
|
|
|
8
8
|
import { heldPrefs, prefsRead } from "./prefs-state.mjs";
|
|
9
9
|
import { pushEvent } from "./event-sink.mjs";
|
|
10
10
|
import { outputWatch, touchSession } from "./session-tracking.mjs";
|
|
11
|
-
import { maybeResolveContext, maybeResolveModel, maybeResolveUsage } from "./session-enrichment.mjs";
|
|
11
|
+
import { maybeResolveContext, maybeResolveModel, maybeResolveSessionName, maybeResolveUsage } from "./session-enrichment.mjs";
|
|
12
12
|
|
|
13
13
|
const FILE_LIMIT = 128;
|
|
14
14
|
const REGISTRY_BYTES = 64 * 1024;
|
|
15
15
|
const TRANSCRIPT_BYTES = 256 * 1024;
|
|
16
|
-
const
|
|
16
|
+
const TASK_NOTICE = /^\s*<task-notification>[\s\S]*?<\/task-notification>/;
|
|
17
|
+
const normalizeStart = value =>typeof value === "string" ? value.trim().replace(/\s+/g, " ") : "";
|
|
17
18
|
|
|
18
19
|
/** PID existence alone cannot distinguish a reused PID from the old process. */
|
|
19
20
|
export async function claudeProcessStarts(pids) {
|
|
@@ -64,7 +65,9 @@ export async function claudeRecoveryPrompt(path) {
|
|
|
64
65
|
const content = row.message?.content;
|
|
65
66
|
const value = typeof content === "string" ? content : Array.isArray(content)
|
|
66
67
|
? content.filter(part => part?.type === "text" && typeof part.text === "string").map(part => part.text).join("\n") : "";
|
|
67
|
-
|
|
68
|
+
// A background task's notice comes in as a user turn; the prompt is what a
|
|
69
|
+
// person typed (the deck's injected-prompt.ts reads the same wrapper).
|
|
70
|
+
if (value && !TASK_NOTICE.test(value)) prompt = value;
|
|
68
71
|
}
|
|
69
72
|
return { prompt, model };
|
|
70
73
|
} catch { return {}; }
|
|
@@ -76,7 +79,9 @@ export function createClaudeRecovery({ workspace = "", home = claudeConfigDir(),
|
|
|
76
79
|
enrich = raw => {
|
|
77
80
|
outputWatch.note(raw.session_id, raw.transcript_path);
|
|
78
81
|
touchSession(raw.session_id);
|
|
79
|
-
|
|
82
|
+
// The name too: a recovered session sends no hook until its next turn, and
|
|
83
|
+
// its row would read as its folder until then.
|
|
84
|
+
maybeResolveModel(raw); maybeResolveUsage(raw); maybeResolveContext(raw); maybeResolveSessionName(raw);
|
|
80
85
|
}, enabled = () => heldPrefs.current().recoverClaudeSessions !== false } = {}) {
|
|
81
86
|
let stopped = false, pending = null, startupEnabled, startupFiles;
|
|
82
87
|
const startupIdentities = new Map();
|
|
@@ -63,7 +63,7 @@ export const CLAUDE_SETTINGS = [
|
|
|
63
63
|
{
|
|
64
64
|
id: "crossSessionInbound", key: "crossSessionInbound", group: "sessions", kind: "choice", since: "2.1.224",
|
|
65
65
|
label: "Messages from other sessions",
|
|
66
|
-
note: "What a session does when another of your
|
|
66
|
+
note: "What a session does when another of your sessions sends it a message.",
|
|
67
67
|
options: [
|
|
68
68
|
{ value: null, label: "Claude Code decides" },
|
|
69
69
|
{ value: "accept", label: "Accept" },
|
|
@@ -75,19 +75,19 @@ export const CLAUDE_SETTINGS = [
|
|
|
75
75
|
{
|
|
76
76
|
id: "listAgents", key: "permissions.deny", tool: "ListAgents", group: "sessions", kind: "allowTool", since: "2.1.224",
|
|
77
77
|
label: "Let sessions find each other",
|
|
78
|
-
note: "
|
|
78
|
+
note: "Claude can list your other sessions, their folders and whether they are busy.",
|
|
79
79
|
keywords: ["listagents", "peers", "see other sessions", "privacy", "isolation", "list agents"],
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
82
|
id: "isolatePeerMachines", key: "isolatePeerMachines", group: "sessions", kind: "switch", unset: false, since: "2.1.224",
|
|
83
83
|
label: "Ask before messaging other machines",
|
|
84
|
-
note: "Claude asks
|
|
84
|
+
note: "Claude asks before a message leaves this computer.",
|
|
85
85
|
keywords: ["remote control", "cloud", "cross-machine", "approval"],
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
88
|
id: "autoMemoryEnabled", key: "autoMemoryEnabled", group: "memory", kind: "switch", unset: true,
|
|
89
89
|
label: "Auto memory",
|
|
90
|
-
note: "Claude keeps notes it learns
|
|
90
|
+
note: "Claude keeps notes it learns and reads them in later sessions.",
|
|
91
91
|
overrides: [
|
|
92
92
|
{ env: "CLAUDE_CODE_DISABLE_AUTO_MEMORY", when: "on", effect: "Off" },
|
|
93
93
|
{ env: "CLAUDE_CODE_DISABLE_AUTO_MEMORY", when: "off", effect: "On" },
|
|
@@ -97,14 +97,14 @@ export const CLAUDE_SETTINGS = [
|
|
|
97
97
|
{
|
|
98
98
|
id: "autoCompactEnabled", key: "autoCompactEnabled", group: "memory", kind: "switch", unset: true,
|
|
99
99
|
label: "Compact automatically",
|
|
100
|
-
note: "
|
|
100
|
+
note: "Near the context limit, Claude summarises the conversation so the session can go on.",
|
|
101
101
|
overrides: [{ env: "DISABLE_AUTO_COMPACT", when: "on", effect: "Off" }],
|
|
102
102
|
keywords: ["compact", "context", "summarize", "context window"],
|
|
103
103
|
},
|
|
104
104
|
{
|
|
105
105
|
id: "cleanupPeriodDays", key: "cleanupPeriodDays", group: "memory", kind: "days", unset: 30,
|
|
106
106
|
label: "Keep conversations",
|
|
107
|
-
note: "Older
|
|
107
|
+
note: "Older ones are deleted and leave the resume list.",
|
|
108
108
|
options: [7, 14, 30, 90, 180, 365, 3650],
|
|
109
109
|
keywords: ["transcripts", "history", "retention", "delete", "resume", "cleanup"],
|
|
110
110
|
},
|
|
@@ -390,7 +390,7 @@ export function updateClaudeSetting(id, value, options = {}) {
|
|
|
390
390
|
if (!again || again.raw !== read.raw) continue;
|
|
391
391
|
if (read.raw !== null) {
|
|
392
392
|
const backupDir = deckDataDir(platform, env, home);
|
|
393
|
-
await mkdir(backupDir, { recursive: true });
|
|
393
|
+
await mkdir(backupDir, { recursive: true, mode: 0o700 });
|
|
394
394
|
await writePrivate((platform === "win32" ? win32.join : posix.join)(backupDir, SETTINGS_BACKUP), read.raw);
|
|
395
395
|
}
|
|
396
396
|
await mkdir(paths.dir, { recursive: true });
|
|
@@ -77,7 +77,7 @@ async function load(o) {
|
|
|
77
77
|
|
|
78
78
|
async function save(o, state) {
|
|
79
79
|
const target = filePath(o);
|
|
80
|
-
await mkdir(dirname(target), { recursive: true });
|
|
80
|
+
await mkdir(dirname(target), { recursive: true, mode: 0o700 });
|
|
81
81
|
const { tmp, handle } = await createTemp(target, { mode: 0o600 });
|
|
82
82
|
try {
|
|
83
83
|
try { await handle.writeFile(JSON.stringify(state) + '\n', 'utf8'); await handle.sync(); }
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { FREE_AUTO_REVIEW_TIER, isFreeAutoReview } from "./codex-review-policy.mjs";
|
|
2
|
+
import { GPT_62, ULTRAFAST_INTRO_END, ULTRAFAST_INTRO_TIER } from "./codex-ultrafast.mjs";
|
|
2
3
|
// Price only observed increases under recorded settings, never a whole session
|
|
3
4
|
// at its latest tier. These are API-equivalent estimates, not billing evidence.
|
|
4
5
|
const FIELDS = ["input_tokens", "output_tokens", "cached_input_tokens", "cache_write_input_tokens"];
|
|
5
|
-
const TIERS = new Map([["default", "standard"], ["standard", "standard"], ["priority", "fast"], ["fast", "fast"], ["flex", "flex"]]);
|
|
6
|
+
const TIERS = new Map([["default", "standard"], ["standard", "standard"], ["priority", "fast"], ["fast", "fast"], ["flex", "flex"], ["ultrafast", "ultrafast"]]);
|
|
6
7
|
const count = n => typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : 0;
|
|
7
8
|
const empty = () => Object.fromEntries(FIELDS.map(k => [k, 0]));
|
|
8
9
|
export function codexCostState() {
|
|
@@ -51,7 +52,11 @@ export function foldCodexCost(state, obj) {
|
|
|
51
52
|
const free = isFreeAutoReview(state.model, state.creator, obj.timestamp)
|
|
52
53
|
&& (isFreeAutoReview(state.model, state.creator, priorUsageAt)
|
|
53
54
|
|| isFreeAutoReview(state.model, state.creator, state.startedAt));
|
|
54
|
-
|
|
55
|
+
let billedTier = free ? FREE_AUTO_REVIEW_TIER : state.tier;
|
|
56
|
+
if (billedTier === "ultrafast" && GPT_62.test(state.model)) {
|
|
57
|
+
const at = Date.parse(obj.timestamp);
|
|
58
|
+
billedTier = !Number.isFinite(at) ? "unknown" : at < ULTRAFAST_INTRO_END ? ULTRAFAST_INTRO_TIER : "ultrafast";
|
|
59
|
+
}
|
|
55
60
|
if (billedTier && billedTier !== "standard") {
|
|
56
61
|
const share = bucket.speeds.get(billedTier) ?? empty();
|
|
57
62
|
for (const k of FIELDS) share[k] += delta[k];
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
// Parent-owned V2 agents pause by finishing a cooperative checkpoint, never by
|
|
2
2
|
// interrupting tool execution whose start is absent from the native item feed.
|
|
3
3
|
import { liveError } from './codex-live-rpc.mjs';
|
|
4
|
-
import { readCodexLiveTurn } from './codex-live-handoff.mjs';
|
|
4
|
+
import { readCodexLiveTurn, usageLimitedTurn } from './codex-live-handoff.mjs';
|
|
5
5
|
|
|
6
6
|
const inputs = turn => turn.items.filter(i => i.type === 'userMessage').map(i => i.id);
|
|
7
7
|
export async function requestCodexLiveCheckpoints(rpc, entries, options) {
|
|
8
|
-
for (const entry of entries)
|
|
9
|
-
|
|
8
|
+
for (const entry of entries) {
|
|
9
|
+
if (entry.rateLimited) await options.record(entry, 'paused');
|
|
10
|
+
else if (!entry.checkpointReady) await options.record(entry, 'checkpoint_waiting');
|
|
11
|
+
}
|
|
12
|
+
for (const owner of entries.filter(e => !e.resumeViaThreadId && !e.checkpointReady && !e.rateLimited)) {
|
|
10
13
|
await options.beforeSend?.();
|
|
11
14
|
await options.record(owner, 'checkpoint_sent');
|
|
12
15
|
const targets = entries.filter(e => e.resumeViaThreadId === owner.threadId).reverse().map(e => e.threadId);
|
|
13
|
-
const
|
|
14
|
-
+ 'Use native send_message to ask each of these existing subagents to finish its current tool call, record a concise checkpoint of its unfinished assignment, '
|
|
16
|
+
const family = targets.length ? 'Use native send_message to ask each of these existing subagents to finish its current tool call, record a concise checkpoint of its unfinished assignment, '
|
|
15
17
|
+ 'then END its current response with CCDECK_CHECKPOINT_' + owner.checkpointId + ': ' + JSON.stringify(targets)
|
|
16
18
|
+ '. This is a temporary pause, not completion of the original assignments. Do not spawn replacements or close agents. '
|
|
17
|
-
+ 'Do not message an agent that already finished or was closed. Wait for all requested checkpoints, then
|
|
18
|
-
|
|
19
|
+
+ 'Do not message an agent that already finished or was closed. Wait for all requested checkpoints, then ' : '';
|
|
20
|
+
const text = 'A ccdeck account change is pending. Keep the existing assignments and conversation history. '
|
|
21
|
+
+ 'Do not cancel running commands or replay tools. Finish the current tool call, then avoid starting new work before the account change. '
|
|
22
|
+
+ family + 'Record a concise checkpoint of your own unfinished work and END your current response '
|
|
23
|
+
+ 'with CCDECK_CHECKPOINT_' + owner.checkpointId + '. Do not resume any checkpointed task until the account change is complete and you receive the continuation instruction. '
|
|
19
24
|
+ 'Honor newer user instructions; if the user cancelled or asked to stop, remain stopped.';
|
|
20
25
|
await rpc.request('turn/steer', { threadId: owner.threadId, expectedTurnId: owner.turnId,
|
|
21
26
|
clientUserMessageId: owner.checkpointId, input: [{ type: 'text', text }] });
|
|
@@ -33,15 +38,25 @@ export async function inspectCodexLiveCheckpoints(rpc, entries, options) {
|
|
|
33
38
|
if (!turn || turn.itemsView !== 'full' || !Array.isArray(turn.items)) throw liveError('native_activity_unknown');
|
|
34
39
|
if (turn.rootTurnId !== entry.rootTurnId || !entry.resumeViaThreadId && turn.id !== entry.turnId) throw liveError('native_activity_changed');
|
|
35
40
|
if (!entry.resumeViaThreadId) {
|
|
36
|
-
const previous = turn.items.filter(i => i.type === 'userMessage' && (entry.checkpointReady || i.clientId !== entry.checkpointId)).map(i => i.id);
|
|
41
|
+
const previous = turn.items.filter(i => i.type === 'userMessage' && (entry.checkpointReady || entry.rateLimited || i.clientId !== entry.checkpointId)).map(i => i.id);
|
|
37
42
|
if (JSON.stringify(previous) !== JSON.stringify(entry.inputIds)) throw liveError('native_activity_changed');
|
|
38
43
|
}
|
|
44
|
+
if (entry.rateLimited) {
|
|
45
|
+
if (turn.id !== entry.turnId || !usageLimitedTurn(turn) || t.status?.type !== 'idle' || t.canAcceptDirectInput !== true
|
|
46
|
+
|| turn.items.some(i => i.status === 'inProgress')) throw liveError('native_activity_changed');
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
39
49
|
if (entry.checkpointReady) {
|
|
40
50
|
if (turn.id !== entry.turnId || turn.status !== 'completed'
|
|
41
51
|
|| !turn.items.some(i => i.type === 'agentMessage' && i.text?.includes('CCDECK_CHECKPOINT_' + entry.checkpointId))) throw liveError('native_activity_changed');
|
|
42
52
|
continue;
|
|
43
53
|
}
|
|
44
54
|
if (turn.status === 'inProgress') { pending = true; continue; }
|
|
55
|
+
if (usageLimitedTurn(turn) && t.status?.type === 'idle' && t.canAcceptDirectInput === true
|
|
56
|
+
&& !entry.resumeViaThreadId && turn.items.every(i => i.status !== 'inProgress')) {
|
|
57
|
+
entry.turnId = turn.id; entry.inputIds = inputs(turn); entry.rateLimited = true;
|
|
58
|
+
await options.record(entry, 'paused'); continue;
|
|
59
|
+
}
|
|
45
60
|
if (turn.status !== 'completed') throw liveError('native_continue_unconfirmed');
|
|
46
61
|
const ready = turn.items.some(i => i.type === 'agentMessage' && i.text?.includes('CCDECK_CHECKPOINT_' + entry.checkpointId));
|
|
47
62
|
if (ready) {
|
|
@@ -49,7 +64,7 @@ export async function inspectCodexLiveCheckpoints(rpc, entries, options) {
|
|
|
49
64
|
await options.record(entry, 'checkpoint_ready');
|
|
50
65
|
} else await options.record(entry, 'skipped'); // Naturally finished work stays finished.
|
|
51
66
|
}
|
|
52
|
-
const paused = entries.filter(e => e.checkpointReady);
|
|
67
|
+
const paused = entries.filter(e => e.checkpointReady || e.rateLimited);
|
|
53
68
|
if (!pending && paused.some(e => e.resumeViaThreadId && !paused.some(p => p.threadId === e.resumeViaThreadId))) throw liveError('native_continue_unconfirmed');
|
|
54
69
|
return pending ? null : { waiting: false, paused };
|
|
55
70
|
}
|
|
@@ -282,7 +282,8 @@ export function createCodexLiveAccountController(input = {}) {
|
|
|
282
282
|
const actual = await rpc.request('account/read', { refreshToken: false });
|
|
283
283
|
if (!authCurrent() || !sameNativeAccount(actual, resumeIdentity)) throw liveError('account_changed_outside_deck');
|
|
284
284
|
};
|
|
285
|
-
const resume = async () => continueCodexLiveHandoff(rpc,
|
|
285
|
+
const resume = async (includeRateLimited = true) => continueCodexLiveHandoff(rpc,
|
|
286
|
+
includeRateLimited ? handoff : { ...handoff, paused: handoff.paused.filter(entry => !entry.rateLimited) }, {
|
|
286
287
|
isCurrent: () => authCurrent() && !!rpc,
|
|
287
288
|
beforeSend: async entry => {
|
|
288
289
|
if (!await lease?.valid()) throw liveError('native_control_lost');
|
|
@@ -306,7 +307,13 @@ export function createCodexLiveAccountController(input = {}) {
|
|
|
306
307
|
if (!await lease.valid()) throw liveError('native_control_lost');
|
|
307
308
|
const before = await rpc.request('account/read', { refreshToken: false });
|
|
308
309
|
resumeIdentity = before;
|
|
309
|
-
handoff = await prepareCodexLiveHandoff(rpc, { isCurrent: owner,
|
|
310
|
+
handoff = await prepareCodexLiveHandoff(rpc, { isCurrent: owner, cooperativeTools: true,
|
|
311
|
+
recoverRateLimited: !refresh && !checkpoint && !sameAccount(before, next),
|
|
312
|
+
beforeRecovery: async entry => {
|
|
313
|
+
await assertProfileAvailable(); await assertAutoEnabled();
|
|
314
|
+
if (!owner()) throw liveError('account_changed_outside_deck');
|
|
315
|
+
await record(entry, 'paused');
|
|
316
|
+
},
|
|
310
317
|
beforeInterrupt: async entry => {
|
|
311
318
|
await assertProfileAvailable();
|
|
312
319
|
await assertAutoEnabled();
|
|
@@ -315,6 +322,7 @@ export function createCodexLiveAccountController(input = {}) {
|
|
|
315
322
|
if (!owner()) throw liveError('account_changed_outside_deck');
|
|
316
323
|
}, afterInterrupt: (entry, phase) => record(entry, phase) });
|
|
317
324
|
if (handoff.checkpoint) {
|
|
325
|
+
handoff.checkpoint.unshift(...handoff.paused);
|
|
318
326
|
if (checkpoint) handoff.checkpoint.unshift(...checkpoint.handoff.paused);
|
|
319
327
|
const previousRelease = releaseSubscriptions;
|
|
320
328
|
const release = await retainCodexLiveHandoff(rpc, handoff.checkpoint);
|
|
@@ -366,7 +374,9 @@ export function createCodexLiveAccountController(input = {}) {
|
|
|
366
374
|
await save().catch(() => update({ reason: 'ownership_not_saved' }));
|
|
367
375
|
if (handoff.paused.length) {
|
|
368
376
|
try {
|
|
369
|
-
|
|
377
|
+
// A checkpoint can itself end with a usage error. Only a different
|
|
378
|
+
// login authorizes retrying that failure, including this late race.
|
|
379
|
+
const result = await resume(!refresh && !sameAccount(before, next));
|
|
370
380
|
if (result.delegated?.length) {
|
|
371
381
|
childContinuation = { rpc, entries: result.delegated, deadline: Date.now() + (options.delegationTimeoutMs ?? 60_000),
|
|
372
382
|
record, journal, identity: resumeIdentity };
|
|
@@ -390,7 +400,7 @@ export function createCodexLiveAccountController(input = {}) {
|
|
|
390
400
|
}
|
|
391
401
|
const lostControl = ['native_control_lost', 'account_changed_outside_deck', 'native_disconnected'].includes(error.code);
|
|
392
402
|
if (!maybeApplied && !lostControl && handoff?.paused?.length && rpc && !closed) {
|
|
393
|
-
try { await resume(); } catch { update({ continuation: 'manual_required' }); }
|
|
403
|
+
try { await resume(false); } catch { update({ continuation: 'manual_required' }); }
|
|
394
404
|
}
|
|
395
405
|
if (handoff?.paused?.length && (maybeApplied || lostControl)) update({ continuation: 'manual_required' });
|
|
396
406
|
if (journal.entries.length && journal.phase !== 'finished') update({ continuation: 'manual_required' });
|
|
@@ -5,6 +5,8 @@ import { liveError } from './codex-live-rpc.mjs';
|
|
|
5
5
|
|
|
6
6
|
const passive = new Set(['userMessage', 'hookPrompt', 'agentMessage', 'functionCallOutput', 'plan', 'reasoning']);
|
|
7
7
|
const terminal = new Set(['completed', 'failed', 'declined']);
|
|
8
|
+
const drainable = new Set(['commandExecution', 'mcpToolCall', 'dynamicToolCall', 'fileChange']);
|
|
9
|
+
const USAGE_RECOVERY_MS = 5 * 60_000;
|
|
8
10
|
const tool = item => !passive.has(item.type);
|
|
9
11
|
const completed = item => item.status !== 'inProgress' && (terminal.has(item.status)
|
|
10
12
|
|| Number.isFinite(item.completedAtMs) && item.completedAtMs > 0);
|
|
@@ -32,6 +34,14 @@ const safe = (turn, thread, known) => turn?.itemsView === 'full' && Array.isArra
|
|
|
32
34
|
&& turn.items.every(i => passive.has(i.type) || completed(i) || childWait(i, thread, known));
|
|
33
35
|
const inputIds = turn => turn.items.filter(i => i.type === 'userMessage').map(i => i.id);
|
|
34
36
|
const sameInputs = (a, b) => JSON.stringify(inputIds(a)) === JSON.stringify(inputIds(b));
|
|
37
|
+
export const usageLimitedTurn = turn => turn?.status === 'failed' && turn.error?.codexErrorInfo === 'usageLimitExceeded';
|
|
38
|
+
const freshUsageFailure = (turn, now) => usageLimitedTurn(turn) && Number.isFinite(turn.completedAt)
|
|
39
|
+
&& turn.completedAt * 1000 <= now && now - turn.completedAt * 1000 <= USAGE_RECOVERY_MS;
|
|
40
|
+
const continuableTurn = (turn, entry) => entry.rateLimited
|
|
41
|
+
? usageLimitedTurn(turn) && (turn.rootTurnId ?? turn.id) === entry.rootTurnId : turn?.status === 'interrupted';
|
|
42
|
+
const limitedEntry = ({ thread, turn }) => ({ threadId: thread.id, turnId: turn.id,
|
|
43
|
+
rootTurnId: turn.rootTurnId ?? turn.id, messageId: randomUUID(), inputIds: inputIds(turn), rateLimited: true,
|
|
44
|
+
...(thread.parentThreadId ? { parentThreadId: thread.parentThreadId } : {}) });
|
|
35
45
|
const retained = new WeakMap();
|
|
36
46
|
|
|
37
47
|
/** Keep this connection's observations attached until a cooperative handoff
|
|
@@ -86,10 +96,10 @@ async function liveLatest(rpc, thread) {
|
|
|
86
96
|
}
|
|
87
97
|
}
|
|
88
98
|
export const readCodexLiveTurn = (rpc, thread) => thread.status?.type === 'active' ? liveLatest(rpc, thread) : latest(rpc, thread.id);
|
|
89
|
-
async function snapshot(rpc) {
|
|
99
|
+
async function snapshot(rpc, options = {}) {
|
|
90
100
|
const page = await rpc.request('thread/loaded/list', { limit: 65 });
|
|
91
101
|
if (!Array.isArray(page?.data) || page.data.length > 64 || page.nextCursor) throw liveError('native_activity_unknown');
|
|
92
|
-
const threads = [], known = new Map();
|
|
102
|
+
const threads = [], known = new Map(), limited = [];
|
|
93
103
|
for (const id of page.data) {
|
|
94
104
|
if (typeof id !== 'string') throw liveError('native_activity_unknown');
|
|
95
105
|
const result = await rpc.request('thread/read', { threadId: id, includeTurns: false });
|
|
@@ -122,15 +132,17 @@ async function snapshot(rpc) {
|
|
|
122
132
|
if (t.status.type === 'active' || turn?.status === 'inProgress' || turn?.items?.some(i => i.status === 'inProgress')) threads.push({ id,
|
|
123
133
|
active: t.status.type === 'active',
|
|
124
134
|
thread: t, flags: t.status.activeFlags, turn });
|
|
135
|
+
else if (options.recoverRateLimited && t.status.type === 'idle' && t.canAcceptDirectInput === true
|
|
136
|
+
&& freshUsageFailure(turn, options.now ?? Date.now()) && safe(turn, t, known)) limited.push({ thread: t, turn });
|
|
125
137
|
}
|
|
126
|
-
return { threads, known };
|
|
138
|
+
return { threads, known, limited };
|
|
127
139
|
}
|
|
128
140
|
|
|
129
141
|
/** A waiting result sends no interrupt and no authentication mutation. */
|
|
130
142
|
export async function prepareCodexLiveHandoff(rpc, options = {}) {
|
|
131
143
|
const isCurrent = options.isCurrent ?? (() => true);
|
|
132
144
|
const paused = [];
|
|
133
|
-
const { threads: initial, known } = await snapshot(rpc);
|
|
145
|
+
const { threads: initial, known, limited } = await snapshot(rpc, options);
|
|
134
146
|
const routes = new Map();
|
|
135
147
|
for (const t of initial) {
|
|
136
148
|
if (!t.thread || !v2Child(t.thread)) continue;
|
|
@@ -147,6 +159,22 @@ export async function prepareCodexLiveHandoff(rpc, options = {}) {
|
|
|
147
159
|
if (owner && ![...routes.values()].includes(owner)) return { waiting: true, paused };
|
|
148
160
|
}
|
|
149
161
|
const cooperative = new Set([...routes.keys(), ...routes.values()]);
|
|
162
|
+
// A long command (for example a CI watcher) may never leave a model-only
|
|
163
|
+
// window. Ask its direct-input owner to checkpoint instead of endlessly
|
|
164
|
+
// polling for that window. No tool is interrupted or authenticated over.
|
|
165
|
+
if (options.cooperativeTools && !routes.size
|
|
166
|
+
&& initial.some(t => Array.isArray(t.turn?.items) && t.turn.items.some(i => drainable.has(i.type) && i.status === 'inProgress'))
|
|
167
|
+
&& initial.every(t => t.active && t.thread?.canAcceptDirectInput === true
|
|
168
|
+
&& Array.isArray(t.flags) && !t.flags.length && t.turn?.status === 'inProgress'
|
|
169
|
+
&& t.turn.itemsView === 'full' && Array.isArray(t.turn.items) && t.turn.items.some(i => i.type === 'userMessage')
|
|
170
|
+
&& t.turn.items.every(i => passive.has(i.type) || completed(i) || childWait(i, t.thread, known)
|
|
171
|
+
|| drainable.has(i.type) && i.status === 'inProgress'))) {
|
|
172
|
+
return { waiting: true, paused: limited.map(limitedEntry), checkpoint: initial.map(t => ({
|
|
173
|
+
threadId: t.id, turnId: t.turn.id, rootTurnId: t.turn.rootTurnId ?? t.turn.id,
|
|
174
|
+
inputIds: inputIds(t.turn), messageId: randomUUID(), checkpointId: randomUUID(),
|
|
175
|
+
...(t.thread.parentThreadId ? { parentThreadId: t.thread.parentThreadId } : {}),
|
|
176
|
+
})) };
|
|
177
|
+
}
|
|
150
178
|
if (initial.some(t => !t.active || t.thread?.canAcceptDirectInput === false && !routes.has(t.id)
|
|
151
179
|
|| t.thread?.parentThreadId && t.thread.canAcceptDirectInput !== true && !routes.has(t.id)
|
|
152
180
|
|| !Array.isArray(t.flags) || t.flags.length || t.turn?.status !== 'inProgress'
|
|
@@ -162,7 +190,7 @@ export async function prepareCodexLiveHandoff(rpc, options = {}) {
|
|
|
162
190
|
// interrupt that family based on an empty snapshot: ask its owner to drain
|
|
163
191
|
// tools and collect terminal checkpoints through normal agent messaging.
|
|
164
192
|
const owners = new Set(routes.values()), markers = new Map([...owners].map(id => [id, randomUUID()]));
|
|
165
|
-
return { waiting: true, paused, checkpoint: initial.filter(t => routes.has(t.id) || owners.has(t.id)).map(t => ({
|
|
193
|
+
return { waiting: true, paused: limited.map(limitedEntry), checkpoint: initial.filter(t => routes.has(t.id) || owners.has(t.id)).map(t => ({
|
|
166
194
|
threadId: t.id, turnId: t.turn.id, rootTurnId: t.turn.rootTurnId ?? t.turn.id, inputIds: inputIds(t.turn), messageId: randomUUID(),
|
|
167
195
|
checkpointId: markers.get(routes.get(t.id) ?? t.id),
|
|
168
196
|
...(t.thread.parentThreadId ? { parentThreadId: t.thread.parentThreadId } : {}),
|
|
@@ -173,7 +201,15 @@ export async function prepareCodexLiveHandoff(rpc, options = {}) {
|
|
|
173
201
|
for (const observed of initial) {
|
|
174
202
|
if (!isCurrent()) throw liveError('native_switch_superseded');
|
|
175
203
|
const now = (await rpc.request('thread/read', { threadId: observed.id, includeTurns: false }))?.thread;
|
|
176
|
-
if (now?.status?.type !== 'active')
|
|
204
|
+
if (now?.status?.type !== 'active') {
|
|
205
|
+
if (options.recoverRateLimited && now?.id === observed.id && now.status.type === 'idle'
|
|
206
|
+
&& now.canAcceptDirectInput === true && (now.parentThreadId ?? null) === (observed.thread.parentThreadId ?? null)) {
|
|
207
|
+
const failed = await latest(rpc, now.id);
|
|
208
|
+
if (failed?.id === observed.turn.id && freshUsageFailure(failed, options.now ?? Date.now())
|
|
209
|
+
&& safe(failed, now, known) && sameInputs(observed.turn, failed)) limited.push({ thread: now, turn: failed });
|
|
210
|
+
}
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
177
213
|
const turn = await liveLatest(rpc, now);
|
|
178
214
|
if (turn?.id !== observed.turn.id || now.status.activeFlags?.length || now.canAcceptDirectInput === false && !routes.has(observed.id)
|
|
179
215
|
|| (now.parentThreadId ?? null) !== (observed.thread.parentThreadId ?? null)
|
|
@@ -189,13 +225,20 @@ export async function prepareCodexLiveHandoff(rpc, options = {}) {
|
|
|
189
225
|
await rpc.request('turn/interrupt', { threadId: observed.id, turnId: turn.id });
|
|
190
226
|
const after = await latest(rpc, observed.id);
|
|
191
227
|
if (after?.id === turn.id && after.status === 'completed') { await options.afterInterrupt?.(entry, 'skipped'); continue; }
|
|
192
|
-
if (after?.id !== turn.id || after.status !== 'interrupted') throw liveError('native_interrupt_unconfirmed');
|
|
228
|
+
if (after?.id !== turn.id || after.status !== 'interrupted' && !(options.recoverRateLimited && usageLimitedTurn(after))) throw liveError('native_interrupt_unconfirmed');
|
|
193
229
|
if (!sameInputs(turn, after)) throw liveError('native_activity_changed');
|
|
194
230
|
const previous = new Set(turn.items.map(i => i.id));
|
|
195
231
|
if (after.items.some(i => tool(i) && !previous.has(i.id) && !completed(i))) throw liveError('native_tool_interrupted');
|
|
232
|
+
if (usageLimitedTurn(after)) entry.rateLimited = true;
|
|
196
233
|
paused.push(entry);
|
|
197
234
|
await options.afterInterrupt?.(entry, 'paused');
|
|
198
235
|
}
|
|
236
|
+
for (const { thread, turn } of limited) {
|
|
237
|
+
const entry = limitedEntry({ thread, turn });
|
|
238
|
+
if (!isCurrent()) throw liveError('native_switch_superseded');
|
|
239
|
+
await options.beforeRecovery?.(entry);
|
|
240
|
+
paused.push(entry);
|
|
241
|
+
}
|
|
199
242
|
await assertCodexLiveQuiet(rpc);
|
|
200
243
|
return { waiting: false, paused };
|
|
201
244
|
} catch (error) {
|
|
@@ -223,6 +266,7 @@ export async function continueCodexLiveHandoff(rpc, handoff, options = {}) {
|
|
|
223
266
|
if (entry.resumeViaThreadId && t?.status?.type === 'notLoaded') throw liveError('native_continue_unconfirmed');
|
|
224
267
|
await options.onSkip?.(entry); continue;
|
|
225
268
|
}
|
|
269
|
+
if (entry.rateLimited && t?.canAcceptDirectInput !== true) throw liveError('native_activity_changed');
|
|
226
270
|
if (entry.resumeViaThreadId ? !v2Child(t) || t.parentThreadId !== entry.parentThreadId
|
|
227
271
|
: t?.canAcceptDirectInput === false || entry.parentThreadId
|
|
228
272
|
&& (t?.canAcceptDirectInput !== true || t.parentThreadId !== entry.parentThreadId)) throw liveError('native_activity_changed');
|
|
@@ -230,7 +274,7 @@ export async function continueCodexLiveHandoff(rpc, handoff, options = {}) {
|
|
|
230
274
|
// New input, natural completion, archival or a different turn wins over us.
|
|
231
275
|
const checkpoint = entry.checkpointReady && turn?.status === 'completed'
|
|
232
276
|
&& turn.items?.some(i => i.type === 'agentMessage' && i.text?.includes('CCDECK_CHECKPOINT_' + entry.checkpointId));
|
|
233
|
-
if (turn?.id !== entry.turnId || (!checkpoint && turn
|
|
277
|
+
if (turn?.id !== entry.turnId || (!checkpoint && !continuableTurn(turn, entry))
|
|
234
278
|
|| JSON.stringify(inputIds(turn)) !== JSON.stringify(entry.inputIds)) {
|
|
235
279
|
await options.onSkip?.(entry); continue;
|
|
236
280
|
}
|
|
@@ -249,7 +293,7 @@ export async function continueCodexLiveHandoff(rpc, handoff, options = {}) {
|
|
|
249
293
|
const finalTurn = await latest(rpc, entry.threadId);
|
|
250
294
|
const finalCheckpoint = entry.checkpointReady && finalTurn?.status === 'completed'
|
|
251
295
|
&& finalTurn.items?.some(i => i.type === 'agentMessage' && i.text?.includes('CCDECK_CHECKPOINT_' + entry.checkpointId));
|
|
252
|
-
if (finalTurn?.id !== entry.turnId || (!finalCheckpoint && finalTurn
|
|
296
|
+
if (finalTurn?.id !== entry.turnId || (!finalCheckpoint && !continuableTurn(finalTurn, entry))
|
|
253
297
|
|| JSON.stringify(inputIds(finalTurn)) !== JSON.stringify(entry.inputIds)) {
|
|
254
298
|
await options.onSkip?.(entry); continue;
|
|
255
299
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Codex keeps conversation titles in a separate append-only index, not in
|
|
2
|
+
// the rollout. Read its bounded tail once per home and retain no prompts.
|
|
3
|
+
import { constants } from 'node:fs';
|
|
4
|
+
import { open } from 'node:fs/promises';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
|
|
7
|
+
export const CODEX_NAMES_BYTES = 1024 * 1024;
|
|
8
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
9
|
+
|
|
10
|
+
export function createCodexNameReader() {
|
|
11
|
+
const homes = new Map();
|
|
12
|
+
return async function names(home, now = Date.now()) {
|
|
13
|
+
const old = homes.get(home);
|
|
14
|
+
if (old && now >= old.checked && now - old.checked < 1000) return old.names;
|
|
15
|
+
let file;
|
|
16
|
+
try {
|
|
17
|
+
file = await open(join(home, 'session_index.jsonl'), constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
18
|
+
const stat = await file.stat();
|
|
19
|
+
if (!stat.isFile()) return new Map();
|
|
20
|
+
const stamp = `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeMs}`;
|
|
21
|
+
if (old?.stamp === stamp) { old.checked = now; return old.names; }
|
|
22
|
+
const size = Math.min(stat.size, CODEX_NAMES_BYTES);
|
|
23
|
+
const from = stat.size - size;
|
|
24
|
+
const buffer = Buffer.alloc(size);
|
|
25
|
+
const { bytesRead } = await file.read(buffer, 0, size, from);
|
|
26
|
+
const text = buffer.subarray(0, bytesRead).toString('utf8');
|
|
27
|
+
const lines = text.split('\n');
|
|
28
|
+
if (from > 0) lines.shift();
|
|
29
|
+
lines.pop(); // an incomplete last append is not an index record
|
|
30
|
+
const result = new Map();
|
|
31
|
+
for (const line of lines) {
|
|
32
|
+
let row;
|
|
33
|
+
try { row = JSON.parse(line); } catch { continue; }
|
|
34
|
+
if (!UUID.test(row?.id ?? '') || typeof row.thread_name !== 'string') continue;
|
|
35
|
+
const name = row.thread_name.trim();
|
|
36
|
+
if (!name || name.length > 160 || /[\u0000-\u001f\u007f]/.test(name)) continue;
|
|
37
|
+
const id = row.id.toLowerCase();
|
|
38
|
+
result.delete(id); result.set(id, name);
|
|
39
|
+
while (result.size > 512) result.delete(result.keys().next().value);
|
|
40
|
+
}
|
|
41
|
+
homes.delete(home); homes.set(home, { stamp, checked: now, names: result });
|
|
42
|
+
while (homes.size > 32) homes.delete(homes.keys().next().value);
|
|
43
|
+
return result;
|
|
44
|
+
} catch { return old?.names ?? new Map(); }
|
|
45
|
+
finally { await file?.close(); }
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const readCodexNames = createCodexNameReader();
|
|
@@ -86,7 +86,7 @@ export function responseItemModel(obj) {
|
|
|
86
86
|
* rather than indexed, and a part with no string `text` contributes nothing
|
|
87
87
|
* instead of printing "undefined" into the prompt the card shows.
|
|
88
88
|
*/
|
|
89
|
-
function codexItemText(item) {
|
|
89
|
+
export function codexItemText(item) {
|
|
90
90
|
const parts = Array.isArray(item && item.content) ? item.content : [];
|
|
91
91
|
return parts.map(p => (p && typeof p.text === "string" ? p.text : "")).join("");
|
|
92
92
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// OpenAI's GPT-6.2 introductory Ultrafast rates end on March 1, 2027
|
|
2
|
+
// at midnight Pacific time. Keep the historical rate in the usage bucket.
|
|
3
|
+
export const ULTRAFAST_INTRO_END = Date.parse("2027-03-01T00:00:00-08:00");
|
|
4
|
+
export const ULTRAFAST_INTRO_TIER = "ultrafast-intro";
|
|
5
|
+
export const GPT_62 = /^gpt[-_]6[-_.]2[-_](?:astra|sol)\b(?![-_][A-Za-z])/i;
|
|
@@ -29,6 +29,7 @@ import { readLiveDecks } from "./live-decks.mjs";
|
|
|
29
29
|
// The bounded chunk reads the Claude transcripts use — see jsonl-chunks.mjs.
|
|
30
30
|
import { readAppendedLines, readByteRange } from "./jsonl-chunks.mjs";
|
|
31
31
|
import { maybeResolveCodexMemory } from "./session-enrichment.mjs";
|
|
32
|
+
import { readCodexNames } from "./codex-names.mjs";
|
|
32
33
|
// event-pipeline.mjs's pushEvent, reached without importing it — see
|
|
33
34
|
// event-sink.mjs.
|
|
34
35
|
import { pushEvent } from "./event-sink.mjs";
|
|
@@ -519,6 +520,16 @@ function codexScanOnce(firstRun) {
|
|
|
519
520
|
return codexScan;
|
|
520
521
|
}
|
|
521
522
|
|
|
523
|
+
/** The newest tracked rollout for a session in this deck's workspace. */
|
|
524
|
+
export function codexTranscriptPath(sid) {
|
|
525
|
+
let newest = null;
|
|
526
|
+
for (const [path, state] of codexFileState) {
|
|
527
|
+
if (state.skip || state.sid !== sid || rolloutNameId(basename(path)) !== sid) continue;
|
|
528
|
+
if (!newest || state.mtimeMs > newest.mtimeMs) newest = { path, mtimeMs: state.mtimeMs };
|
|
529
|
+
}
|
|
530
|
+
return newest?.path ?? null;
|
|
531
|
+
}
|
|
532
|
+
|
|
522
533
|
/**
|
|
523
534
|
* One scan that begins after this call, awaited — what the poll does every
|
|
524
535
|
* 1500ms, on demand.
|
|
@@ -675,6 +686,20 @@ async function scanRollouts(firstRun) {
|
|
|
675
686
|
// readAppendedLines cannot advance a cursor past `size`. It is resynced
|
|
676
687
|
// FORWARD rather than back to zero because re-reading a rollout from the
|
|
677
688
|
// beginning is precisely the full replay #981 is about.
|
|
689
|
+
// A title can change while a rollout is idle: check before its early
|
|
690
|
+
// return too. The same persisted event updates list, header and board.
|
|
691
|
+
if (state.rootOpened) {
|
|
692
|
+
const name = (await readCodexNames(rolloutHome(path), now)).get(state.sid);
|
|
693
|
+
if (name && name !== state.providerName) {
|
|
694
|
+
const persistName = !eventLogPath() || writesCodexLog({
|
|
695
|
+
decks: await liveDecks(), pid: process.pid, cwd: state.cwd,
|
|
696
|
+
codexHome: canonicalLogPath(rolloutHome(path)),
|
|
697
|
+
});
|
|
698
|
+
pushEvent({ hook_event_name: "SessionNamed", provider: "codex",
|
|
699
|
+
session_id: state.sid, cwd: state.cwd, sessionName: name }, "codex", { persist: persistName });
|
|
700
|
+
state.providerName = name;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
678
703
|
if (st.size < state.offset) state.offset = st.size;
|
|
679
704
|
if (st.size <= state.offset) continue;
|
|
680
705
|
|