@codelia/runtime 0.1.45 → 0.1.47
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 +129 -46
- package/dist/index.js +129 -46
- 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,
|
|
@@ -5977,10 +5986,33 @@ var shellStateSchema = import_zod10.z.enum([
|
|
|
5977
5986
|
var shellRunSchema = import_zod10.z.object({
|
|
5978
5987
|
command: import_zod10.z.string().describe("Shell command to execute in the current workspace."),
|
|
5979
5988
|
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
|
-
`
|
|
5989
|
+
timeout: import_zod10.z.number().int().positive().optional().describe(
|
|
5990
|
+
`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 running until completion, cancel, or runtime exit.`
|
|
5982
5991
|
),
|
|
5983
|
-
background: import_zod10.z.boolean().optional().describe(
|
|
5992
|
+
background: import_zod10.z.boolean().optional().describe(
|
|
5993
|
+
"Return immediately with task info instead of waiting. Manage the task with shell_status/logs/wait/result/cancel. Default: false."
|
|
5994
|
+
)
|
|
5995
|
+
}).superRefine((input, ctx) => {
|
|
5996
|
+
if (input.timeout === void 0) {
|
|
5997
|
+
return;
|
|
5998
|
+
}
|
|
5999
|
+
if (input.background ?? false) {
|
|
6000
|
+
if (input.timeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
6001
|
+
ctx.addIssue({
|
|
6002
|
+
code: import_zod10.z.ZodIssueCode.custom,
|
|
6003
|
+
path: ["timeout"],
|
|
6004
|
+
message: `Background timeout must be ${MAX_EXECUTION_TIMEOUT_SECONDS} seconds or less. Omit timeout to run without an execution timer.`
|
|
6005
|
+
});
|
|
6006
|
+
}
|
|
6007
|
+
return;
|
|
6008
|
+
}
|
|
6009
|
+
if (input.timeout > MAX_TIMEOUT_SECONDS) {
|
|
6010
|
+
ctx.addIssue({
|
|
6011
|
+
code: import_zod10.z.ZodIssueCode.custom,
|
|
6012
|
+
path: ["timeout"],
|
|
6013
|
+
message: `Foreground timeout must be ${MAX_TIMEOUT_SECONDS} seconds or less.`
|
|
6014
|
+
});
|
|
6015
|
+
}
|
|
5984
6016
|
});
|
|
5985
6017
|
var shellTaskKeySchema = import_zod10.z.object({
|
|
5986
6018
|
key: import_zod10.z.string().describe("Canonical shell task key returned by shell or shell_list.")
|
|
@@ -6010,10 +6042,14 @@ var normalizeOptionalLabel = (value) => {
|
|
|
6010
6042
|
const label = value.trim();
|
|
6011
6043
|
return label.length > 0 ? label : void 0;
|
|
6012
6044
|
};
|
|
6013
|
-
var
|
|
6045
|
+
var resolveShellTimeoutSeconds = (value, background) => {
|
|
6046
|
+
if (background) {
|
|
6047
|
+
return value === void 0 ? void 0 : Math.max(1, Math.trunc(value));
|
|
6048
|
+
}
|
|
6014
6049
|
const requestedTimeout = value ?? DEFAULT_TIMEOUT_SECONDS;
|
|
6015
|
-
return Math.max(1, Math.min(requestedTimeout, MAX_TIMEOUT_SECONDS));
|
|
6050
|
+
return Math.max(1, Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS));
|
|
6016
6051
|
};
|
|
6052
|
+
var formatShellTimeoutForLog = (value) => value === void 0 ? "none" : String(value);
|
|
6017
6053
|
var normalizeShellTaskKey = (value) => {
|
|
6018
6054
|
const key = value.trim();
|
|
6019
6055
|
if (!key) {
|
|
@@ -6285,7 +6321,7 @@ var createShellTool = (sandboxKey, options = {}) => {
|
|
|
6285
6321
|
const shared = getSharedDeps(options);
|
|
6286
6322
|
return (0, import_core11.defineTool)({
|
|
6287
6323
|
name: "shell",
|
|
6288
|
-
description: "
|
|
6324
|
+
description: "Run a shell command in the sandbox. By default wait for completion; with `background=true`, return a task you can inspect, wait on, or cancel later.",
|
|
6289
6325
|
input: shellRunSchema,
|
|
6290
6326
|
execute: async (input, ctx) => {
|
|
6291
6327
|
const sandbox = await getSandboxContext(ctx, sandboxKey);
|
|
@@ -6295,11 +6331,11 @@ var createShellTool = (sandboxKey, options = {}) => {
|
|
|
6295
6331
|
throw new Error("command is required.");
|
|
6296
6332
|
}
|
|
6297
6333
|
const label = normalizeOptionalLabel(input.label);
|
|
6298
|
-
const timeoutSeconds = clampTimeoutSeconds(input.timeout);
|
|
6299
6334
|
const background = input.background ?? false;
|
|
6335
|
+
const timeoutSeconds = resolveShellTimeoutSeconds(input.timeout, background);
|
|
6300
6336
|
const commandSummary = summarizeCommand(command);
|
|
6301
6337
|
(0, import_logger.debugLog)(
|
|
6302
|
-
`shell.start cwd=${sandbox.workingDir} timeout_s=${timeoutSeconds} background=${background} command="${commandSummary}"`
|
|
6338
|
+
`shell.start cwd=${sandbox.workingDir} timeout_s=${formatShellTimeoutForLog(timeoutSeconds)} background=${background} command="${commandSummary}"`
|
|
6303
6339
|
);
|
|
6304
6340
|
try {
|
|
6305
6341
|
const taskId = import_node_crypto6.default.randomUUID();
|
|
@@ -11126,7 +11162,36 @@ var requireShellTask = async (taskManager, taskId) => {
|
|
|
11126
11162
|
}
|
|
11127
11163
|
return task;
|
|
11128
11164
|
};
|
|
11129
|
-
var
|
|
11165
|
+
var resolveShellTimeoutSeconds2 = (requestedTimeout, background) => {
|
|
11166
|
+
if (requestedTimeout !== void 0) {
|
|
11167
|
+
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
11168
|
+
return {
|
|
11169
|
+
error: {
|
|
11170
|
+
code: import_protocol6.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
11171
|
+
message: "timeout_seconds must be a positive number"
|
|
11172
|
+
}
|
|
11173
|
+
};
|
|
11174
|
+
}
|
|
11175
|
+
if (!background) {
|
|
11176
|
+
return Math.max(
|
|
11177
|
+
1,
|
|
11178
|
+
Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS)
|
|
11179
|
+
);
|
|
11180
|
+
}
|
|
11181
|
+
if (requestedTimeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
11182
|
+
return {
|
|
11183
|
+
error: {
|
|
11184
|
+
code: import_protocol6.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
11185
|
+
message: `background timeout_seconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less; omit timeout_seconds to run without an execution timer`
|
|
11186
|
+
}
|
|
11187
|
+
};
|
|
11188
|
+
}
|
|
11189
|
+
return Math.max(1, Math.trunc(requestedTimeout));
|
|
11190
|
+
}
|
|
11191
|
+
return background ? void 0 : DEFAULT_TIMEOUT_SECONDS;
|
|
11192
|
+
};
|
|
11193
|
+
var formatShellTimeoutForLog2 = (value) => value === void 0 ? "none" : String(value);
|
|
11194
|
+
var parseShellStartRequest = (state, params, options) => {
|
|
11130
11195
|
const command = params?.command?.trim() ?? "";
|
|
11131
11196
|
if (!command) {
|
|
11132
11197
|
return {
|
|
@@ -11136,19 +11201,13 @@ var parseShellStartRequest = (state, params) => {
|
|
|
11136
11201
|
}
|
|
11137
11202
|
};
|
|
11138
11203
|
}
|
|
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)
|
|
11204
|
+
const timeoutSeconds = resolveShellTimeoutSeconds2(
|
|
11205
|
+
params?.timeout_seconds,
|
|
11206
|
+
options.background
|
|
11151
11207
|
);
|
|
11208
|
+
if (typeof timeoutSeconds === "object") {
|
|
11209
|
+
return timeoutSeconds;
|
|
11210
|
+
}
|
|
11152
11211
|
const cwd = resolveShellCwd(state, params?.cwd);
|
|
11153
11212
|
if (!cwd) {
|
|
11154
11213
|
return {
|
|
@@ -11189,12 +11248,13 @@ var createShellHandlers = ({
|
|
|
11189
11248
|
};
|
|
11190
11249
|
};
|
|
11191
11250
|
const spawnShell = async (params, toolName) => {
|
|
11192
|
-
const
|
|
11251
|
+
const background = toolName === "shell.start";
|
|
11252
|
+
const parsed = parseShellStartRequest(state, params, { background });
|
|
11193
11253
|
if ("error" in parsed) {
|
|
11194
11254
|
throw parsed.error;
|
|
11195
11255
|
}
|
|
11196
11256
|
log2(
|
|
11197
|
-
`${toolName}.start origin=ui_bang cwd=${parsed.cwd} timeout_s=${parsed.timeoutSeconds} command="${parsed.commandSummary}"`
|
|
11257
|
+
`${toolName}.start origin=ui_bang cwd=${parsed.cwd} timeout_s=${formatShellTimeoutForLog2(parsed.timeoutSeconds)} command="${parsed.commandSummary}"`
|
|
11198
11258
|
);
|
|
11199
11259
|
const task = await shellTaskManager.spawn(
|
|
11200
11260
|
{
|
|
@@ -11622,7 +11682,36 @@ var toTaskInfo = (task) => ({
|
|
|
11622
11682
|
});
|
|
11623
11683
|
var isTaskKind = (value) => value === "shell" || value === "subagent";
|
|
11624
11684
|
var isTaskState = (value) => value === "queued" || value === "running" || value === "completed" || value === "failed" || value === "cancelled";
|
|
11625
|
-
var
|
|
11685
|
+
var resolveShellTimeoutSeconds3 = (requestedTimeout, background) => {
|
|
11686
|
+
if (requestedTimeout !== void 0) {
|
|
11687
|
+
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
11688
|
+
return {
|
|
11689
|
+
error: {
|
|
11690
|
+
code: import_protocol8.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
11691
|
+
message: "timeout_seconds must be a positive number"
|
|
11692
|
+
}
|
|
11693
|
+
};
|
|
11694
|
+
}
|
|
11695
|
+
if (!background) {
|
|
11696
|
+
return Math.max(
|
|
11697
|
+
1,
|
|
11698
|
+
Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS)
|
|
11699
|
+
);
|
|
11700
|
+
}
|
|
11701
|
+
if (requestedTimeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
11702
|
+
return {
|
|
11703
|
+
error: {
|
|
11704
|
+
code: import_protocol8.RPC_ERROR_CODE.INVALID_PARAMS,
|
|
11705
|
+
message: `background timeout_seconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less; omit timeout_seconds to run without an execution timer`
|
|
11706
|
+
}
|
|
11707
|
+
};
|
|
11708
|
+
}
|
|
11709
|
+
return Math.max(1, Math.trunc(requestedTimeout));
|
|
11710
|
+
}
|
|
11711
|
+
return background ? void 0 : DEFAULT_TIMEOUT_SECONDS;
|
|
11712
|
+
};
|
|
11713
|
+
var formatShellTimeoutForLog3 = (value) => value === void 0 ? "none" : String(value);
|
|
11714
|
+
var parseShellSpawnRequest = (state, params, options) => {
|
|
11626
11715
|
const command = params.command?.trim() ?? "";
|
|
11627
11716
|
if (!command) {
|
|
11628
11717
|
return {
|
|
@@ -11632,19 +11721,13 @@ var parseShellSpawnRequest = (state, params) => {
|
|
|
11632
11721
|
}
|
|
11633
11722
|
};
|
|
11634
11723
|
}
|
|
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)
|
|
11724
|
+
const timeoutSeconds = resolveShellTimeoutSeconds3(
|
|
11725
|
+
params.timeout_seconds,
|
|
11726
|
+
options.background
|
|
11647
11727
|
);
|
|
11728
|
+
if (typeof timeoutSeconds === "object") {
|
|
11729
|
+
return timeoutSeconds;
|
|
11730
|
+
}
|
|
11648
11731
|
const cwd = resolveShellCwd2(state, params.cwd);
|
|
11649
11732
|
if (!cwd) {
|
|
11650
11733
|
return {
|
|
@@ -11685,15 +11768,15 @@ var createTaskHandlers = ({
|
|
|
11685
11768
|
});
|
|
11686
11769
|
return;
|
|
11687
11770
|
}
|
|
11688
|
-
const
|
|
11771
|
+
const background = params.background !== false;
|
|
11772
|
+
const parsed = parseShellSpawnRequest(state, params, { background });
|
|
11689
11773
|
if ("error" in parsed) {
|
|
11690
11774
|
sendError(id, parsed.error);
|
|
11691
11775
|
return;
|
|
11692
11776
|
}
|
|
11693
11777
|
try {
|
|
11694
|
-
const background = params.background !== false;
|
|
11695
11778
|
log2(
|
|
11696
|
-
`task.spawn kind=shell cwd=${parsed.cwd} timeout_s=${parsed.timeoutSeconds} background=${background} command="${parsed.commandSummary}"`
|
|
11779
|
+
`task.spawn kind=shell cwd=${parsed.cwd} timeout_s=${formatShellTimeoutForLog3(parsed.timeoutSeconds)} background=${background} command="${parsed.commandSummary}"`
|
|
11697
11780
|
);
|
|
11698
11781
|
const task = await tasks.spawn(
|
|
11699
11782
|
{
|
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,
|
|
@@ -5985,10 +5994,33 @@ var shellStateSchema = z10.enum([
|
|
|
5985
5994
|
var shellRunSchema = z10.object({
|
|
5986
5995
|
command: z10.string().describe("Shell command to execute in the current workspace."),
|
|
5987
5996
|
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
|
-
`
|
|
5997
|
+
timeout: z10.number().int().positive().optional().describe(
|
|
5998
|
+
`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 running until completion, cancel, or runtime exit.`
|
|
5990
5999
|
),
|
|
5991
|
-
background: z10.boolean().optional().describe(
|
|
6000
|
+
background: z10.boolean().optional().describe(
|
|
6001
|
+
"Return immediately with task info instead of waiting. Manage the task with shell_status/logs/wait/result/cancel. Default: false."
|
|
6002
|
+
)
|
|
6003
|
+
}).superRefine((input, ctx) => {
|
|
6004
|
+
if (input.timeout === void 0) {
|
|
6005
|
+
return;
|
|
6006
|
+
}
|
|
6007
|
+
if (input.background ?? false) {
|
|
6008
|
+
if (input.timeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
6009
|
+
ctx.addIssue({
|
|
6010
|
+
code: z10.ZodIssueCode.custom,
|
|
6011
|
+
path: ["timeout"],
|
|
6012
|
+
message: `Background timeout must be ${MAX_EXECUTION_TIMEOUT_SECONDS} seconds or less. Omit timeout to run without an execution timer.`
|
|
6013
|
+
});
|
|
6014
|
+
}
|
|
6015
|
+
return;
|
|
6016
|
+
}
|
|
6017
|
+
if (input.timeout > MAX_TIMEOUT_SECONDS) {
|
|
6018
|
+
ctx.addIssue({
|
|
6019
|
+
code: z10.ZodIssueCode.custom,
|
|
6020
|
+
path: ["timeout"],
|
|
6021
|
+
message: `Foreground timeout must be ${MAX_TIMEOUT_SECONDS} seconds or less.`
|
|
6022
|
+
});
|
|
6023
|
+
}
|
|
5992
6024
|
});
|
|
5993
6025
|
var shellTaskKeySchema = z10.object({
|
|
5994
6026
|
key: z10.string().describe("Canonical shell task key returned by shell or shell_list.")
|
|
@@ -6018,10 +6050,14 @@ var normalizeOptionalLabel = (value) => {
|
|
|
6018
6050
|
const label = value.trim();
|
|
6019
6051
|
return label.length > 0 ? label : void 0;
|
|
6020
6052
|
};
|
|
6021
|
-
var
|
|
6053
|
+
var resolveShellTimeoutSeconds = (value, background) => {
|
|
6054
|
+
if (background) {
|
|
6055
|
+
return value === void 0 ? void 0 : Math.max(1, Math.trunc(value));
|
|
6056
|
+
}
|
|
6022
6057
|
const requestedTimeout = value ?? DEFAULT_TIMEOUT_SECONDS;
|
|
6023
|
-
return Math.max(1, Math.min(requestedTimeout, MAX_TIMEOUT_SECONDS));
|
|
6058
|
+
return Math.max(1, Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS));
|
|
6024
6059
|
};
|
|
6060
|
+
var formatShellTimeoutForLog = (value) => value === void 0 ? "none" : String(value);
|
|
6025
6061
|
var normalizeShellTaskKey = (value) => {
|
|
6026
6062
|
const key = value.trim();
|
|
6027
6063
|
if (!key) {
|
|
@@ -6293,7 +6329,7 @@ var createShellTool = (sandboxKey, options = {}) => {
|
|
|
6293
6329
|
const shared = getSharedDeps(options);
|
|
6294
6330
|
return defineTool9({
|
|
6295
6331
|
name: "shell",
|
|
6296
|
-
description: "
|
|
6332
|
+
description: "Run a shell command in the sandbox. By default wait for completion; with `background=true`, return a task you can inspect, wait on, or cancel later.",
|
|
6297
6333
|
input: shellRunSchema,
|
|
6298
6334
|
execute: async (input, ctx) => {
|
|
6299
6335
|
const sandbox = await getSandboxContext(ctx, sandboxKey);
|
|
@@ -6303,11 +6339,11 @@ var createShellTool = (sandboxKey, options = {}) => {
|
|
|
6303
6339
|
throw new Error("command is required.");
|
|
6304
6340
|
}
|
|
6305
6341
|
const label = normalizeOptionalLabel(input.label);
|
|
6306
|
-
const timeoutSeconds = clampTimeoutSeconds(input.timeout);
|
|
6307
6342
|
const background = input.background ?? false;
|
|
6343
|
+
const timeoutSeconds = resolveShellTimeoutSeconds(input.timeout, background);
|
|
6308
6344
|
const commandSummary = summarizeCommand(command);
|
|
6309
6345
|
debugLog(
|
|
6310
|
-
`shell.start cwd=${sandbox.workingDir} timeout_s=${timeoutSeconds} background=${background} command="${commandSummary}"`
|
|
6346
|
+
`shell.start cwd=${sandbox.workingDir} timeout_s=${formatShellTimeoutForLog(timeoutSeconds)} background=${background} command="${commandSummary}"`
|
|
6311
6347
|
);
|
|
6312
6348
|
try {
|
|
6313
6349
|
const taskId = crypto6.randomUUID();
|
|
@@ -11166,7 +11202,36 @@ var requireShellTask = async (taskManager, taskId) => {
|
|
|
11166
11202
|
}
|
|
11167
11203
|
return task;
|
|
11168
11204
|
};
|
|
11169
|
-
var
|
|
11205
|
+
var resolveShellTimeoutSeconds2 = (requestedTimeout, background) => {
|
|
11206
|
+
if (requestedTimeout !== void 0) {
|
|
11207
|
+
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
11208
|
+
return {
|
|
11209
|
+
error: {
|
|
11210
|
+
code: RPC_ERROR_CODE5.INVALID_PARAMS,
|
|
11211
|
+
message: "timeout_seconds must be a positive number"
|
|
11212
|
+
}
|
|
11213
|
+
};
|
|
11214
|
+
}
|
|
11215
|
+
if (!background) {
|
|
11216
|
+
return Math.max(
|
|
11217
|
+
1,
|
|
11218
|
+
Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS)
|
|
11219
|
+
);
|
|
11220
|
+
}
|
|
11221
|
+
if (requestedTimeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
11222
|
+
return {
|
|
11223
|
+
error: {
|
|
11224
|
+
code: RPC_ERROR_CODE5.INVALID_PARAMS,
|
|
11225
|
+
message: `background timeout_seconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less; omit timeout_seconds to run without an execution timer`
|
|
11226
|
+
}
|
|
11227
|
+
};
|
|
11228
|
+
}
|
|
11229
|
+
return Math.max(1, Math.trunc(requestedTimeout));
|
|
11230
|
+
}
|
|
11231
|
+
return background ? void 0 : DEFAULT_TIMEOUT_SECONDS;
|
|
11232
|
+
};
|
|
11233
|
+
var formatShellTimeoutForLog2 = (value) => value === void 0 ? "none" : String(value);
|
|
11234
|
+
var parseShellStartRequest = (state, params, options) => {
|
|
11170
11235
|
const command = params?.command?.trim() ?? "";
|
|
11171
11236
|
if (!command) {
|
|
11172
11237
|
return {
|
|
@@ -11176,19 +11241,13 @@ var parseShellStartRequest = (state, params) => {
|
|
|
11176
11241
|
}
|
|
11177
11242
|
};
|
|
11178
11243
|
}
|
|
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)
|
|
11244
|
+
const timeoutSeconds = resolveShellTimeoutSeconds2(
|
|
11245
|
+
params?.timeout_seconds,
|
|
11246
|
+
options.background
|
|
11191
11247
|
);
|
|
11248
|
+
if (typeof timeoutSeconds === "object") {
|
|
11249
|
+
return timeoutSeconds;
|
|
11250
|
+
}
|
|
11192
11251
|
const cwd = resolveShellCwd(state, params?.cwd);
|
|
11193
11252
|
if (!cwd) {
|
|
11194
11253
|
return {
|
|
@@ -11229,12 +11288,13 @@ var createShellHandlers = ({
|
|
|
11229
11288
|
};
|
|
11230
11289
|
};
|
|
11231
11290
|
const spawnShell = async (params, toolName) => {
|
|
11232
|
-
const
|
|
11291
|
+
const background = toolName === "shell.start";
|
|
11292
|
+
const parsed = parseShellStartRequest(state, params, { background });
|
|
11233
11293
|
if ("error" in parsed) {
|
|
11234
11294
|
throw parsed.error;
|
|
11235
11295
|
}
|
|
11236
11296
|
log2(
|
|
11237
|
-
`${toolName}.start origin=ui_bang cwd=${parsed.cwd} timeout_s=${parsed.timeoutSeconds} command="${parsed.commandSummary}"`
|
|
11297
|
+
`${toolName}.start origin=ui_bang cwd=${parsed.cwd} timeout_s=${formatShellTimeoutForLog2(parsed.timeoutSeconds)} command="${parsed.commandSummary}"`
|
|
11238
11298
|
);
|
|
11239
11299
|
const task = await shellTaskManager.spawn(
|
|
11240
11300
|
{
|
|
@@ -11666,7 +11726,36 @@ var toTaskInfo = (task) => ({
|
|
|
11666
11726
|
});
|
|
11667
11727
|
var isTaskKind = (value) => value === "shell" || value === "subagent";
|
|
11668
11728
|
var isTaskState = (value) => value === "queued" || value === "running" || value === "completed" || value === "failed" || value === "cancelled";
|
|
11669
|
-
var
|
|
11729
|
+
var resolveShellTimeoutSeconds3 = (requestedTimeout, background) => {
|
|
11730
|
+
if (requestedTimeout !== void 0) {
|
|
11731
|
+
if (!Number.isFinite(requestedTimeout) || requestedTimeout <= 0) {
|
|
11732
|
+
return {
|
|
11733
|
+
error: {
|
|
11734
|
+
code: RPC_ERROR_CODE7.INVALID_PARAMS,
|
|
11735
|
+
message: "timeout_seconds must be a positive number"
|
|
11736
|
+
}
|
|
11737
|
+
};
|
|
11738
|
+
}
|
|
11739
|
+
if (!background) {
|
|
11740
|
+
return Math.max(
|
|
11741
|
+
1,
|
|
11742
|
+
Math.min(Math.trunc(requestedTimeout), MAX_TIMEOUT_SECONDS)
|
|
11743
|
+
);
|
|
11744
|
+
}
|
|
11745
|
+
if (requestedTimeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
|
|
11746
|
+
return {
|
|
11747
|
+
error: {
|
|
11748
|
+
code: RPC_ERROR_CODE7.INVALID_PARAMS,
|
|
11749
|
+
message: `background timeout_seconds must be ${MAX_EXECUTION_TIMEOUT_SECONDS} or less; omit timeout_seconds to run without an execution timer`
|
|
11750
|
+
}
|
|
11751
|
+
};
|
|
11752
|
+
}
|
|
11753
|
+
return Math.max(1, Math.trunc(requestedTimeout));
|
|
11754
|
+
}
|
|
11755
|
+
return background ? void 0 : DEFAULT_TIMEOUT_SECONDS;
|
|
11756
|
+
};
|
|
11757
|
+
var formatShellTimeoutForLog3 = (value) => value === void 0 ? "none" : String(value);
|
|
11758
|
+
var parseShellSpawnRequest = (state, params, options) => {
|
|
11670
11759
|
const command = params.command?.trim() ?? "";
|
|
11671
11760
|
if (!command) {
|
|
11672
11761
|
return {
|
|
@@ -11676,19 +11765,13 @@ var parseShellSpawnRequest = (state, params) => {
|
|
|
11676
11765
|
}
|
|
11677
11766
|
};
|
|
11678
11767
|
}
|
|
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)
|
|
11768
|
+
const timeoutSeconds = resolveShellTimeoutSeconds3(
|
|
11769
|
+
params.timeout_seconds,
|
|
11770
|
+
options.background
|
|
11691
11771
|
);
|
|
11772
|
+
if (typeof timeoutSeconds === "object") {
|
|
11773
|
+
return timeoutSeconds;
|
|
11774
|
+
}
|
|
11692
11775
|
const cwd = resolveShellCwd2(state, params.cwd);
|
|
11693
11776
|
if (!cwd) {
|
|
11694
11777
|
return {
|
|
@@ -11729,15 +11812,15 @@ var createTaskHandlers = ({
|
|
|
11729
11812
|
});
|
|
11730
11813
|
return;
|
|
11731
11814
|
}
|
|
11732
|
-
const
|
|
11815
|
+
const background = params.background !== false;
|
|
11816
|
+
const parsed = parseShellSpawnRequest(state, params, { background });
|
|
11733
11817
|
if ("error" in parsed) {
|
|
11734
11818
|
sendError(id, parsed.error);
|
|
11735
11819
|
return;
|
|
11736
11820
|
}
|
|
11737
11821
|
try {
|
|
11738
|
-
const background = params.background !== false;
|
|
11739
11822
|
log2(
|
|
11740
|
-
`task.spawn kind=shell cwd=${parsed.cwd} timeout_s=${parsed.timeoutSeconds} background=${background} command="${parsed.commandSummary}"`
|
|
11823
|
+
`task.spawn kind=shell cwd=${parsed.cwd} timeout_s=${formatShellTimeoutForLog3(parsed.timeoutSeconds)} background=${background} command="${parsed.commandSummary}"`
|
|
11741
11824
|
);
|
|
11742
11825
|
const task = await tasks.spawn(
|
|
11743
11826
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codelia/runtime",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.47",
|
|
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.47",
|
|
27
|
+
"@codelia/config-loader": "0.1.47",
|
|
28
|
+
"@codelia/core": "0.1.47",
|
|
29
|
+
"@codelia/logger": "0.1.47",
|
|
30
|
+
"@codelia/model-metadata": "0.1.47",
|
|
31
|
+
"@codelia/protocol": "0.1.47",
|
|
32
|
+
"@codelia/shared-types": "0.1.47",
|
|
33
|
+
"@codelia/storage": "0.1.47",
|
|
34
34
|
"eventsource-parser": "^3.0.6",
|
|
35
35
|
"oauth4webapi": "^3.8.4",
|
|
36
36
|
"zod": "^4.3.5"
|