@codelia/runtime 0.1.60 → 0.1.61

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
@@ -6924,6 +6924,7 @@ var SHELL_LABEL_MAX_CHARS = 80;
6924
6924
  var SHELL_LIST_DEFAULT_LIMIT = 20;
6925
6925
  var SHELL_LIST_MAX_LIMIT = 100;
6926
6926
  var SHELL_LOGS_MAX_TAIL_LINES = 500;
6927
+ var SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT = false;
6927
6928
  var shellStateSchema = import_zod10.z.enum([
6928
6929
  "queued",
6929
6930
  "running",
@@ -6943,6 +6944,9 @@ var shellRunSchema = import_zod10.z.object({
6943
6944
  ),
6944
6945
  detached_wait: import_zod10.z.boolean().optional().describe(
6945
6946
  "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."
6947
+ ),
6948
+ include_stderr_on_success: import_zod10.z.boolean().optional().describe(
6949
+ `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
6950
  )
6947
6951
  }).superRefine((input, ctx) => {
6948
6952
  if (input.timeout === void 0) {
@@ -6969,11 +6973,18 @@ var shellRunSchema = import_zod10.z.object({
6969
6973
  var shellTaskKeySchema = import_zod10.z.object({
6970
6974
  key: import_zod10.z.string().describe("Canonical shell task key returned by shell or shell_list.")
6971
6975
  });
6976
+ var shellSuccessStderrSchema = {
6977
+ include_stderr_on_success: import_zod10.z.boolean().optional().describe(
6978
+ `Include stderr when the command succeeds. Default: ${String(SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT)}. Set true to include success-case stderr in terminal results.`
6979
+ )
6980
+ };
6972
6981
  var shellWaitSchema = shellTaskKeySchema.extend({
6973
6982
  wait_timeout: import_zod10.z.number().int().positive().max(MAX_TIMEOUT_SECONDS).optional().describe(
6974
6983
  `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
- )
6984
+ ),
6985
+ ...shellSuccessStderrSchema
6976
6986
  });
6987
+ var shellResultSchema = shellTaskKeySchema.extend(shellSuccessStderrSchema);
6977
6988
  var shellStreamSchema = import_zod10.z.enum(["stdout", "stderr"]);
