feat(config): add configurable agent ordering

This commit is contained in:
YeonGyu-Kim
2026-05-08 16:08:18 +09:00
parent 8667d7e5b8
commit 9522dd4ca4
16 changed files with 400 additions and 57 deletions
+11 -28
View File
@@ -1,35 +1,16 @@
import { getAgentListDisplayName } from "../shared/agent-display-names"
import { DEFAULT_AGENT_ORDER, resolveAgentOrderDisplayNames } from "../shared/agent-ordering"
/**
* CRITICAL: This is the ONLY source of truth for core agent ordering.
* The order is: sisyphus → hephaestus → prometheus → atlas
* Default source of truth for core agent ordering.
* The default order is: sisyphus → hephaestus → prometheus → atlas.
*
* DO NOT CHANGE THIS ORDER. Any PR attempting to modify this order
* or introduce alternative ordering mechanisms (ZWSP prefixes, sort
* shims, etc.) will be rejected.
* User config may override the runtime order through `agent_order`; missing
* core agents still fall back to this default order. Do not reintroduce sort
* key prefixes or a second ordering constant.
*
* See: src/plugin-handlers/AGENTS.md for architectural context.
*/
export const CANONICAL_CORE_AGENT_ORDER = [
"sisyphus",
"hephaestus",
"prometheus",
"atlas",
] as const
type CoreAgentName = (typeof CANONICAL_CORE_AGENT_ORDER)[number]
const CORE_AGENT_ORDER: ReadonlyArray<{
configKey: CoreAgentName
displayName: string
order: number
}> = CANONICAL_CORE_AGENT_ORDER.map((configKey, index) => ({
configKey,
displayName: getAgentListDisplayName(configKey),
order: index + 1,
}))
const CORE_DISPLAY_NAMES = new Set(CORE_AGENT_ORDER.map((a) => a.displayName))
export const CANONICAL_CORE_AGENT_ORDER = DEFAULT_AGENT_ORDER
function injectOrderField(agentConfig: unknown, order: number): unknown {
if (typeof agentConfig === "object" && agentConfig !== null) {
@@ -40,13 +21,15 @@ function injectOrderField(agentConfig: unknown, order: number): unknown {
export function reorderAgentsByPriority(
agents: Record<string, unknown>,
agentOrder?: readonly string[],
): Record<string, unknown> {
const ordered: Record<string, unknown> = {}
const seen = new Set<string>()
const orderedDisplayNames = resolveAgentOrderDisplayNames(agentOrder)
for (const { displayName, order } of CORE_AGENT_ORDER) {
for (const [index, displayName] of orderedDisplayNames.entries()) {
if (Object.prototype.hasOwnProperty.call(agents, displayName)) {
ordered[displayName] = injectOrderField(agents[displayName], order)
ordered[displayName] = injectOrderField(agents[displayName], index + 1)
seen.add(displayName)
}
}