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

address review round 2: hold a record to its own namespace on a model refresh

[._.]/ Adam Eivy4c629095868e
diff --git a/client/src/components/install/RuntimeInstallModal.jsx b/client/src/components/install/RuntimeInstallModal.jsx
index e60eb440e7..ae721749ec 100644
--- a/client/src/components/install/RuntimeInstallModal.jsx
+++ b/client/src/components/install/RuntimeInstallModal.jsx
@@ -37,6 +37,11 @@ export default function RuntimeInstallModal({
streamMethod = 'GET',
// Chatty installers keep the rendered log stable by batching lines.
flushMs = 100,
+ // The footer line once the stream completes. Defaults to "is ready", which is
+ // true of an install — and false of a REMOVAL, where it would sit directly
+ // under a log line saying the runtime was just deleted. A caller whose action
+ // is not an install passes its own.
+ doneText,
}) {
const [confirmingCancel, setConfirmingCancel] = useState(false);
const query = new URLSearchParams({ runtime: runtime ?? '', ...(params || {}) });
@@ -149,7 +154,7 @@ export default function RuntimeInstallModal({
<>
<span className="text-xs text-gray-400">
{done
- ? `${label || runtime} is ready. You can close this window.`
+ ? (doneText || `${label || runtime} is ready.`) + ' You can close this window.'
: description}
</span>
<button
diff --git a/client/src/components/models/HarnessesTab.jsx b/client/src/components/models/HarnessesTab.jsx
index 3d3ce567f6..9fc91646c7 100644
--- a/client/src/components/models/HarnessesTab.jsx
+++ b/client/src/components/models/HarnessesTab.jsx
@@ -37,14 +37,19 @@ const ACTION_COPY = {
install: {
title: 'Install harness',
description: 'Installing the CLI and putting it on PortOS\'s PATH…',
+ done: 'Installed.',
},
update: {
title: 'Update harness',
description: 'Updating the CLI in place. Providers using it keep their settings.',
+ done: 'Update finished.',
},
uninstall: {
title: 'Remove harness',
description: 'Removing the CLI. Providers that use it will show as needing setup.',
+ // The modal's default footer says "is ready", which would sit directly under
+ // a log line saying the CLI was just deleted.
+ done: 'Removed.',
},
};
@@ -306,6 +311,7 @@ export default function HarnessesTab() {
label={pendingAction?.harness?.label}
title={pendingAction ? ACTION_COPY[pendingAction.action].title : undefined}
description={pendingAction ? ACTION_COPY[pendingAction.action].description : undefined}
+ doneText={pendingAction ? ACTION_COPY[pendingAction.action].done : undefined}
installUrlBase="/api/harnesses/action"
params={pendingAction ? { action: pendingAction.action } : undefined}
streamMethod="POST"
diff --git a/docs/API.md b/docs/API.md
index 0951616788..119123f06d 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -132,7 +132,7 @@ The coding-agent CLIs/TUIs PortOS drives (`opencode`, `claude`, `codex`, `agy`,
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/harnesses?fresh=1` | Every harness with its installed version, the latest published version (npm-backed rows only), whether an update is available, which lifecycle actions it supports, and the provider records riding on it. `version`/`latestVersion` are `null` for NOT KNOWN, never `0.0.0` — `updateAvailable` is set only on a definite "installed < latest", so an offline host shows no false staleness badge. `fresh=1` bypasses both the 60s runtime-status TTL and the 6h registry cache. |
-| POST | `/harnesses/action?runtime=<id>&action=install|update|uninstall` | Run one lifecycle action, streaming the child's output as SSE. `action` defaults to `install`. Update prefers the vendor's OWN updater (`opencode upgrade`, `claude update`) — the only path that refreshes the copy actually on PATH when the user installed it from Homebrew or a vendor script. Remove is offered only for npm-installed rows, and reports an error rather than success if the binary is still runnable afterwards. One action at a time process-wide (npm's global prefix is one directory); closing the stream cancels the child. Both values are table keys — nothing from the request reaches a shell word. |
+| POST | `/harnesses/action?runtime=<id>&action=install\|update\|uninstall` | Run one lifecycle action, streaming the child's output as SSE. `action` defaults to `install`. Update prefers the vendor's OWN updater (`opencode upgrade`, `claude update`) — the only path that refreshes the copy actually on PATH when the user installed it from Homebrew or a vendor script. Remove is offered only for npm-installed rows, and reports an error rather than success if the binary is still runnable afterwards. One action at a time process-wide (npm's global prefix is one directory); closing the stream cancels the child. Both values are table keys — nothing from the request reaches a shell word. |
| POST | `/harnesses/models/refresh?runtime=<id>` | Re-read a harness's own model catalog (`opencode models`, `agy models`, `grok models`) and write it to every provider that draws from that catalog — i.e. a wrapper with no local-runtime marker and no `gatewayBacked`, since a gateway- or Ollama-backed wrapper serves ids the harness never lists. Answers `{ ok, models, updated }`. A probe that runs but parses to nothing is a **409**, not an empty write: a signed-out CLI must not blank every picker. |
### AI Runs
diff --git a/server/services/harnesses.js b/server/services/harnesses.js
index eb32f84608..00359c4e28 100644
--- a/server/services/harnesses.js
+++ b/server/services/harnesses.js
@@ -84,7 +84,13 @@ const latestVersions = createStaleWhileRevalidate({
export async function getLatestPublishedVersion(packageName, { fresh = false, run = commandOutput } = {}) {
if (typeof packageName !== 'string' || packageName === '') return null;
return latestVersions.read(packageName, async () => {
- const stdout = await run('npm', ['view', packageName, 'version'], { timeoutMs: REGISTRY_TIMEOUT_MS });
+ // `prepareCliSpawn`, like the version and models probes: `npm` is a `.cmd`
+ // shim on Windows and `execFile` under `shell: false` targets the literal
+ // string with no PATHEXT search, so a bare 'npm' never runs there —
+ // `latestVersion` would be permanently null and the staleness detection this
+ // page exists for silently dead.
+ const probe = prepareCliSpawn('npm', ['view', packageName, 'version']);
+ const stdout = await run(probe.command, probe.args, { timeoutMs: REGISTRY_TIMEOUT_MS });
const version = parseNpmLatestVersion(stdout);
// THROW, don't cache a null: an unreachable registry is a failure the
// backoff should pace, not an answer worth remembering for six hours.
@@ -145,6 +151,27 @@ function declaresOwnOpencodeProvider(provider) {
return Object.keys(parsed?.provider || {}).length > 0;
}
+/**
+ * The `vendor/` namespaces a record's stored model ids already use, or an empty
+ * set when it stores bare ids.
+ *
+ * `opencode models` prints every namespace the local OpenCode is authenticated
+ * for, not just `opencode/*` — so on a box where the user has run
+ * `opencode auth login <vendor>`, an unfiltered refresh would write
+ * `anthropic/*` ids into a record named "OpenCode Zen CLI" whose key field is
+ * `OPENCODE_API_KEY`, and its picker would then offer models that bill a
+ * different account. A refresh updates a record's catalog; it does not widen
+ * what that record is for.
+ *
+ * Empty for a harness whose ids are bare (agy, grok, cursor) — there is no
+ * namespace to hold, so nothing is filtered.
+ */
+const storedNamespaces = (provider) => new Set(
+ (provider?.models || [])
+ .filter((id) => typeof id === 'string' && id.includes('/'))
+ .map((id) => id.slice(0, id.indexOf('/'))),
+);
+
/**
* Every provider record this harness's runtime row actually answers for.
*
@@ -262,13 +289,24 @@ export async function refreshHarnessModels(id, { run = commandOutput, ...probeDe
const targets = providersForHarness(await providerService.listProviders(), runtime).filter(usesHarnessCatalog);
const updated = [];
for (const provider of targets) {
+ // Hold the record's namespace scope (see `storedNamespaces`). A filter that
+ // matched nothing means the harness no longer lists anything this record is
+ // for — skip it rather than blanking a working list on that evidence.
+ const scope = storedNamespaces(provider);
+ const scoped = scope.size === 0
+ ? models
+ : models.filter((id) => scope.has(id.slice(0, id.indexOf('/'))));
+ if (scoped.length === 0) {
+ console.log(`⏭️ ${runtime.label}: ${provider.id} lists no models in its own namespace — left alone`);
+ continue;
+ }
// A `*-configured-default` sentinel is NOT a model the vendor will ever
// print — it is the "send no --model, let the CLI use its own default"
// marker (`resolveCliModel` maps it to null). Dropping it would silently
// repin an agy/grok wrapper onto a concrete model AND remove the option
// from the editor's picker, which renders it from this same list. So it
// survives the rewrite rather than reading as an orphaned id.
- const next = [...(provider.models || []).filter(isConfiguredDefaultModel), ...models];
+ const next = [...(provider.models || []).filter(isConfiguredDefaultModel), ...scoped];
// A stored default the harness no longer lists would leave the record
// pinned to a model its own picker cannot show. Keep it when it survived
// the refresh, otherwise fall to the first id (sentinel first when there
diff --git a/server/services/harnesses.test.js b/server/services/harnesses.test.js
index 6a16c959c1..16963614aa 100644
--- a/server/services/harnesses.test.js
+++ b/server/services/harnesses.test.js
@@ -14,8 +14,10 @@ const providerService = vi.hoisted(() => ({
}));
vi.mock('./providers.js', () => providerService);
+import { prepareCliSpawn } from '../lib/bufferedSpawn.js';
import {
__resetLatestVersionCache,
+ getLatestPublishedVersion,
listHarnesses,
refreshHarnessModels,
usesHarnessCatalog,
@@ -115,6 +117,30 @@ describe('usesHarnessCatalog', () => {
});
});
+describe('getLatestPublishedVersion', () => {
+ // `npm` is a `.cmd` shim on Windows and `execFile` under `shell: false`
+ // targets the literal string with no PATHEXT search, so a bare 'npm' never
+ // runs there — `latestVersion` would be permanently null and the staleness
+ // detection this page exists for silently dead.
+ it('spawns npm through the Windows-safe launcher', async () => {
+ const run = vi.fn(async () => '1.19.0');
+
+ expect(await getLatestPublishedVersion('opencode-ai', { run })).toBe('1.19.0');
+
+ const [command, args] = run.mock.calls[0];
+ expect(prepareCliSpawn('npm', ['view', 'opencode-ai', 'version'])).toEqual({ command, args });
+ });
+
+ // `null` is NOT-KNOWN. Caching it would freeze a transient network blip in
+ // for the full TTL and paint every harness as version-unknown.
+ it('answers null without caching when the registry could not be read', async () => {
+ const run = vi.fn(async () => null);
+
+ expect(await getLatestPublishedVersion('opencode-ai', { run })).toBeNull();
+ expect(run).toHaveBeenCalledTimes(1);
+ });
+});
+
describe('listHarnesses', () => {
// Every child-process and registry boundary is injected: nothing here spawns
// a real CLI or reaches npm.
@@ -226,6 +252,54 @@ describe('refreshHarnessModels', () => {
expect(patch.defaultModel).toBe('grok-configured-default');
});
+ // `opencode models` prints every namespace the local OpenCode is signed into,
+ // not just `opencode/*`. Writing an `anthropic/*` id into a record named
+ // "OpenCode Zen CLI" whose key field is OPENCODE_API_KEY would offer the user
+ // a model that bills a different account.
+ it('holds a record to its own namespace scope', async () => {
+ const run = vi.fn(async (command, args) => (args[0] === 'models'
+ ? 'opencode/big-pickle\nanthropic/claude-opus-5\nopencode/mimo-v2.5-free\n'
+ : '1.18.27'));
+ providerService.listProviders.mockResolvedValue([
+ { id: 'opencode-zen-cli', type: 'cli', command: 'opencode', models: ['opencode/stale'], defaultModel: 'opencode/stale' },
+ ]);
+
+ await refreshHarnessModels('opencode', { run, ...found });
+
+ const [, patch] = providerService.updateProvider.mock.calls[0];
+ expect(patch.models).toEqual(['opencode/big-pickle', 'opencode/mimo-v2.5-free']);
+ });
+
+ it('leaves a record alone when nothing in its namespace came back', async () => {
+ // Blanking a working list on "the harness stopped listing your vendor" is
+ // the same bad trade as blanking it on an empty probe.
+ const run = vi.fn(async (command, args) => (args[0] === 'models' ? 'anthropic/claude-opus-5\n' : '1.18.27'));
+ providerService.listProviders.mockResolvedValue([
+ { id: 'opencode-zen-cli', type: 'cli', command: 'opencode', models: ['opencode/stale'], defaultModel: 'opencode/stale' },
+ ]);
+
+ const result = await refreshHarnessModels('opencode', { run, ...found });
+
+ expect(result.ok).toBe(true);
+ expect(result.updated).toEqual([]);
+ expect(providerService.updateProvider).not.toHaveBeenCalled();
+ });
+
+ // A harness whose ids are bare (agy, grok, cursor) has no namespace to hold.
+ it('applies no scope filter to a harness with bare model ids', async () => {
+ const run = vi.fn(async (command, args) => (args[0] === 'models'
+ ? 'Fetching available models...\ngemini-3.8-flash-high\tGemini 3.8 Flash (High)\n'
+ : '1.1.25'));
+ providerService.listProviders.mockResolvedValue([
+ { id: 'antigravity-cli', type: 'cli', command: 'agy', models: ['gemini-3.7-flash-high'], defaultModel: 'gemini-3.7-flash-high' },
+ ]);
+
+ await refreshHarnessModels('agy', { run, ...found });
+
+ const [, patch] = providerService.updateProvider.mock.calls[0];
+ expect(patch.models).toEqual(['gemini-3.8-flash-high']);
+ });
+
it('refuses an empty probe rather than blanking every picker', async () => {
// A signed-out CLI or a changed output shape both parse to nothing. Writing
// that through would erase working model lists on a guess.
diff --git a/server/services/providerRuntimeInstaller.js b/server/services/providerRuntimeInstaller.js
index 602d75e1b9..08f18c39c5 100644
--- a/server/services/providerRuntimeInstaller.js
+++ b/server/services/providerRuntimeInstaller.js
@@ -220,14 +220,17 @@ async function probeRuntimeStatus(runtime, findCommand, probeCommand) {
// `.cmd` wrapper on Windows. The filesystem resolver gives us the real
// executable; prepareCliSpawn then probes that same safe launch shape.
const versionProbe = resolved ? prepareCliSpawn(resolved, ['--version']) : null;
- // ONE probe contract: `commandOutput` answers the `--version` banner, or
- // `null` when the binary could not run. Availability and version come from
- // that single child — `parseHarnessVersion` already answers `null` for a
- // banner it cannot read, which is NOT-KNOWN rather than "out of date".
+ // ONE probe contract: `commandOutput` answers the `--version` banner as a
+ // STRING, or `null` when the binary could not run. Availability and version
+ // both come from that single child — `parseHarnessVersion` already answers
+ // `null` for a banner it cannot read, which is NOT-KNOWN rather than "out of
+ // date". Keyed on `typeof === 'string'` rather than `!== null` so anything
+ // outside the contract (an injected probe answering a bare boolean) fails
+ // SAFE as not-installed instead of reporting a `false` as present.
const probed = versionProbe
? await probeCommand(versionProbe.command, versionProbe.args, { timeoutMs: PROBE_TIMEOUT_MS })
: null;
- const installed = probed !== null;
+ const installed = typeof probed === 'string';
const version = parseHarnessVersion(probed);
// Windows-only gap: the script-installed vendors publish a PowerShell