fix(agents): address all PR #2299 code review findings
Blocking fixes: - B1: Return empty restrictions for unknown/custom agents instead of EXPLORATION_AGENT_DENYLIST, allowing custom agents full tool access - B2: Use Object.create(null) consistently across all 5 agent-loading result objects to prevent prototype pollution - B3: Add code comment documenting custom agent bash access trust model - B4: Mock getOpenCodeConfigDir in opencode-config-agents-reader tests to prevent global config dir leakage Non-blocking fixes: - N1: Use resolveAgentDefinitionPaths with project boundary enforcement in opencode-config-agents-reader for path containment - N2: Add session-scoped 30s TTL cache to resolveCallableAgents to avoid redundant SDK IPC calls per tool invocation - N3: Extract shared parseToolsConfig into src/shared/parse-tools-config.ts replacing 4 duplicated local implementations - N4: Add .min(1) to AgentDefinitionPathSchema rejecting empty paths - N5: Add resolve-agent-definition-paths.test.ts covering tilde expansion, relative paths, boundary enforcement, and null containmentDir - N6: Validate agent mode against allowed values instead of bare type assertion in opencode-config-agents-reader
This commit is contained in:
@@ -1,23 +1,9 @@
|
||||
import { existsSync, readFileSync } from "fs"
|
||||
import { parseJsoncSafe } from "../../shared/jsonc-parser"
|
||||
import { parseToolsConfig } from "../../shared/parse-tools-config"
|
||||
import { mapClaudeModelToOpenCode } from "./claude-model-mapper"
|
||||
import type { AgentScope, AgentJsonDefinition, ClaudeCodeAgentConfig, LoadedAgent } from "./types"
|
||||
|
||||
function parseToolsConfig(tools?: string | string[]): Record<string, boolean> | undefined {
|
||||
if (!tools) return undefined
|
||||
|
||||
const toolsArray = Array.isArray(tools) ? tools : tools.split(",").map((t) => t.trim())
|
||||
const filtered = toolsArray.filter((t) => typeof t === "string" && t.length > 0)
|
||||
|
||||
if (filtered.length === 0) return undefined
|
||||
|
||||
const result: Record<string, boolean> = {}
|
||||
for (const tool of filtered) {
|
||||
result[tool.toLowerCase()] = true
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export function parseJsonAgentFile(filePath: string, scope: AgentScope): LoadedAgent | null {
|
||||
try {
|
||||
if (!existsSync(filePath)) {
|
||||
|
||||
Reference in New Issue
Block a user