Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is my attempt at integrating the PAI system into Gemini code while preserving the existing installations. Claude and Gemini should be able to coexist in the same system as well.
It looked like a quick fix at first...
Summary
Implements first-class support for the Google Gemini CLI while refactoring the system into a "Safe Distro" model. This elevates PAI into an independent infrastructure layer (
~/.config/pai) capable of serving multiple AI clients (Claude Code, Gemini) simultaneously, ensuring shared memory, identity, and skills across all tools.gemini-paiadapter for full PAI context injection and hook simulation.install.tsstandardized to XDG paths (~/.config/pai) with multi-tool integration.Motivation
Previously, PAI was tightly coupled to the
~/.claudedirectory structure. To integrate Google Gemini support, we faced a choice: hack it in as a sidecar, or elevate PAI to a proper infrastructure layer.We chose the latter. This PR decouples the "Brain" (PAI) from the "Interface" (Claude/Gemini). By standardizing on
PAI_DIR, we allow the user to switch tools seamlessly while maintaining a single source of truth for their AI's personality and memory.What's Changed
Core Infrastructure
Tools/gemini-pai.tsBundles/Kai/install.ts~/.config/pai. ImplementsinstallSymlinkswith proactive backup logic (.old) to safely integrate with Claude Code. Decoupled IO for testability.Packs/kai-hook-system/src/initialize-session.tsPAI_SOURCE_APPto correctly identify the calling tool (Claude vs Gemini) for observability logs.Documentation & Standards
Packs/kai-core-install/src/skills/CORE/SKILL.mdPacks/kai-prompting-skill/src/skills/Prompting/Standards.mdBundles/Kai/README.md~/.config/paidefault and Gemini setup.Tools/VERIFY.mdTesting
tests/install-config.test.tstests/gemini-pai.test.tstests/install-logic.test.tsKey Improvements
1. The "Safe Distro" Pattern
Instead of hijacking the
geminibinary, we introducegemini-pai. This adapter is self-aware: it locates the PAI installation relative to itself or via explicit aliases generated by the installer. This eliminates environment dependency bugs and allows for isolated testing.2. Multi-Tool Architecture (Smart Symlinks)
The installer now treats PAI as the host and tools as clients:
~/.config/pai(XDG standard).~/.claudedirectory is detected, the installer safely backs up its internal folders (skills,hooks, etc.) to.oldand replaces them with symlinks to PAI.3. Gemini Context Injection Strategy
Since Gemini CLI lacks a native "system prompt" config file, we implemented a lightweight but robust injection strategy:
gemini-paiwrapper prepends thePAI SYSTEM INITIALIZATIONblock directly to the user's prompt.gemini-pai "hello", it responds and exits (respecting pipes). If you rungemini-paialone, it launches a full interactive session with the infrastructure loaded.4. Refactoring: console.log → InstallerIO
While the core goal was Gemini integration, we refactored the installation logic to use an InstallerIO interface. This was necessary to:
validate output without running a real terminal.
coverage of the installation flow.
Aligns with PAI Principles
This PR implements the "Safe Distro" model for Gemini integration, strictly adhering to the following PAI principles:
Principle 3: Scaffolding > Model
The Tools/gemini-pai.ts wrapper acts as intelligent scaffolding. It ensures that the AI always receives the correct system context, identity (CLIO), and available skill index before a session begins, making the model's performance more reliable through architectural support.
Principle 5: Code Before Prompts
Logic for environment detection, .env loading, and dynamic context assembly is handled deterministically in TypeScript. This prevents "hallucinated context" by providing hard-coded truth to the model via the wrapper.
Principle 6: Spec / Test / Evals First
This feature includes a comprehensive test suite (tests/gemini-pai.test.ts, tests/install-logic.test.ts) that verifies context injection and environment loading, ensuring the integration works as specified before it hits production.
Principle 7: UNIX Philosophy (Modular Tooling)
The gemini-pai adapter is a composable tool that follows the "do one thing well" rule—it manages the PAI-to-Gemini bridge while respecting standard streams and existing CLI flags.
Principle 8: ENG / SRE Principles
By adopting the "Safe Distro" approach (wrapper scripts instead of alias hijacking), we ensure the system is robust, easy to debug, and simple to roll back without corrupting the underlying shell environment.
Principle 9: CLI as Interface
The integration reinforces the CLI-first nature of PAI, providing a seamless way to invoke advanced AI capabilities directly from the terminal with full access to local scripts and tools.
Testing Status
Exhaustively verified on Linux (Ubuntu) and via sandbox environments:
bun test), covering environment parsing, path logic, and configuration preservation.~/.config/pai.~/.claudefolders are correctly converted to symlinks, forcing Claude to adopt the PAI identity.