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(slack): post one summary reply when a Slack-origin task hits 'done'
Chaitanya Girib0e611e7c152
diff --git a/src/main/hive.ts b/src/main/hive.tsindex 29d45b13..232d8b79 100644--- a/src/main/hive.ts+++ b/src/main/hive.ts@@ -55,6 +55,13 @@ export interface HiveTask {dependsOn: string[];priority: number;createdAt: string;+ /** 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 };}export interface AgentMeta {diff --git a/src/main/index.ts b/src/main/index.tsindex c2fb9163..c899ffe5 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -503,6 +503,20 @@ let slackReplyServer: SlackReplyServer | null = null;* Request URL after a reopen (Slack reuses it until the server is stopped). */let lastSlackUrl: string | undefined;+// ─── Slack done-notifier (Slack-origin task → done → one summary reply) ───────+/** Polls the shared kanban (hive/tasks.json) for Slack-origin tasks that reach+ * 'done' and posts ONE summary reply into the originating thread. Lifecycle is+ * tied to `slackServer`. OUTBOUND-only: it never touches inbound queue/lanes. */+let slackDoneTimer: ReturnType<typeof setInterval> | null = null;+/** Re-entrancy guard so a slow post can't overlap the next tick. */+let slackDonePolling = false;+/** Task ids already notified — exactly-once across re-reads AND restarts. Lazily+ * loaded from / persisted to `slackDoneNotifiedPath()`. */+let slackDoneNotified: Set<string> | null = null;+/** Ids already 'done' when the observer started — baselined (never notified) so a+ * summary only ever fires on a live …→done transition, not on pre-existing dones. */+let slackDoneBaseline: Set<string> | null = null;+/** Absolute path to the bundled `md-slack-reply.cjs` helper. Packaged: under* `process.resourcesPath` (electron-builder extraResources). Dev: the repo's* `resources/` dir, resolved from the app path. */@@ -518,6 +532,95 @@ function slackReplyConfigPath(): string {return join(app.getPath('userData'), 'slack-reply.json');}+/** Ledger of task ids whose done-summary has already been posted. Ids ONLY — no+ * secret ever lands here. Under userData (out of the repo, out of MemPalace). */+function slackDoneNotifiedPath(): string {+ return join(app.getPath('userData'), 'slack-done-notified.json');+}++function loadSlackDoneNotified(): Set<string> {+ try {+ const arr = JSON.parse(readFileSync(slackDoneNotifiedPath(), 'utf8'));+ if (Array.isArray(arr)) return new Set(arr.filter((x): x is string => typeof x === 'string'));+ } catch { /* missing/corrupt → start empty */ }+ return new Set();+}++function persistSlackDoneNotified(set: Set<string>): void {+ try { writeFileSync(slackDoneNotifiedPath(), JSON.stringify([...set])); }+ catch (e) { console.error('[slack] could not persist done-notify ledger:', e); }+}++/** The single in-thread summary for a finished task. Sourced from the task's+ * result/description (falling back to the title), trimmed Slack-friendly. */+function slackDoneSummary(task: HiveTask): string {+ const body = (task.result ?? task.description ?? '').trim();+ const head = `:white_check_mark: *Done:* ${task.title}`;+ const text = body ? `${head}\n${body}` : head;+ return text.length > 2800 ? `${text.slice(0, 2799)}…` : text;+}++/** One observation pass over the kanban. Posts a summary for any Slack-origin+ * task that has newly reached 'done'. Best-effort and self-guarding — it must+ * never throw into the timer, and the bot token never leaves this function. */+async function pollSlackDoneTasks(): Promise<void> {+ if (slackDonePolling) return;+ const botToken = readConfig().slackBotToken;+ if (!botToken) return; // can't post without the token — nothing to do+ let tasks: HiveTask[];+ try {+ const ledger = hive.tasks() as { tasks?: HiveTask[] };+ tasks = Array.isArray(ledger?.tasks) ? ledger.tasks : [];+ } catch { return; } // unreadable/missing tasks.json → skip this tick++ const notified = slackDoneNotified ?? (slackDoneNotified = loadSlackDoneNotified());++ // First tick seeds the baseline (ids already done) and posts nothing — so we+ // only ever fire on a transition observed live this session.+ if (slackDoneBaseline === null) {+ slackDoneBaseline = new Set(tasks.filter((t) => t.status === 'done').map((t) => t.id));+ return;+ }+ const baseline = slackDoneBaseline;++ slackDonePolling = true;+ try {+ for (const t of tasks) {+ if (t.status !== 'done') continue;+ if (baseline.has(t.id) || notified.has(t.id)) continue; // already handled+ const slack = t.slack;+ if (!slack || !slack.channel || !slack.thread_ts) continue; // non-Slack-origin → leave alone+ const res = await postSlackReply({+ botToken, channel: slack.channel, thread_ts: slack.thread_ts, text: slackDoneSummary(t)+ });+ if (res.ok) {+ notified.add(t.id);+ persistSlackDoneNotified(notified); // mark-on-success → exactly one delivered reply+ } else {+ // Genuinely undelivered → leave unmarked so a later tick retries. Log+ // the id + error only; never the token or message body.+ console.error('[slack] done-summary post failed for task', t.id, '-', res.error);+ }+ }+ } finally {+ slackDonePolling = false;+ }+}++/** Begin watching the kanban for Slack-origin done-transitions (idempotent). */+function startSlackDoneObserver(): void {+ if (slackDoneTimer) return;+ slackDoneNotified = loadSlackDoneNotified();+ slackDoneBaseline = null; // re-seed on the first tick of this session+ slackDoneTimer = setInterval(() => { void pollSlackDoneTasks(); }, 5000);+}++/** Stop watching the kanban. Safe to call when not running. */+function stopSlackDoneObserver(): void {+ if (slackDoneTimer) { clearInterval(slackDoneTimer); slackDoneTimer = null; }+ slackDoneBaseline = null;+}+/** Build a SlackWebhookServer from the current config and start it, replacing* any running instance, and return the start result (incl. the public tunnel* URL the user pastes into Slack). No-op + error result when the integration is@@ -549,6 +652,9 @@ async function startSlackServer(): Promise<{ ok: boolean; url?: string; error?:// the discovery file for the bundled helper. Best-effort: reply path being// unavailable must not sink ingestion.await startSlackReplyServer();+ // Begin watching the kanban for Slack-origin tasks that reach 'done', to post+ // their one summary reply in-thread. OUTBOUND-only; never touches ingestion.+ startSlackDoneObserver();return res;}@@ -582,6 +688,7 @@ function stopSlackServer(): void {slackServer = null;try { slackReplyServer?.stop(); } catch (e) { console.error('[slack] reply stop failed:', e); }slackReplyServer = null;+ stopSlackDoneObserver();try { if (existsSync(slackReplyConfigPath())) unlinkSync(slackReplyConfigPath()); } catch { /* noop */ }}diff --git a/src/preload/index.ts b/src/preload/index.tsindex 831b6c47..00851b03 100644--- a/src/preload/index.ts+++ b/src/preload/index.ts@@ -42,6 +42,10 @@ export interface HiveTask {dependsOn: string[];priority: number;createdAt: string;+ /** 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 };}/** A message the router just delivered, with its resolved recipient ids. Drives