Skip to content

Commit c750df3

Browse files
committed
fix(scout): use effect schema tool params
1 parent 3bf0c79 commit c750df3

2 files changed

Lines changed: 32 additions & 42 deletions

File tree

packages/opencode/src/tool/repo_clone.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
import path from "path"
2-
import z from "zod"
3-
import { Effect } from "effect"
2+
import { Effect, Schema } from "effect"
43
import { AppFileSystem } from "@opencode-ai/shared/filesystem"
54
import { Flock } from "@opencode-ai/shared/util/flock"
65
import { Git } from "@/git"
76
import DESCRIPTION from "./repo_clone.txt"
87
import * as Tool from "./tool"
98
import { parseRepositoryReference, repositoryCachePath, sameRepositoryReference } from "@/util/repository"
109

11-
type Parameters = {
12-
repository: string
13-
refresh?: boolean
14-
}
15-
16-
const parameters: z.ZodType<Parameters> = z.object({
17-
repository: z
18-
.string()
19-
.describe("Repository to clone, as a git URL, host/path reference, or GitHub owner/repo shorthand"),
20-
refresh: z.boolean().optional().describe("When true, fetches the latest remote state into the managed cache"),
10+
export const Parameters = Schema.Struct({
11+
repository: Schema.String.annotate({
12+
description: "Repository to clone, as a git URL, host/path reference, or GitHub owner/repo shorthand",
13+
}),
14+
refresh: Schema.optional(Schema.Boolean).annotate({
15+
description: "When true, fetches the latest remote state into the managed cache",
16+
}),
2117
})
2218

2319
type Metadata = {
@@ -49,16 +45,16 @@ function resetTarget(input: {
4945
return "HEAD"
5046
}
5147

52-
export const RepoCloneTool = Tool.define<typeof parameters, Metadata, AppFileSystem.Service | Git.Service>(
48+
export const RepoCloneTool = Tool.define<typeof Parameters, Metadata, AppFileSystem.Service | Git.Service>(
5349
"repo_clone",
5450
Effect.gen(function* () {
5551
const fs = yield* AppFileSystem.Service
5652
const git = yield* Git.Service
5753

5854
return {
5955
description: DESCRIPTION,
60-
parameters,
61-
execute: (params: Parameters, ctx: Tool.Context<Metadata>) =>
56+
parameters: Parameters,
57+
execute: (params: Schema.Schema.Type<typeof Parameters>, ctx: Tool.Context<Metadata>) =>
6258
Effect.gen(function* () {
6359
const reference = parseRepositoryReference(params.repository)
6460
if (!reference) throw new Error("Repository must be a git URL, host/path reference, or GitHub owner/repo shorthand")
@@ -152,6 +148,6 @@ export const RepoCloneTool = Tool.define<typeof parameters, Metadata, AppFileSys
152148
(lock) => Effect.promise(() => lock.release()).pipe(Effect.ignore),
153149
)
154150
}).pipe(Effect.orDie),
155-
} satisfies Tool.DefWithoutID<typeof parameters, Metadata>
151+
} satisfies Tool.DefWithoutID<typeof Parameters, Metadata>
156152
}),
157153
)

packages/opencode/src/tool/repo_overview.ts

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from "path"
2-
import z from "zod"
3-
import { Effect } from "effect"
2+
import { Effect, Schema } from "effect"
43
import { AppFileSystem } from "@opencode-ai/shared/filesystem"
54
import { Git } from "@/git"
65
import { assertExternalDirectoryEffect } from "./external-directory"
@@ -9,24 +8,17 @@ import * as Tool from "./tool"
98
import { parseRepositoryReference, repositoryCachePath } from "@/util/repository"
109
import { Instance } from "@/project/instance"
1110

12-
type Parameters = {
13-
repository?: string
14-
path?: string
15-
depth?: number
16-
}
17-
18-
const parameters: z.ZodType<Parameters> = z
19-
.object({
20-
repository: z
21-
.string()
22-
.optional()
23-
.describe("Cached repository to inspect, as a git URL, host/path reference, or GitHub owner/repo shorthand"),
24-
path: z.string().optional().describe("Directory path to inspect instead of a cached repository"),
25-
depth: z.number().int().positive().max(6).optional().describe("Maximum structure depth to include. Defaults to 3."),
26-
})
27-
.refine((input) => Boolean(input.repository || input.path), {
28-
message: "Either repository or path is required",
11+
export const Parameters = Schema.Struct({
12+
repository: Schema.optional(Schema.String).annotate({
13+
description: "Cached repository to inspect, as a git URL, host/path reference, or GitHub owner/repo shorthand",
14+
}),
15+
path: Schema.optional(Schema.String).annotate({
16+
description: "Directory path to inspect instead of a cached repository",
17+
}),
18+
depth: Schema.optional(Schema.Number).annotate({
19+
description: "Maximum structure depth to include. Defaults to 3.",
2920
})
21+
})
3022

3123
type Metadata = {
3224
path: string
@@ -84,19 +76,21 @@ function commonEntrypoints(files: Set<string>) {
8476
return ["index.ts", "index.tsx", "index.js", "index.mjs", "main.ts", "main.js", "src/index.ts", "src/index.tsx", "src/index.js", "src/main.ts", "src/main.js"].filter((file) => files.has(file))
8577
}
8678

87-
export const RepoOverviewTool = Tool.define<typeof parameters, Metadata, AppFileSystem.Service | Git.Service>(
79+
export const RepoOverviewTool = Tool.define<typeof Parameters, Metadata, AppFileSystem.Service | Git.Service>(
8880
"repo_overview",
8981
Effect.gen(function* () {
9082
const fs = yield* AppFileSystem.Service
9183
const git = yield* Git.Service
9284

93-
const resolveTarget = Effect.fn("RepoOverviewTool.resolveTarget")(function* (params: Parameters) {
85+
const resolveTarget = Effect.fn("RepoOverviewTool.resolveTarget")(function* (params: Schema.Schema.Type<typeof Parameters>) {
9486
if (params.path) {
9587
const full = path.isAbsolute(params.path) ? params.path : path.resolve(Instance.directory, params.path)
9688
return { path: full, repository: params.repository }
9789
}
9890

99-
const parsed = parseRepositoryReference(params.repository!)
91+
if (!params.repository) throw new Error("Either repository or path is required")
92+
93+
const parsed = parseRepositoryReference(params.repository)
10094
if (!parsed) throw new Error("Repository must be a git URL, host/path reference, or GitHub owner/repo shorthand")
10195

10296
const repository = parsed.label
@@ -152,11 +146,11 @@ export const RepoOverviewTool = Tool.define<typeof parameters, Metadata, AppFile
152146

153147
return {
154148
description: DESCRIPTION,
155-
parameters,
156-
execute: (params: Parameters, ctx: Tool.Context<Metadata>) =>
149+
parameters: Parameters,
150+
execute: (params: Schema.Schema.Type<typeof Parameters>, ctx: Tool.Context<Metadata>) =>
157151
Effect.gen(function* () {
158152
const target = yield* resolveTarget(params)
159-
const depth = params.depth ?? 3
153+
const depth = !params.depth || !Number.isInteger(params.depth) || params.depth < 1 || params.depth > 6 ? 3 : params.depth
160154

161155
yield* assertExternalDirectoryEffect(ctx, target.path, { kind: "directory" })
162156
yield* ctx.ask({
@@ -239,6 +233,6 @@ export const RepoOverviewTool = Tool.define<typeof parameters, Metadata, AppFile
239233
].join("\n"),
240234
}
241235
}).pipe(Effect.orDie),
242-
} satisfies Tool.DefWithoutID<typeof parameters, Metadata>
236+
} satisfies Tool.DefWithoutID<typeof Parameters, Metadata>
243237
}),
244238
)

0 commit comments

Comments
 (0)