@use-aistack/cli 0.18.1 → 0.19.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/dist/index.js CHANGED
@@ -18906,7 +18906,7 @@ function apiEquivalentCost(modelKey, t, atMs) {
18906
18906
  }
18907
18907
 
18908
18908
  // src/version.ts
18909
- var CLI_VERSION = true ? "0.18.1" : "0.0.0-dev";
18909
+ var CLI_VERSION = true ? "0.19.0" : "0.0.0-dev";
18910
18910
 
18911
18911
  // src/api.ts
18912
18912
  var BASE_URL = process.env.AISTACK_URL || "https://aistack.to";
@@ -21172,7 +21172,7 @@ async function hasRecentFile(roots, matches, sinceMs, opts = {}) {
21172
21172
  }
21173
21173
 
21174
21174
  // ../workflow-rules/src/daily.ts
21175
- var WORKFLOW_AGGREGATES_V4 = "workflow-aggregates/v4";
21175
+ var WORKFLOW_AGGREGATES_V5 = "workflow-aggregates/v5";
21176
21176
  var LOG_BUCKETS_V1 = "log-buckets/v1";
21177
21177
  var LOG_BUCKETS_V2 = "log-buckets/v2";
21178
21178
  var EMPTY_PHASE_TOTALS = Object.freeze({
@@ -21183,6 +21183,7 @@ var EMPTY_PHASE_TOTALS = Object.freeze({
21183
21183
  unknown: 0
21184
21184
  });
21185
21185
  var CACHE_TTL_SEC = 300;
21186
+ var LONG_GAP_SEC = 3600;
21186
21187
  var SHORT_SESSION_CALLS = 2;
21187
21188
  var TOOL_RESULT_NAMES = [
21188
21189
  "Agent",
@@ -21204,6 +21205,7 @@ var TOOL_RESULT_NAMES = [
21204
21205
  "grep_command",
21205
21206
  "list_dir",
21206
21207
  "local_shell",
21208
+ "read",
21207
21209
  "read_file",
21208
21210
  "shell",
21209
21211
  "tool_search",
@@ -21222,6 +21224,32 @@ function toolResultName(tool) {
21222
21224
  if (tool.includes("__")) return "mcp";
21223
21225
  return "other";
21224
21226
  }
21227
+ var EFFORT_RAW_LEVELS = [
21228
+ "low",
21229
+ "medium",
21230
+ "high",
21231
+ "xhigh",
21232
+ "max",
21233
+ "other"
21234
+ ];
21235
+ function effortRawLevelOf(effort) {
21236
+ switch (effort.toLowerCase()) {
21237
+ case "low":
21238
+ case "minimal":
21239
+ return "low";
21240
+ case "medium":
21241
+ return "medium";
21242
+ case "high":
21243
+ return "high";
21244
+ case "xhigh":
21245
+ return "xhigh";
21246
+ case "max":
21247
+ case "ultra":
21248
+ return "max";
21249
+ default:
21250
+ return "other";
21251
+ }
21252
+ }
21225
21253
  var EFFORT_LEVELS = [
21226
21254
  "low",
21227
21255
  "medium",
@@ -21405,9 +21433,60 @@ function foldEfficiencyDays(days) {
21405
21433
  thinking: blocks.reduce((n, b) => n + b.thinking, 0),
21406
21434
  text: blocks.reduce((n, b) => n + b.text, 0)
21407
21435
  }
21408
- } : {}
21436
+ } : {},
21437
+ ...foldEfficiencyV5(days)
21409
21438
  };
21410
21439
  }
21440
+ var addBand = (into, from) => {
21441
+ into.calls += from.calls;
21442
+ into.cacheWrite += from.cacheWrite;
21443
+ into.cacheRead += from.cacheRead;
21444
+ into.input += from.input;
21445
+ };
21446
+ var emptyBand = () => ({
21447
+ calls: 0,
21448
+ cacheWrite: 0,
21449
+ cacheRead: 0,
21450
+ input: 0
21451
+ });
21452
+ function foldEfficiencyV5(days) {
21453
+ if (days.length === 0) return {};
21454
+ const every = (key2) => days.every((day) => day[key2] !== void 0);
21455
+ const sum = (pick) => days.reduce((total, day) => total + (pick(day) ?? 0), 0);
21456
+ const out = {};
21457
+ if (every("gapBands")) {
21458
+ const short = emptyBand();
21459
+ const long = emptyBand();
21460
+ for (const day of days) {
21461
+ if (!day.gapBands) continue;
21462
+ addBand(short, day.gapBands.short);
21463
+ addBand(long, day.gapBands.long);
21464
+ }
21465
+ out.gapBands = { short, long };
21466
+ }
21467
+ if (every("warmOrphanCacheWrites")) {
21468
+ out.warmOrphanCacheWrites = sum((d) => d.warmOrphanCacheWrites);
21469
+ out.warmOrphanCacheWriteTokens = sum((d) => d.warmOrphanCacheWriteTokens);
21470
+ }
21471
+ if (every("headlessSessions"))
21472
+ out.headlessSessions = sum((d) => d.headlessSessions);
21473
+ if (every("coldCompactions"))
21474
+ out.coldCompactions = sum((d) => d.coldCompactions);
21475
+ if (every("effortRaw")) {
21476
+ out.effortRaw = sumBy(
21477
+ days.flatMap((d) => d.effortRaw ?? []),
21478
+ (row) => row.level,
21479
+ (into, from) => {
21480
+ into.responses += from.responses;
21481
+ into.outputTokens += from.outputTokens;
21482
+ },
21483
+ (row) => ({ ...row })
21484
+ ).sort(
21485
+ (a, b) => EFFORT_RAW_LEVELS.indexOf(a.level) - EFFORT_RAW_LEVELS.indexOf(b.level)
21486
+ );
21487
+ }
21488
+ return out;
21489
+ }
21411
21490
  function foldLengths(rows) {
21412
21491
  return sumBy(
21413
21492
  rows,
@@ -21841,6 +21920,7 @@ var COMPONENT_RULES = [
21841
21920
  // ../workflow-rules/src/efficiency.ts
21842
21921
  var BIG_RESULT_BUCKET = logBucketV2(32768);
21843
21922
  var HIGH_CONTEXT_BUCKET = logBucketV2(131072);
21923
+ var LONG_GAP_BUCKET = logBucket(3600) + 1;
21844
21924
 
21845
21925
  // ../workflow-rules/src/metricRules.ts
21846
21926
  var METRIC_RULES_V2 = "metric-rules/v2";
@@ -22795,7 +22875,7 @@ function buildSyncBody(built, syncConfig, autoSync, trigger = "manual", measured
22795
22875
  }
22796
22876
 
22797
22877
  // src/workflow/reducer.ts
22798
- var WORKFLOW_AGGREGATE_VERSION = WORKFLOW_AGGREGATES_V4;
22878
+ var WORKFLOW_AGGREGATE_VERSION = WORKFLOW_AGGREGATES_V5;
22799
22879
  function createWorkflowLocalSources() {
22800
22880
  return { projectWorkspaces: /* @__PURE__ */ new Set(), activeProjectDays: /* @__PURE__ */ new Map() };
22801
22881
  }
@@ -22869,6 +22949,9 @@ function shellIncludes(arg, head) {
22869
22949
  function sessionState() {
22870
22950
  return {
22871
22951
  compacted: false,
22952
+ compactionTs: [],
22953
+ toolResults: [],
22954
+ headless: false,
22872
22955
  events: [],
22873
22956
  responses: /* @__PURE__ */ new Map(),
22874
22957
  nextAnonymousResponse: 0,
@@ -22881,6 +22964,12 @@ function sessionState() {
22881
22964
  lastTs: void 0
22882
22965
  };
22883
22966
  }
22967
+ var emptyBand2 = () => ({
22968
+ calls: 0,
22969
+ cacheWrite: 0,
22970
+ cacheRead: 0,
22971
+ input: 0
22972
+ });
22884
22973
  function dayState() {
22885
22974
  return {
22886
22975
  sessions: 0,
@@ -22940,7 +23029,13 @@ function dayState() {
22940
23029
  sessionsCompacted: 0,
22941
23030
  toolResults: /* @__PURE__ */ new Map(),
22942
23031
  blocks: { thinking: 0, text: 0 },
22943
- hasBlocks: false
23032
+ hasBlocks: false,
23033
+ gapBands: { short: emptyBand2(), long: emptyBand2() },
23034
+ warmOrphanCacheWrites: 0,
23035
+ warmOrphanCacheWriteTokens: 0,
23036
+ headlessSessions: 0,
23037
+ coldCompactions: 0,
23038
+ effortRaw: /* @__PURE__ */ new Map()
22944
23039
  },
22945
23040
  hasEfficiency: false
22946
23041
  };
@@ -22950,7 +23045,6 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
22950
23045
  const eventCells = /* @__PURE__ */ new Map();
22951
23046
  const webSearchesByDate = /* @__PURE__ */ new Map();
22952
23047
  const compactionsByDate = /* @__PURE__ */ new Map();
22953
- const toolResultsByDate = /* @__PURE__ */ new Map();
22954
23048
  const eventDates = /* @__PURE__ */ new Set();
22955
23049
  let finished;
22956
23050
  const getSession3 = (key2) => {
@@ -22970,6 +23064,8 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
22970
23064
  state.lastTs = state.lastTs === void 0 ? observation.tsMs : Math.max(state.lastTs, observation.tsMs);
22971
23065
  state.parentSession ??= observation.parentSession;
22972
23066
  state.sidechain ||= observation.sidechain === true;
23067
+ if (observation.type === "response" && observation.headless)
23068
+ state.headless = true;
22973
23069
  const at = new Date(observation.tsMs);
22974
23070
  const date = utcDateOf2(observation.tsMs);
22975
23071
  if (observation.projectWorkspace) {
@@ -23027,7 +23123,8 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
23027
23123
  thinking: finiteNonnegative(observation.blocks.thinking),
23028
23124
  text: finiteNonnegative(observation.blocks.text)
23029
23125
  }
23030
- } : {}
23126
+ } : {},
23127
+ ...finiteNonnegative(observation.cacheTtlSec) > 0 ? { cacheTtlSec: finiteNonnegative(observation.cacheTtlSec) } : {}
23031
23128
  };
23032
23129
  const existing = state.responses.get(responseId);
23033
23130
  const magnitude = (value) => value.routingTokens ?? (value.thinkingTokens ?? 0) + (value.responseTokens ?? 0);
@@ -23038,21 +23135,14 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
23038
23135
  const turnId = observation.turnId ?? `anonymous:${state.nextAnonymousTurn++}`;
23039
23136
  state.turns.set(turnId, observation.questionBack);
23040
23137
  } else if (observation.type === "toolResult") {
23041
- const bytes = finiteNonnegative(observation.bytes);
23042
- const byDate = toolResultsByDate.get(date) ?? /* @__PURE__ */ new Map();
23043
- const name = toolResultName(observation.tool);
23044
- const row = byDate.get(name) ?? {
23045
- results: 0,
23046
- bytes: 0,
23047
- buckets: /* @__PURE__ */ new Map()
23048
- };
23049
- row.results++;
23050
- row.bytes += bytes;
23051
- bump2(row.buckets, logBucketV2(bytes));
23052
- byDate.set(name, row);
23053
- toolResultsByDate.set(date, byDate);
23138
+ state.toolResults.push({
23139
+ tsMs: observation.tsMs,
23140
+ tool: toolResultName(observation.tool),
23141
+ bytes: finiteNonnegative(observation.bytes)
23142
+ });
23054
23143
  } else {
23055
23144
  state.compacted = true;
23145
+ state.compactionTs.push(observation.tsMs);
23056
23146
  bump2(compactionsByDate, date);
23057
23147
  }
23058
23148
  },
@@ -23190,14 +23280,31 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
23190
23280
  day.efficiency.blocks.thinking += response.blocks.thinking;
23191
23281
  day.efficiency.blocks.text += response.blocks.text;
23192
23282
  }
23283
+ for (const response of responses) {
23284
+ if (!response.effort) continue;
23285
+ day.hasEfficiency = true;
23286
+ const level = effortRawLevelOf(response.effort);
23287
+ const row = day.efficiency.effortRaw.get(level) ?? {
23288
+ responses: 0,
23289
+ outputTokens: 0
23290
+ };
23291
+ row.responses++;
23292
+ row.outputTokens += response.responseTokens ?? 0;
23293
+ day.efficiency.effortRaw.set(level, row);
23294
+ }
23193
23295
  if (calls.length > 0) {
23194
23296
  day.hasEfficiency = true;
23195
23297
  const eff = day.efficiency;
23196
23298
  let peak = 0;
23299
+ let ttlSec = CACHE_TTL_SEC;
23300
+ const ttlAt = [];
23197
23301
  calls.forEach((call, i) => {
23198
23302
  const context = call.contextTokens ?? 0;
23199
23303
  peak = Math.max(peak, context);
23200
23304
  const previous = calls[i - 1];
23305
+ const ttlBefore = ttlSec;
23306
+ if (call.cacheTtlSec !== void 0) ttlSec = call.cacheTtlSec;
23307
+ ttlAt.push(ttlSec);
23201
23308
  if (!previous) return;
23202
23309
  const gapSec = (call.tsMs - previous.tsMs) / 1e3;
23203
23310
  bump2(eff.callGaps, logBucket(gapSec));
@@ -23205,20 +23312,52 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
23205
23312
  eff.callsAfterGap++;
23206
23313
  eff.cacheWriteAfterGap += call.cacheWriteTokens ?? 0;
23207
23314
  eff.inputAfterGap += call.inputTokens ?? 0;
23315
+ const band = gapSec > LONG_GAP_SEC ? eff.gapBands.long : eff.gapBands.short;
23316
+ band.calls++;
23317
+ band.cacheWrite += call.cacheWriteTokens ?? 0;
23318
+ band.cacheRead += call.cacheReadTokens ?? 0;
23319
+ band.input += call.inputTokens ?? 0;
23208
23320
  }
23209
23321
  if ((call.cacheWriteTokens ?? 0) > 0 && (call.cacheReadTokens ?? 0) === 0) {
23210
23322
  eff.orphanCacheWrites++;
23211
23323
  eff.orphanCacheWriteTokens += call.cacheWriteTokens ?? 0;
23324
+ if (gapSec <= ttlBefore) {
23325
+ eff.warmOrphanCacheWrites++;
23326
+ eff.warmOrphanCacheWriteTokens += call.cacheWriteTokens ?? 0;
23327
+ }
23212
23328
  }
23213
23329
  });
23330
+ for (const ts of state.compactionTs) {
23331
+ let last = -1;
23332
+ for (let i = 0; i < calls.length; i++) {
23333
+ if ((calls[i]?.tsMs ?? Infinity) <= ts) last = i;
23334
+ }
23335
+ const before = calls[last];
23336
+ if (before && (ts - before.tsMs) / 1e3 > (ttlAt[last] ?? CACHE_TTL_SEC))
23337
+ eff.coldCompactions++;
23338
+ }
23214
23339
  bump2(eff.sessionMaxContext, logBucketV2(peak));
23215
23340
  bump2(eff.sessionCalls, logBucket(calls.length));
23216
- if (calls.length <= SHORT_SESSION_CALLS) {
23341
+ if (state.headless) eff.headlessSessions++;
23342
+ else if (calls.length <= SHORT_SESSION_CALLS) {
23217
23343
  eff.shortSessions++;
23218
23344
  eff.shortSessionFirstCallTokens += calls[0]?.contextTokens ?? 0;
23219
23345
  }
23220
23346
  if (state.compacted) eff.sessionsCompacted++;
23221
23347
  }
23348
+ for (const result of state.toolResults) {
23349
+ const resultDay = dayOf(utcDateOf2(result.tsMs));
23350
+ resultDay.hasEfficiency = true;
23351
+ const held = resultDay.efficiency.toolResults.get(result.tool) ?? {
23352
+ results: 0,
23353
+ bytes: 0,
23354
+ buckets: /* @__PURE__ */ new Map()
23355
+ };
23356
+ held.results++;
23357
+ held.bytes += result.bytes;
23358
+ bump2(held.buckets, logBucketV2(result.bytes));
23359
+ resultDay.efficiency.toolResults.set(result.tool, held);
23360
+ }
23222
23361
  }
23223
23362
  }
