Skip to content
Myr

Under an agent, run every release step but the publish, and hand a person the npm command only for a package that would publish

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Review of 715. - Fix: under an agent, any run with `--publish` was refused whole and exited 0. So `--build --publish` and `--upload --publish` built or uploaded nothing yet reported success. The printed `npm publish` command also skipped the checks a person's `--publish` runs: the staged version, and every file the manifest names. Today that means it handed over a package without dist/pi.js, or one of another version. - `releaseRun` (scripts/lib/release.ts) gives the steps a run takes and the agent markers it hands the publish to. Under an agent, it runs every other step the flags name. `releasePlan` still fails with PublishNeedsAPerson, as the issue's Check asks. Both share one step list (`stepsOf`) and one input type (`ReleaseFlags`). - steps.ts splits the publish step's checks out as `publishable`. scripts/release.ts runs it before printing the command, so an agent's `--publish` needs `--version`, as a person's does, and refuses an incomplete package. `main` takes the env as a parameter; the entry reads process.env once. - Fix: the comment on the import scanner said generated source in strings never starts a line with `import`. dist/bin.js has one: the rules' /bun main template imports ./job.json. The comment now says such a line is read, and that one naming a package fails Unpinned. - Fix: the npm README's start block wrote `claim` without its <ask>. - Tests: two releaseRun cases in packages/config/test/release.test.ts. One checks that an agent's build-upload-publish runs every other step and hands the publish over, while a person's publishes. The other checks that an unknown stage is refused under an agent too. Both were red by assertion against a stub that refused the whole plan. - Checked by hand under CLAUDECODE. `--publish` alone fails with VersionNeeded. `--publish --version 0.1.0` against the 0.0.0 staged package is refused. `--build --publish --version 0.1.0-review.715` builds, then refuses because dist/pi.js is missing (706). With a stand-in pi.js, the run prints the command and exits 0.

authored by oscabriel · committed by oscabriel · parent 612a0f7 · Browse files · 5 files+174 added−54 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+174 added−54 removed

  • tests:+52 added−0 removed
  • other:+122 added−54 removed

5 files+174 added−54 removed

