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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: support persistent Mind image attachments with Codex TUI
[._.]/ Adam Eivy74fc9fa7409c
diff --git a/server/lib/README.md b/server/lib/README.mdindex 4056d921dc..74fe7e402d 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -248,7 +248,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `cliProviderArgs.js` | Per-CLI argv conventions (`buildCliArgs`) for stdin prompt delivery — dependency-light extraction from runner.js so out-of-process callers (autofixer) can import it. || `cliProviderRun.js` | One-shot CLI provider invocation (`pickCliProvider` + `runCliProviderPrompt`) — lightweight path for the autofixer + calendar MCP sync to honor the configured provider/model. Optional `safetyProfile` runs only maintained no-tool vendor recipes and composes the same restricted environment, refusing extra argv and unsupported providers. || `cliStderrNoise.js` | `isKnownCliStderrNoise(trimmedLine)` — drops the real Anthropic `claude` CLI's harmless `[claude-code:unrecognized_model]` SDK telemetry line, which fires on every claude-ollama / claude-ollama-tui run because those providers point the binary's `ANTHROPIC_BASE_URL` at a local Ollama model the SDK doesn't recognize. |-| `codex.js` | OpenAI Codex CLI (`codex`) provider helpers — the `CODEX_COMMAND`/`CODEX_CLI_ID` constants, the `isCodexCommand` predicate, and `ensureCodexTuiArgs` (injects `--dangerously-bypass-approvals-and-sandbox` + disables the startup update-check config, skipped when the argv already declares an approval/sandbox posture via `argvHasFlag`). Extracted from `tuiHandshake.js` (#3618) to match the one-file-per-vendor shape of `antigravity.js`/`grok.js`/`kimi.js`/`cursor.js`, which `providerVendors.js` consumes as registry rows. Also owns `buildCodexOssArgs` — the `--oss --local-provider <ns>` pair emitted from a record's `ollamaBacked` marker, so the Codex harness runs on a local model without rewriting the user's `~/.codex/config.toml` (the record-classification half of that lives in `providerModels.js`, so `providerPrerequisites.js` can classify a codex record without importing a vendor argv module). |+| `codex.js` | OpenAI Codex CLI (`codex`) provider helpers — the `CODEX_COMMAND`/`CODEX_CLI_ID` constants, the `isCodexCommand` and `isVisionCapableCodexTuiProvider` predicates, and `ensureCodexTuiArgs` (injects `--dangerously-bypass-approvals-and-sandbox` + disables the startup update-check config, skipped when the argv already declares an approval/sandbox posture via `argvHasFlag`). Extracted from `tuiHandshake.js` (#3618) to match the one-file-per-vendor shape of `antigravity.js`/`grok.js`/`kimi.js`/`cursor.js`, which `providerVendors.js` consumes as registry rows. Also owns `buildCodexOssArgs` — the `--oss --local-provider <ns>` pair emitted from a record's `ollamaBacked` marker, so the Codex harness runs on a local model without rewriting the user's `~/.codex/config.toml` (the record-classification half of that lives in `providerModels.js`, so `providerPrerequisites.js` can classify a codex record without importing a vendor argv module). || `cursor.js` | Cursor Agent (`cursor-agent`) provider helpers — the `CURSOR_COMMAND` binary constant, the `isCursorCommand` predicate, and the `ensureCursorHeadlessArgs` (`--print --force`, folding any pinned reasoning effort into `--model`) / `ensureCursorTuiArgs` (`--force`) argv builders. `--force` is load-bearing beyond approvals: it also clears cursor's workspace-trust gate, which otherwise EXITS a headless run before any work happens. The prompt rides raw stdin (like claude/codex, unlike grok/kimi), and cursor needs no configured-default sentinel — its `auto` router is a real model id passed straight to `--model`. || `grok.js` | xAI Grok Build (`grok`) provider helpers — id/endpoint constants (`GROK_API_ID`/`GROK_CLI_ID`/`GROK_TUI_ID`/`GROK_API_ENDPOINT`), `isGrokCommand`/`isGrokCliProvider`/`isGrokTuiProvider` predicates, `ensureGrokHeadlessArgs`/`ensureGrokTuiArgs` argv builders (grok reads its prompt from `--prompt-file /dev/stdin`, not raw stdin; model selection uses the `GROK_CONFIGURED_DEFAULT` sentinel in `providerModels.js` so PortOS omits `--model` like Antigravity), and `prepareGrokPromptFile` (Windows temp-file delivery fallback). || `grokVideoClip.js` | Clip lengths grok's `image_to_video` actually delivers — `GROK_VIDEO_DURATIONS` (`[6, 10]`, measured in #3022: a 2s/3s request returns the same 6.04s clip), `GROK_VIDEO_DEFAULT_DURATION`, `resolveGrokDuration()` (validate an already-grok-shaped request, else default), and `nearestGrokDuration()` (round a length authored against another backend's continuous contract UP to the shortest clip that covers it — for translating a CD/commission `targetDurationSeconds`). Dependency-free so `validation.js` / `routes/videoGen.js` can derive their schemas from the same list the services gate on. |diff --git a/server/lib/codex.js b/server/lib/codex.jsindex 004060d44e..e99b73dd3c 100644--- a/server/lib/codex.js+++ b/server/lib/codex.js@@ -30,6 +30,10 @@ import {export const CODEX_COMMAND = 'codex';export const CODEX_CLI_ID = 'codex';+/** The interactive Codex runner forwards images with its native --image flag. */+export const isVisionCapableCodexTuiProvider = (provider) =>+ provider?.type === 'tui' && isCodexCommand(provider.command);+/*** Match by normalized binary basename (like isGrokCommand/isKimiCommand) so a* path- or `.exe`-configured provider is still recognized.diff --git a/server/services/persistentMindImageCapability.js b/server/services/persistentMindImageCapability.jsindex 8b9831c138..68e751c1c7 100644--- a/server/services/persistentMindImageCapability.js+++ b/server/services/persistentMindImageCapability.js@@ -1,5 +1,6 @@/** Resolve whether the pinned Persistent Mind provider/model can consume images. */+import { isVisionCapableCodexTuiProvider } from '../lib/codex.js';import { isVisionCapableCliProvider, isVisionModel } from '../lib/localModelHeuristics.js';import { listModels } from './localLlm.js';import * as ollamaManager from './ollamaManager.js';@@ -34,8 +35,11 @@ export async function resolvePersistentMindImageCapability({ listBackendModels = listModels, getOllamaCapabilities = ollamaManager.getModelCapabilities } = {},) {if (!provider) return result('unsupported', 'Choose a Persistent Mind provider before attaching images.');+ if (isVisionCapableCodexTuiProvider(provider)) {+ return result('supported', 'Codex TUI accepts image attachments with the initial prompt.');+ }if (provider.type === 'tui') {- return result('unsupported', 'Interactive TUI providers cannot receive Persistent Mind image attachments.');+ return result('unsupported', 'This TUI provider cannot receive Persistent Mind image attachments. Choose Codex or a vision-capable CLI/API provider.');}if (provider.type === 'cli') {return isVisionCapableCliProvider(provider)diff --git a/server/services/persistentMindImageCapability.test.js b/server/services/persistentMindImageCapability.test.jsindex e08509231f..60923557c5 100644--- a/server/services/persistentMindImageCapability.test.js+++ b/server/services/persistentMindImageCapability.test.js@@ -5,10 +5,11 @@ import {} from './persistentMindImageCapability.js';describe('Persistent Mind image capability', () => {- it('supports Codex and Claude CLI providers but rejects other CLI and TUI transports', async () => {+ it('supports vision CLI providers and Codex TUI while rejecting unsupported transports', async () => {await expect(resolvePersistentMindImageCapability({ provider: { type: 'cli', command: 'codex' }, model: 'gpt-5' })).resolves.toMatchObject({ status: 'supported' });await expect(resolvePersistentMindImageCapability({ provider: { type: 'cli', command: 'claude' }, model: 'claude-opus' })).resolves.toMatchObject({ status: 'supported' });await expect(resolvePersistentMindImageCapability({ provider: { type: 'cli', command: 'opencode' }, model: 'example' })).resolves.toMatchObject({ status: 'unsupported' });+ await expect(resolvePersistentMindImageCapability({ provider: { type: 'tui', command: '/opt/bin/codex' }, model: 'gpt-6-astra' })).resolves.toMatchObject({ status: 'supported' });await expect(resolvePersistentMindImageCapability({ provider: { type: 'tui' }, model: 'example' })).resolves.toMatchObject({ status: 'unsupported' });});diff --git a/server/services/promptRunner.js b/server/services/promptRunner.jsindex 6ee875b093..96576a0ecd 100644--- a/server/services/promptRunner.js+++ b/server/services/promptRunner.js@@ -26,6 +26,7 @@* stay honest about what the runner actually executed.*/+import { isVisionCapableCodexTuiProvider } from '../lib/codex.js';import { createRun, executeApiRun, executeCliRun, extractBakedModel, hasModelFlag, stopRun, patchRunMetadata, finalizeRunRecord } from './runner.js';import { getActiveProvider, getProviderById, getAllProviders } from './providers.js';// `./tuiPromptRunner.js` (which drags node-pty in through `./shell.js`) and@@ -462,7 +463,8 @@ export function assertProvider(provider, { message, code, status = 503 } = {}) {* Guard a vision run against a transport that did not receive images.** API providers base64-inline images, while the shared CLI lifecycle stages- * file attachments for Codex and Claude Code. TUI and other CLI providers must+ * file attachments for Codex and Claude Code. Codex TUI forwards native image+ * arguments. Other TUI and CLI providers must* not be accepted because they would answer from the text prompt alone.* `runPromptThroughProvider` can swap the provider two ways — a proactive swap* inside createRun (`result.provider`) or a retry fallback after failure@@ -479,7 +481,7 @@ export function assertProvider(provider, { message, code, status = 503 } = {}) {*/export function assertVisionRunUsedImages(result, requestedProvider) {const ran = result?.provider || result?.fallbackProvider || requestedProvider;- const usedImages = ran?.type === 'api' || isVisionCapableCliProvider(ran);+ const usedImages = ran?.type === 'api' || isVisionCapableCliProvider(ran) || isVisionCapableCodexTuiProvider(ran);if (ran?.type && !usedImages) {// Name both providers so the cause is actionable. The usual trigger is a// proactive/retry swap because the requested API provider is in a temporary@@ -1187,7 +1189,8 @@ async function executeProviderRunOnce({}if (screenshots.length > 0&& provider.type !== PROVIDER_TYPES.API- && !isVisionCapableCliProvider(provider)) {+ && !isVisionCapableCliProvider(provider)+ && !isVisionCapableCodexTuiProvider(provider)) {throw new ServerError('The selected provider cannot receive image attachments. Choose Codex, Claude Code, or a vision API provider.',{ status: 422, code: 'VISION_PROVIDER_UNSUPPORTED' },@@ -1434,7 +1437,7 @@ async function executeProviderRunOnce({// `source` (e.g. 'pipeline-manuscript-completeness') labels the live,// interactive view this TUI run surfaces in the Shell page.import('./tuiPromptRunner.js')- .then(({ executeTuiRun }) => executeTuiRun({ runId, provider: providerForRun, prompt, workspacePath: effectiveCwd, onData, onComplete, onReady: onRunReady, timeout: effectiveTimeout, label: source }))+ .then(({ executeTuiRun }) => executeTuiRun({ runId, provider: providerForRun, prompt, screenshots, workspacePath: effectiveCwd, onData, onComplete, onReady: onRunReady, timeout: effectiveTimeout, label: source })).catch(safeReject);} else {safeReject(new Error(`Unsupported provider type: ${effectiveProvider.type}`));diff --git a/server/services/promptRunner.test.js b/server/services/promptRunner.test.jsindex d4b23000d7..fba459fbac 100644--- a/server/services/promptRunner.test.js+++ b/server/services/promptRunner.test.js@@ -149,6 +149,24 @@ describe('promptRunner — happy paths', () => {})).rejects.toMatchObject({ code: 'VISION_PROVIDER_UNSUPPORTED' });});+ it('forwards image attachments through the pinned Codex TUI', async () => {+ const provider = { id: 'codex-tui', type: 'tui', command: 'codex', defaultModel: 'gpt-6-astra' };+ tuiRunner.executeTuiRun.mockImplementation(async ({ screenshots, onComplete }) => {+ expect(screenshots).toEqual(['/tmp/example.png']);+ onComplete({ success: true, text: 'Image description' });+ });+ const output = await runPromptThroughProvider({+ provider, prompt: 'Inspect image', screenshots: ['/tmp/example.png'], source: 'test', allowFallback: false,+ });+ expect(output.text).toBe('Image description');+ expect(assertVisionRunUsedImages(output, provider)).toBe(provider);+ expect(runner.executeCliRun).not.toHaveBeenCalled();+ await expect(runPromptThroughProvider({+ provider: { ...provider, command: 'claude' }, prompt: 'Inspect image',+ screenshots: ['/tmp/example.png'], source: 'test', allowFallback: false,+ })).rejects.toMatchObject({ code: 'VISION_PROVIDER_UNSUPPORTED' });+ });+it('routes API providers through executeApiRun, accumulates text, resolves { text, runId, model }', async () => {runner.executeApiRun.mockImplementation(async ({ onData, onComplete }) => {onData('foo');diff --git a/server/services/tuiPromptRunner.js b/server/services/tuiPromptRunner.jsindex 4d9633196e..c765f983c8 100644--- a/server/services/tuiPromptRunner.js+++ b/server/services/tuiPromptRunner.js@@ -37,7 +37,8 @@import { spawn as ptySpawn } from 'node-pty';-import { join, resolve } from 'path';+import { basename, isAbsolute, join, resolve } from 'path';+import { access } from 'node:fs/promises';import { ensureDir, PATHS, tryReadFile } from '../lib/fileUtils.js';import { createStreamingAnsiStripper, stripAnsi } from '../lib/ansiStrip.js';import {@@ -148,7 +149,7 @@ const PTY_ROWS = 50;* it reports itself, not a provider incident for the autofixer to escalate.* @returns {Promise<void>}*/-export async function executeTuiRun({ runId, provider, prompt, workspacePath, onData, onComplete, onReady, timeout, idleMs, label, guard = false, reportFailure = true }) {+export async function executeTuiRun({ runId, provider, prompt, screenshots = [], workspacePath, onData, onComplete, onReady, timeout, idleMs, label, guard = false, reportFailure = true }) {if (!provider || typeof provider !== 'object') {throw new Error('executeTuiRun: provider is required');}@@ -159,6 +160,15 @@ export async function executeTuiRun({ runId, provider, prompt, workspacePath, onconst invocation = buildTuiInvocation(provider, provider.defaultModel);const { command } = invocation;const args = buildOneShotTuiArgs(command, invocation.args);+ if (screenshots.length > 0) {+ if (!isCodexCommand(command)) throw new Error('This TUI provider cannot receive image attachments');+ for (const screenshot of screenshots) {+ if (typeof screenshot !== 'string' || !screenshot) throw new Error('Invalid screenshot path');+ const imagePath = isAbsolute(screenshot) ? screenshot : resolve(PATHS.screenshots, basename(screenshot));+ await access(imagePath);+ args.push('--image', imagePath);+ }+ }const promptDelayMs = provider.tuiPromptDelayMs ?? DEFAULT_TUI_PROMPT_DELAY_MS;const idleThresholdMs = idleMs ?? provider.tuiOneShotIdleMs ?? DEFAULT_ONE_SHOT_IDLE_MS;const totalTimeoutMs = timeout ?? provider.timeout ?? DEFAULT_TIMEOUT_MS;diff --git a/server/services/tuiPromptRunner.test.js b/server/services/tuiPromptRunner.test.jsindex da753e1b3b..cc8947b824 100644--- a/server/services/tuiPromptRunner.test.js+++ b/server/services/tuiPromptRunner.test.js@@ -453,6 +453,27 @@ describe('executeTuiRun', () => {});describe('startup hooks', () => {+ it('passes image paths as native Codex arguments and refuses missing images before spawn', async () => {+ const provider = { id: 'codex-tui', type: 'tui', command: 'codex', defaultModel: 'gpt-6-astra' };+ const imagePath = join(runsTmpDirRef.current, 'example image.png');+ await writeFile(imagePath, 'image fixture');+ const promise = executeTuiRun({+ runId: 'run-images', provider, prompt: 'Describe image',+ screenshots: [imagePath], workspacePath: TEST_WORKSPACE,+ });+ await vi.waitFor(() => expect(ptySpawnMock).toHaveBeenCalledTimes(1));+ const args = ptySpawnMock.mock.calls[0][1];+ expect(args.slice(args.indexOf('--image'), args.indexOf('--image') + 2)).toEqual(['--image', imagePath]);+ ptyInstances[0].emitExit({ exitCode: 0 });+ await promise;+ ptySpawnMock.mockClear();+ await expect(executeTuiRun({+ runId: 'run-missing-image', provider, prompt: 'Describe image',+ screenshots: [join(runsTmpDirRef.current, 'missing.png')], workspacePath: TEST_WORKSPACE,+ })).rejects.toThrow();+ expect(ptySpawnMock).not.toHaveBeenCalled();+ });+it('disables Codex multi-agent fan-out for one-shot prompt runs', async () => {const provider = {id: 'codex-tui', type: 'tui', command: '/opt/homebrew/bin/codex', defaultModel: 'gpt-x',