policy.ts
This file
Path
packages/protocol/src/domain/policy.ts
170 lines · 4.4 KiB · TypeScript
Last changed by
Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 1–87why, one step back1import { Brand } from "@repo/brand";2import { Effect, Schema, Struct } from "effect";34import { Handle, LandedSha, RepoPath } from "../ids.ts";5import { Ask } from "./ask.ts";6import { RatchetSpec } from "./check.ts";7import { AtLeastOne, Glob, NoneOrMore } from "./common.ts";8import { AskKind } from "./kind.ts";9import { RunBlock } from "./run.ts";10import { Territory } from "./territory.ts";11import { VisibilityPolicy } from "./visibility.ts";1213const Source = Schema.Literals(["config", "defaults"]);1415const Budget = Schema.Struct({16 decisionsPerDay: AtLeastOne,17 expireDays: AtLeastOne,18});1920const Caps = Schema.Struct({21 claimsPerPerson: AtLeastOne,22 /** `0` turns proposals off. */23 proposalsPerPerson: NoneOrMore,24});2526const Claims = Schema.Struct({27 lapseAfterMs: AtLeastOne,28 warnAfterMs: AtLeastOne,29});3031const RecordWindow = Schema.Struct({32 /** `0` counts a landing from the day it lands. */33 countsAfterDays: NoneOrMore,34 windowDays: AtLeastOne,35});3637const Vouch = Schema.Struct({38 file: RepoPath,39 mode: Schema.Literals(["forCode", "all", "bansOnly"]),40});4142const Agents = Schema.Literals(["trailer", "none"]);4344const Functions = Schema.Struct({45 admit: Schema.Boolean,46 opensAlone: Schema.Boolean,47});4849const Weakening = Schema.Struct({50 markers: Schema.Array(Schema.NonEmptyString),51});5253export const Policy = Schema.Struct({54 agents: Agents,55 asks: Schema.Array(Ask),56 at: LandedSha,57 budget: Budget,58 caps: Caps,59 claims: Claims,60 deciders: Schema.Array(61 Schema.Struct({ handles: Schema.NonEmptyArray(Handle), paths: Glob })62 ),63 functions: Functions,64 judge: Schema.Struct({65 paths: Schema.Array(Glob),66 pointers: Schema.Array(Schema.NonEmptyString),67 }),68 kinds: Schema.Array(AskKind),69 modules: Schema.Array(Territory),70 ratchets: Schema.Array(RatchetSpec),71 record: RecordWindow,72 run: RunBlock,73 source: Source,74 visibility: Schema.optionalKey(VisibilityPolicy),75 vouch: Vouch,76 vouches: Schema.Array(77 Schema.Struct({78 denounced: Schema.Boolean,79 handle: Handle,80 note: Schema.optionalKey(Schema.String),81 })82 ),83 weakening: Weakening,84});8586export type Policy = typeof Policy.Type;87Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
line 88why, one step back88// Without its layers: the ledger shows those, and keeps the cartridge removable.Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d
lines 89–94why, one step back89export const PublicPolicy = Policy.mapFields(90 Struct.omit(["asks", "functions", "visibility"])91);9293export type PublicPolicy = typeof PublicPolicy.Type;94Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
lines 95–96why, one step back95// Lives here, beside the policy whose read names it: a module of its own96// would cost the root's preloaded bytes.Merge build/imported-from into mainoscabrielbefore adoptionf224a14
lines 97–103why, one step back97export const ImportSource = Schema.Struct({98 branch: Schema.optionalKey(Schema.NonEmptyString),99 url: Schema.String.check(Schema.isPattern(/^https:\/\/\S+$/u)),100});101102export type ImportSource = typeof ImportSource.Type;103Name the ask an opening opened, say why a policy has not evaluated, and give code history a durable storeoscabrielbefore adoption51f046c
lines 104–110why, one step back104export const PolicyPending = Schema.Struct({105 at: LandedSha,106 reason: Schema.Literals(["noConfig", "configFailed"]),107});108109export type PolicyPending = typeof PolicyPending.Type;110Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 111–157why, one step back111export const AskInput = Ask.mapFields(112 Struct.omit(["openedAt", "openedIn", "project", "state"])113);114115export type AskInput = typeof AskInput.Type;116117export const FromCI = Schema.TaggedStruct("FromCI", {});118119export type FromCI = typeof FromCI.Type;120121export const PolicyInput = Schema.Struct({122 agents: Agents.pipe(Schema.withDecodingDefaultKey(Effect.succeed("trailer"))),123 asks: Schema.Array(AskInput),124 budget: Budget.pipe(125 Schema.withDecodingDefaultKey(126 Effect.succeed({ decisionsPerDay: 5, expireDays: 14 })127 )128 ),129 caps: Caps.pipe(130 Schema.withDecodingDefaultKey(131 Effect.succeed({ claimsPerPerson: 3, proposalsPerPerson: 2 })132 )133 ),134 claims: Claims.pipe(135 Schema.withDecodingDefaultKey(136 Effect.succeed({ lapseAfterMs: 86_400_000, warnAfterMs: 7_200_000 })137 )138 ),139 deciders: Schema.Array(140 Schema.Struct({141 handles: Schema.Union([142 Schema.NonEmptyArray(Handle),143 Schema.Literal("owners"),144 ]),145 paths: Glob,146 })147 ),148 functions: Functions,149 kinds: Schema.Array(AskKind),150 ratchets: Schema.Array(RatchetSpec),151 record: RecordWindow.pipe(152 Schema.withDecodingDefaultKey(153 Effect.succeed({ countsAfterDays: 30, windowDays: 365 })154 )155 ),156 run: Schema.Union([RunBlock, FromCI]),157 source: Source,Merge build/608-datekit-maintainers-layer: datekit has a maintainers layer of sealed checks, each citing the clause it enforces, and the seed pushes itoscabrielbefore adoption166f6c9
line 158why, one step back158 visibility: Schema.optionalKey(VisibilityPolicy),Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 159–170why, one step back159 vouch: Vouch.pipe(160 Schema.withDecodingDefaultKey(161 Effect.succeed({162 file: `${Brand.configDir}/vouched.td`,163 mode: "forCode" as const,164 })165 )166 ),167 weakening: Weakening,168});169170export type PolicyInput = typeof PolicyInput.Type;