2026-02-17 14:52:40 +09:00
|
|
|
import { getPlanProgress, readBoulderState } from "../../features/boulder-state"
|
2026-04-05 15:34:02 +09:00
|
|
|
import {
|
|
|
|
|
getSessionAgent,
|
|
|
|
|
isAgentRegistered,
|
|
|
|
|
subagentSessions,
|
|
|
|
|
} from "../../features/claude-code-session-state"
|
2026-02-17 17:50:47 +09:00
|
|
|
import {
|
|
|
|
|
getActiveContinuationMarkerReason,
|
|
|
|
|
isContinuationMarkerActive,
|
|
|
|
|
readContinuationMarker,
|
|
|
|
|
} from "../../features/run-continuation-state"
|
2026-04-05 15:34:02 +09:00
|
|
|
import { isSessionInBoulderLineage } from "../../hooks/atlas/boulder-session-lineage"
|
|
|
|
|
import { getAgentConfigKey } from "../../shared/agent-display-names"
|
2026-02-17 14:52:40 +09:00
|
|
|
import { readState as readRalphLoopState } from "../../hooks/ralph-loop/storage"
|
2026-04-05 15:34:02 +09:00
|
|
|
import type { RunContext } from "./types"
|
2026-02-17 14:52:40 +09:00
|
|
|
|
|
|
|
|
export interface ContinuationState {
|
|
|
|
|
hasActiveBoulder: boolean
|
|
|
|
|
hasActiveRalphLoop: boolean
|
2026-02-17 17:50:47 +09:00
|
|
|
hasHookMarker: boolean
|
|
|
|
|
hasTodoHookMarker: boolean
|
|
|
|
|
hasActiveHookMarker: boolean
|
|
|
|
|
activeHookMarkerReason: string | null
|
2026-02-17 14:52:40 +09:00
|
|
|
}
|
|
|
|
|
|
2026-04-05 15:34:02 +09:00
|
|
|
export async function getContinuationState(
|
|
|
|
|
directory: string,
|
|
|
|
|
sessionID: string,
|
|
|
|
|
client?: RunContext["client"],
|
|
|
|
|
): Promise<ContinuationState> {
|
2026-02-17 17:50:47 +09:00
|
|
|
const marker = readContinuationMarker(directory, sessionID)
|
|
|
|
|
|
2026-02-17 14:52:40 +09:00
|
|
|
return {
|
2026-04-05 15:34:02 +09:00
|
|
|
hasActiveBoulder: await hasActiveBoulderContinuation(directory, sessionID, client),
|
2026-02-17 14:52:40 +09:00
|
|
|
hasActiveRalphLoop: hasActiveRalphLoopContinuation(directory, sessionID),
|
2026-02-17 17:50:47 +09:00
|
|
|
hasHookMarker: marker !== null,
|
|
|
|
|
hasTodoHookMarker: marker?.sources.todo !== undefined,
|
|
|
|
|
hasActiveHookMarker: isContinuationMarkerActive(marker),
|
|
|
|
|
activeHookMarkerReason: getActiveContinuationMarkerReason(marker),
|
2026-02-17 14:52:40 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-05 15:34:02 +09:00
|
|
|
async function hasActiveBoulderContinuation(
|
|
|
|
|
directory: string,
|
|
|
|
|
sessionID: string,
|
|
|
|
|
client?: RunContext["client"],
|
|
|
|
|
): Promise<boolean> {
|
2026-02-17 14:52:40 +09:00
|
|
|
const boulder = readBoulderState(directory)
|
|
|
|
|
if (!boulder) return false
|
|
|
|
|
|
|
|
|
|
const progress = getPlanProgress(boulder.active_plan)
|
2026-04-05 15:34:02 +09:00
|
|
|
if (progress.isComplete) return false
|
|
|
|
|
if (boulder.session_ids.includes(sessionID)) return true
|
|
|
|
|
if (!client) return false
|
|
|
|
|
if (!subagentSessions.has(sessionID)) return false
|
|
|
|
|
|
|
|
|
|
const requiredAgentName = boulder.agent ?? (isAgentRegistered("atlas") ? "atlas" : undefined)
|
|
|
|
|
if (!requiredAgentName || !isAgentRegistered(requiredAgentName)) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sessionAgent = getSessionAgent(sessionID)
|
|
|
|
|
const agentKey = getAgentConfigKey(sessionAgent ?? "")
|
|
|
|
|
const requiredAgentKey = getAgentConfigKey(requiredAgentName)
|
|
|
|
|
const isEligibleSubagent =
|
|
|
|
|
agentKey === requiredAgentKey
|
|
|
|
|
|| (requiredAgentKey === getAgentConfigKey("atlas") && agentKey === getAgentConfigKey("sisyphus"))
|
|
|
|
|
|
|
|
|
|
if (!isEligibleSubagent) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return isSessionInBoulderLineage({
|
|
|
|
|
client,
|
|
|
|
|
sessionID,
|
|
|
|
|
boulderSessionIDs: boulder.session_ids,
|
|
|
|
|
})
|
2026-02-17 14:52:40 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hasActiveRalphLoopContinuation(directory: string, sessionID: string): boolean {
|
|
|
|
|
const state = readRalphLoopState(directory)
|
|
|
|
|
if (!state || !state.active) return false
|
|
|
|
|
|
|
|
|
|
if (state.session_id && state.session_id !== sessionID) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|