23224
23363
  for (const [date, compactions] of compactionsByDate) {
@@ -23226,22 +23365,6 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
23226
23365
  day.hasContext = true;
23227
23366
  day.context.compactions += compactions;
23228
23367
  }
23229
- for (const [date, rows] of toolResultsByDate) {
23230
- const day = dayOf(date);
23231
- day.hasEfficiency = true;
23232
- for (const [tool, row] of rows) {
23233
- const held = day.efficiency.toolResults.get(tool) ?? {
23234
- results: 0,
23235
- bytes: 0,
23236
- buckets: /* @__PURE__ */ new Map()
23237
- };
23238
- held.results += row.results;
23239
- held.bytes += row.bytes;
23240
- for (const [bucket, results] of row.buckets)
23241
- bump2(held.buckets, bucket, results);
23242
- day.efficiency.toolResults.set(tool, held);
23243
- }
23244
- }
23245
23368
  for (const date of eventDates) {
23246
23369
  const day = dayOf(date);
23247
23370
  for (const [key2, events] of eventCells.get(date) ?? []) {
@@ -23424,7 +23547,16 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
23424
23547
  })).sort(
23425
23548
  (a, b) => b.bytes - a.bytes || a.tool.localeCompare(b.tool)
23426
23549
  ),
23427
- ...day.efficiency.hasBlocks ? { blocks: day.efficiency.blocks } : {}
23550
+ ...day.efficiency.hasBlocks ? { blocks: day.efficiency.blocks } : {},
23551
+ gapBands: day.efficiency.gapBands,
23552
+ warmOrphanCacheWrites: day.efficiency.warmOrphanCacheWrites,
23553
+ warmOrphanCacheWriteTokens: day.efficiency.warmOrphanCacheWriteTokens,
23554
+ headlessSessions: day.efficiency.headlessSessions,
23555
+ coldCompactions: day.efficiency.coldCompactions,
23556
+ effortRaw: EFFORT_RAW_LEVELS.flatMap((level) => {
23557
+ const row = day.efficiency.effortRaw.get(level);
23558
+ return row ? [{ level, ...row }] : [];
23559
+ })
23428
23560
  }
