Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Post command approval cards in the requesting DM thread (#2110)

Joshua France09c074ce495f
diff --git a/src/core/approval-store.ts b/src/core/approval-store.ts
index ab2742092..22539b804 100644
--- a/src/core/approval-store.ts
+++ b/src/core/approval-store.ts
@@ -13,6 +13,12 @@ export function approvalDeliveryRecipient(actor: { externalId?: string } | undef
return id && !id.startsWith("system:") ? id : undefined;
}
+function dmThreadTs(request: NonNullable<PendingApprovalRecord["request"]>): string | undefined {
+ if (request.conversation?.kind !== "dm" || !request.deliveryTarget) return undefined;
+ const [channel, threadTs] = request.deliveryTarget.split(":");
+ return channel?.startsWith("D") && threadTs ? threadTs : undefined;
+}
+
export function createApprovalStore(
backing: DurableMap<PendingApprovalRecord>,
deliveries: Pick<DeliveryStore, "enqueue">,
@@ -21,10 +27,12 @@ export function createApprovalStore(
if (record.request?.surface !== "slack") return;
const actorId = approvalDeliveryRecipient(record.request.actor);
if (!actorId) return;
+ const threadTs = dmThreadTs(record.request);
await deliveries.enqueue({
destination: {
...principalDestination(actorId, actorId),
commandApprovalId: id,
+ ...(threadTs ? { threadTs } : {}),
...(record.request.slackSource
? { slackAccountId: record.request.slackSource.accountId, slackTeamId: record.request.slackSource.teamId }
: {}),
diff --git a/test/approval-store.test.ts b/test/approval-store.test.ts
index 46cf3b0d9..6f11df2e1 100644
--- a/test/approval-store.test.ts
+++ b/test/approval-store.test.ts
@@ -92,3 +92,22 @@ test("system approvals stay pending without enqueuing or reviving an impossible
assert.deepEqual(await deliveries.pending("principal"), []);
assert.equal((await deliveries.get(stale.id))?.expiredAt, expiredAt, "a sweep must not revive the stale DM");
});
+
+test("approvals requested from a Slack DM thread are delivered into that thread", async () => {
+ for (const threadRef of ["dm:D1:1700.1", "agent:main:subagent:child"]) {
+ const deliveries = createDeliveryStore();
+ const approvals = createApprovalStore(createMemoryMap<PendingApprovalRecord>(), deliveries);
+ const approval = record(threadRef);
+ approval.request!.deliveryTarget = "D1:1700.1";
+ await approvals.put("A1", approval);
+ const [delivery] = await deliveries.pending("principal");
+ assert.equal(delivery?.destination.threadTs, "1700.1");
+ }
+ const deliveries = createDeliveryStore();
+ const approvals = createApprovalStore(createMemoryMap<PendingApprovalRecord>(), deliveries);
+ const channel = record("channel:C1:1700.2");
+ channel.request!.conversation = { kind: "channel", threadRef: "channel:C1:1700.2" } as never;
+ channel.request!.deliveryTarget = "C1:1700.2";
+ await approvals.put("A2", channel);
+ assert.equal((await deliveries.pending("principal"))[0]?.destination.threadTs, undefined);
+});