modified:packages/config/test/release.test.ts+52 added
31 unmodified lines
32 publishManifest,33 PublishNeedsAPerson,34 releaseManifest,35 releasePlan,36 releaseRun,37 releaseVersion,38 targets,39 Unpinned,40 unreleased,
208 unmodified lines
249 Result.fail(new PublishNeedsAPerson({ markers: ["CLAUDECODE"] }))250 );251 });252253 it("under an agent, still runs every other step it was asked for, and hands only the publish to a person", () => {254 expect({255 agent: releaseRun({256 build: true,257 env: { CLAUDECODE: "1" },258 publish: true,259 stage: "demo",260 upload: true,261 }),262 alone: releaseRun({263 build: false,264 env: { CLAUDECODE: "1" },265 publish: true,266 upload: false,267 }),268 person: releaseRun({269 build: false,270 env: {},271 publish: true,272 upload: false,273 }),274 }).toStrictEqual({275 agent: Result.succeed({276 handOver: ["CLAUDECODE"],277 steps: [278 "tsdown",279 "manifest",280 "copySkills",281 "compile",282 "installScript",283 "checksums",284 "upload",285 ],286 }),287 alone: Result.succeed({ handOver: ["CLAUDECODE"], steps: [] }),288 person: Result.succeed({ handOver: [], steps: ["publish"] }),289 });290 });291292 it("refuses an unknown stage under an agent too, before it hands anything over", () => {293 expect(294 releaseRun({295 build: false,296 env: { CLAUDECODE: "1" },297 publish: true,298 stage: "prod",299 upload: true,300 })301 ).toStrictEqual(Result.fail(new UnknownStage({ stage: "prod" })));302 });303304 it("publishes last when a person runs it", () => {305 expect(306 Result.map(307 releasePlan({ build: false, env: {}, publish: true, upload: false }),
386 unmodified lines
modified:scripts/lib/release/readme.ts+3 added-3 removed
modified:scripts/lib/release/steps.ts+14 added-5 removed
545 unmodified lines
546 Effect.map(fs.exists(path.join(layout.npm, file)), (exists) => !exists)547 );548 });549550/** `publish`: `npm publish` of the staged package, once it is whole and of this version. */551const publish = (layout: Layout, release: Release) =>550/**551 * The staged package is whole and of this release's version, so what552 * `npm publish` ships is what this release built: checked before the553 * publish runs, and before an agent hands its command to a person (H2).554 */555export const publishable = (layout: Layout, release: Release) =>556 Effect.gen(function* () {557 const path = yield* Path.Path;558559 yield* readPackage("publish", path.join(layout.npm, "package.json")).pipe(
13 unmodified lines
573 (missing) =>574 failed("publish", `the staged package lacks ${missing.join(", ")}`)575 )576 );577 });578574 return yield* run(579/** `publish`: `npm publish` of the staged package, once it is `publishable`. */580const publish = (layout: Layout, release: Release) =>581 Effect.andThen(582 publishable(layout, release),583 run(584 "publish",585 "npm",586 ["publish", layout.npm, "--access", "public"],587 layout.root579 );580 });588 )589 );590591/** `installScript`: the install script for this version, fetching from the release's origin. */592const writeInstallScript = (layout: Layout, release: Release) =>593 Effect.gen(function* () {
37 unmodified lines
modified:scripts/lib/release.ts+69 added-29 removed
28 unmodified lines
2930/**31 * A module statement as rolldown writes one, at the start of a line: an32 * `import … from "x"` or `export … from "x"`, over any number of lines, or a33 * side-effect `import "x"`. Prose and generated source inside strings never34 * start a line of the build with `import`, so they are not read as imports.33 * side-effect `import "x"`. Prose and inline strings are not read, but a34 * template literal's line can start with `import` (`dist/bin.js` holds one:35 * the rules' `/bun` main imports `./job.json`). Such a line naming a36 * package is read as an import, which fails the pin loudly (`Unpinned`)37 * rather than letting an import slip through unpinned.38 */39const STATEMENT =40 /^(?:import|export)\b[^;"'`]*?\bfrom\s*["'](?<from>[^"']+)["']|^import\s*["'](?<bare>[^"']+)["']/gmu;41
238 unmodified lines
280281/** What a build or an upload ends with: the install script for its origin, and the digests. */282const RELEASE_FILES: readonly ReleaseStep[] = ["installScript", "checksums"];283281/**282 * The steps a release runs, in order: `build` (416's build with both283 * targets, the npm package and the binaries), the install script and the284 * checksums, `upload` to the stage's own release storage, and `publish`285 * last. An upload names a stage the repo declares (`dev-oscabriel` or286 * `demo`); a stage given to a build only says whose origin the install287 * script fetches from, and is checked the same way. Under any agent's env,288 * a plan that publishes is refused whole (H2): the script prints the289 * command for a person to run instead.290 */291export const releasePlan = (input: {284/** What `bun run release` was asked to do, and the env it runs in. */285export interface ReleaseFlags {286 readonly build: boolean;287 readonly upload: boolean;288 readonly stage?: string;289 readonly publish: boolean;290 readonly env: Readonly<Record<string, string | undefined>>;297}): Result.Result<298 readonly ReleaseStep[],299 PublishNeedsAPerson | NoStage | UnknownStage300> => {301 const markers = input.publish ? agentMarkers(input.env) : [];291}292303 if (markers.length > 0) {304 return Result.fail(new PublishNeedsAPerson({ markers }));305 }306307 if (input.stage === undefined && input.upload) {293/**294 * The steps `flags` name, in order: `build` (416's build with both295 * targets, the npm package and the binaries), the install script and the296 * checksums, `upload` to the stage's own release storage, and `publish`297 * last. An upload names a stage the repo declares (`dev-oscabriel` or298 * `demo`); a stage given to a build only says whose origin the install299 * script fetches from, and is checked the same way.300 */301const stepsOf = (302 flags: ReleaseFlags303): Result.Result<readonly ReleaseStep[], NoStage | UnknownStage> => {304 if (flags.stage === undefined && flags.upload) {305 return Result.fail(new NoStage());306 }307311 if (input.stage !== undefined && Option.isNone(declaredStage(input.stage))) {312 return Result.fail(new UnknownStage({ stage: input.stage }));308 if (flags.stage !== undefined && Option.isNone(declaredStage(flags.stage))) {309 return Result.fail(new UnknownStage({ stage: flags.stage }));310 }311312 return Result.succeed([316 ...(input.build ? BUILD : []),317 ...(input.build || input.upload ? RELEASE_FILES : []),318 ...(input.upload ? (["upload"] as const) : []),319 ...(input.publish ? (["publish"] as const) : []),313 ...(flags.build ? BUILD : []),314 ...(flags.build || flags.upload ? RELEASE_FILES : []),315 ...(flags.upload ? (["upload"] as const) : []),316 ...(flags.publish ? (["publish"] as const) : []),317 ]);318};319320/**321 * The steps a release runs, in order (`stepsOf`). Under any agent's env, a322 * plan that publishes is refused (H2); `releaseRun` says what the script323 * then does instead.324 */325export const releasePlan = (326 flags: ReleaseFlags327): Result.Result<328 readonly ReleaseStep[],329 PublishNeedsAPerson | NoStage | UnknownStage330> => {331 const markers = flags.publish ? agentMarkers(flags.env) : [];332333 return markers.length > 0334 ? Result.fail(new PublishNeedsAPerson({ markers }))335 : stepsOf(flags);336};337338/** One run of `bun run release`: the steps it runs, and who it hands the publish to. */339export interface ReleaseRun {340 readonly steps: readonly ReleaseStep[];341 /** The agent markers that refused the publish (H2); none when a person runs it. */342 readonly handOver: readonly string[];343}344345/**346 * What the script runs for `flags`. A person's run is the plan. Under an347 * agent, a run that publishes still runs every other step it names, so a348 * `--build --publish` builds, and hands the publish to a person in place349 * of running it: the script checks the staged package and prints the350 * command (H2), rather than ending well with nothing done.351 */352export const releaseRun = (353 flags: ReleaseFlags354): Result.Result<ReleaseRun, NoStage | UnknownStage> => {355 const handOver = flags.publish ? agentMarkers(flags.env) : [];356357 return Result.map(358 stepsOf({ ...flags, publish: flags.publish && handOver.length === 0 }),359 (steps) => ({ handOver, steps })360 );361};362363// --- The version -------------------------------------------------------------364365/**366 * An upload or a publish names its `--version`, and it is one the platform
168 unmodified lines
modified:scripts/release.ts+36 added-17 removed
18 unmodified lines
19 * `releases/manifest.json` last; the platform then serves `<origin>/install.sh`20 * and `<origin>/releases/…` (issue 420). Nothing goes to GitHub.21 *22 * `--publish` runs `npm publish` only when a person runs it: under any23 * agent's env (`@repo/protocol/audit`'s table) it does nothing, prints the24 * command for a person to run, and exits 0 (H2). The release's core lives25 * in `lib/release.ts`, its steps in `lib/release/steps.ts`.23 * agent's env (`@repo/protocol/audit`'s table) the run still does every24 * other step it names, checks the staged package as a publish would, prints25 * the command for a person to run, and exits 0 (H2). The release's core26 * lives in `lib/release.ts`, its steps in `lib/release/steps.ts`.27 */28import { BunRuntime, BunServices } from "@effect/platform-bun";29import {30 Console,
14 unmodified lines
45 subdomainFile,46 WorkersDev,47} from "../infra/stages.ts";48import type { Stage } from "../infra/stages.ts";48import { releasePlan, releaseVersion } from "./lib/release.ts";49import { releaseRun, releaseVersion } from "./lib/release.ts";50import {51 layoutOf,52 missingFromPackage,53 publishable,54 publishCommand,55 ReleaseFailed,56 runStep,57} from "./lib/release/steps.ts";
137 unmodified lines
195 }196 });197198/**197 * Under an agent, `--publish` does nothing but say what a person runs198 * (H2), and the run ends well: the agent has done all it may.199 * Under an agent, the publish is a person's (H2): once the staged package200 * is whole and of this version, say what they run, and end well, since the201 * agent has done all it may.202 */200const handOver = (markers: readonly string[]) =>203const handOver = (204 layout: Layout,205 release: Release,206 markers: readonly string[]207) =>208 Effect.gen(function* () {209 const path = yield* Path.Path;203 const layout = yield* layoutOf(yield* repoRoot);210211 yield* publishable(layout, release);212213 yield* Console.log(214 [207 `release: an agent runs this (${markers.join(", ")}), so it publishes nothing (H2).`,208 "A person publishes the staged package, after `npm login`, from the repo root:",215 `release: an agent runs this (${markers.join(", ")}), so it doesn't publish (H2).`,216 `A person publishes the staged package (${release.version}), after \`npm login\`, from the repo root:`,217 "",218 ` ${publishCommand(layout, path)}`,219 ].join("\n")220 );221 });222215export const main = (argv: readonly string[]) =>223export const main = (224 argv: readonly string[],225 env: Readonly<Record<string, string | undefined>>226) =>227 Effect.gen(function* () {228 const options = yield* optionsOf(argv);229 const root = yield* repoRoot;230 const layout = yield* layoutOf(root);231221 // The env as this process got it: an agent's harness marks it there.222 const steps = yield* Effect.fromResult(223 releasePlan({ ...options, env: process.env })232 const { handOver: markers, steps } = yield* Effect.fromResult(233 releaseRun({ ...options, env })234 );235236 const version = yield* Effect.fromResult(releaseVersion(options));237
10 unmodified lines
248 }));249250 const release: Release = { origin, stage, version };251252 const planned = [253 ...steps,254 ...(markers.length > 0 ? ["publish (by a person)"] : []),255 ];256257 yield* Console.log(243 `release ${version}: ${steps.join(", ")} (the install script fetches from ${origin})`258 `release ${version}: ${planned.join(", ")} (the install script fetches from ${origin})`259 );260261 for (const step of steps) {262 yield* Console.log(`release: ${step}`);263 yield* runStep(step, layout, release);264 }265266 yield* report(layout, version);267268 if (markers.length > 0) {269 yield* handOver(layout, release, markers);270 }271 }).pipe(253 Effect.catchTag("PublishNeedsAPerson", ({ markers }) => handOver(markers)),272 Effect.tapError((failure) => Console.error(`release: ${failure.message}`)),273 Effect.mapError(() => new Reported())274 );275
1 unmodified line
277 BunRuntime.runMain(278 Effect.gen(function* () {279 const args = yield* (yield* Stdio.Stdio).args;280281 // The env as this process got it: an agent's harness marks it there.263 return yield* main(args);282 return yield* main(args, process.env);283 }).pipe(Effect.provide(BunServices.layer))284 );285}