| phase | implementation |
|---|---|
| title | Gemini CLI Adapter in @ai-devkit/agent-manager - Implementation |
| feature | gemini-cli-adapter |
| description | Implementation notes for Gemini CLI adapter support in the package agent manager and CLI integration |
- Branch:
feat/gemini-cli-adapter - Install dependencies with
npm ci - Build + lint + test with:
npx nx run agent-manager:buildnpx nx run agent-manager:lintnpx nx run agent-manager:testnpx nx run cli:test -- --runInBand src/__tests__/commands/agent.test.ts
- Package adapter implementation:
packages/agent-manager/src/adapters/GeminiCliAdapter.ts
- Package exports:
packages/agent-manager/src/adapters/index.tspackages/agent-manager/src/index.ts
- CLI wiring:
packages/cli/src/commands/agent.ts
- Tests:
packages/agent-manager/src/__tests__/adapters/GeminiCliAdapter.test.tspackages/cli/src/__tests__/commands/agent.test.ts
- README matrix update:
README.md(Agent Control Support row for Gemini CLI)
- Adapter contract:
type = 'gemini', pluscanHandle,detectAgents,getConversation. - Process detection:
listAgentProcesses('node')+isGeminiExecutable(argv)token-scan for basenamegemini/gemini.exe/gemini.js. - Project-to-session mapping:
- Walk from the process cwd to the nearest
.gitboundary (fallback: starting cwd) - Compute sha256 of the resolved project root →
projectHash - Cross-check against
~/.gemini/projects.jsonfor theshortIdused in the session path
- Walk from the process cwd to the nearest
- Session file discovery:
~/.gemini/tmp/<shortId>/chats/session-*.json, filtered to the matchingprojectHash. - Content normalization:
resolveContent(content)acceptsstring | Part[]and returns a concatenated string ofpart.textvalues; non-text parts are dropped. messageText(entry)prefersdisplayContentovercontent.
- Follow
CodexAdapterstructure for helper extraction and error handling. - Keep parsing inside the adapter; keep CLI-side formatting unchanged.
- Fail soft: malformed session entries are skipped; adapter-level exceptions return empty results so other adapters still render.
- Avoid adapter-specific customization the maintainer flagged as unnecessary (e.g., Windows-specific basename handling was reverted).
AgentManagerparallel aggregation across Claude + Codex + GeminiTerminalFocusManageropen/focus flow reused without Gemini-specific branches- CLI list/json output mapping unchanged
- Missing
~/.gemini/projects.jsonor~/.gemini/tmp→ empty result, no throw. - Malformed session JSON → skip that file, continue with the rest.
- Polymorphic
content→ handled byresolveContentso.trim()never runs on an array. - Adapter-level throw is caught at the manager layer, isolating the failure.
- Process detection is bounded by the number of live
nodeprocesses on the host. - Session file reads are scoped to the
shortIdresolved fromprojects.jsonfor each live Gemini process — not a full~/.gemini/tmpscan. - Reuses existing async aggregation model in
AgentManager.
- Reads only local files under
~/.geminiand local process metadata already permitted by existing adapters. - No external network calls; no execution of user content.
- Completed:
packages/agent-manager/src/adapters/GeminiCliAdapter.ts- Package exports in
packages/agent-manager/src/adapters/index.tsandsrc/index.ts packages/cli/src/commands/agent.tsregistersGeminiCliAdapterfor list and open- README "Agent Control Support" row for Gemini CLI flipped to ✅
- Unit tests (42 total) including the 5 added after maintainer review for array-shaped content
- Review-iteration fixes:
- Introduced
resolveContent(string | Part[])+messageText(entry)helpers to handle Gemini'sPart[]user content - Reverted Windows-specific
path.win32.basenamecustomization (per "đừng custom quá nhiều")
- Introduced
- Commands verified:
npx nx run-many -t build test lint✅npx nx run agent-manager:test -- --runInBand src/__tests__/adapters/GeminiCliAdapter.test.ts✅ (42 passed)- End-to-end: real Gemini CLI session surfaced correctly in
ai-devkit agent list