{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../src/core/canvas/resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB,wBAAwB,CAAC;AAyBxD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAU/D","sourcesContent":["/**\n * Module resolution for a forked canvas extension.\n *\n * Design: `docs/canvas-extensions-design.md` §4.1. A canvas extension's only\n * external import is `@github/copilot-sdk/extension`, and GitHub's own\n * `docs/extensions.md` says that import \"is resolved automatically — you don't\n * install it\". So hoocode has to make the specifier resolvable inside the child\n * without writing anything into the extension directory: a catalog canvas must\n * stay byte-identical to upstream (tier 1 of the design's ownership split).\n *\n * The mechanism is a Node module-resolution hook (`node:module`'s `register`)\n * delivered entirely through `--import` **data: URLs**. Nothing is written to\n * disk and no `.mjs` asset has to be copied into `dist/` or embedded in the\n * packaged binary — the whole resolver is two generated modules that exist only\n * as command-line arguments.\n */\n\n/** The specifier a canvas extension imports, and the package it belongs to. */\nexport const CANVAS_SDK_PACKAGE = \"@github/copilot-sdk\";\n\n/**\n * Resolution hooks, as source. `initialize` receives the shim URL through\n * `register`'s `data` channel rather than the environment, because the hooks run\n * on a separate loader thread and the documented `data` path is the supported way\n * to parameterise them.\n */\nconst HOOKS_SOURCE = `\nlet shimUrl;\nexport function initialize(data) {\n\tshimUrl = data.shimUrl;\n}\nexport async function resolve(specifier, context, next) {\n\tif (specifier === ${JSON.stringify(CANVAS_SDK_PACKAGE)} || specifier.startsWith(${JSON.stringify(`${CANVAS_SDK_PACKAGE}/`)})) {\n\t\treturn { url: shimUrl, shortCircuit: true };\n\t}\n\treturn next(specifier, context);\n}\n`;\n\nfunction dataModule(source: string): string {\n\treturn `data:text/javascript,${encodeURIComponent(source)}`;\n}\n\n/**\n * Build the `--import` argument that makes `@github/copilot-sdk` resolve to\n * `shimUrl` inside the child.\n *\n * @param shimUrl Absolute `file:` URL of the module implementing the SDK surface.\n */\nexport function canvasResolverImportArg(shimUrl: string): string {\n\tif (!shimUrl.startsWith(\"file://\")) {\n\t\tthrow new Error(`Canvas shim URL must be an absolute file: URL, received \"${shimUrl}\".`);\n\t}\n\tconst hooksUrl = dataModule(HOOKS_SOURCE);\n\tconst registerSource = `\nimport { register } from \"node:module\";\nregister(${JSON.stringify(hooksUrl)}, { parentURL: import.meta.url, data: ${JSON.stringify({ shimUrl })} });\n`;\n\treturn dataModule(registerSource);\n}\n"]}