23429
23561
  } : {}
23430
23562
  }))
@@ -23433,7 +23565,6 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
23433
23565
  eventCells.clear();
23434
23566
  webSearchesByDate.clear();
23435
23567
  compactionsByDate.clear();
23436
- toolResultsByDate.clear();
23437
23568
  eventDates.clear();
23438
23569
  return finished;
23439
23570
  }
@@ -23576,6 +23707,9 @@ function ingestClaudeWorkflow(agg, rec, ctx, tsMs) {
23576
23707
  inputTokens: counts2.input,
23577
23708
  cacheReadTokens: counts2.cacheRead,
23578
23709
  cacheWriteTokens: counts2.cacheWrite5m + counts2.cacheWrite1h + counts2.cacheWriteUnsplit,
23710
+ // The TTL this call wrote under (v5): a subscription within plan
23711
+ // usage writes the main conversation at one hour.
23712
+ ...counts2.cacheWrite1h > 0 ? { cacheTtlSec: 3600 } : counts2.cacheWrite5m > 0 ? { cacheTtlSec: 300 } : {},
23579
23713
  ...first ? {
23580
23714
  firstCall: {
23581
23715
  harnessTokens: counts2.cacheRead,
@@ -23597,7 +23731,11 @@ function ingestClaudeWorkflow(agg, rec, ctx, tsMs) {
23597
23731
  ...counts2 ? { routingTokens: countsTotal(counts2) } : {},
23598
23732
  ...asStr(rec.effort) ?? asStr(msg.effort) ? { effort: asStr(rec.effort) ?? asStr(msg.effort) } : {},
23599
23733
  ...context ?? {},
23600
- ...blocks.thinking + blocks.text > 0 && isApiCall(rec) ? { blocks } : {}
23734
+ ...blocks.thinking + blocks.text > 0 && isApiCall(rec) ? { blocks } : {},
23735
+ // A script started the session (v5). `claude -p` records carry
23736
+ // `entrypoint: "sdk-cli"` (seen in a local transcript on 2026-09-24);
23737
+ // the other SDK entrypoints share the `sdk-` prefix.
23738
+ ...asStr(rec.entrypoint)?.startsWith("sdk-") ? { headless: true } : {}
23601
23739
  });
23602
23740
  const tools = [];
23603
23741
  for (const rawBlock of asArr(msg.content)) {
@@ -23854,8 +23992,7 @@ function ingestClaudeToolResults(agg, rec, ctx, tsMs) {
23854
23992
  const block = asObj(rawBlock);
23855
23993
  if (!block || asStr(block.type) !== "tool_result") continue;
23856
23994
  const toolUseId = asStr(block.tool_use_id);
23857
- const content = block.content;
23858
- const bytes = typeof content === "string" ? Buffer.byteLength(content) : content === void 0 || content === null ? 0 : Buffer.byteLength(JSON.stringify(content));
23995
+ const bytes = toolResultBytes(block.content);
23859
23996
  agg.workflow.ingest({
23860
23997
  type: "toolResult",
23861
23998
  session,
@@ -23868,6 +24005,21 @@ function ingestClaudeToolResults(agg, rec, ctx, tsMs) {
23868
24005
  });
23869
24006
  }
23870
24007
  }
24008
+ function toolResultBytes(content) {
24009
+ if (typeof content === "string") return Buffer.byteLength(content);
24010
+ if (content === void 0 || content === null) return 0;
24011
+ if (!Array.isArray(content))
24012
+ return Buffer.byteLength(JSON.stringify(content));
24013
+ let bytes = 0;
24014
+ for (const rawBlock of content) {
24015
+ const block = asObj(rawBlock);
24016
+ if (block && asStr(block.type) === "image") continue;
24017
+ if (block && asStr(block.type) === "text" && typeof block.text === "string")
24018
+ bytes += Buffer.byteLength(block.text);
24019
+ else bytes += Buffer.byteLength(JSON.stringify(rawBlock));
24020
+ }
24021
+ return bytes;
24022
+ }
23871
24023
  function ingestUser(agg, rec) {
23872
24024
  const msg = asObj(rec.message);
23873
24025
  if (!msg) return;
@@ -24080,12 +24232,16 @@ function genuineDelta(payload, state, tsMs) {
24080
24232
  if (!last) return null;
24081
24233
  const inputTotal = asNum(last.input_tokens);
24082
24234
  const cached = Math.min(asNum(last.cached_input_tokens), inputTotal);
24235
+ const written = Math.min(
24236
+ asNum(last.cache_write_input_tokens),
24237
+ inputTotal - cached
24238
+ );
24083
24239
  const counts2 = {
24084
- input: inputTotal - cached,
24240
+ input: inputTotal - cached - written,
24085
24241
  output: asNum(last.output_tokens),
24086
24242
  cacheWrite5m: 0,
24087
24243
  cacheWrite1h: 0,
24088
- cacheWriteUnsplit: 0,
24244
+ cacheWriteUnsplit: written,
24089
24245
  cacheRead: cached
24090
24246
  };
24091
24247
  if (countsTotal(counts2) === 0) return null;
@@ -24156,6 +24312,13 @@ function noteActivity(agg, state, tsMs) {
24156
24312
  if (state.cliVersion) agg.ccVersions.add(cleanName(state.cliVersion));
24157
24313
  agg.projectDirs.add(state.cwd ?? "(unknown)");
24158
24314
  }
24315
+ function codexCacheTtlSec(model) {
24316
+ const match = /gpt-(\d+)\.(\d+)/.exec(model);
24317
+ if (!match) return 300;
24318
+ const major = Number(match[1]);
24319
+ const minor = Number(match[2]);
24320
+ return major > 5 || major === 5 && minor >= 6 ? 1800 : 300;
24321
+ }
24159
24322
  function ingestEvent(agg, payload, state, tsMs, firstCall) {
24160
24323
  const delta = genuineDelta(payload, state, tsMs);
24161
24324
  if (!delta) return;
@@ -24192,15 +24355,16 @@ function ingestEvent(agg, payload, state, tsMs, firstCall) {
24192
24355
  // instructions and tool specs, cached by an earlier session) and
24193
24356
  // the fresh part is the instructions: AGENTS.md, environment,
24194
24357
  // skills and the first prompt. Same method as Claude Code (#358).
24195
- contextTokens: counts2.input + counts2.cacheRead,
24358
+ contextTokens: counts2.input + counts2.cacheRead + counts2.cacheWriteUnsplit,
24196
24359
  inputTokens: counts2.input,
24197
24360
  cacheReadTokens: counts2.cacheRead,
24198
- cacheWriteTokens: 0,
24361
+ cacheWriteTokens: counts2.cacheWriteUnsplit,
24362
+ cacheTtlSec: codexCacheTtlSec(modelKey),
24199
24363
  ...contextWindow > 0 ? { contextWindow } : {},
24200
24364
  ...firstCall && !state.forked ? {
24201
24365
  firstCall: {
24202
24366
  harnessTokens: counts2.cacheRead,
24203
- instructionsTokens: counts2.input
24367
+ instructionsTokens: counts2.input + counts2.cacheWriteUnsplit
24204
24368
  }
24205
24369
  } : {}
24206
24370
  });
@@ -29628,7 +29792,7 @@ function buildWorkflowExtraction(harnessWorkflows, git, utcOffsetMinutes = machi
29628
29792
  ])
29629
29793
  ].sort();
29630
29794
  return {
29631
- aggregateVersion: WORKFLOW_AGGREGATES_V4,
29795
+ aggregateVersion: WORKFLOW_AGGREGATES_V5,
29632
29796
  utcOffsetMinutes,
29633
29797
  days: dates.map((date) => {
29634
29798
  const projects = projectDays.get(date)?.size;
@@ -29968,7 +30132,7 @@ var PHASE_ORDER = ["scout", "build", "verify", "handoff", "unknown"];
29968
30132
  function workflowBlock(workflowDays, utcOffsetMinutes, host) {
29969
30133
  const out = [];
29970
30134
  const folded = foldWorkflowDays(workflowDays, {
29971
- aggregateVersion: WORKFLOW_AGGREGATES_V4,
30135
+ aggregateVersion: WORKFLOW_AGGREGATES_V5,
29972
30136
  utcOffsetMinutes
29973
30137
  });
29974
30138
  const harnesses = folded?.harnesses ?? [];
@@ -29978,7 +30142,7 @@ function workflowBlock(workflowDays, utcOffsetMinutes, host) {
29978
30142
  ...new Set(withPlaybook.map((h) => h.phase?.ruleVersion ?? ""))
29979
30143
  ].filter(Boolean);
29980
30144
  out.push(
29981
- `workflow ${harnesses.length} harness${harnesses.length === 1 ? "" : "es"} \xB7 ${sessions} sessions \xB7 ${WORKFLOW_AGGREGATES_V4}`
30145
+ `workflow ${harnesses.length} harness${harnesses.length === 1 ? "" : "es"} \xB7 ${sessions} sessions \xB7 ${WORKFLOW_AGGREGATES_V5}`
29982
30146
  );
29983
30147
  const first = folded?.dates[0];
29984
30148
  const last = folded?.dates.at(-1);