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): autonomy preamble on god's prompt for Slack-origin work

Chaitanya Giride3fb8e09c67
diff --git a/src/main/index.ts b/src/main/index.ts
index 6418fa12..2cb876eb 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -589,6 +589,15 @@ let slackReplyServer: SlackReplyServer | null = null;
* Request URL after a reopen (Slack reuses it until the server is stopped). */
let lastSlackUrl: string | undefined;
+/** Fixed policy preamble prepended (server-side, authoritatively) to the working
+ * instruction god reads for any Slack-origin request. It tells god there is no
+ * interactive human at the keyboard: act autonomously, pausing only for the
+ * enumerated high-severity actions, and route genuine decisions back as a Slack
+ * reply. This is prepended to god's PROMPT only — the human-facing kanban card
+ * TITLE stays the user's raw text (the renderer keeps them split). Trailing
+ * space is intentional so the user's message reads naturally after it. */
+const SLACK_AUTONOMY_PREAMBLE = `[SLACK-ORIGIN REQUEST — AUTONOMOUS MODE] This task arrived via Slack; there is no interactive human at the keyboard. Do NOT ask interactive questions and do NOT wait on the human — execute it autonomously end to end, doing reads and normal work freely. PAUSE and ask ONLY for these HIGH-SEVERITY actions: (1) pushing to main or any remote, (2) buying or spawning infrastructure or paid services, (3) deleting an existing repo, file, or folder you did NOT create. For critical infrastructure and git-push-type changes, stay READ-ONLY unless explicitly approved. If a genuine DECISION is needed to proceed, do NOT block: complete everything you safely can, then ASK YOUR QUESTION AS THE SLACK REPLY — phrase it clearly with explicit numbered OPTIONS — using the Slack reply helper, and record it on this task's humanQA as {q, options, askedAt (ISO + human-readable day & time), thread_ts}. When a later Slack message arrives in a thread that already has a pending recorded question (match by thread_ts), treat it as the answer and resume. The user's message starts now: `;
+
// ─── 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
@@ -851,8 +860,13 @@ async function startSlackServer(): Promise<{ ok: boolean; url?: string; error?:
m._rawFiles ?? [],
readConfig().slackBotToken
);
- const ipcMsg: { text: string; channel: string; ts: string; thread_ts: string; files?: typeof localFiles } = {
- text: m.text, channel: m.channel, ts: m.ts, thread_ts: m.thread_ts
+ // `text` stays the user's RAW Slack text → drives the readable kanban card
+ // title. `autonomyPreamble` is the authoritative policy block the renderer
+ // prepends ONLY to god's working instruction (his PTY prompt), keeping the
+ // card title human-facing-clean. Server-side so it applies to every session.
+ const ipcMsg: { text: string; channel: string; ts: string; thread_ts: string; autonomyPreamble: string; files?: typeof localFiles } = {
+ text: m.text, channel: m.channel, ts: m.ts, thread_ts: m.thread_ts,
+ autonomyPreamble: SLACK_AUTONOMY_PREAMBLE
};
if (localFiles.length > 0) ipcMsg.files = localFiles;
try { liveWebContents()?.send('slack:incomingMessage', ipcMsg); }
diff --git a/src/preload/index.ts b/src/preload/index.ts
index db1be78a..df3c33c2 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -604,8 +604,8 @@ const api = {
// ─── Slack integration (Slack message → Michael's queue) ─────────────────────
/** Register a listener for inbound Slack messages; returns an unsubscribe fn.
* The message carries the thread coordinates needed to reply in-thread. */
- onSlackMessage: (cb: (msg: { text: string; channel: string; ts: string; thread_ts: string; files?: { path: string; name: string; mimetype: string }[] }) => void): (() => void) => {
- const listener = (_e: IpcRendererEvent, msg: { text: string; channel: string; ts: string; thread_ts: string; files?: { path: string; name: string; mimetype: string }[] }) => cb(msg);
+ onSlackMessage: (cb: (msg: { text: string; channel: string; ts: string; thread_ts: string; autonomyPreamble?: string; files?: { path: string; name: string; mimetype: string }[] }) => void): (() => void) => {
+ const listener = (_e: IpcRendererEvent, msg: { text: string; channel: string; ts: string; thread_ts: string; autonomyPreamble?: string; files?: { path: string; name: string; mimetype: string }[] }) => cb(msg);
ipcRenderer.on('slack:incomingMessage', listener);
return () => ipcRenderer.removeListener('slack:incomingMessage', listener);
},
diff --git a/src/renderer/src/hooks/useHive.ts b/src/renderer/src/hooks/useHive.ts
index f4112679..80c7dc39 100644
--- a/src/renderer/src/hooks/useHive.ts
+++ b/src/renderer/src/hooks/useHive.ts
@@ -482,7 +482,11 @@ export function useHive(config: HarnessConfig | null): void {
if (next.text.trim().toLowerCase() === '/clear') {
useStore.getState().updateAgent(target.id, { contextTokens: 0, contextLimit: undefined, progress: 0 });
}
- submitToPty(target.ptyId, wrap ? wrap(next) : next.text).catch(() => { /* pty may have died */ });
+ // `instruction` (when present) is the authoritative text to type into the
+ // PTY — e.g. Slack-origin work carries the autonomy preamble there while the
+ // kanban card keeps `text` (raw) as its readable title. UI/card surfaces
+ // never read `instruction`, so this stays invisible to the human board.
+ submitToPty(target.ptyId, wrap ? wrap(next) : (next.instruction ?? next.text)).catch(() => { /* pty may have died */ });
return true;
};
@@ -562,7 +566,14 @@ export function useHive(config: HarnessConfig | null): void {
text = text ? `${text}\n\nAttached files:\n${fileLines}` : `Attached files:\n${fileLines}`;
}
const slack = { channel: msg.channel, thread_ts: msg.thread_ts };
- useStore.getState().enqueueMessage(GOD_ID, text, { slack });
+ // `text` (raw user request + any attachment lines) drives the human-facing
+ // kanban card title/description. The autonomy preamble — supplied verbatim
+ // by main, the authoritative source — is prepended ONLY to god's working
+ // instruction (what gets typed into his PTY), so the board stays readable
+ // while every Slack-origin god-session runs under the autonomy policy. When
+ // main sends no preamble (older build), god just gets the raw text.
+ const instruction = msg.autonomyPreamble ? `${msg.autonomyPreamble}${text}` : undefined;
+ useStore.getState().enqueueMessage(GOD_ID, text, { slack, instruction });
// Immediate "queued" acknowledgement in the originating Slack thread.
void window.cth.slackReply({
channel: msg.channel,
diff --git a/src/renderer/src/store/store.ts b/src/renderer/src/store/store.ts
index f2ecd047..c4c11678 100644
--- a/src/renderer/src/store/store.ts
+++ b/src/renderer/src/store/store.ts
@@ -96,6 +96,11 @@ export interface QueuedMessage {
ts: number;
/** Slack-originated: thread coordinates so the office can reply in-thread. */
slack?: { channel: string; thread_ts: string };
+ /** Optional override for the text actually typed into the agent's PTY. When set,
+ * the drain submits THIS instead of `text`, while UI/card surfaces keep using
+ * `text`. Used by Slack-origin work to carry the autonomy preamble to god's
+ * prompt without polluting the human-readable kanban card title (= raw `text`). */
+ instruction?: string;
}
export type SidebarTab = 'terminal' | 'files' | 'messages' | 'traces';
@@ -169,8 +174,10 @@ 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, meta?: { slack?: { channel: string; thread_ts: string } }) => void;
+ /** Park a message for an agent. Returns nothing; the flush loop delivers it.
+ * `meta.instruction`, when set, is what gets typed into the PTY instead of
+ * `text` (UI/card surfaces still show `text`). */
+ enqueueMessage: (agentId: string, text: string, meta?: { slack?: { channel: string; thread_ts: string }; instruction?: string }) => void;
/** Drop a single queued message (user removed it, or it was just delivered). */
removeQueuedMessage: (agentId: string, messageId: string) => void;
/** Clear an agent's entire pending queue. */
@@ -464,7 +471,8 @@ export const useStore = create<State>((set) => ({
if (!trimmed) return s;
const msg: QueuedMessage = {
id: newQueuedId(), text: trimmed, ts: Date.now(),
- ...(meta?.slack ? { slack: meta.slack } : {})
+ ...(meta?.slack ? { slack: meta.slack } : {}),
+ ...(meta?.instruction ? { instruction: meta.instruction } : {})
};
const messageQueues = { ...s.messageQueues, [agentId]: [...(s.messageQueues[agentId] ?? []), msg] };
persistQueues(messageQueues);