@koalaauto/agentchannel 3.30.3 → 3.32.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.
@@ -1,7 +1,7 @@
1
1
  import type { CanUseTool, HookCallbackMatcher, Options } from '@anthropic-ai/claude-agent-sdk';
2
2
  import type { Perm } from '../perm.js';
3
3
  import { type PathPolicy } from './paths.js';
4
- import type { AdapterResult, AdapterRunOptions, RuntimeAdapter } from './types.js';
4
+ import { type AdapterResult, type AdapterRunOptions, type RuntimeAdapter } from './types.js';
5
5
  /** Best-effort Bash deny list for `workdir` (the SDK sandbox is the real boundary). */
6
6
  export declare const BASH_DENY: RegExp[];
7
7
  /** S3: the only `ach` subcommands a spawned agent is pre-approved to run. */
@@ -77,6 +77,14 @@ export declare function thinkingFor(model: string | undefined, env?: Record<stri
77
77
  display: 'summarized';
78
78
  };
79
79
  };
80
+ /**
81
+ * The model a Claude run used: the one the CLI names in its init message, else the only one its result lists usage for. A run
82
+ * lists more than one when Claude Code does side work on a small model (titles, searches), which says nothing about the one
83
+ * that answered, so several without an init name stay unknown.
84
+ */
85
+ export declare function modelOf(init: unknown, modelUsage?: unknown): string | undefined;
86
+ /** The effort a hook input says the turn ran at, after the CLI's own downgrades for the model (the init message does not carry it). */
87
+ export declare function effortOf(input: unknown): string | undefined;
80
88
  export interface ClaudeAdapterOptions {
81
89
  model?: string;
82
90
  }
@@ -2,6 +2,7 @@ import { homedir } from 'node:os';
2
2
  import { toolDenied } from './paths.js';
3
3
  import { macTempPatterns, readable, systemPaths } from './scope.js';
4
4
  import { spawnGroup } from './procgroup.js';
5
+ import { modelId } from './types.js';
5
6
  /** Best-effort Bash deny list for `workdir` (the SDK sandbox is the real boundary). */
6
7
  export const BASH_DENY = [
7
8
  /\brm\s+-[a-z]*r[a-z]*f?[a-z]*\s+(\/|~|\$HOME)(\s|$)/i,
@@ -193,6 +194,24 @@ export function thinkingFor(model, env = {}) {
193
194
  }
194
195
  return { thinking: { type: 'adaptive', display: 'summarized' } };
195
196
  }
