Files
oh-my-opencode-free-fork/src/tools/index.ts
Victor Jaepyo Jo 95645effd7 fix(ralph-loop): clear orphaned state when original session no longer exists (#446)
* fix(ralph-loop): clear orphaned state when original session no longer exists

When a session with an active ralph-loop terminates abnormally (abort, window close),
the state file remains with active: true. Previously, when a new session started,
the hook would skip the orphaned state without cleaning it up.

This fix adds session existence validation:
- Before skipping a loop owned by a different session, check if that session still exists
- If the original session no longer exists, clear the orphan state and log
- If the original session still exists, skip as before (it's another active session's loop)

Changes:
- Add checkSessionExists option to RalphLoopOptions for dependency injection
- Wire up sessionExists from session-manager as the default implementation
- Add tests for orphan state cleanup and active session preservation

* fix(ralph-loop): add error handling around checkSessionExists call

Wraps the async checkSessionExists call in try/catch for consistency
with other async operations in this file. If the check throws, logs
the error and falls back to the original behavior (not clearing state).

---------

Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
2026-01-03 14:11:59 +09:00

82 lines
1.9 KiB
TypeScript

import {
lsp_hover,
lsp_goto_definition,
lsp_find_references,
lsp_document_symbols,
lsp_workspace_symbols,
lsp_diagnostics,
lsp_servers,
lsp_prepare_rename,
lsp_rename,
lsp_code_actions,
lsp_code_action_resolve,
} from "./lsp"
import {
ast_grep_search,
ast_grep_replace,
} from "./ast-grep"
import { grep } from "./grep"
import { glob } from "./glob"
import { slashcommand } from "./slashcommand"
import {
session_list,
session_read,
session_search,
session_info,
} from "./session-manager"
export { sessionExists } from "./session-manager/storage"
export { interactive_bash, startBackgroundCheck as startTmuxCheck } from "./interactive-bash"
export { createSkillTool } from "./skill"
export { getTmuxPath } from "./interactive-bash/utils"
export { createSkillMcpTool } from "./skill-mcp"
import {
createBackgroundTask,
createBackgroundOutput,
createBackgroundCancel,
} from "./background-task"
import type { PluginInput, ToolDefinition } from "@opencode-ai/plugin"
import type { BackgroundManager } from "../features/background-agent"
type OpencodeClient = PluginInput["client"]
export { createCallOmoAgent } from "./call-omo-agent"
export { createLookAt } from "./look-at"
export function createBackgroundTools(manager: BackgroundManager, client: OpencodeClient): Record<string, ToolDefinition> {
return {
background_task: createBackgroundTask(manager),
background_output: createBackgroundOutput(manager, client),
background_cancel: createBackgroundCancel(manager, client),
}
}
export const builtinTools: Record<string, ToolDefinition> = {
lsp_hover,
lsp_goto_definition,
lsp_find_references,
lsp_document_symbols,
lsp_workspace_symbols,
lsp_diagnostics,
lsp_servers,
lsp_prepare_rename,
lsp_rename,
lsp_code_actions,
lsp_code_action_resolve,
ast_grep_search,
ast_grep_replace,
grep,
glob,
slashcommand,
session_list,
session_read,
session_search,
session_info,
}