From b21124085df5a18a3a965acc35ded40d622053de Mon Sep 17 00:00:00 2001 From: GLDRoger <130458023+GLDRoger@users.noreply.github.com> Date: Tue, 10 Nov 2026 14:48:39 +0530 Subject: [PATCH 1/4] feat(kin): leads just work; no level ladder The owner never sees levels or promotions. A lead works at L2 in its owner's DM and in groups its owner owns, computed from stored membership; other chats keep the conservative default and refuse in plain words. Removes the promotion ladder (Promotion.ts, shadow entries, review and summary cards, deferPromotion/review/shadowMemory RPCs, the levels screen) and the shadow dry-run script. K035 takes the old level cards out of chats and the Waiting list. Merges stay owner-signed. Co-Authored-By: Claude Opus 5.5 --- .../src/features/chats/KinChatScreen.tsx | 38 +- .../src/features/chats/KinLevelsScreen.tsx | 301 ------ .../chats/approvals/KinApprovalsScreen.tsx | 2 +- apps/mobile/src/features/chats/routes.tsx | 6 - .../src/features/chats/state/kinClient.ts | 37 - .../features/chats/widgets/KinDigestCard.tsx | 2 +- .../chats/widgets/KinPromotionCard.tsx | 128 --- .../chats/widgets/KinShadowReviewCard.tsx | 193 ---- .../features/chats/widgets/KinWidgetView.tsx | 6 - .../server/scripts/kin-shadow-dry-run.test.ts | 227 ----- apps/server/scripts/kin-shadow-dry-run.ts | 955 ------------------ apps/server/src/kin/KinServer.ts | 8 +- .../src/kin/approvals/PendingActions.ts | 13 +- .../server/src/kin/approvals/RequestAction.ts | 78 +- .../src/kin/approvals/handlers/setLevel.ts | 16 +- apps/server/src/kin/approvals/layer.ts | 2 +- apps/server/src/kin/approvals/mcp.test.ts | 113 +-- apps/server/src/kin/approvals/mcp.ts | 2 +- apps/server/src/kin/chat/KinChatService.ts | 4 +- apps/server/src/kin/chat/approvalCards.ts | 2 +- apps/server/src/kin/cli/lead.ts | 4 +- apps/server/src/kin/floor/KinFloor.ts | 2 +- apps/server/src/kin/layer.ts | 8 +- apps/server/src/kin/lead/KinEventQueue.ts | 3 +- .../src/kin/lead/KinLeadProvision.test.ts | 2 +- apps/server/src/kin/lead/KinLevels.test.ts | 225 ++--- apps/server/src/kin/lead/KinLevels.ts | 292 +----- apps/server/src/kin/lead/LevelGate.ts | 595 ++--------- apps/server/src/kin/lead/WakeupRunner.test.ts | 2 - .../src/kin/lead/WakeupRunner.testkit.ts | 6 - apps/server/src/kin/lead/WakeupRunner.ts | 8 - apps/server/src/kin/lead/Workers.test.ts | 56 +- apps/server/src/kin/lead/Workers.ts | 50 +- apps/server/src/kin/lead/instructions.ts | 9 +- apps/server/src/kin/lead/layer.ts | 7 +- apps/server/src/kin/lead/mcp/handlers.ts | 4 +- apps/server/src/kin/lead/mcp/tools.ts | 13 +- .../src/kin/levels/LevelControl.test.ts | 467 +++++++++ apps/server/src/kin/levels/LevelControl.ts | 320 ++++++ apps/server/src/kin/levels/Promotion.test.ts | 943 ----------------- apps/server/src/kin/levels/Promotion.ts | 915 ----------------- apps/server/src/kin/levels/rpcHandlers.ts | 19 +- .../server/src/kin/mcp/KinChatToolkit.test.ts | 203 +--- apps/server/src/kin/mcp/KinChatToolkit.ts | 7 +- .../src/kin/mcp/agentContextBudget.json | 4 +- apps/server/src/kin/mcp/layer.ts | 3 - .../src/kin/memory/MemoryPullRequests.test.ts | 38 +- .../src/kin/memory/MemoryWriter.test.ts | 97 -- apps/server/src/kin/memory/MemoryWriter.ts | 152 --- .../src/kin/persistence/KinMigrations.test.ts | 58 +- .../src/kin/persistence/KinMigrations.ts | 3 + .../migrations/K035_RetireLevelCards.ts | 21 + apps/server/src/kin/push/KinPushSender.ts | 2 +- .../src/kin/reply/KinReplyBridge.test.ts | 6 +- apps/server/src/kin/reply/KinReplyBridge.ts | 16 +- apps/server/src/kin/triggers/deferralFlow.ts | 2 +- .../server/src/kin/triggers/deferrals.test.ts | 2 +- apps/web/src/kin/KinCards.tsx | 28 - apps/web/src/kin/KinChatView.tsx | 6 +- branding/rules.yaml | 4 +- docs/kin/DESIGN.md | 26 +- docs/kin/KT.md | 30 +- docs/kin/PLAN.md | 22 +- docs/kin/specs/approvals.md | 8 +- docs/kin/specs/lead.md | 77 +- docs/kin/specs/mobile.md | 2 +- docs/operations/kin-shadow-dry-run.md | 132 --- evals/mcp-tool-use/cases/kin.ndjson | 16 +- packages/client-runtime/package.json | 4 - .../src/kin/kinApprovalPresentation.test.ts | 10 +- .../src/kin/kinApprovalPresentation.ts | 15 +- .../src/kin/kinCardPresentation.test.ts | 271 +---- .../src/kin/kinCardPresentation.ts | 31 +- .../client-runtime/src/kin/kinChatFeed.ts | 2 +- .../src/kin/kinDeferralPresentation.ts | 2 +- .../src/kin/kinLevelsPresentation.ts | 456 --------- .../src/kin/kinScreenState.test.ts | 18 +- .../client-runtime/src/kin/kinScreenState.ts | 6 +- .../src/state/commandPermissions.test.ts | 3 - packages/contracts/src/kinLead.ts | 30 - packages/contracts/src/kinLevels.ts | 139 +-- packages/contracts/src/kinRpcs.ts | 3 - 82 files changed, 1400 insertions(+), 6638 deletions(-) delete mode 100644 apps/mobile/src/features/chats/KinLevelsScreen.tsx delete mode 100644 apps/mobile/src/features/chats/widgets/KinPromotionCard.tsx delete mode 100644 apps/mobile/src/features/chats/widgets/KinShadowReviewCard.tsx delete mode 100644 apps/server/scripts/kin-shadow-dry-run.test.ts delete mode 100644 apps/server/scripts/kin-shadow-dry-run.ts create mode 100644 apps/server/src/kin/levels/LevelControl.test.ts create mode 100644 apps/server/src/kin/levels/LevelControl.ts delete mode 100644 apps/server/src/kin/levels/Promotion.test.ts delete mode 100644 apps/server/src/kin/levels/Promotion.ts create mode 100644 apps/server/src/kin/persistence/migrations/K035_RetireLevelCards.ts delete mode 100644 docs/operations/kin-shadow-dry-run.md delete mode 100644 packages/client-runtime/src/kin/kinLevelsPresentation.ts diff --git a/apps/mobile/src/features/chats/KinChatScreen.tsx b/apps/mobile/src/features/chats/KinChatScreen.tsx index a8abd872ca92e..1a390b135548c 100644 --- a/apps/mobile/src/features/chats/KinChatScreen.tsx +++ b/apps/mobile/src/features/chats/KinChatScreen.tsx @@ -136,7 +136,7 @@ import { kinAgentAvatar, kinAvatarView, type KinAvatarView, - kinLevelsAgentId, + kinOwnedLeadAgentId, kinStaleNotice, } from "@t3tools/client-runtime/kin/kinScreenState"; import { useKinHostAt } from "./state/useKinHost"; @@ -227,10 +227,8 @@ function KinLiveChat(props: { inbox?._tag === "Success" ? inbox.value.value.chats.find((chat) => chat.chatId === chatId) : undefined; - const canReadLevels = useAtomValue(kinClient.levelsRead.permissionAtom(props.environmentId)); - // The owner's own lead in their direct chat: the only one they can see and stop. - const ownedAgentId = summary === undefined ? null : kinLevelsAgentId(summary, viewer.personId); - const levelsAgentId = canReadLevels ? ownedAgentId : null; + // The owner's own lead in their direct chat: the only one they can stop. + const ownedAgentId = summary === undefined ? null : kinOwnedLeadAgentId(summary, viewer.personId); const canInterrupt = useAtomValue(kinClient.leadInterrupt.permissionAtom(props.environmentId)); const retry = () => { @@ -261,11 +259,6 @@ function KinLiveChat(props: { ) } agentName={summary === undefined ? null : kinDirectAgentName(summary, viewer.agentNames)} - levels={ - levelsAgentId === null - ? null - : { environmentId: props.environmentId, orgId: props.orgId, agentId: levelsAgentId } - } unread={summary?.unread ?? null} stopLead={ environmentId === null || summary === undefined || ownedAgentId === null || !canInterrupt @@ -398,7 +391,6 @@ function KinChatAppBar(props: { readonly presence: KinPresence | undefined; readonly tasks: string | null; readonly onBack: () => void; - readonly actions: ComponentPropsWithRef["actions"]; }) { const pill = Platform.OS === "ios"; const now = useKinPresenceNow(!pill && kinPresenceNeedsClock(props.presence)); @@ -411,7 +403,7 @@ function KinChatAppBar(props: { ); return ( <> - + {/* Always set, so going back to the default size resets the bar. */} navigation.goBack()} - actions={ - levels == null - ? undefined - : [ - { - accessibilityLabel: "Levels", - icon: "slider.horizontal.3", - onPress: () => navigation.navigate("KinLevels", levels), - }, - ] - } /> {state._tag === "ready" ? ( @@ -976,7 +950,7 @@ function KinChatFeed(props: { viewerMemberId, reactorName, ); - // The host refuses reactions on approval, level, review and deferral cards. + // The host refuses reactions on approval and deferral cards. const reactable = canReact && message.status === "posted" && @@ -1302,7 +1276,7 @@ function KinFeedMessageActions(props: { props.viewerMemberId, props.reactorName, ); - // The host refuses reactions on approval, level, review and deferral cards. + // The host refuses reactions on approval and deferral cards. const reactable = props.canReact && message.status === "posted" && diff --git a/apps/mobile/src/features/chats/KinLevelsScreen.tsx b/apps/mobile/src/features/chats/KinLevelsScreen.tsx deleted file mode 100644 index b19609b7c495a..0000000000000 --- a/apps/mobile/src/features/chats/KinLevelsScreen.tsx +++ /dev/null @@ -1,301 +0,0 @@ -import { useAtomValue } from "@effect/atom-react"; -import { useNavigation, type StaticScreenProps } from "@react-navigation/native"; -import { - EnvironmentId, - KinAgentId, - KinChatError, - KinOrgId, - type KinLevelsGetInput, -} from "@t3tools/contracts"; -import * as Cause from "effect/Cause"; -import * as Option from "effect/Option"; -import * as Schema from "effect/Schema"; -import { AsyncResult } from "effect/reactivity"; -import { useState } from "react"; -import { Alert, View } from "react-native"; - -import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator"; -import { AppBar } from "../../components/ui/AppBar"; -import { AppText as Text } from "../../components/ui/AppText"; -import { Button } from "../../components/ui/Button"; -import { EmptyState } from "../../components/ui/EmptyState"; -import { ErrorBanner } from "../../components/ui/ErrorBanner"; -import { ScreenContent } from "../../components/ui/ScreenContent"; -import { ScreenScrollView } from "../../components/ui/ScreenScrollView"; -import { appAtomRegistry } from "../../state/atom-registry"; -import { useAtomCommand } from "../../state/use-atom-command"; -import { kinClient } from "./state/kinClient"; -import { KinApprovalCard } from "./widgets/KinApprovalCard"; -import { kinChatTitle, kinDirectory } from "@t3tools/client-runtime/kin/kinScreenState"; -import { useKinHostAt } from "./state/useKinHost"; -import { - kinLevelsFailure, - kinLevelsFailureText, - kinLevelsScreenView, - type KinLevelChange, - type KinLevelsRow, -} from "@t3tools/client-runtime/kin/kinLevelsPresentation"; - -type KinLevelsParams = { - readonly environmentId: string; - readonly orgId: string; - readonly agentId: string; -}; - -const decodeEnvironmentId = Schema.decodeUnknownOption(EnvironmentId); -const decodeOrgId = Schema.decodeUnknownOption(KinOrgId); -const decodeAgentId = Schema.decodeUnknownOption(KinAgentId); -const isKinChatError = Schema.is(KinChatError); - -/** The owner's view of one lead's levels: its own, each chat's cap, the trial and open raises. */ -export function KinLevelsScreen({ route }: StaticScreenProps) { - const navigation = useNavigation(); - const environmentId = Option.getOrNull(decodeEnvironmentId(route.params.environmentId)); - const orgId = Option.getOrNull(decodeOrgId(route.params.orgId)); - const agentId = Option.getOrNull(decodeAgentId(route.params.agentId)); - return ( - - navigation.goBack()} /> - - - {environmentId === null || orgId === null || agentId === null ? ( - - ) : ( - - )} - - - - ); -} - -function KinLevelsBody(props: { - readonly environmentId: EnvironmentId; - readonly input: KinLevelsGetInput; -}) { - const { environmentId, input } = props; - const atom = kinClient.levels({ environmentId, input }); - const result = useAtomValue(atom); - const host = useKinHostAt(environmentId); - const { agentNames } = kinDirectory(host._tag === "unpaired" ? { _tag: "none" } : host); - const inbox = useAtomValue(kinClient.inbox({ environmentId, input: {} })); - const canChange = useAtomValue(kinClient.lower.permissionAtom(environmentId)); - const lower = useAtomCommand(kinClient.lower, { reportFailure: false }); - const raise = useAtomCommand(kinClient.raise, { reportFailure: false }); - const [pending, setPending] = useState(null); - const [notice, setNotice] = useState<{ readonly text: string; readonly error: boolean } | null>( - null, - ); - - if (AsyncResult.isInitial(result)) { - return ( - - - - ); - } - if (AsyncResult.isFailure(result)) { - const cause = Cause.squash(result.cause); - if (isKinChatError(cause) && cause.reason === "not_found") { - return ( - - ); - } - if (isKinChatError(cause) && cause.reason === "not_allowed") { - return ( - - ); - } - return ( - - - -