@koalaauto/agentchannel 3.41.1 → 3.42.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,6 +1,6 @@
1
1
  import type { Config } from './config.js';
2
2
  import { type Attachment, type StorageConfig, type TaskFile } from './attachments.js';
3
- export type TaskStatus = 'submitted' | 'working' | 'input-required' | 'awaiting_acceptance' | 'awaiting_merge' | 'completed' | 'failed' | 'canceled';
3
+ export type TaskStatus = 'submitted' | 'working' | 'input-required' | 'awaiting_review' | 'awaiting_acceptance' | 'awaiting_merge' | 'completed' | 'failed' | 'canceled';
4
4
  export declare const TERMINAL: readonly TaskStatus[];
5
5
  export declare function isTerminal(s: string | undefined): boolean;
6
6
  /** What a run really ran with, as its tool reported it (see AdapterResult.model). */
@@ -14,6 +14,8 @@ export interface Agent {
14
14
  name: string;
15
15
  owner?: string;
16
16
  owner_name?: string;
17
+ /** The team's system agent: owned by no one, the admins look after it (docs/specs/system-channels.md). */
18
+ system?: boolean;
17
19
  runtime?: string;
18
20
  description?: string;
19
21
  perm_level?: string;
@@ -411,14 +413,16 @@ export declare class Client {
411
413
  /** After pushing a task's branch: the hub opens (or finds) its pull request and links it; with `error`, says the push failed. */
412
414
  taskPr(taskId: string, body: {
413
415
  run_id: string;
414
- github: string;
416
+ github?: string;
415
417
  branch?: string;
416
418
  commit?: string;
417
419
  error?: string;
420
+ nothing?: boolean;
418
421
  }): Promise<{
419
422
  pr?: string;
420
423
  number?: number;
421
424
  opened?: boolean;
425
+ status?: string;
422
426
  }>;
423
427
  agents(): Promise<Agent[]>;
424
428
  sendTask(input: SendTaskInput, files?: string[]): Promise<Task>;
@@ -498,6 +502,7 @@ export declare class Client {
498
502
  name: string;
499
503
  description: string;
500
504
  }[];
505
+ review?: boolean;
501
506
  } & Partial<import('./runner/runner.js').RunnerStartInfo>): Promise<any>;
