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
feat(enrich): replace visible Dwight assistant with invisible headless Haiku enrichment
Chaitanya Giriacc13a352b06
diff --git a/src/main/assistant.ts b/src/main/assistant.tsindex ffe1ba15..6431b05f 100644--- a/src/main/assistant.ts+++ b/src/main/assistant.ts@@ -5,9 +5,9 @@ import { resolveCommand, userShellPath } from './shellEnv';/*** Michael's silent prep assistant.*- * Runs a one-shot, headless `claude -p` session (Sonnet, 1M context) that NEVER- * appears on the office floor or in the agent list. Given a short, possibly- * vague instruction the user parked for Michael, it locates the relevant project+ * Runs a one-shot, headless `claude -p` session (Haiku) that NEVER appears on+ * the office floor or in the agent list. Given a short, possibly vague+ * instruction the user parked for Michael, it locates the relevant project* directory (it starts in Michael's home and can read every registered repo),* gathers concrete context read-only, and rewrites the instruction into a* single self-contained prompt Michael can execute autonomously.@@ -16,9 +16,8 @@ import { resolveCommand, userShellPath } from './shellEnv';* delivers the enriched prompt to Michael with no extra plumbing.*/-/** Sonnet with the 1M-token context window — chosen for cheap, large-context- * context-gathering that won't compete with Michael's own (Opus) session. */-const ASSISTANT_MODEL = 'claude-sonnet-4-6[1m]';+/** Haiku 4.5 — fast, cheap, and works without usage credits by default. */+const ASSISTANT_MODEL = 'claude-haiku-4-5';const DEFAULT_TIMEOUT_MS = 180_000;diff --git a/src/main/hive.ts b/src/main/hive.tsindex 63d091a7..ab7466d8 100644--- a/src/main/hive.ts+++ b/src/main/hive.ts@@ -563,21 +563,6 @@ export class HiveManager {: [resolveTo(msg.to)].filter((t) => t !== msg.from);for (const t of targets) {const target = reg.agents[t];- // Enforce the assistant's send-only contract AT THE ROUTER: it has no- // composer, is excluded from the inbox-wake nudge, and never reads an- // inbox — yet direct mail used to be delivered there anyway, where it- // rotted unread (observed live: a task brief plus the follow-up- // reprimand about the unread inbox, both unread for hours). Bounce such- // mail to god instead, so the sender's intent surfaces immediately and- // nothing is silently lost.- if (target?.isAssistant) {- this.deliver({- ...msg,- to: godId,- subject: `[bounced — "${t}" is the send-only prep assistant; route work to a real agent] ${msg.subject}`- }, godId);- continue;- }if (target && !isClaudeProvider(target.provider ?? 'claude')) {this.deliver({...msg,diff --git a/src/renderer/src/components/CommandCenterPanel.tsx b/src/renderer/src/components/CommandCenterPanel.tsxindex f52491b0..5ee7bea6 100644--- a/src/renderer/src/components/CommandCenterPanel.tsx+++ b/src/renderer/src/components/CommandCenterPanel.tsx@@ -571,9 +571,9 @@ function FloorTab({ seed }: { seed: { text: string; seq: number } }) {<ArchivedSection />- <Section title="ASSISTANT">+ <Section title="ENRICH"><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>- <span style={{ fontSize: 13, color: 'var(--cth-ink-700)' }}>Route Michael's queue through Dwight</span>+ <span style={{ fontSize: 13, color: 'var(--cth-ink-700)' }}>Enrich prompts with Haiku before Michael</span><buttononClick={() => setEnrichEnabled(!enrichEnabled)}style={{diff --git a/src/renderer/src/components/MessageQueueComposer.tsx b/src/renderer/src/components/MessageQueueComposer.tsxindex 9382fc03..f5c95d1a 100644--- a/src/renderer/src/components/MessageQueueComposer.tsx+++ b/src/renderer/src/components/MessageQueueComposer.tsx@@ -15,8 +15,9 @@ export interface MessageQueueComposerProps {* TUI one-by-one as soon as it goes idle (see useHive's flush loop).** For Michael, a global "enrich" toggle decides routing: OFF → messages type- * straight into Michael; ON → they're routed through the assistant ("Dwight"),- * which gathers repo context and forwards an improved prompt to Michael.+ * straight into Michael; ON → a headless Haiku call enriches the prompt with+ * repo context before it reaches Michael. Messages show 'enriching…' in the+ * queue while the Haiku call is in flight.*/export function MessageQueueComposer({ agent }: MessageQueueComposerProps) {const queue = useStore((s) => s.messageQueues[agent.id]) ?? EMPTY_QUEUE;@@ -32,7 +33,7 @@ export function MessageQueueComposer({ agent }: MessageQueueComposerProps) {const setDraft = useStore((s) => s.setDraft);const setText = (t: string) => setDraft(agent.id, t);- // The enrich toggle governs Michael's queue (it routes through the assistant).+ // The enrich toggle governs Michael's queue (headless Haiku enrichment).const showEnrichToggle = !!agent.isGod;const idle = agent.status === 'idle';@@ -53,7 +54,7 @@ export function MessageQueueComposer({ agent }: MessageQueueComposerProps) {const statusHint = queue.length === 0? null: showEnrichToggle && enrichEnabled- ? `→ Dwight (enrich) → Michael · ${queue.length} queued`+ ? `Haiku enriching → Michael · ${queue.length} queued`: idle? `sending to ${agent.name} one-by-one…`: `${agent.name} is busy — ${queue.length} queued`;@@ -114,28 +115,32 @@ export function MessageQueueComposer({ agent }: MessageQueueComposerProps) {<div key={m.id} style={{display: 'flex', alignItems: 'flex-start', gap: 6,padding: '4px 6px',- background: 'var(--cth-paper-100)',- boxShadow: 'inset 0 0 0 1px var(--cth-ink-300)'+ background: m.enriching ? 'var(--cth-lemon-light)' : 'var(--cth-paper-100)',+ boxShadow: `inset 0 0 0 1px ${m.enriching ? 'var(--cth-lemon)' : 'var(--cth-ink-300)'}`}}><span style={{fontFamily: 'var(--cth-font-mono)', fontSize: 12,color: 'var(--cth-ink-500)', lineHeight: '18px', flexShrink: 0- }}>{i + 1}.</span>+ }}>{m.enriching ? <Icon name="sparkle" /> : `${i + 1}.`}</span><divtitle={m.text}style={{flex: 1, minWidth: 0,- fontSize: 13, lineHeight: '18px', color: 'var(--cth-ink-900)',+ fontSize: 13, lineHeight: '18px',+ color: m.enriching ? 'var(--cth-ink-700)' : 'var(--cth-ink-900)',+ fontStyle: m.enriching ? 'italic' : 'normal',display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical',overflow: 'hidden', whiteSpace: 'pre-wrap', wordBreak: 'break-word'}}- >{m.text}</div>+ >{m.enriching ? 'enriching prompt…' : m.text}</div><buttononClick={() => removeQueuedMessage(agent.id, m.id)}title="Remove from queue"+ disabled={m.enriching}style={{flexShrink: 0, border: 'none', background: 'transparent',- cursor: 'pointer', color: 'var(--cth-ink-500)', padding: 0,+ cursor: m.enriching ? 'default' : 'pointer',+ color: m.enriching ? 'var(--cth-ink-300)' : 'var(--cth-ink-500)', padding: 0,display: 'inline-flex', alignItems: 'center'}}>diff --git a/src/renderer/src/hooks/useHive.ts b/src/renderer/src/hooks/useHive.tsindex c8f099c9..531973fb 100644--- a/src/renderer/src/hooks/useHive.ts+++ b/src/renderer/src/hooks/useHive.ts@@ -2,7 +2,6 @@ import { useEffect, useRef } from 'react';import { useStore, type Agent, type StationKind, type ToolKind } from '@/store/store';import {buildSpawnCommand,- ASSISTANT_MODEL,inferAgentProvider,isClaudeProvider,type HarnessConfig@@ -10,8 +9,6 @@ import {const GOD_ID = 'god';const GOD_PTY = `pty-${GOD_ID}`;-const ASSISTANT_ID = 'assistant';-const ASSISTANT_PTY = `pty-${ASSISTANT_ID}`;// How long to let Claude Code's TUI finish booting before we type the first// thing into Michael's terminal, and how long to PAUSE after the /remote-control@@ -80,17 +77,6 @@ function submitToPty(ptyId: string, text: string, settleMs = 250): Promise<void>return next;}-/** Wrap a user message as an enrich task for the assistant. The assistant's- * system prompt has the full instructions; this just frames the one task. */-function enrichTaskPrompt(text: string): string {- return [- `ENRICH TASK: ${text}`,- '',- '(Identify the relevant project, cd in, gather READ-ONLY context, then send the improved,',- 'self-contained prompt to Michael via an outbox message with "to":"god". Do not do the task yourself.)'- ].join('\n');-}-/** Tool name → where the avatar walks + what it carries. */const TOOL_STATION: Record<string, { station: StationKind; carry?: ToolKind }> = {Read: { station: 'shelf', carry: 'Read' },@@ -131,17 +117,13 @@ export function useHive(config: HarnessConfig | null): void {// 'working' (there's a short window where it still reads 'idle' right after we// type into it). One message per cooldown keeps delivery strictly one-by-one.const lastFlush = useRef<Record<string, number>>({});- // In-flight spawn guards so a re-render / StrictMode double-mount can't spawn- // Michael or the assistant twice (the window between the listPtys check and- // the spawnPty call is otherwise racy).+ // In-flight spawn guard so a re-render / StrictMode double-mount can't spawn+ // Michael twice (the window between the listPtys check and spawnPty is racy).const godSpawning = useRef(false);- const assistantSpawning = useRef(false);// Per-agent timestamp until which auto-typers (inbox-wake #3, queue-drain #4)// must leave the agent alone — set while its boot sequence is typing so nothing// collides with /remote-control + the orientation prompt.const bootGraceUntil = useRef<Record<string, number>>({});- // Reactive so the assistant bootstrap (effect #1b) re-runs once Michael is ready.- const godStatus = useStore((s) => s.godStatus);// #5C/#7C.4 — latest circuit-breaker level per agent. When 'constrained'/// 'stopped' the avatar is pinned to 'looping' and hook events must NOT flip it// back to 'working' (the flicker the spec calls out); only a genuine Stop clears it.@@ -222,62 +204,6 @@ export function useHive(config: HarnessConfig | null): void {return () => { cancelled = true; clearTimeout(t); timers.forEach(clearTimeout); };}, [config?.onboardingComplete, config?.harnessHome]);- // 1b) Bootstrap Michael's prep assistant ("Dwight") — only after Michael is- // ready, and only once. Same live-PTY idempotency + spawn-guard as #1.- useEffect(() => {- if (!config?.onboardingComplete || !config.harnessHome) return;- if (godStatus !== 'ready') return;- let cancelled = false;- const t = setTimeout(async () => {- if (cancelled) return;- const live = await window.cth.listPtys().catch(() => []);- if (live.some((p) => p.id === ASSISTANT_PTY)) return; // already running- if (cancelled || assistantSpawning.current) return;- assistantSpawning.current = true;- useStore.getState().removeAgent(ASSISTANT_ID); // clear any stale restored entry-- const command = buildSpawnCommand(config, ASSISTANT_MODEL, 'claude');- const [exe, ...args] = command.trim().split(/\s+/);- const res = await window.cth.spawnPty({- id: ASSISTANT_PTY,- cwd: config.harnessHome!,- command: exe,- provider: 'claude',- args,- cols: 100,- rows: 30,- hive: { id: ASSISTANT_ID, name: 'Dwight', provider: 'claude', cwd: config.harnessHome!, isAssistant: true, role: "Michael's prep assistant" }- });- if (cancelled || !res.ok) { assistantSpawning.current = false; return; }- const assistant: Agent = {- id: ASSISTANT_ID,- name: 'Dwight',- character: 'dwight',- accent: 'sky',- description: "assistant — enriches prompts with repo context, forwards them to Michael",- project: 'hive',- tmuxTarget: '',- cwd: config.harnessHome!,- status: 'idle',- action: 'standing by',- progress: 0,- currentStation: 'desk',- ptyId: ASSISTANT_PTY,- command: command.trim(),- provider: 'claude',- model: ASSISTANT_MODEL,- isAssistant: true,- recentTextTs: Date.now()- };- // addAgent auto-selects the new agent; restore the prior selection so the- // assistant booting in the background doesn't yank focus off Michael.- const prevSel = useStore.getState().selectedId;- useStore.getState().addAgent(assistant);- useStore.getState().select(prevSel ?? GOD_ID);- }, 400);- return () => { cancelled = true; clearTimeout(t); };- }, [config?.onboardingComplete, config?.harnessHome, godStatus]);-// 2) Drive avatars from real hook events emitted by each agent's shim.useEffect(() => {return window.cth.onHiveHookEvent((e) => {@@ -436,22 +362,6 @@ export function useHive(config: HarnessConfig | null): void {return () => clearInterval(iv);}, [config?.onboardingComplete]);- // 3b) Closing time: the hive mail rails cover god + workers, but the prep- // assistant is send-only (no inbox) — the god is even told NOT to wait- // for it. So when the protocol starts, the harness itself asks the- // assistant to save its memory, best-effort, directly via its terminal.- useEffect(() => {- return window.cth.onClosingTime?.((ev) => {- if (ev.phase !== 'started') return;- const asst = useStore.getState().agents.find((a) => a.isAssistant && a.ptyId);- if (!asst?.ptyId) return;- void submitToPty(- asst.ptyId,- 'CLOSING TIME — the harness is shutting down. Append your durable learnings and any in-progress context to your memory.md NOW, then stop. Do not start new work.'- );- });- }, []);-// 4) Drain each agent's queued messages to its terminal, one at a time, the// moment the agent goes idle. This is what lets the user keep sending// messages while the agent's "cloud terminal" is mid-run: the messages@@ -485,11 +395,11 @@ export function useHive(config: HarnessConfig | null): void {};const flush = () => {- const { agents, messageQueues, enrichEnabled } = useStore.getState();+ const { agents, messageQueues, enrichEnabled, markMessageEnriching, removeQueuedMessage, enqueueMessage } = useStore.getState();const byId = (id: string) => agents.find((a) => a.id === id);- // Sub-agents (and the assistant's own direct queue): flush verbatim into- // their own terminal. Michael's queue is handled specially below.+ // Sub-agents: flush verbatim into their own terminal. Michael's queue is+ // handled separately below.for (const a of agents) {if (a.id === GOD_ID) continue;if (!a.ptyId || a.status !== 'idle') continue;@@ -497,14 +407,31 @@ export function useHive(config: HarnessConfig | null): void {dispatch(a.id, a);}- // 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.+ // Michael's queue: enrich OFF → straight to Michael; enrich ON → headless+ // Haiku call (assistant:enrich IPC) that replaces the raw text with an+ // enriched prompt. Slash commands (e.g. /compact) are NEVER enriched.+ // An in-flight enrichment is flagged .enriching = true — skip it so flush+ // can't double-dispatch while the async Haiku call is running.if (messageQueues[GOD_ID]?.length) {- 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));+ const next = messageQueues[GOD_ID][0];+ if (!next.enriching) {+ const isCmd = next.text.startsWith('/');+ if (enrichEnabled && !isCmd) {+ markMessageEnriching(GOD_ID, next.id);+ const god = byId(GOD_ID);+ window.cth.enrichMessage({ message: next.text, cwd: god?.cwd ?? '' })+ .then((res) => {+ removeQueuedMessage(GOD_ID, next.id);+ enqueueMessage(GOD_ID, res.ok && res.prompt ? res.prompt : next.text);+ })+ .catch(() => {+ removeQueuedMessage(GOD_ID, next.id);+ enqueueMessage(GOD_ID, next.text);+ });+ } else {+ dispatch(GOD_ID, byId(GOD_ID));+ }+ }}};diff --git a/src/renderer/src/scene/office/OfficeFloor.tsx b/src/renderer/src/scene/office/OfficeFloor.tsxindex 6c9e89a0..1e3a1917 100644--- a/src/renderer/src/scene/office/OfficeFloor.tsx+++ b/src/renderer/src/scene/office/OfficeFloor.tsx@@ -298,16 +298,11 @@ export function OfficeFloor() {if (waitTiles.length === 0) waitTiles.push(entrance);// Seat 0 is desk-ceo — "Michael's room" — reserved for the god agent.- // Seat 1 is reserved for his prep assistant ("Dwight") so it always sits in- // the desk next to him. Everyone else claims from seat 2 onward.+ // All other workers claim seats from 1 onward.const GOD_SEAT = 0;- const ASSISTANT_SEAT = 1;const claimSeat = (agent: Agent): number | null => {if (agent.isGod) { seatClaims.add(GOD_SEAT); return GOD_SEAT; }- if (agent.isAssistant && seatTiles.length > ASSISTANT_SEAT) {- seatClaims.add(ASSISTANT_SEAT); return ASSISTANT_SEAT;- }- for (let i = 2; i < seatTiles.length; i++) {+ for (let i = 1; i < seatTiles.length; i++) {if (!seatClaims.has(i)) { seatClaims.add(i); return i; }}return null;diff --git a/src/renderer/src/store/store.ts b/src/renderer/src/store/store.tsindex 83df593d..862a16d5 100644--- a/src/renderer/src/store/store.ts+++ b/src/renderer/src/store/store.ts@@ -87,12 +87,15 @@ export interface FeedEntry {/** A message the user has parked for an agent while its terminal was busy.* Queued messages are drained one at a time when the agent next goes idle (see* useHive's flush loop). For Michael's queue the enrich toggle decides whether- * each one is typed into Michael directly or routed through the assistant. */+ * each one is sent through headless Haiku enrichment or typed in directly. */export interface QueuedMessage {id: string;text: string;/** epoch ms the message was queued — drives ordering and the "queued 2m ago" hint */ts: number;+ /** True while headless Haiku enrichment is in flight. Prevents double-dispatch;+ * the message stays visible in the queue with an 'enriching…' indicator. */+ enriching?: boolean;}export type SidebarTab = 'terminal' | 'files' | 'messages' | 'traces';@@ -175,6 +178,9 @@ interface State {enqueueMessage: (agentId: string, text: string) => void;/** Drop a single queued message (user removed it, or it was just delivered). */removeQueuedMessage: (agentId: string, messageId: string) => void;+ /** Mark a queued message as enriching (in-flight Haiku call). Prevents the+ * drain from double-dispatching it while enrichment is in progress. */+ markMessageEnriching: (agentId: string, messageId: string) => void;/** Clear an agent's entire pending queue. */clearQueue: (agentId: string) => void;setAddAgentOpen: (open: boolean) => void;@@ -487,6 +493,16 @@ export const useStore = create<State>((set) => ({persistQueues(messageQueues);return { messageQueues };}),+ markMessageEnriching: (agentId, messageId) =>+ set((s) => {+ const q = s.messageQueues[agentId];+ if (!q) return s;+ const idx = q.findIndex((m) => m.id === messageId);+ if (idx === -1) return s;+ const updated = [...q];+ updated[idx] = { ...updated[idx], enriching: true };+ return { messageQueues: { ...s.messageQueues, [agentId]: updated } };+ }),clearQueue: (agentId) =>set((s) => {if (!s.messageQueues[agentId]?.length) return s;