Skip to content

Commit 245e265

Browse files
joahgHertzclaude
committed
fix(agents): keep the owner-DM exception in Goose, Pi and harness-kit turns
Goose, Pi and the harness kit built the turn's channel with only `dm`, so in a DM with only the owner they still told the agent to start a Solo chat. Each now passes `ownerDm` the way the Claude Code runtime does. AGNTOPS-780 Co-authored-by: Hertz <c6741012416ef5c49a865db79682113385c5fb998e8c890234fb442b59e22748@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Joah Gerstenberg <[email protected]>
1 parent 46a493d commit 245e265

5 files changed

Lines changed: 51 additions & 8 deletions

File tree

‎src/bundled/goose/runtime.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
type StandaloneTurn,
3030
type TurnResult,
3131
} from "../../features/agents/service";
32-
import { ownerReads } from "../../features/agents/reads";
32+
import { ownerDm, ownerReads } from "../../features/agents/reads";
3333
import { soloChat } from "../../features/agents/solo-chat";
3434
import { SessionControls } from "../../features/agent-harness/session-control";
3535
import type {
@@ -781,6 +781,13 @@ export class GooseRuntime {
781781
id: channelId,
782782
...(summary?.name ? { name: summary.name } : {}),
783783
dm,
784+
...(ownerDm(
785+
{ dm, members: summary?.members ?? [] },
786+
agent.pubkey,
787+
owner,
788+
)
789+
? { ownerDm: true }
790+
: {}),
784791
},
785792
...(thread ? { thread } : {}),
786793
context: unseen,

‎src/bundled/pi/runtime.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { fromOwner, workflowOf } from "../../features/agents/owner-attestation";
3333
import { type AgentKey, pubkeyOf } from "../../features/agents/membership";
3434
import { sessionPrompts } from "../../features/agents/session-prompts";
3535
import { localStore, type AgentStore } from "../../features/agents/store";
36-
import type { AgentReads } from "../../features/agents/reads";
36+
import { ownerDm, type AgentReads } from "../../features/agents/reads";
3737
import type {
3838
Agent,
3939
AgentHandle,
@@ -1332,6 +1332,7 @@ export class PiRuntime {
13321332
id: channelId,
13331333
...(summary?.name ? { name: summary.name } : {}),
13341334
dm,
1335+
...(ownerDm(summary, agent.pubkey, owner) ? { ownerDm: true } : {}),
13351336
},
13361337
...(thread ? { thread } : {}),
13371338
context: unseen,

‎src/features/agent-harness/kit.test.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it, vi } from "vitest";
2-
import { RESUMED_PROMPT } from "../../buzz-mcp/prompt";
2+
import { DM_PROMPT, RESUMED_PROMPT } from "../../buzz-mcp/prompt";
33
import { fromOwner } from "../agents/owner-attestation";
44
import type { AgentHandle, Delivery } from "../agents/service";
55
import { eventDto, type EventData, type RelayEvent } from "../relay/events";
@@ -44,6 +44,7 @@ function setup(
4444
options: Readonly<{
4545
type?: "stream" | "dm" | "solo";
4646
name?: string;
47+
members?: readonly string[];
4748
thread?: readonly EventData[];
4849
core?: string | null;
4950
notes?: readonly string[];
@@ -70,7 +71,7 @@ function setup(
7071
id: channel,
7172
...(options.name === "" ? {} : { name: options.name ?? "general" }),
7273
channelType: options.type ?? "stream",
73-
members: [],
74+
members: options.members ?? [],
7475
},
7576
],
7677
}),
@@ -173,6 +174,20 @@ describe("harnessKit.conversation", () => {
173174
).toMatchObject({ key: channel, topLevel: true });
174175
});
175176

177+
it("answers in a DM with only its owner, and sends any other DM's answer to a Solo chat", async () => {
178+
const event = reply("2", "1", "go");
179+
const prompt = async (members: readonly string[]) => {
180+
const { kit, delivery } = setup({ type: "dm", name: "", members });
181+
const d = delivery({ type: "mention", event });
182+
const conversation = await kit.conversation(d, "thread");
183+
if (!conversation) throw new Error("not admitted");
184+
return (await kit.turnPrompt(d, conversation)).text;
185+
};
186+
expect(await prompt([self, alice])).not.toContain(DM_PROMPT);
187+
expect(await prompt([self, alice, mallory])).toContain(DM_PROMPT);
188+
expect(await prompt([])).toContain(DM_PROMPT);
189+
});
190+
176191
it("refuses a mention from anyone else, and triggers that are not its", async () => {
177192
const { kit, delivery } = setup();
178193
const event = message("2", "@Ampy rm -rf", { pubkey: mallory });

‎src/features/agent-harness/kit.ts‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
import type { McpHandler } from "../host/service";
2222
import type { AgentKey } from "../agents/membership";
2323
import { fromOwner } from "../agents/owner-attestation";
24-
import { ownerReads } from "../agents/reads";
24+
import { ownerDm, ownerReads } from "../agents/reads";
2525
import type {
2626
AgentHandle,
2727
ConversationWake,
@@ -129,6 +129,8 @@ type Admitted = Readonly<{
129129
event: EventData;
130130
solo: boolean;
131131
dm: boolean;
132+
/** A DM with only the agent's owner, which it answers in. */
133+
ownerDm: boolean;
132134
name?: string;
133135
wake?: ConversationWake;
134136
resumed: boolean;
@@ -264,6 +266,11 @@ export function harnessKit(sources: Sources): HarnessKit {
264266
event,
265267
solo,
266268
dm,
269+
ownerDm: ownerDm(
270+
{ dm, members: found?.members ?? [] },
271+
agent.pubkey,
272+
agent.owner,
273+
),
267274
...(found?.name ? { name: found.name } : {}),
268275
...(wake ? { wake } : {}),
269276
resumed: trigger.type === "mention" && !!trigger.resumed,
@@ -295,7 +302,15 @@ export function harnessKit(sources: Sources): HarnessKit {
295302
conversation,
296303
options = {},
297304
) {
298-
const { event, solo, dm, name, wake, resumed } = known(conversation);
305+
const {
306+
event,
307+
solo,
308+
dm,
309+
ownerDm: withOwner,
310+
name,
311+
wake,
312+
resumed,
313+
} = known(conversation);
299314
const { key, channel: channelId, topLevel } = conversation;
300315
const ready = session(agent.key);
301316
const thread = threadReference(event);
@@ -380,7 +395,12 @@ export function harnessKit(sources: Sources): HarnessKit {
380395
scope: key === channelId ? "channel" : "thread",
381396
topLevel,
382397
channelLevel: topLevel && !solo,
383-
channel: { id: channelId, ...(name ? { name } : {}), dm },
398+
channel: {
399+
id: channelId,
400+
...(name ? { name } : {}),
401+
dm,
402+
...(withOwner ? { ownerDm: true } : {}),
403+
},
384404
...(thread ? { thread } : {}),
385405
context: unseen,
386406
total: earlier.length + 1,

‎src/features/agents/reads.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type ChannelFacts = Readonly<{
3131
/** Whether `facts` is a DM only the agent and its owner are in, the one DM
3232
* an agent answers in. */
3333
export function ownerDm(
34-
facts: ChannelFacts | undefined,
34+
facts: Pick<ChannelFacts, "dm" | "members"> | undefined,
3535
agent: string,
3636
owner: string | undefined,
3737
) {

0 commit comments

Comments
 (0)