refactor(core): replace bash tool with shell tool

This commit is contained in:
Dax Raad 2026-06-29 00:43:04 -04:00
commit 5ae93092aa
37 changed files with 2260 additions and 901 deletions

View file

@ -15,6 +15,7 @@ import type { Definition } from "@opencode-ai/schema/event"
import { AgentGroup } from "./groups/agent"
import { HealthGroup } from "./groups/health"
import { PtyGroup } from "./groups/pty"
import { ShellGroup } from "./groups/shell"
import { makeQuestionGroup } from "./groups/question"
import { ReferenceGroup } from "./groups/reference"
import { Authorization } from "./middleware/authorization"
@ -52,6 +53,7 @@ const makeApiFromGroup = <
.add(SkillGroup.middleware(locationMiddleware))
.add(eventGroup)
.add(PtyGroup.middleware(locationMiddleware))
.add(ShellGroup.middleware(locationMiddleware))
.add(makeQuestionGroup(locationMiddleware, sessionLocationMiddleware))
.add(ReferenceGroup.middleware(locationMiddleware))
.add(ProjectCopyGroup.middleware(locationMiddleware))

View file

@ -118,3 +118,12 @@ export class PtyNotFoundError extends Schema.TaggedErrorClass<PtyNotFoundError>(
},
{ httpApiStatus: 404 },
) {}
export class ShellNotFoundError extends Schema.TaggedErrorClass<ShellNotFoundError>()(
"ShellNotFoundError",
{
id: Schema.String,
message: Schema.String,
},
{ httpApiStatus: 404 },
) {}

View file

@ -0,0 +1,89 @@
import { Shell } from "@opencode-ai/schema/shell"
import { Location } from "@opencode-ai/schema/location"
import { Schema } from "effect"
import { HttpApiEndpoint, HttpApiGroup, HttpApiSchema, OpenApi } from "effect/unstable/httpapi"
import { ShellNotFoundError } from "../errors"
import { LocationQuery, locationQueryOpenApi } from "./location"
export const ShellGroup = HttpApiGroup.make("server.shell")
.add(
HttpApiEndpoint.get("shell.list", "/api/shell", {
query: LocationQuery,
success: Location.response(Schema.Array(Shell.Info)),
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.shell.list",
summary: "List running shell commands",
description: "List currently running shell commands for a location. Exited commands are not included.",
}),
),
)
.add(
HttpApiEndpoint.post("shell.create", "/api/shell", {
query: LocationQuery,
payload: Shell.CreateInput,
success: Location.response(Shell.Info),
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.shell.create",
summary: "Run shell command",
description:
"Spawn one non-interactive shell command for a location. Combined stdout/stderr is captured to a file pageable via output.",
}),
),
)
.add(
HttpApiEndpoint.get("shell.get", "/api/shell/:id", {
params: { id: Shell.ID },
query: LocationQuery,
success: Location.response(Shell.Info),
error: ShellNotFoundError,
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.shell.get",
summary: "Get shell command",
description: "Get one shell command, including its status and exit code once exited.",
}),
),
)
.add(
HttpApiEndpoint.get("shell.output", "/api/shell/:id/output", {
params: { id: Shell.ID },
query: Schema.Struct({ ...LocationQuery.fields, ...Shell.OutputInput.fields }),
success: Location.response(Shell.Output),
error: ShellNotFoundError,
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.shell.output",
summary: "Read shell output",
description: "Page through captured combined output by absolute byte cursor.",
}),
),
)
.add(
HttpApiEndpoint.delete("shell.remove", "/api/shell/:id", {
params: { id: Shell.ID },
query: LocationQuery,
success: HttpApiSchema.NoContent,
error: ShellNotFoundError,
})
.annotateMerge(locationQueryOpenApi)
.annotateMerge(
OpenApi.annotations({
identifier: "v2.shell.remove",
summary: "Remove shell command",
description: "Terminate and remove one shell command and its retained output.",
}),
),
)
.annotateMerge(
OpenApi.annotations({ title: "shell", description: "Experimental location-scoped shell command routes." }),
)