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
|
@@ -68,6 +68,8 @@ const percentile = (sorted, p) => sorted.length ? sorted[Math.max(0, Math.ceil(s
|
|
|
68
68
|
let totalMs = null, observedSince = null, observedUntil = null;
|
|
69
69
|
const providers = { claude: { calls: 0, measured: 0, failed: 0 }, codex: { calls: 0, measured: 0, failed: 0 } };
|
|
70
70
|
for (const [id, call] of calls) {
|
|
71
|
+
// One session's turn needs none of the tool groupings below.
|
|
72
|
+
if (query.turnId) break;
|
|
71
73
|
const start = call.start, end = call.end;
|
|
72
74
|
if (!start) { if (!call.skill && !call.turn && !call['turn-end']) orphaned++; continue; }
|
|
73
75
|
if (start.t < since || start.t > until || query.provider !== 'all' && start.provider !== query.provider) continue;
|
|
@@ -115,13 +117,45 @@ const percentile = (sorted, p) => sorted.length ? sorted[Math.max(0, Math.ceil(s
|
|
|
115
117
|
}
|
|
116
118
|
const sum = { turns: 0, open: 0, totalMs: 0, claudeMs: 0, machineMs: 0, youMs: 0 }, machine = new Map(), you = new Map(), replies = [], stops = {};
|
|
117
119
|
const add = (map, operation, ms) => map.set(operation, (map.get(operation) ?? 0) + ms);
|
|
120
|
+
// A session's own turn (`turnId`) is cut by the same rules, alone and whatever its date.
|
|
121
|
+
const wanted = query.turnId; let wantedOpen = false;
|
|
122
|
+
// A turn that heard nothing for this long was interrupted (Claude Code closed, the
|
|
123
|
+
// machine slept): Bash's own longest timeout is 10 minutes and a reply streams events
|
|
124
|
+
// well inside that, so half an hour of silence is not a turn still working. It ends
|
|
125
|
+
// where its last event was, instead of counting the idle time as Claude's.
|
|
126
|
+
const IDLE = 30 * 60000;
|
|
118
127
|
for (const [id, call] of calls) {
|
|
119
|
-
const begin = call.turn
|
|
120
|
-
|
|
121
|
-
if (!
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
const begin = call.turn;
|
|
129
|
+
let end = call['turn-end'];
|
|
130
|
+
if (!begin || (wanted ? id !== wanted : begin.t < since || begin.t > until)) continue;
|
|
131
|
+
// The session's own turn: the last thing it heard, and whether Claude went back to
|
|
132
|
+
// work after a Stop (a Stop hook sent it on, so that Stop did not close the turn).
|
|
133
|
+
let last = finite(begin.at) ? begin.at : null;
|
|
134
|
+
if (wanted) {
|
|
135
|
+
for (const c of calls.values()) {
|
|
136
|
+
if (c.start?.turn !== id) continue;
|
|
137
|
+
if (end && finite(c.start.at) && finite(end.at) && c.start.at > end.at) end = undefined;
|
|
138
|
+
for (const edge of [c.start.at, c.end?.at]) if (finite(edge) && last !== null && edge > last) last = edge;
|
|
139
|
+
}
|
|
140
|
+
if (end && finite(end.at) && last !== null && end.at > last) last = end.at;
|
|
141
|
+
}
|
|
142
|
+
let ended = end && finite(begin.at) && finite(end.at) && end.at > begin.at && end.at - begin.at <= DAY;
|
|
143
|
+
let closeAt = ended ? end.at : null;
|
|
144
|
+
if (wanted && !ended && last !== null && last > begin.at && last - begin.at <= DAY && now - last > IDLE) { ended = true; closeAt = last; }
|
|
145
|
+
// That turn, while it is open, runs to now.
|
|
146
|
+
const inFlight = !!wanted && !ended && finite(begin.at) && now > begin.at && now - begin.at <= DAY;
|
|
147
|
+
if (!ended && !inFlight) { sum.open++; wantedOpen = true; continue; }
|
|
148
|
+
const a = begin.at, b = ended ? closeAt : now, spans = [];
|
|
149
|
+
sum.turns++; sum.totalMs += b - a; wantedOpen = !ended;
|
|
150
|
+
if (ended && end?.stop && closeAt === end.at && end.stop !== 'done') stops[end.stop] = (stops[end.stop] ?? 0) + 1;
|
|
151
|
+
// A call still running has no end yet: it is this machine's time up to now, unless it
|
|
152
|
+
// is a question, which is waiting for your answer and so is yours. (The journal holds
|
|
153
|
+
// no event for a permission prompt being answered; the panel moves that wait itself.)
|
|
154
|
+
if (inFlight) for (const open of calls.values()) {
|
|
155
|
+
const s = open.start;
|
|
156
|
+
if (s?.turn !== id || open.end || !finite(s.at) || holders.has(s.tool)) continue;
|
|
157
|
+
spans.push(questions.has(s.tool) ? [s.at, b, you, s.lead ?? s.operations] : [s.at, b, machine, s.lead ?? s.operations]);
|
|
158
|
+
}
|
|
125
159
|
for (const { start: s, end: e } of byTurn.get(id) ?? []) {
|
|
126
160
|
// A command's time is its lead's: npm test's, not the tail reading its output.
|
|
127
161
|
const own = s.lead ?? s.operations;
|
|
@@ -149,6 +183,10 @@ const percentile = (sorted, p) => sorted.length ? sorted[Math.max(0, Math.ceil(s
|
|
|
149
183
|
spend(b);
|
|
150
184
|
if (reply) replies.push([replyFrom, reply]);
|
|
151
185
|
}
|
|
186
|
+
if (wanted) {
|
|
187
|
+
const found = sum.turns > 0 || wantedOpen;
|
|
188
|
+
return { ok: true, turn: found ? { open: wantedOpen, totalMs: sum.totalMs, claudeMs: sum.claudeMs, machineMs: sum.machineMs, youMs: sum.youMs } : null };
|
|
189
|
+
}
|
|
152
190
|
// Claude's replies by the reader's calendar day, so a slow afternoon shows as one.
|
|
153
191
|
const dayOf = new Intl.DateTimeFormat('en-CA', { timeZone: query.timeZone ?? 'UTC', year: 'numeric', month: '2-digit', day: '2-digit' });
|
|
154
192
|
const days = new Map();
|
|
@@ -19,12 +19,21 @@ export function auditQuery(params) {
|
|
|
19
19
|
if (since && (!calendarDate(since) || !calendarDate(until) || since > until || Date.parse(until) - Date.parse(since) >= 90 * 86400000)) return null;
|
|
20
20
|
return { provider, days, timeZone, ...(view === 'skills' ? { view, skill } : { operation }), ...(history ? { history: true } : {}), ...(since ? { since: Date.parse(since), until: Date.parse(until) + 86400000 - 1 } : {}) };
|
|
21
21
|
}
|
|
22
|
+
// `?session=<id>` asks for one session's current turn, or its last, and nothing else: a
|
|
23
|
+
// turn is one answer, not a window of turns, so a range beside it has nothing to narrow.
|
|
24
|
+
export function sessionQuery(params) {
|
|
25
|
+
const session = params.get('session');
|
|
26
|
+
if ([...params.keys()].some(key => key !== 'session') || params.getAll('session').length !== 1 || !/^[\w.:-]{1,256}$/.test(session ?? '')) return null;
|
|
27
|
+
return { provider: 'claude', days: 7, timeZone: 'UTC', session };
|
|
28
|
+
}
|
|
22
29
|
export async function handleToolAudit(req, res) {
|
|
23
30
|
const audit = toolAudit();
|
|
24
31
|
if (!audit) return send(res, 503, { ok: false, reason: 'unavailable' });
|
|
25
32
|
if (req.method === 'GET') {
|
|
26
33
|
if (new URL(req.url, 'http://localhost').pathname.endsWith('/storage')) return send(res, 200, await audit.status());
|
|
27
|
-
const
|
|
34
|
+
const params = new URL(req.url, 'http://localhost').searchParams;
|
|
35
|
+
const bySession = params.has('session');
|
|
36
|
+
const query = bySession ? sessionQuery(params) : auditQuery(params);
|
|
28
37
|
if (!query) return send(res, 400, { ok: false, reason: 'bad_range' });
|
|
29
38
|
const controller = new AbortController();
|
|
30
39
|
const cancel = () => { if (!res.writableEnded) controller.abort(); };
|
|
@@ -33,6 +42,8 @@ export async function handleToolAudit(req, res) {
|
|
|
33
42
|
try { report = await audit.report(query, controller.signal); }
|
|
34
43
|
catch (e) { if (controller.signal.aborted) return; throw e; }
|
|
35
44
|
finally { res.off('close', cancel); }
|
|
45
|
+
// The session's turn alone: no journal totals, no device id, nothing but the lanes.
|
|
46
|
+
if (bySession) return send(res, report.ok ? 200 : 409, report.ok ? report.turn : report);
|
|
36
47
|
// The Skills tab says when the commands a person types cannot be counted.
|
|
37
48
|
if (report.ok && query.view === 'skills' && deckProviders().claude) report.typedCommands = await skillHookState();
|
|
38
49
|
return send(res, report.ok ? 200 : 409, report);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { appendFile, mkdir, readFile, readdir, stat, unlink } from 'node:fs/promises';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { join } from 'node:path';
|
|
5
|
+
import { basename, join } from 'node:path';
|
|
6
6
|
import { Worker } from 'node:worker_threads';
|
|
7
7
|
import { deckDataDir } from './deck-home.mjs';
|
|
8
8
|
import { writeFileAtomic } from './atomic-write.mjs';
|
|
@@ -29,17 +29,26 @@ const runMs = ms => typeof ms === 'number' && Number.isFinite(ms) && ms >= 0 &&
|
|
|
29
29
|
|
|
30
30
|
export function createToolAudit({ dir, now = Date.now, runReport = workerReport } = {}) {
|
|
31
31
|
let meta, readyPromise, serial = Promise.resolve(), pending = [], timer, storageOk = true, dropped = 0, reportFlight = null, prunedDay = null;
|
|
32
|
+
// A session's turn question has a flight of its own, one per session: it must never
|
|
33
|
+
// make the range report (Tool activity) answer busy, nor wait for it.
|
|
34
|
+
const turnFlights = new Map();
|
|
32
35
|
// The last arguments each session typed a command with, as a digest held in memory:
|
|
33
36
|
// the same command again with the same arguments is a repeat, such as a /loop tick.
|
|
34
37
|
const lastArgs = new Map();
|
|
35
38
|
// Each session's calls still running, and whether a permission prompt came up while
|
|
36
39
|
// they did: that is what tells a wait for approval from hooks starting the tool.
|
|
37
40
|
const running = new Map();
|
|
41
|
+
// The prompt each session began last, in memory only: the journal files a turn under a
|
|
42
|
+
// digest of device, epoch, session and prompt together, so a session's turn can be
|
|
43
|
+
// found only by hashing the key the same way. Never written, never answered.
|
|
44
|
+
// `floor` is the earliest time a journal file can hold the turn's rows, so the worker
|
|
45
|
+
// reads those files and no others (null: unknown, read them all).
|
|
46
|
+
const latestTurn = new Map();
|
|
38
47
|
const enqueue = fn => { const task = serial.then(fn); serial = task.catch(() => {}); return task; };
|
|
39
48
|
const ready = () => {
|
|
40
49
|
if (readyPromise) return readyPromise;
|
|
41
50
|
const attempt = (async () => {
|
|
42
|
-
await mkdir(dir, { recursive: true });
|
|
51
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
43
52
|
try { meta = JSON.parse(await readFile(join(dir, 'settings.json'), 'utf8')); }
|
|
44
53
|
catch (e) { if (e.code !== 'ENOENT') throw e; }
|
|
45
54
|
if (meta && !validMeta(meta)) throw new Error('Unreadable tool history settings');
|
|
@@ -113,9 +122,14 @@ export function createToolAudit({ dir, now = Date.now, runReport = workerReport
|
|
|
113
122
|
const key = promptKey(raw);
|
|
114
123
|
if (!key) return;
|
|
115
124
|
const t = now(), at = opts.receivedAt ?? t, start = raw.hook_event_name === 'UserPromptSubmit';
|
|
125
|
+
if (start) noteLatest(raw.session_id, key, t);
|
|
116
126
|
queue({ id: key, provider: 'claude', kind: start ? 'turn' : 'turn-end', t, at: measured(at, t), clock: 'hook',
|
|
117
127
|
...(start ? {} : { stop: raw.hook_event_name === 'Stop' ? 'done' : stopError(raw) }) });
|
|
118
128
|
};
|
|
129
|
+
const noteLatest = (session, key, floor) => {
|
|
130
|
+
latestTurn.delete(session); latestTurn.set(session, { key, floor: Number.isFinite(floor) ? floor : null });
|
|
131
|
+
if (latestTurn.size > 500) latestTurn.delete(latestTurn.keys().next().value);
|
|
132
|
+
};
|
|
119
133
|
const calls = session => {
|
|
120
134
|
let held = running.get(session);
|
|
121
135
|
if (!held) { running.set(session, held = new Map()); if (running.size > 500) running.delete(running.keys().next().value); }
|
|
@@ -124,6 +138,13 @@ export function createToolAudit({ dir, now = Date.now, runReport = workerReport
|
|
|
124
138
|
return {
|
|
125
139
|
async start() { await ready(); },
|
|
126
140
|
observe(raw, source, opts = {}) {
|
|
141
|
+
// The boot replay writes nothing, but it tells a restarted deck which prompt each
|
|
142
|
+
// session began last, so the Time tab can find that turn again (memory only).
|
|
143
|
+
if (opts.replay && source === 'hook' && raw?.hook_event_name === 'UserPromptSubmit' && raw.provider !== 'codex' && typeof raw.session_id === 'string' && raw.session_id.length <= 256) {
|
|
144
|
+
const key = promptKey(raw);
|
|
145
|
+
if (key) noteLatest(raw.session_id, key, Number.isFinite(opts.receivedAt) ? opts.receivedAt - 3600000 : null);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
127
148
|
if (opts.replay || !['hook', 'codex'].includes(source)) return;
|
|
128
149
|
if (raw?.hook_event_name === 'UserPromptExpansion' && source === 'hook') return typed(raw, opts);
|
|
129
150
|
const claudeHook = source === 'hook' && raw?.provider !== 'codex' && typeof raw?.session_id === 'string' && raw.session_id.length <= 256;
|
|
@@ -146,7 +167,7 @@ export function createToolAudit({ dir, now = Date.now, runReport = workerReport
|
|
|
146
167
|
if (name) Object.assign(row, skillUse(name, 'agent', raw.session_id, raw.cwd, typeof raw.agent_id === 'string' && raw.agent_id));
|
|
147
168
|
if (claudeHook) {
|
|
148
169
|
const key = promptKey(raw);
|
|
149
|
-
if (key) row.turn = key;
|
|
170
|
+
if (key) { row.turn = key; if (!latestTurn.has(raw.session_id)) noteLatest(raw.session_id, key, t - DAY); }
|
|
150
171
|
const held = calls(raw.session_id);
|
|
151
172
|
held.set(raw.tool_use_id, false);
|
|
152
173
|
if (held.size > 200) held.delete(held.keys().next().value);
|
|
@@ -180,18 +201,31 @@ export function createToolAudit({ dir, now = Date.now, runReport = workerReport
|
|
|
180
201
|
async clear() { return enqueue(async () => {
|
|
181
202
|
await flush();
|
|
182
203
|
for (const name of await files()) await unlink(join(dir, name));
|
|
183
|
-
meta = { ...meta, epoch: randomUUID(), startedAt: now(), skillsSince: now(), turnsSince: now() }; await saveMeta(); dropped = 0; storageOk = true; lastArgs.clear(); running.clear();
|
|
204
|
+
meta = { ...meta, epoch: randomUUID(), startedAt: now(), skillsSince: now(), turnsSince: now() }; await saveMeta(); dropped = 0; storageOk = true; lastArgs.clear(); running.clear(); latestTurn.clear();
|
|
184
205
|
return { ok: true };
|
|
185
206
|
}); },
|
|
186
207
|
async report(query, signal) {
|
|
187
|
-
|
|
188
|
-
reportFlight
|
|
208
|
+
const asking = query.session;
|
|
209
|
+
if (asking === undefined ? reportFlight : turnFlights.has(asking)) return { ok: false, reason: 'busy' };
|
|
210
|
+
const flight = (async () => {
|
|
211
|
+
// `session` is the one query that names a session. It leaves here as the digest
|
|
212
|
+
// of that session's latest turn, so the worker never sees the id.
|
|
213
|
+
const latest = asking === undefined ? undefined : latestTurn.get(asking);
|
|
214
|
+
if (asking !== undefined && !latest) return { ok: true, turn: null };
|
|
189
215
|
const snapshot = await enqueue(async () => { await flush(); const inv = await inventory(); return { ...inv, meta: { ...meta }, storageOk, dropped }; });
|
|
190
|
-
const
|
|
216
|
+
const { session, ...rest } = query;
|
|
217
|
+
let asked = query, files = snapshot.journal;
|
|
218
|
+
if (latest) {
|
|
219
|
+
asked = { ...rest, turnId: digest(`${snapshot.meta.deviceId}|${snapshot.meta.epoch}|${latest.key}`) };
|
|
220
|
+
// The turn's rows sit in the file of the day it began or a later one.
|
|
221
|
+
if (latest.floor !== null) { const from = `${date(latest.floor)}.jsonl`; files = files.filter(file => basename(file.path) >= from); }
|
|
222
|
+
}
|
|
223
|
+
const result = await runReport({ files, query: asked, now: now(), meta: snapshot.meta }, signal);
|
|
191
224
|
if (meta.epoch !== snapshot.meta.epoch) return { ok: false, reason: 'history_cleared' };
|
|
192
225
|
return { ...result, bytes: snapshot.bytes, storageOk: snapshot.storageOk, dropped: snapshot.dropped, deviceId: snapshot.meta.deviceId, startedAt: snapshot.meta.startedAt, skillsSince: snapshot.meta.skillsSince, turnsSince: snapshot.meta.turnsSince, retentionDays: snapshot.meta.retentionDays };
|
|
193
226
|
})();
|
|
194
|
-
|
|
227
|
+
if (asking === undefined) reportFlight = flight; else turnFlights.set(asking, flight);
|
|
228
|
+
try { return await flight; } finally { if (asking === undefined) reportFlight = null; else turnFlights.delete(asking); }
|
|
195
229
|
},
|
|
196
230
|
async close() { await enqueue(flush); },
|
|
197
231
|
};
|
|
@@ -14,7 +14,7 @@ export function capturePreferences(directory = join(homedir(), '.agents-deck'),
|
|
|
14
14
|
async read(port) { try { return JSON.parse(await readFile(file(port), 'utf8')); } catch { return null; } },
|
|
15
15
|
write(port, value) {
|
|
16
16
|
writes = writes.catch(() => {}).then(async () => {
|
|
17
|
-
await mkdir(directory, { recursive: true });
|
|
17
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
18
18
|
const target = file(port), temp = target + `.${process.pid}.tmp`;
|
|
19
19
|
await writeFile(temp, JSON.stringify(value), { mode: 0o600 });
|
|
20
20
|
await chmod(temp, 0o600); await renameWithRetry(temp, target);
|
|
@@ -107,7 +107,7 @@ setcap cap_net_raw,cap_net_admin=eip "$tool"
|
|
|
107
107
|
/** The script, written where its owner can read it, and the command that runs it. */
|
|
108
108
|
async function handOver(script, directory) {
|
|
109
109
|
const file = join(directory, 'radar-capture-setup.sh');
|
|
110
|
-
await mkdir(directory, { recursive: true });
|
|
110
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
111
111
|
await writeFile(file, script, { mode: 0o600 });
|
|
112
112
|
return `sudo sh '${file.replaceAll("'", "'\\''")}'`;
|
|
113
113
|
}
|
|
@@ -60,7 +60,7 @@ import { foldsCase } from "./log-election.mjs";
|
|
|
60
60
|
// costs nothing (it is a directory only this user writes either way) and
|
|
61
61
|
// removes half of that failure mode. The other half is why the refusal is
|
|
62
62
|
// logged rather than silent.
|
|
63
|
-
function claudeTranscriptRoots() {
|
|
63
|
+
export function claudeTranscriptRoots() {
|
|
64
64
|
// Resolved per call, like every other claudeConfigDir() reader in src/server,
|
|
65
65
|
// so nothing captures the answer from an environment that has moved.
|
|
66
66
|
const roots = [resolve(claudeConfigDir(), "projects")];
|
|
@@ -356,6 +356,7 @@ function newTranscriptState() {
|
|
|
356
356
|
subagentModels: {},
|
|
357
357
|
aiTitle: null, // newest "ai-title" entry, the session's sentence title
|
|
358
358
|
agentName: null, // newest "agent-name" entry, the session's short name
|
|
359
|
+
customTitle: null, // newest "custom-title" entry, the name the user gave it
|
|
359
360
|
recap: null, // newest "away_summary" no later turn retired — session-recap.mjs
|
|
360
361
|
usage: newUsageTotals(),
|
|
361
362
|
// The same totals, split by the model that produced them (#686). The flat
|
|
@@ -376,11 +377,17 @@ function newTranscriptState() {
|
|
|
376
377
|
}
|
|
377
378
|
|
|
378
379
|
// ─── Session naming ──────────────────────────────────────────────────────
|
|
379
|
-
// CC writes
|
|
380
|
-
// the transcript carries
|
|
380
|
+
// CC writes three whole-line records that name the session, and nothing else in
|
|
381
|
+
// the transcript carries any of them:
|
|
381
382
|
//
|
|
382
383
|
// {"type":"ai-title","aiTitle":"Inspect repository to understand current state","sessionId":"…"}
|
|
383
384
|
// {"type":"agent-name","agentName":"account-management-oauth-flow","sessionId":"…"}
|
|
385
|
+
// {"type":"custom-title","customTitle":"loroloop","sessionId":"…"}
|
|
386
|
+
//
|
|
387
|
+
// The third is the name the USER gave the session, with /rename or `--name`:
|
|
388
|
+
// the one Claude Code prints in its prompt separator, so it is the one the deck
|
|
389
|
+
// shows ahead of the other two. A rename appends a new record, so the last one
|
|
390
|
+
// wins here too.
|
|
384
391
|
//
|
|
385
392
|
// Both are re-emitted on roughly every turn rather than only when they change.
|
|
386
393
|
// Measured on the two largest transcripts on this machine: 685 `ai-title`
|
|
@@ -398,15 +405,14 @@ function newTranscriptState() {
|
|
|
398
405
|
// would repeat the card.
|
|
399
406
|
const AI_TITLE_MARK = '"ai-title"';
|
|
400
407
|
const AGENT_NAME_MARK = '"agent-name"';
|
|
408
|
+
const CUSTOM_TITLE_MARK = '"custom-title"';
|
|
401
409
|
|
|
402
410
|
/** Fold one line's naming records into `out`. Last value wins. Pure: `out` is
|
|
403
|
-
* the only thing written, and a line that is not one of the
|
|
404
|
-
* is a truncated fragment of one — leaves it untouched. */
|
|
411
|
+
* the only thing written, and a line that is not one of the three records —
|
|
412
|
+
* or is a truncated fragment of one — leaves it untouched. */
|
|
405
413
|
export function foldSessionNamingLine(out, line) {
|
|
406
414
|
if (!line) return;
|
|
407
|
-
|
|
408
|
-
const hasName = line.includes(AGENT_NAME_MARK);
|
|
409
|
-
if (!hasTitle && !hasName) return;
|
|
415
|
+
if (!line.includes(AI_TITLE_MARK) && !line.includes(AGENT_NAME_MARK) && !line.includes(CUSTOM_TITLE_MARK)) return;
|
|
410
416
|
let obj = null;
|
|
411
417
|
try { obj = JSON.parse(line); } catch { return; }
|
|
412
418
|
if (!obj || typeof obj !== "object") return;
|
|
@@ -414,6 +420,8 @@ export function foldSessionNamingLine(out, line) {
|
|
|
414
420
|
out.aiTitle = obj.aiTitle;
|
|
415
421
|
} else if (obj.type === "agent-name" && typeof obj.agentName === "string" && obj.agentName) {
|
|
416
422
|
out.agentName = obj.agentName;
|
|
423
|
+
} else if (obj.type === "custom-title" && typeof obj.customTitle === "string" && obj.customTitle.trim()) {
|
|
424
|
+
out.customTitle = obj.customTitle;
|
|
417
425
|
}
|
|
418
426
|
}
|
|
419
427
|
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { codexItemText } from "./codex-translate.mjs";
|
|
2
|
+
|
|
3
|
+
// A Claude Code transcript's lines, as the turns Chat draws: what you typed,
|
|
4
|
+
// what the assistant said, and one row per tool call. Pure: lines in, turns
|
|
5
|
+
// out, nothing read from disk and nothing remembered between calls.
|
|
6
|
+
//
|
|
7
|
+
// WHAT IS LEFT OUT, ON PURPOSE. Thinking blocks (they are not part of the
|
|
8
|
+
// conversation a reader follows), sidechain lines (a subagent's own talk),
|
|
9
|
+
// meta lines (text Claude Code wrote for itself), and a user line that only
|
|
10
|
+
// carries a tool's answer: that is the tool replying, not you typing.
|
|
11
|
+
//
|
|
12
|
+
// BOUNDED. Chat has no virtualisation, so the answer is the last MAX_TURNS
|
|
13
|
+
// turns and each text is cut at MAX_TEXT, because the transcript's own size
|
|
14
|
+
// says nothing about how much a page can draw.
|
|
15
|
+
export const MAX_TURNS = 200;
|
|
16
|
+
export const MAX_TEXT = 4000;
|
|
17
|
+
export const MAX_ARG = 120;
|
|
18
|
+
|
|
19
|
+
// The input fields a tool call is summed up by, in the order they are tried:
|
|
20
|
+
// what a command ran, then which file, folder, pattern or address it touched.
|
|
21
|
+
const ARG_FIELDS = ["command", "file_path", "path", "pattern", "url", "description"];
|
|
22
|
+
|
|
23
|
+
const cut = (text, max) => (text.length > max ? `${text.slice(0, max - 1)}…` : text);
|
|
24
|
+
|
|
25
|
+
/** One line of a tool call's input, or an empty string. */
|
|
26
|
+
export function toolArg(input) {
|
|
27
|
+
if (!input || typeof input !== "object") return "";
|
|
28
|
+
for (const field of ARG_FIELDS) {
|
|
29
|
+
const value = input[field];
|
|
30
|
+
if (typeof value !== "string") continue;
|
|
31
|
+
const first = value.split(/\r?\n/).find(line => line.trim() !== "");
|
|
32
|
+
if (first !== undefined) return cut(first.trim(), MAX_ARG);
|
|
33
|
+
}
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function parse(line) {
|
|
38
|
+
if (!line) return null;
|
|
39
|
+
try {
|
|
40
|
+
const rec = JSON.parse(line);
|
|
41
|
+
return rec && typeof rec === "object" ? rec : null;
|
|
42
|
+
} catch { return null; }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// CLAUDE CODE'S OWN BOOKKEEPING IS NOT WHAT THE PERSON TYPED. A slash
|
|
46
|
+
// command's wrappers, a local command's output, an interruption note, the
|
|
47
|
+
// notice a background task sends when it finishes, and the summary written
|
|
48
|
+
// when a conversation is compacted are all user lines in the file, but none
|
|
49
|
+
// was typed, and the summary alone runs to thousands of characters. They would
|
|
50
|
+
// be drawn as "you said".
|
|
51
|
+
const WRAPPERS = /<(command-name|command-message|command-args|local-command-stdout|local-command-stderr)>[\s\S]*?<\/\1>/g;
|
|
52
|
+
// The notice has to OPEN the line, as the rail reads it (injected-prompt.ts):
|
|
53
|
+
// a person who mentions the tag mid-sentence typed it.
|
|
54
|
+
const TASK_NOTICE = /^\s*<task-notification>[\s\S]*?<\/task-notification>/;
|
|
55
|
+
const INTERRUPTED = /^\[Request interrupted by user/;
|
|
56
|
+
const SUMMARY_LEAD = /^This session is being continued from a previous conversation/;
|
|
57
|
+
|
|
58
|
+
/** The text a user line carries: a string, or its text parts joined, without the bookkeeping. */
|
|
59
|
+
function userText(content) {
|
|
60
|
+
let text;
|
|
61
|
+
if (typeof content === "string") text = content;
|
|
62
|
+
else if (Array.isArray(content)) {
|
|
63
|
+
text = content
|
|
64
|
+
.filter(part => part && part.type === "text" && typeof part.text === "string")
|
|
65
|
+
.map(part => part.text)
|
|
66
|
+
.join("\n");
|
|
67
|
+
} else return "";
|
|
68
|
+
text = text.replace(WRAPPERS, "").trim().replace(TASK_NOTICE, "").trim();
|
|
69
|
+
return INTERRUPTED.test(text) ? "" : text;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The turns in `lines`, oldest first.
|
|
74
|
+
*
|
|
75
|
+
* A tool call with no answer anywhere in `lines` is `running`. The answer is
|
|
76
|
+
* looked for in every line, a sidechain's included, since only the id ties
|
|
77
|
+
* them together.
|
|
78
|
+
*/
|
|
79
|
+
export function transcriptTurns(lines) {
|
|
80
|
+
return transcriptWindow(lines).turns;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The same turns, and whether the cap on them dropped any from the front. */
|
|
84
|
+
export function transcriptWindow(lines) {
|
|
85
|
+
const records = [];
|
|
86
|
+
const answered = new Set();
|
|
87
|
+
for (const line of lines) {
|
|
88
|
+
const rec = parse(line);
|
|
89
|
+
if (!rec) continue;
|
|
90
|
+
records.push(rec);
|
|
91
|
+
const content = rec.message?.content;
|
|
92
|
+
if (rec.type === "user" && Array.isArray(content)) {
|
|
93
|
+
for (const part of content) {
|
|
94
|
+
if (part?.type === "tool_result" && typeof part.tool_use_id === "string") answered.add(part.tool_use_id);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const turns = [];
|
|
99
|
+
let afterCompaction = false;
|
|
100
|
+
for (const rec of records) {
|
|
101
|
+
if (rec.type === "system") afterCompaction = rec.subtype === "compact_boundary";
|
|
102
|
+
if (rec.isSidechain === true || rec.isMeta === true) continue;
|
|
103
|
+
const content = rec.message?.content;
|
|
104
|
+
if (rec.type === "user") {
|
|
105
|
+
const summary = rec.isCompactSummary === true || (afterCompaction && SUMMARY_LEAD.test(userText(content)));
|
|
106
|
+
afterCompaction = false;
|
|
107
|
+
if (summary) continue;
|
|
108
|
+
const text = userText(content);
|
|
109
|
+
if (text) turns.push({ kind: "user", text: cut(text, MAX_TEXT) });
|
|
110
|
+
} else if (rec.type === "assistant" && Array.isArray(content)) {
|
|
111
|
+
for (const part of content) {
|
|
112
|
+
if (!part || typeof part !== "object") continue;
|
|
113
|
+
if (part.type === "text" && typeof part.text === "string" && part.text.trim()) {
|
|
114
|
+
turns.push({ kind: "assistant", text: cut(part.text.trim(), MAX_TEXT) });
|
|
115
|
+
} else if (part.type === "tool_use" && typeof part.name === "string") {
|
|
116
|
+
const turn = { kind: "tool", name: cut(part.name, MAX_ARG), arg: toolArg(part.input) };
|
|
117
|
+
if (typeof part.id !== "string" || !answered.has(part.id)) turn.running = true;
|
|
118
|
+
turns.push(turn);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return capTurns(turns);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function capTurns(turns) {
|
|
127
|
+
return turns.length > MAX_TURNS ? { turns: turns.slice(-MAX_TURNS), cut: true } : { turns, cut: false };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Prefer Codex's conversation events. The model-facing response items repeat
|
|
131
|
+
* these messages and can also carry injected user-role context. */
|
|
132
|
+
export function codexTranscriptWindow(lines) {
|
|
133
|
+
const turns = [];
|
|
134
|
+
for (const line of lines) {
|
|
135
|
+
const record = parse(line);
|
|
136
|
+
if (record?.type !== "event_msg") continue;
|
|
137
|
+
const event = record.payload;
|
|
138
|
+
let kind, text;
|
|
139
|
+
if (event?.type === "user_message" || event?.type === "agent_message") {
|
|
140
|
+
kind = event.type === "user_message" ? "user" : "assistant";
|
|
141
|
+
text = event.message;
|
|
142
|
+
} else if (event?.type === "item_completed") {
|
|
143
|
+
if (event.item?.type === "UserMessage") {
|
|
144
|
+
kind = "user";
|
|
145
|
+
text = codexItemText(event.item);
|
|
146
|
+
} else if (event.item?.type === "AgentMessage") {
|
|
147
|
+
kind = "assistant";
|
|
148
|
+
text = typeof event.item.content === "string" ? event.item.content : codexItemText(event.item);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (typeof text === "string" && text.trim()) turns.push({ kind, text: cut(text.trim(), MAX_TEXT) });
|
|
152
|
+
}
|
|
153
|
+
return capTurns(turns);
|
|
154
|
+
}
|
|
@@ -676,6 +676,7 @@ export const LAN_REFUSED = Object.freeze({
|
|
|
676
676
|
unreachable: "Nothing answered at any address in that invite. Check that deck is running with its Local network switch on.",
|
|
677
677
|
prefs_unreadable: "this deck cannot read its settings file, so it will not write over it. The deck's log names the file.",
|
|
678
678
|
prefs_not_writable: "this deck is not allowed to save its settings. The deck's log names the folder.",
|
|
679
|
+
prefs_no_space: "the disk this deck saves its settings on is full, so they were not saved. Free some space, then try again.",
|
|
679
680
|
bad_request: "the deck did not take that",
|
|
680
681
|
unknown_action: "this deck does not know that yet — an update of ccdeck brings it",
|
|
681
682
|
});
|
package/src/server/tui-view.mjs
CHANGED
|
@@ -1072,6 +1072,28 @@ function accountRows(rows, { home, at, width }, look) {
|
|
|
1072
1072
|
});
|
|
1073
1073
|
}
|
|
1074
1074
|
|
|
1075
|
+
/**
|
|
1076
|
+
* A window whose reset has passed since it was read (#100). Its number is the
|
|
1077
|
+
* old window's, and nothing is known about the new one until claude-swap reads
|
|
1078
|
+
* it again — the panel's own rule (lane-view.ts `lapsed`), which draws it as
|
|
1079
|
+
* reset rather than as the number it had, and not as 0% either, which nobody
|
|
1080
|
+
* has read. Here it went on showing that number under "live", the countdown
|
|
1081
|
+
* gone, for as long as the screen stayed up.
|
|
1082
|
+
*/
|
|
1083
|
+
export function lapsed(l, now) {
|
|
1084
|
+
return typeof l?.resetAt === "number" && Number.isFinite(l.resetAt) && l.resetAt > 0 && l.resetAt * 1000 <= now;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
/** A lapsed lane in the list: an empty meter one cell shorter and "reset"
|
|
1088
|
+
* where the percentage was, in the same width; the glyph alone where there is
|
|
1089
|
+
* no meter. */
|
|
1090
|
+
function lapsedCell(head, { kind, bar }, look) {
|
|
1091
|
+
const { tone, g } = look;
|
|
1092
|
+
if (kind === "C") return `${head}${tone.muted}${padStart(g.restart, 4)}${tone.reset}`;
|
|
1093
|
+
const cell = `${head}${gauge(0, Math.max(0, bar - 1), look)} ${tone.muted}reset${tone.reset}`;
|
|
1094
|
+
return kind === "B" ? cell : `${cell} ${" ".repeat(9)}`;
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1075
1097
|
function laneCells(a, { kind, bar }, labelW, look) {
|
|
1076
1098
|
const { tone, g, now } = look;
|
|
1077
1099
|
const lanes = LANE_IDS.map(id => (a.lanes ?? []).find(l => l.id === id) ?? null);
|
|
@@ -1079,6 +1101,7 @@ function laneCells(a, { kind, bar }, labelW, look) {
|
|
|
1079
1101
|
return lanes.map(l => {
|
|
1080
1102
|
if (!l) return " ".repeat(laneWidth(kind, bar, labelW));
|
|
1081
1103
|
const head = `${tone.muted}${padEnd(oneLine(l.label), labelW)}${tone.reset} `;
|
|
1104
|
+
if (lapsed(l, now)) return lapsedCell(head, { kind, bar }, look);
|
|
1082
1105
|
const pct = `${pctTone(l.pct, tone)}${padStart(`${Math.round(l.pct)}%`, 4)}${tone.reset}`;
|
|
1083
1106
|
if (kind === "C") return `${head}${pct}`;
|
|
1084
1107
|
if (kind === "B") return `${head}${gauge(l.pct, bar, look)} ${pct}`;
|
|
@@ -1143,6 +1166,11 @@ function detailPanel(a, home, width, look) {
|
|
|
1143
1166
|
note,
|
|
1144
1167
|
lines: [...said, ...lanes.map((l, i) => {
|
|
1145
1168
|
const u = untils[i];
|
|
1169
|
+
if (lapsed(l, now)) {
|
|
1170
|
+
// One cell off the meter for the space a percentage carries in its
|
|
1171
|
+
// pad: "reset" is as wide as that pad, and would touch the meter.
|
|
1172
|
+
return `${tone.muted}${padEnd(oneLine(l.label), labelW)}${tone.reset} ${gauge(0, Math.max(0, bar - 1), look)} ${tone.muted}reset${tone.reset}`;
|
|
1173
|
+
}
|
|
1146
1174
|
const reset = !tail || !u ? "" : tail === words ? ` ${tone.muted}resets in ${u}${tone.reset}` : ` ${tone.muted}${g.restart} ${u}${tone.reset}`;
|
|
1147
1175
|
return `${tone.muted}${padEnd(oneLine(l.label), labelW)}${tone.reset} ${gauge(l.pct, bar, look)}`
|
|
1148
1176
|
+ `${pctTone(l.pct, tone)}${padStart(`${Math.round(l.pct)}%`, 5)}${tone.reset}${reset}`;
|