Skip to content
Myr

code.ts

This file

Path

packages/project/src/code.ts

132 lines · 4.3 KiB · TypeScript

Last changed by

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

History of this file

Take it

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

lines 1–9why, one step back
1/**
2 * A project's code as its readers browse it, read from its canonical repo3 * only (no payload names a repo, so no fork or layer can be named, principle4 * 7): refs, trees, every path, files, the first-parent log, a commit's diff5 * and why each line is there. Host-free: both the platform's handlers and6 * the web's dev world call these with the `RepoHost` they run on, and7 * consult the project's record only for main's landed commit, its landings8 * and its forks (`CodeProject`). Reads by object id go through `CodeCache`.9 *

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 10–11why, one step back
10 * Each read lives in its own module under `code/`; `whyOf` is a stub until
11 * 912 lands.

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

lines 12–39why, one step back
12 */
13import type { RepoHost } from "@repo/artifacts/repo-host";14import type {15 CommitDiff,16 CommitView,17 ForkRef,18 PathList,19 RefsView,20 Rev,21 FileView,22 TreeListing,23 WhyView,24} from "@repo/protocol/domain/code";25import type { LandingView } from "@repo/protocol/domain/landing";26import { RepoName } from "@repo/protocol/ids";27import type {28 CommitSha,29 LandedSha,30 ProjectName,31 RepoPath,32} from "@repo/protocol/ids";33import type {34 UnknownCommit,35 UnknownPath,36 UnknownRevision,37} from "@repo/protocol/refusal";38import { Effect, Option } from "effect";39

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 40–45why, one step back
40import { commitDiff } from "./code/commit.ts";
41import { fileView } from "./code/file.ts";42import { logPage } from "./code/log.ts";43import { pathList } from "./code/paths.ts";44import { refsView } from "./code/refs.ts";45import { listing } from "./code/tree.ts";

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

lines 46–49why, one step back
46import type { ProjectApi } from "./project.ts";
4748/** What the code reads take from a project's record, beside its canonical repo. */49export interface CodeProject {

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 50–51why, one step back
50 /** The project, as its refs name it. */
51 readonly project: ProjectName;

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

lines 52–70why, one step back
52 /** The project's canonical repo: never a fork's or a layer's. */
53 readonly repo: RepoName;54 /** Main's landed commit; none before the first push. */55 readonly head: Effect.Effect<Option.Option<LandedSha>>;56 /** The landings among `shas`, so a forged trailer never reads as one. */57 readonly landings: (58 shas: readonly CommitSha[]59 ) => Effect.Effect<readonly LandingView[]>;60 readonly forks: Effect.Effect<readonly ForkRef[]>;61}6263/** The code reads' view of `project`, through its `ProjectApi`. */64export const codeProjectOf = (65 api: ProjectApi,66 project: ProjectName67): CodeProject => ({68 forks: api.forks(),69 head: Effect.map(api.head(), ({ landed }) => Option.fromUndefinedOr(landed)),70 landings: api.landings,

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

line 71why, one step back
71 project,

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

lines 72–78why, one step back
72 repo: RepoName.make(project),
73});7475const notBuilt = (issue: string) => Effect.die(`not built: ${issue}`);7677/** Main's landed commit, its tags peeled and sorted newest first, and its forks. */78export const refsOf = (

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 79–80why, one step back
79 project: CodeProject
80): Effect.Effect<RefsView, never, RepoHost> => refsView(project);

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

lines 81–83why, one step back
81
82/** One folder at `at` (main when none), folders first, with its README. */83export const treeOf = (

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 84–86why, one step back
84 project: CodeProject,
85 at: Option.Option<Rev>,86 path: Option.Option<RepoPath>

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

line 87why, one step back
87): Effect.Effect<TreeListing, UnknownRevision | UnknownPath, RepoHost> =>

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

line 88why, one step back
88 listing(project, at, path);

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

lines 89–91why, one step back
89
90/** Every file path at `at`, up to the cap. */91export const pathsOf = (

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 92–94why, one step back
92 project: CodeProject,
93 at: Option.Option<Rev>94): Effect.Effect<PathList, UnknownRevision, RepoHost> => pathList(project, at);

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

lines 95–97why, one step back
95
96/** One file at `at`: its text, or that it is binary or too large. */97export const fileOf = (

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 98–100why, one step back
98 project: CodeProject,
99 at: Option.Option<Rev>,100 path: RepoPath

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

line 101why, one step back
101): Effect.Effect<FileView, UnknownRevision | UnknownPath, RepoHost> =>

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

line 102why, one step back
102 fileView(project, at, path);

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

lines 103–105why, one step back
103
104/** A page of first-parent commits from `at`, each landing with its record. */105export const logOf = (

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 106–107why, one step back
106 project: CodeProject,
107 input: {

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

lines 108–116why, one step back
108 readonly at: Option.Option<Rev>;
109 readonly path: Option.Option<RepoPath>;110 readonly from: number;111 readonly limit: number;112 }113): Effect.Effect<114 { readonly commits: readonly CommitView[]; readonly next?: number },115 UnknownRevision,116 RepoHost

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

line 117why, one step back
117> => logPage(project, input);

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

lines 118–120why, one step back
118
119/** One commit and the files it changed against its first parent. */120export const commitOf = (

Merge branch 'build/903-code-reads'oscabrielbefore adoption7608aca

lines 121–124why, one step back
121 project: CodeProject,
122 sha: CommitSha123): Effect.Effect<CommitDiff, UnknownCommit, RepoHost> =>124 commitDiff(project, sha);

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

lines 125–132why, one step back
125
126/** Why each line of a file at `at` is there. */127export const whyOf = (128 _project: CodeProject,129 _at: Option.Option<Rev>,130 _path: RepoPath131): Effect.Effect<WhyView, UnknownRevision | UnknownPath, RepoHost> =>132 notBuilt("912");