@koalaauto/agentchannel 3.22.0 → 3.24.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.
@@ -8,7 +8,7 @@ import { Client as HubClient, HubError, isTerminal } from '../client.js';
8
8
  import { taskFiles } from '../attachments.js';
9
9
  import { buildAgentEnv } from '../env.js';
10
10
  import { effectivePerm } from '../perm.js';
11
- import { ANSWER_SCHEMA, buildAnswerPrompt, buildMentionPrompt, buildResumePrompt, buildTaskPrompt, postUrl, refOf, taskUrl } from '../prompts.js';
11
+ import { ANSWER_SCHEMA, buildAnswerPrompt, buildMentionPrompt, buildResumePrompt, buildTaskPrompt, postUrl, refOf, REMOTE_FAILED_PREFIX, taskUrl } from '../prompts.js';
12
12
  import { RunnerState } from './state.js';
13
13
  import { looksLikeLoginError, summarizeRuntimeError } from '../envcheck.js';
14
14
  import { redact } from '../redact.js';
@@ -668,6 +668,7 @@ export class Runner {
668
668
  files: files.map(promptFile),
669
669
  channel: await this.channelContext(claim.task),
670
670
  wiki: claim.wiki,
671
+ remote: !!this.o.adapter.remote,
671
672
  });
672
673
  this.reportPromptSize(taskId, rec.runId, prompt);
673
674
  const sess = this.state.session(taskId, 'work');
@@ -750,6 +751,7 @@ export class Runner {
750
751
  handoffChanged,
751
752
  files: files.filter((f) => !shown.has(f.key)).map(promptFile),
752
753
  nudge,
754
+ remote: !!this.o.adapter.remote,
753
755
  })
