feat: migrate hook callers to SDK message finders on SQLite backend
This commit is contained in:
@@ -1,9 +1,29 @@
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
|
||||
import { findNearestMessageWithFields, findFirstMessageWithAgent } from "../../features/hook-message-injector"
|
||||
import {
|
||||
findFirstMessageWithAgentFromSDK,
|
||||
findNearestMessageWithFieldsFromSDK,
|
||||
} from "../../features/hook-message-injector"
|
||||
import { getSessionAgent } from "../../features/claude-code-session-state"
|
||||
import { readBoulderState } from "../../features/boulder-state"
|
||||
import { getMessageDir } from "../../shared/opencode-message-dir"
|
||||
import { isSqliteBackend } from "../../shared/opencode-storage-detection"
|
||||
|
||||
type OpencodeClient = PluginInput["client"]
|
||||
|
||||
async function getAgentFromMessageFiles(
|
||||
sessionID: string,
|
||||
client?: OpencodeClient
|
||||
): Promise<string | undefined> {
|
||||
if (isSqliteBackend() && client) {
|
||||
const firstAgent = await findFirstMessageWithAgentFromSDK(client, sessionID)
|
||||
if (firstAgent) return firstAgent
|
||||
|
||||
const nearest = await findNearestMessageWithFieldsFromSDK(client, sessionID)
|
||||
return nearest?.agent
|
||||
}
|
||||
|
||||
function getAgentFromMessageFiles(sessionID: string): string | undefined {
|
||||
const messageDir = getMessageDir(sessionID)
|
||||
if (!messageDir) return undefined
|
||||
return findFirstMessageWithAgent(messageDir) ?? findNearestMessageWithFields(messageDir)?.agent
|
||||
@@ -21,7 +41,11 @@ function getAgentFromMessageFiles(sessionID: string): string | undefined {
|
||||
* - Message files return "prometheus" (oldest message from /plan)
|
||||
* - But boulder.json has agent: "atlas" (set by /start-work)
|
||||
*/
|
||||
export function getAgentFromSession(sessionID: string, directory: string): string | undefined {
|
||||
export async function getAgentFromSession(
|
||||
sessionID: string,
|
||||
directory: string,
|
||||
client?: OpencodeClient
|
||||
): Promise<string | undefined> {
|
||||
// Check in-memory first (current session)
|
||||
const memoryAgent = getSessionAgent(sessionID)
|
||||
if (memoryAgent) return memoryAgent
|
||||
@@ -33,5 +57,5 @@ export function getAgentFromSession(sessionID: string, directory: string): strin
|
||||
}
|
||||
|
||||
// Fallback to message files
|
||||
return getAgentFromMessageFiles(sessionID)
|
||||
return await getAgentFromMessageFiles(sessionID, client)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export function createPrometheusMdOnlyHook(ctx: PluginInput) {
|
||||
input: { tool: string; sessionID: string; callID: string },
|
||||
output: { args: Record<string, unknown>; message?: string }
|
||||
): Promise<void> => {
|
||||
const agentName = getAgentFromSession(input.sessionID, ctx.directory)
|
||||
const agentName = await getAgentFromSession(input.sessionID, ctx.directory, ctx.client)
|
||||
|
||||
if (!isPrometheusAgent(agentName)) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user