@platless/axom-cli 0.3.13 → 0.6.36
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 +18 -5
- package/dist/axom-patch/cli/README.md +119 -9
- 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 +123 -0
- package/dist/axom-patch/cli/account-limits/kimi-proxy.mjs +81 -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/codex-terminal-output.json +16 -0
- package/dist/axom-patch/cli/commandcode-account-limits.json +30 -0
- package/dist/axom-patch/cli/kimi-quota.mjs +12 -0
- package/dist/axom-patch/cli/kimi-subagents.mjs +173 -0
- package/dist/axom-patch/cli/nightly-task.md +194 -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/codex-terminal-output.mjs +33 -0
- package/dist/axom-patch/cli/probes/kimi-subagent-subwork.mjs +82 -0
- package/dist/axom-patch/cli/probes/pi-subagent-subwork.mjs +211 -0
- package/dist/axom-patch/cli/probes/zcode-subagent-subwork.mjs +257 -0
- package/dist/axom-patch/cli/qoder/dist/axom-acp-compat.mjs +1591 -0
- package/dist/axom-patch/cli/qoder/releases/1.1.75.json +360 -0
- package/dist/axom-patch/cli/qoder-background-terminal.md +13 -5
- package/dist/axom-patch/cli/qoder-foreground-output.md +14 -7
- package/dist/axom-patch/cli/qoder-native-acp.json +227 -0
- package/dist/axom-patch/cli/qoder-steering.md +20 -25
- package/dist/axom-patch/cli/qoder-subagent-subwork.md +17 -68
- package/dist/axom-patch/cli/runtime.json +39 -15
- package/dist/axom-patch/cli/zcode-account-limits.json +30 -0
- package/dist/axom-patch/cli/zcode-models.json +37 -0
- package/dist/axom-patch/cli/zcode-subagent-subwork.json +72 -0
- package/dist/cli.js +4 -9
- package/dist/commands/knowledge.js +47 -0
- package/dist/commands/update.js +65 -3
- package/dist/commands/workstation.js +73 -7
- package/dist/install/claude/commands.js +13 -13
- 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/mcp.js +1 -1
- package/dist/native/darwin-arm64/axom-quic +0 -0
- package/dist/test/keeperKit.js +67 -0
- package/dist/workstation/acp/acpAgents.js +2192 -636
- package/dist/workstation/acp/acpClient.js +84 -495
- 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 +324 -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 +290 -0
- package/dist/workstation/acp/installErrors.js +12 -2
- package/dist/workstation/acp/installProbe.js +1 -1
- package/dist/workstation/acp/managedPatches.js +239 -159
- package/dist/workstation/acp/managedRuntime.js +314 -0
- package/dist/workstation/acp/outbox.js +330 -0
- package/dist/workstation/acp/patchAssets.js +60 -3
- package/dist/workstation/acp/permission.js +42 -10
- package/dist/workstation/acp/processor/checkpoint.js +78 -0
- package/dist/workstation/acp/processor/commands.js +35 -0
- package/dist/workstation/acp/processor/control.js +282 -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 +105 -0
- package/dist/workstation/acp/processor/sdkSchemas.js +61 -0
- package/dist/workstation/acp/processor/session.js +496 -0
- package/dist/workstation/acp/processor/state.js +67 -0
- package/dist/workstation/acp/processor/step.js +442 -0
- package/dist/workstation/acp/processor/test/fixtureLog.js +58 -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 +390 -0
- package/dist/workstation/acp/processorSession.js +1348 -0
- package/dist/workstation/acp/registry/catalog.js +189 -41
- package/dist/workstation/acp/registry/launch.js +76 -119
- package/dist/workstation/acp/sessionUpdateMapper.js +18 -7
- package/dist/workstation/acp/steering.js +58 -0
- package/dist/workstation/acp/switching.js +111 -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/fakeAgent.js +13 -0
- package/dist/workstation/acp/test/keeperWorld.js +295 -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/sanitize.js +344 -0
- package/dist/workstation/acp/test/raw/sources.js +135 -0
- package/dist/workstation/acp/test/realAdapter.js +331 -0
- package/dist/workstation/acp/test/scriptAgent.js +214 -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 +1289 -544
- 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 +172 -8
- package/dist/workstation/channels/url.js +1 -1
- package/dist/workstation/config.js +16 -4
- package/dist/workstation/connection/encryptedChannel.js +4 -1
- package/dist/workstation/control/bindingStore.js +200 -0
- package/dist/workstation/control/commands.js +124 -0
- package/dist/workstation/control/daemonIdentity.js +53 -0
- package/dist/workstation/control/enrollment.js +106 -0
- package/dist/workstation/control/inspect.js +71 -0
- package/dist/workstation/control/locks.js +63 -0
- package/dist/workstation/control/protocol.js +40 -0
- package/dist/workstation/control/restartGuard.js +46 -0
- package/dist/workstation/control/runtimeClient.js +97 -0
- package/dist/workstation/control/runtimeHost.js +148 -0
- package/dist/workstation/control/serverIdentity.js +35 -0
- package/dist/workstation/daemon.js +393 -12
- package/dist/workstation/daemonctl.js +103 -14
- package/dist/workstation/desktopControl/audio.js +99 -0
- package/dist/workstation/desktopControl/capabilities.js +92 -0
- package/dist/workstation/desktopControl/captureModes.js +9 -0
- package/dist/workstation/desktopControl/captureTargetLabel.js +9 -0
- package/dist/workstation/desktopControl/deviceSockets.js +246 -0
- package/dist/workstation/desktopControl/helperProcess.js +353 -0
- package/dist/workstation/desktopControl/lobby.js +129 -0
- package/dist/workstation/desktopControl/macProvider.js +155 -0
- package/dist/workstation/desktopControl/media.js +331 -0
- package/dist/workstation/desktopControl/nativeProvider.js +1018 -0
- package/dist/workstation/desktopControl/networkEvidence.js +43 -0
- package/dist/workstation/desktopControl/overview.js +58 -0
- package/dist/workstation/desktopControl/protocol.js +302 -0
- package/dist/workstation/desktopControl/quicMedia.js +240 -0
- package/dist/workstation/desktopControl/rateController.js +226 -0
- package/dist/workstation/desktopControl/supervisor.js +1681 -0
- package/dist/workstation/desktopControl/transport.js +27 -0
- package/dist/workstation/desktopControl/wallpaper.js +78 -0
- 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/credentials.js +142 -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} +152 -39
- 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 +124 -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 +289 -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 +76 -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/managedInstall.js +57 -0
- package/dist/workstation/protocol/accountLimits.js +47 -0
- package/dist/workstation/protocol/agent.js +50 -19
- package/dist/workstation/protocol/common.js +30 -0
- package/dist/workstation/protocol/computer.js +15 -4
- package/dist/workstation/protocol/management.js +141 -4
- package/dist/workstation/protocol/runtimeDiagnostics.js +15 -0
- package/dist/workstation/rd/artifact.js +119 -0
- package/dist/workstation/rd/control.js +119 -0
- package/dist/workstation/rd/display.js +29 -0
- package/dist/workstation/rd/provider.js +222 -0
- package/dist/workstation/rd/sessions.js +391 -0
- package/dist/workstation/rd/state.js +45 -0
- package/dist/workstation/rd/update.js +171 -0
- package/dist/workstation/rd/upkeep.js +38 -0
- package/dist/workstation/register.js +27 -37
- package/dist/workstation/service/installer.js +104 -13
- package/dist/workstation/service/launchd.js +1 -0
- package/dist/workstation/storageMetrics.js +118 -0
- package/dist/workstation/systemMetrics.js +154 -93
- package/dist/workstation/toolchain.js +94 -0
- package/dist/workstation/tools/browser.js +28 -4
- 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/artifact.js +2 -1
- package/dist/workstation/update/coordinator.js +3 -0
- package/dist/workstation/update/globalInstall.js +116 -0
- package/dist/workstation/update/npmInstaller.js +49 -23
- package/dist/workstation/update/ptyPreflight.js +21 -0
- package/dist/workstation/update/rdRollback.js +145 -0
- package/dist/workstation/update/runUpdate.js +3 -2
- package/dist/workstation/update/taskRegistry.js +105 -11
- package/dist/workstation/update/watchdog.js +16790 -334
- package/package.json +11 -8
- package/skills/axom/SKILL.md +11 -11
- package/skills/axom-definition/SKILL.md +3 -3
- package/skills/axom-platform/SKILL.md +3 -3
- package/dist/axom-patch/cli/probes/qoder-steering.mjs +0 -89
- package/dist/axom-patch/cli/probes/qoder-subagent-origin.mjs +0 -49
- package/dist/axom-patch/cli/qoder-steering.json +0 -52
- package/dist/axom-patch/cli/qoder-subagent-origin.json +0 -73
- package/dist/commands/guide.js +0 -38
- package/dist/workstation/acp/acpSession.js +0 -1475
- package/dist/workstation/acp/contract.js +0 -499
- package/dist/workstation/acp/delegationMcp.js +0 -24
- package/dist/workstation/acp/draftInterceptor.js +0 -163
- package/dist/workstation/acp/qoderStartup.js +0 -45
- 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/backgroundProcess.js +0 -106
- package/dist/workstation/qoderAdapter/backgroundTerminal.js +0 -262
- package/dist/workstation/qoderAdapter/completedContinuation.js +0 -139
- package/dist/workstation/qoderAdapter/contract.js +0 -78
- package/dist/workstation/qoderAdapter/foregroundOutput.js +0 -30
- package/dist/workstation/qoderAdapter/history.js +0 -87
- package/dist/workstation/qoderAdapter/identityIndex.js +0 -191
- package/dist/workstation/qoderAdapter/inputQueue.js +0 -42
- package/dist/workstation/qoderAdapter/main.js +0 -93
- package/dist/workstation/qoderAdapter/mapper.js +0 -117
- package/dist/workstation/qoderAdapter/observerPlugin.js +0 -245
- package/dist/workstation/qoderAdapter/observerReceiver.js +0 -187
- package/dist/workstation/qoderAdapter/permissions.js +0 -61
- package/dist/workstation/qoderAdapter/profile.js +0 -93
- package/dist/workstation/qoderAdapter/sdkDriver.js +0 -49
- package/dist/workstation/qoderAdapter/session.js +0 -319
- package/dist/workstation/qoderAdapter/subagentMeta.js +0 -28
- package/dist/workstation/qoderAdapter/subwork.js +0 -77
- package/dist/workstation/qoderAdapter/taskControl.js +0 -38
- package/dist/workstation/qoderAdapter/taskEvent.js +0 -26
- package/dist/workstation/qoderAdapter/taskLedger.js +0 -163
- package/dist/workstation/qoderAdapter/usage.js +0 -37
- package/dist/workstation/tools/core.js +0 -50
- package/dist/workstation/tools/files.js +0 -525
- package/dist/workstation/tools/terminal.js +0 -214
- /package/dist/workstation/{qoderAdapter/types.js → desktopControl/provider.js} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { connectEncryptedChannel } from '../connection/encryptedChannel.js';
|
|
3
3
|
import { AGENT_WIRE_MIN_VERSION, AGENT_WIRE_RESUME_OFFER_VERSION, AGENT_WIRE_VERSION, decodeAgentFrame, encodeAgentFrame, outboundAgentFrameRejection, } from '../protocol/agent.js';
|
|
4
|
-
import { bridgesForWire } from '../protocol/common.js';
|
|
4
|
+
import { bridgesForWire, helloRoster } from '../protocol/common.js';
|
|
5
5
|
import { workstationChannelUrl } from './url.js';
|
|
6
6
|
/** Binds daemon-scoped sessions only to the encrypted agent channel's sender. */
|
|
7
7
|
export class AgentChannel {
|
|
@@ -25,7 +25,9 @@ export class AgentChannel {
|
|
|
25
25
|
// Hoisted rather than inlined twice: `closeAll` compares it by identity to decide whether the
|
|
26
26
|
// binding it is being asked to drop is still this connection's. See AgentSessionManager.closeAll.
|
|
27
27
|
const send = (frame) => channel.send(frame);
|
|
28
|
-
|
|
28
|
+
// The socket's unsent bytes: the manager's socket gate holds session frames back above 1 MiB so the heartbeat (written by the
|
|
29
|
+
// channel itself) never queues behind a backlog (spec §5.6).
|
|
30
|
+
void dispatchAgentChannelFrames(channel.messages, send, this.options.agents, () => channel.close(), () => channel.bufferedAmount);
|
|
29
31
|
void channel.closed.then(() => this.options.agents.closeAll(send));
|
|
30
32
|
return { closed: channel.closed, close: () => channel.close() };
|
|
31
33
|
}
|
|
@@ -58,10 +60,10 @@ export function agentHeartbeat(seq, sentAtEpochMs, agents) {
|
|
|
58
60
|
}
|
|
59
61
|
/** Exported so the roster this hello carries can be asserted without opening a socket. */
|
|
60
62
|
export function buildAgentHelloFrame(ticket, bridges) {
|
|
61
|
-
return { t: 'agent_hello', ticket, bridges: bridgesForWire(bridges(), 'agent_hello') };
|
|
63
|
+
return { t: 'agent_hello', ticket, bridges: bridgesForWire(helloRoster(bridges()), 'agent_hello') };
|
|
62
64
|
}
|
|
63
65
|
/** Negotiates one agent connection and emits exactly one reconnect offer when the server supports it. */
|
|
64
|
-
export async function dispatchAgentChannelFrames(messages, send, agents, close = () => { }) {
|
|
66
|
+
export async function dispatchAgentChannelFrames(messages, send, agents, close = () => { }, bufferedAmount) {
|
|
65
67
|
let offered = false;
|
|
66
68
|
try {
|
|
67
69
|
for await (const frame of messages) {
|
|
@@ -71,7 +73,7 @@ export async function dispatchAgentChannelFrames(messages, send, agents, close =
|
|
|
71
73
|
return;
|
|
72
74
|
}
|
|
73
75
|
const negotiated = Math.min(frame.agentWire, AGENT_WIRE_VERSION);
|
|
74
|
-
agents.bindSend(send, negotiated);
|
|
76
|
+
agents.bindSend(send, negotiated, bufferedAmount);
|
|
75
77
|
if (!offered && negotiated >= AGENT_WIRE_RESUME_OFFER_VERSION) {
|
|
76
78
|
offered = true;
|
|
77
79
|
send({ t: 'agent_resume_offer', sessions: await agents.resumeOfferSessions() });
|
|
@@ -3,19 +3,21 @@ import { resolveBrowserBinding } from '../desktop/binding.js';
|
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
4
|
import { connectEncryptedChannel } from '../connection/encryptedChannel.js';
|
|
5
5
|
import { runExec } from '../exec.js';
|
|
6
|
+
import { ExecPolicy, keeperExecsOutliveTheChannel } from '../exec/policy.js';
|
|
7
|
+
import { ComputerExecWire } from './computerExecs.js';
|
|
6
8
|
import { decodeComputerFrame, encodeComputerFrame } from '../protocol/computer.js';
|
|
7
9
|
import { workstationChannelUrl } from './url.js';
|
|
8
10
|
import { TaskRegistry } from '../update/taskRegistry.js';
|
|
9
|
-
import {
|
|
10
|
-
import { computerFileError } from '../filePaths.js';
|
|
11
|
-
import { ToolsClient } from '../tools/client.js';
|
|
11
|
+
import { toFileError } from '../files/errors.js';
|
|
12
12
|
import { object } from '../tools/validation.js';
|
|
13
|
+
import { isUnaccountedTool } from '../tools/router.js';
|
|
14
|
+
import { requestRootFileExecutors } from '../files/adapters/computerFileFrames.js';
|
|
13
15
|
/**
|
|
14
16
|
* Consumes computer frames without serializing long-running commands behind one another.
|
|
15
17
|
* All command failures and post-close sends are contained here because this is called detached
|
|
16
18
|
* from the socket connection loop.
|
|
17
19
|
*/
|
|
18
|
-
export async function dispatchComputerFrames(messages, send, execute, tasks = new TaskRegistry(), files = {}, tools, desktop) {
|
|
20
|
+
export async function dispatchComputerFrames(messages, send, execute, tasks = new TaskRegistry(), files = {}, tools, desktop, durable = {}) {
|
|
19
21
|
const active = new Map();
|
|
20
22
|
const activeTools = new Set();
|
|
21
23
|
let open = true;
|
|
@@ -25,6 +27,9 @@ export async function dispatchComputerFrames(messages, send, execute, tasks = ne
|
|
|
25
27
|
send(frame);
|
|
26
28
|
}
|
|
27
29
|
catch { /* socket already closed */ } };
|
|
30
|
+
// Wire ≥ 5 (keeperExecsOutliveTheChannel): exec frames go to the exec policy, which owns the execs (spec §4.3).
|
|
31
|
+
const execWire = new ComputerExecWire(durable.host ?? new ExecPolicy(), tasks, { send: safeSend, bufferedAmount: durable.bufferedAmount ?? (() => 0) }, durable.log);
|
|
32
|
+
const durableWire = () => keeperExecsOutliveTheChannel(wireVersion);
|
|
28
33
|
const run = (request) => {
|
|
29
34
|
if (!tasks.accepting) {
|
|
30
35
|
safeSend({ t: 'exec_exit', id: request.id, exitCode: null, stdout: '', stderr: 'Workstation is not accepting new work', timedOut: false, truncated: false });
|
|
@@ -35,6 +40,8 @@ export async function dispatchComputerFrames(messages, send, execute, tasks = ne
|
|
|
35
40
|
// the most recently accepted request while the older promise still cleans up its own entry.
|
|
36
41
|
active.get(request.id)?.abort();
|
|
37
42
|
active.set(request.id, controller);
|
|
43
|
+
// Wire ≤ 4 (spec §4.3 "compat", §8.2): every exec, in keeper-terminal or not, is a shell task (counted, drained, aborted by a
|
|
44
|
+
// force update) and is killed when the channel closes: the server reports it ended and an agent may run it again.
|
|
38
45
|
void (async () => {
|
|
39
46
|
try {
|
|
40
47
|
const exit = await tasks.withShellTask(async (shutdown) => {
|
|
@@ -43,10 +50,19 @@ export async function dispatchComputerFrames(messages, send, execute, tasks = ne
|
|
|
43
50
|
controller.abort();
|
|
44
51
|
else
|
|
45
52
|
shutdown.addEventListener('abort', onShutdown, { once: true });
|
|
53
|
+
// A keeper-terminal exec is a shell task here AND in keeper-terminal's execRunning: counted once on the page (minor 7).
|
|
54
|
+
let uncount;
|
|
46
55
|
try {
|
|
47
|
-
return await execute(request, request.streaming ? (stream, chunk) => safeSend({ t: 'exec_output', id: request.id, stream, chunk }) : undefined, controller.signal
|
|
56
|
+
return await execute(request, request.streaming ? (stream, chunk) => safeSend({ t: 'exec_output', id: request.id, stream, chunk }) : undefined, controller.signal, {
|
|
57
|
+
outlivesChannel: false,
|
|
58
|
+
onStarted: (info) => { if (info.durable) {
|
|
59
|
+
uncount?.();
|
|
60
|
+
uncount = tasks.countKeeperExec();
|
|
61
|
+
} },
|
|
62
|
+
});
|
|
48
63
|
}
|
|
49
64
|
finally {
|
|
65
|
+
uncount?.();
|
|
50
66
|
shutdown.removeEventListener('abort', onShutdown);
|
|
51
67
|
}
|
|
52
68
|
});
|
|
@@ -94,16 +110,18 @@ export async function dispatchComputerFrames(messages, send, execute, tasks = ne
|
|
|
94
110
|
else
|
|
95
111
|
shutdown.addEventListener('abort', onShutdown, { once: true });
|
|
96
112
|
try {
|
|
113
|
+
if (files.runFrame)
|
|
114
|
+
return await files.runFrame(request, controller.signal);
|
|
97
115
|
if (request.t === 'file_read_request') {
|
|
98
|
-
return await (files.readFile ??
|
|
116
|
+
return await (files.readFile ?? requestRootFileExecutors.readFile)({ root: request.root, path: request.path, startLine: request.startLine, maxLines: request.maxLines }, controller.signal);
|
|
99
117
|
}
|
|
100
118
|
if (request.t === 'file_write_request') {
|
|
101
|
-
return await (files.writeFile ??
|
|
119
|
+
return await (files.writeFile ?? requestRootFileExecutors.writeFile)({ root: request.root, path: request.path, content: request.content, mode: request.mode, expectedSha256: request.expectedSha256 }, controller.signal);
|
|
102
120
|
}
|
|
103
121
|
if (request.t === 'file_ls_request') {
|
|
104
|
-
return await (files.listDir ??
|
|
122
|
+
return await (files.listDir ?? requestRootFileExecutors.listDir)({ root: request.root, path: request.path, startAfter: request.startAfter, maxEntries: request.maxEntries }, controller.signal);
|
|
105
123
|
}
|
|
106
|
-
return await (files.createDir ??
|
|
124
|
+
return await (files.createDir ?? requestRootFileExecutors.createDir)({ root: request.root, path: request.path, parents: request.parents }, controller.signal);
|
|
107
125
|
}
|
|
108
126
|
finally {
|
|
109
127
|
shutdown.removeEventListener('abort', onShutdown);
|
|
@@ -111,6 +129,10 @@ export async function dispatchComputerFrames(messages, send, execute, tasks = ne
|
|
|
111
129
|
});
|
|
112
130
|
if (active.get(request.id) !== controller)
|
|
113
131
|
return;
|
|
132
|
+
if (files.runFrame) {
|
|
133
|
+
safeSend(data);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
114
136
|
if (request.t === 'file_read_request')
|
|
115
137
|
safeSend({ t: 'file_read_result', id: request.id, data: data });
|
|
116
138
|
else if (request.t === 'file_write_request')
|
|
@@ -123,7 +145,7 @@ export async function dispatchComputerFrames(messages, send, execute, tasks = ne
|
|
|
123
145
|
catch (error) {
|
|
124
146
|
if (active.get(request.id) !== controller)
|
|
125
147
|
return;
|
|
126
|
-
const mapped =
|
|
148
|
+
const mapped = toFileError(error);
|
|
127
149
|
if (controller.signal.aborted) {
|
|
128
150
|
const mutation = request.t === 'file_write_request' || request.t === 'file_mkdir_request';
|
|
129
151
|
fail(mutation ? 'outcome_unknown' : 'workstation_offline', request.t === 'file_write_request' ? 'Write outcome is unknown after cancellation'
|
|
@@ -145,12 +167,15 @@ export async function dispatchComputerFrames(messages, send, execute, tasks = ne
|
|
|
145
167
|
fail('Workstation tools require computer wire v3');
|
|
146
168
|
return;
|
|
147
169
|
}
|
|
148
|
-
|
|
170
|
+
// tools.info (a probe) and terminal.* (PTYs live in their keeper) answer while draining and are not work a restart
|
|
171
|
+
// would interrupt: no admission gate, no shell-task accounting.
|
|
172
|
+
const probe = isUnaccountedTool(request.method);
|
|
173
|
+
if (!probe && !tasks.accepting) {
|
|
149
174
|
fail('Workstation is not accepting new work');
|
|
150
175
|
return;
|
|
151
176
|
}
|
|
152
177
|
if (!tools && request.method !== 'browser.sharedText') {
|
|
153
|
-
fail('Workstation tools
|
|
178
|
+
fail('Workstation tools are not configured');
|
|
154
179
|
return;
|
|
155
180
|
}
|
|
156
181
|
if (activeTools.has(request.id)) {
|
|
@@ -165,10 +190,11 @@ export async function dispatchComputerFrames(messages, send, execute, tasks = ne
|
|
|
165
190
|
void (async () => {
|
|
166
191
|
let timer;
|
|
167
192
|
try {
|
|
168
|
-
const
|
|
193
|
+
const call = () => Promise.race([
|
|
169
194
|
request.method === 'browser.sharedText' ? (desktop ? desktop.insertText(request.params) : Promise.reject(Error('Shared desktop unavailable'))) : tools(request.method, request.params),
|
|
170
195
|
new Promise((_resolve, reject) => { timer = setTimeout(() => reject(new Error('Workstation tool timed out; mutation outcome may be unknown')), 7500); }),
|
|
171
|
-
])
|
|
196
|
+
]);
|
|
197
|
+
const result = probe ? await call() : await tasks.withShellTask(call);
|
|
172
198
|
if (!object(result))
|
|
173
199
|
throw new Error('Invalid workstation tool result');
|
|
174
200
|
safeSend({ t: 'tool_result', id: request.id, ok: true, result, error: null });
|
|
@@ -189,10 +215,25 @@ export async function dispatchComputerFrames(messages, send, execute, tasks = ne
|
|
|
189
215
|
desktop?.onFrame(frame);
|
|
190
216
|
else if (frame.t === 'tool_request')
|
|
191
217
|
runTool(frame);
|
|
192
|
-
else if (frame.t === 'exec_request')
|
|
193
|
-
|
|
194
|
-
|
|
218
|
+
else if (frame.t === 'exec_request') {
|
|
219
|
+
if (durableWire())
|
|
220
|
+
execWire.request(frame);
|
|
221
|
+
else
|
|
222
|
+
run(frame);
|
|
223
|
+
}
|
|
224
|
+
else if (frame.t === 'exec_cancel') {
|
|
195
225
|
active.get(frame.id)?.abort();
|
|
226
|
+
if (durableWire())
|
|
227
|
+
execWire.cancel(frame);
|
|
228
|
+
}
|
|
229
|
+
else if (frame.t === 'exec_attach') {
|
|
230
|
+
if (durableWire())
|
|
231
|
+
execWire.attachFrame(frame);
|
|
232
|
+
}
|
|
233
|
+
else if (frame.t === 'exec_ack') {
|
|
234
|
+
if (durableWire())
|
|
235
|
+
execWire.ack(frame);
|
|
236
|
+
}
|
|
196
237
|
else if (frame.t === 'computer_ready') {
|
|
197
238
|
wireVersion = frame.wireVersion;
|
|
198
239
|
desktop?.ready(frame.generation, frame.wireVersion);
|
|
@@ -204,6 +245,7 @@ export async function dispatchComputerFrames(messages, send, execute, tasks = ne
|
|
|
204
245
|
finally {
|
|
205
246
|
open = false;
|
|
206
247
|
desktop?.close();
|
|
248
|
+
execWire.close();
|
|
207
249
|
for (const controller of active.values())
|
|
208
250
|
controller.abort();
|
|
209
251
|
}
|
|
@@ -213,11 +255,15 @@ export class ComputerChannel {
|
|
|
213
255
|
options;
|
|
214
256
|
tasks;
|
|
215
257
|
tools;
|
|
258
|
+
/** One exec host for every channel this object opens: execs outlive a channel and are re-attached on the next one. */
|
|
259
|
+
execs;
|
|
216
260
|
constructor(options) {
|
|
217
261
|
this.options = options;
|
|
218
262
|
this.tasks = options.taskRegistry ?? new TaskRegistry();
|
|
219
|
-
|
|
220
|
-
|
|
263
|
+
this.execs = options.execs ?? new ExecPolicy();
|
|
264
|
+
// Tools only through the caller's router (daemon.ts): no fallback to a terminal-kind ToolsClient, whose request() would start
|
|
265
|
+
// (or reach) the legacy tools keeper behind the TerminalRouter's back.
|
|
266
|
+
this.tools = options.tools;
|
|
221
267
|
}
|
|
222
268
|
activeTaskCount() { return this.tasks.snapshot().activeShellTasks; }
|
|
223
269
|
async connect(ticket, signal) {
|
|
@@ -233,7 +279,9 @@ export class ComputerChannel {
|
|
|
233
279
|
return { closed: channel.closed, close: () => channel.close() };
|
|
234
280
|
}
|
|
235
281
|
async dispatch(channel) {
|
|
236
|
-
const desktop = new DesktopBridge(resolveBrowserBinding(this.options.browserBinding
|
|
237
|
-
await dispatchComputerFrames(channel.messages, (frame) => channel.send(frame), this.options.runExec ?? runExec, this.tasks, this.options, this.tools, desktop
|
|
282
|
+
const desktop = new DesktopBridge(resolveBrowserBinding(this.options.browserBinding), frame => channel.send(frame), () => channel.bufferedAmount);
|
|
283
|
+
await dispatchComputerFrames(channel.messages, (frame) => channel.send(frame), this.options.runExec ?? ((request, onOutput, signal) => runExec(request, onOutput, signal)), this.tasks, this.options, this.tools, desktop, {
|
|
284
|
+
host: this.execs, bufferedAmount: () => channel.bufferedAmount, log: this.options.log,
|
|
285
|
+
});
|
|
238
286
|
}
|
|
239
287
|
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// COMPUTER wire v5 exec frames of ONE computer channel (spec §4.3, §8.2): exec_request / exec_attach / exec_ack / exec_cancel in,
|
|
2
|
+
// exec_started / exec_output (with offsets) / exec_status / exec_exit out. The execs themselves belong to the exec policy
|
|
3
|
+
// (exec/policy.ts `DurableExecHost`), not to this channel: a channel close only stops this channel's attachments.
|
|
4
|
+
//
|
|
5
|
+
// - A keeper exec (durable) is never a shell task: not counted in `activeShellTasks`, admitted while an update drains, untouched by
|
|
6
|
+
// a force update (`stopAll`) and by a channel close.
|
|
7
|
+
// - A fallback exec (in this process, `durable:false`) keeps today's semantics: a shell task, refused while draining, killed by a
|
|
8
|
+
// force update and by a channel close.
|
|
9
|
+
// - An exec_request for an id the policy already knows is an attach (exec_started again, then its output from offset 0): never a
|
|
10
|
+
// second run.
|
|
11
|
+
import { ExecAttachment, wireExitFrame } from '../exec/attach.js';
|
|
12
|
+
import { durableExitFrame } from '../exec/policy.js';
|
|
13
|
+
export const NOT_ACCEPTING_MESSAGE = 'Workstation is not accepting new work';
|
|
14
|
+
/** How soon an `exec_attach` whose exec's state could not be decided asks the policy again. */
|
|
15
|
+
export const ATTACH_UNDECIDED_RETRY_MS = 2000;
|
|
16
|
+
/** A v5 `exec_exit` that is not the outcome of a durable exec (refused, limit, fallback): today's fields plus `cancelled`. */
|
|
17
|
+
function plainExit(exit, cancelled) {
|
|
18
|
+
return { ...exit, cancelled };
|
|
19
|
+
}
|
|
20
|
+
export class ComputerExecWire {
|
|
21
|
+
host;
|
|
22
|
+
tasks;
|
|
23
|
+
channel;
|
|
24
|
+
log;
|
|
25
|
+
options;
|
|
26
|
+
/** This channel's attachment per server exec id (one at a time: a newer attach replaces the older). */
|
|
27
|
+
attachments = new Map();
|
|
28
|
+
/** In-process (fallback) execs started by this channel: they die with it. */
|
|
29
|
+
fallbacks = new Map();
|
|
30
|
+
/** Requests between receipt and knowing where they run, with an exec_cancel received meanwhile. */
|
|
31
|
+
pending = new Map();
|
|
32
|
+
closed = false;
|
|
33
|
+
constructor(host, tasks, channel, log = () => { }, options = {}) {
|
|
34
|
+
this.host = host;
|
|
35
|
+
this.tasks = tasks;
|
|
36
|
+
this.channel = channel;
|
|
37
|
+
this.log = log;
|
|
38
|
+
this.options = options;
|
|
39
|
+
}
|
|
40
|
+
send(frame) { if (!this.closed)
|
|
41
|
+
this.channel.send(frame); }
|
|
42
|
+
request(frame) {
|
|
43
|
+
if (this.fallbacks.has(frame.id) || this.pending.has(frame.id))
|
|
44
|
+
return; // the same request again on this channel: already running
|
|
45
|
+
const pending = { cancelled: false };
|
|
46
|
+
this.pending.set(frame.id, pending);
|
|
47
|
+
// Counted (not gated, not stoppable) from here until the exec has its first checkpoint: a drain admits a v5 exec, but a restart
|
|
48
|
+
// inside this window would leave keeper-terminal with an exec the next daemon can only identify by its id (spec §8.2).
|
|
49
|
+
const release = this.tasks.holdShellTask();
|
|
50
|
+
void (async () => {
|
|
51
|
+
try {
|
|
52
|
+
const started = await this.host.startOrFind(frame);
|
|
53
|
+
if (started.kind !== 'durable')
|
|
54
|
+
release();
|
|
55
|
+
if (started.kind === 'exit') {
|
|
56
|
+
this.send(plainExit(started.exit, false));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (started.kind === 'durable') {
|
|
60
|
+
const { exec } = started;
|
|
61
|
+
const uncount = this.tasks.countKeeperExec(); // held in activeShellTasks AND running in keeper-terminal (minor 7)
|
|
62
|
+
void exec.firstCheckpoint.finally(() => { uncount(); release(); });
|
|
63
|
+
this.send({ t: 'exec_started', id: frame.id, durable: true, ...(exec.pid !== null ? { pid: exec.pid } : {}), startedAtMs: exec.startedAtMs });
|
|
64
|
+
this.attach(frame.id, exec, 0);
|
|
65
|
+
if (pending.cancelled)
|
|
66
|
+
void this.host.cancel(frame.id).catch(() => { }); // cancelled before the policy knew the id
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Not durable: today's rules (spec §8.2): refused while an update drains, counted, killed by a force update or a close.
|
|
70
|
+
if (!this.tasks.accepting || this.closed) {
|
|
71
|
+
this.send(plainExit({ t: 'exec_exit', id: frame.id, exitCode: null, stdout: '', stderr: NOT_ACCEPTING_MESSAGE, timedOut: false, truncated: false }, false));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await this.runFallback(frame, started.run, pending.cancelled);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
release();
|
|
78
|
+
this.send(plainExit({ t: 'exec_exit', id: frame.id, exitCode: null, stdout: '', stderr: error instanceof Error ? error.message : String(error), timedOut: false, truncated: false }, false));
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
if (this.pending.get(frame.id) === pending)
|
|
82
|
+
this.pending.delete(frame.id);
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
}
|
|
86
|
+
async runFallback(frame, run, cancelledEarly) {
|
|
87
|
+
const entry = { controller: new AbortController(), cancelled: cancelledEarly };
|
|
88
|
+
if (cancelledEarly)
|
|
89
|
+
entry.controller.abort();
|
|
90
|
+
this.fallbacks.set(frame.id, entry);
|
|
91
|
+
let offset = 0;
|
|
92
|
+
const onOutput = frame.streaming
|
|
93
|
+
? (stream, chunk) => this.send({ t: 'exec_output', id: frame.id, stream, chunk, offset: offset++, recvAtMs: Date.now() })
|
|
94
|
+
: undefined;
|
|
95
|
+
try {
|
|
96
|
+
const exit = await this.tasks.withShellTask(async (shutdown) => {
|
|
97
|
+
const onShutdown = () => entry.controller.abort();
|
|
98
|
+
if (shutdown.aborted)
|
|
99
|
+
onShutdown();
|
|
100
|
+
else
|
|
101
|
+
shutdown.addEventListener('abort', onShutdown, { once: true });
|
|
102
|
+
try {
|
|
103
|
+
return await run(onOutput, entry.controller.signal, (info) => {
|
|
104
|
+
this.send({ t: 'exec_started', id: frame.id, durable: false, ...(info.pid !== undefined ? { pid: info.pid } : {}), startedAtMs: info.startedAtMs });
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
shutdown.removeEventListener('abort', onShutdown);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
this.send(plainExit(exit, entry.cancelled));
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
this.send(plainExit({ t: 'exec_exit', id: frame.id, exitCode: null, stdout: '', stderr: error instanceof Error ? error.message : String(error), timedOut: false, truncated: false }, entry.cancelled));
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
if (this.fallbacks.get(frame.id) === entry)
|
|
118
|
+
this.fallbacks.delete(frame.id);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** Streams `exec` to this channel from `fromOffset` (replacing an older attachment of the same id). */
|
|
122
|
+
attach(id, exec, fromOffset) {
|
|
123
|
+
if (this.closed)
|
|
124
|
+
return;
|
|
125
|
+
this.attachments.get(id)?.stop();
|
|
126
|
+
const attachment = new ExecAttachment(exec, { send: (frame) => this.send(frame), bufferedAmount: () => this.channel.bufferedAmount() }, {
|
|
127
|
+
id, fromOffset, log: this.log,
|
|
128
|
+
exitFrame: (outcome) => wireExitFrame(durableExitFrame(id, outcome), outcome, exec.gapBytes),
|
|
129
|
+
});
|
|
130
|
+
this.attachments.set(id, attachment);
|
|
131
|
+
void attachment.done.finally(() => { if (this.attachments.get(id) === attachment)
|
|
132
|
+
this.attachments.delete(id); });
|
|
133
|
+
}
|
|
134
|
+
/** `exec_attach`: `exec_status` now, then the output from `fromOffset` and, once ended, the final status and the exit. */
|
|
135
|
+
attachFrame(frame) {
|
|
136
|
+
void (async () => {
|
|
137
|
+
if (this.fallbacks.has(frame.id)) { // in this process on this very channel: nothing to re-attach, it is still streaming here
|
|
138
|
+
this.send({ t: 'exec_status', id: frame.id, state: 'running', headOffset: -1, committedOffset: -1 });
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
// It ran in this process for another channel (its exec_started{durable:false} may never have reached the server): `running` /
|
|
142
|
+
// `exited` and, once it ended, its exit — never `unknown`, which would make the server send the request again (Task 26).
|
|
143
|
+
const fallback = this.host.fallbackOf?.(frame.id);
|
|
144
|
+
if (fallback) {
|
|
145
|
+
this.send({ t: 'exec_status', id: frame.id, state: fallback.done ? 'exited' : 'running', headOffset: -1, committedOffset: -1 });
|
|
146
|
+
const exit = await fallback.exit;
|
|
147
|
+
this.send({ t: 'exec_status', id: frame.id, state: 'exited', headOffset: -1, committedOffset: -1 });
|
|
148
|
+
this.send({ ...exit, id: frame.id });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
// `unknown` only when the policy PROVED nobody runs it (the server then gives the exec up, or sends its request again). When
|
|
152
|
+
// keeper-terminal could not be asked (slow after a restart, not answering) the answer waits: asked again until it is decided or
|
|
153
|
+
// this channel closes (the next channel's attach asks anew). The server's own wait limit bounds it.
|
|
154
|
+
let exec;
|
|
155
|
+
while (exec === undefined) {
|
|
156
|
+
try {
|
|
157
|
+
exec = await this.host.find(frame.id);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
if (this.closed)
|
|
161
|
+
return;
|
|
162
|
+
this.log(`exec ${frame.id}: attach deferred: ${error instanceof Error ? error.message : String(error)}`);
|
|
163
|
+
await new Promise((resolve) => setTimeout(resolve, this.options.undecidedRetryMs ?? ATTACH_UNDECIDED_RETRY_MS));
|
|
164
|
+
if (this.closed)
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (!exec) {
|
|
169
|
+
this.send({ t: 'exec_status', id: frame.id, state: 'unknown', headOffset: -1, committedOffset: -1 });
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const status = await exec.wireStatus();
|
|
173
|
+
this.send({ t: 'exec_status', id: frame.id, ...status });
|
|
174
|
+
this.attach(frame.id, exec, frame.fromOffset);
|
|
175
|
+
})().catch((error) => this.log(`exec ${frame.id}: attach failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
176
|
+
}
|
|
177
|
+
ack(frame) { this.host.acknowledge(frame.id, frame.throughOffset); }
|
|
178
|
+
/** `exec_cancel`: idempotent, silent for an unknown or ended exec. */
|
|
179
|
+
cancel(frame) {
|
|
180
|
+
const pending = this.pending.get(frame.id);
|
|
181
|
+
if (pending)
|
|
182
|
+
pending.cancelled = true;
|
|
183
|
+
const fallback = this.fallbacks.get(frame.id);
|
|
184
|
+
if (fallback) {
|
|
185
|
+
fallback.cancelled = true;
|
|
186
|
+
fallback.controller.abort();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
void this.host.cancel(frame.id, frame.signal).catch((error) => this.log(`exec ${frame.id}: cancel failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
190
|
+
}
|
|
191
|
+
/** The channel closed: stop streaming (durable execs keep running for the next channel) and kill this channel's fallback execs. */
|
|
192
|
+
close() {
|
|
193
|
+
this.closed = true;
|
|
194
|
+
for (const attachment of this.attachments.values())
|
|
195
|
+
attachment.stop();
|
|
196
|
+
this.attachments.clear();
|
|
197
|
+
for (const fallback of this.fallbacks.values())
|
|
198
|
+
fallback.controller.abort();
|
|
199
|
+
}
|
|
200
|
+
}
|