754
756
  : buildTaskPrompt({
755
757
  agentName: me.name,
@@ -763,6 +765,7 @@ export class Runner {
763
765
  files: files.map(promptFile),
764
766
  channel: await this.channelContext(bundle.task),
765
767
  wiki: bundle.wiki,
768
+ remote: !!this.o.adapter.remote,
766
769
  });
767
770
  if (!resume)
768
771
  this.reportPromptSize(taskId, rec.runId, prompt);
@@ -867,6 +870,12 @@ export class Runner {
867
870
  this.state.drop(taskId);
868
871
  return;
869
872
  }
873
+ // A remote (cloud sandbox) agent has no `ach`: its final message is the result, reported here.
874
+ if (this.o.adapter.remote && task.status === 'working') {
875
+ await this.reportRemote(rec, result);
876
+ this.state.drop(taskId);
877
+ return;
878
+ }
870
879
  if (task.status === 'working') {
871
880
  // The agent stopped without `ach complete`, `ach fail` or a question. That
872
881
  // is not a finished task: ask it once to finish properly; if it stops
@@ -888,6 +897,26 @@ export class Runner {
888
897
  }
889
898
  this.state.drop(taskId);
890
899
  }
900
+ /** Complete the task with a remote run's final message, or fail it when the message starts with FAILED:. */
901
+ async reportRemote(rec, result) {
902
+ const { client } = this.o;
903
+ const taskId = rec.taskId;
904
+ const text = result.finalText.trim();
905
+ const where = result.sessionId ? `\n\n(${this.o.adapter.name} session ${result.sessionId})` : '';
906
+ if (!text) {
907
+ await client.fail(taskId, `the ${this.o.adapter.name} run ended without a final message${where}`, rec.runId).catch((e) => this.log(`fail ${taskId}: ${e?.message ?? e}`));
908
+ this.taskLog(taskId, 'failed: remote run ended without a final message');
909
+ return;
910
+ }
911
+ if (text.toUpperCase().startsWith(REMOTE_FAILED_PREFIX)) {
912
+ const reason = text.slice(REMOTE_FAILED_PREFIX.length).trim() || 'the agent could not do it';
913
+ await client.fail(taskId, `${reason}${where}`.slice(0, 8000), rec.runId).catch((e) => this.log(`fail ${taskId}: ${e?.message ?? e}`));
914
+ this.taskLog(taskId, 'failed: the remote agent reported FAILED');
915
+ return;
916
+ }
917
+ await client.complete(taskId, `${text}${where}`.slice(0, 20000), rec.runId, undefined, rec.handoffVersion).catch((e) => this.log(`complete ${taskId}: ${e?.message ?? e}`));
918
+ this.taskLog(taskId, 'completed with the remote run\'s final message');
919
+ }
891
920
  /** Base URL for links shown to agents (§19). */
892
921
  base() {
893
922
  return this.o.publicUrl || this.o.hub;
@@ -969,7 +998,7 @@ export class Runner {
969
998
  async postStructuredReply(threadId, token, text, logKey) {
970
999
  let out;
971
1000
  try {
972
- out = JSON.parse(text.trim());
1001
+ out = parseStructured(text);
973
1002
  }
974
1003
  catch {
975
1004
  this.taskLog(logKey, 'mention run returned no JSON; nothing posted');
@@ -1040,7 +1069,7 @@ export class Runner {
1040
1069
  async postStructuredAnswer(q, token, text) {
1041
1070
  let out;
1042
1071
  try {
1043
- out = JSON.parse(text.trim());
1072
+ out = parseStructured(text);
1044
1073
  }
1045
1074
  catch {
1046
1075
  this.taskLog(q.task, 'answer run returned no JSON; the question will escalate');
@@ -1372,3 +1401,32 @@ function promptFile(f) {
1372
1401
  const { key: _key, ...rest } = f;
1373
1402
  return rest;
1374
1403
  }
1404
+ /**
1405
+ * The JSON object a structured run ended with. Codex returns it bare (outputSchema); a remote run's final message may
1406
+ * wrap it in a ```json fence or a sentence, so the last {...} in the text is taken. Throws when there is none.
1407
+ */
1408
+ export function parseStructured(text) {
1409
+ const t = text.trim();
1410
+ try {
1411
+ return JSON.parse(t);
1412
+ }
1413
+ catch {
1414
+ /* not bare JSON */
1415
+ }
1416
+ const fenced = t.match(/```(?:json)?\s*([\s\S]*?)```/g);
1417
+ for (const f of (fenced ?? []).reverse()) {
1418
+ try {
1419
+ return JSON.parse(f.replace(/^```(?:json)?\s*/, '').replace(/```$/, '').trim());
1420
+ }
1421
+ catch {
1422
+ /* next */
1423
+ }
1424
+ }
1425
+ const start = t.lastIndexOf('{"action"');
1426
+ if (start >= 0) {
1427
+ const end = t.lastIndexOf('}');
1428
+ if (end > start)
1429
+ return JSON.parse(t.slice(start, end + 1));
1430
+ }
1431
+ throw new Error('no JSON object');
1432
+ }
@@ -34,7 +34,7 @@ export interface SandboxFix {
34
34
  commands: string[];
35
35
  }
36
36
  export interface SandboxStatus {
37
- tool: SandboxTool;
37
+ tool: SandboxTool | 'kiro';
38
38
  ok: boolean;
39
39
  /** ok, but the probe could not run (an older Codex without `codex sandbox`): not blocking, doctor warns. */
40
40
  unverified?: boolean;
@@ -6,8 +6,10 @@ export interface Retired {
6
6
  path: string;
7
7
  }
8
8
  /**
9
- * Stop and delete the other services of the agent whose home this is (not the one at `ownPath`). `run` false only deletes the files
10
- * (the installer was told not to load anything). Returns what was retired.
9
+ * Stop and delete the other services of this agent: same home, and named after one of `names` (the agent's name and former names).
10
+ * A service in the same home under a name this agent never had is another agent's runner whose key was replaced in that home
11
+ * (a `join` or `login` there): it is not deleted, it goes to `kept` so the installer can say so. Without `names` every service in
12
+ * the home counts as this agent's (the old rule). `run` false only deletes the files (the installer was told not to load anything).
11
13
  */
12
14
  export declare function retireSiblings(o: {
13
15
  platform: ServiceSpec['platform'];
@@ -16,6 +18,8 @@ export declare function retireSiblings(o: {
16
18
  ownPath: string;
17
19
  ownHome: string;
18
20
  run: boolean;
21
+ names?: string[];
22
+ kept?: Retired[];
19
23
  }): Retired[];
20
24
  /** Was this process started by its own service (launchd, systemd)? A runner someone started by hand must not be replaced by a restart. */
21
25
  export declare function startedByService(agentName: string, platform: string, env: NodeJS.ProcessEnv): boolean;
@@ -12,15 +12,24 @@ import { listServices, serviceFile, serviceLabel, specOf, writeServiceFile } fro
12
12
  export function homeOfService(s, env = process.env) {
13
13
  return s.env.AGENTCHANNEL_HOME || achHome({ ...env, AGENTCHANNEL_HOME: '' });
14
14
  }
15
+ /** A service label's form of an agent name (what `serviceFile` puts in the file name). */
16
+ const labelName = (n) => n.replace(/[^A-Za-z0-9-]/g, '-');
15
17
  /**
16
- * Stop and delete the other services of the agent whose home this is (not the one at `ownPath`). `run` false only deletes the files
17
- * (the installer was told not to load anything). Returns what was retired.
18
+ * Stop and delete the other services of this agent: same home, and named after one of `names` (the agent's name and former names).
19
+ * A service in the same home under a name this agent never had is another agent's runner whose key was replaced in that home
20
+ * (a `join` or `login` there): it is not deleted, it goes to `kept` so the installer can say so. Without `names` every service in
21
+ * the home counts as this agent's (the old rule). `run` false only deletes the files (the installer was told not to load anything).
18
22
  */
19
23
  export function retireSiblings(o) {
20
24
  const out = [];
25
+ const mine = o.names ? new Set(o.names.map(labelName)) : undefined;
21
26
  for (const s of listServices(o.platform, o.dir, o.env)) {
22
27
  if (s.path === o.ownPath || homeOfService(s, o.env) !== o.ownHome)
23
28
  continue;
29
+ if (mine && !mine.has(s.agentName)) {
30
+ o.kept?.push({ agentName: s.agentName, path: s.path });
31
+ continue;
32
+ }
24
33
  if (o.run) {
25
34
  for (const c of serviceFile(specOf(s, o.platform), o.dir, o.env).stop) {
26
35
  try {
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.22.0";
1
+ export declare const VERSION = "3.24.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.22.0';
1
+ export const VERSION = '3.24.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.22.0",
3
+ "version": "3.24.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",