Agent Harness Anatomy #10: Gemini CLI — the routed, policy-gated terminal agent

by David P. S. Marques

Series: Agent Harness Anatomy — top-down dissections of real agent harnesses, grounded in verifiable source code. Every behavioral claim below carries a footnote to a pinned GitHub permalink; the full evidence lives in the endnotes.

Version block

Gemini CLI architecture

Explore the interactive architecture diagram 14 nodes, 15 edges — pan, zoom, and follow every subsystem link

The mental model

Every CLI harness in this series so far has been a program with one model, one loop, and one policy. Gemini CLI breaks all three assumptions. It is Google's terminal coding agent — the third lab-built CLI in the series after Codex CLI — and its architecture is organized around delegation: a per-turn model router picks which model answers, a tool scheduler with explicit lifecycle states executes calls, a TOML policy engine with priority tiers decides what needs asking, and eleven hook types let extensions rewrite tool arguments, LLM requests, and even streamed responses mid-flight.1

The governing idea: the core loop doesn't decide much. GeminiClient.sendMessageStream is a thin orchestrator — it checks turn budgets, runs loop detection, asks the router which model to use, and streams events.2 The intelligence lives in the surrounding machinery: the router's composite strategy chain (fallback → override → approval-mode → classifiers → default), the scheduler's Validating → Scheduled → executing → terminal lifecycle, and a confirmation bus that decouples policy decisions from the UI that renders them.3

The tradeoff is machinery for control. Where pi has a loop and extensions, Gemini CLI has a router, a scheduler, a policy engine, a hook system, a context manager, a compression service, a recording service, and a background memory-extraction service — roughly 138,000 lines in packages/core alone.4 You get per-turn model selection, learned approval policies, and eleven interception points; you pay in the number of systems you must understand to predict what a turn will do.

Package map

The repo is an npm workspaces monorepo. For this article five areas matter:5

