github-router 0.3.348 → 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-P_vba-ri.js → attribution-settings-BgYkynRc.js} +14 -12
- package/dist/{attribution-settings-P_vba-ri.js.map → attribution-settings-BgYkynRc.js.map} +1 -1
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/{claude-D26fp1ih.js → claude-Chtd07VA.js} +25 -10
- package/dist/{claude-D26fp1ih.js.map → claude-Chtd07VA.js.map} +1 -1
- package/dist/{codex-DM97sCtu.js → codex-DayPQ8t5.js} +4 -4
- package/dist/{codex-DM97sCtu.js.map → codex-DayPQ8t5.js.map} +1 -1
- package/dist/engine-T81FYVwK.js +2 -0
- package/dist/{gate-discovery-V-mslLHt.js → gate-discovery-CBOPoK9-.js} +2 -2
- package/dist/{gate-discovery-V-mslLHt.js.map → gate-discovery-CBOPoK9-.js.map} +1 -1
- package/dist/hooks.mjs +472 -49
- 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-prompt-submit-DRCJ5kWC.js +559 -0
- package/dist/internal-prompt-submit-DRCJ5kWC.js.map +1 -0
- package/dist/{internal-stop-hook-v5WF6Kc2.js → internal-stop-hook-CIe2kVss.js} +2 -2
- package/dist/{internal-stop-hook-v5WF6Kc2.js.map → internal-stop-hook-CIe2kVss.js.map} +1 -1
- package/dist/main.js +8 -8
- package/dist/{peer-mcp-personas-C200IycG.js → peer-mcp-personas-agpBeTgS.js} +233 -61
- package/dist/peer-mcp-personas-agpBeTgS.js.map +1 -0
- package/dist/{pi-BWGfNpi7.js → pi-BLDBFXg3.js} +5 -5
- package/dist/{pi-BWGfNpi7.js.map → pi-BLDBFXg3.js.map} +1 -1
- package/dist/{prompt-submit-hook-wjuHUrpS.js → prompt-submit-hook-CBGlhEpU.js} +94 -35
- package/dist/prompt-submit-hook-CBGlhEpU.js.map +1 -0
- package/dist/{provision-BFTONLfA.js → provision-BKdrO1Sv.js} +2 -2
- package/dist/{provision-BFTONLfA.js.map → provision-BKdrO1Sv.js.map} +1 -1
- package/dist/{serve-D9xQeGqi.js → serve-p_58sDJK.js} +6 -6
- package/dist/{serve-D9xQeGqi.js.map → serve-p_58sDJK.js.map} +1 -1
- package/dist/{server-setup-R1HQtpR9.js → server-setup-PAHohZ-u.js} +25 -14
- package/dist/server-setup-PAHohZ-u.js.map +1 -0
- package/dist/{start-vg2n8UjI.js → start-CTHcqkQL.js} +3 -3
- package/dist/{start-vg2n8UjI.js.map → start-CTHcqkQL.js.map} +1 -1
- package/package.json +1 -1
- package/dist/aic-statusline-settings-YoDG20pq.js.map +0 -1
- package/dist/engine-VTQo0qUy.js +0 -2
- package/dist/internal-aic-status-CCvU7zhC.js.map +0 -1
- package/dist/internal-prompt-submit-B1nd4y4V.js +0 -213
- package/dist/internal-prompt-submit-B1nd4y4V.js.map +0 -1
- package/dist/peer-mcp-personas-C200IycG.js.map +0 -1
- package/dist/prompt-submit-hook-wjuHUrpS.js.map +0 -1
- package/dist/server-setup-R1HQtpR9.js.map +0 -1
package/dist/hooks.mjs
CHANGED
|
@@ -35471,41 +35471,65 @@ function parseNeedMoreQuery(solText) {
|
|
|
35471
35471
|
return solText.slice(idx + 10).split("\n", 1)[0]?.trim().slice(0, 280) ?? "";
|
|
35472
35472
|
}
|
|
35473
35473
|
/**
|
|
35474
|
-
* System prompt for the Sol rewriter.
|
|
35475
|
-
*
|
|
35476
|
-
*
|
|
35477
|
-
*
|
|
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.
|
|
35478
35492
|
*/
|
|
35479
35493
|
function buildSolRewriteSystem(opts) {
|
|
35480
35494
|
const searchNoun = opts.bluebirdEnabled ? "Bluebird lexical + semantic code search" : opts.searchEnabled ? "local lexical + semantic code search" : "lexical code search";
|
|
35481
|
-
return `You are a
|
|
35482
|
-
Turn budget: you have at most ${opts.turnBudget} tool turns TOTAL (search/read). You may use ZERO tools and
|
|
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.`;
|
|
35483
35497
|
}
|
|
35484
|
-
/** Assemble the capped static pack Sol sees (static-first for cache hits).
|
|
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. */
|
|
35485
35501
|
function buildStaticContextPack(pack) {
|
|
35486
35502
|
const parts = [`USER REQUEST:\n${pack.prompt}`];
|
|
35487
35503
|
if (pack.agentsMd.trim().length > 0) parts.push(`REPO GUIDANCE (AGENTS.md):\n${pack.agentsMd.slice(0, CHEAPEST_REWRITE_GUIDANCE_CAP)}`);
|
|
35488
35504
|
if (pack.claudeMd.trim().length > 0) parts.push(`REPO GUIDANCE (CLAUDE.md):\n${pack.claudeMd.slice(0, CHEAPEST_REWRITE_GUIDANCE_CAP)}`);
|
|
35489
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));
|
|
35490
35507
|
if (pack.searchContext.trim().length > 0) parts.push(pack.searchContext);
|
|
35491
35508
|
return parts.join("\n\n");
|
|
35492
35509
|
}
|
|
35493
35510
|
/**
|
|
35494
|
-
* Wrap Sol's raw
|
|
35511
|
+
* Wrap Sol's raw contract as the additive Luna-facing block. Returns "" when
|
|
35495
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.
|
|
35496
35518
|
*/
|
|
35497
35519
|
function wrapLunaBrief(solText) {
|
|
35498
35520
|
const body = solText.replace(DEEP_GROUNDING_FLAG, "").split("\n").filter((line) => !line.trimStart().startsWith(NEED_MORE_PREFIX)).join("\n").trim();
|
|
35499
35521
|
if (body.length === 0) return "";
|
|
35500
|
-
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}`;
|
|
35501
35523
|
}
|
|
35502
35524
|
/**
|
|
35503
|
-
* Run the adaptive rewrite. Returns
|
|
35504
|
-
* anything is missing/empty/over-budget
|
|
35505
|
-
* existing V2 scope/goal path
|
|
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.
|
|
35506
35530
|
*/
|
|
35507
35531
|
async function runCheapestRewrite(input) {
|
|
35508
|
-
const timeoutMs = input.io.timeoutMs ??
|
|
35532
|
+
const timeoutMs = input.io.timeoutMs ?? 3e4;
|
|
35509
35533
|
const controller = new AbortController();
|
|
35510
35534
|
let timer;
|
|
35511
35535
|
try {
|
|
@@ -35517,7 +35541,8 @@ async function runCheapestRewrite(input) {
|
|
|
35517
35541
|
input.io.staticPack().catch(() => ({
|
|
35518
35542
|
agentsMd: "",
|
|
35519
35543
|
claudeMd: "",
|
|
35520
|
-
repoStructure: ""
|
|
35544
|
+
repoStructure: "",
|
|
35545
|
+
verifyCommand: ""
|
|
35521
35546
|
}))
|
|
35522
35547
|
]);
|
|
35523
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)}`;
|
|
@@ -35526,6 +35551,7 @@ async function runCheapestRewrite(input) {
|
|
|
35526
35551
|
agentsMd: statik.agentsMd,
|
|
35527
35552
|
claudeMd: statik.claudeMd,
|
|
35528
35553
|
repoStructure: statik.repoStructure,
|
|
35554
|
+
verifyCommand: statik.verifyCommand,
|
|
35529
35555
|
searchContext
|
|
35530
35556
|
});
|
|
35531
35557
|
const first = await input.io.inferSol(buildSolRewriteSystem({
|
|
@@ -35540,7 +35566,8 @@ async function runCheapestRewrite(input) {
|
|
|
35540
35566
|
const brief = wrapLunaBrief(first);
|
|
35541
35567
|
return brief.length > 0 ? brief : null;
|
|
35542
35568
|
}
|
|
35543
|
-
const
|
|
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)}`;
|
|
35544
35571
|
if (extra.trim().length === 0) {
|
|
35545
35572
|
const brief = wrapLunaBrief(first);
|
|
35546
35573
|
return brief.length > 0 ? brief : null;
|
|
@@ -35549,7 +35576,7 @@ async function runCheapestRewrite(input) {
|
|
|
35549
35576
|
searchEnabled: input.searchEnabled,
|
|
35550
35577
|
bluebirdEnabled: input.bluebirdEnabled,
|
|
35551
35578
|
turnBudget: 5
|
|
35552
|
-
}), `${user}\n\nFOLLOW-UP GROUNDING for "${followUp}":\n${extra
|
|
35579
|
+
}), `${user}\n\nFOLLOW-UP GROUNDING for "${followUp}":\n${extra}\n\nRewrite the contract with this grounding (same rules, short).`, controller.signal).catch(() => "");
|
|
35553
35580
|
const brief = wrapLunaBrief(second.trim().length > 0 ? second : first);
|
|
35554
35581
|
return brief.length > 0 ? brief : null;
|
|
35555
35582
|
})();
|
|
@@ -35557,10 +35584,23 @@ async function runCheapestRewrite(input) {
|
|
|
35557
35584
|
const raced = await Promise.race([work, new Promise((resolve) => {
|
|
35558
35585
|
timer = setTimeout(() => resolve("__timeout__"), timeoutMs);
|
|
35559
35586
|
})]);
|
|
35560
|
-
if (raced === "__timeout__"
|
|
35561
|
-
|
|
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
|
+
};
|
|
35562
35599
|
} catch {
|
|
35563
|
-
return
|
|
35600
|
+
return {
|
|
35601
|
+
brief: null,
|
|
35602
|
+
timedOut: false
|
|
35603
|
+
};
|
|
35564
35604
|
} finally {
|
|
35565
35605
|
if (timer) clearTimeout(timer);
|
|
35566
35606
|
controller.abort();
|
|
@@ -35693,16 +35733,27 @@ async function decidePromptSubmitV2(input) {
|
|
|
35693
35733
|
rewriteDisabled: input.rewriteDisabled === true
|
|
35694
35734
|
}) && sessionId.length > 0 && !await input.rewrite.hasRewriteRun(sessionId).catch(() => true)) {
|
|
35695
35735
|
await input.rewrite.markRewriteRun(sessionId).catch(() => {});
|
|
35696
|
-
const
|
|
35736
|
+
const rewrite = await runCheapestRewrite({
|
|
35697
35737
|
prompt,
|
|
35698
35738
|
searchEnabled,
|
|
35699
35739
|
bluebirdEnabled,
|
|
35700
35740
|
io: input.rewrite
|
|
35701
|
-
}).catch(() =>
|
|
35702
|
-
|
|
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) {
|
|
35703
35754
|
decision.inject = joinSections([
|
|
35704
35755
|
searchTip,
|
|
35705
|
-
|
|
35756
|
+
PROMPT_STEER_GOAL,
|
|
35706
35757
|
findingsBlock
|
|
35707
35758
|
]);
|
|
35708
35759
|
return decision;
|
|
@@ -35789,13 +35840,312 @@ function readCappedFile(absPath, cap) {
|
|
|
35789
35840
|
}
|
|
35790
35841
|
}
|
|
35791
35842
|
/**
|
|
35792
|
-
*
|
|
35793
|
-
*
|
|
35794
|
-
*
|
|
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 "".
|
|
35795
36143
|
*/
|
|
35796
36144
|
function buildStaticPack(workspace) {
|
|
35797
|
-
const
|
|
35798
|
-
const
|
|
36145
|
+
const root = resolveProjectRoot(workspace);
|
|
36146
|
+
const guidance = readHierarchicalGuidance(workspace, root);
|
|
36147
|
+
const agentsMd = guidance.agentsMd;
|
|
36148
|
+
const claudeMd = agentsMd.length > 0 ? "" : guidance.claudeMd;
|
|
35799
36149
|
let listing;
|
|
35800
36150
|
try {
|
|
35801
36151
|
listing = readdirSync(workspace, { withFileTypes: true }).slice(0, 60).map((e) => e.isDirectory() ? `${e.name}/` : e.name).join(", ");
|
|
@@ -35803,20 +36153,22 @@ function buildStaticPack(workspace) {
|
|
|
35803
36153
|
listing = "";
|
|
35804
36154
|
}
|
|
35805
36155
|
let pkgSnippet;
|
|
35806
|
-
|
|
35807
|
-
|
|
35808
|
-
|
|
35809
|
-
|
|
35810
|
-
} catch {
|
|
35811
|
-
pkgSnippet = "";
|
|
35812
|
-
}
|
|
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);
|
|
35813
36160
|
return {
|
|
35814
36161
|
agentsMd,
|
|
35815
36162
|
claudeMd,
|
|
35816
|
-
repoStructure: [
|
|
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)
|
|
35817
36169
|
};
|
|
35818
36170
|
}
|
|
35819
|
-
var SEARCH_TIMEOUT_MS, INFER_TIMEOUT_MS, REWRITE_TIMEOUT_MS, internalPromptSubmit;
|
|
36171
|
+
var SEARCH_TIMEOUT_MS, INFER_TIMEOUT_MS, REWRITE_TIMEOUT_MS, PROJECT_ROOT_MARKERS, SCAN_SKIP_DIRS, NO_VERIFICATION, internalPromptSubmit;
|
|
35820
36172
|
var init_internal_prompt_submit = __esmMin((() => {
|
|
35821
36173
|
init_dist$1();
|
|
35822
36174
|
init_cheapest_prompt_rewrite();
|
|
@@ -35826,8 +36178,44 @@ var init_internal_prompt_submit = __esmMin((() => {
|
|
|
35826
36178
|
init_prompt_submit_hook();
|
|
35827
36179
|
init_stop_gate_policy();
|
|
35828
36180
|
SEARCH_TIMEOUT_MS = 8e3;
|
|
35829
|
-
INFER_TIMEOUT_MS =
|
|
35830
|
-
REWRITE_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
|
+
};
|
|
35831
36219
|
internalPromptSubmit = defineCommand({
|
|
35832
36220
|
meta: {
|
|
35833
36221
|
name: "internal-prompt-submit",
|
|
@@ -39127,7 +39515,16 @@ var init_copilot_discount = __esmMin((() => {
|
|
|
39127
39515
|
* Segment order (left = highest priority; narrow terminals drop from the
|
|
39128
39516
|
* right, `AIC` is never dropped):
|
|
39129
39517
|
*
|
|
39130
|
-
* `[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.
|
|
39131
39528
|
*
|
|
39132
39529
|
* The `$` segment is the DISCOUNTED actual (`~$` = factor-discounted
|
|
39133
39530
|
* session total from `copilot-discount.ts`, capped at AIC × $0.01) — NOT
|
|
@@ -39171,6 +39568,8 @@ function parseStatusInput(raw) {
|
|
|
39171
39568
|
if (ctx) {
|
|
39172
39569
|
const pct = finiteNumber(ctx.used_percentage);
|
|
39173
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);
|
|
39174
39573
|
const tIn = finiteNumber(ctx.total_input_tokens);
|
|
39175
39574
|
if (tIn !== void 0 && tIn >= 0) out.totalInputTokens = Math.floor(tIn);
|
|
39176
39575
|
const tOut = finiteNumber(ctx.total_output_tokens);
|
|
@@ -39201,6 +39600,18 @@ function compactTokens(n) {
|
|
|
39201
39600
|
if (n >= 1e3) return `${(n / 1e3).toFixed(1)}k`;
|
|
39202
39601
|
return `${n}`;
|
|
39203
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
|
+
}
|
|
39204
39615
|
/** `45000` → `0m45s`, `198000` → `3m18s`, `3720000` → `1h02m`. */
|
|
39205
39616
|
function formatDurationMs(ms) {
|
|
39206
39617
|
const totalSeconds = Math.floor(ms / 1e3);
|
|
@@ -39216,10 +39627,18 @@ function dirLeaf(cwd) {
|
|
|
39216
39627
|
const parts = trimmed.split(/[/\\]/);
|
|
39217
39628
|
return parts[parts.length - 1] ?? trimmed;
|
|
39218
39629
|
}
|
|
39219
|
-
|
|
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);
|
|
39220
39639
|
if (usedPct === void 0 || !Number.isFinite(usedPct)) return {
|
|
39221
|
-
text: `${DIM}[----------] --%${RESET}`,
|
|
39222
|
-
plain:
|
|
39640
|
+
text: `${DIM}[----------] --%${RESET}${DIM}${WINDOW_JOINER}${win}${RESET}`,
|
|
39641
|
+
plain: `[----------] --%${WINDOW_JOINER}${win}`
|
|
39223
39642
|
};
|
|
39224
39643
|
const u = Math.max(0, Math.min(100, Math.round(usedPct)));
|
|
39225
39644
|
let filled = Math.round(u / 100 * CTX_BAR_LEN);
|
|
@@ -39227,8 +39646,8 @@ function buildCtxSegment(usedPct) {
|
|
|
39227
39646
|
if (filled < 0) filled = 0;
|
|
39228
39647
|
const bar = `#`.repeat(filled) + `-`.repeat(CTX_BAR_LEN - filled);
|
|
39229
39648
|
return {
|
|
39230
|
-
text: `${u < 50 ? GREEN : u < 75 ? YELLOW : RED}[${bar}] ${u}%${RESET}`,
|
|
39231
|
-
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}`
|
|
39232
39651
|
};
|
|
39233
39652
|
}
|
|
39234
39653
|
/**
|
|
@@ -39358,13 +39777,15 @@ function terminalWidth(env = process.env) {
|
|
|
39358
39777
|
* PINNED — it renders even when nothing else fits. `actualUsd` feeds the
|
|
39359
39778
|
* `~$` segment (the capped factor-discounted total from
|
|
39360
39779
|
* `discountedUsdForSnapshot`, same snapshot the fragment came from).
|
|
39361
|
-
* Droppable segments in priority order: ctx, model, dir/git,
|
|
39362
|
-
* 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.
|
|
39363
39784
|
*/
|
|
39364
39785
|
function assembleStatusLine(aicFragment, input, opts = {}) {
|
|
39365
39786
|
const aic = aicFragment.trim();
|
|
39366
39787
|
const aicText = aic ? `${AIC_COLOR}${aic}${RESET}` : "";
|
|
39367
|
-
const droppable = [buildCtxSegment(input.usedPct)];
|
|
39788
|
+
const droppable = [buildCtxSegment(input.usedPct, input.windowSize)];
|
|
39368
39789
|
const model = buildModelSegment(input.modelName);
|
|
39369
39790
|
if (model) droppable.push(model);
|
|
39370
39791
|
const dirGit = buildDirGitSegment(input.cwd, opts.branch);
|
|
@@ -39405,7 +39826,7 @@ function buildRichStatusLine(stdinRaw, aicFragment, opts = {}) {
|
|
|
39405
39826
|
...opts.actualUsd !== void 0 ? { actualUsd: opts.actualUsd } : {}
|
|
39406
39827
|
});
|
|
39407
39828
|
}
|
|
39408
|
-
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;
|
|
39409
39830
|
var init_default_statusline = __esmMin((() => {
|
|
39410
39831
|
init_copilot_discount();
|
|
39411
39832
|
init_exec();
|
|
@@ -39424,6 +39845,8 @@ var init_default_statusline = __esmMin((() => {
|
|
|
39424
39845
|
GIT_TIMEOUT_MS = 300;
|
|
39425
39846
|
WIDTH_FALLBACK = 120;
|
|
39426
39847
|
SEP_TEXT = `${DIM} | ${RESET}`;
|
|
39848
|
+
WINDOW_JOINER = "·";
|
|
39849
|
+
UNKNOWN_WINDOW = "--";
|
|
39427
39850
|
}));
|
|
39428
39851
|
//#endregion
|
|
39429
39852
|
//#region src/internal-aic-status.ts
|