Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions .agents/skills/verify-kin/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ A run takes about 15 minutes; `--runs <n>` sets samples per action (default 5),
re-seeding, and `--only prompts` captures just the prompts and tool lists (about 4 minutes). A tool
listed as deferred (`_meta` anthropic/alwaysLoad false) counts apart from the upfront ones. `--compare <old.json> [--threshold 15]` adds old, new and change per metric and flags
what got worse. `--render <run.json> --findings <findings.json>` redraws the page with a written
"what stands out" list (`[{title, number, cause, where, worth}]`). It never calls a model; worker
reports are not measured, since workers here need a real repository.
"what stands out" list (`[{title, number, cause, where, worth}]`). It never calls a model.

## Phone

Expand Down
10 changes: 9 additions & 1 deletion apps/mobile/src/features/chats/KinSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { selectKinInboxView } from "@t3tools/client-runtime/kin/kinInboxModel";
import {
KIN_DAILY_LIMIT,
kinDailyLimitChoices,
kinDailyLimitUsed,
kinDailyLimitWaiting,
} from "@t3tools/client-runtime/kin/kinBudget";
import {
Expand Down Expand Up @@ -370,9 +371,16 @@ function KinDailyLimitSection(props: {
const { choices, current } = kinDailyLimitChoices(budget);
const label = choices.find((choice) => choice.value === current)?.label ?? "…";
const waiting = kinDailyLimitWaiting(budget);
const used = kinDailyLimitUsed(budget);
return (
<>
<SettingsSection footer={KIN_DAILY_LIMIT.detail}>
<SettingsSection
footer={
used === null
? KIN_DAILY_LIMIT.detail
: `${KIN_DAILY_LIMIT.used}: ${used}. ${KIN_DAILY_LIMIT.detail}`
}
>
<Menu
actions={choices.map((choice) => ({
id: choice.value,
Expand Down
6 changes: 0 additions & 6 deletions apps/server/src/kin/approvals/ActionExecutor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1779,12 +1779,6 @@ describe("KinActionExecutor", () => {
"const run = new Function(",
],
],
// A worker's browser resolves Playwright from Kin's install; its brief only quotes the line.
[
"kin/lead/workerBrowser.ts",
["const requireHere = NodeModule.createRequire(import.meta.url);"],
],
["kin/lead/workerBrief.ts", ["*- Playwright (playwright-core, no test runner):"]],
// Scripts run with `node -e` on a device host.
...[
"device/sshDeviceScript.ts",
Expand Down
10 changes: 5 additions & 5 deletions apps/server/src/kin/approvals/RequestAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type PullRequestFacts = Extract<KinResolvedTarget, { readonly _tag: "pull_reques

/**
* What the server reads from GitHub itself; the agent only names the PR. `target` comes back
* with the worker project's spelling of the repository, so one PR keys one action.
* with the project's spelling of the repository, so one PR keys one action.
*/
export class KinPullRequestFacts extends Context.Service<
KinPullRequestFacts,
Expand Down Expand Up @@ -91,16 +91,16 @@ export const layerPullRequestFacts = Layer.effect(
// One refusal for "not this lead's repo" and "no such PR", so private repos can't be probed.
const notFound = new KinApprovalError({
reason: "not_found",
message: "No such pull request in this agent's worker projects.",
message: "No such pull request in this agent's projects.",
});
// Public GitHub reads through any project, so the lead's worker projects are the allowlist.
// Public GitHub reads through any project, so the lead's projects are the allowlist.
const project = Effect.fn("KinPullRequestFacts.project")(function* (
target: PullRequestTarget,
projectIds: ReadonlyArray<ProjectId>,
) {
const shells = yield* projects
.listShells({ projectIds })
.pipe(Effect.mapError(() => unavailable("This agent's worker projects can't be read.")));
.pipe(Effect.mapError(() => unavailable("This agent's projects can't be read.")));
const match = shells
.filter((shell) => projectIds.includes(shell.id))
.map((shell) => ({
Expand Down Expand Up @@ -396,7 +396,7 @@ const make = Effect.gen(function* () {
if (current.lead.worker_projects_json !== lead.worker_projects_json)
return yield* refuse(
"invalid_state",
"This agent's worker projects changed while GitHub answered. Try again.",
"This agent's projects changed while GitHub answered. Try again.",
);
if (!KinLevels.atLeast(level, PRIVILEGED_LEVEL))
return yield* refuse("invalid_state", NOT_OPEN);
Expand Down
149 changes: 16 additions & 133 deletions apps/server/src/kin/chat/KinChatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
KIN_MEMORY_CHANGES_CARD,
KIN_DOC_CARD,
type KinMessageRefInput,
KIN_WORKER_PUBLISH_CARD,
KIN_SOCIAL_PACK_CARD,
KIN_SOCIAL_WEEK_CARD,
KinMessagesReactInput,
Expand All @@ -31,8 +30,7 @@ import {
type KinAuthor,
type KinAgentId,
type ThreadId,
type EnvironmentId,
type KinTaskCardState,
type NodeId,
type KinChat,
type KinChatListEvent,
type KinChatStreamEvent,
Expand Down Expand Up @@ -90,7 +88,6 @@ import { undoDeferral } from "../triggers/KinTriggerService.ts";
import * as ScheduledTasks from "../widgets/scheduledTaskCard.ts";
import * as ReminderCard from "../widgets/reminderCard.ts";
import * as SocialCards from "../social/cards.ts";
import * as PublishCard from "../widgets/workerPublishCard.ts";
import { answerChange } from "../work/companyProfile.ts";
import { KinRefreshObserver } from "./KinRefreshHub.ts";
import { docsForViewer } from "./privateDocs.ts";
Expand All @@ -100,7 +97,7 @@ import { effectiveAudience } from "../lead/Audience.ts";
import { KinStop } from "../lead/KinStop.ts";
import { isOrgOwner } from "../lead/orgState.ts";
import { docPageSources } from "../work/docFiles.ts";
import { turnSensitive } from "../work/workerAttempts.ts";
import { turnSensitive } from "../work/sensitiveReads.ts";
import * as Repository from "./KinChatRepository.ts";
import type { WriteAudience } from "./KinChatRepository.ts";
import { KinAttachmentStore } from "./KinAttachmentStore.ts";
Expand Down Expand Up @@ -264,22 +261,11 @@ export class KinChatService extends Context.Service<
readonly audience: WriteAudience;
readonly authorAgentId: KinAgentId;
readonly threadId: ThreadId;
/** T3's id for the delegated task, which task_cancel takes; else the thread's. */
readonly taskId?: NodeId;
readonly title: string;
readonly model: string | null;
/** A thread in a linked environment: no thread here to read, so the caller says its status. */
readonly remote?: {
readonly environmentId: EnvironmentId;
readonly status: KinTaskCardState["status"];
};
}) => Effect.Effect<KinWidget, ServiceError, OrchestratorV2 | ServerEnvironment>;
/** Server-only, like createTaskCard: Kin's worker launcher closes and reopens worker cards. */
readonly setTaskCardClosed: (input: {
readonly orgId: KinOrgId;
readonly chatId: KinChatId;
readonly audience: WriteAudience;
readonly threadId: ThreadId;
readonly closed: boolean;
}) => Effect.Effect<KinWidget, ServiceError>;
/**
* Server-only: closes an unanswered choice card, as replaced by a newer one for the same
* thing, or with `outcome` saying what became of it (an open question's default taken).
Expand All @@ -306,22 +292,6 @@ export class KinChatService extends Context.Service<
readonly detail: string;
readonly send: KinSendCard;
}) => Effect.Effect<KinWidget, ServiceError>;
/** Server-only: a remote card's live fields, which no thread here can refresh. */
readonly setTaskCardState: (input: {
readonly orgId: KinOrgId;
readonly chatId: KinChatId;
readonly audience: WriteAudience;
readonly threadId: ThreadId;
readonly state: Pick<KinTaskCardState, "status" | "pullRequests" | "lastError">;
}) => Effect.Effect<KinWidget, ServiceError>;
/** The docs a document job made, from the job's stored row; on this server's own cards. */
readonly setTaskCardDocuments: (input: {
readonly orgId: KinOrgId;
readonly chatId: KinChatId;
readonly threadId: ThreadId;
readonly documents: NonNullable<KinTaskCardState["documents"]>;
readonly lastError: string | null;
}) => Effect.Effect<KinWidget, ServiceError>;
readonly act: (
identity: PersonCaller,
input: KinWidgetsActInput,
Expand Down Expand Up @@ -888,10 +858,6 @@ const make = Effect.gen(function* () {
request.value,
).pipe(Effect.provideService(SqlClient.SqlClient, sql), Effect.mapError(cardTapError))
: null;
const publishTap =
widget.type === KIN_WORKER_PUBLISH_CARD
? yield* PublishCard.describePublishTap(widget, request.actionId, request.value)
: null;
const socialTap =
widget.type === KIN_SOCIAL_WEEK_CARD
? yield* SocialCards.describeWeekTap(widget, request.actionId, request.value)
Expand All @@ -900,17 +866,15 @@ const make = Effect.gen(function* () {
widget.type === KIN_SOCIAL_PACK_CARD
? yield* SocialCards.describePackTap(widget, request.actionId)
: null;
const tap = choice ?? reminder ?? scheduled ?? publishTap ?? socialTap ?? packTap;
const tap = choice ?? reminder ?? scheduled ?? socialTap ?? packTap;
const body = yield* encodeAction({
widgetId: request.widgetId,
revision: request.revision,
actionId: request.actionId,
...(request.value === undefined ? {} : { value: request.value }),
...(tap === null ? {} : { text: tap.text }),
// The server finished this tap itself, so it doesn't wake the lead.
...((reminder ?? scheduled ?? publishTap ?? socialTap ?? packTap)?.wake === false
? { handled: true }
: {}),
...((reminder ?? scheduled ?? socialTap ?? packTap)?.wake === false ? { handled: true } : {}),
}).pipe(Effect.mapError(() => invalidState));
const previous = yield* repo.findClientMessage({
...member,
Expand Down Expand Up @@ -965,16 +929,10 @@ const make = Effect.gen(function* () {
hub.publish({ type: "widget.updated", orgId: identity.orgId, widget: closed }),
);
}
const ownerCard = publishTap !== null || socialTap !== null || packTap !== null;
const ownerCard = socialTap !== null || packTap !== null;
if (reminder !== null || scheduled !== null || ownerCard) {
const nowMs = yield* Clock.currentTimeMillis;
let applied: { readonly state: unknown; readonly closed: boolean } | null = null;
// The owner's decision binds to the commit and title the card shows; the follower publishes.
if (publishTap !== null)
applied = yield* PublishCard.applyPublishTap(widget, publishTap, identity.personId).pipe(
Effect.provideService(SqlClient.SqlClient, sql),
Effect.mapError(cardTapError),
);
// The owner's Confirm binds to the posts the card shows; the scheduler hands them over.
if (socialTap !== null)
applied = yield* SocialCards.applyWeekTap(widget, socialTap, identity.personId).pipe(
Expand Down Expand Up @@ -1003,10 +961,10 @@ const make = Effect.gen(function* () {
const at = yield* now;
const updated = yield* repo.updateWidget({
...widget,
// A publish card quotes the lead's title, so only the owner's chat may hold it.
// Social's cards quote the owner's drafts, so only the owner's chat may hold them.
audience: ownerCard ? "owner" : "chat",
state: applied.state,
...(publishTap === null && socialTap?.action !== "confirm" ? {} : { awaiting: [] }),
...(socialTap?.action !== "confirm" ? {} : { awaiting: [] }),
expectedRevision: widget.revision,
closedAt: applied.closed ? at : widget.closedAt,
updatedAt: at,
Expand Down Expand Up @@ -2209,12 +2167,9 @@ const make = Effect.gen(function* () {
if (input.orgId !== "kin-default") return yield* notFound;
const environment = yield* ServerEnvironment;
const orchestrator = yield* OrchestratorV2;
const shell =
input.remote === undefined
? yield* orchestrator
.getThreadShell(input.threadId)
.pipe(Effect.orElseSucceed(() => null))
: undefined;
const shell = yield* orchestrator
.getThreadShell(input.threadId)
.pipe(Effect.orElseSucceed(() => null));
if (shell === null) return yield* notFound;
const agent = yield* requireRecord(
repo.getAgent({ orgId: input.orgId, agentId: input.authorAgentId }),
Expand Down Expand Up @@ -2252,13 +2207,13 @@ const make = Effect.gen(function* () {
}
const updatedAt = yield* now;
const state = yield* TaskCard.decodeTaskCardEffect({
taskId: input.threadId,
taskId: input.taskId ?? input.threadId,
environmentId: yield* environment.getEnvironmentId,
threadId: input.threadId,
remoteEnvironmentId: input.remote?.environmentId ?? null,
remoteEnvironmentId: null,
title: input.title,
model: input.model,
status: input.remote?.status ?? "waiting",
status: "waiting",
pullRequests: [],
lastError: null,
updatedAt,
Expand Down Expand Up @@ -2297,7 +2252,7 @@ const make = Effect.gen(function* () {
widgetClass: "native",
type: "task",
revision: 1,
state: shell === undefined ? state : TaskCard.taskCardState(state, shell, updatedAt),
state: TaskCard.taskCardState(state, shell, updatedAt),
source: null,
feed: null,
awaiting: [],
Expand All @@ -2314,26 +2269,6 @@ const make = Effect.gen(function* () {
yield* sql.afterCommit(cards.track(widget));
return widget;
}, transaction),
setTaskCardClosed: Effect.fn("KinChatService.setTaskCardClosed")(function* (input) {
const existing = yield* requireRecord(
repo.getWidget({ orgId: input.orgId, widgetId: yield* taskCardWidgetId(input) }),
);
if (existing.type !== "task" || existing.chatId !== input.chatId) return yield* notFound;
if ((existing.closedAt !== null) === input.closed) return existing;
const widget = yield* repo.updateWidget({
...existing,
audience: input.audience,
awaiting: input.closed ? [] : existing.awaiting,
expectedRevision: existing.revision,
closedAt: input.closed ? yield* now : null,
updatedAt: yield* now,
});
if (input.closed)
for (const item of yield* repo.waitingForWidget(widget)) yield* resolve(item, "closed");
yield* sql.afterCommit(cards.track(widget));
yield* hub.publish({ type: "widget.updated", orgId: input.orgId, widget });
return widget;
}, transaction),
closeReplaced: Effect.fn("KinChatService.closeReplaced")(function* (input) {
const existing = yield* repo.getWidget(input);
if (Option.isNone(existing) || existing.value.type !== "choice") return;
Expand Down Expand Up @@ -2406,55 +2341,6 @@ const make = Effect.gen(function* () {
yield* hub.publish({ type: "widget.updated", orgId: input.orgId, widget });
return widget;
}, transaction),
setTaskCardState: Effect.fn("KinChatService.setTaskCardState")(function* (input) {
const existing = yield* requireRecord(
repo.getWidget({ orgId: input.orgId, widgetId: yield* taskCardWidgetId(input) }),
);
if (existing.type !== "task" || existing.chatId !== input.chatId) return yield* notFound;
const previous = yield* TaskCard.decodeTaskCardEffect(existing.state).pipe(
Effect.mapError(() => invalidState),
);
if (previous.remoteEnvironmentId === null) return yield* invalidState;
const next = { ...previous, ...input.state };
if (existing.closedAt !== null || TaskCard.taskCardEquivalent(next, previous))
return existing;
const updatedAt = yield* now;
const widget = yield* repo.updateWidget({
...existing,
audience: input.audience,
state: { ...next, updatedAt },
expectedRevision: existing.revision,
updatedAt,
});
yield* hub.publish({ type: "widget.updated", orgId: input.orgId, widget });
return widget;
}, transaction),
setTaskCardDocuments: Effect.fn("KinChatService.setTaskCardDocuments")(function* (input) {
const existing = yield* requireRecord(
repo.getWidget({ orgId: input.orgId, widgetId: yield* taskCardWidgetId(input) }),
);
if (existing.type !== "task" || existing.chatId !== input.chatId) return yield* notFound;
const previous = yield* TaskCard.decodeTaskCardEffect(existing.state).pipe(
Effect.mapError(() => invalidState),
);
if (previous.remoteEnvironmentId !== null) return yield* invalidState;
const next = {
...previous,
documents: input.documents,
...(input.lastError === null ? {} : { lastError: input.lastError }),
};
if (TaskCard.taskCardEquivalent(next, previous)) return existing;
const updatedAt = yield* now;
const widget = yield* repo.updateWidget({
...existing,
audience: "owner",
state: { ...next, updatedAt },
expectedRevision: existing.revision,
updatedAt,
});
yield* hub.publish({ type: "widget.updated", orgId: input.orgId, widget });
return widget;
}, transaction),
upsertWidget: Effect.fn("KinChatService.upsertWidget")(function* (identity, input) {
const member = yield* memberFor(identity, input.chatId);
yield* canWrite(identity, member);
Expand All @@ -2466,8 +2352,6 @@ const make = Effect.gen(function* () {
if (
input.type === "owner_check" ||
input.type === "deferral" ||
// Only Kin's publish gate writes one, from its own git and GitHub.
input.type === KIN_WORKER_PUBLISH_CARD ||
// Only Kin draws Social's cards, from its stored drafts and the service's own names.
input.type === KIN_SOCIAL_WEEK_CARD ||
input.type === KIN_SOCIAL_PACK_CARD ||
Expand Down Expand Up @@ -2630,7 +2514,6 @@ const make = Effect.gen(function* () {
if (
(widget.type === "reminder" ||
widget.type === "scheduled_task" ||
widget.type === KIN_WORKER_PUBLISH_CARD ||
widget.type === KIN_SOCIAL_WEEK_CARD ||
widget.type === KIN_SOCIAL_PACK_CARD) &&
!owning &&
Expand Down
Loading