Skip to content
Myr

code.ts

This file

Path

packages/protocol/src/domain/code.ts

234 lines · 6.1 KiB · TypeScript

Last changed by

Merge redesign into mainoscabrielbefore adoptioncaedd21

History of this file

Take it

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

line 1why, one step back
1// Read from the project's canonical repo only: no payload names a repo.

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 2why, one step back
2import { Data, Option, Schema } from "effect";

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 3–6why, one step back
3
4import {5 AskId,6 BlobSha,

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 7why, one step back
7 BranchName,

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 8–23why, one step back
8 CommitSha,
9 Handle,10 LandedSha,11 ProjectName,12 RepoName,13 RepoPath,14 TreeSha,15} from "../ids.ts";16import { ClaimState } from "./claim.ts";17import { LandingView } from "./landing.ts";1819export const TagName = Schema.NonEmptyString.check(20 Schema.isMaxLength(255)21).pipe(Schema.brand("TagName"));2223export type TagName = typeof TagName.Type;

Close the wave: openings are heard as landings, and the code store is written downoscabrielbefore adoption2587726

lines 24–29why, one step back
24
25export const packageOf = (tag: string): Option.Option<string> => {26 const at = tag.lastIndexOf("@");2728 return at > 0 ? Option.some(tag.slice(0, at)) : Option.none();29};

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 30–36why, one step back
30
31export const Rev = Schema.String.check(32 Schema.isMinLength(1),33 Schema.isMaxLength(255)34);3536export type Rev = typeof Rev.Type;

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 37–107why, one step back
37
38/** Where in a fork an address points: a branch by its exact name, or a commit the fork holds. */39export type ForkPoint = Data.TaggedEnum<{40 Branch: { readonly name: BranchName };41 Commit: { readonly sha: CommitSha };42}>;4344export const ForkPoint = Data.taggedEnum<ForkPoint>();4546/**47 * An answer fork named by its claimant and ask (ADR 0043), never by its repo:48 * the platform finds it among the project's listed forks.49 */50export interface ForkAddress {51 readonly ask: AskId;52 readonly handle: Handle;53 readonly point: ForkPoint;54}5556const FORK = /^@(?<handle>[^/:]+)\/(?<ask>[^/:]+)(?::(?<point>.*))?$/u;5758const FULL_SHA = /^[0-9a-f]{40}$/u;5960const decodeHandle = Schema.decodeUnknownOption(Handle);6162const decodeAsk = Schema.decodeUnknownOption(AskId);6364const decodeBranch = Schema.decodeUnknownOption(BranchName);6566const pointOf = (text: string | undefined): Option.Option<ForkPoint> => {67 if (text === undefined) {68 return Option.some(ForkPoint.Branch({ name: BranchName.make("main") }));69 }7071 if (FULL_SHA.test(text)) {72 return Option.some(ForkPoint.Commit({ sha: CommitSha.make(text) }));73 }7475 return Option.map(decodeBranch(text), (name) => ForkPoint.Branch({ name }));76};7778/**79 * `@<handle>/<ask>` is the fork's `main`; `@<handle>/<ask>:<branch>` a branch80 * matched by its exact name, and `@<handle>/<ask>:<sha>` a full commit id the81 * fork holds. A closed parse: each part is decoded as its own schema, and82 * nothing read here is ever joined into a ref path.83 */84export const forkAddressOf = (rev: string): Option.Option<ForkAddress> => {85 const groups = FORK.exec(rev)?.groups;8687 if (groups === undefined) {88 return Option.none();89 }9091 const { ask, handle, point } = groups;9293 return Option.all({94 ask: decodeAsk(ask),95 handle: decodeHandle(handle),96 point: pointOf(point),97 });98};99100/** The revision that names a fork's branch (its `main` when absent) or one of its commits. */101export const forkRev = (102 fork: { readonly ask: AskId; readonly handle: Handle },103 point?: string104): Rev =>105 point === undefined || point === "main"106 ? `@${fork.handle}/${fork.ask}`107 : `@${fork.handle}/${fork.ask}:${point}`;

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 108–178why, one step back
108
109export const TagRef = Schema.Struct({ name: TagName, sha: CommitSha });110111export type TagRef = typeof TagRef.Type;112113export const ForkRef = Schema.Struct({114 ask: Schema.optionalKey(AskId),115 handle: Handle,116 kind: Schema.Literals(["claim", "working"]),117 repo: RepoName,118 state: Schema.optionalKey(ClaimState),119});120121export type ForkRef = typeof ForkRef.Type;122123export const RefsView = Schema.Struct({124 forks: Schema.Array(ForkRef),125 landed: Schema.optionalKey(LandedSha),126 project: ProjectName,127 tags: Schema.Array(TagRef),128});129130export type RefsView = typeof RefsView.Type;131132export const CodeEntry = Schema.Struct({133 mode: Schema.String,134 name: Schema.NonEmptyString,135 path: RepoPath,136 sha: Schema.String,137 type: Schema.Literals(["blob", "tree", "submodule", "symlink"]),138});139140export type CodeEntry = typeof CodeEntry.Type;141142export const TreeListing = Schema.Struct({143 at: CommitSha,144 entries: Schema.Array(CodeEntry),145 path: Schema.optionalKey(RepoPath),146 readme: Schema.optionalKey(Schema.Struct({ path: RepoPath, sha: BlobSha })),147});148149export type TreeListing = typeof TreeListing.Type;150151export const PathList = Schema.Struct({152 at: CommitSha,153 paths: Schema.Array(RepoPath),154 truncated: Schema.Boolean,155});156157export type PathList = typeof PathList.Type;158159export const FileView = Schema.Struct({160 at: CommitSha,161 binary: Schema.Boolean,162 path: RepoPath,163 sha: BlobSha,164 size: Schema.Int,165 text: Schema.optionalKey(Schema.String),166 truncated: Schema.Boolean,167});168169export type FileView = typeof FileView.Type;170171export const Signature = Schema.Struct({172 at: Schema.DateTimeUtcFromString,173 email: Schema.String,174 name: Schema.String,175});176177export type Signature = typeof Signature.Type;178

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

