@penvhq/launcher 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/bin.cjs +1519 -0
- package/dist/bin.cjs.map +1 -0
- package/dist/bin.d.cts +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +55 -0
- package/dist/bin.js.map +1 -0
- package/dist/chunk-2AF67CKY.js +1552 -0
- package/dist/chunk-2AF67CKY.js.map +1 -0
- package/dist/index.cjs +1628 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +601 -0
- package/dist/index.d.ts +601 -0
- package/dist/index.js +135 -0
- package/dist/index.js.map +1 -0
- package/package.json +31 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config-edit.ts","../src/errors.ts","../src/declaration.ts","../src/home.ts","../src/integrity.ts","../src/tar.ts","../src/store.ts","../src/registry.ts","../src/add.ts","../src/repair.ts","../src/delegate.ts","../src/engine.ts","../src/fetcher.ts","../src/pins.ts","../src/project.ts","../src/launcher.ts"],"sourcesContent":["/**\n * The one-line edit `add` offers to `penv.config.ts`.\n *\n * The file is the user's, so it is scanned rather than parsed and re-emitted:\n * reformatting someone's config — dropping its comments, resorting its keys — to\n * change one string is not the edit that was offered. The scanner understands\n * exactly one thing, the `providers` block, and answers \"I do not know this\n * file\" for anything else rather than guessing at a rewrite.\n */\n\n/** One environment's entry in the `providers` block. */\nexport interface ProviderEntry {\n readonly environment: string;\n /** The package it names today, when the entry declares a `type` string. */\n readonly type: string | undefined;\n}\n\ninterface TypeSlot {\n /** The `type` string literal's bounds, quotes included. */\n readonly start: number;\n readonly end: number;\n readonly value: string;\n}\n\ninterface Entry extends ProviderEntry {\n readonly slot: TypeSlot | undefined;\n}\n\nconst QUOTES = new Set(['\"', \"'\", \"`\"]);\n\n/** The index after whitespace and comments starting at `index`. */\nfunction skipTrivia(source: string, index: number): number {\n let i = index;\n for (;;) {\n const ch = source.charAt(i);\n if (ch === \" \" || ch === \"\\t\" || ch === \"\\n\" || ch === \"\\r\") {\n i += 1;\n continue;\n }\n if (ch === \"/\" && source.charAt(i + 1) === \"/\") {\n const end = source.indexOf(\"\\n\", i);\n i = end === -1 ? source.length : end + 1;\n continue;\n }\n if (ch === \"/\" && source.charAt(i + 1) === \"*\") {\n const end = source.indexOf(\"*/\", i + 2);\n i = end === -1 ? source.length : end + 2;\n continue;\n }\n return i;\n }\n}\n\n/** The index after a string or template literal opening at `index`. */\nfunction skipString(source: string, index: number): number {\n const quote = source.charAt(index);\n let i = index + 1;\n while (i < source.length) {\n const ch = source.charAt(i);\n if (ch === \"\\\\\") {\n i += 2;\n continue;\n }\n if (ch === quote) {\n return i + 1;\n }\n i += 1;\n }\n return source.length;\n}\n\n/** The index just past the `}` matching the `{` at `open`, or -1. */\nfunction matchBrace(source: string, open: number): number {\n let depth = 0;\n let i = open;\n while (i < source.length) {\n const ch = source.charAt(i);\n if (QUOTES.has(ch)) {\n i = skipString(source, i);\n continue;\n }\n const skipped = skipTrivia(source, i);\n if (skipped !== i) {\n i = skipped;\n continue;\n }\n if (ch === \"{\" || ch === \"[\" || ch === \"(\") {\n depth += 1;\n } else if (ch === \"}\" || ch === \"]\" || ch === \")\") {\n depth -= 1;\n if (depth === 0) {\n return i + 1;\n }\n }\n i += 1;\n }\n return -1;\n}\n\n/** An object key at `index` — `\"name\"`, `'name'` or a bare identifier — and where it ends. */\nfunction readKey(source: string, index: number): { key: string; end: number } | undefined {\n const ch = source.charAt(index);\n if (ch === '\"' || ch === \"'\") {\n const end = skipString(source, index);\n return { key: source.slice(index + 1, end - 1), end };\n }\n const match = /^[A-Za-z_$][A-Za-z0-9_$]*/.exec(source.slice(index));\n return match === null ? undefined : { key: match[0], end: index + match[0].length };\n}\n\n/** The `type: \"...\"` literal directly inside one entry, when it has one. */\nfunction typeSlotIn(source: string, open: number, close: number): TypeSlot | undefined {\n let i = skipTrivia(source, open + 1);\n while (i < close - 1) {\n const key = readKey(source, i);\n if (key === undefined) {\n return undefined;\n }\n const colon = skipTrivia(source, key.end);\n if (source.charAt(colon) !== \":\") {\n return undefined;\n }\n const valueStart = skipTrivia(source, colon + 1);\n const ch = source.charAt(valueStart);\n let valueEnd: number;\n if (QUOTES.has(ch)) {\n valueEnd = skipString(source, valueStart);\n if (key.key === \"type\" && ch !== \"`\") {\n return {\n start: valueStart,\n end: valueEnd,\n value: source.slice(valueStart + 1, valueEnd - 1),\n };\n }\n } else if (ch === \"{\" || ch === \"[\" || ch === \"(\") {\n valueEnd = matchBrace(source, valueStart);\n if (valueEnd === -1) {\n return undefined;\n }\n } else {\n const comma = /[,}]/.exec(source.slice(valueStart));\n valueEnd = comma === null ? close - 1 : valueStart + comma.index;\n }\n i = skipTrivia(source, valueEnd);\n if (source.charAt(i) === \",\") {\n i = skipTrivia(source, i + 1);\n }\n }\n return undefined;\n}\n\n/** The `providers` block's entries, or `undefined` for a config penv cannot read. */\nfunction scan(source: string): Entry[] | undefined {\n const found = /(?:^|[\\s{,;])providers\\s*:\\s*\\{/.exec(source);\n if (found === null) {\n return undefined;\n }\n const open = found.index + found[0].length - 1;\n const close = matchBrace(source, open);\n if (close === -1) {\n return undefined;\n }\n\n const entries: Entry[] = [];\n let i = skipTrivia(source, open + 1);\n while (i < close - 1) {\n const key = readKey(source, i);\n if (key === undefined) {\n return undefined;\n }\n const colon = skipTrivia(source, key.end);\n if (source.charAt(colon) !== \":\") {\n return undefined;\n }\n const entryOpen = skipTrivia(source, colon + 1);\n if (source.charAt(entryOpen) !== \"{\") {\n return undefined;\n }\n const entryClose = matchBrace(source, entryOpen);\n if (entryClose === -1) {\n return undefined;\n }\n const slot = typeSlotIn(source, entryOpen, entryClose);\n entries.push({ environment: key.key, type: slot?.value, slot });\n i = skipTrivia(source, entryClose);\n if (source.charAt(i) === \",\") {\n i = skipTrivia(source, i + 1);\n }\n }\n return entries;\n}\n\n/** Every environment the `providers` block names, in the order the file declares them. */\nexport function readProviderEntries(source: string): ProviderEntry[] | undefined {\n return scan(source)?.map(({ environment, type }) => ({ environment, type }));\n}\n\n/** The same text with one environment pointed at `type`, or `undefined` if it cannot be. */\nexport function setProviderType(\n source: string,\n environment: string,\n type: string,\n): string | undefined {\n const entry = scan(source)?.find((candidate) => candidate.environment === environment);\n if (entry?.slot === undefined) {\n return undefined;\n }\n return `${source.slice(0, entry.slot.start)}${JSON.stringify(type)}${source.slice(entry.slot.end)}`;\n}\n","/**\n * What the launcher refuses, and the one command that clears each refusal.\n *\n * Every one of these is a wrong-bytes or no-bytes answer to the same question —\n * which penv is this project's — so they all name the package, the version, and\n * a single next command. Only the two engine-pin refusals mention the\n * launcher/engine split, because a launcher that cannot record which engine it\n * ran is the one failure that cannot be described without it; the rest name a\n * package and a command, and leave penv looking like one program.\n */\n\nimport {\n ENGINE_PACKAGE,\n EXTENSIONS_PATH,\n MANIFEST_PATH,\n OFFICIAL_SCOPE,\n PenvError,\n} from \"@penvhq/core\";\n\n/** The command that materializes everything the manifest pins. */\nexport const INSTALL_COMMAND = \"penv install\";\n\n/** How long a package outside the official scope must have existed. */\nexport const MIN_PACKAGE_AGE_DAYS = 7;\n\n/** The flag that overrides {@link MIN_PACKAGE_AGE_DAYS}, and only that. */\nexport const TRUST_YOUNG_FLAG = \"--trust-young\";\n\n/** The `penv add` that would repeat this exact decision. */\nfunction addCommand(name: string, version?: string, extra?: string): string {\n const spec = version === undefined ? name : `${name}@${version}`;\n return `penv add ${spec}${extra === undefined ? \"\" : ` ${extra}`}`;\n}\n\n/** The command was typed outside any penv project. */\nexport class NoProjectError extends PenvError {\n override readonly name = \"NoProjectError\";\n\n constructor(cwd: string) {\n super(\n \"PENV_NO_PROJECT\",\n `penv found no ${MANIFEST_PATH} in ${cwd} or any parent directory`,\n \"Run `penv init` here to adopt this project.\",\n );\n }\n}\n\n/** The pinned bytes are not on this machine, and this run does not download. */\nexport class PackageMissingError extends PenvError {\n override readonly name = \"PackageMissingError\";\n\n constructor(name: string, version: string, home: string) {\n super(\n \"PENV_PACKAGE_MISSING\",\n `${name} ${version} is not installed in ${home}, and this run does not download`,\n `Run \\`${INSTALL_COMMAND}\\` — CI and production install the versions the manifest pins ` +\n \"before the command that needs them.\",\n );\n }\n}\n\n/** The bytes on this machine are not the bytes the manifest pins. */\nexport class PackageCorruptError extends PenvError {\n override readonly name = \"PackageCorruptError\";\n\n constructor(name: string, version: string, dir: string) {\n super(\n \"PENV_PACKAGE_CORRUPT\",\n `${name} ${version} in ${dir} is not the bytes ${MANIFEST_PATH} pins`,\n `Delete ${dir} and run \\`${INSTALL_COMMAND}\\` — penv runs the exact bytes the manifest ` +\n \"names, or nothing.\",\n );\n }\n}\n\n/** The download was offered and declined. */\nexport class InstallDeclinedError extends PenvError {\n override readonly name = \"InstallDeclinedError\";\n\n constructor(name: string, version: string) {\n super(\n \"PENV_INSTALL_DECLINED\",\n `${name} ${version} was not downloaded`,\n `Run \\`${INSTALL_COMMAND}\\` when you want penv to fetch the versions this project pins.`,\n );\n }\n}\n\n/** The registry could not be reached, or answered with something other than the tarball. */\nexport class DownloadFailedError extends PenvError {\n override readonly name = \"DownloadFailedError\";\n\n constructor(name: string, version: string, url: string, detail: string) {\n super(\n \"PENV_DOWNLOAD_FAILED\",\n `Downloading ${name} ${version} from ${url} failed: ${detail}`,\n `Run \\`${INSTALL_COMMAND}\\` again when the registry is reachable.`,\n );\n }\n}\n\n/** The registry served bytes the manifest does not pin. Nothing is installed. */\nexport class DownloadIntegrityError extends PenvError {\n override readonly name = \"DownloadIntegrityError\";\n\n constructor(name: string, version: string, url: string) {\n super(\n \"PENV_DOWNLOAD_INTEGRITY\",\n `${name} ${version} from ${url} is not the bytes ${MANIFEST_PATH} pins`,\n `Check the registry — the bytes it served are not the ones the pin was reviewed against, ` +\n \"so penv installed nothing.\",\n );\n }\n}\n\n/** An archive entry penv will not write to disk. */\nexport class ArchiveError extends PenvError {\n override readonly name = \"ArchiveError\";\n\n constructor(name: string, version: string, entry: string) {\n super(\n \"PENV_ARCHIVE\",\n `The ${name} ${version} archive holds \\`${entry}\\`, which penv will not extract`,\n \"Check the registry — penv extracts regular files under `package/` and nothing else.\",\n );\n }\n}\n\n/** `penv add` with nothing to add. */\nexport class AddSubjectError extends PenvError {\n override readonly name = \"AddSubjectError\";\n\n constructor() {\n super(\n \"PENV_ADD_SUBJECT\",\n \"`penv add` names no package\",\n \"Run `penv add @penvhq/provider-vault`, or any provider package name — optionally with \" +\n \"`@<version>` to pin one other than the latest.\",\n );\n }\n}\n\n/** A package name npm would not recognise. */\nexport class AddPackageNameError extends PenvError {\n override readonly name = \"AddPackageNameError\";\n\n constructor(spec: string) {\n super(\n \"PENV_ADD_PACKAGE_NAME\",\n `\\`${spec}\\` is not an npm package name`,\n \"Name the package exactly as npm does, e.g. `penv add @acme/provider-consul@1.4.2`.\",\n );\n }\n}\n\n/** A flag `penv add` does not have. */\nexport class AddFlagError extends PenvError {\n override readonly name = \"AddFlagError\";\n\n constructor(flag: string) {\n super(\n \"PENV_ADD_FLAG\",\n `\\`penv add\\` does not understand \\`${flag}\\``,\n `Run \\`penv add <package>\\` with \\`${TRUST_YOUNG_FLAG}\\` or \\`--registry <url>\\` — those ` +\n \"are the two it takes.\",\n );\n }\n}\n\n/** `--registry` with something that is not an https origin. */\nexport class AddRegistryError extends PenvError {\n override readonly name = \"AddRegistryError\";\n\n constructor(value: string) {\n super(\n \"PENV_ADD_REGISTRY\",\n `\\`--registry ${value}\\` is not an https URL`,\n \"Write the registry's origin, e.g. `--registry https://npm.acme.internal`. Over plain http \" +\n \"the integrity check proves only that you got the bytes an attacker on the network chose.\",\n );\n }\n}\n\n/** penv's own packages, offered by a registry that is not npmjs. */\nexport class OfficialRegistryError extends PenvError {\n override readonly name = \"OfficialRegistryError\";\n\n constructor(name: string, registry: string) {\n super(\n \"PENV_OFFICIAL_REGISTRY\",\n `${name} was asked for from ${registry}, and \\`${OFFICIAL_SCOPE}*\\` packages come from npmjs`,\n `Run \\`${addCommand(name)}\\` without \\`--registry\\`. The official scope is the one penv ` +\n \"adds without a trust question, so penv will not take it from somewhere else.\",\n );\n }\n}\n\n/** The registry could not be read at all. */\nexport class RegistryUnreadableError extends PenvError {\n override readonly name = \"RegistryUnreadableError\";\n\n constructor(name: string, url: string, detail: string) {\n super(\n \"PENV_REGISTRY_UNREADABLE\",\n `Reading ${name} from ${url} failed: ${detail}`,\n `Run \\`${addCommand(name)}\\` again when the registry is reachable.`,\n );\n }\n}\n\n/** The registry has no such package. */\nexport class PackageUnknownError extends PenvError {\n override readonly name = \"PackageUnknownError\";\n\n constructor(name: string, url: string) {\n super(\n \"PENV_PACKAGE_UNKNOWN\",\n `${url} publishes no versions of ${name}`,\n \"Check the package name against the registry — penv adds a package that exists or nothing.\",\n );\n }\n}\n\n/** The package exists; the version asked for does not. */\nexport class VersionUnknownError extends PenvError {\n override readonly name = \"VersionUnknownError\";\n\n constructor(name: string, version: string, url: string) {\n super(\n \"PENV_VERSION_UNKNOWN\",\n `${url} publishes no ${version} of ${name}`,\n `Run \\`${addCommand(name)}\\` to take the version \\`latest\\` points at.`,\n );\n }\n}\n\n/** The registry answered, but without a fact the manifest has to record. */\nexport class ReleaseIncompleteError extends PenvError {\n override readonly name = \"ReleaseIncompleteError\";\n\n constructor(name: string, version: string, url: string, missing: string) {\n super(\n \"PENV_RELEASE_INCOMPLETE\",\n `${url} records no ${missing} for ${name} ${version}`,\n `Check the registry — the manifest pins ${missing} for every package, so penv records what ` +\n \"the registry states or refuses to record it at all.\",\n );\n }\n}\n\n/** A third-party package younger than the age gate, with no override. */\nexport class PackageTooYoungError extends PenvError {\n override readonly name = \"PackageTooYoungError\";\n\n constructor(name: string, version: string, publishedAt: string) {\n super(\n \"PENV_PACKAGE_TOO_YOUNG\",\n `${name} ${version} was published ${publishedAt}, and penv waits ${MIN_PACKAGE_AGE_DAYS} ` +\n `days before adding a package outside \\`${OFFICIAL_SCOPE}*\\``,\n `Run \\`${addCommand(name, version, TRUST_YOUNG_FLAG)}\\` to add it anyway and record why. ` +\n \"The wait is there because a hijacked publish is usually caught within days.\",\n );\n }\n}\n\n/**\n * Extension entries penv could not read, that the command in hand does not repair.\n *\n * One unreadable entry is what `penv add <pkg>` exists to rewrite, so that is the\n * remedy. More than one is beyond a single `add` — each rewrites only its own —\n * and the manifest is committed, so the file itself is the thing to restore.\n */\nexport class ManifestEntriesUnreadableError extends PenvError {\n override readonly name = \"ManifestEntriesUnreadableError\";\n\n constructor(names: readonly string[]) {\n const one = names.length === 1;\n super(\n \"PENV_MANIFEST_ENTRIES_UNREADABLE\",\n `${MANIFEST_PATH} holds ${one ? \"an extension entry\" : \"extension entries\"} penv cannot ` +\n `read: ${names.join(\", \")}`,\n one\n ? `Run \\`${addCommand(names[0] ?? \"\")}\\` to rewrite that entry — it resolves the package ` +\n \"again and records what the registry states.\"\n : `Restore it with \\`git checkout ${MANIFEST_PATH}\\`. Each \\`penv add\\` rewrites only its ` +\n \"own entry, so more than one broken entry is not something one of them can fix.\",\n );\n }\n}\n\n/** `penv add` needs the registry, and `--no-download` says this run has no network. */\nexport class AddNoDownloadError extends PenvError {\n override readonly name = \"AddNoDownloadError\";\n\n constructor(name: string) {\n super(\n \"PENV_ADD_NO_DOWNLOAD\",\n `Adding ${name} means reading the registry for the version and integrity to pin, and ` +\n \"`--no-download` says this run does not\",\n `Run \\`${addCommand(name)}\\` without \\`--no-download\\`. Nothing was fetched or written.`,\n );\n }\n}\n\n/**\n * `penv add` on a machine with nobody at it.\n *\n * It is refused everywhere, not only for the packages that pay the trust\n * ceremony: what `add` writes is two committed files, and a pipeline that\n * rewrites the manifest it was handed is a pipeline choosing which bytes the\n * project runs. `penv install` is the command CI has, and it installs exactly\n * what a person already decided.\n */\nexport class AddNotInteractiveError extends PenvError {\n override readonly name = \"AddNotInteractiveError\";\n\n constructor(name: string) {\n super(\n \"PENV_ADD_NOT_INTERACTIVE\",\n `Adding ${name} rewrites ${MANIFEST_PATH}, and this run has nobody to decide that`,\n `Run \\`${addCommand(name)}\\` from a terminal and commit what it writes. In CI, run ` +\n `\\`${INSTALL_COMMAND}\\` — it installs the versions the committed manifest already pins.`,\n );\n }\n}\n\n/** The trust ceremony was declined. Nothing was installed or recorded. */\nexport class TrustDeclinedError extends PenvError {\n override readonly name = \"TrustDeclinedError\";\n\n constructor(name: string, version: string) {\n super(\n \"PENV_TRUST_DECLINED\",\n `${name} ${version} was not trusted, so penv installed and recorded nothing`,\n `Run \\`${addCommand(name, version)}\\` again when you have reviewed what it does.`,\n );\n }\n}\n\n/** A third-party trust block with nobody named in it. */\nexport class TrustPublisherMissingError extends PenvError {\n override readonly name = \"TrustPublisherMissingError\";\n\n constructor(name: string, version: string) {\n super(\n \"PENV_TRUST_PUBLISHER_MISSING\",\n `The publisher of ${name} ${version} was left empty, and the registry names none either`,\n `Run \\`${addCommand(name, version)}\\` again and name the npm account you checked — a ` +\n \"third-party trust block records who was trusted, not only that someone was.\",\n );\n }\n}\n\n/** The trust block's one human field came back empty. */\nexport class TrustReasonMissingError extends PenvError {\n override readonly name = \"TrustReasonMissingError\";\n\n constructor(name: string, version: string) {\n super(\n \"PENV_TRUST_REASON_MISSING\",\n `The reason for trusting ${name} ${version} was left empty`,\n `Run \\`${addCommand(name, version)}\\` again and write one line on what you checked — the ` +\n \"next reviewer reads that line, not the diff.\",\n );\n }\n}\n\n/** `penv.types` names a file the published package does not contain. */\nexport class DeclarationMissingError extends PenvError {\n override readonly name = \"DeclarationMissingError\";\n\n constructor(name: string, file: string) {\n super(\n \"PENV_DECLARATION_MISSING\",\n `${name} declares its types at \\`${file}\\`, and the published package has no such file`,\n `Report it to ${name}. penv commits the declaration a provider ships, so it will not ` +\n \"invent one that claims to describe this provider's configuration.\",\n );\n }\n}\n\n/** The declaration a package ships reaches for something the project does not have. */\nexport class DeclarationNotSelfContainedError extends PenvError {\n override readonly name = \"DeclarationNotSelfContainedError\";\n\n constructor(name: string, file: string, specifier: string) {\n super(\n \"PENV_DECLARATION_NOT_SELF_CONTAINED\",\n `The declaration ${name} ships at \\`${file}\\` imports \\`${specifier}\\``,\n `Report it to ${name}. What penv commits to ${EXTENSIONS_PATH} is types and nothing else, ` +\n \"so it can only carry a declaration that stands on its own.\",\n );\n }\n}\n\n/** A launcher built from source, asked to record which bytes it just ran. */\nexport class EnginePinUnreleasedError extends PenvError {\n override readonly name = \"EnginePinUnreleasedError\";\n\n constructor() {\n super(\n \"PENV_ENGINE_PIN_UNRELEASED\",\n `This penv was built from source, so it carries no published integrity for ${ENGINE_PACKAGE} ` +\n `to write into ${MANIFEST_PATH}`,\n \"Install penv from npm with `npm install -g @penvhq/launcher` and run the command again — a released \" +\n \"launcher ships the integrity of the engine it ships.\",\n );\n }\n}\n\n/** The pin embedded at release time and the engine beside it are different versions. */\nexport class EnginePinMismatchError extends PenvError {\n override readonly name = \"EnginePinMismatchError\";\n\n constructor(pinned: string, ran: string) {\n super(\n \"PENV_ENGINE_PIN_MISMATCH\",\n `This penv carries the integrity of ${ENGINE_PACKAGE} ${pinned} and just ran ${ran}, so it ` +\n \"cannot record which bytes scaffolded this project\",\n \"Reinstall the launcher with `npm install -g @penvhq/launcher` — its pin and its engine ship together.\",\n );\n }\n}\n\n/** An installed directory with nothing runnable in it. */\nexport class EngineEntryError extends PenvError {\n override readonly name = \"EngineEntryError\";\n\n constructor(name: string, version: string, dir: string) {\n super(\n \"PENV_ENGINE_ENTRY\",\n `${name} ${version} in ${dir} declares no bin penv can run`,\n `Delete ${dir} and run \\`${INSTALL_COMMAND}\\` to install it again.`,\n );\n }\n}\n","/**\n * The committed, type-only declaration an added extension contributes.\n *\n * The adapter lives in `$PENV_HOME` and is loaded only for an explicit provider\n * operation, so the project can never import it — which would leave\n * `penv.config.ts` untyped for exactly the providers it names. This closes that\n * gap the only way a committed file can: by carrying the provider's own config\n * declaration as text, checked to reach for nothing the project does not have.\n *\n * A package points at that declaration with `penv.types` in its `package.json`;\n * one that ships none gets the open base shape under its own name, which is\n * still enough for the `type` field to be checked against something real.\n */\n\nimport { mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, resolve, sep } from \"node:path\";\nimport { EXTENSIONS_PATH } from \"@penvhq/core\";\nimport { DeclarationMissingError, DeclarationNotSelfContainedError } from \"./errors.js\";\n\n/** The one module a shipped declaration may reach for: it is the augmentation target. */\nconst AUGMENTATION_TARGET = \"@penvhq/core\";\n\n/** `from \"x\"`, `import \"x\"`, `import(\"x\")`, `require(\"x\")`, `declare module \"x\"`. */\nconst MODULE_SPECIFIER = /(?:\\bfrom|\\bmodule|\\bimport|\\brequire)\\s*\\(?\\s*([\"'])([^\"']*)\\1/g;\n\n/** What an extension's `package.json` tells `add`, and nothing more. */\nexport interface ExtensionPackage {\n /** A path inside the package to a self-contained declaration file. */\n readonly types: string | undefined;\n /** The engine command that finishes setting this provider up, e.g. `cloud login`. */\n readonly onboard: string | undefined;\n}\n\nfunction field(source: unknown, key: string): unknown {\n return typeof source === \"object\" && source !== null && Object.hasOwn(source, key)\n ? (source as Record<string, unknown>)[key]\n : undefined;\n}\n\nfunction text(value: unknown): string | undefined {\n return typeof value === \"string\" && value.trim() !== \"\" ? value.trim() : undefined;\n}\n\n/**\n * The `penv` block of an installed package. Advisory, so a package without one —\n * or with an unreadable `package.json` — declares nothing rather than failing an\n * install that already succeeded.\n */\nexport function readExtensionPackage(dir: string): ExtensionPackage {\n let parsed: unknown;\n try {\n parsed = JSON.parse(readFileSync(join(dir, \"package.json\"), \"utf8\"));\n } catch {\n return { types: undefined, onboard: undefined };\n }\n const penv = field(parsed, \"penv\");\n return { types: text(field(penv, \"types\")), onboard: text(field(penv, \"onboard\")) };\n}\n\nexport interface DeclarationSubject {\n readonly name: string;\n readonly version: string;\n /** Recorded in the header: what npm knew about where these bytes came from. */\n readonly attested: boolean;\n}\n\nfunction header(subject: DeclarationSubject): string {\n const provenance = subject.attested\n ? \"npm records a provenance attestation for it\"\n : \"npm records no provenance attestation for it\";\n return (\n `// Written by \\`penv add ${subject.name}\\`, and committed.\\n` +\n `// ${subject.name} ${subject.version} — ${provenance}.\\n` +\n \"//\\n\" +\n \"// Types only: this declares the shape of the provider's `penv.config.ts`\\n\" +\n \"// entry. It holds no adapter code, no credentials, and no values.\\n\"\n );\n}\n\n/** The shape a package that ships no declaration of its own still gets. */\nfunction openShape(name: string): string {\n return (\n `import type { ProviderConfig } from \"${AUGMENTATION_TARGET}\";\\n` +\n \"\\n\" +\n `declare module \"${AUGMENTATION_TARGET}\" {\\n` +\n \" interface ProviderConfigMap {\\n\" +\n ` ${JSON.stringify(name)}: ProviderConfig & { readonly type: ${JSON.stringify(name)} };\\n` +\n \" }\\n\" +\n \"}\\n\"\n );\n}\n\n/**\n * A shipped declaration is committed verbatim or not at all.\n *\n * It is about to live in a repository where the package it came from is not\n * installed, so a specifier pointing anywhere else resolves to nothing and turns\n * a helpful type into a broken build in someone else's checkout.\n */\nfunction assertSelfContained(name: string, file: string, source: string): void {\n MODULE_SPECIFIER.lastIndex = 0;\n for (;;) {\n const match = MODULE_SPECIFIER.exec(source);\n if (match === null) {\n return;\n }\n const specifier = match[2] ?? \"\";\n if (specifier !== AUGMENTATION_TARGET) {\n throw new DeclarationNotSelfContainedError(name, file, specifier);\n }\n }\n}\n\n/** The declaration's text: the package's own, or the open shape under its name. */\nexport function renderDeclaration(\n subject: DeclarationSubject,\n shipped?: { readonly file: string; readonly source: string },\n): string {\n if (shipped === undefined) {\n return `${header(subject)}\\n${openShape(subject.name)}`;\n }\n assertSelfContained(subject.name, shipped.file, shipped.source);\n const body = shipped.source.replace(/^/, \"\").trimEnd();\n return `${header(subject)}\\n${body}\\n`;\n}\n\n/** The declared file's text, from inside the installed package and nowhere else. */\nfunction readShipped(name: string, dir: string, declared: string): string {\n const root = resolve(dir);\n const file = resolve(root, ...declared.split(\"/\"));\n if (!file.startsWith(root + sep)) {\n throw new DeclarationMissingError(name, declared);\n }\n try {\n return readFileSync(file, \"utf8\");\n } catch {\n throw new DeclarationMissingError(name, declared);\n }\n}\n\n/** Where one extension's declaration lives, relative to the project root, POSIX. */\nexport function declarationPath(name: string): string {\n return `${EXTENSIONS_PATH}/${name}.d.ts`;\n}\n\nexport interface WriteDeclarationOptions extends DeclarationSubject {\n readonly root: string;\n /** The installed package directory, read for the declaration it ships. */\n readonly dir: string;\n readonly types: string | undefined;\n}\n\n/** Writes the declaration and answers with the path a message prints. */\nexport function writeDeclaration(options: WriteDeclarationOptions): string {\n const relative = declarationPath(options.name);\n const file = join(options.root, ...relative.split(\"/\"));\n\n let shipped: { file: string; source: string } | undefined;\n if (options.types !== undefined) {\n shipped = {\n file: options.types,\n source: readShipped(options.name, options.dir, options.types),\n };\n }\n\n const text = renderDeclaration(options, shipped);\n mkdirSync(dirname(file), { recursive: true });\n writeFileSync(file, text);\n return relative;\n}\n","/**\n * `$PENV_HOME` — the one directory the launcher owns.\n *\n * Engines and extensions are addressed by exact name and exact version, so a\n * machine holds every version any of its projects pins at once and no project's\n * command is ever answered by another project's bytes.\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { join, resolve, sep } from \"node:path\";\nimport { PenvError } from \"@penvhq/core\";\n\n/** A read-only view of the process environment. */\nexport type Environment = Readonly<Record<string, string | undefined>>;\n\n/** The variable that moves the store off `~/.penv`. */\nexport const PENV_HOME_VAR = \"PENV_HOME\";\n\n/** The two things the store holds, and the directory each lives under. */\nexport type PackageKind = \"engines\" | \"extensions\";\n\n/** How the launcher was installed, recorded by the installer that did it. */\nexport const HOME_META_FILE = \"meta.json\";\n\n/** Written beside an installed package: the SSRI of the tarball it came from. */\nexport const INTEGRITY_FILE = \".penv-integrity\";\n\n/** The update command for a launcher whose installer recorded nothing. */\nexport const NPM_UPDATE_COMMAND = \"npm install -g @penvhq/launcher\";\n\n/** The store, from the environment. `~/.penv` unless `$PENV_HOME` says otherwise. */\nexport function penvHome(env: Environment): string {\n const declared = env[PENV_HOME_VAR];\n if (declared !== undefined && declared.trim() !== \"\") {\n return resolve(declared);\n }\n return join(homedir(), \".penv\");\n}\n\n/**\n * Where one exact version lives.\n *\n * The manifest's grammar already refuses a name or a version that could climb\n * out of the store, so the containment check is the second lock rather than the\n * first: this function is also reached from `penv add`, where the name is\n * whatever the user typed.\n *\n * Containment is measured against the bucket, not against `$PENV_HOME`. A name\n * of `../extensions/x` stays inside the store while landing an engine among the\n * extensions, and a store where the two are not separated is a store where the\n * kind a caller asked for is not the kind it gets.\n */\nexport function packageDir(home: string, kind: PackageKind, name: string, version: string): string {\n const bucket = resolve(home, kind);\n const dir = resolve(bucket, ...name.split(\"/\"), version);\n if (!dir.startsWith(bucket + sep)) {\n throw new PenvError(\n \"PENV_HOME_ESCAPE\",\n `\\`${name}\\` at \\`${version}\\` resolves to ${dir}, which is outside ${bucket}`,\n \"Name the package exactly as npm does, e.g. `@penvhq/provider-vault`.\",\n );\n }\n return dir;\n}\n\n/** The advisory record an installer leaves in the store. */\ninterface LauncherMeta {\n readonly installMethod?: unknown;\n readonly updateCommand?: unknown;\n}\n\n/**\n * The command that updates this launcher.\n *\n * Advisory, so it never throws: a store with no `meta.json`, or one holding\n * something unreadable, falls back to the npm form rather than turning a\n * manifest-format refusal into a second failure about a metadata file.\n */\nexport function launcherUpdateCommand(home: string): string {\n let meta: LauncherMeta;\n try {\n meta = JSON.parse(readFileSync(join(home, HOME_META_FILE), \"utf8\")) as LauncherMeta;\n } catch {\n return NPM_UPDATE_COMMAND;\n }\n const command = meta?.updateCommand;\n if (typeof command === \"string\" && command.trim() !== \"\") {\n return command.trim();\n }\n return NPM_UPDATE_COMMAND;\n}\n","/**\n * The one hash penv checks: npm's SSRI, over the tarball bytes.\n *\n * The manifest pins the same string npm recorded, so the value compared here is\n * the value a reviewer approved in the diff — not a digest penv invented.\n */\n\nimport { createHash } from \"node:crypto\";\n\n/** The SSRI of some bytes, in the form the manifest pins. */\nexport function integrityOf(bytes: Uint8Array): string {\n return `sha512-${createHash(\"sha512\").update(bytes).digest(\"base64\")}`;\n}\n","/**\n * The npm tarball reader.\n *\n * An npm package is a gzipped ustar archive whose every path begins `package/`,\n * so this reads exactly that and refuses everything else: no symlinks, no\n * hardlinks, no absolute paths, no `..`, nothing outside `package/`. The\n * checksum in each header is not verified because the SSRI over the whole\n * tarball already was, before a single block was read.\n */\n\nimport { gunzipSync } from \"node:zlib\";\nimport { ArchiveError } from \"./errors.js\";\n\n/** One regular file, at its path relative to the package root. */\nexport interface TarEntry {\n readonly path: string;\n readonly bytes: Uint8Array;\n}\n\n/** The package a refusal names. */\nexport interface ArchiveSubject {\n readonly name: string;\n readonly version: string;\n}\n\nconst BLOCK = 512;\nconst NAME = { start: 0, length: 100 };\nconst SIZE = { start: 124, length: 12 };\nconst TYPE_FLAG = 156;\nconst PREFIX = { start: 345, length: 155 };\nconst ROOT = \"package/\";\n\nfunction text(block: Uint8Array, start: number, length: number): string {\n const field = block.subarray(start, start + length);\n const end = field.indexOf(0);\n return new TextDecoder().decode(end === -1 ? field : field.subarray(0, end)).trim();\n}\n\nfunction octal(block: Uint8Array, start: number, length: number): number {\n const value = text(block, start, length);\n return value === \"\" ? 0 : Number.parseInt(value, 8);\n}\n\n/** The `path` record of a pax header, which is how a long name arrives. */\nfunction paxPath(data: Uint8Array): string | undefined {\n for (const record of new TextDecoder().decode(data).split(\"\\n\")) {\n const match = /^\\d+ path=(.*)$/.exec(record);\n if (match?.[1] !== undefined) {\n return match[1];\n }\n }\n return undefined;\n}\n\n/**\n * The path an entry is written to, relative to the destination.\n *\n * Every refusal here is the same refusal — an archive that would write outside\n * the directory penv extracts into — so they carry one code and name the entry.\n */\nfunction safePath(raw: string, subject: ArchiveSubject): string {\n if (!raw.startsWith(ROOT)) {\n throw new ArchiveError(subject.name, subject.version, raw);\n }\n const path = raw.slice(ROOT.length);\n const segments = path.split(\"/\");\n if (\n path === \"\" ||\n path.includes(\"\\\\\") ||\n path.startsWith(\"/\") ||\n /^[A-Za-z]:/.test(path) ||\n segments.some((segment) => segment === \"..\" || segment === \"\")\n ) {\n throw new ArchiveError(subject.name, subject.version, raw);\n }\n return path;\n}\n\n/** Every regular file in an npm tarball, `package/` stripped. */\nexport function readTarball(gzipped: Uint8Array, subject: ArchiveSubject): TarEntry[] {\n const archive = new Uint8Array(gunzipSync(gzipped));\n const entries: TarEntry[] = [];\n let override: string | undefined;\n\n for (let offset = 0; offset + BLOCK <= archive.length; offset += BLOCK) {\n const header = archive.subarray(offset, offset + BLOCK);\n const name = text(header, NAME.start, NAME.length);\n if (name === \"\") {\n break;\n }\n const size = octal(header, SIZE.start, SIZE.length);\n const dataStart = offset + BLOCK;\n // A size that is not a whole count of bytes inside this archive is refused\n // rather than clamped: NaN or a negative walked the offset off the end and\n // returned the entries read so far, which is a truncated package that passed.\n if (!Number.isSafeInteger(size) || size < 0 || dataStart + size > archive.length) {\n throw new ArchiveError(subject.name, subject.version, name);\n }\n const flag = String.fromCharCode(header[TYPE_FLAG] ?? 0);\n const data = archive.subarray(dataStart, dataStart + size);\n offset += Math.ceil(size / BLOCK) * BLOCK;\n\n if (flag === \"x\" || flag === \"g\") {\n override = paxPath(data) ?? override;\n continue;\n }\n const prefix = text(header, PREFIX.start, PREFIX.length);\n const raw = override ?? (prefix === \"\" ? name : `${prefix}/${name}`);\n override = undefined;\n\n // Directories are implied by the files written into them, so a directory\n // entry produces nothing and needs no path check.\n if (flag === \"5\") {\n continue;\n }\n if (flag !== \"0\" && flag !== \"\\0\") {\n throw new ArchiveError(subject.name, subject.version, raw);\n }\n entries.push({ path: safePath(raw, subject), bytes: new Uint8Array(data) });\n }\n\n return entries;\n}\n","/**\n * The store: what is installed, and how something absent gets installed.\n *\n * An installed package carries the SSRI of the tarball it came from, written\n * beside it at install time, so every later run compares the manifest's pin\n * against a recorded answer instead of re-hashing a directory that would never\n * hash to an npm integrity anyway. Three states, and only three: the bytes the\n * manifest pins, no bytes, or bytes that are not the ones pinned.\n */\n\nimport {\n existsSync,\n mkdirSync,\n mkdtempSync,\n readFileSync,\n renameSync,\n rmSync,\n writeFileSync,\n} from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { DownloadFailedError, DownloadIntegrityError } from \"./errors.js\";\nimport type { Fetcher } from \"./fetcher.js\";\nimport { INTEGRITY_FILE, type PackageKind, packageDir } from \"./home.js\";\nimport { integrityOf } from \"./integrity.js\";\nimport { readTarball } from \"./tar.js\";\n\n/** One exact thing the manifest names. */\nexport interface Pin {\n readonly name: string;\n readonly version: string;\n readonly integrity: string;\n /** Only when the package comes from somewhere other than npmjs. */\n readonly registry?: string;\n}\n\n/** Where penv looks when a pin names no registry. */\nexport const DEFAULT_REGISTRY = \"https://registry.npmjs.org\";\n\nexport type InstallState = \"installed\" | \"absent\" | \"corrupt\";\n\nexport interface Installation {\n readonly dir: string;\n readonly state: InstallState;\n}\n\n/** npm's tarball address, which an exact version can be built rather than looked up. */\nexport function tarballUrl(pin: Pin): string {\n const registry = (pin.registry ?? DEFAULT_REGISTRY).replace(/\\/+$/, \"\");\n const basename = pin.name.slice(pin.name.lastIndexOf(\"/\") + 1);\n return `${registry}/${pin.name}/-/${basename}-${pin.version}.tgz`;\n}\n\n/** What this machine holds for one pin. */\nexport function inspectInstall(home: string, kind: PackageKind, pin: Pin): Installation {\n const dir = packageDir(home, kind, pin.name, pin.version);\n if (!existsSync(dir)) {\n return { dir, state: \"absent\" };\n }\n let recorded: string;\n try {\n recorded = readFileSync(join(dir, INTEGRITY_FILE), \"utf8\").trim();\n } catch {\n return { dir, state: \"corrupt\" };\n }\n return { dir, state: recorded === pin.integrity ? \"installed\" : \"corrupt\" };\n}\n\nexport interface InstallOptions {\n readonly home: string;\n readonly kind: PackageKind;\n readonly pin: Pin;\n readonly fetcher: Fetcher;\n}\n\n/**\n * Downloads one pin, verifies it, and installs it — in that order, and never a\n * different one.\n *\n * The extraction happens in a staging directory and arrives by rename, so an\n * interrupted install leaves nothing that a later run could read as installed.\n */\nexport async function installPin(options: InstallOptions): Promise<string> {\n const { home, kind, pin, fetcher } = options;\n const dir = packageDir(home, kind, pin.name, pin.version);\n const url = tarballUrl(pin);\n\n let bytes: Uint8Array;\n try {\n bytes = await fetcher.get(url);\n } catch (cause) {\n const detail = cause instanceof Error ? cause.message : String(cause);\n throw new DownloadFailedError(pin.name, pin.version, url, detail);\n }\n if (integrityOf(bytes) !== pin.integrity) {\n throw new DownloadIntegrityError(pin.name, pin.version, url);\n }\n\n const entries = readTarball(bytes, pin);\n const parent = dirname(dir);\n mkdirSync(parent, { recursive: true });\n const staging = mkdtempSync(join(parent, `.${pin.version}-`));\n try {\n for (const entry of entries) {\n const file = join(staging, ...entry.path.split(\"/\"));\n mkdirSync(dirname(file), { recursive: true });\n writeFileSync(file, entry.bytes);\n }\n writeFileSync(join(staging, INTEGRITY_FILE), `${pin.integrity}\\n`);\n rmSync(dir, { recursive: true, force: true });\n renameSync(staging, dir);\n } finally {\n rmSync(staging, { recursive: true, force: true });\n }\n return dir;\n}\n","/**\n * What the registry says about one release.\n *\n * Everything `add` decides from — the exact version behind `latest`, the\n * integrity of the bytes, when it was published, who published it, whether npm\n * holds a provenance attestation — is metadata, so it arrives through the same\n * fetcher the tarball does. One network seam, and a test suite that serves both\n * from memory.\n */\n\nimport {\n PackageUnknownError,\n RegistryUnreadableError,\n ReleaseIncompleteError,\n VersionUnknownError,\n} from \"./errors.js\";\nimport type { Fetcher } from \"./fetcher.js\";\nimport { DEFAULT_REGISTRY } from \"./store.js\";\n\n/** One published version, reduced to the facts a trust decision is made on. */\nexport interface Release {\n readonly name: string;\n readonly version: string;\n readonly integrity: string;\n /** ISO 8601, as the registry's `time` map records it. */\n readonly publishedAt: string;\n /** The npm account credited with the publish, when the registry names one. */\n readonly publisher: string | undefined;\n /** Whether npm holds a provenance attestation for these exact bytes. */\n readonly attested: boolean;\n}\n\nexport interface ReleaseQuery {\n readonly name: string;\n /** Absent means whatever `latest` points at today. */\n readonly version?: string;\n /** Only when the package comes from somewhere other than npmjs. */\n readonly registry?: string;\n readonly fetcher: Fetcher;\n}\n\nfunction record(value: unknown): Record<string, unknown> | undefined {\n return typeof value === \"object\" && value !== null && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n}\n\n/** Own properties only: a package named `constructor` must answer `undefined`. */\nfunction at(source: Record<string, unknown> | undefined, key: string): unknown {\n return source !== undefined && Object.hasOwn(source, key) ? source[key] : undefined;\n}\n\nfunction text(value: unknown): string | undefined {\n return typeof value === \"string\" && value.trim() !== \"\" ? value : undefined;\n}\n\n/** The packument's address, which an exact name can be built rather than searched. */\nexport function packumentUrl(registry: string | undefined, name: string): string {\n return `${(registry ?? DEFAULT_REGISTRY).replace(/\\/+$/, \"\")}/${name}`;\n}\n\nfunction publisherOf(release: Record<string, unknown>): string | undefined {\n const npmUser = text(at(record(release._npmUser), \"name\"));\n if (npmUser !== undefined) {\n return npmUser;\n }\n const maintainers = release.maintainers;\n if (!Array.isArray(maintainers)) {\n return undefined;\n }\n return text(at(record(maintainers[0]), \"name\"));\n}\n\n/** The one release `add` is about to decide on, or why the registry could not say. */\nexport async function fetchRelease(query: ReleaseQuery): Promise<Release> {\n const url = packumentUrl(query.registry, query.name);\n\n let bytes: Uint8Array;\n try {\n bytes = await query.fetcher.get(url);\n } catch (cause) {\n throw new RegistryUnreadableError(\n query.name,\n url,\n cause instanceof Error ? cause.message : String(cause),\n );\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(new TextDecoder().decode(bytes));\n } catch (cause) {\n throw new RegistryUnreadableError(\n query.name,\n url,\n cause instanceof Error ? cause.message : String(cause),\n );\n }\n\n const packument = record(parsed);\n const versions = record(at(packument, \"versions\"));\n if (versions === undefined) {\n throw new PackageUnknownError(query.name, url);\n }\n\n const tags = record(at(packument, \"dist-tags\"));\n const asked = query.version ?? text(at(tags, \"latest\"));\n if (asked === undefined) {\n throw new PackageUnknownError(query.name, url);\n }\n\n // A version that is not a version is read as a dist-tag, so `@next` resolves\n // the way npm resolves it — and the manifest still pins what it pointed at.\n const version =\n record(at(versions, asked)) === undefined ? (text(at(tags, asked)) ?? asked) : asked;\n const release = record(at(versions, version));\n if (release === undefined) {\n throw new VersionUnknownError(query.name, asked, url);\n }\n\n const dist = record(at(release, \"dist\"));\n const integrity = text(at(dist, \"integrity\"));\n const publishedAt = text(at(record(at(packument, \"time\")), version));\n if (integrity === undefined) {\n throw new ReleaseIncompleteError(query.name, version, url, \"integrity\");\n }\n if (publishedAt === undefined || Number.isNaN(Date.parse(publishedAt))) {\n throw new ReleaseIncompleteError(query.name, version, url, \"publish time\");\n }\n\n return {\n name: query.name,\n version,\n integrity,\n publishedAt,\n publisher: publisherOf(release),\n attested: record(at(dist, \"attestations\")) !== undefined,\n };\n}\n","/**\n * `penv add <package>` — the one command that decides to trust something.\n *\n * It belongs to the launcher rather than the engine because everything it does\n * is the launcher's: resolve an exact version, verify the bytes, install them\n * into `$PENV_HOME`, and write the manifest that pins them. No engine is needed\n * for any of that, and the engine importing the store would close a cycle.\n *\n * The trust model exists for strangers, and only strangers pay it. An\n * `@penvhq/*` package is resolved, verified and recorded without one question;\n * a public third-party package waits out a minimum age and commits a block\n * saying who published it and why a person trusted it; a package from a private\n * registry commits the registry and the acknowledgement. Credentials are never\n * part of any of it — `.npmrc` owns those.\n *\n * Nothing here puts adapter code on any startup path. What lands in the project\n * is two committed files with no runtime in them: the manifest entry, and a\n * type-only declaration.\n *\n * Because those two files are committed, `add` is a decision and needs a person:\n * `--no-download` and a run with nobody at it are both refused before the first\n * request, and CI gets `penv install`, which installs what the manifest already\n * pins rather than choosing what it should.\n */\n\nimport { readFileSync, writeFileSync } from \"node:fs\";\nimport { relative, sep } from \"node:path\";\nimport type { Manifest, ManifestExtension, ManifestTrust } from \"@penvhq/core\";\nimport { findConfigFile, MANIFEST_PATH, OFFICIAL_SCOPE, serializeManifest } from \"@penvhq/core\";\nimport { readProviderEntries, setProviderType } from \"./config-edit.js\";\nimport { readExtensionPackage, writeDeclaration } from \"./declaration.js\";\nimport {\n AddFlagError,\n AddNoDownloadError,\n AddNotInteractiveError,\n AddPackageNameError,\n AddRegistryError,\n AddSubjectError,\n ManifestEntriesUnreadableError,\n MIN_PACKAGE_AGE_DAYS,\n OfficialRegistryError,\n PackageTooYoungError,\n TRUST_YOUNG_FLAG,\n TrustDeclinedError,\n TrustPublisherMissingError,\n TrustReasonMissingError,\n} from \"./errors.js\";\nimport type { Fetcher } from \"./fetcher.js\";\nimport type { LauncherIo } from \"./io.js\";\nimport { fetchRelease, type Release } from \"./registry.js\";\nimport { readManifestForRepair } from \"./repair.js\";\nimport { DEFAULT_REGISTRY, installPin } from \"./store.js\";\n\n/** npm's package-name grammar, scoped or bare — the manifest's, checked before the fetch. */\nconst PACKAGE_NAME = /^(?:@[a-z0-9~-][a-z0-9._~-]*\\/)?[a-z0-9~-][a-z0-9._~-]*$/;\n\nconst REGISTRY_FLAG = \"--registry\";\n\nconst DAY_MS = 24 * 60 * 60 * 1000;\n\n/** Which ceremony a package pays, decided by its scope and where it comes from. */\ntype Tier = \"official\" | \"third-party\" | \"private\";\n\nexport interface AddOptions {\n /** The tokens after `add`. */\n readonly argv: readonly string[];\n /** The project root — the directory holding `.penv/`. */\n readonly root: string;\n readonly manifestFile: string;\n readonly home: string;\n readonly io: LauncherIo;\n readonly fetcher: Fetcher;\n /** The launcher's `--no-download`: this run reaches no registry at all. */\n readonly noDownload?: boolean;\n /** True on a CI runner, which may have a terminal and still have nobody at it. */\n readonly ci?: boolean;\n /** Injected so the age gate is testable without waiting seven days. */\n readonly now?: () => Date;\n}\n\nexport interface AddResult {\n /** The engine command the provider declares, when its offer was accepted. */\n readonly onboard: readonly string[] | undefined;\n}\n\ninterface Request {\n readonly name: string;\n readonly version: string | undefined;\n /** Absent means npmjs, which the manifest never names. */\n readonly registry: string | undefined;\n readonly trustYoung: boolean;\n}\n\n/** npmjs under any spelling is not a registry the manifest records. */\nfunction normalizeRegistry(raw: string): string | undefined {\n let url: URL;\n try {\n url = new URL(raw);\n } catch {\n throw new AddRegistryError(raw);\n }\n if (url.protocol !== \"https:\") {\n throw new AddRegistryError(raw);\n }\n return url.origin === new URL(DEFAULT_REGISTRY).origin ? undefined : raw.replace(/\\/+$/, \"\");\n}\n\n/** `@scope/name@version` splits at the last `@`, which is never the scope's. */\nfunction splitSpec(spec: string): { name: string; version: string | undefined } {\n const at = spec.lastIndexOf(\"@\");\n if (at <= 0) {\n return { name: spec, version: undefined };\n }\n return { name: spec.slice(0, at), version: spec.slice(at + 1) };\n}\n\nfunction parseRequest(argv: readonly string[]): Request {\n let spec: string | undefined;\n let registry: string | undefined;\n let trustYoung = false;\n\n for (let index = 0; index < argv.length; index += 1) {\n const token = argv[index] ?? \"\";\n if (token === TRUST_YOUNG_FLAG) {\n trustYoung = true;\n continue;\n }\n if (token === REGISTRY_FLAG) {\n const value = argv[index + 1];\n if (value === undefined || value.startsWith(\"-\")) {\n throw new AddFlagError(REGISTRY_FLAG);\n }\n registry = normalizeRegistry(value);\n index += 1;\n continue;\n }\n if (token.startsWith(\"-\")) {\n throw new AddFlagError(token);\n }\n if (spec !== undefined) {\n throw new AddSubjectError();\n }\n spec = token;\n }\n\n if (spec === undefined || spec === \"\") {\n throw new AddSubjectError();\n }\n const { name, version } = splitSpec(spec);\n if (!PACKAGE_NAME.test(name) || version === \"\") {\n throw new AddPackageNameError(spec);\n }\n return { name, version, registry, trustYoung };\n}\n\nfunction tierOf(request: Request): Tier {\n if (request.name.startsWith(OFFICIAL_SCOPE)) {\n if (request.registry !== undefined) {\n throw new OfficialRegistryError(request.name, request.registry);\n }\n return \"official\";\n }\n return request.registry === undefined ? \"third-party\" : \"private\";\n}\n\n/** The block the reader of the commit sees before they are asked to decide. */\nfunction showRelease(io: LauncherIo, release: Release, registry: string | undefined): void {\n io.out(` publisher ${release.publisher ?? \"not stated by the registry\"}`);\n io.out(` published ${release.publishedAt}`);\n io.out(` integrity ${release.integrity}`);\n if (registry !== undefined) {\n io.out(` registry ${registry}`);\n }\n}\n\nasync function askReason(io: LauncherIo, release: Release): Promise<string> {\n const reason = (await io.ask(\"Why do you trust it? One line, for the next reviewer.\")).trim();\n if (reason === \"\") {\n throw new TrustReasonMissingError(release.name, release.version);\n }\n return reason;\n}\n\n/**\n * The trust ceremony, or nothing at all.\n *\n * Seal 6: the official scope reaches the `return undefined` above every prompt,\n * so an `@penvhq/*` add cannot grow a question by accident — there is no code\n * path from here to `confirm` for it.\n */\nasync function trustFor(\n tier: Tier,\n release: Release,\n request: Request,\n io: LauncherIo,\n now: Date,\n): Promise<ManifestTrust | undefined> {\n if (tier === \"official\") {\n return undefined;\n }\n\n if (tier === \"third-party\") {\n const age = now.getTime() - Date.parse(release.publishedAt);\n if (age < MIN_PACKAGE_AGE_DAYS * DAY_MS && !request.trustYoung) {\n throw new PackageTooYoungError(release.name, release.version, release.publishedAt);\n }\n io.out(\n `${release.name} ${release.version} is outside \\`${OFFICIAL_SCOPE}*\\`, so the manifest ` +\n \"records who you trusted and why.\",\n );\n showRelease(io, release, undefined);\n if (!(await io.confirm(`Trust ${release.name} ${release.version}?`))) {\n throw new TrustDeclinedError(release.name, release.version);\n }\n const publisher =\n release.publisher ?? (await io.ask(\"Who publishes it? The npm account name.\")).trim();\n if (publisher === \"\") {\n throw new TrustPublisherMissingError(release.name, release.version);\n }\n return {\n tier: \"third-party\",\n publisher,\n publishedAt: release.publishedAt,\n acknowledgedAt: now.toISOString(),\n reason: await askReason(io, release),\n };\n }\n\n io.out(\n `${release.name} ${release.version} comes from a private registry. The manifest records the ` +\n \"registry and your acknowledgement; your `.npmrc` keeps the credentials.\",\n );\n showRelease(io, release, request.registry);\n if (!(await io.confirm(`Trust ${release.name} ${release.version}?`))) {\n throw new TrustDeclinedError(release.name, release.version);\n }\n return {\n tier: \"private\",\n acknowledgedAt: now.toISOString(),\n reason: await askReason(io, release),\n };\n}\n\n/**\n * The manifest with this one extension recorded, serialized — and so validated.\n *\n * The entry being replaced is allowed to be one penv cannot read: a broken entry\n * refuses with `penv add <pkg>`, and a remedy has to survive the parse it names.\n * Every other entry is validated as usual, and what gets written is validated in\n * full by {@link serializeManifest}, so `add` cannot leave behind an entry the\n * next command chokes on.\n */\nfunction recordExtension(manifestFile: string, name: string, entry: ManifestExtension): string {\n const { manifest, broken } = readManifestForRepair(readFileSync(manifestFile, \"utf8\"));\n const others = broken.filter((other) => other !== name);\n if (others.length > 0) {\n throw new ManifestEntriesUnreadableError(others);\n }\n const next: Manifest = {\n ...manifest,\n extensions: { ...manifest.extensions, [name]: entry },\n };\n return serializeManifest(next);\n}\n\n/**\n * The `penv.config.ts` edit, offered once per environment and applied on a yes.\n *\n * Every provider entry is its own decision — a team rarely points development\n * and production at the same store on the same day — so this asks per\n * environment rather than assuming one answer covers the file.\n */\nasync function offerConfigEdit(options: AddOptions, name: string): Promise<void> {\n const { io, root } = options;\n const configFile = findConfigFile(root);\n const line = `Add \\`type: ${JSON.stringify(name)}\\` to an environment in penv.config.ts.`;\n if (configFile === undefined) {\n io.out(line);\n return;\n }\n\n const shown = relative(root, configFile).split(sep).join(\"/\");\n let current = readFileSync(configFile, \"utf8\");\n const entries = readProviderEntries(current);\n if (entries === undefined || entries.length === 0) {\n io.out(line);\n return;\n }\n if (entries.every((entry) => entry.type === name)) {\n return;\n }\n if (!io.interactive) {\n io.out(line);\n return;\n }\n\n for (const entry of entries) {\n if (entry.type === name) {\n continue;\n }\n if (!(await io.confirm(`Point \\`${entry.environment}\\` at ${name} in ${shown}?`))) {\n continue;\n }\n const next = setProviderType(current, entry.environment, name);\n if (next === undefined) {\n io.out(`Add \\`type: ${JSON.stringify(name)}\\` to \\`${entry.environment}\\` in ${shown}.`);\n continue;\n }\n current = next;\n writeFileSync(configFile, current);\n io.out(`✓ ${shown} points \\`${entry.environment}\\` at ${name}`);\n }\n}\n\n/** Seal 7: the provider's own next step, offered — never run because `add` ran. */\nasync function offerOnboarding(\n io: LauncherIo,\n name: string,\n onboard: string | undefined,\n): Promise<readonly string[] | undefined> {\n if (onboard === undefined) {\n return undefined;\n }\n const args = onboard.split(/\\s+/).filter((token) => token !== \"\");\n if (args.length === 0) {\n return undefined;\n }\n const command = `penv ${args.join(\" \")}`;\n if (io.interactive && (await io.confirm(`Run \\`${command}\\` now?`))) {\n return args;\n }\n io.out(`Run \\`${command}\\` to finish setting ${name} up.`);\n return undefined;\n}\n\nexport async function add(options: AddOptions): Promise<AddResult> {\n const { io, fetcher, home, root, manifestFile } = options;\n const request = parseRequest(options.argv);\n const tier = tierOf(request);\n const now = (options.now ?? (() => new Date()))();\n\n // Both refusals come before the first request, so a run that cannot finish an\n // add has not read the registry, written the manifest, or filled the store.\n if (options.noDownload === true) {\n throw new AddNoDownloadError(request.name);\n }\n if (options.ci === true || !io.interactive) {\n throw new AddNotInteractiveError(request.name);\n }\n\n const release = await fetchRelease({\n name: request.name,\n ...(request.version === undefined ? {} : { version: request.version }),\n ...(request.registry === undefined ? {} : { registry: request.registry }),\n fetcher,\n });\n const trust = await trustFor(tier, release, request, io, now);\n\n const entry: ManifestExtension = {\n version: release.version,\n integrity: release.integrity,\n ...(request.registry === undefined ? {} : { registry: request.registry }),\n ...(trust === undefined ? {} : { trust }),\n };\n // Serialized before anything is downloaded: a manifest that would not validate\n // is a refusal, not a cache full of bytes nobody can pin.\n const manifestText = recordExtension(manifestFile, release.name, entry);\n\n const dir = await installPin({\n home,\n kind: \"extensions\",\n pin: {\n name: release.name,\n version: release.version,\n integrity: release.integrity,\n ...(request.registry === undefined ? {} : { registry: request.registry }),\n },\n fetcher,\n });\n\n const installed = readExtensionPackage(dir);\n const declaration = writeDeclaration({\n root,\n dir,\n name: release.name,\n version: release.version,\n attested: release.attested,\n types: installed.types,\n });\n writeFileSync(manifestFile, manifestText);\n\n const provenance = release.attested\n ? \"npm records a provenance attestation\"\n : \"npm records no provenance attestation\";\n io.out(`✓ ${release.name} ${release.version} installed — ${provenance}`);\n io.out(`✓ ${MANIFEST_PATH} pins it`);\n io.out(`✓ ${declaration} declares its config type`);\n\n await offerConfigEdit(options, release.name);\n return { onboard: await offerOnboarding(io, release.name, installed.onboard) };\n}\n","/**\n * Reading a manifest that one of its own remedies is supposed to fix.\n *\n * A broken extension entry refuses with `Run \\`penv add <pkg>\\` to rewrite that\n * entry` — and `penv add` parsed the whole manifest before it got that far, so\n * the refusal's remedy hit the refusal. Same for `penv install`, which is what\n * every missing-package refusal names.\n *\n * So the two repair commands read the manifest through here instead: every entry\n * that validates is kept, the ones that do not are named, and nothing else is\n * relaxed. The format, the engine pin, unknown root keys and the forbidden-content\n * scan are all still full refusals — an entry cannot be repaired in a file penv\n * could not run afterwards anyway. What comes back is an ordinary `Manifest`, so\n * a broken entry can never be written back out: `penv add` restores it only by\n * resolving the package again, through `serializeManifest`, which validates.\n */\n\nimport type { Manifest } from \"@penvhq/core\";\nimport { parseManifest } from \"@penvhq/core\";\n\nexport interface RepairableManifest {\n /** Every entry that validates, and nothing that does not. */\n readonly manifest: Manifest;\n /** The extension names whose entries were unreadable, sorted. */\n readonly broken: readonly string[];\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** The manifest with `extensions` replaced, parsed — so every other check still runs. */\nfunction parseWith(base: Record<string, unknown>, extensions: Record<string, unknown>): Manifest {\n return parseManifest(JSON.stringify({ ...base, extensions }));\n}\n\nexport function readManifestForRepair(text: string): RepairableManifest {\n let parsed: unknown;\n try {\n parsed = JSON.parse(text);\n } catch {\n // Not JSON at all: nothing to take apart, and `parseManifest` says it better.\n return { manifest: parseManifest(text), broken: [] };\n }\n\n const root = isPlainObject(parsed) ? parsed : undefined;\n const declared = root?.extensions;\n if (root === undefined || !isPlainObject(declared)) {\n // `extensions` is missing or is not a map of entries. That is not one bad\n // entry, and no `penv add` names it — the refusal for it stands.\n return { manifest: parseManifest(text), broken: [] };\n }\n\n const { extensions: _, ...base } = root;\n // Everything outside the entries decides first, and its refusals are unchanged.\n parseWith(base, {});\n\n const kept: Record<string, unknown> = {};\n const broken: string[] = [];\n for (const [name, entry] of Object.entries(declared)) {\n try {\n parseWith(base, { [name]: entry });\n kept[name] = entry;\n } catch {\n broken.push(name);\n }\n }\n return { manifest: parseWith(base, kept), broken: broken.sort() };\n}\n","/**\n * Handing the command over.\n *\n * The engine is a child process, not an import: it is a different version of\n * penv than the launcher, and it has to be able to be. What crosses is the\n * argument list exactly as typed, the three streams, the exit code, and the\n * signal that ended it — nothing is parsed, rewritten, or summarized on the way.\n */\n\nimport { spawn } from \"node:child_process\";\nimport { constants } from \"node:os\";\nimport type { Environment } from \"./home.js\";\n\nexport interface Delegation {\n /** The executable to run — node, for a JS engine entry. */\n readonly command: string;\n readonly args: readonly string[];\n readonly cwd: string;\n readonly env: Environment;\n}\n\n/** Runs the child and answers with the exit code the caller should exit with. */\nexport type Spawner = (delegation: Delegation) => Promise<number>;\n\n/** The signals a launcher must not swallow on its way to the child. */\nconst FORWARDED = [\"SIGINT\", \"SIGTERM\", \"SIGHUP\", \"SIGQUIT\"] as const;\n\nfunction signalNumber(signal: NodeJS.Signals): number {\n const signals = constants.signals as Record<string, number | undefined>;\n return signals[signal] ?? 0;\n}\n\nexport function nodeSpawner(): Spawner {\n return (delegation) =>\n new Promise<number>((settle, fail) => {\n const child = spawn(delegation.command, [...delegation.args], {\n cwd: delegation.cwd,\n env: { ...delegation.env },\n stdio: \"inherit\",\n });\n\n const handlers = FORWARDED.map((signal) => {\n const handler = () => {\n child.kill(signal);\n };\n process.on(signal, handler);\n return { signal, handler } as const;\n });\n const release = () => {\n for (const { signal, handler } of handlers) {\n process.off(signal, handler);\n }\n };\n\n child.on(\"error\", (error) => {\n release();\n fail(error);\n });\n child.on(\"exit\", (code, signal) => {\n release();\n if (signal !== null) {\n // Die the way the child died: a shell reading `$?` learns that the\n // command was killed, not that penv chose to return a number.\n process.kill(process.pid, signal);\n settle(128 + signalNumber(signal));\n return;\n }\n settle(code ?? 0);\n });\n });\n}\n","/**\n * Turning an installed directory into something to run.\n *\n * The engine that ships with the launcher and the engine a project pins are the\n * same kind of thing — a package directory with a `bin` — so there is one\n * resolver and one spawn path, and `penv init` outside a project takes exactly\n * the route `penv get` takes inside one.\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, join, resolve, sep } from \"node:path\";\nimport { ENGINE_PACKAGE, PenvError } from \"@penvhq/core\";\nimport { EngineEntryError } from \"./errors.js\";\n\n/** The bin name the engine publishes. `penv` itself belongs to the launcher. */\nexport const ENGINE_BIN = \"penv-engine\";\n\nexport interface Engine {\n readonly name: string;\n readonly version: string;\n readonly dir: string;\n /** The JS file to hand to node, absolute. */\n readonly entry: string;\n}\n\ninterface PackageManifest {\n readonly version?: unknown;\n readonly bin?: unknown;\n}\n\nfunction readPackageManifest(dir: string): PackageManifest | undefined {\n try {\n return JSON.parse(readFileSync(join(dir, \"package.json\"), \"utf8\")) as PackageManifest;\n } catch {\n return undefined;\n }\n}\n\nfunction binPath(bin: unknown): string | undefined {\n if (typeof bin === \"string\") {\n return bin;\n }\n if (typeof bin !== \"object\" || bin === null) {\n return undefined;\n }\n const entries = Object.entries(bin as Record<string, unknown>).filter(\n (entry): entry is [string, string] => typeof entry[1] === \"string\",\n );\n const named = entries.find(([name]) => name === ENGINE_BIN);\n const chosen = named ?? (entries.length === 1 ? entries[0] : undefined);\n return chosen?.[1];\n}\n\n/**\n * The engine installed at `dir`, or the refusal that says it is not runnable.\n *\n * `bin` comes out of the package's own `package.json`, so it is checked for\n * containment like every other path the launcher resolves from something it did\n * not write: a `bin` of `../../x.js` names a file penv would hand to node from\n * outside the package the manifest pinned.\n */\nexport function engineAt(dir: string, name: string, version: string): Engine {\n const manifest = readPackageManifest(dir);\n const bin = manifest === undefined ? undefined : binPath(manifest.bin);\n const root = resolve(dir);\n const entry = bin === undefined ? undefined : resolve(root, bin);\n if (entry === undefined || !entry.startsWith(root + sep) || !existsSync(entry)) {\n throw new EngineEntryError(name, version, dir);\n }\n return { name, version, dir, entry };\n}\n\n/**\n * The engine that shipped with this launcher — the one that runs `init` in a\n * directory that is not a project yet.\n *\n * It is resolved rather than bundled: a launcher installed from npm gets the\n * engine as a dependency, which is what makes it a package directory with a\n * `bin` like every other engine in the store.\n */\nexport function bundledEngine(): Engine {\n const require = createRequire(import.meta.url);\n let manifestFile: string;\n try {\n manifestFile = require.resolve(`${ENGINE_PACKAGE}/package.json`);\n } catch {\n throw new PenvError(\n \"PENV_NO_BUNDLED_ENGINE\",\n `This penv installation is missing ${ENGINE_PACKAGE}, the engine it runs \\`init\\` with`,\n \"Reinstall the launcher with `npm install -g @penvhq/launcher`.\",\n );\n }\n const dir = dirname(manifestFile);\n const version = readPackageManifest(dir)?.version;\n return engineAt(dir, ENGINE_PACKAGE, typeof version === \"string\" ? version : \"unknown\");\n}\n","/**\n * Every byte penv downloads comes through here.\n *\n * One method, so the test suite hands the store a fake and the whole launcher\n * runs with no network at all — and so the \"CI never downloads\" guarantee is a\n * property of one call site rather than of every place a URL is built.\n */\n\nexport interface Fetcher {\n /** The bytes at `url`, or a thrown error saying what the registry did. */\n get(url: string): Promise<Uint8Array>;\n}\n\n/** The real one: `fetch`, and a thrown error for anything that is not 200. */\nexport function httpFetcher(): Fetcher {\n return {\n async get(url) {\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`the registry answered ${response.status} ${response.statusText}`);\n }\n return new Uint8Array(await response.arrayBuffer());\n },\n };\n}\n","/**\n * The published identity of the engine that ships with this launcher.\n *\n * A manifest pins bytes, and bytes are named by the SSRI npm recorded for the\n * tarball — which nothing can compute from an installed directory, and which\n * `init` may not go and ask for, because adoption is offline. So the launcher\n * carries the answer: the release pipeline publishes `@penvhq/cli`, reads that\n * integrity from the registry, writes it here, and only then publishes `penv`.\n * The pin and the engine beside it describe one release or the launcher refuses\n * to use either.\n *\n * The value checked into this repository is a placeholder that no registry could\n * ever serve, and {@link assertReleasePin} is the gate that keeps it out of a\n * published launcher and out of anyone's project.\n */\n\nimport { ENGINE_PACKAGE, type ManifestEngine } from \"@penvhq/core\";\nimport { EnginePinMismatchError, EnginePinUnreleasedError } from \"./errors.js\";\n\n/** Deliberately not an SSRI: nothing can install, or verify, what it names. */\nexport const DEV_PIN_INTEGRITY = \"sha512-development-build-not-a-published-release\";\n\n/** The version that goes with it, equally unpublishable. */\nexport const DEV_PIN_VERSION = \"0.0.0-dev\";\n\n/** Rewritten by the release step, after `@penvhq/cli` is on the registry. */\nexport const BUNDLED_ENGINE_PIN: ManifestEngine = {\n package: ENGINE_PACKAGE,\n version: DEV_PIN_VERSION,\n integrity: DEV_PIN_INTEGRITY,\n};\n\n/** The release gate: a launcher built from source has nothing to pin. */\nexport function assertReleasePin(pin: ManifestEngine): void {\n if (pin.integrity === DEV_PIN_INTEGRITY || pin.version === DEV_PIN_VERSION) {\n throw new EnginePinUnreleasedError();\n }\n}\n\n/** The pin for the engine that just ran, or the refusal that says there is none. */\nexport function releaseEnginePin(pin: ManifestEngine, ranVersion: string): ManifestEngine {\n assertReleasePin(pin);\n if (pin.version !== ranVersion) {\n throw new EnginePinMismatchError(pin.version, ranVersion);\n }\n return pin;\n}\n","/**\n * Finding the project a command was typed in.\n *\n * The manifest is the marker, not `penv.config.ts`: the launcher's whole job is\n * to run the engine the project pins, and the manifest is the file that pins it.\n * A checkout whose `node_modules` has never been installed still answers.\n */\n\nimport { existsSync } from \"node:fs\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { MANIFEST_PATH, stateDir } from \"@penvhq/core\";\n\nexport interface Project {\n /** The directory holding `.penv/`. */\n readonly root: string;\n /** The manifest, absolute. */\n readonly manifestFile: string;\n}\n\nconst MANIFEST_SEGMENTS = MANIFEST_PATH.split(\"/\");\n\nfunction findUp(cwd: string, matches: (dir: string) => boolean): string | undefined {\n let dir = resolve(cwd);\n for (;;) {\n if (matches(dir)) {\n return dir;\n }\n const parent = dirname(dir);\n if (parent === dir) {\n return undefined;\n }\n dir = parent;\n }\n}\n\n/** The nearest project at or above `cwd`, or `undefined` outside one. */\nexport function findProject(cwd: string): Project | undefined {\n const root = findUp(cwd, (dir) => existsSync(join(dir, ...MANIFEST_SEGMENTS)));\n return root === undefined ? undefined : { root, manifestFile: join(root, ...MANIFEST_SEGMENTS) };\n}\n\n/**\n * The project a delegated `init` or `migrate` left behind, recognised by the\n * state directory rather than the manifest it does not have yet.\n *\n * A command that previewed and wrote nothing leaves none, which is what keeps a\n * `penv migrate` typed in an ordinary directory from being handed a manifest.\n */\nexport function findAdoptedRoot(cwd: string): string | undefined {\n return findUp(cwd, (dir) => existsSync(stateDir(dir)));\n}\n","/**\n * The launcher protocol.\n *\n * One question is asked on every invocation — which penv is this project's — and\n * everything here is the answer to it: find the manifest, read only the format\n * it declares, prove the pinned bytes are on this machine, hand the command\n * over. The launcher parses `--no-download` and `--version` and nothing else;\n * every other token is the engine's business and crosses untouched.\n *\n * Downloading is the one behavior that differs by where penv is running. CI and\n * production never download during a run — they refuse and name the command that\n * installs — because a production start that is also a network event is a\n * production start that can fail for a reason nobody chose.\n */\n\nimport { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { Manifest, ManifestEngine } from \"@penvhq/core\";\nimport {\n MANIFEST_FORMAT,\n MANIFEST_PATH,\n PenvError,\n parseManifest,\n serializeManifest,\n UnsupportedManifestFormatError,\n} from \"@penvhq/core\";\nimport { add } from \"./add.js\";\nimport type { Spawner } from \"./delegate.js\";\nimport { type Engine, engineAt } from \"./engine.js\";\nimport {\n InstallDeclinedError,\n ManifestEntriesUnreadableError,\n NoProjectError,\n PackageCorruptError,\n PackageMissingError,\n} from \"./errors.js\";\nimport type { Fetcher } from \"./fetcher.js\";\nimport {\n type Environment,\n launcherUpdateCommand,\n type PackageKind,\n PENV_HOME_VAR,\n penvHome,\n} from \"./home.js\";\nimport type { LauncherIo } from \"./io.js\";\nimport { releaseEnginePin } from \"./pins.js\";\nimport type { Project } from \"./project.js\";\nimport { findAdoptedRoot, findProject } from \"./project.js\";\nimport { type RepairableManifest, readManifestForRepair } from \"./repair.js\";\nimport { inspectInstall, installPin, type Pin } from \"./store.js\";\n\nexport interface LauncherOptions {\n /** The command line, minus the executable — `process.argv.slice(2)`. */\n readonly argv: readonly string[];\n readonly cwd: string;\n readonly env: Environment;\n readonly io: LauncherIo;\n readonly fetcher: Fetcher;\n readonly spawn: Spawner;\n /** The engine that shipped with this launcher, resolved only when it is needed. */\n readonly bundledEngine: () => Engine;\n /** That engine's published identity, embedded at release time. */\n readonly bundledPin: ManifestEngine;\n}\n\n/** The launcher's own commands. Everything else belongs to the engine. */\nconst INSTALL = \"install\";\nconst ADD = \"add\";\nconst VERSION_FLAGS = new Set([\"--version\", \"-v\"]);\nconst HELP_FLAGS = new Set([\"--help\", \"-h\"]);\nconst NO_DOWNLOAD = \"--no-download\";\n\n/** What runs outside a project, on the engine that shipped with the launcher — and leaves one behind. */\nconst ADOPTS = new Set([\"init\", \"migrate\"]);\n\ninterface PinnedPackage {\n readonly kind: PackageKind;\n readonly pin: Pin;\n}\n\n/**\n * `--no-download` leads, or it is the engine's.\n *\n * The launcher owns the tokens before the command name and nothing after it, so\n * a flag the engine also understands can never be eaten here, and what the\n * engine receives is what the user typed.\n */\nfunction splitLauncherFlags(argv: readonly string[]): {\n noDownload: boolean;\n forwarded: readonly string[];\n} {\n let index = 0;\n let noDownload = false;\n while (argv[index] === NO_DOWNLOAD) {\n noDownload = true;\n index += 1;\n }\n return { noDownload, forwarded: argv.slice(index) };\n}\n\n/** The command the user ran, replayed so a refusal can tell them to run it again. */\nfunction invokedCommand(argv: readonly string[]): string {\n const parts = argv.map((token) => (/\\s/.test(token) ? JSON.stringify(token) : token));\n return [\"penv\", ...parts].join(\" \");\n}\n\nfunction isCi(env: Environment): boolean {\n const ci = env.CI;\n return ci !== undefined && ci !== \"\" && ci !== \"0\" && ci.toLowerCase() !== \"false\";\n}\n\n/** The engine's pin, which is the one every run needs. */\nfunction enginePinOf(manifest: Manifest): Pin {\n return {\n name: manifest.engine.package,\n version: manifest.engine.version,\n integrity: manifest.engine.integrity,\n };\n}\n\nfunction extensionPinsOf(manifest: Manifest): Pin[] {\n return Object.entries(manifest.extensions).map<Pin>(([name, entry]) => ({\n name,\n version: entry.version,\n integrity: entry.integrity,\n ...(entry.registry === undefined ? {} : { registry: entry.registry }),\n }));\n}\n\n/** Everything the manifest pins, engine first. */\nfunction pinsOf(manifest: Manifest): PinnedPackage[] {\n return [\n { kind: \"engines\", pin: enginePinOf(manifest) },\n ...extensionPinsOf(manifest).map<PinnedPackage>((pin) => ({ kind: \"extensions\", pin })),\n ];\n}\n\n/**\n * The one refusal that admits penv is two programs, with its blanks filled.\n *\n * Core writes that error; the launcher is the only place that knows how this\n * installation updates and what the user typed.\n */\nfunction reportable(error: unknown, home: string, argv: readonly string[]): unknown {\n return error instanceof UnsupportedManifestFormatError\n ? error.withLauncherUpdate({\n updateCommand: launcherUpdateCommand(home),\n invokedCommand: invokedCommand(argv),\n })\n : error;\n}\n\nfunction readManifest(manifestFile: string, home: string, argv: readonly string[]): Manifest {\n try {\n return parseManifest(readFileSync(manifestFile, \"utf8\"));\n } catch (error) {\n throw reportable(error, home, argv);\n }\n}\n\n/**\n * The manifest as `install` and `add` read it: every entry that validates, and\n * the names of the ones that do not.\n *\n * These two are the commands every other refusal names as its remedy, so they are\n * the two that must survive the file they are meant to repair. Nothing outside\n * the extension entries is relaxed — the format gate and the engine pin still\n * refuse outright, because an entry repaired in a manifest penv could not run\n * afterwards is not a repair.\n */\nfunction readManifestToRepair(\n manifestFile: string,\n home: string,\n argv: readonly string[],\n): RepairableManifest {\n try {\n return readManifestForRepair(readFileSync(manifestFile, \"utf8\"));\n } catch (error) {\n throw reportable(error, home, argv);\n }\n}\n\n/** A `PenvError` prints as written; anything else is a bug and keeps its stack. */\nfunction report(error: unknown, io: LauncherIo): void {\n if (error instanceof PenvError && error.remedy !== undefined) {\n const suffix = `\\n ${error.remedy}`;\n const message = error.message.endsWith(suffix)\n ? error.message.slice(0, -suffix.length)\n : error.message;\n io.err(`✗ ${message}`);\n io.err(` → ${error.remedy}`);\n return;\n }\n io.err(`✗ ${error instanceof Error ? (error.stack ?? error.message) : String(error)}`);\n}\n\nexport async function runLauncher(options: LauncherOptions): Promise<number> {\n try {\n return await launch(options);\n } catch (error) {\n report(error, options.io);\n return 1;\n }\n}\n\nasync function launch(options: LauncherOptions): Promise<number> {\n const { argv, cwd, env, io } = options;\n const { noDownload, forwarded } = splitLauncherFlags(argv);\n const first = forwarded[0];\n const home = penvHome(env);\n const project = findProject(cwd);\n\n if (project === undefined) {\n if (first !== undefined && VERSION_FLAGS.has(first)) {\n io.out(`penv ${options.bundledEngine().version}`);\n return 0;\n }\n if (first === undefined || HELP_FLAGS.has(first)) {\n return delegate(options, options.bundledEngine(), forwarded, home, cwd);\n }\n if (ADOPTS.has(first)) {\n return adopt(options, forwarded, home, cwd);\n }\n throw new NoProjectError(cwd);\n }\n\n // The two repair commands read the manifest ahead of the strict parse, so a\n // refusal that names one of them leaves that one runnable.\n if (first === INSTALL) {\n const { manifest, broken } = readManifestToRepair(project.manifestFile, home, argv);\n return install(options, pinsOf(manifest), home, broken);\n }\n\n if (first === ADD) {\n return addExtension(options, project, home, forwarded.slice(1), noDownload);\n }\n\n const manifest = readManifest(project.manifestFile, home, argv);\n if (first !== undefined && VERSION_FLAGS.has(first)) {\n io.out(`penv ${manifest.engine.version}`);\n return 0;\n }\n\n const enginePin = enginePinOf(manifest);\n const engineDir = await ensure(options, \"engines\", enginePin, home, noDownload);\n for (const pin of extensionPinsOf(manifest)) {\n await ensure(options, \"extensions\", pin, home, noDownload);\n }\n const engine = engineAt(engineDir, enginePin.name, enginePin.version);\n return delegate(options, engine, forwarded, home, cwd);\n}\n\n/**\n * `init` and `migrate` on the bundled engine, and the manifest recording which\n * engine that was.\n *\n * The write belongs here because the pin does: an engine cannot compute the npm\n * integrity of its own tarball, and neither command is allowed a network to go\n * and read it. It happens only after the child succeeds, only where the child\n * left a `.penv/state/` behind — a preview that wrote nothing is not an adoption\n * — and never over a manifest that is already there, whoever wrote it.\n */\nasync function adopt(\n options: LauncherOptions,\n forwarded: readonly string[],\n home: string,\n cwd: string,\n): Promise<number> {\n const engine = options.bundledEngine();\n const code = await delegate(options, engine, forwarded, home, cwd);\n if (code !== 0) {\n return code;\n }\n\n const root = findAdoptedRoot(cwd);\n if (root === undefined) {\n return 0;\n }\n const manifestFile = join(root, ...MANIFEST_PATH.split(\"/\"));\n if (existsSync(manifestFile)) {\n return 0;\n }\n\n const pin = releaseEnginePin(options.bundledPin, engine.version);\n writeFileSync(\n manifestFile,\n serializeManifest({ format: MANIFEST_FORMAT, engine: pin, extensions: {} }),\n );\n options.io.out(`✓ ${MANIFEST_PATH} pins ${pin.package} ${pin.version}`);\n return 0;\n}\n\n/** The pinned bytes on disk, or the refusal that says why they are not. */\nasync function ensure(\n options: LauncherOptions,\n kind: PackageKind,\n pin: Pin,\n home: string,\n noDownload: boolean,\n): Promise<string> {\n const { io, env, fetcher } = options;\n const { dir, state } = inspectInstall(home, kind, pin);\n if (state === \"installed\") {\n return dir;\n }\n if (state === \"corrupt\") {\n throw new PackageCorruptError(pin.name, pin.version, dir);\n }\n if (noDownload || isCi(env) || !io.interactive) {\n throw new PackageMissingError(pin.name, pin.version, home);\n }\n const consented = await io.confirm(\n `penv needs ${pin.name} ${pin.version} for this project. Download and verify it now?`,\n );\n if (!consented) {\n throw new InstallDeclinedError(pin.name, pin.version);\n }\n return installPin({ home, kind, pin, fetcher });\n}\n\n/**\n * `penv install`: the preinstall step, which is the one command that may download.\n *\n * Entries it could not read are installed around rather than refused on: the\n * engine and the readable extensions land, and each broken entry is reported with\n * the `penv add` that rewrites it. The exit code is still a failure, because what\n * the manifest names is not all on the machine.\n */\nasync function install(\n options: LauncherOptions,\n pins: readonly PinnedPackage[],\n home: string,\n broken: readonly string[],\n): Promise<number> {\n for (const { kind, pin } of pins) {\n const { dir, state } = inspectInstall(home, kind, pin);\n if (state === \"corrupt\") {\n throw new PackageCorruptError(pin.name, pin.version, dir);\n }\n if (state === \"installed\") {\n options.io.out(`✓ ${pin.name} ${pin.version} already installed`);\n continue;\n }\n await installPin({ home, kind, pin, fetcher: options.fetcher });\n options.io.out(`✓ ${pin.name} ${pin.version} installed`);\n }\n if (broken.length > 0) {\n report(new ManifestEntriesUnreadableError(broken), options.io);\n return 1;\n }\n return 0;\n}\n\n/**\n * `penv add`: the launcher's command, because everything it writes is the\n * launcher's — the store and the manifest that pins it.\n *\n * The engine is resolved only if the provider's onboarding offer is accepted, so\n * a project can add an extension before its engine has ever been installed.\n */\nasync function addExtension(\n options: LauncherOptions,\n project: Project,\n home: string,\n argv: readonly string[],\n noDownload: boolean,\n): Promise<number> {\n const { onboard } = await add({\n argv,\n root: project.root,\n manifestFile: project.manifestFile,\n home,\n io: options.io,\n fetcher: options.fetcher,\n noDownload,\n ci: isCi(options.env),\n });\n if (onboard === undefined) {\n return 0;\n }\n const enginePin = enginePinOf(readManifest(project.manifestFile, home, options.argv));\n const dir = await ensure(options, \"engines\", enginePin, home, noDownload);\n const engine = engineAt(dir, enginePin.name, enginePin.version);\n return delegate(options, engine, onboard, home, options.cwd);\n}\n\n/**\n * The child gets the resolved store, because the engine loads the extensions the\n * launcher just verified out of it and the two must not disagree about where it\n * is. Everything else about the environment is the user's.\n */\nfunction delegate(\n options: LauncherOptions,\n engine: Engine,\n forwarded: readonly string[],\n home: string,\n cwd: string,\n): Promise<number> {\n return options.spawn({\n command: process.execPath,\n args: [engine.entry, ...forwarded],\n cwd,\n env: { ...options.env, [PENV_HOME_VAR]: home },\n });\n}\n"],"mappings":";AA4BA,IAAM,SAAS,oBAAI,IAAI,CAAC,KAAK,KAAK,GAAG,CAAC;AAGtC,SAAS,WAAW,QAAgB,OAAuB;AACzD,MAAI,IAAI;AACR,aAAS;AACP,UAAM,KAAK,OAAO,OAAO,CAAC;AAC1B,QAAI,OAAO,OAAO,OAAO,OAAQ,OAAO,QAAQ,OAAO,MAAM;AAC3D,WAAK;AACL;AAAA,IACF;AACA,QAAI,OAAO,OAAO,OAAO,OAAO,IAAI,CAAC,MAAM,KAAK;AAC9C,YAAM,MAAM,OAAO,Q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C7D;AAOA,SAAS,SACP,SACA,QACA,WACA,MACA,KACiB;AACjB,SAAO,QAAQ,MAAM;AAAA,IACnB,SAAS,QAAQ;AAAA,IACjB,MAAM,CAAC,OAAO,OAAO,GAAG,SAAS;AAAA,IACjC;AAAA,IACA,KAAK,EAAE,GAAG,QAAQ,KAAK,CAAC,aAAa,GAAG,KAAK;AAAA,EAC/C,CAAC;AACH;","names":["EXTENSIONS_PATH","EXTENSIONS_PATH","relative","text","readFileSync","join","resolve","sep","PenvError","text","field","record","header","mkdirSync","readFileSync","writeFileSync","dirname","join","readFileSync","join","dirname","mkdirSync","writeFileSync","text","readFileSync","writeFileSync","sep","MANIFEST_PATH","OFFICIAL_SCOPE","text","at","OFFICIAL_SCOPE","readFileSync","sep","writeFileSync","MANIFEST_PATH","existsSync","readFileSync","dirname","join","resolve","sep","ENGINE_PACKAGE","PenvError","readFileSync","join","resolve","sep","existsSync","require","ENGINE_PACKAGE","PenvError","dirname","ENGINE_PACKAGE","ENGINE_PACKAGE","existsSync","dirname","join","resolve","MANIFEST_PATH","existsSync","readFileSync","writeFileSync","join","MANIFEST_PATH","PenvError","parseManifest","serializeManifest","parseManifest","readFileSync","PenvError","manifest","join","MANIFEST_PATH","existsSync","writeFileSync","serializeManifest"]}
|