@koalaauto/agentchannel 3.99.1 → 3.99.3
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.
- package/dist/src/attention.d.ts +27 -0
- package/dist/src/attention.js +63 -2
- package/dist/src/mcp.d.ts +10 -7
- package/dist/src/mcp.js +42 -15
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
package/dist/src/attention.d.ts
CHANGED
|
@@ -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). */
|
package/dist/src/attention.js
CHANGED
|
@@ -31,7 +31,7 @@ export function attentionKind(type) {
|
|
|
31
31
|
return 'mention';
|
|
32
32
|
if (/repl|change_request|changes_requested/.test(t))
|
|
33
33
|
return 'reply';
|
|
34
|
-
if (/task/.test(t))
|
|
34
|
+
if (/task|accept|review|merge|takeover/.test(t))
|
|
35
35
|
return 'task';
|
|
36
36
|
return 'item';
|
|
37
37
|
}
|
|
@@ -54,7 +54,9 @@ export function normalizeAttention(r, fromNotifications = false) {
|
|
|
54
54
|
counts[k] = (counts[k] ?? 0) + 1;
|
|
55
55
|
ids.push(String(x.id ?? x.event_id ?? x.message_id ?? `${k}:${ids.length}`));
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
// the hub's own list of what waits (`waiting`); an older hub has only `by_kind`, which also counts the day's activity
|
|
58
|
+
// around the person (mentions of their agents, replies in their threads): of it only the kinds that wait are taken
|
|
59
|
+
const byKind = r?.waiting ?? waitingOf(r?.by_kind) ?? r?.counts;
|
|
58
60
|
if (!items.length && byKind && typeof byKind === 'object') {
|
|
59
61
|
// GET /me/attention: counts only (no ids); "new" = a count went up (AttentionNotifier)
|
|
60
62
|
for (const [key, n] of Object.entries(byKind)) {
|
|
@@ -72,6 +74,14 @@ export function normalizeAttention(r, fromNotifications = false) {
|
|
|
72
74
|
.map((x) => ({ id: line(x.id, 40), task: line(x.task, 20), runs: line(x.runs), money: line(x.money, 80), confirm: line(x.confirm, 40), decline: line(x.decline, 40) }));
|
|
73
75
|
return { total, counts, ids, confirmations };
|
|
74
76
|
}
|
|
77
|
+
/** GET /me/attention `by_kind` of a hub without `waiting`: the kinds that wait for the person, the @ of themself as `mention`. */
|
|
78
|
+
const WAITING_KINDS = ['decision', 'question', 'acceptance', 'merge', 'review', 'takeover', 'unanswered'];
|
|
79
|
+
function waitingOf(by) {
|
|
80
|
+
if (!by || typeof by !== 'object')
|
|
81
|
+
return undefined;
|
|
82
|
+
const b = by;
|
|
83
|
+
return { ...Object.fromEntries(WAITING_KINDS.map((k) => [k, Number(b[k]) || 0])), mention: Number(b.mention_you) || 0 };
|
|
84
|
+
}
|
|
75
85
|
/** What needs the owner now (agent key: the owner's view). */
|
|
76
86
|
export async function fetchAttention(request) {
|
|
77
87
|
try {
|
|
@@ -110,6 +120,57 @@ export function confirmationText(c, lang = 'en') {
|
|
|
110
120
|
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
121
|
}
|
|
112
122
|
export const NOTICE_GAP_MS = 10 * 60_000;
|
|
123
|
+
/**
|
|
124
|
+
* A reminder that waits for the session's next tool result (docs/specs/mcp-client.md §7). The other ways into a session
|
|
125
|
+
* depend on the client (a Claude Code channel needs a start flag, `codex queue` the session's id, which Codex does not give
|
|
126
|
+
* its MCP servers) and fail without a sound; a tool result is what every client hands its model. One line per kind, the
|
|
127
|
+
* newest; taken once. A count of what waits that is older than `staleMs` is counted again before it is said (`fresh`),
|
|
128
|
+
* so a session that was idle for hours does not announce what has been answered since.
|
|
129
|
+
*/
|
|
130
|
+
export class PendingNotice {
|
|
131
|
+
o;
|
|
132
|
+
held = new Map();
|
|
133
|
+
/** What waits now, as the line to say, or null when nothing does. Set by the session's notifier. */
|
|
134
|
+
fresh;
|
|
135
|
+
constructor(o = {}) {
|
|
136
|
+
this.o = o;
|
|
137
|
+
}
|
|
138
|
+
now() {
|
|
139
|
+
return (this.o.now ?? Date.now)();
|
|
140
|
+
}
|
|
141
|
+
put(kind, text) {
|
|
142
|
+
if (text)
|
|
143
|
+
this.held.set(kind, { text, at: this.now() });
|
|
144
|
+
}
|
|
145
|
+
/** The person is reading what waits themselves: nothing to tell them about it. */
|
|
146
|
+
drop(kind) {
|
|
147
|
+
this.held.delete(kind);
|
|
148
|
+
}
|
|
149
|
+
get waiting() {
|
|
150
|
+
return this.held.size > 0;
|
|
151
|
+
}
|
|
152
|
+
/** Everything held, once: the lines for the next tool result ([] when nothing). */
|
|
153
|
+
async take() {
|
|
154
|
+
if (!this.held.size)
|
|
155
|
+
return [];
|
|
156
|
+
const all = [...this.held];
|
|
157
|
+
this.held.clear();
|
|
158
|
+
const out = [];
|
|
159
|
+
for (const [kind, n] of all) {
|
|
160
|
+
if (kind !== ATTENTION_NOTICE || !this.fresh || this.now() - n.at <= (this.o.staleMs ?? NOTICE_GAP_MS))
|
|
161
|
+
out.push(n.text);
|
|
162
|
+
else {
|
|
163
|
+
const now = await this.fresh().catch(() => n.text);
|
|
164
|
+
if (now)
|
|
165
|
+
out.push(now);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/** The kinds of reminder a session holds: what waits for the person, and that a newer `ach` is out. */
|
|
172
|
+
export const ATTENTION_NOTICE = 'attention';
|
|
173
|
+
export const STALE_NOTICE = 'stale';
|
|
113
174
|
export class AttentionNotifier {
|
|
114
175
|
o;
|
|
115
176
|
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
|
-
* -
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
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
|
-
|
|
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
|
-
* -
|
|
835
|
-
*
|
|
836
|
-
*
|
|
837
|
-
*
|
|
838
|
-
*
|
|
839
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
869
|
+
sent = true;
|
|
849
870
|
}
|
|
850
871
|
catch {
|
|
851
|
-
|
|
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,
|
package/dist/src/version.d.ts
CHANGED
package/dist/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koalaauto/agentchannel",
|
|
3
|
-
"version": "3.99.
|
|
3
|
+
"version": "3.99.3",
|
|
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",
|