Your team of AI agents, on your Mac, Windows or Linux. Agents that talk in channels, write code, review each other and use your tools, on the Claude Code, Codex, OpenCode or Pi you already have. Anything that touches the real world waits for your yes.
TypeScript agent-teamagentic-aiai-agentsai-assistantclaude-codecodexcursorelectrongrokgrok-bot-alternativelinuxlocal-firstmacosmcpmulti-agentopenclaw-alternativeopencodewindows
Fix Gemini agents not reading Tucano's settings, and lock down what a working folder can change (#89)
Gabriel Simionato Ambrósiocbe59f1a6860
diff --git a/src/core/engines/detect.ts b/src/core/engines/detect.tsindex 50b7fe0..a7eb5fd 100644--- a/src/core/engines/detect.ts+++ b/src/core/engines/detect.ts@@ -232,7 +232,7 @@ export async function detectGemini(): Promise<{ status: EngineStatus; models: stconst path = await which('gemini')if (!path) return { status: { installed: false, loggedIn: false }, models: [] }const v = await run(path, ['--version'])- const home = process.env['GEMINI_CLI_HOME'] || join(homedir(), '.gemini')+ const home = join(process.env['GEMINI_CLI_HOME'] || homedir(), '.gemini')const signedIn = existsSync(join(home, 'oauth_creds.json')) || !!(process.env['GEMINI_API_KEY'] || process.env['GOOGLE_API_KEY'] || process.env['GOOGLE_GENAI_USE_VERTEXAI'])const models = geminiModels()return {diff --git a/src/core/engines/gemini.ts b/src/core/engines/gemini.tsindex 3e4fc98..583eaed 100644--- a/src/core/engines/gemini.ts+++ b/src/core/engines/gemini.ts@@ -73,7 +73,8 @@ export function geminiArgs(turn: Pick<Turn, 'model'>): string[] {return ['-p', '', '--output-format', 'stream-json', '--approval-mode', 'yolo', '-m', turn.model]}-const userHomeOf = (): string => process.env['GEMINI_CLI_HOME'] || join(homedir(), '.gemini')+// GEMINI_CLI_HOME is the CLI's home: its files (login included) live in .gemini/ under it.+const userHomeOf = (): string => join(process.env['GEMINI_CLI_HOME'] || homedir(), '.gemini')// Where the app keeps the Gemini homes, in its data folder.export const geminiAppDir = (dataDir: string): string => join(dataDir, 'gemini')@@ -94,47 +95,61 @@ function linkOrCopy(target: string, at: string): void {}// A home for one turn. Gemini reads settings, context files (GEMINI.md), its MCP-// servers and its session from the home, so a fresh home per turn keeps a turn-// to its own tools and leaves no session behind. settings.json gives the gateway+// servers and its session from the home (under .gemini/), so a fresh home per turn+// keeps a turn to its own tools and leaves no session behind. settings.json gives the gateway// as the only MCP server and turns the built-in tools off; the person's login// (OAuth credentials, or an env-based key/gateway) is brought in; the agent's-// instructions go to a file the CLI reads as the system prompt. The settings-// nest the way the CLI expects (mcpServers, tools.core/exclude, a quiet UI).+// instructions go to a file the CLI reads as the system prompt.export function geminiHome(appDir: string, turn: Pick<Turn, 'system' | 'mcpUrl' | 'web'>, userHome = userHomeOf()): string {mkdirSync(appDir, { recursive: true })const home = join(appDir, randomBytes(8).toString('hex'))- mkdirSync(home, { recursive: true })+ const dot = join(home, '.gemini')+ mkdirSync(dot, { recursive: true })// The person's login stays theirs: link the OAuth credentials and the account- // marker (an env-based key or company gateway needs nothing here).- for (const f of ['oauth_creds.json', 'google_accounts.json']) linkOrCopy(join(userHome, f), join(home, f))+ // marker into .gemini/, where the CLI looks (an env-based key or company+ // gateway needs nothing here).+ for (const f of ['oauth_creds.json', 'google_accounts.json']) linkOrCopy(join(userHome, f), join(dot, f))// The agent is Tucano's: its instructions are the system prompt (GEMINI_SYSTEM_MD// points the CLI at this file, see geminiEnv).writeFileSync(join(home, 'system.md'), turn.system)+ // Keys as Gemini CLI 0.28 reads them (older flat keys like coreTools are ignored).const settings: Record<string, unknown> = {// The app's gateway is the only MCP server; its tools reach the model.- ...(turn.mcpUrl ? { mcpServers: { [GATEWAY_NAME]: { httpUrl: turn.mcpUrl } } } : {}),+ ...(turn.mcpUrl ? { mcpServers: { [GATEWAY_NAME]: { url: turn.mcpUrl, type: 'http', trust: true } } } : {}),+ // ...and the only one allowed: a server declared anywhere else never starts.+ mcp: { allowed: [GATEWAY_NAME] },// No built-in tools (shell, files, memory); only web search, and only when- // the agent has the web. coreTools is the allow-list of built-ins.- coreTools: turn.web ? [GEMINI_WEB] : [],+ // the agent has the web. tools.core is the allow-list of built-ins; no+ // discovery or call command, so no tools come from running a command.+ tools: { core: turn.web ? [GEMINI_WEB] : [], discoveryCommand: '', callCommand: '' },+ // No hooks: a hook is a command the CLI runs around each turn.+ hooksConfig: { enabled: false },// Nothing of Gemini's own that would run behind the app's back or spend- // tokens outside the receipts.- extensions: { disableAll: true },- experimental: { skills: { enabled: false } },+ // tokens outside the receipts: no skills, no built-in subagents. Extensions+ // load from the home, which is fresh, so there are none.+ skills: { enabled: false },+ agents: { overrides: { codebase_investigator: { enabled: false }, cli_help: { enabled: false } } },privacy: { usageStatisticsEnabled: false },+ telemetry: { enabled: false, logPrompts: false },ui: { showMemoryUsage: false },general: { checkpointing: { enabled: false } }}- writeFileSync(join(home, 'settings.json'), JSON.stringify(settings, null, 2))+ writeFileSync(join(dot, 'settings.json'), JSON.stringify(settings, null, 2))return home}// The env a gemini turn runs with: its own home, the system prompt file, and no// context-file discovery (the person's GEMINI.md never leaks into the agent).+// The turn's settings are also the system settings: Gemini applies those last,+// over a .gemini/settings.json in the working folder (headless, the CLI trusts+// any folder). That only holds for the keys we set: built-in tools, MCP servers,+// skills, subagents, tool discovery, hooks and telemetry. A key a newer CLI adds+// is the folder's until it's set here too.export function geminiEnv(home: string, base: NodeJS.ProcessEnv = {}): NodeJS.ProcessEnv {- return { ...base, GEMINI_CLI_HOME: home, GEMINI_SYSTEM_MD: join(home, 'system.md') }+ return { ...base, GEMINI_CLI_HOME: home, GEMINI_CLI_SYSTEM_SETTINGS_PATH: join(home, '.gemini', 'settings.json'), GEMINI_SYSTEM_MD: join(home, 'system.md') }}// The model is "<provider>/<model>" as the picker lists it; the CLI wants thediff --git a/test/engines.test.ts b/test/engines.test.tsindex b7e6fff..1bccbf1 100644--- a/test/engines.test.ts+++ b/test/engines.test.ts@@ -278,20 +278,32 @@ describe('Gemini config', () => {const appDir = mkdtempSync(join(tmpdir(), 'gh-'))const home = geminiHome(appDir, { system: 'You are Iris.', mcpUrl: 'http://127.0.0.1:1/mcp/x', web: false }, userHome)expect(home.startsWith(appDir)).toBe(true)- const s = JSON.parse(readFileSync(join(home, 'settings.json'), 'utf8')) as Record<string, unknown>- expect(s['mcpServers']).toEqual({ tucano: { httpUrl: 'http://127.0.0.1:1/mcp/x' } })- expect(s['coreTools']).toEqual([]) // no built-in tools, no web- expect((s['experimental'] as Record<string, unknown>)['skills']).toEqual({ enabled: false })+ // the CLI reads $GEMINI_CLI_HOME/.gemini/, so nothing goes at the root+ const s = JSON.parse(readFileSync(join(home, '.gemini', 'settings.json'), 'utf8')) as Record<string, unknown>+ expect(existsSync(join(home, 'settings.json'))).toBe(false)+ expect(s['mcpServers']).toEqual({ tucano: { url: 'http://127.0.0.1:1/mcp/x', type: 'http', trust: true } })+ expect(existsSync(join(home, '.gemini', 'oauth_creds.json'))).toBe(true)+ expect(existsSync(join(home, 'oauth_creds.json'))).toBe(false)+ // keys as the CLI reads them: tools.core, not the old flat coreTools+ expect(s['tools']).toEqual({ core: [], discoveryCommand: '', callCommand: '' }) // no built-in tools, no web, no discovered tools+ expect(s['coreTools']).toBeUndefined()+ expect(s['mcp']).toEqual({ allowed: ['tucano'] })+ expect(s['skills']).toEqual({ enabled: false })+ expect(s['agents']).toEqual({ overrides: { codebase_investigator: { enabled: false }, cli_help: { enabled: false } } })expect((s['privacy'] as Record<string, unknown>)['usageStatisticsEnabled']).toBe(false)+ // nothing a working folder could turn into a command or a request: hooks, telemetry+ expect(s['hooksConfig']).toEqual({ enabled: false })+ expect(s['telemetry']).toEqual({ enabled: false, logPrompts: false })// the agent's instructions are the system prompt, and the login is brought inexpect(readFileSync(join(home, 'system.md'), 'utf8')).toBe('You are Iris.')- expect(geminiEnv(home, { PATH: '/x' })).toEqual({ PATH: '/x', GEMINI_CLI_HOME: home, GEMINI_SYSTEM_MD: join(home, 'system.md') })+ // the turn's settings are also the system settings, applied over the working folder's+ expect(geminiEnv(home, { PATH: '/x' })).toEqual({ PATH: '/x', GEMINI_CLI_HOME: home, GEMINI_CLI_SYSTEM_SETTINGS_PATH: join(home, '.gemini', 'settings.json'), GEMINI_SYSTEM_MD: join(home, 'system.md') })})it('turns on only the web search when the agent has the web', () => {const home = geminiHome(mkdtempSync(join(tmpdir(), 'gh2-')), { system: 's', mcpUrl: undefined, web: true }, mkdtempSync(join(tmpdir(), 'gu2-')))- const s = JSON.parse(readFileSync(join(home, 'settings.json'), 'utf8')) as Record<string, unknown>- expect(s['coreTools']).toEqual(['google_web_search'])+ const s = JSON.parse(readFileSync(join(home, '.gemini', 'settings.json'), 'utf8')) as Record<string, unknown>+ expect(s['tools']).toEqual({ core: ['google_web_search'], discoveryCommand: '', callCommand: '' })expect(s['mcpServers']).toBeUndefined()})