197
+ const EFFORT_LEVELS = ['low', 'medium', 'high', 'xhigh', 'max'];
198
+ /**
199
+ * The model a Claude run used: the one the CLI names in its init message, else the only one its result lists usage for. A run
200
+ * lists more than one when Claude Code does side work on a small model (titles, searches), which says nothing about the one
201
+ * that answered, so several without an init name stay unknown.
202
+ */
203
+ export function modelOf(init, modelUsage) {
204
+ const named = modelId(init);
205
+ if (named)
206
+ return named;
207
+ const used = modelUsage && typeof modelUsage === 'object' ? Object.keys(modelUsage) : [];
208
+ return used.length === 1 ? modelId(used[0]) : undefined;
209
+ }
210
+ /** The effort a hook input says the turn ran at, after the CLI's own downgrades for the model (the init message does not carry it). */
211
+ export function effortOf(input) {
212
+ const level = input?.effort?.level;
213
+ return typeof level === 'string' && EFFORT_LEVELS.includes(level) ? level : undefined;
214
+ }
196
215
  export class ClaudeAdapter {
197
216
  o;
198
217
  name = 'claude';
@@ -223,6 +242,27 @@ export class ClaudeAdapter {
223
242
  abortController.abort();
224
243
  else
225
244
  opts.signal.addEventListener('abort', onAbort, { once: true });
245
+ // what the run really used: the model comes from the init message below, the effort from a hook that only reads
246
+ let model;
247
+ let effort;
248
+ const effortHook = {
249
+ hooks: [
250
+ async (input) => {
251
+ effort = effortOf(input) ?? effort;
252
+ return {};
253
+ },
254
+ ],
255
+ };
256
+ const permOptions = claudePermOptions(opts.perm, {
257
+ cwd: opts.cwd,
258
+ hub: opts.hub,
259
+ mode: opts.mode,
260
+ readRoots: opts.readRoots,
261
+ denyReadPaths: opts.denyReadPaths,
262
+ home: opts.realHome ?? opts.env.HOME,
263
+ tmpDir: opts.tmpDir,
264
+ netAllow: opts.netAllow,
265
+ });
226
266
  const options = {
227
267
  cwd: opts.cwd,
228
268
  env: opts.env,
@@ -231,16 +271,9 @@ export class ClaudeAdapter {
231
271
  ...(this.o.model ? { model: this.o.model } : {}),
232
272
  ...(opts.maxBudgetUsd && opts.maxBudgetUsd > 0 ? { maxBudgetUsd: opts.maxBudgetUsd } : {}),
233
273
  ...(withThinking ? thinkingFor(this.o.model, opts.env) : {}),
234
- ...claudePermOptions(opts.perm, {
235
- cwd: opts.cwd,
236
- hub: opts.hub,
237
- mode: opts.mode,
238
- readRoots: opts.readRoots,
239
- denyReadPaths: opts.denyReadPaths,
240
- home: opts.realHome ?? opts.env.HOME,
241
- tmpDir: opts.tmpDir,
242
- netAllow: opts.netAllow,
243
- }),
274
+ ...permOptions,
275
+ // after the policy's own hooks, never instead of them: the first tool call or the end of a turn tells what effort applied
276
+ hooks: { ...permOptions.hooks, PreToolUse: [...(permOptions.hooks?.PreToolUse ?? []), effortHook], Stop: [...(permOptions.hooks?.Stop ?? []), effortHook] },
244
277
  spawnClaudeCodeProcess: (s) => spawnGroup(s.command, s.args, {
245
278
  cwd: s.cwd,
246
279
  env: s.env,
@@ -285,6 +318,7 @@ export class ClaudeAdapter {
285
318
  }
286
319
  else if (m.type === 'result') {
287
320
  costUsd = anyM.total_cost_usd;
321
+ model = modelOf(model, anyM.modelUsage);
288
322
  opts.onEvent({ type: 'usage', data: { costUsd, usage: anyM.usage } });
289
323
  if (anyM.subtype === 'success' && !anyM.is_error) {
290
324
  ok = true;
@@ -296,6 +330,8 @@ export class ClaudeAdapter {
296
330
  }
297
331
  }
298
332
  else {
333
+ if (m.type === 'system' && anyM.subtype === 'init')
334
+ model = modelId(anyM.model) ?? model;
299
335
  opts.onEvent({ type: 'tool', data: { type: m.type, subtype: anyM.subtype } });
300
336
  }
301
337
  }
@@ -310,6 +346,6 @@ export class ClaudeAdapter {
310
346
  }
311
347
  if (!finalText)
312
348
  finalText = lastText.join('\n');
313
- return { finalText, sessionId, costUsd, costCumulative: true, ok, error };
349
+ return { finalText, sessionId, costUsd, costCumulative: true, ok, error, ...(model ? { model } : {}), ...(effort ? { effort } : {}) };
314
350
  }
315
351
  }
@@ -1,6 +1,6 @@
1
1
  import type { SandboxMode, ThreadOptions, Usage } from '@openai/codex-sdk';
2
2
  import type { Perm } from '../perm.js';
3
- import type { AdapterResult, AdapterRunOptions, RuntimeAdapter } from './types.js';
3
+ import { type AdapterResult, type AdapterRunOptions, type RuntimeAdapter } from './types.js';
4
4
  /** USD per 1M tokens. Configurable via ACH_CODEX_PRICE='{"input":..,"cached_input":..,"output":..}'. */
5
5
  export interface PriceTable {
6
6
  input: number;
@@ -1,6 +1,7 @@
1
1
  import { execFileSync } from 'node:child_process';
2
2
  import { readable, systemPaths } from './scope.js';
3
3
  import { KILL_GRACE_MS } from './procgroup.js';
4
+ import { modelId } from './types.js';
4
5
  export const DEFAULT_CODEX_PRICE = { input: 1.25, cached_input: 0.125, output: 10 };
5
6
  export function priceFromEnv(env = process.env) {
6
7
  try {
@@ -328,6 +329,8 @@ export class CodexAdapter {
328
329
  estimated: true,
329
330
  ok: !error,
330
331
  error,
332
+ // Codex does not say which model it used: only a model pinned with --model is known
333
+ ...(modelId(this.o.model) ? { model: this.o.model } : {}),
331
334
  };
332
335
  }
333
336
  }
@@ -22,6 +22,11 @@ export type FakeStep = {
22
22
  cost: number;
23
23
  } | {
24
24
  thinking: string;
25
+ } | {
26
+ used: {
27
+ model?: string;
28
+ effort?: string;
29
+ };
25
30
  } | {
26
31
  call: {
27
32
  name: string;
@@ -58,6 +58,7 @@ export class FakeAdapter {
58
58
  const ach = this.o.ach ?? spawnAch;
59
59
  let text = '';
60
60
  let cost;
61
+ let used = {};
61
62
  try {
62
63
  for (const step of this.o.script(info)) {
63
64
  if (opts.signal.aborted)
@@ -85,6 +86,9 @@ export class FakeAdapter {
85
86
  cost = step.cost;
86
87
  opts.onEvent({ type: 'usage', data: { costUsd: cost } });
87
88
  }
89
+ else if ('used' in step) {
90
+ used = step.used;
91
+ }
88
92
  else if ('thinking' in step) {
89
93
  opts.onEvent({ type: 'thinking', data: step.thinking });
90
94
  }
@@ -101,7 +105,7 @@ export class FakeAdapter {
101
105
  opts.onEvent({ type: 'tool_end', data: { id: step.toolEnd } });
102
106
  }
103
107
  else if ('fail' in step) {
104
- return { finalText: text, sessionId, costUsd: cost, ok: false, error: step.fail };
108
+ return { finalText: text, sessionId, costUsd: cost, ...used, ok: false, error: step.fail };
105
109
  }
106
110
  else if ('throw' in step) {
107
111
  throw new Error(step.throw);
@@ -109,8 +113,8 @@ export class FakeAdapter {
109
113
  }
110
114
  }
111
115
  catch (e) {
112
- return { finalText: text, sessionId, costUsd: cost, ok: false, error: opts.signal.aborted ? 'aborted' : String(e?.message ?? e) };
116
+ return { finalText: text, sessionId, costUsd: cost, ...used, ok: false, error: opts.signal.aborted ? 'aborted' : String(e?.message ?? e) };
113
117
  }
114
- return { finalText: text, sessionId, costUsd: cost, ok: true };
118
+ return { finalText: text, sessionId, costUsd: cost, ...used, ok: true };
115
119
  }
116
120
  }
@@ -1,4 +1,4 @@
1
- import type { AdapterEvent, AdapterResult, AdapterRunOptions, RuntimeAdapter } from './types.js';
1
+ import { type AdapterEvent, type AdapterResult, type AdapterRunOptions, type RuntimeAdapter } from './types.js';
2
2
  /**
3
3
  * Kiro runtime: each run is a Kiro cloud session started headlessly with
4
4
  * `kiro-cli chat --v3 --no-interactive --cloud --repo <owner/name> "<prompt>"` (KIRO_API_KEY).
@@ -1,5 +1,6 @@
1
1
  import { execFileSync } from 'node:child_process';
2
2
  import { spawnGroup } from './procgroup.js';
3
+ import { modelId } from './types.js';
3
4
  /**
4
5
  * Kiro runtime: each run is a Kiro cloud session started headlessly with
5
6
  * `kiro-cli chat --v3 --no-interactive --cloud --repo <owner/name> "<prompt>"` (KIRO_API_KEY).
@@ -288,7 +289,7 @@ export class KiroAdapter {
288
289
  const ok = !err && code === 0 && !opts.signal.aborted;
289
290
  const error = ok ? undefined : opts.signal.aborted ? 'aborted' : err ?? (stripAnsi(stderr).trim().split('\n').slice(-3).join(' ') || `kiro-cli exited ${code}`);
290
291
  // Kiro bills credits, not dollars, and the CLI does not print them (2.37.1): the cost stays unknown, never guessed.
291
- resolve({ result: { finalText, sessionId: out.sessionId, ok, error, estimated: true }, progressed });
292
+ resolve({ result: { finalText, sessionId: out.sessionId, ok, error, estimated: true, ...(modelId(this.o.model) ? { model: this.o.model } : {}) }, progressed });
292
293
  };
293
294
  child.on('error', (e) => finish(null, e?.code === 'ENOENT' ? `kiro-cli not found (${bin}): install it (curl -fsSL https://cli.kiro.dev/install | bash) or set ACH_KIRO_BIN` : String(e?.message ?? e)));
294
295
  child.on('close', (code) => finish(code));
@@ -10,6 +10,8 @@ export interface AdapterEvent {
10
10
  data: any;
11
11
  }
12
12
  export type RunMode = 'work' | 'answer' | 'mention';
13
+ /** A model id as the hub stores and the panel shows it: a plain token, nothing a tool could put a sentence into. */
14
+ export declare function modelId(v: unknown): string | undefined;
13
15
  export interface AdapterRunOptions {
14
16
  prompt: string;
15
17
  cwd: string;
@@ -51,6 +53,13 @@ export interface AdapterResult {
51
53
  costCumulative?: boolean;
52
54
  /** True when cost is estimated from tokens (codex). */
53
55
  estimated?: boolean;
56
+ /**
57
+ * What the run really used, as the tool reported it (not what anyone configured): the model's id (claude: the one the CLI named
58
+ * when it started, e.g. claude-opus-5-5) and the reasoning effort it applied after its own downgrades. Left out when unknown:
59
+ * codex and kiro only say what `--model` pinned.
60
+ */
61
+ model?: string;
62
+ effort?: string;
54
63
  ok: boolean;
55
64
  error?: string;
56
65
  }
@@ -1 +1,4 @@
1
- export {};
1
+ /** A model id as the hub stores and the panel shows it: a plain token, nothing a tool could put a sentence into. */
2
+ export function modelId(v) {
3
+ return typeof v === 'string' && /^[A-Za-z0-9][A-Za-z0-9._:/[\]-]{0,79}$/.test(v) ? v : undefined;
4
+ }
@@ -3,6 +3,11 @@ import { type Attachment, type StorageConfig, type TaskFile } from './attachment
3
3
  export type TaskStatus = 'submitted' | 'working' | 'input-required' | 'awaiting_acceptance' | 'completed' | 'failed' | 'canceled';
4
4
  export declare const TERMINAL: readonly TaskStatus[];
5
5
  export declare function isTerminal(s: string | undefined): boolean;
6
+ /** What a run really ran with, as its tool reported it (see AdapterResult.model). */
7
+ export interface RunUsed {
8
+ model?: string;
9
+ effort?: string;
10
+ }
6
11
  export type MessageKind = 'question' | 'answer' | 'decision_request' | 'decision' | 'progress' | 'result' | 'note';
7
12
  export interface Agent {
8
13
  id: string;
@@ -215,6 +220,19 @@ export interface MentionItem {
215
220
  thread: Post;
216
221
  channel_name: string;
217
222
  }
223
+ /** How a mention run went, as the runner tells the hub when it ends it (all optional: an older hub ignores it). */
224
+ export interface MentionOutcome {
225
+ ok?: boolean;
226
+ error?: string;
227
+ /** the agent's last message: its answer when it wrote one but never posted it */
228
+ text?: string;
229
+ /** the last commands that failed: name, what was run, what it printed */
230
+ errors?: {
231
+ name: string;
232
+ input: string;
233
+ output: string;
234
+ }[];
235
+ }
218
236
  export interface MentionRun extends MentionItem {
219
237
  replies: Post[];
220
238
  recent: Post[];
@@ -411,7 +429,8 @@ export declare class Client {
411
429
  cancel(taskId: string, reason: string): Promise<any>;
412
430
  /** The total size of a work prompt (Memory trial metrics). */
413
431
  promptSize(taskId: string, run_id: string, chars: number, parts?: Record<string, number>): Promise<any>;
414
- usage(taskId: string, run_id: string, cost_usd: number, estimated: boolean): Promise<any>;
432
+ /** `used`: the model and the effort the run really ran with, when the tool said (the panel shows them on the run). */
433
+ usage(taskId: string, run_id: string, cost_usd: number, estimated: boolean, used?: RunUsed): Promise<any>;
415
434
  /**
416
435
  * design §27: what keeps this agent's runner from taking tasks on its machine (null: nothing). The hub shows it as
417
436
  * "needs setup" with the fix.
@@ -485,8 +504,9 @@ export declare class Client {
485
504
  }>;
486
505
  /** Take an @mention: a read-only "mention" run token for its thread. */
487
506
  mentionRun(mentionId: string, run_id: string): Promise<MentionRun>;
488
- mentionEnd(mentionId: string, run_id: string): Promise<any>;
489
- mentionUsage(mentionId: string, run_id: string, cost_usd: number, estimated: boolean): Promise<any>;
507
+ /** The run is over. `outcome` is how it went: the hub says so in the thread when the agent posted nothing there. */
508
+ mentionEnd(mentionId: string, run_id: string, outcome?: MentionOutcome): Promise<any>;
509
+ mentionUsage(mentionId: string, run_id: string, cost_usd: number, estimated: boolean, used?: RunUsed): Promise<any>;
490
510
  agentProfile(name: string): Promise<any>;
491
511
  /** `ach remember`: a fact or lesson with its source (hub permalink or GitHub URL); toTeam promotes it to the team overview. */
492
512
  remember(text: string, source: string, o?: {
@@ -7,6 +7,7 @@ export const TERMINAL = ['completed', 'failed', 'canceled'];
7
7
  export function isTerminal(s) {
8
8
  return !!s && TERMINAL.includes(s);
9
9
  }
10
+ const usedBody = (u) => ({ ...(u?.model ? { model: u.model } : {}), ...(u?.effort ? { effort: u.effort } : {}) });
10
11
  /** Parse `name` or `name@base` (CLI `--read-repo`). */
11
12
  export function parseLinkRepo(v) {
12
13
  const i = v.indexOf('@');
@@ -349,8 +350,9 @@ export class Client {
349
350
  async promptSize(taskId, run_id, chars, parts = {}) {
350
351
  return this.ach('POST', '/memory/prompt-size', { task: taskId, run_id, chars, parts });
351
352
  }
352
- async usage(taskId, run_id, cost_usd, estimated) {
353
- return this.ach('POST', `/tasks/${enc(taskId)}/usage`, { run_id, cost_usd, estimated });
353
+ /** `used`: the model and the effort the run really ran with, when the tool said (the panel shows them on the run). */
354
+ async usage(taskId, run_id, cost_usd, estimated, used) {
355
+ return this.ach('POST', `/tasks/${enc(taskId)}/usage`, { run_id, cost_usd, estimated, ...usedBody(used) });
354
356
  }
355
357
  /**
356
358
  * design §27: what keeps this agent's runner from taking tasks on its machine (null: nothing). The hub shows it as
@@ -449,11 +451,12 @@ export class Client {
449
451
  async mentionRun(mentionId, run_id) {
450
452
  return this.ach('POST', `/mentions/${enc(mentionId)}/run`, { run_id });
451
453
  }
452
- async mentionEnd(mentionId, run_id) {
453
- return this.ach('POST', `/mentions/${enc(mentionId)}/end`, { run_id });
454
+ /** The run is over. `outcome` is how it went: the hub says so in the thread when the agent posted nothing there. */
455
+ async mentionEnd(mentionId, run_id, outcome = {}) {
456
+ return this.ach('POST', `/mentions/${enc(mentionId)}/end`, { run_id, ...outcome });
454
457
  }
455
- async mentionUsage(mentionId, run_id, cost_usd, estimated) {
456
- return this.ach('POST', `/mentions/${enc(mentionId)}/usage`, { run_id, cost_usd, estimated });
458
+ async mentionUsage(mentionId, run_id, cost_usd, estimated, used) {
459
+ return this.ach('POST', `/mentions/${enc(mentionId)}/usage`, { run_id, cost_usd, estimated, ...usedBody(used) });
457
460
  }
458
461
  async agentProfile(name) {
459
462
  return this.ach('GET', `/profiles/agents/${enc(name)}`);
@@ -1,8 +1,9 @@
1
- import type { RuntimeAdapter } from '../adapters/types.js';
2
- import { type Agent, type Client, type MentionItem, type Message } from '../client.js';
1
+ import type { AdapterResult, RuntimeAdapter } from '../adapters/types.js';
2
+ import { type Agent, type Client, type MentionItem, type MentionOutcome, type Message } from '../client.js';
3
3
  import { type Perm } from '../perm.js';
4
4
  import { RunnerState } from './state.js';
5
5
  import type { Workspace } from './workspace.js';
6
+ import { TraceRecorder } from '../trace.js';
6
7
  import { type SandboxStatus } from '../sandboxcheck.js';
7
8
  export type RunnerClient = Pick<Client, 'me' | 'inbox' | 'claim' | 'getTask' | 'postMessage' | 'complete' | 'fail' | 'usage' | 'heartbeat' | 'answerRun' | 'endRun'> & Partial<Pick<Client, 'download' | 'channelPosts' | 'mentionRun' | 'mentionEnd' | 'mentionUsage' | 'promptSize' | 'reportSetup' | 'reportRepos' | 'reportRunner' | 'release' | 'putTrace'>>;
8
9
  export interface RunnerOptions {
@@ -92,6 +93,8 @@ export type Job = {
92
93
  item: MentionItem;
93
94
  };
94
95
  export declare function jobKey(j: Job): string;
96
+ /** What the hub is told about a mention run that ended: whether it worked, why not, its last words, the commands that failed. */
97
+ export declare function mentionOutcome(result: AdapterResult, reason: Active['reason'], recorder?: TraceRecorder, secrets?: readonly string[]): MentionOutcome;
95
98
  interface Active {
96
99
  job: Job;
97
100
  controller: AbortController;
@@ -20,6 +20,21 @@ export function jobKey(j) {
20
20
  return `mention:${j.item.mention.id}`;
21
21
  return j.kind === 'answer' ? `answer:${j.question.id}` : `task:${j.taskId}`;
22
22
  }
23
+ /** What the hub is told about a mention run that ended: whether it worked, why not, its last words, the commands that failed. */
24
+ export function mentionOutcome(result, reason, recorder, secrets = []) {
25
+ const errors = (recorder?.finish().steps ?? [])
26
+ .filter((s) => s.kind === 'tool' && s.is_error)
27
+ .slice(-3)
28
+ .map((s) => ({ name: s.name ?? 'tool', input: s.input ?? '', output: s.output ?? '' }));
29
+ const error = redact(reason ? `the run was stopped (${reason})` : result.error ?? '', secrets);
30
+ const text = redact(result.finalText ?? '', secrets);
31
+ return {
32
+ ok: !!result.ok && !reason,
33
+ ...(error ? { error: error.slice(0, 400) } : {}),
34
+ ...(text ? { text: text.slice(0, 6000) } : {}),
35
+ ...(errors.length ? { errors } : {}),
36
+ };
37
+ }
23
38
  const TOKEN_REFRESH_MS = 20 * 3600_000;
24
39
  const PRUNE_EVERY_MS = 10 * 60_000;
25
40
  /** A gate decision that lets the run go ahead (S1). Anything else rejects. */
@@ -1097,6 +1112,9 @@ export class Runner {
1097
1112
  const threadId = run.thread.id;
1098
1113
  const rec = { taskId: key, runId, phase: 'running', workdir: this.o.dir, runToken: run.run_token, tokenAt: Date.now(), seen: [] };
1099
1114
  const structured = !!this.o.adapter.structuredAnswers;
1115
+ // how it went, told to the hub when the mention is closed: a run that ends with nothing said in the thread is made visible there
1116
+ let outcome = { ok: false, error: 'the run did not finish' };
1117
+ let recorded;
1100
1118
  try {
1101
1119
  const prompt = buildMentionPrompt({
1102
1120
  agentName: me.name,
@@ -1112,14 +1130,20 @@ export class Runner {
1112
1130
  });
1113
1131
  const result = await this.execute(rec, entry, prompt, undefined, 'mention', structured ? ANSWER_SCHEMA : undefined, {
1114
1132
  threadId,
1115
- usage: (cost, est) => client.mentionUsage(mid, runId, cost, est),
1133
+ usage: (cost, est, used) => client.mentionUsage(mid, runId, cost, est, used),
1134
+ recorder: (r) => { recorded = r; },
1116
1135
  });
1136
+ outcome = mentionOutcome(result, entry.reason, recorded, [rec.runToken, ...(this.o.secrets ?? []), this.o.cfSecret ?? ''].filter(Boolean));
1117
1137
  if (structured && result.ok && !entry.reason)
1118
1138
  await this.postStructuredReply(threadId, run.run_token, result.finalText, key);
1119
1139
  }
1140
+ catch (e) {
1141
+ outcome = { ok: false, error: String(e?.message ?? e).slice(0, 400) };
1142
+ throw e;
1143
+ }
1120
1144
  finally {
1121
1145
  if (!this.fatal)
1122
- await client.mentionEnd?.(mid, runId).catch((e) => this.log(`mention-end ${mid}: ${e?.message ?? e}`));
1146
+ await client.mentionEnd?.(mid, runId, outcome).catch((e) => this.log(`mention-end ${mid}: ${e?.message ?? e}`));
1123
1147
  }
1124
1148
  }
1125
1149
  /** Codex mention runs: the runner posts the reply the agent returned. */
@@ -1280,6 +1304,7 @@ export class Runner {
1280
1304
  // the values of the variables handed through (--pass-env) are secrets too: masked wherever a tool prints them
1281
1305
  const passed = (this.o.passEnv ?? []).map((n) => process.env[n] ?? '').filter((v) => v.length >= 8);
1282
1306
  const recorder = new TraceRecorder([rec.runToken, ...(this.o.secrets ?? []), this.o.cfSecret ?? '', ...passed].filter(Boolean));
1307
+ extra.recorder?.(recorder);
1283
1308
  let hb;
1284
1309
  hb =
1285
1310
  mode === 'work'
@@ -1366,10 +1391,11 @@ export class Runner {
1366
1391
  this.state.setSession(taskId, mode, { id: result.sessionId, cwd: rec.workdir, ...(result.costCumulative && result.costUsd !== undefined ? { costTotal: Number(result.costUsd) } : {}) });
1367
1392
  }
1368
1393
  // §14.7: usage after every adapter run, success or failure.
1369
- const usage = extra.usage ?? ((cost, est) => client.usage(taskId, rec.runId, cost, est));
1394
+ // with the model and the effort the run really ran with: the panel shows them on the run, so nobody has to guess
1395
+ const usage = extra.usage ?? ((cost, est, used) => client.usage(taskId, rec.runId, cost, est, used));
1370
1396
  if (!this.fatal)
1371
- await usage(runCost, !!result.estimated).catch((e) => this.log(`usage ${taskId}: ${e?.message ?? e}`));
1372
- this.taskLog(taskId, `${mode} run end ok=${result.ok} cost=${result.costUsd ?? 0} err=${result.error ?? ''}`);
1397
+ await usage(runCost, !!result.estimated, { model: result.model, effort: result.effort }).catch((e) => this.log(`usage ${taskId}: ${e?.message ?? e}`));
1398
+ this.taskLog(taskId, `${mode} run end ok=${result.ok} cost=${result.costUsd ?? 0} model=${result.model ?? '?'} effort=${result.effort ?? '?'} err=${result.error ?? ''}`);
1373
1399
  if (mode !== 'mention')
1374
1400
  await this.uploadTrace(taskId, rec.runId, mode, startedAt, result, recorder, !this.fatal);
1375
1401
  return result;
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.30.3";
1
+ export declare const VERSION = "3.32.0";
2
2
  /** The npm package (scripts/release.mjs keeps it and VERSION in step with package.json). */
3
3
  export declare const PKG_NAME = "@koalaauto/agentchannel";
4
4
  /**
@@ -1,4 +1,4 @@
1
- export const VERSION = '3.30.3';
1
+ export const VERSION = '3.32.0';
2
2
  /** The npm package (scripts/release.mjs keeps it and VERSION in step with package.json). */
3
3
  export const PKG_NAME = '@koalaauto/agentchannel';
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalaauto/agentchannel",
3
- "version": "3.30.3",
3
+ "version": "3.32.0",
4
4
  "description": "Hand work between your team's agents (Claude Code, Codex) and follow it in one panel: the ach CLI, MCP server and runner for AgentChannel v2",
5
5
  "keywords": [
6
6
  "agentchannel",