mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
fix(core): derive positional input solely from freeform tools
This commit is contained in:
@@ -305,9 +305,7 @@ function inventoryTools(inventory: Inventory) {
|
||||
getNode(root, qualifiedName(registration)).tool = Tool.make({
|
||||
description: child.description,
|
||||
input: child.inputSchema,
|
||||
flat:
|
||||
registration.options?.flat ??
|
||||
(child.freeform !== undefined && ToolDefinition.freeformField(child.inputSchema) !== undefined),
|
||||
flat: child.freeform !== undefined && ToolDefinition.freeformField(child.inputSchema) !== undefined,
|
||||
output: child.outputSchema ?? Schema.NullOr(Schema.String),
|
||||
execute: (input) => Run.use((run) => run.executeTool(name, registration, input)),
|
||||
})
|
||||
|
||||
@@ -50,20 +50,23 @@ test("Code Mode lists one string argument for freeform tools and executes both i
|
||||
expect((await run('return await tools.echo("object required")')).error).toBe(true)
|
||||
})
|
||||
|
||||
test("Core tools can opt into positional Code Mode calls with multiple fields", async () => {
|
||||
test("a freeform declaration on a multi-field Core tool keeps the named input", async () => {
|
||||
const tool = {
|
||||
name: "scan",
|
||||
description: "Scan a path",
|
||||
options: { flat: true },
|
||||
freeform: { type: "text" },
|
||||
input: Schema.Struct({ path: Schema.String, options: Schema.Struct({ recursive: Schema.Boolean }) }),
|
||||
output: Schema.String,
|
||||
execute: ({ path, options }) => Effect.succeed({ output: `${path}:${options.recursive}` }),
|
||||
} satisfies Info
|
||||
const tools = new Map([[tool.name, tool]])
|
||||
const signature = "tools.scan(path: string, options: { recursive: boolean }): Promise<string>"
|
||||
expect(CodeModeTool.catalog({ tools }).tools).toContainEqual(expect.objectContaining({ signature }))
|
||||
const codeMode = createCodeMode(tools)
|
||||
const positional = await Effect.runPromise(
|
||||
codeMode.execute({ code: 'return await tools.scan("src", {recursive:true})' }, context),
|
||||
)
|
||||
expect(positional.output.error).toBe(true)
|
||||
const result = await Effect.runPromise(
|
||||
createCodeMode(tools).execute({ code: 'return await tools.scan("src", {recursive:true})' }, context),
|
||||
codeMode.execute({ code: 'return await tools.scan({path:"src", options:{recursive:true}})' }, context),
|
||||
)
|
||||
expect(result.output).toMatchObject({
|
||||
output: "src:true",
|
||||
|
||||
@@ -47,13 +47,10 @@ export type Options = BaseOptions &
|
||||
| {
|
||||
readonly codemode?: true
|
||||
readonly pinned?: boolean
|
||||
/** Offer top-level fields as positional arguments in Code Mode. */
|
||||
readonly flat?: boolean
|
||||
}
|
||||
| {
|
||||
readonly codemode: boolean
|
||||
readonly pinned?: never
|
||||
readonly flat?: never
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -1029,16 +1029,6 @@ If the selected model's API lists `regex` in models.dev, the model can write `OP
|
||||
|
||||
If you expose the same tool inside Code Mode (`codemode: true`), its JavaScript signature takes one string: `await tools.ticket("OPS-42")`. Code Mode also accepts `await tools.ticket({ id: "OPS-42" })` for existing scripts. Both forms work independently of the model's freeform support.
|
||||
|
||||
#### Positional arguments in Code Mode
|
||||
|
||||
Set `options: { flat: true }` to expose a tool's top-level fields as positional arguments in schema order. For example, `input: Schema.Struct({ path: Schema.String, options: Schema.Struct({ recursive: Schema.Boolean }) })` becomes:
|
||||
|
||||
```js
|
||||
await tools.scan("src", { recursive: true })
|
||||
```
|
||||
|
||||
The executor receives `{ path: "src", options: { recursive: true } }`. Named-object calls also work and take precedence when a single object fits both forms. Code Mode enables `flat` by default for eligible freeform tools; set `options.flat` to `false` to use the object signature.
|
||||
|
||||
Call `reload()` after changing source data captured by the callback. Reload replays the active transforms without
|
||||
changing their order; it does not rerun plugin setup.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user