@use-aistack/cli 0.16.11 → 0.18.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.16.11" : "0.0.0-dev";
18909
+ var CLI_VERSION = true ? "0.18.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_V3 = "workflow-aggregates/v3";
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 = WORKFLOW_AGGREGATES_V3;
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") ingestUser(agg, rec);
23271
- else if (type === "system") {
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: WORKFLOW_AGGREGATES_V3,
29630
+ aggregateVersion: WORKFLOW_AGGREGATES_V4,
29333
29631
  utcOffsetMinutes,
29334
29632
  days: dates.map((date) => {
29335
29633
  const projects = projectDays.get(date)?.size;
@@ -29426,16 +29724,59 @@ function withheldCount(payload) {
29426
29724
  const w = payload.inventory.withheld;
29427
29725
  return w.builtinTools + w.mcpServers + w.skills + w.subagents + w.slashCommands;
29428
29726
  }
29429
- function buildGateDialog(ctx) {
29430
- const { payloads, keptPrivate } = ctx.body;
29431
- const n = payloads.reduce((a, p8) => a + withheldCount(p8), 0);
29432
- const lines2 = ["Publish to aistack?"];
29433
- if (n > 0) {
29434
- lines2.push(
29435
- keptPrivate === void 0 ? `${n} name${n === 1 ? "" : "s"} stay${n === 1 ? "s" : ""} on this machine` : `${n} private review name${n === 1 ? "" : "s"} will be stored`
29727
+ function buildGateDialog(_ctx) {
29728
+ return `Publish to aistack?
29729
+ ${PUBLIC_LINE}`;
29730
+ }
29731
+ var NEVER_SENT = "your prompts, responses, code, file paths, and repo names";
29732
+ var PUBLIC_LINE = "Nothing sensitive is shown in public.";
29733
+ function buildGateBrief(ctx) {
29734
+ const { body, config, source, baseUrl } = ctx;
29735
+ const host = baseUrl.replace(/^https?:\/\//, "");
29736
+ const out = [];
29737
+ if (config.stack === null) {
29738
+ out.push("No linked stack, so publish is unavailable.");
29739
+ } else {
29740
+ out.push(`Publishing to ${config.stack.name}`);
29741
+ out.push(`${host}/stacks/${config.stack.slug}`);
29742
+ }
29743
+ out.push("");
29744
+ const measured = body.payloads.filter((p8) => p8.activity.totalTokens > 0);
29745
+ const sessions = measured.reduce((a, p8) => a + p8.activity.sessions, 0);
29746
+ const tokens = measured.reduce((a, p8) => a + p8.activity.totalTokens, 0);
29747
+ const windowDays = body.payloads[0]?.window.days ?? 30;
29748
+ const counts2 = [
29749
+ `${measured.length} harness${measured.length === 1 ? "" : "es"}`,
29750
+ `${sessions.toLocaleString("en-US")} session${sessions === 1 ? "" : "s"}`,
29751
+ `${fmtTokens(tokens)} tokens`,
29752
+ `last ${windowDays} days`
29753
+ ];
29754
+ const workflow = config.publishWorkflow ? (body.measuredDays?.days ?? []).some((d) => d.workflow) : false;
29755
+ const kinds = [
29756
+ ...body.payloads.some((p8) => p8.models.length > 0) ? ["model names"] : [],
29757
+ ...body.payloads.some(
29758
+ (p8) => NAME_CATEGORIES.some((c) => p8.inventory[c].length > 0)
29759
+ ) ? ["tool and skill names"] : [],
29760
+ ...workflow ? ["time per phase", "git line counts"] : []
29761
+ ];
29762
+ out.push("Sent: statistics about your usage");
29763
+ out.push(` ${counts2.join(" \xB7 ")}`);
29764
+ if (kinds.length > 0) out.push(` ${kinds.join(", ")}`);
29765
+ out.push(`Never sent: ${NEVER_SENT}`);
29766
+ out.push(PUBLIC_LINE);
29767
+ if (body.autoSync !== void 0) {
29768
+ out.push("");
29769
+ out.push(
29770
+ `Auto-sync: ${body.autoSync.enabled ? `on, about every ${body.autoSync.frequencyHours} hours` : "off"}`
29436
29771
  );
29437
29772
  }
29438
- return lines2.join("\n");
29773
+ if (source === "bundled") {
29774
+ out.push("");
29775
+ out.push(
29776
+ "! Could not fetch your settings from aistack, so this publishes less."
29777
+ );
29778
+ }
29779
+ return out.join("\n");
29439
29780
  }
29440
29781
  var CATEGORY_LABEL = {
29441
29782
  builtinTools: "actions",
@@ -29626,7 +29967,7 @@ var PHASE_ORDER = ["scout", "build", "verify", "handoff", "unknown"];
29626
29967
  function workflowBlock(workflowDays, utcOffsetMinutes, host) {
29627
29968
  const out = [];
29628
29969
  const folded = foldWorkflowDays(workflowDays, {
29629
- aggregateVersion: WORKFLOW_AGGREGATES_V3,
29970
+ aggregateVersion: WORKFLOW_AGGREGATES_V4,
29630
29971
  utcOffsetMinutes
29631
29972
  });
29632
29973
  const harnesses = folded?.harnesses ?? [];
@@ -29636,7 +29977,7 @@ function workflowBlock(workflowDays, utcOffsetMinutes, host) {
29636
29977
  ...new Set(withPlaybook.map((h) => h.phase?.ruleVersion ?? ""))
29637
29978
  ].filter(Boolean);
29638
29979
  out.push(
29639
- `workflow ${harnesses.length} harness${harnesses.length === 1 ? "" : "es"} \xB7 ${sessions} sessions \xB7 ${WORKFLOW_AGGREGATES_V3}`
29980
+ `workflow ${harnesses.length} harness${harnesses.length === 1 ? "" : "es"} \xB7 ${sessions} sessions \xB7 ${WORKFLOW_AGGREGATES_V4}`
29640
29981
  );
29641
29982
  const first = folded?.dates[0];
29642
29983
  const last = folded?.dates.at(-1);
@@ -29653,6 +29994,26 @@ function workflowBlock(workflowDays, utcOffsetMinutes, host) {
29653
29994
  ).join(" \xB7 ");
29654
29995
  out.push(` ${mix} \xB7 ${ruleVersions.join(", ")}`);
29655
29996
  }
29997
+ const efficiency = harnesses.flatMap(
29998
+ (h) => h.efficiency ? [h.efficiency] : []
29999
+ );
30000
+ if (efficiency.length > 0) {
30001
+ const calls = efficiency.reduce(
30002
+ (a, e) => a + e.callGaps.reduce((n, b) => n + b.calls, 0) + e.sessionCalls.reduce((n, b) => n + b.sessions, 0),
30003
+ 0
30004
+ );
30005
+ const afterGap = efficiency.reduce((a, e) => a + e.callsAfterGap, 0);
30006
+ const results = efficiency.reduce(
30007
+ (a, e) => a + e.toolResults.reduce((n, t) => n + t.results, 0),
30008
+ 0
30009
+ );
30010
+ const tools = [
30011
+ ...new Set(efficiency.flatMap((e) => e.toolResults.map((t) => t.tool)))
30012
+ ].sort();
30013
+ out.push(
30014
+ ` efficiency: ${calls} calls, ${afterGap} after a break \xB7 ${results} tool result sizes${tools.length ? ` (${tools.join(", ")})` : ""}`
30015
+ );
30016
+ }
29656
30017
  const git = folded?.git;
29657
30018
  out.push(
29658
30019
  `git ${git?.commits ?? 0} commits \xB7 ${fmtTokens((git?.additions ?? 0) + (git?.removals ?? 0))} lines changed`
@@ -29757,11 +30118,11 @@ function buildGateSummary(ctx) {
29757
30118
  const examples = shown.map((r) => r.names > 1 ? `${r.label} \xD7${r.names}` : r.label).join(", ");
29758
30119
  const more = rows.length > shown.length ? `, ...${rows.length - shown.length} more` : "";
29759
30120
  out.push(
29760
- `private ${n} review name${n === 1 ? "" : "s"} \xB7 ${examples}${more}`
30121
+ `private ${n} unapproved name${n === 1 ? "" : "s"} \xB7 ${examples}${more}`
29761
30122
  );
29762
30123
  if (body.keptPrivate !== void 0 && config.stack !== null) {
29763
30124
  out.push(
29764
- ` stored privately for your review at ${host}/stacks/${config.stack.slug}/changes`
30125
+ ` never shown in public, only you see them at ${host}/stacks/${config.stack.slug}/changes`
29765
30126
  );
29766
30127
  out.push(
29767
30128
  " (turn off: Review kept-private names, on your stack)"
@@ -30160,6 +30521,7 @@ async function stageSync(deps) {
30160
30521
  body,
30161
30522
  keptPrivate,
30162
30523
  summary: buildGateSummary(ctx),
30524
+ brief: buildGateBrief(ctx),
30163
30525
  dialog: buildGateDialog(ctx),
30164
30526
  config,
30165
30527
  token,
@@ -30599,24 +30961,28 @@ async function syncCommand(options = {}) {
30599
30961
  }
30600
30962
  board.stop();
30601
30963
  const s = p7.spinner();
30602
- p7.log.message(staged.summary.split("\n").map(styleSummaryLine).join("\n"));
30964
+ p7.log.message(staged.brief.split("\n").map(styleBriefLine).join("\n"));
30603
30965
  if (staged.blockedReason !== null) {
30604
30966
  outroError(staged.blockedReason);
30605
30967
  process.exitCode = 1;
30606
30968
  return;
30607
30969
  }
30608
- const decision = await p7.select({
30609
- message: staged.dialog.split("\n").join(dim(" \xB7 ")),
30610
- options: [
30611
- {
30612
- value: "publish",
30613
- label: "Publish",
30614
- hint: "no sensitive data is shared"
30615
- },
30616
- { value: "cancel", label: "Cancel", hint: "nothing leaves this machine" }
30617
- ],
30618
- initialValue: "publish"
30619
- });
30970
+ let showedDetails = false;
30971
+ let decision;
30972
+ for (; ; ) {
30973
+ decision = await p7.select({
30974
+ message: "Publish to aistack?",
30975
+ options: [
30976
+ { value: "publish", label: "Publish" },
30977
+ ...showedDetails ? [] : [{ value: "details", label: "Show details" }],
30978
+ { value: "cancel", label: "Cancel", hint: "nothing is sent" }
30979
+ ],
30980
+ initialValue: "publish"
30981
+ });
30982
+ if (decision !== "details") break;
30983
+ showedDetails = true;
30984
+ p7.log.message(staged.summary.split("\n").map(styleSummaryLine).join("\n"));
30985
+ }
30620
30986
  if (p7.isCancel(decision) || decision !== "publish") {
30621
30987
  outroCancel("nothing was sent");
30622
30988
  return;
@@ -30626,24 +30992,10 @@ async function syncCommand(options = {}) {
30626
30992
  const res = await syncPublish(staged.token, staged.bodyJson);
30627
30993
  staged.acknowledgePublish?.();
30628
30994
  s.stop("Published");
30629
- const lines2 = [
30630
- `Snapshot received ${fmtReceivedAt(res.receivedAt)}`,
30631
- "",
30632
- "Your stack now shows what actually ran:",
30633
- lime(res.url)
30634
- ];
30995
+ const lines2 = ["See your stack:", lime(res.url)];
30635
30996
  if (res.keptPrivate.refused && staged.body.keptPrivate !== void 0) {
30636
30997
  lines2.push(
30637
- "Note: the server refused the kept-private names because its review switch is off. They stayed on this machine."
30638
- );
30639
- } else if (res.keptPrivate.stored > 0) {
30640
- lines2.push(
30641
- `${res.keptPrivate.stored} private review name${res.keptPrivate.stored === 1 ? "" : "s"} stored at ${res.url}/changes`
30642
- );
30643
- }
30644
- if (res.keptPrivate.machineStored > 0) {
30645
- lines2.push(
30646
- "This machine's private label was stored for the same review."
30998
+ "Note: the server refused the unapproved names because its review switch is off. They stayed on this machine."
30647
30999
  );
30648
31000
  }
30649
31001
  p7.log.message(lines2.join("\n"));
@@ -30657,6 +31009,14 @@ async function syncCommand(options = {}) {
30657
31009
  process.exitCode = 1;
30658
31010
  }
30659
31011
  }
31012
+ function styleBriefLine(line) {
31013
+ const labelled = /^(Sent:|Never sent:|Auto-sync:)(.*)$/.exec(line);
31014
+ if (labelled) return `${dim(labelled[1] ?? "")}${labelled[2] ?? ""}`;
31015
+ if (line.startsWith("Publishing to ")) return bold(line);
31016
+ if (/^\S+\/stacks\//.test(line)) return lime(line);
31017
+ if (line.startsWith(" ")) return dim(line);
31018
+ return line;
31019
+ }
30660
31020
  function styleSummaryLine(line) {
30661
31021
  if (line.startsWith("\u2500")) return dim(line);
30662
31022
  const section2 = /^([A-Z][A-Z0-9 .-]+?)( \d+)?$/.exec(line);
@@ -30872,7 +31232,7 @@ function createSyncServer(deps, send) {
30872
31232
  );
30873
31233
  } else if (res.keptPrivate.stored > 0) {
30874
31234
  lines2.push(
30875
- `${res.keptPrivate.stored} private review name${res.keptPrivate.stored === 1 ? "" : "s"} stored at ${res.url}/changes`
31235
+ `${res.keptPrivate.stored} unapproved name${res.keptPrivate.stored === 1 ? "" : "s"} visible only to you at ${res.url}/changes, never shown in public`
30876
31236
  );
30877
31237
  }
30878
31238
  if (res.keptPrivate.machineStored > 0) {