Skip to content
2 changes: 2 additions & 0 deletions apps/server/src/kin/chat/clearedChatPrompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const memory = Layer.succeed(
ensureCheckouts: () => Effect.die("Unused"),
prepareWakeup: () => Effect.die("Unused"),
readIndex: () => Effect.die("Unused"),
rememberPublished: () => Effect.die("Unused"),
readRulesBook: () => Effect.die("Unused"),
readRules: () => Effect.die("Unused"),
query: () => Effect.succeed([]),
readItem: () => Effect.die("Unused"),
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/kin/featureMap/feature-map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ features:
proof:
- apps/server/src/kin/memory/Memory.test.ts
- apps/server/src/kin/memory/MemoryWriter.test.ts
- apps/server/src/kin/memory/MemoryChanges.test.ts

# ── Tasks ──────────────────────────────────────────────────────────────────────────────────
- id: tasks
Expand Down Expand Up @@ -1911,6 +1912,8 @@ features:
unlisted:
"phone:KinBillsAdd": Where a photo or PDF shared into Kin lands; it opens the chat bills are added in at once.
"web:team": Old address; opens the Settings modal on Team.
"rpc:kin.memory.readRules": Owner-only rulebook reader; editor client ships separately.
"rpc:kin.memory.saveRules": Owner-only rulebook editor; editor client ships separately.
"web:memory": Old address; opens the Settings modal on Memory.
"web:settings/approvals": The app's old address; opens Kin's Settings → Approvals.
"web:settings/company": The app's old address; opens Kin's Settings → Company details.
Expand Down
109 changes: 59 additions & 50 deletions apps/server/src/kin/hostBackup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,64 +373,73 @@ it.effect("a memory write the writer refuses every night tells the owner once pe
}).pipe(Effect.provide(daytimeServices)),
);

