Skip to content

Commit 5cb897f

Browse files
committed
tui: guard path formatting inputs
Issue #29895
1 parent c613c33 commit 5cb897f

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

packages/opencode/src/cli/cmd/tui/context/path-format.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Global } from "@opencode-ai/core/global"
44

55
const context = createContext<{
66
path: () => string
7-
format: (input?: string) => string
7+
format: (input?: unknown) => string
88
}>()
99

1010
export function PathFormatterProvider(props: ParentProps<{ path: string | undefined }>) {
@@ -23,8 +23,8 @@ export function usePathFormatter() {
2323
return value
2424
}
2525

26-
function formatPath(input: string | undefined, base: string | undefined) {
27-
if (!input) return ""
26+
function formatPath(input: unknown, base: string | undefined) {
27+
if (typeof input !== "string" || !input) return ""
2828

2929
const root = base || process.cwd()
3030
const absolute = path.isAbsolute(input) ? input : path.resolve(root, input)

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,10 +2531,10 @@ function Skill(props: ToolProps<typeof SkillTool>) {
25312531
)
25322532
}
25332533

2534-
function Diagnostics(props: { diagnostics?: Record<string, Record<string, any>[]>; filePath: string }) {
2534+
function Diagnostics(props: { diagnostics?: Record<string, Record<string, any>[]>; filePath: unknown }) {
25352535
const { theme } = useTheme()
25362536
const errors = createMemo(() => {
2537-
const normalized = Filesystem.normalizePath(props.filePath)
2537+
const normalized = Filesystem.normalizePath(typeof props.filePath === "string" ? props.filePath : "")
25382538
const arr = props.diagnostics?.[normalized] ?? []
25392539
return arr.filter((x) => x.severity === 1).slice(0, 3)
25402540
})
@@ -2563,8 +2563,8 @@ function input(input: Record<string, any>, omit?: string[]): string {
25632563
return `[${primitives.map(([key, value]) => `${key}=${value}`).join(", ")}]`
25642564
}
25652565

2566-
function filetype(input?: string) {
2567-
if (!input) return "none"
2566+
function filetype(input?: unknown) {
2567+
if (typeof input !== "string" || !input) return "none"
25682568
const ext = path.extname(input)
25692569
const language = LANGUAGE_EXTENSIONS[ext]
25702570
if (["typescriptreact", "javascriptreact", "javascript"].includes(language)) return "typescript"

packages/opencode/src/cli/cmd/tui/routes/session/permission.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import { usePathFormatter } from "../../context/path-format"
2020

2121
type PermissionStage = "permission" | "always" | "reject"
2222

23-
function filetype(input?: string) {
24-
if (!input) return "none"
23+
function filetype(input?: unknown) {
24+
if (typeof input !== "string" || !input) return "none"
2525
const ext = path.extname(input)
2626
const language = LANGUAGE_EXTENSIONS[ext]
2727
if (["typescriptreact", "javascriptreact", "javascript"].includes(language)) return "typescript"
@@ -35,8 +35,14 @@ function EditBody(props: { request: PermissionRequest }) {
3535
const config = useTuiConfig()
3636
const dimensions = useTerminalDimensions()
3737

38-
const filepath = createMemo(() => (props.request.metadata?.filepath as string) ?? "")
39-
const diff = createMemo(() => (props.request.metadata?.diff as string) ?? "")
38+
const filepath = createMemo(() => {
39+
const value = props.request.metadata?.filepath
40+
return typeof value === "string" ? value : ""
41+
})
42+
const diff = createMemo(() => {
43+
const value = props.request.metadata?.diff
44+
return typeof value === "string" ? value : ""
45+
})
4046

4147
const view = createMemo(() => {
4248
const diffStyle = config.diff_style

0 commit comments

Comments
 (0)