sections.ts
This file
Path
packages/agent-kit/src/sections.ts
240 lines · 9.1 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
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–7why, one step back1import { Brand } from "@repo/brand";2import { RatchetMeasure } from "@repo/protocol/domain/check";3import type { AskKind, CheckKind, ClaimRule } from "@repo/protocol/domain/kind";4import type { Policy } from "@repo/protocol/domain/policy";5import type { RunBlock } from "@repo/protocol/domain/run";6import { Array as Arr, Order, Predicate } from "effect";7Merge redesign into mainoscabrielbefore adoptioncaedd21
line 8why, one step back8import { pushCommand } from "./install.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 9–21why, one step back9import { code, listed, table } from "./text.ts";1011const cli = (...words: readonly string[]) =>12 code([Brand.cli, ...words].join(" "));1314const remote = Brand.slug;1516const notesRef = `refs/notes/${Brand.slug}`;1718export const loopSteps = () => [19 `1. Read the ask, then claim it: ${cli("ask", "<ask>")}, then ${cli("claim", "<ask>")}. The claim prints your fork's remote; add it with ${code(`git remote add ${remote} <remote>`)}.`,20 "2. Work inside the ask's territory until its check passes.",21 `3. Run ${cli("check")}. It gives the refusals a push would get, then runs the ask's check and the project's lanes; fix everything it reports.`,Merge redesign into mainoscabrielbefore adoptioncaedd21
line 22why, one step back22 `4. Push your answer to your fork: ${code(pushCommand)}. The push itself can be refused; follow the answer with ${cli("status")}.`,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 23–121why, one step back23 `5. Read the verdict on your head: ${code(`git fetch ${remote} ${notesRef}:${notesRef}`)}, then ${code(`git notes --ref=${Brand.slug} show HEAD`)}. It is JSON: match on its \`_tag\`, and run a refusal's \`next\`.`,24];2526const unitsOfTime = [27 { ms: 86_400_000 * 7, one: "week" },28 { ms: 86_400_000, one: "day" },29 { ms: 3_600_000, one: "hour" },30 { ms: 60_000, one: "minute" },31 { ms: 1000, one: "second" },32] as const;3334export const span = (ms: number) => {35 const unit = unitsOfTime.find((each) => ms % each.ms === 0) ?? unitsOfTime[4];3637 const count = Math.round(ms / unit.ms);3839 return `${count} ${unit.one}${count === 1 ? "" : "s"}`;40};4142export const claimTerms = (policy: Policy) =>43 `A claim stays alive only while you push to it: after ${span(policy.claims.warnAfterMs)} without a push it is warned, and after ${span(policy.claims.lapseAfterMs)} it lapses. You may hold ${policy.caps.claimsPerPerson} ${policy.caps.claimsPerPerson === 1 ? "claim" : "claims"} at once in this project.`;4445const byName = <A>(name: (item: A) => string) =>46 Order.mapInput(Order.String, name);4748const judgeLines = (judge: Policy["judge"]) => [49 ...judge.paths.map((path) => `- ${code(path)}`),50 ...judge.pointers.map(51 (pointer) => `- ${code(pointer)} (only that part of the file)`52 ),53];5455const measureOf = RatchetMeasure.match({56 Count: ({ command, rule }) =>57 rule === undefined58 ? `the lint findings ${code(command)} prints`59 : `the ${code(rule)} findings ${code(command)} prints`,60 Metric: ({ command, path }) =>61 `the number at ${code(path)} in the JSON ${code(command)} prints`,62});6364const ratchetLines = (ratchets: Policy["ratchets"]) =>65 Arr.sort(66 ratchets,67 byName((ratchet: Policy["ratchets"][number]) => ratchet.name)68 ).map(69 (ratchet) =>70 `- ${code(ratchet.name)}${ratchet.territory === undefined ? "" : ` in ${code(ratchet.territory)}`}: ${measureOf(ratchet.measure)}`71 );7273export const changeSection = (policy: Policy) => {74 const { judge, modules, ratchets, weakening } = policy;7576 const publicFiles = modules.some(77 ({ publicFiles: files }) => files !== undefined78 );7980 const territories = Arr.sort(81 modules,82 byName((module: Policy["modules"][number]) => module.module)83 );8485 return [86 "## What an answer may change",87 "",88 `Change files only inside the ask's territory, the module ${cli("ask", "<ask>")} names; a push that changes anything else is refused with \`OutOfScope\`.`,89 ...(territories.length === 090 ? []91 : [92 "",93 ...table(94 ["Module", "Paths", "Public files"],95 territories.map((module) => [96 code(module.module),97 module.paths.map(code).join(", "),98 module.publicFiles === undefined99 ? "every file"100 : module.publicFiles.map(code).join(", "),101 ])102 ),103 ]),104 ...(publicFiles105 ? [106 "",107 "Import another module only through its public files; an import that reaches past them is refused with `ReachedInternals`.",108 ]109 : []),110 ...(judge.paths.length + judge.pointers.length === 0111 ? []112 : [113 "",114 "Never change the judge closure, the files that decide what the checks do; a push that changes one is refused with `TouchedJudge`:",115 "",116 ...judgeLines(judge),117 ]),118 ...(weakening.markers.length === 0119 ? []120 : [121 "",Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 122why, one step back122 `Never add a marker that turns a check off: ${weakening.markers.map(code).join(", ")}. One without a reason is refused with \`Weakened\`; one with a reason waits for a maintainer.`,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 123–127why, one step back123 ]),124 ...(ratchets.length === 0125 ? []126 : [127 "",Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 128why, one step back128 "Ratchets only go down: an answer that raises one is refused with `Weakened`, and only a maintainer raises one.",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 129–188why, one step back129 "",130 ...ratchetLines(ratchets),131 ]),132 "",133 ];134};135136export const lanesOf = (run: RunBlock) =>137 Arr.sort(138 Object.entries(run.checks),139 byName(([lane]: readonly [string, string]) => lane)140 );141142export const runSection = (run: RunBlock) => [143 "## The run block",144 "",145 `The project's own commands. The platform runs them exactly as written, on the merged tree, in the ${code(run.image ?? "checker:default")} image; ${cli("check")} runs them on your machine.`,146 "",147 ...(run.setup === undefined ? [] : [`- Setup, once: ${code(run.setup)}`]),148 ...(run.setupEgress === undefined || run.setupEgress.length === 0149 ? []150 : [151 `- Setup may reach ${run.setupEgress.map(code).join(", ")}; the checks reach no network.`,152 ]),153 ...(run.doctor === undefined ? [] : [`- Doctor: ${code(run.doctor)}`]),154 `- One check file: ${code(run.test)}, with \`{path}\` the ask's check file`,155 "- Lanes, each run on every answer:",156 ...lanesOf(run).map(157 ([lane, command]) => ` - ${code(lane)}: ${code(command)}`158 ),159 "",160];161162const checkKindText = (kind: CheckKind, run: RunBlock) =>163 ({164 lintToZero:165 "a lint rule's findings in the territory go to zero; the ask names the rule and the command that counts them.",166 migrate:167 "every use of one name moves to another; the ask names the command that counts the uses left.",168 ratchet: "a named ratchet goes down; the ask names it.",169 redThenGreen: `one check file fails on main by an assertion, and passes with your answer; ${cli("check")} runs it with ${code(run.test)}.`,170 symbolAbsent:171 "the last step of a migrate: a name is gone; the ask names the command that counts its uses.",172 })[kind];173174const claimerText = (rule: ClaimRule, vouchFile: string) => {175 if (Predicate.isString(rule)) {176 return rule === "anyone"177 ? "anyone signed in."178 : `anyone a member has vouched for in ${code(vouchFile)}.`;179 }180181 return "record" in rule182 ? `anyone whose record has at least ${rule.record.atLeast} ${rule.record.atLeast === 1 ? "landing" : "landings"} in ${code(rule.record.area)}.`183 : `a newcomer, with ${code(rule.newcomer.mentor)} as mentor.`;184};185186const finishText = {187 never: "none: a passing answer lands as it is.",188 optional:Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 189why, one step back189 "a maintainer may add commits of their own to a passing answer before it lands, credited `Finished-by`.",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
line 190why, one step back190 required:Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 191why, one step back191 "a passing answer waits for a maintainer's commits on top before it lands, credited `Finished-by`.",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 192–215why, one step back192} as const satisfies Record<AskKind["finish"], string>;193194const kindLines = (kind: AskKind, policy: Policy) => [195 `### ${code(kind.name)}`,196 "",197 `- Check: ${checkKindText(kind.checkKind, policy.run)}`,198 `- Who may claim: ${claimerText(kind.claimers, policy.vouch.file)}`,199 kind.race === 1200 ? "- Claims at once: 1; the claim is exclusive."201 : `- Claims at once: up to ${kind.race}.`,202 `- Finish: ${finishText[kind.finish]}`,203 ...(kind.oneWay ? ["- One way: a later answer can't undo its answers."] : []),204 ...(kind.requires.length === 0205 ? []206 : [`- The brief states: ${listed(kind.requires)}.`]),207 "",208];209210export const kindsSection = (policy: Policy) =>211 policy.kinds.length === 0212 ? []213 : [214 "## Ask kinds",215 "",Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 216why, one step back216 `Each ask is of one kind, which says how its check judges an answer, who may claim it and whether a maintainer finishes it; ${cli("ask", "<ask>")} names 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 217–240why, one step back217 "",218 ...Arr.sort(219 policy.kinds,220 byName((kind: AskKind) => kind.name)221 ).flatMap((kind) => kindLines(kind, policy)),222 ];223224export const unfencedNorms = (agents: Policy["agents"] = "trailer") => [225 "- Keep an answer to its ask's want. The gate holds the files you change to the territory, but nothing measures how much you change inside it.",226 ...(agents === "none"227 ? []228 : [229 "- Name the agent you work through. A landing carries an `Assisted-by:` trailer for the agent your harness's environment names; a harness that names none goes unnamed.",230 ]),231];232233export const unfencedSection = (agents: Policy["agents"] = "trailer") => [234 "## No fence yet",235 "",236 "Norms that nothing checks yet. Keep them; the gate does not refuse an answer that breaks one.",237 "",238 ...unfencedNorms(agents),239 "",240];