mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Update skills UI components for managed skills (#165)
* ralph: ralph-repo-level-skills-dialog-skillseditor-fix completed after 4 iterations * Remove parent session notification and child session tracking from Ralph loops Sending promptAsync to parent sessions on loop completion could resume work in previously inactive sessions. Removed parentSessionId from RalphState, child session tracking maps, and all related event handling. Watchdog stall detection still works via the session status API. * Migrate global skills to workspace path * Add skill injection to scheduled job prompts * Refactor schedules UI with MultiSelect and tab menu * Update skills UI components for managed skills
This commit is contained in:
1 parent
4bd0940ab9
commit
c3cba72b51
22 files changed
+981
-337
No files matched your search
@@ -28,7 +28,6 @@ export function createRalphEventHandler(
|
||||
const lastActivityTime = new Map<string, number>()
|
||||
const stallWatchdogs = new Map<string, NodeJS.Timeout>()
|
||||
const consecutiveStalls = new Map<string, number>()
|
||||
const childSessions = new Map<string, Set<string>>()
|
||||
async function commitAndCleanupWorktree(state: RalphState): Promise<{ committed: boolean; cleaned: boolean }> {
|
||||
if (state.inPlace) {
|
||||
logger.log(`Ralph: in-place mode, skipping commit and cleanup`)
|
||||
@@ -81,19 +80,6 @@ export function createRalphEventHandler(
|
||||
return { committed, cleaned }
|
||||
}
|
||||
|
||||
function findRalphParent(childSessionId: string): string | undefined {
|
||||
for (const [ralphId, children] of childSessions.entries()) {
|
||||
if (children.has(childSessionId)) {
|
||||
return ralphId
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function recordActivity(sessionId: string): void {
|
||||
lastActivityTime.set(sessionId, Date.now())
|
||||
}
|
||||
|
||||
function stopWatchdog(sessionId: string): void {
|
||||
const interval = stallWatchdogs.get(sessionId)
|
||||
if (interval) {
|
||||
@@ -102,7 +88,6 @@ export function createRalphEventHandler(
|
||||
}
|
||||
lastActivityTime.delete(sessionId)
|
||||
consecutiveStalls.delete(sessionId)
|
||||
childSessions.delete(sessionId)
|
||||
}
|
||||
|
||||
function startWatchdog(sessionId: string): void {
|
||||
@@ -129,11 +114,8 @@ export function createRalphEventHandler(
|
||||
const statusResult = await v2Client.session.status()
|
||||
const statuses = (statusResult.data ?? {}) as Record<string, { type: string }>
|
||||
|
||||
const sessionIds = [sessionId, ...(childSessions.get(sessionId) ?? [])]
|
||||
const hasActiveWork = sessionIds.some(id => {
|
||||
const status = statuses[id]?.type
|
||||
return status === 'busy' || status === 'retry' || status === 'compact'
|
||||
})
|
||||
const status = statuses[sessionId]?.type
|
||||
const hasActiveWork = status === 'busy' || status === 'retry' || status === 'compact'
|
||||
|
||||
if (hasActiveWork) {
|
||||
lastActivityTime.set(sessionId, Date.now())
|
||||
@@ -182,19 +164,6 @@ export function createRalphEventHandler(
|
||||
}
|
||||
|
||||
async function terminateLoop(sessionId: string, state: RalphState, reason: string): Promise<void> {
|
||||
const children = childSessions.get(sessionId)
|
||||
if (children) {
|
||||
await Promise.all(
|
||||
Array.from(children).map(async (childId) => {
|
||||
try {
|
||||
await v2Client.session.abort({ sessionID: childId })
|
||||
} catch {
|
||||
// Child session may already be idle
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
stopWatchdog(sessionId)
|
||||
|
||||
const retryTimeout = retryTimeouts.get(sessionId)
|
||||
@@ -222,49 +191,6 @@ export function createRalphEventHandler(
|
||||
if (reason === 'completed') {
|
||||
commitResult = await commitAndCleanupWorktree(state)
|
||||
}
|
||||
|
||||
if (state.parentSessionId) {
|
||||
try {
|
||||
let notificationText: string
|
||||
if (state.inPlace) {
|
||||
if (reason === 'completed') {
|
||||
notificationText = [
|
||||
`Ralph loop "${state.worktreeName}" completed (in-place).`,
|
||||
'',
|
||||
`Iteration: ${state.iteration}`,
|
||||
`Changes are in the current directory on branch: ${state.worktreeBranch}`,
|
||||
].join('\n')
|
||||
} else {
|
||||
notificationText = `Ralph loop "${state.worktreeName}" terminated (in-place).\n\nReason: ${reason}\nIteration: ${state.iteration}\nDirectory: ${state.worktreeDir}\nBranch: ${state.worktreeBranch}`
|
||||
}
|
||||
} else if (reason === 'completed' && commitResult) {
|
||||
const parts = [`Ralph loop "${state.worktreeName}" completed.`, '', `Iteration: ${state.iteration}`]
|
||||
if (commitResult.committed) {
|
||||
parts.push(`Changes committed on branch: ${state.worktreeBranch}`)
|
||||
}
|
||||
if (commitResult.cleaned) {
|
||||
parts.push(`Worktree removed. Use \`git merge ${state.worktreeBranch}\` or \`git checkout ${state.worktreeBranch}\` to access the changes.`)
|
||||
} else {
|
||||
parts.push(`Worktree: ${state.worktreeDir}`)
|
||||
}
|
||||
notificationText = parts.join('\n')
|
||||
} else {
|
||||
notificationText = `Ralph loop "${state.worktreeName}" terminated.\n\nReason: ${reason}\nIteration: ${state.iteration}\nWorktree: ${state.worktreeDir}\nBranch: ${state.worktreeBranch}`
|
||||
}
|
||||
|
||||
await client.session.promptAsync({
|
||||
path: { id: state.parentSessionId },
|
||||
body: {
|
||||
parts: [{
|
||||
type: 'text' as const,
|
||||
text: notificationText,
|
||||
}],
|
||||
},
|
||||
})
|
||||
} catch (err) {
|
||||
logger.error(`Ralph: failed to notify parent session`, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePromptError(sessionId: string, state: RalphState, context: string, err: unknown, retryFn?: () => Promise<void>): Promise<void> {
|
||||
@@ -580,35 +506,6 @@ export function createRalphEventHandler(
|
||||
return
|
||||
}
|
||||
|
||||
if (event.type === 'session.created' || event.type === 'session.updated') {
|
||||
const info = event.properties?.info as { id?: string; parentID?: string } | undefined
|
||||
if (info?.id && info?.parentID) {
|
||||
const parentState = ralphService.getActiveState(info.parentID)
|
||||
if (parentState?.active) {
|
||||
let children = childSessions.get(info.parentID)
|
||||
if (!children) {
|
||||
children = new Set()
|
||||
childSessions.set(info.parentID, children)
|
||||
}
|
||||
children.add(info.id)
|
||||
recordActivity(info.parentID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type === 'session.status') {
|
||||
const eventSessionId = event.properties?.sessionID as string
|
||||
if (eventSessionId) {
|
||||
if (ralphService.getActiveState(eventSessionId)?.active) {
|
||||
recordActivity(eventSessionId)
|
||||
}
|
||||
const parentId = findRalphParent(eventSessionId)
|
||||
if (parentId) {
|
||||
recordActivity(parentId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type === 'session.error') {
|
||||
const errorProps = event.properties as { sessionID?: string; error?: { name?: string } }
|
||||
const eventSessionId = errorProps?.sessionID
|
||||
@@ -622,21 +519,6 @@ export function createRalphEventHandler(
|
||||
logger.log(`Ralph: session ${eventSessionId} aborted, terminating loop`)
|
||||
await terminateLoop(eventSessionId, state, 'user_aborted')
|
||||
}
|
||||
|
||||
const parentId = findRalphParent(eventSessionId)
|
||||
if (parentId) {
|
||||
const parentState = ralphService.getActiveState(parentId)
|
||||
if (parentState?.active) {
|
||||
logger.log(`Ralph: child session abort detected, terminating parent loop ${parentId}`)
|
||||
await terminateLoop(parentId, parentState, 'user_aborted')
|
||||
}
|
||||
}
|
||||
|
||||
const childLoops = ralphService.findByParentSessionId(eventSessionId)
|
||||
for (const childLoop of childLoops) {
|
||||
logger.log(`Ralph: launcher session ${eventSessionId} aborted, terminating child loop ${childLoop.sessionId}`)
|
||||
await terminateLoop(childLoop.sessionId, childLoop, 'user_aborted')
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -648,13 +530,6 @@ export function createRalphEventHandler(
|
||||
const state = ralphService.getActiveState(sessionId)
|
||||
if (!state || !state.active) return
|
||||
|
||||
const parentId = findRalphParent(sessionId)
|
||||
if (parentId) {
|
||||
recordActivity(parentId)
|
||||
}
|
||||
|
||||
recordActivity(sessionId)
|
||||
|
||||
try {
|
||||
// Re-check state right before calling phase handler as extra safety
|
||||
const freshState = ralphService.getActiveState(sessionId)
|
||||
@@ -689,7 +564,6 @@ export function createRalphEventHandler(
|
||||
}
|
||||
lastActivityTime.clear()
|
||||
consecutiveStalls.clear()
|
||||
childSessions.clear()
|
||||
logger.log('Ralph: cleared all retry timeouts')
|
||||
}
|
||||
|
||||
|
||||
@@ -408,7 +408,6 @@ export function createMemoryPlugin(config: PluginConfig): Plugin {
|
||||
audit: boolean
|
||||
agent?: string
|
||||
model?: { providerID: string; modelID: string }
|
||||
parentSessionId?: string
|
||||
inPlace?: boolean
|
||||
onLoopStarted?: (sessionId: string) => void
|
||||
}
|
||||
@@ -506,7 +505,6 @@ export function createMemoryPlugin(config: PluginConfig): Plugin {
|
||||
audit: options.audit,
|
||||
errorCount: 0,
|
||||
auditCount: 0,
|
||||
parentSessionId: options.parentSessionId,
|
||||
inPlace: options.inPlace,
|
||||
}
|
||||
|
||||
@@ -873,7 +871,6 @@ Do NOT output text without also making this tool call.
|
||||
agent: 'code',
|
||||
model: ralphModel,
|
||||
inPlace: args.inPlace,
|
||||
parentSessionId: context.sessionID,
|
||||
onLoopStarted: (id) => ralphHandler.startWatchdog(id),
|
||||
})
|
||||
},
|
||||
@@ -1045,7 +1042,6 @@ Do NOT output text without also making this tool call.
|
||||
audit: stoppedState.audit,
|
||||
errorCount: 0,
|
||||
auditCount: 0,
|
||||
parentSessionId: stoppedState.parentSessionId,
|
||||
inPlace: stoppedState.inPlace,
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ export interface RalphState {
|
||||
auditCount: number
|
||||
terminationReason?: string
|
||||
completedAt?: string
|
||||
parentSessionId?: string
|
||||
inPlace?: boolean
|
||||
}
|
||||
|
||||
@@ -40,7 +39,6 @@ export interface RalphService {
|
||||
listActive(): RalphState[]
|
||||
listRecent(): RalphState[]
|
||||
findByWorktreeName(name: string): RalphState | null
|
||||
findByParentSessionId(parentId: string): RalphState[]
|
||||
getStallTimeoutMs(): number
|
||||
getMinAudits(): number
|
||||
terminateAll(): void
|
||||
@@ -143,10 +141,6 @@ export function createRalphService(
|
||||
return active.find((s) => s.worktreeName === name) ?? null
|
||||
}
|
||||
|
||||
function findByParentSessionId(parentId: string): RalphState[] {
|
||||
return listActive().filter((s) => s.parentSessionId === parentId)
|
||||
}
|
||||
|
||||
function getStallTimeoutMs(): number {
|
||||
return ralphConfig?.stallTimeoutMs ?? STALL_TIMEOUT_MS
|
||||
}
|
||||
@@ -180,7 +174,6 @@ export function createRalphService(
|
||||
listActive,
|
||||
listRecent,
|
||||
findByWorktreeName,
|
||||
findByParentSessionId,
|
||||
getStallTimeoutMs,
|
||||
getMinAudits,
|
||||
terminateAll,
|
||||
|
||||
Reference in new issue
Block a user