Skip to content
Myr

refusals.ts

This file

Path

packages/agent-kit/src/refusals.ts

290 lines · 10.4 KiB · TypeScript

Last changed by

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

History of this file

Take 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

line 1why, one step back
1import { Brand } from "@repo/brand";

Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862

line 2why, one step back
2import { ExitCode, exitCodeOfTag, precedence } from "@repo/protocol/exit-code";

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 3–26why, one step back
3import { groups } from "@repo/protocol/refusal";
4import { Exit, Predicate, SchemaAST } from "effect";56import { code, table } from "./text.ts";78const answerGroups = [9 "Push and claim",10 "Shape",11 "Merge",12 "Checks",13 "Never counted against the answerer",14] as const;1516type Group = (typeof groups)[number];1718type Member = Group["members"][number];1920type AnswerMember = Extract<21 Group,22 { readonly name: (typeof answerGroups)[number] }23>["members"][number];2425type AnswerTag = InstanceType<AnswerMember>["_tag"];26

Merge build/1108 into mainoscabrielbefore adoption8d9ece9

lines 27–28why, one step back
27type Tag = InstanceType<Member>["_tag"];
28

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 29–45why, one step back
29interface Repair {
30 readonly todo: string;31 readonly next?: string;32 readonly nextNames?: string;33}3435const cli = (...words: readonly string[]) => [Brand.cli, ...words].join(" ");3637const repairs = {38 AskBlocked: {39 todo: "Wait for the asks it names to land, or answer one of them first.",40 },41 AskFull: { todo: "Someone else holds the claim: pick another ask." },42 AttemptsExhausted: {43 todo: "Wait until `resetsAt`: you used every attempt on that area's held-back checks for now.",44 },45 CapReached: {

Say which limit a CapReached reached and when to try again, and that a fork takes branches onlyoscabrielbefore adoption42ea9b7

line 46why, one step back
46 todo: "Read `limit`: for claims, release or land a claim you hold; for proposals, wait for an open one to be decided; for drafts, the proposal has had every draft round it takes; with `retryAfter`, wait that many seconds and try again.",

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 47–86why, one step back
47 },
48 ChecksFailed: {49 nextNames: "the command that reproduces the failure",50 todo: "Run `next` to see the failure, fix it, and push again.",51 },52 ClaimLapsed: {53 next: cli("claim", "<ask>"),54 todo: "Your claim lapsed after a spell without a push: claim the ask again if it is still open.",55 },56 Denounced: {57 todo: "The project's vouch file denounces you: it takes no claims or proposals from you.",58 },59 DirectPush: {60 todo: "Main moves only by a landing: push your answer to your claim's fork.",61 },62 Flake: {63 todo: "Nothing: the check failed and then passed on the same tree, and the platform runs it again.",64 },65 HeldBackFailed: {66 todo: "A held-back check failed; you see only its area and suite. Fix the behaviour and push again.",67 },68 NoAsk: {69 todo: "Push to the fork your claim gave you, which names its ask.",70 },71 NotClaimed: {72 next: cli("claim", "<ask>"),73 todo: "Claim the ask, then push again.",74 },75 NotVouched: { todo: "Ask a member of the project to vouch for you." },76 OutOfScope: {77 todo: "Undo your changes to the paths it names: they are outside the ask's territory.",78 },79 PrivatePathInPublicTree: {80 todo: "Take the held-back paths it names out of your answer.",81 },82 ReachedInternals: {83 todo: "Import the other module only through its public files.",84 },85 RepoBusy: { todo: "Push again." },86 StaleBase: {

Merge refusal/stale-base-movers into mainoscabrielbefore adoptiona23e097

line 87why, one step back
87 todo: "Main moved: rebase onto it, resolve the conflicts it names, and push again. `movedBy` names the landing that last changed each conflicting path, with its `author` and `ask`: keep that change as you resolve.",

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 88–96why, one step back
88 },
89 StaleLayer: { todo: "Nothing: the answer is checked again." },90 TouchedJudge: {91 todo: "Undo your changes to the paths it names: they decide what the checks do.",92 },93 VerifierBlocked: {94 todo: "Nothing: the platform could not run the checks, and runs them again.",95 },96 Weakened: {

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

line 97why, one step back
97 todo: "Take the marker out; a marker without a reason may get one after ` -- ` for a maintainer to weigh, but one a maintainer declined stays out; never raise a ratchet.",

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 98–100why, one step back
98 },
99} as const satisfies Record<AnswerTag, Repair>;100

