Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Carry the Slack source onto sub-agent runs (#1676)

Joshua Francee41da30be234
diff --git a/src/sessions/session-syscalls.ts b/src/sessions/session-syscalls.ts
index 00291406e..e9e4b54a7 100644
--- a/src/sessions/session-syscalls.ts
+++ b/src/sessions/session-syscalls.ts
@@ -176,6 +176,8 @@ interface SessionSyscallBinding {
| "readOnly"
| "scopeVersion"
| "sessionParticipantIds"
+ | "slackSource"
+ | "externalSlack"
> & { origin?: OrchestratorInput["origin"] };
}
@@ -296,6 +298,8 @@ function childRunRequest(child: Session, meta: SpawnMeta, text: string, displayT
...(meta.scopeVersion ? { scopeVersion: meta.scopeVersion } : {}),
...(meta.sessionParticipantIds ? { sessionParticipantIds: meta.sessionParticipantIds } : {}),
surface: meta.surface,
+ ...(meta.slackSource ? { slackSource: meta.slackSource } : {}),
+ ...(meta.externalSlack ? { externalSlack: meta.externalSlack } : {}),
...(meta.deliveryTarget ? { deliveryTarget: meta.deliveryTarget } : {}),
...(meta.deliveryCandidates ? { deliveryCandidates: meta.deliveryCandidates } : {}),
actor: meta.actor,
@@ -593,6 +597,8 @@ export function createSessionSyscalls(deps: SessionSyscallDeps): SessionSyscalls
: {}),
...(caller.unattendedGrants ? { unattendedGrants: [...caller.unattendedGrants] } : {}),
openFingerprint: fingerprint,
+ ...(binding.request.slackSource ? { slackSource: binding.request.slackSource } : {}),
+ ...(binding.request.externalSlack ? { externalSlack: binding.request.externalSlack } : {}),
...(binding.request.scopeVersion ? { scopeVersion: binding.request.scopeVersion } : {}),
...(binding.request.sessionParticipantIds
? { sessionParticipantIds: binding.request.sessionParticipantIds }
diff --git a/src/types.ts b/src/types.ts
index 585b24db4..2879bb0c6 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -68,6 +68,8 @@ export interface Conversation {
export type SessionType = "dm" | "channel" | "group";
export interface SpawnMeta {
+ slackSource?: TurnRequest["slackSource"];
+ externalSlack?: TurnRequest["externalSlack"];
surfaceTools?: boolean;
deliveryCandidates?: TurnRequest["deliveryCandidates"];
origin?: TurnOrigin;
diff --git a/test/session-syscalls.test.ts b/test/session-syscalls.test.ts
index ce8106bb7..ef8b4fb44 100644
--- a/test/session-syscalls.test.ts
+++ b/test/session-syscalls.test.ts
@@ -1657,3 +1657,52 @@ for (const surface of ["slack", "web"] as const) {
});
}
}
+
+test("children of a Slack group turn keep its source so external-workspace policy admits them", async () => {
+ const { externalSlackRequestAllowed } = await import("../src/resolution/external-slack.ts");
+ const { externalSlackNamespace } = await import("../src/slack/external-access.ts");
+ const access = { companyDomains: ["partner.example"], serviceCredentials: ["search"] };
+ const policies = { ext: access };
+ const admitted = (request: OrchestratorInput) =>
+ externalSlackRequestAllowed({ ...request, surface: request.surface ?? "" }, policies);
+ const sessions = createMemorySessionStore();
+ const { runs } = createMemoryRunStore();
+ const factory = createSessionSyscalls({
+ mailbox: createSessionMailbox(createMemoryMap<SessionMessage>()),
+ sessions,
+ runs,
+ signals: createMemoryRunSignalStore(),
+ maxAttempts: 3,
+ });
+ const cases = [
+ {
+ threadRef: "slack:group:G1",
+ request: { slackSource: { accountId: "staff", teamId: "T1", userId: "U1" } },
+ },
+ {
+ threadRef: `${externalSlackNamespace("T2", access)}:C2`,
+ request: { externalSlack: { accountId: "ext", teamId: "T2", userId: "U1", ...access } },
+ },
+ ];
+ for (const c of cases) {
+ const group: Conversation = { kind: "group", threadRef: c.threadRef, channelRef: c.threadRef, audience: [actor] };
+ const room = await sessions.getOrCreateByThread(c.threadRef, "group", scope, undefined, "slack");
+ await sessions.addParticipant(room.id, actor.id);
+ const syscalls = factory.forTurn({
+ session: room,
+ scopeId: scope,
+ request: { surface: "slack", conversation: group, actor, ...c.request },
+ });
+ const opened = await syscalls.open({ task: "look into it" });
+ assert.ok(opened.ok);
+ const child = await freshSession(sessions, opened.sessionId);
+ const [run] = await runs.inFlightForThread(child.threadRef);
+ assert.ok(admitted(run!.request));
+ assert.deepEqual(run!.request.externalSlack, "externalSlack" in c.request ? c.request.externalSlack : undefined);
+ const followed = await syscalls.write({ target: child.id, text: "more", followup: true });
+ assert.ok(followed.ok, JSON.stringify(followed));
+ const latest = (await runs.inFlightForThread(child.threadRef)).at(-1)!;
+ assert.ok(admitted(latest.request));
+ assert.deepEqual(latest.request.externalSlack, run!.request.externalSlack);
+ }
+});