502
507
  reportSetup(sandbox: {
503
508
  tool: string;
@@ -2,6 +2,8 @@ import type { Judgment, Message, Post, Task, WikiContext } from './client.js';
2
2
  export interface PromptCtx {
3
3
  agentName: string;
4
4
  ownerName?: string;
5
+ /** The team's system agent: no owner, no one's personal memory; the admins look after it. */
6
+ system?: boolean;
5
7
  senderName?: string;
6
8
  task: Task;
7
9
  handoff: string;
@@ -274,7 +274,7 @@ function channelText(c) {
274
274
  function header(c) {
275
275
  const t = c.task;
276
276
  return [
277
- `You are agent "${c.agentName}"${c.ownerName ? `, owned by ${c.ownerName}` : ''}. Agent "${c.senderName ?? t.from_agent ?? 'unknown'}" sent you task ${refOf(t)} via AgentChannel.`,
277
+ `You are agent "${c.agentName}"${c.system ? ", the team's system agent (owned by no one; the team's admins look after you)" : c.ownerName ? `, owned by ${c.ownerName}` : ''}. Agent "${c.senderName ?? t.from_agent ?? 'unknown'}" sent you task ${refOf(t)} via AgentChannel.`,
278
278
  `Priority: ${t.priority ?? 'n/a'}. Handoff version: ${c.handoffVersion ?? t.handoff_version ?? 1}.`,
279
279
  ...(c.taskUrl ? [`Task page: ${c.taskUrl}`] : []),
280
280
  ].join('\n');
@@ -295,7 +295,8 @@ function completeRule(review) {
295
295
  function rules(review) {
296
296
  return [
297
297
  'Rules:',
298
- "- Work only inside the current directory. Do not commit or push: when your run ends, the runner commits your changes on this task's branch and, when the repository is on GitHub, pushes it and opens the task's pull request (the deliverable the sender reviews; each later round updates it). Keep notes, result files and screenshots in `.ach/` here: it is never committed.",
298
+ "- Work only inside the current directory. Do not commit or push: when your run ends, the runner commits your changes on this task's branch and, when the repository is on GitHub, pushes it and opens the task's pull request (the deliverable; each later round updates it). When the task is someone else's, your owner reviews it before the sender sees it. Keep notes, result files and screenshots in `.ach/` here: it is never committed.",
299
+ "- Before `ach complete`, run the project's own checks (build, type check, tests: what its CLAUDE.md, AGENTS.md, Makefile or package scripts say) on what you changed. The checkout's installed dependencies are linked in. Put the commands you ran and their outcome in the result. Checks that fail mean the work is not done: fix them, and if you cannot, start the result with what fails.",
299
300
  '- Talk through the `ach` CLI (the task id is already set):',
300
301
  ' - `ach progress "<text>"` for short status updates.',
301
302
  ' - `ach ask "<question>"` asks the sender a factual question. Then stop and end your turn; you will be resumed with the answer.',
@@ -2,7 +2,7 @@ import type { AdapterResult, RuntimeAdapter } from '../adapters/types.js';
2
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
- import type { Workspace } from './workspace.js';
5
+ import { type Workspace } from './workspace.js';
6
6
  import { TraceRecorder } from '../trace.js';
7
7
  import { type SandboxStatus } from '../sandboxcheck.js';
8
8
  export type RunnerClient = Pick<Client, 'me' | 'inbox' | 'claim' | 'getTask' | 'postMessage' | 'complete' | 'fail' | 'usage' | 'heartbeat' | 'answerRun' | 'endRun'> & Partial<Pick<Client, 'download' | 'githubToken' | 'channelPosts' | 'mentionRun' | 'mentionEnd' | 'mentionUsage' | 'promptSize' | 'reportSetup' | 'reportRepos' | 'reportRunner' | 'release' | 'putTrace' | 'pushToken' | 'taskPr'>>;
@@ -258,15 +258,24 @@ export declare class Runner {
258
258
  * The agent's own record (permission, network allowlist, budget), read again when it is older than ME_TTL_MS: an admin who
259
259
  * lowers the permission or narrows net_allow (say, after a suspected injection) is obeyed by the next run, not the next restart.
260
260
  */
261
+ /**
262
+ * The system agent works for the team, so no person's memory may reach its runs: Claude Code loads the memory of the git
263
+ * checkout a run is in. Its runner must start in a directory that is not one (docs/specs/system-channels.md); in a checkout
264
+ * it takes nothing and says so once.
265
+ */
266
+ private systemCheckoutWarned;
267
+ private systemInCheckout;
261
268
  private ensureMe;
262
269
  private runWork;
263
270
  private runResume;
264
271
  /** S10: the agent cannot write .git, so the runner commits its changes after every work run. */
265
272
  private commitWork;
266
273
  /**
267
- * The deliverable of a code task is its pull request. Once the agent finished a round (the task waits for acceptance, or is
268
- * completed), the runner pushes the task's branch with a push token for that one repository and the hub opens the pull request
269
- * (or the open one simply gets the new commits). The agent never holds the token. A failed push is said on the task.
274
+ * The deliverable of a code task is its pull request. Once the agent finished a round (the task waits for its owner's review or
275
+ * for acceptance, or is completed), the runner pushes the task's branch with a push token for that one repository and the hub
276
+ * opens the pull request (a draft while the owner reviews it) or the open one simply gets the new commits. The agent never holds
277
+ * the token. A failed push is said on the task. A round that changed no code tells the hub so: a task waiting for its owner's
278
+ * review then has nothing to review and goes on to acceptance.
270
279
  */
271
280
  private deliverPr;
272
281
  private afterWork;
@@ -15,6 +15,7 @@ import { linkWindowsSandbox, unlinkWindowsSandbox, WINDOWS_ELEVATED_CONFIG } fro
15
15
  import { effectivePerm } from '../perm.js';
16
16
  import { ANSWER_SCHEMA, buildAnswerPrompt, buildMentionPrompt, buildResumePrompt, buildTaskPrompt, postUrl, refOf, REMOTE_FAILED_PREFIX, taskUrl } from '../prompts.js';
17
17
  import { RunnerState } from './state.js';
18
+ import { isGitRepo } from './workspace.js';
18
19
  import { looksLikeLoginError, quotaProblem, summarizeRuntimeError } from '../envcheck.js';
19
20
  import { redact } from '../redact.js';
20
21
  import { TraceRecorder } from '../trace.js';
@@ -369,6 +370,8 @@ export class Runner {
369
370
  this.meAt = Date.now();
370
371
  }
371
372
  const me = await this.ensureMe();
373
+ if (me.system && (await this.systemInCheckout()))
374
+ return;
372
375
  // New tasks.
373
376
  const blocked = budgetBlocked(me);
374
377
  const now = Date.now();
@@ -508,7 +511,8 @@ export class Runner {
508
511
  return;
509
512
  }
510
513
  try {
511
- await this.o.client.reportRunner({ perm: this.o.perm, runtime, pass_env: [...new Set(this.o.passEnv ?? [])], capabilities, ...(this.o.startInfo ?? {}) });
514
+ // review: this runner knows the owner's review step (a task it finishes may wait in awaiting_review, design §36)
515
+ await this.o.client.reportRunner({ perm: this.o.perm, runtime, pass_env: [...new Set(this.o.passEnv ?? [])], capabilities, review: true, ...(this.o.startInfo ?? {}) });
512
516
  this.runnerReported = true;
513
517
  this.capsReported = sig;
514
518
  }
@@ -726,6 +730,20 @@ export class Runner {
726
730
  * The agent's own record (permission, network allowlist, budget), read again when it is older than ME_TTL_MS: an admin who
727
731
  * lowers the permission or narrows net_allow (say, after a suspected injection) is obeyed by the next run, not the next restart.
728
732
  */
733
+ /**
734
+ * The system agent works for the team, so no person's memory may reach its runs: Claude Code loads the memory of the git
735
+ * checkout a run is in. Its runner must start in a directory that is not one (docs/specs/system-channels.md); in a checkout
736
+ * it takes nothing and says so once.
737
+ */
738
+ systemCheckoutWarned = false;
739
+ async systemInCheckout() {
740
+ if (!(await isGitRepo(this.o.dir)))
741
+ return false;
742
+ if (!this.systemCheckoutWarned)
743
+ this.log(`${this.o.dir} is a git checkout: the system agent's runner must start in a directory that is not one (no project, no one's memory). Taking no tasks.`);
744
+ this.systemCheckoutWarned = true;
745
+ return true;
746
+ }
729
747
  async ensureMe() {
730
748
  if (!this.me || Date.now() - this.meAt > ME_TTL_MS) {
731
749
  try {
@@ -829,6 +847,7 @@ export class Runner {
829
847
  const prompt = buildTaskPrompt({
830
848
  agentName: me.name,
831
849
  ownerName: me.owner_name,
850
+ system: !!me.system,
832
851
  senderName: claim.task.from_agent_name,
833
852
  task: claim.task,
834
853
  handoff: claim.handoff,
@@ -928,6 +947,7 @@ export class Runner {
928
947
  : buildTaskPrompt({
929
948
  agentName: me.name,
930
949
  ownerName: me.owner_name,
950
+ system: !!me.system,
931
951
  senderName: bundle.task.from_agent_name,
932
952
  task: bundle.task,
933
953
  handoff: bundle.handoff,
@@ -972,18 +992,27 @@ export class Runner {
972
992
  }
973
993
  }
974
994
  /**
975
- * The deliverable of a code task is its pull request. Once the agent finished a round (the task waits for acceptance, or is
976
- * completed), the runner pushes the task's branch with a push token for that one repository and the hub opens the pull request
977
- * (or the open one simply gets the new commits). The agent never holds the token. A failed push is said on the task.
995
+ * The deliverable of a code task is its pull request. Once the agent finished a round (the task waits for its owner's review or
996
+ * for acceptance, or is completed), the runner pushes the task's branch with a push token for that one repository and the hub
997
+ * opens the pull request (a draft while the owner reviews it) or the open one simply gets the new commits. The agent never holds
998
+ * the token. A failed push is said on the task. A round that changed no code tells the hub so: a task waiting for its owner's
999
+ * review then has nothing to review and goes on to acceptance.
978
1000
  */
979
1001
  async deliverPr(rec, task) {
980
1002
  const { client, workspace } = this.o;
981
- if (!workspace.deliverable || !workspace.push || !client.pushToken || !client.taskPr)
1003
+ if (!client.taskPr)
982
1004
  return;
983
- if (task.status !== 'awaiting_acceptance' && task.status !== 'completed')
1005
+ if (task.status !== 'awaiting_review' && task.status !== 'awaiting_acceptance' && task.status !== 'completed')
984
1006
  return;
985
1007
  if ((task.run_id ?? '') !== rec.runId)
986
1008
  return;
1009
+ const nothing = async () => {
1010
+ if (task.status !== 'awaiting_review')
1011
+ return;
1012
+ await client.taskPr(rec.taskId, { run_id: rec.runId, nothing: true }).catch((e) => this.taskLog(rec.taskId, `nothing to review: ${e?.message ?? e}`));
1013
+ };
1014
+ if (!workspace.deliverable || !workspace.push || !client.pushToken)
1015
+ return nothing();
987
1016
  let d;
988
1017
  try {
989
1018
  d = await workspace.deliverable(task);
@@ -993,7 +1022,7 @@ export class Runner {
993
1022
  return;
994
1023
  }
995
1024
  if (!d)
996
- return;
1025
+ return nothing();
997
1026
  const say = (error) => client.taskPr(rec.taskId, { run_id: rec.runId, github: d.github, error }).catch(() => undefined);
998
1027
  let tok;
999
1028
  try {
@@ -1352,15 +1381,16 @@ export class Runner {
1352
1381
  join(this.o.home, 'bin'),
1353
1382
  ...readRepos.flatMap((r) => r.roots),
1354
1383
  ...(taskId ? [this.filesDir(taskId)] : []),
1355
- // the owner's Claude Code memory for this project, read-only (docs/specs/agent-autonomy.md)
1356
- ...[ownerMemoryDir(cwd, home)].filter((d) => !!d),
1384
+ // the owner's Claude Code memory for this project, read-only (docs/specs/agent-autonomy.md); the system agent has no owner
1385
+ ...(this.me?.system ? [] : [ownerMemoryDir(cwd, home)].filter((d) => !!d)),
1357
1386
  ];
1358
1387
  }
1359
1388
  /** What a full task prompt carries besides the task: the owner's memory for this project and the project's instructions. */
1360
1389
  runContext(workdir) {
1361
1390
  if (this.o.adapter.remote)
1362
1391
  return { project: [] };
1363
- const dir = ownerMemoryDir(workdir, realHomeOf(this.o.baseEnv ?? process.env));
1392
+ // the system agent works for the team: no person's memory, whatever machine it runs on (docs/specs/system-channels.md)
1393
+ const dir = this.me?.system ? undefined : ownerMemoryDir(workdir, realHomeOf(this.o.baseEnv ?? process.env));
1364
1394
  // Claude Code shows the index itself (it keys memory by the repository); other runtimes get it in the prompt
1365
1395
  const ownerMemory = dir ? { dir, ...(this.o.adapter.name === 'claude' ? {} : { index: memoryIndex(dir) }) } : undefined;
1366
1396
  return { ownerMemory, project: projectInstructions(workdir, this.o.adapter.name) };
@@ -1461,7 +1491,7 @@ export class Runner {
1461
1491
  // Except when the agent finished it itself (`ach complete` / `ach fail`, which leaves
1462
1492
  // a task sent with review waiting for acceptance): let the turn end so its usage is recorded.
1463
1493
  const st = e instanceof HubError ? String(e.body?.status ?? '') : '';
1464
- const finished = ['completed', 'failed', 'awaiting_acceptance', 'awaiting_merge'].includes(st);
1494
+ const finished = ['completed', 'failed', 'awaiting_review', 'awaiting_acceptance', 'awaiting_merge'].includes(st);
1465
1495
  if (is409(e) && !entry.reason && !finished) {
1466
1496
  entry.reason = 'lost';
1467
1497
  this.taskLog(taskId, 'heartbeat 409: run lost the task; aborting');
@@ -91,3 +91,9 @@ export declare class GitWorkspace implements Workspace {
91
91
  list(): string[];
92
92
  mtime(taskId: string): number;
93
93
  }
94
+ /**
95
+ * A fresh worktree has the code but none of the checkout's installed dependencies, so the agent could neither build nor test what
96
+ * it wrote. Each node_modules the checkout has (at its root and up to two folders down) that git ignores is linked into the same
97
+ * place in the worktree. The agent reads them; its sandbox lets it write only inside the worktree, so it cannot change them.
98
+ */
99
+ export declare function linkDeps(dir: string, p: string, log?: (s: string) => void): Promise<number>;
@@ -1,5 +1,5 @@
1
1
  import { execFile } from 'node:child_process';
2
- import { existsSync, mkdirSync, readdirSync, rmSync, statSync } from 'node:fs';
2
+ import { existsSync, lstatSync, mkdirSync, readdirSync, rmSync, statSync, symlinkSync } from 'node:fs';
3
3
  import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
4
4
  import { promisify } from 'node:util';
5
5
  const pexec = promisify(execFile);
@@ -166,8 +166,12 @@ export class GitWorkspace {
166
166
  async prepare(task, agentName) {
167
167
  const p = this.path(task.id);
168
168
  const dir = this.repoDir(task);
169
- if (existsSync(p))
169
+ if (existsSync(p)) {
170
+ // a worktree made before its dependencies were linked in (an older runner) gets them on its next round
171
+ if ((await isGitRepo(dir)) && (await isGitRepo(p)))
172
+ await linkDeps(dir, p, this.log);
170
173
  return p;
174
+ }
171
175
  mkdirSync(this.root, { recursive: true, mode: 0o700 });
172
176
  if (!(await isGitRepo(dir))) {
173
177
  // a task that names a repo expects its code: an empty dir would only let the agent find out for itself
@@ -203,6 +207,7 @@ export class GitWorkspace {
203
207
  await git(dir, ['worktree', 'add', p, branch]);
204
208
  else
205
209
  await git(dir, ['worktree', 'add', '-b', branch, p, start]);
210
+ await linkDeps(dir, p, this.log);
206
211
  return p;
207
212
  }
208
213
  async resolveRef(dir, base) {
@@ -288,7 +293,9 @@ export class GitWorkspace {
288
293
  }
289
294
  const safe = [...ident];
290
295
  // .ach/ holds the agent's notes, result file and screenshots, ach-files/ the task's downloads: neither belongs in the work
291
- await git(p, [...safe, 'add', '-A', '--', '.', ':(exclude).ach', ':(exclude)ach-files']);
296
+ // node_modules: the checkout's installed dependencies, linked in by linkDeps (a link is a file to git, which ignore rules
297
+ // written as `node_modules/` do not match)
298
+ await git(p, [...safe, 'add', '-A', '--', '.', ':(exclude).ach', ':(exclude)ach-files', ':(exclude,glob)**/node_modules']);
292
299
  if (!(await git(p, ['diff', '--cached', '--name-only'])))
293
300
  return undefined;
294
301
  await git(p, [...safe, 'commit', '--no-verify', '-q', '-m', message]);
@@ -359,3 +366,59 @@ export class GitWorkspace {
359
366
  }
360
367
  }
361
368
  }
369
+ /**
370
+ * A fresh worktree has the code but none of the checkout's installed dependencies, so the agent could neither build nor test what
371
+ * it wrote. Each node_modules the checkout has (at its root and up to two folders down) that git ignores is linked into the same
372
+ * place in the worktree. The agent reads them; its sandbox lets it write only inside the worktree, so it cannot change them.
373
+ */
374
+ export async function linkDeps(dir, p, log = () => undefined) {
375
+ const found = [];
376
+ const walk = (rel, depth) => {
377
+ let names = [];
378
+ try {
379
+ names = readdirSync(join(dir, rel));
380
+ }
381
+ catch {
382
+ return;
383
+ }
384
+ for (const n of names) {
385
+ if (n === '.git')
386
+ continue;
387
+ const r = rel ? `${rel}/${n}` : n;
388
+ let st;
389
+ try {
390
+ st = lstatSync(join(dir, r));
391
+ }
392
+ catch {
393
+ continue;
394
+ }
395
+ if (!st.isDirectory())
396
+ continue;
397
+ if (n === 'node_modules')
398
+ found.push(r);
399
+ else if (depth < 2 && !n.startsWith('.'))
400
+ walk(r, depth + 1);
401
+ }
402
+ };
403
+ walk('', 0);
404
+ let linked = 0;
405
+ for (const r of found) {
406
+ const to = join(p, r);
407
+ if (!existsSync(dirname(to)) || existsSync(to))
408
+ continue;
409
+ try {
410
+ await git(dir, ['check-ignore', '-q', r]); // exits non-zero when git would track it: never link that
411
+ }
412
+ catch {
413
+ continue;
414
+ }
415
+ try {
416
+ symlinkSync(join(dir, r), to, 'dir');
417
+ linked++;
418
+ }
419
+ catch (e) {
420
+ log(`link ${r}: ${e?.message ?? e}`);
421
+ }
422
+ }
423
+ return linked;
424
+ }
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.41.1";
1
+ export declare const VERSION = "3.42.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.41.1';
1
+ export const VERSION = '3.42.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.41.1",
3
+ "version": "3.42.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",