Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
91f51b8
chore(kin): claim APPR-1 approval contracts
Surajsm60720 Nov 8, 2026
617826a
feat(kin): approval contracts and pure grant verifier (APPR-1)
Surajsm60720 Nov 8, 2026
c54ec4f
fix(kin): match APPR-6's level and device-key targets (APPR-1)
Surajsm60720 Nov 8, 2026
dff3091
fix(kin): fail closed on a non-finite clock and transformed grant fie…
Surajsm60720 Nov 8, 2026
46bbc1f
Merge origin/kin into kin-appr-1-contracts
Surajsm60720 Nov 8, 2026
368abbb
fix(kin): keep approval RPCs out of the chat handler group after merg…
Surajsm60720 Nov 8, 2026
2eb710f
Merge origin/kin into kin-appr-1-contracts; register approval handler…
Surajsm60720 Nov 8, 2026
9a36ba5
Merge remote-tracking branch 'origin/kin' into kin-appr-1-contracts
Surajsm60720 Nov 8, 2026
25d4897
fix(contracts): refuse NUL in Kin approval text fields
Surajsm60720 Nov 8, 2026
29c900b
chore: merge origin/kin into kin-appr-1-contracts
Surajsm60720 Nov 8, 2026
9ebb580
chore: merge origin/kin into kin-appr-1-contracts
Surajsm60720 Nov 8, 2026
8fd56d4
chore: merge origin/kin into kin-appr-1-contracts
Surajsm60720 Nov 8, 2026
99d8172
Merge remote-tracking branch 'origin/kin' into kin-appr-1-contracts
Surajsm60720 Nov 8, 2026
f1d1feb
feat(contracts): add disabled reason to KinApprovalError
Surajsm60720 Nov 8, 2026
1e51562
Merge remote-tracking branch 'origin/kin' into kin-appr-1-contracts
Surajsm60720 Nov 8, 2026
d48ee0e
Merge remote-tracking branch 'origin/kin' into kin-appr-1-contracts
GLDRoger Nov 8, 2026
cc7e872
fix(kin): refuse climbing branch names and content paths in approval …
GLDRoger Nov 8, 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
30 changes: 30 additions & 0 deletions apps/server/src/kin/approvals/rpcHandlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { KinApprovalError, KinApprovalRpcs } from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as Stream from "effect/Stream";
import * as RpcGroup from "effect/rpc/RpcGroup";

import type { AuthenticatedSession } from "../../auth/EnvironmentAuth.ts";

const group = RpcGroup.make(...KinApprovalRpcs);
// Every method refuses until its task lands (APPR-3, -4, -5, -10); nothing here can approve.
const unavailable = Effect.fail(
new KinApprovalError({ reason: "unavailable", message: "Kin approvals are unavailable." }),
);

