@kubb/studio 5.20.2 → 5.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["mkdir","process","process","kubbVersion","version","writeFile","NodeWebSocket","delay","delay"],"sources":["../src/agentKey.ts","../../../internals/utils/src/promise.ts","../../../internals/utils/src/casing.ts","../../../internals/utils/src/errors.ts","../../../internals/utils/src/runtime.ts","../../../internals/utils/src/fs.ts","../package.json","../../../internals/shared/src/constants.ts","../../../internals/shared/src/configFile/ast.ts","../../../internals/shared/src/configFile/rules.ts","../../../internals/shared/src/configFile/text.ts","../../../internals/shared/src/configFile/configFile.ts","../src/diff.ts","../src/generations.ts","../src/generationEvents.ts","../src/publicFetch.ts","../src/resolveConfig.ts","../src/url.ts","../src/connect.ts","../src/pair.ts","../src/snapshot.ts"],"sourcesContent":["import { createPublicKey, generateKeyPairSync, hash, sign, verify } from 'node:crypto'\nimport type { AgentSignatureContext } from './protocol.ts'\n\nfunction signedBytes({ context, payload }: { context: AgentSignatureContext; payload: string }): Buffer {\n return Buffer.from(`${context}\\n${payload}`, 'utf8')\n}\n\n/**\n * Creates the agent's Ed25519 key as a PKCS #8 PEM string, to store with the token.\n */\nexport function generateAgentKey(): string {\n return generateKeyPairSync('ed25519').privateKey.export({ format: 'pem', type: 'pkcs8' }).toString()\n}\n\n/**\n * Returns the raw 32-byte public key of `privateKey`, base64url without padding.\n */\nexport function getAgentPublicKey(privateKey: string): string {\n return createPublicKey(privateKey).export({ format: 'jwk' }).x!\n}\n\n/**\n * Signs `payload` for `context` and returns the Ed25519 signature in base64url.\n */\nexport function signAgentPayload({ privateKey, context, payload }: { privateKey: string; context: AgentSignatureContext; payload: string }): string {\n return sign(null, signedBytes({ context, payload }), privateKey).toString('base64url')\n}\n\n/**\n * Checks a {@link signAgentPayload} signature. Malformed input returns `false` and never throws.\n */\nexport function verifyAgentSignature({\n publicKey,\n context,\n payload,\n signature,\n}: {\n publicKey: string\n context: AgentSignatureContext\n payload: string\n signature: string\n}): boolean {\n try {\n const key = createPublicKey({ key: { kty: 'OKP', crv: 'Ed25519', x: publicKey }, format: 'jwk' })\n return verify(null, signedBytes({ context, payload }), key, Buffer.from(signature, 'base64url'))\n } catch {\n return false\n }\n}\n\nexport function getTokenRefreshPayload({ token, signedAt }: { token: string; signedAt: number }): string {\n return `${signedAt}\\n${hash('sha256', token)}`\n}\n","/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Returns the value cached under `key` in `store`, computing and storing it on the first call.\n * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive\n * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.\n *\n * @example\n * `const refs = memo(refCache, node, () => collectRefs(node))`\n */\nexport function memo<TKey, TValue>(store: Store<TKey, TValue>, key: TKey, compute: () => TValue): TValue {\n const cached = store.get(key)\n if (cached !== undefined || store.has(key)) return cached as TValue\n const value = compute()\n store.set(key, value)\n return value\n}\n\n/**\n * Creates a store for `memo`. With no options it is a `Map`. Each option changes one thing:\n *\n * - `weak` holds the keys weakly, in a `WeakMap`, so an entry goes away with its key.\n * - `max` bounds the store: it empties itself before the entry that would pass `max`, which keeps a\n * cache in a long-running process from growing without end. `max: 1` keeps only the last entry.\n *\n * @example\n * `const patterns = memo.create<string, RegExp>()`\n *\n * @example Freed with its key\n * `const refs = memo.create<SchemaNode, Array<string>>({ weak: true })`\n *\n * @example Bounded\n * `const names = memo.create<string, string>({ max: 100_000 })`\n *\n * @example Many values per key\n * ```ts\n * const filesByPlugin = memo.create<string, Array<string>>()\n * memo(filesByPlugin, 'plugin-ts', () => []).push('models.ts')\n * ```\n */\nfunction createStore<TKey, TValue>(options?: { weak?: false; max?: undefined }): Map<TKey, TValue>\nfunction createStore<TKey extends WeakKey, TValue>(options: { weak: true; max?: undefined }): WeakMap<TKey, TValue>\nfunction createStore<TKey, TValue>(options: { max: number; weak?: false }): Store<TKey, TValue>\nfunction createStore<TKey, TValue>({ weak, max }: { weak?: boolean; max?: number } = {}): Store<TKey, TValue> {\n if (weak) return new WeakMap<WeakKey, TValue>() as Store<TKey, TValue>\n const entry = new Map<TKey, TValue>()\n if (max === undefined) return entry\n const set = (key: TKey, value: TValue) => {\n if (entry.size >= max) entry.clear()\n entry.set(key, value)\n }\n if (max !== 1) return { has: (key) => entry.has(key), get: (key) => entry.get(key), set }\n // A key equal to the stored one but a different object, such as a copy of a string, replaces the\n // stored key, so the next lookup is an identity hit instead of a full comparison.\n const touch = (key: TKey) => {\n if (!entry.has(key)) return false\n set(key, entry.get(key) as TValue)\n return true\n }\n return { has: touch, get: (key) => (touch(key) ? entry.get(key) : undefined), set }\n}\n\nmemo.create = createStore\n\ntype ParallelOptions<TItem> = {\n /**\n * Items to work through, handed out in order.\n */\n items: ReadonlyArray<TItem>\n /**\n * How many items may be in flight at once.\n */\n limit: number\n /**\n * Runs once per item, with the item's position so a caller can report progress.\n */\n run(item: TItem, index: number): Promise<void>\n}\n\n/**\n * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each\n * takes the next item the moment it frees up instead of waiting for a batch to drain.\n *\n * @example\n * ```ts\n * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })\n * ```\n */\nexport async function inParallel<TItem>({ items, limit, run }: ParallelOptions<TItem>): Promise<void> {\n const queue = items.entries()\n\n const worker = async (): Promise<void> => {\n for (const [index, item] of queue) await run(item, index)\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()))\n}\n","import { memo } from './promise.ts'\n\ntype Options = {\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction convert(text: string, pascal: boolean): string {\n return (\n text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n // A status range such as `2xx` stays one word.\n .replace(/(\\d)(?!xx(?![a-z]))([a-z])/g, '$1 $2')\n .split(/[\\s\\-_./\\\\:]+/)\n .filter(Boolean)\n .map((word, i) => {\n if (word.length > 1 && word === word.toUpperCase()) return word\n const head = i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()\n return head + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n )\n}\n\n// Plugins case the same names on every visit. Clearing at the limit bounds a long-running host.\nconst cache = memo.create<string, string>({ max: 100_000 })\n\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const key = `${pascal ? 'P' : 'c'}${text}`\n return memo(cache, key, () => convert(text, pascal))\n}\n\n/**\n * Converts `text` to camelCase.\n *\n * @example Word boundaries\n * `camelCase('hello-world') // 'helloWorld'`\n *\n * @example With a prefix\n * `camelCase('tag', { prefix: 'create' }) // 'createTag'`\n */\nexport function camelCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n *\n * @example Word boundaries\n * `pascalCase('hello-world') // 'HelloWorld'`\n *\n * @example With a suffix\n * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`\n */\nexport function pascalCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n// A word starts at `petType`, `sensor2Reading`, and `HTTPResponse`, while `IDs` and `OAuth` stay whole\nconst wordStart = /(?<=[a-z\\d])(?=[A-Z])|(?<=[A-Z]{2})(?=[A-Z][a-z]{2})/\n\n// A segment without lowercase letters, such as `COOL` or `2D`, stays one word, so a snake_case name is left unchanged.\nfunction words(text: string): Array<string> {\n return text\n .split(/[\\s\\-_./\\\\:]+/)\n .filter(Boolean)\n .flatMap((segment) => (segment === segment.toUpperCase() ? segment : segment.split(wordStart)))\n}\n\n/**\n * Uppercases only the first character of `text`. Unlike `pascalCase` it never splits words or strips characters.\n *\n * @example\n * `capitalize('getPetById') // 'GetPetById'`\n */\nexport function capitalize(text: string): string {\n return `${text.charAt(0).toUpperCase()}${text.slice(1)}`\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * `snakeCase('helloWorld') // 'hello_world'`\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return words(`${prefix} ${text} ${suffix}`)\n .map((word) => word.replace(/[^a-zA-Z0-9]/g, '').toLowerCase())\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * `screamingSnakeCase('helloWorld') // 'HELLO_WORLD'`\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new Error('Build failed', { cause: toError(err) })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Returns `error` followed by every error in its `cause` chain, outermost first. Stops at a\n * non-`Error` cause or a cycle.\n *\n * @example\n * ```ts\n * getErrorChain(new Error('Config failed loading', { cause: new Error('boom') })).map((error) => error.message)\n * // ['Config failed loading', 'boom']\n * ```\n */\nexport function getErrorChain(error: unknown): Array<Error> {\n const chain: Array<Error> = []\n for (let current = error; current instanceof Error && !chain.includes(current); current = current.cause) {\n chain.push(current)\n }\n return chain\n}\n","// Bun polyfills `process.versions.node`, so detection keys off the globals instead.\nconst isBun = typeof Bun !== 'undefined'\nconst isDeno = 'Deno' in globalThis\n\n/**\n * The JavaScript runtime executing the current process: its name, version and whether it is Bun.\n *\n * @example\n * ```ts\n * runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise\n * ```\n */\nexport const runtime = { isBun, ...detect() } as const\n\nfunction detect(): { name: 'bun' | 'deno' | 'node'; version: string } {\n if (isBun) return { name: 'bun', version: process.versions.bun ?? '' }\n if (isDeno) return { name: 'deno', version: (globalThis as { Deno?: { version?: { deno?: string } } }).Deno?.version?.deno ?? '' }\n return { name: 'node', version: process.versions?.node ?? '' }\n}\n","import { existsSync, readFile, readFileSync, writeFile } from 'node:fs'\nimport { access, glob as globNode, mkdir } from 'node:fs/promises'\nimport { dirname, isAbsolute, join, relative, resolve } from 'node:path'\nimport { runtime } from './runtime.ts'\n\nexport { existsSync } from 'node:fs'\nexport { mkdir, mkdtemp, rm } from 'node:fs/promises'\n\n/**\n * Resolves to `true` when the file or directory at `path` exists.\n * Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.\n *\n * @example\n * ```ts\n * if (await exists('./kubb.config.ts')) {\n * const content = await read('./kubb.config.ts')\n * }\n * ```\n */\nexport async function exists(path: string): Promise<boolean> {\n if (runtime.isBun) {\n return Bun.file(path).exists()\n }\n return access(path).then(\n () => true,\n () => false,\n )\n}\n\n/**\n * Reads the file at `path` as a UTF-8 string.\n * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.\n *\n * @example\n * ```ts\n * const source = await read('./src/Pet.ts')\n * ```\n */\nexport async function read(path: string): Promise<string> {\n if (runtime.isBun) {\n return Bun.file(path).text()\n }\n // The callback API skips the `FileHandle` every `fs/promises` call opens.\n return new Promise((resolvePromise, reject) => readFile(path, { encoding: 'utf8' }, (error, data) => (error ? reject(error) : resolvePromise(data))))\n}\n\n/**\n * Reads the file at `path` as a UTF-8 string, or `null` when it does not exist or cannot be read.\n * Uses `Bun.file().text()` when running under Bun, `fs.readFileSync` otherwise.\n *\n * @example\n * ```ts\n * const stored = await readIfExists('./src/gen/Pet.ts') // null on a first run\n * ```\n */\nexport async function readIfExists(path: string): Promise<string | null> {\n if (runtime.isBun) {\n return Bun.file(path)\n .text()\n .catch(() => null)\n }\n // A small read is faster on the main thread than a thread-pool round trip, and `existsSync`\n // answers a missing file without building an error.\n if (!existsSync(path)) return null\n try {\n return readFileSync(path, 'utf8')\n } catch (_error) {\n return null\n }\n}\n\ntype WriteOptions = {\n /**\n * Previously read content, or `null` when the file does not exist.\n * Omitting this value reads the file before writing.\n */\n stored?: string | null\n /**\n * When `true`, re-reads the file immediately after writing and throws if the\n * content does not match — useful for catching write failures on unreliable file systems.\n */\n sanity?: boolean\n}\n\n/**\n * Whether `stored` already holds `source`, comparing on the trimmed text rather than the exact\n * bytes. Surrounding whitespace is what a formatter adds and what editors strip, and neither is a\n * reason to rewrite the file.\n *\n * Both sides are trimmed, so a storage that keeps bytes verbatim settles on the same answer as one\n * that normalizes what it stores. Trimming only `stored` would leave a source with leading\n * whitespace rewritten on every build, since the stored copy keeps the whitespace the comparison\n * has already dropped.\n */\nexport function matchesStored({ stored, source }: { stored: string; source: string }): boolean {\n return stored.trim() === source.trim()\n}\n\n/**\n * Writes `data` to `path`, trimming surrounding whitespace and ending the file with a single newline\n * the way prettier, biome, and oxfmt all do.\n * Skips the write when the trimmed content is empty, or when the file already holds that content.\n * Creates any missing parent directories automatically.\n * When `sanity` is `true`, re-reads the file after writing and throws if the content does not match.\n *\n * @example\n * ```ts\n * await write('./src/Pet.ts', source) // writes and returns the trimmed content plus a newline\n * await write('./src/Pet.ts', source) // null — file unchanged\n * await write('./src/Pet.ts', ' ') // null — empty content skipped\n * ```\n */\nexport async function write(path: string, data: string, options: WriteOptions = {}): Promise<string | null> {\n const trimmed = data.trim()\n if (trimmed === '') return null\n\n const content = `${trimmed}\\n`\n const resolved = resolve(path)\n const stored = options.stored === undefined ? await readIfExists(resolved) : options.stored\n if (matchesStored({ stored: stored ?? '', source: trimmed })) return null\n\n await writeRaw(resolved, content)\n\n if (options.sanity) {\n const savedData = await read(resolved)\n if (savedData !== content) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n return savedData\n }\n\n return content\n}\n\n/**\n * Writes UTF-8 content verbatim, including empty files and surrounding whitespace.\n * Uses Bun.write under Bun and creates missing parent directories under either runtime.\n *\n * @example\n * await writeRaw('./cache/output.ts', ' // keep these bytes\\n\\n')\n */\nexport async function writeRaw(path: string, content: string): Promise<void> {\n const resolved = resolve(path)\n if (runtime.isBun) {\n await Bun.write(resolved, content)\n return\n }\n try {\n await new Promise<void>((resolvePromise, reject) =>\n writeFile(resolved, content, { encoding: 'utf-8' }, (error) => (error ? reject(error) : resolvePromise())),\n )\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error\n await mkdir(dirname(resolved), { recursive: true })\n await new Promise<void>((resolvePromise, reject) =>\n writeFile(resolved, content, { encoding: 'utf-8' }, (error) => (error ? reject(error) : resolvePromise())),\n )\n }\n}\n\n/**\n * Lists non-hidden regular files below `directory` as relative POSIX paths, excluding directories and symlinks.\n * Uses Bun.Glob under Bun because its Node glob compatibility API lacks directory-entry support.\n *\n * @example\n * for await (const path of listFiles('./src')) console.log(path)\n */\nexport async function* listFiles(directory: string): AsyncGenerator<string> {\n const cwd = resolve(directory)\n if (runtime.isBun) {\n yield* new Bun.Glob('**/*').scan({ cwd, dot: false, onlyFiles: true, followSymlinks: false })\n return\n }\n for await (const entry of globNode('**/*', { cwd, withFileTypes: true })) {\n if (entry.isFile()) yield toPosixPath(relative(cwd, join(entry.parentPath, entry.name)))\n }\n}\n\n/**\n * Converts a filesystem path to use POSIX (`/`) separators.\n *\n * Most of the codebase compares and composes paths as strings (prefix matching, joining for\n * import specifiers, splitting on `/`). On POSIX `path.resolve` already returns `/`-separated\n * paths, but on Windows it returns `\\`-separated paths, which breaks every such comparison.\n *\n * Routing every path that crosses a module boundary through `toPosixPath` keeps the rest of the\n * code platform-agnostic. The conversion runs unconditionally so Windows-specific behavior is\n * exercisable from POSIX CI.\n *\n * @example\n * toPosixPath('C:\\\\repo\\\\src\\\\pet.ts') // 'C:/repo/src/pet.ts'\n */\nexport function toPosixPath(filePath: string): string {\n return filePath.replaceAll('\\\\', '/')\n}\n\n/**\n * Resolves to `true` when `path` is `parent` itself or nested inside it. Both sides are resolved\n * to absolute paths first, so relative and `..`-containing inputs compare correctly.\n *\n * Guards a destructive or an out-of-tree operation: before wiping an output directory, check that\n * it does not contain the project root, and before loading a path a caller supplied, check that it\n * did not escape the directory it is allowed to read from.\n *\n * @example\n * isPathInside('./src/gen', '.') // true — nested inside the root\n * isPathInside('.', '.') // true — the same directory counts as inside\n * isPathInside('.', './src/gen') // false — the root is not inside its own output\n * isPathInside('../other', '.') // false — escapes the root\n */\nexport function isPathInside(path: string, parent: string): boolean {\n const resolvedPath = resolve(path)\n const resolvedParent = resolve(parent)\n if (resolvedPath === resolvedParent) {\n return true\n }\n\n const rel = relative(resolvedParent, resolvedPath)\n\n return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel)\n}\n","","export const KUBB_CONFIG_FILENAME = 'kubb.config.ts' as const\n\n/** File extensions a Kubb config file may use. */\nexport const CONFIG_EXTENSIONS = ['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs'] as const\n\nexport const KUBB_PACKAGE_NAME = 'kubb' as const\n\n/**\n * Extensions `kubb` ships at its own version, so they count as installed without being a direct\n * dependency. `constants.test.ts` checks it against the `kubb` package's dependencies.\n */\nexport const BUNDLED_PACKAGES: ReadonlyArray<string> = ['@kubb/adapter-oas', '@kubb/parser-ts', '@kubb/parser-md', '@kubb/plugin-barrel']\n\nexport const initDefaults = {\n inputPath: './openapi.yaml',\n outputPath: './src/gen',\n plugins: ['plugin-ts'],\n} as const\n","import { getErrorMessage } from '@internals/utils'\nimport { type Comment, type Expression, type Program, parse } from 'yuku-parser'\n\nexport type {\n ArrayExpression,\n AssignmentExpression,\n BindingProperty,\n CallExpression,\n Comment,\n Expression,\n ImportDeclaration,\n ObjectExpression,\n ObjectPropertyKind,\n Program,\n RestElement,\n SpreadElement,\n VariableDeclaration,\n} from 'yuku-parser'\n\n/** Node types the config editor reads from the yuku AST. */\nexport const nodeTypes = {\n arrayExpression: 'ArrayExpression',\n arrowFunctionExpression: 'ArrowFunctionExpression',\n assignmentExpression: 'AssignmentExpression',\n blockStatement: 'BlockStatement',\n callExpression: 'CallExpression',\n exportDefaultDeclaration: 'ExportDefaultDeclaration',\n expressionStatement: 'ExpressionStatement',\n functionExpression: 'FunctionExpression',\n identifier: 'Identifier',\n importDeclaration: 'ImportDeclaration',\n importSpecifier: 'ImportSpecifier',\n literal: 'Literal',\n memberExpression: 'MemberExpression',\n objectExpression: 'ObjectExpression',\n objectPattern: 'ObjectPattern',\n property: 'Property',\n returnStatement: 'ReturnStatement',\n spreadElement: 'SpreadElement',\n tSAsExpression: 'TSAsExpression',\n tSSatisfiesExpression: 'TSSatisfiesExpression',\n templateLiteral: 'TemplateLiteral',\n unaryExpression: 'UnaryExpression',\n variableDeclaration: 'VariableDeclaration',\n} as const\n\nexport const commentTypes = { line: 'Line' } as const\nexport const propertyKinds = { init: 'init' } as const\nexport const unaryOperators = { minus: '-', plus: '+' } as const\nconst diagnosticSeverities = { error: 'error' } as const\n\n/** A parsed file: its statements and every comment in it, or why it could not be parsed. */\ntype ParsedSource = { program: Program; comments: Array<Comment> } | { reason: string }\n\n/**\n * Parses `source` as a TypeScript module. Never throws: a syntax error, or a native parser that\n * cannot load on this platform, comes back as a `reason`.\n */\nexport function parseSource(source: string): ParsedSource {\n try {\n // Parentheses are dropped, so `export default (defineConfig({}))` reads as the call itself.\n const { program, comments, diagnostics } = parse(source, { lang: 'ts', sourceType: 'module', preserveParens: false })\n if (diagnostics.some((diagnostic) => diagnostic.severity === diagnosticSeverities.error)) return { reason: 'the config file could not be parsed' }\n return { program, comments }\n } catch (error) {\n return { reason: `the config parser could not load on this platform: ${getErrorMessage(error)}` }\n }\n}\n\n/** Parses `source` as one expression, such as a commented-out `pluginTs({ ... })` call. */\nexport function parseExpression(source: string): Expression | undefined {\n const parsed = parseSource(source)\n if ('reason' in parsed) return undefined\n const [statement] = parsed.program.body\n return parsed.program.body.length === 1 && statement?.type === nodeTypes.expressionStatement ? statement.expression : undefined\n}\n","import path from 'node:path'\nimport { type ExtensionKind, isPackageName } from '@kubb/core'\nimport { camelCase } from '@internals/utils'\nimport { extensionKinds, type InstalledExtensions, type OptionValue } from './types.ts'\n\n/** `@kubb/plugin-ts` becomes `plugin-ts`, the `name` Kubb plugin factories use. */\nexport function toPluginName(packageName: string): string {\n return packageName.split('/').pop() ?? packageName\n}\n\n/** `@kubb/plugin-react-query` becomes `pluginReactQuery`, the export a plugin package uses by convention. */\nexport function toExportName(packageName: string): string {\n return camelCase(toPluginName(packageName))\n}\n\nconst KUBB_PLUGIN_SPECIFIER = /^@kubb\\/plugin-[\\w.-]+$/\n\n/** Only a `@kubb/plugin-*` package or an installed extension of `kind` may be imported, never a path or URL. */\nexport function isAllowedPlugin({\n packageName,\n extensions,\n kind = extensionKinds.plugin,\n}: {\n packageName: string\n extensions: InstalledExtensions\n kind?: ExtensionKind\n}): boolean {\n if (!isPackageName(packageName)) return false\n return (kind === extensionKinds.plugin && KUBB_PLUGIN_SPECIFIER.test(packageName)) || extensions.get(packageName)?.manifest.kind === kind\n}\n\nconst UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype'])\n\n/** Whether `key` can be an option key without reaching the object's prototype. */\nexport function isSafeKey(key: string): boolean {\n return !UNSAFE_KEYS.has(key)\n}\n\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null) return false\n const prototype = Object.getPrototypeOf(value)\n return prototype === null || prototype === Object.prototype\n}\n\n/** Whether `value` survives a JSON round trip, so an edit never writes a lossy copy into the file. */\nexport function isOptionValue(value: unknown): value is OptionValue {\n if (value === null || typeof value === 'string' || typeof value === 'boolean') return true\n if (typeof value === 'number') return Number.isFinite(value)\n if (Array.isArray(value)) return value.every(isOptionValue)\n if (isPlainObject(value)) return Object.entries(value).every(([key, entry]) => isSafeKey(key) && isOptionValue(entry))\n\n return false\n}\n\n/** The root `output` members Studio may set, with the values each takes. */\nconst OUTPUT_VALUES: Record<string, (value: unknown) => boolean> = {\n barrel: (value) => value === false || (isPlainObject(value) && Object.keys(value).length === 1 && (value.type === 'named' || value.type === 'all')),\n format: (value) => value === false || ['auto', 'prettier', 'biome', 'oxfmt'].includes(value as string),\n lint: (value) => value === false || ['auto', 'eslint', 'biome', 'oxlint'].includes(value as string),\n clean: (value) => typeof value === 'boolean',\n defaultBanner: (value) => value === false || value === 'simple' || value === 'full',\n}\n\nexport function isOutputKey(key: string): boolean {\n return Object.hasOwn(OUTPUT_VALUES, key)\n}\n\nexport function isOutputValue({ key, value }: { key: string; value: unknown }): boolean {\n return isOutputKey(key) && OUTPUT_VALUES[key]!(value)\n}\n\nexport function pickOutput<T>(output: Record<string, T>): Record<string, T> {\n return Object.fromEntries(Object.entries(output).filter(([key]) => isOutputKey(key)))\n}\n\n/**\n * Returns the first `output.path` in `value`, at any depth (`override` entries included), that is\n * absolute or climbs out of the folder it resolves against.\n */\nexport function findEscapingOutputPath(value: unknown): string | undefined {\n if (!Array.isArray(value) && !isPlainObject(value)) return undefined\n\n const output = isPlainObject(value) ? value.output : undefined\n if (isPlainObject(output) && typeof output.path === 'string') {\n const normalized = path.posix.normalize(output.path.replaceAll('\\\\', '/'))\n // Checked before normalizing, which turns `C:/../src` into `src`. A drive letter always leaves the folder.\n if (path.posix.isAbsolute(normalized) || /^[a-z]:/i.test(output.path) || normalized === '..' || normalized.startsWith('../')) return output.path\n }\n for (const entry of Object.values(value)) {\n const found = findEscapingOutputPath(entry)\n if (found !== undefined) return found\n }\n return undefined\n}\n","import type { ValueOf } from '@internals/utils'\nimport { type ArrayExpression, nodeTypes, type ObjectExpression } from './ast.ts'\nimport type { OptionValue } from './types.ts'\n\n/**\n * A valid JavaScript identifier, so an import name can only ever print as `import { name } from`,\n * never as source that breaks out of the import statement.\n */\nexport const IDENTIFIER_PATTERN = /^[A-Za-z_$][\\w$]*$/\n\nexport const quotes = { single: `'`, double: `\"` } as const\nexport type Quote = ValueOf<typeof quotes>\n\n/** `source` with the text between `start` and `end` replaced by `text`. */\nexport function replaceText(source: string, start: number, end: number, text = ''): string {\n return `${source.slice(0, start)}${text}${source.slice(end)}`\n}\n\n/** The 1-based line and 0-based column of `offset` in `source`. */\nexport function getPosition(source: string, offset: number): { line: number; column: number } {\n return { line: source.slice(0, offset).split('\\n').length, column: offset - source.lastIndexOf('\\n', offset - 1) - 1 }\n}\n\n/** Writes `value` as a single-line literal with the file's quote style. */\nexport function printValue(value: OptionValue, quote: Quote): string {\n if (typeof value === 'string') {\n // JSON's escaping covers every character that could end the literal or the line.\n const escaped = JSON.stringify(value).slice(1, -1)\n return quote === quotes.double ? `\"${escaped}\"` : `'${escaped.replaceAll(`\\\\\"`, `\"`).replaceAll(`'`, `\\\\'`)}'`\n }\n if (value === null || typeof value !== 'object') return String(value)\n if (Array.isArray(value)) return `[${value.map((item) => printValue(item, quote)).join(', ')}]`\n\n const entries = Object.entries(value)\n return entries.length ? `{ ${entries.map(([key, item]) => `${printKey(key, quote)}: ${printValue(item, quote)}`).join(', ')} }` : '{}'\n}\n\n/** An object key as source text: bare when it is an identifier, quoted otherwise. */\nexport function printKey(key: string, quote: Quote): string {\n return IDENTIFIER_PATTERN.test(key) ? key : printValue(key, quote)\n}\n\n/** `value` wrapped in one object per key of `path`: `wrapPath(['enum', 'type'], 'enum')` is `{ enum: { type: 'enum' } }`. */\nexport function wrapPath(path: Array<string>, value: OptionValue): OptionValue {\n return path.reduceRight<OptionValue>((inner, key) => ({ [key]: inner }), value)\n}\n\n/**\n * Adds `text` as the last item of an object or array literal, following its layout: on a line of\n * its own with the last item's indentation when the literal spans lines, inline otherwise.\n */\nexport function appendItem(source: string, container: ObjectExpression | ArrayExpression, text: string): string {\n const { start, end } = container\n const items: Array<{ start: number; end: number } | null> = container.type === nodeTypes.objectExpression ? container.properties : container.elements\n const last = items.filter((item) => item !== null).at(-1)\n\n if (!last) {\n const inner = source.slice(start + 1, end - 1)\n // A comment inside the empty literal stays, after the new item.\n if (inner.trim()) return replaceText(source, start + 1, start + 1, /^\\s/.test(inner) ? `${text},` : `${text}, `)\n return replaceText(source, start, end, container.type === nodeTypes.objectExpression ? `{ ${text} }` : `[${text}]`)\n }\n\n const between = source.slice(last.end, end - 1)\n // The closing bracket shares the last item's line: add the item inline.\n if (!between.includes('\\n')) return replaceText(source, last.end, last.end, `, ${text}`)\n\n const lineStart = source.lastIndexOf('\\n', last.start - 1) + 1\n const indent = source.slice(lineStart).match(/^[ \\t]*/)?.[0] ?? ''\n // After the last item's comma and any comment on its line, so neither moves. `between` holds a\n // newline, so one always follows.\n const lineEnd = source.indexOf('\\n', last.end)\n const comma = /^\\s*,/.test(between)\n\n return `${source.slice(0, last.end)}${comma ? '' : ','}${source.slice(last.end, lineEnd)}\\n${indent}${text}${comma ? ',' : ''}${source.slice(lineEnd)}`\n}\n\n/** Drops the item at `index` from an object or array literal, with its own lines when it sits on them alone. */\nexport function removeItem(source: string, node: ObjectExpression | ArrayExpression, index: number): string {\n const items: Array<{ start: number; end: number }> =\n node.type === nodeTypes.objectExpression ? node.properties : node.elements.filter((element) => element !== null)\n if (items.length === 1) return replaceText(source, node.start, node.end, node.type === nodeTypes.objectExpression ? '{}' : '[]')\n\n const { start, end } = items[index]!\n const lineStart = source.lastIndexOf('\\n', start - 1) + 1\n const nextNewline = source.indexOf('\\n', end)\n const lineEnd = nextNewline === -1 ? source.length : nextNewline\n if (!source.slice(lineStart, start).trim() && /^\\s*,?\\s*(\\/\\/.*)?$/.test(source.slice(end, lineEnd))) {\n return replaceText(source, lineStart, Math.min(lineEnd + 1, source.length))\n }\n\n const next = items[index + 1]\n return next ? replaceText(source, start, next.start) : replaceText(source, items[index - 1]!.end, end)\n}\n","import type { ExtensionKind } from '@kubb/core'\nimport { getErrorMessage, memo, read, writeRaw } from '@internals/utils'\nimport type { ValueOf } from '@internals/utils'\nimport {\n type AssignmentExpression,\n type BindingProperty,\n type CallExpression,\n type Comment,\n type Expression,\n type ImportDeclaration,\n type ObjectExpression,\n type ObjectPropertyKind,\n type Program,\n type RestElement,\n type SpreadElement,\n type VariableDeclaration,\n commentTypes,\n nodeTypes,\n parseExpression,\n parseSource,\n propertyKinds,\n unaryOperators,\n} from './ast.ts'\nimport { findEscapingOutputPath, isAllowedPlugin, isOptionValue, isOutputKey, isOutputValue, isSafeKey, pickOutput, toExportName } from './rules.ts'\nimport { appendItem, getPosition, IDENTIFIER_PATTERN, printKey, printValue, quotes, type Quote, removeItem, replaceText, wrapPath } from './text.ts'\nimport {\n type ConfigEdit,\n ConfigEditOperation,\n type ConfigEditOutcome,\n type ConfigFileView,\n type ConfigRef,\n type ConfigView,\n extensionKinds,\n type InstalledExtensions,\n type OptionsView,\n type OptionValue,\n type PluginView,\n} from './types.ts'\n\n/** The marker `disable-plugin` writes, with the block's line count so `enable-plugin` restores exactly those lines. */\nconst DISABLED_MARKER_PATTERN = /^kubb:disabled (.+)\\s+(\\d+)$/\n\nconst OPERATIONS = new Set<string>(Object.values(ConfigEditOperation))\nconst OPTION_OPERATIONS = new Set<string>([ConfigEditOperation.SET_OPTION, ConfigEditOperation.REMOVE_OPTION])\nconst OUTPUT_OPERATIONS = new Set<string>([ConfigEditOperation.SET_OUTPUT, ConfigEditOperation.REMOVE_OUTPUT])\nconst KINDS = new Set<string>(Object.values(extensionKinds))\n\n/** Identifiers the editor matches by name. */\nconst identifiers = { defineConfig: 'defineConfig', require: 'require', module: 'module', exports: 'exports' } as const\n\nconst moduleKinds = { esm: 'esm', cjs: 'cjs' } as const\ntype ModuleKind = ValueOf<typeof moduleKinds>\n\ntype EditResult = { source: string } | { reason: string }\ntype ParsedConfig = { program: Program; comments: Array<Comment>; configs: Array<ObjectExpression>; kind: ModuleKind }\ntype ValueNode = Expression | SpreadElement | null | undefined\ntype Import = { from: string; exported: string }\ntype FactoryCall = { importName: string; exportName: string; packageName: string; call: CallExpression }\ntype DisabledBlock = { packageName: string; line: number; end: number; code: Array<string> }\ntype OutputEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.SET_OUTPUT | typeof ConfigEditOperation.REMOVE_OUTPUT }>\ntype OptionEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.SET_OPTION | typeof ConfigEditOperation.REMOVE_OPTION }>\ntype AddPluginEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.ADD_PLUGIN }>\ntype DisablePluginEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.DISABLE_PLUGIN }>\ntype RemoveExtensionEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.REMOVE_EXTENSION }>\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value !== ''\n}\n\n/** Edits cross the wire, so their shape is checked before anything reads them. */\nfunction validateEdit(edit: ConfigEdit): string | undefined {\n const { operation, plugin, config, path, kind, input, value, options } = (typeof edit === 'object' && edit !== null ? edit : {}) as Record<string, unknown>\n\n if (typeof operation !== 'string' || !OPERATIONS.has(operation)) return `unknown operation ${JSON.stringify(operation)}`\n if (config !== undefined && typeof config !== 'string' && !Number.isSafeInteger(config)) return 'config must name an entry or give its index'\n\n if (operation === ConfigEditOperation.SET_INPUT) {\n return typeof input === 'string' && input.trim() !== '' ? undefined : 'the edit names no input'\n }\n\n const isOption = OPTION_OPERATIONS.has(operation)\n const isOutput = OUTPUT_OPERATIONS.has(operation)\n\n if (!isOutput && !isNonEmptyString(plugin)) return 'the edit names no plugin'\n\n // The next generation writes there, so an edit may only point a plugin inside the output folder.\n const written =\n operation === ConfigEditOperation.SET_OPTION && Array.isArray(path) ? path.reduceRight<unknown>((inner, key) => ({ [String(key)]: inner }), value) : options\n const escaping = findEscapingOutputPath(written)\n if (escaping !== undefined) return `output.path ${JSON.stringify(escaping)} resolves outside the output folder`\n\n if (kind !== undefined) {\n if (typeof kind !== 'string' || !KINDS.has(kind)) return `unknown kind ${JSON.stringify(kind)}`\n const takesKind = operation === ConfigEditOperation.ADD_PLUGIN || operation === ConfigEditOperation.REMOVE_EXTENSION\n if (takesKind && kind === extensionKinds.adapter) return `${operation} takes a plugin or a parser, since a config has one adapter`\n if (!isOption && !takesKind) return `${operation} edits the plugins array, so it takes no kind`\n }\n\n if (!isOption && !isOutput) return undefined\n\n if (!Array.isArray(path) || !path.every(isNonEmptyString)) return 'path must be a list of option names'\n if (path.length === 0) return 'no option path given'\n\n const unsafe = path.find((key) => !isSafeKey(key))\n if (unsafe !== undefined) return `${unsafe} cannot be used as an option name`\n\n if (isOutput && !isOutputKey(path[0]!)) return `output.${path[0]} can only be changed in the config file`\n\n return undefined\n}\n\n// Finding the config\n\n/** Steps through `as`/`satisfies` and `() => ...` wrappers to the config object. */\nfunction unwrapValue(node: ValueNode): ValueNode {\n if (!node) return undefined\n if (node.type === nodeTypes.tSAsExpression || node.type === nodeTypes.tSSatisfiesExpression) return unwrapValue(node.expression)\n if (node.type !== nodeTypes.arrowFunctionExpression && node.type !== nodeTypes.functionExpression) return node\n if (node.body?.type !== nodeTypes.blockStatement) return unwrapValue(node.body as Expression | null)\n\n const returned = node.body.body.find((statement) => statement.type === nodeTypes.returnStatement)\n return unwrapValue(returned?.type === nodeTypes.returnStatement ? returned.argument : undefined)\n}\n\nfunction isModuleExports(node: AssignmentExpression['left']): boolean {\n return (\n node.type === nodeTypes.memberExpression &&\n !node.computed &&\n node.object.type === nodeTypes.identifier &&\n node.object.name === identifiers.module &&\n node.property.type === nodeTypes.identifier &&\n node.property.name === identifiers.exports\n )\n}\n\n/** The exported config value and how the file exports it. */\nfunction findExport(program: Program): { exported: ValueNode; kind: ModuleKind } {\n for (const node of program.body) {\n if (node.type === nodeTypes.exportDefaultDeclaration) {\n // A `function` or `class` declaration is never a `defineConfig(...)` call, so `findConfigs` refuses it.\n return { exported: node.declaration as Expression, kind: moduleKinds.esm }\n }\n if (node.type === nodeTypes.expressionStatement && node.expression.type === nodeTypes.assignmentExpression && isModuleExports(node.expression.left)) {\n return { exported: node.expression.right, kind: moduleKinds.cjs }\n }\n }\n return { exported: undefined, kind: moduleKinds.esm }\n}\n\n/** Every config object in `export default` or `module.exports = defineConfig(...)`, or why the file is unmanaged. */\nfunction findConfigs(source: string): ParsedConfig | { reason: string } {\n const parsed = parseSource(source)\n if ('reason' in parsed) return parsed\n\n const { exported, kind } = findExport(parsed.program)\n const value = unwrapValue(exported)\n if (!value) return { reason: 'no `export default` or `module.exports` found' }\n if (value.type !== nodeTypes.callExpression || value.callee.type !== nodeTypes.identifier || value.callee.name !== identifiers.defineConfig) {\n return { reason: 'the exported config is not a defineConfig(...) call' }\n }\n\n const argument = unwrapValue(value.arguments[0])\n if (!argument) return { reason: 'defineConfig(...) was called without a config' }\n\n const entries = argument.type === nodeTypes.arrayExpression ? argument.elements.map((element) => unwrapValue(element)) : [argument]\n const configs = entries.filter((entry): entry is ObjectExpression => entry?.type === nodeTypes.objectExpression)\n if (configs.length !== entries.length) return { reason: 'config is not an object literal' }\n\n return { ...parsed, configs, kind }\n}\n\nfunction findConfigEntry(configs: Array<ObjectExpression>, ref: ConfigRef | undefined): ObjectExpression | undefined {\n return typeof ref === 'string' ? configs.find((entry) => getConfigName(entry) === ref) : configs[ref ?? 0]\n}\n\n// Reading object literals\n\nfunction getKey(entry: ObjectPropertyKind | BindingProperty | RestElement): string | undefined {\n if (entry.type !== nodeTypes.property || entry.computed) return undefined\n if (entry.key.type === nodeTypes.identifier) return entry.key.name\n return entry.key.type === nodeTypes.literal && typeof entry.key.value === 'string' ? entry.key.value : undefined\n}\n\n/** The last one wins when the key repeats, as at runtime. */\nfunction findProperty(node: ObjectExpression, key: string): { member: ObjectPropertyKind; index: number } | undefined {\n const index = node.properties.findLastIndex((entry) => getKey(entry) === key)\n return index === -1 ? undefined : { member: node.properties[index]!, index }\n}\n\nfunction getValue(node: ObjectExpression, key: string): ValueNode {\n const member = findProperty(node, key)?.member\n return member?.type === nodeTypes.property ? member.value : member\n}\n\nfunction getConfigName(config: ObjectExpression): string | undefined {\n const name = getValue(config, 'name')\n return name?.type === nodeTypes.literal && typeof name.value === 'string' ? name.value : undefined\n}\n\nfunction isOverridden(node: ObjectExpression, index: number): boolean {\n return node.properties.slice(index + 1).some((entry) => entry.type === nodeTypes.spreadElement)\n}\n\n/** `key: value`, not a method, getter, setter, or `{ key }` shorthand. */\nfunction isPlainProperty(member: Extract<ObjectPropertyKind, { type: typeof nodeTypes.property }>): boolean {\n return !member.method && !member.shorthand && member.kind === propertyKinds.init\n}\n\n/** A literal's value, `undefined` for code. */\nfunction readLiteral(node: ValueNode): OptionValue | undefined {\n switch (node?.type) {\n case nodeTypes.literal:\n // A bigint or a regex is code, not a value JSON can carry. A regex Node cannot compile also has a `null` value.\n return 'regex' in node || 'bigint' in node ? undefined : (node.value as OptionValue)\n case nodeTypes.templateLiteral:\n return node.expressions.length ? undefined : (node.quasis[0]?.value.cooked ?? '')\n case nodeTypes.unaryExpression: {\n const value = readLiteral(node.argument)\n if (typeof value !== 'number') return undefined\n if (node.operator === unaryOperators.minus) return -value\n if (node.operator === unaryOperators.plus) return value\n return undefined\n }\n case nodeTypes.arrayExpression: {\n const values = node.elements.map((element) => readLiteral(element))\n return values.every((value) => value !== undefined) ? values : undefined\n }\n case nodeTypes.objectExpression: {\n const entries: Record<string, OptionValue> = {}\n for (const entry of node.properties) {\n if (entry.type !== nodeTypes.property) return undefined\n const key = getKey(entry)\n const value = readLiteral(entry.value)\n // A `__proto__` key would replace the object's prototype instead of adding an entry.\n if (key === undefined || !isSafeKey(key) || value === undefined) return undefined\n entries[key] = value\n }\n return entries\n }\n }\n return undefined\n}\n\n// Imports and factory calls\n\nfunction getRequirePath(node: ValueNode): string | undefined {\n if (node?.type !== nodeTypes.callExpression || node.callee.type !== nodeTypes.identifier || node.callee.name !== identifiers.require) return undefined\n const [argument] = node.arguments\n return argument?.type === nodeTypes.literal && typeof argument.value === 'string' ? argument.value : undefined\n}\n\n/** `import { exported as local } from '...'`. A default or namespace import has no exported name, so its local name stands in. */\nfunction importBindings(statement: ImportDeclaration): Array<[string, Import]> {\n return statement.specifiers.map((specifier) => {\n const imported = specifier.type === nodeTypes.importSpecifier ? specifier.imported : specifier.local\n const exported = imported.type === nodeTypes.identifier ? imported.name : imported.value\n return [specifier.local.name, { from: statement.source.value, exported }]\n })\n}\n\n/** `const { exported: local } = require('...')`. */\nfunction requireBindings(statement: VariableDeclaration): Array<[string, Import]> {\n return statement.declarations.flatMap((declarator): Array<[string, Import]> => {\n const from = getRequirePath(declarator.init)\n if (from === undefined || declarator.id.type !== nodeTypes.objectPattern) return []\n\n return declarator.id.properties.flatMap((entry): Array<[string, Import]> => {\n if (entry.type !== nodeTypes.property || entry.value.type !== nodeTypes.identifier) return []\n return [[entry.value.name, { from, exported: getKey(entry) ?? entry.value.name }]]\n })\n })\n}\n\nfunction getImports(program: Program): Map<string, Import> {\n return new Map(\n program.body.flatMap((statement) => {\n if (statement.type === nodeTypes.importDeclaration) return importBindings(statement)\n if (statement.type === nodeTypes.variableDeclaration) return requireBindings(statement)\n return []\n }),\n )\n}\n\nfunction isImportStatement(node: Program['body'][number], kind: ModuleKind): boolean {\n if (kind === moduleKinds.esm) return node.type === nodeTypes.importDeclaration\n return node.type === nodeTypes.variableDeclaration && node.declarations.some((declarator) => getRequirePath(declarator.init) !== undefined)\n}\n\n/** The quote of the first string literal in the file, so new code matches it. */\nfunction detectQuote(node: unknown): Quote | undefined {\n if (!node || typeof node !== 'object') return undefined\n const { type, raw } = node as { type?: string; raw?: unknown }\n if (type === nodeTypes.literal && typeof raw === 'string' && (raw[0] === quotes.single || raw[0] === quotes.double)) return raw[0]\n for (const child of Object.values(node)) {\n const quote = detectQuote(child)\n if (quote) return quote\n }\n return undefined\n}\n\n/** The `adapter` value, or the elements of the `plugins` or `parsers` array. */\nfunction factoryNodes(config: ObjectExpression, kind: ExtensionKind): Array<ValueNode> {\n if (kind === extensionKinds.adapter) return [getValue(config, 'adapter')]\n const array = getValue(config, `${kind}s`)\n return array?.type === nodeTypes.arrayExpression ? array.elements : []\n}\n\n/** The factory calls of one kind whose callee the file imports. */\nfunction findCalls(program: Program, config: ObjectExpression, kind: ExtensionKind = extensionKinds.plugin): Array<FactoryCall> {\n const imports = getImports(program)\n return factoryNodes(config, kind).flatMap((node) => {\n if (node?.type !== nodeTypes.callExpression || node.callee.type !== nodeTypes.identifier) return []\n const imported = imports.get(node.callee.name)\n return imported ? [{ importName: node.callee.name, exportName: imported.exported, packageName: imported.from, call: node }] : []\n })\n}\n\n// Disabled plugins\n\n/** Whether nothing but whitespace precedes `offset` on its line. */\nfunction startsLine(source: string, offset: number): boolean {\n return source.slice(source.lastIndexOf('\\n', offset - 1) + 1, offset).trim() === ''\n}\n\n/** The `disable-plugin` blocks in this config, read from marker comments since the call is no longer a node. */\nfunction findDisabled(source: string, comments: Array<Comment>, config: ObjectExpression): Array<DisabledBlock> {\n const lines = source.split('\\n')\n\n return comments.flatMap((comment) => {\n const match = comment.type === commentTypes.line ? comment.value.trim().match(DISABLED_MARKER_PATTERN) : null\n // Only markers inside this entry, on a line of their own, so another entry or a trailing comment never matches.\n if (!match || comment.start < config.start || comment.end > config.end || !startsLine(source, comment.start)) return []\n\n const line = getPosition(source, comment.start).line\n const end = line + Number(match[2])\n const code = lines.slice(line, end).map((text) => text.replace(/^(\\s*)\\/\\/ ?/, '$1').replace(/^\\s+$/, ''))\n return [{ packageName: match[1]!, line, end, code }]\n })\n}\n\n// Reading options\n\n/** Literal members as `value` and code paths as `locked`, `undefined` for a computed key. */\nfunction readEditable(node: ObjectExpression, prefix: Array<string> = []): { value: Record<string, OptionValue>; locked: Array<Array<string>> } | undefined {\n const value: Record<string, OptionValue> = {}\n const locked: Array<Array<string>> = []\n\n for (const [index, entry] of node.properties.entries()) {\n if (entry.type === nodeTypes.spreadElement) continue\n const key = getKey(entry)\n if (key === undefined) return undefined\n if (findProperty(node, key)?.index !== index) continue\n\n const path = [...prefix, key]\n // A `__proto__` key replaces the prototype, so it reads as code.\n if (!isSafeKey(key)) {\n locked.push(path)\n continue\n }\n\n const member = isOverridden(node, index) ? undefined : entry.value\n const literal = readLiteral(member)\n if (literal !== undefined) {\n value[key] = literal\n continue\n }\n if (member?.type !== nodeTypes.objectExpression) {\n locked.push(path)\n continue\n }\n\n const nested = readEditable(member, path)\n if (!nested) return undefined\n value[key] = nested.value\n locked.push(...nested.locked)\n }\n return { value, locked }\n}\n\nfunction readObjectOptions(options: ObjectExpression): OptionsView {\n const entries: OptionsView = {}\n for (const [index, entry] of options.properties.entries()) {\n const key = getKey(entry)\n if (key === undefined || !isSafeKey(key)) continue\n\n const member = entry.type === nodeTypes.property && !isOverridden(options, index) ? entry.value : undefined\n const value = readLiteral(member)\n if (value !== undefined) {\n entries[key] = { literal: true, value }\n continue\n }\n entries[key] = { literal: false, ...(member?.type === nodeTypes.objectExpression ? readEditable(member) : undefined) }\n }\n return entries\n}\n\nfunction readCallOptions(call: CallExpression): OptionsView {\n const options = call.arguments[0]\n return options?.type === nodeTypes.objectExpression ? readObjectOptions(options) : {}\n}\n\nfunction readDisabledOptions(code: Array<string>): OptionsView {\n const call = parseExpression(code.join('\\n').trim().replace(/,$/, ''))\n return call?.type === nodeTypes.callExpression ? readCallOptions(call) : {}\n}\n\nfunction toPluginView({ importName, packageName, call }: FactoryCall): PluginView {\n return { importName, packageName, options: readCallOptions(call) }\n}\n\n/** Active and disabled plugins, in source order so a disabled plugin keeps its place. */\nfunction readPlugins({ source, parsed, config }: { source: string; parsed: ParsedConfig; config: ObjectExpression }): Array<PluginView> {\n const importNames = new Map([...getImports(parsed.program)].map(([local, { from }]) => [from, local]))\n\n const active = findCalls(parsed.program, config).map((call) => ({ line: getPosition(source, call.call.start).line, plugin: toPluginView(call) }))\n const disabled = findDisabled(source, parsed.comments, config).map(({ packageName, line, code }) => ({\n line,\n plugin: {\n importName: importNames.get(packageName) ?? toExportName(packageName),\n packageName,\n options: readDisabledOptions(code),\n disabled: true as const,\n },\n }))\n\n return [...active, ...disabled].sort((a, b) => a.line - b.line).map(({ plugin }) => plugin)\n}\n\nfunction readConfigView({ source, parsed, config }: { source: string; parsed: ParsedConfig; config: ObjectExpression }): ConfigView {\n const [adapter] = findCalls(parsed.program, config, extensionKinds.adapter).map(toPluginView)\n const parsers = findCalls(parsed.program, config, extensionKinds.parser).map(toPluginView)\n const output = getOutput(config)\n\n return {\n name: getConfigName(config),\n plugins: readPlugins({ source, parsed, config }),\n ...(adapter && { adapter }),\n ...(parsers.length ? { parsers } : {}),\n ...(!('reason' in output) && { output: pickOutput(readObjectOptions(output.object)) }),\n }\n}\n\n/** Which plugins the file declares and which options Studio may write. */\nexport function readConfig(source: string): ConfigFileView {\n const parsed = findConfigs(source)\n if ('reason' in parsed) return { managed: false, reason: parsed.reason }\n\n return { managed: true, configs: parsed.configs.map((config) => readConfigView({ source, parsed, config })) }\n}\n\n/** The modules the file imports, empty when it cannot be parsed. */\nexport function readImports(source: string): Array<string> {\n const parsed = parseSource(source)\n if ('reason' in parsed) return []\n return [...new Set([...getImports(parsed.program).values()].map(({ from }) => from))]\n}\n\n// Editing options\n\ntype FoundPath = { object: ObjectExpression; index: number; value: Expression } | { object: ObjectExpression; missing: number } | { reason: string }\n\n/** Follows `path` to its literal, or to the first missing key. Refuses a value set in code. */\nfunction findPath(options: ObjectExpression, path: Array<string>): FoundPath {\n let object = options\n\n for (const [depth, key] of path.entries()) {\n const found = findProperty(object, key)\n if (!found) return { object, missing: depth }\n if (isOverridden(object, found.index)) {\n return { reason: `${path.slice(0, depth + 1).join('.')} can be overridden by a spread after it, so it is customized in code` }\n }\n\n const { member, index } = found\n const isLast = depth === path.length - 1\n if (isLast) {\n return member.type === nodeTypes.property && readLiteral(member.value) !== undefined\n ? { object, index, value: member.value }\n : { reason: `${path.join('.')} is customized in code` }\n }\n if (member.type !== nodeTypes.property || member.value.type !== nodeTypes.objectExpression) {\n return { reason: `${key} is not an object, so ${path.join('.')} cannot be reached` }\n }\n object = member.value\n }\n return { reason: 'no option path given' }\n}\n\nfunction setAtPath({\n source,\n options,\n path,\n value,\n quote,\n}: {\n source: string\n options: ObjectExpression\n path: Array<string>\n value: OptionValue\n quote: Quote\n}): EditResult {\n const target = findPath(options, path)\n if ('reason' in target) return target\n if ('missing' in target) {\n const [key, ...rest] = path.slice(target.missing)\n return { source: appendItem(source, target.object, `${printKey(key!, quote)}: ${printValue(wrapPath(rest, value), quote)}`) }\n }\n return { source: replaceText(source, target.value.start, target.value.end, printValue(value, quote)) }\n}\n\nfunction removeAtPath({ source, options, path }: { source: string; options: ObjectExpression; path: Array<string> }): EditResult {\n const target = findPath(options, path)\n if ('reason' in target) return target\n if ('missing' in target) return { source }\n return { source: removeItem(source, target.object, target.index) }\n}\n\nfunction setOption(source: string, call: CallExpression, path: Array<string>, value: unknown, quote: Quote): EditResult {\n if (!isOptionValue(value)) return { reason: 'the value is not a literal that can be written to a config file' }\n\n const options = call.arguments[0]\n if (!options) {\n const closing = call.end - 1\n if (source[closing] !== ')') return { reason: 'the factory call could not be located in the file' }\n return { source: replaceText(source, closing, closing, printValue(wrapPath(path, value), quote)) }\n }\n if (options.type !== nodeTypes.objectExpression) return { reason: 'the factory was not called with an object literal' }\n return setAtPath({ source, options, path, value, quote })\n}\n\nfunction removeOption(source: string, call: CallExpression, path: Array<string>): EditResult {\n const options = call.arguments[0]\n if (!options) return { source }\n if (options.type !== nodeTypes.objectExpression) return { reason: 'the factory was not called with an object literal' }\n return removeAtPath({ source, options, path })\n}\n\nfunction editOption({\n source,\n parsed,\n config,\n edit,\n quote,\n extensions,\n}: {\n source: string\n parsed: ParsedConfig\n config: ObjectExpression\n edit: OptionEdit\n quote: Quote\n extensions: InstalledExtensions\n}): EditResult {\n const kind = edit.kind ?? extensionKinds.plugin\n // A package can ship several factories (`parserTs`, `parserTsx`), so prefer the export its manifest names.\n const calls = findCalls(parsed.program, config, kind).filter((entry) => entry.packageName === edit.plugin)\n const exportName = extensions.get(edit.plugin)?.manifest.export ?? toExportName(edit.plugin)\n const call = (calls.find((entry) => entry.exportName === exportName) ?? calls[0])?.call\n\n if (!call) {\n if (kind === extensionKinds.adapter) return { reason: `${edit.plugin} is not the config's adapter` }\n const disabled = kind === extensionKinds.plugin && findDisabled(source, parsed.comments, config).some((block) => block.packageName === edit.plugin)\n return { reason: disabled ? `${edit.plugin} is disabled, enable it first` : `${edit.plugin} is not in the ${kind}s array` }\n }\n\n if (edit.operation === ConfigEditOperation.SET_OPTION) return setOption(source, call, edit.path, edit.value, quote)\n return removeOption(source, call, edit.path)\n}\n\n// Editing the config's own fields\n\nfunction setInput(source: string, config: ObjectExpression, input: string, quote: Quote): EditResult {\n const value = printValue(input, quote)\n const found = findProperty(config, 'input')\n if (!found) return { source: appendItem(source, config, `input: ${value}`) }\n if (found.member.type !== nodeTypes.property || !isPlainProperty(found.member)) return { reason: 'input is not a plain property' }\n if (isOverridden(config, found.index)) return { reason: 'a spread after input could override it' }\n return { source: replaceText(source, found.member.value.start, found.member.value.end, value) }\n}\n\nfunction getOutput(config: ObjectExpression): { object: ObjectExpression } | { reason: string } {\n const found = findProperty(config, 'output')\n if (found?.member.type !== nodeTypes.property || found.member.value.type !== nodeTypes.objectExpression) return { reason: 'output is not an object literal' }\n if (isOverridden(config, found.index)) return { reason: 'a spread after output could override it' }\n return { object: found.member.value }\n}\n\nfunction editOutput({ source, config, edit, quote }: { source: string; config: ObjectExpression; edit: OutputEdit; quote: Quote }): EditResult {\n const output = getOutput(config)\n if ('reason' in output) return output\n if (edit.operation === ConfigEditOperation.REMOVE_OUTPUT) return removeAtPath({ source, options: output.object, path: edit.path })\n\n const [key, ...rest] = edit.path\n if (!isOptionValue(edit.value) || !isOutputValue({ key: key!, value: wrapPath(rest, edit.value) }))\n return { reason: `the value is not one output.${key} takes` }\n return setAtPath({ source, options: output.object, path: edit.path, value: edit.value, quote })\n}\n\n// Adding, disabling, and enabling plugins\n\n/** Adds the import after the last one, matching its semicolon style. */\nfunction addImport({\n source,\n parsed,\n importNames,\n moduleSpecifier,\n quote,\n}: {\n source: string\n parsed: ParsedConfig\n importNames: Array<string>\n moduleSpecifier: string\n quote: Quote\n}): string {\n const lastImport = parsed.program.body.findLast((node) => isImportStatement(node, parsed.kind))\n const afterLine = lastImport ? getPosition(source, lastImport.end).line : 0\n const lines = source.split('\\n')\n\n const semicolon = afterLine > 0 && lines[afterLine - 1]?.trimEnd().endsWith(';') ? ';' : ''\n const specifier = `${quote}${moduleSpecifier}${quote}`\n const statement =\n parsed.kind === moduleKinds.esm ? `import { ${importNames.join(', ')} } from ${specifier}` : `const { ${importNames.join(', ')} } = require(${specifier})`\n\n lines.splice(afterLine, 0, `${statement}${semicolon}`)\n if (afterLine === 0) lines.splice(1, 0, '')\n\n return lines.join('\\n')\n}\n\n/**\n * The parsers `defineConfig` applies when a config sets no `parsers`, by import name. Adding a parser\n * to such a config writes these too, or the new array would replace them.\n */\nconst DEFAULT_PARSERS = [\n { importName: 'parserTs', packageName: '@kubb/parser-ts' },\n { importName: 'parserTsx', packageName: '@kubb/parser-ts' },\n { importName: 'parserMd', packageName: '@kubb/parser-md' },\n] as const\n\n/**\n * Adds a plugin to `plugins`, or with `kind: 'parser'` a parser to `parsers`. Replaying the same add\n * is a no-op, while an import name taken by another package is an error.\n */\nfunction addPlugin({\n source,\n parsed,\n config,\n edit,\n quote,\n extensions,\n}: {\n source: string\n parsed: ParsedConfig\n config: ObjectExpression\n edit: AddPluginEdit\n quote: Quote\n extensions: InstalledExtensions\n}): EditResult {\n const kind = edit.kind ?? extensionKinds.plugin\n const isParser = kind === extensionKinds.parser\n if (!isAllowedPlugin({ packageName: edit.plugin, extensions, kind })) {\n return {\n reason: isParser ? `\"${edit.plugin}\" is not an installed Kubb parser` : `\"${edit.plugin}\" is not a @kubb/plugin-* package or an installed Kubb plugin`,\n }\n }\n\n const importName = extensions.get(edit.plugin)?.manifest.export ?? toExportName(edit.plugin)\n if (!IDENTIFIER_PATTERN.test(importName)) return { reason: `\"${importName}\" is not a valid import name` }\n // A package can ship several parsers (`parserTs` and `parserTsx`), so a parser is matched by its export too.\n if (findCalls(parsed.program, config, kind).some((entry) => entry.packageName === edit.plugin && (!isParser || entry.exportName === importName))) {\n return { source }\n }\n\n const options = edit.options ?? {}\n if (!isOptionValue(options)) return { reason: 'the options are not literals that can be written to a config file' }\n\n const key = `${kind}s`\n const array = getValue(config, key)\n if (array ? array.type !== nodeTypes.arrayExpression : !isParser) return { reason: `${key} is not an array literal` }\n // A config without `parsers` runs the defaults, so the new array lists them before the added parser.\n const defaults = isParser && !array ? DEFAULT_PARSERS.filter((parser) => parser.importName !== importName) : []\n\n // The missing imports by package, so `parserTs` and `parserTsx` share one line.\n const imports = getImports(parsed.program)\n const missing = memo.create<string, Array<string>>()\n for (const item of [...defaults, { importName, packageName: edit.plugin }]) {\n const from = imports.get(item.importName)?.from\n if (from && from !== item.packageName) return { reason: `${item.importName} is already imported from ${from}` }\n if (!from) memo(missing, item.packageName, () => []).push(item.importName)\n }\n\n // The array sits below the imports, so adding to it first leaves the import lines where they are.\n const call = `${importName}(${Object.keys(options).length ? printValue(options, quote) : ''})`\n const next =\n array?.type === nodeTypes.arrayExpression\n ? appendItem(source, array, call)\n : appendItem(source, config, `parsers: [${[...defaults.map((parser) => `${parser.importName}()`), call].join(', ')}]`)\n\n return {\n source: [...missing].reduceRight(\n (current, [moduleSpecifier, importNames]) => addImport({ source: current, parsed, importNames, moduleSpecifier, quote }),\n next,\n ),\n }\n}\n\n/** One item per line, so a call can be commented out alone. Skipped when comments sit between items. */\nfunction splitPlugins(source: string, config: ObjectExpression): string | undefined {\n const array = getValue(config, 'plugins')\n if (array?.type !== nodeTypes.arrayExpression) return undefined\n\n const items = array.elements.flatMap((element) => (element ? [element] : []))\n const { start, end } = array\n const gaps = [source.slice(start + 1, items[0]?.start ?? end - 1), ...items.map((item, index) => source.slice(item.end, items[index + 1]?.start ?? end - 1))]\n if (!items.length || gaps.some((gap) => !/^[\\s,]*$/.test(gap))) return undefined\n\n const lineStart = source.lastIndexOf('\\n', start - 1) + 1\n const indent = source.slice(lineStart).match(/^[ \\t]*/)?.[0] ?? ''\n const lines = items.map((item) => `${indent} ${source.slice(item.start, item.end)},`)\n\n return replaceText(source, start, end, `[\\n${lines.join('\\n')}\\n${indent}]`)\n}\n\nfunction disablePlugin(source: string, program: Program, config: ObjectExpression, plugin: string): EditResult {\n const call = findCalls(program, config).find((entry) => entry.packageName === plugin)?.call\n if (!call) return { reason: `${plugin} is not in the plugins array` }\n\n const start = getPosition(source, call.start)\n const end = getPosition(source, call.end)\n const lines = source.split('\\n')\n const from = start.line - 1\n const to = end.line - 1\n const firstLine = lines[from] ?? ''\n\n // Only safe when the call sits alone on its lines: anything else on its first line, or on its last\n // line besides a trailing comma, would be swallowed into the comment and corrupt the file.\n if (firstLine.slice(0, start.column).trim() || !/^,?\\s*$/.test((lines[to] ?? '').slice(end.column))) {\n return { reason: `${plugin} shares a line with other code, so it cannot be commented out safely` }\n }\n\n const indent = firstLine.match(/^\\s*/)?.[0] ?? ''\n const commented = lines.slice(from, to + 1).map((line) => (line.trim() ? `${indent}// ${line.slice(indent.length)}` : `${indent}//`))\n lines.splice(from, commented.length, `${indent}// kubb:disabled ${plugin} ${commented.length}`, ...commented)\n\n return { source: lines.join('\\n') }\n}\n\n/** Disables the plugin, first putting a one-line `plugins: [a(), b()]` (what `add-plugin` writes) on separate lines. */\nfunction disablePluginInConfig({\n source,\n parsed,\n config,\n edit,\n}: {\n source: string\n parsed: ParsedConfig\n config: ObjectExpression\n edit: DisablePluginEdit\n}): EditResult {\n const result = disablePlugin(source, parsed.program, config, edit.plugin)\n if (!('reason' in result) || !result.reason.includes('shares a line')) return result\n\n const split = splitPlugins(source, config)\n if (split === undefined) return result\n\n const reparsed = findConfigs(split)\n const reparsedConfig = 'reason' in reparsed ? undefined : findConfigEntry(reparsed.configs, edit.config)\n if ('reason' in reparsed || !reparsedConfig) return result\n\n return disablePlugin(split, reparsed.program, reparsedConfig, edit.plugin)\n}\n\nfunction enablePlugin(source: string, comments: Array<Comment>, config: ObjectExpression, plugin: string): EditResult {\n const block = findDisabled(source, comments, config).find((entry) => entry.packageName === plugin)\n if (!block) return { reason: `${plugin} is not disabled` }\n\n const lines = source.split('\\n')\n lines.splice(block.line - 1, block.end - block.line + 1, ...block.code)\n return { source: lines.join('\\n') }\n}\n\n// Removing extensions\n\n/** Drops the import statements of `packageName` once nothing else in the file uses their names. */\nfunction removeUnusedImports(source: string, packageName: string): string {\n const parsed = parseSource(source)\n if ('reason' in parsed) return source\n\n // From the last statement up, so the offsets of the earlier ones stay valid.\n return parsed.program.body.reduceRight((current, statement) => {\n const bindings =\n statement.type === nodeTypes.importDeclaration\n ? importBindings(statement)\n : statement.type === nodeTypes.variableDeclaration\n ? requireBindings(statement)\n : []\n if (!bindings.length || bindings.some(([, { from }]) => from !== packageName)) return current\n\n const rest = replaceText(current, statement.start, statement.end)\n if (bindings.some(([local]) => new RegExp(`(?<![\\\\w$])${local.replaceAll('$', '\\\\$')}(?![\\\\w$])`).test(rest))) return current\n\n const lineStart = current.lastIndexOf('\\n', statement.start - 1) + 1\n const lineEnd = current.indexOf('\\n', statement.end)\n const after = lineEnd === -1 ? current.length : lineEnd + 1\n // At the top of the file, the blank line after the import goes too, so the file does not start with one.\n return replaceText(current, lineStart, lineStart === 0 && current[after] === '\\n' ? after + 1 : after)\n }, source)\n}\n\n/**\n * Removes every call of a plugin or parser package, and the block `disable-plugin` commented out,\n * then its unused imports. Removing what the config does not hold is a no-op. Refuses to empty\n * `parsers`, since a config with no parser cannot print files.\n */\nfunction removeExtension(source: string, edit: RemoveExtensionEdit): EditResult {\n const kind = edit.kind ?? extensionKinds.plugin\n let current = source\n\n // One call at a time, re-parsing in between, since each removal moves the ones after it.\n for (;;) {\n const parsed = findConfigs(current)\n if ('reason' in parsed) return parsed\n const config = findConfigEntry(parsed.configs, edit.config)\n if (!config) return { reason: `no config entry found for ${JSON.stringify(edit.config)}` }\n\n const array = getValue(config, `${kind}s`)\n const calls = findCalls(parsed.program, config, kind).filter((entry) => entry.packageName === edit.plugin)\n const block = findDisabled(current, parsed.comments, config).find((entry) => entry.packageName === edit.plugin)\n\n if (calls[0] && array?.type === nodeTypes.arrayExpression) {\n const elements = array.elements.filter((element) => element !== null)\n if (kind === extensionKinds.parser && elements.length === calls.length) return { reason: `${edit.plugin} is the last parser in the parsers array` }\n current = removeItem(current, array, elements.indexOf(calls[0].call))\n continue\n }\n if (block && kind === extensionKinds.plugin) {\n const lines = current.split('\\n')\n lines.splice(block.line - 1, block.end - block.line + 1)\n current = lines.join('\\n')\n continue\n }\n return { source: current === source ? source : removeUnusedImports(current, edit.plugin) }\n }\n}\n\n// Applying edits\n\n/** Every edit re-parses the file, since the previous one rewrote it. */\nfunction applyEdit({ source, edit, extensions }: { source: string; edit: ConfigEdit; extensions: InstalledExtensions }): EditResult {\n const parsed = findConfigs(source)\n if ('reason' in parsed) return parsed\n\n const config = findConfigEntry(parsed.configs, edit.config)\n if (!config) return { reason: `no config entry found for ${JSON.stringify(edit.config)}` }\n const quote = detectQuote(parsed.program) ?? quotes.single\n\n switch (edit.operation) {\n case ConfigEditOperation.SET_INPUT:\n return setInput(source, config, edit.input, quote)\n case ConfigEditOperation.SET_OUTPUT:\n case ConfigEditOperation.REMOVE_OUTPUT:\n return editOutput({ source, config, edit, quote })\n case ConfigEditOperation.DISABLE_PLUGIN:\n return disablePluginInConfig({ source, parsed, config, edit })\n case ConfigEditOperation.ENABLE_PLUGIN:\n return enablePlugin(source, parsed.comments, config, edit.plugin)\n case ConfigEditOperation.ADD_PLUGIN:\n return addPlugin({ source, parsed, config, edit, quote, extensions })\n case ConfigEditOperation.REMOVE_EXTENSION:\n return removeExtension(source, edit)\n case ConfigEditOperation.SET_OPTION:\n case ConfigEditOperation.REMOVE_OPTION:\n return editOption({ source, parsed, config, edit, quote, extensions })\n }\n}\n\n/** Applies edits in place, touching only the text each targets. A refused edit is reported and the rest still run. */\nexport function editConfig({ source, edits, extensions = new Map() }: { source: string; edits: Array<ConfigEdit>; extensions?: InstalledExtensions }): {\n source: string\n outcomes: Array<ConfigEditOutcome>\n changed: boolean\n} {\n let current = source\n\n const outcomes = edits.map((edit): ConfigEditOutcome => {\n try {\n const invalid = validateEdit(edit)\n if (invalid) return { edit, applied: false, reason: invalid }\n\n const result = applyEdit({ source: current, edit, extensions })\n if ('reason' in result) return { edit, applied: false, reason: result.reason }\n current = result.source\n return { edit, applied: true }\n } catch (error) {\n return { edit, applied: false, reason: getErrorMessage(error) }\n }\n })\n\n return { source: current, outcomes, changed: current !== source }\n}\n\n/** Applies `edits` to `filePath`, writing only when something changed. */\nexport async function editConfigFile({ filePath, edits, extensions }: { filePath: string; edits: Array<ConfigEdit>; extensions?: InstalledExtensions }) {\n const current = await read(filePath)\n const result = editConfig({ source: current, edits, extensions })\n if (result.changed) await writeRaw(filePath, result.source)\n return result\n}\n","import { structuredPatch, type StructuredPatchHunk } from 'diff'\nimport type { DiffHunk, DiffStats } from './protocol.ts'\n\nconst CONTEXT_LINES = 3\n// Past this, each remaining segment shows as one replace block.\nconst DIFF_TIMEOUT_MS = 1_000\n\n// Lines keep their `\\n`, so a last line without one differs from the same line with one.\nconst splitLines = (text: string) => (text === '' ? [] : text.split(/(?<=\\n)/))\n\n// Longest increasing subsequence of `values`, as indexes into it.\nfunction longestIncreasing(values: Array<number>): Array<number> {\n const tails: Array<number> = []\n const prev: Array<number> = []\n for (const [index, value] of values.entries()) {\n let low = 0\n let high = tails.length\n while (low < high) {\n const mid = (low + high) >> 1\n if (values[tails[mid]!]! < value) low = mid + 1\n else high = mid\n }\n prev[index] = low > 0 ? tails[low - 1]! : -1\n tails[low] = index\n }\n const result: Array<number> = []\n for (let index = tails.at(-1) ?? -1; index !== -1; index = prev[index]!) result.push(index)\n return result.reverse()\n}\n\n// Where to cut both files so each segment diffs on its own: inside each unchanged stretch that keeps a full\n// context on both sides, so no hunk crosses a cut. Lines that occur once in each file, in the same order, find them.\nfunction cutPoints(before: Array<string>, after: Array<string>): Array<[number, number]> {\n const counts = new Map<string, { before: number; after: number; index: number }>()\n for (const [index, line] of before.entries()) {\n const count = counts.get(line)\n if (count) count.before++\n else counts.set(line, { before: 1, after: 0, index })\n }\n const afterIndex = new Map<string, number>()\n for (const [index, line] of after.entries()) {\n const count = counts.get(line)\n if (!count) continue\n count.after++\n afterIndex.set(line, index)\n }\n // Map order is insertion order, so these are sorted by their index in `before`.\n const unique = [...counts]\n .filter(([, count]) => count.before === 1 && count.after === 1)\n .map(([line, count]) => [count.index, afterIndex.get(line)!] as const)\n const anchors = longestIncreasing(unique.map(([, index]) => index)).map((index) => unique[index]!)\n\n const cuts: Array<[number, number]> = [[0, 0]]\n let run = { before: 0, after: 0, length: 0 }\n const closeRun = () => {\n if (run.length > 2 * CONTEXT_LINES) cuts.push([run.before + CONTEXT_LINES, run.after + CONTEXT_LINES])\n }\n let i = 0\n let j = 0\n for (const [anchorBefore, anchorAfter] of anchors) {\n // The lines between two anchors are unchanged when both sides hold the same lines.\n const unchanged = anchorBefore - i === anchorAfter - j && before.slice(i, anchorBefore).every((line, offset) => line === after[j + offset])\n if (unchanged && run.length && run.before + run.length === i) {\n run.length += anchorBefore - i + 1\n } else {\n closeRun()\n run = unchanged ? { before: i, after: j, length: anchorBefore - i + 1 } : { before: anchorBefore, after: anchorAfter, length: 1 }\n }\n i = anchorBefore + 1\n j = anchorAfter + 1\n }\n closeRun()\n cuts.push([before.length, after.length])\n return cuts\n}\n\n// A segment with no time left to diff shows as one block that replaces everything between its shared first and last lines.\nfunction replaceHunk(before: Array<string>, after: Array<string>): Array<StructuredPatchHunk> {\n let start = 0\n while (start < before.length && start < after.length && before[start] === after[start]) start++\n let end = 0\n while (end < before.length - start && end < after.length - start && before[before.length - 1 - end] === after[after.length - 1 - end]) end++\n const removed = before.slice(start, before.length - end)\n const added = after.slice(start, after.length - end)\n if (!removed.length && !added.length) return []\n\n const lines = (prefix: string, rows: Array<string>) =>\n rows.flatMap((row) => (row.endsWith('\\n') ? [`${prefix}${row.slice(0, -1)}`] : [`${prefix}${row}`, '\\\']))\n // Same numbering as `structuredPatch`, which starts an empty side at line 1 too.\n return [{ oldStart: start + 1, oldLines: removed.length, newStart: start + 1, newLines: added.length, lines: [...lines('-', removed), ...lines('+', added)] }]\n}\n\n// One Myers diff over a whole file grows with lines times changes and stalls on large specs, so each segment\n// between cuts is diffed on its own.\nexport function diffHunks(before: string, after: string, timeout = DIFF_TIMEOUT_MS): { hunks: Array<StructuredPatchHunk>; stats: DiffStats } {\n const beforeLines = splitLines(before)\n const afterLines = splitLines(after)\n const cuts = cutPoints(beforeLines, afterLines)\n const deadline = Date.now() + timeout\n\n const hunks: Array<StructuredPatchHunk> = []\n let coarse = false\n for (const [index, [beforeStart, afterStart]] of cuts.slice(0, -1).entries()) {\n const [beforeEnd, afterEnd] = cuts[index + 1]!\n const segmentBefore = beforeLines.slice(beforeStart, beforeEnd)\n const segmentAfter = afterLines.slice(afterStart, afterEnd)\n const patch = structuredPatch('', '', segmentBefore.join(''), segmentAfter.join(''), undefined, undefined, {\n context: CONTEXT_LINES,\n timeout: Math.max(0, deadline - Date.now()),\n })\n if (!patch) coarse = true\n for (const hunk of patch?.hunks ?? replaceHunk(segmentBefore, segmentAfter)) {\n hunks.push({ ...hunk, oldStart: hunk.oldStart + beforeStart, newStart: hunk.newStart + afterStart })\n }\n }\n\n const lines = hunks.flatMap((hunk) => hunk.lines)\n const stats: DiffStats = {\n additions: lines.filter((line) => line[0] === '+').length,\n deletions: lines.filter((line) => line[0] === '-').length,\n hunks: hunks.length,\n lines: lines.length,\n coarse,\n }\n return { hunks, stats }\n}\n\n// Pages hold whole hunks, so a hunk is cut only when it alone is longer than a page. Its parts share its `index`.\nexport function pageHunks({ hunks, cursor, limit }: { hunks: Array<StructuredPatchHunk>; cursor: number; limit: number }): {\n hunks: Array<DiffHunk>\n nextCursor: number | null\n} {\n const page: Array<DiffHunk> = []\n let used = 0\n let start = 0\n for (const [index, hunk] of hunks.entries()) {\n const offset = Math.max(0, cursor - start)\n start += hunk.lines.length\n const remaining = hunk.lines.length - offset\n if (remaining <= 0) continue\n if (used > 0 && remaining > limit - used) break\n let take = Math.min(remaining, limit - used)\n // A `\\ No newline` marker stays with its line, so no part starts with one.\n if (hunk.lines[offset + take]?.startsWith('\\\\')) take++\n page.push({ index, ...hunk, lines: hunk.lines.slice(offset, offset + take) })\n used += take\n if (used >= limit) break\n }\n const total = hunks.reduce((sum, hunk) => sum + hunk.lines.length, 0)\n return { hunks: page, nextCursor: cursor + used < total ? cursor + used : null }\n}\n","import { createHash, randomUUID } from 'node:crypto'\nimport { isAbsolute, relative, resolve, sep } from 'node:path'\nimport process from 'node:process'\nimport { inParallel } from '@internals/utils'\nimport { ast, type InputNode } from '@kubb/ast'\nimport { type Config, createKubb, type Diagnostic, Diagnostics, fsStorage, type Hookable, type KubbHooks, type Storage } from '@kubb/core'\nimport { type FilePage, type ReadFilesResult } from './protocol.ts'\n\nconst READ_CONCURRENCY = 50\nconst MB = 1024 * 1024\nconst INDEX_KEY = 'studio/generations.json'\n\n/**\n * Files a run produced, or the output directory held, keyed by path relative to `root`.\n */\nexport type SourceFiles = { storage: Storage; root: string; paths: Set<string> }\n\n/**\n * The path form {@link SourceFiles} keys on: relative to `root`, with forward slashes.\n */\nexport function relativeStoragePath({ root, filePath }: { root: string; filePath: string }): string {\n return (isAbsolute(filePath) ? relative(resolve(root), filePath) : filePath).replaceAll('\\\\', '/')\n}\n\n/**\n * A set as kept in the store.\n */\ntype KeptSet = {\n /**\n * The paths a read is checked against. Empty when the set was too large to keep its content.\n */\n paths: Array<string>\n hashes: Record<string, string>\n bytes: number\n}\n\ntype KeptGeneration = {\n jobId: string\n initial?: boolean\n /** When the store took it, in epoch milliseconds. Absent on an index written before it existed. */\n keptAt?: number\n output: KeptSet\n inputBytes?: number\n}\n\n/**\n * The content fingerprint Studio compares snapshots by. Agent runs and CI uploads must agree on it.\n */\nexport const hashOf = (content: string) => createHash('sha1').update(content).digest('hex').slice(0, 16)\n\n/**\n * The bytes `entries` keep on disk: output, written files, and kept input.\n */\nconst totalBytes = (entries: Array<KeptGeneration>) => entries.reduce((sum, { output, inputBytes }) => sum + output.bytes + (inputBytes ?? 0), 0)\n\nfunction positiveNumber(value: string | undefined): number | undefined {\n const parsed = Number(value)\n return value && Number.isFinite(parsed) && parsed > 0 ? parsed : undefined\n}\n\n/**\n * How many generations an agent keeps and how large they may get, read from\n * `KUBB_AGENT_MAX_GENERATIONS` and `KUBB_AGENT_MAX_GENERATIONS_MB`.\n * An unset or invalid value keeps the default.\n */\nexport function resolveGenerationLimits(): { maxCount: number; maxMb: number } {\n return {\n maxCount: Math.max(1, Math.floor(positiveNumber(process.env.KUBB_AGENT_MAX_GENERATIONS) ?? 8)),\n maxMb: positiveNumber(process.env.KUBB_AGENT_MAX_GENERATIONS_MB) ?? 100,\n }\n}\n\n/**\n * Folds error-severity diagnostics into one thrown error so logs name the failing plugin or pass.\n */\nexport function generationFailure(diagnostics: ReadonlyArray<Diagnostic>): Error {\n const reasons = diagnostics\n .filter(Diagnostics.isProblem)\n .filter((diagnostic) => diagnostic.severity === 'error')\n .map((diagnostic) => (diagnostic.plugin ? `${diagnostic.plugin}: ${diagnostic.message}` : diagnostic.message))\n\n if (!reasons.length) return new Error('Generation failed')\n\n return new Error(`Generation failed: ${reasons.length} error${reasons.length === 1 ? '' : 's'}: ${reasons.join('; ')}`)\n}\n\n/**\n * Runs one generation and returns the files it produced. The formatter, the linter, and\n * `output.postGenerate` only run with `allowExec`. Throws when any plugin reports an error.\n */\nexport async function generate({\n config,\n hooks,\n signal,\n allowExec,\n fileRefs,\n}: {\n config: Config\n hooks?: Hookable<KubbHooks>\n signal?: AbortSignal\n allowExec: boolean\n fileRefs?: Array<string>\n}): Promise<SourceFiles & { input: InputNode | null }> {\n const output = allowExec ? config.output : { ...config.output, format: false as const, lint: false as const, postGenerate: [] }\n const kubb = createKubb({ ...config, output }, { hooks, signal, fileRefs })\n const result = await kubb.generate()\n if (!result.success) throw generationFailure(result.diagnostics)\n\n // `kubb.config` carries the defaults, such as the fs storage a config loaded by the CLI leaves unset.\n const { storage, root } = kubb.config\n return {\n storage,\n root,\n paths: new Set(result.files.map((file) => relativeStoragePath({ root, filePath: file.path }))),\n input: result.input,\n }\n}\n\n/**\n * What the output directory holds when the editor connects. `undefined` when `outputPath` is not a real\n * subdirectory of `root` (listing the root would take in every source file) or holds more than `maxFiles`.\n */\nexport async function listDisk({ root, outputPath, maxFiles }: { root: string; outputPath: string; maxFiles: number }): Promise<SourceFiles | undefined> {\n const outputDir = resolve(root, outputPath)\n const fromRoot = relative(resolve(root), outputDir)\n if (!fromRoot || fromRoot.startsWith('..') || fromRoot.startsWith(sep)) return undefined\n\n const storage = fsStorage()\n const keys = await storage.readKeys(outputDir)\n if (keys.length > maxFiles) return undefined\n\n const paths = keys\n .filter((key) => !key.split('/').includes('node_modules'))\n .map((key) => relative(resolve(root), resolve(outputDir, key)).replaceAll('\\\\', '/'))\n return { storage, root, paths: new Set(paths) }\n}\n\n/**\n * Keeps recent generations by job id in `storage`, with an index next to them so a store on disk\n * survives a restart. A generation is only ever looked up by its job id, so on a pooled sandbox one\n * tenant never reaches another's output. Initial disk output and generated jobs each get their\n * own `maxCount` and `maxMb` budget. Each budget always keeps its newest entry.\n */\nexport function createGenerationStore({\n storage,\n maxCount,\n maxMb,\n ttlMs,\n now = Date.now,\n}: {\n storage: Storage\n maxCount: number\n maxMb: number\n /** How long a generation stays readable. Unset, it stays until count or size pushes it out. */\n ttlMs?: number\n now?: () => number\n}) {\n let index: Array<KeptGeneration> | undefined\n\n // An entry from before `keptAt` existed never expires, so upgrading drops nothing.\n const isLive = (generation: KeptGeneration) => ttlMs === undefined || generation.keptAt === undefined || now() - generation.keptAt < ttlMs\n\n // Hashed so a job id from the wire can never point outside the store.\n const dirOf = (jobId: string) => `studio/generations/${hashOf(jobId)}/`\n\n async function load(): Promise<Array<KeptGeneration>> {\n if (index) return index\n const stored = await storage.readItem(INDEX_KEY).catch(() => null)\n try {\n index = stored ? (JSON.parse(stored) as Array<KeptGeneration>) : []\n } catch {\n index = []\n }\n return index\n }\n\n /**\n * Copies `files` into the store as one set of `jobId`. Above `maxSetMb` only the hashes are kept.\n */\n async function keep({ jobId, files, maxSetMb }: { jobId: string; files: SourceFiles; maxSetMb: number }): Promise<KeptSet> {\n const maxSetBytes = maxSetMb * MB\n const hashes: Record<string, string> = {}\n let bytes = 0\n await inParallel({\n items: [...files.paths],\n limit: READ_CONCURRENCY,\n run: async (path) => {\n // Output outside the root would land outside the store too.\n if (path.split('/').includes('..')) return\n const content = await files.storage.readItem(resolve(files.root, path))\n if (content === null) return\n hashes[path] = hashOf(content)\n bytes += Buffer.byteLength(content)\n if (bytes <= maxSetBytes) await storage.writeItem(`${dirOf(jobId)}output/${path}`, content)\n },\n })\n if (bytes > maxSetBytes) {\n await storage.empty(`${dirOf(jobId)}output/`)\n return { paths: [], hashes, bytes: 0 }\n }\n return { paths: Object.keys(hashes), hashes, bytes }\n }\n\n async function drop(jobId: string): Promise<void> {\n await storage.empty(dirOf(jobId))\n }\n\n async function add(generation: KeptGeneration): Promise<void> {\n const current = await load()\n for (const expired of current.filter((entry) => !isLive(entry))) await drop(expired.jobId)\n const live = current.filter((entry) => entry.jobId !== generation.jobId && isLive(entry))\n const sharesBudget = (entry: KeptGeneration) => Boolean(entry.initial) === Boolean(generation.initial)\n const entries = live.filter(sharesBudget)\n entries.push({ ...generation, keptAt: now() })\n while (entries.length > 1 && (entries.length > maxCount || totalBytes(entries) > maxMb * MB)) {\n await drop(entries.shift()!.jobId)\n }\n index = [...live.filter((entry) => !sharesBudget(entry)), ...entries]\n await storage.writeItem(INDEX_KEY, JSON.stringify(index))\n }\n\n return {\n keep,\n drop,\n /**\n * Captures initial disk output, reusing a retained ID when its hashes and readable paths match.\n * A temporary candidate is discarded on reuse, so reconnects do not consume retention slots.\n */\n async keepInitial(files: SourceFiles): Promise<KeptGeneration> {\n const jobId = randomUUID()\n const output = await keep({ jobId, files, maxSetMb: maxMb })\n const hashes = Object.entries(output.hashes)\n const previous = (await load()).findLast(\n (entry) =>\n entry.initial &&\n isLive(entry) &&\n entry.output.paths.length === output.paths.length &&\n Object.keys(entry.output.hashes).length === hashes.length &&\n hashes.every(([path, hash]) => entry.output.hashes[path] === hash),\n )\n if (previous) {\n await drop(jobId)\n await add(previous)\n return previous\n }\n const generation = { jobId, output, initial: true }\n await add(generation)\n return generation\n },\n /**\n * Keeps the `InputNode` of `jobId` and returns its size in bytes, or 0 when it keeps none. A ref schema loses\n * the copy of its target, which `input.schemas` holds: with it, a large spec outgrows what `JSON.stringify` can return.\n */\n async keepInput({ jobId, input, maxSetMb }: { jobId: string; input: InputNode | null; maxSetMb: number }): Promise<number> {\n if (!input) return 0\n let json: string\n try {\n json = JSON.stringify(\n ast.node.transform(input, { schema: (node) => (node.type === 'ref' && node.schema ? { ...node, schema: undefined } : undefined) }),\n )\n } catch {\n // An adapter can return what JSON cannot hold, which must not fail a finished generation.\n return 0\n }\n const bytes = Buffer.byteLength(json)\n if (bytes > maxSetMb * MB) return 0\n await storage.writeItem(`${dirOf(jobId)}input.json`, json)\n return bytes\n },\n /**\n * The input `keepInput` kept for `jobId`, or `undefined` when there is none.\n */\n async readInput(jobId: string): Promise<InputNode | undefined> {\n const stored = await storage.readItem(`${dirOf(jobId)}input.json`)\n return stored === null ? undefined : (JSON.parse(stored) as InputNode)\n },\n get: async (jobId: string) => (await load()).find((generation) => generation.jobId === jobId && isLive(generation)),\n add,\n /**\n * Reads the requested paths the set holds, skipping any it does not, one page of lines when `limit` is given.\n */\n async read({\n generation,\n paths,\n cursor = 0,\n limit,\n }: {\n generation: KeptGeneration\n paths: Array<string>\n cursor?: number\n limit?: number\n }): Promise<ReadFilesResult> {\n const kept = new Set(generation.output.paths)\n const files: Record<string, string> = {}\n const pages: Record<string, FilePage> = {}\n await inParallel({\n items: paths.filter((path) => kept.has(path)),\n limit: READ_CONCURRENCY,\n run: async (path) => {\n const content = await storage.readItem(`${dirOf(generation.jobId)}output/${path}`)\n if (content === null) return\n if (limit === undefined) {\n files[path] = content\n return\n }\n const lines = content.split(/\\r\\n|\\r|\\n/)\n const end = Math.min(cursor + limit, lines.length)\n files[path] = lines.slice(cursor, end).join('\\n')\n pages[path] = { nextCursor: end < lines.length ? end : null, totalLines: lines.length }\n },\n })\n return limit === undefined ? { files } : { files, pages }\n },\n }\n}\n\nexport type GenerationStore = ReturnType<typeof createGenerationStore>\n","import { stripVTControlCharacters } from 'node:util'\nimport type { Hookable, KubbHooks } from '@kubb/core'\nimport { type GenerationEvent, type GenerationEventPayloads, type GenerationEventType, generationEventTypes } from './protocol.ts'\nimport { relativeStoragePath } from './generations.ts'\n\n/** How each published hook's context becomes its wire payload; a hook without a projection fails to compile. */\ntype Projections = { [Type in GenerationEventType]: (...args: KubbHooks[Type]) => GenerationEventPayloads[Type] }\n\nconst MAX_QUEUED_EVENTS = 1_024\nconst RESERVED_EVENTS = 64\nconst isDiscardable = (type: GenerationEventType) => type === 'kubb:files:processing:update' || type === 'kubb:info' || type === 'kubb:success'\n\n/** Forwards selected Kubb lifecycle events to a native Cap'n Web stream. */\nexport function createGenerationStream(\n hooks: Hookable<KubbHooks>,\n jobId: string,\n): { stream: ReadableStream<GenerationEvent>; close: () => Promise<void>; fail: (error?: unknown) => void } {\n const unhooks: Array<() => void> = []\n let root = ''\n let controller!: ReadableStreamDefaultController<GenerationEvent>\n let closed = false\n const stream = new ReadableStream<GenerationEvent>(\n {\n start: (value) => {\n controller = value\n },\n cancel: () => {\n closed = true\n detach()\n },\n },\n { highWaterMark: MAX_QUEUED_EVENTS },\n )\n\n /**\n * Registers a listener and keeps its remover, so one generation's listeners come off the session\n * emitter again when that generation ends.\n */\n function on<TName extends keyof KubbHooks & string>(name: TName, handler: (...args: KubbHooks[TName]) => unknown): void {\n unhooks.push(hooks.hook(name, handler))\n }\n\n function emitEvent<Type extends GenerationEventType>(type: Type, data: GenerationEventPayloads[Type]): void {\n if (closed) return\n const event = { jobId, type, data, version: 1 as const, timestamp: Date.now() } as unknown as GenerationEvent\n if (controller.desiredSize! <= RESERVED_EVENTS && isDiscardable(type)) return\n if (controller.desiredSize! <= 0) {\n fail(new Error(`Generation event stream exceeded ${MAX_QUEUED_EVENTS} queued events`))\n return\n }\n controller.enqueue(event)\n }\n\n const projections: Projections = {\n 'kubb:plugin:start': ({ plugin }) => [{ plugin: { name: plugin.name } }],\n 'kubb:plugin:end': ({ plugin, duration, success }) => [{ plugin: { name: plugin.name }, duration, success }],\n 'kubb:build:start': ({ config, adapter }) => [{ config: { name: config.name }, adapter: { name: adapter.name } }],\n 'kubb:build:end': ({ files, config, outputDir }) => [\n { files: files.map((file) => ({ path: relativeStoragePath({ root: config.root, filePath: file.path }), name: file.name })), outputDir },\n ],\n 'kubb:files:processing:start': ({ files }) => [{ total: files.length }],\n 'kubb:files:processing:update': ({ files }) => [\n {\n files: files.map(({ file, processed, total, percentage }) => ({\n file: relativeStoragePath({ root, filePath: file.path }),\n processed,\n total,\n percentage,\n })),\n },\n ],\n 'kubb:files:processing:end': ({ files }) => [{ total: files.length }],\n 'kubb:info': ({ message, info }) => [{ message: stripVTControlCharacters(message), info }],\n 'kubb:success': ({ message, info }) => [{ message: stripVTControlCharacters(message), info }],\n 'kubb:warn': ({ message, info }) => [{ message: stripVTControlCharacters(message), info }],\n 'kubb:error': ({ error }) => [{ message: error.message, stack: error.stack }],\n 'kubb:diagnostic': ({ diagnostic }) => [\n {\n code: diagnostic.code,\n message: diagnostic.message,\n severity: diagnostic.severity,\n location: 'location' in diagnostic ? diagnostic.location : undefined,\n help: 'help' in diagnostic ? diagnostic.help : undefined,\n plugin: 'plugin' in diagnostic ? diagnostic.plugin : undefined,\n stack: 'cause' in diagnostic ? diagnostic.cause?.stack : undefined,\n },\n ],\n 'kubb:generation:start': ({ config }) => [{ name: config.name, plugins: config.plugins.length }],\n 'kubb:generation:end': () => [],\n 'kubb:generation:summary': ({ duration, fileCount, failedPlugins, status }) => [{ duration, fileCount, failedPlugins, status }],\n 'kubb:lifecycle:start': () => [],\n 'kubb:lifecycle:end': () => [],\n 'kubb:format:start': () => [],\n 'kubb:format:end': () => [],\n 'kubb:lint:start': () => [],\n 'kubb:lint:end': () => [],\n 'kubb:hooks:start': () => [],\n 'kubb:hooks:end': () => [],\n 'kubb:hook:start': ({ id, command, args }) => [{ id, command, args: args ? [...args] : undefined }],\n 'kubb:hook:line': ({ id, line }) => [{ id, line }],\n 'kubb:hook:end': ({ id, command, args, success, error }) => [\n { id, command, args: args ? [...args] : undefined, success, error: error ? { message: error.message, stack: error.stack } : undefined },\n ],\n }\n\n function forward<Type extends GenerationEventType>(type: Type): void {\n on(type, (...args: KubbHooks[Type]) => {\n emitEvent(type, projections[type](...args))\n // Generators render in memory without awaiting I/O, so the socket only sends once the event loop gets a turn.\n if (!isDiscardable(type)) return new Promise<void>((resolve) => setImmediate(resolve))\n })\n }\n\n // Paths in `kubb:files:processing:update` are made relative to the root the build announced.\n on('kubb:build:start', ({ config }) => {\n root = config.root\n })\n\n for (const type of generationEventTypes) forward(type)\n\n /**\n * Takes this generation's listeners off the session emitter. Safe to call twice.\n */\n function detach(): void {\n for (const unhook of unhooks) unhook()\n unhooks.length = 0\n }\n\n async function close(): Promise<void> {\n if (closed) {\n return\n }\n closed = true\n detach()\n controller.close()\n }\n\n function fail(error?: unknown): void {\n detach()\n if (closed) {\n return\n }\n closed = true\n controller.error(error)\n }\n\n return { stream, close, fail }\n}\n","import dns from 'node:dns'\nimport http from 'node:http'\nimport https from 'node:https'\nimport net from 'node:net'\nimport { Readable, Transform } from 'node:stream'\nimport { isPublicAddress } from '@kubb/core'\n\nconst MAX_REDIRECTS = 5\nconst MAX_BYTES = 50 * 1024 * 1024\nconst REDIRECTS = new Set([301, 302, 303, 307, 308])\nconst NO_BODY = new Set([204, 205, 304])\n\nfunction notPublic(host: string): Error {\n return new Error(`${host} is not a public address, so this agent does not fetch from it`)\n}\n\nfunction createLookup(blocked?: net.BlockList): net.LookupFunction {\n return (hostname, options, callback) => {\n dns.lookup(hostname, { ...options, all: true }, (error, addresses) => {\n if (error) return callback(error, '', 0)\n const found = addresses as Array<dns.LookupAddress>\n // One private answer is enough to refuse, so a name cannot mix a public and a private record.\n if (!found.length || found.some(({ address }) => !isPublicAddress(address, blocked))) return callback(notPublic(hostname), '', 0)\n return options.all ? callback(null, found) : callback(null, found[0]!.address, found[0]!.family)\n })\n }\n}\n\nfunction request({ url, blocked, signal }: { url: URL; blocked?: net.BlockList; signal?: AbortSignal | null }): Promise<Response> {\n if (url.protocol !== 'http:' && url.protocol !== 'https:') return Promise.reject(new Error(`Only http and https URLs are fetched, not ${url.protocol}`))\n // An IP literal skips the lookup below, so it is checked here.\n const host = url.hostname.replace(/^\\[|\\]$/g, '')\n if (net.isIP(host) && !isPublicAddress(host, blocked)) return Promise.reject(notPublic(host))\n\n return new Promise((resolve, reject) => {\n const send = url.protocol === 'https:' ? https.request : http.request\n // `lookup` runs for the connection itself, so a name that changes its answer after a check cannot reach a blocked address.\n const req = send(url, { method: 'GET', lookup: createLookup(blocked), signal: signal ?? undefined, headers: { 'accept-encoding': 'identity' } }, (res) => {\n const headers = new Headers()\n for (const [key, value] of Object.entries(res.headers)) {\n for (const item of [value].flat()) if (item !== undefined) headers.append(key, item)\n }\n let total = 0\n const limit = new Transform({\n transform(chunk: Buffer, _encoding, done) {\n total += chunk.length\n done(total > MAX_BYTES ? new Error('The response is larger than 50 MB') : null, chunk)\n },\n })\n res.on('error', (error) => limit.destroy(error))\n res.pipe(limit)\n const body = NO_BODY.has(res.statusCode ?? 0) ? null : (Readable.toWeb(limit) as unknown as ReadableStream)\n resolve(new Response(body, { status: res.statusCode, statusText: res.statusMessage, headers }))\n })\n req.on('error', reject)\n req.end()\n })\n}\n\n/**\n * Builds a `fetch` that only reaches addresses `blocked` does not list. It follows redirects itself\n * and checks every hop, and takes GET requests only, since that is all a spec load needs.\n */\nexport function createPublicFetch(blocked?: net.BlockList): typeof fetch {\n const publicFetch = async (input: Parameters<typeof fetch>[0], init?: RequestInit): Promise<Response> => {\n if (typeof input !== 'string' && !(input instanceof URL)) throw new TypeError('This agent fetches by URL only')\n if (init?.method && init.method.toUpperCase() !== 'GET') throw new TypeError('This agent only sends GET requests')\n\n let url = new URL(input)\n for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {\n const response = await request({ url, blocked, signal: init?.signal })\n const location = response.headers.get('location')\n if (!REDIRECTS.has(response.status) || !location) return response\n await response.body?.cancel()\n url = new URL(location, url)\n }\n throw new Error(`Stopped after ${MAX_REDIRECTS} redirects from ${String(input)}`)\n }\n return publicFetch as typeof fetch\n}\n\n/**\n * Runs `run` with the global `fetch` limited to public addresses, then puts the original back.\n * A sandbox or managed agent runs one job at a time, so nothing else shares the window.\n */\nexport async function withPublicFetch<T>(run: () => Promise<T>): Promise<T> {\n const original = globalThis.fetch\n globalThis.fetch = createPublicFetch()\n try {\n return await run()\n } finally {\n globalThis.fetch = original\n }\n}\n","import { existsSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport path from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { type Adapter, type Config, Diagnostics, type ExtensionKind, getInputKind, type Parser, type Plugin, resolveMeta } from '@kubb/core'\nimport { isAllowedPlugin, isOptionValue, isOutputKey, isOutputValue, isPlainObject, isSafeKey, toExportName, toPluginName } from '@internals/shared'\nimport { isPathInside, toError } from '@internals/utils'\nimport type { AgentType, InstalledExtensions, JSONKubbConfig } from './protocol.ts'\n\n/**\n * Turns the JSON config Studio sends back into live Kubb objects.\n *\n * A plugin or adapter instance carries closures (`parse`, `getImports`, ...) that cannot survive\n * JSON, so both sides pass options over the wire and the factory is re-invoked here with the merged\n * result. Only packages {@link isAllowedPlugin} accepts are resolved this way, never an arbitrary\n * module the payload names.\n */\n\n/**\n * Imports a package, falling back to how the user's project would resolve it.\n *\n * `import()` resolves from this file, so a linked or globally installed Studio (`pnpm link`,\n * `npm i -g`) only sees its own `node_modules` and misses the plugins installed next to the user's\n * config. The retry resolves from `process.cwd()` instead.\n */\nasync function importFromProject(packageName: string): Promise<Record<string, unknown>> {\n try {\n return await import(packageName)\n } catch {\n const requireModule = createRequire(pathToFileURL(`${process.cwd()}/`))\n // `requireModule.resolve` picks the package's `require` condition, so prefer the ESM build sitting\n // next to it. Loading the CJS copy would pull in a second `@kubb/core` instance.\n const resolved = requireModule.resolve(packageName)\n const esm = resolved.replace(/\\.cjs$/, '.js')\n\n return await import(pathToFileURL(esm !== resolved && existsSync(esm) ? esm : resolved).href)\n }\n}\n\n/**\n * Adds the `@kubb/` scope a plugin's package carries but its `name` does not, the inverse of\n * {@link toPluginName}. A name outside the `plugin-` convention is left alone, so a third-party\n * plugin is not reported as one of Kubb's.\n *\n * @example\n * ```ts\n * toPackageName('plugin-ts') // '@kubb/plugin-ts'\n * toPackageName('@acme/my-plugin') // '@acme/my-plugin'\n * ```\n */\nexport function toPackageName(name: string): string {\n return name.startsWith('plugin-') ? `@kubb/${name}` : name\n}\n\n/**\n * The name Studio knows an extension by: the package of the installed extension whose manifest\n * `name` matches, otherwise its own `name`, so a plugin defined in the user's project is never\n * reported as a Kubb package that does not exist.\n *\n * @example\n * ```ts\n * toStudioName({ name: 'plugin-ts', extensions }) // '@kubb/plugin-ts'\n * toStudioName({ name: 'plugin-zod-operations', extensions }) // 'plugin-zod-operations', a local plugin\n * ```\n */\nexport function toStudioName({\n name,\n extensions = new Map(),\n kind = 'plugin',\n}: {\n name: string\n extensions?: InstalledExtensions\n kind?: ExtensionKind\n}): string {\n return [...extensions.values()].find(({ manifest }) => manifest.kind === kind && manifest.name === name)?.package ?? name\n}\n\n/**\n * Dynamically imports an extension package and returns its factory. Callers check\n * {@link isAllowedPlugin} or derive the package from a disk instance first, so an arbitrary module\n * never reaches `import()`.\n *\n * Packages must be pre-installed in the Docker image at build time via the `KUBB_PACKAGES`\n * build ARG, no runtime installation is possible in the distroless container.\n *\n * Resolution order: the manifest's `export`, else the camelCase named export the package name\n * implies (e.g. `pluginTs`), then the default export.\n *\n * @throws if the package cannot be imported or exports no callable factory.\n */\nasync function loadFactory({\n packageName,\n extensions,\n kind = 'plugin',\n}: {\n packageName: string\n extensions: InstalledExtensions\n kind?: ExtensionKind\n}): Promise<(options: unknown) => unknown> {\n const label = { plugin: 'Plugin', adapter: 'Adapter', parser: 'Parser' }[kind]\n let mod: Record<string, unknown>\n try {\n mod = await importFromProject(packageName)\n } catch (cause) {\n throw new Diagnostics.Error({\n code: kind === 'plugin' ? Diagnostics.code.pluginNotFound : Diagnostics.code.unknown,\n severity: 'error',\n message: `${label} \"${packageName}\" could not be loaded. Make sure it is installed: \\`npm install ${packageName}\\``,\n cause: toError(cause),\n })\n }\n\n const manifestExport = extensions.get(packageName)?.manifest.export\n if (manifestExport) {\n if (typeof mod[manifestExport] === 'function') return mod[manifestExport] as (options: unknown) => unknown\n throw new Diagnostics.Error({\n code: Diagnostics.code.incompatibleExtension,\n severity: 'error',\n message: `${label} \"${packageName}\" does not export \"${manifestExport}\", the factory its kubb-extension.json names.`,\n help: 'Install a version of the plugin whose exports match its kubb-extension.json.',\n })\n }\n\n const exportName = toExportName(packageName)\n if (typeof mod[exportName] === 'function') return mod[exportName] as (options: unknown) => unknown\n if (typeof mod['default'] === 'function') return mod['default'] as (options: unknown) => unknown\n\n throw new Diagnostics.Error({\n code: Diagnostics.code.incompatibleExtension,\n severity: 'error',\n message: `${label} \"${packageName}\" does not export a callable factory. Tried the named export \"${exportName}\" and \"default\".`,\n help: 'Install a Kubb plugin package that exports its factory.',\n })\n}\n\n/**\n * Resolves each plugin entry by dynamically importing its package and calling its factory with the\n * provided options. Only packages {@link isAllowedPlugin} accepts are loaded.\n *\n * @example\n * ```ts\n * const plugins = await resolvePlugins({\n * plugins: [\n * { name: '@kubb/plugin-react-query', options: { output: { path: './hooks' } } },\n * { name: '@kubb/plugin-ts', options: { output: { path: './types' } } },\n * ],\n * })\n * ```\n */\nexport async function resolvePlugins({\n plugins,\n extensions = new Map(),\n}: {\n plugins: NonNullable<JSONKubbConfig['plugins']>\n extensions?: InstalledExtensions\n}): Promise<Array<Plugin>> {\n return Promise.all(\n plugins.map(async ({ name, options }) => {\n if (!isAllowedPlugin({ packageName: name, extensions })) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.pluginNotFound,\n severity: 'error',\n message: `Plugin \"${name}\" is not an installed Kubb plugin. Studio loads @kubb/plugin-* packages and installed packages that ship a kubb-extension.json with kind \"plugin\".`,\n })\n }\n const factory = await loadFactory({ packageName: name, extensions })\n return factory(options ?? {}) as Plugin\n }),\n )\n}\n\n/**\n * A JSON copy of plugin or adapter options: functions and other values JSON cannot hold are left\n * out, so nothing callable crosses the socket. Options that cannot be copied at all, such as a\n * circular structure, come back empty.\n *\n * @example\n * ```ts\n * toJSONOptions({ output: { path: 'types' }, group: { name: () => 'x' } }) // { output: { path: 'types' }, group: {} }\n * ```\n */\nexport function toJSONOptions(options: unknown): Record<string, unknown> {\n try {\n const copy = JSON.parse(\n JSON.stringify(options ?? {}, (key, value: unknown) => (isSafeKey(key) && typeof value !== 'bigint' ? value : undefined)),\n ) as unknown\n return isPlainObject(copy) ? copy : {}\n } catch {\n return {}\n }\n}\n\n/**\n * Deep-merges Studio's options over the disk options, with Studio taking priority, except where the\n * disk value cannot survive JSON. Studio only ever saw a lossy copy of such a value, so the disk\n * value is kept rather than replaced by what Studio echoes back. Plain objects merge key by key, so\n * Studio can still change a literal that sits next to a function (e.g. `group.type` beside `group.name`).\n *\n * @example\n * ```ts\n * mergeOptions({ macros: [camelCaseMacro], syntaxType: 'type' }, { macros: [{ name: 'camelCase' }], syntaxType: 'interface' })\n * // { macros: [camelCaseMacro], syntaxType: 'interface' }\n * mergeOptions({ emptySchemaType: 'any' }, { emptySchemaType: null }) // {}\n * ```\n */\nexport function mergeOptions(disk: Record<string, unknown>, studio: Record<string, unknown>): Record<string, unknown> {\n const merged: Record<string, unknown> = { ...disk }\n\n for (const [key, value] of Object.entries(studio)) {\n if (!isSafeKey(key)) continue\n const current = disk[key]\n\n // A `null` from Studio is a field set back to \"unset\", so the factory default applies again.\n if (value === null) {\n if (current === undefined || isOptionValue(current)) delete merged[key]\n continue\n }\n\n if (isPlainObject(current) && isPlainObject(value)) {\n merged[key] = mergeOptions(current, value)\n continue\n }\n if (current !== undefined && !isOptionValue(current)) continue\n\n merged[key] = value\n }\n\n return merged\n}\n\n/**\n * Merges studio plugin options with disk config plugins.\n * Studio takes priority: options from studio win over disk (except values only the disk config\n * can express, see {@link mergeOptions}), and a plugin Studio explicitly\n * disabled is dropped even when the disk config still lists it. Disk plugins without a studio\n * counterpart are kept as-is. Studio plugins not present on disk are appended.\n *\n * For plugins present in both configs, the plugin is re-instantiated with merged options\n * so that all internal closures correctly reference the merged values.\n */\nexport async function mergePlugins({\n diskPlugins,\n studioPlugins,\n extensions = new Map(),\n}: {\n diskPlugins: Array<Plugin> | undefined\n studioPlugins: JSONKubbConfig['plugins'] | undefined\n extensions?: InstalledExtensions\n}): Promise<Array<Plugin> | undefined> {\n const pluginNameOf = (packageName: string) => extensions.get(packageName)?.manifest.name ?? toPluginName(packageName)\n // Matched on the package's base name rather than by instantiating first. Every Kubb plugin\n // factory returns exactly that (`@kubb/plugin-ts` → `plugin-ts`), enforced by the `satisfies` on\n // each factory's name.\n const disabledNames = new Set((studioPlugins ?? []).filter((entry) => entry.disabled).map((entry) => pluginNameOf(entry.name)))\n const activeDiskPlugins = disabledNames.size ? diskPlugins?.filter((plugin) => !disabledNames.has(resolveMeta(plugin).name)) : diskPlugins\n const activeStudioPlugins = studioPlugins?.filter((entry) => !entry.disabled)\n\n if (!activeDiskPlugins && !activeStudioPlugins?.length) return undefined\n if (!activeStudioPlugins?.length) return activeDiskPlugins\n\n if (!activeDiskPlugins) return resolvePlugins({ plugins: activeStudioPlugins, extensions })\n\n const studioEntryByName = new Map(activeStudioPlugins.map((entry) => [pluginNameOf(entry.name), entry] as const))\n const diskNames = new Set(activeDiskPlugins.map((plugin) => plugin.name))\n\n // Each plugin is instantiated once, with its final options. Resolving the whole payload first\n // just to read the names would build every overlapping plugin twice and discard the first.\n const merged = await Promise.all(\n activeDiskPlugins.map(async (diskPlugin) => {\n const studioEntry = studioEntryByName.get(resolveMeta(diskPlugin).name)\n if (!studioEntry) return diskPlugin\n\n // Disk as base, studio overrides, then re-instantiate so the plugin's closures reference the\n // merged values. A plugin that never sets `options` (e.g. `@kubb/plugin-barrel`) leaves\n // `diskPlugin.options` undefined.\n const diskOptions = (diskPlugin.options as Record<string, unknown>) ?? {}\n const options = mergeOptions(diskOptions, (studioEntry.options as Record<string, unknown>) ?? {})\n // A plugin defined in the user's project has no package to re-instantiate it from. Studio\n // echoing its options back unchanged is fine, any real change can only be made on disk.\n const unchanged = JSON.stringify(toJSONOptions(options)) === JSON.stringify(toJSONOptions(diskOptions))\n const [resolved] = await resolvePlugins({ plugins: [{ name: studioEntry.name, options }], extensions }).catch((cause: unknown) => {\n if (unchanged) return [diskPlugin]\n throw new Diagnostics.Error({\n code: Diagnostics.code.pluginNotFound,\n severity: 'error',\n message: `Plugin \"${diskPlugin.name}\" is not an installed @kubb/plugin-* package or Kubb extension, so Studio cannot change its options. Edit it in the config file, or only enable or disable it from Studio.`,\n cause: toError(cause),\n })\n })\n\n return resolved ?? diskPlugin\n }),\n )\n\n const studioOnly = activeStudioPlugins.filter((entry) => !diskNames.has(pluginNameOf(entry.name)))\n\n return [...merged, ...(await resolvePlugins({ plugins: studioOnly, extensions }))]\n}\n\n/**\n * Throws `KUBB_PATH_TRAVERSAL` when a plugin would write outside the config's output folder to a path\n * the disk config does not set. Studio can change `output.path`, also inside `override`, and add\n * plugins, so without this check any member of the Studio organization could write any file the agent\n * can reach, including `node_modules` code the next run imports. A path from the config file stays\n * allowed, since a monorepo may write outside its root.\n */\nexport function assertOutputPaths({\n plugins,\n diskPlugins,\n root,\n outputPath,\n}: {\n plugins: Array<Plugin>\n diskPlugins: Array<Plugin>\n root: string\n outputPath: string\n}): void {\n const base = path.resolve(root, outputPath)\n const targetsOf = (plugin: Plugin): Array<string> => {\n const { output, override } = (plugin.options ?? {}) as { output?: { path?: unknown }; override?: Array<{ options?: { output?: { path?: unknown } } }> }\n const outputs = [output, ...(Array.isArray(override) ? override.map((entry) => entry?.options?.output) : [])]\n return outputs.flatMap((entry) => (typeof entry?.path === 'string' ? [path.resolve(base, entry.path)] : []))\n }\n const diskTargets = new Set(diskPlugins.flatMap(targetsOf))\n\n for (const plugin of plugins) {\n const target = targetsOf(plugin).find((resolved) => !diskTargets.has(resolved) && !isPathInside(resolved, base))\n if (!target) continue\n\n throw new Diagnostics.Error({\n code: Diagnostics.code.pathTraversal,\n severity: 'error',\n message: `Plugin \"${plugin.name}\" would write to \"${target}\", outside the output folder \"${base}\". Studio can only set an output path inside it.`,\n help: 'Choose an output path inside the output folder, or set this path in the config file.',\n location: { kind: 'config' },\n plugin: plugin.name,\n })\n }\n}\n\n/**\n * The folders a `$ref` may read local files from on each kind of agent. Studio may have sent the\n * spec, so a shared agent gets none, and a managed agent only the git checkout it made itself. A\n * project agent gets its `root` and the folder of the file `input` in its own config. `undefined`\n * means no limit, which only `allowFileRefs` grants.\n */\nexport function resolveFileRefs({\n agentType,\n allowFileRefs,\n root,\n input,\n checkoutDir,\n}: {\n agentType: AgentType\n allowFileRefs: boolean\n root: string\n input?: Config['input']\n checkoutDir?: string\n}): Array<string> | undefined {\n if (agentType === 'sandbox' || agentType === 'global') return []\n if (agentType === 'managed') return checkoutDir ? [checkoutDir] : []\n if (allowFileRefs) return undefined\n const isFile = typeof input === 'string' && getInputKind(input) === 'file'\n return isFile ? [root, path.dirname(path.resolve(root, input))] : [root]\n}\n\n/**\n * Re-invokes the factory behind a disk adapter or parser with Studio's options merged over its own.\n * An instance carries live functions (`parse`, `print`, ...) that cannot survive JSON, so Studio's\n * options are a patch, not a replacement, and the factory is found from the disk instance itself: the\n * installed extension whose manifest names it, or the `@kubb/<kind>-<name>` package for a built-in\n * one. Throws when no factory resolves, as `mergePlugins` does, so an override Studio sent is never\n * dropped without a word. An extension without a manifest, such as `parserTsx`, has no options in\n * Studio, so Studio never sends one for it.\n */\nasync function rebuildExtension<T extends Adapter | Parser>({\n disk,\n studioOptions,\n kind,\n extensions,\n}: {\n disk: T\n studioOptions: object | undefined\n kind: ExtensionKind\n extensions: InstalledExtensions\n}): Promise<T> {\n if (!studioOptions || !Object.keys(studioOptions).length) return disk\n\n const { name } = resolveMeta(disk)\n const installed = [...extensions.values()].find(({ manifest }) => manifest.kind === kind && manifest.name === name)\n const packageName = installed?.package ?? `@kubb/${kind}-${name}`\n const factory = await loadFactory({ packageName, extensions, kind }).catch((cause: unknown) => {\n throw new Diagnostics.Error({\n code: kind === 'plugin' ? Diagnostics.code.pluginNotFound : Diagnostics.code.unknown,\n severity: 'error',\n message: `The ${kind} \"${name}\" is not an installed Kubb extension, so Studio cannot change its options. Edit it in the config file.`,\n cause: toError(cause),\n })\n })\n\n return factory(mergeOptions((disk.options as Record<string, unknown>) ?? {}, studioOptions as Record<string, unknown>)) as T\n}\n\n/** Merges Studio's valid `output` overrides, with `null` unsetting a member. */\nexport function mergeOutput({ output, studio }: { output: Config['output']; studio: unknown }): Config['output'] {\n if (!isPlainObject(studio)) return output\n const overrides = Object.fromEntries(Object.entries(studio).filter(([key, value]) => (value === null ? isOutputKey(key) : isOutputValue({ key, value }))))\n return mergeOptions(output, overrides) as Config['output']\n}\n\n/**\n * Merges Studio-provided adapter option overrides into the disk config's adapter, see {@link rebuildExtension}.\n */\nexport async function mergeAdapter(diskAdapter: Adapter | undefined, studioOptions: object | undefined, extensions: InstalledExtensions = new Map()) {\n if (!diskAdapter) return diskAdapter\n\n return rebuildExtension({ disk: diskAdapter, studioOptions, kind: 'adapter', extensions })\n}\n\n/**\n * Merges Studio-provided parser option overrides into the disk config's parsers, matched by the name\n * Studio knows each parser by, see {@link rebuildExtension}. Parsers Studio does not name are kept as is.\n */\nexport async function mergeParsers({\n diskParsers,\n studioParsers,\n extensions = new Map(),\n}: {\n diskParsers: Array<Parser>\n studioParsers: JSONKubbConfig['parsers'] | undefined\n extensions?: InstalledExtensions\n}): Promise<Array<Parser>> {\n if (!studioParsers?.length) return diskParsers\n\n const studioOptions = new Map(studioParsers.map((entry) => [entry.name, entry.options]))\n\n return Promise.all(\n diskParsers.map((parser) =>\n rebuildExtension({\n disk: parser,\n studioOptions: studioOptions.get(toStudioName({ name: resolveMeta(parser).name, extensions, kind: 'parser' })),\n kind: 'parser',\n extensions,\n }),\n ),\n )\n}\n","import { Diagnostics } from '@kubb/core'\n\n/**\n * Hosted Kubb Studio URL, used when a host passes none.\n */\nexport const defaultStudioUrl = 'https://kubb.studio'\n\n// `URL` keeps IPv6 brackets, so `::1` is `[::1]`.\nfunction isLoopbackHost(hostname: string): boolean {\n return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]'\n}\n\n/**\n * Appends `path` to the Studio URL and refuses plaintext to anything but this machine, so a token\n * or API key never crosses the network unencrypted. `socket` switches the scheme to `ws:`/`wss:`.\n *\n * @example\n * ```ts\n * secureUrl({ studioUrl: 'https://kubb.studio', path: '/api/agent/socket', socket: true }).href // 'wss://kubb.studio/api/agent/socket'\n * ```\n */\nexport function secureUrl({ studioUrl, path, socket = false }: { studioUrl: string; path: string; socket?: boolean }): URL {\n const url = new URL(`${studioUrl.replace(/\\/+$/, '')}${path}`)\n\n if (url.protocol !== 'https:' && !(url.protocol === 'http:' && isLoopbackHost(url.hostname))) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `Refusing to reach Kubb Studio at ${url.origin}: use an https:// URL, or a loopback host for local development`,\n })\n }\n if (socket) url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'\n\n return url\n}\n","import { randomUUID } from 'node:crypto'\nimport { existsSync } from 'node:fs'\nimport { writeFile } from 'node:fs/promises'\nimport { createRequire } from 'node:module'\nimport { tmpdir } from 'node:os'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { setTimeout as delay } from 'node:timers/promises'\nimport { getErrorMessage, isPathInside, mkdtemp, read, rm, toError } from '@internals/utils'\nimport {\n Diagnostics,\n cacheStorage,\n checkoutGitInput,\n type Config,\n fsStorage,\n getInputKind,\n type InputKind,\n Hookable,\n type KubbHooks,\n type ProblemCode,\n type Storage,\n readInstalledPackages,\n resolveCacheDir,\n resolveMeta,\n} from '@kubb/core'\nimport { newWebSocketRpcSession, RpcTarget } from 'capnweb'\nimport { x } from 'tinyexec'\nimport { version as kubbVersion } from '../package.json'\nimport { BUNDLED_PACKAGES, editConfigFile, pickOutput, readConfig, readImports } from '@internals/shared'\nimport { signAgentPayload } from './agentKey.ts'\nimport { diffHunks, pageHunks } from './diff.ts'\nimport { createGenerationStream } from './generationEvents.ts'\nimport { createGenerationStore, generate, type GenerationStore, listDisk, resolveGenerationLimits } from './generations.ts'\nimport {\n AGENT_INSTANCE_HEADER,\n AGENT_SOCKET_PATH,\n type AgentApi,\n AgentPermission,\n AgentCloseCode,\n AgentMessage,\n type AgentConnectInfo,\n type AgentPermissions,\n AgentSignatureContext,\n type AgentType,\n type ConfigEdit,\n ConfigEditOperation,\n type ConfigEntryView,\n type ConfigFileView,\n type ConfigRef,\n type ConnectMessagePayload,\n type DiskOutput,\n type GenerateInput,\n type GenerateResult,\n type GenerationEvent,\n type GenerationRun,\n type InstalledExtensions,\n MAX_CONNECT_CHALLENGE_LENGTH,\n MAX_FILES_PER_REQUEST,\n MAX_PAGE_LINES,\n type ReadDiffInput,\n type ReadDiffResult,\n type ReadFilesInput,\n type ReadFilesResult,\n type ReadInputInput,\n type ReadInputResult,\n type InstallExtensionInput,\n type InstallExtensionResult,\n type RemoveExtensionInput,\n type RemoveExtensionResult,\n type SaveConfigInput,\n type SaveResult,\n type StudioApi,\n type UpdateExtensionsInput,\n type UpdateExtensionsResult,\n} from './protocol.ts'\nimport { withPublicFetch } from './publicFetch.ts'\nimport { assertOutputPaths, mergeAdapter, mergeOutput, mergeParsers, mergePlugins, resolveFileRefs, toJSONOptions, toStudioName } from './resolveConfig.ts'\nimport { defaultStudioUrl, secureUrl } from './url.ts'\n\nconst HEARTBEAT_INTERVAL_MS = 30_000\nconst SHARED_AGENT_TYPES = new Set<AgentType>(['sandbox', 'global'])\n// Studio marks an agent offline after its liveness window, so a slower cadence would look dead.\nconst MAX_HEARTBEAT_INTERVAL_MS = 60_000\nconst PING_TIMEOUT_MS = 10_000\nconst OPEN_TIMEOUT_MS = 5_000\nconst MAX_RETRY_DELAY_MS = 30_000\nconst DISK_SNAPSHOT_MAX_FILES = 10_000\n// Sandboxes keep temporary output sets with a short lifetime.\nconst SANDBOX_GENERATION_TTL_MS = 15 * 60_000\n// What Studio may send a managed agent as its spec. Not `file` or `object`: a path would read the container's disk.\nconst MANAGED_INPUT_KINDS = new Set<InputKind>(['inline', 'url', 'git'])\n\n/**\n * Studio closed with {@link AgentCloseCode.UNAUTHORIZED}. Hosts forget the token and pair again.\n */\nexport class InvalidAgentTokenError extends Error {\n constructor(studioUrl: string) {\n super(`Kubb Studio rejected this agent's token. It expired or was revoked, or the agent was deleted in ${studioUrl}.`)\n this.name = 'InvalidAgentTokenError'\n }\n}\n\n/**\n * Studio closed with {@link AgentCloseCode.INCOMPATIBLE}. Only an upgrade helps.\n */\nexport class IncompatibleAgentError extends Error {\n constructor({ studioUrl, detail }: { studioUrl: string; detail?: string }) {\n super(`Kubb Studio at ${studioUrl} requires a newer agent${detail ? `: ${detail}` : ''}. Upgrade kubb or the Kubb agent image.`)\n this.name = 'IncompatibleAgentError'\n }\n}\n\nexport type StudioConnectedContext = AgentConnectInfo & {\n url: string\n /**\n * The Studio, runtime, and host versions, so a host can show a mismatch.\n */\n versions: { studio: string; kubb: string; agent: string }\n}\n\ndeclare global {\n namespace Kubb {\n interface KubbHooksRegistry {\n /**\n * Fired after each handshake, including reconnects.\n */\n 'studio:connected': [ctx: StudioConnectedContext]\n 'studio:disconnected': [ctx: { code: number; reason: string }]\n 'studio:reconnecting': [ctx: { delayMs: number }]\n /**\n * A finished command and what it did, such as `applied 2/3 edits to kubb.config.ts`.\n */\n 'studio:command': [\n ctx: {\n command: 'generate' | 'saveConfig' | 'installExtension' | 'updateExtensions' | 'removeExtension' | 'readFiles' | 'readInput' | 'readDiff'\n info: string\n /**\n * The Studio user who asked for the command, when Studio names one.\n */\n requestedBy?: string\n /**\n * Set when a generation failed. Its diagnostics went out through `kubb:generation:end`.\n */\n failed?: boolean\n },\n ]\n /**\n * A refused or ignored request, with the missing permission so the host can add a remedy.\n */\n 'studio:warn': [ctx: { message: string; permission?: AgentPermission }]\n 'studio:error': [ctx: { error: Error }]\n }\n }\n}\n\nexport type ConnectAgentOptions = {\n /**\n * The agent's bearer token, from {@link pairAgent}. A function is read before every socket opens.\n */\n token: string | (() => string | Promise<string>)\n /**\n * The agent key from `generateAgentKey`, which signs the connect challenge.\n */\n privateKey?: string\n studioUrl?: string\n /**\n * The config path shown in Studio, relative to `root` unless absolute.\n */\n configPath: string\n /**\n * Called for every handshake and every generation, so edits on disk show up. One entry per\n * `defineConfig(...)` entry, and a generation names the one it runs.\n */\n loadConfigs: () => Promise<Array<Config>>\n /**\n * The host's own version, reported to Studio next to the runtime's.\n */\n version: string\n /**\n * The project root generation runs against.\n * @default process.cwd()\n */\n root?: string\n /**\n * What Studio may do in this project. Every permission is off unless granted.\n */\n permissions?: Partial<AgentPermissions>\n /**\n * The kind of agent the host runs. A `'sandbox'` or `'global'` agent is shared, and lets Studio read what it generated.\n * Studio's own `sandbox` and `managed` flags only take permissions away.\n * @default 'user'\n */\n agentType?: AgentType\n /** The CLI entry `installExtension` runs `kubb add` with. Found through the project's `kubb` or `@kubb/cli` dependency when omitted. */\n kubbBin?: string\n /**\n * Receives the `studio:*` hooks and the `kubb:*` hooks of every generation.\n */\n hooks?: Hookable<KubbHooks>\n signal?: AbortSignal\n /**\n * Longest wait between reconnect attempts, in milliseconds.\n * @default 30000\n */\n maxRetryDelay?: number\n /**\n * Milliseconds between keep-alive pings, at most 60000.\n * @default 30000\n */\n heartbeatInterval?: number\n}\n\ntype ResolvedOptions = Required<Omit<ConnectAgentOptions, 'signal' | 'kubbBin' | 'privateKey'>> & {\n signal?: AbortSignal\n kubbBin?: string\n privateKey?: string\n permissions: AgentPermissions\n configFile: string\n}\n\ntype Rpc = { studio: StudioApi; closed: Promise<{ code: number; reason: string }>; close: () => void }\n\n// Tests swap in an in-process pair.\nexport type OpenRpc = (input: { url: URL; token: string; instanceId: string; agent: AgentApi }) => Rpc\n\ntype Session = {\n info?: AgentConnectInfo\n connected: PromiseWithResolvers<AgentConnectInfo>\n closed: boolean\n active?: { jobId: string; abort: () => void; settled: Promise<void> }\n install?: { abort: () => void; settled: Promise<void> }\n saving?: boolean\n}\n\nconst INSTALL_TIMEOUT_MS = 5 * 60_000\n/** How many trailing lines of a failed `kubb add` the reason keeps. */\nconst INSTALL_OUTPUT_LINES = 20\n/** `owner/slug` or `slug`, as `kubb add` takes it. Checked before it becomes an argument. */\nconst REGISTRY_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\\/[a-z0-9]+(?:-[a-z0-9]+)*)?$/\n\n/** The CLI the project depends on, so `kubb add` installs next to what the config imports. */\nfunction findKubbBin(root: string): string | undefined {\n const requireModule = createRequire(path.resolve(root, 'package.json'))\n const names = ['kubb', '@kubb/cli']\n // Nearest directory first, so a nested project does not pick up an ancestor's CLI.\n return (requireModule.resolve.paths('kubb') ?? [])\n .flatMap((dir) => names.map((name) => path.join(dir, name, 'bin', 'kubb.js')))\n .find((bin) => existsSync(bin))\n}\n\n/** Runs a `kubb` command without a shell, and keeps the end of its output for the failure reason. */\nasync function runKubb({ bin, args, cwd, signal }: { bin: string; args: Array<string>; cwd: string; signal: AbortSignal }) {\n try {\n const { stdout, stderr, exitCode } = await x(process.execPath, [bin, ...args], {\n signal,\n timeout: INSTALL_TIMEOUT_MS,\n throwOnError: false,\n nodeOptions: { cwd, env: { ...process.env, NO_COLOR: '1', FORCE_COLOR: '0' } },\n })\n const output = `${stdout}\\n${stderr}`.trim().split('\\n').slice(-INSTALL_OUTPUT_LINES).join('\\n')\n return { failed: exitCode !== 0, output: output || `kubb ${args[0]} exited with ${exitCode ?? 'a signal'}` }\n } catch (error) {\n // tinyexec still throws when the timeout hits or the process cannot start.\n return { failed: true, output: `kubb ${args[0]} did not run: ${getErrorMessage(error)}` }\n }\n}\n\n// A throwing host listener must not break the connection.\nfunction emit<TName extends keyof KubbHooks & string>(hooks: Hookable<KubbHooks>, name: TName, ...args: KubbHooks[TName]): Promise<void> {\n return Promise.resolve(hooks.callHook(name, ...args)).catch(() => {})\n}\n\nfunction isValidPage({ cursor, limit }: Pick<ReadFilesInput, 'cursor' | 'limit'>): boolean {\n if (limit === undefined) return cursor === undefined\n if (cursor !== undefined && (!Number.isSafeInteger(cursor) || cursor < 0)) return false\n return Number.isSafeInteger(limit) && limit >= 1 && limit <= MAX_PAGE_LINES\n}\n\n/**\n * Maps generated paths into a temporary directory while keeping the project root for input resolution.\n */\nfunction stagingStorage({ root, directory }: { root: string; directory: string }): Storage {\n const storage = fsStorage()\n const target = (key: string) => {\n const relative = path.relative(root, path.resolve(root, key))\n if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) throw new Error('Output path escapes the project root')\n return path.join(directory, relative)\n }\n return {\n name: 'fs',\n readItem: (key) => storage.readItem(target(key)),\n writeItem: (key, value) => storage.writeItem(target(key), value),\n removeItem: (key) => storage.removeItem(target(key)),\n readKeys: (base) => storage.readKeys(base ? target(base) : directory),\n empty: (base) => (base ? storage.empty(target(base)) : Promise.resolve()),\n }\n}\n\ntype RunHandle = { stream: ReadableStream<GenerationEvent>; result: Promise<GenerateResult>; stop: () => void }\n\nclass GenerationRunTarget extends RpcTarget implements GenerationRun {\n readonly #run: RunHandle\n\n constructor(run: RunHandle) {\n super()\n this.#run = run\n }\n\n async events() {\n return this.#run.stream\n }\n result() {\n return this.#run.result\n }\n async cancel() {\n this.#run.stop()\n }\n // Cap'n Web also calls this when the peer session is torn down, so a dropped socket stops the run.\n [Symbol.dispose]() {\n this.#run.stop()\n }\n}\n\n/** A save's edit once a `set-input` document is named, or why it was refused. */\ntype KeptEdit = (ConfigEdit & { document?: { fileName: string; text: string } }) | { reason: string }\n\n// Cap'n Web exposes only prototype methods, so the public methods are exactly `AgentApi`.\nclass Agent extends RpcTarget implements AgentApi {\n readonly #options: ResolvedOptions\n readonly #session: Session\n readonly #limits = resolveGenerationLimits()\n #store: GenerationStore | undefined\n readonly #sandboxCacheRoot = path.join(tmpdir(), `kubb-studio-${randomUUID()}`)\n // Kept sets never change, so a diff is computed once and its pages are cut from it.\n readonly #diffs = new Map<string, ReturnType<typeof diffHunks>>()\n\n constructor({ options, session }: { options: ResolvedOptions; session: Session }) {\n super()\n this.#options = options\n this.#session = session\n }\n\n get #sandbox(): boolean {\n return SHARED_AGENT_TYPES.has(this.#options.agentType) || this.#session.info?.sandbox === true\n }\n\n get #managed(): boolean {\n return this.#options.agentType === 'managed' || this.#session.info?.managed === true\n }\n\n // The host's kind, unless Studio's flags narrow it to a sandbox or a managed agent.\n get #agentType(): AgentType {\n if (this.#sandbox) return 'sandbox'\n if (this.#managed) return 'managed'\n return this.#options.agentType\n }\n\n // A sandbox has no project to write to or edit. Only the host's `agentType` grants reads.\n get #permissions(): AgentPermissions {\n const { permissions, agentType } = this.#options\n const sandbox = SHARED_AGENT_TYPES.has(agentType)\n if (this.#managed) return { ...permissions, allowFileRefs: false }\n if (!this.#sandbox) return permissions\n\n return {\n ...permissions,\n allowWrite: false,\n allowConfigEdit: false,\n allowInstall: false,\n allowUpdate: false,\n allowRemove: false,\n allowSaveInput: false,\n allowFileRefs: false,\n allowRead: sandbox || permissions.allowRead,\n allowReadAst: sandbox || permissions.allowReadAst,\n }\n }\n\n // Owned agents retain output in the project cache. Each sandbox connection has a temporary cache.\n get #generations(): GenerationStore {\n this.#store ??= createGenerationStore({\n storage: cacheStorage({ root: this.#sandbox ? this.#sandboxCacheRoot : this.#options.root }),\n maxCount: this.#limits.maxCount,\n maxMb: this.#limits.maxMb,\n ttlMs: this.#sandbox ? SANDBOX_GENERATION_TTL_MS : undefined,\n })\n return this.#store\n }\n\n async clear() {\n if (this.#sandbox) await rm(resolveCacheDir(this.#sandboxCacheRoot), { recursive: true, force: true })\n }\n\n #warn({ message, permission }: { message: string; permission?: AgentPermission }): Promise<void> {\n return emit(this.#options.hooks, 'studio:warn', { message, permission })\n }\n\n // Studio shows the thrown message, and the host logs the same text.\n async #refuse({\n message,\n permission,\n code = Diagnostics.code.unknown,\n }: {\n message: string\n permission?: AgentPermission\n code?: ProblemCode\n }): Promise<never> {\n await this.#warn({ message, permission })\n throw new Diagnostics.Error({ code, severity: 'error', message })\n }\n\n #assertConnected(): void {\n if (!this.#session.info)\n throw new Diagnostics.Error({ code: Diagnostics.code.internalError, severity: 'error', message: 'Studio must call connect() before any other command' })\n }\n\n #logCommand(command: KubbHooks['studio:command'][0]['command'], info: string, requestedBy?: string, failed?: boolean): Promise<void> {\n return emit(this.#options.hooks, 'studio:command', { command, info, requestedBy, failed })\n }\n\n // Not cached: the user can edit the file between two Studio actions.\n async #readConfigFileView(source: Promise<string>): Promise<ConfigFileView | undefined> {\n if (!this.#permissions.allowConfigEdit) return undefined\n\n try {\n return readConfig(await source)\n } catch (error) {\n await this.#warn({ message: `Could not read ${this.#options.configFile}: ${getErrorMessage(error)}` })\n return undefined\n }\n }\n\n // Not cached either: the user can install a plugin while the agent runs. Keeps each project\n // dependency, config import and built-in that resolves and ships a valid `kubb-extension.json`.\n async #installedExtensions(source = read(this.#options.configFile)): Promise<InstalledExtensions> {\n const imports = await source.then(readImports, () => [])\n const installed = await readInstalledPackages({ root: this.#options.root, packages: [...imports, ...BUNDLED_PACKAGES], resolveFrom: ['kubb'] })\n\n return new Map(\n installed.flatMap(({ package: name, version, manifest }) =>\n version !== undefined && manifest\n ? [[name, { package: name, version, manifest, ...(BUNDLED_PACKAGES.includes(name) ? { bundled: true as const } : {}) }] as const]\n : [],\n ),\n )\n }\n\n async connect(info: AgentConnectInfo): Promise<ConnectMessagePayload> {\n this.#session.info = info\n const { configPath, root, version, loadConfigs, configFile } = this.#options\n const source = read(configFile)\n const [configs, file, extensions] = await Promise.all([loadConfigs(), this.#readConfigFileView(source), this.#installedExtensions(source)])\n // Copied through JSON: Cap'n Web would otherwise pass every function in the options as a stub\n // Studio could call, running the user's config code in this process.\n const entries: Array<ConfigEntryView> = []\n for (const config of configs) {\n const disk = await this.#readDiskOutput(config).catch(async (error: unknown) => {\n await this.#warn({ message: `Could not read the output directory: ${getErrorMessage(error)}` })\n return undefined\n })\n entries.push({ ...toEntryView(config, extensions), ...(disk && { disk }) })\n }\n this.#session.connected.resolve(info)\n const { privateKey } = this.#options\n const { challenge } = info\n const signature =\n privateKey && typeof challenge === 'string' && challenge && challenge.length <= MAX_CONNECT_CHALLENGE_LENGTH\n ? signAgentPayload({ privateKey, context: AgentSignatureContext.CONNECT, payload: challenge })\n : undefined\n\n return {\n versions: { kubb: kubbVersion, agent: version },\n root,\n config: { path: configPath, file, extensions: [...extensions.values()], configs: entries },\n permissions: this.#permissions,\n ...(signature && { signature }),\n }\n }\n\n async #readDiskOutput(config: Config): Promise<DiskOutput | undefined> {\n if (this.#sandbox || !this.#permissions.allowRead || this.#session.active) return undefined\n const files = await listDisk({ root: this.#options.root, outputPath: config.output.path, maxFiles: DISK_SNAPSHOT_MAX_FILES })\n if (!files) return undefined\n\n const { jobId, output } = await this.#generations.keepInitial(files)\n return { jobId, files: output.paths, hashes: output.hashes }\n }\n\n startGeneration(input: GenerateInput): GenerationRun {\n const stream = createGenerationStream(this.#options.hooks, input.jobId)\n const controller = new AbortController()\n const result = this.#runGeneration(input, controller).then(\n (value) => stream.close().then(() => value),\n (error: unknown) => {\n stream.fail(error)\n throw error\n },\n )\n // A disconnect can reject this after the remote caller disappeared.\n void result.catch(() => {})\n\n return new GenerationRunTarget({\n stream: stream.stream,\n result,\n stop: () => {\n controller.abort(new Error('Generation canceled'))\n stream.fail()\n },\n })\n }\n\n /**\n * Keeps a job's output and permitted parsed input, then cleans up its temporary generation directories.\n */\n async #runGeneration(input: GenerateInput, controller: AbortController): Promise<GenerateResult> {\n this.#assertConnected()\n // Checked before the first `await`, so two calls in the same tick can't both pass.\n if (this.#session.closed) throw new Diagnostics.Error({ code: Diagnostics.code.internalError, severity: 'error', message: 'Connection is closed' })\n if (this.#session.active) return this.#refuse({ message: AgentMessage.GENERATION_IN_PROGRESS })\n if (this.#session.install) return this.#refuse({ message: AgentMessage.INSTALL_IN_PROGRESS })\n if (this.#session.saving) return this.#refuse({ message: AgentMessage.SAVE_IN_PROGRESS })\n const settled = Promise.withResolvers<void>()\n this.#session.active = { jobId: input.jobId, abort: () => controller.abort(new Error('Generation canceled')), settled: settled.promise }\n let root = this.#options.root\n let outputRoot: string | undefined\n\n try {\n // Kubb keys its manifest cache by root, so sandbox tenants sharing one root would read each other's.\n if (this.#sandbox) root = await mkdtemp(path.join(tmpdir(), 'kubb-job-'))\n if (!this.#sandbox && !this.#permissions.allowWrite) outputRoot = await mkdtemp(path.join(tmpdir(), 'kubb-output-'))\n return await this.#generate({ input, root, outputRoot, signal: controller.signal })\n } finally {\n if (root !== this.#options.root) {\n await Promise.all([rm(root, { recursive: true, force: true }), rm(resolveCacheDir(root), { recursive: true, force: true })]).catch(() => {})\n }\n if (outputRoot) await rm(outputRoot, { recursive: true, force: true })\n this.#session.active = undefined\n settled.resolve()\n }\n }\n\n /**\n * Merges Studio's config over the project config and confines generation to the configured output folder.\n */\n async #generate({\n input,\n root,\n outputRoot,\n signal,\n }: {\n input: GenerateInput\n root: string\n outputRoot?: string\n signal: AbortSignal\n }): Promise<GenerateResult> {\n const { jobId, config: patch } = input\n // A sandbox has no spec on disk, so it only ever generates from the content Studio sends. A path\n // or URL would make it read host files or fetch internal addresses on behalf of any tenant.\n const studioInput = this.#sandbox || this.#managed ? patch?.input : undefined\n if (this.#sandbox && (typeof studioInput !== 'string' || !studioInput.trim() || getInputKind(studioInput) !== 'inline')) {\n return this.#refuse({ message: AgentMessage.SANDBOX_INPUT_ONLY })\n }\n // Studio may point a managed agent at a URL or a git file, and it falls back to its config's input without one. A file path would read the container's disk.\n if (this.#managed && studioInput !== undefined && !MANAGED_INPUT_KINDS.has(getInputKind(studioInput))) {\n return this.#refuse({ message: AgentMessage.MANAGED_INPUT_KIND })\n }\n\n const [configs, extensions] = await Promise.all([this.#options.loadConfigs(), this.#installedExtensions()])\n const config = pickConfig(configs, patch?.config)\n if (!config) return this.#refuse({ message: AgentMessage.CONFIG_ENTRY_NOT_FOUND })\n const [plugins, adapter, parsers] = await Promise.all([\n mergePlugins({ diskPlugins: config.plugins, studioPlugins: patch?.plugins, extensions }).then((merged) => {\n assertOutputPaths({ plugins: merged ?? [], diskPlugins: config.plugins, root, outputPath: config.output.path })\n return merged\n }),\n mergeAdapter(config.adapter, patch?.adapter, extensions),\n mergeParsers({ diskParsers: config.parsers, studioParsers: patch?.parsers, extensions }),\n ]).catch(async (error: unknown) => {\n // Thrown before core runs, so nothing else reports it to the host.\n await emit(this.#options.hooks, 'kubb:error', { error: toError(error) })\n throw error\n })\n\n const activePlugins = plugins ?? config.plugins\n\n if (patch?.input && !this.#sandbox && !this.#managed) {\n // A `kubb:warn` rather than `studio:warn`, so the generation's event stream carries it to Studio too.\n await emit(this.#options.hooks, 'kubb:warn', {\n message: 'Ignored the spec from Studio: generating from a Studio spec is only available to a sandbox or managed agent',\n })\n }\n\n // A managed agent checks out any git input itself, the config's too, so the fetch stays on public addresses.\n const managedInput = this.#managed ? (studioInput ?? config.input) : undefined\n const checkout =\n typeof managedInput === 'string' && getInputKind(managedInput) === 'git'\n ? await checkoutGitInput(managedInput, signal, { publicOnly: true, authorization: input.gitAuth?.authorization }).catch((error: unknown) =>\n this.#refuse({ message: getErrorMessage(error), code: Diagnostics.code.gitInputFailed }),\n )\n : undefined\n const run = () =>\n generate({\n config: {\n ...config,\n root,\n input: checkout?.path ?? studioInput ?? config.input,\n output: mergeOutput({ output: config.output, studio: patch?.output }),\n storage: outputRoot ? stagingStorage({ root, directory: outputRoot }) : fsStorage(),\n plugins: activePlugins,\n adapter,\n parsers,\n },\n hooks: this.#options.hooks,\n signal,\n allowExec: this.#permissions.allowWrite && this.#permissions.allowExec,\n fileRefs: resolveFileRefs({\n agentType: this.#agentType,\n allowFileRefs: this.#permissions.allowFileRefs,\n root: this.#options.root,\n input: config.input,\n checkoutDir: checkout?.dir,\n }),\n })\n // The adapter fetches the URL and every `$ref` in it, so a shared or hosted agent limits the fetch itself to public addresses.\n const files = await (this.#sandbox || this.#managed ? withPublicFetch(run) : run())\n .catch(async (error: unknown) => {\n await this.#generations.drop(jobId)\n await this.#logCommand('generate', getErrorMessage(error), input.requestedBy, true)\n throw error\n })\n .finally(() => checkout?.dispose())\n\n const output = await this.#generations.keep({ jobId, files, maxSetMb: this.#limits.maxMb })\n // Only `readInput` reads it, which needs `allowReadAst`.\n const inputBytes = await this.#generations.keepInput({ jobId, input: this.#permissions.allowReadAst ? files.input : null, maxSetMb: this.#limits.maxMb })\n if (!output.paths.length && Object.keys(output.hashes).length) {\n await this.#warn({ message: 'Kept only the hashes of this generation: its output is too large to keep' })\n }\n await this.#generations.add({ jobId, output, inputBytes })\n await this.#logCommand(\n 'generate',\n `${activePlugins.length} plugin${activePlugins.length === 1 ? '' : 's'}, ${this.#permissions.allowWrite ? 'written to disk' : 'staged on disk'}${studioInput !== undefined ? ', from a Studio spec' : ''}`,\n input.requestedBy,\n )\n\n return {\n status: 'success',\n files: [...files.paths],\n fileCount: files.paths.size,\n hashes: output.hashes,\n }\n }\n\n async saveConfig(input: SaveConfigInput): Promise<SaveResult> {\n this.#assertConnected()\n const { configPath, configFile } = this.#options\n\n if (!Array.isArray(input.edits)) {\n await this.#warn({ message: 'Ignored save: the message carried no edits' })\n return { outcomes: [], changed: false }\n }\n\n const edits = input.edits\n const refuse = (reason: string): SaveResult => ({ outcomes: edits.map((edit) => ({ edit, applied: false, reason })), changed: false })\n\n if (!this.#permissions.allowConfigEdit) {\n await this.#warn({ message: 'Ignored save: editing kubb.config.ts was not granted' })\n return refuse('the agent was not granted permission to edit kubb.config.ts')\n }\n\n // A running generation reloads the config, so it would see half the change.\n const busy = this.#busy()\n if (busy) return refuse(busy)\n\n // Keeps `kubb add` from rewriting the config while this save is still writing it.\n this.#session.saving = true\n try {\n const kept: Array<KeptEdit> = []\n for (const edit of edits) kept.push(await this.#keepInput(edit))\n const written = await editConfigFile({\n filePath: configFile,\n edits: kept.flatMap((edit) => ('reason' in edit ? [] : [edit])),\n extensions: await this.#installedExtensions(),\n })\n let next = 0\n // Back in the order Studio sent them, each naming the edit as sent rather than the document's file.\n const outcomes = kept.map((edit, index) =>\n 'reason' in edit ? { edit: edits[index]!, applied: false, reason: edit.reason } : { ...written.outcomes[next++]!, edit: edits[index]! },\n )\n // A document is written only once its config edit applied, in edit order, so the last edit for a file wins.\n let wroteDocument = false\n for (const [index, edit] of kept.entries()) {\n if (!('document' in edit) || !edit.document || !outcomes[index]!.applied) continue\n await writeFile(path.join(this.#options.root, edit.document.fileName), edit.document.text, 'utf-8')\n wroteDocument = true\n }\n const changed = written.changed || wroteDocument\n const applied = outcomes.filter((outcome) => outcome.applied).length\n await this.#logCommand('saveConfig', `applied ${applied}/${outcomes.length} edits to ${configPath}`, input.requestedBy)\n\n return { outcomes, changed }\n } catch (error) {\n // Refuse every edit so Studio hears back instead of waiting.\n await emit(this.#options.hooks, 'studio:error', { error: toError(error) })\n return refuse(getErrorMessage(error))\n } finally {\n this.#session.saving = false\n }\n }\n\n /**\n * Readies a `set-input` edit for the config file: a document is pointed at `openapi.yaml` (`openapi.json`\n * for JSON) in the project, one file per config entry, for `saveConfig` to write once the edit applies.\n * A managed agent refuses a file path, as in a generation. Every agent refuses a file path outside the project.\n */\n async #keepInput(edit: ConfigEdit): Promise<KeptEdit> {\n // A blank input goes on unchanged, so the config writer refuses it before any file is written.\n if (edit?.operation !== ConfigEditOperation.SET_INPUT || typeof edit.input !== 'string' || !edit.input.trim()) return edit\n if (!this.#permissions.allowSaveInput) {\n await this.#warn({ message: 'Ignored the spec to save: saving the input was not granted', permission: AgentPermission.SAVE_INPUT })\n return { reason: 'the agent was not granted permission to save the input' }\n }\n const kind = getInputKind(edit.input)\n if (this.#managed && !MANAGED_INPUT_KINDS.has(kind)) return { reason: AgentMessage.MANAGED_INPUT_KIND }\n // The next generation reads the input file itself, and the `$ref` limit does not cover it.\n // A `url` that is not http(s), such as `C:\\spec.yaml`, is read as a file path too.\n const isFilePath = kind === 'file' || (kind === 'url' && !/^https?:/i.test(edit.input))\n if (isFilePath && !isPathInside(path.resolve(this.#options.root, edit.input), this.#options.root)) {\n return { reason: 'the input is a file outside the project' }\n }\n if (kind !== 'inline') return edit\n\n const entry = edit.config === undefined || edit.config === 0 ? '' : `-${String(edit.config).replace(/[^\\w.-]/g, '-')}`\n const fileName = `openapi${entry}.${isJson(edit.input) ? 'json' : 'yaml'}`\n return { ...edit, input: `./${fileName}`, document: { fileName, text: edit.input } }\n }\n\n /**\n * Installs a registry extension into the project with `kubb add <id> --yes`, which also adds a\n * plugin to `kubb.config.ts`. Studio calls `connect()` again afterwards to see the result.\n */\n async installExtension(input: InstallExtensionInput): Promise<InstallExtensionResult> {\n this.#assertConnected()\n const { root, configFile, kubbBin = findKubbBin(root) } = this.#options\n const refuse = async (reason: string, permission?: AgentPermission): Promise<InstallExtensionResult> => {\n await this.#warn({ message: `Ignored install: ${reason}`, permission })\n return { installed: false, reason }\n }\n\n if (typeof input?.id !== 'string' || !REGISTRY_ID.test(input.id)) return refuse('the message carried no registry id')\n if (!this.#permissions.allowInstall) return refuse('installing extensions was not granted', AgentPermission.INSTALL)\n if (!this.#permissions.allowConfigEdit) return refuse('editing kubb.config.ts was not granted', AgentPermission.CONFIG_EDIT)\n const busy = this.#busy()\n if (busy) return refuse(busy)\n if (!kubbBin) return refuse('kubb is not installed in the project')\n\n const { failed, output } = await this.#runKubb({ bin: kubbBin, args: ['add', input.id, '--yes', '--config', configFile] })\n await this.#logCommand('installExtension', `${failed ? 'failed to install' : 'installed'} ${input.id}`, input.requestedBy, failed)\n return failed ? { installed: false, reason: output } : { installed: true }\n }\n\n /**\n * Moves installed extensions to the registry's version with `kubb update [ids] --yes`, which\n * installs packages and leaves `kubb.config.ts` alone. Studio calls `connect()` again afterwards.\n */\n async updateExtensions(input: UpdateExtensionsInput): Promise<UpdateExtensionsResult> {\n this.#assertConnected()\n const { root, kubbBin = findKubbBin(root) } = this.#options\n const refuse = async (reason: string, permission?: AgentPermission): Promise<UpdateExtensionsResult> => {\n await this.#warn({ message: `Ignored update: ${reason}`, permission })\n return { updated: false, reason }\n }\n\n const ids = input?.ids ?? []\n if (!Array.isArray(ids) || !ids.every((id) => typeof id === 'string' && REGISTRY_ID.test(id))) return refuse('the message carried an invalid registry id')\n if (!this.#permissions.allowUpdate) return refuse('updating extensions was not granted', AgentPermission.UPDATE)\n const busy = this.#busy()\n if (busy) return refuse(busy)\n if (!kubbBin) return refuse('kubb is not installed in the project')\n\n const { failed, output } = await this.#runKubb({ bin: kubbBin, args: ['update', ...ids, '--yes'] })\n await this.#logCommand('updateExtensions', `${failed ? 'failed to update' : 'updated'} ${ids.join(', ') || 'all extensions'}`, input?.requestedBy, failed)\n return failed ? { updated: false, reason: output } : { updated: true }\n }\n\n /**\n * Removes an extension with `kubb remove <id> --yes`, which deletes it from `kubb.config.ts` and\n * uninstalls its package. Studio calls `connect()` again afterwards.\n */\n async removeExtension(input: RemoveExtensionInput): Promise<RemoveExtensionResult> {\n this.#assertConnected()\n const { root, configFile, kubbBin = findKubbBin(root) } = this.#options\n const refuse = async (reason: string, permission?: AgentPermission): Promise<RemoveExtensionResult> => {\n await this.#warn({ message: `Ignored remove: ${reason}`, permission })\n return { removed: false, reason }\n }\n\n if (typeof input?.id !== 'string' || !REGISTRY_ID.test(input.id)) return refuse('the message carried no registry id')\n if (!this.#permissions.allowRemove) return refuse('removing extensions was not granted', AgentPermission.REMOVE)\n if (!this.#permissions.allowConfigEdit) return refuse('editing kubb.config.ts was not granted', AgentPermission.CONFIG_EDIT)\n const busy = this.#busy()\n if (busy) return refuse(busy)\n if (!kubbBin) return refuse('kubb is not installed in the project')\n\n const { failed, output } = await this.#runKubb({ bin: kubbBin, args: ['remove', input.id, '--yes', '--config', configFile] })\n await this.#logCommand('removeExtension', `${failed ? 'failed to remove' : 'removed'} ${input.id}`, input.requestedBy, failed)\n return failed ? { removed: false, reason: output } : { removed: true }\n }\n\n /** Why a command that touches the project cannot start right now. */\n #busy(): string | undefined {\n if (this.#session.active) return 'a generation is in progress'\n if (this.#session.install) return 'an install, update, or remove is in progress'\n if (this.#session.saving) return 'a save is in progress'\n return undefined\n }\n\n /** Runs `kubb` in the project while holding off saves and generations, and ends it when the socket closes. */\n async #runKubb({ bin, args }: { bin: string; args: Array<string> }) {\n const controller = new AbortController()\n const settled = Promise.withResolvers<void>()\n this.#session.install = { abort: () => controller.abort(), settled: settled.promise }\n try {\n return await runKubb({ bin, args, cwd: this.#options.root, signal: controller.signal })\n } finally {\n this.#session.install = undefined\n settled.resolve()\n }\n }\n\n /**\n * Returns the Kubb AST a kept job parsed its spec into. Refused without `allowReadAst`.\n */\n async readInput(input: ReadInputInput): Promise<ReadInputResult> {\n this.#assertConnected()\n if (!this.#permissions.allowReadAst) return this.#refuse({ message: AgentMessage.READ_AST_NOT_ALLOWED, permission: AgentPermission.READ_AST })\n if (typeof input.jobId !== 'string' || !input.jobId) return this.#refuse({ message: AgentMessage.JOB_REQUIRED })\n\n const generation = await this.#generations.get(input.jobId)\n if (!generation) return this.#refuse({ message: AgentMessage.GENERATION_GONE })\n // A rerun of the job can leave an earlier run's input on disk, so trust only what this run kept.\n const kept = generation.inputBytes ? await this.#generations.readInput(input.jobId) : undefined\n if (!kept) return this.#refuse({ message: AgentMessage.NO_INPUT })\n await this.#logCommand('readInput', 'read the API input')\n\n return { input: kept }\n }\n\n /**\n * Returns the requested files of a kept job, one page of lines at a time. Refused without `allowRead`.\n */\n async readFiles(input: ReadFilesInput): Promise<ReadFilesResult> {\n this.#assertConnected()\n if (!this.#permissions.allowRead) return this.#refuse({ message: AgentMessage.READ_NOT_ALLOWED, permission: AgentPermission.READ })\n if (!Array.isArray(input.paths) || typeof input.jobId !== 'string' || !input.jobId) {\n return this.#refuse({ message: AgentMessage.FILE_REQUEST_INVALID })\n }\n const { paths } = input\n if (paths.length > MAX_FILES_PER_REQUEST) return this.#refuse({ message: AgentMessage.TOO_MANY_FILES })\n if (!isValidPage(input)) return this.#refuse({ message: AgentMessage.INVALID_PAGE })\n\n const generation = await this.#generations.get(input.jobId)\n if (!generation) return this.#refuse({ message: AgentMessage.GENERATION_GONE })\n\n // Only paths the set holds are read, never an arbitrary path.\n const result = await this.#generations.read({ generation, paths, cursor: input.cursor, limit: input.limit })\n await this.#logCommand('readFiles', `read ${Object.keys(result.files).length}/${paths.length} requested file${paths.length === 1 ? '' : 's'}`)\n\n return result\n }\n\n /**\n * Returns one page of the line diff of a file between two kept sets. Refused without `allowRead`.\n */\n async readDiff(input: ReadDiffInput): Promise<ReadDiffResult> {\n this.#assertConnected()\n if (!this.#permissions.allowRead) return this.#refuse({ message: AgentMessage.READ_NOT_ALLOWED, permission: AgentPermission.READ })\n const { jobId, path, base, cursor = 0, limit } = input\n if (typeof jobId !== 'string' || !jobId || typeof path !== 'string' || !path || typeof base?.jobId !== 'string' || !base.jobId) {\n return this.#refuse({ message: AgentMessage.DIFF_REQUEST_INVALID })\n }\n if (!isValidPage({ cursor, limit })) {\n return this.#refuse({ message: AgentMessage.INVALID_PAGE })\n }\n\n const [generation, baseGeneration] = await Promise.all([this.#generations.get(jobId), this.#generations.get(base.jobId)])\n if (!generation || !baseGeneration) return this.#refuse({ message: AgentMessage.GENERATION_GONE })\n\n // Only paths the sets hold are read, never an arbitrary path.\n const [after, before] = await Promise.all([\n this.#generations.read({ generation, paths: [path] }),\n this.#generations.read({ generation: baseGeneration, paths: [path] }),\n ])\n const afterContent = after.files[path]\n // Over the size cap only hashes are kept, which must not read as a deleted file.\n if (afterContent === undefined && path in generation.output.hashes) return this.#refuse({ message: AgentMessage.HASHES_ONLY })\n const beforeContent = before.files[path]\n if (beforeContent === undefined)\n return { hunks: [], nextCursor: null, hasBase: false, stats: { additions: 0, deletions: 0, hunks: 0, lines: 0, coarse: false } }\n\n const key = JSON.stringify([jobId, base.jobId, path])\n let diff = this.#diffs.get(key)\n if (!diff) {\n diff = diffHunks(beforeContent, afterContent ?? '')\n this.#diffs.set(key, diff)\n // A few recent diffs cover paging through the open file and switching back to the last one.\n if (this.#diffs.size > 4) this.#diffs.delete(this.#diffs.keys().next().value!)\n }\n await this.#logCommand('readDiff', `read the diff of ${path}`)\n\n return { ...pageHunks({ hunks: diff.hunks, cursor, limit }), hasBase: true, stats: diff.stats }\n }\n}\n\nconst openWebSocketRpc: OpenRpc = ({ url, token, instanceId, agent }) => {\n // Node's `WebSocket` takes undici's `headers` option, which the DOM typing leaves out.\n const NodeWebSocket = WebSocket as unknown as new (url: URL, init: { headers: Record<string, string> }) => WebSocket\n const socket = new NodeWebSocket(url, { headers: { Authorization: `Bearer ${token}`, [AGENT_INSTANCE_HEADER]: instanceId } })\n const timer = setTimeout(() => socket.close(3008, 'Connection timeout'), OPEN_TIMEOUT_MS)\n socket.addEventListener('open', () => clearTimeout(timer), { once: true })\n\n const closed = new Promise<Awaited<Rpc['closed']>>((resolve) => {\n socket.addEventListener('close', ({ code, reason }) => resolve({ code, reason }), { once: true })\n // Node fires only `error` when the handshake itself fails.\n socket.addEventListener('error', () => {\n if (socket.readyState !== WebSocket.OPEN) resolve({ code: 1006, reason: '' })\n })\n }).finally(() => clearTimeout(timer))\n\n const studio = newWebSocketRpcSession<StudioApi>(socket, agent)\n studio.onRpcBroken(() => socket.close())\n\n return {\n studio,\n closed,\n close: () => {\n studio[Symbol.dispose]()\n socket.close()\n },\n }\n}\n\nasync function runSession({ options, openRpc, url, instanceId }: { options: ResolvedOptions; openRpc: OpenRpc; url: URL; instanceId: string }) {\n const { hooks, signal, heartbeatInterval, studioUrl, version } = options\n const token = typeof options.token === 'function' ? await options.token() : options.token\n if (signal?.aborted) return { code: 1000, reason: '', connected: false }\n const session: Session = { connected: Promise.withResolvers(), closed: false }\n const agent = new Agent({ options, session })\n const rpc = openRpc({ url, token, instanceId, agent })\n signal?.addEventListener('abort', rpc.close, { once: true })\n let timer: ReturnType<typeof setTimeout> | undefined\n\n // Races each ping against a deadline, so a half-open socket can't hang it forever.\n const heartbeat = async (): Promise<void> => {\n let deadline: ReturnType<typeof setTimeout> | undefined\n const timedOut = new Promise<boolean>((resolve) => (deadline = setTimeout(resolve, PING_TIMEOUT_MS, true)))\n const failed = await Promise.race([\n Promise.resolve(rpc.studio.ping()).then(\n () => false,\n () => true,\n ),\n timedOut,\n ])\n clearTimeout(deadline)\n if (failed) return rpc.close()\n if (!session.closed) timer = setTimeout(heartbeat, heartbeatInterval)\n }\n\n void session.connected.promise.then(\n async (info) => {\n await emit(hooks, 'studio:connected', { ...info, url: studioUrl, versions: { studio: info.studioVersion, kubb: kubbVersion, agent: version } })\n if (!session.closed) timer = setTimeout(heartbeat, heartbeatInterval)\n },\n () => {},\n )\n\n const close = await rpc.closed\n session.closed = true\n clearTimeout(timer)\n signal?.removeEventListener('abort', rpc.close)\n session.connected.reject(new Error('The socket closed before Studio called connect()'))\n // Captured and aborted before the warning, so a slow listener neither keeps the run going nor\n // sees it finish and clear `session.active` first.\n const active = session.active\n if (active) {\n active.abort()\n await emit(hooks, 'studio:warn', { message: 'Canceled the running generation: the connection to Kubb Studio closed' })\n }\n await active?.settled\n session.install?.abort()\n await session.install?.settled\n await agent.clear()\n\n return { ...close, connected: session.info !== undefined }\n}\n\n/**\n * The connection loop with a swappable transport. {@link connectAgent} passes a real WebSocket.\n */\n/** The entry Studio named by position or `name`, else the first. `undefined` for one the file does not have. */\nfunction pickConfig(configs: Array<Config>, ref: ConfigRef | undefined): Config | undefined {\n if (typeof ref === 'string') return configs.find((config) => config.name === ref)\n if (ref !== undefined && !Number.isSafeInteger(ref)) return undefined\n return configs[ref ?? 0]\n}\n\n/** Whether `text` parses as JSON, so a pasted document is saved under the matching extension. */\nfunction isJson(text: string): boolean {\n try {\n JSON.parse(text)\n return true\n } catch {\n return false\n }\n}\n\n/** The input path or URL Studio may show: no inline document, and no credentials from a URL. */\nfunction reportedInput(input: Config['input']): string | undefined {\n if (typeof input !== 'string') return undefined\n const kind = getInputKind(input)\n if (kind === 'inline') return undefined\n // The scp-style git form (`git+git@host:org/repo.git`) is no URL and carries no password.\n if ((kind !== 'url' && kind !== 'git') || !URL.canParse(input)) return input\n const url = new URL(input)\n url.username = ''\n url.password = ''\n return url.href\n}\n\n/** A JSON copy of one resolved entry, each extension named by the package its manifest is in. */\nfunction toEntryView(config: Config, extensions: InstalledExtensions): ConfigEntryView {\n const input = reportedInput(config.input)\n return {\n ...(config.name !== undefined && { name: config.name }),\n ...(input !== undefined && { input }),\n output: config.output.path,\n outputOptions: toJSONOptions(pickOutput(config.output)),\n plugins: config.plugins.map((plugin) => ({\n name: toStudioName({ name: resolveMeta(plugin).name, extensions }),\n options: toJSONOptions(plugin.options),\n })),\n adapter: config.adapter && {\n name: toStudioName({ name: resolveMeta(config.adapter).name, extensions, kind: 'adapter' }),\n options: toJSONOptions(config.adapter.options),\n },\n parsers: config.parsers.map((parser) => ({\n name: toStudioName({ name: resolveMeta(parser).name, extensions, kind: 'parser' }),\n options: toJSONOptions(parser.options),\n })),\n }\n}\n\nexport async function runAgent({ options, openRpc }: { options: ConnectAgentOptions; openRpc: OpenRpc }): Promise<void> {\n const root = options.root ?? process.cwd()\n const resolved: ResolvedOptions = {\n ...options,\n studioUrl: options.studioUrl ?? defaultStudioUrl,\n root,\n agentType: options.agentType ?? 'user',\n configFile: path.resolve(root, options.configPath),\n permissions: {\n allowWrite: false,\n allowConfigEdit: false,\n allowInstall: false,\n allowUpdate: false,\n allowRemove: false,\n allowSaveInput: false,\n allowFileRefs: false,\n allowExec: false,\n allowRead: false,\n allowReadAst: false,\n ...options.permissions,\n },\n hooks: options.hooks ?? new Hookable<KubbHooks>(),\n maxRetryDelay: options.maxRetryDelay ?? MAX_RETRY_DELAY_MS,\n heartbeatInterval: Math.min(options.heartbeatInterval ?? HEARTBEAT_INTERVAL_MS, MAX_HEARTBEAT_INTERVAL_MS),\n }\n const { studioUrl, hooks, signal, maxRetryDelay } = resolved\n const url = secureUrl({ studioUrl, path: AGENT_SOCKET_PATH, socket: true })\n // One per call, so a reconnect is the same process to Studio and a restart is a new one.\n const instanceId = randomUUID()\n let attempt = 0\n\n while (!signal?.aborted) {\n const { code, reason, connected } = await runSession({ options: resolved, openRpc, url, instanceId })\n if (signal?.aborted) return\n await emit(hooks, 'studio:disconnected', { code, reason })\n\n if (code === AgentCloseCode.UNAUTHORIZED) throw new InvalidAgentTokenError(studioUrl)\n if (code === AgentCloseCode.INCOMPATIBLE) throw new IncompatibleAgentError({ studioUrl, detail: reason })\n if (code === AgentCloseCode.SUPERSEDED) return\n\n // Reset only once Studio called connect(), so a socket that opens and closes again backs off.\n if (connected) attempt = 0\n const delayMs = Math.random() * Math.min(1_000 * 2 ** Math.min(attempt++, 16), maxRetryDelay)\n await emit(hooks, 'studio:reconnecting', { delayMs })\n await delay(delayMs, undefined, { signal }).catch(() => {})\n }\n}\n\n/**\n * Connects this project to Kubb Studio and serves its commands until `signal` aborts. Reconnects\n * with jittered backoff, and resolves when another process of the agent takes over. Rejects with\n * {@link InvalidAgentTokenError} so the host can pair again, or {@link IncompatibleAgentError}.\n *\n * @example\n * ```ts\n * const hooks = new Hookable<KubbHooks>()\n * hooks.hook('studio:connected', ({ agentSlug }) => console.log(`Connected as ${agentSlug}`))\n *\n * await connectAgent({ token, configPath: 'kubb.config.ts', loadConfigs, version: '1.0.0', hooks, signal })\n * ```\n */\nexport function connectAgent(options: ConnectAgentOptions): Promise<void> {\n return runAgent({ options, openRpc: openWebSocketRpc })\n}\n","import { hash } from 'node:crypto'\nimport { setTimeout as delay } from 'node:timers/promises'\nimport { toError } from '@internals/utils'\nimport { Diagnostics } from '@kubb/core'\nimport { ofetch } from 'ofetch'\nimport { getAgentPublicKey, getTokenRefreshPayload, signAgentPayload } from './agentKey.ts'\nimport { InvalidAgentTokenError } from './connect.ts'\nimport { AgentSignatureContext, type TokenRefreshProof } from './protocol.ts'\nimport { defaultStudioUrl, secureUrl } from './url.ts'\n\n/**\n * RFC 8628 device-authorization response from Studio's `/api/auth/device/code` endpoint.\n * Field names match the RFC; the CLI polls with `device_code` and shows `user_code` to the user.\n */\nexport type PairingSession = {\n device_code: string\n user_code: string\n verification_uri: string\n verification_uri_complete: string\n expires_in: number\n interval: number\n}\n\ntype PairingResult = {\n /**\n * Bearer token for this machine. Write credentials with mode 0600 and never log the value.\n */\n token: string\n agent: {\n /**\n * Stable agent id in Studio.\n */\n id: string\n /**\n * Short slug used in logs and the UI (for example `brave-otter`).\n */\n slug: string\n /**\n * Display name chosen at pairing time.\n */\n name: string\n /**\n * This agent's organization slug, absent for a sandbox or global agent, which has none.\n */\n organizationSlug?: string\n }\n}\n\n/**\n * What this machine registers as. Any member may approve `cli` (`kubb studio`); only an admin may\n * approve `user` and `sandbox` (the Docker image). A `ci` agent never pairs.\n */\ntype PairingAgentType = 'cli' | 'user' | 'sandbox'\n\n/** Labels, not secrets: a person approving the code in the browser is what authorizes a pairing. */\nconst CLIENT_IDS = { cli: 'kubb-cli', agent: 'kubb-agent' } as const\n\n/**\n * Thrown when a caller aborts `startPairing` or `pollForPairingToken` through their `signal`, such\n * as a `kubb studio` shutdown mid-pairing. Distinct from a denial or an expired code, so a host can\n * exit quietly instead of reporting a pairing failure.\n */\nexport class PairingCanceledError extends Error {\n constructor() {\n super('Pairing was canceled')\n this.name = 'PairingCanceledError'\n }\n}\n\n/** Thrown when the code expired unapproved. A fresh code can still succeed. */\nexport class PairingExpiredError extends Error {\n constructor(message = 'The pairing code expired, pair again') {\n super(message)\n this.name = 'PairingExpiredError'\n }\n}\n\n/** Thrown when the pairing was denied in the browser, including by the organization's agent limit. */\nexport class PairingDeniedError extends Error {\n constructor(message = 'Pairing was denied in the browser') {\n super(message)\n this.name = 'PairingDeniedError'\n }\n}\n\ntype StartPairingOptions = {\n studioUrl?: string\n type: PairingAgentType\n /**\n * Display name for the agent, usually the project or machine name.\n */\n name: string\n hostname: string\n /**\n * A stable secret the host keeps for this machine. Studio stores its hash against the agent, so\n * the same machine pairing again rotates one agent's token instead of creating a second agent.\n */\n machineId: string\n /**\n * The agent key from `generateAgentKey`. Only its public half is sent.\n */\n privateKey?: string\n /**\n * Aborting this cancels the request in flight and rejects with {@link PairingCanceledError}.\n */\n signal?: AbortSignal\n}\n\n/**\n * Asks Studio for a pairing code, sending the hashed machine id with it.\n */\nexport async function startPairing({\n studioUrl = defaultStudioUrl,\n type,\n name,\n hostname,\n machineId,\n privateKey,\n signal,\n}: StartPairingOptions): Promise<PairingSession> {\n try {\n const pairing = await ofetch<PairingSession>(secureUrl({ studioUrl, path: '/api/auth/device/code' }).href, {\n method: 'POST',\n body: {\n client_id: type === 'cli' ? CLIENT_IDS.cli : CLIENT_IDS.agent,\n name,\n hostname,\n machine_token: hash('sha256', machineId),\n agent_kind: type === 'cli' ? undefined : type,\n public_key: privateKey ? getAgentPublicKey(privateKey) : undefined,\n },\n signal,\n })\n if (typeof pairing?.device_code !== 'string')\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: 'Kubb Studio returned no pairing code',\n help: 'Try again later. If it keeps failing, check the Kubb Studio status.',\n })\n\n return pairing\n } catch (error) {\n if (signal?.aborted) {\n throw new PairingCanceledError()\n }\n\n throw error\n }\n}\n\ntype PollOptions = {\n studioUrl?: string\n session: PairingSession\n /**\n * Aborting this stops polling and rejects with {@link PairingCanceledError}, whether the abort\n * lands between polls or during the wait for the next one.\n */\n signal?: AbortSignal\n /** Called when a poll could not reach Studio. Polling carries on. */\n onRetry?: (error: Error) => void\n}\n\ntype PollError = 'authorization_pending' | 'slow_down' | 'expired_token' | 'access_denied' | 'invalid_grant'\n\ntype PollResponse =\n | PairingResult\n | {\n error: PollError | string\n /**\n * Why, when Studio has something more useful to say than the RFC code. An approval that hits\n * the organization's agent limit comes back as `access_denied` with the limit spelled out.\n */\n error_description?: string\n }\n\nfunction isPairingResult(response: PollResponse): response is PairingResult {\n return 'token' in response && typeof response.token === 'string'\n}\n\n/**\n * Polls until the user approves or denies, honoring the server's `slow_down` back-off.\n *\n * Studio's own endpoint is used rather than the auth layer's `/device/token`, because an approved\n * Kubb pairing is worth an agent bearer token, not a user session.\n *\n * @throws {PairingExpiredError} when the code expires before anyone approves it.\n * @throws {PairingDeniedError} when the pairing is denied in the browser.\n * @throws {PairingCanceledError} when `signal` aborts.\n */\nexport async function pollForPairingToken({ studioUrl = defaultStudioUrl, session, signal, onRetry }: PollOptions): Promise<PairingResult> {\n // Both fields cross the network, so neither is trusted as-is: a missing or zero `interval` would\n // spin the poll loop, and a missing or zero `expires_in` would expire the code before the first\n // poll. `> 0` is also false for `NaN` and for a missing field, so it doubles as the type guard.\n const deadline = Date.now() + (session.expires_in > 0 ? session.expires_in : 600) * 1000\n let intervalMs = (session.interval > 0 ? session.interval : 5) * 1000\n\n while (Date.now() < deadline) {\n if (signal?.aborted) {\n throw new PairingCanceledError()\n }\n\n try {\n await delay(intervalMs, undefined, { signal })\n } catch {\n throw new PairingCanceledError()\n }\n\n let response: PollResponse\n try {\n // A denial, an expiry, and \"not yet\" all come back as 4xx with a body to switch on.\n const { status, _data } = await ofetch.raw<PollResponse>(secureUrl({ studioUrl, path: '/api/agent/token' }).href, {\n method: 'POST',\n body: { device_code: session.device_code },\n signal,\n ignoreResponseError: true,\n })\n if (status >= 500 || !_data || typeof _data !== 'object')\n throw new Diagnostics.Error({\n code: Diagnostics.code.inputRequestFailed,\n severity: 'error',\n message: `Kubb Studio answered with status ${status}`,\n help: 'Try again later.',\n })\n response = _data\n } catch (error) {\n if (signal?.aborted) {\n throw new PairingCanceledError()\n }\n\n // Studio can be briefly unreachable (a deploy) while the code is still valid, so retry.\n onRetry?.(toError(error))\n continue\n }\n\n if (isPairingResult(response)) {\n return response\n }\n\n if (!('error' in response) || typeof response.error !== 'string') {\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: 'Kubb Studio returned an empty pairing response, pair again',\n })\n }\n\n if (response.error === 'authorization_pending') {\n continue\n }\n\n if (response.error === 'slow_down') {\n intervalMs += 5_000\n continue\n }\n\n if (response.error === 'access_denied') {\n throw new PairingDeniedError(response.error_description)\n }\n\n if (response.error === 'expired_token' || response.error === 'invalid_grant') {\n throw new PairingExpiredError(response.error_description)\n }\n\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: response.error_description ?? `Pairing failed (${response.error})`,\n help: 'Pair again with `kubb studio login`.',\n })\n }\n\n throw new PairingExpiredError()\n}\n\ntype PairAgentOptions = StartPairingOptions & {\n /** Shows the code to whoever approves it. Called again for each fresh code. */\n onCode: (session: PairingSession, attempt: number) => void | Promise<void>\n /** Called when a poll could not reach Studio. Polling carries on. */\n onRetry?: (error: Error) => void\n /**\n * Codes to ask for in total when one expires unapproved. A denial or abort ends it at once.\n * @default 1\n */\n maxAttempts?: number\n}\n\n/**\n * Pairs this machine with Studio: asks for a code, hands it to the host to show, and waits for approval.\n */\nexport async function pairAgent({ onCode, onRetry, maxAttempts = 1, ...options }: PairAgentOptions): Promise<PairingResult> {\n for (let attempt = 1; ; attempt++) {\n const session = await startPairing(options)\n await onCode(session, attempt)\n\n try {\n return await pollForPairingToken({ studioUrl: options.studioUrl, session, signal: options.signal, onRetry })\n } catch (error) {\n if (!(error instanceof PairingExpiredError) || attempt >= maxAttempts) {\n throw error\n }\n }\n }\n}\n\nconst REFRESH_TIMEOUT_MS = 15_000\n\ntype RefreshAgentTokenOptions = {\n studioUrl?: string\n token: string\n /**\n * The secret the machine paired with.\n */\n machineId: string\n /**\n * The stored agent key, which signs the request.\n */\n privateKey?: string\n signal?: AbortSignal\n /**\n * How long to wait for an answer, in milliseconds.\n *\n * @default 15000\n */\n timeout?: number\n}\n\n/**\n * Trades the agent's token for a new one. The old token stops working at once, so store the new\n * one first. Resolves `null` when there is nothing to refresh, and rejects with\n * {@link InvalidAgentTokenError} when the token is refused.\n */\nexport async function refreshAgentToken({\n studioUrl = defaultStudioUrl,\n token,\n machineId,\n privateKey,\n signal,\n timeout = REFRESH_TIMEOUT_MS,\n}: RefreshAgentTokenOptions): Promise<string | null> {\n const deadline = AbortSignal.timeout(timeout)\n const signedAt = Date.now()\n const proof: TokenRefreshProof | undefined = privateKey\n ? {\n signed_at: signedAt,\n signature: signAgentPayload({ privateKey, context: AgentSignatureContext.TOKEN_REFRESH, payload: getTokenRefreshPayload({ token, signedAt }) }),\n }\n : undefined\n const { status, _data } = await ofetch\n .raw<{ token?: unknown }>(secureUrl({ studioUrl, path: '/api/agent/token/refresh' }).href, {\n method: 'POST',\n headers: { Authorization: `Bearer ${token}` },\n body: { machine_id: machineId, ...proof },\n signal: signal ? AbortSignal.any([signal, deadline]) : deadline,\n ignoreResponseError: true,\n // A second attempt would send a token the first may have retired.\n retry: 0,\n })\n .catch((error: unknown) => {\n if (deadline.aborted && !signal?.aborted)\n throw new Diagnostics.Error({\n code: Diagnostics.code.inputRequestFailed,\n severity: 'error',\n message: `Kubb Studio did not answer the token refresh within ${timeout} ms`,\n help: 'The token is unchanged. Try again later.',\n })\n throw error\n })\n\n if (status === 404 || status === 409) return null\n if (status === 401) throw new InvalidAgentTokenError(studioUrl)\n if (status < 200 || status >= 300)\n throw new Diagnostics.Error({\n code: Diagnostics.code.inputRequestFailed,\n severity: 'error',\n message: `Kubb Studio answered the token refresh with status ${status}`,\n help: 'The token is unchanged. Try again later.',\n })\n if (typeof _data?.token !== 'string' || !_data.token)\n throw new Diagnostics.Error({ code: Diagnostics.code.unknown, severity: 'error', message: 'Kubb Studio answered the token refresh without a token' })\n\n return _data.token\n}\n","import { tmpdir } from 'node:os'\nimport { join, resolve } from 'node:path'\nimport { gzipSync } from 'node:zlib'\nimport { getErrorMessage, mkdir, mkdtemp, read, rm, writeRaw } from '@internals/utils'\nimport { type Config, Diagnostics, fsStorage, type Hookable, Kubb, type KubbHooks, readInstalledPackages, resolveMeta } from '@kubb/core'\nimport { ofetch } from 'ofetch'\nimport { generationFailure, hashOf, relativeStoragePath } from './generations.ts'\nimport { MAX_SNAPSHOT_BYTES, type PublishedSnapshot, type SnapshotUploadMetadata } from './protocol.ts'\nimport { toPackageName } from './resolveConfig.ts'\nimport { defaultStudioUrl, secureUrl } from './url.ts'\n\nconst UPLOAD_TIMEOUT_MS = 120_000\n\n// Plugins whose output a snapshot carries without depending on the plugin package.\nconst BUNDLED_DEPENDENCIES = ['@kubb/plugin-barrel']\n\ntype SnapshotFiles = Record<string, string>\ntype SnapshotPackage = { name: string; version: string; peerDependencies: Record<string, string> }\n\n/**\n * Maps a generated file to its path in the package, from its `src`/`dist` segment on, without `..` parts that could escape it.\n */\nfunction packagePath(filePath: string): string {\n const normalized = filePath.replaceAll('\\\\', '/')\n const relativePath = normalized.match(/\\/(?:src|dist)\\/.*$/)?.[0] ?? normalized\n return relativePath\n .split('/')\n .filter((part) => part && part !== '.' && part !== '..')\n .join('/')\n}\n\n/**\n * Splits a tar path into the 100-byte USTAR `name` and the 155-byte `prefix`, and throws for a path that fits neither.\n */\nfunction splitEntryPath(path: string): { name: string; prefix: string } {\n if (Buffer.byteLength(path) <= 100) return { name: path, prefix: '' }\n for (let i = path.lastIndexOf('/'); i > 0; i = path.lastIndexOf('/', i - 1)) {\n const prefix = path.slice(0, i)\n const name = path.slice(i + 1)\n if (Buffer.byteLength(prefix) <= 155 && Buffer.byteLength(name) <= 100) return { name, prefix }\n }\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `Snapshot path is too long for a tar entry: ${path}`,\n help: 'Shorten the output path or the generated file names.',\n })\n}\n\nfunction header(path: string, size: number): Buffer {\n const { name, prefix } = splitEntryPath(path)\n const value = Buffer.alloc(512)\n value.write(name)\n value.write('0000644\\0', 100)\n for (const offset of [108, 116, 265, 297]) value.write('0000000\\0', offset)\n value.write(`${size.toString(8).padStart(11, '0')}\\0`, 124)\n // npm's fixed mtime, so the same files always pack to the same integrity.\n value.write('03560116604\\0', 136)\n value.fill(32, 148, 156)\n value.write('0', 156)\n value.write('ustar\\0', 257)\n value.write('00', 263)\n value.write(prefix, 345)\n const checksum = value.reduce((sum, byte) => sum + byte, 0)\n value.write(`${checksum.toString(8).padStart(6, '0')}\\0 `, 148)\n return value\n}\n\n/**\n * Loads `tsdown` on first use. It is an optional peer dependency: it is large, and only snapshots need it.\n */\nexport async function loadTsdown(load = () => import('tsdown')): Promise<typeof import('tsdown')> {\n try {\n return await load()\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ERR_MODULE_NOT_FOUND' || !(error as Error).message.includes(\"'tsdown'\")) throw error\n throw new Diagnostics.Error({\n code: Diagnostics.code.missingDependency,\n severity: 'error',\n message: 'Missing dependency: tsdown. A snapshot builds its dist files with tsdown, which Kubb does not install by default.',\n help: 'Run `npm i -D tsdown` in the project, then try again.',\n })\n }\n}\n\n/**\n * Packs a generation's files into a gzipped, npm-installable tarball: a `package/` root with the\n * generated sources, a `tsdown`-built `dist/` (esm + cjs), and a `package.json` manifest.\n */\nexport async function createSnapshotPackage({ files, packageInfo }: { files: SnapshotFiles; packageInfo: SnapshotPackage }): Promise<Buffer> {\n const sources = new Map<string, { name: string; content: string }>()\n for (const [name, content] of Object.entries(files)) {\n const path = packagePath(name)\n const owner = sources.get(path)?.name\n if (owner)\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `Snapshot has two generated files that sanitize to the same path \"package/${path}\": \"${owner}\" and \"${name}\"`,\n help: 'Rename one of the generated files, for example with a plugin resolver.',\n })\n sources.set(path, { name, content })\n }\n const root = await mkdtemp(join(tmpdir(), 'kubb-snapshot-'))\n const dist = join(root, 'dist')\n\n try {\n await mkdir(dist)\n await Promise.all(\n [...sources].map(async ([path, { content }]) => {\n await writeRaw(join(root, path), content)\n }),\n )\n const entry = [...sources.keys()].filter((path) => /\\.(?:[cm]?[jt]sx?)$/.test(path)).map((path) => join(root, path))\n if (entry.length) {\n const { build } = await loadTsdown()\n // `fixedExtension` emits the `.mjs`/`.cjs` the manifest names, whatever \"type\" the host's own package.json sets.\n await build({\n entry,\n outDir: dist,\n format: ['esm', 'cjs'],\n dts: false,\n sourcemap: false,\n unbundle: true,\n report: false,\n logLevel: 'silent',\n fixedExtension: true,\n })\n }\n const built = await fsStorage().readKeys(dist)\n // Only `@kubb/plugin-barrel` produces a `dist/index.*` for `main`, `module`, and `exports['.']` to name.\n const hasBarrel = built.includes('index.mjs') && built.includes('index.cjs')\n const manifest = {\n ...packageInfo,\n type: 'module',\n ...(hasBarrel ? { main: './dist/index.cjs', module: './dist/index.mjs' } : {}),\n // `exports` denies any subpath it does not list, so the wildcard keeps each generated file importable.\n exports: {\n ...(hasBarrel ? { '.': { import: './dist/index.mjs', require: './dist/index.cjs' } } : {}),\n './*': { import: './dist/*.mjs', require: './dist/*.cjs' },\n },\n }\n const entries = new Map<string, string>([\n ['package.json', JSON.stringify(manifest, null, 2)],\n ...[...sources].map(([path, { content }]) => [path, content] as const),\n ...(await Promise.all(built.map(async (key) => [`dist/${key}`, await read(join(dist, key))] as const))),\n ])\n const chunks = [...entries].flatMap(([path, content]) => {\n const bytes = Buffer.from(content)\n return [header(`package/${path}`, bytes.length), bytes, Buffer.alloc((512 - (bytes.length % 512)) % 512)]\n })\n return gzipSync(Buffer.concat([...chunks, Buffer.alloc(1024)]))\n } finally {\n await rm(root, { recursive: true, force: true })\n }\n}\n\ntype CreateSnapshotOptions = Omit<SnapshotUploadMetadata, 'hashes' | 'peerDependencies'> & {\n studioUrl?: string\n /**\n * Organization CI API key, sent as `x-api-key`.\n */\n apiKey: string\n /**\n * Every entry of the project's Kubb config, generated like `kubb generate`: formatter, linter, and `output.postGenerate` included.\n * One package holds the output of them all.\n */\n configs: Array<Config>\n hooks?: Hookable<KubbHooks>\n signal?: AbortSignal\n}\n\n/**\n * Generates the project, packs it as an npm tarball, and publishes it to Studio in one `POST /api/snapshots` request.\n *\n * @example\n * ```ts\n * const { url } = await createSnapshot({ apiKey: process.env.KUBB_TOKEN!, configs, id: 'gh:123:pr-4', name: 'acme/api#4', packageName: '@acme/api', version: '1.0.0' })\n * ```\n */\nexport async function createSnapshot({\n studioUrl = defaultStudioUrl,\n apiKey,\n configs,\n hooks,\n signal,\n ...metadata\n}: CreateSnapshotOptions): Promise<PublishedSnapshot> {\n const url = secureUrl({ studioUrl, path: '/api/snapshots' })\n const buildConfigs = configs.map((config) => ({ ...config, storage: fsStorage() }))\n const failures: Array<unknown> = []\n // Each package path with the file on disk it comes from.\n const sources = new Map<string, string>()\n // A failing entry does not stop the others, like `kubb generate`, so one run reports every failure.\n for await (const { success, error, diagnostics, files, kubb } of Kubb.generate(buildConfigs, { hooks, signal })) {\n if (!success) {\n failures.push(error ?? generationFailure(diagnostics))\n continue\n }\n const { root } = kubb.config\n for (const file of files) {\n const path = relativeStoragePath({ root, filePath: file.path })\n const source = resolve(root, path)\n const owner = sources.get(path)\n if (owner && owner !== source)\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `Snapshot has two generated files at \"${path}\": \"${owner}\" and \"${source}\"`,\n help: 'Give the config entries the same `root`, or output paths that do not overlap.',\n })\n sources.set(path, source)\n }\n }\n // Nothing is published from a partial generation.\n if (failures.length === 1) throw failures[0]\n if (failures.length) throw new AggregateError(failures, failures.map(getErrorMessage).join('\\n'))\n\n const storage = fsStorage()\n const files = Object.fromEntries(\n await Promise.all(\n [...sources].map(async ([path, source]) => {\n const content = await storage.readItem(source)\n if (content === null)\n throw new Diagnostics.Error({\n code: Diagnostics.code.internalError,\n severity: 'error',\n message: `The generation listed ${path} but did not keep its content`,\n })\n return [path, content] as const\n }),\n ),\n )\n const pluginNames = [...new Set(configs.flatMap((config) => config.plugins.map((plugin) => resolveMeta(plugin).name)))]\n const roots = [...new Set(configs.map((config) => config.root))]\n const installed = (\n await Promise.all(roots.map((root) => readInstalledPackages({ root, packages: pluginNames.map(toPackageName), resolveFrom: ['kubb'] })))\n ).flat()\n // A third-party plugin is found by the manifest its package ships, as `@kubb/plugin-x` only names a built-in.\n const packageOf = (name: string) => installed.find(({ manifest }) => manifest?.kind === 'plugin' && manifest.name === name)?.package ?? toPackageName(name)\n const names = [...new Set(pluginNames.map(packageOf))]\n const peerDependencies = Object.fromEntries(installed.flatMap(({ package: name, version }) => (names.includes(name) && version ? [[name, version]] : [])))\n // The package would declare no version for a plugin that is not installed.\n const missing = names.filter((name) => !(name in peerDependencies) && !BUNDLED_DEPENDENCIES.includes(name))\n if (missing.length)\n throw new Diagnostics.Error({\n code: Diagnostics.code.missingDependency,\n severity: 'error',\n message: `Missing dependencies: ${missing.join(', ')}`,\n help: 'Install the listed plugin packages in the project.',\n })\n\n const bytes = await createSnapshotPackage({ files, packageInfo: { name: metadata.packageName, version: metadata.version, peerDependencies } })\n if (bytes.length > MAX_SNAPSHOT_BYTES) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `The snapshot is ${Math.ceil(bytes.length / 1024 / 1024)} MB, over the ${MAX_SNAPSHOT_BYTES / 1024 / 1024} MB limit`,\n help: 'Generate fewer files, for example with `include` or `exclude` on the plugins.',\n })\n }\n\n const hashes = Object.fromEntries(Object.entries(files).map(([path, content]) => [path, hashOf(content)]))\n const body = new FormData()\n body.set('metadata', JSON.stringify({ ...metadata, hashes, peerDependencies } satisfies SnapshotUploadMetadata))\n body.set('tarball', new Blob([new Uint8Array(bytes)], { type: 'application/gzip' }), 'snapshot.tgz')\n\n const timeout = AbortSignal.timeout(UPLOAD_TIMEOUT_MS)\n // A redirect would forward the CI key and tarball to wherever it points.\n const { ok, status, _data } = await ofetch.raw<{ snapshot?: PublishedSnapshot; message?: string; data?: { upgradeUrl?: string } }>(url.href, {\n method: 'POST',\n headers: { 'x-api-key': apiKey },\n body,\n redirect: 'error',\n signal: signal ? AbortSignal.any([signal, timeout]) : timeout,\n ignoreResponseError: true,\n })\n if (!ok) {\n const upgrade = _data?.data?.upgradeUrl ? ` Upgrade at ${_data.data.upgradeUrl}.` : ''\n throw new Diagnostics.Error({\n code: Diagnostics.code.inputRequestFailed,\n severity: 'error',\n message: `Kubb Studio refused the snapshot (status ${status})${_data?.message ? `: ${_data.message}` : ''}.${upgrade}`,\n help: 'Check the API key and your plan, then try again.',\n })\n }\n if (!_data?.snapshot)\n throw new Diagnostics.Error({\n code: Diagnostics.code.inputRequestFailed,\n severity: 'error',\n message: `Kubb Studio returned no snapshot (status ${status})`,\n help: 'Try again later.',\n })\n return _data.snapshot\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAS,YAAY,EAAE,SAAS,WAAwE;CACtG,OAAO,OAAO,KAAK,GAAG,QAAQ,IAAI,WAAW,MAAM;AACrD;;;;AAKA,SAAgB,mBAA2B;CACzC,OAAO,oBAAoB,SAAS,CAAC,CAAC,WAAW,OAAO;EAAE,QAAQ;EAAO,MAAM;CAAQ,CAAC,CAAC,CAAC,SAAS;AACrG;;;;AAKA,SAAgB,kBAAkB,YAA4B;CAC5D,OAAO,gBAAgB,UAAU,CAAC,CAAC,OAAO,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,EAAE,IAAI,QAAQ,UAAU,MAAM,OAAO,IAAwF,IAAI,MAAM;EAC3I,QAAQ;EACR,SAAS,EAAE,aAAa,OAAO;EAC/B;EACA,UAAU;EACV,QAAQ,SAAS,YAAY,IAAI,CAAC,QAAQ,OAAO,CAAC,IAAI;EACtD,qBAAqB;CACvB,CAAC;CACD,IAAI,CAAC,IAAI;EACP,MAAM,UAAU,OAAO,MAAM,aAAa,eAAe,MAAM,KAAK,WAAW,KAAK;EACpF,MAAM,IAAI,YAAY,MAAM;GAC1B,MAAM,YAAY,KAAK;GACvB,UAAU;GACV,SAAS,4CAA4C,OAAO,GAAG,OAAO,UAAU,KAAK,MAAM,YAAY,GAAG,GAAG;GAC7G,MAAM;EACR,CAAC;CACH;CACA,IAAI,CAAC,OAAO,UACV,MAAM,IAAI,YAAY,MAAM;EAC1B,MAAM,YAAY,KAAK;EACvB,UAAU;EACV,SAAS,4CAA4C,OAAO;EAC5D,MAAM;CACR,CAAC;CACH,OAAO,MAAM;AACf"}
1
+ {"version":3,"file":"index.js","names":["mkdir","process","process","version","kubbVersion","writeFile","NodeWebSocket","delay","delay"],"sources":["../src/agentKey.ts","../../../internals/utils/src/promise.ts","../../../internals/utils/src/casing.ts","../../../internals/utils/src/errors.ts","../../../internals/utils/src/runtime.ts","../../../internals/utils/src/fs.ts","../package.json","../../../internals/shared/src/constants.ts","../../../internals/shared/src/configFile/ast.ts","../../../internals/shared/src/configFile/rules.ts","../../../internals/shared/src/configFile/text.ts","../../../internals/shared/src/configFile/configFile.ts","../src/diff.ts","../src/generations.ts","../src/generationEvents.ts","../src/publicFetch.ts","../src/resolveConfig.ts","../src/url.ts","../src/connect.ts","../src/pair.ts","../src/snapshot.ts"],"sourcesContent":["import { createPublicKey, generateKeyPairSync, hash, sign, verify } from 'node:crypto'\nimport type { AgentSignatureContext } from './protocol.ts'\n\nfunction signedBytes({ context, payload }: { context: AgentSignatureContext; payload: string }): Buffer {\n return Buffer.from(`${context}\\n${payload}`, 'utf8')\n}\n\n/**\n * Creates the agent's Ed25519 key as a PKCS #8 PEM string, to store with the token.\n */\nexport function generateAgentKey(): string {\n return generateKeyPairSync('ed25519').privateKey.export({ format: 'pem', type: 'pkcs8' }).toString()\n}\n\n/**\n * Returns the raw 32-byte public key of `privateKey`, base64url without padding.\n */\nexport function getAgentPublicKey(privateKey: string): string {\n return createPublicKey(privateKey).export({ format: 'jwk' }).x!\n}\n\n/**\n * Signs `payload` for `context` and returns the Ed25519 signature in base64url.\n */\nexport function signAgentPayload({ privateKey, context, payload }: { privateKey: string; context: AgentSignatureContext; payload: string }): string {\n return sign(null, signedBytes({ context, payload }), privateKey).toString('base64url')\n}\n\n/**\n * Checks a {@link signAgentPayload} signature. Malformed input returns `false` and never throws.\n */\nexport function verifyAgentSignature({\n publicKey,\n context,\n payload,\n signature,\n}: {\n publicKey: string\n context: AgentSignatureContext\n payload: string\n signature: string\n}): boolean {\n try {\n const key = createPublicKey({ key: { kty: 'OKP', crv: 'Ed25519', x: publicKey }, format: 'jwk' })\n return verify(null, signedBytes({ context, payload }), key, Buffer.from(signature, 'base64url'))\n } catch {\n return false\n }\n}\n\nexport function getTokenRefreshPayload({ token, signedAt }: { token: string; signedAt: number }): string {\n return `${signedAt}\\n${hash('sha256', token)}`\n}\n","/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Returns the value cached under `key` in `store`, computing and storing it on the first call.\n * Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive\n * keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.\n *\n * @example\n * `const refs = memo(refCache, node, () => collectRefs(node))`\n */\nexport function memo<TKey, TValue>(store: Store<TKey, TValue>, key: TKey, compute: () => TValue): TValue {\n const cached = store.get(key)\n if (cached !== undefined || store.has(key)) return cached as TValue\n const value = compute()\n store.set(key, value)\n return value\n}\n\n/**\n * Creates a store for `memo`. With no options it is a `Map`. Each option changes one thing:\n *\n * - `weak` holds the keys weakly, in a `WeakMap`, so an entry goes away with its key.\n * - `max` bounds the store: it empties itself before the entry that would pass `max`, which keeps a\n * cache in a long-running process from growing without end. `max: 1` keeps only the last entry.\n *\n * @example\n * `const patterns = memo.create<string, RegExp>()`\n *\n * @example Freed with its key\n * `const refs = memo.create<SchemaNode, Array<string>>({ weak: true })`\n *\n * @example Bounded\n * `const names = memo.create<string, string>({ max: 100_000 })`\n *\n * @example Many values per key\n * ```ts\n * const filesByPlugin = memo.create<string, Array<string>>()\n * memo(filesByPlugin, 'plugin-ts', () => []).push('models.ts')\n * ```\n */\nfunction createStore<TKey, TValue>(options?: { weak?: false; max?: undefined }): Map<TKey, TValue>\nfunction createStore<TKey extends WeakKey, TValue>(options: { weak: true; max?: undefined }): WeakMap<TKey, TValue>\nfunction createStore<TKey, TValue>(options: { max: number; weak?: false }): Store<TKey, TValue>\nfunction createStore<TKey, TValue>({ weak, max }: { weak?: boolean; max?: number } = {}): Store<TKey, TValue> {\n if (weak) return new WeakMap<WeakKey, TValue>() as Store<TKey, TValue>\n const entry = new Map<TKey, TValue>()\n if (max === undefined) return entry\n const set = (key: TKey, value: TValue) => {\n if (entry.size >= max) entry.clear()\n entry.set(key, value)\n }\n if (max !== 1) return { has: (key) => entry.has(key), get: (key) => entry.get(key), set }\n // A key equal to the stored one but a different object, such as a copy of a string, replaces the\n // stored key, so the next lookup is an identity hit instead of a full comparison.\n const touch = (key: TKey) => {\n if (!entry.has(key)) return false\n set(key, entry.get(key) as TValue)\n return true\n }\n return { has: touch, get: (key) => (touch(key) ? entry.get(key) : undefined), set }\n}\n\nmemo.create = createStore\n\ntype ParallelOptions<TItem> = {\n /**\n * Items to work through, handed out in order.\n */\n items: ReadonlyArray<TItem>\n /**\n * How many items may be in flight at once.\n */\n limit: number\n /**\n * Runs once per item, with the item's position so a caller can report progress.\n */\n run(item: TItem, index: number): Promise<void>\n}\n\n/**\n * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each\n * takes the next item the moment it frees up instead of waiting for a batch to drain.\n *\n * @example\n * ```ts\n * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })\n * ```\n */\nexport async function inParallel<TItem>({ items, limit, run }: ParallelOptions<TItem>): Promise<void> {\n const queue = items.entries()\n\n const worker = async (): Promise<void> => {\n for (const [index, item] of queue) await run(item, index)\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()))\n}\n","import { memo } from './promise.ts'\n\ntype Options = {\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction convert(text: string, pascal: boolean): string {\n return (\n text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n // A status range such as `2xx` stays one word.\n .replace(/(\\d)(?!xx(?![a-z]))([a-z])/g, '$1 $2')\n .split(/[\\s\\-_./\\\\:]+/)\n .filter(Boolean)\n .map((word, i) => {\n if (word.length > 1 && word === word.toUpperCase()) return word\n const head = i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()\n return head + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n )\n}\n\n// Plugins case the same names on every visit. Clearing at the limit bounds a long-running host.\nconst cache = memo.create<string, string>({ max: 100_000 })\n\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const key = `${pascal ? 'P' : 'c'}${text}`\n return memo(cache, key, () => convert(text, pascal))\n}\n\n/**\n * Converts `text` to camelCase.\n *\n * @example Word boundaries\n * `camelCase('hello-world') // 'helloWorld'`\n *\n * @example With a prefix\n * `camelCase('tag', { prefix: 'create' }) // 'createTag'`\n */\nexport function camelCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n *\n * @example Word boundaries\n * `pascalCase('hello-world') // 'HelloWorld'`\n *\n * @example With a suffix\n * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`\n */\nexport function pascalCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n// A word starts at `petType`, `sensor2Reading`, and `HTTPResponse`, while `IDs` and `OAuth` stay whole\nconst wordStart = /(?<=[a-z\\d])(?=[A-Z])|(?<=[A-Z]{2})(?=[A-Z][a-z]{2})/\n\n// A segment without lowercase letters, such as `COOL` or `2D`, stays one word, so a snake_case name is left unchanged.\nfunction words(text: string): Array<string> {\n return text\n .split(/[\\s\\-_./\\\\:]+/)\n .filter(Boolean)\n .flatMap((segment) => (segment === segment.toUpperCase() ? segment : segment.split(wordStart)))\n}\n\n/**\n * Uppercases only the first character of `text`. Unlike `pascalCase` it never splits words or strips characters.\n *\n * @example\n * `capitalize('getPetById') // 'GetPetById'`\n */\nexport function capitalize(text: string): string {\n return `${text.charAt(0).toUpperCase()}${text.slice(1)}`\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * `snakeCase('helloWorld') // 'hello_world'`\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return words(`${prefix} ${text} ${suffix}`)\n .map((word) => word.replace(/[^a-zA-Z0-9]/g, '').toLowerCase())\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * `screamingSnakeCase('helloWorld') // 'HELLO_WORLD'`\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","/**\n * Coerces an unknown thrown value to an `Error` instance.\n * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.\n *\n * @example\n * ```ts\n * try { ... } catch(err) {\n * throw new Error('Build failed', { cause: toError(err) })\n * }\n * ```\n */\nexport function toError(value: unknown): Error {\n return value instanceof Error ? value : new Error(String(value))\n}\n\n/**\n * Extracts a human-readable message from any thrown value.\n *\n * @example\n * ```ts\n * getErrorMessage(new Error('oops')) // 'oops'\n * getErrorMessage('plain string') // 'plain string'\n * ```\n */\nexport function getErrorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Returns `error` followed by every error in its `cause` chain, outermost first. Stops at a\n * non-`Error` cause or a cycle.\n *\n * @example\n * ```ts\n * getErrorChain(new Error('Config failed loading', { cause: new Error('boom') })).map((error) => error.message)\n * // ['Config failed loading', 'boom']\n * ```\n */\nexport function getErrorChain(error: unknown): Array<Error> {\n const chain: Array<Error> = []\n for (let current = error; current instanceof Error && !chain.includes(current); current = current.cause) {\n chain.push(current)\n }\n return chain\n}\n","// Bun polyfills `process.versions.node`, so detection keys off the globals instead.\nconst isBun = typeof Bun !== 'undefined'\nconst isDeno = 'Deno' in globalThis\n\n/**\n * The JavaScript runtime executing the current process: its name, version and whether it is Bun.\n *\n * @example\n * ```ts\n * runtime.name // 'bun' when run with `bun kubb`, 'node' otherwise\n * ```\n */\nexport const runtime = { isBun, ...detect() } as const\n\nfunction detect(): { name: 'bun' | 'deno' | 'node'; version: string } {\n if (isBun) return { name: 'bun', version: process.versions.bun ?? '' }\n if (isDeno) return { name: 'deno', version: (globalThis as { Deno?: { version?: { deno?: string } } }).Deno?.version?.deno ?? '' }\n return { name: 'node', version: process.versions?.node ?? '' }\n}\n","import { existsSync, readFile, readFileSync, writeFile } from 'node:fs'\nimport { access, glob as globNode, mkdir } from 'node:fs/promises'\nimport { dirname, isAbsolute, join, relative, resolve } from 'node:path'\nimport { runtime } from './runtime.ts'\n\nexport { existsSync } from 'node:fs'\nexport { mkdir, mkdtemp, rm } from 'node:fs/promises'\n\n/**\n * Resolves to `true` when the file or directory at `path` exists.\n * Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.\n *\n * @example\n * ```ts\n * if (await exists('./kubb.config.ts')) {\n * const content = await read('./kubb.config.ts')\n * }\n * ```\n */\nexport async function exists(path: string): Promise<boolean> {\n if (runtime.isBun) {\n return Bun.file(path).exists()\n }\n return access(path).then(\n () => true,\n () => false,\n )\n}\n\n/**\n * Reads the file at `path` as a UTF-8 string.\n * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.\n *\n * @example\n * ```ts\n * const source = await read('./src/Pet.ts')\n * ```\n */\nexport async function read(path: string): Promise<string> {\n if (runtime.isBun) {\n return Bun.file(path).text()\n }\n // The callback API skips the `FileHandle` every `fs/promises` call opens.\n return new Promise((resolvePromise, reject) => readFile(path, { encoding: 'utf8' }, (error, data) => (error ? reject(error) : resolvePromise(data))))\n}\n\n/**\n * Reads the file at `path` as a UTF-8 string, or `null` when it does not exist or cannot be read.\n * Uses `Bun.file().text()` when running under Bun, `fs.readFileSync` otherwise.\n *\n * @example\n * ```ts\n * const stored = await readIfExists('./src/gen/Pet.ts') // null on a first run\n * ```\n */\nexport async function readIfExists(path: string): Promise<string | null> {\n if (runtime.isBun) {\n return Bun.file(path)\n .text()\n .catch(() => null)\n }\n // A small read is faster on the main thread than a thread-pool round trip, and `existsSync`\n // answers a missing file without building an error.\n if (!existsSync(path)) return null\n try {\n return readFileSync(path, 'utf8')\n } catch (_error) {\n return null\n }\n}\n\ntype WriteOptions = {\n /**\n * Previously read content, or `null` when the file does not exist.\n * Omitting this value reads the file before writing.\n */\n stored?: string | null\n /**\n * When `true`, re-reads the file immediately after writing and throws if the\n * content does not match — useful for catching write failures on unreliable file systems.\n */\n sanity?: boolean\n}\n\n/**\n * Whether `stored` already holds `source`, comparing on the trimmed text rather than the exact\n * bytes. Surrounding whitespace is what a formatter adds and what editors strip, and neither is a\n * reason to rewrite the file.\n *\n * Both sides are trimmed, so a storage that keeps bytes verbatim settles on the same answer as one\n * that normalizes what it stores. Trimming only `stored` would leave a source with leading\n * whitespace rewritten on every build, since the stored copy keeps the whitespace the comparison\n * has already dropped.\n */\nexport function matchesStored({ stored, source }: { stored: string; source: string }): boolean {\n return stored.trim() === source.trim()\n}\n\n/**\n * Writes `data` to `path`, trimming surrounding whitespace and ending the file with a single newline\n * the way prettier, biome, and oxfmt all do.\n * Skips the write when the trimmed content is empty, or when the file already holds that content.\n * Creates any missing parent directories automatically.\n * When `sanity` is `true`, re-reads the file after writing and throws if the content does not match.\n *\n * @example\n * ```ts\n * await write('./src/Pet.ts', source) // writes and returns the trimmed content plus a newline\n * await write('./src/Pet.ts', source) // null — file unchanged\n * await write('./src/Pet.ts', ' ') // null — empty content skipped\n * ```\n */\nexport async function write(path: string, data: string, options: WriteOptions = {}): Promise<string | null> {\n const trimmed = data.trim()\n if (trimmed === '') return null\n\n const content = `${trimmed}\\n`\n const resolved = resolve(path)\n const stored = options.stored === undefined ? await readIfExists(resolved) : options.stored\n if (matchesStored({ stored: stored ?? '', source: trimmed })) return null\n\n await writeRaw(resolved, content)\n\n if (options.sanity) {\n const savedData = await read(resolved)\n if (savedData !== content) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n return savedData\n }\n\n return content\n}\n\n/**\n * Writes UTF-8 content verbatim, including empty files and surrounding whitespace.\n * Uses Bun.write under Bun and creates missing parent directories under either runtime.\n *\n * @example\n * await writeRaw('./cache/output.ts', ' // keep these bytes\\n\\n')\n */\nexport async function writeRaw(path: string, content: string): Promise<void> {\n const resolved = resolve(path)\n if (runtime.isBun) {\n await Bun.write(resolved, content)\n return\n }\n try {\n await new Promise<void>((resolvePromise, reject) =>\n writeFile(resolved, content, { encoding: 'utf-8' }, (error) => (error ? reject(error) : resolvePromise())),\n )\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error\n await mkdir(dirname(resolved), { recursive: true })\n await new Promise<void>((resolvePromise, reject) =>\n writeFile(resolved, content, { encoding: 'utf-8' }, (error) => (error ? reject(error) : resolvePromise())),\n )\n }\n}\n\n/**\n * Lists non-hidden regular files below `directory` as relative POSIX paths, excluding directories and symlinks.\n * Uses Bun.Glob under Bun because its Node glob compatibility API lacks directory-entry support.\n *\n * @example\n * for await (const path of listFiles('./src')) console.log(path)\n */\nexport async function* listFiles(directory: string): AsyncGenerator<string> {\n const cwd = resolve(directory)\n if (runtime.isBun) {\n yield* new Bun.Glob('**/*').scan({ cwd, dot: false, onlyFiles: true, followSymlinks: false })\n return\n }\n for await (const entry of globNode('**/*', { cwd, withFileTypes: true })) {\n if (entry.isFile()) yield toPosixPath(relative(cwd, join(entry.parentPath, entry.name)))\n }\n}\n\n/**\n * Converts a filesystem path to use POSIX (`/`) separators.\n *\n * Most of the codebase compares and composes paths as strings (prefix matching, joining for\n * import specifiers, splitting on `/`). On POSIX `path.resolve` already returns `/`-separated\n * paths, but on Windows it returns `\\`-separated paths, which breaks every such comparison.\n *\n * Routing every path that crosses a module boundary through `toPosixPath` keeps the rest of the\n * code platform-agnostic. The conversion runs unconditionally so Windows-specific behavior is\n * exercisable from POSIX CI.\n *\n * @example\n * toPosixPath('C:\\\\repo\\\\src\\\\pet.ts') // 'C:/repo/src/pet.ts'\n */\nexport function toPosixPath(filePath: string): string {\n return filePath.replaceAll('\\\\', '/')\n}\n\n/**\n * Resolves to `true` when `path` is `parent` itself or nested inside it. Both sides are resolved\n * to absolute paths first, so relative and `..`-containing inputs compare correctly.\n *\n * Guards a destructive or an out-of-tree operation: before wiping an output directory, check that\n * it does not contain the project root, and before loading a path a caller supplied, check that it\n * did not escape the directory it is allowed to read from.\n *\n * @example\n * isPathInside('./src/gen', '.') // true — nested inside the root\n * isPathInside('.', '.') // true — the same directory counts as inside\n * isPathInside('.', './src/gen') // false — the root is not inside its own output\n * isPathInside('../other', '.') // false — escapes the root\n */\nexport function isPathInside(path: string, parent: string): boolean {\n const resolvedPath = resolve(path)\n const resolvedParent = resolve(parent)\n if (resolvedPath === resolvedParent) {\n return true\n }\n\n const rel = relative(resolvedParent, resolvedPath)\n\n return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel)\n}\n","","export const KUBB_CONFIG_FILENAME = 'kubb.config.ts' as const\n\n/** File extensions a Kubb config file may use. */\nexport const CONFIG_EXTENSIONS = ['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs'] as const\n\nexport const KUBB_PACKAGE_NAME = 'kubb' as const\n\n/**\n * Extensions `kubb` ships at its own version, so they count as installed without being a direct\n * dependency. `constants.test.ts` checks it against the `kubb` package's dependencies.\n */\nexport const BUNDLED_PACKAGES: ReadonlyArray<string> = ['@kubb/adapter-oas', '@kubb/parser-ts', '@kubb/parser-md', '@kubb/plugin-barrel']\n\nexport const initDefaults = {\n inputPath: './openapi.yaml',\n outputPath: './src/gen',\n plugins: ['plugin-ts'],\n} as const\n","import { getErrorMessage } from '@internals/utils'\nimport { type Comment, type Expression, type Program, parse } from 'yuku-parser'\n\nexport type {\n ArrayExpression,\n AssignmentExpression,\n BindingProperty,\n CallExpression,\n Comment,\n Expression,\n ImportDeclaration,\n ObjectExpression,\n ObjectPropertyKind,\n Program,\n RestElement,\n SpreadElement,\n VariableDeclaration,\n} from 'yuku-parser'\n\n/** Node types the config editor reads from the yuku AST. */\nexport const nodeTypes = {\n arrayExpression: 'ArrayExpression',\n arrowFunctionExpression: 'ArrowFunctionExpression',\n assignmentExpression: 'AssignmentExpression',\n blockStatement: 'BlockStatement',\n callExpression: 'CallExpression',\n exportDefaultDeclaration: 'ExportDefaultDeclaration',\n expressionStatement: 'ExpressionStatement',\n functionExpression: 'FunctionExpression',\n identifier: 'Identifier',\n importDeclaration: 'ImportDeclaration',\n importSpecifier: 'ImportSpecifier',\n literal: 'Literal',\n memberExpression: 'MemberExpression',\n objectExpression: 'ObjectExpression',\n objectPattern: 'ObjectPattern',\n property: 'Property',\n returnStatement: 'ReturnStatement',\n spreadElement: 'SpreadElement',\n tSAsExpression: 'TSAsExpression',\n tSSatisfiesExpression: 'TSSatisfiesExpression',\n templateLiteral: 'TemplateLiteral',\n unaryExpression: 'UnaryExpression',\n variableDeclaration: 'VariableDeclaration',\n} as const\n\nexport const commentTypes = { line: 'Line' } as const\nexport const propertyKinds = { init: 'init' } as const\nexport const unaryOperators = { minus: '-', plus: '+' } as const\nconst diagnosticSeverities = { error: 'error' } as const\n\n/** A parsed file: its statements and every comment in it, or why it could not be parsed. */\ntype ParsedSource = { program: Program; comments: Array<Comment> } | { reason: string }\n\n/**\n * Parses `source` as a TypeScript module. Never throws: a syntax error, or a native parser that\n * cannot load on this platform, comes back as a `reason`.\n */\nexport function parseSource(source: string): ParsedSource {\n try {\n // Parentheses are dropped, so `export default (defineConfig({}))` reads as the call itself.\n const { program, comments, diagnostics } = parse(source, { lang: 'ts', sourceType: 'module', preserveParens: false })\n if (diagnostics.some((diagnostic) => diagnostic.severity === diagnosticSeverities.error)) return { reason: 'the config file could not be parsed' }\n return { program, comments }\n } catch (error) {\n return { reason: `the config parser could not load on this platform: ${getErrorMessage(error)}` }\n }\n}\n\n/** Parses `source` as one expression, such as a commented-out `pluginTs({ ... })` call. */\nexport function parseExpression(source: string): Expression | undefined {\n const parsed = parseSource(source)\n if ('reason' in parsed) return undefined\n const [statement] = parsed.program.body\n return parsed.program.body.length === 1 && statement?.type === nodeTypes.expressionStatement ? statement.expression : undefined\n}\n","import path from 'node:path'\nimport { type ExtensionKind, isPackageName } from '@kubb/core'\nimport { camelCase } from '@internals/utils'\nimport { extensionKinds, type InstalledExtensions, type OptionValue } from './types.ts'\n\n/** `@kubb/plugin-ts` becomes `plugin-ts`, the `name` Kubb plugin factories use. */\nexport function toPluginName(packageName: string): string {\n return packageName.split('/').pop() ?? packageName\n}\n\n/** `@kubb/plugin-react-query` becomes `pluginReactQuery`, the export a plugin package uses by convention. */\nexport function toExportName(packageName: string): string {\n return camelCase(toPluginName(packageName))\n}\n\nconst KUBB_PLUGIN_SPECIFIER = /^@kubb\\/plugin-[\\w.-]+$/\n\n/** Only a `@kubb/plugin-*` package or an installed extension of `kind` may be imported, never a path or URL. */\nexport function isAllowedPlugin({\n packageName,\n extensions,\n kind = extensionKinds.plugin,\n}: {\n packageName: string\n extensions: InstalledExtensions\n kind?: ExtensionKind\n}): boolean {\n if (!isPackageName(packageName)) return false\n return (kind === extensionKinds.plugin && KUBB_PLUGIN_SPECIFIER.test(packageName)) || extensions.get(packageName)?.manifest.kind === kind\n}\n\nconst UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype'])\n\n/** Whether `key` can be an option key without reaching the object's prototype. */\nexport function isSafeKey(key: string): boolean {\n return !UNSAFE_KEYS.has(key)\n}\n\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null) return false\n const prototype = Object.getPrototypeOf(value)\n return prototype === null || prototype === Object.prototype\n}\n\n/** Whether `value` survives a JSON round trip, so an edit never writes a lossy copy into the file. */\nexport function isOptionValue(value: unknown): value is OptionValue {\n if (value === null || typeof value === 'string' || typeof value === 'boolean') return true\n if (typeof value === 'number') return Number.isFinite(value)\n if (Array.isArray(value)) return value.every(isOptionValue)\n if (isPlainObject(value)) return Object.entries(value).every(([key, entry]) => isSafeKey(key) && isOptionValue(entry))\n\n return false\n}\n\n/** The root `output` members Studio may set, with the values each takes. */\nconst OUTPUT_VALUES: Record<string, (value: unknown) => boolean> = {\n barrel: (value) => value === false || (isPlainObject(value) && Object.keys(value).length === 1 && (value.type === 'named' || value.type === 'all')),\n format: (value) => value === false || ['auto', 'prettier', 'biome', 'oxfmt'].includes(value as string),\n lint: (value) => value === false || ['auto', 'eslint', 'biome', 'oxlint'].includes(value as string),\n clean: (value) => typeof value === 'boolean',\n defaultBanner: (value) => value === false || value === 'simple' || value === 'full',\n}\n\nexport function isOutputKey(key: string): boolean {\n return Object.hasOwn(OUTPUT_VALUES, key)\n}\n\nexport function isOutputValue({ key, value }: { key: string; value: unknown }): boolean {\n return isOutputKey(key) && OUTPUT_VALUES[key]!(value)\n}\n\nexport function pickOutput<T>(output: Record<string, T>): Record<string, T> {\n return Object.fromEntries(Object.entries(output).filter(([key]) => isOutputKey(key)))\n}\n\n/**\n * Returns the first `output.path` in `value`, at any depth (`override` entries included), that is\n * absolute or climbs out of the folder it resolves against.\n */\nexport function findEscapingOutputPath(value: unknown): string | undefined {\n if (!Array.isArray(value) && !isPlainObject(value)) return undefined\n\n const output = isPlainObject(value) ? value.output : undefined\n if (isPlainObject(output) && typeof output.path === 'string') {\n const normalized = path.posix.normalize(output.path.replaceAll('\\\\', '/'))\n // Checked before normalizing, which turns `C:/../src` into `src`. A drive letter always leaves the folder.\n if (path.posix.isAbsolute(normalized) || /^[a-z]:/i.test(output.path) || normalized === '..' || normalized.startsWith('../')) return output.path\n }\n for (const entry of Object.values(value)) {\n const found = findEscapingOutputPath(entry)\n if (found !== undefined) return found\n }\n return undefined\n}\n","import type { ValueOf } from '@internals/utils'\nimport { type ArrayExpression, nodeTypes, type ObjectExpression } from './ast.ts'\nimport type { OptionValue } from './types.ts'\n\n/**\n * A valid JavaScript identifier, so an import name can only ever print as `import { name } from`,\n * never as source that breaks out of the import statement.\n */\nexport const IDENTIFIER_PATTERN = /^[A-Za-z_$][\\w$]*$/\n\nexport const quotes = { single: `'`, double: `\"` } as const\nexport type Quote = ValueOf<typeof quotes>\n\n/** `source` with the text between `start` and `end` replaced by `text`. */\nexport function replaceText(source: string, start: number, end: number, text = ''): string {\n return `${source.slice(0, start)}${text}${source.slice(end)}`\n}\n\n/** The 1-based line and 0-based column of `offset` in `source`. */\nexport function getPosition(source: string, offset: number): { line: number; column: number } {\n return { line: source.slice(0, offset).split('\\n').length, column: offset - source.lastIndexOf('\\n', offset - 1) - 1 }\n}\n\n/** Writes `value` as a single-line literal with the file's quote style. */\nexport function printValue(value: OptionValue, quote: Quote): string {\n if (typeof value === 'string') {\n // JSON's escaping covers every character that could end the literal or the line.\n const escaped = JSON.stringify(value).slice(1, -1)\n return quote === quotes.double ? `\"${escaped}\"` : `'${escaped.replaceAll(`\\\\\"`, `\"`).replaceAll(`'`, `\\\\'`)}'`\n }\n if (value === null || typeof value !== 'object') return String(value)\n if (Array.isArray(value)) return `[${value.map((item) => printValue(item, quote)).join(', ')}]`\n\n const entries = Object.entries(value)\n return entries.length ? `{ ${entries.map(([key, item]) => `${printKey(key, quote)}: ${printValue(item, quote)}`).join(', ')} }` : '{}'\n}\n\n/** An object key as source text: bare when it is an identifier, quoted otherwise. */\nexport function printKey(key: string, quote: Quote): string {\n return IDENTIFIER_PATTERN.test(key) ? key : printValue(key, quote)\n}\n\n/** `value` wrapped in one object per key of `path`: `wrapPath(['enum', 'type'], 'enum')` is `{ enum: { type: 'enum' } }`. */\nexport function wrapPath(path: Array<string>, value: OptionValue): OptionValue {\n return path.reduceRight<OptionValue>((inner, key) => ({ [key]: inner }), value)\n}\n\n/**\n * Adds `text` as the last item of an object or array literal, following its layout: on a line of\n * its own with the last item's indentation when the literal spans lines, inline otherwise.\n */\nexport function appendItem(source: string, container: ObjectExpression | ArrayExpression, text: string): string {\n const { start, end } = container\n const items: Array<{ start: number; end: number } | null> = container.type === nodeTypes.objectExpression ? container.properties : container.elements\n const last = items.filter((item) => item !== null).at(-1)\n\n if (!last) {\n const inner = source.slice(start + 1, end - 1)\n // A comment inside the empty literal stays, after the new item.\n if (inner.trim()) return replaceText(source, start + 1, start + 1, /^\\s/.test(inner) ? `${text},` : `${text}, `)\n return replaceText(source, start, end, container.type === nodeTypes.objectExpression ? `{ ${text} }` : `[${text}]`)\n }\n\n const between = source.slice(last.end, end - 1)\n // The closing bracket shares the last item's line: add the item inline.\n if (!between.includes('\\n')) return replaceText(source, last.end, last.end, `, ${text}`)\n\n const lineStart = source.lastIndexOf('\\n', last.start - 1) + 1\n const indent = source.slice(lineStart).match(/^[ \\t]*/)?.[0] ?? ''\n // After the last item's comma and any comment on its line, so neither moves. `between` holds a\n // newline, so one always follows.\n const lineEnd = source.indexOf('\\n', last.end)\n const comma = /^\\s*,/.test(between)\n\n return `${source.slice(0, last.end)}${comma ? '' : ','}${source.slice(last.end, lineEnd)}\\n${indent}${text}${comma ? ',' : ''}${source.slice(lineEnd)}`\n}\n\n/** Drops the item at `index` from an object or array literal, with its own lines when it sits on them alone. */\nexport function removeItem(source: string, node: ObjectExpression | ArrayExpression, index: number): string {\n const items: Array<{ start: number; end: number }> =\n node.type === nodeTypes.objectExpression ? node.properties : node.elements.filter((element) => element !== null)\n if (items.length === 1) return replaceText(source, node.start, node.end, node.type === nodeTypes.objectExpression ? '{}' : '[]')\n\n const { start, end } = items[index]!\n const lineStart = source.lastIndexOf('\\n', start - 1) + 1\n const nextNewline = source.indexOf('\\n', end)\n const lineEnd = nextNewline === -1 ? source.length : nextNewline\n if (!source.slice(lineStart, start).trim() && /^\\s*,?\\s*(\\/\\/.*)?$/.test(source.slice(end, lineEnd))) {\n return replaceText(source, lineStart, Math.min(lineEnd + 1, source.length))\n }\n\n const next = items[index + 1]\n return next ? replaceText(source, start, next.start) : replaceText(source, items[index - 1]!.end, end)\n}\n","import type { ExtensionKind } from '@kubb/core'\nimport { getErrorMessage, memo, read, writeRaw } from '@internals/utils'\nimport type { ValueOf } from '@internals/utils'\nimport {\n type AssignmentExpression,\n type BindingProperty,\n type CallExpression,\n type Comment,\n type Expression,\n type ImportDeclaration,\n type ObjectExpression,\n type ObjectPropertyKind,\n type Program,\n type RestElement,\n type SpreadElement,\n type VariableDeclaration,\n commentTypes,\n nodeTypes,\n parseExpression,\n parseSource,\n propertyKinds,\n unaryOperators,\n} from './ast.ts'\nimport { findEscapingOutputPath, isAllowedPlugin, isOptionValue, isOutputKey, isOutputValue, isSafeKey, pickOutput, toExportName } from './rules.ts'\nimport { appendItem, getPosition, IDENTIFIER_PATTERN, printKey, printValue, quotes, type Quote, removeItem, replaceText, wrapPath } from './text.ts'\nimport {\n type ConfigEdit,\n ConfigEditOperation,\n type ConfigEditOutcome,\n type ConfigFileView,\n type ConfigRef,\n type ConfigView,\n extensionKinds,\n type InstalledExtensions,\n type OptionsView,\n type OptionValue,\n type PluginView,\n} from './types.ts'\n\n/** The marker `disable-plugin` writes, with the block's line count so `enable-plugin` restores exactly those lines. */\nconst DISABLED_MARKER_PATTERN = /^kubb:disabled (.+)\\s+(\\d+)$/\n\nconst OPERATIONS = new Set<string>(Object.values(ConfigEditOperation))\nconst OPTION_OPERATIONS = new Set<string>([ConfigEditOperation.SET_OPTION, ConfigEditOperation.REMOVE_OPTION])\nconst OUTPUT_OPERATIONS = new Set<string>([ConfigEditOperation.SET_OUTPUT, ConfigEditOperation.REMOVE_OUTPUT])\nconst KINDS = new Set<string>(Object.values(extensionKinds))\n\n/** Identifiers the editor matches by name. */\nconst identifiers = { defineConfig: 'defineConfig', require: 'require', module: 'module', exports: 'exports' } as const\n\nconst moduleKinds = { esm: 'esm', cjs: 'cjs' } as const\ntype ModuleKind = ValueOf<typeof moduleKinds>\n\ntype EditResult = { source: string } | { reason: string }\ntype ParsedConfig = { program: Program; comments: Array<Comment>; configs: Array<ObjectExpression>; kind: ModuleKind }\ntype ValueNode = Expression | SpreadElement | null | undefined\ntype Import = { from: string; exported: string }\ntype FactoryCall = { importName: string; exportName: string; packageName: string; call: CallExpression }\ntype DisabledBlock = { packageName: string; line: number; end: number; code: Array<string> }\ntype OutputEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.SET_OUTPUT | typeof ConfigEditOperation.REMOVE_OUTPUT }>\ntype OptionEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.SET_OPTION | typeof ConfigEditOperation.REMOVE_OPTION }>\ntype AddPluginEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.ADD_PLUGIN }>\ntype DisablePluginEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.DISABLE_PLUGIN }>\ntype RemoveExtensionEdit = Extract<ConfigEdit, { operation: typeof ConfigEditOperation.REMOVE_EXTENSION }>\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value !== ''\n}\n\n/** Edits cross the wire, so their shape is checked before anything reads them. */\nfunction validateEdit(edit: ConfigEdit): string | undefined {\n const { operation, plugin, config, path, kind, input, value, options } = (typeof edit === 'object' && edit !== null ? edit : {}) as Record<string, unknown>\n\n if (typeof operation !== 'string' || !OPERATIONS.has(operation)) return `unknown operation ${JSON.stringify(operation)}`\n if (config !== undefined && typeof config !== 'string' && !Number.isSafeInteger(config)) return 'config must name an entry or give its index'\n\n if (operation === ConfigEditOperation.SET_INPUT) {\n return typeof input === 'string' && input.trim() !== '' ? undefined : 'the edit names no input'\n }\n\n const isOption = OPTION_OPERATIONS.has(operation)\n const isOutput = OUTPUT_OPERATIONS.has(operation)\n\n if (!isOutput && !isNonEmptyString(plugin)) return 'the edit names no plugin'\n\n // The next generation writes there, so an edit may only point a plugin inside the output folder.\n const written =\n operation === ConfigEditOperation.SET_OPTION && Array.isArray(path) ? path.reduceRight<unknown>((inner, key) => ({ [String(key)]: inner }), value) : options\n const escaping = findEscapingOutputPath(written)\n if (escaping !== undefined) return `output.path ${JSON.stringify(escaping)} resolves outside the output folder`\n\n if (kind !== undefined) {\n if (typeof kind !== 'string' || !KINDS.has(kind)) return `unknown kind ${JSON.stringify(kind)}`\n const takesKind = operation === ConfigEditOperation.ADD_PLUGIN || operation === ConfigEditOperation.REMOVE_EXTENSION\n if (takesKind && kind === extensionKinds.adapter) return `${operation} takes a plugin or a parser, since a config has one adapter`\n if (!isOption && !takesKind) return `${operation} edits the plugins array, so it takes no kind`\n }\n\n if (!isOption && !isOutput) return undefined\n\n if (!Array.isArray(path) || !path.every(isNonEmptyString)) return 'path must be a list of option names'\n if (path.length === 0) return 'no option path given'\n\n const unsafe = path.find((key) => !isSafeKey(key))\n if (unsafe !== undefined) return `${unsafe} cannot be used as an option name`\n\n if (isOutput && !isOutputKey(path[0]!)) return `output.${path[0]} can only be changed in the config file`\n\n return undefined\n}\n\n// Finding the config\n\n/** Steps through `as`/`satisfies` and `() => ...` wrappers to the config object. */\nfunction unwrapValue(node: ValueNode): ValueNode {\n if (!node) return undefined\n if (node.type === nodeTypes.tSAsExpression || node.type === nodeTypes.tSSatisfiesExpression) return unwrapValue(node.expression)\n if (node.type !== nodeTypes.arrowFunctionExpression && node.type !== nodeTypes.functionExpression) return node\n if (node.body?.type !== nodeTypes.blockStatement) return unwrapValue(node.body as Expression | null)\n\n const returned = node.body.body.find((statement) => statement.type === nodeTypes.returnStatement)\n return unwrapValue(returned?.type === nodeTypes.returnStatement ? returned.argument : undefined)\n}\n\nfunction isModuleExports(node: AssignmentExpression['left']): boolean {\n return (\n node.type === nodeTypes.memberExpression &&\n !node.computed &&\n node.object.type === nodeTypes.identifier &&\n node.object.name === identifiers.module &&\n node.property.type === nodeTypes.identifier &&\n node.property.name === identifiers.exports\n )\n}\n\n/** The exported config value and how the file exports it. */\nfunction findExport(program: Program): { exported: ValueNode; kind: ModuleKind } {\n for (const node of program.body) {\n if (node.type === nodeTypes.exportDefaultDeclaration) {\n // A `function` or `class` declaration is never a `defineConfig(...)` call, so `findConfigs` refuses it.\n return { exported: node.declaration as Expression, kind: moduleKinds.esm }\n }\n if (node.type === nodeTypes.expressionStatement && node.expression.type === nodeTypes.assignmentExpression && isModuleExports(node.expression.left)) {\n return { exported: node.expression.right, kind: moduleKinds.cjs }\n }\n }\n return { exported: undefined, kind: moduleKinds.esm }\n}\n\n/** Every config object in `export default` or `module.exports = defineConfig(...)`, or why the file is unmanaged. */\nfunction findConfigs(source: string): ParsedConfig | { reason: string } {\n const parsed = parseSource(source)\n if ('reason' in parsed) return parsed\n\n const { exported, kind } = findExport(parsed.program)\n const value = unwrapValue(exported)\n if (!value) return { reason: 'no `export default` or `module.exports` found' }\n if (value.type !== nodeTypes.callExpression || value.callee.type !== nodeTypes.identifier || value.callee.name !== identifiers.defineConfig) {\n return { reason: 'the exported config is not a defineConfig(...) call' }\n }\n\n const argument = unwrapValue(value.arguments[0])\n if (!argument) return { reason: 'defineConfig(...) was called without a config' }\n\n const entries = argument.type === nodeTypes.arrayExpression ? argument.elements.map((element) => unwrapValue(element)) : [argument]\n const configs = entries.filter((entry): entry is ObjectExpression => entry?.type === nodeTypes.objectExpression)\n if (configs.length !== entries.length) return { reason: 'config is not an object literal' }\n\n return { ...parsed, configs, kind }\n}\n\nfunction findConfigEntry(configs: Array<ObjectExpression>, ref: ConfigRef | undefined): ObjectExpression | undefined {\n return typeof ref === 'string' ? configs.find((entry) => getConfigName(entry) === ref) : configs[ref ?? 0]\n}\n\n// Reading object literals\n\nfunction getKey(entry: ObjectPropertyKind | BindingProperty | RestElement): string | undefined {\n if (entry.type !== nodeTypes.property || entry.computed) return undefined\n if (entry.key.type === nodeTypes.identifier) return entry.key.name\n return entry.key.type === nodeTypes.literal && typeof entry.key.value === 'string' ? entry.key.value : undefined\n}\n\n/** The last one wins when the key repeats, as at runtime. */\nfunction findProperty(node: ObjectExpression, key: string): { member: ObjectPropertyKind; index: number } | undefined {\n const index = node.properties.findLastIndex((entry) => getKey(entry) === key)\n return index === -1 ? undefined : { member: node.properties[index]!, index }\n}\n\nfunction getValue(node: ObjectExpression, key: string): ValueNode {\n const member = findProperty(node, key)?.member\n return member?.type === nodeTypes.property ? member.value : member\n}\n\nfunction getConfigName(config: ObjectExpression): string | undefined {\n const name = getValue(config, 'name')\n return name?.type === nodeTypes.literal && typeof name.value === 'string' ? name.value : undefined\n}\n\nfunction isOverridden(node: ObjectExpression, index: number): boolean {\n return node.properties.slice(index + 1).some((entry) => entry.type === nodeTypes.spreadElement)\n}\n\n/** `key: value`, not a method, getter, setter, or `{ key }` shorthand. */\nfunction isPlainProperty(member: Extract<ObjectPropertyKind, { type: typeof nodeTypes.property }>): boolean {\n return !member.method && !member.shorthand && member.kind === propertyKinds.init\n}\n\n/** A literal's value, `undefined` for code. */\nfunction readLiteral(node: ValueNode): OptionValue | undefined {\n switch (node?.type) {\n case nodeTypes.literal:\n // A bigint or a regex is code, not a value JSON can carry. A regex Node cannot compile also has a `null` value.\n return 'regex' in node || 'bigint' in node ? undefined : (node.value as OptionValue)\n case nodeTypes.templateLiteral:\n return node.expressions.length ? undefined : (node.quasis[0]?.value.cooked ?? '')\n case nodeTypes.unaryExpression: {\n const value = readLiteral(node.argument)\n if (typeof value !== 'number') return undefined\n if (node.operator === unaryOperators.minus) return -value\n if (node.operator === unaryOperators.plus) return value\n return undefined\n }\n case nodeTypes.arrayExpression: {\n const values = node.elements.map((element) => readLiteral(element))\n return values.every((value) => value !== undefined) ? values : undefined\n }\n case nodeTypes.objectExpression: {\n const entries: Record<string, OptionValue> = {}\n for (const entry of node.properties) {\n if (entry.type !== nodeTypes.property) return undefined\n const key = getKey(entry)\n const value = readLiteral(entry.value)\n // A `__proto__` key would replace the object's prototype instead of adding an entry.\n if (key === undefined || !isSafeKey(key) || value === undefined) return undefined\n entries[key] = value\n }\n return entries\n }\n }\n return undefined\n}\n\n// Imports and factory calls\n\nfunction getRequirePath(node: ValueNode): string | undefined {\n if (node?.type !== nodeTypes.callExpression || node.callee.type !== nodeTypes.identifier || node.callee.name !== identifiers.require) return undefined\n const [argument] = node.arguments\n return argument?.type === nodeTypes.literal && typeof argument.value === 'string' ? argument.value : undefined\n}\n\n/** `import { exported as local } from '...'`. A default or namespace import has no exported name, so its local name stands in. */\nfunction importBindings(statement: ImportDeclaration): Array<[string, Import]> {\n return statement.specifiers.map((specifier) => {\n const imported = specifier.type === nodeTypes.importSpecifier ? specifier.imported : specifier.local\n const exported = imported.type === nodeTypes.identifier ? imported.name : imported.value\n return [specifier.local.name, { from: statement.source.value, exported }]\n })\n}\n\n/** `const { exported: local } = require('...')`. */\nfunction requireBindings(statement: VariableDeclaration): Array<[string, Import]> {\n return statement.declarations.flatMap((declarator): Array<[string, Import]> => {\n const from = getRequirePath(declarator.init)\n if (from === undefined || declarator.id.type !== nodeTypes.objectPattern) return []\n\n return declarator.id.properties.flatMap((entry): Array<[string, Import]> => {\n if (entry.type !== nodeTypes.property || entry.value.type !== nodeTypes.identifier) return []\n return [[entry.value.name, { from, exported: getKey(entry) ?? entry.value.name }]]\n })\n })\n}\n\nfunction getImports(program: Program): Map<string, Import> {\n return new Map(\n program.body.flatMap((statement) => {\n if (statement.type === nodeTypes.importDeclaration) return importBindings(statement)\n if (statement.type === nodeTypes.variableDeclaration) return requireBindings(statement)\n return []\n }),\n )\n}\n\nfunction isImportStatement(node: Program['body'][number], kind: ModuleKind): boolean {\n if (kind === moduleKinds.esm) return node.type === nodeTypes.importDeclaration\n return node.type === nodeTypes.variableDeclaration && node.declarations.some((declarator) => getRequirePath(declarator.init) !== undefined)\n}\n\n/** The quote of the first string literal in the file, so new code matches it. */\nfunction detectQuote(node: unknown): Quote | undefined {\n if (!node || typeof node !== 'object') return undefined\n const { type, raw } = node as { type?: string; raw?: unknown }\n if (type === nodeTypes.literal && typeof raw === 'string' && (raw[0] === quotes.single || raw[0] === quotes.double)) return raw[0]\n for (const child of Object.values(node)) {\n const quote = detectQuote(child)\n if (quote) return quote\n }\n return undefined\n}\n\n/** The `adapter` value, or the elements of the `plugins` or `parsers` array. */\nfunction factoryNodes(config: ObjectExpression, kind: ExtensionKind): Array<ValueNode> {\n if (kind === extensionKinds.adapter) return [getValue(config, 'adapter')]\n const array = getValue(config, `${kind}s`)\n return array?.type === nodeTypes.arrayExpression ? array.elements : []\n}\n\n/** The factory calls of one kind whose callee the file imports. */\nfunction findCalls(program: Program, config: ObjectExpression, kind: ExtensionKind = extensionKinds.plugin): Array<FactoryCall> {\n const imports = getImports(program)\n return factoryNodes(config, kind).flatMap((node) => {\n if (node?.type !== nodeTypes.callExpression || node.callee.type !== nodeTypes.identifier) return []\n const imported = imports.get(node.callee.name)\n return imported ? [{ importName: node.callee.name, exportName: imported.exported, packageName: imported.from, call: node }] : []\n })\n}\n\n// Disabled plugins\n\n/** Whether nothing but whitespace precedes `offset` on its line. */\nfunction startsLine(source: string, offset: number): boolean {\n return source.slice(source.lastIndexOf('\\n', offset - 1) + 1, offset).trim() === ''\n}\n\n/** The `disable-plugin` blocks in this config, read from marker comments since the call is no longer a node. */\nfunction findDisabled(source: string, comments: Array<Comment>, config: ObjectExpression): Array<DisabledBlock> {\n const lines = source.split('\\n')\n\n return comments.flatMap((comment) => {\n const match = comment.type === commentTypes.line ? comment.value.trim().match(DISABLED_MARKER_PATTERN) : null\n // Only markers inside this entry, on a line of their own, so another entry or a trailing comment never matches.\n if (!match || comment.start < config.start || comment.end > config.end || !startsLine(source, comment.start)) return []\n\n const line = getPosition(source, comment.start).line\n const end = line + Number(match[2])\n const code = lines.slice(line, end).map((text) => text.replace(/^(\\s*)\\/\\/ ?/, '$1').replace(/^\\s+$/, ''))\n return [{ packageName: match[1]!, line, end, code }]\n })\n}\n\n// Reading options\n\n/** Literal members as `value` and code paths as `locked`, `undefined` for a computed key. */\nfunction readEditable(node: ObjectExpression, prefix: Array<string> = []): { value: Record<string, OptionValue>; locked: Array<Array<string>> } | undefined {\n const value: Record<string, OptionValue> = {}\n const locked: Array<Array<string>> = []\n\n for (const [index, entry] of node.properties.entries()) {\n if (entry.type === nodeTypes.spreadElement) continue\n const key = getKey(entry)\n if (key === undefined) return undefined\n if (findProperty(node, key)?.index !== index) continue\n\n const path = [...prefix, key]\n // A `__proto__` key replaces the prototype, so it reads as code.\n if (!isSafeKey(key)) {\n locked.push(path)\n continue\n }\n\n const member = isOverridden(node, index) ? undefined : entry.value\n const literal = readLiteral(member)\n if (literal !== undefined) {\n value[key] = literal\n continue\n }\n if (member?.type !== nodeTypes.objectExpression) {\n locked.push(path)\n continue\n }\n\n const nested = readEditable(member, path)\n if (!nested) return undefined\n value[key] = nested.value\n locked.push(...nested.locked)\n }\n return { value, locked }\n}\n\nfunction readObjectOptions(options: ObjectExpression): OptionsView {\n const entries: OptionsView = {}\n for (const [index, entry] of options.properties.entries()) {\n const key = getKey(entry)\n if (key === undefined || !isSafeKey(key)) continue\n\n const member = entry.type === nodeTypes.property && !isOverridden(options, index) ? entry.value : undefined\n const value = readLiteral(member)\n if (value !== undefined) {\n entries[key] = { literal: true, value }\n continue\n }\n entries[key] = { literal: false, ...(member?.type === nodeTypes.objectExpression ? readEditable(member) : undefined) }\n }\n return entries\n}\n\nfunction readCallOptions(call: CallExpression): OptionsView {\n const options = call.arguments[0]\n return options?.type === nodeTypes.objectExpression ? readObjectOptions(options) : {}\n}\n\nfunction readDisabledOptions(code: Array<string>): OptionsView {\n const call = parseExpression(code.join('\\n').trim().replace(/,$/, ''))\n return call?.type === nodeTypes.callExpression ? readCallOptions(call) : {}\n}\n\nfunction toPluginView({ importName, packageName, call }: FactoryCall): PluginView {\n return { importName, packageName, options: readCallOptions(call) }\n}\n\n/** Active and disabled plugins, in source order so a disabled plugin keeps its place. */\nfunction readPlugins({ source, parsed, config }: { source: string; parsed: ParsedConfig; config: ObjectExpression }): Array<PluginView> {\n const importNames = new Map([...getImports(parsed.program)].map(([local, { from }]) => [from, local]))\n\n const active = findCalls(parsed.program, config).map((call) => ({ line: getPosition(source, call.call.start).line, plugin: toPluginView(call) }))\n const disabled = findDisabled(source, parsed.comments, config).map(({ packageName, line, code }) => ({\n line,\n plugin: {\n importName: importNames.get(packageName) ?? toExportName(packageName),\n packageName,\n options: readDisabledOptions(code),\n disabled: true as const,\n },\n }))\n\n return [...active, ...disabled].sort((a, b) => a.line - b.line).map(({ plugin }) => plugin)\n}\n\nfunction readConfigView({ source, parsed, config }: { source: string; parsed: ParsedConfig; config: ObjectExpression }): ConfigView {\n const [adapter] = findCalls(parsed.program, config, extensionKinds.adapter).map(toPluginView)\n const parsers = findCalls(parsed.program, config, extensionKinds.parser).map(toPluginView)\n const output = getOutput(config)\n\n return {\n name: getConfigName(config),\n plugins: readPlugins({ source, parsed, config }),\n ...(adapter && { adapter }),\n ...(parsers.length ? { parsers } : {}),\n ...(!('reason' in output) && { output: pickOutput(readObjectOptions(output.object)) }),\n }\n}\n\n/** Which plugins the file declares and which options Studio may write. */\nexport function readConfig(source: string): ConfigFileView {\n const parsed = findConfigs(source)\n if ('reason' in parsed) return { managed: false, reason: parsed.reason }\n\n return { managed: true, configs: parsed.configs.map((config) => readConfigView({ source, parsed, config })) }\n}\n\n/** The modules the file imports, empty when it cannot be parsed. */\nexport function readImports(source: string): Array<string> {\n const parsed = parseSource(source)\n if ('reason' in parsed) return []\n return [...new Set([...getImports(parsed.program).values()].map(({ from }) => from))]\n}\n\n// Editing options\n\ntype FoundPath = { object: ObjectExpression; index: number; value: Expression } | { object: ObjectExpression; missing: number } | { reason: string }\n\n/** Follows `path` to its literal, or to the first missing key. Refuses a value set in code. */\nfunction findPath(options: ObjectExpression, path: Array<string>): FoundPath {\n let object = options\n\n for (const [depth, key] of path.entries()) {\n const found = findProperty(object, key)\n if (!found) return { object, missing: depth }\n if (isOverridden(object, found.index)) {\n return { reason: `${path.slice(0, depth + 1).join('.')} can be overridden by a spread after it, so it is customized in code` }\n }\n\n const { member, index } = found\n const isLast = depth === path.length - 1\n if (isLast) {\n return member.type === nodeTypes.property && readLiteral(member.value) !== undefined\n ? { object, index, value: member.value }\n : { reason: `${path.join('.')} is customized in code` }\n }\n if (member.type !== nodeTypes.property || member.value.type !== nodeTypes.objectExpression) {\n return { reason: `${key} is not an object, so ${path.join('.')} cannot be reached` }\n }\n object = member.value\n }\n return { reason: 'no option path given' }\n}\n\nfunction setAtPath({\n source,\n options,\n path,\n value,\n quote,\n}: {\n source: string\n options: ObjectExpression\n path: Array<string>\n value: OptionValue\n quote: Quote\n}): EditResult {\n const target = findPath(options, path)\n if ('reason' in target) return target\n if ('missing' in target) {\n const [key, ...rest] = path.slice(target.missing)\n return { source: appendItem(source, target.object, `${printKey(key!, quote)}: ${printValue(wrapPath(rest, value), quote)}`) }\n }\n return { source: replaceText(source, target.value.start, target.value.end, printValue(value, quote)) }\n}\n\nfunction removeAtPath({ source, options, path }: { source: string; options: ObjectExpression; path: Array<string> }): EditResult {\n const target = findPath(options, path)\n if ('reason' in target) return target\n if ('missing' in target) return { source }\n return { source: removeItem(source, target.object, target.index) }\n}\n\nfunction setOption(source: string, call: CallExpression, path: Array<string>, value: unknown, quote: Quote): EditResult {\n if (!isOptionValue(value)) return { reason: 'the value is not a literal that can be written to a config file' }\n\n const options = call.arguments[0]\n if (!options) {\n const closing = call.end - 1\n if (source[closing] !== ')') return { reason: 'the factory call could not be located in the file' }\n return { source: replaceText(source, closing, closing, printValue(wrapPath(path, value), quote)) }\n }\n if (options.type !== nodeTypes.objectExpression) return { reason: 'the factory was not called with an object literal' }\n return setAtPath({ source, options, path, value, quote })\n}\n\nfunction removeOption(source: string, call: CallExpression, path: Array<string>): EditResult {\n const options = call.arguments[0]\n if (!options) return { source }\n if (options.type !== nodeTypes.objectExpression) return { reason: 'the factory was not called with an object literal' }\n return removeAtPath({ source, options, path })\n}\n\nfunction editOption({\n source,\n parsed,\n config,\n edit,\n quote,\n extensions,\n}: {\n source: string\n parsed: ParsedConfig\n config: ObjectExpression\n edit: OptionEdit\n quote: Quote\n extensions: InstalledExtensions\n}): EditResult {\n const kind = edit.kind ?? extensionKinds.plugin\n // A package can ship several factories (`parserTs`, `parserTsx`), so prefer the export its manifest names.\n const calls = findCalls(parsed.program, config, kind).filter((entry) => entry.packageName === edit.plugin)\n const exportName = extensions.get(edit.plugin)?.manifest.export ?? toExportName(edit.plugin)\n const call = (calls.find((entry) => entry.exportName === exportName) ?? calls[0])?.call\n\n if (!call) {\n if (kind === extensionKinds.adapter) return { reason: `${edit.plugin} is not the config's adapter` }\n const disabled = kind === extensionKinds.plugin && findDisabled(source, parsed.comments, config).some((block) => block.packageName === edit.plugin)\n return { reason: disabled ? `${edit.plugin} is disabled, enable it first` : `${edit.plugin} is not in the ${kind}s array` }\n }\n\n if (edit.operation === ConfigEditOperation.SET_OPTION) return setOption(source, call, edit.path, edit.value, quote)\n return removeOption(source, call, edit.path)\n}\n\n// Editing the config's own fields\n\nfunction setInput(source: string, config: ObjectExpression, input: string, quote: Quote): EditResult {\n const value = printValue(input, quote)\n const found = findProperty(config, 'input')\n if (!found) return { source: appendItem(source, config, `input: ${value}`) }\n if (found.member.type !== nodeTypes.property || !isPlainProperty(found.member)) return { reason: 'input is not a plain property' }\n if (isOverridden(config, found.index)) return { reason: 'a spread after input could override it' }\n return { source: replaceText(source, found.member.value.start, found.member.value.end, value) }\n}\n\nfunction getOutput(config: ObjectExpression): { object: ObjectExpression } | { reason: string } {\n const found = findProperty(config, 'output')\n if (found?.member.type !== nodeTypes.property || found.member.value.type !== nodeTypes.objectExpression) return { reason: 'output is not an object literal' }\n if (isOverridden(config, found.index)) return { reason: 'a spread after output could override it' }\n return { object: found.member.value }\n}\n\nfunction editOutput({ source, config, edit, quote }: { source: string; config: ObjectExpression; edit: OutputEdit; quote: Quote }): EditResult {\n const output = getOutput(config)\n if ('reason' in output) return output\n if (edit.operation === ConfigEditOperation.REMOVE_OUTPUT) return removeAtPath({ source, options: output.object, path: edit.path })\n\n const [key, ...rest] = edit.path\n if (!isOptionValue(edit.value) || !isOutputValue({ key: key!, value: wrapPath(rest, edit.value) }))\n return { reason: `the value is not one output.${key} takes` }\n return setAtPath({ source, options: output.object, path: edit.path, value: edit.value, quote })\n}\n\n// Adding, disabling, and enabling plugins\n\n/** Adds the import after the last one, matching its semicolon style. */\nfunction addImport({\n source,\n parsed,\n importNames,\n moduleSpecifier,\n quote,\n}: {\n source: string\n parsed: ParsedConfig\n importNames: Array<string>\n moduleSpecifier: string\n quote: Quote\n}): string {\n const lastImport = parsed.program.body.findLast((node) => isImportStatement(node, parsed.kind))\n const afterLine = lastImport ? getPosition(source, lastImport.end).line : 0\n const lines = source.split('\\n')\n\n const semicolon = afterLine > 0 && lines[afterLine - 1]?.trimEnd().endsWith(';') ? ';' : ''\n const specifier = `${quote}${moduleSpecifier}${quote}`\n const statement =\n parsed.kind === moduleKinds.esm ? `import { ${importNames.join(', ')} } from ${specifier}` : `const { ${importNames.join(', ')} } = require(${specifier})`\n\n lines.splice(afterLine, 0, `${statement}${semicolon}`)\n if (afterLine === 0) lines.splice(1, 0, '')\n\n return lines.join('\\n')\n}\n\n/**\n * The parsers `defineConfig` applies when a config sets no `parsers`, by import name. Adding a parser\n * to such a config writes these too, or the new array would replace them.\n */\nconst DEFAULT_PARSERS = [\n { importName: 'parserTs', packageName: '@kubb/parser-ts' },\n { importName: 'parserTsx', packageName: '@kubb/parser-ts' },\n { importName: 'parserMd', packageName: '@kubb/parser-md' },\n] as const\n\n/**\n * Adds a plugin to `plugins`, or with `kind: 'parser'` a parser to `parsers`. Replaying the same add\n * is a no-op, while an import name taken by another package is an error.\n */\nfunction addPlugin({\n source,\n parsed,\n config,\n edit,\n quote,\n extensions,\n}: {\n source: string\n parsed: ParsedConfig\n config: ObjectExpression\n edit: AddPluginEdit\n quote: Quote\n extensions: InstalledExtensions\n}): EditResult {\n const kind = edit.kind ?? extensionKinds.plugin\n const isParser = kind === extensionKinds.parser\n if (!isAllowedPlugin({ packageName: edit.plugin, extensions, kind })) {\n return {\n reason: isParser ? `\"${edit.plugin}\" is not an installed Kubb parser` : `\"${edit.plugin}\" is not a @kubb/plugin-* package or an installed Kubb plugin`,\n }\n }\n\n const importName = extensions.get(edit.plugin)?.manifest.export ?? toExportName(edit.plugin)\n if (!IDENTIFIER_PATTERN.test(importName)) return { reason: `\"${importName}\" is not a valid import name` }\n // A package can ship several parsers (`parserTs` and `parserTsx`), so a parser is matched by its export too.\n if (findCalls(parsed.program, config, kind).some((entry) => entry.packageName === edit.plugin && (!isParser || entry.exportName === importName))) {\n return { source }\n }\n\n const options = edit.options ?? {}\n if (!isOptionValue(options)) return { reason: 'the options are not literals that can be written to a config file' }\n\n const key = `${kind}s`\n const array = getValue(config, key)\n if (array ? array.type !== nodeTypes.arrayExpression : !isParser) return { reason: `${key} is not an array literal` }\n // A config without `parsers` runs the defaults, so the new array lists them before the added parser.\n const defaults = isParser && !array ? DEFAULT_PARSERS.filter((parser) => parser.importName !== importName) : []\n\n // The missing imports by package, so `parserTs` and `parserTsx` share one line.\n const imports = getImports(parsed.program)\n const missing = memo.create<string, Array<string>>()\n for (const item of [...defaults, { importName, packageName: edit.plugin }]) {\n const from = imports.get(item.importName)?.from\n if (from && from !== item.packageName) return { reason: `${item.importName} is already imported from ${from}` }\n if (!from) memo(missing, item.packageName, () => []).push(item.importName)\n }\n\n // The array sits below the imports, so adding to it first leaves the import lines where they are.\n const call = `${importName}(${Object.keys(options).length ? printValue(options, quote) : ''})`\n const next =\n array?.type === nodeTypes.arrayExpression\n ? appendItem(source, array, call)\n : appendItem(source, config, `parsers: [${[...defaults.map((parser) => `${parser.importName}()`), call].join(', ')}]`)\n\n return {\n source: [...missing].reduceRight(\n (current, [moduleSpecifier, importNames]) => addImport({ source: current, parsed, importNames, moduleSpecifier, quote }),\n next,\n ),\n }\n}\n\n/** One item per line, so a call can be commented out alone. Skipped when comments sit between items. */\nfunction splitPlugins(source: string, config: ObjectExpression): string | undefined {\n const array = getValue(config, 'plugins')\n if (array?.type !== nodeTypes.arrayExpression) return undefined\n\n const items = array.elements.flatMap((element) => (element ? [element] : []))\n const { start, end } = array\n const gaps = [source.slice(start + 1, items[0]?.start ?? end - 1), ...items.map((item, index) => source.slice(item.end, items[index + 1]?.start ?? end - 1))]\n if (!items.length || gaps.some((gap) => !/^[\\s,]*$/.test(gap))) return undefined\n\n const lineStart = source.lastIndexOf('\\n', start - 1) + 1\n const indent = source.slice(lineStart).match(/^[ \\t]*/)?.[0] ?? ''\n const lines = items.map((item) => `${indent} ${source.slice(item.start, item.end)},`)\n\n return replaceText(source, start, end, `[\\n${lines.join('\\n')}\\n${indent}]`)\n}\n\nfunction disablePlugin(source: string, program: Program, config: ObjectExpression, plugin: string): EditResult {\n const call = findCalls(program, config).find((entry) => entry.packageName === plugin)?.call\n if (!call) return { reason: `${plugin} is not in the plugins array` }\n\n const start = getPosition(source, call.start)\n const end = getPosition(source, call.end)\n const lines = source.split('\\n')\n const from = start.line - 1\n const to = end.line - 1\n const firstLine = lines[from] ?? ''\n\n // Only safe when the call sits alone on its lines: anything else on its first line, or on its last\n // line besides a trailing comma, would be swallowed into the comment and corrupt the file.\n if (firstLine.slice(0, start.column).trim() || !/^,?\\s*$/.test((lines[to] ?? '').slice(end.column))) {\n return { reason: `${plugin} shares a line with other code, so it cannot be commented out safely` }\n }\n\n const indent = firstLine.match(/^\\s*/)?.[0] ?? ''\n const commented = lines.slice(from, to + 1).map((line) => (line.trim() ? `${indent}// ${line.slice(indent.length)}` : `${indent}//`))\n lines.splice(from, commented.length, `${indent}// kubb:disabled ${plugin} ${commented.length}`, ...commented)\n\n return { source: lines.join('\\n') }\n}\n\n/** Disables the plugin, first putting a one-line `plugins: [a(), b()]` (what `add-plugin` writes) on separate lines. */\nfunction disablePluginInConfig({\n source,\n parsed,\n config,\n edit,\n}: {\n source: string\n parsed: ParsedConfig\n config: ObjectExpression\n edit: DisablePluginEdit\n}): EditResult {\n const result = disablePlugin(source, parsed.program, config, edit.plugin)\n if (!('reason' in result) || !result.reason.includes('shares a line')) return result\n\n const split = splitPlugins(source, config)\n if (split === undefined) return result\n\n const reparsed = findConfigs(split)\n const reparsedConfig = 'reason' in reparsed ? undefined : findConfigEntry(reparsed.configs, edit.config)\n if ('reason' in reparsed || !reparsedConfig) return result\n\n return disablePlugin(split, reparsed.program, reparsedConfig, edit.plugin)\n}\n\nfunction enablePlugin(source: string, comments: Array<Comment>, config: ObjectExpression, plugin: string): EditResult {\n const block = findDisabled(source, comments, config).find((entry) => entry.packageName === plugin)\n if (!block) return { reason: `${plugin} is not disabled` }\n\n const lines = source.split('\\n')\n lines.splice(block.line - 1, block.end - block.line + 1, ...block.code)\n return { source: lines.join('\\n') }\n}\n\n// Removing extensions\n\n/** Drops the import statements of `packageName` once nothing else in the file uses their names. */\nfunction removeUnusedImports(source: string, packageName: string): string {\n const parsed = parseSource(source)\n if ('reason' in parsed) return source\n\n // From the last statement up, so the offsets of the earlier ones stay valid.\n return parsed.program.body.reduceRight((current, statement) => {\n const bindings =\n statement.type === nodeTypes.importDeclaration\n ? importBindings(statement)\n : statement.type === nodeTypes.variableDeclaration\n ? requireBindings(statement)\n : []\n if (!bindings.length || bindings.some(([, { from }]) => from !== packageName)) return current\n\n const rest = replaceText(current, statement.start, statement.end)\n if (bindings.some(([local]) => new RegExp(`(?<![\\\\w$])${local.replaceAll('$', '\\\\$')}(?![\\\\w$])`).test(rest))) return current\n\n const lineStart = current.lastIndexOf('\\n', statement.start - 1) + 1\n const lineEnd = current.indexOf('\\n', statement.end)\n const after = lineEnd === -1 ? current.length : lineEnd + 1\n // At the top of the file, the blank line after the import goes too, so the file does not start with one.\n return replaceText(current, lineStart, lineStart === 0 && current[after] === '\\n' ? after + 1 : after)\n }, source)\n}\n\n/**\n * Removes every call of a plugin or parser package, and the block `disable-plugin` commented out,\n * then its unused imports. Removing what the config does not hold is a no-op. Refuses to empty\n * `parsers`, since a config with no parser cannot print files.\n */\nfunction removeExtension(source: string, edit: RemoveExtensionEdit): EditResult {\n const kind = edit.kind ?? extensionKinds.plugin\n let current = source\n\n // One call at a time, re-parsing in between, since each removal moves the ones after it.\n for (;;) {\n const parsed = findConfigs(current)\n if ('reason' in parsed) return parsed\n const config = findConfigEntry(parsed.configs, edit.config)\n if (!config) return { reason: `no config entry found for ${JSON.stringify(edit.config)}` }\n\n const array = getValue(config, `${kind}s`)\n const calls = findCalls(parsed.program, config, kind).filter((entry) => entry.packageName === edit.plugin)\n const block = findDisabled(current, parsed.comments, config).find((entry) => entry.packageName === edit.plugin)\n\n if (calls[0] && array?.type === nodeTypes.arrayExpression) {\n const elements = array.elements.filter((element) => element !== null)\n if (kind === extensionKinds.parser && elements.length === calls.length) return { reason: `${edit.plugin} is the last parser in the parsers array` }\n current = removeItem(current, array, elements.indexOf(calls[0].call))\n continue\n }\n if (block && kind === extensionKinds.plugin) {\n const lines = current.split('\\n')\n lines.splice(block.line - 1, block.end - block.line + 1)\n current = lines.join('\\n')\n continue\n }\n return { source: current === source ? source : removeUnusedImports(current, edit.plugin) }\n }\n}\n\n// Applying edits\n\n/** Every edit re-parses the file, since the previous one rewrote it. */\nfunction applyEdit({ source, edit, extensions }: { source: string; edit: ConfigEdit; extensions: InstalledExtensions }): EditResult {\n const parsed = findConfigs(source)\n if ('reason' in parsed) return parsed\n\n const config = findConfigEntry(parsed.configs, edit.config)\n if (!config) return { reason: `no config entry found for ${JSON.stringify(edit.config)}` }\n const quote = detectQuote(parsed.program) ?? quotes.single\n\n switch (edit.operation) {\n case ConfigEditOperation.SET_INPUT:\n return setInput(source, config, edit.input, quote)\n case ConfigEditOperation.SET_OUTPUT:\n case ConfigEditOperation.REMOVE_OUTPUT:\n return editOutput({ source, config, edit, quote })\n case ConfigEditOperation.DISABLE_PLUGIN:\n return disablePluginInConfig({ source, parsed, config, edit })\n case ConfigEditOperation.ENABLE_PLUGIN:\n return enablePlugin(source, parsed.comments, config, edit.plugin)\n case ConfigEditOperation.ADD_PLUGIN:\n return addPlugin({ source, parsed, config, edit, quote, extensions })\n case ConfigEditOperation.REMOVE_EXTENSION:\n return removeExtension(source, edit)\n case ConfigEditOperation.SET_OPTION:\n case ConfigEditOperation.REMOVE_OPTION:\n return editOption({ source, parsed, config, edit, quote, extensions })\n }\n}\n\n/** Applies edits in place, touching only the text each targets. A refused edit is reported and the rest still run. */\nexport function editConfig({ source, edits, extensions = new Map() }: { source: string; edits: Array<ConfigEdit>; extensions?: InstalledExtensions }): {\n source: string\n outcomes: Array<ConfigEditOutcome>\n changed: boolean\n} {\n let current = source\n\n const outcomes = edits.map((edit): ConfigEditOutcome => {\n try {\n const invalid = validateEdit(edit)\n if (invalid) return { edit, applied: false, reason: invalid }\n\n const result = applyEdit({ source: current, edit, extensions })\n if ('reason' in result) return { edit, applied: false, reason: result.reason }\n current = result.source\n return { edit, applied: true }\n } catch (error) {\n return { edit, applied: false, reason: getErrorMessage(error) }\n }\n })\n\n return { source: current, outcomes, changed: current !== source }\n}\n\n/** Applies `edits` to `filePath`, writing only when something changed. */\nexport async function editConfigFile({ filePath, edits, extensions }: { filePath: string; edits: Array<ConfigEdit>; extensions?: InstalledExtensions }) {\n const current = await read(filePath)\n const result = editConfig({ source: current, edits, extensions })\n if (result.changed) await writeRaw(filePath, result.source)\n return result\n}\n","import { structuredPatch, type StructuredPatchHunk } from 'diff'\nimport type { DiffHunk, DiffStats } from './protocol.ts'\n\nconst CONTEXT_LINES = 3\n// Past this, each remaining segment shows as one replace block.\nconst DIFF_TIMEOUT_MS = 1_000\n\n// Lines keep their `\\n`, so a last line without one differs from the same line with one.\nconst splitLines = (text: string) => (text === '' ? [] : text.split(/(?<=\\n)/))\n\n// Longest increasing subsequence of `values`, as indexes into it.\nfunction longestIncreasing(values: Array<number>): Array<number> {\n const tails: Array<number> = []\n const prev: Array<number> = []\n for (const [index, value] of values.entries()) {\n let low = 0\n let high = tails.length\n while (low < high) {\n const mid = (low + high) >> 1\n if (values[tails[mid]!]! < value) low = mid + 1\n else high = mid\n }\n prev[index] = low > 0 ? tails[low - 1]! : -1\n tails[low] = index\n }\n const result: Array<number> = []\n for (let index = tails.at(-1) ?? -1; index !== -1; index = prev[index]!) result.push(index)\n return result.reverse()\n}\n\n// Where to cut both files so each segment diffs on its own: inside each unchanged stretch that keeps a full\n// context on both sides, so no hunk crosses a cut. Lines that occur once in each file, in the same order, find them.\nfunction cutPoints(before: Array<string>, after: Array<string>): Array<[number, number]> {\n const counts = new Map<string, { before: number; after: number; index: number }>()\n for (const [index, line] of before.entries()) {\n const count = counts.get(line)\n if (count) count.before++\n else counts.set(line, { before: 1, after: 0, index })\n }\n const afterIndex = new Map<string, number>()\n for (const [index, line] of after.entries()) {\n const count = counts.get(line)\n if (!count) continue\n count.after++\n afterIndex.set(line, index)\n }\n // Map order is insertion order, so these are sorted by their index in `before`.\n const unique = [...counts]\n .filter(([, count]) => count.before === 1 && count.after === 1)\n .map(([line, count]) => [count.index, afterIndex.get(line)!] as const)\n const anchors = longestIncreasing(unique.map(([, index]) => index)).map((index) => unique[index]!)\n\n const cuts: Array<[number, number]> = [[0, 0]]\n let run = { before: 0, after: 0, length: 0 }\n const closeRun = () => {\n if (run.length > 2 * CONTEXT_LINES) cuts.push([run.before + CONTEXT_LINES, run.after + CONTEXT_LINES])\n }\n let i = 0\n let j = 0\n for (const [anchorBefore, anchorAfter] of anchors) {\n // The lines between two anchors are unchanged when both sides hold the same lines.\n const unchanged = anchorBefore - i === anchorAfter - j && before.slice(i, anchorBefore).every((line, offset) => line === after[j + offset])\n if (unchanged && run.length && run.before + run.length === i) {\n run.length += anchorBefore - i + 1\n } else {\n closeRun()\n run = unchanged ? { before: i, after: j, length: anchorBefore - i + 1 } : { before: anchorBefore, after: anchorAfter, length: 1 }\n }\n i = anchorBefore + 1\n j = anchorAfter + 1\n }\n closeRun()\n cuts.push([before.length, after.length])\n return cuts\n}\n\n// A segment with no time left to diff shows as one block that replaces everything between its shared first and last lines.\nfunction replaceHunk(before: Array<string>, after: Array<string>): Array<StructuredPatchHunk> {\n let start = 0\n while (start < before.length && start < after.length && before[start] === after[start]) start++\n let end = 0\n while (end < before.length - start && end < after.length - start && before[before.length - 1 - end] === after[after.length - 1 - end]) end++\n const removed = before.slice(start, before.length - end)\n const added = after.slice(start, after.length - end)\n if (!removed.length && !added.length) return []\n\n const lines = (prefix: string, rows: Array<string>) =>\n rows.flatMap((row) => (row.endsWith('\\n') ? [`${prefix}${row.slice(0, -1)}`] : [`${prefix}${row}`, '\\\']))\n // Same numbering as `structuredPatch`, which starts an empty side at line 1 too.\n return [{ oldStart: start + 1, oldLines: removed.length, newStart: start + 1, newLines: added.length, lines: [...lines('-', removed), ...lines('+', added)] }]\n}\n\n// One Myers diff over a whole file grows with lines times changes and stalls on large specs, so each segment\n// between cuts is diffed on its own.\nexport function diffHunks(before: string, after: string, timeout = DIFF_TIMEOUT_MS): { hunks: Array<StructuredPatchHunk>; stats: DiffStats } {\n const beforeLines = splitLines(before)\n const afterLines = splitLines(after)\n const cuts = cutPoints(beforeLines, afterLines)\n const deadline = Date.now() + timeout\n\n const hunks: Array<StructuredPatchHunk> = []\n let coarse = false\n for (const [index, [beforeStart, afterStart]] of cuts.slice(0, -1).entries()) {\n const [beforeEnd, afterEnd] = cuts[index + 1]!\n const segmentBefore = beforeLines.slice(beforeStart, beforeEnd)\n const segmentAfter = afterLines.slice(afterStart, afterEnd)\n const patch = structuredPatch('', '', segmentBefore.join(''), segmentAfter.join(''), undefined, undefined, {\n context: CONTEXT_LINES,\n timeout: Math.max(0, deadline - Date.now()),\n })\n if (!patch) coarse = true\n for (const hunk of patch?.hunks ?? replaceHunk(segmentBefore, segmentAfter)) {\n hunks.push({ ...hunk, oldStart: hunk.oldStart + beforeStart, newStart: hunk.newStart + afterStart })\n }\n }\n\n const lines = hunks.flatMap((hunk) => hunk.lines)\n const stats: DiffStats = {\n additions: lines.filter((line) => line[0] === '+').length,\n deletions: lines.filter((line) => line[0] === '-').length,\n hunks: hunks.length,\n lines: lines.length,\n coarse,\n }\n return { hunks, stats }\n}\n\n// Pages hold whole hunks, so a hunk is cut only when it alone is longer than a page. Its parts share its `index`.\nexport function pageHunks({ hunks, cursor, limit }: { hunks: Array<StructuredPatchHunk>; cursor: number; limit: number }): {\n hunks: Array<DiffHunk>\n nextCursor: number | null\n} {\n const page: Array<DiffHunk> = []\n let used = 0\n let start = 0\n for (const [index, hunk] of hunks.entries()) {\n const offset = Math.max(0, cursor - start)\n start += hunk.lines.length\n const remaining = hunk.lines.length - offset\n if (remaining <= 0) continue\n if (used > 0 && remaining > limit - used) break\n let take = Math.min(remaining, limit - used)\n // A `\\ No newline` marker stays with its line, so no part starts with one.\n if (hunk.lines[offset + take]?.startsWith('\\\\')) take++\n page.push({ index, ...hunk, lines: hunk.lines.slice(offset, offset + take) })\n used += take\n if (used >= limit) break\n }\n const total = hunks.reduce((sum, hunk) => sum + hunk.lines.length, 0)\n return { hunks: page, nextCursor: cursor + used < total ? cursor + used : null }\n}\n","import { createHash, randomUUID } from 'node:crypto'\nimport { isAbsolute, relative, resolve, sep } from 'node:path'\nimport process from 'node:process'\nimport { inParallel } from '@internals/utils'\nimport { ast, type InputNode } from '@kubb/ast'\nimport { type Config, createKubb, type Diagnostic, Diagnostics, fsStorage, type Hookable, type KubbHooks, type Storage } from '@kubb/core'\nimport { type FilePage, type ReadFilesResult } from './protocol.ts'\n\nconst READ_CONCURRENCY = 50\nconst MB = 1024 * 1024\nconst INDEX_KEY = 'studio/generations.json'\n\n/**\n * Files a run produced, or the output directory held, keyed by path relative to `root`.\n */\nexport type SourceFiles = { storage: Storage; root: string; paths: Set<string> }\n\n/**\n * The path form {@link SourceFiles} keys on: relative to `root`, with forward slashes.\n */\nexport function relativeStoragePath({ root, filePath }: { root: string; filePath: string }): string {\n return (isAbsolute(filePath) ? relative(resolve(root), filePath) : filePath).replaceAll('\\\\', '/')\n}\n\n/**\n * A set as kept in the store.\n */\ntype KeptSet = {\n /**\n * The paths a read is checked against. Empty when the set was too large to keep its content.\n */\n paths: Array<string>\n hashes: Record<string, string>\n bytes: number\n}\n\ntype KeptGeneration = {\n jobId: string\n initial?: boolean\n /** When the store took it, in epoch milliseconds. Absent on an index written before it existed. */\n keptAt?: number\n output: KeptSet\n inputBytes?: number\n}\n\n/**\n * The content fingerprint Studio compares snapshots by. Agent runs and CI uploads must agree on it.\n */\nexport const hashOf = (content: string) => createHash('sha1').update(content).digest('hex').slice(0, 16)\n\n/**\n * The bytes `entries` keep on disk: output, written files, and kept input.\n */\nconst totalBytes = (entries: Array<KeptGeneration>) => entries.reduce((sum, { output, inputBytes }) => sum + output.bytes + (inputBytes ?? 0), 0)\n\nfunction positiveNumber(value: string | undefined): number | undefined {\n const parsed = Number(value)\n return value && Number.isFinite(parsed) && parsed > 0 ? parsed : undefined\n}\n\n/**\n * How many generations an agent keeps and how large they may get, read from\n * `KUBB_AGENT_MAX_GENERATIONS` and `KUBB_AGENT_MAX_GENERATIONS_MB`.\n * An unset or invalid value keeps the default.\n */\nexport function resolveGenerationLimits(): { maxCount: number; maxMb: number } {\n return {\n maxCount: Math.max(1, Math.floor(positiveNumber(process.env.KUBB_AGENT_MAX_GENERATIONS) ?? 8)),\n maxMb: positiveNumber(process.env.KUBB_AGENT_MAX_GENERATIONS_MB) ?? 100,\n }\n}\n\n/**\n * Folds error-severity diagnostics into one thrown error so logs name the failing plugin or pass.\n */\nexport function generationFailure(diagnostics: ReadonlyArray<Diagnostic>): Error {\n const reasons = diagnostics\n .filter(Diagnostics.isProblem)\n .filter((diagnostic) => diagnostic.severity === 'error')\n .map((diagnostic) => (diagnostic.plugin ? `${diagnostic.plugin}: ${diagnostic.message}` : diagnostic.message))\n\n if (!reasons.length) return new Error('Generation failed')\n\n return new Error(`Generation failed: ${reasons.length} error${reasons.length === 1 ? '' : 's'}: ${reasons.join('; ')}`)\n}\n\n/**\n * Runs one generation and returns the files it produced. The formatter, the linter, and\n * `output.postGenerate` only run with `allowExec`. Throws when any plugin reports an error.\n */\nexport async function generate({\n config,\n hooks,\n signal,\n allowExec,\n fileRefs,\n}: {\n config: Config\n hooks?: Hookable<KubbHooks>\n signal?: AbortSignal\n allowExec: boolean\n fileRefs?: Array<string>\n}): Promise<SourceFiles & { input: InputNode | null }> {\n const output = allowExec ? config.output : { ...config.output, format: false as const, lint: false as const, postGenerate: [] }\n const kubb = createKubb({ ...config, output }, { hooks, signal, fileRefs })\n const result = await kubb.generate()\n if (!result.success) throw generationFailure(result.diagnostics)\n\n // `kubb.config` carries the defaults, such as the fs storage a config loaded by the CLI leaves unset.\n const { storage, root } = kubb.config\n return {\n storage,\n root,\n paths: new Set(result.files.map((file) => relativeStoragePath({ root, filePath: file.path }))),\n input: result.input,\n }\n}\n\n/**\n * What the output directory holds when the editor connects. `undefined` when `outputPath` is not a real\n * subdirectory of `root` (listing the root would take in every source file) or holds more than `maxFiles`.\n */\nexport async function listDisk({ root, outputPath, maxFiles }: { root: string; outputPath: string; maxFiles: number }): Promise<SourceFiles | undefined> {\n const outputDir = resolve(root, outputPath)\n const fromRoot = relative(resolve(root), outputDir)\n if (!fromRoot || fromRoot.startsWith('..') || fromRoot.startsWith(sep)) return undefined\n\n const storage = fsStorage()\n const keys = await storage.readKeys(outputDir)\n if (keys.length > maxFiles) return undefined\n\n const paths = keys\n .filter((key) => !key.split('/').includes('node_modules'))\n .map((key) => relative(resolve(root), resolve(outputDir, key)).replaceAll('\\\\', '/'))\n return { storage, root, paths: new Set(paths) }\n}\n\n/**\n * Keeps recent generations by job id in `storage`, with an index next to them so a store on disk\n * survives a restart. A generation is only ever looked up by its job id, so on a pooled sandbox one\n * tenant never reaches another's output. Initial disk output and generated jobs each get their\n * own `maxCount` and `maxMb` budget. Each budget always keeps its newest entry.\n */\nexport function createGenerationStore({\n storage,\n maxCount,\n maxMb,\n ttlMs,\n now = Date.now,\n}: {\n storage: Storage\n maxCount: number\n maxMb: number\n /** How long a generation stays readable. Unset, it stays until count or size pushes it out. */\n ttlMs?: number\n now?: () => number\n}) {\n let index: Array<KeptGeneration> | undefined\n\n // An entry from before `keptAt` existed never expires, so upgrading drops nothing.\n const isLive = (generation: KeptGeneration) => ttlMs === undefined || generation.keptAt === undefined || now() - generation.keptAt < ttlMs\n\n // Hashed so a job id from the wire can never point outside the store.\n const dirOf = (jobId: string) => `studio/generations/${hashOf(jobId)}/`\n\n async function load(): Promise<Array<KeptGeneration>> {\n if (index) return index\n const stored = await storage.readItem(INDEX_KEY).catch(() => null)\n try {\n index = stored ? (JSON.parse(stored) as Array<KeptGeneration>) : []\n } catch {\n index = []\n }\n return index\n }\n\n /**\n * Copies `files` into the store as one set of `jobId`. Above `maxSetMb` only the hashes are kept.\n */\n async function keep({ jobId, files, maxSetMb }: { jobId: string; files: SourceFiles; maxSetMb: number }): Promise<KeptSet> {\n const maxSetBytes = maxSetMb * MB\n const hashes: Record<string, string> = {}\n let bytes = 0\n await inParallel({\n items: [...files.paths],\n limit: READ_CONCURRENCY,\n run: async (path) => {\n // Output outside the root would land outside the store too.\n if (path.split('/').includes('..')) return\n const content = await files.storage.readItem(resolve(files.root, path))\n if (content === null) return\n hashes[path] = hashOf(content)\n bytes += Buffer.byteLength(content)\n if (bytes <= maxSetBytes) await storage.writeItem(`${dirOf(jobId)}output/${path}`, content)\n },\n })\n if (bytes > maxSetBytes) {\n await storage.empty(`${dirOf(jobId)}output/`)\n return { paths: [], hashes, bytes: 0 }\n }\n return { paths: Object.keys(hashes), hashes, bytes }\n }\n\n async function drop(jobId: string): Promise<void> {\n await storage.empty(dirOf(jobId))\n }\n\n async function add(generation: KeptGeneration): Promise<void> {\n const current = await load()\n for (const expired of current.filter((entry) => !isLive(entry))) await drop(expired.jobId)\n const live = current.filter((entry) => entry.jobId !== generation.jobId && isLive(entry))\n const sharesBudget = (entry: KeptGeneration) => Boolean(entry.initial) === Boolean(generation.initial)\n const entries = live.filter(sharesBudget)\n entries.push({ ...generation, keptAt: now() })\n while (entries.length > 1 && (entries.length > maxCount || totalBytes(entries) > maxMb * MB)) {\n await drop(entries.shift()!.jobId)\n }\n index = [...live.filter((entry) => !sharesBudget(entry)), ...entries]\n await storage.writeItem(INDEX_KEY, JSON.stringify(index))\n }\n\n return {\n keep,\n drop,\n /**\n * Captures initial disk output, reusing a retained ID when its hashes and readable paths match.\n * A temporary candidate is discarded on reuse, so reconnects do not consume retention slots.\n */\n async keepInitial(files: SourceFiles): Promise<KeptGeneration> {\n const jobId = randomUUID()\n const output = await keep({ jobId, files, maxSetMb: maxMb })\n const hashes = Object.entries(output.hashes)\n const previous = (await load()).findLast(\n (entry) =>\n entry.initial &&\n isLive(entry) &&\n entry.output.paths.length === output.paths.length &&\n Object.keys(entry.output.hashes).length === hashes.length &&\n hashes.every(([path, hash]) => entry.output.hashes[path] === hash),\n )\n if (previous) {\n await drop(jobId)\n await add(previous)\n return previous\n }\n const generation = { jobId, output, initial: true }\n await add(generation)\n return generation\n },\n /**\n * Keeps the `InputNode` of `jobId` and returns its size in bytes, or 0 when it keeps none. A ref schema loses\n * the copy of its target, which `input.schemas` holds: with it, a large spec outgrows what `JSON.stringify` can return.\n */\n async keepInput({ jobId, input, maxSetMb }: { jobId: string; input: InputNode | null; maxSetMb: number }): Promise<number> {\n if (!input) return 0\n let json: string\n try {\n json = JSON.stringify(\n ast.node.transform(input, { schema: (node) => (node.type === 'ref' && node.schema ? { ...node, schema: undefined } : undefined) }),\n )\n } catch {\n // An adapter can return what JSON cannot hold, which must not fail a finished generation.\n return 0\n }\n const bytes = Buffer.byteLength(json)\n if (bytes > maxSetMb * MB) return 0\n await storage.writeItem(`${dirOf(jobId)}input.json`, json)\n return bytes\n },\n /**\n * The input `keepInput` kept for `jobId`, or `undefined` when there is none.\n */\n async readInput(jobId: string): Promise<InputNode | undefined> {\n const stored = await storage.readItem(`${dirOf(jobId)}input.json`)\n return stored === null ? undefined : (JSON.parse(stored) as InputNode)\n },\n get: async (jobId: string) => (await load()).find((generation) => generation.jobId === jobId && isLive(generation)),\n add,\n /**\n * Reads the requested paths the set holds, skipping any it does not, one page of lines when `limit` is given.\n */\n async read({\n generation,\n paths,\n cursor = 0,\n limit,\n }: {\n generation: KeptGeneration\n paths: Array<string>\n cursor?: number\n limit?: number\n }): Promise<ReadFilesResult> {\n const kept = new Set(generation.output.paths)\n const files: Record<string, string> = {}\n const pages: Record<string, FilePage> = {}\n await inParallel({\n items: paths.filter((path) => kept.has(path)),\n limit: READ_CONCURRENCY,\n run: async (path) => {\n const content = await storage.readItem(`${dirOf(generation.jobId)}output/${path}`)\n if (content === null) return\n if (limit === undefined) {\n files[path] = content\n return\n }\n const lines = content.split(/\\r\\n|\\r|\\n/)\n const end = Math.min(cursor + limit, lines.length)\n files[path] = lines.slice(cursor, end).join('\\n')\n pages[path] = { nextCursor: end < lines.length ? end : null, totalLines: lines.length }\n },\n })\n return limit === undefined ? { files } : { files, pages }\n },\n }\n}\n\nexport type GenerationStore = ReturnType<typeof createGenerationStore>\n","import { stripVTControlCharacters } from 'node:util'\nimport type { Hookable, KubbHooks } from '@kubb/core'\nimport { type GenerationEvent, type GenerationEventPayloads, type GenerationEventType, generationEventTypes } from './protocol.ts'\nimport { relativeStoragePath } from './generations.ts'\n\n/** How each published hook's context becomes its wire payload; a hook without a projection fails to compile. */\ntype Projections = { [Type in GenerationEventType]: (...args: KubbHooks[Type]) => GenerationEventPayloads[Type] }\n\nconst MAX_QUEUED_EVENTS = 1_024\nconst RESERVED_EVENTS = 64\nconst isDiscardable = (type: GenerationEventType) => type === 'kubb:files:processing:update' || type === 'kubb:info' || type === 'kubb:success'\n\n/** Forwards selected Kubb lifecycle events to a native Cap'n Web stream. */\nexport function createGenerationStream(\n hooks: Hookable<KubbHooks>,\n jobId: string,\n): { stream: ReadableStream<GenerationEvent>; close: () => Promise<void>; fail: (error?: unknown) => void } {\n const unhooks: Array<() => void> = []\n let root = ''\n let controller!: ReadableStreamDefaultController<GenerationEvent>\n let closed = false\n const stream = new ReadableStream<GenerationEvent>(\n {\n start: (value) => {\n controller = value\n },\n cancel: () => {\n closed = true\n detach()\n },\n },\n { highWaterMark: MAX_QUEUED_EVENTS },\n )\n\n /**\n * Registers a listener and keeps its remover, so one generation's listeners come off the session\n * emitter again when that generation ends.\n */\n function on<TName extends keyof KubbHooks & string>(name: TName, handler: (...args: KubbHooks[TName]) => unknown): void {\n unhooks.push(hooks.hook(name, handler))\n }\n\n function emitEvent<Type extends GenerationEventType>(type: Type, data: GenerationEventPayloads[Type]): void {\n if (closed) return\n const event = { jobId, type, data, version: 1 as const, timestamp: Date.now() } as unknown as GenerationEvent\n if (controller.desiredSize! <= RESERVED_EVENTS && isDiscardable(type)) return\n if (controller.desiredSize! <= 0) {\n fail(new Error(`Generation event stream exceeded ${MAX_QUEUED_EVENTS} queued events`))\n return\n }\n controller.enqueue(event)\n }\n\n const projections: Projections = {\n 'kubb:plugin:start': ({ plugin }) => [{ plugin: { name: plugin.name } }],\n 'kubb:plugin:end': ({ plugin, duration, success }) => [{ plugin: { name: plugin.name }, duration, success }],\n 'kubb:build:start': ({ config, adapter }) => [{ config: { name: config.name }, adapter: { name: adapter.name } }],\n 'kubb:build:end': ({ files, config, outputDir }) => [\n { files: files.map((file) => ({ path: relativeStoragePath({ root: config.root, filePath: file.path }), name: file.name })), outputDir },\n ],\n 'kubb:files:processing:start': ({ files }) => [{ total: files.length }],\n 'kubb:files:processing:update': ({ files }) => [\n {\n files: files.map(({ file, processed, total, percentage }) => ({\n file: relativeStoragePath({ root, filePath: file.path }),\n processed,\n total,\n percentage,\n })),\n },\n ],\n 'kubb:files:processing:end': ({ files }) => [{ total: files.length }],\n 'kubb:info': ({ message, info }) => [{ message: stripVTControlCharacters(message), info }],\n 'kubb:success': ({ message, info }) => [{ message: stripVTControlCharacters(message), info }],\n 'kubb:warn': ({ message, info }) => [{ message: stripVTControlCharacters(message), info }],\n 'kubb:error': ({ error }) => [{ message: error.message, stack: error.stack }],\n 'kubb:diagnostic': ({ diagnostic }) => [\n {\n code: diagnostic.code,\n message: diagnostic.message,\n severity: diagnostic.severity,\n location: 'location' in diagnostic ? diagnostic.location : undefined,\n help: 'help' in diagnostic ? diagnostic.help : undefined,\n plugin: 'plugin' in diagnostic ? diagnostic.plugin : undefined,\n stack: 'cause' in diagnostic ? diagnostic.cause?.stack : undefined,\n },\n ],\n 'kubb:generation:start': ({ config }) => [{ name: config.name, plugins: config.plugins.length }],\n 'kubb:generation:end': () => [],\n 'kubb:generation:summary': ({ duration, fileCount, failedPlugins, status }) => [{ duration, fileCount, failedPlugins, status }],\n 'kubb:lifecycle:start': () => [],\n 'kubb:lifecycle:end': () => [],\n 'kubb:format:start': () => [],\n 'kubb:format:end': () => [],\n 'kubb:lint:start': () => [],\n 'kubb:lint:end': () => [],\n 'kubb:hooks:start': () => [],\n 'kubb:hooks:end': () => [],\n 'kubb:hook:start': ({ id, command, args }) => [{ id, command, args: args ? [...args] : undefined }],\n 'kubb:hook:line': ({ id, line }) => [{ id, line }],\n 'kubb:hook:end': ({ id, command, args, success, error }) => [\n { id, command, args: args ? [...args] : undefined, success, error: error ? { message: error.message, stack: error.stack } : undefined },\n ],\n }\n\n function forward<Type extends GenerationEventType>(type: Type): void {\n on(type, (...args: KubbHooks[Type]) => {\n emitEvent(type, projections[type](...args))\n // Generators render in memory without awaiting I/O, so the socket only sends once the event loop gets a turn.\n if (!isDiscardable(type)) return new Promise<void>((resolve) => setImmediate(resolve))\n })\n }\n\n // Paths in `kubb:files:processing:update` are made relative to the root the build announced.\n on('kubb:build:start', ({ config }) => {\n root = config.root\n })\n\n for (const type of generationEventTypes) forward(type)\n\n /**\n * Takes this generation's listeners off the session emitter. Safe to call twice.\n */\n function detach(): void {\n for (const unhook of unhooks) unhook()\n unhooks.length = 0\n }\n\n async function close(): Promise<void> {\n if (closed) {\n return\n }\n closed = true\n detach()\n controller.close()\n }\n\n function fail(error?: unknown): void {\n detach()\n if (closed) {\n return\n }\n closed = true\n controller.error(error)\n }\n\n return { stream, close, fail }\n}\n","import dns from 'node:dns'\nimport http from 'node:http'\nimport https from 'node:https'\nimport net from 'node:net'\nimport { Readable, Transform } from 'node:stream'\nimport { isPublicAddress } from '@kubb/core'\n\nconst MAX_REDIRECTS = 5\nconst MAX_BYTES = 50 * 1024 * 1024\nconst REDIRECTS = new Set([301, 302, 303, 307, 308])\nconst NO_BODY = new Set([204, 205, 304])\n\nfunction notPublic(host: string): Error {\n return new Error(`${host} is not a public address, so this agent does not fetch from it`)\n}\n\nfunction createLookup(blocked?: net.BlockList): net.LookupFunction {\n return (hostname, options, callback) => {\n dns.lookup(hostname, { ...options, all: true }, (error, addresses) => {\n if (error) return callback(error, '', 0)\n const found = addresses as Array<dns.LookupAddress>\n // One private answer is enough to refuse, so a name cannot mix a public and a private record.\n if (!found.length || found.some(({ address }) => !isPublicAddress(address, blocked))) return callback(notPublic(hostname), '', 0)\n return options.all ? callback(null, found) : callback(null, found[0]!.address, found[0]!.family)\n })\n }\n}\n\nfunction request({ url, blocked, signal }: { url: URL; blocked?: net.BlockList; signal?: AbortSignal | null }): Promise<Response> {\n if (url.protocol !== 'http:' && url.protocol !== 'https:') return Promise.reject(new Error(`Only http and https URLs are fetched, not ${url.protocol}`))\n // An IP literal skips the lookup below, so it is checked here.\n const host = url.hostname.replace(/^\\[|\\]$/g, '')\n if (net.isIP(host) && !isPublicAddress(host, blocked)) return Promise.reject(notPublic(host))\n\n return new Promise((resolve, reject) => {\n const send = url.protocol === 'https:' ? https.request : http.request\n // `lookup` runs for the connection itself, so a name that changes its answer after a check cannot reach a blocked address.\n const req = send(url, { method: 'GET', lookup: createLookup(blocked), signal: signal ?? undefined, headers: { 'accept-encoding': 'identity' } }, (res) => {\n const headers = new Headers()\n for (const [key, value] of Object.entries(res.headers)) {\n for (const item of [value].flat()) if (item !== undefined) headers.append(key, item)\n }\n let total = 0\n const limit = new Transform({\n transform(chunk: Buffer, _encoding, done) {\n total += chunk.length\n done(total > MAX_BYTES ? new Error('The response is larger than 50 MB') : null, chunk)\n },\n })\n res.on('error', (error) => limit.destroy(error))\n res.pipe(limit)\n const body = NO_BODY.has(res.statusCode ?? 0) ? null : (Readable.toWeb(limit) as unknown as ReadableStream)\n resolve(new Response(body, { status: res.statusCode, statusText: res.statusMessage, headers }))\n })\n req.on('error', reject)\n req.end()\n })\n}\n\n/**\n * Builds a `fetch` that only reaches addresses `blocked` does not list. It follows redirects itself\n * and checks every hop, and takes GET requests only, since that is all a spec load needs.\n */\nexport function createPublicFetch(blocked?: net.BlockList): typeof fetch {\n const publicFetch = async (input: Parameters<typeof fetch>[0], init?: RequestInit): Promise<Response> => {\n if (typeof input !== 'string' && !(input instanceof URL)) throw new TypeError('This agent fetches by URL only')\n if (init?.method && init.method.toUpperCase() !== 'GET') throw new TypeError('This agent only sends GET requests')\n\n let url = new URL(input)\n for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {\n const response = await request({ url, blocked, signal: init?.signal })\n const location = response.headers.get('location')\n if (!REDIRECTS.has(response.status) || !location) return response\n await response.body?.cancel()\n url = new URL(location, url)\n }\n throw new Error(`Stopped after ${MAX_REDIRECTS} redirects from ${String(input)}`)\n }\n return publicFetch as typeof fetch\n}\n\n/**\n * Runs `run` with the global `fetch` limited to public addresses, then puts the original back.\n * A sandbox or managed agent runs one job at a time, so nothing else shares the window.\n */\nexport async function withPublicFetch<T>(run: () => Promise<T>): Promise<T> {\n const original = globalThis.fetch\n globalThis.fetch = createPublicFetch()\n try {\n return await run()\n } finally {\n globalThis.fetch = original\n }\n}\n","import { existsSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport path from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { type Adapter, type Config, Diagnostics, type ExtensionKind, getInputKind, type Parser, type Plugin, resolveMeta } from '@kubb/core'\nimport { isAllowedPlugin, isOptionValue, isOutputKey, isOutputValue, isPlainObject, isSafeKey, toExportName, toPluginName } from '@internals/shared'\nimport { isPathInside, toError } from '@internals/utils'\nimport type { AgentType, InstalledExtensions, JSONKubbConfig } from './protocol.ts'\n\n/**\n * Turns the JSON config Studio sends back into live Kubb objects.\n *\n * A plugin or adapter instance carries closures (`parse`, `getImports`, ...) that cannot survive\n * JSON, so both sides pass options over the wire and the factory is re-invoked here with the merged\n * result. Only packages {@link isAllowedPlugin} accepts are resolved this way, never an arbitrary\n * module the payload names.\n */\n\n/**\n * Imports a package, falling back to how the user's project would resolve it.\n *\n * `import()` resolves from this file, so a linked or globally installed Studio (`pnpm link`,\n * `npm i -g`) only sees its own `node_modules` and misses the plugins installed next to the user's\n * config. The retry resolves from `process.cwd()` instead.\n */\nasync function importFromProject(packageName: string): Promise<Record<string, unknown>> {\n try {\n return await import(packageName)\n } catch {\n const requireModule = createRequire(pathToFileURL(`${process.cwd()}/`))\n // `requireModule.resolve` picks the package's `require` condition, so prefer the ESM build sitting\n // next to it. Loading the CJS copy would pull in a second `@kubb/core` instance.\n const resolved = requireModule.resolve(packageName)\n const esm = resolved.replace(/\\.cjs$/, '.js')\n\n return await import(pathToFileURL(esm !== resolved && existsSync(esm) ? esm : resolved).href)\n }\n}\n\n/**\n * Adds the `@kubb/` scope a plugin's package carries but its `name` does not, the inverse of\n * {@link toPluginName}. A name outside the `plugin-` convention is left alone, so a third-party\n * plugin is not reported as one of Kubb's.\n *\n * @example\n * ```ts\n * toPackageName('plugin-ts') // '@kubb/plugin-ts'\n * toPackageName('@acme/my-plugin') // '@acme/my-plugin'\n * ```\n */\nexport function toPackageName(name: string): string {\n return name.startsWith('plugin-') ? `@kubb/${name}` : name\n}\n\n/**\n * The name Studio knows an extension by: the package of the installed extension whose manifest\n * `name` matches, otherwise its own `name`, so a plugin defined in the user's project is never\n * reported as a Kubb package that does not exist.\n *\n * @example\n * ```ts\n * toStudioName({ name: 'plugin-ts', extensions }) // '@kubb/plugin-ts'\n * toStudioName({ name: 'plugin-zod-operations', extensions }) // 'plugin-zod-operations', a local plugin\n * ```\n */\nexport function toStudioName({\n name,\n extensions = new Map(),\n kind = 'plugin',\n}: {\n name: string\n extensions?: InstalledExtensions\n kind?: ExtensionKind\n}): string {\n return [...extensions.values()].find(({ manifest }) => manifest.kind === kind && manifest.name === name)?.package ?? name\n}\n\n/**\n * Dynamically imports an extension package and returns its factory. Callers check\n * {@link isAllowedPlugin} or derive the package from a disk instance first, so an arbitrary module\n * never reaches `import()`.\n *\n * Packages must be pre-installed in the Docker image at build time via the `KUBB_PACKAGES`\n * build ARG, no runtime installation is possible in the distroless container.\n *\n * Resolution order: the manifest's `export`, else the camelCase named export the package name\n * implies (e.g. `pluginTs`), then the default export.\n *\n * @throws if the package cannot be imported or exports no callable factory.\n */\nasync function loadFactory({\n packageName,\n extensions,\n kind = 'plugin',\n}: {\n packageName: string\n extensions: InstalledExtensions\n kind?: ExtensionKind\n}): Promise<(options: unknown) => unknown> {\n const label = { plugin: 'Plugin', adapter: 'Adapter', parser: 'Parser' }[kind]\n let mod: Record<string, unknown>\n try {\n mod = await importFromProject(packageName)\n } catch (cause) {\n throw new Diagnostics.Error({\n code: kind === 'plugin' ? Diagnostics.code.pluginNotFound : Diagnostics.code.unknown,\n severity: 'error',\n message: `${label} \"${packageName}\" could not be loaded. Make sure it is installed: \\`npm install ${packageName}\\``,\n cause: toError(cause),\n })\n }\n\n const manifestExport = extensions.get(packageName)?.manifest.export\n if (manifestExport) {\n if (typeof mod[manifestExport] === 'function') return mod[manifestExport] as (options: unknown) => unknown\n throw new Diagnostics.Error({\n code: Diagnostics.code.incompatibleExtension,\n severity: 'error',\n message: `${label} \"${packageName}\" does not export \"${manifestExport}\", the factory its kubb-extension.json names.`,\n help: 'Install a version of the plugin whose exports match its kubb-extension.json.',\n })\n }\n\n const exportName = toExportName(packageName)\n if (typeof mod[exportName] === 'function') return mod[exportName] as (options: unknown) => unknown\n if (typeof mod['default'] === 'function') return mod['default'] as (options: unknown) => unknown\n\n throw new Diagnostics.Error({\n code: Diagnostics.code.incompatibleExtension,\n severity: 'error',\n message: `${label} \"${packageName}\" does not export a callable factory. Tried the named export \"${exportName}\" and \"default\".`,\n help: 'Install a Kubb plugin package that exports its factory.',\n })\n}\n\n/**\n * Resolves each plugin entry by dynamically importing its package and calling its factory with the\n * provided options. Only packages {@link isAllowedPlugin} accepts are loaded.\n *\n * @example\n * ```ts\n * const plugins = await resolvePlugins({\n * plugins: [\n * { name: '@kubb/plugin-react-query', options: { output: { path: './hooks' } } },\n * { name: '@kubb/plugin-ts', options: { output: { path: './types' } } },\n * ],\n * })\n * ```\n */\nexport async function resolvePlugins({\n plugins,\n extensions = new Map(),\n}: {\n plugins: NonNullable<JSONKubbConfig['plugins']>\n extensions?: InstalledExtensions\n}): Promise<Array<Plugin>> {\n return Promise.all(\n plugins.map(async ({ name, options }) => {\n if (!isAllowedPlugin({ packageName: name, extensions })) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.pluginNotFound,\n severity: 'error',\n message: `Plugin \"${name}\" is not an installed Kubb plugin. Studio loads @kubb/plugin-* packages and installed packages that ship a kubb-extension.json with kind \"plugin\".`,\n })\n }\n const factory = await loadFactory({ packageName: name, extensions })\n return factory(options ?? {}) as Plugin\n }),\n )\n}\n\n/**\n * A JSON copy of plugin or adapter options: functions and other values JSON cannot hold are left\n * out, so nothing callable crosses the socket. Options that cannot be copied at all, such as a\n * circular structure, come back empty.\n *\n * @example\n * ```ts\n * toJSONOptions({ output: { path: 'types' }, group: { name: () => 'x' } }) // { output: { path: 'types' }, group: {} }\n * ```\n */\nexport function toJSONOptions(options: unknown): Record<string, unknown> {\n try {\n const copy = JSON.parse(\n JSON.stringify(options ?? {}, (key, value: unknown) => (isSafeKey(key) && typeof value !== 'bigint' ? value : undefined)),\n ) as unknown\n return isPlainObject(copy) ? copy : {}\n } catch {\n return {}\n }\n}\n\n/**\n * Deep-merges Studio's options over the disk options, with Studio taking priority, except where the\n * disk value cannot survive JSON. Studio only ever saw a lossy copy of such a value, so the disk\n * value is kept rather than replaced by what Studio echoes back. Plain objects merge key by key, so\n * Studio can still change a literal that sits next to a function (e.g. `group.type` beside `group.name`).\n *\n * @example\n * ```ts\n * mergeOptions({ macros: [camelCaseMacro], syntaxType: 'type' }, { macros: [{ name: 'camelCase' }], syntaxType: 'interface' })\n * // { macros: [camelCaseMacro], syntaxType: 'interface' }\n * mergeOptions({ emptySchemaType: 'any' }, { emptySchemaType: null }) // {}\n * ```\n */\nexport function mergeOptions(disk: Record<string, unknown>, studio: Record<string, unknown>): Record<string, unknown> {\n const merged: Record<string, unknown> = { ...disk }\n\n for (const [key, value] of Object.entries(studio)) {\n if (!isSafeKey(key)) continue\n const current = disk[key]\n\n // A `null` from Studio is a field set back to \"unset\", so the factory default applies again.\n if (value === null) {\n if (current === undefined || isOptionValue(current)) delete merged[key]\n continue\n }\n\n if (isPlainObject(current) && isPlainObject(value)) {\n merged[key] = mergeOptions(current, value)\n continue\n }\n if (current !== undefined && !isOptionValue(current)) continue\n\n merged[key] = value\n }\n\n return merged\n}\n\n/**\n * Merges studio plugin options with disk config plugins.\n * Studio takes priority: options from studio win over disk (except values only the disk config\n * can express, see {@link mergeOptions}), and a plugin Studio explicitly\n * disabled is dropped even when the disk config still lists it. Disk plugins without a studio\n * counterpart are kept as-is. Studio plugins not present on disk are appended.\n *\n * For plugins present in both configs, the plugin is re-instantiated with merged options\n * so that all internal closures correctly reference the merged values.\n */\nexport async function mergePlugins({\n diskPlugins,\n studioPlugins,\n extensions = new Map(),\n}: {\n diskPlugins: Array<Plugin> | undefined\n studioPlugins: JSONKubbConfig['plugins'] | undefined\n extensions?: InstalledExtensions\n}): Promise<Array<Plugin> | undefined> {\n const pluginNameOf = (packageName: string) => extensions.get(packageName)?.manifest.name ?? toPluginName(packageName)\n // Matched on the package's base name rather than by instantiating first. Every Kubb plugin\n // factory returns exactly that (`@kubb/plugin-ts` → `plugin-ts`), enforced by the `satisfies` on\n // each factory's name.\n const disabledNames = new Set((studioPlugins ?? []).filter((entry) => entry.disabled).map((entry) => pluginNameOf(entry.name)))\n const activeDiskPlugins = disabledNames.size ? diskPlugins?.filter((plugin) => !disabledNames.has(resolveMeta(plugin).name)) : diskPlugins\n const activeStudioPlugins = studioPlugins?.filter((entry) => !entry.disabled)\n\n if (!activeDiskPlugins && !activeStudioPlugins?.length) return undefined\n if (!activeStudioPlugins?.length) return activeDiskPlugins\n\n if (!activeDiskPlugins) return resolvePlugins({ plugins: activeStudioPlugins, extensions })\n\n const studioEntryByName = new Map(activeStudioPlugins.map((entry) => [pluginNameOf(entry.name), entry] as const))\n const diskNames = new Set(activeDiskPlugins.map((plugin) => plugin.name))\n\n // Each plugin is instantiated once, with its final options. Resolving the whole payload first\n // just to read the names would build every overlapping plugin twice and discard the first.\n const merged = await Promise.all(\n activeDiskPlugins.map(async (diskPlugin) => {\n const studioEntry = studioEntryByName.get(resolveMeta(diskPlugin).name)\n if (!studioEntry) return diskPlugin\n\n // Disk as base, studio overrides, then re-instantiate so the plugin's closures reference the\n // merged values. A plugin that never sets `options` (e.g. `@kubb/plugin-barrel`) leaves\n // `diskPlugin.options` undefined.\n const diskOptions = (diskPlugin.options as Record<string, unknown>) ?? {}\n const options = mergeOptions(diskOptions, (studioEntry.options as Record<string, unknown>) ?? {})\n // A plugin defined in the user's project has no package to re-instantiate it from. Studio\n // echoing its options back unchanged is fine, any real change can only be made on disk.\n const unchanged = JSON.stringify(toJSONOptions(options)) === JSON.stringify(toJSONOptions(diskOptions))\n const [resolved] = await resolvePlugins({ plugins: [{ name: studioEntry.name, options }], extensions }).catch((cause: unknown) => {\n if (unchanged) return [diskPlugin]\n throw new Diagnostics.Error({\n code: Diagnostics.code.pluginNotFound,\n severity: 'error',\n message: `Plugin \"${diskPlugin.name}\" is not an installed @kubb/plugin-* package or Kubb extension, so Studio cannot change its options. Edit it in the config file, or only enable or disable it from Studio.`,\n cause: toError(cause),\n })\n })\n\n return resolved ?? diskPlugin\n }),\n )\n\n const studioOnly = activeStudioPlugins.filter((entry) => !diskNames.has(pluginNameOf(entry.name)))\n\n return [...merged, ...(await resolvePlugins({ plugins: studioOnly, extensions }))]\n}\n\n/**\n * Throws `KUBB_PATH_TRAVERSAL` when a plugin would write outside the config's output folder to a path\n * the disk config does not set. Studio can change `output.path`, also inside `override`, and add\n * plugins, so without this check any member of the Studio organization could write any file the agent\n * can reach, including `node_modules` code the next run imports. A path from the config file stays\n * allowed, since a monorepo may write outside its root.\n */\nexport function assertOutputPaths({\n plugins,\n diskPlugins,\n root,\n outputPath,\n}: {\n plugins: Array<Plugin>\n diskPlugins: Array<Plugin>\n root: string\n outputPath: string\n}): void {\n const base = path.resolve(root, outputPath)\n const targetsOf = (plugin: Plugin): Array<string> => {\n const { output, override } = (plugin.options ?? {}) as { output?: { path?: unknown }; override?: Array<{ options?: { output?: { path?: unknown } } }> }\n const outputs = [output, ...(Array.isArray(override) ? override.map((entry) => entry?.options?.output) : [])]\n return outputs.flatMap((entry) => (typeof entry?.path === 'string' ? [path.resolve(base, entry.path)] : []))\n }\n const diskTargets = new Set(diskPlugins.flatMap(targetsOf))\n\n for (const plugin of plugins) {\n const target = targetsOf(plugin).find((resolved) => !diskTargets.has(resolved) && !isPathInside(resolved, base))\n if (!target) continue\n\n throw new Diagnostics.Error({\n code: Diagnostics.code.pathTraversal,\n severity: 'error',\n message: `Plugin \"${plugin.name}\" would write to \"${target}\", outside the output folder \"${base}\". Studio can only set an output path inside it.`,\n help: 'Choose an output path inside the output folder, or set this path in the config file.',\n location: { kind: 'config' },\n plugin: plugin.name,\n })\n }\n}\n\n/**\n * The folders a `$ref` may read local files from on each kind of agent. Studio may have sent the\n * spec, so a shared agent gets none, and a managed agent only the git checkout it made itself. A\n * project agent gets its `root` and the folder of the file `input` in its own config. `undefined`\n * means no limit, which only `allowFileRefs` grants.\n */\nexport function resolveFileRefs({\n agentType,\n allowFileRefs,\n root,\n input,\n checkoutDir,\n}: {\n agentType: AgentType\n allowFileRefs: boolean\n root: string\n input?: Config['input']\n checkoutDir?: string\n}): Array<string> | undefined {\n if (agentType === 'sandbox' || agentType === 'global') return []\n if (agentType === 'managed') return checkoutDir ? [checkoutDir] : []\n if (allowFileRefs) return undefined\n const isFile = typeof input === 'string' && getInputKind(input) === 'file'\n return isFile ? [root, path.dirname(path.resolve(root, input))] : [root]\n}\n\n/**\n * Re-invokes the factory behind a disk adapter or parser with Studio's options merged over its own.\n * An instance carries live functions (`parse`, `print`, ...) that cannot survive JSON, so Studio's\n * options are a patch, not a replacement, and the factory is found from the disk instance itself: the\n * installed extension whose manifest names it, or the `@kubb/<kind>-<name>` package for a built-in\n * one. Throws when no factory resolves, as `mergePlugins` does, so an override Studio sent is never\n * dropped without a word. An extension without a manifest, such as `parserTsx`, has no options in\n * Studio, so Studio never sends one for it.\n */\nasync function rebuildExtension<T extends Adapter | Parser>({\n disk,\n studioOptions,\n kind,\n extensions,\n}: {\n disk: T\n studioOptions: object | undefined\n kind: ExtensionKind\n extensions: InstalledExtensions\n}): Promise<T> {\n if (!studioOptions || !Object.keys(studioOptions).length) return disk\n\n const { name } = resolveMeta(disk)\n const installed = [...extensions.values()].find(({ manifest }) => manifest.kind === kind && manifest.name === name)\n const packageName = installed?.package ?? `@kubb/${kind}-${name}`\n const factory = await loadFactory({ packageName, extensions, kind }).catch((cause: unknown) => {\n throw new Diagnostics.Error({\n code: kind === 'plugin' ? Diagnostics.code.pluginNotFound : Diagnostics.code.unknown,\n severity: 'error',\n message: `The ${kind} \"${name}\" is not an installed Kubb extension, so Studio cannot change its options. Edit it in the config file.`,\n cause: toError(cause),\n })\n })\n\n return factory(mergeOptions((disk.options as Record<string, unknown>) ?? {}, studioOptions as Record<string, unknown>)) as T\n}\n\n/** Merges Studio's valid `output` overrides, with `null` unsetting a member. */\nexport function mergeOutput({ output, studio }: { output: Config['output']; studio: unknown }): Config['output'] {\n if (!isPlainObject(studio)) return output\n const overrides = Object.fromEntries(Object.entries(studio).filter(([key, value]) => (value === null ? isOutputKey(key) : isOutputValue({ key, value }))))\n return mergeOptions(output, overrides) as Config['output']\n}\n\n/**\n * Merges Studio-provided adapter option overrides into the disk config's adapter, see {@link rebuildExtension}.\n */\nexport async function mergeAdapter(diskAdapter: Adapter | undefined, studioOptions: object | undefined, extensions: InstalledExtensions = new Map()) {\n if (!diskAdapter) return diskAdapter\n\n return rebuildExtension({ disk: diskAdapter, studioOptions, kind: 'adapter', extensions })\n}\n\n/**\n * Merges Studio-provided parser option overrides into the disk config's parsers, matched by the name\n * Studio knows each parser by, see {@link rebuildExtension}. Parsers Studio does not name are kept as is.\n */\nexport async function mergeParsers({\n diskParsers,\n studioParsers,\n extensions = new Map(),\n}: {\n diskParsers: Array<Parser>\n studioParsers: JSONKubbConfig['parsers'] | undefined\n extensions?: InstalledExtensions\n}): Promise<Array<Parser>> {\n if (!studioParsers?.length) return diskParsers\n\n const studioOptions = new Map(studioParsers.map((entry) => [entry.name, entry.options]))\n\n return Promise.all(\n diskParsers.map((parser) =>\n rebuildExtension({\n disk: parser,\n studioOptions: studioOptions.get(toStudioName({ name: resolveMeta(parser).name, extensions, kind: 'parser' })),\n kind: 'parser',\n extensions,\n }),\n ),\n )\n}\n","import { Diagnostics } from '@kubb/core'\n\n/**\n * Hosted Kubb Studio URL, used when a host passes none.\n */\nexport const defaultStudioUrl = 'https://kubb.studio'\n\n// `URL` keeps IPv6 brackets, so `::1` is `[::1]`.\nfunction isLoopbackHost(hostname: string): boolean {\n return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]'\n}\n\n/**\n * Appends `path` to the Studio URL and refuses plaintext to anything but this machine, so a token\n * or API key never crosses the network unencrypted. `socket` switches the scheme to `ws:`/`wss:`.\n *\n * @example\n * ```ts\n * secureUrl({ studioUrl: 'https://kubb.studio', path: '/api/agent/socket', socket: true }).href // 'wss://kubb.studio/api/agent/socket'\n * ```\n */\nexport function secureUrl({ studioUrl, path, socket = false }: { studioUrl: string; path: string; socket?: boolean }): URL {\n const url = new URL(`${studioUrl.replace(/\\/+$/, '')}${path}`)\n\n if (url.protocol !== 'https:' && !(url.protocol === 'http:' && isLoopbackHost(url.hostname))) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `Refusing to reach Kubb Studio at ${url.origin}: use an https:// URL, or a loopback host for local development`,\n })\n }\n if (socket) url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'\n\n return url\n}\n","import { randomUUID } from 'node:crypto'\nimport { existsSync } from 'node:fs'\nimport { writeFile } from 'node:fs/promises'\nimport { createRequire } from 'node:module'\nimport { tmpdir } from 'node:os'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { setTimeout as delay } from 'node:timers/promises'\nimport { getErrorMessage, isPathInside, mkdtemp, read, rm, toError } from '@internals/utils'\nimport {\n Diagnostics,\n cacheStorage,\n checkoutGitInput,\n type Config,\n fsStorage,\n getInputKind,\n type InputKind,\n Hookable,\n type KubbHooks,\n type ProblemCode,\n type Storage,\n readInstalledPackages,\n resolveCacheDir,\n resolveMeta,\n} from '@kubb/core'\nimport { newWebSocketRpcSession, RpcTarget } from 'capnweb'\nimport { x } from 'tinyexec'\nimport { version as kubbVersion } from '../package.json'\nimport { BUNDLED_PACKAGES, editConfigFile, pickOutput, readConfig, readImports } from '@internals/shared'\nimport { signAgentPayload } from './agentKey.ts'\nimport { diffHunks, pageHunks } from './diff.ts'\nimport { createGenerationStream } from './generationEvents.ts'\nimport { createGenerationStore, generate, type GenerationStore, listDisk, resolveGenerationLimits } from './generations.ts'\nimport {\n AGENT_INSTANCE_HEADER,\n AGENT_SOCKET_PATH,\n type AgentApi,\n AgentPermission,\n AgentCloseCode,\n AgentMessage,\n type AgentConnectInfo,\n type AgentPermissions,\n AgentSignatureContext,\n type AgentType,\n type ConfigEdit,\n ConfigEditOperation,\n type ConfigEntryView,\n type ConfigFileView,\n type ConfigRef,\n type ConnectMessagePayload,\n type DiskOutput,\n type GenerateInput,\n type GenerateResult,\n type GenerationEvent,\n type GenerationRun,\n type InstalledExtensions,\n MAX_CONNECT_CHALLENGE_LENGTH,\n MAX_FILES_PER_REQUEST,\n MAX_PAGE_LINES,\n type ReadDiffInput,\n type ReadDiffResult,\n type ReadFilesInput,\n type ReadFilesResult,\n type ReadInputInput,\n type ReadInputResult,\n type InstallExtensionInput,\n type InstallExtensionResult,\n type RemoveExtensionInput,\n type RemoveExtensionResult,\n type SaveConfigInput,\n type SaveResult,\n type StudioApi,\n type UpdateExtensionsInput,\n type UpdateExtensionsResult,\n} from './protocol.ts'\nimport { withPublicFetch } from './publicFetch.ts'\nimport { assertOutputPaths, mergeAdapter, mergeOutput, mergeParsers, mergePlugins, resolveFileRefs, toJSONOptions, toStudioName } from './resolveConfig.ts'\nimport { defaultStudioUrl, secureUrl } from './url.ts'\n\nconst HEARTBEAT_INTERVAL_MS = 30_000\nconst SHARED_AGENT_TYPES = new Set<AgentType>(['sandbox', 'global'])\n// Studio marks an agent offline after its liveness window, so a slower cadence would look dead.\nconst MAX_HEARTBEAT_INTERVAL_MS = 60_000\nconst PING_TIMEOUT_MS = 10_000\nconst OPEN_TIMEOUT_MS = 5_000\nconst MAX_RETRY_DELAY_MS = 30_000\nconst DISK_SNAPSHOT_MAX_FILES = 10_000\n// Sandboxes keep temporary output sets with a short lifetime.\nconst SANDBOX_GENERATION_TTL_MS = 15 * 60_000\n// What Studio may send a managed agent as its spec. Not `file` or `object`: a path would read the container's disk.\nconst MANAGED_INPUT_KINDS = new Set<InputKind>(['inline', 'url', 'git'])\n\n/**\n * Studio closed with {@link AgentCloseCode.UNAUTHORIZED}. Hosts forget the token and pair again.\n */\nexport class InvalidAgentTokenError extends Error {\n constructor(studioUrl: string) {\n super(`Kubb Studio rejected this agent's token. It expired or was revoked, or the agent was deleted in ${studioUrl}.`)\n this.name = 'InvalidAgentTokenError'\n }\n}\n\n/**\n * Studio closed with {@link AgentCloseCode.INCOMPATIBLE}. Only an upgrade helps.\n */\nexport class IncompatibleAgentError extends Error {\n constructor({ studioUrl, detail }: { studioUrl: string; detail?: string }) {\n super(`Kubb Studio at ${studioUrl} requires a newer agent${detail ? `: ${detail}` : ''}. Upgrade kubb or the Kubb agent image.`)\n this.name = 'IncompatibleAgentError'\n }\n}\n\nexport type StudioConnectedContext = AgentConnectInfo & {\n url: string\n /**\n * The Studio, runtime, and host versions, so a host can show a mismatch.\n */\n versions: { studio: string; kubb: string; agent: string }\n}\n\ndeclare global {\n namespace Kubb {\n interface KubbHooksRegistry {\n /**\n * Fired after each handshake, including reconnects.\n */\n 'studio:connected': [ctx: StudioConnectedContext]\n 'studio:disconnected': [ctx: { code: number; reason: string }]\n 'studio:reconnecting': [ctx: { delayMs: number }]\n /**\n * A finished command and what it did, such as `applied 2/3 edits to kubb.config.ts`.\n */\n 'studio:command': [\n ctx: {\n command: 'generate' | 'saveConfig' | 'installExtension' | 'updateExtensions' | 'removeExtension' | 'readFiles' | 'readInput' | 'readDiff'\n info: string\n /**\n * The Studio user who asked for the command, when Studio names one.\n */\n requestedBy?: string\n /**\n * Set when a generation failed. Its diagnostics went out through `kubb:generation:end`.\n */\n failed?: boolean\n },\n ]\n /**\n * A refused or ignored request, with the missing permission so the host can add a remedy.\n */\n 'studio:warn': [ctx: { message: string; permission?: AgentPermission }]\n 'studio:error': [ctx: { error: Error }]\n }\n }\n}\n\nexport type ConnectAgentOptions = {\n /**\n * The agent's bearer token, from {@link pairAgent}. A function is read before every socket opens.\n */\n token: string | (() => string | Promise<string>)\n /**\n * The agent key from `generateAgentKey`, which signs the connect challenge.\n */\n privateKey?: string\n studioUrl?: string\n /**\n * The config path shown in Studio, relative to `root` unless absolute.\n */\n configPath: string\n /**\n * Called for every handshake and every generation, so edits on disk show up. One entry per\n * `defineConfig(...)` entry, and a generation names the one it runs.\n */\n loadConfigs: () => Promise<Array<Config>>\n /**\n * The host's own version, reported to Studio next to the runtime's.\n */\n version: string\n /**\n * The project root generation runs against.\n * @default process.cwd()\n */\n root?: string\n /**\n * What Studio may do in this project. Every permission is off unless granted.\n */\n permissions?: Partial<AgentPermissions>\n /**\n * The kind of agent the host runs. A `'sandbox'` or `'global'` agent is shared, and lets Studio read what it generated.\n * Studio's own `sandbox` and `managed` flags only take permissions away.\n * @default 'user'\n */\n agentType?: AgentType\n /** The CLI entry `installExtension` runs `kubb add` with. Found through the project's `kubb` or `@kubb/cli` dependency when omitted. */\n kubbBin?: string\n /**\n * Receives the `studio:*` hooks and the `kubb:*` hooks of every generation.\n */\n hooks?: Hookable<KubbHooks>\n signal?: AbortSignal\n /**\n * Longest wait between reconnect attempts, in milliseconds.\n * @default 30000\n */\n maxRetryDelay?: number\n /**\n * Milliseconds between keep-alive pings, at most 60000.\n * @default 30000\n */\n heartbeatInterval?: number\n}\n\ntype ResolvedOptions = Required<Omit<ConnectAgentOptions, 'signal' | 'kubbBin' | 'privateKey'>> & {\n signal?: AbortSignal\n kubbBin?: string\n privateKey?: string\n permissions: AgentPermissions\n configFile: string\n}\n\ntype Rpc = { studio: StudioApi; closed: Promise<{ code: number; reason: string }>; close: () => void }\n\n// Tests swap in an in-process pair.\nexport type OpenRpc = (input: { url: URL; token: string; instanceId: string; agent: AgentApi }) => Rpc\n\ntype Session = {\n info?: AgentConnectInfo\n connected: PromiseWithResolvers<AgentConnectInfo>\n closed: boolean\n active?: { jobId: string; abort: () => void; settled: Promise<void> }\n install?: { abort: () => void; settled: Promise<void> }\n saving?: boolean\n}\n\nconst INSTALL_TIMEOUT_MS = 5 * 60_000\n/** How many trailing lines of a failed `kubb add` the reason keeps. */\nconst INSTALL_OUTPUT_LINES = 20\n/** `owner/slug` or `slug`, as `kubb add` takes it. Checked before it becomes an argument. */\nconst REGISTRY_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\\/[a-z0-9]+(?:-[a-z0-9]+)*)?$/\n\n/** The CLI the project depends on, so `kubb add` installs next to what the config imports. */\nfunction findKubbBin(root: string): string | undefined {\n const requireModule = createRequire(path.resolve(root, 'package.json'))\n const names = ['kubb', '@kubb/cli']\n // Nearest directory first, so a nested project does not pick up an ancestor's CLI.\n return (requireModule.resolve.paths('kubb') ?? [])\n .flatMap((dir) => names.map((name) => path.join(dir, name, 'bin', 'kubb.js')))\n .find((bin) => existsSync(bin))\n}\n\n/** Runs a `kubb` command without a shell, and keeps the end of its output for the failure reason. */\nasync function runKubb({ bin, args, cwd, signal }: { bin: string; args: Array<string>; cwd: string; signal: AbortSignal }) {\n try {\n const { stdout, stderr, exitCode } = await x(process.execPath, [bin, ...args], {\n signal,\n timeout: INSTALL_TIMEOUT_MS,\n throwOnError: false,\n nodeOptions: { cwd, env: { ...process.env, NO_COLOR: '1', FORCE_COLOR: '0' } },\n })\n const output = `${stdout}\\n${stderr}`.trim().split('\\n').slice(-INSTALL_OUTPUT_LINES).join('\\n')\n return { failed: exitCode !== 0, output: output || `kubb ${args[0]} exited with ${exitCode ?? 'a signal'}` }\n } catch (error) {\n // tinyexec still throws when the timeout hits or the process cannot start.\n return { failed: true, output: `kubb ${args[0]} did not run: ${getErrorMessage(error)}` }\n }\n}\n\n// A throwing host listener must not break the connection.\nfunction emit<TName extends keyof KubbHooks & string>(hooks: Hookable<KubbHooks>, name: TName, ...args: KubbHooks[TName]): Promise<void> {\n return Promise.resolve(hooks.callHook(name, ...args)).catch(() => {})\n}\n\nfunction isValidPage({ cursor, limit }: Pick<ReadFilesInput, 'cursor' | 'limit'>): boolean {\n if (limit === undefined) return cursor === undefined\n if (cursor !== undefined && (!Number.isSafeInteger(cursor) || cursor < 0)) return false\n return Number.isSafeInteger(limit) && limit >= 1 && limit <= MAX_PAGE_LINES\n}\n\n/**\n * Maps generated paths into a temporary directory while keeping the project root for input resolution.\n */\nfunction stagingStorage({ root, directory }: { root: string; directory: string }): Storage {\n const storage = fsStorage()\n const target = (key: string) => {\n const relative = path.relative(root, path.resolve(root, key))\n if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) throw new Error('Output path escapes the project root')\n return path.join(directory, relative)\n }\n return {\n name: 'fs',\n readItem: (key) => storage.readItem(target(key)),\n writeItem: (key, value) => storage.writeItem(target(key), value),\n removeItem: (key) => storage.removeItem(target(key)),\n readKeys: (base) => storage.readKeys(base ? target(base) : directory),\n empty: (base) => (base ? storage.empty(target(base)) : Promise.resolve()),\n }\n}\n\ntype RunHandle = { stream: ReadableStream<GenerationEvent>; result: Promise<GenerateResult>; stop: () => void }\n\nclass GenerationRunTarget extends RpcTarget implements GenerationRun {\n readonly #run: RunHandle\n\n constructor(run: RunHandle) {\n super()\n this.#run = run\n }\n\n async events() {\n return this.#run.stream\n }\n result() {\n return this.#run.result\n }\n async cancel() {\n this.#run.stop()\n }\n // Cap'n Web also calls this when the peer session is torn down, so a dropped socket stops the run.\n [Symbol.dispose]() {\n this.#run.stop()\n }\n}\n\n/** A save's edit once a `set-input` document is named, or why it was refused. */\ntype KeptEdit = (ConfigEdit & { document?: { fileName: string; text: string } }) | { reason: string }\n\n// Cap'n Web exposes only prototype methods, so the public methods are exactly `AgentApi`.\nclass Agent extends RpcTarget implements AgentApi {\n readonly #options: ResolvedOptions\n readonly #session: Session\n readonly #limits = resolveGenerationLimits()\n #store: GenerationStore | undefined\n readonly #sandboxCacheRoot = path.join(tmpdir(), `kubb-studio-${randomUUID()}`)\n // Kept sets never change, so a diff is computed once and its pages are cut from it.\n readonly #diffs = new Map<string, ReturnType<typeof diffHunks>>()\n\n constructor({ options, session }: { options: ResolvedOptions; session: Session }) {\n super()\n this.#options = options\n this.#session = session\n }\n\n get #sandbox(): boolean {\n return SHARED_AGENT_TYPES.has(this.#options.agentType) || this.#session.info?.sandbox === true\n }\n\n get #managed(): boolean {\n return this.#options.agentType === 'managed' || this.#session.info?.managed === true\n }\n\n // The host's kind, unless Studio's flags narrow it to a sandbox or a managed agent.\n get #agentType(): AgentType {\n if (this.#sandbox) return 'sandbox'\n if (this.#managed) return 'managed'\n return this.#options.agentType\n }\n\n // A sandbox has no project to write to or edit. Only the host's `agentType` grants reads.\n get #permissions(): AgentPermissions {\n const { permissions, agentType } = this.#options\n const sandbox = SHARED_AGENT_TYPES.has(agentType)\n if (this.#managed) return { ...permissions, allowFileRefs: false }\n if (!this.#sandbox) return permissions\n\n return {\n ...permissions,\n allowWrite: false,\n allowConfigEdit: false,\n allowInstall: false,\n allowUpdate: false,\n allowRemove: false,\n allowSaveInput: false,\n allowFileRefs: false,\n allowRead: sandbox || permissions.allowRead,\n allowReadAst: sandbox || permissions.allowReadAst,\n }\n }\n\n // Owned agents retain output in the project cache. Each sandbox connection has a temporary cache.\n get #generations(): GenerationStore {\n this.#store ??= createGenerationStore({\n storage: cacheStorage({ root: this.#sandbox ? this.#sandboxCacheRoot : this.#options.root }),\n maxCount: this.#limits.maxCount,\n maxMb: this.#limits.maxMb,\n ttlMs: this.#sandbox ? SANDBOX_GENERATION_TTL_MS : undefined,\n })\n return this.#store\n }\n\n async clear() {\n if (this.#sandbox) await rm(resolveCacheDir(this.#sandboxCacheRoot), { recursive: true, force: true })\n }\n\n #warn({ message, permission }: { message: string; permission?: AgentPermission }): Promise<void> {\n return emit(this.#options.hooks, 'studio:warn', { message, permission })\n }\n\n // Studio shows the thrown message, and the host logs the same text.\n async #refuse({\n message,\n permission,\n code = Diagnostics.code.unknown,\n }: {\n message: string\n permission?: AgentPermission\n code?: ProblemCode\n }): Promise<never> {\n await this.#warn({ message, permission })\n throw new Diagnostics.Error({ code, severity: 'error', message })\n }\n\n #assertConnected(): void {\n if (!this.#session.info)\n throw new Diagnostics.Error({ code: Diagnostics.code.internalError, severity: 'error', message: 'Studio must call connect() before any other command' })\n }\n\n #logCommand(command: KubbHooks['studio:command'][0]['command'], info: string, requestedBy?: string, failed?: boolean): Promise<void> {\n return emit(this.#options.hooks, 'studio:command', { command, info, requestedBy, failed })\n }\n\n // Not cached: the user can edit the file between two Studio actions.\n async #readConfigFileView(source: Promise<string>): Promise<ConfigFileView | undefined> {\n if (!this.#permissions.allowConfigEdit) return undefined\n\n try {\n return readConfig(await source)\n } catch (error) {\n await this.#warn({ message: `Could not read ${this.#options.configFile}: ${getErrorMessage(error)}` })\n return undefined\n }\n }\n\n // Not cached either: the user can install a plugin while the agent runs. Keeps each project\n // dependency, config import and built-in that resolves and ships a valid `kubb-extension.json`.\n async #installedExtensions(source = read(this.#options.configFile)): Promise<InstalledExtensions> {\n const imports = await source.then(readImports, () => [])\n const installed = await readInstalledPackages({ root: this.#options.root, packages: [...imports, ...BUNDLED_PACKAGES], resolveFrom: ['kubb'] })\n\n return new Map(\n installed.flatMap(({ package: name, version, manifest }) =>\n version !== undefined && manifest\n ? [[name, { package: name, version, manifest, ...(BUNDLED_PACKAGES.includes(name) ? { bundled: true as const } : {}) }] as const]\n : [],\n ),\n )\n }\n\n async connect(info: AgentConnectInfo): Promise<ConnectMessagePayload> {\n this.#session.info = info\n const { configPath, root, version, loadConfigs, configFile } = this.#options\n const source = read(configFile)\n const [configs, file, extensions] = await Promise.all([loadConfigs(), this.#readConfigFileView(source), this.#installedExtensions(source)])\n // Copied through JSON: Cap'n Web would otherwise pass every function in the options as a stub\n // Studio could call, running the user's config code in this process.\n const entries: Array<ConfigEntryView> = []\n for (const config of configs) {\n const disk = await this.#readDiskOutput(config).catch(async (error: unknown) => {\n await this.#warn({ message: `Could not read the output directory: ${getErrorMessage(error)}` })\n return undefined\n })\n entries.push({ ...toEntryView(config, extensions), ...(disk && { disk }) })\n }\n this.#session.connected.resolve(info)\n const { privateKey } = this.#options\n const { challenge } = info\n const signature =\n privateKey && typeof challenge === 'string' && challenge && challenge.length <= MAX_CONNECT_CHALLENGE_LENGTH\n ? signAgentPayload({ privateKey, context: AgentSignatureContext.CONNECT, payload: challenge })\n : undefined\n\n return {\n versions: { kubb: kubbVersion, agent: version },\n root,\n config: { path: configPath, file, extensions: [...extensions.values()], configs: entries },\n permissions: this.#permissions,\n ...(signature && { signature }),\n }\n }\n\n async #readDiskOutput(config: Config): Promise<DiskOutput | undefined> {\n if (this.#sandbox || !this.#permissions.allowRead || this.#session.active) return undefined\n const files = await listDisk({ root: this.#options.root, outputPath: config.output.path, maxFiles: DISK_SNAPSHOT_MAX_FILES })\n if (!files) return undefined\n\n const { jobId, output } = await this.#generations.keepInitial(files)\n return { jobId, files: output.paths, hashes: output.hashes }\n }\n\n startGeneration(input: GenerateInput): GenerationRun {\n const stream = createGenerationStream(this.#options.hooks, input.jobId)\n const controller = new AbortController()\n const result = this.#runGeneration(input, controller).then(\n (value) => stream.close().then(() => value),\n (error: unknown) => {\n stream.fail(error)\n throw error\n },\n )\n // A disconnect can reject this after the remote caller disappeared.\n void result.catch(() => {})\n\n return new GenerationRunTarget({\n stream: stream.stream,\n result,\n stop: () => {\n controller.abort(new Error('Generation canceled'))\n stream.fail()\n },\n })\n }\n\n /**\n * Keeps a job's output and permitted parsed input, then cleans up its temporary generation directories.\n */\n async #runGeneration(input: GenerateInput, controller: AbortController): Promise<GenerateResult> {\n this.#assertConnected()\n // Checked before the first `await`, so two calls in the same tick can't both pass.\n if (this.#session.closed) throw new Diagnostics.Error({ code: Diagnostics.code.internalError, severity: 'error', message: 'Connection is closed' })\n if (this.#session.active) return this.#refuse({ message: AgentMessage.GENERATION_IN_PROGRESS })\n if (this.#session.install) return this.#refuse({ message: AgentMessage.INSTALL_IN_PROGRESS })\n if (this.#session.saving) return this.#refuse({ message: AgentMessage.SAVE_IN_PROGRESS })\n const settled = Promise.withResolvers<void>()\n this.#session.active = { jobId: input.jobId, abort: () => controller.abort(new Error('Generation canceled')), settled: settled.promise }\n let root = this.#options.root\n let outputRoot: string | undefined\n\n try {\n // Kubb keys its manifest cache by root, so sandbox tenants sharing one root would read each other's.\n if (this.#sandbox) root = await mkdtemp(path.join(tmpdir(), 'kubb-job-'))\n if (!this.#sandbox && !this.#permissions.allowWrite) outputRoot = await mkdtemp(path.join(tmpdir(), 'kubb-output-'))\n return await this.#generate({ input, root, outputRoot, signal: controller.signal })\n } finally {\n if (root !== this.#options.root) {\n await Promise.all([rm(root, { recursive: true, force: true }), rm(resolveCacheDir(root), { recursive: true, force: true })]).catch(() => {})\n }\n if (outputRoot) await rm(outputRoot, { recursive: true, force: true })\n this.#session.active = undefined\n settled.resolve()\n }\n }\n\n /**\n * Merges Studio's config over the project config and confines generation to the configured output folder.\n */\n async #generate({\n input,\n root,\n outputRoot,\n signal,\n }: {\n input: GenerateInput\n root: string\n outputRoot?: string\n signal: AbortSignal\n }): Promise<GenerateResult> {\n const { jobId, config: patch } = input\n // A sandbox has no spec on disk, so it only ever generates from the content Studio sends. A path\n // or URL would make it read host files or fetch internal addresses on behalf of any tenant.\n const studioInput = this.#sandbox || this.#managed ? patch?.input : undefined\n if (this.#sandbox && (typeof studioInput !== 'string' || !studioInput.trim() || getInputKind(studioInput) !== 'inline')) {\n return this.#refuse({ message: AgentMessage.SANDBOX_INPUT_ONLY })\n }\n // Studio may point a managed agent at a URL or a git file, and it falls back to its config's input without one. A file path would read the container's disk.\n if (this.#managed && studioInput !== undefined && !MANAGED_INPUT_KINDS.has(getInputKind(studioInput))) {\n return this.#refuse({ message: AgentMessage.MANAGED_INPUT_KIND })\n }\n\n const [configs, extensions] = await Promise.all([this.#options.loadConfigs(), this.#installedExtensions()])\n const config = pickConfig(configs, patch?.config)\n if (!config) return this.#refuse({ message: AgentMessage.CONFIG_ENTRY_NOT_FOUND })\n const [plugins, adapter, parsers] = await Promise.all([\n mergePlugins({ diskPlugins: config.plugins, studioPlugins: patch?.plugins, extensions }).then((merged) => {\n assertOutputPaths({ plugins: merged ?? [], diskPlugins: config.plugins, root, outputPath: config.output.path })\n return merged\n }),\n mergeAdapter(config.adapter, patch?.adapter, extensions),\n mergeParsers({ diskParsers: config.parsers, studioParsers: patch?.parsers, extensions }),\n ]).catch(async (error: unknown) => {\n // Thrown before core runs, so nothing else reports it to the host.\n await emit(this.#options.hooks, 'kubb:error', { error: toError(error) })\n throw error\n })\n\n const activePlugins = plugins ?? config.plugins\n\n if (patch?.input && !this.#sandbox && !this.#managed) {\n // A `kubb:warn` rather than `studio:warn`, so the generation's event stream carries it to Studio too.\n await emit(this.#options.hooks, 'kubb:warn', {\n message: 'Ignored the spec from Studio: generating from a Studio spec is only available to a sandbox or managed agent',\n })\n }\n\n // A managed agent checks out any git input itself, the config's too, so the fetch stays on public addresses.\n const managedInput = this.#managed ? (studioInput ?? config.input) : undefined\n const checkout =\n typeof managedInput === 'string' && getInputKind(managedInput) === 'git'\n ? await checkoutGitInput(managedInput, signal, { publicOnly: true, authorization: input.gitAuth?.authorization }).catch((error: unknown) =>\n this.#refuse({ message: getErrorMessage(error), code: Diagnostics.code.gitInputFailed }),\n )\n : undefined\n const run = () =>\n generate({\n config: {\n ...config,\n root,\n input: checkout?.path ?? studioInput ?? config.input,\n output: mergeOutput({ output: config.output, studio: patch?.output }),\n storage: outputRoot ? stagingStorage({ root, directory: outputRoot }) : fsStorage(),\n plugins: activePlugins,\n adapter,\n parsers,\n },\n hooks: this.#options.hooks,\n signal,\n allowExec: this.#permissions.allowWrite && this.#permissions.allowExec,\n fileRefs: resolveFileRefs({\n agentType: this.#agentType,\n allowFileRefs: this.#permissions.allowFileRefs,\n root: this.#options.root,\n input: config.input,\n checkoutDir: checkout?.dir,\n }),\n })\n // The adapter fetches the URL and every `$ref` in it, so a shared or hosted agent limits the fetch itself to public addresses.\n const files = await (this.#sandbox || this.#managed ? withPublicFetch(run) : run())\n .catch(async (error: unknown) => {\n await this.#generations.drop(jobId)\n await this.#logCommand('generate', getErrorMessage(error), input.requestedBy, true)\n throw error\n })\n .finally(() => checkout?.dispose())\n\n const output = await this.#generations.keep({ jobId, files, maxSetMb: this.#limits.maxMb })\n // Only `readInput` reads it, which needs `allowReadAst`.\n const inputBytes = await this.#generations.keepInput({ jobId, input: this.#permissions.allowReadAst ? files.input : null, maxSetMb: this.#limits.maxMb })\n if (!output.paths.length && Object.keys(output.hashes).length) {\n await this.#warn({ message: 'Kept only the hashes of this generation: its output is too large to keep' })\n }\n await this.#generations.add({ jobId, output, inputBytes })\n await this.#logCommand(\n 'generate',\n `${activePlugins.length} plugin${activePlugins.length === 1 ? '' : 's'}, ${this.#permissions.allowWrite ? 'written to disk' : 'staged on disk'}${studioInput !== undefined ? ', from a Studio spec' : ''}`,\n input.requestedBy,\n )\n\n return {\n status: 'success',\n files: [...files.paths],\n fileCount: files.paths.size,\n hashes: output.hashes,\n }\n }\n\n async saveConfig(input: SaveConfigInput): Promise<SaveResult> {\n this.#assertConnected()\n const { configPath, configFile } = this.#options\n\n if (!Array.isArray(input.edits)) {\n await this.#warn({ message: 'Ignored save: the message carried no edits' })\n return { outcomes: [], changed: false }\n }\n\n const edits = input.edits\n const refuse = (reason: string): SaveResult => ({ outcomes: edits.map((edit) => ({ edit, applied: false, reason })), changed: false })\n\n if (!this.#permissions.allowConfigEdit) {\n await this.#warn({ message: 'Ignored save: editing kubb.config.ts was not granted' })\n return refuse('the agent was not granted permission to edit kubb.config.ts')\n }\n\n // A running generation reloads the config, so it would see half the change.\n const busy = this.#busy()\n if (busy) return refuse(busy)\n\n // Keeps `kubb add` from rewriting the config while this save is still writing it.\n this.#session.saving = true\n try {\n const kept: Array<KeptEdit> = []\n for (const edit of edits) kept.push(await this.#keepInput(edit))\n const written = await editConfigFile({\n filePath: configFile,\n edits: kept.flatMap((edit) => ('reason' in edit ? [] : [edit])),\n extensions: await this.#installedExtensions(),\n })\n let next = 0\n // Back in the order Studio sent them, each naming the edit as sent rather than the document's file.\n const outcomes = kept.map((edit, index) =>\n 'reason' in edit ? { edit: edits[index]!, applied: false, reason: edit.reason } : { ...written.outcomes[next++]!, edit: edits[index]! },\n )\n // A document is written only once its config edit applied, in edit order, so the last edit for a file wins.\n let wroteDocument = false\n for (const [index, edit] of kept.entries()) {\n if (!('document' in edit) || !edit.document || !outcomes[index]!.applied) continue\n await writeFile(path.join(this.#options.root, edit.document.fileName), edit.document.text, 'utf-8')\n wroteDocument = true\n }\n const changed = written.changed || wroteDocument\n const applied = outcomes.filter((outcome) => outcome.applied).length\n await this.#logCommand('saveConfig', `applied ${applied}/${outcomes.length} edits to ${configPath}`, input.requestedBy)\n\n return { outcomes, changed }\n } catch (error) {\n // Refuse every edit so Studio hears back instead of waiting.\n await emit(this.#options.hooks, 'studio:error', { error: toError(error) })\n return refuse(getErrorMessage(error))\n } finally {\n this.#session.saving = false\n }\n }\n\n /**\n * Readies a `set-input` edit for the config file: a document is pointed at `openapi.yaml` (`openapi.json`\n * for JSON) in the project, one file per config entry, for `saveConfig` to write once the edit applies.\n * A managed agent refuses a file path, as in a generation. Every agent refuses a file path outside the project.\n */\n async #keepInput(edit: ConfigEdit): Promise<KeptEdit> {\n // A blank input goes on unchanged, so the config writer refuses it before any file is written.\n if (edit?.operation !== ConfigEditOperation.SET_INPUT || typeof edit.input !== 'string' || !edit.input.trim()) return edit\n if (!this.#permissions.allowSaveInput) {\n await this.#warn({ message: 'Ignored the spec to save: saving the input was not granted', permission: AgentPermission.SAVE_INPUT })\n return { reason: 'the agent was not granted permission to save the input' }\n }\n const kind = getInputKind(edit.input)\n if (this.#managed && !MANAGED_INPUT_KINDS.has(kind)) return { reason: AgentMessage.MANAGED_INPUT_KIND }\n // The next generation reads the input file itself, and the `$ref` limit does not cover it.\n // A `url` that is not http(s), such as `C:\\spec.yaml`, is read as a file path too.\n const isFilePath = kind === 'file' || (kind === 'url' && !/^https?:/i.test(edit.input))\n if (isFilePath && !isPathInside(path.resolve(this.#options.root, edit.input), this.#options.root)) {\n return { reason: 'the input is a file outside the project' }\n }\n if (kind !== 'inline') return edit\n\n const entry = edit.config === undefined || edit.config === 0 ? '' : `-${String(edit.config).replace(/[^\\w.-]/g, '-')}`\n const fileName = `openapi${entry}.${isJson(edit.input) ? 'json' : 'yaml'}`\n return { ...edit, input: `./${fileName}`, document: { fileName, text: edit.input } }\n }\n\n /**\n * Installs a registry extension into the project with `kubb add <id> --yes`, which also adds a\n * plugin to `kubb.config.ts`. Studio calls `connect()` again afterwards to see the result.\n */\n async installExtension(input: InstallExtensionInput): Promise<InstallExtensionResult> {\n this.#assertConnected()\n const { root, configFile, kubbBin = findKubbBin(root) } = this.#options\n const refuse = async (reason: string, permission?: AgentPermission): Promise<InstallExtensionResult> => {\n await this.#warn({ message: `Ignored install: ${reason}`, permission })\n return { installed: false, reason }\n }\n\n if (typeof input?.id !== 'string' || !REGISTRY_ID.test(input.id)) return refuse('the message carried no registry id')\n if (!this.#permissions.allowInstall) return refuse('installing extensions was not granted', AgentPermission.INSTALL)\n if (!this.#permissions.allowConfigEdit) return refuse('editing kubb.config.ts was not granted', AgentPermission.CONFIG_EDIT)\n const busy = this.#busy()\n if (busy) return refuse(busy)\n if (!kubbBin) return refuse('kubb is not installed in the project')\n\n const { failed, output } = await this.#runKubb({ bin: kubbBin, args: ['add', input.id, '--yes', '--config', configFile] })\n await this.#logCommand('installExtension', `${failed ? 'failed to install' : 'installed'} ${input.id}`, input.requestedBy, failed)\n return failed ? { installed: false, reason: output } : { installed: true }\n }\n\n /**\n * Moves installed extensions to the registry's version with `kubb update [ids] --yes`, which\n * installs packages and leaves `kubb.config.ts` alone. Studio calls `connect()` again afterwards.\n */\n async updateExtensions(input: UpdateExtensionsInput): Promise<UpdateExtensionsResult> {\n this.#assertConnected()\n const { root, kubbBin = findKubbBin(root) } = this.#options\n const refuse = async (reason: string, permission?: AgentPermission): Promise<UpdateExtensionsResult> => {\n await this.#warn({ message: `Ignored update: ${reason}`, permission })\n return { updated: false, reason }\n }\n\n const ids = input?.ids ?? []\n if (!Array.isArray(ids) || !ids.every((id) => typeof id === 'string' && REGISTRY_ID.test(id))) return refuse('the message carried an invalid registry id')\n if (!this.#permissions.allowUpdate) return refuse('updating extensions was not granted', AgentPermission.UPDATE)\n const busy = this.#busy()\n if (busy) return refuse(busy)\n if (!kubbBin) return refuse('kubb is not installed in the project')\n\n const { failed, output } = await this.#runKubb({ bin: kubbBin, args: ['update', ...ids, '--yes'] })\n await this.#logCommand('updateExtensions', `${failed ? 'failed to update' : 'updated'} ${ids.join(', ') || 'all extensions'}`, input?.requestedBy, failed)\n return failed ? { updated: false, reason: output } : { updated: true }\n }\n\n /**\n * Removes an extension with `kubb remove <id> --yes`, which deletes it from `kubb.config.ts` and\n * uninstalls its package. Studio calls `connect()` again afterwards.\n */\n async removeExtension(input: RemoveExtensionInput): Promise<RemoveExtensionResult> {\n this.#assertConnected()\n const { root, configFile, kubbBin = findKubbBin(root) } = this.#options\n const refuse = async (reason: string, permission?: AgentPermission): Promise<RemoveExtensionResult> => {\n await this.#warn({ message: `Ignored remove: ${reason}`, permission })\n return { removed: false, reason }\n }\n\n if (typeof input?.id !== 'string' || !REGISTRY_ID.test(input.id)) return refuse('the message carried no registry id')\n if (!this.#permissions.allowRemove) return refuse('removing extensions was not granted', AgentPermission.REMOVE)\n if (!this.#permissions.allowConfigEdit) return refuse('editing kubb.config.ts was not granted', AgentPermission.CONFIG_EDIT)\n const busy = this.#busy()\n if (busy) return refuse(busy)\n if (!kubbBin) return refuse('kubb is not installed in the project')\n\n const { failed, output } = await this.#runKubb({ bin: kubbBin, args: ['remove', input.id, '--yes', '--config', configFile] })\n await this.#logCommand('removeExtension', `${failed ? 'failed to remove' : 'removed'} ${input.id}`, input.requestedBy, failed)\n return failed ? { removed: false, reason: output } : { removed: true }\n }\n\n /** Why a command that touches the project cannot start right now. */\n #busy(): string | undefined {\n if (this.#session.active) return 'a generation is in progress'\n if (this.#session.install) return 'an install, update, or remove is in progress'\n if (this.#session.saving) return 'a save is in progress'\n return undefined\n }\n\n /** Runs `kubb` in the project while holding off saves and generations, and ends it when the socket closes. */\n async #runKubb({ bin, args }: { bin: string; args: Array<string> }) {\n const controller = new AbortController()\n const settled = Promise.withResolvers<void>()\n this.#session.install = { abort: () => controller.abort(), settled: settled.promise }\n try {\n return await runKubb({ bin, args, cwd: this.#options.root, signal: controller.signal })\n } finally {\n this.#session.install = undefined\n settled.resolve()\n }\n }\n\n /**\n * Returns the Kubb AST a kept job parsed its spec into. Refused without `allowReadAst`.\n */\n async readInput(input: ReadInputInput): Promise<ReadInputResult> {\n this.#assertConnected()\n if (!this.#permissions.allowReadAst) return this.#refuse({ message: AgentMessage.READ_AST_NOT_ALLOWED, permission: AgentPermission.READ_AST })\n if (typeof input.jobId !== 'string' || !input.jobId) return this.#refuse({ message: AgentMessage.JOB_REQUIRED })\n\n const generation = await this.#generations.get(input.jobId)\n if (!generation) return this.#refuse({ message: AgentMessage.GENERATION_GONE })\n // A rerun of the job can leave an earlier run's input on disk, so trust only what this run kept.\n const kept = generation.inputBytes ? await this.#generations.readInput(input.jobId) : undefined\n if (!kept) return this.#refuse({ message: AgentMessage.NO_INPUT })\n await this.#logCommand('readInput', 'read the API input')\n\n return { input: kept }\n }\n\n /**\n * Returns the requested files of a kept job, one page of lines at a time. Refused without `allowRead`.\n */\n async readFiles(input: ReadFilesInput): Promise<ReadFilesResult> {\n this.#assertConnected()\n if (!this.#permissions.allowRead) return this.#refuse({ message: AgentMessage.READ_NOT_ALLOWED, permission: AgentPermission.READ })\n if (!Array.isArray(input.paths) || typeof input.jobId !== 'string' || !input.jobId) {\n return this.#refuse({ message: AgentMessage.FILE_REQUEST_INVALID })\n }\n const { paths } = input\n if (paths.length > MAX_FILES_PER_REQUEST) return this.#refuse({ message: AgentMessage.TOO_MANY_FILES })\n if (!isValidPage(input)) return this.#refuse({ message: AgentMessage.INVALID_PAGE })\n\n const generation = await this.#generations.get(input.jobId)\n if (!generation) return this.#refuse({ message: AgentMessage.GENERATION_GONE })\n\n // Only paths the set holds are read, never an arbitrary path.\n const result = await this.#generations.read({ generation, paths, cursor: input.cursor, limit: input.limit })\n await this.#logCommand('readFiles', `read ${Object.keys(result.files).length}/${paths.length} requested file${paths.length === 1 ? '' : 's'}`)\n\n return result\n }\n\n /**\n * Returns one page of the line diff of a file between two kept sets. Refused without `allowRead`.\n */\n async readDiff(input: ReadDiffInput): Promise<ReadDiffResult> {\n this.#assertConnected()\n if (!this.#permissions.allowRead) return this.#refuse({ message: AgentMessage.READ_NOT_ALLOWED, permission: AgentPermission.READ })\n const { jobId, path, base, cursor = 0, limit } = input\n if (typeof jobId !== 'string' || !jobId || typeof path !== 'string' || !path || typeof base?.jobId !== 'string' || !base.jobId) {\n return this.#refuse({ message: AgentMessage.DIFF_REQUEST_INVALID })\n }\n if (!isValidPage({ cursor, limit })) {\n return this.#refuse({ message: AgentMessage.INVALID_PAGE })\n }\n\n const [generation, baseGeneration] = await Promise.all([this.#generations.get(jobId), this.#generations.get(base.jobId)])\n if (!generation || !baseGeneration) return this.#refuse({ message: AgentMessage.GENERATION_GONE })\n\n // Only paths the sets hold are read, never an arbitrary path.\n const [after, before] = await Promise.all([\n this.#generations.read({ generation, paths: [path] }),\n this.#generations.read({ generation: baseGeneration, paths: [path] }),\n ])\n const afterContent = after.files[path]\n // Over the size cap only hashes are kept, which must not read as a deleted file.\n if (afterContent === undefined && path in generation.output.hashes) return this.#refuse({ message: AgentMessage.HASHES_ONLY })\n const beforeContent = before.files[path]\n if (beforeContent === undefined)\n return { hunks: [], nextCursor: null, hasBase: false, stats: { additions: 0, deletions: 0, hunks: 0, lines: 0, coarse: false } }\n\n const key = JSON.stringify([jobId, base.jobId, path])\n let diff = this.#diffs.get(key)\n if (!diff) {\n diff = diffHunks(beforeContent, afterContent ?? '')\n this.#diffs.set(key, diff)\n // A few recent diffs cover paging through the open file and switching back to the last one.\n if (this.#diffs.size > 4) this.#diffs.delete(this.#diffs.keys().next().value!)\n }\n await this.#logCommand('readDiff', `read the diff of ${path}`)\n\n return { ...pageHunks({ hunks: diff.hunks, cursor, limit }), hasBase: true, stats: diff.stats }\n }\n}\n\nconst openWebSocketRpc: OpenRpc = ({ url, token, instanceId, agent }) => {\n // Node's `WebSocket` takes undici's `headers` option, which the DOM typing leaves out.\n const NodeWebSocket = WebSocket as unknown as new (url: URL, init: { headers: Record<string, string> }) => WebSocket\n const socket = new NodeWebSocket(url, { headers: { Authorization: `Bearer ${token}`, [AGENT_INSTANCE_HEADER]: instanceId } })\n const timer = setTimeout(() => socket.close(3008, 'Connection timeout'), OPEN_TIMEOUT_MS)\n socket.addEventListener('open', () => clearTimeout(timer), { once: true })\n\n const closed = new Promise<Awaited<Rpc['closed']>>((resolve) => {\n socket.addEventListener('close', ({ code, reason }) => resolve({ code, reason }), { once: true })\n // Node fires only `error` when the handshake itself fails.\n socket.addEventListener('error', () => {\n if (socket.readyState !== WebSocket.OPEN) resolve({ code: 1006, reason: '' })\n })\n }).finally(() => clearTimeout(timer))\n\n const studio = newWebSocketRpcSession<StudioApi>(socket, agent)\n studio.onRpcBroken(() => socket.close())\n\n return {\n studio,\n closed,\n close: () => {\n studio[Symbol.dispose]()\n socket.close()\n },\n }\n}\n\nasync function runSession({ options, openRpc, url, instanceId }: { options: ResolvedOptions; openRpc: OpenRpc; url: URL; instanceId: string }) {\n const { hooks, signal, heartbeatInterval, studioUrl, version } = options\n const token = typeof options.token === 'function' ? await options.token() : options.token\n if (signal?.aborted) return { code: 1000, reason: '', connected: false }\n const session: Session = { connected: Promise.withResolvers(), closed: false }\n const agent = new Agent({ options, session })\n const rpc = openRpc({ url, token, instanceId, agent })\n signal?.addEventListener('abort', rpc.close, { once: true })\n let timer: ReturnType<typeof setTimeout> | undefined\n\n // Races each ping against a deadline, so a half-open socket can't hang it forever.\n const heartbeat = async (): Promise<void> => {\n let deadline: ReturnType<typeof setTimeout> | undefined\n const timedOut = new Promise<boolean>((resolve) => (deadline = setTimeout(resolve, PING_TIMEOUT_MS, true)))\n const failed = await Promise.race([\n Promise.resolve(rpc.studio.ping()).then(\n () => false,\n () => true,\n ),\n timedOut,\n ])\n clearTimeout(deadline)\n if (failed) return rpc.close()\n if (!session.closed) timer = setTimeout(heartbeat, heartbeatInterval)\n }\n\n void session.connected.promise.then(\n async (info) => {\n await emit(hooks, 'studio:connected', { ...info, url: studioUrl, versions: { studio: info.studioVersion, kubb: kubbVersion, agent: version } })\n if (!session.closed) timer = setTimeout(heartbeat, heartbeatInterval)\n },\n () => {},\n )\n\n const close = await rpc.closed\n session.closed = true\n clearTimeout(timer)\n signal?.removeEventListener('abort', rpc.close)\n session.connected.reject(new Error('The socket closed before Studio called connect()'))\n // Captured and aborted before the warning, so a slow listener neither keeps the run going nor\n // sees it finish and clear `session.active` first.\n const active = session.active\n if (active) {\n active.abort()\n await emit(hooks, 'studio:warn', { message: 'Canceled the running generation: the connection to Kubb Studio closed' })\n }\n await active?.settled\n session.install?.abort()\n await session.install?.settled\n await agent.clear()\n\n return { ...close, connected: session.info !== undefined }\n}\n\n/**\n * The connection loop with a swappable transport. {@link connectAgent} passes a real WebSocket.\n */\n/** The entry Studio named by position or `name`, else the first. `undefined` for one the file does not have. */\nfunction pickConfig(configs: Array<Config>, ref: ConfigRef | undefined): Config | undefined {\n if (typeof ref === 'string') return configs.find((config) => config.name === ref)\n if (ref !== undefined && !Number.isSafeInteger(ref)) return undefined\n return configs[ref ?? 0]\n}\n\n/** Whether `text` parses as JSON, so a pasted document is saved under the matching extension. */\nfunction isJson(text: string): boolean {\n try {\n JSON.parse(text)\n return true\n } catch {\n return false\n }\n}\n\n/** The input path or URL Studio may show: no inline document, and no credentials from a URL. */\nfunction reportedInput(input: Config['input']): string | undefined {\n if (typeof input !== 'string') return undefined\n const kind = getInputKind(input)\n if (kind === 'inline') return undefined\n // The scp-style git form (`git+git@host:org/repo.git`) is no URL and carries no password.\n if ((kind !== 'url' && kind !== 'git') || !URL.canParse(input)) return input\n const url = new URL(input)\n url.username = ''\n url.password = ''\n return url.href\n}\n\n/** A JSON copy of one resolved entry, each extension named by the package its manifest is in. */\nfunction toEntryView(config: Config, extensions: InstalledExtensions): ConfigEntryView {\n const input = reportedInput(config.input)\n return {\n ...(config.name !== undefined && { name: config.name }),\n ...(input !== undefined && { input }),\n output: config.output.path,\n outputOptions: toJSONOptions(pickOutput(config.output)),\n plugins: config.plugins.map((plugin) => ({\n name: toStudioName({ name: resolveMeta(plugin).name, extensions }),\n options: toJSONOptions(plugin.options),\n })),\n adapter: config.adapter && {\n name: toStudioName({ name: resolveMeta(config.adapter).name, extensions, kind: 'adapter' }),\n options: toJSONOptions(config.adapter.options),\n },\n parsers: config.parsers.map((parser) => ({\n name: toStudioName({ name: resolveMeta(parser).name, extensions, kind: 'parser' }),\n options: toJSONOptions(parser.options),\n })),\n }\n}\n\nexport async function runAgent({ options, openRpc }: { options: ConnectAgentOptions; openRpc: OpenRpc }): Promise<void> {\n const root = options.root ?? process.cwd()\n const resolved: ResolvedOptions = {\n ...options,\n studioUrl: options.studioUrl ?? defaultStudioUrl,\n root,\n agentType: options.agentType ?? 'user',\n configFile: path.resolve(root, options.configPath),\n permissions: {\n allowWrite: false,\n allowConfigEdit: false,\n allowInstall: false,\n allowUpdate: false,\n allowRemove: false,\n allowSaveInput: false,\n allowFileRefs: false,\n allowExec: false,\n allowRead: false,\n allowReadAst: false,\n ...options.permissions,\n },\n hooks: options.hooks ?? new Hookable<KubbHooks>(),\n maxRetryDelay: options.maxRetryDelay ?? MAX_RETRY_DELAY_MS,\n heartbeatInterval: Math.min(options.heartbeatInterval ?? HEARTBEAT_INTERVAL_MS, MAX_HEARTBEAT_INTERVAL_MS),\n }\n const { studioUrl, hooks, signal, maxRetryDelay } = resolved\n const url = secureUrl({ studioUrl, path: AGENT_SOCKET_PATH, socket: true })\n // One per call, so a reconnect is the same process to Studio and a restart is a new one.\n const instanceId = randomUUID()\n let attempt = 0\n\n while (!signal?.aborted) {\n const { code, reason, connected } = await runSession({ options: resolved, openRpc, url, instanceId })\n if (signal?.aborted) return\n await emit(hooks, 'studio:disconnected', { code, reason })\n\n if (code === AgentCloseCode.UNAUTHORIZED) throw new InvalidAgentTokenError(studioUrl)\n if (code === AgentCloseCode.INCOMPATIBLE) throw new IncompatibleAgentError({ studioUrl, detail: reason })\n if (code === AgentCloseCode.SUPERSEDED) return\n\n // Reset only once Studio called connect(), so a socket that opens and closes again backs off.\n if (connected) attempt = 0\n const delayMs = Math.random() * Math.min(1_000 * 2 ** Math.min(attempt++, 16), maxRetryDelay)\n await emit(hooks, 'studio:reconnecting', { delayMs })\n await delay(delayMs, undefined, { signal }).catch(() => {})\n }\n}\n\n/**\n * Connects this project to Kubb Studio and serves its commands until `signal` aborts. Reconnects\n * with jittered backoff, and resolves when another process of the agent takes over. Rejects with\n * {@link InvalidAgentTokenError} so the host can pair again, or {@link IncompatibleAgentError}.\n *\n * @example\n * ```ts\n * const hooks = new Hookable<KubbHooks>()\n * hooks.hook('studio:connected', ({ agentSlug }) => console.log(`Connected as ${agentSlug}`))\n *\n * await connectAgent({ token, configPath: 'kubb.config.ts', loadConfigs, version: '1.0.0', hooks, signal })\n * ```\n */\nexport function connectAgent(options: ConnectAgentOptions): Promise<void> {\n return runAgent({ options, openRpc: openWebSocketRpc })\n}\n","import { hash } from 'node:crypto'\nimport { setTimeout as delay } from 'node:timers/promises'\nimport { toError } from '@internals/utils'\nimport { Diagnostics } from '@kubb/core'\nimport { ofetch } from 'ofetch'\nimport { getAgentPublicKey, getTokenRefreshPayload, signAgentPayload } from './agentKey.ts'\nimport { InvalidAgentTokenError } from './connect.ts'\nimport { AgentSignatureContext, type TokenRefreshProof } from './protocol.ts'\nimport { defaultStudioUrl, secureUrl } from './url.ts'\n\n/**\n * RFC 8628 device-authorization response from Studio's `/api/auth/device/code` endpoint.\n * Field names match the RFC; the CLI polls with `device_code` and shows `user_code` to the user.\n */\nexport type PairingSession = {\n device_code: string\n user_code: string\n verification_uri: string\n verification_uri_complete: string\n expires_in: number\n interval: number\n}\n\ntype PairingResult = {\n /**\n * Bearer token for this machine. Write credentials with mode 0600 and never log the value.\n */\n token: string\n agent: {\n /**\n * Stable agent id in Studio.\n */\n id: string\n /**\n * Short slug used in logs and the UI (for example `brave-otter`).\n */\n slug: string\n /**\n * Display name chosen at pairing time.\n */\n name: string\n /**\n * This agent's organization slug, absent for a sandbox or global agent, which has none.\n */\n organizationSlug?: string\n }\n}\n\n/**\n * What this machine registers as. Any member may approve `cli` (`kubb studio`); only an admin may\n * approve `user` and `sandbox` (the Docker image). A `ci` agent never pairs.\n */\ntype PairingAgentType = 'cli' | 'user' | 'sandbox'\n\n/** Labels, not secrets: a person approving the code in the browser is what authorizes a pairing. */\nconst CLIENT_IDS = { cli: 'kubb-cli', agent: 'kubb-agent' } as const\n\n/**\n * Thrown when a caller aborts `startPairing` or `pollForPairingToken` through their `signal`, such\n * as a `kubb studio` shutdown mid-pairing. Distinct from a denial or an expired code, so a host can\n * exit quietly instead of reporting a pairing failure.\n */\nexport class PairingCanceledError extends Error {\n constructor() {\n super('Pairing was canceled')\n this.name = 'PairingCanceledError'\n }\n}\n\n/** Thrown when the code expired unapproved. A fresh code can still succeed. */\nexport class PairingExpiredError extends Error {\n constructor(message = 'The pairing code expired, pair again') {\n super(message)\n this.name = 'PairingExpiredError'\n }\n}\n\n/** Thrown when the pairing was denied in the browser, including by the organization's agent limit. */\nexport class PairingDeniedError extends Error {\n constructor(message = 'Pairing was denied in the browser') {\n super(message)\n this.name = 'PairingDeniedError'\n }\n}\n\ntype StartPairingOptions = {\n studioUrl?: string\n type: PairingAgentType\n /**\n * Display name for the agent, usually the project or machine name.\n */\n name: string\n hostname: string\n /**\n * A stable secret the host keeps for this machine. Studio stores its hash against the agent, so\n * the same machine pairing again rotates one agent's token instead of creating a second agent.\n */\n machineId: string\n /**\n * The agent key from `generateAgentKey`. Only its public half is sent.\n */\n privateKey?: string\n /**\n * Aborting this cancels the request in flight and rejects with {@link PairingCanceledError}.\n */\n signal?: AbortSignal\n}\n\n/**\n * Asks Studio for a pairing code, sending the hashed machine id with it.\n */\nexport async function startPairing({\n studioUrl = defaultStudioUrl,\n type,\n name,\n hostname,\n machineId,\n privateKey,\n signal,\n}: StartPairingOptions): Promise<PairingSession> {\n try {\n const pairing = await ofetch<PairingSession>(secureUrl({ studioUrl, path: '/api/auth/device/code' }).href, {\n method: 'POST',\n body: {\n client_id: type === 'cli' ? CLIENT_IDS.cli : CLIENT_IDS.agent,\n name,\n hostname,\n machine_token: hash('sha256', machineId),\n agent_kind: type === 'cli' ? undefined : type,\n public_key: privateKey ? getAgentPublicKey(privateKey) : undefined,\n },\n signal,\n })\n if (typeof pairing?.device_code !== 'string')\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: 'Kubb Studio returned no pairing code',\n help: 'Try again later. If it keeps failing, check the Kubb Studio status.',\n })\n\n return pairing\n } catch (error) {\n if (signal?.aborted) {\n throw new PairingCanceledError()\n }\n\n throw error\n }\n}\n\ntype PollOptions = {\n studioUrl?: string\n session: PairingSession\n /**\n * Aborting this stops polling and rejects with {@link PairingCanceledError}, whether the abort\n * lands between polls or during the wait for the next one.\n */\n signal?: AbortSignal\n /** Called when a poll could not reach Studio. Polling carries on. */\n onRetry?: (error: Error) => void\n}\n\ntype PollError = 'authorization_pending' | 'slow_down' | 'expired_token' | 'access_denied' | 'invalid_grant'\n\ntype PollResponse =\n | PairingResult\n | {\n error: PollError | string\n /**\n * Why, when Studio has something more useful to say than the RFC code. An approval that hits\n * the organization's agent limit comes back as `access_denied` with the limit spelled out.\n */\n error_description?: string\n }\n\nfunction isPairingResult(response: PollResponse): response is PairingResult {\n return 'token' in response && typeof response.token === 'string'\n}\n\n/**\n * Polls until the user approves or denies, honoring the server's `slow_down` back-off.\n *\n * Studio's own endpoint is used rather than the auth layer's `/device/token`, because an approved\n * Kubb pairing is worth an agent bearer token, not a user session.\n *\n * @throws {PairingExpiredError} when the code expires before anyone approves it.\n * @throws {PairingDeniedError} when the pairing is denied in the browser.\n * @throws {PairingCanceledError} when `signal` aborts.\n */\nexport async function pollForPairingToken({ studioUrl = defaultStudioUrl, session, signal, onRetry }: PollOptions): Promise<PairingResult> {\n // Both fields cross the network, so neither is trusted as-is: a missing or zero `interval` would\n // spin the poll loop, and a missing or zero `expires_in` would expire the code before the first\n // poll. `> 0` is also false for `NaN` and for a missing field, so it doubles as the type guard.\n const deadline = Date.now() + (session.expires_in > 0 ? session.expires_in : 600) * 1000\n let intervalMs = (session.interval > 0 ? session.interval : 5) * 1000\n\n while (Date.now() < deadline) {\n if (signal?.aborted) {\n throw new PairingCanceledError()\n }\n\n try {\n await delay(intervalMs, undefined, { signal })\n } catch {\n throw new PairingCanceledError()\n }\n\n let response: PollResponse\n try {\n // A denial, an expiry, and \"not yet\" all come back as 4xx with a body to switch on.\n const { status, _data } = await ofetch.raw<PollResponse>(secureUrl({ studioUrl, path: '/api/agent/token' }).href, {\n method: 'POST',\n body: { device_code: session.device_code },\n signal,\n ignoreResponseError: true,\n })\n if (status >= 500 || !_data || typeof _data !== 'object')\n throw new Diagnostics.Error({\n code: Diagnostics.code.inputRequestFailed,\n severity: 'error',\n message: `Kubb Studio answered with status ${status}`,\n help: 'Try again later.',\n })\n response = _data\n } catch (error) {\n if (signal?.aborted) {\n throw new PairingCanceledError()\n }\n\n // Studio can be briefly unreachable (a deploy) while the code is still valid, so retry.\n onRetry?.(toError(error))\n continue\n }\n\n if (isPairingResult(response)) {\n return response\n }\n\n if (!('error' in response) || typeof response.error !== 'string') {\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: 'Kubb Studio returned an empty pairing response, pair again',\n })\n }\n\n if (response.error === 'authorization_pending') {\n continue\n }\n\n if (response.error === 'slow_down') {\n intervalMs += 5_000\n continue\n }\n\n if (response.error === 'access_denied') {\n throw new PairingDeniedError(response.error_description)\n }\n\n if (response.error === 'expired_token' || response.error === 'invalid_grant') {\n throw new PairingExpiredError(response.error_description)\n }\n\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: response.error_description ?? `Pairing failed (${response.error})`,\n help: 'Pair again with `kubb studio login`.',\n })\n }\n\n throw new PairingExpiredError()\n}\n\ntype PairAgentOptions = StartPairingOptions & {\n /** Shows the code to whoever approves it. Called again for each fresh code. */\n onCode: (session: PairingSession, attempt: number) => void | Promise<void>\n /** Called when a poll could not reach Studio. Polling carries on. */\n onRetry?: (error: Error) => void\n /**\n * Codes to ask for in total when one expires unapproved. A denial or abort ends it at once.\n * @default 1\n */\n maxAttempts?: number\n}\n\n/**\n * Pairs this machine with Studio: asks for a code, hands it to the host to show, and waits for approval.\n */\nexport async function pairAgent({ onCode, onRetry, maxAttempts = 1, ...options }: PairAgentOptions): Promise<PairingResult> {\n for (let attempt = 1; ; attempt++) {\n const session = await startPairing(options)\n await onCode(session, attempt)\n\n try {\n return await pollForPairingToken({ studioUrl: options.studioUrl, session, signal: options.signal, onRetry })\n } catch (error) {\n if (!(error instanceof PairingExpiredError) || attempt >= maxAttempts) {\n throw error\n }\n }\n }\n}\n\nconst REFRESH_TIMEOUT_MS = 15_000\n\ntype RefreshAgentTokenOptions = {\n studioUrl?: string\n token: string\n /**\n * The secret the machine paired with.\n */\n machineId: string\n /**\n * The stored agent key, which signs the request.\n */\n privateKey?: string\n signal?: AbortSignal\n /**\n * How long to wait for an answer, in milliseconds.\n *\n * @default 15000\n */\n timeout?: number\n}\n\n/**\n * Trades the agent's token for a new one. The old token stops working at once, so store the new\n * one first. Resolves `null` when there is nothing to refresh, and rejects with\n * {@link InvalidAgentTokenError} when the token is refused.\n */\nexport async function refreshAgentToken({\n studioUrl = defaultStudioUrl,\n token,\n machineId,\n privateKey,\n signal,\n timeout = REFRESH_TIMEOUT_MS,\n}: RefreshAgentTokenOptions): Promise<string | null> {\n const deadline = AbortSignal.timeout(timeout)\n const signedAt = Date.now()\n const proof: TokenRefreshProof | undefined = privateKey\n ? {\n signed_at: signedAt,\n signature: signAgentPayload({ privateKey, context: AgentSignatureContext.TOKEN_REFRESH, payload: getTokenRefreshPayload({ token, signedAt }) }),\n }\n : undefined\n const { status, _data } = await ofetch\n .raw<{ token?: unknown }>(secureUrl({ studioUrl, path: '/api/agent/token/refresh' }).href, {\n method: 'POST',\n headers: { Authorization: `Bearer ${token}` },\n body: { machine_id: machineId, ...proof },\n signal: signal ? AbortSignal.any([signal, deadline]) : deadline,\n ignoreResponseError: true,\n // A second attempt would send a token the first may have retired.\n retry: 0,\n })\n .catch((error: unknown) => {\n if (deadline.aborted && !signal?.aborted)\n throw new Diagnostics.Error({\n code: Diagnostics.code.inputRequestFailed,\n severity: 'error',\n message: `Kubb Studio did not answer the token refresh within ${timeout} ms`,\n help: 'The token is unchanged. Try again later.',\n })\n throw error\n })\n\n if (status === 404 || status === 409) return null\n if (status === 401) throw new InvalidAgentTokenError(studioUrl)\n if (status < 200 || status >= 300)\n throw new Diagnostics.Error({\n code: Diagnostics.code.inputRequestFailed,\n severity: 'error',\n message: `Kubb Studio answered the token refresh with status ${status}`,\n help: 'The token is unchanged. Try again later.',\n })\n if (typeof _data?.token !== 'string' || !_data.token)\n throw new Diagnostics.Error({ code: Diagnostics.code.unknown, severity: 'error', message: 'Kubb Studio answered the token refresh without a token' })\n\n return _data.token\n}\n","import { tmpdir } from 'node:os'\nimport { join, resolve } from 'node:path'\nimport { gzipSync } from 'node:zlib'\nimport { getErrorMessage, mkdir, mkdtemp, read, rm, writeRaw } from '@internals/utils'\nimport { type Config, Diagnostics, fsStorage, type Hookable, Kubb, type KubbHooks, readInstalledPackages, resolveMeta } from '@kubb/core'\nimport { ofetch } from 'ofetch'\nimport { generationFailure, hashOf, relativeStoragePath } from './generations.ts'\nimport { MAX_SNAPSHOT_BYTES, type PublishedSnapshot, type SnapshotUploadMetadata } from './protocol.ts'\nimport { toPackageName } from './resolveConfig.ts'\nimport { defaultStudioUrl, secureUrl } from './url.ts'\n\nconst UPLOAD_TIMEOUT_MS = 120_000\n\n// Plugins whose output a snapshot carries without depending on the plugin package.\nconst BUNDLED_DEPENDENCIES = ['@kubb/plugin-barrel']\n\ntype SnapshotFiles = Record<string, string>\ntype SnapshotPackage = { name: string; version: string; peerDependencies: Record<string, string> }\n\n/**\n * Maps a generated file to its path in the package, from its `src`/`dist` segment on, without `..` parts that could escape it.\n */\nfunction packagePath(filePath: string): string {\n const normalized = filePath.replaceAll('\\\\', '/')\n const relativePath = normalized.match(/\\/(?:src|dist)\\/.*$/)?.[0] ?? normalized\n return relativePath\n .split('/')\n .filter((part) => part && part !== '.' && part !== '..')\n .join('/')\n}\n\n/**\n * Splits a tar path into the 100-byte USTAR `name` and the 155-byte `prefix`, and throws for a path that fits neither.\n */\nfunction splitEntryPath(path: string): { name: string; prefix: string } {\n if (Buffer.byteLength(path) <= 100) return { name: path, prefix: '' }\n for (let i = path.lastIndexOf('/'); i > 0; i = path.lastIndexOf('/', i - 1)) {\n const prefix = path.slice(0, i)\n const name = path.slice(i + 1)\n if (Buffer.byteLength(prefix) <= 155 && Buffer.byteLength(name) <= 100) return { name, prefix }\n }\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `Snapshot path is too long for a tar entry: ${path}`,\n help: 'Shorten the output path or the generated file names.',\n })\n}\n\nfunction header(path: string, size: number): Buffer {\n const { name, prefix } = splitEntryPath(path)\n const value = Buffer.alloc(512)\n value.write(name)\n value.write('0000644\\0', 100)\n for (const offset of [108, 116, 265, 297]) value.write('0000000\\0', offset)\n value.write(`${size.toString(8).padStart(11, '0')}\\0`, 124)\n // npm's fixed mtime, so the same files always pack to the same integrity.\n value.write('03560116604\\0', 136)\n value.fill(32, 148, 156)\n value.write('0', 156)\n value.write('ustar\\0', 257)\n value.write('00', 263)\n value.write(prefix, 345)\n const checksum = value.reduce((sum, byte) => sum + byte, 0)\n value.write(`${checksum.toString(8).padStart(6, '0')}\\0 `, 148)\n return value\n}\n\n/**\n * Loads `tsdown` on first use. It is an optional peer dependency: it is large, and only snapshots need it.\n */\nexport async function loadTsdown(load = () => import('tsdown')): Promise<typeof import('tsdown')> {\n try {\n return await load()\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ERR_MODULE_NOT_FOUND' || !(error as Error).message.includes(\"'tsdown'\")) throw error\n throw new Diagnostics.Error({\n code: Diagnostics.code.missingDependency,\n severity: 'error',\n message: 'Missing dependency: tsdown. A snapshot builds its dist files with tsdown, which Kubb does not install by default.',\n help: 'Run `npm i -D tsdown` in the project, then try again.',\n })\n }\n}\n\n/**\n * Packs a generation's files into a gzipped, npm-installable tarball: a `package/` root with the\n * generated sources, a `tsdown`-built `dist/` (esm + cjs), and a `package.json` manifest.\n */\nexport async function createSnapshotPackage({ files, packageInfo }: { files: SnapshotFiles; packageInfo: SnapshotPackage }): Promise<Buffer> {\n const sources = new Map<string, { name: string; content: string }>()\n for (const [name, content] of Object.entries(files)) {\n const path = packagePath(name)\n const owner = sources.get(path)?.name\n if (owner)\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `Snapshot has two generated files that sanitize to the same path \"package/${path}\": \"${owner}\" and \"${name}\"`,\n help: 'Rename one of the generated files, for example with a plugin resolver.',\n })\n sources.set(path, { name, content })\n }\n const root = await mkdtemp(join(tmpdir(), 'kubb-snapshot-'))\n const dist = join(root, 'dist')\n\n try {\n await mkdir(dist)\n await Promise.all(\n [...sources].map(async ([path, { content }]) => {\n await writeRaw(join(root, path), content)\n }),\n )\n const entry = [...sources.keys()].filter((path) => /\\.(?:[cm]?[jt]sx?)$/.test(path)).map((path) => join(root, path))\n if (entry.length) {\n const { build } = await loadTsdown()\n // `fixedExtension` emits the `.mjs`/`.cjs` the manifest names, whatever \"type\" the host's own package.json sets.\n await build({\n entry,\n outDir: dist,\n format: ['esm', 'cjs'],\n dts: false,\n sourcemap: false,\n unbundle: true,\n report: false,\n logLevel: 'silent',\n fixedExtension: true,\n })\n }\n const built = await fsStorage().readKeys(dist)\n // Only `@kubb/plugin-barrel` produces a `dist/index.*` for `main`, `module`, and `exports['.']` to name.\n const hasBarrel = built.includes('index.mjs') && built.includes('index.cjs')\n const manifest = {\n ...packageInfo,\n type: 'module',\n ...(hasBarrel ? { main: './dist/index.cjs', module: './dist/index.mjs' } : {}),\n // `exports` denies any subpath it does not list, so the wildcard keeps each generated file importable.\n exports: {\n ...(hasBarrel ? { '.': { import: './dist/index.mjs', require: './dist/index.cjs' } } : {}),\n './*': { import: './dist/*.mjs', require: './dist/*.cjs' },\n },\n }\n const entries = new Map<string, string>([\n ['package.json', JSON.stringify(manifest, null, 2)],\n ...[...sources].map(([path, { content }]) => [path, content] as const),\n ...(await Promise.all(built.map(async (key) => [`dist/${key}`, await read(join(dist, key))] as const))),\n ])\n const chunks = [...entries].flatMap(([path, content]) => {\n const bytes = Buffer.from(content)\n return [header(`package/${path}`, bytes.length), bytes, Buffer.alloc((512 - (bytes.length % 512)) % 512)]\n })\n return gzipSync(Buffer.concat([...chunks, Buffer.alloc(1024)]))\n } finally {\n await rm(root, { recursive: true, force: true })\n }\n}\n\ntype CreateSnapshotOptions = Omit<SnapshotUploadMetadata, 'hashes' | 'peerDependencies'> & {\n studioUrl?: string\n /**\n * Organization CI API key, sent as `x-api-key`.\n */\n apiKey: string\n /**\n * Every entry of the project's Kubb config, generated like `kubb generate`: formatter, linter, and `output.postGenerate` included.\n * One package holds the output of them all.\n */\n configs: Array<Config>\n hooks?: Hookable<KubbHooks>\n signal?: AbortSignal\n}\n\n/**\n * Generates the project, packs it as an npm tarball, and publishes it to Studio in one `POST /api/snapshots` request.\n *\n * @example\n * ```ts\n * const { url } = await createSnapshot({ apiKey: process.env.KUBB_TOKEN!, configs, id: 'gh:123:pr-4', name: 'acme/api#4', packageName: '@acme/api', version: '1.0.0' })\n * ```\n */\nexport async function createSnapshot({\n studioUrl = defaultStudioUrl,\n apiKey,\n configs,\n hooks,\n signal,\n ...metadata\n}: CreateSnapshotOptions): Promise<PublishedSnapshot> {\n const url = secureUrl({ studioUrl, path: '/api/snapshots' })\n const buildConfigs = configs.map((config) => ({ ...config, storage: fsStorage() }))\n const failures: Array<unknown> = []\n // Each package path with the file on disk it comes from.\n const sources = new Map<string, string>()\n // A failing entry does not stop the others, like `kubb generate`, so one run reports every failure.\n for await (const { success, error, diagnostics, files, kubb } of Kubb.generate(buildConfigs, { hooks, signal })) {\n if (!success) {\n failures.push(error ?? generationFailure(diagnostics))\n continue\n }\n const { root } = kubb.config\n for (const file of files) {\n const path = relativeStoragePath({ root, filePath: file.path })\n const source = resolve(root, path)\n const owner = sources.get(path)\n if (owner && owner !== source)\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `Snapshot has two generated files at \"${path}\": \"${owner}\" and \"${source}\"`,\n help: 'Give the config entries the same `root`, or output paths that do not overlap.',\n })\n sources.set(path, source)\n }\n }\n // Nothing is published from a partial generation.\n if (failures.length === 1) throw failures[0]\n if (failures.length) throw new AggregateError(failures, failures.map(getErrorMessage).join('\\n'))\n\n const storage = fsStorage()\n const files = Object.fromEntries(\n await Promise.all(\n [...sources].map(async ([path, source]) => {\n const content = await storage.readItem(source)\n if (content === null)\n throw new Diagnostics.Error({\n code: Diagnostics.code.internalError,\n severity: 'error',\n message: `The generation listed ${path} but did not keep its content`,\n })\n return [path, content] as const\n }),\n ),\n )\n const pluginNames = [...new Set(configs.flatMap((config) => config.plugins.map((plugin) => resolveMeta(plugin).name)))]\n const roots = [...new Set(configs.map((config) => config.root))]\n const installed = (\n await Promise.all(roots.map((root) => readInstalledPackages({ root, packages: pluginNames.map(toPackageName), resolveFrom: ['kubb'] })))\n ).flat()\n // A third-party plugin is found by the manifest its package ships, as `@kubb/plugin-x` only names a built-in.\n const packageOf = (name: string) => installed.find(({ manifest }) => manifest?.kind === 'plugin' && manifest.name === name)?.package ?? toPackageName(name)\n const names = [...new Set(pluginNames.map(packageOf))]\n const peerDependencies = Object.fromEntries(installed.flatMap(({ package: name, version }) => (names.includes(name) && version ? [[name, version]] : [])))\n // The package would declare no version for a plugin that is not installed.\n const missing = names.filter((name) => !(name in peerDependencies) && !BUNDLED_DEPENDENCIES.includes(name))\n if (missing.length)\n throw new Diagnostics.Error({\n code: Diagnostics.code.missingDependency,\n severity: 'error',\n message: `Missing dependencies: ${missing.join(', ')}`,\n help: 'Install the listed plugin packages in the project.',\n })\n\n const bytes = await createSnapshotPackage({ files, packageInfo: { name: metadata.packageName, version: metadata.version, peerDependencies } })\n if (bytes.length > MAX_SNAPSHOT_BYTES) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.unknown,\n severity: 'error',\n message: `The snapshot is ${Math.ceil(bytes.length / 1024 / 1024)} MB, over the ${MAX_SNAPSHOT_BYTES / 1024 / 1024} MB limit`,\n help: 'Generate fewer files, for example with `include` or `exclude` on the plugins.',\n })\n }\n\n const hashes = Object.fromEntries(Object.entries(files).map(([path, content]) => [path, hashOf(content)]))\n const body = new FormData()\n body.set('metadata', JSON.stringify({ ...metadata, hashes, peerDependencies } satisfies SnapshotUploadMetadata))\n body.set('tarball', new Blob([new Uint8Array(bytes)], { type: 'application/gzip' }), 'snapshot.tgz')\n\n const timeout = AbortSignal.timeout(UPLOAD_TIMEOUT_MS)\n // A redirect would forward the CI key and tarball to wherever it points.\n const { ok, status, _data } = await ofetch.raw<{ snapshot?: PublishedSnapshot; message?: string; data?: { upgradeUrl?: string } }>(url.href, {\n method: 'POST',\n headers: { 'x-api-key': apiKey },\n body,\n redirect: 'error',\n signal: signal ? AbortSignal.any([signal, timeout]) : timeout,\n ignoreResponseError: true,\n })\n if (!ok) {\n const upgrade = _data?.data?.upgradeUrl ? ` Upgrade at ${_data.data.upgradeUrl}.` : ''\n throw new Diagnostics.Error({\n code: Diagnostics.code.inputRequestFailed,\n severity: 'error',\n message: `Kubb Studio refused the snapshot (status ${status})${_data?.message ? `: ${_data.message}` : ''}.${upgrade}`,\n help: 'Check the API key and your plan, then try again.',\n })\n }\n if (!_data?.snapshot)\n throw new Diagnostics.Error({\n code: Diagnostics.code.inputRequestFailed,\n severity: 'error',\n message: `Kubb Studio returned no snapshot (status ${status})`,\n help: 'Try again later.',\n })\n return _data.snapshot\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAS,YAAY,EAAE,SAAS,WAAwE;CACtG,OAAO,OAAO,KAAK,GAAG,QAAQ,IAAI,WAAW,MAAM;AACrD;;;;AAKA,SAAgB,mBAA2B;CACzC,OAAO,oBAAoB,SAAS,CAAC,CAAC,WAAW,OAAO;EAAE,QAAQ;EAAO,MAAM;CAAQ,CAAC,CAAC,CAAC,SAAS;AACrG;;;;AAKA,SAAgB,kBAAkB,YAA4B;CAC5D,OAAO,gBAAgB,UAAU,CAAC,CAAC,OAAO,EAAE,QAAQ,MAAM,CAAC,CAAC,CAAC;AAC/D;;;;AAKA,SAAgB,iBAAiB,EAAE,YAAY,SAAS,WAA4F;CAClJ,OAAO,KAAK,MAAM,YAAY;EAAE;EAAS;CAAQ,CAAC,GAAG,UAAU,CAAC,CAAC,SAAS,WAAW;AACvF;;;;AAKA,SAAgB,qBAAqB,EACnC,WACA,SACA,SACA,aAMU;CACV,IAAI;EACF,MAAM,MAAM,gBAAgB;GAAE,KAAK;IAAE,KAAK;IAAO,KAAK;IAAW,GAAG;GAAU;GAAG,QAAQ;EAAM,CAAC;EAChG,OAAO,OAAO,MAAM,YAAY;GAAE;GAAS;EAAQ,CAAC,GAAG,KAAK,OAAO,KAAK,WAAW,WAAW,CAAC;CACjG,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAgB,uBAAuB,EAAE,OAAO,YAAyD;CACvG,OAAO,GAAG,SAAS,IAAI,KAAK,UAAU,KAAK;AAC7C;;;;;;;;;;AC3BA,SAAgB,KAAmB,OAA4B,KAAW,SAA+B;CACvG,MAAM,SAAS,MAAM,IAAI,GAAG;CAC5B,IAAI,WAAW,KAAA,KAAa,MAAM,IAAI,GAAG,GAAG,OAAO;CACnD,MA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