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: 6 Copilot findings on v1.54.0 PR

[._.]/ Adam Eivy419620ef6615
diff --git a/PLAN.md b/PLAN.md
index a157731846..a80c3b5ae9 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -10,21 +10,17 @@ For project goals, see [GOALS.md](./GOALS.md). For completed work, see [DONE.md]
### v1.54.0 release-review deferred items
-Captured 2026-05-13 during /do:release; rated below release-blocker but worth picking up:
+Captured 2026-05-13 during /do:release; rated below release-blocker but worth picking up. Six of the originals landed in the release PR after Copilot review — only items below remained.
-- [ ] **`WorldPromptRefineModal.jsx:182-185` — empty-list fallback restores deleted unlocked influences.** When a user has an unlocked embrace/avoid list and asks the LLM to clear it, the LLM returns `[]` but the client falls back to `originals.influences.*`, so the cleared list is silently restored. The diff modal shows the empty list to the user, so they can see it before applying — but Apply then ignores the diff. Drop the `.length ? a : b` guard for unlocked lists (locked path is already covered by server-side `mergeInfluencesWithLocksAdditive`). Add a regression test that sets `locked.influencesEmbrace = false`, LLM returns `embrace: []`, and asserts the patch carries `embrace: []`.
- [ ] **Holistic refine deletion confirmation UX.** Refine can silently delete every unlocked variation/composite if the LLM omits them — by design (`drops unlocked items the LLM omits` test pins this), but the Apply button doesn't surface the deletion count. Add a "N items will be removed" callout in `StructureDiff` or an explicit confirm step in `WorldPromptRefineModal.handleApply`. `client/src/components/worldBuilder/WorldPromptRefineModal.jsx:187-189`.
- [ ] **`mergeVariations` NPE guard in `WorldBuilder.jsx:435-445`.** `new Set(locked.map((v) => v.label.toLowerCase()))` assumes every locked variation has a string label. Mid-edit drafts could violate this. Match the `fresh` loop's `v.label?.toLowerCase()` guard and `.filter(Boolean)`.
-- [ ] **`server/routes/worldBuilder.js` lockedSchema strict-mode rejects legacy `influences` key.** `sanitizeLocked` migrates `locked.influences: true` → per-list locks on read, but the PATCH route's `lockedSchema.strict()` 400s if a stale client/script sends the legacy key. Either drop `.strict()` or whitelist `influences: z.boolean().optional()` so the migration story is symmetric. Single-user impact, but cleaner.
- [ ] **Client tests for deep routing + drag.** No React Testing Library coverage for `/world-builder/:worldId` URL state, `@dnd-kit` chip reorder, or the localStorage-backed sidebar collapse. Add smoke tests for `goToWorld(id)` URL transitions and chip-reorder ordering (mock `useSortable`).
-- [ ] **`server/lib/aiToolkit/providers.js:200` — `testProvider` calls `execAsync(\`which ${provider.command}\`)` with user-controlled `command`.** Vendored from the published toolkit; PortOS is single-user/no-auth so this is "self-injection" only, but the field has no allowlist or escape. Switch to `execFile`/`spawn` with args array, or validate `provider.command` against `/^[A-Za-z0-9_-]+$/` before execAsync.
- [ ] **`server/lib/aiToolkit/providers.js:25-31` — codex migration destructively drops extra `models[]` entries.** If `models` is `[sentinel, "gpt-5"]` (transitional/manual state), the migration overwrites the whole array with `[sentinel]`, silently losing extras. Either preserve non-sentinel entries or log a `console.warn` before overwrite.
- [ ] **`server/lib/aiToolkit/routes/providers.js:47-60, 62-70` — POST/PUT skip Zod validation.** `providerSchema` exists in `validation.js` but is never applied; routes only do ad-hoc `name`/`type` checks. Per PortOS convention all route inputs should validate. Wire `validate(providerSchema, req.body)` or remove `validation.js` as dead code.
- [ ] **`server/lib/aiToolkit/validation.js:3-17` — schema missing `fallbackProvider`, `lightModel`, `mediumModel`, `heavyModel`.** Schema doesn't match `createProvider()`'s field list. If validation is ever wired up, valid requests with these new fields will be stripped or rejected. Add them.
- [ ] **`server/lib/aiToolkit/providers.js:124-143` — `createProvider` explicit field list vs. `updateProvider` spread asymmetry.** Future fields added to the UI but not to `createProvider`'s explicit list are silently dropped on creation but preserved on update. Add an end-to-end test that creates a provider with every field from `providers.sample.json` and asserts persistence, or switch `createProvider` to spread.
- [ ] **`server/index.js:222-224` — providers warm-up is fire-and-forget.** Comment claims it "lands before any inbound request can race a concurrent write," but PortOS is single-process and the call is unawaited. Works incidentally because the awaited startup chain runs long, not by guarantee. Either `await aiToolkit.services.providers.getAllProviders()` before `httpServer.listen()`, or rewrite the comment to match reality ("pre-warm the providers cache and let the migration log fire before request logging starts").
- [ ] **`server/lib/aiToolkit/providers.js:70-76` — corrupt `providers.json` crashes warm-up.** Truncated JSON throws from `JSON.parse` in `loadProviders`, and every subsequent request also throws. Wrap parse in try/catch; on failure rename the bad file to `.corrupt` and fall back to the sample.
-- [ ] **`server/lib/aiToolkit/runner.js:52-59` — `safeJsonParse` is not actually safe.** Function name suggests safety but contains an unguarded `JSON.parse`. Wrap in try/catch and return `fallback` on parse failure.
## Backlog
diff --git a/client/src/components/worldBuilder/WorldPromptRefineModal.jsx b/client/src/components/worldBuilder/WorldPromptRefineModal.jsx
index 2f787d08f3..f3de2d5bbb 100644
--- a/client/src/components/worldBuilder/WorldPromptRefineModal.jsx
+++ b/client/src/components/worldBuilder/WorldPromptRefineModal.jsx
@@ -120,7 +120,15 @@ export default function WorldPromptRefineModal({
if (!open) return null;
- const allLocked = WORLD_LOCKABLE_FIELDS.every((k) => locked[k]);
+ const allTopLocked = WORLD_LOCKABLE_FIELDS.every((k) => locked[k]);
+ // The button stays enabled when there's *any* category variation or composite
+ // sheet present — the holistic refine flow can still tune unlocked structure
+ // items even if every top-level bible field is locked.
+ const hasRefinableStructure = (
+ (categories && Object.values(categories).some((cat) => (cat?.variations || []).length > 0))
+ || (Array.isArray(compositeSheets) && compositeSheets.length > 0)
+ );
+ const allLocked = allTopLocked && !hasRefinableStructure;
const hasResult = Object.keys(refined).length > 0 || rationale !== '';
const canRefine = feedback.trim() && starterPrompt.trim() && selectedProviderId && !refining && !allLocked;
const canApply = hasResult && (refined.starterPrompt || '').trim();
@@ -176,13 +184,19 @@ export default function WorldPromptRefineModal({
}
const refinedInf = ensureInfluences(refined.influences);
const origInf = originals.influences;
- // Influences in refine mode are append-only when locked, so the server's
- // returned list is always safe to apply directly (locked tokens are
- // preserved in order, new tokens appended).
- patch.influences = {
- embrace: refinedInf.embrace.length ? refinedInf.embrace : origInf.embrace,
- avoid: refinedInf.avoid.length ? refinedInf.avoid : origInf.avoid,
- };
+ // Locked lists are append-only server-side (returned list always contains
+ // locked tokens in order). Unlocked lists may be cleared by the LLM in
+ // response to feedback like "drop all influences" — apply the empty list
+ // when it's an explicit decision rather than an omission. `refined` only
+ // carries `influences` when the server actually returned one, so a missing
+ // key here means "no change" and falls back to the originals.
+ const refinedHasInfluences = Object.prototype.hasOwnProperty.call(refined, 'influences');
+ if (refinedHasInfluences) {
+ patch.influences = {
+ embrace: locked.influencesEmbrace && refinedInf.embrace.length === 0 ? origInf.embrace : refinedInf.embrace,
+ avoid: locked.influencesAvoid && refinedInf.avoid.length === 0 ? origInf.avoid : refinedInf.avoid,
+ };
+ }
// Server already enforced per-item locks before returning these.
if (refined.categories) patch.categories = refined.categories;
if (refined.compositeSheets) patch.compositeSheets = refined.compositeSheets;
diff --git a/server/lib/aiToolkit/providerStatus.js b/server/lib/aiToolkit/providerStatus.js
index 6124c2eb9f..fe65fe4468 100644
--- a/server/lib/aiToolkit/providerStatus.js
+++ b/server/lib/aiToolkit/providerStatus.js
@@ -116,12 +116,28 @@ export function createProviderStatusService(config = {}) {
},
getStatus(providerId) {
- return statusCache.providers[providerId] || {
- available: true,
- reason: 'ok',
- message: 'Provider available',
- lastChecked: new Date().toISOString()
- };
+ const status = statusCache.providers[providerId];
+ if (!status) {
+ return {
+ available: true,
+ reason: 'ok',
+ message: 'Provider available',
+ lastChecked: new Date().toISOString()
+ };
+ }
+ // Auto-recover when the estimatedRecovery deadline has passed — without
+ // this check a provider remains marked unavailable until the next
+ // service restart (or an explicit markAvailable call) even after its
+ // wait window has elapsed, so fallback selection keeps skipping it.
+ if (status.estimatedRecovery && Date.now() > new Date(status.estimatedRecovery).getTime()) {
+ return {
+ available: true,
+ reason: 'ok',
+ message: 'Provider available',
+ lastChecked: new Date().toISOString()
+ };
+ }
+ return status;
},
getAllStatuses() {
diff --git a/server/lib/aiToolkit/providers.js b/server/lib/aiToolkit/providers.js
index 7fa5bfb65e..6361441425 100644
--- a/server/lib/aiToolkit/providers.js
+++ b/server/lib/aiToolkit/providers.js
@@ -2,13 +2,13 @@ import { readFile, writeFile, mkdir } from 'fs/promises';
import { existsSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
-import { exec } from 'child_process';
+import { execFile } from 'child_process';
import { promisify } from 'util';
const __dirname = dirname(fileURLToPath(import.meta.url));
const DEFAULT_SAMPLE_PATH = join(__dirname, 'defaults/providers.sample.json');
-const execAsync = promisify(exec);
+const execFileAsync = promisify(execFile);
const CODEX_CONFIGURED_DEFAULT = 'codex-configured-default';
const CODEX_MODEL_KEYS = ['defaultModel', 'lightModel', 'mediumModel', 'heavyModel'];
@@ -197,18 +197,25 @@ export function createProviderService(config = {}) {
}
if (provider.type === 'cli') {
- const { stdout } = await execAsync(`which ${provider.command}`).catch(() => ({ stdout: '', stderr: 'not found' }));
+ // Use execFile (no shell) so user-configured `provider.command` cannot
+ // inject extra shell commands via metacharacters.
+ const { stdout } = await execFileAsync('which', [provider.command])
+ .catch(() => ({ stdout: '', stderr: 'not found' }));
if (!stdout.trim()) {
return { success: false, error: `Command '${provider.command}' not found in PATH` };
}
- const { stdout: versionOut } = await execAsync(`${provider.command} --version 2>/dev/null || ${provider.command} -v 2>/dev/null || echo "available"`).catch(() => ({ stdout: 'available' }));
+ const tryVersion = async (flag) => {
+ const out = await execFileAsync(provider.command, [flag]).catch(() => null);
+ return out?.stdout?.trim() || null;
+ };
+ const versionOut = (await tryVersion('--version')) || (await tryVersion('-v')) || 'available';
return {
success: true,
path: stdout.trim(),
- version: versionOut.trim()
+ version: versionOut
};
}
diff --git a/server/lib/aiToolkit/runner.js b/server/lib/aiToolkit/runner.js
index a6acc51116..60c71bb017 100644
--- a/server/lib/aiToolkit/runner.js
+++ b/server/lib/aiToolkit/runner.js
@@ -54,8 +54,12 @@ export function createRunnerService(config = {}) {
return fallback;
}
- const parsed = JSON.parse(str);
- return parsed ?? fallback;
+ try {
+ const parsed = JSON.parse(str);
+ return parsed ?? fallback;
+ } catch {
+ return fallback;
+ }
}
async function handleProviderError(providerId, errorAnalysis, output) {
diff --git a/server/routes/worldBuilder.js b/server/routes/worldBuilder.js
index 1b16d113bf..01b8afd2cf 100644
--- a/server/routes/worldBuilder.js
+++ b/server/routes/worldBuilder.js
@@ -69,10 +69,14 @@ const llmSchema = z.object({
// `locked` is a sparse map of `{ field: true }` for the LOCKABLE_FIELDS list.
// `false` is treated the same as omitted — only `true` records a lock so the
-// stored shape stays minimal and additive.
-const lockedSchema = z.object(
- Object.fromEntries(svc.LOCKABLE_FIELDS.map((k) => [k, z.boolean().optional()])),
-).strict();
+// stored shape stays minimal and additive. Accept legacy `influences` key as
+// an alias for both `influencesEmbrace` and `influencesAvoid` so older clients
+// PATCHing a previously saved lock map still pass validation (sanitizeLocked
+// rewrites it on read into the per-list keys).
+const lockedSchema = z.object({
+ ...Object.fromEntries(svc.LOCKABLE_FIELDS.map((k) => [k, z.boolean().optional()])),
+ influences: z.boolean().optional(),
+}).strict();
const influenceEntrySchema = z.string().trim().min(1).max(svc.INFLUENCE_ENTRY_MAX);
const influencesSchema = z.object({