The best way to control Claude Code, Codex and more from any computer or phone

main
ts 24 lines 937 Bytes
Raw
1 /** Application policy, shared by push, REST ref writes, and pull merges. */
2 import * as Git from "@alchemy.run/git";
3 import * as Effect from "effect/Effect";
4 import { Session, Unauthorized } from "./auth.ts";
5
6 export const checkRefChanges = (repo: Git.RepoMetaData, updates: ReadonlyArray<Git.RefUpdate>) =>
7 Effect.gen(function* () {
8 const { user } = yield* Session;
9 if (user === null) return yield* new Unauthorized();
10 for (const update of updates) {
11 if (user.id.toLowerCase() !== repo.owner.toLowerCase()) {
12 return yield* new Git.PushDenied({
13 ref: update.ref,
14 reason: "only the repository owner may change refs",
15 });
16 }
17 if (update.ref === `refs/heads/${repo.defaultBranch}` && /^0+$/.test(update.newOid)) {
18 return yield* new Git.PushDenied({
19 ref: update.ref,
20 reason: "the default branch cannot be deleted",
21 });
22 }
23 }
24 });