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: 7 Copilot findings on v1.54.0 PR (iter 2)

[._.]/ Adam Eivye2d5f141abee
diff --git a/package-lock.json b/package-lock.json
index 9d2c10f109..b92fb88369 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1209,33 +1209,6 @@
"optional": true
}
}
- },
- "server": {
- "name": "portos-server",
- "version": "1.7.1",
- "extraneous": true,
- "dependencies": {
- "axios": "^1.7.9",
- "cors": "^2.8.5",
- "express": "^5.2.1",
- "multer": "^2.0.2",
- "node-pty": "^1.2.0-beta.10",
- "pg": "^8.19.0",
- "pm2": "^5.4.3",
- "portos-ai-toolkit": "^0.8.0",
- "sax": "^1.4.4",
- "socket.io": "^4.8.3",
- "socket.io-client": "^4.8.3",
- "unzipper": "^0.12.3",
- "uuid": "^11.0.3",
- "ws": "^8.18.0",
- "zod": "^3.24.1"
- },
- "devDependencies": {
- "@vitest/coverage-v8": "^4.0.16",
- "supertest": "^7.1.4",
- "vitest": "^4.0.16"
- }
}
}
}
diff --git a/server/lib/aiToolkit/index.js b/server/lib/aiToolkit/index.js
index 0911fe77bd..ac228eca68 100644
--- a/server/lib/aiToolkit/index.js
+++ b/server/lib/aiToolkit/index.js
@@ -114,12 +114,14 @@ export function createAIToolkit(config = {}) {
},
mountRoutes(app, basePath = '/api') {
- app.use(`${basePath}/providers`, providersRouter);
- app.use(`${basePath}/runs`, runsRouter);
- app.use(`${basePath}/prompts`, promptsRouter);
+ // Mount the more specific /providers/status BEFORE /providers so that
+ // the providers router's GET /:id doesn't intercept "status" as an id.
if (providerStatusRouter) {
app.use(`${basePath}/providers/status`, providerStatusRouter);
}
+ app.use(`${basePath}/providers`, providersRouter);
+ app.use(`${basePath}/runs`, runsRouter);
+ app.use(`${basePath}/prompts`, promptsRouter);
}
};
}
diff --git a/server/lib/aiToolkit/providerStatus.js b/server/lib/aiToolkit/providerStatus.js
index fe65fe4468..f4a34070e6 100644
--- a/server/lib/aiToolkit/providerStatus.js
+++ b/server/lib/aiToolkit/providerStatus.js
@@ -141,7 +141,24 @@ export function createProviderStatusService(config = {}) {
},
getAllStatuses() {
- return { ...statusCache };
+ // Apply the same recovery check getStatus() uses so the aggregate
+ // endpoint reports a recovered provider as available instead of
+ // returning the stale cached unavailable entry.
+ const now = Date.now();
+ const providers = {};
+ for (const [id, status] of Object.entries(statusCache.providers || {})) {
+ if (status.estimatedRecovery && now > new Date(status.estimatedRecovery).getTime()) {
+ providers[id] = {
+ available: true,
+ reason: 'ok',
+ message: 'Provider available',
+ lastChecked: new Date().toISOString()
+ };
+ } else {
+ providers[id] = status;
+ }
+ }
+ return { ...statusCache, providers };
},
isAvailable(providerId) {
diff --git a/server/lib/aiToolkit/runner.js b/server/lib/aiToolkit/runner.js
index 60c71bb017..864e2cd761 100644
--- a/server/lib/aiToolkit/runner.js
+++ b/server/lib/aiToolkit/runner.js
@@ -378,7 +378,12 @@ export function createRunnerService(config = {}) {
}
}
- if (!output.trim() && reasoning.trim()) {
+ // Capture the fallback decision BEFORE mutating `output` — otherwise
+ // the metadata check below (`!output.trim() && reasoning.trim()`) is
+ // always false on the reasoning-only path because `output` was just
+ // overwritten with the reasoning text.
+ const usedReasoningAsFallback = !output.trim() && reasoning.trim().length > 0;
+ if (usedReasoningAsFallback) {
console.log(`🧠 Reasoning model detected - using reasoning as output (${reasoning.length} chars)`);
output = reasoning;
onData?.({ text: reasoning, isReasoning: true });
@@ -394,7 +399,7 @@ export function createRunnerService(config = {}) {
metadata.success = true;
metadata.outputSize = Buffer.byteLength(output);
metadata.hadReasoning = reasoning.length > 0;
- metadata.usedReasoningAsFallback = !output.trim() && reasoning.trim();
+ metadata.usedReasoningAsFallback = usedReasoningAsFallback;
await writeFile(metadataPath, JSON.stringify(metadata, null, 2));
hooks.onRunCompleted?.(metadata, output);
diff --git a/server/services/worldBuilder.js b/server/services/worldBuilder.js
index 6c5d38efd1..c285a759e5 100644
--- a/server/services/worldBuilder.js
+++ b/server/services/worldBuilder.js
@@ -241,18 +241,22 @@ export const sanitizeInfluences = (raw = {}) => {
// Build a refined influences object that honors per-list locks. Locked lists
// take their value from `fallback` (originals); unlocked lists take from
-// `fresh` (the LLM output), falling back to `fallback` when the LLM omitted
-// that list. Mirrors `mergeInfluencesWithLocks` in client/services/apiWorldBuilder.js.
+// `fresh` (the LLM output), falling back to `fallback` ONLY when the LLM
+// omitted that list (key absent). An explicit `[]` is applied so the user
+// can intentionally clear an unlocked list. Mirrors `mergeInfluencesWithLocks`
+// in client/services/apiWorldBuilder.js.
export const mergeInfluencesWithLocks = (locked, fresh, fallback) => {
const freshSafe = sanitizeInfluences(fresh);
const fallbackSafe = sanitizeInfluences(fallback);
+ const freshHasEmbrace = Array.isArray(fresh?.embrace);
+ const freshHasAvoid = Array.isArray(fresh?.avoid);
return {
embrace: locked?.influencesEmbrace
? fallbackSafe.embrace
- : (freshSafe.embrace.length ? freshSafe.embrace : fallbackSafe.embrace),
+ : (freshHasEmbrace ? freshSafe.embrace : fallbackSafe.embrace),
avoid: locked?.influencesAvoid
? fallbackSafe.avoid
- : (freshSafe.avoid.length ? freshSafe.avoid : fallbackSafe.avoid),
+ : (freshHasAvoid ? freshSafe.avoid : fallbackSafe.avoid),
};
};
@@ -276,13 +280,18 @@ const appendUnique = (existing, additions) => {
export const mergeInfluencesWithLocksAdditive = (locked, fresh, fallback) => {
const freshSafe = sanitizeInfluences(fresh);
const fallbackSafe = sanitizeInfluences(fallback);
+ // Distinguish "LLM omitted the list" (preserve fallback) from "LLM
+ // returned []" (apply — user explicitly cleared the unlocked list).
+ // The additive locked path is unaffected: an empty append-list is a no-op.
+ const freshHasEmbrace = Array.isArray(fresh?.embrace);
+ const freshHasAvoid = Array.isArray(fresh?.avoid);
return {
embrace: locked?.influencesEmbrace
? appendUnique(fallbackSafe.embrace, freshSafe.embrace)
- : (freshSafe.embrace.length ? freshSafe.embrace : fallbackSafe.embrace),
+ : (freshHasEmbrace ? freshSafe.embrace : fallbackSafe.embrace),
avoid: locked?.influencesAvoid
? appendUnique(fallbackSafe.avoid, freshSafe.avoid)
- : (freshSafe.avoid.length ? freshSafe.avoid : fallbackSafe.avoid),
+ : (freshHasAvoid ? freshSafe.avoid : fallbackSafe.avoid),
};
};
diff --git a/server/services/worldBuilderRefine.js b/server/services/worldBuilderRefine.js
index 2078426061..8e89ac8603 100644
--- a/server/services/worldBuilderRefine.js
+++ b/server/services/worldBuilderRefine.js
@@ -463,10 +463,16 @@ export async function refineWorldPrompts({
});
}
const safeLocked = sanitizeLocked(locked);
- // Refusing the run if everything is locked spares the user a confusing
- // "nothing changed" outcome (the LLM would echo every field, then the
- // server would overwrite with originals, then the modal would show no diff).
- if (LOCKABLE_FIELDS.every((k) => safeLocked[k])) {
+ // hasStructure also unblocks an all-top-level-locked refine — the user
+ // can still want to tune unlocked variations or composite boards.
+ const hasStructure =
+ (categories && typeof categories === "object" && Object.keys(categories).length > 0) ||
+ (Array.isArray(compositeSheets) && compositeSheets.length > 0);
+ // Refusing the run if everything is locked AND there is no structure spares
+ // the user a confusing "nothing changed" outcome (the LLM would echo every
+ // field, then the server would overwrite with originals, then the modal
+ // would show no diff). When there is structure to refine, fall through.
+ if (LOCKABLE_FIELDS.every((k) => safeLocked[k]) && !hasStructure) {
throw new ServerError(
"All fields are locked — unlock at least one before refining",
{ status: 400, code: "ALL_FIELDS_LOCKED" },
@@ -504,10 +510,6 @@ export async function refineWorldPrompts({
// Trim originals up front so we can pass them to both the LLM AND use them
// verbatim as the lock fallback below.
- const hasStructure =
- (categories && typeof categories === "object" && Object.keys(categories).length > 0) ||
- (Array.isArray(compositeSheets) && compositeSheets.length > 0);
-
const originals = {
starterPrompt: trimTo(starterPrompt, STARTER_PROMPT_MAX),
stylePrompt: trimTo(stylePrompt, PROMPT_FRAGMENT_MAX),
@@ -551,9 +553,11 @@ export async function refineWorldPrompts({
};
// Scalar fields: if locked, echo the original; otherwise take the LLM's
- // value (or fall back to original when missing/empty so the modal never
- // receives a blank where the user had content). Influences is an object
- // with per-list locks — handled separately below.
+ // value, distinguishing "key absent / null" (fall back to original) from
+ // an intentional "" (apply — the user asked to clear it). Mirrors the
+ // expand merge's pick semantics so an unlocked field like negativePrompt
+ // can actually be cleared by refine. Influences uses per-list locks and is
+ // handled separately below.
const refined = {};
for (const key of LOCKABLE_FIELDS) {
if (isInfluenceLockField(key)) continue;
@@ -561,8 +565,12 @@ export async function refineWorldPrompts({
refined[key] = originals[key];
continue;
}
- const llmValue = trimTo(parsed[key], FIELD_CAPS[key]);
- refined[key] = llmValue || originals[key];
+ const raw = parsed[key];
+ if (raw === null || raw === undefined) {
+ refined[key] = originals[key];
+ } else {
+ refined[key] = trimTo(raw, FIELD_CAPS[key]);
+ }
}
// Refine path uses APPEND-ONLY semantics for locked influence lists — the
// user wants "lock = don't rebuild, but you may append". Expand still calls