From abf7507ae732e6daf034a24ac223e3cad9bd50f6 Mon Sep 17 00:00:00 2001 From: GLDRoger <130458023+GLDRoger@users.noreply.github.com> Date: Sun, 29 Nov 2026 20:21:14 +0530 Subject: [PATCH] fix(kin): keep one-turn setup out of session standing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Send Chief of staff setup guidance with the turn that requested it. Its appearance or disappearance must not reset the owner's direct session. People-change: The Chief of staff keeps the owner’s conversation after the first setup message. Co-Authored-By: GPT-6.2 Sol --- apps/server/src/kin/lead/LeadPrompt.test.ts | 24 ++++++++++++++------- apps/server/src/kin/lead/LeadPrompt.ts | 4 ++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/apps/server/src/kin/lead/LeadPrompt.test.ts b/apps/server/src/kin/lead/LeadPrompt.test.ts index da94e593b2a9..dfd54b059aad 100644 --- a/apps/server/src/kin/lead/LeadPrompt.test.ts +++ b/apps/server/src/kin/lead/LeadPrompt.test.ts @@ -1645,6 +1645,7 @@ it.effect( WHERE chat_id = ${chatId}`; yield* sql`UPDATE kin_leads SET domain = 'chief-of-staff' WHERE agent_id = ${agentId}`; const prompt = yield* KinLeadPrompt; + const keys: PromptFingerprint[] = []; const say = Effect.fn("test.say")(function* (id: string, clientMessageId: string) { yield* repo.insertMessage({ audience: "chat", @@ -1677,8 +1678,9 @@ it.effect( provenance: { _tag: "human", personId, memberId }, }); yield* stored(`wake-${id}`, [said]); - return prompt.build({ + return prompt.buildSession({ ...input, + observePrompt: (fingerprint) => keys.push(fingerprint), wakeupId: KinWakeupId.make(`wake-${id}`), lane: { chatId, mode: "reply" }, events: [said], @@ -1687,7 +1689,14 @@ it.effect( const guidance = `${PROMPT_HEADINGS.setUp}\n\n${CHIEF_OF_STAFF_SET_UP}`; // The owner's first word to the company's first agent gets it. const hello = yield* say("hello", "c-1"); - expect(yield* hello).toContain(guidance); + const first = yield* hello; + expect(first.full).toContain(guidance); + const firstKey = keys.at(-1)?.standing; + const later = yield* yield* say("later", "c-2"); + expect(later.full).not.toContain(PROMPT_HEADINGS.setUp); + expect(later.full).not.toContain(CHIEF_OF_STAFF_SET_UP); + expect(keys.at(-1)?.standing).toBe(firstKey); + // Not where another agent came first: an older company's new Chief of staff. yield* repo.insertAgent({ orgId, @@ -1697,16 +1706,15 @@ it.effect( ownerPersonId: personId, createdAt: "1969-12-31T00:00:00.000Z", }); - expect(yield* hello).not.toContain(PROMPT_HEADINGS.setUp); + expect((yield* hello).full).not.toContain(PROMPT_HEADINGS.setUp); yield* sql`UPDATE kin_agents SET created_at = '2999-01-01T00:00:00.000Z' WHERE agent_id = 'older-lead'`; - // Nothing after the first word does, so a company that talks to it reads what it read. - const later = yield* yield* say("later", "c-2"); - expect(later).not.toContain(PROMPT_HEADINGS.setUp); - expect(later).not.toContain(CHIEF_OF_STAFF_SET_UP); // Set up… does, whenever it is sent; another seat never reads it. const pressed = yield* say("pressed", `${KIN_SET_UP_MESSAGE_PREFIX}c-3`); - expect(yield* pressed).toContain(guidance); + const pressedTurn = yield* pressed; + expect(pressedTurn.full).toContain(guidance); + expect(pressedTurn.message).toContain(guidance); + expect(keys.at(-1)?.standing).toBe(firstKey); yield* sql`UPDATE kin_leads SET domain = 'finance' WHERE agent_id = ${agentId}`; expect(yield* pressed).not.toContain(PROMPT_HEADINGS.setUp); }).pipe(Effect.provide(layer)), diff --git a/apps/server/src/kin/lead/LeadPrompt.ts b/apps/server/src/kin/lead/LeadPrompt.ts index 3d2a943a4c8f..27b34bb70af1 100644 --- a/apps/server/src/kin/lead/LeadPrompt.ts +++ b/apps/server/src/kin/lead/LeadPrompt.ts @@ -207,7 +207,7 @@ const promptSectionPlaces = { playbooks: "standing", thisCompany: "standing", whatWeSell: "standing", - setUp: "standing", + setUp: "message", checkIns: "checkIns", work: "work", started: "message", @@ -2982,7 +2982,7 @@ export class KinLeadPrompt extends Context.Service< : setUp ? [ ownerPart(promptSectionPlaces.setUp, PROMPT_HEADINGS.setUp), - ownerPart("standing", CHIEF_OF_STAFF_SET_UP), + ownerPart("message", CHIEF_OF_STAFF_SET_UP), ] : []), ...(checkIns.length === 0