@koalaauto/agentchannel 3.99.1 → 3.99.2

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.
@@ -35,6 +35,33 @@ export declare function noticeText(a: Attention, lang?: 'en' | 'zh'): string;
35
35
  /** One confirmation, for the person and for the session that answers for them (`decide` with the request id and the answer). Pure. */
36
36
  export declare function confirmationText(c: Confirmation, lang?: 'en' | 'zh'): string;
37
37
  export declare const NOTICE_GAP_MS: number;
38
+ /**
39
+ * A reminder that waits for the session's next tool result (docs/specs/mcp-client.md §7). The other ways into a session
40
+ * depend on the client (a Claude Code channel needs a start flag, `codex queue` the session's id, which Codex does not give
41
+ * its MCP servers) and fail without a sound; a tool result is what every client hands its model. One line per kind, the
42
+ * newest; taken once. A count of what waits that is older than `staleMs` is counted again before it is said (`fresh`),
43
+ * so a session that was idle for hours does not announce what has been answered since.
44
+ */
45
+ export declare class PendingNotice {
46
+ private o;
47
+ private held;
48
+ /** What waits now, as the line to say, or null when nothing does. Set by the session's notifier. */
49
+ fresh?: () => Promise<string | null>;
50
+ constructor(o?: {
51
+ staleMs?: number;
52
+ now?: () => number;
53
+ });
54
+ private now;
55
+ put(kind: string, text: string): void;
56
+ /** The person is reading what waits themselves: nothing to tell them about it. */
57
+ drop(kind: string): void;
58
+ get waiting(): boolean;
59
+ /** Everything held, once: the lines for the next tool result ([] when nothing). */
60
+ take(): Promise<string[]>;
61
+ }
62
+ /** The kinds of reminder a session holds: what waits for the person, and that a newer `ach` is out. */
63
+ export declare const ATTENTION_NOTICE = "attention";
64
+ export declare const STALE_NOTICE = "stale";
38
65
  export interface AttentionNotifierOptions {
39
66
  fetch: () => Promise<Attention>;
40
67
  /** Shows the line; resolves false when it could not (unsupported: stays silent). */
@@ -110,6 +110,57 @@ export function confirmationText(c, lang = 'en') {
110
110
  return `${c.task} waits for your confirmation: ${c.runs}${c.money ? ` · cost ${c.money}` : ''}. Once you say yes or no, answer with decide (task_id ${c.task}, message_id ${c.id}, reply "${c.confirm}" or "${c.decline}").`;
111
111
  }
112
112
  export const NOTICE_GAP_MS = 10 * 60_000;
113
+ /**
114
+ * A reminder that waits for the session's next tool result (docs/specs/mcp-client.md §7). The other ways into a session
115
+ * depend on the client (a Claude Code channel needs a start flag, `codex queue` the session's id, which Codex does not give
116
+ * its MCP servers) and fail without a sound; a tool result is what every client hands its model. One line per kind, the
117
+ * newest; taken once. A count of what waits that is older than `staleMs` is counted again before it is said (`fresh`),
118
+ * so a session that was idle for hours does not announce what has been answered since.
119
+ */
120
+ export class PendingNotice {
121
+ o;
122
+ held = new Map();
123
+ /** What waits now, as the line to say, or null when nothing does. Set by the session's notifier. */
124
+ fresh;
125
+ constructor(o = {}) {
126
+ this.o = o;
127
+ }
128
+ now() {
129
+ return (this.o.now ?? Date.now)();
130
+ }
131
+ put(kind, text) {
132
+ if (text)
133
+ this.held.set(kind, { text, at: this.now() });
134
+ }
135
+ /** The person is reading what waits themselves: nothing to tell them about it. */
136
+ drop(kind) {
137
+ this.held.delete(kind);
138
+ }
139
+ get waiting() {
140
+ return this.held.size > 0;
141
+ }
142
+ /** Everything held, once: the lines for the next tool result ([] when nothing). */
143
+ async take() {
144
+ if (!this.held.size)
145
+ return [];
146
+ const all = [...this.held];
147
+ this.held.clear();
148
+ const out = [];
149
+ for (const [kind, n] of all) {
150
+ if (kind !== ATTENTION_NOTICE || !this.fresh || this.now() - n.at <= (this.o.staleMs ?? NOTICE_GAP_MS))
151
+ out.push(n.text);
152
+ else {
153
+ const now = await this.fresh().catch(() => n.text);
154
+ if (now)
155
+ out.push(now);
156
+ }
157
+ }
158
+ return out;
159
+ }
160
+ }
161
+ /** The kinds of reminder a session holds: what waits for the person, and that a newer `ach` is out. */
162
+ export const ATTENTION_NOTICE = 'attention';
163
+ export const STALE_NOTICE = 'stale';
113
164
  export class AttentionNotifier {
114
165
  o;
115
166
  noticed = new Set();
package/dist/src/mcp.d.ts CHANGED
@@ -71,6 +71,8 @@ export declare const toolHints: (name: string) => {
71
71
  readOnlyHint: boolean;
72
72
  destructiveHint: boolean;
73
73
  };
74
+ /** A held reminder as the last text item of a tool result: said to be the hub's own word, apart from what the tool returned. */
75
+ export declare const noticeInResult: (lines: string[]) => string;
74
76
  /**
75
77
  * Ask the person, in their client's own question box (MCP elicitation), whether something waiting on a card goes out
76
78
  * (docs/specs/mcp-client.md §4.2). One step: the box has no field, so the client's own two buttons are the answer: accept
@@ -100,14 +102,15 @@ export declare function buildMcpServer(client: Client, o?: {
100
102
  }): McpServer;
101
103
  /**
102
104
  * Where the one-line reminder goes in the session that runs this server.
103
- * - Codex (client name "codex..."): `codex queue --thread <id>` when the
104
- * session id is known (CODEX_THREAD_ID / ACH_CODEX_THREAD_ID), else nothing
105
- * (the desktop notifier covers it).
106
- * - Anything else: a Claude Code channel notification. Claude Code shows it
107
- * only when started with channels enabled for this server; otherwise it is
108
- * dropped silently (nothing breaks).
105
+ * - Always: held for the session's next tool result (PendingNotice): the one way every client is known to pass on. Tested
106
+ * in Claude Code, Codex, Kiro and Antigravity (docs/specs/mcp-client.md §7).
107
+ * - Codex (client name "codex..."): also `codex queue --thread <id>` when the session id is known (CODEX_THREAD_ID /
108
+ * ACH_CODEX_THREAD_ID); when that worked the person has it already and nothing is held. Codex 0.163 gives its MCP servers
109
+ * no such id.
110
+ * - Anything else: also a Claude Code channel notification. Claude Code shows it only when started with channels enabled for
111
+ * this server and says nothing when it drops it, so it never counts as delivered.
109
112
  */
110
- export declare function sessionDeliverer(server: McpServer, env?: NodeJS.ProcessEnv, exec?: Exec): (text: string) => Promise<boolean>;
113
+ export declare function sessionDeliverer(server: McpServer, env?: NodeJS.ProcessEnv, exec?: Exec, kind?: string): (text: string) => Promise<boolean>;
111
114
  /**
112
115
  * Reminders, never content (see attention.ts): follow the hub's change stream
113
116
  * and push a rate-limited one-line notice into the open session. Off with
package/dist/src/mcp.js CHANGED
@@ -9,7 +9,7 @@ import { VERSION } from './version.js';
9
9
  import { resolveAttachments, taskFiles } from './attachments.js';
10
10
  import { guideHeader, readGuide } from './guide.js';
11
11
  import { isAbsolute, join, relative } from 'node:path';
12
- import { AttentionNotifier, ChangeFeed, codexQueue, defaultExec, fetchAttention, wakesAttention } from './attention.js';
12
+ import { ATTENTION_NOTICE, AttentionNotifier, ChangeFeed, PendingNotice, STALE_NOTICE, codexQueue, defaultExec, fetchAttention, noticeText, wakesAttention } from './attention.js';
13
13
  import { isZh } from './client.js';
14
14
  import { ToolUse } from './client-use.js';
15
15
  import { startStaleNotice } from './selfupdate.js';
@@ -242,6 +242,10 @@ export const CLAUDE_CHANNEL_METHOD = 'notifications/claude/channel';
242
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']);
243
243
  const OWNER_LEVEL_TOOLS = new Set(['decide', 'cancel_task', 'handle_task', 'take_back']);
244
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
+ /** Tools that show what waits: the reminder that something does is not added to their result. */
246
+ const INBOX_TOOLS = new Set(['owner_inbox', 'inbox']);
247
+ /** A held reminder as the last text item of a tool result: said to be the hub's own word, apart from what the tool returned. */
248
+ export const noticeInResult = (lines) => `[A reminder from AgentChannel itself, not part of this tool's result. Pass it on to your user in one line, after what they asked for.]\n${lines.join('\n')}`;
245
249
  /** handle_task's actions: the hub's act and the name its text goes by. */
246
250
  const TASK_ACTS = {
247
251
  accept: ['accept_task', 'note'],
@@ -307,6 +311,9 @@ export function buildMcpServer(client, o = {}) {
307
311
  everyMs: o.useEveryMs,
308
312
  });
309
313
  server.toolUse = use;
314
+ // reminders that wait for the next tool result (attention.ts PendingNotice): what every client hands its model
315
+ const pending = new PendingNotice();
316
+ server.pendingNotice = pending;
310
317
  // every tool carries its hints, whatever registers it
311
318
  const register = server.registerTool.bind(server);
312
319
  const registered = new Set();
@@ -329,9 +336,16 @@ export function buildMcpServer(client, o = {}) {
329
336
  const began = Date.now();
330
337
  let failed = true;
331
338
  try {
332
- const r = await counted(...args);
339
+ const r = (await counted(...args));
333
340
  failed = !!r?.isError;
334
- return r;
341
+ // asking what waits is the answer to "something waits": that reminder is not said on top of it
342
+ if (!failed && INBOX_TOOLS.has(name))
343
+ pending.drop(ATTENTION_NOTICE);
344
+ if (failed || !pending.waiting || !Array.isArray(r?.content))
345
+ return r;
346
+ const lines = await pending.take();
347
+ // its own text item after the tool's: the result itself stays what the tool gave
348
+ return lines.length ? { ...r, content: [...r.content, { type: 'text', text: noticeInResult(lines) }] } : r;
335
349
  }
336
350
  finally {
337
351
  use.count(name, failed, Date.now() - began);
@@ -831,25 +845,34 @@ export function buildMcpServer(client, o = {}) {
831
845
  }
832
846
  /**
833
847
  * Where the one-line reminder goes in the session that runs this server.
834
- * - Codex (client name "codex..."): `codex queue --thread <id>` when the
835
- * session id is known (CODEX_THREAD_ID / ACH_CODEX_THREAD_ID), else nothing
836
- * (the desktop notifier covers it).
837
- * - Anything else: a Claude Code channel notification. Claude Code shows it
838
- * only when started with channels enabled for this server; otherwise it is
839
- * dropped silently (nothing breaks).
848
+ * - Always: held for the session's next tool result (PendingNotice): the one way every client is known to pass on. Tested
849
+ * in Claude Code, Codex, Kiro and Antigravity (docs/specs/mcp-client.md §7).
850
+ * - Codex (client name "codex..."): also `codex queue --thread <id>` when the session id is known (CODEX_THREAD_ID /
851
+ * ACH_CODEX_THREAD_ID); when that worked the person has it already and nothing is held. Codex 0.163 gives its MCP servers
852
+ * no such id.
853
+ * - Anything else: also a Claude Code channel notification. Claude Code shows it only when started with channels enabled for
854
+ * this server and says nothing when it drops it, so it never counts as delivered.
840
855
  */
841
- export function sessionDeliverer(server, env = process.env, exec = defaultExec) {
856
+ export function sessionDeliverer(server, env = process.env, exec = defaultExec, kind = ATTENTION_NOTICE) {
842
857
  return async (text) => {
858
+ const pending = server.pendingNotice;
843
859
  const name = String(server.server.getClientVersion()?.name ?? '');
844
- if (/codex/i.test(name))
845
- return codexQueue(text, env, exec);
860
+ if (/codex/i.test(name)) {
861
+ if (await codexQueue(text, env, exec))
862
+ return true;
863
+ pending?.put(kind, text);
864
+ return !!pending;
865
+ }
866
+ let sent = false;
846
867
  try {
847
868
  await server.server.notification({ method: CLAUDE_CHANNEL_METHOD, params: { content: text, meta: { source: 'agentchannel', kind: 'reminder' } } });
848
- return true;
869
+ sent = true;
849
870
  }
850
871
  catch {
851
- return false;
872
+ sent = false;
852
873
  }
874
+ pending?.put(kind, text);
875
+ return sent || !!pending;
853
876
  };
854
877
  }
855
878
  /**
@@ -872,12 +895,16 @@ export function startSessionNotices(server, client, o = {}) {
872
895
  // (only what is addressed to this person: counting again for every event of the team made this the hub's most asked question)
873
896
  // (and not in the same instant as the person's other sessions: 2026-11-24, six of them counted together two seconds after one
874
897
  // reply, and D1 refused them all as overloaded)
898
+ // a held count that grew old is counted again before it is said (PendingNotice.fresh)
899
+ const held = server.pendingNotice;
900
+ if (held)
901
+ held.fresh = async () => { const a = await fetchAttention(request); return a.total > 0 ? noticeText(a, isZh(env) ? 'zh' : 'en') : null; };
875
902
  const feed = new ChangeFeed({ socket: () => client.eventsSocket(), onChange: () => notifier.check(), relevant: wakesAttention, spreadMs: 3000, log: o.log, ...o.feed });
876
903
  const done = feed.run();
877
904
  // a session cannot be restarted from outside: when the hub names a newer ach, say so once (see selfupdate.ts)
878
905
  const stale = startStaleNotice({
879
906
  fetchVersions: () => client.request('GET', '/api/ach/auth/config'),
880
- deliver: sessionDeliverer(server, env, o.exec),
907
+ deliver: sessionDeliverer(server, env, o.exec, STALE_NOTICE),
881
908
  lang: isZh(env) ? 'zh' : 'en',
882
909
  firstMs: o.staleFirstMs,
883
910
  log: o.log,
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.99.1";
1
+ export declare const VERSION = "3.99.2";
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.99.1';
1
+ export const VERSION = '3.99.2';
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.99.1",
3
+ "version": "3.99.2",
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",