@namzu/sdk 32.0.0 → 33.0.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/CHANGELOG.md +127 -0
- package/dist/authorization/gate.d.ts +1 -1
- package/dist/authorization/gate.js +1 -1
- package/dist/connector/index.d.ts +1 -1
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +1 -1
- package/dist/connector/index.js.map +1 -1
- package/dist/connector/mcp/adapter.d.ts.map +1 -1
- package/dist/connector/mcp/adapter.js +71 -16
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +3 -2
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/http-redirect.d.ts +17 -0
- package/dist/connector/mcp/http-redirect.d.ts.map +1 -0
- package/dist/connector/mcp/http-redirect.js +31 -0
- package/dist/connector/mcp/http-redirect.js.map +1 -0
- package/dist/connector/mcp/http-sse.d.ts.map +1 -1
- package/dist/connector/mcp/http-sse.js +5 -0
- package/dist/connector/mcp/http-sse.js.map +1 -1
- package/dist/connector/mcp/image-admission.d.ts +16 -0
- package/dist/connector/mcp/image-admission.d.ts.map +1 -0
- package/dist/connector/mcp/image-admission.js +288 -0
- package/dist/connector/mcp/image-admission.js.map +1 -0
- package/dist/connector/mcp/stdio.d.ts +13 -0
- package/dist/connector/mcp/stdio.d.ts.map +1 -1
- package/dist/connector/mcp/stdio.js +66 -23
- package/dist/connector/mcp/stdio.js.map +1 -1
- package/dist/connector/mcp/streamable-http.d.ts.map +1 -1
- package/dist/connector/mcp/streamable-http.js +3 -0
- package/dist/connector/mcp/streamable-http.js.map +1 -1
- package/dist/constants/tools/index.js +1 -1
- package/dist/constants/tools/index.js.map +1 -1
- package/dist/execution/base.d.ts +13 -0
- package/dist/execution/base.d.ts.map +1 -1
- package/dist/execution/base.js +103 -8
- package/dist/execution/base.js.map +1 -1
- package/dist/execution/errors.d.ts +12 -0
- package/dist/execution/errors.d.ts.map +1 -0
- package/dist/execution/errors.js +21 -0
- package/dist/execution/errors.js.map +1 -0
- package/dist/execution/factory.d.ts.map +1 -1
- package/dist/execution/factory.js +1 -0
- package/dist/execution/factory.js.map +1 -1
- package/dist/execution/hybrid.d.ts +5 -0
- package/dist/execution/hybrid.d.ts.map +1 -1
- package/dist/execution/hybrid.js +36 -16
- package/dist/execution/hybrid.js.map +1 -1
- package/dist/execution/index.d.ts +1 -0
- package/dist/execution/index.d.ts.map +1 -1
- package/dist/execution/index.js +1 -0
- package/dist/execution/index.js.map +1 -1
- package/dist/execution/local.d.ts +13 -0
- package/dist/execution/local.d.ts.map +1 -1
- package/dist/execution/local.js +145 -19
- package/dist/execution/local.js.map +1 -1
- package/dist/execution/output.d.ts +27 -0
- package/dist/execution/output.d.ts.map +1 -0
- package/dist/execution/output.js +105 -0
- package/dist/execution/output.js.map +1 -0
- package/dist/execution/remote.d.ts +26 -2
- package/dist/execution/remote.d.ts.map +1 -1
- package/dist/execution/remote.js +86 -15
- package/dist/execution/remote.js.map +1 -1
- package/dist/plugin/lifecycle.d.ts.map +1 -1
- package/dist/plugin/lifecycle.js +9 -3
- package/dist/plugin/lifecycle.js.map +1 -1
- package/dist/process/kill-tree.d.ts +11 -13
- package/dist/process/kill-tree.d.ts.map +1 -1
- package/dist/process/kill-tree.js +11 -13
- package/dist/process/kill-tree.js.map +1 -1
- package/dist/provider/fallback.d.ts.map +1 -1
- package/dist/provider/fallback.js +31 -0
- package/dist/provider/fallback.js.map +1 -1
- package/dist/provider/idle-timeout.d.ts.map +1 -1
- package/dist/provider/idle-timeout.js +5 -0
- package/dist/provider/idle-timeout.js.map +1 -1
- package/dist/provider/retry.d.ts.map +1 -1
- package/dist/provider/retry.js +5 -0
- package/dist/provider/retry.js.map +1 -1
- package/dist/public-runtime.d.ts +2 -2
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +2 -2
- package/dist/public-runtime.js.map +1 -1
- package/dist/registry/tool/execute.d.ts +7 -1
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js +201 -54
- package/dist/registry/tool/execute.js.map +1 -1
- package/dist/run/command-gate.d.ts.map +1 -1
- package/dist/run/command-gate.js +11 -0
- package/dist/run/command-gate.js.map +1 -1
- package/dist/run/workspace-fingerprint.d.ts +4 -4
- package/dist/run/workspace-fingerprint.d.ts.map +1 -1
- package/dist/run/workspace-fingerprint.js +6 -4
- package/dist/run/workspace-fingerprint.js.map +1 -1
- package/dist/runtime/bidi/index.d.ts +1 -1
- package/dist/runtime/bidi/index.d.ts.map +1 -1
- package/dist/runtime/bidi/index.js +1 -1
- package/dist/runtime/bidi/index.js.map +1 -1
- package/dist/runtime/bidi/session.d.ts +19 -0
- package/dist/runtime/bidi/session.d.ts.map +1 -1
- package/dist/runtime/bidi/session.js +150 -26
- package/dist/runtime/bidi/session.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +43 -1
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +626 -161
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +46 -4
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +84 -22
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/request-rich-content.d.ts.map +1 -1
- package/dist/runtime/query/request-rich-content.js +33 -13
- package/dist/runtime/query/request-rich-content.js.map +1 -1
- package/dist/runtime/query/resume-pending.d.ts +5 -1
- package/dist/runtime/query/resume-pending.d.ts.map +1 -1
- package/dist/runtime/query/resume-pending.js +66 -1
- package/dist/runtime/query/resume-pending.js.map +1 -1
- package/dist/runtime/query/tool-output-budget.d.ts.map +1 -1
- package/dist/runtime/query/tool-output-budget.js +45 -16
- package/dist/runtime/query/tool-output-budget.js.map +1 -1
- package/dist/runtime/query/tooling.d.ts +6 -0
- package/dist/runtime/query/tooling.d.ts.map +1 -1
- package/dist/runtime/query/tooling.js +4 -0
- package/dist/runtime/query/tooling.js.map +1 -1
- package/dist/sandbox/provider/local.d.ts.map +1 -1
- package/dist/sandbox/provider/local.js +193 -41
- package/dist/sandbox/provider/local.js.map +1 -1
- package/dist/scheduler/delegating.d.ts +2 -1
- package/dist/scheduler/delegating.d.ts.map +1 -1
- package/dist/scheduler/delegating.js +6 -5
- package/dist/scheduler/delegating.js.map +1 -1
- package/dist/scheduler/local.d.ts +2 -1
- package/dist/scheduler/local.d.ts.map +1 -1
- package/dist/scheduler/local.js +2 -2
- package/dist/scheduler/local.js.map +1 -1
- package/dist/session/workspace/driver.d.ts +12 -4
- package/dist/session/workspace/driver.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.d.ts +17 -3
- package/dist/session/workspace/git-worktree.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.js +153 -34
- package/dist/session/workspace/git-worktree.js.map +1 -1
- package/dist/skills/registry.d.ts +15 -0
- package/dist/skills/registry.d.ts.map +1 -1
- package/dist/skills/registry.js +33 -0
- package/dist/skills/registry.js.map +1 -1
- package/dist/tools/builtins/computer-use.d.ts.map +1 -1
- package/dist/tools/builtins/computer-use.js +39 -2
- package/dist/tools/builtins/computer-use.js.map +1 -1
- package/dist/tools/builtins/run-code.d.ts.map +1 -1
- package/dist/tools/builtins/run-code.js +9 -11
- package/dist/tools/builtins/run-code.js.map +1 -1
- package/dist/tools/builtins/skill.d.ts +2 -1
- package/dist/tools/builtins/skill.d.ts.map +1 -1
- package/dist/tools/builtins/skill.js +250 -6
- package/dist/tools/builtins/skill.js.map +1 -1
- package/dist/tools/coordinator/agent.d.ts.map +1 -1
- package/dist/tools/coordinator/agent.js +100 -30
- package/dist/tools/coordinator/agent.js.map +1 -1
- package/dist/types/agent/manager.d.ts +1 -1
- package/dist/types/agent/manager.d.ts.map +1 -1
- package/dist/types/agent/scheduler.d.ts +10 -1
- package/dist/types/agent/scheduler.d.ts.map +1 -1
- package/dist/types/authorization/index.d.ts +12 -12
- package/dist/types/bidi/index.d.ts +19 -2
- package/dist/types/bidi/index.d.ts.map +1 -1
- package/dist/types/computer-use/index.d.ts +18 -0
- package/dist/types/computer-use/index.d.ts.map +1 -1
- package/dist/types/connector/execution-context.d.ts +3 -1
- package/dist/types/connector/execution-context.d.ts.map +1 -1
- package/dist/types/execution/index.d.ts +43 -1
- package/dist/types/execution/index.d.ts.map +1 -1
- package/dist/types/hitl/index.d.ts +11 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/message/index.d.ts +1 -1
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +2 -1
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/plugin/index.d.ts +14 -1
- package/dist/types/plugin/index.d.ts.map +1 -1
- package/dist/types/plugin/index.js +1 -0
- package/dist/types/plugin/index.js.map +1 -1
- package/dist/types/provider/interface.d.ts +14 -0
- package/dist/types/provider/interface.d.ts.map +1 -1
- package/dist/types/sandbox/index.d.ts +15 -10
- package/dist/types/sandbox/index.d.ts.map +1 -1
- package/dist/types/sandbox/index.js.map +1 -1
- package/dist/types/tool/index.d.ts +77 -6
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/tool/index.js.map +1 -1
- package/dist/types/workspace/ref.d.ts +5 -0
- package/dist/types/workspace/ref.d.ts.map +1 -1
- package/dist/utils/abort.d.ts +8 -0
- package/dist/utils/abort.d.ts.map +1 -1
- package/dist/utils/abort.js +16 -0
- package/dist/utils/abort.js.map +1 -1
- package/package.json +4 -4
- package/src/authorization/gate.ts +1 -1
- package/src/connector/index.ts +2 -0
- package/src/connector/mcp/adapter.ts +82 -21
- package/src/connector/mcp/client.ts +2 -1
- package/src/connector/mcp/http-redirect.ts +32 -0
- package/src/connector/mcp/http-sse.ts +5 -0
- package/src/connector/mcp/image-admission.ts +272 -0
- package/src/connector/mcp/stdio.ts +63 -21
- package/src/connector/mcp/streamable-http.ts +3 -0
- package/src/constants/tools/index.ts +1 -1
- package/src/execution/base.ts +124 -7
- package/src/execution/errors.ts +24 -0
- package/src/execution/factory.ts +1 -0
- package/src/execution/hybrid.ts +47 -16
- package/src/execution/index.ts +1 -0
- package/src/execution/local.ts +164 -19
- package/src/execution/output.ts +104 -0
- package/src/execution/remote.ts +122 -17
- package/src/plugin/lifecycle.ts +9 -3
- package/src/process/kill-tree.ts +11 -13
- package/src/provider/fallback.ts +39 -0
- package/src/provider/idle-timeout.ts +8 -0
- package/src/provider/retry.ts +8 -0
- package/src/public-runtime.ts +7 -1
- package/src/registry/tool/execute.ts +230 -64
- package/src/run/command-gate.ts +12 -0
- package/src/run/workspace-fingerprint.ts +5 -4
- package/src/runtime/bidi/index.ts +1 -1
- package/src/runtime/bidi/session.ts +177 -28
- package/src/runtime/query/executor.ts +769 -163
- package/src/runtime/query/index.ts +53 -6
- package/src/runtime/query/iteration/phases/tool-review.ts +87 -23
- package/src/runtime/query/request-rich-content.ts +39 -14
- package/src/runtime/query/resume-pending.ts +83 -1
- package/src/runtime/query/tool-output-budget.ts +52 -17
- package/src/runtime/query/tooling.ts +10 -0
- package/src/sandbox/provider/local.ts +213 -45
- package/src/scheduler/delegating.ts +6 -5
- package/src/scheduler/local.ts +3 -2
- package/src/session/workspace/driver.ts +12 -4
- package/src/session/workspace/git-worktree.ts +173 -34
- package/src/skills/registry.ts +47 -0
- package/src/tools/builtins/computer-use.ts +45 -2
- package/src/tools/builtins/run-code.ts +9 -11
- package/src/tools/builtins/skill.ts +325 -7
- package/src/tools/coordinator/agent.ts +108 -33
- package/src/types/agent/manager.ts +1 -1
- package/src/types/agent/scheduler.ts +10 -1
- package/src/types/bidi/index.ts +19 -2
- package/src/types/computer-use/index.ts +19 -0
- package/src/types/connector/execution-context.ts +3 -0
- package/src/types/execution/index.ts +46 -1
- package/src/types/hitl/index.ts +11 -0
- package/src/types/message/index.ts +3 -2
- package/src/types/plugin/index.ts +15 -0
- package/src/types/provider/interface.ts +18 -0
- package/src/types/sandbox/index.ts +15 -10
- package/src/types/tool/index.ts +85 -6
- package/src/types/workspace/ref.ts +5 -0
- package/src/utils/abort.ts +18 -0
package/dist/execution/local.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
|
+
import { killTree } from '../process/kill-tree.js';
|
|
5
|
+
import { subscribeToAbort } from '../utils/abort.js';
|
|
4
6
|
import { BaseExecutionContext } from './base.js';
|
|
7
|
+
import { BoundedTailCapture } from './output.js';
|
|
8
|
+
const LOCAL_COMMAND_DEFAULT_TIMEOUT_MS = 30_000;
|
|
9
|
+
const LOCAL_COMMAND_KILL_GRACE_MS = 3_000;
|
|
10
|
+
const LOCAL_COMMAND_DEFAULT_MAX_OUTPUT_BYTES = 4 * 1024 * 1024;
|
|
11
|
+
const LOCAL_COMMAND_HARD_MAX_OUTPUT_BYTES = 64 * 1024 * 1024;
|
|
5
12
|
export class LocalExecutionContext extends BaseExecutionContext {
|
|
6
13
|
id;
|
|
7
14
|
environment = 'local';
|
|
@@ -10,6 +17,14 @@ export class LocalExecutionContext extends BaseExecutionContext {
|
|
|
10
17
|
envVars;
|
|
11
18
|
capabilities;
|
|
12
19
|
shell;
|
|
20
|
+
maxOutputBytes;
|
|
21
|
+
/**
|
|
22
|
+
* Constructor-created contexts are intentionally executable before
|
|
23
|
+
* `initialize()`: `createCommandGate()` has always used that public path.
|
|
24
|
+
* Teardown closes admission synchronously; an explicit initialize reopens it.
|
|
25
|
+
*/
|
|
26
|
+
acceptsCommands = true;
|
|
27
|
+
activeCommands = new Set();
|
|
13
28
|
constructor(options) {
|
|
14
29
|
super(options.log);
|
|
15
30
|
this.id = options.id;
|
|
@@ -18,6 +33,13 @@ export class LocalExecutionContext extends BaseExecutionContext {
|
|
|
18
33
|
this.envVars = options.envVars ?? {};
|
|
19
34
|
this.capabilities = options.capabilities ?? ['filesystem', 'process', 'shell'];
|
|
20
35
|
this.shell = options.shell;
|
|
36
|
+
const maxOutputBytes = options.maxOutputBytes ?? LOCAL_COMMAND_DEFAULT_MAX_OUTPUT_BYTES;
|
|
37
|
+
if (!Number.isSafeInteger(maxOutputBytes) ||
|
|
38
|
+
maxOutputBytes <= 0 ||
|
|
39
|
+
maxOutputBytes > LOCAL_COMMAND_HARD_MAX_OUTPUT_BYTES) {
|
|
40
|
+
throw new RangeError(`The value of "maxOutputBytes" is out of range. It must be a positive safe integer no greater than ${LOCAL_COMMAND_HARD_MAX_OUTPUT_BYTES}. Received ${maxOutputBytes}`);
|
|
41
|
+
}
|
|
42
|
+
this.maxOutputBytes = maxOutputBytes;
|
|
21
43
|
}
|
|
22
44
|
async doInitialize() {
|
|
23
45
|
if (!existsSync(this.cwd)) {
|
|
@@ -25,7 +47,21 @@ export class LocalExecutionContext extends BaseExecutionContext {
|
|
|
25
47
|
}
|
|
26
48
|
this.log.info('Local context initialized', { 'namzu.execution.cwd': this.cwd });
|
|
27
49
|
}
|
|
28
|
-
|
|
50
|
+
onInitializationStarted() {
|
|
51
|
+
this.acceptsCommands = false;
|
|
52
|
+
}
|
|
53
|
+
onInitializationCommitted() {
|
|
54
|
+
this.acceptsCommands = true;
|
|
55
|
+
}
|
|
56
|
+
onTeardownRequested() {
|
|
57
|
+
this.acceptsCommands = false;
|
|
58
|
+
}
|
|
59
|
+
async doTeardown() {
|
|
60
|
+
const admitted = [...this.activeCommands];
|
|
61
|
+
for (const operation of admitted)
|
|
62
|
+
operation.cancel('teardown');
|
|
63
|
+
await Promise.all(admitted.map((operation) => operation.closed));
|
|
64
|
+
}
|
|
29
65
|
getCwd() {
|
|
30
66
|
return this.cwd;
|
|
31
67
|
}
|
|
@@ -55,56 +91,145 @@ export class LocalExecutionContext extends BaseExecutionContext {
|
|
|
55
91
|
return this.capabilities.includes(cap);
|
|
56
92
|
}
|
|
57
93
|
async executeCommand(command, args = [], options) {
|
|
94
|
+
if (!this.acceptsCommands) {
|
|
95
|
+
throw new Error(`Local execution context "${this.id}" is tearing down or torn down. Call initialize() before executing another command.`);
|
|
96
|
+
}
|
|
58
97
|
if (!this.hasCapability('process') && !this.hasCapability('shell')) {
|
|
59
98
|
return {
|
|
60
99
|
exitCode: 1,
|
|
61
100
|
stdout: '',
|
|
62
101
|
stderr: 'Command execution not available: context lacks process/shell capability',
|
|
102
|
+
stdoutTruncated: false,
|
|
103
|
+
stderrTruncated: false,
|
|
63
104
|
durationMs: 0,
|
|
64
105
|
};
|
|
65
106
|
}
|
|
66
107
|
const cwd = options?.cwd ? resolve(this.cwd, options.cwd) : this.cwd;
|
|
67
108
|
const env = { ...process.env, ...this.envVars, ...options?.env };
|
|
68
|
-
const timeoutMs = options?.timeoutMs ??
|
|
109
|
+
const timeoutMs = options?.timeoutMs ?? LOCAL_COMMAND_DEFAULT_TIMEOUT_MS;
|
|
110
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs < 0) {
|
|
111
|
+
throw new RangeError(`The value of "timeoutMs" is out of range. It must be an unsigned integer. Received ${timeoutMs}`);
|
|
112
|
+
}
|
|
69
113
|
// node's spawn() only keeps argv separation when it execs the binary directly;
|
|
70
114
|
// with shell enabled it re-joins command+args into one unescaped string and hands
|
|
71
115
|
// it to sh/cmd.exe, so any caller-supplied arg becomes shell syntax rather than a
|
|
72
116
|
// literal value. Since `command`/`args` here are whatever a tool call passed in,
|
|
73
117
|
// shell interpretation must be an explicit opt-in, never the silent default.
|
|
74
118
|
const shell = options?.shell ?? this.shell ?? false;
|
|
75
|
-
|
|
119
|
+
const callerSignal = options?.signal;
|
|
120
|
+
if (callerSignal?.aborted) {
|
|
121
|
+
return {
|
|
122
|
+
exitCode: null,
|
|
123
|
+
stdout: '',
|
|
124
|
+
stderr: '',
|
|
125
|
+
stdoutTruncated: false,
|
|
126
|
+
stderrTruncated: false,
|
|
127
|
+
durationMs: 0,
|
|
128
|
+
termination: { origin: 'caller', admitted: false },
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
let operation;
|
|
132
|
+
const result = new Promise((resolvePromise) => {
|
|
76
133
|
const start = performance.now();
|
|
77
134
|
const proc = spawn(command, args, {
|
|
78
135
|
cwd,
|
|
79
136
|
env,
|
|
80
137
|
shell,
|
|
81
|
-
|
|
138
|
+
// POSIX process-group ownership is the strongest boundary available
|
|
139
|
+
// to this host execution context. Windows uses taskkill /T in
|
|
140
|
+
// `killTree`; neither path relies on Node's direct-child timeout.
|
|
141
|
+
detached: process.platform !== 'win32',
|
|
82
142
|
});
|
|
83
|
-
|
|
84
|
-
|
|
143
|
+
const stdout = new BoundedTailCapture(this.maxOutputBytes);
|
|
144
|
+
const stderr = new BoundedTailCapture(this.maxOutputBytes);
|
|
145
|
+
let spawnError;
|
|
146
|
+
let cancellation;
|
|
147
|
+
let escalation;
|
|
148
|
+
let deadline;
|
|
149
|
+
let disposeCallerAbort;
|
|
150
|
+
let settled = false;
|
|
151
|
+
const terminate = (signal) => {
|
|
152
|
+
killTree(proc, signal);
|
|
153
|
+
};
|
|
154
|
+
const cancel = (origin) => {
|
|
155
|
+
if (settled || cancellation !== undefined)
|
|
156
|
+
return;
|
|
157
|
+
cancellation = origin;
|
|
158
|
+
terminate('SIGTERM');
|
|
159
|
+
escalation = setTimeout(() => {
|
|
160
|
+
escalation = undefined;
|
|
161
|
+
terminate('SIGKILL');
|
|
162
|
+
}, LOCAL_COMMAND_KILL_GRACE_MS);
|
|
163
|
+
escalation.unref?.();
|
|
164
|
+
};
|
|
165
|
+
let resolveClosed;
|
|
166
|
+
const closed = new Promise((resolveClose) => {
|
|
167
|
+
resolveClosed = resolveClose;
|
|
168
|
+
});
|
|
169
|
+
operation = { cancel, closed };
|
|
170
|
+
this.activeCommands.add(operation);
|
|
171
|
+
if (timeoutMs > 0) {
|
|
172
|
+
deadline = setTimeout(() => cancel('deadline'), timeoutMs);
|
|
173
|
+
deadline.unref?.();
|
|
174
|
+
}
|
|
85
175
|
proc.stdout?.on('data', (data) => {
|
|
86
|
-
stdout
|
|
176
|
+
stdout.push(data);
|
|
87
177
|
});
|
|
88
178
|
proc.stderr?.on('data', (data) => {
|
|
89
|
-
stderr
|
|
179
|
+
stderr.push(data);
|
|
90
180
|
});
|
|
91
|
-
proc.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
durationMs: Math.round(performance.now() - start),
|
|
97
|
-
});
|
|
181
|
+
proc.once('error', (err) => {
|
|
182
|
+
// `close` follows `error` and is the point at which inherited stdio
|
|
183
|
+
// has drained. Releasing ownership here would strand a descendant
|
|
184
|
+
// which still holds those descriptors.
|
|
185
|
+
spawnError = err;
|
|
98
186
|
});
|
|
99
|
-
proc.
|
|
187
|
+
proc.once('close', (code, signal) => {
|
|
188
|
+
if (settled)
|
|
189
|
+
return;
|
|
190
|
+
settled = true;
|
|
191
|
+
disposeCallerAbort?.();
|
|
192
|
+
if (deadline !== undefined)
|
|
193
|
+
clearTimeout(deadline);
|
|
194
|
+
if (escalation !== undefined) {
|
|
195
|
+
clearTimeout(escalation);
|
|
196
|
+
escalation = undefined;
|
|
197
|
+
// Do not retain a numeric process-group id for a later timer after
|
|
198
|
+
// close: the host can reuse it. Force the cancellation boundary now.
|
|
199
|
+
terminate('SIGKILL');
|
|
200
|
+
}
|
|
201
|
+
this.activeCommands.delete(operation);
|
|
202
|
+
resolveClosed?.();
|
|
203
|
+
if (spawnError !== undefined) {
|
|
204
|
+
if (stderr.retainedBytes > 0)
|
|
205
|
+
stderr.push(Buffer.from('\n'));
|
|
206
|
+
stderr.push(Buffer.from(spawnError.message));
|
|
207
|
+
}
|
|
100
208
|
resolvePromise({
|
|
101
|
-
exitCode: 1,
|
|
102
|
-
stdout,
|
|
103
|
-
stderr:
|
|
209
|
+
exitCode: spawnError === undefined ? code : 1,
|
|
210
|
+
stdout: stdout.text,
|
|
211
|
+
stderr: stderr.text,
|
|
212
|
+
stdoutTruncated: stdout.truncated,
|
|
213
|
+
stderrTruncated: stderr.truncated,
|
|
104
214
|
durationMs: Math.round(performance.now() - start),
|
|
215
|
+
...(cancellation === undefined
|
|
216
|
+
? {}
|
|
217
|
+
: {
|
|
218
|
+
termination: {
|
|
219
|
+
origin: cancellation === 'deadline' ? 'timeout' : cancellation,
|
|
220
|
+
admitted: true,
|
|
221
|
+
...(signal === null ? {} : { signal }),
|
|
222
|
+
},
|
|
223
|
+
}),
|
|
105
224
|
});
|
|
106
225
|
});
|
|
226
|
+
if (callerSignal !== undefined) {
|
|
227
|
+
disposeCallerAbort = subscribeToAbort(callerSignal, () => cancel('caller'));
|
|
228
|
+
if (callerSignal.aborted)
|
|
229
|
+
cancel('caller');
|
|
230
|
+
}
|
|
107
231
|
});
|
|
232
|
+
return result;
|
|
108
233
|
}
|
|
109
234
|
toConfig() {
|
|
110
235
|
return {
|
|
@@ -115,6 +240,7 @@ export class LocalExecutionContext extends BaseExecutionContext {
|
|
|
115
240
|
envVars: this.envVars,
|
|
116
241
|
capabilities: this.capabilities,
|
|
117
242
|
shell: this.shell,
|
|
243
|
+
maxOutputBytes: this.maxOutputBytes,
|
|
118
244
|
};
|
|
119
245
|
}
|
|
120
246
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../src/execution/local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../src/execution/local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,M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YAC3C,CAAC;QACF,CAAC,CAAC,CAAA;QACF,OAAO,MAAM,CAAA;IACd,CAAC;IAED,QAAQ;QACP,OAAO;YACN,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,WAAW,EAAE,OAAO;YACpB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,cAAc,EAAE,IAAI,CAAC,cAAc;SACnC,CAAA;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retain the newest bytes of one command-output stream under a hard bound.
|
|
3
|
+
*
|
|
4
|
+
* Bytes stay undecoded until the command closes, so a UTF-8 code point split
|
|
5
|
+
* across ordinary stream chunks is not corrupted. The backing store grows
|
|
6
|
+
* geometrically up to the configured cap and becomes a ring only when output
|
|
7
|
+
* crosses it; no incoming chunk is retained by reference.
|
|
8
|
+
*/
|
|
9
|
+
export declare class BoundedTailCapture {
|
|
10
|
+
private readonly capBytes;
|
|
11
|
+
private storage;
|
|
12
|
+
private start;
|
|
13
|
+
private length;
|
|
14
|
+
private lostBytes;
|
|
15
|
+
constructor(capBytes: number);
|
|
16
|
+
push(chunk: Buffer): void;
|
|
17
|
+
/** Ordered copy of the retained raw bytes. */
|
|
18
|
+
get bytes(): Buffer;
|
|
19
|
+
get text(): string;
|
|
20
|
+
get truncated(): boolean;
|
|
21
|
+
/** Diagnostic invariant used by the internal killing observers. */
|
|
22
|
+
get retainedBytes(): number;
|
|
23
|
+
/** Diagnostic invariant used by the internal killing observers. */
|
|
24
|
+
get allocatedBytes(): number;
|
|
25
|
+
private ensureCapacity;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/execution/output.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,kBAAkB;IAMlB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IALrC,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,KAAK,CAAI;IACjB,OAAO,CAAC,MAAM,CAAI;IAClB,OAAO,CAAC,SAAS,CAAQ;gBAEI,QAAQ,EAAE,MAAM;IAM7C,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IA8BzB,8CAA8C;IAC9C,IAAI,KAAK,IAAI,MAAM,CAOlB;IAED,IAAI,IAAI,IAAI,MAAM,CAcjB;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,mEAAmE;IACnE,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED,mEAAmE;IACnE,IAAI,cAAc,IAAI,MAAM,CAE3B;IAED,OAAO,CAAC,cAAc;CAatB"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retain the newest bytes of one command-output stream under a hard bound.
|
|
3
|
+
*
|
|
4
|
+
* Bytes stay undecoded until the command closes, so a UTF-8 code point split
|
|
5
|
+
* across ordinary stream chunks is not corrupted. The backing store grows
|
|
6
|
+
* geometrically up to the configured cap and becomes a ring only when output
|
|
7
|
+
* crosses it; no incoming chunk is retained by reference.
|
|
8
|
+
*/
|
|
9
|
+
export class BoundedTailCapture {
|
|
10
|
+
capBytes;
|
|
11
|
+
storage = Buffer.alloc(0);
|
|
12
|
+
start = 0;
|
|
13
|
+
length = 0;
|
|
14
|
+
lostBytes = false;
|
|
15
|
+
constructor(capBytes) {
|
|
16
|
+
this.capBytes = capBytes;
|
|
17
|
+
if (!Number.isSafeInteger(capBytes) || capBytes <= 0) {
|
|
18
|
+
throw new RangeError('BoundedTailCapture capBytes must be a positive safe integer');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
push(chunk) {
|
|
22
|
+
if (chunk.length === 0)
|
|
23
|
+
return;
|
|
24
|
+
if (chunk.length >= this.capBytes) {
|
|
25
|
+
if (chunk.length > this.capBytes || this.length > 0)
|
|
26
|
+
this.lostBytes = true;
|
|
27
|
+
this.ensureCapacity(this.capBytes);
|
|
28
|
+
chunk.copy(this.storage, 0, chunk.length - this.capBytes);
|
|
29
|
+
this.start = 0;
|
|
30
|
+
this.length = this.capBytes;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const combinedLength = this.length + chunk.length;
|
|
34
|
+
if (combinedLength <= this.capBytes) {
|
|
35
|
+
this.ensureCapacity(combinedLength);
|
|
36
|
+
chunk.copy(this.storage, this.length);
|
|
37
|
+
this.length = combinedLength;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.lostBytes = true;
|
|
41
|
+
this.ensureCapacity(this.capBytes);
|
|
42
|
+
const end = (this.start + this.length) % this.capBytes;
|
|
43
|
+
const first = Math.min(chunk.length, this.capBytes - end);
|
|
44
|
+
chunk.copy(this.storage, end, 0, first);
|
|
45
|
+
if (first < chunk.length)
|
|
46
|
+
chunk.copy(this.storage, 0, first);
|
|
47
|
+
this.start = (this.start + combinedLength - this.capBytes) % this.capBytes;
|
|
48
|
+
this.length = this.capBytes;
|
|
49
|
+
}
|
|
50
|
+
/** Ordered copy of the retained raw bytes. */
|
|
51
|
+
get bytes() {
|
|
52
|
+
const ordered = Buffer.allocUnsafe(this.length);
|
|
53
|
+
if (this.length === 0)
|
|
54
|
+
return ordered;
|
|
55
|
+
const first = Math.min(this.length, this.storage.length - this.start);
|
|
56
|
+
this.storage.copy(ordered, 0, this.start, this.start + first);
|
|
57
|
+
if (first < this.length)
|
|
58
|
+
this.storage.copy(ordered, first, 0, this.length - first);
|
|
59
|
+
return ordered;
|
|
60
|
+
}
|
|
61
|
+
get text() {
|
|
62
|
+
const ordered = this.bytes;
|
|
63
|
+
let offset = 0;
|
|
64
|
+
// Tail eviction can leave continuation bytes from a valid UTF-8 code
|
|
65
|
+
// point at the new left edge. They are an artifact of the cut, not an
|
|
66
|
+
// authored replacement character, so discard only that partial prefix.
|
|
67
|
+
if (this.lostBytes) {
|
|
68
|
+
while (offset < ordered.length) {
|
|
69
|
+
const firstByte = ordered[offset];
|
|
70
|
+
if (firstByte === undefined || (firstByte & 0xc0) !== 0x80)
|
|
71
|
+
break;
|
|
72
|
+
offset++;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return ordered.toString('utf8', offset);
|
|
76
|
+
}
|
|
77
|
+
get truncated() {
|
|
78
|
+
return this.lostBytes;
|
|
79
|
+
}
|
|
80
|
+
/** Diagnostic invariant used by the internal killing observers. */
|
|
81
|
+
get retainedBytes() {
|
|
82
|
+
return this.length;
|
|
83
|
+
}
|
|
84
|
+
/** Diagnostic invariant used by the internal killing observers. */
|
|
85
|
+
get allocatedBytes() {
|
|
86
|
+
return this.storage.length;
|
|
87
|
+
}
|
|
88
|
+
ensureCapacity(required) {
|
|
89
|
+
if (this.storage.length >= required)
|
|
90
|
+
return;
|
|
91
|
+
let capacity = Math.max(1, this.storage.length);
|
|
92
|
+
while (capacity < required)
|
|
93
|
+
capacity = Math.min(this.capBytes, capacity * 2);
|
|
94
|
+
const grown = Buffer.allocUnsafe(capacity);
|
|
95
|
+
if (this.length > 0) {
|
|
96
|
+
const first = Math.min(this.length, this.storage.length - this.start);
|
|
97
|
+
this.storage.copy(grown, 0, this.start, this.start + first);
|
|
98
|
+
if (first < this.length)
|
|
99
|
+
this.storage.copy(grown, first, 0, this.length - first);
|
|
100
|
+
}
|
|
101
|
+
this.storage = grown;
|
|
102
|
+
this.start = 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/execution/output.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,OAAO,kBAAkB;IAMD;IALrB,OAAO,GAAG,MAAM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,EAAE,QAAQ,GAAG,CAAC,CAAC,CAAA;QAC5E,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;QAC1C,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;YACrE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,CAAA;YAC3D,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM;gBAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,CAAA;QACjF,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;IACf,CAAC;CACD"}
|
|
@@ -1,22 +1,35 @@
|
|
|
1
|
-
import type { CommandOptions, CommandResult, ExecutionCapability, ExecutionEnvironment, RemoteCommandHandler, RemoteExecutionContextConfig, RemoteTarget } from '../types/connector/index.js';
|
|
1
|
+
import type { CommandExecutor, CommandOptions, CommandResult, ExecutionCapability, ExecutionEnvironment, RemoteCommandHandler, RemoteExecutionContextConfig, RemoteTarget } from '../types/connector/index.js';
|
|
2
2
|
import type { Logger } from '../utils/logger.js';
|
|
3
3
|
import { BaseExecutionContext } from './base.js';
|
|
4
4
|
export interface RemoteExecutionContextOptions {
|
|
5
5
|
id: string;
|
|
6
6
|
target: RemoteTarget;
|
|
7
7
|
capabilities?: ExecutionCapability[];
|
|
8
|
+
/**
|
|
9
|
+
* Executes a command while preserving its argument boundaries at Namzu's
|
|
10
|
+
* remote seam. A downstream executor may still interpret `shell` according
|
|
11
|
+
* to its own target.
|
|
12
|
+
*/
|
|
13
|
+
commandExecutor?: CommandExecutor;
|
|
14
|
+
/** @deprecated Use `commandExecutor`. */
|
|
8
15
|
commandHandler?: RemoteCommandHandler;
|
|
9
16
|
log?: Logger;
|
|
10
17
|
}
|
|
11
|
-
export declare class RemoteExecutionContext extends BaseExecutionContext {
|
|
18
|
+
export declare class RemoteExecutionContext extends BaseExecutionContext implements CommandExecutor {
|
|
12
19
|
readonly id: string;
|
|
13
20
|
readonly environment: ExecutionEnvironment;
|
|
14
21
|
private target;
|
|
15
22
|
private connected;
|
|
16
23
|
private capabilities;
|
|
24
|
+
private commandExecutor;
|
|
17
25
|
private commandHandler;
|
|
26
|
+
private lifecycleAdmissionsOpen;
|
|
27
|
+
private readonly activeCommands;
|
|
18
28
|
constructor(options: RemoteExecutionContextOptions);
|
|
19
29
|
protected doInitialize(): Promise<void>;
|
|
30
|
+
protected onInitializationStarted(): void;
|
|
31
|
+
protected onInitializationCommitted(): void;
|
|
32
|
+
protected onTeardownRequested(): void;
|
|
20
33
|
protected doTeardown(): Promise<void>;
|
|
21
34
|
connect(): Promise<void>;
|
|
22
35
|
disconnect(): Promise<void>;
|
|
@@ -25,9 +38,20 @@ export declare class RemoteExecutionContext extends BaseExecutionContext {
|
|
|
25
38
|
getConnectionString(): string;
|
|
26
39
|
getCapabilities(): ExecutionCapability[];
|
|
27
40
|
hasCapability(cap: ExecutionCapability): boolean;
|
|
41
|
+
setCommandExecutor(executor: CommandExecutor): void;
|
|
42
|
+
/** @deprecated Use `setCommandExecutor()`. */
|
|
28
43
|
setCommandHandler(handler: RemoteCommandHandler): void;
|
|
44
|
+
executeCommand(command: string, args?: string[], options?: CommandOptions): Promise<CommandResult>;
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Use `executeCommand()` so command arguments retain their
|
|
47
|
+
* boundaries at Namzu's remote execution seam.
|
|
48
|
+
*/
|
|
29
49
|
executeRemote(command: string, options?: CommandOptions): Promise<CommandResult>;
|
|
30
50
|
toConfig(): RemoteExecutionContextConfig;
|
|
31
51
|
private validateTarget;
|
|
52
|
+
private admitCommand;
|
|
53
|
+
private assertCancellationUnsupported;
|
|
54
|
+
private assertIdleForDisconnect;
|
|
55
|
+
private trackCommand;
|
|
32
56
|
}
|
|
33
57
|
//# sourceMappingURL=remote.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/execution/remote.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,YAAY,EACZ,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/execution/remote.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,eAAe,EACf,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,4BAA4B,EAC5B,YAAY,EACZ,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAGhD,MAAM,WAAW,6BAA6B;IAC7C,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,YAAY,CAAA;IACpB,YAAY,CAAC,EAAE,mBAAmB,EAAE,CAAA;IACpC;;;;OAIG;IACH,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,yCAAyC;IACzC,cAAc,CAAC,EAAE,oBAAoB,CAAA;IACrC,GAAG,CAAC,EAAE,MAAM,CAAA;CACZ;AAED,qBAAa,sBAAuB,SAAQ,oBAAqB,YAAW,eAAe;I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B;IAIrC,OAAO,CAAC,uBAAuB;IAM/B,OAAO,CAAC,YAAY;CA0BpB"}
|
package/dist/execution/remote.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { BaseExecutionContext } from './base.js';
|
|
2
|
+
import { CommandCancellationUnsupportedError, RemoteExecutionBusyError } from './errors.js';
|
|
2
3
|
export class RemoteExecutionContext extends BaseExecutionContext {
|
|
3
4
|
id;
|
|
4
5
|
environment = 'remote';
|
|
5
6
|
target;
|
|
6
7
|
connected = false;
|
|
7
8
|
capabilities;
|
|
9
|
+
commandExecutor;
|
|
8
10
|
commandHandler;
|
|
11
|
+
lifecycleAdmissionsOpen = true;
|
|
12
|
+
activeCommands = new Set();
|
|
9
13
|
constructor(options) {
|
|
10
14
|
super(options.log);
|
|
11
15
|
this.id = options.id;
|
|
12
16
|
this.target = options.target;
|
|
13
17
|
this.capabilities = options.capabilities ?? ['network'];
|
|
18
|
+
this.commandExecutor = options.commandExecutor;
|
|
14
19
|
this.commandHandler = options.commandHandler;
|
|
15
20
|
}
|
|
16
21
|
async doInitialize() {
|
|
@@ -20,17 +25,25 @@ export class RemoteExecutionContext extends BaseExecutionContext {
|
|
|
20
25
|
'namzu.execution.target_host': this.target.host,
|
|
21
26
|
});
|
|
22
27
|
}
|
|
28
|
+
onInitializationStarted() {
|
|
29
|
+
this.lifecycleAdmissionsOpen = false;
|
|
30
|
+
}
|
|
31
|
+
onInitializationCommitted() {
|
|
32
|
+
this.lifecycleAdmissionsOpen = true;
|
|
33
|
+
}
|
|
34
|
+
onTeardownRequested() {
|
|
35
|
+
this.lifecycleAdmissionsOpen = false;
|
|
36
|
+
}
|
|
23
37
|
async doTeardown() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this.emit({
|
|
27
|
-
type: 'remote_disconnected',
|
|
28
|
-
contextId: this.id,
|
|
29
|
-
host: this.target.host,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
38
|
+
this.assertIdleForDisconnect();
|
|
39
|
+
await this.disconnect();
|
|
32
40
|
}
|
|
33
41
|
async connect() {
|
|
42
|
+
if (!this.lifecycleAdmissionsOpen) {
|
|
43
|
+
throw new Error(`Remote execution context "${this.id}" cannot connect until initialization commits after teardown or failed initialization.`);
|
|
44
|
+
}
|
|
45
|
+
if (this.connected)
|
|
46
|
+
return;
|
|
34
47
|
this.connected = true;
|
|
35
48
|
this.emit({
|
|
36
49
|
type: 'remote_connected',
|
|
@@ -46,6 +59,7 @@ export class RemoteExecutionContext extends BaseExecutionContext {
|
|
|
46
59
|
async disconnect() {
|
|
47
60
|
if (!this.connected)
|
|
48
61
|
return;
|
|
62
|
+
this.assertIdleForDisconnect();
|
|
49
63
|
this.connected = false;
|
|
50
64
|
this.emit({
|
|
51
65
|
type: 'remote_disconnected',
|
|
@@ -70,17 +84,32 @@ export class RemoteExecutionContext extends BaseExecutionContext {
|
|
|
70
84
|
hasCapability(cap) {
|
|
71
85
|
return this.capabilities.includes(cap);
|
|
72
86
|
}
|
|
87
|
+
setCommandExecutor(executor) {
|
|
88
|
+
this.commandExecutor = executor;
|
|
89
|
+
}
|
|
90
|
+
/** @deprecated Use `setCommandExecutor()`. */
|
|
73
91
|
setCommandHandler(handler) {
|
|
74
92
|
this.commandHandler = handler;
|
|
75
93
|
}
|
|
76
|
-
async
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
throw new Error(`Remote context "${this.id}" is not connected. Call connect() first.`);
|
|
94
|
+
async executeCommand(command, args = [], options) {
|
|
95
|
+
if (this.commandExecutor) {
|
|
96
|
+
const executor = this.admitCommand(this.commandExecutor, `No remote command executor configured for context "${this.id}". Set one via setCommandExecutor() before calling executeCommand().`);
|
|
97
|
+
this.assertCancellationUnsupported(options?.signal);
|
|
98
|
+
return this.trackCommand(() => executor.executeCommand(command, args, options));
|
|
82
99
|
}
|
|
83
|
-
|
|
100
|
+
const handler = this.admitCommand(this.commandHandler, `No remote command executor configured for context "${this.id}". Set one via setCommandExecutor() before calling executeCommand().`);
|
|
101
|
+
this.assertCancellationUnsupported(options?.signal);
|
|
102
|
+
const fullCommand = args.length > 0 ? `${command} ${args.join(' ')}` : command;
|
|
103
|
+
return this.trackCommand(() => handler.executeRemote(fullCommand, options));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated Use `executeCommand()` so command arguments retain their
|
|
107
|
+
* boundaries at Namzu's remote execution seam.
|
|
108
|
+
*/
|
|
109
|
+
async executeRemote(command, options) {
|
|
110
|
+
const handler = this.admitCommand(this.commandHandler, `No remote command handler configured for context "${this.id}". Set one via setCommandHandler() before calling executeRemote().`);
|
|
111
|
+
this.assertCancellationUnsupported(options?.signal);
|
|
112
|
+
return this.trackCommand(() => handler.executeRemote(command, options));
|
|
84
113
|
}
|
|
85
114
|
toConfig() {
|
|
86
115
|
return {
|
|
@@ -98,5 +127,47 @@ export class RemoteExecutionContext extends BaseExecutionContext {
|
|
|
98
127
|
throw new Error(`Unsupported remote target type: "${target.type}"`);
|
|
99
128
|
}
|
|
100
129
|
}
|
|
130
|
+
admitCommand(implementation, missingMessage) {
|
|
131
|
+
if (implementation === undefined)
|
|
132
|
+
throw new Error(missingMessage);
|
|
133
|
+
if (!this.lifecycleAdmissionsOpen) {
|
|
134
|
+
throw new Error(`Remote execution context "${this.id}" is initializing, tearing down, or torn down. Wait for initialization to commit before executing another command.`);
|
|
135
|
+
}
|
|
136
|
+
if (!this.connected) {
|
|
137
|
+
throw new Error(`Remote context "${this.id}" is not connected. Call connect() first.`);
|
|
138
|
+
}
|
|
139
|
+
return implementation;
|
|
140
|
+
}
|
|
141
|
+
assertCancellationUnsupported(signal) {
|
|
142
|
+
if (signal !== undefined)
|
|
143
|
+
throw new CommandCancellationUnsupportedError(this.id);
|
|
144
|
+
}
|
|
145
|
+
assertIdleForDisconnect() {
|
|
146
|
+
if (this.activeCommands.size > 0) {
|
|
147
|
+
throw new RemoteExecutionBusyError(this.id, this.activeCommands.size);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
trackCommand(invoke) {
|
|
151
|
+
const ownership = Symbol('remote-command');
|
|
152
|
+
this.activeCommands.add(ownership);
|
|
153
|
+
const release = () => {
|
|
154
|
+
this.activeCommands.delete(ownership);
|
|
155
|
+
};
|
|
156
|
+
let operation;
|
|
157
|
+
try {
|
|
158
|
+
operation = Promise.resolve(invoke());
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
release();
|
|
162
|
+
return Promise.reject(error);
|
|
163
|
+
}
|
|
164
|
+
return operation.then((result) => {
|
|
165
|
+
release();
|
|
166
|
+
return result;
|
|
167
|
+
}, (error) => {
|
|
168
|
+
release();
|
|
169
|
+
throw error;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
101
172
|
}
|
|
102
173
|
//# sourceMappingURL=remote.js.map
|