6978
6989
  var shellListSchema = import_zod10.z.object({
6979
6990
  limit: import_zod10.z.number().int().positive().max(SHELL_LIST_MAX_LIMIT).optional().describe(
@@ -7057,26 +7068,11 @@ var trimNonEmpty = (value) => {
7057
7068
  const trimmed = value.trimEnd();
7058
7069
  return trimmed.trim().length > 0 ? trimmed : null;
7059
7070
  };
7060
- var pickShellOutput = (task) => {
7061
- const stdout = trimNonEmpty(task.result?.stdout);
7062
- const stderr = trimNonEmpty(task.result?.stderr);
7071
+ var shellTerminalUsesCompactSuccessStreams = (task) => {
7063
7072
  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
- };
7073
+ return task.state === "completed" && (exitCode === null || exitCode === void 0 || exitCode === 0);
7079
7074
  };
7075
+ var resolveIncludeStderrOnSuccess = (value) => value ?? SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT;
7080
7076
  var shellBasePayload = (task) => ({
7081
7077
  key: getShellTaskKey(task),
7082
7078
  state: task.state,
@@ -7088,8 +7084,11 @@ var shellStatusPayload = (task, options = {}) => ({
7088
7084
  ...options.stillRunning ? { still_running: true } : {},
7089
7085
  ...options.aborted ? { aborted: true } : {}
7090
7086
  });
7091
- var shellTerminalPayload = (task) => {
7087
+ var shellTerminalPayload = (task, options = {}) => {
7092
7088
  const payload = shellBasePayload(task);
7089
+ const stdout = trimNonEmpty(task.result?.stdout);
7090
+ const stderr = trimNonEmpty(task.result?.stderr);
7091
+ const compactSuccess = !resolveIncludeStderrOnSuccess(options.includeStderrOnSuccess) && shellTerminalUsesCompactSuccessStreams(task);
7093
7092
  if (task.result?.exit_code !== void 0 && task.result.exit_code !== null) {
7094
7093
  payload.exit_code = task.result.exit_code;
7095
7094
  }
@@ -7102,11 +7101,16 @@ var shellTerminalPayload = (task) => {
7102
7101
  if (task.cancellation_reason) {
7103
7102
  payload.cancellation_reason = task.cancellation_reason;
7104
7103
  }
7105
- const output = pickShellOutput(task);
7106
- if (output) {
7107
- payload[output.field] = output.content;
7108
- if (output.cacheId) {
7109
- payload.cache_id = output.cacheId;
7104
+ if (stdout) {
7105
+ payload.stdout = stdout;
7106
+ if (task.result?.stdout_cache_id) {
7107
+ payload.stdout_cache_id = task.result.stdout_cache_id;
7108
+ }
7109
+ }
7110
+ if (!compactSuccess && stderr) {
7111
+ payload.stderr = stderr;
7112
+ if (task.result?.stderr_cache_id) {
7113
+ payload.stderr_cache_id = task.result.stderr_cache_id;
7110
7114
  }
7111
7115
  }
7112
7116
  return payload;
@@ -7345,7 +7349,7 @@ var createShellTool = (sandboxKey, options = {}) => {
7345
7349
  const shared = getSharedDeps(options);
7346
7350
  return (0, import_core11.defineTool)({
7347
7351
  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.",
7352
+ 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
7353
  input: shellRunSchema,
7350
7354
  execute: async (input, ctx) => {
7351
7355
  const sandbox = await getSandboxContext(ctx, sandboxKey);
@@ -7398,7 +7402,9 @@ var createShellTool = (sandboxKey, options = {}) => {
7398
7402
  (0, import_logger.debugLog)(
7399
7403
  `shell.done task_id=${task.task_id} state=${settled.state} duration_ms=${settled.result?.duration_ms ?? -1}`
7400
7404
  );
7401
- return shellTerminalPayload(settled);
7405
+ return shellTerminalPayload(settled, {
7406
+ includeStderrOnSuccess: input.include_stderr_on_success
7407
+ });
7402
7408
  } catch (error) {
7403
7409
  throw formatTaskError(error);
7404
7410
  }
@@ -7456,7 +7462,7 @@ var createShellLogsTool = (options = {}) => {
7456
7462
  const shared = getSharedDeps(options);
7457
7463
  return (0, import_core11.defineTool)({
7458
7464
  name: "shell_logs",
7459
- description: "Read recent stdout or stderr for a running or finished shell task.",
7465
+ 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
7466
  input: shellLogsSchema,
7461
7467
  execute: async (input) => {
7462
7468
  try {
@@ -7478,7 +7484,7 @@ var createShellWaitTool = (options = {}) => {
7478
7484
  const shared = getSharedDeps(options);
7479
7485
  return (0, import_core11.defineTool)({
7480
7486
  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.",
7487
+ 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
7488
  input: shellWaitSchema,
7483
7489
  execute: async (input, ctx) => {
7484
7490
  try {
@@ -7500,7 +7506,9 @@ var createShellWaitTool = (options = {}) => {
7500
7506
  stillRunning: result.stillRunning
7501
7507
  });
7502
7508
  }
7503
- return shellTerminalPayload(result.task);
7509
+ return shellTerminalPayload(result.task, {
7510
+ includeStderrOnSuccess: waitInput.include_stderr_on_success
7511
+ });
7504
7512
  } catch (error) {
7505
7513
  throw formatTaskError(error);
7506
7514
  }
@@ -7511,12 +7519,15 @@ var createShellResultTool = (options = {}) => {
7511
7519
  const shared = getSharedDeps(options);
7512
7520
  return (0, import_core11.defineTool)({
7513
7521
  name: "shell_result",
7514
- description: "Read the retained terminal result for a shell task as compact JSON.",
7515
- input: shellTaskKeySchema,
7522
+ 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.",
7523
+ input: shellResultSchema,
7516
7524
  execute: async (input) => {
7517
7525
  try {
7518
- const task = await resolveShellTask(shared.tasks, input);
7519
- return isTerminalTaskState(task.state) ? shellTerminalPayload(task) : shellStatusPayload(task);
7526
+ const resultInput = input;
7527
+ const task = await resolveShellTask(shared.tasks, resultInput);
7528
+ return isTerminalTaskState(task.state) ? shellTerminalPayload(task, {
7529
+ includeStderrOnSuccess: resultInput.include_stderr_on_success
7530
+ }) : shellStatusPayload(task);
7520
7531
  } catch (error) {
7521
7532
  throw formatTaskError(error);
7522
7533
  }
package/dist/index.js CHANGED
@@ -6928,6 +6928,7 @@ var SHELL_LABEL_MAX_CHARS = 80;
6928
6928
  var SHELL_LIST_DEFAULT_LIMIT = 20;
6929
6929
  var SHELL_LIST_MAX_LIMIT = 100;
6930
6930
  var SHELL_LOGS_MAX_TAIL_LINES = 500;
6931
+ var SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT = false;
6931
6932
  var shellStateSchema = z10.enum([
6932
6933
  "queued",
6933
6934
  "running",
@@ -6947,6 +6948,9 @@ var shellRunSchema = z10.object({
6947
6948
  ),
6948
6949
  detached_wait: z10.boolean().optional().describe(
6949
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: z10.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.`
6950
6954
  )
6951
6955
  }).superRefine((input, ctx) => {
6952
6956
  if (input.timeout === void 0) {
@@ -6973,11 +6977,18 @@ var shellRunSchema = z10.object({
6973
6977
  var shellTaskKeySchema = z10.object({
6974
6978
  key: z10.string().describe("Canonical shell task key returned by shell or shell_list.")
6975
6979
  });
6980
+ var shellSuccessStderrSchema = {
6981
+ include_stderr_on_success: z10.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
+ };
6976
6985
  var shellWaitSchema = shellTaskKeySchema.extend({
6977
6986
  wait_timeout: z10.number().int().positive().max(MAX_TIMEOUT_SECONDS).optional().describe(
6978
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.`
6979
- )
6988
+ ),
6989
+ ...shellSuccessStderrSchema
6980
6990
  });
6991
+ var shellResultSchema = shellTaskKeySchema.extend(shellSuccessStderrSchema);
6981
6992
  var shellStreamSchema = z10.enum(["stdout", "stderr"]);
6982
6993
  var shellListSchema = z10.object({
6983
6994
  limit: z10.number().int().positive().max(SHELL_LIST_MAX_LIMIT).optional().describe(
@@ -7061,26 +7072,11 @@ var trimNonEmpty = (value) => {
7061
7072
  const trimmed = value.trimEnd();
7062
7073
  return trimmed.trim().length > 0 ? trimmed : null;
7063
7074
  };
7064
- var pickShellOutput = (task) => {
7065
- const stdout = trimNonEmpty(task.result?.stdout);
7066
- const stderr = trimNonEmpty(task.result?.stderr);
7075
+ var shellTerminalUsesCompactSuccessStreams = (task) => {
7067
7076
  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
- };
7077
+ return task.state === "completed" && (exitCode === null || exitCode === void 0 || exitCode === 0);
7083
7078
  };
7079
+ var resolveIncludeStderrOnSuccess = (value) => value ?? SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT;
7084
7080
  var shellBasePayload = (task) => ({
7085
7081
  key: getShellTaskKey(task),
7086
7082
  state: task.state,
@@ -7092,8 +7088,11 @@ var shellStatusPayload = (task, options = {}) => ({
7092
7088
  ...options.stillRunning ? { still_running: true } : {},
7093
7089
  ...options.aborted ? { aborted: true } : {}
7094
7090
  });
7095
- var shellTerminalPayload = (task) => {
7091
+ var shellTerminalPayload = (task, options = {}) => {
7096
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);
7097
7096
  if (task.result?.exit_code !== void 0 && task.result.exit_code !== null) {
7098
7097
  payload.exit_code = task.result.exit_code;
7099
7098
  }
@@ -7106,11 +7105,16 @@ var shellTerminalPayload = (task) => {
7106
7105
  if (task.cancellation_reason) {
7107
7106
  payload.cancellation_reason = task.cancellation_reason;
7108
7107
  }
7109
- const output = pickShellOutput(task);
7110
- if (output) {
7111
- payload[output.field] = output.content;
7112
- if (output.cacheId) {
7113
- 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;
7114
7118
  }
7115
7119
  }
7116
7120
  return payload;
@@ -7349,7 +7353,7 @@ var createShellTool = (sandboxKey, options = {}) => {
7349
7353
  const shared = getSharedDeps(options);
7350
7354
  return defineTool9({
7351
7355
  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.",
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.",
7353
7357
  input: shellRunSchema,
7354
7358
  execute: async (input, ctx) => {
7355
7359
  const sandbox = await getSandboxContext(ctx, sandboxKey);
@@ -7402,7 +7406,9 @@ var createShellTool = (sandboxKey, options = {}) => {
7402
7406
  debugLog(
7403
7407
  `shell.done task_id=${task.task_id} state=${settled.state} duration_ms=${settled.result?.duration_ms ?? -1}`
7404
7408
  );
7405
- return shellTerminalPayload(settled);
7409
+ return shellTerminalPayload(settled, {
7410
+ includeStderrOnSuccess: input.include_stderr_on_success
7411
+ });
7406
7412
  } catch (error) {
7407
7413
  throw formatTaskError(error);
7408
7414
  }
@@ -7460,7 +7466,7 @@ var createShellLogsTool = (options = {}) => {
7460
7466
  const shared = getSharedDeps(options);
7461
7467
  return defineTool9({
7462
7468
  name: "shell_logs",
7463
- 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.",
7464
7470
  input: shellLogsSchema,
7465
7471
  execute: async (input) => {
7466
7472
  try {
@@ -7482,7 +7488,7 @@ var createShellWaitTool = (options = {}) => {
7482
7488
  const shared = getSharedDeps(options);
7483
7489
  return defineTool9({
7484
7490
  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.",
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.",
7486
7492
  input: shellWaitSchema,
7487
7493
  execute: async (input, ctx) => {
7488
7494
  try {
@@ -7504,7 +7510,9 @@ var createShellWaitTool = (options = {}) => {
7504
7510
  stillRunning: result.stillRunning
7505
7511
  });
7506
7512
  }
7507
- return shellTerminalPayload(result.task);
7513
+ return shellTerminalPayload(result.task, {
7514
+ includeStderrOnSuccess: waitInput.include_stderr_on_success
7515
+ });
7508
7516
  } catch (error) {
7509
7517
  throw formatTaskError(error);
7510
7518
  }
@@ -7515,12 +7523,15 @@ var createShellResultTool = (options = {}) => {
7515
7523
  const shared = getSharedDeps(options);
7516
7524
  return defineTool9({
7517
7525
  name: "shell_result",
7518
- description: "Read the retained terminal result for a shell task as compact JSON.",
7519
- 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,
7520
7528
  execute: async (input) => {
7521
7529
  try {
7522
- const task = await resolveShellTask(shared.tasks, input);
7523
- 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);
7524
7535
  } catch (error) {
7525
7536
  throw formatTaskError(error);
7526
7537
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codelia/runtime",
3
- "version": "0.1.60",
3
+ "version": "0.1.61",
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.61",
27
+ "@codelia/config-loader": "0.1.61",
28
+ "@codelia/core": "0.1.61",
29
+ "@codelia/logger": "0.1.61",
30
+ "@codelia/model-metadata": "0.1.61",
31
+ "@codelia/protocol": "0.1.61",
32
+ "@codelia/shared-types": "0.1.61",
33
+ "@codelia/storage": "0.1.61",
34
34
  "eventsource-parser": "^3.0.6",
35
35
  "oauth4webapi": "^3.8.4",
36
36
  "zod": "^4.3.5"