@koalaauto/agentchannel 3.86.1 → 3.87.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.
@@ -194,6 +194,13 @@ export interface ConventionsLayer {
194
194
  /** The agent's own rules, kept on the hub with their versions (docs/specs/agent-definition.md); version 0 and '' when it has none. */
195
195
  export interface RulesLayer extends ConventionsLayer {
196
196
  version: number;
197
+ /** its reference files (an older hub leaves them out) */
198
+ files?: {
199
+ name: string;
200
+ size: number;
201
+ }[];
202
+ /** set by the runner: where this machine keeps that version's files for its runs to read */
203
+ dir?: string;
197
204
  }
198
205
  export interface Judgment {
199
206
  team?: ConventionsLayer;
@@ -578,6 +585,8 @@ export declare class Client {
578
585
  /** All attachments on a task (handoff versions and messages), with hub download URLs. */
579
586
  taskFiles(taskId: string): Promise<TaskFile[]>;
580
587
  /** Download one attachment into `dir`; returns the local path. */
588
+ /** One reference file of an agent's rules (docs/specs/agent-definition.md), of that version. */
589
+ ruleFile(agent: string, file: string, version: number): Promise<string>;
581
590
  download(a: Attachment, dir: string): Promise<string>;
582
591
  /** Publish an artifact (one checked local .html file) or, with `artifact`, a new version of it. */
583
592
  publishArtifact(file: string, o: {
@@ -343,6 +343,11 @@ export class Client {
343
343
  return taskFiles(await this.getTask(taskId));
344
344
  }
345
345
  /** Download one attachment into `dir`; returns the local path. */
346
+ /** One reference file of an agent's rules (docs/specs/agent-definition.md), of that version. */
347
+ async ruleFile(agent, file, version) {
348
+ const r = await this.ach('GET', `/agents/${encodeURIComponent(agent)}/rules/files/${encodeURIComponent(file)}?version=${version}`);
349
+ return String(r?.text ?? '');
350
+ }
346
351
  async download(a, dir) {
347
352
  const h = this.headers(false);
348
353
  delete h.accept;
package/dist/src/ids.d.ts CHANGED
@@ -50,7 +50,7 @@ export declare const KIND: {
50
50
  readonly wiki_versions: "X";
51
51
  };
52
52
  /** Tables without an `id` column of their own (keyed by the ids of other rows). */
53
- export declare const NO_ID_TABLES: readonly ["ach_fts", "artifact_refs", "artifact_versions", "agent_rule_versions", "name_changes", "push_recalls", "rate_hits", "text_refs", "todos"];
53
+ export declare const NO_ID_TABLES: readonly ["ach_fts", "artifact_refs", "artifact_versions", "mechanism_versions", "agent_rule_files", "agent_rule_versions", "name_changes", "push_recalls", "rate_hits", "text_refs", "todos"];
54
54
  export type IdTable = keyof typeof KIND;
55
55
  export type IdKind = (typeof KIND)[IdTable];
56
56
  /** Which format newId makes and normalizeId returns: 'legacy' before the cutover migrated the data (2026-11-24), 'kind' since. */
package/dist/src/ids.js CHANGED
@@ -58,7 +58,7 @@ export const KIND = {
58
58
  wiki_versions: 'X',
59
59
  };
60
60
  /** Tables without an `id` column of their own (keyed by the ids of other rows). */
61
- export const NO_ID_TABLES = ['ach_fts', 'artifact_refs', 'artifact_versions', 'agent_rule_versions', 'name_changes', 'push_recalls', 'rate_hits', 'text_refs', 'todos'];
61
+ export const NO_ID_TABLES = ['ach_fts', 'artifact_refs', 'artifact_versions', 'mechanism_versions', 'agent_rule_files', 'agent_rule_versions', 'name_changes', 'push_recalls', 'rate_hits', 'text_refs', 'todos'];
62
62
  /** Which format newId makes and normalizeId returns: 'legacy' before the cutover migrated the data (2026-11-24), 'kind' since. */
63
63
  export const ID_FORMAT = 'kind';
64
64
  const LETTERS = 'PMTHUGCDFKRSIX';
@@ -64,11 +64,6 @@ export declare function linkedDocsText(docs?: LinkedDoc[]): string[];
64
64
  export declare function linkedTasksText(tasks?: LinkedTask[]): string[];
65
65
  /** Trusted: the language the people on this hub read; the instructions around it stay English. Nothing for a hub that sends none. */
66
66
  export declare function langText(lang?: 'en' | 'zh'): string[];
67
- /**
68
- * Trusted: the team's conventions (admins; they only tighten the default), the owner's own (for all their agents), then the
69
- * agent's own rules (written by whoever looks after it; the hub keeps them, with versions), in that order, each with who wrote it.
70
- * The repository's instructions follow (projectText).
71
- */
72
67
  export declare function conventionsText(j?: Judgment, ownerName?: string): string[];
73
68
  /**
74
69
  * How an agent decides between doing it, asking another agent and asking a person (docs/specs/agent-autonomy.md). The same for
@@ -31,14 +31,22 @@ export function langText(lang) {
31
31
  * agent's own rules (written by whoever looks after it; the hub keeps them, with versions), in that order, each with who wrote it.
32
32
  * The repository's instructions follow (projectText).
33
33
  */
34
+ /** The reference files of the rules: where to read each here, or (a cloud run, a failed fetch) that they are not in this run. */
35
+ function ruleFilesText(r) {
36
+ if (!r.files?.length)
37
+ return [];
38
+ if (!r.dir)
39
+ return [`Your reference files (${r.files.map((f) => f.name).join(', ')}) are not available in this run; say so if you need one.`];
40
+ return [`Your reference files (read the one your rules point to when you need it; read-only, kept in step with the rules):`, ...r.files.map((f) => `- ${r.dir}/${f.name} (${f.size} characters)`)];
41
+ }
34
42
  export function conventionsText(j, ownerName) {
35
43
  const out = [];
36
44
  if (j?.team?.text)
37
45
  out.push(`Team conventions (set by ${j.team.by_name || 'an admin'}; every agent follows them; they only tighten the list above):`, j.team.text, '');
38
46
  if (j?.owner?.text)
39
47
  out.push(`${j.owner.by_name || ownerName || 'Your owner'}'s conventions (for all their agents; within the team's conventions they may tighten or loosen the list above, never the system's limits):`, j.owner.text, '');
40
- if (j?.rules?.text)
41
- out.push(`Your rules (how you work; version ${j.rules.version}, saved by ${j.rules.by_name || 'an admin'}${j.rules.at ? ` on ${j.rules.at.slice(0, 10)}` : ''}; kept on the hub for the whole team to read; they never loosen the team's conventions or the system's limits):`, j.rules.text, '');
48
+ if (j?.rules?.text || j?.rules?.files?.length)
49
+ out.push(`Your rules (how you work; version ${j.rules.version}, saved by ${j.rules.by_name || 'an admin'}${j.rules.at ? ` on ${j.rules.at.slice(0, 10)}` : ''}; kept on the hub for the whole team to read; they never loosen the team's conventions or the system's limits):`, ...(j.rules.text ? [j.rules.text] : []), ...ruleFilesText(j.rules), '');
42
50
  return out;
43
51
  }
44
52
  /**
@@ -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' | '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' | 'reportRunner' | 'reportModels' | 'release' | 'putTrace' | 'putMentionTrace' | 'pushToken' | 'taskPr' | 'prepareRun' | 'prepared' | 'readDoc'>>;
11
11
  export interface RunnerOptions {
12
12
  client: RunnerClient;
13
13
  adapter: RuntimeAdapter;
@@ -356,6 +356,12 @@ export declare class Runner {
356
356
  private teamOwned;
357
357
  /** What a full task prompt carries besides the task: the owner's memory for this project and the project's instructions. */
358
358
  private runContext;
359
+ /**
360
+ * The judgment with the agent's reference files on this machine: each version's files are fetched once into
361
+ * <home>/rules/v<N>/ (readable by every run, not a secret), and older versions are removed. A cloud run reads nothing of this
362
+ * machine, so it gets the names only; a failed fetch leaves the dir out and the prompt says the files are not here.
363
+ */
364
+ private withRuleFiles;
359
365
  /** Where a task's attachments are downloaded for its agents (readable, outside the worktree). */
360
366
  filesDir(taskId: string): string;
361
367
  /** The task's attachments, downloaded into filesDir (best effort: a failed download is listed without a path). */
@@ -1,5 +1,5 @@
1
1
  import { randomBytes } from 'node:crypto';
2
- import { appendFileSync, mkdirSync } from 'node:fs';
2
+ import { appendFileSync, existsSync, mkdirSync, readdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { join } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
@@ -1104,7 +1104,7 @@ export class Runner {
1104
1104
  files: files.map(promptFile),
1105
1105
  channel: await this.channelContext(claim.task),
1106
1106
  wiki: claim.wiki,
1107
- judgment: claim.judgment,
1107
+ judgment: await this.withRuleFiles(claim.judgment),
1108
1108
  remote: !!this.cloud,
1109
1109
  report: !this.o.adapter.spec.ach,
1110
1110
  achTool: this.o.adapter.spec.achBy === 'tool',
@@ -1209,7 +1209,7 @@ export class Runner {
1209
1209
  files: files.map(promptFile),
1210
1210
  channel: await this.channelContext(bundle.task),
1211
1211
  wiki: bundle.wiki,
1212
- judgment: bundle.judgment,
1212
+ judgment: await this.withRuleFiles(bundle.judgment),
1213
1213
  remote: !!this.cloud,
1214
1214
  report: !this.o.adapter.spec.ach,
1215
1215
  achTool: this.o.adapter.spec.achBy === 'tool',
@@ -1545,6 +1545,7 @@ export class Runner {
1545
1545
  const material = [run.post?.body, run.thread?.body, ...(run.replies ?? []).map((p) => p.body), run.task?.handoff, ...(run.task?.messages ?? []).map((m) => m.body)];
1546
1546
  const docs = structured ? await this.linkedDocs(material, key) : [];
1547
1547
  const tasks = structured ? await this.linkedTasks([run.post?.body, run.thread?.body, ...(run.replies ?? []).map((p) => p.body)], key, run.task?.ref) : [];
1548
+ const judgment = await this.withRuleFiles(run.judgment);
1548
1549
  const promptFor = (since) => buildMentionPrompt({
1549
1550
  ...(since ? { since } : {}),
1550
1551
  docs,
@@ -1559,7 +1560,7 @@ export class Runner {
1559
1560
  replies: run.replies ?? [],
1560
1561
  recent: run.recent ?? [],
1561
1562
  task: run.task,
1562
- judgment: run.judgment,
1563
+ judgment,
1563
1564
  threadUrl: !this.o.publicUrl && typeof run.thread.url === 'string' && /^https?:\/\//.test(run.thread.url) ? run.thread.url : postUrl(this.base(), threadId),
1564
1565
  structured,
1565
1566
  });
@@ -1695,6 +1696,8 @@ export class Runner {
1695
1696
  ...[developerDir()].filter((d) => !!d),
1696
1697
  ...gitCommonDir(cwd),
1697
1698
  join(this.o.home, 'bin'),
1699
+ // the reference files of the agent's rules, as the hub keeps them (withRuleFiles)
1700
+ join(this.o.home, 'rules'),
1698
1701
  ...readRepos.flatMap((r) => r.roots),
1699
1702
  ...(taskId ? [this.filesDir(taskId)] : []),
1700
1703
  // the owner's Claude Code memory for this project, read-only (docs/specs/agent-autonomy.md); a team agent has no owner
@@ -1724,6 +1727,41 @@ export class Runner {
1724
1727
  const ownerMemory = dir ? { dir, ...(this.o.adapter.spec.ownerMemory === 'native' ? {} : { index: memoryIndex(dir) }) } : undefined;
1725
1728
  return { ownerMemory, project: projectInstructions(workdir, this.o.adapter.spec.ownFiles) };
1726
1729
  }
1730
+ /**
1731
+ * The judgment with the agent's reference files on this machine: each version's files are fetched once into
1732
+ * <home>/rules/v<N>/ (readable by every run, not a secret), and older versions are removed. A cloud run reads nothing of this
1733
+ * machine, so it gets the names only; a failed fetch leaves the dir out and the prompt says the files are not here.
1734
+ */
1735
+ async withRuleFiles(j) {
1736
+ const r = j?.rules;
1737
+ if (!r?.files?.length || !r.version || this.cloud || !this.o.client.ruleFile || !this.me?.name)
1738
+ return j;
1739
+ const root = join(this.o.home, 'rules');
1740
+ const dir = join(root, `v${r.version}`);
1741
+ try {
1742
+ if (!existsSync(join(dir, '.complete'))) {
1743
+ const tmp = `${dir}.tmp-${process.pid}`;
1744
+ rmSync(tmp, { recursive: true, force: true });
1745
+ mkdirSync(tmp, { recursive: true, mode: 0o755 });
1746
+ for (const f of r.files) {
1747
+ if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(f.name))
1748
+ continue;
1749
+ writeFileSync(join(tmp, f.name), await this.o.client.ruleFile(this.me.name, f.name, r.version), { mode: 0o644 });
1750
+ }
1751
+ writeFileSync(join(tmp, '.complete'), '');
1752
+ rmSync(dir, { recursive: true, force: true });
1753
+ renameSync(tmp, dir);
1754
+ }
1755
+ for (const old of readdirSync(root))
1756
+ if (old !== `v${r.version}`)
1757
+ rmSync(join(root, old), { recursive: true, force: true });
1758
+ return { ...j, rules: { ...r, dir } };
1759
+ }
1760
+ catch (e) {
1761
+ this.log(`reference files of rules v${r.version}: ${e?.message ?? e}`);
1762
+ return j;
1763
+ }
1764
+ }
1727
1765
  /** Where a task's attachments are downloaded for its agents (readable, outside the worktree). */
1728
1766
  filesDir(taskId) {
1729
1767
  return join(this.o.home, 'files', taskId.replace(/[^A-Za-z0-9_-]/g, '_'));
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.86.1";
1
+ export declare const VERSION = "3.87.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.86.1';
1
+ export const VERSION = '3.87.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.86.1",
3
+ "version": "3.87.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",