feat(config): add configurable agent ordering
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user