@cmodjs/core 8.4.0 → 8.4.2
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/docs/commands.md +1 -1
- package/docs/ui.md +7 -7
- package/package.json +1 -1
- package/records.d.ts +1 -1
- package/records.js +1 -1
- package/runtime/buttons.d.ts.map +1 -1
- package/runtime/buttons.js +1 -0
- package/runtime/rpc.d.ts +1 -0
- package/runtime/rpc.d.ts.map +1 -1
- package/runtime/rpc.js +63 -12
- package/src/records.ts +1 -1
- package/src/runtime/buttons.ts +1 -0
- package/src/runtime/rpc.ts +66 -13
- package/src/testing/fake-claude.ts +8 -1
- package/src/testing/fake-serve.ts +1 -1
- package/testing/fake-claude.d.ts.map +1 -1
- package/testing/fake-claude.js +8 -2
- package/testing/fake-serve.js +1 -1
package/docs/commands.md
CHANGED
|
@@ -167,7 +167,7 @@ Adds the plugin's marketplace to Claude Code and installs the plugin through Cla
|
|
|
167
167
|
cmod update [name]
|
|
168
168
|
```
|
|
169
169
|
|
|
170
|
-
Updates the named plugin, or every plugin Claude Code has installed, through Claude Code, then runs the install step of each mod whose version or scripts changed. A linked plugin is skipped, because saving its files updates it. When Claude Code fails to update a plugin, `cmod update` names it, updates the rest, and exits 1. Every running session then loads the new version.
|
|
170
|
+
Updates the named plugin, or every plugin Claude Code has installed, through Claude Code, then runs the install step of each mod whose version or scripts changed. A linked plugin is skipped, because saving its files updates it. When Claude Code fails to update a plugin, `cmod update` names it, updates the rest, and exits 1. An updated cmod plugin also downloads its cmod program, as a session start does, so `cmod serve` moves to the new version without one. Every running session then loads the new version.
|
|
171
171
|
|
|
172
172
|
### cmod remove
|
|
173
173
|
|
package/docs/ui.md
CHANGED
|
@@ -229,13 +229,13 @@ event Close { session, mod, id }
|
|
|
229
229
|
|
|
230
230
|
The Herdr app shows Claude Code in its terminals, and cmod's Herdr mod draws every mod's widgets, views, and pages beside them, so a mod writes no Herdr code. `cmod serve` places it in `mods/cmod/` of Herdr's home ([cmod serve](commands.md#cmod-serve)), and it reaches each session through [`cmod ui`](commands.md#cmod-ui), with `surface: 'herdr'` and `columns` its width in 8-pixel columns. Toasts and questions stay in Claude Code's own terminal, which Herdr shows.
|
|
231
231
|
|
|
232
|
-
It shows the session of the focused terminal: the terminal's foreground process, whose `sessions/<pid>.json` in Claude Code's config folder names the session. A terminal of a shell, or on another machine,
|
|
232
|
+
It shows the session of the focused terminal: the terminal's foreground process, whose `sessions/<pid>.json` in Claude Code's config folder names the session. A terminal of a shell, or on another machine, names no session, so a dock keeps the last session it showed, as a mod pane taking the keyboard does.
|
|
233
233
|
|
|
234
234
|
It never docks itself, because Herdr writes a dock into whichever layout file shows when it first sees the mod, once per Herdr home, and a layout another mod rewrites loses it for good. Herdr shows it in two ways. `mod.open` with `{ "name": "cmod" }` opens the dock as a window over any layout, Herdr's own included, and closes it when run again: from `herdr-app do mod.open:cmod`, a `keys.json` binding such as `"ctrl-shift-m": "mod.open:cmod"`, or another mod's `run`. The window takes no keyboard, so the dock keeps following the focused terminal, and Herdr remembers where it was dragged. A layout author places it anywhere a mod goes instead, with the `props` that say what it shows:
|
|
235
235
|
|
|
236
|
-
- `{ "mod": "cmod" }`, or `{ "show": "views" }`, shows the focused session's views as tabs, and hosts the focused session, in a layout and in the `mod.open` window alike: its `show` carries `isHost`, so the session opens no Sidebar of its own. An `Open` with `isAsked` selects the view's tab, and a dock in a layout also shows its own block: it selects the block's branch of each stack above it and shows each hidden node on the way, with `layout.select` and `layout.show`, wherever the layout puts it. It shows the views in the order `views` lists them, the cmod plugin's own `dashboard`, `history`, and `settings` among them, and
|
|
236
|
+
- `{ "mod": "cmod" }`, or `{ "show": "views" }`, shows the focused session's views as tabs, and hosts the focused session, in a layout and in the `mod.open` window alike: its `show` carries `isHost`, so the session opens no Sidebar of its own. An `Open` with `isAsked` selects the view's tab, and a dock in a layout also shows its own block: it selects the block's branch of each stack above it and shows each hidden node on the way, with `layout.select` and `layout.show`, wherever the layout puts it. It shows the views in the order `views` lists them, the cmod plugin's own `dashboard`, `history`, and `settings` among them, and the session's open pages after them in the same row, which scrolls. A page opens as a Herdr tab, `tab.new` with `{ "show": "page", "session", "mod", "id", "title" }`. A page a mod opens itself opens the same way on `Open`, and its tab closes on `Close`. A view a mod opens becomes the shown tab, and a `Close` of the shown view goes back to the first one, as the Sidebar takes a closed view away.
|
|
237
237
|
- `{ "show": "widgets", "area": "belowPrompt" }` draws in a row each widget that lists that area, drawn for that area, for a status bar block. `area` is the value of an area constant: `abovePrompt`, `belowPrompt`, `working`, `turnEnd`, or `dashboard`, the default. In a pane header Herdr gives `props().terminal`, so each pane's header draws its own session's widgets.
|
|
238
|
-
- `{ "show": "page", "session": "<id>", "mod": "<mod>", "id": "<page>" }` draws one page of one session, as the dock's
|
|
238
|
+
- `{ "show": "page", "session": "<id>", "mod": "<mod>", "id": "<page>" }` draws one page of one session, as a page in the dock's row opens it.
|
|
239
239
|
|
|
240
240
|
Each dock and page tab tells `show` the view or page it draws, under a client name it makes once, so the mod's view or page counts as `isShown` while Herdr shows it. It tells again when its shown tab or its focused session changes, renews the list every 5 seconds, and clears it when its focused session changes or the placement closes. A `{ "show": "widgets" }` block tells nothing, because `isShown` is about views and pages.
|
|
241
241
|
|
|
@@ -246,11 +246,11 @@ Each dock and page tab tells `show` the view or page it draws, under a client na
|
|
|
246
246
|
|
|
247
247
|
Each element draws as Herdr's own, and each `label`, or a `Text`'s text, is its accessible name:
|
|
248
248
|
|
|
249
|
-
- `Box` draws a flex row or column with its gap, padding, margin, sizes,
|
|
250
|
-
- `Text` draws its text with its color, weight, and style. A theme color such as `'success'` draws in the Herdr theme's color of the same meaning.
|
|
251
|
-
- `Button` draws Herdr's button
|
|
249
|
+
- `Box` draws a flex row or column with its gap, padding, margin, sizes, and background, a column as 8 pixels across, a row as 20 pixels down, and a space step as 8 pixels. A `borderStyle` draws a card, and a `Box` at `position: 'absolute'` and `top: 0` beside one, the terminal's title on a border, draws as a heading above that card.
|
|
250
|
+
- `Text` draws its text with its color, weight, and style. A theme color such as `'success'` draws in the Herdr theme's color of the same meaning. A `Text` with a `backgroundColor` draws as a chip, and text that lays out in cells, with block or box-drawing characters or a run of spaces, keeps the terminal font so its columns line up.
|
|
251
|
+
- `Button` draws Herdr's button: `variant: 'primary'` as its solid button, a `plain` and `dimColor` one as a quiet row of a list, and any other as an outlined one, with its `label` and its `hotkey`. A press runs its handler, and a `Button` with `href` opens an `http:` or `https:` page in the browser, and copies any other link.
|
|
252
252
|
- `Input` draws a field, and `rows` above 1 a text area. Each change runs `onInput`, and Enter runs `onSubmit`.
|
|
253
|
-
- `Select` draws its options as a
|
|
253
|
+
- `Select` draws its options as a segmented control, with the selected one marked.
|
|
254
254
|
- `Markdown` draws Herdr's Markdown text. A link it lists in `pressableLinks`, or any link without them, runs `onLinkPress`, and with no `onLinkPress` it opens as a `Button`'s `href` does.
|
|
255
255
|
- `Code` draws a read-only code view with the language's colors.
|
|
256
256
|
- `Image` and `Svg` draw the picture, which the mod writes under `mods/cmod/.drawn/` first, because Herdr draws only a picture in its home. An image from shared memory draws its `label`.
|
package/package.json
CHANGED
package/records.d.ts
CHANGED
|
@@ -189,7 +189,7 @@ export declare function newestLog(entries: readonly LogEntry[]): LogEntry[];
|
|
|
189
189
|
export declare function versionsLine({ mod, core, cmod, program, claudeCode }: LogVersions): string;
|
|
190
190
|
export declare function logReport(entry: LogEntry): string;
|
|
191
191
|
export declare function parseConsent(value: unknown, path: string): Record<string, string[]>;
|
|
192
|
-
export declare const coreVersion = "8.4.
|
|
192
|
+
export declare const coreVersion = "8.4.2";
|
|
193
193
|
export declare const oldestCmodVersion = "8.0.0";
|
|
194
194
|
export declare function hotkeyCommand(mod: string, hotkey: string): string;
|
|
195
195
|
export declare function hotkeyBindings(mod: string, hotkeys: Hotkeys | undefined): Record<string, string>;
|
package/records.js
CHANGED
|
@@ -402,7 +402,7 @@ function readHotkeys(hotkeys) {
|
|
|
402
402
|
throw new Error(`package.json "cmod.hotkeys" is not a map of hotkeys to their title and optional default combo. ${fix}`);
|
|
403
403
|
return { hotkeys: checkHotkeys('package.json "cmod"', hotkeys) };
|
|
404
404
|
}
|
|
405
|
-
export const coreVersion = '8.4.
|
|
405
|
+
export const coreVersion = '8.4.2';
|
|
406
406
|
export const oldestCmodVersion = '8.0.0';
|
|
407
407
|
export function hotkeyCommand(mod, hotkey) {
|
|
408
408
|
return `${mod}--${hotkey}`;
|
package/runtime/buttons.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buttons.d.ts","sourceRoot":"","sources":["../src/runtime/buttons.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAGhD,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,CAAA;IAC1C,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAC7B,CAAA;AAED,wBAAgB,YAAY,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAqB,EAAE,OAAO,EAAE,EAAE,YAAY,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"buttons.d.ts","sourceRoot":"","sources":["../src/runtime/buttons.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAGhD,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,CAAA;IAC1C,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAC7B,CAAA;AAED,wBAAgB,YAAY,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAqB,EAAE,OAAO,EAAE,EAAE,YAAY,GAAG,aAAa,CAWhH"}
|
package/runtime/buttons.js
CHANGED
|
@@ -5,6 +5,7 @@ export function filledButton({ key, label, hotkey, variant = 'secondary', onPres
|
|
|
5
5
|
plain: true,
|
|
6
6
|
key,
|
|
7
7
|
label,
|
|
8
|
+
variant,
|
|
8
9
|
...(hotkey === undefined ? {} : { hotkey }),
|
|
9
10
|
onPress,
|
|
10
11
|
children: Text({ backgroundColor: isPrimary ? 'claude' : 'userMessageBackground', color: isPrimary ? 'inverseText' : 'text', bold: isPrimary, children: ` ${label} ` }),
|
package/runtime/rpc.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export type Peer = {
|
|
|
43
43
|
close(reason: Error): void;
|
|
44
44
|
readonly signal: AbortSignal;
|
|
45
45
|
};
|
|
46
|
+
export declare const pollChars = 1000000;
|
|
46
47
|
export declare function createPeer({ send, handle }: {
|
|
47
48
|
readonly send: (message: RpcMessage) => void;
|
|
48
49
|
readonly handle: RpcHandler;
|
package/runtime/rpc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/runtime/rpc.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,CAAA;AAEnC,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAEvG,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,C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M,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAElP,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,CAOvE;AAED,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC,GAAG;IACzD,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;IAC7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB,CAAA;AAED,wBAAgB,UAAU,CAAC,EACzB,IAAI,EACJ,MAAM,EACN,SAAS,EACT,OAAO,EACP,IAAI,EACJ,OAAc,EACd,eAAuB,GACxB,EAAE;IACD,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,OAAO,CAAA;IACnD,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;IAC3C,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAA;CACnC,GAAG,SAAS,CA2IZ"}
|
package/runtime/rpc.js
CHANGED
|
@@ -16,6 +16,40 @@ export class RpcError extends Error {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
const cancelMethod = '$/cancelRequest';
|
|
19
|
+
const partMethod = '$/part';
|
|
20
|
+
export const pollChars = 1_000_000;
|
|
21
|
+
function partsOf(message, chars) {
|
|
22
|
+
const text = JSON.stringify(message);
|
|
23
|
+
const size = Math.max(1, Math.floor(chars / 4));
|
|
24
|
+
const count = Math.ceil(text.length / size);
|
|
25
|
+
return Array.from({ length: count }, (_, index) => ({ jsonrpc: '2.0', method: partMethod, params: { text: text.slice(index * size, (index + 1) * size), isLast: index === count - 1 } }));
|
|
26
|
+
}
|
|
27
|
+
function partOf(message) {
|
|
28
|
+
if (typeof message !== 'object' || message === null)
|
|
29
|
+
return undefined;
|
|
30
|
+
const fields = message;
|
|
31
|
+
const params = fields['params'];
|
|
32
|
+
return fields['method'] === partMethod && typeof params === 'object' && params !== null ? params : undefined;
|
|
33
|
+
}
|
|
34
|
+
function takenWithin(outbox, chars) {
|
|
35
|
+
if (chars === undefined)
|
|
36
|
+
return outbox.splice(0);
|
|
37
|
+
const taken = [];
|
|
38
|
+
let size = 0;
|
|
39
|
+
while (outbox.length > 0) {
|
|
40
|
+
const next = outbox[0];
|
|
41
|
+
const length = JSON.stringify(next).length;
|
|
42
|
+
if (length > chars && !('method' in next && next.method === partMethod)) {
|
|
43
|
+
outbox.splice(0, 1, ...partsOf(next, chars));
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (taken.length > 0 && size + length > chars)
|
|
47
|
+
break;
|
|
48
|
+
taken.push(outbox.shift());
|
|
49
|
+
size += length;
|
|
50
|
+
}
|
|
51
|
+
return taken;
|
|
52
|
+
}
|
|
19
53
|
export function createPeer({ send, handle }) {
|
|
20
54
|
const closing = new AbortController();
|
|
21
55
|
const waiting = new Map();
|
|
@@ -147,17 +181,18 @@ export function rpcRoutes({ handle, onClose, now, pollMs = 8000, liveMs = 30_000
|
|
|
147
181
|
send: (message) => {
|
|
148
182
|
if (entry === undefined)
|
|
149
183
|
return;
|
|
184
|
+
outbox.push(message);
|
|
150
185
|
if (entry.poll === undefined)
|
|
151
|
-
return
|
|
186
|
+
return;
|
|
152
187
|
const poll = entry.poll;
|
|
153
188
|
entry.poll = undefined;
|
|
154
|
-
poll(
|
|
189
|
+
poll(takenWithin(outbox, entry.chars));
|
|
155
190
|
},
|
|
156
191
|
handle: (method, params, signal) => handler(method, params, signal),
|
|
157
192
|
});
|
|
158
193
|
const connection = Object.assign(peer, { id });
|
|
159
194
|
const handler = handle(connection);
|
|
160
|
-
entry = { connection, outbox, poll: undefined, seenAt: now() };
|
|
195
|
+
entry = { connection, outbox, poll: undefined, chars: undefined, seenAt: now() };
|
|
161
196
|
held.set(id, entry);
|
|
162
197
|
return entry;
|
|
163
198
|
};
|
|
@@ -173,10 +208,11 @@ export function rpcRoutes({ handle, onClose, now, pollMs = 8000, liveMs = 30_000
|
|
|
173
208
|
each.seenAt = now();
|
|
174
209
|
return each;
|
|
175
210
|
};
|
|
176
|
-
const poll = (each, signal) => new Promise((resolve) => {
|
|
211
|
+
const poll = (each, signal, chars) => new Promise((resolve) => {
|
|
177
212
|
each.poll?.([]);
|
|
213
|
+
each.chars = chars;
|
|
178
214
|
if (each.outbox.length > 0)
|
|
179
|
-
return resolve(each.outbox
|
|
215
|
+
return resolve(takenWithin(each.outbox, chars));
|
|
180
216
|
const timer = timers.setTimeout(() => answer([]), pollMs);
|
|
181
217
|
const answer = (messages) => {
|
|
182
218
|
timers.clearTimeout(timer);
|
|
@@ -197,24 +233,26 @@ export function rpcRoutes({ handle, onClose, now, pollMs = 8000, liveMs = 30_000
|
|
|
197
233
|
});
|
|
198
234
|
const route = async (request) => {
|
|
199
235
|
sweep();
|
|
200
|
-
const
|
|
236
|
+
const url = new URL(request.path, 'http://cmod');
|
|
237
|
+
const [, id] = /^\/rpc\/([\w-]{1,64})$/.exec(url.pathname) ?? [];
|
|
238
|
+
const chars = Number(url.searchParams.get('chars'));
|
|
201
239
|
try {
|
|
202
|
-
if (
|
|
240
|
+
if (url.pathname === `${rpcPath}/connect` && request.method === 'POST')
|
|
203
241
|
return { status: 200, json: { connection: open().connection.id } };
|
|
204
242
|
if (id === undefined)
|
|
205
|
-
return { status: 404, json: { error: `cmod has no ${request.method} ${
|
|
243
|
+
return { status: 404, json: { error: `cmod has no ${request.method} ${url.pathname}.` } };
|
|
206
244
|
if (request.method === 'DELETE') {
|
|
207
245
|
drop(id, 'the client closed it');
|
|
208
246
|
return { status: 204 };
|
|
209
247
|
}
|
|
210
248
|
const each = known(id);
|
|
211
249
|
if (request.method === 'GET')
|
|
212
|
-
return { status: 200, json: await poll(each, request.signal) };
|
|
250
|
+
return { status: 200, json: await poll(each, request.signal, Number.isInteger(chars) && chars > 0 ? chars : undefined) };
|
|
213
251
|
if (request.method === 'POST') {
|
|
214
252
|
each.connection.receive(await request.json());
|
|
215
253
|
return { status: 204 };
|
|
216
254
|
}
|
|
217
|
-
return { status: 405, json: { error: `cmod has no ${request.method} ${
|
|
255
|
+
return { status: 405, json: { error: `cmod has no ${request.method} ${url.pathname}.` } };
|
|
218
256
|
}
|
|
219
257
|
catch (error) {
|
|
220
258
|
if (error instanceof GoneError)
|
|
@@ -311,12 +349,24 @@ export function connectRpc({ call, handle, onConnect, onError, wait, retryMs = 2
|
|
|
311
349
|
};
|
|
312
350
|
const pollLoop = async (link) => {
|
|
313
351
|
while (current === link && !isClosed) {
|
|
314
|
-
const answer = await call(`${rpcPath}/${link.id}`, { method: 'GET' }).catch((error) => ({ status: 0, text: String(error) }));
|
|
352
|
+
const answer = await call(`${rpcPath}/${link.id}?chars=${pollChars}`, { method: 'GET' }).catch((error) => ({ status: 0, text: String(error) }));
|
|
315
353
|
if (current !== link)
|
|
316
354
|
return;
|
|
317
355
|
if (answer.status !== 200)
|
|
318
356
|
return lose(link, new RpcUnreached(`cmod serve answered the poll with ${answer.status}: ${answer.text}`));
|
|
319
|
-
|
|
357
|
+
for (const message of [JSON.parse(answer.text)].flat()) {
|
|
358
|
+
const part = partOf(message);
|
|
359
|
+
if (part === undefined) {
|
|
360
|
+
link.peer.receive(message);
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
link.part += String(part['text']);
|
|
364
|
+
if (part['isLast'] !== true)
|
|
365
|
+
continue;
|
|
366
|
+
const whole = link.part;
|
|
367
|
+
link.part = '';
|
|
368
|
+
link.peer.receive(JSON.parse(whole));
|
|
369
|
+
}
|
|
320
370
|
}
|
|
321
371
|
};
|
|
322
372
|
let hasConnected = false;
|
|
@@ -349,6 +399,7 @@ export function connectRpc({ call, handle, onConnect, onError, wait, retryMs = 2
|
|
|
349
399
|
}),
|
|
350
400
|
lastAsked: undefined,
|
|
351
401
|
undelivered: new Set(),
|
|
402
|
+
part: '',
|
|
352
403
|
};
|
|
353
404
|
current = link;
|
|
354
405
|
hasConnected = true;
|
package/src/records.ts
CHANGED
|
@@ -493,7 +493,7 @@ function readHotkeys(hotkeys: unknown): Steps {
|
|
|
493
493
|
return { hotkeys: checkHotkeys('package.json "cmod"', hotkeys as Record<string, HotkeyInit>) }
|
|
494
494
|
}
|
|
495
495
|
|
|
496
|
-
export const coreVersion = '8.4.
|
|
496
|
+
export const coreVersion = '8.4.2'
|
|
497
497
|
|
|
498
498
|
export const oldestCmodVersion = '8.0.0'
|
|
499
499
|
|
package/src/runtime/buttons.ts
CHANGED
|
@@ -15,6 +15,7 @@ export function filledButton({ key, label, hotkey, variant = 'secondary', onPres
|
|
|
15
15
|
plain: true,
|
|
16
16
|
key,
|
|
17
17
|
label,
|
|
18
|
+
variant,
|
|
18
19
|
...(hotkey === undefined ? {} : { hotkey }),
|
|
19
20
|
onPress,
|
|
20
21
|
children: Text({ backgroundColor: isPrimary ? 'claude' : 'userMessageBackground', color: isPrimary ? 'inverseText' : 'text', bold: isPrimary, children: ` ${label} ` }),
|
package/src/runtime/rpc.ts
CHANGED
|
@@ -40,6 +40,42 @@ export type Peer = {
|
|
|
40
40
|
|
|
41
41
|
const cancelMethod = '$/cancelRequest'
|
|
42
42
|
|
|
43
|
+
const partMethod = '$/part'
|
|
44
|
+
|
|
45
|
+
export const pollChars = 1_000_000
|
|
46
|
+
|
|
47
|
+
function partsOf(message: RpcMessage, chars: number): RpcMessage[] {
|
|
48
|
+
const text = JSON.stringify(message)
|
|
49
|
+
const size = Math.max(1, Math.floor(chars / 4))
|
|
50
|
+
const count = Math.ceil(text.length / size)
|
|
51
|
+
return Array.from({ length: count }, (_, index) => ({ jsonrpc: '2.0', method: partMethod, params: { text: text.slice(index * size, (index + 1) * size), isLast: index === count - 1 } }))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function partOf(message: unknown): Readonly<Record<string, unknown>> | undefined {
|
|
55
|
+
if (typeof message !== 'object' || message === null) return undefined
|
|
56
|
+
const fields = message as Readonly<Record<string, unknown>>
|
|
57
|
+
const params = fields['params']
|
|
58
|
+
return fields['method'] === partMethod && typeof params === 'object' && params !== null ? (params as Readonly<Record<string, unknown>>) : undefined
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function takenWithin(outbox: RpcMessage[], chars: number | undefined): RpcMessage[] {
|
|
62
|
+
if (chars === undefined) return outbox.splice(0)
|
|
63
|
+
const taken: RpcMessage[] = []
|
|
64
|
+
let size = 0
|
|
65
|
+
while (outbox.length > 0) {
|
|
66
|
+
const next = outbox[0] as RpcMessage
|
|
67
|
+
const length = JSON.stringify(next).length
|
|
68
|
+
if (length > chars && !('method' in next && next.method === partMethod)) {
|
|
69
|
+
outbox.splice(0, 1, ...partsOf(next, chars))
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
72
|
+
if (taken.length > 0 && size + length > chars) break
|
|
73
|
+
taken.push(outbox.shift() as RpcMessage)
|
|
74
|
+
size += length
|
|
75
|
+
}
|
|
76
|
+
return taken
|
|
77
|
+
}
|
|
78
|
+
|
|
43
79
|
type Waiting = { resolve(value: unknown): void; reject(error: Error): void }
|
|
44
80
|
|
|
45
81
|
export function createPeer({ send, handle }: { readonly send: (message: RpcMessage) => void; readonly handle: RpcHandler }): Peer {
|
|
@@ -151,6 +187,7 @@ type Held = {
|
|
|
151
187
|
readonly connection: RpcConnection
|
|
152
188
|
readonly outbox: RpcMessage[]
|
|
153
189
|
poll: ((messages: RpcMessage[]) => void) | undefined
|
|
190
|
+
chars: number | undefined
|
|
154
191
|
seenAt: number
|
|
155
192
|
}
|
|
156
193
|
|
|
@@ -198,16 +235,17 @@ export function rpcRoutes({
|
|
|
198
235
|
const peer = createPeer({
|
|
199
236
|
send: (message) => {
|
|
200
237
|
if (entry === undefined) return
|
|
201
|
-
|
|
238
|
+
outbox.push(message)
|
|
239
|
+
if (entry.poll === undefined) return
|
|
202
240
|
const poll = entry.poll
|
|
203
241
|
entry.poll = undefined
|
|
204
|
-
poll(
|
|
242
|
+
poll(takenWithin(outbox, entry.chars))
|
|
205
243
|
},
|
|
206
244
|
handle: (method, params, signal) => handler(method, params, signal),
|
|
207
245
|
})
|
|
208
246
|
const connection: RpcConnection = Object.assign(peer, { id })
|
|
209
247
|
const handler = handle(connection)
|
|
210
|
-
entry = { connection, outbox, poll: undefined, seenAt: now() }
|
|
248
|
+
entry = { connection, outbox, poll: undefined, chars: undefined, seenAt: now() }
|
|
211
249
|
held.set(id, entry)
|
|
212
250
|
return entry
|
|
213
251
|
}
|
|
@@ -223,10 +261,11 @@ export function rpcRoutes({
|
|
|
223
261
|
return each
|
|
224
262
|
}
|
|
225
263
|
|
|
226
|
-
const poll = (each: Held, signal: AbortSignal) =>
|
|
264
|
+
const poll = (each: Held, signal: AbortSignal, chars: number | undefined) =>
|
|
227
265
|
new Promise<RpcMessage[]>((resolve) => {
|
|
228
266
|
each.poll?.([])
|
|
229
|
-
|
|
267
|
+
each.chars = chars
|
|
268
|
+
if (each.outbox.length > 0) return resolve(takenWithin(each.outbox, chars))
|
|
230
269
|
const timer = timers.setTimeout(() => answer([]), pollMs)
|
|
231
270
|
const answer = (messages: RpcMessage[]) => {
|
|
232
271
|
timers.clearTimeout(timer)
|
|
@@ -246,21 +285,23 @@ export function rpcRoutes({
|
|
|
246
285
|
|
|
247
286
|
const route = async (request: RpcHttpRequest): Promise<RpcHttpAnswer> => {
|
|
248
287
|
sweep()
|
|
249
|
-
const
|
|
288
|
+
const url = new URL(request.path, 'http://cmod')
|
|
289
|
+
const [, id] = /^\/rpc\/([\w-]{1,64})$/.exec(url.pathname) ?? []
|
|
290
|
+
const chars = Number(url.searchParams.get('chars'))
|
|
250
291
|
try {
|
|
251
|
-
if (
|
|
252
|
-
if (id === undefined) return { status: 404, json: { error: `cmod has no ${request.method} ${
|
|
292
|
+
if (url.pathname === `${rpcPath}/connect` && request.method === 'POST') return { status: 200, json: { connection: open().connection.id } }
|
|
293
|
+
if (id === undefined) return { status: 404, json: { error: `cmod has no ${request.method} ${url.pathname}.` } }
|
|
253
294
|
if (request.method === 'DELETE') {
|
|
254
295
|
drop(id, 'the client closed it')
|
|
255
296
|
return { status: 204 }
|
|
256
297
|
}
|
|
257
298
|
const each = known(id)
|
|
258
|
-
if (request.method === 'GET') return { status: 200, json: await poll(each, request.signal) }
|
|
299
|
+
if (request.method === 'GET') return { status: 200, json: await poll(each, request.signal, Number.isInteger(chars) && chars > 0 ? chars : undefined) }
|
|
259
300
|
if (request.method === 'POST') {
|
|
260
301
|
each.connection.receive(await request.json())
|
|
261
302
|
return { status: 204 }
|
|
262
303
|
}
|
|
263
|
-
return { status: 405, json: { error: `cmod has no ${request.method} ${
|
|
304
|
+
return { status: 405, json: { error: `cmod has no ${request.method} ${url.pathname}.` } }
|
|
264
305
|
} catch (error) {
|
|
265
306
|
if (error instanceof GoneError) return { status: goneStatus, json: { error: error.message } }
|
|
266
307
|
throw error
|
|
@@ -346,7 +387,7 @@ export function connectRpc({
|
|
|
346
387
|
readonly retryMs?: number
|
|
347
388
|
readonly keepsConnecting?: boolean
|
|
348
389
|
}): RpcClient {
|
|
349
|
-
type Link = { readonly id: string; readonly peer: Peer; lastAsked: RpcId | undefined; readonly undelivered: Set<RpcId
|
|
390
|
+
type Link = { readonly id: string; readonly peer: Peer; lastAsked: RpcId | undefined; readonly undelivered: Set<RpcId>; part: string }
|
|
350
391
|
let current: Link | undefined
|
|
351
392
|
let connecting: Promise<Link> | undefined
|
|
352
393
|
let isClosed = false
|
|
@@ -385,10 +426,21 @@ export function connectRpc({
|
|
|
385
426
|
|
|
386
427
|
const pollLoop = async (link: Link) => {
|
|
387
428
|
while (current === link && !isClosed) {
|
|
388
|
-
const answer = await call(`${rpcPath}/${link.id}`, { method: 'GET' }).catch((error: unknown) => ({ status: 0, text: String(error) }))
|
|
429
|
+
const answer = await call(`${rpcPath}/${link.id}?chars=${pollChars}`, { method: 'GET' }).catch((error: unknown) => ({ status: 0, text: String(error) }))
|
|
389
430
|
if (current !== link) return
|
|
390
431
|
if (answer.status !== 200) return lose(link, new RpcUnreached(`cmod serve answered the poll with ${answer.status}: ${answer.text}`))
|
|
391
|
-
|
|
432
|
+
for (const message of [JSON.parse(answer.text) as unknown].flat()) {
|
|
433
|
+
const part = partOf(message)
|
|
434
|
+
if (part === undefined) {
|
|
435
|
+
link.peer.receive(message)
|
|
436
|
+
continue
|
|
437
|
+
}
|
|
438
|
+
link.part += String(part['text'])
|
|
439
|
+
if (part['isLast'] !== true) continue
|
|
440
|
+
const whole = link.part
|
|
441
|
+
link.part = ''
|
|
442
|
+
link.peer.receive(JSON.parse(whole))
|
|
443
|
+
}
|
|
392
444
|
}
|
|
393
445
|
}
|
|
394
446
|
|
|
@@ -420,6 +472,7 @@ export function connectRpc({
|
|
|
420
472
|
}),
|
|
421
473
|
lastAsked: undefined,
|
|
422
474
|
undelivered: new Set(),
|
|
475
|
+
part: '',
|
|
423
476
|
}
|
|
424
477
|
current = link
|
|
425
478
|
hasConnected = true
|
|
@@ -195,7 +195,12 @@ export function fakeClaude(plugin: { readonly name: string; readonly root: strin
|
|
|
195
195
|
},
|
|
196
196
|
http: {
|
|
197
197
|
fetch: async (url, init) => {
|
|
198
|
-
if (fakes.http.fetch === undefined && init?.socketPath?.endsWith('/serve.sock') === true)
|
|
198
|
+
if (fakes.http.fetch === undefined && init?.socketPath?.endsWith('/serve.sock') === true) {
|
|
199
|
+
const answer = await serve.fetch(url, init)
|
|
200
|
+
const bytes = new TextEncoder().encode(answer.text).length
|
|
201
|
+
if (bytes > fetchBodyLimit) throw new Error(`$.http.fetch: ${url} refused: body of ${bytes} bytes is over the ${fetchBodyLimit}-byte limit`)
|
|
202
|
+
return answer
|
|
203
|
+
}
|
|
199
204
|
return fetchFake(url, init)
|
|
200
205
|
},
|
|
201
206
|
},
|
|
@@ -285,6 +290,8 @@ export function fakeClaude(plugin: { readonly name: string; readonly root: strin
|
|
|
285
290
|
return { claude, calls, fakes, shown, store, serve, settle, placePane }
|
|
286
291
|
}
|
|
287
292
|
|
|
293
|
+
const fetchBodyLimit = 4_194_304
|
|
294
|
+
|
|
288
295
|
declare function setTimeout(fn: () => void, ms: number): unknown
|
|
289
296
|
declare function clearTimeout(timeout: unknown): void
|
|
290
297
|
|
|
@@ -87,7 +87,7 @@ export function fakeServe(
|
|
|
87
87
|
},
|
|
88
88
|
async fetch(url, init = {}) {
|
|
89
89
|
requests += 1
|
|
90
|
-
const answered = await routing.routes.route({ method: init.method ?? 'GET', path: new URL(url).pathname
|
|
90
|
+
const answered = await routing.routes.route({ method: init.method ?? 'GET', path: `${new URL(url).pathname}${new URL(url).search}`, signal: new AbortController().signal, json: async () => JSON.parse(String(init.body)) as unknown })
|
|
91
91
|
if (answered === undefined) return { status: 404, ok: false, headers: {}, text: '' }
|
|
92
92
|
return { status: answered.status, ok: answered.status >= 200 && answered.status < 300, headers: {}, text: answered.json === undefined ? '' : JSON.stringify(answered.json) }
|
|
93
93
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-claude.d.ts","sourceRoot":"","sources":["../src/testing/fake-claude.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAS,MAAM,aAAa,CAAA;AAEhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAElD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAK/D,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE/D,MAA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AAM,EAAE,CAAA;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAA;IACxB,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAA;IACxB,QAAQ,CAAC,SAAS,EAAE,aAAa,EAAE,CAAA;CACpC,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;IACzB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACvB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;CAC5B,CAAA;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC,GAAG,OAAO,CAGtF;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,UAAU,CA0N/F"}
|
package/testing/fake-claude.js
CHANGED
|
@@ -140,8 +140,13 @@ export function fakeClaude(plugin) {
|
|
|
140
140
|
},
|
|
141
141
|
http: {
|
|
142
142
|
fetch: async (url, init) => {
|
|
143
|
-
if (fakes.http.fetch === undefined && init?.socketPath?.endsWith('/serve.sock') === true)
|
|
144
|
-
|
|
143
|
+
if (fakes.http.fetch === undefined && init?.socketPath?.endsWith('/serve.sock') === true) {
|
|
144
|
+
const answer = await serve.fetch(url, init);
|
|
145
|
+
const bytes = new TextEncoder().encode(answer.text).length;
|
|
146
|
+
if (bytes > fetchBodyLimit)
|
|
147
|
+
throw new Error(`$.http.fetch: ${url} refused: body of ${bytes} bytes is over the ${fetchBodyLimit}-byte limit`);
|
|
148
|
+
return answer;
|
|
149
|
+
}
|
|
145
150
|
return fetchFake(url, init);
|
|
146
151
|
},
|
|
147
152
|
},
|
|
@@ -228,6 +233,7 @@ export function fakeClaude(plugin) {
|
|
|
228
233
|
};
|
|
229
234
|
return { claude, calls, fakes, shown, store, serve, settle, placePane };
|
|
230
235
|
}
|
|
236
|
+
const fetchBodyLimit = 4_194_304;
|
|
231
237
|
function isServeHolder(argv) {
|
|
232
238
|
return argv[1] === 'program' && argv[2] === cmodPluginName && argv.at(-2) === cmodPluginName && argv.at(-1) === 'serve';
|
|
233
239
|
}
|
package/testing/fake-serve.js
CHANGED
|
@@ -48,7 +48,7 @@ export function fakeServe(fakes, { device, programs, clock = realClock }) {
|
|
|
48
48
|
},
|
|
49
49
|
async fetch(url, init = {}) {
|
|
50
50
|
requests += 1;
|
|
51
|
-
const answered = await routing.routes.route({ method: init.method ?? 'GET', path: new URL(url).pathname
|
|
51
|
+
const answered = await routing.routes.route({ method: init.method ?? 'GET', path: `${new URL(url).pathname}${new URL(url).search}`, signal: new AbortController().signal, json: async () => JSON.parse(String(init.body)) });
|
|
52
52
|
if (answered === undefined)
|
|
53
53
|
return { status: 404, ok: false, headers: {}, text: '' };
|
|
54
54
|
return { status: answered.status, ok: answered.status >= 200 && answered.status < 300, headers: {}, text: answered.json === undefined ? '' : JSON.stringify(answered.json) };
|