fix(cli): use getAgentRuntimeName for agent resolution in run command
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import pc from "picocolors"
|
import pc from "picocolors"
|
||||||
import type { RunOptions } from "./types"
|
import type { RunOptions } from "./types"
|
||||||
import type { OhMyOpenCodeConfig } from "../../config"
|
import type { OhMyOpenCodeConfig } from "../../config"
|
||||||
import { getAgentConfigKey, getAgentDisplayName } from "../../shared/agent-display-names"
|
import { getAgentConfigKey, getAgentDisplayName, getAgentRuntimeName } from "../../shared/agent-display-names"
|
||||||
|
|
||||||
const CORE_AGENT_ORDER = ["sisyphus", "hephaestus", "prometheus", "atlas"] as const
|
const CORE_AGENT_ORDER = ["sisyphus", "hephaestus", "prometheus", "atlas"] as const
|
||||||
const DEFAULT_AGENT = "sisyphus"
|
const DEFAULT_AGENT = "sisyphus"
|
||||||
@@ -21,11 +21,12 @@ const normalizeAgentName = (agent?: string): ResolvedAgent | undefined => {
|
|||||||
|
|
||||||
const configKey = getAgentConfigKey(trimmed)
|
const configKey = getAgentConfigKey(trimmed)
|
||||||
const displayName = getAgentDisplayName(configKey)
|
const displayName = getAgentDisplayName(configKey)
|
||||||
|
const runtimeName = getAgentRuntimeName(configKey)
|
||||||
const isKnownAgent = displayName !== configKey
|
const isKnownAgent = displayName !== configKey
|
||||||
|
|
||||||
return {
|
return {
|
||||||
configKey,
|
configKey,
|
||||||
resolvedName: isKnownAgent ? displayName : trimmed,
|
resolvedName: isKnownAgent ? runtimeName : trimmed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,27 +62,28 @@ export const resolveRunAgent = (
|
|||||||
envAgent ??
|
envAgent ??
|
||||||
configAgent ?? {
|
configAgent ?? {
|
||||||
configKey: DEFAULT_AGENT,
|
configKey: DEFAULT_AGENT,
|
||||||
resolvedName: getAgentDisplayName(DEFAULT_AGENT),
|
resolvedName: getAgentRuntimeName(DEFAULT_AGENT),
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAgentDisabled(resolved.configKey, pluginConfig)) {
|
if (isAgentDisabled(resolved.configKey, pluginConfig)) {
|
||||||
const fallback = pickFallbackAgent(pluginConfig)
|
const fallback = pickFallbackAgent(pluginConfig)
|
||||||
const fallbackName = getAgentDisplayName(fallback)
|
const fallbackDisplayName = getAgentDisplayName(fallback)
|
||||||
|
const fallbackRuntimeName = getAgentRuntimeName(fallback)
|
||||||
const fallbackDisabled = isAgentDisabled(fallback, pluginConfig)
|
const fallbackDisabled = isAgentDisabled(fallback, pluginConfig)
|
||||||
if (fallbackDisabled) {
|
if (fallbackDisabled) {
|
||||||
console.log(
|
console.log(
|
||||||
pc.yellow(
|
pc.yellow(
|
||||||
`Requested agent "${resolved.resolvedName}" is disabled and no enabled core agent was found. Proceeding with "${fallbackName}".`
|
`Requested agent "${resolved.resolvedName}" is disabled and no enabled core agent was found. Proceeding with "${fallbackDisplayName}".`
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return fallbackName
|
return fallbackRuntimeName
|
||||||
}
|
}
|
||||||
console.log(
|
console.log(
|
||||||
pc.yellow(
|
pc.yellow(
|
||||||
`Requested agent "${resolved.resolvedName}" is disabled. Falling back to "${fallbackName}".`
|
`Requested agent "${resolved.resolvedName}" is disabled. Falling back to "${fallbackDisplayName}".`
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return fallbackName
|
return fallbackRuntimeName
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolved.resolvedName
|
return resolved.resolvedName
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test"
|
import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test"
|
||||||
import { OhMyOpenCodeConfigSchema, type OhMyOpenCodeConfig } from "../../config"
|
import { OhMyOpenCodeConfigSchema, type OhMyOpenCodeConfig } from "../../config"
|
||||||
import { resolveRunAgent } from "./agent-resolver"
|
import { resolveRunAgent } from "./agent-resolver"
|
||||||
|
import { getAgentRuntimeName } from "../../shared/agent-display-names"
|
||||||
|
|
||||||
const createConfig = (overrides: Partial<OhMyOpenCodeConfig> = {}): OhMyOpenCodeConfig =>
|
const createConfig = (overrides: Partial<OhMyOpenCodeConfig> = {}): OhMyOpenCodeConfig =>
|
||||||
OhMyOpenCodeConfigSchema.parse(overrides)
|
OhMyOpenCodeConfigSchema.parse(overrides)
|
||||||
@@ -31,7 +32,7 @@ describe("resolveRunAgent", () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(agent).toBe("Hephaestus - Deep Agent")
|
expect(agent).toBe(getAgentRuntimeName("hephaestus"))
|
||||||
})
|
})
|
||||||
|
|
||||||
it("uses env agent over config", () => {
|
it("uses env agent over config", () => {
|
||||||
@@ -43,7 +44,7 @@ describe("resolveRunAgent", () => {
|
|||||||
const agent = resolveRunAgent({ message: "test" }, config, env)
|
const agent = resolveRunAgent({ message: "test" }, config, env)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(agent).toBe("Atlas - Plan Executor")
|
expect(agent).toBe(getAgentRuntimeName("atlas"))
|
||||||
})
|
})
|
||||||
|
|
||||||
it("uses config agent over default", () => {
|
it("uses config agent over default", () => {
|
||||||
@@ -54,7 +55,7 @@ describe("resolveRunAgent", () => {
|
|||||||
const agent = resolveRunAgent({ message: "test" }, config, {})
|
const agent = resolveRunAgent({ message: "test" }, config, {})
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(agent).toBe("Prometheus - Plan Builder")
|
expect(agent).toBe(getAgentRuntimeName("prometheus"))
|
||||||
})
|
})
|
||||||
|
|
||||||
it("falls back to sisyphus when none set", () => {
|
it("falls back to sisyphus when none set", () => {
|
||||||
@@ -65,7 +66,7 @@ describe("resolveRunAgent", () => {
|
|||||||
const agent = resolveRunAgent({ message: "test" }, config, {})
|
const agent = resolveRunAgent({ message: "test" }, config, {})
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(agent).toBe("Sisyphus - Ultraworker")
|
expect(agent).toBe(getAgentRuntimeName("sisyphus"))
|
||||||
})
|
})
|
||||||
|
|
||||||
it("skips disabled sisyphus for next available core agent", () => {
|
it("skips disabled sisyphus for next available core agent", () => {
|
||||||
@@ -76,10 +77,10 @@ describe("resolveRunAgent", () => {
|
|||||||
const agent = resolveRunAgent({ message: "test" }, config, {})
|
const agent = resolveRunAgent({ message: "test" }, config, {})
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(agent).toBe("Hephaestus - Deep Agent")
|
expect(agent).toBe(getAgentRuntimeName("hephaestus"))
|
||||||
})
|
})
|
||||||
|
|
||||||
it("maps display-name style default_run_agent values to canonical display names", () => {
|
it("maps display-name style default_run_agent values to canonical runtime names", () => {
|
||||||
// given
|
// given
|
||||||
const config = createConfig({ default_run_agent: "Sisyphus - Ultraworker" })
|
const config = createConfig({ default_run_agent: "Sisyphus - Ultraworker" })
|
||||||
|
|
||||||
@@ -87,7 +88,7 @@ describe("resolveRunAgent", () => {
|
|||||||
const agent = resolveRunAgent({ message: "test" }, config, {})
|
const agent = resolveRunAgent({ message: "test" }, config, {})
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(agent).toBe("Sisyphus - Ultraworker")
|
expect(agent).toBe(getAgentRuntimeName("sisyphus"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user