@codelia/runtime 0.1.72 → 0.1.75
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/{chunk-F4WMTUWR.js → chunk-XOARD2XH.js} +385 -172
- package/dist/index.cjs +385 -172
- package/dist/index.js +1 -1
- package/dist/sdk.cjs +385 -172
- package/dist/sdk.d.cts +17 -0
- package/dist/sdk.d.ts +17 -0
- package/dist/sdk.js +1 -1
- package/package.json +9 -9
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: [
|
|
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: [
|
|
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
|
|
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
|
|
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
|
|
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
|
+
).optional().describe(
|
|
5460
|
+
"Current full-content SHA-256 guard from read/read_line metadata. Omit when unavailable."
|
|
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:
|
|
5488
|
-
file_path:
|
|
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:
|
|
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:
|
|
5495
|
-
replace_all:
|
|
5496
|
-
match_mode:
|
|
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:
|
|
5500
|
-
dry_run:
|
|
5501
|
-
expected_hash:
|
|
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
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
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
|
|
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 =
|
|
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:
|
|
6226
|
-
task_id:
|
|
6227
|
-
base_ref:
|
|
6228
|
-
worktree_path:
|
|
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:
|
|
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:
|
|
6261
|
-
include_closed:
|
|
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:
|
|
6285
|
-
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:
|
|
6304
|
-
lane_id:
|
|
6305
|
-
remove_worktree:
|
|
6306
|
-
force:
|
|
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:
|
|
6329
|
-
idle_ttl_minutes:
|
|
6330
|
-
remove_worktree:
|
|
6331
|
-
force:
|
|
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
|
|
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:
|
|
6408
|
-
file_path:
|
|
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:
|
|
6412
|
-
limit:
|
|
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
|
|
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:
|
|
6523
|
-
file_path:
|
|
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:
|
|
6527
|
-
char_offset:
|
|
6528
|
-
char_limit:
|
|
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
|
|
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:
|
|
6709
|
-
query:
|
|
6710
|
-
max_results:
|
|
6711
|
-
backend:
|
|
6712
|
-
allowed_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
|
|
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
|
|
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 =
|
|
7294
|
-
command:
|
|
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:
|
|
7298
|
-
`
|
|
7432
|
+
label: import_zod11.z.string().max(SHELL_LABEL_MAX_CHARS).optional().describe(
|
|
7433
|
+
`Short label used to build the returned task key. Max ${SHELL_LABEL_MAX_CHARS} chars.`
|
|
7434
|
+
),
|
|
7435
|
+
timeout: import_zod11.z.number().int().positive().optional().describe(
|
|
7436
|
+
`Execution timeout in seconds. Foreground: default ${DEFAULT_TIMEOUT_SECONDS}, max ${MAX_TIMEOUT_SECONDS}. Detached: max ${MAX_EXECUTION_TIMEOUT_SECONDS}; omit for no execution timer.`
|
|
7299
7437
|
),
|
|
7300
|
-
|
|
7301
|
-
|
|
7438
|
+
detached_wait: import_zod11.z.boolean().optional().describe(
|
|
7439
|
+
"Return a task key immediately instead of waiting. The runtime owns the child until completion, cancellation, or runtime exit; use follow-up shell tools. Default: false."
|
|
7302
7440
|
),
|
|
7303
|
-
|
|
7304
|
-
"
|
|
7441
|
+
stdin_mode: shellStdinModeSchema.optional().describe(
|
|
7442
|
+
"Child stdin: closed (default) or pipe. pipe requires detached_wait=true and shell_stdin_write."
|
|
7305
7443
|
),
|
|
7306
|
-
include_stderr_on_success:
|
|
7307
|
-
`Include stderr
|
|
7444
|
+
include_stderr_on_success: import_zod11.z.boolean().optional().describe(
|
|
7445
|
+
`Include stderr on success. Default: ${String(SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT)}.`
|
|
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:
|
|
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:
|
|
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 =
|
|
7332
|
-
key:
|
|
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:
|
|
7336
|
-
`Include stderr
|
|
7502
|
+
include_stderr_on_success: import_zod11.z.boolean().optional().describe(
|
|
7503
|
+
`Include stderr on success. Default: ${String(SHELL_INCLUDE_STDERR_ON_SUCCESS_DEFAULT)}.`
|
|
7337
7504
|
)
|
|
7338
7505
|
};
|
|
7339
7506
|
var shellWaitSchema = shellTaskKeySchema.extend({
|
|
7340
|
-
wait_timeout:
|
|
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 =
|
|
7347
|
-
var shellListSchema =
|
|
7348
|
-
limit:
|
|
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:
|
|
7519
|
+
include_terminal: import_zod11.z.boolean().optional().describe("Include completed/failed/cancelled tasks. Default: false.")
|
|
7353
7520
|
});
|
|
7354
|
-
var shellLogsSchema =
|
|
7355
|
-
key:
|
|
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:
|
|
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
|
|
7877
|
+
description: "Run a shell command as a managed child process in the sandbox. It waits with stdin closed by default; use detached_wait for a task key and stdin_mode=pipe only when follow-up shell_stdin_write calls are needed.",
|
|
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 up to 64 KiB of UTF-8 text to a live shell task started with detached_wait=true and stdin_mode=pipe; use shell_logs or shell_wait afterward.",
|
|
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)({
|
|
@@ -7842,7 +8039,7 @@ var createShellWaitTool = (options = {}) => {
|
|
|
7842
8039
|
const shared = getSharedDeps(options);
|
|
7843
8040
|
return (0, import_core12.defineTool)({
|
|
7844
8041
|
name: "shell_wait",
|
|
7845
|
-
description: "Wait
|
|
8042
|
+
description: "Wait within a bounded window for a shell task, returning compact running status or its terminal stdout/stderr result.",
|
|
7846
8043
|
input: shellWaitSchema,
|
|
7847
8044
|
execute: async (input, ctx) => {
|
|
7848
8045
|
try {
|
|
@@ -7877,7 +8074,7 @@ var createShellResultTool = (options = {}) => {
|
|
|
7877
8074
|
const shared = getSharedDeps(options);
|
|
7878
8075
|
return (0, import_core12.defineTool)({
|
|
7879
8076
|
name: "shell_result",
|
|
7880
|
-
description: "Read
|
|
8077
|
+
description: "Read a shell task's retained terminal stdout/stderr result, or its current status if still running.",
|
|
7881
8078
|
input: shellResultSchema,
|
|
7882
8079
|
execute: async (input) => {
|
|
7883
8080
|
try {
|
|
@@ -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
|
|
7918
|
-
var SkillLoadInputSchema =
|
|
7919
|
-
name:
|
|
7920
|
-
path:
|
|
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
|
|
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:
|
|
7977
|
-
query:
|
|
7978
|
-
limit:
|
|
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:
|
|
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
|
|
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,39 @@ var pickNextTodo = (todos) => {
|
|
|
8112
8309
|
var todoStore = /* @__PURE__ */ new Map();
|
|
8113
8310
|
|
|
8114
8311
|
// src/tools/todo-mutate.ts
|
|
8115
|
-
var todoStatusSchema =
|
|
8116
|
-
var todoPrioritySchema =
|
|
8117
|
-
var todoItemSchema =
|
|
8118
|
-
id:
|
|
8119
|
-
|
|
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(
|
|
8316
|
+
"Stable ID. Omit to generate one; preserve the existing ID when replacing a known item."
|
|
8317
|
+
),
|
|
8318
|
+
content: import_zod14.z.string().min(1).describe("Todo item text."),
|
|
8120
8319
|
status: todoStatusSchema.describe("Todo status."),
|
|
8121
8320
|
priority: todoPrioritySchema.optional().describe("Priority 1(high)-5(low). Default is 3."),
|
|
8122
|
-
notes:
|
|
8123
|
-
activeForm:
|
|
8321
|
+
notes: import_zod14.z.string().optional().describe("Implementation notes."),
|
|
8322
|
+
activeForm: import_zod14.z.string().optional().describe("In-progress phrasing for UI display.")
|
|
8124
8323
|
});
|
|
8125
|
-
var todoPatchItemSchema =
|
|
8126
|
-
id:
|
|
8127
|
-
remove:
|
|
8128
|
-
content:
|
|
8129
|
-
status: todoStatusSchema.
|
|
8130
|
-
priority: todoPrioritySchema.
|
|
8131
|
-
notes:
|
|
8132
|
-
activeForm:
|
|
8133
|
-
"
|
|
8324
|
+
var todoPatchItemSchema = import_zod14.z.object({
|
|
8325
|
+
id: import_zod14.z.string().min(1).describe("Target todo ID."),
|
|
8326
|
+
remove: import_zod14.z.boolean().optional().describe("Set true to remove the todo item."),
|
|
8327
|
+
content: import_zod14.z.string().min(1).optional().describe("New todo text; omit to keep the current value."),
|
|
8328
|
+
status: todoStatusSchema.optional().describe("New status; omit to keep the current value."),
|
|
8329
|
+
priority: todoPrioritySchema.optional().describe("New priority; omit to keep the current value."),
|
|
8330
|
+
notes: import_zod14.z.string().optional().describe("New notes; omit to keep the current value, empty clears."),
|
|
8331
|
+
activeForm: import_zod14.z.string().optional().describe(
|
|
8332
|
+
"New in-progress phrasing; omit to keep the current value, empty clears."
|
|
8134
8333
|
)
|
|
8135
8334
|
});
|
|
8136
|
-
var todoNewInputSchema =
|
|
8137
|
-
todos:
|
|
8335
|
+
var todoNewInputSchema = import_zod14.z.object({
|
|
8336
|
+
todos: import_zod14.z.array(todoItemSchema).min(1).describe("Full todo list to start or replace the current plan.")
|
|
8138
8337
|
}).strict();
|
|
8139
|
-
var todoAppendInputSchema =
|
|
8140
|
-
todos:
|
|
8338
|
+
var todoAppendInputSchema = import_zod14.z.object({
|
|
8339
|
+
todos: import_zod14.z.array(todoItemSchema).min(1).describe("Todo items to append to the current plan.")
|
|
8141
8340
|
}).strict();
|
|
8142
|
-
var todoPatchInputSchema =
|
|
8143
|
-
updates:
|
|
8341
|
+
var todoPatchInputSchema = import_zod14.z.object({
|
|
8342
|
+
updates: import_zod14.z.array(todoPatchItemSchema).min(1).describe("Patch operations for existing todo items.")
|
|
8144
8343
|
}).strict();
|
|
8145
|
-
var todoClearInputSchema =
|
|
8344
|
+
var todoClearInputSchema = import_zod14.z.object({}).strict();
|
|
8146
8345
|
var statusSymbol = {
|
|
8147
8346
|
pending: "[ ]",
|
|
8148
8347
|
in_progress: "[>]",
|
|
@@ -8197,11 +8396,11 @@ var withPatchApplied = (currentTodos, updates) => {
|
|
|
8197
8396
|
const previous = nextInputs[index];
|
|
8198
8397
|
nextInputs[index] = {
|
|
8199
8398
|
...previous,
|
|
8200
|
-
content: update.content !==
|
|
8201
|
-
status: update.status !==
|
|
8202
|
-
priority: update.priority !==
|
|
8203
|
-
notes: update.notes !==
|
|
8204
|
-
activeForm: update.activeForm !==
|
|
8399
|
+
content: update.content !== void 0 ? update.content : previous.content,
|
|
8400
|
+
status: update.status !== void 0 ? update.status : previous.status,
|
|
8401
|
+
priority: update.priority !== void 0 ? update.priority : previous.priority,
|
|
8402
|
+
notes: update.notes !== void 0 ? update.notes : previous.notes,
|
|
8403
|
+
activeForm: update.activeForm !== void 0 ? update.activeForm : previous.activeForm
|
|
8205
8404
|
};
|
|
8206
8405
|
}
|
|
8207
8406
|
return { todos: normalizeTodoItems(nextInputs) };
|
|
@@ -8293,7 +8492,7 @@ var createTodoClearTool = (sandboxKey, sessionContextKey) => createTodoMutationT
|
|
|
8293
8492
|
|
|
8294
8493
|
// src/tools/todo-read.ts
|
|
8295
8494
|
var import_core16 = require("@codelia/core");
|
|
8296
|
-
var
|
|
8495
|
+
var import_zod15 = require("zod");
|
|
8297
8496
|
var statusSymbol2 = {
|
|
8298
8497
|
pending: "[ ]",
|
|
8299
8498
|
in_progress: "[>]",
|
|
@@ -8302,7 +8501,7 @@ var statusSymbol2 = {
|
|
|
8302
8501
|
var createTodoReadTool = (sandboxKey, sessionContextKey) => (0, import_core16.defineTool)({
|
|
8303
8502
|
name: "todo_read",
|
|
8304
8503
|
description: "Read the in-session todo plan with execution order and next step.",
|
|
8305
|
-
input:
|
|
8504
|
+
input: import_zod15.z.object({}),
|
|
8306
8505
|
execute: async (_input, ctx) => {
|
|
8307
8506
|
const sandbox = await getSandboxContext(ctx, sandboxKey);
|
|
8308
8507
|
const sessionContext = sessionContextKey ? await getToolSessionContext(ctx, sessionContextKey) : null;
|
|
@@ -8339,14 +8538,14 @@ var createTodoReadTool = (sandboxKey, sessionContextKey) => (0, import_core16.de
|
|
|
8339
8538
|
|
|
8340
8539
|
// src/tools/tool-output-cache.ts
|
|
8341
8540
|
var import_core17 = require("@codelia/core");
|
|
8342
|
-
var
|
|
8541
|
+
var import_zod16 = require("zod");
|
|
8343
8542
|
var createToolOutputCacheTool = (store) => (0, import_core17.defineTool)({
|
|
8344
8543
|
name: "tool_output_cache",
|
|
8345
8544
|
description: "Read cached tool output by ref_id.",
|
|
8346
|
-
input:
|
|
8347
|
-
ref_id:
|
|
8348
|
-
offset:
|
|
8349
|
-
limit:
|
|
8545
|
+
input: import_zod16.z.object({
|
|
8546
|
+
ref_id: import_zod16.z.string().describe("Tool output reference ID."),
|
|
8547
|
+
offset: import_zod16.z.number().int().nonnegative().optional().describe("Optional 0-based line offset."),
|
|
8548
|
+
limit: import_zod16.z.number().int().positive().optional().describe("Optional max number of lines to return.")
|
|
8350
8549
|
}),
|
|
8351
8550
|
execute: async (input) => {
|
|
8352
8551
|
if (!store.read) {
|
|
@@ -8365,11 +8564,11 @@ var createToolOutputCacheTool = (store) => (0, import_core17.defineTool)({
|
|
|
8365
8564
|
var createToolOutputCacheLineTool = (store) => (0, import_core17.defineTool)({
|
|
8366
8565
|
name: "tool_output_cache_line",
|
|
8367
8566
|
description: "Read a single cached output line segment by line number and char offset.",
|
|
8368
|
-
input:
|
|
8369
|
-
ref_id:
|
|
8370
|
-
line_number:
|
|
8371
|
-
char_offset:
|
|
8372
|
-
char_limit:
|
|
8567
|
+
input: import_zod16.z.object({
|
|
8568
|
+
ref_id: import_zod16.z.string().describe("Tool output reference ID."),
|
|
8569
|
+
line_number: import_zod16.z.number().int().positive().describe("1-based line number to read."),
|
|
8570
|
+
char_offset: import_zod16.z.number().int().nonnegative().optional().describe("0-based start character in the target line. Default 0."),
|
|
8571
|
+
char_limit: import_zod16.z.number().int().positive().optional().describe("Max chars to return.")
|
|
8373
8572
|
}),
|
|
8374
8573
|
execute: async (input) => {
|
|
8375
8574
|
if (!store.readLine) {
|
|
@@ -8389,13 +8588,13 @@ var createToolOutputCacheLineTool = (store) => (0, import_core17.defineTool)({
|
|
|
8389
8588
|
var createToolOutputCacheGrepTool = (store) => (0, import_core17.defineTool)({
|
|
8390
8589
|
name: "tool_output_cache_grep",
|
|
8391
8590
|
description: "Search cached tool output by ref_id.",
|
|
8392
|
-
input:
|
|
8393
|
-
ref_id:
|
|
8394
|
-
pattern:
|
|
8395
|
-
regex:
|
|
8396
|
-
before:
|
|
8397
|
-
after:
|
|
8398
|
-
max_matches:
|
|
8591
|
+
input: import_zod16.z.object({
|
|
8592
|
+
ref_id: import_zod16.z.string().describe("Tool output reference ID."),
|
|
8593
|
+
pattern: import_zod16.z.string().describe("Text or regex pattern to search for."),
|
|
8594
|
+
regex: import_zod16.z.boolean().optional().describe("Interpret pattern as regex when true. Default false."),
|
|
8595
|
+
before: import_zod16.z.number().int().nonnegative().optional().describe("Context lines before each match. Default 0."),
|
|
8596
|
+
after: import_zod16.z.number().int().nonnegative().optional().describe("Context lines after each match. Default 0."),
|
|
8597
|
+
max_matches: import_zod16.z.number().int().positive().optional().describe("Maximum number of matches to return.")
|
|
8399
8598
|
}),
|
|
8400
8599
|
execute: async (input) => {
|
|
8401
8600
|
if (!store.grep) {
|
|
@@ -8419,7 +8618,7 @@ var createToolOutputCacheGrepTool = (store) => (0, import_core17.defineTool)({
|
|
|
8419
8618
|
var import_node_fs13 = require("fs");
|
|
8420
8619
|
var import_node_path13 = __toESM(require("path"), 1);
|
|
8421
8620
|
var import_core18 = require("@codelia/core");
|
|
8422
|
-
var
|
|
8621
|
+
var import_zod17 = require("zod");
|
|
8423
8622
|
var DEFAULT_MAX_BYTES2 = 5 * 1024 * 1024;
|
|
8424
8623
|
var MAX_MAX_BYTES = 10 * 1024 * 1024;
|
|
8425
8624
|
var MIME_BY_EXTENSION = {
|
|
@@ -8435,14 +8634,14 @@ var resolveImageMime = (filePath) => {
|
|
|
8435
8634
|
var createViewImageTool = (sandboxKey) => (0, import_core18.defineTool)({
|
|
8436
8635
|
name: "view_image",
|
|
8437
8636
|
description: "Load one local png/jpeg/webp/gif image (default max 5MB) for multimodal inspection.",
|
|
8438
|
-
input:
|
|
8439
|
-
file_path:
|
|
8637
|
+
input: import_zod17.z.object({
|
|
8638
|
+
file_path: import_zod17.z.string().describe(
|
|
8440
8639
|
"Single local png/jpeg/webp/gif image path. Sandbox-bounded unless full-access mode is active."
|
|
8441
8640
|
),
|
|
8442
|
-
detail:
|
|
8641
|
+
detail: import_zod17.z.enum(["auto", "low", "high"]).optional().describe(
|
|
8443
8642
|
"Model image-detail hint (`auto`/`low`/`high`). Default auto."
|
|
8444
8643
|
),
|
|
8445
|
-
max_bytes:
|
|
8644
|
+
max_bytes: import_zod17.z.number().int().positive().max(MAX_MAX_BYTES).optional().describe("Max file size in bytes. Default 5242880, Max 10485760.")
|
|
8446
8645
|
}),
|
|
8447
8646
|
execute: async (input, ctx) => {
|
|
8448
8647
|
let resolved;
|
|
@@ -8493,7 +8692,7 @@ var createViewImageTool = (sandboxKey) => (0, import_core18.defineTool)({
|
|
|
8493
8692
|
|
|
8494
8693
|
// src/tools/webfetch.ts
|
|
8495
8694
|
var import_core19 = require("@codelia/core");
|
|
8496
|
-
var
|
|
8695
|
+
var import_zod18 = require("zod");
|
|
8497
8696
|
var DEFAULT_TIMEOUT_MS3 = 1e4;
|
|
8498
8697
|
var MAX_TIMEOUT_MS = 3e4;
|
|
8499
8698
|
var DEFAULT_MAX_BYTES3 = 2e5;
|
|
@@ -8749,13 +8948,13 @@ var classifyFetchError = (error, timeoutMs) => {
|
|
|
8749
8948
|
var createWebfetchTool = () => (0, import_core19.defineTool)({
|
|
8750
8949
|
name: "webfetch",
|
|
8751
8950
|
description: "Fetch an HTTP(S) URL and return bounded normalized markdown/text/html for textual content, not binary downloads.",
|
|
8752
|
-
input:
|
|
8753
|
-
url:
|
|
8754
|
-
output_format:
|
|
8755
|
-
timeout_ms:
|
|
8951
|
+
input: import_zod18.z.object({
|
|
8952
|
+
url: import_zod18.z.string().min(1).describe("HTTP(S) URL to fetch."),
|
|
8953
|
+
output_format: import_zod18.z.enum(["markdown", "text", "html"]).optional().describe("Normalized output format. Default markdown."),
|
|
8954
|
+
timeout_ms: import_zod18.z.number().int().positive().max(MAX_TIMEOUT_MS).optional().describe(
|
|
8756
8955
|
`Fetch timeout in ms. Default ${DEFAULT_TIMEOUT_MS3}, Max ${MAX_TIMEOUT_MS}.`
|
|
8757
8956
|
),
|
|
8758
|
-
max_bytes:
|
|
8957
|
+
max_bytes: import_zod18.z.number().int().positive().max(MAX_MAX_BYTES2).optional().describe(
|
|
8759
8958
|
`Max response bytes to keep. Default ${DEFAULT_MAX_BYTES3}, Max ${MAX_MAX_BYTES2}.`
|
|
8760
8959
|
)
|
|
8761
8960
|
}),
|
|
@@ -8829,15 +9028,16 @@ var createWebfetchTool = () => (0, import_core19.defineTool)({
|
|
|
8829
9028
|
var import_node_fs14 = require("fs");
|
|
8830
9029
|
var import_node_path14 = __toESM(require("path"), 1);
|
|
8831
9030
|
var import_core20 = require("@codelia/core");
|
|
8832
|
-
var
|
|
9031
|
+
var import_zod19 = require("zod");
|
|
8833
9032
|
var createWriteTool = (sandboxKey, outputCacheStore) => (0, import_core20.defineTool)({
|
|
8834
9033
|
name: "write",
|
|
8835
|
-
description: "Write full UTF-8 text to a file, replacing any existing contents and creating parent directories if needed.",
|
|
8836
|
-
input:
|
|
8837
|
-
file_path:
|
|
9034
|
+
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.",
|
|
9035
|
+
input: import_zod19.z.object({
|
|
9036
|
+
file_path: import_zod19.z.string().describe(
|
|
8838
9037
|
"File path. Sandbox-bounded unless full-access mode is active."
|
|
8839
9038
|
),
|
|
8840
|
-
content:
|
|
9039
|
+
content: import_zod19.z.string().describe("Full replacement UTF-8 text content to write."),
|
|
9040
|
+
expected_hash: expectedContentHashSchema
|
|
8841
9041
|
}),
|
|
8842
9042
|
execute: async (input, ctx) => {
|
|
8843
9043
|
let resolved;
|
|
@@ -8849,13 +9049,21 @@ var createWriteTool = (sandboxKey, outputCacheStore) => (0, import_core20.define
|
|
|
8849
9049
|
}
|
|
8850
9050
|
try {
|
|
8851
9051
|
let before = "";
|
|
9052
|
+
let fileExists = false;
|
|
8852
9053
|
try {
|
|
8853
9054
|
before = await import_node_fs14.promises.readFile(resolved, "utf8");
|
|
9055
|
+
fileExists = true;
|
|
8854
9056
|
} catch (error) {
|
|
8855
9057
|
if (error.code !== "ENOENT") {
|
|
8856
9058
|
throw error;
|
|
8857
9059
|
}
|
|
8858
9060
|
}
|
|
9061
|
+
assertExpectedContentHash({
|
|
9062
|
+
expectedHash: input.expected_hash,
|
|
9063
|
+
fileExists,
|
|
9064
|
+
content: before,
|
|
9065
|
+
filePath: input.file_path
|
|
9066
|
+
});
|
|
8859
9067
|
await import_node_fs14.promises.mkdir(import_node_path14.default.dirname(resolved), { recursive: true });
|
|
8860
9068
|
await import_node_fs14.promises.writeFile(resolved, input.content, "utf8");
|
|
8861
9069
|
const diffPayload = await buildDiffPayload({
|
|
@@ -8885,6 +9093,11 @@ var createTools = (sandboxKey, agentsResolverKey, skillsResolverKey, options = {
|
|
|
8885
9093
|
outputCacheStore: options.toolOutputCacheStore,
|
|
8886
9094
|
sessionContextKey: options.todoSessionContextKey
|
|
8887
9095
|
}),
|
|
9096
|
+
createShellStdinWriteTool({
|
|
9097
|
+
taskManager: options.taskManager,
|
|
9098
|
+
outputCacheStore: options.toolOutputCacheStore,
|
|
9099
|
+
sessionContextKey: options.todoSessionContextKey
|
|
9100
|
+
}),
|
|
8888
9101
|
createShellListTool({
|
|
8889
9102
|
taskManager: options.taskManager,
|
|
8890
9103
|
outputCacheStore: options.toolOutputCacheStore
|