@r_masseater/msch 0.114.0 → 0.115.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -4,13 +4,13 @@ import { $ as isIdentifier, A as uniqueByReference, B as getTextOfJSDocComment,
4
4
  import { S as workspaceDependencies$1, _ as shadcnUiOf, a as workspaceConfigs, b as installedManifest, c as publicEntriesOf, d as splitFrontmatter, h as deployEntries, i as publishedWorkspaces, l as isIndexSkill, m as bundledEntries, o as entryNameOf, p as workspaceLinks, r as packedWorkspaces, s as isBinEntry, u as FRONTMATTER, x as readManifest, y as dependencyEntries } from "./published-J2q6skGp.mjs";
5
5
  import { C as keyName, D as stringsIn, E as propertyValue, S as childrenOf$4, T as nestedValues, a as workspaceManifest, b as workspaceConfigOf, c as TASK_NAMES, d as definesTask, f as hasVerifyTask, i as workspaceProjects, l as TEST_TASK_NAMES, n as unmatchedWorkspacePatterns, r as workspaceDirectories, s as RUN_TASKS, t as publishedProjects, u as VERIFY_TASK, w as literalOf, x as KeySchema } from "./workspace-projects-DYfp6Tpn.mjs";
6
6
  import { a as parent, i as join, n as isInside, t as baseName$1 } from "./path-DUttmo2s.mjs";
7
- import { n as DECISION_TIMEOUT_MS, r as JAPANESE, t as DECISION_MODEL } from "./config-BBdsNPSO.mjs";
8
- import { a as CI_TASKS, d as isIgnored, l as existsAt, m as patternOf$1, n as builtTextRuleNames, o as MSCH_TASK_COMMANDS, p as namedWorkspaces, r as secretsOf, s as MSCH_VERIFY_COMMANDS, t as TEXT_IGNORES } from "./repository-text-Cu-_rD_Q.mjs";
7
+ import { i as USAGE_SPOOL, n as DECISION_TIMEOUT_MS, r as JAPANESE, t as DECISION_MODEL } from "./config-W6Uy7bV8.mjs";
8
+ import { a as CI_TASKS, c as meteredCommand, f as isIgnored, h as patternOf$1, m as namedWorkspaces, n as builtTextRuleNames, o as MSCH_TASK_COMMANDS, r as secretsOf, s as MSCH_VERIFY_COMMANDS, t as TEXT_IGNORES, u as existsAt } from "./repository-text-B2uz0JJc.mjs";
9
9
  import { t as startedOnce } from "./started-once-muJbvD_I.mjs";
10
- import { g as decisionTestRules, n as MARKDOWN_RULES, p as lint$3, t as MARKDOWN_IGNORES, x as exempt } from "./define-lint-preset-BXnNnSR9.mjs";
10
+ import { g as decisionTestRules, n as MARKDOWN_RULES, p as lint$3, t as MARKDOWN_IGNORES, x as exempt } from "./define-lint-preset-BC6R-LkX.mjs";
11
11
  import { builtinModules, isBuiltin } from "node:module";
12
12
  import { VpToolsError, findCiDrift, runVpa } from "@r_masseater/vite-plus-adopt";
13
- import { Array as Array$1, Boolean as Boolean$1, Clock, Config, Console, Context, Effect, Equal, FileSystem, Function, HashMap, HashSet, Match, Metric, Number as Number$1, Option, Order, Path, Predicate, Record, Result, Runtime, Schedule, Schema, SchemaTransformation, Stdio, Stream, String as String$1, pipe } from "effect";
13
+ import { Array as Array$1, Boolean as Boolean$1, Clock, Config, Console, Context, Effect, Equal, FileSystem, Function, HashMap, HashSet, Match, Metric, Number as Number$1, Option, Order, Path, Predicate, Record, Redacted, Result, Runtime, Schedule, Schema, SchemaTransformation, Stdio, Stream, String as String$1, pipe } from "effect";
14
14
  import { Argument, Command, Flag } from "effect/cli";
15
15
  import { ChildProcess, ChildProcessSpawner } from "effect/process";
16
16
  import { hookFlags } from "@r_masseater/masseater-utils/hook-flags";
@@ -37,13 +37,14 @@ import { parse as parse$2 } from "sql-parser-cst";
37
37
  import { findSkillFiles } from "@tanstack/intent";
38
38
  import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
39
39
  import { runMainWith } from "@r_masseater/masseater-utils/node-main";
40
+ import { dual } from "effect/Function";
40
41
  import { finished, mustSucceed, outputOf, succeeds, writeOutputs } from "@r_masseater/masseater-utils/github-workflow";
41
42
  import { arch, platform } from "node:os";
42
43
  import { Base64 } from "effect/encoding";
43
- import { dual } from "effect/Function";
44
+ import { CALLS_METRIC, mergeTallies, talliesIn, usageMetricsOf } from "@r_masseater/masseater-utils/usage-meter/report";
44
45
  // package.json
45
46
  var name = "@r_masseater/msch";
46
- var version = "0.114.0";
47
+ var version = "0.115.0";
47
48
  var homepage = "https://github.com/masseater/ecosystems/tree/main/libs/msch#readme";
48
49
  var repository = {
49
50
  "type": "git",
@@ -14687,7 +14688,10 @@ const taskWeakenings = (run, expected) => {
14687
14688
  const tasks = sectionOf(sectionOf(run)["tasks"]);
14688
14689
  const dependsOn = listOf$2(sectionOf(tasks[TASK_NAMES.verify])["dependsOn"]);
14689
14690
  return [
14690
- ...pipe(Record.toEntries(expected.tasks), Array$1.filter(([name, command]) => !Equal.equals(sectionOf(tasks[name])["command"], command)), Array$1.map(([name]) => ({
14691
+ ...pipe(Record.toEntries(expected.tasks), Array$1.filter(([name, command]) => {
14692
+ const actual = sectionOf(tasks[name])["command"];
14693
+ return !Equal.equals(actual, command) && !(Predicate.isString(command) && Equal.equals(actual, meteredCommand(command)));
14694
+ }), Array$1.map(([name]) => ({
14691
14695
  anchor: "run",
14692
14696
  message: `The ${name} task does not run what msch builds for it. Leave msch's tasks as repositoryConfig builds them; add other work under another task name.`
14693
14697
  }))),
@@ -20284,2360 +20288,2221 @@ const agentsCommand = Command.make("agents", {
20284
20288
  stateDirectory: Argument.String("state-directory").pipe(Argument.withDescription("The directory that keeps each finished step, so a rerun resumes from it")),
20285
20289
  json: jsonFlag
20286
20290
  }, agents).pipe(Command.withDescription("Has a swarm of agents plan, investigate and refute what the repository's rules and history miss"));
20287
- // src/features/publish-workspace/model/export-targets.ts
20288
- const PATTERN = "*";
20289
- const taggedError$3 = Schema.TaggedError;
20290
- /** @internal */
20291
- var MissingExportTargets = class extends taggedError$3()("MissingExportTargets", { message: Schema.String }) {};
20292
- const singleTarget = (target) => {
20293
- if (String$1.includes(PATTERN)(target)) return [];
20294
- return [target];
20295
- };
20296
- /** @internal */
20297
- const foldExports = (cases) => (exports) => {
20298
- if (Predicate.isString(exports)) return cases.string(exports);
20299
- if (Array$1.isArray(exports)) return cases.array(exports);
20300
- if (Predicate.isReadonlyObject(exports)) return cases.object(exports);
20301
- return cases.other();
20302
- };
20303
- /** @internal */
20304
- const exportTargetsOf = (exports) => foldExports({
20305
- string: singleTarget,
20306
- array: Array$1.flatMap(exportTargetsOf),
20307
- object: (record) => Array$1.flatMap(Record.values(record), exportTargetsOf),
20308
- other: () => []
20309
- })(exports);
20310
- const publishedExportsOf = (manifest) => pipe(Option.fromUndefinedOr(manifest.publishConfig), Option.flatMap((config) => Option.fromUndefinedOr(config.exports)), Option.orElse(() => Option.fromUndefinedOr(manifest.exports)), Option.getOrUndefined);
20311
- const missingMessage = (missing) => `The published exports point to files the build did not write: ${Array$1.join(missing, ", ")}`;
20312
- /** @internal */
20313
- const checkExportTargets = Effect.fn("publish.checkExportTargets")(function* checkExportTargets(directory) {
20314
- const fileSystem = yield* FileSystem.FileSystem;
20315
- const path = yield* Path.Path;
20316
- const manifest = yield* readPackageJson(directory);
20317
- const missing = yield* Effect.filter(exportTargetsOf(publishedExportsOf(manifest)), (target) => Effect.map(fileSystem.exists(path.join(directory, target)), (found) => !found));
20318
- return yield* pipe(missing, Array$1.match({
20319
- onEmpty: () => Effect.void,
20320
- onNonEmpty: (list) => Effect.fail(MissingExportTargets.make({ message: missingMessage(list) }))
20321
- }));
20322
- });
20323
- // src/features/publish-workspace/model/compat-manifest.ts
20324
- const UNVERSIONED$3 = "0.0.0";
20325
- const VITE = "vite";
20326
- /** @internal */
20327
- const VITE_PLUS = "vite-plus";
20328
- const MODULE_EXTENSIONS = [
20329
- ".js",
20330
- ".mjs",
20331
- ".cjs"
20332
- ];
20333
- const taggedError$2 = Schema.TaggedError;
20334
- /** @internal */
20335
- var IncompatiblePackage = class extends taggedError$2()("IncompatiblePackage", { message: Schema.String }) {};
20336
- const lowestOf = (range) => pipe(Option.fromNullishOr(semver.validRange(range)), Option.flatMap(() => Option.fromNullishOr(semver.minVersion(range))), Option.map(({ version }) => version));
20337
- const floorOf = (version) => {
20338
- if (semver.prerelease(version) !== null) return version;
20339
- return `~${String(semver.major(version))}.${String(semver.minor(version))}.0`;
20291
+ // src/features/run-changed/model/batches.ts
20292
+ const ARITY$1 = 2;
20293
+ const NO_BATCHES = [];
20294
+ const EMPTY_BATCH = {
20295
+ units: [],
20296
+ sources: 0
20340
20297
  };
20341
- const pinnedPeer = ([name, range]) => Option.match(lowestOf(range), {
20342
- onNone: () => [],
20343
- onSome: (version) => {
20344
- if (version === UNVERSIONED$3) return [[name, range]];
20345
- return [[name, floorOf(version)]];
20346
- }
20298
+ const bySourcesDescending = Order.mapInput(Order.flip(Order.Number), (unit) => unit.sources);
20299
+ const byName = Order.mapInput(Order.String, (unit) => unit.name);
20300
+ const added = (batch, unit) => ({
20301
+ units: [...batch.units, unit],
20302
+ sources: batch.sources + unit.sources
20347
20303
  });
20348
- const floorPeers = (peers) => pipe(Record.toEntries(peers), Array$1.flatMap(pinnedPeer), Record.fromEntries);
20349
- const nodeFloorOf = (manifest) => pipe(Option.fromUndefinedOr(manifest.engines), Option.flatMap(({ node }) => Option.fromUndefinedOr(node)), Option.flatMap(lowestOf));
20350
- const withoutViteOfVitePlus = (peers) => {
20351
- if (Record.has(peers, "vite-plus")) return Record.remove(peers, VITE);
20352
- return peers;
20353
- };
20354
- /** @internal */
20355
- const viteAliasOf = (vitePlusManifest) => pipe(decodePackageJson(vitePlusManifest), Option.flatMapNullishOr(({ dependencies }) => dependencies), Option.flatMap(Record.get(VITE)), Option.map((spec) => `${VITE}@${spec}`));
20356
- const casesOf = (manifest, floor) => {
20357
- const declared = withoutViteOfVitePlus(manifest.peerDependencies ?? {});
20358
- const latest = `^${String(semver.major(floor))}`;
20359
- return [
20360
- {
20361
- label: "floor",
20362
- node: floorOf(floor),
20363
- peers: floorPeers(declared)
20364
- },
20365
- {
20366
- label: "latest",
20367
- node: latest,
20368
- peers: declared
20369
- },
20370
- {
20371
- label: "npx",
20372
- node: latest,
20373
- peers: {}
20374
- }
20375
- ];
20376
- };
20377
- /** @internal */
20378
- const compatCasesOf = (manifest) => pipe(nodeFloorOf(manifest), Option.match({
20379
- onNone: () => [],
20380
- onSome: (floor) => casesOf(manifest, floor)
20304
+ const joined = (batches, unit, index) => pipe(Array$1.modify(batches, index, (batch) => added(batch, unit)), Option.getOrElse(() => batches));
20305
+ const placed = (batches, unit, limit) => pipe(batches, Array$1.findFirstIndex((batch) => batch.sources + unit.sources <= limit), Option.match({
20306
+ onNone: () => [...batches, added(EMPTY_BATCH, unit)],
20307
+ onSome: (index) => joined(batches, unit, index)
20381
20308
  }));
20382
- const loadsAModule = (target) => pipe(exportTargetsOf(target), Array$1.some((file) => pipe(MODULE_EXTENSIONS, Array$1.some((extension) => String$1.endsWith(extension)(file)))));
20383
- const exportedSubpaths = (exports) => pipe(exportEntriesOf(exports), Array$1.filter(([, target]) => loadsAModule(target)), Array$1.map(([subpath]) => subpath));
20384
- const subpathsOf = foldExports({
20385
- string: () => [ROOT_SUBPATH],
20386
- array: () => [ROOT_SUBPATH],
20387
- object: exportedSubpaths,
20388
- other: () => []
20309
+ const filled = (batches, units, limit) => Array$1.matchLeft(units, {
20310
+ onEmpty: () => batches,
20311
+ onNonEmpty: (unit, rest) => filled(placed(batches, unit, limit), rest, limit)
20389
20312
  });
20390
- const binFilesOf = (bin) => {
20391
- if (Predicate.isUndefined(bin)) return [];
20392
- if (Predicate.isString(bin)) return [bin];
20393
- return Record.values(bin);
20394
- };
20395
- /** @internal */
20396
- const smokeTargetsOf = (manifest) => {
20397
- const published = Option.fromUndefinedOr(manifest.publishConfig);
20398
- const exports = pipe(published, Option.flatMap(({ exports: own }) => Option.fromUndefinedOr(own)), Option.getOrElse(() => manifest.exports));
20399
- const bin = pipe(published, Option.flatMap(({ bin: own }) => Option.fromUndefinedOr(own)), Option.getOrElse(() => manifest.bin));
20400
- return {
20401
- imports: pipe(subpathsOf(exports), Array$1.map((subpath) => importSpecifierOf(manifest.name, subpath))),
20402
- bins: binFilesOf(bin)
20403
- };
20313
+ const batched = (units, limit) => {
20314
+ const ordered = pipe(units, Array$1.sortBy(bySourcesDescending, byName));
20315
+ return pipe(filled(NO_BATCHES, ordered, limit), Array$1.map((batch) => batch.units));
20404
20316
  };
20405
- // src/features/publish-workspace/model/compat-start.ts
20406
- const NOT_LOADED = String.raw`ERR_(MODULE_NOT_FOUND|PACKAGE_|INVALID_PACKAGE|UNKNOWN_FILE|UNSUPPORTED_DIR|REQUIRE_ESM)|SyntaxError`;
20407
- /** @internal */
20408
- const LOAD_FAILURE = `/${NOT_LOADED}/u`;
20409
- /** @internal */
20410
- const CRASH = String.raw`/${NOT_LOADED}|\n\s+at\s.+:\d+:\d+/u`;
20411
- /** @internal */
20412
- const BIN_ARGUMENTS = [["--help"], ["--compat-unknown-flag"]];
20413
- const spawnChecked = (failure) => `import { spawnSync } from "node:child_process"; const { stderr } = spawnSync(process.execPath, process.argv.slice(1), { encoding: "utf8", stdio: ["ignore", "ignore", "pipe"], timeout: 60000 }); if (${failure}.test(stderr)) { process.stderr.write(stderr); process.exit(1); }`;
20414
- /** @internal */
20415
- const loadsCleanly = ({ runtime, consumer, failure, args }) => mustSucceed({
20416
- command: runtime,
20417
- args: [
20418
- "--input-type=module",
20419
- "-e",
20420
- spawnChecked(failure),
20421
- "--",
20422
- ...args
20423
- ],
20424
- cwd: consumer
20425
- });
20426
- // src/features/publish-workspace/model/plugin-lock.ts
20427
- const PLUGIN_FILE = ".claude-plugin/plugin.json";
20428
- const PACKED_ROOT = "package";
20429
- const NPM_LOCK$1 = "package-lock.json";
20430
- const MINIMUM_RELEASE_AGE_DAYS = 1;
20431
- const SCOPE = /^@[^/]+\//u;
20432
- /** @internal */
20433
- const PLUGIN_LOCK = "npm-shrinkwrap.json";
20434
- /** @internal */
20435
- const NPM_QUIET = [
20436
- "--ignore-scripts",
20437
- "--no-audit",
20438
- "--no-fund"
20439
- ];
20440
20317
  /** @internal */
20441
- const isPlugin = Effect.fn("publish.isPlugin")(function* isPlugin(directory) {
20442
- const fileSystem = yield* FileSystem.FileSystem;
20443
- const path = yield* Path.Path;
20444
- return yield* fileSystem.exists(path.join(directory, PLUGIN_FILE));
20318
+ const batchesOf = dual(ARITY$1, batched);
20319
+ // src/features/run-changed/model/records.ts
20320
+ const RECORDS = [...MSCH_CACHE, "changed"];
20321
+ const ARGUMENT_SEPARATOR$1 = "\0";
20322
+ const recordsOf = Effect.fn("recordsOf")(function* recordsOf(root, command) {
20323
+ const files = yield* RepositoryFiles;
20324
+ const name = yield* files.hash(Array$1.join(command, ARGUMENT_SEPARATOR$1));
20325
+ return yield* recordsIn(files.join(root, ...RECORDS, name));
20445
20326
  });
20446
- /** @internal */
20447
- const unpacked = Effect.fn("publish.unpacked")(function* unpacked(tarball, directory) {
20448
- const fileSystem = yield* FileSystem.FileSystem;
20449
- const path = yield* Path.Path;
20450
- yield* fileSystem.makeDirectory(directory, { recursive: true });
20451
- yield* mustSucceed({
20452
- command: "tar",
20453
- args: [
20454
- "-xzf",
20455
- tarball,
20456
- "-C",
20457
- directory
20458
- ]
20459
- });
20460
- return path.join(directory, PACKED_ROOT);
20327
+ // src/features/run-changed/model/units.ts
20328
+ const SEPARATOR$2 = "/";
20329
+ const FIELD_SEPARATOR = "\0";
20330
+ const LINE_SEPARATOR = "\n";
20331
+ const EMPTY = "";
20332
+ const READ_CONCURRENCY$3 = 16;
20333
+ const SOURCE_FILE = /\.[cm]?[jt]sx?$/u;
20334
+ const SHARED_CONFIG = /^(?:[^/]+\.config\.[cm]?[jt]s|tsconfig(?:\.[^/]+)?\.json|\.gitignore)$/u;
20335
+ const memberOf = (names) => (file) => pipe(names, Array$1.findFirst((name) => String$1.startsWith(`${name}${SEPARATOR$2}`)(file)), Option.getOrElse(() => "."));
20336
+ const entryOf = ([file, digest]) => `${file}${FIELD_SEPARATOR}${digest}`;
20337
+ const digested = Effect.fn("digested")(function* digested(root, file) {
20338
+ const files = yield* RepositoryFiles;
20339
+ const digest = yield* files.hashFile(files.join(root, file));
20340
+ return [file, Option.getOrElse(digest, () => EMPTY)];
20461
20341
  });
20462
- /** @internal */
20463
- const installsDependencies = Effect.fn("publish.installsDependencies")(function* installsDependencies(root) {
20464
- const { dependencies } = yield* readVersionedPackageJson(root);
20465
- return pipe(Option.fromUndefinedOr(dependencies), Option.exists((held) => !Record.isEmptyRecord(held)));
20342
+ const hashed = (lines) => Effect.gen(function* hashLines() {
20343
+ return yield* (yield* RepositoryFiles).hash(Array$1.join(lines, LINE_SEPARATOR));
20466
20344
  });
20467
- /** @internal */
20468
- const agedFlags = ({ name, direct }) => pipe(Option.fromNullishOr(SCOPE.exec(name)), Option.map(([scope]) => `${scope}*`), Option.toArray, Array$1.appendAll(direct), Array$1.map((excluded) => `--min-release-age-exclude=${excluded}`), Array$1.prepend(`--min-release-age=${String(MINIMUM_RELEASE_AGE_DAYS)}`));
20469
- const npmLock = (root, flags) => mustSucceed({
20470
- command: "npm",
20471
- args: [
20472
- "install",
20473
- "--package-lock-only",
20474
- `--registry=${PUBLIC_REGISTRY}`,
20475
- ...flags,
20476
- ...NPM_QUIET
20477
- ],
20478
- cwd: root
20345
+ const ownedBy = (listing, name) => Option.getOrElse(Record.get(listing.owned, name), () => []);
20346
+ const entriesIn = (listing, name) => pipe(ownedBy(listing, name), Array$1.map(entryOf));
20347
+ const sourcesIn = (listing, name) => pipe(ownedBy(listing, name), Array$1.filter(([file]) => SOURCE_FILE.test(file))).length;
20348
+ const closureOf$1 = Effect.fn("closureOf")(function* closureOf(root, name) {
20349
+ const files = yield* RepositoryFiles;
20350
+ const directories = yield* workspaceClosure(files.join(root, name));
20351
+ const names = pipe(directories, Array$1.map((directory) => files.relative(root, directory)), Array$1.filter(String$1.isNonEmpty));
20352
+ return Array$1.sort(names, Order.String);
20479
20353
  });
20480
- const lockedOf = Effect.fn("publish.lockedOf")(function* lockedOf(root) {
20481
- const { name, dependencies } = yield* readVersionedPackageJson(root);
20482
- const direct = Record.keys(dependencies ?? {});
20483
- if (Array$1.isReadonlyArrayEmpty(direct)) return Option.none();
20484
- return Option.some({
20354
+ const memberIn = (listing) => (name) => Effect.gen(function* readMember() {
20355
+ const files = yield* RepositoryFiles;
20356
+ return {
20485
20357
  name,
20486
- direct
20487
- });
20358
+ sources: sourcesIn(listing, name),
20359
+ digest: yield* hashed(entriesIn(listing, name)),
20360
+ installed: yield* installedPackages(listing.root, files.join(listing.root, name)),
20361
+ closure: yield* closureOf$1(listing.root, name)
20362
+ };
20488
20363
  });
20489
- const writeLock = (root, locked) => npmLock(root, agedFlags(locked)).pipe(Effect.matchEffect({
20490
- onFailure: () => Console.warn(`${locked.name}: no dependency set is a day old, so the lock takes newer versions`).pipe(Effect.andThen(npmLock(root, []))),
20491
- onSuccess: () => Effect.void
20492
- }));
20493
- /** @internal */
20494
- const lockPlugin = Effect.fn("publish.lockPlugin")(function* lockPlugin(tarball, temporary) {
20495
- const fileSystem = yield* FileSystem.FileSystem;
20496
- const path = yield* Path.Path;
20497
- const unpackedTo = path.join(temporary, "locked");
20498
- const root = yield* unpacked(tarball, unpackedTo);
20499
- const locked = yield* lockedOf(root);
20500
- if (Option.isNone(locked)) return;
20501
- yield* writeLock(root, locked.value);
20502
- yield* fileSystem.rename(path.join(root, NPM_LOCK$1), path.join(root, PLUGIN_LOCK));
20503
- yield* mustSucceed({
20504
- command: "tar",
20505
- args: [
20506
- "-czf",
20507
- tarball,
20508
- "-C",
20509
- unpackedTo,
20510
- PACKED_ROOT
20511
- ]
20512
- });
20513
- });
20514
- // src/features/publish-workspace/model/compat-plugin.ts
20515
- const NPM_LOCK = "package-lock.json";
20516
- const installed = Effect.fn("compat.pluginInstalled")(function* installed(name, root) {
20517
- const fileSystem = yield* FileSystem.FileSystem;
20518
- const path = yield* Path.Path;
20519
- const lock = path.join(root, PLUGIN_LOCK);
20520
- if (!(yield* fileSystem.exists(lock))) return yield* IncompatiblePackage.make({ message: `${name} is a Claude Code plugin with dependencies, but its tarball has no ${PLUGIN_LOCK}, so Claude Code installs none of them` });
20521
- yield* fileSystem.copyFile(lock, path.join(root, NPM_LOCK));
20522
- return yield* mustSucceed({
20523
- command: "npm",
20524
- args: ["ci", ...NPM_QUIET],
20525
- cwd: root
20526
- });
20364
+ const reached = (members) => (closure) => pipe(members, Array$1.filter(({ name }) => Array$1.contains(closure, name)));
20365
+ const linesOf = (found) => {
20366
+ const installed = pipe(found, Array$1.flatMap((member) => member.installed), Array$1.dedupe);
20367
+ const digests = pipe(found, Array$1.map(({ name, digest }) => entryOf([name, digest])));
20368
+ return [...Array$1.sort(installed, Order.String), ...digests];
20369
+ };
20370
+ const sharedKey = Effect.fn("sharedKey")(function* sharedKey(listing, members) {
20371
+ const installed = yield* installedPackages(listing.root, listing.root);
20372
+ const closure = yield* closureOf$1(listing.root, EMPTY);
20373
+ const config = pipe(ownedBy(listing, "."), Array$1.filter(([file]) => SHARED_CONFIG.test(file)), Array$1.map(entryOf));
20374
+ return yield* hashed([
20375
+ ...installed,
20376
+ ...config,
20377
+ ...linesOf(reached(members)(closure))
20378
+ ]);
20527
20379
  });
20528
- const startsBins = Effect.fn("compat.pluginBins")(function* startsBins(manifest, root) {
20529
- const path = yield* Path.Path;
20530
- const startOf = (file) => {
20531
- const started = Array$1.prepend(path.join(root, file));
20532
- return pipe(BIN_ARGUMENTS, Array$1.map(started));
20380
+ const rootPaths = (listing) => pipe(ownedBy(listing, "."), Array$1.map(([file]) => file), Array$1.map((file) => {
20381
+ const [top] = String$1.split(file, SEPARATOR$2);
20382
+ if (pipe(listing.names, Array$1.some((name) => String$1.startsWith(`${top}${SEPARATOR$2}`)(name)))) return file;
20383
+ return top;
20384
+ }), Array$1.dedupe);
20385
+ const rootUnit = Effect.fn("rootUnit")(function* rootUnit(listing, shared) {
20386
+ const key = yield* hashed([
20387
+ shared,
20388
+ ".",
20389
+ ...entriesIn(listing, ".")
20390
+ ]);
20391
+ return {
20392
+ name: ".",
20393
+ paths: rootPaths(listing),
20394
+ key,
20395
+ sources: sourcesIn(listing, ".")
20533
20396
  };
20534
- const runs = pipe(smokeTargetsOf(manifest).bins, Array$1.flatMap(startOf));
20535
- yield* Effect.forEach(runs, (args) => loadsCleanly({
20536
- runtime: process.execPath,
20537
- consumer: root,
20538
- failure: CRASH,
20539
- args
20540
- }), {
20541
- concurrency: 1,
20542
- discard: true
20543
- });
20544
20397
  });
20545
- /** @internal */
20546
- const checkPluginInstall = Effect.fn("compat.plugin")(function* checkPluginInstall(directory, manifest, tarballs) {
20547
- const tarball = Record.get(tarballs, manifest.name);
20548
- if (!(yield* isPlugin(directory)) || Option.isNone(tarball)) return;
20549
- const cache = yield* (yield* FileSystem.FileSystem).makeTempDirectoryScoped();
20550
- const root = yield* unpacked(tarball.value, cache);
20551
- if (yield* installsDependencies(root)) yield* installed(manifest.name, root);
20552
- yield* Console.log(`${manifest.name} plugin: installed the way Claude Code caches it`);
20553
- yield* startsBins(manifest, root);
20554
- }, Effect.scoped);
20555
- // src/features/publish-workspace/model/platforms.ts
20556
- const RUNNERS = {
20557
- linux: "ubuntu-latest",
20558
- windows: "windows-latest",
20559
- macos: "macos-latest"
20560
- };
20561
- const NODE_PLATFORMS = {
20562
- linux: "linux",
20563
- win32: "windows",
20564
- darwin: "macos"
20565
- };
20566
- const BUILD = "release:";
20567
- const CHECK = "release:check:";
20568
- const LIBC = {
20569
- gnu: "glibc",
20570
- musl: "musl"
20571
- };
20572
- const CPU_INDEX = 1;
20573
- const ABI_INDEX = 2;
20574
- const systems = Record.keys(RUNNERS);
20575
- const runnersFor = (tasks, prefix) => pipe(systems, Array$1.filter((os) => Array$1.contains(tasks, `${prefix}${os}`)), Array$1.map((os) => ({
20576
- os,
20577
- runner: RUNNERS[os]
20398
+ const memberUnit = (shared, members) => (member) => hashed([
20399
+ shared,
20400
+ member.name,
20401
+ ...linesOf(reached(members)(member.closure))
20402
+ ]).pipe(Effect.map((key) => ({
20403
+ name: member.name,
20404
+ paths: [member.name],
20405
+ key,
20406
+ sources: member.sources
20578
20407
  })));
20579
- /** @internal */
20580
- const buildsOf = (tasks) => runnersFor(tasks, BUILD);
20581
- /** @internal */
20582
- const checksOf = (tasks) => runnersFor(tasks, CHECK);
20583
- /** @internal */
20584
- const nativeTargetsOf = (targets) => pipe(targets, Array$1.flatMap((target) => pipe(Array$1.head(String$1.split(target, "-")), Option.flatMap((platform) => Record.get(NODE_PLATFORMS, platform)), Option.map((os) => ({
20585
- target,
20586
- runner: RUNNERS[os]
20587
- })), Option.toArray)));
20588
- const libcOf = (parts) => pipe(Array$1.get(parts, ABI_INDEX), Option.flatMap((abi) => Record.get(LIBC, abi)), Option.match({
20589
- onNone: () => ({}),
20590
- onSome: (libc) => ({ libc: [libc] })
20591
- }));
20592
- /** @internal */
20593
- const nativeFileOf = ({ binary, target }) => `${binary}.${target}.node`;
20594
- /** @internal */
20595
- const nativeFields = (native) => {
20596
- const parts = String$1.split(native.target, "-");
20597
- const file = nativeFileOf(native);
20598
- return {
20599
- name: `${native.name}-${native.target}`,
20600
- version: native.version,
20601
- os: Option.toArray(Array$1.head(parts)),
20602
- cpu: Option.toArray(Array$1.get(parts, CPU_INDEX)),
20603
- ...libcOf(parts),
20604
- main: file,
20605
- files: [file]
20408
+ const unitsOf = Effect.fn("unitsOf")(function* unitsOf(root) {
20409
+ const listed = yield* (yield* RepositoryFiles).listedFiles(root);
20410
+ const names = yield* workspaceDirectories(root);
20411
+ const entries = yield* Effect.forEach(listed, (file) => digested(root, file), { concurrency: READ_CONCURRENCY$3 });
20412
+ const listing = {
20413
+ root,
20414
+ names,
20415
+ owned: Array$1.groupBy(entries, ([file]) => memberOf(names)(file))
20606
20416
  };
20607
- };
20608
- /** @internal */
20609
- const nativeReadme = ({ name, target }) => `# ${name}-${target}\n\nThe prebuilt ${target} native addon of [${name}](https://www.npmjs.com/package/${name}). Install ${name} instead; npm picks this package for your platform.\n`;
20610
- // src/features/publish-workspace/model/native-package.ts
20611
- const NPM_DIR = "npm";
20612
- const NATIVE_DIR = "native";
20613
- const KEPT_FIELDS = [
20614
- "license",
20615
- "repository",
20616
- "homepage",
20617
- "bugs",
20618
- "engines"
20619
- ];
20620
- const keptFields = Effect.fn("keptFields")(function* keptFields(directory) {
20621
- const fields = yield* readRawPackageJson(directory);
20622
- return pipe(fields, Record.filter((_value, key) => Array$1.contains(KEPT_FIELDS, key)));
20417
+ const members = yield* Effect.forEach(names, memberIn(listing), { concurrency: READ_CONCURRENCY$3 });
20418
+ const shared = yield* sharedKey(listing, members);
20419
+ const units = yield* Effect.forEach(members, memberUnit(shared, members), { concurrency: 1 });
20420
+ return [yield* rootUnit(listing, shared), ...units];
20623
20421
  });
20624
- /** @internal */
20625
- const writeNative = Effect.fn("publish.writeNative")(function* writeNative(directory, native) {
20626
- const fileSystem = yield* FileSystem.FileSystem;
20627
- const path = yield* Path.Path;
20628
- const kept = yield* keptFields(directory);
20629
- const target = path.resolve(directory, NPM_DIR, native.target);
20630
- const file = nativeFileOf(native);
20631
- yield* fileSystem.makeDirectory(target, { recursive: true });
20632
- yield* fileSystem.copyFile(path.join(directory, NATIVE_DIR, file), path.join(target, file));
20633
- yield* Effect.all([writePackageJson(target, {
20634
- ...kept,
20635
- ...nativeFields(native)
20636
- }), fileSystem.writeFileString(path.join(target, "README.md"), nativeReadme(native))], { concurrency: "unbounded" });
20637
- return target;
20422
+ // src/features/run-changed/model/run.ts
20423
+ const SUCCESS$4 = 0;
20424
+ const LIST_SEPARATOR = ", ";
20425
+ const ARGUMENT_SEPARATOR = " ";
20426
+ const EVERYTHING = "everything";
20427
+ const SINGLE_BATCH = 1;
20428
+ const report = Effect.fn("report")(function* report(text) {
20429
+ const stdio = yield* Stdio.Stdio;
20430
+ yield* Stream.make(`msch changed: ${text}\n`).pipe(Stream.run(stdio.stderr()), Effect.orDie);
20638
20431
  });
20639
- // src/features/publish-workspace/model/pack-hook.ts
20640
- const HOOK_FILE = "pack-hook.mjs";
20641
- /** @internal */
20642
- const WIDEN_RANGES = `const EXACT = /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$/u;
20643
- const widen = (held) =>
20644
- held === undefined
20645
- ? undefined
20646
- : Object.fromEntries(Object.entries(held).map(([name, specifier]) => [name, EXACT.test(specifier) ? \`^\${specifier}\` : specifier]));
20647
- export const hooks = {
20648
- beforePacking: (manifest) => ({
20649
- ...manifest,
20650
- dependencies: widen(manifest.dependencies),
20651
- peerDependencies: widen(manifest.peerDependencies),
20652
- }),
20432
+ const pathsOf = (units, changed) => {
20433
+ if (changed.length === units.length) return [];
20434
+ return pipe(changed, Array$1.flatMap(({ paths }) => paths));
20653
20435
  };
20654
- `;
20655
- /** @internal */
20656
- const LOCKABLE_PLUGIN = `export const hooks = {
20657
- beforePacking: ({ devDependencies, ...manifest }) => manifest,
20436
+ const namesOf = (units, changed) => {
20437
+ if (changed.length === units.length) return EVERYTHING;
20438
+ return pipe(changed, Array$1.map(({ name }) => name), Array$1.join(LIST_SEPARATOR));
20658
20439
  };
20659
- `;
20660
- const hookOf = (plugin) => {
20661
- if (plugin) return LOCKABLE_PLUGIN;
20662
- return WIDEN_RANGES;
20440
+ const exitCodeOf = Effect.fn("exitCodeOf")(function* exitCodeOf(root, [command, ...args]) {
20441
+ const code = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make(command, args, {
20442
+ cwd: root,
20443
+ extendEnv: true,
20444
+ stdin: "ignore",
20445
+ stdout: "inherit",
20446
+ stderr: "inherit"
20447
+ }));
20448
+ return Number(code);
20449
+ });
20450
+ const keyOf = ({ key }) => key;
20451
+ const keysAfter = (plan, records, batch) => {
20452
+ const current = pipe(plan.units, Array$1.map(keyOf));
20453
+ const kept = pipe(records.passed, Array$1.filter((key) => Array$1.contains(current, key)));
20454
+ return Array$1.dedupe([...kept, ...pipe(batch, Array$1.map(keyOf))]);
20663
20455
  };
20664
- /** @internal */
20665
- const packHookEnv = Effect.fn("publish.packHook")(function* packHookEnv(directory, plugin) {
20666
- const fileSystem = yield* FileSystem.FileSystem;
20667
- const hook = (yield* Path.Path).join(directory, HOOK_FILE);
20668
- yield* fileSystem.writeFileString(hook, hookOf(plugin));
20669
- return { pnpm_config_pnpmfile: hook };
20456
+ const ranBatch = Effect.fn("ranBatch")(function* ranBatch(plan, batch) {
20457
+ const code = yield* exitCodeOf(plan.root, [...plan.command, ...pathsOf(plan.units, batch)]);
20458
+ const records = yield* recordsOf(plan.root, plan.command);
20459
+ const keys = keysAfter(plan, records, batch);
20460
+ yield* Effect.when(keepOnly(records, keys), Effect.succeed(code === SUCCESS$4));
20461
+ return code;
20462
+ });
20463
+ const ran = Effect.fn("ran")(function* ran(plan, batchSources) {
20464
+ const batches = batchesOf(plan.changed, batchSources);
20465
+ yield* Effect.when(report(`${String(batches.length)} batches of at most ${String(batchSources)} source files`), Effect.succeed(batches.length > SINGLE_BATCH));
20466
+ const codes = yield* Effect.forEach(batches, (batch) => ranBatch(plan, batch), { concurrency: 1 });
20467
+ return pipe(codes, Array$1.findFirst((code) => code !== SUCCESS$4), Option.getOrElse(() => SUCCESS$4));
20670
20468
  });
20671
- // src/features/publish-workspace/model/pack.ts
20672
- const TARBALL = "package.tgz";
20673
20469
  /** @internal */
20674
- const pack = Effect.fn("publish.pack")(function* pack(directory) {
20675
- const fileSystem = yield* FileSystem.FileSystem;
20676
- const path = yield* Path.Path;
20677
- const temporary = yield* fileSystem.makeTempDirectoryScoped();
20678
- const tarball = path.join(temporary, TARBALL);
20679
- const plugin = yield* isPlugin(directory);
20680
- const env = yield* packHookEnv(temporary, plugin);
20681
- yield* mustSucceed({
20682
- command: "vp",
20683
- args: [
20684
- "pm",
20685
- "pack",
20686
- "--out",
20687
- tarball
20688
- ],
20689
- env,
20690
- cwd: directory
20691
- });
20692
- if (plugin) yield* lockPlugin(tarball, temporary);
20693
- return tarball;
20470
+ const runChanged = Effect.fn("runChanged")(function* runChanged(root, { command, batchSources }) {
20471
+ const units = yield* unitsOf(root);
20472
+ const records = yield* recordsOf(root, command);
20473
+ const changed = pipe(units, Array$1.filter(({ key }) => !Array$1.contains(records.passed, key)));
20474
+ const since = `since \`${Array$1.join(command, ARGUMENT_SEPARATOR)}\` last passed`;
20475
+ if (!Array$1.isReadonlyArrayNonEmpty(changed)) {
20476
+ yield* report(`nothing changed ${since}`);
20477
+ return SUCCESS$4;
20478
+ }
20479
+ yield* report(`${String(changed.length)} of ${String(units.length)} changed ${since}: ${namesOf(units, changed)}`);
20480
+ return yield* ran({
20481
+ root,
20482
+ command,
20483
+ units,
20484
+ changed
20485
+ }, batchSources);
20694
20486
  });
20695
- // src/features/publish-workspace/model/compat-native.ts
20696
- const HOST_PREFIX = `${platform()}-${arch()}-`;
20697
- const builtOf$1 = (directory, manifest) => pipe(Option.fromUndefinedOr(manifest.native), Option.flatMap(({ binary, targets }) => pipe(targets, Array$1.findFirst(String$1.startsWith(HOST_PREFIX)), Option.map((target) => ({
20698
- directory,
20699
- manifest,
20700
- binary,
20701
- target
20702
- })))));
20703
- const packedNative = Effect.fn("compat.packedNative")(function* packedNative({ directory, manifest, binary, target }) {
20704
- const written = yield* writeNative(directory, {
20705
- name: manifest.name,
20706
- version: manifest.version,
20707
- binary,
20708
- target
20709
- });
20710
- const tarball = yield* pack(written);
20711
- return [[`${manifest.name}-${target}`, tarball]];
20487
+ // src/app/changed-command.ts
20488
+ const SUCCESS$3 = 0;
20489
+ const ONE_FAILURE$1 = 1;
20490
+ const NO_LIMIT = Number.POSITIVE_INFINITY;
20491
+ const atLeastOne = Schema.isGreaterThanOrEqualTo(1);
20492
+ const BatchSize = Schema.Int.check(atLeastOne);
20493
+ const changed = Effect.fn("changed")(function* changed(input) {
20494
+ const files = yield* RepositoryFiles;
20495
+ if ((yield* runChanged(files.resolve("."), {
20496
+ batchSources: input.batchSources,
20497
+ command: [input.program, ...input.rest]
20498
+ })) !== SUCCESS$3) return yield* ProblemsFound.make({ count: ONE_FAILURE$1 });
20499
+ return yield* Effect.void;
20712
20500
  });
20713
20501
  /** @internal */
20714
- const nativeTarballs = Effect.fn("compat.native")(function* nativeTarballs(directory, manifest) {
20715
- const none = [];
20716
- return yield* pipe(builtOf$1(directory, manifest), Option.match({
20717
- onNone: () => Effect.succeed(none),
20718
- onSome: packedNative
20719
- }));
20502
+ const changedCommand = Command.make("changed", {
20503
+ batchSources: Flag.Int("batch-sources").pipe(Flag.withDescription("Runs the command in batches of at most this many source files"), Flag.withSchema(BatchSize), Flag.withDefault(NO_LIMIT)),
20504
+ program: Argument.String("command").pipe(Argument.withDescription("The command to run, written after --")),
20505
+ rest: Argument.String("argument").pipe(Argument.withDescription("The arguments of the command"), Argument.variadic())
20506
+ }, changed).pipe(Command.withDescription("Runs a command with the paths of the workspaces whose inputs changed since it last passed"));
20507
+ // src/app/lookup-report.ts
20508
+ const NONE_FOUND = 0;
20509
+ const LINE_BREAK$1 = "\n";
20510
+ const byPlace = Order.Struct({
20511
+ file: Order.String,
20512
+ line: Order.Number
20720
20513
  });
20721
- // src/features/publish-workspace/model/compat-workspace.ts
20722
- const closureOf$1 = (known, names, seen) => {
20723
- const [name, ...rest] = names;
20724
- if (Predicate.isUndefined(name)) return seen;
20725
- const found = Record.get(known, name);
20726
- const reached = pipe(seen, Array$1.some((item) => item.manifest.name === name));
20727
- if (Option.isNone(found) || reached) return closureOf$1(known, rest, seen);
20728
- const inner = closureOf$1(known, runtimeDependencyNames(found.value.manifest), [...seen, found.value]);
20729
- return closureOf$1(known, rest, inner);
20514
+ const textOf = (row, describe) => (json, rows) => {
20515
+ if (json) return Schema.encodeEffect(row.pipe(Schema.Array, Schema.fromJsonString))(rows);
20516
+ return Effect.succeed(pipe(rows, Array$1.map((found) => `${describe(found)}${LINE_BREAK$1}`), Array$1.join("")));
20730
20517
  };
20731
20518
  /** @internal */
20732
- const workspacesBeside = Effect.fn("compat.workspaces")(function* workspacesBeside(directory) {
20733
- const fileSystem = yield* FileSystem.FileSystem;
20734
- const path = yield* Path.Path;
20735
- const parent = path.dirname(path.resolve(directory));
20736
- const entries = yield* fileSystem.readDirectory(parent);
20737
- const found = yield* Effect.forEach(entries, (entry) => readVersionedPackageJson(path.join(parent, entry)).pipe(Effect.map((manifest) => [{
20738
- directory: path.join(parent, entry),
20739
- manifest
20740
- }]), Effect.orElseSucceed(() => [])), { concurrency: 1 });
20741
- return pipe(Array$1.flatten(found), Array$1.map((workspace) => [workspace.manifest.name, workspace]), Record.fromEntries);
20519
+ const lookupReport = ({ row, rows, describe }) => (json) => Effect.gen(function* report() {
20520
+ const found = yield* rows((yield* RepositoryFiles).resolve("."));
20521
+ const text = yield* textOf(row, describe)(json, Array$1.sort(found, byPlace));
20522
+ yield* writeStdout(text);
20523
+ if (found.length > NONE_FOUND) return yield* ProblemsFound.make({ count: found.length });
20524
+ return NONE_FOUND;
20742
20525
  });
20743
- const builtTarball = Effect.fn("compat.pack")(function* builtTarball(directory) {
20744
- yield* mustSucceed({
20745
- command: "vp",
20746
- args: ["run", "build"],
20747
- cwd: directory
20748
- });
20749
- return yield* pack(directory);
20526
+ // src/app/exits-command.ts
20527
+ const MetRow = Schema.Struct({
20528
+ file: Schema.String,
20529
+ line: Schema.Finite,
20530
+ section: Schema.String,
20531
+ key: Schema.String,
20532
+ condition: Schema.String,
20533
+ outcome: Schema.Literals(["met", "unchecked"])
20750
20534
  });
20751
- const tarballsOf = Effect.fn("compat.tarballs")(function* tarballsOf({ directory, manifest }) {
20752
- const tarball = yield* builtTarball(directory);
20753
- const natives = yield* nativeTarballs(directory, manifest);
20754
- const own = [[manifest.name, tarball]];
20755
- return {
20756
- name: manifest.name,
20757
- version: manifest.version,
20758
- tarballs: Record.fromEntries([...own, ...natives])
20759
- };
20535
+ const VERDICTS$2 = {
20536
+ met: "is met. Remove the deviation and run verify.",
20537
+ unchecked: "could not be checked. Check it by hand or rerun where the lookup is reachable."
20538
+ };
20539
+ const describeRow$3 = (row) => `${row.file}:${String(row.line)} ${row.section} ${row.key}: the exit condition ${row.condition} ${VERDICTS$2[row.outcome]}`;
20540
+ const rowsIn = Effect.fn("rowsIn")(function* rowsIn(root) {
20541
+ const files = yield* RepositoryFiles;
20542
+ const met = yield* upstreamExitsMet(root);
20543
+ return pipe(met, Array$1.map(({ file, met: { entry, condition, outcome } }) => ({
20544
+ file: files.relative(root, file),
20545
+ line: entry.line,
20546
+ section: entry.section,
20547
+ key: entry.key,
20548
+ condition,
20549
+ outcome
20550
+ })));
20760
20551
  });
20761
20552
  /** @internal */
20762
- const workspaceTarballs = Effect.fn("compat.local")(function* workspaceTarballs(directory, manifest) {
20763
- const known = yield* workspacesBeside(directory);
20764
- const reached = closureOf$1(known, runtimeDependencyNames(manifest), [{
20765
- directory,
20766
- manifest
20767
- }]);
20768
- return yield* Effect.forEach(reached, tarballsOf, { concurrency: 1 });
20553
+ const exitsCommand = Command.make("exits", { json: jsonFlag }, ({ json }) => lookupReport({
20554
+ row: MetRow,
20555
+ rows: rowsIn,
20556
+ describe: describeRow$3
20557
+ })(json)).pipe(Command.withDescription("Reports upstream deviations whose exit condition is met"));
20558
+ // src/features/judge-documents/model/agent-prompt.ts
20559
+ /** @internal */
20560
+ const AgentAnswer = Schema.Struct({
20561
+ verdict: Schema.Literals([
20562
+ "violation",
20563
+ "pass",
20564
+ "unknown"
20565
+ ]),
20566
+ quote: Schema.String,
20567
+ reason: Schema.String
20769
20568
  });
20770
- const meetsPeer = (peers) => ({ name, version }) => Option.match(Record.get(peers, name), {
20771
- onNone: () => true,
20772
- onSome: (range) => semver.validRange(range) === null || semver.satisfies(version, range)
20569
+ /** @internal */
20570
+ const AGENT_SCHEMA = Schema.toJsonSchemaDocument(AgentAnswer).schema;
20571
+ const listOf = (names) => pipe(names, Array$1.map((name) => `- ${name}`), Array$1.join("\n"));
20572
+ const readableNames = (context) => pipe(context, Array$1.map(({ name }) => name));
20573
+ /** @internal */
20574
+ const promptOf = ({ rule, target, context }) => pipe([
20575
+ "Judge one rule against one file. The working directory holds only the files you may read.",
20576
+ `Rule: ${rule.question}`,
20577
+ `Target file: ${target.name}`,
20578
+ "Other readable files:",
20579
+ listOf(readableNames(context)),
20580
+ "Read the target file, and read the other files when the rule needs them.",
20581
+ "Answer \"violation\" only when the target file breaks the rule, \"pass\" when it does not, and \"unknown\" when these files do not let you decide.",
20582
+ "For a violation, copy the offending text from the target file exactly as written into quote, without paraphrase and without added or removed characters. Leave quote empty otherwise.",
20583
+ "Give the reason in one sentence."
20584
+ ], Array$1.join("\n"));
20585
+ // src/features/judge-documents/model/verdict.ts
20586
+ const LINE_BREAK = "\n";
20587
+ const FIRST_LINE$1 = 1;
20588
+ const Violation = Schema.Struct({
20589
+ status: Schema.Literal("violation"),
20590
+ line: Schema.Int,
20591
+ quote: Schema.String,
20592
+ reason: Schema.String
20593
+ });
20594
+ const Pass = Schema.Struct({ status: Schema.Literal("pass") });
20595
+ Schema.Struct({
20596
+ status: Schema.Literal("unknown"),
20597
+ reason: Schema.String
20773
20598
  });
20774
20599
  /** @internal */
20775
- const tarballsFor = (peers) => (local) => pipe(local, Array$1.filter(meetsPeer(peers)), Array$1.flatMap(({ tarballs }) => Record.toEntries(tarballs)), Record.fromEntries);
20776
- // src/features/publish-workspace/model/compat.ts
20777
- const INSTALL_FLAGS = ["--no-audit", "--no-fund"];
20778
- const IMPORT_ONLY = "await import(process.argv[1])";
20779
- const Versions$1 = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
20780
- const installedNode = Effect.fn("compat.node")(function* installedNode(directory, range) {
20600
+ const DecidedVerdictSchema = Schema.Union([Violation, Pass]);
20601
+ /** @internal */
20602
+ const unknownBecause = (reason) => ({
20603
+ status: "unknown",
20604
+ reason
20605
+ });
20606
+ /** @internal */
20607
+ const isDecided = (verdict) => verdict.status !== "unknown";
20608
+ /** @internal */
20609
+ const textOfLine = ({ text, line }) => pipe(String$1.split(text, LINE_BREAK), Array$1.get(line - FIRST_LINE$1), Option.getOrElse(() => ""));
20610
+ // src/features/judge-documents/model/agent-judge.ts
20611
+ const AGENT_MODEL = "claude-sonnet-5-5";
20612
+ const AGENT_EFFORT = "medium";
20613
+ const AGENT_TOOLS = [
20614
+ "Read",
20615
+ "Grep",
20616
+ "Glob"
20617
+ ];
20618
+ const AGENT_MAX_TURNS = 50;
20619
+ const AGENT_TIMEOUT = "10 minutes";
20620
+ const sandboxOf = Effect.fn("sandboxOf")(function* sandboxOf(files) {
20621
+ const fs = yield* FileSystem.FileSystem;
20781
20622
  const path = yield* Path.Path;
20782
- yield* (yield* FileSystem.FileSystem).makeDirectory(directory, { recursive: true });
20783
- const listed = yield* outputOf({
20784
- command: "npm",
20785
- args: [
20786
- "view",
20787
- "node",
20788
- "versions",
20789
- "--json"
20790
- ],
20791
- cwd: directory
20792
- });
20793
- const versions = yield* Schema.decodeEffect(Versions$1)(listed);
20794
- const version = yield* Effect.fromOption(Option.fromNullishOr(semver.maxSatisfying([...versions], range))).pipe(Effect.mapError(() => IncompatiblePackage.make({ message: `No Node.js release satisfies ${range}` })));
20795
- yield* mustSucceed({
20796
- command: "npm",
20797
- args: [
20798
- "install",
20799
- ...INSTALL_FLAGS,
20800
- `node@${version}`
20801
- ],
20802
- cwd: directory
20623
+ const directory = yield* fs.makeTempDirectoryScoped({ prefix: "msch-judge-" });
20624
+ yield* Effect.forEach(files, ({ name, text }) => {
20625
+ const file = path.join(directory, name);
20626
+ return fs.makeDirectory(path.dirname(file), { recursive: true }).pipe(Effect.andThen(fs.writeFileString(file, text)));
20627
+ }, {
20628
+ concurrency: "unbounded",
20629
+ discard: true
20803
20630
  });
20804
- return {
20805
- version,
20806
- binary: path.join(directory, "node_modules", "node", "bin", "node")
20807
- };
20808
- });
20809
- const consumerFields = ({ peers, tarballs }) => ({
20810
- private: true,
20811
- type: "module",
20812
- dependencies: {
20813
- ...peers,
20814
- ...pipe(tarballs, Record.map((file) => `file:${file}`))
20815
- },
20816
- overrides: Record.fromIterableWith(Record.keys(tarballs), (sibling) => [sibling, `$${sibling}`])
20817
- });
20818
- const withViteOfVitePlus = Effect.fn("compat.vite")(function* withViteOfVitePlus(directory) {
20819
- const fileSystem = yield* FileSystem.FileSystem;
20820
- const path = yield* Path.Path;
20821
- const text = yield* fileSystem.readFileString(path.join(directory, "node_modules", VITE_PLUS, PACKAGE_JSON_FILE));
20822
- yield* Option.match(viteAliasOf(text), {
20823
- onNone: () => Effect.void,
20824
- onSome: (alias) => mustSucceed({
20825
- command: "npm",
20826
- args: [
20827
- "install",
20828
- "--ignore-scripts",
20829
- "--force",
20830
- ...INSTALL_FLAGS,
20831
- alias
20832
- ],
20833
- cwd: directory
20834
- })
20835
- });
20836
- });
20837
- const installedConsumer = Effect.fn("compat.consumer")(function* installedConsumer(root, consumer) {
20838
- const fileSystem = yield* FileSystem.FileSystem;
20839
- const directory = (yield* Path.Path).join(root, "consumer");
20840
- yield* fileSystem.makeDirectory(directory, { recursive: true });
20841
- yield* writePackageJson(directory, consumerFields(consumer));
20842
- yield* mustSucceed({
20843
- command: "npm",
20844
- args: [
20845
- "install",
20846
- "--ignore-scripts",
20847
- ...INSTALL_FLAGS
20848
- ],
20849
- cwd: directory
20850
- });
20851
- if (Record.has(consumer.peers, "vite-plus")) yield* withViteOfVitePlus(directory);
20852
20631
  return directory;
20853
20632
  });
20854
- const importsOf = (manifest, compat) => {
20855
- if (compat.label === "npx") return [];
20856
- return smokeTargetsOf(manifest).imports;
20857
- };
20858
- const smoke = Effect.fn("compat.smoke")(function* smoke({ manifest, compat, runtime, consumer }) {
20859
- const path = yield* Path.Path;
20860
- const importer = [
20861
- "--input-type=module",
20862
- "-e",
20863
- IMPORT_ONLY
20864
- ];
20865
- const runs = pipe(smokeTargetsOf(manifest).bins, Array$1.flatMap((file) => pipe(BIN_ARGUMENTS, Array$1.map((args) => [path.join(consumer, "node_modules", manifest.name, file), ...args]))));
20866
- yield* Effect.forEach(importsOf(manifest, compat), (specifier) => loadsCleanly({
20867
- runtime,
20868
- consumer,
20869
- failure: LOAD_FAILURE,
20870
- args: [...importer, specifier]
20633
+ const verdictOf = (target, answer) => {
20634
+ if (answer.verdict === "pass") return { status: "pass" };
20635
+ if (answer.verdict === "unknown") return unknownBecause(answer.reason);
20636
+ return Option.match(lineOfQuote({
20637
+ text: target.text,
20638
+ quote: answer.quote
20871
20639
  }), {
20872
- concurrency: 1,
20873
- discard: true
20640
+ onNone: () => unknownBecause("the quoted text is not in the target file"),
20641
+ onSome: (line) => ({
20642
+ status: "violation",
20643
+ line,
20644
+ quote: answer.quote,
20645
+ reason: answer.reason
20646
+ })
20874
20647
  });
20875
- yield* Effect.forEach(runs, (args) => loadsCleanly({
20876
- runtime,
20877
- consumer,
20878
- failure: CRASH,
20879
- args
20880
- }), {
20881
- concurrency: 1,
20882
- discard: true
20648
+ };
20649
+ const judgeIn = Effect.fn("agentJudge")(function* judging(query, input) {
20650
+ const output = yield* query({
20651
+ directory: yield* sandboxOf([input.target, ...input.context]),
20652
+ prompt: promptOf(input),
20653
+ schema: AGENT_SCHEMA,
20654
+ tools: AGENT_TOOLS,
20655
+ allowed: AGENT_TOOLS,
20656
+ model: AGENT_MODEL,
20657
+ effort: AGENT_EFFORT,
20658
+ maxTurns: AGENT_MAX_TURNS
20883
20659
  });
20660
+ const answer = yield* Schema.decodeUnknownEffect(AgentAnswer)(output);
20661
+ return verdictOf(input.target, answer);
20884
20662
  });
20885
- const runCase = Effect.fn("compat.case")(function* runCase({ manifest, local, compat }) {
20886
- const fileSystem = yield* FileSystem.FileSystem;
20887
- const path = yield* Path.Path;
20888
- const root = yield* fileSystem.makeTempDirectoryScoped();
20889
- const runtime = yield* installedNode(path.join(root, "runtime"), compat.node);
20890
- const tarballs = tarballsFor(compat.peers)(local);
20891
- const consumer = yield* installedConsumer(root, {
20892
- peers: compat.peers,
20893
- tarballs
20894
- });
20895
- const peers = pipe(Record.toEntries(compat.peers), Array$1.map(([name, range]) => `${name}@${range}`), Array$1.join(", "));
20896
- yield* Console.log(`${manifest.name} ${compat.label}: Node.js ${runtime.version}, peers ${peers}`);
20897
- yield* smoke({
20898
- manifest,
20899
- compat,
20900
- runtime: runtime.binary,
20901
- consumer
20902
- });
20903
- }, Effect.scoped);
20663
+ const reasonOf$1 = (failure) => {
20664
+ if (typeof failure === "string") return failure;
20665
+ if (failure instanceof Error) return failure.message;
20666
+ return String(failure);
20667
+ };
20904
20668
  /** @internal */
20905
- const checkCompat = Effect.fn("publish.compat")(function* checkCompat(directory) {
20906
- const manifest = yield* readVersionedPackageJson(directory);
20907
- const cases = compatCasesOf(manifest);
20908
- if (Array$1.isReadonlyArrayEmpty(cases)) return yield* IncompatiblePackage.make({ message: `${manifest.name} declares no engines.node, so there is no supported Node.js range to check` });
20909
- const local = yield* workspaceTarballs(directory, manifest);
20910
- yield* Effect.forEach(cases, (compat) => runCase({
20911
- manifest,
20912
- local,
20913
- compat
20914
- }), {
20915
- concurrency: 1,
20916
- discard: true
20669
+ const agentJudge = (query) => ({
20670
+ identity: {
20671
+ model: AGENT_MODEL,
20672
+ promptVersion: 1
20673
+ },
20674
+ judge: (input) => judgeIn(query, input).pipe(Effect.scoped, Effect.timeout(AGENT_TIMEOUT), Effect.match({
20675
+ onSuccess: (verdict) => verdict,
20676
+ onFailure: (failure) => unknownBecause(reasonOf$1(failure))
20677
+ }))
20678
+ });
20679
+ // src/features/judge-documents/model/decision-judge.ts
20680
+ const ANSWERED_YES = "The decision model answered yes.";
20681
+ const judgeDecision = ({ rule, target: { text } }) => Effect.sync(() => {
20682
+ const judged = judgeText({
20683
+ rule: {
20684
+ id: rule.id,
20685
+ question: rule.question,
20686
+ cutoff: rule.cutoff
20687
+ },
20688
+ text,
20689
+ model: DECISION_MODEL,
20690
+ timeoutMs: DECISION_TIMEOUT_MS,
20691
+ env: {}
20917
20692
  });
20918
- return yield* checkPluginInstall(directory, manifest, tarballsFor({})(local));
20919
- }, Effect.scoped);
20920
- // src/features/publish-workspace/model/consumer-build.ts
20921
- const PNPMFILE = ".pnpmfile.cjs";
20922
- const TASK = "msch";
20923
- const SUCCESS$4 = 0;
20924
- const TARBALLS_ENV = "MSCH_CONSUMER_TARBALLS";
20925
- const TaskGraph$1 = Schema.Struct({ tasks: Schema.Record(Schema.String, Schema.Unknown) }).pipe(Schema.fromJsonString);
20926
- const Tarballed = Schema.Struct({
20927
- tarballs: Schema.Record(Schema.String, Schema.String),
20928
- natives: Schema.Record(Schema.String, Schema.Array(Schema.String))
20929
- }).pipe(Schema.fromJsonString);
20693
+ if (judged.status === "violation") return {
20694
+ status: "violation",
20695
+ line: judged.line,
20696
+ quote: textOfLine({
20697
+ text,
20698
+ line: judged.line
20699
+ }),
20700
+ reason: ANSWERED_YES
20701
+ };
20702
+ if (judged.status === "pass") return { status: "pass" };
20703
+ return unknownBecause(judged.reason);
20704
+ });
20930
20705
  /** @internal */
20931
- const PNPMFILE_SOURCE = Array$1.join([
20932
- `const { tarballs, natives } = JSON.parse(process.env.${TARBALLS_ENV});`,
20933
- "const fields = [\"dependencies\", \"devDependencies\", \"optionalDependencies\"];",
20934
- "module.exports = {",
20935
- " hooks: {",
20936
- " readPackage(manifest) {",
20937
- " for (const field of fields) {",
20938
- " for (const [name, file] of Object.entries(tarballs)) {",
20939
- " if (name in (manifest[field] || {})) manifest[field][name] = \"file:\" + file;",
20940
- " }",
20941
- " }",
20942
- " for (const name of natives[manifest.name] || []) {",
20943
- " manifest.optionalDependencies = { ...manifest.optionalDependencies, [name]: \"file:\" + tarballs[name] };",
20944
- " }",
20945
- " return manifest;",
20946
- " },",
20947
- " },",
20948
- "};",
20949
- ""
20950
- ], "\n");
20951
- const headerOf = (token) => `http.https://github.com/.extraheader=Authorization: basic ${Base64.encode(`x-access-token:${token}`)}`;
20706
+ const DECISION_JUDGE = {
20707
+ identity: {
20708
+ model: DECISION_MODEL,
20709
+ promptVersion: 1
20710
+ },
20711
+ judge: judgeDecision
20712
+ };
20713
+ // src/features/judge-documents/model/judge-rules.ts
20714
+ const DECISION_CUTOFF = .8;
20952
20715
  /** @internal */
20953
- const cloneArguments = ({ fullName, directory, token }) => [
20954
- ...Option.match(token, {
20955
- onNone: () => [],
20956
- onSome: (value) => ["-c", headerOf(value)]
20957
- }),
20958
- "clone",
20959
- "--depth",
20960
- "1",
20961
- "--quiet",
20962
- `https://github.com/${fullName}.git`,
20963
- directory
20716
+ const JUDGE_RULES = [
20717
+ {
20718
+ kind: "decision",
20719
+ id: "agents-no-task-record",
20720
+ files: ["**/AGENTS.md"],
20721
+ question: "Does this document record finished work, such as a changelog, a dated list of completed tasks or the history of what was changed and why, instead of rules and facts that stay true? Answer no for standing rules, commands and structure, even when a rule names a date or gives the reason it exists.",
20722
+ message: "Do not add a record of finished work to AGENTS.md. Put the reason for a change in its commit message.",
20723
+ cutoff: DECISION_CUTOFF
20724
+ },
20725
+ {
20726
+ kind: "decision",
20727
+ id: "readme-no-code-restatement",
20728
+ files: ["**/README.md"],
20729
+ question: "Does this README list what the code already shows, such as every file, module, exported function, parameter, option or endpoint, instead of saying what the project is, how to start using it and where it is published? Answer no for a short table of entry points that a reader needs before opening the code, and for install and usage commands.",
20730
+ message: "Do not copy what the code shows into the README. Say what it is, how to start using it and where it is published, and leave parameters, options and file lists to the types and the code.",
20731
+ cutoff: DECISION_CUTOFF
20732
+ },
20733
+ {
20734
+ kind: "agent",
20735
+ id: "skill-restates-skill",
20736
+ files: ["**/skills/*/SKILL.md"],
20737
+ context: ["../*/SKILL.md", "./**/*.md"],
20738
+ question: "Does this skill state a rule that another skill among the readable files also states in substance, so that two copies of one rule can drift apart? Answer no when the two rules differ in scope or reason, and when this skill only points to the other one.",
20739
+ message: "Keep each rule in one skill. Replace the copy with a pointer to the skill that owns the rule, or move the rule to where both can follow it."
20740
+ }
20964
20741
  ];
20965
- const stateOf = Effect.fn("consumers.state")(function* stateOf(directory) {
20966
- return `${yield* outputOf({
20967
- command: "git",
20968
- args: [
20969
- "status",
20970
- "--porcelain=v1",
20971
- "--untracked-files=all"
20972
- ],
20973
- cwd: directory
20974
- })}\n${yield* outputOf({
20975
- command: "git",
20976
- args: ["diff"],
20977
- cwd: directory
20978
- })}`;
20742
+ // src/features/judge-documents/model/judge-cache.ts
20743
+ const encodeJson = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
20744
+ const decodeCached = Schema.decodeUnknownOption(Schema.fromJsonString(DecidedVerdictSchema));
20745
+ const encodeCached = Schema.encodeEffect(Schema.fromJsonString(DecidedVerdictSchema));
20746
+ const ruleKey = ({ rule }) => {
20747
+ if (rule.kind === "decision") return {
20748
+ kind: rule.kind,
20749
+ id: rule.id,
20750
+ question: rule.question,
20751
+ cutoff: rule.cutoff
20752
+ };
20753
+ return {
20754
+ kind: rule.kind,
20755
+ id: rule.id,
20756
+ question: rule.question,
20757
+ context: rule.context
20758
+ };
20759
+ };
20760
+ /** @internal */
20761
+ const cacheKeyOf = Effect.fn("cacheKeyOf")(function* cacheKeyOf(input, identity) {
20762
+ const files = yield* RepositoryFiles;
20763
+ const json = yield* encodeJson({
20764
+ ...identity,
20765
+ rule: ruleKey(input),
20766
+ target: input.target,
20767
+ context: pipe(input.context, Array$1.map(({ name, text }) => [name, text]))
20768
+ }).pipe(Effect.orDie);
20769
+ return yield* files.hash(json);
20979
20770
  });
20980
- const hasTask = Effect.fn("consumers.hasTask")(function* hasTask(directory) {
20981
- const listed = yield* outputOf({
20982
- command: "vp",
20983
- args: ["run", "--json"],
20984
- cwd: directory
20985
- });
20986
- const { tasks } = yield* Schema.decodeEffect(TaskGraph$1)(listed);
20987
- return Record.has(tasks, TASK);
20771
+ const fileOf = (directory, key) => RepositoryFiles.pipe(Effect.map((files) => files.join(directory, `${key}.json`)));
20772
+ /** @internal */
20773
+ const readCached = Effect.fn("readCached")(function* readCached(directory, key) {
20774
+ const files = yield* RepositoryFiles;
20775
+ const file = yield* fileOf(directory, key);
20776
+ return (yield* files.readFile(file)).pipe(Option.flatMap(decodeCached));
20988
20777
  });
20989
- const REPORTED_LINES = 40;
20990
- const tailOf = (output) => pipe(String$1.split("\n")(output), Array$1.takeRight(REPORTED_LINES), Array$1.join("\n"));
20991
- const brokenReason = Effect.fn("consumers.reason")(function* brokenReason(directory) {
20992
- const before = yield* stateOf(directory);
20993
- const { code, output } = yield* finished({
20994
- command: "vp",
20995
- args: [
20996
- "run",
20997
- "--no-cache",
20998
- TASK
20999
- ],
21000
- cwd: directory
21001
- });
21002
- const after = yield* stateOf(directory);
21003
- if (code !== SUCCESS$4) return Option.some(`vp run ${TASK} exited with ${String(code)}:\n${tailOf(output)}`);
21004
- return Option.liftPredicate(after, (state) => state !== before).pipe(Option.map((state) => `vp run ${TASK} rewrote files:\n${state}`));
20778
+ /** @internal */
20779
+ const writeCached = Effect.fn("writeCached")(function* writeCached(directory, { key, verdict }) {
20780
+ if (!isDecided(verdict)) return;
20781
+ const files = yield* RepositoryFiles;
20782
+ const file = yield* fileOf(directory, key);
20783
+ const text = yield* encodeCached(verdict).pipe(Effect.orDie);
20784
+ yield* files.writeFile(file, text);
21005
20785
  });
21006
- const install = (directory, options) => mustSucceed({
21007
- command: "vp",
21008
- args: ["install", options.flag],
21009
- cwd: directory,
21010
- env: options.env
20786
+ // src/features/judge-documents/model/judge-input.ts
20787
+ /** @internal */
20788
+ const isDecisionInput = (input) => input.rule.kind === "decision";
20789
+ /** @internal */
20790
+ const isAgentInput = (input) => input.rule.kind === "agent";
20791
+ /** @internal */
20792
+ const readJudgedFile = Effect.fn("readJudgedFile")(function* readJudgedFile(root, name) {
20793
+ const files = yield* RepositoryFiles;
20794
+ return (yield* files.readFile(files.join(root, name))).pipe(Option.map((found) => ({
20795
+ name,
20796
+ text: found
20797
+ })));
21011
20798
  });
21012
- const withNewBuild = Effect.fn("consumers.withNewBuild")(function* withNewBuild(directory, build) {
21013
- const fileSystem = yield* FileSystem.FileSystem;
21014
- const pnpmfile = (yield* Path.Path).join(directory, PNPMFILE);
21015
- const encoded = yield* Schema.encodeEffect(Tarballed)(build);
21016
- yield* fileSystem.writeFileString(pnpmfile, PNPMFILE_SOURCE);
21017
- yield* install(directory, {
21018
- flag: "--no-frozen-lockfile",
21019
- env: { [TARBALLS_ENV]: encoded }
21020
- });
21021
- yield* fileSystem.remove(pnpmfile);
21022
- yield* mustSucceed({
21023
- command: "git",
21024
- args: [
21025
- "checkout",
21026
- "--",
21027
- "."
21028
- ],
21029
- cwd: directory
21030
- });
21031
- return yield* brokenReason(directory);
20799
+ /** @internal */
20800
+ const readJudgedFiles = Effect.fn("readJudgedFiles")(function* readJudgedFiles(root, names) {
20801
+ const read = yield* Effect.forEach(names, (name) => readJudgedFile(root, name), { concurrency: "unbounded" });
20802
+ return pipe(read, Array$1.getSomes);
21032
20803
  });
21033
- const onItsOwnMain = Effect.fn("consumers.onItsOwnMain")(function* onItsOwnMain(directory) {
21034
- yield* mustSucceed({
21035
- command: "git",
21036
- args: [
21037
- "checkout",
21038
- "--",
21039
- "."
21040
- ],
21041
- cwd: directory
21042
- });
21043
- yield* mustSucceed({
21044
- command: "git",
21045
- args: ["clean", "-fdq"],
21046
- cwd: directory
21047
- });
21048
- yield* install(directory, {
21049
- flag: "--frozen-lockfile",
21050
- env: {}
21051
- });
21052
- return yield* brokenReason(directory);
20804
+ // src/features/judge-documents/model/judge-pairs.ts
20805
+ const GLOB = ":(glob)";
20806
+ const globsOf = (patterns) => pipe(patterns, Array$1.map((pattern) => `${GLOB}${pattern}`));
20807
+ const contextNames = Effect.fn("contextNames")(function* contextNames(root, rule, name) {
20808
+ if (rule.kind === "decision") return [];
20809
+ const files = yield* RepositoryFiles;
20810
+ const directory = files.dirname(name);
20811
+ const listed = yield* Effect.forEach(rule.context, (pattern) => files.matchingFiles(root, globsOf([files.join(directory, pattern)])), { concurrency: "unbounded" });
20812
+ return pipe(listed, Array$1.flatten, Array$1.filter((found) => found !== name), Array$1.dedupe, (names) => Array$1.sort(names, Order.String));
21053
20813
  });
21054
- const cloned = Effect.fn("consumers.clone")(function* cloned({ consumer, token }) {
21055
- const fileSystem = yield* FileSystem.FileSystem;
21056
- const path = yield* Path.Path;
21057
- const root = yield* fileSystem.makeTempDirectoryScoped();
21058
- const directory = path.join(root, "consumer");
21059
- yield* mustSucceed({
21060
- command: "git",
21061
- args: cloneArguments({
21062
- fullName: consumer.fullName,
21063
- directory,
21064
- token
21065
- })
20814
+ const inputOf = Effect.fn("inputOf")(function* inputOf(root, { rule, name }) {
20815
+ const target = yield* readJudgedFile(root, name);
20816
+ if (Option.isNone(target)) return Option.none();
20817
+ const names = yield* contextNames(root, rule, name);
20818
+ const context = yield* readJudgedFiles(root, names);
20819
+ return Option.some({
20820
+ rule,
20821
+ target: target.value,
20822
+ context
21066
20823
  });
21067
- return directory;
21068
20824
  });
21069
- const verdict = Effect.fn("consumers.verdict")(function* verdict({ consumer, build }, directory) {
21070
- const reason = yield* withNewBuild(directory, build);
21071
- if (Option.isNone(reason)) {
21072
- yield* Console.log(`${consumer.fullName}: ${TASK} passes with the new build`);
21073
- return reason;
21074
- }
21075
- const baseline = yield* onItsOwnMain(directory);
21076
- if (Option.isSome(baseline)) {
21077
- yield* Console.log(`${consumer.fullName}: already fails on its own main, skipped`);
21078
- return Option.none();
21079
- }
21080
- return Option.some(`${consumer.fullName}: ${reason.value}`);
20825
+ const inputsOf = Effect.fn("inputsOf")(function* inputsOf(root, rule) {
20826
+ const names = yield* (yield* RepositoryFiles).matchingFiles(root, globsOf(rule.files));
20827
+ const inputs = yield* Effect.forEach(names, (name) => inputOf(root, {
20828
+ rule,
20829
+ name
20830
+ }), { concurrency: "unbounded" });
20831
+ return Array$1.getSomes(inputs);
21081
20832
  });
21082
20833
  /** @internal */
21083
- const checkConsumer = Effect.fn("consumers.check")(function* checkConsumer(checked) {
21084
- const directory = yield* cloned(checked);
21085
- if (!(yield* hasTask(directory))) {
21086
- yield* Console.log(`${checked.consumer.fullName}: has no ${TASK} task, skipped`);
21087
- return Option.none();
21088
- }
21089
- return yield* verdict(checked, directory);
21090
- }, Effect.scoped);
21091
- // src/features/publish-workspace/model/consumer-repositories.ts
21092
- const GH = "gh";
21093
- const SUCCESS$3 = 0;
21094
- const READ_RAW = "Accept: application/vnd.github.raw+json";
21095
- const MANIFESTS = ["package.json", "pnpm-workspace.yaml"];
21096
- const REMOTE$1 = /[:/](?<owner>[^/:]+)\/(?<name>[^/]+?)(?:\.git)?$/u;
21097
- const INSTALLATION = "/installation/repositories";
21098
- const OWNED = "/user/repos?affiliation=owner";
21099
- const REPOSITORY_FIELDS = "{full_name,archived,fork}|tojson";
21100
- const Repository$1 = Schema.Struct({
21101
- full_name: Schema.String,
21102
- archived: Schema.Boolean,
21103
- fork: Schema.Boolean
20834
+ const judgeInputs = Effect.fn("judgeInputs")(function* judgeInputs(root, rules) {
20835
+ const perRule = yield* Effect.forEach(rules, (rule) => inputsOf(root, rule), { concurrency: "unbounded" });
20836
+ return Array$1.flatten(perRule);
21104
20837
  });
21105
- const decodeRepository = Schema.decodeUnknownOption(Schema.fromJsonString(Repository$1));
21106
- /** @internal */
21107
- const repositoriesOf = (lines) => pipe(String$1.split("\n")(lines), Array$1.flatMap((line) => Option.toArray(decodeRepository(line))), Array$1.filter(({ archived, fork }) => !archived && !fork), Array$1.map(({ full_name: fullName }) => ({ fullName })));
21108
- /** @internal */
21109
- const remoteOf = (url) => pipe(Option.fromNullishOr(REMOTE$1.exec(url)), Option.flatMapNullishOr(({ groups }) => groups), Option.map(({ owner, name }) => `${owner ?? ""}/${name ?? ""}`));
21110
- /** @internal */
21111
- const consumersOf = (repositories) => (self) => {
21112
- const prefix = pipe(String$1.split("/")(self), Array$1.head, Option.getOrElse(() => ""));
21113
- return pipe(repositories, Array$1.filter(({ fullName }) => String$1.startsWith(`${prefix}/`)(fullName) && fullName !== self));
20838
+ // src/features/judge-documents/model/judge-repository.ts
20839
+ const AGENT_CONCURRENCY = 4;
20840
+ const SEQUENTIAL = 1;
20841
+ const FIRST_COLUMN = 1;
20842
+ const QUOTE_START = 0;
20843
+ const QUOTE_LIMIT = 160;
20844
+ const WHITESPACE = /\s+/gu;
20845
+ const oneLine = (text) => pipe(text, String$1.replaceAll(WHITESPACE, " "), String$1.trim, String$1.slice(QUOTE_START, QUOTE_LIMIT));
20846
+ const cachedBy = (directory, judge) => (input) => Effect.gen(function* cached() {
20847
+ const key = yield* cacheKeyOf(input, judge.identity);
20848
+ const hit = yield* readCached(directory, key);
20849
+ if (Option.isSome(hit)) return hit.value;
20850
+ const verdict = yield* judge.judge(input);
20851
+ yield* writeCached(directory, {
20852
+ key,
20853
+ verdict
20854
+ });
20855
+ return verdict;
20856
+ });
20857
+ const problemOf = (file, { input, verdict }) => {
20858
+ const { rule } = input;
20859
+ if (verdict.status === "pass") return Option.none();
20860
+ if (verdict.status === "unknown") return Option.some(problemInFile("judge-unknown")(file, `Could not decide ${rule.id}. ${verdict.reason}`));
20861
+ return Option.some(problemAtPosition(rule.id)(file, {
20862
+ line: verdict.line,
20863
+ column: FIRST_COLUMN
20864
+ }, `${rule.message} ${verdict.reason} Quoted: ${oneLine(verdict.quote)}`));
21114
20865
  };
21115
20866
  /** @internal */
21116
- const mentionsAny = (names) => (text) => pipe(names, Array$1.some((name) => String$1.includes(name)(text)));
21117
- const envOf = (token) => Option.match(token, {
21118
- onNone: () => ({}),
21119
- onSome: (value) => ({ GH_TOKEN: value })
20867
+ const judgeRepository = Effect.fn("judgeRepository")(function* judgeRepository(root, setup) {
20868
+ const files = yield* RepositoryFiles;
20869
+ const inputs = yield* judgeInputs(root, setup.rules);
20870
+ const decisions = pipe(inputs, Array$1.filter(isDecisionInput));
20871
+ const agents = pipe(inputs, Array$1.filter(isAgentInput));
20872
+ const decided = yield* Effect.forEach(decisions, cachedBy(setup.cacheDirectory, setup.decision), { concurrency: SEQUENTIAL });
20873
+ const reasoned = yield* Effect.forEach(agents, cachedBy(setup.cacheDirectory, setup.agent), { concurrency: AGENT_CONCURRENCY });
20874
+ const answered = [...decisions, ...agents];
20875
+ return pipe(Array$1.zip(answered, [...decided, ...reasoned]), Array$1.map(([input, verdict]) => problemOf(files.join(root, input.target.name), {
20876
+ input,
20877
+ verdict
20878
+ })), Array$1.getSomes);
21120
20879
  });
21121
- const apiOutput = (args, token) => finished({
21122
- command: GH,
21123
- args: ["api", ...args],
21124
- env: envOf(token)
21125
- }).pipe(Effect.map(({ output, code }) => pipe(Option.some(output), Option.filter(() => code === SUCCESS$3))));
21126
- const listing = (path, expression, token) => apiOutput([
21127
- "--paginate",
21128
- path,
21129
- "--jq",
21130
- expression
21131
- ], token).pipe(Effect.map(Option.map(repositoriesOf)));
21132
- /** @internal */
21133
- const listRepositories = (token) => listing(INSTALLATION, `.repositories[]|${REPOSITORY_FIELDS}`, token).pipe(Effect.flatMap(Option.match({
21134
- onNone: () => listing(OWNED, `.[]|${REPOSITORY_FIELDS}`, token),
21135
- onSome: (found) => Effect.succeedSome(found)
21136
- })));
21137
- /** @internal */
21138
- const manifestsOf = (token) => ({ fullName }) => Effect.forEach(MANIFESTS, (file) => apiOutput([
21139
- `repos/${fullName}/contents/${file}`,
21140
- "-H",
21141
- READ_RAW
21142
- ], token).pipe(Effect.map(Option.getOrElse(() => ""))), { concurrency: 1 }).pipe(Effect.map(Array$1.join("\n")));
21143
- // src/features/publish-workspace/model/consumers.ts
21144
- const MANIFEST_READ_CONCURRENCY = 4;
21145
- /** @internal */
21146
- const dependentsOf = (known) => (names) => {
21147
- const reached = pipe(known, Record.filter(({ manifest }) => pipe(runtimeDependencyNames(manifest), Array$1.some((name) => Array$1.contains(names, name)))), Record.keys);
21148
- const added = pipe(reached, Array$1.filter((name) => !Array$1.contains(names, name)));
21149
- if (Array$1.isReadonlyArrayEmpty(added)) return names;
21150
- return dependentsOf(known)([...names, ...added]);
21151
- };
21152
- const tokenOf = Config.option(Config.String("GITHUB_APP_TOKEN"));
21153
- const selfOf = Effect.fn("consumers.self")(function* selfOf() {
21154
- const given = yield* Config.option(Config.String("GITHUB_REPOSITORY"));
21155
- if (Option.isSome(given)) return given.value;
21156
- const url = yield* outputOf({
21157
- command: "git",
21158
- args: [
21159
- "remote",
21160
- "get-url",
21161
- "origin"
21162
- ]
20880
+ // src/app/judge-command.ts
20881
+ const judge = Effect.fn("judge")(function* judge(input) {
20882
+ const files = yield* RepositoryFiles;
20883
+ const root = files.resolve(".");
20884
+ const found = yield* judgeRepository(root, {
20885
+ cacheDirectory: files.resolve(input.cacheDirectory),
20886
+ rules: JUDGE_RULES,
20887
+ decision: DECISION_JUDGE,
20888
+ agent: agentJudge(sdkAgentQuery)
21163
20889
  });
21164
- return Option.getOrElse(remoteOf(url), () => "");
21165
- });
21166
- const nativesOf = (local) => pipe(local, Array$1.map(({ name, tarballs }) => [name, pipe(Record.keys(tarballs), Array$1.filter((entry) => entry !== name))]), Record.fromEntries);
21167
- const builtOf = Effect.fn("consumers.built")(function* builtOf(directories) {
21168
- const built = yield* Effect.forEach(directories, (directory) => readVersionedPackageJson(directory).pipe(Effect.flatMap((manifest) => workspaceTarballs(directory, manifest))), { concurrency: 1 });
21169
- const local = Array$1.flatten(built);
21170
- return {
21171
- tarballs: tarballsFor({})(local),
21172
- natives: nativesOf(local)
21173
- };
21174
- });
21175
- const mentioning = Effect.fn("consumers.mentioning")(function* mentioning(candidates, names, token) {
21176
- return yield* Effect.filter(candidates, (consumer) => manifestsOf(token)(consumer).pipe(Effect.map(mentionsAny(names))), { concurrency: MANIFEST_READ_CONCURRENCY });
21177
- });
21178
- const namesAffected = Effect.fn("consumers.affected")(function* namesAffected(directories) {
21179
- const [first = "."] = directories;
21180
- const known = yield* workspacesBeside(first);
21181
- const own = yield* Effect.forEach(directories, (directory) => readVersionedPackageJson(directory).pipe(Effect.map(({ name }) => name)), { concurrency: 1 });
21182
- return dependentsOf(known)(own);
21183
- });
21184
- const unlisted = Effect.fn("consumers.unlisted")(function* unlisted() {
21185
- if (yield* Config.Boolean("GITHUB_ACTIONS").pipe(Config.withDefault(false))) return yield* IncompatiblePackage.make({ message: "The consumers of the new build could not be listed, so none of them was checked" });
21186
- return yield* Console.log("consumers skipped: no GitHub access to list them");
21187
- });
21188
- const failing = Effect.fn("consumers.failing")(function* failing(found, build, token) {
21189
- const reasons = yield* Effect.forEach(found, (consumer) => checkConsumer({
21190
- consumer,
21191
- build,
21192
- token
21193
- }), { concurrency: 1 });
21194
- return Array$1.getSomes(reasons);
21195
- });
21196
- const consumersAffected = Effect.fn("consumers.found")(function* consumersAffected(directories, token) {
21197
- const listed = yield* listRepositories(token);
21198
- if (Option.isNone(listed)) return Option.none();
21199
- const self = yield* selfOf();
21200
- const names = yield* namesAffected(directories);
21201
- const found = yield* mentioning(consumersOf(listed.value)(self), names, token);
21202
- const listedNames = pipe(found, Array$1.map(({ fullName }) => fullName));
21203
- yield* Console.log(`consumers: ${Array$1.join(listedNames, ", ")}`);
21204
- return Option.some(found);
21205
- });
21206
- const verified = Effect.fn("consumers.verified")(function* verified(directories, found, token) {
21207
- const build = yield* builtOf(directories);
21208
- const broken = yield* failing(found, build, token);
21209
- if (Array$1.isReadonlyArrayNonEmpty(broken)) return yield* IncompatiblePackage.make({ message: `The new build breaks its consumers:\n${Array$1.join(broken, "\n")}` });
21210
- return yield* Effect.void;
20890
+ const problems = sortProblems(found);
20891
+ yield* reportProblems(root, {
20892
+ problems,
20893
+ json: input.json
20894
+ });
20895
+ return yield* failWhenAny(problems.length);
21211
20896
  });
21212
20897
  /** @internal */
21213
- const checkConsumers = Effect.fn("publish.consumers")(function* checkConsumers(directories) {
21214
- if (Array$1.isReadonlyArrayEmpty(directories)) return yield* Effect.void;
21215
- const token = yield* tokenOf;
21216
- const found = yield* consumersAffected(directories, token);
21217
- if (Option.isNone(found)) return yield* unlisted();
21218
- return yield* verified(directories, found.value, token);
21219
- }, Effect.scoped);
21220
- // src/features/publish-workspace/model/manifest.ts
21221
- const UNVERSIONED$2 = "0.0.0";
21222
- const ROOT = ".";
21223
- /** @internal */
21224
- const releaseName = ({ name }) => unscopedNameOf(name);
21225
- /** @internal */
21226
- const isRoot = (directory) => directory === ROOT;
20898
+ const judgeCommand = Command.make("judge", {
20899
+ cacheDirectory: Argument.String("cache-directory").pipe(Argument.withDescription("The directory that keeps the verdicts between runs")),
20900
+ json: jsonFlag
20901
+ }, judge).pipe(Command.withDescription("Judges documents against rules that need reading, and reports violations"));
20902
+ // src/features/publish-workspace/model/export-targets.ts
20903
+ const PATTERN = "*";
20904
+ const taggedError$3 = Schema.TaggedError;
21227
20905
  /** @internal */
21228
- const tagOf = ({ directory, name, version }) => {
21229
- if (isRoot(directory)) return `v${version}`;
21230
- return `${releaseName({ name })}-v${version}`;
20906
+ var MissingExportTargets = class extends taggedError$3()("MissingExportTargets", { message: Schema.String }) {};
20907
+ const singleTarget = (target) => {
20908
+ if (String$1.includes(PATTERN)(target)) return [];
20909
+ return [target];
21231
20910
  };
21232
20911
  /** @internal */
21233
- const environmentOf = (manifest) => `${releaseName(manifest)}-release`;
21234
- /** @internal */
21235
- const isVersioned = ({ version }) => version !== UNVERSIONED$2;
20912
+ const foldExports = (cases) => (exports) => {
20913
+ if (Predicate.isString(exports)) return cases.string(exports);
20914
+ if (Array$1.isArray(exports)) return cases.array(exports);
20915
+ if (Predicate.isReadonlyObject(exports)) return cases.object(exports);
20916
+ return cases.other();
20917
+ };
21236
20918
  /** @internal */
21237
- const goesToNpm = (manifest) => !pipe(Option.fromUndefinedOr(manifest.private), Option.getOrElse(() => false));
21238
- // src/features/publish-workspace/model/dependencies.ts
21239
- const WORKSPACE_PROTOCOL$1 = "workspace:";
21240
- const READ_CONCURRENCY$3 = 8;
21241
- const WAIT_INTERVAL = "30 seconds";
21242
- const WAIT_ATTEMPTS = 120;
20919
+ const exportTargetsOf = (exports) => foldExports({
20920
+ string: singleTarget,
20921
+ array: Array$1.flatMap(exportTargetsOf),
20922
+ object: (record) => Array$1.flatMap(Record.values(record), exportTargetsOf),
20923
+ other: () => []
20924
+ })(exports);
20925
+ const publishedExportsOf = (manifest) => pipe(Option.fromUndefinedOr(manifest.publishConfig), Option.flatMap((config) => Option.fromUndefinedOr(config.exports)), Option.orElse(() => Option.fromUndefinedOr(manifest.exports)), Option.getOrUndefined);
20926
+ const missingMessage = (missing) => `The published exports point to files the build did not write: ${Array$1.join(missing, ", ")}`;
21243
20927
  /** @internal */
21244
- const REGISTRY_FLAGS = ["--registry", PUBLIC_REGISTRY];
20928
+ const checkExportTargets = Effect.fn("publish.checkExportTargets")(function* checkExportTargets(directory) {
20929
+ const fileSystem = yield* FileSystem.FileSystem;
20930
+ const path = yield* Path.Path;
20931
+ const manifest = yield* readPackageJson(directory);
20932
+ const missing = yield* Effect.filter(exportTargetsOf(publishedExportsOf(manifest)), (target) => Effect.map(fileSystem.exists(path.join(directory, target)), (found) => !found));
20933
+ return yield* pipe(missing, Array$1.match({
20934
+ onEmpty: () => Effect.void,
20935
+ onNonEmpty: (list) => Effect.fail(MissingExportTargets.make({ message: missingMessage(list) }))
20936
+ }));
20937
+ });
20938
+ // src/features/publish-workspace/model/compat-manifest.ts
20939
+ const UNVERSIONED$3 = "0.0.0";
20940
+ const VITE = "vite";
21245
20941
  /** @internal */
21246
- const PUBLISH_FLAGS = [
21247
- "--provenance",
21248
- "--access",
21249
- "public",
21250
- ...REGISTRY_FLAGS
20942
+ const VITE_PLUS = "vite-plus";
20943
+ const MODULE_EXTENSIONS = [
20944
+ ".js",
20945
+ ".mjs",
20946
+ ".cjs"
21251
20947
  ];
20948
+ const taggedError$2 = Schema.TaggedError;
21252
20949
  /** @internal */
21253
- const onNpm = Effect.fn("publish.onNpm")(function* onNpm({ directory, name, version }) {
21254
- return yield* succeeds({
21255
- command: "npm",
21256
- args: [
21257
- "view",
21258
- `${name}@${version}`,
21259
- "version",
21260
- ...REGISTRY_FLAGS
21261
- ],
21262
- cwd: directory
21263
- });
20950
+ var IncompatiblePackage = class extends taggedError$2()("IncompatiblePackage", { message: Schema.String }) {};
20951
+ const lowestOf = (range) => pipe(Option.fromNullishOr(semver.validRange(range)), Option.flatMap(() => Option.fromNullishOr(semver.minVersion(range))), Option.map(({ version }) => version));
20952
+ const floorOf = (version) => {
20953
+ if (semver.prerelease(version) !== null) return version;
20954
+ return `~${String(semver.major(version))}.${String(semver.minor(version))}.0`;
20955
+ };
20956
+ const pinnedPeer = ([name, range]) => Option.match(lowestOf(range), {
20957
+ onNone: () => [],
20958
+ onSome: (version) => {
20959
+ if (version === UNVERSIONED$3) return [[name, range]];
20960
+ return [[name, floorOf(version)]];
20961
+ }
21264
20962
  });
21265
- const taggedError$1 = Schema.TaggedError;
20963
+ const floorPeers = (peers) => pipe(Record.toEntries(peers), Array$1.flatMap(pinnedPeer), Record.fromEntries);
20964
+ const nodeFloorOf = (manifest) => pipe(Option.fromUndefinedOr(manifest.engines), Option.flatMap(({ node }) => Option.fromUndefinedOr(node)), Option.flatMap(lowestOf));
20965
+ const withoutViteOfVitePlus = (peers) => {
20966
+ if (Record.has(peers, "vite-plus")) return Record.remove(peers, VITE);
20967
+ return peers;
20968
+ };
21266
20969
  /** @internal */
21267
- var UnpublishedDependencies = class extends taggedError$1()("UnpublishedDependencies", { message: Schema.String }) {};
21268
- const workspaceDependencies = (manifest) => pipe(Option.fromUndefinedOr(manifest.dependencies), Option.map((dependencies) => pipe(dependencies, Record.filter(String$1.startsWith(WORKSPACE_PROTOCOL$1)), Record.keys)), Option.getOrElse(() => []));
21269
- const failWhenMissing = (missing, manifest) => {
21270
- if (Array$1.isReadonlyArrayEmpty(missing)) return Effect.void;
21271
- const names = pipe(missing, Array$1.map(({ directory, name, version }) => `${name}@${version} (${directory})`), Array$1.join(", "));
21272
- return Effect.fail(UnpublishedDependencies.make({ message: `${manifest.name} depends on versions that are not on npm yet. Publish them first: ${names}` }));
20970
+ const viteAliasOf = (vitePlusManifest) => pipe(decodePackageJson(vitePlusManifest), Option.flatMapNullishOr(({ dependencies }) => dependencies), Option.flatMap(Record.get(VITE)), Option.map((spec) => `${VITE}@${spec}`));
20971
+ const casesOf = (manifest, floor) => {
20972
+ const declared = withoutViteOfVitePlus(manifest.peerDependencies ?? {});
20973
+ const latest = `^${String(semver.major(floor))}`;
20974
+ return [
20975
+ {
20976
+ label: "floor",
20977
+ node: floorOf(floor),
20978
+ peers: floorPeers(declared)
20979
+ },
20980
+ {
20981
+ label: "latest",
20982
+ node: latest,
20983
+ peers: declared
20984
+ },
20985
+ {
20986
+ label: "npx",
20987
+ node: latest,
20988
+ peers: {}
20989
+ }
20990
+ ];
21273
20991
  };
21274
- const missingDependencies = Effect.fn("publish.missingDependencies")(function* missingDependencies({ manifest, workspaces }) {
21275
- const wanted = workspaceDependencies(manifest);
21276
- const siblings = yield* Effect.forEach(workspaces, (directory) => readVersionedPackageJson(directory).pipe(Effect.map((found) => ({
21277
- directory,
21278
- ...found
21279
- }))), { concurrency: READ_CONCURRENCY$3 });
21280
- const internal = pipe(siblings, Array$1.filter((sibling) => Array$1.contains(wanted, sibling.name) && goesToNpm(sibling)));
21281
- const missing = yield* Effect.filter(internal, (sibling) => onNpm(sibling).pipe(Effect.map((published) => !published)), { concurrency: READ_CONCURRENCY$3 });
21282
- yield* failWhenMissing(missing, manifest);
21283
- });
21284
20992
  /** @internal */
21285
- const requirePublishedDependencies = (dependent) => missingDependencies(dependent).pipe(Effect.tapError((missing) => Effect.logInfo(`waiting: ${missing.message}`)), Effect.retry({
21286
- schedule: Schedule.spaced(WAIT_INTERVAL),
21287
- times: WAIT_ATTEMPTS,
21288
- while: Schema.is(UnpublishedDependencies)
20993
+ const compatCasesOf = (manifest) => pipe(nodeFloorOf(manifest), Option.match({
20994
+ onNone: () => [],
20995
+ onSome: (floor) => casesOf(manifest, floor)
21289
20996
  }));
21290
- // src/features/publish-workspace/model/provenance.ts
21291
- const ATTESTATIONS = "https://registry.npmjs.org/-/npm/v1/attestations/";
21292
- const SLSA = /slsa\.dev\/provenance/u;
21293
- const Digest = Schema.Struct({ gitCommit: Schema.String });
21294
- const Dependency = Schema.Struct({
21295
- uri: Schema.String,
21296
- digest: Digest
21297
- });
21298
- const BuildDefinition = Schema.Struct({ resolvedDependencies: Schema.Array(Dependency) });
21299
- const Predicate$1 = Schema.Struct({ buildDefinition: BuildDefinition });
21300
- const Statement = Schema.fromJsonString(Schema.Struct({ predicate: Predicate$1 }));
21301
- const Envelope = Schema.Struct({ payload: Schema.String });
21302
- const Bundle = Schema.Struct({ dsseEnvelope: Envelope });
21303
- const Attestation = Schema.Struct({
21304
- predicateType: Schema.String,
21305
- bundle: Bundle
20997
+ const loadsAModule = (target) => pipe(exportTargetsOf(target), Array$1.some((file) => pipe(MODULE_EXTENSIONS, Array$1.some((extension) => String$1.endsWith(extension)(file)))));
20998
+ const exportedSubpaths = (exports) => pipe(exportEntriesOf(exports), Array$1.filter(([, target]) => loadsAModule(target)), Array$1.map(([subpath]) => subpath));
20999
+ const subpathsOf = foldExports({
21000
+ string: () => [ROOT_SUBPATH],
21001
+ array: () => [ROOT_SUBPATH],
21002
+ object: exportedSubpaths,
21003
+ other: () => []
21306
21004
  });
21307
- const Attestations = Schema.Struct({ attestations: Schema.Array(Attestation) });
21005
+ const binFilesOf = (bin) => {
21006
+ if (Predicate.isUndefined(bin)) return [];
21007
+ if (Predicate.isString(bin)) return [bin];
21008
+ return Record.values(bin);
21009
+ };
21308
21010
  /** @internal */
21309
- const commitOf = (repository) => (payload) => pipe(Base64.decodeString(payload), Effect.fromResult, Effect.flatMap(Schema.decodeEffect(Statement)), Effect.map(({ predicate }) => pipe(Array$1.head(predicate.buildDefinition.resolvedDependencies), Option.filter(({ uri }) => String$1.includes(`github.com/${repository}@`)(uri)), Option.map(({ digest }) => digest.gitCommit))), Effect.orElseSucceed(() => Option.none()));
21011
+ const smokeTargetsOf = (manifest) => {
21012
+ const published = Option.fromUndefinedOr(manifest.publishConfig);
21013
+ const exports = pipe(published, Option.flatMap(({ exports: own }) => Option.fromUndefinedOr(own)), Option.getOrElse(() => manifest.exports));
21014
+ const bin = pipe(published, Option.flatMap(({ bin: own }) => Option.fromUndefinedOr(own)), Option.getOrElse(() => manifest.bin));
21015
+ return {
21016
+ imports: pipe(subpathsOf(exports), Array$1.map((subpath) => importSpecifierOf(manifest.name, subpath))),
21017
+ bins: binFilesOf(bin)
21018
+ };
21019
+ };
21020
+ // src/features/publish-workspace/model/compat-start.ts
21021
+ const NOT_LOADED = String.raw`ERR_(MODULE_NOT_FOUND|PACKAGE_|INVALID_PACKAGE|UNKNOWN_FILE|UNSUPPORTED_DIR|REQUIRE_ESM)|SyntaxError`;
21310
21022
  /** @internal */
21311
- const provenanceCommit = Effect.fn("publish.provenanceCommit")(function* provenanceCommit({ name, version }) {
21312
- const client = yield* HttpClient.HttpClient;
21313
- const repository = yield* Config.String("GITHUB_REPOSITORY");
21314
- const url = `${ATTESTATIONS}${String$1.replace("/", "%2f")(name)}@${version}`;
21315
- const found = yield* HttpClient.filterStatusOk(client).get(url).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Attestations)), Effect.map(({ attestations }) => Array$1.findFirst(attestations, ({ predicateType }) => SLSA.test(predicateType))), Effect.orElseSucceed(() => Option.none()));
21316
- if (Option.isNone(found)) return Option.none();
21317
- return yield* commitOf(repository)(found.value.bundle.dsseEnvelope.payload);
21023
+ const LOAD_FAILURE = `/${NOT_LOADED}/u`;
21024
+ /** @internal */
21025
+ const CRASH = String.raw`/${NOT_LOADED}|\n\s+at\s.+:\d+:\d+/u`;
21026
+ /** @internal */
21027
+ const BIN_ARGUMENTS = [["--help"], ["--compat-unknown-flag"]];
21028
+ const spawnChecked = (failure) => `import { spawnSync } from "node:child_process"; const { stderr } = spawnSync(process.execPath, process.argv.slice(1), { encoding: "utf8", stdio: ["ignore", "ignore", "pipe"], timeout: 60000 }); if (${failure}.test(stderr)) { process.stderr.write(stderr); process.exit(1); }`;
21029
+ /** @internal */
21030
+ const loadsCleanly = ({ runtime, consumer, failure, args }) => mustSucceed({
21031
+ command: runtime,
21032
+ args: [
21033
+ "--input-type=module",
21034
+ "-e",
21035
+ spawnChecked(failure),
21036
+ "--",
21037
+ ...args
21038
+ ],
21039
+ cwd: consumer
21318
21040
  });
21319
- // src/features/publish-workspace/model/tags.ts
21320
- const UNVERSIONED$1 = "0.0.0";
21321
- const LOOKUP_CONCURRENCY$2 = 4;
21322
- const Versions = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
21041
+ // src/features/publish-workspace/model/plugin-lock.ts
21042
+ const PLUGIN_FILE = ".claude-plugin/plugin.json";
21043
+ const PACKED_ROOT = "package";
21044
+ const NPM_LOCK$1 = "package-lock.json";
21045
+ const MINIMUM_RELEASE_AGE_DAYS = 1;
21046
+ const SCOPE = /^@[^/]+\//u;
21323
21047
  /** @internal */
21324
- const tagged = Effect.fn("publish.tagged")(function* tagged(tag) {
21325
- const repository = yield* Config.String("GITHUB_REPOSITORY");
21326
- return yield* succeeds({
21327
- command: "gh",
21328
- args: ["api", `repos/${repository}/git/ref/tags/${tag}`]
21329
- });
21048
+ const PLUGIN_LOCK = "npm-shrinkwrap.json";
21049
+ /** @internal */
21050
+ const NPM_QUIET = [
21051
+ "--ignore-scripts",
21052
+ "--no-audit",
21053
+ "--no-fund"
21054
+ ];
21055
+ /** @internal */
21056
+ const isPlugin = Effect.fn("publish.isPlugin")(function* isPlugin(directory) {
21057
+ const fileSystem = yield* FileSystem.FileSystem;
21058
+ const path = yield* Path.Path;
21059
+ return yield* fileSystem.exists(path.join(directory, PLUGIN_FILE));
21330
21060
  });
21331
- const tokenEnv = Config.option(Config.String("GITHUB_APP_TOKEN")).pipe(Effect.map(Option.match({
21332
- onNone: () => ({}),
21333
- onSome: (value) => ({ GH_TOKEN: value })
21334
- })));
21335
21061
  /** @internal */
21336
- const createTag = Effect.fn("publish.createTag")(function* createTag({ tag, sha }) {
21337
- const repository = yield* Config.String("GITHUB_REPOSITORY");
21338
- const env = yield* tokenEnv;
21339
- yield* Effect.logInfo(`tagging ${tag} at ${sha}`);
21062
+ const unpacked = Effect.fn("publish.unpacked")(function* unpacked(tarball, directory) {
21063
+ const fileSystem = yield* FileSystem.FileSystem;
21064
+ const path = yield* Path.Path;
21065
+ yield* fileSystem.makeDirectory(directory, { recursive: true });
21340
21066
  yield* mustSucceed({
21341
- command: "gh",
21342
- env,
21067
+ command: "tar",
21343
21068
  args: [
21344
- "api",
21345
- "-X",
21346
- "POST",
21347
- `repos/${repository}/git/refs`,
21348
- "-f",
21349
- `ref=refs/tags/${tag}`,
21350
- "-f",
21351
- `sha=${sha}`
21069
+ "-xzf",
21070
+ tarball,
21071
+ "-C",
21072
+ directory
21352
21073
  ]
21353
21074
  });
21075
+ return path.join(directory, PACKED_ROOT);
21354
21076
  });
21355
- const isRelease = (version) => version !== UNVERSIONED$1 && semver.valid(version) !== null && semver.prerelease(version) === null;
21356
- const publishedVersions$1 = Effect.fn("publish.publishedVersions")(function* publishedVersions({ directory, manifest }) {
21357
- if (!goesToNpm(manifest)) return [];
21358
- const text = yield* outputOf({
21359
- command: "npm",
21360
- args: [
21361
- "view",
21362
- manifest.name,
21363
- "versions",
21364
- "--json",
21365
- ...REGISTRY_FLAGS
21366
- ],
21367
- cwd: directory
21368
- }).pipe(Effect.orElseSucceed(() => "[]"));
21369
- const versions = yield* Schema.decodeEffect(Versions)(text).pipe(Effect.orElseSucceed(() => []));
21370
- return pipe(versions, Array$1.filter((version) => isRelease(version) && version !== manifest.version));
21077
+ /** @internal */
21078
+ const installsDependencies = Effect.fn("publish.installsDependencies")(function* installsDependencies(root) {
21079
+ const { dependencies } = yield* readVersionedPackageJson(root);
21080
+ return pipe(Option.fromUndefinedOr(dependencies), Option.exists((held) => !Record.isEmptyRecord(held)));
21371
21081
  });
21372
21082
  /** @internal */
21373
- const untaggedVersions = Effect.fn("publish.untaggedVersions")(function* untaggedVersions(workspace) {
21374
- const versions = yield* publishedVersions$1(workspace);
21375
- return yield* Effect.filter(versions, (version) => tagged(tagOf({
21376
- directory: workspace.directory,
21377
- name: workspace.manifest.name,
21378
- version
21379
- })).pipe(Effect.map((found) => !found)), { concurrency: LOOKUP_CONCURRENCY$2 });
21083
+ const agedFlags = ({ name, direct }) => pipe(Option.fromNullishOr(SCOPE.exec(name)), Option.map(([scope]) => `${scope}*`), Option.toArray, Array$1.appendAll(direct), Array$1.map((excluded) => `--min-release-age-exclude=${excluded}`), Array$1.prepend(`--min-release-age=${String(MINIMUM_RELEASE_AGE_DAYS)}`));
21084
+ const npmLock = (root, flags) => mustSucceed({
21085
+ command: "npm",
21086
+ args: [
21087
+ "install",
21088
+ "--package-lock-only",
21089
+ `--registry=${PUBLIC_REGISTRY}`,
21090
+ ...flags,
21091
+ ...NPM_QUIET
21092
+ ],
21093
+ cwd: root
21380
21094
  });
21381
- const backfillVersion = Effect.fn("publish.backfillVersion")(function* backfillVersion(workspace, version) {
21382
- const { directory, manifest } = workspace;
21383
- const tag = tagOf({
21384
- directory,
21385
- name: manifest.name,
21386
- version
21095
+ const lockedOf = Effect.fn("publish.lockedOf")(function* lockedOf(root) {
21096
+ const { name, dependencies } = yield* readVersionedPackageJson(root);
21097
+ const direct = Record.keys(dependencies ?? {});
21098
+ if (Array$1.isReadonlyArrayEmpty(direct)) return Option.none();
21099
+ return Option.some({
21100
+ name,
21101
+ direct
21387
21102
  });
21388
- const commit = yield* provenanceCommit({
21389
- name: manifest.name,
21390
- version
21103
+ });
21104
+ const writeLock = (root, locked) => npmLock(root, agedFlags(locked)).pipe(Effect.matchEffect({
21105
+ onFailure: () => Console.warn(`${locked.name}: no dependency set is a day old, so the lock takes newer versions`).pipe(Effect.andThen(npmLock(root, []))),
21106
+ onSuccess: () => Effect.void
21107
+ }));
21108
+ /** @internal */
21109
+ const lockPlugin = Effect.fn("publish.lockPlugin")(function* lockPlugin(tarball, temporary) {
21110
+ const fileSystem = yield* FileSystem.FileSystem;
21111
+ const path = yield* Path.Path;
21112
+ const unpackedTo = path.join(temporary, "locked");
21113
+ const root = yield* unpacked(tarball, unpackedTo);
21114
+ const locked = yield* lockedOf(root);
21115
+ if (Option.isNone(locked)) return;
21116
+ yield* writeLock(root, locked.value);
21117
+ yield* fileSystem.rename(path.join(root, NPM_LOCK$1), path.join(root, PLUGIN_LOCK));
21118
+ yield* mustSucceed({
21119
+ command: "tar",
21120
+ args: [
21121
+ "-czf",
21122
+ tarball,
21123
+ "-C",
21124
+ unpackedTo,
21125
+ PACKED_ROOT
21126
+ ]
21391
21127
  });
21392
- if (Option.isNone(commit)) {
21393
- yield* Effect.logWarning(`${tag} has no npm provenance, so it stays untagged`);
21394
- return;
21395
- }
21396
- yield* createTag({
21397
- tag,
21398
- sha: commit.value
21128
+ });
21129
+ // src/features/publish-workspace/model/compat-plugin.ts
21130
+ const NPM_LOCK = "package-lock.json";
21131
+ const installed = Effect.fn("compat.pluginInstalled")(function* installed(name, root) {
21132
+ const fileSystem = yield* FileSystem.FileSystem;
21133
+ const path = yield* Path.Path;
21134
+ const lock = path.join(root, PLUGIN_LOCK);
21135
+ if (!(yield* fileSystem.exists(lock))) return yield* IncompatiblePackage.make({ message: `${name} is a Claude Code plugin with dependencies, but its tarball has no ${PLUGIN_LOCK}, so Claude Code installs none of them` });
21136
+ yield* fileSystem.copyFile(lock, path.join(root, NPM_LOCK));
21137
+ return yield* mustSucceed({
21138
+ command: "npm",
21139
+ args: ["ci", ...NPM_QUIET],
21140
+ cwd: root
21399
21141
  });
21400
21142
  });
21401
- /** @internal */
21402
- const backfillTags = Effect.fn("publish.backfillTags")(function* backfillTags(workspace) {
21403
- const versions = yield* untaggedVersions(workspace);
21404
- yield* Effect.forEach(versions, (version) => backfillVersion(workspace, version), {
21143
+ const startsBins = Effect.fn("compat.pluginBins")(function* startsBins(manifest, root) {
21144
+ const path = yield* Path.Path;
21145
+ const startOf = (file) => {
21146
+ const started = Array$1.prepend(path.join(root, file));
21147
+ return pipe(BIN_ARGUMENTS, Array$1.map(started));
21148
+ };
21149
+ const runs = pipe(smokeTargetsOf(manifest).bins, Array$1.flatMap(startOf));
21150
+ yield* Effect.forEach(runs, (args) => loadsCleanly({
21151
+ runtime: process.execPath,
21152
+ consumer: root,
21153
+ failure: CRASH,
21154
+ args
21155
+ }), {
21405
21156
  concurrency: 1,
21406
21157
  discard: true
21407
21158
  });
21408
21159
  });
21409
- // src/features/publish-workspace/model/plan.ts
21410
- const HOOK = "release:publish";
21411
- const WORKFLOW = "publish.yml";
21412
- const PLAN_CONCURRENCY = 4;
21413
- const NONE = 0;
21414
- const TRAILING_SLASH = /\/$/u;
21415
- const Task = Schema.Struct({
21416
- package: Schema.String,
21417
- name: Schema.String
21418
- });
21419
- const TaskGraph = Schema.fromJsonString(Schema.Struct({
21420
- workspaceRoot: Schema.String,
21421
- tasks: Schema.Record(Schema.String, Task)
21422
- }));
21423
- const Runner = Schema.Struct({
21424
- os: Schema.String,
21425
- runner: Schema.String
21426
- });
21427
- const NativeTarget = Schema.Struct({
21428
- target: Schema.String,
21429
- runner: Schema.String
21430
- });
21431
- const PlanSchema = Schema.Struct({
21432
- directory: Schema.String,
21433
- name: Schema.String,
21434
- version: Schema.String,
21435
- tag: Schema.String,
21436
- environment: Schema.String,
21437
- npm: Schema.Boolean,
21438
- native: Schema.Array(NativeTarget),
21439
- builds: Schema.Array(Runner),
21440
- checks: Schema.Array(Runner),
21441
- release: Schema.Boolean,
21442
- tagged: Schema.Boolean,
21443
- hook: Schema.Boolean
21444
- });
21445
- const AssetCount = Schema.fromJsonString(Schema.Finite);
21446
21160
  /** @internal */
21447
- const graphTasks = outputOf({
21448
- command: "vp",
21449
- args: ["run", "--json"]
21450
- }).pipe(Effect.flatMap(Schema.decodeEffect(TaskGraph)), Effect.map(({ tasks }) => Record.values(tasks)));
21451
- const tasksIn = (tasks, directory) => pipe(tasks, Array$1.filter((task) => task.package === directory), Array$1.map(({ name }) => name));
21161
+ const checkPluginInstall = Effect.fn("compat.plugin")(function* checkPluginInstall(directory, manifest, tarballs) {
21162
+ const tarball = Record.get(tarballs, manifest.name);
21163
+ if (!(yield* isPlugin(directory)) || Option.isNone(tarball)) return;
21164
+ const cache = yield* (yield* FileSystem.FileSystem).makeTempDirectoryScoped();
21165
+ const root = yield* unpacked(tarball.value, cache);
21166
+ if (yield* installsDependencies(root)) yield* installed(manifest.name, root);
21167
+ yield* Console.log(`${manifest.name} plugin: installed the way Claude Code caches it`);
21168
+ yield* startsBins(manifest, root);
21169
+ }, Effect.scoped);
21170
+ // src/features/publish-workspace/model/platforms.ts
21171
+ const RUNNERS = {
21172
+ linux: "ubuntu-latest",
21173
+ windows: "windows-latest",
21174
+ macos: "macos-latest"
21175
+ };
21176
+ const NODE_PLATFORMS = {
21177
+ linux: "linux",
21178
+ win32: "windows",
21179
+ darwin: "macos"
21180
+ };
21181
+ const BUILD = "release:";
21182
+ const CHECK = "release:check:";
21183
+ const LIBC = {
21184
+ gnu: "glibc",
21185
+ musl: "musl"
21186
+ };
21187
+ const CPU_INDEX = 1;
21188
+ const ABI_INDEX = 2;
21189
+ const systems = Record.keys(RUNNERS);
21190
+ const runnersFor = (tasks, prefix) => pipe(systems, Array$1.filter((os) => Array$1.contains(tasks, `${prefix}${os}`)), Array$1.map((os) => ({
21191
+ os,
21192
+ runner: RUNNERS[os]
21193
+ })));
21452
21194
  /** @internal */
21453
- const workspacesOf = (tasks) => pipe(tasks, Array$1.map((task) => task.package), Array$1.dedupe);
21454
- const allTagged = Effect.fn("publish.allTagged")(function* allTagged(directory, manifest) {
21455
- if (!isVersioned(manifest)) return true;
21456
- const current = yield* tagged(tagOf({
21457
- directory,
21458
- ...manifest
21459
- }));
21460
- const older = yield* untaggedVersions({
21461
- directory,
21462
- manifest
21463
- });
21464
- return current && Array$1.isReadonlyArrayEmpty(older);
21465
- });
21466
- const workspaceOf = (directory) => Path.Path.pipe(Effect.map((path) => String$1.replace(TRAILING_SLASH, "")(path.normalize(directory))));
21195
+ const buildsOf = (tasks) => runnersFor(tasks, BUILD);
21467
21196
  /** @internal */
21468
- const released = Effect.fn("publish.released")(function* released(tag) {
21469
- const repository = yield* Config.String("GITHUB_REPOSITORY");
21470
- return yield* succeeds({
21471
- command: "gh",
21472
- args: [
21473
- "release",
21474
- "view",
21475
- tag,
21476
- "--repo",
21477
- repository
21478
- ]
21479
- });
21480
- });
21197
+ const checksOf = (tasks) => runnersFor(tasks, CHECK);
21481
21198
  /** @internal */
21482
- const releasedWithAssets = Effect.fn("publish.releasedWithAssets")(function* releasedWithAssets(tag) {
21483
- const view = [
21484
- "release",
21485
- "view",
21486
- tag,
21487
- "--repo",
21488
- yield* Config.String("GITHUB_REPOSITORY")
21489
- ];
21490
- if (!(yield* released(tag))) return false;
21491
- return (yield* outputOf({
21492
- command: "gh",
21493
- args: [
21494
- ...view,
21495
- "--json",
21496
- "assets",
21497
- "--jq",
21498
- ".assets | length"
21499
- ]
21500
- }).pipe(Effect.flatMap(Schema.decodeEffect(AssetCount)))) > NONE;
21501
- });
21502
- const keepWhen = (kept) => (items) => pipe(items, Array$1.filter(() => kept));
21503
- const unpublished = Effect.fn("publish.unpublished")(function* unpublished(directory, manifest) {
21504
- if (!goesToNpm(manifest)) return false;
21505
- return !(yield* onNpm({
21506
- directory,
21507
- ...manifest
21508
- }));
21509
- });
21510
- const needsNpm = Effect.fn("publish.needsNpm")(function* needsNpm(directory, manifest, workspaces) {
21511
- if (!(yield* unpublished(directory, manifest))) return false;
21512
- yield* requirePublishedDependencies({
21513
- manifest,
21514
- workspaces
21515
- });
21516
- return true;
21517
- });
21518
- const needsRelease = Effect.fn("publish.needsRelease")(function* needsRelease(directory, manifest, builds) {
21519
- const tag = tagOf({
21520
- directory,
21521
- ...manifest
21522
- });
21523
- if (!isVersioned(manifest)) return false;
21524
- if (isRoot(directory)) return !(yield* released(tag));
21525
- if (Array$1.isReadonlyArrayEmpty(builds)) return false;
21526
- return !(yield* releasedWithAssets(tag));
21527
- });
21528
- const nativeOf = (manifest) => pipe(Option.fromUndefinedOr(manifest.native), Option.map(({ targets }) => nativeTargetsOf(targets)), Option.getOrElse(() => []));
21199
+ const nativeTargetsOf = (targets) => pipe(targets, Array$1.flatMap((target) => pipe(Array$1.head(String$1.split(target, "-")), Option.flatMap((platform) => Record.get(NODE_PLATFORMS, platform)), Option.map((os) => ({
21200
+ target,
21201
+ runner: RUNNERS[os]
21202
+ })), Option.toArray)));
21203
+ const libcOf = (parts) => pipe(Array$1.get(parts, ABI_INDEX), Option.flatMap((abi) => Record.get(LIBC, abi)), Option.match({
21204
+ onNone: () => ({}),
21205
+ onSome: (libc) => ({ libc: [libc] })
21206
+ }));
21529
21207
  /** @internal */
21530
- const planOf = Effect.fn("publish.plan")(function* planOf(directory) {
21531
- const workspace = yield* workspaceOf(directory);
21532
- const manifest = yield* readVersionedPackageJson(workspace);
21533
- const graph = yield* graphTasks;
21534
- const tasks = tasksIn(graph, workspace);
21535
- const npm = yield* needsNpm(workspace, manifest, workspacesOf(graph));
21536
- const release = yield* needsRelease(workspace, manifest, buildsOf(tasks));
21537
- const built = keepWhen(release || !isVersioned(manifest));
21538
- const tag = tagOf({
21539
- directory: workspace,
21540
- ...manifest
21541
- });
21208
+ const nativeFileOf = ({ binary, target }) => `${binary}.${target}.node`;
21209
+ /** @internal */
21210
+ const nativeFields = (native) => {
21211
+ const parts = String$1.split(native.target, "-");
21212
+ const file = nativeFileOf(native);
21542
21213
  return {
21543
- directory: workspace,
21544
- name: releaseName(manifest),
21545
- version: manifest.version,
21546
- tag,
21547
- tagged: yield* allTagged(workspace, manifest),
21548
- environment: environmentOf(manifest),
21549
- npm,
21550
- native: keepWhen(npm)(nativeOf(manifest)),
21551
- builds: built(buildsOf(tasks)),
21552
- checks: built(checksOf(tasks)),
21553
- release,
21554
- hook: release && Array$1.contains(tasks, HOOK)
21214
+ name: `${native.name}-${native.target}`,
21215
+ version: native.version,
21216
+ os: Option.toArray(Array$1.head(parts)),
21217
+ cpu: Option.toArray(Array$1.get(parts, CPU_INDEX)),
21218
+ ...libcOf(parts),
21219
+ main: file,
21220
+ files: [file]
21555
21221
  };
21556
- });
21557
- const untaggedCurrent = Effect.fn("publish.untaggedCurrent")(function* untaggedCurrent(directory, manifest) {
21558
- if (!isVersioned(manifest)) return false;
21559
- return !(yield* tagged(tagOf({
21560
- directory,
21561
- ...manifest
21562
- })));
21563
- });
21564
- const pending = Effect.fn("publish.pending")(function* pending(graph, directory) {
21565
- const manifest = yield* readVersionedPackageJson(directory);
21566
- const builds = buildsOf(tasksIn(graph, directory));
21567
- const needed = yield* Effect.all([
21568
- unpublished(directory, manifest),
21569
- needsRelease(directory, manifest, builds),
21570
- untaggedCurrent(directory, manifest)
21571
- ], { concurrency: "unbounded" });
21572
- return pipe(needed, Array$1.contains(true));
21573
- });
21574
- /** @internal */
21575
- const dispatchPending = Effect.fn("publish.dispatchPending")(function* dispatchPending(ref) {
21576
- const repository = yield* Config.String("GITHUB_REPOSITORY");
21577
- const graph = yield* graphTasks;
21578
- const directories = yield* Effect.filter(workspacesOf(graph), (directory) => pending(graph, directory), { concurrency: PLAN_CONCURRENCY });
21579
- yield* Effect.forEach(directories, (directory) => Effect.logInfo(`publishing ${directory}`).pipe(Effect.andThen(mustSucceed({
21580
- command: "gh",
21581
- args: [
21582
- "workflow",
21583
- "run",
21584
- WORKFLOW,
21585
- "--repo",
21586
- repository,
21587
- "--ref",
21588
- ref,
21589
- "-f",
21590
- `workspace=${directory}`
21591
- ]
21592
- }))), {
21593
- concurrency: 1,
21594
- discard: true
21595
- });
21596
- });
21222
+ };
21597
21223
  /** @internal */
21598
- const writePlan = Effect.fn("publish.writePlan")(function* writePlan(plan) {
21599
- const encoded = yield* Schema.encodeEffect(Schema.fromJsonString(PlanSchema))(plan);
21600
- yield* Effect.logInfo(encoded);
21601
- yield* writeOutputs({ plan: encoded });
21224
+ const nativeReadme = ({ name, target }) => `# ${name}-${target}\n\nThe prebuilt ${target} native addon of [${name}](https://www.npmjs.com/package/${name}). Install ${name} instead; npm picks this package for your platform.\n`;
21225
+ // src/features/publish-workspace/model/native-package.ts
21226
+ const NPM_DIR = "npm";
21227
+ const NATIVE_DIR = "native";
21228
+ const KEPT_FIELDS = [
21229
+ "license",
21230
+ "repository",
21231
+ "homepage",
21232
+ "bugs",
21233
+ "engines"
21234
+ ];
21235
+ const keptFields = Effect.fn("keptFields")(function* keptFields(directory) {
21236
+ const fields = yield* readRawPackageJson(directory);
21237
+ return pipe(fields, Record.filter((_value, key) => Array$1.contains(KEPT_FIELDS, key)));
21602
21238
  });
21603
- // src/features/publish-workspace/model/compat-plan.ts
21604
- const Directories = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
21605
21239
  /** @internal */
21606
- const isChecked = Effect.fn("compat.isChecked")(function* isChecked(directory) {
21607
- const manifest = yield* readVersionedPackageJson(directory);
21608
- return goesToNpm(manifest) && !Array$1.isReadonlyArrayEmpty(compatCasesOf(manifest));
21240
+ const writeNative = Effect.fn("publish.writeNative")(function* writeNative(directory, native) {
21241
+ const fileSystem = yield* FileSystem.FileSystem;
21242
+ const path = yield* Path.Path;
21243
+ const kept = yield* keptFields(directory);
21244
+ const target = path.resolve(directory, NPM_DIR, native.target);
21245
+ const file = nativeFileOf(native);
21246
+ yield* fileSystem.makeDirectory(target, { recursive: true });
21247
+ yield* fileSystem.copyFile(path.join(directory, NATIVE_DIR, file), path.join(target, file));
21248
+ yield* Effect.all([writePackageJson(target, {
21249
+ ...kept,
21250
+ ...nativeFields(native)
21251
+ }), fileSystem.writeFileString(path.join(target, "README.md"), nativeReadme(native))], { concurrency: "unbounded" });
21252
+ return target;
21609
21253
  });
21254
+ // src/features/publish-workspace/model/pack-hook.ts
21255
+ const HOOK_FILE = "pack-hook.mjs";
21610
21256
  /** @internal */
21611
- const writeCompatPlan = Effect.fn("publish.compatPlan")(function* writeCompatPlan() {
21612
- const graph = yield* graphTasks;
21613
- const checked = yield* Effect.filter(workspacesOf(graph), isChecked, { concurrency: 1 });
21614
- const encoded = yield* Schema.encodeEffect(Directories)(checked);
21615
- yield* Effect.logInfo(encoded);
21616
- yield* writeOutputs({ directories: encoded });
21617
- });
21618
- // src/features/publish-workspace/model/compat-changed.ts
21619
- const LOCAL_ONLY = "the compat jobs of the verify workflow run it for every package in CI";
21620
- const ARITY$1 = 2;
21621
- const selected = (workspaces, directories) => {
21622
- if (Array$1.isReadonlyArrayEmpty(directories)) return workspaces;
21623
- return pipe(workspaces, Array$1.filter((workspace) => Array$1.contains(directories, workspace)));
21257
+ const WIDEN_RANGES = `const EXACT = /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$/u;
21258
+ const widen = (held) =>
21259
+ held === undefined
21260
+ ? undefined
21261
+ : Object.fromEntries(Object.entries(held).map(([name, specifier]) => [name, EXACT.test(specifier) ? \`^\${specifier}\` : specifier]));
21262
+ export const hooks = {
21263
+ beforePacking: (manifest) => ({
21264
+ ...manifest,
21265
+ dependencies: widen(manifest.dependencies),
21266
+ peerDependencies: widen(manifest.peerDependencies),
21267
+ }),
21624
21268
  };
21269
+ `;
21625
21270
  /** @internal */
21626
- const selectedWorkspaces = dual(ARITY$1, selected);
21271
+ const LOCKABLE_PLUGIN = `export const hooks = {
21272
+ beforePacking: ({ devDependencies, ...manifest }) => manifest,
21273
+ };
21274
+ `;
21275
+ const hookOf = (plugin) => {
21276
+ if (plugin) return LOCKABLE_PLUGIN;
21277
+ return WIDEN_RANGES;
21278
+ };
21627
21279
  /** @internal */
21628
- const checkChangedCompat = Effect.fn("publish.compatChanged")(function* checkChangedCompat(directories) {
21629
- if (yield* Config.Boolean("GITHUB_ACTIONS").pipe(Config.withDefault(false))) return yield* Console.log(`compat skipped: ${LOCAL_ONLY}`);
21630
- const graph = yield* graphTasks;
21631
- const chosen = selectedWorkspaces(workspacesOf(graph), directories);
21632
- const checked = yield* Effect.filter(chosen, isChecked, { concurrency: 1 });
21633
- yield* Effect.forEach(checked, checkCompat, {
21634
- concurrency: 1,
21635
- discard: true
21636
- });
21637
- return yield* checkConsumers(checked);
21638
- });
21639
- // src/features/publish-workspace/model/npm.ts
21640
- const verifyPackage = Effect.fn("publish.verify")(function* verifyPackage(directory, manifest) {
21641
- const tasks = [
21642
- "build",
21643
- "test",
21644
- ...pipe(Option.fromUndefinedOr(manifest["size-limit"]), Option.map(() => "size"), Option.toArray)
21645
- ];
21646
- yield* Effect.forEach(tasks, (task) => mustSucceed({
21647
- command: "vp",
21648
- args: ["run", task],
21649
- cwd: directory
21650
- }), {
21651
- concurrency: 1,
21652
- discard: true
21653
- });
21654
- yield* checkExportTargets(directory);
21655
- yield* checkCompat(directory);
21280
+ const packHookEnv = Effect.fn("publish.packHook")(function* packHookEnv(directory, plugin) {
21281
+ const fileSystem = yield* FileSystem.FileSystem;
21282
+ const hook = (yield* Path.Path).join(directory, HOOK_FILE);
21283
+ yield* fileSystem.writeFileString(hook, hookOf(plugin));
21284
+ return { pnpm_config_pnpmfile: hook };
21656
21285
  });
21657
- const publishNative = Effect.fn("publish.publishNative")(function* publishNative(target) {
21658
- const { name, version } = yield* readVersionedPackageJson(target);
21659
- if (yield* onNpm({
21660
- directory: target,
21661
- name,
21662
- version
21663
- })) {
21664
- yield* Console.log(`${name}@${version} is already published, skipping`);
21665
- return name;
21666
- }
21286
+ // src/features/publish-workspace/model/pack.ts
21287
+ const TARBALL = "package.tgz";
21288
+ /** @internal */
21289
+ const pack = Effect.fn("publish.pack")(function* pack(directory) {
21290
+ const fileSystem = yield* FileSystem.FileSystem;
21291
+ const path = yield* Path.Path;
21292
+ const temporary = yield* fileSystem.makeTempDirectoryScoped();
21293
+ const tarball = path.join(temporary, TARBALL);
21294
+ const plugin = yield* isPlugin(directory);
21295
+ const env = yield* packHookEnv(temporary, plugin);
21667
21296
  yield* mustSucceed({
21668
- command: "npm",
21297
+ command: "vp",
21669
21298
  args: [
21670
- "publish",
21671
- ".",
21672
- ...PUBLISH_FLAGS
21299
+ "pm",
21300
+ "pack",
21301
+ "--out",
21302
+ tarball
21673
21303
  ],
21674
- cwd: target
21304
+ env,
21305
+ cwd: directory
21675
21306
  });
21676
- return name;
21307
+ if (plugin) yield* lockPlugin(tarball, temporary);
21308
+ return tarball;
21677
21309
  });
21678
- const addOptionalDependencies = (directory, names, version) => updatePackageJson(directory, { optionalDependencies: pipe(names, Array$1.map((name) => [name, version]), Record.fromEntries) }).pipe(Effect.withSpan("publish.optionalDependencies"));
21679
- const publishNatives = Effect.fn("publish.publishNatives")(function* publishNatives(directory, manifest) {
21680
- if (Predicate.isUndefined(manifest.native)) return;
21681
- const { binary, targets } = manifest.native;
21682
- const written = yield* Effect.forEach(targets, (target) => writeNative(directory, {
21310
+ // src/features/publish-workspace/model/compat-native.ts
21311
+ const HOST_PREFIX = `${platform()}-${arch()}-`;
21312
+ const builtOf$1 = (directory, manifest) => pipe(Option.fromUndefinedOr(manifest.native), Option.flatMap(({ binary, targets }) => pipe(targets, Array$1.findFirst(String$1.startsWith(HOST_PREFIX)), Option.map((target) => ({
21313
+ directory,
21314
+ manifest,
21315
+ binary,
21316
+ target
21317
+ })))));
21318
+ const packedNative = Effect.fn("compat.packedNative")(function* packedNative({ directory, manifest, binary, target }) {
21319
+ const written = yield* writeNative(directory, {
21683
21320
  name: manifest.name,
21684
21321
  version: manifest.version,
21685
21322
  binary,
21686
21323
  target
21687
- }), { concurrency: 1 });
21688
- const names = yield* Effect.forEach(written, publishNative, { concurrency: 1 });
21689
- yield* addOptionalDependencies(directory, names, manifest.version);
21324
+ });
21325
+ const tarball = yield* pack(written);
21326
+ return [[`${manifest.name}-${target}`, tarball]];
21690
21327
  });
21691
21328
  /** @internal */
21692
- const publishToNpm = Effect.fn("publish.npm")(function* publishToNpm(directory) {
21693
- const manifest = yield* readVersionedPackageJson(directory);
21694
- if (yield* onNpm({
21329
+ const nativeTarballs = Effect.fn("compat.native")(function* nativeTarballs(directory, manifest) {
21330
+ const none = [];
21331
+ return yield* pipe(builtOf$1(directory, manifest), Option.match({
21332
+ onNone: () => Effect.succeed(none),
21333
+ onSome: packedNative
21334
+ }));
21335
+ });
21336
+ // src/features/publish-workspace/model/compat-workspace.ts
21337
+ const closureOf = (known, names, seen) => {
21338
+ const [name, ...rest] = names;
21339
+ if (Predicate.isUndefined(name)) return seen;
21340
+ const found = Record.get(known, name);
21341
+ const reached = pipe(seen, Array$1.some((item) => item.manifest.name === name));
21342
+ if (Option.isNone(found) || reached) return closureOf(known, rest, seen);
21343
+ const inner = closureOf(known, runtimeDependencyNames(found.value.manifest), [...seen, found.value]);
21344
+ return closureOf(known, rest, inner);
21345
+ };
21346
+ /** @internal */
21347
+ const workspacesBeside = Effect.fn("compat.workspaces")(function* workspacesBeside(directory) {
21348
+ const fileSystem = yield* FileSystem.FileSystem;
21349
+ const path = yield* Path.Path;
21350
+ const parent = path.dirname(path.resolve(directory));
21351
+ const entries = yield* fileSystem.readDirectory(parent);
21352
+ const found = yield* Effect.forEach(entries, (entry) => readVersionedPackageJson(path.join(parent, entry)).pipe(Effect.map((manifest) => [{
21353
+ directory: path.join(parent, entry),
21354
+ manifest
21355
+ }]), Effect.orElseSucceed(() => [])), { concurrency: 1 });
21356
+ return pipe(Array$1.flatten(found), Array$1.map((workspace) => [workspace.manifest.name, workspace]), Record.fromEntries);
21357
+ });
21358
+ const builtTarball = Effect.fn("compat.pack")(function* builtTarball(directory) {
21359
+ yield* mustSucceed({
21360
+ command: "vp",
21361
+ args: ["run", "build"],
21362
+ cwd: directory
21363
+ });
21364
+ return yield* pack(directory);
21365
+ });
21366
+ const tarballsOf = Effect.fn("compat.tarballs")(function* tarballsOf({ directory, manifest }) {
21367
+ const tarball = yield* builtTarball(directory);
21368
+ const natives = yield* nativeTarballs(directory, manifest);
21369
+ const own = [[manifest.name, tarball]];
21370
+ return {
21371
+ name: manifest.name,
21372
+ version: manifest.version,
21373
+ tarballs: Record.fromEntries([...own, ...natives])
21374
+ };
21375
+ });
21376
+ /** @internal */
21377
+ const workspaceTarballs = Effect.fn("compat.local")(function* workspaceTarballs(directory, manifest) {
21378
+ const known = yield* workspacesBeside(directory);
21379
+ const reached = closureOf(known, runtimeDependencyNames(manifest), [{
21695
21380
  directory,
21696
- ...manifest
21697
- })) return yield* Console.log(`${manifest.name}@${manifest.version} is already published`);
21698
- yield* verifyPackage(directory, manifest);
21699
- yield* publishNatives(directory, manifest);
21700
- const tarball = yield* pack(directory);
21701
- return yield* mustSucceed({
21381
+ manifest
21382
+ }]);
21383
+ return yield* Effect.forEach(reached, tarballsOf, { concurrency: 1 });
21384
+ });
21385
+ const meetsPeer = (peers) => ({ name, version }) => Option.match(Record.get(peers, name), {
21386
+ onNone: () => true,
21387
+ onSome: (range) => semver.validRange(range) === null || semver.satisfies(version, range)
21388
+ });
21389
+ /** @internal */
21390
+ const tarballsFor = (peers) => (local) => pipe(local, Array$1.filter(meetsPeer(peers)), Array$1.flatMap(({ tarballs }) => Record.toEntries(tarballs)), Record.fromEntries);
21391
+ // src/features/publish-workspace/model/compat.ts
21392
+ const INSTALL_FLAGS = ["--no-audit", "--no-fund"];
21393
+ const IMPORT_ONLY = "await import(process.argv[1])";
21394
+ const Versions$1 = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
21395
+ const installedNode = Effect.fn("compat.node")(function* installedNode(directory, range) {
21396
+ const path = yield* Path.Path;
21397
+ yield* (yield* FileSystem.FileSystem).makeDirectory(directory, { recursive: true });
21398
+ const listed = yield* outputOf({
21702
21399
  command: "npm",
21703
21400
  args: [
21704
- "publish",
21705
- tarball,
21706
- ...PUBLISH_FLAGS
21401
+ "view",
21402
+ "node",
21403
+ "versions",
21404
+ "--json"
21707
21405
  ],
21708
21406
  cwd: directory
21709
21407
  });
21710
- }, Effect.scoped);
21711
- // src/features/publish-workspace/model/release.ts
21712
- const ASSETS = "release-assets";
21713
- const revisionOf = Effect.fn("publish.revision")(function* revisionOf(manifest) {
21714
- const head = yield* Config.String("GITHUB_SHA");
21715
- if (!goesToNpm(manifest)) return head;
21716
- const published = yield* provenanceCommit(manifest);
21717
- return Option.getOrElse(published, () => head);
21718
- });
21719
- const tagRevision = Effect.fn("publish.tag")(function* tagRevision(tag, manifest) {
21720
- if (yield* tagged(tag)) return;
21721
- const sha = yield* revisionOf(manifest);
21722
- yield* createTag({
21723
- tag,
21724
- sha
21408
+ const versions = yield* Schema.decodeEffect(Versions$1)(listed);
21409
+ const version = yield* Effect.fromOption(Option.fromNullishOr(semver.maxSatisfying([...versions], range))).pipe(Effect.mapError(() => IncompatiblePackage.make({ message: `No Node.js release satisfies ${range}` })));
21410
+ yield* mustSucceed({
21411
+ command: "npm",
21412
+ args: [
21413
+ "install",
21414
+ ...INSTALL_FLAGS,
21415
+ `node@${version}`
21416
+ ],
21417
+ cwd: directory
21725
21418
  });
21419
+ return {
21420
+ version,
21421
+ binary: path.join(directory, "node_modules", "node", "bin", "node")
21422
+ };
21726
21423
  });
21727
- const assetsIn = Effect.fn("publish.assets")(function* assetsIn(directory) {
21424
+ const consumerFields = ({ peers, tarballs }) => ({
21425
+ private: true,
21426
+ type: "module",
21427
+ dependencies: {
21428
+ ...peers,
21429
+ ...pipe(tarballs, Record.map((file) => `file:${file}`))
21430
+ },
21431
+ overrides: Record.fromIterableWith(Record.keys(tarballs), (sibling) => [sibling, `$${sibling}`])
21432
+ });
21433
+ const withViteOfVitePlus = Effect.fn("compat.vite")(function* withViteOfVitePlus(directory) {
21728
21434
  const fileSystem = yield* FileSystem.FileSystem;
21729
21435
  const path = yield* Path.Path;
21730
- const folder = path.join(directory, ASSETS);
21731
- if (!(yield* fileSystem.exists(folder))) return [];
21732
- const names = yield* fileSystem.readDirectory(folder, { recursive: true });
21733
- const files = yield* Effect.filter(pipe(names, Array$1.map((name) => path.join(folder, name))), (file) => fileSystem.stat(file).pipe(Effect.map(({ type }) => type === "File"), Effect.orElseSucceed(() => false)));
21734
- return Array$1.sort(files, Order.String);
21436
+ const text = yield* fileSystem.readFileString(path.join(directory, "node_modules", VITE_PLUS, PACKAGE_JSON_FILE));
21437
+ yield* Option.match(viteAliasOf(text), {
21438
+ onNone: () => Effect.void,
21439
+ onSome: (alias) => mustSucceed({
21440
+ command: "npm",
21441
+ args: [
21442
+ "install",
21443
+ "--ignore-scripts",
21444
+ "--force",
21445
+ ...INSTALL_FLAGS,
21446
+ alias
21447
+ ],
21448
+ cwd: directory
21449
+ })
21450
+ });
21735
21451
  });
21736
- const LIBRARY_NOTES = [
21737
- "--latest=false",
21738
- "--notes",
21739
- ""
21740
- ];
21741
- const ROOT_NOTES = ["--latest", "--generate-notes"];
21742
- const notesOf = (directory) => {
21743
- if (isRoot(directory)) return ROOT_NOTES;
21744
- return LIBRARY_NOTES;
21745
- };
21746
- const createRelease = Effect.fn("publish.createRelease")(function* createRelease({ directory, manifest }) {
21747
- const tag = tagOf({
21748
- directory,
21749
- ...manifest
21750
- });
21751
- const notes = notesOf(directory);
21752
- const repository = yield* Config.String("GITHUB_REPOSITORY");
21753
- if (yield* succeeds({
21754
- command: "gh",
21755
- args: [
21756
- "release",
21757
- "view",
21758
- tag,
21759
- "--repo",
21760
- repository
21761
- ]
21762
- })) return;
21452
+ const installedConsumer = Effect.fn("compat.consumer")(function* installedConsumer(root, consumer) {
21453
+ const fileSystem = yield* FileSystem.FileSystem;
21454
+ const directory = (yield* Path.Path).join(root, "consumer");
21455
+ yield* fileSystem.makeDirectory(directory, { recursive: true });
21456
+ yield* writePackageJson(directory, consumerFields(consumer));
21763
21457
  yield* mustSucceed({
21764
- command: "gh",
21458
+ command: "npm",
21765
21459
  args: [
21766
- "release",
21767
- "create",
21768
- tag,
21769
- "--repo",
21770
- repository,
21771
- "--verify-tag",
21772
- "--title",
21773
- `${releaseName(manifest)} v${manifest.version}`,
21774
- ...notes
21775
- ]
21460
+ "install",
21461
+ "--ignore-scripts",
21462
+ ...INSTALL_FLAGS
21463
+ ],
21464
+ cwd: directory
21776
21465
  });
21466
+ if (Record.has(consumer.peers, "vite-plus")) yield* withViteOfVitePlus(directory);
21467
+ return directory;
21777
21468
  });
21778
- const uploadAssets = Effect.fn("publish.uploadAssets")(function* uploadAssets({ directory, manifest }) {
21779
- const tag = tagOf({
21780
- directory,
21781
- ...manifest
21782
- });
21783
- const files = yield* assetsIn(directory);
21784
- if (Array$1.isReadonlyArrayEmpty(files) || (yield* releasedWithAssets(tag))) return;
21785
- const repository = yield* Config.String("GITHUB_REPOSITORY");
21786
- yield* createRelease({
21787
- directory,
21788
- manifest
21469
+ const importsOf = (manifest, compat) => {
21470
+ if (compat.label === "npx") return [];
21471
+ return smokeTargetsOf(manifest).imports;
21472
+ };
21473
+ const smoke = Effect.fn("compat.smoke")(function* smoke({ manifest, compat, runtime, consumer }) {
21474
+ const path = yield* Path.Path;
21475
+ const importer = [
21476
+ "--input-type=module",
21477
+ "-e",
21478
+ IMPORT_ONLY
21479
+ ];
21480
+ const runs = pipe(smokeTargetsOf(manifest).bins, Array$1.flatMap((file) => pipe(BIN_ARGUMENTS, Array$1.map((args) => [path.join(consumer, "node_modules", manifest.name, file), ...args]))));
21481
+ yield* Effect.forEach(importsOf(manifest, compat), (specifier) => loadsCleanly({
21482
+ runtime,
21483
+ consumer,
21484
+ failure: LOAD_FAILURE,
21485
+ args: [...importer, specifier]
21486
+ }), {
21487
+ concurrency: 1,
21488
+ discard: true
21789
21489
  });
21790
- yield* mustSucceed({
21791
- command: "gh",
21792
- args: [
21793
- "release",
21794
- "upload",
21795
- tag,
21796
- ...files,
21797
- "--repo",
21798
- repository,
21799
- "--clobber"
21800
- ]
21490
+ yield* Effect.forEach(runs, (args) => loadsCleanly({
21491
+ runtime,
21492
+ consumer,
21493
+ failure: CRASH,
21494
+ args
21495
+ }), {
21496
+ concurrency: 1,
21497
+ discard: true
21801
21498
  });
21802
21499
  });
21803
- /** @internal */
21804
- const publishRelease = Effect.fn("publish.release")(function* publishRelease(directory) {
21805
- const manifest = yield* readVersionedPackageJson(directory);
21806
- if (!isVersioned(manifest)) {
21807
- yield* Effect.logInfo(`${manifest.name} has no version to publish`);
21808
- return;
21809
- }
21810
- const tag = tagOf({
21811
- directory,
21812
- ...manifest
21500
+ const runCase = Effect.fn("compat.case")(function* runCase({ manifest, local, compat }) {
21501
+ const fileSystem = yield* FileSystem.FileSystem;
21502
+ const path = yield* Path.Path;
21503
+ const root = yield* fileSystem.makeTempDirectoryScoped();
21504
+ const runtime = yield* installedNode(path.join(root, "runtime"), compat.node);
21505
+ const tarballs = tarballsFor(compat.peers)(local);
21506
+ const consumer = yield* installedConsumer(root, {
21507
+ peers: compat.peers,
21508
+ tarballs
21813
21509
  });
21814
- yield* Effect.andThen(tagRevision(tag, manifest), backfillTags({
21815
- directory,
21816
- manifest
21817
- }));
21818
- yield* writeOutputs({ tag });
21819
- if (isRoot(directory)) yield* createRelease({
21820
- directory,
21821
- manifest
21510
+ const peers = pipe(Record.toEntries(compat.peers), Array$1.map(([name, range]) => `${name}@${range}`), Array$1.join(", "));
21511
+ yield* Console.log(`${manifest.name} ${compat.label}: Node.js ${runtime.version}, peers ${peers}`);
21512
+ yield* smoke({
21513
+ manifest,
21514
+ compat,
21515
+ runtime: runtime.binary,
21516
+ consumer
21822
21517
  });
21823
- yield* uploadAssets({
21824
- directory,
21825
- manifest
21518
+ }, Effect.scoped);
21519
+ /** @internal */
21520
+ const checkCompat = Effect.fn("publish.compat")(function* checkCompat(directory) {
21521
+ const manifest = yield* readVersionedPackageJson(directory);
21522
+ const cases = compatCasesOf(manifest);
21523
+ if (Array$1.isReadonlyArrayEmpty(cases)) return yield* IncompatiblePackage.make({ message: `${manifest.name} declares no engines.node, so there is no supported Node.js range to check` });
21524
+ const local = yield* workspaceTarballs(directory, manifest);
21525
+ yield* Effect.forEach(cases, (compat) => runCase({
21526
+ manifest,
21527
+ local,
21528
+ compat
21529
+ }), {
21530
+ concurrency: 1,
21531
+ discard: true
21826
21532
  });
21827
- });
21828
- // src/app/callers-command.ts
21533
+ return yield* checkPluginInstall(directory, manifest, tarballsFor({})(local));
21534
+ }, Effect.scoped);
21535
+ // src/features/publish-workspace/model/consumer-build.ts
21536
+ const PNPMFILE = ".pnpmfile.cjs";
21537
+ const TASK = "msch";
21829
21538
  const SUCCESS$2 = 0;
21830
- const REMOTE = "git";
21831
- const REMOTE_ARGS = [
21832
- "remote",
21833
- "get-url",
21834
- "origin"
21835
- ];
21836
- const taggedError = Schema.TaggedError;
21539
+ const TARBALLS_ENV = "MSCH_CONSUMER_TARBALLS";
21540
+ const TaskGraph$1 = Schema.Struct({ tasks: Schema.Record(Schema.String, Schema.Unknown) }).pipe(Schema.fromJsonString);
21541
+ const Tarballed = Schema.Struct({
21542
+ tarballs: Schema.Record(Schema.String, Schema.String),
21543
+ natives: Schema.Record(Schema.String, Schema.Array(Schema.String))
21544
+ }).pipe(Schema.fromJsonString);
21837
21545
  /** @internal */
21838
- var RepositoriesUnlisted = class extends taggedError()("RepositoriesUnlisted", { message: Schema.String }) {};
21839
- const ownRepository = Effect.fn("ownRepository")(function* ownRepository() {
21840
- const given = yield* Config.option(Config.String("GITHUB_REPOSITORY"));
21841
- if (Option.isSome(given)) return given;
21842
- const remote = yield* finished({
21843
- command: REMOTE,
21844
- args: REMOTE_ARGS
21546
+ const PNPMFILE_SOURCE = Array$1.join([
21547
+ `const { tarballs, natives } = JSON.parse(process.env.${TARBALLS_ENV});`,
21548
+ "const fields = [\"dependencies\", \"devDependencies\", \"optionalDependencies\"];",
21549
+ "module.exports = {",
21550
+ " hooks: {",
21551
+ " readPackage(manifest) {",
21552
+ " for (const field of fields) {",
21553
+ " for (const [name, file] of Object.entries(tarballs)) {",
21554
+ " if (name in (manifest[field] || {})) manifest[field][name] = \"file:\" + file;",
21555
+ " }",
21556
+ " }",
21557
+ " for (const name of natives[manifest.name] || []) {",
21558
+ " manifest.optionalDependencies = { ...manifest.optionalDependencies, [name]: \"file:\" + tarballs[name] };",
21559
+ " }",
21560
+ " return manifest;",
21561
+ " },",
21562
+ " },",
21563
+ "};",
21564
+ ""
21565
+ ], "\n");
21566
+ const headerOf = (token) => `http.https://github.com/.extraheader=Authorization: basic ${Base64.encode(`x-access-token:${token}`)}`;
21567
+ /** @internal */
21568
+ const cloneArguments = ({ fullName, directory, token }) => [
21569
+ ...Option.match(token, {
21570
+ onNone: () => [],
21571
+ onSome: (value) => ["-c", headerOf(value)]
21572
+ }),
21573
+ "clone",
21574
+ "--depth",
21575
+ "1",
21576
+ "--quiet",
21577
+ `https://github.com/${fullName}.git`,
21578
+ directory
21579
+ ];
21580
+ const stateOf = Effect.fn("consumers.state")(function* stateOf(directory) {
21581
+ return `${yield* outputOf({
21582
+ command: "git",
21583
+ args: [
21584
+ "status",
21585
+ "--porcelain=v1",
21586
+ "--untracked-files=all"
21587
+ ],
21588
+ cwd: directory
21589
+ })}\n${yield* outputOf({
21590
+ command: "git",
21591
+ args: ["diff"],
21592
+ cwd: directory
21593
+ })}`;
21594
+ });
21595
+ const hasTask = Effect.fn("consumers.hasTask")(function* hasTask(directory) {
21596
+ const listed = yield* outputOf({
21597
+ command: "vp",
21598
+ args: ["run", "--json"],
21599
+ cwd: directory
21845
21600
  });
21846
- return remoteOf(String$1.trim(remote.output));
21601
+ const { tasks } = yield* Schema.decodeEffect(TaskGraph$1)(listed);
21602
+ return Record.has(tasks, TASK);
21847
21603
  });
21848
- const textsOf = Effect.fn("textsOf")(function* textsOf(fullName) {
21849
- const directory = yield* (yield* FileSystem.FileSystem).makeTempDirectoryScoped({ prefix: "msch-callers-" });
21850
- if ((yield* finished({
21851
- command: "sh",
21604
+ const REPORTED_LINES = 40;
21605
+ const tailOf = (output) => pipe(String$1.split("\n")(output), Array$1.takeRight(REPORTED_LINES), Array$1.join("\n"));
21606
+ const brokenReason = Effect.fn("consumers.reason")(function* brokenReason(directory) {
21607
+ const before = yield* stateOf(directory);
21608
+ const { code, output } = yield* finished({
21609
+ command: "vp",
21852
21610
  args: [
21853
- "-c",
21854
- "gh api \"repos/$1/tarball\" | tar -xz --strip-components=1 -C \"$2\"",
21855
- "sh",
21856
- fullName,
21857
- directory
21858
- ]
21859
- })).code !== SUCCESS$2) return yield* RepositoriesUnlisted.make({ message: `${fullName} could not be downloaded` });
21860
- return yield* textsUnder(directory, fullName);
21861
- }, Effect.scoped);
21862
- const otherTexts = Effect.fn("otherTexts")(function* otherTexts() {
21863
- const listed = yield* listRepositories(Option.none());
21864
- const self = yield* ownRepository();
21865
- if (Option.isNone(listed) || Option.isNone(self)) return yield* RepositoriesUnlisted.make({ message: "The repositories of the owner could not be listed, so no caller was looked up" });
21866
- const others = consumersOf(listed.value)(self.value);
21867
- const texts = yield* Effect.forEach(others, ({ fullName }) => textsOf(fullName), { concurrency: 1 });
21868
- return Array$1.flatten(texts);
21611
+ "run",
21612
+ "--no-cache",
21613
+ TASK
21614
+ ],
21615
+ cwd: directory
21616
+ });
21617
+ const after = yield* stateOf(directory);
21618
+ if (code !== SUCCESS$2) return Option.some(`vp run ${TASK} exited with ${String(code)}:\n${tailOf(output)}`);
21619
+ return Option.liftPredicate(after, (state) => state !== before).pipe(Option.map((state) => `vp run ${TASK} rewrote files:\n${state}`));
21869
21620
  });
21870
- const callers = Effect.fn("callers")(function* callers(input) {
21871
- const root = (yield* RepositoryFiles).resolve(".");
21872
- const texts = yield* otherTexts();
21873
- const found = yield* surfaceProblems(root, {
21874
- reach: "published",
21875
- callers: texts
21621
+ const install = (directory, options) => mustSucceed({
21622
+ command: "vp",
21623
+ args: ["install", options.flag],
21624
+ cwd: directory,
21625
+ env: options.env
21626
+ });
21627
+ const withNewBuild = Effect.fn("consumers.withNewBuild")(function* withNewBuild(directory, build) {
21628
+ const fileSystem = yield* FileSystem.FileSystem;
21629
+ const pnpmfile = (yield* Path.Path).join(directory, PNPMFILE);
21630
+ const encoded = yield* Schema.encodeEffect(Tarballed)(build);
21631
+ yield* fileSystem.writeFileString(pnpmfile, PNPMFILE_SOURCE);
21632
+ yield* install(directory, {
21633
+ flag: "--no-frozen-lockfile",
21634
+ env: { [TARBALLS_ENV]: encoded }
21876
21635
  });
21877
- const problems = sortProblems(found);
21878
- yield* reportProblems(root, {
21879
- problems,
21880
- json: input.json
21636
+ yield* fileSystem.remove(pnpmfile);
21637
+ yield* mustSucceed({
21638
+ command: "git",
21639
+ args: [
21640
+ "checkout",
21641
+ "--",
21642
+ "."
21643
+ ],
21644
+ cwd: directory
21881
21645
  });
21882
- return yield* failWhenAny(problems.length);
21646
+ return yield* brokenReason(directory);
21883
21647
  });
21884
- /** @internal */
21885
- const callersCommand = Command.make("callers", { json: jsonFlag }, callers).pipe(Command.withDescription("Reports what a published package exports or declares as a command or flag that no repository of the owner uses"));
21886
- // src/features/run-changed/model/batches.ts
21887
- const ARITY = 2;
21888
- const NO_BATCHES = [];
21889
- const EMPTY_BATCH = {
21890
- units: [],
21891
- sources: 0
21892
- };
21893
- const bySourcesDescending = Order.mapInput(Order.flip(Order.Number), (unit) => unit.sources);
21894
- const byName = Order.mapInput(Order.String, (unit) => unit.name);
21895
- const added = (batch, unit) => ({
21896
- units: [...batch.units, unit],
21897
- sources: batch.sources + unit.sources
21648
+ const onItsOwnMain = Effect.fn("consumers.onItsOwnMain")(function* onItsOwnMain(directory) {
21649
+ yield* mustSucceed({
21650
+ command: "git",
21651
+ args: [
21652
+ "checkout",
21653
+ "--",
21654
+ "."
21655
+ ],
21656
+ cwd: directory
21657
+ });
21658
+ yield* mustSucceed({
21659
+ command: "git",
21660
+ args: ["clean", "-fdq"],
21661
+ cwd: directory
21662
+ });
21663
+ yield* install(directory, {
21664
+ flag: "--frozen-lockfile",
21665
+ env: {}
21666
+ });
21667
+ return yield* brokenReason(directory);
21898
21668
  });
21899
- const joined = (batches, unit, index) => pipe(Array$1.modify(batches, index, (batch) => added(batch, unit)), Option.getOrElse(() => batches));
21900
- const placed = (batches, unit, limit) => pipe(batches, Array$1.findFirstIndex((batch) => batch.sources + unit.sources <= limit), Option.match({
21901
- onNone: () => [...batches, added(EMPTY_BATCH, unit)],
21902
- onSome: (index) => joined(batches, unit, index)
21903
- }));
21904
- const filled = (batches, units, limit) => Array$1.matchLeft(units, {
21905
- onEmpty: () => batches,
21906
- onNonEmpty: (unit, rest) => filled(placed(batches, unit, limit), rest, limit)
21669
+ const cloned = Effect.fn("consumers.clone")(function* cloned({ consumer, token }) {
21670
+ const fileSystem = yield* FileSystem.FileSystem;
21671
+ const path = yield* Path.Path;
21672
+ const root = yield* fileSystem.makeTempDirectoryScoped();
21673
+ const directory = path.join(root, "consumer");
21674
+ yield* mustSucceed({
21675
+ command: "git",
21676
+ args: cloneArguments({
21677
+ fullName: consumer.fullName,
21678
+ directory,
21679
+ token
21680
+ })
21681
+ });
21682
+ return directory;
21907
21683
  });
21908
- const batched = (units, limit) => {
21909
- const ordered = pipe(units, Array$1.sortBy(bySourcesDescending, byName));
21910
- return pipe(filled(NO_BATCHES, ordered, limit), Array$1.map((batch) => batch.units));
21911
- };
21912
- /** @internal */
21913
- const batchesOf = dual(ARITY, batched);
21914
- // src/features/run-changed/model/records.ts
21915
- const RECORDS = [...MSCH_CACHE, "changed"];
21916
- const ARGUMENT_SEPARATOR$1 = "\0";
21917
- const recordsOf = Effect.fn("recordsOf")(function* recordsOf(root, command) {
21918
- const files = yield* RepositoryFiles;
21919
- const name = yield* files.hash(Array$1.join(command, ARGUMENT_SEPARATOR$1));
21920
- return yield* recordsIn(files.join(root, ...RECORDS, name));
21684
+ const verdict = Effect.fn("consumers.verdict")(function* verdict({ consumer, build }, directory) {
21685
+ const reason = yield* withNewBuild(directory, build);
21686
+ if (Option.isNone(reason)) {
21687
+ yield* Console.log(`${consumer.fullName}: ${TASK} passes with the new build`);
21688
+ return reason;
21689
+ }
21690
+ const baseline = yield* onItsOwnMain(directory);
21691
+ if (Option.isSome(baseline)) {
21692
+ yield* Console.log(`${consumer.fullName}: already fails on its own main, skipped`);
21693
+ return Option.none();
21694
+ }
21695
+ return Option.some(`${consumer.fullName}: ${reason.value}`);
21921
21696
  });
21922
- // src/features/run-changed/model/units.ts
21923
- const SEPARATOR$2 = "/";
21924
- const FIELD_SEPARATOR = "\0";
21925
- const LINE_SEPARATOR = "\n";
21926
- const EMPTY = "";
21927
- const READ_CONCURRENCY$2 = 16;
21928
- const SOURCE_FILE = /\.[cm]?[jt]sx?$/u;
21929
- const SHARED_CONFIG = /^(?:[^/]+\.config\.[cm]?[jt]s|tsconfig(?:\.[^/]+)?\.json|\.gitignore)$/u;
21930
- const memberOf = (names) => (file) => pipe(names, Array$1.findFirst((name) => String$1.startsWith(`${name}${SEPARATOR$2}`)(file)), Option.getOrElse(() => "."));
21931
- const entryOf = ([file, digest]) => `${file}${FIELD_SEPARATOR}${digest}`;
21932
- const digested = Effect.fn("digested")(function* digested(root, file) {
21933
- const files = yield* RepositoryFiles;
21934
- const digest = yield* files.hashFile(files.join(root, file));
21935
- return [file, Option.getOrElse(digest, () => EMPTY)];
21697
+ /** @internal */
21698
+ const checkConsumer = Effect.fn("consumers.check")(function* checkConsumer(checked) {
21699
+ const directory = yield* cloned(checked);
21700
+ if (!(yield* hasTask(directory))) {
21701
+ yield* Console.log(`${checked.consumer.fullName}: has no ${TASK} task, skipped`);
21702
+ return Option.none();
21703
+ }
21704
+ return yield* verdict(checked, directory);
21705
+ }, Effect.scoped);
21706
+ // src/features/publish-workspace/model/consumer-repositories.ts
21707
+ const GH = "gh";
21708
+ const SUCCESS$1 = 0;
21709
+ const READ_RAW = "Accept: application/vnd.github.raw+json";
21710
+ const MANIFESTS = ["package.json", "pnpm-workspace.yaml"];
21711
+ const REMOTE$1 = /[:/](?<owner>[^/:]+)\/(?<name>[^/]+?)(?:\.git)?$/u;
21712
+ const INSTALLATION = "/installation/repositories";
21713
+ const OWNED = "/user/repos?affiliation=owner";
21714
+ const REPOSITORY_FIELDS = "{full_name,archived,fork}|tojson";
21715
+ const Repository$1 = Schema.Struct({
21716
+ full_name: Schema.String,
21717
+ archived: Schema.Boolean,
21718
+ fork: Schema.Boolean
21936
21719
  });
21937
- const hashed = (lines) => Effect.gen(function* hashLines() {
21938
- return yield* (yield* RepositoryFiles).hash(Array$1.join(lines, LINE_SEPARATOR));
21720
+ const decodeRepository = Schema.decodeUnknownOption(Schema.fromJsonString(Repository$1));
21721
+ /** @internal */
21722
+ const repositoriesOf = (lines) => pipe(String$1.split("\n")(lines), Array$1.flatMap((line) => Option.toArray(decodeRepository(line))), Array$1.filter(({ archived, fork }) => !archived && !fork), Array$1.map(({ full_name: fullName }) => ({ fullName })));
21723
+ /** @internal */
21724
+ const remoteOf = (url) => pipe(Option.fromNullishOr(REMOTE$1.exec(url)), Option.flatMapNullishOr(({ groups }) => groups), Option.map(({ owner, name }) => `${owner ?? ""}/${name ?? ""}`));
21725
+ /** @internal */
21726
+ const consumersOf = (repositories) => (self) => {
21727
+ const prefix = pipe(String$1.split("/")(self), Array$1.head, Option.getOrElse(() => ""));
21728
+ return pipe(repositories, Array$1.filter(({ fullName }) => String$1.startsWith(`${prefix}/`)(fullName) && fullName !== self));
21729
+ };
21730
+ /** @internal */
21731
+ const mentionsAny = (names) => (text) => pipe(names, Array$1.some((name) => String$1.includes(name)(text)));
21732
+ const envOf = (token) => Option.match(token, {
21733
+ onNone: () => ({}),
21734
+ onSome: (value) => ({ GH_TOKEN: value })
21939
21735
  });
21940
- const ownedBy = (listing, name) => Option.getOrElse(Record.get(listing.owned, name), () => []);
21941
- const entriesIn = (listing, name) => pipe(ownedBy(listing, name), Array$1.map(entryOf));
21942
- const sourcesIn = (listing, name) => pipe(ownedBy(listing, name), Array$1.filter(([file]) => SOURCE_FILE.test(file))).length;
21943
- const closureOf = Effect.fn("closureOf")(function* closureOf(root, name) {
21944
- const files = yield* RepositoryFiles;
21945
- const directories = yield* workspaceClosure(files.join(root, name));
21946
- const names = pipe(directories, Array$1.map((directory) => files.relative(root, directory)), Array$1.filter(String$1.isNonEmpty));
21947
- return Array$1.sort(names, Order.String);
21736
+ const apiOutput = (args, token) => finished({
21737
+ command: GH,
21738
+ args: ["api", ...args],
21739
+ env: envOf(token)
21740
+ }).pipe(Effect.map(({ output, code }) => pipe(Option.some(output), Option.filter(() => code === SUCCESS$1))));
21741
+ const listing = (path, expression, token) => apiOutput([
21742
+ "--paginate",
21743
+ path,
21744
+ "--jq",
21745
+ expression
21746
+ ], token).pipe(Effect.map(Option.map(repositoriesOf)));
21747
+ /** @internal */
21748
+ const listRepositories = (token) => listing(INSTALLATION, `.repositories[]|${REPOSITORY_FIELDS}`, token).pipe(Effect.flatMap(Option.match({
21749
+ onNone: () => listing(OWNED, `.[]|${REPOSITORY_FIELDS}`, token),
21750
+ onSome: (found) => Effect.succeedSome(found)
21751
+ })));
21752
+ /** @internal */
21753
+ const manifestsOf = (token) => ({ fullName }) => Effect.forEach(MANIFESTS, (file) => apiOutput([
21754
+ `repos/${fullName}/contents/${file}`,
21755
+ "-H",
21756
+ READ_RAW
21757
+ ], token).pipe(Effect.map(Option.getOrElse(() => ""))), { concurrency: 1 }).pipe(Effect.map(Array$1.join("\n")));
21758
+ // src/features/publish-workspace/model/consumers.ts
21759
+ const MANIFEST_READ_CONCURRENCY = 4;
21760
+ /** @internal */
21761
+ const dependentsOf = (known) => (names) => {
21762
+ const reached = pipe(known, Record.filter(({ manifest }) => pipe(runtimeDependencyNames(manifest), Array$1.some((name) => Array$1.contains(names, name)))), Record.keys);
21763
+ const added = pipe(reached, Array$1.filter((name) => !Array$1.contains(names, name)));
21764
+ if (Array$1.isReadonlyArrayEmpty(added)) return names;
21765
+ return dependentsOf(known)([...names, ...added]);
21766
+ };
21767
+ const tokenOf = Config.option(Config.String("GITHUB_APP_TOKEN"));
21768
+ const selfOf = Effect.fn("consumers.self")(function* selfOf() {
21769
+ const given = yield* Config.option(Config.String("GITHUB_REPOSITORY"));
21770
+ if (Option.isSome(given)) return given.value;
21771
+ const url = yield* outputOf({
21772
+ command: "git",
21773
+ args: [
21774
+ "remote",
21775
+ "get-url",
21776
+ "origin"
21777
+ ]
21778
+ });
21779
+ return Option.getOrElse(remoteOf(url), () => "");
21948
21780
  });
21949
- const memberIn = (listing) => (name) => Effect.gen(function* readMember() {
21950
- const files = yield* RepositoryFiles;
21781
+ const nativesOf = (local) => pipe(local, Array$1.map(({ name, tarballs }) => [name, pipe(Record.keys(tarballs), Array$1.filter((entry) => entry !== name))]), Record.fromEntries);
21782
+ const builtOf = Effect.fn("consumers.built")(function* builtOf(directories) {
21783
+ const built = yield* Effect.forEach(directories, (directory) => readVersionedPackageJson(directory).pipe(Effect.flatMap((manifest) => workspaceTarballs(directory, manifest))), { concurrency: 1 });
21784
+ const local = Array$1.flatten(built);
21951
21785
  return {
21952
- name,
21953
- sources: sourcesIn(listing, name),
21954
- digest: yield* hashed(entriesIn(listing, name)),
21955
- installed: yield* installedPackages(listing.root, files.join(listing.root, name)),
21956
- closure: yield* closureOf(listing.root, name)
21786
+ tarballs: tarballsFor({})(local),
21787
+ natives: nativesOf(local)
21957
21788
  };
21958
21789
  });
21959
- const reached = (members) => (closure) => pipe(members, Array$1.filter(({ name }) => Array$1.contains(closure, name)));
21960
- const linesOf = (found) => {
21961
- const installed = pipe(found, Array$1.flatMap((member) => member.installed), Array$1.dedupe);
21962
- const digests = pipe(found, Array$1.map(({ name, digest }) => entryOf([name, digest])));
21963
- return [...Array$1.sort(installed, Order.String), ...digests];
21964
- };
21965
- const sharedKey = Effect.fn("sharedKey")(function* sharedKey(listing, members) {
21966
- const installed = yield* installedPackages(listing.root, listing.root);
21967
- const closure = yield* closureOf(listing.root, EMPTY);
21968
- const config = pipe(ownedBy(listing, "."), Array$1.filter(([file]) => SHARED_CONFIG.test(file)), Array$1.map(entryOf));
21969
- return yield* hashed([
21970
- ...installed,
21971
- ...config,
21972
- ...linesOf(reached(members)(closure))
21973
- ]);
21974
- });
21975
- const rootPaths = (listing) => pipe(ownedBy(listing, "."), Array$1.map(([file]) => file), Array$1.map((file) => {
21976
- const [top] = String$1.split(file, SEPARATOR$2);
21977
- if (pipe(listing.names, Array$1.some((name) => String$1.startsWith(`${top}${SEPARATOR$2}`)(name)))) return file;
21978
- return top;
21979
- }), Array$1.dedupe);
21980
- const rootUnit = Effect.fn("rootUnit")(function* rootUnit(listing, shared) {
21981
- const key = yield* hashed([
21982
- shared,
21983
- ".",
21984
- ...entriesIn(listing, ".")
21985
- ]);
21986
- return {
21987
- name: ".",
21988
- paths: rootPaths(listing),
21989
- key,
21990
- sources: sourcesIn(listing, ".")
21991
- };
21992
- });
21993
- const memberUnit = (shared, members) => (member) => hashed([
21994
- shared,
21995
- member.name,
21996
- ...linesOf(reached(members)(member.closure))
21997
- ]).pipe(Effect.map((key) => ({
21998
- name: member.name,
21999
- paths: [member.name],
22000
- key,
22001
- sources: member.sources
22002
- })));
22003
- const unitsOf = Effect.fn("unitsOf")(function* unitsOf(root) {
22004
- const listed = yield* (yield* RepositoryFiles).listedFiles(root);
22005
- const names = yield* workspaceDirectories(root);
22006
- const entries = yield* Effect.forEach(listed, (file) => digested(root, file), { concurrency: READ_CONCURRENCY$2 });
22007
- const listing = {
22008
- root,
22009
- names,
22010
- owned: Array$1.groupBy(entries, ([file]) => memberOf(names)(file))
22011
- };
22012
- const members = yield* Effect.forEach(names, memberIn(listing), { concurrency: READ_CONCURRENCY$2 });
22013
- const shared = yield* sharedKey(listing, members);
22014
- const units = yield* Effect.forEach(members, memberUnit(shared, members), { concurrency: 1 });
22015
- return [yield* rootUnit(listing, shared), ...units];
22016
- });
22017
- // src/features/run-changed/model/run.ts
22018
- const SUCCESS$1 = 0;
22019
- const LIST_SEPARATOR = ", ";
22020
- const ARGUMENT_SEPARATOR = " ";
22021
- const EVERYTHING = "everything";
22022
- const SINGLE_BATCH = 1;
22023
- const report = Effect.fn("report")(function* report(text) {
22024
- const stdio = yield* Stdio.Stdio;
22025
- yield* Stream.make(`msch changed: ${text}\n`).pipe(Stream.run(stdio.stderr()), Effect.orDie);
21790
+ const mentioning = Effect.fn("consumers.mentioning")(function* mentioning(candidates, names, token) {
21791
+ return yield* Effect.filter(candidates, (consumer) => manifestsOf(token)(consumer).pipe(Effect.map(mentionsAny(names))), { concurrency: MANIFEST_READ_CONCURRENCY });
22026
21792
  });
22027
- const pathsOf = (units, changed) => {
22028
- if (changed.length === units.length) return [];
22029
- return pipe(changed, Array$1.flatMap(({ paths }) => paths));
22030
- };
22031
- const namesOf = (units, changed) => {
22032
- if (changed.length === units.length) return EVERYTHING;
22033
- return pipe(changed, Array$1.map(({ name }) => name), Array$1.join(LIST_SEPARATOR));
22034
- };
22035
- const exitCodeOf = Effect.fn("exitCodeOf")(function* exitCodeOf(root, [command, ...args]) {
22036
- const code = yield* (yield* ChildProcessSpawner.ChildProcessSpawner).exitCode(ChildProcess.make(command, args, {
22037
- cwd: root,
22038
- extendEnv: true,
22039
- stdin: "ignore",
22040
- stdout: "inherit",
22041
- stderr: "inherit"
22042
- }));
22043
- return Number(code);
21793
+ const namesAffected = Effect.fn("consumers.affected")(function* namesAffected(directories) {
21794
+ const [first = "."] = directories;
21795
+ const known = yield* workspacesBeside(first);
21796
+ const own = yield* Effect.forEach(directories, (directory) => readVersionedPackageJson(directory).pipe(Effect.map(({ name }) => name)), { concurrency: 1 });
21797
+ return dependentsOf(known)(own);
22044
21798
  });
22045
- const keyOf = ({ key }) => key;
22046
- const keysAfter = (plan, records, batch) => {
22047
- const current = pipe(plan.units, Array$1.map(keyOf));
22048
- const kept = pipe(records.passed, Array$1.filter((key) => Array$1.contains(current, key)));
22049
- return Array$1.dedupe([...kept, ...pipe(batch, Array$1.map(keyOf))]);
22050
- };
22051
- const ranBatch = Effect.fn("ranBatch")(function* ranBatch(plan, batch) {
22052
- const code = yield* exitCodeOf(plan.root, [...plan.command, ...pathsOf(plan.units, batch)]);
22053
- const records = yield* recordsOf(plan.root, plan.command);
22054
- const keys = keysAfter(plan, records, batch);
22055
- yield* Effect.when(keepOnly(records, keys), Effect.succeed(code === SUCCESS$1));
22056
- return code;
21799
+ const unlisted = Effect.fn("consumers.unlisted")(function* unlisted() {
21800
+ if (yield* Config.Boolean("GITHUB_ACTIONS").pipe(Config.withDefault(false))) return yield* IncompatiblePackage.make({ message: "The consumers of the new build could not be listed, so none of them was checked" });
21801
+ return yield* Console.log("consumers skipped: no GitHub access to list them");
22057
21802
  });
22058
- const ran = Effect.fn("ran")(function* ran(plan, batchSources) {
22059
- const batches = batchesOf(plan.changed, batchSources);
22060
- yield* Effect.when(report(`${String(batches.length)} batches of at most ${String(batchSources)} source files`), Effect.succeed(batches.length > SINGLE_BATCH));
22061
- const codes = yield* Effect.forEach(batches, (batch) => ranBatch(plan, batch), { concurrency: 1 });
22062
- return pipe(codes, Array$1.findFirst((code) => code !== SUCCESS$1), Option.getOrElse(() => SUCCESS$1));
21803
+ const failing = Effect.fn("consumers.failing")(function* failing(found, build, token) {
21804
+ const reasons = yield* Effect.forEach(found, (consumer) => checkConsumer({
21805
+ consumer,
21806
+ build,
21807
+ token
21808
+ }), { concurrency: 1 });
21809
+ return Array$1.getSomes(reasons);
22063
21810
  });
22064
- /** @internal */
22065
- const runChanged = Effect.fn("runChanged")(function* runChanged(root, { command, batchSources }) {
22066
- const units = yield* unitsOf(root);
22067
- const records = yield* recordsOf(root, command);
22068
- const changed = pipe(units, Array$1.filter(({ key }) => !Array$1.contains(records.passed, key)));
22069
- const since = `since \`${Array$1.join(command, ARGUMENT_SEPARATOR)}\` last passed`;
22070
- if (!Array$1.isReadonlyArrayNonEmpty(changed)) {
22071
- yield* report(`nothing changed ${since}`);
22072
- return SUCCESS$1;
22073
- }
22074
- yield* report(`${String(changed.length)} of ${String(units.length)} changed ${since}: ${namesOf(units, changed)}`);
22075
- return yield* ran({
22076
- root,
22077
- command,
22078
- units,
22079
- changed
22080
- }, batchSources);
21811
+ const consumersAffected = Effect.fn("consumers.found")(function* consumersAffected(directories, token) {
21812
+ const listed = yield* listRepositories(token);
21813
+ if (Option.isNone(listed)) return Option.none();
21814
+ const self = yield* selfOf();
21815
+ const names = yield* namesAffected(directories);
21816
+ const found = yield* mentioning(consumersOf(listed.value)(self), names, token);
21817
+ const listedNames = pipe(found, Array$1.map(({ fullName }) => fullName));
21818
+ yield* Console.log(`consumers: ${Array$1.join(listedNames, ", ")}`);
21819
+ return Option.some(found);
22081
21820
  });
22082
- // src/app/changed-command.ts
22083
- const SUCCESS = 0;
22084
- const ONE_FAILURE$1 = 1;
22085
- const NO_LIMIT = Number.POSITIVE_INFINITY;
22086
- const atLeastOne = Schema.isGreaterThanOrEqualTo(1);
22087
- const BatchSize = Schema.Int.check(atLeastOne);
22088
- const changed = Effect.fn("changed")(function* changed(input) {
22089
- const files = yield* RepositoryFiles;
22090
- if ((yield* runChanged(files.resolve("."), {
22091
- batchSources: input.batchSources,
22092
- command: [input.program, ...input.rest]
22093
- })) !== SUCCESS) return yield* ProblemsFound.make({ count: ONE_FAILURE$1 });
21821
+ const verified = Effect.fn("consumers.verified")(function* verified(directories, found, token) {
21822
+ const build = yield* builtOf(directories);
21823
+ const broken = yield* failing(found, build, token);
21824
+ if (Array$1.isReadonlyArrayNonEmpty(broken)) return yield* IncompatiblePackage.make({ message: `The new build breaks its consumers:\n${Array$1.join(broken, "\n")}` });
22094
21825
  return yield* Effect.void;
22095
21826
  });
22096
21827
  /** @internal */
22097
- const changedCommand = Command.make("changed", {
22098
- batchSources: Flag.Int("batch-sources").pipe(Flag.withDescription("Runs the command in batches of at most this many source files"), Flag.withSchema(BatchSize), Flag.withDefault(NO_LIMIT)),
22099
- program: Argument.String("command").pipe(Argument.withDescription("The command to run, written after --")),
22100
- rest: Argument.String("argument").pipe(Argument.withDescription("The arguments of the command"), Argument.variadic())
22101
- }, changed).pipe(Command.withDescription("Runs a command with the paths of the workspaces whose inputs changed since it last passed"));
22102
- // src/app/lookup-report.ts
22103
- const NONE_FOUND = 0;
22104
- const LINE_BREAK$1 = "\n";
22105
- const byPlace = Order.Struct({
22106
- file: Order.String,
22107
- line: Order.Number
22108
- });
22109
- const textOf = (row, describe) => (json, rows) => {
22110
- if (json) return Schema.encodeEffect(row.pipe(Schema.Array, Schema.fromJsonString))(rows);
22111
- return Effect.succeed(pipe(rows, Array$1.map((found) => `${describe(found)}${LINE_BREAK$1}`), Array$1.join("")));
22112
- };
21828
+ const checkConsumers = Effect.fn("publish.consumers")(function* checkConsumers(directories) {
21829
+ if (Array$1.isReadonlyArrayEmpty(directories)) return yield* Effect.void;
21830
+ const token = yield* tokenOf;
21831
+ const found = yield* consumersAffected(directories, token);
21832
+ if (Option.isNone(found)) return yield* unlisted();
21833
+ return yield* verified(directories, found.value, token);
21834
+ }, Effect.scoped);
21835
+ // src/features/publish-workspace/model/manifest.ts
21836
+ const UNVERSIONED$2 = "0.0.0";
21837
+ const ROOT = ".";
22113
21838
  /** @internal */
22114
- const lookupReport = ({ row, rows, describe }) => (json) => Effect.gen(function* report() {
22115
- const found = yield* rows((yield* RepositoryFiles).resolve("."));
22116
- const text = yield* textOf(row, describe)(json, Array$1.sort(found, byPlace));
22117
- yield* writeStdout(text);
22118
- if (found.length > NONE_FOUND) return yield* ProblemsFound.make({ count: found.length });
22119
- return NONE_FOUND;
22120
- });
22121
- // src/app/exits-command.ts
22122
- const MetRow = Schema.Struct({
22123
- file: Schema.String,
22124
- line: Schema.Finite,
22125
- section: Schema.String,
22126
- key: Schema.String,
22127
- condition: Schema.String,
22128
- outcome: Schema.Literals(["met", "unchecked"])
22129
- });
22130
- const VERDICTS$2 = {
22131
- met: "is met. Remove the deviation and run verify.",
22132
- unchecked: "could not be checked. Check it by hand or rerun where the lookup is reachable."
22133
- };
22134
- const describeRow$3 = (row) => `${row.file}:${String(row.line)} ${row.section} ${row.key}: the exit condition ${row.condition} ${VERDICTS$2[row.outcome]}`;
22135
- const rowsIn = Effect.fn("rowsIn")(function* rowsIn(root) {
22136
- const files = yield* RepositoryFiles;
22137
- const met = yield* upstreamExitsMet(root);
22138
- return pipe(met, Array$1.map(({ file, met: { entry, condition, outcome } }) => ({
22139
- file: files.relative(root, file),
22140
- line: entry.line,
22141
- section: entry.section,
22142
- key: entry.key,
22143
- condition,
22144
- outcome
22145
- })));
22146
- });
21839
+ const releaseName = ({ name }) => unscopedNameOf(name);
22147
21840
  /** @internal */
22148
- const exitsCommand = Command.make("exits", { json: jsonFlag }, ({ json }) => lookupReport({
22149
- row: MetRow,
22150
- rows: rowsIn,
22151
- describe: describeRow$3
22152
- })(json)).pipe(Command.withDescription("Reports upstream deviations whose exit condition is met"));
22153
- // src/features/judge-documents/model/agent-prompt.ts
21841
+ const isRoot = (directory) => directory === ROOT;
22154
21842
  /** @internal */
22155
- const AgentAnswer = Schema.Struct({
22156
- verdict: Schema.Literals([
22157
- "violation",
22158
- "pass",
22159
- "unknown"
22160
- ]),
22161
- quote: Schema.String,
22162
- reason: Schema.String
22163
- });
21843
+ const tagOf = ({ directory, name, version }) => {
21844
+ if (isRoot(directory)) return `v${version}`;
21845
+ return `${releaseName({ name })}-v${version}`;
21846
+ };
22164
21847
  /** @internal */
22165
- const AGENT_SCHEMA = Schema.toJsonSchemaDocument(AgentAnswer).schema;
22166
- const listOf = (names) => pipe(names, Array$1.map((name) => `- ${name}`), Array$1.join("\n"));
22167
- const readableNames = (context) => pipe(context, Array$1.map(({ name }) => name));
21848
+ const environmentOf = (manifest) => `${releaseName(manifest)}-release`;
22168
21849
  /** @internal */
22169
- const promptOf = ({ rule, target, context }) => pipe([
22170
- "Judge one rule against one file. The working directory holds only the files you may read.",
22171
- `Rule: ${rule.question}`,
22172
- `Target file: ${target.name}`,
22173
- "Other readable files:",
22174
- listOf(readableNames(context)),
22175
- "Read the target file, and read the other files when the rule needs them.",
22176
- "Answer \"violation\" only when the target file breaks the rule, \"pass\" when it does not, and \"unknown\" when these files do not let you decide.",
22177
- "For a violation, copy the offending text from the target file exactly as written into quote, without paraphrase and without added or removed characters. Leave quote empty otherwise.",
22178
- "Give the reason in one sentence."
22179
- ], Array$1.join("\n"));
22180
- // src/features/judge-documents/model/verdict.ts
22181
- const LINE_BREAK = "\n";
22182
- const FIRST_LINE$1 = 1;
22183
- const Violation = Schema.Struct({
22184
- status: Schema.Literal("violation"),
22185
- line: Schema.Int,
22186
- quote: Schema.String,
22187
- reason: Schema.String
22188
- });
22189
- const Pass = Schema.Struct({ status: Schema.Literal("pass") });
22190
- Schema.Struct({
22191
- status: Schema.Literal("unknown"),
22192
- reason: Schema.String
22193
- });
21850
+ const isVersioned = ({ version }) => version !== UNVERSIONED$2;
22194
21851
  /** @internal */
22195
- const DecidedVerdictSchema = Schema.Union([Violation, Pass]);
21852
+ const goesToNpm = (manifest) => !pipe(Option.fromUndefinedOr(manifest.private), Option.getOrElse(() => false));
21853
+ // src/features/publish-workspace/model/dependencies.ts
21854
+ const WORKSPACE_PROTOCOL$1 = "workspace:";
21855
+ const READ_CONCURRENCY$2 = 8;
21856
+ const WAIT_INTERVAL = "30 seconds";
21857
+ const WAIT_ATTEMPTS = 120;
22196
21858
  /** @internal */
22197
- const unknownBecause = (reason) => ({
22198
- status: "unknown",
22199
- reason
22200
- });
22201
- /** @internal */
22202
- const isDecided = (verdict) => verdict.status !== "unknown";
21859
+ const REGISTRY_FLAGS = ["--registry", PUBLIC_REGISTRY];
22203
21860
  /** @internal */
22204
- const textOfLine = ({ text, line }) => pipe(String$1.split(text, LINE_BREAK), Array$1.get(line - FIRST_LINE$1), Option.getOrElse(() => ""));
22205
- // src/features/judge-documents/model/agent-judge.ts
22206
- const AGENT_MODEL = "claude-sonnet-5-5";
22207
- const AGENT_EFFORT = "medium";
22208
- const AGENT_TOOLS = [
22209
- "Read",
22210
- "Grep",
22211
- "Glob"
21861
+ const PUBLISH_FLAGS = [
21862
+ "--provenance",
21863
+ "--access",
21864
+ "public",
21865
+ ...REGISTRY_FLAGS
22212
21866
  ];
22213
- const AGENT_MAX_TURNS = 50;
22214
- const AGENT_TIMEOUT = "10 minutes";
22215
- const sandboxOf = Effect.fn("sandboxOf")(function* sandboxOf(files) {
22216
- const fs = yield* FileSystem.FileSystem;
22217
- const path = yield* Path.Path;
22218
- const directory = yield* fs.makeTempDirectoryScoped({ prefix: "msch-judge-" });
22219
- yield* Effect.forEach(files, ({ name, text }) => {
22220
- const file = path.join(directory, name);
22221
- return fs.makeDirectory(path.dirname(file), { recursive: true }).pipe(Effect.andThen(fs.writeFileString(file, text)));
22222
- }, {
22223
- concurrency: "unbounded",
22224
- discard: true
22225
- });
22226
- return directory;
22227
- });
22228
- const verdictOf = (target, answer) => {
22229
- if (answer.verdict === "pass") return { status: "pass" };
22230
- if (answer.verdict === "unknown") return unknownBecause(answer.reason);
22231
- return Option.match(lineOfQuote({
22232
- text: target.text,
22233
- quote: answer.quote
22234
- }), {
22235
- onNone: () => unknownBecause("the quoted text is not in the target file"),
22236
- onSome: (line) => ({
22237
- status: "violation",
22238
- line,
22239
- quote: answer.quote,
22240
- reason: answer.reason
22241
- })
22242
- });
22243
- };
22244
- const judgeIn = Effect.fn("agentJudge")(function* judging(query, input) {
22245
- const output = yield* query({
22246
- directory: yield* sandboxOf([input.target, ...input.context]),
22247
- prompt: promptOf(input),
22248
- schema: AGENT_SCHEMA,
22249
- tools: AGENT_TOOLS,
22250
- allowed: AGENT_TOOLS,
22251
- model: AGENT_MODEL,
22252
- effort: AGENT_EFFORT,
22253
- maxTurns: AGENT_MAX_TURNS
22254
- });
22255
- const answer = yield* Schema.decodeUnknownEffect(AgentAnswer)(output);
22256
- return verdictOf(input.target, answer);
22257
- });
22258
- const reasonOf$1 = (failure) => {
22259
- if (typeof failure === "string") return failure;
22260
- if (failure instanceof Error) return failure.message;
22261
- return String(failure);
22262
- };
22263
21867
  /** @internal */
22264
- const agentJudge = (query) => ({
22265
- identity: {
22266
- model: AGENT_MODEL,
22267
- promptVersion: 1
22268
- },
22269
- judge: (input) => judgeIn(query, input).pipe(Effect.scoped, Effect.timeout(AGENT_TIMEOUT), Effect.match({
22270
- onSuccess: (verdict) => verdict,
22271
- onFailure: (failure) => unknownBecause(reasonOf$1(failure))
22272
- }))
22273
- });
22274
- // src/features/judge-documents/model/decision-judge.ts
22275
- const ANSWERED_YES = "The decision model answered yes.";
22276
- const judgeDecision = ({ rule, target: { text } }) => Effect.sync(() => {
22277
- const judged = judgeText({
22278
- rule: {
22279
- id: rule.id,
22280
- question: rule.question,
22281
- cutoff: rule.cutoff
22282
- },
22283
- text,
22284
- model: DECISION_MODEL,
22285
- timeoutMs: DECISION_TIMEOUT_MS,
22286
- env: {}
21868
+ const onNpm = Effect.fn("publish.onNpm")(function* onNpm({ directory, name, version }) {
21869
+ return yield* succeeds({
21870
+ command: "npm",
21871
+ args: [
21872
+ "view",
21873
+ `${name}@${version}`,
21874
+ "version",
21875
+ ...REGISTRY_FLAGS
21876
+ ],
21877
+ cwd: directory
22287
21878
  });
22288
- if (judged.status === "violation") return {
22289
- status: "violation",
22290
- line: judged.line,
22291
- quote: textOfLine({
22292
- text,
22293
- line: judged.line
22294
- }),
22295
- reason: ANSWERED_YES
22296
- };
22297
- if (judged.status === "pass") return { status: "pass" };
22298
- return unknownBecause(judged.reason);
22299
21879
  });
21880
+ const taggedError$1 = Schema.TaggedError;
22300
21881
  /** @internal */
22301
- const DECISION_JUDGE = {
22302
- identity: {
22303
- model: DECISION_MODEL,
22304
- promptVersion: 1
22305
- },
22306
- judge: judgeDecision
22307
- };
22308
- // src/features/judge-documents/model/judge-rules.ts
22309
- const DECISION_CUTOFF = .8;
22310
- /** @internal */
22311
- const JUDGE_RULES = [
22312
- {
22313
- kind: "decision",
22314
- id: "agents-no-task-record",
22315
- files: ["**/AGENTS.md"],
22316
- question: "Does this document record finished work, such as a changelog, a dated list of completed tasks or the history of what was changed and why, instead of rules and facts that stay true? Answer no for standing rules, commands and structure, even when a rule names a date or gives the reason it exists.",
22317
- message: "Do not add a record of finished work to AGENTS.md. Put the reason for a change in its commit message.",
22318
- cutoff: DECISION_CUTOFF
22319
- },
22320
- {
22321
- kind: "decision",
22322
- id: "readme-no-code-restatement",
22323
- files: ["**/README.md"],
22324
- question: "Does this README list what the code already shows, such as every file, module, exported function, parameter, option or endpoint, instead of saying what the project is, how to start using it and where it is published? Answer no for a short table of entry points that a reader needs before opening the code, and for install and usage commands.",
22325
- message: "Do not copy what the code shows into the README. Say what it is, how to start using it and where it is published, and leave parameters, options and file lists to the types and the code.",
22326
- cutoff: DECISION_CUTOFF
22327
- },
22328
- {
22329
- kind: "agent",
22330
- id: "skill-restates-skill",
22331
- files: ["**/skills/*/SKILL.md"],
22332
- context: ["../*/SKILL.md", "./**/*.md"],
22333
- question: "Does this skill state a rule that another skill among the readable files also states in substance, so that two copies of one rule can drift apart? Answer no when the two rules differ in scope or reason, and when this skill only points to the other one.",
22334
- message: "Keep each rule in one skill. Replace the copy with a pointer to the skill that owns the rule, or move the rule to where both can follow it."
22335
- }
22336
- ];
22337
- // src/features/judge-documents/model/judge-cache.ts
22338
- const encodeJson = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
22339
- const decodeCached = Schema.decodeUnknownOption(Schema.fromJsonString(DecidedVerdictSchema));
22340
- const encodeCached = Schema.encodeEffect(Schema.fromJsonString(DecidedVerdictSchema));
22341
- const ruleKey = ({ rule }) => {
22342
- if (rule.kind === "decision") return {
22343
- kind: rule.kind,
22344
- id: rule.id,
22345
- question: rule.question,
22346
- cutoff: rule.cutoff
22347
- };
22348
- return {
22349
- kind: rule.kind,
22350
- id: rule.id,
22351
- question: rule.question,
22352
- context: rule.context
22353
- };
21882
+ var UnpublishedDependencies = class extends taggedError$1()("UnpublishedDependencies", { message: Schema.String }) {};
21883
+ const workspaceDependencies = (manifest) => pipe(Option.fromUndefinedOr(manifest.dependencies), Option.map((dependencies) => pipe(dependencies, Record.filter(String$1.startsWith(WORKSPACE_PROTOCOL$1)), Record.keys)), Option.getOrElse(() => []));
21884
+ const failWhenMissing = (missing, manifest) => {
21885
+ if (Array$1.isReadonlyArrayEmpty(missing)) return Effect.void;
21886
+ const names = pipe(missing, Array$1.map(({ directory, name, version }) => `${name}@${version} (${directory})`), Array$1.join(", "));
21887
+ return Effect.fail(UnpublishedDependencies.make({ message: `${manifest.name} depends on versions that are not on npm yet. Publish them first: ${names}` }));
22354
21888
  };
22355
- /** @internal */
22356
- const cacheKeyOf = Effect.fn("cacheKeyOf")(function* cacheKeyOf(input, identity) {
22357
- const files = yield* RepositoryFiles;
22358
- const json = yield* encodeJson({
22359
- ...identity,
22360
- rule: ruleKey(input),
22361
- target: input.target,
22362
- context: pipe(input.context, Array$1.map(({ name, text }) => [name, text]))
22363
- }).pipe(Effect.orDie);
22364
- return yield* files.hash(json);
21889
+ const missingDependencies = Effect.fn("publish.missingDependencies")(function* missingDependencies({ manifest, workspaces }) {
21890
+ const wanted = workspaceDependencies(manifest);
21891
+ const siblings = yield* Effect.forEach(workspaces, (directory) => readVersionedPackageJson(directory).pipe(Effect.map((found) => ({
21892
+ directory,
21893
+ ...found
21894
+ }))), { concurrency: READ_CONCURRENCY$2 });
21895
+ const internal = pipe(siblings, Array$1.filter((sibling) => Array$1.contains(wanted, sibling.name) && goesToNpm(sibling)));
21896
+ const missing = yield* Effect.filter(internal, (sibling) => onNpm(sibling).pipe(Effect.map((published) => !published)), { concurrency: READ_CONCURRENCY$2 });
21897
+ yield* failWhenMissing(missing, manifest);
22365
21898
  });
22366
- const fileOf = (directory, key) => RepositoryFiles.pipe(Effect.map((files) => files.join(directory, `${key}.json`)));
22367
21899
  /** @internal */
22368
- const readCached = Effect.fn("readCached")(function* readCached(directory, key) {
22369
- const files = yield* RepositoryFiles;
22370
- const file = yield* fileOf(directory, key);
22371
- return (yield* files.readFile(file)).pipe(Option.flatMap(decodeCached));
21900
+ const requirePublishedDependencies = (dependent) => missingDependencies(dependent).pipe(Effect.tapError((missing) => Effect.logInfo(`waiting: ${missing.message}`)), Effect.retry({
21901
+ schedule: Schedule.spaced(WAIT_INTERVAL),
21902
+ times: WAIT_ATTEMPTS,
21903
+ while: Schema.is(UnpublishedDependencies)
21904
+ }));
21905
+ // src/features/publish-workspace/model/provenance.ts
21906
+ const ATTESTATIONS = "https://registry.npmjs.org/-/npm/v1/attestations/";
21907
+ const SLSA = /slsa\.dev\/provenance/u;
21908
+ const Digest = Schema.Struct({ gitCommit: Schema.String });
21909
+ const Dependency = Schema.Struct({
21910
+ uri: Schema.String,
21911
+ digest: Digest
22372
21912
  });
22373
- /** @internal */
22374
- const writeCached = Effect.fn("writeCached")(function* writeCached(directory, { key, verdict }) {
22375
- if (!isDecided(verdict)) return;
22376
- const files = yield* RepositoryFiles;
22377
- const file = yield* fileOf(directory, key);
22378
- const text = yield* encodeCached(verdict).pipe(Effect.orDie);
22379
- yield* files.writeFile(file, text);
21913
+ const BuildDefinition = Schema.Struct({ resolvedDependencies: Schema.Array(Dependency) });
21914
+ const Predicate$1 = Schema.Struct({ buildDefinition: BuildDefinition });
21915
+ const Statement = Schema.fromJsonString(Schema.Struct({ predicate: Predicate$1 }));
21916
+ const Envelope = Schema.Struct({ payload: Schema.String });
21917
+ const Bundle = Schema.Struct({ dsseEnvelope: Envelope });
21918
+ const Attestation = Schema.Struct({
21919
+ predicateType: Schema.String,
21920
+ bundle: Bundle
22380
21921
  });
22381
- // src/features/judge-documents/model/judge-input.ts
22382
- /** @internal */
22383
- const isDecisionInput = (input) => input.rule.kind === "decision";
21922
+ const Attestations = Schema.Struct({ attestations: Schema.Array(Attestation) });
22384
21923
  /** @internal */
22385
- const isAgentInput = (input) => input.rule.kind === "agent";
21924
+ const commitOf = (repository) => (payload) => pipe(Base64.decodeString(payload), Effect.fromResult, Effect.flatMap(Schema.decodeEffect(Statement)), Effect.map(({ predicate }) => pipe(Array$1.head(predicate.buildDefinition.resolvedDependencies), Option.filter(({ uri }) => String$1.includes(`github.com/${repository}@`)(uri)), Option.map(({ digest }) => digest.gitCommit))), Effect.orElseSucceed(() => Option.none()));
22386
21925
  /** @internal */
22387
- const readJudgedFile = Effect.fn("readJudgedFile")(function* readJudgedFile(root, name) {
22388
- const files = yield* RepositoryFiles;
22389
- return (yield* files.readFile(files.join(root, name))).pipe(Option.map((found) => ({
22390
- name,
22391
- text: found
22392
- })));
21926
+ const provenanceCommit = Effect.fn("publish.provenanceCommit")(function* provenanceCommit({ name, version }) {
21927
+ const client = yield* HttpClient.HttpClient;
21928
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
21929
+ const url = `${ATTESTATIONS}${String$1.replace("/", "%2f")(name)}@${version}`;
21930
+ const found = yield* HttpClient.filterStatusOk(client).get(url).pipe(Effect.flatMap(HttpClientResponse.schemaBodyJson(Attestations)), Effect.map(({ attestations }) => Array$1.findFirst(attestations, ({ predicateType }) => SLSA.test(predicateType))), Effect.orElseSucceed(() => Option.none()));
21931
+ if (Option.isNone(found)) return Option.none();
21932
+ return yield* commitOf(repository)(found.value.bundle.dsseEnvelope.payload);
22393
21933
  });
21934
+ // src/features/publish-workspace/model/tags.ts
21935
+ const UNVERSIONED$1 = "0.0.0";
21936
+ const LOOKUP_CONCURRENCY$2 = 4;
21937
+ const Versions = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
22394
21938
  /** @internal */
22395
- const readJudgedFiles = Effect.fn("readJudgedFiles")(function* readJudgedFiles(root, names) {
22396
- const read = yield* Effect.forEach(names, (name) => readJudgedFile(root, name), { concurrency: "unbounded" });
22397
- return pipe(read, Array$1.getSomes);
21939
+ const tagged = Effect.fn("publish.tagged")(function* tagged(tag) {
21940
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
21941
+ return yield* succeeds({
21942
+ command: "gh",
21943
+ args: ["api", `repos/${repository}/git/ref/tags/${tag}`]
21944
+ });
22398
21945
  });
22399
- // src/features/judge-documents/model/judge-pairs.ts
22400
- const GLOB = ":(glob)";
22401
- const globsOf = (patterns) => pipe(patterns, Array$1.map((pattern) => `${GLOB}${pattern}`));
22402
- const contextNames = Effect.fn("contextNames")(function* contextNames(root, rule, name) {
22403
- if (rule.kind === "decision") return [];
22404
- const files = yield* RepositoryFiles;
22405
- const directory = files.dirname(name);
22406
- const listed = yield* Effect.forEach(rule.context, (pattern) => files.matchingFiles(root, globsOf([files.join(directory, pattern)])), { concurrency: "unbounded" });
22407
- return pipe(listed, Array$1.flatten, Array$1.filter((found) => found !== name), Array$1.dedupe, (names) => Array$1.sort(names, Order.String));
22408
- });
22409
- const inputOf = Effect.fn("inputOf")(function* inputOf(root, { rule, name }) {
22410
- const target = yield* readJudgedFile(root, name);
22411
- if (Option.isNone(target)) return Option.none();
22412
- const names = yield* contextNames(root, rule, name);
22413
- const context = yield* readJudgedFiles(root, names);
22414
- return Option.some({
22415
- rule,
22416
- target: target.value,
22417
- context
21946
+ const tokenEnv = Config.option(Config.String("GITHUB_APP_TOKEN")).pipe(Effect.map(Option.match({
21947
+ onNone: () => ({}),
21948
+ onSome: (value) => ({ GH_TOKEN: value })
21949
+ })));
21950
+ /** @internal */
21951
+ const createTag = Effect.fn("publish.createTag")(function* createTag({ tag, sha }) {
21952
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
21953
+ const env = yield* tokenEnv;
21954
+ yield* Effect.logInfo(`tagging ${tag} at ${sha}`);
21955
+ yield* mustSucceed({
21956
+ command: "gh",
21957
+ env,
21958
+ args: [
21959
+ "api",
21960
+ "-X",
21961
+ "POST",
21962
+ `repos/${repository}/git/refs`,
21963
+ "-f",
21964
+ `ref=refs/tags/${tag}`,
21965
+ "-f",
21966
+ `sha=${sha}`
21967
+ ]
22418
21968
  });
22419
21969
  });
22420
- const inputsOf = Effect.fn("inputsOf")(function* inputsOf(root, rule) {
22421
- const names = yield* (yield* RepositoryFiles).matchingFiles(root, globsOf(rule.files));
22422
- const inputs = yield* Effect.forEach(names, (name) => inputOf(root, {
22423
- rule,
22424
- name
22425
- }), { concurrency: "unbounded" });
22426
- return Array$1.getSomes(inputs);
21970
+ const isRelease = (version) => version !== UNVERSIONED$1 && semver.valid(version) !== null && semver.prerelease(version) === null;
21971
+ const publishedVersions$1 = Effect.fn("publish.publishedVersions")(function* publishedVersions({ directory, manifest }) {
21972
+ if (!goesToNpm(manifest)) return [];
21973
+ const text = yield* outputOf({
21974
+ command: "npm",
21975
+ args: [
21976
+ "view",
21977
+ manifest.name,
21978
+ "versions",
21979
+ "--json",
21980
+ ...REGISTRY_FLAGS
21981
+ ],
21982
+ cwd: directory
21983
+ }).pipe(Effect.orElseSucceed(() => "[]"));
21984
+ const versions = yield* Schema.decodeEffect(Versions)(text).pipe(Effect.orElseSucceed(() => []));
21985
+ return pipe(versions, Array$1.filter((version) => isRelease(version) && version !== manifest.version));
22427
21986
  });
22428
21987
  /** @internal */
22429
- const judgeInputs = Effect.fn("judgeInputs")(function* judgeInputs(root, rules) {
22430
- const perRule = yield* Effect.forEach(rules, (rule) => inputsOf(root, rule), { concurrency: "unbounded" });
22431
- return Array$1.flatten(perRule);
21988
+ const untaggedVersions = Effect.fn("publish.untaggedVersions")(function* untaggedVersions(workspace) {
21989
+ const versions = yield* publishedVersions$1(workspace);
21990
+ return yield* Effect.filter(versions, (version) => tagged(tagOf({
21991
+ directory: workspace.directory,
21992
+ name: workspace.manifest.name,
21993
+ version
21994
+ })).pipe(Effect.map((found) => !found)), { concurrency: LOOKUP_CONCURRENCY$2 });
22432
21995
  });
22433
- // src/features/judge-documents/model/judge-repository.ts
22434
- const AGENT_CONCURRENCY = 4;
22435
- const SEQUENTIAL = 1;
22436
- const FIRST_COLUMN = 1;
22437
- const QUOTE_START = 0;
22438
- const QUOTE_LIMIT = 160;
22439
- const WHITESPACE = /\s+/gu;
22440
- const oneLine = (text) => pipe(text, String$1.replaceAll(WHITESPACE, " "), String$1.trim, String$1.slice(QUOTE_START, QUOTE_LIMIT));
22441
- const cachedBy = (directory, judge) => (input) => Effect.gen(function* cached() {
22442
- const key = yield* cacheKeyOf(input, judge.identity);
22443
- const hit = yield* readCached(directory, key);
22444
- if (Option.isSome(hit)) return hit.value;
22445
- const verdict = yield* judge.judge(input);
22446
- yield* writeCached(directory, {
22447
- key,
22448
- verdict
21996
+ const backfillVersion = Effect.fn("publish.backfillVersion")(function* backfillVersion(workspace, version) {
21997
+ const { directory, manifest } = workspace;
21998
+ const tag = tagOf({
21999
+ directory,
22000
+ name: manifest.name,
22001
+ version
22002
+ });
22003
+ const commit = yield* provenanceCommit({
22004
+ name: manifest.name,
22005
+ version
22006
+ });
22007
+ if (Option.isNone(commit)) {
22008
+ yield* Effect.logWarning(`${tag} has no npm provenance, so it stays untagged`);
22009
+ return;
22010
+ }
22011
+ yield* createTag({
22012
+ tag,
22013
+ sha: commit.value
22449
22014
  });
22450
- return verdict;
22451
22015
  });
22452
- const problemOf = (file, { input, verdict }) => {
22453
- const { rule } = input;
22454
- if (verdict.status === "pass") return Option.none();
22455
- if (verdict.status === "unknown") return Option.some(problemInFile("judge-unknown")(file, `Could not decide ${rule.id}. ${verdict.reason}`));
22456
- return Option.some(problemAtPosition(rule.id)(file, {
22457
- line: verdict.line,
22458
- column: FIRST_COLUMN
22459
- }, `${rule.message} ${verdict.reason} Quoted: ${oneLine(verdict.quote)}`));
22460
- };
22461
22016
  /** @internal */
22462
- const judgeRepository = Effect.fn("judgeRepository")(function* judgeRepository(root, setup) {
22463
- const files = yield* RepositoryFiles;
22464
- const inputs = yield* judgeInputs(root, setup.rules);
22465
- const decisions = pipe(inputs, Array$1.filter(isDecisionInput));
22466
- const agents = pipe(inputs, Array$1.filter(isAgentInput));
22467
- const decided = yield* Effect.forEach(decisions, cachedBy(setup.cacheDirectory, setup.decision), { concurrency: SEQUENTIAL });
22468
- const reasoned = yield* Effect.forEach(agents, cachedBy(setup.cacheDirectory, setup.agent), { concurrency: AGENT_CONCURRENCY });
22469
- const answered = [...decisions, ...agents];
22470
- return pipe(Array$1.zip(answered, [...decided, ...reasoned]), Array$1.map(([input, verdict]) => problemOf(files.join(root, input.target.name), {
22471
- input,
22472
- verdict
22473
- })), Array$1.getSomes);
22474
- });
22475
- // src/app/judge-command.ts
22476
- const judge = Effect.fn("judge")(function* judge(input) {
22477
- const files = yield* RepositoryFiles;
22478
- const root = files.resolve(".");
22479
- const found = yield* judgeRepository(root, {
22480
- cacheDirectory: files.resolve(input.cacheDirectory),
22481
- rules: JUDGE_RULES,
22482
- decision: DECISION_JUDGE,
22483
- agent: agentJudge(sdkAgentQuery)
22484
- });
22485
- const problems = sortProblems(found);
22486
- yield* reportProblems(root, {
22487
- problems,
22488
- json: input.json
22017
+ const backfillTags = Effect.fn("publish.backfillTags")(function* backfillTags(workspace) {
22018
+ const versions = yield* untaggedVersions(workspace);
22019
+ yield* Effect.forEach(versions, (version) => backfillVersion(workspace, version), {
22020
+ concurrency: 1,
22021
+ discard: true
22489
22022
  });
22490
- return yield* failWhenAny(problems.length);
22491
22023
  });
22024
+ // src/features/publish-workspace/model/plan.ts
22025
+ const HOOK = "release:publish";
22026
+ const WORKFLOW = "publish.yml";
22027
+ const PLAN_CONCURRENCY = 4;
22028
+ const NONE = 0;
22029
+ const TRAILING_SLASH = /\/$/u;
22030
+ const Task = Schema.Struct({
22031
+ package: Schema.String,
22032
+ name: Schema.String
22033
+ });
22034
+ const TaskGraph = Schema.fromJsonString(Schema.Struct({
22035
+ workspaceRoot: Schema.String,
22036
+ tasks: Schema.Record(Schema.String, Task)
22037
+ }));
22038
+ const Runner = Schema.Struct({
22039
+ os: Schema.String,
22040
+ runner: Schema.String
22041
+ });
22042
+ const NativeTarget = Schema.Struct({
22043
+ target: Schema.String,
22044
+ runner: Schema.String
22045
+ });
22046
+ const PlanSchema = Schema.Struct({
22047
+ directory: Schema.String,
22048
+ name: Schema.String,
22049
+ version: Schema.String,
22050
+ tag: Schema.String,
22051
+ environment: Schema.String,
22052
+ npm: Schema.Boolean,
22053
+ native: Schema.Array(NativeTarget),
22054
+ builds: Schema.Array(Runner),
22055
+ checks: Schema.Array(Runner),
22056
+ release: Schema.Boolean,
22057
+ tagged: Schema.Boolean,
22058
+ hook: Schema.Boolean
22059
+ });
22060
+ const AssetCount = Schema.fromJsonString(Schema.Finite);
22492
22061
  /** @internal */
22493
- const judgeCommand = Command.make("judge", {
22494
- cacheDirectory: Argument.String("cache-directory").pipe(Argument.withDescription("The directory that keeps the verdicts between runs")),
22495
- json: jsonFlag
22496
- }, judge).pipe(Command.withDescription("Judges documents against rules that need reading, and reports violations"));
22497
- // src/app/publish-command.ts
22498
- const directory = Argument.String("directory").pipe(Argument.withDescription("The workspace directory"));
22499
- const plan = Command.make("plan", { directory }, (input) => planOf(input.directory).pipe(Effect.flatMap(writePlan))).pipe(Command.withDescription("Decides what publishing the workspace takes"));
22500
- const npm = Command.make("npm", { directory }, (input) => publishToNpm(input.directory)).pipe(Command.withDescription("Publishes the workspace to npm"));
22501
- const release = Command.make("release", { directory }, (input) => publishRelease(input.directory)).pipe(Command.withDescription("Publishes the workspace as a GitHub Release"));
22502
- const compat = Command.make("compat", { directory }, (input) => checkCompat(input.directory)).pipe(Command.withDescription("Checks the packed workspace against what it says it supports"));
22503
- const consumers = Command.make("consumers", { directory }, (input) => checkConsumers([input.directory])).pipe(Command.withDescription("Checks the repositories that use the workspace against its build"));
22504
- const compatPlan = Command.make("compat-plan", {}, () => writeCompatPlan()).pipe(Command.withDescription("Lists the workspaces whose compatibility is checked"));
22505
- const compatChanged = Command.make("compat-changed", { directories: Argument.String("directory").pipe(Argument.withDescription("The workspace directories that changed"), Argument.variadic()) }, (input) => checkChangedCompat(input.directories)).pipe(Command.withDescription("Checks the compatibility of the workspaces that changed"));
22506
- const dispatch = Command.make("dispatch", { ref: Argument.String("ref").pipe(Argument.withDescription("The ref to publish from")) }, (input) => dispatchPending(input.ref)).pipe(Command.withDescription("Starts the publish workflow for every version that is not out yet"));
22062
+ const graphTasks = outputOf({
22063
+ command: "vp",
22064
+ args: ["run", "--json"]
22065
+ }).pipe(Effect.flatMap(Schema.decodeEffect(TaskGraph)), Effect.map(({ tasks }) => Record.values(tasks)));
22066
+ const tasksIn = (tasks, directory) => pipe(tasks, Array$1.filter((task) => task.package === directory), Array$1.map(({ name }) => name));
22507
22067
  /** @internal */
22508
- const publishCommand = Command.make("publish").pipe(Command.withDescription("Plans and publishes a workspace to npm and GitHub Releases"), Command.withSubcommands([
22509
- plan,
22510
- npm,
22511
- release,
22512
- compat,
22513
- consumers,
22514
- compatPlan,
22515
- compatChanged,
22516
- dispatch
22517
- ]));
22518
- // src/features/check-published-versions/model/overdue.ts
22519
- const PUBLISH_WINDOW_MS = 72e5;
22520
- const versionAt = (root, tip, { file }) => RepositoryFiles.pipe(Effect.flatMap((files) => files.readAtRevision(root, tip, file)), Effect.map((before) => pipe(before, Option.flatMap(decodePackageJson), Option.flatMap(({ version }) => Option.fromUndefinedOr(version)))));
22521
- const publishWindowPassed = (root, { file }) => Effect.gen(function* passed() {
22522
- const committed = yield* (yield* RepositoryFiles).committedAt(root, file);
22523
- const now = yield* Clock.currentTimeMillis;
22524
- return Option.exists(committed, (at) => now - at >= PUBLISH_WINDOW_MS);
22068
+ const workspacesOf = (tasks) => pipe(tasks, Array$1.map((task) => task.package), Array$1.dedupe);
22069
+ const allTagged = Effect.fn("publish.allTagged")(function* allTagged(directory, manifest) {
22070
+ if (!isVersioned(manifest)) return true;
22071
+ const current = yield* tagged(tagOf({
22072
+ directory,
22073
+ ...manifest
22074
+ }));
22075
+ const older = yield* untaggedVersions({
22076
+ directory,
22077
+ manifest
22078
+ });
22079
+ return current && Array$1.isReadonlyArrayEmpty(older);
22525
22080
  });
22081
+ const workspaceOf = (directory) => Path.Path.pipe(Effect.map((path) => String$1.replace(TRAILING_SLASH, "")(path.normalize(directory))));
22526
22082
  /** @internal */
22527
- const overdue = ({ root, tip, sibling }) => Option.match(sibling, {
22528
- onNone: () => Effect.succeed(true),
22529
- onSome: (found) => Effect.gen(function* overdueSibling() {
22530
- const before = yield* versionAt(root, tip, found);
22531
- if (!Option.contains(before, found.version)) return false;
22532
- return yield* publishWindowPassed(root, found);
22533
- })
22083
+ const released = Effect.fn("publish.released")(function* released(tag) {
22084
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
22085
+ return yield* succeeds({
22086
+ command: "gh",
22087
+ args: [
22088
+ "release",
22089
+ "view",
22090
+ tag,
22091
+ "--repo",
22092
+ repository
22093
+ ]
22094
+ });
22534
22095
  });
22535
- // src/features/check-published-versions/model/published-dependencies.ts
22536
- const WORKSPACE_PROTOCOL = "workspace:";
22537
- const CATALOG_PROTOCOL = "catalog:";
22538
- const UNVERSIONED = "0.0.0";
22539
- const FIRST_LINE = 1;
22540
- const READ_CONCURRENCY$1 = 16;
22541
- const LOOKUP_CONCURRENCY$1 = 4;
22542
- const SECTIONS = ["dependencies", "optionalDependencies"];
22543
- const Packument$1 = Schema.Struct({ versions: Schema.Record(Schema.String, Schema.Unknown) });
22544
- const packageAt = (file, text) => pipe(decodePackageJson(text), Option.filter((manifest) => manifest.private !== true), Option.flatMap((manifest) => Option.all({
22545
- name: Option.fromUndefinedOr(manifest.name),
22546
- version: Option.fromUndefinedOr(manifest.version)
22547
- }).pipe(Option.filter(({ version }) => version !== UNVERSIONED), Option.map(({ name, version }) => ({
22548
- file,
22549
- name,
22550
- version,
22551
- text,
22552
- specified: pipe(SECTIONS, Array$1.flatMap((section) => specifiedIn(manifest[section])))
22553
- })))));
22554
- const OK = 200;
22555
- const NOT_FOUND$1 = 404;
22556
- const versionsIn = (response) => {
22557
- if (response.status === OK) return HttpClientResponse.schemaBodyJson(Packument$1)(response).pipe(Effect.map(({ versions }) => Option.some(Record.keys(versions))));
22558
- if (response.status === NOT_FOUND$1) return Effect.succeedSome([]);
22559
- return Effect.succeedNone;
22096
+ /** @internal */
22097
+ const releasedWithAssets = Effect.fn("publish.releasedWithAssets")(function* releasedWithAssets(tag) {
22098
+ const view = [
22099
+ "release",
22100
+ "view",
22101
+ tag,
22102
+ "--repo",
22103
+ yield* Config.String("GITHUB_REPOSITORY")
22104
+ ];
22105
+ if (!(yield* released(tag))) return false;
22106
+ return (yield* outputOf({
22107
+ command: "gh",
22108
+ args: [
22109
+ ...view,
22110
+ "--json",
22111
+ "assets",
22112
+ "--jq",
22113
+ ".assets | length"
22114
+ ]
22115
+ }).pipe(Effect.flatMap(Schema.decodeEffect(AssetCount)))) > NONE;
22116
+ });
22117
+ const keepWhen = (kept) => (items) => pipe(items, Array$1.filter(() => kept));
22118
+ const unpublished = Effect.fn("publish.unpublished")(function* unpublished(directory, manifest) {
22119
+ if (!goesToNpm(manifest)) return false;
22120
+ return !(yield* onNpm({
22121
+ directory,
22122
+ ...manifest
22123
+ }));
22124
+ });
22125
+ const needsNpm = Effect.fn("publish.needsNpm")(function* needsNpm(directory, manifest, workspaces) {
22126
+ if (!(yield* unpublished(directory, manifest))) return false;
22127
+ yield* requirePublishedDependencies({
22128
+ manifest,
22129
+ workspaces
22130
+ });
22131
+ return true;
22132
+ });
22133
+ const needsRelease = Effect.fn("publish.needsRelease")(function* needsRelease(directory, manifest, builds) {
22134
+ const tag = tagOf({
22135
+ directory,
22136
+ ...manifest
22137
+ });
22138
+ if (!isVersioned(manifest)) return false;
22139
+ if (isRoot(directory)) return !(yield* released(tag));
22140
+ if (Array$1.isReadonlyArrayEmpty(builds)) return false;
22141
+ return !(yield* releasedWithAssets(tag));
22142
+ });
22143
+ const nativeOf = (manifest) => pipe(Option.fromUndefinedOr(manifest.native), Option.map(({ targets }) => nativeTargetsOf(targets)), Option.getOrElse(() => []));
22144
+ /** @internal */
22145
+ const planOf = Effect.fn("publish.plan")(function* planOf(directory) {
22146
+ const workspace = yield* workspaceOf(directory);
22147
+ const manifest = yield* readVersionedPackageJson(workspace);
22148
+ const graph = yield* graphTasks;
22149
+ const tasks = tasksIn(graph, workspace);
22150
+ const npm = yield* needsNpm(workspace, manifest, workspacesOf(graph));
22151
+ const release = yield* needsRelease(workspace, manifest, buildsOf(tasks));
22152
+ const built = keepWhen(release || !isVersioned(manifest));
22153
+ const tag = tagOf({
22154
+ directory: workspace,
22155
+ ...manifest
22156
+ });
22157
+ return {
22158
+ directory: workspace,
22159
+ name: releaseName(manifest),
22160
+ version: manifest.version,
22161
+ tag,
22162
+ tagged: yield* allTagged(workspace, manifest),
22163
+ environment: environmentOf(manifest),
22164
+ npm,
22165
+ native: keepWhen(npm)(nativeOf(manifest)),
22166
+ builds: built(buildsOf(tasks)),
22167
+ checks: built(checksOf(tasks)),
22168
+ release,
22169
+ hook: release && Array$1.contains(tasks, HOOK)
22170
+ };
22171
+ });
22172
+ const untaggedCurrent = Effect.fn("publish.untaggedCurrent")(function* untaggedCurrent(directory, manifest) {
22173
+ if (!isVersioned(manifest)) return false;
22174
+ return !(yield* tagged(tagOf({
22175
+ directory,
22176
+ ...manifest
22177
+ })));
22178
+ });
22179
+ const pending = Effect.fn("publish.pending")(function* pending(graph, directory) {
22180
+ const manifest = yield* readVersionedPackageJson(directory);
22181
+ const builds = buildsOf(tasksIn(graph, directory));
22182
+ const needed = yield* Effect.all([
22183
+ unpublished(directory, manifest),
22184
+ needsRelease(directory, manifest, builds),
22185
+ untaggedCurrent(directory, manifest)
22186
+ ], { concurrency: "unbounded" });
22187
+ return pipe(needed, Array$1.contains(true));
22188
+ });
22189
+ /** @internal */
22190
+ const dispatchPending = Effect.fn("publish.dispatchPending")(function* dispatchPending(ref) {
22191
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
22192
+ const graph = yield* graphTasks;
22193
+ const directories = yield* Effect.filter(workspacesOf(graph), (directory) => pending(graph, directory), { concurrency: PLAN_CONCURRENCY });
22194
+ yield* Effect.forEach(directories, (directory) => Effect.logInfo(`publishing ${directory}`).pipe(Effect.andThen(mustSucceed({
22195
+ command: "gh",
22196
+ args: [
22197
+ "workflow",
22198
+ "run",
22199
+ WORKFLOW,
22200
+ "--repo",
22201
+ repository,
22202
+ "--ref",
22203
+ ref,
22204
+ "-f",
22205
+ `workspace=${directory}`
22206
+ ]
22207
+ }))), {
22208
+ concurrency: 1,
22209
+ discard: true
22210
+ });
22211
+ });
22212
+ /** @internal */
22213
+ const writePlan = Effect.fn("publish.writePlan")(function* writePlan(plan) {
22214
+ const encoded = yield* Schema.encodeEffect(Schema.fromJsonString(PlanSchema))(plan);
22215
+ yield* Effect.logInfo(encoded);
22216
+ yield* writeOutputs({ plan: encoded });
22217
+ });
22218
+ // src/features/publish-workspace/model/compat-plan.ts
22219
+ const Directories = Schema.String.pipe(Schema.Array, Schema.fromJsonString);
22220
+ /** @internal */
22221
+ const isChecked = Effect.fn("compat.isChecked")(function* isChecked(directory) {
22222
+ const manifest = yield* readVersionedPackageJson(directory);
22223
+ return goesToNpm(manifest) && !Array$1.isReadonlyArrayEmpty(compatCasesOf(manifest));
22224
+ });
22225
+ /** @internal */
22226
+ const writeCompatPlan = Effect.fn("publish.compatPlan")(function* writeCompatPlan() {
22227
+ const graph = yield* graphTasks;
22228
+ const checked = yield* Effect.filter(workspacesOf(graph), isChecked, { concurrency: 1 });
22229
+ const encoded = yield* Schema.encodeEffect(Directories)(checked);
22230
+ yield* Effect.logInfo(encoded);
22231
+ yield* writeOutputs({ directories: encoded });
22232
+ });
22233
+ // src/features/publish-workspace/model/compat-changed.ts
22234
+ const LOCAL_ONLY = "the compat jobs of the verify workflow run it for every package in CI";
22235
+ const ARITY = 2;
22236
+ const selected = (workspaces, directories) => {
22237
+ if (Array$1.isReadonlyArrayEmpty(directories)) return workspaces;
22238
+ return pipe(workspaces, Array$1.filter((workspace) => Array$1.contains(directories, workspace)));
22560
22239
  };
22561
- const publishedVersions = (name) => abbreviatedPackument(name).pipe(Effect.flatMap(versionsIn), Effect.orElseSucceed(() => Option.none()));
22562
- const catalogRanges = (settings) => pipe(settings, Option.map((found) => [...pipe(specifiedIn(found["catalog"]), Array$1.map(({ name, specifier }) => [name, specifier])), ...pipe(namedCatalogsOf(found), Array$1.flatMap(([, held]) => specifiedIn(held)), Array$1.map(({ name, specifier }) => [name, specifier]))]), Option.getOrElse(() => []), HashMap.fromIterable);
22563
- const lineOf = (text, dependency) => pipe(String$1.split(text, "\n"), Array$1.findFirstIndex((line) => String$1.includes(`"${dependency}"`)(line)), Option.match({
22564
- onNone: () => FIRST_LINE,
22565
- onSome: (index) => index + FIRST_LINE
22566
- }));
22567
- const rangeOf = (catalog, { name, specifier }) => {
22568
- if (String$1.startsWith(CATALOG_PROTOCOL)(specifier)) return HashMap.get(catalog, name);
22569
- return Option.some(specifier);
22240
+ /** @internal */
22241
+ const selectedWorkspaces = dual(ARITY, selected);
22242
+ /** @internal */
22243
+ const checkChangedCompat = Effect.fn("publish.compatChanged")(function* checkChangedCompat(directories) {
22244
+ if (yield* Config.Boolean("GITHUB_ACTIONS").pipe(Config.withDefault(false))) return yield* Console.log(`compat skipped: ${LOCAL_ONLY}`);
22245
+ const graph = yield* graphTasks;
22246
+ const chosen = selectedWorkspaces(workspacesOf(graph), directories);
22247
+ const checked = yield* Effect.filter(chosen, isChecked, { concurrency: 1 });
22248
+ yield* Effect.forEach(checked, checkCompat, {
22249
+ concurrency: 1,
22250
+ discard: true
22251
+ });
22252
+ return yield* checkConsumers(checked);
22253
+ });
22254
+ // src/features/publish-workspace/model/npm.ts
22255
+ const verifyPackage = Effect.fn("publish.verify")(function* verifyPackage(directory, manifest) {
22256
+ const tasks = [
22257
+ "build",
22258
+ "test",
22259
+ ...pipe(Option.fromUndefinedOr(manifest["size-limit"]), Option.map(() => "size"), Option.toArray)
22260
+ ];
22261
+ yield* Effect.forEach(tasks, (task) => mustSucceed({
22262
+ command: "vp",
22263
+ args: ["run", task],
22264
+ cwd: directory
22265
+ }), {
22266
+ concurrency: 1,
22267
+ discard: true
22268
+ });
22269
+ yield* checkExportTargets(directory);
22270
+ yield* checkCompat(directory);
22271
+ });
22272
+ const publishNative = Effect.fn("publish.publishNative")(function* publishNative(target) {
22273
+ const { name, version } = yield* readVersionedPackageJson(target);
22274
+ if (yield* onNpm({
22275
+ directory: target,
22276
+ name,
22277
+ version
22278
+ })) {
22279
+ yield* Console.log(`${name}@${version} is already published, skipping`);
22280
+ return name;
22281
+ }
22282
+ yield* mustSucceed({
22283
+ command: "npm",
22284
+ args: [
22285
+ "publish",
22286
+ ".",
22287
+ ...PUBLISH_FLAGS
22288
+ ],
22289
+ cwd: target
22290
+ });
22291
+ return name;
22292
+ });
22293
+ const addOptionalDependencies = (directory, names, version) => updatePackageJson(directory, { optionalDependencies: pipe(names, Array$1.map((name) => [name, version]), Record.fromEntries) }).pipe(Effect.withSpan("publish.optionalDependencies"));
22294
+ const publishNatives = Effect.fn("publish.publishNatives")(function* publishNatives(directory, manifest) {
22295
+ if (Predicate.isUndefined(manifest.native)) return;
22296
+ const { binary, targets } = manifest.native;
22297
+ const written = yield* Effect.forEach(targets, (target) => writeNative(directory, {
22298
+ name: manifest.name,
22299
+ version: manifest.version,
22300
+ binary,
22301
+ target
22302
+ }), { concurrency: 1 });
22303
+ const names = yield* Effect.forEach(written, publishNative, { concurrency: 1 });
22304
+ yield* addOptionalDependencies(directory, names, manifest.version);
22305
+ });
22306
+ /** @internal */
22307
+ const publishToNpm = Effect.fn("publish.npm")(function* publishToNpm(directory) {
22308
+ const manifest = yield* readVersionedPackageJson(directory);
22309
+ if (yield* onNpm({
22310
+ directory,
22311
+ ...manifest
22312
+ })) return yield* Console.log(`${manifest.name}@${manifest.version} is already published`);
22313
+ yield* verifyPackage(directory, manifest);
22314
+ yield* publishNatives(directory, manifest);
22315
+ const tarball = yield* pack(directory);
22316
+ return yield* mustSucceed({
22317
+ command: "npm",
22318
+ args: [
22319
+ "publish",
22320
+ tarball,
22321
+ ...PUBLISH_FLAGS
22322
+ ],
22323
+ cwd: directory
22324
+ });
22325
+ }, Effect.scoped);
22326
+ // src/features/publish-workspace/model/release.ts
22327
+ const ASSETS = "release-assets";
22328
+ const revisionOf = Effect.fn("publish.revision")(function* revisionOf(manifest) {
22329
+ const head = yield* Config.String("GITHUB_SHA");
22330
+ if (!goesToNpm(manifest)) return head;
22331
+ const published = yield* provenanceCommit(manifest);
22332
+ return Option.getOrElse(published, () => head);
22333
+ });
22334
+ const tagRevision = Effect.fn("publish.tag")(function* tagRevision(tag, manifest) {
22335
+ if (yield* tagged(tag)) return;
22336
+ const sha = yield* revisionOf(manifest);
22337
+ yield* createTag({
22338
+ tag,
22339
+ sha
22340
+ });
22341
+ });
22342
+ const assetsIn = Effect.fn("publish.assets")(function* assetsIn(directory) {
22343
+ const fileSystem = yield* FileSystem.FileSystem;
22344
+ const path = yield* Path.Path;
22345
+ const folder = path.join(directory, ASSETS);
22346
+ if (!(yield* fileSystem.exists(folder))) return [];
22347
+ const names = yield* fileSystem.readDirectory(folder, { recursive: true });
22348
+ const files = yield* Effect.filter(pipe(names, Array$1.map((name) => path.join(folder, name))), (file) => fileSystem.stat(file).pipe(Effect.map(({ type }) => type === "File"), Effect.orElseSucceed(() => false)));
22349
+ return Array$1.sort(files, Order.String);
22350
+ });
22351
+ const LIBRARY_NOTES = [
22352
+ "--latest=false",
22353
+ "--notes",
22354
+ ""
22355
+ ];
22356
+ const ROOT_NOTES = ["--latest", "--generate-notes"];
22357
+ const notesOf = (directory) => {
22358
+ if (isRoot(directory)) return ROOT_NOTES;
22359
+ return LIBRARY_NOTES;
22570
22360
  };
22571
- const siblingWanted = (siblings, owner) => ({ name }) => pipe(HashMap.get(siblings, name), Option.map((sibling) => ({
22572
- owner,
22573
- name,
22574
- range: sibling.version,
22575
- sibling: Option.some(sibling)
22576
- })), Option.toArray);
22577
- const registryWanted = ({ siblings, catalog, routes }, owner) => (specified) => pipe(Option.liftPredicate(specified, ({ name }) => isOwnPackage(routes)(name)), Option.flatMap((own) => rangeOf(catalog, own)), Option.map((range) => ({
22578
- owner,
22579
- name: specified.name,
22580
- range,
22581
- sibling: pipe(HashMap.get(siblings, specified.name), Option.filter(({ version }) => semver.satisfies(version, range)))
22582
- })), Option.toArray);
22583
- const wantedBy = (sources) => (owner) => pipe(owner.specified, Array$1.flatMap((specified) => {
22584
- if (String$1.startsWith(WORKSPACE_PROTOCOL)(specified.specifier)) return siblingWanted(sources.siblings, owner)(specified);
22585
- return registryWanted(sources, owner)(specified);
22586
- }));
22587
- const lookupsOf = (wanted) => pipe(wanted, Array$1.map(({ name }) => name), Array$1.dedupe, (names) => Effect.forEach(names, (name) => Effect.map(publishedVersions(name), (found) => [name, found]), { concurrency: LOOKUP_CONCURRENCY$1 }), Effect.map(HashMap.fromIterable));
22588
- const reasonOf = (sibling) => Option.match(sibling, {
22589
- onNone: () => "is not on npm. Publish it first, or lower the range to a version that is.",
22590
- onSome: ({ file }) => `is still not on npm two hours after ${file} reached main. Read the failed publish run for it.`
22361
+ const createRelease = Effect.fn("publish.createRelease")(function* createRelease({ directory, manifest }) {
22362
+ const tag = tagOf({
22363
+ directory,
22364
+ ...manifest
22365
+ });
22366
+ const notes = notesOf(directory);
22367
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
22368
+ if (yield* succeeds({
22369
+ command: "gh",
22370
+ args: [
22371
+ "release",
22372
+ "view",
22373
+ tag,
22374
+ "--repo",
22375
+ repository
22376
+ ]
22377
+ })) return;
22378
+ yield* mustSucceed({
22379
+ command: "gh",
22380
+ args: [
22381
+ "release",
22382
+ "create",
22383
+ tag,
22384
+ "--repo",
22385
+ repository,
22386
+ "--verify-tag",
22387
+ "--title",
22388
+ `${releaseName(manifest)} v${manifest.version}`,
22389
+ ...notes
22390
+ ]
22391
+ });
22591
22392
  });
22592
- const missingIn = (known) => ({ owner, name, range, sibling }) => pipe(HashMap.get(known, name), Option.flatten, Option.filter((published) => semver.maxSatisfying([...published], range) === null), Option.map(() => ({
22593
- file: owner.file,
22594
- line: lineOf(owner.text, name),
22595
- dependency: `${name}@${range}`,
22596
- reason: reasonOf(sibling)
22597
- })), Option.toArray);
22598
- const wantedIn = Effect.fn("wantedIn")(function* wantedIn(root) {
22599
- const manifests = yield* manifestTexts(root);
22600
- const packages = pipe(manifests, Array$1.flatMap(({ file, text }) => Option.toArray(packageAt(file, text))));
22601
- const siblings = HashMap.fromIterable(pipe(packages, Array$1.map((found) => [found.name, found])));
22602
- const settings = yield* workspaceManifest(root);
22603
- const catalog = catalogRanges(pipe(settings, Option.map(fieldsOf)));
22604
- const routes = yield* packageRoutes(root);
22605
- return pipe(packages, Array$1.flatMap(wantedBy({
22606
- siblings,
22607
- catalog,
22608
- routes
22609
- })));
22393
+ const uploadAssets = Effect.fn("publish.uploadAssets")(function* uploadAssets({ directory, manifest }) {
22394
+ const tag = tagOf({
22395
+ directory,
22396
+ ...manifest
22397
+ });
22398
+ const files = yield* assetsIn(directory);
22399
+ if (Array$1.isReadonlyArrayEmpty(files) || (yield* releasedWithAssets(tag))) return;
22400
+ const repository = yield* Config.String("GITHUB_REPOSITORY");
22401
+ yield* createRelease({
22402
+ directory,
22403
+ manifest
22404
+ });
22405
+ yield* mustSucceed({
22406
+ command: "gh",
22407
+ args: [
22408
+ "release",
22409
+ "upload",
22410
+ tag,
22411
+ ...files,
22412
+ "--repo",
22413
+ repository,
22414
+ "--clobber"
22415
+ ]
22416
+ });
22417
+ });
22418
+ /** @internal */
22419
+ const publishRelease = Effect.fn("publish.release")(function* publishRelease(directory) {
22420
+ const manifest = yield* readVersionedPackageJson(directory);
22421
+ if (!isVersioned(manifest)) {
22422
+ yield* Effect.logInfo(`${manifest.name} has no version to publish`);
22423
+ return;
22424
+ }
22425
+ const tag = tagOf({
22426
+ directory,
22427
+ ...manifest
22428
+ });
22429
+ yield* Effect.andThen(tagRevision(tag, manifest), backfillTags({
22430
+ directory,
22431
+ manifest
22432
+ }));
22433
+ yield* writeOutputs({ tag });
22434
+ if (isRoot(directory)) yield* createRelease({
22435
+ directory,
22436
+ manifest
22437
+ });
22438
+ yield* uploadAssets({
22439
+ directory,
22440
+ manifest
22441
+ });
22442
+ });
22443
+ // src/app/callers-command.ts
22444
+ const SUCCESS = 0;
22445
+ const REMOTE = "git";
22446
+ const REMOTE_ARGS = [
22447
+ "remote",
22448
+ "get-url",
22449
+ "origin"
22450
+ ];
22451
+ const taggedError = Schema.TaggedError;
22452
+ /** @internal */
22453
+ var RepositoriesUnlisted = class extends taggedError()("RepositoriesUnlisted", { message: Schema.String }) {};
22454
+ /** @internal */
22455
+ const ownRepository = Effect.fn("ownRepository")(function* ownRepository() {
22456
+ const given = yield* Config.option(Config.String("GITHUB_REPOSITORY"));
22457
+ if (Option.isSome(given)) return given;
22458
+ const remote = yield* finished({
22459
+ command: REMOTE,
22460
+ args: REMOTE_ARGS
22461
+ });
22462
+ return remoteOf(String$1.trim(remote.output));
22610
22463
  });
22611
- /** @internal */
22612
- const missingVersions = Effect.fn("missingVersions")(function* missingVersions(root) {
22613
- const tip = yield* baseName;
22614
- const wanted = yield* wantedIn(root);
22615
- const due = yield* Effect.filter(wanted, ({ sibling }) => overdue({
22616
- root,
22617
- tip,
22618
- sibling
22619
- }), { concurrency: READ_CONCURRENCY$1 });
22620
- const known = yield* lookupsOf(due);
22621
- return pipe(due, Array$1.flatMap(missingIn(known)));
22464
+ const textsOf = Effect.fn("textsOf")(function* textsOf(fullName) {
22465
+ const directory = yield* (yield* FileSystem.FileSystem).makeTempDirectoryScoped({ prefix: "msch-callers-" });
22466
+ if ((yield* finished({
22467
+ command: "sh",
22468
+ args: [
22469
+ "-c",
22470
+ "gh api \"repos/$1/tarball\" | tar -xz --strip-components=1 -C \"$2\"",
22471
+ "sh",
22472
+ fullName,
22473
+ directory
22474
+ ]
22475
+ })).code !== SUCCESS) return yield* RepositoriesUnlisted.make({ message: `${fullName} could not be downloaded` });
22476
+ return yield* textsUnder(directory, fullName);
22477
+ }, Effect.scoped);
22478
+ const otherTexts = Effect.fn("otherTexts")(function* otherTexts() {
22479
+ const listed = yield* listRepositories(Option.none());
22480
+ const self = yield* ownRepository();
22481
+ if (Option.isNone(listed) || Option.isNone(self)) return yield* RepositoriesUnlisted.make({ message: "The repositories of the owner could not be listed, so no caller was looked up" });
22482
+ const others = consumersOf(listed.value)(self.value);
22483
+ const texts = yield* Effect.forEach(others, ({ fullName }) => textsOf(fullName), { concurrency: 1 });
22484
+ return Array$1.flatten(texts);
22622
22485
  });
22623
- // src/app/published-command.ts
22624
- const Row$2 = Schema.Struct({
22625
- file: Schema.String,
22626
- line: Schema.Finite,
22627
- dependency: Schema.String,
22628
- reason: Schema.String
22486
+ const callers = Effect.fn("callers")(function* callers(input) {
22487
+ const root = (yield* RepositoryFiles).resolve(".");
22488
+ const texts = yield* otherTexts();
22489
+ const found = yield* surfaceProblems(root, {
22490
+ reach: "published",
22491
+ callers: texts
22492
+ });
22493
+ const problems = sortProblems(found);
22494
+ yield* reportProblems(root, {
22495
+ problems,
22496
+ json: input.json
22497
+ });
22498
+ return yield* failWhenAny(problems.length);
22629
22499
  });
22630
- const describeRow$2 = (row) => `${row.file}:${String(row.line)} ${row.dependency} ${row.reason}`;
22631
22500
  /** @internal */
22632
- const publishedCommand = Command.make("published", { json: jsonFlag }, ({ json }) => lookupReport({
22633
- row: Row$2,
22634
- rows: missingVersions,
22635
- describe: describeRow$2
22636
- })(json)).pipe(Command.withDescription("Reports a dependency range that no version on npm satisfies"));
22501
+ const callersCommand = Command.make("callers", { json: jsonFlag }, callers).pipe(Command.withDescription("Reports what a published package exports or declares as a command or flag that no repository of the owner uses"));
22637
22502
  // src/features/check-references/model/markdown-texts.ts
22638
22503
  const MARKDOWN = ".md";
22639
22504
  const FIXTURE = /(?:^|\/)fixtures\//u;
22640
- const READ_CONCURRENCY = 16;
22505
+ const READ_CONCURRENCY$1 = 16;
22641
22506
  /** @internal */
22642
22507
  const markdownTexts = Effect.fn("markdownTexts")(function* markdownTexts(root) {
22643
22508
  const files = yield* RepositoryFiles;
@@ -22646,7 +22511,7 @@ const markdownTexts = Effect.fn("markdownTexts")(function* markdownTexts(root) {
22646
22511
  const read = yield* Effect.forEach(documents, (file) => Effect.map(files.readFile(file), Option.map((source) => ({
22647
22512
  file,
22648
22513
  source
22649
- }))), { concurrency: READ_CONCURRENCY });
22514
+ }))), { concurrency: READ_CONCURRENCY$1 });
22650
22515
  return Array$1.getSomes(read);
22651
22516
  });
22652
22517
  // src/features/check-references/model/declared-symbols.ts
@@ -22703,7 +22568,7 @@ const declaredSymbols = Effect.fn("declaredSymbols")(function* declaredSymbols(g
22703
22568
  // src/features/check-references/model/resolve-reference.ts
22704
22569
  const GITHUB = "https://api.github.com/repos/";
22705
22570
  const RAW = "application/vnd.github.raw+json";
22706
- const NOT_FOUND = 404;
22571
+ const NOT_FOUND$1 = 404;
22707
22572
  const MULTIPLE_CHOICES = 300;
22708
22573
  const SEPARATOR = "/";
22709
22574
  const LATEST = "latest";
@@ -22722,12 +22587,12 @@ const Repository = Schema.Struct({
22722
22587
  default_branch: Schema.String
22723
22588
  });
22724
22589
  const Version = Schema.Struct({ deprecated: Schema.optional(Schema.String) });
22725
- const Packument = Schema.Struct({
22590
+ const Packument$1 = Schema.Struct({
22726
22591
  "dist-tags": Schema.Record(Schema.String, Schema.String),
22727
22592
  versions: Schema.Record(Schema.String, Version)
22728
22593
  });
22729
- const answered = (lookup, missing, next) => Effect.flatMap(sent(lookup), (response) => {
22730
- if (response.status === NOT_FOUND) return Effect.succeed(broken(missing));
22594
+ const answered$1 = (lookup, missing, next) => Effect.flatMap(sent(lookup), (response) => {
22595
+ if (response.status === NOT_FOUND$1) return Effect.succeed(broken(missing));
22731
22596
  if (response.status >= MULTIPLE_CHOICES) return Effect.succeed(unchecked(`the lookup answered HTTP ${String(response.status)}`));
22732
22597
  return next(response);
22733
22598
  });
@@ -22756,11 +22621,11 @@ const repositoryContentsOutcome = (reference, repository, token) => {
22756
22621
  const url = `${GITHUB}${reference.owner}/${reference.repo}/contents/${encodedPath(reference.path)}?ref=${encodeURIComponent(branch)}`;
22757
22622
  const missing = `${reference.path} does not exist on ${branch} of ${reference.owner}/${reference.repo}. Point at where it lives now.`;
22758
22623
  return Option.match(reference.symbol, {
22759
- onNone: () => answered(jsonLookup({
22624
+ onNone: () => answered$1(jsonLookup({
22760
22625
  url,
22761
22626
  token
22762
22627
  }), missing, () => Effect.succeed(found)),
22763
- onSome: (symbol) => answered({
22628
+ onSome: (symbol) => answered$1({
22764
22629
  url,
22765
22630
  token,
22766
22631
  accept: RAW
@@ -22774,7 +22639,7 @@ const githubOutcome = Effect.fn("githubOutcome")(function* githubOutcome(referen
22774
22639
  token
22775
22640
  });
22776
22641
  const missing = `${reference.owner}/${reference.repo} does not exist, or the token in GH_TOKEN cannot read it.`;
22777
- return yield* answered(lookup, missing, (response) => Effect.flatMap(HttpClientResponse.schemaBodyJson(Repository)(response), (repository) => repositoryContentsOutcome(reference, repository, token)));
22642
+ return yield* answered$1(lookup, missing, (response) => Effect.flatMap(HttpClientResponse.schemaBodyJson(Repository)(response), (repository) => repositoryContentsOutcome(reference, repository, token)));
22778
22643
  });
22779
22644
  const versionOf = ({ "dist-tags": tags }, requested) => Option.match(requested, {
22780
22645
  onNone: () => Option.fromNullishOr(tags[LATEST]),
@@ -22790,7 +22655,7 @@ const versionOutcome = ({ name, version }, packument) => Option.match(versionOf(
22790
22655
  })
22791
22656
  })
22792
22657
  });
22793
- const npmOutcome = (reference) => answered(abbreviatedLookup(reference.name), `${reference.name} is not published on npm.`, (response) => Effect.map(HttpClientResponse.schemaBodyJson(Packument)(response), (packument) => versionOutcome(reference, packument)));
22658
+ const npmOutcome = (reference) => answered$1(abbreviatedLookup(reference.name), `${reference.name} is not published on npm.`, (response) => Effect.map(HttpClientResponse.schemaBodyJson(Packument$1)(response), (packument) => versionOutcome(reference, packument)));
22794
22659
  /** @internal */
22795
22660
  const resolveReference = (reference) => Match.value(reference).pipe(Match.discriminatorsExhaustive("kind")({
22796
22661
  github: githubOutcome,
@@ -22800,7 +22665,7 @@ const resolveReference = (reference) => Match.value(reference).pipe(Match.discri
22800
22665
  onSuccess: (outcome) => outcome
22801
22666
  }));
22802
22667
  // src/features/check-references/model/unresolved-references.ts
22803
- const LOOKUP_CONCURRENCY = 4;
22668
+ const LOOKUP_CONCURRENCY$1 = 4;
22804
22669
  const occurrencesIn = (links) => pipe(links, Array$1.flatMap(({ path, line, destination }) => pipe(referenceOf(destination), Option.map((reference) => ({
22805
22670
  file: path,
22806
22671
  line,
@@ -22832,12 +22697,12 @@ const unresolvedReferences = Effect.fn("unresolvedReferences")(function* unresol
22832
22697
  }))));
22833
22698
  const occurrences = occurrencesIn(links);
22834
22699
  const distinct = pipe(occurrences, Array$1.dedupeWith((left, right) => describeReference(left.reference) === describeReference(right.reference)), Array$1.map(({ reference }) => reference));
22835
- const resolved = yield* Effect.forEach(distinct, (reference) => Effect.map(resolveReference(reference), (outcome) => [describeReference(reference), outcome]), { concurrency: LOOKUP_CONCURRENCY });
22700
+ const resolved = yield* Effect.forEach(distinct, (reference) => Effect.map(resolveReference(reference), (outcome) => [describeReference(reference), outcome]), { concurrency: LOOKUP_CONCURRENCY$1 });
22836
22701
  const outcomes = HashMap.fromIterable(resolved);
22837
22702
  return pipe(occurrences, Array$1.flatMap(unresolvedOf(outcomes)));
22838
22703
  });
22839
22704
  // src/app/refs-command.ts
22840
- const Row$1 = Schema.Struct({
22705
+ const Row$2 = Schema.Struct({
22841
22706
  file: Schema.String,
22842
22707
  line: Schema.Finite,
22843
22708
  reference: Schema.String,
@@ -22848,28 +22713,15 @@ const VERDICTS$1 = {
22848
22713
  broken: "is stale:",
22849
22714
  unchecked: "could not be checked:"
22850
22715
  };
22851
- const describeRow$1 = (row) => `${row.file}:${String(row.line)} ${row.reference} ${VERDICTS$1[row.outcome]} ${row.reason}`;
22716
+ const describeRow$2 = (row) => `${row.file}:${String(row.line)} ${row.reference} ${VERDICTS$1[row.outcome]} ${row.reason}`;
22852
22717
  /** @internal */
22853
22718
  const refsCommand = Command.make("refs", { json: jsonFlag }, ({ json }) => lookupReport({
22854
- row: Row$1,
22719
+ row: Row$2,
22855
22720
  rows: unresolvedReferences,
22856
- describe: describeRow$1
22721
+ describe: describeRow$2
22857
22722
  })(json)).pipe(Command.withDescription("Reports github: and npm: reference links whose target is gone"));
22858
- // src/app/unbumped-command.ts
22859
- const unbumped = Effect.fn("unbumped")(function* unbumped() {
22860
- const root = (yield* RepositoryFiles).resolve(".");
22861
- const found = yield* checkPackageVersions(root);
22862
- const problems = sortProblems(found);
22863
- yield* reportProblems(root, {
22864
- problems,
22865
- json: false
22866
- });
22867
- return yield* failWhenAny(problems.length);
22868
- });
22869
- /** @internal */
22870
- const unbumpedCommand = Command.make("unbumped", {}, unbumped).pipe(Command.withDescription("Reports a changed workspace whose version is not above the base"));
22871
22723
  // src/app/upstream-command.ts
22872
- const Row = Schema.Struct({
22724
+ const Row$1 = Schema.Struct({
22873
22725
  file: Schema.String,
22874
22726
  line: Schema.Finite,
22875
22727
  upstream: Schema.String,
@@ -22881,24 +22733,267 @@ const VERDICTS = {
22881
22733
  undecided: "has changes nobody decided on. Read them, then set reviewed, verdict and reason of the record.",
22882
22734
  unchecked: "could not be checked. Check it by hand or rerun where the lookup is reachable."
22883
22735
  };
22884
- const describeRow = (row) => `${row.file}:${String(row.line)} upstream ${row.upstream} after ${row.reviewed}: ${row.detail}. It ${VERDICTS[row.outcome]}`;
22736
+ const describeRow$1 = (row) => `${row.file}:${String(row.line)} upstream ${row.upstream} after ${row.reviewed}: ${row.detail}. It ${VERDICTS[row.outcome]}`;
22737
+ /** @internal */
22738
+ const upstreamCommand = Command.make("upstream", { json: jsonFlag }, ({ json }) => lookupReport({
22739
+ row: Row$1,
22740
+ rows: undecidedUpdates,
22741
+ describe: describeRow$1
22742
+ })(json)).pipe(Command.withDescription("Reports an upstream of a reimplementation that released since its verdict"));
22743
+ // src/app/usage-command.ts
22744
+ const METRICS_PATH = "/v1/metrics";
22745
+ const UNAUTHORIZED = 401;
22746
+ const FORBIDDEN = 403;
22747
+ const OK_FROM = 200;
22748
+ const OK_BELOW = 300;
22749
+ const SERVICE_NAME = "msch";
22750
+ const NANOS_PER_MILLI = 1000000n;
22751
+ const spoolFiles = Effect.fn("spoolFiles")(function* spoolFiles(spool) {
22752
+ const fs = yield* FileSystem.FileSystem;
22753
+ const path = yield* Path.Path;
22754
+ const names = yield* fs.readDirectory(spool).pipe(Effect.orElseSucceed(() => []));
22755
+ return pipe(names, Array$1.map((name) => path.join(spool, name)));
22756
+ });
22757
+ const removed = (files) => FileSystem.FileSystem.pipe(Effect.flatMap((fs) => Effect.forEach(files, (file) => fs.remove(file).pipe(Effect.ignore), {
22758
+ concurrency: "unbounded",
22759
+ discard: true
22760
+ })));
22761
+ const withKey = (key) => Option.match(key, {
22762
+ onNone: () => (request) => request,
22763
+ onSome: (value) => HttpClientRequest.bearerToken(Redacted.value(value))
22764
+ });
22765
+ const posted = Effect.fn("posted")(function* posted(input) {
22766
+ const client = yield* HttpClient.HttpClient;
22767
+ const request = yield* HttpClientRequest.post(`${input.endpoint}${METRICS_PATH}`).pipe(withKey(input.key), HttpClientRequest.bodyJson(input.body));
22768
+ return yield* client.execute(request);
22769
+ });
22770
+ const spooledTallies = Effect.fn("spooledTallies")(function* spooledTallies(files) {
22771
+ const fs = yield* FileSystem.FileSystem;
22772
+ const texts = yield* Effect.forEach(files, (file) => fs.readFileString(file).pipe(Effect.orElseSucceed(() => "")), { concurrency: "unbounded" });
22773
+ return mergeTallies(pipe(texts, Array$1.flatMap(talliesIn)));
22774
+ });
22775
+ const bodyOf = Effect.fn("bodyOf")(function* bodyOf(tallies) {
22776
+ const millis = yield* Clock.currentTimeMillis;
22777
+ const now = BigInt(millis) * NANOS_PER_MILLI;
22778
+ const name = yield* ownRepository().pipe(Effect.orElseSucceed(() => Option.none()));
22779
+ return usageMetricsOf({
22780
+ resource: {
22781
+ "service.name": SERVICE_NAME,
22782
+ "vcs.repository.name": Option.getOrElse(name, () => "")
22783
+ },
22784
+ startNanos: now,
22785
+ endNanos: now
22786
+ })(tallies);
22787
+ });
22788
+ const refusalHint = (apiKeyEnv) => Option.match(apiKeyEnv, {
22789
+ onNone: () => "Pass --api-key-env or let the proxy add the key.",
22790
+ onSome: (name) => `Set ${name} or let the proxy add the key.`
22791
+ });
22792
+ const isRefused = (status) => status === UNAUTHORIZED || status === FORBIDDEN;
22793
+ const answered = (target, files, status) => {
22794
+ if (status >= OK_FROM && status < OK_BELOW) return removed(files);
22795
+ if (isRefused(status)) return Console.error(`msch usage: the endpoint refused the counters (${String(status)}), so the ${CALLS_METRIC} counters of this run were dropped. ${refusalHint(target.apiKeyEnv)}`).pipe(Effect.andThen(removed(files)));
22796
+ return Console.error(`msch usage: the endpoint answered ${String(status)}, so the counters stay in the spool for the next run.`);
22797
+ };
22798
+ const sentOrKept = Effect.fn("sentOrKept")(function* sentOrKept(target, files, tallies) {
22799
+ const key = yield* Option.match(target.apiKeyEnv, {
22800
+ onNone: () => Effect.succeed(Option.none()),
22801
+ onSome: (name) => Config.option(Config.Redacted(name)).pipe(Effect.orElseSucceed(() => Option.none()))
22802
+ });
22803
+ const body = yield* bodyOf(tallies);
22804
+ const sent = yield* posted({
22805
+ endpoint: target.endpoint,
22806
+ key,
22807
+ body
22808
+ }).pipe(Effect.option);
22809
+ if (Option.isNone(sent)) return yield* Console.error("msch usage: the endpoint could not be reached, so the counters stay in the spool for the next run.");
22810
+ return yield* answered(target, files, sent.value.status);
22811
+ });
22812
+ /** @internal */
22813
+ const sendUsage = Effect.fn("sendUsage")(function* sendUsage(root, target) {
22814
+ const path = yield* Path.Path;
22815
+ const files = yield* spoolFiles(path.join(root, USAGE_SPOOL));
22816
+ const tallies = yield* spooledTallies(files);
22817
+ if (Array$1.isReadonlyArrayEmpty(tallies)) return yield* removed(files);
22818
+ return yield* sentOrKept(target, files, tallies);
22819
+ });
22820
+ const usage = Effect.fn("usage")(function* usage(target) {
22821
+ const repository = yield* RepositoryFiles;
22822
+ return yield* sendUsage(repository.resolve("."), target);
22823
+ });
22824
+ // src/app/network-commands.ts
22825
+ /** @internal */
22826
+ const NETWORK_COMMANDS = [
22827
+ callersCommand,
22828
+ refsCommand,
22829
+ upstreamCommand,
22830
+ Command.make("usage", {
22831
+ endpoint: Flag.String("endpoint").pipe(Flag.withDescription("Sends the counters to this OTLP/HTTP base URL")),
22832
+ apiKeyEnv: Flag.String("api-key-env").pipe(Flag.withDescription("Reads the bearer token from this environment variable"), Flag.optional)
22833
+ }, usage).pipe(Command.withDescription("Sends the calls that metered libraries counted during the checks, then empties the spool"))
22834
+ ];
22835
+ // src/app/publish-command.ts
22836
+ const directory = Argument.String("directory").pipe(Argument.withDescription("The workspace directory"));
22837
+ const plan = Command.make("plan", { directory }, (input) => planOf(input.directory).pipe(Effect.flatMap(writePlan))).pipe(Command.withDescription("Decides what publishing the workspace takes"));
22838
+ const npm = Command.make("npm", { directory }, (input) => publishToNpm(input.directory)).pipe(Command.withDescription("Publishes the workspace to npm"));
22839
+ const release = Command.make("release", { directory }, (input) => publishRelease(input.directory)).pipe(Command.withDescription("Publishes the workspace as a GitHub Release"));
22840
+ const compat = Command.make("compat", { directory }, (input) => checkCompat(input.directory)).pipe(Command.withDescription("Checks the packed workspace against what it says it supports"));
22841
+ const consumers = Command.make("consumers", { directory }, (input) => checkConsumers([input.directory])).pipe(Command.withDescription("Checks the repositories that use the workspace against its build"));
22842
+ const compatPlan = Command.make("compat-plan", {}, () => writeCompatPlan()).pipe(Command.withDescription("Lists the workspaces whose compatibility is checked"));
22843
+ const compatChanged = Command.make("compat-changed", { directories: Argument.String("directory").pipe(Argument.withDescription("The workspace directories that changed"), Argument.variadic()) }, (input) => checkChangedCompat(input.directories)).pipe(Command.withDescription("Checks the compatibility of the workspaces that changed"));
22844
+ const dispatch = Command.make("dispatch", { ref: Argument.String("ref").pipe(Argument.withDescription("The ref to publish from")) }, (input) => dispatchPending(input.ref)).pipe(Command.withDescription("Starts the publish workflow for every version that is not out yet"));
22845
+ /** @internal */
22846
+ const publishCommand = Command.make("publish").pipe(Command.withDescription("Plans and publishes a workspace to npm and GitHub Releases"), Command.withSubcommands([
22847
+ plan,
22848
+ npm,
22849
+ release,
22850
+ compat,
22851
+ consumers,
22852
+ compatPlan,
22853
+ compatChanged,
22854
+ dispatch
22855
+ ]));
22856
+ // src/features/check-published-versions/model/overdue.ts
22857
+ const PUBLISH_WINDOW_MS = 72e5;
22858
+ const versionAt = (root, tip, { file }) => RepositoryFiles.pipe(Effect.flatMap((files) => files.readAtRevision(root, tip, file)), Effect.map((before) => pipe(before, Option.flatMap(decodePackageJson), Option.flatMap(({ version }) => Option.fromUndefinedOr(version)))));
22859
+ const publishWindowPassed = (root, { file }) => Effect.gen(function* passed() {
22860
+ const committed = yield* (yield* RepositoryFiles).committedAt(root, file);
22861
+ const now = yield* Clock.currentTimeMillis;
22862
+ return Option.exists(committed, (at) => now - at >= PUBLISH_WINDOW_MS);
22863
+ });
22864
+ /** @internal */
22865
+ const overdue = ({ root, tip, sibling }) => Option.match(sibling, {
22866
+ onNone: () => Effect.succeed(true),
22867
+ onSome: (found) => Effect.gen(function* overdueSibling() {
22868
+ const before = yield* versionAt(root, tip, found);
22869
+ if (!Option.contains(before, found.version)) return false;
22870
+ return yield* publishWindowPassed(root, found);
22871
+ })
22872
+ });
22873
+ // src/features/check-published-versions/model/published-dependencies.ts
22874
+ const WORKSPACE_PROTOCOL = "workspace:";
22875
+ const CATALOG_PROTOCOL = "catalog:";
22876
+ const UNVERSIONED = "0.0.0";
22877
+ const FIRST_LINE = 1;
22878
+ const READ_CONCURRENCY = 16;
22879
+ const LOOKUP_CONCURRENCY = 4;
22880
+ const SECTIONS = ["dependencies", "optionalDependencies"];
22881
+ const Packument = Schema.Struct({ versions: Schema.Record(Schema.String, Schema.Unknown) });
22882
+ const packageAt = (file, text) => pipe(decodePackageJson(text), Option.filter((manifest) => manifest.private !== true), Option.flatMap((manifest) => Option.all({
22883
+ name: Option.fromUndefinedOr(manifest.name),
22884
+ version: Option.fromUndefinedOr(manifest.version)
22885
+ }).pipe(Option.filter(({ version }) => version !== UNVERSIONED), Option.map(({ name, version }) => ({
22886
+ file,
22887
+ name,
22888
+ version,
22889
+ text,
22890
+ specified: pipe(SECTIONS, Array$1.flatMap((section) => specifiedIn(manifest[section])))
22891
+ })))));
22892
+ const OK = 200;
22893
+ const NOT_FOUND = 404;
22894
+ const versionsIn = (response) => {
22895
+ if (response.status === OK) return HttpClientResponse.schemaBodyJson(Packument)(response).pipe(Effect.map(({ versions }) => Option.some(Record.keys(versions))));
22896
+ if (response.status === NOT_FOUND) return Effect.succeedSome([]);
22897
+ return Effect.succeedNone;
22898
+ };
22899
+ const publishedVersions = (name) => abbreviatedPackument(name).pipe(Effect.flatMap(versionsIn), Effect.orElseSucceed(() => Option.none()));
22900
+ const catalogRanges = (settings) => pipe(settings, Option.map((found) => [...pipe(specifiedIn(found["catalog"]), Array$1.map(({ name, specifier }) => [name, specifier])), ...pipe(namedCatalogsOf(found), Array$1.flatMap(([, held]) => specifiedIn(held)), Array$1.map(({ name, specifier }) => [name, specifier]))]), Option.getOrElse(() => []), HashMap.fromIterable);
22901
+ const lineOf = (text, dependency) => pipe(String$1.split(text, "\n"), Array$1.findFirstIndex((line) => String$1.includes(`"${dependency}"`)(line)), Option.match({
22902
+ onNone: () => FIRST_LINE,
22903
+ onSome: (index) => index + FIRST_LINE
22904
+ }));
22905
+ const rangeOf = (catalog, { name, specifier }) => {
22906
+ if (String$1.startsWith(CATALOG_PROTOCOL)(specifier)) return HashMap.get(catalog, name);
22907
+ return Option.some(specifier);
22908
+ };
22909
+ const siblingWanted = (siblings, owner) => ({ name }) => pipe(HashMap.get(siblings, name), Option.map((sibling) => ({
22910
+ owner,
22911
+ name,
22912
+ range: sibling.version,
22913
+ sibling: Option.some(sibling)
22914
+ })), Option.toArray);
22915
+ const registryWanted = ({ siblings, catalog, routes }, owner) => (specified) => pipe(Option.liftPredicate(specified, ({ name }) => isOwnPackage(routes)(name)), Option.flatMap((own) => rangeOf(catalog, own)), Option.map((range) => ({
22916
+ owner,
22917
+ name: specified.name,
22918
+ range,
22919
+ sibling: pipe(HashMap.get(siblings, specified.name), Option.filter(({ version }) => semver.satisfies(version, range)))
22920
+ })), Option.toArray);
22921
+ const wantedBy = (sources) => (owner) => pipe(owner.specified, Array$1.flatMap((specified) => {
22922
+ if (String$1.startsWith(WORKSPACE_PROTOCOL)(specified.specifier)) return siblingWanted(sources.siblings, owner)(specified);
22923
+ return registryWanted(sources, owner)(specified);
22924
+ }));
22925
+ const lookupsOf = (wanted) => pipe(wanted, Array$1.map(({ name }) => name), Array$1.dedupe, (names) => Effect.forEach(names, (name) => Effect.map(publishedVersions(name), (found) => [name, found]), { concurrency: LOOKUP_CONCURRENCY }), Effect.map(HashMap.fromIterable));
22926
+ const reasonOf = (sibling) => Option.match(sibling, {
22927
+ onNone: () => "is not on npm. Publish it first, or lower the range to a version that is.",
22928
+ onSome: ({ file }) => `is still not on npm two hours after ${file} reached main. Read the failed publish run for it.`
22929
+ });
22930
+ const missingIn = (known) => ({ owner, name, range, sibling }) => pipe(HashMap.get(known, name), Option.flatten, Option.filter((published) => semver.maxSatisfying([...published], range) === null), Option.map(() => ({
22931
+ file: owner.file,
22932
+ line: lineOf(owner.text, name),
22933
+ dependency: `${name}@${range}`,
22934
+ reason: reasonOf(sibling)
22935
+ })), Option.toArray);
22936
+ const wantedIn = Effect.fn("wantedIn")(function* wantedIn(root) {
22937
+ const manifests = yield* manifestTexts(root);
22938
+ const packages = pipe(manifests, Array$1.flatMap(({ file, text }) => Option.toArray(packageAt(file, text))));
22939
+ const siblings = HashMap.fromIterable(pipe(packages, Array$1.map((found) => [found.name, found])));
22940
+ const settings = yield* workspaceManifest(root);
22941
+ const catalog = catalogRanges(pipe(settings, Option.map(fieldsOf)));
22942
+ const routes = yield* packageRoutes(root);
22943
+ return pipe(packages, Array$1.flatMap(wantedBy({
22944
+ siblings,
22945
+ catalog,
22946
+ routes
22947
+ })));
22948
+ });
22949
+ /** @internal */
22950
+ const missingVersions = Effect.fn("missingVersions")(function* missingVersions(root) {
22951
+ const tip = yield* baseName;
22952
+ const wanted = yield* wantedIn(root);
22953
+ const due = yield* Effect.filter(wanted, ({ sibling }) => overdue({
22954
+ root,
22955
+ tip,
22956
+ sibling
22957
+ }), { concurrency: READ_CONCURRENCY });
22958
+ const known = yield* lookupsOf(due);
22959
+ return pipe(due, Array$1.flatMap(missingIn(known)));
22960
+ });
22961
+ // src/app/published-command.ts
22962
+ const Row = Schema.Struct({
22963
+ file: Schema.String,
22964
+ line: Schema.Finite,
22965
+ dependency: Schema.String,
22966
+ reason: Schema.String
22967
+ });
22968
+ const describeRow = (row) => `${row.file}:${String(row.line)} ${row.dependency} ${row.reason}`;
22969
+ /** @internal */
22970
+ const publishedCommand = Command.make("published", { json: jsonFlag }, ({ json }) => lookupReport({
22971
+ row: Row,
22972
+ rows: missingVersions,
22973
+ describe: describeRow
22974
+ })(json)).pipe(Command.withDescription("Reports a dependency range that no version on npm satisfies"));
22975
+ // src/app/unbumped-command.ts
22976
+ const unbumped = Effect.fn("unbumped")(function* unbumped() {
22977
+ const root = (yield* RepositoryFiles).resolve(".");
22978
+ const found = yield* checkPackageVersions(root);
22979
+ const problems = sortProblems(found);
22980
+ yield* reportProblems(root, {
22981
+ problems,
22982
+ json: false
22983
+ });
22984
+ return yield* failWhenAny(problems.length);
22985
+ });
22885
22986
  // src/app/subcommands.ts
22886
22987
  /** @internal */
22887
22988
  const SUBCOMMANDS = [
22888
22989
  agentsCommand,
22889
- callersCommand,
22890
22990
  changedCommand,
22891
22991
  exitsCommand,
22892
22992
  judgeCommand,
22893
22993
  publishCommand,
22894
22994
  publishedCommand,
22895
- refsCommand,
22896
- unbumpedCommand,
22897
- Command.make("upstream", { json: jsonFlag }, ({ json }) => lookupReport({
22898
- row: Row,
22899
- rows: undecidedUpdates,
22900
- describe: describeRow
22901
- })(json)).pipe(Command.withDescription("Reports an upstream of a reimplementation that released since its verdict"))
22995
+ Command.make("unbumped", {}, unbumped).pipe(Command.withDescription("Reports a changed workspace whose version is not above the base")),
22996
+ ...NETWORK_COMMANDS
22902
22997
  ];
22903
22998
  // src/app/cli.ts
22904
22999
  const NO_PROBLEMS = 0;