line 179why, one step back
179/** `landing` is the platform's own record: a trailer in an imported commit never makes one. */

Add the code-browser, policy and drafting contracts, peeled tags and commit times on the port, and the AI bindingoscabrielbefore adoptionfc4691d

lines 180–234why, one step back
180export const CommitView = Schema.Struct({
181 author: Signature,182 body: Schema.String,183 committer: Signature,184 landing: Schema.optionalKey(LandingView),185 parents: Schema.Array(CommitSha),186 sha: CommitSha,187 subject: Schema.String,188 trailers: Schema.Array(189 Schema.Struct({ key: Schema.String, value: Schema.String })190 ),191 tree: TreeSha,192});193194export type CommitView = typeof CommitView.Type;195196export const ChangedFile = Schema.Struct({197 after: Schema.optionalKey(BlobSha),198 before: Schema.optionalKey(BlobSha),199 binary: Schema.Boolean,200 newText: Schema.optionalKey(Schema.String),201 oldText: Schema.optionalKey(Schema.String),202 path: RepoPath,203 status: Schema.Literals(["added", "modified", "deleted"]),204});205206export type ChangedFile = typeof ChangedFile.Type;207208export const CommitDiff = Schema.Struct({209 commit: CommitView,210 files: Schema.Array(ChangedFile),211 truncated: Schema.Boolean,212});213214export type CommitDiff = typeof CommitDiff.Type;215216/** Lines `start` to `end` (1-based, inclusive) came in with commit `sha`. */217export const WhyRange = Schema.Struct({218 end: Schema.Int,219 sha: CommitSha,220 start: Schema.Int,221});222223export type WhyRange = typeof WhyRange.Type;224225export const WhyView = Schema.Struct({226 at: CommitSha,227 commits: Schema.Array(CommitView),228 landings: Schema.Array(LandingView),229 path: RepoPath,230 ranges: Schema.Array(WhyRange),231 stoppedAt: Schema.optionalKey(CommitSha),232});233234export type WhyView = typeof WhyView.Type;