Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
60eb310
refactor(kin): describe instruction placement without changing requests
GLDRoger Nov 28, 2026
065ae9a
feat(kin): cache the standing rules at the start of Claude conversations
GLDRoger Nov 28, 2026
2909157
merge: bring the latest train 16 into the instruction block branch
GLDRoger Nov 28, 2026
fe3de2f
merge: prove byte-neutral placement on the corrected train 16 base
GLDRoger Nov 28, 2026
a359f3d
merge: keep the proved corrected X in the candidate history
GLDRoger Nov 28, 2026
dca99c2
test(kin): pin the candidate requests on the corrected base
GLDRoger Nov 28, 2026
bce5acc
fix(kin): keep shared cache lifetime on the provider default
GLDRoger Nov 28, 2026
af61128
test(kin): the leading block holds every system section once
GLDRoger Nov 28, 2026
ecbdbeb
fix(kin): a /goal no longer uses up the session's instruction block
GLDRoger Nov 28, 2026
b43922b
fix(kin): a /clear gives the session its instruction block back
GLDRoger Nov 28, 2026
3b5dcea
Merge reviewed Kin shared instruction block
GLDRoger Nov 29, 2026
0fe5b8d
feat(kin): configure Claude instruction placement per host
GLDRoger Nov 29, 2026
23b651e
fix(kin): keep Claude system prompt recording on
GLDRoger Nov 29, 2026
af2f76c
fix(kin): cache every Claude conversation for one hour
GLDRoger Nov 29, 2026
0b695c3
fix(kin): send file-based expense creation through bills
GLDRoger Nov 29, 2026
38223b5
fix(evals): replay Claude compaction in portable user context
GLDRoger Nov 29, 2026
cf0da5d
test(kin): record the Claude cache smoke result
GLDRoger Nov 29, 2026
5e9cc54
fix(kin): keep file exposure out of wake recovery receipts
GLDRoger Nov 29, 2026
6e1a724
fix(kin): only a PDF or picture sends a typed expense to bills_add
GLDRoger Nov 29, 2026
a80bc7c
merge: Kin's standing instructions travel as a marked first block tha…
GLDRoger Nov 29, 2026
ce57e07
chore(kin): join this step onto kin as the checked train holds it
GLDRoger Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion apps/server/src/kin/lead/AgentSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { KinIdentity } from "../chat/KinIdentity.ts";
import { KinServer } from "../KinServer.ts";
import { approvalOf } from "../questions/approval.ts";
import { aborted, effectiveAudience, SESSION_REFUSAL, SHARED_THREAD_PREFIX } from "./Audience.ts";
import { markOutside, outsideRead } from "./OutsideContent.ts";
import { markFileRead, markOutside, outsideRead } from "./OutsideContent.ts";
import { KinAgentSessionPolicy } from "./sessionPolicy.ts";
import { listedOnSharedThread, SHARED_TOOLS } from "./SharedTools.ts";
import { BILLS_THREAD_PREFIX, BILLS_TOOLS } from "./billsOnly.ts";
Expand Down Expand Up @@ -358,6 +358,20 @@ export const sessionPolicyLayer = Layer.effect(
webSearch: Effect.fn("KinAgentSessionPolicy.webSearch")((threadId: ThreadId, host?: string) =>
webSearchRefusal(threadId, host).pipe(Effect.provideService(SqlClient.SqlClient, sql)),
),
fileRead: Effect.fn("KinAgentSessionPolicy.fileRead")(
function* (threadId: ThreadId) {
const { turn } = yield* governingTurn(threadId);
if (turn === undefined) return SESSION_REFUSAL.none;
yield* markFileRead(turn, "file");
return undefined;
},
Effect.provideService(SqlClient.SqlClient, sql),
Effect.catchCause((cause) =>
Effect.logWarning("Kin file-read check failed; refusing", { cause }).pipe(
Effect.as<string | undefined>(SESSION_REFUSAL.none),
),
),
),
delegated: Effect.fn("KinAgentSessionPolicy.delegated")((threadId: ThreadId) =>
delegatedFromLead(threadId).pipe(Effect.provideService(SqlClient.SqlClient, sql)),
),
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/kin/lead/LeadPrompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5058,7 +5058,7 @@ it.effect(
subject: { type: "reminder", itemId: "rem" },
lateByMs: 0,
});
const owners = kinInstructions("owner", "claudeAgent");
const owners = kinInstructions("owner", "claudeAgent").text;

// A reply, then two messages steered into the same session.
const asked = yield* turn([event("asked")], "reply");
Expand Down Expand Up @@ -5141,7 +5141,7 @@ it.effect(
leftAt: null,
mutedUntil: null,
});
const confined = kinInstructions("confined", "claudeAgent");
const confined = kinInstructions("confined", "claudeAgent").text;
expect(repeatedGuidance(confined, [(yield* turn([event("group")], "reply")).text])).toEqual(
[],
);
Expand Down
19 changes: 19 additions & 0 deletions apps/server/src/kin/lead/OutsideContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ export const REPO_READ_REFUSAL = (name: string | undefined) =>
? "This turn read a repo for this chat, so it can only answer here: do that. Anything else waits for the next message."
: `This turn read a repo for ${name}, so it can only answer ${name} here: do that. Anything else waits for ${name}'s next message.`;

