github-router 0.3.347 → 0.3.349
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/dist/{aic-statusline-settings-YoDG20pq.js → aic-statusline-settings-DCFywz3N.js} +2 -2
- package/dist/aic-statusline-settings-DCFywz3N.js.map +1 -0
- package/dist/{attribution-settings-50S3mk4N.js → attribution-settings-BgYkynRc.js} +30 -18
- package/dist/attribution-settings-BgYkynRc.js.map +1 -0
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/{claude-D0rojAcX.js → claude-Chtd07VA.js} +32 -16
- package/dist/claude-Chtd07VA.js.map +1 -0
- package/dist/{codex-kcdKpoOe.js → codex-DayPQ8t5.js} +4 -4
- package/dist/{codex-kcdKpoOe.js.map → codex-DayPQ8t5.js.map} +1 -1
- package/dist/engine-T81FYVwK.js +2 -0
- package/dist/{gate-discovery-CzZ5Oc3H.js → gate-discovery-CBOPoK9-.js} +4 -4
- package/dist/{gate-discovery-CzZ5Oc3H.js.map → gate-discovery-CBOPoK9-.js.map} +1 -1
- package/dist/hooks.mjs +684 -14
- package/dist/hooks.sha256 +1 -1
- package/dist/{internal-aic-status-CCvU7zhC.js → internal-aic-status-lM0YNDaH.js} +52 -11
- package/dist/internal-aic-status-lM0YNDaH.js.map +1 -0
- package/dist/{internal-artifact-open-lta2UPnE.js → internal-artifact-open-CXJbMXpq.js} +2 -2
- package/dist/{internal-artifact-open-lta2UPnE.js.map → internal-artifact-open-CXJbMXpq.js.map} +1 -1
- package/dist/{internal-plan-review-B4f0dpss.js → internal-plan-review-F-WbltsT.js} +3 -3
- package/dist/{internal-plan-review-B4f0dpss.js.map → internal-plan-review-F-WbltsT.js.map} +1 -1
- package/dist/internal-prompt-submit-DRCJ5kWC.js +559 -0
- package/dist/internal-prompt-submit-DRCJ5kWC.js.map +1 -0
- package/dist/{internal-session-bind-IpZ5hJzR.js → internal-session-bind-LrYEo-kg.js} +2 -2
- package/dist/{internal-session-bind-IpZ5hJzR.js.map → internal-session-bind-LrYEo-kg.js.map} +1 -1
- package/dist/{internal-stop-hook-BdVV3NyD.js → internal-stop-hook-CIe2kVss.js} +5 -5
- package/dist/{internal-stop-hook-BdVV3NyD.js.map → internal-stop-hook-CIe2kVss.js.map} +1 -1
- package/dist/{internal-stop-review-C7bOxX1q.js → internal-stop-review-nL003JIj.js} +2 -2
- package/dist/{internal-stop-review-C7bOxX1q.js.map → internal-stop-review-nL003JIj.js.map} +1 -1
- package/dist/main.js +12 -12
- package/dist/{orchestration-Ccmfslh4.js → orchestration-DjuJRhXn.js} +2 -2
- package/dist/{orchestration-Ccmfslh4.js.map → orchestration-DjuJRhXn.js.map} +1 -1
- package/dist/{peer-mcp-personas-DlmmbpD6.js → peer-mcp-personas-agpBeTgS.js} +258 -52
- package/dist/peer-mcp-personas-agpBeTgS.js.map +1 -0
- package/dist/{pi-07uTIAcP.js → pi-BLDBFXg3.js} +5 -5
- package/dist/{pi-07uTIAcP.js.map → pi-BLDBFXg3.js.map} +1 -1
- package/dist/{plan-review-hook-BTvxvCCo.js → plan-review-hook-DMqPHBBN.js} +2 -2
- package/dist/{plan-review-hook-BTvxvCCo.js.map → plan-review-hook-DMqPHBBN.js.map} +1 -1
- package/dist/prompt-submit-hook-CBGlhEpU.js +411 -0
- package/dist/prompt-submit-hook-CBGlhEpU.js.map +1 -0
- package/dist/{provision-D_rmmqTq.js → provision-BKdrO1Sv.js} +2 -2
- package/dist/{provision-D_rmmqTq.js.map → provision-BKdrO1Sv.js.map} +1 -1
- package/dist/{serve-DbrYa6zo.js → serve-p_58sDJK.js} +8 -8
- package/dist/{serve-DbrYa6zo.js.map → serve-p_58sDJK.js.map} +1 -1
- package/dist/{server-setup-CKhj8I0W.js → server-setup-PAHohZ-u.js} +86 -33
- package/dist/server-setup-PAHohZ-u.js.map +1 -0
- package/dist/{start-BXVrchgI.js → start-CTHcqkQL.js} +3 -3
- package/dist/{start-BXVrchgI.js.map → start-CTHcqkQL.js.map} +1 -1
- package/dist/{stop-gate-hook-DZVfKoSh.js → stop-gate-hook-DRcYQAtf.js} +2 -2
- package/dist/{stop-gate-hook-DZVfKoSh.js.map → stop-gate-hook-DRcYQAtf.js.map} +1 -1
- package/dist/{stop-gate-policy-Gd_cNT9-.js → stop-gate-policy-CbLklfV2.js} +21 -2
- package/dist/{stop-gate-policy-Gd_cNT9-.js.map → stop-gate-policy-CbLklfV2.js.map} +1 -1
- package/package.json +1 -1
- package/dist/aic-statusline-settings-YoDG20pq.js.map +0 -1
- package/dist/attribution-settings-50S3mk4N.js.map +0 -1
- package/dist/claude-D0rojAcX.js.map +0 -1
- package/dist/engine-BWxxbsSu.js +0 -2
- package/dist/internal-aic-status-CCvU7zhC.js.map +0 -1
- package/dist/internal-prompt-submit-DGxv_Vgl.js +0 -127
- package/dist/internal-prompt-submit-DGxv_Vgl.js.map +0 -1
- package/dist/peer-mcp-personas-DlmmbpD6.js.map +0 -1
- package/dist/prompt-submit-hook-BeLUDy_m.js +0 -173
- package/dist/prompt-submit-hook-BeLUDy_m.js.map +0 -1
- package/dist/server-setup-CKhj8I0W.js.map +0 -1
package/dist/hooks.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import g, { stdin, stdout } from "node:process";
|
|
|
6
6
|
import * as tty from "node:tty";
|
|
7
7
|
import { WriteStream } from "node:tty";
|
|
8
8
|
import f from "node:readline";
|
|
9
|
-
import fs, { existsSync, mkdirSync, promises, readFileSync, realpathSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
9
|
+
import fs, { existsSync, mkdirSync, promises, readFileSync, readdirSync, realpathSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
11
|
import { spawn, spawnSync } from "node:child_process";
|
|
12
12
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
@@ -3647,6 +3647,25 @@ function fileLastPromptStore(stateDir) {
|
|
|
3647
3647
|
}
|
|
3648
3648
|
};
|
|
3649
3649
|
}
|
|
3650
|
+
function fileRewriteFlagStore(stateDir) {
|
|
3651
|
+
const fileFor = (sid) => path.join(stateDir, `rewrite-done-${createHash("sha256").update(sid).digest("hex").slice(0, 32)}`);
|
|
3652
|
+
return {
|
|
3653
|
+
async hasRun(sid) {
|
|
3654
|
+
try {
|
|
3655
|
+
await promises.access(fileFor(sid));
|
|
3656
|
+
return true;
|
|
3657
|
+
} catch {
|
|
3658
|
+
return false;
|
|
3659
|
+
}
|
|
3660
|
+
},
|
|
3661
|
+
async markRun(sid) {
|
|
3662
|
+
await promises.mkdir(stateDir, { recursive: true });
|
|
3663
|
+
const tmp = `${fileFor(sid)}.${process.pid}.tmp`;
|
|
3664
|
+
await promises.writeFile(tmp, "1", { mode: 384 });
|
|
3665
|
+
await promises.rename(tmp, fileFor(sid));
|
|
3666
|
+
}
|
|
3667
|
+
};
|
|
3668
|
+
}
|
|
3650
3669
|
var repoRootMemo;
|
|
3651
3670
|
var init_stop_gate_policy = __esmMin((() => {
|
|
3652
3671
|
init_exec();
|
|
@@ -35429,6 +35448,176 @@ var init_internal_stop_hook = __esmMin((() => {
|
|
|
35429
35448
|
});
|
|
35430
35449
|
}));
|
|
35431
35450
|
//#endregion
|
|
35451
|
+
//#region src/lib/cheapest-prompt-rewrite.ts
|
|
35452
|
+
function isCheapestRewriteDisabledEnv(env = process.env) {
|
|
35453
|
+
const v = (env.GH_ROUTER_DISABLE_CHEAPEST_REWRITE ?? "").trim().toLowerCase();
|
|
35454
|
+
return v === "1" || v === "true" || v === "yes" || v === "on";
|
|
35455
|
+
}
|
|
35456
|
+
function isCheapestRewriteEligible(input) {
|
|
35457
|
+
if (!input.steerEnabled) return false;
|
|
35458
|
+
if (input.rewriteDisabled) return false;
|
|
35459
|
+
if (input.profile !== "cheapest") return false;
|
|
35460
|
+
return input.promptIsNonTrivial;
|
|
35461
|
+
}
|
|
35462
|
+
/** Adaptive budget: 5 only on Sol's explicit deep-grounding flag, else 3. */
|
|
35463
|
+
function resolveRewriteTurnBudget(solText) {
|
|
35464
|
+
if (typeof solText === "string" && solText.includes("needs_deep_grounding=true")) return 5;
|
|
35465
|
+
return 3;
|
|
35466
|
+
}
|
|
35467
|
+
/** Extract a single follow-up query Sol names via `NEED_MORE: <query>. */
|
|
35468
|
+
function parseNeedMoreQuery(solText) {
|
|
35469
|
+
const idx = solText.indexOf(NEED_MORE_PREFIX);
|
|
35470
|
+
if (idx < 0) return "";
|
|
35471
|
+
return solText.slice(idx + 10).split("\n", 1)[0]?.trim().slice(0, 280) ?? "";
|
|
35472
|
+
}
|
|
35473
|
+
/**
|
|
35474
|
+
* System prompt for the Sol rewriter.
|
|
35475
|
+
*
|
|
35476
|
+
* The job is a GROUNDED EXECUTION CONTRACT for a fast mini-tier executor
|
|
35477
|
+
* (Luna), not a step-by-step procedure. This is the strong-planner /
|
|
35478
|
+
* weak-follower split (a strong model plans, a small one executes), adapted
|
|
35479
|
+
* to Luna's level. Evidence-driven choices:
|
|
35480
|
+
* - Lead with grounding + explicit constraints: small models' documented
|
|
35481
|
+
* weak spot is instruction/constraint following, while their biggest gain
|
|
35482
|
+
* comes from a stronger model handing them repo facts they cannot cheaply
|
|
35483
|
+
* gather themselves.
|
|
35484
|
+
* - Anti-CoT: explicit step-by-step reasoning prompts measurably degrade
|
|
35485
|
+
* instruction-following (models neglect simple constraints and invent
|
|
35486
|
+
* content), so the brief must NOT prescribe micro-steps, must NOT ask
|
|
35487
|
+
* Luna to "reason through" anything, and the ordered plan is OPTIONAL.
|
|
35488
|
+
* - Fidelity is the one hard invariant: never invent requirements or
|
|
35489
|
+
* acceptance criteria; a stated unknown beats a confident guess.
|
|
35490
|
+
* It also names the turn budget (and that zero tools is allowed) so Sol does
|
|
35491
|
+
* not pad grounding.
|
|
35492
|
+
*/
|
|
35493
|
+
function buildSolRewriteSystem(opts) {
|
|
35494
|
+
const searchNoun = opts.bluebirdEnabled ? "Bluebird lexical + semantic code search" : opts.searchEnabled ? "local lexical + semantic code search" : "lexical code search";
|
|
35495
|
+
return `You are a planning advisor for a coding agent. A fast, cheap mini-tier model (Luna) will execute the user's request. Produce a SHORT, GROUNDED EXECUTION CONTRACT that lets Luna do its best work — not a procedure for it to follow blindly.
|
|
35496
|
+
Turn budget: you have at most ${opts.turnBudget} tool turns TOTAL (search/read). You may use ZERO tools and write the contract immediately when the static context already suffices — do not pad turns. Stop grounding as soon as you can name exact content to change; prefer acting over more searching.\nIf the task is large/cross-cutting and the context is genuinely insufficient, you may emit "${DEEP_GROUNDING_FLAG}" plus one line "${NEED_MORE_PREFIX} <single targeted query>" to earn follow-up grounding; otherwise finish now.\nGrounding available: ${searchNoun} results, repo guidance (AGENTS.md/CLAUDE.md), and repo structure are in your context. Prefer targeted reads over full-file reads.\nThe user's original request is AUTHORITATIVE; your contract is counsel. Preserve the user's intent exactly — NEVER invent requirements, acceptance criteria, or scope the user did not ask for, and never change what "done" means to them. When grounding cannot resolve something, state it as an open question rather than guessing.\nEmit the contract with these sections, in order, using the section names as plain labels:\n- INTENT: the user's goal, in their terms (one or two lines).\n- GROUNDING: the load-bearing repo facts Luna would otherwise have to rediscover — exact files/symbols with file:line, the convention or existing pattern that applies. Name file:line because Luna cannot afford to re-discover it.\n- CONSTRAINTS: scope boundaries, explicit things NOT to do, and the success criterion — the constraints are the highest-value part of this contract.\n- VERIFY: the single check that settles "done" (the exact build/test/read command), or "unknown".\n- OPEN QUESTIONS: anything grounding could not resolve. Never fabricate an answer.\n- PLAN (OPTIONAL): include a short ordered plan ONLY when sequencing genuinely matters; omit it otherwise.\nDo NOT tell Luna to "think step by step" or "reason through" anything, and do NOT write a long procedural recipe — give it facts, constraints, and the check. Keep the contract short and flat. Respond with the contract body only, no preamble.`;
|
|
35497
|
+
}
|
|
35498
|
+
/** Assemble the capped static pack Sol sees (static-first for cache hits).
|
|
35499
|
+
* The USER REQUEST is passed through IN FULL (never truncated) — only the
|
|
35500
|
+
* repo-derived sections are capped. */
|
|
35501
|
+
function buildStaticContextPack(pack) {
|
|
35502
|
+
const parts = [`USER REQUEST:\n${pack.prompt}`];
|
|
35503
|
+
if (pack.agentsMd.trim().length > 0) parts.push(`REPO GUIDANCE (AGENTS.md):\n${pack.agentsMd.slice(0, CHEAPEST_REWRITE_GUIDANCE_CAP)}`);
|
|
35504
|
+
if (pack.claudeMd.trim().length > 0) parts.push(`REPO GUIDANCE (CLAUDE.md):\n${pack.claudeMd.slice(0, CHEAPEST_REWRITE_GUIDANCE_CAP)}`);
|
|
35505
|
+
if (pack.repoStructure.trim().length > 0) parts.push(`REPO STRUCTURE:\n${pack.repoStructure.slice(0, CHEAPEST_REWRITE_STRUCTURE_CAP)}`);
|
|
35506
|
+
if (pack.verifyCommand.trim().length > 0) parts.push(pack.verifyCommand.slice(0, 512));
|
|
35507
|
+
if (pack.searchContext.trim().length > 0) parts.push(pack.searchContext);
|
|
35508
|
+
return parts.join("\n\n");
|
|
35509
|
+
}
|
|
35510
|
+
/**
|
|
35511
|
+
* Wrap Sol's raw contract as the additive Luna-facing block. Returns "" when
|
|
35512
|
+
* Sol produced nothing usable (caller treats that as fail-open).
|
|
35513
|
+
*
|
|
35514
|
+
* The header states the trust/authority relationship explicitly (mirroring how
|
|
35515
|
+
* prior-turn review findings are framed): this is a stronger model's distilled
|
|
35516
|
+
* counsel about HOW to approach the request, while the user's own request
|
|
35517
|
+
* above remains authoritative.
|
|
35518
|
+
*/
|
|
35519
|
+
function wrapLunaBrief(solText) {
|
|
35520
|
+
const body = solText.replace(DEEP_GROUNDING_FLAG, "").split("\n").filter((line) => !line.trimStart().startsWith(NEED_MORE_PREFIX)).join("\n").trim();
|
|
35521
|
+
if (body.length === 0) return "";
|
|
35522
|
+
return `EXECUTION BRIEF (a stronger model's distilled guidance — advisory, non-authoritative): how to approach the request above. The user's request remains authoritative; adapt this brief if the repo contradicts it.\n${body.length > 2e3 ? `${body.slice(0, CHEAPEST_REWRITE_BRIEF_CAP).trimEnd()}…` : body}`;
|
|
35523
|
+
}
|
|
35524
|
+
/**
|
|
35525
|
+
* Run the adaptive rewrite. Returns `{ brief, timedOut }`: `brief` is the
|
|
35526
|
+
* wrapped additive contract, or null when anything is missing/empty/over-budget
|
|
35527
|
+
* so the caller falls back to the existing V2 scope/goal path; `timedOut` is
|
|
35528
|
+
* true only when the wall-clock budget elapsed first. Never throws to the
|
|
35529
|
+
* orchestrator.
|
|
35530
|
+
*/
|
|
35531
|
+
async function runCheapestRewrite(input) {
|
|
35532
|
+
const timeoutMs = input.io.timeoutMs ?? 3e4;
|
|
35533
|
+
const controller = new AbortController();
|
|
35534
|
+
let timer;
|
|
35535
|
+
try {
|
|
35536
|
+
const work = (async () => {
|
|
35537
|
+
const semanticAvailable = input.searchEnabled || input.bluebirdEnabled;
|
|
35538
|
+
const [lexical, semantic, statik] = await Promise.all([
|
|
35539
|
+
input.io.searchCode(input.prompt, "lexical", controller.signal).catch(() => ""),
|
|
35540
|
+
semanticAvailable ? input.io.searchCode(input.prompt, "semantic", controller.signal).catch(() => "") : Promise.resolve(""),
|
|
35541
|
+
input.io.staticPack().catch(() => ({
|
|
35542
|
+
agentsMd: "",
|
|
35543
|
+
claudeMd: "",
|
|
35544
|
+
repoStructure: "",
|
|
35545
|
+
verifyCommand: ""
|
|
35546
|
+
}))
|
|
35547
|
+
]);
|
|
35548
|
+
const searchContext = semanticAvailable ? `Lexical search results:\n${lexical.slice(0, CHEAPEST_REWRITE_SEARCH_CAP)}\n\nSemantic search results:\n${semantic.slice(0, CHEAPEST_REWRITE_SEARCH_CAP)}` : `Lexical search results:\n${lexical.slice(0, CHEAPEST_REWRITE_SEARCH_CAP)}`;
|
|
35549
|
+
const user = buildStaticContextPack({
|
|
35550
|
+
prompt: input.prompt,
|
|
35551
|
+
agentsMd: statik.agentsMd,
|
|
35552
|
+
claudeMd: statik.claudeMd,
|
|
35553
|
+
repoStructure: statik.repoStructure,
|
|
35554
|
+
verifyCommand: statik.verifyCommand,
|
|
35555
|
+
searchContext
|
|
35556
|
+
});
|
|
35557
|
+
const first = await input.io.inferSol(buildSolRewriteSystem({
|
|
35558
|
+
searchEnabled: input.searchEnabled,
|
|
35559
|
+
bluebirdEnabled: input.bluebirdEnabled,
|
|
35560
|
+
turnBudget: 3
|
|
35561
|
+
}), user, controller.signal).catch(() => "");
|
|
35562
|
+
if (!first || first.trim().length === 0) return null;
|
|
35563
|
+
const budget = resolveRewriteTurnBudget(first);
|
|
35564
|
+
const followUp = parseNeedMoreQuery(first);
|
|
35565
|
+
if (budget !== 5 || followUp.length === 0) {
|
|
35566
|
+
const brief = wrapLunaBrief(first);
|
|
35567
|
+
return brief.length > 0 ? brief : null;
|
|
35568
|
+
}
|
|
35569
|
+
const [extraLexical, extraSemantic] = await Promise.all([input.io.searchCode(followUp, "lexical", controller.signal).catch(() => ""), semanticAvailable ? input.io.searchCode(followUp, "semantic", controller.signal).catch(() => "") : Promise.resolve("")]);
|
|
35570
|
+
const extra = semanticAvailable ? `Lexical search results:\n${extraLexical.slice(0, CHEAPEST_REWRITE_SEARCH_CAP)}\n\nSemantic search results:\n${extraSemantic.slice(0, CHEAPEST_REWRITE_SEARCH_CAP)}` : `Lexical search results:\n${extraLexical.slice(0, CHEAPEST_REWRITE_SEARCH_CAP)}`;
|
|
35571
|
+
if (extra.trim().length === 0) {
|
|
35572
|
+
const brief = wrapLunaBrief(first);
|
|
35573
|
+
return brief.length > 0 ? brief : null;
|
|
35574
|
+
}
|
|
35575
|
+
const second = await input.io.inferSol(buildSolRewriteSystem({
|
|
35576
|
+
searchEnabled: input.searchEnabled,
|
|
35577
|
+
bluebirdEnabled: input.bluebirdEnabled,
|
|
35578
|
+
turnBudget: 5
|
|
35579
|
+
}), `${user}\n\nFOLLOW-UP GROUNDING for "${followUp}":\n${extra}\n\nRewrite the contract with this grounding (same rules, short).`, controller.signal).catch(() => "");
|
|
35580
|
+
const brief = wrapLunaBrief(second.trim().length > 0 ? second : first);
|
|
35581
|
+
return brief.length > 0 ? brief : null;
|
|
35582
|
+
})();
|
|
35583
|
+
work.catch(() => {});
|
|
35584
|
+
const raced = await Promise.race([work, new Promise((resolve) => {
|
|
35585
|
+
timer = setTimeout(() => resolve("__timeout__"), timeoutMs);
|
|
35586
|
+
})]);
|
|
35587
|
+
if (raced === "__timeout__") return {
|
|
35588
|
+
brief: null,
|
|
35589
|
+
timedOut: true
|
|
35590
|
+
};
|
|
35591
|
+
if (raced === null) return {
|
|
35592
|
+
brief: null,
|
|
35593
|
+
timedOut: false
|
|
35594
|
+
};
|
|
35595
|
+
return {
|
|
35596
|
+
brief: raced,
|
|
35597
|
+
timedOut: false
|
|
35598
|
+
};
|
|
35599
|
+
} catch {
|
|
35600
|
+
return {
|
|
35601
|
+
brief: null,
|
|
35602
|
+
timedOut: false
|
|
35603
|
+
};
|
|
35604
|
+
} finally {
|
|
35605
|
+
if (timer) clearTimeout(timer);
|
|
35606
|
+
controller.abort();
|
|
35607
|
+
}
|
|
35608
|
+
}
|
|
35609
|
+
var CHEAPEST_REWRITE_MODEL, CHEAPEST_REWRITE_EFFORT, CHEAPEST_REWRITE_SEARCH_CAP, CHEAPEST_REWRITE_GUIDANCE_CAP, CHEAPEST_REWRITE_STRUCTURE_CAP, CHEAPEST_REWRITE_BRIEF_CAP, DEEP_GROUNDING_FLAG, NEED_MORE_PREFIX;
|
|
35610
|
+
var init_cheapest_prompt_rewrite = __esmMin((() => {
|
|
35611
|
+
CHEAPEST_REWRITE_MODEL = "gpt-5.6-sol";
|
|
35612
|
+
CHEAPEST_REWRITE_EFFORT = "medium";
|
|
35613
|
+
CHEAPEST_REWRITE_SEARCH_CAP = 6144;
|
|
35614
|
+
CHEAPEST_REWRITE_GUIDANCE_CAP = 4096;
|
|
35615
|
+
CHEAPEST_REWRITE_STRUCTURE_CAP = 2048;
|
|
35616
|
+
CHEAPEST_REWRITE_BRIEF_CAP = 2e3;
|
|
35617
|
+
DEEP_GROUNDING_FLAG = "needs_deep_grounding=true";
|
|
35618
|
+
NEED_MORE_PREFIX = "NEED_MORE:";
|
|
35619
|
+
}));
|
|
35620
|
+
//#endregion
|
|
35432
35621
|
//#region src/lib/orchestration/prompt-submit-hook.ts
|
|
35433
35622
|
/**
|
|
35434
35623
|
* Cheap, conservative complexity heuristic — a long prompt, an imperative
|
|
@@ -35537,6 +35726,39 @@ async function decidePromptSubmitV2(input) {
|
|
|
35537
35726
|
const bluebirdEnabled = input.bluebirdEnabled === true;
|
|
35538
35727
|
const semanticAvailable = searchEnabled || bluebirdEnabled;
|
|
35539
35728
|
const searchTip = getPromptSearchTip(searchEnabled, bluebirdEnabled);
|
|
35729
|
+
if (input.rewrite && isCheapestRewriteEligible({
|
|
35730
|
+
profile: input.profile,
|
|
35731
|
+
promptIsNonTrivial: isNonTrivialPrompt(prompt),
|
|
35732
|
+
steerEnabled: input.steerEnabled,
|
|
35733
|
+
rewriteDisabled: input.rewriteDisabled === true
|
|
35734
|
+
}) && sessionId.length > 0 && !await input.rewrite.hasRewriteRun(sessionId).catch(() => true)) {
|
|
35735
|
+
await input.rewrite.markRewriteRun(sessionId).catch(() => {});
|
|
35736
|
+
const rewrite = await runCheapestRewrite({
|
|
35737
|
+
prompt,
|
|
35738
|
+
searchEnabled,
|
|
35739
|
+
bluebirdEnabled,
|
|
35740
|
+
io: input.rewrite
|
|
35741
|
+
}).catch(() => ({
|
|
35742
|
+
brief: null,
|
|
35743
|
+
timedOut: false
|
|
35744
|
+
}));
|
|
35745
|
+
if (rewrite.brief && rewrite.brief.length > 0) {
|
|
35746
|
+
decision.inject = joinSections([
|
|
35747
|
+
searchTip,
|
|
35748
|
+
rewrite.brief,
|
|
35749
|
+
findingsBlock
|
|
35750
|
+
]);
|
|
35751
|
+
return decision;
|
|
35752
|
+
}
|
|
35753
|
+
if (rewrite.timedOut) {
|
|
35754
|
+
decision.inject = joinSections([
|
|
35755
|
+
searchTip,
|
|
35756
|
+
PROMPT_STEER_GOAL,
|
|
35757
|
+
findingsBlock
|
|
35758
|
+
]);
|
|
35759
|
+
return decision;
|
|
35760
|
+
}
|
|
35761
|
+
}
|
|
35540
35762
|
const scopeSystem = getPromptScopeSystem(searchEnabled, bluebirdEnabled);
|
|
35541
35763
|
const timeoutMs = input.io.timeoutMs ?? 22e3;
|
|
35542
35764
|
let goal = PROMPT_STEER_GOAL;
|
|
@@ -35570,6 +35792,7 @@ async function decidePromptSubmitV2(input) {
|
|
|
35570
35792
|
}
|
|
35571
35793
|
var PROMPT_STEER_GOAL, SEARCH_CONTEXT_CAP;
|
|
35572
35794
|
var init_prompt_submit_hook = __esmMin((() => {
|
|
35795
|
+
init_cheapest_prompt_rewrite();
|
|
35573
35796
|
init_self_invocation();
|
|
35574
35797
|
init_stop_gate_policy();
|
|
35575
35798
|
PROMPT_STEER_GOAL = "GOAL (advisory): for a non-trivial task, FIRST run /gh-research on this ask to information saturation — verify the load-bearing claims against the actual code before planning, and do not plan or write code until research is saturated. THEN, for an implementation or change task, run /gh-orchestrate to compose and run a floor-raising workflow (it checkpoints before expensive work). Skip both for a trivial ask; you may decline if they do not fit.";
|
|
@@ -35577,7 +35800,10 @@ var init_prompt_submit_hook = __esmMin((() => {
|
|
|
35577
35800
|
}));
|
|
35578
35801
|
//#endregion
|
|
35579
35802
|
//#region src/internal-prompt-submit.ts
|
|
35580
|
-
var internal_prompt_submit_exports = /* @__PURE__ */ __exportAll({
|
|
35803
|
+
var internal_prompt_submit_exports = /* @__PURE__ */ __exportAll({
|
|
35804
|
+
buildStaticPack: () => buildStaticPack,
|
|
35805
|
+
internalPromptSubmit: () => internalPromptSubmit
|
|
35806
|
+
});
|
|
35581
35807
|
/**
|
|
35582
35808
|
* Read the hook payload from stdin SYNCHRONOUSLY (`readFileSync(0)`). An async
|
|
35583
35809
|
* stdin read leaves an in-flight libuv FS request that, on Windows, races the
|
|
@@ -35605,16 +35831,391 @@ function workspaceFromStdin(stdin) {
|
|
|
35605
35831
|
} catch {}
|
|
35606
35832
|
return process.cwd();
|
|
35607
35833
|
}
|
|
35608
|
-
|
|
35834
|
+
/** Read a text file best-effort, capped; missing/unreadable -> "". */
|
|
35835
|
+
function readCappedFile(absPath, cap) {
|
|
35836
|
+
try {
|
|
35837
|
+
return readFileSync(absPath, "utf8").slice(0, cap);
|
|
35838
|
+
} catch {
|
|
35839
|
+
return "";
|
|
35840
|
+
}
|
|
35841
|
+
}
|
|
35842
|
+
/**
|
|
35843
|
+
* Resolve the project root for `startDir`: the nearest ancestor (inclusive)
|
|
35844
|
+
* holding a `.git` entry — a file in worktrees/submodules, else a directory.
|
|
35845
|
+
*
|
|
35846
|
+
* A `.git` anywhere in the walk WINS over a nearer project marker, because
|
|
35847
|
+
* inside a repository the root's guidance is the one that applies: a workspace
|
|
35848
|
+
* package with its own `package.json` must not become the root, or the
|
|
35849
|
+
* repo-root `AGENTS.md` would never be read. With no `.git` above (non-repo
|
|
35850
|
+
* working tree), the nearest project marker is the best available root, so
|
|
35851
|
+
* non-git projects still get hierarchical guidance.
|
|
35852
|
+
*
|
|
35853
|
+
* Sync `existsSync` only, deliberately: this runs inside the rewrite's 30s
|
|
35854
|
+
* budget on every non-trivial prompt, and the async `repoRoot()` helper in
|
|
35855
|
+
* `stop-gate-policy` spawns `git rev-parse` — too expensive for a value a
|
|
35856
|
+
* directory probe answers. Falls back to `startDir`, and the walk is bounded
|
|
35857
|
+
* so a deep or symlinked path can't spin.
|
|
35858
|
+
*/
|
|
35859
|
+
function resolveProjectRoot(startDir) {
|
|
35860
|
+
const start = path.resolve(startDir);
|
|
35861
|
+
const MAX_ROOT_LEVELS = 8;
|
|
35862
|
+
let current = start;
|
|
35863
|
+
let nearestMarker;
|
|
35864
|
+
for (let i = 0; i < MAX_ROOT_LEVELS; i++) {
|
|
35865
|
+
if (existsSync(path.join(current, ".git"))) return current;
|
|
35866
|
+
if (!nearestMarker && PROJECT_ROOT_MARKERS.some((m) => existsSync(path.join(current, m)))) nearestMarker = current;
|
|
35867
|
+
const parent = path.dirname(current);
|
|
35868
|
+
if (parent === current) break;
|
|
35869
|
+
current = parent;
|
|
35870
|
+
}
|
|
35871
|
+
return nearestMarker ?? start;
|
|
35872
|
+
}
|
|
35873
|
+
/**
|
|
35874
|
+
* Read the nearest AGENTS.md / CLAUDE.md guidance for `startDir`, walking up
|
|
35875
|
+
* toward (and including) `root`. Frontier guidance treats AGENTS.md as
|
|
35876
|
+
* hierarchical: the closest file to the work wins — so the chain is built and
|
|
35877
|
+
* joined CLOSEST-FIRST. That ordering is load-bearing, not cosmetic: the caller
|
|
35878
|
+
* truncates the joined text with `slice(0, CAP)`, which keeps the head, so
|
|
35879
|
+
* closest-first is what makes the nearest file survive the budget. (Root-first
|
|
35880
|
+
* ordering plus a head-truncating slice silently starves the nearest guidance.)
|
|
35881
|
+
*
|
|
35882
|
+
* The walk is bounded to `MAX_LEVELS` directories from the start dir and always
|
|
35883
|
+
* includes the root, so a deep subdirectory still sees repo-root conventions
|
|
35884
|
+
* without paying to read every level. AGENTS.md and CLAUDE.md are collected
|
|
35885
|
+
* independently; the caller uses CLAUDE.md only when no AGENTS.md was found at
|
|
35886
|
+
* any level. Returns empty strings when none exist.
|
|
35887
|
+
*/
|
|
35888
|
+
function readHierarchicalGuidance(startDir, root) {
|
|
35889
|
+
const start = path.resolve(startDir);
|
|
35890
|
+
const rootAbs = path.resolve(root);
|
|
35891
|
+
const dirs = [];
|
|
35892
|
+
let current = start;
|
|
35893
|
+
const MAX_LEVELS = 3;
|
|
35894
|
+
for (let i = 0; i < MAX_LEVELS; i++) {
|
|
35895
|
+
dirs.push(current);
|
|
35896
|
+
if (current === rootAbs) break;
|
|
35897
|
+
const parent = path.dirname(current);
|
|
35898
|
+
if (parent === current) break;
|
|
35899
|
+
current = parent;
|
|
35900
|
+
}
|
|
35901
|
+
if (!dirs.includes(rootAbs)) dirs.push(rootAbs);
|
|
35902
|
+
const agentsParts = [];
|
|
35903
|
+
const claudeParts = [];
|
|
35904
|
+
for (const dir of dirs) {
|
|
35905
|
+
const agents = readCappedFile(path.join(dir, "AGENTS.md"), CHEAPEST_REWRITE_GUIDANCE_CAP);
|
|
35906
|
+
if (agents.length > 0) agentsParts.push(agents);
|
|
35907
|
+
const claude = readCappedFile(path.join(dir, "CLAUDE.md"), CHEAPEST_REWRITE_GUIDANCE_CAP);
|
|
35908
|
+
if (claude.length > 0) claudeParts.push(claude);
|
|
35909
|
+
}
|
|
35910
|
+
return {
|
|
35911
|
+
agentsMd: agentsParts.join("\n").slice(0, CHEAPEST_REWRITE_GUIDANCE_CAP),
|
|
35912
|
+
claudeMd: claudeParts.join("\n").slice(0, CHEAPEST_REWRITE_GUIDANCE_CAP)
|
|
35913
|
+
};
|
|
35914
|
+
}
|
|
35915
|
+
/** `packageManager` is versioned (`"pnpm@9.1.0"`) — take the leading name. */
|
|
35916
|
+
function runnerFromPackageManager(value) {
|
|
35917
|
+
if (typeof value !== "string") return void 0;
|
|
35918
|
+
const name = value.trim().split("@")[0]?.trim() ?? "";
|
|
35919
|
+
return name === "npm" || name === "pnpm" || name === "yarn" || name === "bun" ? name : void 0;
|
|
35920
|
+
}
|
|
35921
|
+
/** Lockfile → runner, searching `dirs` in order (nearest first). */
|
|
35922
|
+
function runnerFromLockfiles(dirs) {
|
|
35923
|
+
const table = [
|
|
35924
|
+
["bun.lock", "bun"],
|
|
35925
|
+
["bun.lockb", "bun"],
|
|
35926
|
+
["pnpm-lock.yaml", "pnpm"],
|
|
35927
|
+
["yarn.lock", "yarn"],
|
|
35928
|
+
["package-lock.json", "npm"]
|
|
35929
|
+
];
|
|
35930
|
+
for (const dir of dirs) for (const [lockfile, runner] of table) if (existsSync(path.join(dir, lockfile))) return runner;
|
|
35931
|
+
}
|
|
35932
|
+
/** Lockfile-less repos still name their runner in the script bodies. */
|
|
35933
|
+
function runnerFromScriptBodies(scripts) {
|
|
35934
|
+
for (const body of Object.values(scripts)) {
|
|
35935
|
+
if (typeof body !== "string") continue;
|
|
35936
|
+
const head = body.trimStart();
|
|
35937
|
+
if (head.startsWith("bun ")) return "bun";
|
|
35938
|
+
if (head.startsWith("pnpm ")) return "pnpm";
|
|
35939
|
+
if (head.startsWith("yarn ")) return "yarn";
|
|
35940
|
+
if (head.startsWith("npm ")) return "npm";
|
|
35941
|
+
}
|
|
35942
|
+
}
|
|
35943
|
+
/** Resolve the package runner for `dir`'s project. */
|
|
35944
|
+
function resolvePackageRunner(dir, root, pkg) {
|
|
35945
|
+
return runnerFromPackageManager(pkg.packageManager) ?? runnerFromLockfiles([dir, root]) ?? runnerFromScriptBodies(pkg.scripts ?? {}) ?? "npm";
|
|
35946
|
+
}
|
|
35947
|
+
/**
|
|
35948
|
+
* `<runner> run <name>` for EVERY script name, including `test`.
|
|
35949
|
+
*
|
|
35950
|
+
* The obvious shorthand (`npm test`) is NOT safe: `bun test` invokes Bun's
|
|
35951
|
+
* built-in test runner and ignores the `test` script entirely, so a repo whose
|
|
35952
|
+
* `test` script is `bun run build && bun scripts/run-tests.ts` would be told to
|
|
35953
|
+
* skip its own build and orchestrator. `run` is accepted by npm, pnpm, yarn
|
|
35954
|
+
* (1 and berry) and bun alike.
|
|
35955
|
+
*/
|
|
35956
|
+
function scriptCommand(runner, name) {
|
|
35957
|
+
return `${runner} run ${name}`;
|
|
35958
|
+
}
|
|
35959
|
+
/** Pick test/build/lint scripts, in preference order. */
|
|
35960
|
+
function pickVerifyScripts(scripts) {
|
|
35961
|
+
return [
|
|
35962
|
+
"test",
|
|
35963
|
+
"test:unit",
|
|
35964
|
+
"build",
|
|
35965
|
+
"typecheck",
|
|
35966
|
+
"lint"
|
|
35967
|
+
].filter((name) => {
|
|
35968
|
+
const body = scripts[name];
|
|
35969
|
+
return typeof body === "string" && body.trim().length > 0;
|
|
35970
|
+
});
|
|
35971
|
+
}
|
|
35972
|
+
/**
|
|
35973
|
+
* Bounded search for a project file (`*.sln`, `*.csproj`) at `dir` and up to
|
|
35974
|
+
* `maxDepth` levels below it. Entries are capped per directory so a huge tree
|
|
35975
|
+
* can't stall the hook, and heavy/known-noise directories are skipped.
|
|
35976
|
+
*/
|
|
35977
|
+
function findProjectFile(dir, matches, maxDepth = 2) {
|
|
35978
|
+
if (maxDepth < 0) return void 0;
|
|
35979
|
+
let entries;
|
|
35980
|
+
try {
|
|
35981
|
+
entries = readdirSync(dir, { withFileTypes: true }).slice(0, 200);
|
|
35982
|
+
} catch {
|
|
35983
|
+
return;
|
|
35984
|
+
}
|
|
35985
|
+
for (const entry of entries) if (matches(entry.name)) return entry.name;
|
|
35986
|
+
if (maxDepth === 0) return void 0;
|
|
35987
|
+
for (const entry of entries) {
|
|
35988
|
+
if (!entry.isDirectory() || SCAN_SKIP_DIRS.has(entry.name)) continue;
|
|
35989
|
+
const hit = findProjectFile(path.join(dir, entry.name), matches, maxDepth - 1);
|
|
35990
|
+
if (hit) return hit;
|
|
35991
|
+
}
|
|
35992
|
+
}
|
|
35993
|
+
/** Tier 0c: .NET. `dotnet test` restores + builds, but a solution-wide build
|
|
35994
|
+
* is still the gate, and `dotnet format` is only proposed when the repo
|
|
35995
|
+
* actually carries an .editorconfig to check against. */
|
|
35996
|
+
function dotnetVerification(root, cwd) {
|
|
35997
|
+
for (const dir of root === cwd ? [cwd] : [root, cwd]) {
|
|
35998
|
+
const project = findProjectFile(dir, (name) => /\.(sln|csproj)$/i.test(name));
|
|
35999
|
+
if (!project) continue;
|
|
36000
|
+
const commands = ["dotnet build", "dotnet test"];
|
|
36001
|
+
if (existsSync(path.join(dir, ".editorconfig"))) commands.push("dotnet format --verify-no-changes");
|
|
36002
|
+
return {
|
|
36003
|
+
ecosystem: `dotnet (${project})`,
|
|
36004
|
+
verifyCommand: `VERIFY COMMAND: ${commands.join(" ; ")}`
|
|
36005
|
+
};
|
|
36006
|
+
}
|
|
36007
|
+
}
|
|
36008
|
+
/** Parse `name:` target lines out of a Makefile (skipping `%` pattern rules). */
|
|
36009
|
+
function makeTargets(dir) {
|
|
36010
|
+
const body = readCappedFile([
|
|
36011
|
+
"Makefile",
|
|
36012
|
+
"makefile",
|
|
36013
|
+
"GNUmakefile"
|
|
36014
|
+
].map((name) => path.join(dir, name)).find((abs) => existsSync(abs)) ?? path.join(dir, "Makefile"), 8192);
|
|
36015
|
+
const targets = /* @__PURE__ */ new Set();
|
|
36016
|
+
for (const line of body.split("\n")) {
|
|
36017
|
+
const match = /^([A-Za-z0-9][A-Za-z0-9_.-]*)\s*:(?!=)/.exec(line);
|
|
36018
|
+
if (match?.[1] && !match[1].includes("%")) targets.add(match[1]);
|
|
36019
|
+
}
|
|
36020
|
+
return targets;
|
|
36021
|
+
}
|
|
36022
|
+
/** Tier 1 ladder. First marker hit wins; each entry returns "" for a repo it
|
|
36023
|
+
* recognizes but can't derive a command for (which lets the next probe try). */
|
|
36024
|
+
function markerVerification(cwd, root) {
|
|
36025
|
+
for (const dir of root === cwd ? [cwd] : [cwd, root]) {
|
|
36026
|
+
if (existsSync(path.join(dir, "go.mod"))) return {
|
|
36027
|
+
ecosystem: "go (go.mod)",
|
|
36028
|
+
verifyCommand: "VERIFY COMMAND: go build ./... ; go test ./... ; go vet ./..."
|
|
36029
|
+
};
|
|
36030
|
+
if (existsSync(path.join(dir, "Cargo.toml"))) return {
|
|
36031
|
+
ecosystem: "rust (Cargo.toml)",
|
|
36032
|
+
verifyCommand: "VERIFY COMMAND: cargo build ; cargo test"
|
|
36033
|
+
};
|
|
36034
|
+
if (existsSync(path.join(dir, "mix.exs"))) return {
|
|
36035
|
+
ecosystem: "elixir (mix.exs)",
|
|
36036
|
+
verifyCommand: "VERIFY COMMAND: mix test"
|
|
36037
|
+
};
|
|
36038
|
+
if (existsSync(path.join(dir, "Gemfile"))) return {
|
|
36039
|
+
ecosystem: "ruby (Gemfile)",
|
|
36040
|
+
verifyCommand: findProjectFile(dir, (name) => name === "spec", 0) !== void 0 ? "VERIFY COMMAND: bundle exec rspec" : "VERIFY COMMAND: bundle exec rake test"
|
|
36041
|
+
};
|
|
36042
|
+
const denoConfig = ["deno.json", "deno.jsonc"].map((name) => path.join(dir, name)).find((abs) => existsSync(abs));
|
|
36043
|
+
if (denoConfig) {
|
|
36044
|
+
const tasks = readCappedFile(denoConfig, 32768);
|
|
36045
|
+
if (/"test"\s*:/.test(tasks) || /'test'\s*:/.test(tasks)) return {
|
|
36046
|
+
ecosystem: "deno (deno.json)",
|
|
36047
|
+
verifyCommand: "VERIFY COMMAND: deno task test"
|
|
36048
|
+
};
|
|
36049
|
+
}
|
|
36050
|
+
const pyproject = path.join(dir, "pyproject.toml");
|
|
36051
|
+
const pyprojectBody = readCappedFile(pyproject, 32768);
|
|
36052
|
+
const setupCfg = readCappedFile(path.join(dir, "setup.cfg"), 32768);
|
|
36053
|
+
if (["tests", "test"].some((name) => findProjectFile(dir, (entry) => entry === name, 0) !== void 0) || existsSync(path.join(dir, "pytest.ini")) || existsSync(path.join(dir, "tox.ini")) || /\[tool\.pytest/.test(pyprojectBody) || /\[tool:pytest\]/.test(setupCfg)) {
|
|
36054
|
+
const commands = [existsSync(path.join(dir, "uv.lock")) ? "uv run pytest" : existsSync(path.join(dir, "poetry.lock")) ? "poetry run pytest" : existsSync(path.join(dir, "Pipfile")) ? "pipenv run pytest" : "pytest"];
|
|
36055
|
+
if (existsSync(path.join(dir, "mypy.ini")) || /\[tool\.mypy/.test(pyprojectBody)) commands.push("mypy .");
|
|
36056
|
+
if (existsSync(path.join(dir, "ruff.toml")) || /\[tool\.ruff/.test(pyprojectBody)) commands.push("ruff check .");
|
|
36057
|
+
return {
|
|
36058
|
+
ecosystem: `python (${path.basename(pyproject)})`,
|
|
36059
|
+
verifyCommand: `VERIFY COMMAND: ${commands.join(" ; ")}`
|
|
36060
|
+
};
|
|
36061
|
+
}
|
|
36062
|
+
if (existsSync(path.join(dir, "Makefile")) || existsSync(path.join(dir, "makefile")) || existsSync(path.join(dir, "GNUmakefile"))) {
|
|
36063
|
+
const targets = makeTargets(dir);
|
|
36064
|
+
const picked = [
|
|
36065
|
+
"test",
|
|
36066
|
+
"tests",
|
|
36067
|
+
"check",
|
|
36068
|
+
"ci",
|
|
36069
|
+
"verify",
|
|
36070
|
+
"build",
|
|
36071
|
+
"lint"
|
|
36072
|
+
].filter((name) => targets.has(name)).slice(0, 2);
|
|
36073
|
+
if (picked.length > 0) return {
|
|
36074
|
+
ecosystem: "make (Makefile)",
|
|
36075
|
+
verifyCommand: `VERIFY COMMAND: ${picked.map((t) => `make ${t}`).join(" ; ")}`
|
|
36076
|
+
};
|
|
36077
|
+
}
|
|
36078
|
+
}
|
|
36079
|
+
return NO_VERIFICATION;
|
|
36080
|
+
}
|
|
36081
|
+
/** Full detection: JS/TS first, then .NET, then the marker ladder. */
|
|
36082
|
+
function detectVerification(cwd, root) {
|
|
36083
|
+
const cwdPkg = readPackageJson(cwd);
|
|
36084
|
+
if (cwdPkg) {
|
|
36085
|
+
const picks = pickVerifyScripts(cwdPkg.scripts ?? {});
|
|
36086
|
+
if (picks.length > 0) {
|
|
36087
|
+
const runner = resolvePackageRunner(cwd, root, cwdPkg);
|
|
36088
|
+
return {
|
|
36089
|
+
ecosystem: `node (${runner})`,
|
|
36090
|
+
verifyCommand: `VERIFY COMMAND: ${picks.map((n) => scriptCommand(runner, n)).join(" ; ")}`
|
|
36091
|
+
};
|
|
36092
|
+
}
|
|
36093
|
+
}
|
|
36094
|
+
const ancestor = findAncestorScriptRoot(cwd, root);
|
|
36095
|
+
if (ancestor) {
|
|
36096
|
+
const { dir, pkg } = ancestor;
|
|
36097
|
+
const runner = resolvePackageRunner(dir, root, pkg);
|
|
36098
|
+
return {
|
|
36099
|
+
ecosystem: `node (${runner}, workspace root)`,
|
|
36100
|
+
verifyCommand: `VERIFY COMMAND (run from ${dir}): ` + pickVerifyScripts(pkg.scripts ?? {}).map((n) => scriptCommand(runner, n)).join(" ; ")
|
|
36101
|
+
};
|
|
36102
|
+
}
|
|
36103
|
+
return dotnetVerification(root, cwd) ?? markerVerification(cwd, root);
|
|
36104
|
+
}
|
|
36105
|
+
/**
|
|
36106
|
+
* Nearest strict ancestor of `cwd` whose package.json declares at least one
|
|
36107
|
+
* recognized verify script — the monorepo case, where the workspace manifest is
|
|
36108
|
+
* the real gate. Never ascends above `root` (so a stray `~/package.json` can't
|
|
36109
|
+
* be picked up for a session already at the project root), and bounded so a
|
|
36110
|
+
* deep sub-package can't pay for a long ascent.
|
|
36111
|
+
*/
|
|
36112
|
+
function findAncestorScriptRoot(cwd, root) {
|
|
36113
|
+
const start = path.resolve(cwd);
|
|
36114
|
+
const rootAbs = path.resolve(root);
|
|
36115
|
+
if (rootAbs === start) return void 0;
|
|
36116
|
+
const MAX_ASCENT = 4;
|
|
36117
|
+
let current = path.dirname(start);
|
|
36118
|
+
for (let i = 0; i <= MAX_ASCENT; i++) {
|
|
36119
|
+
const pkg = readPackageJson(current);
|
|
36120
|
+
if (pkg && pickVerifyScripts(pkg.scripts ?? {}).length > 0) return {
|
|
36121
|
+
dir: current,
|
|
36122
|
+
pkg
|
|
36123
|
+
};
|
|
36124
|
+
if (current === rootAbs) break;
|
|
36125
|
+
const parent = path.dirname(current);
|
|
36126
|
+
if (parent === current) break;
|
|
36127
|
+
current = parent;
|
|
36128
|
+
}
|
|
36129
|
+
}
|
|
36130
|
+
function readPackageJson(dir) {
|
|
36131
|
+
const raw = readCappedFile(path.join(dir, "package.json"), 65536);
|
|
36132
|
+
if (raw.length === 0) return void 0;
|
|
36133
|
+
try {
|
|
36134
|
+
const parsed = JSON.parse(raw);
|
|
36135
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
|
|
36136
|
+
} catch {}
|
|
36137
|
+
}
|
|
36138
|
+
/**
|
|
36139
|
+
* Static repo context for the cheapest rewrite: hierarchical AGENTS.md
|
|
36140
|
+
* (preferred) / CLAUDE.md (fallback) + top-level structure + a detected
|
|
36141
|
+
* ecosystem + its VERIFY COMMAND line. All synchronous (tiny reads) and
|
|
36142
|
+
* capped; missing files yield "".
|
|
36143
|
+
*/
|
|
36144
|
+
function buildStaticPack(workspace) {
|
|
36145
|
+
const root = resolveProjectRoot(workspace);
|
|
36146
|
+
const guidance = readHierarchicalGuidance(workspace, root);
|
|
36147
|
+
const agentsMd = guidance.agentsMd;
|
|
36148
|
+
const claudeMd = agentsMd.length > 0 ? "" : guidance.claudeMd;
|
|
36149
|
+
let listing;
|
|
36150
|
+
try {
|
|
36151
|
+
listing = readdirSync(workspace, { withFileTypes: true }).slice(0, 60).map((e) => e.isDirectory() ? `${e.name}/` : e.name).join(", ");
|
|
36152
|
+
} catch {
|
|
36153
|
+
listing = "";
|
|
36154
|
+
}
|
|
36155
|
+
let pkgSnippet;
|
|
36156
|
+
const pkg = readPackageJson(workspace);
|
|
36157
|
+
if (pkg) pkgSnippet = `scripts: [${pkg.scripts ? Object.keys(pkg.scripts).slice(0, 20).join(", ") : ""}] deps: [${Object.keys(pkg.dependencies ?? {}).slice(0, 20).join(", ")}]`;
|
|
36158
|
+
else pkgSnippet = "";
|
|
36159
|
+
const { ecosystem, verifyCommand: detected } = detectVerification(workspace, root);
|
|
36160
|
+
return {
|
|
36161
|
+
agentsMd,
|
|
36162
|
+
claudeMd,
|
|
36163
|
+
repoStructure: [
|
|
36164
|
+
`top-level: ${listing}`,
|
|
36165
|
+
ecosystem ? `ecosystem: ${ecosystem}` : "",
|
|
36166
|
+
pkgSnippet
|
|
36167
|
+
].filter((s) => s.trim().length > 0 && s !== "top-level: ").join("\n").slice(0, CHEAPEST_REWRITE_STRUCTURE_CAP),
|
|
36168
|
+
verifyCommand: detected.slice(0, 512)
|
|
36169
|
+
};
|
|
36170
|
+
}
|
|
36171
|
+
var SEARCH_TIMEOUT_MS, INFER_TIMEOUT_MS, REWRITE_TIMEOUT_MS, PROJECT_ROOT_MARKERS, SCAN_SKIP_DIRS, NO_VERIFICATION, internalPromptSubmit;
|
|
35609
36172
|
var init_internal_prompt_submit = __esmMin((() => {
|
|
35610
36173
|
init_dist$1();
|
|
36174
|
+
init_cheapest_prompt_rewrite();
|
|
35611
36175
|
init_exec();
|
|
35612
36176
|
init_hook_mcp_client();
|
|
35613
36177
|
init_stop_gate_hook();
|
|
35614
36178
|
init_prompt_submit_hook();
|
|
35615
36179
|
init_stop_gate_policy();
|
|
35616
36180
|
SEARCH_TIMEOUT_MS = 8e3;
|
|
35617
|
-
INFER_TIMEOUT_MS =
|
|
36181
|
+
INFER_TIMEOUT_MS = 25e3;
|
|
36182
|
+
REWRITE_TIMEOUT_MS = 3e4;
|
|
36183
|
+
PROJECT_ROOT_MARKERS = [
|
|
36184
|
+
"package.json",
|
|
36185
|
+
"go.mod",
|
|
36186
|
+
"Cargo.toml",
|
|
36187
|
+
"pyproject.toml",
|
|
36188
|
+
"setup.py",
|
|
36189
|
+
"mix.exs",
|
|
36190
|
+
"Gemfile",
|
|
36191
|
+
"deno.json",
|
|
36192
|
+
"deno.jsonc",
|
|
36193
|
+
"global.json",
|
|
36194
|
+
"Makefile",
|
|
36195
|
+
"makefile",
|
|
36196
|
+
"GNUmakefile"
|
|
36197
|
+
];
|
|
36198
|
+
SCAN_SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
36199
|
+
".git",
|
|
36200
|
+
"node_modules",
|
|
36201
|
+
"dist",
|
|
36202
|
+
"build",
|
|
36203
|
+
"out",
|
|
36204
|
+
"target",
|
|
36205
|
+
"bin",
|
|
36206
|
+
"obj",
|
|
36207
|
+
"vendor",
|
|
36208
|
+
"venv",
|
|
36209
|
+
".venv",
|
|
36210
|
+
"__pycache__",
|
|
36211
|
+
"coverage",
|
|
36212
|
+
".next",
|
|
36213
|
+
".turbo"
|
|
36214
|
+
]);
|
|
36215
|
+
NO_VERIFICATION = {
|
|
36216
|
+
ecosystem: "",
|
|
36217
|
+
verifyCommand: ""
|
|
36218
|
+
};
|
|
35618
36219
|
internalPromptSubmit = defineCommand({
|
|
35619
36220
|
meta: {
|
|
35620
36221
|
name: "internal-prompt-submit",
|
|
@@ -35635,6 +36236,40 @@ var init_internal_prompt_submit = __esmMin((() => {
|
|
|
35635
36236
|
steerEnabled,
|
|
35636
36237
|
searchEnabled,
|
|
35637
36238
|
bluebirdEnabled,
|
|
36239
|
+
profile: (process.env.GH_ROUTER_PROFILE ?? "").trim().toLowerCase(),
|
|
36240
|
+
rewriteDisabled: isCheapestRewriteDisabledEnv(),
|
|
36241
|
+
rewrite: {
|
|
36242
|
+
searchCode: async (query, mode, signal) => {
|
|
36243
|
+
const r = await callMcpTool({
|
|
36244
|
+
runtime,
|
|
36245
|
+
group: "search",
|
|
36246
|
+
tool: "code",
|
|
36247
|
+
args: {
|
|
36248
|
+
query,
|
|
36249
|
+
workspace,
|
|
36250
|
+
mode,
|
|
36251
|
+
limit: 10,
|
|
36252
|
+
summary: false
|
|
36253
|
+
},
|
|
36254
|
+
timeoutMs: SEARCH_TIMEOUT_MS,
|
|
36255
|
+
signal
|
|
36256
|
+
});
|
|
36257
|
+
return r.isError ? "" : r.text;
|
|
36258
|
+
},
|
|
36259
|
+
inferSol: (system, user, signal) => callInference({
|
|
36260
|
+
serverUrl: runtime.serverUrl,
|
|
36261
|
+
model: CHEAPEST_REWRITE_MODEL,
|
|
36262
|
+
instructions: system,
|
|
36263
|
+
input: user,
|
|
36264
|
+
effort: CHEAPEST_REWRITE_EFFORT,
|
|
36265
|
+
timeoutMs: INFER_TIMEOUT_MS,
|
|
36266
|
+
signal
|
|
36267
|
+
}),
|
|
36268
|
+
staticPack: async () => buildStaticPack(workspace),
|
|
36269
|
+
hasRewriteRun: (sid) => fileRewriteFlagStore(stopReviewStateDir()).hasRun(sid),
|
|
36270
|
+
markRewriteRun: (sid) => fileRewriteFlagStore(stopReviewStateDir()).markRun(sid),
|
|
36271
|
+
timeoutMs: REWRITE_TIMEOUT_MS
|
|
36272
|
+
},
|
|
35638
36273
|
io: {
|
|
35639
36274
|
searchCode: async (query, mode, signal) => {
|
|
35640
36275
|
const r = await callMcpTool({
|
|
@@ -38880,7 +39515,16 @@ var init_copilot_discount = __esmMin((() => {
|
|
|
38880
39515
|
* Segment order (left = highest priority; narrow terminals drop from the
|
|
38881
39516
|
* right, `AIC` is never dropped):
|
|
38882
39517
|
*
|
|
38883
|
-
* `[AIC] | [ctx bar]
|
|
39518
|
+
* `[AIC] | [ctx bar] %·window | model | dir (branch) | ~$actual | in/out | dur | +a -r`
|
|
39519
|
+
*
|
|
39520
|
+
* The `·window` suffix is the session's own context window (`200K`, `272K`,
|
|
39521
|
+
* `1M`, `--` when the client does not report one), so a percentage is always
|
|
39522
|
+
* readable against a real denominator: the cheap 200K cost classes versus Pi's
|
|
39523
|
+
* 272K Copilot Default-tier windows, and a `/model` switch into Claude Code's
|
|
39524
|
+
* 1M accounting are visible at a glance. Both clients already report it
|
|
39525
|
+
* (`context_window.context_window_size`: Claude Code 2.1.285+ resolves it from
|
|
39526
|
+
* the active model, the Pi footer payload forwards `getContextUsage()`'s), so
|
|
39527
|
+
* no launch-time plumbing is involved.
|
|
38884
39528
|
*
|
|
38885
39529
|
* The `$` segment is the DISCOUNTED actual (`~$` = factor-discounted
|
|
38886
39530
|
* session total from `copilot-discount.ts`, capped at AIC × $0.01) — NOT
|
|
@@ -38924,6 +39568,8 @@ function parseStatusInput(raw) {
|
|
|
38924
39568
|
if (ctx) {
|
|
38925
39569
|
const pct = finiteNumber(ctx.used_percentage);
|
|
38926
39570
|
if (pct !== void 0) out.usedPct = pct;
|
|
39571
|
+
const size = finiteNumber(ctx.context_window_size);
|
|
39572
|
+
if (size !== void 0 && size > 0) out.windowSize = Math.floor(size);
|
|
38927
39573
|
const tIn = finiteNumber(ctx.total_input_tokens);
|
|
38928
39574
|
if (tIn !== void 0 && tIn >= 0) out.totalInputTokens = Math.floor(tIn);
|
|
38929
39575
|
const tOut = finiteNumber(ctx.total_output_tokens);
|
|
@@ -38954,6 +39600,18 @@ function compactTokens(n) {
|
|
|
38954
39600
|
if (n >= 1e3) return `${(n / 1e3).toFixed(1)}k`;
|
|
38955
39601
|
return `${n}`;
|
|
38956
39602
|
}
|
|
39603
|
+
/**
|
|
39604
|
+
* Context window, compact and exact where it matters: `200000` → `200K`,
|
|
39605
|
+
* `272000` → `272K`, `1000000` → `1M`, `1048576` → `1.05M`. Trailing zeros
|
|
39606
|
+
* are trimmed so the round client windows stay short. Total: a missing,
|
|
39607
|
+
* non-finite, or non-positive size yields `--` rather than a wrong number.
|
|
39608
|
+
*/
|
|
39609
|
+
function formatWindow(tokens) {
|
|
39610
|
+
if (tokens === void 0 || !Number.isFinite(tokens) || tokens <= 0) return UNKNOWN_WINDOW;
|
|
39611
|
+
if (tokens >= 1e6) return `${String(Number((tokens / 1e6).toFixed(2)))}M`;
|
|
39612
|
+
if (tokens >= 1e3) return `${String(Number((tokens / 1e3).toFixed(2)))}K`;
|
|
39613
|
+
return `${Math.floor(tokens)}`;
|
|
39614
|
+
}
|
|
38957
39615
|
/** `45000` → `0m45s`, `198000` → `3m18s`, `3720000` → `1h02m`. */
|
|
38958
39616
|
function formatDurationMs(ms) {
|
|
38959
39617
|
const totalSeconds = Math.floor(ms / 1e3);
|
|
@@ -38969,10 +39627,18 @@ function dirLeaf(cwd) {
|
|
|
38969
39627
|
const parts = trimmed.split(/[/\\]/);
|
|
38970
39628
|
return parts[parts.length - 1] ?? trimmed;
|
|
38971
39629
|
}
|
|
38972
|
-
|
|
39630
|
+
/**
|
|
39631
|
+
* Context segment: `[####------] 42%·200K`. The percentage keeps the
|
|
39632
|
+
* green/yellow/red threshold coloring; the window is dimmed so it reads as
|
|
39633
|
+
* context, not another metric. Both halves are independently optional —
|
|
39634
|
+
* `windowSize` undefined renders `--` (clients that report no window), and
|
|
39635
|
+
* `usedPct` undefined keeps the placeholder bar.
|
|
39636
|
+
*/
|
|
39637
|
+
function buildCtxSegment(usedPct, windowSize) {
|
|
39638
|
+
const win = formatWindow(windowSize);
|
|
38973
39639
|
if (usedPct === void 0 || !Number.isFinite(usedPct)) return {
|
|
38974
|
-
text: `${DIM}[----------] --%${RESET}`,
|
|
38975
|
-
plain:
|
|
39640
|
+
text: `${DIM}[----------] --%${RESET}${DIM}${WINDOW_JOINER}${win}${RESET}`,
|
|
39641
|
+
plain: `[----------] --%${WINDOW_JOINER}${win}`
|
|
38976
39642
|
};
|
|
38977
39643
|
const u = Math.max(0, Math.min(100, Math.round(usedPct)));
|
|
38978
39644
|
let filled = Math.round(u / 100 * CTX_BAR_LEN);
|
|
@@ -38980,8 +39646,8 @@ function buildCtxSegment(usedPct) {
|
|
|
38980
39646
|
if (filled < 0) filled = 0;
|
|
38981
39647
|
const bar = `#`.repeat(filled) + `-`.repeat(CTX_BAR_LEN - filled);
|
|
38982
39648
|
return {
|
|
38983
|
-
text: `${u < 50 ? GREEN : u < 75 ? YELLOW : RED}[${bar}] ${u}%${RESET}`,
|
|
38984
|
-
plain: `[${bar}] ${u}
|
|
39649
|
+
text: `${u < 50 ? GREEN : u < 75 ? YELLOW : RED}[${bar}] ${u}%${RESET}${DIM}${WINDOW_JOINER}${win}${RESET}`,
|
|
39650
|
+
plain: `[${bar}] ${u}%${WINDOW_JOINER}${win}`
|
|
38985
39651
|
};
|
|
38986
39652
|
}
|
|
38987
39653
|
/**
|
|
@@ -39111,13 +39777,15 @@ function terminalWidth(env = process.env) {
|
|
|
39111
39777
|
* PINNED — it renders even when nothing else fits. `actualUsd` feeds the
|
|
39112
39778
|
* `~$` segment (the capped factor-discounted total from
|
|
39113
39779
|
* `discountedUsdForSnapshot`, same snapshot the fragment came from).
|
|
39114
|
-
* Droppable segments in priority order: ctx, model, dir/git,
|
|
39115
|
-
* dur, lines.
|
|
39780
|
+
* Droppable segments in priority order: ctx (`%·window`), model, dir/git,
|
|
39781
|
+
* ~$, toks, dur, lines. The window rides inside the ctx segment rather than
|
|
39782
|
+
* taking its own slot, so the added width is ~6 columns instead of a whole
|
|
39783
|
+
* ` | 200K` group.
|
|
39116
39784
|
*/
|
|
39117
39785
|
function assembleStatusLine(aicFragment, input, opts = {}) {
|
|
39118
39786
|
const aic = aicFragment.trim();
|
|
39119
39787
|
const aicText = aic ? `${AIC_COLOR}${aic}${RESET}` : "";
|
|
39120
|
-
const droppable = [buildCtxSegment(input.usedPct)];
|
|
39788
|
+
const droppable = [buildCtxSegment(input.usedPct, input.windowSize)];
|
|
39121
39789
|
const model = buildModelSegment(input.modelName);
|
|
39122
39790
|
if (model) droppable.push(model);
|
|
39123
39791
|
const dirGit = buildDirGitSegment(input.cwd, opts.branch);
|
|
@@ -39158,7 +39826,7 @@ function buildRichStatusLine(stdinRaw, aicFragment, opts = {}) {
|
|
|
39158
39826
|
...opts.actualUsd !== void 0 ? { actualUsd: opts.actualUsd } : {}
|
|
39159
39827
|
});
|
|
39160
39828
|
}
|
|
39161
|
-
var ESC, RESET, DIM, GREEN, YELLOW, RED, ORANGE, CYAN, MAGENTA, BLUE, AIC_COLOR, CTX_BAR_LEN, GIT_TIMEOUT_MS, WIDTH_FALLBACK, SEP_TEXT;
|
|
39829
|
+
var ESC, RESET, DIM, GREEN, YELLOW, RED, ORANGE, CYAN, MAGENTA, BLUE, AIC_COLOR, CTX_BAR_LEN, GIT_TIMEOUT_MS, WIDTH_FALLBACK, SEP_TEXT, WINDOW_JOINER, UNKNOWN_WINDOW;
|
|
39162
39830
|
var init_default_statusline = __esmMin((() => {
|
|
39163
39831
|
init_copilot_discount();
|
|
39164
39832
|
init_exec();
|
|
@@ -39177,6 +39845,8 @@ var init_default_statusline = __esmMin((() => {
|
|
|
39177
39845
|
GIT_TIMEOUT_MS = 300;
|
|
39178
39846
|
WIDTH_FALLBACK = 120;
|
|
39179
39847
|
SEP_TEXT = `${DIM} | ${RESET}`;
|
|
39848
|
+
WINDOW_JOINER = "·";
|
|
39849
|
+
UNKNOWN_WINDOW = "--";
|
|
39180
39850
|
}));
|
|
39181
39851
|
//#endregion
|
|
39182
39852
|
//#region src/internal-aic-status.ts
|