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(behaviour):add compact behaviour change on heartbeat.
Chaitanya Giri7de4309c4d3d
diff --git a/src/main/config.ts b/src/main/config.tsindex 44e30141..2d9ec8c3 100644--- a/src/main/config.ts+++ b/src/main/config.ts@@ -38,8 +38,11 @@ export const OPS_STANDUP_MISSION: ScheduledMission = {'Hourly ops standup. Review every agent: who is doing what, and confirm each ' +'is still running (not stalled or idle-stale). Check the task board — are ' +'in-flight tasks on track, and is anything blocked or unowned? Flag stale ' +- 'agents and at-risk tasks, and keep the board accurate. (Terminal contexts ' +- 'are auto-compacted as part of this standup.)',+ 'agents and at-risk tasks, and keep the board accurate. (As part of this ' ++ "standup each working agent is asked to summarise its current task and the " ++ '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};diff --git a/src/main/index.ts b/src/main/index.tsindex aed82c82..7829477b 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -212,16 +212,12 @@ function syncMissions(): void {if (hive.enabled()) {hive.send({ to: m.to, act: 'request', subject: m.label, body: m.body }, 'scheduler');}- // Compact every live terminal's context on this tick. Send the slash- // command, then a return a beat later (the input box needs the text to- // register before submit — mirrors the renderer's submitToPty cadence).+ // Auto-compact: do NOT jam /compact into busy terminals. Hand it to the+ // renderer, which queues a /compact per agent (deduped — never two at+ // once) and delivers it only when that agent goes idle (its drain loop),+ // so a working agent compacts between steps, never mid-step.if (m.autoCompact) {- for (const t of ptyManager.list()) {- try {- ptyManager.write(t.id, '/compact');- setTimeout(() => { try { ptyManager.write(t.id, '\r'); } catch { /* pty gone */ } }, 200);- } catch { /* pty gone */ }- }+ try { liveWebContents()?.send('mission:autoCompact'); } catch { /* window gone */ }}const current = readConfig().missions ?? [];const next = current.map((x) =>@@ -363,20 +359,14 @@ function buildHeartbeatDigest(quietMs: number): string {].join('\n');}-/** Re-engage a quiet floor: ALWAYS drop a durable digest into god's inbox; and- * ONLY when god's PTY is genuinely idle (>5s since last output = not mid-stream)- * also nudge it to wake a dormant god. The idle gate is the ironclad safety —- * never type into a PTY that produced output recently. */+/** Re-engage a quiet floor: drop a durable digest into god's inbox. We never+ * type directly into god's PTY here — if he's busy that would jam mid-step. The+ * inbox message is delivered by the renderer's busy-aware inbox-wake (it nudges+ * god to read his inbox only once he's idle), so the heartbeat defers around a+ * working god instead of interrupting him. */function reengageGod(digest: string): void {if (!hive.enabled()) return;hive.send({ to: 'god', act: 'request', subject: 'Heartbeat', body: digest }, 'heartbeat');- const godId = hive.registry().godId;- if (!godId) return;- const godPty = ptyForAgent(godId);- if (godPty && (ptyManager.idleFor(godPty) ?? 0) > 5_000) {- ptyManager.write(godPty, 'Heartbeat digest waiting in your inbox — review, re-engage anyone stalled, else rest.');- setTimeout(() => { try { ptyManager.write(godPty, '\r'); } catch { /* pty gone */ } }, 200);- }}/** A native toast for breaker constrain/stop, gated on the notifications setting. */diff --git a/src/preload/index.ts b/src/preload/index.tsindex 5cdabcc8..d44d7060 100644--- a/src/preload/index.ts+++ b/src/preload/index.ts@@ -474,6 +474,13 @@ const api = {ipcRenderer.on('missions:updated', listener);return () => ipcRenderer.removeListener('missions:updated', listener);},+ /** Fires when an autoCompact mission ticks — the renderer queues a /compact+ * per agent (deduped) and delivers it when each agent is idle. */+ onAutoCompact: (cb: () => void): (() => void) => {+ const listener = (): void => cb();+ ipcRenderer.on('mission:autoCompact', listener);+ return () => ipcRenderer.removeListener('mission:autoCompact', listener);+ },// ─── Full-text search across hive files (board, tasks, memory) ─────────────textSearch: (q: string): Promise<{ ok: boolean; results: Array<{ source: string; excerpt: string }> }> =>diff --git a/src/renderer/src/hooks/useHive.ts b/src/renderer/src/hooks/useHive.tsindex 333b0b74..e2bcf6fe 100644--- a/src/renderer/src/hooks/useHive.ts+++ b/src/renderer/src/hooks/useHive.ts@@ -30,6 +30,14 @@ const INITIAL_GOD_PROMPT = ['Then begin orchestrating: triage requests, delegate work to the team, and keep everyone unblocked. You are fully autonomous — there is no approval queue, so handle tool-permission prompts in this session yourself (the human can approve them remotely from their phone).'].join('\n');+// Scheduled auto-compact command (from the ops standup). Queued per agent and+// delivered when idle, so it never interrupts a working agent. The focus+// instructions make the agent record its current task + next step into the+// summary, so it resumes from the same point after compacting.+const COMPACT_CMD =+ '/compact Summarise exactly what you are currently working on and the next step, ' ++ 'so you can resume from the same point — then continue that work after compacting.';+// Per-pty submission chain. Every submitToPty for a given pty is appended here so// two callers (e.g. the boot sequence's /remote-control and the inbox-wake nudge)// can NEVER interleave their text + Enter — which jammed them onto one line and@@ -441,8 +449,11 @@ export function useHive(config: HarnessConfig | null): void {// Michael's queue: enrich OFF → straight to Michael; enrich ON → wrap as an// ENRICH TASK and route to the assistant, which forwards to Michael's inbox.+ // A slash command (e.g. a queued /compact) is NEVER enriched — it must hit+ // Michael's own session verbatim.if (messageQueues[GOD_ID]?.length) {- if (enrichEnabled) dispatch(GOD_ID, byId(ASSISTANT_ID), enrichTaskPrompt);+ const isCmd = messageQueues[GOD_ID][0].text.startsWith('/');+ if (enrichEnabled && !isCmd) dispatch(GOD_ID, byId(ASSISTANT_ID), enrichTaskPrompt);else dispatch(GOD_ID, byId(GOD_ID));}};@@ -471,4 +482,21 @@ export function useHive(config: HarnessConfig | null): void {useStore.getState().enqueueMessage(GOD_ID, msg.text.trim());});}, [config?.onboardingComplete]);++ // 6) Auto-compact (scheduled standup). Main fires this per tick; we queue a+ // /compact for each live agent so the drain (#4) delivers it only when the+ // agent is idle — never jamming a working terminal. Deduped: if a /compact+ // is already queued for an agent, skip it (no second one piles up).+ useEffect(() => {+ if (!config?.onboardingComplete) return;+ return window.cth.onAutoCompact(() => {+ const { agents, messageQueues, enqueueMessage } = useStore.getState();+ for (const a of agents) {+ if (!a.ptyId) continue;+ const queued = messageQueues[a.id] ?? [];+ if (queued.some((m) => m.text.trimStart().startsWith('/compact'))) continue;+ enqueueMessage(a.id, COMPACT_CMD);+ }+ });+ }, [config?.onboardingComplete]);}