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
stop badging a provider that resolves its binary outside PortOS's PATH (#4611)
[._.]/ Adam Eivyea491752c90c
diff --git a/client/src/utils/README.md b/client/src/utils/README.mdindex b8d5bed391..5fd2869881 100644--- a/client/src/utils/README.md+++ b/client/src/utils/README.md@@ -41,7 +41,7 @@ grep -i "what you want to do" client/src/utils/README.md| `urlNormalize` | `isUrl` detection, `normalizeUrl` (optional git/`requireDot` modes), `isHttpUrl` (explicit http(s) only — safe-href check), and `tiktokVideoId` / `tiktokEmbedSrc` (host-anchored TikTok video-id extraction + its Embed Player URL, so a reference embeds without loading TikTok's embed.js). || `platform` | `isMac` detection and `modKey` (⌘/Ctrl) for keyboard-shortcut display. || `navWorkingSet` | Recent/pinned nav persistence (`recordVisit`, `togglePin`, `isPinned`) plus `resolveRecentNavEntries` for mapping stored deep links back to their longest matching nav-manifest entry. |-| `providers` | AI-provider type predicates and helpers (`isCliProvider`, `isApiProvider`, `isCodexProvider`, `isAntigravityProvider`, `isOrcaRouterBackedProvider` (the OpenCode wrapper that inherits its API key from the sibling `orcarouter` API provider at spawn time), `filterSelectableModels`, `resolveCliEffort` (mirror — what a stored effort actually runs as, so the picker can name a clamped level), `configuredDefaultIn` — the sentinel a provider's catalog carries, so a picker can render an option matching a sentinel-valued tier instead of a blank select — `getProviderTimeout`, `resolveEffectiveProvider` — the provider a record actually runs on (its pin, else the active provider) plus whether it fell back, so a "Default" option can name what it resolves to — `resolveSeriesRunLlm` (mirror of server `seriesLlmOverride.js`: which provider/model a Pipeline **series** run resolves to — per-run override → `series.llm` → active provider) and `providerModelLabel` (the one "Provider / model" phrasing), configured-default sentinels, and the claude/codex/agy thinking-effort levels — `effortLevelsForProvider`, mirror of server `providerModels.js`). Also `isRunnerAllowedCommand(command, allowedCommands)` — would the CoS Agent Runner (`/spawn`, `/spawn-tui`) accept this command? Mirrors only the *normalization* in `server/cos-runner/allowedCommands.js` (the list itself arrives as `runnerAllowedCommands` on `GET /api/providers`, because the allowlist is an exec boundary and stays hand-curated server-side); returns `null` for "list not fetched / field blank" so a failed fetch never renders a warning. Pinned by `server/cos-runner/allowedCommands.parity.test.js`. `isPrivateNetworkEndpoint(endpoint)` — loopback, RFC1918/tailnet address, or a `.local`/`.ts.net`/single-label host, i.e. somewhere an unauthenticated OpenAI-compatible server is a normal setup rather than a missing API key. `isLocalInstanceProvider(provider)` — the narrower question, mirroring server `localProviderRuntime.js#isLocalInstanceEndpoint`: does this provider talk to a daemon on THIS machine (loopback, or no endpoint at all)? Gate anything that explains a provider by inspecting the host PortOS runs on — install state, "start it from Settings → Local LLM" — since `localBackendForProvider` matches by NAME and would otherwise claim a peer's LM Studio. And `providerCardState(provider, { runtime, status, orcaRouterKeySet })` + `PROVIDER_CARD_STATE` — is a provider ready to run, benched, blocked on a missing prerequisite (CLI not installed / API key absent), or simply switched off? Reads the SERVER's `missingPrerequisites` (published per provider on `GET /api/providers` from `server/lib/providerPrerequisites.js`, and the same computation `getFallbackProvider` routes on) and adds only what the browser alone can see — the local-app runtime shape; derives the credential checks itself only when an older server publishes nothing. `null` inputs mean "not probed", never "missing". Drives the AI Providers page card colors and grouping — distinct from `ProviderReadiness`/`GET /api/providers/readiness`, which probes the local daemon behind a provider. And `providerRuntimeKey(provider)` — the key a provider's runtime is published under by `GET /api/providers/runtimes`, so a card can show its CLI install status (bare binary name for a cli/tui provider, provider id for an API provider fronted by a local app); the runtime table itself stays server-side. |+| `providers` | AI-provider type predicates and helpers (`isCliProvider`, `isApiProvider`, `isCodexProvider`, `isAntigravityProvider`, `isOrcaRouterBackedProvider` (the OpenCode wrapper that inherits its API key from the sibling `orcarouter` API provider at spawn time), `filterSelectableModels`, `resolveCliEffort` (mirror — what a stored effort actually runs as, so the picker can name a clamped level), `configuredDefaultIn` — the sentinel a provider's catalog carries, so a picker can render an option matching a sentinel-valued tier instead of a blank select — `getProviderTimeout`, `resolveEffectiveProvider` — the provider a record actually runs on (its pin, else the active provider) plus whether it fell back, so a "Default" option can name what it resolves to — `resolveSeriesRunLlm` (mirror of server `seriesLlmOverride.js`: which provider/model a Pipeline **series** run resolves to — per-run override → `series.llm` → active provider) and `providerModelLabel` (the one "Provider / model" phrasing), configured-default sentinels, and the claude/codex/agy thinking-effort levels — `effortLevelsForProvider`, mirror of server `providerModels.js`). Also `isRunnerAllowedCommand(command, allowedCommands)` — would the CoS Agent Runner (`/spawn`, `/spawn-tui`) accept this command? Mirrors only the *normalization* in `server/cos-runner/allowedCommands.js` (the list itself arrives as `runnerAllowedCommands` on `GET /api/providers`, because the allowlist is an exec boundary and stays hand-curated server-side); returns `null` for "list not fetched / field blank" so a failed fetch never renders a warning. Pinned by `server/cos-runner/allowedCommands.parity.test.js`. `isPrivateNetworkEndpoint(endpoint)` — loopback, RFC1918/tailnet address, or a `.local`/`.ts.net`/single-label host, i.e. somewhere an unauthenticated OpenAI-compatible server is a normal setup rather than a missing API key. `isLocalInstanceProvider(provider)` — the narrower question, mirroring server `localProviderRuntime.js#isLocalInstanceEndpoint`: does this provider talk to a daemon on THIS machine (loopback, or no endpoint at all)? Gate anything that explains a provider by inspecting the host PortOS runs on — install state, "start it from Settings → Local LLM" — since `localBackendForProvider` matches by NAME and would otherwise claim a peer's LM Studio. And `providerCardState(provider, { runtime, status, orcaRouterKeySet })` + `PROVIDER_CARD_STATE` — is a provider ready to run, benched, blocked on a missing prerequisite (CLI not installed / API key absent), or simply switched off? Reads the SERVER's `missingPrerequisites` (published per provider on `GET /api/providers` from `server/lib/providerPrerequisites.js`, and the same computation `getFallbackProvider` routes on) and adds only what the browser alone can see — the local-app runtime shape; derives the credential checks itself only when an older server publishes nothing. `null` inputs mean "not probed", never "missing". Drives the AI Providers page card colors and grouping — distinct from `ProviderReadiness`/`GET /api/providers/readiness`, which probes the local daemon behind a provider. `resolvesOutsidePortosPath(provider)` — does this provider resolve its binary somewhere the runtime probe never looked (an explicit path in `command`, or its own `PATH` in `envVars`)? Mirror of the same two guards in the server's `providerRuntimeKey`, and what keeps the card's badge from accusing a working provider the router happily routes. And `providerRuntimeKey(provider)` — the key a provider's runtime is published under by `GET /api/providers/runtimes`, so a card can show its CLI install status (bare binary name for a cli/tui provider, provider id for an API provider fronted by a local app); the runtime table itself stays server-side. || `layeredIntelligenceReasons` | Canonical gloss for the Layered Intelligence loop's run-outcome reason tokens, shared by the on-demand toast and the durable "Last run" line (`formatLiReason`, `liReasonTone`, `LI_NEUTRAL_REASONS`). |## Module loading / resiliencediff --git a/client/src/utils/providers.js b/client/src/utils/providers.jsindex 581c2a2b71..4dcd109353 100644--- a/client/src/utils/providers.js+++ b/client/src/utils/providers.js@@ -709,6 +709,17 @@ const PRIVATE_IP_RE = /^(?:10\.|192\.168\.|172\.(?:1[6-9]|2\d|3[01])\.|169\.254\* claim hostnames like `fdrive.example.com`, and `fd::1` expands to a leading* hextet of `0x00fd`, which is not in `fc00::/7` at all.*/+/**+ * Gate for {@link PRIVATE_IP_RE}: is this host an IPv4 literal at all?+ *+ * The range test above matches a PREFIX, which on its own also claims DNS names+ * that merely start like one — `10.evil.example` — and would report a keyless+ * PUBLIC endpoint as needing no key. Hosts arriving there have already been+ * through `URL`, which canonicalizes any IPv4 spelling to a dotted quad.+ * Mirror of the server helper in server/lib/providerPrerequisites.js.+ */+const isIpv4Literal = (host) => /^\d{1,3}(?:\.\d{1,3}){3}$/.test(host);+const isPrivateIpv6 = (host) => {if (!host.includes(':')) return false;const first = host.split(':')[0];@@ -740,7 +751,7 @@ export const isPrivateNetworkEndpoint = (endpoint) => {const candidate = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed) ? trimmed : `http://${trimmed}`;if (!URL.canParse(candidate)) return false;const host = new URL(candidate).hostname.toLowerCase().replace(/^\[|\]$/g, '');- if (PRIVATE_IP_RE.test(host)) return true;+ if (isIpv4Literal(host) && PRIVATE_IP_RE.test(host)) return true;if (isPrivateIpv6(host)) return true;if (/\.(local|internal|lan|home\.arpa|ts\.net)$/.test(host)) return true;// A single-label host resolves only inside the local network (`http://nas:11434`).@@ -910,6 +921,24 @@ export const isRunnerAllowedCommand = (command, allowedCommands) => {* through `localBackendForProvider` (which also matches a renamed provider by* its endpoint) and get their install state from the local-LLM status.*/+/**+ * Does this provider resolve its binary somewhere PortOS's runtime probe never+ * looked — an explicit path in `command`, or a `PATH` of its own in+ * `envVars`?+ *+ * The runtime row answers one question, "does the bare binary resolve on+ * PortOS's PATH?", and neither of these is that question: the runner spawns+ * such a provider against its own resolution. MIRROR of the same two guards in+ * `providerRuntimeKey` in server/lib/providerPrerequisites.js, which is what+ * keeps the card's badge and the server's routing decision agreeing.+ * @param {{type?:string,command?:string,envVars?:Record<string,string>}} provider+ */+export const resolvesOutsidePortosPath = (provider) => {+ if (!isProcessProvider(provider)) return false;+ if (/[\\/]/.test(String(provider?.command || '').trim())) return true;+ return Object.keys(provider?.envVars || {}).some((key) => key.toUpperCase() === 'PATH');+};+export const providerRuntimeKey = (provider) => {if (!isProcessProvider(provider)) return null;const command = provider?.command;@@ -1050,7 +1079,16 @@ export const providerCardState = (provider, { runtime = null, status = null, orc// / Ollama app installed with no CLI shim on PATH), which the server's runtime// table does not cover. For a plain CLI provider this is the same row the// server probed, and `addMissing` de-dupes it by code.- if (runtime && runtime.installed === false) {+ //+ // Except when the provider resolves its binary somewhere else. The runtime row+ // answers "does the bare binary resolve on PortOS's PATH?", which says nothing+ // about a provider configured as `/opt/tools/codex` or one that overrides+ // `PATH` in its own env — the runner spawns those against their own+ // resolution. Badging them NEEDS SETUP accuses a working provider, and the+ // server (which owns the routing decision) already declines to. The install+ // widget still renders from the same row: "PortOS can install this for you"+ // remains true and useful either way.+ if (runtime && runtime.installed === false && !resolvesOutsidePortosPath(provider)) {addMissing('runtime', `${runtime.label || 'Runtime'} is not installed`);}if (!published) {diff --git a/client/src/utils/providers.test.js b/client/src/utils/providers.test.jsindex 0947ecd278..5d3a37b780 100644--- a/client/src/utils/providers.test.js+++ b/client/src/utils/providers.test.js@@ -1258,6 +1258,18 @@ describe('providerCardState', () => {.toBe(PROVIDER_CARD_STATE.READY);});+ // The RFC1918 test matches a prefix; without an IPv4-literal gate it also+ // claims DNS names that merely start like one, waving a real public endpoint+ // through as needing no key.+ it.each([+ 'https://10.evil.example/v1',+ 'https://172.16.evil.example/v1',+ 'https://100.64.evil.example/v1',+ ])('still demands a key from %s, which only LOOKS like a private range', (endpoint) => {+ expect(providerCardState({ id: 'spoof', type: 'api', endpoint, enabled: true }).state)+ .toBe(PROVIDER_CARD_STATE.BLOCKED);+ });+it('still demands a key from a public endpoint', () => {expect(providerCardState({ id: 'cloud', type: 'api', endpoint: 'https://api.example.com/v1', enabled: true }).state).toBe(PROVIDER_CARD_STATE.BLOCKED);@@ -1335,6 +1347,18 @@ describe('providerCardState', () => {expect(readiness.missing).toEqual([{ code: 'runtime', label: 'LM Studio is not installed' }]);});+ // The runtime row answers "is the BARE binary on PortOS's PATH?" — which is+ // not this provider's question. The server declines to route on it, so the+ // badge must not accuse it either.+ it.each([+ ['an explicit command path', { command: '/opt/example/bin/opencode' }],+ ['a PATH of its own in envVars', { envVars: { PATH: '/opt/example/bin' } }],+ ])('does not badge a provider that resolves outside PortOS PATH — %s', (_label, over) => {+ const readiness = providerCardState(cli(over), { runtime: { label: 'OpenCode CLI', installed: false } });+ expect(readiness.state).toBe(PROVIDER_CARD_STATE.READY);+ expect(readiness.missing).toEqual([]);+ });+it('does not double-report a runtime both sides found missing', () => {const readiness = providerCardState(cli({ missingPrerequisites: [{ code: 'runtime', label: 'OpenCode CLI is not installed' }] }),diff --git a/server/lib/README.md b/server/lib/README.mdindex 192a1b55f7..860f69be25 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -109,7 +109,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `aiProvider.js` | Shared AI provider utilities for LLM calls. || `promptRunner.js` | Shared LLM runner wrapper. || `providerCooldown.js` | Provider bench policy — `resolveProviderBench(analysis)` → `null` (don't bench) / a `usage-limit` marker / an `unavailable` marker with the per-category cooldown from `COOLDOWN_MS_BY_CATEGORY`. Declines to bench request/response-specific categories (`isRequestSpecificCategory` / `isSchemaTypeCategory`) so one bad model id or off-shape response can't take a healthy provider offline. Shared by `promptRunner.js` (prompt cascade) and `services/agentFinalization.js` (finished CoS agent run) so both bench a category for the same window. Pure. |-| `providerPrerequisites.js` | Can a provider run on this host AT ALL — `providerPrerequisites(provider, { runtime, orcaRouterKeySet })` → `{ met, missing: [{ code, label }] }` (CLI binary on PATH, API key stored for a public endpoint, the sibling key an OrcaRouter wrapper inherits), plus `providerRuntimeKey` (`null` for an API provider AND for a command carrying an explicit path — the runtime table only answers "does the BARE binary resolve on PATH?"), `isPrivateNetworkEndpoint` (mirror of the client copy: loopback/RFC1918/tailnet CGNAT + ULA/`.ts.net`/single-label hosts need no key) and `describeMissingPrerequisites`. `runtime: null` = NOT PROBED and never counts as missing. Feeds BOTH `GET /api/providers` and the fallback chain in `aiToolkit/providerStatus.js` (via `services/providerPrerequisites.js`), so a `NEEDS SETUP` card and the router read one computation (#4611). `ROUTING_BLOCKING_CODES`/`blocksRouting(missing)` narrow what ROUTING may act on to the missing binary — a credential finding stays presentation-only until #4612 teaches this module about env-var credentials, since a provider can authenticate through one. Pure. |+| `providerPrerequisites.js` | Can a provider run on this host AT ALL — `providerPrerequisites(provider, { runtime, orcaRouterKeySet })` → `{ met, missing: [{ code, label }] }` (CLI binary on PATH, API key stored for a public endpoint, the sibling key an OrcaRouter wrapper inherits), plus `providerRuntimeKey` (`null` for an API provider, for a command carrying an explicit path, and for a provider with its own `PATH` in `envVars` — the runtime table only answers "does the BARE binary resolve on PortOS's PATH?", which is not those providers' question), `isPrivateNetworkEndpoint` (mirror of the client copy: loopback/RFC1918/tailnet CGNAT + ULA/`.ts.net`/single-label hosts need no key) and `describeMissingPrerequisites`. `runtime: null` = NOT PROBED and never counts as missing. Feeds BOTH `GET /api/providers` and the fallback chain in `aiToolkit/providerStatus.js` (via `services/providerPrerequisites.js`), so a `NEEDS SETUP` card and the router read one computation (#4611). `ROUTING_BLOCKING_CODES`/`blocksRouting(missing)` narrow what ROUTING may act on to the missing binary — a credential finding stays presentation-only until #4612 teaches this module about env-var credentials, since a provider can authenticate through one. Pure. || `tuiPromptRunner.js` | One-shot TUI prompt runner (PTY-driven). || `tuiHandshake.js` | Shared TUI invocation + paste-handshake constants. Also owns `SUBMIT_KEY` — the single Enter byte every PTY writer sends, whether it's submitting a pasted TUI prompt or a command PortOS injected into a shell session. It is CR, never LF: a POSIX pty's ICRNL hides the difference, but cmd.exe under Windows ConPTY accepts only CR and leaves an LF-terminated line typed-but-unexecuted at the prompt. || `tuiUsageScrape.js` | `scrapeTuiUsage({ command, slashCommand, … })` + `USAGE_SANDBOX_DIR` — drive an agy/grok TUI in a sandbox PTY, send a slash command, return the ANSI-stripped screen (for quota panels `--print` can't reach). |diff --git a/server/lib/providerPrerequisites.js b/server/lib/providerPrerequisites.jsindex e2a687118e..fd1b8db510 100644--- a/server/lib/providerPrerequisites.js+++ b/server/lib/providerPrerequisites.js@@ -45,6 +45,17 @@ import { commandBasename } from './providerModels.js';*/const PRIVATE_IP_RE = /^(?:10\.|192\.168\.|172\.(?:1[6-9]|2\d|3[01])\.|169\.254\.|100\.(?:6[4-9]|[7-9]\d|1[01]\d|12[0-7])\.)/;+/**+ * Gate for {@link PRIVATE_IP_RE}: is this host an IPv4 literal at all?+ *+ * The range test above matches a PREFIX, which on its own also claims DNS names+ * that merely start like one — `10.evil.example`, `172.16.evil.example` — and+ * would report a keyless PUBLIC endpoint as needing no key. Hosts arriving here+ * have already been through `URL`, which canonicalizes any IPv4 spelling to a+ * dotted quad, so this is the exact shape a real address takes.+ */+const isIpv4Literal = (host) => /^\d{1,3}(?:\.\d{1,3}){3}$/.test(host);+/*** IPv6 counterpart to {@link PRIVATE_IP_RE}: unique-local (`fc00::/7`) and* link-local (`fe80::/10`). Tailscale hands out a ULA address alongside the@@ -105,7 +116,7 @@ export const isPrivateNetworkEndpoint = (endpoint) => {const host = endpointHost(endpoint);if (host === null) return false;if (isLocalInstanceHost(host)) return true;- if (PRIVATE_IP_RE.test(host)) return true;+ if (isIpv4Literal(host) && PRIVATE_IP_RE.test(host)) return true;if (isPrivateIpv6(host)) return true;if (/\.(local|internal|lan|home\.arpa|ts\.net)$/.test(host)) return true;// A single-label host resolves only inside the local network (`http://nas:11434`).@@ -135,6 +146,10 @@ export const providerRuntimeKey = (provider) => {if (!isProcessProvider(provider)) return null;const command = typeof provider?.command === 'string' ? provider.command.trim() : '';if (command === '' || /[\\/]/.test(command)) return null;+ // Same reasoning as the explicit path: a provider that overrides `PATH` in its+ // own env is resolved against THAT path at spawn time (`buildCliChildEnv`),+ // not the one the table scanned, so the table's answer isn't about it.+ if (Object.keys(provider?.envVars || {}).some((key) => key.toUpperCase() === 'PATH')) return null;return commandBasename(command) || null;};diff --git a/server/lib/providerPrerequisites.test.js b/server/lib/providerPrerequisites.test.jsindex 501693966a..df1b93a46a 100644--- a/server/lib/providerPrerequisites.test.js+++ b/server/lib/providerPrerequisites.test.js@@ -27,6 +27,14 @@ describe('providerRuntimeKey', () => {expect(providerRuntimeKey(cli({ command: 'C:\\tools\\codex.exe' }))).toBeNull();});+ // Same reasoning: the runner resolves such a provider against ITS PATH, not+ // the one the table scanned.+ it('is null for a provider carrying its own PATH', () => {+ expect(providerRuntimeKey(cli({ envVars: { PATH: '/opt/example/bin' } }))).toBeNull();+ expect(providerRuntimeKey(cli({ envVars: { path: '/opt/example/bin' } }))).toBeNull();+ expect(providerRuntimeKey(cli({ envVars: { ANTHROPIC_BASE_URL: 'http://localhost:11434' } }))).toBe('codex');+ });+it('is null for a provider with no spawned command', () => {expect(providerRuntimeKey(api())).toBeNull();expect(providerRuntimeKey(cli({ command: '' }))).toBeNull();@@ -58,6 +66,9 @@ describe('isPrivateNetworkEndpoint', () => {'http://192.0.2.10:1234/v1', // TEST-NET-1 is routable, not private'http://fdrive.example.com', // must not match the fc00::/7 hextet rule by prefix'http://[fd::1]:11434', // leading hextet 0x00fd is NOT in fc00::/7+ 'https://10.evil.example', // a DNS name that merely STARTS like RFC1918+ 'https://172.16.evil.example',+ 'https://100.64.evil.example','','not a url at all ::::',])('treats %s as NOT private', (endpoint) => {