export const makeKinApprovalHandlers = (_session: AuthenticatedSession) =>
Effect.sync(() =>
group.of({
"kin.approvals.list": () => Stream.fromEffect(unavailable),
"kin.approvals.get": () => unavailable,
"kin.approvals.challenge": () => unavailable,
"kin.approvals.submitGrant": () => unavailable,
"kin.approvals.reject": () => unavailable,
"kin.approvals.keyChallenge": () => unavailable,
"kin.approvals.registerKey": () => unavailable,
"kin.approvals.confirmKey": () => unavailable,
"kin.approvals.listKeys": () => unavailable,
"kin.approvals.revokeKey": () => unavailable,
"kin.audit.list": () => unavailable,
"kin.audit.verify": () => unavailable,
}),
);
4 changes: 2 additions & 2 deletions apps/server/src/kin/chat/rpcHandlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
KinAgentId,
KinChatId,
KinMessageId,
KinRpcs,
KinChatAndBudgetRpcs,
KinOrgId,
ThreadId,
RpcScopeAuthorization,
Expand Down Expand Up @@ -76,7 +76,7 @@ const probe = WsRpcGroup.omit(
tag !== WS_METHODS.serverProbe,
),
);
const group = RpcGroup.make(...KinRpcs, ...probe.requests.values()).middleware(
const group = RpcGroup.make(...KinChatAndBudgetRpcs, ...probe.requests.values()).middleware(
RpcScopeAuthorization,
);
const seed = Effect.gen(function* () {
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/kin/rpcHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { KinRpcs } from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as RpcGroup from "effect/rpc/RpcGroup";
import type { AuthenticatedSession } from "../auth/EnvironmentAuth.ts";
import { makeKinApprovalHandlers } from "./approvals/rpcHandlers.ts";
import { makeKinChatHandlers } from "./chat/rpcHandlers.ts";

const group = RpcGroup.make(...KinRpcs);
Expand All @@ -11,5 +12,6 @@ export const makeKinHandlers = Effect.fn("makeKinHandlers")(function* (
) {
return group.of({
...(yield* makeKinChatHandlers(session)),
...(yield* makeKinApprovalHandlers(session)),
});
});
2 changes: 1 addition & 1 deletion docs/kin/specs/approvals.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export const KinGrantPayload = Schema.Struct({
5. The RPC caller's session is the session the key was registered from, or another session of the same person → `session_mismatch`. (Defence in depth; the signature is the real check.)
6. Pending action exists in the org, is `awaiting_approval`, and `revision` and `nonce` match → `stale` (the card refreshes).
7. `kind`, `target`, `targetDigest`, `headSha`, `base`, `mergeMethod` equal the server's record → `target_mismatch`.
8. `|now − iat| ≤ 300` and `exp − iat ≤ 900` → `time_window`.
8. `now` is a finite number, `|now − iat| ≤ 300`, `iat < exp`, `exp − iat ≤ 900` and `now < exp` → `time_window`.
9. Re-read the PR from GitHub with the bot token; head and base still match → `head_moved` (rotate nonce, refresh card).
10. In one transaction: insert `kin_grants` (`jti` UNIQUE, `(action_id, approver)` UNIQUE) and CAS the action to `approved` → `replayed` on conflict.

Expand Down
1 change: 1 addition & 0 deletions packages/contracts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ export * from "./clientRpcPermissions.ts";
export * from "./kinChat.ts";
export * from "./kinLead.ts";
export * from "./kinTriggers.ts";
export * from "./kinApprovals.ts";

export * from "./kinRpcs.ts";
49 changes: 49 additions & 0 deletions packages/contracts/src/kinApprovals.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { describe, expect, it } from "@effect/vitest";
import * as Schema from "effect/Schema";

import { BranchName, KinApprovalsRegisterKeyInput, KinContentPath } from "./kinApprovals.ts";

const accepts = (schema: Schema.Top, value: unknown) =>
Schema.is(schema as Schema.Codec<unknown>)(value);

describe("approval names", () => {
it.each(["main", "feature/kin-1", "release/v1.2", "a+b_c-d"])("accepts branch %s", (name) => {
expect(accepts(BranchName, name)).toBe(true);
});
it.each([
"../../x",
"x/../y",
"/main",
"main/",
"a//b",
".hidden",
"a/.b",
"x.lock",
"a/b.lock",
"main.",
])("refuses branch %s", (name) => {
expect(accepts(BranchName, name)).toBe(false);
});
it.each(["rules.md", "memory/people/priya.md", ".kin/rules.md"])("accepts path %s", (path) => {
expect(accepts(KinContentPath, path)).toBe(true);
});
it.each(["../../.ssh/authorized_keys", "a/../b", "/etc/passwd", "a//b", "./rules.md", "a/"])(
"refuses path %s",
(path) => {
expect(accepts(KinContentPath, path)).toBe(false);
},
);
it("caps each attestation certificate", () => {
const input = (cert: string) => ({
orgId: "org_01",
publicJwk: { kty: "EC", crv: "P-256", x: "x".repeat(43), y: "y".repeat(43) },
platform: "android",
challenge: "abc",
attestation: { certificateChain: [cert] },
deviceLabel: "Phone",
});
const decode = Schema.decodeUnknownExit(KinApprovalsRegisterKeyInput);
expect(decode(input("A".repeat(8192)))._tag).toBe("Success");
expect(decode(input("A".repeat(8193)))._tag).toBe("Failure");
});
});
Loading