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(compaction): one schedule, and one pending /compact per agent
Chaitanya Girifdac49812aa9
diff --git a/src/main/config.ts b/src/main/config.tsindex c4fec87a..1c55241d 100644--- a/src/main/config.ts+++ b/src/main/config.ts@@ -70,8 +70,13 @@ export const OPS_STANDUP_MISSION: ScheduledMission = {'next step, then compact and resume from the same point — so terminal ' +'contexts stay bounded without losing work. The compaction is queued and ' +'runs when an agent is idle, so it never interrupts work mid-step.)',- enabled: true,- autoCompact: true+ enabled: true+ // NO autoCompact. Compaction belongs to contextTrigger.compact and nothing else.+ // This flag used to live here as well, which meant a default install asked for+ // compaction on TWO cadences — hourly from this standup and 2-hourly from the+ // trigger — the exact "two controls that disagree" the maint-1 retirement below+ // was written to end. The standup's own prose still describes compaction, and+ // that stays true: the trigger does it, just not on this mission's clock.};/** The built-in heartbeat (Lane A #1). A context-aware beat that, each tick,@@ -105,8 +110,8 @@ export const HEARTBEAT_MISSION: ScheduledMission = {* Shipped DISABLED (v0.3.4 founder decision): scheduled compaction is opt-in.* Turn it on in Settings → General or the Schedules tab; the Schedules warning* panel explains the risk of leaving it off for long-running agents. It is the- * SINGLE source of truth for compaction (migration drops autoCompact off other- * missions), and it's persistent: deleting it makes it reappear DISABLED.+ * SINGLE source of truth for compaction, and it's persistent: deleting it makes+ * it reappear DISABLED.* Existing installs keep whatever enabled state the user already has* (compactMaintenanceSeeded guards re-seeding). */export const COMPACT_MAINTENANCE_MISSION: ScheduledMission = {diff --git a/src/main/index.ts b/src/main/index.tsindex 473c132c..98ed0bbc 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -882,6 +882,31 @@ function ensureDefaultMissions(): void {console.log('[triggers] retired the compact-maintenance mission into contextTrigger.compact',`(enabled: ${retiring.enabled}, everyMs: ${retiring.intervalMs})`);}++ // autoCompact RETIREMENT: the flag above was only ever half-removed. Retiring+ // `compact-maintenance` left `autoCompact: true` sitting on the ops standup, so+ // a default install still asked for compaction on TWO cadences — hourly from the+ // standup, 2-hourly from the trigger — which is precisely the disagreement that+ // retirement claims to have ended. (config.ts even documented a migration that+ // strips this; it did not exist.)+ //+ // Strip it wherever it survives. This is a pure de-duplication, not a behaviour+ // change: contextTrigger.compact still runs, still on the user's own cadence and+ // pressure gate, and it is what actually performed every one of these+ // compactions already — both paths have called emitContextTrigger since Triggers+ // landed. Idempotent, so it costs one no-op scan per boot once clean.+ const cfg4 = readConfig();+ const missions4 = cfg4.missions ?? [];+ if (missions4.some((m) => m.autoCompact)) {+ writeConfig({+ missions: missions4.map(({ autoCompact, ...rest }) => {+ void autoCompact;+ return rest;+ })+ });+ console.log('[triggers] dropped the legacy per-mission autoCompact flag —',+ 'contextTrigger.compact is now the only schedule that compacts');+ }}// ─── Heartbeat (Lane A #1) + circuit-breaker beat (#6.6b) ────────────────────diff --git a/src/renderer/src/store/store.ts b/src/renderer/src/store/store.tsindex a68577b5..9da1a90c 100644--- a/src/renderer/src/store/store.ts+++ b/src/renderer/src/store/store.ts@@ -6,6 +6,7 @@ import type { StatusKind } from '@/components/PixelBadge';import type { AgentProvider } from '@shared/agentProvider';import type { HireManifest } from '@shared/hire';import { DEFAULT_ORG_TRIGGER, type OrgTriggerConfig, type WebhookTrigger } from '@shared/triggers';+import { isCompactionCommand } from '@shared/providerAutomation';import type { LimitHold } from '@shared/rateLimit';export type ToolKind =@@ -730,6 +731,21 @@ export const useStore = create<State>((set) => ({set((s) => {const trimmed = text.trim();if (!trimmed) return s;+ // ONE PENDING COMPACT PER AGENT. Compaction is idempotent in the worst way:+ // the first `/compact` does the work and every one behind it answers+ // "nothing to compact", so a queue that accumulates them spends a delivery+ // slot and a model round-trip per copy to achieve nothing, and buries the+ // operator's real backlog behind them.+ //+ // The invariant lives HERE rather than at the call sites because there are+ // several — the context trigger, god dispatching a work order, Slack, the+ // composer — and each one that grew its own check could still be bypassed+ // by the next path someone adds. The context trigger's own check stays as+ // cheap defence in depth, but this is the one that cannot be routed around.+ const queued = s.messageQueues[agentId] ?? [];+ if (isCompactionCommand(trimmed) && queued.some((m) => isCompactionCommand(m.text))) {+ return s;+ }const msg: QueuedMessage = {id: newQueuedId(), text: trimmed, ts: Date.now(),...(meta?.slack ? { slack: meta.slack } : {}),diff --git a/src/shared/providerAutomation.ts b/src/shared/providerAutomation.tsindex 20402df6..e25dff1b 100644--- a/src/shared/providerAutomation.ts+++ b/src/shared/providerAutomation.ts@@ -160,6 +160,30 @@ export function compactionCommandForProvider(return compactTakesFocus && focus ? `${compact} ${focus}` : compact;}+/** Every distinct compaction verb this harness can type, across all providers.+ * Derived from CONTEXT_COMMANDS rather than hand-listed, so a provider added to+ * that table is covered here without a second edit anyone could forget. */+const COMPACT_VERBS: ReadonlySet<string> = new Set(+ Object.values(CONTEXT_COMMANDS)+ .map((c) => c.compact)+ .filter((c): c is string => typeof c === 'string' && c.length > 0)+);++/**+ * Is this queued text a compaction command?+ *+ * Matches the leading VERB only, so `/compact keep the auth decisions` counts+ * while a human sentence that merely mentions compaction does not — the queue+ * carries both, and mistaking prose for a command would silently drop real work.+ *+ * Provider-agnostic on purpose: the queue is keyed by agent, not provider, and a+ * duplicate `/compact` is worth dropping regardless of which CLI is going to+ * receive it.+ */+export function isCompactionCommand(text: string): boolean {+ return COMPACT_VERBS.has(text.trim().split(/\s+/)[0]);+}+/*** The context-clearing command to type, or null when nothing typed can reach* this provider.diff --git a/test/provider-automation.test.cjs b/test/provider-automation.test.cjsindex 9ecc72e6..c93848a9 100644--- a/test/provider-automation.test.cjs+++ b/test/provider-automation.test.cjs@@ -8,10 +8,42 @@ const {clearCommandForProvider,compactionCommandForProvider,contextCommandsForProvider,+ isCompactionCommand,remoteControlCommandForProvider,terminalReadySettleMs,terminalReadyToReceive} = loadTs('src/shared/providerAutomation.ts');++// — the queue's one-pending-compact invariant depends entirely on this predicate —++test('isCompactionCommand matches every provider that has a compact verb', () => {+ for (const p of ['claude', 'codex', 'grok', 'kimi', 'qwen', 'opencode', 'pi', 'copilot']) {+ const cmd = compactionCommandForProvider(p, '');+ if (!cmd) continue; // provider has no typeable compaction — nothing to dedupe+ assert.equal(isCompactionCommand(cmd), true, `${p}: ${cmd}`);+ }+});++test('a focus suffix still reads as a compaction command', () => {+ // This is the real queued shape — the trigger appends the operator's focus+ // text, so matching the whole string instead of the verb would never dedupe.+ assert.equal(isCompactionCommand('/compact keep the auth decisions'), true);+ assert.equal(isCompactionCommand(' /compact keep everything '), true);+});++test('prose that merely mentions compaction is NOT a command', () => {+ // The queue carries human instructions too; dropping one as a duplicate+ // compact would silently lose real work.+ assert.equal(isCompactionCommand('please /compact when you are done'), false);+ assert.equal(isCompactionCommand('compact the context'), false);+ assert.equal(isCompactionCommand('summarise and compact'), false);+ assert.equal(isCompactionCommand(''), false);+});++test('a clear command is not a compaction command', () => {+ assert.equal(isCompactionCommand('/clear'), false);+ assert.equal(isCompactionCommand('/new'), false);+});const { DEFAULT_COMPACTION_FOCUS } = loadTs('src/shared/triggers.ts');const { AGENT_PROVIDER_PRESETS } = loadTs('src/shared/agentProvider.ts');