@cotal-ai/connector-claude-code 0.92.2 → 0.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/dist/app-host.d.ts +2 -5
- package/dist/app-host.d.ts.map +1 -1
- package/dist/claude-events.d.ts +8 -0
- package/dist/claude-events.d.ts.map +1 -0
- package/dist/hook.cjs +264 -13
- package/dist/hooks.d.ts +5 -0
- package/dist/hooks.d.ts.map +1 -1
- package/dist/index.js +37 -7
- package/dist/mcp.cjs +1061 -416
- package/dist/mcp.d.ts.map +1 -1
- package/dist/monitor.cjs +286 -9
- package/dist/native-binding.d.ts +7 -0
- package/dist/native-binding.d.ts.map +1 -0
- package/dist/native-deliveries.d.ts +31 -0
- package/dist/native-deliveries.d.ts.map +1 -0
- package/dist/wake-feed.d.ts +11 -3
- package/dist/wake-feed.d.ts.map +1 -1
- package/hooks/native-wake.js +204 -19
- package/package.json +4 -4
package/dist/mcp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAqJtD,yFAAyF;AACzF,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,KAAK,EAAE,QAAQ,CAAC;IAChB,MAAM,EAAE,QAAQ,CAAC;IACjB;uDACmD;IACnD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;gFAC4E;IAC5E,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb;uDACmD;IACnD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;+BAE+B;AAC/B,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,CAAC,CAQ3F"}
|
package/dist/monitor.cjs
CHANGED
|
@@ -1,10 +1,133 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
// src/monitor.ts
|
|
4
|
-
var
|
|
4
|
+
var import_node_net2 = require("node:net");
|
|
5
5
|
|
|
6
6
|
// ../../packages/core/dist/secret-fs.js
|
|
7
|
+
var import_node_fs = require("node:fs");
|
|
8
|
+
var import_node_child_process = require("node:child_process");
|
|
9
|
+
var import_node_path = require("node:path");
|
|
7
10
|
var isWin = process.platform === "win32";
|
|
11
|
+
function sys32(exe) {
|
|
12
|
+
const root = process.env.SystemRoot || process.env.windir || "C:\\Windows";
|
|
13
|
+
return (0, import_node_path.join)(root, "System32", exe);
|
|
14
|
+
}
|
|
15
|
+
var cachedSid;
|
|
16
|
+
function ownerSid() {
|
|
17
|
+
if (cachedSid)
|
|
18
|
+
return cachedSid;
|
|
19
|
+
const out = (0, import_node_child_process.execFileSync)(sys32("whoami.exe"), ["/user", "/fo", "csv", "/nh"], { encoding: "utf8" });
|
|
20
|
+
const sid = out.trim().split(",").pop()?.replace(/^"|"$/g, "").trim();
|
|
21
|
+
if (!sid || !/^S-1-/.test(sid))
|
|
22
|
+
throw new Error(`could not determine the current user's SID from \`whoami\` (got: ${out.trim()})`);
|
|
23
|
+
cachedSid = sid;
|
|
24
|
+
return sid;
|
|
25
|
+
}
|
|
26
|
+
var BROAD_SIDS = ["S-1-1-0", "S-1-5-11", "S-1-5-32-545"];
|
|
27
|
+
function hardenPrivate(path, kind) {
|
|
28
|
+
if (!isWin) {
|
|
29
|
+
if (kind === "file")
|
|
30
|
+
(0, import_node_fs.closeSync)(openPrivate(path, import_node_fs.constants.O_RDONLY));
|
|
31
|
+
else
|
|
32
|
+
(0, import_node_fs.chmodSync)(path, 448);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const perm = kind === "dir" ? "(OI)(CI)(F)" : "(F)";
|
|
36
|
+
const removeBroad = BROAD_SIDS.flatMap((sid) => ["/remove:g", `*${sid}`]);
|
|
37
|
+
const grant = (sid) => ["/grant:r", `*${sid}:${perm}`];
|
|
38
|
+
try {
|
|
39
|
+
(0, import_node_child_process.execFileSync)(sys32("icacls.exe"), [
|
|
40
|
+
path,
|
|
41
|
+
"/inheritance:r",
|
|
42
|
+
...removeBroad,
|
|
43
|
+
...grant(ownerSid()),
|
|
44
|
+
...grant("S-1-5-18"),
|
|
45
|
+
...grant("S-1-5-32-544")
|
|
46
|
+
], { stdio: ["ignore", "ignore", "pipe"] });
|
|
47
|
+
} catch (e) {
|
|
48
|
+
throw new Error(`failed to harden ${kind} "${path}" to private via icacls: ${e.message.trim()}. Cotal will not leave a secret with a permissive ACL - ensure the path is on an NTFS volume and %SystemRoot%\\System32\\icacls.exe is available.`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function notPrivate(path, why) {
|
|
52
|
+
const refused = new Error(`refusing to write "${path}": it ${why}; it was left unchanged`);
|
|
53
|
+
refused.code = "EPERM";
|
|
54
|
+
return refused;
|
|
55
|
+
}
|
|
56
|
+
function openPrivate(path, flags) {
|
|
57
|
+
if (isWin) {
|
|
58
|
+
const fd2 = (0, import_node_fs.openSync)(path, flags, 384);
|
|
59
|
+
try {
|
|
60
|
+
(0, import_node_fs.fchmodSync)(fd2, 384);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
(0, import_node_fs.closeSync)(fd2);
|
|
63
|
+
throw e;
|
|
64
|
+
}
|
|
65
|
+
return fd2;
|
|
66
|
+
}
|
|
67
|
+
let fd;
|
|
68
|
+
try {
|
|
69
|
+
fd = (0, import_node_fs.openSync)(path, flags | import_node_fs.constants.O_NOFOLLOW | import_node_fs.constants.O_NONBLOCK, 384);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
if (e.code === "ELOOP")
|
|
72
|
+
throw notPrivate(path, "is a symlink");
|
|
73
|
+
throw e;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const info = (0, import_node_fs.fstatSync)(fd);
|
|
77
|
+
if (!info.isFile())
|
|
78
|
+
throw notPrivate(path, "is not a regular file");
|
|
79
|
+
if (info.uid !== process.getuid())
|
|
80
|
+
throw notPrivate(path, `is owned by uid ${info.uid}, not this user`);
|
|
81
|
+
(0, import_node_fs.fchmodSync)(fd, 384);
|
|
82
|
+
return fd;
|
|
83
|
+
} catch (e) {
|
|
84
|
+
(0, import_node_fs.closeSync)(fd);
|
|
85
|
+
throw e;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function writeSecretFile(path, data) {
|
|
89
|
+
writePrivate(path, data, false);
|
|
90
|
+
}
|
|
91
|
+
function writeBytes(path, data, exclusive) {
|
|
92
|
+
const fd = openPrivate(path, import_node_fs.constants.O_WRONLY | import_node_fs.constants.O_CREAT | (exclusive ? import_node_fs.constants.O_EXCL : 0));
|
|
93
|
+
try {
|
|
94
|
+
(0, import_node_fs.ftruncateSync)(fd);
|
|
95
|
+
(0, import_node_fs.writeFileSync)(fd, data);
|
|
96
|
+
} finally {
|
|
97
|
+
(0, import_node_fs.closeSync)(fd);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function writePrivate(path, data, exclusive) {
|
|
101
|
+
writeBytes(path, data, exclusive);
|
|
102
|
+
if (!isWin)
|
|
103
|
+
return;
|
|
104
|
+
try {
|
|
105
|
+
hardenPrivate(path, "file");
|
|
106
|
+
} catch (e) {
|
|
107
|
+
try {
|
|
108
|
+
(0, import_node_fs.unlinkSync)(path);
|
|
109
|
+
} catch {
|
|
110
|
+
}
|
|
111
|
+
throw e;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function writeSecretFileAtomic(path, data) {
|
|
115
|
+
const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
116
|
+
try {
|
|
117
|
+
writeSecretFile(tmp, data);
|
|
118
|
+
(0, import_node_fs.renameSync)(tmp, path);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
try {
|
|
121
|
+
(0, import_node_fs.unlinkSync)(tmp);
|
|
122
|
+
} catch {
|
|
123
|
+
}
|
|
124
|
+
throw e;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function mkSecretDir(path) {
|
|
128
|
+
(0, import_node_fs.mkdirSync)(path, { recursive: true, mode: 448 });
|
|
129
|
+
hardenPrivate(path, "dir");
|
|
130
|
+
}
|
|
8
131
|
|
|
9
132
|
// ../connector-core/dist/session-env.js
|
|
10
133
|
function hasIdentity(env = process.env) {
|
|
@@ -15,18 +138,31 @@ function hasIdentity(env = process.env) {
|
|
|
15
138
|
var MAX_FRAME_BYTES = 1 << 20;
|
|
16
139
|
|
|
17
140
|
// src/wake-feed.ts
|
|
18
|
-
var
|
|
141
|
+
var import_node_fs2 = require("node:fs");
|
|
19
142
|
var import_node_os = require("node:os");
|
|
20
|
-
var
|
|
143
|
+
var import_node_path2 = require("node:path");
|
|
144
|
+
|
|
145
|
+
// src/native-deliveries.ts
|
|
146
|
+
var ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
147
|
+
var INLINE_FRAME_LIMIT = 4096;
|
|
148
|
+
function isNativeInlineFrame(value) {
|
|
149
|
+
if (!value || typeof value !== "object") return false;
|
|
150
|
+
const frame = value;
|
|
151
|
+
const item = frame.inline;
|
|
152
|
+
return typeof frame.id === "string" && ID.test(frame.id) && typeof frame.route === "string" && !!item && item.v === 1 && typeof item.receipt === "string" && ID.test(item.receipt) && typeof item.session === "string" && ID.test(item.session) && typeof item.text === "string" && item.text.startsWith(`Cotal: inline messages for connection_id ${frame.id}.
|
|
153
|
+
`) && Number.isInteger(item.count) && item.count > 0 && item.count <= 8 && Number.isInteger(item.remaining) && item.remaining >= 0 && JSON.stringify(frame).length <= INLINE_FRAME_LIMIT;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/wake-feed.ts
|
|
21
157
|
var WAKE_ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
22
158
|
var WIN_PIPES = "\\\\.\\pipe\\";
|
|
23
159
|
var WIN_PREFIX = "cotal-claude-wake-";
|
|
24
160
|
function wakeDir() {
|
|
25
161
|
if (process.platform === "win32") return WIN_PIPES;
|
|
26
162
|
const uid = process.getuid();
|
|
27
|
-
const dir = (0,
|
|
28
|
-
(0,
|
|
29
|
-
const st = (0,
|
|
163
|
+
const dir = (0, import_node_path2.join)((0, import_node_os.tmpdir)(), `cotal-claude-wake-${uid}`);
|
|
164
|
+
(0, import_node_fs2.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
165
|
+
const st = (0, import_node_fs2.lstatSync)(dir);
|
|
30
166
|
if (!st.isDirectory() || st.uid !== uid || (st.mode & 63) !== 0) throw new Error(`${dir} is not a private directory of this user's`);
|
|
31
167
|
return dir;
|
|
32
168
|
}
|
|
@@ -42,20 +178,125 @@ function alive(pid) {
|
|
|
42
178
|
}
|
|
43
179
|
function wakeSocketPath(claudePid, serverPid = process.pid) {
|
|
44
180
|
const dir = wakeDir();
|
|
45
|
-
return process.platform === "win32" ? `${dir}${entryName(claudePid, serverPid)}` : (0,
|
|
181
|
+
return process.platform === "win32" ? `${dir}${entryName(claudePid, serverPid)}` : (0, import_node_path2.join)(dir, entryName(claudePid, serverPid));
|
|
46
182
|
}
|
|
47
183
|
function wakeSockets(claudePid) {
|
|
48
184
|
const dir = wakeDir();
|
|
49
|
-
return (0,
|
|
185
|
+
return (0, import_node_fs2.readdirSync)(dir).flatMap((name) => {
|
|
50
186
|
const m = ENTRY.exec(name);
|
|
51
187
|
return m?.[1] === String(claudePid) && alive(Number(m[2])) ? [wakeSocketPath(claudePid, Number(m[2]))] : [];
|
|
52
188
|
});
|
|
53
189
|
}
|
|
190
|
+
function nativeSocketPath(feed) {
|
|
191
|
+
return `${feed}.native`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// src/native-binding.ts
|
|
195
|
+
var import_node_fs3 = require("node:fs");
|
|
196
|
+
var import_node_net = require("node:net");
|
|
197
|
+
var import_node_os2 = require("node:os");
|
|
198
|
+
var import_node_path3 = require("node:path");
|
|
199
|
+
function stateFile(session) {
|
|
200
|
+
if (!WAKE_ID.test(session)) throw new Error("invalid native session identity");
|
|
201
|
+
const root = (0, import_node_path3.join)((0, import_node_os2.tmpdir)(), `cotal-claude-native-${process.getuid?.() ?? "local"}`);
|
|
202
|
+
const st = (0, import_node_fs3.lstatSync)(root, { throwIfNoEntry: false });
|
|
203
|
+
if (st && (!st.isDirectory() || process.getuid && st.uid !== process.getuid()))
|
|
204
|
+
throw new Error("native session state is not this user's private directory");
|
|
205
|
+
mkSecretDir(root);
|
|
206
|
+
return (0, import_node_path3.join)(root, `${session}.json`);
|
|
207
|
+
}
|
|
208
|
+
function readRecord(file) {
|
|
209
|
+
const st = (0, import_node_fs3.lstatSync)(file, { throwIfNoEntry: false });
|
|
210
|
+
if (!st) return void 0;
|
|
211
|
+
if (!st.isFile() || st.size > 16384 || process.getuid && (st.uid !== process.getuid() || (st.mode & 63) !== 0))
|
|
212
|
+
throw new Error("native session state is not an owner-private bounded regular file");
|
|
213
|
+
const value = JSON.parse((0, import_node_fs3.readFileSync)(file, "utf8"));
|
|
214
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("invalid native session state");
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
function transcriptMatches(session, path) {
|
|
218
|
+
return typeof path === "string" && (0, import_node_path3.isAbsolute)(path) && (0, import_node_path3.basename)(path) === `${session}.jsonl`;
|
|
219
|
+
}
|
|
220
|
+
function readPersonalBinding(session) {
|
|
221
|
+
const event = readRecord(stateFile(session));
|
|
222
|
+
if (!event || event.session_id !== session || !transcriptMatches(session, event.transcript_path))
|
|
223
|
+
throw new Error("no native command-hook transcript binding for this session");
|
|
224
|
+
return event;
|
|
225
|
+
}
|
|
226
|
+
async function forward(event, hostPid) {
|
|
227
|
+
const paths = wakeSockets(hostPid);
|
|
228
|
+
if (!paths.length) throw new Error("no local native lifecycle server");
|
|
229
|
+
await Promise.all(paths.map((path) => new Promise((resolve, reject) => {
|
|
230
|
+
const socket = (0, import_node_net.createConnection)(nativeSocketPath(path));
|
|
231
|
+
let reply = "";
|
|
232
|
+
socket.setEncoding("utf8");
|
|
233
|
+
socket.setTimeout(2e3, () => socket.destroy(new Error("native lifecycle relay timed out")));
|
|
234
|
+
socket.on("connect", () => socket.write(`${JSON.stringify({ op: "native", event })}
|
|
235
|
+
`));
|
|
236
|
+
socket.on("data", (data) => {
|
|
237
|
+
reply += data;
|
|
238
|
+
if (reply.length > 128) socket.destroy();
|
|
239
|
+
});
|
|
240
|
+
socket.on("error", reject);
|
|
241
|
+
socket.on("close", () => {
|
|
242
|
+
try {
|
|
243
|
+
if (JSON.parse(reply).ok === true) resolve();
|
|
244
|
+
else reject(new Error("native lifecycle binding refused"));
|
|
245
|
+
} catch {
|
|
246
|
+
reject(new Error("native lifecycle binding was not confirmed"));
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
})));
|
|
250
|
+
}
|
|
251
|
+
async function bindPersonalSession(event, hostPid) {
|
|
252
|
+
const session = event.session_id;
|
|
253
|
+
if (typeof session !== "string" || !Number.isInteger(hostPid) || hostPid <= 0)
|
|
254
|
+
throw new Error("invalid native lifecycle binding");
|
|
255
|
+
const previous = readPersonalBinding(session);
|
|
256
|
+
if (previous.transcript_path !== event.transcript_path)
|
|
257
|
+
throw new Error("native lifecycle binding does not match the command hook");
|
|
258
|
+
writeSecretFileAtomic(`${stateFile(session)}.host`, JSON.stringify({ hostPid }));
|
|
259
|
+
await forward(event, hostPid);
|
|
260
|
+
}
|
|
54
261
|
|
|
55
262
|
// src/monitor.ts
|
|
56
263
|
var SCAN_MS = 1e3;
|
|
57
264
|
var wakeEvent = (id) => `Cotal: a new message for connection_id ${id}. Read it with cotal_inbox.`;
|
|
58
265
|
var previewEvent = (id, preview) => `Cotal preview for connection_id ${id}: ${JSON.stringify(preview)}`;
|
|
266
|
+
async function relayNative(claude, raw) {
|
|
267
|
+
const event = JSON.parse(raw);
|
|
268
|
+
if (typeof event.session_id !== "string" || !WAKE_ID.test(event.session_id) || raw.length > 8192)
|
|
269
|
+
throw new Error("invalid native lifecycle frame");
|
|
270
|
+
await bindPersonalSession(event, claude);
|
|
271
|
+
}
|
|
272
|
+
async function relayInline(claude, session) {
|
|
273
|
+
let input = "";
|
|
274
|
+
for await (const piece of process.stdin) {
|
|
275
|
+
input += piece;
|
|
276
|
+
if (input.length > 1024) throw new Error("inline receipt is too large");
|
|
277
|
+
}
|
|
278
|
+
const frame = JSON.parse(input);
|
|
279
|
+
if (!session || frame.session !== session || typeof frame.route !== "string" || !wakeSockets(claude).includes(frame.route) || !["claim", "commit", "defer", "reject", "retry"].includes(String(frame.action)) || typeof frame.receipt !== "string" || !WAKE_ID.test(frame.receipt) || typeof frame.id !== "string" || !WAKE_ID.test(frame.id)) throw new Error("invalid inline receipt");
|
|
280
|
+
const reply = await new Promise((resolve, reject) => {
|
|
281
|
+
const socket = (0, import_node_net2.createConnection)(nativeSocketPath(frame.route));
|
|
282
|
+
let buffer = "";
|
|
283
|
+
socket.setEncoding("utf8");
|
|
284
|
+
socket.setTimeout(2e3, () => socket.destroy(new Error("inline receipt timed out")));
|
|
285
|
+
socket.on("connect", () => socket.write(`${JSON.stringify({ ...frame, op: "inline" })}
|
|
286
|
+
`));
|
|
287
|
+
socket.on("data", (piece) => {
|
|
288
|
+
buffer += piece;
|
|
289
|
+
if (buffer.length > INLINE_FRAME_LIMIT + 64) socket.destroy(new Error("inline reply is too large"));
|
|
290
|
+
});
|
|
291
|
+
socket.on("error", reject);
|
|
292
|
+
socket.on("close", () => resolve(buffer));
|
|
293
|
+
});
|
|
294
|
+
const result = JSON.parse(reply);
|
|
295
|
+
if (result.ok !== true && result.ok !== false || result.frame !== void 0 && !isNativeInlineFrame(result.frame))
|
|
296
|
+
throw new Error("invalid inline reply");
|
|
297
|
+
process.stdout.write(`${JSON.stringify(result)}
|
|
298
|
+
`);
|
|
299
|
+
}
|
|
59
300
|
function main() {
|
|
60
301
|
if (hasIdentity()) return;
|
|
61
302
|
const claude = process.argv.includes("--native") ? process.ppid : Number(process.env.CLAUDE_PID);
|
|
@@ -64,19 +305,55 @@ function main() {
|
|
|
64
305
|
process.exitCode = 1;
|
|
65
306
|
return;
|
|
66
307
|
}
|
|
308
|
+
const bindingAt = process.argv.indexOf("--native-binding");
|
|
309
|
+
if (bindingAt >= 0) {
|
|
310
|
+
try {
|
|
311
|
+
process.stdout.write(`${JSON.stringify(readPersonalBinding(process.argv[bindingAt + 1] ?? ""))}
|
|
312
|
+
`);
|
|
313
|
+
} catch {
|
|
314
|
+
process.exitCode = 1;
|
|
315
|
+
}
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const eventAt = process.argv.indexOf("--native-event");
|
|
319
|
+
if (eventAt >= 0) {
|
|
320
|
+
void relayNative(claude, process.argv[eventAt + 1] ?? "").catch(() => {
|
|
321
|
+
process.stderr.write("[cotal-monitor] native lifecycle binding was not confirmed\n");
|
|
322
|
+
process.exitCode = 1;
|
|
323
|
+
});
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const sessionAt = process.argv.indexOf("--session");
|
|
327
|
+
const session = sessionAt >= 0 ? process.argv[sessionAt + 1] : void 0;
|
|
328
|
+
if (session !== void 0 && !WAKE_ID.test(session)) throw new Error("invalid native session identity");
|
|
329
|
+
if (process.argv.includes("--native-delivery")) {
|
|
330
|
+
void relayInline(claude, session).catch(() => {
|
|
331
|
+
process.exitCode = 1;
|
|
332
|
+
});
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
67
335
|
const reading = /* @__PURE__ */ new Set();
|
|
68
336
|
const read = (path) => {
|
|
69
337
|
reading.add(path);
|
|
70
338
|
let buf = "";
|
|
71
|
-
const s = (0,
|
|
339
|
+
const s = (0, import_node_net2.createConnection)(path);
|
|
72
340
|
s.setEncoding("utf8");
|
|
341
|
+
if (session) s.on("connect", () => s.write(`${JSON.stringify({ op: "watch", session, inline: 1 })}
|
|
342
|
+
`));
|
|
73
343
|
s.on("data", (d) => {
|
|
74
344
|
buf += d;
|
|
75
345
|
for (let i; (i = buf.indexOf("\n")) >= 0; ) {
|
|
76
346
|
const line = buf.slice(0, i);
|
|
77
347
|
buf = buf.slice(i + 1);
|
|
78
348
|
try {
|
|
349
|
+
if (line.length > INLINE_FRAME_LIMIT) continue;
|
|
79
350
|
const frame = JSON.parse(line);
|
|
351
|
+
if (isNativeInlineFrame(frame)) {
|
|
352
|
+
if (frame.inline.session === session && frame.route === path)
|
|
353
|
+
process.stdout.write(`Cotal inline delivery: ${JSON.stringify(frame)}
|
|
354
|
+
`);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
80
357
|
if (typeof frame.id !== "string" || !WAKE_ID.test(frame.id)) continue;
|
|
81
358
|
const preview = frame.preview;
|
|
82
359
|
if (!preview || !Number.isInteger(preview.unread) || !Array.isArray(preview.rows) || preview.rows.length > 8 || !preview.rows.every((row) => typeof row === "string" && Array.from(row).length <= 240)) continue;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function readPersonalBinding(session: string): Record<string, unknown>;
|
|
2
|
+
/** The native module supplies its host pid. Keep it separate so simultaneous command hooks cannot
|
|
3
|
+
* overwrite the route while saving newer metadata. No identity is inferred from a lone server. */
|
|
4
|
+
export declare function bindPersonalSession(event: Record<string, unknown>, hostPid: number): Promise<void>;
|
|
5
|
+
/** Only bounded metadata crosses this pipe. Prompts, arguments, results and error details do not. */
|
|
6
|
+
export declare function observePersonalHook(value: unknown): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=native-binding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-binding.d.ts","sourceRoot":"","sources":["../src/native-binding.ts"],"names":[],"mappings":"AAiCA,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAK5E;AAoBD;kGACkG;AAClG,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CASxG;AAED,qGAAqG;AACrG,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAwBvE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Socket } from "node:net";
|
|
2
|
+
import type { InlineDeliveryBatch, InlineDeliveryPayload } from "@cotal-ai/connector-core";
|
|
3
|
+
export declare const INLINE_FRAME_LIMIT = 4096;
|
|
4
|
+
export interface NativeInlineFrame {
|
|
5
|
+
id: string;
|
|
6
|
+
inline: InlineDeliveryPayload & {
|
|
7
|
+
v: 1;
|
|
8
|
+
receipt: string;
|
|
9
|
+
session: string;
|
|
10
|
+
};
|
|
11
|
+
route: string;
|
|
12
|
+
}
|
|
13
|
+
/** Validate a private helper frame before any of its text can enter a native conversation. */
|
|
14
|
+
export declare function isNativeInlineFrame(value: unknown): value is NativeInlineFrame;
|
|
15
|
+
/** Transient native handoffs hold existing inbox entries, not a second message or ACK store. */
|
|
16
|
+
export declare class NativeDeliveries {
|
|
17
|
+
private readonly route;
|
|
18
|
+
private readonly timeoutMs;
|
|
19
|
+
private offers;
|
|
20
|
+
private sessions;
|
|
21
|
+
private settled;
|
|
22
|
+
constructor(route: string, timeoutMs?: number);
|
|
23
|
+
pending(session: string): boolean;
|
|
24
|
+
fits(id: string, session: string, payload: InlineDeliveryPayload): boolean;
|
|
25
|
+
send(reader: Socket, id: string, session: string, batch: InlineDeliveryBatch, onSettled: (delivered: boolean) => void, retry: () => void): boolean;
|
|
26
|
+
request(value: Record<string, unknown>): Record<string, unknown>;
|
|
27
|
+
private finish;
|
|
28
|
+
dropReader(reader: Socket): void;
|
|
29
|
+
close(): void;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=native-deliveries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-deliveries.d.ts","sourceRoot":"","sources":["../src/native-deliveries.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAG3F,eAAO,MAAM,kBAAkB,OAAQ,CAAC;AACxC,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,qBAAqB,GAAG;QAAE,CAAC,EAAE,CAAC,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3E,KAAK,EAAE,MAAM,CAAC;CACf;AAWD,8FAA8F;AAC9F,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,iBAAiB,CAU9E;AAED,gGAAgG;AAChG,qBAAa,gBAAgB;IAKf,OAAO,CAAC,QAAQ,CAAC,KAAK;IAAU,OAAO,CAAC,QAAQ,CAAC,SAAS;IAJtE,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,OAAO,CAA8F;gBAEhF,KAAK,EAAE,MAAM,EAAmB,SAAS,SAAS;IAE/E,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAQjC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO;IAI1E,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,EAAE,KAAK,EAAE,MAAM,IAAI,GAAG,OAAO;IAalJ,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAoChE,OAAO,CAAC,MAAM;IAed,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIhC,KAAK,IAAI,IAAI;CAId"}
|
package/dist/wake-feed.d.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import type { RenderedInboxPreview } from "@cotal-ai/connector-core";
|
|
1
|
+
import type { InlineDeliveryBatch, InlineDeliveryPayload, RenderedInboxPreview } from "@cotal-ai/connector-core";
|
|
2
2
|
/** A connection id the feed carries. Gateway ids are UUIDs, so anything else is not one. */
|
|
3
3
|
export declare const WAKE_ID: RegExp;
|
|
4
4
|
/** The socket server `serverPid` opens for the Claude Code process `claudePid`. */
|
|
5
5
|
export declare function wakeSocketPath(claudePid: number, serverPid?: number): string;
|
|
6
6
|
/** The feed sockets of the Claude Code process `claudePid` whose server is running, one per server. */
|
|
7
7
|
export declare function wakeSockets(claudePid: number): string[];
|
|
8
|
+
/** Lifecycle requests use a separate socket so an event relay is never mistaken for a wake reader. */
|
|
9
|
+
export declare function nativeSocketPath(feed: string): string;
|
|
8
10
|
export interface WakeFeed {
|
|
9
11
|
/** Write one bounded preview + `id` to every monitor reading the feed. False when none is. */
|
|
10
|
-
send(id: string, preview: RenderedInboxPreview): boolean;
|
|
12
|
+
send(id: string, preview: RenderedInboxPreview, session?: string): boolean;
|
|
13
|
+
supportsInline(session: string): boolean;
|
|
14
|
+
inlinePending(session: string): boolean;
|
|
15
|
+
fitsInline(id: string, session: string, payload: InlineDeliveryPayload): boolean;
|
|
16
|
+
sendInline(id: string, session: string, batch: InlineDeliveryBatch, settled: (delivered: boolean) => void, retry: () => void): boolean;
|
|
17
|
+
/** Native lifecycle frames are routed by their explicit session identity, never reader order. */
|
|
18
|
+
onNative(fn: (event: Record<string, unknown>) => Promise<void>): void;
|
|
11
19
|
/** Whether a monitor is reading the feed now. */
|
|
12
|
-
watched(): boolean;
|
|
20
|
+
watched(session?: string): boolean;
|
|
13
21
|
/** Run `fn` each time a monitor starts reading. */
|
|
14
22
|
onReader(fn: () => void): void;
|
|
15
23
|
close(): void;
|
package/dist/wake-feed.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wake-feed.d.ts","sourceRoot":"","sources":["../src/wake-feed.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wake-feed.d.ts","sourceRoot":"","sources":["../src/wake-feed.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAGjH,4FAA4F;AAC5F,eAAO,MAAM,OAAO,QAA2B,CAAC;AA6BhD,mFAAmF;AACnF,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,GAAE,MAAoB,GAAG,MAAM,CAGzF;AAED,uGAAuG;AACvG,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAMvD;AAED,sGAAsG;AACtG,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,MAAM,WAAW,QAAQ;IACvB,8FAA8F;IAC9F,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3E,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IACzC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC;IACjF,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,EAAE,OAAO,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,EAAE,KAAK,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC;IACvI,iGAAiG;IACjG,QAAQ,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACtE,iDAAiD;IACjD,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACnC,mDAAmD;IACnD,QAAQ,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC/B,KAAK,IAAI,IAAI,CAAC;CACf;AAED,yEAAyE;AACzE,wBAAsB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAgGvE"}
|