@koalaauto/agentchannel 3.51.0 → 3.52.1

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.
@@ -65,6 +65,8 @@ export declare class KiroOutput {
65
65
  finalText(): string;
66
66
  private flushMessage;
67
67
  private flushThought;
68
+ /** What a runError event said: the reason the run failed. */
69
+ runError?: string;
68
70
  private setSession;
69
71
  private line;
70
72
  }
@@ -85,7 +87,7 @@ export declare class KiroAdapter implements RuntimeAdapter {
85
87
  readonly remote = true;
86
88
  constructor(o?: KiroAdapterOptions);
87
89
  run(opts: AdapterRunOptions): Promise<AdapterResult>;
88
- /** `kiro-cli chat --list-models --format json`: the models this key may use, their credit rate, and default_model. */
90
+ /** the models this key may use, their credit rate, the effort levels each takes and the default: from an ACP session (`kiro-cli acp`), else `kiro-cli chat --list-models --format json`. */
89
91
  listModels(o: {
90
92
  env: Record<string, string>;
91
93
  cwd: string;
@@ -1,6 +1,6 @@
1
1
  import { execFileSync } from 'node:child_process';
2
2
  import { spawnGroup } from './procgroup.js';
3
- import { ask, kiroModels } from './models.js';
3
+ import { ask, KIRO_ACP_INPUT, kiroAcpModels, kiroModels } from './models.js';
4
4
  import { modelId } from './types.js';
5
5
  /**
6
6
  * Kiro runtime: each run is a Kiro cloud session started headlessly with
@@ -140,6 +140,8 @@ export class KiroOutput {
140
140
  this.onEvent({ type: 'thinking', data: this.thought });
141
141
  this.thought = '';
142
142
  }
143
+ /** What a runError event said: the reason the run failed. */
144
+ runError;
143
145
  setSession(id) {
144
146
  if (typeof id !== 'string' || !id || id === this.sessionId)
145
147
  return;
@@ -203,6 +205,17 @@ export class KiroOutput {
203
205
  else
204
206
  this.onEvent({ type: 'tool', data: { type: kind } });
205
207
  break;
208
+ case 'config_option_update':
209
+ // the options kiro offers for this session (model, effort levels): kept in the trace so the levels each model takes can be read
210
+ this.onEvent({ type: 'tool', data: { type: kind, options: JSON.stringify(u.configOptions ?? u.options ?? u).slice(0, 1500) } });
211
+ break;
212
+ case 'runError': {
213
+ // the run itself failed: keep what kiro says, it is the reason (stderr only carries warnings)
214
+ const m = p.error ?? p.message ?? p.reason ?? p.data ?? p;
215
+ this.runError = (typeof m === 'string' ? m : (m?.message ?? JSON.stringify(m))).slice(0, 600);
216
+ this.onEvent({ type: 'error', data: `kiro run error: ${this.runError}` });
217
+ break;
218
+ }
206
219
  case 'tool_call_update':
207
220
  if (u.status === 'completed' || u.status === 'failed') {
208
221
  this.onEvent({ type: 'tool_end', data: { id: String(u.toolCallId ?? u.id ?? ''), is_error: u.status === 'failed', output: contentText(u.content) || (u.rawOutput ? JSON.stringify(u.rawOutput) : '') } });
@@ -273,7 +286,7 @@ export class KiroAdapter {
273
286
  }
274
287
  return first.result;
275
288
  }
276
- /** `kiro-cli chat --list-models --format json`: the models this key may use, their credit rate, and default_model. */
289
+ /** the models this key may use, their credit rate, the effort levels each takes and the default: from an ACP session (`kiro-cli acp`), else `kiro-cli chat --list-models --format json`. */
277
290
  async listModels(o) {
278
291
  const env = this.o.env ?? process.env;
279
292
  const bin = this.o.bin ?? env.ACH_KIRO_BIN ?? 'kiro-cli';
@@ -285,7 +298,14 @@ export class KiroAdapter {
285
298
  return undefined; // not all of it yet
286
299
  }
287
300
  };
288
- return ask(bin, ['chat', '--list-models', '--format', 'json'], kiroEnv(o.env, { realHome: o.realHome, apiKey: this.o.apiKey ?? env.KIRO_API_KEY }), { cwd: o.cwd, timeoutMs: 30_000, done });
301
+ const kenv = kiroEnv(o.env, { realHome: o.realHome, apiKey: this.o.apiKey ?? env.KIRO_API_KEY });
302
+ // an ACP session lists the effort levels each model takes; --list-models does not: asked second, for the models alone
303
+ try {
304
+ return await ask(bin, ['acp'], kenv, { cwd: o.cwd, timeoutMs: 30_000, input: KIRO_ACP_INPUT, done: kiroAcpModels });
305
+ }
306
+ catch {
307
+ return ask(bin, ['chat', '--list-models', '--format', 'json'], kenv, { cwd: o.cwd, timeoutMs: 30_000, done });
308
+ }
289
309
  }
290
310
  runOnce(opts, repo, format) {
291
311
  const env = this.o.env ?? process.env;
@@ -325,8 +345,8 @@ export class KiroAdapter {
325
345
  done = true;
326
346
  out.end();
327
347
  const finalText = out.finalText();
328
- const ok = !err && code === 0 && !opts.signal.aborted;
329
- const error = ok ? undefined : opts.signal.aborted ? 'aborted' : err ?? (stripAnsi(stderr).trim().split('\n').slice(-3).join(' ') || `kiro-cli exited ${code}`);
348
+ const ok = !err && code === 0 && !out.runError && !opts.signal.aborted;
349
+ const error = ok ? undefined : opts.signal.aborted ? 'aborted' : err ?? (out.runError ? `kiro run error: ${out.runError}` : stripAnsi(stderr).split('\n').map((l) => l.trim()).filter((l) => l && !/^\[warn\]/.test(l)).slice(-3).join(' ') || `kiro-cli exited ${code}${out.runError === undefined ? ' without saying why' : ''}`);
330
350
  // Kiro bills credits, not dollars, and the CLI does not print them (2.37.1): the cost stays unknown, never guessed.
331
351
  resolve({ result: { finalText, sessionId: out.sessionId, ok, error, estimated: true, ...(modelId((opts.model ?? this.o.model)) ? { model: (opts.model ?? this.o.model) } : {}) }, progressed });
332
352
  };
@@ -22,6 +22,13 @@ export declare function claudeModels(raw: unknown): RuntimeModels;
22
22
  export declare function codexModels(raw: unknown): RuntimeModels;
23
23
  /** `kiro-cli chat --list-models --format json`: {models: [{model_id, description, rate_multiplier}], default_model}. Pure. */
24
24
  export declare function kiroModels(raw: unknown): RuntimeModels;
25
+ /** The JSON-RPC lines that open an ACP session in `kiro-cli acp` (no prompt is sent, nothing is spent): its answer lists the models. */
26
+ export declare const KIRO_ACP_INPUT: string;
27
+ /**
28
+ * The session/new answer among `kiro-cli acp` output lines, once it is there: its "model" config option lists each model with
29
+ * the effort levels it takes (_meta.kiro.effortLevels; none for Auto), its credit rate and the model the session starts on. Pure.
30
+ */
31
+ export declare function kiroAcpModels(out: string): RuntimeModels | undefined;
25
32
  /** Run `cmd args`, feed it `input`, and resolve with what `done` makes of its stdout so far (or reject on timeout / exit). */
26
33
  export declare function ask<T>(cmd: string, args: string[], env: Record<string, string>, o: {
27
34
  input?: string;
@@ -51,6 +51,42 @@ export function kiroModels(raw) {
51
51
  models: list(xs.map((x) => entry(x?.model_id, { label: x?.model_name !== x?.model_id ? x?.model_name : undefined, description: x?.description, rate: x?.rate_multiplier }))),
52
52
  };
53
53
  }
54
+ /** The JSON-RPC lines that open an ACP session in `kiro-cli acp` (no prompt is sent, nothing is spent): its answer lists the models. */
55
+ export const KIRO_ACP_INPUT = [
56
+ { jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: 1, clientCapabilities: {} } },
57
+ { jsonrpc: '2.0', id: 2, method: 'session/new', params: { cwd: '/tmp', mcpServers: [] } },
58
+ ].map((x) => JSON.stringify(x)).join('\n') + '\n';
59
+ /**
60
+ * The session/new answer among `kiro-cli acp` output lines, once it is there: its "model" config option lists each model with
61
+ * the effort levels it takes (_meta.kiro.effortLevels; none for Auto), its credit rate and the model the session starts on. Pure.
62
+ */
63
+ export function kiroAcpModels(out) {
64
+ for (const line of out.split('\n')) {
65
+ if (!line.startsWith('{'))
66
+ continue;
67
+ let j;
68
+ try {
69
+ j = JSON.parse(line);
70
+ }
71
+ catch {
72
+ continue;
73
+ }
74
+ if (j?.id !== 2)
75
+ continue;
76
+ if (j.error)
77
+ throw new Error(`kiro-cli acp: ${String(j.error?.message ?? 'session/new failed').slice(0, 200)}`);
78
+ const opt = (Array.isArray(j.result?.configOptions) ? j.result.configOptions : []).find((c) => c?.id === 'model');
79
+ const xs = Array.isArray(opt?.options) ? opt.options : [];
80
+ return {
81
+ ...(modelId(opt?.currentValue) ? { default: opt.currentValue } : {}),
82
+ models: list(xs.map((x) => {
83
+ const k = x?._meta?.kiro;
84
+ return entry(x?.value, { label: x?.name !== x?.value ? x?.name : undefined, description: x?.description, efforts: k?.hasEffort === false ? undefined : k?.effortLevels, rate: k?.rateMultiplier });
85
+ })),
86
+ };
87
+ }
88
+ return undefined;
89
+ }
54
90
  /** Run `cmd args`, feed it `input`, and resolve with what `done` makes of its stdout so far (or reject on timeout / exit). */
55
91
  export function ask(cmd, args, env, o) {
56
92
  return new Promise((resolve, reject) => {
@@ -30,6 +30,8 @@ export interface Agent {
30
30
  name: string;
31
31
  owner?: string;
32
32
  owner_name?: string;
33
+ /** The hub's default language: what the agent writes for people (ACH_DEFAULT_LANG). Only on an agent's own /me. */
34
+ lang?: 'en' | 'zh';
33
35
  /** Who it belongs to (docs/mechanisms.md): a person (personal) or the team (team: no one person, the admins look after it). */
34
36
  kind?: 'personal' | 'team';
35
37
  /** system: the team's one system agent (a team agent that does the hub's own work). */
@@ -111,12 +111,12 @@ export function accountProblem(s) {
111
111
  export function effortRejected(s) {
112
112
  if (!s)
113
113
  return false;
114
- return /\b(reasoning[ _.]?)?effort\b[^\n]{0,80}\b(invalid|not supported|unsupported|unknown|must be one of|is not (a )?valid|not allowed)|\b(invalid|unsupported|unknown) (value for )?(reasoning[ _.]?)?effort/i.test(s);
114
+ return /\b(reasoning[ _.]?)?effort\b[^\n]{0,80}\b(invalid|not supported|unsupported|unknown|must be one of|is not (a )?valid|not allowed)|\bno (reasoning[ _.]?)?effort levels\b|\b(invalid|unsupported|unknown) (value for )?(reasoning[ _.]?)?effort/i.test(s);
115
115
  }
116
116
  export function modelRejected(s) {
117
117
  if (!s)
118
118
  return false;
119
- return /issue with the selected model|\bmodel\b[^\n]{0,80}\b(does not exist|not found|not available|not supported|is not (a )?valid|unknown|invalid|you do not have access)|\b(invalid|unknown|unsupported) model\b|not_found_error[^\n]{0,40}model/i.test(s);
119
+ return /issue with the selected model|failed to set model|\bmodel\b[^\n]{0,80}\b(does not exist|not found|not available|not supported|is not (a )?valid|unknown|invalid|you do not have access)|\b(invalid|unknown|unsupported) model\b|not_found_error[^\n]{0,40}model/i.test(s);
120
120
  }
121
121
  /** Does a run's error say the tool is not logged in (or its key was refused)? */
122
122
  export function looksLikeLoginError(s) {
@@ -38,7 +38,11 @@ export interface PromptCtx {
38
38
  }[];
39
39
  /** The layers people add to the default judgment: the team's conventions, then the owner's own. */
40
40
  judgment?: Judgment;
41
+ /** The hub's default language: what people read (replies, posts, results) is written in it. */
42
+ lang?: 'en' | 'zh';
41
43
  }
44
+ /** Trusted: the language the people on this hub read; the instructions around it stay English. Nothing for a hub that sends none. */
45
+ export declare function langText(lang?: 'en' | 'zh'): string[];
42
46
  /**
43
47
  * Trusted: the team's conventions (admins; they only tighten the default) and the owner's own (for all their agents), in that
44
48
  * order, each with who wrote it and when.
@@ -214,4 +218,5 @@ export declare function buildMentionPrompt(c: {
214
218
  recent: Post[];
215
219
  threadUrl?: string;
216
220
  structured?: boolean;
221
+ lang?: 'en' | 'zh';
217
222
  }): string;
@@ -1,4 +1,11 @@
1
1
  import { wikiPromptParts } from './wiki.js';
2
+ /** Trusted: the language the people on this hub read; the instructions around it stay English. Nothing for a hub that sends none. */
3
+ export function langText(lang) {
4
+ if (!lang)
5
+ return [];
6
+ const name = lang === 'zh' ? 'Chinese (简体中文)' : 'English';
7
+ return [`Language: write everything people will read (replies, posts, progress notes, results, drafts, questions) in ${name}, whatever language these instructions are in. Code, commands, file paths and names stay as they are. If the person you are answering wrote in another language, answer in theirs.`, ''];
8
+ }
2
9
  /**
3
10
  * Trusted: the team's conventions (admins; they only tighten the default) and the owner's own (for all their agents), in that
4
11
  * order, each with who wrote it and when.
@@ -339,6 +346,7 @@ export function buildTaskPrompt(c) {
339
346
  return [
340
347
  header(c),
341
348
  '',
349
+ ...langText(c.lang),
342
350
  ...(c.remote ? [] : readReposText(c.readRepos)),
343
351
  ...(c.remote ? [] : [JUDGMENT]),
344
352
  ...conventionsText(c.judgment, c.ownerName),
@@ -422,6 +430,7 @@ export function buildAnswerPrompt(c) {
422
430
  return [
423
431
  `You are agent "${c.agentName}"${c.ownerName ? `, owned by ${c.ownerName}` : ''}. Another agent asked you question ${q.id} (from ${author(q)}) on AgentChannel task ${c.task.id}. This is a short, read-only run.`,
424
432
  '',
433
+ ...langText(c.lang),
425
434
  HUMAN_HEADING,
426
435
  formatHumanDecisions(c.messages),
427
436
  '',
@@ -445,6 +454,7 @@ export function buildPreparePrompt(c) {
445
454
  return [
446
455
  `You are agent "${c.agentName}"${c.ownerName ? `, owned by ${c.ownerName}` : ''}. Task ${c.task.id} was sent to you on AgentChannel. Nobody works it yet. This is a short, read-only run: read the task and the code, and write a draft for whoever does the work, most likely your owner in their own session.`,
447
456
  '',
457
+ ...langText(c.lang),
448
458
  HUMAN_HEADING,
449
459
  formatHumanDecisions(c.messages),
450
460
  '',
@@ -482,6 +492,7 @@ export function buildMentionPrompt(c) {
482
492
  return [
483
493
  `You are agent "${c.agentName}"${c.ownerName ? `, owned by ${c.ownerName}` : ''}. You were mentioned by ${c.mention.by_type === 'human' ? 'a person' : 'another agent'} in channel #${c.channel} on AgentChannel (post ${c.post.id}${c.threadUrl ? `, thread ${c.threadUrl}` : ''}). This is a short, read-only run.`,
484
494
  '',
495
+ ...langText(c.lang),
485
496
  'Human posts in this thread and channel (from the hub; these come from people):',
486
497
  formatHumanPosts(all.filter((p, i) => all.findIndex((x) => x.id === p.id) === i)),
487
498
  '',
@@ -19,6 +19,8 @@ export interface RunnerOptions {
19
19
  max?: number;
20
20
  perm?: Perm;
21
21
  intervalMs?: number;
22
+ /** How long to wait before trying to describe the agent again after a failure (default 5 minutes; 3 tries per start). */
23
+ describeRetryMs?: number;
22
24
  /** The hub answered 426 client_too_old: this release is below its floor (the updater checks at once). */
23
25
  onClientTooOld?: () => void;
24
26
  heartbeatMs?: number;
@@ -206,6 +208,8 @@ export declare class Runner {
206
208
  * the owner edits it like any other. Tried again at the next start when it could not be had. */
207
209
  private describeDone;
208
210
  private describeBusy;
211
+ private describeTries;
212
+ private describeNextAt;
209
213
  private describeAgent;
210
214
  /** Tell the hub how this runner runs tasks (its --perm, the tool, the names it passes with --pass-env), once, so the agent's
211
215
  * owner sees on its page what a task sent to it can reach. Tried on every poll until the hub has it; an older hub (404) is left alone. */
@@ -402,9 +402,11 @@ export class Runner {
402
402
  * the owner edits it like any other. Tried again at the next start when it could not be had. */
403
403
  describeDone = false;
404
404
  describeBusy = false;
405
+ describeTries = 0;
406
+ describeNextAt = 0;
405
407
  async describeAgent() {
406
408
  const { adapter, client, workspace } = this.o;
407
- if (this.describeDone || this.describeBusy || adapter.remote || !client.reportDescription || !workspace.repoDirs)
409
+ if (this.describeDone || this.describeBusy || Date.now() < this.describeNextAt || adapter.remote || !client.reportDescription || !workspace.repoDirs)
408
410
  return;
409
411
  this.describeBusy = true;
410
412
  try {
@@ -459,10 +461,18 @@ export class Runner {
459
461
  this.log(`description: ${text.slice(0, 120)}`);
460
462
  }
461
463
  catch (e) {
462
- // once per start, whatever the outcome; an older hub without /me/description (404) says nothing
463
- if (!(e instanceof HubError && e.status === 404))
464
- this.log(`description: ${String(e?.message ?? e).slice(0, 200)} (trying again at the next start)`);
465
- this.describeDone = true;
464
+ // an older hub without /me/description (404) says nothing and is left alone; any other failure (a hub or network that was not
465
+ // reachable while many runners restarted at once, a model that said nothing) is tried again, three times in all per start
466
+ if (e instanceof HubError && e.status === 404)
467
+ this.describeDone = true;
468
+ else if (++this.describeTries >= 3) {
469
+ this.describeDone = true;
470
+ this.log(`description: ${String(e?.message ?? e).slice(0, 200)} (gave up until the next start)`);
471
+ }
472
+ else {
473
+ this.describeNextAt = Date.now() + (this.o.describeRetryMs ?? 5 * 60_000);
474
+ this.log(`description: ${String(e?.message ?? e).slice(0, 200)} (trying again in ${Math.round((this.o.describeRetryMs ?? 5 * 60_000) / 60_000)} min)`);
475
+ }
466
476
  }
467
477
  finally {
468
478
  this.describeBusy = false;
@@ -841,6 +851,7 @@ export class Runner {
841
851
  const prompt = buildPreparePrompt({
842
852
  agentName: me.name,
843
853
  ownerName: me.owner_name,
854
+ lang: me.lang,
844
855
  senderName: bundle.task.from_agent_name,
845
856
  task: bundle.task,
846
857
  handoff: bundle.handoff,
@@ -957,6 +968,7 @@ export class Runner {
957
968
  const prompt = buildTaskPrompt({
958
969
  agentName: me.name,
959
970
  ownerName: me.owner_name,
971
+ lang: me.lang,
960
972
  kind: me.kind, role: me.role,
961
973
  senderName: claim.task.from_agent_name,
962
974
  task: claim.task,
@@ -1057,6 +1069,7 @@ export class Runner {
1057
1069
  : buildTaskPrompt({
1058
1070
  agentName: me.name,
1059
1071
  ownerName: me.owner_name,
1072
+ lang: me.lang,
1060
1073
  kind: me.kind, role: me.role,
1061
1074
  senderName: bundle.task.from_agent_name,
1062
1075
  task: bundle.task,
@@ -1362,6 +1375,7 @@ export class Runner {
1362
1375
  const prompt = buildMentionPrompt({
1363
1376
  agentName: me.name,
1364
1377
  ownerName: me.owner_name,
1378
+ lang: me.lang,
1365
1379
  channel: run.channel_name,
1366
1380
  mention: run.mention,
1367
1381
  post: run.post,
@@ -1442,6 +1456,7 @@ export class Runner {
1442
1456
  const prompt = buildAnswerPrompt({
1443
1457
  agentName: me.name,
1444
1458
  ownerName: me.owner_name,
1459
+ lang: me.lang,
1445
1460
  task: bundle.task,
1446
1461
  handoff: bundle.handoff,
1447
1462
  messages: bundle.messages,
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.51.0";
1
+ export declare const VERSION = "3.52.1";
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.51.0';
1
+ export const VERSION = '3.52.1';
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.51.0",
3
+ "version": "3.52.1",
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",