@agent-sh/harness-read 0.2.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/LICENSE +21 -0
- package/README.md +34 -0
- package/dist/index.cjs +590 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +141 -0
- package/dist/index.d.ts +141 -0
- package/dist/index.js +544 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/binary.ts","../src/format.ts","../src/lines.ts","../src/schema.ts","../src/suggest.ts","../src/read.ts"],"names":["path","Buffer","v","toolError","defaultNodeOperations","withFileLock","matchesAnyPattern","isInsideAnyRoot","createHash"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,IAAM,aAAA,GAAgB;AACtB,IAAM,eAAA,GAAkB;AACxB,IAAM,eAAA,GAAkB,0BAA0B,eAAe,CAAA,OAAA,CAAA;AACjE,IAAM,YAAY,EAAA,GAAK;AACvB,IAAM,eAAA,GAAkB,CAAA,EAAG,SAAA,GAAY,IAAI,CAAA,GAAA,CAAA;AAC3C,IAAM,aAAA,GAAgB,IAAI,IAAA,GAAO;AACjC,IAAM,mBAAA,GAAsB,IAAA;AAC5B,IAAM,sBAAA,GAAyB,CAAA;AAE/B,IAAM,iBAAA,uBAA6C,GAAA,CAAI;AAAA,EAC5D,MAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AAAA,EACA,QAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,MA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,MACA,UAAU,IAAA,CAAK,QAAA;AAAA,MACf,YAAY,IAAA,CAAK;AAAA;AACnB,GACF;AAEA,EAAA,IAAI,QAAQ,KAAA,EAAO;AACjB,IAAA,OAAA,CAAQ,KAAA,CAAM,GAAA;AAAA,MACZ;AAAA,QACE,IAAA,EAAM,YAAA;AAAA,QACN,UAAU,IAAA,CAAK,QAAA;AAAA,QACf,YAAY,IAAA,CAAK,IAAA;AAAA,QACjB,MAAA;AAAA,QACA;AAAA,OACF;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAEA,EAAA,IAAI,QAAQ,MAAA,EAAQ;AAClB,IAAA,OAAA,CAAQ,OAAO,MAAA,CAAO;AAAA,MACpB,IAAA,EAAM,YAAA;AAAA,MACN,MAAA;AAAA,MACA,UAAU,IAAA,CAAK,QAAA;AAAA,MACf,YAAY,IAAA,CAAK,IAAA;AAAA,MACjB,cAAA,EAAgB,OAAO,KAAA,CAAM,MAAA;AAAA,MAC7B,MAAA;AAAA,MACA,KAAA;AAAA,MACA,YAAA,EAAc,KAAK,GAAA;AAAI,KACxB,CAAA;AAAA,EACH;AAEA,EAAA,OAAO,UAAA;AACT","file":"index.cjs","sourcesContent":["export const DEFAULT_LIMIT = 2000;\nexport const MAX_LINE_LENGTH = 2000;\nexport const MAX_LINE_SUFFIX = `... (line truncated to ${MAX_LINE_LENGTH} chars)`;\nexport const MAX_BYTES = 50 * 1024;\nexport const MAX_BYTES_LABEL = `${MAX_BYTES / 1024} KB`;\nexport const MAX_FILE_SIZE = 5 * 1024 * 1024;\nexport const BINARY_SAMPLE_BYTES = 4096;\nexport const FUZZY_SUGGESTION_LIMIT = 3;\n\nexport const BINARY_EXTENSIONS: ReadonlySet<string> = new Set([\n \".zip\",\n \".tar\",\n \".gz\",\n \".exe\",\n \".dll\",\n \".so\",\n \".class\",\n \".jar\",\n \".war\",\n \".7z\",\n \".doc\",\n \".docx\",\n \".xls\",\n \".xlsx\",\n \".ppt\",\n \".pptx\",\n \".odt\",\n \".ods\",\n \".odp\",\n \".bin\",\n \".dat\",\n \".obj\",\n \".o\",\n \".a\",\n \".lib\",\n \".wasm\",\n \".pyc\",\n \".pyo\",\n]);\n","import path from \"node:path\";\nimport { BINARY_EXTENSIONS } from \"./constants.js\";\n\nexport function isBinaryByExtension(filepath: string): boolean {\n return BINARY_EXTENSIONS.has(path.extname(filepath).toLowerCase());\n}\n\nexport function isBinaryByContent(sample: Uint8Array): boolean {\n if (sample.length === 0) return false;\n let nonPrintable = 0;\n for (let i = 0; i < sample.length; i++) {\n const b = sample[i] as number;\n if (b === 0) return true;\n if (b < 9 || (b > 13 && b < 32)) nonPrintable++;\n }\n return nonPrintable / sample.length > 0.3;\n}\n\nexport function isBinary(filepath: string, sample: Uint8Array): boolean {\n return isBinaryByExtension(filepath) || isBinaryByContent(sample);\n}\n\nexport function isImageMime(mime: string): boolean {\n if (!mime.startsWith(\"image/\")) return false;\n if (mime === \"image/svg+xml\") return false;\n return true;\n}\n\nexport function isPdfMime(mime: string): boolean {\n return mime === \"application/pdf\";\n}\n","import { MAX_BYTES_LABEL } from \"./constants.js\";\nimport type {\n AttachmentReadResult,\n DirReadResult,\n TextReadResult,\n} from \"./types.js\";\n\nexport function formatText(\n params: {\n path: string;\n offset: number;\n lines: readonly string[];\n totalLines: number;\n more: boolean;\n byteCap: boolean;\n },\n): string {\n const { path, offset, lines, totalLines, more, byteCap } = params;\n const header = `<path>${path}</path>\\n<type>file</type>\\n<content>`;\n\n if (lines.length === 0 && totalLines === 0) {\n return `${header}\\n(File exists but is empty)\\n</content>`;\n }\n\n const body = lines.map((line, i) => `${offset + i}: ${line}`).join(\"\\n\");\n const last = offset + lines.length - 1;\n const next = last + 1;\n\n let hint: string;\n if (byteCap) {\n const pct = totalLines > 0 ? Math.round((last / totalLines) * 100) : 0;\n const remaining = Math.max(totalLines - last, 0);\n hint = `(Output capped at ${MAX_BYTES_LABEL}. Showing lines ${offset}-${last} of ${totalLines} · ${pct}% covered · ${remaining} lines remaining. Next offset: ${next}.)`;\n } else if (more) {\n const pct = Math.round((last / totalLines) * 100);\n const remaining = Math.max(totalLines - last, 0);\n hint = `(Showing lines ${offset}-${last} of ${totalLines} · ${pct}% covered · ${remaining} lines remaining. Next offset: ${next}.)`;\n } else {\n hint = `(End of file · ${totalLines} lines total)`;\n }\n\n return `${header}\\n${body}\\n\\n${hint}\\n</content>`;\n}\n\nexport function formatDirectory(params: {\n path: string;\n entries: readonly string[];\n offset: number;\n totalEntries: number;\n more: boolean;\n}): string {\n const { path, entries, offset, totalEntries, more } = params;\n const header = `<path>${path}</path>\\n<type>directory</type>\\n<entries>`;\n const body = entries.join(\"\\n\");\n const last = offset + entries.length - 1;\n const next = last + 1;\n const remaining = Math.max(totalEntries - last, 0);\n const hint = more\n ? `(Showing ${entries.length} of ${totalEntries} entries · ${remaining} remaining. Next offset: ${next}.)`\n : `(${totalEntries} entries)`;\n return `${header}\\n${body}\\n\\n${hint}\\n</entries>`;\n}\n\nexport function formatAttachment(kind: \"Image\" | \"PDF\"): string {\n return `${kind} read successfully`;\n}\n\nexport function asTextResult(x: TextReadResult): TextReadResult {\n return x;\n}\nexport function asDirResult(x: DirReadResult): DirReadResult {\n return x;\n}\nexport function asAttachResult(x: AttachmentReadResult): AttachmentReadResult {\n return x;\n}\n","import { Buffer } from \"node:buffer\";\nimport type { ReadOperations } from \"@agent-sh/harness-core\";\nimport {\n MAX_BYTES,\n MAX_LINE_LENGTH,\n MAX_LINE_SUFFIX,\n} from \"./constants.js\";\n\nexport interface StreamLinesOptions {\n readonly offset: number;\n readonly limit: number;\n readonly maxBytes?: number;\n readonly maxLineLength?: number;\n readonly signal?: AbortSignal;\n}\n\nexport interface StreamLinesResult {\n readonly lines: readonly string[];\n readonly totalLines: number;\n readonly offset: number;\n readonly more: boolean;\n readonly byteCap: boolean;\n}\n\nexport async function streamLines(\n ops: ReadOperations,\n path: string,\n opts: StreamLinesOptions,\n): Promise<StreamLinesResult> {\n const maxBytes = opts.maxBytes ?? MAX_BYTES;\n const maxLineLen = opts.maxLineLength ?? MAX_LINE_LENGTH;\n const start = opts.offset - 1;\n\n const out: string[] = [];\n let bytes = 0;\n let totalLines = 0;\n let more = false;\n let byteCap = false;\n\n const signalOpt: { signal?: AbortSignal } = {};\n if (opts.signal !== undefined) signalOpt.signal = opts.signal;\n\n const iter = ops.openLineStream(path, signalOpt);\n\n for await (const raw of iter) {\n totalLines += 1;\n if (totalLines <= start) continue;\n\n if (out.length >= opts.limit) {\n more = true;\n continue;\n }\n\n const truncated =\n raw.length > maxLineLen ? raw.substring(0, maxLineLen) + MAX_LINE_SUFFIX : raw;\n\n const size = Buffer.byteLength(truncated, \"utf8\") + (out.length > 0 ? 1 : 0);\n if (bytes + size > maxBytes) {\n byteCap = true;\n more = true;\n break;\n }\n\n out.push(truncated);\n bytes += size;\n }\n\n return {\n lines: out,\n totalLines,\n offset: opts.offset,\n more,\n byteCap,\n };\n}\n","import * as v from \"valibot\";\nimport type { ToolDefinition } from \"@agent-sh/harness-core\";\nimport type { ReadParams } from \"./types.js\";\n\nexport const ReadParamsSchema = v.object({\n path: v.pipe(v.string(), v.minLength(1, \"path must not be empty\")),\n offset: v.optional(\n v.pipe(v.number(), v.integer(), v.minValue(1, \"offset must be >= 1\")),\n ),\n limit: v.optional(\n v.pipe(v.number(), v.integer(), v.minValue(1, \"limit must be >= 1\")),\n ),\n});\n\nexport type ParsedReadParams = v.InferOutput<typeof ReadParamsSchema>;\n\nexport function parseReadParams(input: unknown): ParsedReadParams {\n return v.parse(ReadParamsSchema, input);\n}\n\nexport function safeParseReadParams(input: unknown):\n | { ok: true; value: ReadParams }\n | { ok: false; issues: v.BaseIssue<unknown>[] } {\n const result = v.safeParse(ReadParamsSchema, input);\n if (result.success) return { ok: true, value: result.output };\n return { ok: false, issues: result.issues };\n}\n\nexport const READ_TOOL_NAME = \"read\";\n\nexport const READ_TOOL_DESCRIPTION = `Read a file or directory from the local filesystem.\n\nUsage:\n- The path parameter should be an absolute path. If relative, it resolves against the session working directory.\n- By default, returns up to 2000 lines from the start of the file.\n- The offset parameter is the 1-indexed line number to start from.\n- For later sections, call this tool again with a larger offset.\n- Use the grep tool for content search in large files; glob to locate files by pattern.\n- Contents are returned with each line prefixed by its line number as \"<line>: <content>\".\n- Any line longer than 2000 characters is truncated.\n- Call this tool in parallel when reading multiple files.\n- Avoid tiny repeated slices (under 30 lines). Read a larger window instead.\n- Images and PDFs are returned as file attachments.\n- Binary files are refused; use specialized tools.`;\n\nexport const readToolDefinition: ToolDefinition = {\n name: READ_TOOL_NAME,\n description: READ_TOOL_DESCRIPTION,\n inputSchema: {\n type: \"object\",\n properties: {\n path: {\n type: \"string\",\n description:\n \"Absolute path (preferred) or path relative to the session cwd.\",\n },\n offset: {\n type: \"integer\",\n minimum: 1,\n description: \"1-indexed line number to start reading from.\",\n },\n limit: {\n type: \"integer\",\n minimum: 1,\n description: \"Maximum number of lines to read. Defaults to 2000.\",\n },\n },\n required: [\"path\"],\n additionalProperties: false,\n },\n};\n","import path from \"node:path\";\nimport type { ReadOperations } from \"@agent-sh/harness-core\";\nimport { FUZZY_SUGGESTION_LIMIT } from \"./constants.js\";\n\nexport async function suggestSiblings(\n ops: ReadOperations,\n missingPath: string,\n): Promise<readonly string[]> {\n const dir = path.dirname(missingPath);\n const base = path.basename(missingPath).toLowerCase();\n let entries: readonly string[];\n try {\n entries = await ops.readDirectory(dir);\n } catch {\n return [];\n }\n const scored: { p: string; score: number }[] = [];\n for (const entry of entries) {\n const lower = entry.toLowerCase();\n const score = similarity(base, lower);\n if (score > 0) scored.push({ p: path.join(dir, entry), score });\n }\n scored.sort((a, b) => b.score - a.score);\n return scored.slice(0, FUZZY_SUGGESTION_LIMIT).map((s) => s.p);\n}\n\nfunction similarity(a: string, b: string): number {\n if (a === b) return 1000;\n if (a.length === 0 || b.length === 0) return 0;\n if (a.includes(b) || b.includes(a)) return 500;\n const prefix = commonPrefix(a, b);\n if (prefix >= 3) return 200 + prefix;\n if (prefix >= 2 && Math.abs(a.length - b.length) <= 2) return 100 + prefix;\n const aExt = extOf(a);\n const bExt = extOf(b);\n if (aExt && aExt === bExt) return 10;\n return 0;\n}\n\nfunction commonPrefix(a: string, b: string): number {\n const n = Math.min(a.length, b.length);\n let i = 0;\n while (i < n && a[i] === b[i]) i++;\n return i;\n}\n\nfunction extOf(name: string): string {\n const dot = name.lastIndexOf(\".\");\n return dot > 0 ? name.slice(dot) : \"\";\n}\n","import { Buffer } from \"node:buffer\";\nimport { createHash } from \"node:crypto\";\nimport path from \"node:path\";\nimport {\n defaultNodeOperations,\n isInsideAnyRoot,\n matchesAnyPattern,\n toolError,\n withFileLock,\n type ReadOperations,\n type ToolError,\n} from \"@agent-sh/harness-core\";\nimport { isBinary, isImageMime, isPdfMime } from \"./binary.js\";\nimport {\n BINARY_SAMPLE_BYTES,\n DEFAULT_LIMIT,\n MAX_FILE_SIZE,\n} from \"./constants.js\";\nimport {\n formatAttachment,\n formatDirectory,\n formatText,\n} from \"./format.js\";\nimport { streamLines } from \"./lines.js\";\nimport { safeParseReadParams } from \"./schema.js\";\nimport { suggestSiblings } from \"./suggest.js\";\nimport type {\n AttachmentReadResult,\n DirReadResult,\n ErrorReadResult,\n ReadParams,\n ReadResult,\n ReadSessionConfig,\n TextReadResult,\n} from \"./types.js\";\n\nfunction err(error: ToolError): ErrorReadResult {\n return { kind: \"error\", error };\n}\n\nexport async function read(\n input: unknown,\n session: ReadSessionConfig,\n): Promise<ReadResult> {\n const parsed = safeParseReadParams(input);\n if (!parsed.ok) {\n const messages = parsed.issues.map((i) => i.message).join(\"; \");\n return err(toolError(\"INVALID_PARAM\", messages, { cause: parsed.issues }));\n }\n const params = parsed.value;\n\n const ops = session.ops ?? defaultNodeOperations();\n\n const resolvedPath = await resolvePath(ops, session.cwd, params.path);\n const fence = await fencePath(ops, session, resolvedPath);\n if (fence !== undefined) return err(fence);\n\n return withFileLock(resolvedPath, () =>\n executeRead(ops, session, resolvedPath, params),\n );\n}\n\nasync function resolvePath(\n ops: ReadOperations,\n cwd: string,\n input: string,\n): Promise<string> {\n const absolute = path.isAbsolute(input) ? input : path.resolve(cwd, input);\n try {\n return await ops.realpath(absolute);\n } catch {\n return absolute;\n }\n}\n\nasync function fencePath(\n ops: ReadOperations,\n session: ReadSessionConfig,\n resolvedPath: string,\n): Promise<ToolError | undefined> {\n const { permissions } = session;\n\n const isSensitive = matchesAnyPattern(\n resolvedPath,\n permissions.sensitivePatterns,\n );\n const insideWorkspace = isInsideAnyRoot(resolvedPath, permissions.roots);\n const needsAsk =\n isSensitive ||\n (!insideWorkspace && permissions.bypassWorkspaceGuard !== true);\n\n if (isSensitive && permissions.hook === undefined) {\n return toolError(\n \"SENSITIVE\",\n `Refusing to read sensitive path: ${resolvedPath}`,\n { meta: { path: resolvedPath } },\n );\n }\n\n if (\n !insideWorkspace &&\n permissions.bypassWorkspaceGuard !== true &&\n permissions.hook === undefined\n ) {\n if (process.env.E2E_DEBUG_PERMISSIONS) {\n // eslint-disable-next-line no-console\n console.error(\n `[read fencePath] OUTSIDE_WORKSPACE reject: resolvedPath=${JSON.stringify(resolvedPath)} roots=${JSON.stringify(permissions.roots)}`,\n );\n }\n return toolError(\n \"OUTSIDE_WORKSPACE\",\n `Path is outside all configured workspace roots: ${resolvedPath}`,\n { meta: { path: resolvedPath, roots: permissions.roots } },\n );\n }\n\n if (permissions.hook !== undefined) {\n const reason = isSensitive\n ? \"sensitive\"\n : !insideWorkspace\n ? \"outside_workspace\"\n : \"in_workspace\";\n const alwaysPatterns = needsAsk\n ? [path.dirname(resolvedPath) + \"/*\"]\n : [\"*\"];\n const decision = await permissions.hook({\n tool: \"read\",\n path: resolvedPath,\n action: \"read\",\n always_patterns: alwaysPatterns,\n metadata: { reason },\n });\n if (decision === \"deny\") {\n return toolError(\n \"PERMISSION_DENIED\",\n `Read denied by user: ${resolvedPath}`,\n { meta: { path: resolvedPath } },\n );\n }\n }\n\n return undefined;\n}\n\nasync function executeRead(\n ops: ReadOperations,\n session: ReadSessionConfig,\n resolvedPath: string,\n params: ReadParams,\n): Promise<ReadResult> {\n let stat;\n try {\n stat = await ops.stat(resolvedPath);\n } catch (e) {\n return err(\n toolError(\"IO_ERROR\", `stat failed: ${(e as Error).message}`, {\n cause: e,\n }),\n );\n }\n\n if (!stat) {\n const suggestions = await suggestSiblings(ops, resolvedPath);\n const msg =\n suggestions.length > 0\n ? `File not found: ${resolvedPath}\\n\\nDid you mean one of these?\\n${suggestions.join(\"\\n\")}`\n : `File not found: ${resolvedPath}`;\n return err(\n toolError(\"NOT_FOUND\", msg, { meta: { path: resolvedPath, suggestions } }),\n );\n }\n\n if (stat.type === \"directory\") {\n return readDirectory(ops, resolvedPath, params);\n }\n\n const maxSize = session.maxFileSize ?? MAX_FILE_SIZE;\n if (stat.size > maxSize) {\n return err(\n toolError(\n \"TOO_LARGE\",\n `File size ${stat.size} exceeds max ${maxSize}. Use a narrower offset/limit or grep first.`,\n { meta: { path: resolvedPath, size: stat.size, maxSize } },\n ),\n );\n }\n\n const half = session.modelContextTokens\n ? Math.floor(session.modelContextTokens / 2)\n : undefined;\n const tokensPerByte = session.tokensPerByte ?? 0.3;\n if (half !== undefined && stat.size * tokensPerByte > half) {\n return err(\n toolError(\n \"TOO_LARGE\",\n `File would consume more than half of the model context (~${Math.floor(stat.size * tokensPerByte)} tokens > ${half}). Use offset/limit or grep first.`,\n { meta: { path: resolvedPath, size: stat.size, half } },\n ),\n );\n }\n\n const mime = ops.mimeType(resolvedPath);\n if (isImageMime(mime) || isPdfMime(mime)) {\n return readAttachment(ops, resolvedPath, mime, stat.size);\n }\n\n const sample = await readSample(ops, resolvedPath, stat.size);\n if (isBinary(resolvedPath, sample)) {\n return err(\n toolError(\"BINARY\", `Cannot read binary file: ${resolvedPath}`, {\n meta: { path: resolvedPath },\n }),\n );\n }\n\n return readText(ops, session, resolvedPath, stat, params);\n}\n\nasync function readSample(\n ops: ReadOperations,\n p: string,\n size: number,\n): Promise<Uint8Array> {\n if (size === 0) return new Uint8Array();\n const bytes = await ops.readFile(p);\n return bytes.length > BINARY_SAMPLE_BYTES\n ? bytes.subarray(0, BINARY_SAMPLE_BYTES)\n : bytes;\n}\n\nasync function readDirectory(\n ops: ReadOperations,\n resolvedPath: string,\n params: ReadParams,\n): Promise<DirReadResult> {\n const entries = await ops.readDirectoryEntries(resolvedPath);\n const named = await Promise.all(\n entries.map(async (e) => {\n if (e.type === \"directory\") return e.name + \"/\";\n if (e.type !== \"symlink\") return e.name;\n const target = await ops\n .stat(path.join(resolvedPath, e.name))\n .catch(() => undefined);\n return target?.type === \"directory\" ? e.name + \"/\" : e.name;\n }),\n );\n named.sort((a, b) => a.localeCompare(b, undefined, { sensitivity: \"base\" }));\n\n const offset = params.offset ?? 1;\n const limit = params.limit ?? DEFAULT_LIMIT;\n const start = offset - 1;\n const sliced = named.slice(start, start + limit);\n const more = start + sliced.length < named.length;\n\n const output = formatDirectory({\n path: resolvedPath,\n entries: sliced,\n offset,\n totalEntries: named.length,\n more,\n });\n\n return {\n kind: \"directory\",\n output,\n meta: {\n path: resolvedPath,\n totalEntries: named.length,\n returnedEntries: sliced.length,\n offset,\n limit,\n more,\n },\n };\n}\n\nasync function readAttachment(\n ops: ReadOperations,\n resolvedPath: string,\n mime: string,\n size: number,\n): Promise<AttachmentReadResult> {\n const bytes = await ops.readFile(resolvedPath);\n const kind: \"Image\" | \"PDF\" = mime === \"application/pdf\" ? \"PDF\" : \"Image\";\n const dataUrl = `data:${mime};base64,${Buffer.from(bytes).toString(\"base64\")}`;\n return {\n kind: \"attachment\",\n output: formatAttachment(kind),\n attachments: [{ mime, dataUrl }],\n meta: { path: resolvedPath, mime, size_bytes: size },\n };\n}\n\nasync function readText(\n ops: ReadOperations,\n session: ReadSessionConfig,\n resolvedPath: string,\n stat: { size: number; mtime_ms: number },\n params: ReadParams,\n): Promise<ReadResult> {\n const offset = params.offset ?? 1;\n const limit = params.limit ?? session.defaultLimit ?? DEFAULT_LIMIT;\n\n if (session.cache) {\n const cached = session.cache.get({\n path: resolvedPath,\n mtime_ms: stat.mtime_ms,\n size_bytes: stat.size,\n offset,\n limit,\n });\n if (cached) {\n if (session.ledger) {\n session.ledger.record({\n path: resolvedPath,\n sha256: cached.meta.sha256,\n mtime_ms: stat.mtime_ms,\n size_bytes: stat.size,\n lines_returned: cached.meta.returnedLines,\n offset,\n limit,\n timestamp_ms: Date.now(),\n });\n }\n return cached;\n }\n }\n\n const lineStreamOpts: {\n offset: number;\n limit: number;\n maxBytes?: number;\n maxLineLength?: number;\n signal?: AbortSignal;\n } = { offset, limit };\n if (session.maxBytes !== undefined) lineStreamOpts.maxBytes = session.maxBytes;\n if (session.maxLineLength !== undefined)\n lineStreamOpts.maxLineLength = session.maxLineLength;\n if (session.signal !== undefined) lineStreamOpts.signal = session.signal;\n\n const result = await streamLines(ops, resolvedPath, lineStreamOpts);\n\n if (result.totalLines > 0 && offset > result.totalLines) {\n return err(\n toolError(\n \"INVALID_PARAM\",\n `Offset ${offset} is out of range for this file (${result.totalLines} lines)`,\n { meta: { path: resolvedPath, totalLines: result.totalLines } },\n ),\n );\n }\n\n const bytes = await ops.readFile(resolvedPath);\n const sha256 = createHash(\"sha256\").update(bytes).digest(\"hex\");\n\n const output = formatText({\n path: resolvedPath,\n offset,\n lines: result.lines,\n totalLines: result.totalLines,\n more: result.more,\n byteCap: result.byteCap,\n });\n\n const textResult: TextReadResult = {\n kind: \"text\",\n output,\n meta: {\n path: resolvedPath,\n totalLines: result.totalLines,\n returnedLines: result.lines.length,\n offset,\n limit,\n byteCap: result.byteCap,\n more: result.more,\n sha256,\n mtime_ms: stat.mtime_ms,\n size_bytes: stat.size,\n },\n };\n\n if (session.cache) {\n session.cache.set(\n {\n path: resolvedPath,\n mtime_ms: stat.mtime_ms,\n size_bytes: stat.size,\n offset,\n limit,\n },\n textResult,\n );\n }\n\n if (session.ledger) {\n session.ledger.record({\n path: resolvedPath,\n sha256,\n mtime_ms: stat.mtime_ms,\n size_bytes: stat.size,\n lines_returned: result.lines.length,\n offset,\n limit,\n timestamp_ms: Date.now(),\n });\n }\n\n return textResult;\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ToolError, PermissionPolicy, ReadOperations, Cache, Ledger, ToolDefinition } from '@agent-sh/harness-core';
|
|
2
|
+
import * as v from 'valibot';
|
|
3
|
+
|
|
4
|
+
interface ReadParams {
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly offset?: number;
|
|
7
|
+
readonly limit?: number;
|
|
8
|
+
}
|
|
9
|
+
interface ReadSessionConfig {
|
|
10
|
+
readonly cwd: string;
|
|
11
|
+
readonly permissions: PermissionPolicy;
|
|
12
|
+
readonly ops?: ReadOperations;
|
|
13
|
+
readonly cache?: Cache<TextReadResult>;
|
|
14
|
+
readonly ledger?: Ledger;
|
|
15
|
+
readonly modelContextTokens?: number;
|
|
16
|
+
readonly tokensPerByte?: number;
|
|
17
|
+
readonly maxFileSize?: number;
|
|
18
|
+
readonly maxBytes?: number;
|
|
19
|
+
readonly defaultLimit?: number;
|
|
20
|
+
readonly maxLineLength?: number;
|
|
21
|
+
readonly signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
interface TextMeta {
|
|
24
|
+
readonly path: string;
|
|
25
|
+
readonly totalLines: number;
|
|
26
|
+
readonly returnedLines: number;
|
|
27
|
+
readonly offset: number;
|
|
28
|
+
readonly limit: number;
|
|
29
|
+
readonly byteCap: boolean;
|
|
30
|
+
readonly more: boolean;
|
|
31
|
+
readonly sha256: string;
|
|
32
|
+
readonly mtime_ms: number;
|
|
33
|
+
readonly size_bytes: number;
|
|
34
|
+
}
|
|
35
|
+
interface DirMeta {
|
|
36
|
+
readonly path: string;
|
|
37
|
+
readonly totalEntries: number;
|
|
38
|
+
readonly returnedEntries: number;
|
|
39
|
+
readonly offset: number;
|
|
40
|
+
readonly limit: number;
|
|
41
|
+
readonly more: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface AttachmentMeta {
|
|
44
|
+
readonly path: string;
|
|
45
|
+
readonly mime: string;
|
|
46
|
+
readonly size_bytes: number;
|
|
47
|
+
}
|
|
48
|
+
interface Attachment {
|
|
49
|
+
readonly mime: string;
|
|
50
|
+
readonly dataUrl: string;
|
|
51
|
+
}
|
|
52
|
+
type TextReadResult = {
|
|
53
|
+
readonly kind: "text";
|
|
54
|
+
readonly output: string;
|
|
55
|
+
readonly meta: TextMeta;
|
|
56
|
+
};
|
|
57
|
+
type DirReadResult = {
|
|
58
|
+
readonly kind: "directory";
|
|
59
|
+
readonly output: string;
|
|
60
|
+
readonly meta: DirMeta;
|
|
61
|
+
};
|
|
62
|
+
type AttachmentReadResult = {
|
|
63
|
+
readonly kind: "attachment";
|
|
64
|
+
readonly output: string;
|
|
65
|
+
readonly attachments: readonly Attachment[];
|
|
66
|
+
readonly meta: AttachmentMeta;
|
|
67
|
+
};
|
|
68
|
+
type ErrorReadResult = {
|
|
69
|
+
readonly kind: "error";
|
|
70
|
+
readonly error: ToolError;
|
|
71
|
+
};
|
|
72
|
+
type ReadResult = TextReadResult | DirReadResult | AttachmentReadResult | ErrorReadResult;
|
|
73
|
+
|
|
74
|
+
declare function read(input: unknown, session: ReadSessionConfig): Promise<ReadResult>;
|
|
75
|
+
|
|
76
|
+
declare const ReadParamsSchema: v.ObjectSchema<{
|
|
77
|
+
readonly path: v.SchemaWithPipe<[v.StringSchema<undefined>, v.MinLengthAction<string, 1, "path must not be empty">]>;
|
|
78
|
+
readonly offset: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, "offset must be >= 1">]>, never>;
|
|
79
|
+
readonly limit: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, "limit must be >= 1">]>, never>;
|
|
80
|
+
}, undefined>;
|
|
81
|
+
type ParsedReadParams = v.InferOutput<typeof ReadParamsSchema>;
|
|
82
|
+
declare function parseReadParams(input: unknown): ParsedReadParams;
|
|
83
|
+
declare function safeParseReadParams(input: unknown): {
|
|
84
|
+
ok: true;
|
|
85
|
+
value: ReadParams;
|
|
86
|
+
} | {
|
|
87
|
+
ok: false;
|
|
88
|
+
issues: v.BaseIssue<unknown>[];
|
|
89
|
+
};
|
|
90
|
+
declare const READ_TOOL_NAME = "read";
|
|
91
|
+
declare const READ_TOOL_DESCRIPTION = "Read a file or directory from the local filesystem.\n\nUsage:\n- The path parameter should be an absolute path. If relative, it resolves against the session working directory.\n- By default, returns up to 2000 lines from the start of the file.\n- The offset parameter is the 1-indexed line number to start from.\n- For later sections, call this tool again with a larger offset.\n- Use the grep tool for content search in large files; glob to locate files by pattern.\n- Contents are returned with each line prefixed by its line number as \"<line>: <content>\".\n- Any line longer than 2000 characters is truncated.\n- Call this tool in parallel when reading multiple files.\n- Avoid tiny repeated slices (under 30 lines). Read a larger window instead.\n- Images and PDFs are returned as file attachments.\n- Binary files are refused; use specialized tools.";
|
|
92
|
+
declare const readToolDefinition: ToolDefinition;
|
|
93
|
+
|
|
94
|
+
declare function isBinaryByExtension(filepath: string): boolean;
|
|
95
|
+
declare function isBinaryByContent(sample: Uint8Array): boolean;
|
|
96
|
+
declare function isBinary(filepath: string, sample: Uint8Array): boolean;
|
|
97
|
+
declare function isImageMime(mime: string): boolean;
|
|
98
|
+
declare function isPdfMime(mime: string): boolean;
|
|
99
|
+
|
|
100
|
+
interface StreamLinesOptions {
|
|
101
|
+
readonly offset: number;
|
|
102
|
+
readonly limit: number;
|
|
103
|
+
readonly maxBytes?: number;
|
|
104
|
+
readonly maxLineLength?: number;
|
|
105
|
+
readonly signal?: AbortSignal;
|
|
106
|
+
}
|
|
107
|
+
interface StreamLinesResult {
|
|
108
|
+
readonly lines: readonly string[];
|
|
109
|
+
readonly totalLines: number;
|
|
110
|
+
readonly offset: number;
|
|
111
|
+
readonly more: boolean;
|
|
112
|
+
readonly byteCap: boolean;
|
|
113
|
+
}
|
|
114
|
+
declare function streamLines(ops: ReadOperations, path: string, opts: StreamLinesOptions): Promise<StreamLinesResult>;
|
|
115
|
+
|
|
116
|
+
declare function suggestSiblings(ops: ReadOperations, missingPath: string): Promise<readonly string[]>;
|
|
117
|
+
|
|
118
|
+
declare function formatText(params: {
|
|
119
|
+
path: string;
|
|
120
|
+
offset: number;
|
|
121
|
+
lines: readonly string[];
|
|
122
|
+
totalLines: number;
|
|
123
|
+
more: boolean;
|
|
124
|
+
byteCap: boolean;
|
|
125
|
+
}): string;
|
|
126
|
+
declare function formatDirectory(params: {
|
|
127
|
+
path: string;
|
|
128
|
+
entries: readonly string[];
|
|
129
|
+
offset: number;
|
|
130
|
+
totalEntries: number;
|
|
131
|
+
more: boolean;
|
|
132
|
+
}): string;
|
|
133
|
+
declare function formatAttachment(kind: "Image" | "PDF"): string;
|
|
134
|
+
|
|
135
|
+
declare const DEFAULT_LIMIT = 2000;
|
|
136
|
+
declare const MAX_LINE_LENGTH = 2000;
|
|
137
|
+
declare const MAX_BYTES: number;
|
|
138
|
+
declare const MAX_FILE_SIZE: number;
|
|
139
|
+
declare const BINARY_EXTENSIONS: ReadonlySet<string>;
|
|
140
|
+
|
|
141
|
+
export { type Attachment, type AttachmentMeta, type AttachmentReadResult, BINARY_EXTENSIONS, DEFAULT_LIMIT, type DirMeta, type DirReadResult, type ErrorReadResult, MAX_BYTES, MAX_FILE_SIZE, MAX_LINE_LENGTH, READ_TOOL_DESCRIPTION, READ_TOOL_NAME, type ReadParams, ReadParamsSchema, type ReadResult, type ReadSessionConfig, type TextMeta, type TextReadResult, formatAttachment, formatDirectory, formatText, isBinary, isBinaryByContent, isBinaryByExtension, isImageMime, isPdfMime, parseReadParams, read, readToolDefinition, safeParseReadParams, streamLines, suggestSiblings };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ToolError, PermissionPolicy, ReadOperations, Cache, Ledger, ToolDefinition } from '@agent-sh/harness-core';
|
|
2
|
+
import * as v from 'valibot';
|
|
3
|
+
|
|
4
|
+
interface ReadParams {
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly offset?: number;
|
|
7
|
+
readonly limit?: number;
|
|
8
|
+
}
|
|
9
|
+
interface ReadSessionConfig {
|
|
10
|
+
readonly cwd: string;
|
|
11
|
+
readonly permissions: PermissionPolicy;
|
|
12
|
+
readonly ops?: ReadOperations;
|
|
13
|
+
readonly cache?: Cache<TextReadResult>;
|
|
14
|
+
readonly ledger?: Ledger;
|
|
15
|
+
readonly modelContextTokens?: number;
|
|
16
|
+
readonly tokensPerByte?: number;
|
|
17
|
+
readonly maxFileSize?: number;
|
|
18
|
+
readonly maxBytes?: number;
|
|
19
|
+
readonly defaultLimit?: number;
|
|
20
|
+
readonly maxLineLength?: number;
|
|
21
|
+
readonly signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
interface TextMeta {
|
|
24
|
+
readonly path: string;
|
|
25
|
+
readonly totalLines: number;
|
|
26
|
+
readonly returnedLines: number;
|
|
27
|
+
readonly offset: number;
|
|
28
|
+
readonly limit: number;
|
|
29
|
+
readonly byteCap: boolean;
|
|
30
|
+
readonly more: boolean;
|
|
31
|
+
readonly sha256: string;
|
|
32
|
+
readonly mtime_ms: number;
|
|
33
|
+
readonly size_bytes: number;
|
|
34
|
+
}
|
|
35
|
+
interface DirMeta {
|
|
36
|
+
readonly path: string;
|
|
37
|
+
readonly totalEntries: number;
|
|
38
|
+
readonly returnedEntries: number;
|
|
39
|
+
readonly offset: number;
|
|
40
|
+
readonly limit: number;
|
|
41
|
+
readonly more: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface AttachmentMeta {
|
|
44
|
+
readonly path: string;
|
|
45
|
+
readonly mime: string;
|
|
46
|
+
readonly size_bytes: number;
|
|
47
|
+
}
|
|
48
|
+
interface Attachment {
|
|
49
|
+
readonly mime: string;
|
|
50
|
+
readonly dataUrl: string;
|
|
51
|
+
}
|
|
52
|
+
type TextReadResult = {
|
|
53
|
+
readonly kind: "text";
|
|
54
|
+
readonly output: string;
|
|
55
|
+
readonly meta: TextMeta;
|
|
56
|
+
};
|
|
57
|
+
type DirReadResult = {
|
|
58
|
+
readonly kind: "directory";
|
|
59
|
+
readonly output: string;
|
|
60
|
+
readonly meta: DirMeta;
|
|
61
|
+
};
|
|
62
|
+
type AttachmentReadResult = {
|
|
63
|
+
readonly kind: "attachment";
|
|
64
|
+
readonly output: string;
|
|
65
|
+
readonly attachments: readonly Attachment[];
|
|
66
|
+
readonly meta: AttachmentMeta;
|
|
67
|
+
};
|
|
68
|
+
type ErrorReadResult = {
|
|
69
|
+
readonly kind: "error";
|
|
70
|
+
readonly error: ToolError;
|
|
71
|
+
};
|
|
72
|
+
type ReadResult = TextReadResult | DirReadResult | AttachmentReadResult | ErrorReadResult;
|
|
73
|
+
|
|
74
|
+
declare function read(input: unknown, session: ReadSessionConfig): Promise<ReadResult>;
|
|
75
|
+
|
|
76
|
+
declare const ReadParamsSchema: v.ObjectSchema<{
|
|
77
|
+
readonly path: v.SchemaWithPipe<[v.StringSchema<undefined>, v.MinLengthAction<string, 1, "path must not be empty">]>;
|
|
78
|
+
readonly offset: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, "offset must be >= 1">]>, never>;
|
|
79
|
+
readonly limit: v.OptionalSchema<v.SchemaWithPipe<[v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, "limit must be >= 1">]>, never>;
|
|
80
|
+
}, undefined>;
|
|
81
|
+
type ParsedReadParams = v.InferOutput<typeof ReadParamsSchema>;
|
|
82
|
+
declare function parseReadParams(input: unknown): ParsedReadParams;
|
|
83
|
+
declare function safeParseReadParams(input: unknown): {
|
|
84
|
+
ok: true;
|
|
85
|
+
value: ReadParams;
|
|
86
|
+
} | {
|
|
87
|
+
ok: false;
|
|
88
|
+
issues: v.BaseIssue<unknown>[];
|
|
89
|
+
};
|
|
90
|
+
declare const READ_TOOL_NAME = "read";
|
|
91
|
+
declare const READ_TOOL_DESCRIPTION = "Read a file or directory from the local filesystem.\n\nUsage:\n- The path parameter should be an absolute path. If relative, it resolves against the session working directory.\n- By default, returns up to 2000 lines from the start of the file.\n- The offset parameter is the 1-indexed line number to start from.\n- For later sections, call this tool again with a larger offset.\n- Use the grep tool for content search in large files; glob to locate files by pattern.\n- Contents are returned with each line prefixed by its line number as \"<line>: <content>\".\n- Any line longer than 2000 characters is truncated.\n- Call this tool in parallel when reading multiple files.\n- Avoid tiny repeated slices (under 30 lines). Read a larger window instead.\n- Images and PDFs are returned as file attachments.\n- Binary files are refused; use specialized tools.";
|
|
92
|
+
declare const readToolDefinition: ToolDefinition;
|
|
93
|
+
|
|
94
|
+
declare function isBinaryByExtension(filepath: string): boolean;
|
|
95
|
+
declare function isBinaryByContent(sample: Uint8Array): boolean;
|
|
96
|
+
declare function isBinary(filepath: string, sample: Uint8Array): boolean;
|
|
97
|
+
declare function isImageMime(mime: string): boolean;
|
|
98
|
+
declare function isPdfMime(mime: string): boolean;
|
|
99
|
+
|
|
100
|
+
interface StreamLinesOptions {
|
|
101
|
+
readonly offset: number;
|
|
102
|
+
readonly limit: number;
|
|
103
|
+
readonly maxBytes?: number;
|
|
104
|
+
readonly maxLineLength?: number;
|
|
105
|
+
readonly signal?: AbortSignal;
|
|
106
|
+
}
|
|
107
|
+
interface StreamLinesResult {
|
|
108
|
+
readonly lines: readonly string[];
|
|
109
|
+
readonly totalLines: number;
|
|
110
|
+
readonly offset: number;
|
|
111
|
+
readonly more: boolean;
|
|
112
|
+
readonly byteCap: boolean;
|
|
113
|
+
}
|
|
114
|
+
declare function streamLines(ops: ReadOperations, path: string, opts: StreamLinesOptions): Promise<StreamLinesResult>;
|
|
115
|
+
|
|
116
|
+
declare function suggestSiblings(ops: ReadOperations, missingPath: string): Promise<readonly string[]>;
|
|
117
|
+
|
|
118
|
+
declare function formatText(params: {
|
|
119
|
+
path: string;
|
|
120
|
+
offset: number;
|
|
121
|
+
lines: readonly string[];
|
|
122
|
+
totalLines: number;
|
|
123
|
+
more: boolean;
|
|
124
|
+
byteCap: boolean;
|
|
125
|
+
}): string;
|
|
126
|
+
declare function formatDirectory(params: {
|
|
127
|
+
path: string;
|
|
128
|
+
entries: readonly string[];
|
|
129
|
+
offset: number;
|
|
130
|
+
totalEntries: number;
|
|
131
|
+
more: boolean;
|
|
132
|
+
}): string;
|
|
133
|
+
declare function formatAttachment(kind: "Image" | "PDF"): string;
|
|
134
|
+
|
|
135
|
+
declare const DEFAULT_LIMIT = 2000;
|
|
136
|
+
declare const MAX_LINE_LENGTH = 2000;
|
|
137
|
+
declare const MAX_BYTES: number;
|
|
138
|
+
declare const MAX_FILE_SIZE: number;
|
|
139
|
+
declare const BINARY_EXTENSIONS: ReadonlySet<string>;
|
|
140
|
+
|
|
141
|
+
export { type Attachment, type AttachmentMeta, type AttachmentReadResult, BINARY_EXTENSIONS, DEFAULT_LIMIT, type DirMeta, type DirReadResult, type ErrorReadResult, MAX_BYTES, MAX_FILE_SIZE, MAX_LINE_LENGTH, READ_TOOL_DESCRIPTION, READ_TOOL_NAME, type ReadParams, ReadParamsSchema, type ReadResult, type ReadSessionConfig, type TextMeta, type TextReadResult, formatAttachment, formatDirectory, formatText, isBinary, isBinaryByContent, isBinaryByExtension, isImageMime, isPdfMime, parseReadParams, read, readToolDefinition, safeParseReadParams, streamLines, suggestSiblings };
|