an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
fix(memory): arm the mine loop when mempalace is installed after boot
Ed Chan18d83c7a611f
diff --git a/package.json b/package.jsonindex 7e01c131..863bba80 100644--- a/package.json+++ b/package.json@@ -19,7 +19,7 @@"typecheck:node": "tsc --noEmit -p tsconfig.node.json","typecheck:web": "tsc --noEmit -p tsconfig.web.json","typecheck": "npm run typecheck:node && npm run typecheck:web",- "test:focused": "node --test test/codex-remote.test.cjs test/control.test.cjs test/provider-automation.test.cjs test/provider-config.test.cjs test/queue-delivery.test.cjs test/terminal-automation.test.cjs test/terminal-recovery.test.cjs test/roster.test.cjs test/proc-kill.test.cjs test/expand-tilde.test.cjs test/hive-cwd.test.cjs test/hive-hook-node.test.cjs test/hive-roster-injection.test.cjs test/hive-runtime-path.test.cjs test/cli-install-ladder.test.cjs test/node-install.test.cjs test/office-gl-recovery.test.cjs test/update-state.test.cjs test/transcript-project-dir.test.cjs test/commit-graph.test.cjs test/task-ledger.test.cjs",+ "test:focused": "node --test test/codex-remote.test.cjs test/control.test.cjs test/provider-automation.test.cjs test/provider-config.test.cjs test/queue-delivery.test.cjs test/terminal-automation.test.cjs test/terminal-recovery.test.cjs test/roster.test.cjs test/proc-kill.test.cjs test/expand-tilde.test.cjs test/hive-cwd.test.cjs test/hive-hook-node.test.cjs test/hive-roster-injection.test.cjs test/hive-runtime-path.test.cjs test/cli-install-ladder.test.cjs test/node-install.test.cjs test/office-gl-recovery.test.cjs test/update-state.test.cjs test/transcript-project-dir.test.cjs test/commit-graph.test.cjs test/task-ledger.test.cjs test/memory-rearm.test.cjs","check:links": "node tools/check-release-links.cjs","dist": "npm run build && electron-builder","dist:mac": "npm run build && electron-builder --mac",diff --git a/src/main/index.ts b/src/main/index.tsindex dc37a9b0..9dab0c22 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -3099,7 +3099,11 @@ ipcMain.handle('hive:setArchived', (_evt, id: unknown, archived: unknown) => {});// ─── IPC: semantic memory (MemPalace CLI) ───────────────────────────────────-ipcMain.handle('hive:memoryStatus', () => { memory.resetBinCache(); return memory.status(); });+// refresh() = resetBinCache + an idempotent start(). The poll is the one thing+// that reliably notices mempalace being installed after boot, so it is what arms+// the mine loop that boot's start() had to skip — otherwise the pill reads+// "getting ready" until the app is restarted.+ipcMain.handle('hive:memoryStatus', () => memory.refresh());ipcMain.handle('hive:searchMemory', (_evt, query: unknown, wing: unknown) => {if (typeof query !== 'string' || !query.trim()) return { ok: false, output: '', error: 'empty query' };return memory.search(query, { wing: typeof wing === 'string' ? wing : undefined });diff --git a/src/main/memory.ts b/src/main/memory.tsindex 008e680b..95a813ab 100644--- a/src/main/memory.ts+++ b/src/main/memory.ts@@ -167,6 +167,29 @@ export class MemoryManager {if (this.mineTimer) { clearInterval(this.mineTimer); this.mineTimer = null; }}+ /**+ * Re-resolve the CLI, arm the mine loop if it is only now possible, and report.+ *+ * `start()` runs once at boot and bails when mempalace isn't on PATH yet. If the+ * user installs it AFTER that — the common case, since the settings panel is+ * where they find out they need it — nothing re-invoked `start()`, so the mine+ * loop never ran. The palace is created by the first `mempalace mine`, so it+ * never appeared either, and `initialized` (existsSync(palace)) stayed false+ * while `available` flipped true: the status pill read "On — getting ready…"+ * forever and only an app restart cleared it.+ *+ * The status poll is the one thing that reliably notices the install, so it is+ * where the re-arm belongs. `start()` is idempotent (initStarted), so repeated+ * polls never start a second loop — and it still deliberately does NOT run+ * `mempalace init`, which ends in an interactive "Mine now? [Y/n]" that `--yes`+ * doesn't cover and that hangs a spawned child.+ */+ refresh(): MemoryStatus {+ this.resetBinCache();+ this.start();+ return this.status();+ }+private startMineLoop(): void {if (this.mineTimer) return;this.mineNow();diff --git a/test/memory-rearm.test.cjs b/test/memory-rearm.test.cjsnew file mode 100644index 00000000..8d5d2755--- /dev/null+++ b/test/memory-rearm.test.cjs@@ -0,0 +1,83 @@+'use strict';++/**+ * Semantic memory must not be stuck on "getting ready" until the app restarts.+ *+ * start() runs once at boot and bails when mempalace isn't on PATH. Installing+ * it afterwards — the usual order, since the settings panel is where you learn+ * you need it — left nothing to re-invoke start(), so the mine loop never ran,+ * the palace (created by the first mine) never appeared, and the pill read+ * "On — getting ready…" forever while `available` correctly read true.+ *+ * The status poll notices the install, so the poll is what arms the loop.+ * `bin()` is stubbed here because the real one probes the machine's PATH, which+ * would make the outcome depend on whether the developer happens to have+ * mempalace installed.+ */++const test = require('node:test');+const assert = require('node:assert/strict');+const fs = require('node:fs');+const os = require('node:os');+const path = require('node:path');+const loadTs = require('./load-ts.cjs');++const { MemoryManager } = loadTs('src/main/memory.ts');++/** A manager over an empty temp home whose CLI resolution we control. */+function managerWithCli(t, opts = {}) {+ const home = fs.mkdtempSync(path.join(os.tmpdir(), 'md-memory-'));+ const state = { bin: opts.bin ?? null, enabled: opts.enabled !== false };+ const memory = new MemoryManager(() => home, () => ({ enabled: state.enabled, model: 'minilm' }));+ memory.bin = () => state.bin; // the real one shells out to `which mempalace`+ t.after(() => { memory.stop(); fs.rmSync(home, { recursive: true, force: true }); });+ return { memory, state, home };+}++/** The mine loop is armed exactly when its interval handle exists. */+const armed = (memory) => memory.mineTimer !== null;++test('a poll before mempalace is installed reports "not available" and arms nothing', (t) => {+ const { memory } = managerWithCli(t);++ const status = memory.refresh();++ assert.equal(status.available, false);+ assert.equal(status.active, false);+ assert.equal(armed(memory), false);+});++test('a poll AFTER mempalace appears arms the mine loop that boot had to skip', (t) => {+ const { memory, state } = managerWithCli(t);++ memory.start(); // boot: mempalace not installed yet+ assert.equal(armed(memory), false, 'nothing to start');++ state.bin = '/fake/bin/mempalace'; // the user installs it while the app runs+ const status = memory.refresh();++ assert.equal(status.available, true);+ assert.equal(status.active, true);+ assert.equal(armed(memory), true, 'this is what left the pill on "getting ready" forever');+});++test('polling again never starts a second mine loop', (t) => {+ const { memory } = managerWithCli(t, { bin: '/fake/bin/mempalace' });++ memory.refresh();+ const first = memory.mineTimer;+ memory.refresh();+ memory.refresh();++ assert.equal(memory.mineTimer, first, 'the palace permits a single writer — one loop only');+});++test('memory turned off in settings stays off however often it is polled', (t) => {+ const { memory } = managerWithCli(t, { bin: '/fake/bin/mempalace', enabled: false });++ const status = memory.refresh();++ assert.equal(status.available, true, 'the CLI is there…');+ assert.equal(status.enabled, false, '…but the user said no');+ assert.equal(armed(memory), false);+});