generated.ts
This file
Path
packages/project/src/generated.ts
156 lines · 4.5 KiB · TypeScript
Last changed by
Merge build/comments-project into mainoscabrielbefore adoption49efd2a
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–20why, one step back1import { Brand } from "@repo/brand";2import { formatLanding } from "@repo/git/trailers";3import type { Credit } from "@repo/protocol/domain/credit";4import type { LandingView } from "@repo/protocol/domain/landing";5import type { Policy } from "@repo/protocol/domain/policy";6import { RepoPath, RequestId, sameHandle } from "@repo/protocol/ids";7import type { Handle, LandedSha, ProjectName } from "@repo/protocol/ids";8import { Array, Context, Effect, Option } from "effect";910import { decidersFor } from "./attention/decisions.ts";11import { platformHandle } from "./attention/effects.ts";1213export interface GeneratedFile {14 readonly path: string;15 readonly content: string;16}1718export type ReadAt = (path: string) => Effect.Effect<Option.Option<string>>;1920/**Merge build/comments-project into mainoscabrielbefore adoption49efd2a
lines 21–22why, one step back21 * `read` is for files written into rather than over (AGENTS.md: text outside22 * its block is the project's own).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–35why, one step back23 */24export type Generate = (input: {25 readonly project: ProjectName;26 readonly policy: Policy;27 readonly landed: LandedSha;28 readonly read: ReadAt;29}) => Effect.Effect<readonly GeneratedFile[]>;3031export interface FollowUp {32 readonly author: Handle;33 readonly credits: readonly Credit[];34 readonly files: Array.NonEmptyReadonlyArray<GeneratedFile>;35 readonly message: string;Merge build/comments-project into mainoscabrielbefore adoption49efd2a
line 36why, one step back36 /** The same follow-up landed again finds the first 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 37–40why, one step back37 readonly requestId: RequestId;38}3940/**Merge build/comments-project into mainoscabrielbefore adoption49efd2a
lines 41–42why, one step back41 * The default makes no files, so a project given none gets no follow-up42 * landing.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 43–106why, one step back43 */44export const ProjectGenerator = Context.Reference<Generate>(45 "project/ProjectGenerator",46 { defaultValue: () => () => Effect.succeed([]) }47);4849export const generatedRequestId = (landed: LandedSha) =>50 RequestId.make(`gen-${landed}`);5152const configPath = RepoPath.make(`${Brand.configDir}/project.ts`);5354const deciderOf = (input: {55 readonly after: Policy;56 readonly initializer: Handle;57 readonly landing: LandingView;58}): Handle => {59 const { author, credits } = input.landing;6061 const decided = Array.findFirst(62 credits,63 ({ role }) => role === "Decided-by"64 ).pipe(Option.map(({ handle }) => handle));6566 const authorDecides = decidersFor(input.after, [configPath]).some((each) =>67 sameHandle(each, author)68 );6970 return Option.getOrElse(71 Option.orElse(decided, () =>72 authorDecides ? Option.some(author) : Option.none()73 ),74 () => input.initializer75 );76};7778const sameFiles = (79 one: readonly GeneratedFile[],80 other: readonly GeneratedFile[]81) =>82 one.length === other.length &&83 one.every(84 ({ content, path }, index) =>85 other[index]?.path === path && other[index]?.content === content86 );8788const messageOf = (input: {89 readonly credits: readonly Credit[];90 readonly files: readonly GeneratedFile[];91 readonly landed: LandedSha;92 readonly requestId: RequestId;93}) =>94 formatLanding({95 assisted: [],96 body: [97 `The config at ${input.landed} changed what these files say, so the platform wrote them again from it:`,98 "",99 ...input.files.map(({ path }) => `- ${path}`),100 ].join("\n"),101 credits: input.credits,102 requestId: input.requestId,103 subject: "Regenerate the contribute skill and the AGENTS.md block",104 });105106/**Merge build/comments-project into mainoscabrielbefore adoption49efd2a
lines 107–108why, one step back107 * Never folded into the landing that changed the config: the follow-up holds108 * only the regenerated files, and is none when nothing they say changed.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 109–156why, one step back109 */110export const generatedFollowUp = (111 input: {112 readonly project: ProjectName;113 readonly initializer: Handle;114 readonly before: Option.Option<Policy>;115 readonly after: Policy;116 readonly landing: LandingView;117 readonly read: ReadAt;118 },119 generate: Generate120): Effect.Effect<Option.Option<FollowUp>> =>121 Effect.gen(function* () {122 const { landing, project, read } = input;123 const landed = landing.sha;124 const at = (policy: Policy) => generate({ landed, policy, project, read });125 const after = yield* at(input.after);126127 if (Option.isSome(input.before)) {128 const before = yield* at(input.before.value);129130 if (sameFiles(before, after)) {131 return Option.none();132 }133 }134135 const differing = yield* Effect.filter(after, ({ content, path }) =>136 Effect.map(read(path), (held) => !Option.contains(held, content))137 );138139 if (!Array.isReadonlyArrayNonEmpty(differing)) {140 return Option.none();141 }142143 const credits: readonly Credit[] = [144 { handle: deciderOf(input), role: "Decided-by" },145 ];146147 const requestId = generatedRequestId(landed);148149 return Option.some({150 author: platformHandle,151 credits,152 files: differing,153 message: messageOf({ credits, files: differing, landed, requestId }),154 requestId,155 });156 });