@fnndsc/calypso 0.4.3 → 0.5.1

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 CHANGED
@@ -14,11 +14,12 @@ The wire contract, daemon, session bus, identity-keyed discovery, and ChELL remo
14
14
 
15
15
  The contract is defined as [zod](https://zod.dev) schemas — the single source of truth, from which the message types are inferred and against which every message is validated at the boundary.
16
16
 
17
- - **Messages** (two direction-keyed unions): surfaces attach, execute, complete,
18
- answer prompts, return local pipe results or failures, and return edits; the
17
+ - **Messages** (two direction-keyed unions): surfaces attach with their local
18
+ capabilities, execute, complete,
19
+ answer prompts, return local pipe and shell results or failures, and return edits; the
19
20
  daemon acknowledges attachment, returns results and completion, streams output
20
21
  and structured progress, broadcasts session envelopes, pushes prompt context,
21
- delegates prompts/pipes/edits to the originating surface, and reports errors.
22
+ delegates prompts/pipes/shell escapes/edits to the originating surface, and reports errors.
22
23
  - **Envelope** — the `commandEnvelopeSchema` validates cumin's `CommandEnvelope` on the wire; a compile-time guard keeps the schema in step with cumin's type so the published contract can never silently drift from what the code produces.
23
24
  - **Boundary validation** — structural violations are rejected; unknown *additive* fields are tolerated, so a daemon accepts extensions from a newer minor without understanding them. Parsing never throws.
24
25
  - **Versioning** — the contract version (`CONTRACT_VERSION`) is carried in the attach handshake and refused on mismatch; within a major, changes are additive only.
@@ -152,7 +152,11 @@ export function berth_read(identity) {
152
152
  const berth = berth_validate(JSON.parse(readFileSync(path, 'utf-8')));
153
153
  return berth && berth.identity === identity ? berth : null;
154
154
  }
155
- catch {
155
+ catch (error) {
156
+ // A corrupt berth file reading as "no daemon" sends the user down a
157
+ // confusing start-a-new-daemon path; name the file so it can be removed.
158
+ const msg = error instanceof Error ? error.message : String(error);
159
+ console.error(`[!] Ignoring unreadable berth file ${path}: ${msg}`);
156
160
  return null;
157
161
  }
158
162
  }
@@ -178,8 +182,11 @@ export function berthAll_read() {
178
182
  berths.push(berth);
179
183
  }
180
184
  }
181
- catch {
182
- // A malformed or vanished file is simply skipped.
185
+ catch (error) {
186
+ // Skipped, but named: a corrupted berth silently vanishing from the
187
+ // --remote picker is indistinguishable from a stopped daemon.
188
+ const msg = error instanceof Error ? error.message : String(error);
189
+ console.error(`[!] Skipping unreadable berth file ${join(dir, name)}: ${msg}`);
183
190
  }
184
191
  }
185
192
  return berths;
