2026-02-08 15:01:42 +09:00
|
|
|
import type { PluginInput } from "@opencode-ai/plugin"
|
|
|
|
|
import { createAtlasEventHandler } from "./event-handler"
|
|
|
|
|
import { createToolExecuteAfterHandler } from "./tool-execute-after"
|
|
|
|
|
import { createToolExecuteBeforeHandler } from "./tool-execute-before"
|
2026-03-18 17:31:27 +09:00
|
|
|
import type { AtlasHookOptions, PendingTaskRef, SessionState } from "./types"
|
2026-02-08 15:01:42 +09:00
|
|
|
|
|
|
|
|
export function createAtlasHook(ctx: PluginInput, options?: AtlasHookOptions) {
|
|
|
|
|
const sessions = new Map<string, SessionState>()
|
|
|
|
|
const pendingFilePaths = new Map<string, string>()
|
2026-03-18 17:31:27 +09:00
|
|
|
const pendingTaskRefs = new Map<string, PendingTaskRef>()
|
2026-02-27 13:38:52 -07:00
|
|
|
const autoCommit = options?.autoCommit ?? true
|
2026-02-08 15:01:42 +09:00
|
|
|
|
|
|
|
|
function getState(sessionID: string): SessionState {
|
|
|
|
|
let state = sessions.get(sessionID)
|
|
|
|
|
if (!state) {
|
|
|
|
|
state = { promptFailureCount: 0 }
|
|
|
|
|
sessions.set(sessionID, state)
|
|
|
|
|
}
|
|
|
|
|
return state
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
handler: createAtlasEventHandler({ ctx, options, sessions, getState }),
|
2026-03-17 17:25:46 +09:00
|
|
|
"tool.execute.before": createToolExecuteBeforeHandler({ ctx, pendingFilePaths, pendingTaskRefs }),
|
|
|
|
|
"tool.execute.after": createToolExecuteAfterHandler({ ctx, pendingFilePaths, pendingTaskRefs, autoCommit, getState }),
|
2026-02-08 15:01:42 +09:00
|
|
|
}
|
|
|
|
|
}
|