diff --git a/backend/__tests__/unit/routes/registry.install-hosted-greeting.test.js b/backend/__tests__/unit/routes/registry.install-hosted-greeting.test.js index f01403094..0012693da 100644 --- a/backend/__tests__/unit/routes/registry.install-hosted-greeting.test.js +++ b/backend/__tests__/unit/routes/registry.install-hosted-greeting.test.js @@ -178,4 +178,17 @@ describe('registry install — a hosted agent joins with one post', () => { expect(introPosts()).toHaveLength(1); expect(introPosts()[0][0].authorKind).toBe('kernel'); }); + + it('in a personal room, the greeting gets no handle, since plain replies are auto-routed there', async () => { + Pod.findById.mockImplementation(() => { + const doc = { _id: 'pod-1', createdBy: 'user-1', members: ['user-1', 'bot-1'], type: 'agent-room' }; + return { ...buildLeanChain(doc), select: () => buildLeanChain(doc) }; + }); + const res = makeRes(); + await installHandler(makeReq('hosted'), res); + + expect(res.json).toHaveBeenCalledWith(expect.objectContaining({ success: true })); + expect(mockFireFirstContact).toHaveBeenCalledWith(expect.not.objectContaining({ mentionHandle: expect.anything() })); + expect(mockFireFirstContact).toHaveBeenCalledWith(expect.objectContaining({ hostedAgentUserId: 'bot-1' })); + }); }); diff --git a/backend/routes/registry/install.ts b/backend/routes/registry/install.ts index 5c179cbb2..1dbf3f6eb 100644 --- a/backend/routes/registry/install.ts +++ b/backend/routes/registry/install.ts @@ -31,6 +31,7 @@ const HostedRuntime = require('../../services/hostedRuntimeService'); const HostedEngine = require('../../services/hostedEngine'); const { reservedAgentNameRefusal } = require('../../services/agentNameReservation'); const { normalizeAvatarUrl } = require('../../services/avatarService'); +const { isPersonalPodType } = require('../../services/podTypePolicyService'); const { getUserId, resolveUsername, @@ -871,7 +872,10 @@ installRouter.post('/install', logAgentInstallRefusal('/api/registry/install'), podId, installedByUserId: userId, installerIsAgent: installerUser?.isBot === true, - ...(greetsItself ? { mentionHandle: handle } : {}), + // A personal pod (agent-room, agent-dm, agent-admin) auto-routes every + // plain reply to the agent, so the greeting must not tell the person to + // @mention it there. Only a team pod needs the handle. + ...(greetsItself && !isPersonalPodType(pod?.type) ? { mentionHandle: handle } : {}), ...(greetsItself ? { hostedAgentUserId: String(agentUser._id) } : {}), }); } catch (firstContactError: unknown) {