Multiplayer agent harness for work.
Slack Agents support: pin QM to the top bar (agent_view) (#572)
Joshua France568252bd4e6d
diff --git a/cli/package-lock.json b/cli/package-lock.jsonindex 6a1229211..8b469f6a2 100644--- a/cli/package-lock.json+++ b/cli/package-lock.json@@ -1,12 +1,12 @@{"name": "@yc-software/qm",- "version": "0.1.5",+ "version": "0.1.6","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@yc-software/qm",- "version": "0.1.5",+ "version": "0.1.6","license": "MIT","bin": {"qm": "dist/bin/qm.js"diff --git a/cli/package.json b/cli/package.jsonindex d7349677a..4fbc357d4 100644--- a/cli/package.json+++ b/cli/package.json@@ -1,6 +1,6 @@{"name": "@yc-software/qm",- "version": "0.1.5",+ "version": "0.1.6","license": "MIT","description": "Control-plane CLI for portable QM deployments on Docker, Fly, and AWS.","type": "module",diff --git a/cli/templates/slack-manifest.json b/cli/templates/slack-manifest.jsonindex 4434a964a..a920d4816 100644--- a/cli/templates/slack-manifest.json+++ b/cli/templates/slack-manifest.json@@ -13,6 +13,9 @@"bot_user": {"display_name": "agent","always_online": true+ },+ "agent_view": {+ "agent_description": "A workspace agent you can pin to the Slack top bar. Ask it anything; it can also act on what you're currently viewing."}},"oauth_config": {@@ -41,7 +44,8 @@"reactions:read","pins:read","pins:write",- "emoji:read"+ "emoji:read",+ "assistant:write"]}},@@ -59,7 +63,9 @@"channel_rename","channel_unarchive","reaction_added",- "reaction_removed"+ "reaction_removed",+ "assistant_thread_started",+ "assistant_thread_context_changed"]},"interactivity": {diff --git a/src/slack/README.md b/src/slack/README.mdindex 461f22749..02b0c2298 100644--- a/src/slack/README.md+++ b/src/slack/README.md@@ -21,6 +21,24 @@ Slack ⇄ (WebSocket) slack surface (in core) ── direct calls ──▶(Socket Mode is already enabled by the manifest. No request URLs to configure.)+### Slack Agents (top-bar pin)++The manifest enables Slack's [Agents & AI Apps](https://docs.slack.dev/ai/developing-agents)+feature (`agent_view`) for one reason: users can pin the app to the Slack top bar and open+it anywhere. Conversations in the resulting split pane are ordinary DM thread messages and+flow through the normal DM machinery unchanged — none of the extra agent UI (status+indicators, thread titles, context passing, suggested prompts) is implemented.++Two caveats:++- **Paid plan required.** Slack only serves the AI-apps experience on paid plans (the+ Developer Program sandbox also works).+- **Existing installs must update the manifest and reinstall** to pick up the+ `assistant:write` scope and the `assistant_thread_started` and+ `assistant_thread_context_changed` events (Slack requires both to enable the feature;+ the plugin acknowledges them as no-ops). Installs that don't update keep working+ exactly as before.+> **Running locally alongside another developer? Each dev needs their OWN app.**> See [Local dev with multiple developers](#local-dev-with-multiple-developers)> below — set the manifest `name`/`display_name` to `agent-<yourname>` beforediff --git a/src/slack/events.ts b/src/slack/events.tsindex 7f5a4d695..e8bec5620 100644--- a/src/slack/events.ts+++ b/src/slack/events.ts@@ -252,6 +252,9 @@ export function registerSlackEvents(await forceDirectorySync(client, e.channel, principalId);});+ app.event("assistant_thread_started", async () => {});+ app.event("assistant_thread_context_changed", async () => {});+app.event("reaction_added", async ({ event, body, client }: any) => {await handleReactionEvent(event as SlackReactionEvent, body as any, client, true);});diff --git a/src/slack/manifest.json b/src/slack/manifest.jsonindex 4434a964a..a920d4816 100644--- a/src/slack/manifest.json+++ b/src/slack/manifest.json@@ -13,6 +13,9 @@"bot_user": {"display_name": "agent","always_online": true+ },+ "agent_view": {+ "agent_description": "A workspace agent you can pin to the Slack top bar. Ask it anything; it can also act on what you're currently viewing."}},"oauth_config": {@@ -41,7 +44,8 @@"reactions:read","pins:read","pins:write",- "emoji:read"+ "emoji:read",+ "assistant:write"]}},@@ -59,7 +63,9 @@"channel_rename","channel_unarchive","reaction_added",- "reaction_removed"+ "reaction_removed",+ "assistant_thread_started",+ "assistant_thread_context_changed"]},"interactivity": {diff --git a/test/slack-agent-pin.test.ts b/test/slack-agent-pin.test.tsnew file mode 100644index 000000000..f86d0db3b--- /dev/null+++ b/test/slack-agent-pin.test.ts@@ -0,0 +1,44 @@+import { test } from "node:test";+import assert from "node:assert/strict";+import { registerSlackEvents } from "../src/slack/events.ts";+import { createDeduper } from "../src/slack/lib.ts";+import type { TurnHandler } from "../src/slack/turn-handler.ts";++function fakeApp() {+ const events = new Map<string, (args: any) => Promise<void>>();+ const messages: Array<(args: any) => Promise<void>> = [];+ return {+ app: {+ event: (name: string, h: (args: any) => Promise<void>) => void events.set(name, h),+ message: (h: (args: any) => Promise<void>) => void messages.push(h),+ },+ fire: (name: string, event: unknown) => events.get(name)!({ event, body: {}, client: {}, context: {} }),+ hasEvent: (name: string) => events.has(name),+ im: (message: Record<string, unknown>) =>+ messages[0]!({ message: { channel_type: "im", ...message }, body: {}, client: {}, context: {} }),+ };+}++test("assistant events are acknowledged as no-ops and pane messages dispatch as plain DM turns", async () => {+ const dispatched: any[] = [];+ const app = fakeApp();+ registerSlackEvents(app.app, {+ handler: {+ dispatch: async (_key: string, inc: any) => void dispatched.push(inc),+ handleReactionEvent: async () => {},+ botHasStakeInThread: async () => false,+ } as unknown as TurnHandler,+ mirror: { mirrorMessageEvent: async () => {}, pushSurfaceEvents: async () => {} } as any,+ directory: { syncForUnseenGroup: () => {}, forceDirectorySync: async () => {} } as any,+ ids: { botUserId: "UBOT", ownBotId: "BBOT" } as any,+ deduper: createDeduper(),+ });+ assert.equal(app.hasEvent("assistant_thread_started"), true);+ assert.equal(app.hasEvent("assistant_thread_context_changed"), true);+ await app.fire("assistant_thread_started", { assistant_thread: { channel_id: "D111", thread_ts: "100.1" } });+ await app.im({ channel: "D111", user: "U1", text: "hello", ts: "100.2", thread_ts: "100.1" });+ assert.equal(dispatched.length, 1);+ assert.equal(dispatched[0].kind, "dm");+ assert.equal(dispatched[0].threadTs, "100.1");+ assert.equal(dispatched[0].contextNote, undefined);+});