multica/src/agent/tools/groups.ts
yushen 9cc89cf297 feat(subagent): add sessions_list tool for viewing spawned sub-tasks
Adds a new `sessions_list` tool to the Subagent tool group, allowing
agents to query the status of their spawned sub-tasks. Supports both
list mode (all runs) and detail mode (specific runId).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 17:58:22 +08:00

98 lines
2.2 KiB
TypeScript

/**
* Tool groups for policy-based filtering.
*
* Groups provide shortcuts for allowing/denying multiple tools at once.
* Use "group:name" in allow/deny lists.
*/
/**
* Tool name aliases for compatibility.
* Maps alternative names to canonical tool names.
*/
export const TOOL_NAME_ALIASES: Record<string, string> = {
bash: "exec",
shell: "exec",
search: "web_search",
fetch: "web_fetch",
};
/**
* Tool groups - shortcuts for multiple tools.
* Use "group:name" in allow/deny lists.
*/
export const TOOL_GROUPS: Record<string, string[]> = {
// File system operations
"group:fs": ["read", "write", "edit", "glob"],
// Runtime/execution tools
"group:runtime": ["exec", "process"],
// Web tools
"group:web": ["web_search", "web_fetch"],
// Memory tools (requires profile)
"group:memory": ["memory_search"],
// Subagent tools
"group:subagent": ["sessions_spawn", "sessions_list"],
// Cron/scheduling tools
"group:cron": ["cron"],
// All core tools
"group:core": [
"read",
"write",
"edit",
"glob",
"exec",
"process",
"web_search",
"web_fetch",
],
};
/**
* Default tools denied for subagents.
* Subagents should not have access to session management or system tools.
*/
export const DEFAULT_SUBAGENT_TOOL_DENY: string[] = [
// Subagents cannot spawn subagents (no nested spawning)
"sessions_spawn",
];
/**
* Normalize a tool name to its canonical form.
*/
export function normalizeToolName(name: string): string {
const normalized = name.trim().toLowerCase();
return TOOL_NAME_ALIASES[normalized] ?? normalized;
}
/**
* Normalize a list of tool names.
*/
export function normalizeToolList(list?: string[]): string[] {
if (!list) return [];
return list.map(normalizeToolName).filter(Boolean);
}
/**
* Expand group references in a tool list.
* "group:fs" -> ["read", "write", "edit", "glob"]
*/
export function expandToolGroups(list?: string[]): string[] {
const normalized = normalizeToolList(list);
const expanded: string[] = [];
for (const value of normalized) {
const group = TOOL_GROUPS[value];
if (group) {
expanded.push(...group);
continue;
}
expanded.push(value);
}
return Array.from(new Set(expanded));
}