Skip to content
Myr

Merge examples/cli-dev-dependency into main

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

authored by oscabriel · committed by oscabriel · parents 6e2833d, 192230d · Browse files · 24 files+272 added−44 removed
This commit

State

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

Diff stats

24 files+272 added−44 removed

  • tests:+104 added−6 removed
  • other:+168 added−38 removed

24 files+272 added−44 removed

modified:apps/cli/src/local/local-policy.ts+3 added-4 removed
120 unmodified lines
121 dir,122 "tsconfig.json",123 JSON.stringify({124 compilerOptions: {125 paths: {126 [`${Brand.cliPackage}/rules`]: [sdk],127 "@repo/sdk": [sdk],128 },125 paths: Object.fromEntries(126 [...Brand.sdkImports, "@repo/sdk"].map((name) => [name, [sdk]])127 ),128 },129 })130 );131
263 unmodified lines
modified:apps/sandbox/src/lander/script.ts+3 added-1 removed
407 unmodified lines
408export const resolution = (sdk: string) =>409 `${JSON.stringify(410 {411 compilerOptions: {412 paths: { [`${Brand.cliPackage}/rules`]: [sdk], "@repo/sdk": [sdk] },412 paths: Object.fromEntries(413 [...Brand.sdkImports, "@repo/sdk"].map((name) => [name, [sdk]])414 ),415 },416 },417 null,418 2
191 unmodified lines
modified:apps/sandbox/test/lander.test.ts+42 added-1 removed
232 unmodified lines
233234 return yield* Effect.promise((): Promise<Imported> => import(target));235 });236237const SDK_NAMES = [`"${Brand.cliPackage}/rules"`, '"@repo/sdk"'];237const SDK_NAMES = [238 ...Brand.sdkImports.map((name) => JSON.stringify(name)),239 '"@repo/sdk"',240];241242const pointedAtSdk = (source: string) => {243 let pointed = source;244
462 unmodified lines
707 }).pipe(Effect.scoped, Effect.provide(TestServices))708 );709710 it.live(711 "bundles a folder that imports the sdk by a name it had before, as a project made then still does",712 () =>713 Effect.gen(function* () {714 const [current, former] = Brand.sdkImports;715 const repos = yield* world;716717 const formerly = Object.fromEntries(718 Object.entries(configFolder).map(([file, source]) => [719 file,720 source === null ? null : source.replaceAll(current, former),721 ])722 );723724 expect(formerly[config("project.ts")]).toContain(former);725726 const at = yield* startedWith(repos, formerly);727728 const bundled = yield* bundleRules(bundleWire(repos, at)).pipe(729 Effect.provide(box(repos.work))730 );731732 const projectModule = yield* importedFrom(733 bundled.modules,734 config("project.ts")735 );736737 const projectAsCommitted = yield* importedFrom(738 asCommitted(configFolder),739 config("project.ts")740 );741742 expect(dataOf(projectModule)).toStrictEqual(743 dataOf(projectAsCommitted)744 );745 }).pipe(Effect.scoped, Effect.provide(TestServices))746 );747748 it.live(749 "gives no modules for a repo with no config folder, so the project runs on the defaults",750 () =>751 Effect.gen(function* () {752 const repos = yield* world;
485 unmodified lines
modified:examples/burrow/.myr/asks/drop-legacy-fetch.ask.ts+1 added-1 removed
added:examples/burrow/.myr/package.json+7 added
modified:examples/burrow/.myr/project.ts+1 added-1 removed
added:examples/burrow/.myr/tsconfig.json+16 added
modified:examples/datekit/.myr/asks/add-months-clamp.ask.ts+1 added-1 removed
modified:examples/datekit/.myr/asks/format-ordinal.ask.ts+1 added-1 removed
1import { kinds, territory } from "@myr/cli/rules";1import { kinds, territory } from "@myrtechnology/cli/rules";23export default kinds.fix.ask({4 current: "The 11th, 12th and 13th of a month print as 11st, 12nd and 13rd.",5 mentor: "okonkwo",
6 unmodified lines
modified:examples/datekit/.myr/asks/parse-iso-week.ask.ts+1 added-1 removed
1import { kinds, territory } from "@myr/cli/rules";1import { kinds, territory } from "@myrtechnology/cli/rules";23export default kinds.fix.ask({4 current:5 "parseISO gives an invalid date for every week date, so a payroll week or a sprint stored as 2026-W41 can't be read back.",
8 unmodified lines
added:examples/datekit/.myr/package.json+7 added
1{2 "private": true,3 "type": "module",4 "devDependencies": {5 "@myrtechnology/cli": "0.2.2"6 }7}
modified:examples/datekit/.myr/project.ts+1 added-1 removed
1import { kinds, project } from "@myr/cli/rules";1import { kinds, project } from "@myrtechnology/cli/rules";23/**4 * How datekit takes changes. Each change we want is an ask in asks/, with a5 * test that fails on main; an answer lands when that test passes and the
18 unmodified lines
added:examples/datekit/.myr/tsconfig.json+16 added
1{2 "compilerOptions": {3 "target": "ES2023",4 "lib": ["ES2023"],5 "module": "Preserve",6 "moduleResolution": "bundler",7 "allowImportingTsExtensions": true,8 "noEmit": true,9 "strict": true,10 "noUncheckedIndexedAccess": true,11 "exactOptionalPropertyTypes": true,12 "verbatimModuleSyntax": true,13 "skipLibCheck": true14 },15 "include": ["**/*.ts"]16}
modified:examples/datekit/.myr/visibility.ts+1 added-1 removed
1import { flows, layer, sealedChecks, visibility } from "@myr/cli/rules";1import { flows, layer, sealedChecks, visibility } from "@myrtechnology/cli/rules";23/**4 * What datekit keeps out of its public tree, and why. The maintainers hold5 * checks for how dates are shown (export) and read (parser) in a layer of
21 unmodified lines
modified:examples/datekit/layers/maintainers/.myr/layer.json+2 added-2 removed
110 unmodified lines
111 "path": "checks/held-back/parser/fraction-digits.test.ts"112 }113 ],114 "knownBad": [115 "f7ba08a5de930667c6769382352b58574d6b5805",116 "ec27b34dcec611e099a0039e33bf003c48c4a8b5"115 "dbaee401dfda08e13c16ce9066727e2adb99ceca",116 "af5d85ab3e43a2809ff19559f397028dbf3e86bf"117 ],118 "layer": "maintainers"119}
modified:examples/datekit/layers/maintainers/.myr/layer.ts+4 added-4 removed
1import { layerManifest } from "@myr/cli/rules";2import type { AreaOf } from "@myr/cli/rules";1import { layerManifest } from "@myrtechnology/cli/rules";2import type { AreaOf } from "@myrtechnology/cli/rules";34// The public config sits beside this file in a maintainer's work tree, where5// the layer is overlaid on main at the same paths.6import type policy from "./visibility.ts";
128 unmodified lines
135 },136 ],137 knownBad: [138 // known-bad/export: unescapes only the first pair of quotes.139 "f7ba08a5de930667c6769382352b58574d6b5805",139 "dbaee401dfda08e13c16ce9066727e2adb99ceca",140 // known-bad/parser: rounds the digits past the millisecond.141 "ec27b34dcec611e099a0039e33bf003c48c4a8b5",141 "af5d85ab3e43a2809ff19559f397028dbf3e86bf",142 ],143 layer: "maintainers",144});
modified:packages/brand/src/index.ts+10 added-2 removed
4 unmodified lines
5// The platform's own host on prod: where the CLI signs in and reads when6// nothing names another platform.7const platformHost = `git.${domain}`;89// npm's `@myr` is another account's, so the package's scope spells the domain.10const npmScope = `@${slug}technology`;1112const cliPackage = `${npmScope}/cli`;1314export const Brand = {15 cli: slug,11 cliPackage: `@${slug}/cli`,16 cliPackage,17 configDir: `.${slug}`,18 domain,19 gitCredentialHelper: `git-credential-${slug}`,20 gitRemoteHelper: `git-remote-${slug}`,21 githubOrg: `get${slug}`,22 name: "Myr",18 npmScope: `@${slug}`,23 npmScope,24 platformHost,25 platformUrl: `https://${platformHost}`,26 refsPrefix: `refs/${slug}/`,27 // Each name a config folder imports the sdk by: the package's own, then28 // the one it had before its scope moved, which projects made then keep.29 sdkImports: [`${cliPackage}/rules`, `@${slug}/cli/rules`],30 slug,31 urlScheme: `${slug}://`,32} as const;
modified:packages/brand/src/leaks.ts+6 added-2 removed
29 unmodified lines
30 (dir === "layers" && layerDir === Brand.configDir))31 );32};3334// Letters on either side make it another word ("myriad"), not the name.35const NAME = new RegExp(`(?<![a-z])${Brand.slug}(?![a-z])`, "iu");34// Letters on either side make it another word ("myriad"), not the name; the35// npm scope spells it with the domain's word joined on.36const NAME = new RegExp(37 `(?<![a-z])(?:${Brand.slug}|${Brand.npmScope.slice(1)})(?![a-z])`,38 "iu"39);4041const mayNameTheBrand = (path: string) =>42 path.startsWith(HOME) || PROSE.test(path) || inExampleConfig(path);43
26 unmodified lines
modified:packages/config/test/release.test.ts+57 added-4 removed
23 unmodified lines
24 checksumsFile,25 importedPackages,26 installScript,27 namedFiles,28 NotServedAsLatest,29 pinnedDependencies,30 publishManifest,31 PublishNeedsAPerson,32 releaseManifest,33 releasePlan,34 releaseRun,35 releaseVersion,36 servedAsLatest,37 targets,38 Unpinned,39 unreleased,40 uploads,
26 unmodified lines
67 dependencies: runtime,68 version: "0.1.0",69 });7071 // A bin path in npm's normal form, without `./`: npm rewrites any other72 // and warns that it was "invalid and removed" though it keeps it.73 it("is the brand's CLI package, with both names as bins", () => {74 expect({75 bin: manifest.bin,76 license: manifest.license,77 name: manifest.name,78 version: manifest.version,79 }).toStrictEqual({80 bin: {77 [Brand.cli]: "./dist/bin.js",78 [Brand.gitCredentialHelper]: "./dist/bin.js",81 [Brand.cli]: "dist/bin.js",82 [Brand.gitCredentialHelper]: "dist/bin.js",83 },84 license: "MIT",85 name: Brand.cliPackage,86 version: "0.1.0",
176 unmodified lines
263 alone: releaseRun({264 build: false,265 env: { CLAUDECODE: "1" },266 publish: true,267 stage: "dev-oscabriel",268 upload: false,269 }),270 person: releaseRun({271 build: false,272 env: {},273 publish: true,274 stage: "dev-oscabriel",275 upload: false,276 }),277 }).toStrictEqual({278 agent: Result.succeed({
27 unmodified lines
306307 it("publishes last when a person runs it", () => {308 expect(309 Result.map(304 releasePlan({ build: false, env: {}, publish: true, upload: false }),310 releasePlan({311 build: false,312 env: {},313 publish: true,314 stage: "dev-oscabriel",315 upload: false,316 }),317 Arr.last318 )319 ).toStrictEqual(Result.succeed(Option.some("publish")));320 });
69 unmodified lines
390 wrong: Result.fail(new VersionNeeded({ given: "latest" })),391 });392 });393394 // A publish reads the stage's release manifest, so it names its stage, even395 // when an agent hands it to a person.382 it("refuses an upload to a stage the repo doesn't declare, or to none", () => {396 it("refuses an upload or a publish to a stage the repo doesn't declare, or to none", () => {397 expect({398 handedOver: releaseRun({399 build: false,400 env: { CLAUDECODE: "1" },401 publish: true,402 upload: false,403 }),404 none: releasePlan({405 build: false,406 env: {},407 publish: false,408 upload: true,409 }),410 publish: releasePlan({411 build: false,412 env: {},413 publish: true,414 upload: false,415 }),416 unknown: releasePlan({417 build: false,418 env: {},419 publish: false,420 stage: "staging",421 upload: true,422 }),423 }).toStrictEqual({424 handedOver: Result.fail(new NoStage()),425 none: Result.fail(new NoStage()),426 publish: Result.fail(new NoStage()),427 unknown: Result.fail(new UnknownStage({ stage: "staging" })),428 });429 });430});
108 unmodified lines
539 versions: { "0.1.0": { assets: second } },540 });541 });542543 it("publishes to npm only the version the stage's install script serves as latest", () => {544 expect({545 ahead: servedAsLatest({ manifest: first, version: "0.2.0" }),546 earlier: servedAsLatest({547 manifest: releaseManifest({548 assets: second,549 previous: first,550 version: "0.2.0",551 }),552 version: "0.1.0",553 }),554 latest: servedAsLatest({ manifest: first, version: "0.1.0" }),555 unreleased: servedAsLatest({ manifest: undefined, version: "0.1.0" }),556 }).toStrictEqual({557 ahead: Result.fail(558 new NotServedAsLatest({ latest: "0.1.0", version: "0.2.0" })559 ),560 earlier: Result.fail(561 new NotServedAsLatest({ latest: "0.2.0", version: "0.1.0" })562 ),563 latest: Result.void,564 unreleased: Result.fail(new NotServedAsLatest({ version: "0.1.0" })),565 });566 });567568 it("refuses to release a version again with other bytes, since its files are cached for good", () => {569 expect({570 again: unreleased({571 assets: first.versions["0.1.0"].assets,
228 unmodified lines
modified:packages/config/test/seed.test.ts+5 added-1 removed
60 unmodified lines
61 expect(plan.initFiles.map(({ path }) => path)).toStrictEqual([62 ".env.schema",63 ".env.test",64 ".gitignore",65 `${config}/package.json`,66 `${config}/project.ts`,67 `${config}/tsconfig.json`,68 `${config}/visibility.ts`,69 `${config}/vouched.td`,70 "LICENSE",71 "README.md",
78 unmodified lines
150 ]);151152 const paths = plan.initFiles.map(({ path }) => path);153152 expect(paths).toHaveLength(50);154 expect(paths).toHaveLength(52);155156 expect(paths).toStrictEqual(157 expect.arrayContaining([158 `${config}/package.json`,159 `${config}/project.ts`,160 `${config}/tsconfig.json`,161 "bun.lock",162 "packages/kit/src/legacy.ts",163 "scripts/count-callers.ts",164 ])
402 unmodified lines
modified:scripts/lib/release/steps.ts+42 added-9 removed
29 unmodified lines
30 pinnedDependencies,31 publishManifest,32 ReleaseManifest,33 releaseManifest,34 servedAsLatest,35 targets,36 unreleased,37 uploads,38} from "../release.ts";
302 unmodified lines
341 "wrangler"342 );343344// Wrangler's own login, never the read-mostly infra token.344const wrangler = (layout: Layout, cwd: string, args: readonly string[]) =>345const wrangler = (346 step: ReleaseStep,347 layout: Layout,348 cwd: string,349 args: readonly string[]350) =>351 Effect.gen(function* () {352 const path = yield* Path.Path;353 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;354
16 unmodified lines
371 return { exitCode: Number(exitCode), output };372 }).pipe(373 Effect.scoped,374 Effect.mapError(({ message }) =>369 failed("upload", `wrangler didn't run: ${message}`)375 failed(step, `wrangler didn't run: ${message}`)376 )377 );378379const NO_SUCH_KEY = "The specified key does not exist";380375const previousManifest = (layout: Layout, bucket: string, scratch: string) =>381const bucketManifest = (382 step: ReleaseStep,383 layout: Layout,384 bucket: string,385 scratch: string386) =>387 Effect.gen(function* () {388 const fs = yield* FileSystem.FileSystem;389 const path = yield* Path.Path;390 const file = path.join(scratch, "previous.json");391381 const got = yield* wrangler(layout, scratch, [392 const got = yield* wrangler(step, layout, scratch, [393 "r2",394 "object",395 "get",396 `${bucket}/${MANIFEST_KEY}`,
5 unmodified lines
402 if (got.exitCode !== 0) {403 return got.output.includes(NO_SUCH_KEY)404 ? Option.none()405 : yield* failed(395 "upload",406 step,407 `wrangler r2 object get ${bucket}/${MANIFEST_KEY} failed:\n${got.output.trim()}`408 );409 }410
4 unmodified lines
415 text416 ).pipe(417 Effect.mapError(({ message }) =>418 failed(408 "upload",419 step,420 `${bucket}/${MANIFEST_KEY} doesn't decode, so the platform answers 503 until it is fixed by hand: ${message}`421 )422 )423 )
14 unmodified lines
438 const scratch = yield* fs.makeTempDirectoryScoped({439 prefix: "release-715-",440 });441431 const previous = yield* previousManifest(layout, bucket, scratch);442 const previous = yield* bucketManifest("upload", layout, bucket, scratch);443 const assets = yield* assetsIn(layout);444445 yield* Effect.fromResult(446 unreleased({
19 unmodified lines
466 for (const { file, key } of uploads({467 files: Object.keys(assets),468 version: release.version,469 })) {459 yield* wrangler(layout, scratch, [470 yield* wrangler("upload", layout, scratch, [471 "r2",472 "object",473 "put",474 `${bucket}/${key}`,
52 unmodified lines
527 (missing) =>528 failed("publish", `the staged package lacks ${missing.join(", ")}`)529 )530 );520 });531532 const stage = yield* Effect.fromOption(release.stage).pipe(533 Effect.mapError(() => failed("publish", "a publish names its --stage"))534 );535536 const scratch = yield* FileSystem.FileSystem.pipe(537 Effect.flatMap((fs) => fs.makeTempDirectoryScoped({ prefix: "release-" }))538 );539540 const manifest = yield* bucketManifest(541 "publish",542 layout,543 resources(stage).releases,544 scratch545 );546547 yield* Effect.fromResult(548 servedAsLatest({549 manifest: Option.getOrUndefined(manifest),550 version: release.version,551 })552 ).pipe(Effect.mapError(({ message }) => failed("publish", message)));553 }).pipe(Effect.scoped);554555const publish = (layout: Layout, release: Release) =>556 Effect.andThen(557 publishable(layout, release),558 run(
53 unmodified lines
modified:scripts/lib/release.ts+43 added-5 removed
92 unmodified lines
93 )94 );95};9697// `exports` takes the path with `./`; `bin` takes npm's normal form without98// it, which `npm publish` would otherwise rewrite with a warning.99const BIN = "./dist/bin.js";100101const BIN_TARGET = "dist/bin.js";102103interface LibraryEntry {104 readonly types: string;105 readonly default: string;106}
37 unmodified lines
144 readonly version: string;145 readonly dependencies: Readonly<Record<string, string>>;146 }147): PublishManifest => ({144 bin: { [brand.cli]: BIN, [brand.gitCredentialHelper]: BIN },148 bin: { [brand.cli]: BIN_TARGET, [brand.gitCredentialHelper]: BIN_TARGET },149 dependencies: input.dependencies,150 description: `The ${brand.name} command line: find an ask, claim it, check your answer, and read its verdict; also git's credential helper, and a pi package.`,151 exports: {152 ".": BIN,
73 unmodified lines
226 readonly publish: boolean;227 readonly env: Readonly<Record<string, string | undefined>>;228}229230// A publish reads the stage's release manifest, so it names its stage even231// when it is handed to a person: `runsPublish` is whether this run runs it.232const stepsOf = (227 flags: ReleaseFlags233 flags: ReleaseFlags,234 runsPublish = flags.publish235): Result.Result<readonly ReleaseStep[], NoStage | UnknownStage> => {229 if (flags.stage === undefined && flags.upload) {236 if (flags.stage === undefined && (flags.upload || flags.publish)) {237 return Result.fail(new NoStage());238 }239240 if (flags.stage !== undefined && Option.isNone(declaredStage(flags.stage))) {
3 unmodified lines
244 return Result.succeed([245 ...(flags.build ? BUILD : []),246 ...(flags.build || flags.upload ? RELEASE_FILES : []),247 ...(flags.upload ? (["upload"] as const) : []),241 ...(flags.publish ? (["publish"] as const) : []),248 ...(runsPublish ? (["publish"] as const) : []),249 ]);250};251252export const releasePlan = (
23 unmodified lines
276): Result.Result<ReleaseRun, NoStage | UnknownStage> => {277 const handOver = flags.publish ? agentMarkers(flags.env) : [];278279 return Result.map(273 stepsOf({ ...flags, publish: flags.publish && handOver.length === 0 }),280 stepsOf(flags, flags.publish && handOver.length === 0),281 (steps) => ({ handOver, steps })282 );283};284
83 unmodified lines
368 ? Result.void369 : Result.fail(new VersionReleased({ version: input.version }));370};371372export class NotServedAsLatest extends Schema.TaggedError<NotServedAsLatest>()(373 "NotServedAsLatest",374 { latest: Schema.optionalKey(Schema.String), version: Schema.String }375) {376 override get message() {377 const serves =378 this.latest === undefined ? "serves no release" : `serves ${this.latest}`;379380 return `npm gets only the version the stage's install script serves as latest, and it ${serves}, not ${this.version}: upload --version ${this.version} to the stage first, or in the same run`;381 }382}383384/** npm and the install script give one version: the stage's latest. */385export const servedAsLatest = (input: {386 readonly version: string;387 readonly manifest: ReleaseManifest | undefined;388}): Result.Result<void, NotServedAsLatest> => {389 if (input.manifest === undefined) {390 return Result.fail(new NotServedAsLatest({ version: input.version }));391 }392393 return input.manifest.latest === input.version394 ? Result.void395 : Result.fail(396 new NotServedAsLatest({397 latest: input.manifest.latest,398 version: input.version,399 })400 );401};402403export const MANIFEST_KEY = "releases/manifest.json";404405const byName = <A>(record: Readonly<Record<string, A>>) =>406 Arr.sortWith(Object.entries(record), ([name]) => name, Order.String);
25 unmodified lines
modified:scripts/release.ts+1 added-1 removed
38 unmodified lines
39 "--version",40]);4142const USAGE =43 "bun run release -- [--build] [--upload --stage <dev-…|prod>] [--publish] [--version <semver>] [--origin <url>]";43 "bun run release -- [--build] [--upload] [--publish] [--stage <dev-…|prod>] [--version <semver>] [--origin <url>]";4445// Already said in one line, so the runtime exits 1 without printing it again.46class Reported extends Schema.TaggedError<Reported>()("Reported", {}) {47 override readonly [Runtime.errorReported] = false;
197 unmodified lines
modified:AGENTS.md+1 added-1 removed
66 unmodified lines
67- `smoke -- --stage <stage>`: read-only probes against a live stage. `--since <instant>` then reads the stage's Workers Logs through the SQL API, with infra's credentials (Account Analytics Read), and fails on any exception or error-level line since then. `--loop` then runs the whole core loop on a throwaway project, `smoke-<run>`, through the CLI and git, and refuses `prod`.68- `seed`: puts the two example projects on a platform (`--world node` on this machine, or `--stage <stage>`); a second run changes nothing. `--only <example> --as <name>` seeds a fresh copy under another name, and refuses a taken one. Their projects and people are fictional, so it refuses `prod` unless `--allow-fictional` is given, and each example's README says it is fictional on its page; `swarm` and `smoke --loop` refuse `prod` always.69- `import-examples -- --stage <stage>`: imports the open-source repos the code browser is previewed on, one at a time, onto any declared stage, `prod` included, each recorded in the ledger as kept; `--tags` backfills the tags Artifacts' import leaves out, `--only <name>` imports one, and `--world node` imports onto this machine.70- `swarm -- --stage <stage> --project <name>`: plans six fictional contributors, on four harnesses, against one split family on a stage, claims each one's ask, prepares a workspace with a clone of its fork outside the checkout, starts each harness headless on the brief and sends every refusal back into the same session, at most three times, then writes the run's summary; `--view herdr` runs them in herdr panes beside a counter, and `--dry-run` only prints the plan.71- `release -- --build | --upload --stage <stage> | --publish`: builds the CLI's npm package and two binaries, uploads a release to the stage's own bucket, which the platform serves, and leaves `npm publish` to a person: under an agent it prints the command instead.71- `release -- --build | --upload --stage <stage> | --publish --stage <stage>`: builds the CLI's npm package and two binaries, uploads a release to the stage's own bucket, which the platform serves, and leaves `npm publish` to a person: under an agent it prints the command instead. A publish refuses any version but the one its stage's bucket serves as latest, so npm and the install script give the same CLI.7273## Nouns7475Each code noun has one home:
64 unmodified lines