@milkenjoyer/toolchain 0.14.1 → 0.16.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.
Files changed (53) hide show
  1. package/README.md +17 -17
  2. package/STARTS.md +11 -0
  3. package/dist/effect-plugin-BsrW5_nI.mjs +79 -0
  4. package/dist/effect-plugin.d.mts +2 -3966
  5. package/dist/effect-plugin.mjs +1 -1
  6. package/dist/fmt-BaECz64m.mjs +8 -0
  7. package/dist/fmt.mjs +1 -8
  8. package/dist/formal.mjs +1 -1
  9. package/dist/guard-Doqk4Fju.mjs +143 -0
  10. package/dist/guard.mjs +1 -96
  11. package/dist/{lint-IhmtnBbx.mjs → lint-CfztB4u8.mjs} +1 -1
  12. package/dist/lint.mjs +1 -1
  13. package/dist/standard.mjs +557 -4
  14. package/dist/starts.d.mts +100 -0
  15. package/dist/starts.mjs +385 -0
  16. package/package.json +11 -9
  17. package/src/arithmetic.ts +60 -0
  18. package/src/compatible.ts +512 -0
  19. package/src/conformance.ts +56 -0
  20. package/src/effect-plugin.ts +24 -0
  21. package/src/effect-tsgo.ts +44 -0
  22. package/src/exceptions.ts +17 -0
  23. package/src/fmt.ts +13 -0
  24. package/src/foldkit-plugin.ts +51 -0
  25. package/src/guard.ts +307 -0
  26. package/src/hooks.ts +205 -0
  27. package/src/index.ts +1 -0
  28. package/src/knip.ts +25 -0
  29. package/src/lint.ts +170 -0
  30. package/src/plugin.ts +21 -0
  31. package/src/rules/no-comments.ts +36 -0
  32. package/src/rules/no-process-env.ts +68 -0
  33. package/src/rules/prefer-accessible-scene-locators.ts +227 -0
  34. package/src/rules/require-command-answer-names.ts +144 -0
  35. package/src/rules/require-past-tense-messages.ts +201 -0
  36. package/src/rules/use-temp-file-scoped.ts +132 -0
  37. package/src/rules.ts +121 -0
  38. package/src/shared/foldkit-api.ts +51 -0
  39. package/src/shared/member-path.ts +106 -0
  40. package/src/shared/syntax.ts +47 -0
  41. package/src/standard/alchemy.ts +70 -0
  42. package/src/standard/checks.ts +10 -1
  43. package/src/standard/config.ts +84 -0
  44. package/src/standard/domain-rules.ts +204 -0
  45. package/src/standard/domain.ts +296 -0
  46. package/src/standard/infra.ts +486 -0
  47. package/src/starts/boat.ts +140 -0
  48. package/src/starts/budget.ts +151 -0
  49. package/src/starts/policy.ts +171 -0
  50. package/src/starts.ts +84 -0
  51. package/src/versions.ts +221 -0
  52. package/dist/effect-plugin-BXUx9PPu.mjs +0 -3561
  53. package/dist/manifest-xQwgnYI1.mjs +0 -53
package/dist/standard.mjs CHANGED
@@ -1,8 +1,13 @@
1
1
  #!/usr/bin/env bun
2
+ import { a as ruleFindings, c as exactFindings, l as manifestRanges, s as PLAIN } from "./guard-Doqk4Fju.mjs";
3
+ import { t as fmt } from "./fmt-BaECz64m.mjs";
2
4
  import { n as criticalFindings, t as decode } from "./specs-file-NsQF4V7X.mjs";
3
- import { n as exactFindings, r as manifestRanges, t as PLAIN } from "./manifest-xQwgnYI1.mjs";
5
+ import * as Arr from "effect/Array";
6
+ import * as Option from "effect/Option";
7
+ import * as R from "effect/Record";
4
8
  import * as Schema from "effect/Schema";
5
9
  import * as Effect from "effect/Effect";
10
+ import { posix } from "node:path";
6
11
  import { NodeServices } from "@effect/platform-node";
7
12
  import * as Cause from "effect/Cause";
8
13
  import * as Console from "effect/Console";
@@ -12,6 +17,8 @@ import * as Stream from "effect/Stream";
12
17
  import { FileSystem } from "effect/FileSystem";
13
18
  import { fileURLToPath } from "node:url";
14
19
  import { Path } from "effect/Path";
20
+ import { isDeepStrictEqual } from "node:util";
21
+ import { Visitor, parseSync } from "oxc-parser";
15
22
  // src/standard/plugin-skills.ts
16
23
  const pluginSkills = {
17
24
  "agent-kit": [
@@ -159,7 +166,82 @@ const skillNames = (repo) => Effect.succeed(repo.tracked.flatMap((file) => {
159
166
  message: `shares its name with ${plugin}:${name}`
160
167
  }] : []);
161
168
  }));
