refactor: wave 1 - extract leaf modules, rename catch-all files, split index.ts hooks
- Split 25+ index.ts files into hook.ts + extracted modules - Rename all catch-all utils.ts/helpers.ts to domain-specific names - Split src/tools/lsp/ into ~15 focused modules - Split src/tools/delegate-task/ into ~18 focused modules - Separate shared types from implementation - 155 files changed, 60+ new files created - All typecheck clean, 61 tests pass
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
|
||||
import { log } from "../../shared/logger"
|
||||
|
||||
const HOOK_NAME = "stop-continuation-guard"
|
||||
|
||||
export interface StopContinuationGuard {
|
||||
event: (input: { event: { type: string; properties?: unknown } }) => Promise<void>
|
||||
"chat.message": (input: { sessionID?: string }) => Promise<void>
|
||||
stop: (sessionID: string) => void
|
||||
isStopped: (sessionID: string) => boolean
|
||||
clear: (sessionID: string) => void
|
||||
}
|
||||
|
||||
export function createStopContinuationGuardHook(
|
||||
_ctx: PluginInput
|
||||
): StopContinuationGuard {
|
||||
const stoppedSessions = new Set<string>()
|
||||
|
||||
const stop = (sessionID: string): void => {
|
||||
stoppedSessions.add(sessionID)
|
||||
log(`[${HOOK_NAME}] Continuation stopped for session`, { sessionID })
|
||||
}
|
||||
|
||||
const isStopped = (sessionID: string): boolean => {
|
||||
return stoppedSessions.has(sessionID)
|
||||
}
|
||||
|
||||
const clear = (sessionID: string): void => {
|
||||
stoppedSessions.delete(sessionID)
|
||||
log(`[${HOOK_NAME}] Continuation guard cleared for session`, { sessionID })
|
||||
}
|
||||
|
||||
const event = async ({
|
||||
event,
|
||||
}: {
|
||||
event: { type: string; properties?: unknown }
|
||||
}): Promise<void> => {
|
||||
const props = event.properties as Record<string, unknown> | undefined
|
||||
|
||||
if (event.type === "session.deleted") {
|
||||
const sessionInfo = props?.info as { id?: string } | undefined
|
||||
if (sessionInfo?.id) {
|
||||
clear(sessionInfo.id)
|
||||
log(`[${HOOK_NAME}] Session deleted: cleaned up`, { sessionID: sessionInfo.id })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const chatMessage = async ({
|
||||
sessionID,
|
||||
}: {
|
||||
sessionID?: string
|
||||
}): Promise<void> => {
|
||||
if (sessionID && stoppedSessions.has(sessionID)) {
|
||||
clear(sessionID)
|
||||
log(`[${HOOK_NAME}] Cleared stop state on new user message`, { sessionID })
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
event,
|
||||
"chat.message": chatMessage,
|
||||
stop,
|
||||
isStopped,
|
||||
clear,
|
||||
}
|
||||
}
|
||||
@@ -1,67 +1,2 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
import { log } from "../../shared/logger"
|
||||
|
||||
const HOOK_NAME = "stop-continuation-guard"
|
||||
|
||||
export interface StopContinuationGuard {
|
||||
event: (input: { event: { type: string; properties?: unknown } }) => Promise<void>
|
||||
"chat.message": (input: { sessionID?: string }) => Promise<void>
|
||||
stop: (sessionID: string) => void
|
||||
isStopped: (sessionID: string) => boolean
|
||||
clear: (sessionID: string) => void
|
||||
}
|
||||
|
||||
export function createStopContinuationGuardHook(
|
||||
_ctx: PluginInput
|
||||
): StopContinuationGuard {
|
||||
const stoppedSessions = new Set<string>()
|
||||
|
||||
const stop = (sessionID: string): void => {
|
||||
stoppedSessions.add(sessionID)
|
||||
log(`[${HOOK_NAME}] Continuation stopped for session`, { sessionID })
|
||||
}
|
||||
|
||||
const isStopped = (sessionID: string): boolean => {
|
||||
return stoppedSessions.has(sessionID)
|
||||
}
|
||||
|
||||
const clear = (sessionID: string): void => {
|
||||
stoppedSessions.delete(sessionID)
|
||||
log(`[${HOOK_NAME}] Continuation guard cleared for session`, { sessionID })
|
||||
}
|
||||
|
||||
const event = async ({
|
||||
event,
|
||||
}: {
|
||||
event: { type: string; properties?: unknown }
|
||||
}): Promise<void> => {
|
||||
const props = event.properties as Record<string, unknown> | undefined
|
||||
|
||||
if (event.type === "session.deleted") {
|
||||
const sessionInfo = props?.info as { id?: string } | undefined
|
||||
if (sessionInfo?.id) {
|
||||
clear(sessionInfo.id)
|
||||
log(`[${HOOK_NAME}] Session deleted: cleaned up`, { sessionID: sessionInfo.id })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const chatMessage = async ({
|
||||
sessionID,
|
||||
}: {
|
||||
sessionID?: string
|
||||
}): Promise<void> => {
|
||||
if (sessionID && stoppedSessions.has(sessionID)) {
|
||||
clear(sessionID)
|
||||
log(`[${HOOK_NAME}] Cleared stop state on new user message`, { sessionID })
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
event,
|
||||
"chat.message": chatMessage,
|
||||
stop,
|
||||
isStopped,
|
||||
clear,
|
||||
}
|
||||
}
|
||||
export { createStopContinuationGuardHook } from "./hook"
|
||||
export type { StopContinuationGuard } from "./hook"
|
||||
|
||||
Reference in New Issue
Block a user