contracts.ts
This file
Path
packages/protocol/src/contracts.ts
1,100 lines · 31.6 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
1import { Context, Schema } from "effect";2import { Rpc, RpcGroup, RpcSchema } from "effect/rpc";3import type { RpcClient, RpcClientError } from "effect/rpc";45import {6 Audience,7 Cli,8 Description,9 Destructive,10 Idempotent,11 NeedsApproval,12 ReadOnly,13 SurfaceName,14 Surfaces,15 Visibility,16} from "./annotations.ts";17import {18 AnswerReceipt,19 AnswerView,20 LandReceipt,21 Verdict,22} from "./domain/answer.ts";23import { Ask, AskListing, Reserve } from "./domain/ask.ts";24import { ClaimView } from "./domain/claim.ts";25import {26 CommitDiff,27 CommitView,28 PathList,29 RefsView,30 Rev,31 FileView,32 TreeListing,33 WhyView,34} from "./domain/code.ts";35import { ConfigFile, NoneOrMore } from "./domain/common.ts";36import { Choice, Decision, Today } from "./domain/decision.ts";37import { EnvSchemaView } from "./domain/env.ts";38import { ProjectEvent } from "./domain/event.ts";39import { FrontPageEntry, ProjectListing } from "./domain/front-page.ts";40import { LandingView } from "./domain/landing.ts";41import { ImportSource, PolicyPending, PublicPolicy } from "./domain/policy.ts";42import { DraftNote, Proposal } from "./domain/proposal.ts";43import { RecentLandings } from "./domain/recent-landing.ts";44import { CreditSummary } from "./domain/record.ts";45import { Ledger } from "./domain/visibility.ts";46import {47 AskId,48 CommitSha,49 DecisionId,50 EnvKey,51 Handle,52 KindName,53 LandedSha,54 LaneName,55 ProjectName,56 ProposalId,57 RepoName,58 RepoPath,59 RequestId,60} from "./ids.ts";61import { Authenticated } from "./principal.ts";62import {63 AskBlocked,64 AskFull,65 CapReached,66 ClaimLapsed,67 DecisionClosed,68 Denounced,69 DraftInProgress,70 ImportFailed,71 NotYourNamespace,72 IncompleteBrief,73 NotClaimed,74 NotDecider,75 NotRedFirst,76 NotSensitive,77 NotVouched,78 OutOfScope,79 PrivatePathInPublicTree,80 ProjectExists,81 ProposalClosed,82 ReachedInternals,83 RepoBusy,84 StaleBase,85 TouchedJudge,86 UnknownAsk,87 UnknownCommit,88 UnknownDecision,89 UnknownEnvItem,90 UnknownPath,91 UnknownProject,92 UnknownProposal,93 UnknownRevision,94 ValueTooShort,95 VerifierBlocked,96 WeakCheck,97 Weakened,98} from "./refusal.ts";99100export {101 Audience,102 Cli,103 Description,104 Destructive,105 Idempotent,106 NeedsApproval,107 ReadOnly,108 SurfaceName,109 Surfaces,110 Visibility,111} from "./annotations.ts";112113// Lint keeps "shape" out of code names, so the tag is spelled once, here.114const envSchemaTag = "envShape";115116const servedOn = {117 claim: ["rpc", "mcp", "cli"],118 credits: SurfaceName.literals,119 decide: SurfaceName.literals,120 draftAsk: SurfaceName.literals,121 [envSchemaTag]: SurfaceName.literals,122 // A log may hold text an agent's transcript should not carry: never MCP.123 evidence: ["rpc", "cli"],124 finish: ["rpc", "mcp", "cli"],125 flagAsk: ["rpc", "mcp", "cli"],126 fork: ["rpc", "mcp", "cli"],127 frontPage: SurfaceName.literals,128 initProject: ["rpc", "mcp", "cli", "web"],129 land: ["rpc", "mcp", "cli"],130 landing: SurfaceName.literals,131 ledger: SurfaceName.literals,132 listAsks: SurfaceName.literals,133 // A commit's diff and every path stay off MCP: no cap fits a transcript.134 // No command: git reads code locally.135 listPaths: ["rpc", "web"],136 listProjects: SurfaceName.literals,137 listRefs: ["rpc", "mcp", "web"],138 log: ["rpc", "mcp", "web"],139 openAsk: ["rpc", "mcp", "cli"],140 projectPolicy: SurfaceName.literals,141 proposeAsk: SurfaceName.literals,142 readFile: ["rpc", "mcp", "web"],143 readTree: ["rpc", "mcp", "web"],144 // A list with no command: an agent asks it over MCP, a person reads it on the landing.145 recentLandings: ["rpc", "mcp", "web"],146 release: ["rpc", "mcp", "cli"],147 // A value must never pass through an agent's transcript, so never MCP.148 setEnv: ["rpc", "cli"],149 showAsk: SurfaceName.literals,150 showCommit: ["rpc", "web"],151 showProposal: SurfaceName.literals,152 status: SurfaceName.literals,153 submitAnswer: ["rpc", "mcp", "cli"],154 today: SurfaceName.literals,155 verdict: SurfaceName.literals,156 vouch: ["rpc", "mcp", "cli"],157 watch: ["rpc", "web"],158 why: ["rpc", "mcp", "web"],159} as const satisfies Record<string, readonly SurfaceName[]>;160161// An empty `Schema.Struct` has no object root in JSON Schema, which an MCP162// tool's input needs; this is the form `Tool.EmptyParams` takes.163const NoPayload = Schema.Record(Schema.String, Schema.Never);164165export class ListProjects extends Rpc.make("listProjects", {166 payload: NoPayload,167 success: Schema.Struct({ projects: Schema.Array(ProjectListing) }),168})169 .annotate(170 Description,171 "List every project on the platform, with its posture and how many asks it has open."172 )173 .annotate(Audience, "public")174 .annotate(Visibility, "public")175 .annotate(ReadOnly, true)176 .annotate(Idempotent, true)177 .annotate(Destructive, false)178 .annotate(NeedsApproval, false)179 .annotate(Cli, { name: "projects" })180 .annotate(Surfaces, servedOn.listProjects) {}181182export class RecentLandingsOf extends Rpc.make("recentLandings", {183 payload: NoPayload,184 success: Schema.Struct({ landings: RecentLandings }),185})186 .annotate(187 Description,188 "List the latest landings across every project, and the answers the gate refused, the latest first: when, the project, the ask and its want, and each refusal's tag and area."189 )190 .annotate(Audience, "public")191 .annotate(Visibility, "public")192 .annotate(ReadOnly, true)193 .annotate(Idempotent, true)194 .annotate(Destructive, false)195 .annotate(NeedsApproval, false)196 .annotate(Surfaces, servedOn.recentLandings) {}197198export class FrontPage extends Rpc.make("frontPage", {199 payload: {200 kind: Schema.optionalKey(KindName),201 reserved: Schema.optionalKey(Reserve),202 },203 success: Schema.Struct({ entries: Schema.Array(FrontPageEntry) }),204})205 .annotate(206 Description,207 "List the open asks across every project, each saying whether the caller may take it; optionally of one kind, or held for newcomers or people."208 )209 .annotate(Audience, "public")210 .annotate(Visibility, "public")211 .annotate(ReadOnly, true)212 .annotate(Idempotent, true)213 .annotate(Destructive, false)214 .annotate(NeedsApproval, false)215 .annotate(Cli, { name: "front" })216 .annotate(Surfaces, servedOn.frontPage) {}217218export class ListAsks extends Rpc.make("listAsks", {219 error: UnknownProject,220 payload: { project: ProjectName },221 success: Schema.Struct({ asks: Schema.Array(AskListing) }),222})223 .annotate(Description, "List a project's open asks.")224 .annotate(Audience, "public")225 .annotate(Visibility, "public")226 .annotate(ReadOnly, true)227 .annotate(Idempotent, true)228 .annotate(Destructive, false)229 .annotate(NeedsApproval, false)230 .annotate(Cli, { name: "asks" })231 .annotate(Surfaces, servedOn.listAsks) {}232233export class ShowAsk extends Rpc.make("showAsk", {234 error: Schema.Union([UnknownProject, UnknownAsk]),235 payload: { ask: AskId, project: ProjectName },236 success: Schema.Struct({237 ask: Ask,238 brief: Schema.NonEmptyString,239 }),240})241 .annotate(242 Description,243 "Show one ask in full, with its brief in Markdown for an answerer to read first."244 )245 .annotate(Audience, "public")246 .annotate(Visibility, "public")247 .annotate(ReadOnly, true)248 .annotate(Idempotent, true)249 .annotate(Destructive, false)250 .annotate(NeedsApproval, false)251 .annotate(Cli, { name: "ask", positional: ["ask"] })252 .annotate(Surfaces, servedOn.showAsk) {}253254export class Status extends Rpc.make("status", {255 error: UnknownProject,256 payload: { project: Schema.optionalKey(ProjectName) },257 success: Schema.Struct({258 answers: Schema.Array(AnswerView),259 claims: Schema.Array(ClaimView),260 handle: Handle,261 }),262})263 .annotate(264 Description,265 "Show who the caller is, and their claims and answers, in one project or in every one."266 )267 .annotate(Audience, "signedIn")268 .annotate(Visibility, "public")269 .annotate(ReadOnly, true)270 .annotate(Idempotent, true)271 .annotate(Destructive, false)272 .annotate(NeedsApproval, false)273 .annotate(Cli, { name: "status" })274 .annotate(Surfaces, servedOn.status) {}275276export class VerdictOf extends Rpc.make("verdict", {277 error: Schema.Union([UnknownProject, UnknownAsk]),278 payload: {279 ask: AskId,280 /** The answer's head; its latest when absent. */281 head: Schema.optionalKey(CommitSha),282 project: ProjectName,283 },284 success: Schema.Struct({ verdict: Schema.optionalKey(Verdict) }),285})286 .annotate(287 Description,288 "Show the verdict on an answer to an ask, for its latest head or the one named; held-back checks show one bit per area."289 )290 .annotate(Audience, "public")291 .annotate(Visibility, "public")292 .annotate(ReadOnly, true)293 .annotate(Idempotent, true)294 .annotate(Destructive, false)295 .annotate(NeedsApproval, false)296 .annotate(Cli, { formerFlags: ["ask"], name: "verdict", positional: ["ask"] })297 .annotate(Surfaces, servedOn.verdict) {}298299export class LandingOf extends Rpc.make("landing", {300 error: Schema.Union([UnknownProject, UnknownCommit]),301 payload: { project: ProjectName, sha: CommitSha },302 success: Schema.Struct({ landing: LandingView }),303})304 .annotate(305 Description,306 "Show one landing on a project's main: the ask it answered, the people it credits and its verdict."307 )308 .annotate(Audience, "public")309 .annotate(Visibility, "public")310 .annotate(ReadOnly, true)311 .annotate(Idempotent, true)312 .annotate(Destructive, false)313 .annotate(NeedsApproval, false)314 .annotate(Cli, { name: "landing" })315 .annotate(Surfaces, servedOn.landing) {}316317export class Credits extends Rpc.make("credits", {318 payload: { handle: Handle },319 success: Schema.Struct({ credits: Schema.Array(CreditSummary) }),320})321 .annotate(322 Description,323 "Count a person's credits by project, area and role; never a score."324 )325 .annotate(Audience, "public")326 .annotate(Visibility, "public")327 .annotate(ReadOnly, true)328 .annotate(Idempotent, true)329 .annotate(Destructive, false)330 .annotate(NeedsApproval, false)331 .annotate(Cli, { name: "credits" })332 .annotate(Surfaces, servedOn.credits) {}333334export class TodayOf extends Rpc.make("today", {335 error: Schema.Union([NotDecider, UnknownProject]),336 payload: { project: Schema.optionalKey(ProjectName) },337 success: Today,338})339 .annotate(340 Description,341 "Show the caller's Today: the decisions to take, held to their budget, each with its evidence and a safe default."342 )343 .annotate(Audience, "decider")344 .annotate(Visibility, "maintainers")345 .annotate(ReadOnly, true)346 .annotate(Idempotent, true)347 .annotate(Destructive, false)348 .annotate(NeedsApproval, false)349 .annotate(Cli, { name: "today" })350 .annotate(Surfaces, servedOn.today) {}351352export class LedgerOf extends Rpc.make("ledger", {353 error: UnknownProject,354 payload: { project: ProjectName },355 success: Ledger,356})357 .annotate(358 Description,359 "Show a project's ledger: its layers, counts, commitments, releases and posture changes."360 )361 .annotate(Audience, "public")362 .annotate(Visibility, "public")363 .annotate(ReadOnly, true)364 .annotate(Idempotent, true)365 .annotate(Destructive, false)366 .annotate(NeedsApproval, false)367 .annotate(Cli, { name: "ledger" })368 .annotate(Surfaces, servedOn.ledger) {}369370export class EnvSchemaOf extends Rpc.make(envSchemaTag, {371 error: UnknownProject,372 payload: { project: ProjectName },373 success: EnvSchemaView,374})375 .annotate(376 Description,377 "Show a project's env shape: the public schema of its environment variables, and who set each write-only value; never a value."378 )379 .annotate(Audience, "public")380 .annotate(Visibility, "public")381 .annotate(ReadOnly, true)382 .annotate(Idempotent, true)383 .annotate(Destructive, false)384 .annotate(NeedsApproval, false)385 .annotate(Cli, { name: "env shape" })386 .annotate(Surfaces, servedOn[envSchemaTag]) {}387388export class Watch extends Rpc.make("watch", {389 error: UnknownProject,390 payload: {391 project: ProjectName,392 since: Schema.optionalKey(Schema.Int),393 },394 stream: true,395 success: ProjectEvent,396})397 .annotate(398 Description,399 "Stream what happens in a project as it happens, replaying from a sequence number when given one."400 )401 .annotate(Audience, "public")402 .annotate(Visibility, "public")403 .annotate(ReadOnly, true)404 .annotate(Idempotent, false)405 .annotate(Destructive, false)406 .annotate(NeedsApproval, false)407 .annotate(Surfaces, servedOn.watch) {}408409export class ListRefs extends Rpc.make("listRefs", {410 error: UnknownProject,411 payload: { project: ProjectName },412 success: RefsView,413})414 .annotate(415 Description,416 "List a project's refs: main's landed commit, its tags peeled to their commits, and its forks."417 )418 .annotate(Audience, "public")419 .annotate(Visibility, "public")420 .annotate(ReadOnly, true)421 .annotate(Idempotent, true)422 .annotate(Destructive, false)423 .annotate(NeedsApproval, false)424 .annotate(Surfaces, servedOn.listRefs) {}425426export class ReadTree extends Rpc.make("readTree", {427 error: Schema.Union([UnknownProject, UnknownRevision, UnknownPath]),428 payload: {429 /** `main`, a commit, a tag or a fork's address (`@<handle>/<ask>`); main's landed commit when absent. */430 at: Schema.optionalKey(Rev),431 path: Schema.optionalKey(RepoPath),432 project: ProjectName,433 },434 success: TreeListing,435})436 .annotate(437 Description,438 "List one folder of a project at a revision, folders first, with its README when it has one."439 )440 .annotate(Audience, "public")441 .annotate(Visibility, "public")442 .annotate(ReadOnly, true)443 .annotate(Idempotent, true)444 .annotate(Destructive, false)445 .annotate(NeedsApproval, false)446 .annotate(Surfaces, servedOn.readTree) {}447448export class ListPaths extends Rpc.make("listPaths", {449 error: Schema.Union([UnknownProject, UnknownRevision]),450 payload: { at: Schema.optionalKey(Rev), project: ProjectName },451 success: PathList,452})453 .annotate(454 Description,455 "List every file path in a project at a revision, up to a cap."456 )457 .annotate(Audience, "public")458 .annotate(Visibility, "public")459 .annotate(ReadOnly, true)460 .annotate(Idempotent, true)461 .annotate(Destructive, false)462 .annotate(NeedsApproval, false)463 .annotate(Surfaces, servedOn.listPaths) {}464465export class ReadFile extends Rpc.make("readFile", {466 error: Schema.Union([UnknownProject, UnknownRevision, UnknownPath]),467 payload: {468 at: Schema.optionalKey(Rev),469 path: RepoPath,470 project: ProjectName,471 },472 success: FileView,473})474 .annotate(475 Description,476 "Read one file of a project at a revision: its text, or that it is binary or too large to show."477 )478 .annotate(Audience, "public")479 .annotate(Visibility, "public")480 .annotate(ReadOnly, true)481 .annotate(Idempotent, true)482 .annotate(Destructive, false)483 .annotate(NeedsApproval, false)484 .annotate(Surfaces, servedOn.readFile) {}485486export class LogOf extends Rpc.make("log", {487 error: Schema.Union([UnknownProject, UnknownRevision]),488 payload: {489 at: Schema.optionalKey(Rev),490 from: Schema.optionalKey(NoneOrMore),491 /** 30 when absent. */492 limit: Schema.optionalKey(493 Schema.Int.check(Schema.isBetween({ maximum: 100, minimum: 1 }))494 ),495 path: Schema.optionalKey(RepoPath),496 project: ProjectName,497 },498 success: Schema.Struct({499 commits: Schema.Array(CommitView),500 /** Where the next page starts; absent on the last. */501 next: Schema.optionalKey(NoneOrMore),502 }),503})504 .annotate(505 Description,506 "List a project's commits along first parents from a revision, newest first, each landing with its ask, people and verdict."507 )508 .annotate(Audience, "public")509 .annotate(Visibility, "public")510 .annotate(ReadOnly, true)511 .annotate(Idempotent, true)512 .annotate(Destructive, false)513 .annotate(NeedsApproval, false)514 .annotate(Surfaces, servedOn.log) {}515516export class ShowCommit extends Rpc.make("showCommit", {517 error: Schema.Union([UnknownProject, UnknownCommit, UnknownRevision]),518 payload: {519 /** A fork's address, to read the commit in that fork; the project's own commits when absent. */520 at: Schema.optionalKey(Rev),521 project: ProjectName,522 sha: CommitSha,523 },524 success: CommitDiff,525})526 .annotate(527 Description,528 "Show one commit of a project and the files it changed against its first parent."529 )530 .annotate(Audience, "public")531 .annotate(Visibility, "public")532 .annotate(ReadOnly, true)533 .annotate(Idempotent, true)534 .annotate(Destructive, false)535 .annotate(NeedsApproval, false)536 .annotate(Surfaces, servedOn.showCommit) {}537538export class WhyOf extends Rpc.make("why", {539 error: Schema.Union([UnknownProject, UnknownRevision, UnknownPath]),540 payload: {541 at: Schema.optionalKey(Rev),542 path: RepoPath,543 project: ProjectName,544 },545 success: WhyView,546})547 .annotate(548 Description,549 "Say why each line of a file is there: the commit that brought it, and the landing, ask and people behind that commit."550 )551 .annotate(Audience, "public")552 .annotate(Visibility, "public")553 .annotate(ReadOnly, true)554 .annotate(Idempotent, true)555 .annotate(Destructive, false)556 .annotate(NeedsApproval, false)557 .annotate(Surfaces, servedOn.why) {}558559export class PolicyOf extends Rpc.make("projectPolicy", {560 error: UnknownProject,561 payload: { project: ProjectName },562 success: Schema.Struct({563 importedFrom: Schema.optionalKey(ImportSource),564 policy: Schema.optionalKey(PublicPolicy),565 unevaluated: Schema.optionalKey(PolicyPending),566 }),567})568 .annotate(569 Description,570 "Show a project's evaluated config folder at its landed commit: who decides which paths, its vouches, caps, budget and claim timing; for an import, its source."571 )572 .annotate(Audience, "public")573 .annotate(Visibility, "public")574 .annotate(ReadOnly, true)575 .annotate(Idempotent, true)576 .annotate(Destructive, false)577 .annotate(NeedsApproval, false)578 .annotate(Cli, { name: "policy" })579 .annotate(Surfaces, servedOn.projectPolicy) {}580581export class ShowProposal extends Rpc.make("showProposal", {582 error: Schema.Union([UnknownProject, UnknownProposal]),583 payload: { project: ProjectName, proposal: ProposalId },584 success: Schema.Struct({585 files: Schema.Array(ConfigFile),586 proposal: Proposal,587 }),588})589 .annotate(590 Description,591 "Show one proposal, its draft's state and the ask files it holds."592 )593 .annotate(Audience, "public")594 .annotate(Visibility, "public")595 .annotate(ReadOnly, true)596 .annotate(Idempotent, true)597 .annotate(Destructive, false)598 .annotate(NeedsApproval, false)599 .annotate(Cli, { name: "proposal", positional: ["proposal"] })600 .annotate(Surfaces, servedOn.showProposal) {}601602export class InitProject extends Rpc.make("initProject", {603 error: Schema.Union([ProjectExists, NotYourNamespace, ImportFailed]),604 payload: {605 import: Schema.optionalKey(ImportSource),606 project: ProjectName,607 },608 success: Schema.Struct({609 landed: Schema.optionalKey(LandedSha),610 project: ProjectName,611 remote: Schema.NonEmptyString,612 }),613})614 .annotate(615 Description,616 "Make a project, empty or imported from a public git repo, with the caller as its maintainer."617 )618 .annotate(Audience, "signedIn")619 .annotate(Visibility, "public")620 .annotate(ReadOnly, false)621 .annotate(Idempotent, false)622 .annotate(Destructive, false)623 .annotate(NeedsApproval, true)624 .annotate(Cli, { name: "init" })625 .annotate(Surfaces, servedOn.initProject) {}626627export class OpenAsk extends Rpc.make("openAsk", {628 error: Schema.Union([629 UnknownProject,630 NotDecider,631 NotRedFirst,632 WeakCheck,633 IncompleteBrief,634 TouchedJudge,635 VerifierBlocked,636 StaleBase,637 ]),638 payload: {639 ask: AskId,640 files: Schema.NonEmptyArray(ConfigFile),641 project: ProjectName,642 },643 success: Schema.Struct({ ask: Ask, landed: LandedSha }),644})645 .annotate(646 Description,647 "Open an ask by landing its file, once its check fails on main by an assertion, twice in the same way."648 )649 .annotate(Audience, "decider")650 .annotate(Visibility, "public")651 .annotate(ReadOnly, false)652 .annotate(Idempotent, false)653 .annotate(Destructive, false)654 .annotate(NeedsApproval, true)655 .annotate(Cli, { name: "ask open", positional: ["ask"] })656 .annotate(Surfaces, servedOn.openAsk) {}657658const draftsAlone = Schema.makeFilter(659 (payload: {660 readonly draft?: true;661 readonly files?: unknown;662 readonly sealed?: unknown;663 }) =>664 payload.draft === undefined ||665 (payload.files === undefined && payload.sealed === undefined)666 ? true667 : "a drafted proposal carries neither files nor a sealed answer"668);669670export class ProposeAsk extends Rpc.make("proposeAsk", {671 error: Schema.Union([UnknownProject, Denounced, CapReached, NotVouched]),672 payload: Schema.Struct({673 draft: Schema.optionalKey(Schema.Literal(true)),674 files: Schema.optionalKey(Schema.NonEmptyArray(ConfigFile)),675 project: ProjectName,676 sealed: Schema.optionalKey(Schema.Struct({ head: CommitSha })),677 territory: Schema.optionalKey(Schema.NonEmptyString),678 want: Schema.NonEmptyString,679 }).check(draftsAlone),680 success: Schema.Struct({ proposal: Proposal }),681})682 .annotate(683 Description,684 "Propose an ask, optionally with a sealed answer; the proposal expires unless a maintainer accepts it."685 )686 .annotate(Audience, "signedIn")687 .annotate(Visibility, "public")688 .annotate(ReadOnly, false)689 .annotate(Idempotent, false)690 .annotate(Destructive, false)691 .annotate(NeedsApproval, false)692 .annotate(Cli, { name: "propose" })693 .annotate(Surfaces, servedOn.proposeAsk) {}694695export class DraftAsk extends Rpc.make("draftAsk", {696 error: Schema.Union([697 UnknownProject,698 UnknownProposal,699 ProposalClosed,700 NotDecider,701 DraftInProgress,702 CapReached,703 ]),704 payload: {705 note: Schema.optionalKey(DraftNote),706 project: ProjectName,707 proposal: ProposalId,708 },709 success: Schema.Struct({ proposal: Proposal }),710})711 .annotate(712 Description,713 "Have the platform's agent draft, or draft again, an open proposal's ask and its failing check; the proposer or a maintainer may ask."714 )715 .annotate(Audience, "signedIn")716 .annotate(Visibility, "public")717 .annotate(ReadOnly, false)718 .annotate(Idempotent, false)719 .annotate(Destructive, false)720 .annotate(NeedsApproval, false)721 .annotate(Cli, { name: "ask draft", positional: ["proposal"] })722 .annotate(Surfaces, servedOn.draftAsk) {}723724export class FlagAsk extends Rpc.make("flagAsk", {725 error: Schema.Union([UnknownProject, UnknownAsk, Denounced, CapReached]),726 payload: {727 ask: AskId,728 project: ProjectName,729 reason: Schema.NonEmptyString,730 },731 success: Schema.Struct({ proposal: Proposal }),732})733 .annotate(734 Description,735 "Flag an open ask to its maintainers with a reason, as a proposal that expires unless a maintainer accepts it."736 )737 .annotate(Audience, "signedIn")738 .annotate(Visibility, "public")739 .annotate(ReadOnly, false)740 .annotate(Idempotent, false)741 .annotate(Destructive, false)742 .annotate(NeedsApproval, false)743 .annotate(Cli, { name: "ask flag", positional: ["ask"] })744 .annotate(Surfaces, servedOn.flagAsk) {}745746export class Decide extends Rpc.make("decide", {747 error: Schema.Union([748 UnknownProject,749 UnknownDecision,750 DecisionClosed,751 NotDecider,752 VerifierBlocked,753 StaleBase,754 ]),755 payload: {756 choice: Choice,757 decision: DecisionId,758 note: Schema.optionalKey(Schema.String),759 project: ProjectName,760 },761 success: Schema.Struct({ decision: Decision }),762})763 .annotate(764 Description,765 "Take one decision from Today: accept, decline, adopt or revert."766 )767 .annotate(Audience, "decider")768 .annotate(Visibility, "maintainers")769 .annotate(ReadOnly, false)770 .annotate(Idempotent, false)771 .annotate(Destructive, false)772 .annotate(NeedsApproval, true)773 .annotate(Cli, { name: "decide" })774 .annotate(Surfaces, servedOn.decide) {}775776export class Claim extends Rpc.make("claim", {777 error: Schema.Union([778 UnknownProject,779 UnknownAsk,780 AskFull,781 AskBlocked,782 CapReached,783 NotVouched,784 Denounced,785 ]),786 payload: { ask: AskId, project: ProjectName },787 success: Schema.Struct({ claim: ClaimView }),788})789 .annotate(790 Description,791 "Claim an ask: an exclusive, expiring right to answer it, with a fork to push to; claiming it again returns the same claim."792 )793 .annotate(Audience, "signedIn")794 .annotate(Visibility, "public")795 .annotate(ReadOnly, false)796 .annotate(Idempotent, true)797 .annotate(Destructive, false)798 .annotate(NeedsApproval, false)799 .annotate(Cli, { name: "claim", positional: ["ask"] })800 .annotate(Surfaces, servedOn.claim) {}801802export class Release extends Rpc.make("release", {803 error: Schema.Union([UnknownProject, NotClaimed]),804 payload: { ask: AskId, project: ProjectName },805 success: Schema.Struct({ released: Schema.Boolean }),806})807 .annotate(808 Description,809 "Release the caller's claim on an ask, so anyone may claim it again."810 )811 .annotate(Audience, "signedIn")812 .annotate(Visibility, "public")813 .annotate(ReadOnly, false)814 .annotate(Idempotent, true)815 .annotate(Destructive, false)816 .annotate(NeedsApproval, false)817 .annotate(Cli, { formerFlags: ["ask"], name: "release", positional: ["ask"] })818 .annotate(Surfaces, servedOn.release) {}819820export class SubmitAnswer extends Rpc.make("submitAnswer", {821 error: Schema.Union([822 UnknownProject,823 NotClaimed,824 ClaimLapsed,825 StaleBase,826 RepoBusy,827 OutOfScope,828 TouchedJudge,829 Weakened,830 ReachedInternals,831 PrivatePathInPublicTree,832 ]),833 payload: {834 ask: AskId,835 base: CommitSha,836 head: CommitSha,837 project: ProjectName,838 requestId: RequestId,839 },840 success: AnswerReceipt,841})842 .annotate(843 Description,844 "Offer the commit `head`, built on `base`, as an answer to a claimed ask; the receipt says it is being checked, and it lands if it passes."845 )846 .annotate(Audience, "signedIn")847 .annotate(Visibility, "public")848 .annotate(ReadOnly, false)849 .annotate(Idempotent, true)850 .annotate(Destructive, false)851 .annotate(NeedsApproval, false)852 .annotate(Cli, { formerFlags: ["ask"], name: "submit", positional: ["ask"] })853 .annotate(Surfaces, servedOn.submitAnswer) {}854855export class Finish extends Rpc.make("finish", {856 error: Schema.Union([857 UnknownProject,858 NotDecider,859 StaleBase,860 RepoBusy,861 TouchedJudge,862 ]),863 payload: {864 ask: AskId,865 base: CommitSha,866 head: CommitSha,867 project: ProjectName,868 requestId: RequestId,869 },870 success: AnswerReceipt,871})872 .annotate(873 Description,874 "Finish a passing answer with a maintainer's own commits on top; they are checked again, and credited with Finished-by when it lands."875 )876 .annotate(Audience, "decider")877 .annotate(Visibility, "public")878 .annotate(ReadOnly, false)879 .annotate(Idempotent, true)880 .annotate(Destructive, false)881 .annotate(NeedsApproval, true)882 .annotate(Cli, { formerFlags: ["ask"], name: "finish", positional: ["ask"] })883 .annotate(Surfaces, servedOn.finish) {}884885export class Land extends Rpc.make("land", {886 error: Schema.Union([UnknownProject, NotDecider, StaleBase, RepoBusy]),887 payload: {888 base: CommitSha,889 head: CommitSha,890 message: Schema.NonEmptyString,891 project: ProjectName,892 requestId: RequestId,893 },894 success: LandReceipt,895})896 .annotate(897 Description,898 "Land a maintainer's own change from their working fork, after the same checks an answer passes."899 )900 .annotate(Audience, "decider")901 .annotate(Visibility, "public")902 .annotate(ReadOnly, false)903 .annotate(Idempotent, true)904 .annotate(Destructive, false)905 .annotate(NeedsApproval, true)906 .annotate(Cli, { name: "land" })907 .annotate(Surfaces, servedOn.land) {}908909export class Fork extends Rpc.make("fork", {910 error: Schema.Union([UnknownProject, NotVouched, Denounced]),911 payload: { project: ProjectName },912 success: Schema.Struct({913 fork: RepoName,914 remote: Schema.NonEmptyString,915 }),916})917 .annotate(918 Description,919 "Make the caller's working fork of a project, or return it if it exists."920 )921 .annotate(Audience, "signedIn")922 .annotate(Visibility, "public")923 .annotate(ReadOnly, false)924 .annotate(Idempotent, true)925 .annotate(Destructive, false)926 .annotate(NeedsApproval, false)927 .annotate(Cli, { name: "fork" })928 .annotate(Surfaces, servedOn.fork) {}929930export class Vouch extends Rpc.make("vouch", {931 error: Schema.Union([UnknownProject, NotDecider, StaleBase]),932 payload: {933 handle: Handle,934 note: Schema.optionalKey(Schema.String),935 project: ProjectName,936 verdict: Schema.Literals(["vouch", "denounce"]),937 },938 success: Schema.Struct({ landed: LandedSha }),939})940 .annotate(941 Description,942 "Vouch for a person, or denounce them, by landing a line in the project's vouch file."943 )944 .annotate(Audience, "decider")945 .annotate(Visibility, "public")946 .annotate(ReadOnly, false)947 .annotate(Idempotent, false)948 .annotate(Destructive, false)949 .annotate(NeedsApproval, true)950 .annotate(Cli, { name: "vouch" })951 .annotate(Surfaces, servedOn.vouch) {}952953export class EvidenceOf extends Rpc.make("evidence", {954 error: Schema.Union([UnknownProject, NotDecider]),955 payload: {956 project: ProjectName,957 ref: Schema.NonEmptyString,958 },959 success: Schema.Struct({960 lane: LaneName,961 /** The log's tail: its last 256 KiB, where a failure prints. */962 text: Schema.String,963 truncated: Schema.Boolean,964 }),965})966 .annotate(967 Description,968 "Show the log a failing lane left, by the logRef its verdict names, to the answer's own claimant and the project's maintainers only; the last 256 KiB."969 )970 // The handler lets in the answer's claimant and the project's maintainers.971 .annotate(Audience, "signedIn")972 .annotate(Visibility, "maintainers")973 .annotate(ReadOnly, true)974 .annotate(Idempotent, true)975 .annotate(Destructive, false)976 .annotate(NeedsApproval, false)977 .annotate(Cli, { name: "evidence", positional: ["ref"] })978 .annotate(Surfaces, servedOn.evidence) {}979980export class SetEnv extends Rpc.make("setEnv", {981 error: Schema.Union([982 UnknownProject,983 NotDecider,984 UnknownEnvItem,985 NotSensitive,986 ValueTooShort,987 ]),988 payload: {989 acknowledgeShort: Schema.optionalKey(Schema.Boolean),990 key: EnvKey,991 project: ProjectName,992 /** The write-only value: the raw string on the wire, never printed. */993 value: Schema.RedactedFromValue(Schema.String),994 },995 success: Schema.Struct({996 key: EnvKey,997 setAt: Schema.DateTimeUtcFromString,998 setBy: Handle,999 }),1000})1001 .annotate(1002 Description,1003 "Set the write-only value of a sensitive env item; nobody can read it back."1004 )1005 .annotate(Audience, "decider")1006 .annotate(Visibility, "public")1007 .annotate(ReadOnly, false)1008 .annotate(Idempotent, true)1009 .annotate(Destructive, false)1010 .annotate(NeedsApproval, true)1011 .annotate(Cli, { name: "env set" })1012 .annotate(Surfaces, servedOn.setEnv) {}10131014export class Contracts extends RpcGroup.make(1015 ListProjects,1016 RecentLandingsOf,1017 FrontPage,1018 ListAsks,1019 ShowAsk,1020 Status,1021 VerdictOf,1022 LandingOf,1023 Credits,1024 TodayOf,1025 LedgerOf,1026 EnvSchemaOf,1027 Watch,1028 ListRefs,1029 ReadTree,1030 ListPaths,1031 ReadFile,1032 LogOf,1033 ShowCommit,1034 WhyOf,1035 PolicyOf,1036 ShowProposal,1037 InitProject,1038 OpenAsk,1039 ProposeAsk,1040 DraftAsk,1041 FlagAsk,1042 Decide,1043 Claim,1044 Release,1045 SubmitAnswer,1046 Finish,1047 Land,1048 Fork,1049 Vouch,1050 EvidenceOf,1051 SetEnv1052).middleware(Authenticated) {}10531054export type Contract = RpcGroup.Rpcs<typeof Contracts>;10551056type ServedOn = typeof servedOn;10571058export type TagOn<S extends SurfaceName> = {1059 readonly [Tag in keyof ServedOn]: S extends ServedOn[Tag][number]1060 ? Tag1061 : never;1062}[keyof ServedOn];10631064export type ContractOn<S extends SurfaceName> = Extract<1065 Contract,1066 { readonly _tag: TagOn<S> }1067>;10681069const isServedOn =1070 <S extends SurfaceName>(surface: S) =>1071 (rpc: Contract): rpc is ContractOn<S> =>1072 Context.get(rpc.annotations, Surfaces).includes(surface);10731074export const surfaced = <S extends SurfaceName>(1075 surface: S1076): RpcGroup.RpcGroup<ContractOn<S>> =>1077 RpcGroup.make(1078 ...[...Contracts.requests.values()].filter(isServedOn(surface))1079 );10801081export const partsOf = (rpc: Contract) =>1082 RpcSchema.isStreamSchema(rpc.successSchema)1083 ? {1084 error: rpc.successSchema.error,1085 payload: rpc.payloadSchema,1086 success: rpc.successSchema.success,1087 }1088 : {1089 error: rpc.errorSchema,1090 payload: rpc.payloadSchema,1091 success: rpc.successSchema,1092 };10931094export class Client extends Context.Service<1095 Client,1096 RpcClient.RpcClient<1097 RpcGroup.Rpcs<typeof Contracts>,1098 RpcClientError.RpcClientError1099 >1100>()("protocol/Client") {}