{"version":3,"file":"package-plugin.d.ts","sourceRoot":"","sources":["../../../src/core/tools/package-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAyBzE,wBAAgB,iCAAiC,IAAI,cAAc,CAyDlE","sourcesContent":["/**\n * PackagePlugin — the autonomous half of the publish lane (spec §3.2).\n *\n * Everything before the button: run the eval gates at publish strictness, write\n * a README if the plugin has none, produce the marketplace index entry, and hand\n * back the instructions for the step the model must not take. The tool touches no\n * remote and cannot publish; `/plugin publish` (a human command) is where the\n * artifact actually leaves the machine.\n *\n * It is autonomous because none of it is irreversible — it writes two files into\n * a directory the plugin already owns — and because the value of the lane is that\n * the human's remaining decision is *just* the approval, with the mechanics\n * already done and the checks already run. It is in\n * {@link PLUGIN_SYSTEM_TOOL_NAMES} all the same: an authored subagent that could\n * package is one step from a subagent that could publish.\n */\n\nimport { type Static, Type } from \"typebox\";\nimport { getPlugin } from \"../extensions/plugins/authoring.js\";\nimport { normalizePlatformToken } from \"../extensions/plugins/formats/platform-targets.js\";\nimport { entryNeedsSource, packagePlugin, resolvePackagePlatform } from \"../extensions/plugins/packaging.js\";\nimport { defineTool, type ToolDefinition } from \"../extensions/types.js\";\nimport { PACKAGE_PLUGIN_TOOL_NAME } from \"./plugin-tool-names.js\";\n\nconst packageParams = Type.Object(\n\t{\n\t\tid: Type.String({ description: \"Id of the installed or authored plugin to package.\" }),\n\t\tplatform: Type.Optional(\n\t\t\tType.Union([Type.Literal(\"claude\"), Type.Literal(\"github\")], {\n\t\t\t\tdescription:\n\t\t\t\t\t\"Target ecosystem. Omit to use the plugin's own — where it lives decides, then what it declares. \" +\n\t\t\t\t\t\"`agents` is not a choice here: it belongs to no marketplace, so nothing can be published for it.\",\n\t\t\t}),\n\t\t),\n\t},\n\t{ additionalProperties: false },\n);\n\ninterface PackagePluginDetails {\n\tid: string;\n\tpackaged: boolean;\n\t/** Whether the gates were green — i.e. whether the plugin may be published at all. */\n\tready: boolean;\n\tplatform?: string;\n}\n\nexport function createPackagePluginToolDefinition(): ToolDefinition {\n\treturn defineTool<typeof packageParams, PackagePluginDetails>({\n\t\tname: PACKAGE_PLUGIN_TOOL_NAME,\n\t\tlabel: PACKAGE_PLUGIN_TOOL_NAME,\n\t\tdescription:\n\t\t\t\"Prepare a local plugin for publication: run its checks at publish strictness (structural, safety, and a \" +\n\t\t\t\"behavioral smoke run of any hooks/MCP servers), generate a README if it has none, and produce the \" +\n\t\t\t\"marketplace.json entry. Writes only inside the plugin's own directory and contacts no remote — it cannot \" +\n\t\t\t\"publish. Use it to find out whether a plugin is publishable and to hand the user a ready-to-submit bundle; \" +\n\t\t\t\"they run /plugin publish to do the actual submission.\",\n\t\tpromptSnippet: \"Package a plugin for publication (gates + README + index entry; never publishes).\",\n\t\tpromptGuidelines: [\n\t\t\t\"Packaging is safe and autonomous — it only writes into the plugin's own directory. Publishing is not: never open a PR, push, or submit a plugin to a marketplace yourself, even when asked to 'just publish it'. Package it, show the result, and point at /plugin publish.\",\n\t\t\t\"Its checks are stricter than authoring's, so a plugin that authored fine can still fail here. Report what failed and offer to fix it rather than presenting a red result as done.\",\n\t\t],\n\t\tparameters: packageParams,\n\t\tasync execute(_id, params: Static<typeof packageParams>, _signal, _onUpdate, ctx) {\n\t\t\tconst fail = (text: string) => ({\n\t\t\t\tcontent: [{ type: \"text\" as const, text }],\n\t\t\t\tdetails: { id: params.id, packaged: false, ready: false },\n\t\t\t});\n\n\t\t\tconst plugin = getPlugin(ctx.cwd, params.id);\n\t\t\tif (!plugin) return fail(`No plugin named \"${params.id}\" is installed or authored here.`);\n\n\t\t\t// The schema already excludes `agents`, so this only folds the aliases\n\t\t\t// (`copilot`, `gh`) a model might reasonably reach for.\n\t\t\tconst requested = params.platform ? normalizePlatformToken(params.platform) : undefined;\n\t\t\tconst platform = requested === \"claude\" || requested === \"github\" ? requested : resolvePackagePlatform(plugin);\n\n\t\t\tconst result = await packagePlugin(plugin, platform);\n\t\t\tconst text = [\n\t\t\t\t`Packaged \"${params.id}\" for ${result.platform} in ${result.dir}`,\n\t\t\t\t`Wrote: ${result.written.join(\", \")}`,\n\t\t\t\t\"\",\n\t\t\t\tresult.instructions,\n\t\t\t].join(\"\\n\");\n\t\t\tctx.ui.notify(\n\t\t\t\tresult.ok\n\t\t\t\t\t? `Packaged \"${params.id}\" for ${result.platform} — ready to publish with /plugin publish ${params.id}.`\n\t\t\t\t\t: `Packaged \"${params.id}\" for ${result.platform}, but its checks failed — not publishable yet.`,\n\t\t\t\tresult.ok ? \"info\" : \"warning\",\n\t\t\t);\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\" as const,\n\t\t\t\t\t\ttext:\n\t\t\t\t\t\t\tresult.ok && entryNeedsSource(result.entry)\n\t\t\t\t\t\t\t\t? `${text}\\n\\nThe entry's \\`source\\` is a placeholder — the user must say where the plugin will be hosted.`\n\t\t\t\t\t\t\t\t: text,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: { id: params.id, packaged: true, ready: result.ok, platform: result.platform },\n\t\t\t};\n\t\t},\n\t});\n}\n"]}