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
merge: integrate feat/slack-queue — Slack inbound/outbound + webhook
Chaitanya Giri9390d00862d0
diff --cc src/main/hive.tsindex 8aa11897,d7e00d7e..eb91941d--- a/src/main/hive.ts+++ b/src/main/hive.ts@@@ -65,10 -55,18 +65,22 @@@ export interface HiveTaskdependsOn: string[];priority: number;createdAt: string;+ /** First-class human feedback: the god appends {q} when a card can only+ * proceed with the human's input (status goes blocked); the harness UI+ * fills in {a}. The full history stays on the card forever. */+ humanQA?: HumanQA[];+ /** Outcome summary, surfaced by the Slack done-notifier when this card reaches+ * 'done'. Optional; the notifier falls back to description/title. */+ result?: string;+ /** Set when this task originated from a Slack message — the thread the+ * done-summary reply is posted back into. Consumed OUTBOUND only; populating+ * it is the inbound/kanban side's job and does not affect routing. */+ slack?: { channel: string; thread_ts: string };+ /** Set when this task originated from a generic webhook POST. Stores the SHA-256+ * of the capability token (never the raw token — that's returned to the caller+ * once and never persisted), so a GET status lookup can match by hashing the+ * presented token. Read-only capability: it never widens routing or exposure. */+ webhook?: { tokenHash: string };}export interface AgentMeta {diff --cc src/main/index.tsindex ea0e831b,7fb939da..ce74a01a--- a/src/main/index.ts+++ b/src/main/index.ts@@@ -22,11 -23,10 +23,12 @@@ import { PersistStore } from './db'import { enrichMessage } from './assistant';import { readAgentUsage, readContextTokens } from './transcript';import { listIssues, listCIRuns } from './github';- import { SlackWebhookServer } from './slack';+ import { SlackWebhookServer, SlackReplyServer, postSlackReply } from './slack';+ import { WebhookServer, type WebhookInbound, type WebhookTaskStatus } from './webhook';import { TelemetryCollector } from './telemetry';import { ControlRegistry } from './control';+import { ClosingTimeController } from './closingTime';+import { inferAgentProvider, isClaudeProvider, nonInteractiveEnvForProvider, type AgentProvider } from '../shared/agentProvider';const isDev = !!process.env.ELECTRON_RENDERER_URL;const ptyManager = new PtyManager();diff --cc src/preload/index.tsindex 3dc68922,60db08c1..37b00eff--- a/src/preload/index.ts+++ b/src/preload/index.ts@@@ -55,9 -42,13 +55,16 @@@ export interface HiveTaskdependsOn: string[];priority: number;createdAt: string;+ /** First-class human feedback: god appends {q}, the harness UI fills {a};+ * the full history stays on the card. */+ humanQA?: HumanQA[];+ /** Outcome summary used for the Slack done-notification. */+ result?: string;+ /** Origin thread for a Slack-sourced task (drives the done-summary reply). */+ slack?: { channel: string; thread_ts: string };+ /** SHA-256 of the capability token for a generic-webhook-sourced task (drives+ * the GET status lookup; the raw token is never persisted). */+ webhook?: { tokenHash: string };}/** A message the router just delivered, with its resolved recipient ids. Drivesdiff --cc src/renderer/src/hooks/useHive.tsindex f89865bf,1af5f6e6..c47b013d--- a/src/renderer/src/hooks/useHive.ts+++ b/src/renderer/src/hooks/useHive.ts@@@ -1,11 -1,6 +1,11 @@@import { useEffect, useRef } from 'react';- import { useStore, type Agent, type StationKind, type ToolKind } from '@/store/store';+ import { useStore, type Agent, type QueuedMessage, type StationKind, type ToolKind } from '@/store/store';-import { buildSpawnCommand, ASSISTANT_MODEL, type HarnessConfig } from '@/store/config';+import {+ buildSpawnCommand,+ inferAgentProvider,+ isClaudeProvider,+ type HarnessConfig+} from '@/store/config';const GOD_ID = 'god';const GOD_PTY = `pty-${GOD_ID}`;@@@ -394,12 -437,45 +394,45 @@@ export function useHive(config: Harnessreturn true;};+ // Promote a genuine Slack-origin work item to a stamped kanban card the first+ // time it's dispatched to the office. The card carries slack:{channel,thread_ts}+ // (origin thread) so the main-process done-observer can post its one summary+ // reply in-thread once the card later reaches 'done'. ADDITIVE + idempotent ++ // best-effort: a failure here never affects the dispatch that already happened,+ // and only dispatched work items land here (slash commands/acks never do).+ type SlackTaskCard = Parameters<typeof window.cth.hiveWriteTasks>[0][number];+ const ensureSlackCard = async (m: QueuedMessage): Promise<void> => {+ const slack = m.slack;+ if (!slack) return;+ try {+ const raw = await window.cth.hiveTasks();+ const existing: SlackTaskCard[] =+ raw && typeof raw === 'object' && Array.isArray((raw as { tasks?: unknown }).tasks)+ ? (raw as { tasks: SlackTaskCard[] }).tasks+ : [];+ const id = `slack-${slack.thread_ts}-${m.id}`;+ if (existing.some((t) => t.id === id)) return; // already promoted — no dup+ const title = m.text.length > 80 ? `${m.text.slice(0, 79)}…` : m.text;+ const card: SlackTaskCard = {+ id,+ title,+ description: m.text,+ status: 'todo',+ dependsOn: [],+ priority: 1,+ createdAt: new Date().toISOString(),+ slack+ };+ await window.cth.hiveWriteTasks([...existing, card]);+ } catch { /* best-effort: card promotion must never sink dispatch */ }+ };+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;@@@ -407,29 -483,27 +440,23 @@@dispatch(a.id, a);}- // 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.- // Michael's queue, routed per HEAD message:- // - slash command (e.g. /compact) → Michael verbatim, NEVER enriched.- // - Slack #enrich tag OR the global enrich toggle → ENRICH TASK to Dwight,- // who forwards to Michael.- // - otherwise → straight to Michael.- // Slack-origin work items are stamped as kanban cards on successful dispatch;- // the main-process done-observer posts the one in-thread summary when a card- // reaches 'done' (no per-worker reply directive — that's the single path).++ // Michael's queue: slash commands go verbatim (no card). Slack-origin or++ // enrich-enabled non-commands go through headless Haiku. Slack card is++ // stamped BEFORE enrichment — enriched re-queue loses .slack/.enrich.if (messageQueues[GOD_ID]?.length) {- const next = messageQueues[GOD_ID][0];- if (!next.enriching) {- const isCmd = next.text.startsWith('/');- if (enrichEnabled && !isCmd) {- markMessageEnriching(GOD_ID, next.id);+ const head = messageQueues[GOD_ID][0];- const isCmd = head.text.startsWith('/');- if (isCmd) {- // Control command (e.g. /compact) — never a work item: no card (anti-spam).- dispatch(GOD_ID, byId(GOD_ID));- } else if (head.enrich || enrichEnabled) {- if (dispatch(GOD_ID, byId(ASSISTANT_ID), (m) => enrichTaskPrompt(m.text)) && head.slack) {- void ensureSlackCard(head);- }- } else {- if (dispatch(GOD_ID, byId(GOD_ID)) && head.slack) {- void ensureSlackCard(head);++ if (!head.enriching) {++ const isCmd = head.text.startsWith('/');++ if (isCmd) { dispatch(GOD_ID, byId(GOD_ID)); }++ else if (head.enrich || enrichEnabled) {++ if (head.slack) void ensureSlackCard(head);++ markMessageEnriching(GOD_ID, head.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);- });++ window.cth.enrichMessage({ message: head.text, cwd: god?.cwd ?? '' })++ .then((res) => { removeQueuedMessage(GOD_ID, head.id); enqueueMessage(GOD_ID, res.ok && res.prompt ? res.prompt : head.text); })++ .catch(() => { removeQueuedMessage(GOD_ID, head.id); enqueueMessage(GOD_ID, head.text); });+ } else {- dispatch(GOD_ID, byId(GOD_ID));++ if (dispatch(GOD_ID, byId(GOD_ID)) && head.slack) void ensureSlackCard(head);}}}diff --cc src/renderer/src/store/store.tsindex 862a16d5,29a6c7d4..bf206be3--- a/src/renderer/src/store/store.ts+++ b/src/renderer/src/store/store.ts@@@ -93,9 -90,10 +93,13 @@@ export interface QueuedMessagetext: 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;+ /** Slack-originated: route to the enrich queue regardless of the global toggle. */+ enrich?: boolean;+ /** Slack-originated: thread coordinates so the office can reply in-thread. */+ slack?: { channel: string; thread_ts: string };}export type SidebarTab = 'terminal' | 'files' | 'messages' | 'traces';@@@ -174,13 -155,11 +178,14 @@@ interface State* composer) doesn't eat what the user was typing. */drafts: Record<string, string>;setDraft: (agentId: string, text: string) => void;- /** Park a message for an agent. Returns nothing; the flush loop delivers it. */- enqueueMessage: (agentId: string, text: string) => void;+ /** Park a message for an agent. Returns nothing; the flush loop delivers it.+ * `meta` carries optional Slack routing context (enrich flag + reply thread). */+ enqueueMessage: (agentId: string, text: string, meta?: { enrich?: boolean; slack?: { channel: string; thread_ts: 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;