import libraries, increase file read limit (still low). verify wip

This commit is contained in:
Shivering Ocelot committed 2026-10-09 14:44:23 -05:00
1 parent 80454f9a2a
commit ff65f18f80
3 files changed
+60 -15

No files matched your search

+10 -3
View File
@@ -16,7 +16,7 @@
import * as fs from 'fs';
import * as path from 'path';
const MAX_READ_BYTES = 1024;
const MAX_READ_BYTES = 10*1024;
const MAX_ITERATIONS = 20;
/* ------------------------------------------------------------------ *
@@ -66,12 +66,13 @@ function readFile(args, { root, scope }) {
let lines = fs.readFileSync(abs, 'utf8').split('\n');
const from = args.lineStart != null ? args.lineStart - 1 : 0;
const to = args.lineEnd != null ? args.lineEnd : lines.length;
const lineCount = lines.length;
lines = lines.slice(from, to);
let content = lines.join('\n');
const bytes = Buffer.from(content, 'utf8');
if (bytes.length > MAX_READ_BYTES) {
content = bytes.slice(0, MAX_READ_BYTES).toString('utf8');
throw new Error(`too large: ${bytes.length} bytes requested (max ${MAX_READ_BYTES}, ${lineCount} lines in ${file})`);
}
return content;
}
@@ -127,7 +128,7 @@ const DEFAULT_TOOLS = {
'read-file': {
scope: 'read',
handler: readFile,
description: 'Read a file.',
description: 'Read up to 10KB from a file, with optional line range.',
parameters: {
type: 'object',
properties: {
@@ -239,6 +240,7 @@ function makeExecutor(bundle, root) {
try {
return tool.handler(args || {}, { root, scope: tool.scope });
} catch (err) {
console.error(err);
return `Error: ${err.message}`;
}
};
@@ -355,6 +357,7 @@ async function run({
open = null,
tools = null,
defaultTools = true,
verify = null,
} = {}) {
const Gral = global.Gral;
const root = Gral && Gral.path ? Gral.path : process.cwd();
@@ -420,6 +423,10 @@ async function run({
if (calls.length) {
console.log('called: ' + calls.map(c => c.tool_name));
}
if (verify && verify()) {
return null;
}
}
throw new Error(`run: exceeded ${MAX_ITERATIONS} tool-call iterations`);