@krtclcdy/tersio 2.25.4 → 2.25.6
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 +27 -63
- package/dashboard/dist/index.html +18 -16
- package/dist/cli/backups.js +187 -0
- package/dist/cli/banner.js +4 -3
- package/dist/cli/common.js +29 -13
- package/dist/cli/currency.js +1 -1
- package/dist/cli/dashboard.js +168 -110
- package/dist/cli/doctor-fix.js +232 -50
- package/dist/cli/doctor.js +281 -32
- package/dist/cli/hosts.js +29 -9
- package/dist/cli/install.js +204 -69
- package/dist/cli/interactive.js +3 -3
- package/dist/cli/manifest.js +125 -17
- package/dist/cli/profile.js +14 -9
- package/dist/cli/rtk-wiring.js +1 -1
- package/dist/cli/settings.js +20 -5
- package/dist/cli/uninstall.js +24 -8
- package/dist/cli/update.js +9 -10
- package/dist/cli/usage.js +75 -7
- package/dist/extensions/{caveman-session → caveman}/index.js +4 -2
- package/{extensions/caveman-session → dist/extensions/caveman}/rule-megacave.md +5 -3
- package/{extensions/caveman-session → dist/extensions/caveman}/rule-ultra.md +4 -4
- package/dist/extensions/caveman/rule.md +89 -0
- package/dist/extensions/{combo-toggle → combo}/index.js +62 -21
- package/dist/extensions/{tersio-commands → commands}/index.js +2 -2
- package/dist/extensions/pstack/index.js +119 -0
- package/dist/extensions/pstack/rule.md +65 -0
- package/dist/extensions/{rtk-filter/index.js → rtk/filter.js} +1 -2
- package/dist/extensions/{rtk-session/index.js → rtk/session.js} +5 -5
- package/dist/extensions/{opencode/server.js → server.js} +98 -14
- package/dist/extensions/shared/agent-stats.js +1198 -0
- package/dist/extensions/shared/brand-marks.js +153 -0
- package/dist/extensions/shared/carbon.js +1 -1
- package/dist/extensions/shared/plugin-settings.js +12 -7
- package/dist/extensions/shared/pricing.js +86 -30
- package/dist/extensions/shared/rtk-gain.js +4 -9
- package/dist/extensions/shared/session-state.js +15 -10
- package/dist/extensions/shared/sqlite.js +168 -0
- package/dist/extensions/shared/status.js +8 -8
- package/dist/extensions/shared/types.js +1 -1
- package/dist/extensions/shared/usage-ledger.js +113 -39
- package/dist/extensions/shared/usage-store.js +191 -48
- package/dist/extensions/{lib → shared}/utils.js +6 -6
- package/dist/extensions/timing/index.js +31 -0
- package/dist/extensions/{ai-addons-updater → updater}/index.js +13 -6
- package/dist/probe-catalog.js +48 -0
- package/dist/probe-catalog188.js +44 -0
- package/dist/tersio.js +9 -4
- package/extensions/{caveman-session → caveman}/index.ts +4 -2
- package/{dist/extensions/caveman-session → extensions/caveman}/rule-megacave.md +5 -3
- package/{dist/extensions/caveman-session → extensions/caveman}/rule-ultra.md +4 -4
- package/extensions/caveman/rule.md +89 -0
- package/extensions/{combo-toggle → combo}/index.ts +62 -19
- package/extensions/{tersio-commands → commands}/index.ts +2 -2
- package/extensions/pstack/index.ts +128 -0
- package/extensions/pstack/rule.md +65 -0
- package/extensions/{rtk-filter/index.ts → rtk/filter.ts} +1 -2
- package/extensions/{rtk-session/index.ts → rtk/session.ts} +5 -5
- package/extensions/{opencode/server.ts → server.ts} +81 -16
- package/extensions/shared/agent-stats.ts +1605 -0
- package/extensions/shared/brand-marks.ts +163 -0
- package/extensions/shared/carbon.ts +1 -1
- package/extensions/shared/plugin-settings.ts +13 -7
- package/extensions/shared/pricing.ts +95 -32
- package/extensions/shared/rtk-gain.ts +4 -9
- package/extensions/shared/session-state.ts +18 -13
- package/extensions/shared/sqlite.ts +168 -0
- package/extensions/shared/status.ts +9 -8
- package/extensions/shared/types.ts +2 -1
- package/extensions/shared/usage-ledger.ts +134 -46
- package/extensions/shared/usage-store.ts +202 -50
- package/extensions/{lib → shared}/utils.ts +6 -6
- package/extensions/timing/index.ts +45 -0
- package/extensions/{ai-addons-updater → updater}/index.ts +15 -9
- package/package.json +27 -18
- package/dist/extensions/caveman-session/rule.md +0 -79
- package/extensions/caveman-session/rule.md +0 -79
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// Brand mark catalog: names not bytes; Simple Icons files are CC0-1.0, marks remain their owners'.
|
|
2
|
+
const SIMPLE_ICONS = "https://cdn.jsdelivr.net/npm/simple-icons@16/icons";
|
|
3
|
+
|
|
4
|
+
/** Slug to mark URL. Only slugs named here resolve to a mark; the rest get a monogram. */
|
|
5
|
+
export const REMOTE_MARKS: Readonly<Record<string, string>> = {
|
|
6
|
+
// Simple Icons, CC0-1.0.
|
|
7
|
+
anthropic: `${SIMPLE_ICONS}/anthropic.svg`,
|
|
8
|
+
google: `${SIMPLE_ICONS}/google.svg`,
|
|
9
|
+
meta: `${SIMPLE_ICONS}/meta.svg`,
|
|
10
|
+
deepseek: `${SIMPLE_ICONS}/deepseek.svg`,
|
|
11
|
+
qwen: `${SIMPLE_ICONS}/qwen.svg`,
|
|
12
|
+
x: `${SIMPLE_ICONS}/x.svg`,
|
|
13
|
+
mistralai: `${SIMPLE_ICONS}/mistralai.svg`,
|
|
14
|
+
minimax: `${SIMPLE_ICONS}/minimax.svg`,
|
|
15
|
+
zdotai: `${SIMPLE_ICONS}/zdotai.svg`,
|
|
16
|
+
xiaomi: `${SIMPLE_ICONS}/xiaomi.svg`,
|
|
17
|
+
kimi: `${SIMPLE_ICONS}/kimi.svg`,
|
|
18
|
+
moonshotai: `${SIMPLE_ICONS}/moonshotai.svg`,
|
|
19
|
+
nvidia: `${SIMPLE_ICONS}/nvidia.svg`,
|
|
20
|
+
amd: `${SIMPLE_ICONS}/amd.svg`,
|
|
21
|
+
ollama: `${SIMPLE_ICONS}/ollama.svg`,
|
|
22
|
+
cline: `${SIMPLE_ICONS}/cline.svg`,
|
|
23
|
+
githubcopilot: `${SIMPLE_ICONS}/githubcopilot.svg`,
|
|
24
|
+
openrouter: `${SIMPLE_ICONS}/openrouter.svg`,
|
|
25
|
+
github: `${SIMPLE_ICONS}/github.svg`,
|
|
26
|
+
instagram: `${SIMPLE_ICONS}/instagram.svg`,
|
|
27
|
+
reddit: `${SIMPLE_ICONS}/reddit.svg`,
|
|
28
|
+
// Owner-hosted, nominative use.
|
|
29
|
+
groq: "https://groq.com/favicon.svg",
|
|
30
|
+
poolside: "https://poolside.ai/favicon/favicon.svg",
|
|
31
|
+
// AWS owns Kiro; Wikimedia hosts its vector, as AWS serves only a 16x16 ICO that cannot grow into a tile.
|
|
32
|
+
amazonaws: "https://upload.wikimedia.org/wikipedia/commons/5/5c/AWS_Simple_Icons_AWS_Cloud.svg",
|
|
33
|
+
cerebras:
|
|
34
|
+
"https://cdn.sanity.io/images/e4qjo92p/production/e7a55ae5ab7e2c4fdfd4e66a51f628d1f2f44207-967x967.png?w=256&h=256&fit=max",
|
|
35
|
+
inclusionai: "https://cdn-avatars.huggingface.co/v1/production/uploads/662e1f9da266499277937d33/fyKuazRifqiaIO34xrhhm.jpeg",
|
|
36
|
+
// Owner avatars: the vendor or gateway posts no standalone icon, so its account picture stands in.
|
|
37
|
+
stepfun: "https://cdn-avatars.huggingface.co/v1/production/uploads/644f7e6233ac8f46fa0b9e26/CmF2ocXhkr2UtHXgmwq7-.png",
|
|
38
|
+
// typesafe.ai serves one full-bleed tile: a dark square with pink art inside it.
|
|
39
|
+
typesafe: "https://framerusercontent.com/images/aNFzSFxM4fjICmnibw7npfZjcQ.png",
|
|
40
|
+
// A gateway's own brand, which names the service that served the request. Never another vendor's logo.
|
|
41
|
+
opencode: "https://opencode.ai/favicon.svg",
|
|
42
|
+
commandcode: "https://commandcode.ai/favicon.ico",
|
|
43
|
+
kilo: "https://kilo.ai/favicon.ico",
|
|
44
|
+
magpie: "https://usemagpie.ai/favicon.png",
|
|
45
|
+
gmicloud: "https://gmicloud.ai/favicon.ico",
|
|
46
|
+
charmhyper: "https://github.com/charmbracelet.png?size=80",
|
|
47
|
+
// WorkBuddy's own favicon, a hashed asset on the Tencent CDN its page serves.
|
|
48
|
+
workbuddy:
|
|
49
|
+
"https://download.codebuddy.ai/web/workbuddy/913b2390aae396c66b937bd9143ae5259306d7d7/assets/logo.svg",
|
|
50
|
+
// Trae's own favicon: a dark tile carrying its green mark, so the tile matches the artwork.
|
|
51
|
+
trae: "https://lf16-web-neutral.traecdn.ai/obj/trae-ai-static/trae_website/favicon.png",
|
|
52
|
+
// Kiro's own icon, a purple tile with the mark drawn inside it.
|
|
53
|
+
kiro: "https://kiro.dev/icon.svg",
|
|
54
|
+
// Meituan's own icon: its yellow tile with the logotype.
|
|
55
|
+
meituan: "https://s3plus.meituan.net/v1/mss_e2821d7f0cfe4ac1bf9202ecf9590e67/cdn-prod/file:1040877d/favicon-mt.ico",
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** Tile fill per slug from the brand's own page, never a guess; an absent slug keeps the plain panel. */
|
|
59
|
+
export const MARK_BG: Readonly<Record<string, string>> = {
|
|
60
|
+
// Simple Icons marks: the vendor's brand color, taken from its own brand page.
|
|
61
|
+
anthropic: "#d97757",
|
|
62
|
+
meta: "#0082fb",
|
|
63
|
+
google: "#4285f4",
|
|
64
|
+
deepseek: "#4d6bfe",
|
|
65
|
+
qwen: "#6950ef",
|
|
66
|
+
mistralai: "#ff7000",
|
|
67
|
+
minimax: "#e11d48",
|
|
68
|
+
// Kimi's own favicon carries this blue, not the Moonshot violet.
|
|
69
|
+
kimi: "#1782fe",
|
|
70
|
+
xiaomi: "#ff6900",
|
|
71
|
+
nvidia: "#76b900",
|
|
72
|
+
amd: "#ed1c24",
|
|
73
|
+
x: "#000000",
|
|
74
|
+
ollama: "#000000",
|
|
75
|
+
zdotai: "#2d2d2d",
|
|
76
|
+
github: "#181717",
|
|
77
|
+
githubcopilot: "#181717",
|
|
78
|
+
cline: "#9f58fa",
|
|
79
|
+
openrouter: "#03080a",
|
|
80
|
+
instagram: "#e4405f",
|
|
81
|
+
reddit: "#ff4500",
|
|
82
|
+
linkedin: "#0a66c2",
|
|
83
|
+
// Owner-hosted marks match the asset's own square; art that already carries color takes a white tile.
|
|
84
|
+
groq: "#f43e01",
|
|
85
|
+
poolside: "#4137ff",
|
|
86
|
+
cerebras: "#ffffff",
|
|
87
|
+
typesafe: "#171717",
|
|
88
|
+
charmhyper: "#ffffff",
|
|
89
|
+
stepfun: "#ffffff",
|
|
90
|
+
kilo: "#f7f576",
|
|
91
|
+
opencode: "#131010",
|
|
92
|
+
// The AWS cloud mark draws its own orange and its own white, so the tile stays plain white.
|
|
93
|
+
amazonaws: "#ffffff",
|
|
94
|
+
// The mark's own artwork is white, so the tile is white and the glyph is black.
|
|
95
|
+
openai: "#ffffff",
|
|
96
|
+
commandcode: "#ffffff",
|
|
97
|
+
gmicloud: "#ffffff",
|
|
98
|
+
magpie: "#0b0b0c",
|
|
99
|
+
// WorkBuddy's mark is a full-bleed teal tile carrying its own white art.
|
|
100
|
+
workbuddy: "#01c886",
|
|
101
|
+
// The mark is a full-bleed tile, so the tile fill repeats the artwork's own background.
|
|
102
|
+
trae: "#000000",
|
|
103
|
+
kiro: "#9046ff",
|
|
104
|
+
meituan: "#ffd100",
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/** Glyph scale per slug over the tile clip; the measured ink box decides, and one is the default. */
|
|
108
|
+
export const MARK_SCALE: Readonly<Record<string, number>> = {
|
|
109
|
+
kimi: 0.72,
|
|
110
|
+
zdotai: 0.72,
|
|
111
|
+
openrouter: 0.9,
|
|
112
|
+
magpie: 1.15,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** WCAG relative luminance of a `#rrggbb` string. */
|
|
116
|
+
export function luminance(hex: string): number {
|
|
117
|
+
const n = parseInt(hex.slice(1), 16);
|
|
118
|
+
const ch = [(n >> 16) & 255, (n >> 8) & 255, n & 255].map((v) => {
|
|
119
|
+
const s = v / 255;
|
|
120
|
+
return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
|
|
121
|
+
});
|
|
122
|
+
return 0.2126 * ch[0] + 0.7152 * ch[1] + 0.0722 * ch[2];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The ink legible on a tile fill: luminance above 0.35 takes black, else white. */
|
|
126
|
+
export function contrastInk(hex: string): string {
|
|
127
|
+
return luminance(hex) > 0.35 ? "#000000" : "#ffffff";
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Marks carrying their own color or background; a filled-tile asset must draw as an image, not a mask. */
|
|
131
|
+
export const COLORED_MARKS: ReadonlySet<string> = new Set([
|
|
132
|
+
"cerebras",
|
|
133
|
+
"inclusionai",
|
|
134
|
+
"typesafe",
|
|
135
|
+
"opencode",
|
|
136
|
+
"commandcode",
|
|
137
|
+
"kilo",
|
|
138
|
+
"magpie",
|
|
139
|
+
"charmhyper",
|
|
140
|
+
"stepfun",
|
|
141
|
+
// The ICO and inline PNGs are dark tiles with light art; flat-orange Groq draws as a mask instead.
|
|
142
|
+
"gmicloud",
|
|
143
|
+
"stealth",
|
|
144
|
+
"cognition",
|
|
145
|
+
// A full-bleed teal tile with its own white art, so a mask would flatten both into one ink.
|
|
146
|
+
"workbuddy",
|
|
147
|
+
// Each is a full-bleed brand tile with its own ink, so a mask would flatten both into one color.
|
|
148
|
+
"trae",
|
|
149
|
+
"kiro",
|
|
150
|
+
"meituan",
|
|
151
|
+
// Carries its own orange and its own white, so a mask would flatten both into one ink.
|
|
152
|
+
"amazonaws",
|
|
153
|
+
]);
|
|
154
|
+
|
|
155
|
+
/** The URL a mark comes from, or null when the name has no hosted mark. */
|
|
156
|
+
export function markUrl(slug: string): string | null {
|
|
157
|
+
return REMOTE_MARKS[slug] ?? null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** True when the mark carries its own color and must draw as an image. */
|
|
161
|
+
export function isColoredMark(slug: string): boolean {
|
|
162
|
+
return COLORED_MARKS.has(slug);
|
|
163
|
+
}
|
|
@@ -44,7 +44,7 @@ interface RegistryEntry {
|
|
|
44
44
|
source: 'registry' | 'borrowed';
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
//
|
|
47
|
+
// Verbatim from EcoLogits' model_repository; borrows cite the param disclosure they replace (MoE active/total).
|
|
48
48
|
const TABLE: RegistryEntry[] = [
|
|
49
49
|
{ match: 'opus', active: 625.0, total: 2000, provider: 'anthropic', source: 'registry' },
|
|
50
50
|
{ match: 'sonnet', active: 137.5, total: 440, provider: 'anthropic', source: 'registry' },
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { homeDir, tersioHome } from '
|
|
5
|
+
import { homeDir, tersioHome } from './utils.ts';
|
|
6
6
|
|
|
7
7
|
export const PLUGIN_NAME = '@krtclcdy/tersio';
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ export function tersioSettingsFile(): string {
|
|
|
11
11
|
return path.join(tersioHome(), 'settings.json');
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
// Older installs kept these as OMP plugin settings; still read so switching
|
|
14
|
+
// Older installs kept these as OMP plugin settings; still read so switching stores does not reset a user's defaults.
|
|
15
15
|
function legacyOmpSettings(): Record<string, unknown> | null {
|
|
16
16
|
const configHome = process.env.XDG_CONFIG_HOME || path.join(homeDir(), '.config');
|
|
17
17
|
for (const p of [
|
|
@@ -39,7 +39,7 @@ function readSettingsFile(): Record<string, unknown> | null {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
// The stored settings;
|
|
42
|
+
// The stored settings; {} when the file is missing or corrupt.
|
|
43
43
|
export function readPluginSettings(): Record<string, unknown> {
|
|
44
44
|
return readSettingsFile() ?? legacyOmpSettings() ?? {};
|
|
45
45
|
}
|
|
@@ -47,6 +47,8 @@ export function readPluginSettings(): Record<string, unknown> {
|
|
|
47
47
|
const COMBO_LEVELS = new Set(['off', 'medium', 'balanced', 'max']);
|
|
48
48
|
const CAVEMAN_MODES = new Set(['off', 'lite', 'full', 'ultra', 'megacave', 'megacave-lite', 'megacave-full', 'megacave-ultra', 'wenyan', 'wenyan-lite', 'wenyan-full', 'wenyan-ultra']);
|
|
49
49
|
const PONYTAIL_MODES = new Set(['off', 'lite', 'full', 'ultra']);
|
|
50
|
+
// Opt-in only: no combo preset writes this, so it never reaches a user who did not ask for it.
|
|
51
|
+
const PSTACK_MODES = new Set(['off', 'on']);
|
|
50
52
|
|
|
51
53
|
function readStringDefault(key: string, valid: Set<string>): string {
|
|
52
54
|
const raw = readPluginSettings()[key];
|
|
@@ -70,15 +72,19 @@ export function readPonytailDefault(): string {
|
|
|
70
72
|
return readStringDefault('ponytailDefault', PONYTAIL_MODES);
|
|
71
73
|
}
|
|
72
74
|
|
|
75
|
+
export function readPstackDefault(): string {
|
|
76
|
+
return readStringDefault('pstackDefault', PSTACK_MODES);
|
|
77
|
+
}
|
|
78
|
+
|
|
73
79
|
export function isComboSetupComplete(): boolean {
|
|
74
80
|
return readPluginSettings().comboSetupComplete === true;
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
const COMBO_MODE_DEFAULTS = {
|
|
78
|
-
off: { cavemanDefault: 'off', rtkDefault: false, ponytailDefault: 'off' },
|
|
79
|
-
medium: { cavemanDefault: 'lite', rtkDefault: true, ponytailDefault: 'lite' },
|
|
80
|
-
balanced: { cavemanDefault: 'full', rtkDefault: true, ponytailDefault: 'full' },
|
|
81
|
-
max: { cavemanDefault: 'ultra', rtkDefault: true, ponytailDefault: 'ultra' },
|
|
84
|
+
off: { cavemanDefault: 'off', rtkDefault: false, ponytailDefault: 'off', pstackDefault: 'off' },
|
|
85
|
+
medium: { cavemanDefault: 'lite', rtkDefault: true, ponytailDefault: 'lite', pstackDefault: 'on' },
|
|
86
|
+
balanced: { cavemanDefault: 'full', rtkDefault: true, ponytailDefault: 'full', pstackDefault: 'on' },
|
|
87
|
+
max: { cavemanDefault: 'ultra', rtkDefault: true, ponytailDefault: 'ultra', pstackDefault: 'on' },
|
|
82
88
|
} as const;
|
|
83
89
|
|
|
84
90
|
export function saveComboSetup(level: string): boolean {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//
|
|
1
|
+
// pricing.ts — model pricing from LiteLLM. Exact id → prefix strip → default, known:false if unpriced.
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { tersioDataPath } from '
|
|
4
|
+
import { tersioDataPath } from './utils.ts';
|
|
5
5
|
|
|
6
6
|
export interface ModelPrice {
|
|
7
7
|
input: number;
|
|
@@ -13,8 +13,21 @@ export interface ModelPrice {
|
|
|
13
13
|
// Sonnet-class default for unpriced models; always paired with known:false.
|
|
14
14
|
export const DEFAULT_PRICE: ModelPrice = { input: 2, output: 10, cacheRead: 0.2, cacheWrite: 2.5 };
|
|
15
15
|
|
|
16
|
+
/** How a price was found, strongest first; `tail` and `default` are estimates. */
|
|
17
|
+
export type PriceTier = 'measured' | 'override' | 'exact' | 'alias' | 'tail' | 'default';
|
|
18
|
+
|
|
19
|
+
/** Tiers firm enough to call a price; `tail` and `default` are estimates. */
|
|
20
|
+
export const PRICE_TIERS_FIRM: readonly PriceTier[] = ['measured', 'override', 'exact', 'alias'];
|
|
21
|
+
|
|
22
|
+
export interface PriceHit {
|
|
23
|
+
price: ModelPrice;
|
|
24
|
+
known: boolean;
|
|
25
|
+
live: boolean;
|
|
26
|
+
tier: PriceTier;
|
|
27
|
+
}
|
|
28
|
+
|
|
16
29
|
const LITELLM_URL = 'https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json';
|
|
17
|
-
// Readers use the file even when stale
|
|
30
|
+
// Readers use the file even when stale; one refresh per process. `tersio update` still forces a fresh fetch.
|
|
18
31
|
const CACHE_TTL_MS = 7 * 24 * 3600 * 1000;
|
|
19
32
|
let refreshInflight: Promise<boolean> | null = null;
|
|
20
33
|
|
|
@@ -24,13 +37,51 @@ export function pricesCachePath(): string {
|
|
|
24
37
|
return tersioDataPath('prices.json', 'tersio-prices.json');
|
|
25
38
|
}
|
|
26
39
|
|
|
40
|
+
/** Operator prices keyed as the transcript spells a model; a `*` prefix matches any gateway suffix. */
|
|
41
|
+
export function pricesOverridePath(): string {
|
|
42
|
+
const override = process.env.TERSIO_PRICES_OVERRIDE_FILE;
|
|
43
|
+
if (override) return override;
|
|
44
|
+
return tersioDataPath('prices.local.json', 'tersio-prices.local.json');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The override file's mtime, or 0 when absent. Callers key their memo on it. */
|
|
48
|
+
function overrideStamp(): number {
|
|
49
|
+
try {
|
|
50
|
+
return fs.statSync(pricesOverridePath()).mtimeMs;
|
|
51
|
+
} catch {
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let overrideCache: { stamp: number; exact: Map<string, ModelPrice>; tails: Array<[string, ModelPrice]> } | null = null;
|
|
57
|
+
|
|
58
|
+
/** Reads the override file, keeping a `*`-prefixed entry as a suffix matcher. */
|
|
59
|
+
function loadOverrides(stamp = overrideStamp()): { exact: Map<string, ModelPrice>; tails: Array<[string, ModelPrice]> } | null {
|
|
60
|
+
if (stamp === 0) return null;
|
|
61
|
+
const file = pricesOverridePath();
|
|
62
|
+
if (overrideCache && overrideCache.stamp === stamp) return overrideCache;
|
|
63
|
+
const exact = new Map<string, ModelPrice>();
|
|
64
|
+
const tails: Array<[string, ModelPrice]> = [];
|
|
65
|
+
try {
|
|
66
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf8')) as Record<string, unknown>;
|
|
67
|
+
for (const [id, row] of Object.entries(parsed ?? {})) {
|
|
68
|
+
const price = asPrice(row);
|
|
69
|
+
if (!price) continue;
|
|
70
|
+
if (id.startsWith('*')) tails.push([id.slice(1).toLowerCase(), price]);
|
|
71
|
+
else exact.set(id, price);
|
|
72
|
+
}
|
|
73
|
+
} catch { /* an unreadable override is empty, not fatal */ }
|
|
74
|
+
overrideCache = { stamp, exact, tails };
|
|
75
|
+
return overrideCache;
|
|
76
|
+
}
|
|
77
|
+
|
|
27
78
|
export function pricesUrl(): string {
|
|
28
79
|
return process.env.TERSIO_PRICES_URL || LITELLM_URL;
|
|
29
80
|
}
|
|
30
81
|
|
|
31
82
|
export interface LivePrices {
|
|
32
83
|
fetchedAt: number;
|
|
33
|
-
//
|
|
84
|
+
// Tuples [input, output, cacheRead, cacheWrite] per LiteLLM id — the full feed caches to ~1MB, not multi-MB objects.
|
|
34
85
|
exact: Record<string, [number, number, number, number]>;
|
|
35
86
|
deprecated?: string[];
|
|
36
87
|
}
|
|
@@ -109,30 +160,29 @@ export function canonicalPriceId(model: string): string {
|
|
|
109
160
|
return MODEL_ALIASES.find((a) => a.id === key || a.feed === key || key.endsWith(`/${a.id}`) || key.endsWith(`/${a.feed}`))?.id ?? key;
|
|
110
161
|
}
|
|
111
162
|
|
|
112
|
-
export function priceFor(model: string, live?: LivePrices | null):
|
|
163
|
+
export function priceFor(model: string, live?: LivePrices | null): PriceHit {
|
|
113
164
|
const table = live === undefined ? loadLivePrices() : live;
|
|
114
165
|
if (live === undefined) {
|
|
115
|
-
|
|
166
|
+
// An operator who edits the override file expects the new price at once, not after a refresh.
|
|
167
|
+
const stamp = overrideStamp();
|
|
168
|
+
if (memoTable !== table || memoStamp !== stamp) {
|
|
169
|
+
memoTable = table;
|
|
170
|
+
memoStamp = stamp;
|
|
171
|
+
memo = new Map();
|
|
172
|
+
}
|
|
116
173
|
const hit = memo.get(model);
|
|
117
174
|
if (hit) return hit;
|
|
118
|
-
const resolved = resolvePrice(model, table);
|
|
175
|
+
const resolved = resolvePrice(model, table, stamp);
|
|
119
176
|
memo.set(model, resolved);
|
|
120
177
|
return resolved;
|
|
121
178
|
}
|
|
122
|
-
return resolvePrice(model, table);
|
|
179
|
+
return resolvePrice(model, table, overrideStamp());
|
|
123
180
|
}
|
|
124
181
|
|
|
125
|
-
// Recent rows repeat a
|
|
182
|
+
// Recent rows repeat a few models; the memo turns thousands of lookups into one per model. Cleared on table change.
|
|
126
183
|
let memoTable: LivePrices | null | undefined;
|
|
127
|
-
let
|
|
128
|
-
|
|
129
|
-
function priceMemo(table: LivePrices | null): Map<string, { price: ModelPrice; known: boolean; live: boolean }> {
|
|
130
|
-
if (memoTable !== table) {
|
|
131
|
-
memoTable = table;
|
|
132
|
-
memo = new Map();
|
|
133
|
-
}
|
|
134
|
-
return memo;
|
|
135
|
-
}
|
|
184
|
+
let memoStamp = 0;
|
|
185
|
+
let memo = new Map<string, PriceHit>();
|
|
136
186
|
|
|
137
187
|
// Validated once per table instead of once per lookup.
|
|
138
188
|
let compiledTable: LivePrices | null = null;
|
|
@@ -150,26 +200,39 @@ function priceEntries(table: LivePrices): Array<[string, ModelPrice]> {
|
|
|
150
200
|
return entries;
|
|
151
201
|
}
|
|
152
202
|
|
|
153
|
-
function resolvePrice(model: string, table: LivePrices | null
|
|
154
|
-
//
|
|
155
|
-
const
|
|
203
|
+
function resolvePrice(model: string, table: LivePrices | null, stamp = overrideStamp()): PriceHit {
|
|
204
|
+
// The operator's file wins outright: it is the only source that can name what a gateway charges.
|
|
205
|
+
const overrides = loadOverrides(stamp);
|
|
206
|
+
if (overrides) {
|
|
207
|
+
const own = overrides.exact.get(model) ?? overrides.exact.get(model.toLowerCase());
|
|
208
|
+
if (own) return { price: own, known: true, live: false, tier: 'override' };
|
|
209
|
+
const low = model.toLowerCase();
|
|
210
|
+
for (const [suffix, price] of overrides.tails) {
|
|
211
|
+
if (low === suffix || low.endsWith(`/${suffix}`)) {
|
|
212
|
+
return { price, known: true, live: false, tier: 'override' };
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// An alias runs the same chain, so it still resolves when the feed keys it under a provider prefix.
|
|
218
|
+
const alias = MODEL_ALIASES.find((a) => a.id === model.toLowerCase());
|
|
219
|
+
const id = alias?.feed ?? model;
|
|
156
220
|
if (table) {
|
|
157
221
|
const entries = priceEntries(table);
|
|
222
|
+
// The id verbatim, then case-folded; nothing guessed.
|
|
223
|
+
const hit = entries.find(([k]) => k === id) ?? entries.find(([k]) => k === id.toLowerCase());
|
|
224
|
+
if (hit) return { price: hit[1], known: true, live: true, tier: alias ? 'alias' : 'exact' };
|
|
225
|
+
|
|
158
226
|
const lower = id.toLowerCase();
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
// first cached key that ends with the full id, then with the bare tail
|
|
163
|
-
// segment, so "codex/openai/gpt-6-luna" still finds "gpt-6-luna".
|
|
164
|
-
const name = lower;
|
|
165
|
-
const tail = name.split('/').pop() ?? name;
|
|
166
|
-
const key = entries.find(([k]) => {
|
|
227
|
+
const tail = lower.split('/').pop() ?? lower;
|
|
228
|
+
// Bare name under any provider (need not be the billing one); tier `tail` keeps it out of a firm total.
|
|
229
|
+
const bare = entries.find(([k]) => {
|
|
167
230
|
const lk = k.toLowerCase();
|
|
168
|
-
return lk ===
|
|
231
|
+
return lk === tail || lk.endsWith(`/${tail}`);
|
|
169
232
|
});
|
|
170
|
-
if (
|
|
233
|
+
if (bare) return { price: bare[1], known: true, live: true, tier: 'tail' };
|
|
171
234
|
}
|
|
172
|
-
return { price: DEFAULT_PRICE, known: false, live: false };
|
|
235
|
+
return { price: DEFAULT_PRICE, known: false, live: false, tier: 'default' };
|
|
173
236
|
}
|
|
174
237
|
// Fetch LiteLLM pricing and write the cache. False on any failure — callers fall back silently.
|
|
175
238
|
export async function refreshPrices(): Promise<boolean> {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Savings read from rtk history, never estimated; modes bench in docs/BENCHMARK.md.
|
|
2
|
-
import { execFileSync } from 'node:child_process';
|
|
3
2
|
import fs from 'node:fs';
|
|
4
3
|
import os from 'node:os';
|
|
5
4
|
import path from 'node:path';
|
|
5
|
+
import { sqliteRead } from './sqlite.ts';
|
|
6
6
|
|
|
7
7
|
export interface RtkCommandRow {
|
|
8
8
|
command: string;
|
|
@@ -23,7 +23,7 @@ export interface RtkGain {
|
|
|
23
23
|
|
|
24
24
|
const EMPTY: RtkGain = { commands: 0, saved: 0, input: 0, avgPct: 0, totalMs: 0, byCommand: [] };
|
|
25
25
|
|
|
26
|
-
// The table shows one clipped cell, so bound the command before it
|
|
26
|
+
// The table shows one clipped cell, so bound the command before it reaches /data.json.
|
|
27
27
|
const MAX_CMD_CHARS = 200;
|
|
28
28
|
|
|
29
29
|
// A multi-line stored command would derail every row after it; flatten on read.
|
|
@@ -40,12 +40,7 @@ export function rtkDbPath(): string {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
function query(db: string, sql: string): string[][] {
|
|
43
|
-
|
|
44
|
-
encoding: 'utf8',
|
|
45
|
-
timeout: 5000,
|
|
46
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
47
|
-
});
|
|
48
|
-
return out
|
|
43
|
+
return sqliteRead(db, sql)
|
|
49
44
|
.split('\n')
|
|
50
45
|
.filter((line) => line.trim())
|
|
51
46
|
.map((line) => line.split('\t'));
|
|
@@ -54,7 +49,7 @@ function query(db: string, sql: string): string[][] {
|
|
|
54
49
|
export function readRtkGain(limit = 10, cutoffMs?: number): RtkGain {
|
|
55
50
|
try {
|
|
56
51
|
if (!fs.existsSync(rtkDbPath())) return EMPTY;
|
|
57
|
-
// View-level cutoff only: rtk's
|
|
52
|
+
// View-level cutoff only: rtk's rows stay untouched. Unparseable timestamps land on 0 and drop from filtered views.
|
|
58
53
|
const where = cutoffMs && cutoffMs > 0
|
|
59
54
|
? `WHERE CAST(strftime('%s', timestamp) AS INTEGER) >= ${Math.floor(cutoffMs / 1000)}`
|
|
60
55
|
: '';
|
|
@@ -3,32 +3,35 @@ import type { ComboLevel, ComboState, ExtensionCtx, SessionEntry } from './types
|
|
|
3
3
|
|
|
4
4
|
const BRIDGE_KEY = Symbol.for('tersio/combo-session-state');
|
|
5
5
|
|
|
6
|
-
// A verbatim sentence from omp's subagent prompt, so it can drift; read from the installed omp binary on 2026-10-01.
|
|
6
|
+
// A verbatim sentence from omp's subagent prompt, so it can drift; read from the installed omp binary on 2026-10-01.
|
|
7
7
|
export const OMP_SUBAGENT_MARKER = 'Worker agent: delegated tasks.';
|
|
8
8
|
|
|
9
|
+
// Every level above off turns pstack on with the other three; off is the one level without it.
|
|
9
10
|
export const COMBO_LEVELS: Record<string, Readonly<ComboState>> = Object.freeze({
|
|
10
|
-
off: Object.freeze({ level: 'off', caveman: 'off', rtk: 'off', ponytail: 'off' }),
|
|
11
|
-
medium: Object.freeze({ level: 'medium', caveman: 'lite', rtk: 'on', ponytail: 'lite' }),
|
|
12
|
-
balanced: Object.freeze({ level: 'balanced', caveman: 'full', rtk: 'on', ponytail: 'full' }),
|
|
13
|
-
max: Object.freeze({ level: 'max', caveman: 'ultra', rtk: 'on', ponytail: 'ultra' }),
|
|
11
|
+
off: Object.freeze({ level: 'off', caveman: 'off', rtk: 'off', ponytail: 'off', pstack: 'off' }),
|
|
12
|
+
medium: Object.freeze({ level: 'medium', caveman: 'lite', rtk: 'on', ponytail: 'lite', pstack: 'on' }),
|
|
13
|
+
balanced: Object.freeze({ level: 'balanced', caveman: 'full', rtk: 'on', ponytail: 'full', pstack: 'on' }),
|
|
14
|
+
max: Object.freeze({ level: 'max', caveman: 'ultra', rtk: 'on', ponytail: 'ultra', pstack: 'on' }),
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
const MODE_VALUES: Record<string, Set<string>> = {
|
|
17
18
|
caveman: new Set(['off', 'lite', 'full', 'ultra', 'megacave', 'megacave-lite', 'megacave-full', 'megacave-ultra', 'wenyan', 'wenyan-lite', 'wenyan-full', 'wenyan-ultra']),
|
|
18
19
|
rtk: new Set(['off', 'on']),
|
|
19
20
|
ponytail: new Set(['off', 'lite', 'full', 'ultra']),
|
|
21
|
+
pstack: new Set(['off', 'on']),
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
// Upstream renamed wenyan to megacave and kept the old spelling as an alias.
|
|
23
25
|
const CAVEMAN_LEGACY_PREFIX = /^wenyan/;
|
|
24
26
|
|
|
25
|
-
type ModeName = 'caveman' | 'rtk' | 'ponytail';
|
|
27
|
+
type ModeName = 'caveman' | 'rtk' | 'ponytail' | 'pstack';
|
|
26
28
|
type Modes = Record<ModeName, string>;
|
|
27
29
|
|
|
28
30
|
const MODE_ENTRY_TYPES: Record<string, ModeName> = {
|
|
29
31
|
'caveman-mode': 'caveman',
|
|
30
32
|
'rtk-mode': 'rtk',
|
|
31
33
|
'ponytail-mode': 'ponytail',
|
|
34
|
+
'pstack-mode': 'pstack',
|
|
32
35
|
};
|
|
33
36
|
|
|
34
37
|
/** True when the branch carries Tersio's own mode state; a subagent starts without it. */
|
|
@@ -54,7 +57,7 @@ export function normalizeMode(name: ModeName, value: unknown): string | null {
|
|
|
54
57
|
export function deriveLevel(modes: Modes | null | undefined): ComboLevel {
|
|
55
58
|
for (const level of Object.keys(COMBO_LEVELS) as ComboLevel[]) {
|
|
56
59
|
const preset = COMBO_LEVELS[level];
|
|
57
|
-
if (preset.caveman === modes?.caveman && preset.rtk === modes?.rtk && preset.ponytail === modes?.ponytail) return level;
|
|
60
|
+
if (preset.caveman === modes?.caveman && preset.rtk === modes?.rtk && preset.ponytail === modes?.ponytail && preset.pstack === modes?.pstack) return level;
|
|
58
61
|
}
|
|
59
62
|
return 'custom';
|
|
60
63
|
}
|
|
@@ -72,6 +75,7 @@ function normalizedState(modes: Partial<Modes> | null | undefined, level: ComboL
|
|
|
72
75
|
caveman: normalizeMode('caveman', modes?.caveman) || 'off',
|
|
73
76
|
rtk: normalizeMode('rtk', modes?.rtk) || 'off',
|
|
74
77
|
ponytail: normalizeMode('ponytail', modes?.ponytail) || 'off',
|
|
78
|
+
pstack: normalizeMode('pstack', modes?.pstack) || 'off',
|
|
75
79
|
};
|
|
76
80
|
return Object.freeze({ level: isKnownLevel(level) ? level : deriveLevel(state), ...state });
|
|
77
81
|
}
|
|
@@ -122,7 +126,7 @@ export function normalizeComboLevel(value: unknown): ComboLevel | null {
|
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
|
|
125
|
-
// Last-wins scan for a custom session entry; skips
|
|
129
|
+
// Last-wins scan for a custom session entry; skips unparseable values so a corrupt write never shadows a valid one.
|
|
126
130
|
export function lastCustomValue<T>(entries: SessionEntry[] | null | undefined, customType: string, pick: (data: SessionEntry['data']) => T | null | undefined): T | null {
|
|
127
131
|
if (!Array.isArray(entries)) return null;
|
|
128
132
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
@@ -156,15 +160,16 @@ export function setSharedComboMode(name: ModeName, value: unknown): Readonly<Com
|
|
|
156
160
|
const mode = normalizeMode(name, value);
|
|
157
161
|
if (!mode) return getSharedComboState();
|
|
158
162
|
const modes = { ...getSharedComboState(), [name]: mode } as Modes;
|
|
159
|
-
// Derive the level from the final
|
|
163
|
+
// Derive the level from the final quartet, so a redundant same-value write cannot strand a preset at 'custom'.
|
|
160
164
|
return publish(normalizedState(modes));
|
|
161
165
|
}
|
|
162
166
|
|
|
163
|
-
export function setSharedComboModes(modes: { caveman?: unknown; rtk?: unknown; ponytail?: unknown }): Readonly<ComboState> {
|
|
167
|
+
export function setSharedComboModes(modes: { caveman?: unknown; rtk?: unknown; ponytail?: unknown; pstack?: unknown }): Readonly<ComboState> {
|
|
164
168
|
return publish(normalizedState({
|
|
165
169
|
caveman: normalizeMode('caveman', modes.caveman) || 'off',
|
|
166
170
|
rtk: normalizeMode('rtk', modes.rtk) || 'off',
|
|
167
171
|
ponytail: normalizeMode('ponytail', modes.ponytail) || 'off',
|
|
172
|
+
pstack: normalizeMode('pstack', modes.pstack) || 'off',
|
|
168
173
|
}));
|
|
169
174
|
}
|
|
170
175
|
|
|
@@ -185,13 +190,13 @@ export function reconcileSharedComboEntries(entries: SessionEntry[] | null | und
|
|
|
185
190
|
if (mode) modes[name] = mode;
|
|
186
191
|
}
|
|
187
192
|
}
|
|
188
|
-
// The level reflects the final
|
|
193
|
+
// The level reflects the final quartet, not write order, so a preset followed by the same values reconciles back.
|
|
189
194
|
return publish(normalizedState(modes));
|
|
190
195
|
}
|
|
191
196
|
|
|
192
197
|
// One-line session-wide mode summary for change confirmations.
|
|
193
|
-
export function activeModesSummary(state: { caveman: string; rtk: string; ponytail: string }): string {
|
|
194
|
-
return `caveman=${state.caveman.toUpperCase()}, rtk=${state.rtk.toUpperCase()}, ponytail=${state.ponytail.toUpperCase()}`;
|
|
198
|
+
export function activeModesSummary(state: { caveman: string; rtk: string; ponytail: string; pstack: string }): string {
|
|
199
|
+
return `caveman=${state.caveman.toUpperCase()}, rtk=${state.rtk.toUpperCase()}, ponytail=${state.ponytail.toUpperCase()}, pstack=${state.pstack.toUpperCase()}`;
|
|
195
200
|
}
|
|
196
201
|
|
|
197
202
|
// Keyed registration drops stale closures; hosts offer no teardown hook.
|