@platless/axom-cli 0.3.13 → 0.5.9
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/axom-patch/cli/README.md +30 -8
- package/dist/axom-patch/cli/account-limits/README.md +27 -0
- package/dist/axom-patch/cli/account-limits/antigravity-proxy.mjs +47 -0
- package/dist/axom-patch/cli/account-limits/antigravity-read.mjs +90 -0
- package/dist/axom-patch/cli/account-limits/antigravity.mjs +46 -0
- package/dist/axom-patch/cli/account-limits/generate.py +120 -0
- package/dist/axom-patch/cli/account-limits/kimi-proxy.mjs +64 -0
- package/dist/axom-patch/cli/account-limits/normalize.mjs +151 -0
- package/dist/axom-patch/cli/claude-account-limits.json +37 -0
- package/dist/axom-patch/cli/codex-account-limits.json +37 -0
- package/dist/axom-patch/cli/commandcode-account-limits.json +30 -0
- package/dist/axom-patch/cli/nightly-task.md +152 -0
- package/dist/axom-patch/cli/pi-subagent-subwork.json +23 -0
- package/dist/axom-patch/cli/probes/claude-late-async-terminal.mjs +5 -1
- package/dist/axom-patch/cli/probes/pi-subagent-subwork.mjs +211 -0
- package/dist/axom-patch/cli/probes/qoder-steering.mjs +1 -1
- package/dist/axom-patch/cli/probes/qoder-subagent-origin.mjs +20 -8
- package/dist/axom-patch/cli/probes/zcode-subagent-subwork.mjs +257 -0
- package/dist/axom-patch/cli/qoder-background-terminal.md +2 -1
- package/dist/axom-patch/cli/qoder-foreground-output.md +4 -3
- package/dist/axom-patch/cli/qoder-steering.json +15 -15
- package/dist/axom-patch/cli/qoder-subagent-origin.json +21 -21
- package/dist/axom-patch/cli/runtime.json +34 -8
- package/dist/axom-patch/cli/zcode-account-limits.json +31 -0
- package/dist/axom-patch/cli/zcode-models.json +38 -0
- package/dist/axom-patch/cli/zcode-subagent-subwork.json +73 -0
- package/dist/cli.js +33 -6
- package/dist/keepers/acp/keeper.mjs +3083 -0
- package/dist/keepers/acp/manifest.json +9 -0
- package/dist/keepers/terminal/keeper.mjs +8469 -0
- package/dist/keepers/terminal/manifest.json +9 -0
- package/dist/keepers/terminal/node_modules/node-pty/lib/conpty_console_list_agent.js +25 -0
- package/dist/keepers/terminal/node_modules/node-pty/lib/eventEmitter2.js +47 -0
- package/dist/keepers/terminal/node_modules/node-pty/lib/index.js +52 -0
- package/dist/keepers/terminal/node_modules/node-pty/lib/interfaces.js +7 -0
- package/dist/keepers/terminal/node_modules/node-pty/lib/shared/conout.js +10 -0
- package/dist/keepers/terminal/node_modules/node-pty/lib/terminal.js +190 -0
- package/dist/keepers/terminal/node_modules/node-pty/lib/types.js +7 -0
- package/dist/keepers/terminal/node_modules/node-pty/lib/unixTerminal.js +351 -0
- package/dist/keepers/terminal/node_modules/node-pty/lib/utils.js +38 -0
- package/dist/keepers/terminal/node_modules/node-pty/lib/windowsConoutConnection.js +131 -0
- package/dist/keepers/terminal/node_modules/node-pty/lib/windowsPtyAgent.js +344 -0
- package/dist/keepers/terminal/node_modules/node-pty/lib/windowsTerminal.js +209 -0
- package/dist/keepers/terminal/node_modules/node-pty/lib/worker/conoutSocketWorker.js +22 -0
- package/dist/keepers/terminal/node_modules/node-pty/package.json +66 -0
- package/dist/keepers/terminal/node_modules/node-pty/prebuilds/darwin-arm64/pty.node +0 -0
- package/dist/keepers/terminal/node_modules/node-pty/prebuilds/darwin-arm64/spawn-helper +0 -0
- package/dist/keepers/terminal/node_modules/node-pty/prebuilds/darwin-x64/pty.node +0 -0
- package/dist/keepers/terminal/node_modules/node-pty/prebuilds/darwin-x64/spawn-helper +0 -0
- package/dist/keepers/terminal/node_modules/node-pty/prebuilds/linux-arm64/pty.node +0 -0
- package/dist/keepers/terminal/node_modules/node-pty/prebuilds/linux-x64/pty.node +0 -0
- package/dist/runtime-deps/qoder-sdk/package-lock.json +1189 -0
- package/dist/runtime-deps/qoder-sdk/package.json +8 -0
- package/dist/test/keeperKit.js +67 -0
- package/dist/workstation/acp/acpAgents.js +2163 -611
- package/dist/workstation/acp/acpClient.js +60 -497
- package/dist/workstation/acp/adoption.js +10 -396
- package/dist/workstation/acp/binaryInstall.js +100 -27
- package/dist/workstation/acp/builds/gc.js +245 -0
- package/dist/workstation/acp/builds/install/binary.js +28 -0
- package/dist/workstation/acp/builds/install/npm.js +235 -0
- package/dist/workstation/acp/builds/install/uv.js +254 -0
- package/dist/workstation/acp/builds/migrate.js +195 -0
- package/dist/workstation/acp/builds/model.js +128 -0
- package/dist/workstation/acp/builds/nodeGate.js +100 -0
- package/dist/workstation/acp/builds/store.js +352 -0
- package/dist/workstation/acp/commandTableProbe.js +68 -0
- package/dist/workstation/acp/configOptions.js +103 -1
- package/dist/workstation/acp/envSecrets.js +27 -0
- package/dist/workstation/acp/initializeResponse.js +285 -0
- package/dist/workstation/acp/installErrors.js +12 -2
- package/dist/workstation/acp/installProbe.js +1 -1
- package/dist/workstation/acp/managedPatches.js +76 -160
- package/dist/workstation/acp/outbox.js +330 -0
- package/dist/workstation/acp/patchAssets.js +20 -3
- package/dist/workstation/acp/permission.js +42 -10
- package/dist/workstation/acp/processor/checkpoint.js +87 -0
- package/dist/workstation/acp/processor/commands.js +35 -0
- package/dist/workstation/acp/processor/control.js +355 -0
- package/dist/workstation/acp/processor/emit.js +26 -0
- package/dist/workstation/acp/processor/jsonrpc.js +172 -0
- package/dist/workstation/acp/processor/memoryLog.js +49 -0
- package/dist/workstation/acp/processor/origins.js +48 -0
- package/dist/workstation/acp/processor/output.js +67 -0
- package/dist/workstation/acp/processor/projection.js +42 -0
- package/dist/workstation/acp/processor/record.js +128 -0
- package/dist/workstation/acp/processor/runtime.js +181 -0
- package/dist/workstation/acp/processor/sdkSchemas.js +61 -0
- package/dist/workstation/acp/processor/session.js +525 -0
- package/dist/workstation/acp/processor/sideChannel.js +80 -0
- package/dist/workstation/acp/processor/state.js +74 -0
- package/dist/workstation/acp/processor/step.js +459 -0
- package/dist/workstation/acp/processor/test/fixtureLog.js +65 -0
- package/dist/workstation/acp/processor/test/harness.js +120 -0
- package/dist/workstation/acp/processor/test/largeIdEcho.js +50 -0
- package/dist/workstation/acp/processor/test/rawAgent.js +70 -0
- package/dist/workstation/acp/processor/transport/generations.js +76 -0
- package/dist/workstation/acp/processor/transport/keeper.js +130 -0
- package/dist/workstation/acp/processor/transport/local.js +269 -0
- package/dist/workstation/acp/processor/transport/types.js +78 -0
- package/dist/workstation/acp/processor/updates.js +364 -0
- package/dist/workstation/acp/processorSession.js +1512 -0
- package/dist/workstation/acp/qoderStartup.js +1 -1
- package/dist/workstation/acp/registry/catalog.js +154 -32
- package/dist/workstation/acp/registry/launch.js +61 -119
- package/dist/workstation/acp/sessionUpdateMapper.js +18 -7
- package/dist/workstation/acp/steering.js +58 -0
- package/dist/workstation/acp/switching.js +114 -0
- package/dist/workstation/acp/terminalLogin.js +16 -42
- package/dist/workstation/acp/terminalLoginSpec.js +41 -0
- package/dist/workstation/acp/test/adapterFixtures.js +256 -0
- package/dist/workstation/acp/test/daemonLife.js +106 -0
- package/dist/workstation/acp/test/keeperWorld.js +267 -0
- package/dist/workstation/acp/test/memoryOutbox.js +55 -0
- package/dist/workstation/acp/test/raw/fixtures.js +196 -0
- package/dist/workstation/acp/test/raw/qoderCaptures.js +125 -0
- package/dist/workstation/acp/test/raw/sanitize.js +344 -0
- package/dist/workstation/acp/test/raw/sources.js +249 -0
- package/dist/workstation/acp/test/realAdapter.js +377 -0
- package/dist/workstation/acp/test/scriptAgent.js +206 -0
- package/dist/workstation/acp/test/sessionFrames.js +42 -0
- package/dist/workstation/acp/timedCommand.js +4 -2
- package/dist/workstation/acp/uvxInstall.js +72 -122
- package/dist/workstation/agentFlow.js +103 -0
- package/dist/workstation/agentSessions.js +1324 -474
- package/dist/workstation/channels/agent.js +7 -5
- package/dist/workstation/channels/computer.js +69 -21
- package/dist/workstation/channels/computerExecs.js +200 -0
- package/dist/workstation/channels/management.js +84 -4
- package/dist/workstation/daemon.js +288 -7
- package/dist/workstation/daemonctl.js +28 -2
- package/dist/workstation/exec/attach.js +126 -0
- package/dist/workstation/exec/command.js +40 -0
- package/dist/workstation/exec/durable.js +517 -0
- package/dist/workstation/exec/fallback.js +106 -0
- package/dist/workstation/exec/policy.js +837 -0
- package/dist/workstation/exec/shaping.js +211 -0
- package/dist/workstation/exec.js +3 -112
- package/dist/workstation/files/adapters/computerFileFrames.js +51 -0
- package/dist/workstation/files/adapters/toolRequests.js +121 -0
- package/dist/workstation/files/client.js +455 -0
- package/dist/workstation/files/errors.js +28 -0
- package/dist/workstation/files/fence.js +350 -0
- package/dist/workstation/files/find/fileIndex.js +153 -0
- package/dist/workstation/files/find/fuzzy.js +155 -0
- package/dist/workstation/files/host.js +122 -0
- package/dist/workstation/files/hostProtocol.js +2 -0
- package/dist/workstation/files/media/cache.js +620 -0
- package/dist/workstation/files/media/encoding.js +308 -0
- package/dist/workstation/files/media/estimator.js +100 -0
- package/dist/workstation/files/media/media.js +325 -0
- package/dist/workstation/files/media/packedAudio.js +23 -0
- package/dist/workstation/files/media/scheduler.js +551 -0
- package/dist/workstation/files/media/types.js +5 -0
- package/dist/workstation/files/scope.js +45 -0
- package/dist/workstation/files/structured.js +284 -0
- package/dist/workstation/{fileOps.js → files/text.js} +117 -38
- package/dist/workstation/files/uploads.js +351 -0
- package/dist/workstation/journal.js +65 -236
- package/dist/workstation/keepers/acp/client.js +101 -0
- package/dist/workstation/keepers/acp/envelope.js +62 -0
- package/dist/workstation/keepers/acp/host.js +419 -0
- package/dist/workstation/keepers/acp/main.js +18 -0
- package/dist/workstation/keepers/acp/memoryStream.js +121 -0
- package/dist/workstation/keepers/acp/params.js +137 -0
- package/dist/workstation/keepers/acp/protocol.js +66 -0
- package/dist/workstation/keepers/acp/recover.js +120 -0
- package/dist/workstation/keepers/acp/session.js +584 -0
- package/dist/workstation/keepers/acp/stderr.js +154 -0
- package/dist/workstation/keepers/kit/activity.js +103 -0
- package/dist/workstation/keepers/kit/bootstrap.js +164 -0
- package/dist/workstation/keepers/kit/buildVersion.js +51 -0
- package/dist/workstation/keepers/kit/bundle.js +120 -0
- package/dist/workstation/keepers/kit/client.js +432 -0
- package/dist/workstation/keepers/kit/identity.js +21 -0
- package/dist/workstation/keepers/kit/ipc.js +112 -0
- package/dist/workstation/keepers/kit/launchConfig.js +8 -0
- package/dist/workstation/keepers/kit/launcher.js +249 -0
- package/dist/workstation/keepers/kit/lock.js +123 -0
- package/dist/workstation/keepers/kit/orphanSweep.js +86 -0
- package/dist/workstation/keepers/kit/paths.js +75 -0
- package/dist/workstation/keepers/kit/protocol.js +43 -0
- package/dist/workstation/keepers/kit/server.js +518 -0
- package/dist/workstation/keepers/kit/streamLog.js +697 -0
- package/dist/workstation/keepers/legacy.js +296 -0
- package/dist/workstation/keepers/policy.js +576 -0
- package/dist/workstation/keepers/stop.js +34 -0
- package/dist/workstation/keepers/terminal/client.js +213 -0
- package/dist/workstation/keepers/terminal/exec.js +981 -0
- package/dist/workstation/keepers/terminal/generations.js +129 -0
- package/dist/workstation/keepers/terminal/keeper.js +62 -0
- package/dist/workstation/keepers/terminal/main.js +43 -0
- package/dist/workstation/keepers/terminal/orphanSweep.js +3 -0
- package/dist/workstation/keepers/terminal/params.js +27 -0
- package/dist/workstation/keepers/terminal/protocol.js +56 -0
- package/dist/workstation/keepers/terminal/pty.js +330 -0
- package/dist/workstation/protocol/accountLimits.js +47 -0
- package/dist/workstation/protocol/agent.js +48 -4
- package/dist/workstation/protocol/common.js +30 -0
- package/dist/workstation/protocol/computer.js +15 -4
- package/dist/workstation/protocol/management.js +50 -2
- package/dist/workstation/qoderAdapter/backgroundProcess.js +18 -6
- package/dist/workstation/qoderAdapter/backgroundTerminal.js +78 -147
- package/dist/workstation/qoderAdapter/backgroundTerminalFold.js +372 -0
- package/dist/workstation/qoderAdapter/callbackContext.js +76 -0
- package/dist/workstation/qoderAdapter/foregroundOutput.js +15 -9
- package/dist/workstation/qoderAdapter/history.js +1 -3
- package/dist/workstation/qoderAdapter/main.js +4 -2
- package/dist/workstation/qoderAdapter/sdkDriver.js +1 -2
- package/dist/workstation/qoderAdapter/sdkRuntime.js +93 -0
- package/dist/workstation/qoderAdapter/sdkRuntimeInstall.js +145 -0
- package/dist/workstation/qoderAdapter/session.js +1 -1
- package/dist/workstation/qoderAdapter/subwork.js +15 -7
- package/dist/workstation/systemMetrics.js +110 -1
- package/dist/workstation/tools/client.js +9 -1
- package/dist/workstation/tools/info.js +50 -0
- package/dist/workstation/tools/keeperProcess.js +15 -5
- package/dist/workstation/tools/router.js +55 -0
- package/dist/workstation/tools/terminalRouter.js +222 -0
- package/dist/workstation/tools/validation.js +37 -1
- package/dist/workstation/update/coordinator.js +3 -0
- package/dist/workstation/update/ptyPreflight.js +21 -0
- package/dist/workstation/update/taskRegistry.js +105 -11
- package/package.json +10 -7
- package/dist/workstation/acp/acpSession.js +0 -1475
- package/dist/workstation/acp/contract.js +0 -499
- package/dist/workstation/acp/draftInterceptor.js +0 -163
- package/dist/workstation/acp/sessionScope.js +0 -19
- package/dist/workstation/filePaths.js +0 -174
- package/dist/workstation/fileWorker.js +0 -81
- package/dist/workstation/fileWorkerClient.js +0 -121
- package/dist/workstation/qoderAdapter/taskEvent.js +0 -26
- package/dist/workstation/tools/core.js +0 -50
- package/dist/workstation/tools/files.js +0 -525
- package/dist/workstation/tools/terminal.js +0 -214
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import os from 'node:os';
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
|
-
import { identifier, integer, keys, TOOL_RESULT_BYTES } from './validation.js';
|
|
4
|
-
const require = createRequire(import.meta.url);
|
|
5
|
-
const { Terminal } = require('@xterm/headless');
|
|
6
|
-
const { SerializeAddon } = require('@xterm/addon-serialize');
|
|
7
|
-
const HISTORY_BYTES = 1024 * 1024;
|
|
8
|
-
const MAX_POLL_BYTES = 64 * 1024;
|
|
9
|
-
const SCROLLBACK = 1000;
|
|
10
|
-
export class PersistentTerminals {
|
|
11
|
-
files;
|
|
12
|
-
options;
|
|
13
|
-
sessions = new Map();
|
|
14
|
-
ptyModule;
|
|
15
|
-
error;
|
|
16
|
-
constructor(files, options) {
|
|
17
|
-
this.files = files;
|
|
18
|
-
this.options = options;
|
|
19
|
-
try {
|
|
20
|
-
this.ptyModule = (options.loadPty ?? (() => require('node-pty')))();
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
this.error = 'Terminal native dependency unavailable; reinstall CLI with optional node-pty support';
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
get available() { return !!this.ptyModule; }
|
|
27
|
-
descriptor(s) {
|
|
28
|
-
return { id: s.id, name: s.name, cwd: s.cwd, cols: s.cols, rows: s.rows, exited: s.exited, exitCode: s.exitCode, controllerId: s.controllerId };
|
|
29
|
-
}
|
|
30
|
-
control(s, clientId) {
|
|
31
|
-
if (s.controllerId !== clientId)
|
|
32
|
-
throw new Error('Terminal is controlled by another client; take control explicitly');
|
|
33
|
-
}
|
|
34
|
-
resize(s, p) {
|
|
35
|
-
const cols = integer(p, 'cols', 20, 300, s.cols);
|
|
36
|
-
const rows = integer(p, 'rows', 5, 100, s.rows);
|
|
37
|
-
if (cols !== s.cols || rows !== s.rows) {
|
|
38
|
-
if (!s.exited)
|
|
39
|
-
s.pty.resize(cols, rows);
|
|
40
|
-
s.terminal.resize(cols, rows);
|
|
41
|
-
s.cols = cols;
|
|
42
|
-
s.rows = rows;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
snapshot(s) {
|
|
46
|
-
// Scroll position belongs to the viewer, never the keeper. Serialization includes normal and
|
|
47
|
-
// alternate buffers, SGR attributes, cursor and modes; it starts from a clean emulator.
|
|
48
|
-
for (let scrollback = SCROLLBACK;; scrollback = Math.floor(scrollback / 2)) {
|
|
49
|
-
const snapshot = '\x1bc' + s.serializer.serialize({ scrollback });
|
|
50
|
-
if (Buffer.byteLength(JSON.stringify({ snapshot })) < TOOL_RESULT_BYTES - 8192)
|
|
51
|
-
return snapshot;
|
|
52
|
-
if (!scrollback)
|
|
53
|
-
throw new Error('Terminal screen exceeds snapshot limit; resize to a smaller viewport');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
output(s, data) {
|
|
57
|
-
if (!data || s.closed)
|
|
58
|
-
return;
|
|
59
|
-
const bytes = Buffer.byteLength(data);
|
|
60
|
-
s.pendingBytes += bytes;
|
|
61
|
-
if (s.pendingBytes > 256 * 1024)
|
|
62
|
-
s.pty.pause();
|
|
63
|
-
const previous = s.rendered;
|
|
64
|
-
s.rendered = previous.then(() => new Promise(resolve => {
|
|
65
|
-
s.terminal.write(data, () => {
|
|
66
|
-
// Each PTY event is a sequence boundary. A single large event can exceed the history budget;
|
|
67
|
-
// dropping it is safe because poll then returns a fully rendered snapshot.
|
|
68
|
-
s.seq += 1;
|
|
69
|
-
s.ring.push({ seq: s.seq, data, bytes });
|
|
70
|
-
s.ringBytes += bytes;
|
|
71
|
-
const limit = this.options.historyBytes ?? HISTORY_BYTES;
|
|
72
|
-
while (s.ringBytes > limit && s.ring.length)
|
|
73
|
-
s.ringBytes -= s.ring.shift().bytes;
|
|
74
|
-
s.pendingBytes -= bytes;
|
|
75
|
-
if (s.pendingBytes < 64 * 1024 && !s.exited)
|
|
76
|
-
s.pty.resume();
|
|
77
|
-
resolve();
|
|
78
|
-
});
|
|
79
|
-
}));
|
|
80
|
-
}
|
|
81
|
-
async dispatch(method, p) {
|
|
82
|
-
if (method === 'terminal.list') {
|
|
83
|
-
keys(p, []);
|
|
84
|
-
return { sessions: [...this.sessions.values()].map(s => this.descriptor(s)) };
|
|
85
|
-
}
|
|
86
|
-
if (!this.ptyModule)
|
|
87
|
-
throw new Error(this.error ?? 'Terminal unavailable');
|
|
88
|
-
const id = identifier(p, 'id');
|
|
89
|
-
const clientId = identifier(p, 'clientId');
|
|
90
|
-
if (method === 'terminal.create') {
|
|
91
|
-
keys(p, ['id', 'clientId', 'name', 'cwd', 'cols', 'rows']);
|
|
92
|
-
const cols = integer(p, 'cols', 20, 300, 100);
|
|
93
|
-
const rows = integer(p, 'rows', 5, 100, 30);
|
|
94
|
-
if (p.name !== undefined && (typeof p.name !== 'string' || !p.name.length || p.name.length > 128 || /[\x00-\x1f]/.test(p.name)))
|
|
95
|
-
throw new Error('Invalid terminal name');
|
|
96
|
-
const old = this.sessions.get(id);
|
|
97
|
-
if (old)
|
|
98
|
-
return this.descriptor(old);
|
|
99
|
-
if (this.sessions.size >= 8)
|
|
100
|
-
throw new Error('Terminal session limit exceeded');
|
|
101
|
-
if (p.cwd !== undefined && typeof p.cwd !== 'string')
|
|
102
|
-
throw new Error('Invalid cwd');
|
|
103
|
-
const cwd = await this.files.resolve(p.cwd ?? this.files.home);
|
|
104
|
-
const terminal = new Terminal({ cols, rows, scrollback: SCROLLBACK, allowProposedApi: true });
|
|
105
|
-
const serializer = new SerializeAddon();
|
|
106
|
-
// Headless and browser xterm share the addon contract, but their declaration packages differ.
|
|
107
|
-
terminal.loadAddon(serializer);
|
|
108
|
-
let pty;
|
|
109
|
-
try {
|
|
110
|
-
pty = this.ptyModule.spawn(this.options.shell ?? process.env.SHELL ?? os.userInfo().shell ?? '/bin/sh', ['-l'], { name: 'xterm-256color', cwd, cols, rows, env: { ...process.env, TERM: 'xterm-256color', COLORTERM: 'truecolor' } });
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
terminal.dispose();
|
|
114
|
-
throw error;
|
|
115
|
-
}
|
|
116
|
-
const session = { id, name: p.name ?? 'Terminal', cwd, cols, rows, exited: false, exitCode: null, controllerId: clientId, pty, closed: false, terminal, serializer, seq: 0, ring: [], ringBytes: 0, pendingBytes: 0, rendered: Promise.resolve() };
|
|
117
|
-
pty.onData(data => this.output(session, data));
|
|
118
|
-
pty.onExit(event => { session.exited = true; session.exitCode = event.exitCode; });
|
|
119
|
-
// Answering terminal queries (DA/DSR, etc.) is keeper-owned and does not require a web client.
|
|
120
|
-
terminal.onData(data => { if (!session.exited)
|
|
121
|
-
pty.write(data); });
|
|
122
|
-
this.sessions.set(id, session);
|
|
123
|
-
return this.descriptor(session);
|
|
124
|
-
}
|
|
125
|
-
const s = this.sessions.get(id);
|
|
126
|
-
if (!s)
|
|
127
|
-
throw new Error('Terminal session not found; keeper restart loses live PTYs');
|
|
128
|
-
switch (method) {
|
|
129
|
-
case 'terminal.attach': {
|
|
130
|
-
keys(p, ['id', 'clientId', 'cols', 'rows']);
|
|
131
|
-
// Validate dimensions even for a viewer, but only the controller's dimensions affect PTY.
|
|
132
|
-
integer(p, 'cols', 20, 300, s.cols);
|
|
133
|
-
integer(p, 'rows', 5, 100, s.rows);
|
|
134
|
-
await s.rendered;
|
|
135
|
-
if (s.controllerId === null)
|
|
136
|
-
s.controllerId = clientId;
|
|
137
|
-
if (s.controllerId === clientId)
|
|
138
|
-
this.resize(s, p);
|
|
139
|
-
return { session: this.descriptor(s), seq: s.seq, snapshot: this.snapshot(s), control: s.controllerId === clientId };
|
|
140
|
-
}
|
|
141
|
-
case 'terminal.poll': {
|
|
142
|
-
keys(p, ['id', 'clientId', 'after']);
|
|
143
|
-
const after = integer(p, 'after', 0, Number.MAX_SAFE_INTEGER);
|
|
144
|
-
await s.rendered;
|
|
145
|
-
const common = { exited: s.exited, exitCode: s.exitCode, control: s.controllerId === clientId };
|
|
146
|
-
if (after > s.seq || after < (s.ring[0]?.seq ?? s.seq + 1) - 1)
|
|
147
|
-
return { ...common, seq: s.seq, data: '', reset: true, snapshot: this.snapshot(s) };
|
|
148
|
-
let data = '';
|
|
149
|
-
let bytes = 0;
|
|
150
|
-
let seq = after;
|
|
151
|
-
for (const output of s.ring) {
|
|
152
|
-
if (output.seq <= after)
|
|
153
|
-
continue;
|
|
154
|
-
if (bytes + output.bytes > MAX_POLL_BYTES) {
|
|
155
|
-
if (!bytes)
|
|
156
|
-
return { ...common, seq: s.seq, data: '', reset: true, snapshot: this.snapshot(s) };
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
data += output.data;
|
|
160
|
-
bytes += output.bytes;
|
|
161
|
-
seq = output.seq;
|
|
162
|
-
}
|
|
163
|
-
return { ...common, seq, data, reset: false };
|
|
164
|
-
}
|
|
165
|
-
case 'terminal.takeover':
|
|
166
|
-
keys(p, ['id', 'clientId']);
|
|
167
|
-
s.controllerId = clientId;
|
|
168
|
-
return { ok: true };
|
|
169
|
-
case 'terminal.detach':
|
|
170
|
-
keys(p, ['id', 'clientId']);
|
|
171
|
-
if (s.controllerId === clientId)
|
|
172
|
-
s.controllerId = null;
|
|
173
|
-
return { ok: true };
|
|
174
|
-
case 'terminal.write':
|
|
175
|
-
keys(p, ['id', 'clientId', 'data']);
|
|
176
|
-
this.control(s, clientId);
|
|
177
|
-
if (s.exited)
|
|
178
|
-
throw new Error('Terminal has exited');
|
|
179
|
-
if (typeof p.data !== 'string' || Buffer.byteLength(p.data) > 64 * 1024)
|
|
180
|
-
throw new Error('Invalid terminal input');
|
|
181
|
-
s.pty.write(p.data);
|
|
182
|
-
return { ok: true };
|
|
183
|
-
case 'terminal.resize':
|
|
184
|
-
keys(p, ['id', 'clientId', 'cols', 'rows']);
|
|
185
|
-
this.control(s, clientId);
|
|
186
|
-
integer(p, 'cols', 20, 300);
|
|
187
|
-
integer(p, 'rows', 5, 100);
|
|
188
|
-
await s.rendered;
|
|
189
|
-
this.resize(s, p);
|
|
190
|
-
return { ok: true };
|
|
191
|
-
case 'terminal.close':
|
|
192
|
-
keys(p, ['id', 'clientId']);
|
|
193
|
-
this.control(s, clientId);
|
|
194
|
-
this.sessions.delete(id);
|
|
195
|
-
s.closed = true;
|
|
196
|
-
if (!s.exited)
|
|
197
|
-
s.pty.kill();
|
|
198
|
-
await s.rendered;
|
|
199
|
-
s.terminal.dispose();
|
|
200
|
-
return { ok: true };
|
|
201
|
-
default: throw new Error('Unsupported terminal tool');
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
async dispose() {
|
|
205
|
-
for (const session of this.sessions.values()) {
|
|
206
|
-
session.closed = true;
|
|
207
|
-
if (!session.exited)
|
|
208
|
-
session.pty.kill();
|
|
209
|
-
await session.rendered;
|
|
210
|
-
session.terminal.dispose();
|
|
211
|
-
}
|
|
212
|
-
this.sessions.clear();
|
|
213
|
-
}
|
|
214
|
-
}
|