it.effect("background memory refusals open one silent notice in the owner's private chat", () =>
Effect.gen(function* () {
yield* seed;
const sql = yield* SqlClient.SqlClient;
const { writeEpisode } = yield* MemoryRecoveryHooks;
if (writeEpisode === undefined) return assert.fail("Missing memory notices");
yield* Effect.all(
[
writeEpisode(orgId, "deleted-quotes", "remote"),
writeEpisode(orgId, "deleted-quotes", "remote"),
],
{ concurrency: "unbounded", discard: true },
);
yield* writeEpisode(orgId, "deleted-quotes", "scanner");
yield* writeEpisode(orgId, "deleted-quotes", "remote");
const rows = sql<{ chatId: string; person: string; silent: number; open: number }>`SELECT
it.effect.each(["deleted-quotes", "online-copy"] as const)(
"background %s refusals open one silent notice in the owner's private chat",
(operation) =>
Effect.gen(function* () {
yield* seed;
const sql = yield* SqlClient.SqlClient;
const { writeEpisode } = yield* MemoryRecoveryHooks;
if (writeEpisode === undefined) return assert.fail("Missing memory notices");
const refusal = operation === "online-copy" ? "direct-push-refused" : "remote";
yield* Effect.all(
[writeEpisode(orgId, operation, refusal), writeEpisode(orgId, operation, refusal)],
{ concurrency: "unbounded", discard: true },
);
if (operation === "online-copy") {
const rows = yield* sql<{ body: string }>`SELECT body FROM kin_messages
WHERE org_id = ${orgId} AND message_id LIKE 'kin-memory-write:%'`;
assert.deepStrictEqual(rows, [
{
body: "Memory is saved here, but the repository refused to publish it; ask the host administrator to check write access and branch protection.",
},
]);
}
yield* writeEpisode(orgId, operation, "scanner");
yield* writeEpisode(orgId, operation, refusal);
const rows = sql<{ chatId: string; person: string; silent: number; open: number }>`SELECT
m.chat_id AS "chatId", w.person_id AS person, m.silent,
w.resolved_at IS NULL AS open
FROM kin_messages m JOIN kin_waiting w
ON w.org_id = m.org_id AND w.message_id = m.message_id
WHERE m.org_id = ${orgId} AND m.message_id LIKE 'kin-memory-write:%'
ORDER BY m.seq`;
assert.deepStrictEqual(yield* rows, [
{ chatId: "rhea-chief", person: "rhea", silent: 1, open: 1 },
{ chatId: "rhea-chief", person: "rhea", silent: 1, open: 1 },
]);
const chat = yield* Chat.KinChatService;
const [answered] = yield* sql<{ waitingId: string }>`SELECT waiting_id AS "waitingId"
FROM kin_waiting WHERE org_id = ${orgId} AND message_id LIKE 'kin-memory-write:%:remote:%'`;
if (answered === undefined) return assert.fail("Missing owner notice");
yield* chat.resolveNotice({
orgId,
waitingId: KinWaitingId.make(answered.waitingId),
resolution: "answered",
});
yield* writeEpisode(orgId, "deleted-quotes", "remote");
assert.deepStrictEqual(
(yield* rows).map(({ open }) => open),
[0, 1],
);
yield* writeEpisode(orgId, "deleted-quotes", undefined);
assert.deepStrictEqual(
(yield* rows).map(({ open }) => open),
[0, 0],
);
yield* writeEpisode(orgId, "deleted-quotes", "remote");
assert.deepStrictEqual(
(yield* rows).map(({ open }) => open),
[0, 0, 1],
);
}).pipe(
Effect.provide(
OwnerNotices.layer.pipe(
Layer.provideMerge(services),
withFixtureClock(DAY_START + 13 * HOUR),
assert.deepStrictEqual(yield* rows, [
{ chatId: "rhea-chief", person: "rhea", silent: 1, open: 1 },
{ chatId: "rhea-chief", person: "rhea", silent: 1, open: 1 },
]);
const chat = yield* Chat.KinChatService;
const [answered] = yield* sql<{ waitingId: string }>`SELECT waiting_id AS "waitingId"
FROM kin_waiting WHERE org_id = ${orgId} AND message_id LIKE ${`kin-memory-write:%:${refusal}:%`}`;
if (answered === undefined) return assert.fail("Missing owner notice");
yield* chat.resolveNotice({
orgId,
waitingId: KinWaitingId.make(answered.waitingId),
resolution: "answered",
});
yield* writeEpisode(orgId, operation, refusal);
assert.deepStrictEqual(
(yield* rows).map(({ open }) => open),
[0, 1],
);
yield* writeEpisode(orgId, operation, undefined);
assert.deepStrictEqual(
(yield* rows).map(({ open }) => open),
[0, 0],
);
yield* writeEpisode(orgId, operation, refusal);
assert.deepStrictEqual(
(yield* rows).map(({ open }) => open),
[0, 0, 1],
);
}).pipe(
Effect.provide(
OwnerNotices.layer.pipe(
Layer.provideMerge(services),
withFixtureClock(DAY_START + 13 * HOUR),
),
),
),
),
);

const decodeCard = Schema.decodeUnknownSync(Schema.fromJsonString(KinHostTroubleCard));
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/kin/lead/LeadPrompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4670,6 +4670,8 @@ const markedMemory = Layer.succeed(
ensureCheckouts: () => Effect.die("Unused"),
prepareWakeup: () => Effect.die("Unused"),
readIndex: () => Effect.die("Unused"),
rememberPublished: () => Effect.die("Unused"),
readRulesBook: () => Effect.die("Unused"),
readRules: () => Effect.die("Unused"),
query: () => Effect.succeed([]),
readItem: () => Effect.die("Unused"),
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/kin/lead/LeadPrompt.testkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ export const memory = Layer.succeed(
ensureCheckouts: () => Effect.die("Unused"),
prepareWakeup: () => Effect.die("Unused"),
readIndex: () => Effect.die("Unused"),
rememberPublished: () => Effect.die("Unused"),
readRulesBook: () => Effect.die("Unused"),
readRules: () => Effect.die("Unused"),
// A reminder asked for in fixture-room, which only some tests create.
query: () =>
Expand Down
15 changes: 13 additions & 2 deletions apps/server/src/kin/lead/LeadPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ export interface KinLeadPromptInput {
readonly wakeupId: KinWakeupId;
readonly events: ReadonlyArray<KinEvent>;
readonly memoryHead: string;
readonly rulesHead?: string;
readonly budgetContext?: string;
readonly observePrompt?: (fingerprint: PromptFingerprint) => void;
/** The chat the lead's plain text goes to; see the reply bridge. */
Expand Down Expand Up @@ -2011,7 +2012,12 @@ export class KinLeadPrompt extends Context.Service<
);
const snapshot = ownerOnly
? yield* Effect.gen(function* () {
const read = yield* memory.readPromptSnapshot(orgId, memoryHead, { lead: agentId });
const read = yield* memory.readPromptSnapshot(
orgId,
memoryHead,
{ lead: agentId },
input.rulesHead,
);
const hidden = yield* sharedOrigins(orgId, agentId);
return hidden.size === 0
? read
Expand All @@ -2037,7 +2043,12 @@ export class KinLeadPrompt extends Context.Service<
const teamIndex = ownerOnly
? ""
: yield* Effect.gen(function* () {
const read = yield* memory.readPromptSnapshot(orgId, memoryHead, { lead: agentId });
const read = yield* memory.readPromptSnapshot(
orgId,
memoryHead,
{ lead: agentId },
input.rulesHead,
);
const items = yield* reaching(
orgId,
audience,
Expand Down
5 changes: 4 additions & 1 deletion apps/server/src/kin/lead/OwnerNotices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export const layer = Layer.effect(
? undefined
: {
id: failure,
body: `${MEMORY_WRITE_OPERATION_WORDS[operation]} ${MEMORY_WRITE_FAILURE_WORDS[failure]}${link === undefined ? "" : ` ${link}`}`,
body:
failure === "direct-push-refused"
? MEMORY_WRITE_FAILURE_WORDS[failure]
: `${MEMORY_WRITE_OPERATION_WORDS[operation]} ${MEMORY_WRITE_FAILURE_WORDS[failure]}${link === undefined ? "" : ` ${link}`}`,
scope: "cause",
silentDuringQuietHours: true,
},
Expand Down
Loading
Loading