refactor(hooks): extract shared isOrchestratorAgent utility to avoid duplication

This commit is contained in:
YeonGyu-Kim
2026-02-28 13:32:09 +09:00
parent 35edcecd8f
commit 4f8286c561
4 changed files with 26 additions and 45 deletions

View File

@@ -6,8 +6,7 @@ import {
} from "./storage";
import { TARGET_TOOLS, AGENT_TOOLS, REMINDER_MESSAGE } from "./constants";
import type { AgentUsageState } from "./types";
import { getSessionAgent } from "../../features/claude-code-session-state";
import { getAgentConfigKey } from "../../shared/agent-display-names";
import { isOrchestratorAgent } from "../../shared/orchestrator-agents";
interface ToolExecuteInput {
tool: string;
@@ -28,23 +27,6 @@ interface EventInput {
};
}
/**
* Only orchestrator agents should receive usage reminders.
* Subagents (explore, librarian, oracle, etc.) are the targets of delegation,
* so reminding them to delegate to themselves is counterproductive.
*/
const ORCHESTRATOR_AGENTS = new Set([
"sisyphus",
"sisyphus-junior",
"atlas",
"hephaestus",
"prometheus",
]);
function isOrchestratorAgent(agentName: string): boolean {
return ORCHESTRATOR_AGENTS.has(getAgentConfigKey(agentName));
}
export function createAgentUsageReminderHook(_ctx: PluginInput) {
const sessionStates = new Map<string, AgentUsageState>();
@@ -80,8 +62,7 @@ export function createAgentUsageReminderHook(_ctx: PluginInput) {
) => {
const { tool, sessionID } = input;
const agent = getSessionAgent(sessionID);
if (agent && !isOrchestratorAgent(agent)) {
if (!isOrchestratorAgent(sessionID)) {
return;
}

View File

@@ -1,20 +1,9 @@
import type { PluginInput } from "@opencode-ai/plugin"
import type { AvailableSkill } from "../../agents/dynamic-agent-prompt-builder"
import { getSessionAgent } from "../../features/claude-code-session-state"
import { log } from "../../shared"
import { getAgentConfigKey } from "../../shared/agent-display-names"
import { isOrchestratorAgent } from "../../shared/orchestrator-agents"
import { buildReminderMessage } from "./formatter"
/**
* Target agents that should receive category+skill reminders.
* These are orchestrator agents that delegate work to specialized agents.
*/
const TARGET_AGENTS = new Set([
"sisyphus",
"sisyphus-junior",
"atlas",
])
/**
* Tools that indicate the agent is doing work that could potentially be delegated.
* When these tools are used, we remind the agent about the category+skill system.
@@ -73,22 +62,11 @@ export function createCategorySkillReminderHook(
return sessionStates.get(sessionID)!
}
function isTargetAgent(sessionID: string, inputAgent?: string): boolean {
const agent = getSessionAgent(sessionID) ?? inputAgent
if (!agent) return false
const agentKey = getAgentConfigKey(agent)
return (
TARGET_AGENTS.has(agentKey) ||
agentKey.includes("sisyphus") ||
agentKey.includes("atlas")
)
}
const toolExecuteAfter = async (input: ToolExecuteInput, output: ToolExecuteOutput) => {
const { tool, sessionID } = input
const toolLower = tool.toLowerCase()
if (!isTargetAgent(sessionID, input.agent)) {
if (!isOrchestratorAgent(sessionID, input.agent)) {
return
}

View File

@@ -32,6 +32,7 @@ export * from "./session-cursor"
export * from "./shell-env"
export * from "./system-directive"
export * from "./agent-tool-restrictions"
export * from "./orchestrator-agents"
export * from "./model-requirements"
export * from "./model-resolver"
export { normalizeFallbackModels } from "./model-resolver"

View File

@@ -0,0 +1,21 @@
import { getSessionAgent } from "../features/claude-code-session-state"
import { getAgentConfigKey } from "./agent-display-names"
export const ORCHESTRATOR_AGENTS = new Set([
"sisyphus",
"sisyphus-junior",
"atlas",
"hephaestus",
"prometheus",
])
export function isOrchestratorAgent(sessionID: string, inputAgent?: string): boolean {
const agent = getSessionAgent(sessionID) ?? inputAgent
if (!agent) return true
const agentKey = getAgentConfigKey(agent)
return (
ORCHESTRATOR_AGENTS.has(agentKey) ||
agentKey.includes("sisyphus") ||
agentKey.includes("atlas")
)
}