github-router 0.3.343 → 0.3.345
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 +13 -8
- package/dist/{aic-ledger-D4fmThbS.js → aic-ledger-D4oMcg7c.js} +24 -2
- package/dist/aic-ledger-D4oMcg7c.js.map +1 -0
- package/dist/{attribution-settings-DJEBjfJQ.js → attribution-settings-B7i9EI_k.js} +4 -4
- package/dist/{attribution-settings-DJEBjfJQ.js.map → attribution-settings-B7i9EI_k.js.map} +1 -1
- package/dist/{auth-DjKEIiqG.js → auth-Cgsy2T0s.js} +2 -2
- package/dist/{auth-DjKEIiqG.js.map → auth-Cgsy2T0s.js.map} +1 -1
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/{check-usage-B7UrDwD8.js → check-usage-26G2hw_F.js} +3 -3
- package/dist/{check-usage-B7UrDwD8.js.map → check-usage-26G2hw_F.js.map} +1 -1
- package/dist/{claude-DJeYKVL2.js → claude-CqAnTpZv.js} +9 -9
- package/dist/{claude-DJeYKVL2.js.map → claude-CqAnTpZv.js.map} +1 -1
- package/dist/{codex-cUYAC32x.js → codex-DVTp1CuU.js} +5 -5
- package/dist/{codex-cUYAC32x.js.map → codex-DVTp1CuU.js.map} +1 -1
- package/dist/{copilot-discount-yDaMQob0.js → copilot-discount-CilBhKQW.js} +2 -2
- package/dist/{copilot-discount-yDaMQob0.js.map → copilot-discount-CilBhKQW.js.map} +1 -1
- package/dist/engine-PexAztE4.js +2 -0
- package/dist/{gate-discovery-BIBgN6mA.js → gate-discovery-TC3k4dr1.js} +2 -2
- package/dist/{gate-discovery-BIBgN6mA.js.map → gate-discovery-TC3k4dr1.js.map} +1 -1
- package/dist/{get-copilot-usage-CGaV01dC.js → get-copilot-usage-C_6ast5h.js} +2 -2
- package/dist/{get-copilot-usage-CGaV01dC.js.map → get-copilot-usage-C_6ast5h.js.map} +1 -1
- package/dist/hooks.mjs +92 -0
- package/dist/hooks.sha256 +1 -1
- package/dist/{internal-aic-status-BmXhfpTS.js → internal-aic-status-CCvU7zhC.js} +3 -3
- package/dist/{internal-aic-status-BmXhfpTS.js.map → internal-aic-status-CCvU7zhC.js.map} +1 -1
- package/dist/{internal-stop-hook-Dyn0fRpZ.js → internal-stop-hook-BjdKy6On.js} +2 -2
- package/dist/{internal-stop-hook-Dyn0fRpZ.js.map → internal-stop-hook-BjdKy6On.js.map} +1 -1
- package/dist/main.js +10 -10
- package/dist/{models-68HDOEPK.js → models-BGCeGVXl.js} +2 -2
- package/dist/{models-68HDOEPK.js.map → models-BGCeGVXl.js.map} +1 -1
- package/dist/{peer-mcp-personas-Dt0VRKYz.js → peer-mcp-personas-CIV3aDP6.js} +13 -5
- package/dist/peer-mcp-personas-CIV3aDP6.js.map +1 -0
- package/dist/{pi-CnsdJGF0.js → pi-DJM02Mm2.js} +530 -95
- package/dist/pi-DJM02Mm2.js.map +1 -0
- package/dist/{provision-D_aHUCXt.js → provision-J68elA3c.js} +2 -2
- package/dist/{provision-D_aHUCXt.js.map → provision-J68elA3c.js.map} +1 -1
- package/dist/{serve-CwaKseAj.js → serve-CCjPimSJ.js} +6 -6
- package/dist/{serve-CwaKseAj.js.map → serve-CCjPimSJ.js.map} +1 -1
- package/dist/{server-setup-CtzSW7Ms.js → server-setup-BO-kzlt0.js} +27 -11
- package/dist/server-setup-BO-kzlt0.js.map +1 -0
- package/dist/{start-DqfQyqxD.js → start-B_ikqtvL.js} +3 -3
- package/dist/{start-DqfQyqxD.js.map → start-B_ikqtvL.js.map} +1 -1
- package/dist/state-CVp30CBF.js.map +1 -1
- package/dist/{token-DATA_OQK.js → token-s5Wd-Kwr.js} +2 -1
- package/dist/{token-DATA_OQK.js.map → token-s5Wd-Kwr.js.map} +1 -1
- package/package.json +2 -2
- package/dist/aic-ledger-D4fmThbS.js.map +0 -1
- package/dist/engine-DvGukHty.js +0 -2
- package/dist/peer-mcp-personas-Dt0VRKYz.js.map +0 -1
- package/dist/pi-CnsdJGF0.js.map +0 -1
- package/dist/server-setup-CtzSW7Ms.js.map +0 -1
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import { I as withInstallLock, N as warmTreeSitterPool } from "./service-backend-7SPDLUB9.js";
|
|
2
|
+
import { t as getPackageVersion } from "./version-C8x2hQrZ.js";
|
|
3
|
+
import { t as PATHS } from "./paths-CpbTHKeP.js";
|
|
2
4
|
import { t as state } from "./state-CVp30CBF.js";
|
|
3
5
|
import { c as runCommandVoid, o as resolveExecutable, s as runCommandCapture } from "./exec-MCU1H-KZ.js";
|
|
4
|
-
import { E as formatBalancedPrerequisiteFailure, I as validateCheapestProfilePrerequisites, M as resolveLaunchProfile, N as validateBalancedProfilePrerequisites, a as setupAndServe, c as startKeepAwake, f as enableFileLogging, i as parseSharedArgs, j as profileDescriptor, k as formatCheapestPrerequisiteFailure, l as stopKeepAwake, o as sharedServerArgs, r as getPiLaunchEnvVars, z as
|
|
6
|
+
import { B as runSelfUpdate, E as formatBalancedPrerequisiteFailure, I as validateCheapestProfilePrerequisites, M as resolveLaunchProfile, N as validateBalancedProfilePrerequisites, a as setupAndServe, c as startKeepAwake, f as enableFileLogging, i as parseSharedArgs, j as profileDescriptor, k as formatCheapestPrerequisiteFailure, l as stopKeepAwake, o as sharedServerArgs, r as getPiLaunchEnvVars, z as queueDetachedGlobalInstall } from "./server-setup-BO-kzlt0.js";
|
|
5
7
|
import { a as BALANCED_PROFILE_NATIVE_EFFORTS, c as BALANCED_PROFILE_ORACLE_MODEL, r as BALANCED_PROFILE_MODELS, s as BALANCED_PROFILE_ORACLE_EFFORT } from "./balanced-profile-contract-C6AgFJNp.js";
|
|
6
|
-
import { D as toolbeltEnabled, Gt as registerLaunch, In as CHEAPEST_PROFILE_NATIVE_EFFORTS, Kt as unregisterLaunch, Mn as CHEAPEST_PROFILE_ADVISOR_EFFORT, Nn as CHEAPEST_PROFILE_ADVISOR_MODEL, Pn as CHEAPEST_PROFILE_MODELS, Rn as CHEAPEST_PROFILE_ORACLE_EFFORT, an as provisionAndIndexColbert, ft as browserToolsEnabled, in as colbertDegradedWarning, nn as provisionBrowserAssets, zn as CHEAPEST_PROFILE_ORACLE_MODEL } from "./peer-mcp-personas-
|
|
8
|
+
import { D as toolbeltEnabled, Gt as registerLaunch, In as CHEAPEST_PROFILE_NATIVE_EFFORTS, Kt as unregisterLaunch, Mn as CHEAPEST_PROFILE_ADVISOR_EFFORT, Nn as CHEAPEST_PROFILE_ADVISOR_MODEL, Pn as CHEAPEST_PROFILE_MODELS, Rn as CHEAPEST_PROFILE_ORACLE_EFFORT, an as provisionAndIndexColbert, ft as browserToolsEnabled, in as colbertDegradedWarning, nn as provisionBrowserAssets, zn as CHEAPEST_PROFILE_ORACLE_MODEL } from "./peer-mcp-personas-CIV3aDP6.js";
|
|
7
9
|
import { r as resolveSelfInvocation } from "./self-invocation-DIUyoRgL.js";
|
|
8
|
-
import { i as launchChild, t as provisionToolbelt } from "./provision-
|
|
9
|
-
import { d as sweepStaleAicLedgerFiles, t as aicLedgerPath } from "./aic-ledger-
|
|
10
|
+
import { i as launchChild, t as provisionToolbelt } from "./provision-J68elA3c.js";
|
|
11
|
+
import { d as sweepStaleAicLedgerFiles, n as aicSnapshot, o as formatAicExitSummary, t as aicLedgerPath, u as removeAicLedgerFile } from "./aic-ledger-D4oMcg7c.js";
|
|
10
12
|
import { i as buildAicStatusHookCommand, n as AIC_STATUSLINE_DISABLE_ENV, t as AIC_LEDGER_ENV } from "./aic-statusline-settings-YoDG20pq.js";
|
|
13
|
+
import { n as formatDiscountedCostTable, t as discountedUsdForSnapshot } from "./copilot-discount-CilBhKQW.js";
|
|
11
14
|
import { defineCommand } from "citty";
|
|
12
15
|
import consola from "consola";
|
|
16
|
+
import { existsSync } from "node:fs";
|
|
13
17
|
import path from "node:path";
|
|
14
18
|
import { randomBytes } from "node:crypto";
|
|
15
|
-
import fs from "node:fs/promises";
|
|
19
|
+
import fs$1 from "node:fs/promises";
|
|
16
20
|
import os from "node:os";
|
|
17
21
|
import process$1 from "node:process";
|
|
18
22
|
//#region src/lib/pi-version-check.ts
|
|
19
23
|
const PI_NPM_PACKAGE = "@earendil-works/pi-coding-agent";
|
|
20
24
|
/** Minimum Pi version the `pi` launcher supports. */
|
|
21
|
-
const PI_MIN_VERSION = "0.
|
|
25
|
+
const PI_MIN_VERSION = "0.87.1";
|
|
22
26
|
const THROTTLE_HOURS = 1;
|
|
23
27
|
const NPM_VIEW_TIMEOUT_MS = 5e3;
|
|
24
28
|
const PI_VERSION_TIMEOUT_MS = 3e3;
|
|
@@ -29,7 +33,7 @@ function cacheFilePath() {
|
|
|
29
33
|
}
|
|
30
34
|
async function readCache() {
|
|
31
35
|
try {
|
|
32
|
-
const raw = await fs.readFile(cacheFilePath(), "utf8");
|
|
36
|
+
const raw = await fs$1.readFile(cacheFilePath(), "utf8");
|
|
33
37
|
const parsed = JSON.parse(raw);
|
|
34
38
|
if (typeof parsed.checkedAt !== "string" || parsed.installedVersion !== null && typeof parsed.installedVersion !== "string" || parsed.latestVersion !== null && typeof parsed.latestVersion !== "string") return null;
|
|
35
39
|
return parsed;
|
|
@@ -39,8 +43,8 @@ async function readCache() {
|
|
|
39
43
|
}
|
|
40
44
|
async function writeCache(cache) {
|
|
41
45
|
try {
|
|
42
|
-
await fs.mkdir(path.dirname(cacheFilePath()), { recursive: true });
|
|
43
|
-
await fs.writeFile(cacheFilePath(), JSON.stringify(cache), { mode: 384 });
|
|
46
|
+
await fs$1.mkdir(path.dirname(cacheFilePath()), { recursive: true });
|
|
47
|
+
await fs$1.writeFile(cacheFilePath(), JSON.stringify(cache), { mode: 384 });
|
|
44
48
|
} catch (err) {
|
|
45
49
|
consola.debug("Failed to write pi version-check cache:", err);
|
|
46
50
|
}
|
|
@@ -171,20 +175,77 @@ async function checkPiVersion(opts = {}) {
|
|
|
171
175
|
}
|
|
172
176
|
/**
|
|
173
177
|
* Install (or upgrade) Pi from npm under the cross-process install lock.
|
|
174
|
-
*
|
|
175
|
-
*
|
|
178
|
+
* Returns `true` when this call performed the install, `false` when
|
|
179
|
+
* another process holds the lock (caller skips — its install will land
|
|
180
|
+
* for a later launch). Best-effort: throws on failure; callers fall
|
|
181
|
+
* back to the installed version with a visible warning rather than
|
|
182
|
+
* stranding the launch.
|
|
176
183
|
*/
|
|
177
|
-
|
|
184
|
+
function updatePi(version, opts = {}) {
|
|
178
185
|
const npmPath = resolveExecutable("npm");
|
|
179
186
|
if (!npmPath) throw new Error("npm not found on PATH; cannot install Pi automatically");
|
|
180
|
-
|
|
187
|
+
return withInstallLock("pi-install.lock", async () => {
|
|
181
188
|
consola.info(`Installing ${PI_NPM_PACKAGE}@${version}...`);
|
|
182
189
|
await runCommandVoid([
|
|
183
190
|
npmPath,
|
|
184
191
|
"install",
|
|
185
192
|
"-g",
|
|
186
193
|
`${PI_NPM_PACKAGE}@${version}`
|
|
187
|
-
], {
|
|
194
|
+
], {
|
|
195
|
+
timeoutMs: NPM_INSTALL_TIMEOUT_MS,
|
|
196
|
+
signal: opts.signal
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Blocking fresh install for when Pi is absent entirely. Installs
|
|
202
|
+
* `@latest`, then force re-checks; throws when Pi still is not on PATH
|
|
203
|
+
* (caller exits with the install command). Only used when there is no
|
|
204
|
+
* usable Pi at all — the healthy path never blocks on npm.
|
|
205
|
+
*/
|
|
206
|
+
async function ensurePiInstalled(opts = {}) {
|
|
207
|
+
const acquired = await updatePi("latest", opts);
|
|
208
|
+
const retry = await checkPiVersion({ force: true });
|
|
209
|
+
if (retry.installed && retry.installedVersion) return retry.installedVersion;
|
|
210
|
+
throw new Error(acquired ? "install did not place pi on PATH" : "another Pi install is already running; retry in a moment");
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Fire-and-forget freshness refresh for a healthy Pi install. Never
|
|
214
|
+
* blocks launch and never throws: on the throttled schedule it probes
|
|
215
|
+
* npm for a newer Pi and, when one exists, queues a DETACHED post-exit
|
|
216
|
+
* install (same pattern as the proxy self-update) so neither startup
|
|
217
|
+
* nor the running session nor shutdown ever waits on npm. The
|
|
218
|
+
* cross-process install lock serializes against concurrent launches;
|
|
219
|
+
* every failure degrades to a debug log.
|
|
220
|
+
*
|
|
221
|
+
* Deliberately never touches a below-floor install: the floor is
|
|
222
|
+
* enforced foreground by the launcher (fail-closed), and a background
|
|
223
|
+
* task must not change what the running session validated.
|
|
224
|
+
*/
|
|
225
|
+
function refreshPiInBackground(opts) {
|
|
226
|
+
if (!opts.autoUpdate) return;
|
|
227
|
+
(async () => {
|
|
228
|
+
try {
|
|
229
|
+
if (!shouldCheckNow(await readCache())) return;
|
|
230
|
+
const installedVersion = await getInstalledPiVersion();
|
|
231
|
+
if (!meetsPiMinVersion(installedVersion)) return;
|
|
232
|
+
const npmPath = resolveExecutable("npm");
|
|
233
|
+
const latestVersion = await getLatestPiVersion();
|
|
234
|
+
await writeCache({
|
|
235
|
+
checkedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
236
|
+
installedVersion,
|
|
237
|
+
latestVersion
|
|
238
|
+
});
|
|
239
|
+
if (!npmPath) return;
|
|
240
|
+
if (!latestVersion || !isPiNewer(installedVersion, latestVersion)) return;
|
|
241
|
+
if (await withInstallLock("pi-install.lock", async () => {
|
|
242
|
+
queueDetachedGlobalInstall(npmPath, `@earendil-works/pi-coding-agent@${latestVersion}`);
|
|
243
|
+
})) consola.info(`Pi ${installedVersion} → ${latestVersion} update queued; it takes effect on the next launch.`);
|
|
244
|
+
} catch (err) {
|
|
245
|
+
consola.debug("Background Pi refresh failed:", err);
|
|
246
|
+
}
|
|
247
|
+
})().catch((err) => {
|
|
248
|
+
consola.debug("Background Pi refresh failed:", err);
|
|
188
249
|
});
|
|
189
250
|
}
|
|
190
251
|
//#endregion
|
|
@@ -482,11 +543,11 @@ function piMirrorDir() {
|
|
|
482
543
|
*/
|
|
483
544
|
async function ensurePiAgentMirror() {
|
|
484
545
|
const mirror = piMirrorDir();
|
|
485
|
-
await fs.mkdir(mirror, { recursive: true });
|
|
546
|
+
await fs$1.mkdir(mirror, { recursive: true });
|
|
486
547
|
const source = userPiAgentDir();
|
|
487
548
|
let entries;
|
|
488
549
|
try {
|
|
489
|
-
entries = await fs.readdir(source);
|
|
550
|
+
entries = await fs$1.readdir(source);
|
|
490
551
|
} catch {
|
|
491
552
|
return mirror;
|
|
492
553
|
}
|
|
@@ -499,7 +560,7 @@ async function ensurePiAgentMirror() {
|
|
|
499
560
|
]);
|
|
500
561
|
await Promise.all(entries.filter((e) => !SKIP.has(e)).map(async (entry) => {
|
|
501
562
|
try {
|
|
502
|
-
await fs.cp(path.join(source, entry), path.join(mirror, entry), { recursive: true });
|
|
563
|
+
await fs$1.cp(path.join(source, entry), path.join(mirror, entry), { recursive: true });
|
|
503
564
|
} catch (err) {
|
|
504
565
|
consola.debug(`Pi mirror: skipping ${entry}:`, err);
|
|
505
566
|
}
|
|
@@ -509,7 +570,7 @@ async function ensurePiAgentMirror() {
|
|
|
509
570
|
/** Remove THIS launch's Pi mirror on shutdown. Best-effort, never throws. */
|
|
510
571
|
async function removeOwnPiAgentMirror() {
|
|
511
572
|
try {
|
|
512
|
-
await fs.rm(piMirrorDir(), {
|
|
573
|
+
await fs$1.rm(piMirrorDir(), {
|
|
513
574
|
recursive: true,
|
|
514
575
|
force: true
|
|
515
576
|
});
|
|
@@ -525,14 +586,14 @@ async function sweepStalePiAgentMirrors() {
|
|
|
525
586
|
const root = path.join(appDir(), "pi-mirrors");
|
|
526
587
|
let entries;
|
|
527
588
|
try {
|
|
528
|
-
entries = await fs.readdir(root);
|
|
589
|
+
entries = await fs$1.readdir(root);
|
|
529
590
|
} catch {
|
|
530
591
|
return;
|
|
531
592
|
}
|
|
532
593
|
await Promise.all(entries.map(async (entry) => {
|
|
533
594
|
const dir = path.join(root, entry);
|
|
534
595
|
try {
|
|
535
|
-
const stat = await fs.stat(dir);
|
|
596
|
+
const stat = await fs$1.stat(dir);
|
|
536
597
|
const ageMs = Date.now() - stat.mtimeMs;
|
|
537
598
|
const pidMatch = /^pi-agent-(\d+)-[0-9a-f]+$/.exec(entry);
|
|
538
599
|
let dead = ageMs > 864e5;
|
|
@@ -544,7 +605,7 @@ async function sweepStalePiAgentMirrors() {
|
|
|
544
605
|
dead = true;
|
|
545
606
|
}
|
|
546
607
|
}
|
|
547
|
-
if (dead) await fs.rm(dir, {
|
|
608
|
+
if (dead) await fs$1.rm(dir, {
|
|
548
609
|
recursive: true,
|
|
549
610
|
force: true
|
|
550
611
|
});
|
|
@@ -555,9 +616,36 @@ async function sweepStalePiAgentMirrors() {
|
|
|
555
616
|
}
|
|
556
617
|
//#endregion
|
|
557
618
|
//#region src/lib/pi-models-settings.ts
|
|
619
|
+
/**
|
|
620
|
+
* Pi thinking levels that can appear in `thinkingLevelMap`. `off` is
|
|
621
|
+
* omitted: it means "no reasoning" and is never mapped to a provider
|
|
622
|
+
* value.
|
|
623
|
+
*/
|
|
624
|
+
const PI_THINKING_LEVELS = [
|
|
625
|
+
"minimal",
|
|
626
|
+
"low",
|
|
627
|
+
"medium",
|
|
628
|
+
"high",
|
|
629
|
+
"xhigh",
|
|
630
|
+
"max"
|
|
631
|
+
];
|
|
632
|
+
/**
|
|
633
|
+
* Build a Pi `thinkingLevelMap` from a catalog `reasoning_effort`
|
|
634
|
+
* allowlist: supported levels map to themselves, unsupported to `null`
|
|
635
|
+
* (Pi hides them in `/thinking`). Returns `undefined` when the catalog
|
|
636
|
+
* carries no effort signal so Pi falls back to its own defaults rather
|
|
637
|
+
* than a guessed map.
|
|
638
|
+
*/
|
|
639
|
+
function piThinkingLevelMapFor(efforts) {
|
|
640
|
+
if (!efforts || efforts.length === 0) return void 0;
|
|
641
|
+
const set = new Set(efforts);
|
|
642
|
+
const map = {};
|
|
643
|
+
for (const level of PI_THINKING_LEVELS) map[level] = set.has(level) ? level : null;
|
|
644
|
+
return map;
|
|
645
|
+
}
|
|
558
646
|
/** Provider key used in models.json and agent `provider/model` references. */
|
|
559
647
|
const PI_PROVIDER_NAME = "gh-router";
|
|
560
|
-
const PI_MIN_VERSION_NOTE = "Requires Pi >= 0.
|
|
648
|
+
const PI_MIN_VERSION_NOTE = "Requires Pi >= 0.87.1 and Node >= 22.19.";
|
|
561
649
|
function piLeadModel(profileId) {
|
|
562
650
|
return profileId === "cheapest" ? CHEAPEST_PROFILE_MODELS.lead : BALANCED_PROFILE_MODELS.lead;
|
|
563
651
|
}
|
|
@@ -636,6 +724,51 @@ function piProfileModelIds(profileId, opts = {}) {
|
|
|
636
724
|
return [...ids];
|
|
637
725
|
}
|
|
638
726
|
/**
|
|
727
|
+
* Conservative per-model image resize Pi applies before sending.
|
|
728
|
+
* Docs-example values: 1568px, 512KiB encoded payload, JPEG quality 75.
|
|
729
|
+
* Well under Copilot's 3MiB decoded limit and ample for UI screenshots
|
|
730
|
+
* (measured ~35KB PNG), so sends stay fast and cheap. A model publishing
|
|
731
|
+
* a smaller `max_prompt_image_size` clamps `maxBytes` further via
|
|
732
|
+
* `piImageResizeFor` (encoded budget scaled from the decoded limit).
|
|
733
|
+
*/
|
|
734
|
+
const PI_IMAGE_RESIZE_MAX_WIDTH = 1568;
|
|
735
|
+
const PI_IMAGE_RESIZE_MAX_HEIGHT = 1568;
|
|
736
|
+
const PI_IMAGE_RESIZE_MAX_BYTES = 524288;
|
|
737
|
+
/**
|
|
738
|
+
* Derive the `inputLimits.images.resize` budget for a model row.
|
|
739
|
+
* Returns `undefined` for text-only models (explicit `vision === false`).
|
|
740
|
+
* Otherwise the conservative defaults, with `maxBytes` clamped to the
|
|
741
|
+
* decoded catalog limit scaled to encoded units when that limit is
|
|
742
|
+
* smaller than the default budget.
|
|
743
|
+
*/
|
|
744
|
+
function piImageResizeFor(vision, maxImageBytes) {
|
|
745
|
+
if (vision === false) return void 0;
|
|
746
|
+
let maxBytes = PI_IMAGE_RESIZE_MAX_BYTES;
|
|
747
|
+
if (typeof maxImageBytes === "number" && Number.isFinite(maxImageBytes) && maxImageBytes > 0) {
|
|
748
|
+
const scaled = Math.floor(maxImageBytes * 4 / 3);
|
|
749
|
+
if (scaled < maxBytes) maxBytes = Math.max(scaled, 1);
|
|
750
|
+
}
|
|
751
|
+
return { images: { resize: {
|
|
752
|
+
maxWidth: PI_IMAGE_RESIZE_MAX_WIDTH,
|
|
753
|
+
maxHeight: PI_IMAGE_RESIZE_MAX_HEIGHT,
|
|
754
|
+
maxBytes,
|
|
755
|
+
jpegQuality: 75
|
|
756
|
+
} } };
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* Derive a per-model Responses/Completions API from catalog endpoints.
|
|
760
|
+
* Returns `undefined` when the catalog carries no endpoint signal so the
|
|
761
|
+
* caller falls back to the provider default. A Responses-capable model
|
|
762
|
+
* stays on the provider default; a chat-only model overrides to
|
|
763
|
+
* completions.
|
|
764
|
+
*/
|
|
765
|
+
function piApiForEndpoints(endpoints) {
|
|
766
|
+
if (!endpoints || endpoints.length === 0) return void 0;
|
|
767
|
+
const lower = endpoints.map((e) => e.toLowerCase());
|
|
768
|
+
if (lower.some((e) => e.includes("responses"))) return "openai-responses";
|
|
769
|
+
if (lower.some((e) => e.includes("chat") || e.includes("completion"))) return "openai-completions";
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
639
772
|
* Fallback per-request output cap when the catalog carries no
|
|
640
773
|
* max_output_tokens. Matches the documented Luna/Grok 128K ceiling;
|
|
641
774
|
* the live catalog always wins. Never below the proxy's 16-token floor.
|
|
@@ -674,11 +807,23 @@ function piUsdCostFor(prices) {
|
|
|
674
807
|
* Responses-only on Copilot, and Pi POSTs `{baseUrl}/responses` for
|
|
675
808
|
* that API — i.e. our `/v1/responses`, the Codex-proven path. Sending
|
|
676
809
|
* these models to `/v1/chat/completions` is a Copilot 400 (observed).
|
|
810
|
+
* A model whose catalog endpoints lack Responses (future chat-served
|
|
811
|
+
* model) overrides per-model via `piApiForEndpoints`.
|
|
677
812
|
*
|
|
678
813
|
* Every row is BARE (no `[1m]`) with its cheap-tier window from
|
|
679
814
|
* `piContextWindowFor` (272K Luna/Sol, 200K Grok/unknown): Pi budgets
|
|
680
815
|
* `contextWindow` per model, so each role gets its cheapest tier and
|
|
681
816
|
* Long-tier (2x) pricing is structurally unreachable.
|
|
817
|
+
*
|
|
818
|
+
* Vision is fail-open: only an explicit catalog `vision === false`
|
|
819
|
+
* advertises `["text"]`; unknown models advertise `["text","image"]`
|
|
820
|
+
* so Pi's native image paths (@path/--file/paste/read) stay available
|
|
821
|
+
* and the proxy vision preflight (drop-with-note + learned upstream
|
|
822
|
+
* ceilings) remains the backstop. Vision rows also carry
|
|
823
|
+
* `inputLimits.images.resize` so Pi resizes before sending instead of
|
|
824
|
+
* paying a send-then-drop round trip, and `thinkingLevelMap` from the
|
|
825
|
+
* catalog `reasoning_effort` allowlist so Pi never offers an effort
|
|
826
|
+
* tier Copilot would 400.
|
|
682
827
|
*/
|
|
683
828
|
function buildPiModelsJson(opts) {
|
|
684
829
|
const baseUrl = `${opts.serverUrl.replace(/\/+$/, "")}/v1`;
|
|
@@ -692,15 +837,20 @@ function buildPiModelsJson(opts) {
|
|
|
692
837
|
const entry = opts.catalog?.find((m) => m.id === id);
|
|
693
838
|
const out = entry?.maxOutputTokens;
|
|
694
839
|
const maxTokens = typeof out === "number" && Number.isFinite(out) && out >= 16 ? Math.floor(out) : PI_MAX_TOKENS_FALLBACK;
|
|
695
|
-
const
|
|
840
|
+
const endpointApi = piApiForEndpoints(entry?.endpoints);
|
|
841
|
+
const override = opts.apiOverrides?.[id] ?? endpointApi;
|
|
842
|
+
const thinkingLevelMap = piThinkingLevelMapFor(entry?.efforts);
|
|
843
|
+
const inputLimits = piImageResizeFor(entry?.vision, entry?.maxImageBytes);
|
|
696
844
|
return {
|
|
697
845
|
id,
|
|
698
846
|
name: id,
|
|
699
847
|
reasoning: true,
|
|
700
|
-
input: ["text"],
|
|
848
|
+
input: entry?.vision === false ? ["text"] : ["text", "image"],
|
|
701
849
|
contextWindow: piContextWindowFor(id, entry?.maxContextTokens),
|
|
702
850
|
maxTokens,
|
|
703
851
|
...entry?.cost ? { cost: entry.cost } : {},
|
|
852
|
+
...thinkingLevelMap ? { thinkingLevelMap } : {},
|
|
853
|
+
...inputLimits ? { inputLimits } : {},
|
|
704
854
|
...override && override !== providerApi ? { api: override } : {}
|
|
705
855
|
};
|
|
706
856
|
})
|
|
@@ -750,6 +900,138 @@ function derivePiCompactionSettings(catalog, modelIds) {
|
|
|
750
900
|
};
|
|
751
901
|
}
|
|
752
902
|
/**
|
|
903
|
+
* Presentational settings keys that stay user-customizable. When the
|
|
904
|
+
* snapshotted user settings already define one of these, the user's
|
|
905
|
+
* value wins over the built default at launch-merge time (see
|
|
906
|
+
* `applyCosmeticUserOverrides`). Everything else the builder emits —
|
|
907
|
+
* models, tools, thinking levels, compaction, retry, packages — stays
|
|
908
|
+
* built-wins: those are the cost contract, not a preference.
|
|
909
|
+
*/
|
|
910
|
+
const PI_COSMETIC_SETTING_KEYS = [
|
|
911
|
+
"hideThinkingBlock",
|
|
912
|
+
"theme",
|
|
913
|
+
"themeAdaptive",
|
|
914
|
+
"groupToolCalls",
|
|
915
|
+
"readOutputMode",
|
|
916
|
+
"searchOutputMode",
|
|
917
|
+
"mcpOutputMode",
|
|
918
|
+
"bashOutputMode",
|
|
919
|
+
"toolBackground",
|
|
920
|
+
"terminal",
|
|
921
|
+
"images",
|
|
922
|
+
"markdown",
|
|
923
|
+
"collapseChangelog"
|
|
924
|
+
];
|
|
925
|
+
/**
|
|
926
|
+
* Overlay user-defined presentational values onto built settings.
|
|
927
|
+
* Only keys listed in `PI_COSMETIC_SETTING_KEYS` that are actually
|
|
928
|
+
* present (not `undefined`) in `userSettings` override — so a user
|
|
929
|
+
* `~/.pi/agent/settings.json` with e.g. `"hideThinkingBlock": false`
|
|
930
|
+
* or `"readOutputMode": "preview"` keeps their look, while everyone
|
|
931
|
+
* else gets the Claude-Code-like defaults. Returns the picked
|
|
932
|
+
* overrides (empty object when the user customized nothing).
|
|
933
|
+
*/
|
|
934
|
+
function applyCosmeticUserOverrides(userSettings, builtSettings) {
|
|
935
|
+
const overrides = {};
|
|
936
|
+
if (!userSettings) return overrides;
|
|
937
|
+
const built = builtSettings;
|
|
938
|
+
for (const key of PI_COSMETIC_SETTING_KEYS) {
|
|
939
|
+
if (!(key in userSettings)) continue;
|
|
940
|
+
const value = userSettings[key];
|
|
941
|
+
if (value === void 0) continue;
|
|
942
|
+
if (!(key in built)) continue;
|
|
943
|
+
overrides[key] = value;
|
|
944
|
+
}
|
|
945
|
+
return overrides;
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Helpful third-party bundle, wired extensions-only (skills/prompts/
|
|
949
|
+
* themes filtered out so third-party prose never reaches Ctrl+O — same
|
|
950
|
+
* policy as `pi-subagents`). Router-owned surfaces stay excluded:
|
|
951
|
+
* no statusline/footer package (built into `local:gh-router-pi`), no
|
|
952
|
+
* compaction replacers, no provider/model overriders.
|
|
953
|
+
*
|
|
954
|
+
* - `pi-mcp-adapter`: MCP servers as one proxy tool instead of hundreds
|
|
955
|
+
* of definitions (context/cost win).
|
|
956
|
+
* - `pi-web-access`: search/fetch/PDF-extract fallback. Only wired when
|
|
957
|
+
* the launch has neither `--search` nor `--browse`, otherwise it
|
|
958
|
+
* double-pays our ColBERT/browser surfaces.
|
|
959
|
+
* - `pi-agent-extensions`: allowlisted stable extensions only
|
|
960
|
+
* (sessions, structured questions, todos, handoff, context/files
|
|
961
|
+
* dashboards, notifications, analytics). `review`/`loop`/`workflow`/
|
|
962
|
+
* `control` overlap our delegate/review pipeline and `powerline-footer`
|
|
963
|
+
* would fight the router-owned AIC footer, so all are excluded.
|
|
964
|
+
*/
|
|
965
|
+
const PI_HELPERS_MCP_ADAPTER = {
|
|
966
|
+
source: "npm:pi-mcp-adapter",
|
|
967
|
+
skills: [],
|
|
968
|
+
prompts: []
|
|
969
|
+
};
|
|
970
|
+
const PI_HELPERS_WEB_ACCESS = {
|
|
971
|
+
source: "npm:pi-web-access",
|
|
972
|
+
skills: [],
|
|
973
|
+
prompts: []
|
|
974
|
+
};
|
|
975
|
+
/** Verified manifest paths (pi-agent-extensions 0.5.x). Bare relative
|
|
976
|
+
* form, NO `./` prefix: Pi matches package-filter patterns with
|
|
977
|
+
* minimatch against root-relative paths, and a `./` prefix matches
|
|
978
|
+
* nothing (observed live: zero extensions loaded, silent). */
|
|
979
|
+
const PI_HELPERS_AGENT_EXTENSIONS = {
|
|
980
|
+
source: "npm:pi-agent-extensions",
|
|
981
|
+
extensions: [
|
|
982
|
+
"extensions/sessions/index.ts",
|
|
983
|
+
"extensions/ask-user/index.ts",
|
|
984
|
+
"extensions/handoff/index.ts",
|
|
985
|
+
"extensions/notify/index.ts",
|
|
986
|
+
"extensions/context/index.ts",
|
|
987
|
+
"extensions/files/index.ts",
|
|
988
|
+
"extensions/todos/index.ts",
|
|
989
|
+
"extensions/answer/index.ts",
|
|
990
|
+
"extensions/cwd-history/index.ts",
|
|
991
|
+
"extensions/session-breakdown/index.ts"
|
|
992
|
+
],
|
|
993
|
+
skills: [],
|
|
994
|
+
prompts: [],
|
|
995
|
+
themes: []
|
|
996
|
+
};
|
|
997
|
+
/** Claude-look UI bundle: transcript grouping, Shiki diffs, Ctrl+O
|
|
998
|
+
* previews. Default-on (purely presentational — zero model cost);
|
|
999
|
+
* opt out with `--no-ui`. `pi-code` behaviors stay a docs recipe:
|
|
1000
|
+
* its `/memory` + `/context` commands would collide with the
|
|
1001
|
+
* router-owned pair in `gh-router-pi`, and Pi offers no per-command
|
|
1002
|
+
* filtering inside one extension. */
|
|
1003
|
+
const PI_UI_PACKAGES = Object.freeze(["npm:pi-claude-code-ui"]);
|
|
1004
|
+
/**
|
|
1005
|
+
* Claude Code dark theme (`#D77757` coral and friends) from
|
|
1006
|
+
* `better-claude-code-ui`, which ships six CC palettes. Themes-only:
|
|
1007
|
+
* extensions/skills/prompts are explicitly emptied so none of the
|
|
1008
|
+
* package's status line, footer, or tool rendering loads and fights
|
|
1009
|
+
* the router-owned footer or `pi-claude-code-ui`. Theme files are
|
|
1010
|
+
* pure JSON data — loading the whole `./theme` dir costs nothing at
|
|
1011
|
+
* runtime and leaves all six CC variants pickable via `/settings`,
|
|
1012
|
+
* with `claude-code-dark` the default (see `PI_CC_DARK_THEME`).
|
|
1013
|
+
*/
|
|
1014
|
+
const PI_CC_THEME_PACKAGE = {
|
|
1015
|
+
source: "npm:better-claude-code-ui",
|
|
1016
|
+
themes: ["theme/*.json"],
|
|
1017
|
+
extensions: [],
|
|
1018
|
+
skills: [],
|
|
1019
|
+
prompts: []
|
|
1020
|
+
};
|
|
1021
|
+
/** Default Pi theme: genuine Claude Code dark palette. */
|
|
1022
|
+
const PI_CC_DARK_THEME = "claude-code-dark";
|
|
1023
|
+
/** Built-in tools enabled at startup (Pi-native set incl. Windows). */
|
|
1024
|
+
const PI_DEFAULT_TOOLS = Object.freeze([
|
|
1025
|
+
"read",
|
|
1026
|
+
"bash",
|
|
1027
|
+
"powershell",
|
|
1028
|
+
"edit",
|
|
1029
|
+
"write",
|
|
1030
|
+
"grep",
|
|
1031
|
+
"find",
|
|
1032
|
+
"ls"
|
|
1033
|
+
]);
|
|
1034
|
+
/**
|
|
753
1035
|
* Build the per-launch `settings.json`. Additive over the snapshotted
|
|
754
1036
|
* user settings (the launcher merges lists it owns): narrow model
|
|
755
1037
|
* scope, fixed thinking, limited toolset, derived compaction, and the
|
|
@@ -758,6 +1040,11 @@ function derivePiCompactionSettings(catalog, modelIds) {
|
|
|
758
1040
|
* `pi-subagents` rides `peersEnabled` and loads extensions ONLY
|
|
759
1041
|
* (skills/prompts filtered out — the mode's own skills/prompts cover
|
|
760
1042
|
* the roster, so the third-party sets never reach Ctrl+O).
|
|
1043
|
+
* The helpful bundle rides `helpers` (default on, peers-gated):
|
|
1044
|
+
* `pi-mcp-adapter` + allowlisted `pi-agent-extensions` always, plus
|
|
1045
|
+
* `pi-web-access` only when neither search nor browse is on (otherwise
|
|
1046
|
+
* it double-pays our ColBERT/browser surfaces). The `--ui` bundle
|
|
1047
|
+
* (`pi-code`, `pi-claude-code-ui`) is opt-in.
|
|
761
1048
|
* The statusline footer is built into `local:gh-router-pi` (no
|
|
762
1049
|
* third-party statusline package: the community bridge reads only the
|
|
763
1050
|
* user's real global/project settings and never sees the launch mirror,
|
|
@@ -765,36 +1052,78 @@ function derivePiCompactionSettings(catalog, modelIds) {
|
|
|
765
1052
|
*/
|
|
766
1053
|
function buildPiSettingsJson(opts) {
|
|
767
1054
|
const peers = opts.peers !== false;
|
|
1055
|
+
const helpers = opts.helpers !== false && peers;
|
|
1056
|
+
const webAccess = helpers && !opts.searchEnabled && !opts.browseEnabled;
|
|
1057
|
+
const ui = opts.ui !== false;
|
|
768
1058
|
const modelIds = piProfileModelIds(opts.profileId, { peers });
|
|
1059
|
+
const modelThinkingLevels = {};
|
|
1060
|
+
modelThinkingLevels[`${PI_PROVIDER_NAME}/${piLeadModel(opts.profileId)}`] = piLeadThinking(opts.profileId);
|
|
1061
|
+
for (const role of piNativeRoles(opts.profileId)) modelThinkingLevels[`${PI_PROVIDER_NAME}/${role.model}`] = role.thinking;
|
|
1062
|
+
modelThinkingLevels[`${PI_PROVIDER_NAME}/${piOracleModel(opts.profileId)}`] = piOracleThinking(opts.profileId);
|
|
1063
|
+
const advisor = piAdvisorModel(opts.profileId);
|
|
1064
|
+
if (advisor) modelThinkingLevels[`${PI_PROVIDER_NAME}/${advisor.model}`] = advisor.thinking;
|
|
769
1065
|
return {
|
|
770
1066
|
defaultProvider: PI_PROVIDER_NAME,
|
|
771
1067
|
defaultModel: piLeadModel(opts.profileId),
|
|
772
1068
|
defaultThinkingLevel: piLeadThinking(opts.profileId),
|
|
773
1069
|
enabledModels: modelIds.map((id) => `${PI_PROVIDER_NAME}/${id}`),
|
|
774
|
-
defaultTools: [
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
1070
|
+
defaultTools: [...PI_DEFAULT_TOOLS],
|
|
1071
|
+
modelThinkingLevels,
|
|
1072
|
+
terminal: {
|
|
1073
|
+
showImages: true,
|
|
1074
|
+
imageWidthCells: 60,
|
|
1075
|
+
showTerminalProgress: true
|
|
1076
|
+
},
|
|
1077
|
+
markdown: { mermaid: "streaming" },
|
|
1078
|
+
collapseChangelog: true,
|
|
1079
|
+
images: {
|
|
1080
|
+
autoResize: true,
|
|
1081
|
+
blockImages: false
|
|
1082
|
+
},
|
|
1083
|
+
transport: "auto",
|
|
1084
|
+
hideThinkingBlock: true,
|
|
1085
|
+
...ui ? {
|
|
1086
|
+
themeAdaptive: false,
|
|
1087
|
+
groupToolCalls: true,
|
|
1088
|
+
readOutputMode: "summary",
|
|
1089
|
+
searchOutputMode: "count",
|
|
1090
|
+
mcpOutputMode: "summary",
|
|
1091
|
+
bashOutputMode: "summary",
|
|
1092
|
+
toolBackground: "transparent",
|
|
1093
|
+
theme: PI_CC_DARK_THEME
|
|
1094
|
+
} : {},
|
|
1095
|
+
branchSummary: {
|
|
1096
|
+
reserveTokens: 16384,
|
|
1097
|
+
skipPrompt: false
|
|
1098
|
+
},
|
|
783
1099
|
compaction: derivePiCompactionSettings(opts.catalog, modelIds),
|
|
784
1100
|
retry: {
|
|
785
1101
|
enabled: true,
|
|
786
|
-
maxRetries: 3
|
|
1102
|
+
maxRetries: 3,
|
|
1103
|
+
provider: { maxRetries: 0 }
|
|
787
1104
|
},
|
|
788
|
-
packages: [
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
1105
|
+
packages: [
|
|
1106
|
+
...peers ? [{
|
|
1107
|
+
source: "npm:pi-subagents",
|
|
1108
|
+
skills: [],
|
|
1109
|
+
prompts: []
|
|
1110
|
+
}] : [],
|
|
1111
|
+
...helpers ? [PI_HELPERS_MCP_ADAPTER, PI_HELPERS_AGENT_EXTENSIONS] : [],
|
|
1112
|
+
...webAccess ? [PI_HELPERS_WEB_ACCESS] : [],
|
|
1113
|
+
...ui ? [...PI_UI_PACKAGES, PI_CC_THEME_PACKAGE] : [],
|
|
1114
|
+
"local:gh-router-pi"
|
|
1115
|
+
],
|
|
793
1116
|
...peers ? { subagents: { agentOverrides: {
|
|
794
1117
|
scout: { disabled: true },
|
|
795
1118
|
worker: { disabled: true },
|
|
796
1119
|
researcher: { disabled: true },
|
|
797
|
-
"evidence-auditor": { disabled: true }
|
|
1120
|
+
"evidence-auditor": { disabled: true },
|
|
1121
|
+
"claude-code": { disabled: true },
|
|
1122
|
+
"claude-code-writer": { disabled: true },
|
|
1123
|
+
"codex-exec": { disabled: true },
|
|
1124
|
+
"codex-exec-writer": { disabled: true },
|
|
1125
|
+
"cursor-agent": { disabled: true },
|
|
1126
|
+
"cursor-agent-writer": { disabled: true }
|
|
798
1127
|
} } } : {}
|
|
799
1128
|
};
|
|
800
1129
|
}
|
|
@@ -844,11 +1173,19 @@ function roleDescription(profileId, role) {
|
|
|
844
1173
|
* is how the roster pins gh-router models/thinking for cost control.
|
|
845
1174
|
* The shadowed `advisor` alias dies with the builtin oracle definition,
|
|
846
1175
|
* which is why `advisor` ships as its own file on cheapest.
|
|
1176
|
+
* Shadowing deliberately does NOT inherit `contact_supervisor` on
|
|
1177
|
+
* reviewer (leaf) or `defaultContext: fork` on oracle (fresh keeps
|
|
1178
|
+
* the cold-start consultant contract).
|
|
847
1179
|
* - `allowedAgents` only narrows an existing nesting grant, so every
|
|
848
1180
|
* delegating agent also sets `allowNestedSubagents: true` and lists
|
|
849
1181
|
* `subagent` in `tools`. Depth reaches 3 on balanced
|
|
850
1182
|
* (lead → General-Purpose → reviewer → Explore), covered by
|
|
851
1183
|
* `PI_SUBAGENT_MAX_DEPTH=3` in the launch env (default guard is 2).
|
|
1184
|
+
* - `async: false` on every file: foreground children run in-process
|
|
1185
|
+
* with the parent's full tool registry. The detached background
|
|
1186
|
+
* runner demonstrably drops read/bash from its registry (observed
|
|
1187
|
+
* live as "requested unavailable child tools: [read, bash]"),
|
|
1188
|
+
* failing every strict-allowlist child it touches.
|
|
852
1189
|
* - Deliberately NO `output:`/`defaultReads`/`defaultProgress` file
|
|
853
1190
|
* bindings: single-shot launches resolve relative outputs under
|
|
854
1191
|
* per-run artifact dirs while `defaultReads` resolves against the
|
|
@@ -869,7 +1206,7 @@ function buildPiAgentFiles(profileId) {
|
|
|
869
1206
|
for (const role of piNativeRoles(profileId)) {
|
|
870
1207
|
const isImplementer = role.name === "General-Purpose";
|
|
871
1208
|
const isReviewer = role.name === "reviewer";
|
|
872
|
-
const tools = isImplementer ? "
|
|
1209
|
+
const tools = isImplementer ? "read, grep, find, ls, bash, edit, write, subagent, contact_supervisor" : isReviewer ? profileId === "balanced" ? "read, grep, find, ls, watchdog_diff, subagent" : "read, grep, find, ls, watchdog_diff" : "read, grep, find, ls, bash";
|
|
873
1210
|
const lines = [
|
|
874
1211
|
"---",
|
|
875
1212
|
`name: ${role.name}`,
|
|
@@ -878,6 +1215,7 @@ function buildPiAgentFiles(profileId) {
|
|
|
878
1215
|
`model: ${PI_PROVIDER_NAME}/${role.model}`,
|
|
879
1216
|
`thinking: ${role.thinking}`,
|
|
880
1217
|
"advertise: true",
|
|
1218
|
+
"async: false",
|
|
881
1219
|
"systemPromptMode: replace",
|
|
882
1220
|
"inheritProjectContext: true",
|
|
883
1221
|
"defaultContext: fresh"
|
|
@@ -895,10 +1233,11 @@ function buildPiAgentFiles(profileId) {
|
|
|
895
1233
|
"---",
|
|
896
1234
|
"name: oracle",
|
|
897
1235
|
"description: Second opinion before acting. Challenges assumptions without editing. Use when the decision itself feels risky.",
|
|
898
|
-
"tools:
|
|
1236
|
+
"tools: read, grep, find, ls, bash",
|
|
899
1237
|
`model: ${PI_PROVIDER_NAME}/${piOracleModel(profileId)}`,
|
|
900
1238
|
`thinking: ${piOracleThinking(profileId)}`,
|
|
901
1239
|
"advertise: true",
|
|
1240
|
+
"async: false",
|
|
902
1241
|
"systemPromptMode: replace",
|
|
903
1242
|
"inheritProjectContext: true",
|
|
904
1243
|
"defaultContext: fresh",
|
|
@@ -916,10 +1255,11 @@ function buildPiAgentFiles(profileId) {
|
|
|
916
1255
|
"---",
|
|
917
1256
|
"name: advisor",
|
|
918
1257
|
"description: Advisory plan review for the lead: review the final plan before it is presented. Never executes.",
|
|
919
|
-
"tools:
|
|
1258
|
+
"tools: read, grep, find, ls",
|
|
920
1259
|
`model: ${PI_PROVIDER_NAME}/${advisor.model}`,
|
|
921
1260
|
`thinking: ${advisor.thinking}`,
|
|
922
1261
|
"advertise: true",
|
|
1262
|
+
"async: false",
|
|
923
1263
|
"systemPromptMode: replace",
|
|
924
1264
|
"inheritProjectContext: true",
|
|
925
1265
|
"defaultContext: fresh",
|
|
@@ -934,6 +1274,32 @@ function buildPiAgentFiles(profileId) {
|
|
|
934
1274
|
return files;
|
|
935
1275
|
}
|
|
936
1276
|
/**
|
|
1277
|
+
* One elegant three-line launch summary for the `pi` preamble,
|
|
1278
|
+
* written directly to stderr (no reporter icons or timestamps).
|
|
1279
|
+
* Missing facts are omitted, never printed as blanks — a first run
|
|
1280
|
+
* that never resolved versions still renders cleanly.
|
|
1281
|
+
*/
|
|
1282
|
+
function buildPiLaunchCard(opts) {
|
|
1283
|
+
const surface = [];
|
|
1284
|
+
surface.push(opts.peers ? "peers" : "peerless");
|
|
1285
|
+
if (opts.peers && opts.helpers) surface.push("helpers");
|
|
1286
|
+
if (opts.ui) surface.push("ui");
|
|
1287
|
+
if (opts.swe) surface.push("swe");
|
|
1288
|
+
if (opts.search) surface.push("search");
|
|
1289
|
+
if (opts.browse) surface.push("browse");
|
|
1290
|
+
const identity = [
|
|
1291
|
+
opts.accountType,
|
|
1292
|
+
opts.login,
|
|
1293
|
+
opts.copilotVersion ? `copilot chat ${opts.copilotVersion}` : void 0,
|
|
1294
|
+
opts.vsCodeVersion ? `vscode ${opts.vsCodeVersion}` : void 0
|
|
1295
|
+
].filter((part) => typeof part === "string" && part.length > 0);
|
|
1296
|
+
return [
|
|
1297
|
+
`github-router v${opts.version} · pi (${opts.profileId})`,
|
|
1298
|
+
` ${identity.join(" · ")}`,
|
|
1299
|
+
` lead ${opts.lead} · ${opts.modelCount} models · ${surface.join(" ")} · ${opts.serverUrl}`
|
|
1300
|
+
].join("\n");
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
937
1303
|
* Short operating digest appended to APPEND_SYSTEM.md (prompt-cache-stable).
|
|
938
1304
|
* Mode identity — always injected. Peer consult sentences drop out under
|
|
939
1305
|
* `peers: false` so the digest never names tools that don't exist.
|
|
@@ -946,7 +1312,7 @@ function buildPiAppendSystem(profileId, opts = {}) {
|
|
|
946
1312
|
"",
|
|
947
1313
|
`- Lead owns planning directly; there is no Plan subagent.`
|
|
948
1314
|
];
|
|
949
|
-
if (peers) lines.push(`- Delegate FREELY to Explore for discovery and General-Purpose for scoped work.`, profileId === "balanced" ? `- Send work to reviewer ONLY when the change alters behavior.` : `- Send finished work to reviewer for assessment.`, `- Ask oracle for a second opinion when the decision itself feels risky.`, advisor ? `- Review the final plan with advisor (advisory) before presenting it.` : `- There is no advisor in this mode: oracle is the only consultant.`, `- Verify, don't vote: consultant verdicts never substitute for running the tests.`);
|
|
1315
|
+
if (peers) lines.push(`- Delegate FREELY to Explore for discovery and General-Purpose for scoped work.`, `- Call subagent directly (agent + task); save workflows for genuinely parallel fanout.`, profileId === "balanced" ? `- Send work to reviewer ONLY when the change alters behavior.` : `- Send finished work to reviewer for assessment.`, `- Ask oracle for a second opinion when the decision itself feels risky.`, advisor ? `- Review the final plan with advisor (advisory) before presenting it.` : `- There is no advisor in this mode: oracle is the only consultant.`, `- Verify, don't vote: consultant verdicts never substitute for running the tests.`, `- After any subagent work completes, always write the final answer yourself.`);
|
|
950
1316
|
else lines.push(`- Peerless launch: no subagents or consultants in this session; plan, implement, and verify directly.`);
|
|
951
1317
|
lines.push("", `(${PI_MIN_VERSION_NOTE})`, "");
|
|
952
1318
|
return lines.join("\n");
|
|
@@ -1454,6 +1820,11 @@ function buildPiSkills(opts) {
|
|
|
1454
1820
|
"into the `General-Purpose` brief to implement, `reviewer` to check,",
|
|
1455
1821
|
"`General-Purpose` to apply feedback. Keep delegated tasks",
|
|
1456
1822
|
"scoped with file:line evidence on return.",
|
|
1823
|
+
"Call `subagent` directly (agent + task). Reserve `workflowScript`",
|
|
1824
|
+
"workflows for genuinely parallel or scripted multi-step fanout —",
|
|
1825
|
+
"our agents run foreground and background runs add spawn overhead.",
|
|
1826
|
+
"After any subagent work completes, always write the final answer",
|
|
1827
|
+
"yourself; never end on tool output or completion notices alone.",
|
|
1457
1828
|
opts.profileId === "balanced" ? "Send work to reviewer ONLY when the change alters behavior." : "Send finished work to reviewer for assessment."
|
|
1458
1829
|
].join("\n")
|
|
1459
1830
|
});
|
|
@@ -1531,12 +1902,12 @@ const piArgs = {
|
|
|
1531
1902
|
"update-check": {
|
|
1532
1903
|
type: "boolean",
|
|
1533
1904
|
default: true,
|
|
1534
|
-
description: "
|
|
1905
|
+
description: "Verify Pi is installed and above the supported floor on launch (fast local probe), and refresh it in the background (throttled hourly). Set to false (--no-update-check) to skip both (offline/CI)."
|
|
1535
1906
|
},
|
|
1536
1907
|
"auto-update": {
|
|
1537
1908
|
type: "boolean",
|
|
1538
1909
|
default: true,
|
|
1539
|
-
description: "
|
|
1910
|
+
description: "Refresh Pi in the background (throttled hourly): probe npm and queue a post-exit install when newer, without delaying launch. Set to false (--no-auto-update) to disable background updates (the install floor is still enforced)."
|
|
1540
1911
|
},
|
|
1541
1912
|
swe: {
|
|
1542
1913
|
type: "boolean",
|
|
@@ -1548,6 +1919,16 @@ const piArgs = {
|
|
|
1548
1919
|
default: true,
|
|
1549
1920
|
description: "Wire the peer/subagent floor: native agent files, the oracle tool (plus cheapest-only advisor), the gh-oracle skill, and the pi-subagents package. Set to false (--no-peers) for a lead-only session; prereqs then validate the lead model only."
|
|
1550
1921
|
},
|
|
1922
|
+
helpers: {
|
|
1923
|
+
type: "boolean",
|
|
1924
|
+
default: true,
|
|
1925
|
+
description: "Wire the helpful bundle: pi-mcp-adapter, allowlisted pi-agent-extensions (sessions, ask_user, todos, handoff, context, files, analytics — no review/loop/footer), and pi-web-access when neither --search nor --browse is on. Set to false (--no-helpers) for pi-subagents + gh-router-pi only."
|
|
1926
|
+
},
|
|
1927
|
+
ui: {
|
|
1928
|
+
type: "boolean",
|
|
1929
|
+
default: true,
|
|
1930
|
+
description: "Load the Claude-look transcript UI (pi-claude-code-ui: grouped rows, Shiki diffs, Ctrl+O previews). Presentational only, zero model cost. Set to false (--no-ui) for stock Pi rendering."
|
|
1931
|
+
},
|
|
1551
1932
|
"memory-bridge": {
|
|
1552
1933
|
type: "boolean",
|
|
1553
1934
|
default: true,
|
|
@@ -1598,12 +1979,12 @@ function collectPiPassthroughArgs(rawArgs, argsDef) {
|
|
|
1598
1979
|
return forwarded;
|
|
1599
1980
|
}
|
|
1600
1981
|
async function writeJsonFile(file, value) {
|
|
1601
|
-
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
1602
|
-
await fs.writeFile(file, `${JSON.stringify(value, null, 2)}\n`, { mode: 384 });
|
|
1982
|
+
await fs$1.mkdir(path.dirname(file), { recursive: true });
|
|
1983
|
+
await fs$1.writeFile(file, `${JSON.stringify(value, null, 2)}\n`, { mode: 384 });
|
|
1603
1984
|
}
|
|
1604
1985
|
async function writeTextFile(file, content) {
|
|
1605
|
-
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
1606
|
-
await fs.writeFile(file, content, { mode: 384 });
|
|
1986
|
+
await fs$1.mkdir(path.dirname(file), { recursive: true });
|
|
1987
|
+
await fs$1.writeFile(file, content, { mode: 384 });
|
|
1607
1988
|
}
|
|
1608
1989
|
const pi = defineCommand({
|
|
1609
1990
|
meta: {
|
|
@@ -1626,51 +2007,76 @@ const pi = defineCommand({
|
|
|
1626
2007
|
const profileId = launchProfileId;
|
|
1627
2008
|
let server;
|
|
1628
2009
|
let serverUrl;
|
|
2010
|
+
const updateCheck = args["update-check"] !== false;
|
|
2011
|
+
const autoUpdate = args["auto-update"] !== false;
|
|
2012
|
+
let installedVersion = null;
|
|
2013
|
+
const pendingInstall = {
|
|
2014
|
+
promise: null,
|
|
2015
|
+
abort: null
|
|
2016
|
+
};
|
|
2017
|
+
if (updateCheck) {
|
|
2018
|
+
try {
|
|
2019
|
+
installedVersion = await getInstalledPiVersion();
|
|
2020
|
+
} catch (err) {
|
|
2021
|
+
consola.debug("Pi presence probe failed:", err);
|
|
2022
|
+
}
|
|
2023
|
+
if (installedVersion === null) {
|
|
2024
|
+
const controller = new AbortController();
|
|
2025
|
+
pendingInstall.abort = () => controller.abort();
|
|
2026
|
+
pendingInstall.promise = ensurePiInstalled({ signal: controller.signal });
|
|
2027
|
+
pendingInstall.promise.catch(() => {});
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
1629
2030
|
try {
|
|
1630
|
-
const
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
2031
|
+
const quietBoot = existsSync(PATHS.GITHUB_TOKEN_PATH) && !parsed.verbose && !parsed.showToken;
|
|
2032
|
+
const priorLevel = consola.level;
|
|
2033
|
+
if (quietBoot) consola.level = 1;
|
|
2034
|
+
let setupResult;
|
|
2035
|
+
try {
|
|
2036
|
+
setupResult = await setupAndServe({
|
|
2037
|
+
...parsed,
|
|
2038
|
+
port: parsed.port,
|
|
2039
|
+
silent: true
|
|
2040
|
+
});
|
|
2041
|
+
} finally {
|
|
2042
|
+
if (quietBoot) consola.level = priorLevel;
|
|
2043
|
+
}
|
|
2044
|
+
server = setupResult.server;
|
|
2045
|
+
serverUrl = setupResult.serverUrl;
|
|
1637
2046
|
} catch (error) {
|
|
2047
|
+
pendingInstall.abort?.();
|
|
1638
2048
|
consola.error("Failed to start server:", error instanceof Error ? error.message : error);
|
|
1639
2049
|
process$1.exit(1);
|
|
1640
2050
|
}
|
|
1641
2051
|
runSelfUpdate({ selfUpdate: args["self-update"] !== false });
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
2052
|
+
if (pendingInstall.promise) try {
|
|
2053
|
+
installedVersion = await pendingInstall.promise;
|
|
2054
|
+
} catch (err) {
|
|
2055
|
+
consola.error(`Pi is not installed and automatic install failed (${err instanceof Error ? err.message : String(err)}). Install it with \`npm install -g @earendil-works/pi-coding-agent\`, then retry.`);
|
|
2056
|
+
process$1.exit(1);
|
|
2057
|
+
} finally {
|
|
2058
|
+
pendingInstall.promise = null;
|
|
2059
|
+
pendingInstall.abort = null;
|
|
2060
|
+
}
|
|
2061
|
+
if (updateCheck && installedVersion !== null) if (!meetsPiMinVersion(installedVersion)) {
|
|
2062
|
+
if (autoUpdate) try {
|
|
1647
2063
|
await updatePi("latest");
|
|
1648
|
-
|
|
1649
|
-
} catch (err) {
|
|
1650
|
-
consola.error(`Pi is not installed and automatic install failed (${err instanceof Error ? err.message : String(err)}). Install it with \`npm install -g @earendil-works/pi-coding-agent\`, then retry.`);
|
|
1651
|
-
process$1.exit(1);
|
|
1652
|
-
}
|
|
1653
|
-
else if (check.needsMinUpgrade) if (autoUpdate && check.latestVersion) try {
|
|
1654
|
-
await updatePi(check.latestVersion);
|
|
2064
|
+
installedVersion = await getInstalledPiVersion();
|
|
1655
2065
|
} catch (err) {
|
|
1656
|
-
consola.error(`Installed Pi v${
|
|
2066
|
+
consola.error(`Installed Pi v${installedVersion} is below the supported floor and auto-upgrade failed (${err instanceof Error ? err.message : String(err)}). Upgrade manually: \`npm install -g @earendil-works/pi-coding-agent@latest\`.`);
|
|
1657
2067
|
process$1.exit(1);
|
|
1658
2068
|
}
|
|
1659
|
-
|
|
1660
|
-
consola.error(`Installed Pi v${
|
|
2069
|
+
if (!meetsPiMinVersion(installedVersion)) {
|
|
2070
|
+
consola.error(`Installed Pi v${installedVersion} is below the supported floor. Upgrade: \`npm install -g @earendil-works/pi-coding-agent@latest\`.`);
|
|
1661
2071
|
process$1.exit(1);
|
|
1662
2072
|
}
|
|
1663
|
-
|
|
1664
|
-
await updatePi(check.latestVersion);
|
|
1665
|
-
} catch (err) {
|
|
1666
|
-
consola.warn(`Auto-update of Pi to ${check.latestVersion} failed (${err instanceof Error ? err.message : String(err)}); continuing with installed v${check.installedVersion}.`);
|
|
1667
|
-
}
|
|
1668
|
-
else consola.warn(`Pi v${check.installedVersion} is installed; v${check.latestVersion} is available. Run with --auto-update (the default) to install on launch.`);
|
|
1669
|
-
} catch (err) {
|
|
1670
|
-
consola.debug("Pi version check failed:", err);
|
|
1671
|
-
}
|
|
2073
|
+
} else refreshPiInBackground({ autoUpdate });
|
|
1672
2074
|
const peersEnabled = args["peers"] !== false;
|
|
1673
2075
|
const sweEnabled = args["swe"] === true;
|
|
2076
|
+
const helpersEnabled = args["helpers"] !== false;
|
|
2077
|
+
const uiEnabled = args["ui"] !== false;
|
|
2078
|
+
const searchEnabled = parsed.searchEnabled || process$1.env.GH_ROUTER_ENABLE_SEMANTIC_SEARCH === "1";
|
|
2079
|
+
const browseEnabled = browserToolsEnabled();
|
|
1674
2080
|
const prereqCheck = profileId === "cheapest" ? validateCheapestProfilePrerequisites(state.models, { peers: peersEnabled }) : validateBalancedProfilePrerequisites(state.models, { peers: peersEnabled });
|
|
1675
2081
|
if (!prereqCheck.ok) {
|
|
1676
2082
|
const message = profileId === "cheapest" ? formatCheapestPrerequisiteFailure(prereqCheck.missing) : formatBalancedPrerequisiteFailure(prereqCheck.missing);
|
|
@@ -1688,8 +2094,6 @@ const pi = defineCommand({
|
|
|
1688
2094
|
}
|
|
1689
2095
|
enableFileLogging();
|
|
1690
2096
|
try {
|
|
1691
|
-
const searchEnabled = parsed.searchEnabled || process$1.env.GH_ROUTER_ENABLE_SEMANTIC_SEARCH === "1";
|
|
1692
|
-
const browseEnabled = browserToolsEnabled();
|
|
1693
2097
|
const catalog = state.models?.data.map((m) => {
|
|
1694
2098
|
const cost = piUsdCostFor(m.billing?.token_prices);
|
|
1695
2099
|
return {
|
|
@@ -1699,6 +2103,8 @@ const pi = defineCommand({
|
|
|
1699
2103
|
maxOutputTokens: m.capabilities?.limits?.max_output_tokens ?? 0,
|
|
1700
2104
|
efforts: m.capabilities?.supports?.reasoning_effort ?? [],
|
|
1701
2105
|
endpoints: m.supported_endpoints ?? [],
|
|
2106
|
+
vision: m.capabilities?.supports?.vision,
|
|
2107
|
+
maxImageBytes: m.capabilities?.limits?.vision?.max_prompt_image_size,
|
|
1702
2108
|
...cost ? { cost } : {}
|
|
1703
2109
|
};
|
|
1704
2110
|
});
|
|
@@ -1711,7 +2117,7 @@ const pi = defineCommand({
|
|
|
1711
2117
|
const settingsPath = path.join(mirror, "settings.json");
|
|
1712
2118
|
let userSettings = {};
|
|
1713
2119
|
try {
|
|
1714
|
-
const raw = await fs.readFile(settingsPath, "utf8");
|
|
2120
|
+
const raw = await fs$1.readFile(settingsPath, "utf8");
|
|
1715
2121
|
const parsedSettings = JSON.parse(raw);
|
|
1716
2122
|
if (parsedSettings && typeof parsedSettings === "object") userSettings = parsedSettings;
|
|
1717
2123
|
} catch {
|
|
@@ -1722,12 +2128,16 @@ const pi = defineCommand({
|
|
|
1722
2128
|
searchEnabled,
|
|
1723
2129
|
browseEnabled,
|
|
1724
2130
|
catalog,
|
|
1725
|
-
peers: peersEnabled
|
|
2131
|
+
peers: peersEnabled,
|
|
2132
|
+
helpers: helpersEnabled,
|
|
2133
|
+
ui: uiEnabled
|
|
1726
2134
|
});
|
|
1727
2135
|
const mergedSubagents = mergeSubagentsSettings(userSettings["subagents"], builtSettings.subagents);
|
|
2136
|
+
const cosmeticOverrides = applyCosmeticUserOverrides(userSettings, builtSettings);
|
|
1728
2137
|
await writeJsonFile(settingsPath, {
|
|
1729
2138
|
...userSettings,
|
|
1730
2139
|
...builtSettings,
|
|
2140
|
+
...cosmeticOverrides,
|
|
1731
2141
|
...mergedSubagents ? { subagents: mergedSubagents } : {}
|
|
1732
2142
|
});
|
|
1733
2143
|
const bridgeDisabled = args["memory-bridge"] === false || process$1.env.GH_ROUTER_PI_BRIDGE === "0" || process$1.env.GH_ROUTER_DISABLE_PI_BRIDGE === "1";
|
|
@@ -1784,7 +2194,7 @@ const pi = defineCommand({
|
|
|
1784
2194
|
const agentsPath = path.join(mirror, "AGENTS.md");
|
|
1785
2195
|
let existing;
|
|
1786
2196
|
try {
|
|
1787
|
-
existing = await fs.readFile(agentsPath, "utf8");
|
|
2197
|
+
existing = await fs$1.readFile(agentsPath, "utf8");
|
|
1788
2198
|
} catch {
|
|
1789
2199
|
existing = void 0;
|
|
1790
2200
|
}
|
|
@@ -1842,8 +2252,23 @@ const pi = defineCommand({
|
|
|
1842
2252
|
const extraArgs = collectPiPassthroughArgs(rawArgs, piArgs);
|
|
1843
2253
|
const lead = piLeadModel(profileId);
|
|
1844
2254
|
const modelIds = piProfileModelIds(profileId, { peers: peersEnabled });
|
|
1845
|
-
|
|
1846
|
-
|
|
2255
|
+
process$1.stderr.write(`${buildPiLaunchCard({
|
|
2256
|
+
version: getPackageVersion(),
|
|
2257
|
+
profileId,
|
|
2258
|
+
accountType: parsed.accountType,
|
|
2259
|
+
login: state.githubUserLogin,
|
|
2260
|
+
copilotVersion: state.copilotVersion,
|
|
2261
|
+
vsCodeVersion: state.vsCodeVersion,
|
|
2262
|
+
lead,
|
|
2263
|
+
modelCount: modelIds.length,
|
|
2264
|
+
peers: peersEnabled,
|
|
2265
|
+
helpers: helpersEnabled && peersEnabled,
|
|
2266
|
+
ui: uiEnabled,
|
|
2267
|
+
swe: sweEnabled,
|
|
2268
|
+
search: searchEnabled,
|
|
2269
|
+
browse: browseEnabled,
|
|
2270
|
+
serverUrl
|
|
2271
|
+
})}\n`);
|
|
1847
2272
|
if (sweEnabled && !peersEnabled) process$1.stderr.write("Note: --swe without --peers emits no delegate/review skills or prompts (no agents behind them in a peerless launch).\n");
|
|
1848
2273
|
const { disposeBluebirdClients } = await import("./bluebird-client-bn9Yv6Cb.js");
|
|
1849
2274
|
launchChild({
|
|
@@ -1860,15 +2285,25 @@ const pi = defineCommand({
|
|
|
1860
2285
|
extraArgs,
|
|
1861
2286
|
model: lead,
|
|
1862
2287
|
serverUrl
|
|
1863
|
-
}, server, {
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
2288
|
+
}, server, {
|
|
2289
|
+
onShutdown: async () => {
|
|
2290
|
+
unregisterLaunch(entry.launchId);
|
|
2291
|
+
await stopKeepAwake();
|
|
2292
|
+
await disposeBluebirdClients();
|
|
2293
|
+
await removeOwnPiAgentMirror();
|
|
2294
|
+
await removeAicLedgerFile();
|
|
2295
|
+
},
|
|
2296
|
+
onExitSummary: () => {
|
|
2297
|
+
const snapshot = aicSnapshot();
|
|
2298
|
+
if (snapshot.requests === 0 || snapshot.totalNanoAiu <= 0) return;
|
|
2299
|
+
const summary = formatAicExitSummary(snapshot, { verbose: consola.level >= 4 });
|
|
2300
|
+
const table = formatDiscountedCostTable(snapshot, discountedUsdForSnapshot(snapshot));
|
|
2301
|
+
return table ? `${summary}\n${table}` : summary;
|
|
2302
|
+
}
|
|
2303
|
+
});
|
|
1869
2304
|
}
|
|
1870
2305
|
});
|
|
1871
2306
|
//#endregion
|
|
1872
2307
|
export { pi };
|
|
1873
2308
|
|
|
1874
|
-
//# sourceMappingURL=pi-
|
|
2309
|
+
//# sourceMappingURL=pi-DJM02Mm2.js.map
|