const EXPENSE_FILE_REFUSAL = "This turn read a file or photo. Use bills_add to enter the expense.";

// A read is not visible work and must not suppress recovery of an interrupted wake.
const fileReadKey = (wakeupId: string) => `read-file:${wakeupId}`;

export const markFileRead = Effect.fn("KinOutsideContent.markFileRead")(function* (
turn: Pick<Turn, "orgId" | "wakeupId">,
kind: "file" | "photo",
) {
yield* stampEvent(turn.orgId, fileReadKey(turn.wakeupId), kind);
});

export const expenseFileRefusal = Effect.fn("KinOutsideContent.expenseFileRefusal")(function* (
turn: Pick<Turn, "orgId" | "wakeupId">,
) {
const read = yield* storedStamp(turn.orgId, fileReadKey(turn.wakeupId));
return read === undefined ? undefined : EXPENSE_FILE_REFUSAL;
});

const field = (args: unknown, name: string) =>
Predicate.hasProperty(args, name) ? args[name] : undefined;

Expand Down
28 changes: 21 additions & 7 deletions apps/server/src/kin/lead/WakeupRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ import {
withSessionChanges,
type KinLeadPromptInput,
} from "./LeadPrompt.ts";
import { billPhotoMode, KinTurnContent } from "./turn/content.ts";
import { billPhotoMode, KinTurnContent, shownAsPicture } from "./turn/content.ts";
import {
backgroundWake,
chooseLeadModel,
Expand Down Expand Up @@ -167,7 +167,7 @@ import { claude } from "./turn/providers/claude.ts";
import { KinWorkspace } from "../gendocs/workspace.ts";
import { KinBoot, carryFacts, decideCarry, ulid, type PromptFingerprint } from "./sessionCarry.ts";
import { closeQuietRunCards, postQuietRunCard } from "./quietRunCard.ts";
import { inheritSession, outsideRead } from "./OutsideContent.ts";
import { inheritSession, markFileRead, outsideRead } from "./OutsideContent.ts";
import { turnSensitive } from "../work/sensitiveReads.ts";

const isSteerRun = (wakeupId: KinWakeupId, run: { readonly userMessageId: string }) =>
Expand Down Expand Up @@ -1033,7 +1033,8 @@ const make = Effect.gen(function* () {
SELECT tool, COUNT(*) AS results, SUM(length(result)) AS chars
FROM results WHERE result IS NOT NULL
GROUP BY tool ORDER BY chars DESC, tool LIMIT 12`;
const driver = driverOf(yield* settings.getSettings, thread.modelSelection);
const hostSettings = yield* settings.getSettings;
const driver = driverOf(hostSettings, thread.modelSelection);
const [lead] = yield* sql<{ domain: string }>`SELECT domain FROM kin_leads
WHERE org_id = ${row.orgId} AND agent_id = ${row.agentId} ORDER BY agent_id`;
yield* Effect.logInfo("Kin wake-up context.", {
Expand Down Expand Up @@ -1062,7 +1063,9 @@ const make = Effect.gen(function* () {
driver === undefined
? null
: NodeCrypto.createHash("sha256")
.update(leadThreadInstructions(threadId, driver))
.update(
leadThreadInstructions(threadId, driver, hostSettings.kinInstructionPlacement),
)
.digest("hex"),
providerTurns: providerTurns.length,
contextTokens,
Expand Down Expand Up @@ -1193,7 +1196,7 @@ const make = Effect.gen(function* () {
const first = !steering.framed;
steering.framed = true;
const deliver = Effect.gen(function* () {
const { text, attachments } = yield* turnContent.prepare({
const { text, attachments, fileShown } = yield* turnContent.prepare({
text: yield* prompt.steer({
orgId,
agentId,
Expand All @@ -1210,6 +1213,8 @@ const make = Effect.gen(function* () {
});
yield* holdFloor();
if (yield* wasStopped(row)) return;
if (fileShown) yield* markFileRead(row, "file").pipe(provideSql);
if (attachments.some(shownAsPicture)) yield* markFileRead(row, "photo").pipe(provideSql);
if (Option.isSome(bridge))
yield* bridge.value.steered(orgId, wakeupId, {
n,
Expand Down Expand Up @@ -2387,7 +2392,13 @@ const make = Effect.gen(function* () {
driver === undefined
? null
: NodeCrypto.createHash("sha256")
.update(leadThreadInstructions(threadId, driver))
.update(
leadThreadInstructions(
threadId,
driver,
hostSettings.kinInstructionPlacement,
),
)
.digest("hex"),
bootId,
toolListSha,
Expand Down Expand Up @@ -2525,14 +2536,17 @@ const make = Effect.gen(function* () {
);
if (ownerClaude && built !== undefined && (taken === undefined || !send.freshContext))
snapshot = { sections: built.sections, index: built.index };
const { text, attachments } =
const { text, attachments, fileShown } =
legacyContent ??
(yield* turnContent.prepare({
text: send.text,
attachments: files,
billPhotos,
offersBillsAdd: canAddBills,
}));
if (fileShown) yield* markFileRead(row, "file").pipe(provideSql);
if (attachments.some(shownAsPicture))
yield* markFileRead(row, "photo").pipe(provideSql);
// A finished task's run may already be this wake-up's (above).
if (registry.lookup(threadId)?.wakeupId !== wakeupId)
yield* registry.register(threadId, {
Expand Down
Loading
Loading