@koalaauto/agentchannel 3.87.1 → 3.89.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). */
@@ -1057,6 +1059,7 @@ export class Runner {
1057
1059
  runToken: claim.run_token,
1058
1060
  tokenAt: Date.now(),
1059
1061
  handoffVersion: claim.task.handoff_version,
1062
+ ...(claim.task.perm === 'read' ? { readOnly: true } : {}),
1060
1063
  seen: Array.from(new Set([...(prev?.seen ?? []), ...claim.messages.map((m) => m.id)])),
1061
1064
  ...(prev?.gate ? { gate: prev.gate } : {}),
1062
1065
  ...(readRepos.length ? { readRepos } : {}),
@@ -1450,7 +1453,12 @@ export class Runner {
1450
1453
  this.taskLog(taskId, 'failed: the remote agent reported FAILED');
1451
1454
  return;
1452
1455
  }
1453
- await client.complete(taskId, `${text}${where}`.slice(0, 20000), rec.runId, undefined, rec.handoffVersion).catch((e) => this.log(`complete ${taskId}: ${e?.message ?? e}`));
1456
+ // 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
1457
+ const { rest, notes } = splitYodaNotes(text);
1458
+ for (const n of notes) {
1459
+ 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}`));
1460
+ }
1461
+ 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
1462
  this.taskLog(taskId, 'completed with the remote run\'s final message');
1455
1463
  }
1456
1464
  /** Base URL for links shown to agents (§19). */
@@ -1713,6 +1721,34 @@ export class Runner {
1713
1721
  const spec = this.o.adapter.spec;
1714
1722
  return spec.structuredAnswers || !spec.ach;
1715
1723
  }
1724
+ /** the project memory index last told to the hub, and when the file was last looked at */
1725
+ projectMemoryReported;
1726
+ projectMemoryCheckedAt = 0;
1727
+ /**
1728
+ * 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
1729
+ * note, never the notes). The owner's Yoda reads it, so it knows what each of its parts knows (primary-agent-design §11.15).
1730
+ * Looked at every few minutes, sent when it changed. Not for a team agent (no person) or a cloud run (no machine).
1731
+ */
1732
+ async reportProjectMemory(now = Date.now()) {
1733
+ if (!this.o.client.reportProjectMemory || this.cloud || !this.me || this.teamOwned())
1734
+ return;
1735
+ if (now - this.projectMemoryCheckedAt < PROJECT_MEMORY_EVERY_MS)
1736
+ return;
1737
+ this.projectMemoryCheckedAt = now;
1738
+ const dir = ownerMemoryDir(this.o.dir, realHomeOf(this.o.baseEnv ?? process.env));
1739
+ const index = dir ? memoryIndex(dir) : '';
1740
+ if (index === this.projectMemoryReported || (!index && this.projectMemoryReported === undefined))
1741
+ return;
1742
+ try {
1743
+ await this.o.client.reportProjectMemory(index);
1744
+ this.projectMemoryReported = index;
1745
+ }
1746
+ catch (e) {
1747
+ // an older hub has no such route: say nothing more
1748
+ if (e instanceof HubError && (e.status === 404 || e.status === 400))
1749
+ this.projectMemoryReported = index;
1750
+ }
1751
+ }
1716
1752
  /** Owned by no one person (the system agent, or a team agent such as one that does a channel mechanism for the team). */
1717
1753
  teamOwned() {
1718
1754
  return this.me?.kind === 'team';
@@ -1815,7 +1851,8 @@ export class Runner {
1815
1851
  // where this run's session is kept: a task's by the task, a thread's mention runs by the thread, a read-ahead's nowhere
1816
1852
  const sessKey = mode === 'mention' ? (extra.threadId ? threadKey(extra.threadId) : '') : mode === 'prepare' ? '' : taskId;
1817
1853
  const sessKind = mode;
1818
- const perm = mode === 'work' ? effectivePerm(me.perm_level, this.o.perm) : 'read';
1854
+ // a read-only task (perm: read) runs with read access only, whatever the agent's own level
1855
+ const perm = mode === 'work' && !rec.readOnly ? effectivePerm(me.perm_level, this.o.perm) : 'read';
1819
1856
  const env = buildAgentEnv(this.o.baseEnv ?? process.env, {
1820
1857
  hub: this.o.hub,
1821
1858
  runToken: rec.runToken,
@@ -2077,6 +2114,7 @@ export class Runner {
2077
2114
  try {
2078
2115
  await this.reportRepos();
2079
2116
  await this.reportRunner();
2117
+ await this.reportProjectMemory();
2080
2118
  // not awaited: listing starts the tool (up to a few seconds), and claiming work must not wait for it
2081
2119
  void this.reportModels();
2082
2120
  void this.describeAgent();
@@ -6,6 +6,8 @@ export interface RunRecord {
6
6
  runToken: string;
7
7
  tokenAt: number;
8
8
  handoffVersion?: number;
9
+ /** A read-only task (`perm: read`): its runs get read access only, whatever the agent's own level. */
10
+ readOnly?: boolean;
9
11
  /** The agent stopped once without finishing and was asked to finish (runner afterWork). */
10
12
  nudged?: boolean;
11
13
  /** Message ids the worker has already been shown. */
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.87.1";
1
+ export declare const VERSION = "3.89.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.1';
1
+ export const VERSION = '3.89.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.1",
3
+ "version": "3.89.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",