mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-20 19:06:22 +00:00
fix(core): Remove dead code and documentation related to the obsolete list tool. (#22672)
This commit is contained in:
@@ -1566,7 +1566,6 @@ export namespace ACP {
|
||||
case "context7_get_library_docs":
|
||||
return "search"
|
||||
|
||||
case "list":
|
||||
case "read":
|
||||
return "read"
|
||||
|
||||
@@ -1587,8 +1586,6 @@ export namespace ACP {
|
||||
return input["path"] ? [{ path: input["path"] }] : []
|
||||
case "bash":
|
||||
return []
|
||||
case "list":
|
||||
return input["path"] ? [{ path: input["path"] }] : []
|
||||
default:
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import type { Argv } from "yargs"
|
||||
|
||||
type AgentMode = "all" | "primary" | "subagent"
|
||||
|
||||
const AVAILABLE_TOOLS = ["bash", "read", "write", "edit", "list", "glob", "grep", "webfetch", "task", "todowrite"]
|
||||
const AVAILABLE_TOOLS = ["bash", "read", "write", "edit", "glob", "grep", "webfetch", "task", "todowrite"]
|
||||
|
||||
const AgentCreateCommand = cmd({
|
||||
command: "create",
|
||||
|
||||
@@ -15,7 +15,6 @@ import { Permission } from "../../permission"
|
||||
import { Tool } from "../../tool/tool"
|
||||
import { GlobTool } from "../../tool/glob"
|
||||
import { GrepTool } from "../../tool/grep"
|
||||
import { ListTool } from "../../tool/ls"
|
||||
import { ReadTool } from "../../tool/read"
|
||||
import { WebFetchTool } from "../../tool/webfetch"
|
||||
import { EditTool } from "../../tool/edit"
|
||||
@@ -103,14 +102,6 @@ function grep(info: ToolProps<typeof GrepTool>) {
|
||||
})
|
||||
}
|
||||
|
||||
function list(info: ToolProps<typeof ListTool>) {
|
||||
const dir = info.input.path ? normalizePath(info.input.path) : ""
|
||||
inline({
|
||||
icon: "→",
|
||||
title: dir ? `List ${dir}` : "List",
|
||||
})
|
||||
}
|
||||
|
||||
function read(info: ToolProps<typeof ReadTool>) {
|
||||
const file = normalizePath(info.input.filePath)
|
||||
const pairs = Object.entries(info.input).filter(([key, value]) => {
|
||||
@@ -420,7 +411,6 @@ export const RunCommand = cmd({
|
||||
if (part.tool === "bash") return bash(props<typeof BashTool>(part))
|
||||
if (part.tool === "glob") return glob(props<typeof GlobTool>(part))
|
||||
if (part.tool === "grep") return grep(props<typeof GrepTool>(part))
|
||||
if (part.tool === "list") return list(props<typeof ListTool>(part))
|
||||
if (part.tool === "read") return read(props<typeof ReadTool>(part))
|
||||
if (part.tool === "write") return write(props<typeof WriteTool>(part))
|
||||
if (part.tool === "webfetch") return webfetch(props<typeof WebFetchTool>(part))
|
||||
|
||||
@@ -41,7 +41,6 @@ import { BashTool } from "@/tool/bash"
|
||||
import type { GlobTool } from "@/tool/glob"
|
||||
import { TodoWriteTool } from "@/tool/todo"
|
||||
import type { GrepTool } from "@/tool/grep"
|
||||
import type { ListTool } from "@/tool/ls"
|
||||
import type { EditTool } from "@/tool/edit"
|
||||
import type { ApplyPatchTool } from "@/tool/apply_patch"
|
||||
import type { WebFetchTool } from "@/tool/webfetch"
|
||||
@@ -1555,9 +1554,6 @@ function ToolPart(props: { last: boolean; part: ToolPart; message: AssistantMess
|
||||
<Match when={props.part.tool === "grep"}>
|
||||
<Grep {...toolprops} />
|
||||
</Match>
|
||||
<Match when={props.part.tool === "list"}>
|
||||
<List {...toolprops} />
|
||||
</Match>
|
||||
<Match when={props.part.tool === "webfetch"}>
|
||||
<WebFetch {...toolprops} />
|
||||
</Match>
|
||||
@@ -1936,20 +1932,6 @@ function Grep(props: ToolProps<typeof GrepTool>) {
|
||||
)
|
||||
}
|
||||
|
||||
function List(props: ToolProps<typeof ListTool>) {
|
||||
const dir = createMemo(() => {
|
||||
if (props.input.path) {
|
||||
return normalizePath(props.input.path)
|
||||
}
|
||||
return ""
|
||||
})
|
||||
return (
|
||||
<InlineTool icon="→" pending="Listing directory..." complete={props.input.path !== undefined} part={props.part}>
|
||||
List {dir()}
|
||||
</InlineTool>
|
||||
)
|
||||
}
|
||||
|
||||
function WebFetch(props: ToolProps<typeof WebFetchTool>) {
|
||||
return (
|
||||
<InlineTool icon="%" pending="Fetching from the web..." complete={(props.input as any).url} part={props.part}>
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
import * as path from "path"
|
||||
import z from "zod"
|
||||
import { Effect } from "effect"
|
||||
import * as Stream from "effect/Stream"
|
||||
import { InstanceState } from "@/effect/instance-state"
|
||||
import { Ripgrep } from "../file/ripgrep"
|
||||
import { assertExternalDirectoryEffect } from "./external-directory"
|
||||
import DESCRIPTION from "./ls.txt"
|
||||
import { Tool } from "./tool"
|
||||
|
||||
export const IGNORE_PATTERNS = [
|
||||
"node_modules/",
|
||||
"__pycache__/",
|
||||
".git/",
|
||||
"dist/",
|
||||
"build/",
|
||||
"target/",
|
||||
"vendor/",
|
||||
"bin/",
|
||||
"obj/",
|
||||
".idea/",
|
||||
".vscode/",
|
||||
".zig-cache/",
|
||||
"zig-out",
|
||||
".coverage",
|
||||
"coverage/",
|
||||
"vendor/",
|
||||
"tmp/",
|
||||
"temp/",
|
||||
".cache/",
|
||||
"cache/",
|
||||
"logs/",
|
||||
".venv/",
|
||||
"venv/",
|
||||
"env/",
|
||||
]
|
||||
|
||||
const LIMIT = 100
|
||||
|
||||
export const ListTool = Tool.define(
|
||||
"list",
|
||||
Effect.gen(function* () {
|
||||
const rg = yield* Ripgrep.Service
|
||||
|
||||
return {
|
||||
description: DESCRIPTION,
|
||||
parameters: z.object({
|
||||
path: z
|
||||
.string()
|
||||
.describe("The absolute path to the directory to list (must be absolute, not relative)")
|
||||
.optional(),
|
||||
ignore: z.array(z.string()).describe("List of glob patterns to ignore").optional(),
|
||||
}),
|
||||
execute: (params: { path?: string; ignore?: string[] }, ctx: Tool.Context) =>
|
||||
Effect.gen(function* () {
|
||||
const ins = yield* InstanceState.context
|
||||
const search = path.resolve(ins.directory, params.path || ".")
|
||||
yield* assertExternalDirectoryEffect(ctx, search, { kind: "directory" })
|
||||
|
||||
yield* ctx.ask({
|
||||
permission: "list",
|
||||
patterns: [search],
|
||||
always: ["*"],
|
||||
metadata: {
|
||||
path: search,
|
||||
},
|
||||
})
|
||||
|
||||
const glob = IGNORE_PATTERNS.map((item) => `!${item}*`).concat(params.ignore?.map((item) => `!${item}`) || [])
|
||||
const files = yield* rg.files({ cwd: search, glob, signal: ctx.abort }).pipe(
|
||||
Stream.take(LIMIT + 1),
|
||||
Stream.runCollect,
|
||||
Effect.map((chunk) => [...chunk]),
|
||||
)
|
||||
|
||||
const truncated = files.length > LIMIT
|
||||
if (truncated) files.length = LIMIT
|
||||
|
||||
const dirs = new Set<string>()
|
||||
const map = new Map<string, string[]>()
|
||||
for (const file of files) {
|
||||
const dir = path.dirname(file)
|
||||
const parts = dir === "." ? [] : dir.split("/")
|
||||
for (let i = 0; i <= parts.length; i++) {
|
||||
dirs.add(i === 0 ? "." : parts.slice(0, i).join("/"))
|
||||
}
|
||||
if (!map.has(dir)) map.set(dir, [])
|
||||
map.get(dir)!.push(path.basename(file))
|
||||
}
|
||||
|
||||
function render(dir: string, depth: number): string {
|
||||
const indent = " ".repeat(depth)
|
||||
let output = ""
|
||||
if (depth > 0) output += `${indent}${path.basename(dir)}/\n`
|
||||
|
||||
const child = " ".repeat(depth + 1)
|
||||
const dirs2 = Array.from(dirs)
|
||||
.filter((item) => path.dirname(item) === dir && item !== dir)
|
||||
.sort()
|
||||
for (const item of dirs2) {
|
||||
output += render(item, depth + 1)
|
||||
}
|
||||
|
||||
const files = map.get(dir) || []
|
||||
for (const file of files.sort()) {
|
||||
output += `${child}${file}\n`
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
return {
|
||||
title: path.relative(ins.worktree, search),
|
||||
metadata: {
|
||||
count: files.length,
|
||||
truncated,
|
||||
},
|
||||
output: `${search}/\n` + render(".", 0),
|
||||
}
|
||||
}).pipe(Effect.orDie),
|
||||
}
|
||||
}),
|
||||
)
|
||||
@@ -1 +0,0 @@
|
||||
Lists files and directories in a given path. The path parameter must be absolute; omit it to use the current workspace directory. You can optionally provide an array of glob patterns to ignore with the ignore parameter. You should generally prefer the Glob and Grep tools, if you know which directories to search.
|
||||
Reference in New Issue
Block a user