YeonGyu-Kim 180d16b977 fix: prevent plugin crash by removing non-function exports from barrel files
BREAKING: OpenCode plugin loader calls all exports as functions.
Exporting non-function values (schemas, constants, types) causes TypeError.

Changes:
- Remove OhMyOpenCodeConfigSchema export from root index.ts
- Replace 'export *' with explicit function exports in hooks/index.ts
- Remove 'export *' from comment-checker/index.ts
2025-12-05 04:08:59 +09:00

98 lines
2.5 KiB
TypeScript

import type { PendingCall, FileComments } from "./types"
import { detectComments, isSupportedFile } from "./detector"
import { applyFilters } from "./filters"
import { formatHookMessage } from "./output"
const pendingCalls = new Map<string, PendingCall>()
const PENDING_CALL_TTL = 60_000
function cleanupOldPendingCalls(): void {
const now = Date.now()
for (const [callID, call] of pendingCalls) {
if (now - call.timestamp > PENDING_CALL_TTL) {
pendingCalls.delete(callID)
}
}
}
setInterval(cleanupOldPendingCalls, 10_000)
export function createCommentCheckerHooks() {
return {
"tool.execute.before": async (
input: { tool: string; sessionID: string; callID: string },
output: { args: Record<string, unknown> }
): Promise<void> => {
const toolLower = input.tool.toLowerCase()
if (toolLower !== "write" && toolLower !== "edit" && toolLower !== "multiedit") {
return
}
const filePath = (output.args.filePath ?? output.args.file_path) as string | undefined
const content = output.args.content as string | undefined
if (!filePath) {
return
}
if (!isSupportedFile(filePath)) {
return
}
pendingCalls.set(input.callID, {
filePath,
content,
tool: toolLower as "write" | "edit" | "multiedit",
sessionID: input.sessionID,
timestamp: Date.now(),
})
},
"tool.execute.after": async (
input: { tool: string; sessionID: string; callID: string },
output: { title: string; output: string; metadata: unknown }
): Promise<void> => {
const pendingCall = pendingCalls.get(input.callID)
if (!pendingCall) {
return
}
pendingCalls.delete(input.callID)
if (output.output.toLowerCase().includes("error")) {
return
}
try {
let content: string
if (pendingCall.content) {
content = pendingCall.content
} else {
const file = Bun.file(pendingCall.filePath)
content = await file.text()
}
const rawComments = await detectComments(pendingCall.filePath, content)
const filteredComments = applyFilters(rawComments)
if (filteredComments.length === 0) {
return
}
const fileComments: FileComments[] = [
{
filePath: pendingCall.filePath,
comments: filteredComments,
},
]
const message = formatHookMessage(fileComments)
output.output += `\n\n${message}`
} catch {}
},
}
}