Merge build/1108 into mainoscabrielbefore adoption8d9ece9

lines 101–116why, one step back
101const elsewhere = {
102 DecisionClosed: {103 todo: "Nothing to decide: it was taken already, or expired to its default.",104 },105 DraftInProgress: {106 next: cli("proposal", "<proposal>"),107 todo: "Wait: the platform is drafting this proposal's ask already, and `next` shows when it settles.",108 },109 ImportFailed: { todo: "Read `reason`, then import again." },110 IncompleteBrief: {111 todo: "Fill in the fields `missing` names: the ask's kind requires them.",112 },113 LayerContentInPublicTree: {114 todo: "Take the paths it names out: their files stay private and never enter a public tree.",115 },116 NotDecider: {

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

line 117why, one step back
117 todo: "Only one of the project's maintainers may do this: ask one of them.",

Merge build/1108 into mainoscabrielbefore adoption8d9ece9

lines 118–124why, one step back
118 },
119 NotRedFirst: {120 todo: "Make the ask's check fail on main by an assertion, the same way twice, then open the ask again.",121 },122 NotSensitive: {123 todo: "Only an `@sensitive` item holds a write-only value: `next` shows which items are.",124 },

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 125–127why, one step back
125 NotYourNamespace: {
126 todo: "Make the project in your own namespace: `next` names it with your handle.",127 },

Merge build/1108 into mainoscabrielbefore adoption8d9ece9

line 128why, one step back
128 PostureChange: {

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

line 129why, one step back
129 todo: "A maintainer declined the posture change it names (`from`, `to`): take out what changes the posture; `next` lists the decisions.",

Merge build/1108 into mainoscabrielbefore adoption8d9ece9

lines 130–173why, one step back
130 },
131 ProjectExists: { todo: "Pick another name: that one is taken." },132 ProposalClosed: {133 todo: "Nothing more is drafted for it: the proposal was accepted, declined or expired.",134 },135 SecretInOutput: {136 todo: "Take the write-only value of `item` out of the output or the tree (`where`), then check again.",137 },138 UnknownAsk: {139 todo: "Check the ask's name: `next` lists the project's open asks.",140 },141 UnknownCommit: {142 todo: "Fetch the project, then name a commit it holds.",143 },144 UnknownDecision: {145 todo: "Check the decision's id: `next` lists the decisions waiting on you.",146 },147 UnknownEnvItem: {148 todo: "Name a key the project's env shape has: `next` lists them.",149 },150 UnknownPath: {151 todo: "Name a path the commit holds: `next` lists its files.",152 },153 UnknownProject: {154 todo: "Check the project's name: every project is listed in the index.",155 },156 UnknownProposal: {157 todo: "Check the proposal's id: `next` lists the proposals waiting on you.",158 },159 UnknownRevision: {160 todo: "Name `main`, a commit the project holds or one of its tags: `next` lists its refs.",161 },162 UnstatedRequirement: {163 todo: "State in public what the area's held-back check holds, or take the check out of the suite.",164 },165 ValueTooShort: {166 nextNames: `${code(cli("env", "set", "<key>"))}, with ${code("--acknowledge-short")} when the value is above the floor`,167 todo: "Give a longer value, or acknowledge a short one where the floor allows it.",168 },169 WeakCheck: {170 todo: "Strengthen the check: as it stands, the trivial answer `weakness` names would pass it.",171 },172} as const satisfies Record<Exclude<Tag, AnswerTag>, Repair>;173

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 174–175why, one step back
174const repairOf = new Map<string, Repair>(Object.entries(repairs));
175

Merge build/1108 into mainoscabrielbefore adoption8d9ece9

lines 176–180why, one step back
176const everyRepairOf = new Map<string, Repair>([
177 ...repairOf,178 ...Object.entries(elsewhere),179]);180

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 181–194why, one step back
181const constructorDefault = (ast: SchemaAST.AST) => {
182 const fill = ast.context?.constructorDefault;183184 return fill !== undefined &&185 Exit.isExit(fill) &&186 Exit.isSuccess(fill) &&187 Predicate.isString(fill.value)188 ? fill.value189 : undefined;190};191192export interface AnswerRefusal {193 readonly tag: string;194 readonly retryable: boolean;

Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862

line 195why, one step back
195 readonly exitCode: ExitCode;

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 196–209why, one step back
196 readonly next: string;
197 readonly todo: string;198}199200const nextOf = (fixed: string | undefined, repair: Repair | undefined) => {201 if (fixed !== undefined) {202 return code(fixed);203 }204205 return repair?.next === undefined206 ? (repair?.nextNames ?? "")207 : code(repair.next);208};209

