Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Classify sidebar sessions by their stored surface and hide automation runs (#2340)

Regan Bell1d370c408372
diff --git a/plugins/web-ui/src/chat.ts b/plugins/web-ui/src/chat.ts
index 59955b916..03942627e 100644
--- a/plugins/web-ui/src/chat.ts
+++ b/plugins/web-ui/src/chat.ts
@@ -173,7 +173,6 @@ import {
renderList,
sessionsState,
sessionSlackUrl,
- surfaceOf,
openSession,
syncWorkingPulse,
} from "./sessions";
@@ -185,6 +184,7 @@ import {
isAbandonedNewChat,
shouldStartProactiveOpener,
markWorking,
+ surfaceOf,
watchActivityLabel,
} from "./session-list";
import { liveTurnThreadRef } from "./working-dot";
diff --git a/plugins/web-ui/src/contexts.ts b/plugins/web-ui/src/contexts.ts
index 2cc173e36..8a03cd435 100644
--- a/plugins/web-ui/src/contexts.ts
+++ b/plugins/web-ui/src/contexts.ts
@@ -30,8 +30,8 @@ import { actionSnippet, fieldSelect, formatBytes, initials, menuSelect, relTime
import { icon } from "./icons";
import { appState, replacePanePreservingFocus, switchView, syncUrlFromState } from "./shell";
import { startNewChat } from "./sessions";
-import { groupDmTitle, openSession, refreshSessions, sessionsState, slackLogo, surfaceOf } from "./sessions";
-import { activityOf } from "./session-list";
+import { groupDmTitle, openSession, refreshSessions, sessionsState, slackLogo } from "./sessions";
+import { activityOf, sidebarSessions, surfaceOf } from "./session-list";
import type { WebhookView } from "./webhooks";
import type { CronView } from "./crons";
import { cronRunSummary, cronRunSummaryTitle, cronScheduleSummary } from "./cron-format";
@@ -286,7 +286,7 @@ export function scopeFilterControl(current: string | null, onSelect: (scopeId: s
}
function sessionsIn(scopeId: string): CoreSession[] {
- return sessionsState.list
+ return sidebarSessions(sessionsState.list)
.filter((s) => s.scopeId === scopeId && !s.archived)
.sort((a, b) => activityOf(b) - activityOf(a));
}
diff --git a/plugins/web-ui/src/core-bridge.ts b/plugins/web-ui/src/core-bridge.ts
index 1a81c1d17..bb3581c1e 100644
--- a/plugins/web-ui/src/core-bridge.ts
+++ b/plugins/web-ui/src/core-bridge.ts
@@ -263,7 +263,7 @@ export interface CoreProject {
export function slackThreadUrl(workspaceUrl: string | null, threadRef: string): string | null {
if (!workspaceUrl) return null;
- const m = threadRef.match(/^(?:dm|ch):([A-Z0-9]+)(?::(\d+)\.(\d+))?$/i);
+ const m = threadRef.match(/^(?:dm|ch|grp):([A-Z0-9]+)(?::(\d+)\.(\d+))?$/i);
if (!m) return null;
return `${workspaceUrl}/archives/${m[1]}${m[2] ? `/p${m[2]}${m[3]}` : ""}`;
}
diff --git a/plugins/web-ui/src/session-list.ts b/plugins/web-ui/src/session-list.ts
index 839f02e77..09f452d47 100644
--- a/plugins/web-ui/src/session-list.ts
+++ b/plugins/web-ui/src/session-list.ts
@@ -29,8 +29,22 @@ export function activityOf(s: CoreSession): number {
export type ChatBrowseStatus = "active" | "waiting" | "archived";
+export function surfaceOf(s: Pick<CoreSession, "surface">): "web" | "slack" | "core" {
+ return s.surface === "web" || s.surface === "slack" ? s.surface : "core";
+}
+
+const AUTOMATION_RUN_LABELS: Record<string, string> = {
+ cron: "Cron run",
+ webhook: "Webhook run",
+ loop: "Loop run",
+};
+
+export function automationRunLabel(s: Pick<CoreSession, "surface">): string | null {
+ return (s.surface && AUTOMATION_RUN_LABELS[s.surface]) || null;
+}
+
export function sidebarSessions(sessions: readonly CoreSession[]): CoreSession[] {
- return sessions.filter((session) => !session.parentSessionId);
+ return sessions.filter((session) => !session.parentSessionId && !automationRunLabel(session));
}
export function splitPinned<T extends Pick<CoreSession, "pinned">>(sessions: readonly T[]): { pinned: T[]; rest: T[] } {
@@ -264,7 +278,7 @@ export function shouldStartProactiveOpener(state: {
scopeId: string | null;
messageCount: number;
loaded: boolean;
- sessions: readonly Pick<CoreSession, "id" | "threadRef">[];
+ sessions: readonly Pick<CoreSession, "id" | "surface">[];
}): boolean {
return (
!state.started &&
@@ -272,7 +286,7 @@ export function shouldStartProactiveOpener(state: {
state.scopeId === null &&
state.messageCount === 0 &&
state.loaded &&
- !state.sessions.some((session) => session.id && !session.threadRef.startsWith("cron:"))
+ !state.sessions.some((session) => session.id && !automationRunLabel(session))
);
}
diff --git a/plugins/web-ui/src/sessions.ts b/plugins/web-ui/src/sessions.ts
index 07246d60c..0c47ccb3f 100644
--- a/plugins/web-ui/src/sessions.ts
+++ b/plugins/web-ui/src/sessions.ts
@@ -55,6 +55,7 @@ import {
import { deepLinkPath, isPlainLeftClick, sessionLink, UI_BASE } from "./deep-link";
import {
activityOf,
+ automationRunLabel,
chatBrowseStatusMatches,
bumpActivity,
sidebarSessions,
@@ -63,6 +64,7 @@ import {
recentProjectSeeds,
reconcileSessions,
rowIndicators,
+ surfaceOf,
splitPinned,
withPendingSession,
withoutUnsentPending,
@@ -250,13 +252,6 @@ function listWhen(ms: number): string {
return new Date(ms).toLocaleDateString([], { month: "short", day: "numeric" });
}
-export function surfaceOf(s: CoreSession): string {
- if (s.threadRef.startsWith("web:")) return "web";
- if (s.threadRef.startsWith("dm:") || s.threadRef.startsWith("ch:")) return "slack";
- if (s.threadRef.startsWith("agent:main:subagent:") && s.surface) return s.surface;
- return "core";
-}
-
export function sessionSlackUrl(s: Pick<CoreSession, "threadRef">): string | null {
return slackThreadUrl(appState.me?.slackWorkspaceUrl ?? null, s.threadRef);
}
@@ -274,13 +269,15 @@ function projectMenuKey(scopeId: string): string {
}
export function defaultSessionTitle(s: CoreSession): string {
+ const automation = automationRunLabel(s);
+ if (automation) return automation;
const project = projectName(s.scopeId);
if (project) return project;
const surface = surfaceOf(s);
if (surface === "web") return "Web chat";
if (s.type === "channel") return channelLabel(s) ?? "Channel";
if (s.type === "group") return groupDmText(s.channelName) ?? s.channelName?.trim() ?? "Group DM";
- return "Direct message";
+ return surface === "slack" ? "Direct message" : "Untitled chat";
}
function channelLabel(s: CoreSession): string | null {
@@ -1333,7 +1330,7 @@ export function setWebOnly(webOnly: boolean): void {
}
export function revealSessionSurface(s: CoreSession): void {
- if (!sessionsState.webOnly || surfaceOf(s) === "web") return;
+ if (!sessionsState.webOnly || surfaceOf(s) === "web" || automationRunLabel(s)) return;
setWebOnly(false);
}
diff --git a/plugins/web-ui/test/document-title.test.ts b/plugins/web-ui/test/document-title.test.ts
index 5daff7cec..b7ac48480 100644
--- a/plugins/web-ui/test/document-title.test.ts
+++ b/plugins/web-ui/test/document-title.test.ts
@@ -78,8 +78,20 @@ test("document title follows session switches, split-pane focus, and sign-out",
const { mainConversation } = await vite.ssrLoadModule("/src/conversations.ts");
const { openSession, refreshSessions, sessionsState } = await vite.ssrLoadModule("/src/sessions.ts");
const { mountRestoredCanvas, beginSessionDrag } = await vite.ssrLoadModule("/src/split.ts");
- const oldSession = { id: "old", threadRef: "web:old", scopeId: "personal:tester", title: "Old title" };
- const newSession = { id: "new", threadRef: "web:new", scopeId: "personal:tester", title: "New title" };
+ const oldSession = {
+ id: "old",
+ threadRef: "web:old",
+ scopeId: "personal:tester",
+ surface: "web",
+ title: "Old title",
+ };
+ const newSession = {
+ id: "new",
+ threadRef: "web:new",
+ scopeId: "personal:tester",
+ surface: "web",
+ title: "New title",
+ };
sessionsState.list = [oldSession, newSession];
appState.me = { user: "tester", org: "test" };
appState.currentView = "chats";
diff --git a/plugins/web-ui/test/session-list.test.ts b/plugins/web-ui/test/session-list.test.ts
index b480bf78b..3c42fb081 100644
--- a/plugins/web-ui/test/session-list.test.ts
+++ b/plugins/web-ui/test/session-list.test.ts
@@ -1,6 +1,8 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import {
+ automationRunLabel,
+ surfaceOf,
activityOf,
cronRowMeta,
sidebarSessions,
@@ -545,7 +547,13 @@ test("first personal chat opens proactively even when background suggestions alr
sessions: [],
};
assert.equal(shouldStartProactiveOpener(first), true);
- assert.equal(shouldStartProactiveOpener({ ...first, sessions: [saved("refresh", "cron:refresh:fire:1")] }), true);
+ assert.equal(
+ shouldStartProactiveOpener({
+ ...first,
+ sessions: [{ ...saved("refresh", "cron:refresh:fire:1"), surface: "cron" }],
+ }),
+ true,
+ );
assert.equal(shouldStartProactiveOpener({ ...first, sessions: [pending("web:alice:draft")] }), true);
for (const threadRef of ["web:alice:previous", "dm:D123:123.456", "ch:C123:123.456"]) {
assert.equal(shouldStartProactiveOpener({ ...first, sessions: [saved("previous", threadRef)] }), false);
@@ -566,6 +574,23 @@ test("sidebar excludes attached subagents including pinned and orphaned children
assert.deepEqual(sidebarSessions([parent, child, pinned, orphan, detached]), [parent, detached]);
});
+test("surfaceOf shows only stored web and Slack surfaces as themselves", () => {
+ assert.deepEqual([{ surface: "slack" }, { surface: "web" }, { surface: "swarm" }, {}].map(surfaceOf), [
+ "slack",
+ "web",
+ "core",
+ "core",
+ ]);
+});
+
+test("sidebar excludes cron, webhook, and loop runs but keeps conversations", () => {
+ const web = { ...saved("web", "web:alice:one"), surface: "web" };
+ const slack = { ...saved("slack", "grp:C1:1700000000.000100"), surface: "slack" };
+ const runs = ["cron", "webhook", "loop"].map((surface) => ({ ...saved(surface, `${surface}:x`), surface }));
+ assert.deepEqual(sidebarSessions([web, slack, ...runs]), [web, slack]);
+ assert.deepEqual([...runs, slack].map(automationRunLabel), ["Cron run", "Webhook run", "Loop run", null]);
+});
+
test("cronRowMeta shows the next fire and the last result of a session's cron", () => {
const now = Date.now();
assert.equal(cronRowMeta({ id: "c", nextFireAt: now + 10 * 60_000 + 1_000 }), "next fire in 10m");
diff --git a/plugins/web-ui/test/sidebar-surface-default.test.ts b/plugins/web-ui/test/sidebar-surface-default.test.ts
index 1528070c5..cefaeec23 100644
--- a/plugins/web-ui/test/sidebar-surface-default.test.ts
+++ b/plugins/web-ui/test/sidebar-surface-default.test.ts
@@ -9,6 +9,7 @@ for (const stored of [null, "1", "0", "unavailable"] as const) {
id: "web",
threadRef: "web:tester:one",
scopeId: "personal:tester",
+ surface: "web",
title: "Web chat",
canContinue: true,
createdAt: 3,
@@ -17,9 +18,32 @@ for (const stored of [null, "1", "0", "unavailable"] as const) {
id: "slack",
threadRef: "ch:C_TEAM:1700000000.000100",
scopeId: "channel:C_TEAM",
+ surface: "slack",
title: "Team chat",
createdAt: 2,
},
+ {
+ id: "group",
+ threadRef: "grp:C_PRIVATE:1700000000.000200",
+ scopeId: "channel:C_PRIVATE",
+ surface: "slack",
+ title: "Private channel thread",
+ createdAt: 1.5,
+ },
+ {
+ id: "cron-run",
+ threadRef: "cron:c1:fire:abc",
+ scopeId: "personal:tester",
+ surface: "cron",
+ createdAt: 5,
+ },
+ {
+ id: "webhook-run",
+ threadRef: "agent:main:webhook:w1",
+ scopeId: "personal:tester",
+ surface: "webhook",
+ createdAt: 4,
+ },
{ id: "child", threadRef: "web:tester:child", scopeId: "personal:tester", parentSessionId: "web", createdAt: 1 },
{
id: "archived",
@@ -52,17 +76,21 @@ for (const stored of [null, "1", "0", "unavailable"] as const) {
const rowIds = () =>
[...document.querySelectorAll<HTMLElement>("#sidebar-body .session-row")].map((row) => row.dataset.sessionId);
const slackRow = () => document.querySelector('[data-session-id="slack"]');
- assert.deepEqual(rowIds(), stored === "1" ? ["web"] : ["web", "slack"]);
+ const groupRow = () => document.querySelector('[data-session-id="group"]');
+ assert.deepEqual(rowIds(), stored === "1" ? ["web"] : ["web", "slack", "group"]);
if (stored !== "1") {
assert.ok(slackRow()?.querySelector(".slack-logo"));
+ assert.ok(groupRow()?.querySelector(".slack-logo"));
assert.match(slackRow()?.querySelector(".session")?.getAttribute("aria-label") ?? "", /slack/);
}
assert.equal(document.querySelector('[data-view="inbox"]'), null);
assert.equal(document.querySelector('[data-view="calendar"]'), null);
sidebar.setWebOnly(true);
assert.deepEqual(rowIds(), ["web"]);
+ sidebar.revealSessionSurface(sessions.find((s) => s.id === "cron-run"));
+ assert.equal(sidebar.sessionsState.webOnly, true);
sidebar.setWebOnly(false);
- assert.deepEqual(rowIds(), ["web", "slack"]);
+ assert.deepEqual(rowIds(), ["web", "slack", "group"]);
assert.ok(slackRow()?.querySelector(".slack-logo"));
assert.equal(slackRow()?.querySelector(".ro-lock"), null);
assert.match(slackRow()?.querySelector(".session")?.getAttribute("aria-label") ?? "", /read-only/);
diff --git a/src/api/app-messaging.ts b/src/api/app-messaging.ts
index f8f278cad..9b5d449e5 100644
--- a/src/api/app-messaging.ts
+++ b/src/api/app-messaging.ts
@@ -540,7 +540,13 @@ export function createMessagingMethods(
if (!delivery || delivery.destination.type !== "principal") return;
const recipientId = delivery.destination.target;
const recipientScope = scopeId("personal", recipientId);
- const session = await deps.sessions.getOrCreateByThread(recipientThreadRef, "dm", recipientScope);
+ const session = await deps.sessions.getOrCreateByThread(
+ recipientThreadRef,
+ "dm",
+ recipientScope,
+ undefined,
+ "slack",
+ );
await deps.deliveries.recordRecipientThread(delivery.id, recipientThreadRef, Date.now());
await deps.sessions.addParticipant(session.id, recipientId);
},
diff --git a/src/api/app-sessions.ts b/src/api/app-sessions.ts
index 0544a153d..2e0189572 100644
--- a/src/api/app-sessions.ts
+++ b/src/api/app-sessions.ts
@@ -937,7 +937,7 @@ export function createSessionMethods(
source.type,
source.scopeId,
source.channelName,
- source.surface ?? "web",
+ "web",
);
await Promise.all(
(projectMembers ?? [principalId]).map((memberId) => deps.sessions.addParticipant(forked.id, memberId)),
diff --git a/test/dm-relay.test.ts b/test/dm-relay.test.ts
index f62390ba7..80599b766 100644
--- a/test/dm-relay.test.ts
+++ b/test/dm-relay.test.ts
@@ -426,6 +426,7 @@ describe("agent → teammate DM: delivery events in the recipient's session (ant
const session = await sessions.getByThread("dm:D-alice");
assert.ok(session, "recipient DM session created");
+ assert.equal(session!.surface, "slack");
const entries = await sessions.getEntries(session!.id);
assert.equal(
entries.some((e) => e.type === "assistant"),
diff --git a/test/session-fork.test.ts b/test/session-fork.test.ts
index 107f92209..a5539c091 100644
--- a/test/session-fork.test.ts
+++ b/test/session-fork.test.ts
@@ -30,6 +30,7 @@ test("forking copies the transcript into a fresh independent web session", async
assert.ok(fork, "participant can fork");
assert.notEqual(fork.session.id, sid);
assert.ok(fork.session.threadRef.startsWith("web:U1:"), "fork lives on a fresh web thread");
+ assert.equal(fork.session.surface, "web");
assert.notEqual(fork.session.threadRef, source.session.threadRef);
assert.equal(fork.session.scopeId, source.session.scopeId);
const stored = await Promise.all(