169
+ // src/standard/alchemy.ts
170
+ const resolve = (name, written, groups) => {
171
+ if (!written.startsWith("catalog:")) return written;
172
+ const catalog = written.slice(8);
173
+ return (catalog === "" ? groups.get("workspaces.catalog")?.[name] ?? groups.get("catalog")?.[name] : groups.get(`workspaces.catalogs.${catalog}`)?.[name] ?? groups.get(`catalogs.${catalog}`)?.[name]) ?? written;
174
+ };
175
+ const alchemyPins = (repo) => Effect.gen(function* () {
176
+ const root = yield* read(repo, "package.json", manifestRanges);
177
+ if (!root.ok) return root.findings;
178
+ const groups = new Map(root.value);
179
+ const entries = [];
180
+ const findings = [];
181
+ for (const file of repo.tracked.filter((name) => /(?:^|\/)package\.json$/u.test(name)).toSorted()) {
182
+ const input = file === "package.json" ? root : yield* read(repo, file, manifestRanges);
183
+ if (!input.ok) {
184
+ findings.push(...input.findings);
185
+ continue;
186
+ }
187
+ for (const [field, ranges] of input.value) for (const [name, written] of Object.entries(ranges).toSorted(([a], [b]) => a.localeCompare(b))) if (name === "alchemy" || name.startsWith("@alchemy.run/")) entries.push({
188
+ file,
189
+ field,
190
+ name,
191
+ version: resolve(name, written, groups)
192
+ });
193
+ }
194
+ const expected = entries.find((entry) => entry.name === "alchemy")?.version ?? entries[0]?.version;
195
+ for (const entry of entries) if (!PLAIN.test(entry.version) || entry.version !== expected) findings.push({
196
+ file: entry.file,
197
+ message: `${entry.field} ${entry.name}: ${entry.version} must match the exact Alchemy version ${expected}`
198
+ });
199
+ return findings;
200
+ });
162
201
  // src/standard/config.ts
202
+ const ConfigValue = Schema.declare((value) => typeof value === "object" && value !== null);
203
+ const ConfigFactory = Schema.declare((value) => typeof value === "function");
204
+ const parseConfig = Schema.decodeUnknownSync(ConfigValue);
205
+ const parseModule$1 = Schema.decodeUnknownSync(Schema.Struct({ default: Schema.Unknown }));
206
+ const lintConfig = (repo) => Effect.gen(function* () {
207
+ const path = yield* Path;
208
+ const configs = repo.tracked.filter((file) => /^vite\.config\.(?:ts|mts|js|mjs)$/u.test(file));
209
+ const findings = [];
210
+ for (const file of configs) {
211
+ const input = yield* read(repo, file, (text) => text);
212
+ if (!input.ok) {
213
+ findings.push(...input.findings);
214
+ continue;
215
+ }
216
+ const loaded = yield* Effect.tryPromise({
217
+ try: async () => {
218
+ const imported = await import(path.join(repo.root, file));
219
+ const exported = await parseModule$1(imported).default;
220
+ const config = parseConfig(Schema.is(ConfigFactory)(exported) ? await exported({
221
+ command: "build",
222
+ mode: "production"
223
+ }) : exported);
224
+ const messages = config.lint === void 0 ? ["configure lint with the shared lint() preset"] : [...ruleFindings(config.lint)];
225
+ const expected = fmt();
226
+ const actual = config.fmt;
227
+ const keys = /* @__PURE__ */ new Set([...Object.keys(expected), ...Object.keys(actual ?? {})]);
228
+ keys.delete("ignorePatterns");
229
+ for (const key of keys) if (!isDeepStrictEqual(Reflect.get(expected, key), actual === void 0 ? void 0 : Reflect.get(actual, key))) messages.push(`set fmt.${key} to the shared fmt() value`);
230
+ if (!(expected.ignorePatterns ?? []).every((pattern) => actual?.ignorePatterns?.includes(pattern) === true)) messages.push("include every shared fmt() ignore pattern");
231
+ return messages;
232
+ },
233
+ catch: (error) => `cannot import config: ${String(error instanceof Error ? error.message : error).split("\n")[0]}`
234
+ }).pipe(Effect.match({
235
+ onFailure: (message) => [message],
236
+ onSuccess: (messages) => messages
237
+ }));
238
+ findings.push(...loaded.map((message) => ({
239
+ file,
240
+ message
241
+ })));
242
+ }
243
+ return findings;
244
+ });
163
245
  const lintFmt = (repo) => Effect.gen(function* () {
164
246
  const path = yield* Path;
165
247
  const roots = repo.tracked.filter((file) => /^vite\.config\.(?:ts|mts|js|mjs)$/u.test(file));
@@ -246,6 +328,257 @@ const tsconfig = (repo) => Effect.gen(function* () {
246
328
  });
247
329
  return findings;
248
330
  });
