refactor: remove AI-generated code smells from prepublish changes
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<string, string>()
|
||||
|
||||
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()
|
||||
},
|
||||
|
||||
@@ -15,7 +15,6 @@ export async function waitForCompletion(
|
||||
): Promise<void> {
|
||||
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<string, { type: string }>)
|
||||
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<unknown>, {
|
||||
preferResponseOnMissingData: true,
|
||||
|
||||
Reference in New Issue
Block a user