github-router 0.3.378 → 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-BR5Umj2L.js → attribution-settings-BJ1fjX7V.js} +10 -10
- package/dist/{attribution-settings-BR5Umj2L.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--4O3wHRq.js → claude-BWwkOMi3.js} +26 -25
- package/dist/{claude--4O3wHRq.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-DHRMLpSo.js → codex-C6ix3BaY.js} +8 -7
- package/dist/{codex-DHRMLpSo.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-B0EFY6l7.js → pi-YhoA26wi.js} +718 -119
- package/dist/pi-YhoA26wi.js.map +1 -0
- package/dist/pi-foreign-artifacts-CNt6wQ1P.js +660 -0
- package/dist/pi-foreign-artifacts-CNt6wQ1P.js.map +1 -0
- 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-C13q-9w0.js → serve-DrHAX2Bh.js} +15 -14
- package/dist/{serve-C13q-9w0.js.map → serve-DrHAX2Bh.js.map} +1 -1
- package/dist/{server-setup-CptI7SUT.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-DioCGjM8.js → start-DvV3Lbwy.js} +5 -4
- package/dist/{start-DioCGjM8.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-B0EFY6l7.js.map +0 -1
- package/dist/pi-memory-bridge-Dvj1T3e3.js +0 -403
- package/dist/pi-memory-bridge-Dvj1T3e3.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-CptI7SUT.js.map +0 -1
- package/dist/service-backend-Cdgz6WPx.js.map +0 -1
|
@@ -0,0 +1,660 @@
|
|
|
1
|
+
import { d as redactSecrets, f as splitFrontmatter, o as capBytes } from "./pi-memory-bridge-BxmCIIbk.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
// src/lib/pi-foreign-artifacts.ts
|
|
6
|
+
/**
|
|
7
|
+
* Bridge the INHERITED artifact directories — Claude Code's `.claude/` /
|
|
8
|
+
* `~/.claude/` and Copilot's `.github/` / `~/.copilot/` — into a
|
|
9
|
+
* `github-router pi` launch.
|
|
10
|
+
*
|
|
11
|
+
* Three namespaces, three different failure modes, one rule set:
|
|
12
|
+
*
|
|
13
|
+
* | namespace | same-name outcome in Pi | reported? |
|
|
14
|
+
* |-----------------|-----------------------------------------------|-----------|
|
|
15
|
+
* | agent registry | `mergeRuntimeAgents` throws, EVERY `subagent` | yes |
|
|
16
|
+
* | | call in the process fails until it is removed | |
|
|
17
|
+
* | `skills/*` | the other `SKILL.md` is overwritten in place | **no** |
|
|
18
|
+
* | `prompts/*.md` | the other file is overwritten in place | **no** |
|
|
19
|
+
*
|
|
20
|
+
* So the planner reserves names BEFORE anything is written, and the rule
|
|
21
|
+
* differs by namespace on purpose:
|
|
22
|
+
*
|
|
23
|
+
* - **agents**: a name the router itself already ships (its roster, the
|
|
24
|
+
* pi-subagents builtins, the read-only CLI adapters) means the role
|
|
25
|
+
* already exists — the foreign definition is **skipped and reported**.
|
|
26
|
+
* Two agents with one purpose in one catalog is the ambiguity that
|
|
27
|
+
* produces wrong delegations, and a registry identity is not the only
|
|
28
|
+
* carrier of the content (the skill and prompt are).
|
|
29
|
+
* - **skills and prompts**: the file IS the only carrier, so they are
|
|
30
|
+
* **renamed, never skipped** — `gh-oracle` → `gh-oracle-2`,
|
|
31
|
+
* `review.md` → `review-2.md`.
|
|
32
|
+
*
|
|
33
|
+
* Renaming happens for anything else that is taken, deterministically:
|
|
34
|
+
* agents become `<slug>-<scope>` (then `-2`, `-3`…), skills and prompts
|
|
35
|
+
* become `<slug>-2` (then `-3`…). No source prefix — a prefix is not a
|
|
36
|
+
* namespace (it walks straight into the builtin `claude-code` /
|
|
37
|
+
* `claude-code-writer`) and it renames artifacts the user recognises for no
|
|
38
|
+
* safety gain, since the reservation is what makes collisions unreachable.
|
|
39
|
+
*
|
|
40
|
+
* Foreign `model:` and `aliases:` are never emitted. The model would be a
|
|
41
|
+
* Copilot slug that `isUnavailableSubagentModel` refuses (so every run of
|
|
42
|
+
* that agent fails), and an alias is another registry identity that can
|
|
43
|
+
* collide invisibly. Every bridged agent therefore runs on the launch's
|
|
44
|
+
* lead model. `tools:` is dropped from the frontmatter and folded into the
|
|
45
|
+
* body as prose, because an unresolvable entry in pi-subagents' strict
|
|
46
|
+
* allowlist hard-fails the child.
|
|
47
|
+
*
|
|
48
|
+
* Nothing here imports pi-subagents or Pi: the router owns one rule and
|
|
49
|
+
* reads the same frontmatter the loaders read, so a version bump upstream
|
|
50
|
+
* cannot silently move a name out from under it.
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* Every name pi-subagents reserves for itself — `BUILTIN_AGENT_NAMES` from
|
|
54
|
+
* the installed package plus the live alias map, the read-only CLI adapters,
|
|
55
|
+
* and the router's own roster.
|
|
56
|
+
*
|
|
57
|
+
* Cannot be imported: pi-subagents is an installed Pi extension, never a
|
|
58
|
+
* router dependency (bundling its internals would couple the launcher to a
|
|
59
|
+
* version it does not pin). LAST_VERIFIED against pi-subagents 0.88.0:
|
|
60
|
+
* `src/agents/builtin-names.js` for the 13 names, and a live `snapshot.all`
|
|
61
|
+
* for the aliases (`oracle → advisor`,
|
|
62
|
+
* `worker → developer, coder, implementer, develop`; every other builtin
|
|
63
|
+
* carries none).
|
|
64
|
+
*
|
|
65
|
+
* Drift here is not a correctness hole: the extension's `tool_result` net
|
|
66
|
+
* unregisters anything the registry rejects at merge time. It is a
|
|
67
|
+
* friendliness hole (a foreign agent skipped needlessly), which is why this
|
|
68
|
+
* list is commented rather than guessed.
|
|
69
|
+
*/
|
|
70
|
+
const PI_FOREIGN_ROUTER_OWNED_AGENTS = Object.freeze([
|
|
71
|
+
"advisor",
|
|
72
|
+
"claude-code",
|
|
73
|
+
"claude-code-writer",
|
|
74
|
+
"codex-exec",
|
|
75
|
+
"codex-exec-writer",
|
|
76
|
+
"cursor-agent",
|
|
77
|
+
"cursor-agent-writer",
|
|
78
|
+
"delegate",
|
|
79
|
+
"evidence-auditor",
|
|
80
|
+
"oracle",
|
|
81
|
+
"researcher",
|
|
82
|
+
"reviewer",
|
|
83
|
+
"scout",
|
|
84
|
+
"worker",
|
|
85
|
+
"developer",
|
|
86
|
+
"coder",
|
|
87
|
+
"implementer",
|
|
88
|
+
"develop"
|
|
89
|
+
]);
|
|
90
|
+
/**
|
|
91
|
+
* The router's own agent roster is NOT in the constant above: it depends on
|
|
92
|
+
* the launch (`buildPiAgentFiles` writes Explore / General-Purpose / reviewer /
|
|
93
|
+
* oracle / advisor, and `--no-peers` writes none), so `buildReservedNames`
|
|
94
|
+
* takes it as `emittedAgents` instead. A hardcoded copy here would skip a
|
|
95
|
+
* foreign `Explore` on a peerless launch that publishes no such role.
|
|
96
|
+
*/
|
|
97
|
+
/** Foreign artifact roots. Project + user, Claude + Copilot. */
|
|
98
|
+
const SKILL_ROOTS_PROJECT = [".claude/skills", ".github/skills"];
|
|
99
|
+
const SKILL_ROOTS_USER = [".claude/skills", ".copilot/skills"];
|
|
100
|
+
const AGENT_ROOTS_PROJECT = [".claude/agents", ".github/agents"];
|
|
101
|
+
const AGENT_ROOTS_USER = [".claude/agents", ".copilot/agents"];
|
|
102
|
+
const PROMPT_ROOTS_PROJECT = [".claude/commands", ".github/prompts"];
|
|
103
|
+
const PROMPT_ROOTS_USER = [".claude/commands"];
|
|
104
|
+
/** Pi's own artifact roots in the mirror / repo / home, for reservation. */
|
|
105
|
+
const PI_SKILL_ROOTS_REL = [
|
|
106
|
+
"skills",
|
|
107
|
+
".pi/skills",
|
|
108
|
+
".agents/skills"
|
|
109
|
+
];
|
|
110
|
+
const PI_PROMPT_ROOTS_REL = ["prompts", ".pi/prompts"];
|
|
111
|
+
const PI_AGENT_ROOTS_REL = [
|
|
112
|
+
"agents",
|
|
113
|
+
".pi/agents",
|
|
114
|
+
".agents"
|
|
115
|
+
];
|
|
116
|
+
/** Caps. Pi refuses a skill without a description (`core/skills.js:252`). */
|
|
117
|
+
const MAX_FOREIGN_AGENT_BODY_BYTES = 8192;
|
|
118
|
+
const MAX_FOREIGN_DESCRIPTION_CHARS = 200;
|
|
119
|
+
const MAX_FOREIGN_SKILL_DESCRIPTION_CHARS = 1e3;
|
|
120
|
+
const MAX_FOREIGN_INDEX_BYTES = 4096;
|
|
121
|
+
/** Mirrors Pi's own limits so a bridged file can never be rejected. */
|
|
122
|
+
const MAX_SKILL_NAME_CHARS = 64;
|
|
123
|
+
function lower(s) {
|
|
124
|
+
return s.trim().toLowerCase();
|
|
125
|
+
}
|
|
126
|
+
/** Collapse to a legal Pi/prompt path segment and registry name. */
|
|
127
|
+
function piForeignSlug(raw) {
|
|
128
|
+
const slug = String(raw ?? "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
129
|
+
const trimmed = slug.length > MAX_SKILL_NAME_CHARS ? slug.slice(0, MAX_SKILL_NAME_CHARS).replace(/-+$/, "") : slug;
|
|
130
|
+
return trimmed.length > 0 ? trimmed : "foreign";
|
|
131
|
+
}
|
|
132
|
+
function collapseLine(raw) {
|
|
133
|
+
return raw.replace(/\s+/g, " ").trim();
|
|
134
|
+
}
|
|
135
|
+
function truncateChars(raw, max) {
|
|
136
|
+
if (raw.length <= max) return raw;
|
|
137
|
+
return `${raw.slice(0, Math.max(0, max - 1)).trimEnd()}…`;
|
|
138
|
+
}
|
|
139
|
+
/** YAML-ish frontmatter read: `key: value` on one line, quotes stripped. */
|
|
140
|
+
function frontmatterValue(frontmatter, key) {
|
|
141
|
+
const match = new RegExp(`^${key}\\s*:\\s*(.*)$`, "im").exec(frontmatter);
|
|
142
|
+
if (!match) return void 0;
|
|
143
|
+
const value = match[1].trim().replace(/^["']/, "").replace(/["']$/, "").trim();
|
|
144
|
+
return value.length > 0 ? value : void 0;
|
|
145
|
+
}
|
|
146
|
+
/** Space- and comma-separated list value (`tools: read, grep, bash`). */
|
|
147
|
+
function frontmatterList(frontmatter, key) {
|
|
148
|
+
const raw = frontmatterValue(frontmatter, key);
|
|
149
|
+
if (!raw) return [];
|
|
150
|
+
return raw.replace(/^\[/, "").replace(/\]$/, "").split(/[,\s]+/).map((s) => s.trim()).filter((s) => s.length > 0);
|
|
151
|
+
}
|
|
152
|
+
async function readIfExists(file) {
|
|
153
|
+
try {
|
|
154
|
+
return await fs.readFile(file, "utf8");
|
|
155
|
+
} catch {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async function isDirectory(dir) {
|
|
160
|
+
try {
|
|
161
|
+
return (await fs.stat(dir)).isDirectory();
|
|
162
|
+
} catch {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async function listDir(dir) {
|
|
167
|
+
try {
|
|
168
|
+
return (await fs.readdir(dir)).sort();
|
|
169
|
+
} catch {
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** Repo root: walk up for `.git`, else the given cwd. Never throws. */
|
|
174
|
+
async function piForeignRepoRoot(cwd) {
|
|
175
|
+
let dir = path.resolve(cwd);
|
|
176
|
+
for (let depth = 0; depth < 12; depth++) try {
|
|
177
|
+
await fs.stat(path.join(dir, ".git"));
|
|
178
|
+
return dir;
|
|
179
|
+
} catch {
|
|
180
|
+
const parent = path.dirname(dir);
|
|
181
|
+
if (parent === dir) break;
|
|
182
|
+
dir = parent;
|
|
183
|
+
}
|
|
184
|
+
return cwd;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Which product an artifact came from, from its path alone.
|
|
188
|
+
*
|
|
189
|
+
* Normalized to forward slashes first: the roots above are POSIX literals, so
|
|
190
|
+
* a Windows path (`\.github\.`) would otherwise match nothing and every
|
|
191
|
+
* artifact would be labelled Claude. The label reaches the index and the
|
|
192
|
+
* provenance line, i.e. the model's view of where an agent came from.
|
|
193
|
+
*/
|
|
194
|
+
function piForeignSourceOf(file) {
|
|
195
|
+
const posix = file.replace(/\\/g, "/");
|
|
196
|
+
return posix.includes("/.github/") || posix.includes("/.copilot/") ? "copilot" : "claude";
|
|
197
|
+
}
|
|
198
|
+
function provenancePath(file, repoRoot, homeDir) {
|
|
199
|
+
const rel = (base, prefix) => {
|
|
200
|
+
const out = path.relative(base, file);
|
|
201
|
+
return out.length > 0 && !out.startsWith("..") ? `${prefix}${out.split(path.sep).join("/")}` : void 0;
|
|
202
|
+
};
|
|
203
|
+
return rel(repoRoot, "") ?? rel(homeDir, "~/") ?? path.basename(file);
|
|
204
|
+
}
|
|
205
|
+
/** Every `<dir>/*.md` under an agent root (flat — that is all Pi scans). */
|
|
206
|
+
async function agentIdentityKeys(root) {
|
|
207
|
+
const keys = [];
|
|
208
|
+
for (const name of await listDir(root)) {
|
|
209
|
+
if (!name.endsWith(".md")) continue;
|
|
210
|
+
const stem = name.replace(/\.agent\.md$/, "").replace(/\.md$/, "");
|
|
211
|
+
const raw = await readIfExists(path.join(root, name));
|
|
212
|
+
if (raw === void 0) continue;
|
|
213
|
+
const { frontmatter } = splitFrontmatter(raw);
|
|
214
|
+
const authored = frontmatterValue(frontmatter, "name") ?? stem;
|
|
215
|
+
keys.push(authored, stem);
|
|
216
|
+
for (const key of [
|
|
217
|
+
"aliases",
|
|
218
|
+
"alias",
|
|
219
|
+
"localName"
|
|
220
|
+
]) keys.push(...frontmatterList(frontmatter, key));
|
|
221
|
+
}
|
|
222
|
+
return keys;
|
|
223
|
+
}
|
|
224
|
+
async function skillNamesUnder(root) {
|
|
225
|
+
const names = [];
|
|
226
|
+
for (const entry of await listDir(root)) {
|
|
227
|
+
if (entry.startsWith(".")) continue;
|
|
228
|
+
const dir = path.join(root, entry);
|
|
229
|
+
if (await isDirectory(dir)) {
|
|
230
|
+
names.push(entry);
|
|
231
|
+
const raw = await readIfExists(path.join(dir, "SKILL.md"));
|
|
232
|
+
if (raw !== void 0) {
|
|
233
|
+
const named = frontmatterValue(splitFrontmatter(raw).frontmatter, "name");
|
|
234
|
+
if (named) names.push(named);
|
|
235
|
+
}
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if (entry.endsWith(".md")) {
|
|
239
|
+
const stem = entry.replace(/\.md$/, "");
|
|
240
|
+
names.push(stem);
|
|
241
|
+
const raw = await readIfExists(path.join(root, entry));
|
|
242
|
+
if (raw !== void 0) {
|
|
243
|
+
const named = frontmatterValue(splitFrontmatter(raw).frontmatter, "name");
|
|
244
|
+
if (named) names.push(named);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return names;
|
|
249
|
+
}
|
|
250
|
+
async function promptNamesUnder(root) {
|
|
251
|
+
const names = [];
|
|
252
|
+
for (const entry of await listDir(root)) {
|
|
253
|
+
const full = path.join(root, entry);
|
|
254
|
+
if (await isDirectory(full)) {
|
|
255
|
+
names.push(...await promptNamesUnder(full));
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (entry.endsWith(".md")) names.push(entry.replace(/\.md$/, ""));
|
|
259
|
+
}
|
|
260
|
+
return names;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Build the four reservation sets.
|
|
264
|
+
*
|
|
265
|
+
* `emittedSkills` / `emittedPrompts` are the names THIS launch is about to
|
|
266
|
+
* write, so a foreign artifact can never land on top of one the router just
|
|
267
|
+
* created in the same process (the `<mirror>/` scan would see a stale copy
|
|
268
|
+
* from the previous launch, not this one).
|
|
269
|
+
*/
|
|
270
|
+
async function buildReservedNames(opts) {
|
|
271
|
+
const routerOwnedAgents = new Set(PI_FOREIGN_ROUTER_OWNED_AGENTS.map(lower));
|
|
272
|
+
for (const name of opts.emittedAgents ?? []) routerOwnedAgents.add(lower(name));
|
|
273
|
+
const agents = /* @__PURE__ */ new Set();
|
|
274
|
+
const skills = /* @__PURE__ */ new Set();
|
|
275
|
+
const prompts = /* @__PURE__ */ new Set();
|
|
276
|
+
for (const root of [
|
|
277
|
+
path.join(opts.mirrorDir, PI_AGENT_ROOTS_REL[0]),
|
|
278
|
+
path.join(opts.repoRoot, PI_AGENT_ROOTS_REL[1]),
|
|
279
|
+
path.join(opts.repoRoot, PI_AGENT_ROOTS_REL[2]),
|
|
280
|
+
path.join(opts.homeDir, ".pi/agent/agents"),
|
|
281
|
+
path.join(opts.homeDir, ".agents")
|
|
282
|
+
]) for (const key of await agentIdentityKeys(root)) agents.add(lower(key));
|
|
283
|
+
for (const key of routerOwnedAgents) agents.add(key);
|
|
284
|
+
for (const root of [
|
|
285
|
+
path.join(opts.mirrorDir, PI_SKILL_ROOTS_REL[0]),
|
|
286
|
+
path.join(opts.repoRoot, PI_SKILL_ROOTS_REL[1]),
|
|
287
|
+
path.join(opts.repoRoot, PI_SKILL_ROOTS_REL[2]),
|
|
288
|
+
path.join(opts.homeDir, ".pi/agent/skills"),
|
|
289
|
+
path.join(opts.homeDir, ".agents/skills")
|
|
290
|
+
]) for (const name of await skillNamesUnder(root)) skills.add(lower(name));
|
|
291
|
+
for (const name of opts.emittedSkills ?? []) skills.add(lower(name));
|
|
292
|
+
for (const root of [path.join(opts.mirrorDir, PI_PROMPT_ROOTS_REL[0]), path.join(opts.repoRoot, PI_PROMPT_ROOTS_REL[1])]) for (const name of await promptNamesUnder(root)) prompts.add(lower(name));
|
|
293
|
+
for (const name of opts.emittedPrompts ?? []) prompts.add(lower(name));
|
|
294
|
+
return {
|
|
295
|
+
routerOwnedAgents,
|
|
296
|
+
agents,
|
|
297
|
+
skills,
|
|
298
|
+
prompts
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/** Deterministic suffix search shared by agents and skills/prompts. */
|
|
302
|
+
function claim(taken, base, suffixes) {
|
|
303
|
+
if (!taken.has(lower(base))) {
|
|
304
|
+
taken.add(lower(base));
|
|
305
|
+
return base;
|
|
306
|
+
}
|
|
307
|
+
for (const candidate of suffixes()) if (!taken.has(lower(candidate))) {
|
|
308
|
+
taken.add(lower(candidate));
|
|
309
|
+
return candidate;
|
|
310
|
+
}
|
|
311
|
+
return base;
|
|
312
|
+
}
|
|
313
|
+
function* scopeSuffixes(base, scope) {
|
|
314
|
+
yield `${base}-${scope}`;
|
|
315
|
+
for (let n = 2; n < 1e3; n++) yield `${base}-${scope}-${n}`;
|
|
316
|
+
}
|
|
317
|
+
function* ordinals(base) {
|
|
318
|
+
for (let n = 2; n < 1e3; n++) yield `${base}-${n}`;
|
|
319
|
+
}
|
|
320
|
+
async function collectAgentFiles(roots) {
|
|
321
|
+
const out = [];
|
|
322
|
+
for (const { dir, scope } of roots) for (const entry of await listDir(dir)) {
|
|
323
|
+
if (!entry.endsWith(".md")) continue;
|
|
324
|
+
out.push({
|
|
325
|
+
file: path.join(dir, entry),
|
|
326
|
+
scope
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
return byScopeThenPath(out);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Scope is the FIRST sort key, not the root order.
|
|
333
|
+
*
|
|
334
|
+
* The two roots per scope (`.claude/…`, `.github/…`) are visited in a fixed
|
|
335
|
+
* order, but `readdir` order is filesystem-dependent and the plan's suffixes
|
|
336
|
+
* (`writer` vs `writer-user`) are assigned first-come. A project artifact must
|
|
337
|
+
* win its authored name over a user artifact of the same name on every machine,
|
|
338
|
+
* so the ordering is stated here rather than inherited from the walk.
|
|
339
|
+
*/
|
|
340
|
+
function byScopeThenPath(rows) {
|
|
341
|
+
return rows.sort((a, b) => {
|
|
342
|
+
if (a.scope !== b.scope) return a.scope === "project" ? -1 : 1;
|
|
343
|
+
return a.file < b.file ? -1 : a.file > b.file ? 1 : 0;
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
async function collectSkillFiles(roots) {
|
|
347
|
+
const out = [];
|
|
348
|
+
for (const { dir, scope } of roots) for (const entry of await listDir(dir)) {
|
|
349
|
+
if (entry.startsWith(".")) continue;
|
|
350
|
+
const full = path.join(dir, entry);
|
|
351
|
+
if (await isDirectory(full)) {
|
|
352
|
+
const skillFile = path.join(full, "SKILL.md");
|
|
353
|
+
const raw = await readIfExists(skillFile);
|
|
354
|
+
if (raw === void 0) continue;
|
|
355
|
+
out.push({
|
|
356
|
+
file: skillFile,
|
|
357
|
+
scope,
|
|
358
|
+
name: frontmatterValue(splitFrontmatter(raw).frontmatter, "name") ?? entry
|
|
359
|
+
});
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (entry.endsWith(".md")) {
|
|
363
|
+
const raw = await readIfExists(full);
|
|
364
|
+
if (raw === void 0) continue;
|
|
365
|
+
out.push({
|
|
366
|
+
file: full,
|
|
367
|
+
scope,
|
|
368
|
+
name: frontmatterValue(splitFrontmatter(raw).frontmatter, "name") ?? entry.replace(/\.md$/, "")
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return byScopeThenPath(out);
|
|
373
|
+
}
|
|
374
|
+
async function collectPromptFiles(roots) {
|
|
375
|
+
const out = [];
|
|
376
|
+
const walk = async (dir, scope, prefix) => {
|
|
377
|
+
for (const entry of await listDir(dir)) {
|
|
378
|
+
if (entry.startsWith(".")) continue;
|
|
379
|
+
const full = path.join(dir, entry);
|
|
380
|
+
if (await isDirectory(full)) {
|
|
381
|
+
await walk(full, scope, `${prefix}${entry}-`);
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (!entry.endsWith(".md")) continue;
|
|
385
|
+
const stem = entry.replace(/\.prompt\.md$/, "").replace(/\.md$/, "");
|
|
386
|
+
out.push({
|
|
387
|
+
file: full,
|
|
388
|
+
scope,
|
|
389
|
+
name: `${prefix}${stem}`
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
for (const { dir, scope } of roots) await walk(dir, scope, "");
|
|
394
|
+
return byScopeThenPath(out);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Build the bridge plan. Pure over the filesystem: reads the foreign roots
|
|
398
|
+
* and the reservation sets, writes nothing.
|
|
399
|
+
*/
|
|
400
|
+
async function planForeignArtifacts(opts) {
|
|
401
|
+
const { repoRoot, homeDir, reservedNames: reserved } = opts;
|
|
402
|
+
const plan = {
|
|
403
|
+
skills: [],
|
|
404
|
+
prompts: [],
|
|
405
|
+
agents: [],
|
|
406
|
+
skipped: []
|
|
407
|
+
};
|
|
408
|
+
const skillNames = new Set(reserved.skills);
|
|
409
|
+
const promptNames = new Set(reserved.prompts);
|
|
410
|
+
const agentNames = new Set(reserved.agents);
|
|
411
|
+
const skillFiles = await collectSkillFiles([...SKILL_ROOTS_PROJECT.map((rel) => ({
|
|
412
|
+
dir: path.join(repoRoot, rel),
|
|
413
|
+
scope: "project"
|
|
414
|
+
})), ...SKILL_ROOTS_USER.map((rel) => ({
|
|
415
|
+
dir: path.join(homeDir, rel),
|
|
416
|
+
scope: "user"
|
|
417
|
+
}))]);
|
|
418
|
+
for (const { file, name } of skillFiles) {
|
|
419
|
+
const raw = await readIfExists(file);
|
|
420
|
+
if (raw === void 0) continue;
|
|
421
|
+
const shown = provenancePath(file, repoRoot, homeDir);
|
|
422
|
+
const { frontmatter, body } = splitFrontmatter(raw);
|
|
423
|
+
const description = collapseLine(frontmatterValue(frontmatter, "description") ?? "");
|
|
424
|
+
if (!description) {
|
|
425
|
+
plan.skipped.push({
|
|
426
|
+
name,
|
|
427
|
+
file: shown,
|
|
428
|
+
reason: "skill has no description (Pi requires one)"
|
|
429
|
+
});
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
const authored = piForeignSlug(name);
|
|
433
|
+
const finalName = claim(skillNames, authored, () => ordinals(authored));
|
|
434
|
+
const allowed = frontmatterList(frontmatter, "allowed-tools");
|
|
435
|
+
plan.skills.push({
|
|
436
|
+
name: finalName,
|
|
437
|
+
...finalName === authored ? {} : { renamedFrom: name },
|
|
438
|
+
content: `${buildSkillFrontmatter(description)}\n${buildArtifactBody({
|
|
439
|
+
body,
|
|
440
|
+
source: piForeignSourceOf(file),
|
|
441
|
+
shown,
|
|
442
|
+
allowed
|
|
443
|
+
})}`
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
const promptFiles = await collectPromptFiles([...PROMPT_ROOTS_PROJECT.map((rel) => ({
|
|
447
|
+
dir: path.join(repoRoot, rel),
|
|
448
|
+
scope: "project"
|
|
449
|
+
})), ...PROMPT_ROOTS_USER.map((rel) => ({
|
|
450
|
+
dir: path.join(homeDir, rel),
|
|
451
|
+
scope: "user"
|
|
452
|
+
}))]);
|
|
453
|
+
for (const { file, name } of promptFiles) {
|
|
454
|
+
const raw = await readIfExists(file);
|
|
455
|
+
if (raw === void 0) continue;
|
|
456
|
+
const shown = provenancePath(file, repoRoot, homeDir);
|
|
457
|
+
const authored = piForeignSlug(name);
|
|
458
|
+
const finalName = claim(promptNames, authored, () => ordinals(authored));
|
|
459
|
+
const { body } = splitFrontmatter(raw);
|
|
460
|
+
plan.prompts.push({
|
|
461
|
+
name: finalName,
|
|
462
|
+
...finalName === authored ? {} : { renamedFrom: name },
|
|
463
|
+
content: `${buildArtifactBody({
|
|
464
|
+
body,
|
|
465
|
+
source: piForeignSourceOf(file),
|
|
466
|
+
shown,
|
|
467
|
+
allowed: []
|
|
468
|
+
})}\n`
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
const agentFiles = await collectAgentFiles([...AGENT_ROOTS_PROJECT.map((rel) => ({
|
|
472
|
+
dir: path.join(repoRoot, rel),
|
|
473
|
+
scope: "project"
|
|
474
|
+
})), ...AGENT_ROOTS_USER.map((rel) => ({
|
|
475
|
+
dir: path.join(homeDir, rel),
|
|
476
|
+
scope: "user"
|
|
477
|
+
}))]);
|
|
478
|
+
const seenBodies = /* @__PURE__ */ new Set();
|
|
479
|
+
for (const { file, scope } of agentFiles) {
|
|
480
|
+
const raw = await readIfExists(file);
|
|
481
|
+
if (raw === void 0) continue;
|
|
482
|
+
const shown = provenancePath(file, repoRoot, homeDir);
|
|
483
|
+
const stem = path.basename(file).replace(/\.agent\.md$/, "").replace(/\.md$/, "");
|
|
484
|
+
const { frontmatter, body } = splitFrontmatter(raw);
|
|
485
|
+
const originalName = frontmatterValue(frontmatter, "name") ?? stem;
|
|
486
|
+
const description = collapseLine(frontmatterValue(frontmatter, "description") ?? "");
|
|
487
|
+
if (!description) {
|
|
488
|
+
plan.skipped.push({
|
|
489
|
+
name: originalName,
|
|
490
|
+
file: shown,
|
|
491
|
+
reason: "no description in frontmatter (not a usable agent definition)"
|
|
492
|
+
});
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
const authored = piForeignSlug(originalName);
|
|
496
|
+
if (reserved.routerOwnedAgents.has(lower(originalName))) {
|
|
497
|
+
plan.skipped.push({
|
|
498
|
+
name: originalName,
|
|
499
|
+
file: shown,
|
|
500
|
+
reason: "name is owned by gh-router or a pi-subagents builtin (that role already exists)"
|
|
501
|
+
});
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
const hash = `${authored}\u0000${body}`;
|
|
505
|
+
if (seenBodies.has(hash)) {
|
|
506
|
+
plan.skipped.push({
|
|
507
|
+
name: originalName,
|
|
508
|
+
file: shown,
|
|
509
|
+
reason: "duplicate of an identical definition already bridged from another emitted path"
|
|
510
|
+
});
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
seenBodies.add(hash);
|
|
514
|
+
const finalName = claim(agentNames, authored, () => scopeSuffixes(authored, scope));
|
|
515
|
+
const tools = frontmatterList(frontmatter, "tools");
|
|
516
|
+
plan.agents.push({
|
|
517
|
+
name: finalName,
|
|
518
|
+
originalName,
|
|
519
|
+
description: truncateChars(description, MAX_FOREIGN_DESCRIPTION_CHARS),
|
|
520
|
+
body: capBytes(buildArtifactBody({
|
|
521
|
+
body,
|
|
522
|
+
source: piForeignSourceOf(file),
|
|
523
|
+
shown,
|
|
524
|
+
allowed: tools
|
|
525
|
+
}), MAX_FOREIGN_AGENT_BODY_BYTES, "gh-router foreign-agent bridge").text.trim(),
|
|
526
|
+
source: piForeignSourceOf(file),
|
|
527
|
+
scope,
|
|
528
|
+
file: shown,
|
|
529
|
+
...finalName === authored ? {} : { renamedFrom: originalName }
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
return plan;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Frontmatter for a bridged skill.
|
|
536
|
+
*
|
|
537
|
+
* The `name:` key is deliberately ABSENT: Pi resolves a skill's name from the
|
|
538
|
+
* frontmatter when present and from the parent directory otherwise
|
|
539
|
+
* (`core/skills.js:245`), so dropping it lets the directory we just wrote
|
|
540
|
+
* decide. Keeping the authored `name: gh-oracle` inside `gh-oracle-2/SKILL.md`
|
|
541
|
+
* makes BOTH copies load as `gh-oracle` and the foreign one loses as a
|
|
542
|
+
* `collision` diagnostic — a silent loss.
|
|
543
|
+
*/
|
|
544
|
+
function buildSkillFrontmatter(description) {
|
|
545
|
+
return `---\ndescription: ${truncateChars(description, MAX_FOREIGN_SKILL_DESCRIPTION_CHARS).replace(/\r?\n/g, " ")}\n---\n`;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* The shared body shape for bridged artifacts: a provenance line (so the
|
|
549
|
+
* origin is visible where it runs, not only where it was written), the
|
|
550
|
+
* original tool policy as prose (Pi cannot enforce a foreign allowlist, and an
|
|
551
|
+
* unresolvable entry would hard-fail the child), then the authored body.
|
|
552
|
+
*
|
|
553
|
+
* The body is secret-redacted on the way through: a foreign agent or command is
|
|
554
|
+
* user-authored prose that has never been through the router, and copying it
|
|
555
|
+
* into a launch mirror verbatim would move any token pasted into it into a
|
|
556
|
+
* second file tree.
|
|
557
|
+
*/
|
|
558
|
+
function buildArtifactBody(opts) {
|
|
559
|
+
const provenance = `> Bridged by github-router from ${opts.source === "copilot" ? "Copilot" : "Claude"} \`${opts.shown}\`.`;
|
|
560
|
+
const policy = opts.allowed.length > 0 ? `> Authored tool policy (advisory in Pi): ${opts.allowed.join(", ")}.` : void 0;
|
|
561
|
+
const trimmed = redactSecrets(opts.body).replace(/^\n+/, "");
|
|
562
|
+
return [
|
|
563
|
+
provenance,
|
|
564
|
+
...policy ? [policy] : [],
|
|
565
|
+
"",
|
|
566
|
+
trimmed
|
|
567
|
+
].join("\n");
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* The one index the model sees. Deliberately a compact list, not the bodies:
|
|
571
|
+
* runtime agents are never advertised (`advertised-agent-prompt.js`), and
|
|
572
|
+
* spending the 16-entry / 12 KiB catalog on foreign agents would crowd out
|
|
573
|
+
* the router's own roster. The model calls
|
|
574
|
+
* `subagent({action:"list", options:{search:"…"}})` for full descriptions.
|
|
575
|
+
*/
|
|
576
|
+
function buildForeignAgentIndex(agents, opts = {}) {
|
|
577
|
+
if (agents.length === 0) return "";
|
|
578
|
+
const maxBytes = opts.maxBytes ?? MAX_FOREIGN_INDEX_BYTES;
|
|
579
|
+
const header = [
|
|
580
|
+
"Agents bridged from .claude / .github / ~/.copilot. They are NOT preloaded:",
|
|
581
|
+
"call subagent({action:\"list\", options:{search:\"<term>\"}}) for full descriptions,",
|
|
582
|
+
"then subagent({agent:\"<name>\", task:\"…\"}). They run on this profile's lead model."
|
|
583
|
+
];
|
|
584
|
+
const rows = agents.map((a) => `- ${a.name} [${a.source}, ${a.scope}] — ${a.description}`);
|
|
585
|
+
const included = [];
|
|
586
|
+
let bytes = Buffer.byteLength([...header, ...included].join("\n"), "utf8");
|
|
587
|
+
for (const row of rows) {
|
|
588
|
+
const size = Buffer.byteLength(`${row}\n`, "utf8");
|
|
589
|
+
if (bytes + size > maxBytes) break;
|
|
590
|
+
included.push(row);
|
|
591
|
+
bytes += size;
|
|
592
|
+
}
|
|
593
|
+
const omitted = rows.length - included.length;
|
|
594
|
+
const tail = omitted > 0 ? [`+${omitted} more; {action:"list", options:{search:"<term>"}}`] : [];
|
|
595
|
+
return [
|
|
596
|
+
...header,
|
|
597
|
+
...included,
|
|
598
|
+
...tail
|
|
599
|
+
].join("\n");
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Write the plan's skills and prompts into the mirror.
|
|
603
|
+
*
|
|
604
|
+
* `overwritten` counts a target that already existed. It must be `0` on every
|
|
605
|
+
* launch — the reservation is what guarantees it — and the launcher warns when
|
|
606
|
+
* it is not, which is the tripwire for the silent-clobber failure this whole
|
|
607
|
+
* module exists to prevent. Agents are NOT written: they are registry entries.
|
|
608
|
+
*/
|
|
609
|
+
async function writeForeignArtifacts(mirrorDir, plan) {
|
|
610
|
+
let skills = 0;
|
|
611
|
+
let prompts = 0;
|
|
612
|
+
let overwritten = 0;
|
|
613
|
+
const write = async (file, content) => {
|
|
614
|
+
if (await readIfExists(file) !== void 0) overwritten += 1;
|
|
615
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
616
|
+
await fs.writeFile(file, content, "utf8");
|
|
617
|
+
};
|
|
618
|
+
for (const skill of plan.skills) {
|
|
619
|
+
await write(path.join(mirrorDir, "skills", skill.name, "SKILL.md"), skill.content);
|
|
620
|
+
skills += 1;
|
|
621
|
+
}
|
|
622
|
+
for (const prompt of plan.prompts) {
|
|
623
|
+
await write(path.join(mirrorDir, "prompts", `${prompt.name}.md`), prompt.content);
|
|
624
|
+
prompts += 1;
|
|
625
|
+
}
|
|
626
|
+
return {
|
|
627
|
+
skills,
|
|
628
|
+
prompts,
|
|
629
|
+
overwritten
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Count the foreign AGENT definitions a `--foreign` launch would consider.
|
|
634
|
+
*
|
|
635
|
+
* Exists so a launch without the flag can still say the artifacts are there:
|
|
636
|
+
* the bridge is invisible by design, and a user who has `.github/agents/` has
|
|
637
|
+
* no other way to learn the flag exists. Deliberately a `readdir` count rather
|
|
638
|
+
* than a plan — no reservations, no body reads, and it must stay cheap because
|
|
639
|
+
* it runs on every non-`--foreign` launch.
|
|
640
|
+
*
|
|
641
|
+
* Counts **stems**, not files, because first-mate dual-emits every role into
|
|
642
|
+
* `.github/agents` AND `.claude/agents` with byte-identical bodies: a file
|
|
643
|
+
* count would report 16 where the user has 8 roles, which reads like the bridge
|
|
644
|
+
* found something it did not.
|
|
645
|
+
*/
|
|
646
|
+
async function countForeignAgentFiles(opts) {
|
|
647
|
+
const stems = /* @__PURE__ */ new Set();
|
|
648
|
+
for (const root of [...AGENT_ROOTS_PROJECT.map((rel) => path.join(opts.repoRoot, rel)), ...AGENT_ROOTS_USER.map((rel) => path.join(opts.homeDir, rel))]) for (const entry of await listDir(root)) {
|
|
649
|
+
if (!entry.endsWith(".md")) continue;
|
|
650
|
+
stems.add(entry.replace(/\.agent\.md$/, "").replace(/\.md$/, ""));
|
|
651
|
+
}
|
|
652
|
+
return stems.size;
|
|
653
|
+
}
|
|
654
|
+
/** Default home dir for the planner (separate seam so tests stay hermetic). */
|
|
655
|
+
function piForeignHomeDir() {
|
|
656
|
+
return os.homedir();
|
|
657
|
+
}
|
|
658
|
+
export { buildForeignAgentIndex, buildReservedNames, countForeignAgentFiles, piForeignHomeDir, piForeignRepoRoot, planForeignArtifacts, writeForeignArtifacts };
|
|
659
|
+
|
|
660
|
+
//# sourceMappingURL=pi-foreign-artifacts-CNt6wQ1P.js.map
|