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 code-review (xhigh): 4 fixes from the batch review

Adam Eivy0b5ab708b470
diff --git a/scripts/lib/envFile.js b/scripts/lib/envFile.js
index ef552f8753..c89d7b2f9e 100644
--- a/scripts/lib/envFile.js
+++ b/scripts/lib/envFile.js
@@ -51,7 +51,10 @@ export function upsertEnvKey(filePath, key, value) {
const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const pattern = new RegExp(`^${escaped}=.*`, 'm');
if (pattern.test(content)) {
- content = content.replace(pattern, `${key}=${value}`);
+ // Replacer FUNCTION (not a string) so `$`-sequences in `value` (e.g. a
+ // password like `p$$word` or `$&`) are written literally instead of being
+ // interpreted as String.replace special patterns.
+ content = content.replace(pattern, () => `${key}=${value}`);
} else {
content = `${key}=${value}\n${content}`;
}
diff --git a/scripts/lib/envFile.test.js b/scripts/lib/envFile.test.js
index 4ea755b386..07bf9ddf7a 100644
--- a/scripts/lib/envFile.test.js
+++ b/scripts/lib/envFile.test.js
@@ -87,4 +87,11 @@ describe('upsertEnvKey', () => {
upsertEnvKey(envPath, 'LLM_BACKEND', 'lmstudio');
expect(parseEnvFile(envPath)).toMatchObject({ LLM_BACKEND: 'lmstudio' });
});
+
+ it('writes values containing $ literally (no String.replace pattern interpretation)', () => {
+ upsertEnvKey(envPath, 'PGPASSWORD', 'placeholder');
+ // $$ , $& , $1 would all be mangled by a string replacement arg.
+ upsertEnvKey(envPath, 'PGPASSWORD', 'p$$ass$&w$1ord');
+ expect(parseEnvFile(envPath)).toMatchObject({ PGPASSWORD: 'p$$ass$&w$1ord' });
+ });
});
diff --git a/server/services/sharing/importer.js b/server/services/sharing/importer.js
index a7ca26c741..6bf7cf1391 100644
--- a/server/services/sharing/importer.js
+++ b/server/services/sharing/importer.js
@@ -412,9 +412,17 @@ async function applyAutoMerge(bucket, manifest, records, { availableAssetKeys =
};
const mergeOne = async ({ kind, record, getFn, insertFn, updateFn, label }) => {
+ const suppressKind = kind === 'issue' ? 'series' : kind;
+ const suppressId = kind === 'issue' ? record.seriesId : record.id;
const existing = await getFn(record.id).catch(() => null);
if (!existing) {
- await insertFn(record).catch((err) => {
+ // Suppress re-export around the insert exactly like the UPDATE branch:
+ // insertXxxWithId now fires emitRecordUpdated on the tombstone-resurrection
+ // path, which would otherwise echo the just-imported record straight back
+ // into the bucket we're importing from. The peer-sync propagation that
+ // resurrection ALSO triggers (autoSubscribeRecordToAllPeers) is a separate
+ // mechanism and stays intact — only the bucket re-export is suppressed.
+ await withReexportSuppressed(suppressKind, suppressId, () => insertFn(record)).catch((err) => {
// Duplicate id is benign — a parallel manifest already inserted it.
if (err?.code?.endsWith('_DUPLICATE')) return null;
console.log(`⚠️ sharing.importer: insertWithId(${kind}=${record.id}) failed: ${err.message}`);
@@ -423,8 +431,6 @@ async function applyAutoMerge(bucket, manifest, records, { availableAssetKeys =
return;
}
if (remoteWins(existing.updatedAt, record.updatedAt)) {
- const suppressKind = kind === 'issue' ? 'series' : kind;
- const suppressId = kind === 'issue' ? record.seriesId : record.id;
await withReexportSuppressed(suppressKind, suppressId, () => updateFn(existing.id, record));
overridden.push({ kind, id: record.id, label });
applied++;
diff --git a/server/services/voice/pipeline.js b/server/services/voice/pipeline.js
index 79a5aed1dd..f34e9c9fc9 100644
--- a/server/services/voice/pipeline.js
+++ b/server/services/voice/pipeline.js
@@ -263,7 +263,11 @@ const MEMORY_INJECT_LIMIT = 5;
//
// Exported for unit testing.
export const buildMemoryContext = async (userText, { limit = MEMORY_INJECT_LIMIT } = {}) => {
- const memories = await getRelevantMemories({ description: userText }, { limit });
+ // getRelevantMemories → generateQueryEmbedding does a bare `await fetch` that
+ // REJECTS (not returns null) when the embeddings backend is unreachable, so
+ // catch here to honor the "zero memories rather than killing the turn"
+ // contract above — otherwise a down embed server errors every recall turn.
+ const memories = await getRelevantMemories({ description: userText }, { limit }).catch(() => null);
if (!Array.isArray(memories) || !memories.length) return null;
const top = memories.slice(0, limit).filter((m) => m && typeof m.content === 'string' && m.content.trim());
if (!top.length) return null;
diff --git a/server/services/voice/pipeline.test.js b/server/services/voice/pipeline.test.js
index 90ce630575..5278e76f47 100644
--- a/server/services/voice/pipeline.test.js
+++ b/server/services/voice/pipeline.test.js
@@ -285,4 +285,11 @@ describe('buildMemoryContext', () => {
getRelevantMemories.mockResolvedValueOnce(null);
expect(await buildMemoryContext('what did I say about X?')).toBeNull();
});
+
+ it('returns null (does NOT throw) when retrieval rejects — embeddings backend down', async () => {
+ // generateEmbedding does a bare `await fetch` that REJECTS on a network
+ // failure; buildMemoryContext must degrade to no-memories, not kill the turn.
+ getRelevantMemories.mockRejectedValueOnce(new Error('ECONNREFUSED embeddings'));
+ await expect(buildMemoryContext('what did I decide about X?')).resolves.toBeNull();
+ });
});
diff --git a/server/services/voice/tools.js b/server/services/voice/tools.js
index b2bfd81090..3500b37116 100644
--- a/server/services/voice/tools.js
+++ b/server/services/voice/tools.js
@@ -214,7 +214,12 @@ const GROUP_INTENT = {
// "jot", "file" — without which moving brain_capture out of the always-on
// set would break "remember to buy milk" style turns.
brain: /\b(search|find|look ?up|recall|what did I (?:say|write|note)|brain|inbox|capture|remember|remind me|jot|note (?:that|to|down)|save (?:this|that)|file (?:this|that|it)|add (?:this|that|it) to (?:my )?(?:brain|inbox|notes?))\b/i,
- meatspace: /\b(drink|drank|beer|wine|whiskey|shot|cocktail|cigarette|vape|pouch|nicotine|weigh|pound|kilo|kg|smoke|smoking|workout|exercise|exercised|run|ran|jog|yoga|lift(?:ed|ing)?|cardio|gym|cycling|cycled|swim|swam|how am I|summary today|log (?:a|my) (?:drink|weight|nicotine|workout))\b/i,
+ // Bare `run`/`ran` were dropped — they collide with common command phrasing
+ // ("run the pipeline", "I ran the report") and would expose the workout tool
+ // on non-fitness turns. Genuine run-logging is recovered via the "went
+ // for/on a … run" and "ran a/N/for/my …" phrasings below; the other activity
+ // nouns (jog/yoga/cardio/gym/cycling/swim/…) rarely collide in voice commands.
+ meatspace: /\b(drink|drank|beer|wine|whiskey|shot|cocktail|cigarette|vape|pouch|nicotine|weigh|pound|kilo|kg|smoke|smoking|workout|exercise|exercised|jog|yoga|lift(?:ed|ing)?|cardio|gym|cycling|cycled|swim|swam|how am I|summary today|log (?:a|my) (?:drink|weight|nicotine|workout|run|exercise))\b|\bwent (?:for|on) (?:a |an )?(?:\w+ ){0,2}(?:run|jog|swim|ride|walk|hike|workout)\b|\bran (?:a |an |\d|for |my )/i,
// Calendar reads — "what's on my calendar", "what do I have today",
// "next meeting", "what's next", "upcoming", "any appointments". Tight-ish
// so plain "open calendar" still routes to ui_navigate, not calendar_today.
diff --git a/server/services/voice/tools.test.js b/server/services/voice/tools.test.js
index 6cba0d0b0f..4ae1705ed5 100644
--- a/server/services/voice/tools.test.js
+++ b/server/services/voice/tools.test.js
@@ -1086,6 +1086,15 @@ describe('new tool intent routing', () => {
it('routes workout utterances to the meatspace group', () => {
expect(classifyIntent('log a workout').has('meatspace')).toBe(true);
expect(classifyIntent('I went for a run').has('meatspace')).toBe(true);
+ expect(classifyIntent('went for a 30 minute run').has('meatspace')).toBe(true);
+ expect(classifyIntent('I ran a 5k this morning').has('meatspace')).toBe(true);
+ expect(classifyIntent('did some cardio at the gym').has('meatspace')).toBe(true);
+ });
+ it('does NOT route command phrasings of run/ran to the meatspace group', () => {
+ // Bare run/ran collide with common commands — must not expose the workout tool.
+ expect(classifyIntent('run the pipeline render').has('meatspace')).toBe(false);
+ expect(classifyIntent('I ran the report again').has('meatspace')).toBe(false);
+ expect(classifyIntent('run it one more time').has('meatspace')).toBe(false);
});
it('routes visual-description utterances to the vision group', () => {
expect(classifyIntent("what's on this chart?").has('vision')).toBe(true);