Merge pull request #3242 from code-yeongyu/fix/zwsp-api-leak
fix(agents): remove ZWSP prefixes from config.agent keys (#3238)
This commit is contained in:
@@ -9,11 +9,11 @@ import type { OhMyOpenCodeConfig } from "../config"
|
||||
import * as agentLoader from "../features/claude-code-agent-loader"
|
||||
import * as skillLoader from "../features/opencode-skill-loader"
|
||||
import type { LoadedSkill } from "../features/opencode-skill-loader"
|
||||
import { getAgentDisplayName, getAgentListDisplayName } from "../shared/agent-display-names"
|
||||
import { getAgentDisplayName, getAgentDisplayName } from "../shared/agent-display-names"
|
||||
import { applyAgentConfig } from "./agent-config-handler"
|
||||
import type { PluginComponents } from "./plugin-components-loader"
|
||||
|
||||
const BUILTIN_SISYPHUS_DISPLAY_NAME = getAgentListDisplayName("sisyphus")
|
||||
const BUILTIN_SISYPHUS_DISPLAY_NAME = getAgentDisplayName("sisyphus")
|
||||
const BUILTIN_SISYPHUS_JUNIOR_DISPLAY_NAME = getAgentDisplayName("sisyphus-junior")
|
||||
const BUILTIN_MULTIMODAL_LOOKER_DISPLAY_NAME = getAgentDisplayName("multimodal-looker")
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect } from "bun:test"
|
||||
import { remapAgentKeysToDisplayNames } from "./agent-key-remapper"
|
||||
import { getAgentListDisplayName } from "../shared/agent-display-names"
|
||||
import { getAgentDisplayName } from "../shared/agent-display-names"
|
||||
|
||||
describe("remapAgentKeysToDisplayNames", () => {
|
||||
it("remaps known agent keys to display names", () => {
|
||||
@@ -14,7 +14,7 @@ describe("remapAgentKeysToDisplayNames", () => {
|
||||
const result = remapAgentKeysToDisplayNames(agents)
|
||||
|
||||
// then known agents get display name keys only
|
||||
expect(result[getAgentListDisplayName("sisyphus")]).toBeDefined()
|
||||
expect(result[getAgentDisplayName("sisyphus")]).toBeDefined()
|
||||
expect(result["oracle"]).toBeDefined()
|
||||
expect(result["sisyphus"]).toBeUndefined()
|
||||
})
|
||||
@@ -49,21 +49,21 @@ describe("remapAgentKeysToDisplayNames", () => {
|
||||
const result = remapAgentKeysToDisplayNames(agents)
|
||||
|
||||
// then all get display name keys
|
||||
expect(result[getAgentListDisplayName("sisyphus")]).toBeDefined()
|
||||
expect(result[getAgentDisplayName("sisyphus")]).toBeDefined()
|
||||
expect(result["sisyphus"]).toBeUndefined()
|
||||
expect(result[getAgentListDisplayName("hephaestus")]).toBeDefined()
|
||||
expect(result[getAgentDisplayName("hephaestus")]).toBeDefined()
|
||||
expect(result["hephaestus"]).toBeUndefined()
|
||||
expect(result[getAgentListDisplayName("prometheus")]).toBeDefined()
|
||||
expect(result[getAgentDisplayName("prometheus")]).toBeDefined()
|
||||
expect(result["prometheus"]).toBeUndefined()
|
||||
expect(result[getAgentListDisplayName("atlas")]).toBeDefined()
|
||||
expect(result[getAgentDisplayName("atlas")]).toBeDefined()
|
||||
expect(result["atlas"]).toBeUndefined()
|
||||
expect(result[getAgentListDisplayName("athena")]).toBeDefined()
|
||||
expect(result[getAgentDisplayName("athena")]).toBeDefined()
|
||||
expect(result["athena"]).toBeUndefined()
|
||||
expect(result[getAgentListDisplayName("metis")]).toBeDefined()
|
||||
expect(result[getAgentDisplayName("metis")]).toBeDefined()
|
||||
expect(result["metis"]).toBeUndefined()
|
||||
expect(result[getAgentListDisplayName("momus")]).toBeDefined()
|
||||
expect(result[getAgentDisplayName("momus")]).toBeDefined()
|
||||
expect(result["momus"]).toBeUndefined()
|
||||
expect(result[getAgentListDisplayName("sisyphus-junior")]).toBeDefined()
|
||||
expect(result[getAgentDisplayName("sisyphus-junior")]).toBeDefined()
|
||||
expect(result["sisyphus-junior"]).toBeUndefined()
|
||||
})
|
||||
|
||||
@@ -77,8 +77,8 @@ describe("remapAgentKeysToDisplayNames", () => {
|
||||
const result = remapAgentKeysToDisplayNames(agents)
|
||||
|
||||
// then only display key is emitted
|
||||
expect(Object.keys(result)).toEqual([getAgentListDisplayName("sisyphus")])
|
||||
expect(result[getAgentListDisplayName("sisyphus")]).toBeDefined()
|
||||
expect(Object.keys(result)).toEqual([getAgentDisplayName("sisyphus")])
|
||||
expect(result[getAgentDisplayName("sisyphus")]).toBeDefined()
|
||||
expect(result["sisyphus"]).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getAgentListDisplayName } from "../shared/agent-display-names"
|
||||
import { getAgentDisplayName } from "../shared/agent-display-names"
|
||||
|
||||
export function remapAgentKeysToDisplayNames(
|
||||
agents: Record<string, unknown>,
|
||||
@@ -6,7 +6,7 @@ export function remapAgentKeysToDisplayNames(
|
||||
const result: Record<string, unknown> = {}
|
||||
|
||||
for (const [key, value] of Object.entries(agents)) {
|
||||
const displayName = getAgentListDisplayName(key)
|
||||
const displayName = getAgentDisplayName(key)
|
||||
if (displayName && displayName !== key) {
|
||||
result[displayName] = value
|
||||
// Regression guard: do not also assign result[key].
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
|
||||
import { reorderAgentsByPriority } from "./agent-priority-order"
|
||||
import { getAgentListDisplayName } from "../shared/agent-display-names"
|
||||
import { getAgentDisplayName } from "../shared/agent-display-names"
|
||||
|
||||
describe("reorderAgentsByPriority", () => {
|
||||
test("moves core agents to canonical order and injects runtime order fields", () => {
|
||||
// given
|
||||
const sisyphus = getAgentListDisplayName("sisyphus")
|
||||
const hephaestus = getAgentListDisplayName("hephaestus")
|
||||
const prometheus = getAgentListDisplayName("prometheus")
|
||||
const atlas = getAgentListDisplayName("atlas")
|
||||
const oracle = getAgentListDisplayName("oracle")
|
||||
const sisyphus = getAgentDisplayName("sisyphus")
|
||||
const hephaestus = getAgentDisplayName("hephaestus")
|
||||
const prometheus = getAgentDisplayName("prometheus")
|
||||
const atlas = getAgentDisplayName("atlas")
|
||||
const oracle = getAgentDisplayName("oracle")
|
||||
|
||||
const agents: Record<string, unknown> = {
|
||||
[oracle]: { name: "oracle", mode: "subagent" },
|
||||
@@ -59,8 +59,8 @@ describe("reorderAgentsByPriority", () => {
|
||||
|
||||
test("leaves non-object agent configs untouched while still reordering keys", () => {
|
||||
// given
|
||||
const sisyphus = getAgentListDisplayName("sisyphus")
|
||||
const atlas = getAgentListDisplayName("atlas")
|
||||
const sisyphus = getAgentDisplayName("sisyphus")
|
||||
const atlas = getAgentDisplayName("atlas")
|
||||
|
||||
const agents: Record<string, unknown> = {
|
||||
[atlas]: "atlas-config",
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { getAgentListDisplayName } from "../shared/agent-display-names";
|
||||
import { getAgentDisplayName } from "../shared/agent-display-names";
|
||||
|
||||
const CORE_AGENT_ORDER: ReadonlyArray<{ displayName: string; order: number }> = [
|
||||
{ displayName: getAgentListDisplayName("sisyphus"), order: 1 },
|
||||
{ displayName: getAgentListDisplayName("hephaestus"), order: 2 },
|
||||
{ displayName: getAgentListDisplayName("prometheus"), order: 3 },
|
||||
{ displayName: getAgentListDisplayName("atlas"), order: 4 },
|
||||
{ displayName: getAgentDisplayName("sisyphus"), order: 1 },
|
||||
{ displayName: getAgentDisplayName("hephaestus"), order: 2 },
|
||||
{ displayName: getAgentDisplayName("prometheus"), order: 3 },
|
||||
{ displayName: getAgentDisplayName("atlas"), order: 4 },
|
||||
];
|
||||
|
||||
function injectOrderField(
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { PluginComponents } from "./plugin-components-loader";
|
||||
import { applyCommandConfig } from "./command-config-handler";
|
||||
import {
|
||||
getAgentDisplayName,
|
||||
getAgentListDisplayName,
|
||||
getAgentDisplayName,
|
||||
} from "../shared/agent-display-names";
|
||||
|
||||
function createPluginComponents(): PluginComponents {
|
||||
@@ -122,7 +122,7 @@ describe("applyCommandConfig", () => {
|
||||
|
||||
// then
|
||||
const commandConfig = config.command as Record<string, { agent?: string }>;
|
||||
expect(commandConfig["start-work"]?.agent).toBe(getAgentListDisplayName("atlas"));
|
||||
expect(commandConfig["start-work"]?.agent).toBe(getAgentDisplayName("atlas"));
|
||||
});
|
||||
|
||||
test("normalizes legacy display-name command agents to the exported list key", async () => {
|
||||
@@ -147,6 +147,6 @@ describe("applyCommandConfig", () => {
|
||||
|
||||
// then
|
||||
const commandConfig = config.command as Record<string, { agent?: string }>;
|
||||
expect(commandConfig["start-work"]?.agent).toBe(getAgentListDisplayName("atlas"));
|
||||
expect(commandConfig["start-work"]?.agent).toBe(getAgentDisplayName("atlas"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { OhMyOpenCodeConfig } from "../config";
|
||||
import {
|
||||
getAgentConfigKey,
|
||||
getAgentListDisplayName,
|
||||
getAgentDisplayName,
|
||||
} from "../shared/agent-display-names";
|
||||
import {
|
||||
loadUserCommands,
|
||||
@@ -99,7 +99,7 @@ export async function applyCommandConfig(params: {
|
||||
function remapCommandAgentFields(commands: Record<string, Record<string, unknown>>): void {
|
||||
for (const cmd of Object.values(commands)) {
|
||||
if (cmd?.agent && typeof cmd.agent === "string") {
|
||||
cmd.agent = getAgentListDisplayName(getAgentConfigKey(cmd.agent));
|
||||
cmd.agent = getAgentDisplayName(getAgentConfigKey(cmd.agent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { describe, test, expect, spyOn, beforeEach, afterEach } from "bun:test"
|
||||
import { resolveCategoryConfig, createConfigHandler } from "./config-handler"
|
||||
import type { CategoryConfig } from "../config/schema"
|
||||
import type { OhMyOpenCodeConfig } from "../config"
|
||||
import { getAgentDisplayName, getAgentListDisplayName } from "../shared/agent-display-names"
|
||||
import { getAgentDisplayName, getAgentDisplayName } from "../shared/agent-display-names"
|
||||
|
||||
import * as agents from "../agents"
|
||||
import * as sisyphusJunior from "../agents/sisyphus-junior"
|
||||
@@ -246,10 +246,10 @@ describe("Plan agent demote behavior", () => {
|
||||
// #then
|
||||
const keys = Object.keys(config.agent as Record<string, unknown>)
|
||||
const coreAgents = [
|
||||
getAgentListDisplayName("sisyphus"),
|
||||
getAgentListDisplayName("hephaestus"),
|
||||
getAgentListDisplayName("prometheus"),
|
||||
getAgentListDisplayName("atlas"),
|
||||
getAgentDisplayName("sisyphus"),
|
||||
getAgentDisplayName("hephaestus"),
|
||||
getAgentDisplayName("prometheus"),
|
||||
getAgentDisplayName("atlas"),
|
||||
]
|
||||
const ordered = keys.filter((key) => coreAgents.includes(key))
|
||||
expect(ordered).toEqual(coreAgents)
|
||||
@@ -294,10 +294,10 @@ describe("Plan agent demote behavior", () => {
|
||||
reorderSpy.mock.calls.at(0)?.[0] as Record<string, unknown>
|
||||
)
|
||||
expect(assembledAgentKeys.slice(0, 4)).toEqual([
|
||||
getAgentListDisplayName("sisyphus"),
|
||||
getAgentListDisplayName("hephaestus"),
|
||||
getAgentListDisplayName("prometheus"),
|
||||
getAgentListDisplayName("atlas"),
|
||||
getAgentDisplayName("sisyphus"),
|
||||
getAgentDisplayName("hephaestus"),
|
||||
getAgentDisplayName("prometheus"),
|
||||
getAgentDisplayName("atlas"),
|
||||
])
|
||||
})
|
||||
|
||||
@@ -336,7 +336,7 @@ describe("Plan agent demote behavior", () => {
|
||||
expect(agents.plan).toBeDefined()
|
||||
expect(agents.plan.mode).toBe("subagent")
|
||||
expect(agents.plan.prompt).toBeUndefined()
|
||||
expect(agents[getAgentListDisplayName("prometheus")]?.prompt).toBeDefined()
|
||||
expect(agents[getAgentDisplayName("prometheus")]?.prompt).toBeDefined()
|
||||
})
|
||||
|
||||
test("plan agent remains unchanged when planner is disabled", async () => {
|
||||
@@ -370,7 +370,7 @@ describe("Plan agent demote behavior", () => {
|
||||
|
||||
// #then - plan is not touched, prometheus is not created
|
||||
const agents = config.agent as Record<string, { mode?: string; name?: string; prompt?: string }>
|
||||
expect(agents[getAgentListDisplayName("prometheus")]).toBeUndefined()
|
||||
expect(agents[getAgentDisplayName("prometheus")]).toBeUndefined()
|
||||
expect(agents.plan).toBeDefined()
|
||||
expect(agents.plan.mode).toBe("primary")
|
||||
expect(agents.plan.prompt).toBe("original plan prompt")
|
||||
@@ -401,7 +401,7 @@ describe("Plan agent demote behavior", () => {
|
||||
|
||||
// then
|
||||
const agents = config.agent as Record<string, { mode?: string }>
|
||||
const prometheusKey = getAgentListDisplayName("prometheus")
|
||||
const prometheusKey = getAgentDisplayName("prometheus")
|
||||
expect(agents[prometheusKey]).toBeDefined()
|
||||
expect(agents[prometheusKey].mode).toBe("all")
|
||||
})
|
||||
@@ -437,7 +437,7 @@ describe("Agent permission defaults", () => {
|
||||
|
||||
// #then
|
||||
const agentConfig = config.agent as Record<string, { permission?: Record<string, string> }>
|
||||
const hephaestusKey = getAgentListDisplayName("hephaestus")
|
||||
const hephaestusKey = getAgentDisplayName("hephaestus")
|
||||
expect(agentConfig[hephaestusKey]).toBeDefined()
|
||||
expect(agentConfig[hephaestusKey].permission?.task).toBe("allow")
|
||||
})
|
||||
@@ -779,7 +779,7 @@ describe("Prometheus direct override priority over category", () => {
|
||||
|
||||
// then - direct override's reasoningEffort wins
|
||||
const agents = config.agent as Record<string, { reasoningEffort?: string }>
|
||||
const pKey = getAgentListDisplayName("prometheus")
|
||||
const pKey = getAgentDisplayName("prometheus")
|
||||
expect(agents[pKey]).toBeDefined()
|
||||
expect(agents[pKey].reasoningEffort).toBe("low")
|
||||
})
|
||||
@@ -820,7 +820,7 @@ describe("Prometheus direct override priority over category", () => {
|
||||
|
||||
// then - category's reasoningEffort is applied
|
||||
const agents = config.agent as Record<string, { reasoningEffort?: string }>
|
||||
const pKey = getAgentListDisplayName("prometheus")
|
||||
const pKey = getAgentDisplayName("prometheus")
|
||||
expect(agents[pKey]).toBeDefined()
|
||||
expect(agents[pKey].reasoningEffort).toBe("high")
|
||||
})
|
||||
@@ -862,7 +862,7 @@ describe("Prometheus direct override priority over category", () => {
|
||||
|
||||
// then - direct temperature wins over category
|
||||
const agents = config.agent as Record<string, { temperature?: number }>
|
||||
const pKey = getAgentListDisplayName("prometheus")
|
||||
const pKey = getAgentDisplayName("prometheus")
|
||||
expect(agents[pKey]).toBeDefined()
|
||||
expect(agents[pKey].temperature).toBe(0.1)
|
||||
})
|
||||
@@ -898,7 +898,7 @@ describe("Prometheus direct override priority over category", () => {
|
||||
|
||||
// #then - prompt_append is appended to base prompt, not overwriting it
|
||||
const agents = config.agent as Record<string, { prompt?: string }>
|
||||
const pKey = getAgentListDisplayName("prometheus")
|
||||
const pKey = getAgentDisplayName("prometheus")
|
||||
expect(agents[pKey]).toBeDefined()
|
||||
expect(agents[pKey].prompt).toContain("Prometheus")
|
||||
expect(agents[pKey].prompt).toContain(customInstructions)
|
||||
@@ -1290,18 +1290,18 @@ describe("command agent routing coherence", () => {
|
||||
//#then
|
||||
const agentConfig = config.agent as Record<string, unknown>
|
||||
const commandConfig = config.command as Record<string, { agent?: string }>
|
||||
expect(Object.keys(agentConfig)).toContain(getAgentListDisplayName("atlas"))
|
||||
expect(commandConfig["start-work"]?.agent).toBe(getAgentListDisplayName("atlas"))
|
||||
expect(Object.keys(agentConfig)).toContain(getAgentDisplayName("atlas"))
|
||||
expect(commandConfig["start-work"]?.agent).toBe(getAgentDisplayName("atlas"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("per-agent todowrite/todoread deny when task_system enabled", () => {
|
||||
const AGENTS_WITH_TODO_DENY = new Set([
|
||||
getAgentListDisplayName("sisyphus"),
|
||||
getAgentListDisplayName("hephaestus"),
|
||||
getAgentListDisplayName("prometheus"),
|
||||
getAgentListDisplayName("atlas"),
|
||||
getAgentListDisplayName("sisyphus-junior"),
|
||||
getAgentDisplayName("sisyphus"),
|
||||
getAgentDisplayName("hephaestus"),
|
||||
getAgentDisplayName("prometheus"),
|
||||
getAgentDisplayName("atlas"),
|
||||
getAgentDisplayName("sisyphus-junior"),
|
||||
])
|
||||
|
||||
test("denies todowrite and todoread for primary agents when task_system is enabled", async () => {
|
||||
@@ -1381,10 +1381,10 @@ describe("per-agent todowrite/todoread deny when task_system enabled", () => {
|
||||
expect(lastCall?.[11]).toBe(false)
|
||||
|
||||
const agentResult = config.agent as Record<string, { permission?: Record<string, unknown> }>
|
||||
expect(agentResult[getAgentListDisplayName("sisyphus")]?.permission?.todowrite).toBeUndefined()
|
||||
expect(agentResult[getAgentListDisplayName("sisyphus")]?.permission?.todoread).toBeUndefined()
|
||||
expect(agentResult[getAgentListDisplayName("hephaestus")]?.permission?.todowrite).toBeUndefined()
|
||||
expect(agentResult[getAgentListDisplayName("hephaestus")]?.permission?.todoread).toBeUndefined()
|
||||
expect(agentResult[getAgentDisplayName("sisyphus")]?.permission?.todowrite).toBeUndefined()
|
||||
expect(agentResult[getAgentDisplayName("sisyphus")]?.permission?.todoread).toBeUndefined()
|
||||
expect(agentResult[getAgentDisplayName("hephaestus")]?.permission?.todowrite).toBeUndefined()
|
||||
expect(agentResult[getAgentDisplayName("hephaestus")]?.permission?.todoread).toBeUndefined()
|
||||
})
|
||||
|
||||
test("does not deny todowrite/todoread when task_system is undefined", async () => {
|
||||
@@ -1420,8 +1420,8 @@ describe("per-agent todowrite/todoread deny when task_system enabled", () => {
|
||||
expect(lastCall?.[11]).toBe(false)
|
||||
|
||||
const agentResult = config.agent as Record<string, { permission?: Record<string, unknown> }>
|
||||
expect(agentResult[getAgentListDisplayName("sisyphus")]?.permission?.todowrite).toBeUndefined()
|
||||
expect(agentResult[getAgentListDisplayName("sisyphus")]?.permission?.todoread).toBeUndefined()
|
||||
expect(agentResult[getAgentDisplayName("sisyphus")]?.permission?.todowrite).toBeUndefined()
|
||||
expect(agentResult[getAgentDisplayName("sisyphus")]?.permission?.todoread).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { OhMyOpenCodeConfig } from "../config";
|
||||
import { getAgentDisplayName, getAgentListDisplayName } from "../shared/agent-display-names";
|
||||
import { getAgentDisplayName } from "../shared/agent-display-names";
|
||||
import { isTaskSystemEnabled } from "../shared";
|
||||
|
||||
type AgentWithPermission = { permission?: Record<string, unknown> };
|
||||
@@ -16,7 +16,7 @@ function getConfigQuestionPermission(): string | null {
|
||||
}
|
||||
|
||||
function agentByKey(agentResult: Record<string, unknown>, key: string): AgentWithPermission | undefined {
|
||||
return (agentResult[getAgentListDisplayName(key)] ?? agentResult[getAgentDisplayName(key)] ?? agentResult[key]) as
|
||||
return (agentResult[getAgentDisplayName(key)] ?? agentResult[key]) as
|
||||
| AgentWithPermission
|
||||
| undefined;
|
||||
}
|
||||
|
||||
@@ -57,6 +57,13 @@ export function getAgentDisplayName(configKey: string): string {
|
||||
return configKey
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Do NOT use for config.agent keys or API-facing names.
|
||||
* ZWSP prefixes leak into the /agent API response and break prompt_async consumers.
|
||||
* Use getAgentDisplayName() instead. The `order` field injected by
|
||||
* reorderAgentsByPriority() handles sort ordering without invisible characters.
|
||||
* See: https://github.com/code-yeongyu/oh-my-openagent/issues/3238
|
||||
*/
|
||||
export function getAgentListDisplayName(configKey: string): string {
|
||||
const displayName = getAgentDisplayName(configKey)
|
||||
const prefix = AGENT_LIST_SORT_PREFIXES[configKey.toLowerCase()]
|
||||
|
||||
Reference in New Issue
Block a user