@thenewlabs/entangle-serve 2.6.2 → 2.7.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/daemon.d.ts +23 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +245 -0
- package/dist/daemon.js.map +1 -0
- package/dist/host-session.d.ts +99 -0
- package/dist/host-session.d.ts.map +1 -0
- package/dist/host-session.js +83 -0
- package/dist/host-session.js.map +1 -0
- package/dist/host-terminal.d.ts +7 -12
- package/dist/host-terminal.d.ts.map +1 -1
- package/dist/host-terminal.js +95 -103
- package/dist/host-terminal.js.map +1 -1
- package/dist/index.js +375 -112
- package/dist/index.js.map +1 -1
- package/dist/ipc.d.ts +103 -0
- package/dist/ipc.d.ts.map +1 -0
- package/dist/ipc.js +115 -0
- package/dist/ipc.js.map +1 -0
- package/dist/remote-host-session.d.ts +72 -0
- package/dist/remote-host-session.d.ts.map +1 -0
- package/dist/remote-host-session.js +170 -0
- package/dist/remote-host-session.js.map +1 -0
- package/dist/session-registry.d.ts +51 -0
- package/dist/session-registry.d.ts.map +1 -0
- package/dist/session-registry.js +167 -0
- package/dist/session-registry.js.map +1 -0
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,128 +1,385 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import * as net from 'net';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import { spawn } from 'child_process';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
2
6
|
import { Command } from 'commander';
|
|
3
7
|
import { getConfig, getVersionInfo, OutputHandler, parseOutputMode } from '@thenewlabs/entangle-utils';
|
|
4
8
|
import { startAgent } from './agent.js';
|
|
5
9
|
import { createCapability, resolveServeTarget } from './capability.js';
|
|
6
10
|
import { promptHidden } from './prompt.js';
|
|
7
11
|
import { SharedWorkspace } from './shared-workspace.js';
|
|
12
|
+
import { LocalHostSession } from './host-session.js';
|
|
8
13
|
import { attachHostTerminal } from './host-terminal.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
14
|
+
import { RemoteHostSession } from './remote-host-session.js';
|
|
15
|
+
import { cleanupStale, defaultSessionName, ensureRunDir, findSession, isAlive, listSessions, logPath, removeSession, socketPath, } from './session-registry.js';
|
|
16
|
+
// Hidden daemon entry: the interactive shared path spawns this same binary as
|
|
17
|
+
// `node <index.js> __daemon` (detached), which must run the headless daemon
|
|
18
|
+
// (see daemon.ts) rather than the CLI. Detected before the commander program is
|
|
19
|
+
// built/parsed so the daemon never touches argv parsing. Uses .then() rather
|
|
20
|
+
// than top-level await so the esbuild (cjs) standalone bundle still builds.
|
|
21
|
+
if (process.argv[2] === '__daemon') {
|
|
22
|
+
import('./daemon.js')
|
|
23
|
+
.then(({ runDaemon }) => runDaemon())
|
|
24
|
+
.catch((err) => {
|
|
25
|
+
console.error('Daemon failed to start:', err instanceof Error ? err.message : String(err));
|
|
26
|
+
process.exit(1);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
runCli();
|
|
31
|
+
}
|
|
32
|
+
/** How long to wait for a freshly spawned daemon's socket to become connectable. */
|
|
33
|
+
const SOCKET_POLL_INTERVAL_MS = 100;
|
|
34
|
+
const SOCKET_POLL_TIMEOUT_MS = 8000;
|
|
35
|
+
/** Resolve after `ms`. */
|
|
36
|
+
function delay(ms) {
|
|
37
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
38
|
+
}
|
|
39
|
+
/** Connect to a unix socket, rejecting on connection error. */
|
|
40
|
+
function connectSocket(path) {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const socket = net.connect(path);
|
|
43
|
+
const onError = (err) => reject(err);
|
|
44
|
+
socket.once('error', onError);
|
|
45
|
+
socket.once('connect', () => { socket.removeListener('error', onError); resolve(socket); });
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Poll a socket path until it accepts a connection, resolving the connected
|
|
50
|
+
* socket. Rejects with a pointer to `logFile` if it never comes up in time. The
|
|
51
|
+
* socket is left flowing-paused (no 'data' listener) so no daemon frames are
|
|
52
|
+
* lost before the RemoteHostSession attaches its reader.
|
|
53
|
+
*/
|
|
54
|
+
async function pollSocket(path, logFile) {
|
|
55
|
+
const deadline = Date.now() + SOCKET_POLL_TIMEOUT_MS;
|
|
56
|
+
for (;;) {
|
|
57
|
+
try {
|
|
58
|
+
return await connectSocket(path);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
if (Date.now() >= deadline) {
|
|
62
|
+
throw new Error(`Session daemon did not come up within ${SOCKET_POLL_TIMEOUT_MS / 1000}s (socket ${path}); see log: ${logFile}`);
|
|
63
|
+
}
|
|
64
|
+
await delay(SOCKET_POLL_INTERVAL_MS);
|
|
52
65
|
}
|
|
53
|
-
else {
|
|
54
|
-
password = process.env.AGENT_PASSWORD;
|
|
55
|
-
}
|
|
56
|
-
// Shared-terminal mode: on by default when attached to a real terminal,
|
|
57
|
-
// forced by --shared, disabled by --headless/--no-shared. Only meaningful
|
|
58
|
-
// in text mode (stream-json is for programmatic invokers).
|
|
59
|
-
const isTty = !!process.stdout.isTTY && !!process.stdin.isTTY;
|
|
60
|
-
const shared = options.headless === true ? false
|
|
61
|
-
: options.shared === true ? true
|
|
62
|
-
: isTty && outputMode === 'text';
|
|
63
|
-
let sharedWorkspace;
|
|
64
|
-
// The host UI (when attached) sizes the active window to the box interior
|
|
65
|
-
// and takes the session URL for its bottom bar once the relay assigns it.
|
|
66
|
-
let hostHandle;
|
|
67
|
-
if (shared) {
|
|
68
|
-
const cols = process.stdout.columns || 80;
|
|
69
|
-
const rows = process.stdout.rows || 24;
|
|
70
|
-
sharedWorkspace = new SharedWorkspace(output, { cols, rows });
|
|
71
|
-
if (isTty)
|
|
72
|
-
hostHandle = attachHostTerminal(sharedWorkspace, output);
|
|
73
|
-
}
|
|
74
|
-
await startAgent({
|
|
75
|
-
serverUrl,
|
|
76
|
-
outputMode: program.opts().outputMode,
|
|
77
|
-
...(password ? { password } : {}),
|
|
78
|
-
...(pinnedCapability && { pinnedCapability }),
|
|
79
|
-
...(sharedWorkspace && {
|
|
80
|
-
sharedWorkspace,
|
|
81
|
-
onCapabilityReady: ({ link }) => {
|
|
82
|
-
if (hostHandle)
|
|
83
|
-
hostHandle.setUrl(link);
|
|
84
|
-
else
|
|
85
|
-
output.info(`⧉ entangle session shared — open to collaborate:\n ${link}\n`);
|
|
86
|
-
},
|
|
87
|
-
}),
|
|
88
|
-
});
|
|
89
66
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Spawn the detached daemon for `sessionName` (this same binary re-invoked with
|
|
70
|
+
* the hidden `__daemon` arg) and poll its socket, resolving the connected socket
|
|
71
|
+
* the host UI attaches to. The daemon inherits its config via env vars.
|
|
72
|
+
*/
|
|
73
|
+
async function spawnDaemon(opts) {
|
|
74
|
+
const { sessionName, serverUrl, cap, password } = opts;
|
|
75
|
+
ensureRunDir();
|
|
76
|
+
const sock = socketPath(sessionName);
|
|
77
|
+
const logFile = logPath(sessionName);
|
|
78
|
+
const logFd = fs.openSync(logFile, 'a');
|
|
79
|
+
const entry = fileURLToPath(import.meta.url);
|
|
80
|
+
const child = spawn(process.execPath, [entry, '__daemon'], {
|
|
81
|
+
detached: true,
|
|
82
|
+
stdio: ['ignore', logFd, logFd],
|
|
83
|
+
env: {
|
|
84
|
+
...process.env,
|
|
85
|
+
ENTANGLE_DAEMON_SESSION: sessionName,
|
|
86
|
+
ENTANGLE_DAEMON_SOCKET: sock,
|
|
87
|
+
ENTANGLE_DAEMON_SERVER: serverUrl,
|
|
88
|
+
ENTANGLE_DAEMON_CAP: JSON.stringify(cap),
|
|
89
|
+
...(password ? { ENTANGLE_DAEMON_PASSWORD: password } : {}),
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
child.unref();
|
|
93
|
+
fs.closeSync(logFd); // the child holds its own fd
|
|
94
|
+
return pollSocket(sock, logFile);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Attach this terminal to a daemon over its (already connected) socket: wrap it
|
|
98
|
+
* in a RemoteHostSession sized to the current terminal and hand it to the host
|
|
99
|
+
* UI. host-terminal keeps the process alive and calls process.exit on the
|
|
100
|
+
* session's exit/detach path.
|
|
101
|
+
*/
|
|
102
|
+
function attachToSocket(socket, output) {
|
|
103
|
+
const session = new RemoteHostSession(socket, {
|
|
104
|
+
cols: process.stdout.columns || 80,
|
|
105
|
+
rows: process.stdout.rows || 24,
|
|
106
|
+
});
|
|
107
|
+
attachHostTerminal(session, output);
|
|
108
|
+
}
|
|
109
|
+
/** Reduce a session URL to a short, secret-free form (drops the `#S=` fragment). */
|
|
110
|
+
function shortUrl(url) {
|
|
111
|
+
if (!url)
|
|
112
|
+
return '';
|
|
113
|
+
try {
|
|
114
|
+
const u = new URL(url);
|
|
115
|
+
return `${u.origin}${u.pathname}`;
|
|
95
116
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
117
|
+
catch {
|
|
118
|
+
return url;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** SIGTERM a session, drop it from the registry, and unlink its socket. */
|
|
122
|
+
function killSession(info, output) {
|
|
102
123
|
try {
|
|
103
|
-
process.
|
|
104
|
-
const outputMode = parseOutputMode(program.opts().outputMode);
|
|
105
|
-
const output = new OutputHandler({ mode: outputMode });
|
|
106
|
-
const cap = await createCapability({
|
|
107
|
-
singleRun: options.singleRun,
|
|
108
|
-
outputMode: program.opts().outputMode,
|
|
109
|
-
});
|
|
110
|
-
output.info('\nCapability created:');
|
|
111
|
-
output.info(`capId: ${cap.capId}`);
|
|
112
|
-
output.info(`S: ${cap.S}`);
|
|
113
|
-
const config = getConfig();
|
|
114
|
-
const relayUrl = config.relayUrl || config.publicOrigin || 'https://suncoder.dev';
|
|
115
|
-
const link = `${relayUrl}/cap/${cap.capId}#S=${cap.S}`;
|
|
116
|
-
output.info(`\nWeb URL: ${link}`);
|
|
124
|
+
process.kill(info.pid, 'SIGTERM');
|
|
117
125
|
}
|
|
118
|
-
catch
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
process.exit(1);
|
|
126
|
+
catch { /* already gone */ }
|
|
127
|
+
removeSession(info.name);
|
|
128
|
+
try {
|
|
129
|
+
fs.unlinkSync(info.socket);
|
|
123
130
|
}
|
|
124
|
-
}
|
|
125
|
-
|
|
131
|
+
catch { /* already gone */ }
|
|
132
|
+
output.info(`Killed session "${info.name}" (pid ${info.pid}).`);
|
|
133
|
+
}
|
|
134
|
+
function runCli() {
|
|
135
|
+
const program = new Command();
|
|
136
|
+
program
|
|
137
|
+
.name('entangle-serve')
|
|
138
|
+
.description('Entangle secure agent for exposing CLI tools')
|
|
139
|
+
.version(getVersionInfo())
|
|
140
|
+
.option('--output-mode <mode>', 'Output mode: text or stream-json', 'text');
|
|
141
|
+
program
|
|
142
|
+
// Default command: `entangle serve [url]` runs the agent without needing an
|
|
143
|
+
// explicit `start`. The positional URL is either a bare relay origin
|
|
144
|
+
// (mint a fresh capability there) or a full capability URL (serve that exact
|
|
145
|
+
// capability); flags still work and take precedence over the positional.
|
|
146
|
+
.command('start', { isDefault: true })
|
|
147
|
+
.description('Start the agent (mint a fresh capability or serve a pinned one) and register with the relay')
|
|
148
|
+
.argument('[url]', 'Relay origin (https://relay) to mint a fresh capability on, or a full capability URL (https://relay/cap/<capId>#S=<secret>) to serve that exact capability')
|
|
149
|
+
.option('--server <url>', 'Relay server URL (overrides the origin of the positional URL)')
|
|
150
|
+
.option('--password [password]', 'Require a password to connect; pass the flag alone to be prompted, or set AGENT_PASSWORD')
|
|
151
|
+
.option('--capability <url>', 'Serve a specific capability URL (https://relay/cap/<capId>#S=<secret>) instead of minting a fresh ephemeral one; its host is also used as the relay server')
|
|
152
|
+
.option('--shared', 'Serve one shared terminal that everyone with the URL attaches to (default when run in a terminal)')
|
|
153
|
+
.option('--headless', 'Run headless: each connection gets its own shell instead of a shared terminal')
|
|
154
|
+
.option('--session <name>', 'Name of the detachable session to start or reattach to (defaults to one derived from the capability)')
|
|
155
|
+
.action(async (url, options) => {
|
|
156
|
+
try {
|
|
157
|
+
// Propagate output mode to all loggers in this process
|
|
158
|
+
process.env.OUTPUT_MODE = program.opts().outputMode;
|
|
159
|
+
const outputMode = parseOutputMode(program.opts().outputMode);
|
|
160
|
+
const output = new OutputHandler({ mode: outputMode });
|
|
161
|
+
output.version('Entangle Agent', getVersionInfo());
|
|
162
|
+
const config = getConfig();
|
|
163
|
+
const { serverUrl, pinnedCapability } = await resolveServeTarget({
|
|
164
|
+
positionalUrl: url,
|
|
165
|
+
capabilityFlag: options.capability,
|
|
166
|
+
serverFlag: options.server,
|
|
167
|
+
envCapability: process.env.ENTANGLE_CAPABILITY,
|
|
168
|
+
configRelayUrl: config.relayUrl,
|
|
169
|
+
});
|
|
170
|
+
// `--password` with no value (commander yields `true`) prompts interactively
|
|
171
|
+
// so the secret never appears in argv; a string value or AGENT_PASSWORD is
|
|
172
|
+
// used verbatim.
|
|
173
|
+
let password;
|
|
174
|
+
if (options.password === true) {
|
|
175
|
+
password = await promptHidden('Agent password: ');
|
|
176
|
+
}
|
|
177
|
+
else if (typeof options.password === 'string') {
|
|
178
|
+
password = options.password;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
password = process.env.AGENT_PASSWORD;
|
|
182
|
+
}
|
|
183
|
+
// Shared-terminal mode: on by default when attached to a real terminal,
|
|
184
|
+
// forced by --shared, disabled by --headless/--no-shared. Only meaningful
|
|
185
|
+
// in text mode (stream-json is for programmatic invokers).
|
|
186
|
+
const isTty = !!process.stdout.isTTY && !!process.stdin.isTTY;
|
|
187
|
+
const shared = options.headless === true ? false
|
|
188
|
+
: options.shared === true ? true
|
|
189
|
+
: isTty && outputMode === 'text';
|
|
190
|
+
// The interactive shared path (a real terminal serving one shared session
|
|
191
|
+
// in text mode) is daemonized tmux-style: a detached daemon owns the
|
|
192
|
+
// session + relay connection and this process is just a client that
|
|
193
|
+
// attaches to it, so closing the terminal (or Ctrl-B d) leaves the session
|
|
194
|
+
// running. Every other path keeps today's in-foreground behavior below.
|
|
195
|
+
if (shared && isTty && outputMode === 'text') {
|
|
196
|
+
// The daemon must pin a concrete capability, so mint the ephemeral one
|
|
197
|
+
// here (instead of letting startAgent mint it) when none was pinned.
|
|
198
|
+
const cap = pinnedCapability ?? await createCapability({ singleRun: false });
|
|
199
|
+
const sessionName = options.session || defaultSessionName(cap.capId);
|
|
200
|
+
cleanupStale();
|
|
201
|
+
const existing = findSession(sessionName);
|
|
202
|
+
let socket;
|
|
203
|
+
if (existing && isAlive(existing)) {
|
|
204
|
+
// Reattach to the live daemon. It may be serving a different
|
|
205
|
+
// capability than the one we just resolved (e.g. a reused --session
|
|
206
|
+
// name); attaching to the running one is the least surprising choice.
|
|
207
|
+
if (existing.capId !== cap.capId) {
|
|
208
|
+
output.info(`A session named "${sessionName}" is already running with a different capability; attaching to it.`);
|
|
209
|
+
}
|
|
210
|
+
socket = await connectSocket(existing.socket);
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
socket = await spawnDaemon({ sessionName, serverUrl, cap, ...(password ? { password } : {}) });
|
|
214
|
+
}
|
|
215
|
+
attachToSocket(socket, output);
|
|
216
|
+
return; // host-terminal drives the process lifetime from here
|
|
217
|
+
}
|
|
218
|
+
let sharedWorkspace;
|
|
219
|
+
// The host UI (when attached) renders against a HostSession — an
|
|
220
|
+
// abstraction over the workspace + log/URL sources — so the same UI can
|
|
221
|
+
// later run against a socket-backed session. It sizes the active window to
|
|
222
|
+
// the box interior and takes the session URL for its bottom bar once the
|
|
223
|
+
// relay assigns it.
|
|
224
|
+
let hostSession;
|
|
225
|
+
if (shared) {
|
|
226
|
+
const cols = process.stdout.columns || 80;
|
|
227
|
+
const rows = process.stdout.rows || 24;
|
|
228
|
+
sharedWorkspace = new SharedWorkspace(output, { cols, rows });
|
|
229
|
+
if (isTty) {
|
|
230
|
+
hostSession = new LocalHostSession(sharedWorkspace, output);
|
|
231
|
+
attachHostTerminal(hostSession, output);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
await startAgent({
|
|
235
|
+
serverUrl,
|
|
236
|
+
outputMode: program.opts().outputMode,
|
|
237
|
+
...(password ? { password } : {}),
|
|
238
|
+
...(pinnedCapability && { pinnedCapability }),
|
|
239
|
+
...(sharedWorkspace && {
|
|
240
|
+
sharedWorkspace,
|
|
241
|
+
onCapabilityReady: ({ link }) => {
|
|
242
|
+
if (hostSession)
|
|
243
|
+
hostSession.setUrl(link);
|
|
244
|
+
else
|
|
245
|
+
output.info(`⧉ entangle session shared — open to collaborate:\n ${link}\n`);
|
|
246
|
+
},
|
|
247
|
+
}),
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
const outputMode = parseOutputMode(program.opts().outputMode);
|
|
252
|
+
const output = new OutputHandler({ mode: outputMode });
|
|
253
|
+
output.error('Failed to start agent', error instanceof Error ? error.message : String(error));
|
|
254
|
+
process.exit(1);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
program
|
|
258
|
+
.command('create-cap')
|
|
259
|
+
.description('Create a new capability')
|
|
260
|
+
.option('--single-run', 'Allow only one run per session (default: multiple runs allowed)')
|
|
261
|
+
.action(async (options) => {
|
|
262
|
+
try {
|
|
263
|
+
process.env.OUTPUT_MODE = program.opts().outputMode;
|
|
264
|
+
const outputMode = parseOutputMode(program.opts().outputMode);
|
|
265
|
+
const output = new OutputHandler({ mode: outputMode });
|
|
266
|
+
const cap = await createCapability({
|
|
267
|
+
singleRun: options.singleRun,
|
|
268
|
+
outputMode: program.opts().outputMode,
|
|
269
|
+
});
|
|
270
|
+
output.info('\nCapability created:');
|
|
271
|
+
output.info(`capId: ${cap.capId}`);
|
|
272
|
+
output.info(`S: ${cap.S}`);
|
|
273
|
+
const config = getConfig();
|
|
274
|
+
const relayUrl = config.relayUrl || config.publicOrigin || 'https://suncoder.dev';
|
|
275
|
+
const link = `${relayUrl}/cap/${cap.capId}#S=${cap.S}`;
|
|
276
|
+
output.info(`\nWeb URL: ${link}`);
|
|
277
|
+
}
|
|
278
|
+
catch (error) {
|
|
279
|
+
const outputMode = parseOutputMode(program.opts().outputMode);
|
|
280
|
+
const output = new OutputHandler({ mode: outputMode });
|
|
281
|
+
output.error('Failed to create capability', error instanceof Error ? error.message : String(error));
|
|
282
|
+
process.exit(1);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
program
|
|
286
|
+
.command('ls')
|
|
287
|
+
.alias('list')
|
|
288
|
+
.description('List running serve sessions')
|
|
289
|
+
.action(() => {
|
|
290
|
+
const output = new OutputHandler({ mode: parseOutputMode(program.opts().outputMode) });
|
|
291
|
+
cleanupStale();
|
|
292
|
+
const sessions = listSessions();
|
|
293
|
+
if (sessions.length === 0) {
|
|
294
|
+
output.info('No sessions.');
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
for (const s of sessions) {
|
|
298
|
+
const alive = isAlive(s) ? `alive(${s.pid})` : 'dead';
|
|
299
|
+
const created = new Date(s.createdAt).toISOString();
|
|
300
|
+
const where = shortUrl(s.url) || s.capId;
|
|
301
|
+
output.text(`${s.name}\t${alive}\t${created}\t${where}`);
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
program
|
|
305
|
+
.command('kill [name]')
|
|
306
|
+
.description('Kill a running session by name (SIGTERM); with no name, the only session')
|
|
307
|
+
.option('--all', 'Kill every running session')
|
|
308
|
+
.action((name, options) => {
|
|
309
|
+
const output = new OutputHandler({ mode: parseOutputMode(program.opts().outputMode) });
|
|
310
|
+
cleanupStale();
|
|
311
|
+
const sessions = listSessions();
|
|
312
|
+
if (options.all) {
|
|
313
|
+
if (sessions.length === 0) {
|
|
314
|
+
output.info('No sessions.');
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
for (const s of sessions)
|
|
318
|
+
killSession(s, output);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
let target;
|
|
322
|
+
if (name) {
|
|
323
|
+
target = findSession(name);
|
|
324
|
+
if (!target) {
|
|
325
|
+
output.error(`No session named "${name}".`);
|
|
326
|
+
process.exit(1);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
else if (sessions.length === 0) {
|
|
330
|
+
output.info('No sessions.');
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
else if (sessions.length === 1) {
|
|
334
|
+
target = sessions[0];
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
output.error('Multiple sessions; specify one to kill (or --all):');
|
|
338
|
+
for (const s of sessions)
|
|
339
|
+
output.text(` ${s.name}`);
|
|
340
|
+
process.exit(1);
|
|
341
|
+
}
|
|
342
|
+
if (target)
|
|
343
|
+
killSession(target, output);
|
|
344
|
+
});
|
|
345
|
+
program
|
|
346
|
+
.command('attach [name]')
|
|
347
|
+
.description('Attach to a running session by name (or the only one) without a URL')
|
|
348
|
+
.action(async (name) => {
|
|
349
|
+
const output = new OutputHandler({ mode: parseOutputMode(program.opts().outputMode) });
|
|
350
|
+
cleanupStale();
|
|
351
|
+
const sessions = listSessions();
|
|
352
|
+
let target;
|
|
353
|
+
if (name) {
|
|
354
|
+
target = findSession(name);
|
|
355
|
+
}
|
|
356
|
+
else if (sessions.length === 0) {
|
|
357
|
+
output.error('No sessions to attach to.');
|
|
358
|
+
process.exit(1);
|
|
359
|
+
}
|
|
360
|
+
else if (sessions.length === 1) {
|
|
361
|
+
target = sessions[0];
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
output.error('Multiple sessions; specify one to attach to:');
|
|
365
|
+
for (const s of sessions)
|
|
366
|
+
output.text(` ${s.name}`);
|
|
367
|
+
process.exit(1);
|
|
368
|
+
}
|
|
369
|
+
if (!target || !isAlive(target)) {
|
|
370
|
+
output.error(`No live session named "${name ?? ''}".`);
|
|
371
|
+
process.exit(1);
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
const socket = await connectSocket(target.socket);
|
|
375
|
+
attachToSocket(socket, output);
|
|
376
|
+
}
|
|
377
|
+
catch (error) {
|
|
378
|
+
output.error('Failed to attach', error instanceof Error ? error.message : String(error));
|
|
379
|
+
process.exit(1);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
program.addHelpText('after', `
|
|
126
383
|
Examples:
|
|
127
384
|
# Mint a fresh capability and serve it on a relay
|
|
128
385
|
entangle serve https://entangle.thenewlabs.com
|
|
@@ -133,7 +390,13 @@ Examples:
|
|
|
133
390
|
# Mint on the configured/default relay
|
|
134
391
|
entangle serve
|
|
135
392
|
|
|
393
|
+
# List / attach / kill detachable sessions
|
|
394
|
+
entangle serve ls
|
|
395
|
+
entangle serve attach <name>
|
|
396
|
+
entangle serve kill <name>
|
|
397
|
+
|
|
136
398
|
# Just create a capability without starting the agent
|
|
137
399
|
entangle serve create-cap`);
|
|
138
|
-
program.parse();
|
|
400
|
+
program.parse();
|
|
401
|
+
}
|
|
139
402
|
//# sourceMappingURL=index.js.map
|
package/d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CAAC,CAAC;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACzF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE;;;;;;;;;;;;;;;;;4BAiBD,CAAC,CAAC;IAE9B,OAAO,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC"}
|
package/dist/ipc.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { Duplex } from 'stream';
|
|
2
|
+
import type { WindowStateBody } from '@thenewlabs/entangle-protocol';
|
|
3
|
+
/** Bytes of the length prefix that precedes every JSON payload. */
|
|
4
|
+
export declare const HEADER_BYTES = 4;
|
|
5
|
+
/**
|
|
6
|
+
* Maximum accepted payload size. A frame declaring a larger payload is rejected
|
|
7
|
+
* (the decoder errors) rather than buffering an unbounded amount of memory for
|
|
8
|
+
* a payload that may never fully arrive. 8 MB comfortably fits a full-screen
|
|
9
|
+
* replay while capping a hostile/framed-wrong peer.
|
|
10
|
+
*/
|
|
11
|
+
export declare const MAX_FRAME_BYTES: number;
|
|
12
|
+
/** A window operation requested by the client (tmux-style window control). */
|
|
13
|
+
export type WindowOp = 'new' | 'next' | 'prev' | 'select' | 'close';
|
|
14
|
+
/** Messages sent from an attached terminal client to the daemon. */
|
|
15
|
+
export type ClientToDaemon = {
|
|
16
|
+
t: 'hello';
|
|
17
|
+
cols: number;
|
|
18
|
+
rows: number;
|
|
19
|
+
}
|
|
20
|
+
/** Keystrokes / raw terminal input, base64-encoded. */
|
|
21
|
+
| {
|
|
22
|
+
t: 'input';
|
|
23
|
+
data: string;
|
|
24
|
+
} | {
|
|
25
|
+
t: 'resize';
|
|
26
|
+
cols: number;
|
|
27
|
+
rows: number;
|
|
28
|
+
} | {
|
|
29
|
+
t: 'win';
|
|
30
|
+
op: WindowOp;
|
|
31
|
+
index?: number;
|
|
32
|
+
} | {
|
|
33
|
+
t: 'detach';
|
|
34
|
+
};
|
|
35
|
+
/** Messages sent from the daemon to an attached terminal client. */
|
|
36
|
+
export type DaemonToClient =
|
|
37
|
+
/** Live terminal output, base64-encoded. */
|
|
38
|
+
{
|
|
39
|
+
t: 'data';
|
|
40
|
+
chunk: string;
|
|
41
|
+
}
|
|
42
|
+
/** Scrollback replay sent right after attach, base64-encoded. */
|
|
43
|
+
| {
|
|
44
|
+
t: 'replay';
|
|
45
|
+
chunk: string;
|
|
46
|
+
} | {
|
|
47
|
+
t: 'window-state';
|
|
48
|
+
state: WindowStateBody;
|
|
49
|
+
}
|
|
50
|
+
/** Number of currently attached viewers. */
|
|
51
|
+
| {
|
|
52
|
+
t: 'viewers';
|
|
53
|
+
n: number;
|
|
54
|
+
} | {
|
|
55
|
+
t: 'log';
|
|
56
|
+
line: string;
|
|
57
|
+
} | {
|
|
58
|
+
t: 'url';
|
|
59
|
+
url: string;
|
|
60
|
+
} | {
|
|
61
|
+
t: 'exit';
|
|
62
|
+
code: number | null;
|
|
63
|
+
};
|
|
64
|
+
/** Any framed IPC message, in either direction. */
|
|
65
|
+
export type IpcMessage = ClientToDaemon | DaemonToClient;
|
|
66
|
+
/** Encode a binary terminal chunk as a base64 string for the JSON wire. */
|
|
67
|
+
export declare function encodeChunk(data: Uint8Array): string;
|
|
68
|
+
/** Decode a base64 chunk string back into a Buffer of terminal bytes. */
|
|
69
|
+
export declare function decodeChunk(chunk: string): Buffer;
|
|
70
|
+
/**
|
|
71
|
+
* Serialize a message to a length-prefixed frame: a 4-byte big-endian payload
|
|
72
|
+
* length followed by the UTF-8 JSON payload.
|
|
73
|
+
*
|
|
74
|
+
* @throws if the resulting payload exceeds {@link MAX_FRAME_BYTES}.
|
|
75
|
+
*/
|
|
76
|
+
export declare function encodeMessage(msg: IpcMessage): Buffer;
|
|
77
|
+
/** Encode and write a single message to a socket/stream. */
|
|
78
|
+
export declare function writeMessage(socket: Duplex, msg: IpcMessage): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Incrementally decodes length-prefixed frames from a byte stream, tolerating
|
|
81
|
+
* partial reads (a frame split across chunks) and coalesced reads (many frames
|
|
82
|
+
* in one chunk). A frame whose declared length exceeds {@link MAX_FRAME_BYTES}
|
|
83
|
+
* makes {@link push} throw rather than buffering unbounded memory — callers
|
|
84
|
+
* should treat that as a fatal protocol error and close the socket.
|
|
85
|
+
*/
|
|
86
|
+
export declare class FrameDecoder {
|
|
87
|
+
private buffer;
|
|
88
|
+
/**
|
|
89
|
+
* Feed received bytes; returns every message that became fully available.
|
|
90
|
+
* @throws if a frame declares a payload larger than {@link MAX_FRAME_BYTES}
|
|
91
|
+
* or if a completed payload is not valid JSON.
|
|
92
|
+
*/
|
|
93
|
+
push(chunk: Uint8Array): IpcMessage[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Attach a {@link FrameDecoder} to a socket and invoke `onMessage` for each
|
|
97
|
+
* decoded message. A decode error (oversize frame or malformed JSON) is routed
|
|
98
|
+
* to `onError` if provided, otherwise emitted on the socket as an `'error'`.
|
|
99
|
+
*
|
|
100
|
+
* @returns a detach function that removes the installed `'data'` listener.
|
|
101
|
+
*/
|
|
102
|
+
export declare function createMessageReader(socket: Duplex, onMessage: (msg: IpcMessage) => void, onError?: (err: Error) => void): () => void;
|
|
103
|
+
//# sourceMappingURL=ipc.d.ts.map
|