@koalaauto/agentchannel 3.87.0 → 3.88.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.
@@ -7,7 +7,7 @@ import { TraceRecorder } from '../trace.js';
7
7
  import { type SandboxStatus } from '../sandboxcheck.js';
8
8
  export * from './home.js';
9
9
  export * from './structured.js';
10
- export type RunnerClient = Pick<Client, 'me' | 'inbox' | 'claim' | 'getTask' | 'postMessage' | 'complete' | 'fail' | 'usage' | 'heartbeat' | 'answerRun' | 'endRun'> & Partial<Pick<Client, 'readOnly' | 'download' | 'githubToken' | 'channelPosts' | 'mentionRun' | 'mentionEnd' | 'mentionUsage' | 'promptSize' | 'ruleFile' | 'reportSetup' | 'reportRepos' | 'reportProfile' | 'reportRunner' | 'reportModels' | 'release' | 'putTrace' | 'putMentionTrace' | 'pushToken' | 'taskPr' | 'prepareRun' | 'prepared' | 'readDoc'>>;
10
+ export type RunnerClient = Pick<Client, 'me' | 'inbox' | 'claim' | 'getTask' | 'postMessage' | 'complete' | 'fail' | 'usage' | 'heartbeat' | 'answerRun' | 'endRun'> & Partial<Pick<Client, 'readOnly' | 'download' | 'githubToken' | 'channelPosts' | 'mentionRun' | 'mentionEnd' | 'mentionUsage' | 'promptSize' | 'ruleFile' | 'reportSetup' | 'reportRepos' | 'reportProfile' | 'reportProjectMemory' | 'yodaRemember' | 'reportRunner' | 'reportModels' | 'release' | 'putTrace' | 'putMentionTrace' | 'pushToken' | 'taskPr' | 'prepareRun' | 'prepared' | 'readDoc'>>;
11
11
  export interface RunnerOptions {
12
12
  client: RunnerClient;
13
13
  adapter: RuntimeAdapter;
@@ -352,6 +352,15 @@ export declare class Runner {
352
352
  private get cloud();
353
353
  /** Short runs return JSON by a schema and the runner posts it: the runtime's way, and the only way without `ach` in the run. */
354
354
  private get structured();
355
+ /** the project memory index last told to the hub, and when the file was last looked at */
356
+ private projectMemoryReported;
357
+ private projectMemoryCheckedAt;
358
+ /**
359
+ * Tell the hub what this agent knows about its project: the index of the owner's memory for it on this machine (one line per
360
+ * note, never the notes). The owner's Yoda reads it, so it knows what each of its parts knows (primary-agent-design §11.15).
361
+ * Looked at every few minutes, sent when it changed. Not for a team agent (no person) or a cloud run (no machine).
362
+ */
363
+ private reportProjectMemory;
355
364
  /** Owned by no one person (the system agent, or a team agent such as one that does a channel mechanism for the team). */
356
365
  private teamOwned;
357
366
  /** What a full task prompt carries besides the task: the owner's memory for this project and the project's instructions. */
@@ -17,7 +17,7 @@ import { taskFiles } from '../attachments.js';
17
17
  import { buildAgentEnv, inheritedEnv } from '../env.js';
18
18
  import { unlinkWindowsSandbox } from '../codexhome.js';
19
19
  import { effectivePerm } from '../perm.js';
20
- import { ANSWER_SCHEMA, MENTION_SCHEMA, buildAnswerPrompt, buildMentionPrompt, buildPreparePrompt, buildResumePrompt, buildTaskPrompt, postUrl, refOf, REMOTE_FAILED_PREFIX, taskUrl } from '../prompts.js';
20
+ import { ANSWER_SCHEMA, MENTION_SCHEMA, splitYodaNotes, buildAnswerPrompt, buildMentionPrompt, buildPreparePrompt, buildResumePrompt, buildTaskPrompt, postUrl, refOf, REMOTE_FAILED_PREFIX, taskUrl } from '../prompts.js';
21
21
  import { linkedDocs } from './linked-docs.js';
22
22
  import { linkedTasks } from './linked-tasks.js';
23
23
  import { RunnerState, threadKey } from './state.js';
@@ -36,6 +36,8 @@ export * from './home.js';
36
36
  export * from './structured.js';
37
37
  /** How long the runner trusts its copy of the agent's record before reading it again. */
38
38
  const ME_TTL_MS = 60_000;
39
+ /** How often the runner looks whether the project's memory index changed (it reports it to the hub when it did). */
40
+ const PROJECT_MEMORY_EVERY_MS = 5 * 60_000;
39
41
  /** How long a hub that has no GitHub App is left alone before a run asks it for a token again. */
40
42
  const GITHUB_OFF_MS = 10 * 60_000;
41
43
  /** The same after a failure that may pass (GitHub down, a setup being fixed). */
@@ -1450,7 +1452,12 @@ export class Runner {
1450
1452
  this.taskLog(taskId, 'failed: the remote agent reported FAILED');
1451
1453
  return;
1452
1454
  }
1453
- await client.complete(taskId, `${text}${where}`.slice(0, 20000), rec.runId, undefined, rec.handoffVersion).catch((e) => this.log(`complete ${taskId}: ${e?.message ?? e}`));
1455
+ // what the run learnt about its owner goes to their Yoda as proposals (it had no `ach` to say so itself), not into the result
1456
+ const { rest, notes } = splitYodaNotes(text);
1457
+ for (const n of notes) {
1458
+ await client.yodaRemember?.(n, undefined, taskId).then(() => this.taskLog(taskId, 'proposed a memory to the owner\'s Yoda'), (e) => this.taskLog(taskId, `yoda memory: ${e?.message ?? e}`));
1459
+ }
1460
+ await client.complete(taskId, `${rest || text}${where}`.slice(0, 20000), rec.runId, undefined, rec.handoffVersion).catch((e) => this.log(`complete ${taskId}: ${e?.message ?? e}`));
1454
1461
  this.taskLog(taskId, 'completed with the remote run\'s final message');
1455
1462
  }
1456
1463
  /** Base URL for links shown to agents (§19). */
@@ -1713,6 +1720,34 @@ export class Runner {
1713
1720
  const spec = this.o.adapter.spec;
1714
1721
  return spec.structuredAnswers || !spec.ach;
1715
1722
  }
1723
+ /** the project memory index last told to the hub, and when the file was last looked at */
1724
+ projectMemoryReported;
1725
+ projectMemoryCheckedAt = 0;
1726
+ /**
1727
+ * Tell the hub what this agent knows about its project: the index of the owner's memory for it on this machine (one line per
1728
+ * note, never the notes). The owner's Yoda reads it, so it knows what each of its parts knows (primary-agent-design §11.15).
1729
+ * Looked at every few minutes, sent when it changed. Not for a team agent (no person) or a cloud run (no machine).
1730
+ */
1731
+ async reportProjectMemory(now = Date.now()) {
1732
+ if (!this.o.client.reportProjectMemory || this.cloud || !this.me || this.teamOwned())
1733
+ return;
1734
+ if (now - this.projectMemoryCheckedAt < PROJECT_MEMORY_EVERY_MS)
1735
+ return;
1736
+ this.projectMemoryCheckedAt = now;
1737
+ const dir = ownerMemoryDir(this.o.dir, realHomeOf(this.o.baseEnv ?? process.env));
1738
+ const index = dir ? memoryIndex(dir) : '';
1739
+ if (index === this.projectMemoryReported || (!index && this.projectMemoryReported === undefined))
1740
+ return;
1741
+ try {
1742
+ await this.o.client.reportProjectMemory(index);
1743
+ this.projectMemoryReported = index;
1744
+ }
1745
+ catch (e) {
1746
+ // an older hub has no such route: say nothing more
1747
+ if (e instanceof HubError && (e.status === 404 || e.status === 400))
1748
+ this.projectMemoryReported = index;
1749
+ }
1750
+ }
1716
1751
  /** Owned by no one person (the system agent, or a team agent such as one that does a channel mechanism for the team). */
1717
1752
  teamOwned() {
1718
1753
  return this.me?.kind === 'team';
@@ -2077,6 +2112,7 @@ export class Runner {
2077
2112
  try {
2078
2113
  await this.reportRepos();
2079
2114
  await this.reportRunner();
2115
+ await this.reportProjectMemory();
2080
2116
  // not awaited: listing starts the tool (up to a few seconds), and claiming work must not wait for it
2081
2117
  void this.reportModels();
2082
2118
  void this.describeAgent();
@@ -204,6 +204,24 @@ export type SpawnSelf = (file: string, args: string[], env: NodeJS.ProcessEnv) =
204
204
  exit: Promise<number>;
205
205
  kill: (sig: NodeJS.Signals) => void;
206
206
  };
207
+ /**
208
+ * A runner started by hand through npx, after an update: npx would start the old release again from its cache, and nothing else
209
+ * starts it at all (2026-11-24: hand-started npx runners on Windows stayed on 3.68 or stopped). The release goes into the install
210
+ * in the AgentChannel home, and this process starts it from there through the launcher and stays as its parent (superviseSelf);
211
+ * from then on the runner runs from that install and updates it in place. Undefined when it could not be installed: the caller
212
+ * exits as before.
213
+ */
214
+ export declare function restartFromNpx(o: {
215
+ target: string | undefined;
216
+ app: string;
217
+ argv: string[];
218
+ install?: (app: string, version: string) => Promise<{
219
+ ok: boolean;
220
+ detail: string;
221
+ }>;
222
+ supervise?: (argv: string[]) => Promise<number>;
223
+ log: (s: string) => void;
224
+ }): Promise<number | undefined>;
207
225
  /**
208
226
  * After a global install replaced this CLI's files, run the same command line again (the new release) and stay as its parent: the
209
227
  * terminal, the Startup script or whatever started the runner still sees one process. The child knows it is watched
@@ -464,6 +464,25 @@ const defaultSpawnSelf = (file, args, env) => {
464
464
  kill: (sig) => void child.kill(sig),
465
465
  };
466
466
  };
467
+ /**
468
+ * A runner started by hand through npx, after an update: npx would start the old release again from its cache, and nothing else
469
+ * starts it at all (2026-11-24: hand-started npx runners on Windows stayed on 3.68 or stopped). The release goes into the install
470
+ * in the AgentChannel home, and this process starts it from there through the launcher and stays as its parent (superviseSelf);
471
+ * from then on the runner runs from that install and updates it in place. Undefined when it could not be installed: the caller
472
+ * exits as before.
473
+ */
474
+ export async function restartFromNpx(o) {
475
+ if (!o.target)
476
+ return undefined;
477
+ const r = await (o.install ?? ((app, v) => installIntoApp(app, v, defaultInstallExec)))(o.app, o.target);
478
+ if (!r.ok) {
479
+ o.log(`ach run: could not put ${o.target} into ${o.app} (${r.detail}); exiting: run it again to start the new release`);
480
+ return undefined;
481
+ }
482
+ o.log(`ach run: updated; ${o.target} is in ${o.app}, starting it here`);
483
+ const argv = [o.argv[0], join(o.app, 'ach.mjs'), ...o.argv.slice(2)];
484
+ return (o.supervise ?? ((a) => superviseSelf({ log: o.log, argv: a })))(argv);
485
+ }
467
486
  /**
468
487
  * After a global install replaced this CLI's files, run the same command line again (the new release) and stay as its parent: the
469
488
  * terminal, the Startup script or whatever started the runner still sees one process. The child knows it is watched
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.87.0";
1
+ export declare const VERSION = "3.88.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.87.0';
1
+ export const VERSION = '3.88.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.87.0",
3
+ "version": "3.88.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",