Area Role Scale
packages/core/src/core/The client: GeminiClient, Turn, GeminiChat — the loopclient.ts (1,313 lines), turn.ts, geminiChat.ts (1,881 lines)
packages/core/src/scheduler/Tool execution: lifecycle scheduler, policy, confirmationscheduler.ts (1,003 lines)
packages/core/src/tools/26 built-in tools, registry, MCP client39 tool files
packages/core/src/policy/ + safety/ + sandbox/TOML policy engine, checkers, per-OS sandboxespolicies/*.toml
packages/core/src/routing/Per-turn model router (composite strategies)modelRouterService.ts
packages/core/src/hooks/11 hook event types, command + runtime hookshooks/types.ts
packages/core/src/agents/Subagents: registry, invoke_agent, isolated executorslocal-executor.ts
packages/core/src/context/ + services/Compression, recording, memory, context managerchatCompressionService.ts
packages/cli/src/Ink TUI, non-interactive mode, ACP, stream consumption364 files

The core loop

The loop lives in GeminiClient.sendMessageStream (packages/core/src/core/client.ts:908). Its shape:6

const MAX_TURNS = 100;  // client.ts:79

async *sendMessageStream(request, signal, prompt_id, turns = MAX_TURNS, ...) {
  // ... hooks, loop-detector reset ...
  const boundedTurns = Math.min(turns, MAX_TURNS);
  let turn = new Turn(this.getChat(), prompt_id);
  turn = yield* this.processTurn(request, signal, prompt_id, boundedTurns, ...);
  // ... AfterAgent hooks, continuation handling ...
}

processTurn (client.ts:627) does the per-turn work: increment the session turn counter (bail with MaxSessionTurns if exceeded), render history through the context manager, check for context overflow, consult the loop detector, then route the model:7

const router = this.config.getModelRouterService();
const decision = await router.route(routingContext);
modelToUse = decision.model;
// ... unless currentSequenceModel is sticky from a previous turn

The router itself is a composite strategy chain — order matters: FallbackStrategy → OverrideStrategy → ApprovalModeStrategy → GemmaClassifierStrategy (opt-in) → ClassifierStrategy → NumericalClassifierStrategy → DefaultStrategy.8 Every turn re-routes unless a sequence model is pinned, which means the model answering turn N+1 can differ from turn N — by design, not accident.

Turn.run (core/turn.ts:271) streams one model call and yields typed events: Thought, Content, ToolCallRequest (one per function call, accumulated in pendingToolCalls), Citation, Finished, Retry, Error.9 Function-call IDs are synthesized as ${name}__${rawCallId} when the API doesn't supply one.10

Tool calls don't execute in core. The CLI's useGeminiStream hook collects ToolCallRequest events, then useToolScheduler.scheduleToolCalls hands them to the core scheduler; when the batch completes, handleCompletedTools calls submitQuery(responsesToSend, { isContinuation: true }), which re-enters sendMessageStream with functionResponse parts.11 The loop is split across the package boundary: core streams and decides, the CLI schedules and feeds back.

Termination comes from five directions: no pending tool calls (plus a next-speaker LLM check — see trace), MAX_TURNS (100), the loop detector (repeated event patterns), MaxSessionTurns, or user abort.12 The next-speaker check is the subtle one: when a turn ends with no tool calls, a separate LLM call decides whether the model should continue ("Please continue.") or the turn is done.13 And if the model returns empty text after executing tools, the CLI auto-nudges: "[System: You successfully executed a tool but returned an empty response. Please analyze the tool output...]".14

One turn of the agent loop

Per-turn model routing

Trace one turn

Trace Summarize the changes in this repo through the interactive CLI:15

  1. Input. The Ink TUI captures the prompt; submitQuery calls geminiClient.sendMessageStream(request, signal, prompt_id). BeforeAgent hooks fire once per prompt_id (dedup-guarded); a hook can stop the turn, block it, or inject <hook_context>.16
  2. Turn budget. processTurn increments sessionTurnCount and bails with MaxSessionTurns if the session cap is exceeded. The context manager renders history (or the legacy path compresses if over threshold). boundedTurns = Math.min(turns, 100).17
  3. Loop guard. loopDetector.turnStarted() — repeated prompt patterns abort here with LoopDetected before the model is ever called.18
  4. Route the model. The composite strategy chain picks the model for this turn; the decision (model, source strategy, latency, reasoning) is telemetry-logged as a ModelRoutingEvent.19 setTools(modelToUse) refreshes model-dependent tool descriptions.
  5. Model call. Turn.run → GeminiChat.sendMessageStream → the Gemini API. BeforeModel hooks can rewrite the outgoing request (model, config, contents); AfterModel hooks see each streamed chunk and can replace it.20 The model emits text plus a run_shell_command call (git log --oneline -10).
  6. Tool request. Turn yields ToolCallRequest; the CLI collects it and scheduleToolCalls enqueues it in the core scheduler. The scheduler moves it through lifecycle states: Validating → (policy + confirmation) → Scheduled → executing → terminal.21
  7. Approval. _processToolCall: BeforeTool hook first (can rewrite args — flagged inputModifiedByHook — or force ask), then checkPolicy (ALLOW/DENY/ASK_USER from the TOML engine), then taint-risk escalation (build-file edits force ASK_USER), then resolveConfirmation over the message bus → the TUI dialog. "Always allow" publishes UPDATE_POLICY, persisting to the autosaved TOML.22
  8. Execute and feed back. The tool runs; output is truncated if over threshold and converted to functionResponse parts. handleCompletedTools calls submitQuery(responses, {isContinuation: true}) → back to step 2 with boundedTurns - 1. When a turn ends with no tool calls, the next-speaker check decides: model continues or turn ends.23

Tool approval pipeline

Play the 8-step trace One turn through Gemini CLI — input, turn budget, loop guard, routing, model call, scheduling, approval, execution

Subsystem inventory

Tool system. 26 built-in tools in the main registry (read_file, replace, write_file, run_shell_command, grep_search, glob, web_fetch, google_web_search, ask_user, write_todos, invoke_agent, plan-mode tools, tracker tools, background-process tools, MCP resource tools).24 ToolRegistry.sortTools() orders by priority: 0 = built-in, 1 = project-discovered, 2 = MCP.25 There is no tool search or dynamic retrieval — every active tool is serialized into getFunctionDeclarations() and sent to the model on every turn.26 Every object-typed schema gets an injected wait_for_previous boolean so the model can force sequential execution.27 Tool declarations are model-family-aware: CoreToolSet maps families (default-legacy, gemini-3) to per-tool declaration overrides.28

Policy engine. TOML rules with match dimensions (tool name/wildcards, args regex, annotations, approval-mode scoping, interactivity) sorted by priority — first match wins.29 Priority tiers are structural: Default=1 < Extension=2 < Workspace=3 < User=4 < Admin=5, so an admin rule always beats a user rule regardless of numeric priority.30 Bundled policies cover read-only allows, write asks, yolo/headless/plan-mode behavior, and a sandbox default.31 Shell commands get special treatment: wrappers stripped, compound commands split and each subcommand recursively checked, redirections downgrade ALLOW → ASK_USER, dangerous commands force ASK_USER.32 Extension-supplied policies are sanitized — ALLOW rules and yolo-mode rules are dropped.33

Confirmation bus. MessageBus (an EventEmitter) decouples policy from UI: tools publish TOOL_CONFIRMATION_REQUEST with a correlation ID; the bus runs the policy engine first, then auto-responds (ALLOW/DENY) or emits to subscribers (the TUI dialog, ACP sessions).34 Subagent buses are untrusted — forcedDecision and server names are stripped before forwarding to the parent bus, preventing policy bypass.35 Confirmation requests time out after 30s, defaulting to ask.36

Safety checkers. Named checkers attach to tool calls and run after the policy decision; failures fail closed to DENY.37 Two in-process checkers (allowed-path, conseca) plus external checkers spawned as child processes with a JSON protocol (5s timeout, any failure → DENY).38 Conseca is the notable one: a Gemini Flash model generates a least-privilege per-tool security policy from the conversation, then enforces it per call — an LLM-written, LLM-enforced policy. It's gated behind a setting, default off, and fail-open when disabled.39

Sandbox. Per-OS managers: macOS Seatbelt (strict-allowlist SBPL profile, (deny default)), Linux bubblewrap (--unshare-all, --ro-bind / /), Windows restricted tokens + job objects via a C# helper.40 Sandbox TOML configures per-mode (plan/default/accepting_edits) network, readonly, and approved tools.41

Model router. Covered in the loop section — the composite strategy chain is the distinctive mechanism. Worth adding: routing decisions are telemetry-logged with source strategy and reasoning, so routing is auditable after the fact.42

Memory. Sessions persist as JSONL under ~/.gemini/tmp/<projectHash>/chats/ — one JSON object per line, full API parts, tool-call records with token summaries; $rewindTo records support history truncation on resume.43 Two compaction paths: the legacy ChatCompressionService (triggers at 0.5 × token limit, summarizes the oldest 70% into a structured <state_snapshot> XML with a two-pass self-correction probe, keeps the newest 30% verbatim)44 and the experimental opt-in ContextManager (65k-token budget, node aging, async snapshot pipeline).45 Cross-session memory is GEMINI.md files in four tiers: global → system instruction; extension + project → first-user-message bootstrap; per-directory → JIT injection into tool output on path access.46 No vector DB, no SQLite, no embeddings — memory is markdown concatenated into the prompt.47 A background extraction service mines old session JSONLs (every 30 min, ≥10 user messages, ≥3h idle, lock-coordinated across CLI instances) proposing skill patches and memory updates.48

Session persistence and memory

Hooks. 11 event types: BeforeTool / AfterTool, BeforeAgent / AfterAgent, BeforeModel / AfterModel, BeforeToolSelection, Notification, SessionStart / SessionEnd, PreCompress.49 Command hooks (shell subprocess, JSON over stdin, 60s timeout) or runtime hooks (in-process). They can block, rewrite tool args (re-validated), append <hook_context>, replace streamed LLM chunks, restrict the tool set per request, or stop the whole agent.50 Failures are non-fatal — logged, telemetry-recorded, execution continues.51 Project hooks are dropped in untrusted folders.52

Subagents. The model spawns subagents through one tool, invoke_agent ({agent_name, prompt}).53 Each runs in a LocalAgentExecutor with isolated registries (fresh tool/prompt/resource registries cloned from the parent's allowlist), a derived untrusted message bus, and its own GeminiChat.54 No nesting: Kind.Agent tools are excluded from subagent registries.55 Every subagent must call the mandatory complete_task tool to terminate normally; output is schema-validated.56 Budgets: maxTurns (default 30), maxTimeMinutes (default 10, confirmation waits pause the clock), 60s grace period for final complete_task.57 User-authored agents are Markdown files with YAML frontmatter in .gemini/agents/ (project, trust-gated with hash acknowledgement) or ~/.gemini/agents/.58 Remote agents speak A2A.59

Subagent invocation

MCP. Servers declared in settings (or contributed by extensions); McpClientManager owns one client per server (keyed by config hash).60 Discovered tools become DiscoveredMCPTools namespaced mcp_<server>_<tool> (63-char API limit, ... truncation), registered into the main tool registry — the model sees them as ordinary tools.61 list_changed notifications trigger re-discovery and registry swap.62 stdio servers are refused in untrusted folders; stdio env is sanitized with dangerous vars blocked.63

Skills. SKILL.md files (frontmatter name + description, markdown body), discovered built-in → extension → user → project with precedence and trust gating.64 Two-stage loading: the system prompt lists name/description/location only; the model calls activate_skill, which (after user confirmation for non-built-ins) injects the full body wrapped in <activated_skill> tags.65 A background skill-extraction agent proposes new skills from session history — authoring, not execution.66

Interfaces. Ink TUI (interactive), non-interactive gemini -p mode, ACP (agent-client protocol) sessions, an A2A server package, a programmatic SDK, and a VS Code IDE companion.67

What it deliberately omits

Comparison matrix row

# Dimension Gemini CLI (v0.63.0)
1Agent loopsendMessageStream → processTurn → Turn.run; MAX_TURNS=100; per-turn model router; loop detector; next-speaker LLM check; BeforeAgent/AfterAgent hooks
2Tool system26 built-ins; ToolRegistry with priority sort; no tool search — all tools sent every turn; wait_for_previous injected; model-family declaration overrides
3Model providersGemini API via @google/genai; per-turn composite router (fallback → override → approval-mode → classifiers → default); sequence-model stickiness
4Prompt constructionSystem prompt + tiered GEMINI.md injection; per-turn tool refresh; BeforeModel hooks can rewrite the request
5Memory/sessionJSONL session recording; legacy compression (0.5 threshold, <state_snapshot>, two-pass probe) + opt-in ContextManager; 4-tier GEMINI.md; background extraction service
6Reasoning/planningNo separate planner; subagents via invoke_agent (isolated registries, complete_task mandatory, no nesting); write_todos tracking
7ExtensibilityMCP (namespaced mcp_); skills (two-stage activate_skill); 11 hook types; extensions contribute servers/skills/agents/hooks
8InterfacesInk TUI; non-interactive CLI; ACP; A2A server; SDK; VS Code companion
9Failure handlingRetry with backoff; loop detector; taint escalation; hook fail-open; compression-failure fallback to truncation
10Security model4 approval modes; TOML policy engine (tiered priorities); confirmation bus; per-OS sandbox; Conseca (opt-in, default off); trust-gated everything

Endnotes

All notes VERIFIED against v0.63.0

(573846625af9e93b3b968e0e0b86bb093a4c9b16).

GH = https://github.com/google-gemini/gemini-cli/blob/573846625af9e93b3b968e0e0b86bb093a4c9b16/.


  1. GH…/packages/core/src/routing/modelRouterService.ts#L40-L70 (strategy chain); GH…/packages/core/src/scheduler/scheduler.ts#L446 (lifecycle loop); GH…/packages/core/src/policy/config.ts#L70-L89 (tiers); GH…/packages/core/src/hooks/types.ts#L43-L52 (11 events).  ↩

  2. GH…/packages/core/src/core/client.ts#L908-L975 (sendMessageStream orchestration).  ↩

  3. GH…/packages/core/src/confirmation-bus/message-bus.ts#L97-L164 (bus flow).  ↩

  4. 479 non-test GH…/packages/core/src/.ts files in GH…/packages/core/src, ~137,643 lines (counted at the pinned tag; includes blanks/comments).  ↩

  5. Package sizes counted at the pinned tag; GH…/packages/cli holds the TUI and stream consumption.  ↩

  6. GH…/packages/core/src/core/client.ts#L79 (MAX_TURNS); GH…/packages/core/src/core/client.ts#L908 (sendMessageStream signature).  ↩

  7. GH…/packages/core/src/core/client.ts#L627-L700 (processTurn: turn count, context render, loop detector).  ↩

  8. GH…/packages/core/src/routing/modelRouterService.ts#L40-L70 (strategy order); GH…/packages/core/src/routing/modelRouterService.ts#L75-L140 (route()).  ↩

  9. GH…/packages/core/src/core/turn.ts#L271-L300 (Turn.run event loop); GH…/packages/core/src/core/turn.ts#L254-L270 (fields).  ↩

  10. GH…/packages/core/src/core/turn.ts#L470-L480 (call ID synthesis).  ↩

  11. GH…/packages/cli/src/ui/hooks/useGeminiStream.ts#L1540-L1640 (event consumption); GH…/packages/cli/src/ui/hooks/useGeminiStream.ts#L1972-L2190 (handleCompletedTools → submitQuery continuation).  ↩

  12. GH…/packages/core/src/core/client.ts#L636-L650 (session turns, MaxSessionTurns); GH…/packages/core/src/core/client.ts#L840-L880 (loop detector in stream).  ↩

  13. GH…/packages/core/src/core/client.ts#L890-L910 (checkNextSpeaker, "Please continue.").  ↩

  14. GH…/packages/cli/src/ui/hooks/useGeminiStream.ts#L1640-L1665 (auto-nudge).  ↩

  15. Trace reconstructed from the code paths cited per step; no live run was performed.  ↩

  16. GH…/packages/core/src/core/client.ts#L165-L216 (fireBeforeAgentHookSafe, dedup, <hook_context>).  ↩

  17. GH…/packages/core/src/core/client.ts#L627-L660 (turn count, context render, boundedTurns).  ↩

  18. GH…/packages/core/src/core/client.ts#L760-L775 (loopDetector.turnStarted).  ↩

  19. GH…/packages/core/src/routing/modelRouterService.ts#L75-L140 (route(), ModelRoutingEvent telemetry).  ↩

  20. GH…/packages/core/src/core/geminiChat.ts#L992-L1062 (fireBeforeModelEvent, fireBeforeToolSelectionEvent); GH…/packages/core/src/core/geminiChat.ts#L1466-L1482 (fireAfterModelEvent, chunk replacement).  ↩

  21. GH…/packages/core/src/scheduler/scheduler.ts#L446-L560 (_processQueue, _processNextItem, lifecycle states).  ↩

  22. GH…/packages/core/src/scheduler/scheduler.ts#L628-L760 (_processToolCall: hook → policy → taint → confirmation → policy update).  ↩

  23. GH…/packages/cli/src/ui/hooks/useGeminiStream.ts#L2185-L2195 (continuation submitQuery).  ↩

  24. GH…/packages/core/src/config/config.ts#L4009-L4123 (registration); GH…/packages/core/src/tools/tool-names.ts#L203-L231 (name list; see recon for registry discrepancies).  ↩

  25. GH…/packages/core/src/tools/tool-registry.ts#L307-L348 (sortTools priorities).  ↩

  26. Negative grep for toolsearch|tool_search|search_tool over GH…/packages/core/src/tools/, GH…/packages/core/src/scheduler/, GH…/packages/core/src/config/config.ts — no hits; GH…/packages/core/src/tools/tool-registry.ts#L663-L705 sends all active tools.  ↩

  27. GH…/packages/core/src/tools/tools.ts#L585-L625 (wait_for_previous injection).  ↩

  28. GH…/packages/core/src/tools/definitions/types.ts#L21-L44, GH…/packages/core/src/tools/definitions/coreTools.ts#L69-L77, GH…/packages/core/src/tools/definitions/resolver.ts#L14-L29 (model-family overrides).  ↩

  29. GH…/packages/core/src/policy/policy-engine.ts#L610-L660 (check); GH…/packages/core/src/policy/types.ts#L110-L186 (match dimensions).  ↩

  30. GH…/packages/core/src/policy/config.ts#L70-L89 (tier constants and composition).  ↩

  31. GH…/packages/core/src/policy/policies/read-only.toml, GH…/packages/core/src/policy/policies/write.toml, GH…/packages/core/src/policy/policies/yolo.toml, GH…/packages/core/src/policy/policies/non-interactive.toml, GH…/packages/core/src/policy/policies/plan.toml, GH…/packages/core/src/policy/policies/sandbox-default.toml.  ↩

  32. GH…/packages/core/src/policy/policy-engine.ts#L365-L606 (shell heuristics, subcommand recursion, redirection downgrade).  ↩

  33. GH…/packages/core/src/policy/config.ts#L236-L280 (loadExtensionPolicies sanitization).  ↩

  34. GH…/packages/core/src/confirmation-bus/message-bus.ts#L18-L24 (types); GH…/packages/core/src/confirmation-bus/message-bus.ts#L97-L164 (publish flow).  ↩

  35. GH…/packages/core/src/confirmation-bus/message-bus.ts#L44-L90 (untrusted bus stripping).  ↩

  36. GH…/packages/core/src/tools/tools.ts#L359 (30s timeout, default ask).  ↩

  37. GH…/packages/core/src/policy/types.ts#L189-L241 (SafetyCheckerRule); GH…/packages/core/src/safety/checker-runner.ts#L99-L104 (fail-closed).  ↩

  38. GH…/packages/core/src/safety/protocol.ts#L20-L68 (external checker protocol); GH…/packages/core/src/safety/checker-runner.ts#L114-L236 (5s timeout, DENY on failure).  ↩

  39. GH…/packages/core/src/safety/conseca/conseca.ts#L60-L116 (generate + enforce); GH…/packages/cli/src/config/settingsSchema.ts#L2007-L2017 (default false); GH…/packages/core/src/policy/policies/conseca.toml#L1-L6 (priority 100).  ↩

  40. GH…/packages/core/src/sandbox/macos/MacOsSandboxManager.ts#L46; GH…/packages/core/src/sandbox/linux/LinuxSandboxManager.ts#L144; GH…/packages/core/src/sandbox/windows/WindowsSandboxManager.ts#L61; GH…/packages/core/src/services/sandboxManager.ts#L289 (noop fallback).  ↩

  41. GH…/packages/core/src/policy/sandboxPolicyManager.ts#L19-L43 (per-mode config); GH…/packages/core/src/policy/policies/sandbox-default.toml.  ↩

  42. GH…/packages/core/src/routing/modelRouterService.ts#L120-L140 (ModelRoutingEvent logging).  ↩

  43. GH…/packages/core/src/services/chatRecordingService.ts#L480-L564 (paths, JSONL format); GH…/packages/core/src/services/chatRecordingTypes.ts#L44-L103 (record shapes).  ↩

  44. GH…/packages/core/src/context/chatCompressionService.ts#L45 (0.5 threshold); GH…/packages/core/src/context/chatCompressionService.ts#L269 (30% preserve); GH…/packages/core/src/prompts/snippets.ts#L898-L980 (<state_snapshot>); GH…/packages/core/src/context/chatCompressionService.ts#L588-L643 (two-pass probe).  ↩

  45. GH…/packages/core/src/config/config.ts#L1205-L1206 (opt-in default off); GH…/packages/core/src/context/contextManager.ts#L352-L440 (65k budget, aging).  ↩

  46. GH…/packages/core/src/tools/memoryTool.ts#L11-L12 (file names); GH…/packages/core/src/utils/memoryDiscovery.ts#L317-L427 (scopes); GH…/packages/core/src/config/config.ts#L2590-L2634 (tiered injection); GH…/packages/core/src/context/memoryContextManager.ts#L125-L158 (JIT).  ↩

  47. Negative grep for sqlite|embedding|chroma|faiss on memory/session paths — no hits.  ↩

  48. GH…/packages/core/src/services/memoryService.ts#L56-L62 (cadence gates); GH…/packages/core/src/services/memoryService.ts#L1133-L1180 (lock coordination); GH…/packages/core/src/services/memoryService.ts#L1372-L1402 (outputs).  ↩

  49. GH…/packages/core/src/hooks/types.ts#L43-L52 (enum); GH…/packages/core/src/hooks/types.ts#L578-L752 (per-event inputs).  ↩

  50. GH…/packages/core/src/core/coreToolHookTriggers.ts#L64-L234 (tool hook powers); GH…/packages/core/src/core/geminiChat.ts#L999-L1045 (BeforeModel rewrite); GH…/packages/core/src/hooks/types.ts#L130-L211 (decisions).  ↩

  51. GH…/packages/core/src/hooks/hookEventHandler.ts#L389-L404; GH…/packages/core/src/hooks/hookSystem.ts#L261-L307 (safe defaults).  ↩

  52. GH…/packages/core/src/hooks/hookRegistry.ts#L178-L185 (untrusted-folder drop).  ↩

  53. GH…/packages/core/src/tools/tool-names.ts#L191 (invoke_agent); GH…/packages/core/src/agents/agent-tool.ts#L43-L122 (AgentTool, prompt smart-mapping).  ↩

  54. GH…/packages/core/src/agents/local-executor.ts#L168-L282 (isolated registries, derived bus).  ↩

  55. GH…/packages/core/src/agents/local-executor.ts#L206-L213 (Agent-kind exclusion).  ↩

  56. GH…/packages/core/src/agents/local-executor.ts#L271-L276 (mandatory complete_task, schema validation).  ↩

  57. GH…/packages/core/src/agents/types.ts#L54-L66 (budgets); GH…/packages/core/src/agents/local-executor.ts#L602-L616 (deadline timer); GH…/packages/core/src/agents/local-executor.ts#L109 (grace period).  ↩

  58. GH…/packages/core/src/agents/agentLoader.ts#L87-L115 (frontmatter schema); GH…/packages/core/src/agents/registry.ts#L158-L276 (load order); GH…/packages/core/src/agents/registry.ts#L173-L202 (trust gating).  ↩

  59. GH…/packages/core/src/agents/remote-invocation.ts; GH…/packages/core/src/agents/auth-provider/.  ↩

  60. GH…/packages/core/src/config/config.ts#L805-L1077 (server config); GH…/packages/core/src/tools/mcp-client-manager.ts#L305-L408 (keyed clients, discovery).  ↩

  61. GH…/packages/core/src/tools/mcp-tool.ts#L501-L538 (DiscoveredMCPTool); GH…/packages/core/src/tools/mcp-tool.ts#L541-L573 (generateValidName, 63-char limit).  ↩

  62. GH…/packages/core/src/tools/mcp-client.ts#L698-L768 (refreshTools on list_changed).  ↩

  63. GH…/packages/core/src/tools/mcp-client.ts#L2317 (stdio refused untrusted); GH…/packages/core/src/tools/mcp-client.ts#L2320-L2365 (env sanitization).  ↩

  64. GH…/packages/core/src/skills/skillLoader.ts#L16-L30 (SkillDefinition); GH…/packages/core/src/skills/skillManager.ts#L54-L111 (precedence); GH…/packages/core/src/skills/skillManager.ts#L82-L87 (trust gate).  ↩

  65. GH…/packages/core/src/prompts/snippets.ts#L314-L325 (renderAgentSkills); GH…/packages/core/src/tools/activate-skill.ts#L85-L158 (confirmation, <activated_skill> injection).  ↩

  66. GH…/packages/core/src/agents/skill-extraction-agent.ts#L27-L91.  ↩

  67. GH…/packages/cli/src/gemini.tsx (TUI); GH…/packages/cli/src/nonInteractiveCli.ts; GH…/packages/cli/src/acp/; GH…/packages/a2a-server/; GH…/packages/sdk/; GH…/packages/vscode-ide-companion/.  ↩

  68. GH…/packages/cli/src/config/settingsSchema.ts#L238 (YOLO CLI-only).  ↩