@@ -1 +1 @@
1
- {"version":3,"file":"berth.js","sourceRoot":"","sources":["../../src/daemon/berth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AACjG,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAe,MAAM,UAAU,CAAC;AAE/D,iFAAiF;AACjF,MAAM,iBAAiB,GAAW,QAAQ,CAAC;AAC3C,8EAA8E;AAC9E,MAAM,YAAY,GAAW,SAAS,CAAC;AAiBvC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,OAAe;IAC9D,MAAM,WAAW,GAAW,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACnD,IAAI,aAAqB,CAAC;IAC1B,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;QACvB,aAAa,GAAG,OAAO,CAAC;IAC1B,CAAC;SAAM,CAAC;QACN,MAAM,MAAM,GAAW,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC;QACnE,MAAM,IAAI,GAAW,OAAO,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;QACpD,wEAAw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,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,IAAI,CAAC,cAAc,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAC/D,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,kBAAkB;IACX,KAAK,CAAC,IAAI;QACf,MAAM,MAAM,GAAY,aAAa,EAAE,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,MAAM,IAAI,GAAY,EAAE,CAAC;QACzB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,MAAM,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,CAAC;iBAAM,CAAC;gBACN,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @file Correlated request broker.
3
+ *
4
+ * One lifecycle for every correlation-id request/reply exchange over a
5
+ * WebSocket: the daemon's four surface-delegated brokers (prompt, pipeline
6
+ * segment, host shell, edit) and the remote client's own pending requests all
7
+ * previously reimplemented this shape independently, with divergent
8
+ * correctness (leaked close-listeners, settles that accepted answers from any
9
+ * socket, kinds with no failure path). This class is the single
10
+ * implementation: id generation, the pending map, close-listener hygiene, and
11
+ * origin validation live here; what a request or reply looks like on the wire
12
+ * stays with the caller, so the protocol is unchanged.
13
+ *
14
+ * @module
15
+ */
16
+ import type { WebSocket } from 'ws';
17
+ /**
18
+ * A broker for one kind of correlated request over a WebSocket.
19
+ *
20
+ * Guarantees, uniformly for every kind: an id unique within the broker, a
21
+ * rejection when the origin socket closes before answering, removal of the
22
+ * close listener once settled (no per-request listener leak), and settles
23
+ * accepted only from the socket the request was sent to (no cross-surface
24
+ * answering).
25
+ *
26
+ * @example
27
+ * ```
28
+ * const prompts = new RequestBroker<string>('p', 'surface disconnected before answering');
29
+ * const answer = await prompts.open(surface.socket, (promptId) =>
30
+ * send(surface.socket, { type: 'prompt', promptId, message, hidden }));
31
+ * // on a promptAnswer message:
32
+ * prompts.settle(socket, message.promptId, message.answer);
33
+ * ```
34
+ */
35
+ export declare class RequestBroker<TReply> {
36
+ private readonly idPrefix;
37
+ private readonly disconnectReason;
38
+ private readonly pending;
39
+ private seq;
40
+ /**
41
+ * @param idPrefix - Prefix for generated correlation ids (e.g. `'p'`).
42
+ * @param disconnectReason - Rejection message when the origin closes first.
43
+ */
44
+ constructor(idPrefix: string, disconnectReason: string);
45
+ /**
46
+ * Opens a request with a generated id: registers the pending entry and its
47
+ * close guard, then invokes `send` with the id to put the request on the
48
+ * wire.
49
+ *
50
+ * @param origin - The socket the request goes to; only it may settle.
51
+ * @param send - Callback that transmits the request, given the new id.
52
+ * @returns The correlated reply.
53
+ * @throws {Error} With the broker's disconnect reason when the origin closes
54
+ * before answering, or the reason given to {@link fail}.
55
+ */
56
+ open(origin: WebSocket, send: (id: string) => void): Promise<TReply>;
57
+ /**
58
+ * Opens a request under a caller-supplied id, for callers that already
59
+ * correlate ids externally (the remote client's execute/complete counter).
60
+ *
61
+ * @param id - The correlation id to register.
62
+ * @param origin - The socket the request goes to; only it may settle.
63
+ * @param send - Callback that transmits the request, given the id.
64
+ * @returns The correlated reply.
65
+ * @throws {Error} As {@link open}.
66
+ */
67
+ openWithId(id: string, origin: WebSocket, send: (id: string) => void): Promise<TReply>;
68
+ /**
69
+ * Resolves a pending request with its reply. Ignored when the id is unknown
70
+ * or the reply arrives from a socket other than the request's origin.
71
+ *
72
+ * @param socket - The socket the reply arrived on.
73
+ * @param id - The correlation id.
74
+ * @param reply - The reply value.
75
+ */
76
+ settle(socket: WebSocket, id: string, reply: TReply): void;
77
+ /**
78
+ * Rejects a pending request with a reported failure. Ignored when the id is
79
+ * unknown or the failure arrives from a socket other than the request's
80
+ * origin.
81
+ *
82
+ * @param socket - The socket the failure arrived on.
83
+ * @param id - The correlation id.
84
+ * @param reason - Human-readable failure reason.
85
+ */
86
+ fail(socket: WebSocket, id: string, reason: string): void;
87
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * A broker for one kind of correlated request over a WebSocket.
3
+ *
4
+ * Guarantees, uniformly for every kind: an id unique within the broker, a
5
+ * rejection when the origin socket closes before answering, removal of the
6
+ * close listener once settled (no per-request listener leak), and settles
7
+ * accepted only from the socket the request was sent to (no cross-surface
8
+ * answering).
9
+ *
10
+ * @example
11
+ * ```
12
+ * const prompts = new RequestBroker<string>('p', 'surface disconnected before answering');
13
+ * const answer = await prompts.open(surface.socket, (promptId) =>
14
+ * send(surface.socket, { type: 'prompt', promptId, message, hidden }));
15
+ * // on a promptAnswer message:
16
+ * prompts.settle(socket, message.promptId, message.answer);
17
+ * ```
18
+ */
19
+ export class RequestBroker {
20
+ idPrefix;
21
+ disconnectReason;
22
+ pending = new Map();
23
+ seq = 0;
24
+ /**
25
+ * @param idPrefix - Prefix for generated correlation ids (e.g. `'p'`).
26
+ * @param disconnectReason - Rejection message when the origin closes first.
27
+ */
28
+ constructor(idPrefix, disconnectReason) {
29
+ this.idPrefix = idPrefix;
30
+ this.disconnectReason = disconnectReason;
31
+ }
32
+ /**
33
+ * Opens a request with a generated id: registers the pending entry and its
34
+ * close guard, then invokes `send` with the id to put the request on the
35
+ * wire.
36
+ *
37
+ * @param origin - The socket the request goes to; only it may settle.
38
+ * @param send - Callback that transmits the request, given the new id.
39
+ * @returns The correlated reply.
40
+ * @throws {Error} With the broker's disconnect reason when the origin closes
41
+ * before answering, or the reason given to {@link fail}.
42
+ */
43
+ open(origin, send) {
44
+ return this.openWithId(`${this.idPrefix}${this.seq++}`, origin, send);
45
+ }
46
+ /**
47
+ * Opens a request under a caller-supplied id, for callers that already
48
+ * correlate ids externally (the remote client's execute/complete counter).
49
+ *
50
+ * @param id - The correlation id to register.
51
+ * @param origin - The socket the request goes to; only it may settle.
52
+ * @param send - Callback that transmits the request, given the id.
53
+ * @returns The correlated reply.
54
+ * @throws {Error} As {@link open}.
55
+ */
56
+ openWithId(id, origin, send) {
57
+ return new Promise((resolve, reject) => {
58
+ const onClose = () => {
59
+ if (this.pending.delete(id)) {
60
+ reject(new Error(this.disconnectReason));
61
+ }
62
+ };
63
+ this.pending.set(id, { origin, onClose, resolve, reject });
64
+ origin.once('close', onClose);
65
+ send(id);
66
+ });
67
+ }
68
+ /**
69
+ * Resolves a pending request with its reply. Ignored when the id is unknown
70
+ * or the reply arrives from a socket other than the request's origin.
71
+ *
72
+ * @param socket - The socket the reply arrived on.
73
+ * @param id - The correlation id.
74
+ * @param reply - The reply value.
75
+ */
76
+ settle(socket, id, reply) {
77
+ const entry = this.pending.get(id);
78
+ if (!entry || entry.origin !== socket)
79
+ return;
80
+ this.pending.delete(id);
81
+ entry.origin.removeListener('close', entry.onClose);
82
+ entry.resolve(reply);
83
+ }
84
+ /**
85
+ * Rejects a pending request with a reported failure. Ignored when the id is
86
+ * unknown or the failure arrives from a socket other than the request's
87
+ * origin.
88
+ *
89
+ * @param socket - The socket the failure arrived on.
90
+ * @param id - The correlation id.
91
+ * @param reason - Human-readable failure reason.
92
+ */
93
+ fail(socket, id, reason) {
94
+ const entry = this.pending.get(id);
95
+ if (!entry || entry.origin !== socket)
96
+ return;
97
+ this.pending.delete(id);
98
+ entry.origin.removeListener('close', entry.onClose);
99
+ entry.reject(new Error(reason));
100
+ }
101
+ }
102
+ //# sourceMappingURL=broker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker.js","sourceRoot":"","sources":["../../src/daemon/broker.ts"],"names":[],"mappings":"AA2BA;;;;;;;;;;;;;;;;;GAiBG;AACH,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MAAM,KAAK,MAAM;YAAE,OAAO;QAC9C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACxB,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACpD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED;;;;;;;;OAQG;IACI,IAAI,CAAC,MAAiB,EAAE,EAAU,EAAE,MAAc;QACvD,MAAM,KAAK,GAAsC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;YAAE,OAAO;QAC9C,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACxB,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACpD,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAClC,CAAC;CACF"}
@@ -46,7 +46,11 @@ export function discovery_read() {
46
46
  }
47
47
  return null;
48
48
  }
49
- catch {
49
+ catch (error) {
50
+ // Same rationale as berth_read: a corrupt discovery file must not be
51
+ // indistinguishable from "no daemon running".
52
+ const msg = error instanceof Error ? error.message : String(error);
53
+ console.error(`[!] Ignoring unreadable discovery file ${path}: ${msg}`);
50
54
  return null;
51
55
  }
52
56
  }
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/daemon/discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,Q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@returns The envelopes of the executed commands, in order.
35
35
  */
36
36
  line_execute(line: string): Promise<CommandEnvelope[]>;
37
+ /**
38
+ * Requests cancellation of the foreground command when it supports it.
39
+ *
40
+ * @returns True when the active command accepted the request.
41
+ */
42
+ line_cancel?(): boolean;
37
43
  /**
38
44
  * Computes completion candidates for a partial input line.
39
45
  *
@@ -1,4 +1,34 @@
1
+ import { CalypsoDaemon } from './server.js';
1
2
  import type { BrasaEngine } from '@fnndsc/brasa';
3
+ import { type OutputSink } from '@fnndsc/brasa';
4
+ import type { ProgressEvent } from '@fnndsc/brasa';
5
+ import { type Surface } from '@fnndsc/brasa';
6
+ /** The daemon sink forwards live command output to the executing surface. */
7
+ export declare class DaemonSink implements OutputSink {
8
+ private readonly daemon;
9
+ constructor(daemon: CalypsoDaemon);
10
+ /** @inheritdoc */
11
+ data_write(chunk: string | Buffer): void;
12
+ /** @inheritdoc */
13
+ err_write(chunk: string | Buffer): void;
14
+ /** @inheritdoc */
15
+ status_write(text: string): void;
16
+ /** @inheritdoc */
17
+ progress_write(event: ProgressEvent): void;
18
+ private output_write;
19
+ }
20
+ /**
21
+ * Builds the surface a daemon-hosted engine talks to.
22
+ *
23
+ * Interactivity is a surface capability: prompts, pipeline segments, shell
24
+ * escapes, and local editing reach the surface running the command through
25
+ * the daemon's brokers, without knowing the transport. Nothing ever spawns
26
+ * on the daemon host.
27
+ *
28
+ * @param daemon - The daemon whose brokers deliver the capability requests.
29
+ * @returns The surface to install with `surface_set` on the daemon host.
30
+ */
31
+ export declare function daemonSurface_create(daemon: CalypsoDaemon): Surface;
2
32
  /**
3
33
  * Starts the daemon over an engine and advertises it for same-user discovery.
4
34
  *
@@ -17,10 +17,11 @@ import { token_generate } from './token.js';
17
17
  import { sink_set } from '@fnndsc/brasa';
18
18
  import { surface_set } from '@fnndsc/brasa';
19
19
  import { sessionPromptContext_build } from '@fnndsc/brasa';
20
+ import { welcomeLine_build, versionReport_build, versions_get, buildHash_get, fortune_random } from '@fnndsc/brasa';
20
21
  import { chrisContext } from '@fnndsc/cumin';
21
22
  import { identity_forSession, berth_write, berth_read, berth_path, berthUrl_isAlive, DISCONNECTED_IDENTITY } from './berth.js';
22
23
  /** The daemon sink forwards live command output to the executing surface. */
23
- class DaemonSink {
24
+ export class DaemonSink {
24
25
  daemon;
25
26
  constructor(daemon) {
26
27
  this.daemon = daemon;
@@ -38,6 +39,32 @@ class DaemonSink {
38
39
  this.daemon.output_current(channel, text);
39
40
  }
40
41
  }
42
+ /**
43
+ * Builds the surface a daemon-hosted engine talks to.
44
+ *
45
+ * Interactivity is a surface capability: prompts, pipeline segments, shell
46
+ * escapes, and local editing reach the surface running the command through
47
+ * the daemon's brokers, without knowing the transport. Nothing ever spawns
48
+ * on the daemon host.
49
+ *
50
+ * @param daemon - The daemon whose brokers deliver the capability requests.
51
+ * @returns The surface to install with `surface_set` on the daemon host.
52
+ */
53
+ export function daemonSurface_create(daemon) {
54
+ return {
55
+ capabilities: {
56
+ hiddenInput: true,
57
+ localEdit: true,
58
+ tty: true,
59
+ pipeSegments: true,
60
+ shellCommands: true,
61
+ },
62
+ prompt: (request) => daemon.prompt_current(request.message, request.hidden ?? false),
63
+ pipeSegment: (command, input) => daemon.pipe_current(command, input),
64
+ shellCommand: (command) => daemon.shell_current(command),
65
+ localEdit: (request) => daemon.edit_current(request.content, request.extension),
66
+ };
67
+ }
41
68
  /**
42
69
  * Starts the daemon over an engine and advertises it for same-user discovery.
43
70
  *
@@ -82,24 +109,22 @@ export async function daemon_launch(engine, beforeListen) {
82
109
  // Only the daemon holds the session context, so it renders the themed
83
110
  // prompt and pushes it to surfaces.
84
111
  promptProvider: () => sessionPromptContext_build(),
112
+ // Report this process's own versions and build hash so attaching surfaces
113
+ // greet with the daemon's truth rather than their local install's.
114
+ stack: { ...versions_get(), build: buildHash_get() },
85
115
  });
86
116
  sink_set(new DaemonSink(daemon));
87
- // Interactivity is a surface capability: a builtin that prompts, or a
88
- // pipeline segment, reaches the surface running the command through the
89
- // daemon's brokers, over the wire, without knowing the transport — and
90
- // nothing ever spawns on the daemon host.
91
- const surface = {
92
- capabilities: { hiddenInput: true, localEdit: true, tty: true, pipeSegments: true },
93
- prompt: (request) => daemon.prompt_current(request.message, request.hidden ?? false),
94
- pipeSegment: (command, input) => daemon.pipe_current(command, input),
95
- localEdit: (request) => daemon.edit_current(request.content, request.extension),
96
- };
97
- surface_set(surface);
117
+ surface_set(daemonSurface_create(daemon));
98
118
  const port = await daemon.start();
99
119
  const url = `ws://127.0.0.1:${port}`;
100
120
  const berth = { identity, url, token };
101
121
  berth_write(berth);
102
122
  const attachHint = identity === DISCONNECTED_IDENTITY ? '' : ` ${identity}`;
123
+ console.log(chalk.bold.cyan(welcomeLine_build('calypso')));
124
+ for (const line of versionReport_build().split('\n')) {
125
+ console.log(chalk.gray(` ${line}`));
126
+ }
127
+ console.log(chalk.gray(fortune_random(4)));
103
128
  console.log(chalk.green(`[+] CALYPSO daemon listening on ${url}`));
104
129
  console.log(chalk.gray(` identity: ${identity}`));
105
130
  console.log(chalk.gray(` token: ${token}`));
@@ -1 +1 @@
1
- {"version":3,"file":"launch.js","sourceRoot":"","sources":["../../src/daemon/launch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAmB,MAAM,eAAe,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAiF,MAAM,eAAe,CAAC;AAC3H,OAAO,EAAE,0BAA0B,EAA6B,MAAM,eAAe,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,qBAAqB,EAAc,MAAM,YAAY,CAAC;AAE3I,6E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,CAAC;IAClE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,6CAA6C,UAAU,EAAE,CAAC,CAAC,CAAC;AACrF,CAAC"}
@@ -1,5 +1,23 @@
1
1
  import type { HostedEngine } from './engine.js';
2
2
  import type { ProgressEvent, PromptContext } from '../protocol/messages.js';
3
+ /**
4
+ * The hosting process's stack identity, sent to surfaces in the attach ack.
5
+ * Injected by the host (which resolves it from brasa) rather than resolved
6
+ * here, keeping the transport server free of engine dependencies.
7
+ *
8
+ * @property chell - The daemon's installed chell version.
9
+ * @property calypso - The daemon's installed calypso version.
10
+ * @property build - The daemon's short build hash.
11
+ */
12
+ export interface DaemonStackInfo {
13
+ chell: string;
14
+ calypso: string;
15
+ build: string;
16
+ brasa?: string;
17
+ chili?: string;
18
+ salsa?: string;
19
+ cumin?: string;
20
+ }
3
21
  /** The result of a surface's local edit, returned by {@link CalypsoDaemon.edit_current}. */
4
22
  export interface EditOutcome {
5
23
  content: string;
@@ -26,6 +44,8 @@ export interface DaemonOptions {
26
44
  host?: string;
27
45
  scrollbackSize?: number;
28
46
  promptProvider?: () => PromptContext | Promise<PromptContext>;
47
+ /** The hosting process's versions and build hash, reported on attach. */
48
+ stack?: DaemonStackInfo;
29
49
  }
30
50
  /**
31
51
  * A WebSocket daemon hosting one engine for attached surfaces, with a session
@@ -38,6 +58,7 @@ export declare class CalypsoDaemon {
38
58
  private readonly host;
39
59
  private readonly scrollbackSize;
40
60
  private readonly promptProvider;
61
+ private readonly stack;
41
62
  /** The one session all surfaces share; returned in each attach ack. */
42
63
  private readonly sessionId;
43
64
  private readonly surfaces;
@@ -51,12 +72,10 @@ export declare class CalypsoDaemon {
51
72
  private queue;
52
73
  private currentOrigin;
53
74
  private currentId;
54
- private readonly pendingPrompts;
55
- private promptSeq;
56
- private readonly pendingPipes;
57
- private pipeSeq;
58
- private readonly pendingEdits;
59
- private editSeq;
75
+ private readonly prompts;
76
+ private readonly pipes;
77
+ private readonly shells;
78
+ private readonly edits;
60
79
  /**
61
80
  * @param options - The engine to host, the attach token, the bind address,
62
81
  * and the scrollback size.
@@ -81,6 +100,14 @@ export declare class CalypsoDaemon {
81
100
  * @param socket - The connected surface.
82
101
  */
83
102
  private connection_handle;
103
+ /**
104
+ * Relays a cancellation request only to the surface's own foreground command.
105
+ *
106
+ * @param origin - Surface asking to cancel a command.
107
+ * @param message - Correlated command identifier to cancel.
108
+ * @returns Nothing. The running command reports its normal final envelope.
109
+ */
110
+ private cancel_run;
84
111
  /**
85
112
  * Validates an attach handshake: contract version, then constant-time
86
113
  * token check. On success the surface is acknowledged, registered on the
@@ -132,8 +159,9 @@ export declare class CalypsoDaemon {
132
159
  * @param message - The prompt text to show.
133
160
  * @param hidden - Whether to request no-echo entry (a password).
134
161
  * @returns The surface's answer.
135
- * @throws {Error} When no command is executing (nothing to prompt for) or the
136
- * surface disconnects before answering.
162
+ * @throws {Error} When no command is executing, the surface cannot securely
163
+ * collect a requested hidden answer, or the surface disconnects before
164
+ * answering.
137
165
  */
138
166
  prompt_current(message: string, hidden: boolean): Promise<string>;
139
167
  /**
@@ -155,13 +183,6 @@ export declare class CalypsoDaemon {
155
183
  * @returns True when the chunk was sent to a surface.
156
184
  */
157
185
  output_current(channel: 'data' | 'err' | 'status', chunk: string): boolean;
158
- /**
159
- * Resolves a pending prompt with the surface's answer.
160
- *
161
- * @param promptId - The prompt correlation id.
162
- * @param answer - The answer the surface supplied.
163
- */
164
- private promptAnswer_settle;
165
186
  /**
166
187
  * Runs a pipeline segment on the surface running the current command,
167
188
  * returning its output. The host installs a `pipeSegment` on its engine-side
@@ -175,19 +196,14 @@ export declare class CalypsoDaemon {
175
196
  */
176
197
  pipe_current(command: string, input: Buffer): Promise<Buffer>;
177
198
  /**
178
- * Resolves a pending pipe segment with the surface's output.
179
- *
180
- * @param pipeId - The pipe correlation id.
181
- * @param output - The base64-encoded segment output.
182
- */
183
- private pipeResult_settle;
184
- /**
185
- * Rejects a pending pipeline segment with the surface's failure.
199
+ * Runs a host-shell command on the surface running the current command.
200
+ * The daemon never spawns the process itself.
186
201
  *
187
- * @param pipeId - The pipe correlation id.
188
- * @param reason - Human-readable command failure.
202
+ * @param command - The shell command without the leading `!`.
203
+ * @returns The surface process exit code.
204
+ * @throws {Error} When no command is executing or the surface disconnects.
189
205
  */
190
- private pipeError_settle;
206
+ shell_current(command: string): Promise<number>;
191
207
  /**
192
208
  * Opens content in the editor of the surface running the current command
193
209
  * and returns the edited result. The host installs a `localEdit` on its
@@ -200,13 +216,6 @@ export declare class CalypsoDaemon {
200
216
  * @throws {Error} When no command is executing or the surface disconnects.
201
217
  */
202
218
  edit_current(content: string, extension: string | undefined): Promise<EditOutcome>;
203
- /**
204
- * Resolves a pending edit with the surface's result.
205
- *
206
- * @param editId - The edit correlation id.
207
- * @param outcome - The edited content and changed flag.
208
- */
209
- private editResult_settle;
210
219
  /**
211
220
  * Runs one completion request and sends its reply, or an error. Completion
212
221
  * is a read and is not broadcast.