Skip to content

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

feat(slack): bundle md-slack-reply.cjs helper + preload reply/status API

Chaitanya Girie54abf206ba8
diff --git a/electron-builder.yml b/electron-builder.yml
index 13b774bc..93b1e493 100644
--- a/electron-builder.yml
+++ b/electron-builder.yml
@@ -18,6 +18,13 @@ files:
- "!**/*.{md,map,ts,tsx}"
- "!**/{.eslintrc,.prettierrc,tsconfig*.json,electron.vite.config.*}"
+# Ship the standalone Slack reply helper as a plain file under the app's
+# resources dir (process.resourcesPath). It runs under `node`, NOT inside the
+# asar, so the office worker can invoke `node <resources>/md-slack-reply.cjs`.
+extraResources:
+ - from: resources/md-slack-reply.cjs
+ to: md-slack-reply.cjs
+
asarUnpack:
- "**/node_modules/node-pty/**"
# better-sqlite3 is native (bindings/prebuild need the .node on the real FS).
diff --git a/resources/md-slack-reply.cjs b/resources/md-slack-reply.cjs
new file mode 100755
index 00000000..8acdaea5
--- /dev/null
+++ b/resources/md-slack-reply.cjs
@@ -0,0 +1,100 @@
+#!/usr/bin/env node
+/**
+ * md-slack-reply.cjs — post a message back into the Slack thread that triggered
+ * an office run, WITHOUT ever handling the bot token.
+ *
+ * The Munder Difflin main process runs a loopback-only HTTP endpoint (bound to
+ * 127.0.0.1, never tunneled) and writes its `{ port, token }` to a small
+ * discovery file under the app's userData dir. This helper reads that file and
+ * POSTs the reply to the endpoint, which holds the bot token and forwards to
+ * Slack's chat.postMessage. The token never appears here, in the prompt, or in
+ * any transcript.
+ *
+ * Usage:
+ * node md-slack-reply.cjs --channel C123 --thread 1700000000.000100 --text "..."
+ * (optional) --config /abs/path/to/slack-reply.json
+ *
+ * The discovery file is located via, in order: --config, then the
+ * MD_SLACK_REPLY_CONFIG env var (injected into every agent by main).
+ */
+'use strict';
+
+const fs = require('node:fs');
+const http = require('node:http');
+
+/** Parse `--key value` and `--key=value` pairs from argv. */
+function parseArgs(argv) {
+ const out = {};
+ for (let i = 0; i < argv.length; i++) {
+ const a = argv[i];
+ if (!a.startsWith('--')) continue;
+ const eq = a.indexOf('=');
+ if (eq !== -1) { out[a.slice(2, eq)] = a.slice(eq + 1); continue; }
+ const key = a.slice(2);
+ const next = argv[i + 1];
+ if (next !== undefined && !next.startsWith('--')) { out[key] = next; i++; }
+ else out[key] = true;
+ }
+ return out;
+}
+
+function fail(msg) {
+ process.stderr.write(`md-slack-reply: ${msg}\n`);
+ process.exit(1);
+}
+
+const args = parseArgs(process.argv.slice(2));
+const channel = args.channel;
+const thread = args.thread || args.thread_ts;
+const text = args.text;
+
+if (!channel || !thread || !text || text === true) {
+ fail('required: --channel <id> --thread <ts> --text "<message>"');
+}
+
+const configPath = args.config || process.env.MD_SLACK_REPLY_CONFIG;
+if (!configPath) {
+ fail('cannot locate the reply endpoint: set MD_SLACK_REPLY_CONFIG or pass --config');
+}
+
+let cfg;
+try {
+ cfg = JSON.parse(fs.readFileSync(configPath, 'utf8'));
+} catch (e) {
+ fail(`reply endpoint not running (could not read ${configPath}): ${e.message}`);
+}
+if (!cfg || typeof cfg.port !== 'number' || typeof cfg.token !== 'string') {
+ fail(`malformed reply config at ${configPath}`);
+}
+
+const body = JSON.stringify({ channel, thread_ts: thread, text });
+const req = http.request(
+ {
+ method: 'POST',
+ host: '127.0.0.1',
+ port: cfg.port,
+ path: '/reply',
+ headers: {
+ 'content-type': 'application/json',
+ 'content-length': Buffer.byteLength(body),
+ 'x-md-reply-token': cfg.token
+ }
+ },
+ (res) => {
+ const chunks = [];
+ res.on('data', (c) => chunks.push(c));
+ res.on('end', () => {
+ const raw = Buffer.concat(chunks).toString('utf8');
+ let json = {};
+ try { json = JSON.parse(raw); } catch { /* non-JSON body */ }
+ if (res.statusCode === 200 && json.ok) {
+ process.stdout.write('Posted reply to Slack thread.\n');
+ process.exit(0);
+ }
+ fail(`reply failed (HTTP ${res.statusCode}): ${json.error || raw || 'unknown error'}`);
+ });
+ }
+);
+req.on('error', (e) => fail(`could not reach reply endpoint: ${e.message}`));
+req.write(body);
+req.end();
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 0cf48983..831b6c47 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -514,9 +514,9 @@ const api = {
// ─── Slack integration (Slack message → Michael's queue) ─────────────────────
/** Register a listener for inbound Slack messages; returns an unsubscribe fn.
- * Same pattern as onHiveHookEvent. */
- onSlackMessage: (cb: (msg: { text: string }) => void): (() => void) => {
- const listener = (_e: IpcRendererEvent, msg: { text: string }) => cb(msg);
+ * The message carries the thread coordinates needed to reply in-thread. */
+ onSlackMessage: (cb: (msg: { text: string; channel: string; ts: string; thread_ts: string }) => void): (() => void) => {
+ const listener = (_e: IpcRendererEvent, msg: { text: string; channel: string; ts: string; thread_ts: string }) => cb(msg);
ipcRenderer.on('slack:incomingMessage', listener);
return () => ipcRenderer.removeListener('slack:incomingMessage', listener);
},
@@ -527,6 +527,18 @@ const api = {
/** Stop the Slack webhook server + tunnel. */
slackStop: (): Promise<{ ok: boolean }> =>
ipcRenderer.invoke('slack:stop'),
+ /** Current connection state + last Request URL (so Settings can hydrate the
+ * "Connected" badge and re-show the persisted tunnel URL on reopen). */
+ slackStatus: (): Promise<{ running: boolean; url?: string }> =>
+ ipcRenderer.invoke('slack:status'),
+ /** Post a reply into a Slack thread (the bot token stays in main). Used for the
+ * renderer's immediate "queued" ack. */
+ slackReply: (m: { channel: string; thread_ts: string; text: string }): Promise<{ ok: boolean; error?: string }> =>
+ ipcRenderer.invoke('slack:reply', m),
+ /** Absolute path to the bundled reply helper, for the office worker's
+ * end-of-run "post your summary back to Slack" instruction. */
+ slackReplyScriptPath: (): Promise<string> =>
+ ipcRenderer.invoke('slack:replyScriptPath'),
/** Persist Slack settings (and stop the server if disabled / secret cleared). */
slackSetConfig: (patch: {
signingSecret?: string; botToken?: string; channelId?: string; port?: number; enabled?: boolean;