@codelia/runtime 0.1.72 → 0.1.74

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
@@ -1923,6 +1923,7 @@ var import_node_path3 = __toESM(require("path"), 1);
1923
1923
 
1924
1924
  // src/tasks/shell-executor.ts
1925
1925
  var import_node_child_process3 = require("child_process");
1926
+ var import_node_perf_hooks = require("perf_hooks");
1926
1927
 
1927
1928
  // src/tools/bash-utils.ts
1928
1929
  var import_node_child_process2 = require("child_process");
@@ -1946,6 +1947,10 @@ var summarizeCommand = (command) => {
1946
1947
  var DEFAULT_EXCERPT_LINES = 80;
1947
1948
  var MAX_INLINE_OUTPUT_BYTES = 64 * 1024;
1948
1949
  var FORCE_KILL_DELAY_MS = 2e3;
1950
+ var MAX_STDIN_WRITE_BYTES = 64 * 1024;
1951
+ var DEFAULT_STDIN_WRITE_TIMEOUT_MS = 3e4;
1952
+ var defaultMonotonicNowMs = () => import_node_perf_hooks.performance.now();
1953
+ var elapsedMilliseconds = (startedAt, monotonicNowMs) => Math.max(0, Math.round(monotonicNowMs() - startedAt));
1949
1954
  var utf8ByteLength = (value) => Buffer.byteLength(value, "utf8");
1950
1955
  var truncateUtf8Prefix = (value, maxBytes) => {
1951
1956
  if (maxBytes <= 0 || value.length === 0) return "";
@@ -2038,19 +2043,20 @@ var buildShellTaskResult = async (outputCache, options) => {
2038
2043
  ...stderrCacheId ? { stderr_cache_id: stderrCacheId } : {}
2039
2044
  };
2040
2045
  };
2041
- var spawnShellProcess = (command, cwd) => {
2046
+ var spawnShellProcess = (command, cwd, stdinMode) => {
2047
+ const stdin = stdinMode === "pipe" ? "pipe" : "ignore";
2042
2048
  const shellPath = process.platform === "win32" ? "" : process.env.SHELL?.trim() || "";
2043
2049
  if (shellPath) {
2044
2050
  return (0, import_node_child_process3.spawn)(shellPath, ["-lc", command], {
2045
2051
  cwd,
2046
- stdio: ["ignore", "pipe", "pipe"],
2052
+ stdio: [stdin, "pipe", "pipe"],
2047
2053
  detached: true
2048
2054
  });
2049
2055
  }
2050
2056
  return (0, import_node_child_process3.spawn)(command, {
2051
2057
  cwd,
2052
2058
  shell: true,
2053
- stdio: ["ignore", "pipe", "pipe"],
2059
+ stdio: [stdin, "pipe", "pipe"],
2054
2060
  detached: process.platform !== "win32"
2055
2061
  });
2056
2062
  };
@@ -2075,11 +2081,18 @@ var startShellTask = (options) => {
2075
2081
  }
2076
2082
  const maxOutputBytes = options.maxOutputBytes ?? MAX_OUTPUT_BYTES;
2077
2083
  const forceKillDelayMs = options.forceKillDelayMs ?? FORCE_KILL_DELAY_MS;
2078
- const startedAt = Date.now();
2084
+ const monotonicNowMs = options.monotonicNowMs ?? defaultMonotonicNowMs;
2085
+ const stdinMode = options.stdinMode ?? "closed";
2086
+ const stdinWriteTimeoutMs = options.stdinWriteTimeoutMs ?? DEFAULT_STDIN_WRITE_TIMEOUT_MS;
2087
+ const monotonicStartedAt = monotonicNowMs();
2079
2088
  const child = (options.spawnProcess ?? spawnShellProcess)(
2080
2089
  options.command,
2081
- options.cwd
2090
+ options.cwd,
2091
+ stdinMode
2082
2092
  );
2093
+ if (stdinMode === "pipe" && child.stdin === null) {
2094
+ throw new Error("stdin_mode=pipe requires a writable child stdin stream");
2095
+ }
2083
2096
  const metadata = typeof child.pid === "number" ? {
2084
2097
  executor_pid: child.pid,
2085
2098
  executor_pgid: process.platform === "win32" ? void 0 : child.pid
@@ -2091,6 +2104,51 @@ var startShellTask = (options) => {
2091
2104
  let cancelRequested = false;
2092
2105
  let timeoutHandle;
2093
2106
  let forceKillHandle;
2107
+ let stdinClosed = stdinMode === "closed";
2108
+ let stdinWriteQueue = Promise.resolve();
2109
+ const markStdinClosed = () => {
2110
+ if (stdinClosed) return;
2111
+ stdinClosed = true;
2112
+ };
2113
+ const invalidateStdin = () => {
2114
+ if (stdinClosed) return;
2115
+ markStdinClosed();
2116
+ child.stdin?.destroy();
2117
+ };
2118
+ const performStdinWrite = async (input) => {
2119
+ if (stdinMode !== "pipe" || child.stdin === null) {
2120
+ throw new Error("stdin was not opened as a pipe");
2121
+ }
2122
+ const stdin = child.stdin;
2123
+ if (settled) throw new Error("task is already terminal");
2124
+ if (stdinClosed || stdin.destroyed || stdin.writableEnded) {
2125
+ throw new Error("stdin is already closed");
2126
+ }
2127
+ const bytesWritten = utf8ByteLength(input.text);
2128
+ if (bytesWritten > MAX_STDIN_WRITE_BYTES) {
2129
+ throw new Error(
2130
+ `stdin write exceeds ${MAX_STDIN_WRITE_BYTES} UTF-8 bytes`
2131
+ );
2132
+ }
2133
+ if (bytesWritten > 0) {
2134
+ await new Promise((resolve, reject) => {
2135
+ const timer = setTimeout(() => {
2136
+ invalidateStdin();
2137
+ reject(new Error("stdin write timed out waiting for backpressure"));
2138
+ }, stdinWriteTimeoutMs);
2139
+ stdin.write(input.text, "utf8", (error) => {
2140
+ clearTimeout(timer);
2141
+ if (error) reject(error);
2142
+ else resolve();
2143
+ });
2144
+ });
2145
+ }
2146
+ if (input.close) {
2147
+ markStdinClosed();
2148
+ stdin.end();
2149
+ }
2150
+ return { bytes_written: bytesWritten, stdin_closed: stdinClosed };
2151
+ };
2094
2152
  const clearForceKillHandle = () => {
2095
2153
  if (!forceKillHandle) return;
2096
2154
  clearTimeout(forceKillHandle);
@@ -2107,7 +2165,12 @@ var startShellTask = (options) => {
2107
2165
  const settle = async (outcome) => {
2108
2166
  if (settled) return;
2109
2167
  settled = true;
2168
+ invalidateStdin();
2110
2169
  if (timeoutHandle) clearTimeout(timeoutHandle);
2170
+ const durationMs = elapsedMilliseconds(
2171
+ monotonicStartedAt,
2172
+ monotonicNowMs
2173
+ );
2111
2174
  let result;
2112
2175
  try {
2113
2176
  result = await buildShellTaskResult(options.outputCache, {
@@ -2117,7 +2180,7 @@ var startShellTask = (options) => {
2117
2180
  rawStderr: stderr,
2118
2181
  exitCode: outcome.exitCode,
2119
2182
  signal: outcome.signal,
2120
- durationMs: Date.now() - startedAt
2183
+ durationMs
2121
2184
  });
2122
2185
  } catch {
2123
2186
  result = buildShellTaskResultBase({
@@ -2125,7 +2188,7 @@ var startShellTask = (options) => {
2125
2188
  rawStderr: stderr,
2126
2189
  exitCode: outcome.exitCode,
2127
2190
  signal: outcome.signal,
2128
- durationMs: Date.now() - startedAt
2191
+ durationMs
2129
2192
  });
2130
2193
  }
2131
2194
  resolve({
@@ -2208,8 +2271,19 @@ var startShellTask = (options) => {
2208
2271
  metadata,
2209
2272
  wait,
2210
2273
  readOutput: async (stream) => stream === "stdout" ? stdout : stderr,
2274
+ ...stdinMode === "pipe" ? {
2275
+ writeInput: (input) => {
2276
+ const write = stdinWriteQueue.then(() => performStdinWrite(input));
2277
+ stdinWriteQueue = write.then(
2278
+ () => void 0,
2279
+ () => void 0
2280
+ );
2281
+ return write;
2282
+ }
2283
+ } : {},
2211
2284
  cancel: async () => {
2212
2285
  if (settled) return;
2286
+ invalidateStdin();
2213
2287
  cancelRequested = true;
2214
2288
  terminateChild(child, "SIGTERM");
2215
2289
  scheduleForceKill();
@@ -3562,6 +3636,7 @@ var SYSTEM_TOOL_ALLOWLIST_MINIMAL = [
3562
3636
  "shell_wait",
3563
3637
  "shell_result",
3564
3638
  "shell_cancel",
3639
+ "shell_stdin_write",
3565
3640
  "lane_list",
3566
3641
  "lane_status",
3567
3642
  "done"
@@ -5369,11 +5444,40 @@ var createDoneTool = () => (0, import_core6.defineTool)({
5369
5444
  });
5370
5445
 
5371
5446
  // src/tools/edit.ts
5372
- var import_node_crypto4 = __toESM(require("crypto"), 1);
5373
5447
  var import_node_fs8 = require("fs");
5374
5448
  var import_node_path10 = __toESM(require("path"), 1);
5375
5449
  var import_core7 = require("@codelia/core");
5450
+ var import_zod6 = require("zod");
5451
+
5452
+ // src/tools/content-hash.ts
5453
+ var import_node_crypto4 = __toESM(require("crypto"), 1);
5376
5454
  var import_zod5 = require("zod");
5455
+ var CONTENT_SHA256_PATTERN = /^[a-f0-9]{64}$/;
5456
+ var expectedContentHashSchema = import_zod5.z.string().regex(
5457
+ CONTENT_SHA256_PATTERN,
5458
+ "expected_hash must be a lowercase 64-character SHA-256 hash"
5459
+ ).nullable().default(null).describe(
5460
+ "Current full-content SHA-256 guard. Copy content_sha256 from a current read/read_line result or explicitly compute the same UTF-8 content hash."
5461
+ );
5462
+ var hashUtf8Content = (content) => import_node_crypto4.default.createHash("sha256").update(content).digest("hex");
5463
+ var assertExpectedContentHash = (input) => {
5464
+ if (!input.expectedHash) return;
5465
+ if (!input.fileExists) {
5466
+ throw new Error(
5467
+ `Expected hash provided but file not found: ${input.filePath}`
5468
+ );
5469
+ }
5470
+ if (hashUtf8Content(input.content) !== input.expectedHash) {
5471
+ throw new Error(
5472
+ `Hash mismatch for ${input.filePath}. The file changed since it was read; read it again and retry with the new content_sha256.`
5473
+ );
5474
+ }
5475
+ };
5476
+ var appendReadMetadata = (output, content) => `${output}
5477
+
5478
+ [read_metadata] content_sha256=${hashUtf8Content(content)}`;
5479
+
5480
+ // src/tools/edit.ts
5377
5481
  var trimLine = (line) => line.replace(/\r$/, "").trim();
5378
5482
  var lineRangeToIndices = (lines, startLine, lineCount) => {
5379
5483
  let startIndex = 0;
@@ -5480,25 +5584,24 @@ var applyReplacements = (content, matches, replacement) => {
5480
5584
  }
5481
5585
  return next;
5482
5586
  };
5483
- var hashContent = (content) => import_node_crypto4.default.createHash("sha256").update(content).digest("hex");
5484
5587
  var createEditTool = (sandboxKey, outputCacheStore) => (0, import_core7.defineTool)({
5485
5588
  name: "edit",
5486
5589
  description: "Edit a file by replacing matched text with new text; supports guarded match modes and dry-run preview.",
5487
- input: import_zod5.z.object({
5488
- file_path: import_zod5.z.string().describe(
5590
+ input: import_zod6.z.object({
5591
+ file_path: import_zod6.z.string().describe(
5489
5592
  "File path. Sandbox-bounded unless full-access mode is active."
5490
5593
  ),
5491
- old_string: import_zod5.z.string().describe(
5594
+ old_string: import_zod6.z.string().describe(
5492
5595
  "Text to find. Use empty string to replace the whole file content."
5493
5596
  ),
5494
- new_string: import_zod5.z.string().describe("Replacement text."),
5495
- replace_all: import_zod5.z.boolean().optional().describe("Replace all matches when true. Default false."),
5496
- match_mode: import_zod5.z.enum(["exact", "line_trimmed", "block_anchor", "auto"]).optional().describe(
5597
+ new_string: import_zod6.z.string().describe("Replacement text."),
5598
+ replace_all: import_zod6.z.boolean().optional().describe("Replace all matches when true. Default false."),
5599
+ match_mode: import_zod6.z.enum(["exact", "line_trimmed", "block_anchor", "auto"]).optional().describe(
5497
5600
  "Match strategy: exact, line_trimmed, block_anchor, or auto (tries exact -> line_trimmed -> block_anchor). Default auto."
5498
5601
  ),
5499
- expected_replacements: import_zod5.z.number().int().nonnegative().optional().describe("Expected replacement count (guard)."),
5500
- dry_run: import_zod5.z.boolean().optional().describe("Preview diff only when true. Default false."),
5501
- expected_hash: import_zod5.z.string().optional().describe("Optional SHA-256 hash guard for current file content.")
5602
+ expected_replacements: import_zod6.z.number().int().nonnegative().optional().describe("Expected replacement count (guard)."),
5603
+ dry_run: import_zod6.z.boolean().optional().describe("Preview diff only when true. Default false."),
5604
+ expected_hash: expectedContentHashSchema
5502
5605
  }),
5503
5606
  execute: async (input, ctx) => {
5504
5607
  let resolved;
@@ -5534,17 +5637,12 @@ var createEditTool = (sandboxKey, outputCacheStore) => (0, import_core7.defineTo
5534
5637
  throw new Error(`File not found: ${input.file_path}`);
5535
5638
  }
5536
5639
  }
5537
- if (input.expected_hash) {
5538
- if (!fileExists) {
5539
- throw new Error(
5540
- `Expected hash provided but file not found: ${input.file_path}`
5541
- );
5542
- }
5543
- const currentHash = hashContent(content);
5544
- if (currentHash !== input.expected_hash) {
5545
- throw new Error(`Hash mismatch for ${input.file_path}`);
5546
- }
5547
- }
5640
+ assertExpectedContentHash({
5641
+ expectedHash: input.expected_hash,
5642
+ fileExists,
5643
+ content,
5644
+ filePath: input.file_path
5645
+ });
5548
5646
  let replacements = 0;
5549
5647
  let modeUsed = "exact";
5550
5648
  let nextContent = content;
@@ -5620,7 +5718,7 @@ var createEditTool = (sandboxKey, outputCacheStore) => (0, import_core7.defineTo
5620
5718
 
5621
5719
  // src/tools/lane.ts
5622
5720
  var import_core8 = require("@codelia/core");
5623
- var import_zod6 = require("zod");
5721
+ var import_zod7 = require("zod");
5624
5722
 
5625
5723
  // src/lanes/manager.ts
5626
5724
  var import_node_crypto5 = __toESM(require("crypto"), 1);
@@ -6192,7 +6290,7 @@ var LaneManager = class {
6192
6290
 
6193
6291
  // src/tools/lane.ts
6194
6292
  var laneManager = new LaneManager();
6195
- var backendSchema = import_zod6.z.enum(["tmux", "zellij"]);
6293
+ var backendSchema = import_zod7.z.enum(["tmux", "zellij"]);
6196
6294
  var formatError = (error) => {
6197
6295
  if (error instanceof LaneManagerError) {
6198
6296
  return new Error(`${error.code}: ${error.message}`);
@@ -6222,14 +6320,14 @@ var buildLaneHints = (lane) => {
6222
6320
  var createLaneCreateTool = (sandboxKey) => (0, import_core8.defineTool)({
6223
6321
  name: "lane_create",
6224
6322
  description: "Create a Task lane (worktree slot) and start autonomous execution in tmux/zellij.",
6225
- input: import_zod6.z.object({
6226
- task_id: import_zod6.z.string().describe("Task identifier."),
6227
- base_ref: import_zod6.z.string().optional().describe("Base git ref. Default: HEAD."),
6228
- worktree_path: import_zod6.z.string().optional().describe(
6323
+ input: import_zod7.z.object({
6324
+ task_id: import_zod7.z.string().describe("Task identifier."),
6325
+ base_ref: import_zod7.z.string().optional().describe("Base git ref. Default: HEAD."),
6326
+ worktree_path: import_zod7.z.string().optional().describe(
6229
6327
  "Optional worktree path override. Default: ~/.codelia/worktrees/<task-slug>-<lane-id8>."
6230
6328
  ),
6231
6329
  mux_backend: backendSchema.optional().describe("Multiplexer backend. Default: tmux."),
6232
- seed_context: import_zod6.z.string().optional().describe("Optional initial text context.")
6330
+ seed_context: import_zod7.z.string().optional().describe("Optional initial text context.")
6233
6331
  }),
6234
6332
  execute: async (input, ctx) => {
6235
6333
  const sandbox = await getSandboxContext(ctx, sandboxKey);
@@ -6257,8 +6355,8 @@ var createLaneCreateTool = (sandboxKey) => (0, import_core8.defineTool)({
6257
6355
  var createLaneListTool = (sandboxKey) => (0, import_core8.defineTool)({
6258
6356
  name: "lane_list",
6259
6357
  description: "List Task lanes (worktree slots) and current states.",
6260
- input: import_zod6.z.object({
6261
- include_closed: import_zod6.z.boolean().optional().describe("Include closed lanes. Default: false.")
6358
+ input: import_zod7.z.object({
6359
+ include_closed: import_zod7.z.boolean().optional().describe("Include closed lanes. Default: false.")
6262
6360
  }),
6263
6361
  execute: async (input, ctx) => {
6264
6362
  await getSandboxContext(ctx, sandboxKey);
@@ -6281,8 +6379,8 @@ var createLaneListTool = (sandboxKey) => (0, import_core8.defineTool)({
6281
6379
  var createLaneStatusTool = (sandboxKey) => (0, import_core8.defineTool)({
6282
6380
  name: "lane_status",
6283
6381
  description: "Get Task lane status and backend liveness.",
6284
- input: import_zod6.z.object({
6285
- lane_id: import_zod6.z.string().describe("Lane id.")
6382
+ input: import_zod7.z.object({
6383
+ lane_id: import_zod7.z.string().describe("Lane id.")
6286
6384
  }),
6287
6385
  execute: async (input, ctx) => {
6288
6386
  await getSandboxContext(ctx, sandboxKey);
@@ -6300,10 +6398,10 @@ var createLaneStatusTool = (sandboxKey) => (0, import_core8.defineTool)({
6300
6398
  var createLaneCloseTool = (sandboxKey) => (0, import_core8.defineTool)({
6301
6399
  name: "lane_close",
6302
6400
  description: "Close a Task lane and optionally remove its worktree.",
6303
- input: import_zod6.z.object({
6304
- lane_id: import_zod6.z.string().describe("Lane id."),
6305
- remove_worktree: import_zod6.z.boolean().optional().describe("Remove worktree. Default: true."),
6306
- force: import_zod6.z.boolean().optional().describe("Force close/cleanup. Default: false.")
6401
+ input: import_zod7.z.object({
6402
+ lane_id: import_zod7.z.string().describe("Lane id."),
6403
+ remove_worktree: import_zod7.z.boolean().optional().describe("Remove worktree. Default: true."),
6404
+ force: import_zod7.z.boolean().optional().describe("Force close/cleanup. Default: false.")
6307
6405
  }),
6308
6406
  execute: async (input, ctx) => {
6309
6407
  await getSandboxContext(ctx, sandboxKey);
@@ -6325,10 +6423,10 @@ var createLaneCloseTool = (sandboxKey) => (0, import_core8.defineTool)({
6325
6423
  var createLaneGcTool = (sandboxKey) => (0, import_core8.defineTool)({
6326
6424
  name: "lane_gc",
6327
6425
  description: "Close stale finished/error lanes after idle TTL.",
6328
- input: import_zod6.z.object({
6329
- idle_ttl_minutes: import_zod6.z.number().int().positive().describe("Idle TTL in minutes."),
6330
- remove_worktree: import_zod6.z.boolean().optional().describe("Remove worktree on close. Default: false."),
6331
- force: import_zod6.z.boolean().optional().describe("Force cleanup for dirty worktrees. Default: false.")
6426
+ input: import_zod7.z.object({
6427
+ idle_ttl_minutes: import_zod7.z.number().int().positive().describe("Idle TTL in minutes."),
6428
+ remove_worktree: import_zod7.z.boolean().optional().describe("Remove worktree on close. Default: false."),
6429
+ force: import_zod7.z.boolean().optional().describe("Force cleanup for dirty worktrees. Default: false.")
6332
6430
  }),
6333
6431
  execute: async (input, ctx) => {
6334
6432
  await getSandboxContext(ctx, sandboxKey);
@@ -6347,7 +6445,7 @@ var createLaneGcTool = (sandboxKey) => (0, import_core8.defineTool)({
6347
6445
  // src/tools/read.ts
6348
6446
  var import_node_fs11 = require("fs");
6349
6447
  var import_core9 = require("@codelia/core");
6350
- var import_zod7 = require("zod");
6448
+ var import_zod8 = require("zod");
6351
6449
  var DEFAULT_READ_LIMIT = 2e3;
6352
6450
  var DEFAULT_MAX_LINE_LENGTH = 1e3;
6353
6451
  var DEFAULT_MAX_BYTES = 64 * 1024;
@@ -6403,13 +6501,13 @@ var buildTruncatedLinesSummary = (lineNumbers) => {
6403
6501
  };
6404
6502
  var createReadTool = (sandboxKey) => (0, import_core9.defineTool)({
6405
6503
  name: "read",
6406
- description: "Read a bounded text-file preview by 0-based line offset/limit; large output is truncated and long lines should fall back to read_line.",
6407
- input: import_zod7.z.object({
6408
- file_path: import_zod7.z.string().describe(
6504
+ description: "Read a bounded text-file preview by 0-based line offset/limit and return the full UTF-8 content SHA-256 metadata for edit.expected_hash; large output is truncated and long lines should fall back to read_line.",
6505
+ input: import_zod8.z.object({
6506
+ file_path: import_zod8.z.string().describe(
6409
6507
  "Text file path. Sandbox-bounded unless full-access mode is active."
6410
6508
  ),
6411
- offset: import_zod7.z.number().int().nonnegative().optional().describe("0-based start line. Default 0."),
6412
- limit: import_zod7.z.number().int().positive().optional().describe("Max preview lines to read. Default 2000.")
6509
+ offset: import_zod8.z.number().int().nonnegative().optional().describe("0-based start line. Default 0."),
6510
+ limit: import_zod8.z.number().int().positive().optional().describe("Max preview lines to read. Default 2000.")
6413
6511
  }),
6414
6512
  execute: async (input, ctx) => {
6415
6513
  let resolved;
@@ -6499,7 +6597,7 @@ ${truncatedLinesSummary}`;
6499
6597
 
6500
6598
  For full long-line content, use read_line({"file_path":${JSON.stringify(input.file_path)},"line_number":${firstClippedLineNumber},"char_offset":0,"char_limit":10000}).`;
6501
6599
  }
6502
- return output;
6600
+ return appendReadMetadata(output, content);
6503
6601
  } catch (error) {
6504
6602
  return `Error reading file: ${String(error)}`;
6505
6603
  }
@@ -6509,7 +6607,7 @@ For full long-line content, use read_line({"file_path":${JSON.stringify(input.fi
6509
6607
  // src/tools/read-line.ts
6510
6608
  var import_node_fs12 = require("fs");
6511
6609
  var import_core10 = require("@codelia/core");
6512
- var import_zod8 = require("zod");
6610
+ var import_zod9 = require("zod");
6513
6611
  var DEFAULT_CHAR_LIMIT = 1e4;
6514
6612
  var MAX_CHAR_LIMIT = 1e5;
6515
6613
  var GRAPHEME_SEGMENTER = new Intl.Segmenter(void 0, {
@@ -6518,14 +6616,14 @@ var GRAPHEME_SEGMENTER = new Intl.Segmenter(void 0, {
6518
6616
  var splitGraphemes = (value) => Array.from(GRAPHEME_SEGMENTER.segment(value), ({ segment }) => segment);
6519
6617
  var createReadLineTool = (sandboxKey) => (0, import_core10.defineTool)({
6520
6618
  name: "read_line",
6521
- description: "Read one physical line as paged grapheme-based text by 1-based line number and 0-based char offset.",
6522
- input: import_zod8.z.object({
6523
- file_path: import_zod8.z.string().describe(
6619
+ description: "Read one physical line as paged grapheme-based text by 1-based line number and 0-based char offset, with the full UTF-8 content SHA-256 metadata for edit.expected_hash.",
6620
+ input: import_zod9.z.object({
6621
+ file_path: import_zod9.z.string().describe(
6524
6622
  "Text file path. Sandbox-bounded unless full-access mode is active."
6525
6623
  ),
6526
- line_number: import_zod8.z.number().int().positive().describe("1-based line number to read."),
6527
- char_offset: import_zod8.z.number().int().nonnegative().optional().describe("0-based grapheme offset in the target line. Default 0."),
6528
- char_limit: import_zod8.z.number().int().positive().max(MAX_CHAR_LIMIT).optional().describe(
6624
+ line_number: import_zod9.z.number().int().positive().describe("1-based line number to read."),
6625
+ char_offset: import_zod9.z.number().int().nonnegative().optional().describe("0-based grapheme offset in the target line. Default 0."),
6626
+ char_limit: import_zod9.z.number().int().positive().max(MAX_CHAR_LIMIT).optional().describe(
6529
6627
  `Max graphemes to return. Default 10000, Max ${MAX_CHAR_LIMIT}.`
6530
6628
  )
6531
6629
  }),
@@ -6577,7 +6675,7 @@ Use char_offset=${endOffset} to continue.`;
6577
6675
  output += `
6578
6676
  read_line({"file_path":${JSON.stringify(input.file_path)},"line_number":${input.line_number},"char_offset":${endOffset},"char_limit":${charLimit}})`;
6579
6677
  }
6580
- return output;
6678
+ return appendReadMetadata(output, content);
6581
6679
  } catch (error) {
6582
6680
  return `Error reading file: ${String(error)}`;
6583
6681
  }
@@ -6586,7 +6684,7 @@ read_line({"file_path":${JSON.stringify(input.file_path)},"line_number":${input.
6586
6684
 
6587
6685
  // src/tools/search.ts
6588
6686
  var import_core11 = require("@codelia/core");
6589
- var import_zod9 = require("zod");
6687
+ var import_zod10 = require("zod");
6590
6688
  var normalizeDomain = (value) => value.trim().toLowerCase().replace(/\.+$/, "");
6591
6689
  var shouldKeepUrl = (url, allowedDomains) => {
6592
6690
  if (!allowedDomains.length) return true;
@@ -6705,11 +6803,11 @@ var runBraveSearch = async (query, maxResults, allowedDomains, apiKey) => {
6705
6803
  var createSearchTool = (options) => (0, import_core11.defineTool)({
6706
6804
  name: "search",
6707
6805
  description: "Search the web and return concise source candidates.",
6708
- input: import_zod9.z.object({
6709
- query: import_zod9.z.string().min(1).describe("Search query."),
6710
- max_results: import_zod9.z.number().int().min(1).max(20).optional().describe("Max results. Default 5."),
6711
- backend: import_zod9.z.enum(["ddg", "brave"]).optional().describe("Search backend. Default comes from config."),
6712
- allowed_domains: import_zod9.z.array(import_zod9.z.string().min(1)).optional().describe("Optional allowlist of domains.")
6806
+ input: import_zod10.z.object({
6807
+ query: import_zod10.z.string().min(1).describe("Search query."),
6808
+ max_results: import_zod10.z.number().int().min(1).max(20).optional().describe("Max results. Default 5."),
6809
+ backend: import_zod10.z.enum(["ddg", "brave"]).optional().describe("Search backend. Default comes from config."),
6810
+ allowed_domains: import_zod10.z.array(import_zod10.z.string().min(1)).optional().describe("Optional allowlist of domains.")
6713
6811
  }),
6714
6812
  execute: async (input) => {
6715
6813
  const backend = input.backend ?? options.defaultBackend;
@@ -6747,7 +6845,7 @@ var createSearchTool = (options) => (0, import_core11.defineTool)({
6747
6845
  var import_node_crypto7 = __toESM(require("crypto"), 1);
6748
6846
  var import_core12 = require("@codelia/core");
6749
6847
  var import_storage7 = require("@codelia/storage");
6750
- var import_zod10 = require("zod");
6848
+ var import_zod11 = require("zod");
6751
6849
 
6752
6850
  // src/tasks/manager.ts
6753
6851
  var import_node_crypto6 = __toESM(require("crypto"), 1);
@@ -7134,6 +7232,42 @@ var TaskManager = class {
7134
7232
  }
7135
7233
  return active.handle.readOutput(stream);
7136
7234
  }
7235
+ async writeInput(taskId, input) {
7236
+ const task = await this.requireTask(taskId);
7237
+ if (isTerminalTaskState(task.state)) {
7238
+ throw new TaskManagerError(
7239
+ "task_input_unavailable",
7240
+ `Task ${taskId} is already ${task.state}.`
7241
+ );
7242
+ }
7243
+ if (task.owner_runtime_id !== this.runtimeId) {
7244
+ throw new TaskManagerError(
7245
+ "task_owned_by_other_runtime",
7246
+ `Task ${taskId} is owned by another runtime.`
7247
+ );
7248
+ }
7249
+ if (task.parent_session_id !== void 0 && task.parent_session_id !== input.sessionId) {
7250
+ throw new TaskManagerError(
7251
+ "task_owned_by_other_session",
7252
+ `Task ${taskId} belongs to another agent session.`
7253
+ );
7254
+ }
7255
+ const active = this.activeTasks.get(taskId);
7256
+ if (!active?.handle.writeInput) {
7257
+ throw new TaskManagerError(
7258
+ "task_input_unavailable",
7259
+ `Task ${taskId} has no live local stdin pipe.`
7260
+ );
7261
+ }
7262
+ const result = await active.handle.writeInput({
7263
+ text: input.text,
7264
+ close: input.close
7265
+ });
7266
+ return {
7267
+ task: await this.status(taskId) ?? task,
7268
+ result
7269
+ };
7270
+ }
7137
7271
  async wait(taskId, options = {}) {
7138
7272
  const active = this.activeTasks.get(taskId);
7139
7273
  if (active) {
@@ -7283,37 +7417,48 @@ var SHELL_LIST_DEFAULT_LIMIT = 20;
7283
7417
  var SHELL_LIST_MAX_LIMIT = 100;
7284
7418
  var SHELL_LOGS_MAX_TAIL_LINES = 500;
7285
7419
  var SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT = false;
7286
- var shellStateSchema = import_zod10.z.enum([
7420
+ var shellStdinModeSchema = import_zod11.z.enum(["closed", "pipe"]);
7421
+ var shellStateSchema = import_zod11.z.enum([
7287
7422
  "queued",
7288
7423
  "running",
7289
7424
  "completed",
7290
7425
  "failed",
7291
7426
  "cancelled"
7292
7427
  ]);
7293
- var shellRunSchema = import_zod10.z.object({
7294
- command: import_zod10.z.string().describe(
7428
+ var shellRunSchema = import_zod11.z.object({
7429
+ command: import_zod11.z.string().describe(
7295
7430
  "Shell command to execute as a runtime-managed child process in the current workspace."
7296
7431
  ),
7297
- label: import_zod10.z.string().max(SHELL_LABEL_MAX_CHARS).optional().describe(
7432
+ label: import_zod11.z.string().max(SHELL_LABEL_MAX_CHARS).optional().describe(
7298
7433
  `Optional short task label used to build the returned task key. Max ${SHELL_LABEL_MAX_CHARS} chars.`
7299
7434
  ),
7300
- timeout: import_zod10.z.number().int().positive().optional().describe(
7435
+ timeout: import_zod11.z.number().int().positive().optional().describe(
7301
7436
  `Execution timeout in seconds. Foreground default: ${DEFAULT_TIMEOUT_SECONDS}, max ${MAX_TIMEOUT_SECONDS}. Detached-wait mode accepts larger values up to ${MAX_EXECUTION_TIMEOUT_SECONDS}; omit to keep the managed child job running until completion, cancel, or runtime exit.`
7302
7437
  ),
7303
- detached_wait: import_zod10.z.boolean().optional().describe(
7438
+ detached_wait: import_zod11.z.boolean().optional().describe(
7304
7439
  "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."
7305
7440
  ),
7306
- include_stderr_on_success: import_zod10.z.boolean().optional().describe(
7441
+ stdin_mode: shellStdinModeSchema.optional().describe(
7442
+ "Child stdin behavior. Default: closed (immediate EOF). Use pipe only with detached_wait=true, then send bounded UTF-8 text with shell_stdin_write."
7443
+ ),
7444
+ include_stderr_on_success: import_zod11.z.boolean().optional().describe(
7307
7445
  `Include stderr when the command succeeds. Default: ${String(SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT)}. Set true to include success-case stderr in terminal results.`
7308
7446
  )
7309
7447
  }).superRefine((input, ctx) => {
7448
+ if (input.stdin_mode === "pipe" && input.detached_wait !== true) {
7449
+ ctx.addIssue({
7450
+ code: import_zod11.z.ZodIssueCode.custom,
7451
+ path: ["stdin_mode"],
7452
+ message: "stdin_mode=pipe requires detached_wait=true."
7453
+ });
7454
+ }
7310
7455
  if (input.timeout === void 0) {
7311
7456
  return;
7312
7457
  }
7313
7458
  if (input.detached_wait ?? false) {
7314
7459
  if (input.timeout > MAX_EXECUTION_TIMEOUT_SECONDS) {
7315
7460
  ctx.addIssue({
7316
- code: import_zod10.z.ZodIssueCode.custom,
7461
+ code: import_zod11.z.ZodIssueCode.custom,
7317
7462
  path: ["timeout"],
7318
7463
  message: `Detached-wait timeout must be ${MAX_EXECUTION_TIMEOUT_SECONDS} seconds or less. Omit timeout to run without an execution timer.`
7319
7464
  });
@@ -7322,39 +7467,61 @@ var shellRunSchema = import_zod10.z.object({
7322
7467
  }
7323
7468
  if (input.timeout > MAX_TIMEOUT_SECONDS) {
7324
7469
  ctx.addIssue({
7325
- code: import_zod10.z.ZodIssueCode.custom,
7470
+ code: import_zod11.z.ZodIssueCode.custom,
7326
7471
  path: ["timeout"],
7327
7472
  message: `Foreground timeout must be ${MAX_TIMEOUT_SECONDS} seconds or less.`
7328
7473
  });
7329
7474
  }
7330
7475
  });
7331
- var shellTaskKeySchema = import_zod10.z.object({
7332
- key: import_zod10.z.string().describe("Canonical shell task key returned by shell or shell_list.")
7476
+ var shellTaskKeySchema = import_zod11.z.object({
7477
+ key: import_zod11.z.string().describe("Canonical shell task key returned by shell or shell_list.")
7478
+ });
7479
+ var shellStdinWriteSchema = shellTaskKeySchema.extend({
7480
+ text: import_zod11.z.string().describe("UTF-8 text to write to the task stdin pipe."),
7481
+ append_newline: import_zod11.z.boolean().optional().describe("Append one newline before writing. Default: false."),
7482
+ close: import_zod11.z.boolean().optional().describe("Close stdin after this write completes. Default: false.")
7483
+ }).superRefine((input, ctx) => {
7484
+ const close = input.close ?? false;
7485
+ const text = `${input.text}${input.append_newline ? "\n" : ""}`;
7486
+ if (text.length === 0 && !close) {
7487
+ ctx.addIssue({
7488
+ code: import_zod11.z.ZodIssueCode.custom,
7489
+ path: ["text"],
7490
+ message: "text must be non-empty unless close=true."
7491
+ });
7492
+ }
7493
+ if (utf8ByteLength3(text) > MAX_STDIN_WRITE_BYTES) {
7494
+ ctx.addIssue({
7495
+ code: import_zod11.z.ZodIssueCode.custom,
7496
+ path: ["text"],
7497
+ message: `stdin writes are limited to ${MAX_STDIN_WRITE_BYTES} UTF-8 bytes after append_newline.`
7498
+ });
7499
+ }
7333
7500
  });
7334
7501
  var shellSuccessStderrSchema = {
7335
- include_stderr_on_success: import_zod10.z.boolean().optional().describe(
7502
+ include_stderr_on_success: import_zod11.z.boolean().optional().describe(
7336
7503
  `Include stderr when the command succeeds. Default: ${String(SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT)}. Set true to include success-case stderr in terminal results.`
7337
7504
  )
7338
7505
  };
7339
7506
  var shellWaitSchema = shellTaskKeySchema.extend({
7340
- wait_timeout: import_zod10.z.number().int().positive().max(MAX_TIMEOUT_SECONDS).optional().describe(
7507
+ wait_timeout: import_zod11.z.number().int().positive().max(MAX_TIMEOUT_SECONDS).optional().describe(
7341
7508
  `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.`
7342
7509
  ),
7343
7510
  ...shellSuccessStderrSchema
7344
7511
  });
7345
7512
  var shellResultSchema = shellTaskKeySchema.extend(shellSuccessStderrSchema);
7346
- var shellStreamSchema = import_zod10.z.enum(["stdout", "stderr"]);
7347
- var shellListSchema = import_zod10.z.object({
7348
- limit: import_zod10.z.number().int().positive().max(SHELL_LIST_MAX_LIMIT).optional().describe(
7513
+ var shellStreamSchema = import_zod11.z.enum(["stdout", "stderr"]);
7514
+ var shellListSchema = import_zod11.z.object({
7515
+ limit: import_zod11.z.number().int().positive().max(SHELL_LIST_MAX_LIMIT).optional().describe(
7349
7516
  `Max tasks to return. Default: ${SHELL_LIST_DEFAULT_LIMIT}. Max ${SHELL_LIST_MAX_LIMIT}.`
7350
7517
  ),
7351
7518
  state: shellStateSchema.optional().describe("Exact state filter. Default: active tasks only."),
7352
- include_terminal: import_zod10.z.boolean().optional().describe("Include completed/failed/cancelled tasks. Default: false.")
7519
+ include_terminal: import_zod11.z.boolean().optional().describe("Include completed/failed/cancelled tasks. Default: false.")
7353
7520
  });
7354
- var shellLogsSchema = import_zod10.z.object({
7355
- key: import_zod10.z.string().describe("Canonical shell task key returned by shell or shell_list."),
7521
+ var shellLogsSchema = import_zod11.z.object({
7522
+ key: import_zod11.z.string().describe("Canonical shell task key returned by shell or shell_list."),
7356
7523
  stream: shellStreamSchema.optional().describe("Stream to read. Default: stdout."),
7357
- tail_lines: import_zod10.z.number().int().positive().max(SHELL_LOGS_MAX_TAIL_LINES).optional().describe(
7524
+ tail_lines: import_zod11.z.number().int().positive().max(SHELL_LOGS_MAX_TAIL_LINES).optional().describe(
7358
7525
  `Return only the last N lines. Max ${SHELL_LOGS_MAX_TAIL_LINES}.`
7359
7526
  )
7360
7527
  });
@@ -7707,7 +7874,7 @@ var createShellTool = (sandboxKey, options = {}) => {
7707
7874
  const shared = getSharedDeps(options);
7708
7875
  return (0, import_core12.defineTool)({
7709
7876
  name: "shell",
7710
- 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.",
7877
+ 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 stdin closed; with `detached_wait=true`, skip the attached wait and return compact JSON with the task key. Set stdin_mode=pipe only for detached tasks that need bounded follow-up writes through shell_stdin_write.",
7711
7878
  input: shellRunSchema,
7712
7879
  execute: async (input, ctx) => {
7713
7880
  const sandbox = await getSandboxContext(ctx, sandboxKey);
@@ -7718,6 +7885,7 @@ var createShellTool = (sandboxKey, options = {}) => {
7718
7885
  }
7719
7886
  const label = normalizeOptionalLabel(input.label);
7720
7887
  const detachedWait = input.detached_wait ?? false;
7888
+ const stdinMode = input.stdin_mode ?? "closed";
7721
7889
  const timeoutSeconds = resolveShellTimeoutSeconds(
7722
7890
  input.timeout,
7723
7891
  detachedWait
@@ -7746,7 +7914,8 @@ var createShellTool = (sandboxKey, options = {}) => {
7746
7914
  cwd: sandbox.workingDir,
7747
7915
  timeoutSeconds,
7748
7916
  toolName: "shell",
7749
- outputCache: shared.outputCacheStore
7917
+ outputCache: shared.outputCacheStore,
7918
+ stdinMode
7750
7919
  })
7751
7920
  );
7752
7921
  if (detachedWait) {
@@ -7769,6 +7938,34 @@ var createShellTool = (sandboxKey, options = {}) => {
7769
7938
  }
7770
7939
  });
7771
7940
  };
7941
+ var createShellStdinWriteTool = (options = {}) => {
7942
+ const shared = getSharedDeps(options);
7943
+ return (0, import_core12.defineTool)({
7944
+ name: "shell_stdin_write",
7945
+ description: "Write at most 64 KiB of UTF-8 text to a live local shell task started with detached_wait=true and stdin_mode=pipe. Writes are serialized and restricted to the same runtime and originating agent session. Use shell_logs to inspect output and shell_wait for completion.",
7946
+ input: shellStdinWriteSchema,
7947
+ execute: async (input, ctx) => {
7948
+ try {
7949
+ const task = await resolveShellTask(shared.tasks, input);
7950
+ const sessionContext = options.sessionContextKey ? await getToolSessionContext(ctx, options.sessionContextKey) : null;
7951
+ const text = `${input.text}${input.append_newline ? "\n" : ""}`;
7952
+ const written = await shared.tasks.writeInput(task.task_id, {
7953
+ text,
7954
+ close: input.close ?? false,
7955
+ sessionId: sessionContext?.sessionId ?? void 0
7956
+ });
7957
+ return {
7958
+ key: getShellTaskKey(written.task),
7959
+ state: written.task.state,
7960
+ bytes_written: written.result.bytes_written,
7961
+ stdin_closed: written.result.stdin_closed
7962
+ };
7963
+ } catch (error) {
7964
+ throw formatTaskError(error);
7965
+ }
7966
+ }
7967
+ });
7968
+ };
7772
7969
  var createShellListTool = (options = {}) => {
7773
7970
  const shared = getSharedDeps(options);
7774
7971
  return (0, import_core12.defineTool)({
@@ -7914,10 +8111,10 @@ var createShellCancelTool = (options = {}) => {
7914
8111
 
7915
8112
  // src/tools/skill-load.ts
7916
8113
  var import_core13 = require("@codelia/core");
7917
- var import_zod11 = require("zod");
7918
- var SkillLoadInputSchema = import_zod11.z.object({
7919
- name: import_zod11.z.string().min(1).optional().describe("Exact skill name to load."),
7920
- path: import_zod11.z.string().min(1).optional().describe("Absolute or workspace-relative path to SKILL.md.")
8114
+ var import_zod12 = require("zod");
8115
+ var SkillLoadInputSchema = import_zod12.z.object({
8116
+ name: import_zod12.z.string().min(1).optional().describe("Exact skill name to load."),
8117
+ path: import_zod12.z.string().min(1).optional().describe("Absolute or workspace-relative path to SKILL.md.")
7921
8118
  }).refine((value) => !!value.name || !!value.path, {
7922
8119
  message: "name or path is required",
7923
8120
  path: ["name"]
@@ -7969,16 +8166,16 @@ var createSkillLoadTool = (skillsResolverKey) => (0, import_core13.defineTool)({
7969
8166
 
7970
8167
  // src/tools/skill-search.ts
7971
8168
  var import_core14 = require("@codelia/core");
7972
- var import_zod12 = require("zod");
8169
+ var import_zod13 = require("zod");
7973
8170
  var createSkillSearchTool = (skillsResolverKey) => (0, import_core14.defineTool)({
7974
8171
  name: "skill_search",
7975
8172
  description: "Search installed local skills by name, description, or path.",
7976
- input: import_zod12.z.object({
7977
- query: import_zod12.z.string().min(1).describe("Search query text."),
7978
- limit: import_zod12.z.number().int().positive().optional().describe(
8173
+ input: import_zod13.z.object({
8174
+ query: import_zod13.z.string().min(1).describe("Search query text."),
8175
+ limit: import_zod13.z.number().int().positive().optional().describe(
7979
8176
  "Optional max result count. Higher values may be clamped by config."
7980
8177
  ),
7981
- scope: import_zod12.z.enum(["repo", "user"]).optional().describe("Optional scope filter.")
8178
+ scope: import_zod13.z.enum(["repo", "user"]).optional().describe("Optional scope filter.")
7982
8179
  }),
7983
8180
  execute: async (input, ctx) => {
7984
8181
  try {
@@ -8002,7 +8199,7 @@ var createSkillSearchTool = (skillsResolverKey) => (0, import_core14.defineTool)
8002
8199
 
8003
8200
  // src/tools/todo-mutate.ts
8004
8201
  var import_core15 = require("@codelia/core");
8005
- var import_zod13 = require("zod");
8202
+ var import_zod14 = require("zod");
8006
8203
 
8007
8204
  // src/tools/todo-store.ts
8008
8205
  var TODO_SESSION_META_KEY = "codelia_todos";
@@ -8112,37 +8309,37 @@ var pickNextTodo = (todos) => {
8112
8309
  var todoStore = /* @__PURE__ */ new Map();
8113
8310
 
8114
8311
  // src/tools/todo-mutate.ts
8115
- var todoStatusSchema = import_zod13.z.enum(["pending", "in_progress", "completed"]);
8116
- var todoPrioritySchema = import_zod13.z.number().int().min(1).max(5);
8117
- var todoItemSchema = import_zod13.z.object({
8118
- id: import_zod13.z.string().min(1).optional().describe("Optional stable ID. Keep if the task already exists."),
8119
- content: import_zod13.z.string().min(1).describe("Todo item text."),
8312
+ var todoStatusSchema = import_zod14.z.enum(["pending", "in_progress", "completed"]);
8313
+ var todoPrioritySchema = import_zod14.z.number().int().min(1).max(5);
8314
+ var todoItemSchema = import_zod14.z.object({
8315
+ id: import_zod14.z.string().min(1).optional().describe("Optional stable ID. Keep if the task already exists."),
8316
+ content: import_zod14.z.string().min(1).describe("Todo item text."),
8120
8317
  status: todoStatusSchema.describe("Todo status."),
8121
8318
  priority: todoPrioritySchema.optional().describe("Priority 1(high)-5(low). Default is 3."),
8122
- notes: import_zod13.z.string().optional().describe("Optional implementation notes."),
8123
- activeForm: import_zod13.z.string().optional().describe("Optional in-progress phrasing for UI display.")
8319
+ notes: import_zod14.z.string().optional().describe("Optional implementation notes."),
8320
+ activeForm: import_zod14.z.string().optional().describe("Optional in-progress phrasing for UI display.")
8124
8321
  });
8125
- var todoPatchItemSchema = import_zod13.z.object({
8126
- id: import_zod13.z.string().min(1).describe("Target todo ID."),
8127
- remove: import_zod13.z.boolean().optional().describe("Set true to remove the todo item."),
8128
- content: import_zod13.z.string().min(1).nullable().default(null).describe("Updated todo text (null keeps current)."),
8322
+ var todoPatchItemSchema = import_zod14.z.object({
8323
+ id: import_zod14.z.string().min(1).describe("Target todo ID."),
8324
+ remove: import_zod14.z.boolean().optional().describe("Set true to remove the todo item."),
8325
+ content: import_zod14.z.string().min(1).nullable().default(null).describe("Updated todo text (null keeps current)."),
8129
8326
  status: todoStatusSchema.nullable().default(null).describe("Updated status (null keeps current)."),
8130
8327
  priority: todoPrioritySchema.nullable().default(null).describe("Updated priority (null keeps current)."),
8131
- notes: import_zod13.z.string().nullable().default(null).describe("Updated notes (null keeps current, empty clears)."),
8132
- activeForm: import_zod13.z.string().nullable().default(null).describe(
8328
+ notes: import_zod14.z.string().nullable().default(null).describe("Updated notes (null keeps current, empty clears)."),
8329
+ activeForm: import_zod14.z.string().nullable().default(null).describe(
8133
8330
  "Updated in-progress phrasing (null keeps current, empty clears)."
8134
8331
  )
8135
8332
  });
8136
- var todoNewInputSchema = import_zod13.z.object({
8137
- todos: import_zod13.z.array(todoItemSchema).min(1).describe("Full todo list to start or replace the current plan.")
8333
+ var todoNewInputSchema = import_zod14.z.object({
8334
+ todos: import_zod14.z.array(todoItemSchema).min(1).describe("Full todo list to start or replace the current plan.")
8138
8335
  }).strict();
8139
- var todoAppendInputSchema = import_zod13.z.object({
8140
- todos: import_zod13.z.array(todoItemSchema).min(1).describe("Todo items to append to the current plan.")
8336
+ var todoAppendInputSchema = import_zod14.z.object({
8337
+ todos: import_zod14.z.array(todoItemSchema).min(1).describe("Todo items to append to the current plan.")
8141
8338
  }).strict();
8142
- var todoPatchInputSchema = import_zod13.z.object({
8143
- updates: import_zod13.z.array(todoPatchItemSchema).min(1).describe("Patch operations for existing todo items.")
8339
+ var todoPatchInputSchema = import_zod14.z.object({
8340
+ updates: import_zod14.z.array(todoPatchItemSchema).min(1).describe("Patch operations for existing todo items.")
8144
8341
  }).strict();
8145
- var todoClearInputSchema = import_zod13.z.object({}).strict();
8342
+ var todoClearInputSchema = import_zod14.z.object({}).strict();
8146
8343
  var statusSymbol = {
8147
8344
  pending: "[ ]",
8148
8345
  in_progress: "[>]",
@@ -8293,7 +8490,7 @@ var createTodoClearTool = (sandboxKey, sessionContextKey) => createTodoMutationT
8293
8490
 
8294
8491
  // src/tools/todo-read.ts
8295
8492
  var import_core16 = require("@codelia/core");
8296
- var import_zod14 = require("zod");
8493
+ var import_zod15 = require("zod");
8297
8494
  var statusSymbol2 = {
8298
8495
  pending: "[ ]",
8299
8496
  in_progress: "[>]",
@@ -8302,7 +8499,7 @@ var statusSymbol2 = {
8302
8499
  var createTodoReadTool = (sandboxKey, sessionContextKey) => (0, import_core16.defineTool)({
8303
8500
  name: "todo_read",
8304
8501
  description: "Read the in-session todo plan with execution order and next step.",
8305
- input: import_zod14.z.object({}),
8502
+ input: import_zod15.z.object({}),
8306
8503
  execute: async (_input, ctx) => {
8307
8504
  const sandbox = await getSandboxContext(ctx, sandboxKey);
8308
8505
  const sessionContext = sessionContextKey ? await getToolSessionContext(ctx, sessionContextKey) : null;
@@ -8339,14 +8536,14 @@ var createTodoReadTool = (sandboxKey, sessionContextKey) => (0, import_core16.de
8339
8536
 
8340
8537
  // src/tools/tool-output-cache.ts
8341
8538
  var import_core17 = require("@codelia/core");
8342
- var import_zod15 = require("zod");
8539
+ var import_zod16 = require("zod");
8343
8540
  var createToolOutputCacheTool = (store) => (0, import_core17.defineTool)({
8344
8541
  name: "tool_output_cache",
8345
8542
  description: "Read cached tool output by ref_id.",
8346
- input: import_zod15.z.object({
8347
- ref_id: import_zod15.z.string().describe("Tool output reference ID."),
8348
- offset: import_zod15.z.number().int().nonnegative().optional().describe("Optional 0-based line offset."),
8349
- limit: import_zod15.z.number().int().positive().optional().describe("Optional max number of lines to return.")
8543
+ input: import_zod16.z.object({
8544
+ ref_id: import_zod16.z.string().describe("Tool output reference ID."),
8545
+ offset: import_zod16.z.number().int().nonnegative().optional().describe("Optional 0-based line offset."),
8546
+ limit: import_zod16.z.number().int().positive().optional().describe("Optional max number of lines to return.")
8350
8547
  }),
8351
8548
  execute: async (input) => {
8352
8549
  if (!store.read) {
@@ -8365,11 +8562,11 @@ var createToolOutputCacheTool = (store) => (0, import_core17.defineTool)({
8365
8562
  var createToolOutputCacheLineTool = (store) => (0, import_core17.defineTool)({
8366
8563
  name: "tool_output_cache_line",
8367
8564
  description: "Read a single cached output line segment by line number and char offset.",
8368
- input: import_zod15.z.object({
8369
- ref_id: import_zod15.z.string().describe("Tool output reference ID."),
8370
- line_number: import_zod15.z.number().int().positive().describe("1-based line number to read."),
8371
- char_offset: import_zod15.z.number().int().nonnegative().optional().describe("0-based start character in the target line. Default 0."),
8372
- char_limit: import_zod15.z.number().int().positive().optional().describe("Max chars to return.")
8565
+ input: import_zod16.z.object({
8566
+ ref_id: import_zod16.z.string().describe("Tool output reference ID."),
8567
+ line_number: import_zod16.z.number().int().positive().describe("1-based line number to read."),
8568
+ char_offset: import_zod16.z.number().int().nonnegative().optional().describe("0-based start character in the target line. Default 0."),
8569
+ char_limit: import_zod16.z.number().int().positive().optional().describe("Max chars to return.")
8373
8570
  }),
8374
8571
  execute: async (input) => {
8375
8572
  if (!store.readLine) {
@@ -8389,13 +8586,13 @@ var createToolOutputCacheLineTool = (store) => (0, import_core17.defineTool)({
8389
8586
  var createToolOutputCacheGrepTool = (store) => (0, import_core17.defineTool)({
8390
8587
  name: "tool_output_cache_grep",
8391
8588
  description: "Search cached tool output by ref_id.",
8392
- input: import_zod15.z.object({
8393
- ref_id: import_zod15.z.string().describe("Tool output reference ID."),
8394
- pattern: import_zod15.z.string().describe("Text or regex pattern to search for."),
8395
- regex: import_zod15.z.boolean().optional().describe("Interpret pattern as regex when true. Default false."),
8396
- before: import_zod15.z.number().int().nonnegative().optional().describe("Context lines before each match. Default 0."),
8397
- after: import_zod15.z.number().int().nonnegative().optional().describe("Context lines after each match. Default 0."),
8398
- max_matches: import_zod15.z.number().int().positive().optional().describe("Maximum number of matches to return.")
8589
+ input: import_zod16.z.object({
8590
+ ref_id: import_zod16.z.string().describe("Tool output reference ID."),
8591
+ pattern: import_zod16.z.string().describe("Text or regex pattern to search for."),
8592
+ regex: import_zod16.z.boolean().optional().describe("Interpret pattern as regex when true. Default false."),
8593
+ before: import_zod16.z.number().int().nonnegative().optional().describe("Context lines before each match. Default 0."),
8594
+ after: import_zod16.z.number().int().nonnegative().optional().describe("Context lines after each match. Default 0."),
8595
+ max_matches: import_zod16.z.number().int().positive().optional().describe("Maximum number of matches to return.")
8399
8596
  }),
8400
8597
  execute: async (input) => {
8401
8598
  if (!store.grep) {
@@ -8419,7 +8616,7 @@ var createToolOutputCacheGrepTool = (store) => (0, import_core17.defineTool)({
8419
8616
  var import_node_fs13 = require("fs");
8420
8617
  var import_node_path13 = __toESM(require("path"), 1);
8421
8618
  var import_core18 = require("@codelia/core");
8422
- var import_zod16 = require("zod");
8619
+ var import_zod17 = require("zod");
8423
8620
  var DEFAULT_MAX_BYTES2 = 5 * 1024 * 1024;
8424
8621
  var MAX_MAX_BYTES = 10 * 1024 * 1024;
8425
8622
  var MIME_BY_EXTENSION = {
@@ -8435,14 +8632,14 @@ var resolveImageMime = (filePath) => {
8435
8632
  var createViewImageTool = (sandboxKey) => (0, import_core18.defineTool)({
8436
8633
  name: "view_image",
8437
8634
  description: "Load one local png/jpeg/webp/gif image (default max 5MB) for multimodal inspection.",
8438
- input: import_zod16.z.object({
8439
- file_path: import_zod16.z.string().describe(
8635
+ input: import_zod17.z.object({
8636
+ file_path: import_zod17.z.string().describe(
8440
8637
  "Single local png/jpeg/webp/gif image path. Sandbox-bounded unless full-access mode is active."
8441
8638
  ),
8442
- detail: import_zod16.z.enum(["auto", "low", "high"]).optional().describe(
8639
+ detail: import_zod17.z.enum(["auto", "low", "high"]).optional().describe(
8443
8640
  "Model image-detail hint (`auto`/`low`/`high`). Default auto."
8444
8641
  ),
8445
- max_bytes: import_zod16.z.number().int().positive().max(MAX_MAX_BYTES).optional().describe("Max file size in bytes. Default 5242880, Max 10485760.")
8642
+ max_bytes: import_zod17.z.number().int().positive().max(MAX_MAX_BYTES).optional().describe("Max file size in bytes. Default 5242880, Max 10485760.")
8446
8643
  }),
8447
8644
  execute: async (input, ctx) => {
8448
8645
  let resolved;
@@ -8493,7 +8690,7 @@ var createViewImageTool = (sandboxKey) => (0, import_core18.defineTool)({
8493
8690
 
8494
8691
  // src/tools/webfetch.ts
8495
8692
  var import_core19 = require("@codelia/core");
8496
- var import_zod17 = require("zod");
8693
+ var import_zod18 = require("zod");
8497
8694
  var DEFAULT_TIMEOUT_MS3 = 1e4;
8498
8695
  var MAX_TIMEOUT_MS = 3e4;
8499
8696
  var DEFAULT_MAX_BYTES3 = 2e5;
@@ -8749,13 +8946,13 @@ var classifyFetchError = (error, timeoutMs) => {
8749
8946
  var createWebfetchTool = () => (0, import_core19.defineTool)({
8750
8947
  name: "webfetch",
8751
8948
  description: "Fetch an HTTP(S) URL and return bounded normalized markdown/text/html for textual content, not binary downloads.",
8752
- input: import_zod17.z.object({
8753
- url: import_zod17.z.string().min(1).describe("HTTP(S) URL to fetch."),
8754
- output_format: import_zod17.z.enum(["markdown", "text", "html"]).optional().describe("Normalized output format. Default markdown."),
8755
- timeout_ms: import_zod17.z.number().int().positive().max(MAX_TIMEOUT_MS).optional().describe(
8949
+ input: import_zod18.z.object({
8950
+ url: import_zod18.z.string().min(1).describe("HTTP(S) URL to fetch."),
8951
+ output_format: import_zod18.z.enum(["markdown", "text", "html"]).optional().describe("Normalized output format. Default markdown."),
8952
+ timeout_ms: import_zod18.z.number().int().positive().max(MAX_TIMEOUT_MS).optional().describe(
8756
8953
  `Fetch timeout in ms. Default ${DEFAULT_TIMEOUT_MS3}, Max ${MAX_TIMEOUT_MS}.`
8757
8954
  ),
8758
- max_bytes: import_zod17.z.number().int().positive().max(MAX_MAX_BYTES2).optional().describe(
8955
+ max_bytes: import_zod18.z.number().int().positive().max(MAX_MAX_BYTES2).optional().describe(
8759
8956
  `Max response bytes to keep. Default ${DEFAULT_MAX_BYTES3}, Max ${MAX_MAX_BYTES2}.`
8760
8957
  )
8761
8958
  }),
@@ -8829,15 +9026,16 @@ var createWebfetchTool = () => (0, import_core19.defineTool)({
8829
9026
  var import_node_fs14 = require("fs");
8830
9027
  var import_node_path14 = __toESM(require("path"), 1);
8831
9028
  var import_core20 = require("@codelia/core");
8832
- var import_zod18 = require("zod");
9029
+ var import_zod19 = require("zod");
8833
9030
  var createWriteTool = (sandboxKey, outputCacheStore) => (0, import_core20.defineTool)({
8834
9031
  name: "write",
8835
- description: "Write full UTF-8 text to a file, replacing any existing contents and creating parent directories if needed.",
8836
- input: import_zod18.z.object({
8837
- file_path: import_zod18.z.string().describe(
9032
+ description: "Write full UTF-8 text to a file, replacing any existing contents and creating parent directories if needed; supports the same full-content hash guard as edit.",
9033
+ input: import_zod19.z.object({
9034
+ file_path: import_zod19.z.string().describe(
8838
9035
  "File path. Sandbox-bounded unless full-access mode is active."
8839
9036
  ),
8840
- content: import_zod18.z.string().describe("Full replacement UTF-8 text content to write.")
9037
+ content: import_zod19.z.string().describe("Full replacement UTF-8 text content to write."),
9038
+ expected_hash: expectedContentHashSchema
8841
9039
  }),
8842
9040
  execute: async (input, ctx) => {
8843
9041
  let resolved;
@@ -8849,13 +9047,21 @@ var createWriteTool = (sandboxKey, outputCacheStore) => (0, import_core20.define
8849
9047
  }
8850
9048
  try {
8851
9049
  let before = "";
9050
+ let fileExists = false;
8852
9051
  try {
8853
9052
  before = await import_node_fs14.promises.readFile(resolved, "utf8");
9053
+ fileExists = true;
8854
9054
  } catch (error) {
8855
9055
  if (error.code !== "ENOENT") {
8856
9056
  throw error;
8857
9057
  }
8858
9058
  }
9059
+ assertExpectedContentHash({
9060
+ expectedHash: input.expected_hash,
9061
+ fileExists,
9062
+ content: before,
9063
+ filePath: input.file_path
9064
+ });
8859
9065
  await import_node_fs14.promises.mkdir(import_node_path14.default.dirname(resolved), { recursive: true });
8860
9066
  await import_node_fs14.promises.writeFile(resolved, input.content, "utf8");
8861
9067
  const diffPayload = await buildDiffPayload({
@@ -8885,6 +9091,11 @@ var createTools = (sandboxKey, agentsResolverKey, skillsResolverKey, options = {
8885
9091
  outputCacheStore: options.toolOutputCacheStore,
8886
9092
  sessionContextKey: options.todoSessionContextKey
8887
9093
  }),
9094
+ createShellStdinWriteTool({
9095
+ taskManager: options.taskManager,
9096
+ outputCacheStore: options.toolOutputCacheStore,
9097
+ sessionContextKey: options.todoSessionContextKey
9098
+ }),
8888
9099
  createShellListTool({
8889
9100
  taskManager: options.taskManager,
8890
9101
  outputCacheStore: options.toolOutputCacheStore