Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Clarify hosted and custom Slack setup in admin UI (#1212)

Regan Bell67e040c57ee2
diff --git a/docs/screenshots/slack-setup/hosted.png b/docs/screenshots/slack-setup/hosted.png
new file mode 100644
index 000000000..9a9071bf2
Binary files /dev/null and b/docs/screenshots/slack-setup/hosted.png differ
diff --git a/docs/screenshots/slack-setup/public.png b/docs/screenshots/slack-setup/public.png
new file mode 100644
index 000000000..f1b9f12f4
Binary files /dev/null and b/docs/screenshots/slack-setup/public.png differ
diff --git a/plugins/admin/README.md b/plugins/admin/README.md
index b6417e3c8..296f4a8ab 100644
--- a/plugins/admin/README.md
+++ b/plugins/admin/README.md
@@ -85,3 +85,11 @@ status) · `POST /api/logout` ·
`POST /api/external-users` (invite) · `DELETE /api/external-users/:email` (revoke) — all
proxied to the core's `/v1/admin/…` with the admin actor injected. Grant and external-user
mutation is **org_admin-only** (enforced in the core, not the surface).
+
+## Slack setup
+
+Hosted Add to Slack is shown only when core reports `installAvailable`, enabled by
+`QM_SLACK_SERVICE_URL` and its matching `QM_SLACK_SERVICE_TOKEN`. Public deployments
+without that service lead with the preconfigured Slack app manifest and token form.
+Connected hosted apps offer Re-add to Slack; custom apps must be disconnected before
+switching to the hosted app. Both paths retain the custom app setup instructions.
diff --git a/plugins/admin/public/index.html b/plugins/admin/public/index.html
index f9fa1e825..8b2e5fa4b 100644
--- a/plugins/admin/public/index.html
+++ b/plugins/admin/public/index.html
@@ -4850,6 +4850,122 @@
gap: 9px;
}
}
+
+ #card-slack-installation > .head {
+ border: 0;
+ padding-bottom: 6px;
+ }
+ #card-slack-installation > .head h2 {
+ font-size: 13px;
+ font-weight: 500;
+ color: var(--muted);
+ }
+ #card-slack-installation > .body {
+ padding-top: 0;
+ }
+ #card-slack-installation .slack-connection {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 16px;
+ padding: 10px 8px;
+ border-radius: 8px;
+ }
+ #card-slack-installation h3 {
+ font-size: 14px;
+ font-weight: 500;
+ margin: 0;
+ line-height: 20px;
+ }
+ #card-slack-installation .hint {
+ margin: 2px 0 0;
+ font-size: 12px;
+ line-height: 18px;
+ }
+ .slack-connection-actions {
+ display: flex;
+ gap: 4px;
+ flex-wrap: wrap;
+ }
+ #card-slack-installation .slack-connection-actions button {
+ min-height: 32px;
+ padding: 6px 10px;
+ border: 0;
+ border-radius: 8px;
+ box-shadow: none;
+ background: transparent;
+ color: var(--muted);
+ font-size: 13px;
+ font-weight: 400;
+ }
+ #card-slack-installation .slack-connection-actions button:hover {
+ background: var(--subtle);
+ color: var(--text);
+ }
+ #card-slack-installation #slack-installation-start {
+ color: var(--text);
+ }
+ #slack-own-app-guide {
+ margin-top: 4px;
+ }
+ #slack-own-app-guide summary {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ list-style: none;
+ padding: 9px 8px;
+ border-radius: 8px;
+ cursor: pointer;
+ font-size: 13px;
+ font-weight: 400;
+ color: var(--muted);
+ }
+ #slack-own-app-guide summary::-webkit-details-marker {
+ display: none;
+ }
+ #slack-own-app-guide summary:hover {
+ background: var(--subtle);
+ color: var(--text);
+ }
+ .slack-guide-arrow {
+ font-size: 18px;
+ line-height: 16px;
+ }
+ #slack-own-app-guide[open] .slack-guide-arrow {
+ transform: rotate(90deg);
+ }
+ #slack-own-app-guide > p,
+ #slack-own-app-guide > ol,
+ #slack-own-app-guide > button {
+ margin-left: 8px;
+ }
+ #slack-own-app-guide p,
+ #slack-own-app-guide ol {
+ color: var(--muted);
+ max-width: 760px;
+ line-height: 1.65;
+ }
+ #slack-own-app-guide li {
+ padding: 4px 0 8px 4px;
+ }
+ #slack-token-editor {
+ max-width: 560px;
+ margin-top: 20px;
+ }
+ #st-slack-installation:empty {
+ display: none;
+ }
+ #st-slack-installation {
+ display: block;
+ margin-top: 16px;
+ }
+ @media (max-width: 640px) {
+ #card-slack-installation .slack-connection {
+ align-items: flex-start;
+ flex-direction: column;
+ gap: 16px;
+ }
+ }
</style>
</head>
<body>
@@ -6131,20 +6247,27 @@
</section>
<section class="card" id="card-slack-installation">
<div class="head">
- <h2>Slack installation</h2>
- <p>
- Add Slack after the web deployment is working. Tokens are validated with Slack, encrypted in durable
- storage, and never displayed again.
- </p>
+ <h2>Slack</h2>
</div>
<div class="body">
- <button class="primary hidden" id="slack-installation-start">Add to Slack</button>
- <p class="hint" id="slack-installation-state">Not configured.</p>
+ <div class="slack-connection">
+ <div class="slack-connection-info">
+ <h3 id="slack-installation-state">Connect your workspace</h3>
+ <p class="hint" id="slack-installation-description">Add the QM app to get started.</p>
+ </div>
+ <div class="slack-connection-actions">
+ <button class="primary hidden" id="slack-installation-start">Add to Slack</button>
+ <button class="danger hidden" id="slack-installation-delete">Disconnect</button>
+ </div>
+ </div>
<details id="slack-own-app-guide">
- <summary>Set up your own Slack app</summary>
+ <summary>
+ <span id="slack-own-app-label">Use your own Slack app</span>
+ <span class="slack-guide-arrow" aria-hidden="true">›</span>
+ </summary>
<p>
- Use a workspace-owned app with your bot's name. You'll need permission to install apps in Slack.
- Slack still applies rate limits; this does not provide unlimited history.
+ Give your bot its own name and identity. Start with our preconfigured manifest, then connect your
+ app below.
</p>
<ol>
<li>
@@ -6176,42 +6299,40 @@
</li>
</ol>
<p class="hint">
- Replacing a connected app changes the Slack bot identity. Invite the new bot to your channels and
- start a new DM with it. The old app stays installed in Slack until a workspace admin removes it. To
- switch back to the hosted app, remove this connection first, then choose Add to Slack.
+ Replacing a connected app changes the bot identity. Invite the new bot to your channels and start a
+ new DM with it. The old app stays installed until a workspace admin removes it.
+ <span id="slack-hosted-switch" class="hidden"
+ >To switch back to the QM app, disconnect here first, then choose Add to Slack.</span
+ >
</p>
<button type="button" id="slack-enter-tokens">I have both tokens</button>
+ <div class="hidden" id="slack-token-editor">
+ <label style="display: block; margin-bottom: 8px"
+ >Bot User OAuth Token
+ <input
+ type="password"
+ id="slack-bot-token"
+ autocomplete="off"
+ placeholder="xoxb-…"
+ style="width: 100%"
+ /></label>
+ <label style="display: block; margin-bottom: 8px"
+ >App-Level Token
+ <input
+ type="password"
+ id="slack-app-token"
+ autocomplete="off"
+ placeholder="xapp-…"
+ style="width: 100%"
+ /></label>
+ <p class="field-hint">
+ Use an app-level token with <code>connections:write</code>. Saving activates or reloads the Slack
+ surface within a few seconds.
+ </p>
+ <button class="primary hidden" id="slack-installation-save">Validate and connect</button>
+ </div>
</details>
- <div class="hidden" id="slack-token-editor">
- <label style="display: block; margin-bottom: 8px"
- >Bot User OAuth Token
- <input
- type="password"
- id="slack-bot-token"
- autocomplete="off"
- placeholder="xoxb-…"
- style="width: 100%"
- /></label>
- <label style="display: block; margin-bottom: 8px"
- >App-Level Token
- <input
- type="password"
- id="slack-app-token"
- autocomplete="off"
- placeholder="xapp-…"
- style="width: 100%"
- /></label>
- <p class="field-hint">
- Use an app-level token with <code>connections:write</code>. Saving activates or reloads the Slack
- surface within a few seconds.
- </p>
- </div>
- </div>
- <div class="foot">
- <button type="button" id="slack-rotate">Rotate tokens…</button
- ><button class="primary hidden" id="slack-installation-save">Validate and connect</button
- ><button class="danger" id="slack-installation-delete">Remove</button
- ><span class="status" id="st-slack-installation"></span>
+ <span class="status" role="status" id="st-slack-installation"></span>
</div>
</section>
</div>
@@ -10274,24 +10395,28 @@
r.data.configured && r.data.source === "admin"
? "Remove your current connection before switching to the hosted app."
: "";
- $("slack-rotate").textContent = r.data.configured ? "Replace connection…" : "Set up your own app…";
+ $("slack-installation-start").textContent = r.data.configured ? "Re-add to Slack" : "Add to Slack";
+ $("slack-installation-description").textContent = r.data.configured
+ ? r.data.source === "service"
+ ? "QM app"
+ : "Custom app"
+ : r.data.installAvailable
+ ? "Add the QM app or connect your own below."
+ : "Create a Slack app from our manifest, then connect it here.";
+ $("slack-own-app-label").textContent = r.data.installAvailable ? "Use your own Slack app" : "Set up Slack";
+ $("slack-hosted-switch").classList.toggle("hidden", !r.data.installAvailable);
+ if (!r.data.installAvailable && !r.data.configured) $("slack-own-app-guide").open = true;
if (new URLSearchParams(location.search).get("setup") === "slack") {
$("slack-own-app-guide").open = true;
$("card-slack-installation").scrollIntoView({ block: "start" });
}
if (r.data.createUrl) $("slack-installation-create").href = r.data.createUrl;
- $("slack-installation-state").textContent =
- r.data.source === "environment"
- ? "Connected using deployment environment secrets. Saving here replaces them with admin-managed encrypted tokens."
- : r.data.source === "invalid_environment"
- ? "The deployment contains only one Slack token. Save a matching pair here to repair it."
- : r.data.configured
- ? "Connected to " +
- (r.data.teamName || r.data.teamId || "a Slack workspace") +
- (r.data.updatedBy ? " · saved by " + r.data.updatedBy : "")
- : r.data.managed
- ? "Disabled by an administrator."
- : "Not configured.";
+ $("slack-installation-state").textContent = r.data.configured
+ ? r.data.teamName || r.data.teamId || "Slack workspace"
+ : r.data.source === "invalid_environment"
+ ? "Finish connecting your app"
+ : "Connect your workspace";
+ $("slack-installation-delete").classList.toggle("hidden", !r.data.configured);
$("slack-installation-delete").disabled = !r.data.configured;
}
$("slack-installation-start").onclick = async () => {
@@ -10332,10 +10457,6 @@
"ok",
);
};
- $("slack-rotate").onclick = () => {
- $("slack-own-app-guide").open = true;
- $("slack-own-app-guide").scrollIntoView({ behavior: "smooth", block: "start" });
- };
$("slack-enter-tokens").onclick = () => {
$("slack-token-editor").classList.remove("hidden");
$("slack-installation-save").classList.remove("hidden");
@@ -10343,14 +10464,19 @@
$("card-slack-installation").scrollIntoView({ behavior: "smooth", block: "start" });
};
$("slack-installation-delete").onclick = async () => {
- if (!confirm("Remove the Slack bot connection? Slack chat will stop until new tokens are saved.")) return;
+ if (
+ !confirm(
+ "Disconnect this Slack app? QM will stop replying in Slack until you reconnect. The app will remain installed in your workspace.",
+ )
+ )
+ return;
const r = await api("DELETE", "/api/slack-installation");
if (!r.ok) {
setStatus("st-slack-installation", r.data?.message || "Remove failed.", "err");
return;
}
await loadSlackInstallation();
- setStatus("st-slack-installation", "Removed", "ok");
+ setStatus("st-slack-installation", "Slack disconnected.", "ok");
};
$("conn-reset").onclick = resetConnForm;
async function deleteConn(provider) {
diff --git a/plugins/admin/test/default-view.test.ts b/plugins/admin/test/default-view.test.ts
index 1c7fc9c1b..5136bdbca 100644
--- a/plugins/admin/test/default-view.test.ts
+++ b/plugins/admin/test/default-view.test.ts
@@ -82,7 +82,7 @@ test("connector setup uses the live catalog and shows exact provider and callbac
assert.doesNotMatch(html, /const CONNECTOR_CATALOG = \[/);
assert.match(html, /id="slack-bot-token"/);
assert.match(html, /api\("PUT", "\/api\/slack-installation"/);
- assert.match(html, /encrypted in durable storage/);
+ assert.match(html, /Use your own Slack app/);
});
test("temporary onboarding covers model credentials, Slack, and OAuth setup", () => {
@@ -470,7 +470,7 @@ test("admin parity views expose the requested card groups and real navigation ac
"+ Add flag",
"View usage ›",
"View users ›",
- "Rotate tokens…",
+ "Use your own Slack app",
"+ Add OAuth app",
]) {
assert.ok(html.includes(action), `missing ${action}`);
diff --git a/plugins/admin/test/slack-installation-view.test.ts b/plugins/admin/test/slack-installation-view.test.ts
new file mode 100644
index 000000000..84a499fc3
--- /dev/null
+++ b/plugins/admin/test/slack-installation-view.test.ts
@@ -0,0 +1,60 @@
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import test from "node:test";
+import vm from "node:vm";
+
+const html = readFileSync(new URL("../public/index.html", import.meta.url), "utf8");
+async function render(data: Record<string, unknown>) {
+ const elements = new Map<string, any>();
+ const start = html.indexOf("async function loadSlackInstallation() {");
+ const end = html.indexOf('$("slack-installation-start").onclick', start);
+ await vm.runInNewContext(html.slice(start, end) + "loadSlackInstallation()", {
+ $: (id: string) => {
+ assert.ok(html.includes(`id="${id}"`), `missing ${id}`);
+ if (!elements.has(id)) {
+ const hidden = new Set<string>();
+ elements.set(id, {
+ open: false,
+ classList: {
+ toggle: (name: string, value: boolean) => (value ? hidden.add(name) : hidden.delete(name)),
+ contains: (name: string) => hidden.has(name),
+ },
+ });
+ }
+ return elements.get(id);
+ },
+ api: async () => ({ ok: true, data }),
+ URLSearchParams,
+ location: { search: "" },
+ });
+ return (id: string) => elements.get(id);
+}
+
+test("public QM leads with manifest setup and hides hosted actions and instructions", async () => {
+ const el = await render({
+ configured: false,
+ source: "none",
+ createUrl: "https://api.slack.com/apps?manifest_json=test",
+ });
+ assert.equal(el("slack-installation-start").classList.contains("hidden"), true);
+ assert.equal(el("slack-own-app-guide").open, true);
+ assert.equal(el("slack-own-app-label").textContent, "Set up Slack");
+ assert.equal(el("slack-hosted-switch").classList.contains("hidden"), true);
+ assert.match(el("slack-installation-description").textContent, /manifest/);
+ assert.match(el("slack-installation-create").href, /manifest_json/);
+});
+
+test("hosted connection offers re-add and keeps custom setup secondary", async () => {
+ const el = await render({ configured: true, source: "service", installAvailable: true, teamName: "Development YC" });
+ assert.equal(el("slack-installation-start").textContent, "Re-add to Slack");
+ assert.equal(el("slack-installation-start").disabled, false);
+ assert.equal(el("slack-installation-state").textContent, "Development YC");
+ assert.equal(el("slack-own-app-label").textContent, "Use your own Slack app");
+ assert.equal(el("slack-own-app-guide"), undefined);
+});
+
+test("custom connection cannot be replaced by hosted OAuth without disconnecting", async () => {
+ const el = await render({ configured: true, source: "admin", installAvailable: true });
+ assert.equal(el("slack-installation-start").disabled, true);
+ assert.equal(el("slack-installation-description").textContent, "Custom app");
+});