@codelia/runtime 0.1.45 → 0.1.48
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/index.cjs +244 -53
- package/dist/index.js +244 -53
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -5638,6 +5638,8 @@ var import_node_child_process3 = require("child_process");
|
|
|
5638
5638
|
var DEBUG_MAX_COMMAND_CHARS = 200;
|
|
5639
5639
|
var DEFAULT_TIMEOUT_SECONDS = 120;
|
|
5640
5640
|
var MAX_TIMEOUT_SECONDS = 300;
|
|
5641
|
+
var MAX_TIMER_DELAY_MS = 2147483647;
|
|
5642
|
+
var MAX_EXECUTION_TIMEOUT_SECONDS = Math.floor(MAX_TIMER_DELAY_MS / 1e3);
|
|
5641
5643
|
var MAX_OUTPUT_BYTES = 10 * 1024 * 1024;
|
|
5642
5644
|
var summarizeCommand = (command) => {
|
|
5643
5645
|
const normalized = command.trim().replace(/\s+/g, " ");
|
|
@@ -5772,7 +5774,12 @@ var terminateChild = (child, signal) => {
|
|
|
5772
5774
|
}
|
|
5773
5775
|
};
|
|
5774
5776
|
var startShellTask = (options) => {
|
|
5775
|
-
const timeoutSeconds = options.timeoutSeconds
|
|
5777
|
+
const timeoutSeconds = options.timeoutSeconds;
|
|
5778
|
+
if (timeoutSeconds !== void 0 && timeoutSeconds > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
5779
|
+
throw new Error(
|
|
5780
|
+
`timeoutSeconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less to fit Node's timer range; omit timeoutSeconds to run without an execution timer.`
|
|
5781
|
+
);
|
|
5782
|
+
}
|
|
5776
5783
|
const maxOutputBytes = options.maxOutputBytes ?? MAX_OUTPUT_BYTES;
|
|
5777
5784
|
const forceKillDelayMs = options.forceKillDelayMs ?? FORCE_KILL_DELAY_MS;
|
|
5778
5785
|
const startedAt = Date.now();
|
|
@@ -5892,12 +5899,14 @@ var startShellTask = (options) => {
|
|
|
5892
5899
|
failureMessage: `Command failed with exit code ${code ?? "unknown"}${signal ? ` signal ${signal}` : ""}`
|
|
5893
5900
|
});
|
|
5894
5901
|
});
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5902
|
+
if (timeoutSeconds !== void 0) {
|
|
5903
|
+
timeoutHandle = setTimeout(() => {
|
|
5904
|
+
cancelRequested = false;
|
|
5905
|
+
terminateChild(child, "SIGTERM");
|
|
5906
|
+
scheduleForceKill();
|
|
5907
|
+
fail(`Command timed out after ${Math.trunc(timeoutSeconds)}s`, "SIGTERM");
|
|
5908
|
+
}, timeoutSeconds * 1e3);
|
|
5909
|
+
}
|
|
5901
5910
|
});
|
|
5902
5911
|
return {
|
|
5903
5912
|
metadata,
|
|
@@ -5975,16 +5984,46 @@ var shellStateSchema = import_zod10.z.enum([
|
|
|
5975
5984
|
"cancelled"
|
|
5976
5985
|
]);
|
|
5977
5986
|
var shellRunSchema = import_zod10.z.object({
|
|
5978
|
-
command: import_zod10.z.string().describe(
|
|
5987
|
+
command: import_zod10.z.string().describe(
|
|
5988
|
+
"Shell command to execute as a runtime-managed child process in the current workspace."
|
|
5989
|
+
),
|
|
5979
5990
|
label: import_zod10.z.string().max(SHELL_LABEL_MAX_CHARS).optional().describe(`Optional short task label used to build the returned task key. Max ${SHELL_LABEL_MAX_CHARS} chars.`),
|
|
5980
|
-
timeout: import_zod10.z.number().int().positive().
|
|
5981
|
-
`
|
|
5991
|
+
timeout: import_zod10.z.number().int().positive().optional().describe(
|
|
5992
|
+
`Execution timeout in seconds. Foreground default: ${DEFAULT_TIMEOUT_SECONDS}, max ${MAX_TIMEOUT_SECONDS}. Background accepts larger values up to ${MAX_EXECUTION_TIMEOUT_SECONDS}; omit to keep the managed child job running until completion, cancel, or runtime exit.`
|
|
5982
5993
|
),
|
|
5983
|
-
background: import_zod10.z.boolean().optional().describe(
|
|
5994
|
+
background: import_zod10.z.boolean().optional().describe(
|
|
5995
|
+
"Detach the wait and return task info immediately. The runtime still owns the child process, so this is not persistence/daemonization. Manage it with shell_status/logs/wait/result/cancel. Default: false."
|
|
5996
|
+
)
|
|
5997
|
+
}).superRefine((input, ctx) => {
|
|
5998
|
+
if (input.timeout === void 0) {
|
|
5999
|
+
return;
|
|
6000
|
+
}
|
|
6001
|
+
if (input.background ?? false) {
|
|
6002
|
+
if (input.timeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
6003
|
+
ctx.addIssue({
|
|
6004
|
+
code: import_zod10.z.ZodIssueCode.custom,
|
|
6005
|
+
path: ["timeout"],
|
|
6006
|
+
message: `Background timeout must be ${MAX_EXECUTION_TIMEOUT_SECONDS} seconds or less. Omit timeout to run without an execution timer.`
|
|
6007
|
+
});
|
|
6008
|
+
}
|
|
6009
|
+
return;
|
|
6010
|
+
}
|
|
6011
|
+
if (input.timeout > MAX_TIMEOUT_SECONDS) {
|
|
6012
|
+
ctx.addIssue({
|
|
6013
|
+
code: import_zod10.z.ZodIssueCode.custom,
|
|
6014
|
+
path: ["timeout"],
|
|
6015
|
+
message: `Foreground timeout must be ${MAX_TIMEOUT_SECONDS} seconds or less.`
|
|
6016
|
+
});
|
|
6017
|
+
}
|
|
5984
6018
|
});
|
|
5985
6019
|
var shellTaskKeySchema = import_zod10.z.object({
|
|
5986
6020
|
key: import_zod10.z.string().describe("Canonical shell task key returned by shell or shell_list.")
|
|
5987
6021
|
});
|
|
6022
|
+
var shellWaitSchema = shellTaskKeySchema.extend({
|
|
6023
|
+
wait_timeout: import_zod10.z.number().int().positive().max(MAX_TIMEOUT_SECONDS).optional().describe(
|
|
6024
|
+
`Attached wait window in seconds. Default: ${DEFAULT_TIMEOUT_SECONDS}. Max ${MAX_TIMEOUT_SECONDS}. Returns still_running=true if the task has not finished before this window expires.`
|
|
6025
|
+
)
|
|
6026
|
+
});
|
|
5988
6027
|
var shellStreamSchema = import_zod10.z.enum(["stdout", "stderr"]);
|
|
5989
6028
|
var shellListSchema = import_zod10.z.object({
|
|
5990
6029
|
limit: import_zod10.z.number().int().positive().max(SHELL_LIST_MAX_LIMIT).optional().describe(
|
|
@@ -6010,10 +6049,14 @@ var normalizeOptionalLabel = (value) => {
|
|
|
6010
6049
|
const label = value.trim();
|
|
6011
6050
|
return label.length > 0 ? label : void 0;
|
|
6012
6051
|
};
|
|
6013
|
-
var
|
|
6052
|
+
var resolveShellTimeoutSeconds = (value, background) => {
|
|
6053
|
+
if (background) {
|
|
6054
|
+
return value === void 0 ? void 0 : Math.max(1, Math.trunc(value));
|
|
6055
|
+
}
|
|
6014
6056
|
const requestedTimeout = value ?? DEFAULT_TIMEOUT_SECONDS;
|
|
6015
|
-
return Math.max(1, Math.min(requestedTimeout, MAX_TIMEOUT_SECONDS));
|
|
6057
|
+
return Math.max(1, Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS));
|
|
6016
6058
|
};
|
|
6059
|
+
var formatShellTimeoutForLog = (value) => value === void 0 ? "none" : String(value);
|
|
6017
6060
|
var normalizeShellTaskKey = (value) => {
|
|
6018
6061
|
const key = value.trim();
|
|
6019
6062
|
if (!key) {
|
|
@@ -6281,11 +6324,54 @@ var waitForManagedTask = async (tasks, taskId, signal) => {
|
|
|
6281
6324
|
throw error;
|
|
6282
6325
|
}
|
|
6283
6326
|
};
|
|
6327
|
+
var resolveShellWaitTimeoutSeconds = (value) => Math.max(1, Math.min(Math.trunc(value ?? DEFAULT_TIMEOUT_SECONDS), MAX_TIMEOUT_SECONDS));
|
|
6328
|
+
var waitForManagedTaskWindow = async (tasks, taskId, options) => {
|
|
6329
|
+
let timeoutHandle;
|
|
6330
|
+
const waitPromise = waitForManagedTask(tasks, taskId, options.signal).then(
|
|
6331
|
+
(result) => ({
|
|
6332
|
+
type: "task",
|
|
6333
|
+
result
|
|
6334
|
+
})
|
|
6335
|
+
);
|
|
6336
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
6337
|
+
timeoutHandle = setTimeout(
|
|
6338
|
+
() => resolve({ type: "timeout" }),
|
|
6339
|
+
options.waitTimeoutSeconds * 1e3
|
|
6340
|
+
);
|
|
6341
|
+
});
|
|
6342
|
+
try {
|
|
6343
|
+
const outcome = await Promise.race([waitPromise, timeoutPromise]);
|
|
6344
|
+
if (outcome.type === "task") {
|
|
6345
|
+
return {
|
|
6346
|
+
task: outcome.result.task,
|
|
6347
|
+
aborted: outcome.result.aborted,
|
|
6348
|
+
stillRunning: false
|
|
6349
|
+
};
|
|
6350
|
+
}
|
|
6351
|
+
const task = await requireTask(tasks, taskId);
|
|
6352
|
+
if (isTerminalTaskState(task.state)) {
|
|
6353
|
+
return {
|
|
6354
|
+
task,
|
|
6355
|
+
aborted: false,
|
|
6356
|
+
stillRunning: false
|
|
6357
|
+
};
|
|
6358
|
+
}
|
|
6359
|
+
return {
|
|
6360
|
+
task,
|
|
6361
|
+
aborted: false,
|
|
6362
|
+
stillRunning: true
|
|
6363
|
+
};
|
|
6364
|
+
} finally {
|
|
6365
|
+
if (timeoutHandle) {
|
|
6366
|
+
clearTimeout(timeoutHandle);
|
|
6367
|
+
}
|
|
6368
|
+
}
|
|
6369
|
+
};
|
|
6284
6370
|
var createShellTool = (sandboxKey, options = {}) => {
|
|
6285
6371
|
const shared = getSharedDeps(options);
|
|
6286
6372
|
return (0, import_core11.defineTool)({
|
|
6287
6373
|
name: "shell",
|
|
6288
|
-
description: "
|
|
6374
|
+
description: "Run a shell command as a runtime-managed child process in the sandbox. By default wait for completion; with `background=true`, detach the wait and return task info you can inspect, wait on, or cancel later.",
|
|
6289
6375
|
input: shellRunSchema,
|
|
6290
6376
|
execute: async (input, ctx) => {
|
|
6291
6377
|
const sandbox = await getSandboxContext(ctx, sandboxKey);
|
|
@@ -6295,11 +6381,11 @@ var createShellTool = (sandboxKey, options = {}) => {
|
|
|
6295
6381
|
throw new Error("command is required.");
|
|
6296
6382
|
}
|
|
6297
6383
|
const label = normalizeOptionalLabel(input.label);
|
|
6298
|
-
const timeoutSeconds = clampTimeoutSeconds(input.timeout);
|
|
6299
6384
|
const background = input.background ?? false;
|
|
6385
|
+
const timeoutSeconds = resolveShellTimeoutSeconds(input.timeout, background);
|
|
6300
6386
|
const commandSummary = summarizeCommand(command);
|
|
6301
6387
|
(0, import_logger.debugLog)(
|
|
6302
|
-
`shell.start cwd=${sandbox.workingDir} timeout_s=${timeoutSeconds} background=${background} command="${commandSummary}"`
|
|
6388
|
+
`shell.start cwd=${sandbox.workingDir} timeout_s=${formatShellTimeoutForLog(timeoutSeconds)} background=${background} command="${commandSummary}"`
|
|
6303
6389
|
);
|
|
6304
6390
|
try {
|
|
6305
6391
|
const taskId = import_node_crypto6.default.randomUUID();
|
|
@@ -6417,18 +6503,25 @@ var createShellWaitTool = (options = {}) => {
|
|
|
6417
6503
|
const shared = getSharedDeps(options);
|
|
6418
6504
|
return (0, import_core11.defineTool)({
|
|
6419
6505
|
name: "shell_wait",
|
|
6420
|
-
description: "Wait for a shell task
|
|
6421
|
-
input:
|
|
6506
|
+
description: "Wait for a shell task within a bounded window and return its retained outcome; if the window expires first, return still_running=true.",
|
|
6507
|
+
input: shellWaitSchema,
|
|
6422
6508
|
execute: async (input, ctx) => {
|
|
6423
6509
|
try {
|
|
6424
|
-
const
|
|
6425
|
-
const
|
|
6510
|
+
const waitInput = input;
|
|
6511
|
+
const task = await resolveShellTask(shared.tasks, waitInput);
|
|
6512
|
+
const result = await waitForManagedTaskWindow(
|
|
6426
6513
|
shared.tasks,
|
|
6427
6514
|
task.task_id,
|
|
6428
|
-
|
|
6515
|
+
{
|
|
6516
|
+
waitTimeoutSeconds: resolveShellWaitTimeoutSeconds(
|
|
6517
|
+
waitInput.wait_timeout
|
|
6518
|
+
),
|
|
6519
|
+
signal: ctx.signal
|
|
6520
|
+
}
|
|
6429
6521
|
);
|
|
6430
6522
|
return {
|
|
6431
6523
|
...result.aborted ? { aborted: true } : {},
|
|
6524
|
+
...result.stillRunning ? { still_running: true } : {},
|
|
6432
6525
|
task: toShellTaskInfo(result.task)
|
|
6433
6526
|
};
|
|
6434
6527
|
} catch (error) {
|
|
@@ -11126,7 +11219,58 @@ var requireShellTask = async (taskManager, taskId) => {
|
|
|
11126
11219
|
}
|
|
11127
11220
|
return task;
|
|
11128
11221
|
};
|
|
11129
|
-
var
|
|
11222
|
+
var resolveShellTimeoutSeconds2 = (requestedTimeout, background) => {
|
|
11223
|
+
if (requestedTimeout !== void 0) {
|
|
11224
|
+
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
11225
|
+
return {
|
|
11226
|
+
error: {
|
|
11227
|
+
code: import_protocol6.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
11228
|
+
message: "timeout_seconds must be a positive number"
|
|
11229
|
+
}
|
|
11230
|
+
};
|
|
11231
|
+
}
|
|
11232
|
+
if (!background) {
|
|
11233
|
+
return Math.max(
|
|
11234
|
+
1,
|
|
11235
|
+
Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS)
|
|
11236
|
+
);
|
|
11237
|
+
}
|
|
11238
|
+
if (requestedTimeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
11239
|
+
return {
|
|
11240
|
+
error: {
|
|
11241
|
+
code: import_protocol6.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
11242
|
+
message: `background timeout_seconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less; omit timeout_seconds to run without an execution timer`
|
|
11243
|
+
}
|
|
11244
|
+
};
|
|
11245
|
+
}
|
|
11246
|
+
return Math.max(1, Math.trunc(requestedTimeout));
|
|
11247
|
+
}
|
|
11248
|
+
return background ? void 0 : DEFAULT_TIMEOUT_SECONDS;
|
|
11249
|
+
};
|
|
11250
|
+
var resolveShellWaitTimeoutSeconds2 = (requestedTimeout) => {
|
|
11251
|
+
if (requestedTimeout !== void 0) {
|
|
11252
|
+
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
11253
|
+
return {
|
|
11254
|
+
error: {
|
|
11255
|
+
code: import_protocol6.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
11256
|
+
message: "wait_timeout_seconds must be a positive number"
|
|
11257
|
+
}
|
|
11258
|
+
};
|
|
11259
|
+
}
|
|
11260
|
+
if (requestedTimeout > MAX_TIMEOUT_SECONDS) {
|
|
11261
|
+
return {
|
|
11262
|
+
error: {
|
|
11263
|
+
code: import_protocol6.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
11264
|
+
message: `wait_timeout_seconds must be ${MAX_TIMEOUT_SECONDS} seconds or less`
|
|
11265
|
+
}
|
|
11266
|
+
};
|
|
11267
|
+
}
|
|
11268
|
+
return Math.max(1, Math.trunc(requestedTimeout));
|
|
11269
|
+
}
|
|
11270
|
+
return DEFAULT_TIMEOUT_SECONDS;
|
|
11271
|
+
};
|
|
11272
|
+
var formatShellTimeoutForLog2 = (value) => value === void 0 ? "none" : String(value);
|
|
11273
|
+
var parseShellStartRequest = (state, params, options) => {
|
|
11130
11274
|
const command = params?.command?.trim() ?? "";
|
|
11131
11275
|
if (!command) {
|
|
11132
11276
|
return {
|
|
@@ -11136,19 +11280,13 @@ var parseShellStartRequest = (state, params) => {
|
|
|
11136
11280
|
}
|
|
11137
11281
|
};
|
|
11138
11282
|
}
|
|
11139
|
-
const
|
|
11140
|
-
|
|
11141
|
-
|
|
11142
|
-
error: {
|
|
11143
|
-
code: import_protocol6.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
11144
|
-
message: "timeout_seconds must be a positive number"
|
|
11145
|
-
}
|
|
11146
|
-
};
|
|
11147
|
-
}
|
|
11148
|
-
const timeoutSeconds = Math.max(
|
|
11149
|
-
1,
|
|
11150
|
-
Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS)
|
|
11283
|
+
const timeoutSeconds = resolveShellTimeoutSeconds2(
|
|
11284
|
+
params?.timeout_seconds,
|
|
11285
|
+
options.background
|
|
11151
11286
|
);
|
|
11287
|
+
if (typeof timeoutSeconds === "object") {
|
|
11288
|
+
return timeoutSeconds;
|
|
11289
|
+
}
|
|
11152
11290
|
const cwd = resolveShellCwd(state, params?.cwd);
|
|
11153
11291
|
if (!cwd) {
|
|
11154
11292
|
return {
|
|
@@ -11189,12 +11327,13 @@ var createShellHandlers = ({
|
|
|
11189
11327
|
};
|
|
11190
11328
|
};
|
|
11191
11329
|
const spawnShell = async (params, toolName) => {
|
|
11192
|
-
const
|
|
11330
|
+
const background = toolName === "shell.start";
|
|
11331
|
+
const parsed = parseShellStartRequest(state, params, { background });
|
|
11193
11332
|
if ("error" in parsed) {
|
|
11194
11333
|
throw parsed.error;
|
|
11195
11334
|
}
|
|
11196
11335
|
log2(
|
|
11197
|
-
`${toolName}.start origin=ui_bang cwd=${parsed.cwd} timeout_s=${parsed.timeoutSeconds} command="${parsed.commandSummary}"`
|
|
11336
|
+
`${toolName}.start origin=ui_bang cwd=${parsed.cwd} timeout_s=${formatShellTimeoutForLog2(parsed.timeoutSeconds)} command="${parsed.commandSummary}"`
|
|
11198
11337
|
);
|
|
11199
11338
|
const task = await shellTaskManager.spawn(
|
|
11200
11339
|
{
|
|
@@ -11335,6 +11474,13 @@ var createShellHandlers = ({
|
|
|
11335
11474
|
});
|
|
11336
11475
|
return;
|
|
11337
11476
|
}
|
|
11477
|
+
const waitTimeoutSeconds = resolveShellWaitTimeoutSeconds2(
|
|
11478
|
+
params?.wait_timeout_seconds
|
|
11479
|
+
);
|
|
11480
|
+
if (typeof waitTimeoutSeconds === "object") {
|
|
11481
|
+
sendError(id, waitTimeoutSeconds.error);
|
|
11482
|
+
return;
|
|
11483
|
+
}
|
|
11338
11484
|
try {
|
|
11339
11485
|
const existing = await requireShellTask(shellTaskManager, taskId);
|
|
11340
11486
|
if (isTerminalTaskState(existing.state)) {
|
|
@@ -11342,12 +11488,19 @@ var createShellHandlers = ({
|
|
|
11342
11488
|
return;
|
|
11343
11489
|
}
|
|
11344
11490
|
const controller = new AbortController();
|
|
11491
|
+
let timeoutHandle;
|
|
11345
11492
|
let resolveDetached;
|
|
11346
11493
|
const detachPromise = new Promise(
|
|
11347
11494
|
(resolve) => {
|
|
11348
11495
|
resolveDetached = (result) => resolve({ type: "detached", result });
|
|
11349
11496
|
}
|
|
11350
11497
|
);
|
|
11498
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
11499
|
+
timeoutHandle = setTimeout(() => {
|
|
11500
|
+
controller.abort();
|
|
11501
|
+
resolve({ type: "still_running" });
|
|
11502
|
+
}, waitTimeoutSeconds * 1e3);
|
|
11503
|
+
});
|
|
11351
11504
|
const unregister = registerActiveShellWait(taskId, {
|
|
11352
11505
|
detach: (task) => {
|
|
11353
11506
|
resolveDetached({
|
|
@@ -11365,16 +11518,31 @@ var createShellHandlers = ({
|
|
|
11365
11518
|
}
|
|
11366
11519
|
throw error;
|
|
11367
11520
|
});
|
|
11368
|
-
const outcome = await Promise.race([
|
|
11521
|
+
const outcome = await Promise.race([
|
|
11522
|
+
waitPromise,
|
|
11523
|
+
detachPromise,
|
|
11524
|
+
timeoutPromise
|
|
11525
|
+
]);
|
|
11369
11526
|
if (outcome.type === "detached") {
|
|
11370
11527
|
sendResult(id, outcome.result);
|
|
11371
11528
|
return;
|
|
11372
11529
|
}
|
|
11530
|
+
if (outcome.type === "still_running") {
|
|
11531
|
+
const task = await requireShellTask(shellTaskManager, taskId);
|
|
11532
|
+
sendResult(id, {
|
|
11533
|
+
...toShellTaskInfo2(task),
|
|
11534
|
+
...isTerminalTaskState(task.state) ? {} : { still_running: true }
|
|
11535
|
+
});
|
|
11536
|
+
return;
|
|
11537
|
+
}
|
|
11373
11538
|
if (outcome.type === "aborted") {
|
|
11374
11539
|
return;
|
|
11375
11540
|
}
|
|
11376
11541
|
sendResult(id, toShellTaskInfo2(outcome.task));
|
|
11377
11542
|
} finally {
|
|
11543
|
+
if (timeoutHandle) {
|
|
11544
|
+
clearTimeout(timeoutHandle);
|
|
11545
|
+
}
|
|
11378
11546
|
unregister();
|
|
11379
11547
|
}
|
|
11380
11548
|
} catch (error) {
|
|
@@ -11622,7 +11790,36 @@ var toTaskInfo = (task) => ({
|
|
|
11622
11790
|
});
|
|
11623
11791
|
var isTaskKind = (value) => value === "shell" || value === "subagent";
|
|
11624
11792
|
var isTaskState = (value) => value === "queued" || value === "running" || value === "completed" || value === "failed" || value === "cancelled";
|
|
11625
|
-
var
|
|
11793
|
+
var resolveShellTimeoutSeconds3 = (requestedTimeout, background) => {
|
|
11794
|
+
if (requestedTimeout !== void 0) {
|
|
11795
|
+
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
11796
|
+
return {
|
|
11797
|
+
error: {
|
|
11798
|
+
code: import_protocol8.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
11799
|
+
message: "timeout_seconds must be a positive number"
|
|
11800
|
+
}
|
|
11801
|
+
};
|
|
11802
|
+
}
|
|
11803
|
+
if (!background) {
|
|
11804
|
+
return Math.max(
|
|
11805
|
+
1,
|
|
11806
|
+
Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS)
|
|
11807
|
+
);
|
|
11808
|
+
}
|
|
11809
|
+
if (requestedTimeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
11810
|
+
return {
|
|
11811
|
+
error: {
|
|
11812
|
+
code: import_protocol8.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
11813
|
+
message: `background timeout_seconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less; omit timeout_seconds to run without an execution timer`
|
|
11814
|
+
}
|
|
11815
|
+
};
|
|
11816
|
+
}
|
|
11817
|
+
return Math.max(1, Math.trunc(requestedTimeout));
|
|
11818
|
+
}
|
|
11819
|
+
return background ? void 0 : DEFAULT_TIMEOUT_SECONDS;
|
|
11820
|
+
};
|
|
11821
|
+
var formatShellTimeoutForLog3 = (value) => value === void 0 ? "none" : String(value);
|
|
11822
|
+
var parseShellSpawnRequest = (state, params, options) => {
|
|
11626
11823
|
const command = params.command?.trim() ?? "";
|
|
11627
11824
|
if (!command) {
|
|
11628
11825
|
return {
|
|
@@ -11632,19 +11829,13 @@ var parseShellSpawnRequest = (state, params) => {
|
|
|
11632
11829
|
}
|
|
11633
11830
|
};
|
|
11634
11831
|
}
|
|
11635
|
-
const
|
|
11636
|
-
|
|
11637
|
-
|
|
11638
|
-
error: {
|
|
11639
|
-
code: import_protocol8.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
11640
|
-
message: "timeout_seconds must be a positive number"
|
|
11641
|
-
}
|
|
11642
|
-
};
|
|
11643
|
-
}
|
|
11644
|
-
const timeoutSeconds = Math.max(
|
|
11645
|
-
1,
|
|
11646
|
-
Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS)
|
|
11832
|
+
const timeoutSeconds = resolveShellTimeoutSeconds3(
|
|
11833
|
+
params.timeout_seconds,
|
|
11834
|
+
options.background
|
|
11647
11835
|
);
|
|
11836
|
+
if (typeof timeoutSeconds === "object") {
|
|
11837
|
+
return timeoutSeconds;
|
|
11838
|
+
}
|
|
11648
11839
|
const cwd = resolveShellCwd2(state, params.cwd);
|
|
11649
11840
|
if (!cwd) {
|
|
11650
11841
|
return {
|
|
@@ -11685,15 +11876,15 @@ var createTaskHandlers = ({
|
|
|
11685
11876
|
});
|
|
11686
11877
|
return;
|
|
11687
11878
|
}
|
|
11688
|
-
const
|
|
11879
|
+
const background = params.background !== false;
|
|
11880
|
+
const parsed = parseShellSpawnRequest(state, params, { background });
|
|
11689
11881
|
if ("error" in parsed) {
|
|
11690
11882
|
sendError(id, parsed.error);
|
|
11691
11883
|
return;
|
|
11692
11884
|
}
|
|
11693
11885
|
try {
|
|
11694
|
-
const background = params.background !== false;
|
|
11695
11886
|
log2(
|
|
11696
|
-
`task.spawn kind=shell cwd=${parsed.cwd} timeout_s=${parsed.timeoutSeconds} background=${background} command="${parsed.commandSummary}"`
|
|
11887
|
+
`task.spawn kind=shell cwd=${parsed.cwd} timeout_s=${formatShellTimeoutForLog3(parsed.timeoutSeconds)} background=${background} command="${parsed.commandSummary}"`
|
|
11697
11888
|
);
|
|
11698
11889
|
const task = await tasks.spawn(
|
|
11699
11890
|
{
|
package/dist/index.js
CHANGED
|
@@ -5646,6 +5646,8 @@ import { spawn as spawn3 } from "child_process";
|
|
|
5646
5646
|
var DEBUG_MAX_COMMAND_CHARS = 200;
|
|
5647
5647
|
var DEFAULT_TIMEOUT_SECONDS = 120;
|
|
5648
5648
|
var MAX_TIMEOUT_SECONDS = 300;
|
|
5649
|
+
var MAX_TIMER_DELAY_MS = 2147483647;
|
|
5650
|
+
var MAX_EXECUTION_TIMEOUT_SECONDS = Math.floor(MAX_TIMER_DELAY_MS / 1e3);
|
|
5649
5651
|
var MAX_OUTPUT_BYTES = 10 * 1024 * 1024;
|
|
5650
5652
|
var summarizeCommand = (command) => {
|
|
5651
5653
|
const normalized = command.trim().replace(/\s+/g, " ");
|
|
@@ -5780,7 +5782,12 @@ var terminateChild = (child, signal) => {
|
|
|
5780
5782
|
}
|
|
5781
5783
|
};
|
|
5782
5784
|
var startShellTask = (options) => {
|
|
5783
|
-
const timeoutSeconds = options.timeoutSeconds
|
|
5785
|
+
const timeoutSeconds = options.timeoutSeconds;
|
|
5786
|
+
if (timeoutSeconds !== void 0 && timeoutSeconds > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
5787
|
+
throw new Error(
|
|
5788
|
+
`timeoutSeconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less to fit Node's timer range; omit timeoutSeconds to run without an execution timer.`
|
|
5789
|
+
);
|
|
5790
|
+
}
|
|
5784
5791
|
const maxOutputBytes = options.maxOutputBytes ?? MAX_OUTPUT_BYTES;
|
|
5785
5792
|
const forceKillDelayMs = options.forceKillDelayMs ?? FORCE_KILL_DELAY_MS;
|
|
5786
5793
|
const startedAt = Date.now();
|
|
@@ -5900,12 +5907,14 @@ var startShellTask = (options) => {
|
|
|
5900
5907
|
failureMessage: `Command failed with exit code ${code ?? "unknown"}${signal ? ` signal ${signal}` : ""}`
|
|
5901
5908
|
});
|
|
5902
5909
|
});
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5910
|
+
if (timeoutSeconds !== void 0) {
|
|
5911
|
+
timeoutHandle = setTimeout(() => {
|
|
5912
|
+
cancelRequested = false;
|
|
5913
|
+
terminateChild(child, "SIGTERM");
|
|
5914
|
+
scheduleForceKill();
|
|
5915
|
+
fail(`Command timed out after ${Math.trunc(timeoutSeconds)}s`, "SIGTERM");
|
|
5916
|
+
}, timeoutSeconds * 1e3);
|
|
5917
|
+
}
|
|
5909
5918
|
});
|
|
5910
5919
|
return {
|
|
5911
5920
|
metadata,
|
|
@@ -5983,16 +5992,46 @@ var shellStateSchema = z10.enum([
|
|
|
5983
5992
|
"cancelled"
|
|
5984
5993
|
]);
|
|
5985
5994
|
var shellRunSchema = z10.object({
|
|
5986
|
-
command: z10.string().describe(
|
|
5995
|
+
command: z10.string().describe(
|
|
5996
|
+
"Shell command to execute as a runtime-managed child process in the current workspace."
|
|
5997
|
+
),
|
|
5987
5998
|
label: z10.string().max(SHELL_LABEL_MAX_CHARS).optional().describe(`Optional short task label used to build the returned task key. Max ${SHELL_LABEL_MAX_CHARS} chars.`),
|
|
5988
|
-
timeout: z10.number().int().positive().
|
|
5989
|
-
`
|
|
5999
|
+
timeout: z10.number().int().positive().optional().describe(
|
|
6000
|
+
`Execution timeout in seconds. Foreground default: ${DEFAULT_TIMEOUT_SECONDS}, max ${MAX_TIMEOUT_SECONDS}. Background accepts larger values up to ${MAX_EXECUTION_TIMEOUT_SECONDS}; omit to keep the managed child job running until completion, cancel, or runtime exit.`
|
|
5990
6001
|
),
|
|
5991
|
-
background: z10.boolean().optional().describe(
|
|
6002
|
+
background: z10.boolean().optional().describe(
|
|
6003
|
+
"Detach the wait and return task info immediately. The runtime still owns the child process, so this is not persistence/daemonization. Manage it with shell_status/logs/wait/result/cancel. Default: false."
|
|
6004
|
+
)
|
|
6005
|
+
}).superRefine((input, ctx) => {
|
|
6006
|
+
if (input.timeout === void 0) {
|
|
6007
|
+
return;
|
|
6008
|
+
}
|
|
6009
|
+
if (input.background ?? false) {
|
|
6010
|
+
if (input.timeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
6011
|
+
ctx.addIssue({
|
|
6012
|
+
code: z10.ZodIssueCode.custom,
|
|
6013
|
+
path: ["timeout"],
|
|
6014
|
+
message: `Background timeout must be ${MAX_EXECUTION_TIMEOUT_SECONDS} seconds or less. Omit timeout to run without an execution timer.`
|
|
6015
|
+
});
|
|
6016
|
+
}
|
|
6017
|
+
return;
|
|
6018
|
+
}
|
|
6019
|
+
if (input.timeout > MAX_TIMEOUT_SECONDS) {
|
|
6020
|
+
ctx.addIssue({
|
|
6021
|
+
code: z10.ZodIssueCode.custom,
|
|
6022
|
+
path: ["timeout"],
|
|
6023
|
+
message: `Foreground timeout must be ${MAX_TIMEOUT_SECONDS} seconds or less.`
|
|
6024
|
+
});
|
|
6025
|
+
}
|
|
5992
6026
|
});
|
|
5993
6027
|
var shellTaskKeySchema = z10.object({
|
|
5994
6028
|
key: z10.string().describe("Canonical shell task key returned by shell or shell_list.")
|
|
5995
6029
|
});
|
|
6030
|
+
var shellWaitSchema = shellTaskKeySchema.extend({
|
|
6031
|
+
wait_timeout: z10.number().int().positive().max(MAX_TIMEOUT_SECONDS).optional().describe(
|
|
6032
|
+
`Attached wait window in seconds. Default: ${DEFAULT_TIMEOUT_SECONDS}. Max ${MAX_TIMEOUT_SECONDS}. Returns still_running=true if the task has not finished before this window expires.`
|
|
6033
|
+
)
|
|
6034
|
+
});
|
|
5996
6035
|
var shellStreamSchema = z10.enum(["stdout", "stderr"]);
|
|
5997
6036
|
var shellListSchema = z10.object({
|
|
5998
6037
|
limit: z10.number().int().positive().max(SHELL_LIST_MAX_LIMIT).optional().describe(
|
|
@@ -6018,10 +6057,14 @@ var normalizeOptionalLabel = (value) => {
|
|
|
6018
6057
|
const label = value.trim();
|
|
6019
6058
|
return label.length > 0 ? label : void 0;
|
|
6020
6059
|
};
|
|
6021
|
-
var
|
|
6060
|
+
var resolveShellTimeoutSeconds = (value, background) => {
|
|
6061
|
+
if (background) {
|
|
6062
|
+
return value === void 0 ? void 0 : Math.max(1, Math.trunc(value));
|
|
6063
|
+
}
|
|
6022
6064
|
const requestedTimeout = value ?? DEFAULT_TIMEOUT_SECONDS;
|
|
6023
|
-
return Math.max(1, Math.min(requestedTimeout, MAX_TIMEOUT_SECONDS));
|
|
6065
|
+
return Math.max(1, Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS));
|
|
6024
6066
|
};
|
|
6067
|
+
var formatShellTimeoutForLog = (value) => value === void 0 ? "none" : String(value);
|
|
6025
6068
|
var normalizeShellTaskKey = (value) => {
|
|
6026
6069
|
const key = value.trim();
|
|
6027
6070
|
if (!key) {
|
|
@@ -6289,11 +6332,54 @@ var waitForManagedTask = async (tasks, taskId, signal) => {
|
|
|
6289
6332
|
throw error;
|
|
6290
6333
|
}
|
|
6291
6334
|
};
|
|
6335
|
+
var resolveShellWaitTimeoutSeconds = (value) => Math.max(1, Math.min(Math.trunc(value ?? DEFAULT_TIMEOUT_SECONDS), MAX_TIMEOUT_SECONDS));
|
|
6336
|
+
var waitForManagedTaskWindow = async (tasks, taskId, options) => {
|
|
6337
|
+
let timeoutHandle;
|
|
6338
|
+
const waitPromise = waitForManagedTask(tasks, taskId, options.signal).then(
|
|
6339
|
+
(result) => ({
|
|
6340
|
+
type: "task",
|
|
6341
|
+
result
|
|
6342
|
+
})
|
|
6343
|
+
);
|
|
6344
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
6345
|
+
timeoutHandle = setTimeout(
|
|
6346
|
+
() => resolve({ type: "timeout" }),
|
|
6347
|
+
options.waitTimeoutSeconds * 1e3
|
|
6348
|
+
);
|
|
6349
|
+
});
|
|
6350
|
+
try {
|
|
6351
|
+
const outcome = await Promise.race([waitPromise, timeoutPromise]);
|
|
6352
|
+
if (outcome.type === "task") {
|
|
6353
|
+
return {
|
|
6354
|
+
task: outcome.result.task,
|
|
6355
|
+
aborted: outcome.result.aborted,
|
|
6356
|
+
stillRunning: false
|
|
6357
|
+
};
|
|
6358
|
+
}
|
|
6359
|
+
const task = await requireTask(tasks, taskId);
|
|
6360
|
+
if (isTerminalTaskState(task.state)) {
|
|
6361
|
+
return {
|
|
6362
|
+
task,
|
|
6363
|
+
aborted: false,
|
|
6364
|
+
stillRunning: false
|
|
6365
|
+
};
|
|
6366
|
+
}
|
|
6367
|
+
return {
|
|
6368
|
+
task,
|
|
6369
|
+
aborted: false,
|
|
6370
|
+
stillRunning: true
|
|
6371
|
+
};
|
|
6372
|
+
} finally {
|
|
6373
|
+
if (timeoutHandle) {
|
|
6374
|
+
clearTimeout(timeoutHandle);
|
|
6375
|
+
}
|
|
6376
|
+
}
|
|
6377
|
+
};
|
|
6292
6378
|
var createShellTool = (sandboxKey, options = {}) => {
|
|
6293
6379
|
const shared = getSharedDeps(options);
|
|
6294
6380
|
return defineTool9({
|
|
6295
6381
|
name: "shell",
|
|
6296
|
-
description: "
|
|
6382
|
+
description: "Run a shell command as a runtime-managed child process in the sandbox. By default wait for completion; with `background=true`, detach the wait and return task info you can inspect, wait on, or cancel later.",
|
|
6297
6383
|
input: shellRunSchema,
|
|
6298
6384
|
execute: async (input, ctx) => {
|
|
6299
6385
|
const sandbox = await getSandboxContext(ctx, sandboxKey);
|
|
@@ -6303,11 +6389,11 @@ var createShellTool = (sandboxKey, options = {}) => {
|
|
|
6303
6389
|
throw new Error("command is required.");
|
|
6304
6390
|
}
|
|
6305
6391
|
const label = normalizeOptionalLabel(input.label);
|
|
6306
|
-
const timeoutSeconds = clampTimeoutSeconds(input.timeout);
|
|
6307
6392
|
const background = input.background ?? false;
|
|
6393
|
+
const timeoutSeconds = resolveShellTimeoutSeconds(input.timeout, background);
|
|
6308
6394
|
const commandSummary = summarizeCommand(command);
|
|
6309
6395
|
debugLog(
|
|
6310
|
-
`shell.start cwd=${sandbox.workingDir} timeout_s=${timeoutSeconds} background=${background} command="${commandSummary}"`
|
|
6396
|
+
`shell.start cwd=${sandbox.workingDir} timeout_s=${formatShellTimeoutForLog(timeoutSeconds)} background=${background} command="${commandSummary}"`
|
|
6311
6397
|
);
|
|
6312
6398
|
try {
|
|
6313
6399
|
const taskId = crypto6.randomUUID();
|
|
@@ -6425,18 +6511,25 @@ var createShellWaitTool = (options = {}) => {
|
|
|
6425
6511
|
const shared = getSharedDeps(options);
|
|
6426
6512
|
return defineTool9({
|
|
6427
6513
|
name: "shell_wait",
|
|
6428
|
-
description: "Wait for a shell task
|
|
6429
|
-
input:
|
|
6514
|
+
description: "Wait for a shell task within a bounded window and return its retained outcome; if the window expires first, return still_running=true.",
|
|
6515
|
+
input: shellWaitSchema,
|
|
6430
6516
|
execute: async (input, ctx) => {
|
|
6431
6517
|
try {
|
|
6432
|
-
const
|
|
6433
|
-
const
|
|
6518
|
+
const waitInput = input;
|
|
6519
|
+
const task = await resolveShellTask(shared.tasks, waitInput);
|
|
6520
|
+
const result = await waitForManagedTaskWindow(
|
|
6434
6521
|
shared.tasks,
|
|
6435
6522
|
task.task_id,
|
|
6436
|
-
|
|
6523
|
+
{
|
|
6524
|
+
waitTimeoutSeconds: resolveShellWaitTimeoutSeconds(
|
|
6525
|
+
waitInput.wait_timeout
|
|
6526
|
+
),
|
|
6527
|
+
signal: ctx.signal
|
|
6528
|
+
}
|
|
6437
6529
|
);
|
|
6438
6530
|
return {
|
|
6439
6531
|
...result.aborted ? { aborted: true } : {},
|
|
6532
|
+
...result.stillRunning ? { still_running: true } : {},
|
|
6440
6533
|
task: toShellTaskInfo(result.task)
|
|
6441
6534
|
};
|
|
6442
6535
|
} catch (error) {
|
|
@@ -11166,7 +11259,58 @@ var requireShellTask = async (taskManager, taskId) => {
|
|
|
11166
11259
|
}
|
|
11167
11260
|
return task;
|
|
11168
11261
|
};
|
|
11169
|
-
var
|
|
11262
|
+
var resolveShellTimeoutSeconds2 = (requestedTimeout, background) => {
|
|
11263
|
+
if (requestedTimeout !== void 0) {
|
|
11264
|
+
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
11265
|
+
return {
|
|
11266
|
+
error: {
|
|
11267
|
+
code: RPC_ERROR_CODE5.INVALID_PARAMS,
|
|
11268
|
+
message: "timeout_seconds must be a positive number"
|
|
11269
|
+
}
|
|
11270
|
+
};
|
|
11271
|
+
}
|
|
11272
|
+
if (!background) {
|
|
11273
|
+
return Math.max(
|
|
11274
|
+
1,
|
|
11275
|
+
Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS)
|
|
11276
|
+
);
|
|
11277
|
+
}
|
|
11278
|
+
if (requestedTimeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
11279
|
+
return {
|
|
11280
|
+
error: {
|
|
11281
|
+
code: RPC_ERROR_CODE5.INVALID_PARAMS,
|
|
11282
|
+
message: `background timeout_seconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less; omit timeout_seconds to run without an execution timer`
|
|
11283
|
+
}
|
|
11284
|
+
};
|
|
11285
|
+
}
|
|
11286
|
+
return Math.max(1, Math.trunc(requestedTimeout));
|
|
11287
|
+
}
|
|
11288
|
+
return background ? void 0 : DEFAULT_TIMEOUT_SECONDS;
|
|
11289
|
+
};
|
|
11290
|
+
var resolveShellWaitTimeoutSeconds2 = (requestedTimeout) => {
|
|
11291
|
+
if (requestedTimeout !== void 0) {
|
|
11292
|
+
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
11293
|
+
return {
|
|
11294
|
+
error: {
|
|
11295
|
+
code: RPC_ERROR_CODE5.INVALID_PARAMS,
|
|
11296
|
+
message: "wait_timeout_seconds must be a positive number"
|
|
11297
|
+
}
|
|
11298
|
+
};
|
|
11299
|
+
}
|
|
11300
|
+
if (requestedTimeout > MAX_TIMEOUT_SECONDS) {
|
|
11301
|
+
return {
|
|
11302
|
+
error: {
|
|
11303
|
+
code: RPC_ERROR_CODE5.INVALID_PARAMS,
|
|
11304
|
+
message: `wait_timeout_seconds must be ${MAX_TIMEOUT_SECONDS} seconds or less`
|
|
11305
|
+
}
|
|
11306
|
+
};
|
|
11307
|
+
}
|
|
11308
|
+
return Math.max(1, Math.trunc(requestedTimeout));
|
|
11309
|
+
}
|
|
11310
|
+
return DEFAULT_TIMEOUT_SECONDS;
|
|
11311
|
+
};
|
|
11312
|
+
var formatShellTimeoutForLog2 = (value) => value === void 0 ? "none" : String(value);
|
|
11313
|
+
var parseShellStartRequest = (state, params, options) => {
|
|
11170
11314
|
const command = params?.command?.trim() ?? "";
|
|
11171
11315
|
if (!command) {
|
|
11172
11316
|
return {
|
|
@@ -11176,19 +11320,13 @@ var parseShellStartRequest = (state, params) => {
|
|
|
11176
11320
|
}
|
|
11177
11321
|
};
|
|
11178
11322
|
}
|
|
11179
|
-
const
|
|
11180
|
-
|
|
11181
|
-
|
|
11182
|
-
error: {
|
|
11183
|
-
code: RPC_ERROR_CODE5.INVALID_PARAMS,
|
|
11184
|
-
message: "timeout_seconds must be a positive number"
|
|
11185
|
-
}
|
|
11186
|
-
};
|
|
11187
|
-
}
|
|
11188
|
-
const timeoutSeconds = Math.max(
|
|
11189
|
-
1,
|
|
11190
|
-
Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS)
|
|
11323
|
+
const timeoutSeconds = resolveShellTimeoutSeconds2(
|
|
11324
|
+
params?.timeout_seconds,
|
|
11325
|
+
options.background
|
|
11191
11326
|
);
|
|
11327
|
+
if (typeof timeoutSeconds === "object") {
|
|
11328
|
+
return timeoutSeconds;
|
|
11329
|
+
}
|
|
11192
11330
|
const cwd = resolveShellCwd(state, params?.cwd);
|
|
11193
11331
|
if (!cwd) {
|
|
11194
11332
|
return {
|
|
@@ -11229,12 +11367,13 @@ var createShellHandlers = ({
|
|
|
11229
11367
|
};
|
|
11230
11368
|
};
|
|
11231
11369
|
const spawnShell = async (params, toolName) => {
|
|
11232
|
-
const
|
|
11370
|
+
const background = toolName === "shell.start";
|
|
11371
|
+
const parsed = parseShellStartRequest(state, params, { background });
|
|
11233
11372
|
if ("error" in parsed) {
|
|
11234
11373
|
throw parsed.error;
|
|
11235
11374
|
}
|
|
11236
11375
|
log2(
|
|
11237
|
-
`${toolName}.start origin=ui_bang cwd=${parsed.cwd} timeout_s=${parsed.timeoutSeconds} command="${parsed.commandSummary}"`
|
|
11376
|
+
`${toolName}.start origin=ui_bang cwd=${parsed.cwd} timeout_s=${formatShellTimeoutForLog2(parsed.timeoutSeconds)} command="${parsed.commandSummary}"`
|
|
11238
11377
|
);
|
|
11239
11378
|
const task = await shellTaskManager.spawn(
|
|
11240
11379
|
{
|
|
@@ -11375,6 +11514,13 @@ var createShellHandlers = ({
|
|
|
11375
11514
|
});
|
|
11376
11515
|
return;
|
|
11377
11516
|
}
|
|
11517
|
+
const waitTimeoutSeconds = resolveShellWaitTimeoutSeconds2(
|
|
11518
|
+
params?.wait_timeout_seconds
|
|
11519
|
+
);
|
|
11520
|
+
if (typeof waitTimeoutSeconds === "object") {
|
|
11521
|
+
sendError(id, waitTimeoutSeconds.error);
|
|
11522
|
+
return;
|
|
11523
|
+
}
|
|
11378
11524
|
try {
|
|
11379
11525
|
const existing = await requireShellTask(shellTaskManager, taskId);
|
|
11380
11526
|
if (isTerminalTaskState(existing.state)) {
|
|
@@ -11382,12 +11528,19 @@ var createShellHandlers = ({
|
|
|
11382
11528
|
return;
|
|
11383
11529
|
}
|
|
11384
11530
|
const controller = new AbortController();
|
|
11531
|
+
let timeoutHandle;
|
|
11385
11532
|
let resolveDetached;
|
|
11386
11533
|
const detachPromise = new Promise(
|
|
11387
11534
|
(resolve) => {
|
|
11388
11535
|
resolveDetached = (result) => resolve({ type: "detached", result });
|
|
11389
11536
|
}
|
|
11390
11537
|
);
|
|
11538
|
+
const timeoutPromise = new Promise((resolve) => {
|
|
11539
|
+
timeoutHandle = setTimeout(() => {
|
|
11540
|
+
controller.abort();
|
|
11541
|
+
resolve({ type: "still_running" });
|
|
11542
|
+
}, waitTimeoutSeconds * 1e3);
|
|
11543
|
+
});
|
|
11391
11544
|
const unregister = registerActiveShellWait(taskId, {
|
|
11392
11545
|
detach: (task) => {
|
|
11393
11546
|
resolveDetached({
|
|
@@ -11405,16 +11558,31 @@ var createShellHandlers = ({
|
|
|
11405
11558
|
}
|
|
11406
11559
|
throw error;
|
|
11407
11560
|
});
|
|
11408
|
-
const outcome = await Promise.race([
|
|
11561
|
+
const outcome = await Promise.race([
|
|
11562
|
+
waitPromise,
|
|
11563
|
+
detachPromise,
|
|
11564
|
+
timeoutPromise
|
|
11565
|
+
]);
|
|
11409
11566
|
if (outcome.type === "detached") {
|
|
11410
11567
|
sendResult(id, outcome.result);
|
|
11411
11568
|
return;
|
|
11412
11569
|
}
|
|
11570
|
+
if (outcome.type === "still_running") {
|
|
11571
|
+
const task = await requireShellTask(shellTaskManager, taskId);
|
|
11572
|
+
sendResult(id, {
|
|
11573
|
+
...toShellTaskInfo2(task),
|
|
11574
|
+
...isTerminalTaskState(task.state) ? {} : { still_running: true }
|
|
11575
|
+
});
|
|
11576
|
+
return;
|
|
11577
|
+
}
|
|
11413
11578
|
if (outcome.type === "aborted") {
|
|
11414
11579
|
return;
|
|
11415
11580
|
}
|
|
11416
11581
|
sendResult(id, toShellTaskInfo2(outcome.task));
|
|
11417
11582
|
} finally {
|
|
11583
|
+
if (timeoutHandle) {
|
|
11584
|
+
clearTimeout(timeoutHandle);
|
|
11585
|
+
}
|
|
11418
11586
|
unregister();
|
|
11419
11587
|
}
|
|
11420
11588
|
} catch (error) {
|
|
@@ -11666,7 +11834,36 @@ var toTaskInfo = (task) => ({
|
|
|
11666
11834
|
});
|
|
11667
11835
|
var isTaskKind = (value) => value === "shell" || value === "subagent";
|
|
11668
11836
|
var isTaskState = (value) => value === "queued" || value === "running" || value === "completed" || value === "failed" || value === "cancelled";
|
|
11669
|
-
var
|
|
11837
|
+
var resolveShellTimeoutSeconds3 = (requestedTimeout, background) => {
|
|
11838
|
+
if (requestedTimeout !== void 0) {
|
|
11839
|
+
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
11840
|
+
return {
|
|
11841
|
+
error: {
|
|
11842
|
+
code: RPC_ERROR_CODE7.INVALID_PARAMS,
|
|
11843
|
+
message: "timeout_seconds must be a positive number"
|
|
11844
|
+
}
|
|
11845
|
+
};
|
|
11846
|
+
}
|
|
11847
|
+
if (!background) {
|
|
11848
|
+
return Math.max(
|
|
11849
|
+
1,
|
|
11850
|
+
Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS)
|
|
11851
|
+
);
|
|
11852
|
+
}
|
|
11853
|
+
if (requestedTimeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
11854
|
+
return {
|
|
11855
|
+
error: {
|
|
11856
|
+
code: RPC_ERROR_CODE7.INVALID_PARAMS,
|
|
11857
|
+
message: `background timeout_seconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less; omit timeout_seconds to run without an execution timer`
|
|
11858
|
+
}
|
|
11859
|
+
};
|
|
11860
|
+
}
|
|
11861
|
+
return Math.max(1, Math.trunc(requestedTimeout));
|
|
11862
|
+
}
|
|
11863
|
+
return background ? void 0 : DEFAULT_TIMEOUT_SECONDS;
|
|
11864
|
+
};
|
|
11865
|
+
var formatShellTimeoutForLog3 = (value) => value === void 0 ? "none" : String(value);
|
|
11866
|
+
var parseShellSpawnRequest = (state, params, options) => {
|
|
11670
11867
|
const command = params.command?.trim() ?? "";
|
|
11671
11868
|
if (!command) {
|
|
11672
11869
|
return {
|
|
@@ -11676,19 +11873,13 @@ var parseShellSpawnRequest = (state, params) => {
|
|
|
11676
11873
|
}
|
|
11677
11874
|
};
|
|
11678
11875
|
}
|
|
11679
|
-
const
|
|
11680
|
-
|
|
11681
|
-
|
|
11682
|
-
error: {
|
|
11683
|
-
code: RPC_ERROR_CODE7.INVALID_PARAMS,
|
|
11684
|
-
message: "timeout_seconds must be a positive number"
|
|
11685
|
-
}
|
|
11686
|
-
};
|
|
11687
|
-
}
|
|
11688
|
-
const timeoutSeconds = Math.max(
|
|
11689
|
-
1,
|
|
11690
|
-
Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS)
|
|
11876
|
+
const timeoutSeconds = resolveShellTimeoutSeconds3(
|
|
11877
|
+
params.timeout_seconds,
|
|
11878
|
+
options.background
|
|
11691
11879
|
);
|
|
11880
|
+
if (typeof timeoutSeconds === "object") {
|
|
11881
|
+
return timeoutSeconds;
|
|
11882
|
+
}
|
|
11692
11883
|
const cwd = resolveShellCwd2(state, params.cwd);
|
|
11693
11884
|
if (!cwd) {
|
|
11694
11885
|
return {
|
|
@@ -11729,15 +11920,15 @@ var createTaskHandlers = ({
|
|
|
11729
11920
|
});
|
|
11730
11921
|
return;
|
|
11731
11922
|
}
|
|
11732
|
-
const
|
|
11923
|
+
const background = params.background !== false;
|
|
11924
|
+
const parsed = parseShellSpawnRequest(state, params, { background });
|
|
11733
11925
|
if ("error" in parsed) {
|
|
11734
11926
|
sendError(id, parsed.error);
|
|
11735
11927
|
return;
|
|
11736
11928
|
}
|
|
11737
11929
|
try {
|
|
11738
|
-
const background = params.background !== false;
|
|
11739
11930
|
log2(
|
|
11740
|
-
`task.spawn kind=shell cwd=${parsed.cwd} timeout_s=${parsed.timeoutSeconds} background=${background} command="${parsed.commandSummary}"`
|
|
11931
|
+
`task.spawn kind=shell cwd=${parsed.cwd} timeout_s=${formatShellTimeoutForLog3(parsed.timeoutSeconds)} background=${background} command="${parsed.commandSummary}"`
|
|
11741
11932
|
);
|
|
11742
11933
|
const task = await tasks.spawn(
|
|
11743
11934
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codelia/runtime",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.48",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20 <25"
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"typecheck": "tsc --noEmit"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@codelia/config": "0.1.
|
|
27
|
-
"@codelia/config-loader": "0.1.
|
|
28
|
-
"@codelia/core": "0.1.
|
|
29
|
-
"@codelia/logger": "0.1.
|
|
30
|
-
"@codelia/model-metadata": "0.1.
|
|
31
|
-
"@codelia/protocol": "0.1.
|
|
32
|
-
"@codelia/shared-types": "0.1.
|
|
33
|
-
"@codelia/storage": "0.1.
|
|
26
|
+
"@codelia/config": "0.1.48",
|
|
27
|
+
"@codelia/config-loader": "0.1.48",
|
|
28
|
+
"@codelia/core": "0.1.48",
|
|
29
|
+
"@codelia/logger": "0.1.48",
|
|
30
|
+
"@codelia/model-metadata": "0.1.48",
|
|
31
|
+
"@codelia/protocol": "0.1.48",
|
|
32
|
+
"@codelia/shared-types": "0.1.48",
|
|
33
|
+
"@codelia/storage": "0.1.48",
|
|
34
34
|
"eventsource-parser": "^3.0.6",
|
|
35
35
|
"oauth4webapi": "^3.8.4",
|
|
36
36
|
"zod": "^4.3.5"
|