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 {
|
function parsePluginVersion(entry: string): string | null {
|
||||||
// Check for current package name
|
|
||||||
if (entry.startsWith(`${PLUGIN_NAME}@`)) {
|
if (entry.startsWith(`${PLUGIN_NAME}@`)) {
|
||||||
const value = entry.slice(PLUGIN_NAME.length + 1)
|
const value = entry.slice(PLUGIN_NAME.length + 1)
|
||||||
if (!value || value === "latest") return null
|
if (!value || value === "latest") return null
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
// Check for legacy package name
|
|
||||||
if (entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)) {
|
if (entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)) {
|
||||||
const value = entry.slice(LEGACY_PLUGIN_NAME.length + 1)
|
const value = entry.slice(LEGACY_PLUGIN_NAME.length + 1)
|
||||||
if (!value || value === "latest") return null
|
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 {
|
function findPluginEntry(entries: string[]): { entry: string; isLocalDev: boolean } | null {
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
// Check for current package name
|
|
||||||
if (entry === PLUGIN_NAME || entry.startsWith(`${PLUGIN_NAME}@`)) {
|
if (entry === PLUGIN_NAME || entry.startsWith(`${PLUGIN_NAME}@`)) {
|
||||||
return { entry, isLocalDev: false }
|
return { entry, isLocalDev: false }
|
||||||
}
|
}
|
||||||
// Check for legacy package name
|
|
||||||
if (entry === LEGACY_PLUGIN_NAME || entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)) {
|
if (entry === LEGACY_PLUGIN_NAME || entry.startsWith(`${LEGACY_PLUGIN_NAME}@`)) {
|
||||||
return { entry, isLocalDev: false }
|
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))) {
|
if (entry.startsWith("file://") && (entry.includes(PLUGIN_NAME) || entry.includes(LEGACY_PLUGIN_NAME))) {
|
||||||
return { entry, isLocalDev: true }
|
return { entry, isLocalDev: true }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// ===== New 3-tier doctor types =====
|
|
||||||
|
|
||||||
export type DoctorMode = "default" | "status" | "verbose"
|
export type DoctorMode = "default" | "status" | "verbose"
|
||||||
|
|
||||||
export interface DoctorOptions {
|
export interface DoctorOptions {
|
||||||
@@ -73,8 +71,6 @@ export interface DoctorResult {
|
|||||||
exitCode: number
|
exitCode: number
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== Legacy types (used by existing checks until migration) =====
|
|
||||||
|
|
||||||
export type CheckCategory =
|
export type CheckCategory =
|
||||||
| "installation"
|
| "installation"
|
||||||
| "configuration"
|
| "configuration"
|
||||||
|
|||||||
@@ -28,10 +28,6 @@ export function appendTranscriptEntry(
|
|||||||
appendFileSync(path, line)
|
appendFileSync(path, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// Claude Code Compatible Transcript Builder
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
interface OpenCodeMessagePart {
|
interface OpenCodeMessagePart {
|
||||||
type: string
|
type: string
|
||||||
tool?: 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 {
|
interface TranscriptCacheEntry {
|
||||||
baseEntries: string[]
|
baseEntries: string[]
|
||||||
tempPath: string | null
|
tempPath: string | null
|
||||||
@@ -172,7 +162,6 @@ export async function buildTranscriptFromSession(
|
|||||||
baseEntries = cached.baseEntries
|
baseEntries = cached.baseEntries
|
||||||
previousTempPath = cached.tempPath
|
previousTempPath = cached.tempPath
|
||||||
} else {
|
} else {
|
||||||
// Fetch full session messages (only on first call or cache expiry)
|
|
||||||
const response = await client.session.messages({
|
const response = await client.session.messages({
|
||||||
path: { id: sessionId },
|
path: { id: sessionId },
|
||||||
query: { directory },
|
query: { directory },
|
||||||
@@ -186,7 +175,6 @@ export async function buildTranscriptFromSession(
|
|||||||
? parseMessagesToEntries(messages as OpenCodeMessage[])
|
? parseMessagesToEntries(messages as OpenCodeMessage[])
|
||||||
: []
|
: []
|
||||||
|
|
||||||
// Clean up old temp file if exists
|
|
||||||
if (cached?.tempPath) {
|
if (cached?.tempPath) {
|
||||||
try { unlinkSync(cached.tempPath) } catch { /* ignore */ }
|
try { unlinkSync(cached.tempPath) } catch { /* ignore */ }
|
||||||
}
|
}
|
||||||
@@ -198,7 +186,6 @@ export async function buildTranscriptFromSession(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append current tool call
|
|
||||||
const allEntries = [...baseEntries, buildCurrentEntry(currentToolName, currentToolInput)]
|
const allEntries = [...baseEntries, buildCurrentEntry(currentToolName, currentToolInput)]
|
||||||
|
|
||||||
if (previousTempPath) {
|
if (previousTempPath) {
|
||||||
@@ -211,7 +198,6 @@ export async function buildTranscriptFromSession(
|
|||||||
)
|
)
|
||||||
writeFileSync(tempPath, allEntries.join("\n") + "\n")
|
writeFileSync(tempPath, allEntries.join("\n") + "\n")
|
||||||
|
|
||||||
// Update cache temp path for cleanup tracking
|
|
||||||
const cacheEntry = transcriptCache.get(sessionId)
|
const cacheEntry = transcriptCache.get(sessionId)
|
||||||
if (cacheEntry) {
|
if (cacheEntry) {
|
||||||
cacheEntry.baseEntries = allEntries
|
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 {
|
export function deleteTempTranscript(path: string | null): void {
|
||||||
if (!path) return
|
if (!path) return
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
export const CODE_BLOCK_PATTERN = /```[\s\S]*?```/g
|
export const CODE_BLOCK_PATTERN = /```[\s\S]*?```/g
|
||||||
export const INLINE_CODE_PATTERN = /`[^`]+`/g
|
export const INLINE_CODE_PATTERN = /`[^`]+`/g
|
||||||
|
|
||||||
// Re-export from submodules
|
|
||||||
export { isPlannerAgent, isNonOmoAgent, getUltraworkMessage } from "./ultrawork"
|
export { isPlannerAgent, isNonOmoAgent, getUltraworkMessage } from "./ultrawork"
|
||||||
export { SEARCH_PATTERN, SEARCH_MESSAGE } from "./search"
|
export { SEARCH_PATTERN, SEARCH_MESSAGE } from "./search"
|
||||||
export { ANALYZE_PATTERN, ANALYZE_MESSAGE } from "./analyze"
|
export { ANALYZE_PATTERN, ANALYZE_MESSAGE } from "./analyze"
|
||||||
|
|
||||||
import { getUltraworkMessage } from "./ultrawork"
|
import { getUltraworkMessage } from "./ultrawork"
|
||||||
import { SEARCH_PATTERN, SEARCH_MESSAGE } from "./search"
|
import { SEARCH_PATTERN, SEARCH_MESSAGE } from "./search"
|
||||||
import { ANALYZE_PATTERN, ANALYZE_MESSAGE } from "./analyze"
|
|
||||||
|
|
||||||
export type KeywordDetector = {
|
export type KeywordDetector = {
|
||||||
pattern: RegExp
|
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>()
|
const sessionCategoryMap = new Map<string, string>()
|
||||||
|
|
||||||
export const SessionCategoryRegistry = {
|
export const SessionCategoryRegistry = {
|
||||||
/**
|
|
||||||
* Register a session with its category
|
|
||||||
*/
|
|
||||||
register: (sessionID: string, category: string): void => {
|
register: (sessionID: string, category: string): void => {
|
||||||
sessionCategoryMap.set(sessionID, category)
|
sessionCategoryMap.set(sessionID, category)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the category for a session
|
|
||||||
*/
|
|
||||||
get: (sessionID: string): string | undefined => {
|
get: (sessionID: string): string | undefined => {
|
||||||
return sessionCategoryMap.get(sessionID)
|
return sessionCategoryMap.get(sessionID)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a session from the registry (cleanup)
|
|
||||||
*/
|
|
||||||
remove: (sessionID: string): void => {
|
remove: (sessionID: string): void => {
|
||||||
sessionCategoryMap.delete(sessionID)
|
sessionCategoryMap.delete(sessionID)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a session is registered
|
|
||||||
*/
|
|
||||||
has: (sessionID: string): boolean => {
|
has: (sessionID: string): boolean => {
|
||||||
return sessionCategoryMap.has(sessionID)
|
return sessionCategoryMap.has(sessionID)
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the size of the registry (for debugging)
|
|
||||||
*/
|
|
||||||
size: (): number => {
|
size: (): number => {
|
||||||
return sessionCategoryMap.size
|
return sessionCategoryMap.size
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear all entries (use with caution, mainly for testing)
|
|
||||||
*/
|
|
||||||
clear: (): void => {
|
clear: (): void => {
|
||||||
sessionCategoryMap.clear()
|
sessionCategoryMap.clear()
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ export async function waitForCompletion(
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
log(`[call_omo_agent] Polling for completion...`)
|
log(`[call_omo_agent] Polling for completion...`)
|
||||||
|
|
||||||
// Poll for session completion
|
|
||||||
const POLL_INTERVAL_MS = 500
|
const POLL_INTERVAL_MS = 500
|
||||||
const MAX_POLL_TIME_MS = 5 * 60 * 1000 // 5 minutes max
|
const MAX_POLL_TIME_MS = 5 * 60 * 1000 // 5 minutes max
|
||||||
const pollStart = Date.now()
|
const pollStart = Date.now()
|
||||||
@@ -24,7 +23,6 @@ export async function waitForCompletion(
|
|||||||
const STABILITY_REQUIRED = 3
|
const STABILITY_REQUIRED = 3
|
||||||
|
|
||||||
while (Date.now() - pollStart < MAX_POLL_TIME_MS) {
|
while (Date.now() - pollStart < MAX_POLL_TIME_MS) {
|
||||||
// Check if aborted
|
|
||||||
if (toolContext.abort?.aborted) {
|
if (toolContext.abort?.aborted) {
|
||||||
log(`[call_omo_agent] Aborted by user`)
|
log(`[call_omo_agent] Aborted by user`)
|
||||||
throw new Error("Task aborted.")
|
throw new Error("Task aborted.")
|
||||||
@@ -32,19 +30,16 @@ export async function waitForCompletion(
|
|||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL_MS))
|
await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL_MS))
|
||||||
|
|
||||||
// Check session status
|
|
||||||
const statusResult = await ctx.client.session.status()
|
const statusResult = await ctx.client.session.status()
|
||||||
const allStatuses = normalizeSDKResponse(statusResult, {} as Record<string, { type: string }>)
|
const allStatuses = normalizeSDKResponse(statusResult, {} as Record<string, { type: string }>)
|
||||||
const sessionStatus = allStatuses[sessionID]
|
const sessionStatus = allStatuses[sessionID]
|
||||||
|
|
||||||
// If session is actively running, reset stability counter
|
|
||||||
if (sessionStatus && sessionStatus.type !== "idle") {
|
if (sessionStatus && sessionStatus.type !== "idle") {
|
||||||
stablePolls = 0
|
stablePolls = 0
|
||||||
lastMsgCount = 0
|
lastMsgCount = 0
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Session is idle - check message stability
|
|
||||||
const messagesCheck = await ctx.client.session.messages({ path: { id: sessionID } })
|
const messagesCheck = await ctx.client.session.messages({ path: { id: sessionID } })
|
||||||
const msgs = normalizeSDKResponse(messagesCheck, [] as Array<unknown>, {
|
const msgs = normalizeSDKResponse(messagesCheck, [] as Array<unknown>, {
|
||||||
preferResponseOnMissingData: true,
|
preferResponseOnMissingData: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user