Skip to content

Commit 5a4baca

Browse files
committed
fix(permission): harden tool name repair
1 parent 803511c commit 5a4baca

3 files changed

Lines changed: 17 additions & 17 deletions

File tree

‎packages/opencode/src/session/llm/native-runtime.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,11 @@ export function stream(input: StreamInput): StreamResult {
152152
}
153153

154154
function repairToolCall(tools: ReturnType<typeof nativeTools>, call: ToolCallPart): ToolCallPart {
155-
if (tools[call.name]) return call
155+
const hasTool = (name: string) => Object.prototype.hasOwnProperty.call(tools, name)
156+
if (hasTool(call.name)) return call
156157
const lower = call.name.toLowerCase()
157-
if (tools[lower]) return { ...call, name: lower }
158-
if (!tools.invalid) return call
158+
if (hasTool(lower)) return { ...call, name: lower }
159+
if (!hasTool("invalid")) return call
159160
return {
160161
...call,
161162
name: "invalid",

‎packages/opencode/src/util/wildcard.ts‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
import { sortBy, pipe } from "remeda"
22

33
export function match(str: string, pattern: string) {
4-
return matchNormalized(str?.replaceAll("\\", "/"), pattern?.replaceAll("\\", "/"))
5-
}
6-
7-
// altimate_change start — preserve POSIX backslashes when matching filesystem paths
8-
export function matchPath(str: string, pattern: string) {
9-
if (process.platform === "win32") return match(str, pattern)
10-
return matchNormalized(str, pattern)
11-
}
12-
// altimate_change end
13-
14-
function matchNormalized(str: string, pattern: string) {
4+
if (str) str = str.replaceAll("\\", "/")
5+
if (pattern) pattern = pattern.replaceAll("\\", "/")
156
let escaped = pattern
167
.replace(/[.+^${}()|[\]\\]/g, "\\$&") // escape special regex chars
178
.replace(/\*/g, ".*") // * becomes .*
@@ -27,6 +18,10 @@ function matchNormalized(str: string, pattern: string) {
2718
return new RegExp("^" + escaped + "$", flags).test(str)
2819
}
2920

21+
// altimate_change start — preserve POSIX backslashes when matching filesystem paths
22+
export { matchPath } from "@opencode-ai/core/util/wildcard"
23+
// altimate_change end
24+
3025
export function all(input: string, patterns: Record<string, any>) {
3126
const sorted = pipe(patterns, Object.entries, sortBy([([key]) => key.length, "asc"], [([key]) => key, "asc"]))
3227
let result = undefined

‎packages/opencode/test/session/llm-native.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ describe("session.llm-native.request", () => {
558558
it.effect("keeps the invalid fallback dispatchable without advertising it to the provider", () =>
559559
Effect.gen(function* () {
560560
let advertised: string[] = []
561-
let invalidInput: unknown
561+
const invalidInputs: unknown[] = []
562562
let visibleCalls = 0
563563
const invalid = tool({
564564
description: "Internal fallback",
@@ -568,7 +568,7 @@ describe("session.llm-native.request", () => {
568568
required: ["tool", "error"],
569569
}),
570570
execute: async (input) => {
571-
invalidInput = input
571+
invalidInputs.push(input)
572572
return "fallback"
573573
},
574574
})
@@ -587,6 +587,7 @@ describe("session.llm-native.request", () => {
587587
return Stream.fromIterable([
588588
LLMEvent.toolCall({ id: "call-visible", name: "VISIBLE", input: {} }),
589589
LLMEvent.toolCall({ id: "call-invalid", name: "write", input: {} }),
590+
LLMEvent.toolCall({ id: "call-inherited", name: "constructor", input: {} }),
590591
LLMEvent.finish({ reason: "tool-calls" }),
591592
])
592593
},
@@ -608,7 +609,10 @@ describe("session.llm-native.request", () => {
608609
const events = Array.from(yield* native.stream.pipe(Stream.runCollect))
609610
expect(advertised).toEqual(["visible"])
610611
expect(visibleCalls).toBe(1)
611-
expect(invalidInput).toEqual({ tool: "write", error: "Unknown tool: write" })
612+
expect(invalidInputs).toEqual([
613+
{ tool: "write", error: "Unknown tool: write" },
614+
{ tool: "constructor", error: "Unknown tool: constructor" },
615+
])
612616
expect(events).toEqual(
613617
expect.arrayContaining([
614618
expect.objectContaining({ type: "tool-call", name: "visible" }),

0 commit comments

Comments
 (0)