@cotal-ai/connector-claude-code 0.90.1 → 0.91.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/dist/monitor.cjs CHANGED
@@ -57,7 +57,7 @@ var SCAN_MS = 1e3;
57
57
  var wakeEvent = (id) => `Cotal: a new message for connection_id ${id}. Read it with cotal_inbox.`;
58
58
  function main() {
59
59
  if (hasIdentity()) return;
60
- const claude = Number(process.env.CLAUDE_PID);
60
+ const claude = process.argv.includes("--native") ? process.ppid : Number(process.env.CLAUDE_PID);
61
61
  if (!Number.isInteger(claude) || claude <= 0) {
62
62
  process.stderr.write("[cotal-monitor] no CLAUDE_PID, so this is not a Claude Code session\n");
63
63
  process.exitCode = 1;
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;
@@ -1 +1 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAMA,OAAO,EAIL,KAAK,sBAAsB,EAI5B,MAAM,gBAAgB,CAAC;AA0JxB,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;AA4JD,eAAO,MAAM,mBAAmB,EAAE,sBAiGjC,CAAC"}
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAMA,OAAO,EAKL,KAAK,sBAAsB,EAK5B,MAAM,gBAAgB,CAAC;AA2IxB,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,sBAgGjC,CAAC"}
package/hooks/hooks.json CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
+ "modules": ["./native-wake.js"],
2
3
  "hooks": {
3
4
  "SessionStart": [
4
5
  {
@@ -0,0 +1,150 @@
1
+ const WAKE = /^Cotal: a new message for connection_id ([A-Za-z0-9_-]{1,128})\. Read it with cotal_inbox\.$/;
2
+ const pending = new Set();
3
+ const expanded = new Set();
4
+ const wakeRows = new Set();
5
+ let submitting = false;
6
+ let paused = false;
7
+ let active = false;
8
+ let reader;
9
+
10
+ async function submit($, inTurn = false) {
11
+ if (submitting || paused || active !== inTurn) return;
12
+ submitting = true;
13
+ try {
14
+ for (const text of pending) {
15
+ if (paused || active !== inTurn) break;
16
+ pending.delete(text);
17
+ try {
18
+ // Appending at a main-loop boundary keeps the wake in this turn. Submitting a prompt
19
+ // instead would queue a second turn, after all the work we need the message to reach.
20
+ const result = inTurn
21
+ ? await $.session.append({ message: { type: 'user', content: [{ type: 'text', text }] } })
22
+ : await $.prompt.submit({ text });
23
+ if (result?.drop || (inTurn && !result?.uuid)) {
24
+ paused = true;
25
+ pending.add(text);
26
+ break;
27
+ }
28
+ } catch {
29
+ paused = true;
30
+ pending.add(text);
31
+ $.ui.log('Cotal incoming delivery is paused. Your next message can resume it.');
32
+ break;
33
+ }
34
+ }
35
+ } finally {
36
+ submitting = false;
37
+ }
38
+ }
39
+
40
+ async function listen($) {
41
+ try {
42
+ // Managed sessions already own a native channel and do not carry this CLI record.
43
+ if (await $.env.get('COTAL_NAME') || await $.env.get('COTAL_LINK') || await $.env.get('COTAL_AGENT_FILE')) return;
44
+ const root = $.plugin.root;
45
+ const record = JSON.parse(await $.fs.read(root + '/dist/cli.json'));
46
+ if (!Array.isArray(record.argv) || typeof record.argv[0] !== 'string') {
47
+ throw new Error('missing Cotal CLI record');
48
+ }
49
+ reader = $.process.spawn({ argv: [record.argv[0], root + '/dist/monitor.cjs', '--native'] });
50
+ let buffer = '';
51
+ for await (const piece of reader) {
52
+ if (piece.stream !== 'stdout') continue;
53
+ buffer += piece.text;
54
+ for (let end; (end = buffer.indexOf('\n')) >= 0;) {
55
+ const line = buffer.slice(0, end);
56
+ buffer = buffer.slice(end + 1);
57
+ if (WAKE.test(line)) {
58
+ pending.add(line);
59
+ void submit($);
60
+ }
61
+ }
62
+ if (buffer.length > 256) throw new Error('invalid Cotal wake feed');
63
+ }
64
+ } catch {
65
+ await reader?.return();
66
+ $.ui.log('Cotal incoming auto-wake is unavailable. Run cotal setup, then reopen Claude.');
67
+ }
68
+ }
69
+
70
+ export function register(on) {
71
+ on('session.append', async ($, e, next) => {
72
+ const own = e.origin.kind === 'plugin' && e.origin.name === $.plugin.name && !e.origin.asUser;
73
+ const text = e.message.content.filter(block => block.type === 'text').map(block => block.text).join('\n');
74
+ const result = await next(e);
75
+ if (own && text.split(/\r?\n/).some(line => WAKE.test(line))) {
76
+ wakeRows.add(e.uuid);
77
+ $.ui.invalidate('ui.render');
78
+ }
79
+ return result;
80
+ });
81
+ on('ui.render', { component: 'UserMessage' }, async ($, e, next) => {
82
+ const origin = e.props.origin;
83
+ const own = origin?.kind === 'plugin' && origin.name === $.plugin.name && !origin.asUser;
84
+ // Desktop renders plugin submissions as SDK rows. Trust the recorded event id, never a
85
+ // text-only match that could hide something the person or another plugin wrote.
86
+ if (!own && !wakeRows.has(e.requestId)) return next(e);
87
+ // Some app versions include their attribution wrapper in the rendered text. Match only our
88
+ // fixed wake line, and keep the full original available through the disclosure below.
89
+ if (!e.props.text.split(/\r?\n/).some(line => WAKE.test(line))) return next(e);
90
+ const { Box, Button } = $.ui.resolve(e);
91
+ const open = expanded.has(e.requestId);
92
+ return Box({
93
+ flexDirection: 'column',
94
+ children: [
95
+ Button({
96
+ key: 'cotal-wake-details',
97
+ label: open ? 'Cotal · new message ▾' : 'Cotal · new message ›',
98
+ plain: true,
99
+ onPress: () => {
100
+ if (open) expanded.delete(e.requestId);
101
+ else expanded.add(e.requestId);
102
+ $.ui.invalidate('ui.render');
103
+ },
104
+ }),
105
+ ...(open ? [await next(e)] : []),
106
+ ],
107
+ });
108
+ });
109
+ on('session.start', async ($, e, next) => {
110
+ const started = await next(e);
111
+ void listen($);
112
+ return started;
113
+ });
114
+ on('prompt.submit', async ($, e, next) => {
115
+ const result = await next(e);
116
+ // The engine stamps the person's input. Peer deliveries, timers and another plugin's prompt
117
+ // must not restart work after Stop. Desktop and SDK hosts submit their own input as sdk.
118
+ if (!result?.drop && ['composer', 'bridge', 'sdk'].includes(e.origin?.kind)) paused = false;
119
+ return result;
120
+ });
121
+ on('turn.start', async ($, e, next) => {
122
+ if (e.agentId === undefined) active = true;
123
+ return next(e);
124
+ });
125
+ on('tool.call', async ($, e, next) => {
126
+ const result = await next(e);
127
+ if (e.agentId === undefined && !next.signal.aborted) await submit($, true);
128
+ return result;
129
+ });
130
+ on('turn.step', async function* ($, e, next) {
131
+ if (e.agentId === undefined) {
132
+ active = true;
133
+ if (!next.signal.aborted) await submit($, true);
134
+ }
135
+ return yield* next(e);
136
+ });
137
+ on('turn.complete', async ($, e, next) => {
138
+ const completed = await next(e);
139
+ if (e.agentId !== undefined) return completed;
140
+ active = false;
141
+ // Stop pauses both wake paths; only the host's next person-origin prompt resumes them.
142
+ if (e.isAborted) paused = true;
143
+ if (!paused && pending.size > 0) void submit($);
144
+ return completed;
145
+ });
146
+ on('session.end', async ($, e, next) => {
147
+ if (e.reason !== 'clear' && e.reason !== 'resume') await reader?.return();
148
+ return next(e);
149
+ });
150
+ }
@@ -1,7 +1 @@
1
- [
2
- {
3
- "name": "cotal",
4
- "command": "node \"${CLAUDE_PLUGIN_ROOT}/dist/monitor.cjs\"",
5
- "description": "Cotal messages"
6
- }
7
- ]
1
+ []
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.90.1",
4
+ "version": "0.91.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.90.1",
29
- "@cotal-ai/core": "0.90.1",
28
+ "@cotal-ai/connector-core": "0.91.0",
29
+ "@cotal-ai/core": "0.91.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",
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"