@koalaauto/agentchannel 3.97.4 → 3.98.1

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.
@@ -0,0 +1,18 @@
1
+ export interface UseRow {
2
+ tool: string;
3
+ calls: number;
4
+ failed: number;
5
+ ms: number;
6
+ }
7
+ export declare class ToolUse {
8
+ private o;
9
+ private rows;
10
+ private timer;
11
+ constructor(o: {
12
+ send: (rows: UseRow[]) => Promise<unknown>;
13
+ everyMs?: number;
14
+ });
15
+ count(tool: string, failed: boolean, ms: number): void;
16
+ /** Report what was counted. A report that fails is dropped: the numbers are for seeing habits, not for billing. */
17
+ flush(): Promise<void>;
18
+ }
@@ -0,0 +1,34 @@
1
+ // How this session's tools are used (docs/specs/mcp-client.md §4.5): every tool call is counted here (the tool, whether it
2
+ // failed, how long it took) and the counts are reported to the hub at most once a minute, in one request. Never arguments or
3
+ // content. Until this existed nothing recorded a tool call, so what people use from a client could not be seen.
4
+ export class ToolUse {
5
+ o;
6
+ rows = new Map();
7
+ timer = null;
8
+ constructor(o) {
9
+ this.o = o;
10
+ }
11
+ count(tool, failed, ms) {
12
+ const r = this.rows.get(tool) ?? { tool, calls: 0, failed: 0, ms: 0 };
13
+ r.calls++;
14
+ if (failed)
15
+ r.failed++;
16
+ r.ms += Math.max(0, Math.round(ms));
17
+ this.rows.set(tool, r);
18
+ if (!this.timer) {
19
+ this.timer = setTimeout(() => void this.flush(), this.o.everyMs ?? 60_000);
20
+ this.timer.unref?.();
21
+ }
22
+ }
23
+ /** Report what was counted. A report that fails is dropped: the numbers are for seeing habits, not for billing. */
24
+ async flush() {
25
+ if (this.timer)
26
+ clearTimeout(this.timer);
27
+ this.timer = null;
28
+ if (!this.rows.size)
29
+ return;
30
+ const rows = [...this.rows.values()];
31
+ this.rows.clear();
32
+ await this.o.send(rows).catch(() => { });
33
+ }
34
+ }
@@ -483,6 +483,7 @@ export interface YodaItem {
483
483
  ok: boolean;
484
484
  };
485
485
  card?: Record<string, unknown>;
486
+ act_id?: string;
486
487
  }
487
488
  /** What `yodaAsk` gives back. `done`: Yoda finished within the wait. */
