UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

294 lines (293 loc) • 29 kB
import { TASK_STOP_CONTRACT } from "./task-tool-shape.js"; export const FULL_SHELL_CONTRACT_ID = "core.bash@1"; export const READONLY_SHELL_CONTRACT_ID = "core.bash_readonly@1"; export const TASK_CREATE_TOOL_NAME = "TaskCreate"; export const TASK_GET_TOOL_NAME = "TaskGet"; export const TASK_UPDATE_TOOL_NAME = "TaskUpdate"; export const TASK_LIST_TOOL_NAME = "TaskList"; export const TODO_WRITE_TOOL_NAME = "TodoWrite"; export const OUTPUT_TOOL_NAME = "StructuredOutput"; export const REFRESH_MCP_TOOLS_TOOL_NAME = "RefreshMcpTools"; export const ARTIFACT_TOOL_NAME = "Artifact"; const shellRuleFace = (params) => ({ grammar: "command", primaryParams: ["command"], params }); const SHELL_RULE_FACE = shellRuleFace(["command", "timeout", "description", "run_in_background"]); const c = (contractId, implementationRevision = "1") => ({ contractId, implementationRevision }); export const TOOL_CATALOG_ENTRIES = [ { id: "read", name: "Read", source: "builtin", definedIn: "src/tools/fs/fs-read.ts", mountedBy: ["hands"], cards: ["text", "notebook", "image", "document"], face: { family: "file-read", boundaryLegs: ["env"], effect: "read", contract: c("core.read@1", "2"), pathTarget: { param: "file_path", aliases: ["path"], access: "read", base: "cwd", absent: "none" }, ruleFace: { params: ["file_path", "path", "offset", "limit", "pages", "allow_large"] }, renderHints: { summaryParams: ["file_path"] }, offload: false, compactable: true, budgetExempt: true, }, }, { id: "edit", name: "Edit", source: "builtin", definedIn: "src/tools/fs/fs-write.ts", mountedBy: ["hands"], cards: ["edit", "create"], face: { family: "file-write", boundaryLegs: ["env"], effect: "write", contract: c("core.edit@1"), pathTarget: { param: "file_path", aliases: ["path"], access: "edit", skillScopeEligible: true, base: "cwd", absent: "none" }, ruleFace: { params: ["file_path", "path", "old_string", "new_string", "replace_all"] }, renderHints: { summaryParams: ["file_path"], approvalCard: "file-edit" }, compactable: true, }, }, { id: "write", name: "Write", source: "builtin", definedIn: "src/tools/fs/fs-write.ts", mountedBy: ["hands"], cards: ["create", "update"], face: { family: "file-write", boundaryLegs: ["env"], effect: "write", contract: c("core.write@1"), pathTarget: { param: "file_path", aliases: ["path"], access: "create", skillScopeEligible: true, base: "cwd", absent: "none" }, ruleFace: { params: ["file_path", "path", "content"] }, renderHints: { summaryParams: ["file_path"], approvalCard: "file-write" }, offload: false, compactable: true, }, }, { id: "notebook-edit", name: "NotebookEdit", source: "builtin", definedIn: "src/tools/fs/fs-write.ts", mountedBy: ["hands"], cards: ["notebook-edit"], face: { family: "file-write", boundaryLegs: ["env"], effect: "write", contract: c("core.notebook_edit@1"), pathTarget: { param: "notebook_path", aliases: ["path"], access: "edit", base: "cwd", absent: "none" }, ruleFace: { params: ["notebook_path", "path", "cell_id", "cell_type", "edit_mode", "new_source"] }, renderHints: { userFacingName: "Edit Notebook", summaryParams: ["notebook_path"], approvalCard: "notebook-edit" }, }, }, { id: "save-tool-result", name: "SaveToolResult", source: "builtin", definedIn: "src/tools/fs/fs-write.ts", mountedBy: ["hands"], cards: [], writtenContent: "kept", face: { family: "file-write", boundaryLegs: ["env"], effect: "write", contract: c("core.save_tool_result@1"), pathTarget: { param: "file_path", aliases: ["path"], access: "create", base: "cwd", absent: "none" }, ruleFace: { params: ["ref", "file_path", "path"] }, renderHints: { summaryParams: ["file_path"], approvalCard: "generic" }, }, }, { id: "bash", name: "Bash", source: "builtin", definedIn: "src/tools/fs/fs-bash.ts", mountedBy: ["hands"], cards: ["bash", "readonly_out_of_root", "read_unestablished", "bash_invalid_timeout", "bash_self_kill_refused"], face: { family: "shell", boundaryLegs: ["env"], effect: "write", contentOrigin: "execution", contract: c(FULL_SHELL_CONTRACT_ID), ruleFace: SHELL_RULE_FACE, renderHints: { summaryParams: ["command"], approvalCard: "shell" }, offloadThresholdChars: 30_000, compactable: true, }, }, { id: "bash-readonly", name: "Bash", source: "builtin", definedIn: "src/tools/fs/fs-bash.ts", mountedBy: ["hands"], cards: ["bash", "readonly_out_of_root", "read_unestablished", "bash_invalid_timeout"], face: { family: "shell", boundaryLegs: ["env"], effect: "read", contract: c(READONLY_SHELL_CONTRACT_ID), ruleFace: SHELL_RULE_FACE, renderHints: { summaryParams: ["command"], approvalCard: "shell" }, offloadThresholdChars: 30_000, compactable: true, }, }, { id: "grep", name: "Grep", source: "builtin", definedIn: "src/tools/fs/fs-search-tools.ts", mountedBy: ["hands"], cards: ["grep"], face: { family: "search", boundaryLegs: ["env"], effect: "read", contract: c("core.grep@1"), pathTarget: { param: "path", access: "read", base: "root", absent: "base" }, ruleFace: { params: ["pattern", "path", "glob", "type", "output_mode", "head_limit", "offset", "multiline", "context", "ignore_case", "-i", "-n", "-o", "-A", "-B", "-C"] }, renderHints: { userFacingName: "Search", summaryParams: ["pattern", "path"] }, offloadThresholdChars: 20_000, compactable: true, }, }, { id: "glob", name: "Glob", source: "builtin", definedIn: "src/tools/fs/fs-search-tools.ts", mountedBy: ["hands"], cards: ["glob"], face: { family: "search", boundaryLegs: ["env"], effect: "read", contract: c("core.glob@1"), pathTarget: { param: "path", access: "read", base: "root", absent: "base", patternParam: "pattern" }, ruleFace: { params: ["pattern", "path", "max_results"] }, renderHints: { userFacingName: "Search", summaryParams: ["pattern", "path"] }, compactable: true, }, }, { id: "repo-map", name: "RepoMap", source: "builtin", definedIn: "src/tools/fs/repo-map.ts", mountedBy: ["hands"], cards: ["repo-map"], face: { family: "search", boundaryLegs: ["env"], effect: "read", contract: c("core.repo_map@1"), pathTarget: { param: "path", access: "read", base: "root", absent: "base" }, ruleFace: { params: ["path", "max_chars", "max_files"] }, }, }, { id: "lsp", name: "LSP", source: "builtin", definedIn: "src/core/lsp.ts", mountedBy: ["hands"], cards: [], face: { family: "search", boundaryLegs: ["env"], effect: "read", contract: c("core.lsp@1"), pathTarget: { param: "filePath", access: "read", base: "cwd", absent: "none" }, ruleFace: { params: ["operation", "filePath", "line", "character", "query"] }, }, }, { id: "artifact", name: ARTIFACT_TOOL_NAME, source: "builtin", definedIn: "src/tools/artifact/artifact-tool.ts", mountedBy: ["optional"], cards: ["artifact"], face: { family: "other", boundaryLegs: "per_call", effect: "write", contract: c("core.artifact@1"), ruleFace: { primaryParams: ["action"], params: ["action", "file_path", "url", "title", "description", "favicon", "label", "baseVersion", "force", "publishContext", "scope", "limit", "path"] }, renderHints: { summaryParams: ["action", "file_path", "url"] } }, }, { id: "enter-worktree", name: "EnterWorktree", source: "builtin", definedIn: "src/tools/worktree.ts", mountedBy: ["hands"], cards: ["worktree"], face: { family: "other", boundaryLegs: ["env"], effect: "write", contract: c("core.enter_worktree@1"), ruleFace: { params: ["name", "path", "baseRef"] } } }, { id: "exit-worktree", name: "ExitWorktree", source: "builtin", definedIn: "src/tools/worktree.ts", mountedBy: ["hands"], cards: ["worktree"], face: { family: "other", boundaryLegs: ["env"], effect: "write", contract: c("core.exit_worktree@1"), ruleFace: { params: ["keep", "discardChanges", "action", "discard_changes"] } } }, { id: "task-stop", name: "TaskStop", source: "builtin", definedIn: "src/core/task-registry.ts", mountedBy: ["hands", "delegation"], cards: ["task-stop"], face: { family: "delegate", boundaryLegs: "per_call", effect: "write", contract: TASK_STOP_CONTRACT, ruleFace: { params: ["task_id", "shell_id"] } } }, { id: "monitor", name: "Monitor", source: "builtin", definedIn: "src/tools/monitor.ts", mountedBy: ["backgroundTasks"], cards: ["monitor-start", "readonly_out_of_root", "read_unestablished"], face: { family: "other", boundaryLegs: ["env"], effect: "write", contract: c("core.monitor@1"), ruleFace: shellRuleFace(["command", "description", "timeout_ms", "persistent"]), offloadThresholdChars: 10_000 } }, { id: "send-message", name: "SendMessage", protocol: ["teammate"], source: "builtin", definedIn: "src/agents/send-message-tool.ts", mountedBy: ["delegation", "hostInternals", "peerLane"], cards: ["send-message"], face: { family: "protocol", boundaryLegs: ["outside_write"], effect: "write", contract: c("core.send_message@1"), ruleFace: { params: ["to", "message", "summary", "notify_when_idle", "urgent"] } } }, { id: "agent-transcript", name: "AgentTranscript", source: "builtin", definedIn: "src/agents/agent-transcript-tool.ts", mountedBy: ["delegation"], cards: ["agent-transcript"], face: { family: "delegate", boundaryLegs: [], effect: "read", contract: c("core.agent_transcript@1"), ruleFace: { params: ["id", "lastN"] } } }, { id: "list-agents", name: "ListAgents", source: "builtin", definedIn: "src/agents/list-agents-tool.ts", mountedBy: ["delegation", "peerLane"], cards: ["list-agents"], face: { family: "protocol", boundaryLegs: [], effect: "read", aliases: ["ListPeers"], contract: c("core.list_agents@1"), ruleFace: { params: ["includeAll"] } } }, { id: "read-inbox", name: "ReadInbox", source: "builtin", definedIn: "src/agents/read-inbox-tool.ts", mountedBy: ["peerLane"], cards: ["read-inbox"], face: { family: "protocol", boundaryLegs: [], effect: "read", contract: c("core.read_inbox@1"), offload: false, budgetExempt: true, ruleFace: { params: ["limit"] } } }, { id: "send-user-message", name: "SendUserMessage", source: "builtin", definedIn: "src/agents/send-user-message-tool.ts", mountedBy: ["optional"], cards: ["send-user-message"], face: { family: "other", boundaryLegs: "per_call", effect: "read", contract: c("core.send_user_message@1", "2"), offload: false, ruleFace: { params: ["message", "status"] } } }, { id: "workflow", name: "Workflow", source: "builtin", definedIn: "src/orchestration/run-workflow-tool.ts", mountedBy: ["workflow"], cards: ["workflow-run"], face: { family: "delegate", boundaryLegs: [], effect: "write", contract: c("core.workflow@1"), renderHints: { approvalCard: "workflow" }, ruleFace: { params: ["script", "name", "scriptPath", "resumeFromRunId"] } } }, { id: "report-blocked", name: "ReportBlocked", protocol: ["delegated"], verdict: "blocked", source: "builtin", definedIn: "src/core/runner/synthetic-tools.ts", mountedBy: ["always"], cards: [], face: { family: "scaffold", boundaryLegs: [], effect: "read", contract: c("core.report_blocked@1"), ruleFace: { params: ["reason"] } } }, { id: "report-findings", name: "ReportFindings", source: "builtin", definedIn: "src/core/runner/synthetic-tools.ts", mountedBy: ["always"], cards: ["report-findings"], face: { family: "scaffold", boundaryLegs: [], effect: "read", contract: c("core.report_findings@1"), ruleFace: { params: ["level"] } } }, { id: "structured-output", name: OUTPUT_TOOL_NAME, protocol: ["structured"], verdict: "result", source: "synthetic", definedIn: "src/core/runner/synthetic-tools.ts", mountedBy: ["optional"], cards: [], face: { family: "scaffold", boundaryLegs: [], effect: "read", contract: c("core.structured_output@1") } }, { id: "skill", name: "Skill", source: "builtin", definedIn: "src/core/runner/synthetic-tools.ts", mountedBy: ["optional"], cards: [], face: { family: "scaffold", boundaryLegs: [], effect: "read", contract: c("core.skill@1"), renderHints: { approvalCard: "skill" }, ruleFace: { params: ["skill", "args"] } } }, { id: "read-tool-result", name: "ReadToolResult", source: "builtin", definedIn: "src/core/tool-result-store.ts", mountedBy: ["optional"], cards: [], face: { family: "scaffold", boundaryLegs: "per_call", effect: "read", contract: c("core.read_tool_result@1"), budgetExempt: true, ruleFace: { params: ["ref", "offset", "limit"] } } }, { id: "tool-search", name: "ToolSearch", source: "builtin", definedIn: "src/core/runner/tool-disclosure.ts", mountedBy: ["optional"], cards: ["tool-search"], face: { family: "scaffold", boundaryLegs: [], effect: "read", contract: c("core.tool_search@1"), ruleFace: { params: ["query", "max_results"] } } }, { id: "advisor", name: "advisor", source: "builtin", definedIn: "src/core/runner/advisor-tool.ts", mountedBy: ["optional"], cards: ["advisor"], face: { family: "scaffold", boundaryLegs: [], effect: "read", contentOrigin: "local", contract: c("core.advisor@1"), offload: false, budgetExempt: true, ruleFace: { params: [] } } }, { id: "ask-user-question", name: "AskUserQuestion", source: "builtin", definedIn: "src/core/ask-question.ts", mountedBy: ["optional"], cards: ["ask-question"], face: { family: "other", boundaryLegs: [], effect: "read", contract: c("core.ask_user_question@1"), renderHints: { approvalCard: "question" }, ruleFace: { params: [] } } }, { id: "exit-plan-mode", name: "ExitPlanMode", source: "builtin", definedIn: "src/core/present-plan-tool.ts", mountedBy: ["optional"], cards: ["exit-plan-mode"], face: { family: "plan", boundaryLegs: [], effect: "read", contract: c("core.exit_plan_mode@1"), renderHints: { userFacingName: "", approvalCard: "plan" }, ruleFace: { params: ["plan"] } } }, { id: "exit-plan-mode-file", name: "ExitPlanMode", source: "builtin", definedIn: "src/core/present-plan-tool.ts", mountedBy: ["optional"], cards: ["exit-plan-mode"], face: { family: "plan", boundaryLegs: [], effect: "read", contract: c("core.exit_plan_mode_file@1"), renderHints: { userFacingName: "", approvalCard: "plan" }, ruleFace: { params: [] } } }, { id: "enter-plan-mode", name: "EnterPlanMode", source: "builtin", definedIn: "src/core/present-plan-tool.ts", mountedBy: ["optional"], cards: ["enter-plan-mode"], face: { family: "plan", boundaryLegs: [], effect: "read", contract: c("core.enter_plan_mode@1"), ruleFace: { params: [] } } }, { id: "refresh-mcp-tools", name: REFRESH_MCP_TOOLS_TOOL_NAME, source: "builtin", definedIn: "src/core/runner/prepare-protocol-tools.ts", mountedBy: ["optional"], cards: [], face: { family: "protocol", boundaryLegs: ["outside_read"], effect: "read", ruleFace: { params: ["server"] } } }, { id: "memory-search", name: "memory_search", source: "builtin", definedIn: "src/core/memory-engine/tools.ts", mountedBy: ["memory"], cards: [], face: { family: "memory", boundaryLegs: [], effect: "read", contentOrigin: "local", contract: c("core.memory_search@1", "7"), offload: false, ruleFace: { params: ["query", "limit", "includeSuperseded", "includeShadowed"] } } }, { id: "memory-get", name: "memory_get", source: "builtin", definedIn: "src/core/memory-engine/tools.ts", mountedBy: ["memory"], cards: [], face: { family: "memory", boundaryLegs: [], effect: "read", contentOrigin: "local", contract: c("core.memory_get@1", "7"), offload: false, ruleFace: { params: ["id", "slug", "scope", "offset", "limit", "lineCursor"] } } }, { id: "memory-index", name: "memory_index", source: "builtin", definedIn: "src/core/memory-engine/tools.ts", mountedBy: ["memory"], cards: [], face: { family: "memory", boundaryLegs: [], effect: "read", contentOrigin: "local", contract: c("core.memory_index@1", "2"), offload: false, ruleFace: { params: ["offset", "limit", "listingRev", "scope", "includeSuperseded", "includeShadowed"] } } }, { id: "memory-list", name: "memory_list", source: "builtin", definedIn: "src/core/shared-memory/tools.ts", mountedBy: ["memory"], cards: [], face: { family: "memory", boundaryLegs: [], effect: "read", contract: c("core.memory_list@1"), offload: false, ruleFace: { params: ["store", "path_prefix", "cursor"] } } }, { id: "memory-read", name: "memory_read", source: "builtin", definedIn: "src/core/shared-memory/tools.ts", mountedBy: ["memory"], cards: [], face: { family: "memory", boundaryLegs: [], effect: "read", contract: c("core.memory_read@1"), offload: false, ruleFace: { params: ["store", "path"] } } }, { id: "cron-create", name: "CronCreate", protocol: ["teammate"], source: "builtin", definedIn: "src/tools/scheduler-tools.ts", mountedBy: ["scheduler"], cards: ["cron-create"], face: { family: "other", boundaryLegs: ["env"], effect: "write", contract: c("core.cron_create@1"), ruleFace: { params: ["prompt", "cron", "recurring", "durable", "label"] } } }, { id: "cron-delete", name: "CronDelete", protocol: ["teammate"], source: "builtin", definedIn: "src/tools/scheduler-tools.ts", mountedBy: ["scheduler"], cards: ["cron-delete"], face: { family: "other", boundaryLegs: ["env"], effect: "idempotent", contract: c("core.cron_delete@1"), ruleFace: { params: ["id"] } } }, { id: "cron-list", name: "CronList", protocol: ["teammate"], source: "builtin", definedIn: "src/tools/scheduler-tools.ts", mountedBy: ["scheduler"], cards: ["cron-list"], face: { family: "other", boundaryLegs: ["env"], effect: "read", contract: c("core.cron_list@1"), ruleFace: { params: [] } } }, { id: "schedule-wakeup", name: "ScheduleWakeup", source: "builtin", definedIn: "src/tools/scheduler-tools.ts", mountedBy: ["scheduler"], cards: ["schedule-wakeup"], face: { family: "other", boundaryLegs: ["env"], effect: "write", contract: c("core.schedule_wakeup@1"), ruleFace: { params: ["delaySeconds", "reason", "prompt", "stop", "noop"] } } }, { id: "web-fetch", name: "WebFetch", source: "builtin", definedIn: "src/tools/web.ts", mountedBy: ["scenario"], cards: ["web-fetch"], face: { family: "web", boundaryLegs: ["outside_read"], effect: "read", contentOrigin: "external", contract: c("core.web_fetch@1"), hostTarget: { param: "url" }, ruleFace: { primaryParams: ["url"], params: ["url", "prompt"] }, renderHints: { summaryParams: ["url"], approvalCard: "fetch" }, compactable: true }, }, { id: "web-search", name: "WebSearch", source: "builtin", definedIn: "src/tools/web.ts", mountedBy: ["scenario"], cards: ["web-search"], face: { family: "web", boundaryLegs: ["outside_read"], effect: "read", contentOrigin: "external", contract: c("core.web_search@1"), ruleFace: { primaryParams: ["query"], params: ["query"] }, renderHints: { summaryParams: ["query"] }, compactable: true }, }, { id: "todo-write", name: TODO_WRITE_TOOL_NAME, source: "builtin", definedIn: "src/tools/todo.ts", mountedBy: ["scenario"], cards: ["todo"], modelGate: "task-scaffold", face: { family: "plan", boundaryLegs: [], effect: "idempotent", contract: c("core.todo_write@1"), ruleFace: { params: [] } } }, { id: "task-create", name: TASK_CREATE_TOOL_NAME, protocol: ["teammate"], source: "builtin", definedIn: "src/tools/task-list.ts", mountedBy: ["scenario"], cards: ["task"], modelGate: "task-scaffold", face: { family: "plan", boundaryLegs: [], effect: "write", contract: c("core.task_create@1"), ruleFace: { params: ["subject", "description", "activeForm"] } } }, { id: "task-get", name: TASK_GET_TOOL_NAME, protocol: ["teammate"], source: "builtin", definedIn: "src/tools/task-list.ts", mountedBy: ["scenario"], cards: ["task"], modelGate: "task-scaffold", face: { family: "plan", boundaryLegs: [], effect: "read", contract: c("core.task_get@1"), ruleFace: { params: ["taskId"] } } }, { id: "task-update", name: TASK_UPDATE_TOOL_NAME, protocol: ["teammate"], source: "builtin", definedIn: "src/tools/task-list.ts", mountedBy: ["scenario"], cards: ["task"], modelGate: "task-scaffold", face: { family: "plan", boundaryLegs: [], effect: "idempotent", contract: c("core.task_update@1"), ruleFace: { params: ["taskId", "status", "subject", "description", "activeForm"] } } }, { id: "task-list", name: TASK_LIST_TOOL_NAME, protocol: ["teammate"], source: "builtin", definedIn: "src/tools/task-list.ts", mountedBy: ["scenario"], cards: ["task-list"], modelGate: "task-scaffold", face: { family: "plan", boundaryLegs: [], effect: "read", contract: c("core.task_list@1"), ruleFace: { params: [] } } }, { id: "agent", name: "Agent", source: "builtin", definedIn: "src/agents/subagent.ts", mountedBy: ["scenario"], cards: ["agent", "fork"], face: { family: "delegate", boundaryLegs: [], contentOrigin: "local", contract: c("core.agent@1"), ruleFace: { params: ["subagent_type", "description", "prompt", "name", "cwd", "model", "isolation", "run_in_background"] } } }, { id: "observer-report", name: "ObserverReport", protocol: ["observer"], verdict: "result", source: "builtin", definedIn: "src/agents/observer.ts", mountedBy: ["scenario"], cards: [], face: { family: "scaffold", boundaryLegs: [], effect: "write", contract: c("core.observer_report@1"), ruleFace: { params: ["report"] } } }, { id: "declare-done", name: "DeclareDone", protocol: ["goal"], verdict: "result", source: "builtin", definedIn: "src/orchestration/goal.ts", mountedBy: ["scenario"], cards: [], face: { family: "scaffold", boundaryLegs: [], effect: "read", ruleFace: { params: ["summary"] } } }, ]; export const ENGINE_CARDS = Object.freeze({ mcp: "src/core/mcp.ts", a2a: "src/core/a2a.ts", path_not_in_root: "src/tools/fs/safety.ts", read_path_denied: "src/tools/fs/safety.ts", readonly_out_of_root: "src/tools/fs/shell-read-check.ts", read_unestablished: "src/tools/fs/shell-read-check.ts", read_targets_refused: "src/tools/fs/shell-read-check.ts", bash_self_kill_refused: "src/tools/fs/pattern-kill-guard.ts", bash: "src/tools/fs/fs-shared.ts", }); export const CARD_SKELETONS = Object.freeze({ create: ["filePath", "contentSha256"], update: ["filePath", "contentSha256"], edit: ["filePath", "replaceAll", "contentSha256"], "notebook-edit": ["notebookPath", "cellId", "editMode", "cellType", "newCellId", "contentSha256"], text: ["file.filePath", "file.numLines", "file.startLine", "file.totalLines", "file.truncatedByTokenCap"], notebook: ["file.filePath"], image: ["file.type", "file.originalSize", "file.dimensions"], document: ["file.type", "file.originalSize", "file.pageCount", "file.timedOut", "fallback.level"], grep: ["mode", "numFiles", "totalFiles", "numMatches", "numLines", "totalLines", "appliedLimit", "appliedOffset", "partial", "fallback"], glob: ["numFiles", "truncated", "durationMs", "totalMatches", "countIsComplete"], "repo-map": ["sourceFiles", "renderedFiles", "nonSourceFiles", "truncated"], bash: ["exitCode", "interrupted", "timedOut", "timeoutSec", "requestedTimeoutSec", "cappedToMaxTimeoutSec", "livenessNoOutput", "noOutputSec", "aborted", "isImage", "output_file", "detached", "task_id", "sandboxUnavailable", "refusedBy", "refused", "transportLost", "envSuspended", "authFailed", "envRefused", "targetUnavailable", "registerFailed", "killFailed", "outcomeUnknown", "code"], bash_invalid_timeout: ["code"], bash_self_kill_refused: ["code", "finding", "pid", "relation"], readonly_out_of_root: ["code"], read_unestablished: ["code"], read_targets_refused: ["code"], path_not_in_root: ["code", "target"], read_path_denied: ["code", "target", "pattern"], artifact: ["action", "plane", "code", "invalidArguments", "url", "path", "bytes", "mediaType", "ref.url", "ref.slug", "ref.version"], worktree: ["action", "worktreeDir", "base", "kept", "metadataPruned"], "task-stop": ["task_type", "task_id", "status", "retrieval_status", "error", "code", "stoppedBy", "completionId"], "monitor-start": ["taskId", "persistent", "envBudgetSec", "effectiveTimeoutMs", "timeoutIgnored", "sessionScoped", "timeoutMs", "requestedTimeoutMs", "wasClamped", "sandboxUnavailable", "refusedBy"], "send-message": ["status", "to", "address", "seq", "task_id", "marker", "doorbell", "verdict", "subscription"], "agent-transcript": ["id", "agentState"], "list-agents": ["directoryFault"], "read-inbox": ["error", "delivered", "pending", "urgent", "notTaken"], "workflow-run": ["status", "workflowRunId", "task_id"], "report-findings": ["count", "level"], "send-user-message": ["status", "kind", "attachments", "ledger.open", "ledger.unverified"], "tool-search": ["total_deferred_tools"], advisor: ["outcome", "model", "servedModel", "stopReason", "code", "errorKind", "hold", "inputTooLongRuledOut", "usage"], "ask-question": ["questionId", "continuationSource", "runContinues", "reason", "code"], "exit-plan-mode": ["isAgent", "filePath"], "enter-plan-mode": ["message"], "cron-create": ["id", "recurring", "durable", "replaced", "nextFireAt"], "cron-delete": ["id"], "cron-list": [], "schedule-wakeup": ["stopped", "scheduledFor", "clampedDelaySeconds", "wasClamped", "noop", "cancelledWakeups"], "web-fetch": ["url", "code", "bytes", "durationMs", "truncated", "partial", "timedOut", "aborted"], "web-search": ["durationSeconds", "searchCount", "retryable"], todo: [], task: ["task.id", "task.status", "task.owner", "deleted"], "task-list": [], agent: ["status", "isAsync", "task_id", "settle_id", "subagent_type", "taskId", "sessionId", "code", "retryAfterMs", "resolvedModel", "worktreePath"], fork: [], mcp: [], a2a: ["state", "kind", "taskId", "contextId", "code", "delivered"], }); const byId = new Map(); for (const e of TOOL_CATALOG_ENTRIES) { if (byId.has(e.id)) throw new Error(`tool catalog: duplicate definition id ${JSON.stringify(e.id)}`); if (e.face.pathTarget !== undefined && e.face.hostTarget !== undefined) throw new Error(`tool catalog: ${JSON.stringify(e.id)} declares a path target and a host target — a face names one protected target`); byId.set(e.id, e); } const CATALOG_CONTRACTS = new WeakSet(); export function toolFace(id) { const e = byId.get(id); if (e === undefined) throw new Error(`tool catalog: no definition ${JSON.stringify(id)}`); const face = { contentOrigin: "local", ...structuredClone(e.face) }; if (face.contract !== undefined) CATALOG_CONTRACTS.add(Object.freeze(face.contract)); return face; } export function isCatalogContract(contract) { return typeof contract === "object" && contract !== null && CATALOG_CONTRACTS.has(contract); } export function engineMountedAs(ids) { const contracts = new Set(ids.map((id) => { const contractId = byId.get(id)?.face.contract?.contractId; if (contractId === undefined) throw new Error(`tool catalog: ${JSON.stringify(id)} declares no contract — an engine mount is judged by its definition's contract`); return contractId; })); return (face) => face?.engineMounted === true && contracts.has(face.contractId); } export const isEngineShellFace = engineMountedAs(["bash", "bash-readonly"]); export const routesContent = engineMountedAs(["ask-user-question", "structured-output", "report-blocked"]); export function mountRuleFace(id) { const primaryParams = toolFace(id).ruleFace?.primaryParams; return primaryParams === undefined ? undefined : { primaryParams: [...primaryParams] }; } function deepFreeze(value) { if (value !== null && typeof value === "object" && !Object.isFrozen(value)) { Object.freeze(value); for (const k of Object.keys(value)) deepFreeze(value[k]); } return value; } deepFreeze(TOOL_CATALOG_ENTRIES); export const TOOL_FACES = Object.freeze(Object.fromEntries(TOOL_CATALOG_ENTRIES.map((e) => [e.id, e.face]))); export const ENGINE_BUILTIN_TOOL_NAMES = Object.freeze([...new Set(TOOL_CATALOG_ENTRIES.filter((e) => e.source === "builtin").map((e) => e.name))]); export const ENGINE_TOOLS = Object.freeze([...new Set(TOOL_CATALOG_ENTRIES.map((e) => e.name))].map((name) => { const aliases = [...new Set(TOOL_CATALOG_ENTRIES.filter((e) => e.name === name).flatMap((e) => e.face.aliases ?? []))]; return Object.freeze(aliases.length > 0 ? { name, aliases: Object.freeze(aliases) } : { name }); })); export function isEngineBuiltinToolName(name) { return ENGINE_BUILTIN_TOOL_NAMES.includes(name); }