From 1f62fa5b2ab1a11696f8610f4701d5e4d583f581 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 23 Feb 2026 02:43:04 +0900 Subject: [PATCH] refactor(tools/call-omo-agent): remove dead code submodules Delete 3 unused files in call-omo-agent module: - session-completion-poller.ts - session-message-output-extractor.ts - subagent-session-prompter.ts Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus --- .../session-completion-poller.ts | 76 --------------- .../session-message-output-extractor.ts | 93 ------------------- .../subagent-session-prompter.ts | 27 ------ 3 files changed, 196 deletions(-) delete mode 100644 src/tools/call-omo-agent/session-completion-poller.ts delete mode 100644 src/tools/call-omo-agent/session-message-output-extractor.ts delete mode 100644 src/tools/call-omo-agent/subagent-session-prompter.ts diff --git a/src/tools/call-omo-agent/session-completion-poller.ts b/src/tools/call-omo-agent/session-completion-poller.ts deleted file mode 100644 index 7b40c2652..000000000 --- a/src/tools/call-omo-agent/session-completion-poller.ts +++ /dev/null @@ -1,76 +0,0 @@ -import type { PluginInput } from "@opencode-ai/plugin" -import { log } from "../../shared" - -function getSessionStatusType(statusResult: unknown, sessionID: string): string | null { - if (typeof statusResult !== "object" || statusResult === null) return null - if (!("data" in statusResult)) return null - const data = (statusResult as { data?: unknown }).data - if (typeof data !== "object" || data === null) return null - const record = data as Record - const entry = record[sessionID] - if (typeof entry !== "object" || entry === null) return null - const typeValue = (entry as Record)["type"] - return typeof typeValue === "string" ? typeValue : null -} - -function getMessagesArray(result: unknown): unknown[] { - if (Array.isArray(result)) return result - if (typeof result !== "object" || result === null) return [] - if (!("data" in result)) return [] - const data = (result as { data?: unknown }).data - return Array.isArray(data) ? data : [] -} - -export async function waitForSessionCompletion( - ctx: PluginInput, - options: { - sessionID: string - abortSignal?: AbortSignal - maxPollTimeMs: number - pollIntervalMs: number - stabilityRequired: number - }, -): Promise<{ ok: true } | { ok: false; reason: "aborted" | "timeout" }> { - const pollStart = Date.now() - let lastMsgCount = 0 - let stablePolls = 0 - - while (Date.now() - pollStart < options.maxPollTimeMs) { - if (options.abortSignal?.aborted) { - log("[call_omo_agent] Aborted by user") - return { ok: false, reason: "aborted" } - } - - await new Promise((resolve) => { - setTimeout(resolve, options.pollIntervalMs) - }) - - const statusResult = await ctx.client.session.status() - const sessionStatusType = getSessionStatusType(statusResult, options.sessionID) - - if (sessionStatusType && sessionStatusType !== "idle") { - stablePolls = 0 - lastMsgCount = 0 - continue - } - - const messagesCheck = await ctx.client.session.messages({ - path: { id: options.sessionID }, - }) - const currentMsgCount = getMessagesArray(messagesCheck).length - - if (currentMsgCount > 0 && currentMsgCount === lastMsgCount) { - stablePolls++ - if (stablePolls >= options.stabilityRequired) { - log("[call_omo_agent] Session complete", { messageCount: currentMsgCount }) - return { ok: true } - } - } else { - stablePolls = 0 - lastMsgCount = currentMsgCount - } - } - - log("[call_omo_agent] Timeout reached") - return { ok: false, reason: "timeout" } -} diff --git a/src/tools/call-omo-agent/session-message-output-extractor.ts b/src/tools/call-omo-agent/session-message-output-extractor.ts deleted file mode 100644 index 3cc2347a2..000000000 --- a/src/tools/call-omo-agent/session-message-output-extractor.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { consumeNewMessages, type CursorMessage } from "../../shared/session-cursor" - -type SessionMessagePart = { - type: string - text?: string - content?: unknown -} - -export type SessionMessage = CursorMessage & { - info?: CursorMessage["info"] & { role?: string } - parts?: SessionMessagePart[] -} - -function getRole(message: SessionMessage): string | null { - const role = message.info?.role - return typeof role === "string" ? role : null -} - -function getCreatedTime(message: SessionMessage): number { - const time = message.info?.time - if (typeof time === "number") return time - if (typeof time === "string") return Number(time) || 0 - const created = time?.created - if (typeof created === "number") return created - if (typeof created === "string") return Number(created) || 0 - return 0 -} - -function isRelevantRole(role: string | null): boolean { - return role === "assistant" || role === "tool" -} - -function extractTextFromParts(parts: SessionMessagePart[] | undefined): string[] { - if (!parts) return [] - const extracted: string[] = [] - - for (const part of parts) { - if ((part.type === "text" || part.type === "reasoning") && part.text) { - extracted.push(part.text) - continue - } - if (part.type !== "tool_result") continue - const content = part.content - if (typeof content === "string" && content) { - extracted.push(content) - continue - } - if (!Array.isArray(content)) continue - for (const block of content) { - if (typeof block !== "object" || block === null) continue - const record = block as Record - const typeValue = record["type"] - const textValue = record["text"] - if ( - (typeValue === "text" || typeValue === "reasoning") && - typeof textValue === "string" && - textValue - ) { - extracted.push(textValue) - } - } - } - - return extracted -} - -export function extractNewSessionOutput( - sessionID: string, - messages: SessionMessage[], -): { output: string; hasNewOutput: boolean } { - const relevantMessages = messages.filter((message) => - isRelevantRole(getRole(message)), - ) - if (relevantMessages.length === 0) { - return { output: "", hasNewOutput: false } - } - - const sortedMessages = [...relevantMessages].sort( - (a, b) => getCreatedTime(a) - getCreatedTime(b), - ) - const newMessages = consumeNewMessages(sessionID, sortedMessages) - if (newMessages.length === 0) { - return { output: "", hasNewOutput: false } - } - - const chunks: string[] = [] - for (const message of newMessages) { - chunks.push(...extractTextFromParts(message.parts)) - } - - const output = chunks.filter((text) => text.length > 0).join("\n\n") - return { output, hasNewOutput: output.length > 0 } -} diff --git a/src/tools/call-omo-agent/subagent-session-prompter.ts b/src/tools/call-omo-agent/subagent-session-prompter.ts deleted file mode 100644 index 286bfc999..000000000 --- a/src/tools/call-omo-agent/subagent-session-prompter.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { PluginInput } from "@opencode-ai/plugin" -import { log, getAgentToolRestrictions } from "../../shared" - -export async function promptSubagentSession( - ctx: PluginInput, - options: { sessionID: string; agent: string; prompt: string }, -): Promise<{ ok: true } | { ok: false; error: string }> { - try { - await ctx.client.session.promptAsync({ - path: { id: options.sessionID }, - body: { - agent: options.agent, - tools: { - ...getAgentToolRestrictions(options.agent), - task: false, - question: false, - }, - parts: [{ type: "text", text: options.prompt }], - }, - }) - return { ok: true } - } catch (error) { - const errorMessage = error instanceof Error ? error.message : String(error) - log("[call_omo_agent] Prompt error", { error: errorMessage }) - return { ok: false, error: errorMessage } - } -}