Merge build/1108 into mainoscabrielbefore adoption8d9ece9

lines 210–218why, one step back
210const rowOf = (
211 member: Member,212 repairTable: ReadonlyMap<string, Repair>213): AnswerRefusal => {214 const { ast: retryable } = member.fields.retryable;215 const fixed = constructorDefault(member.fields.next.ast);216 const repair = repairTable.get(member.identifier);217218 return {

Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862

line 219why, one step back
219 exitCode: exitCodeOfTag(member.identifier),

Merge build/1108 into mainoscabrielbefore adoption8d9ece9

lines 220–226why, one step back
220 next: nextOf(fixed, repair),
221 retryable: SchemaAST.isLiteral(retryable) && retryable.literal === true,222 tag: member.identifier,223 todo: repair?.todo ?? "",224 };225};226

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 227–230why, one step back
227export const answerRefusals: readonly AnswerRefusal[] = groups
228 .flatMap((group): readonly Member[] =>229 answerGroups.some((answer) => answer === group.name) ? group.members : []230 )

Merge build/1108 into mainoscabrielbefore adoption8d9ece9

line 231why, one step back
231 .map((member) => rowOf(member, repairOf));

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 232why, one step back
232

Merge build/1108 into mainoscabrielbefore adoption8d9ece9

lines 233–243why, one step back
233export interface CatalogRow extends AnswerRefusal {
234 readonly group: string;235}236237export const refusalCatalog = (): readonly CatalogRow[] =>238 groups.flatMap((group) =>239 group.members.map((member: Member) => ({240 ...rowOf(member, everyRepairOf),241 group: group.name,242 }))243 );

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 244why, one step back
244

Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862

lines 245–273why, one step back
245const exitMeanings = {
246 [ExitCode.ok]: "It did what it was asked.",247 [ExitCode.failed]: "Something else went wrong; stderr says what.",248 [ExitCode.usage]:249 "The command was misused; stderr names the flag or value, and nothing was sent.",250 [ExitCode.dataErr]:251 "Refused: what you sent has to change (the answer, the ask or the value).",252 [ExitCode.noInput]:253 "Refused: what you named does not exist, or no longer stands open; `next` lists what does.",254 [ExitCode.unavailable]:255 "No platform answered: it is down, or the URL is wrong.",256 [ExitCode.tempFail]:257 "Refused for now: run the refusal's `next`, then try the same thing again.",258 [ExitCode.noPerm]:259 "Refused: you may not do this until you sign in, or someone lets you in.",260} as const satisfies Record<ExitCode, string>;261262export const exitCodeSection = () => [263 "## Exit codes",264 "",265 `${code(Brand.cli)} exits with a code from sysexits(3), so a script or an agent can tell what to do next without reading stderr. A refusal's code follows from its \`retryable\`: 75 when trying again can help, else the code for what has to change, as the Refusals table lists it. A command that meets several refusals at once exits with the first of ${precedence.map(String).join(", ")} among them.`,266 "",267 ...table(268 ["Exit code", "Means"],269 Object.entries(exitMeanings).map(([exit, means]) => [exit, means])270 ),271 "",272];273

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 274–276why, one step back
274export const refusalSection = () => [
275 "## Refusals",276 "",

Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862

line 277why, one step back
277 `Instead of landing an answer, the platform answers with refusals. Git prints them on its \`remote:\` lines, \`${cli("check")}\` and \`${cli("status")}\` print them, and the verdict note holds them as JSON. Each one has a \`_tag\`, \`retryable\` (whether trying the same thing again can help) and \`next\` (the command to run next). The refusals about an answer's files arrive together, so one push hears about all of them. The CLI exits with a refusal's code: 75 when trying again can help, and 65, 66 or 77 when something has to change first.`,

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 278–279why, one step back
278 "",
279 ...table(

Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862

lines 280–281why, one step back
280 ["`_tag`", "Retryable", "Exit code", "`next`", "What to do"],
281 answerRefusals.map(({ exitCode, next, retryable, tag, todo }) => [

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 282–283why, one step back
282 code(tag),
283 retryable ? "yes" : "no",

Merge cli/exit-codes into mainoscabrielbefore adoptionc19a862

line 284why, one step back
284 String(exitCode),

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 285–290why, one step back
285 next,
286 todo,287 ])288 ),289 "",290];