488
489
  export interface YodaAnswer {
@@ -667,11 +668,30 @@ export declare class Client {
667
668
  * What a session connected as a person sends itself, as written: a task, a post or a reply in the person's name. The hub
668
669
  * decides whether it goes at once or waits on a card on the Yoda page (`status`).
669
670
  */
670
- yodaAct(tool: 'send_task' | 'post' | 'reply', args: Record<string, unknown>): Promise<{
671
+ yodaAct(tool: string, args: Record<string, unknown>): Promise<{
671
672
  status: 'done' | 'waiting' | 'failed';
672
673
  text: string;
673
674
  url?: string;
675
+ act?: string;
676
+ undoable?: boolean;
674
677
  }>;
678
+ /** The person's own word on a card, chosen in their client's question box (never a model's argument): docs/specs/mcp-client.md §4.2. */
679
+ yodaDecide(act: string, decision: 'confirm' | 'decline'): Promise<{
680
+ status: 'done' | 'declined' | 'failed';
681
+ text: string;
682
+ }>;
683
+ /** Take back something the person's session or their Yoda did at once. */
684
+ yodaUndo(act: string): Promise<{
685
+ status: string;
686
+ text: string;
687
+ }>;
688
+ /** What this session's tools were called for since it last said so: counts only (docs/specs/mcp-client.md §4.5). */
689
+ clientUse(client: string, calls: {
690
+ tool: string;
691
+ calls: number;
692
+ failed: number;
693
+ ms: number;
694
+ }[]): Promise<unknown>;
675
695
  yodaMemory(): Promise<{
676
696
  memory: {
677
697
  id: string;
@@ -435,6 +435,18 @@ export class Client {
435
435
  async yodaAct(tool, args) {
436
436
  return this.ach('POST', '/yoda/acts', { tool, args, ...(this.yodaFrom ? { from: this.yodaFrom } : {}) });
437
437
  }
438
+ /** The person's own word on a card, chosen in their client's question box (never a model's argument): docs/specs/mcp-client.md §4.2. */
439
+ async yodaDecide(act, decision) {
440
+ return this.ach('POST', `/yoda/acts/${enc(act)}/decide`, { decision });
441
+ }
442
+ /** Take back something the person's session or their Yoda did at once. */
443
+ async yodaUndo(act) {
444
+ return this.ach('POST', `/yoda/acts/${enc(act)}/undo`, {});
445
+ }
446
+ /** What this session's tools were called for since it last said so: counts only (docs/specs/mcp-client.md §4.5). */
447
+ async clientUse(client, calls) {
448
+ return this.ach('POST', '/me/client-use', { client, calls });
449
+ }
438
450
  async yodaMemory() {
439
451
  return this.ach('GET', '/yoda/memory');
440
452
  }
package/dist/src/ids.d.ts CHANGED
@@ -47,7 +47,7 @@ export declare const KIND: {
47
47
  readonly yoda_acts: "X";
48
48
  };
49
49
  /** Tables without an `id` column of their own (keyed by the ids of other rows). */
50
- export declare const NO_ID_TABLES: readonly ["ach_fts", "artifact_refs", "artifact_versions", "mechanism_versions", "agent_project_memory", "yoda_watch", "waits", "agent_rule_files", "agent_rule_versions", "name_changes", "push_recalls", "rate_hits", "text_refs", "todos"];
50
+ export declare const NO_ID_TABLES: readonly ["ach_fts", "artifact_refs", "artifact_versions", "mechanism_versions", "agent_project_memory", "yoda_watch", "waits", "agent_rule_files", "agent_rule_versions", "name_changes", "push_recalls", "rate_hits", "text_refs", "todos", "client_use"];
51
51
  export type IdTable = keyof typeof KIND;
52
52
  export type IdKind = (typeof KIND)[IdTable];
53
53
  /** 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
@@ -55,7 +55,7 @@ export const KIND = {
55
55
  yoda_acts: 'X',
56
56
  };
57
57
  /** Tables without an `id` column of their own (keyed by the ids of other rows). */
58
- export const NO_ID_TABLES = ['ach_fts', 'artifact_refs', 'artifact_versions', 'mechanism_versions', 'agent_project_memory', 'yoda_watch', 'waits', 'agent_rule_files', 'agent_rule_versions', 'name_changes', 'push_recalls', 'rate_hits', 'text_refs', 'todos'];
58
+ export const NO_ID_TABLES = ['ach_fts', 'artifact_refs', 'artifact_versions', 'mechanism_versions', 'agent_project_memory', 'yoda_watch', 'waits', 'agent_rule_files', 'agent_rule_versions', 'name_changes', 'push_recalls', 'rate_hits', 'text_refs', 'todos', 'client_use'];
59
59
  /** Which format newId makes and normalizeId returns: 'legacy' before the cutover migrated the data (2026-11-24), 'kind' since. */
60
60
  export const ID_FORMAT = 'kind';
61
61
  const LETTERS = 'PMTHUGCDFKRSIX';
package/dist/src/mcp.d.ts CHANGED
@@ -13,7 +13,9 @@ export declare const MCP_TOOLS: readonly ["list_agents", "ask_yoda", "yoda_memor
13
13
  /**
14
14
  * The tools of a session connected as a person, with no agent (docs/specs/one-yoda.md): it reads what the person reads and
15
15
  * reaches their Yoda. A task, a post and a reply it sends as written, in the person's name (§13): the hub decides whether each
16
- * goes at once or waits on a card. Everything else that writes on the team, or works a task as an agent, is not here.
16
+ * goes at once or waits on a card. What the person says about a task (accept it, send it back, cancel it, a note) goes the same
17
+ * way, and a card is confirmed in the client's own question box (docs/specs/mcp-client.md). Everything else that writes on the
18
+ * team, or works a task as an agent, is not here.
17
19
  */
18
20
  export declare const PERSON_TOOLS: ReadonlySet<string>;
19
21
  /**
@@ -69,6 +71,14 @@ export declare const toolHints: (name: string) => {
69
71
  readOnlyHint: boolean;
70
72
  destructiveHint: boolean;
71
73
  };
74
+ /**
75
+ * Ask the person, in their client's own question box (MCP elicitation), whether something waiting on a card goes out
76
+ * (docs/specs/mcp-client.md §4.2). Their choice, or null when there is none: the client has no question box, they closed it,
77
+ * or it timed out. Null leaves the card where it is, on the Yoda page. Nothing a model writes reaches this answer.
78
+ */
79
+ export declare function askToConfirm(server: McpServer, what: string, env?: NodeJS.ProcessEnv): Promise<'confirm' | 'decline' | null>;
80
+ /** Which tool settles a waiting item of the person's Inbox (hub: api/person-inbox.ts), in one line; '' when none of ours does. */
81
+ export declare function inboxHandle(i: Record<string, unknown>): string;
72
82
  export declare function buildMcpServer(client: Client, o?: {
73
83
  brief?: string;
74
84
  identity?: string;
@@ -81,6 +91,8 @@ export declare function buildMcpServer(client: Client, o?: {
81
91
  client: Client;
82
92
  name: string;
83
93
  };
94
+ /** how often tool-call counts are reported (default: once a minute) */
95
+ useEveryMs?: number;
84
96
  }): McpServer;
85
97
  /**
86
98
  * Where the one-line reminder goes in the session that runs this server.
package/dist/src/mcp.js CHANGED
@@ -11,6 +11,7 @@ import { guideHeader, readGuide } from './guide.js';
11
11
  import { isAbsolute, join, relative } from 'node:path';
12
12
  import { AttentionNotifier, ChangeFeed, codexQueue, defaultExec, fetchAttention, wakesAttention } from './attention.js';
13
13
  import { isZh } from './client.js';
14
+ import { ToolUse } from './client-use.js';
14
15
  import { startStaleNotice } from './selfupdate.js';
15
16
  import { startRunnerWatchdog } from './watchdog.js';
16
17
  import { decisionTo, explainToUser, unreachedLines } from './names.js';
@@ -102,11 +103,14 @@ export const MCP_TOOLS = [
102
103
  /**
103
104
  * The tools of a session connected as a person, with no agent (docs/specs/one-yoda.md): it reads what the person reads and
104
105
  * reaches their Yoda. A task, a post and a reply it sends as written, in the person's name (§13): the hub decides whether each
105
- * goes at once or waits on a card. Everything else that writes on the team, or works a task as an agent, is not here.
106
+ * goes at once or waits on a card. What the person says about a task (accept it, send it back, cancel it, a note) goes the same
107
+ * way, and a card is confirmed in the client's own question box (docs/specs/mcp-client.md). Everything else that writes on the
108
+ * team, or works a task as an agent, is not here.
106
109
  */
107
110
  export const PERSON_TOOLS = new Set([
108
- 'ask_yoda', 'send_task', 'post', 'reply', 'yoda_memory', 'owner_inbox', 'decide', 'list_agents', 'get_task', 'download_files', 'get_artifact', 'read_doc', 'list_channels', 'read_channel', 'search',
109
- 'memory_search', 'memory_read', 'wiki_search', 'wiki_read', 'guide',
111
+ 'ask_yoda', 'send_task', 'post', 'reply', 'handle_task', 'confirm_card', 'take_back', 'yoda_memory', 'owner_inbox', 'decide', 'list_agents', 'get_task', 'download_files', 'get_artifact', 'read_doc', 'list_channels', 'read_channel', 'search',
112
+ // (not the older wiki_* names: a person's session is newer than they are)
113
+ 'memory_search', 'memory_read', 'guide',
110
114
  ]);
111
115
  /**
112
116
  * What a session connected as a person has besides, when it is opened in the directory of one of their agents: the tools that
@@ -120,9 +124,10 @@ export function personInstructions(name, hand) {
120
124
  `You are connected to AgentChannel as ${name}, through ${name}'s Yoda (their own agent on the team). Your user is ${name}. This session reads what ${name} reads; what it sends on the team goes out in ${name}'s name.`,
121
125
  'AgentChannel hands work between the agents of one team and lets their people follow it in one panel. Tasks are referred to as TASK-128; channels are team streams named #general, #reela/onair.',
122
126
  'Which tool when:',
123
- `- send_task, post, reply: when your user says what to send and to whom (an agent or a person by name, a channel, a thread), send it yourself: it goes out exactly as you wrote it, as ${name}. A post, a reply and a task to one of ${name}'s own agents go out at once (${name} can take them back on the Yoda page); a task to anyone else, and anything ${name} asked to be asked about first, waits on a card on the Yoda page until they confirm it (give them the link; you cannot confirm it from here, and do not send it again). Send only what your user asked you to send.`,
124
- `- ask_yoda: when your user names work and not who does it ("get the gateway team to..."), asks what goes on in the team, or wants anything else done there (answer a question, cancel, schedule): say it to Yoda in their words. Yoda knows who does what and acts as ${name} under the same rules.`,
125
- `- owner_inbox: what waits for ${name}. An item may carry "yoda": what Yoda already said about it (what it is, what it would choose and why); tell ${name} that with the item, as Yoda's word, before they answer. decide: ${name}'s own answer to a decision request addressed to them, when they give it to you here in so many words (never your guess of it). get_task, list_channels, read_channel, search, list_agents: read the team as ${name} sees it. read_doc: a Feishu/Lark document or wiki link.`,
127
+ `- send_task, post, reply: when your user says what to send and to whom (an agent or a person by name, a channel, a thread), send it yourself: it goes out exactly as you wrote it, as ${name}. A post, a reply and a task to one of ${name}'s own agents go out at once (take_back with the act id of the result undoes one); a task to anyone else, and anything ${name} asked to be asked about first, waits on a card until they confirm it: where the client can, they are asked right here; else give them the link to the Yoda page. You never confirm for them, and do not send it again. Send only what your user asked you to send.`,
128
+ `- ask_yoda: when your user names work and not who does it ("get the gateway team to..."), asks what goes on in the team, or wants anything else done there (answer a question, schedule): say it to Yoda in their words. Yoda knows who does what and acts as ${name} under the same rules.`,
129
+ `- handle_task: ${name}'s own word on a task, when they give it to you here: accept it, approve their agent's work, send it back (request_changes), cancel it, or a note to its worker.`,
130
+ `- owner_inbox: what waits for ${name}. An item may carry "yoda": what Yoda already said about it (what it is, what it would choose and why); tell ${name} that with the item, as Yoda's word, before they answer. Each item's "handle" says which tool settles it; "cards" are acts waiting for ${name}'s confirmation (confirm_card asks them). decide: ${name}'s own answer to a decision request addressed to them, when they give it to you here in so many words (never your guess of it). get_task, list_channels, read_channel, search, list_agents: read the team as ${name} sees it. read_doc: a Feishu/Lark document or wiki link.`,
126
131
  '- memory_search (one line + link per hit), memory_read: the team Memory (current state, decisions, lessons, figures). Check it when your user asks how something is done or why something fails.',
127
132
  `- yoda_memory: what Yoda remembers about ${name}; propose one more when you learn how they want something done (it counts once they accept it).`,
128
133
  ...(hand
@@ -235,8 +240,56 @@ export const CLAUDE_CHANNEL_METHOD = 'notifications/claude/channel';
235
240
  * right about which is which.
236
241
  */
237
242
  const READ_ONLY_TOOLS = new Set(['read_doc', 'guide', 'yoda_memory', 'list_agents', 'get_task', 'inbox', 'owner_inbox', 'list_channels', 'read_channel', 'search', 'memory_search', 'memory_read', 'wiki_search', 'wiki_read']);
238
- const OWNER_LEVEL_TOOLS = new Set(['decide', 'cancel_task']);
243
+ const OWNER_LEVEL_TOOLS = new Set(['decide', 'cancel_task', 'handle_task', 'take_back']);
239
244
  export const toolHints = (name) => (READ_ONLY_TOOLS.has(name) ? { readOnlyHint: true } : OWNER_LEVEL_TOOLS.has(name) ? { readOnlyHint: false, destructiveHint: true } : { readOnlyHint: false, destructiveHint: false });
245
+ /** handle_task's actions: the hub's act and the name its text goes by. */
246
+ const TASK_ACTS = {
247
+ accept: ['accept_task', 'note'],
248
+ approve: ['approve_task', 'note'],
249
+ request_changes: ['request_changes', 'body'],
250
+ cancel: ['cancel_task', 'reason'],
251
+ note: ['task_note', 'body'],
252
+ };
253
+ const oneLine = (s) => { const t = String(s ?? '').replace(/\s+/g, ' ').trim(); return t.length > 120 ? `${t.slice(0, 120)}…` : t; };
254
+ /**
255
+ * Ask the person, in their client's own question box (MCP elicitation), whether something waiting on a card goes out
256
+ * (docs/specs/mcp-client.md §4.2). Their choice, or null when there is none: the client has no question box, they closed it,
257
+ * or it timed out. Null leaves the card where it is, on the Yoda page. Nothing a model writes reaches this answer.
258
+ */
259
+ export async function askToConfirm(server, what, env = process.env) {
260
+ if (!server.server.getClientCapabilities()?.elicitation)
261
+ return null;
262
+ const zh = isZh(env);
263
+ const [yes, no] = zh ? ['发出', '不发'] : ['Send', 'Do not send'];
264
+ try {
265
+ const r = await server.server.elicitInput({
266
+ message: zh ? `以你的名义发出?\n${what}` : `Send this in your name?\n${what}`,
267
+ requestedSchema: { type: 'object', properties: { decision: { type: 'string', title: zh ? '决定' : 'Decision', enum: [yes, no] } }, required: ['decision'] },
268
+ }, { timeout: 10 * 60_000 });
269
+ if (r.action !== 'accept')
270
+ return null;
271
+ const d = r.content?.decision;
272
+ return d === yes ? 'confirm' : d === no ? 'decline' : null;
273
+ }
274
+ catch {
275
+ return null;
276
+ }
277
+ }
278
+ /** Which tool settles a waiting item of the person's Inbox (hub: api/person-inbox.ts), in one line; '' when none of ours does. */
279
+ export function inboxHandle(i) {
280
+ const task = String(i.task_ref ?? i.task_id ?? i.id ?? '');
281
+ switch (i.type) {
282
+ case 'decision': return `decide {task_id: ${String(i.task_ref ?? i.task_id ?? '')}, message_id: ${String(i.message_id ?? '')}, reply}: your user's own answer`;
283
+ case 'acceptance': return `handle_task {task_id: ${task}, action: accept | request_changes}`;
284
+ case 'review': return `handle_task {task_id: ${task}, action: approve | request_changes}`;
285
+ case 'merge': return 'merged on GitHub (the pull request of this task); nothing to do here';
286
+ case 'escalation':
287
+ case 'mention': return i.post_id ? `reply {post_id: ${String(i.post_id)}}: your user's answer in that thread` : '';
288
+ case 'assigned': return "their agent cannot pick it up (see `stalled`): its machine or runner needs them; open the item's url";
289
+ case 'blocker': return "resolved on the agent's page (the item's url) once what is missing is there";
290
+ default: return '';
291
+ }
292
+ }
240
293
  export function buildMcpServer(client, o = {}) {
241
294
  // one server, two callers: a tool that works the agent's tasks speaks as the agent, every other tool as the person. Which
242
295
  // one a call is travels with the call itself, so two tools running at once never take each other's
@@ -247,6 +300,15 @@ export function buildMcpServer(client, o = {}) {
247
300
  client = new Proxy(person, { get: (_t, prop) => { const c = asHand.getStore() ? hand : person; const v = c[prop]; return typeof v === 'function' ? v.bind(c) : v; } });
248
301
  }
249
302
  const server = new McpServer({ name: 'ach', version: VERSION }, { instructions: mcpInstructions(o.brief, o.identity, o.memory, o.person, o.hand?.name), capabilities: { experimental: { [CLAUDE_CHANNEL_CAPABILITY]: {} } } });
303
+ // what the session's tools are called for, told to the hub now and then (never while a test or a script turned it off)
304
+ const use = new ToolUse({
305
+ send: (rows) => {
306
+ const v = server.server.getClientVersion();
307
+ return process.env.ACH_CLIENT_USE === '0' ? Promise.resolve() : client.clientUse([v?.name, v?.version].filter(Boolean).join('/'), rows);
308
+ },
309
+ everyMs: o.useEveryMs,
310
+ });
311
+ server.toolUse = use;
250
312
  // every tool carries its hints, whatever registers it
251
313
  const register = server.registerTool.bind(server);
252
314
  const registered = new Set();
@@ -263,6 +325,20 @@ export function buildMcpServer(client, o = {}) {
263
325
  const run = cb;
264
326
  cb = (...args) => asHand.run(true, () => run(...args));
265
327
  }
328
+ // every call is counted (the tool, whether it failed, how long): docs/specs/mcp-client.md §4.5
329
+ const counted = cb;
330
+ cb = async (...args) => {
331
+ const began = Date.now();
332
+ let failed = true;
333
+ try {
334
+ const r = await counted(...args);
335
+ failed = !!r?.isError;
336
+ return r;
337
+ }
338
+ finally {
339
+ use.count(name, failed, Date.now() - began);
340
+ }
341
+ };
266
342
  const desc = o.person && typeof cfg?.description === 'string' ? cfg.description.replace(/\bMY OWNER \(the person\)/g, 'your user').replace(/\byour owner's\b/g, "your user's").replace(/\bYour owner's\b/g, "Your user's").replace(/\bmy owner\b/gi, 'your user').replace(/\byour owner\b/g, 'your user') : cfg?.description;
267
343
  return register(name, { ...cfg, ...(desc !== undefined ? { description: desc } : {}), annotations: { ...toolHints(name), ...(cfg?.annotations ?? {}) } }, cb);
268
344
  };
@@ -291,10 +367,20 @@ export function buildMcpServer(client, o = {}) {
291
367
  }
292
368
  // ---- connected as a person: what the session sends itself, as written (docs/specs/one-yoda.md §13) ----
293
369
  if (o.person) {
294
- const sent = async (tool, args) => wrap(async () => {
370
+ const decided = (d) => (d.status === 'done' ? `Your user confirmed it here. ${d.text}` : d.status === 'declined' ? 'Your user declined it here: it was not done. Do not send it again.' : `Your user confirmed it here, but it was not done: ${d.text}`);
371
+ const sent = async (tool, args, label) => wrap(async () => {
295
372
  const r = await client.yodaAct(tool, args);
296
373
  const text = r.text || `(${r.status || 'the hub said nothing'})`;
297
- return r.status === 'waiting' ? `${text}${r.url ? `\nConfirm or decline on the Yoda page: ${r.url}` : ''}` : text;
374
+ // not done is an error to the client (and counted as one), with the hub's reason
375
+ if (r.status === 'failed')
376
+ throw new Error(text);
377
+ if (r.status !== 'waiting')
378
+ return r.act && r.undoable ? `${text}\nact: ${r.act} (take_back undoes it)` : text;
379
+ // it waits on a card: the person is asked here, in their client's own question box, when it has one
380
+ const word = r.act ? await askToConfirm(server, label) : null;
381
+ if (word && r.act)
382
+ return decided(await client.yodaDecide(r.act, word));
383
+ return `${text}${r.url ? `\nConfirm or decline on the Yoda page: ${r.url}` : ''}`;
298
384
  });
299
385
  server.registerTool('send_task', {
300
386
  description: `Hand a piece of work to an agent, as your user. Use it when they say what is to be done and by whom; when they name work and not who does it, ask_yoda. The handoff goes out exactly as you write it and is all the receiver gets. A task to one of your user's own agents goes at once; to anyone else it waits on a card on the Yoda page until they confirm it. ${HANDOFF_HELP}`,
@@ -308,15 +394,43 @@ export function buildMcpServer(client, o = {}) {
308
394
  priority: z.enum(['P0', 'P1', 'P2', 'P3']).optional().describe('default P2'),
309
395
  channel: z.string().optional().describe('Channel for the task (default: where the agent works)'),
310
396
  },
311
- }, async (a) => sent('send_task', a));
397
+ }, async (a) => sent('send_task', a, `task to ${String(a.to ?? '')}: ${String(a.title ?? '')}`));
312
398
  server.registerTool('post', {
313
399
  description: `Post to a channel, as your user, exactly as you write it, at once (it waits on a card on the Yoda page only when they asked to be asked first for that channel). Only when your user asked for this post. @agent-name in the text wakes that agent for a short read-only reply; @PersonName reaches that person's Inbox. Work that changes something goes by send_task. Before your first post in a channel, read its description (read_channel shows it). ${LINKS_HELP}`,
314
400
  inputSchema: { channel: z.string(), text: z.string().describe('The post, Markdown') },
315
- }, async (a) => sent('post', { channel: a.channel, body: a.text }));
401
+ }, async (a) => sent('post', { channel: a.channel, body: a.text }, `post in #${a.channel.replace(/^#/, '')}: ${oneLine(a.text)}`));
316
402
  server.registerTool('reply', {
317
403
  description: `Reply in a post's thread, as your user, exactly as you write it, at once (a reply to a reply goes to the same thread). post_id may be a task (TASK-128): the reply goes to that task's own thread, which is where a word to a person about a task belongs (with their @name), not a new post. Only when your user asked for this reply. An @agent in it wakes that agent for a read-only reply: when your user says go ahead on work that changes something, send_task it. ${LINKS_HELP}`,
318
404
  inputSchema: { post_id: z.string(), text: z.string().describe('The reply, Markdown') },
319
- }, async (a) => sent('reply', { post: a.post_id, body: a.text }));
405
+ }, async (a) => sent('reply', { post: a.post_id, body: a.text }, `reply in ${a.post_id}: ${oneLine(a.text)}`));
406
+ server.registerTool('handle_task', {
407
+ description: "Your user's own word on a task, when they give it to you here (never your guess of it), done at once in their name. action: accept (a task that waits for them to accept it); approve (work of their own agent that waits for their review); request_changes (send it back with what is to change: also runs a completed or failed task again); cancel (a task they sent); note (more context for the worker agent; a word for a person about a task is a reply in its thread). `text` is required for request_changes and note, optional otherwise.",
408
+ inputSchema: {
409
+ task_id: z.string().describe('TASK-128, or the task id'),
410
+ action: z.enum(['accept', 'approve', 'request_changes', 'cancel', 'note']),
411
+ text: z.string().optional().describe('What is to change, the note, the reason for a cancel, or a few words with an accept'),
412
+ },
413
+ }, async (a) => {
414
+ const [tool, key] = TASK_ACTS[a.action];
415
+ return sent(tool, { task: a.task_id, ...(a.text?.trim() ? { [key]: a.text } : {}) }, `${a.action.replace('_', ' ')} ${a.task_id}`);
416
+ });
417
+ server.registerTool('confirm_card', {
418
+ description: "Put a card that waits for your user's confirmation (owner_inbox `cards`) to them here, in this client's own question box: they choose to confirm or decline, and that is done. You cannot answer for them: there is no argument for it. Where the client has no question box, it gives the link to the Yoda page.",
419
+ inputSchema: { act: z.string().describe('The `act` of the card') },
420
+ }, async (a) => wrap(async () => {
421
+ const y = await client.yoda();
422
+ const card = y.pending.find((i) => i.kind === 'confirm' && i.act_id === a.act);
423
+ if (!card)
424
+ return 'No card waits under that act (it may be decided already): see owner_inbox.';
425
+ const word = await askToConfirm(server, card.body);
426
+ if (!word)
427
+ return `Not decided here${y.url ? `: your user confirms or declines it on the Yoda page: ${y.url}` : '.'}`;
428
+ return decided(await client.yodaDecide(a.act, word));
429
+ }));
430
+ server.registerTool('take_back', {
431
+ description: 'Take back something this session or Yoda did at once in your user\'s name, when they ask: a task that was sent is canceled, a post or reply deleted. `act` comes with the result of send_task, post and reply.',
432
+ inputSchema: { act: z.string() },
433
+ }, async (a) => wrap(async () => (await client.yodaUndo(a.act)).text));
320
434
  }
321
435
  server.registerTool('list_agents', { description: 'List the team\'s agents (name, owner, runtime, description, profile, the repos their runner works in, capabilities, when the runner was last seen, blockers). Use it to pick who to hand work to or ask: description is what its owner says it is for, profile what it actually does (rewritten weekly from its work, including what does not belong with it); repos and capabilities say where it works, runner_at whether it is running, blockers what it cannot do right now. A task\'s repo must be one of the receiver\'s repos when it lists any.', inputSchema: {} }, async () => wrap(() => client.agents()));
322
436
  server.registerTool('send_task', {
@@ -424,7 +538,15 @@ export function buildMcpServer(client, o = {}) {
424
538
  server.registerTool('owner_inbox', {
425
539
  description: "What waits for MY OWNER (the person): decision requests, escalated questions, tasks to accept, new tasks for my agents. This is the person's panel Inbox, which my own `inbox` does not show. Use it when the owner asks what needs their reply; answer for them only with their say-so (reply with as_owner). An item's `yoda` is what their Yoda said about it: pass it on with the item. Items with the same `subject` are one matter (one thread or task): present them together. `all: true` adds the last week's replies and mentions, which wait for nobody (long).",
426
540
  inputSchema: { all: z.boolean().optional() },
427
- }, async (a) => wrap(async () => wrapUntrusted(await client.ownerInbox(a.all === true))));
541
+ }, async (a) => wrap(async () => {
542
+ const inbox = await client.ownerInbox(a.all === true);
543
+ if (!o.person)
544
+ return wrapUntrusted(inbox);
545
+ // a session that is the person: each waiting item says which tool settles it, and the cards waiting for their word come along
546
+ const items = Array.isArray(inbox.items) ? inbox.items.map((i) => { const h = i.pending ? inboxHandle(i) : ''; return h ? { ...i, handle: h } : i; }) : inbox.items;
547
+ const cards = await client.yoda().then((y) => y.pending.filter((i) => i.kind === 'confirm' && i.act_id).map((i) => ({ act: i.act_id, what: i.body, handle: 'confirm_card {act}: asks your user here' })), () => []);
548
+ return wrapUntrusted({ ...inbox, items, ...(cards.length ? { cards } : {}) });
549
+ }));
428
550
  server.registerTool('ask', {
429
551
  description: 'Ask a factual question on a task. It goes to the other party\'s agent by default (`to` takes an agent name, not a person); to reach a person, @ them by name in a post or reply. For money, product direction or irreversible actions use request_decision instead.',
430
552
  inputSchema: { task_id: z.string(), question: z.string(), to: z.string().optional(), attachments: ATTACH },
@@ -814,7 +936,14 @@ export async function startMcp(client, where = { cwd: process.cwd() }) {
814
936
  // this machine's runner, when it stopped and should not have (watchdog.ts): started again from here
815
937
  // (a session connected as a person has no runner to look after)
816
938
  const watchdog = linked && !hand ? { stop() { } } : startRunnerWatchdog({ me: () => (hand ? hand.client : client).me(), log: (s) => process.stderr.write(`[ach mcp] ${s}\n`) });
939
+ // the client ends a session by closing the pipe and then killing the process: what was counted since the last report is
940
+ // told first (a session shorter than a minute would otherwise leave no trace), within a second and a half
941
+ const lastWord = () => Promise.race([server.toolUse?.flush(), new Promise((r) => setTimeout(r, 1500))]).catch(() => { });
942
+ process.stdin.once('end', () => void lastWord());
943
+ for (const sig of ['SIGTERM', 'SIGINT', 'SIGHUP'])
944
+ process.once(sig, () => void lastWord().finally(() => process.exit(0)));
817
945
  server.server.onclose = () => {
946
+ void server.toolUse?.flush();
818
947
  notices?.stop();
819
948
  watchdog.stop();
820
949
  };
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.97.4";
1
+ export declare const VERSION = "3.98.1";
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.97.4';
1
+ export const VERSION = '3.98.1';
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.97.4",
3
+ "version": "3.98.1",
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",