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(0.4.7-rc): ask-me ordering, release drop for fresh installs, compact-latch tests
chaitanyagiri5b80d9aed816
diff --git a/src/main/updater.ts b/src/main/updater.tsindex dfff98c3..f33835b7 100644--- a/src/main/updater.ts+++ b/src/main/updater.ts@@ -5,7 +5,7 @@ import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'import { join } from 'node:path';import { readConfig } from './config';import { DEFAULT_DROP_HTML } from '../shared/releaseDrop';-import { reduceStatus, clampPercent, isNewer, installerUrl, type UpdateStatus } from '../shared/updateState';+import { reduceStatus, clampPercent, isNewer, installerUrl, shouldShowReleaseDrop, type UpdateStatus } from '../shared/updateState';/*** Auto-update from GitHub releases.@@ -459,12 +459,26 @@ export function initAutoUpdater(getWebContents: () => WebContents | null): voidlet previous: string | null = null;try { previous = readFileSync(stampFile, 'utf8').trim() || null; } catch { /* first run */ }const current = app.getVersion();+ // The stamp write stays UNCONDITIONAL on a version change (it already ran+ // even when `previous` was null), which is what arms every install that+ // boots this version even once. Its own try/catch so an unwritable+ // userData cannot skip the decision below by throwing to the outer catch.+ let stamped = false;if (previous !== current) {- mkdirSync(app.getPath('userData'), { recursive: true });- writeFileSync(stampFile, current + '\n', 'utf8');+ try {+ mkdirSync(app.getPath('userData'), { recursive: true });+ writeFileSync(stampFile, current + '\n', 'utf8');+ stamped = true;+ } catch (e) {+ logLine(`last-run-version stamp failed: ${errText(e)}`);+ }}- if (previous && previous !== current && isNewer(current, previous)) {- logLine(`first run after update ${previous} -> ${current}; fetching its release page`);+ // Gated on the stamp having LANDED, not merely been attempted: if the+ // stamp cannot be written, `previous` stays null on every future launch,+ // so firing here would reopen the drop on every single boot forever.+ // Showing it zero times on an unwritable userData is the lesser failure.+ if (stamped && shouldShowReleaseDrop(previous, current)) {+ logLine(`first run of ${current} (previous ${previous ?? 'none'}); fetching its release page`);fetchReleaseBody(current, (notes) => {emit({ state: 'just-updated', version: current, notes });logLine(`just-updated ${current} ${notes ? 'with' : 'without'} release notes`);diff --git a/src/renderer/src/components/AskMeTab.tsx b/src/renderer/src/components/AskMeTab.tsxindex 06e655c5..b1271502 100644--- a/src/renderer/src/components/AskMeTab.tsx+++ b/src/renderer/src/components/AskMeTab.tsx@@ -4,6 +4,7 @@ import { PixelBadge } from './PixelBadge';import { useStore } from '@/store/store';import { MarkdownPreview } from '@/markdown/MarkdownPreview';import { type HiveTask, type HumanQA, openQuestion, waitsOnHuman } from './TasksKanban';+import { compareByNewestAsk } from './askMeOrder';/*** ASK ME — first-class human feedback through the task system.@@ -65,7 +66,16 @@ export function AskMeTab() {const nameFor = (id?: string): string | undefined =>id ? (agents.find((a) => a.id === id)?.name ?? restorable.find((a) => a.id === id)?.name ?? id) : undefined;- const waiting = tasks.filter(waitsOnHuman);+ // Newest ask at the top, oldest at the bottom. Before this the board had no+ // comparator at all, so a question's position was an accident of where its+ // card sat in tasks.json. `filter` already returns a fresh array, so sorting+ // in place never touches the store's own ordering. The ask each card is+ // ranked by comes from openQuestion() — the same predicate waitsOnHuman uses+ // — and only this OUTER list is sorted; a card's humanQA history stays+ // chronological (see askMeOrder.ts).+ const waiting = tasks+ .filter(waitsOnHuman)+ .sort((a, b) => compareByNewestAsk(openQuestion(a), openQuestion(b)));/*** Apply `patch` to the OPEN humanQA entry of one card, on the RAW ledger.diff --git a/src/renderer/src/components/askMeOrder.ts b/src/renderer/src/components/askMeOrder.tsnew file mode 100644index 00000000..947d0230--- /dev/null+++ b/src/renderer/src/components/askMeOrder.ts@@ -0,0 +1,52 @@+/**+ * Ordering for the ASK ME board.+ *+ * The board had NO comparator at all: `tasks.filter(waitsOnHuman)` rendered in+ * whatever order the cards happened to sit in a 440KB tasks.json, which is+ * roughly card-creation order across the whole file and has nothing to do with+ * when a question was asked. A question from five minutes ago could land below+ * one from three days ago, and the order shifted as unrelated cards were added.+ *+ * This module is the ordering rule ONLY, kept free of every import (no React,+ * no store) so the comparator is unit-testable on its own — the same reason+ * queueDelivery.ts keeps its gate structural.+ *+ * IMPORTANT — there are two orderings on this screen and only the OUTER one is+ * sorted here: the list of CARDS (this file). The `humanQA` array WITHIN a card+ * is a conversation history, rendered oldest-first through the "VIEW N EARLIER+ * ANSWERS" collapse, and must stay chronological. Never reverse it.+ */++/** The only thing the ordering needs from a card's open ask. Structural so the+ * test does not have to construct a whole HiveTask. */+export interface AskLike {+ askedAt?: string;+}++/** `askedAt` as epoch ms, or null when it is missing or unparseable.+ * Never throws — a hand-edited ledger must not be able to crash the board. */+export function askedAtMs(open: AskLike | undefined): number | null {+ const raw = open?.askedAt;+ if (!raw) return null;+ const ms = Date.parse(raw);+ return Number.isNaN(ms) ? null : ms;+}++/**+ * Newest ask first, oldest last.+ *+ * Callers pass each card's OPEN question (from `openQuestion()`), so "open"+ * is derived from the same predicate `waitsOnHuman` already uses rather than+ * being defined a second time here.+ *+ * Cards whose open ask carries no parseable `askedAt` sort LAST, so a bad+ * timestamp costs that one card its position instead of throwing.+ */+export function compareByNewestAsk(a: AskLike | undefined, b: AskLike | undefined): number {+ const ax = askedAtMs(a);+ const bx = askedAtMs(b);+ if (ax === null && bx === null) return 0;+ if (ax === null) return 1; // a has no time -> after b+ if (bx === null) return -1; // b has no time -> after a+ return bx - ax; // descending+}diff --git a/src/shared/updateState.ts b/src/shared/updateState.tsindex ad2e7665..9ab86fbc 100644--- a/src/shared/updateState.ts+++ b/src/shared/updateState.ts@@ -90,6 +90,36 @@ export function isNewer(candidate: string, current: string): boolean {return false;}+/**+ * Should the "what's new" release drop open on this launch?+ *+ * `previous` is the `last-run-version` stamp (null when the file does not+ * exist), `current` is the running version.+ *+ * The drop used to require a stamp to already be present, which meant it fired+ * for almost nobody: the stamp AND its reader shipped in the same release, so+ * no earlier install had the file, `previous` read null on the upgrade INTO+ * that release, and a genuinely fresh install had nothing either.+ *+ * - same version relaunch -> false. Seen once is seen.+ * - never run before -> true. The fresh-install case that was missing.+ * - version moved forward -> true. The ordinary upgrade.+ * - version moved BACKWARD -> false. A downgrade has nothing new to announce.+ *+ * Note the forward test is "not a downgrade", not `isNewer(current, previous)`.+ * `isNewer` compares major.minor.patch only and discards `-rc.N`, so a second+ * RC of the same version (0.4.7-rc.1 -> 0.4.7-rc.2) is neither newer nor older;+ * asking "is this a downgrade?" lets that case through DELIBERATELY (a new+ * build does have new notes) while still refusing a real downgrade. Doing it+ * here rather than by teaching `isNewer` about prereleases keeps the change off+ * the badge/pending state machine, which reads `isNewer` for other decisions.+ */+export function shouldShowReleaseDrop(previous: string | null, current: string): boolean {+ if (previous === current) return false;+ if (previous === null) return true;+ return !isNewer(previous, current);+}+/** Download percentages arrive as floats and, on a resumed/differential* download, occasionally out of range. Clamp so the UI can't render `-0%`* or `104%`. */diff --git a/test/askme-order.test.cjs b/test/askme-order.test.cjsnew file mode 100644index 00000000..a88cc1f8--- /dev/null+++ b/test/askme-order.test.cjs@@ -0,0 +1,69 @@+'use strict';++// ASK ME board ordering: newest question at the top, oldest at the bottom.+//+// Before this there was no comparator at all — position was an accident of+// where a card sat in a 440KB tasks.json — so these assert the ordering rule+// itself, not merely that a sort call exists.++const test = require('node:test');+const assert = require('node:assert/strict');+const fs = require('node:fs');+const path = require('node:path');+const loadTs = require('./load-ts.cjs');++const { compareByNewestAsk, askedAtMs } = loadTs('src/renderer/src/components/askMeOrder.ts');++// A card's OPEN ask is what the board ranks by; the comparator takes that entry+// directly, exactly as AskMeTab passes openQuestion(t).+const ask = (askedAt) => (askedAt === undefined ? undefined : { askedAt });++function order(...times) {+ return times.map(ask).sort(compareByNewestAsk).map((e) => e?.askedAt ?? null);+}++test('the newest ask sorts first and the oldest last', () => {+ assert.deepEqual(+ order('2026-08-20T10:00:00Z', '2026-08-26T08:20:00Z', '2026-08-23T12:00:00Z'),+ ['2026-08-26T08:20:00Z', '2026-08-23T12:00:00Z', '2026-08-20T10:00:00Z']+ );+});++test('the founder scenario: a brand-new ask outranks a three-day-old one', () => {+ // The 08:20Z ask landed on a card created minutes earlier, so it sat at the+ // END of the array and rendered at the BOTTOM. It must now come first.+ const [first] = order('2026-08-23T09:00:00Z', '2026-08-26T08:20:00Z');+ assert.equal(first, '2026-08-26T08:20:00Z');+});++test('an unparseable or missing askedAt sorts last instead of throwing', () => {+ assert.deepEqual(+ order('not-a-date', '2026-08-26T08:20:00Z', undefined, '2026-08-20T10:00:00Z'),+ ['2026-08-26T08:20:00Z', '2026-08-20T10:00:00Z', 'not-a-date', null]+ );+ // The card carrying a bad timestamp loses its position, never the board.+ assert.doesNotThrow(() => order('garbage', undefined));+ assert.equal(askedAtMs({ askedAt: 'garbage' }), null);+ assert.equal(askedAtMs(undefined), null);+});++test('two asks at the same instant keep a stable relative order', () => {+ assert.equal(compareByNewestAsk(ask('2026-08-26T08:20:00Z'), ask('2026-08-26T08:20:00Z')), 0);+});++// ── the board actually applies it, to the OUTER list only ────────────────────++const tab = fs.readFileSync(+ path.resolve(__dirname, '..', 'src/renderer/src/components/AskMeTab.tsx'), 'utf8'+);++test('AskMeTab sorts the card list by each card open question', () => {+ assert.match(tab, /\.filter\(waitsOnHuman\)\s*\n\s*\.sort\(\(a, b\) => compareByNewestAsk\(openQuestion\(a\), openQuestion\(b\)\)\)/);+});++test('the humanQA history inside a card is never reversed', () => {+ // That array is a conversation rendered through the "VIEW N EARLIER ANSWERS"+ // collapse; reversing it would make a thread read backwards.+ assert.doesNotMatch(tab, /humanQA[^\n]*\.reverse\(\)/);+ assert.doesNotMatch(tab, /\.reverse\(\)/);+});diff --git a/test/compact-latch.test.cjs b/test/compact-latch.test.cjsnew file mode 100644index 00000000..f3e07434--- /dev/null+++ b/test/compact-latch.test.cjs@@ -0,0 +1,91 @@+'use strict';++// Regression guard for #270 — the compaction latch.+//+// The bug it fixed is SILENT AND SLOW: god latches out of compaction, nothing+// errors, no toast, no log line, and context simply stops compacting until+// something else breaks. Nothing guarded it. The code is correct as shipped;+// this is the missing guard, not a bug hunt, so nothing here refactors it.+//+// Two behaviours:+// (a) fire() with an undeliverable agent enqueues NOTHING+// (b) a failed delivery leaves lastCompactUsed UNCHANGED; a success updates it++const test = require('node:test');+const assert = require('node:assert/strict');+const fs = require('node:fs');+const path = require('node:path');+const loadTs = require('./load-ts.cjs');++// queueDelivery.ts has zero imports by design ("kept structural so the gate is+// testable without dragging the store into the test"), so both primitives the+// latch depends on run for real here.+const { canDeliverToAgent, deliverWithAcknowledgement } = loadTs('src/renderer/src/hooks/queueDelivery.ts');++const QUIESCE = 30_000;++// ── (a) the gate that decides "undeliverable" ────────────────────────────────++test('(a) an agent blocked on a human prompt is undeliverable', () => {+ // The exact scenario #270 names: god 'blocked' on a human prompt. Enqueuing+ // anyway left a stuck /compact at the head of the queue that dedupe then+ // collapsed every later hourly attempt against, forever.+ assert.equal(canDeliverToAgent('blocked', 0, QUIESCE), false);+});++test('(a) idle delivers; a busy loop only delivers once it has gone quiet', () => {+ assert.equal(canDeliverToAgent('idle', null, QUIESCE), true);+ assert.equal(canDeliverToAgent('looping', QUIESCE - 1, QUIESCE), false);+ assert.equal(canDeliverToAgent('looping', QUIESCE, QUIESCE), true);+ // never polled / no output at all is not "quiet", it is unknown+ assert.equal(canDeliverToAgent('looping', null, QUIESCE), false);+});++// ── (b) the delivery result the latch is gated on ────────────────────────────++test('(b) a failed delivery reports false and never acknowledges', () => {+ let acknowledged = false;+ return deliverWithAcknowledgement(+ () => Promise.reject(new Error('pty gone')),+ () => { acknowledged = true; }+ ).then((sent) => {+ assert.equal(sent, false, 'a rejected send is not a delivery');+ assert.equal(acknowledged, false, 'the queue item is left for the next retry');+ });+});++test('(b) a successful delivery reports true and acknowledges once', () => {+ let acknowledged = 0;+ return deliverWithAcknowledgement(+ () => Promise.resolve(),+ () => { acknowledged += 1; }+ ).then((sent) => {+ assert.equal(sent, true);+ assert.equal(acknowledged, 1);+ });+});++// ── both guards are present, and placed where they have to be ────────────────+// useHive.ts is a React hook whose import graph cannot load under node:test, so+// its wiring is asserted against the source text — the house pattern. Removing+// either guard fails a test here, which is what the card asks for.++const hive = fs.readFileSync(+ path.resolve(__dirname, '..', 'src/renderer/src/hooks/useHive.ts'), 'utf8'+);++test('(a) fire() refuses an undeliverable agent BEFORE it enqueues', () => {+ assert.match(hive, /if \(!canDeliverToAgent\(a\.status, ptyQuietMs\(a\.ptyId, now\), QUIESCE_IDLE_MS\)\) continue;/);+ // the gate must sit ahead of the enqueue, not after it+ const gate = hive.indexOf("Gate #109-2");+ const enqueue = hive.indexOf('enqueueMessage', gate);+ assert.ok(gate > 0, 'the compaction-trigger gate is still there');+ assert.ok(enqueue > gate, 'the gate runs before the enqueue it protects');+});++test('(b) the latch is written ONLY on a delivery that happened', () => {+ assert.match(hive, /if \(sent && message\?\.compactUsed !== undefined\) \{/);+ // and there is no second, ungated write that would defeat it+ const writes = hive.match(/lastCompactUsed\.current\[[^\]]+\] = /g) ?? [];+ assert.equal(writes.length, 1, 'exactly one place writes the latch');+});diff --git a/test/release-drop-reach.test.cjs b/test/release-drop-reach.test.cjsnew file mode 100644index 00000000..933237a7--- /dev/null+++ b/test/release-drop-reach.test.cjs@@ -0,0 +1,74 @@+'use strict';++// The release drop must reach fresh installs.+//+// It used to require a `last-run-version` stamp to ALREADY exist, but the stamp+// and its reader shipped in the same release — so no earlier install had the+// file, `previous` read null on the upgrade into that release, and the drop+// fired for almost nobody. These are the card's acceptance criteria (a)-(e).++const test = require('node:test');+const assert = require('node:assert/strict');+const fs = require('node:fs');+const path = require('node:path');+const loadTs = require('./load-ts.cjs');++const { shouldShowReleaseDrop, isNewer } = loadTs('src/shared/updateState.ts');++// (a) a machine that has NEVER run this app+test('(a) a fresh install sees the drop on first launch', () => {+ assert.equal(shouldShowReleaseDrop(null, '0.4.7'), true);+});++// (b) the ordinary upgrade+test('(b) 0.4.6 -> 0.4.7 sees it', () => {+ assert.equal(shouldShowReleaseDrop('0.4.6', '0.4.7'), true);+});++// (c) seen once is seen+test('(c) the same version never fires twice', () => {+ assert.equal(shouldShowReleaseDrop('0.4.7', '0.4.7'), false);+ // …and the launch after a fresh install reads its own stamp back.+ assert.equal(shouldShowReleaseDrop('0.4.7', '0.4.7'), false);+});++// (d) a second RC of the SAME version — deliberate, not accidental+test('(d) 0.4.7-rc.1 -> 0.4.7-rc.2 fires, deliberately', () => {+ // isNewer discards -rc.N, so the two compare EQUAL. That is exactly why the+ // decision asks "is this a downgrade?" instead of "is this newer?".+ assert.equal(isNewer('0.4.7-rc.2', '0.4.7-rc.1'), false, 'isNewer still ignores -rc.N');+ assert.equal(shouldShowReleaseDrop('0.4.7-rc.1', '0.4.7-rc.2'), true);+ // and the rehearsal hop itself+ assert.equal(shouldShowReleaseDrop('0.4.6-rc.1', '0.4.7-rc.1'), true);+});++test('a downgrade announces nothing', () => {+ assert.equal(shouldShowReleaseDrop('0.4.8', '0.4.7'), false);+});++// ── the updater wires the decision, and keeps the stamp unconditional ────────++const updater = fs.readFileSync(path.resolve(__dirname, '..', 'src/main/updater.ts'), 'utf8');++test('the stamp write is still unconditional on a version change', () => {+ // This is what arms every install that boots this version even once, and it+ // is the half that ALREADY worked — it must not be re-gated.+ assert.match(updater, /if \(previous !== current\) \{\s*\n\s*try \{\s*\n\s*mkdirSync/);+});++test('the drop fires only when the stamp actually landed', () => {+ // Otherwise an unwritable userData reopens the drop on every boot forever.+ assert.match(updater, /if \(stamped && shouldShowReleaseDrop\(previous, current\)\)/);+});++test('a failed stamp write cannot skip the decision by throwing', () => {+ assert.match(updater, /logLine\(`last-run-version stamp failed/);+});++// (e) unchanged: no drop block in the body still renders nothing+test('(e) rendering a body with no drop block is untouched', () => {+ const toast = fs.readFileSync(+ path.resolve(__dirname, '..', 'src/renderer/src/components/UpdateToast.tsx'), 'utf8'+ );+ assert.match(toast, /drop/i, 'UpdateToast still decides on the drop block itself');+});