fix(start-work): gracefully handle missing Atlas agent (fixes #2132)
This commit is contained in:
@@ -11,12 +11,23 @@ export function getMainSessionID(): string | undefined {
|
|||||||
return _mainSessionID
|
return _mainSessionID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const registeredAgentNames = new Set<string>()
|
||||||
|
|
||||||
|
export function registerAgentName(name: string): void {
|
||||||
|
registeredAgentNames.add(name.toLowerCase())
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isAgentRegistered(name: string): boolean {
|
||||||
|
return registeredAgentNames.has(name.toLowerCase())
|
||||||
|
}
|
||||||
|
|
||||||
/** @internal For testing only */
|
/** @internal For testing only */
|
||||||
export function _resetForTesting(): void {
|
export function _resetForTesting(): void {
|
||||||
_mainSessionID = undefined
|
_mainSessionID = undefined
|
||||||
subagentSessions.clear()
|
subagentSessions.clear()
|
||||||
syncSubagentSessions.clear()
|
syncSubagentSessions.clear()
|
||||||
sessionAgentMap.clear()
|
sessionAgentMap.clear()
|
||||||
|
registeredAgentNames.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
const sessionAgentMap = new Map<string, string>()
|
const sessionAgentMap = new Map<string, string>()
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
} from "../../features/boulder-state"
|
} from "../../features/boulder-state"
|
||||||
import { log } from "../../shared/logger"
|
import { log } from "../../shared/logger"
|
||||||
import { getAgentDisplayName } from "../../shared/agent-display-names"
|
import { getAgentDisplayName } from "../../shared/agent-display-names"
|
||||||
import { updateSessionAgent } from "../../features/claude-code-session-state"
|
import { updateSessionAgent, isAgentRegistered } from "../../features/claude-code-session-state"
|
||||||
import { detectWorktreePath } from "./worktree-detector"
|
import { detectWorktreePath } from "./worktree-detector"
|
||||||
import { parseUserRequest } from "./parse-user-request"
|
import { parseUserRequest } from "./parse-user-request"
|
||||||
|
|
||||||
@@ -80,9 +80,14 @@ export function createStartWorkHook(ctx: PluginInput) {
|
|||||||
if (!promptText.includes("<session-context>")) return
|
if (!promptText.includes("<session-context>")) return
|
||||||
|
|
||||||
log(`[${HOOK_NAME}] Processing start-work command`, { sessionID: input.sessionID })
|
log(`[${HOOK_NAME}] Processing start-work command`, { sessionID: input.sessionID })
|
||||||
updateSessionAgent(input.sessionID, "atlas")
|
const atlasDisplayName = getAgentDisplayName("atlas")
|
||||||
if (output.message) {
|
if (isAgentRegistered("atlas") || isAgentRegistered(atlasDisplayName)) {
|
||||||
output.message["agent"] = getAgentDisplayName("atlas")
|
updateSessionAgent(input.sessionID, "atlas")
|
||||||
|
if (output.message) {
|
||||||
|
output.message["agent"] = atlasDisplayName
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log(`[${HOOK_NAME}] Atlas agent not available, continuing with current agent`, { sessionID: input.sessionID })
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingState = readBoulderState(ctx.directory)
|
const existingState = readBoulderState(ctx.directory)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import type { OhMyOpenCodeConfig } from "../config";
|
|||||||
import { log, migrateAgentConfig } from "../shared";
|
import { log, migrateAgentConfig } from "../shared";
|
||||||
import { AGENT_NAME_MAP } from "../shared/migration";
|
import { AGENT_NAME_MAP } from "../shared/migration";
|
||||||
import { getAgentDisplayName } from "../shared/agent-display-names";
|
import { getAgentDisplayName } from "../shared/agent-display-names";
|
||||||
|
import { registerAgentName } from "../features/claude-code-session-state";
|
||||||
import {
|
import {
|
||||||
discoverConfigSourceSkills,
|
discoverConfigSourceSkills,
|
||||||
discoverGlobalAgentsSkills,
|
discoverGlobalAgentsSkills,
|
||||||
@@ -292,6 +293,9 @@ export async function applyAgentConfig(params: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const agentResult = params.config.agent as Record<string, unknown>;
|
const agentResult = params.config.agent as Record<string, unknown>;
|
||||||
|
for (const name of Object.keys(agentResult)) {
|
||||||
|
registerAgentName(name);
|
||||||
|
}
|
||||||
log("[config-handler] agents loaded", { agentKeys: Object.keys(agentResult) });
|
log("[config-handler] agents loaded", { agentKeys: Object.keys(agentResult) });
|
||||||
return agentResult;
|
return agentResult;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user