Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: cover gemini-cli argv construction; clarify why Brain uses --prompt

Adam Eivyc324f95de28f
diff --git a/server/services/brain.js b/server/services/brain.js
index 4392b2ecab..145d2e508c 100644
--- a/server/services/brain.js
+++ b/server/services/brain.js
@@ -64,7 +64,11 @@ async function callAI(promptStageName, variables, providerOverride, modelOverrid
if (provider.headlessArgs?.length) {
args.push(...provider.headlessArgs);
}
- // gemini-cli goes interactive unless --prompt is set, hanging on /dev/null stdin
+ // gemini-cli prompt delivery differs here from runner.js and agentCliSpawning.js:
+ // those pipe the prompt via stdin for streaming runs, while this path uses
+ // stdio: ['ignore', ...] for one-shot headless classification. With stdin ignored,
+ // gemini-cli flips to interactive mode and hangs — so the prompt must go via
+ // --prompt, and --output-format text skips interactive-mode detection overhead.
const isGeminiCli = provider.id === 'gemini-cli';
if (isGeminiCli && !args.includes('--output-format') && !args.includes('-o')) {
args.push('--output-format', 'text');
diff --git a/server/services/brain.test.js b/server/services/brain.test.js
index 0e515ad569..bc761a869d 100644
--- a/server/services/brain.test.js
+++ b/server/services/brain.test.js
@@ -83,6 +83,7 @@ vi.mock('child_process', () => ({
spawn: vi.fn()
}));
+import { spawn } from 'child_process';
import * as storage from './brainStorage.js';
import { getProviderById } from './providers.js';
import {
@@ -1005,4 +1006,141 @@ describe('brain service', () => {
expect(getSummary).toBe(storage.getSummary);
});
});
+
+ // ===========================================================================
+ // callAI CLI path — gemini-cli argv construction
+ // Guards against regressions like reintroducing interactive-mode detection,
+ // dropping --prompt, or losing the thinking-model fallback.
+ // ===========================================================================
+
+ describe('callAI CLI path (gemini-cli argv)', () => {
+ function createMockChild(stdoutPayload) {
+ const child = new EventEmitter();
+ child.stdout = new EventEmitter();
+ child.stderr = new EventEmitter();
+ child.kill = vi.fn();
+ // Emit payload and close on next tick so listeners attach first
+ setImmediate(() => {
+ child.stdout.emit('data', Buffer.from(stdoutPayload));
+ child.emit('close', 0);
+ });
+ return child;
+ }
+
+ const validDigestJson = JSON.stringify({
+ digestText: 'tiny digest',
+ topActions: ['a'],
+ stuckThing: 's',
+ smallWin: 'w'
+ });
+
+ beforeEach(() => {
+ // Override outer beforeEach's defaultModel so the callAI fallback path is reachable
+ storage.loadMeta.mockResolvedValue({
+ confidenceThreshold: 0.6,
+ defaultProvider: 'gemini-cli',
+ defaultModel: null
+ });
+ storage.getProjects.mockResolvedValue([{ id: 'p1', name: 'Proj', status: 'active' }]);
+ storage.getAdminItems.mockResolvedValue([]);
+ storage.getPeople.mockResolvedValue([]);
+ storage.getInboxLog.mockResolvedValue([]);
+ storage.createDigest.mockResolvedValue({ id: 'd1' });
+ storage.updateMeta.mockResolvedValue();
+ });
+
+ it('passes prompt via --prompt, forces --output-format text, and falls back to flash-lite when model unset', async () => {
+ getProviderById.mockResolvedValue({
+ id: 'gemini-cli',
+ enabled: true,
+ type: 'cli',
+ command: 'gemini',
+ args: [],
+ timeout: 1000
+ // defaultModel deliberately unset — exercises the flash-lite fallback
+ });
+ spawn.mockReturnValue(createMockChild(validDigestJson));
+
+ await runDailyDigest('gemini-cli');
+
+ expect(spawn).toHaveBeenCalledTimes(1);
+ const [command, args, opts] = spawn.mock.calls[0];
+ expect(command).toBe('gemini');
+ expect(opts.stdio).toEqual(['ignore', 'pipe', 'pipe']);
+
+ // Non-interactive output format pinned
+ const outputFmtIdx = args.indexOf('--output-format');
+ expect(outputFmtIdx).toBeGreaterThanOrEqual(0);
+ expect(args[outputFmtIdx + 1]).toBe('text');
+
+ // Thinking-model fallback
+ const modelIdx = args.indexOf('--model');
+ expect(modelIdx).toBeGreaterThanOrEqual(0);
+ expect(args[modelIdx + 1]).toBe('gemini-2.5-flash-lite');
+
+ // Prompt delivered via flag (not positional) so gemini-cli stays non-interactive
+ const promptIdx = args.indexOf('--prompt');
+ expect(promptIdx).toBeGreaterThanOrEqual(0);
+ expect(args[promptIdx + 1]).toBe('test prompt');
+ });
+
+ it('honors an explicit model override instead of the flash-lite fallback', async () => {
+ getProviderById.mockResolvedValue({
+ id: 'gemini-cli',
+ enabled: true,
+ type: 'cli',
+ command: 'gemini',
+ args: [],
+ defaultModel: 'gemini-2.5-pro',
+ timeout: 1000
+ });
+ spawn.mockReturnValue(createMockChild(validDigestJson));
+
+ await runDailyDigest('gemini-cli');
+
+ const args = spawn.mock.calls[0][1];
+ const modelIdx = args.indexOf('--model');
+ expect(args[modelIdx + 1]).toBe('gemini-2.5-pro');
+ });
+
+ it('does not duplicate --output-format when provider args already specify it', async () => {
+ getProviderById.mockResolvedValue({
+ id: 'gemini-cli',
+ enabled: true,
+ type: 'cli',
+ command: 'gemini',
+ args: ['--output-format', 'json'],
+ defaultModel: 'gemini-2.5-flash-lite',
+ timeout: 1000
+ });
+ spawn.mockReturnValue(createMockChild(validDigestJson));
+
+ await runDailyDigest('gemini-cli');
+
+ const args = spawn.mock.calls[0][1];
+ const occurrences = args.filter(a => a === '--output-format').length;
+ expect(occurrences).toBe(1);
+ expect(args[args.indexOf('--output-format') + 1]).toBe('json');
+ });
+
+ it('uses positional prompt (not --prompt) for non-gemini CLI providers', async () => {
+ getProviderById.mockResolvedValue({
+ id: 'claude-code',
+ enabled: true,
+ type: 'cli',
+ command: 'claude',
+ args: ['-p'],
+ defaultModel: 'sonnet',
+ timeout: 1000
+ });
+ spawn.mockReturnValue(createMockChild(validDigestJson));
+
+ await runDailyDigest('claude-code');
+
+ const args = spawn.mock.calls[0][1];
+ expect(args).not.toContain('--prompt');
+ expect(args).not.toContain('--output-format');
+ expect(args[args.length - 1]).toBe('test prompt');
+ });
+ });
});