@cotal-ai/connector-claude-code 0.90.1 → 0.92.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/.claude-plugin/plugin.json +1 -1
- package/dist/carried.d.ts +4 -2
- package/dist/carried.d.ts.map +1 -1
- package/dist/index.js +230 -74
- package/dist/mcp.cjs +3184 -2594
- package/dist/mcp.d.ts.map +1 -1
- package/dist/monitor.cjs +15 -4
- package/dist/setup.d.ts +1 -0
- package/dist/setup.d.ts.map +1 -1
- package/dist/wake-feed.d.ts +3 -2
- package/dist/wake-feed.d.ts.map +1 -1
- package/hooks/hooks.json +1 -0
- package/hooks/native-wake.js +167 -0
- package/monitors/monitors.json +1 -7
- package/package.json +6 -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;AA2HtD,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
|
@@ -55,9 +55,10 @@ function wakeSockets(claudePid) {
|
|
|
55
55
|
// src/monitor.ts
|
|
56
56
|
var SCAN_MS = 1e3;
|
|
57
57
|
var wakeEvent = (id) => `Cotal: a new message for connection_id ${id}. Read it with cotal_inbox.`;
|
|
58
|
+
var previewEvent = (id, preview) => `Cotal preview for connection_id ${id}: ${JSON.stringify(preview)}`;
|
|
58
59
|
function main() {
|
|
59
60
|
if (hasIdentity()) return;
|
|
60
|
-
const claude = Number(process.env.CLAUDE_PID);
|
|
61
|
+
const claude = process.argv.includes("--native") ? process.ppid : Number(process.env.CLAUDE_PID);
|
|
61
62
|
if (!Number.isInteger(claude) || claude <= 0) {
|
|
62
63
|
process.stderr.write("[cotal-monitor] no CLAUDE_PID, so this is not a Claude Code session\n");
|
|
63
64
|
process.exitCode = 1;
|
|
@@ -72,12 +73,22 @@ function main() {
|
|
|
72
73
|
s.on("data", (d) => {
|
|
73
74
|
buf += d;
|
|
74
75
|
for (let i; (i = buf.indexOf("\n")) >= 0; ) {
|
|
75
|
-
const
|
|
76
|
+
const line = buf.slice(0, i);
|
|
76
77
|
buf = buf.slice(i + 1);
|
|
77
|
-
|
|
78
|
+
try {
|
|
79
|
+
const frame = JSON.parse(line);
|
|
80
|
+
if (typeof frame.id !== "string" || !WAKE_ID.test(frame.id)) continue;
|
|
81
|
+
const preview = frame.preview;
|
|
82
|
+
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;
|
|
83
|
+
process.stdout.write(`${previewEvent(frame.id, preview)}
|
|
84
|
+
${wakeEvent(frame.id)}
|
|
78
85
|
`);
|
|
86
|
+
} catch {
|
|
87
|
+
if (WAKE_ID.test(line)) process.stdout.write(`${wakeEvent(line)}
|
|
88
|
+
`);
|
|
89
|
+
}
|
|
79
90
|
}
|
|
80
|
-
if (buf.length >
|
|
91
|
+
if (buf.length > 4096) s.destroy();
|
|
81
92
|
});
|
|
82
93
|
s.on("error", () => {
|
|
83
94
|
});
|
package/dist/setup.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ConnectorSetupProvider } from "@cotal-ai/core";
|
|
2
|
+
export declare function materialize(name: string, root: string, assets: readonly string[], version?: string, files?: Readonly<Record<string, string>>): void;
|
|
2
3
|
/** Exported so a suite can grade the manifest that is actually written, not a second copy of it. */
|
|
3
4
|
export declare function marketplaceManifest(market: string): {
|
|
4
5
|
name: string;
|
package/dist/setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAMA,OAAO,
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAMA,OAAO,EAML,KAAK,sBAAsB,EAK5B,MAAM,gBAAgB,CAAC;AAqJxB,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM,GAAG,IAAI,CA8CvJ;AAqCD,oGAAoG;AACpG,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACnE,CAKA;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAK/D;AA6PD,eAAO,MAAM,mBAAmB,EAAE,sBAsGjC,CAAC"}
|
package/dist/wake-feed.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RenderedInboxPreview } from "@cotal-ai/connector-core";
|
|
1
2
|
/** A connection id the feed carries. Gateway ids are UUIDs, so anything else is not one. */
|
|
2
3
|
export declare const WAKE_ID: RegExp;
|
|
3
4
|
/** The socket server `serverPid` opens for the Claude Code process `claudePid`. */
|
|
@@ -5,8 +6,8 @@ export declare function wakeSocketPath(claudePid: number, serverPid?: number): s
|
|
|
5
6
|
/** The feed sockets of the Claude Code process `claudePid` whose server is running, one per server. */
|
|
6
7
|
export declare function wakeSockets(claudePid: number): string[];
|
|
7
8
|
export interface WakeFeed {
|
|
8
|
-
/** Write `id` to every monitor reading the feed. False when none is. */
|
|
9
|
-
send(id: string): boolean;
|
|
9
|
+
/** Write one bounded preview + `id` to every monitor reading the feed. False when none is. */
|
|
10
|
+
send(id: string, preview: RenderedInboxPreview): boolean;
|
|
10
11
|
/** Whether a monitor is reading the feed now. */
|
|
11
12
|
watched(): boolean;
|
|
12
13
|
/** Run `fn` each time a monitor starts reading. */
|
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":"AAaA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAErE,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,MAAM,WAAW,QAAQ;IACvB,8FAA8F;IAC9F,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC;IACzD,iDAAiD;IACjD,OAAO,IAAI,OAAO,CAAC;IACnB,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,CAqCvE"}
|
package/hooks/hooks.json
CHANGED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const WAKE = /^Cotal: a new message for connection_id ([A-Za-z0-9_-]{1,128})\. Read it with cotal_inbox\.$/;
|
|
2
|
+
const PREVIEW = /^Cotal preview for connection_id ([A-Za-z0-9_-]{1,128}): (\{.*\})$/;
|
|
3
|
+
const pending = new Set();
|
|
4
|
+
const expanded = new Set();
|
|
5
|
+
const wakeRows = new Set();
|
|
6
|
+
const previews = new Map();
|
|
7
|
+
let submitting = false;
|
|
8
|
+
let paused = false;
|
|
9
|
+
let active = false;
|
|
10
|
+
let reader;
|
|
11
|
+
|
|
12
|
+
async function submit($, inTurn = false) {
|
|
13
|
+
if (submitting || paused || active !== inTurn) return;
|
|
14
|
+
submitting = true;
|
|
15
|
+
try {
|
|
16
|
+
for (const text of pending) {
|
|
17
|
+
if (paused || active !== inTurn) break;
|
|
18
|
+
pending.delete(text);
|
|
19
|
+
try {
|
|
20
|
+
// Appending at a main-loop boundary keeps the wake in this turn. Submitting a prompt
|
|
21
|
+
// instead would queue a second turn, after all the work we need the message to reach.
|
|
22
|
+
const result = inTurn
|
|
23
|
+
? await $.session.append({ message: { type: 'user', content: [{ type: 'text', text }] } })
|
|
24
|
+
: await $.prompt.submit({ text });
|
|
25
|
+
if (result?.drop || (inTurn && !result?.uuid)) {
|
|
26
|
+
paused = true;
|
|
27
|
+
pending.add(text);
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
paused = true;
|
|
32
|
+
pending.add(text);
|
|
33
|
+
$.ui.log('Cotal incoming delivery is paused. Your next message can resume it.');
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} finally {
|
|
38
|
+
submitting = false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function listen($) {
|
|
43
|
+
try {
|
|
44
|
+
// Managed sessions already own a native channel and do not carry this CLI record.
|
|
45
|
+
if (await $.env.get('COTAL_NAME') || await $.env.get('COTAL_LINK') || await $.env.get('COTAL_AGENT_FILE')) return;
|
|
46
|
+
const root = $.plugin.root;
|
|
47
|
+
const record = JSON.parse(await $.fs.read(root + '/dist/cli.json'));
|
|
48
|
+
if (!Array.isArray(record.argv) || typeof record.argv[0] !== 'string') {
|
|
49
|
+
throw new Error('missing Cotal CLI record');
|
|
50
|
+
}
|
|
51
|
+
reader = $.process.spawn({ argv: [record.argv[0], root + '/dist/monitor.cjs', '--native'] });
|
|
52
|
+
let buffer = '';
|
|
53
|
+
for await (const piece of reader) {
|
|
54
|
+
if (piece.stream !== 'stdout') continue;
|
|
55
|
+
buffer += piece.text;
|
|
56
|
+
for (let end; (end = buffer.indexOf('\n')) >= 0;) {
|
|
57
|
+
const line = buffer.slice(0, end);
|
|
58
|
+
buffer = buffer.slice(end + 1);
|
|
59
|
+
const preview = PREVIEW.exec(line);
|
|
60
|
+
if (preview) {
|
|
61
|
+
try {
|
|
62
|
+
const value = JSON.parse(preview[2]);
|
|
63
|
+
if (Number.isInteger(value.unread) && value.unread >= 0 && Array.isArray(value.rows) &&
|
|
64
|
+
value.rows.length <= 8 && value.rows.every(row => typeof row === 'string' && Array.from(row).length <= 240)) {
|
|
65
|
+
previews.set(preview[1], value);
|
|
66
|
+
}
|
|
67
|
+
} catch {}
|
|
68
|
+
} else if (WAKE.test(line)) {
|
|
69
|
+
pending.add(line);
|
|
70
|
+
void submit($);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (buffer.length > 256) throw new Error('invalid Cotal wake feed');
|
|
74
|
+
}
|
|
75
|
+
} catch {
|
|
76
|
+
await reader?.return();
|
|
77
|
+
$.ui.log('Cotal incoming auto-wake is unavailable. Run cotal setup, then reopen Claude.');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function register(on) {
|
|
82
|
+
on('session.append', async ($, e, next) => {
|
|
83
|
+
const own = e.origin.kind === 'plugin' && e.origin.name === $.plugin.name && !e.origin.asUser;
|
|
84
|
+
const text = e.message.content.filter(block => block.type === 'text').map(block => block.text).join('\n');
|
|
85
|
+
const result = await next(e);
|
|
86
|
+
if (own && text.split(/\r?\n/).some(line => WAKE.test(line))) {
|
|
87
|
+
wakeRows.add(e.uuid);
|
|
88
|
+
$.ui.invalidate('ui.render');
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
});
|
|
92
|
+
on('ui.render', { component: 'UserMessage' }, async ($, e, next) => {
|
|
93
|
+
const origin = e.props.origin;
|
|
94
|
+
const own = origin?.kind === 'plugin' && origin.name === $.plugin.name && !origin.asUser;
|
|
95
|
+
// Desktop renders plugin submissions as SDK rows. Trust the recorded event id, never a
|
|
96
|
+
// text-only match that could hide something the person or another plugin wrote.
|
|
97
|
+
if (!own && !wakeRows.has(e.requestId)) return next(e);
|
|
98
|
+
// Some app versions include their attribution wrapper in the rendered text. Match only our
|
|
99
|
+
// fixed wake line, and keep the full original available through the disclosure below.
|
|
100
|
+
if (!e.props.text.split(/\r?\n/).some(line => WAKE.test(line))) return next(e);
|
|
101
|
+
const id = e.props.text.split(/\r?\n/).map(line => WAKE.exec(line)?.[1]).find(Boolean);
|
|
102
|
+
const preview = id ? previews.get(id) : undefined;
|
|
103
|
+
const { Box, Button } = $.ui.resolve(e);
|
|
104
|
+
const open = expanded.has(e.requestId);
|
|
105
|
+
return Box({
|
|
106
|
+
flexDirection: 'column',
|
|
107
|
+
children: [
|
|
108
|
+
Button({
|
|
109
|
+
key: 'cotal-wake-details',
|
|
110
|
+
label: preview
|
|
111
|
+
? `Cotal · ${preview.unread} unread ${open ? '▾' : '›'}`
|
|
112
|
+
: open ? 'Cotal · new message ▾' : 'Cotal · new message ›',
|
|
113
|
+
plain: true,
|
|
114
|
+
onPress: () => {
|
|
115
|
+
if (open) expanded.delete(e.requestId);
|
|
116
|
+
else expanded.add(e.requestId);
|
|
117
|
+
$.ui.invalidate('ui.render');
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
...(open ? preview?.rows?.length
|
|
121
|
+
? preview.rows.map((row, index) => Box({ key: `cotal-preview-${index}`, children: [row] }))
|
|
122
|
+
: [await next(e)] : []),
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
on('session.start', async ($, e, next) => {
|
|
127
|
+
const started = await next(e);
|
|
128
|
+
void listen($);
|
|
129
|
+
return started;
|
|
130
|
+
});
|
|
131
|
+
on('prompt.submit', async ($, e, next) => {
|
|
132
|
+
const result = await next(e);
|
|
133
|
+
// The engine stamps the person's input. Peer deliveries, timers and another plugin's prompt
|
|
134
|
+
// must not restart work after Stop. Desktop and SDK hosts submit their own input as sdk.
|
|
135
|
+
if (!result?.drop && ['composer', 'bridge', 'sdk'].includes(e.origin?.kind)) paused = false;
|
|
136
|
+
return result;
|
|
137
|
+
});
|
|
138
|
+
on('turn.start', async ($, e, next) => {
|
|
139
|
+
if (e.agentId === undefined) active = true;
|
|
140
|
+
return next(e);
|
|
141
|
+
});
|
|
142
|
+
on('tool.call', async ($, e, next) => {
|
|
143
|
+
const result = await next(e);
|
|
144
|
+
if (e.agentId === undefined && !next.signal.aborted) await submit($, true);
|
|
145
|
+
return result;
|
|
146
|
+
});
|
|
147
|
+
on('turn.step', async function* ($, e, next) {
|
|
148
|
+
if (e.agentId === undefined) {
|
|
149
|
+
active = true;
|
|
150
|
+
if (!next.signal.aborted) await submit($, true);
|
|
151
|
+
}
|
|
152
|
+
return yield* next(e);
|
|
153
|
+
});
|
|
154
|
+
on('turn.complete', async ($, e, next) => {
|
|
155
|
+
const completed = await next(e);
|
|
156
|
+
if (e.agentId !== undefined) return completed;
|
|
157
|
+
active = false;
|
|
158
|
+
// Stop pauses both wake paths; only the host's next person-origin prompt resumes them.
|
|
159
|
+
if (e.isAborted) paused = true;
|
|
160
|
+
if (!paused && pending.size > 0) void submit($);
|
|
161
|
+
return completed;
|
|
162
|
+
});
|
|
163
|
+
on('session.end', async ($, e, next) => {
|
|
164
|
+
if (e.reason !== 'clear' && e.reason !== 'resume') await reader?.return();
|
|
165
|
+
return next(e);
|
|
166
|
+
});
|
|
167
|
+
}
|
package/monitors/monitors.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cotal-ai/connector-claude-code",
|
|
3
3
|
"description": "Cotal connector for Claude Code: an installed plugin that joins a session to the mesh.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.92.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@cotal-ai/core": ">=0.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@cotal-ai/connector-core": "0.
|
|
29
|
-
"@cotal-ai/core": "0.
|
|
28
|
+
"@cotal-ai/connector-core": "0.92.0",
|
|
29
|
+
"@cotal-ai/core": "0.92.0",
|
|
30
30
|
"@cotal-ai/smoke-kit": "0.0.0",
|
|
31
31
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
32
32
|
"@nats-io/transport-node": "^3.4.0",
|
|
@@ -45,7 +45,9 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
|
-
"test": "tsx smoke/launch-env.smoke.ts",
|
|
48
|
+
"test": "tsx smoke/launch-env.smoke.ts && tsx smoke/native-wake.smoke.ts && tsx smoke/wake-preview-frame.smoke.ts",
|
|
49
|
+
"test:desktop-setup": "tsx smoke/desktop-only-setup-live.smoke.ts",
|
|
50
|
+
"test:upgrade": "tsx smoke/plugin-upgrade-live.smoke.ts",
|
|
49
51
|
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.smoke.json",
|
|
50
52
|
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json --emitDeclarationOnly && node -e \"require('node:fs').copyFileSync('dist/mcp.d.ts','dist/mcp.d.cts')\" && pnpm run bundle",
|
|
51
53
|
"bundle": "esbuild src/index.ts --bundle --platform=node --format=esm --target=node20 --outfile=dist/index.js --external:@cotal-ai/core && esbuild src/mcp.ts --bundle --platform=node --format=cjs --target=node20 --outfile=dist/mcp.cjs --footer:js=\"module.exports = { serveClaudeSession: module.exports.serveClaudeSession };\" && esbuild src/hook.ts --bundle --platform=node --format=cjs --target=node20 --outfile=dist/hook.cjs && esbuild src/monitor.ts --bundle --platform=node --format=cjs --target=node20 --outfile=dist/monitor.cjs"
|