@use-aistack/cli 0.16.11 → 0.17.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 +331 -13
- 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.17.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_V4 = "workflow-aggregates/v4";
|
|
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({
|
|
@@ -21182,6 +21182,46 @@ var EMPTY_PHASE_TOTALS = Object.freeze({
|
|
|
21182
21182
|
handoff: 0,
|
|
21183
21183
|
unknown: 0
|
|
21184
21184
|
});
|
|
21185
|
+
var CACHE_TTL_SEC = 300;
|
|
21186
|
+
var SHORT_SESSION_CALLS = 2;
|
|
21187
|
+
var TOOL_RESULT_NAMES = [
|
|
21188
|
+
"Agent",
|
|
21189
|
+
"Bash",
|
|
21190
|
+
"Edit",
|
|
21191
|
+
"Glob",
|
|
21192
|
+
"Grep",
|
|
21193
|
+
"MultiEdit",
|
|
21194
|
+
"NotebookEdit",
|
|
21195
|
+
"NotebookRead",
|
|
21196
|
+
"Read",
|
|
21197
|
+
"Skill",
|
|
21198
|
+
"ToolSearch",
|
|
21199
|
+
"WebFetch",
|
|
21200
|
+
"WebSearch",
|
|
21201
|
+
"Write",
|
|
21202
|
+
"apply_patch",
|
|
21203
|
+
"exec_command",
|
|
21204
|
+
"grep_command",
|
|
21205
|
+
"list_dir",
|
|
21206
|
+
"local_shell",
|
|
21207
|
+
"read_file",
|
|
21208
|
+
"shell",
|
|
21209
|
+
"tool_search",
|
|
21210
|
+
"unified_exec",
|
|
21211
|
+
"view_image",
|
|
21212
|
+
"web_search",
|
|
21213
|
+
"write_stdin",
|
|
21214
|
+
"mcp",
|
|
21215
|
+
"other"
|
|
21216
|
+
];
|
|
21217
|
+
function toolResultName(tool) {
|
|
21218
|
+
if (!tool) return "other";
|
|
21219
|
+
if (tool.startsWith("mcp__")) return "mcp";
|
|
21220
|
+
if (tool === "Task") return "Agent";
|
|
21221
|
+
if (TOOL_RESULT_NAMES.includes(tool)) return tool;
|
|
21222
|
+
if (tool.includes("__")) return "mcp";
|
|
21223
|
+
return "other";
|
|
21224
|
+
}
|
|
21185
21225
|
var EFFORT_LEVELS = [
|
|
21186
21226
|
"low",
|
|
21187
21227
|
"medium",
|
|
@@ -21320,6 +21360,54 @@ function foldContextDays(days) {
|
|
|
21320
21360
|
...window === void 0 ? {} : { window }
|
|
21321
21361
|
};
|
|
21322
21362
|
}
|
|
21363
|
+
function foldEfficiencyDays(days) {
|
|
21364
|
+
const versions = (values) => [...new Set(values)].sort().join(" \xB7 ");
|
|
21365
|
+
const sum = (pick) => days.reduce((total, day) => total + pick(day), 0);
|
|
21366
|
+
const blocks = days.flatMap((day) => day.blocks ? [day.blocks] : []);
|
|
21367
|
+
return {
|
|
21368
|
+
countBucketRuleVersion: versions(days.map((d) => d.countBucketRuleVersion)),
|
|
21369
|
+
sizeBucketRuleVersion: versions(days.map((d) => d.sizeBucketRuleVersion)),
|
|
21370
|
+
callGaps: foldCountBuckets(
|
|
21371
|
+
days.flatMap((d) => d.callGaps),
|
|
21372
|
+
"calls"
|
|
21373
|
+
),
|
|
21374
|
+
callsAfterGap: sum((d) => d.callsAfterGap),
|
|
21375
|
+
cacheWriteAfterGap: sum((d) => d.cacheWriteAfterGap),
|
|
21376
|
+
inputAfterGap: sum((d) => d.inputAfterGap),
|
|
21377
|
+
orphanCacheWrites: sum((d) => d.orphanCacheWrites),
|
|
21378
|
+
orphanCacheWriteTokens: sum((d) => d.orphanCacheWriteTokens),
|
|
21379
|
+
sessionMaxContext: foldCountBuckets(
|
|
21380
|
+
days.flatMap((d) => d.sessionMaxContext),
|
|
21381
|
+
"sessions"
|
|
21382
|
+
),
|
|
21383
|
+
sessionCalls: foldCountBuckets(
|
|
21384
|
+
days.flatMap((d) => d.sessionCalls),
|
|
21385
|
+
"sessions"
|
|
21386
|
+
),
|
|
21387
|
+
shortSessions: sum((d) => d.shortSessions),
|
|
21388
|
+
shortSessionFirstCallTokens: sum((d) => d.shortSessionFirstCallTokens),
|
|
21389
|
+
sessionsCompacted: sum((d) => d.sessionsCompacted),
|
|
21390
|
+
toolResults: sumBy(
|
|
21391
|
+
days.flatMap((d) => d.toolResults),
|
|
21392
|
+
(row) => row.tool,
|
|
21393
|
+
(into, from) => {
|
|
21394
|
+
into.results += from.results;
|
|
21395
|
+
into.bytes += from.bytes;
|
|
21396
|
+
into.buckets = foldCountBuckets(
|
|
21397
|
+
[...into.buckets, ...from.buckets],
|
|
21398
|
+
"results"
|
|
21399
|
+
);
|
|
21400
|
+
},
|
|
21401
|
+
(row) => ({ ...row, buckets: [...row.buckets] })
|
|
21402
|
+
).sort((a, b) => b.bytes - a.bytes || a.tool.localeCompare(b.tool)),
|
|
21403
|
+
...blocks.length > 0 ? {
|
|
21404
|
+
blocks: {
|
|
21405
|
+
thinking: blocks.reduce((n, b) => n + b.thinking, 0),
|
|
21406
|
+
text: blocks.reduce((n, b) => n + b.text, 0)
|
|
21407
|
+
}
|
|
21408
|
+
} : {}
|
|
21409
|
+
};
|
|
21410
|
+
}
|
|
21323
21411
|
function foldLengths(rows) {
|
|
21324
21412
|
return sumBy(
|
|
21325
21413
|
rows,
|
|
@@ -21458,6 +21546,11 @@ function foldHarnessDays(days) {
|
|
|
21458
21546
|
}
|
|
21459
21547
|
const contexts = days.flatMap((day) => day.context ? [day.context] : []);
|
|
21460
21548
|
if (contexts.length > 0) out.context = foldContextDays(contexts);
|
|
21549
|
+
const efficiencies = days.flatMap(
|
|
21550
|
+
(day) => day.efficiency ? [day.efficiency] : []
|
|
21551
|
+
);
|
|
21552
|
+
if (efficiencies.length > 0)
|
|
21553
|
+
out.efficiency = foldEfficiencyDays(efficiencies);
|
|
21461
21554
|
return out;
|
|
21462
21555
|
}
|
|
21463
21556
|
var MAX_CHANGED_LINES_PER_COMMIT = 4096;
|
|
@@ -21745,6 +21838,10 @@ var COMPONENT_RULES = [
|
|
|
21745
21838
|
}
|
|
21746
21839
|
];
|
|
21747
21840
|
|
|
21841
|
+
// ../workflow-rules/src/efficiency.ts
|
|
21842
|
+
var BIG_RESULT_BUCKET = logBucketV2(32768);
|
|
21843
|
+
var HIGH_CONTEXT_BUCKET = logBucketV2(131072);
|
|
21844
|
+
|
|
21748
21845
|
// ../workflow-rules/src/metricRules.ts
|
|
21749
21846
|
var METRIC_RULES_V2 = "metric-rules/v2";
|
|
21750
21847
|
var METRIC_RULES = [
|
|
@@ -22697,7 +22794,7 @@ function buildSyncBody(built, syncConfig, autoSync, trigger = "manual", measured
|
|
|
22697
22794
|
}
|
|
22698
22795
|
|
|
22699
22796
|
// src/workflow/reducer.ts
|
|
22700
|
-
var WORKFLOW_AGGREGATE_VERSION =
|
|
22797
|
+
var WORKFLOW_AGGREGATE_VERSION = WORKFLOW_AGGREGATES_V4;
|
|
22701
22798
|
function createWorkflowLocalSources() {
|
|
22702
22799
|
return { projectWorkspaces: /* @__PURE__ */ new Set(), activeProjectDays: /* @__PURE__ */ new Map() };
|
|
22703
22800
|
}
|
|
@@ -22770,6 +22867,7 @@ function shellIncludes(arg, head) {
|
|
|
22770
22867
|
}
|
|
22771
22868
|
function sessionState() {
|
|
22772
22869
|
return {
|
|
22870
|
+
compacted: false,
|
|
22773
22871
|
events: [],
|
|
22774
22872
|
responses: /* @__PURE__ */ new Map(),
|
|
22775
22873
|
nextAnonymousResponse: 0,
|
|
@@ -22826,7 +22924,24 @@ function dayState() {
|
|
|
22826
22924
|
compactions: 0,
|
|
22827
22925
|
window: void 0
|
|
22828
22926
|
},
|
|
22829
|
-
hasContext: false
|
|
22927
|
+
hasContext: false,
|
|
22928
|
+
efficiency: {
|
|
22929
|
+
callGaps: /* @__PURE__ */ new Map(),
|
|
22930
|
+
callsAfterGap: 0,
|
|
22931
|
+
cacheWriteAfterGap: 0,
|
|
22932
|
+
inputAfterGap: 0,
|
|
22933
|
+
orphanCacheWrites: 0,
|
|
22934
|
+
orphanCacheWriteTokens: 0,
|
|
22935
|
+
sessionMaxContext: /* @__PURE__ */ new Map(),
|
|
22936
|
+
sessionCalls: /* @__PURE__ */ new Map(),
|
|
22937
|
+
shortSessions: 0,
|
|
22938
|
+
shortSessionFirstCallTokens: 0,
|
|
22939
|
+
sessionsCompacted: 0,
|
|
22940
|
+
toolResults: /* @__PURE__ */ new Map(),
|
|
22941
|
+
blocks: { thinking: 0, text: 0 },
|
|
22942
|
+
hasBlocks: false
|
|
22943
|
+
},
|
|
22944
|
+
hasEfficiency: false
|
|
22830
22945
|
};
|
|
22831
22946
|
}
|
|
22832
22947
|
function createHarnessWorkflowReducer(harness, localSources = createWorkflowLocalSources()) {
|
|
@@ -22834,6 +22949,7 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
22834
22949
|
const eventCells = /* @__PURE__ */ new Map();
|
|
22835
22950
|
const webSearchesByDate = /* @__PURE__ */ new Map();
|
|
22836
22951
|
const compactionsByDate = /* @__PURE__ */ new Map();
|
|
22952
|
+
const toolResultsByDate = /* @__PURE__ */ new Map();
|
|
22837
22953
|
const eventDates = /* @__PURE__ */ new Set();
|
|
22838
22954
|
let finished;
|
|
22839
22955
|
const getSession3 = (key2) => {
|
|
@@ -22895,6 +23011,21 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
22895
23011
|
observation.firstCall.instructionsTokens
|
|
22896
23012
|
)
|
|
22897
23013
|
}
|
|
23014
|
+
} : {},
|
|
23015
|
+
...observation.inputTokens !== void 0 ? { inputTokens: finiteNonnegative(observation.inputTokens) } : {},
|
|
23016
|
+
...observation.cacheReadTokens !== void 0 ? {
|
|
23017
|
+
cacheReadTokens: finiteNonnegative(observation.cacheReadTokens)
|
|
23018
|
+
} : {},
|
|
23019
|
+
...observation.cacheWriteTokens !== void 0 ? {
|
|
23020
|
+
cacheWriteTokens: finiteNonnegative(
|
|
23021
|
+
observation.cacheWriteTokens
|
|
23022
|
+
)
|
|
23023
|
+
} : {},
|
|
23024
|
+
...observation.blocks ? {
|
|
23025
|
+
blocks: {
|
|
23026
|
+
thinking: finiteNonnegative(observation.blocks.thinking),
|
|
23027
|
+
text: finiteNonnegative(observation.blocks.text)
|
|
23028
|
+
}
|
|
22898
23029
|
} : {}
|
|
22899
23030
|
};
|
|
22900
23031
|
const existing = state.responses.get(responseId);
|
|
@@ -22905,7 +23036,22 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
22905
23036
|
} else if (observation.type === "turn") {
|
|
22906
23037
|
const turnId = observation.turnId ?? `anonymous:${state.nextAnonymousTurn++}`;
|
|
22907
23038
|
state.turns.set(turnId, observation.questionBack);
|
|
23039
|
+
} else if (observation.type === "toolResult") {
|
|
23040
|
+
const bytes = finiteNonnegative(observation.bytes);
|
|
23041
|
+
const byDate = toolResultsByDate.get(date) ?? /* @__PURE__ */ new Map();
|
|
23042
|
+
const name = toolResultName(observation.tool);
|
|
23043
|
+
const row = byDate.get(name) ?? {
|
|
23044
|
+
results: 0,
|
|
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);
|
|
22908
23053
|
} else {
|
|
23054
|
+
state.compacted = true;
|
|
22909
23055
|
bump2(compactionsByDate, date);
|
|
22910
23056
|
}
|
|
22911
23057
|
},
|
|
@@ -23034,12 +23180,67 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
23034
23180
|
context.firstCallCount++;
|
|
23035
23181
|
}
|
|
23036
23182
|
}
|
|
23183
|
+
if (routing === "main") {
|
|
23184
|
+
const calls = responses.filter((response) => response.contextTokens !== void 0).sort((a, b) => a.tsMs - b.tsMs);
|
|
23185
|
+
for (const response of responses) {
|
|
23186
|
+
if (!response.blocks) continue;
|
|
23187
|
+
day.hasEfficiency = true;
|
|
23188
|
+
day.efficiency.hasBlocks = true;
|
|
23189
|
+
day.efficiency.blocks.thinking += response.blocks.thinking;
|
|
23190
|
+
day.efficiency.blocks.text += response.blocks.text;
|
|
23191
|
+
}
|
|
23192
|
+
if (calls.length > 0) {
|
|
23193
|
+
day.hasEfficiency = true;
|
|
23194
|
+
const eff = day.efficiency;
|
|
23195
|
+
let peak = 0;
|
|
23196
|
+
calls.forEach((call, i) => {
|
|
23197
|
+
const context = call.contextTokens ?? 0;
|
|
23198
|
+
peak = Math.max(peak, context);
|
|
23199
|
+
const previous = calls[i - 1];
|
|
23200
|
+
if (!previous) return;
|
|
23201
|
+
const gapSec = (call.tsMs - previous.tsMs) / 1e3;
|
|
23202
|
+
bump2(eff.callGaps, logBucket(gapSec));
|
|
23203
|
+
if (gapSec > CACHE_TTL_SEC) {
|
|
23204
|
+
eff.callsAfterGap++;
|
|
23205
|
+
eff.cacheWriteAfterGap += call.cacheWriteTokens ?? 0;
|
|
23206
|
+
eff.inputAfterGap += call.inputTokens ?? 0;
|
|
23207
|
+
}
|
|
23208
|
+
if ((call.cacheWriteTokens ?? 0) > 0 && (call.cacheReadTokens ?? 0) === 0) {
|
|
23209
|
+
eff.orphanCacheWrites++;
|
|
23210
|
+
eff.orphanCacheWriteTokens += call.cacheWriteTokens ?? 0;
|
|
23211
|
+
}
|
|
23212
|
+
});
|
|
23213
|
+
bump2(eff.sessionMaxContext, logBucketV2(peak));
|
|
23214
|
+
bump2(eff.sessionCalls, logBucket(calls.length));
|
|
23215
|
+
if (calls.length <= SHORT_SESSION_CALLS) {
|
|
23216
|
+
eff.shortSessions++;
|
|
23217
|
+
eff.shortSessionFirstCallTokens += calls[0]?.contextTokens ?? 0;
|
|
23218
|
+
}
|
|
23219
|
+
if (state.compacted) eff.sessionsCompacted++;
|
|
23220
|
+
}
|
|
23221
|
+
}
|
|
23037
23222
|
}
|
|
23038
23223
|
for (const [date, compactions] of compactionsByDate) {
|
|
23039
23224
|
const day = dayOf(date);
|
|
23040
23225
|
day.hasContext = true;
|
|
23041
23226
|
day.context.compactions += compactions;
|
|
23042
23227
|
}
|
|
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
|
+
}
|
|
23043
23244
|
for (const date of eventDates) {
|
|
23044
23245
|
const day = dayOf(date);
|
|
23045
23246
|
for (const [key2, events] of eventCells.get(date) ?? []) {
|
|
@@ -23192,6 +23393,38 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
23192
23393
|
compactions: day.context.compactions,
|
|
23193
23394
|
...day.context.window ? { window: day.context.window.window } : {}
|
|
23194
23395
|
}
|
|
23396
|
+
} : {},
|
|
23397
|
+
...day.hasEfficiency ? {
|
|
23398
|
+
efficiency: {
|
|
23399
|
+
countBucketRuleVersion: LOG_BUCKETS_V1,
|
|
23400
|
+
sizeBucketRuleVersion: LOG_BUCKETS_V2,
|
|
23401
|
+
callGaps: asBuckets(day.efficiency.callGaps, "calls"),
|
|
23402
|
+
callsAfterGap: day.efficiency.callsAfterGap,
|
|
23403
|
+
cacheWriteAfterGap: day.efficiency.cacheWriteAfterGap,
|
|
23404
|
+
inputAfterGap: day.efficiency.inputAfterGap,
|
|
23405
|
+
orphanCacheWrites: day.efficiency.orphanCacheWrites,
|
|
23406
|
+
orphanCacheWriteTokens: day.efficiency.orphanCacheWriteTokens,
|
|
23407
|
+
sessionMaxContext: asBuckets(
|
|
23408
|
+
day.efficiency.sessionMaxContext,
|
|
23409
|
+
"sessions"
|
|
23410
|
+
),
|
|
23411
|
+
sessionCalls: asBuckets(
|
|
23412
|
+
day.efficiency.sessionCalls,
|
|
23413
|
+
"sessions"
|
|
23414
|
+
),
|
|
23415
|
+
shortSessions: day.efficiency.shortSessions,
|
|
23416
|
+
shortSessionFirstCallTokens: day.efficiency.shortSessionFirstCallTokens,
|
|
23417
|
+
sessionsCompacted: day.efficiency.sessionsCompacted,
|
|
23418
|
+
toolResults: [...day.efficiency.toolResults].map(([tool, row]) => ({
|
|
23419
|
+
tool,
|
|
23420
|
+
results: row.results,
|
|
23421
|
+
bytes: row.bytes,
|
|
23422
|
+
buckets: asBuckets(row.buckets, "results")
|
|
23423
|
+
})).sort(
|
|
23424
|
+
(a, b) => b.bytes - a.bytes || a.tool.localeCompare(b.tool)
|
|
23425
|
+
),
|
|
23426
|
+
...day.efficiency.hasBlocks ? { blocks: day.efficiency.blocks } : {}
|
|
23427
|
+
}
|
|
23195
23428
|
} : {}
|
|
23196
23429
|
}))
|
|
23197
23430
|
};
|
|
@@ -23199,6 +23432,7 @@ function createHarnessWorkflowReducer(harness, localSources = createWorkflowLoca
|
|
|
23199
23432
|
eventCells.clear();
|
|
23200
23433
|
webSearchesByDate.clear();
|
|
23201
23434
|
compactionsByDate.clear();
|
|
23435
|
+
toolResultsByDate.clear();
|
|
23202
23436
|
eventDates.clear();
|
|
23203
23437
|
return finished;
|
|
23204
23438
|
}
|
|
@@ -23213,7 +23447,8 @@ function createAggregate2() {
|
|
|
23213
23447
|
workflowLocal,
|
|
23214
23448
|
workflowSeenCalls: /* @__PURE__ */ new Set(),
|
|
23215
23449
|
workflowSeenTurns: /* @__PURE__ */ new Set(),
|
|
23216
|
-
contextFirstCall: /* @__PURE__ */ new Map()
|
|
23450
|
+
contextFirstCall: /* @__PURE__ */ new Map(),
|
|
23451
|
+
workflowToolNames: /* @__PURE__ */ new Map()
|
|
23217
23452
|
});
|
|
23218
23453
|
}
|
|
23219
23454
|
function workflowSessionKey(rec) {
|
|
@@ -23267,8 +23502,10 @@ function ingestRecord(agg, raw, ctx) {
|
|
|
23267
23502
|
if (type === "assistant") {
|
|
23268
23503
|
ingestClaudeWorkflow(agg, rec, ctx, tsMs);
|
|
23269
23504
|
ingestAssistant(agg, rec, tsMs);
|
|
23270
|
-
} else if (type === "user")
|
|
23271
|
-
|
|
23505
|
+
} else if (type === "user") {
|
|
23506
|
+
ingestUser(agg, rec);
|
|
23507
|
+
ingestClaudeToolResults(agg, rec, ctx, tsMs);
|
|
23508
|
+
} else if (type === "system") {
|
|
23272
23509
|
ingestClaudeTurnDuration(agg, rec, ctx, tsMs);
|
|
23273
23510
|
ingestClaudeCompaction(agg, rec, ctx, tsMs);
|
|
23274
23511
|
}
|
|
@@ -23318,6 +23555,13 @@ function ingestClaudeWorkflow(agg, rec, ctx, tsMs) {
|
|
|
23318
23555
|
const messageId = asStr(msg.id);
|
|
23319
23556
|
const newTurn = messageId ? !agg.workflowSeenTurns.has(messageId) : true;
|
|
23320
23557
|
if (messageId) agg.workflowSeenTurns.add(messageId);
|
|
23558
|
+
const blocks = { thinking: 0, text: 0 };
|
|
23559
|
+
for (const rawBlock of asArr(msg.content)) {
|
|
23560
|
+
const block = asObj(rawBlock);
|
|
23561
|
+
const kind = block ? asStr(block.type) : null;
|
|
23562
|
+
if (kind === "thinking") blocks.thinking++;
|
|
23563
|
+
else if (kind === "text") blocks.text++;
|
|
23564
|
+
}
|
|
23321
23565
|
let context = null;
|
|
23322
23566
|
if (counts2 && isApiCall(rec)) {
|
|
23323
23567
|
const held = agg.contextFirstCall.get(session);
|
|
@@ -23328,6 +23572,9 @@ function ingestClaudeWorkflow(agg, rec, ctx, tsMs) {
|
|
|
23328
23572
|
} else if (held !== null && held === messageId) first = true;
|
|
23329
23573
|
context = {
|
|
23330
23574
|
contextTokens: contextOf(counts2),
|
|
23575
|
+
inputTokens: counts2.input,
|
|
23576
|
+
cacheReadTokens: counts2.cacheRead,
|
|
23577
|
+
cacheWriteTokens: counts2.cacheWrite5m + counts2.cacheWrite1h + counts2.cacheWriteUnsplit,
|
|
23331
23578
|
...first ? {
|
|
23332
23579
|
firstCall: {
|
|
23333
23580
|
harnessTokens: counts2.cacheRead,
|
|
@@ -23348,7 +23595,8 @@ function ingestClaudeWorkflow(agg, rec, ctx, tsMs) {
|
|
|
23348
23595
|
...counts2 ? { responseTokens: counts2.output } : {},
|
|
23349
23596
|
...counts2 ? { routingTokens: countsTotal(counts2) } : {},
|
|
23350
23597
|
...asStr(rec.effort) ?? asStr(msg.effort) ? { effort: asStr(rec.effort) ?? asStr(msg.effort) } : {},
|
|
23351
|
-
...context ?? {}
|
|
23598
|
+
...context ?? {},
|
|
23599
|
+
...blocks.thinking + blocks.text > 0 && isApiCall(rec) ? { blocks } : {}
|
|
23352
23600
|
});
|
|
23353
23601
|
const tools = [];
|
|
23354
23602
|
for (const rawBlock of asArr(msg.content)) {
|
|
@@ -23357,11 +23605,12 @@ function ingestClaudeWorkflow(agg, rec, ctx, tsMs) {
|
|
|
23357
23605
|
}
|
|
23358
23606
|
for (const block of tools) {
|
|
23359
23607
|
const id = asStr(block.id);
|
|
23608
|
+
const name = asName(block.name);
|
|
23609
|
+
if (id && name) agg.workflowToolNames.set(id, name);
|
|
23360
23610
|
if (id) {
|
|
23361
23611
|
if (agg.workflowSeenCalls.has(id)) continue;
|
|
23362
23612
|
agg.workflowSeenCalls.add(id);
|
|
23363
23613
|
}
|
|
23364
|
-
const name = asName(block.name);
|
|
23365
23614
|
if (!name) continue;
|
|
23366
23615
|
const input = asObj(block.input) ?? {};
|
|
23367
23616
|
let arg = "";
|
|
@@ -23593,6 +23842,31 @@ function ingestToolUse(agg, block) {
|
|
|
23593
23842
|
bump(agg.toolCalls, name);
|
|
23594
23843
|
}
|
|
23595
23844
|
var SLASH_RE = /<command-name>\/?([^<\n\r]{1,64})<\/command-name>/g;
|
|
23845
|
+
function ingestClaudeToolResults(agg, rec, ctx, tsMs) {
|
|
23846
|
+
if (tsMs === null) return;
|
|
23847
|
+
const session = workflowSessionKey(rec);
|
|
23848
|
+
const msg = asObj(rec.message);
|
|
23849
|
+
if (!session || !msg) return;
|
|
23850
|
+
const sidechain = rec.isSidechain === true;
|
|
23851
|
+
const parentSession = sidechain ? asStr(rec.sessionId) : null;
|
|
23852
|
+
for (const rawBlock of asArr(msg.content)) {
|
|
23853
|
+
const block = asObj(rawBlock);
|
|
23854
|
+
if (!block || asStr(block.type) !== "tool_result") continue;
|
|
23855
|
+
const toolUseId = asStr(block.tool_use_id);
|
|
23856
|
+
const content = block.content;
|
|
23857
|
+
const bytes = typeof content === "string" ? Buffer.byteLength(content) : content === void 0 || content === null ? 0 : Buffer.byteLength(JSON.stringify(content));
|
|
23858
|
+
agg.workflow.ingest({
|
|
23859
|
+
type: "toolResult",
|
|
23860
|
+
session,
|
|
23861
|
+
projectWorkspace: projectWorkspaceDirectory(rec) ?? ctx.projectDir,
|
|
23862
|
+
tsMs,
|
|
23863
|
+
sidechain,
|
|
23864
|
+
...parentSession ? { parentSession } : {},
|
|
23865
|
+
tool: toolUseId && agg.workflowToolNames.get(toolUseId) || "other",
|
|
23866
|
+
bytes
|
|
23867
|
+
});
|
|
23868
|
+
}
|
|
23869
|
+
}
|
|
23596
23870
|
function ingestUser(agg, rec) {
|
|
23597
23871
|
const msg = asObj(rec.message);
|
|
23598
23872
|
if (!msg) return;
|
|
@@ -23794,7 +24068,8 @@ function createFileState() {
|
|
|
23794
24068
|
counted: false,
|
|
23795
24069
|
metaTsMs: null,
|
|
23796
24070
|
forked: false,
|
|
23797
|
-
sawResponse: false
|
|
24071
|
+
sawResponse: false,
|
|
24072
|
+
callNames: /* @__PURE__ */ new Map()
|
|
23798
24073
|
};
|
|
23799
24074
|
}
|
|
23800
24075
|
function genuineDelta(payload, state, tsMs) {
|
|
@@ -23917,6 +24192,9 @@ function ingestEvent(agg, payload, state, tsMs, firstCall) {
|
|
|
23917
24192
|
// the fresh part is the instructions: AGENTS.md, environment,
|
|
23918
24193
|
// skills and the first prompt. Same method as Claude Code (#358).
|
|
23919
24194
|
contextTokens: counts2.input + counts2.cacheRead,
|
|
24195
|
+
inputTokens: counts2.input,
|
|
24196
|
+
cacheReadTokens: counts2.cacheRead,
|
|
24197
|
+
cacheWriteTokens: 0,
|
|
23920
24198
|
...contextWindow > 0 ? { contextWindow } : {},
|
|
23921
24199
|
...firstCall && !state.forked ? {
|
|
23922
24200
|
firstCall: {
|
|
@@ -23951,16 +24229,22 @@ function ingestCall(agg, name, callId) {
|
|
|
23951
24229
|
}
|
|
23952
24230
|
function ingestItem(agg, payload, state, tsMs) {
|
|
23953
24231
|
const type = asStr(payload.type);
|
|
24232
|
+
if (type === "function_call_output" || type === "custom_tool_call_output") {
|
|
24233
|
+
ingestToolResult(agg, payload, state, tsMs);
|
|
24234
|
+
return;
|
|
24235
|
+
}
|
|
23954
24236
|
if (type === "function_call" || type === "custom_tool_call") {
|
|
23955
24237
|
const name = asName(payload.name);
|
|
23956
24238
|
if (!name) return;
|
|
23957
24239
|
const callId = asStr(payload.call_id) ?? asStr(payload.id);
|
|
24240
|
+
if (callId) state.callNames.set(callId, name);
|
|
23958
24241
|
ingestCall(agg, name, callId);
|
|
23959
24242
|
ingestWorkflowCall(agg, payload, name, callId, state, tsMs);
|
|
23960
24243
|
return;
|
|
23961
24244
|
}
|
|
23962
24245
|
if (type === "local_shell_call") {
|
|
23963
24246
|
const callId = asStr(payload.call_id) ?? asStr(payload.id);
|
|
24247
|
+
if (callId) state.callNames.set(callId, "local_shell");
|
|
23964
24248
|
ingestCall(agg, "local_shell", callId);
|
|
23965
24249
|
ingestWorkflowCall(agg, payload, "local_shell", callId, state, tsMs);
|
|
23966
24250
|
} else if (type === "web_search_call") {
|
|
@@ -23986,6 +24270,20 @@ function ingestItem(agg, payload, state, tsMs) {
|
|
|
23986
24270
|
);
|
|
23987
24271
|
}
|
|
23988
24272
|
}
|
|
24273
|
+
function ingestToolResult(agg, payload, state, tsMs) {
|
|
24274
|
+
if (tsMs === null || !state.sessionId) return;
|
|
24275
|
+
const callId = asStr(payload.call_id) ?? asStr(payload.id);
|
|
24276
|
+
const output = payload.output;
|
|
24277
|
+
const bytes = typeof output === "string" ? Buffer.byteLength(output) : output === void 0 || output === null ? 0 : Buffer.byteLength(JSON.stringify(output));
|
|
24278
|
+
agg.workflow.ingest({
|
|
24279
|
+
type: "toolResult",
|
|
24280
|
+
session: state.sessionId,
|
|
24281
|
+
projectWorkspace: state.cwd ?? void 0,
|
|
24282
|
+
tsMs,
|
|
24283
|
+
tool: callId && state.callNames.get(callId) || "other",
|
|
24284
|
+
bytes
|
|
24285
|
+
});
|
|
24286
|
+
}
|
|
23989
24287
|
function ingestWorkflowCall(agg, payload, name, callId, state, tsMs) {
|
|
23990
24288
|
if (tsMs === null || !state.sessionId) return;
|
|
23991
24289
|
if (callId) {
|
|
@@ -29329,7 +29627,7 @@ function buildWorkflowExtraction(harnessWorkflows, git, utcOffsetMinutes = machi
|
|
|
29329
29627
|
])
|
|
29330
29628
|
].sort();
|
|
29331
29629
|
return {
|
|
29332
|
-
aggregateVersion:
|
|
29630
|
+
aggregateVersion: WORKFLOW_AGGREGATES_V4,
|
|
29333
29631
|
utcOffsetMinutes,
|
|
29334
29632
|
days: dates.map((date) => {
|
|
29335
29633
|
const projects = projectDays.get(date)?.size;
|
|
@@ -29626,7 +29924,7 @@ var PHASE_ORDER = ["scout", "build", "verify", "handoff", "unknown"];
|
|
|
29626
29924
|
function workflowBlock(workflowDays, utcOffsetMinutes, host) {
|
|
29627
29925
|
const out = [];
|
|
29628
29926
|
const folded = foldWorkflowDays(workflowDays, {
|
|
29629
|
-
aggregateVersion:
|
|
29927
|
+
aggregateVersion: WORKFLOW_AGGREGATES_V4,
|
|
29630
29928
|
utcOffsetMinutes
|
|
29631
29929
|
});
|
|
29632
29930
|
const harnesses = folded?.harnesses ?? [];
|
|
@@ -29636,7 +29934,7 @@ function workflowBlock(workflowDays, utcOffsetMinutes, host) {
|
|
|
29636
29934
|
...new Set(withPlaybook.map((h) => h.phase?.ruleVersion ?? ""))
|
|
29637
29935
|
].filter(Boolean);
|
|
29638
29936
|
out.push(
|
|
29639
|
-
`workflow ${harnesses.length} harness${harnesses.length === 1 ? "" : "es"} \xB7 ${sessions} sessions \xB7 ${
|
|
29937
|
+
`workflow ${harnesses.length} harness${harnesses.length === 1 ? "" : "es"} \xB7 ${sessions} sessions \xB7 ${WORKFLOW_AGGREGATES_V4}`
|
|
29640
29938
|
);
|
|
29641
29939
|
const first = folded?.dates[0];
|
|
29642
29940
|
const last = folded?.dates.at(-1);
|
|
@@ -29653,6 +29951,26 @@ function workflowBlock(workflowDays, utcOffsetMinutes, host) {
|
|
|
29653
29951
|
).join(" \xB7 ");
|
|
29654
29952
|
out.push(` ${mix} \xB7 ${ruleVersions.join(", ")}`);
|
|
29655
29953
|
}
|
|
29954
|
+
const efficiency = harnesses.flatMap(
|
|
29955
|
+
(h) => h.efficiency ? [h.efficiency] : []
|
|
29956
|
+
);
|
|
29957
|
+
if (efficiency.length > 0) {
|
|
29958
|
+
const calls = efficiency.reduce(
|
|
29959
|
+
(a, e) => a + e.callGaps.reduce((n, b) => n + b.calls, 0) + e.sessionCalls.reduce((n, b) => n + b.sessions, 0),
|
|
29960
|
+
0
|
|
29961
|
+
);
|
|
29962
|
+
const afterGap = efficiency.reduce((a, e) => a + e.callsAfterGap, 0);
|
|
29963
|
+
const results = efficiency.reduce(
|
|
29964
|
+
(a, e) => a + e.toolResults.reduce((n, t) => n + t.results, 0),
|
|
29965
|
+
0
|
|
29966
|
+
);
|
|
29967
|
+
const tools = [
|
|
29968
|
+
...new Set(efficiency.flatMap((e) => e.toolResults.map((t) => t.tool)))
|
|
29969
|
+
].sort();
|
|
29970
|
+
out.push(
|
|
29971
|
+
` efficiency: ${calls} calls, ${afterGap} after a break \xB7 ${results} tool result sizes${tools.length ? ` (${tools.join(", ")})` : ""}`
|
|
29972
|
+
);
|
|
29973
|
+
}
|
|
29656
29974
|
const git = folded?.git;
|
|
29657
29975
|
out.push(
|
|
29658
29976
|
`git ${git?.commits ?? 0} commits \xB7 ${fmtTokens((git?.additions ?? 0) + (git?.removals ?? 0))} lines changed`
|