laohuang 0.3.2 → 0.4.0
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/README.md +142 -16
- package/dist/agent.d.ts +166 -0
- package/dist/agent.js +858 -0
- package/dist/agent.js.map +1 -0
- package/dist/bash-runner.d.ts +79 -0
- package/dist/bash-runner.js +464 -0
- package/dist/bash-runner.js.map +1 -0
- package/dist/cancellation.d.ts +36 -0
- package/dist/cancellation.js +123 -0
- package/dist/cancellation.js.map +1 -0
- package/dist/cli.d.ts +117 -0
- package/dist/cli.js +1307 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +21 -0
- package/dist/client.js +17 -0
- package/dist/client.js.map +1 -0
- package/dist/commands.d.ts +123 -0
- package/dist/commands.js +660 -0
- package/dist/commands.js.map +1 -0
- package/dist/config.d.ts +51 -0
- package/dist/config.js +183 -0
- package/dist/config.js.map +1 -0
- package/dist/credentials.d.ts +12 -0
- package/dist/credentials.js +102 -0
- package/dist/credentials.js.map +1 -0
- package/dist/events.d.ts +288 -0
- package/dist/events.js +838 -0
- package/dist/events.js.map +1 -0
- package/dist/model-adapter.d.ts +138 -0
- package/dist/model-adapter.js +244 -0
- package/dist/model-adapter.js.map +1 -0
- package/dist/model-selection.d.ts +67 -0
- package/dist/model-selection.js +148 -0
- package/dist/model-selection.js.map +1 -0
- package/dist/model-stream.d.ts +128 -0
- package/dist/model-stream.js +582 -0
- package/dist/model-stream.js.map +1 -0
- package/dist/project-instructions.d.ts +99 -0
- package/dist/project-instructions.js +348 -0
- package/dist/project-instructions.js.map +1 -0
- package/dist/providers.d.ts +9 -0
- package/dist/providers.js +26 -0
- package/dist/providers.js.map +1 -0
- package/dist/routing.d.ts +170 -0
- package/dist/routing.js +669 -0
- package/dist/routing.js.map +1 -0
- package/dist/semantic-classifier.d.ts +66 -0
- package/dist/semantic-classifier.js +86 -0
- package/dist/semantic-classifier.js.map +1 -0
- package/dist/session.d.ts +162 -0
- package/dist/session.js +871 -0
- package/dist/session.js.map +1 -0
- package/dist/system-prompt.d.ts +16 -0
- package/dist/system-prompt.js +42 -0
- package/dist/system-prompt.js.map +1 -0
- package/dist/terminal/editor.d.ts +161 -0
- package/dist/terminal/editor.js +1060 -0
- package/dist/terminal/editor.js.map +1 -0
- package/dist/terminal/input.d.ts +61 -0
- package/dist/terminal/input.js +276 -0
- package/dist/terminal/input.js.map +1 -0
- package/dist/terminal/markdown.d.ts +20 -0
- package/dist/terminal/markdown.js +621 -0
- package/dist/terminal/markdown.js.map +1 -0
- package/dist/terminal/screen.d.ts +66 -0
- package/dist/terminal/screen.js +624 -0
- package/dist/terminal/screen.js.map +1 -0
- package/dist/terminal/theme.d.ts +23 -0
- package/dist/terminal/theme.js +101 -0
- package/dist/terminal/theme.js.map +1 -0
- package/dist/terminal/ui.d.ts +285 -0
- package/dist/terminal/ui.js +1815 -0
- package/dist/terminal/ui.js.map +1 -0
- package/dist/tools.d.ts +95 -0
- package/dist/tools.js +444 -0
- package/dist/tools.js.map +1 -0
- package/dist/ui-state.d.ts +51 -0
- package/dist/ui-state.js +194 -0
- package/dist/ui-state.js.map +1 -0
- package/dist/web.d.ts +56 -0
- package/dist/web.js +247 -0
- package/dist/web.js.map +1 -0
- package/package.json +24 -21
- package/bin/laohuang.js +0 -10
- package/lib/launcher.js +0 -133
- package/vendor/laohuangcode-0.3.2-py3-none-any.whl +0 -0
package/dist/tools.js
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/** Tool definitions and execution for the coding agent. */
|
|
2
|
+
import { promises as fs } from "node:fs";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { runBash as runBashCommand } from "./bash-runner.js";
|
|
6
|
+
/** The fixed tool set, in the canonical prompt/schema order. */
|
|
7
|
+
export const TOOL_SPECS = [
|
|
8
|
+
{
|
|
9
|
+
name: "read",
|
|
10
|
+
description: "Read a UTF-8 text file inside the project root.",
|
|
11
|
+
parameters: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {
|
|
14
|
+
path: { type: "string", description: "File path." },
|
|
15
|
+
offset: {
|
|
16
|
+
type: "integer",
|
|
17
|
+
description: "1-based line number to start reading from.",
|
|
18
|
+
minimum: 1,
|
|
19
|
+
},
|
|
20
|
+
limit: {
|
|
21
|
+
type: "integer",
|
|
22
|
+
description: "Maximum number of lines to return.",
|
|
23
|
+
minimum: 1,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
required: ["path"],
|
|
27
|
+
additionalProperties: false,
|
|
28
|
+
},
|
|
29
|
+
promptGuidelines: [
|
|
30
|
+
"Use read for ordinary file inspection rather than cat/sed.",
|
|
31
|
+
"Use offset/limit to page through large files.",
|
|
32
|
+
"Inspect an existing file before changing it.",
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "write",
|
|
37
|
+
description: "Create or fully overwrite a UTF-8 text file.",
|
|
38
|
+
parameters: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
path: { type: "string", description: "File path." },
|
|
42
|
+
content: { type: "string", description: "Full file content." },
|
|
43
|
+
},
|
|
44
|
+
required: ["path", "content"],
|
|
45
|
+
additionalProperties: false,
|
|
46
|
+
},
|
|
47
|
+
promptGuidelines: [
|
|
48
|
+
"Use write only to create a file or replace all of one; use edit for local changes.",
|
|
49
|
+
"Confirm the path and the complete content before writing.",
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "edit",
|
|
54
|
+
description: "Apply a batch of exact, unique text replacements to a file atomically.",
|
|
55
|
+
parameters: {
|
|
56
|
+
type: "object",
|
|
57
|
+
properties: {
|
|
58
|
+
path: { type: "string", description: "File path." },
|
|
59
|
+
edits: {
|
|
60
|
+
type: "array",
|
|
61
|
+
description: "Non-empty list of exact replacements, matched against the original file content.",
|
|
62
|
+
minItems: 1,
|
|
63
|
+
items: {
|
|
64
|
+
type: "object",
|
|
65
|
+
properties: {
|
|
66
|
+
old_text: {
|
|
67
|
+
type: "string",
|
|
68
|
+
description: "Exact text to replace; must appear exactly once in the original content.",
|
|
69
|
+
},
|
|
70
|
+
new_text: { type: "string", description: "Replacement text." },
|
|
71
|
+
},
|
|
72
|
+
required: ["old_text", "new_text"],
|
|
73
|
+
additionalProperties: false,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
required: ["path", "edits"],
|
|
78
|
+
additionalProperties: false,
|
|
79
|
+
},
|
|
80
|
+
promptGuidelines: [
|
|
81
|
+
"Use edit for local changes; targets must exactly and uniquely match the original file.",
|
|
82
|
+
"Edits in one batch are matched against the original content and must not overlap.",
|
|
83
|
+
"Inspect the file first and verify the change when practical.",
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "bash",
|
|
88
|
+
description: "Run a Bash command inside the project root.",
|
|
89
|
+
parameters: {
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: {
|
|
92
|
+
command: { type: "string", description: "Bash command." },
|
|
93
|
+
description: {
|
|
94
|
+
type: "string",
|
|
95
|
+
description: "Concise purpose of the command.",
|
|
96
|
+
},
|
|
97
|
+
workdir: {
|
|
98
|
+
type: "string",
|
|
99
|
+
description: "Working directory for the command; must resolve inside the project root. Defaults to the project root.",
|
|
100
|
+
},
|
|
101
|
+
timeoutMs: {
|
|
102
|
+
type: "integer",
|
|
103
|
+
description: "Timeout in milliseconds.",
|
|
104
|
+
minimum: 1,
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
required: ["command", "description"],
|
|
108
|
+
additionalProperties: false,
|
|
109
|
+
},
|
|
110
|
+
promptGuidelines: [
|
|
111
|
+
"Supply a concise description of what the command does.",
|
|
112
|
+
"Use workdir instead of cd.",
|
|
113
|
+
"Each call runs in an independent shell; state does not persist between calls.",
|
|
114
|
+
"On a non-zero exit, inspect the output before retrying.",
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
];
|
|
118
|
+
/**
|
|
119
|
+
* Internal side channel: the resolved absolute path touched by a successful
|
|
120
|
+
* first-party file tool (read/write/edit), attached non-enumerably so it
|
|
121
|
+
* never serializes into model-visible history. Consumed only by the agent
|
|
122
|
+
* layer for project-instruction discovery.
|
|
123
|
+
*/
|
|
124
|
+
export const TOUCHED_PATH = Symbol("laohuang.touchedPath");
|
|
125
|
+
/** The resolved path a successful file tool touched, if recorded. */
|
|
126
|
+
export function touchedPathOf(result) {
|
|
127
|
+
return result[TOUCHED_PATH];
|
|
128
|
+
}
|
|
129
|
+
/** Attach the touched path invisibly: JSON.stringify, spreads, and
|
|
130
|
+
* Object.entries all skip non-enumerable symbol properties. */
|
|
131
|
+
function withTouchedPath(result, target) {
|
|
132
|
+
Object.defineProperty(result, TOUCHED_PATH, {
|
|
133
|
+
value: target,
|
|
134
|
+
enumerable: false,
|
|
135
|
+
configurable: true,
|
|
136
|
+
});
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
const DEFAULT_IO = {
|
|
140
|
+
readFile: (target) => fs.readFile(target, "utf8"),
|
|
141
|
+
writeFile: (target, content) => fs.writeFile(target, content, "utf8"),
|
|
142
|
+
};
|
|
143
|
+
const NOOP_CONTEXT = {
|
|
144
|
+
isCancelled: () => false,
|
|
145
|
+
cancellationReason: "cancelled",
|
|
146
|
+
publish: () => { },
|
|
147
|
+
};
|
|
148
|
+
async function defaultRunBash(command, options) {
|
|
149
|
+
// Only a context carrying the full publish() surface is safe to hand to
|
|
150
|
+
// bash-runner; anything else (e.g. a bare test stub) is replaced so the
|
|
151
|
+
// runner can fall back to its own default context.
|
|
152
|
+
const context = typeof options.context.publish === "function" ? options.context : null;
|
|
153
|
+
const result = await runBashCommand(command, {
|
|
154
|
+
cwd: options.cwd,
|
|
155
|
+
timeout: options.timeoutSeconds,
|
|
156
|
+
maxOutputChars: options.maxOutputChars,
|
|
157
|
+
context: context,
|
|
158
|
+
env: options.env,
|
|
159
|
+
});
|
|
160
|
+
return result.asDict();
|
|
161
|
+
}
|
|
162
|
+
// Serializes write/edit critical sections per resolved file path, mirroring
|
|
163
|
+
// the Python module-level _MUTATION_LOCKS keyed by Path.
|
|
164
|
+
const mutationLocks = new Map();
|
|
165
|
+
async function withFileMutationLock(key, fn) {
|
|
166
|
+
const previous = mutationLocks.get(key) ?? Promise.resolve();
|
|
167
|
+
let release;
|
|
168
|
+
const current = new Promise((resolve) => {
|
|
169
|
+
release = resolve;
|
|
170
|
+
});
|
|
171
|
+
const tail = previous.then(() => current);
|
|
172
|
+
mutationLocks.set(key, tail);
|
|
173
|
+
await previous;
|
|
174
|
+
try {
|
|
175
|
+
return await fn();
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
release();
|
|
179
|
+
if (mutationLocks.get(key) === tail) {
|
|
180
|
+
mutationLocks.delete(key);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/** Non-strict realpath: resolves symlinks for the deepest existing ancestor
|
|
185
|
+
* and appends the not-yet-created remainder (Python Path.resolve semantics). */
|
|
186
|
+
async function resolveNonStrict(pathname) {
|
|
187
|
+
const missing = [];
|
|
188
|
+
let current = pathname;
|
|
189
|
+
for (;;) {
|
|
190
|
+
try {
|
|
191
|
+
const real = await fs.realpath(current);
|
|
192
|
+
return missing.length === 0 ? real : path.join(real, ...missing.reverse());
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
if (error.code !== "ENOENT") {
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
const parent = path.dirname(current);
|
|
199
|
+
if (parent === current) {
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
missing.push(path.basename(current));
|
|
203
|
+
current = parent;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function resolveNonStrictSync(pathname) {
|
|
208
|
+
const missing = [];
|
|
209
|
+
let current = pathname;
|
|
210
|
+
for (;;) {
|
|
211
|
+
try {
|
|
212
|
+
const real = realpathSync(current);
|
|
213
|
+
return missing.length === 0 ? real : path.join(real, ...missing.reverse());
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
if (error.code !== "ENOENT") {
|
|
217
|
+
throw error;
|
|
218
|
+
}
|
|
219
|
+
const parent = path.dirname(current);
|
|
220
|
+
if (parent === current) {
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
missing.push(path.basename(current));
|
|
224
|
+
current = parent;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/** Counts non-overlapping occurrences, matching Python str.count
|
|
229
|
+
* (including the empty-needle edge: len(text) + 1). */
|
|
230
|
+
function countOccurrences(haystack, needle) {
|
|
231
|
+
if (needle === "") {
|
|
232
|
+
return haystack.length + 1;
|
|
233
|
+
}
|
|
234
|
+
let count = 0;
|
|
235
|
+
let index = 0;
|
|
236
|
+
while ((index = haystack.indexOf(needle, index)) !== -1) {
|
|
237
|
+
count += 1;
|
|
238
|
+
index += needle.length;
|
|
239
|
+
}
|
|
240
|
+
return count;
|
|
241
|
+
}
|
|
242
|
+
function stringArgument(args, key) {
|
|
243
|
+
const value = args[key];
|
|
244
|
+
if (typeof value !== "string") {
|
|
245
|
+
throw new Error(`Missing or invalid argument: ${key}`);
|
|
246
|
+
}
|
|
247
|
+
return value;
|
|
248
|
+
}
|
|
249
|
+
/** Optional positive-integer argument; undefined when absent. */
|
|
250
|
+
function optionalPositiveInteger(args, key) {
|
|
251
|
+
const value = args[key];
|
|
252
|
+
if (value === undefined) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
256
|
+
throw new Error(`Argument ${key} must be a positive integer`);
|
|
257
|
+
}
|
|
258
|
+
return value;
|
|
259
|
+
}
|
|
260
|
+
/** Validate the batched `edits` argument (non-empty array of pairs). */
|
|
261
|
+
function editsArgument(args) {
|
|
262
|
+
const value = args["edits"];
|
|
263
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
264
|
+
throw new Error("Missing or invalid argument: edits");
|
|
265
|
+
}
|
|
266
|
+
return value.map((entry, index) => {
|
|
267
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
|
|
268
|
+
throw new Error(`edits[${index}] must be an object`);
|
|
269
|
+
}
|
|
270
|
+
const record = entry;
|
|
271
|
+
return {
|
|
272
|
+
oldText: stringArgument(record, "old_text"),
|
|
273
|
+
newText: stringArgument(record, "new_text"),
|
|
274
|
+
};
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
function cancelledResult(context) {
|
|
278
|
+
return {
|
|
279
|
+
ok: false,
|
|
280
|
+
status: "cancelled",
|
|
281
|
+
error: context.cancellationReason,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
/** Execute the small set of tools exposed to the model. */
|
|
285
|
+
export class ToolRegistry {
|
|
286
|
+
root;
|
|
287
|
+
bashTimeoutSeconds;
|
|
288
|
+
maxOutputChars;
|
|
289
|
+
executionModes;
|
|
290
|
+
runBash;
|
|
291
|
+
io;
|
|
292
|
+
constructor(root, options = {}) {
|
|
293
|
+
this.root = resolveNonStrictSync(path.resolve(root));
|
|
294
|
+
this.bashTimeoutSeconds = options.bashTimeoutSeconds ?? 120;
|
|
295
|
+
this.maxOutputChars = options.maxOutputChars ?? 20_000;
|
|
296
|
+
this.executionModes = { ...(options.executionModes ?? {}) };
|
|
297
|
+
this.runBash = options.runBash ?? defaultRunBash;
|
|
298
|
+
this.io = options.io ?? DEFAULT_IO;
|
|
299
|
+
}
|
|
300
|
+
get definitions() {
|
|
301
|
+
// promptGuidelines never leaks into the OpenAI tools payload.
|
|
302
|
+
return TOOL_SPECS.map((spec) => ({
|
|
303
|
+
type: "function",
|
|
304
|
+
function: {
|
|
305
|
+
name: spec.name,
|
|
306
|
+
description: spec.description,
|
|
307
|
+
parameters: spec.parameters,
|
|
308
|
+
},
|
|
309
|
+
}));
|
|
310
|
+
}
|
|
311
|
+
/** Ordered fixed specs, consumed by the System Prompt builder. */
|
|
312
|
+
get orderedSpecs() {
|
|
313
|
+
return TOOL_SPECS;
|
|
314
|
+
}
|
|
315
|
+
executionMode(name) {
|
|
316
|
+
return this.executionModes[name];
|
|
317
|
+
}
|
|
318
|
+
async execute(name, args, context) {
|
|
319
|
+
const execution = context ?? NOOP_CONTEXT;
|
|
320
|
+
try {
|
|
321
|
+
if (execution.isCancelled()) {
|
|
322
|
+
return cancelledResult(execution);
|
|
323
|
+
}
|
|
324
|
+
if (name === "read") {
|
|
325
|
+
const target = await this.resolvePath(stringArgument(args, "path"));
|
|
326
|
+
const offset = optionalPositiveInteger(args, "offset") ?? 1;
|
|
327
|
+
const limit = optionalPositiveInteger(args, "limit");
|
|
328
|
+
const content = await this.io.readFile(target);
|
|
329
|
+
if (execution.isCancelled()) {
|
|
330
|
+
return cancelledResult(execution);
|
|
331
|
+
}
|
|
332
|
+
// Split after each newline so a window rejoins byte-identically.
|
|
333
|
+
const lines = content === "" ? [] : content.split(/(?<=\n)/);
|
|
334
|
+
const totalLines = lines.length;
|
|
335
|
+
if (offset > Math.max(totalLines, 1)) {
|
|
336
|
+
throw new Error(`offset ${offset} is out of range; the file has ${totalLines} lines`);
|
|
337
|
+
}
|
|
338
|
+
const window = lines.slice(offset - 1, limit === undefined ? undefined : offset - 1 + limit);
|
|
339
|
+
return withTouchedPath({
|
|
340
|
+
ok: true,
|
|
341
|
+
content: this.truncate(window.join("")),
|
|
342
|
+
offset,
|
|
343
|
+
limit: limit ?? null,
|
|
344
|
+
total_lines: totalLines,
|
|
345
|
+
has_more: offset - 1 + window.length < totalLines,
|
|
346
|
+
}, target);
|
|
347
|
+
}
|
|
348
|
+
if (name === "write") {
|
|
349
|
+
const rawPath = stringArgument(args, "path");
|
|
350
|
+
const target = await this.resolvePath(rawPath);
|
|
351
|
+
return await withFileMutationLock(target, async () => {
|
|
352
|
+
if (execution.isCancelled()) {
|
|
353
|
+
return cancelledResult(execution);
|
|
354
|
+
}
|
|
355
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
356
|
+
await this.io.writeFile(target, stringArgument(args, "content"));
|
|
357
|
+
return withTouchedPath({ ok: true, path: rawPath }, target);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
if (name === "edit") {
|
|
361
|
+
const rawPath = stringArgument(args, "path");
|
|
362
|
+
const target = await this.resolvePath(rawPath);
|
|
363
|
+
const edits = editsArgument(args);
|
|
364
|
+
return await withFileMutationLock(target, async () => {
|
|
365
|
+
if (execution.isCancelled()) {
|
|
366
|
+
return cancelledResult(execution);
|
|
367
|
+
}
|
|
368
|
+
const content = await this.io.readFile(target);
|
|
369
|
+
// Every edit matches against the pre-edit original content.
|
|
370
|
+
const ranges = edits.map((edit, index) => {
|
|
371
|
+
const matches = countOccurrences(content, edit.oldText);
|
|
372
|
+
if (matches !== 1) {
|
|
373
|
+
throw new Error(`edits[${index}]: old_text must appear exactly once; ` +
|
|
374
|
+
`found ${matches} matches`);
|
|
375
|
+
}
|
|
376
|
+
const start = content.indexOf(edit.oldText);
|
|
377
|
+
return { start, end: start + edit.oldText.length, index };
|
|
378
|
+
});
|
|
379
|
+
const ordered = [...ranges].sort((a, b) => a.start - b.start);
|
|
380
|
+
for (let i = 1; i < ordered.length; i += 1) {
|
|
381
|
+
const previous = ordered[i - 1];
|
|
382
|
+
const current = ordered[i];
|
|
383
|
+
if (current.start < previous.end) {
|
|
384
|
+
throw new Error(`edits[${previous.index}] and edits[${current.index}] overlap`);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
let updated = "";
|
|
388
|
+
let cursor = 0;
|
|
389
|
+
for (const range of ordered) {
|
|
390
|
+
updated += content.slice(cursor, range.start);
|
|
391
|
+
updated += edits[range.index].newText;
|
|
392
|
+
cursor = range.end;
|
|
393
|
+
}
|
|
394
|
+
updated += content.slice(cursor);
|
|
395
|
+
if (execution.isCancelled()) {
|
|
396
|
+
return cancelledResult(execution);
|
|
397
|
+
}
|
|
398
|
+
await this.io.writeFile(target, updated);
|
|
399
|
+
return withTouchedPath({ ok: true, path: rawPath }, target);
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
if (name === "bash") {
|
|
403
|
+
const command = stringArgument(args, "command");
|
|
404
|
+
// Required by the schema; validated here too so direct execute()
|
|
405
|
+
// callers get the same enforcement.
|
|
406
|
+
stringArgument(args, "description");
|
|
407
|
+
const workdir = args["workdir"];
|
|
408
|
+
const cwd = workdir === undefined
|
|
409
|
+
? this.root
|
|
410
|
+
: await this.resolvePath(stringArgument(args, "workdir"));
|
|
411
|
+
const timeoutMs = optionalPositiveInteger(args, "timeoutMs");
|
|
412
|
+
return await this.runBash(command, {
|
|
413
|
+
cwd,
|
|
414
|
+
timeoutSeconds: timeoutMs === undefined ? this.bashTimeoutSeconds : timeoutMs / 1000,
|
|
415
|
+
maxOutputChars: this.maxOutputChars,
|
|
416
|
+
context: execution,
|
|
417
|
+
env: process.env,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
return {
|
|
424
|
+
ok: false,
|
|
425
|
+
error: error instanceof Error ? error.message : String(error),
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
async resolvePath(rawPath) {
|
|
430
|
+
const resolved = await resolveNonStrict(path.resolve(this.root, rawPath));
|
|
431
|
+
if (resolved !== this.root && !resolved.startsWith(this.root + path.sep)) {
|
|
432
|
+
throw new Error(`Path is outside the project root: ${rawPath}`);
|
|
433
|
+
}
|
|
434
|
+
return resolved;
|
|
435
|
+
}
|
|
436
|
+
truncate(text) {
|
|
437
|
+
if (text.length <= this.maxOutputChars) {
|
|
438
|
+
return text;
|
|
439
|
+
}
|
|
440
|
+
const omitted = text.length - this.maxOutputChars;
|
|
441
|
+
return `${text.slice(0, this.maxOutputChars)}\n...[truncated ${omitted}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O,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC;QAClD,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,mBAAmB,OAAO,SAAS,CAAC;IAClF,CAAC;CACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Event-reduced terminal state, independent from the agent runtime. */
|
|
2
|
+
export interface ActiveResponse {
|
|
3
|
+
requestId: string;
|
|
4
|
+
text: string;
|
|
5
|
+
status: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ActiveTool {
|
|
8
|
+
toolCallId: string;
|
|
9
|
+
name: string;
|
|
10
|
+
subject: string;
|
|
11
|
+
stdout: string;
|
|
12
|
+
stderr: string;
|
|
13
|
+
status: string;
|
|
14
|
+
}
|
|
15
|
+
export interface UIState {
|
|
16
|
+
sessionState: string;
|
|
17
|
+
activeResponse: ActiveResponse | null;
|
|
18
|
+
activeTools: Map<string, ActiveTool>;
|
|
19
|
+
pendingCount: number;
|
|
20
|
+
heldCount: number;
|
|
21
|
+
provider: string;
|
|
22
|
+
model: string;
|
|
23
|
+
totalTokens: number;
|
|
24
|
+
inputTokens: number;
|
|
25
|
+
outputTokens: number;
|
|
26
|
+
}
|
|
27
|
+
export declare function createUIState(): UIState;
|
|
28
|
+
export interface UIUpdate {
|
|
29
|
+
kind: string;
|
|
30
|
+
text: string;
|
|
31
|
+
correlationId: string;
|
|
32
|
+
stream: string;
|
|
33
|
+
payload: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Minimal structural view of a canonical event. The concrete envelope type
|
|
37
|
+
* is owned by events.ts; anything carrying these fields is accepted.
|
|
38
|
+
*/
|
|
39
|
+
export interface UIEventLike {
|
|
40
|
+
kind?: unknown;
|
|
41
|
+
type?: unknown;
|
|
42
|
+
payload?: unknown;
|
|
43
|
+
correlation_id?: unknown;
|
|
44
|
+
}
|
|
45
|
+
/** Turn canonical events or projected dictionaries into small UI updates. */
|
|
46
|
+
export declare class UIEventReducer {
|
|
47
|
+
#private;
|
|
48
|
+
readonly state: UIState;
|
|
49
|
+
constructor(state?: UIState);
|
|
50
|
+
apply(event: UIEventLike): UIUpdate | null;
|
|
51
|
+
}
|