331
+ // src/standard/domain.ts
332
+ const BLOCK_KINDS = /* @__PURE__ */ new Map([
333
+ ["Aggregate", ["aggregate"]],
334
+ ["Command", ["command"]],
335
+ ["Event", [
336
+ "event",
337
+ "command",
338
+ "view",
339
+ "stream"
340
+ ]],
341
+ ["Rejection", ["rejection", "command"]],
342
+ ["View", ["view"]],
343
+ ["Policy", ["policy"]],
344
+ ["Saga", ["saga"]],
345
+ ["Projection", ["projection"]],
346
+ ["Stream", ["stream"]],
347
+ ["ExternalSystem", ["external"]],
348
+ ["Api", ["api"]],
349
+ ["Model", ["model"]],
350
+ ["RequestContext", ["context"]]
351
+ ]);
352
+ const DOMAIN = "@alchemy.run/domain";
353
+ const TEST_FILE = /(?:^|\/)tests?\/|\.(?:test|proof)\.ts$/u;
354
+ const isRelative = (specifier) => specifier.startsWith("./") || specifier.startsWith("../");
355
+ const within = (directory, file) => directory === "." ? file !== ".." && !file.startsWith("../") && !posix.isAbsolute(file) : file.startsWith(`${directory}/`);
356
+ const targetFile = (file, from, paths) => {
357
+ const target = posix.join(posix.dirname(file), from);
358
+ return [
359
+ target,
360
+ target.replace(/\.js$/u, ".ts"),
361
+ `${target}.ts`,
362
+ `${target}/index.ts`
363
+ ].find((candidate) => paths.includes(candidate)) ?? target;
364
+ };
365
+ const parseModule = (file, source, paths = []) => {
366
+ const result = parseSync(file, source);
367
+ const roots = /* @__PURE__ */ new Set();
368
+ const modules = /* @__PURE__ */ new Map();
369
+ const constructors = /* @__PURE__ */ new Map();
370
+ const relatives = /* @__PURE__ */ new Map();
371
+ const relativeModules = /* @__PURE__ */ new Map();
372
+ for (const statement of result.program.body) {
373
+ if (statement.type !== "ImportDeclaration") continue;
374
+ if (statement.importKind === "type") continue;
375
+ const from = statement.source.value;
376
+ const subpath = from.startsWith(`${DOMAIN}/`) ? from.slice(20) : void 0;
377
+ const kind = subpath !== void 0 && BLOCK_KINDS.has(subpath) ? subpath : void 0;
378
+ const target = isRelative(from) ? targetFile(file, from, paths) : void 0;
379
+ for (const specifier of statement.specifiers) {
380
+ const local = specifier.local.name;
381
+ if (specifier.type === "ImportNamespaceSpecifier") {
382
+ if (from === DOMAIN) roots.add(local);
383
+ else if (kind !== void 0) modules.set(local, kind);
384
+ else if (target !== void 0) relativeModules.set(local, target);
385
+ } else if (specifier.type === "ImportDefaultSpecifier") {
386
+ if (target !== void 0) relatives.set(local, { file: target });
387
+ } else {
388
+ if (specifier.importKind === "type") continue;
389
+ const imported = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
390
+ if (from === DOMAIN && BLOCK_KINDS.has(imported)) constructors.set(local, imported);
391
+ else if (kind !== void 0 && imported === "make") constructors.set(local, kind);
392
+ else if (target !== void 0) relatives.set(local, { file: target });
393
+ }
394
+ }
395
+ }
396
+ const imports = [
397
+ ...result.module.staticImports.map((entry) => entry.moduleRequest.value),
398
+ ...result.module.staticExports.flatMap((entry) => entry.entries.flatMap((binding) => binding.moduleRequest === null ? [] : [binding.moduleRequest.value])),
399
+ ...result.module.dynamicImports.map(({ moduleRequest }) => source.slice(moduleRequest.start, moduleRequest.end).replaceAll(/^["'`]|["'`]$/gu, ""))
400
+ ];
401
+ const blockOf = (callee) => {
402
+ if (callee.type === "Identifier") return constructors.get(callee.name);
403
+ if (callee.type !== "MemberExpression" || callee.computed || callee.object.type !== "Identifier" || callee.property.type !== "Identifier") return void 0;
404
+ const { name } = callee.property;
405
+ return roots.has(callee.object.name) && BLOCK_KINDS.has(name) ? name : name === "make" ? modules.get(callee.object.name) : void 0;
406
+ };
407
+ const reference = (entry) => {
408
+ if (entry.type === "Identifier") return [relatives.get(entry.name) ?? { file }];
409
+ if (entry.type !== "MemberExpression" || entry.computed || entry.object.type !== "Identifier" || entry.property.type !== "Identifier") return [];
410
+ const target = relativeModules.get(entry.object.name);
411
+ return target === void 0 ? [] : [{ file: target }];
412
+ };
413
+ const option = (options, key) => {
414
+ const property = options.properties.find((property) => property.type === "Property" && !property.computed && (property.key.type === "Identifier" ? property.key.name : property.key.type === "Literal" ? property.key.value : void 0) === key);
415
+ return property?.type === "Property" ? property.value : void 0;
416
+ };
417
+ const declared = (options, key) => {
418
+ const value = option(options, key);
419
+ return value?.type === "ArrayExpression" ? value.elements.flatMap((entry) => entry === null || entry.type === "SpreadElement" ? [] : reference(entry)) : [];
420
+ };
421
+ const blocks = [];
422
+ const commands = [];
423
+ const recorders = [];
424
+ const aggregateIds = [];
425
+ const throws = [];
426
+ new Visitor({
427
+ CallExpression(node) {
428
+ const block = blockOf(node.callee);
429
+ const [, options] = node.arguments;
430
+ if (block !== void 0) {
431
+ blocks.push(block);
432
+ if (block === "Aggregate") {
433
+ const id = options?.type === "ObjectExpression" ? option(options, "id") : void 0;
434
+ aggregateIds.push(id === void 0 ? void 0 : reference(id)[0]);
435
+ }
436
+ if (options?.type === "ObjectExpression") {
437
+ if (block === "Command" || block === "View" || block === "Stream") recorders.push([...declared(options, block === "Stream" ? "entries" : "events")]);
438
+ if (block === "Command") commands.push({ rejects: declared(options, "rejects") });
439
+ }
440
+ }
441
+ },
442
+ ThrowStatement(node) {
443
+ throws.push(source.slice(0, node.start).split("\n").length);
444
+ }
445
+ }).visit(result.program);
446
+ return {
447
+ blocks: blocks.toSorted(),
448
+ imports,
449
+ commands,
450
+ recorders,
451
+ aggregateIds,
452
+ throws
453
+ };
454
+ };
455
+ const sourceFiles = (paths, parsed) => {
456
+ const manifests = new Set(paths.filter((file) => posix.basename(file) === "package.json").map((file) => posix.dirname(file)));
457
+ const files = paths.flatMap((file) => {
458
+ const module = parsed.get(file);
459
+ if (module === void 0) return [];
460
+ let root = posix.dirname(file);
461
+ while (root !== "." && !manifests.has(root)) root = posix.dirname(root);
462
+ return manifests.has(root) ? [{
463
+ root,
464
+ file,
465
+ source: file.endsWith(".ts") && !TEST_FILE.test(root === "." ? file : file.slice(root.length + 1)),
466
+ parsed: module
467
+ }] : [];
468
+ });
469
+ const roots = new Set(files.filter((entry) => entry.source && entry.parsed.blocks.length > 0).map((entry) => entry.root));
470
+ return files.filter((entry) => roots.has(entry.root));
471
+ };
472
+ const cache = /* @__PURE__ */ new WeakMap();
473
+ const domain = Effect.fn("standard.domain")(function* (repo) {
474
+ const cached = cache.get(repo);
475
+ if (cached !== void 0) return cached;
476
+ const parsed = /* @__PURE__ */ new Map();
477
+ const findings = [];
478
+ for (const file of repo.tracked.filter((name) => /\.[cm]?[jt]sx?$/u.test(name))) {
479
+ const input = yield* read(repo, file, (text) => parseModule(file, text, repo.tracked));
480
+ if (input.ok) parsed.set(file, input.value);
481
+ else findings.push(...input.findings);
482
+ }
483
+ const files = sourceFiles(repo.tracked, parsed);
484
+ const value = {
485
+ files,
486
+ findings: findings.filter((finding) => files.some((entry) => within(entry.root, finding.file)))
487
+ };
488
+ cache.set(repo, value);
489
+ return value;
490
+ });
491
+ // src/standard/domain-rules.ts
492
+ const KINDS = [
493
+ ...new Set([...BLOCK_KINDS.values()].flat()),
494
+ "middleware",
495
+ "id"
496
+ ];
497
+ const KIND_FILE = new RegExp(`^[A-Z][A-Za-z0-9]*\\.(?<kind>${KINDS.join("|")})\\.ts$`, "u");
498
+ const SUFFIXED = /^[^.]+\..+\.ts$/u;
499
+ const ALLOWED_IMPORT = /^(?:@alchemy\.run\/domain|effect)(?:\/|$)/u;
500
+ const DomainImports = Schema.fromJsonString(Schema.Struct({ standard: Schema.optionalKey(Schema.Struct({ domainImports: Schema.optionalKey(Schema.Array(Schema.String)) })) }));
501
+ const parseDomainImports = Schema.decodeSync(DomainImports);
502
+ const add = (index, key, file) => index.set(key, [...index.get(key) ?? [], file]);
503
+ const packageName$1 = (specifier) => specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
504
+ const layoutFindings = (files, paths) => {
505
+ const sources = files.filter((entry) => entry.source);
506
+ const parsed = new Map(sources.map(({ file, parsed: module }) => [file, module]));
507
+ const importers = /* @__PURE__ */ new Map();
508
+ const recorders = /* @__PURE__ */ new Map();
509
+ const rejecters = /* @__PURE__ */ new Map();
510
+ const findings = [];
511
+ for (const { root, file, parsed: module } of sources) {
512
+ for (const specifier of module.imports) {
513
+ if (!isRelative(specifier)) continue;
514
+ const target = targetFile(file, specifier, paths);
515
+ if (within(root, target)) add(importers, target, file);
516
+ }
517
+ for (const events of module.recorders) for (const target of new Set(events.map((entry) => entry.file))) add(recorders, target, file);
518
+ for (const { rejects } of module.commands) for (const target of new Set(rejects.map((entry) => entry.file))) add(rejecters, target, file);
519
+ }
520
+ for (const { file, parsed: module } of sources) {
521
+ const name = posix.basename(file);
522
+ const { kind } = KIND_FILE.exec(name)?.groups ?? {};
523
+ const { blocks } = module;
524
+ if (kind === void 0) {
525
+ if (SUFFIXED.test(name) || blocks.length > 0) findings.push({
526
+ file,
527
+ message: "a Domain kind file is named <Noun>.<kind>.ts in PascalCase"
528
+ });
529
+ continue;
530
+ }
531
+ const misplaced = [...new Set(blocks.filter((block) => !(BLOCK_KINDS.get(block) ?? []).includes(kind)))];
532
+ if (misplaced.length > 0) findings.push({
533
+ file,
534
+ message: `a .${kind}.ts file does not hold ${misplaced.map((block) => `Domain.${block}`).join(", ")}`
535
+ });
536
+ const [primary, ...extra] = blocks.filter((block) => BLOCK_KINDS.get(block)?.[0] === kind);
537
+ if (primary !== void 0 && extra.length > 0) findings.push({
538
+ file,
539
+ message: `a .${kind}.ts file holds one Domain.${primary}, not ${extra.length + 1}`
540
+ });
541
+ const recordedBy = recorders.get(file) ?? [];
542
+ if (kind === "event" && recordedBy.length < 2) findings.push({
543
+ file,
544
+ message: `a standalone event is recorded by ${recordedBy.length} block(s); it lives in the file of the block that records it, unless more than one block records it`
545
+ });
546
+ const [returnedBy, ...others] = rejecters.get(file) ?? [];
547
+ if (kind === "rejection" && returnedBy !== void 0 && others.length === 0 && (importers.get(file) ?? []).every((user) => (parsed.get(user)?.blocks ?? []).some((block) => block === "Command" || block === "Aggregate"))) findings.push({
548
+ file,
549
+ message: `a standalone rejection is returned only by ${returnedBy}; it lives in that command's file`
550
+ });
551
+ if (kind === "aggregate" && module.aggregateIds.some((id) => id === void 0 || id.file === file || !id.file.endsWith(".id.ts") || !paths.includes(id.file))) findings.push({
552
+ file,
553
+ message: "declare the aggregate's id in an .id.ts file and import it"
554
+ });
555
+ }
556
+ return findings;
557
+ };
558
+ const importFindings = (files, paths, allowed = []) => files.filter((entry) => entry.source).flatMap(({ root, file, parsed }) => parsed.imports.flatMap((specifier) => {
559
+ const target = isRelative(specifier) ? targetFile(file, specifier, paths) : void 0;
560
+ return target !== void 0 && within(root, target) && !paths.some((path) => path.endsWith("/package.json") && posix.dirname(path) !== root && within(root, path) && within(posix.dirname(path), target)) || target === void 0 && (ALLOWED_IMPORT.test(specifier) || allowed.includes(packageName$1(specifier))) ? [] : [{
561
+ file,
562
+ message: `imports ${specifier}; a domain package imports only @alchemy.run/domain, effect and its own files${allowed.length > 0 ? ", plus configured domainImports" : ""}`
563
+ }];
564
+ }));
565
+ const domainLayout = (repo) => Effect.gen(function* () {
566
+ const model = yield* domain(repo);
567
+ return [...model.findings, ...layoutFindings(model.files, repo.tracked)];
568
+ });
569
+ const domainImports = (repo) => Effect.gen(function* () {
570
+ const model = yield* domain(repo);
571
+ if (model.files.length === 0) return [];
572
+ const input = yield* read(repo, "package.json", parseDomainImports);
573
+ if (!input.ok) return input.findings;
574
+ return importFindings(model.files, repo.tracked, input.value.standard?.domainImports ?? []);
575
+ });
576
+ const domainNoThrow = (repo) => Effect.gen(function* () {
577
+ return (yield* domain(repo)).files.filter((entry) => entry.source).flatMap(({ file, parsed }) => parsed.throws.map((line) => ({
578
+ file,
579
+ message: `line ${line}: return a Domain.Rejection or fail with a Schema.TaggedError instead of throwing`
580
+ })));
581
+ });
249
582
  // src/standard/formal.ts
250
583
  const specs = (repo) => Effect.gen(function* () {
251
584
  if (!repo.tracked.includes("specs.json")) return [{
@@ -271,7 +604,7 @@ const Gates = {
271
604
  if: Schema.optionalKey(Schema.Unknown),
272
605
  "continue-on-error": Schema.optionalKey(Schema.Unknown)
273
606
  };
274
- const Workflow = Schema.Struct({ jobs: Schema.Record(Schema.String, Schema.Struct({
607
+ const Workflow$1 = Schema.Struct({ jobs: Schema.Record(Schema.String, Schema.Struct({
275
608
  ...Gates,
276
609
  steps: Schema.optionalKey(Schema.Array(Schema.Struct({
277
610
  ...Gates,
@@ -286,13 +619,227 @@ const readyFormal = (repo) => Effect.gen(function* () {
286
619
  file: ".github/workflows/ready.yml",
287
620
  message: "track a ready workflow running vp exec formal"
288
621
  }];
289
- const input = yield* read(repo, file, (text) => Schema.decodeUnknownSync(Workflow)(Bun.YAML.parse(text)));
622
+ const input = yield* read(repo, file, (text) => Schema.decodeUnknownSync(Workflow$1)(Bun.YAML.parse(text)));
290
623
  if (!input.ok) return input.findings;
291
624
  return Object.values(input.value.jobs).some((job) => enforced(job) && (job.steps ?? []).some((step) => enforced(step) && (step.run ?? "").split("\n").some((line) => line.trim() === "vp exec formal"))) ? [] : [{
292
625
  file,
293
626
  message: "add a step with a vp exec formal line that no if: false or continue-on-error skips or ignores"
294
627
  }];
295
628
  });
629
+ // src/standard/infra.ts
630
+ const COMMAND_WORD = /^[a-z][\w-]*$/u;
631
+ const commandPath = (words) => Arr.takeWhile(words, (word) => Option.isSome(word) && COMMAND_WORD.test(word.value)).flatMap(Option.toArray);
632
+ const CF_READ_VERB = /^(?:get|list|query|search)$/u;
633
+ const CF_WRITE_VERB = /^(?:ack|add|apply|bind|cancel|create|delete|deploy|disable|edit|enable|import|peek|publish|pull|purge|push|put|remove|rename|reset|retry|rm|rollback|rotate|send|set|start|stop|unbind|update|upload|write)$/u;
634
+ const cfReads = (words) => {
635
+ const path = commandPath(words);
636
+ return words.some((word, index) => Option.contains(word, "--dry-run") && !Option.contains(words[index + 1] ?? Option.none(), "=") && !Option.contains(words[index + 1] ?? Option.none(), "false")) || Arr.head(path).pipe(Option.getOrUndefined) === "schema" || Arr.some(path, (word) => CF_READ_VERB.test(word)) && !Arr.some(path, (word) => CF_WRITE_VERB.test(word));
637
+ };
638
+ const PROVIDER_CLIS = {
639
+ wrangler: () => false,
640
+ pscale: (words) => [
641
+ "sql",
642
+ "auth",
643
+ "org"
644
+ ].includes(Arr.head(commandPath(words)).pipe(Option.getOrElse(() => ""))),
645
+ cf: cfReads
646
+ };
647
+ const reachOf = (cli, words) => {
648
+ const path = commandPath(words);
649
+ return PROVIDER_CLIS[cli](words) ? [] : [`${cli} ${Arr.match(path, {
650
+ onEmpty: () => "<unknown>",
651
+ onNonEmpty: (command) => command.join(" ")
652
+ })}`];
653
+ };
654
+ const CLOUDFLARE = "cloudflare";
655
+ const PROVIDERS = [CLOUDFLARE, "planetscale"];
656
+ const PROVIDER_HOST = new RegExp(String.raw`\bapi\.(?:${PROVIDERS.join("|")})\.com\b`, "u");
657
+ const hexDigits = (code, width) => code.toString(16).padStart(width, "0").replaceAll(/[a-f]/gu, (digit) => `[${digit}${digit.toUpperCase()}]`);
658
+ const IDENTITY_ESCAPED = /^[^\dbfnrtuvx]$/u;
659
+ const LINE_CONTINUATIONS = String.raw`(?:\\(?:\r\n?|[\n\u2028\u2029]))*`;
660
+ const spelled = (word) => Array.from(word, (char) => {
661
+ const code = char.codePointAt(0) ?? 0;
662
+ const plain = char === "." ? String.raw`\.` : char;
663
+ const escapes = [
664
+ `x${hexDigits(code, 2)}`,
665
+ `u${hexDigits(code, 4)}`,
666
+ String.raw`u\{0*${hexDigits(code, 1)}\}`,
667
+ `0*${code.toString(8)}`,
668
+ ...IDENTITY_ESCAPED.test(char) ? [plain] : []
669
+ ];
670
+ return String.raw`${LINE_CONTINUATIONS}(?:${plain}|\\(?:${escapes.join("|")}))`;
671
+ }).join("");
672
+ const IDENTIFIER_PART = String.raw`[\p{ID_Continue}$\u200c\u200d]`;
673
+ const SHELL_WORD_CHAR = String.raw`[\w./@-]`;
674
+ const ESCAPE_END = String.raw`\\(?:x[\da-fA-F]{2}|u[\da-fA-F]{4}|u\{[\da-fA-F]+\}|[0-7]{1,3}|[^])`;
675
+ const SHELL_WORD_BEFORE = String.raw`(?:^|\/|(?!${SHELL_WORD_CHAR})[^]|${ESCAPE_END})`;
676
+ const SHELL_WORD_AFTER = String.raw`(?!${SHELL_WORD_CHAR})`;
677
+ const MEMBER_ACCESS_BEFORE = String.raw`(?:(?<!\.)\.|\d\.\.|[[\/\n\r\u2028\u2029])\s*`;
678
+ const MEMBER_ACCESS_AFTER = String.raw`(?!${IDENTIFIER_PART})(?=\s*\]?\s*(?:\??\.|[[\/]))`;
679
+ const spelledBetween = (before, word, after) => String.raw`${spelled(word)}${after}(?<=${before}${spelled(word)})`;
680
+ const MAY_REACH = new RegExp([
681
+ ...["@distilled.cloud/", ...PROVIDERS.map((provider) => `api.${provider}.com`)].map(spelled),
682
+ ...R.keys(PROVIDER_CLIS).map((cli) => spelledBetween(SHELL_WORD_BEFORE, cli, SHELL_WORD_AFTER)),
683
+ `["']${spelled(CLOUDFLARE)}`,
684
+ spelledBetween(MEMBER_ACCESS_BEFORE, "rest", MEMBER_ACCESS_AFTER)
685
+ ].join("|"), "u");
686
+ const MANAGEMENT_CLIENT = new RegExp(String.raw`^(?:@distilled\.cloud\/[^/]+(?:\/(?!Credentials$|Errors$|Retry$)[^/]+)?|${CLOUDFLARE}(?:\/.*)?)$`, "u");
687
+ const RUNTIME_CLIENTS = /* @__PURE__ */ new Set(["@distilled.cloud/boat-dev", "@distilled.cloud/stripe"]);
688
+ const RUNTIME_REST = /* @__PURE__ */ new Map([
689
+ ["git", /* @__PURE__ */ new Set([
690
+ "createBlob",
691
+ "createTree",
692
+ "createCommit",
693
+ "createRef"
694
+ ])],
695
+ ["repos", /* @__PURE__ */ new Set(["createCommitStatus"])],
696
+ ["issues", /* @__PURE__ */ new Set([
697
+ "addAssignees",
698
+ "addLabels",
699
+ "create",
700
+ "createComment",
701
+ "deleteComment",
702
+ "lock",
703
+ "removeAllLabels",
704
+ "removeAssignees",
705
+ "removeLabel",
706
+ "setLabels",
707
+ "unlock",
708
+ "update",
709
+ "updateComment"
710
+ ])],
711
+ ["pulls", /* @__PURE__ */ new Set([
712
+ "create",
713
+ "createReplyForReviewComment",
714
+ "createReview",
715
+ "createReviewComment",
716
+ "deletePendingReview",
717
+ "deleteReviewComment",
718
+ "dismissReview",
719
+ "merge",
720
+ "removeRequestedReviewers",
721
+ "requestReviewers",
722
+ "submitReview",
723
+ "update",
724
+ "updateBranch",
725
+ "updateReview",
726
+ "updateReviewComment"
727
+ ])]
728
+ ]);
729
+ const packageOf = (source) => source.split("/").slice(0, 2).join("/");
730
+ const chainOf = (node) => {
731
+ if (node.type === "Identifier") return [node.name];
732
+ if (node.type !== "MemberExpression" || node.computed) return;
733
+ const head = chainOf(node.object);
734
+ return head === void 0 ? void 0 : [...head, node.property.name];
735
+ };
736
+ const READ_METHOD = /^(?:get|list|query|compare)(?:[A-Z_]|$)/iu;
737
+ const textOf = (node) => {
738
+ if (Option.isNone(node)) return Option.none();
739
+ const { value } = node;
740
+ if (value.type === "Literal") return Schema.is(Schema.String)(value.value) ? Option.some(value.value) : Option.none();
741
+ return value.type === "TemplateLiteral" ? Option.some(value.quasis.map((quasi) => quasi.value.raw).join(" ")) : Option.none();
742
+ };
743
+ const ProviderCli = Schema.Literals(R.keys(PROVIDER_CLIS));
744
+ const cliOf = (word) => {
745
+ const name = word.slice(word.lastIndexOf("/") + 1);
746
+ return Schema.is(ProviderCli)(name) ? Option.some(name) : Option.none();
747
+ };
748
+ const SHELL_TOKEN = new RegExp(String.raw`[;&|\n\x60()]|["'$=]|${SHELL_WORD_CHAR}+`, "gu");
749
+ const SEPARATOR = /^[;&|\n`()]$/u;
750
+ const shellFindings = (text) => {
751
+ const tokens = text.match(SHELL_TOKEN) ?? [];
752
+ return tokens.flatMap((token, index) => {
753
+ const cli = cliOf(token);
754
+ return Option.isNone(cli) ? [] : reachOf(cli.value, Arr.takeWhile(tokens.slice(index + 1), (word) => !SEPARATOR.test(word)).map(Option.some));
755
+ });
756
+ };
757
+ const providerReaches = (file, source) => {
758
+ if (!MAY_REACH.test(source)) return [];
759
+ const found = [];
760
+ const clients = /* @__PURE__ */ new Set();
761
+ const instances = /* @__PURE__ */ new Set();
762
+ const commands = /* @__PURE__ */ new Set();
763
+ const invocation = (operands) => {
764
+ for (const [index, operand] of operands.entries()) {
765
+ const cli = cliOf(Option.getOrElse(Option.map(textOf(operand), (text) => text.trim()), () => ""));
766
+ if (Option.isSome(operand) && Option.isSome(cli)) {
767
+ const after = operands[index + 1] ?? Option.none();
768
+ const words = (Option.isSome(after) && after.value.type === "ArrayExpression" ? after.value.elements.map(Option.fromNullishOr) : operands.slice(index + 1)).map(textOf);
769
+ commands.add(operand.value);
770
+ found.push(...reachOf(cli.value, words));
771
+ }
772
+ }
773
+ };
774
+ const literal = (node) => {
775
+ const text = textOf(Option.some(node));
776
+ if (Option.isNone(text) || commands.has(node)) return;
777
+ if (PROVIDER_HOST.test(text.value)) found.push(`host ${text.value}`);
778
+ found.push(...Option.isNone(cliOf(text.value.trim())) ? shellFindings(text.value) : [`${text.value.trim()} <unknown>`]);
779
+ };
780
+ new Visitor({
781
+ ImportDeclaration: (node) => {
782
+ if (node.importKind === "type" || !MANAGEMENT_CLIENT.test(node.source.value) || RUNTIME_CLIENTS.has(packageOf(node.source.value))) return;
783
+ for (const specifier of node.specifiers) if (specifier.type !== "ImportSpecifier") clients.add(specifier.local.name);
784
+ else if (specifier.importKind !== "type") {
785
+ const imported = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
786
+ if (!READ_METHOD.test(imported)) found.push(`imports ${imported}`);
787
+ }
788
+ },
789
+ VariableDeclarator: (node) => {
790
+ const init = node.init?.type === "AwaitExpression" ? node.init.argument : node.init;
791
+ const callee = init?.type === "NewExpression" || init?.type === "CallExpression" ? init.callee : void 0;
792
+ if (node.id.type === "Identifier" && callee?.type === "Identifier" && clients.has(callee.name)) instances.add(node.id.name);
793
+ },
794
+ CallExpression: (node) => {
795
+ invocation(node.arguments.map(Option.some));
796
+ const [root, ...path] = chainOf(node.callee) ?? [];
797
+ const method = path.at(-1);
798
+ if (root !== void 0 && method !== void 0 && instances.has(root) && !READ_METHOD.test(method)) found.push(`calls ${[root, ...path].join(".")}`);
799
+ },
800
+ NewExpression: (node) => invocation(node.arguments.map(Option.some)),
801
+ ArrayExpression: (node) => invocation(node.elements.map(Option.fromNullishOr)),
802
+ Literal: (node) => literal(node),
803
+ TemplateLiteral: (node) => literal(node),
804
+ MemberExpression: (node) => {
805
+ if (node.computed || node.property.type !== "Identifier") return;
806
+ const method = node.property.name;
807
+ const { object } = node;
808
+ const client = object.type === "Identifier" && clients.has(object.name) ? object.name : void 0;
809
+ const namespace = object.type === "MemberExpression" && object.object.type === "MemberExpression" && object.object.property.type === "Identifier" && object.object.property.name === "rest" ? !object.computed && object.property.type === "Identifier" ? object.property.name : "<computed>" : void 0;
810
+ const target = client ?? (namespace === void 0 || namespace === "search" || RUNTIME_REST.get(namespace)?.has(method) === true ? void 0 : `rest.${namespace}`);
811
+ if (target !== void 0 && !READ_METHOD.test(method)) found.push(`calls ${target}.${method}`);
812
+ }
813
+ }).visit(parseSync(file, source).program);
814
+ return found;
815
+ };
816
+ const PackageScripts = Schema.fromJsonString(Schema.Struct({ scripts: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)) }));
817
+ const Workflow = Schema.Struct({ jobs: Schema.Record(Schema.String, Schema.Struct({ steps: Schema.optionalKey(Schema.Array(Schema.Struct({ run: Schema.optionalKey(Schema.String) }))) })) });
818
+ const SCRIPT = /\.[cm]?[jt]sx?$/u;
819
+ const WORKFLOW = /^\.github\/workflows\/[^/]+\.ya?ml$/u;
820
+ const infra = (repo) => Effect.gen(function* () {
821
+ const findings = [];
822
+ for (const file of repo.tracked) {
823
+ if (/(?:^|\/)wrangler\.(?:jsonc?|toml)$/u.test(file)) {
824
+ findings.push({
825
+ file,
826
+ message: "provision infrastructure with native Alchemy resources instead of a Wrangler config"
827
+ });
828
+ continue;
829
+ }
830
+ if (!SCRIPT.test(file) && !file.endsWith(".sh") && !/(?:^|\/)package\.json$/u.test(file) && !WORKFLOW.test(file)) continue;
831
+ const input = yield* read(repo, file, (text) => {
832
+ if (SCRIPT.test(file)) return providerReaches(file, text);
833
+ if (file.endsWith(".sh")) return shellFindings(text);
834
+ return (WORKFLOW.test(file) ? Object.values(Schema.decodeUnknownSync(Workflow)(Bun.YAML.parse(text)).jobs).flatMap((job) => (job.steps ?? []).flatMap((step) => step.run === void 0 ? [] : [step.run])) : Object.values(Schema.decodeSync(PackageScripts)(text).scripts ?? {})).flatMap(shellFindings);
835
+ });
836
+ findings.push(...input.ok ? input.value.map((reach) => ({
837
+ file,
838
+ message: `${reach}; provision infrastructure with native Alchemy resources`
839
+ })) : input.findings);
840
+ }
841
+ return findings;
842
+ });
296
843
  // src/standard/toolchain.ts
297
844
  const packageName = "@milkenjoyer/toolchain";
298
845
  const pin = (repo) => Effect.gen(function* () {
@@ -354,7 +901,13 @@ const rules = {
354
901
  specs,
355
902
  "ready-formal": readyFormal,
356
903
  "task-agents": taskAgents,
357
- "skill-names": skillNames
904
+ "skill-names": skillNames,
905
+ "infra-through-alchemy": infra,
906
+ "alchemy-pins": alchemyPins,
907
+ "domain-layout": domainLayout,
908
+ "domain-imports": domainImports,
909
+ "domain-no-throw": domainNoThrow,
910
+ "lint-config": lintConfig
358
911
  };
359
912
  // src/standard.ts
360
913
  const singleLine = (message) => message.replaceAll(/\s+/gu, " ").trim();