github-router 0.3.379 → 0.3.380
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -0
- package/dist/ado-tools-CsfbnY8x.js +1 -0
- package/dist/{aic-ledger-CeSXqTEE.js → aic-ledger-6GKI28nY.js} +3 -3
- package/dist/{aic-ledger-CeSXqTEE.js.map → aic-ledger-6GKI28nY.js.map} +1 -1
- package/dist/{aic-statusline-settings-BKveu679.js → aic-statusline-settings-wLL1l_Z6.js} +2 -2
- package/dist/{aic-statusline-settings-BKveu679.js.map → aic-statusline-settings-wLL1l_Z6.js.map} +1 -1
- package/dist/atomic-file-Dif1kLKM.js +198 -0
- package/dist/atomic-file-Dif1kLKM.js.map +1 -0
- package/dist/{attribution-settings-BWYL2b8N.js → attribution-settings-BJ1fjX7V.js} +10 -10
- package/dist/{attribution-settings-BWYL2b8N.js.map → attribution-settings-BJ1fjX7V.js.map} +1 -1
- package/dist/{auth-BZHpTtfF.js → auth-5TKcQbbH.js} +3 -3
- package/dist/{auth-BZHpTtfF.js.map → auth-5TKcQbbH.js.map} +1 -1
- package/dist/bin.js +1479 -0
- package/dist/bin.js.map +1 -0
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/{check-usage-BlIWDuV2.js → check-usage-DM39fdel.js} +4 -4
- package/dist/{check-usage-BlIWDuV2.js.map → check-usage-DM39fdel.js.map} +1 -1
- package/dist/{claude-CSuIdaLV.js → claude-BWwkOMi3.js} +26 -25
- package/dist/{claude-CSuIdaLV.js.map → claude-BWwkOMi3.js.map} +1 -1
- package/dist/{claude-md-injection-Biq_Xhve.js → claude-md-injection-DNMDcw1W.js} +15 -24
- package/dist/claude-md-injection-DNMDcw1W.js.map +1 -0
- package/dist/{codex-BG0pfud9.js → codex-C6ix3BaY.js} +8 -7
- package/dist/{codex-BG0pfud9.js.map → codex-C6ix3BaY.js.map} +1 -1
- package/dist/{copilot-discount-UXC6NQbN.js → copilot-discount-DM98PuAF.js} +2 -2
- package/dist/{copilot-discount-UXC6NQbN.js.map → copilot-discount-DM98PuAF.js.map} +1 -1
- package/dist/{debug-1HUHCWFl.js → debug-Df0Kuzi3.js} +2 -2
- package/dist/{debug-1HUHCWFl.js.map → debug-Df0Kuzi3.js.map} +1 -1
- package/dist/diagnostics-cXjCT_JQ.js +12 -0
- package/dist/diagnostics-cXjCT_JQ.js.map +1 -0
- package/dist/engine-B6la_uIW.js +1 -0
- package/dist/{gate-discovery-DjH9YXoN.js → gate-discovery-2ILpM2fi.js} +5 -5
- package/dist/{gate-discovery-DjH9YXoN.js.map → gate-discovery-2ILpM2fi.js.map} +1 -1
- package/dist/{get-copilot-usage-CKg42gSH.js → get-copilot-usage-BZ6t2hFZ.js} +2 -2
- package/dist/{get-copilot-usage-CKg42gSH.js.map → get-copilot-usage-BZ6t2hFZ.js.map} +1 -1
- package/dist/hooks.mjs +13 -0
- package/dist/hooks.sha256 +1 -1
- package/dist/{index-cmd-sKwchRJz.js → index-cmd-DsK6VFs8.js} +4 -4
- package/dist/{index-cmd-sKwchRJz.js.map → index-cmd-DsK6VFs8.js.map} +1 -1
- package/dist/{internal-aic-status-B_hEeM37.js → internal-aic-status-CUZ7-trf.js} +3 -3
- package/dist/{internal-aic-status-B_hEeM37.js.map → internal-aic-status-CUZ7-trf.js.map} +1 -1
- package/dist/{internal-artifact-open-DbHjipxU.js → internal-artifact-open-DRBg1PpV.js} +2 -2
- package/dist/{internal-artifact-open-DbHjipxU.js.map → internal-artifact-open-DRBg1PpV.js.map} +1 -1
- package/dist/{internal-fast-dispatch-guard-DMzqs-r8.js → internal-fast-dispatch-guard-D6-Ees_6.js} +1 -1
- package/dist/{internal-fast-dispatch-guard-PDdlkPU3.js → internal-fast-dispatch-guard-ZeS9u0A3.js} +2 -2
- package/dist/{internal-fast-dispatch-guard-PDdlkPU3.js.map → internal-fast-dispatch-guard-ZeS9u0A3.js.map} +1 -1
- package/dist/{internal-first-mate-guard-BxPDUsV3.js → internal-first-mate-guard-BijeVpi9.js} +1 -1
- package/dist/{internal-first-mate-guard-4Yro9xNM.js → internal-first-mate-guard-DsEEsLKJ.js} +3 -3
- package/dist/{internal-first-mate-guard-4Yro9xNM.js.map → internal-first-mate-guard-DsEEsLKJ.js.map} +1 -1
- package/dist/{internal-max-dispatch-guard-0teaxIc1.js → internal-max-dispatch-guard-4RLca1i5.js} +2 -2
- package/dist/{internal-max-dispatch-guard-0teaxIc1.js.map → internal-max-dispatch-guard-4RLca1i5.js.map} +1 -1
- package/dist/{internal-max-dispatch-guard-5LSaHN_y.js → internal-max-dispatch-guard-DeEfWqfP.js} +1 -1
- package/dist/{internal-plan-review-BfHLeszV.js → internal-plan-review-bzqGNdtw.js} +3 -3
- package/dist/{internal-plan-review-BfHLeszV.js.map → internal-plan-review-bzqGNdtw.js.map} +1 -1
- package/dist/{internal-prompt-submit-BixNLmM3.js → internal-prompt-submit-BZ2-CExM.js} +4 -4
- package/dist/{internal-prompt-submit-BixNLmM3.js.map → internal-prompt-submit-BZ2-CExM.js.map} +1 -1
- package/dist/{internal-prompt-submit-Ou8xtRXj.js → internal-prompt-submit-ZBhH-SQ1.js} +2 -2
- package/dist/{internal-rebrief-BBGM0PMv.js → internal-rebrief-BIWbN7Sr.js} +4 -4
- package/dist/{internal-rebrief-BBGM0PMv.js.map → internal-rebrief-BIWbN7Sr.js.map} +1 -1
- package/dist/{internal-session-bind-pN1V11Mn.js → internal-session-bind-BL6hFRLO.js} +2 -2
- package/dist/{internal-session-bind-pN1V11Mn.js.map → internal-session-bind-BL6hFRLO.js.map} +1 -1
- package/dist/{internal-stop-hook-DO9Iiaes.js → internal-stop-hook-cDF1MuJZ.js} +5 -5
- package/dist/{internal-stop-hook-DO9Iiaes.js.map → internal-stop-hook-cDF1MuJZ.js.map} +1 -1
- package/dist/{internal-stop-review-BWp-4XWW.js → internal-stop-review-y8zjpK_3.js} +2 -2
- package/dist/{internal-stop-review-BWp-4XWW.js.map → internal-stop-review-y8zjpK_3.js.map} +1 -1
- package/dist/{internal-worker-guard-C9OZPgzu.js → internal-worker-guard-DdyYBZR0.js} +2 -2
- package/dist/{internal-worker-guard-C9OZPgzu.js.map → internal-worker-guard-DdyYBZR0.js.map} +1 -1
- package/dist/{internal-workspace-header-B4TXFBLU.js → internal-workspace-header-BMKbO8yX.js} +2 -2
- package/dist/{internal-workspace-header-B4TXFBLU.js.map → internal-workspace-header-BMKbO8yX.js.map} +1 -1
- package/dist/lib/tree-sitter-pool/worker.js +268 -21
- package/dist/lifecycle-BOjgq9_l.js +1 -0
- package/dist/{lifecycle-vjHAFCaY.js → lifecycle-BlC_kzNt.js} +2 -2
- package/dist/{lifecycle-vjHAFCaY.js.map → lifecycle-BlC_kzNt.js.map} +1 -1
- package/dist/{lifecycle-Dh9y8OF1.js → lifecycle-COZhARmE.js} +2 -2
- package/dist/{lifecycle-Dh9y8OF1.js.map → lifecycle-COZhARmE.js.map} +1 -1
- package/dist/lifecycle-NQvr4flt.js +1 -0
- package/dist/main.js +39 -24
- package/dist/main.js.map +1 -1
- package/dist/{mcp-workspace-header-C5-dOWNa.js → mcp-workspace-header-Bpa4BId8.js} +2 -2
- package/dist/{mcp-workspace-header-C5-dOWNa.js.map → mcp-workspace-header-Bpa4BId8.js.map} +1 -1
- package/dist/{models-B6nH1sS6.js → models-BDV-YLf2.js} +3 -3
- package/dist/{models-B6nH1sS6.js.map → models-BDV-YLf2.js.map} +1 -1
- package/dist/npm-env-H60tX76c.js +130 -0
- package/dist/npm-env-H60tX76c.js.map +1 -0
- package/dist/optional-DGAeyguL.js +586 -0
- package/dist/optional-DGAeyguL.js.map +1 -0
- package/dist/{orchestration-B93jxrWI.js → orchestration-Bto5Nc1Y.js} +2 -2
- package/dist/{orchestration-B93jxrWI.js.map → orchestration-Bto5Nc1Y.js.map} +1 -1
- package/dist/origin-BXtpcKP9.js +382 -0
- package/dist/origin-BXtpcKP9.js.map +1 -0
- package/dist/origin-DbFUCiGp.js +1 -0
- package/dist/paths-CquOjytP.js +1 -0
- package/dist/paths-DK_b2ihK.js +176 -0
- package/dist/paths-DK_b2ihK.js.map +1 -0
- package/dist/{paths-CVEO8jEH.js → paths-DeFmYJhO.js} +16 -3
- package/dist/paths-DeFmYJhO.js.map +1 -0
- package/dist/{peer-mcp-personas-OWsSm6To.js → peer-mcp-personas-Dny0r5Am.js} +14 -14
- package/dist/{peer-mcp-personas-OWsSm6To.js.map → peer-mcp-personas-Dny0r5Am.js.map} +1 -1
- package/dist/{pi-DmeBxzIo.js → pi-YhoA26wi.js} +383 -88
- package/dist/pi-YhoA26wi.js.map +1 -0
- package/dist/{pi-foreign-artifacts-DZ4tioyO.js → pi-foreign-artifacts-CNt6wQ1P.js} +2 -2
- package/dist/{pi-foreign-artifacts-DZ4tioyO.js.map → pi-foreign-artifacts-CNt6wQ1P.js.map} +1 -1
- package/dist/pi-memory-bridge-BxmCIIbk.js +618 -0
- package/dist/pi-memory-bridge-BxmCIIbk.js.map +1 -0
- package/dist/pi-memory-bridge-D5A0h_Kf.js +1 -0
- package/dist/pi-version-check-BeBB0Ny9.js +551 -0
- package/dist/pi-version-check-BeBB0Ny9.js.map +1 -0
- package/dist/pi-version-check-D5RvdLsG.js +1 -0
- package/dist/{plan-review-hook-MhjK92wq.js → plan-review-hook-D_yyjOgO.js} +3 -3
- package/dist/{plan-review-hook-MhjK92wq.js.map → plan-review-hook-D_yyjOgO.js.map} +1 -1
- package/dist/{provision-DPL8aGe2.js → provision-BWtuDq_v.js} +30 -36
- package/dist/provision-BWtuDq_v.js.map +1 -0
- package/dist/rerank-cross-encoder-BhjImuwG.js +192 -0
- package/dist/rerank-cross-encoder-BhjImuwG.js.map +1 -0
- package/dist/{self-invocation-DMUnXVGT.js → self-invocation-Dnq4iVD6.js} +4 -31
- package/dist/{self-invocation-DMUnXVGT.js.map → self-invocation-Dnq4iVD6.js.map} +1 -1
- package/dist/{serve-zbQKfx1E.js → serve-DrHAX2Bh.js} +15 -14
- package/dist/{serve-zbQKfx1E.js.map → serve-DrHAX2Bh.js.map} +1 -1
- package/dist/{server-setup-ClZdV33Q.js → server-setup-DLwejgVA.js} +12 -638
- package/dist/server-setup-DLwejgVA.js.map +1 -0
- package/dist/{service-backend-Cdgz6WPx.js → service-backend-BdhWVRSz.js} +17 -62
- package/dist/service-backend-BdhWVRSz.js.map +1 -0
- package/dist/{start-mnedD5cH.js → start-DvV3Lbwy.js} +5 -4
- package/dist/{start-mnedD5cH.js.map → start-DvV3Lbwy.js.map} +1 -1
- package/dist/{static-context-pack-CtnBwHSd.js → static-context-pack-BKFelEbM.js} +3 -3
- package/dist/{static-context-pack-CtnBwHSd.js.map → static-context-pack-BKFelEbM.js.map} +1 -1
- package/dist/{stop-gate-hook-CBVLD8iB.js → stop-gate-hook-DBOj0TqL.js} +3 -3
- package/dist/{stop-gate-hook-CBVLD8iB.js.map → stop-gate-hook-DBOj0TqL.js.map} +1 -1
- package/dist/{stop-gate-policy-BehNiNix.js → stop-gate-policy-Bp2wGh_W.js} +2 -2
- package/dist/{stop-gate-policy-BehNiNix.js.map → stop-gate-policy-Bp2wGh_W.js.map} +1 -1
- package/dist/{token-CPzYxU4Y.js → token-CKPOBdO0.js} +23 -88
- package/dist/{token-CPzYxU4Y.js.map → token-CKPOBdO0.js.map} +1 -1
- package/dist/{token-DHEkiO4g.js → token-Ygd7D32L.js} +3 -3
- package/dist/{token-DHEkiO4g.js.map → token-Ygd7D32L.js.map} +1 -1
- package/dist/update-CB21YRKz.js +1 -0
- package/dist/update-T1L7yFon.js +1548 -0
- package/dist/update-T1L7yFon.js.map +1 -0
- package/dist/update-fEgWTrIx.js +214 -0
- package/dist/update-fEgWTrIx.js.map +1 -0
- package/dist/update-lock-BeS_WmC8.js +1 -0
- package/dist/update-lock-BmXx6QaR.js +171 -0
- package/dist/update-lock-BmXx6QaR.js.map +1 -0
- package/dist/volatile-root-DQNNvQ7Z.js +50 -0
- package/dist/volatile-root-DQNNvQ7Z.js.map +1 -0
- package/dist/{worker-dispatch-C7RtNOXv.js → worker-dispatch-DBWKTMda.js} +2 -2
- package/dist/{worker-dispatch-C7RtNOXv.js.map → worker-dispatch-DBWKTMda.js.map} +1 -1
- package/dist/{workiq-CQauEAMc.js → workiq-D5b7xlbr.js} +2 -2
- package/dist/{workiq-CQauEAMc.js.map → workiq-D5b7xlbr.js.map} +1 -1
- package/dist/{workiq-tools-DL6rC4bP.js → workiq-tools-DdiQ2DOW.js} +1 -1
- package/package.json +16 -4
- package/dist/ado-tools-CRkyU51J.js +0 -1
- package/dist/claude-md-injection-Biq_Xhve.js.map +0 -1
- package/dist/engine-V46un8Xl.js +0 -1
- package/dist/lifecycle-BENRuuX6.js +0 -1
- package/dist/lifecycle-Dli9vGI2.js +0 -1
- package/dist/paths-Be9_ujQ3.js +0 -1
- package/dist/paths-CVEO8jEH.js.map +0 -1
- package/dist/pi-DmeBxzIo.js.map +0 -1
- package/dist/pi-memory-bridge-Bp9AnYw9.js +0 -1
- package/dist/pi-memory-bridge-CICIdDVP.js +0 -413
- package/dist/pi-memory-bridge-CICIdDVP.js.map +0 -1
- package/dist/provision-DPL8aGe2.js.map +0 -1
- package/dist/rerank-cross-encoder-B87lZgvc.js +0 -110
- package/dist/rerank-cross-encoder-B87lZgvc.js.map +0 -1
- package/dist/server-setup-ClZdV33Q.js.map +0 -1
- package/dist/service-backend-Cdgz6WPx.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as redactSecrets, f as splitFrontmatter, o as capBytes } from "./pi-memory-bridge-BxmCIIbk.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import os from "node:os";
|
|
@@ -657,4 +657,4 @@ function piForeignHomeDir() {
|
|
|
657
657
|
}
|
|
658
658
|
export { buildForeignAgentIndex, buildReservedNames, countForeignAgentFiles, piForeignHomeDir, piForeignRepoRoot, planForeignArtifacts, writeForeignArtifacts };
|
|
659
659
|
|
|
660
|
-
//# sourceMappingURL=pi-foreign-artifacts-
|
|
660
|
+
//# sourceMappingURL=pi-foreign-artifacts-CNt6wQ1P.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-foreign-artifacts-DZ4tioyO.js","names":[],"sources":["../src/lib/pi-foreign-artifacts.ts"],"sourcesContent":["/**\n * Bridge the INHERITED artifact directories — Claude Code's `.claude/` /\n * `~/.claude/` and Copilot's `.github/` / `~/.copilot/` — into a\n * `github-router pi` launch.\n *\n * Three namespaces, three different failure modes, one rule set:\n *\n * | namespace | same-name outcome in Pi | reported? |\n * |-----------------|-----------------------------------------------|-----------|\n * | agent registry | `mergeRuntimeAgents` throws, EVERY `subagent` | yes |\n * | | call in the process fails until it is removed | |\n * | `skills/*` | the other `SKILL.md` is overwritten in place | **no** |\n * | `prompts/*.md` | the other file is overwritten in place | **no** |\n *\n * So the planner reserves names BEFORE anything is written, and the rule\n * differs by namespace on purpose:\n *\n * - **agents**: a name the router itself already ships (its roster, the\n * pi-subagents builtins, the read-only CLI adapters) means the role\n * already exists — the foreign definition is **skipped and reported**.\n * Two agents with one purpose in one catalog is the ambiguity that\n * produces wrong delegations, and a registry identity is not the only\n * carrier of the content (the skill and prompt are).\n * - **skills and prompts**: the file IS the only carrier, so they are\n * **renamed, never skipped** — `gh-oracle` → `gh-oracle-2`,\n * `review.md` → `review-2.md`.\n *\n * Renaming happens for anything else that is taken, deterministically:\n * agents become `<slug>-<scope>` (then `-2`, `-3`…), skills and prompts\n * become `<slug>-2` (then `-3`…). No source prefix — a prefix is not a\n * namespace (it walks straight into the builtin `claude-code` /\n * `claude-code-writer`) and it renames artifacts the user recognises for no\n * safety gain, since the reservation is what makes collisions unreachable.\n *\n * Foreign `model:` and `aliases:` are never emitted. The model would be a\n * Copilot slug that `isUnavailableSubagentModel` refuses (so every run of\n * that agent fails), and an alias is another registry identity that can\n * collide invisibly. Every bridged agent therefore runs on the launch's\n * lead model. `tools:` is dropped from the frontmatter and folded into the\n * body as prose, because an unresolvable entry in pi-subagents' strict\n * allowlist hard-fails the child.\n *\n * Nothing here imports pi-subagents or Pi: the router owns one rule and\n * reads the same frontmatter the loaders read, so a version bump upstream\n * cannot silently move a name out from under it.\n */\n\nimport fs from \"node:fs/promises\"\nimport os from \"node:os\"\nimport path from \"node:path\"\n\nimport { capBytes, redactSecrets, splitFrontmatter } from \"./pi-memory-bridge\"\n\n/**\n * Every name pi-subagents reserves for itself — `BUILTIN_AGENT_NAMES` from\n * the installed package plus the live alias map, the read-only CLI adapters,\n * and the router's own roster.\n *\n * Cannot be imported: pi-subagents is an installed Pi extension, never a\n * router dependency (bundling its internals would couple the launcher to a\n * version it does not pin). LAST_VERIFIED against pi-subagents 0.88.0:\n * `src/agents/builtin-names.js` for the 13 names, and a live `snapshot.all`\n * for the aliases (`oracle → advisor`,\n * `worker → developer, coder, implementer, develop`; every other builtin\n * carries none).\n *\n * Drift here is not a correctness hole: the extension's `tool_result` net\n * unregisters anything the registry rejects at merge time. It is a\n * friendliness hole (a foreign agent skipped needlessly), which is why this\n * list is commented rather than guessed.\n */\nexport const PI_FOREIGN_ROUTER_OWNED_AGENTS: ReadonlyArray<string> = Object.freeze([\n // pi-subagents builtins (BUILTIN_AGENT_NAMES, 0.88.0).\n \"advisor\",\n \"claude-code\",\n \"claude-code-writer\",\n \"codex-exec\",\n \"codex-exec-writer\",\n \"cursor-agent\",\n \"cursor-agent-writer\",\n \"delegate\",\n \"evidence-auditor\",\n \"oracle\",\n \"researcher\",\n \"reviewer\",\n \"scout\",\n \"worker\",\n // Live aliases of those builtins (`oracle`, `worker` above).\n \"developer\",\n \"coder\",\n \"implementer\",\n \"develop\",\n])\n\n/**\n * The router's own agent roster is NOT in the constant above: it depends on\n * the launch (`buildPiAgentFiles` writes Explore / General-Purpose / reviewer /\n * oracle / advisor, and `--no-peers` writes none), so `buildReservedNames`\n * takes it as `emittedAgents` instead. A hardcoded copy here would skip a\n * foreign `Explore` on a peerless launch that publishes no such role.\n */\n\n/** Foreign artifact roots. Project + user, Claude + Copilot. */\nconst SKILL_ROOTS_PROJECT = [\".claude/skills\", \".github/skills\"] as const\nconst SKILL_ROOTS_USER = [\".claude/skills\", \".copilot/skills\"] as const\nconst AGENT_ROOTS_PROJECT = [\".claude/agents\", \".github/agents\"] as const\nconst AGENT_ROOTS_USER = [\".claude/agents\", \".copilot/agents\"] as const\nconst PROMPT_ROOTS_PROJECT = [\".claude/commands\", \".github/prompts\"] as const\nconst PROMPT_ROOTS_USER = [\".claude/commands\"] as const\n\n/** Pi's own artifact roots in the mirror / repo / home, for reservation. */\nconst PI_SKILL_ROOTS_REL = [\"skills\", \".pi/skills\", \".agents/skills\"] as const\nconst PI_PROMPT_ROOTS_REL = [\"prompts\", \".pi/prompts\"] as const\nconst PI_AGENT_ROOTS_REL = [\"agents\", \".pi/agents\", \".agents\"] as const\n\n/** Caps. Pi refuses a skill without a description (`core/skills.js:252`). */\nconst MAX_FOREIGN_AGENT_BODY_BYTES = 8 * 1024\nconst MAX_FOREIGN_DESCRIPTION_CHARS = 200\nconst MAX_FOREIGN_SKILL_DESCRIPTION_CHARS = 1_000\nconst MAX_FOREIGN_INDEX_BYTES = 4 * 1024\n/** Mirrors Pi's own limits so a bridged file can never be rejected. */\nconst MAX_SKILL_NAME_CHARS = 64\n\nexport interface PiForeignAgentSpec {\n /** Final, collision-free, slugged (the authored name unless it was taken). */\n name: string\n /** The name as authored in the source file, before any suffix. */\n originalName: string\n /** One line, whitespace-collapsed, ≤ 200 chars. */\n description: string\n /** Frontmatter stripped, provenance line, tool policy as prose, ≤ 8 KiB. */\n body: string\n source: \"claude\" | \"copilot\"\n scope: \"project\" | \"user\"\n /** Repo- or home-relative provenance, shown in the index. */\n file: string\n /** Set when the name had to change (`gh-oracle` → `gh-oracle-2`). */\n renamedFrom?: string\n}\n\nexport interface PiForeignArtifactDoc {\n /** Final name: skill directory, or prompt file stem. */\n name: string\n content: string\n renamedFrom?: string\n}\n\nexport interface PiForeignPlan {\n /** Written to `<mirror>/skills/<name>/SKILL.md`. */\n skills: Array<PiForeignArtifactDoc>\n /** Written to `<mirror>/prompts/<name>.md`. */\n prompts: Array<PiForeignArtifactDoc>\n /**\n * Registered through the pi-subagents runtime-agent event. NO files are\n * written for these: one registry entry, announced in the prompt index,\n * loaded on demand via `subagent({action:\"list\"})`.\n */\n agents: Array<PiForeignAgentSpec>\n /** Everything dropped rather than bridged, with the reason. Never silent. */\n skipped: Array<{ name: string; file: string; reason: string }>\n}\n\nexport interface PiReservedNames {\n /** Builtins + aliases + adapters + this launch's roster. Never renamed to. */\n routerOwnedAgents: Set<string>\n /** Every agent identity key on disk (name, aliases, localName). */\n agents: Set<string>\n /** Skill names and directory slugs on disk, plus this launch's own. */\n skills: Set<string>\n /** Prompt stems on disk, plus this launch's own. */\n prompts: Set<string>\n}\n\nfunction lower(s: string): string {\n return s.trim().toLowerCase()\n}\n\n/** Collapse to a legal Pi/prompt path segment and registry name. */\nexport function piForeignSlug(raw: string): string {\n const slug = String(raw ?? \"\")\n .toLowerCase()\n // Any run of illegal characters is one separator, so `Copilot Deploy!`\n // and `--spaced Name--` both land on a legal, readable segment.\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n const trimmed = slug.length > MAX_SKILL_NAME_CHARS ? slug.slice(0, MAX_SKILL_NAME_CHARS).replace(/-+$/, \"\") : slug\n // An all-symbols name slugs to nothing; it still needs a usable identity.\n return trimmed.length > 0 ? trimmed : \"foreign\"\n}\n\nfunction collapseLine(raw: string): string {\n return raw.replace(/\\s+/g, \" \").trim()\n}\n\nfunction truncateChars(raw: string, max: number): string {\n if (raw.length <= max) return raw\n return `${raw.slice(0, Math.max(0, max - 1)).trimEnd()}…`\n}\n\n/** YAML-ish frontmatter read: `key: value` on one line, quotes stripped. */\nfunction frontmatterValue(frontmatter: string, key: string): string | undefined {\n const re = new RegExp(`^${key}\\\\s*:\\\\s*(.*)$`, \"im\")\n const match = re.exec(frontmatter)\n if (!match) return undefined\n const value = match[1].trim().replace(/^[\"']/, \"\").replace(/[\"']$/, \"\").trim()\n return value.length > 0 ? value : undefined\n}\n\n/** Space- and comma-separated list value (`tools: read, grep, bash`). */\nfunction frontmatterList(frontmatter: string, key: string): Array<string> {\n const raw = frontmatterValue(frontmatter, key)\n if (!raw) return []\n return raw\n .replace(/^\\[/, \"\")\n .replace(/\\]$/, \"\")\n .split(/[,\\s]+/)\n .map((s) => s.trim())\n .filter((s) => s.length > 0)\n}\n\nasync function readIfExists(file: string): Promise<string | undefined> {\n try {\n return await fs.readFile(file, \"utf8\")\n } catch {\n return undefined\n }\n}\n\nasync function isDirectory(dir: string): Promise<boolean> {\n try {\n return (await fs.stat(dir)).isDirectory()\n } catch {\n return false\n }\n}\n\nasync function listDir(dir: string): Promise<Array<string>> {\n try {\n return (await fs.readdir(dir)).sort()\n } catch {\n return []\n }\n}\n\n/** Repo root: walk up for `.git`, else the given cwd. Never throws. */\nexport async function piForeignRepoRoot(cwd: string): Promise<string> {\n let dir = path.resolve(cwd)\n for (let depth = 0; depth < 12; depth++) {\n try {\n await fs.stat(path.join(dir, \".git\"))\n return dir\n } catch {\n const parent = path.dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n }\n return cwd\n}\n\n/**\n * Which product an artifact came from, from its path alone.\n *\n * Normalized to forward slashes first: the roots above are POSIX literals, so\n * a Windows path (`\\.github\\.`) would otherwise match nothing and every\n * artifact would be labelled Claude. The label reaches the index and the\n * provenance line, i.e. the model's view of where an agent came from.\n */\nexport function piForeignSourceOf(file: string): \"claude\" | \"copilot\" {\n const posix = file.replace(/\\\\/g, \"/\")\n return posix.includes(\"/.github/\") || posix.includes(\"/.copilot/\") ? \"copilot\" : \"claude\"\n}\n\nfunction provenancePath(file: string, repoRoot: string, homeDir: string): string {\n const rel = (base: string, prefix: string): string | undefined => {\n const out = path.relative(base, file)\n return out.length > 0 && !out.startsWith(\"..\") ? `${prefix}${out.split(path.sep).join(\"/\")}` : undefined\n }\n // `~` for home on purpose: the index and the provenance line are read by a\n // human in a transcript, and an absolute path would leak the account name\n // into every bridged artifact.\n return rel(repoRoot, \"\") ?? rel(homeDir, \"~/\") ?? path.basename(file)\n}\n\n/* ------------------------------------------------------------------ */\n/* Reservation */\n/* ------------------------------------------------------------------ */\n\n/** Every `<dir>/*.md` under an agent root (flat — that is all Pi scans). */\nasync function agentIdentityKeys(root: string): Promise<Array<string>> {\n const keys: Array<string> = []\n for (const name of await listDir(root)) {\n if (!name.endsWith(\".md\")) continue\n // `.agent.md` (Copilot) and `*.md` (Claude) both reduce to the stem.\n const stem = name.replace(/\\.agent\\.md$/, \"\").replace(/\\.md$/, \"\")\n const raw = await readIfExists(path.join(root, name))\n if (raw === undefined) continue\n const { frontmatter } = splitFrontmatter(raw)\n const authored = frontmatterValue(frontmatter, \"name\") ?? stem\n keys.push(authored, stem)\n for (const key of [\"aliases\", \"alias\", \"localName\"]) {\n keys.push(...frontmatterList(frontmatter, key))\n }\n }\n return keys\n}\n\nasync function skillNamesUnder(root: string): Promise<Array<string>> {\n const names: Array<string> = []\n for (const entry of await listDir(root)) {\n if (entry.startsWith(\".\")) continue\n const dir = path.join(root, entry)\n if (await isDirectory(dir)) {\n // Directory-based skill: Pi names it from frontmatter, else the dir.\n names.push(entry)\n const raw = await readIfExists(path.join(dir, \"SKILL.md\"))\n if (raw !== undefined) {\n const named = frontmatterValue(splitFrontmatter(raw).frontmatter, \"name\")\n if (named) names.push(named)\n }\n continue\n }\n if (entry.endsWith(\".md\")) {\n // Single-file skill: the stem is the name.\n const stem = entry.replace(/\\.md$/, \"\")\n names.push(stem)\n const raw = await readIfExists(path.join(root, entry))\n if (raw !== undefined) {\n const named = frontmatterValue(splitFrontmatter(raw).frontmatter, \"name\")\n if (named) names.push(named)\n }\n }\n }\n return names\n}\n\nasync function promptNamesUnder(root: string): Promise<Array<string>> {\n const names: Array<string> = []\n for (const entry of await listDir(root)) {\n const full = path.join(root, entry)\n if (await isDirectory(full)) {\n names.push(...(await promptNamesUnder(full)))\n continue\n }\n if (entry.endsWith(\".md\")) names.push(entry.replace(/\\.md$/, \"\"))\n }\n return names\n}\n\n/**\n * Build the four reservation sets.\n *\n * `emittedSkills` / `emittedPrompts` are the names THIS launch is about to\n * write, so a foreign artifact can never land on top of one the router just\n * created in the same process (the `<mirror>/` scan would see a stale copy\n * from the previous launch, not this one).\n */\nexport async function buildReservedNames(opts: {\n mirrorDir: string\n repoRoot: string\n homeDir: string\n /**\n * The router roster THIS launch really publishes (agent-file stems from\n * `buildPiAgentFiles`, empty under `--no-peers`). Part of the router-owned\n * set, because the role exists and the roster must win the name. Kept\n * separate from the constant so a peerless launch does not skip a foreign\n * `Explore` for a roster it never wrote.\n */\n emittedAgents?: ReadonlyArray<string>\n emittedSkills?: ReadonlyArray<string>\n emittedPrompts?: ReadonlyArray<string>\n}): Promise<PiReservedNames> {\n const routerOwnedAgents = new Set<string>(\n PI_FOREIGN_ROUTER_OWNED_AGENTS.map(lower),\n )\n for (const name of opts.emittedAgents ?? []) routerOwnedAgents.add(lower(name))\n const agents = new Set<string>()\n const skills = new Set<string>()\n const prompts = new Set<string>()\n\n for (const root of [\n path.join(opts.mirrorDir, PI_AGENT_ROOTS_REL[0]),\n path.join(opts.repoRoot, PI_AGENT_ROOTS_REL[1]),\n path.join(opts.repoRoot, PI_AGENT_ROOTS_REL[2]),\n path.join(opts.homeDir, \".pi/agent/agents\"),\n path.join(opts.homeDir, \".agents\"),\n ]) {\n for (const key of await agentIdentityKeys(root)) agents.add(lower(key))\n }\n for (const key of routerOwnedAgents) agents.add(key)\n\n for (const root of [\n path.join(opts.mirrorDir, PI_SKILL_ROOTS_REL[0]),\n path.join(opts.repoRoot, PI_SKILL_ROOTS_REL[1]),\n path.join(opts.repoRoot, PI_SKILL_ROOTS_REL[2]),\n path.join(opts.homeDir, \".pi/agent/skills\"),\n path.join(opts.homeDir, \".agents/skills\"),\n ]) {\n for (const name of await skillNamesUnder(root)) skills.add(lower(name))\n }\n for (const name of opts.emittedSkills ?? []) skills.add(lower(name))\n\n for (const root of [\n path.join(opts.mirrorDir, PI_PROMPT_ROOTS_REL[0]),\n path.join(opts.repoRoot, PI_PROMPT_ROOTS_REL[1]),\n ]) {\n for (const name of await promptNamesUnder(root)) prompts.add(lower(name))\n }\n for (const name of opts.emittedPrompts ?? []) prompts.add(lower(name))\n\n return { routerOwnedAgents, agents, skills, prompts }\n}\n\n/* ------------------------------------------------------------------ */\n/* Planner */\n/* ------------------------------------------------------------------ */\n\n/** Deterministic suffix search shared by agents and skills/prompts. */\nfunction claim(\n taken: Set<string>,\n base: string,\n suffixes: () => Iterable<string>,\n): string {\n if (!taken.has(lower(base))) {\n taken.add(lower(base))\n return base\n }\n for (const candidate of suffixes()) {\n if (!taken.has(lower(candidate))) {\n taken.add(lower(candidate))\n return candidate\n }\n }\n // Unreachable: the generator is infinite. Keep TypeScript honest.\n return base\n}\n\nfunction* scopeSuffixes(base: string, scope: string): Generator<string> {\n yield `${base}-${scope}`\n for (let n = 2; n < 1_000; n++) yield `${base}-${scope}-${n}`\n}\n\nfunction* ordinals(base: string): Generator<string> {\n for (let n = 2; n < 1_000; n++) yield `${base}-${n}`\n}\n\nasync function collectAgentFiles(\n roots: ReadonlyArray<{ dir: string; scope: \"project\" | \"user\" }>,\n): Promise<Array<{ file: string; scope: \"project\" | \"user\" }>> {\n const out: Array<{ file: string; scope: \"project\" | \"user\" }> = []\n for (const { dir, scope } of roots) {\n for (const entry of await listDir(dir)) {\n if (!entry.endsWith(\".md\")) continue\n out.push({ file: path.join(dir, entry), scope })\n }\n }\n return byScopeThenPath(out)\n}\n\n/**\n * Scope is the FIRST sort key, not the root order.\n *\n * The two roots per scope (`.claude/…`, `.github/…`) are visited in a fixed\n * order, but `readdir` order is filesystem-dependent and the plan's suffixes\n * (`writer` vs `writer-user`) are assigned first-come. A project artifact must\n * win its authored name over a user artifact of the same name on every machine,\n * so the ordering is stated here rather than inherited from the walk.\n */\nfunction byScopeThenPath<T extends { file: string; scope: \"project\" | \"user\" }>(\n rows: Array<T>,\n): Array<T> {\n return rows.sort((a, b) => {\n if (a.scope !== b.scope) return a.scope === \"project\" ? -1 : 1\n return a.file < b.file ? -1 : a.file > b.file ? 1 : 0\n })\n}\n\nasync function collectSkillFiles(\n roots: ReadonlyArray<{ dir: string; scope: \"project\" | \"user\" }>,\n): Promise<Array<{ file: string; scope: \"project\" | \"user\"; name: string }>> {\n const out: Array<{ file: string; scope: \"project\" | \"user\"; name: string }> = []\n for (const { dir, scope } of roots) {\n for (const entry of await listDir(dir)) {\n if (entry.startsWith(\".\")) continue\n const full = path.join(dir, entry)\n if (await isDirectory(full)) {\n const skillFile = path.join(full, \"SKILL.md\")\n const raw = await readIfExists(skillFile)\n if (raw === undefined) continue\n out.push({\n file: skillFile,\n scope,\n name: frontmatterValue(splitFrontmatter(raw).frontmatter, \"name\") ?? entry,\n })\n continue\n }\n if (entry.endsWith(\".md\")) {\n const raw = await readIfExists(full)\n if (raw === undefined) continue\n out.push({\n file: full,\n scope,\n name:\n frontmatterValue(splitFrontmatter(raw).frontmatter, \"name\")\n ?? entry.replace(/\\.md$/, \"\"),\n })\n }\n }\n }\n return byScopeThenPath(out)\n}\n\nasync function collectPromptFiles(\n roots: ReadonlyArray<{ dir: string; scope: \"project\" | \"user\" }>,\n): Promise<Array<{ file: string; scope: \"project\" | \"user\"; name: string }>> {\n const out: Array<{ file: string; scope: \"project\" | \"user\"; name: string }> = []\n const walk = async (dir: string, scope: \"project\" | \"user\", prefix: string): Promise<void> => {\n for (const entry of await listDir(dir)) {\n if (entry.startsWith(\".\")) continue\n const full = path.join(dir, entry)\n if (await isDirectory(full)) {\n await walk(full, scope, `${prefix}${entry}-`)\n continue\n }\n if (!entry.endsWith(\".md\")) continue\n // `.prompt.md` is Copilot's prompt-file suffix; `deploy.prompt.md` is\n // the command `deploy`, not `deploy-prompt`.\n const stem = entry.replace(/\\.prompt\\.md$/, \"\").replace(/\\.md$/, \"\")\n // Nested commands flatten BEFORE the reservation, because a flattened\n // name can collide with a flat one (`nested/deploy` vs `deploy`).\n out.push({ file: full, scope, name: `${prefix}${stem}` })\n }\n }\n for (const { dir, scope } of roots) await walk(dir, scope, \"\")\n return byScopeThenPath(out)\n}\n\n/**\n * Build the bridge plan. Pure over the filesystem: reads the foreign roots\n * and the reservation sets, writes nothing.\n */\nexport async function planForeignArtifacts(opts: {\n repoRoot: string\n homeDir: string\n mirrorDir: string\n reservedNames: PiReservedNames\n}): Promise<PiForeignPlan> {\n const { repoRoot, homeDir, reservedNames: reserved } = opts\n const plan: PiForeignPlan = { skills: [], prompts: [], agents: [], skipped: [] }\n\n // Reservation sets are copied for the skill/prompt namespaces: they are\n // mutated as this plan claims names, so two foreign files that ask for the\n // same thing disambiguate instead of fighting.\n const skillNames = new Set(reserved.skills)\n const promptNames = new Set(reserved.prompts)\n const agentNames = new Set(reserved.agents)\n\n /* ----- skills (always bridged) ----- */\n const skillFiles = await collectSkillFiles([\n ...SKILL_ROOTS_PROJECT.map((rel) => ({ dir: path.join(repoRoot, rel), scope: \"project\" as const })),\n ...SKILL_ROOTS_USER.map((rel) => ({ dir: path.join(homeDir, rel), scope: \"user\" as const })),\n ])\n for (const { file, name } of skillFiles) {\n const raw = await readIfExists(file)\n if (raw === undefined) continue\n const shown = provenancePath(file, repoRoot, homeDir)\n const { frontmatter, body } = splitFrontmatter(raw)\n const description = collapseLine(frontmatterValue(frontmatter, \"description\") ?? \"\")\n if (!description) {\n // Pi refuses a skill with no description (`core/skills.js:252-254`), so\n // this is a hard skip — reported, never a silent drop.\n plan.skipped.push({ name, file: shown, reason: \"skill has no description (Pi requires one)\" })\n continue\n }\n const authored = piForeignSlug(name)\n const finalName = claim(skillNames, authored, () => ordinals(authored))\n const allowed = frontmatterList(frontmatter, \"allowed-tools\")\n plan.skills.push({\n name: finalName,\n ...(finalName === authored ? {} : { renamedFrom: name }),\n content: `${buildSkillFrontmatter(description)}\\n${buildArtifactBody({\n body,\n source: piForeignSourceOf(file),\n shown,\n allowed,\n })}`,\n })\n }\n\n /* ----- prompts (under --foreign) ----- */\n const promptFiles = await collectPromptFiles([\n ...PROMPT_ROOTS_PROJECT.map((rel) => ({ dir: path.join(repoRoot, rel), scope: \"project\" as const })),\n ...PROMPT_ROOTS_USER.map((rel) => ({ dir: path.join(homeDir, rel), scope: \"user\" as const })),\n ])\n for (const { file, name } of promptFiles) {\n const raw = await readIfExists(file)\n if (raw === undefined) continue\n const shown = provenancePath(file, repoRoot, homeDir)\n const authored = piForeignSlug(name)\n const finalName = claim(promptNames, authored, () => ordinals(authored))\n // A prompt template is prose + `$1`/`$ARGUMENTS` placeholders. The body is\n // otherwise passed through untouched: rewriting placeholders would silently\n // change what the command means, and `$ARGUMENTS` is documented as not\n // bridged. Only a provenance line is prepended, so the command's origin is\n // visible where it runs.\n const { body } = splitFrontmatter(raw)\n plan.prompts.push({\n name: finalName,\n ...(finalName === authored ? {} : { renamedFrom: name }),\n content: `${buildArtifactBody({ body, source: piForeignSourceOf(file), shown, allowed: [] })}\\n`,\n })\n }\n\n /* ----- agents (specs only — no files) ----- */\n const agentFiles = await collectAgentFiles([\n ...AGENT_ROOTS_PROJECT.map((rel) => ({ dir: path.join(repoRoot, rel), scope: \"project\" as const })),\n ...AGENT_ROOTS_USER.map((rel) => ({ dir: path.join(homeDir, rel), scope: \"user\" as const })),\n ])\n // Content-dekeyed dedupe: first-mate dual-emits the same 8 roles into\n // `.github/agents` AND `.claude/agents` with byte-identical bodies, so the\n // second copy of a role must not become `planner-2`.\n const seenBodies = new Set<string>()\n for (const { file, scope } of agentFiles) {\n const raw = await readIfExists(file)\n if (raw === undefined) continue\n const shown = provenancePath(file, repoRoot, homeDir)\n const stem = path.basename(file).replace(/\\.agent\\.md$/, \"\").replace(/\\.md$/, \"\")\n const { frontmatter, body } = splitFrontmatter(raw)\n const originalName = frontmatterValue(frontmatter, \"name\") ?? stem\n const description = collapseLine(frontmatterValue(frontmatter, \"description\") ?? \"\")\n // A flat `.md` without a description is not an agent definition (Copilot\n // requires one; Claude allows it but Pi's index line would be empty).\n if (!description) {\n plan.skipped.push({\n name: originalName,\n file: shown,\n reason: \"no description in frontmatter (not a usable agent definition)\",\n })\n continue\n }\n const authored = piForeignSlug(originalName)\n // Router-owned FIRST: the role already exists under that name, so a second\n // entry with one purpose would only make the catalog ambiguous. Ordered\n // before the dedupe so the dual-emitted `reviewer` from first-mate reports\n // the real reason twice (\"the role exists\") instead of once as a duplicate\n // of a copy that was itself never bridged — the second shape of skip would\n // be true but misleading, since nothing was bridged to duplicate.\n if (reserved.routerOwnedAgents.has(lower(originalName))) {\n plan.skipped.push({\n name: originalName,\n file: shown,\n reason: \"name is owned by gh-router or a pi-subagents builtin (that role already exists)\",\n })\n continue\n }\n const hash = `${authored}\\u0000${body}`\n if (seenBodies.has(hash)) {\n plan.skipped.push({\n name: originalName,\n file: shown,\n reason: \"duplicate of an identical definition already bridged from another emitted path\",\n })\n continue\n }\n seenBodies.add(hash)\n const finalName = claim(agentNames, authored, () => scopeSuffixes(authored, scope))\n const tools = frontmatterList(frontmatter, \"tools\")\n plan.agents.push({\n name: finalName,\n originalName,\n description: truncateChars(description, MAX_FOREIGN_DESCRIPTION_CHARS),\n // Trimmed because pi-subagents' `validateString` rejects a\n // `systemPrompt` that differs from its own `trim()` — and a markdown\n // body always ends with a newline, so an untrimmed body would fail\n // registration for EVERY bridged agent (`runtime-agent-registry.js:48`).\n body: capBytes(\n buildArtifactBody({ body, source: piForeignSourceOf(file), shown, allowed: tools }),\n MAX_FOREIGN_AGENT_BODY_BYTES,\n \"gh-router foreign-agent bridge\",\n ).text.trim(),\n source: piForeignSourceOf(file),\n scope,\n file: shown,\n ...(finalName === authored ? {} : { renamedFrom: originalName }),\n })\n }\n\n return plan\n}\n\n/**\n * Frontmatter for a bridged skill.\n *\n * The `name:` key is deliberately ABSENT: Pi resolves a skill's name from the\n * frontmatter when present and from the parent directory otherwise\n * (`core/skills.js:245`), so dropping it lets the directory we just wrote\n * decide. Keeping the authored `name: gh-oracle` inside `gh-oracle-2/SKILL.md`\n * makes BOTH copies load as `gh-oracle` and the foreign one loses as a\n * `collision` diagnostic — a silent loss.\n */\nfunction buildSkillFrontmatter(description: string): string {\n const safeDescription = truncateChars(description, MAX_FOREIGN_SKILL_DESCRIPTION_CHARS).replace(\n /\\r?\\n/g,\n \" \",\n )\n return `---\\ndescription: ${safeDescription}\\n---\\n`\n}\n\n/**\n * The shared body shape for bridged artifacts: a provenance line (so the\n * origin is visible where it runs, not only where it was written), the\n * original tool policy as prose (Pi cannot enforce a foreign allowlist, and an\n * unresolvable entry would hard-fail the child), then the authored body.\n *\n * The body is secret-redacted on the way through: a foreign agent or command is\n * user-authored prose that has never been through the router, and copying it\n * into a launch mirror verbatim would move any token pasted into it into a\n * second file tree.\n */\nfunction buildArtifactBody(opts: {\n body: string\n source: \"claude\" | \"copilot\"\n shown: string\n allowed: ReadonlyArray<string>\n}): string {\n const provenance = `> Bridged by github-router from ${opts.source === \"copilot\" ? \"Copilot\" : \"Claude\"} \\`${opts.shown}\\`.`\n const policy =\n opts.allowed.length > 0\n ? `> Authored tool policy (advisory in Pi): ${opts.allowed.join(\", \")}.`\n : undefined\n const trimmed = redactSecrets(opts.body).replace(/^\\n+/, \"\")\n return [provenance, ...(policy ? [policy] : []), \"\", trimmed].join(\"\\n\")\n}\n\n/**\n * The one index the model sees. Deliberately a compact list, not the bodies:\n * runtime agents are never advertised (`advertised-agent-prompt.js`), and\n * spending the 16-entry / 12 KiB catalog on foreign agents would crowd out\n * the router's own roster. The model calls\n * `subagent({action:\"list\", options:{search:\"…\"}})` for full descriptions.\n */\nexport function buildForeignAgentIndex(\n agents: ReadonlyArray<PiForeignAgentSpec>,\n opts: { maxBytes?: number } = {},\n): string {\n if (agents.length === 0) return \"\"\n const maxBytes = opts.maxBytes ?? MAX_FOREIGN_INDEX_BYTES\n const header = [\n \"Agents bridged from .claude / .github / ~/.copilot. They are NOT preloaded:\",\n 'call subagent({action:\"list\", options:{search:\"<term>\"}}) for full descriptions,',\n 'then subagent({agent:\"<name>\", task:\"…\"}). They run on this profile\\'s lead model.',\n ]\n const rows = agents.map(\n (a) => `- ${a.name} [${a.source}, ${a.scope}] — ${a.description}`,\n )\n // Ship whole rows: a half-written index line is worse than a count, because\n // the model would call an agent whose description it cannot read.\n const included: Array<string> = []\n let bytes = Buffer.byteLength([...header, ...included].join(\"\\n\"), \"utf8\")\n for (const row of rows) {\n const size = Buffer.byteLength(`${row}\\n`, \"utf8\")\n if (bytes + size > maxBytes) break\n included.push(row)\n bytes += size\n }\n const omitted = rows.length - included.length\n const tail = omitted > 0 ? [`+${omitted} more; {action:\"list\", options:{search:\"<term>\"}}`] : []\n return [...header, ...included, ...tail].join(\"\\n\")\n}\n\n/**\n * Write the plan's skills and prompts into the mirror.\n *\n * `overwritten` counts a target that already existed. It must be `0` on every\n * launch — the reservation is what guarantees it — and the launcher warns when\n * it is not, which is the tripwire for the silent-clobber failure this whole\n * module exists to prevent. Agents are NOT written: they are registry entries.\n */\nexport async function writeForeignArtifacts(\n mirrorDir: string,\n plan: PiForeignPlan,\n): Promise<{ skills: number; prompts: number; overwritten: number }> {\n let skills = 0\n let prompts = 0\n let overwritten = 0\n const write = async (file: string, content: string): Promise<void> => {\n const existing = await readIfExists(file)\n if (existing !== undefined) overwritten += 1\n await fs.mkdir(path.dirname(file), { recursive: true })\n await fs.writeFile(file, content, \"utf8\")\n }\n for (const skill of plan.skills) {\n await write(path.join(mirrorDir, \"skills\", skill.name, \"SKILL.md\"), skill.content)\n skills += 1\n }\n for (const prompt of plan.prompts) {\n await write(path.join(mirrorDir, \"prompts\", `${prompt.name}.md`), prompt.content)\n prompts += 1\n }\n return { skills, prompts, overwritten }\n}\n\n/**\n * Count the foreign AGENT definitions a `--foreign` launch would consider.\n *\n * Exists so a launch without the flag can still say the artifacts are there:\n * the bridge is invisible by design, and a user who has `.github/agents/` has\n * no other way to learn the flag exists. Deliberately a `readdir` count rather\n * than a plan — no reservations, no body reads, and it must stay cheap because\n * it runs on every non-`--foreign` launch.\n *\n * Counts **stems**, not files, because first-mate dual-emits every role into\n * `.github/agents` AND `.claude/agents` with byte-identical bodies: a file\n * count would report 16 where the user has 8 roles, which reads like the bridge\n * found something it did not.\n */\nexport async function countForeignAgentFiles(opts: {\n repoRoot: string\n homeDir: string\n}): Promise<number> {\n const stems = new Set<string>()\n for (const root of [\n ...AGENT_ROOTS_PROJECT.map((rel) => path.join(opts.repoRoot, rel)),\n ...AGENT_ROOTS_USER.map((rel) => path.join(opts.homeDir, rel)),\n ]) {\n for (const entry of await listDir(root)) {\n if (!entry.endsWith(\".md\")) continue\n stems.add(entry.replace(/\\.agent\\.md$/, \"\").replace(/\\.md$/, \"\"))\n }\n }\n return stems.size\n}\n\n/** Default home dir for the planner (separate seam so tests stay hermetic). */\nexport function piForeignHomeDir(): string {\n return os.homedir()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,MAAa,iCAAwD,OAAO,OAAO;CAEjF;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;AAWD,MAAM,sBAAsB,CAAC,kBAAkB,gBAAgB;AAC/D,MAAM,mBAAmB,CAAC,kBAAkB,iBAAiB;AAC7D,MAAM,sBAAsB,CAAC,kBAAkB,gBAAgB;AAC/D,MAAM,mBAAmB,CAAC,kBAAkB,iBAAiB;AAC7D,MAAM,uBAAuB,CAAC,oBAAoB,iBAAiB;AACnE,MAAM,oBAAoB,CAAC,kBAAkB;;AAG7C,MAAM,qBAAqB;CAAC;CAAU;CAAc;AAAgB;AACpE,MAAM,sBAAsB,CAAC,WAAW,aAAa;AACrD,MAAM,qBAAqB;CAAC;CAAU;CAAc;AAAS;;AAG7D,MAAM,+BAA+B;AACrC,MAAM,gCAAgC;AACtC,MAAM,sCAAsC;AAC5C,MAAM,0BAA0B;;AAEh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AAC,GACjE,GAAG,iBAAiB,KAAK,QAAQ,KAAK,KAAK,KAAK,SAAS,GAAG,CAAC,CAC/D,GACE,KAAK,MAAM,SAAS,MAAM,QAAQ,IAAI,GAAG;EACvC,IAAI,CAAC,MAAM,SAAS,KAAK,GAAG;EAC5B,MAAM,IAAI,MAAM,QAAQ,gBAAgB,EAAE,CAAC,CAAC,QAAQ,SAAS,EAAE,CAAC;CAClE;CAEF,OAAO,MAAM;AACf;;AAGA,SAAgB,mBAA2B;CACzC,OAAO,GAAG,QAAQ;AACpB"}
|
|
1
|
+
{"version":3,"file":"pi-foreign-artifacts-CNt6wQ1P.js","names":[],"sources":["../src/lib/pi-foreign-artifacts.ts"],"sourcesContent":["/**\n * Bridge the INHERITED artifact directories — Claude Code's `.claude/` /\n * `~/.claude/` and Copilot's `.github/` / `~/.copilot/` — into a\n * `github-router pi` launch.\n *\n * Three namespaces, three different failure modes, one rule set:\n *\n * | namespace | same-name outcome in Pi | reported? |\n * |-----------------|-----------------------------------------------|-----------|\n * | agent registry | `mergeRuntimeAgents` throws, EVERY `subagent` | yes |\n * | | call in the process fails until it is removed | |\n * | `skills/*` | the other `SKILL.md` is overwritten in place | **no** |\n * | `prompts/*.md` | the other file is overwritten in place | **no** |\n *\n * So the planner reserves names BEFORE anything is written, and the rule\n * differs by namespace on purpose:\n *\n * - **agents**: a name the router itself already ships (its roster, the\n * pi-subagents builtins, the read-only CLI adapters) means the role\n * already exists — the foreign definition is **skipped and reported**.\n * Two agents with one purpose in one catalog is the ambiguity that\n * produces wrong delegations, and a registry identity is not the only\n * carrier of the content (the skill and prompt are).\n * - **skills and prompts**: the file IS the only carrier, so they are\n * **renamed, never skipped** — `gh-oracle` → `gh-oracle-2`,\n * `review.md` → `review-2.md`.\n *\n * Renaming happens for anything else that is taken, deterministically:\n * agents become `<slug>-<scope>` (then `-2`, `-3`…), skills and prompts\n * become `<slug>-2` (then `-3`…). No source prefix — a prefix is not a\n * namespace (it walks straight into the builtin `claude-code` /\n * `claude-code-writer`) and it renames artifacts the user recognises for no\n * safety gain, since the reservation is what makes collisions unreachable.\n *\n * Foreign `model:` and `aliases:` are never emitted. The model would be a\n * Copilot slug that `isUnavailableSubagentModel` refuses (so every run of\n * that agent fails), and an alias is another registry identity that can\n * collide invisibly. Every bridged agent therefore runs on the launch's\n * lead model. `tools:` is dropped from the frontmatter and folded into the\n * body as prose, because an unresolvable entry in pi-subagents' strict\n * allowlist hard-fails the child.\n *\n * Nothing here imports pi-subagents or Pi: the router owns one rule and\n * reads the same frontmatter the loaders read, so a version bump upstream\n * cannot silently move a name out from under it.\n */\n\nimport fs from \"node:fs/promises\"\nimport os from \"node:os\"\nimport path from \"node:path\"\n\nimport { capBytes, redactSecrets, splitFrontmatter } from \"./pi-memory-bridge\"\n\n/**\n * Every name pi-subagents reserves for itself — `BUILTIN_AGENT_NAMES` from\n * the installed package plus the live alias map, the read-only CLI adapters,\n * and the router's own roster.\n *\n * Cannot be imported: pi-subagents is an installed Pi extension, never a\n * router dependency (bundling its internals would couple the launcher to a\n * version it does not pin). LAST_VERIFIED against pi-subagents 0.88.0:\n * `src/agents/builtin-names.js` for the 13 names, and a live `snapshot.all`\n * for the aliases (`oracle → advisor`,\n * `worker → developer, coder, implementer, develop`; every other builtin\n * carries none).\n *\n * Drift here is not a correctness hole: the extension's `tool_result` net\n * unregisters anything the registry rejects at merge time. It is a\n * friendliness hole (a foreign agent skipped needlessly), which is why this\n * list is commented rather than guessed.\n */\nexport const PI_FOREIGN_ROUTER_OWNED_AGENTS: ReadonlyArray<string> = Object.freeze([\n // pi-subagents builtins (BUILTIN_AGENT_NAMES, 0.88.0).\n \"advisor\",\n \"claude-code\",\n \"claude-code-writer\",\n \"codex-exec\",\n \"codex-exec-writer\",\n \"cursor-agent\",\n \"cursor-agent-writer\",\n \"delegate\",\n \"evidence-auditor\",\n \"oracle\",\n \"researcher\",\n \"reviewer\",\n \"scout\",\n \"worker\",\n // Live aliases of those builtins (`oracle`, `worker` above).\n \"developer\",\n \"coder\",\n \"implementer\",\n \"develop\",\n])\n\n/**\n * The router's own agent roster is NOT in the constant above: it depends on\n * the launch (`buildPiAgentFiles` writes Explore / General-Purpose / reviewer /\n * oracle / advisor, and `--no-peers` writes none), so `buildReservedNames`\n * takes it as `emittedAgents` instead. A hardcoded copy here would skip a\n * foreign `Explore` on a peerless launch that publishes no such role.\n */\n\n/** Foreign artifact roots. Project + user, Claude + Copilot. */\nconst SKILL_ROOTS_PROJECT = [\".claude/skills\", \".github/skills\"] as const\nconst SKILL_ROOTS_USER = [\".claude/skills\", \".copilot/skills\"] as const\nconst AGENT_ROOTS_PROJECT = [\".claude/agents\", \".github/agents\"] as const\nconst AGENT_ROOTS_USER = [\".claude/agents\", \".copilot/agents\"] as const\nconst PROMPT_ROOTS_PROJECT = [\".claude/commands\", \".github/prompts\"] as const\nconst PROMPT_ROOTS_USER = [\".claude/commands\"] as const\n\n/** Pi's own artifact roots in the mirror / repo / home, for reservation. */\nconst PI_SKILL_ROOTS_REL = [\"skills\", \".pi/skills\", \".agents/skills\"] as const\nconst PI_PROMPT_ROOTS_REL = [\"prompts\", \".pi/prompts\"] as const\nconst PI_AGENT_ROOTS_REL = [\"agents\", \".pi/agents\", \".agents\"] as const\n\n/** Caps. Pi refuses a skill without a description (`core/skills.js:252`). */\nconst MAX_FOREIGN_AGENT_BODY_BYTES = 8 * 1024\nconst MAX_FOREIGN_DESCRIPTION_CHARS = 200\nconst MAX_FOREIGN_SKILL_DESCRIPTION_CHARS = 1_000\nconst MAX_FOREIGN_INDEX_BYTES = 4 * 1024\n/** Mirrors Pi's own limits so a bridged file can never be rejected. */\nconst MAX_SKILL_NAME_CHARS = 64\n\nexport interface PiForeignAgentSpec {\n /** Final, collision-free, slugged (the authored name unless it was taken). */\n name: string\n /** The name as authored in the source file, before any suffix. */\n originalName: string\n /** One line, whitespace-collapsed, ≤ 200 chars. */\n description: string\n /** Frontmatter stripped, provenance line, tool policy as prose, ≤ 8 KiB. */\n body: string\n source: \"claude\" | \"copilot\"\n scope: \"project\" | \"user\"\n /** Repo- or home-relative provenance, shown in the index. */\n file: string\n /** Set when the name had to change (`gh-oracle` → `gh-oracle-2`). */\n renamedFrom?: string\n}\n\nexport interface PiForeignArtifactDoc {\n /** Final name: skill directory, or prompt file stem. */\n name: string\n content: string\n renamedFrom?: string\n}\n\nexport interface PiForeignPlan {\n /** Written to `<mirror>/skills/<name>/SKILL.md`. */\n skills: Array<PiForeignArtifactDoc>\n /** Written to `<mirror>/prompts/<name>.md`. */\n prompts: Array<PiForeignArtifactDoc>\n /**\n * Registered through the pi-subagents runtime-agent event. NO files are\n * written for these: one registry entry, announced in the prompt index,\n * loaded on demand via `subagent({action:\"list\"})`.\n */\n agents: Array<PiForeignAgentSpec>\n /** Everything dropped rather than bridged, with the reason. Never silent. */\n skipped: Array<{ name: string; file: string; reason: string }>\n}\n\nexport interface PiReservedNames {\n /** Builtins + aliases + adapters + this launch's roster. Never renamed to. */\n routerOwnedAgents: Set<string>\n /** Every agent identity key on disk (name, aliases, localName). */\n agents: Set<string>\n /** Skill names and directory slugs on disk, plus this launch's own. */\n skills: Set<string>\n /** Prompt stems on disk, plus this launch's own. */\n prompts: Set<string>\n}\n\nfunction lower(s: string): string {\n return s.trim().toLowerCase()\n}\n\n/** Collapse to a legal Pi/prompt path segment and registry name. */\nexport function piForeignSlug(raw: string): string {\n const slug = String(raw ?? \"\")\n .toLowerCase()\n // Any run of illegal characters is one separator, so `Copilot Deploy!`\n // and `--spaced Name--` both land on a legal, readable segment.\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n const trimmed = slug.length > MAX_SKILL_NAME_CHARS ? slug.slice(0, MAX_SKILL_NAME_CHARS).replace(/-+$/, \"\") : slug\n // An all-symbols name slugs to nothing; it still needs a usable identity.\n return trimmed.length > 0 ? trimmed : \"foreign\"\n}\n\nfunction collapseLine(raw: string): string {\n return raw.replace(/\\s+/g, \" \").trim()\n}\n\nfunction truncateChars(raw: string, max: number): string {\n if (raw.length <= max) return raw\n return `${raw.slice(0, Math.max(0, max - 1)).trimEnd()}…`\n}\n\n/** YAML-ish frontmatter read: `key: value` on one line, quotes stripped. */\nfunction frontmatterValue(frontmatter: string, key: string): string | undefined {\n const re = new RegExp(`^${key}\\\\s*:\\\\s*(.*)$`, \"im\")\n const match = re.exec(frontmatter)\n if (!match) return undefined\n const value = match[1].trim().replace(/^[\"']/, \"\").replace(/[\"']$/, \"\").trim()\n return value.length > 0 ? value : undefined\n}\n\n/** Space- and comma-separated list value (`tools: read, grep, bash`). */\nfunction frontmatterList(frontmatter: string, key: string): Array<string> {\n const raw = frontmatterValue(frontmatter, key)\n if (!raw) return []\n return raw\n .replace(/^\\[/, \"\")\n .replace(/\\]$/, \"\")\n .split(/[,\\s]+/)\n .map((s) => s.trim())\n .filter((s) => s.length > 0)\n}\n\nasync function readIfExists(file: string): Promise<string | undefined> {\n try {\n return await fs.readFile(file, \"utf8\")\n } catch {\n return undefined\n }\n}\n\nasync function isDirectory(dir: string): Promise<boolean> {\n try {\n return (await fs.stat(dir)).isDirectory()\n } catch {\n return false\n }\n}\n\nasync function listDir(dir: string): Promise<Array<string>> {\n try {\n return (await fs.readdir(dir)).sort()\n } catch {\n return []\n }\n}\n\n/** Repo root: walk up for `.git`, else the given cwd. Never throws. */\nexport async function piForeignRepoRoot(cwd: string): Promise<string> {\n let dir = path.resolve(cwd)\n for (let depth = 0; depth < 12; depth++) {\n try {\n await fs.stat(path.join(dir, \".git\"))\n return dir\n } catch {\n const parent = path.dirname(dir)\n if (parent === dir) break\n dir = parent\n }\n }\n return cwd\n}\n\n/**\n * Which product an artifact came from, from its path alone.\n *\n * Normalized to forward slashes first: the roots above are POSIX literals, so\n * a Windows path (`\\.github\\.`) would otherwise match nothing and every\n * artifact would be labelled Claude. The label reaches the index and the\n * provenance line, i.e. the model's view of where an agent came from.\n */\nexport function piForeignSourceOf(file: string): \"claude\" | \"copilot\" {\n const posix = file.replace(/\\\\/g, \"/\")\n return posix.includes(\"/.github/\") || posix.includes(\"/.copilot/\") ? \"copilot\" : \"claude\"\n}\n\nfunction provenancePath(file: string, repoRoot: string, homeDir: string): string {\n const rel = (base: string, prefix: string): string | undefined => {\n const out = path.relative(base, file)\n return out.length > 0 && !out.startsWith(\"..\") ? `${prefix}${out.split(path.sep).join(\"/\")}` : undefined\n }\n // `~` for home on purpose: the index and the provenance line are read by a\n // human in a transcript, and an absolute path would leak the account name\n // into every bridged artifact.\n return rel(repoRoot, \"\") ?? rel(homeDir, \"~/\") ?? path.basename(file)\n}\n\n/* ------------------------------------------------------------------ */\n/* Reservation */\n/* ------------------------------------------------------------------ */\n\n/** Every `<dir>/*.md` under an agent root (flat — that is all Pi scans). */\nasync function agentIdentityKeys(root: string): Promise<Array<string>> {\n const keys: Array<string> = []\n for (const name of await listDir(root)) {\n if (!name.endsWith(\".md\")) continue\n // `.agent.md` (Copilot) and `*.md` (Claude) both reduce to the stem.\n const stem = name.replace(/\\.agent\\.md$/, \"\").replace(/\\.md$/, \"\")\n const raw = await readIfExists(path.join(root, name))\n if (raw === undefined) continue\n const { frontmatter } = splitFrontmatter(raw)\n const authored = frontmatterValue(frontmatter, \"name\") ?? stem\n keys.push(authored, stem)\n for (const key of [\"aliases\", \"alias\", \"localName\"]) {\n keys.push(...frontmatterList(frontmatter, key))\n }\n }\n return keys\n}\n\nasync function skillNamesUnder(root: string): Promise<Array<string>> {\n const names: Array<string> = []\n for (const entry of await listDir(root)) {\n if (entry.startsWith(\".\")) continue\n const dir = path.join(root, entry)\n if (await isDirectory(dir)) {\n // Directory-based skill: Pi names it from frontmatter, else the dir.\n names.push(entry)\n const raw = await readIfExists(path.join(dir, \"SKILL.md\"))\n if (raw !== undefined) {\n const named = frontmatterValue(splitFrontmatter(raw).frontmatter, \"name\")\n if (named) names.push(named)\n }\n continue\n }\n if (entry.endsWith(\".md\")) {\n // Single-file skill: the stem is the name.\n const stem = entry.replace(/\\.md$/, \"\")\n names.push(stem)\n const raw = await readIfExists(path.join(root, entry))\n if (raw !== undefined) {\n const named = frontmatterValue(splitFrontmatter(raw).frontmatter, \"name\")\n if (named) names.push(named)\n }\n }\n }\n return names\n}\n\nasync function promptNamesUnder(root: string): Promise<Array<string>> {\n const names: Array<string> = []\n for (const entry of await listDir(root)) {\n const full = path.join(root, entry)\n if (await isDirectory(full)) {\n names.push(...(await promptNamesUnder(full)))\n continue\n }\n if (entry.endsWith(\".md\")) names.push(entry.replace(/\\.md$/, \"\"))\n }\n return names\n}\n\n/**\n * Build the four reservation sets.\n *\n * `emittedSkills` / `emittedPrompts` are the names THIS launch is about to\n * write, so a foreign artifact can never land on top of one the router just\n * created in the same process (the `<mirror>/` scan would see a stale copy\n * from the previous launch, not this one).\n */\nexport async function buildReservedNames(opts: {\n mirrorDir: string\n repoRoot: string\n homeDir: string\n /**\n * The router roster THIS launch really publishes (agent-file stems from\n * `buildPiAgentFiles`, empty under `--no-peers`). Part of the router-owned\n * set, because the role exists and the roster must win the name. Kept\n * separate from the constant so a peerless launch does not skip a foreign\n * `Explore` for a roster it never wrote.\n */\n emittedAgents?: ReadonlyArray<string>\n emittedSkills?: ReadonlyArray<string>\n emittedPrompts?: ReadonlyArray<string>\n}): Promise<PiReservedNames> {\n const routerOwnedAgents = new Set<string>(\n PI_FOREIGN_ROUTER_OWNED_AGENTS.map(lower),\n )\n for (const name of opts.emittedAgents ?? []) routerOwnedAgents.add(lower(name))\n const agents = new Set<string>()\n const skills = new Set<string>()\n const prompts = new Set<string>()\n\n for (const root of [\n path.join(opts.mirrorDir, PI_AGENT_ROOTS_REL[0]),\n path.join(opts.repoRoot, PI_AGENT_ROOTS_REL[1]),\n path.join(opts.repoRoot, PI_AGENT_ROOTS_REL[2]),\n path.join(opts.homeDir, \".pi/agent/agents\"),\n path.join(opts.homeDir, \".agents\"),\n ]) {\n for (const key of await agentIdentityKeys(root)) agents.add(lower(key))\n }\n for (const key of routerOwnedAgents) agents.add(key)\n\n for (const root of [\n path.join(opts.mirrorDir, PI_SKILL_ROOTS_REL[0]),\n path.join(opts.repoRoot, PI_SKILL_ROOTS_REL[1]),\n path.join(opts.repoRoot, PI_SKILL_ROOTS_REL[2]),\n path.join(opts.homeDir, \".pi/agent/skills\"),\n path.join(opts.homeDir, \".agents/skills\"),\n ]) {\n for (const name of await skillNamesUnder(root)) skills.add(lower(name))\n }\n for (const name of opts.emittedSkills ?? []) skills.add(lower(name))\n\n for (const root of [\n path.join(opts.mirrorDir, PI_PROMPT_ROOTS_REL[0]),\n path.join(opts.repoRoot, PI_PROMPT_ROOTS_REL[1]),\n ]) {\n for (const name of await promptNamesUnder(root)) prompts.add(lower(name))\n }\n for (const name of opts.emittedPrompts ?? []) prompts.add(lower(name))\n\n return { routerOwnedAgents, agents, skills, prompts }\n}\n\n/* ------------------------------------------------------------------ */\n/* Planner */\n/* ------------------------------------------------------------------ */\n\n/** Deterministic suffix search shared by agents and skills/prompts. */\nfunction claim(\n taken: Set<string>,\n base: string,\n suffixes: () => Iterable<string>,\n): string {\n if (!taken.has(lower(base))) {\n taken.add(lower(base))\n return base\n }\n for (const candidate of suffixes()) {\n if (!taken.has(lower(candidate))) {\n taken.add(lower(candidate))\n return candidate\n }\n }\n // Unreachable: the generator is infinite. Keep TypeScript honest.\n return base\n}\n\nfunction* scopeSuffixes(base: string, scope: string): Generator<string> {\n yield `${base}-${scope}`\n for (let n = 2; n < 1_000; n++) yield `${base}-${scope}-${n}`\n}\n\nfunction* ordinals(base: string): Generator<string> {\n for (let n = 2; n < 1_000; n++) yield `${base}-${n}`\n}\n\nasync function collectAgentFiles(\n roots: ReadonlyArray<{ dir: string; scope: \"project\" | \"user\" }>,\n): Promise<Array<{ file: string; scope: \"project\" | \"user\" }>> {\n const out: Array<{ file: string; scope: \"project\" | \"user\" }> = []\n for (const { dir, scope } of roots) {\n for (const entry of await listDir(dir)) {\n if (!entry.endsWith(\".md\")) continue\n out.push({ file: path.join(dir, entry), scope })\n }\n }\n return byScopeThenPath(out)\n}\n\n/**\n * Scope is the FIRST sort key, not the root order.\n *\n * The two roots per scope (`.claude/…`, `.github/…`) are visited in a fixed\n * order, but `readdir` order is filesystem-dependent and the plan's suffixes\n * (`writer` vs `writer-user`) are assigned first-come. A project artifact must\n * win its authored name over a user artifact of the same name on every machine,\n * so the ordering is stated here rather than inherited from the walk.\n */\nfunction byScopeThenPath<T extends { file: string; scope: \"project\" | \"user\" }>(\n rows: Array<T>,\n): Array<T> {\n return rows.sort((a, b) => {\n if (a.scope !== b.scope) return a.scope === \"project\" ? -1 : 1\n return a.file < b.file ? -1 : a.file > b.file ? 1 : 0\n })\n}\n\nasync function collectSkillFiles(\n roots: ReadonlyArray<{ dir: string; scope: \"project\" | \"user\" }>,\n): Promise<Array<{ file: string; scope: \"project\" | \"user\"; name: string }>> {\n const out: Array<{ file: string; scope: \"project\" | \"user\"; name: string }> = []\n for (const { dir, scope } of roots) {\n for (const entry of await listDir(dir)) {\n if (entry.startsWith(\".\")) continue\n const full = path.join(dir, entry)\n if (await isDirectory(full)) {\n const skillFile = path.join(full, \"SKILL.md\")\n const raw = await readIfExists(skillFile)\n if (raw === undefined) continue\n out.push({\n file: skillFile,\n scope,\n name: frontmatterValue(splitFrontmatter(raw).frontmatter, \"name\") ?? entry,\n })\n continue\n }\n if (entry.endsWith(\".md\")) {\n const raw = await readIfExists(full)\n if (raw === undefined) continue\n out.push({\n file: full,\n scope,\n name:\n frontmatterValue(splitFrontmatter(raw).frontmatter, \"name\")\n ?? entry.replace(/\\.md$/, \"\"),\n })\n }\n }\n }\n return byScopeThenPath(out)\n}\n\nasync function collectPromptFiles(\n roots: ReadonlyArray<{ dir: string; scope: \"project\" | \"user\" }>,\n): Promise<Array<{ file: string; scope: \"project\" | \"user\"; name: string }>> {\n const out: Array<{ file: string; scope: \"project\" | \"user\"; name: string }> = []\n const walk = async (dir: string, scope: \"project\" | \"user\", prefix: string): Promise<void> => {\n for (const entry of await listDir(dir)) {\n if (entry.startsWith(\".\")) continue\n const full = path.join(dir, entry)\n if (await isDirectory(full)) {\n await walk(full, scope, `${prefix}${entry}-`)\n continue\n }\n if (!entry.endsWith(\".md\")) continue\n // `.prompt.md` is Copilot's prompt-file suffix; `deploy.prompt.md` is\n // the command `deploy`, not `deploy-prompt`.\n const stem = entry.replace(/\\.prompt\\.md$/, \"\").replace(/\\.md$/, \"\")\n // Nested commands flatten BEFORE the reservation, because a flattened\n // name can collide with a flat one (`nested/deploy` vs `deploy`).\n out.push({ file: full, scope, name: `${prefix}${stem}` })\n }\n }\n for (const { dir, scope } of roots) await walk(dir, scope, \"\")\n return byScopeThenPath(out)\n}\n\n/**\n * Build the bridge plan. Pure over the filesystem: reads the foreign roots\n * and the reservation sets, writes nothing.\n */\nexport async function planForeignArtifacts(opts: {\n repoRoot: string\n homeDir: string\n mirrorDir: string\n reservedNames: PiReservedNames\n}): Promise<PiForeignPlan> {\n const { repoRoot, homeDir, reservedNames: reserved } = opts\n const plan: PiForeignPlan = { skills: [], prompts: [], agents: [], skipped: [] }\n\n // Reservation sets are copied for the skill/prompt namespaces: they are\n // mutated as this plan claims names, so two foreign files that ask for the\n // same thing disambiguate instead of fighting.\n const skillNames = new Set(reserved.skills)\n const promptNames = new Set(reserved.prompts)\n const agentNames = new Set(reserved.agents)\n\n /* ----- skills (always bridged) ----- */\n const skillFiles = await collectSkillFiles([\n ...SKILL_ROOTS_PROJECT.map((rel) => ({ dir: path.join(repoRoot, rel), scope: \"project\" as const })),\n ...SKILL_ROOTS_USER.map((rel) => ({ dir: path.join(homeDir, rel), scope: \"user\" as const })),\n ])\n for (const { file, name } of skillFiles) {\n const raw = await readIfExists(file)\n if (raw === undefined) continue\n const shown = provenancePath(file, repoRoot, homeDir)\n const { frontmatter, body } = splitFrontmatter(raw)\n const description = collapseLine(frontmatterValue(frontmatter, \"description\") ?? \"\")\n if (!description) {\n // Pi refuses a skill with no description (`core/skills.js:252-254`), so\n // this is a hard skip — reported, never a silent drop.\n plan.skipped.push({ name, file: shown, reason: \"skill has no description (Pi requires one)\" })\n continue\n }\n const authored = piForeignSlug(name)\n const finalName = claim(skillNames, authored, () => ordinals(authored))\n const allowed = frontmatterList(frontmatter, \"allowed-tools\")\n plan.skills.push({\n name: finalName,\n ...(finalName === authored ? {} : { renamedFrom: name }),\n content: `${buildSkillFrontmatter(description)}\\n${buildArtifactBody({\n body,\n source: piForeignSourceOf(file),\n shown,\n allowed,\n })}`,\n })\n }\n\n /* ----- prompts (under --foreign) ----- */\n const promptFiles = await collectPromptFiles([\n ...PROMPT_ROOTS_PROJECT.map((rel) => ({ dir: path.join(repoRoot, rel), scope: \"project\" as const })),\n ...PROMPT_ROOTS_USER.map((rel) => ({ dir: path.join(homeDir, rel), scope: \"user\" as const })),\n ])\n for (const { file, name } of promptFiles) {\n const raw = await readIfExists(file)\n if (raw === undefined) continue\n const shown = provenancePath(file, repoRoot, homeDir)\n const authored = piForeignSlug(name)\n const finalName = claim(promptNames, authored, () => ordinals(authored))\n // A prompt template is prose + `$1`/`$ARGUMENTS` placeholders. The body is\n // otherwise passed through untouched: rewriting placeholders would silently\n // change what the command means, and `$ARGUMENTS` is documented as not\n // bridged. Only a provenance line is prepended, so the command's origin is\n // visible where it runs.\n const { body } = splitFrontmatter(raw)\n plan.prompts.push({\n name: finalName,\n ...(finalName === authored ? {} : { renamedFrom: name }),\n content: `${buildArtifactBody({ body, source: piForeignSourceOf(file), shown, allowed: [] })}\\n`,\n })\n }\n\n /* ----- agents (specs only — no files) ----- */\n const agentFiles = await collectAgentFiles([\n ...AGENT_ROOTS_PROJECT.map((rel) => ({ dir: path.join(repoRoot, rel), scope: \"project\" as const })),\n ...AGENT_ROOTS_USER.map((rel) => ({ dir: path.join(homeDir, rel), scope: \"user\" as const })),\n ])\n // Content-dekeyed dedupe: first-mate dual-emits the same 8 roles into\n // `.github/agents` AND `.claude/agents` with byte-identical bodies, so the\n // second copy of a role must not become `planner-2`.\n const seenBodies = new Set<string>()\n for (const { file, scope } of agentFiles) {\n const raw = await readIfExists(file)\n if (raw === undefined) continue\n const shown = provenancePath(file, repoRoot, homeDir)\n const stem = path.basename(file).replace(/\\.agent\\.md$/, \"\").replace(/\\.md$/, \"\")\n const { frontmatter, body } = splitFrontmatter(raw)\n const originalName = frontmatterValue(frontmatter, \"name\") ?? stem\n const description = collapseLine(frontmatterValue(frontmatter, \"description\") ?? \"\")\n // A flat `.md` without a description is not an agent definition (Copilot\n // requires one; Claude allows it but Pi's index line would be empty).\n if (!description) {\n plan.skipped.push({\n name: originalName,\n file: shown,\n reason: \"no description in frontmatter (not a usable agent definition)\",\n })\n continue\n }\n const authored = piForeignSlug(originalName)\n // Router-owned FIRST: the role already exists under that name, so a second\n // entry with one purpose would only make the catalog ambiguous. Ordered\n // before the dedupe so the dual-emitted `reviewer` from first-mate reports\n // the real reason twice (\"the role exists\") instead of once as a duplicate\n // of a copy that was itself never bridged — the second shape of skip would\n // be true but misleading, since nothing was bridged to duplicate.\n if (reserved.routerOwnedAgents.has(lower(originalName))) {\n plan.skipped.push({\n name: originalName,\n file: shown,\n reason: \"name is owned by gh-router or a pi-subagents builtin (that role already exists)\",\n })\n continue\n }\n const hash = `${authored}\\u0000${body}`\n if (seenBodies.has(hash)) {\n plan.skipped.push({\n name: originalName,\n file: shown,\n reason: \"duplicate of an identical definition already bridged from another emitted path\",\n })\n continue\n }\n seenBodies.add(hash)\n const finalName = claim(agentNames, authored, () => scopeSuffixes(authored, scope))\n const tools = frontmatterList(frontmatter, \"tools\")\n plan.agents.push({\n name: finalName,\n originalName,\n description: truncateChars(description, MAX_FOREIGN_DESCRIPTION_CHARS),\n // Trimmed because pi-subagents' `validateString` rejects a\n // `systemPrompt` that differs from its own `trim()` — and a markdown\n // body always ends with a newline, so an untrimmed body would fail\n // registration for EVERY bridged agent (`runtime-agent-registry.js:48`).\n body: capBytes(\n buildArtifactBody({ body, source: piForeignSourceOf(file), shown, allowed: tools }),\n MAX_FOREIGN_AGENT_BODY_BYTES,\n \"gh-router foreign-agent bridge\",\n ).text.trim(),\n source: piForeignSourceOf(file),\n scope,\n file: shown,\n ...(finalName === authored ? {} : { renamedFrom: originalName }),\n })\n }\n\n return plan\n}\n\n/**\n * Frontmatter for a bridged skill.\n *\n * The `name:` key is deliberately ABSENT: Pi resolves a skill's name from the\n * frontmatter when present and from the parent directory otherwise\n * (`core/skills.js:245`), so dropping it lets the directory we just wrote\n * decide. Keeping the authored `name: gh-oracle` inside `gh-oracle-2/SKILL.md`\n * makes BOTH copies load as `gh-oracle` and the foreign one loses as a\n * `collision` diagnostic — a silent loss.\n */\nfunction buildSkillFrontmatter(description: string): string {\n const safeDescription = truncateChars(description, MAX_FOREIGN_SKILL_DESCRIPTION_CHARS).replace(\n /\\r?\\n/g,\n \" \",\n )\n return `---\\ndescription: ${safeDescription}\\n---\\n`\n}\n\n/**\n * The shared body shape for bridged artifacts: a provenance line (so the\n * origin is visible where it runs, not only where it was written), the\n * original tool policy as prose (Pi cannot enforce a foreign allowlist, and an\n * unresolvable entry would hard-fail the child), then the authored body.\n *\n * The body is secret-redacted on the way through: a foreign agent or command is\n * user-authored prose that has never been through the router, and copying it\n * into a launch mirror verbatim would move any token pasted into it into a\n * second file tree.\n */\nfunction buildArtifactBody(opts: {\n body: string\n source: \"claude\" | \"copilot\"\n shown: string\n allowed: ReadonlyArray<string>\n}): string {\n const provenance = `> Bridged by github-router from ${opts.source === \"copilot\" ? \"Copilot\" : \"Claude\"} \\`${opts.shown}\\`.`\n const policy =\n opts.allowed.length > 0\n ? `> Authored tool policy (advisory in Pi): ${opts.allowed.join(\", \")}.`\n : undefined\n const trimmed = redactSecrets(opts.body).replace(/^\\n+/, \"\")\n return [provenance, ...(policy ? [policy] : []), \"\", trimmed].join(\"\\n\")\n}\n\n/**\n * The one index the model sees. Deliberately a compact list, not the bodies:\n * runtime agents are never advertised (`advertised-agent-prompt.js`), and\n * spending the 16-entry / 12 KiB catalog on foreign agents would crowd out\n * the router's own roster. The model calls\n * `subagent({action:\"list\", options:{search:\"…\"}})` for full descriptions.\n */\nexport function buildForeignAgentIndex(\n agents: ReadonlyArray<PiForeignAgentSpec>,\n opts: { maxBytes?: number } = {},\n): string {\n if (agents.length === 0) return \"\"\n const maxBytes = opts.maxBytes ?? MAX_FOREIGN_INDEX_BYTES\n const header = [\n \"Agents bridged from .claude / .github / ~/.copilot. They are NOT preloaded:\",\n 'call subagent({action:\"list\", options:{search:\"<term>\"}}) for full descriptions,',\n 'then subagent({agent:\"<name>\", task:\"…\"}). They run on this profile\\'s lead model.',\n ]\n const rows = agents.map(\n (a) => `- ${a.name} [${a.source}, ${a.scope}] — ${a.description}`,\n )\n // Ship whole rows: a half-written index line is worse than a count, because\n // the model would call an agent whose description it cannot read.\n const included: Array<string> = []\n let bytes = Buffer.byteLength([...header, ...included].join(\"\\n\"), \"utf8\")\n for (const row of rows) {\n const size = Buffer.byteLength(`${row}\\n`, \"utf8\")\n if (bytes + size > maxBytes) break\n included.push(row)\n bytes += size\n }\n const omitted = rows.length - included.length\n const tail = omitted > 0 ? [`+${omitted} more; {action:\"list\", options:{search:\"<term>\"}}`] : []\n return [...header, ...included, ...tail].join(\"\\n\")\n}\n\n/**\n * Write the plan's skills and prompts into the mirror.\n *\n * `overwritten` counts a target that already existed. It must be `0` on every\n * launch — the reservation is what guarantees it — and the launcher warns when\n * it is not, which is the tripwire for the silent-clobber failure this whole\n * module exists to prevent. Agents are NOT written: they are registry entries.\n */\nexport async function writeForeignArtifacts(\n mirrorDir: string,\n plan: PiForeignPlan,\n): Promise<{ skills: number; prompts: number; overwritten: number }> {\n let skills = 0\n let prompts = 0\n let overwritten = 0\n const write = async (file: string, content: string): Promise<void> => {\n const existing = await readIfExists(file)\n if (existing !== undefined) overwritten += 1\n await fs.mkdir(path.dirname(file), { recursive: true })\n await fs.writeFile(file, content, \"utf8\")\n }\n for (const skill of plan.skills) {\n await write(path.join(mirrorDir, \"skills\", skill.name, \"SKILL.md\"), skill.content)\n skills += 1\n }\n for (const prompt of plan.prompts) {\n await write(path.join(mirrorDir, \"prompts\", `${prompt.name}.md`), prompt.content)\n prompts += 1\n }\n return { skills, prompts, overwritten }\n}\n\n/**\n * Count the foreign AGENT definitions a `--foreign` launch would consider.\n *\n * Exists so a launch without the flag can still say the artifacts are there:\n * the bridge is invisible by design, and a user who has `.github/agents/` has\n * no other way to learn the flag exists. Deliberately a `readdir` count rather\n * than a plan — no reservations, no body reads, and it must stay cheap because\n * it runs on every non-`--foreign` launch.\n *\n * Counts **stems**, not files, because first-mate dual-emits every role into\n * `.github/agents` AND `.claude/agents` with byte-identical bodies: a file\n * count would report 16 where the user has 8 roles, which reads like the bridge\n * found something it did not.\n */\nexport async function countForeignAgentFiles(opts: {\n repoRoot: string\n homeDir: string\n}): Promise<number> {\n const stems = new Set<string>()\n for (const root of [\n ...AGENT_ROOTS_PROJECT.map((rel) => path.join(opts.repoRoot, rel)),\n ...AGENT_ROOTS_USER.map((rel) => path.join(opts.homeDir, rel)),\n ]) {\n for (const entry of await listDir(root)) {\n if (!entry.endsWith(\".md\")) continue\n stems.add(entry.replace(/\\.agent\\.md$/, \"\").replace(/\\.md$/, \"\"))\n }\n }\n return stems.size\n}\n\n/** Default home dir for the planner (separate seam so tests stay hermetic). */\nexport function piForeignHomeDir(): string {\n return os.homedir()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,MAAa,iCAAwD,OAAO,OAAO;CAEjF;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;;AAWD,MAAM,sBAAsB,CAAC,kBAAkB,gBAAgB;AAC/D,MAAM,mBAAmB,CAAC,kBAAkB,iBAAiB;AAC7D,MAAM,sBAAsB,CAAC,kBAAkB,gBAAgB;AAC/D,MAAM,mBAAmB,CAAC,kBAAkB,iBAAiB;AAC7D,MAAM,uBAAuB,CAAC,oBAAoB,iBAAiB;AACnE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