chat-recall 0.7.26 → 0.7.30
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/channel-detect.d.ts +28 -0
- package/dist/channel-detect.d.ts.map +1 -0
- package/dist/channel-detect.js +128 -0
- package/dist/channel-detect.js.map +1 -0
- package/dist/channel-state.d.ts +35 -0
- package/dist/channel-state.d.ts.map +1 -0
- package/dist/channel-state.js +192 -0
- package/dist/channel-state.js.map +1 -0
- package/dist/channel.d.ts +71 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +157 -0
- package/dist/channel.js.map +1 -0
- package/dist/cli.js +1835 -1219
- package/dist/cli.js.map +1 -1
- package/dist/install-hooks.d.ts.map +1 -1
- package/dist/install-hooks.js +32 -1
- package/dist/install-hooks.js.map +1 -1
- package/dist/mcp-relay.js +73 -1
- package/dist/mcp-relay.js.map +1 -1
- package/dist/mcp.js +1433 -456
- package/dist/mcp.js.map +1 -1
- package/dist/message-hook-core.d.ts +14 -1
- package/dist/message-hook-core.d.ts.map +1 -1
- package/dist/message-hook-core.js +14 -1
- package/dist/message-hook-core.js.map +1 -1
- package/dist/message-hook.js +275 -35
- package/dist/message-hook.js.map +1 -1
- package/dist/watch.js +5 -5
- package/package.json +1 -1
- package/skills/chat-recall-sessions/SKILL.md +25 -2
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Does this argument list name chat-recall as a channel server?
|
|
3
|
+
*
|
|
4
|
+
* Each flag takes a list that runs until the next argument starting with `-`.
|
|
5
|
+
* The list can also hold `plugin:<name>@<marketplace>` and, when the prompt
|
|
6
|
+
* follows the flag, the prompt itself: a token only matches on an exact name.
|
|
7
|
+
*/
|
|
8
|
+
export declare function listsOurServer(args: readonly string[]): boolean;
|
|
9
|
+
/** The command line of a process, or null when it is gone or unreadable. */
|
|
10
|
+
export declare function commandLineOf(pid: number): string[] | null;
|
|
11
|
+
/**
|
|
12
|
+
* The command lines above this process: the parent, then the grandparent.
|
|
13
|
+
*
|
|
14
|
+
* Two, for the same reason the message hook watches two: Claude Code may run us
|
|
15
|
+
* through a shell, and that shell can outlive the Claude process that started
|
|
16
|
+
* it. Deeper would reach a terminal multiplexer or an editor, whose flags say
|
|
17
|
+
* nothing about this session.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ancestorPids(from?: number, depth?: number): number[];
|
|
20
|
+
export declare function ancestorCommandLines(pids?: readonly number[]): string[][];
|
|
21
|
+
export interface ChannelDecision {
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
/** Why, for CHAT_RECALL_MESSAGE_HOOK_DEBUG and the log. */
|
|
24
|
+
reason: string;
|
|
25
|
+
}
|
|
26
|
+
/** Whether this session wants channel delivery. */
|
|
27
|
+
export declare function channelDecision(env?: NodeJS.ProcessEnv, args?: readonly string[], ancestors?: () => string[][]): ChannelDecision;
|
|
28
|
+
//# sourceMappingURL=channel-detect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel-detect.d.ts","sourceRoot":"","sources":["../src/channel-detect.ts"],"names":[],"mappings":"AAsCA;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAQ/D;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAc1D;AAWD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,SAAe,EAAE,KAAK,SAAI,GAAG,MAAM,EAAE,CAQrE;AAED,wBAAgB,oBAAoB,CAAC,IAAI,GAAE,SAAS,MAAM,EAAmB,GAAG,MAAM,EAAE,EAAE,CAOzF;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,2DAA2D;IAC3D,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,mDAAmD;AACnD,wBAAgB,eAAe,CAC7B,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,IAAI,GAAE,SAAS,MAAM,EAA0B,EAC/C,SAAS,GAAE,MAAM,MAAM,EAAE,EAAyB,GACjD,eAAe,CAQjB"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this session asked for chat-recall's channel, and why.
|
|
3
|
+
*
|
|
4
|
+
* Claude Code delivers a channel notification into a session as if the user had
|
|
5
|
+
* typed it, which is the only way to reach a session that is idle: no hook runs,
|
|
6
|
+
* so nothing else can. It is off unless the session names our server on the
|
|
7
|
+
* command line, and the session cannot ask us: the MCP server sees neither the
|
|
8
|
+
* client's arguments nor its own, only its parent's.
|
|
9
|
+
*
|
|
10
|
+
* So this reads the argument lists of the processes above us. `claude` is the
|
|
11
|
+
* parent of the MCP server (or of a shell that runs the hook), and the flag is
|
|
12
|
+
* on its command line, where `/proc` and `ps` both show it.
|
|
13
|
+
*
|
|
14
|
+
* Three ways in, most specific first:
|
|
15
|
+
*
|
|
16
|
+
* CHAT_RECALL_CHANNEL=1 the session wants it (also what a test or a wrapper sets)
|
|
17
|
+
* CHAT_RECALL_CHANNEL=0 never, whatever the command line says
|
|
18
|
+
* --channels server:chat-recall
|
|
19
|
+
* --dangerously-load-development-channels server:chat-recall
|
|
20
|
+
*
|
|
21
|
+
* The second flag is the one that works today: a plain MCP server is not on the
|
|
22
|
+
* approved-channels allowlist, so `--channels` alone is refused and the flag it
|
|
23
|
+
* names is never registered. Both are read because the allowlist is Anthropic's
|
|
24
|
+
* to change, and the day chat-recall is on it, the plain form starts working
|
|
25
|
+
* with no change here.
|
|
26
|
+
*
|
|
27
|
+
* Nothing here imports the engine: the relay calls it before it decides how to
|
|
28
|
+
* serve a session, and the relay's whole point is not to pay for the engine.
|
|
29
|
+
*/
|
|
30
|
+
import { execFileSync } from 'node:child_process';
|
|
31
|
+
import { readFileSync } from 'node:fs';
|
|
32
|
+
/** The argument that names our server, in both spellings Claude Code accepts. */
|
|
33
|
+
const OURS = new Set(['server:chat-recall', 'chat-recall']);
|
|
34
|
+
/** The two flags whose value list names the servers of a session. */
|
|
35
|
+
const FLAGS = new Set(['--channels', '--dangerously-load-development-channels']);
|
|
36
|
+
/**
|
|
37
|
+
* Does this argument list name chat-recall as a channel server?
|
|
38
|
+
*
|
|
39
|
+
* Each flag takes a list that runs until the next argument starting with `-`.
|
|
40
|
+
* The list can also hold `plugin:<name>@<marketplace>` and, when the prompt
|
|
41
|
+
* follows the flag, the prompt itself: a token only matches on an exact name.
|
|
42
|
+
*/
|
|
43
|
+
export function listsOurServer(args) {
|
|
44
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
45
|
+
if (!FLAGS.has(args[i]))
|
|
46
|
+
continue;
|
|
47
|
+
for (let j = i + 1; j < args.length && !args[j].startsWith('-'); j += 1) {
|
|
48
|
+
if (OURS.has(args[j]))
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
/** The command line of a process, or null when it is gone or unreadable. */
|
|
55
|
+
export function commandLineOf(pid) {
|
|
56
|
+
try {
|
|
57
|
+
const parts = readFileSync(`/proc/${pid}/cmdline`, 'utf-8').split('\0').filter(Boolean);
|
|
58
|
+
if (parts.length)
|
|
59
|
+
return parts;
|
|
60
|
+
}
|
|
61
|
+
catch { /* not Linux, or the process is gone */ }
|
|
62
|
+
// Windows has no `ps -o`; Git Bash's `ps` prints its usage to stderr instead,
|
|
63
|
+
// which is why the hook guards on the platform too.
|
|
64
|
+
if (process.platform === 'win32')
|
|
65
|
+
return null;
|
|
66
|
+
try {
|
|
67
|
+
const out = execFileSync('ps', ['-o', 'args=', '-p', String(pid)], {
|
|
68
|
+
encoding: 'utf8', timeout: 2000, stdio: ['ignore', 'pipe', 'ignore'],
|
|
69
|
+
}).trim();
|
|
70
|
+
return out ? out.split(/\s+/) : null;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** The parent of a process, or null at pid 1 and on Windows. */
|
|
77
|
+
function parentOf(pid) {
|
|
78
|
+
try {
|
|
79
|
+
const stat = readFileSync(`/proc/${pid}/stat`, 'utf-8');
|
|
80
|
+
const ppid = Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[1]);
|
|
81
|
+
return ppid > 1 ? ppid : null;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The command lines above this process: the parent, then the grandparent.
|
|
89
|
+
*
|
|
90
|
+
* Two, for the same reason the message hook watches two: Claude Code may run us
|
|
91
|
+
* through a shell, and that shell can outlive the Claude process that started
|
|
92
|
+
* it. Deeper would reach a terminal multiplexer or an editor, whose flags say
|
|
93
|
+
* nothing about this session.
|
|
94
|
+
*/
|
|
95
|
+
export function ancestorPids(from = process.ppid, depth = 2) {
|
|
96
|
+
const out = [];
|
|
97
|
+
let pid = from;
|
|
98
|
+
for (let i = 0; i < depth && pid !== null; i += 1) {
|
|
99
|
+
out.push(pid);
|
|
100
|
+
pid = parentOf(pid);
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
export function ancestorCommandLines(pids = ancestorPids()) {
|
|
105
|
+
const out = [];
|
|
106
|
+
for (const pid of pids) {
|
|
107
|
+
const argv = commandLineOf(pid);
|
|
108
|
+
if (argv)
|
|
109
|
+
out.push(argv);
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
113
|
+
/** Whether this session wants channel delivery. */
|
|
114
|
+
export function channelDecision(env = process.env, args = process.argv.slice(2), ancestors = ancestorCommandLines) {
|
|
115
|
+
const asked = env.CHAT_RECALL_CHANNEL;
|
|
116
|
+
if (asked === '0')
|
|
117
|
+
return { enabled: false, reason: 'CHAT_RECALL_CHANNEL=0' };
|
|
118
|
+
if (asked === '1')
|
|
119
|
+
return { enabled: true, reason: 'CHAT_RECALL_CHANNEL=1' };
|
|
120
|
+
if (asked !== undefined && asked !== '')
|
|
121
|
+
return { enabled: false, reason: `CHAT_RECALL_CHANNEL=${asked} is neither 0 nor 1` };
|
|
122
|
+
if (listsOurServer(args))
|
|
123
|
+
return { enabled: true, reason: 'our own --channels flag' };
|
|
124
|
+
if (ancestors().some(listsOurServer))
|
|
125
|
+
return { enabled: true, reason: 'a --channels flag above us' };
|
|
126
|
+
return { enabled: false, reason: 'no channel flag' };
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=channel-detect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel-detect.js","sourceRoot":"","sources":["../src/channel-detect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,iFAAiF;AACjF,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAAC,CAAC;AAE5D,qEAAqE;AACrE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,yCAAyC,CAAC,CAAC,CAAC;AAEjF;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,IAAuB;IACpD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAAE,SAAS;QAClC,KAAK,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC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AmB,CAAC;IACtC,IAAI,KAAK,KAAK,GAAG;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC;IAC9E,IAAI,KAAK,KAAK,GAAG;QAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,uBAAuB,EAAE,CAAC;IAC7E,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,uBAAuB,KAAK,qBAAqB,EAAE,CAAC;IAC9H,IAAI,cAAc,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,yBAAyB,EAAE,CAAC;IACtF,IAAI,SAAS,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC;QAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,4BAA4B,EAAE,CAAC;IACrG,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** After this with no refresh, a waiter stops trusting the marker. */
|
|
2
|
+
export declare const CHANNEL_GONE_MS = 120000;
|
|
3
|
+
/** The state folder the message hook and the waiter already share. */
|
|
4
|
+
export declare function channelStateDir(): string;
|
|
5
|
+
/**
|
|
6
|
+
* Say which session this process belongs to, keyed by the processes above it.
|
|
7
|
+
*
|
|
8
|
+
* The hook is the only thing that ever learns the session id — Claude Code puts
|
|
9
|
+
* it in the hook payload — and it runs in a sibling process of the MCP server,
|
|
10
|
+
* so a file is the only thing they can share. Keyed by the parent pid because
|
|
11
|
+
* that is what both processes have in common: their own `claude`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function recordSessionForPids(sessionId: string, pids: readonly number[]): void;
|
|
14
|
+
/** The session id the hook recorded for one of the processes above us. */
|
|
15
|
+
export declare function sessionIdFromPids(pids: readonly number[]): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Forget the records of processes that are gone.
|
|
18
|
+
*
|
|
19
|
+
* One file per session, and nothing else would ever remove them: the hook is
|
|
20
|
+
* the only writer and it writes only for its own session.
|
|
21
|
+
*/
|
|
22
|
+
export declare function pruneSessionPids(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Claim delivery for this session, so the waiter stops competing for it.
|
|
25
|
+
*
|
|
26
|
+
* Two consumers of the same lease would each deliver a message: the loser is
|
|
27
|
+
* only spared a duplicate while the winner's lease holds. The marker is how the
|
|
28
|
+
* waiter knows which of them owns the session.
|
|
29
|
+
*/
|
|
30
|
+
export declare function markChannelAlive(sessionId: string): void;
|
|
31
|
+
/** Remove the claim, so the waiter takes over again on the next turn. */
|
|
32
|
+
export declare function clearChannelAlive(sessionId: string): void;
|
|
33
|
+
/** Whether a live channel is delivering for this session right now. */
|
|
34
|
+
export declare function channelOwnsSession(sessionId: string, now?: number): boolean;
|
|
35
|
+
//# sourceMappingURL=channel-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel-state.d.ts","sourceRoot":"","sources":["../src/channel-state.ts"],"names":[],"mappings":"AAuBA,sEAAsE;AACtE,eAAO,MAAM,eAAe,SAAU,CAAC;AAEvC,sEAAsE;AACtE,wBAAgB,eAAe,IAAI,MAAM,CAExC;AA8BD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAarF;AAED,0EAA0E;AAC1E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAWxE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CASvC;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAMxD;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAOzD;AAgBD,uEAAuE;AACvE,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,SAAa,GAAG,OAAO,CAS/E"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two files the message hook and the channel share.
|
|
3
|
+
*
|
|
4
|
+
* They run in sibling processes — Claude Code starts one per hook and one MCP
|
|
5
|
+
* server — and they can tell each other only through the state folder both
|
|
6
|
+
* already use. Two questions cross it:
|
|
7
|
+
*
|
|
8
|
+
* by-pid/<pid> which Claude session is this process's parent?
|
|
9
|
+
* The hook is told the session id; the MCP server is not,
|
|
10
|
+
* and cannot ask. Written by the hook, read by the channel.
|
|
11
|
+
*
|
|
12
|
+
* <session>.channel the channel is delivering for this session.
|
|
13
|
+
* Written by the channel every 30 s, read by the waiter,
|
|
14
|
+
* which stands down while it is fresh. Without it both hold
|
|
15
|
+
* the same lease and race for the same message.
|
|
16
|
+
*
|
|
17
|
+
* Deliberately engine-free: the message hook is its own bundle and starts on
|
|
18
|
+
* every turn of every session, so it must not pay for the tool surface.
|
|
19
|
+
*/
|
|
20
|
+
import { mkdirSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
21
|
+
import { join } from 'node:path';
|
|
22
|
+
import { getDataDir } from '@chat-recall/engine/core/data-dir.js';
|
|
23
|
+
/** After this with no refresh, a waiter stops trusting the marker. */
|
|
24
|
+
export const CHANNEL_GONE_MS = 120_000;
|
|
25
|
+
/** The state folder the message hook and the waiter already share. */
|
|
26
|
+
export function channelStateDir() {
|
|
27
|
+
return join(getDataDir(), 'hook-state', 'messages');
|
|
28
|
+
}
|
|
29
|
+
function byPidDir() {
|
|
30
|
+
return join(channelStateDir(), 'by-pid');
|
|
31
|
+
}
|
|
32
|
+
function markerPath(sessionId) {
|
|
33
|
+
return join(channelStateDir(), `${sessionId}.channel`);
|
|
34
|
+
}
|
|
35
|
+
function readText(path) {
|
|
36
|
+
try {
|
|
37
|
+
return readFileSync(path, 'utf-8').trim();
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The kernel's boot-relative start time of a process, or null.
|
|
45
|
+
*
|
|
46
|
+
* A pid is reused, and a record that outlived its process would then name
|
|
47
|
+
* another session's claude. The start time is what tells two processes with the
|
|
48
|
+
* same pid apart: it differs even when the pid does not.
|
|
49
|
+
*/
|
|
50
|
+
function startTimeOf(pid) {
|
|
51
|
+
try {
|
|
52
|
+
const stat = readFileSync(`/proc/${pid}/stat`, 'utf-8');
|
|
53
|
+
const rest = stat.slice(stat.lastIndexOf(')') + 2).split(' ');
|
|
54
|
+
const started = rest[19]; // field 22 of /proc/<pid>/stat
|
|
55
|
+
return started && /^\d+$/.test(started) ? started : null;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
} // not Linux, or the process is gone
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Say which session this process belongs to, keyed by the processes above it.
|
|
63
|
+
*
|
|
64
|
+
* The hook is the only thing that ever learns the session id — Claude Code puts
|
|
65
|
+
* it in the hook payload — and it runs in a sibling process of the MCP server,
|
|
66
|
+
* so a file is the only thing they can share. Keyed by the parent pid because
|
|
67
|
+
* that is what both processes have in common: their own `claude`.
|
|
68
|
+
*/
|
|
69
|
+
export function recordSessionForPids(sessionId, pids) {
|
|
70
|
+
if (!sessionId || !pids.length)
|
|
71
|
+
return;
|
|
72
|
+
try {
|
|
73
|
+
mkdirSync(byPidDir(), { recursive: true });
|
|
74
|
+
for (const pid of pids) {
|
|
75
|
+
if (!Number.isInteger(pid) || pid <= 1)
|
|
76
|
+
continue;
|
|
77
|
+
const path = join(byPidDir(), String(pid));
|
|
78
|
+
const started = startTimeOf(pid);
|
|
79
|
+
const want = started ? `${sessionId} ${started}` : sessionId;
|
|
80
|
+
if (readText(path) === want)
|
|
81
|
+
continue;
|
|
82
|
+
writeFileSync(path, want);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
catch { /* a session without the file keeps the hook path */ }
|
|
86
|
+
}
|
|
87
|
+
/** The session id the hook recorded for one of the processes above us. */
|
|
88
|
+
export function sessionIdFromPids(pids) {
|
|
89
|
+
for (const pid of pids) {
|
|
90
|
+
const raw = readText(join(byPidDir(), String(pid)));
|
|
91
|
+
if (!raw)
|
|
92
|
+
continue;
|
|
93
|
+
const [id, started] = raw.split(' ');
|
|
94
|
+
// A record with a start time is only for the process that wrote it. One
|
|
95
|
+
// without (an older build, or a platform with no /proc) is taken as is.
|
|
96
|
+
if (started !== undefined && started !== startTimeOf(pid))
|
|
97
|
+
continue;
|
|
98
|
+
if (id)
|
|
99
|
+
return id;
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Forget the records of processes that are gone.
|
|
105
|
+
*
|
|
106
|
+
* One file per session, and nothing else would ever remove them: the hook is
|
|
107
|
+
* the only writer and it writes only for its own session.
|
|
108
|
+
*/
|
|
109
|
+
export function pruneSessionPids() {
|
|
110
|
+
try {
|
|
111
|
+
for (const f of readdirSync(byPidDir())) {
|
|
112
|
+
const pid = Number(f);
|
|
113
|
+
if (!Number.isInteger(pid) || pid <= 1) {
|
|
114
|
+
try {
|
|
115
|
+
unlinkSync(join(byPidDir(), f));
|
|
116
|
+
}
|
|
117
|
+
catch { /* raced */ }
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (alive(pid))
|
|
121
|
+
continue;
|
|
122
|
+
try {
|
|
123
|
+
unlinkSync(join(byPidDir(), f));
|
|
124
|
+
}
|
|
125
|
+
catch { /* raced */ }
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch { /* no directory yet */ }
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Claim delivery for this session, so the waiter stops competing for it.
|
|
132
|
+
*
|
|
133
|
+
* Two consumers of the same lease would each deliver a message: the loser is
|
|
134
|
+
* only spared a duplicate while the winner's lease holds. The marker is how the
|
|
135
|
+
* waiter knows which of them owns the session.
|
|
136
|
+
*/
|
|
137
|
+
export function markChannelAlive(sessionId) {
|
|
138
|
+
try {
|
|
139
|
+
mkdirSync(channelStateDir(), { recursive: true });
|
|
140
|
+
const started = startTimeOf(process.pid);
|
|
141
|
+
writeFileSync(markerPath(sessionId), started ? `${process.pid} ${started}` : String(process.pid));
|
|
142
|
+
}
|
|
143
|
+
catch { /* the waiter keeps delivering; a duplicate beats a silence */ }
|
|
144
|
+
}
|
|
145
|
+
/** Remove the claim, so the waiter takes over again on the next turn. */
|
|
146
|
+
export function clearChannelAlive(sessionId) {
|
|
147
|
+
try {
|
|
148
|
+
// Only our own claim: a session restarted since may have a newer channel,
|
|
149
|
+
// and removing its marker would hand a live session back to a waiter.
|
|
150
|
+
if (readMarker(sessionId)?.pid !== process.pid)
|
|
151
|
+
return;
|
|
152
|
+
unlinkSync(markerPath(sessionId));
|
|
153
|
+
}
|
|
154
|
+
catch { /* already gone */ }
|
|
155
|
+
}
|
|
156
|
+
function readMarker(sessionId) {
|
|
157
|
+
try {
|
|
158
|
+
const path = markerPath(sessionId);
|
|
159
|
+
const [pidText, started] = readFileSync(path, 'utf-8').trim().split(' ');
|
|
160
|
+
const pid = Number(pidText);
|
|
161
|
+
if (!Number.isInteger(pid) || pid <= 1)
|
|
162
|
+
return null;
|
|
163
|
+
return { pid, started, mtime: statSync(path).mtimeMs };
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function alive(pid) {
|
|
170
|
+
try {
|
|
171
|
+
process.kill(pid, 0);
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
return e.code === 'EPERM';
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/** Whether a live channel is delivering for this session right now. */
|
|
179
|
+
export function channelOwnsSession(sessionId, now = Date.now()) {
|
|
180
|
+
const marker = readMarker(sessionId);
|
|
181
|
+
if (!marker)
|
|
182
|
+
return false;
|
|
183
|
+
if (now - marker.mtime > CHANNEL_GONE_MS)
|
|
184
|
+
return false;
|
|
185
|
+
if (!alive(marker.pid))
|
|
186
|
+
return false;
|
|
187
|
+
// The pid alone is not enough for a marker that lives for a week: the kernel
|
|
188
|
+
// reuses pids, and a reused one would hold a waiter off a session that has no
|
|
189
|
+
// channel — the silence this file exists to prevent.
|
|
190
|
+
return marker.started === undefined || marker.started === startTimeOf(marker.pid);
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=channel-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel-state.js","sourceRoot":"","sources":["../src/channel-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAElE,sEAAsE;AACtE,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AAEvC,sEAAsE;AACtE,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,CAAC,UAAU,EAAE,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,QAAQ;IACf,OAAO,IAAI,CAAC,eAAe,EAAE,EAAE,QAAQ,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,UAAU,CAAC,SAAiB;IACnC,OAAO,IAAI,CAAC,eAAe,EAAE,EAAE,GAAG,SAAS,UAAU,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,QAAQ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AAC,GAAG,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The channel: chat-recall's messages delivered into a session that is idle.
|
|
3
|
+
*
|
|
4
|
+
* Every other delivery path chat-recall has is a hook, and a hook runs at the
|
|
5
|
+
* edge of a turn. A session that finished its turn and is waiting for the user
|
|
6
|
+
* runs no hooks at all, so the only thing that could reach it was a waiter
|
|
7
|
+
* process held open with `asyncRewake` and woken by exit code 2 — a process
|
|
8
|
+
* with a lifetime, a timeout, a lock file and a parent to watch. Claude Code's
|
|
9
|
+
* channels need none of that: a local MCP server that declares
|
|
10
|
+
* `capabilities.experimental["claude/channel"]` sends
|
|
11
|
+
* `notifications/claude/channel` and the session takes a turn with it, exactly
|
|
12
|
+
* as if the user had typed it. No turn, no timeout, no lock.
|
|
13
|
+
*
|
|
14
|
+
* What this file does is the half that is ours: find out which session this
|
|
15
|
+
* process belongs to, hold the same long-poll the waiter holds, and hand each
|
|
16
|
+
* batch to the client. The store, the lease and the acknowledgement are the
|
|
17
|
+
* ones already there — a message that the channel takes is leased like any
|
|
18
|
+
* other, so a session cannot get it twice.
|
|
19
|
+
*
|
|
20
|
+
* It runs only when the session named our server on the command line
|
|
21
|
+
* (channel-detect.ts). A session that did not gets nothing from here: its
|
|
22
|
+
* notifications would be dropped by the client, and dropping a message we have
|
|
23
|
+
* already acknowledged is losing it, so we must not start polling at all.
|
|
24
|
+
*/
|
|
25
|
+
import type { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
26
|
+
export interface Target {
|
|
27
|
+
base: string;
|
|
28
|
+
token: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Declare the capability the client looks for.
|
|
32
|
+
*
|
|
33
|
+
* It must be registered BEFORE the transport connects: the client reads
|
|
34
|
+
* `capabilities` from the initialize result and decides once, at connect, that
|
|
35
|
+
* this server may push messages into the session. Registering later is silent —
|
|
36
|
+
* the client has already made up its mind.
|
|
37
|
+
*/
|
|
38
|
+
export declare function declareChannel(server: Server): void;
|
|
39
|
+
/**
|
|
40
|
+
* Prepare a session for channel delivery: declare the capability, and return the
|
|
41
|
+
* function that starts delivering, or null when this session did not ask.
|
|
42
|
+
*
|
|
43
|
+
* The two halves are separate because of when the client decides: it reads the
|
|
44
|
+
* capability once, from the initialize result, and never looks again. So the
|
|
45
|
+
* capability goes in before `connect()`, and the loop starts after — polling a
|
|
46
|
+
* server that is not connected yet would deliver into nothing.
|
|
47
|
+
*/
|
|
48
|
+
export declare function beginChannel(server: Server, debug?: (reason: string) => void): (() => void) | null;
|
|
49
|
+
export interface ChannelDeps {
|
|
50
|
+
server: Server;
|
|
51
|
+
target: Target;
|
|
52
|
+
/** The session id, once the hook has recorded it. */
|
|
53
|
+
sessionId: () => string | null;
|
|
54
|
+
debug?: (reason: string) => void;
|
|
55
|
+
now?: () => number;
|
|
56
|
+
sleep?: (ms: number) => Promise<void>;
|
|
57
|
+
post?: (target: Target, path: string, body: unknown, ms: number) => Promise<{
|
|
58
|
+
status: number;
|
|
59
|
+
body: unknown;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Deliver messages until the session ends.
|
|
64
|
+
*
|
|
65
|
+
* The loop mirrors the waiter's, on purpose: same endpoint, same lease, same
|
|
66
|
+
* acknowledgement rule (ack only after the message has left this process), and
|
|
67
|
+
* the same give-up rules, so a server without this route costs a few retries
|
|
68
|
+
* rather than a spin.
|
|
69
|
+
*/
|
|
70
|
+
export declare function runChannel(deps: ChannelDeps): Promise<void>;
|
|
71
|
+
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAcxE,MAAM,WAAW,MAAM;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE;AAEvD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAEnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAclG;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,SAAS,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAC/B,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CAChH;AAiBD;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAsEjE"}
|
package/dist/channel.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { recallTarget } from '@chat-recall/engine/core/remote-target.js';
|
|
2
|
+
import { formatDelivery } from '@chat-recall/engine/core/session-messages.js';
|
|
3
|
+
import { ancestorPids, channelDecision } from './channel-detect.js';
|
|
4
|
+
import { clearChannelAlive, markChannelAlive, sessionIdFromPids } from './channel-state.js';
|
|
5
|
+
import { fetchWithTimeout } from './http.js';
|
|
6
|
+
/** One long-poll; the server holds it for at most 25 s. */
|
|
7
|
+
const WAIT_SECS = 25;
|
|
8
|
+
/** How long a session with no id yet keeps asking the hook for one. */
|
|
9
|
+
const SESSION_ID_WAIT_MS = 90_000;
|
|
10
|
+
/** How often the marker is refreshed; a waiter treats an older one as gone. */
|
|
11
|
+
const MARK_EVERY_MS = 30_000;
|
|
12
|
+
/**
|
|
13
|
+
* Declare the capability the client looks for.
|
|
14
|
+
*
|
|
15
|
+
* It must be registered BEFORE the transport connects: the client reads
|
|
16
|
+
* `capabilities` from the initialize result and decides once, at connect, that
|
|
17
|
+
* this server may push messages into the session. Registering later is silent —
|
|
18
|
+
* the client has already made up its mind.
|
|
19
|
+
*/
|
|
20
|
+
export function declareChannel(server) {
|
|
21
|
+
server.registerCapabilities({ experimental: { 'claude/channel': {} } });
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Prepare a session for channel delivery: declare the capability, and return the
|
|
25
|
+
* function that starts delivering, or null when this session did not ask.
|
|
26
|
+
*
|
|
27
|
+
* The two halves are separate because of when the client decides: it reads the
|
|
28
|
+
* capability once, from the initialize result, and never looks again. So the
|
|
29
|
+
* capability goes in before `connect()`, and the loop starts after — polling a
|
|
30
|
+
* server that is not connected yet would deliver into nothing.
|
|
31
|
+
*/
|
|
32
|
+
export function beginChannel(server, debug) {
|
|
33
|
+
const decision = channelDecision();
|
|
34
|
+
const log = debug ?? ((reason) => {
|
|
35
|
+
if (process.env.CHAT_RECALL_MESSAGE_HOOK_DEBUG === '1')
|
|
36
|
+
process.stderr.write(`chat-recall channel: ${reason}\n`);
|
|
37
|
+
});
|
|
38
|
+
if (!decision.enabled)
|
|
39
|
+
return null;
|
|
40
|
+
const target = recallTarget();
|
|
41
|
+
if (!target) {
|
|
42
|
+
log('asked for, but this machine has no login');
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
declareChannel(server);
|
|
46
|
+
const pids = ancestorPids();
|
|
47
|
+
return () => {
|
|
48
|
+
void runChannel({ server, target, sessionId: () => sessionIdFromPids(pids), debug: log })
|
|
49
|
+
.catch((e) => log(`stopped: ${e instanceof Error ? e.message : String(e)}`));
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function headers(target) {
|
|
53
|
+
const h = { 'content-type': 'application/json' };
|
|
54
|
+
if (target.token)
|
|
55
|
+
h.authorization = `Bearer ${target.token}`;
|
|
56
|
+
return h;
|
|
57
|
+
}
|
|
58
|
+
async function postJson(target, path, body, ms) {
|
|
59
|
+
const res = await fetchWithTimeout(`${target.base}${path}`, {
|
|
60
|
+
method: 'POST', headers: headers(target), body: JSON.stringify(body),
|
|
61
|
+
}, ms);
|
|
62
|
+
return { status: res.status, body: res.ok ? await res.json() : null };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Deliver messages until the session ends.
|
|
66
|
+
*
|
|
67
|
+
* The loop mirrors the waiter's, on purpose: same endpoint, same lease, same
|
|
68
|
+
* acknowledgement rule (ack only after the message has left this process), and
|
|
69
|
+
* the same give-up rules, so a server without this route costs a few retries
|
|
70
|
+
* rather than a spin.
|
|
71
|
+
*/
|
|
72
|
+
export async function runChannel(deps) {
|
|
73
|
+
const debug = deps.debug ?? (() => { });
|
|
74
|
+
const sleep = deps.sleep ?? ((ms) => new Promise((r) => { setTimeout(r, ms); }));
|
|
75
|
+
const post = deps.post ?? postJson;
|
|
76
|
+
let sessionId = deps.sessionId();
|
|
77
|
+
const giveUpAt = Date.now() + SESSION_ID_WAIT_MS;
|
|
78
|
+
while (!sessionId) {
|
|
79
|
+
if (Date.now() > giveUpAt) {
|
|
80
|
+
debug('channel: the hook never recorded this session');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
await sleep(500);
|
|
84
|
+
sessionId = deps.sessionId();
|
|
85
|
+
}
|
|
86
|
+
debug(`channel: delivering for ${sessionId}`);
|
|
87
|
+
markChannelAlive(sessionId);
|
|
88
|
+
let markedAt = Date.now();
|
|
89
|
+
let failures = 0;
|
|
90
|
+
let notFound = 0;
|
|
91
|
+
try {
|
|
92
|
+
for (;;) {
|
|
93
|
+
if (Date.now() - markedAt >= MARK_EVERY_MS) {
|
|
94
|
+
markChannelAlive(sessionId);
|
|
95
|
+
markedAt = Date.now();
|
|
96
|
+
}
|
|
97
|
+
let r;
|
|
98
|
+
try {
|
|
99
|
+
r = await post(deps.target, '/api/live-sessions/wait', { sessionId, timeoutSecs: WAIT_SECS }, (WAIT_SECS + 15) * 1000);
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
r = { status: 0, body: null };
|
|
103
|
+
debug(`channel: request failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
104
|
+
}
|
|
105
|
+
if (r.status === 401 || r.status === 402 || r.status === 403) {
|
|
106
|
+
debug(`channel: HTTP ${r.status}`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const body = r.body;
|
|
110
|
+
if (!body) {
|
|
111
|
+
// The same numbers as the waiter: a 404 at the start is the
|
|
112
|
+
// SessionStart report still on its way, and a network that keeps
|
|
113
|
+
// failing is not worth an hour of retries from a process the session
|
|
114
|
+
// cannot see.
|
|
115
|
+
failures += 1;
|
|
116
|
+
notFound = r.status === 404 ? notFound + 1 : 0;
|
|
117
|
+
if (notFound >= 5 || failures > 120) {
|
|
118
|
+
debug('channel: giving up on the server');
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
await sleep(Math.min(30_000, 1000 * 2 ** Math.min(failures, 5)));
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
failures = 0;
|
|
125
|
+
notFound = 0;
|
|
126
|
+
if (body.ended) {
|
|
127
|
+
debug('channel: the session ended');
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const messages = body.messages ?? [];
|
|
131
|
+
if (!messages.length)
|
|
132
|
+
continue;
|
|
133
|
+
const content = formatDelivery(sessionId, messages, {
|
|
134
|
+
now: (deps.now ?? Date.now)(),
|
|
135
|
+
labels: new Map(Object.entries(body.labels ?? {})),
|
|
136
|
+
});
|
|
137
|
+
try {
|
|
138
|
+
await deps.server.notification({
|
|
139
|
+
method: 'notifications/claude/channel',
|
|
140
|
+
params: { content, meta: { from: 'chat-recall', session: sessionId } },
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
// A message the client never got must not be acknowledged: the lease
|
|
145
|
+
// ends and the waiter, or the next turn, offers it again.
|
|
146
|
+
debug(`channel: could not emit: ${e instanceof Error ? e.message : String(e)}`);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
await post(deps.target, '/api/live-sessions/ack', { sessionId, ids: messages.map((m) => m.id) }, 3000)
|
|
150
|
+
.catch(() => { });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
clearChannelAlive(sessionId);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.js","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AACzE,OAAO,EAAE,cAAc,EAAoB,MAAM,8CAA8C,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7C,2DAA2D;AAC3D,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,uEAAuE;AACvE,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,+EAA+E;AAC/E,MAAM,aAAa,GAAG,MAAM,CAAC;AAI7B;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,MAA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