project.ts
This file
Path
packages/sdk/src/project.ts
214 lines · 6.8 KiB · TypeScript
Last changed by
Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
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–52why, one step back1import { Brand } from "@repo/brand";2import type { PolicyInput } from "@repo/protocol/domain/policy";3import { Duration, Predicate } from "effect";4import type { Types } from "effect";56import type { RatchetMeasure } from "./check.ts";7import { functionsOf, withFunctions } from "./functions.ts";8import type {9 Admit,10 OpensAlone,11 ProjectFunctions,12 WithFunctions,13} from "./functions.ts";14import { kinds as defaultKinds } from "./kind.ts";15import type { DeclaredKind } from "./kind.ts";16import { run as runFrom } from "./run.ts";17import type { RunInput } from "./run.ts";18import type { ModulesInput } from "./territory.ts";1920type PolicyInputEncoded = typeof PolicyInput.Encoded;2122/** A span of time as config writes it: `"2 hours"`, `"14 days"`. */23export type Span = `${number} ${24 | "day"25 | "days"26 | "hour"27 | "hours"28 | "millis"29 | "minute"30 | "minutes"31 | "second"32 | "seconds"33 | "week"34 | "weeks"}`;3536export type Days = `${number} ${"day" | "days" | "week" | "weeks"}`;3738/**39 * What a vouch gates: claims and sealed answers (`forCode`), proposals too40 * (`all`), or nothing but denouncements (`bansOnly`).41 */42export type VouchMode = PolicyInputEncoded["vouch"] extends43 | { readonly mode: infer M }44 | undefined45 ? M46 : never;4748export interface RatchetEntry {49 readonly measure: RatchetMeasure;50 readonly territory?: string;51}52Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
line 53why, one step back53/** A project's process. Every key is optional; one left out takes its default (see `defaults`). */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 54–58why, one step back54export interface ProjectConfig {55 /** A trust rule in code: whether a person may claim an ask. Called on demand. */56 readonly admit?: Admit;57 /** Whether landings carry `Assisted-by:` trailers for the agents people worked through. Default `"trailer"`. */58 readonly agents?: PolicyInputEncoded["agents"];Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 59why, one step back59 /** How many decisions a maintainer takes a day, and how long one waits before its default. Default 5 a day, `"14 days"`. */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 60–73why, one step back60 readonly budget?: {61 readonly decisionsPerDay: number;62 readonly expire: Days;63 };64 /** How many claims and open proposals one person may hold at once. Default 3 claims, 2 proposals. */65 readonly caps?: {66 readonly claimsPerPerson: number;67 readonly proposalsPerPerson: number;68 };69 /** How long a claim may go without a push before it is warned, and before it lapses. Default `"2 hours"`, `"24 hours"`. */70 readonly claims?: {71 readonly lapseAfter: Span;72 readonly warnAfter: Span;73 };Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 74why, one step back74 /** Who decides for which paths: a glob, and its maintainers' handles or `"owners"`. Default `{ "**": "owners" }`. */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 75–205why, one step back75 readonly deciders?: Readonly<76 Record<string, readonly [string, ...string[]] | "owners">77 >;78 /** The ask kinds the project's asks are made from. Default `[kinds.fix]`. */79 readonly kinds?: readonly DeclaredKind[];80 readonly modules?: ModulesInput;81 /** Ratchets, by name: `{ "no-explicit-any": check.ratchet.count("bun run lint --format json", { rule }) }`. */82 readonly ratchets?: Readonly<Record<string, RatchetEntry | RatchetMeasure>>;83 /** When a landing starts to count on a person's record, and for how long. Default `"30 days"`, `"365 days"`. */84 readonly record?: {85 readonly countsAfter: Days;86 readonly window: Days;87 };88 /** The project's own commands. Default `run.fromCI`. */89 readonly run?: RunInput;90 /** What a vouch gates, and the vouch file if not the config folder's `vouched.td`. Default `"forCode"`. */91 readonly vouch?:92 | VouchMode93 | { readonly file: string; readonly mode: VouchMode };94 /** Markers this project counts as weakening a check, beyond the platform's own list. */95 readonly weakening?: { readonly markers: readonly string[] };96}9798export type ProjectDefinition = PolicyInputEncoded &99 WithFunctions<ProjectFunctions>;100101type Settings = Pick<102 PolicyInputEncoded,103 "agents" | "budget" | "caps" | "claims" | "record" | "vouch"104>;105106// Only what the config writes: a key it leaves out stays out, and decoding107// with `PolicyInput` gives it the default, so the defaults have one home.108const settingsOf = (config: ProjectConfig): Settings => {109 const settings: Types.Mutable<Settings> = {};110111 if (config.agents !== undefined) {112 settings.agents = config.agents;113 }114115 if (config.budget !== undefined) {116 settings.budget = {117 decisionsPerDay: config.budget.decisionsPerDay,118 expireDays: Duration.toDays(config.budget.expire),119 };120 }121122 if (config.caps !== undefined) {123 settings.caps = config.caps;124 }125126 if (config.claims !== undefined) {127 settings.claims = {128 lapseAfterMs: Duration.toMillis(config.claims.lapseAfter),129 warnAfterMs: Duration.toMillis(config.claims.warnAfter),130 };131 }132133 if (config.record !== undefined) {134 settings.record = {135 countsAfterDays: Duration.toDays(config.record.countsAfter),136 windowDays: Duration.toDays(config.record.window),137 };138 }139140 if (config.vouch !== undefined) {141 settings.vouch = Predicate.isString(config.vouch)142 ? { file: `${Brand.configDir}/vouched.td`, mode: config.vouch }143 : config.vouch;144 }145146 return settings;147};148149const ratchetsOf = (150 ratchets: NonNullable<ProjectConfig["ratchets"]>151): PolicyInputEncoded["ratchets"] =>152 Object.entries(ratchets).map(([name, entry]) =>153 "measure" in entry ? { ...entry, name } : { measure: entry, name }154 );155156// One `opensAlone` for the project: it asks the proposal's kind, and a kind157// without the rule says no.158const opensAloneOf = (159 declared: readonly DeclaredKind[]160): OpensAlone | undefined => {161 const rules = new Map(162 declared.flatMap((each) => {163 const rule = functionsOf(each).opensAlone;164165 return rule === undefined ? [] : [[each.askKind.name, rule] as const];166 })167 );168169 return rules.size === 0170 ? undefined171 : (proposal) => rules.get(proposal.kind)?.(proposal) ?? false;172};173174const define = (175 config: ProjectConfig,176 source: PolicyInputEncoded["source"]177): ProjectDefinition => {178 const declared = config.kinds ?? [defaultKinds.fix];179180 const functions: ProjectFunctions = {181 admit: config.admit,182 opensAlone: opensAloneOf(declared),183 };184185 return withFunctions(186 {187 ...settingsOf(config),188 asks: [],189 deciders: Object.entries(config.deciders ?? { "**": "owners" }).map(190 ([paths, handles]) => ({ handles, paths })191 ),192 functions: {193 admit: functions.admit !== undefined,194 opensAlone: functions.opensAlone !== undefined,195 },196 kinds: declared.map((each) => each.askKind),197 ratchets: ratchetsOf(config.ratchets ?? {}),198 run: config.run ?? runFrom.fromCI,199 source,200 weakening: config.weakening ?? { markers: [] },201 },202 functions203 );204};205Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
line 206why, one step back206/** Declares a project's process: the default export of the config folder's `project.ts`. */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 207–214why, one step back207export const project = (config: ProjectConfig): ProjectDefinition =>208 define(config, "config");209210export const defaults: ProjectDefinition = define({}, "defaults");211212export const toPolicyInput = (213 definition: ProjectDefinition214): PolicyInputEncoded => ({ ...definition });