refactor: migrate remaining tool files from Bun.file() to Filesystem/stat modules (#14121)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import z from "zod"
|
import z from "zod"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
|
import { Filesystem } from "../util/filesystem"
|
||||||
import DESCRIPTION from "./glob.txt"
|
import DESCRIPTION from "./glob.txt"
|
||||||
import { Ripgrep } from "../file/ripgrep"
|
import { Ripgrep } from "../file/ripgrep"
|
||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
@@ -45,10 +46,7 @@ export const GlobTool = Tool.define("glob", {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
const full = path.resolve(search, file)
|
const full = path.resolve(search, file)
|
||||||
const stats = await Bun.file(full)
|
const stats = Filesystem.stat(full)?.mtime.getTime() ?? 0
|
||||||
.stat()
|
|
||||||
.then((x) => x.mtime.getTime())
|
|
||||||
.catch(() => 0)
|
|
||||||
files.push({
|
files.push({
|
||||||
path: full,
|
path: full,
|
||||||
mtime: stats,
|
mtime: stats,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import z from "zod"
|
import z from "zod"
|
||||||
import { Tool } from "./tool"
|
import { Tool } from "./tool"
|
||||||
|
import { Filesystem } from "../util/filesystem"
|
||||||
import { Ripgrep } from "../file/ripgrep"
|
import { Ripgrep } from "../file/ripgrep"
|
||||||
|
|
||||||
import DESCRIPTION from "./grep.txt"
|
import DESCRIPTION from "./grep.txt"
|
||||||
@@ -83,8 +84,7 @@ export const GrepTool = Tool.define("grep", {
|
|||||||
const lineNum = parseInt(lineNumStr, 10)
|
const lineNum = parseInt(lineNumStr, 10)
|
||||||
const lineText = lineTextParts.join("|")
|
const lineText = lineTextParts.join("|")
|
||||||
|
|
||||||
const file = Bun.file(filePath)
|
const stats = Filesystem.stat(filePath)
|
||||||
const stats = await file.stat().catch(() => null)
|
|
||||||
if (!stats) continue
|
if (!stats) continue
|
||||||
|
|
||||||
matches.push({
|
matches.push({
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import DESCRIPTION from "./lsp.txt"
|
|||||||
import { Instance } from "../project/instance"
|
import { Instance } from "../project/instance"
|
||||||
import { pathToFileURL } from "url"
|
import { pathToFileURL } from "url"
|
||||||
import { assertExternalDirectory } from "./external-directory"
|
import { assertExternalDirectory } from "./external-directory"
|
||||||
|
import { Filesystem } from "../util/filesystem"
|
||||||
|
|
||||||
const operations = [
|
const operations = [
|
||||||
"goToDefinition",
|
"goToDefinition",
|
||||||
@@ -47,7 +48,7 @@ export const LspTool = Tool.define("lsp", {
|
|||||||
const relPath = path.relative(Instance.worktree, file)
|
const relPath = path.relative(Instance.worktree, file)
|
||||||
const title = `${args.operation} ${relPath}:${args.line}:${args.character}`
|
const title = `${args.operation} ${relPath}:${args.line}:${args.character}`
|
||||||
|
|
||||||
const exists = await Bun.file(file).exists()
|
const exists = await Filesystem.exists(file)
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
throw new Error(`File not found: ${file}`)
|
throw new Error(`File not found: ${file}`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Identifier } from "../id/id"
|
|||||||
import { PermissionNext } from "../permission/next"
|
import { PermissionNext } from "../permission/next"
|
||||||
import type { Agent } from "../agent/agent"
|
import type { Agent } from "../agent/agent"
|
||||||
import { Scheduler } from "../scheduler"
|
import { Scheduler } from "../scheduler"
|
||||||
|
import { Filesystem } from "../util/filesystem"
|
||||||
|
|
||||||
export namespace Truncate {
|
export namespace Truncate {
|
||||||
export const MAX_LINES = 2000
|
export const MAX_LINES = 2000
|
||||||
@@ -91,7 +92,7 @@ export namespace Truncate {
|
|||||||
|
|
||||||
const id = Identifier.ascending("tool")
|
const id = Identifier.ascending("tool")
|
||||||
const filepath = path.join(DIR, id)
|
const filepath = path.join(DIR, id)
|
||||||
await Bun.write(Bun.file(filepath), text)
|
await Filesystem.write(filepath, text)
|
||||||
|
|
||||||
const hint = hasTaskTool(agent)
|
const hint = hasTaskTool(agent)
|
||||||
? `The tool call succeeded but the output was truncated. Full output saved to: ${filepath}\nUse the Task tool to have explore agent process this file with Grep and Read (with offset/limit). Do NOT read the full file yourself - delegate to save context.`
|
? `The tool call succeeded but the output was truncated. Full output saved to: ${filepath}\nUse the Task tool to have explore agent process this file with Grep and Read (with offset/limit). Do NOT read the full file yourself - delegate to save context.`
|
||||||
|
|||||||
Reference in New Issue
Block a user