From fd252ea82e1693bb8d624c31c97425236d41a92f Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sat, 4 Apr 2026 02:02:12 +0900 Subject: [PATCH] refactor: remove AI-generated code smells from prepublish changes Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- src/cli/doctor/checks/system-plugin.ts | 5 ---- src/cli/doctor/types.ts | 4 --- src/hooks/claude-code-hooks/transcript.ts | 17 ------------ src/hooks/keyword-detector/constants.ts | 2 -- src/shared/session-category-registry.ts | 26 ------------------- src/tools/call-omo-agent/completion-poller.ts | 5 ---- 6 files changed, 59 deletions(-) diff --git a/src/cli/doctor/checks/system-plugin.ts b/src/cli/doctor/checks/system-plugin.ts index 6abe089a5..531d8bf1d 100644 --- a/src/cli/doctor/checks/system-plugin.ts +++ b/src/cli/doctor/checks/system-plugin.ts @@ -23,13 +23,11 @@ function detectConfigPath(): string | null { } function parsePluginVersion(entry: string): string | null { - // Check for current package name if (entry.startsWith(`${PLUGIN_NAME}@`)) { const value = entry.slice(PLUGIN_NAME.length + 1) if (!value || value === "latest") return null return value } - // Check for legacy package name if (entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)) { const value = entry.slice(LEGACY_PLUGIN_NAME.length + 1) if (!value || value === "latest") return null @@ -40,15 +38,12 @@ function parsePluginVersion(entry: string): string | null { function findPluginEntry(entries: string[]): { entry: string; isLocalDev: boolean } | null { for (const entry of entries) { - // Check for current package name if (entry === PLUGIN_NAME || entry.startsWith(`${PLUGIN_NAME}@`)) { return { entry, isLocalDev: false } } - // Check for legacy package name if (entry === LEGACY_PLUGIN_NAME || entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)) { return { entry, isLocalDev: false } } - // Check for file:// paths that include either name if (entry.startsWith("file://") && (entry.includes(PLUGIN_NAME) || entry.includes(LEGACY_PLUGIN_NAME))) { return { entry, isLocalDev: true } } diff --git a/src/cli/doctor/types.ts b/src/cli/doctor/types.ts index 8c3598b88..ae6f0373a 100644 --- a/src/cli/doctor/types.ts +++ b/src/cli/doctor/types.ts @@ -1,5 +1,3 @@ -// ===== New 3-tier doctor types ===== - export type DoctorMode = "default" | "status" | "verbose" export interface DoctorOptions { @@ -73,8 +71,6 @@ export interface DoctorResult { exitCode: number } -// ===== Legacy types (used by existing checks until migration) ===== - export type CheckCategory = | "installation" | "configuration" diff --git a/src/hooks/claude-code-hooks/transcript.ts b/src/hooks/claude-code-hooks/transcript.ts index ce1f9c98e..71de86537 100644 --- a/src/hooks/claude-code-hooks/transcript.ts +++ b/src/hooks/claude-code-hooks/transcript.ts @@ -28,10 +28,6 @@ export function appendTranscriptEntry( appendFileSync(path, line) } -// ============================================================================ -// Claude Code Compatible Transcript Builder -// ============================================================================ - interface OpenCodeMessagePart { type: string tool?: string @@ -60,12 +56,6 @@ interface DisabledTranscriptEntry { } } -// ============================================================================ -// Session-scoped transcript cache to avoid full session.messages() rebuild -// on every tool call. Cache stores base entries from initial fetch; -// subsequent calls append new tool entries without re-fetching. -// ============================================================================ - interface TranscriptCacheEntry { baseEntries: string[] tempPath: string | null @@ -172,7 +162,6 @@ export async function buildTranscriptFromSession( baseEntries = cached.baseEntries previousTempPath = cached.tempPath } else { - // Fetch full session messages (only on first call or cache expiry) const response = await client.session.messages({ path: { id: sessionId }, query: { directory }, @@ -186,7 +175,6 @@ export async function buildTranscriptFromSession( ? parseMessagesToEntries(messages as OpenCodeMessage[]) : [] - // Clean up old temp file if exists if (cached?.tempPath) { try { unlinkSync(cached.tempPath) } catch { /* ignore */ } } @@ -198,7 +186,6 @@ export async function buildTranscriptFromSession( }) } - // Append current tool call const allEntries = [...baseEntries, buildCurrentEntry(currentToolName, currentToolInput)] if (previousTempPath) { @@ -211,7 +198,6 @@ export async function buildTranscriptFromSession( ) writeFileSync(tempPath, allEntries.join("\n") + "\n") - // Update cache temp path for cleanup tracking const cacheEntry = transcriptCache.get(sessionId) if (cacheEntry) { cacheEntry.baseEntries = allEntries @@ -234,9 +220,6 @@ export async function buildTranscriptFromSession( } } -/** - * Delete temp transcript file (call in finally block) - */ export function deleteTempTranscript(path: string | null): void { if (!path) return try { diff --git a/src/hooks/keyword-detector/constants.ts b/src/hooks/keyword-detector/constants.ts index 584b63b85..5f11717e0 100644 --- a/src/hooks/keyword-detector/constants.ts +++ b/src/hooks/keyword-detector/constants.ts @@ -1,14 +1,12 @@ export const CODE_BLOCK_PATTERN = /```[\s\S]*?```/g export const INLINE_CODE_PATTERN = /`[^`]+`/g -// Re-export from submodules export { isPlannerAgent, isNonOmoAgent, getUltraworkMessage } from "./ultrawork" export { SEARCH_PATTERN, SEARCH_MESSAGE } from "./search" export { ANALYZE_PATTERN, ANALYZE_MESSAGE } from "./analyze" import { getUltraworkMessage } from "./ultrawork" import { SEARCH_PATTERN, SEARCH_MESSAGE } from "./search" -import { ANALYZE_PATTERN, ANALYZE_MESSAGE } from "./analyze" export type KeywordDetector = { pattern: RegExp diff --git a/src/shared/session-category-registry.ts b/src/shared/session-category-registry.ts index ce19e1c04..fd4926077 100644 --- a/src/shared/session-category-registry.ts +++ b/src/shared/session-category-registry.ts @@ -1,52 +1,26 @@ -/** - * Session Category Registry - * - * Maintains a mapping of session IDs to their assigned categories. - * Used by runtime-fallback hook to lookup category-specific fallback_models. - */ - -// Map of sessionID -> category name const sessionCategoryMap = new Map() export const SessionCategoryRegistry = { - /** - * Register a session with its category - */ register: (sessionID: string, category: string): void => { sessionCategoryMap.set(sessionID, category) }, - /** - * Get the category for a session - */ get: (sessionID: string): string | undefined => { return sessionCategoryMap.get(sessionID) }, - /** - * Remove a session from the registry (cleanup) - */ remove: (sessionID: string): void => { sessionCategoryMap.delete(sessionID) }, - /** - * Check if a session is registered - */ has: (sessionID: string): boolean => { return sessionCategoryMap.has(sessionID) }, - /** - * Get the size of the registry (for debugging) - */ size: (): number => { return sessionCategoryMap.size }, - /** - * Clear all entries (use with caution, mainly for testing) - */ clear: (): void => { sessionCategoryMap.clear() }, diff --git a/src/tools/call-omo-agent/completion-poller.ts b/src/tools/call-omo-agent/completion-poller.ts index 61f2829b3..87711e247 100644 --- a/src/tools/call-omo-agent/completion-poller.ts +++ b/src/tools/call-omo-agent/completion-poller.ts @@ -15,7 +15,6 @@ export async function waitForCompletion( ): Promise { log(`[call_omo_agent] Polling for completion...`) - // Poll for session completion const POLL_INTERVAL_MS = 500 const MAX_POLL_TIME_MS = 5 * 60 * 1000 // 5 minutes max const pollStart = Date.now() @@ -24,7 +23,6 @@ export async function waitForCompletion( const STABILITY_REQUIRED = 3 while (Date.now() - pollStart < MAX_POLL_TIME_MS) { - // Check if aborted if (toolContext.abort?.aborted) { log(`[call_omo_agent] Aborted by user`) throw new Error("Task aborted.") @@ -32,19 +30,16 @@ export async function waitForCompletion( await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL_MS)) - // Check session status const statusResult = await ctx.client.session.status() const allStatuses = normalizeSDKResponse(statusResult, {} as Record) const sessionStatus = allStatuses[sessionID] - // If session is actively running, reset stability counter if (sessionStatus && sessionStatus.type !== "idle") { stablePolls = 0 lastMsgCount = 0 continue } - // Session is idle - check message stability const messagesCheck = await ctx.client.session.messages({ path: { id: sessionID } }) const msgs = normalizeSDKResponse(messagesCheck, [] as Array, { preferResponseOnMissingData: true,