diff --git a/packages/junior/src/chat/task-input.ts b/packages/junior/src/chat/task-input.ts index a2029f836c..7f62644bb7 100644 --- a/packages/junior/src/chat/task-input.ts +++ b/packages/junior/src/chat/task-input.ts @@ -51,21 +51,22 @@ export interface EventDoneBy { /** * Connect the mention to the provider handle in the Event text. Without this, * the agent can mention a person and then name them again by handle as if - * they were someone else. + * they were someone else. The "you" rule also applies when the doer is not in + * People involved, because instructions can still ask the agent to mention + * them, such as a requester who reviews their own pull request. */ function doneByLine(doneBy: EventDoneBy, people: readonly string[]): string { const mention = oneLine(doneBy.mention); const handle = doneBy.handle ? oneLine(doneBy.handle) : undefined; + const asYou = `as "you"${handle ? `, and do not also call them "${handle}"` : ""}.`; return [ `Done by: ${mention}. This person did what this Event describes.`, ...(handle ? [`The Event calls them "${handle}". That is the same person.`] : []), - ...(people.includes(mention) - ? [ - `They are also in People involved. Write to them as "you"${handle ? `, and do not also call them "${handle}"` : ""}.`, - ] - : []), + people.includes(mention) + ? `They are also in People involved. Write to them ${asYou}` + : `If you mention them, write to them ${asYou}`, ].join(" "); } diff --git a/packages/junior/tests/unit/chat/task-input.test.ts b/packages/junior/tests/unit/chat/task-input.test.ts index fd26bcf6ea..75de027941 100644 --- a/packages/junior/tests/unit/chat/task-input.test.ts +++ b/packages/junior/tests/unit/chat/task-input.test.ts @@ -58,6 +58,17 @@ describe("renderTaskInput", () => { `); }); + it("links the doer's handle to their mention without People involved", () => { + const text = renderTaskInput({ + doneBy: { mention: "<@U456>", handle: "octocat" }, + instructions: "Tell the person who asked when a review arrives.", + }); + + expect(text).toContain( + 'Done by: <@U456>. This person did what this Event describes. The Event calls them "octocat". That is the same person. If you mention them, write to them as "you", and do not also call them "octocat".\n', + ); + }); + it("omits empty optional sections and clips bounded fields", () => { const text = renderTaskInput({ about: " label ",