@orkestrel/scaffold 0.0.25 → 0.0.27

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/README.md CHANGED
@@ -91,9 +91,14 @@ const compiler = createCompiler()
91
91
  const scaffolding = compiler.compile(createBlueprint('router', { src: ['core', 'server'] }))
92
92
 
93
93
  scaffolding.plan?.artifacts // every planned file, in group order
94
+ scaffolding.questions // the advice the compile could not settle
94
95
  compiler.destroy()
95
96
  ```
96
97
 
98
+ A plan says the workspace can be built. It does not say the workspace should be created: a caller
99
+ creating a fresh workspace refuses on any question beside the plan, blocking or not, exactly as
100
+ `new` does. [`guides/scaffold.md`](guides/scaffold.md) states that rule and what it covers.
101
+
97
102
  `@orkestrel/scaffold/server` is Node-only and holds everything that touches the filesystem or the
98
103
  network: `createMaterializer` writes a plan into a target, `createUpstream` reads the registry and
99
104
  the guide host, and `WriteTransaction` stages and swaps a set of files with rollback.
package/dist/bin/main.js CHANGED
@@ -434,6 +434,43 @@ function auditToExit(audit) {
434
434
  return blocked || drifted ? 1 : 0;
435
435
  }
436
436
  /**
437
+ * Project an audit into the human summary of its outcome.
438
+ *
439
+ * @param audit - The comparison to summarize.
440
+ * @returns The refusal, or the planned-path outcome, its grounds, and any foreign-path count.
441
+ *
442
+ * @remarks
443
+ * A blocking question means the gate produced no plan, so the target was not
444
+ * compared and no finding count is reported. Otherwise the three grounds
445
+ * describe what this run did. `bytes` means content-owned
446
+ * bytes were observed, `existence` means presence or absence alone decided the
447
+ * finding, and `nothing` means a birth-owned path was not examined. Foreign
448
+ * paths remain a separate population because no planned ownership accounts for
449
+ * them.
450
+ *
451
+ * @example
452
+ * ```ts
453
+ * import { auditToSummary } from './helpers.js'
454
+ *
455
+ * auditToSummary({
456
+ * findings: [],
457
+ * questions: [{ field: 'src', message: 'Core is required.', blocking: true }],
458
+ * })
459
+ * // 'Audit did not compare the target because the blueprint was refused.'
460
+ * ```
461
+ */
462
+ function auditToSummary(audit) {
463
+ if (audit.questions.some((question) => question.blocking)) return "Audit did not compare the target because the blueprint was refused.";
464
+ const planned = audit.findings.filter((finding) => finding.drift !== "foreign");
465
+ const drifted = planned.filter((finding) => finding.drift !== "aligned").length;
466
+ const bytes = planned.filter((finding) => finding.ownership === "content" && finding.observed !== void 0).length;
467
+ const existence = planned.filter((finding) => finding.ownership === "presence" || finding.ownership === "content" && finding.drift === "missing").length;
468
+ const nothing = planned.filter((finding) => finding.ownership === "birth").length;
469
+ const foreign = audit.findings.length - planned.length;
470
+ const summary = `${String(drifted)} of ${String(planned.length)} planned path${planned.length === 1 ? "" : "s"} drifted from the plan. Audit compared bytes at ${String(bytes)}, existence at ${String(existence)}, and nothing at ${String(nothing)}.`;
471
+ return foreign === 0 ? summary : `${summary} The plan does not own ${String(foreign)} further path${foreign === 1 ? "" : "s"} beneath its groups.`;
472
+ }
473
+ /**
437
474
  * Project a raised value into the machine-readable failure envelope.
438
475
  *
439
476
  * @param error - The value a command raised.
@@ -758,8 +795,8 @@ var CLI = class CLI {
758
795
  const compiler = createCompiler();
759
796
  try {
760
797
  const scaffolding = compiler.compile(blueprint, groups);
761
- if (scaffolding.plan !== void 0) return scaffolding.plan;
762
- throw new ScaffoldError("BLOCKED", scaffolding.questions.filter((question) => question.blocking).map((question) => `${question.field}: ${question.message}`).join(" "), { questions: scaffolding.questions.length });
798
+ if (scaffolding.plan !== void 0 && scaffolding.questions.length === 0) return scaffolding.plan;
799
+ throw new ScaffoldError("BLOCKED", scaffolding.questions.map((question) => `${question.field}: ${question.message}`).join(" "), { questions: scaffolding.questions.length });
763
800
  } finally {
764
801
  compiler.destroy();
765
802
  }
@@ -769,7 +806,11 @@ var CLI = class CLI {
769
806
  try {
770
807
  const scaffolding = compiler.compile(blueprint, groups);
771
808
  if (scaffolding.plan === void 0) return [compiler.audit(blueprint, {}, groups), void 0];
772
- return [materializer.audit(scaffolding.plan, target), scaffolding.plan];
809
+ const measured = materializer.audit(scaffolding.plan, target);
810
+ return [{
811
+ ...measured,
812
+ questions: [...measured.questions, ...scaffolding.questions]
813
+ }, scaffolding.plan];
773
814
  } finally {
774
815
  compiler.destroy();
775
816
  }
@@ -1053,7 +1094,7 @@ var CLI = class CLI {
1053
1094
  });
1054
1095
  for (const line of table.split("\n")) this.#say(line);
1055
1096
  }
1056
- this.#say(`${String(rows.length)} of ${String(audit.findings.length)} planned path${audit.findings.length === 1 ? "" : "s"} differ from the plan.`);
1097
+ this.#say(auditToSummary(audit));
1057
1098
  }
1058
1099
  #recount(result) {
1059
1100
  this.#say(this.#tally(result));
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","names":["#stdout","#stderr","#output","#diagnostic","#upstream","#say","#refuse","#dispatch","#create","#inspect","#restore","#refresh","#replace","#environments","#resolve","#packages","#compile","#report","#tally","#derive","#projectQuestion","#survey","#groups","#present","#assertProjects","#warn","#previous","#fetch","#publish","#recount","#repository","#merge","#reconcile","#lookup","#pin","#manifest","#probe","#scriptProjects","#inventory","#sanitize"],"sources":["../../src/bin/constants.ts","../../src/bin/errors.ts","../../src/bin/helpers.ts","../../src/bin/CLI.ts","../../src/bin/main.ts"],"sourcesContent":["import type { ParseArgsOptionsConfig } from 'node:util'\nimport type { Verb } from './types.js'\n\n/**\n * The name the executable installs as.\n *\n * @remarks\n * `package.json`'s `bin` field is the authority for what the command is called;\n * this is the same word, so every usage line the executable prints is a command\n * a reader can paste back.\n */\nexport const EXECUTABLE_NAME = 'scaffold'\n\n/**\n * The five {@link Verb} values in usage order, frozen.\n *\n * @remarks\n * The order the type declares them in, which is also the order usage lists them:\n * the verb that creates a workspace, then the one that only reads it, then the\n * three that write to one that already exists, widest last.\n */\nexport const VERBS: readonly Verb[] = Object.freeze([\n\t'new',\n\t'audit',\n\t'repair',\n\t'catalog',\n\t'overwrite',\n])\n\n/** The exit code reporting that the target matched its plan and every step completed. */\nexport const EXIT_CLEAN = 0\n\n/** The exit code reporting that the target drifted, or that a step failed. */\nexport const EXIT_DRIFT = 1\n\n/** The exit code reporting that the command line was not a command. */\nexport const EXIT_USAGE = 2\n\n/**\n * What each exit code means, frozen.\n *\n * @remarks\n * Keyed by the three code constants rather than by literals, so the usage block\n * cannot document a code the executable does not return.\n */\nexport const EXIT_SUMMARY: Readonly<Record<number, string>> = Object.freeze({\n\t[EXIT_CLEAN]: 'clean',\n\t[EXIT_DRIFT]: 'drift or failure',\n\t[EXIT_USAGE]: 'usage error',\n})\n\n/**\n * The machine-readable code a malformed command line reports.\n *\n * @remarks\n * The executable contributes its own codes to the failure envelope, which is why\n * that envelope's `code` is a plain string rather than a `ScaffoldErrorCode`: a\n * command line that never became a command failed before any coded package\n * operation could.\n */\nexport const USAGE_CODE = 'USAGE'\n\n/** The machine-readable code a failure carrying no code of its own reports. */\nexport const FAILED_CODE = 'FAILED'\n\n/** What the failure envelope says when the raised value carried no message. */\nexport const FAILED_MESSAGE = 'The command failed for an unrecognized reason'\n\n/**\n * The positional argument `new` alone takes, as usage writes it.\n *\n * @remarks\n * The workspace name is the only positional argument any verb takes, so it is\n * one value rather than a per-verb table with four holes in it.\n */\nexport const NAME_ARGUMENT = '<name>'\n\n/**\n * Every option the executable accepts, as `node:util` parses them, frozen.\n *\n * @remarks\n * One table for every verb rather than one per verb, because the verb an option\n * belongs to is a domain fact the command union already fixes: parsing decides\n * only whether the word is an option at all, and {@link VERB_OPTIONS} decides\n * whether this verb takes it. No option declares a default, so the parsed keys\n * are exactly the options the caller supplied, which is what makes an option\n * offered to the wrong verb visible rather than silently absorbed. `from`\n * collects repeats because `catalog` may draw on more than one local source; a\n * verb that takes it once refuses the second.\n */\nexport const COMMAND_OPTIONS: ParseArgsOptionsConfig = Object.freeze({\n\tsrc: Object.freeze({ type: 'string' }),\n\tapp: Object.freeze({ type: 'string' }),\n\tbin: Object.freeze({ type: 'boolean' }),\n\tdeps: Object.freeze({ type: 'string' }),\n\tgroups: Object.freeze({ type: 'string' }),\n\tall: Object.freeze({ type: 'boolean' }),\n\tdirty: Object.freeze({ type: 'boolean' }),\n\tfrom: Object.freeze({ type: 'string', multiple: true }),\n\ttarget: Object.freeze({ type: 'string' }),\n\tjson: Object.freeze({ type: 'boolean' }),\n})\n\n/**\n * What each option does, keyed by the token usage prints, frozen.\n *\n * @remarks\n * The key order is the glossary order. A key is the whole displayed token,\n * value placeholder included, because that token is what a reader copies and\n * what {@link VERB_OPTIONS} lists.\n */\nexport const OPTION_SUMMARY: Readonly<Record<string, string>> = Object.freeze({\n\t'--src <list>': 'the published library environments to build: core, browser, server',\n\t'--app <list>': 'the private application environments to build: core, browser, server',\n\t'--bin': 'scaffold a command-line executable at src/bin/main.ts',\n\t'--deps <list>': 'the @orkestrel/* packages the workspace depends on',\n\t'--groups <list>': 'the artifact groups to cover; every group when absent',\n\t'--all': 'fetch a guide for every package the organization publishes, not just the declared ones',\n\t'--dirty': 'delete from a tree carrying uncommitted changes',\n\t'--from <path>':\n\t\t'read the data root from a local path instead of the bundled one; catalog alone accepts it more than once',\n\t'--target <path>': 'the directory the verb operates on; the working directory when absent',\n\t'--json': 'emit one machine-readable value instead of a report',\n})\n\n/**\n * The options each verb takes, in usage order, frozen.\n *\n * @remarks\n * The executable's half of the frozen command union: every option a branch\n * declares is listed against its verb, and every option a branch excludes is\n * absent from it. An option a verb does not list is refused by name rather than\n * parsed and ignored.\n */\nexport const VERB_OPTIONS: Readonly<Record<Verb, readonly string[]>> = Object.freeze({\n\tnew: Object.freeze([\n\t\t'--src <list>',\n\t\t'--app <list>',\n\t\t'--bin',\n\t\t'--deps <list>',\n\t\t'--from <path>',\n\t\t'--target <path>',\n\t\t'--json',\n\t]),\n\taudit: Object.freeze(['--groups <list>', '--from <path>', '--target <path>', '--json']),\n\trepair: Object.freeze(['--groups <list>', '--from <path>', '--target <path>', '--json']),\n\tcatalog: Object.freeze(['--all', '--from <path>', '--target <path>', '--json']),\n\toverwrite: Object.freeze([\n\t\t'--groups <list>',\n\t\t'--dirty',\n\t\t'--from <path>',\n\t\t'--target <path>',\n\t\t'--json',\n\t]),\n})\n\n/**\n * What each verb does, in one line, frozen.\n *\n * @remarks\n * Each line names what the verb writes, because authority is the verb's: a\n * reader deciding which one to run is deciding what they are authorizing.\n */\nexport const VERB_SUMMARY: Readonly<Record<Verb, string>> = Object.freeze({\n\tnew: 'scaffold a workspace',\n\taudit: 'report how the target compares to its plan, writing nothing',\n\trepair: 'write each planned path the target is missing or has let drift',\n\tcatalog: 'regenerate the package table and refresh the guide mirrors',\n\toverwrite:\n\t\t'do everything repair and catalog do, then delete what the plan does not own and re-declare the dependency ranges',\n})\n","import { USAGE_CODE } from './constants.js'\n\n/**\n * The error raised when a command line is not a command.\n *\n * @remarks\n * Distinct from `ScaffoldError` because the two answer different questions and\n * exit differently: a `ScaffoldError` says the package could not serve a\n * well-formed request and exits `1`, while this says there was no request to\n * serve and exits `2`. Folding a usage error into `INVALID` would report a\n * mistyped flag as a failed run.\n *\n * It carries no `context`. Everything a caller can act on is in the message,\n * because the reader of a usage error is a person at a terminal rather than a\n * program branching on a cause.\n *\n * @example\n * ```ts\n * import { isUsageError, UsageError } from './errors.js'\n *\n * try {\n * \tthrow new UsageError(\"Unknown command 'pull'.\")\n * } catch (error) {\n * \tif (isUsageError(error)) error.code // 'USAGE'\n * }\n * ```\n */\nexport class UsageError extends Error {\n\treadonly code: string\n\n\t/**\n\t * Construct a usage error.\n\t *\n\t * @param message - What was wrong with the command line, in one sentence.\n\t */\n\tconstructor(message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'UsageError'\n\t\tthis.code = USAGE_CODE\n\t}\n}\n\n/**\n * Narrow a caught value to a {@link UsageError}.\n *\n * @param value - The caught value to narrow.\n * @returns `true` when `value` is a {@link UsageError}.\n *\n * @example\n * ```ts\n * import { isUsageError } from './errors.js'\n *\n * isUsageError(new Error('plain')) // false\n * isUsageError(undefined) // false\n * ```\n */\nexport function isUsageError(value: unknown): value is UsageError {\n\treturn value instanceof UsageError\n}\n","import type { Audit } from '@src/core'\nimport type { CLICommand, ErrorEnvelope, Verb } from './types.js'\nimport { align, width } from '@orkestrel/console'\nimport { attempt } from '@orkestrel/contract'\nimport { isScaffoldError } from '@src/core'\nimport { parseArgs } from 'node:util'\nimport {\n\tCOMMAND_OPTIONS,\n\tEXECUTABLE_NAME,\n\tEXIT_CLEAN,\n\tEXIT_DRIFT,\n\tEXIT_SUMMARY,\n\tFAILED_CODE,\n\tFAILED_MESSAGE,\n\tNAME_ARGUMENT,\n\tOPTION_SUMMARY,\n\tVERB_OPTIONS,\n\tVERB_SUMMARY,\n\tVERBS,\n} from './constants.js'\nimport { isUsageError, UsageError } from './errors.js'\n\n/**\n * Read the option name out of the token usage displays it as.\n *\n * @param option - The displayed token, such as `--from <path>`.\n * @returns The bare name `node:util` parses the option under.\n *\n * @remarks\n * One token serves both readers: a person reads the value placeholder and the\n * parser reads the name in front of it. Deriving the name means a documented\n * option and an accepted option cannot be two different lists.\n *\n * @example\n * ```ts\n * import { optionToName } from './helpers.js'\n *\n * optionToName('--from <path>') // 'from'\n * optionToName('--json') // 'json'\n * ```\n */\nexport function optionToName(option: string): string {\n\tconst [token = option] = option.split(' ')\n\treturn token.startsWith('--') ? token.slice(2) : token\n}\n\n/**\n * Render one verb's synopsis.\n *\n * @param verb - The verb to describe.\n * @returns The command line this verb accepts, with every option bracketed.\n *\n * @remarks\n * The synopsis is derived from the verb's own option list rather than stored\n * beside it, so a line that documents an option the verb does not take cannot be\n * written. `new` alone carries the positional argument.\n *\n * @example\n * ```ts\n * import { verbToSyntax } from './helpers.js'\n *\n * verbToSyntax('audit') // 'scaffold audit [--groups <list>] …'\n * ```\n */\nexport function verbToSyntax(verb: Verb): string {\n\tconst argument = verb === 'new' ? ` ${NAME_ARGUMENT}` : ''\n\tconst options = VERB_OPTIONS[verb].map((option) => `[${option}]`).join(' ')\n\treturn `${EXECUTABLE_NAME} ${verb}${argument} ${options}`\n}\n\n/**\n * Render the whole command reference.\n *\n * @returns One line per output call: the synopsis, every verb, the option glossary, and the exit codes.\n *\n * @remarks\n * Returned as lines because the executable writes through a handler that takes\n * one line, so the caller never has to split a block back apart. The glossary is\n * printed once for every verb rather than repeated per verb, since seven of the\n * nine options are shared and a reader comparing two verbs wants the difference,\n * not the repetition.\n */\nexport function renderUsage(): readonly string[] {\n\tconst summaries = Object.entries(OPTION_SUMMARY)\n\tconst column = Math.max(...summaries.map(([option]) => width(option)))\n\treturn [\n\t\t`${EXECUTABLE_NAME} <verb> [options]`,\n\t\t'',\n\t\t...VERBS.flatMap((verb) => [` ${verbToSyntax(verb)}`, ` ${VERB_SUMMARY[verb]}`]),\n\t\t'',\n\t\t'options',\n\t\t...summaries.map(([option, summary]) => ` ${align(option, column)} ${summary}`),\n\t\t'',\n\t\t'exit codes',\n\t\t...Object.entries(EXIT_SUMMARY).map(([code, meaning]) => ` ${code} ${meaning}`),\n\t]\n}\n\n/**\n * Read one command out of the arguments following the executable's own name.\n *\n * @param argv - The arguments the executable was given.\n * @returns The command the arguments denote.\n * @throws {@link UsageError} when they denote no command.\n *\n * @remarks\n * The one place untrusted argument text becomes a domain value, and it stays one\n * function because the command union admits no partial command to hand on: every\n * refusal has to happen before the value exists. It refuses in four ways, each\n * naming what was wrong — a word that is not a verb, a word that is not an\n * option, an option this verb does not take, and an argument this verb does not\n * take. `node:util` decides the second and this decides the rest, so an unknown\n * option is reported by the parser that found it rather than re-derived here.\n *\n * A request for usage is not a command and never reaches this: the caller\n * answers it first.\n *\n * @example\n * ```ts\n * import { argvToCommand } from './helpers.js'\n *\n * argvToCommand(['audit', '--json']) // { verb: 'audit', json: true }\n * ```\n */\nexport function argvToCommand(argv: readonly string[]): CLICommand {\n\tconst [head, ...rest] = argv\n\tconst verb = VERBS.find((candidate) => candidate === head)\n\tif (verb === undefined) {\n\t\tconst found = head === undefined ? 'No command given.' : `Unknown command '${head}'.`\n\t\tthrow new UsageError(`${found} Run '${EXECUTABLE_NAME} --help' for the command list.`)\n\t}\n\tconst parsed = attempt(() =>\n\t\tparseArgs({ args: rest, options: COMMAND_OPTIONS, allowPositionals: true, strict: true }),\n\t)\n\tif (!parsed.success) {\n\t\tconst cause = parsed.error\n\t\tthrow new UsageError(\n\t\t\tcause instanceof Error ? cause.message : `Could not read the arguments to '${verb}'.`,\n\t\t)\n\t}\n\tconst { positionals, values } = parsed.value\n\tconst accepted = VERB_OPTIONS[verb].map((option) => optionToName(option))\n\tconst refused = Object.keys(values).filter((name) => !accepted.includes(name))\n\tif (refused.length > 0) {\n\t\tconst names = refused.map((name) => `--${name}`).join(', ')\n\t\tthrow new UsageError(`'${verb}' does not take ${names}.`)\n\t}\n\tconst [name] = positionals\n\tif (positionals.length > 1) {\n\t\tthrow new UsageError(\n\t\t\t`'${verb}' takes at most one argument, and was given ${String(positionals.length)}.`,\n\t\t)\n\t}\n\tif (verb !== 'new' && name !== undefined) {\n\t\tthrow new UsageError(`'${verb}' takes no argument, and was given '${name}'.`)\n\t}\n\tconst paths = Array.isArray(values.from)\n\t\t? values.from.filter((value) => typeof value === 'string')\n\t\t: []\n\tif (verb !== 'catalog' && paths.length > 1) {\n\t\tthrow new UsageError(\n\t\t\t`'${verb}' takes --from once, and was given it ${String(paths.length)} times.`,\n\t\t)\n\t}\n\tconst src = typeof values.src === 'string' ? values.src : undefined\n\tconst app = typeof values.app === 'string' ? values.app : undefined\n\tconst bin = values.bin === true\n\tconst dependencies = typeof values.deps === 'string' ? values.deps : undefined\n\tconst target = typeof values.target === 'string' ? values.target : undefined\n\tconst json = values.json === true\n\tconst [from] = paths\n\tconst location = target === undefined ? {} : { target }\n\tconst source = from === undefined ? {} : { from }\n\tconst selection = typeof values.groups === 'string' ? { groups: values.groups } : {}\n\tswitch (verb) {\n\t\tcase 'new':\n\t\t\tif (name === undefined) {\n\t\t\t\tthrow new UsageError(`'new' needs the workspace ${NAME_ARGUMENT} it is scaffolding.`)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tverb,\n\t\t\t\tname,\n\t\t\t\tjson,\n\t\t\t\t...location,\n\t\t\t\t...source,\n\t\t\t\t...(src === undefined ? {} : { src }),\n\t\t\t\t...(app === undefined ? {} : { app }),\n\t\t\t\t...(bin ? { bin } : {}),\n\t\t\t\t...(dependencies === undefined ? {} : { dependencies }),\n\t\t\t}\n\t\tcase 'audit':\n\t\t\treturn { verb, json, ...location, ...source, ...selection }\n\t\tcase 'repair':\n\t\t\treturn { verb, json, ...location, ...source, ...selection }\n\t\tcase 'catalog':\n\t\t\treturn {\n\t\t\t\tverb,\n\t\t\t\tjson,\n\t\t\t\tall: values.all === true,\n\t\t\t\t...location,\n\t\t\t\t...(paths.length === 0 ? {} : { from: paths }),\n\t\t\t}\n\t\tcase 'overwrite':\n\t\t\treturn {\n\t\t\t\tverb,\n\t\t\t\tjson,\n\t\t\t\tdirty: values.dirty === true,\n\t\t\t\t...location,\n\t\t\t\t...source,\n\t\t\t\t...selection,\n\t\t\t}\n\t}\n}\n\n/**\n * Read the exit code an audit reports.\n *\n * @param audit - The comparison of a plan against a target.\n * @returns `EXIT_CLEAN` when the target matched the plan, `EXIT_DRIFT` otherwise.\n *\n * @remarks\n * One rule for every verb that carries an audit, so `audit`, `repair`, and\n * `overwrite` cannot disagree about what a clean run is. A blocking question\n * means the gate refused the blueprint, so the audit says nothing about the\n * target and the run is a failure. A foreign finding counts: the target holds a\n * file the plan does not own, which is a difference from the plan whether or not\n * this verb was allowed to remove it. A non-blocking question rides a complete\n * result and does not.\n *\n * @example\n * ```ts\n * import { auditToExit } from './helpers.js'\n *\n * auditToExit({ findings: [], questions: [] }) // 0\n * ```\n */\nexport function auditToExit(audit: Audit): number {\n\tconst blocked = audit.questions.some((question) => question.blocking)\n\tconst drifted = audit.findings.some((finding) => finding.drift !== 'aligned')\n\treturn blocked || drifted ? EXIT_DRIFT : EXIT_CLEAN\n}\n\n/**\n * Project a raised value into the machine-readable failure envelope.\n *\n * @param error - The value a command raised.\n * @returns The envelope naming the coded reason and what went wrong.\n *\n * @remarks\n * A `ScaffoldError` and a {@link UsageError} both publish a code, so both are\n * reported under their own. Anything else failed without saying why, and is\n * reported under one code rather than under an invented reading of it; a raised\n * value that is not an `Error` carries no message worth quoting, so the envelope\n * says so instead of stringifying whatever it was.\n *\n * @example\n * ```ts\n * import { errorToEnvelope } from './helpers.js'\n *\n * errorToEnvelope(new Error('boom')) // { error: { code: 'FAILED', message: 'boom' } }\n * ```\n */\nexport function errorToEnvelope(error: unknown): ErrorEnvelope {\n\tif (isUsageError(error) || isScaffoldError(error)) {\n\t\treturn { error: { code: error.code, message: error.message } }\n\t}\n\tconst message = error instanceof Error ? error.message : FAILED_MESSAGE\n\treturn { error: { code: FAILED_CODE, message } }\n}\n","import type {\n\tAudit,\n\tBlueprint,\n\tCatalogEntry,\n\tDependency,\n\tEnvironment,\n\tGroup,\n\tMirror,\n\tPlan,\n\tQuestion,\n\tRelease,\n} from '@src/core'\nimport type {\n\tMaterializeResult,\n\tMaterializerInterface,\n\tRepository,\n\tUpstreamOptions,\n} from '@src/server'\nimport type {\n\tAuditCommand,\n\tCatalogCommand,\n\tCatalogResult,\n\tCLICommand,\n\tCLIInterface,\n\tCLIOptions,\n\tNewCommand,\n\tOutputHandler,\n\tOverwriteCommand,\n\tOverwriteResult,\n\tRepairCommand,\n\tRepairResult,\n} from './types.js'\nimport { execFileSync } from 'node:child_process'\nimport { renderTable, strip, stripControls } from '@orkestrel/console'\nimport { attempt, isRecord, isString, parseJSON } from '@orkestrel/contract'\nimport { createMarkdown, flattenText, isTableNode } from '@orkestrel/markdown'\nimport {\n\tCATALOG_AGENT_PATH,\n\tBIN_ENTRY_PATH,\n\tblueprintToRootVite,\n\tcreateBlueprint,\n\tcreateCompiler,\n\tDEPENDENCY_NAME_PATTERN,\n\tENVIRONMENTS,\n\tGROUPS,\n\tGLOBAL_SETUP_PATH,\n\tGUIDES_TEST_PATH,\n\tINTEGRATION_TEST_PATH,\n\tmanifestToDependencies,\n\tmanifestToName,\n\tMAX_MANIFEST_BYTES,\n\tnameToGuide,\n\tScaffoldError,\n\tSHOWCASE_CONFIG_PATH,\n} from '@src/core'\nimport {\n\tcreateMaterializer,\n\tcreateUpstream,\n\tisExactCaseFile,\n\tisPhysicalDirectory,\n\tisRepository,\n\treadFileText,\n\treadSnapshot,\n\tresolveContainedPath,\n} from '@src/server'\nimport { EXIT_CLEAN, EXIT_DRIFT, EXIT_USAGE } from './constants.js'\nimport { isUsageError, UsageError } from './errors.js'\nimport { argvToCommand, auditToExit, errorToEnvelope, renderUsage } from './helpers.js'\n\n/**\n * The executable: one command line in, one exit code out.\n *\n * @remarks\n * Every destination this class writes to is a handler it was given, and the run\n * ends by returning its code rather than by setting one, so the whole executable\n * is drivable from inside another process. That is what makes proving what a\n * command prints cost a function call: `src/bin/main.ts` is the only module\n * that reads `process.argv` or assigns `process.exitCode`.\n *\n * Every line leaving here is stripped of ANSI escapes and control characters\n * once, on the way out, because a refusal quotes the argument that caused it and\n * that argument came from an untrusted command line. The machine-readable path\n * needs no second pass: `JSON.stringify` escapes a control character into text\n * before it reaches the handler.\n *\n * The collaborators are constructed per run rather than received, because\n * `--from` decides the vendored root the materializer reads and an instance\n * handed in before the command line was parsed could not honour it. The\n * upstream reader is built the same way but from the options, because no\n * command line names an endpoint: a terminal caller means the published\n * registry and the published guide host, and only the process driving the\n * executable can mean anything else. That is the seam that makes the three\n * verbs which read the network provable without one.\n *\n * @example\n * ```ts\n * import { CLI } from './CLI.js'\n *\n * const lines: string[] = []\n * const code = await new CLI({ output: (line) => lines.push(line) }).execute(['--help'])\n * code // 0\n * ```\n */\nexport class CLI implements CLIInterface {\n\t// The two destinations a terminal caller means. They are the only process\n\t// streams this class names, and it names them once: a handler is what every\n\t// write goes through, so the default is a handler too rather than a branch at\n\t// each write site.\n\tstatic readonly #stdout: OutputHandler = (line) => void process.stdout.write(`${line}\\n`)\n\tstatic readonly #stderr: OutputHandler = (line) => void process.stderr.write(`${line}\\n`)\n\treadonly #output: OutputHandler\n\treadonly #diagnostic: OutputHandler\n\t// What every upstream reader this class builds is constructed from. It is held\n\t// once and read by each verb that reads the network, so the three of them\n\t// cannot disagree about which registry and which guide host a run addresses.\n\treadonly #upstream: UpstreamOptions | undefined\n\n\t/**\n\t * Construct the executable over the two destinations it writes to.\n\t *\n\t * @param options - The report and diagnostic handlers and the upstream\n\t * endpoints; the process streams and the published endpoints when absent.\n\t */\n\tconstructor(options?: CLIOptions) {\n\t\tthis.#output = options?.output ?? CLI.#stdout\n\t\tthis.#diagnostic = options?.diagnostic ?? CLI.#stderr\n\t\tthis.#upstream = options?.upstream\n\t}\n\n\t/**\n\t * Run one command line to completion and report through the configured output.\n\t *\n\t * @param argv - The arguments following the executable's own name.\n\t * @returns The exit code: `0` clean, `1` drift or failure, `2` a usage error.\n\t *\n\t * @remarks\n\t * A request for usage is answered before anything is parsed, because it\n\t * replaces the run rather than modifying it, and because `--help` is not an\n\t * option any verb takes. Everything after that is one command: read it,\n\t * dispatch it, render what it produced, and answer with the code it earned.\n\t *\n\t * @example\n\t * ```ts\n\t * import { CLI } from './CLI.js'\n\t *\n\t * await new CLI().execute(['audit', '--json']) // 0 when the target matches its plan\n\t * ```\n\t */\n\tasync execute(argv: readonly string[]): Promise<number> {\n\t\tif (argv.includes('--help')) {\n\t\t\tfor (const line of renderUsage()) this.#say(line)\n\t\t\treturn EXIT_CLEAN\n\t\t}\n\t\tconst read = attempt(() => argvToCommand(argv))\n\t\t// A command line that never became a command carries no `--json`, so the\n\t\t// refusal is prose: there is no machine-readable value for it to pollute.\n\t\tif (!read.success) return this.#refuse(read.error, false)\n\t\tconst command = read.value\n\t\ttry {\n\t\t\treturn await this.#dispatch(command)\n\t\t} catch (error) {\n\t\t\treturn this.#refuse(error, command.json === true)\n\t\t}\n\t}\n\n\t// One verb per branch, each answering with its own exit code. The switch is\n\t// exhaustive over the command union, so a new verb fails to compile here.\n\tasync #dispatch(command: CLICommand): Promise<number> {\n\t\tswitch (command.verb) {\n\t\t\tcase 'new':\n\t\t\t\treturn this.#create(command)\n\t\t\tcase 'audit':\n\t\t\t\treturn this.#inspect(command)\n\t\t\tcase 'repair':\n\t\t\t\treturn this.#restore(command)\n\t\t\tcase 'catalog':\n\t\t\t\treturn this.#refresh(command)\n\t\t\tcase 'overwrite':\n\t\t\t\treturn this.#replace(command)\n\t\t}\n\t}\n\n\t// `new` — resolve the declared dependencies against the registry, compile the\n\t// blueprint the command line describes, and write it into a vacant target.\n\tasync #create(command: NewCommand): Promise<number> {\n\t\tconst target = command.target ?? command.name\n\t\tconst blueprint = createBlueprint(command.name, {\n\t\t\tsrc: this.#environments(command.src, 'src'),\n\t\t\tapp: this.#environments(command.app, 'app'),\n\t\t\tbin: command.bin === true,\n\t\t\tdependencies: await this.#resolve(this.#packages(command.dependencies)),\n\t\t})\n\t\tconst plan = this.#compile(blueprint)\n\t\tconst materializer = createMaterializer(\n\t\t\tcommand.from === undefined ? undefined : { host: command.from },\n\t\t)\n\t\ttry {\n\t\t\tconst result = materializer.materialize(plan, target)\n\t\t\tif (command.json === true) this.#report(result)\n\t\t\telse {\n\t\t\t\tthis.#say(`Scaffolded ${blueprint.name} into ${result.target}.`)\n\t\t\t\tthis.#say(this.#tally(result))\n\t\t\t}\n\t\t\treturn EXIT_CLEAN\n\t\t} finally {\n\t\t\tmaterializer.destroy()\n\t\t}\n\t}\n\n\t// `audit` — compare a target to the plan its own manifest and directories\n\t// describe, through the vendored host a repair would write from, and write\n\t// nothing whatever it finds.\n\t//\n\t// The host is load-bearing here where it once was not, so `--from` reaches the\n\t// comparison and a host that cannot be read refuses the run under its own\n\t// coded reason. Refusing is the honest answer: the comparison this verb\n\t// reports is the hydrated one, and a fallback to the pure compile would report\n\t// `aligned` for exactly the files whose bytes it failed to read.\n\t#inspect(command: AuditCommand): number {\n\t\tconst target = command.target ?? '.'\n\t\tconst blueprint = this.#derive(target)\n\t\tconst question = this.#projectQuestion(target, blueprint)\n\t\tconst materializer = createMaterializer(\n\t\t\tcommand.from === undefined ? undefined : { host: command.from },\n\t\t)\n\t\ttry {\n\t\t\tconst [measured] = this.#survey(materializer, blueprint, target, this.#groups(command.groups))\n\t\t\tconst audit: Audit =\n\t\t\t\tquestion === undefined\n\t\t\t\t\t? measured\n\t\t\t\t\t: { ...measured, questions: [...measured.questions, question] }\n\t\t\tif (command.json === true) this.#report(audit)\n\t\t\telse this.#present(audit)\n\t\t\treturn auditToExit(audit)\n\t\t} finally {\n\t\t\tmaterializer.destroy()\n\t\t}\n\t}\n\n\t// `repair` — write each planned path the target is missing or has let drift,\n\t// then re-audit, because the audit a repair reports is the one taken after it.\n\t// One materializer spans the whole verb: the audit that guides the write, the\n\t// write, and the audit that answers for it are three readings of one vendored\n\t// host, and a second instance could not promise they were.\n\t#restore(command: RepairCommand): number {\n\t\tconst target = command.target ?? '.'\n\t\tconst groups = this.#groups(command.groups)\n\t\tconst blueprint = this.#derive(target)\n\t\tthis.#assertProjects(target, blueprint)\n\t\tconst materializer = createMaterializer(\n\t\t\tcommand.from === undefined ? undefined : { host: command.from },\n\t\t)\n\t\ttry {\n\t\t\tconst [audit, plan] = this.#survey(materializer, blueprint, target, groups)\n\t\t\tif (plan === undefined) {\n\t\t\t\tif (command.json === true) this.#report(audit)\n\t\t\t\telse this.#present(audit)\n\t\t\t\treturn EXIT_DRIFT\n\t\t\t}\n\t\t\tconst result = materializer.repair(plan, audit, target)\n\t\t\tconst [terminal] = this.#survey(materializer, blueprint, target, groups)\n\t\t\tconst outcome: RepairResult = { ...result, audit: terminal }\n\t\t\tif (command.json === true) this.#report(outcome)\n\t\t\telse {\n\t\t\t\tthis.#present(terminal)\n\t\t\t\tthis.#say(this.#tally(result))\n\t\t\t}\n\t\t\treturn auditToExit(terminal)\n\t\t} finally {\n\t\t\tmaterializer.destroy()\n\t\t}\n\t}\n\n\t// `catalog` — regenerate the package table from the organization's published\n\t// list and refresh the guide mirrors the target draws on.\n\tasync #refresh(command: CatalogCommand): Promise<number> {\n\t\tconst target = command.target ?? '.'\n\t\tconst [host, ...extra] = command.from ?? []\n\t\tif (extra.length > 0) {\n\t\t\tthis.#warn(\n\t\t\t\t`Read the data root from ${String(host)}. The other ${String(extra.length)} local root${extra.length === 1 ? '' : 's'} named by --from reach nothing this run does.`,\n\t\t\t)\n\t\t}\n\t\tconst previous = this.#previous(target)\n\t\tconst fetched = await this.#fetch(target, command.all === true)\n\t\tconst materializer = createMaterializer(host === undefined ? undefined : { host })\n\t\tlet result: MaterializeResult\n\t\ttry {\n\t\t\tresult = this.#publish(materializer, target, fetched.entries, fetched.mirrors)\n\t\t} finally {\n\t\t\tmaterializer.destroy()\n\t\t}\n\t\tconst outcome: CatalogResult = {\n\t\t\t...result,\n\t\t\tentries: fetched.entries,\n\t\t\tmirrors: fetched.mirrors,\n\t\t\tdropped: previous.filter((name) => !fetched.entries.some((entry) => entry.name === name)),\n\t\t}\n\t\tif (command.json === true) this.#report(outcome)\n\t\telse this.#recount(outcome)\n\t\treturn fetched.mirrors.some((mirror) => mirror.lookup === 'failed') ? EXIT_DRIFT : EXIT_CLEAN\n\t}\n\n\t// `overwrite` — everything repair and catalog do, plus the two steps only this\n\t// verb carries. The offline half runs first and persists whatever it did,\n\t// because it is the destructive one: a run that cannot reach upstream still\n\t// leaves the target repaired and says which step it could not complete.\n\tasync #replace(command: OverwriteCommand): Promise<number> {\n\t\tconst target = command.target ?? '.'\n\t\tconst groups = this.#groups(command.groups)\n\t\tconst blueprint = this.#derive(target)\n\t\tthis.#assertProjects(target, blueprint)\n\t\tconst repository = this.#repository(target)\n\t\tif (repository.dirty.length > 0 && command.dirty !== true) {\n\t\t\tthrow new ScaffoldError(\n\t\t\t\t'TARGET',\n\t\t\t\t`The target at ${target} carries ${String(repository.dirty.length)} uncommitted change${repository.dirty.length === 1 ? '' : 's'}. Commit them, or pass --dirty to waive the refusal.`,\n\t\t\t\t{ target, dirty: repository.dirty.length },\n\t\t\t)\n\t\t}\n\t\tconst materializer = createMaterializer(\n\t\t\tcommand.from === undefined ? undefined : { host: command.from },\n\t\t)\n\t\ttry {\n\t\t\tconst [audit, plan] = this.#survey(materializer, blueprint, target, groups)\n\t\t\tif (plan === undefined) {\n\t\t\t\tif (command.json === true) this.#report(audit)\n\t\t\t\telse this.#present(audit)\n\t\t\t\treturn EXIT_DRIFT\n\t\t\t}\n\t\t\tconst repaired = materializer.repair(plan, audit, target)\n\t\t\t// The candidate set is the audit's own foreign findings, so a path the\n\t\t\t// plan claims is never a deletion candidate whatever the tree holds, and\n\t\t\t// neither is a path outside the vendored directories this plan expands.\n\t\t\t// `--dirty` is expressed here and nowhere else: the waiver clears the\n\t\t\t// refusal the observed dirty set would otherwise trigger downstream, and\n\t\t\t// waives nothing about which paths are eligible.\n\t\t\tconst removed = materializer.remove(\n\t\t\t\taudit,\n\t\t\t\tcommand.dirty === true ? { tracked: repository.tracked, dirty: [] } : repository,\n\t\t\t\ttarget,\n\t\t\t)\n\t\t\tconst offline = this.#merge(repaired, removed)\n\t\t\tconst online = await this.#reconcile(materializer, target, blueprint.dependencies)\n\t\t\tconst [terminal] = this.#survey(materializer, blueprint, target, groups)\n\t\t\tconst outcome: OverwriteResult = {\n\t\t\t\t...online,\n\t\t\t\t...this.#merge(offline, online),\n\t\t\t\taudit: terminal,\n\t\t\t}\n\t\t\tif (command.json === true) this.#report(outcome)\n\t\t\telse {\n\t\t\t\tthis.#present(terminal)\n\t\t\t\tthis.#recount(outcome)\n\t\t\t\tif (online.note !== undefined) this.#warn(online.note)\n\t\t\t}\n\t\t\tif (online.note !== undefined) return EXIT_DRIFT\n\t\t\treturn auditToExit(terminal)\n\t\t} finally {\n\t\t\tmaterializer.destroy()\n\t\t}\n\t}\n\n\t// The network half of `overwrite`, collected rather than thrown: the offline\n\t// half has already written, so a step that cannot complete is reported as the\n\t// step it was instead of discarding what already landed. It writes through the\n\t// verb's own materializer rather than opening a second one, so every byte the\n\t// run lands comes from the host the caller named once.\n\tasync #reconcile(\n\t\tmaterializer: MaterializerInterface,\n\t\ttarget: string,\n\t\tdeclared: readonly Dependency[],\n\t): Promise<Omit<OverwriteResult, 'audit'>> {\n\t\tconst previous = this.#previous(target)\n\t\ttry {\n\t\t\tconst releases = await this.#lookup(declared)\n\t\t\tconst fetched = await this.#fetch(target, false)\n\t\t\tconst written = this.#merge(\n\t\t\t\tthis.#publish(materializer, target, fetched.entries, fetched.mirrors),\n\t\t\t\tmaterializer.declare(this.#pin(releases), target),\n\t\t\t)\n\t\t\treturn {\n\t\t\t\t...written,\n\t\t\t\tentries: fetched.entries,\n\t\t\t\tmirrors: fetched.mirrors,\n\t\t\t\tdropped: previous.filter((name) => !fetched.entries.some((entry) => entry.name === name)),\n\t\t\t\treleases,\n\t\t\t}\n\t\t} catch (error) {\n\t\t\treturn {\n\t\t\t\ttarget,\n\t\t\t\twritten: [],\n\t\t\t\tskipped: [],\n\t\t\t\tremoved: [],\n\t\t\t\tentries: [],\n\t\t\t\tmirrors: [],\n\t\t\t\tdropped: [],\n\t\t\t\treleases: [],\n\t\t\t\tnote: `The catalog step did not complete: ${errorToEnvelope(error).error.message}`,\n\t\t\t}\n\t\t}\n\t}\n\n\t// Measure each declared range against the registry's latest release.\n\tasync #lookup(declared: readonly Dependency[]): Promise<readonly Release[]> {\n\t\tconst upstream = createUpstream(this.#upstream)\n\t\ttry {\n\t\t\treturn await upstream.lookup(declared)\n\t\t} finally {\n\t\t\tupstream.destroy()\n\t\t}\n\t}\n\n\t// Read the organization's published list and the guides the target draws on.\n\t// The workspace never fetches its own guide: that file is its own product.\n\tasync #fetch(\n\t\ttarget: string,\n\t\tall: boolean,\n\t): Promise<{ readonly entries: readonly CatalogEntry[]; readonly mirrors: readonly Mirror[] }> {\n\t\tconst manifest = this.#manifest(target)\n\t\tconst own = manifestToName(manifest)\n\t\tconst declared = manifestToDependencies(manifest).map((dependency) => dependency.name)\n\t\tconst upstream = createUpstream(this.#upstream)\n\t\ttry {\n\t\t\tconst entries = await upstream.catalog()\n\t\t\tconst names = (all ? entries.map((entry) => entry.name) : declared).filter(\n\t\t\t\t(name) => name !== own,\n\t\t\t)\n\t\t\tconst mirrors = await upstream.fetch(names, readSnapshot(target, names.map(nameToGuide)))\n\t\t\treturn { entries, mirrors }\n\t\t} finally {\n\t\t\tupstream.destroy()\n\t\t}\n\t}\n\n\t// Write the fetched guides to their mirrors and the published list to the\n\t// marker-bounded table, as one result.\n\t#publish(\n\t\tmaterializer: MaterializerInterface,\n\t\ttarget: string,\n\t\tentries: readonly CatalogEntry[],\n\t\tmirrors: readonly Mirror[],\n\t): MaterializeResult {\n\t\treturn this.#merge(materializer.mirror(mirrors, target), materializer.catalog(entries, target))\n\t}\n\n\t// The ranges a found release pins. A lookup that produced no answer names no\n\t// version, so it is left declared as it stands rather than rewritten to a\n\t// guess.\n\t#pin(releases: readonly Release[]): readonly Dependency[] {\n\t\tconst pinned: Dependency[] = []\n\t\tfor (const release of releases) {\n\t\t\tif (release.lookup === 'found')\n\t\t\t\tpinned.push({ name: release.name, range: `^${release.latest}` })\n\t\t}\n\t\treturn pinned\n\t}\n\n\t// Compile a blueprint into the plan it describes, or refuse with the questions\n\t// that closed the gate.\n\t#compile(blueprint: Blueprint, groups?: readonly Group[]): Plan {\n\t\tconst compiler = createCompiler()\n\t\ttry {\n\t\t\tconst scaffolding = compiler.compile(blueprint, groups)\n\t\t\tif (scaffolding.plan !== undefined) return scaffolding.plan\n\t\t\tthrow new ScaffoldError(\n\t\t\t\t'BLOCKED',\n\t\t\t\tscaffolding.questions\n\t\t\t\t\t.filter((question) => question.blocking)\n\t\t\t\t\t.map((question) => `${question.field}: ${question.message}`)\n\t\t\t\t\t.join(' '),\n\t\t\t\t{ questions: scaffolding.questions.length },\n\t\t\t)\n\t\t} finally {\n\t\t\tcompiler.destroy()\n\t\t}\n\t}\n\n\t// Compile a blueprint and compare its plan to what the target currently holds,\n\t// through the vendored host a write would draw on.\n\t//\n\t// The materializer owns the comparison because it is the only one that can\n\t// make it: the pure compile claims presence alone, so it reads a canon file a\n\t// consumer has edited as aligned and a vendored directory as one missing path\n\t// no write could ever satisfy. Hydrating first states the bytes and expands\n\t// the directory into the files the host actually stores, which is the same\n\t// derivation the repair that follows is held to.\n\t//\n\t// The compiler answers the refused case alone. A blueprint the gate closed\n\t// carries no plan, so there is nothing to hydrate and nothing to say about the\n\t// target; the audit carries the questions instead.\n\t#survey(\n\t\tmaterializer: MaterializerInterface,\n\t\tblueprint: Blueprint,\n\t\ttarget: string,\n\t\tgroups?: readonly Group[],\n\t): readonly [audit: Audit, plan: Plan | undefined] {\n\t\tconst compiler = createCompiler()\n\t\ttry {\n\t\t\tconst scaffolding = compiler.compile(blueprint, groups)\n\t\t\tif (scaffolding.plan === undefined) return [compiler.audit(blueprint, {}, groups), undefined]\n\t\t\treturn [materializer.audit(scaffolding.plan, target), scaffolding.plan]\n\t\t} finally {\n\t\t\tcompiler.destroy()\n\t\t}\n\t}\n\n\t// The blueprint a target describes about itself: manifest identity and fleet\n\t// packages, environment directories, and exact structural files. Services stay\n\t// unknown because their birth-owned script is not a declaration of its list.\n\t#derive(target: string): Blueprint {\n\t\tconst manifest = this.#manifest(target)\n\t\tconst declared = manifestToName(manifest)\n\t\tif (declared === undefined) {\n\t\t\tthrow new ScaffoldError('TARGET', `The manifest at ${target} declares no package name.`, {\n\t\t\t\ttarget,\n\t\t\t})\n\t\t}\n\t\tconst bin = resolveContainedPath(target, BIN_ENTRY_PATH)\n\t\tconst integration = resolveContainedPath(target, INTEGRATION_TEST_PATH)\n\t\tconst global = resolveContainedPath(target, GLOBAL_SETUP_PATH)\n\t\tconst showcase = resolveContainedPath(target, SHOWCASE_CONFIG_PATH)\n\t\treturn createBlueprint(declared.slice(declared.lastIndexOf('/') + 1), {\n\t\t\tsrc: this.#probe(target, 'src'),\n\t\t\tapp: this.#probe(target, 'app'),\n\t\t\tdependencies: manifestToDependencies(manifest),\n\t\t\tbin: bin !== undefined && isExactCaseFile(bin),\n\t\t\tintegration: integration !== undefined && isExactCaseFile(integration),\n\t\t\tglobal: global !== undefined && isExactCaseFile(global),\n\t\t\tshowcase: showcase !== undefined && isExactCaseFile(showcase),\n\t\t})\n\t}\n\n\t// Read literal Vitest project values from one shell command. Quotes group a\n\t// token but do not hide the option, while shell expansions make its value\n\t// unresolved and therefore refuse the write that asked the question.\n\t#scriptProjects(script: string): readonly string[] | undefined {\n\t\tconst tokens: Array<{ value: string; resolved: boolean }> = []\n\t\tlet value = ''\n\t\tlet resolved = true\n\t\tlet started = false\n\t\tlet quote: string | undefined\n\t\tfor (let index = 0; index < script.length; index += 1) {\n\t\t\tconst character = script[index]\n\t\t\tif (character === undefined) return undefined\n\t\t\tif (quote === undefined) {\n\t\t\t\tif (/\\s/.test(character)) {\n\t\t\t\t\tif (started) tokens.push({ value, resolved })\n\t\t\t\t\tvalue = ''\n\t\t\t\t\tresolved = true\n\t\t\t\t\tstarted = false\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (';&|()'.includes(character)) {\n\t\t\t\t\tif (started) tokens.push({ value, resolved })\n\t\t\t\t\tconst paired = script[index + 1] === character && (character === '&' || character === '|')\n\t\t\t\t\ttokens.push({ value: paired ? `${character}${character}` : character, resolved: true })\n\t\t\t\t\tvalue = ''\n\t\t\t\t\tresolved = true\n\t\t\t\t\tstarted = false\n\t\t\t\t\tif (paired) index += 1\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (character === '\"' || character === \"'\") {\n\t\t\t\t\tquote = character\n\t\t\t\t\tstarted = true\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (character === '\\\\') {\n\t\t\t\t\tconst escaped = script[index + 1]\n\t\t\t\t\tif (escaped === undefined) return undefined\n\t\t\t\t\tvalue += escaped\n\t\t\t\t\tstarted = true\n\t\t\t\t\tindex += 1\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (character === '$' || character === '`' || character === '%') resolved = false\n\t\t\t\tvalue += character\n\t\t\t\tstarted = true\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (character === quote) {\n\t\t\t\tquote = undefined\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (character === '\\\\' && quote === '\"') {\n\t\t\t\tconst escaped = script[index + 1]\n\t\t\t\tif (escaped === undefined) return undefined\n\t\t\t\tvalue += escaped\n\t\t\t\tindex += 1\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (quote === '\"' && (character === '$' || character === '`' || character === '%')) {\n\t\t\t\tresolved = false\n\t\t\t}\n\t\t\tvalue += character\n\t\t\tstarted = true\n\t\t}\n\t\tif (quote !== undefined) return undefined\n\t\tif (started) tokens.push({ value, resolved })\n\n\t\tconst projects: string[] = []\n\t\tfor (let index = 0; index < tokens.length; index += 1) {\n\t\t\tconst token = tokens[index]\n\t\t\tif (token === undefined) return undefined\n\t\t\tif (token.value === '--project') {\n\t\t\t\tconst project = tokens[index + 1]\n\t\t\t\tif (\n\t\t\t\t\tproject === undefined ||\n\t\t\t\t\t!project.resolved ||\n\t\t\t\t\tproject.value.length === 0 ||\n\t\t\t\t\t['&&', '||', ';', '|', '&', '(', ')'].includes(project.value)\n\t\t\t\t)\n\t\t\t\t\treturn undefined\n\t\t\t\tprojects.push(project.value)\n\t\t\t\tindex += 1\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (token.value.startsWith('--project=')) {\n\t\t\t\tconst project = token.value.slice('--project='.length)\n\t\t\t\tif (!token.resolved || project.length === 0) return undefined\n\t\t\t\tprojects.push(project)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!token.resolved && token.value.includes('--project')) return undefined\n\t\t}\n\t\treturn projects\n\t}\n\n\t// Report the manifest's Vitest calls that the planned root configuration\n\t// cannot register. Audit carries the advisory; writing verbs turn it into the\n\t// hard boundary that keeps a birth-owned script from pointing at a project\n\t// their content-owned configuration removed.\n\t#projectQuestion(target: string, blueprint: Blueprint, writing = false): Question | undefined {\n\t\tconst manifest = this.#manifest(target)\n\t\tconst guides = resolveContainedPath(target, GUIDES_TEST_PATH)\n\t\tconst planned = blueprintToRootVite(blueprint)\n\t\tconst parsed = parseJSON(manifest)\n\t\tconst scripts = isRecord(parsed) && isRecord(parsed.scripts) ? parsed.scripts : undefined\n\t\tconst absent = new Set<string>()\n\t\tlet unresolved = false\n\t\tif (scripts !== undefined) {\n\t\t\tfor (const script of Object.values(scripts)) {\n\t\t\t\tif (!isString(script) || !script.includes('vitest')) continue\n\t\t\t\tconst projects = this.#scriptProjects(script)\n\t\t\t\tif (projects === undefined) {\n\t\t\t\t\tunresolved = true\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfor (const project of projects) {\n\t\t\t\t\tconst guide = project === 'guides' && guides !== undefined && isExactCaseFile(guides)\n\t\t\t\t\tif (\n\t\t\t\t\t\t!planned.includes(`name: { label: '${project}',`) ||\n\t\t\t\t\t\t(project === 'guides' && !guide)\n\t\t\t\t\t) {\n\t\t\t\t\t\tabsent.add(project)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (absent.size === 0 && !unresolved) return undefined\n\t\tconst projects = [...absent].sort()\n\t\tif (unresolved) {\n\t\t\treturn {\n\t\t\t\tfield: 'projects',\n\t\t\t\tmessage: `The manifest at ${target} contains a Vitest project expression that cannot be resolved statically.${projects.length === 0 ? '' : ` It also names projects the planned configuration does not register: ${projects.join(', ')}.`} ${writing ? 'Replace it with a literal --project value or remove the script before using a scaffold writing verb.' : 'Replace it with a literal --project value before relying on the planned configuration.'}`,\n\t\t\t\tblocking: false,\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tfield: 'projects',\n\t\t\tmessage: writing\n\t\t\t\t? `The manifest at ${target} names ${projects.length === 1 ? 'a Vitest project' : 'Vitest projects'} the planned configuration does not register: ${projects.join(', ')}. To continue, remove the ${projects.length === 1 ? 'script that names it' : 'scripts that name them'} or do not use scaffold writing verbs on a workspace that needs ${projects.length === 1 ? 'a custom Vitest project' : 'custom Vitest projects'}.`\n\t\t\t\t: `The manifest at ${target} names ${projects.length === 1 ? 'a Vitest project' : 'Vitest projects'} the planned configuration does not register: ${projects.join(', ')}. Add ${projects.length === 1 ? 'the project' : 'each project'} to vite.config.ts or remove the ${projects.length === 1 ? 'script that names it' : 'scripts that name them'}.`,\n\t\t\tblocking: false,\n\t\t}\n\t}\n\n\t// Writing verbs refuse the advisory because their next step would replace the\n\t// configuration. Audit alone may report it without changing the target.\n\t#assertProjects(target: string, blueprint: Blueprint): void {\n\t\tconst question = this.#projectQuestion(target, blueprint, true)\n\t\tif (question === undefined) return\n\t\tthrow new ScaffoldError('TARGET', question.message, { target })\n\t}\n\n\t// A target's manifest text, which every reading verb needs before it can say\n\t// anything about the target at all.\n\t#manifest(target: string): string {\n\t\tconst manifest = readFileText(target, 'package.json', MAX_MANIFEST_BYTES)\n\t\tif (manifest === undefined) {\n\t\t\tthrow new ScaffoldError('TARGET', `The target at ${target} carries no readable manifest.`, {\n\t\t\t\ttarget,\n\t\t\t})\n\t\t}\n\t\treturn manifest\n\t}\n\n\t// The environments one axis physically ships, read as directories rather than\n\t// declared, because a directory is the fact and a declaration would be a\n\t// second copy of it free to disagree.\n\t#probe(target: string, axis: string): readonly Environment[] {\n\t\treturn ENVIRONMENTS.filter((environment) => {\n\t\t\tconst full = resolveContainedPath(target, `${axis}/${environment}`)\n\t\t\treturn full !== undefined && isPhysicalDirectory(full)\n\t\t})\n\t}\n\n\t// The packages the target's catalog table listed before this run. Read through\n\t// the declared markdown parser rather than by pattern, so a row is a row\n\t// because the document says so.\n\t#previous(target: string): readonly string[] {\n\t\tconst text = readFileText(target, CATALOG_AGENT_PATH)\n\t\tif (text === undefined) return []\n\t\tconst names: string[] = []\n\t\tfor (const table of createMarkdown(text).filter(isTableNode)) {\n\t\t\tfor (const row of table.rows) {\n\t\t\t\tconst [cell] = row\n\t\t\t\tif (cell === undefined) continue\n\t\t\t\tconst name = cell.map(flattenText).join('').trim()\n\t\t\t\tif (DEPENDENCY_NAME_PATTERN.test(name)) names.push(name)\n\t\t\t}\n\t\t}\n\t\treturn names\n\t}\n\n\t// What git reports about the target's working tree. Deletion draws only on\n\t// what git tracks and refuses a tree carrying uncommitted work, so a target\n\t// that is not a repository has no recovery mechanism and is refused here.\n\t#repository(target: string): Repository {\n\t\tconst tracked = this.#inventory(target, ['ls-files', '-z'])\n\t\tconst dirty = this.#inventory(target, [\n\t\t\t'status',\n\t\t\t'--porcelain=v1',\n\t\t\t'--untracked-files=all',\n\t\t\t'-z',\n\t\t]).map((record) => (record.length > 3 && record[2] === ' ' ? record.slice(3) : record))\n\t\tconst state = { tracked, dirty }\n\t\tif (!isRepository(state)) {\n\t\t\tthrow new ScaffoldError('TARGET', `The git state at ${target} is not a readable inventory.`, {\n\t\t\t\ttarget,\n\t\t\t\ttracked: tracked.length,\n\t\t\t\tdirty: dirty.length,\n\t\t\t})\n\t\t}\n\t\treturn state\n\t}\n\n\t// One git query, answered as its NUL-separated records. Git is asked rather\n\t// than reimplemented, because the tracked set and the dirty set are git's own\n\t// answers and nothing else can give them.\n\t#inventory(target: string, args: readonly string[]): readonly string[] {\n\t\tconst read = attempt(() =>\n\t\t\texecFileSync('git', [...args], {\n\t\t\t\tcwd: target,\n\t\t\t\tencoding: 'utf8',\n\t\t\t\twindowsHide: true,\n\t\t\t\tmaxBuffer: MAX_MANIFEST_BYTES,\n\t\t\t\t// git writes its own refusal to its own stderr, and this class owns\n\t\t\t\t// what leaves it: a failure is reported through the diagnostic handler\n\t\t\t\t// the caller supplied, never straight onto a stream nobody chose.\n\t\t\t\tstdio: ['ignore', 'pipe', 'ignore'],\n\t\t\t}),\n\t\t)\n\t\tif (!read.success) {\n\t\t\tthrow new ScaffoldError('TARGET', `The target at ${target} is not a git repository.`, {\n\t\t\t\ttarget,\n\t\t\t})\n\t\t}\n\t\treturn read.value.split('\\0').filter((record) => record.length > 0)\n\t}\n\n\t// The environments a comma-separated selection names, refused by name when it\n\t// names something that is not one.\n\t#environments(selection: string | undefined, axis: string): readonly Environment[] {\n\t\tif (selection === undefined) return []\n\t\tconst requested = selection.split(',')\n\t\tconst refused = requested.filter(\n\t\t\t(name) => !ENVIRONMENTS.some((environment) => environment === name),\n\t\t)\n\t\tif (refused.length > 0) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`'--${axis}' does not take ${refused.join(', ')}. It takes ${ENVIRONMENTS.join(', ')}.`,\n\t\t\t)\n\t\t}\n\t\treturn ENVIRONMENTS.filter((environment) => requested.includes(environment))\n\t}\n\n\t// The groups a comma-separated selection names; absence covers every group.\n\t#groups(selection: string | undefined): readonly Group[] | undefined {\n\t\tif (selection === undefined) return undefined\n\t\tconst requested = selection.split(',')\n\t\tconst refused = requested.filter((name) => !GROUPS.some((group) => group === name))\n\t\tif (refused.length > 0) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`'--groups' does not take ${refused.join(', ')}. It takes ${GROUPS.join(', ')}.`,\n\t\t\t)\n\t\t}\n\t\treturn GROUPS.filter((group) => requested.includes(group))\n\t}\n\n\t// The fleet packages a comma-separated selection names.\n\t#packages(selection: string | undefined): readonly string[] {\n\t\tif (selection === undefined) return []\n\t\tconst requested = selection.split(',')\n\t\tconst refused = requested.filter((name) => !DEPENDENCY_NAME_PATTERN.test(name))\n\t\tif (refused.length > 0) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`'--deps' does not take ${refused.join(', ')}. Every name is a published @orkestrel package.`,\n\t\t\t)\n\t\t}\n\t\treturn requested\n\t}\n\n\t// Pin each named package to the registry's latest release. A name upstream\n\t// cannot answer for is refused rather than pinned to an invented range: the\n\t// workspace would carry a dependency that does not resolve.\n\tasync #resolve(names: readonly string[]): Promise<readonly Dependency[]> {\n\t\tif (names.length === 0) return []\n\t\tconst upstream = createUpstream(this.#upstream)\n\t\tlet releases: readonly Release[]\n\t\ttry {\n\t\t\treleases = await upstream.lookup(names.map((name) => ({ name, range: '*' })))\n\t\t} finally {\n\t\t\tupstream.destroy()\n\t\t}\n\t\tconst refused = releases.filter((release) => release.lookup !== 'found')\n\t\tif (refused.length > 0) {\n\t\t\tthrow new ScaffoldError(\n\t\t\t\t'FETCH',\n\t\t\t\t`The registry named no release for ${refused.map((release) => release.name).join(', ')}.`,\n\t\t\t\t{ names: refused.length },\n\t\t\t)\n\t\t}\n\t\treturn this.#pin(releases)\n\t}\n\n\t// Two results of one run, read as one. Written and skipped never overlap\n\t// across the calls a verb makes, because each call answers for its own paths.\n\t#merge(first: MaterializeResult, second: MaterializeResult): MaterializeResult {\n\t\treturn {\n\t\t\ttarget: first.target,\n\t\t\twritten: [...first.written, ...second.written],\n\t\t\tskipped: [...first.skipped, ...second.skipped],\n\t\t\tremoved: [...first.removed, ...second.removed],\n\t\t}\n\t}\n\n\t// The audit as a person reads it: every advisory first, then one row per path\n\t// that differs, then the count. An aligned path is not listed, because a\n\t// report of everything that is fine is a report nobody reads.\n\t#present(audit: Audit): void {\n\t\tfor (const question of audit.questions) this.#warn(`${question.field}: ${question.message}`)\n\t\tconst rows = audit.findings\n\t\t\t.filter((finding) => finding.drift !== 'aligned')\n\t\t\t.map((finding) => [finding.path, finding.group, finding.drift])\n\t\tif (rows.length > 0) {\n\t\t\tconst table = renderTable({\n\t\t\t\tcolumns: [{ label: 'path' }, { label: 'group' }, { label: 'drift' }],\n\t\t\t\trows,\n\t\t\t})\n\t\t\tfor (const line of table.split('\\n')) this.#say(line)\n\t\t}\n\t\tthis.#say(\n\t\t\t`${String(rows.length)} of ${String(audit.findings.length)} planned path${audit.findings.length === 1 ? '' : 's'} differ from the plan.`,\n\t\t)\n\t}\n\n\t// The catalog outcome as a person reads it.\n\t#recount(result: CatalogResult): void {\n\t\tthis.#say(this.#tally(result))\n\t\tthis.#say(\n\t\t\t`${String(result.entries.length)} published, ${String(result.mirrors.filter((mirror) => mirror.lookup === 'found').length)} guide${result.mirrors.length === 1 ? '' : 's'} fetched, ${String(result.dropped.length)} no longer listed.`,\n\t\t)\n\t\tfor (const mirror of result.mirrors) {\n\t\t\tif (mirror.lookup !== 'found') this.#warn(`${mirror.name}: ${mirror.note}`)\n\t\t}\n\t}\n\n\t// One line stating what a mutation did.\n\t#tally(result: MaterializeResult): string {\n\t\treturn `${String(result.written.length)} written, ${String(result.skipped.length)} unchanged, ${String(result.removed.length)} removed in ${result.target}.`\n\t}\n\n\t// The one machine-readable value a `--json` run emits.\n\t#report(value: unknown): void {\n\t\tthis.#say(JSON.stringify(value))\n\t}\n\n\t// Report a refusal under the code it carries and answer with the code it\n\t// earned: a command line that was not a command is a usage error, and\n\t// everything else is a failed run.\n\t#refuse(error: unknown, json: boolean): number {\n\t\tconst envelope = errorToEnvelope(error)\n\t\tif (json) this.#report(envelope)\n\t\telse this.#warn(`${envelope.error.code}: ${envelope.error.message}`)\n\t\treturn isUsageError(error) ? EXIT_USAGE : EXIT_DRIFT\n\t}\n\n\t#say(line: string): void {\n\t\tthis.#output(this.#sanitize(line))\n\t}\n\n\t#warn(line: string): void {\n\t\tthis.#diagnostic(this.#sanitize(line))\n\t}\n\n\t// The single write path, and the only place hostile bytes are answered for.\n\t// A refusal quotes the argument that caused it, so an escape sequence, a bell,\n\t// or a forged second line arrives here inside otherwise ordinary prose. ANSI\n\t// escapes go first because they are what repaints a terminal, control\n\t// characters next, and what remains is folded onto one line because a handler\n\t// takes one line and a caller writing a record per call must get one record.\n\t#sanitize(line: string): string {\n\t\treturn stripControls(strip(line)).split(/\\r?\\n/).join(' ')\n\t}\n}\n","// The executable entry, and the only module that touches process state: it reads\n// the arguments the process was given and assigns the code the run returned. The\n// `#!/usr/bin/env node` shebang is re-emitted by the build's `output.banner`\n// rather than written here, because the bundler strips a shebang from source.\nimport { CLI } from './CLI.js'\n\nprocess.stdout.on('error', (error) => {\n\tif ('code' in error && error.code === 'EPIPE') return\n\tthrow error\n})\nprocess.exitCode = await new CLI().execute(process.argv.slice(2))\n"],"mappings":";;;;;;;;;;;;;;;;;AAWA,IAAa,kBAAkB;;;;;;;;;AAU/B,IAAa,QAAyB,OAAO,OAAO;CACnD;CACA;CACA;CACA;CACA;AACD,CAAC;;;;;;;;AAkBD,IAAa,eAAiD,OAAO,OAAO;EAC7D,IAAA;EACA,IAAA;EACA,IAAA;AACf,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oB,MAAM,GAAG,OAAO,KAAK,IAAI,OAAO,MAAM;CAE5E;CAGA,OAAO,QAAmC;EACzC,OAAO,GAAG,OAAO,OAAO,QAAQ,MAAM,EAAE,YAAY,OAAO,OAAO,QAAQ,MAAM,EAAE,cAAc,OAAO,OAAO,QAAQ,MAAM,EAAE,cAAc,OAAO,OAAO;CAC3J;CAGA,QAAQ,OAAsB;EAC7B,KAAKpB,KAAK,KAAK,UAAU,KAAK,CAAC;CAChC;CAKA,QAAQ,OAAgB,MAAuB;EAC9C,MAAM,WAAW,gBAAgB,KAAK;EACtC,IAAI,MAAM,KAAKY,QAAQ,QAAQ;OAC1B,KAAKQ,MAAM,GAAG,SAAS,MAAM,KAAK,IAAI,SAAS,MAAM,SAAS;EACnE,OAAO,aAAa,KAAK,IAAA,IAAA;CAC1B;CAEA,KAAK,MAAoB;EACxB,KAAKvB,QAAQ,KAAKqC,UAAU,IAAI,CAAC;CAClC;CAEA,MAAM,MAAoB;EACzB,KAAKpC,YAAY,KAAKoC,UAAU,IAAI,CAAC;CACtC;CAQA,UAAU,MAAsB;EAC/B,OAAO,cAAc,MAAM,IAAI,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,CAAC,KAAK,GAAG;CAC1D;AACD;;;AC94BA,QAAQ,OAAO,GAAG,UAAU,UAAU;CACrC,IAAI,UAAU,SAAS,MAAM,SAAS,SAAS;CAC/C,MAAM;AACP,CAAC;AACD,QAAQ,WAAW,MAAM,IAAI,IAAI,CAAC,CAAC,QAAQ,QAAQ,KAAK,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"main.js","names":["#stdout","#stderr","#output","#diagnostic","#upstream","#say","#refuse","#dispatch","#create","#inspect","#restore","#refresh","#replace","#environments","#resolve","#packages","#compile","#report","#tally","#derive","#projectQuestion","#survey","#groups","#present","#assertProjects","#warn","#previous","#fetch","#publish","#recount","#repository","#merge","#reconcile","#lookup","#pin","#manifest","#probe","#scriptProjects","#inventory","#sanitize"],"sources":["../../src/bin/constants.ts","../../src/bin/errors.ts","../../src/bin/helpers.ts","../../src/bin/CLI.ts","../../src/bin/main.ts"],"sourcesContent":["import type { ParseArgsOptionsConfig } from 'node:util'\nimport type { Verb } from './types.js'\n\n/**\n * The name the executable installs as.\n *\n * @remarks\n * `package.json`'s `bin` field is the authority for what the command is called;\n * this is the same word, so every usage line the executable prints is a command\n * a reader can paste back.\n */\nexport const EXECUTABLE_NAME = 'scaffold'\n\n/**\n * The five {@link Verb} values in usage order, frozen.\n *\n * @remarks\n * The order the type declares them in, which is also the order usage lists them:\n * the verb that creates a workspace, then the one that only reads it, then the\n * three that write to one that already exists, widest last.\n */\nexport const VERBS: readonly Verb[] = Object.freeze([\n\t'new',\n\t'audit',\n\t'repair',\n\t'catalog',\n\t'overwrite',\n])\n\n/** The exit code reporting that the target matched its plan and every step completed. */\nexport const EXIT_CLEAN = 0\n\n/** The exit code reporting that the target drifted, or that a step failed. */\nexport const EXIT_DRIFT = 1\n\n/** The exit code reporting that the command line was not a command. */\nexport const EXIT_USAGE = 2\n\n/**\n * What each exit code means, frozen.\n *\n * @remarks\n * Keyed by the three code constants rather than by literals, so the usage block\n * cannot document a code the executable does not return.\n */\nexport const EXIT_SUMMARY: Readonly<Record<number, string>> = Object.freeze({\n\t[EXIT_CLEAN]: 'clean',\n\t[EXIT_DRIFT]: 'drift or failure',\n\t[EXIT_USAGE]: 'usage error',\n})\n\n/**\n * The machine-readable code a malformed command line reports.\n *\n * @remarks\n * The executable contributes its own codes to the failure envelope, which is why\n * that envelope's `code` is a plain string rather than a `ScaffoldErrorCode`: a\n * command line that never became a command failed before any coded package\n * operation could.\n */\nexport const USAGE_CODE = 'USAGE'\n\n/** The machine-readable code a failure carrying no code of its own reports. */\nexport const FAILED_CODE = 'FAILED'\n\n/** What the failure envelope says when the raised value carried no message. */\nexport const FAILED_MESSAGE = 'The command failed for an unrecognized reason'\n\n/**\n * The positional argument `new` alone takes, as usage writes it.\n *\n * @remarks\n * The workspace name is the only positional argument any verb takes, so it is\n * one value rather than a per-verb table with four holes in it.\n */\nexport const NAME_ARGUMENT = '<name>'\n\n/**\n * Every option the executable accepts, as `node:util` parses them, frozen.\n *\n * @remarks\n * One table for every verb rather than one per verb, because the verb an option\n * belongs to is a domain fact the command union already fixes: parsing decides\n * only whether the word is an option at all, and {@link VERB_OPTIONS} decides\n * whether this verb takes it. No option declares a default, so the parsed keys\n * are exactly the options the caller supplied, which is what makes an option\n * offered to the wrong verb visible rather than silently absorbed. `from`\n * collects repeats because `catalog` may draw on more than one local source; a\n * verb that takes it once refuses the second.\n */\nexport const COMMAND_OPTIONS: ParseArgsOptionsConfig = Object.freeze({\n\tsrc: Object.freeze({ type: 'string' }),\n\tapp: Object.freeze({ type: 'string' }),\n\tbin: Object.freeze({ type: 'boolean' }),\n\tdeps: Object.freeze({ type: 'string' }),\n\tgroups: Object.freeze({ type: 'string' }),\n\tall: Object.freeze({ type: 'boolean' }),\n\tdirty: Object.freeze({ type: 'boolean' }),\n\tfrom: Object.freeze({ type: 'string', multiple: true }),\n\ttarget: Object.freeze({ type: 'string' }),\n\tjson: Object.freeze({ type: 'boolean' }),\n})\n\n/**\n * What each option does, keyed by the token usage prints, frozen.\n *\n * @remarks\n * The key order is the glossary order. A key is the whole displayed token,\n * value placeholder included, because that token is what a reader copies and\n * what {@link VERB_OPTIONS} lists.\n */\nexport const OPTION_SUMMARY: Readonly<Record<string, string>> = Object.freeze({\n\t'--src <list>': 'the published library environments to build: core, browser, server',\n\t'--app <list>': 'the private application environments to build: core, browser, server',\n\t'--bin': 'scaffold a command-line executable at src/bin/main.ts',\n\t'--deps <list>': 'the @orkestrel/* packages the workspace depends on',\n\t'--groups <list>': 'the artifact groups to cover; every group when absent',\n\t'--all': 'fetch a guide for every package the organization publishes, not just the declared ones',\n\t'--dirty': 'delete from a tree carrying uncommitted changes',\n\t'--from <path>':\n\t\t'read the data root from a local path instead of the bundled one; catalog alone accepts it more than once',\n\t'--target <path>': 'the directory the verb operates on; the working directory when absent',\n\t'--json': 'emit one machine-readable value instead of a report',\n})\n\n/**\n * The options each verb takes, in usage order, frozen.\n *\n * @remarks\n * The executable's half of the frozen command union: every option a branch\n * declares is listed against its verb, and every option a branch excludes is\n * absent from it. An option a verb does not list is refused by name rather than\n * parsed and ignored.\n */\nexport const VERB_OPTIONS: Readonly<Record<Verb, readonly string[]>> = Object.freeze({\n\tnew: Object.freeze([\n\t\t'--src <list>',\n\t\t'--app <list>',\n\t\t'--bin',\n\t\t'--deps <list>',\n\t\t'--from <path>',\n\t\t'--target <path>',\n\t\t'--json',\n\t]),\n\taudit: Object.freeze(['--groups <list>', '--from <path>', '--target <path>', '--json']),\n\trepair: Object.freeze(['--groups <list>', '--from <path>', '--target <path>', '--json']),\n\tcatalog: Object.freeze(['--all', '--from <path>', '--target <path>', '--json']),\n\toverwrite: Object.freeze([\n\t\t'--groups <list>',\n\t\t'--dirty',\n\t\t'--from <path>',\n\t\t'--target <path>',\n\t\t'--json',\n\t]),\n})\n\n/**\n * What each verb does, in one line, frozen.\n *\n * @remarks\n * Each line names what the verb writes, because authority is the verb's: a\n * reader deciding which one to run is deciding what they are authorizing.\n */\nexport const VERB_SUMMARY: Readonly<Record<Verb, string>> = Object.freeze({\n\tnew: 'scaffold a workspace',\n\taudit: 'report how the target compares to its plan, writing nothing',\n\trepair: 'write each planned path the target is missing or has let drift',\n\tcatalog: 'regenerate the package table and refresh the guide mirrors',\n\toverwrite:\n\t\t'do everything repair and catalog do, then delete what the plan does not own and re-declare the dependency ranges',\n})\n","import { USAGE_CODE } from './constants.js'\n\n/**\n * The error raised when a command line is not a command.\n *\n * @remarks\n * Distinct from `ScaffoldError` because the two answer different questions and\n * exit differently: a `ScaffoldError` says the package could not serve a\n * well-formed request and exits `1`, while this says there was no request to\n * serve and exits `2`. Folding a usage error into `INVALID` would report a\n * mistyped flag as a failed run.\n *\n * It carries no `context`. Everything a caller can act on is in the message,\n * because the reader of a usage error is a person at a terminal rather than a\n * program branching on a cause.\n *\n * @example\n * ```ts\n * import { isUsageError, UsageError } from './errors.js'\n *\n * try {\n * \tthrow new UsageError(\"Unknown command 'pull'.\")\n * } catch (error) {\n * \tif (isUsageError(error)) error.code // 'USAGE'\n * }\n * ```\n */\nexport class UsageError extends Error {\n\treadonly code: string\n\n\t/**\n\t * Construct a usage error.\n\t *\n\t * @param message - What was wrong with the command line, in one sentence.\n\t */\n\tconstructor(message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'UsageError'\n\t\tthis.code = USAGE_CODE\n\t}\n}\n\n/**\n * Narrow a caught value to a {@link UsageError}.\n *\n * @param value - The caught value to narrow.\n * @returns `true` when `value` is a {@link UsageError}.\n *\n * @example\n * ```ts\n * import { isUsageError } from './errors.js'\n *\n * isUsageError(new Error('plain')) // false\n * isUsageError(undefined) // false\n * ```\n */\nexport function isUsageError(value: unknown): value is UsageError {\n\treturn value instanceof UsageError\n}\n","import type { Audit } from '@src/core'\nimport type { CLICommand, ErrorEnvelope, Verb } from './types.js'\nimport { align, width } from '@orkestrel/console'\nimport { attempt } from '@orkestrel/contract'\nimport { isScaffoldError } from '@src/core'\nimport { parseArgs } from 'node:util'\nimport {\n\tCOMMAND_OPTIONS,\n\tEXECUTABLE_NAME,\n\tEXIT_CLEAN,\n\tEXIT_DRIFT,\n\tEXIT_SUMMARY,\n\tFAILED_CODE,\n\tFAILED_MESSAGE,\n\tNAME_ARGUMENT,\n\tOPTION_SUMMARY,\n\tVERB_OPTIONS,\n\tVERB_SUMMARY,\n\tVERBS,\n} from './constants.js'\nimport { isUsageError, UsageError } from './errors.js'\n\n/**\n * Read the option name out of the token usage displays it as.\n *\n * @param option - The displayed token, such as `--from <path>`.\n * @returns The bare name `node:util` parses the option under.\n *\n * @remarks\n * One token serves both readers: a person reads the value placeholder and the\n * parser reads the name in front of it. Deriving the name means a documented\n * option and an accepted option cannot be two different lists.\n *\n * @example\n * ```ts\n * import { optionToName } from './helpers.js'\n *\n * optionToName('--from <path>') // 'from'\n * optionToName('--json') // 'json'\n * ```\n */\nexport function optionToName(option: string): string {\n\tconst [token = option] = option.split(' ')\n\treturn token.startsWith('--') ? token.slice(2) : token\n}\n\n/**\n * Render one verb's synopsis.\n *\n * @param verb - The verb to describe.\n * @returns The command line this verb accepts, with every option bracketed.\n *\n * @remarks\n * The synopsis is derived from the verb's own option list rather than stored\n * beside it, so a line that documents an option the verb does not take cannot be\n * written. `new` alone carries the positional argument.\n *\n * @example\n * ```ts\n * import { verbToSyntax } from './helpers.js'\n *\n * verbToSyntax('audit') // 'scaffold audit [--groups <list>] …'\n * ```\n */\nexport function verbToSyntax(verb: Verb): string {\n\tconst argument = verb === 'new' ? ` ${NAME_ARGUMENT}` : ''\n\tconst options = VERB_OPTIONS[verb].map((option) => `[${option}]`).join(' ')\n\treturn `${EXECUTABLE_NAME} ${verb}${argument} ${options}`\n}\n\n/**\n * Render the whole command reference.\n *\n * @returns One line per output call: the synopsis, every verb, the option glossary, and the exit codes.\n *\n * @remarks\n * Returned as lines because the executable writes through a handler that takes\n * one line, so the caller never has to split a block back apart. The glossary is\n * printed once for every verb rather than repeated per verb, since seven of the\n * nine options are shared and a reader comparing two verbs wants the difference,\n * not the repetition.\n */\nexport function renderUsage(): readonly string[] {\n\tconst summaries = Object.entries(OPTION_SUMMARY)\n\tconst column = Math.max(...summaries.map(([option]) => width(option)))\n\treturn [\n\t\t`${EXECUTABLE_NAME} <verb> [options]`,\n\t\t'',\n\t\t...VERBS.flatMap((verb) => [` ${verbToSyntax(verb)}`, ` ${VERB_SUMMARY[verb]}`]),\n\t\t'',\n\t\t'options',\n\t\t...summaries.map(([option, summary]) => ` ${align(option, column)} ${summary}`),\n\t\t'',\n\t\t'exit codes',\n\t\t...Object.entries(EXIT_SUMMARY).map(([code, meaning]) => ` ${code} ${meaning}`),\n\t]\n}\n\n/**\n * Read one command out of the arguments following the executable's own name.\n *\n * @param argv - The arguments the executable was given.\n * @returns The command the arguments denote.\n * @throws {@link UsageError} when they denote no command.\n *\n * @remarks\n * The one place untrusted argument text becomes a domain value, and it stays one\n * function because the command union admits no partial command to hand on: every\n * refusal has to happen before the value exists. It refuses in four ways, each\n * naming what was wrong — a word that is not a verb, a word that is not an\n * option, an option this verb does not take, and an argument this verb does not\n * take. `node:util` decides the second and this decides the rest, so an unknown\n * option is reported by the parser that found it rather than re-derived here.\n *\n * A request for usage is not a command and never reaches this: the caller\n * answers it first.\n *\n * @example\n * ```ts\n * import { argvToCommand } from './helpers.js'\n *\n * argvToCommand(['audit', '--json']) // { verb: 'audit', json: true }\n * ```\n */\nexport function argvToCommand(argv: readonly string[]): CLICommand {\n\tconst [head, ...rest] = argv\n\tconst verb = VERBS.find((candidate) => candidate === head)\n\tif (verb === undefined) {\n\t\tconst found = head === undefined ? 'No command given.' : `Unknown command '${head}'.`\n\t\tthrow new UsageError(`${found} Run '${EXECUTABLE_NAME} --help' for the command list.`)\n\t}\n\tconst parsed = attempt(() =>\n\t\tparseArgs({ args: rest, options: COMMAND_OPTIONS, allowPositionals: true, strict: true }),\n\t)\n\tif (!parsed.success) {\n\t\tconst cause = parsed.error\n\t\tthrow new UsageError(\n\t\t\tcause instanceof Error ? cause.message : `Could not read the arguments to '${verb}'.`,\n\t\t)\n\t}\n\tconst { positionals, values } = parsed.value\n\tconst accepted = VERB_OPTIONS[verb].map((option) => optionToName(option))\n\tconst refused = Object.keys(values).filter((name) => !accepted.includes(name))\n\tif (refused.length > 0) {\n\t\tconst names = refused.map((name) => `--${name}`).join(', ')\n\t\tthrow new UsageError(`'${verb}' does not take ${names}.`)\n\t}\n\tconst [name] = positionals\n\tif (positionals.length > 1) {\n\t\tthrow new UsageError(\n\t\t\t`'${verb}' takes at most one argument, and was given ${String(positionals.length)}.`,\n\t\t)\n\t}\n\tif (verb !== 'new' && name !== undefined) {\n\t\tthrow new UsageError(`'${verb}' takes no argument, and was given '${name}'.`)\n\t}\n\tconst paths = Array.isArray(values.from)\n\t\t? values.from.filter((value) => typeof value === 'string')\n\t\t: []\n\tif (verb !== 'catalog' && paths.length > 1) {\n\t\tthrow new UsageError(\n\t\t\t`'${verb}' takes --from once, and was given it ${String(paths.length)} times.`,\n\t\t)\n\t}\n\tconst src = typeof values.src === 'string' ? values.src : undefined\n\tconst app = typeof values.app === 'string' ? values.app : undefined\n\tconst bin = values.bin === true\n\tconst dependencies = typeof values.deps === 'string' ? values.deps : undefined\n\tconst target = typeof values.target === 'string' ? values.target : undefined\n\tconst json = values.json === true\n\tconst [from] = paths\n\tconst location = target === undefined ? {} : { target }\n\tconst source = from === undefined ? {} : { from }\n\tconst selection = typeof values.groups === 'string' ? { groups: values.groups } : {}\n\tswitch (verb) {\n\t\tcase 'new':\n\t\t\tif (name === undefined) {\n\t\t\t\tthrow new UsageError(`'new' needs the workspace ${NAME_ARGUMENT} it is scaffolding.`)\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tverb,\n\t\t\t\tname,\n\t\t\t\tjson,\n\t\t\t\t...location,\n\t\t\t\t...source,\n\t\t\t\t...(src === undefined ? {} : { src }),\n\t\t\t\t...(app === undefined ? {} : { app }),\n\t\t\t\t...(bin ? { bin } : {}),\n\t\t\t\t...(dependencies === undefined ? {} : { dependencies }),\n\t\t\t}\n\t\tcase 'audit':\n\t\t\treturn { verb, json, ...location, ...source, ...selection }\n\t\tcase 'repair':\n\t\t\treturn { verb, json, ...location, ...source, ...selection }\n\t\tcase 'catalog':\n\t\t\treturn {\n\t\t\t\tverb,\n\t\t\t\tjson,\n\t\t\t\tall: values.all === true,\n\t\t\t\t...location,\n\t\t\t\t...(paths.length === 0 ? {} : { from: paths }),\n\t\t\t}\n\t\tcase 'overwrite':\n\t\t\treturn {\n\t\t\t\tverb,\n\t\t\t\tjson,\n\t\t\t\tdirty: values.dirty === true,\n\t\t\t\t...location,\n\t\t\t\t...source,\n\t\t\t\t...selection,\n\t\t\t}\n\t}\n}\n\n/**\n * Read the exit code an audit reports.\n *\n * @param audit - The comparison of a plan against a target.\n * @returns `EXIT_CLEAN` when the target matched the plan, `EXIT_DRIFT` otherwise.\n *\n * @remarks\n * One rule for every verb that carries an audit, so `audit`, `repair`, and\n * `overwrite` cannot disagree about what a clean run is. A blocking question\n * means the gate refused the blueprint, so the audit says nothing about the\n * target and the run is a failure. A foreign finding counts: the target holds a\n * file the plan does not own, which is a difference from the plan whether or not\n * this verb was allowed to remove it. A non-blocking question rides a complete\n * result and does not.\n *\n * @example\n * ```ts\n * import { auditToExit } from './helpers.js'\n *\n * auditToExit({ findings: [], questions: [] }) // 0\n * ```\n */\nexport function auditToExit(audit: Audit): number {\n\tconst blocked = audit.questions.some((question) => question.blocking)\n\tconst drifted = audit.findings.some((finding) => finding.drift !== 'aligned')\n\treturn blocked || drifted ? EXIT_DRIFT : EXIT_CLEAN\n}\n\n/**\n * Project an audit into the human summary of its outcome.\n *\n * @param audit - The comparison to summarize.\n * @returns The refusal, or the planned-path outcome, its grounds, and any foreign-path count.\n *\n * @remarks\n * A blocking question means the gate produced no plan, so the target was not\n * compared and no finding count is reported. Otherwise the three grounds\n * describe what this run did. `bytes` means content-owned\n * bytes were observed, `existence` means presence or absence alone decided the\n * finding, and `nothing` means a birth-owned path was not examined. Foreign\n * paths remain a separate population because no planned ownership accounts for\n * them.\n *\n * @example\n * ```ts\n * import { auditToSummary } from './helpers.js'\n *\n * auditToSummary({\n * findings: [],\n * questions: [{ field: 'src', message: 'Core is required.', blocking: true }],\n * })\n * // 'Audit did not compare the target because the blueprint was refused.'\n * ```\n */\nexport function auditToSummary(audit: Audit): string {\n\tif (audit.questions.some((question) => question.blocking)) {\n\t\treturn 'Audit did not compare the target because the blueprint was refused.'\n\t}\n\tconst planned = audit.findings.filter((finding) => finding.drift !== 'foreign')\n\tconst drifted = planned.filter((finding) => finding.drift !== 'aligned').length\n\t// These counts say what decided each verdict on this run. They partition the\n\t// planned findings, so they sum to `planned.length` and never to `drifted`.\n\tconst bytes = planned.filter(\n\t\t(finding) => finding.ownership === 'content' && finding.observed !== undefined,\n\t).length\n\tconst existence = planned.filter(\n\t\t(finding) =>\n\t\t\tfinding.ownership === 'presence' ||\n\t\t\t(finding.ownership === 'content' && finding.drift === 'missing'),\n\t).length\n\tconst nothing = planned.filter((finding) => finding.ownership === 'birth').length\n\tconst foreign = audit.findings.length - planned.length\n\tconst summary = `${String(drifted)} of ${String(planned.length)} planned path${planned.length === 1 ? '' : 's'} drifted from the plan. Audit compared bytes at ${String(bytes)}, existence at ${String(existence)}, and nothing at ${String(nothing)}.`\n\treturn foreign === 0\n\t\t? summary\n\t\t: `${summary} The plan does not own ${String(foreign)} further path${foreign === 1 ? '' : 's'} beneath its groups.`\n}\n\n/**\n * Project a raised value into the machine-readable failure envelope.\n *\n * @param error - The value a command raised.\n * @returns The envelope naming the coded reason and what went wrong.\n *\n * @remarks\n * A `ScaffoldError` and a {@link UsageError} both publish a code, so both are\n * reported under their own. Anything else failed without saying why, and is\n * reported under one code rather than under an invented reading of it; a raised\n * value that is not an `Error` carries no message worth quoting, so the envelope\n * says so instead of stringifying whatever it was.\n *\n * @example\n * ```ts\n * import { errorToEnvelope } from './helpers.js'\n *\n * errorToEnvelope(new Error('boom')) // { error: { code: 'FAILED', message: 'boom' } }\n * ```\n */\nexport function errorToEnvelope(error: unknown): ErrorEnvelope {\n\tif (isUsageError(error) || isScaffoldError(error)) {\n\t\treturn { error: { code: error.code, message: error.message } }\n\t}\n\tconst message = error instanceof Error ? error.message : FAILED_MESSAGE\n\treturn { error: { code: FAILED_CODE, message } }\n}\n","import type {\n\tAudit,\n\tBlueprint,\n\tCatalogEntry,\n\tDependency,\n\tEnvironment,\n\tGroup,\n\tMirror,\n\tPlan,\n\tQuestion,\n\tRelease,\n} from '@src/core'\nimport type {\n\tMaterializeResult,\n\tMaterializerInterface,\n\tRepository,\n\tUpstreamOptions,\n} from '@src/server'\nimport type {\n\tAuditCommand,\n\tCatalogCommand,\n\tCatalogResult,\n\tCLICommand,\n\tCLIInterface,\n\tCLIOptions,\n\tNewCommand,\n\tOutputHandler,\n\tOverwriteCommand,\n\tOverwriteResult,\n\tRepairCommand,\n\tRepairResult,\n} from './types.js'\nimport { execFileSync } from 'node:child_process'\nimport { renderTable, strip, stripControls } from '@orkestrel/console'\nimport { attempt, isRecord, isString, parseJSON } from '@orkestrel/contract'\nimport { createMarkdown, flattenText, isTableNode } from '@orkestrel/markdown'\nimport {\n\tCATALOG_AGENT_PATH,\n\tBIN_ENTRY_PATH,\n\tblueprintToRootVite,\n\tcreateBlueprint,\n\tcreateCompiler,\n\tDEPENDENCY_NAME_PATTERN,\n\tENVIRONMENTS,\n\tGROUPS,\n\tGLOBAL_SETUP_PATH,\n\tGUIDES_TEST_PATH,\n\tINTEGRATION_TEST_PATH,\n\tmanifestToDependencies,\n\tmanifestToName,\n\tMAX_MANIFEST_BYTES,\n\tnameToGuide,\n\tScaffoldError,\n\tSHOWCASE_CONFIG_PATH,\n} from '@src/core'\nimport {\n\tcreateMaterializer,\n\tcreateUpstream,\n\tisExactCaseFile,\n\tisPhysicalDirectory,\n\tisRepository,\n\treadFileText,\n\treadSnapshot,\n\tresolveContainedPath,\n} from '@src/server'\nimport { EXIT_CLEAN, EXIT_DRIFT, EXIT_USAGE } from './constants.js'\nimport { isUsageError, UsageError } from './errors.js'\nimport {\n\targvToCommand,\n\tauditToExit,\n\tauditToSummary,\n\terrorToEnvelope,\n\trenderUsage,\n} from './helpers.js'\n\n/**\n * The executable: one command line in, one exit code out.\n *\n * @remarks\n * Every destination this class writes to is a handler it was given, and the run\n * ends by returning its code rather than by setting one, so the whole executable\n * is drivable from inside another process. That is what makes proving what a\n * command prints cost a function call: `src/bin/main.ts` is the only module\n * that reads `process.argv` or assigns `process.exitCode`.\n *\n * Every line leaving here is stripped of ANSI escapes and control characters\n * once, on the way out, because a refusal quotes the argument that caused it and\n * that argument came from an untrusted command line. The machine-readable path\n * needs no second pass: `JSON.stringify` escapes a control character into text\n * before it reaches the handler.\n *\n * The collaborators are constructed per run rather than received, because\n * `--from` decides the vendored root the materializer reads and an instance\n * handed in before the command line was parsed could not honour it. The\n * upstream reader is built the same way but from the options, because no\n * command line names an endpoint: a terminal caller means the published\n * registry and the published guide host, and only the process driving the\n * executable can mean anything else. That is the seam that makes the three\n * verbs which read the network provable without one.\n *\n * @example\n * ```ts\n * import { CLI } from './CLI.js'\n *\n * const lines: string[] = []\n * const code = await new CLI({ output: (line) => lines.push(line) }).execute(['--help'])\n * code // 0\n * ```\n */\nexport class CLI implements CLIInterface {\n\t// The two destinations a terminal caller means. They are the only process\n\t// streams this class names, and it names them once: a handler is what every\n\t// write goes through, so the default is a handler too rather than a branch at\n\t// each write site.\n\tstatic readonly #stdout: OutputHandler = (line) => void process.stdout.write(`${line}\\n`)\n\tstatic readonly #stderr: OutputHandler = (line) => void process.stderr.write(`${line}\\n`)\n\treadonly #output: OutputHandler\n\treadonly #diagnostic: OutputHandler\n\t// What every upstream reader this class builds is constructed from. It is held\n\t// once and read by each verb that reads the network, so the three of them\n\t// cannot disagree about which registry and which guide host a run addresses.\n\treadonly #upstream: UpstreamOptions | undefined\n\n\t/**\n\t * Construct the executable over the two destinations it writes to.\n\t *\n\t * @param options - The report and diagnostic handlers and the upstream\n\t * endpoints; the process streams and the published endpoints when absent.\n\t */\n\tconstructor(options?: CLIOptions) {\n\t\tthis.#output = options?.output ?? CLI.#stdout\n\t\tthis.#diagnostic = options?.diagnostic ?? CLI.#stderr\n\t\tthis.#upstream = options?.upstream\n\t}\n\n\t/**\n\t * Run one command line to completion and report through the configured output.\n\t *\n\t * @param argv - The arguments following the executable's own name.\n\t * @returns The exit code: `0` clean, `1` drift or failure, `2` a usage error.\n\t *\n\t * @remarks\n\t * A request for usage is answered before anything is parsed, because it\n\t * replaces the run rather than modifying it, and because `--help` is not an\n\t * option any verb takes. Everything after that is one command: read it,\n\t * dispatch it, render what it produced, and answer with the code it earned.\n\t *\n\t * @example\n\t * ```ts\n\t * import { CLI } from './CLI.js'\n\t *\n\t * await new CLI().execute(['audit', '--json']) // 0 when the target matches its plan\n\t * ```\n\t */\n\tasync execute(argv: readonly string[]): Promise<number> {\n\t\tif (argv.includes('--help')) {\n\t\t\tfor (const line of renderUsage()) this.#say(line)\n\t\t\treturn EXIT_CLEAN\n\t\t}\n\t\tconst read = attempt(() => argvToCommand(argv))\n\t\t// A command line that never became a command carries no `--json`, so the\n\t\t// refusal is prose: there is no machine-readable value for it to pollute.\n\t\tif (!read.success) return this.#refuse(read.error, false)\n\t\tconst command = read.value\n\t\ttry {\n\t\t\treturn await this.#dispatch(command)\n\t\t} catch (error) {\n\t\t\treturn this.#refuse(error, command.json === true)\n\t\t}\n\t}\n\n\t// One verb per branch, each answering with its own exit code. The switch is\n\t// exhaustive over the command union, so a new verb fails to compile here.\n\tasync #dispatch(command: CLICommand): Promise<number> {\n\t\tswitch (command.verb) {\n\t\t\tcase 'new':\n\t\t\t\treturn this.#create(command)\n\t\t\tcase 'audit':\n\t\t\t\treturn this.#inspect(command)\n\t\t\tcase 'repair':\n\t\t\t\treturn this.#restore(command)\n\t\t\tcase 'catalog':\n\t\t\t\treturn this.#refresh(command)\n\t\t\tcase 'overwrite':\n\t\t\t\treturn this.#replace(command)\n\t\t}\n\t}\n\n\t// `new` — resolve the declared dependencies against the registry, compile the\n\t// blueprint the command line describes, and write it into a vacant target.\n\tasync #create(command: NewCommand): Promise<number> {\n\t\tconst target = command.target ?? command.name\n\t\tconst blueprint = createBlueprint(command.name, {\n\t\t\tsrc: this.#environments(command.src, 'src'),\n\t\t\tapp: this.#environments(command.app, 'app'),\n\t\t\tbin: command.bin === true,\n\t\t\tdependencies: await this.#resolve(this.#packages(command.dependencies)),\n\t\t})\n\t\tconst plan = this.#compile(blueprint)\n\t\tconst materializer = createMaterializer(\n\t\t\tcommand.from === undefined ? undefined : { host: command.from },\n\t\t)\n\t\ttry {\n\t\t\tconst result = materializer.materialize(plan, target)\n\t\t\tif (command.json === true) this.#report(result)\n\t\t\telse {\n\t\t\t\tthis.#say(`Scaffolded ${blueprint.name} into ${result.target}.`)\n\t\t\t\tthis.#say(this.#tally(result))\n\t\t\t}\n\t\t\treturn EXIT_CLEAN\n\t\t} finally {\n\t\t\tmaterializer.destroy()\n\t\t}\n\t}\n\n\t// `audit` — compare a target to the plan its own manifest and directories\n\t// describe, through the vendored host a repair would write from, and write\n\t// nothing whatever it finds.\n\t//\n\t// The host is load-bearing here where it once was not, so `--from` reaches the\n\t// comparison and a host that cannot be read refuses the run under its own\n\t// coded reason. Refusing is the honest answer: the comparison this verb\n\t// reports is the hydrated one, and a fallback to the pure compile would report\n\t// `aligned` for exactly the files whose bytes it failed to read.\n\t#inspect(command: AuditCommand): number {\n\t\tconst target = command.target ?? '.'\n\t\tconst blueprint = this.#derive(target)\n\t\tconst question = this.#projectQuestion(target, blueprint)\n\t\tconst materializer = createMaterializer(\n\t\t\tcommand.from === undefined ? undefined : { host: command.from },\n\t\t)\n\t\ttry {\n\t\t\tconst [measured] = this.#survey(materializer, blueprint, target, this.#groups(command.groups))\n\t\t\tconst audit: Audit =\n\t\t\t\tquestion === undefined\n\t\t\t\t\t? measured\n\t\t\t\t\t: { ...measured, questions: [...measured.questions, question] }\n\t\t\tif (command.json === true) this.#report(audit)\n\t\t\telse this.#present(audit)\n\t\t\treturn auditToExit(audit)\n\t\t} finally {\n\t\t\tmaterializer.destroy()\n\t\t}\n\t}\n\n\t// `repair` — write each planned path the target is missing or has let drift,\n\t// then re-audit, because the audit a repair reports is the one taken after it.\n\t// One materializer spans the whole verb: the audit that guides the write, the\n\t// write, and the audit that answers for it are three readings of one vendored\n\t// host, and a second instance could not promise they were.\n\t#restore(command: RepairCommand): number {\n\t\tconst target = command.target ?? '.'\n\t\tconst groups = this.#groups(command.groups)\n\t\tconst blueprint = this.#derive(target)\n\t\tthis.#assertProjects(target, blueprint)\n\t\tconst materializer = createMaterializer(\n\t\t\tcommand.from === undefined ? undefined : { host: command.from },\n\t\t)\n\t\ttry {\n\t\t\tconst [audit, plan] = this.#survey(materializer, blueprint, target, groups)\n\t\t\tif (plan === undefined) {\n\t\t\t\tif (command.json === true) this.#report(audit)\n\t\t\t\telse this.#present(audit)\n\t\t\t\treturn EXIT_DRIFT\n\t\t\t}\n\t\t\tconst result = materializer.repair(plan, audit, target)\n\t\t\tconst [terminal] = this.#survey(materializer, blueprint, target, groups)\n\t\t\tconst outcome: RepairResult = { ...result, audit: terminal }\n\t\t\tif (command.json === true) this.#report(outcome)\n\t\t\telse {\n\t\t\t\tthis.#present(terminal)\n\t\t\t\tthis.#say(this.#tally(result))\n\t\t\t}\n\t\t\treturn auditToExit(terminal)\n\t\t} finally {\n\t\t\tmaterializer.destroy()\n\t\t}\n\t}\n\n\t// `catalog` — regenerate the package table from the organization's published\n\t// list and refresh the guide mirrors the target draws on.\n\tasync #refresh(command: CatalogCommand): Promise<number> {\n\t\tconst target = command.target ?? '.'\n\t\tconst [host, ...extra] = command.from ?? []\n\t\tif (extra.length > 0) {\n\t\t\tthis.#warn(\n\t\t\t\t`Read the data root from ${String(host)}. The other ${String(extra.length)} local root${extra.length === 1 ? '' : 's'} named by --from reach nothing this run does.`,\n\t\t\t)\n\t\t}\n\t\tconst previous = this.#previous(target)\n\t\tconst fetched = await this.#fetch(target, command.all === true)\n\t\tconst materializer = createMaterializer(host === undefined ? undefined : { host })\n\t\tlet result: MaterializeResult\n\t\ttry {\n\t\t\tresult = this.#publish(materializer, target, fetched.entries, fetched.mirrors)\n\t\t} finally {\n\t\t\tmaterializer.destroy()\n\t\t}\n\t\tconst outcome: CatalogResult = {\n\t\t\t...result,\n\t\t\tentries: fetched.entries,\n\t\t\tmirrors: fetched.mirrors,\n\t\t\tdropped: previous.filter((name) => !fetched.entries.some((entry) => entry.name === name)),\n\t\t}\n\t\tif (command.json === true) this.#report(outcome)\n\t\telse this.#recount(outcome)\n\t\treturn fetched.mirrors.some((mirror) => mirror.lookup === 'failed') ? EXIT_DRIFT : EXIT_CLEAN\n\t}\n\n\t// `overwrite` — everything repair and catalog do, plus the two steps only this\n\t// verb carries. The offline half runs first and persists whatever it did,\n\t// because it is the destructive one: a run that cannot reach upstream still\n\t// leaves the target repaired and says which step it could not complete.\n\tasync #replace(command: OverwriteCommand): Promise<number> {\n\t\tconst target = command.target ?? '.'\n\t\tconst groups = this.#groups(command.groups)\n\t\tconst blueprint = this.#derive(target)\n\t\tthis.#assertProjects(target, blueprint)\n\t\tconst repository = this.#repository(target)\n\t\tif (repository.dirty.length > 0 && command.dirty !== true) {\n\t\t\tthrow new ScaffoldError(\n\t\t\t\t'TARGET',\n\t\t\t\t`The target at ${target} carries ${String(repository.dirty.length)} uncommitted change${repository.dirty.length === 1 ? '' : 's'}. Commit them, or pass --dirty to waive the refusal.`,\n\t\t\t\t{ target, dirty: repository.dirty.length },\n\t\t\t)\n\t\t}\n\t\tconst materializer = createMaterializer(\n\t\t\tcommand.from === undefined ? undefined : { host: command.from },\n\t\t)\n\t\ttry {\n\t\t\tconst [audit, plan] = this.#survey(materializer, blueprint, target, groups)\n\t\t\tif (plan === undefined) {\n\t\t\t\tif (command.json === true) this.#report(audit)\n\t\t\t\telse this.#present(audit)\n\t\t\t\treturn EXIT_DRIFT\n\t\t\t}\n\t\t\tconst repaired = materializer.repair(plan, audit, target)\n\t\t\t// The candidate set is the audit's own foreign findings, so a path the\n\t\t\t// plan claims is never a deletion candidate whatever the tree holds, and\n\t\t\t// neither is a path outside the vendored directories this plan expands.\n\t\t\t// `--dirty` is expressed here and nowhere else: the waiver clears the\n\t\t\t// refusal the observed dirty set would otherwise trigger downstream, and\n\t\t\t// waives nothing about which paths are eligible.\n\t\t\tconst removed = materializer.remove(\n\t\t\t\taudit,\n\t\t\t\tcommand.dirty === true ? { tracked: repository.tracked, dirty: [] } : repository,\n\t\t\t\ttarget,\n\t\t\t)\n\t\t\tconst offline = this.#merge(repaired, removed)\n\t\t\tconst online = await this.#reconcile(materializer, target, blueprint.dependencies)\n\t\t\tconst [terminal] = this.#survey(materializer, blueprint, target, groups)\n\t\t\tconst outcome: OverwriteResult = {\n\t\t\t\t...online,\n\t\t\t\t...this.#merge(offline, online),\n\t\t\t\taudit: terminal,\n\t\t\t}\n\t\t\tif (command.json === true) this.#report(outcome)\n\t\t\telse {\n\t\t\t\tthis.#present(terminal)\n\t\t\t\tthis.#recount(outcome)\n\t\t\t\tif (online.note !== undefined) this.#warn(online.note)\n\t\t\t}\n\t\t\tif (online.note !== undefined) return EXIT_DRIFT\n\t\t\treturn auditToExit(terminal)\n\t\t} finally {\n\t\t\tmaterializer.destroy()\n\t\t}\n\t}\n\n\t// The network half of `overwrite`, collected rather than thrown: the offline\n\t// half has already written, so a step that cannot complete is reported as the\n\t// step it was instead of discarding what already landed. It writes through the\n\t// verb's own materializer rather than opening a second one, so every byte the\n\t// run lands comes from the host the caller named once.\n\tasync #reconcile(\n\t\tmaterializer: MaterializerInterface,\n\t\ttarget: string,\n\t\tdeclared: readonly Dependency[],\n\t): Promise<Omit<OverwriteResult, 'audit'>> {\n\t\tconst previous = this.#previous(target)\n\t\ttry {\n\t\t\tconst releases = await this.#lookup(declared)\n\t\t\tconst fetched = await this.#fetch(target, false)\n\t\t\tconst written = this.#merge(\n\t\t\t\tthis.#publish(materializer, target, fetched.entries, fetched.mirrors),\n\t\t\t\tmaterializer.declare(this.#pin(releases), target),\n\t\t\t)\n\t\t\treturn {\n\t\t\t\t...written,\n\t\t\t\tentries: fetched.entries,\n\t\t\t\tmirrors: fetched.mirrors,\n\t\t\t\tdropped: previous.filter((name) => !fetched.entries.some((entry) => entry.name === name)),\n\t\t\t\treleases,\n\t\t\t}\n\t\t} catch (error) {\n\t\t\treturn {\n\t\t\t\ttarget,\n\t\t\t\twritten: [],\n\t\t\t\tskipped: [],\n\t\t\t\tremoved: [],\n\t\t\t\tentries: [],\n\t\t\t\tmirrors: [],\n\t\t\t\tdropped: [],\n\t\t\t\treleases: [],\n\t\t\t\tnote: `The catalog step did not complete: ${errorToEnvelope(error).error.message}`,\n\t\t\t}\n\t\t}\n\t}\n\n\t// Measure each declared range against the registry's latest release.\n\tasync #lookup(declared: readonly Dependency[]): Promise<readonly Release[]> {\n\t\tconst upstream = createUpstream(this.#upstream)\n\t\ttry {\n\t\t\treturn await upstream.lookup(declared)\n\t\t} finally {\n\t\t\tupstream.destroy()\n\t\t}\n\t}\n\n\t// Read the organization's published list and the guides the target draws on.\n\t// The workspace never fetches its own guide: that file is its own product.\n\tasync #fetch(\n\t\ttarget: string,\n\t\tall: boolean,\n\t): Promise<{ readonly entries: readonly CatalogEntry[]; readonly mirrors: readonly Mirror[] }> {\n\t\tconst manifest = this.#manifest(target)\n\t\tconst own = manifestToName(manifest)\n\t\tconst declared = manifestToDependencies(manifest).map((dependency) => dependency.name)\n\t\tconst upstream = createUpstream(this.#upstream)\n\t\ttry {\n\t\t\tconst entries = await upstream.catalog()\n\t\t\tconst names = (all ? entries.map((entry) => entry.name) : declared).filter(\n\t\t\t\t(name) => name !== own,\n\t\t\t)\n\t\t\tconst mirrors = await upstream.fetch(names, readSnapshot(target, names.map(nameToGuide)))\n\t\t\treturn { entries, mirrors }\n\t\t} finally {\n\t\t\tupstream.destroy()\n\t\t}\n\t}\n\n\t// Write the fetched guides to their mirrors and the published list to the\n\t// marker-bounded table, as one result.\n\t#publish(\n\t\tmaterializer: MaterializerInterface,\n\t\ttarget: string,\n\t\tentries: readonly CatalogEntry[],\n\t\tmirrors: readonly Mirror[],\n\t): MaterializeResult {\n\t\treturn this.#merge(materializer.mirror(mirrors, target), materializer.catalog(entries, target))\n\t}\n\n\t// The ranges a found release pins. A lookup that produced no answer names no\n\t// version, so it is left declared as it stands rather than rewritten to a\n\t// guess.\n\t#pin(releases: readonly Release[]): readonly Dependency[] {\n\t\tconst pinned: Dependency[] = []\n\t\tfor (const release of releases) {\n\t\t\tif (release.lookup === 'found')\n\t\t\t\tpinned.push({ name: release.name, range: `^${release.latest}` })\n\t\t}\n\t\treturn pinned\n\t}\n\n\t// Compile a blueprint into the plan it describes, or refuse with the questions\n\t// the gate raised.\n\t//\n\t// `new` is the only caller, and it chooses the shape rather than reading one, so\n\t// it refuses every question the gate raises, advisory or not: an advisory names\n\t// a workspace this package can describe honestly and should not create, and this\n\t// is the last moment the caller can pick a different shape. `#survey` is the\n\t// reading counterpart, and it carries the same advisories through instead.\n\t//\n\t// The refusal is `BLOCKED` whichever kind of question earned it, because both\n\t// are the one fact that code names: this blueprint will not be built. The\n\t// questions the message quotes are what tells the two apart, and a second code\n\t// would be a label for a fact they already carry.\n\t#compile(blueprint: Blueprint, groups?: readonly Group[]): Plan {\n\t\tconst compiler = createCompiler()\n\t\ttry {\n\t\t\tconst scaffolding = compiler.compile(blueprint, groups)\n\t\t\tif (scaffolding.plan !== undefined && scaffolding.questions.length === 0) {\n\t\t\t\treturn scaffolding.plan\n\t\t\t}\n\t\t\tthrow new ScaffoldError(\n\t\t\t\t'BLOCKED',\n\t\t\t\tscaffolding.questions.map((question) => `${question.field}: ${question.message}`).join(' '),\n\t\t\t\t{ questions: scaffolding.questions.length },\n\t\t\t)\n\t\t} finally {\n\t\t\tcompiler.destroy()\n\t\t}\n\t}\n\n\t// Compile a blueprint and compare its plan to what the target currently holds,\n\t// through the vendored host a write would draw on.\n\t//\n\t// The materializer owns the comparison because it is the only one that can\n\t// make it: the pure compile claims presence alone, so it reads a canon file a\n\t// consumer has edited as aligned and a vendored directory as one missing path\n\t// no write could ever satisfy. Hydrating first states the bytes and expands\n\t// the directory into the files the host actually stores, which is the same\n\t// derivation the repair that follows is held to.\n\t//\n\t// The compiler answers the refused case alone. A blueprint the gate closed\n\t// carries no plan, so there is nothing to hydrate and nothing to say about the\n\t// target; the audit carries the questions instead.\n\t#survey(\n\t\tmaterializer: MaterializerInterface,\n\t\tblueprint: Blueprint,\n\t\ttarget: string,\n\t\tgroups?: readonly Group[],\n\t): readonly [audit: Audit, plan: Plan | undefined] {\n\t\tconst compiler = createCompiler()\n\t\ttry {\n\t\t\tconst scaffolding = compiler.compile(blueprint, groups)\n\t\t\tif (scaffolding.plan === undefined) return [compiler.audit(blueprint, {}, groups), undefined]\n\t\t\t// The materializer answers for the target and the gate answers for the\n\t\t\t// blueprint, so an advisory the gate raised rides the comparison rather\n\t\t\t// than being dropped between them. It is non-blocking, so it changes no\n\t\t\t// exit code and never makes an aligned target drift.\n\t\t\tconst measured = materializer.audit(scaffolding.plan, target)\n\t\t\treturn [\n\t\t\t\t{ ...measured, questions: [...measured.questions, ...scaffolding.questions] },\n\t\t\t\tscaffolding.plan,\n\t\t\t]\n\t\t} finally {\n\t\t\tcompiler.destroy()\n\t\t}\n\t}\n\n\t// The blueprint a target describes about itself: manifest identity and fleet\n\t// packages, environment directories, and exact structural files. Services stay\n\t// unknown because their birth-owned script is not a declaration of its list.\n\t#derive(target: string): Blueprint {\n\t\tconst manifest = this.#manifest(target)\n\t\tconst declared = manifestToName(manifest)\n\t\tif (declared === undefined) {\n\t\t\tthrow new ScaffoldError('TARGET', `The manifest at ${target} declares no package name.`, {\n\t\t\t\ttarget,\n\t\t\t})\n\t\t}\n\t\tconst bin = resolveContainedPath(target, BIN_ENTRY_PATH)\n\t\tconst integration = resolveContainedPath(target, INTEGRATION_TEST_PATH)\n\t\tconst global = resolveContainedPath(target, GLOBAL_SETUP_PATH)\n\t\tconst showcase = resolveContainedPath(target, SHOWCASE_CONFIG_PATH)\n\t\treturn createBlueprint(declared.slice(declared.lastIndexOf('/') + 1), {\n\t\t\tsrc: this.#probe(target, 'src'),\n\t\t\tapp: this.#probe(target, 'app'),\n\t\t\tdependencies: manifestToDependencies(manifest),\n\t\t\tbin: bin !== undefined && isExactCaseFile(bin),\n\t\t\tintegration: integration !== undefined && isExactCaseFile(integration),\n\t\t\tglobal: global !== undefined && isExactCaseFile(global),\n\t\t\tshowcase: showcase !== undefined && isExactCaseFile(showcase),\n\t\t})\n\t}\n\n\t// Read literal Vitest project values from one shell command. Quotes group a\n\t// token but do not hide the option, while shell expansions make its value\n\t// unresolved and therefore refuse the write that asked the question.\n\t#scriptProjects(script: string): readonly string[] | undefined {\n\t\tconst tokens: Array<{ value: string; resolved: boolean }> = []\n\t\tlet value = ''\n\t\tlet resolved = true\n\t\tlet started = false\n\t\tlet quote: string | undefined\n\t\tfor (let index = 0; index < script.length; index += 1) {\n\t\t\tconst character = script[index]\n\t\t\tif (character === undefined) return undefined\n\t\t\tif (quote === undefined) {\n\t\t\t\tif (/\\s/.test(character)) {\n\t\t\t\t\tif (started) tokens.push({ value, resolved })\n\t\t\t\t\tvalue = ''\n\t\t\t\t\tresolved = true\n\t\t\t\t\tstarted = false\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (';&|()'.includes(character)) {\n\t\t\t\t\tif (started) tokens.push({ value, resolved })\n\t\t\t\t\tconst paired = script[index + 1] === character && (character === '&' || character === '|')\n\t\t\t\t\ttokens.push({ value: paired ? `${character}${character}` : character, resolved: true })\n\t\t\t\t\tvalue = ''\n\t\t\t\t\tresolved = true\n\t\t\t\t\tstarted = false\n\t\t\t\t\tif (paired) index += 1\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (character === '\"' || character === \"'\") {\n\t\t\t\t\tquote = character\n\t\t\t\t\tstarted = true\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (character === '\\\\') {\n\t\t\t\t\tconst escaped = script[index + 1]\n\t\t\t\t\tif (escaped === undefined) return undefined\n\t\t\t\t\tvalue += escaped\n\t\t\t\t\tstarted = true\n\t\t\t\t\tindex += 1\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (character === '$' || character === '`' || character === '%') resolved = false\n\t\t\t\tvalue += character\n\t\t\t\tstarted = true\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (character === quote) {\n\t\t\t\tquote = undefined\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (character === '\\\\' && quote === '\"') {\n\t\t\t\tconst escaped = script[index + 1]\n\t\t\t\tif (escaped === undefined) return undefined\n\t\t\t\tvalue += escaped\n\t\t\t\tindex += 1\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (quote === '\"' && (character === '$' || character === '`' || character === '%')) {\n\t\t\t\tresolved = false\n\t\t\t}\n\t\t\tvalue += character\n\t\t\tstarted = true\n\t\t}\n\t\tif (quote !== undefined) return undefined\n\t\tif (started) tokens.push({ value, resolved })\n\n\t\tconst projects: string[] = []\n\t\tfor (let index = 0; index < tokens.length; index += 1) {\n\t\t\tconst token = tokens[index]\n\t\t\tif (token === undefined) return undefined\n\t\t\tif (token.value === '--project') {\n\t\t\t\tconst project = tokens[index + 1]\n\t\t\t\tif (\n\t\t\t\t\tproject === undefined ||\n\t\t\t\t\t!project.resolved ||\n\t\t\t\t\tproject.value.length === 0 ||\n\t\t\t\t\t['&&', '||', ';', '|', '&', '(', ')'].includes(project.value)\n\t\t\t\t)\n\t\t\t\t\treturn undefined\n\t\t\t\tprojects.push(project.value)\n\t\t\t\tindex += 1\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (token.value.startsWith('--project=')) {\n\t\t\t\tconst project = token.value.slice('--project='.length)\n\t\t\t\tif (!token.resolved || project.length === 0) return undefined\n\t\t\t\tprojects.push(project)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!token.resolved && token.value.includes('--project')) return undefined\n\t\t}\n\t\treturn projects\n\t}\n\n\t// Report the manifest's Vitest calls that the planned root configuration\n\t// cannot register. Audit carries the advisory; writing verbs turn it into the\n\t// hard boundary that keeps a birth-owned script from pointing at a project\n\t// their content-owned configuration removed.\n\t#projectQuestion(target: string, blueprint: Blueprint, writing = false): Question | undefined {\n\t\tconst manifest = this.#manifest(target)\n\t\tconst guides = resolveContainedPath(target, GUIDES_TEST_PATH)\n\t\tconst planned = blueprintToRootVite(blueprint)\n\t\tconst parsed = parseJSON(manifest)\n\t\tconst scripts = isRecord(parsed) && isRecord(parsed.scripts) ? parsed.scripts : undefined\n\t\tconst absent = new Set<string>()\n\t\tlet unresolved = false\n\t\tif (scripts !== undefined) {\n\t\t\tfor (const script of Object.values(scripts)) {\n\t\t\t\tif (!isString(script) || !script.includes('vitest')) continue\n\t\t\t\tconst projects = this.#scriptProjects(script)\n\t\t\t\tif (projects === undefined) {\n\t\t\t\t\tunresolved = true\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfor (const project of projects) {\n\t\t\t\t\tconst guide = project === 'guides' && guides !== undefined && isExactCaseFile(guides)\n\t\t\t\t\tif (\n\t\t\t\t\t\t!planned.includes(`name: { label: '${project}',`) ||\n\t\t\t\t\t\t(project === 'guides' && !guide)\n\t\t\t\t\t) {\n\t\t\t\t\t\tabsent.add(project)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (absent.size === 0 && !unresolved) return undefined\n\t\tconst projects = [...absent].sort()\n\t\tif (unresolved) {\n\t\t\treturn {\n\t\t\t\tfield: 'projects',\n\t\t\t\tmessage: `The manifest at ${target} contains a Vitest project expression that cannot be resolved statically.${projects.length === 0 ? '' : ` It also names projects the planned configuration does not register: ${projects.join(', ')}.`} ${writing ? 'Replace it with a literal --project value or remove the script before using a scaffold writing verb.' : 'Replace it with a literal --project value before relying on the planned configuration.'}`,\n\t\t\t\tblocking: false,\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tfield: 'projects',\n\t\t\tmessage: writing\n\t\t\t\t? `The manifest at ${target} names ${projects.length === 1 ? 'a Vitest project' : 'Vitest projects'} the planned configuration does not register: ${projects.join(', ')}. To continue, remove the ${projects.length === 1 ? 'script that names it' : 'scripts that name them'} or do not use scaffold writing verbs on a workspace that needs ${projects.length === 1 ? 'a custom Vitest project' : 'custom Vitest projects'}.`\n\t\t\t\t: `The manifest at ${target} names ${projects.length === 1 ? 'a Vitest project' : 'Vitest projects'} the planned configuration does not register: ${projects.join(', ')}. Add ${projects.length === 1 ? 'the project' : 'each project'} to vite.config.ts or remove the ${projects.length === 1 ? 'script that names it' : 'scripts that name them'}.`,\n\t\t\tblocking: false,\n\t\t}\n\t}\n\n\t// Writing verbs refuse the advisory because their next step would replace the\n\t// configuration. Audit alone may report it without changing the target.\n\t#assertProjects(target: string, blueprint: Blueprint): void {\n\t\tconst question = this.#projectQuestion(target, blueprint, true)\n\t\tif (question === undefined) return\n\t\tthrow new ScaffoldError('TARGET', question.message, { target })\n\t}\n\n\t// A target's manifest text, which every reading verb needs before it can say\n\t// anything about the target at all.\n\t#manifest(target: string): string {\n\t\tconst manifest = readFileText(target, 'package.json', MAX_MANIFEST_BYTES)\n\t\tif (manifest === undefined) {\n\t\t\tthrow new ScaffoldError('TARGET', `The target at ${target} carries no readable manifest.`, {\n\t\t\t\ttarget,\n\t\t\t})\n\t\t}\n\t\treturn manifest\n\t}\n\n\t// The environments one axis physically ships, read as directories rather than\n\t// declared, because a directory is the fact and a declaration would be a\n\t// second copy of it free to disagree.\n\t#probe(target: string, axis: string): readonly Environment[] {\n\t\treturn ENVIRONMENTS.filter((environment) => {\n\t\t\tconst full = resolveContainedPath(target, `${axis}/${environment}`)\n\t\t\treturn full !== undefined && isPhysicalDirectory(full)\n\t\t})\n\t}\n\n\t// The packages the target's catalog table listed before this run. Read through\n\t// the declared markdown parser rather than by pattern, so a row is a row\n\t// because the document says so.\n\t#previous(target: string): readonly string[] {\n\t\tconst text = readFileText(target, CATALOG_AGENT_PATH)\n\t\tif (text === undefined) return []\n\t\tconst names: string[] = []\n\t\tfor (const table of createMarkdown(text).filter(isTableNode)) {\n\t\t\tfor (const row of table.rows) {\n\t\t\t\tconst [cell] = row\n\t\t\t\tif (cell === undefined) continue\n\t\t\t\tconst name = cell.map(flattenText).join('').trim()\n\t\t\t\tif (DEPENDENCY_NAME_PATTERN.test(name)) names.push(name)\n\t\t\t}\n\t\t}\n\t\treturn names\n\t}\n\n\t// What git reports about the target's working tree. Deletion draws only on\n\t// what git tracks and refuses a tree carrying uncommitted work, so a target\n\t// that is not a repository has no recovery mechanism and is refused here.\n\t#repository(target: string): Repository {\n\t\tconst tracked = this.#inventory(target, ['ls-files', '-z'])\n\t\tconst dirty = this.#inventory(target, [\n\t\t\t'status',\n\t\t\t'--porcelain=v1',\n\t\t\t'--untracked-files=all',\n\t\t\t'-z',\n\t\t]).map((record) => (record.length > 3 && record[2] === ' ' ? record.slice(3) : record))\n\t\tconst state = { tracked, dirty }\n\t\tif (!isRepository(state)) {\n\t\t\tthrow new ScaffoldError('TARGET', `The git state at ${target} is not a readable inventory.`, {\n\t\t\t\ttarget,\n\t\t\t\ttracked: tracked.length,\n\t\t\t\tdirty: dirty.length,\n\t\t\t})\n\t\t}\n\t\treturn state\n\t}\n\n\t// One git query, answered as its NUL-separated records. Git is asked rather\n\t// than reimplemented, because the tracked set and the dirty set are git's own\n\t// answers and nothing else can give them.\n\t#inventory(target: string, args: readonly string[]): readonly string[] {\n\t\tconst read = attempt(() =>\n\t\t\texecFileSync('git', [...args], {\n\t\t\t\tcwd: target,\n\t\t\t\tencoding: 'utf8',\n\t\t\t\twindowsHide: true,\n\t\t\t\tmaxBuffer: MAX_MANIFEST_BYTES,\n\t\t\t\t// git writes its own refusal to its own stderr, and this class owns\n\t\t\t\t// what leaves it: a failure is reported through the diagnostic handler\n\t\t\t\t// the caller supplied, never straight onto a stream nobody chose.\n\t\t\t\tstdio: ['ignore', 'pipe', 'ignore'],\n\t\t\t}),\n\t\t)\n\t\tif (!read.success) {\n\t\t\tthrow new ScaffoldError('TARGET', `The target at ${target} is not a git repository.`, {\n\t\t\t\ttarget,\n\t\t\t})\n\t\t}\n\t\treturn read.value.split('\\0').filter((record) => record.length > 0)\n\t}\n\n\t// The environments a comma-separated selection names, refused by name when it\n\t// names something that is not one.\n\t#environments(selection: string | undefined, axis: string): readonly Environment[] {\n\t\tif (selection === undefined) return []\n\t\tconst requested = selection.split(',')\n\t\tconst refused = requested.filter(\n\t\t\t(name) => !ENVIRONMENTS.some((environment) => environment === name),\n\t\t)\n\t\tif (refused.length > 0) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`'--${axis}' does not take ${refused.join(', ')}. It takes ${ENVIRONMENTS.join(', ')}.`,\n\t\t\t)\n\t\t}\n\t\treturn ENVIRONMENTS.filter((environment) => requested.includes(environment))\n\t}\n\n\t// The groups a comma-separated selection names; absence covers every group.\n\t#groups(selection: string | undefined): readonly Group[] | undefined {\n\t\tif (selection === undefined) return undefined\n\t\tconst requested = selection.split(',')\n\t\tconst refused = requested.filter((name) => !GROUPS.some((group) => group === name))\n\t\tif (refused.length > 0) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`'--groups' does not take ${refused.join(', ')}. It takes ${GROUPS.join(', ')}.`,\n\t\t\t)\n\t\t}\n\t\treturn GROUPS.filter((group) => requested.includes(group))\n\t}\n\n\t// The fleet packages a comma-separated selection names.\n\t#packages(selection: string | undefined): readonly string[] {\n\t\tif (selection === undefined) return []\n\t\tconst requested = selection.split(',')\n\t\tconst refused = requested.filter((name) => !DEPENDENCY_NAME_PATTERN.test(name))\n\t\tif (refused.length > 0) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`'--deps' does not take ${refused.join(', ')}. Every name is a published @orkestrel package.`,\n\t\t\t)\n\t\t}\n\t\treturn requested\n\t}\n\n\t// Pin each named package to the registry's latest release. A name upstream\n\t// cannot answer for is refused rather than pinned to an invented range: the\n\t// workspace would carry a dependency that does not resolve.\n\tasync #resolve(names: readonly string[]): Promise<readonly Dependency[]> {\n\t\tif (names.length === 0) return []\n\t\tconst upstream = createUpstream(this.#upstream)\n\t\tlet releases: readonly Release[]\n\t\ttry {\n\t\t\treleases = await upstream.lookup(names.map((name) => ({ name, range: '*' })))\n\t\t} finally {\n\t\t\tupstream.destroy()\n\t\t}\n\t\tconst refused = releases.filter((release) => release.lookup !== 'found')\n\t\tif (refused.length > 0) {\n\t\t\tthrow new ScaffoldError(\n\t\t\t\t'FETCH',\n\t\t\t\t`The registry named no release for ${refused.map((release) => release.name).join(', ')}.`,\n\t\t\t\t{ names: refused.length },\n\t\t\t)\n\t\t}\n\t\treturn this.#pin(releases)\n\t}\n\n\t// Two results of one run, read as one. Written and skipped never overlap\n\t// across the calls a verb makes, because each call answers for its own paths.\n\t#merge(first: MaterializeResult, second: MaterializeResult): MaterializeResult {\n\t\treturn {\n\t\t\ttarget: first.target,\n\t\t\twritten: [...first.written, ...second.written],\n\t\t\tskipped: [...first.skipped, ...second.skipped],\n\t\t\tremoved: [...first.removed, ...second.removed],\n\t\t}\n\t}\n\n\t// The audit as a person reads it: every advisory first, then one row per path\n\t// that differs, then the summary. An aligned path is not listed, because a\n\t// report of everything that is fine is a report nobody reads.\n\t#present(audit: Audit): void {\n\t\tfor (const question of audit.questions) this.#warn(`${question.field}: ${question.message}`)\n\t\tconst rows = audit.findings\n\t\t\t.filter((finding) => finding.drift !== 'aligned')\n\t\t\t.map((finding) => [finding.path, finding.group, finding.drift])\n\t\tif (rows.length > 0) {\n\t\t\tconst table = renderTable({\n\t\t\t\tcolumns: [{ label: 'path' }, { label: 'group' }, { label: 'drift' }],\n\t\t\t\trows,\n\t\t\t})\n\t\t\tfor (const line of table.split('\\n')) this.#say(line)\n\t\t}\n\t\tthis.#say(auditToSummary(audit))\n\t}\n\n\t// The catalog outcome as a person reads it.\n\t#recount(result: CatalogResult): void {\n\t\tthis.#say(this.#tally(result))\n\t\tthis.#say(\n\t\t\t`${String(result.entries.length)} published, ${String(result.mirrors.filter((mirror) => mirror.lookup === 'found').length)} guide${result.mirrors.length === 1 ? '' : 's'} fetched, ${String(result.dropped.length)} no longer listed.`,\n\t\t)\n\t\tfor (const mirror of result.mirrors) {\n\t\t\tif (mirror.lookup !== 'found') this.#warn(`${mirror.name}: ${mirror.note}`)\n\t\t}\n\t}\n\n\t// One line stating what a mutation did.\n\t#tally(result: MaterializeResult): string {\n\t\treturn `${String(result.written.length)} written, ${String(result.skipped.length)} unchanged, ${String(result.removed.length)} removed in ${result.target}.`\n\t}\n\n\t// The one machine-readable value a `--json` run emits.\n\t#report(value: unknown): void {\n\t\tthis.#say(JSON.stringify(value))\n\t}\n\n\t// Report a refusal under the code it carries and answer with the code it\n\t// earned: a command line that was not a command is a usage error, and\n\t// everything else is a failed run.\n\t#refuse(error: unknown, json: boolean): number {\n\t\tconst envelope = errorToEnvelope(error)\n\t\tif (json) this.#report(envelope)\n\t\telse this.#warn(`${envelope.error.code}: ${envelope.error.message}`)\n\t\treturn isUsageError(error) ? EXIT_USAGE : EXIT_DRIFT\n\t}\n\n\t#say(line: string): void {\n\t\tthis.#output(this.#sanitize(line))\n\t}\n\n\t#warn(line: string): void {\n\t\tthis.#diagnostic(this.#sanitize(line))\n\t}\n\n\t// The single write path, and the only place hostile bytes are answered for.\n\t// A refusal quotes the argument that caused it, so an escape sequence, a bell,\n\t// or a forged second line arrives here inside otherwise ordinary prose. ANSI\n\t// escapes go first because they are what repaints a terminal, control\n\t// characters next, and what remains is folded onto one line because a handler\n\t// takes one line and a caller writing a record per call must get one record.\n\t#sanitize(line: string): string {\n\t\treturn stripControls(strip(line)).split(/\\r?\\n/).join(' ')\n\t}\n}\n","// The executable entry, and the only module that touches process state: it reads\n// the arguments the process was given and assigns the code the run returned. The\n// `#!/usr/bin/env node` shebang is re-emitted by the build's `output.banner`\n// rather than written here, because the bundler strips a shebang from source.\nimport { CLI } from './CLI.js'\n\nprocess.stdout.on('error', (error) => {\n\tif ('code' in error && error.code === 'EPIPE') return\n\tthrow error\n})\nprocess.exitCode = await new CLI().execute(process.argv.slice(2))\n"],"mappings":";;;;;;;;;;;;;;;;;AAWA,IAAa,kBAAkB;;;;;;;;;AAU/B,IAAa,QAAyB,OAAO,OAAO;CACnD;CACA;CACA;CACA;CACA;AACD,CAAC;;;;;;;;AAkBD,IAAa,eAAiD,OAAO,OAAO;EAC7D,IAAA;EACA,IAAA;EACA,IAAA;AACf,CAAC;;;;;;;;;;AAWD,IAAa,aAAa;;AAG1B,IAAa,cAAc;;AAG3B,IAAa,iBAAiB;;;;;;;;AAS9B,IAAa,gBAAgB;;;;;;;;;;;;;;AAe7B,IAAa,kBAA0C,OAAO,OAAO;CACpE,KAAK,OAAO,OAAO,EAAE,MAAM,SAAS,CAAC;CACrC,KAAK,OAAO,OAAO,EAAE,MAAM,SAAS,CAAC;CACrC,KAA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