sigrank 0.0.176 → 0.0.178
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 +16 -4
- package/adapters.mjs +117 -2
- package/cli.mjs +9 -2
- package/index.mjs +11 -5
- package/package.json +5 -5
- package/submit.mjs +18 -0
- package/tokenpull.mjs +7 -15
- package/tools.mjs +611 -17
package/README.md
CHANGED
|
@@ -66,10 +66,17 @@ For all builders, burners and 10xers.
|
|
|
66
66
|
| **[sigrank-vscode](https://github.com/SunrisesIllNeverSee/sigrank-vscode)** | The IDE extension — see your cascade metrics inline in VS Code. | `code --install-extension sigrank.sigrank` |
|
|
67
67
|
| **[fundscore](https://github.com/SunrisesIllNeverSee/fundscore)** | The repo scorer — investor-readiness scoring for GitHub repos. CLI + MCP server. | `npx fundscore` |
|
|
68
68
|
|
|
69
|
+
### Also in the MO§ES™ suite
|
|
70
|
+
|
|
71
|
+
| Site | What it is |
|
|
72
|
+
| ---- | ---------- |
|
|
73
|
+
| **[SIGNOMY](https://signomy.xyz)** | Governed AI agent marketplace where ranked agents form teams, fill slots, run missions, and earn revenue under constitutional protocol. Agents are free. Operators pay. |
|
|
74
|
+
| **[MO§ES](https://mos2es.com)** | The governance framework that underpins SigRank, SIGNOMY, and all governed agent operations. Structural accountability for agentic systems. |
|
|
75
|
+
|
|
69
76
|
## Quickstart — 3 steps to the board
|
|
70
77
|
|
|
71
78
|
```bash
|
|
72
|
-
# 1. Install (pulls ccusage + tokscale
|
|
79
|
+
# 1. Install (pulls ccusage + tokscale automatically — no separate installs)
|
|
73
80
|
npm install -g sigrank
|
|
74
81
|
|
|
75
82
|
# 2. Sign in (paste a connect code from signalaf.com → Settings → New key)
|
|
@@ -147,7 +154,7 @@ smithery tool call sigrank rank_paste '{"text": "1000000 500000 50000 800000"}'
|
|
|
147
154
|
## Commands
|
|
148
155
|
|
|
149
156
|
```
|
|
150
|
-
⊙ SigRank CLI v0.0.
|
|
157
|
+
⊙ SigRank CLI v0.0.177
|
|
151
158
|
|
|
152
159
|
Default (no args)
|
|
153
160
|
sigrank unified dashboard: cascade + token pillars + board
|
|
@@ -296,10 +303,10 @@ The dashboard pulls from multiple sources and shows them side-by-side for verifi
|
|
|
296
303
|
| ----------------- | ------------------------------------------------------------------------------ | --------------------- |
|
|
297
304
|
| `tokenpull` | On-device JSONL scanner (canon source) | claude, codex, amp, … |
|
|
298
305
|
| `ccusage` | `ccusage <platform> daily --json` CLI (bundled) | claude, codex |
|
|
299
|
-
| `token-dashboard` | `~/.claude/token-dashboard.db` SQLite (
|
|
306
|
+
| `token-dashboard` | `~/.claude/token-dashboard.db` SQLite ([Nate's](https://github.com/nateherkai/token-dashboard)) | claude only |
|
|
300
307
|
| `tokscale` | `tokscale models --json` CLI (bundled, falls back to `~/tokscale_report.json`) | claude, codex |
|
|
301
308
|
|
|
302
|
-
**
|
|
309
|
+
**Non-Claude input is estimated** — most non-Claude systems (Codex, Devin, etc.) combine user input + cache write into a single `input_tokens` field, so true fresh input must be derived. The ruleset (applies to ALL non-Claude systems):
|
|
303
310
|
|
|
304
311
|
```
|
|
305
312
|
input = output × ioRatio (ioRatio derived from Claude ratio, else 2.0)
|
|
@@ -307,6 +314,10 @@ cacheCreate = uncached − input (uncached = input_tokens − cached_inp
|
|
|
307
314
|
cacheRead = exact (from logs)
|
|
308
315
|
```
|
|
309
316
|
|
|
317
|
+
- **Beta** = operator's Claude input/output ratio (if Claude data available)
|
|
318
|
+
- **Alpha** = 2.0 default (when no Claude data)
|
|
319
|
+
- Owner-stated average: 7:1:2 (cache:input:output) → input/output ≈ 0.5
|
|
320
|
+
|
|
310
321
|
Verifier numbers (ccusage/tokscale for codex) show **raw uncached input** (`input_tokens − cached`) — a different field than the estimated input above. The discrepancy is expected and explained inline in the dashboard.
|
|
311
322
|
|
|
312
323
|
---
|
|
@@ -319,6 +330,7 @@ All adapters are token-only (no message content, no cost fields, no credentials)
|
|
|
319
330
|
| ------------------ | ---------------------------------------------- | --------------------------------------------------------------- |
|
|
320
331
|
| Claude Code | ✅ `~/.claude/projects` | Native; dedup by `(session_id, message_id)`; subagents included |
|
|
321
332
|
| Codex | ✅ `~/.codex/sessions` | Estimated input via `io_ratio`; verified vs ccusage |
|
|
333
|
+
| Devin CLI | ✅ `~/.local/share/devin/cli/sessions.db` | Estimated input via `io_ratio`; SQLite; same split as Codex |
|
|
322
334
|
| Amp | ✅ `~/.local/share/amp/threads` | Full 4-pillar; per-message |
|
|
323
335
|
| Kimi | ✅ `~/.kimi/sessions` | Full 4-pillar; `StatusUpdate` lines only |
|
|
324
336
|
| pi-agent | ✅ `~/.pi/agent/sessions` | Full 4-pillar; per-message JSONL |
|
package/adapters.mjs
CHANGED
|
@@ -15,6 +15,14 @@
|
|
|
15
15
|
* messages(root): async generator → { id?, sid?, ts, input, output, cacheCreate, cacheRead, file }
|
|
16
16
|
*
|
|
17
17
|
* SigRank-specific mapping rules (applied consistently across all adapters):
|
|
18
|
+
* - Claude = parsed natively (4 pillars exact, no conversion)
|
|
19
|
+
* - Non-Claude systems = combined input → split via ioRatio:
|
|
20
|
+
* input = floor(output × ioRatio) // Beta from Claude, else Alpha 2.0
|
|
21
|
+
* cacheCreate = max(0, uncached − input)
|
|
22
|
+
* cacheRead = exact
|
|
23
|
+
* (Adapters that yield {ts, output, cacheRead, uncached} via records() go through
|
|
24
|
+
* tokenpullCodex(); adapters that yield native 4-pillar via messages() go through
|
|
25
|
+
* tokenpull() directly. The split happens at the tokenpullAny() routing layer.)
|
|
18
26
|
* - Reasoning / thinking tokens → folded into `output` (they are output-side spend)
|
|
19
27
|
* - No cache-creation data available → cacheCreate: 0 + adapter sets `estimated: true`
|
|
20
28
|
* - Cost fields (USD) → NEVER used or forwarded (SigRank scores cost efficiency from
|
|
@@ -97,10 +105,11 @@ function* parseJsonl(text, filePath) {
|
|
|
97
105
|
/** Run sqlite3 -json and return parsed rows, or [] on error/unavailability.
|
|
98
106
|
* execFile with an args array — no shell, so dbPath/sql need no quoting/escaping
|
|
99
107
|
* (matches the execFile hardening used in tools.mjs / tokenpull.mjs). */
|
|
100
|
-
async function sqliteJson(dbPath, sql) {
|
|
108
|
+
async function sqliteJson(dbPath, sql, timeoutMs = 10_000) {
|
|
101
109
|
try {
|
|
102
110
|
const { stdout } = await execFileP("sqlite3", ["-json", dbPath, sql], {
|
|
103
|
-
timeout:
|
|
111
|
+
timeout: timeoutMs,
|
|
112
|
+
maxBuffer: 256 * 1024 * 1024, // 256MB — Devin's sessions.db yields ~15MB JSON
|
|
104
113
|
});
|
|
105
114
|
return JSON.parse(stdout || "[]");
|
|
106
115
|
} catch {
|
|
@@ -729,6 +738,110 @@ export const hermesAdapter = {
|
|
|
729
738
|
},
|
|
730
739
|
};
|
|
731
740
|
|
|
741
|
+
// ── 14. Devin CLI ────────────────────────────────────────────────────────────
|
|
742
|
+
// SQLite: ~/.local/share/devin/cli/sessions.db
|
|
743
|
+
// Same combined-input problem as Codex: input_tokens INCLUDES cache write, so we
|
|
744
|
+
// yield { ts, output, cacheRead, uncached } and let tokenpullCodex() do the
|
|
745
|
+
// ioRatio split (input = output × ioRatio, cacheCreate = uncached − input).
|
|
746
|
+
// ioRatio comes from Claude (Beta) or the 7:1:2 average (Alpha = 0.5).
|
|
747
|
+
export const devinAdapter = {
|
|
748
|
+
platform: "devin",
|
|
749
|
+
defaultRoot: () => join(homedir(), ".local", "share", "devin", "cli"),
|
|
750
|
+
async *records(root) {
|
|
751
|
+
for (const r of roots("DEVIN_HOME", root)) {
|
|
752
|
+
const dbPath = join(r, "sessions.db");
|
|
753
|
+
const rows = await sqliteJson(
|
|
754
|
+
dbPath,
|
|
755
|
+
`SELECT row_id, session_id,
|
|
756
|
+
json_extract(chat_message, '$.metadata.metrics.input_tokens') as input_tokens,
|
|
757
|
+
json_extract(chat_message, '$.metadata.metrics.output_tokens') as output_tokens,
|
|
758
|
+
json_extract(chat_message, '$.metadata.metrics.cache_read_tokens') as cache_read_tokens,
|
|
759
|
+
json_extract(chat_message, '$.metadata.created_at') as created_at
|
|
760
|
+
FROM message_nodes
|
|
761
|
+
WHERE json_extract(chat_message, '$.role') = 'assistant'
|
|
762
|
+
AND json_extract(chat_message, '$.metadata.metrics.input_tokens') IS NOT NULL
|
|
763
|
+
ORDER BY created_at`,
|
|
764
|
+
60_000,
|
|
765
|
+
);
|
|
766
|
+
for (const row of rows) {
|
|
767
|
+
const inputIncl = Number(row.input_tokens || 0);
|
|
768
|
+
const cached = Number(row.cache_read_tokens || 0);
|
|
769
|
+
const output = Number(row.output_tokens || 0);
|
|
770
|
+
if (inputIncl + output + cached === 0) continue;
|
|
771
|
+
yield {
|
|
772
|
+
ts: row.created_at || null,
|
|
773
|
+
output,
|
|
774
|
+
cacheRead: cached,
|
|
775
|
+
uncached: Math.max(0, inputIncl - cached),
|
|
776
|
+
file: dbPath,
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
},
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
// ── 15. Other (user-supplied JSON) ───────────────────────────────────────────
|
|
784
|
+
// For platforms/models not yet on the adapter list. The user writes a JSON file
|
|
785
|
+
// with the 4 pillars per window and points SIGRANK_OTHER_PATH at it. This lets
|
|
786
|
+
// anyone with a new tool submit without needing a custom adapter.
|
|
787
|
+
//
|
|
788
|
+
// JSON format (all fields optional, missing windows are skipped):
|
|
789
|
+
// {
|
|
790
|
+
// "platform": "my-tool", // optional, defaults to "other"
|
|
791
|
+
// "windows": {
|
|
792
|
+
// "all": { "input": 1000, "output": 2000, "cacheCreate": 500, "cacheRead": 8000 },
|
|
793
|
+
// "30d": { "input": 500, "output": 1000, "cacheCreate": 200, "cacheRead": 4000 },
|
|
794
|
+
// "7d": { "input": 100, "output": 200, "cacheCreate": 50, "cacheRead": 800 }
|
|
795
|
+
// }
|
|
796
|
+
// }
|
|
797
|
+
//
|
|
798
|
+
// The adapter yields one "message" per window with the summed pillars. Since
|
|
799
|
+
// there's no per-message timestamp, all data lands in the "all" window only
|
|
800
|
+
// (same as null-timestamp records in other adapters).
|
|
801
|
+
export const otherAdapter = {
|
|
802
|
+
platform: "other",
|
|
803
|
+
defaultRoot: () => process.env.SIGRANK_OTHER_PATH || "",
|
|
804
|
+
async *messages(root) {
|
|
805
|
+
const filePath = root || process.env.SIGRANK_OTHER_PATH;
|
|
806
|
+
if (!filePath) {
|
|
807
|
+
throw new Error(
|
|
808
|
+
"other adapter: set SIGRANK_OTHER_PATH to a JSON file with your token pillars. " +
|
|
809
|
+
'Format: { "windows": { "all": { "input": N, "output": N, "cacheCreate": N, "cacheRead": N } } }',
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
let text;
|
|
813
|
+
try {
|
|
814
|
+
text = await readFile(filePath, "utf8");
|
|
815
|
+
} catch {
|
|
816
|
+
throw new Error(`other adapter: cannot read ${filePath} — check SIGRANK_OTHER_PATH`);
|
|
817
|
+
}
|
|
818
|
+
let data;
|
|
819
|
+
try {
|
|
820
|
+
data = JSON.parse(text);
|
|
821
|
+
} catch {
|
|
822
|
+
throw new Error(`other adapter: invalid JSON in ${filePath}`);
|
|
823
|
+
}
|
|
824
|
+
const windows = data.windows || {};
|
|
825
|
+
for (const [win, pillars] of Object.entries(windows)) {
|
|
826
|
+
const input = Number(pillars.input || 0);
|
|
827
|
+
const output = Number(pillars.output || 0);
|
|
828
|
+
const cacheCreate = Number(pillars.cacheCreate || pillars.cache_create || 0);
|
|
829
|
+
const cacheRead = Number(pillars.cacheRead || pillars.cache_read || 0);
|
|
830
|
+
if (input + output + cacheCreate + cacheRead === 0) continue;
|
|
831
|
+
yield {
|
|
832
|
+
id: `other:${win}`,
|
|
833
|
+
sid: `other-${win}`,
|
|
834
|
+
ts: null, // no timestamp → lands in "all" window only
|
|
835
|
+
input,
|
|
836
|
+
output,
|
|
837
|
+
cacheCreate,
|
|
838
|
+
cacheRead,
|
|
839
|
+
file: filePath,
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
},
|
|
843
|
+
};
|
|
844
|
+
|
|
732
845
|
// ── Registry ──────────────────────────────────────────────────────────────────
|
|
733
846
|
/** All non-Claude, non-Codex adapters keyed by platform ID. */
|
|
734
847
|
export const ADAPTERS = {
|
|
@@ -745,6 +858,8 @@ export const ADAPTERS = {
|
|
|
745
858
|
goose: gooseAdapter,
|
|
746
859
|
kilo: kiloAdapter,
|
|
747
860
|
hermes: hermesAdapter,
|
|
861
|
+
devin: devinAdapter,
|
|
862
|
+
other: otherAdapter,
|
|
748
863
|
};
|
|
749
864
|
|
|
750
865
|
export const ALL_PLATFORMS = Object.keys(ADAPTERS).concat(["claude", "codex"]);
|
package/cli.mjs
CHANGED
|
@@ -236,7 +236,10 @@ async function fetchBoard(window = "30d") {
|
|
|
236
236
|
const res = await fetch(
|
|
237
237
|
`${DEFAULT_API_BASE}/api/v1/leaderboard?window=${window}&metric=yield_`,
|
|
238
238
|
{
|
|
239
|
-
headers: {
|
|
239
|
+
headers: {
|
|
240
|
+
accept: "application/json",
|
|
241
|
+
"user-agent": `node/${process.version} sigrank-mcp/cli`,
|
|
242
|
+
},
|
|
240
243
|
},
|
|
241
244
|
);
|
|
242
245
|
if (!res.ok) throw new Error(`Board API → HTTP ${res.status}`);
|
|
@@ -491,7 +494,7 @@ function appPillars() {
|
|
|
491
494
|
async function tokenDashPillars() {
|
|
492
495
|
const dbPath = path.join(os.homedir(), ".claude", "token-dashboard.db");
|
|
493
496
|
if (!existsSync(dbPath)) return null;
|
|
494
|
-
// Read directly with sqlite3 —
|
|
497
|
+
// Read directly with sqlite3 — DB created by Nate's token-dashboard (github.com/nateherkai/token-dashboard).
|
|
495
498
|
// Windowed queries using sqlite3's datetime() function.
|
|
496
499
|
const cf =
|
|
497
500
|
"(model LIKE '%claude%' OR model LIKE '%fable%' OR model LIKE '%sonnet%' OR model LIKE '%opus%' OR model LIKE '%haiku%')";
|
|
@@ -934,6 +937,7 @@ async function runWatch({
|
|
|
934
937
|
const ALL_PLATFORMS = [
|
|
935
938
|
"claude",
|
|
936
939
|
"codex",
|
|
940
|
+
"devin",
|
|
937
941
|
"amp",
|
|
938
942
|
"gemini",
|
|
939
943
|
"kimi",
|
|
@@ -944,8 +948,10 @@ const ALL_PLATFORMS = [
|
|
|
944
948
|
"droid",
|
|
945
949
|
"codebuff",
|
|
946
950
|
"copilot",
|
|
951
|
+
"opencode",
|
|
947
952
|
"openclaw",
|
|
948
953
|
"pi",
|
|
954
|
+
"other",
|
|
949
955
|
];
|
|
950
956
|
|
|
951
957
|
async function runSigRank() {
|
|
@@ -1472,6 +1478,7 @@ async function runSigRank() {
|
|
|
1472
1478
|
headers: {
|
|
1473
1479
|
"content-type": "application/json",
|
|
1474
1480
|
accept: "application/json",
|
|
1481
|
+
"user-agent": `node/${process.version} sigrank-mcp/cli`,
|
|
1475
1482
|
},
|
|
1476
1483
|
body: JSON.stringify({
|
|
1477
1484
|
codename,
|
package/index.mjs
CHANGED
|
@@ -194,7 +194,7 @@ async function startMcpServer() {
|
|
|
194
194
|
uri: "sigrank://install-guide",
|
|
195
195
|
name: "Quick Start Guide",
|
|
196
196
|
description:
|
|
197
|
-
"Step-by-step install and first submission: npx sigrank → enroll → submit. Covers ccusage/tokscale
|
|
197
|
+
"Step-by-step install and first submission: npx sigrank → enroll → submit. Covers ccusage/tokscale bundled deps + token-dashboard (Nate's, github.com/nateherkai/token-dashboard), privacy model (token counts only, never prompts), and dry-run workflow.",
|
|
198
198
|
mimeType: "text/markdown",
|
|
199
199
|
},
|
|
200
200
|
{
|
|
@@ -289,14 +289,20 @@ No global install needed. The MCP server starts automatically when an AI client
|
|
|
289
289
|
npx sigrank submit --dry-run
|
|
290
290
|
\`\`\`
|
|
291
291
|
|
|
292
|
-
## Token Pull Sources
|
|
292
|
+
## Token Pull Sources
|
|
293
293
|
|
|
294
|
-
SigRank bundles
|
|
294
|
+
SigRank bundles two token readers as npm dependencies:
|
|
295
295
|
- **ccusage** — Claude Code session logs
|
|
296
296
|
- **tokscale** — multi-platform token telemetry
|
|
297
|
-
- **tokendash** — dashboard + TUI for token usage
|
|
298
297
|
|
|
299
|
-
|
|
298
|
+
A third source, **token-dashboard**, is read from \`~/.claude/token-dashboard.db\` (SQLite).
|
|
299
|
+
That DB is created by [Nate's token-dashboard](https://github.com/nateherkai/token-dashboard) (Python):
|
|
300
|
+
\`\`\`bash
|
|
301
|
+
git clone https://github.com/nateherkai/token-dashboard.git
|
|
302
|
+
cd token-dashboard
|
|
303
|
+
python3 cli.py dashboard
|
|
304
|
+
\`\`\`
|
|
305
|
+
Run the scan once to create the DB; SigRank reads it directly via sqlite3 after that.
|
|
300
306
|
|
|
301
307
|
## MCP Client Setup
|
|
302
308
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sigrank",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.178",
|
|
4
4
|
"author": "SunrisesIllNeverSee (https://github.com/SunrisesIllNeverSee)",
|
|
5
5
|
"description": "SigRank MCP server — the yield cascade + live leaderboard as MCP tools any agent can call",
|
|
6
6
|
"mcpName": "io.github.SunrisesIllNeverSee/sigrank-mcp",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"start": "node index.mjs",
|
|
27
|
-
"test": "node test.mjs && node sign.test.mjs && node --test __tests__/cascade.test.mjs __tests__/badges.test.mjs"
|
|
27
|
+
"test": "node test.mjs && node sign.test.mjs && node --test __tests__/cascade.test.mjs __tests__/badges.test.mjs",
|
|
28
|
+
"sync:platforms": "node scripts/sync-platforms.mjs"
|
|
28
29
|
},
|
|
29
30
|
"files": [
|
|
30
31
|
"index.mjs",
|
|
@@ -64,8 +65,7 @@
|
|
|
64
65
|
],
|
|
65
66
|
"dependencies": {
|
|
66
67
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"tokscale": "^4.0.4"
|
|
68
|
+
"ccusage": "^20.0.17",
|
|
69
|
+
"tokscale": "^4.5.2"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/submit.mjs
CHANGED
|
@@ -11,9 +11,22 @@
|
|
|
11
11
|
|
|
12
12
|
import { snapshotHash, signPayload } from "./sign.mjs";
|
|
13
13
|
import { preflight } from "./preflight.mjs";
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
14
15
|
|
|
15
16
|
const WINDOW_TYPE = { "7d": "7d", "30d": "30d", "90d": "90d", all: "all_time" };
|
|
16
17
|
const WINDOW_SPAN_DAYS = { "7d": 7, "30d": 30, "90d": 90, all_time: 3650 };
|
|
18
|
+
|
|
19
|
+
/** Resolve this package's version for the User-Agent stamp (best-effort). */
|
|
20
|
+
function _pkgVersion() {
|
|
21
|
+
try {
|
|
22
|
+
const pkg = JSON.parse(
|
|
23
|
+
readFileSync(new URL("./package.json", import.meta.url), "utf-8"),
|
|
24
|
+
);
|
|
25
|
+
return pkg.version;
|
|
26
|
+
} catch {
|
|
27
|
+
return "unknown";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
17
30
|
const PLATFORM_ENUM = new Set([
|
|
18
31
|
"claude",
|
|
19
32
|
"chatgpt",
|
|
@@ -181,8 +194,13 @@ export async function submitSignedWindow(
|
|
|
181
194
|
((url, init = {}) => {
|
|
182
195
|
const ctrl = new AbortController();
|
|
183
196
|
const timer = setTimeout(() => ctrl.abort(), 15_000);
|
|
197
|
+
const headers = {
|
|
198
|
+
"user-agent": `node/${process.version} sigrank-mcp/${_pkgVersion()}`,
|
|
199
|
+
...(init.headers || {}),
|
|
200
|
+
};
|
|
184
201
|
return fetch(url, {
|
|
185
202
|
...init,
|
|
203
|
+
headers,
|
|
186
204
|
signal: init.signal || ctrl.signal,
|
|
187
205
|
}).finally(() => clearTimeout(timer));
|
|
188
206
|
});
|
package/tokenpull.mjs
CHANGED
|
@@ -343,7 +343,7 @@ export async function tokenpullCodex({
|
|
|
343
343
|
});
|
|
344
344
|
|
|
345
345
|
return {
|
|
346
|
-
platform: "codex",
|
|
346
|
+
platform: adapter.platform || "codex",
|
|
347
347
|
root: r,
|
|
348
348
|
generatedAt: new Date(nowMs).toISOString(),
|
|
349
349
|
files: files.size,
|
|
@@ -367,13 +367,12 @@ export async function tokenpullCodex({
|
|
|
367
367
|
export async function tokenpullAny(platform, opts = {}) {
|
|
368
368
|
if (!platform || platform === "claude")
|
|
369
369
|
return tokenpull({ adapter: claudeAdapter, ...opts });
|
|
370
|
-
|
|
371
|
-
|
|
370
|
+
// Codex + Devin: both combine input + cache write in input_tokens, so both go
|
|
371
|
+
// through tokenpullCodex() which splits via ioRatio (Beta from Claude, Alpha 2.0).
|
|
372
|
+
if (platform === "codex" || platform === "devin") {
|
|
372
373
|
let ioRatio = opts.ioRatio || 2.0;
|
|
373
374
|
if (!opts.ioRatio) {
|
|
374
375
|
try {
|
|
375
|
-
// Forward root/now from opts so the Beta-ratio derivation is testable
|
|
376
|
-
// (without this, it always reads the real ~/.claude and can't be injected).
|
|
377
376
|
const c = await tokenpull({
|
|
378
377
|
adapter: claudeAdapter,
|
|
379
378
|
root: opts.root,
|
|
@@ -386,15 +385,8 @@ export async function tokenpullAny(platform, opts = {}) {
|
|
|
386
385
|
/* no Claude data → Alpha 2.0 */
|
|
387
386
|
}
|
|
388
387
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
// Cloud agents (Devin, etc.) run server-side — no local JSONL to read
|
|
392
|
-
const CLOUD_AGENTS = { devin: "Cognition/Devin" };
|
|
393
|
-
if (platform in CLOUD_AGENTS) {
|
|
394
|
-
throw new Error(
|
|
395
|
-
`"${platform}" (${CLOUD_AGENTS[platform]}) runs in the cloud — sessions are not written to local JSONL files. ` +
|
|
396
|
-
`There is no local data source to read. If ${CLOUD_AGENTS[platform]} exposes a usage API in future, an adapter can be added.`,
|
|
397
|
-
);
|
|
388
|
+
const adapter = platform === "codex" ? codexAdapter : ADAPTERS.devin;
|
|
389
|
+
return tokenpullCodex({ adapter, ioRatio, ...opts });
|
|
398
390
|
}
|
|
399
391
|
const adapter = ADAPTERS[platform];
|
|
400
392
|
if (!adapter)
|
|
@@ -486,7 +478,7 @@ async function _freshTokendash(platform = "claude") {
|
|
|
486
478
|
if (platform !== "claude") return null;
|
|
487
479
|
const dbPath = join(homedir(), ".claude", "token-dashboard.db");
|
|
488
480
|
// Read the token-dashboard DB directly with sqlite3 (no external python scan
|
|
489
|
-
// needed — the DB is created by
|
|
481
|
+
// needed — the DB is created by Nate's token-dashboard, github.com/nateherkai/token-dashboard).
|
|
490
482
|
// all-time only; the db doesn't expose windowing here.
|
|
491
483
|
if (!existsSync(dbPath)) return null;
|
|
492
484
|
try {
|
package/tools.mjs
CHANGED
|
@@ -26,7 +26,7 @@ import { ALL_PLATFORMS } from "./adapters.mjs";
|
|
|
26
26
|
import { ensureIdentity, recordEnrollment } from "./keystore.mjs";
|
|
27
27
|
import { submitSignedWindow } from "./submit.mjs";
|
|
28
28
|
import { createHash } from "node:crypto";
|
|
29
|
-
import { execFile } from "node:child_process";
|
|
29
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
30
30
|
import { existsSync, readFileSync } from "node:fs";
|
|
31
31
|
import os from "node:os";
|
|
32
32
|
import path from "node:path";
|
|
@@ -256,6 +256,56 @@ export const DEFAULT_FETCH_TIMEOUT =
|
|
|
256
256
|
* past this is malformed or abusive — reject cleanly before parsing/POSTing (E2 hardening). */
|
|
257
257
|
const MAX_INPUT = 1_000_000;
|
|
258
258
|
|
|
259
|
+
/** Resolve this package's version for the User-Agent stamp (best-effort). */
|
|
260
|
+
function agentVersionStamp() {
|
|
261
|
+
try {
|
|
262
|
+
const pkg = JSON.parse(
|
|
263
|
+
readFileSync(new URL("./package.json", import.meta.url), "utf-8"),
|
|
264
|
+
);
|
|
265
|
+
return pkg.version;
|
|
266
|
+
} catch {
|
|
267
|
+
return "unknown";
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* curl-based fetch fallback for when Node's fetch is blocked by Vercel's bot
|
|
273
|
+
* protection (TLS fingerprinting). Returns a Response-like object with .ok,
|
|
274
|
+
* .status, .json(), .text(). Uses execFileSync for synchronous curl execution.
|
|
275
|
+
*/
|
|
276
|
+
function curlFetch(url, init = {}, timeoutMs = 10_000) {
|
|
277
|
+
const args = ["-s", "-S", "-w", "\n__HTTP_STATUS__%{http_code}", "--max-time", String(Math.ceil(timeoutMs / 1000))];
|
|
278
|
+
if (init.method) args.push("-X", init.method);
|
|
279
|
+
const headers = init.headers || {};
|
|
280
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
281
|
+
args.push("-H", `${k}: ${v}`);
|
|
282
|
+
}
|
|
283
|
+
if (init.body) {
|
|
284
|
+
args.push("-d", init.body);
|
|
285
|
+
}
|
|
286
|
+
args.push(url);
|
|
287
|
+
let stdout;
|
|
288
|
+
try {
|
|
289
|
+
stdout = execFileSync("curl", args, {
|
|
290
|
+
encoding: "utf-8",
|
|
291
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
292
|
+
timeout: timeoutMs + 2000,
|
|
293
|
+
});
|
|
294
|
+
} catch (e) {
|
|
295
|
+
throw new Error(`curl transport failed: ${e.message}`);
|
|
296
|
+
}
|
|
297
|
+
// Parse the status code from the trailer
|
|
298
|
+
const statusMatch = stdout.match(/__HTTP_STATUS__(\d+)$/);
|
|
299
|
+
const status = statusMatch ? parseInt(statusMatch[1], 10) : 0;
|
|
300
|
+
const bodyText = statusMatch ? stdout.slice(0, statusMatch.index) : stdout;
|
|
301
|
+
return {
|
|
302
|
+
ok: status >= 200 && status < 300,
|
|
303
|
+
status,
|
|
304
|
+
json: async () => { try { return JSON.parse(bodyText); } catch { return {}; } },
|
|
305
|
+
text: async () => bodyText,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
259
309
|
// ── Smithery quality: output schemas + annotations ──────────────────────────
|
|
260
310
|
// MCP tool annotations hint to clients about side-effects, read-only status, etc.
|
|
261
311
|
const ANNOTATIONS = {
|
|
@@ -747,8 +797,8 @@ export const TOOLS = [
|
|
|
747
797
|
properties: {
|
|
748
798
|
platform: {
|
|
749
799
|
type: "string",
|
|
750
|
-
enum: ALL_PLATFORMS,
|
|
751
|
-
description: `source platform (default: claude). Supported: ${ALL_PLATFORMS.join(", ")}. codex is estimated via io_ratio. Some platforms need setup (e.g. copilot requires COPILOT_OTEL_ENABLED=true).`,
|
|
800
|
+
enum: [...ALL_PLATFORMS, "multi"],
|
|
801
|
+
description: `source platform (default: claude). Supported: ${ALL_PLATFORMS.join(", ")}, multi. 'multi' = combined cascade summed across all locally-detected platforms (needs 2+ active). 'devin' reads from ~/.local/share/devin/cli/sessions.db (SQLite, all windows). 'codex' is estimated via io_ratio. 'other' reads from a user-supplied JSON file (set SIGRANK_OTHER_PATH). Some platforms need setup (e.g. copilot requires COPILOT_OTEL_ENABLED=true).`,
|
|
752
802
|
},
|
|
753
803
|
},
|
|
754
804
|
},
|
|
@@ -780,8 +830,8 @@ export const TOOLS = [
|
|
|
780
830
|
},
|
|
781
831
|
platform: {
|
|
782
832
|
type: "string",
|
|
783
|
-
enum: ALL_PLATFORMS,
|
|
784
|
-
description: `Source platform to pull from (default: claude). Supported: ${ALL_PLATFORMS.join(", ")}. Each platform reads its own session logs locally.`,
|
|
833
|
+
enum: [...ALL_PLATFORMS, "multi"],
|
|
834
|
+
description: `Source platform to pull from (default: claude). Supported: ${ALL_PLATFORMS.join(", ")}, multi. 'multi' = combined cascade summed across all locally-detected platforms (needs 2+ active). 'devin' reads from ~/.local/share/devin/cli/sessions.db (SQLite, all windows). 'other' reads from a user-supplied JSON file (set SIGRANK_OTHER_PATH). Each platform reads its own session logs locally.`,
|
|
785
835
|
},
|
|
786
836
|
},
|
|
787
837
|
},
|
|
@@ -1312,6 +1362,36 @@ export const TOOLS = [
|
|
|
1312
1362
|
},
|
|
1313
1363
|
},
|
|
1314
1364
|
},
|
|
1365
|
+
{
|
|
1366
|
+
name: "tokscale_breakdown",
|
|
1367
|
+
description:
|
|
1368
|
+
"Show a per-model breakdown of your token usage across all platforms detected by tokscale. Models under the threshold (default 1%) are lumped into 'other' to keep the display clean. Useful for seeing which models you actually use per platform (e.g. claude-opus-4-8 76%, claude-sonnet-4-6 11%, other 0.3%). Returns { platform: [{ model, input, output, cacheRead, cacheCreate, pct }] }.",
|
|
1369
|
+
annotations: {
|
|
1370
|
+
title: "Model breakdown",
|
|
1371
|
+
...ANNOTATIONS.readOnlyHint,
|
|
1372
|
+
...ANNOTATIONS.openWorldHint,
|
|
1373
|
+
},
|
|
1374
|
+
inputSchema: {
|
|
1375
|
+
type: "object",
|
|
1376
|
+
properties: {
|
|
1377
|
+
threshold: {
|
|
1378
|
+
type: "number",
|
|
1379
|
+
description:
|
|
1380
|
+
"Models below this fraction of their platform's total tokens are lumped into 'other'. Default 0.01 (1%). Set 0 to see every model.",
|
|
1381
|
+
default: 0.01,
|
|
1382
|
+
},
|
|
1383
|
+
},
|
|
1384
|
+
},
|
|
1385
|
+
outputSchema: {
|
|
1386
|
+
type: "object",
|
|
1387
|
+
properties: {
|
|
1388
|
+
platforms: {
|
|
1389
|
+
type: "object",
|
|
1390
|
+
description: "Map of platform name → array of { model, input, output, cacheRead, cacheCreate, pct }",
|
|
1391
|
+
},
|
|
1392
|
+
},
|
|
1393
|
+
},
|
|
1394
|
+
},
|
|
1315
1395
|
];
|
|
1316
1396
|
|
|
1317
1397
|
// tokenpull window key → the board's window_type enum.
|
|
@@ -1333,9 +1413,191 @@ const _lastWatchSubmitAt = new Map();
|
|
|
1333
1413
|
// keeps only platforms with real local data, and sorts claude → codex → rest.
|
|
1334
1414
|
// Pass `platforms` to scope it (e.g. ['claude'] for a fast first paint).
|
|
1335
1415
|
export async function pullActivePlatforms({ platforms } = {}, opts = {}) {
|
|
1336
|
-
|
|
1416
|
+
// If the caller specified explicit platforms, use those.
|
|
1417
|
+
if (platforms && platforms.length) {
|
|
1418
|
+
return _pullExplicit(platforms, opts);
|
|
1419
|
+
}
|
|
1420
|
+
// Auto-detect: run tokscale once to discover all active clients, then pull
|
|
1421
|
+
// only those. This is much faster than trying all 17 adapters (most fail
|
|
1422
|
+
// silently on a machine that doesn't have that tool installed).
|
|
1423
|
+
//
|
|
1424
|
+
// Flow: tokscale surfaces ALL clients → map to our platform names →
|
|
1425
|
+
// ccusage is primary for Claude (more accurate) → other platforms use
|
|
1426
|
+
// their adapters. Anything in tokscale NOT in ccusage gets included.
|
|
1427
|
+
const detected = await _tokscaleDetectClients().catch(() => null);
|
|
1428
|
+
if (detected && detected.length > 0) {
|
|
1429
|
+
return _pullExplicit(detected, opts);
|
|
1430
|
+
}
|
|
1431
|
+
// Fallback: tokscale not installed or failed → try all adapters (old behavior)
|
|
1432
|
+
return _pullExplicit(ALL_PLATFORMS, opts);
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
/** Run `tokscale models --json` and return the list of our platform names. */
|
|
1436
|
+
async function _tokscaleDetectClients() {
|
|
1437
|
+
const raw = await execFileAsync("tokscale", ["models", "--json"], 60000);
|
|
1438
|
+
const data = JSON.parse(raw);
|
|
1439
|
+
const entries = Array.isArray(data?.entries)
|
|
1440
|
+
? data.entries
|
|
1441
|
+
: Array.isArray(data)
|
|
1442
|
+
? data
|
|
1443
|
+
: [];
|
|
1444
|
+
if (!entries.length) return [];
|
|
1445
|
+
// Complete tokscale client → our platform name mapping.
|
|
1446
|
+
// Tokscale supports 40 clients (as of v3.1.0). We have native adapters for 16;
|
|
1447
|
+
// the rest map to "other" (user-supplied JSON via SIGRANK_OTHER_PATH).
|
|
1448
|
+
// Source: https://github.com/junhoyeo/tokscale
|
|
1449
|
+
const TOKSCALE_CLIENT_MAP = {
|
|
1450
|
+
// Native adapters
|
|
1451
|
+
claude: "claude",
|
|
1452
|
+
codex: "codex",
|
|
1453
|
+
"devin-cli": "devin",
|
|
1454
|
+
"devin-desktop": "devin",
|
|
1455
|
+
gemini: "gemini",
|
|
1456
|
+
amp: "amp",
|
|
1457
|
+
kimi: "kimi",
|
|
1458
|
+
qwen: "qwen",
|
|
1459
|
+
goose: "goose",
|
|
1460
|
+
kilo: "kilo",
|
|
1461
|
+
kilocode: "kilo",
|
|
1462
|
+
hermes: "hermes",
|
|
1463
|
+
droid: "droid",
|
|
1464
|
+
codebuff: "codebuff",
|
|
1465
|
+
copilot: "copilot",
|
|
1466
|
+
opencode: "opencode",
|
|
1467
|
+
openclaw: "openclaw",
|
|
1468
|
+
pi: "pi",
|
|
1469
|
+
// No native adapter yet → "other"
|
|
1470
|
+
cursor: "other",
|
|
1471
|
+
roocode: "other",
|
|
1472
|
+
mux: "other",
|
|
1473
|
+
crush: "other",
|
|
1474
|
+
antigravity: "other",
|
|
1475
|
+
"antigravity-cli": "other",
|
|
1476
|
+
zed: "other",
|
|
1477
|
+
kiro: "other",
|
|
1478
|
+
trae: "other",
|
|
1479
|
+
warp: "other",
|
|
1480
|
+
cline: "other",
|
|
1481
|
+
gjc: "other",
|
|
1482
|
+
grok: "other",
|
|
1483
|
+
jcode: "other",
|
|
1484
|
+
commandcode: "other",
|
|
1485
|
+
micode: "other",
|
|
1486
|
+
junie: "other",
|
|
1487
|
+
zcode: "other",
|
|
1488
|
+
opencodereview: "other",
|
|
1489
|
+
codebuddy: "other",
|
|
1490
|
+
workbuddy: "other",
|
|
1491
|
+
// synthetic = re-attributed from other sources, skip
|
|
1492
|
+
synthetic: null,
|
|
1493
|
+
};
|
|
1494
|
+
const clients = new Set();
|
|
1495
|
+
for (const e of entries) {
|
|
1496
|
+
if (!e || !e.client) continue;
|
|
1497
|
+
if (e.model === "<synthetic>" || e.model === "unknown") continue;
|
|
1498
|
+
const input = Number(e.input) || 0;
|
|
1499
|
+
const output = Number(e.output) || 0;
|
|
1500
|
+
if (input + output === 0) continue;
|
|
1501
|
+
const platform = TOKSCALE_CLIENT_MAP[e.client];
|
|
1502
|
+
if (platform === null) continue; // synthetic → skip
|
|
1503
|
+
clients.add(platform || "other");
|
|
1504
|
+
}
|
|
1505
|
+
return [...clients];
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
/**
|
|
1509
|
+
* Run `tokscale models --json` and return a model-level breakdown per platform.
|
|
1510
|
+
* Models under `threshold` (default 1%) of their platform's total are lumped
|
|
1511
|
+
* into "other" to keep the display clean.
|
|
1512
|
+
*
|
|
1513
|
+
* Returns: { platform: [{ model, input, output, cacheRead, cacheCreate, pct }] }
|
|
1514
|
+
*/
|
|
1515
|
+
export async function tokscaleModelBreakdown(threshold = 0.01) {
|
|
1516
|
+
const raw = await execFileAsync("tokscale", ["models", "--json"], 60000);
|
|
1517
|
+
const data = JSON.parse(raw);
|
|
1518
|
+
const entries = Array.isArray(data?.entries)
|
|
1519
|
+
? data.entries
|
|
1520
|
+
: Array.isArray(data)
|
|
1521
|
+
? data
|
|
1522
|
+
: [];
|
|
1523
|
+
if (!entries.length) return {};
|
|
1524
|
+
|
|
1525
|
+
const TOKSCALE_CLIENT_MAP = {
|
|
1526
|
+
claude: "claude", codex: "codex", "devin-cli": "devin",
|
|
1527
|
+
"devin-desktop": "devin", gemini: "gemini", amp: "amp",
|
|
1528
|
+
kimi: "kimi", qwen: "qwen", goose: "goose", kilo: "kilo",
|
|
1529
|
+
kilocode: "kilo", hermes: "hermes", droid: "droid",
|
|
1530
|
+
codebuff: "codebuff", copilot: "copilot", opencode: "opencode",
|
|
1531
|
+
openclaw: "openclaw", pi: "pi",
|
|
1532
|
+
cursor: "other", roocode: "other", mux: "other", crush: "other",
|
|
1533
|
+
antigravity: "other", "antigravity-cli": "other", zed: "other",
|
|
1534
|
+
kiro: "other", trae: "other", warp: "other", cline: "other",
|
|
1535
|
+
gjc: "other", grok: "other", jcode: "other", commandcode: "other",
|
|
1536
|
+
micode: "other", junie: "other", zcode: "other",
|
|
1537
|
+
opencodereview: "other", codebuddy: "other", workbuddy: "other",
|
|
1538
|
+
synthetic: null,
|
|
1539
|
+
};
|
|
1540
|
+
|
|
1541
|
+
// Group entries by our platform name
|
|
1542
|
+
const byPlatform = {};
|
|
1543
|
+
for (const e of entries) {
|
|
1544
|
+
if (!e || !e.client) continue;
|
|
1545
|
+
if (e.model === "<synthetic>" || e.model === "unknown") continue;
|
|
1546
|
+
const input = Number(e.input) || 0;
|
|
1547
|
+
const output = Number(e.output) || 0;
|
|
1548
|
+
if (input + output === 0) continue;
|
|
1549
|
+
const platform = TOKSCALE_CLIENT_MAP[e.client];
|
|
1550
|
+
if (platform === null) continue;
|
|
1551
|
+
const p = platform || "other";
|
|
1552
|
+
if (!byPlatform[p]) byPlatform[p] = [];
|
|
1553
|
+
byPlatform[p].push({
|
|
1554
|
+
model: e.model,
|
|
1555
|
+
input,
|
|
1556
|
+
output,
|
|
1557
|
+
cacheRead: Number(e.cacheRead) || 0,
|
|
1558
|
+
cacheCreate: Number(e.cacheWrite) || 0,
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
// For each platform: sort by total tokens desc, lump small models into "other"
|
|
1563
|
+
const result = {};
|
|
1564
|
+
for (const [platform, models] of Object.entries(byPlatform)) {
|
|
1565
|
+
const total = models.reduce(
|
|
1566
|
+
(s, m) => s + m.input + m.output + m.cacheRead + m.cacheCreate,
|
|
1567
|
+
0,
|
|
1568
|
+
);
|
|
1569
|
+
if (total === 0) continue;
|
|
1570
|
+
const sorted = models.sort(
|
|
1571
|
+
(a, b) =>
|
|
1572
|
+
b.input + b.output + b.cacheRead + b.cacheCreate -
|
|
1573
|
+
(a.input + a.output + a.cacheRead + a.cacheCreate),
|
|
1574
|
+
);
|
|
1575
|
+
const big = [];
|
|
1576
|
+
const small = { model: "other", input: 0, output: 0, cacheRead: 0, cacheCreate: 0 };
|
|
1577
|
+
for (const m of sorted) {
|
|
1578
|
+
const t = m.input + m.output + m.cacheRead + m.cacheCreate;
|
|
1579
|
+
if (t / total < threshold) {
|
|
1580
|
+
small.input += m.input;
|
|
1581
|
+
small.output += m.output;
|
|
1582
|
+
small.cacheRead += m.cacheRead;
|
|
1583
|
+
small.cacheCreate += m.cacheCreate;
|
|
1584
|
+
} else {
|
|
1585
|
+
big.push({ ...m, pct: t / total });
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
if (small.input + small.output + small.cacheRead + small.cacheCreate > 0) {
|
|
1589
|
+
const t = small.input + small.output + small.cacheRead + small.cacheCreate;
|
|
1590
|
+
big.push({ ...small, pct: t / total });
|
|
1591
|
+
}
|
|
1592
|
+
result[platform] = big;
|
|
1593
|
+
}
|
|
1594
|
+
return result;
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
/** Pull a specific set of platforms in parallel, filter to active ones. */
|
|
1598
|
+
async function _pullExplicit(platforms, opts = {}) {
|
|
1337
1599
|
const settled = await Promise.allSettled(
|
|
1338
|
-
|
|
1600
|
+
platforms.map((p) => callTool("tokenpull", { platform: p }, opts)),
|
|
1339
1601
|
);
|
|
1340
1602
|
const active = settled
|
|
1341
1603
|
.filter((r) => r.status === "fulfilled" && r.value)
|
|
@@ -1357,13 +1619,45 @@ export async function callTool(name, args, opts = {}) {
|
|
|
1357
1619
|
const rawFetch = opts.fetchImpl || fetch;
|
|
1358
1620
|
|
|
1359
1621
|
// Wrap every fetch with an AbortController timeout so a hung network call never
|
|
1360
|
-
// blocks the MCP client indefinitely.
|
|
1361
|
-
|
|
1622
|
+
// blocks the MCP client indefinitely. Vercel's bot protection (security
|
|
1623
|
+
// checkpoint) blocks Node's fetch via TLS fingerprinting — no UA fix helps.
|
|
1624
|
+
// When fetch gets a 403 Vercel challenge, fall back to curl (which passes).
|
|
1625
|
+
const doFetch = async (url, init = {}) => {
|
|
1362
1626
|
const ac = new AbortController();
|
|
1363
1627
|
const timer = setTimeout(() => ac.abort(), timeoutMs);
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1628
|
+
const headers = {
|
|
1629
|
+
"user-agent": `node/${process.version} sigrank-mcp/${agentVersionStamp()}`,
|
|
1630
|
+
...(init.headers || {}),
|
|
1631
|
+
};
|
|
1632
|
+
try {
|
|
1633
|
+
const res = await rawFetch(url, { ...init, headers, signal: ac.signal });
|
|
1634
|
+
// Detect Vercel security checkpoint (403 + HTML body, not JSON)
|
|
1635
|
+
if (res.status === 403) {
|
|
1636
|
+
const text = await res.text();
|
|
1637
|
+
if (text.includes("Vercel Security Checkpoint") || text.includes("x-vercel-challenge")) {
|
|
1638
|
+
// Fall back to curl transport
|
|
1639
|
+
return curlFetch(url, init, timeoutMs);
|
|
1640
|
+
}
|
|
1641
|
+
// Real 403 from the API — return a mock response object
|
|
1642
|
+
return {
|
|
1643
|
+
ok: false,
|
|
1644
|
+
status: 403,
|
|
1645
|
+
json: async () => { try { return JSON.parse(text); } catch { return {}; } },
|
|
1646
|
+
text: async () => text,
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
return res;
|
|
1650
|
+
} catch (e) {
|
|
1651
|
+
if (e.name === "AbortError") throw e;
|
|
1652
|
+
// Network error — try curl as fallback
|
|
1653
|
+
try {
|
|
1654
|
+
return await curlFetch(url, init, timeoutMs);
|
|
1655
|
+
} catch {
|
|
1656
|
+
throw e;
|
|
1657
|
+
}
|
|
1658
|
+
} finally {
|
|
1659
|
+
clearTimeout(timer);
|
|
1660
|
+
}
|
|
1367
1661
|
};
|
|
1368
1662
|
|
|
1369
1663
|
const fetchJson = async (path) => {
|
|
@@ -1405,8 +1699,12 @@ export async function callTool(name, args, opts = {}) {
|
|
|
1405
1699
|
const c = withParseWarnings(pillars, cascade(pillars));
|
|
1406
1700
|
return { ...c, card: narrate(c) };
|
|
1407
1701
|
}
|
|
1408
|
-
if (name === "get_leaderboard")
|
|
1409
|
-
|
|
1702
|
+
if (name === "get_leaderboard") {
|
|
1703
|
+
const params = new URLSearchParams({ metric: "yield_" });
|
|
1704
|
+
if (args?.limit) params.set("limit", String(args.limit));
|
|
1705
|
+
if (args?.window) params.set("window", args.window);
|
|
1706
|
+
return fetchJson(`/api/v1/leaderboard?${params}`);
|
|
1707
|
+
}
|
|
1410
1708
|
if (name === "get_operator") {
|
|
1411
1709
|
const codename = String(args?.codename || "").trim();
|
|
1412
1710
|
if (!codename)
|
|
@@ -1677,6 +1975,67 @@ export async function callTool(name, args, opts = {}) {
|
|
|
1677
1975
|
if (name === "tokenpull") {
|
|
1678
1976
|
// Local read → 4 windows of pillars → cascade each. Token-only, on-device.
|
|
1679
1977
|
const platform = args?.platform || "claude";
|
|
1978
|
+
|
|
1979
|
+
// MULTI: sum every locally-detected platform's pillars per window. Same logic as
|
|
1980
|
+
// submit_verified's multi flow — Devin (cloud, via tokscale) is included.
|
|
1981
|
+
if (platform === "multi") {
|
|
1982
|
+
const detected = [];
|
|
1983
|
+
for (const p of ALL_PLATFORMS) {
|
|
1984
|
+
const r = await pullByPlatform(p, opts).catch(() => null);
|
|
1985
|
+
const live =
|
|
1986
|
+
r &&
|
|
1987
|
+
(r.windows || []).some(
|
|
1988
|
+
(w) =>
|
|
1989
|
+
w.pillars.input +
|
|
1990
|
+
w.pillars.output +
|
|
1991
|
+
w.pillars.cacheCreate +
|
|
1992
|
+
w.pillars.cacheRead >
|
|
1993
|
+
0,
|
|
1994
|
+
);
|
|
1995
|
+
if (live) detected.push(r);
|
|
1996
|
+
}
|
|
1997
|
+
if (detected.length < 2) {
|
|
1998
|
+
return {
|
|
1999
|
+
platform: "multi",
|
|
2000
|
+
status: "skipped",
|
|
2001
|
+
reason: "need_2_platforms",
|
|
2002
|
+
detail: `multi needs 2+ active platforms; found ${detected.length} (${detected.map((d) => d.platform).join(", ") || "none"}).`,
|
|
2003
|
+
windows: [],
|
|
2004
|
+
};
|
|
2005
|
+
}
|
|
2006
|
+
const winKeys = ["7d", "30d", "90d", "all"];
|
|
2007
|
+
const windows = [];
|
|
2008
|
+
for (const wk of winKeys) {
|
|
2009
|
+
const sum = { input: 0, output: 0, cacheCreate: 0, cacheRead: 0 };
|
|
2010
|
+
let msgs = 0;
|
|
2011
|
+
for (const d of detected) {
|
|
2012
|
+
const w = (d.windows || []).find((x) => x.window === wk);
|
|
2013
|
+
if (!w) continue;
|
|
2014
|
+
sum.input += w.pillars.input || 0;
|
|
2015
|
+
sum.output += w.pillars.output || 0;
|
|
2016
|
+
sum.cacheCreate += w.pillars.cacheCreate || 0;
|
|
2017
|
+
sum.cacheRead += w.pillars.cacheRead || 0;
|
|
2018
|
+
msgs += w.messages || 0;
|
|
2019
|
+
}
|
|
2020
|
+
if (sum.input + sum.output + sum.cacheCreate + sum.cacheRead <= 0)
|
|
2021
|
+
continue;
|
|
2022
|
+
const c = cascade(sum);
|
|
2023
|
+
windows.push({
|
|
2024
|
+
window: wk,
|
|
2025
|
+
messages: msgs,
|
|
2026
|
+
pillars: sum,
|
|
2027
|
+
cascade: c,
|
|
2028
|
+
card: narrate(c, `${wk} multi`),
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2031
|
+
return {
|
|
2032
|
+
platform: "multi",
|
|
2033
|
+
estimated: true,
|
|
2034
|
+
sources: detected.map((d) => d.platform),
|
|
2035
|
+
windows,
|
|
2036
|
+
};
|
|
2037
|
+
}
|
|
2038
|
+
|
|
1680
2039
|
const pulled = await pullByPlatform(platform, opts);
|
|
1681
2040
|
const windows = pulled.windows.map((w) => {
|
|
1682
2041
|
const c = cascade(w.pillars);
|
|
@@ -1704,7 +2063,111 @@ export async function callTool(name, args, opts = {}) {
|
|
|
1704
2063
|
// (server re-scores). The board stays platform-agnostic via the 4 pillars; the
|
|
1705
2064
|
// source platform rides along as a tag. Conversion already happened in the adapter.
|
|
1706
2065
|
const codename = String(args?.codename || "").trim();
|
|
1707
|
-
const
|
|
2066
|
+
const platform = args?.platform || "claude";
|
|
2067
|
+
|
|
2068
|
+
// MULTI: same combined cross-platform cascade as submit_verified. Includes Devin
|
|
2069
|
+
// (cloud, via tokscale). Aggregate every locally-detected platform's pillars per
|
|
2070
|
+
// window and publish as platform='multi'.
|
|
2071
|
+
if (platform === "multi") {
|
|
2072
|
+
const detected = [];
|
|
2073
|
+
for (const p of ALL_PLATFORMS) {
|
|
2074
|
+
const r = await pullByPlatform(p, opts).catch(() => null);
|
|
2075
|
+
const live =
|
|
2076
|
+
r &&
|
|
2077
|
+
(r.windows || []).some(
|
|
2078
|
+
(w) =>
|
|
2079
|
+
w.pillars.input +
|
|
2080
|
+
w.pillars.output +
|
|
2081
|
+
w.pillars.cacheCreate +
|
|
2082
|
+
w.pillars.cacheRead >
|
|
2083
|
+
0,
|
|
2084
|
+
);
|
|
2085
|
+
if (live) detected.push(r);
|
|
2086
|
+
}
|
|
2087
|
+
if (detected.length < 2) {
|
|
2088
|
+
return {
|
|
2089
|
+
platform: "multi",
|
|
2090
|
+
codename: codename || undefined,
|
|
2091
|
+
status: "skipped",
|
|
2092
|
+
reason: "need_2_platforms",
|
|
2093
|
+
detail: `multi needs 2+ active platforms; found ${detected.length} (${detected.map((d) => d.platform).join(", ") || "none"}).`,
|
|
2094
|
+
windows: [],
|
|
2095
|
+
};
|
|
2096
|
+
}
|
|
2097
|
+
const winKeys = args?.window ? [args.window] : ["7d", "30d", "90d", "all"];
|
|
2098
|
+
const out = [];
|
|
2099
|
+
for (const wk of winKeys) {
|
|
2100
|
+
const sum = { input: 0, output: 0, cacheCreate: 0, cacheRead: 0 };
|
|
2101
|
+
let msgs = 0;
|
|
2102
|
+
for (const d of detected) {
|
|
2103
|
+
const w = (d.windows || []).find((x) => x.window === wk);
|
|
2104
|
+
if (!w) continue;
|
|
2105
|
+
sum.input += w.pillars.input || 0;
|
|
2106
|
+
sum.output += w.pillars.output || 0;
|
|
2107
|
+
sum.cacheCreate += w.pillars.cacheCreate || 0;
|
|
2108
|
+
sum.cacheRead += w.pillars.cacheRead || 0;
|
|
2109
|
+
msgs += w.messages || 0;
|
|
2110
|
+
}
|
|
2111
|
+
if (sum.input + sum.output + sum.cacheCreate + sum.cacheRead <= 0)
|
|
2112
|
+
continue;
|
|
2113
|
+
const c = cascade(sum);
|
|
2114
|
+
const card = narrate(c, `${wk} multi`);
|
|
2115
|
+
if (!codename) {
|
|
2116
|
+
out.push({
|
|
2117
|
+
window: wk,
|
|
2118
|
+
pillars: sum,
|
|
2119
|
+
cascade: c,
|
|
2120
|
+
card,
|
|
2121
|
+
submission: { status: "not_submitted", reason: "codename_required" },
|
|
2122
|
+
});
|
|
2123
|
+
continue;
|
|
2124
|
+
}
|
|
2125
|
+
const rawPaste = `${sum.input} ${sum.output} ${sum.cacheCreate} ${sum.cacheRead}`;
|
|
2126
|
+
const windowType = WINDOW_TYPE[wk] || wk;
|
|
2127
|
+
const stamp = uploadStamp({
|
|
2128
|
+
codename,
|
|
2129
|
+
window: windowType,
|
|
2130
|
+
pillars: sum,
|
|
2131
|
+
platform: "multi",
|
|
2132
|
+
});
|
|
2133
|
+
const res = await doFetch(`${apiBase}/api/v1/ingest-paste`, {
|
|
2134
|
+
method: "POST",
|
|
2135
|
+
headers: {
|
|
2136
|
+
"content-type": "application/json",
|
|
2137
|
+
accept: "application/json",
|
|
2138
|
+
},
|
|
2139
|
+
body: JSON.stringify({
|
|
2140
|
+
codename,
|
|
2141
|
+
raw_paste: rawPaste,
|
|
2142
|
+
window_type: windowType,
|
|
2143
|
+
telemetry: { platform: { primary: "multi" } },
|
|
2144
|
+
...stamp,
|
|
2145
|
+
}),
|
|
2146
|
+
});
|
|
2147
|
+
let ack;
|
|
2148
|
+
try {
|
|
2149
|
+
ack = await res.json();
|
|
2150
|
+
} catch {
|
|
2151
|
+
ack = { status: "parse_error", httpStatus: res.status };
|
|
2152
|
+
}
|
|
2153
|
+
const ranked = ack?.ranked ?? ack?.accepted ?? false;
|
|
2154
|
+
out.push({
|
|
2155
|
+
window: wk,
|
|
2156
|
+
pillars: sum,
|
|
2157
|
+
cascade: c,
|
|
2158
|
+
card,
|
|
2159
|
+
submission: { ...stamp, httpStatus: res.status, ranked, ...ack },
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
return {
|
|
2163
|
+
platform: "multi",
|
|
2164
|
+
codename: codename || undefined,
|
|
2165
|
+
sources: detected.map((d) => d.platform),
|
|
2166
|
+
windows: out,
|
|
2167
|
+
};
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
const pulled = await pullByPlatform(platform, opts);
|
|
1708
2171
|
const targets = args?.window
|
|
1709
2172
|
? pulled.windows.filter((w) => w.window === args.window)
|
|
1710
2173
|
: pulled.windows;
|
|
@@ -2774,6 +3237,7 @@ export async function callTool(name, args, opts = {}) {
|
|
|
2774
3237
|
const top = ops.map((op) => ({
|
|
2775
3238
|
...op,
|
|
2776
3239
|
behavioral_framing: _behavioralFraming(op),
|
|
3240
|
+
competitive: _competitiveLayer(op, board),
|
|
2777
3241
|
}));
|
|
2778
3242
|
|
|
2779
3243
|
const best = top[0];
|
|
@@ -2781,7 +3245,13 @@ export async function callTool(name, args, opts = {}) {
|
|
|
2781
3245
|
? `${best.codename} tops the SigRank leaderboard at Υ ${best.yield_?.toLocaleString?.() || best.yield_} — ${_behavioralFraming(best)}`
|
|
2782
3246
|
: "No operators on the board yet.";
|
|
2783
3247
|
|
|
2784
|
-
return {
|
|
3248
|
+
return {
|
|
3249
|
+
top_operators: top,
|
|
3250
|
+
total_operators: total,
|
|
3251
|
+
summary,
|
|
3252
|
+
cta: "Check my rank",
|
|
3253
|
+
shareable_url: best ? `${DEFAULT_API_BASE}/operator/${encodeURIComponent(best.codename)}` : null,
|
|
3254
|
+
};
|
|
2785
3255
|
}
|
|
2786
3256
|
|
|
2787
3257
|
if (name === "compare_self") {
|
|
@@ -2843,6 +3313,10 @@ export async function callTool(name, args, opts = {}) {
|
|
|
2843
3313
|
|
|
2844
3314
|
const suggestion = _improvementSuggestion(klass, yourMetrics);
|
|
2845
3315
|
|
|
3316
|
+
// Competitive layer per SHARED_DESIGN_DECISIONS.md §3/§4/§5
|
|
3317
|
+
const competitive = _competitiveLayer(yourMetrics, board);
|
|
3318
|
+
const competitiveSummary = _competitiveSummary(yourMetrics, board);
|
|
3319
|
+
|
|
2846
3320
|
return {
|
|
2847
3321
|
your_metrics: yourMetrics,
|
|
2848
3322
|
power_user_assessment: powerUserAssessment,
|
|
@@ -2850,8 +3324,16 @@ export async function callTool(name, args, opts = {}) {
|
|
|
2850
3324
|
your_yield_vs_avg: yieldVsAvg,
|
|
2851
3325
|
your_class_meaning: classMeaning,
|
|
2852
3326
|
percentile,
|
|
3327
|
+
rank: competitive.rank,
|
|
3328
|
+
total_operators: competitive.total_operators,
|
|
3329
|
+
class_tier: competitive.class_tier,
|
|
3330
|
+
delta_from_average: competitive.delta_from_average,
|
|
3331
|
+
delta_from_top: competitive.delta_from_top,
|
|
2853
3332
|
},
|
|
3333
|
+
competitive_summary: competitiveSummary,
|
|
3334
|
+
shareable_url: competitive.shareable_url,
|
|
2854
3335
|
suggestion,
|
|
3336
|
+
cta: "See where I stand",
|
|
2855
3337
|
};
|
|
2856
3338
|
}
|
|
2857
3339
|
|
|
@@ -2863,9 +3345,10 @@ export async function callTool(name, args, opts = {}) {
|
|
|
2863
3345
|
"compare_operators requires both `codename_a` and `codename_b`.",
|
|
2864
3346
|
);
|
|
2865
3347
|
|
|
2866
|
-
const [opA, opB] = await Promise.all([
|
|
3348
|
+
const [opA, opB, board] = await Promise.all([
|
|
2867
3349
|
fetchJson(`/api/v1/operators/${encodeURIComponent(nameA)}`),
|
|
2868
3350
|
fetchJson(`/api/v1/operators/${encodeURIComponent(nameB)}`),
|
|
3351
|
+
fetchJson("/api/v1/leaderboard?metric=yield_"),
|
|
2869
3352
|
]);
|
|
2870
3353
|
|
|
2871
3354
|
const yieldA = opA.yield_ || 0;
|
|
@@ -2884,6 +3367,7 @@ export async function callTool(name, args, opts = {}) {
|
|
|
2884
3367
|
velocity: opA.velocity,
|
|
2885
3368
|
class: opA.class,
|
|
2886
3369
|
rank: opA.rank,
|
|
3370
|
+
competitive: _competitiveLayer(opA, board),
|
|
2887
3371
|
},
|
|
2888
3372
|
operator_b: {
|
|
2889
3373
|
codename: opB.codename,
|
|
@@ -2892,9 +3376,11 @@ export async function callTool(name, args, opts = {}) {
|
|
|
2892
3376
|
velocity: opB.velocity,
|
|
2893
3377
|
class: opB.class,
|
|
2894
3378
|
rank: opB.rank,
|
|
3379
|
+
competitive: _competitiveLayer(opB, board),
|
|
2895
3380
|
},
|
|
2896
3381
|
verdict,
|
|
2897
3382
|
yield_delta: delta,
|
|
3383
|
+
cta: "Compare me to others",
|
|
2898
3384
|
};
|
|
2899
3385
|
}
|
|
2900
3386
|
|
|
@@ -2915,6 +3401,8 @@ export async function callTool(name, args, opts = {}) {
|
|
|
2915
3401
|
{ class: "Burner", meaning: "Early-stage — tokens burned more than compounded. Low leverage, low velocity. The shift: reuse prior context." },
|
|
2916
3402
|
],
|
|
2917
3403
|
link: "https://signalaf.com/score — check your class tier and yield",
|
|
3404
|
+
shareable_url: `${DEFAULT_API_BASE}/score`,
|
|
3405
|
+
cta: "Learn the scoring",
|
|
2918
3406
|
};
|
|
2919
3407
|
}
|
|
2920
3408
|
|
|
@@ -2986,6 +3474,11 @@ export async function callTool(name, args, opts = {}) {
|
|
|
2986
3474
|
|
|
2987
3475
|
const summary = `Your Υ Yield is ${y.toLocaleString()} (${klass}). ${_improvementSuggestion(klass, metrics)}`;
|
|
2988
3476
|
|
|
3477
|
+
// Competitive layer per SHARED_DESIGN_DECISIONS.md §3/§4/§5
|
|
3478
|
+
const board = await fetchJson("/api/v1/leaderboard?metric=yield_");
|
|
3479
|
+
const competitive = _competitiveLayer(metrics, board);
|
|
3480
|
+
const competitiveSummary = _competitiveSummary(metrics, board);
|
|
3481
|
+
|
|
2989
3482
|
return {
|
|
2990
3483
|
your_metrics: {
|
|
2991
3484
|
yield_: y,
|
|
@@ -2993,16 +3486,117 @@ export async function callTool(name, args, opts = {}) {
|
|
|
2993
3486
|
velocity: v,
|
|
2994
3487
|
class: klass,
|
|
2995
3488
|
},
|
|
3489
|
+
competitive: {
|
|
3490
|
+
rank: competitive.rank,
|
|
3491
|
+
total_operators: competitive.total_operators,
|
|
3492
|
+
percentile: competitive.percentile,
|
|
3493
|
+
class_tier: competitive.class_tier,
|
|
3494
|
+
delta_from_average: competitive.delta_from_average,
|
|
3495
|
+
delta_from_top: competitive.delta_from_top,
|
|
3496
|
+
},
|
|
3497
|
+
competitive_summary: competitiveSummary,
|
|
3498
|
+
shareable_url: competitive.shareable_url,
|
|
2996
3499
|
suggestions,
|
|
2997
3500
|
summary,
|
|
3501
|
+
cta: "Improve my score",
|
|
2998
3502
|
};
|
|
2999
3503
|
}
|
|
3000
3504
|
|
|
3505
|
+
if (name === "tokscale_breakdown") {
|
|
3506
|
+
const threshold = Number(args?.threshold ?? 0.01);
|
|
3507
|
+
const platforms = await tokscaleModelBreakdown(threshold);
|
|
3508
|
+
return { platforms };
|
|
3509
|
+
}
|
|
3510
|
+
|
|
3001
3511
|
throw new Error(`Unknown tool: ${name}`);
|
|
3002
3512
|
}
|
|
3003
3513
|
|
|
3004
3514
|
// ── Intent tool helpers — behavioral framing in power-user language ──────────
|
|
3005
3515
|
|
|
3516
|
+
/**
|
|
3517
|
+
* Competitive layer for tool responses per SHARED_DESIGN_DECISIONS.md §3/§4/§5.
|
|
3518
|
+
* Every tool response that includes operator data must show:
|
|
3519
|
+
* rank, percentile, class_tier, delta_from_average, delta_from_top, shareable_url
|
|
3520
|
+
* Response style: factual + competitive ("You rank #12 of 47 operators...")
|
|
3521
|
+
*/
|
|
3522
|
+
function _competitiveLayer(op, board) {
|
|
3523
|
+
const allOps = Array.isArray(board?.operators || board) ? (board.operators || board) : [];
|
|
3524
|
+
const yields = allOps.map((o) => o.yield_ || 0).sort((a, b) => a - b);
|
|
3525
|
+
const yourYield = op.yield_ || 0;
|
|
3526
|
+
const total = allOps.length;
|
|
3527
|
+
|
|
3528
|
+
// Rank: find operator's position (1-based)
|
|
3529
|
+
let rank = op.rank || null;
|
|
3530
|
+
if (!rank && total > 0) {
|
|
3531
|
+
const sorted = [...allOps].sort((a, b) => (b.yield_ || 0) - (a.yield_ || 0));
|
|
3532
|
+
const idx = sorted.findIndex((o) => o.codename === op.codename);
|
|
3533
|
+
rank = idx >= 0 ? idx + 1 : null;
|
|
3534
|
+
}
|
|
3535
|
+
|
|
3536
|
+
// Percentile: % of operators with yield below this operator
|
|
3537
|
+
const percentile = total > 0
|
|
3538
|
+
? Math.round((yields.filter((y) => y < yourYield).length / total) * 100)
|
|
3539
|
+
: 0;
|
|
3540
|
+
|
|
3541
|
+
// Delta from average
|
|
3542
|
+
const avgYield = total > 0 ? yields.reduce((s, y) => s + y, 0) / total : 0;
|
|
3543
|
+
const deltaFromAvg = avgYield > 0
|
|
3544
|
+
? { absolute: Math.round(yourYield - avgYield),
|
|
3545
|
+
percent: Math.round(((yourYield - avgYield) / avgYield) * 100) }
|
|
3546
|
+
: { absolute: 0, percent: 0 };
|
|
3547
|
+
|
|
3548
|
+
// Delta from top operator
|
|
3549
|
+
const topYield = total > 0 ? Math.max(...yields) : 0;
|
|
3550
|
+
const deltaFromTop = topYield > 0
|
|
3551
|
+
? { absolute: Math.round(topYield - yourYield),
|
|
3552
|
+
percent: Math.round(((topYield - yourYield) / topYield) * 100) }
|
|
3553
|
+
: { absolute: 0, percent: 0 };
|
|
3554
|
+
|
|
3555
|
+
// Shareable URL
|
|
3556
|
+
const shareableUrl = op.codename && op.codename !== "you (local)"
|
|
3557
|
+
? `${DEFAULT_API_BASE}/operator/${encodeURIComponent(op.codename)}`
|
|
3558
|
+
: null;
|
|
3559
|
+
|
|
3560
|
+
return {
|
|
3561
|
+
rank,
|
|
3562
|
+
total_operators: total,
|
|
3563
|
+
percentile,
|
|
3564
|
+
class_tier: op.class || "Burner",
|
|
3565
|
+
delta_from_average: deltaFromAvg,
|
|
3566
|
+
delta_from_top: deltaFromTop,
|
|
3567
|
+
shareable_url: shareableUrl,
|
|
3568
|
+
};
|
|
3569
|
+
}
|
|
3570
|
+
|
|
3571
|
+
/** Factual + competitive summary line per SHARED_DESIGN_DECISIONS.md §4 */
|
|
3572
|
+
function _competitiveSummary(op, board) {
|
|
3573
|
+
const cl = _competitiveLayer(op, board);
|
|
3574
|
+
const parts = [];
|
|
3575
|
+
|
|
3576
|
+
if (cl.rank && cl.total_operators > 0) {
|
|
3577
|
+
parts.push(`You rank #${cl.rank} of ${cl.total_operators} operators.`);
|
|
3578
|
+
}
|
|
3579
|
+
|
|
3580
|
+
const topOp = (board?.operators || board || []).reduce(
|
|
3581
|
+
(best, o) => ((o.yield_ || 0) > (best?.yield_ || 0) ? o : best),
|
|
3582
|
+
null,
|
|
3583
|
+
);
|
|
3584
|
+
if (topOp && topOp.codename) {
|
|
3585
|
+
parts.push(`Top operator is ${topOp.codename} with Υ ${(topOp.yield_ || 0).toLocaleString()}.`);
|
|
3586
|
+
}
|
|
3587
|
+
|
|
3588
|
+
if (cl.delta_from_average.percent !== 0) {
|
|
3589
|
+
const dir = cl.delta_from_average.percent > 0 ? "above" : "below";
|
|
3590
|
+
parts.push(`You're ${Math.abs(cl.delta_from_average.percent)}% ${dir} average.`);
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3593
|
+
if (cl.delta_from_top.percent > 0) {
|
|
3594
|
+
parts.push(`${cl.delta_from_top.percent}% below top.`);
|
|
3595
|
+
}
|
|
3596
|
+
|
|
3597
|
+
return parts.join(" ");
|
|
3598
|
+
}
|
|
3599
|
+
|
|
3006
3600
|
function _behavioralFraming(op) {
|
|
3007
3601
|
const y = op.yield_ || 0;
|
|
3008
3602
|
const l = op.leverage || 0;
|