CodeVetter · Repo Unpack · Extension points
google-gemini/gemini-cli
Almost every subsystem is a plug-in point: ICommandLoader implementations feed CommandService; ToolRegistry.registerTool plus the discovery-command and MCP paths add tools; AgentRegistry loads local .md/agent definitions and remote A2A agents; the policy engine loads TOML rule dirs per tier; hooks subscribe to named lifecycle events; extensions bundle all of the above via gemini-extension.json; skills are discovered by SkillManager and activated via ActivateSkillTool; ContentGenerator is a factory interface; and the policy engine, themes, and model-config service all accept externally supplied entries.
- Slash commands plug in through the ICommandLoader interface — BuiltinCommandLoader (hardcoded), FileCommandLoader (TOML in ~/.gemini/commands, project, extension dirs), McpPromptLoader (MCP prompts), SkillCommandLoader — merged by CommandService.create with SlashCommandResolver de-duplicating conflicts by renaming losers.
- New core tools are added by implementing AnyDeclarativeTool/BaseDeclarativeTool (build() → ToolInvocation with getDescription/shouldConfirmExecute/execute) and registering in Config.createToolRegistry's maybeRegister list, which automatically respects the coreTools allowlist.
- Tools can be added without recompiling via settings toolDiscoveryCommand (JSON function declarations on stdout) + toolCallCommand (JSON params on stdin), executed through the optional sandboxManager — a command-protocol plugin surface.
- MCP servers are the main third-party extension surface: configured in settings/extensions, connected by McpClientManager, their tools appear as DiscoveredMCPTool (MCP_TOOL_PREFIX), prompts become slash commands, and resources are exposed via ReadMcpResourceTool/ListMcpResourcesTool through registries.
- Extensions are defined by a gemini-extension.json manifest (EXTENSIONS_CONFIG_FILENAME) and can contribute MCP servers, context files, custom commands, agents, skills, hooks, themes, and TOML policies; ExtensionManager handles install/enable/disable/update and variable hydration (${extensionPath} etc.).
- The policy engine accepts user rules from multiple TOML directories per tier (default core policies in packages/core/src/policy/policies/*.toml — yolo.toml, read-only.toml, plan.toml, agents.toml etc. — plus --policy paths, workspace, user, and --admin-policy dirs) and dynamic rules pushed over the MessageBus via UpdatePolicy messages.
- Hooks are user/extension-supplied handlers for HookEventName lifecycle events (SessionStart/End, Before/AfterAgent, Before/AfterModel, BeforeToolSelection, Before/AfterTool) executed by HookRunner and aggregated by HookAggregator, capable of injecting context, modifying model calls, or blocking execution.
- Subagents plug in via AgentDefinition objects loaded by loadAgentsFromDirectory (project/user/extension dirs) or built in code; kind:'remote' agents are A2A-protocol endpoints resolved through A2AClientManager with pluggable auth via A2AAuthProviderFactory.
- Skills are markdown-based packages discovered by SkillManager from user/project/extension dirs (loadSkillsFromDir), gated by admin settings and folder trust, exposed to the model through ActivateSkillTool whose schema is re-registered with the discovered skill enum.
- Model selection is extensible: ModelConfigService resolves per-alias model configs, routing/routingStrategy.ts plus availability policyHelpers decide model per request, handleFallback switches models on quota errors, and ModelMappingContentGenerator remaps names for Code Assist (CCPA_AI_MODEL_MAPPINGS). (inferred)
- ContentGenerator is a decorated factory: Fake/Recording/Logging/ModelMapping wrappers compose around either the Code Assist server client or @google/genai — new providers slot in by extending createContentGenerator's authType switch.
- Tool declarations shown to the model are model-family aware: tools/definitions/coreTools.ts + resolver.ts + model-family-sets produce per-model FunctionDeclarations so tool schemas can be swapped per Gemini version without touching tool implementations.