@use-aistack/cli 0.18.0 → 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 +223 -53
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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.
|
|
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
|
|
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";
|
|
@@ -22782,6 +22862,7 @@ function buildSyncBody(built, syncConfig, autoSync, trigger = "manual", measured
|
|
|
22782
22862
|
aggregateVersion: MEASURED_DAYS_V1,
|
|
22783
22863
|
utcOffsetMinutes: measuredDays.utcOffsetMinutes,
|
|
22784
22864
|
...measuredDays.partial ? { partial: true } : {},
|
|
22865
|
+
...measuredDays.partial && measuredDays.partialHarnesses ? { partialHarnesses: measuredDays.partialHarnesses } : {},
|
|
22785
22866
|
days: applyDayConsent(measuredDays.days, syncConfig)
|
|
22786
22867
|
}
|
|
22787
22868
|
} : base;
|
|
@@ -22794,7 +22875,7 @@ function buildSyncBody(built, syncConfig, autoSync, trigger = "manual", measured
|
|
|
22794
22875
|
}
|
|
22795
22876
|
|
|
22796
22877
|
// src/workflow/reducer.ts
|
|
22797
|
-
var WORKFLOW_AGGREGATE_VERSION =
|
|
22878
|
+
var WORKFLOW_AGGREGATE_VERSION = WORKFLOW_AGGREGATES_V5;
|
|
22798
22879
|
function createWorkflowLocalSources() {
|
|
22799
22880
|
return { projectWorkspaces: /* @__PURE__ */ new Set(), activeProjectDays: /* @__PURE__ */ new Map() };
|
|
22800
22881
|
}
|
|
@@ -22868,6 +22949,9 @@ function shellIncludes(arg, head) {
|
|
|
22868
22949
|
function sessionState() {
|
|
22869
22950
|
return {
|
|
22870
22951
|
compacted: false,
|
|
22952
|
+
compactionTs: [],
|
|
22953
|
+
toolResults: [],
|
|
22954
|
+
headless: false,
|
|
22871
22955
|
events: [],
|
|
22872
22956
|
responses: /* @__PURE__ */ new Map(),
|
|
22873
22957
|
nextAnonymousResponse: 0,
|
|
@@ -22880,6 +22964,12 @@ function sessionState() {
|
|
|
22880
22964
|
lastTs: void 0
|
|
22881
22965
|
};
|
|
22882
22966
|
}
|
|
22967
|
+
var emptyBand2 = () => ({
|
|
22968
|
+
calls: 0,
|
|
22969
|
+
cacheWrite: 0,
|
|
22970
|
+
cacheRead: 0,
|
|
22971
|
+
input: 0
|
|
22972
|
+
});
|
|
22883
22973
|
function dayState() {
|
|
22884
22974
|
return {
|
|
22885
22975
|
sessions: 0,
|
|
@@ -22939,7 +23029,13 @@ function dayState() {
|
|
|
22939
23029
|
sessionsCompacted: 0,
|
|
22940
23030
|
toolResults: /* @__PURE__ */ new Map(),
|
|
22941
23031
|
blocks: { thinking: 0, text: 0 },
|
|
22942
|
-
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()
|
|
22943
23039
|
},
|
|
22944
23040
|
hasEfficiency: false
|
|
22945
23041
|
};
|
|
@@ -22949,7 +23045,6 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
22949
23045
|
const eventCells = /* @__PURE__ */ new Map();
|
|
22950
23046
|
const webSearchesByDate = /* @__PURE__ */ new Map();
|
|
22951
23047
|
const compactionsByDate = /* @__PURE__ */ new Map();
|
|
22952
|
-
const toolResultsByDate = /* @__PURE__ */ new Map();
|
|
22953
23048
|
const eventDates = /* @__PURE__ */ new Set();
|
|
22954
23049
|
let finished;
|
|
22955
23050
|
const getSession3 = (key2) => {
|
|
@@ -22969,6 +23064,8 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
22969
23064
|
state.lastTs = state.lastTs === void 0 ? observation.tsMs : Math.max(state.lastTs, observation.tsMs);
|
|
22970
23065
|
state.parentSession ??= observation.parentSession;
|
|
22971
23066
|
state.sidechain ||= observation.sidechain === true;
|
|
23067
|
+
if (observation.type === "response" && observation.headless)
|
|
23068
|
+
state.headless = true;
|
|
22972
23069
|
const at = new Date(observation.tsMs);
|
|
22973
23070
|
const date = utcDateOf2(observation.tsMs);
|
|
22974
23071
|
if (observation.projectWorkspace) {
|
|
@@ -23026,7 +23123,8 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
23026
23123
|
thinking: finiteNonnegative(observation.blocks.thinking),
|
|
23027
23124
|
text: finiteNonnegative(observation.blocks.text)
|
|
23028
23125
|
}
|
|
23029
|
-
} : {}
|
|
23126
|
+
} : {},
|
|
23127
|
+
...finiteNonnegative(observation.cacheTtlSec) > 0 ? { cacheTtlSec: finiteNonnegative(observation.cacheTtlSec) } : {}
|
|
23030
23128
|
};
|
|
23031
23129
|
const existing = state.responses.get(responseId);
|
|
23032
23130
|
const magnitude = (value) => value.routingTokens ?? (value.thinkingTokens ?? 0) + (value.responseTokens ?? 0);
|
|
@@ -23037,21 +23135,14 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
23037
23135
|
const turnId = observation.turnId ?? `anonymous:${state.nextAnonymousTurn++}`;
|
|
23038
23136
|
state.turns.set(turnId, observation.questionBack);
|
|
23039
23137
|
} else if (observation.type === "toolResult") {
|
|
23040
|
-
|
|
23041
|
-
|
|
23042
|
-
|
|
23043
|
-
|
|
23044
|
-
|
|
23045
|
-
bytes: 0,
|
|
23046
|
-
buckets: /* @__PURE__ */ new Map()
|
|
23047
|
-
};
|
|
23048
|
-
row.results++;
|
|
23049
|
-
row.bytes += bytes;
|
|
23050
|
-
bump2(row.buckets, logBucketV2(bytes));
|
|
23051
|
-
byDate.set(name, row);
|
|
23052
|
-
toolResultsByDate.set(date, byDate);
|
|
23138
|
+
state.toolResults.push({
|
|
23139
|
+
tsMs: observation.tsMs,
|
|
23140
|
+
tool: toolResultName(observation.tool),
|
|
23141
|
+
bytes: finiteNonnegative(observation.bytes)
|
|
23142
|
+
});
|
|
23053
23143
|
} else {
|
|
23054
23144
|
state.compacted = true;
|
|
23145
|
+
state.compactionTs.push(observation.tsMs);
|
|
23055
23146
|
bump2(compactionsByDate, date);
|
|
23056
23147
|
}
|
|
23057
23148
|
},
|
|
@@ -23189,14 +23280,31 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
23189
23280
|
day.efficiency.blocks.thinking += response.blocks.thinking;
|
|
23190
23281
|
day.efficiency.blocks.text += response.blocks.text;
|
|
23191
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
|
+
}
|
|
23192
23295
|
if (calls.length > 0) {
|
|
23193
23296
|
day.hasEfficiency = true;
|
|
23194
23297
|
const eff = day.efficiency;
|
|
23195
23298
|
let peak = 0;
|
|
23299
|
+
let ttlSec = CACHE_TTL_SEC;
|
|
23300
|
+
const ttlAt = [];
|
|
23196
23301
|
calls.forEach((call, i) => {
|
|
23197
23302
|
const context = call.contextTokens ?? 0;
|
|
23198
23303
|
peak = Math.max(peak, context);
|
|
23199
23304
|
const previous = calls[i - 1];
|
|
23305
|
+
const ttlBefore = ttlSec;
|
|
23306
|
+
if (call.cacheTtlSec !== void 0) ttlSec = call.cacheTtlSec;
|
|
23307
|
+
ttlAt.push(ttlSec);
|
|
23200
23308
|
if (!previous) return;
|
|
23201
23309
|
const gapSec = (call.tsMs - previous.tsMs) / 1e3;
|
|
23202
23310
|
bump2(eff.callGaps, logBucket(gapSec));
|
|
@@ -23204,20 +23312,52 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
23204
23312
|
eff.callsAfterGap++;
|
|
23205
23313
|
eff.cacheWriteAfterGap += call.cacheWriteTokens ?? 0;
|
|
23206
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;
|
|
23207
23320
|
}
|
|
23208
23321
|
if ((call.cacheWriteTokens ?? 0) > 0 && (call.cacheReadTokens ?? 0) === 0) {
|
|
23209
23322
|
eff.orphanCacheWrites++;
|
|
23210
23323
|
eff.orphanCacheWriteTokens += call.cacheWriteTokens ?? 0;
|
|
23324
|
+
if (gapSec <= ttlBefore) {
|
|
23325
|
+
eff.warmOrphanCacheWrites++;
|
|
23326
|
+
eff.warmOrphanCacheWriteTokens += call.cacheWriteTokens ?? 0;
|
|
23327
|
+
}
|
|
23211
23328
|
}
|
|
23212
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
|
+
}
|
|
23213
23339
|
bump2(eff.sessionMaxContext, logBucketV2(peak));
|
|
23214
23340
|
bump2(eff.sessionCalls, logBucket(calls.length));
|
|
23215
|
-
if (
|
|
23341
|
+
if (state.headless) eff.headlessSessions++;
|
|
23342
|
+
else if (calls.length <= SHORT_SESSION_CALLS) {
|
|
23216
23343
|
eff.shortSessions++;
|
|
23217
23344
|
eff.shortSessionFirstCallTokens += calls[0]?.contextTokens ?? 0;
|
|
23218
23345
|
}
|
|
23219
23346
|
if (state.compacted) eff.sessionsCompacted++;
|
|
23220
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
|
+
}
|
|
23221
23361
|
}
|
|
23222
23362
|
}
|
|
23223
23363
|
for (const [date, compactions] of compactionsByDate) {
|
|
@@ -23225,22 +23365,6 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
23225
23365
|
day.hasContext = true;
|
|
23226
23366
|
day.context.compactions += compactions;
|
|
23227
23367
|
}
|
|
23228
|
-
for (const [date, rows] of toolResultsByDate) {
|
|
23229
|
-
const day = dayOf(date);
|
|
23230
|
-
day.hasEfficiency = true;
|
|
23231
|
-
for (const [tool, row] of rows) {
|
|
23232
|
-
const held = day.efficiency.toolResults.get(tool) ?? {
|
|
23233
|
-
results: 0,
|
|
23234
|
-
bytes: 0,
|
|
23235
|
-
buckets: /* @__PURE__ */ new Map()
|
|
23236
|
-
};
|
|
23237
|
-
held.results += row.results;
|
|
23238
|
-
held.bytes += row.bytes;
|
|
23239
|
-
for (const [bucket, results] of row.buckets)
|
|
23240
|
-
bump2(held.buckets, bucket, results);
|
|
23241
|
-
day.efficiency.toolResults.set(tool, held);
|
|
23242
|
-
}
|
|
23243
|
-
}
|
|
23244
23368
|
for (const date of eventDates) {
|
|
23245
23369
|
const day = dayOf(date);
|
|
23246
23370
|
for (const [key2, events] of eventCells.get(date) ?? []) {
|
|
@@ -23423,7 +23547,16 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
23423
23547
|
})).sort(
|
|
23424
23548
|
(a, b) => b.bytes - a.bytes || a.tool.localeCompare(b.tool)
|
|
23425
23549
|
),
|
|
23426
|
-
...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
|
+
})
|
|
23427
23560
|
}
|
|
23428
23561
|
} : {}
|
|
23429
23562
|
}))
|
|
@@ -23432,7 +23565,6 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
23432
23565
|
eventCells.clear();
|
|
23433
23566
|
webSearchesByDate.clear();
|
|
23434
23567
|
compactionsByDate.clear();
|
|
23435
|
-
toolResultsByDate.clear();
|
|
23436
23568
|
eventDates.clear();
|
|
23437
23569
|
return finished;
|
|
23438
23570
|
}
|
|
@@ -23575,6 +23707,9 @@ function ingestClaudeWorkflow(agg, rec, ctx, tsMs) {
|
|
|
23575
23707
|
inputTokens: counts2.input,
|
|
23576
23708
|
cacheReadTokens: counts2.cacheRead,
|
|
23577
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 } : {},
|
|
23578
23713
|
...first ? {
|
|
23579
23714
|
firstCall: {
|
|
23580
23715
|
harnessTokens: counts2.cacheRead,
|
|
@@ -23596,7 +23731,11 @@ function ingestClaudeWorkflow(agg, rec, ctx, tsMs) {
|
|
|
23596
23731
|
...counts2 ? { routingTokens: countsTotal(counts2) } : {},
|
|
23597
23732
|
...asStr(rec.effort) ?? asStr(msg.effort) ? { effort: asStr(rec.effort) ?? asStr(msg.effort) } : {},
|
|
23598
23733
|
...context ?? {},
|
|
23599
|
-
...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 } : {}
|
|
23600
23739
|
});
|
|
23601
23740
|
const tools = [];
|
|
23602
23741
|
for (const rawBlock of asArr(msg.content)) {
|
|
@@ -23853,8 +23992,7 @@ function ingestClaudeToolResults(agg, rec, ctx, tsMs) {
|
|
|
23853
23992
|
const block = asObj(rawBlock);
|
|
23854
23993
|
if (!block || asStr(block.type) !== "tool_result") continue;
|
|
23855
23994
|
const toolUseId = asStr(block.tool_use_id);
|
|
23856
|
-
const
|
|
23857
|
-
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);
|
|
23858
23996
|
agg.workflow.ingest({
|
|
23859
23997
|
type: "toolResult",
|
|
23860
23998
|
session,
|
|
@@ -23867,6 +24005,21 @@ function ingestClaudeToolResults(agg, rec, ctx, tsMs) {
|
|
|
23867
24005
|
});
|
|
23868
24006
|
}
|
|
23869
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
|
+
}
|
|
23870
24023
|
function ingestUser(agg, rec) {
|
|
23871
24024
|
const msg = asObj(rec.message);
|
|
23872
24025
|
if (!msg) return;
|
|
@@ -24079,12 +24232,16 @@ function genuineDelta(payload, state, tsMs) {
|
|
|
24079
24232
|
if (!last) return null;
|
|
24080
24233
|
const inputTotal = asNum(last.input_tokens);
|
|
24081
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
|
+
);
|
|
24082
24239
|
const counts2 = {
|
|
24083
|
-
input: inputTotal - cached,
|
|
24240
|
+
input: inputTotal - cached - written,
|
|
24084
24241
|
output: asNum(last.output_tokens),
|
|
24085
24242
|
cacheWrite5m: 0,
|
|
24086
24243
|
cacheWrite1h: 0,
|
|
24087
|
-
cacheWriteUnsplit:
|
|
24244
|
+
cacheWriteUnsplit: written,
|
|
24088
24245
|
cacheRead: cached
|
|
24089
24246
|
};
|
|
24090
24247
|
if (countsTotal(counts2) === 0) return null;
|
|
@@ -24155,6 +24312,13 @@ function noteActivity(agg, state, tsMs) {
|
|
|
24155
24312
|
if (state.cliVersion) agg.ccVersions.add(cleanName(state.cliVersion));
|
|
24156
24313
|
agg.projectDirs.add(state.cwd ?? "(unknown)");
|
|
24157
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
|
+
}
|
|
24158
24322
|
function ingestEvent(agg, payload, state, tsMs, firstCall) {
|
|
24159
24323
|
const delta = genuineDelta(payload, state, tsMs);
|
|
24160
24324
|
if (!delta) return;
|
|
@@ -24191,15 +24355,16 @@ function ingestEvent(agg, payload, state, tsMs, firstCall) {
|
|
|
24191
24355
|
// instructions and tool specs, cached by an earlier session) and
|
|
24192
24356
|
// the fresh part is the instructions: AGENTS.md, environment,
|
|
24193
24357
|
// skills and the first prompt. Same method as Claude Code (#358).
|
|
24194
|
-
contextTokens: counts2.input + counts2.cacheRead,
|
|
24358
|
+
contextTokens: counts2.input + counts2.cacheRead + counts2.cacheWriteUnsplit,
|
|
24195
24359
|
inputTokens: counts2.input,
|
|
24196
24360
|
cacheReadTokens: counts2.cacheRead,
|
|
24197
|
-
cacheWriteTokens:
|
|
24361
|
+
cacheWriteTokens: counts2.cacheWriteUnsplit,
|
|
24362
|
+
cacheTtlSec: codexCacheTtlSec(modelKey),
|
|
24198
24363
|
...contextWindow > 0 ? { contextWindow } : {},
|
|
24199
24364
|
...firstCall && !state.forked ? {
|
|
24200
24365
|
firstCall: {
|
|
24201
24366
|
harnessTokens: counts2.cacheRead,
|
|
24202
|
-
instructionsTokens: counts2.input
|
|
24367
|
+
instructionsTokens: counts2.input + counts2.cacheWriteUnsplit
|
|
24203
24368
|
}
|
|
24204
24369
|
} : {}
|
|
24205
24370
|
});
|
|
@@ -29627,7 +29792,7 @@ function buildWorkflowExtraction(harnessWorkflows, git, utcOffsetMinutes = machi
|
|
|
29627
29792
|
])
|
|
29628
29793
|
].sort();
|
|
29629
29794
|
return {
|
|
29630
|
-
aggregateVersion:
|
|
29795
|
+
aggregateVersion: WORKFLOW_AGGREGATES_V5,
|
|
29631
29796
|
utcOffsetMinutes,
|
|
29632
29797
|
days: dates.map((date) => {
|
|
29633
29798
|
const projects = projectDays.get(date)?.size;
|
|
@@ -29967,7 +30132,7 @@ var PHASE_ORDER = ["scout", "build", "verify", "handoff", "unknown"];
|
|
|
29967
30132
|
function workflowBlock(workflowDays, utcOffsetMinutes, host) {
|
|
29968
30133
|
const out = [];
|
|
29969
30134
|
const folded = foldWorkflowDays(workflowDays, {
|
|
29970
|
-
aggregateVersion:
|
|
30135
|
+
aggregateVersion: WORKFLOW_AGGREGATES_V5,
|
|
29971
30136
|
utcOffsetMinutes
|
|
29972
30137
|
});
|
|
29973
30138
|
const harnesses = folded?.harnesses ?? [];
|
|
@@ -29977,7 +30142,7 @@ function workflowBlock(workflowDays, utcOffsetMinutes, host) {
|
|
|
29977
30142
|
...new Set(withPlaybook.map((h) => h.phase?.ruleVersion ?? ""))
|
|
29978
30143
|
].filter(Boolean);
|
|
29979
30144
|
out.push(
|
|
29980
|
-
`workflow ${harnesses.length} harness${harnesses.length === 1 ? "" : "es"} \xB7 ${sessions} sessions \xB7 ${
|
|
30145
|
+
`workflow ${harnesses.length} harness${harnesses.length === 1 ? "" : "es"} \xB7 ${sessions} sessions \xB7 ${WORKFLOW_AGGREGATES_V5}`
|
|
29981
30146
|
);
|
|
29982
30147
|
const first = folded?.dates[0];
|
|
29983
30148
|
const last = folded?.dates.at(-1);
|
|
@@ -30367,6 +30532,7 @@ async function stageSync(deps) {
|
|
|
30367
30532
|
`historical harnesses (${retentionDays} days): ${historical.map((a) => a.name).join(", ") || "none"}`
|
|
30368
30533
|
);
|
|
30369
30534
|
let dayScansComplete = true;
|
|
30535
|
+
const partialHarnesses = /* @__PURE__ */ new Set();
|
|
30370
30536
|
const sessionDatesByHarness = /* @__PURE__ */ new Map();
|
|
30371
30537
|
for (const { adapter, recent } of readings) {
|
|
30372
30538
|
if (!recent) continue;
|
|
@@ -30388,8 +30554,10 @@ async function stageSync(deps) {
|
|
|
30388
30554
|
for (const { adapter, history } of readings) {
|
|
30389
30555
|
if (!history) continue;
|
|
30390
30556
|
const { aggregate, workflow: workflow2, workflowLocal, scanComplete, sessionDates } = history;
|
|
30391
|
-
if (scanComplete === false || history.stats.filesUnreadable > 0 || aggregate.parseErrors > 0)
|
|
30557
|
+
if (scanComplete === false || history.stats.filesUnreadable > 0 || aggregate.parseErrors > 0) {
|
|
30392
30558
|
dayScansComplete = false;
|
|
30559
|
+
partialHarnesses.add(adapter.name);
|
|
30560
|
+
}
|
|
30393
30561
|
if (adapter.name === "grok-build" || adapter.name === "cursor")
|
|
30394
30562
|
sessionDatesByHarness.set(adapter.name, sessionDates ?? /* @__PURE__ */ new Map());
|
|
30395
30563
|
workflowScans.push({ aggregate: workflow2, local: workflowLocal });
|
|
@@ -30441,8 +30609,10 @@ async function stageSync(deps) {
|
|
|
30441
30609
|
for (const date of dates) correctionDates.add(date);
|
|
30442
30610
|
for (const dates of Object.values(current))
|
|
30443
30611
|
for (const date of dates) correctionDates.add(date);
|
|
30444
|
-
if (Object.keys(previous).some((id) => !(id in current)))
|
|
30612
|
+
if (Object.keys(previous).some((id) => !(id in current))) {
|
|
30445
30613
|
dayScansComplete = false;
|
|
30614
|
+
partialHarnesses.add(harness);
|
|
30615
|
+
}
|
|
30446
30616
|
acknowledgements.push(() => saveGrokDateHints(scope, current));
|
|
30447
30617
|
}
|
|
30448
30618
|
if (acknowledgements.length && dayScansComplete)
|
|
@@ -30472,7 +30642,7 @@ async function stageSync(deps) {
|
|
|
30472
30642
|
deps.trigger,
|
|
30473
30643
|
historical.length > 0 ? {
|
|
30474
30644
|
aggregateVersion: MEASURED_DAYS_V1,
|
|
30475
|
-
...!dayScansComplete ? { partial: true } : {},
|
|
30645
|
+
...!dayScansComplete ? { partial: true, partialHarnesses: [...partialHarnesses].sort() } : {},
|
|
30476
30646
|
utcOffsetMinutes: workflow?.utcOffsetMinutes ?? machineUtcOffsetMinutes(),
|
|
30477
30647
|
days: days.send
|
|
30478
30648
|
} : void 0,
|