@codelia/runtime 0.1.60 → 0.1.62

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 CHANGED
@@ -882,7 +882,9 @@ var normalizeExecutionEnvironmentConfig = (value) => {
882
882
  ...configuredCommands
883
883
  ];
884
884
  const commands = Array.from(
885
- new Map(baseCommands.map((command) => [command.join("\0"), command])).values()
885
+ new Map(
886
+ baseCommands.map((command) => [command.join("\0"), command])
887
+ ).values()
886
888
  );
887
889
  return {
888
890
  startupChecks: {
@@ -2019,7 +2021,7 @@ var describeExecutionEnvironmentHost = () => {
2019
2021
  };
2020
2022
  };
2021
2023
  var probeExecutionEnvironmentCommand = (command, timeoutMs, workingDir, probeOptions = {}) => {
2022
- if (command.length === 0 || command[0].trim().length === 0) {
2024
+ if (command.length === 0 || command[0]?.trim().length === 0) {
2023
2025
  return Promise.resolve("invalid command");
2024
2026
  }
2025
2027
  return new Promise((resolve) => {
@@ -2051,7 +2053,9 @@ var probeExecutionEnvironmentCommand = (command, timeoutMs, workingDir, probeOpt
2051
2053
  workingDir
2052
2054
  );
2053
2055
  } catch (error) {
2054
- finish(`error: ${error instanceof Error ? error.message : String(error)}`);
2056
+ finish(
2057
+ `error: ${error instanceof Error ? error.message : String(error)}`
2058
+ );
2055
2059
  return;
2056
2060
  }
2057
2061
  timeoutHandle = setTimeout(() => {
@@ -2122,9 +2126,7 @@ var formatExecutionEnvironmentContext = (options) => {
2122
2126
  if (options.startupChecks && options.startupChecks.length > 0) {
2123
2127
  lines.push("", "startup checks:");
2124
2128
  for (const check of options.startupChecks) {
2125
- lines.push(
2126
- `- ${formatCommandLabel(check.command)} => ${check.summary}`
2127
- );
2129
+ lines.push(`- ${formatCommandLabel(check.command)} => ${check.summary}`);
2128
2130
  }
2129
2131
  }
2130
2132
  lines.push("</execution_environment>");
@@ -6169,7 +6171,9 @@ var createReadLineTool = (sandboxKey) => (0, import_core9.defineTool)({
6169
6171
  ),
6170
6172
  line_number: import_zod8.z.number().int().positive().describe("1-based line number to read."),
6171
6173
  char_offset: import_zod8.z.number().int().nonnegative().optional().describe("0-based grapheme offset in the target line. Default 0."),
6172
- char_limit: import_zod8.z.number().int().positive().max(MAX_CHAR_LIMIT).optional().describe(`Max graphemes to return. Default 10000, Max ${MAX_CHAR_LIMIT}.`)
6174
+ char_limit: import_zod8.z.number().int().positive().max(MAX_CHAR_LIMIT).optional().describe(
6175
+ `Max graphemes to return. Default 10000, Max ${MAX_CHAR_LIMIT}.`
6176
+ )
6173
6177
  }),
6174
6178
  execute: async (input, ctx) => {
6175
6179
  let resolved;
@@ -6924,6 +6928,7 @@ var SHELL_LABEL_MAX_CHARS = 80;
6924
6928
  var SHELL_LIST_DEFAULT_LIMIT = 20;
6925
6929
  var SHELL_LIST_MAX_LIMIT = 100;
6926
6930
  var SHELL_LOGS_MAX_TAIL_LINES = 500;
6931
+ var SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT = false;
6927
6932
  var shellStateSchema = import_zod10.z.enum([
6928
6933
  "queued",
6929
6934
  "running",
@@ -6943,6 +6948,9 @@ var shellRunSchema = import_zod10.z.object({
6943
6948
  ),
6944
6949
  detached_wait: import_zod10.z.boolean().optional().describe(
6945
6950
  "Skip the attached wait and return the task key immediately. The runtime still owns the child process. Use this only for finite jobs you will later inspect, wait on, or cancel. If you need a service-style process to keep running independently, start it with an explicit OS/shell-native out-of-process method such as `nohup`, `setsid`, `disown`, a service manager, or `docker compose up -d`, and verify readiness separately. Default: false."
6951
+ ),
6952
+ include_stderr_on_success: import_zod10.z.boolean().optional().describe(
6953
+ `Include stderr when the command succeeds. Default: ${String(SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT)}. Set true to include success-case stderr in terminal results.`
6946
6954
  )
6947
6955
  }).superRefine((input, ctx) => {
6948
6956
  if (input.timeout === void 0) {
@@ -6969,11 +6977,18 @@ var shellRunSchema = import_zod10.z.object({
6969
6977
  var shellTaskKeySchema = import_zod10.z.object({
6970
6978
  key: import_zod10.z.string().describe("Canonical shell task key returned by shell or shell_list.")
6971
6979
  });
6980
+ var shellSuccessStderrSchema = {
6981
+ include_stderr_on_success: import_zod10.z.boolean().optional().describe(
6982
+ `Include stderr when the command succeeds. Default: ${String(SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT)}. Set true to include success-case stderr in terminal results.`
6983
+ )
6984
+ };
6972
6985
  var shellWaitSchema = shellTaskKeySchema.extend({
6973
6986
  wait_timeout: import_zod10.z.number().int().positive().max(MAX_TIMEOUT_SECONDS).optional().describe(
6974
6987
  `Attached wait window in seconds. Default: ${DEFAULT_TIMEOUT_SECONDS}. Max ${MAX_TIMEOUT_SECONDS}. If the task is still running when the window expires, the tool returns compact status JSON instead of hanging.`
6975
- )
6988
+ ),
6989
+ ...shellSuccessStderrSchema
6976
6990
  });
6991
+ var shellResultSchema = shellTaskKeySchema.extend(shellSuccessStderrSchema);
6977
6992
  var shellStreamSchema = import_zod10.z.enum(["stdout", "stderr"]);
6978
6993
  var shellListSchema = import_zod10.z.object({
6979
6994
  limit: import_zod10.z.number().int().positive().max(SHELL_LIST_MAX_LIMIT).optional().describe(
@@ -7057,26 +7072,11 @@ var trimNonEmpty = (value) => {
7057
7072
  const trimmed = value.trimEnd();
7058
7073
  return trimmed.trim().length > 0 ? trimmed : null;
7059
7074
  };
7060
- var pickShellOutput = (task) => {
7061
- const stdout = trimNonEmpty(task.result?.stdout);
7062
- const stderr = trimNonEmpty(task.result?.stderr);
7075
+ var shellTerminalUsesCompactSuccessStreams = (task) => {
7063
7076
  const exitCode = task.result?.exit_code;
7064
- const preferError = task.state === "failed" || task.state === "cancelled" || exitCode !== null && exitCode !== void 0 && exitCode !== 0;
7065
- const primaryStream = preferError ? "stderr" : "stdout";
7066
- const primaryContent = primaryStream === "stderr" ? stderr : stdout;
7067
- const secondaryContent = primaryStream === "stderr" ? stdout : stderr;
7068
- const selectedStream = primaryContent ? primaryStream : secondaryContent ? primaryStream === "stderr" ? "stdout" : "stderr" : null;
7069
- if (!selectedStream) {
7070
- return null;
7071
- }
7072
- const field = preferError ? "error_output" : "output";
7073
- const cacheId = selectedStream === "stderr" ? task.result?.stderr_cache_id : task.result?.stdout_cache_id;
7074
- return {
7075
- field,
7076
- content: selectedStream === "stderr" ? stderr ?? "" : stdout ?? "",
7077
- ...cacheId ? { cacheId } : {}
7078
- };
7077
+ return task.state === "completed" && (exitCode === null || exitCode === void 0 || exitCode === 0);
7079
7078
  };
7079
+ var resolveIncludeStderrOnSuccess = (value) => value ?? SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT;
7080
7080
  var shellBasePayload = (task) => ({
7081
7081
  key: getShellTaskKey(task),
7082
7082
  state: task.state,
@@ -7088,8 +7088,11 @@ var shellStatusPayload = (task, options = {}) => ({
7088
7088
  ...options.stillRunning ? { still_running: true } : {},
7089
7089
  ...options.aborted ? { aborted: true } : {}
7090
7090
  });
7091
- var shellTerminalPayload = (task) => {
7091
+ var shellTerminalPayload = (task, options = {}) => {
7092
7092
  const payload = shellBasePayload(task);
7093
+ const stdout = trimNonEmpty(task.result?.stdout);
7094
+ const stderr = trimNonEmpty(task.result?.stderr);
7095
+ const compactSuccess = !resolveIncludeStderrOnSuccess(options.includeStderrOnSuccess) && shellTerminalUsesCompactSuccessStreams(task);
7093
7096
  if (task.result?.exit_code !== void 0 && task.result.exit_code !== null) {
7094
7097
  payload.exit_code = task.result.exit_code;
7095
7098
  }
@@ -7102,11 +7105,16 @@ var shellTerminalPayload = (task) => {
7102
7105
  if (task.cancellation_reason) {
7103
7106
  payload.cancellation_reason = task.cancellation_reason;
7104
7107
  }
7105
- const output = pickShellOutput(task);
7106
- if (output) {
7107
- payload[output.field] = output.content;
7108
- if (output.cacheId) {
7109
- payload.cache_id = output.cacheId;
7108
+ if (stdout) {
7109
+ payload.stdout = stdout;
7110
+ if (task.result?.stdout_cache_id) {
7111
+ payload.stdout_cache_id = task.result.stdout_cache_id;
7112
+ }
7113
+ }
7114
+ if (!compactSuccess && stderr) {
7115
+ payload.stderr = stderr;
7116
+ if (task.result?.stderr_cache_id) {
7117
+ payload.stderr_cache_id = task.result.stderr_cache_id;
7110
7118
  }
7111
7119
  }
7112
7120
  return payload;
@@ -7345,7 +7353,7 @@ var createShellTool = (sandboxKey, options = {}) => {
7345
7353
  const shared = getSharedDeps(options);
7346
7354
  return (0, import_core11.defineTool)({
7347
7355
  name: "shell",
7348
- description: "Run a shell command as a runtime-managed child process in the sandbox. By default wait for completion; with `detached_wait=true`, skip the attached wait and return compact JSON with the task key for follow-up tools.",
7356
+ description: "Run a shell command as a runtime-managed child process in the sandbox. Terminal results use `stdout`/`stderr` stream fields; successful results suppress `stderr` by default unless `include_stderr_on_success=true`, and `shell_logs` is available when you need explicit stream reads. By default wait for completion; with `detached_wait=true`, skip the attached wait and return compact JSON with the task key for follow-up tools.",
7349
7357
  input: shellRunSchema,
7350
7358
  execute: async (input, ctx) => {
7351
7359
  const sandbox = await getSandboxContext(ctx, sandboxKey);
@@ -7398,7 +7406,9 @@ var createShellTool = (sandboxKey, options = {}) => {
7398
7406
  (0, import_logger.debugLog)(
7399
7407
  `shell.done task_id=${task.task_id} state=${settled.state} duration_ms=${settled.result?.duration_ms ?? -1}`
7400
7408
  );
7401
- return shellTerminalPayload(settled);
7409
+ return shellTerminalPayload(settled, {
7410
+ includeStderrOnSuccess: input.include_stderr_on_success
7411
+ });
7402
7412
  } catch (error) {
7403
7413
  throw formatTaskError(error);
7404
7414
  }
@@ -7456,7 +7466,7 @@ var createShellLogsTool = (options = {}) => {
7456
7466
  const shared = getSharedDeps(options);
7457
7467
  return (0, import_core11.defineTool)({
7458
7468
  name: "shell_logs",
7459
- description: "Read recent stdout or stderr for a running or finished shell task.",
7469
+ description: "Read recent stdout or stderr for a running or finished shell task. Use this when a compact shell terminal result omitted a stream, such as `stderr` on success.",
7460
7470
  input: shellLogsSchema,
7461
7471
  execute: async (input) => {
7462
7472
  try {
@@ -7478,7 +7488,7 @@ var createShellWaitTool = (options = {}) => {
7478
7488
  const shared = getSharedDeps(options);
7479
7489
  return (0, import_core11.defineTool)({
7480
7490
  name: "shell_wait",
7481
- description: "Wait for a shell task within a bounded window and return compact JSON describing either the running status or terminal result.",
7491
+ description: "Wait for a shell task within a bounded window and return compact JSON describing either the running status or a terminal result with `stdout`/`stderr` stream fields. Successful terminal results suppress `stderr` by default unless `include_stderr_on_success=true`; use `shell_logs` for explicit stream reads.",
7482
7492
  input: shellWaitSchema,
7483
7493
  execute: async (input, ctx) => {
7484
7494
  try {
@@ -7500,7 +7510,9 @@ var createShellWaitTool = (options = {}) => {
7500
7510
  stillRunning: result.stillRunning
7501
7511
  });
7502
7512
  }
7503
- return shellTerminalPayload(result.task);
7513
+ return shellTerminalPayload(result.task, {
7514
+ includeStderrOnSuccess: waitInput.include_stderr_on_success
7515
+ });
7504
7516
  } catch (error) {
7505
7517
  throw formatTaskError(error);
7506
7518
  }
@@ -7511,12 +7523,15 @@ var createShellResultTool = (options = {}) => {
7511
7523
  const shared = getSharedDeps(options);
7512
7524
  return (0, import_core11.defineTool)({
7513
7525
  name: "shell_result",
7514
- description: "Read the retained terminal result for a shell task as compact JSON.",
7515
- input: shellTaskKeySchema,
7526
+ description: "Read the retained terminal result for a shell task as compact JSON with `stdout`/`stderr` stream fields. Successful terminal results suppress `stderr` by default unless `include_stderr_on_success=true`; use `shell_logs` for explicit stream reads.",
7527
+ input: shellResultSchema,
7516
7528
  execute: async (input) => {
7517
7529
  try {
7518
- const task = await resolveShellTask(shared.tasks, input);
7519
- return isTerminalTaskState(task.state) ? shellTerminalPayload(task) : shellStatusPayload(task);
7530
+ const resultInput = input;
7531
+ const task = await resolveShellTask(shared.tasks, resultInput);
7532
+ return isTerminalTaskState(task.state) ? shellTerminalPayload(task, {
7533
+ includeStderrOnSuccess: resultInput.include_stderr_on_success
7534
+ }) : shellStatusPayload(task);
7520
7535
  } catch (error) {
7521
7536
  throw formatTaskError(error);
7522
7537
  }
@@ -7606,7 +7621,9 @@ var createSkillSearchTool = (skillsResolverKey) => (0, import_core13.defineTool)
7606
7621
  description: "Search installed local skills by name, description, or path.",
7607
7622
  input: import_zod12.z.object({
7608
7623
  query: import_zod12.z.string().min(1).describe("Search query text."),
7609
- limit: import_zod12.z.number().int().positive().optional().describe("Optional max result count. Higher values may be clamped by config."),
7624
+ limit: import_zod12.z.number().int().positive().optional().describe(
7625
+ "Optional max result count. Higher values may be clamped by config."
7626
+ ),
7610
7627
  scope: import_zod12.z.enum(["repo", "user"]).optional().describe("Optional scope filter.")
7611
7628
  }),
7612
7629
  execute: async (input, ctx) => {
@@ -8068,7 +8085,9 @@ var createViewImageTool = (sandboxKey) => (0, import_core17.defineTool)({
8068
8085
  file_path: import_zod16.z.string().describe(
8069
8086
  "Single local png/jpeg/webp/gif image path. Sandbox-bounded unless full-access mode is active."
8070
8087
  ),
8071
- detail: import_zod16.z.enum(["auto", "low", "high"]).optional().describe("Model image-detail hint (`auto`/`low`/`high`). Default auto."),
8088
+ detail: import_zod16.z.enum(["auto", "low", "high"]).optional().describe(
8089
+ "Model image-detail hint (`auto`/`low`/`high`). Default auto."
8090
+ ),
8072
8091
  max_bytes: import_zod16.z.number().int().positive().max(MAX_MAX_BYTES).optional().describe("Max file size in bytes. Default 5242880, Max 10485760.")
8073
8092
  }),
8074
8093
  execute: async (input, ctx) => {
@@ -8379,8 +8398,12 @@ var createWebfetchTool = () => (0, import_core18.defineTool)({
8379
8398
  input: import_zod17.z.object({
8380
8399
  url: import_zod17.z.string().min(1).describe("HTTP(S) URL to fetch."),
8381
8400
  output_format: import_zod17.z.enum(["markdown", "text", "html"]).optional().describe("Normalized output format. Default markdown."),
8382
- timeout_ms: import_zod17.z.number().int().positive().max(MAX_TIMEOUT_MS).optional().describe(`Fetch timeout in ms. Default ${DEFAULT_TIMEOUT_MS3}, Max ${MAX_TIMEOUT_MS}.`),
8383
- max_bytes: import_zod17.z.number().int().positive().max(MAX_MAX_BYTES2).optional().describe(`Max response bytes to keep. Default ${DEFAULT_MAX_BYTES3}, Max ${MAX_MAX_BYTES2}.`)
8401
+ timeout_ms: import_zod17.z.number().int().positive().max(MAX_TIMEOUT_MS).optional().describe(
8402
+ `Fetch timeout in ms. Default ${DEFAULT_TIMEOUT_MS3}, Max ${MAX_TIMEOUT_MS}.`
8403
+ ),
8404
+ max_bytes: import_zod17.z.number().int().positive().max(MAX_MAX_BYTES2).optional().describe(
8405
+ `Max response bytes to keep. Default ${DEFAULT_MAX_BYTES3}, Max ${MAX_MAX_BYTES2}.`
8406
+ )
8384
8407
  }),
8385
8408
  execute: async (input) => {
8386
8409
  let url;
@@ -8395,6 +8418,7 @@ var createWebfetchTool = () => (0, import_core18.defineTool)({
8395
8418
  const timeoutMs = input.timeout_ms ?? DEFAULT_TIMEOUT_MS3;
8396
8419
  const maxBytes = input.max_bytes ?? DEFAULT_MAX_BYTES3;
8397
8420
  const outputFormat = input.output_format ?? "markdown";
8421
+ const startedAt = Date.now();
8398
8422
  const controller = new AbortController();
8399
8423
  const timeout = setTimeout(() => controller.abort(), timeoutMs);
8400
8424
  try {
@@ -8424,6 +8448,7 @@ var createWebfetchTool = () => (0, import_core18.defineTool)({
8424
8448
  } else {
8425
8449
  content = normalizeWhitespace(rawText);
8426
8450
  }
8451
+ const durationMs = Math.max(0, Date.now() - startedAt);
8427
8452
  return {
8428
8453
  url: input.url,
8429
8454
  final_url: response.url || input.url,
@@ -8434,7 +8459,8 @@ var createWebfetchTool = () => (0, import_core18.defineTool)({
8434
8459
  title: isHtml ? extractTitle(rawText) ?? null : null,
8435
8460
  content,
8436
8461
  truncated: body.truncated,
8437
- byte_size: body.byteSize
8462
+ byte_size: body.byteSize,
8463
+ duration_ms: durationMs
8438
8464
  };
8439
8465
  } catch (error) {
8440
8466
  const classified = classifyFetchError(error, timeoutMs);
package/dist/index.js CHANGED
@@ -878,7 +878,9 @@ var normalizeExecutionEnvironmentConfig = (value) => {
878
878
  ...configuredCommands
879
879
  ];
880
880
  const commands = Array.from(
881
- new Map(baseCommands.map((command) => [command.join("\0"), command])).values()
881
+ new Map(
882
+ baseCommands.map((command) => [command.join("\0"), command])
883
+ ).values()
882
884
  );
883
885
  return {
884
886
  startupChecks: {
@@ -2015,7 +2017,7 @@ var describeExecutionEnvironmentHost = () => {
2015
2017
  };
2016
2018
  };
2017
2019
  var probeExecutionEnvironmentCommand = (command, timeoutMs, workingDir, probeOptions = {}) => {
2018
- if (command.length === 0 || command[0].trim().length === 0) {
2020
+ if (command.length === 0 || command[0]?.trim().length === 0) {
2019
2021
  return Promise.resolve("invalid command");
2020
2022
  }
2021
2023
  return new Promise((resolve) => {
@@ -2047,7 +2049,9 @@ var probeExecutionEnvironmentCommand = (command, timeoutMs, workingDir, probeOpt
2047
2049
  workingDir
2048
2050
  );
2049
2051
  } catch (error) {
2050
- finish(`error: ${error instanceof Error ? error.message : String(error)}`);
2052
+ finish(
2053
+ `error: ${error instanceof Error ? error.message : String(error)}`
2054
+ );
2051
2055
  return;
2052
2056
  }
2053
2057
  timeoutHandle = setTimeout(() => {
@@ -2118,9 +2122,7 @@ var formatExecutionEnvironmentContext = (options) => {
2118
2122
  if (options.startupChecks && options.startupChecks.length > 0) {
2119
2123
  lines.push("", "startup checks:");
2120
2124
  for (const check of options.startupChecks) {
2121
- lines.push(
2122
- `- ${formatCommandLabel(check.command)} => ${check.summary}`
2123
- );
2125
+ lines.push(`- ${formatCommandLabel(check.command)} => ${check.summary}`);
2124
2126
  }
2125
2127
  }
2126
2128
  lines.push("</execution_environment>");
@@ -6171,7 +6173,9 @@ var createReadLineTool = (sandboxKey) => defineTool7({
6171
6173
  ),
6172
6174
  line_number: z8.number().int().positive().describe("1-based line number to read."),
6173
6175
  char_offset: z8.number().int().nonnegative().optional().describe("0-based grapheme offset in the target line. Default 0."),
6174
- char_limit: z8.number().int().positive().max(MAX_CHAR_LIMIT).optional().describe(`Max graphemes to return. Default 10000, Max ${MAX_CHAR_LIMIT}.`)
6176
+ char_limit: z8.number().int().positive().max(MAX_CHAR_LIMIT).optional().describe(
6177
+ `Max graphemes to return. Default 10000, Max ${MAX_CHAR_LIMIT}.`
6178
+ )
6175
6179
  }),
6176
6180
  execute: async (input, ctx) => {
6177
6181
  let resolved;
@@ -6928,6 +6932,7 @@ var SHELL_LABEL_MAX_CHARS = 80;
6928
6932
  var SHELL_LIST_DEFAULT_LIMIT = 20;
6929
6933
  var SHELL_LIST_MAX_LIMIT = 100;
6930
6934
  var SHELL_LOGS_MAX_TAIL_LINES = 500;
6935
+ var SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT = false;
6931
6936
  var shellStateSchema = z10.enum([
6932
6937
  "queued",
6933
6938
  "running",
@@ -6947,6 +6952,9 @@ var shellRunSchema = z10.object({
6947
6952
  ),
6948
6953
  detached_wait: z10.boolean().optional().describe(
6949
6954
  "Skip the attached wait and return the task key immediately. The runtime still owns the child process. Use this only for finite jobs you will later inspect, wait on, or cancel. If you need a service-style process to keep running independently, start it with an explicit OS/shell-native out-of-process method such as `nohup`, `setsid`, `disown`, a service manager, or `docker compose up -d`, and verify readiness separately. Default: false."
6955
+ ),
6956
+ include_stderr_on_success: z10.boolean().optional().describe(
6957
+ `Include stderr when the command succeeds. Default: ${String(SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT)}. Set true to include success-case stderr in terminal results.`
6950
6958
  )
6951
6959
  }).superRefine((input, ctx) => {
6952
6960
  if (input.timeout === void 0) {
@@ -6973,11 +6981,18 @@ var shellRunSchema = z10.object({
6973
6981
  var shellTaskKeySchema = z10.object({
6974
6982
  key: z10.string().describe("Canonical shell task key returned by shell or shell_list.")
6975
6983
  });
6984
+ var shellSuccessStderrSchema = {
6985
+ include_stderr_on_success: z10.boolean().optional().describe(
6986
+ `Include stderr when the command succeeds. Default: ${String(SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT)}. Set true to include success-case stderr in terminal results.`
6987
+ )
6988
+ };
6976
6989
  var shellWaitSchema = shellTaskKeySchema.extend({
6977
6990
  wait_timeout: z10.number().int().positive().max(MAX_TIMEOUT_SECONDS).optional().describe(
6978
6991
  `Attached wait window in seconds. Default: ${DEFAULT_TIMEOUT_SECONDS}. Max ${MAX_TIMEOUT_SECONDS}. If the task is still running when the window expires, the tool returns compact status JSON instead of hanging.`
6979
- )
6992
+ ),
6993
+ ...shellSuccessStderrSchema
6980
6994
  });
6995
+ var shellResultSchema = shellTaskKeySchema.extend(shellSuccessStderrSchema);
6981
6996
  var shellStreamSchema = z10.enum(["stdout", "stderr"]);
6982
6997
  var shellListSchema = z10.object({
6983
6998
  limit: z10.number().int().positive().max(SHELL_LIST_MAX_LIMIT).optional().describe(
@@ -7061,26 +7076,11 @@ var trimNonEmpty = (value) => {
7061
7076
  const trimmed = value.trimEnd();
7062
7077
  return trimmed.trim().length > 0 ? trimmed : null;
7063
7078
  };
7064
- var pickShellOutput = (task) => {
7065
- const stdout = trimNonEmpty(task.result?.stdout);
7066
- const stderr = trimNonEmpty(task.result?.stderr);
7079
+ var shellTerminalUsesCompactSuccessStreams = (task) => {
7067
7080
  const exitCode = task.result?.exit_code;
7068
- const preferError = task.state === "failed" || task.state === "cancelled" || exitCode !== null && exitCode !== void 0 && exitCode !== 0;
7069
- const primaryStream = preferError ? "stderr" : "stdout";
7070
- const primaryContent = primaryStream === "stderr" ? stderr : stdout;
7071
- const secondaryContent = primaryStream === "stderr" ? stdout : stderr;
7072
- const selectedStream = primaryContent ? primaryStream : secondaryContent ? primaryStream === "stderr" ? "stdout" : "stderr" : null;
7073
- if (!selectedStream) {
7074
- return null;
7075
- }
7076
- const field = preferError ? "error_output" : "output";
7077
- const cacheId = selectedStream === "stderr" ? task.result?.stderr_cache_id : task.result?.stdout_cache_id;
7078
- return {
7079
- field,
7080
- content: selectedStream === "stderr" ? stderr ?? "" : stdout ?? "",
7081
- ...cacheId ? { cacheId } : {}
7082
- };
7081
+ return task.state === "completed" && (exitCode === null || exitCode === void 0 || exitCode === 0);
7083
7082
  };
7083
+ var resolveIncludeStderrOnSuccess = (value) => value ?? SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT;
7084
7084
  var shellBasePayload = (task) => ({
7085
7085
  key: getShellTaskKey(task),
7086
7086
  state: task.state,
@@ -7092,8 +7092,11 @@ var shellStatusPayload = (task, options = {}) => ({
7092
7092
  ...options.stillRunning ? { still_running: true } : {},
7093
7093
  ...options.aborted ? { aborted: true } : {}
7094
7094
  });
7095
- var shellTerminalPayload = (task) => {
7095
+ var shellTerminalPayload = (task, options = {}) => {
7096
7096
  const payload = shellBasePayload(task);
7097
+ const stdout = trimNonEmpty(task.result?.stdout);
7098
+ const stderr = trimNonEmpty(task.result?.stderr);
7099
+ const compactSuccess = !resolveIncludeStderrOnSuccess(options.includeStderrOnSuccess) && shellTerminalUsesCompactSuccessStreams(task);
7097
7100
  if (task.result?.exit_code !== void 0 && task.result.exit_code !== null) {
7098
7101
  payload.exit_code = task.result.exit_code;
7099
7102
  }
@@ -7106,11 +7109,16 @@ var shellTerminalPayload = (task) => {
7106
7109
  if (task.cancellation_reason) {
7107
7110
  payload.cancellation_reason = task.cancellation_reason;
7108
7111
  }
7109
- const output = pickShellOutput(task);
7110
- if (output) {
7111
- payload[output.field] = output.content;
7112
- if (output.cacheId) {
7113
- payload.cache_id = output.cacheId;
7112
+ if (stdout) {
7113
+ payload.stdout = stdout;
7114
+ if (task.result?.stdout_cache_id) {
7115
+ payload.stdout_cache_id = task.result.stdout_cache_id;
7116
+ }
7117
+ }
7118
+ if (!compactSuccess && stderr) {
7119
+ payload.stderr = stderr;
7120
+ if (task.result?.stderr_cache_id) {
7121
+ payload.stderr_cache_id = task.result.stderr_cache_id;
7114
7122
  }
7115
7123
  }
7116
7124
  return payload;
@@ -7349,7 +7357,7 @@ var createShellTool = (sandboxKey, options = {}) => {
7349
7357
  const shared = getSharedDeps(options);
7350
7358
  return defineTool9({
7351
7359
  name: "shell",
7352
- description: "Run a shell command as a runtime-managed child process in the sandbox. By default wait for completion; with `detached_wait=true`, skip the attached wait and return compact JSON with the task key for follow-up tools.",
7360
+ description: "Run a shell command as a runtime-managed child process in the sandbox. Terminal results use `stdout`/`stderr` stream fields; successful results suppress `stderr` by default unless `include_stderr_on_success=true`, and `shell_logs` is available when you need explicit stream reads. By default wait for completion; with `detached_wait=true`, skip the attached wait and return compact JSON with the task key for follow-up tools.",
7353
7361
  input: shellRunSchema,
7354
7362
  execute: async (input, ctx) => {
7355
7363
  const sandbox = await getSandboxContext(ctx, sandboxKey);
@@ -7402,7 +7410,9 @@ var createShellTool = (sandboxKey, options = {}) => {
7402
7410
  debugLog(
7403
7411
  `shell.done task_id=${task.task_id} state=${settled.state} duration_ms=${settled.result?.duration_ms ?? -1}`
7404
7412
  );
7405
- return shellTerminalPayload(settled);
7413
+ return shellTerminalPayload(settled, {
7414
+ includeStderrOnSuccess: input.include_stderr_on_success
7415
+ });
7406
7416
  } catch (error) {
7407
7417
  throw formatTaskError(error);
7408
7418
  }
@@ -7460,7 +7470,7 @@ var createShellLogsTool = (options = {}) => {
7460
7470
  const shared = getSharedDeps(options);
7461
7471
  return defineTool9({
7462
7472
  name: "shell_logs",
7463
- description: "Read recent stdout or stderr for a running or finished shell task.",
7473
+ description: "Read recent stdout or stderr for a running or finished shell task. Use this when a compact shell terminal result omitted a stream, such as `stderr` on success.",
7464
7474
  input: shellLogsSchema,
7465
7475
  execute: async (input) => {
7466
7476
  try {
@@ -7482,7 +7492,7 @@ var createShellWaitTool = (options = {}) => {
7482
7492
  const shared = getSharedDeps(options);
7483
7493
  return defineTool9({
7484
7494
  name: "shell_wait",
7485
- description: "Wait for a shell task within a bounded window and return compact JSON describing either the running status or terminal result.",
7495
+ description: "Wait for a shell task within a bounded window and return compact JSON describing either the running status or a terminal result with `stdout`/`stderr` stream fields. Successful terminal results suppress `stderr` by default unless `include_stderr_on_success=true`; use `shell_logs` for explicit stream reads.",
7486
7496
  input: shellWaitSchema,
7487
7497
  execute: async (input, ctx) => {
7488
7498
  try {
@@ -7504,7 +7514,9 @@ var createShellWaitTool = (options = {}) => {
7504
7514
  stillRunning: result.stillRunning
7505
7515
  });
7506
7516
  }
7507
- return shellTerminalPayload(result.task);
7517
+ return shellTerminalPayload(result.task, {
7518
+ includeStderrOnSuccess: waitInput.include_stderr_on_success
7519
+ });
7508
7520
  } catch (error) {
7509
7521
  throw formatTaskError(error);
7510
7522
  }
@@ -7515,12 +7527,15 @@ var createShellResultTool = (options = {}) => {
7515
7527
  const shared = getSharedDeps(options);
7516
7528
  return defineTool9({
7517
7529
  name: "shell_result",
7518
- description: "Read the retained terminal result for a shell task as compact JSON.",
7519
- input: shellTaskKeySchema,
7530
+ description: "Read the retained terminal result for a shell task as compact JSON with `stdout`/`stderr` stream fields. Successful terminal results suppress `stderr` by default unless `include_stderr_on_success=true`; use `shell_logs` for explicit stream reads.",
7531
+ input: shellResultSchema,
7520
7532
  execute: async (input) => {
7521
7533
  try {
7522
- const task = await resolveShellTask(shared.tasks, input);
7523
- return isTerminalTaskState(task.state) ? shellTerminalPayload(task) : shellStatusPayload(task);
7534
+ const resultInput = input;
7535
+ const task = await resolveShellTask(shared.tasks, resultInput);
7536
+ return isTerminalTaskState(task.state) ? shellTerminalPayload(task, {
7537
+ includeStderrOnSuccess: resultInput.include_stderr_on_success
7538
+ }) : shellStatusPayload(task);
7524
7539
  } catch (error) {
7525
7540
  throw formatTaskError(error);
7526
7541
  }
@@ -7610,7 +7625,9 @@ var createSkillSearchTool = (skillsResolverKey) => defineTool11({
7610
7625
  description: "Search installed local skills by name, description, or path.",
7611
7626
  input: z12.object({
7612
7627
  query: z12.string().min(1).describe("Search query text."),
7613
- limit: z12.number().int().positive().optional().describe("Optional max result count. Higher values may be clamped by config."),
7628
+ limit: z12.number().int().positive().optional().describe(
7629
+ "Optional max result count. Higher values may be clamped by config."
7630
+ ),
7614
7631
  scope: z12.enum(["repo", "user"]).optional().describe("Optional scope filter.")
7615
7632
  }),
7616
7633
  execute: async (input, ctx) => {
@@ -8072,7 +8089,9 @@ var createViewImageTool = (sandboxKey) => defineTool15({
8072
8089
  file_path: z16.string().describe(
8073
8090
  "Single local png/jpeg/webp/gif image path. Sandbox-bounded unless full-access mode is active."
8074
8091
  ),
8075
- detail: z16.enum(["auto", "low", "high"]).optional().describe("Model image-detail hint (`auto`/`low`/`high`). Default auto."),
8092
+ detail: z16.enum(["auto", "low", "high"]).optional().describe(
8093
+ "Model image-detail hint (`auto`/`low`/`high`). Default auto."
8094
+ ),
8076
8095
  max_bytes: z16.number().int().positive().max(MAX_MAX_BYTES).optional().describe("Max file size in bytes. Default 5242880, Max 10485760.")
8077
8096
  }),
8078
8097
  execute: async (input, ctx) => {
@@ -8383,8 +8402,12 @@ var createWebfetchTool = () => defineTool16({
8383
8402
  input: z17.object({
8384
8403
  url: z17.string().min(1).describe("HTTP(S) URL to fetch."),
8385
8404
  output_format: z17.enum(["markdown", "text", "html"]).optional().describe("Normalized output format. Default markdown."),
8386
- timeout_ms: z17.number().int().positive().max(MAX_TIMEOUT_MS).optional().describe(`Fetch timeout in ms. Default ${DEFAULT_TIMEOUT_MS3}, Max ${MAX_TIMEOUT_MS}.`),
8387
- max_bytes: z17.number().int().positive().max(MAX_MAX_BYTES2).optional().describe(`Max response bytes to keep. Default ${DEFAULT_MAX_BYTES3}, Max ${MAX_MAX_BYTES2}.`)
8405
+ timeout_ms: z17.number().int().positive().max(MAX_TIMEOUT_MS).optional().describe(
8406
+ `Fetch timeout in ms. Default ${DEFAULT_TIMEOUT_MS3}, Max ${MAX_TIMEOUT_MS}.`
8407
+ ),
8408
+ max_bytes: z17.number().int().positive().max(MAX_MAX_BYTES2).optional().describe(
8409
+ `Max response bytes to keep. Default ${DEFAULT_MAX_BYTES3}, Max ${MAX_MAX_BYTES2}.`
8410
+ )
8388
8411
  }),
8389
8412
  execute: async (input) => {
8390
8413
  let url;
@@ -8399,6 +8422,7 @@ var createWebfetchTool = () => defineTool16({
8399
8422
  const timeoutMs = input.timeout_ms ?? DEFAULT_TIMEOUT_MS3;
8400
8423
  const maxBytes = input.max_bytes ?? DEFAULT_MAX_BYTES3;
8401
8424
  const outputFormat = input.output_format ?? "markdown";
8425
+ const startedAt = Date.now();
8402
8426
  const controller = new AbortController();
8403
8427
  const timeout = setTimeout(() => controller.abort(), timeoutMs);
8404
8428
  try {
@@ -8428,6 +8452,7 @@ var createWebfetchTool = () => defineTool16({
8428
8452
  } else {
8429
8453
  content = normalizeWhitespace(rawText);
8430
8454
  }
8455
+ const durationMs = Math.max(0, Date.now() - startedAt);
8431
8456
  return {
8432
8457
  url: input.url,
8433
8458
  final_url: response.url || input.url,
@@ -8438,7 +8463,8 @@ var createWebfetchTool = () => defineTool16({
8438
8463
  title: isHtml ? extractTitle(rawText) ?? null : null,
8439
8464
  content,
8440
8465
  truncated: body.truncated,
8441
- byte_size: body.byteSize
8466
+ byte_size: body.byteSize,
8467
+ duration_ms: durationMs
8442
8468
  };
8443
8469
  } catch (error) {
8444
8470
  const classified = classifyFetchError(error, timeoutMs);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codelia/runtime",
3
- "version": "0.1.60",
3
+ "version": "0.1.62",
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.60",
27
- "@codelia/config-loader": "0.1.60",
28
- "@codelia/core": "0.1.60",
29
- "@codelia/logger": "0.1.60",
30
- "@codelia/model-metadata": "0.1.60",
31
- "@codelia/protocol": "0.1.60",
32
- "@codelia/shared-types": "0.1.60",
33
- "@codelia/storage": "0.1.60",
26
+ "@codelia/config": "0.1.62",
27
+ "@codelia/config-loader": "0.1.62",
28
+ "@codelia/core": "0.1.62",
29
+ "@codelia/logger": "0.1.62",
30
+ "@codelia/model-metadata": "0.1.62",
31
+ "@codelia/protocol": "0.1.62",
32
+ "@codelia/shared-types": "0.1.62",
33
+ "@codelia/storage": "0.1.62",
34
34
  "eventsource-parser": "^3.0.6",
35
35
  "oauth4webapi": "^3.8.4",
36
36
  "zod": "^4.3.5"