omp-alamode 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +139 -2
- package/package.json +42 -4
- package/src/credit-balance.ts +237 -0
- package/src/flymode.ts +1 -0
- package/src/lemmeaskchat.ts +1 -0
- package/src/let-me-see.ts +1 -0
- package/src/tokenmunchers.ts +1 -0
- package/src/usage-awareness.ts +306 -0
- package/src/usage-knowledge.ts +714 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Carter Hendricks
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,140 @@
|
|
|
1
|
-
#
|
|
1
|
+
# omp-alamode
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Four [Oh My Pi (`omp`)](https://github.com/can1357/oh-my-pi) plugins in one package, plus optional usage awareness for context, costs, and provider quotas.
|
|
4
|
+
|
|
5
|
+
## Included features
|
|
6
|
+
|
|
7
|
+
| Feature | Command | Plugin |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| Discord questions and away-mode conversations | `/lemmeaskchat` | `omp-lemmeaskchat` |
|
|
10
|
+
| Token-usage leaderboard | `/munch` | `omp-tokenmunchers` |
|
|
11
|
+
| Live multi-agent dashboard | `/agent-tree` | `omp-let-me-see` |
|
|
12
|
+
| Display-only fly-language masking | `/flymode` | `omp-flymode` |
|
|
13
|
+
| Context, session usage, quota information, and manual credit estimates | `/usage-awareness` | Built in |
|
|
14
|
+
|
|
15
|
+
The four upstream plugins keep their original behavior and configuration. This package loads them together; it does not replace their implementations or add a shared settings layer.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Requires **Bun 1.3.0 or later** and **omp 18.20.2 or later**.
|
|
20
|
+
|
|
21
|
+
Once the package is published to npm:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
omp plugin install omp-alamode
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Start a new `omp` session after installing.
|
|
28
|
+
|
|
29
|
+
**Avoid duplicate loading:** uninstall or disable standalone copies of `omp-lemmeaskchat`, `omp-tokenmunchers`, `omp-let-me-see`, and `omp-flymode` before using this bundle. Do not load them separately with `omp -e` alongside it; commands and hooks would register twice.
|
|
30
|
+
|
|
31
|
+
### Setup
|
|
32
|
+
|
|
33
|
+
- **Discord relay:** requires a Discord bot token and your Discord user ID.
|
|
34
|
+
- **Leaderboard:** requires an account and API key; use `/munch login`.
|
|
35
|
+
- **Agent dashboard and fly mode:** no credentials required. Fly mode is off until enabled.
|
|
36
|
+
- **Usage awareness:** no separate credentials or setup. When enabled, it uses the host's existing provider configuration.
|
|
37
|
+
|
|
38
|
+
Existing plugin settings are reused and left untouched. See each upstream plugin's README for its full configuration and command reference:
|
|
39
|
+
|
|
40
|
+
- [lemmeaskchat](https://www.npmjs.com/package/omp-lemmeaskchat)
|
|
41
|
+
- [tokenmunchers](https://www.npmjs.com/package/omp-tokenmunchers)
|
|
42
|
+
- [let-me-see](https://www.npmjs.com/package/omp-let-me-see)
|
|
43
|
+
- [flymode](https://www.npmjs.com/package/omp-flymode)
|
|
44
|
+
|
|
45
|
+
## Usage awareness
|
|
46
|
+
|
|
47
|
+
Usage awareness gives the model a short usage summary for each request. It is **off by default** and must be enabled explicitly.
|
|
48
|
+
|
|
49
|
+
| Command | Action |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| `/usage-awareness` | Toggle on or off |
|
|
52
|
+
| `/usage-awareness on` | Enable for this session |
|
|
53
|
+
| `/usage-awareness off` | Disable and stop adding usage context |
|
|
54
|
+
| `/usage-awareness status` | Show the state and, when enabled, current usage information |
|
|
55
|
+
| `/usage-awareness balance <USD> [low-USD]` | Record a manual credit estimate for the current provider |
|
|
56
|
+
| `/usage-awareness balance clear` | Remove that provider's manual estimate |
|
|
57
|
+
|
|
58
|
+
When enabled, the summary can include:
|
|
59
|
+
|
|
60
|
+
- **Context window:** tokens used, capacity, and remaining space for the active model.
|
|
61
|
+
- **Session usage:** token counts and host-recorded costs, including subagent costs.
|
|
62
|
+
- **Provider quotas:** available limits, remaining allowance, reset times, and report age.
|
|
63
|
+
- **Manual credit estimate:** an estimated remaining dollar range, if you entered a balance.
|
|
64
|
+
|
|
65
|
+
These are separate measurements: context capacity is not a provider quota, and session cost is not a provider invoice.
|
|
66
|
+
|
|
67
|
+
### Privacy and limits
|
|
68
|
+
|
|
69
|
+
While off, the extension makes no provider quota queries and adds no usage context. Setting or clearing a manual balance while off only changes local state; it does not enable awareness or trigger a provider query.
|
|
70
|
+
|
|
71
|
+
All extension state is held in memory. Starting, resuming, switching, or branching a session resets awareness to off and clears manual balances. Nothing is saved to disk.
|
|
72
|
+
|
|
73
|
+
When enabled, quota reads go through the host's public, normalized usage service—not direct provider requests from this extension. Reports up to five minutes old are treated as fresh; older retained reports are historical only. Missing or failed data is unknown, and a past reset time does not prove that allowance has renewed.
|
|
74
|
+
|
|
75
|
+
Quota reports are account-scoped snapshots, not guaranteed allowance for the account used by the next request. Separate account reports are not combined. Raw reports, errors, credentials, and account identifiers are not added to model context.
|
|
76
|
+
|
|
77
|
+
The summary is temporary outgoing context, not saved chat history. Only one copy is added per request, and pending results are discarded after disabling. It adds a small amount of request context but never switches models, changes credentials, aborts tasks, or compacts the session.
|
|
78
|
+
|
|
79
|
+
### Manual pay-as-you-go credit estimates
|
|
80
|
+
|
|
81
|
+
If your provider does not report a usable dollar balance, enter its remaining credit manually:
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
/usage-awareness balance 25
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
This records an estimated starting balance of **$25**, with a default low-credit threshold of **$2.50** (10%). To choose a different threshold:
|
|
88
|
+
|
|
89
|
+
```text
|
|
90
|
+
/usage-awareness balance 25 5
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Amounts are non-negative USD values. The optional threshold is an absolute dollar amount. Each balance belongs to the model provider active when entered; switching providers does not transfer it. An active provider is required to set or clear a balance.
|
|
94
|
+
|
|
95
|
+
The extension records spending baselines when you enter the amount, so earlier recorded costs are not deducted again. It then shows two scenarios, each floored at zero:
|
|
96
|
+
|
|
97
|
+
- **Low scenario:** starting balance minus provider-labelled spending and all recorded task/subagent spending since entry, assuming those child charges used this provider.
|
|
98
|
+
- **High scenario:** starting balance minus provider-labelled spending only.
|
|
99
|
+
|
|
100
|
+
**Both are scenario estimates, not guaranteed bounds. They cannot certify a budget.** Task/subagent charges lack reliable provider attribution. Provider-labelled spending includes recorded assistant and `model_usage` costs for that provider, including entries on inactive branches. Child spending combines the host's subagent total with task-result details, including nested tasks, without double-counting overlaps.
|
|
101
|
+
|
|
102
|
+
The estimate excludes outside-session spending, usage without a recorded USD cost, child `model_usage`, and task/subagent spending absent from task-result details. It is not synchronized with provider billing, quotas, or account balances. Actual remaining credit may be lower; check your provider for the authoritative balance.
|
|
103
|
+
|
|
104
|
+
Re-enter the provider's current balance to correct the estimate after a top-up, outside charge, or billing drift. Re-entry replaces the amount and both spending baselines; it does not add credit to the previous estimate.
|
|
105
|
+
|
|
106
|
+
Possible low-credit and exhaustion reminders use the low scenario, appear only while awareness is enabled, and fire once each per balance entry. Re-entry resets them. They are reminders—not spending caps or enforcement.
|
|
107
|
+
|
|
108
|
+
## Compatibility
|
|
109
|
+
|
|
110
|
+
The declared host minimum is `@oh-my-pi/pi-coding-agent >=18.20.2`. The built-in extension uses the public host interfaces verified against that version.
|
|
111
|
+
|
|
112
|
+
This is not a guarantee that every bundled plugin works on every later host release. In particular, `omp-let-me-see@0.3.0` declares an older optional host peer, `18.8.6`; an optional peer does not establish compatibility.
|
|
113
|
+
|
|
114
|
+
Live provider endpoints, Discord, and leaderboard services require separate credentials and are not covered by the local deterministic tests.
|
|
115
|
+
|
|
116
|
+
## Local development
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
git clone https://github.com/hndrxc/alamode.git
|
|
120
|
+
cd alamode
|
|
121
|
+
bun install
|
|
122
|
+
omp plugin link .
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`omp plugin link .` registers a persistent development link to your checkout. Use it only when you want your local plugin installation to load this directory.
|
|
126
|
+
|
|
127
|
+
Source TypeScript is published as ESM; there is no build step. Each upstream plugin has its own extension entry under `src/`. The built-in extension uses `usage-awareness.ts`, `usage-knowledge.ts`, and `credit-balance.ts`.
|
|
128
|
+
|
|
129
|
+
Run deterministic built-in extension tests and inspect the publish contents with:
|
|
130
|
+
|
|
131
|
+
```sh
|
|
132
|
+
bun test
|
|
133
|
+
npm pack --dry-run --json
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Tests use fake host interfaces and require no provider credentials. They do not replace a compiled-host activation check or live-service testing.
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
MIT © Carter Hendricks
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omp-alamode",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Aggregate Oh My Pi plugin bundle: lemmeaskchat, tokenmunchers, let-me-see, flymode, and built-in session usage awareness with manual PAYG balance estimates",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Carter Hendricks",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"omp-plugin",
|
|
10
|
+
"oh-my-pi",
|
|
11
|
+
"pi-package"
|
|
12
|
+
],
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"omp": {
|
|
19
|
+
"extensions": [
|
|
20
|
+
"src/lemmeaskchat.ts",
|
|
21
|
+
"src/tokenmunchers.ts",
|
|
22
|
+
"src/let-me-see.ts",
|
|
23
|
+
"src/flymode.ts",
|
|
24
|
+
"src/usage-awareness.ts"
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"bun": ">=1.3.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"omp-lemmeaskchat": "^0.3.0",
|
|
32
|
+
"omp-tokenmunchers": "^0.2.0",
|
|
33
|
+
"omp-let-me-see": "^0.3.0",
|
|
34
|
+
"omp-flymode": "^0.1.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@oh-my-pi/pi-coding-agent": ">=18.20.2"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"@oh-my-pi/pi-coding-agent": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manual, session-local credit estimates for the active provider.
|
|
3
|
+
*
|
|
4
|
+
* The operator supplies how much credit remains *now*. We snapshot the cost the
|
|
5
|
+
* host has already recorded for that provider, then subtract later
|
|
6
|
+
* provider-labelled model costs. Task/subagent spend is recorded separately:
|
|
7
|
+
* its aggregate has no provider attribution, so it widens the estimate into a
|
|
8
|
+
* conservative scenario range instead of being silently ignored. The range is a
|
|
9
|
+
* scenario estimate, not a guaranteed bound on real billed credit. Nothing here
|
|
10
|
+
* talks to a provider, reads credentials, or persists across sessions.
|
|
11
|
+
*/
|
|
12
|
+
import type { ExtensionContext, SessionEntry } from "@oh-my-pi/pi-coding-agent";
|
|
13
|
+
|
|
14
|
+
type ReminderLevel = "low" | "exhausted";
|
|
15
|
+
|
|
16
|
+
interface ProviderBalance {
|
|
17
|
+
/** Remaining USD the operator entered at {@link CreditBalances.set}. */
|
|
18
|
+
balance: number;
|
|
19
|
+
lowThreshold: number;
|
|
20
|
+
/** Provider-labelled cost already recorded when the balance was entered. */
|
|
21
|
+
baselineCost: number;
|
|
22
|
+
/** Task/subagent cost already recorded when the balance was entered. */
|
|
23
|
+
baselineChildCost: number;
|
|
24
|
+
/** Highest warning already emitted for this entry; re-entry clears it. */
|
|
25
|
+
reminder?: ReminderLevel;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Sum only costs the host attributed to one provider.
|
|
30
|
+
*
|
|
31
|
+
* Assistant turns and `model_usage` records carry both a provider and their own
|
|
32
|
+
* provider-computed USD cost. Scanning every recorded entry includes off-branch
|
|
33
|
+
* turns, which were still billed. Task tool results never enter this sum: their
|
|
34
|
+
* aggregate child usage has no per-provider breakdown, so adding it by a final
|
|
35
|
+
* resolved model could charge the wrong provider.
|
|
36
|
+
*/
|
|
37
|
+
function providerCost(entries: readonly SessionEntry[], provider: string): number {
|
|
38
|
+
let total = 0;
|
|
39
|
+
for (const entry of entries) {
|
|
40
|
+
if (entry.type === "model_usage") {
|
|
41
|
+
const cost = entry.usage.cost.total;
|
|
42
|
+
if (entry.provider === provider && Number.isFinite(cost) && cost > 0) total += cost;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (entry.type !== "message" || entry.message.role !== "assistant") continue;
|
|
46
|
+
const cost = entry.message.usage.cost.total;
|
|
47
|
+
if (entry.message.provider === provider && Number.isFinite(cost) && cost > 0) total += cost;
|
|
48
|
+
}
|
|
49
|
+
return total;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function usageCost(usage: unknown): number {
|
|
53
|
+
if (usage === null || typeof usage !== "object") return 0;
|
|
54
|
+
if (!("cost" in usage)) return 0;
|
|
55
|
+
const cost = usage.cost;
|
|
56
|
+
if (cost === null || typeof cost !== "object") return 0;
|
|
57
|
+
if (!("total" in cost)) return 0;
|
|
58
|
+
const total = cost.total;
|
|
59
|
+
return typeof total === "number" && Number.isFinite(total) && total > 0 ? total : 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Direct child cost carried by one `TaskToolDetails` object. */
|
|
63
|
+
function taskDetailsCost(details: object): number {
|
|
64
|
+
const top = "usage" in details ? usageCost(details.usage) : 0;
|
|
65
|
+
if (top > 0) return top;
|
|
66
|
+
if (!("results" in details)) return 0;
|
|
67
|
+
const results = details.results;
|
|
68
|
+
if (!Array.isArray(results)) return 0;
|
|
69
|
+
let total = 0;
|
|
70
|
+
for (const result of results) {
|
|
71
|
+
if (result !== null && typeof result === "object" && "usage" in result) {
|
|
72
|
+
total += usageCost(result.usage);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return total;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Sum recorded task-result child cost, including nested `task` details the
|
|
80
|
+
* parent session keeps under `extractedToolData.task`. These totals carry no
|
|
81
|
+
* provider attribution, and child `model_usage` calls are not represented.
|
|
82
|
+
*/
|
|
83
|
+
function nestedTaskCost(details: unknown, seen: Set<object>, includeSelf: boolean): number {
|
|
84
|
+
if (details === null || typeof details !== "object") return 0;
|
|
85
|
+
if (seen.has(details)) return 0;
|
|
86
|
+
seen.add(details);
|
|
87
|
+
|
|
88
|
+
let total = includeSelf ? taskDetailsCost(details) : 0;
|
|
89
|
+
if (!("results" in details)) return total;
|
|
90
|
+
const results = details.results;
|
|
91
|
+
if (!Array.isArray(results)) return total;
|
|
92
|
+
for (const result of results) {
|
|
93
|
+
if (result === null || typeof result !== "object") continue;
|
|
94
|
+
if (!("extractedToolData" in result)) continue;
|
|
95
|
+
const extracted = result.extractedToolData;
|
|
96
|
+
if (extracted === null || typeof extracted !== "object") continue;
|
|
97
|
+
if (!("task" in extracted)) continue;
|
|
98
|
+
const nested = extracted.task;
|
|
99
|
+
if (!Array.isArray(nested)) continue;
|
|
100
|
+
for (const nestedDetails of nested) total += nestedTaskCost(nestedDetails, seen, true);
|
|
101
|
+
}
|
|
102
|
+
return total;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function recordedChildCost(entries: readonly SessionEntry[], reportedSubagentCost: unknown): number {
|
|
106
|
+
let direct = 0;
|
|
107
|
+
let nested = 0;
|
|
108
|
+
const seen = new Set<object>();
|
|
109
|
+
for (const entry of entries) {
|
|
110
|
+
if (entry.type !== "message" || entry.message.role !== "toolResult" || entry.message.toolName !== "task") {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const details = entry.message.details;
|
|
114
|
+
if (details === null || typeof details !== "object") continue;
|
|
115
|
+
direct += taskDetailsCost(details);
|
|
116
|
+
nested += nestedTaskCost(details, seen, false);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const reported =
|
|
120
|
+
typeof reportedSubagentCost === "number" &&
|
|
121
|
+
Number.isFinite(reportedSubagentCost) &&
|
|
122
|
+
reportedSubagentCost > 0
|
|
123
|
+
? reportedSubagentCost
|
|
124
|
+
: 0;
|
|
125
|
+
// The host total and the entry traversal overlap; take the larger total
|
|
126
|
+
// rather than adding both and double-counting completed task results.
|
|
127
|
+
return Math.max(reported, direct + nested);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** At least cents, more precision for tiny positive amounts so they never display as $0.00. */
|
|
131
|
+
function formatUsd(value: number): string {
|
|
132
|
+
if (!Number.isFinite(value)) return "$?";
|
|
133
|
+
if (value === 0) return "$0.00";
|
|
134
|
+
const absolute = Math.abs(value);
|
|
135
|
+
const digits = absolute >= 1 ? 2 : Math.min(10, Math.max(6, 3 - Math.floor(Math.log10(absolute))));
|
|
136
|
+
let text = value.toFixed(digits);
|
|
137
|
+
if (Number(text) === 0) text = value.toExponential(2);
|
|
138
|
+
if (text.includes("e")) return `$${text}`;
|
|
139
|
+
const [whole = "0", fraction = ""] = text.split(".");
|
|
140
|
+
return `$${whole}.${fraction.replace(/0+$/, "").padEnd(2, "0")}`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const SCENARIO_BOUND = "Scenario estimates, not guaranteed bounds; a budget cannot be certified.";
|
|
144
|
+
const ESTIMATE_CAVEAT =
|
|
145
|
+
"Estimate only, not an invoice; also excludes spend outside this session and unpriced usage.";
|
|
146
|
+
|
|
147
|
+
export class CreditBalances {
|
|
148
|
+
#providers = new Map<string, ProviderBalance>();
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Record the operator's current remaining balance for the active provider.
|
|
152
|
+
* Provider-labelled and task/subagent costs already in the session are the
|
|
153
|
+
* baseline, so historical spend is not deducted again. Re-entry replaces the
|
|
154
|
+
* entry and resets reminder state.
|
|
155
|
+
*/
|
|
156
|
+
set(ctx: ExtensionContext, balance: number, lowThreshold?: number): void {
|
|
157
|
+
const provider = ctx.model?.provider;
|
|
158
|
+
if (typeof provider !== "string" || provider.length === 0) {
|
|
159
|
+
throw new TypeError("A credit balance needs an active model provider.");
|
|
160
|
+
}
|
|
161
|
+
if (typeof balance !== "number" || !Number.isFinite(balance) || balance < 0) {
|
|
162
|
+
throw new RangeError("Balance must be a non-negative finite USD amount.");
|
|
163
|
+
}
|
|
164
|
+
const threshold = lowThreshold === undefined ? balance * 0.1 : lowThreshold;
|
|
165
|
+
if (typeof threshold !== "number" || !Number.isFinite(threshold) || threshold < 0) {
|
|
166
|
+
throw new RangeError("Low threshold must be a non-negative finite USD amount.");
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const entries = ctx.sessionManager.getEntries();
|
|
170
|
+
const stats = ctx.sessionManager.getUsageStatistics();
|
|
171
|
+
this.#providers.set(provider, {
|
|
172
|
+
balance,
|
|
173
|
+
lowThreshold: threshold,
|
|
174
|
+
baselineCost: providerCost(entries, provider),
|
|
175
|
+
baselineChildCost: recordedChildCost(entries, stats.subagentCost),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Clear every provider estimate, or just the named provider's. */
|
|
180
|
+
clear(provider?: string): void {
|
|
181
|
+
if (provider === undefined) this.#providers.clear();
|
|
182
|
+
else this.#providers.delete(provider);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Describe the active provider's estimate as a conservative scenario range.
|
|
187
|
+
* The low scenario assumes every recorded task/subagent charge hit this
|
|
188
|
+
* provider; the high scenario excludes them. Reminders use the low scenario
|
|
189
|
+
* and are emitted only for the first possible low reading or newly possible
|
|
190
|
+
* exhaustion.
|
|
191
|
+
*/
|
|
192
|
+
describe(ctx: ExtensionContext): { text: string; reminder?: string } | undefined {
|
|
193
|
+
const provider = ctx.model?.provider;
|
|
194
|
+
if (typeof provider !== "string" || provider.length === 0) return undefined;
|
|
195
|
+
const state = this.#providers.get(provider);
|
|
196
|
+
if (!state) return undefined;
|
|
197
|
+
|
|
198
|
+
const entries = ctx.sessionManager.getEntries();
|
|
199
|
+
const stats = ctx.sessionManager.getUsageStatistics();
|
|
200
|
+
const charged = Math.max(0, providerCost(entries, provider) - state.baselineCost);
|
|
201
|
+
const childCharged = Math.max(0, recordedChildCost(entries, stats.subagentCost) - state.baselineChildCost);
|
|
202
|
+
const upperRaw = state.balance - charged;
|
|
203
|
+
const lowerRaw = upperRaw - childCharged;
|
|
204
|
+
const lower = Math.max(0, lowerRaw);
|
|
205
|
+
const upper = Math.max(0, upperRaw);
|
|
206
|
+
const remaining = lower === upper ? formatUsd(lower) : `${formatUsd(lower)}-${formatUsd(upper)}`;
|
|
207
|
+
|
|
208
|
+
const childNote =
|
|
209
|
+
childCharged > 0
|
|
210
|
+
? `Task/subagent charges are excluded from provider attribution: ${formatUsd(childCharged)} recorded since entry, so the low scenario assumes all of it hit ${provider} and the high scenario excludes it. Task/subagent spend not represented in session task results is also excluded.`
|
|
211
|
+
: `Task/subagent charges are excluded from provider attribution; none were recorded since entry, but any not represented in session task results is also excluded.`;
|
|
212
|
+
|
|
213
|
+
const possibleExhausted = lowerRaw <= 0;
|
|
214
|
+
const possibleLow = !possibleExhausted && lowerRaw <= state.lowThreshold;
|
|
215
|
+
let reminder: string | undefined;
|
|
216
|
+
if (possibleExhausted && state.reminder !== "exhausted") {
|
|
217
|
+
state.reminder = "exhausted";
|
|
218
|
+
reminder =
|
|
219
|
+
`Possible ${provider} credit exhaustion: estimated remaining ${remaining} USD (${SCENARIO_BOUND}). ` +
|
|
220
|
+
`${formatUsd(charged)} charged since entry (provider-labelled). ${childNote} ${ESTIMATE_CAVEAT}`;
|
|
221
|
+
} else if (possibleLow && state.reminder === undefined) {
|
|
222
|
+
state.reminder = "low";
|
|
223
|
+
reminder =
|
|
224
|
+
`Possible ${provider} credit low: estimated remaining ${remaining} USD (${SCENARIO_BOUND}) ` +
|
|
225
|
+
`with low threshold ${formatUsd(state.lowThreshold)}. ` +
|
|
226
|
+
`${formatUsd(charged)} charged since entry (provider-labelled). ${childNote} ${ESTIMATE_CAVEAT}`;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
text:
|
|
231
|
+
`Estimated ${provider} credit: ${remaining} USD remaining of ${formatUsd(state.balance)} entered. ` +
|
|
232
|
+
`${SCENARIO_BOUND} ${formatUsd(charged)} charged since entry (provider-labelled); ` +
|
|
233
|
+
`low threshold ${formatUsd(state.lowThreshold)}. ${childNote} ${ESTIMATE_CAVEAT}`,
|
|
234
|
+
...(reminder === undefined ? {} : { reminder }),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
package/src/flymode.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "omp-flymode";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "omp-lemmeaskchat/src/index.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "omp-let-me-see";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "omp-tokenmunchers";
|