claude-code-session-manager 0.137.0 → 0.139.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/.claude-plugin/marketplace.json +1 -1
- package/README.md +339 -82
- package/dist/assets/{AppSettings-l7NTc0yu.js → AppSettings-CUfWY9vN.js} +2 -2
- package/dist/assets/History-DDnqaLyw.js +2 -0
- package/dist/assets/HomeClaudeConfig-CGD2Onjv.js +3 -0
- package/dist/assets/{Panel-BuInRmA0.js → Panel-Csyd9HbD.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-C-jlYpC_.js +26 -0
- package/dist/assets/{Scheduler-B7sn2mUw.js → Scheduler-NLs08fx7.js} +9 -9
- package/dist/assets/{SkillReferenceGraph-DwV0Ueyc.js → SkillReferenceGraph-DcscPXAG.js} +1 -1
- package/dist/assets/Skills-BpGRKOcY.js +67 -0
- package/dist/assets/{TiptapBody-Bl8hDhhS.js → TiptapBody-DSU3769X.js} +60 -54
- package/dist/assets/ViewTabs-C0PRZx4_.js +1 -0
- package/dist/assets/{VoiceButton-DJx-jY4r.js → VoiceButton-D2rMurNg.js} +1 -1
- package/dist/assets/{historyTotals-Cgjm5q24.js → historyTotals-TcIQs2sh.js} +1 -1
- package/dist/assets/{index-62tyjEQB.css → index-BCySPdtU.css} +1 -1
- package/dist/assets/index-C-d0DCre.js +3124 -0
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +471 -452
- package/package.json +13 -5
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/builder/SKILL.md +12 -4
- package/plugins/session-manager-dev/skills/builder/scripts/publish-preflight.cjs +255 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +12 -5
- package/scripts/README.md +1 -0
- package/scripts/scheduler-mcp-server.cjs +161 -18
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +53 -2
- package/src/main/exchanges.cjs +70 -5
- package/src/main/historyAggregator.cjs +84 -58
- package/src/main/historyDashboard.cjs +18 -13
- package/src/main/index.cjs +35 -9
- package/src/main/ipcSchemas.cjs +133 -5
- package/src/main/lib/claude/effectiveModelInfo.cjs +2 -2
- package/src/main/lib/claude/modelPricing.cjs +148 -0
- package/src/main/lib/demo-video-kit/checks.cjs +16 -0
- package/src/main/lib/epic/epicAdminRoutes.cjs +101 -0
- package/src/main/lib/epic/epicAttachments.cjs +143 -0
- package/src/main/lib/epic/epicJobReceipt.cjs +87 -0
- package/src/main/lib/epic/epicMint.cjs +4 -0
- package/src/main/lib/epic/epicOutsideRead.cjs +306 -0
- package/src/main/lib/epic/epicOutsideState.cjs +233 -0
- package/src/main/lib/epic/epicSettle.cjs +1 -1
- package/src/main/lib/epic/epicStateWatcher.cjs +157 -0
- package/src/main/lib/epic/externalRef.cjs +37 -0
- package/src/main/lib/epic/externalRefIndex.cjs +136 -0
- package/src/main/lib/epic/restorableSessions.cjs +151 -17
- package/src/main/lib/epic/transcriptUsage.cjs +197 -0
- package/src/main/lib/externalContract.cjs +111 -0
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +121 -4
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +83 -1
- package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -6
- package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +50 -8
- package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +218 -4
- package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +19 -3
- package/src/main/lib/feedback-remote/feedbackImages.cjs +171 -0
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +11 -10
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +287 -1
- package/src/main/lib/feedback-remote/needsYouAdminRoutes.cjs +133 -0
- package/src/main/lib/feedback-remote/needsYouIpc.cjs +50 -0
- package/src/main/lib/feedback-remote/needsYouStore.cjs +281 -0
- package/src/main/lib/feedback-remote/remoteFrameAssembler.cjs +113 -0
- package/src/main/lib/historyRollup.cjs +32 -5
- package/src/main/lib/mcpToolCatalog.cjs +111 -14
- package/src/main/lib/persona-macro/agentAdminRoutes.cjs +121 -0
- package/src/main/lib/persona-macro/macroLibrary.cjs +7 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
- package/src/main/lib/process/bootStdioGuard.cjs +32 -0
- package/src/main/lib/process/stdioGuard.cjs +115 -0
- package/src/main/lib/promptSessionSchema.cjs +4 -0
- package/src/main/lib/remoteTranscriptTail.cjs +32 -1
- package/src/main/lib/scheduler/schedulerPaths.cjs +9 -0
- package/src/main/lib/telemetry/auditEvents.cjs +176 -0
- package/src/main/lib/telemetry/eventsAdminRoutes.cjs +45 -0
- package/src/main/loopEfficiencyHandlers.cjs +1 -1
- package/src/main/scheduler.cjs +29 -0
- package/src/main/templates/PRD_AUTHORING.md +1 -0
- package/src/main/transcripts.cjs +62 -7
- package/src/main/webRemote.cjs +122 -18
- package/src/preload/api.d.ts +98 -9
- package/src/preload/apiSurface.cjs +7 -0
- package/src/preload/apiSurface.json +415 -83
- package/src/preload/index.cjs +17 -3
- package/src/seed/agents/demo-video-builder.md +10 -7
- package/dist/assets/AgentLibrary-DV0DTZDC.js +0 -2
- package/dist/assets/Button-Cmfkgjfa.js +0 -1
- package/dist/assets/DocumentEditorPane-MTljV-Uw.js +0 -1
- package/dist/assets/Extensions-Cc1Q_8id.js +0 -2
- package/dist/assets/History-CFo-1DHo.js +0 -2
- package/dist/assets/Library-C_ibFiOx.js +0 -32
- package/dist/assets/ListDetail-ByULG209.js +0 -1
- package/dist/assets/ProjectClaudeConfig-yqqVtHY7.js +0 -25
- package/dist/assets/ProvenanceBadge-CJvnQReI.js +0 -1
- package/dist/assets/Settings-DRRSJksU.js +0 -2
- package/dist/assets/Skills-DVYHA9gV.js +0 -29
- package/dist/assets/SourceChip-DfJ5_5rV.js +0 -1
- package/dist/assets/SystemPrompt-f11wGllK.js +0 -1
- package/dist/assets/Toggle-DaxeFDFp.js +0 -1
- package/dist/assets/ViewTabs-DRtgFKRw.js +0 -1
- package/dist/assets/claude-settings-schema-COigsajx.js +0 -3
- package/dist/assets/index-iQ6pdyuS.js +0 -3116
|
@@ -7,6 +7,7 @@ const os = require('node:os');
|
|
|
7
7
|
const { schemas } = require('./ipcSchemas.cjs');
|
|
8
8
|
const historyRollup = require('./lib/historyRollup.cjs');
|
|
9
9
|
const { sendIfAlive } = require('./lib/sendToRenderer.cjs');
|
|
10
|
+
const { costOfUsage } = require('./lib/claude/modelPricing.cjs');
|
|
10
11
|
|
|
11
12
|
const PROJECTS_DIR = path.join(os.homedir(), '.claude', 'projects');
|
|
12
13
|
const PARSE_BUDGET_MS = 2_000;
|
|
@@ -18,37 +19,6 @@ const MAX_FILE_BYTES = 20 * 1024 * 1024;
|
|
|
18
19
|
// range hit cache instead of self-evicting mid-scan and spuriously truncating.
|
|
19
20
|
const CACHE_MAX = 50_000;
|
|
20
21
|
|
|
21
|
-
// Dollars per million tokens (input / output / cache-read). Cache-read
|
|
22
|
-
// tokens are priced far below input because they're served from
|
|
23
|
-
// Anthropic's prompt cache, not re-processed — this is what makes the
|
|
24
|
-
// cache-savings figure in the dashboard real money, not a vanity stat.
|
|
25
|
-
// fable: Claude Fable 5.1 (claude-fable-5-1) — $10/$50 per MTok input/output,
|
|
26
|
-
// cache reads at $0.25/MTok (the `claude-api` skill's model reference and its
|
|
27
|
-
// Claude Fable 5.1 migration notes, both cached 2026-06-24).
|
|
28
|
-
const MODEL_PRICING = {
|
|
29
|
-
opus: { i: 15, o: 75, c: 1.5 },
|
|
30
|
-
sonnet: { i: 3, o: 15, c: 0.3 },
|
|
31
|
-
haiku: { i: 0.8, o: 4, c: 0.08 },
|
|
32
|
-
fable: { i: 10, o: 50, c: 0.25 },
|
|
33
|
-
};
|
|
34
|
-
const DEFAULT_PRICING_KEY = 'sonnet'; // fallback for unrecognized model ids
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Resolve a raw model id (e.g. "claude-opus-4-8-20260115") to a pricing
|
|
38
|
-
* bucket key. Model ids aren't stable enough to match exactly, so this is a
|
|
39
|
-
* case-insensitive substring check. Unrecognized ids fall back to
|
|
40
|
-
* DEFAULT_PRICING_KEY and are flagged so callers can annotate them as
|
|
41
|
-
* estimated rather than exact.
|
|
42
|
-
*/
|
|
43
|
-
function resolvePricingKey(modelId) {
|
|
44
|
-
const id = String(modelId ?? '').toLowerCase();
|
|
45
|
-
if (id.includes('opus')) return { key: 'opus', estimated: false };
|
|
46
|
-
if (id.includes('sonnet')) return { key: 'sonnet', estimated: false };
|
|
47
|
-
if (id.includes('haiku')) return { key: 'haiku', estimated: false };
|
|
48
|
-
if (id.includes('fable')) return { key: 'fable', estimated: false };
|
|
49
|
-
return { key: DEFAULT_PRICING_KEY, estimated: true };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
22
|
// ── LRU cache ─────────────────────────────────────────────────────────────────
|
|
53
23
|
// Shared implementation: lib/util/lruCache.cjs (re-exported below for existing callers).
|
|
54
24
|
const { LRUCache } = require('./lib/util/lruCache.cjs');
|
|
@@ -96,7 +66,10 @@ async function appendRollupAndNotify(entries) {
|
|
|
96
66
|
|
|
97
67
|
/**
|
|
98
68
|
* Cache for parseJSONL results.
|
|
99
|
-
* Entry shape: { mtimeMs: number, size: number, readOffset: number, inode: number,
|
|
69
|
+
* Entry shape: { mtimeMs: number, size: number, readOffset: number, inode: number,
|
|
70
|
+
* recentIds: Map<string, usage>, result: AggrResult }
|
|
71
|
+
* `recentIds` = the last 64 message ids with their counted usage, handed to
|
|
72
|
+
* the next tail parse so a message straddling two reads is counted once.
|
|
100
73
|
* `size` mirrors stat.size (used for exact-hit comparison).
|
|
101
74
|
* `readOffset` is the byte position of the end of the last complete line
|
|
102
75
|
* (≤ size) — the start position for the next tail-read so we never start
|
|
@@ -177,8 +150,17 @@ async function readSlice(filePath, from, to) {
|
|
|
177
150
|
|
|
178
151
|
// ── line scanners ─────────────────────────────────────────────────────────────
|
|
179
152
|
|
|
153
|
+
// cacheCreation1hTokens is the 1-hour part of cacheCreationTokens
|
|
154
|
+
// (usage.cache_creation.ephemeral_1h_input_tokens); it is priced differently
|
|
155
|
+
// from the 5-minute part, so it is kept alongside the sum.
|
|
156
|
+
const USAGE_FIELDS = ['inputTokens', 'outputTokens', 'cacheReadTokens', 'cacheCreationTokens', 'cacheCreation1hTokens'];
|
|
157
|
+
/** How many recent message ids the accumulator (and the cache entry) remembers. */
|
|
158
|
+
const RECENT_IDS_MAX = 64;
|
|
159
|
+
|
|
180
160
|
/**
|
|
181
161
|
* Scan JSONL lines into an aggregate accumulator (mutates acc).
|
|
162
|
+
* acc.recentIds (Map<message.id, counted usage>, created on demand, last
|
|
163
|
+
* RECENT_IDS_MAX ids) makes a repeated message.id count once.
|
|
182
164
|
* Returns { firstTs, lastTs } — firstTs is only captured when
|
|
183
165
|
* captureFirst=true (else null); lastTs is the most recent event timestamp
|
|
184
166
|
* seen in this batch of lines (file order, so simply "last one wins").
|
|
@@ -209,22 +191,48 @@ function scanAggrLines(lines, acc, captureFirst) {
|
|
|
209
191
|
const outT = usage.output_tokens ?? usage.outputTokens;
|
|
210
192
|
const cacheR = usage.cache_read_input_tokens ?? usage.cacheReadInputTokens;
|
|
211
193
|
const cacheC = usage.cache_creation_input_tokens ?? usage.cacheCreationInputTokens;
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
194
|
+
const cacheC1h = usage.cache_creation?.ephemeral_1h_input_tokens;
|
|
195
|
+
const vals = {
|
|
196
|
+
inputTokens: typeof inT === 'number' ? inT : 0,
|
|
197
|
+
outputTokens: typeof outT === 'number' ? outT : 0,
|
|
198
|
+
cacheReadTokens: typeof cacheR === 'number' ? cacheR : 0,
|
|
199
|
+
cacheCreationTokens: typeof cacheC === 'number' ? cacheC : 0,
|
|
200
|
+
cacheCreation1hTokens: typeof cacheC1h === 'number' ? cacheC1h : 0,
|
|
201
|
+
};
|
|
202
|
+
// A transcript writes one line per content block of a message and
|
|
203
|
+
// repeats the message's usage on each (same rule as
|
|
204
|
+
// lib/epic/transcriptUsage.cjs): per message.id, the counted value of
|
|
205
|
+
// each field is the largest seen, so a repeat adds only the increase.
|
|
206
|
+
const msgId = obj.message?.id;
|
|
207
|
+
let add = vals;
|
|
208
|
+
if (typeof msgId === 'string' && msgId) {
|
|
209
|
+
const recent = acc.recentIds ?? (acc.recentIds = new Map());
|
|
210
|
+
const prevVals = recent.get(msgId);
|
|
211
|
+
if (prevVals) {
|
|
212
|
+
add = {};
|
|
213
|
+
const next = {};
|
|
214
|
+
for (const k of USAGE_FIELDS) {
|
|
215
|
+
const prevK = prevVals[k] || 0;
|
|
216
|
+
add[k] = Math.max(0, vals[k] - prevK);
|
|
217
|
+
next[k] = Math.max(vals[k], prevK);
|
|
218
|
+
}
|
|
219
|
+
recent.delete(msgId);
|
|
220
|
+
recent.set(msgId, next);
|
|
221
|
+
} else {
|
|
222
|
+
recent.set(msgId, { ...vals });
|
|
223
|
+
while (recent.size > RECENT_IDS_MAX) recent.delete(recent.keys().next().value);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
for (const k of USAGE_FIELDS) acc[k] = (acc[k] || 0) + add[k];
|
|
216
227
|
|
|
217
228
|
// Only assistant usage lines carry model+usage together in practice;
|
|
218
229
|
// read defensively rather than assuming every usage line has a model.
|
|
219
230
|
const modelId = obj.message?.model;
|
|
220
231
|
if (typeof modelId === 'string' && modelId) {
|
|
221
232
|
const bucket = acc.byModel[modelId] ?? (acc.byModel[modelId] = {
|
|
222
|
-
inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheCreationTokens: 0,
|
|
233
|
+
inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheCreationTokens: 0, cacheCreation1hTokens: 0,
|
|
223
234
|
});
|
|
224
|
-
|
|
225
|
-
if (typeof outT === 'number') bucket.outputTokens += outT;
|
|
226
|
-
if (typeof cacheR === 'number') bucket.cacheReadTokens += cacheR;
|
|
227
|
-
if (typeof cacheC === 'number') bucket.cacheCreationTokens += cacheC;
|
|
235
|
+
for (const k of USAGE_FIELDS) bucket[k] = (bucket[k] || 0) + add[k];
|
|
228
236
|
}
|
|
229
237
|
}
|
|
230
238
|
|
|
@@ -281,6 +289,7 @@ async function parseJSONL(filePath, stat) {
|
|
|
281
289
|
outputTokens: 0,
|
|
282
290
|
cacheReadTokens: 0,
|
|
283
291
|
cacheCreationTokens: 0,
|
|
292
|
+
cacheCreation1hTokens: 0,
|
|
284
293
|
toolCallCount: 0,
|
|
285
294
|
toolBreakdown: {},
|
|
286
295
|
byModel: {},
|
|
@@ -318,6 +327,8 @@ async function parseJSONL(filePath, stat) {
|
|
|
318
327
|
const readFrom = cached.readOffset ?? cached.size;
|
|
319
328
|
const tail = await readSlice(filePath, readFrom, stat.size);
|
|
320
329
|
const delta = emptyAcc();
|
|
330
|
+
// Copy, so a failed tail parse leaves the cached memory untouched.
|
|
331
|
+
delta.recentIds = new Map(cached.recentIds ?? []);
|
|
321
332
|
const { lastTs: deltaLastTs } = scanAggrLines(tail.split('\n'), delta, false);
|
|
322
333
|
const prev = cached.result;
|
|
323
334
|
const merged = {
|
|
@@ -326,6 +337,7 @@ async function parseJSONL(filePath, stat) {
|
|
|
326
337
|
outputTokens: prev.outputTokens + delta.outputTokens,
|
|
327
338
|
cacheReadTokens: prev.cacheReadTokens + delta.cacheReadTokens,
|
|
328
339
|
cacheCreationTokens: prev.cacheCreationTokens + delta.cacheCreationTokens,
|
|
340
|
+
cacheCreation1hTokens: (prev.cacheCreation1hTokens || 0) + delta.cacheCreation1hTokens,
|
|
329
341
|
toolCallCount: prev.toolCallCount + delta.toolCallCount,
|
|
330
342
|
toolBreakdown: { ...prev.toolBreakdown },
|
|
331
343
|
byModel: {},
|
|
@@ -343,19 +355,20 @@ async function parseJSONL(filePath, stat) {
|
|
|
343
355
|
}
|
|
344
356
|
for (const [modelId, deltaBucket] of Object.entries(delta.byModel)) {
|
|
345
357
|
const b = merged.byModel[modelId] ?? (merged.byModel[modelId] = {
|
|
346
|
-
inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheCreationTokens: 0,
|
|
358
|
+
inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheCreationTokens: 0, cacheCreation1hTokens: 0,
|
|
347
359
|
});
|
|
348
360
|
b.inputTokens += deltaBucket.inputTokens;
|
|
349
361
|
b.outputTokens += deltaBucket.outputTokens;
|
|
350
362
|
b.cacheReadTokens += deltaBucket.cacheReadTokens;
|
|
351
363
|
b.cacheCreationTokens += deltaBucket.cacheCreationTokens;
|
|
364
|
+
b.cacheCreation1hTokens = (b.cacheCreation1hTokens || 0) + (deltaBucket.cacheCreation1hTokens || 0);
|
|
352
365
|
}
|
|
353
366
|
// readOffset advances to the last complete newline so the next tail
|
|
354
367
|
// always starts at a line boundary. size stays at stat.size so the
|
|
355
368
|
// exact-hit check works correctly on the next call.
|
|
356
369
|
const lastNl = tail.lastIndexOf('\n');
|
|
357
370
|
const readOffset = lastNl >= 0 ? readFrom + lastNl + 1 : readFrom;
|
|
358
|
-
aggrCache.set(filePath, { mtimeMs: stat.mtimeMs, size: stat.size, readOffset, inode: stat.ino, result: merged });
|
|
371
|
+
aggrCache.set(filePath, { mtimeMs: stat.mtimeMs, size: stat.size, readOffset, inode: stat.ino, recentIds: delta.recentIds, result: merged });
|
|
359
372
|
return { result: merged, cacheHit: false };
|
|
360
373
|
} catch {
|
|
361
374
|
// fall through to full parse
|
|
@@ -373,6 +386,9 @@ async function parseJSONL(filePath, stat) {
|
|
|
373
386
|
|
|
374
387
|
const acc = emptyAcc();
|
|
375
388
|
const { firstTs, lastTs } = scanAggrLines(text.split('\n'), acc, true);
|
|
389
|
+
// The id memory lives on the cache entry, not in the returned result.
|
|
390
|
+
const recentIds = acc.recentIds ?? new Map();
|
|
391
|
+
delete acc.recentIds;
|
|
376
392
|
acc.firstEventTs = firstTs;
|
|
377
393
|
acc.lastEventTs = lastTs;
|
|
378
394
|
|
|
@@ -386,7 +402,7 @@ async function parseJSONL(filePath, stat) {
|
|
|
386
402
|
|
|
387
403
|
const lastNlFull = text.lastIndexOf('\n');
|
|
388
404
|
const readOffsetFull = lastNlFull >= 0 ? lastNlFull + 1 : 0;
|
|
389
|
-
aggrCache.set(filePath, { mtimeMs: stat.mtimeMs, size: stat.size, readOffset: readOffsetFull, inode: stat.ino, result: acc });
|
|
405
|
+
aggrCache.set(filePath, { mtimeMs: stat.mtimeMs, size: stat.size, readOffset: readOffsetFull, inode: stat.ino, recentIds, result: acc });
|
|
390
406
|
return { result: acc, cacheHit: false };
|
|
391
407
|
}
|
|
392
408
|
|
|
@@ -405,6 +421,7 @@ function emptyBucket(sessionDate, encodedCwd) {
|
|
|
405
421
|
outputTokens: 0,
|
|
406
422
|
cacheReadTokens: 0,
|
|
407
423
|
cacheCreationTokens: 0,
|
|
424
|
+
cacheCreation1hTokens: 0,
|
|
408
425
|
toolCallCount: 0,
|
|
409
426
|
toolBreakdown: {},
|
|
410
427
|
byModel: {},
|
|
@@ -421,18 +438,20 @@ function foldParsedIntoBucket(b, parsed) {
|
|
|
421
438
|
b.outputTokens += parsed.outputTokens;
|
|
422
439
|
b.cacheReadTokens += parsed.cacheReadTokens;
|
|
423
440
|
b.cacheCreationTokens += parsed.cacheCreationTokens;
|
|
441
|
+
b.cacheCreation1hTokens = (b.cacheCreation1hTokens || 0) + (parsed.cacheCreation1hTokens || 0);
|
|
424
442
|
b.toolCallCount += parsed.toolCallCount;
|
|
425
443
|
for (const [tool, cnt] of Object.entries(parsed.toolBreakdown)) {
|
|
426
444
|
b.toolBreakdown[tool] = (b.toolBreakdown[tool] ?? 0) + cnt;
|
|
427
445
|
}
|
|
428
446
|
for (const [modelId, srcBucket] of Object.entries(parsed.byModel ?? {})) {
|
|
429
447
|
const dst = b.byModel[modelId] ?? (b.byModel[modelId] = {
|
|
430
|
-
inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheCreationTokens: 0,
|
|
448
|
+
inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheCreationTokens: 0, cacheCreation1hTokens: 0,
|
|
431
449
|
});
|
|
432
450
|
dst.inputTokens += srcBucket.inputTokens;
|
|
433
451
|
dst.outputTokens += srcBucket.outputTokens;
|
|
434
452
|
dst.cacheReadTokens += srcBucket.cacheReadTokens;
|
|
435
453
|
dst.cacheCreationTokens += srcBucket.cacheCreationTokens;
|
|
454
|
+
dst.cacheCreation1hTokens = (dst.cacheCreation1hTokens || 0) + (srcBucket.cacheCreation1hTokens || 0);
|
|
436
455
|
}
|
|
437
456
|
b.sessionCount++;
|
|
438
457
|
b.errorCount += parsed.errorCount;
|
|
@@ -467,6 +486,7 @@ function bucketToRollupLines(b) {
|
|
|
467
486
|
outputTokens: mb.outputTokens,
|
|
468
487
|
cacheReadTokens: mb.cacheReadTokens,
|
|
469
488
|
cacheCreationTokens: mb.cacheCreationTokens,
|
|
489
|
+
cacheCreation1hTokens: mb.cacheCreation1hTokens || 0,
|
|
470
490
|
toolCallCount: 0,
|
|
471
491
|
toolBreakdown: {},
|
|
472
492
|
errorCount: 0,
|
|
@@ -516,11 +536,21 @@ function rollupMapToRows(map, finalizedDates) {
|
|
|
516
536
|
} else {
|
|
517
537
|
const dst = row.byModel[bucket.modelId] ?? (row.byModel[bucket.modelId] = {
|
|
518
538
|
inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheCreationTokens: 0,
|
|
539
|
+
cacheCreation1hTokens: 0, cacheCreationUnknownTokens: 0,
|
|
519
540
|
});
|
|
520
541
|
dst.inputTokens += bucket.inputTokens || 0;
|
|
521
542
|
dst.outputTokens += bucket.outputTokens || 0;
|
|
522
543
|
dst.cacheReadTokens += bucket.cacheReadTokens || 0;
|
|
523
544
|
dst.cacheCreationTokens += bucket.cacheCreationTokens || 0;
|
|
545
|
+
// A line written before v4 has no 1-hour split: its cache writes count
|
|
546
|
+
// as unknown (costOfUsage prices them at the 1-hour rate, estimated).
|
|
547
|
+
// Both parts are plain sums, so several lines in one bucket stay right.
|
|
548
|
+
if (typeof bucket.cacheCreation1hTokens === 'number') {
|
|
549
|
+
dst.cacheCreation1hTokens += bucket.cacheCreation1hTokens;
|
|
550
|
+
row.cacheCreation1hTokens += bucket.cacheCreation1hTokens;
|
|
551
|
+
} else {
|
|
552
|
+
dst.cacheCreationUnknownTokens += bucket.cacheCreationTokens || 0;
|
|
553
|
+
}
|
|
524
554
|
row.inputTokens += bucket.inputTokens || 0;
|
|
525
555
|
row.outputTokens += bucket.outputTokens || 0;
|
|
526
556
|
row.cacheReadTokens += bucket.cacheReadTokens || 0;
|
|
@@ -946,17 +976,13 @@ async function aggregate(req) {
|
|
|
946
976
|
const byModel = {};
|
|
947
977
|
let estimatedCostUsd = 0;
|
|
948
978
|
for (const [modelId, bucket] of Object.entries(b.byModel)) {
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
estimatedCostUsd += costUsd;
|
|
957
|
-
// What those cache-read tokens would have cost at the full input rate,
|
|
958
|
-
// minus what they actually cost at the cache rate.
|
|
959
|
-
cacheSavingsUsd += bucket.cacheReadTokens * (pricing.i - pricing.c) / 1e6;
|
|
979
|
+
// Priced by lib/claude/modelPricing.cjs: the exact model's current rate,
|
|
980
|
+
// cache writes split 5-minute / 1-hour; estimated when the model id or
|
|
981
|
+
// the write split is unknown.
|
|
982
|
+
const cost = costOfUsage(modelId, bucket);
|
|
983
|
+
byModel[modelId] = { ...bucket, costUsd: cost.costUsd, ...(cost.estimated ? { estimated: true } : {}) };
|
|
984
|
+
estimatedCostUsd += cost.costUsd;
|
|
985
|
+
cacheSavingsUsd += cost.cacheSavingsUsd;
|
|
960
986
|
}
|
|
961
987
|
return { ...b, byModel, estimatedCostUsd };
|
|
962
988
|
});
|
|
@@ -1023,7 +1049,6 @@ const remote = { aggregate };
|
|
|
1023
1049
|
module.exports = {
|
|
1024
1050
|
registerHistoryAggregatorHandlers,
|
|
1025
1051
|
remote,
|
|
1026
|
-
MODEL_PRICING,
|
|
1027
1052
|
finalizeClosedDays,
|
|
1028
1053
|
decodeCwd,
|
|
1029
1054
|
refreshIntradayToday,
|
|
@@ -1032,10 +1057,11 @@ module.exports = {
|
|
|
1032
1057
|
// exported for tests
|
|
1033
1058
|
scanAggrLines,
|
|
1034
1059
|
parseJSONL,
|
|
1035
|
-
resolvePricingKey,
|
|
1036
1060
|
CACHE_MAX,
|
|
1037
1061
|
LRUCache,
|
|
1038
1062
|
computeActiveMinutes,
|
|
1063
|
+
bucketToRollupLines,
|
|
1064
|
+
rollupMapToRows,
|
|
1039
1065
|
mapWithConcurrency,
|
|
1040
1066
|
resetIntradayRegistryForTests,
|
|
1041
1067
|
INTRADAY_STAT_CONCURRENCY,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* instantly regardless of transcript corpus size or retention/cleanup.
|
|
6
6
|
*
|
|
7
7
|
* Only imports historyRollup.cjs (the rollup reader) and pure helpers
|
|
8
|
-
* re-exported from historyAggregator.cjs (
|
|
8
|
+
* re-exported from historyAggregator.cjs (date math) plus lib/claude/modelPricing.cjs (cost) — never
|
|
9
9
|
* fs/promises, never PROJECTS_DIR. See historyDashboard.test.cjs's zero-scan
|
|
10
10
|
* guarantee test.
|
|
11
11
|
*/
|
|
@@ -14,12 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
const { ipcMain } = require('electron');
|
|
16
16
|
const historyRollup = require('./lib/historyRollup.cjs');
|
|
17
|
-
const {
|
|
18
|
-
|
|
19
|
-
resolvePricingKey,
|
|
20
|
-
localDate,
|
|
21
|
-
subtractDays,
|
|
22
|
-
} = require('./historyAggregator.cjs');
|
|
17
|
+
const { localDate, subtractDays } = require('./historyAggregator.cjs');
|
|
18
|
+
const { costOfUsage } = require('./lib/claude/modelPricing.cjs');
|
|
23
19
|
const { schemas } = require('./ipcSchemas.cjs');
|
|
24
20
|
|
|
25
21
|
// Read range start for rangeDays=0 ("all time"). Rollup dates are always
|
|
@@ -58,11 +54,21 @@ function foldBucketIntoRow(row, bucket) {
|
|
|
58
54
|
} else {
|
|
59
55
|
const dst = row.byModel[bucket.modelId] ?? (row.byModel[bucket.modelId] = {
|
|
60
56
|
inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheCreationTokens: 0,
|
|
57
|
+
cacheCreation1hTokens: 0, cacheCreationUnknownTokens: 0,
|
|
61
58
|
});
|
|
62
59
|
dst.inputTokens += bucket.inputTokens || 0;
|
|
63
60
|
dst.outputTokens += bucket.outputTokens || 0;
|
|
64
61
|
dst.cacheReadTokens += bucket.cacheReadTokens || 0;
|
|
65
62
|
dst.cacheCreationTokens += bucket.cacheCreationTokens || 0;
|
|
63
|
+
// A line written before rollup v4 has no 1-hour split: its cache writes
|
|
64
|
+
// count as unknown, which costOfUsage prices at the 1-hour rate and marks
|
|
65
|
+
// estimated. Both parts are plain sums, so a bucket mixing old and new
|
|
66
|
+
// lines (e.g. the previous-period row) stays right.
|
|
67
|
+
if (typeof bucket.cacheCreation1hTokens === 'number') {
|
|
68
|
+
dst.cacheCreation1hTokens += bucket.cacheCreation1hTokens;
|
|
69
|
+
} else {
|
|
70
|
+
dst.cacheCreationUnknownTokens += bucket.cacheCreationTokens || 0;
|
|
71
|
+
}
|
|
66
72
|
row.inputTokens += bucket.inputTokens || 0;
|
|
67
73
|
row.outputTokens += bucket.outputTokens || 0;
|
|
68
74
|
row.cacheReadTokens += bucket.cacheReadTokens || 0;
|
|
@@ -75,12 +81,7 @@ function computeRowCost(row) {
|
|
|
75
81
|
const byModel = {};
|
|
76
82
|
let estimatedCostUsd = 0;
|
|
77
83
|
for (const [modelId, bucket] of Object.entries(row.byModel)) {
|
|
78
|
-
const {
|
|
79
|
-
const pricing = MODEL_PRICING[key];
|
|
80
|
-
const costUsd =
|
|
81
|
-
(bucket.inputTokens + bucket.cacheCreationTokens) * pricing.i / 1e6 +
|
|
82
|
-
bucket.outputTokens * pricing.o / 1e6 +
|
|
83
|
-
bucket.cacheReadTokens * pricing.c / 1e6;
|
|
84
|
+
const { costUsd, estimated } = costOfUsage(modelId, bucket);
|
|
84
85
|
byModel[modelId] = { ...bucket, costUsd, ...(estimated ? { estimated: true } : {}) };
|
|
85
86
|
estimatedCostUsd += costUsd;
|
|
86
87
|
}
|
|
@@ -197,6 +198,9 @@ async function computeDashboard(req) {
|
|
|
197
198
|
addRowToTotals(prevTotals, computeRowCost(prevRow));
|
|
198
199
|
|
|
199
200
|
const provisionalDates = sortedDates.filter((d) => !finalizedDates.has(d));
|
|
201
|
+
// Days finalized under an older ROLLUP_VERSION that the finalize pass could
|
|
202
|
+
// not recount (transcripts gone) — their rows are still served as-is.
|
|
203
|
+
const legacyDates = historyRollup.legacyFinalizedDates(map).filter((d) => d >= from && d <= to);
|
|
200
204
|
|
|
201
205
|
return {
|
|
202
206
|
from,
|
|
@@ -209,6 +213,7 @@ async function computeDashboard(req) {
|
|
|
209
213
|
toolsByProject,
|
|
210
214
|
generatedAt: Date.now(),
|
|
211
215
|
provisionalDates,
|
|
216
|
+
legacyDates,
|
|
212
217
|
};
|
|
213
218
|
}
|
|
214
219
|
|
package/src/main/index.cjs
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// Dead-stdio guard — must be the first statement. After the launching terminal
|
|
2
|
+
// closes, writes to the inherited stdout/stderr fail EIO/EPIPE and would surface
|
|
3
|
+
// as one uncaughtException per console line. The notice goes to the file logger
|
|
4
|
+
// (required lazily: logs.cjs pulls in electron's app), never to the dead stream.
|
|
5
|
+
try { require('./lib/process/bootStdioGuard.cjs').installBootStdioGuard(); } catch { /* the guard must never stop boot */ }
|
|
1
6
|
// Boot diagnostic (SM_BOOT_DIAG=1, set by the packaged smoke): one stderr line that
|
|
2
7
|
// shows whether `electron` resolved to the built-in module or ran in node mode.
|
|
3
8
|
if (process.env.SM_BOOT_DIAG === '1') {
|
|
@@ -91,8 +96,21 @@ scheduler.registerAdminRoutes(adminHttp);
|
|
|
91
96
|
prdCreate.registerAdminRoute(adminHttp, scheduler.remote);
|
|
92
97
|
prdAdminRoutes.registerAdminRoute(adminHttp, scheduler.remote);
|
|
93
98
|
projectHomeAdminRoutes.registerAdminRoute(adminHttp);
|
|
94
|
-
macroAdminRoutes.registerAdminRoute(adminHttp, {
|
|
99
|
+
macroAdminRoutes.registerAdminRoute(adminHttp, {
|
|
100
|
+
onChanged: () => broadcastMacrosChanged(),
|
|
101
|
+
startExternalNewSession: chatRunner.startExternalNewSession,
|
|
102
|
+
isTabBusy: chatRunner.isTabBusy,
|
|
103
|
+
});
|
|
95
104
|
chatRunner.registerAdminRoute(adminHttp);
|
|
105
|
+
// Outside apps' "Needs you" items (lib/feedback-remote/needsYouStore.cjs); changes broadcast `needsYou:changed`.
|
|
106
|
+
function broadcastNeedsYouChanged() {
|
|
107
|
+
sendIfAlive(mainWindow, 'needsYou:changed', {});
|
|
108
|
+
}
|
|
109
|
+
require('./lib/feedback-remote/needsYouAdminRoutes.cjs').registerAdminRoute(adminHttp, {
|
|
110
|
+
onChanged: broadcastNeedsYouChanged,
|
|
111
|
+
});
|
|
112
|
+
// The Dashboard's side: list open items + record the owner's answer (same broadcast).
|
|
113
|
+
require('./lib/feedback-remote/needsYouIpc.cjs').registerNeedsYouIpc({ ipcMain, onChanged: broadcastNeedsYouChanged });
|
|
96
114
|
// Project-to-project feedback conduit — the app is the only process holding
|
|
97
115
|
// several projects' operations roots open, so it performs the cross-folder
|
|
98
116
|
// write (lib/feedback-remote/crossProjectFeedback.cjs).
|
|
@@ -101,6 +119,17 @@ crossProjectFeedback.registerAdminRoute(adminHttp);
|
|
|
101
119
|
// (lib/feedback-remote/crossProjectReply.cjs).
|
|
102
120
|
require('./lib/feedback-remote/crossProjectReply.cjs').registerAdminRoute(adminHttp);
|
|
103
121
|
require('./lib/feedback-remote/customerFeedbackAdminRoutes.cjs').registerAdminRoute(adminHttp);
|
|
122
|
+
// Cursor read over the audit log for outside scripts (read-only).
|
|
123
|
+
require('./lib/telemetry/eventsAdminRoutes.cjs').registerAdminRoute(adminHttp);
|
|
124
|
+
// Outside-facing Epic records for scripts/other projects (read-only).
|
|
125
|
+
require('./lib/epic/epicAdminRoutes.cjs').registerAdminRoute(adminHttp, {
|
|
126
|
+
isTabBusy: chatRunner.isTabBusy,
|
|
127
|
+
listJobs: () => scheduler.remote.listJobs(),
|
|
128
|
+
});
|
|
129
|
+
// Persona roster + per-project effective model/effort for outside apps (read-only).
|
|
130
|
+
require('./lib/persona-macro/agentAdminRoutes.cjs').registerAdminRoute(adminHttp);
|
|
131
|
+
// The scheduler tick turns Epic state changes into epic_state_changed audit rows.
|
|
132
|
+
require('./lib/epic/epicStateWatcher.cjs').configureEpicStateWatcher({ isTabBusy: chatRunner.isTabBusy });
|
|
104
133
|
const supervisor = require('./supervisor.cjs');
|
|
105
134
|
const watchers = require('./watchers.cjs');
|
|
106
135
|
const queueOps = require('./queueOps.cjs');
|
|
@@ -1105,8 +1134,8 @@ ipcMain.handle('epicDelegationStats:get', validated(schemas.epicDelegationStatsG
|
|
|
1105
1134
|
}));
|
|
1106
1135
|
// Renderer Epic lifecycle trace (PRD 940) — append-only, no read/list IPC.
|
|
1107
1136
|
// Kind allowlist enforced by schemas.auditLogAppend, not here.
|
|
1108
|
-
ipcMain.handle('auditLog:append', validated(schemas.auditLogAppend, async ({ kind, cwd, epicId, source }) => {
|
|
1109
|
-
appendAuditEvent(kind, { cwd, epicId, source });
|
|
1137
|
+
ipcMain.handle('auditLog:append', validated(schemas.auditLogAppend, async ({ kind, cwd, epicId, source, fromEpicId }) => {
|
|
1138
|
+
appendAuditEvent(kind, { cwd, epicId, source, ...(fromEpicId ? { fromEpicId } : {}) });
|
|
1110
1139
|
return { ok: true };
|
|
1111
1140
|
}));
|
|
1112
1141
|
git.register(ipcMain);
|
|
@@ -1339,12 +1368,9 @@ app.whenReady().then(async () => {
|
|
|
1339
1368
|
console.error(`[insideHome] SELF-CHECK FAILED: ${bootHomeSelfCheck.error}; sessions will not be able to spawn`);
|
|
1340
1369
|
}
|
|
1341
1370
|
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
} catch { /* telemetry must never break the existing handling below */ }
|
|
1346
|
-
logs.writeLine({ scope: 'main', level: 'error', message: 'uncaughtException', meta: { error: err?.message, stack: err?.stack } });
|
|
1347
|
-
});
|
|
1371
|
+
// A dead-stdio write error (EIO/EPIPE after the terminal closed) is reported
|
|
1372
|
+
// and logged at most once per process; every other error as before.
|
|
1373
|
+
process.on('uncaughtException', require('./lib/process/bootStdioGuard.cjs').createUncaughtExceptionHandler({ reportError: (p) => require('./lib/telemetry/telemetryClient.cjs').reportError(p), writeLine: (e) => logs.writeLine(e) }));
|
|
1348
1374
|
process.on('unhandledRejection', (reason) => {
|
|
1349
1375
|
const r = reason instanceof Error ? { error: reason.message, stack: reason.stack } : { reason: String(reason) };
|
|
1350
1376
|
try {
|