sigrank 0.0.178 → 0.0.179

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.
Files changed (72) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/MCP_SERVER_DESCRIPTION.md +141 -0
  3. package/README.md +8 -0
  4. package/adapters/index.mjs +865 -0
  5. package/adapters/tokenpull.mjs +576 -0
  6. package/adapters.mjs +1 -865
  7. package/analytics/cascade.mjs +274 -0
  8. package/cascade.mjs +1 -274
  9. package/cli.mjs +1 -1853
  10. package/connect.mjs +1 -13
  11. package/identity/connect.mjs +13 -0
  12. package/identity/keystore.mjs +242 -0
  13. package/identity/sign.mjs +106 -0
  14. package/index.mjs +29 -153
  15. package/keystore.mjs +1 -242
  16. package/narrate.mjs +1 -77
  17. package/package.json +29 -13
  18. package/preflight.mjs +1 -191
  19. package/presentation/cli.mjs +1874 -0
  20. package/presentation/narrate.mjs +77 -0
  21. package/presentation/tui.mjs +2668 -0
  22. package/prompts/check-my-efficiency.md +1 -0
  23. package/prompts/compare-with-leader.md +1 -0
  24. package/prompts/simulate-improvement.md +1 -0
  25. package/resources/class-tiers.md +23 -0
  26. package/resources/data-policy.md +27 -0
  27. package/resources/install-guide.md +59 -0
  28. package/resources/privacy-model.md +30 -0
  29. package/resources/scoring-formula.md +28 -0
  30. package/review.mjs +263 -0
  31. package/sign.mjs +1 -106
  32. package/submit/index.mjs +309 -0
  33. package/submit/preflight.mjs +191 -0
  34. package/submit.mjs +1 -303
  35. package/tokenpull.mjs +1 -576
  36. package/tools/_framing.mjs +139 -0
  37. package/tools/_helpers.mjs +258 -0
  38. package/tools/_report.mjs +262 -0
  39. package/tools/_schemas.mjs +394 -0
  40. package/tools/_verifiers.mjs +148 -0
  41. package/tools/compare-operators.mjs +79 -0
  42. package/tools/compare-self.mjs +122 -0
  43. package/tools/describe-power-user.mjs +68 -0
  44. package/tools/diagnose-cascade.mjs +192 -0
  45. package/tools/enroll.mjs +121 -0
  46. package/tools/get-best-operator.mjs +58 -0
  47. package/tools/get-leaderboard.mjs +26 -0
  48. package/tools/get-operator.mjs +33 -0
  49. package/tools/index.mjs +257 -0
  50. package/tools/optimize-efficiency.mjs +160 -0
  51. package/tools/rank-paste.mjs +51 -0
  52. package/tools/rank-windows.mjs +120 -0
  53. package/tools/self-improve.mjs +423 -0
  54. package/tools/simulate-change.mjs +207 -0
  55. package/tools/submit-paste.mjs +118 -0
  56. package/tools/submit-verified.mjs +153 -0
  57. package/tools/suggest-improvements.mjs +168 -0
  58. package/tools/tokenpull-compare.mjs +123 -0
  59. package/tools/tokenpull-submit.mjs +234 -0
  60. package/tools/tokenpull.mjs +113 -0
  61. package/tools/tokscale-breakdown.mjs +159 -0
  62. package/tools/tokscale-competitive-intel.mjs +45 -0
  63. package/tools/tokscale-cost-analysis.mjs +31 -0
  64. package/tools/tokscale-developer-profile.mjs +36 -0
  65. package/tools/tokscale-device-profile.mjs +35 -0
  66. package/tools/tokscale-market-share.mjs +38 -0
  67. package/tools/tokscale-mcp-usage.mjs +33 -0
  68. package/tools/tokscale-model-trends.mjs +32 -0
  69. package/tools/watch-tokenpull.mjs +134 -0
  70. package/tools.mjs +1 -3897
  71. package/tui.mjs +4 -2650
  72. package/banner.svg +0 -7
@@ -0,0 +1,234 @@
1
+ /**
2
+ * tools/tokenpull-submit.mjs — tokenpull_submit tool.
3
+ */
4
+
5
+ import { cascade } from "../analytics/cascade.mjs";
6
+ import { narrate } from "../presentation/narrate.mjs";
7
+ import { ALL_PLATFORMS } from "../adapters/index.mjs";
8
+ import { SUBMIT_OUTPUT, ANNOTATIONS } from "./_schemas.mjs";
9
+ import {
10
+ MAX_INPUT,
11
+ pullByPlatform,
12
+ uploadStamp,
13
+ WINDOW_TYPE,
14
+ } from "./_helpers.mjs";
15
+
16
+ export const TOOL_DEF = {
17
+ name: "tokenpull_submit",
18
+ description:
19
+ "Pull your LOCAL token usage from session logs AND publish it to the SigRank board in one call — the zero-paste flow. Reads the four canonical pillars (input, output, cacheCreate, cacheRead) per window from your local logs, computes the cascade, and submits each window to the board where it is re-scored server-side and tagged with the source platform. Requires a codename to publish; omit for a local preview only. Token-only — no prompt content is read or transmitted.",
20
+ annotations: {
21
+ title: "Pull and submit tokens",
22
+ ...ANNOTATIONS.destructiveHint,
23
+ ...ANNOTATIONS.idempotentHint,
24
+ ...ANNOTATIONS.openWorldHint,
25
+ },
26
+ inputSchema: {
27
+ type: "object",
28
+ properties: {
29
+ codename: {
30
+ type: "string",
31
+ description:
32
+ 'Operator codename to publish under on the leaderboard (e.g. "Iron Lotus"). Required to submit — omit for local preview only.',
33
+ },
34
+ window: {
35
+ type: "string",
36
+ enum: ["7d", "30d", "90d", "all"],
37
+ description:
38
+ 'Submit only this time window (default: all 4 windows). Use "7d" for recent activity or "all" for all-time ranking.',
39
+ },
40
+ platform: {
41
+ type: "string",
42
+ enum: [...ALL_PLATFORMS, "multi"],
43
+ 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.`,
44
+ },
45
+ },
46
+ },
47
+ outputSchema: SUBMIT_OUTPUT,
48
+ };
49
+
50
+ export async function handleTokenpullSubmit(args, ctx) {
51
+ // Pull local usage, then publish each window's CANONICAL pillars to the board
52
+ // (server re-scores). The board stays platform-agnostic via the 4 pillars; the
53
+ // source platform rides along as a tag. Conversion already happened in the adapter.
54
+ const codename = String(args?.codename || "").trim();
55
+ const platform = args?.platform || "claude";
56
+
57
+ // MULTI: same combined cross-platform cascade as submit_verified. Includes Devin
58
+ // (cloud, via tokscale). Aggregate every locally-detected platform's pillars per
59
+ // window and publish as platform='multi'.
60
+ if (platform === "multi") {
61
+ const detected = [];
62
+ for (const p of ALL_PLATFORMS) {
63
+ const r = await pullByPlatform(p, ctx.opts).catch(() => null);
64
+ const live =
65
+ r &&
66
+ (r.windows || []).some(
67
+ (w) =>
68
+ w.pillars.input +
69
+ w.pillars.output +
70
+ w.pillars.cacheCreate +
71
+ w.pillars.cacheRead >
72
+ 0,
73
+ );
74
+ if (live) detected.push(r);
75
+ }
76
+ if (detected.length < 2) {
77
+ return {
78
+ platform: "multi",
79
+ codename: codename || undefined,
80
+ status: "skipped",
81
+ reason: "need_2_platforms",
82
+ detail: `multi needs 2+ active platforms; found ${detected.length} (${detected.map((d) => d.platform).join(", ") || "none"}).`,
83
+ windows: [],
84
+ };
85
+ }
86
+ const winKeys = args?.window ? [args.window] : ["7d", "30d", "90d", "all"];
87
+ const out = [];
88
+ for (const wk of winKeys) {
89
+ const sum = { input: 0, output: 0, cacheCreate: 0, cacheRead: 0 };
90
+ let msgs = 0;
91
+ for (const d of detected) {
92
+ const w = (d.windows || []).find((x) => x.window === wk);
93
+ if (!w) continue;
94
+ sum.input += w.pillars.input || 0;
95
+ sum.output += w.pillars.output || 0;
96
+ sum.cacheCreate += w.pillars.cacheCreate || 0;
97
+ sum.cacheRead += w.pillars.cacheRead || 0;
98
+ msgs += w.messages || 0;
99
+ }
100
+ if (sum.input + sum.output + sum.cacheCreate + sum.cacheRead <= 0)
101
+ continue;
102
+ const c = cascade(sum);
103
+ const card = narrate(c, `${wk} multi`);
104
+ if (!codename) {
105
+ out.push({
106
+ window: wk,
107
+ pillars: sum,
108
+ cascade: c,
109
+ card,
110
+ submission: { status: "not_submitted", reason: "codename_required" },
111
+ });
112
+ continue;
113
+ }
114
+ const rawPaste = `${sum.input} ${sum.output} ${sum.cacheCreate} ${sum.cacheRead}`;
115
+ const windowType = WINDOW_TYPE[wk] || wk;
116
+ const stamp = uploadStamp({
117
+ codename,
118
+ window: windowType,
119
+ pillars: sum,
120
+ platform: "multi",
121
+ });
122
+ const res = await ctx.doFetch(`${ctx.apiBase}/api/v1/ingest-paste`, {
123
+ method: "POST",
124
+ headers: {
125
+ "content-type": "application/json",
126
+ accept: "application/json",
127
+ },
128
+ body: JSON.stringify({
129
+ codename,
130
+ raw_paste: rawPaste,
131
+ window_type: windowType,
132
+ telemetry: { platform: { primary: "multi" } },
133
+ consent_acknowledged: true,
134
+ terms_version: "2026-07-21",
135
+ privacy_version: "2026-07-21",
136
+ ...stamp,
137
+ }),
138
+ });
139
+ let ack;
140
+ try {
141
+ ack = await res.json();
142
+ } catch {
143
+ ack = { status: "parse_error", httpStatus: res.status };
144
+ }
145
+ const ranked = ack?.ranked ?? ack?.accepted ?? false;
146
+ out.push({
147
+ window: wk,
148
+ pillars: sum,
149
+ cascade: c,
150
+ card,
151
+ submission: { ...stamp, httpStatus: res.status, ranked, ...ack },
152
+ });
153
+ }
154
+ return {
155
+ platform: "multi",
156
+ codename: codename || undefined,
157
+ sources: detected.map((d) => d.platform),
158
+ windows: out,
159
+ };
160
+ }
161
+
162
+ const pulled = await pullByPlatform(platform, ctx.opts);
163
+ const targets = args?.window
164
+ ? pulled.windows.filter((w) => w.window === args.window)
165
+ : pulled.windows;
166
+ const out = [];
167
+ for (const w of targets) {
168
+ const c = cascade(w.pillars);
169
+ const card = narrate(c, `${w.window} window`);
170
+ if (!codename) {
171
+ out.push({
172
+ window: w.window,
173
+ pillars: w.pillars,
174
+ cascade: c,
175
+ card,
176
+ submission: { status: "not_submitted", reason: "codename_required" },
177
+ });
178
+ continue;
179
+ }
180
+ // canonical pillars → "input output cacheCreate cacheRead" (the parser's 4-bare-number form)
181
+ const rawPaste = `${w.pillars.input} ${w.pillars.output} ${w.pillars.cacheCreate} ${w.pillars.cacheRead}`;
182
+ const windowType = WINDOW_TYPE[w.window] || w.window;
183
+ const stamp = uploadStamp({
184
+ codename,
185
+ window: windowType,
186
+ pillars: w.pillars,
187
+ platform: pulled.platform,
188
+ });
189
+ const res = await ctx.doFetch(`${ctx.apiBase}/api/v1/ingest-paste`, {
190
+ method: "POST",
191
+ headers: {
192
+ "content-type": "application/json",
193
+ accept: "application/json",
194
+ },
195
+ body: JSON.stringify({
196
+ codename,
197
+ raw_paste: rawPaste,
198
+ window_type: windowType,
199
+ telemetry: { platform: { primary: pulled.platform } },
200
+ consent_acknowledged: true,
201
+ terms_version: "2026-07-21",
202
+ privacy_version: "2026-07-21",
203
+ ...stamp,
204
+ }),
205
+ });
206
+ let ack;
207
+ try {
208
+ ack = await res.json();
209
+ } catch {
210
+ ack = { status: "error", detail: `HTTP ${res.status} (non-JSON)` };
211
+ }
212
+ // ranked = actually on the board (verified + persisted), not just received — parity
213
+ // with submit_verified (submit/index.mjs). An unenrolled/revoked device gets 202 but is NEVER ranked.
214
+ const ranked = !!(
215
+ res.ok &&
216
+ ack.verification_tier === "verified" &&
217
+ ack.persisted === true
218
+ );
219
+ out.push({
220
+ window: w.window,
221
+ pillars: w.pillars,
222
+ cascade: c,
223
+ card,
224
+ ranked,
225
+ submission: { ...stamp, httpStatus: res.status, ranked, ...ack },
226
+ });
227
+ }
228
+ return {
229
+ platform: pulled.platform,
230
+ codename: codename || null,
231
+ generatedAt: pulled.generatedAt,
232
+ windows: out,
233
+ };
234
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * tools/tokenpull.mjs — tokenpull tool.
3
+ */
4
+
5
+ import { cascade } from "../analytics/cascade.mjs";
6
+ import { narrate } from "../presentation/narrate.mjs";
7
+ import { ALL_PLATFORMS } from "../adapters/index.mjs";
8
+ import { TOKENPULL_OUTPUT, ANNOTATIONS } from "./_schemas.mjs";
9
+ import { pullByPlatform } from "./_helpers.mjs";
10
+
11
+ export const TOOL_DEF = {
12
+ name: "tokenpull",
13
+ description:
14
+ "Pull your LOCAL token usage from the platform's session logs and rank it across the four windows (7d/30d/90d/all-time) with the cascade — zero paste. Token-only: reads usage counts not message content. The numbers stay on your machine unless you submit them. Some platforms may have partial data (estimated=true when cacheCreate isn't available) or a dataGap note when the log format doesn't expose raw token counts.",
15
+ annotations: { title: "Pull local token usage", ...ANNOTATIONS.readOnlyHint, ...ANNOTATIONS.openWorldHint },
16
+ inputSchema: {
17
+ type: "object",
18
+ properties: {
19
+ platform: {
20
+ type: "string",
21
+ enum: [...ALL_PLATFORMS, "multi"],
22
+ 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).`,
23
+ },
24
+ },
25
+ },
26
+ outputSchema: TOKENPULL_OUTPUT,
27
+ };
28
+
29
+ export async function handleTokenpull(args, ctx) {
30
+ // Local read → 4 windows of pillars → cascade each. Token-only, on-device.
31
+ const platform = args?.platform || "claude";
32
+
33
+ // MULTI: sum every locally-detected platform's pillars per window. Same logic as
34
+ // submit_verified's multi flow — Devin (cloud, via tokscale) is included.
35
+ if (platform === "multi") {
36
+ const detected = [];
37
+ for (const p of ALL_PLATFORMS) {
38
+ const r = await pullByPlatform(p, ctx.opts).catch(() => null);
39
+ const live =
40
+ r &&
41
+ (r.windows || []).some(
42
+ (w) =>
43
+ w.pillars.input +
44
+ w.pillars.output +
45
+ w.pillars.cacheCreate +
46
+ w.pillars.cacheRead >
47
+ 0,
48
+ );
49
+ if (live) detected.push(r);
50
+ }
51
+ if (detected.length < 2) {
52
+ return {
53
+ platform: "multi",
54
+ status: "skipped",
55
+ reason: "need_2_platforms",
56
+ detail: `multi needs 2+ active platforms; found ${detected.length} (${detected.map((d) => d.platform).join(", ") || "none"}).`,
57
+ windows: [],
58
+ };
59
+ }
60
+ const winKeys = ["7d", "30d", "90d", "all"];
61
+ const windows = [];
62
+ for (const wk of winKeys) {
63
+ const sum = { input: 0, output: 0, cacheCreate: 0, cacheRead: 0 };
64
+ let msgs = 0;
65
+ for (const d of detected) {
66
+ const w = (d.windows || []).find((x) => x.window === wk);
67
+ if (!w) continue;
68
+ sum.input += w.pillars.input || 0;
69
+ sum.output += w.pillars.output || 0;
70
+ sum.cacheCreate += w.pillars.cacheCreate || 0;
71
+ sum.cacheRead += w.pillars.cacheRead || 0;
72
+ msgs += w.messages || 0;
73
+ }
74
+ if (sum.input + sum.output + sum.cacheCreate + sum.cacheRead <= 0)
75
+ continue;
76
+ const c = cascade(sum);
77
+ windows.push({
78
+ window: wk,
79
+ messages: msgs,
80
+ pillars: sum,
81
+ cascade: c,
82
+ card: narrate(c, `${wk} multi`),
83
+ });
84
+ }
85
+ return {
86
+ platform: "multi",
87
+ estimated: true,
88
+ sources: detected.map((d) => d.platform),
89
+ windows,
90
+ };
91
+ }
92
+
93
+ const pulled = await pullByPlatform(platform, ctx.opts);
94
+ const windows = pulled.windows.map((w) => {
95
+ const c = cascade(w.pillars);
96
+ return {
97
+ window: w.window,
98
+ messages: w.messages,
99
+ pillars: w.pillars,
100
+ cascade: c,
101
+ card: narrate(c, `${w.window} ${platform}`),
102
+ };
103
+ });
104
+ return {
105
+ platform: pulled.platform,
106
+ estimated: pulled.estimated || false,
107
+ ...(pulled.ioRatio ? { ioRatio: pulled.ioRatio } : {}),
108
+ generatedAt: pulled.generatedAt,
109
+ files: pulled.files,
110
+ totalMessages: pulled.totalMessages,
111
+ windows,
112
+ };
113
+ }
@@ -0,0 +1,159 @@
1
+ /**
2
+ * tools/tokscale-breakdown.mjs — tokscale_breakdown tool.
3
+ */
4
+
5
+ import { execFileAsync } from "./_helpers.mjs";
6
+ import { ANNOTATIONS } from "./_schemas.mjs";
7
+
8
+ export const TOOL_DEF = {
9
+ name: "tokscale_breakdown",
10
+ description:
11
+ "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 }] }.",
12
+ annotations: {
13
+ title: "Model breakdown",
14
+ ...ANNOTATIONS.readOnlyHint,
15
+ ...ANNOTATIONS.openWorldHint,
16
+ },
17
+ inputSchema: {
18
+ type: "object",
19
+ properties: {
20
+ threshold: {
21
+ type: "number",
22
+ description:
23
+ "Models below this fraction of their platform's total tokens are lumped into 'other'. Default 0.01 (1%). Set 0 to see every model.",
24
+ default: 0.01,
25
+ },
26
+ },
27
+ },
28
+ outputSchema: {
29
+ type: "object",
30
+ properties: {
31
+ platforms: {
32
+ type: "object",
33
+ description: "Map of platform name → array of { model, input, output, cacheRead, cacheCreate, pct }",
34
+ },
35
+ },
36
+ },
37
+ };
38
+
39
+ const TOKSCALE_CLIENT_MAP = {
40
+ claude: "claude",
41
+ codex: "codex",
42
+ "devin-cli": "devin",
43
+ "devin-desktop": "devin",
44
+ gemini: "gemini",
45
+ amp: "amp",
46
+ kimi: "kimi",
47
+ qwen: "qwen",
48
+ goose: "goose",
49
+ kilo: "kilo",
50
+ kilocode: "kilo",
51
+ hermes: "hermes",
52
+ droid: "droid",
53
+ codebuff: "codebuff",
54
+ copilot: "copilot",
55
+ opencode: "opencode",
56
+ openclaw: "openclaw",
57
+ pi: "pi",
58
+ cursor: "other",
59
+ roocode: "other",
60
+ mux: "other",
61
+ crush: "other",
62
+ antigravity: "other",
63
+ "antigravity-cli": "other",
64
+ zed: "other",
65
+ kiro: "other",
66
+ trae: "other",
67
+ warp: "other",
68
+ cline: "other",
69
+ gjc: "other",
70
+ grok: "other",
71
+ jcode: "other",
72
+ commandcode: "other",
73
+ micode: "other",
74
+ junie: "other",
75
+ zcode: "other",
76
+ opencodereview: "other",
77
+ codebuddy: "other",
78
+ workbuddy: "other",
79
+ synthetic: null,
80
+ };
81
+
82
+ /**
83
+ * Run `tokscale models --json` and return a model-level breakdown per platform.
84
+ * Models under `threshold` (default 1%) of their platform's total are lumped
85
+ * into "other" to keep the display clean.
86
+ *
87
+ * Returns: { platform: [{ model, input, output, cacheRead, cacheCreate, pct }] }
88
+ */
89
+ export async function tokscaleModelBreakdown(threshold = 0.01) {
90
+ const raw = await execFileAsync("tokscale", ["models", "--json"], 60000);
91
+ const data = JSON.parse(raw);
92
+ const entries = Array.isArray(data?.entries)
93
+ ? data.entries
94
+ : Array.isArray(data)
95
+ ? data
96
+ : [];
97
+ if (!entries.length) return {};
98
+
99
+ // Group entries by our platform name
100
+ const byPlatform = {};
101
+ for (const e of entries) {
102
+ if (!e || !e.client) continue;
103
+ if (e.model === "<synthetic>" || e.model === "unknown") continue;
104
+ const input = Number(e.input) || 0;
105
+ const output = Number(e.output) || 0;
106
+ if (input + output === 0) continue;
107
+ const platform = TOKSCALE_CLIENT_MAP[e.client];
108
+ if (platform === null) continue;
109
+ const p = platform || "other";
110
+ if (!byPlatform[p]) byPlatform[p] = [];
111
+ byPlatform[p].push({
112
+ model: e.model,
113
+ input,
114
+ output,
115
+ cacheRead: Number(e.cacheRead) || 0,
116
+ cacheCreate: Number(e.cacheWrite) || 0,
117
+ });
118
+ }
119
+
120
+ // For each platform: sort by total tokens desc, lump small models into "other"
121
+ const result = {};
122
+ for (const [platform, models] of Object.entries(byPlatform)) {
123
+ const total = models.reduce(
124
+ (s, m) => s + m.input + m.output + m.cacheRead + m.cacheCreate,
125
+ 0,
126
+ );
127
+ if (total === 0) continue;
128
+ const sorted = models.sort(
129
+ (a, b) =>
130
+ b.input + b.output + b.cacheRead + b.cacheCreate -
131
+ (a.input + a.output + a.cacheRead + a.cacheCreate),
132
+ );
133
+ const big = [];
134
+ const small = { model: "other", input: 0, output: 0, cacheRead: 0, cacheCreate: 0 };
135
+ for (const m of sorted) {
136
+ const t = m.input + m.output + m.cacheRead + m.cacheCreate;
137
+ if (t / total < threshold) {
138
+ small.input += m.input;
139
+ small.output += m.output;
140
+ small.cacheRead += m.cacheRead;
141
+ small.cacheCreate += m.cacheCreate;
142
+ } else {
143
+ big.push({ ...m, pct: t / total });
144
+ }
145
+ }
146
+ if (small.input + small.output + small.cacheRead + small.cacheCreate > 0) {
147
+ const t = small.input + small.output + small.cacheRead + small.cacheCreate;
148
+ big.push({ ...small, pct: t / total });
149
+ }
150
+ result[platform] = big;
151
+ }
152
+ return result;
153
+ }
154
+
155
+ export async function handleTokscaleBreakdown(args) {
156
+ const threshold = Number(args?.threshold ?? 0.01);
157
+ const platforms = await tokscaleModelBreakdown(threshold);
158
+ return { platforms };
159
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * tools/tokscale-competitive-intel.mjs — tokscale_competitive_intel tool.
3
+ */
4
+
5
+ import { tokscaleCompetitiveIntel } from "../tokscale_analytics.mjs";
6
+ import { ANNOTATIONS } from "./_schemas.mjs";
7
+
8
+ export const TOOL_DEF = {
9
+ name: "tokscale_competitive_intel",
10
+ description:
11
+ "Competitive intelligence for any AI tool company. Pass a target tool (by tokscale client slug like 'claude', 'codex', 'devin-cli' or canonical platform name like 'devin', 'other') and get: the target's rank by tokens among all detected tools, its full profile (tokens, cost, model mix, cache_read_pct, cost_per_million_tokens, market share), and a head-to-head comparison against every competitor (each competitor's tokens, cost, model_count, share, cost_per_million_tokens). Returns market_totals for context. If the target is not found, lists all detected clients. Use this to benchmark one AI tool against its competitors on this machine. All data is local — this is your own usage, not aggregate market data.",
12
+ annotations: { title: "Competitive intelligence", ...ANNOTATIONS.readOnlyHint, ...ANNOTATIONS.openWorldHint },
13
+ inputSchema: {
14
+ type: "object",
15
+ properties: {
16
+ target: {
17
+ type: "string",
18
+ description:
19
+ "The AI tool to analyze. Accepts a tokscale client slug (e.g. 'claude', 'codex', 'devin-cli', 'copilot') or a canonical platform name (e.g. 'devin', 'claude', 'other'). Case-insensitive. To discover valid slugs, call tokscale_market_share first.",
20
+ },
21
+ },
22
+ required: ["target"],
23
+ description: "Requires the target tool name. No other parameters accepted.",
24
+ },
25
+ outputSchema: {
26
+ type: "object",
27
+ properties: {
28
+ target: { type: "string", description: "The resolved target slug(s)" },
29
+ found: { type: "boolean", description: "Whether the target was found in local data" },
30
+ rank_by_tokens: { type: "integer", description: "Target's rank among all detected tools by token volume" },
31
+ target_profile: { type: "object", description: "Target's full usage profile with model mix and market share" },
32
+ competitors: { type: "array", description: "All other detected tools with comparison metrics" },
33
+ market_totals: { type: "object", description: "Aggregate market context: { tokens, cost, messages, tool_count }" },
34
+ error: { type: "string", description: "Present if tokscale is unavailable or target is empty" },
35
+ },
36
+ },
37
+ };
38
+
39
+ export async function handleTokscaleCompetitiveIntel(args) {
40
+ const target = String(args?.target || "").trim();
41
+ if (!target) {
42
+ throw new Error("tokscale_competitive_intel requires a non-empty `target` argument (a tokscale client slug like 'claude' or 'codex').");
43
+ }
44
+ return await tokscaleCompetitiveIntel(target);
45
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * tools/tokscale-cost-analysis.mjs — tokscale_cost_analysis tool.
3
+ */
4
+
5
+ import { tokscaleCostAnalysis } from "../tokscale_analytics.mjs";
6
+ import { ANNOTATIONS } from "./_schemas.mjs";
7
+
8
+ export const TOOL_DEF = {
9
+ name: "tokscale_cost_analysis",
10
+ description:
11
+ "Cost analysis per developer per model from your local tokscale data. Returns a per-client × per-model cost breakdown with cost_per_million_tokens, cost_per_message, and share_cost. Includes a per-client cost rollup and totals: total_cost, total_tokens, avg_cost_per_million_tokens, most_expensive_model, cheapest_per_token. Use this to see exactly where your AI spend goes — which tools and models cost the most and which give the best value per token. Do NOT use this for market share — use tokscale_market_share for that.",
12
+ annotations: { title: "Cost analysis per model", ...ANNOTATIONS.readOnlyHint, ...ANNOTATIONS.openWorldHint },
13
+ inputSchema: {
14
+ type: "object",
15
+ properties: {},
16
+ description: "No parameters. Derives cost breakdown from tokscale models data.",
17
+ },
18
+ outputSchema: {
19
+ type: "object",
20
+ properties: {
21
+ entries: { type: "array", description: "Per-client×per-model cost rows sorted by cost desc" },
22
+ client_rollup: { type: "array", description: "Per-client cost summary with share_cost and cost_per_million_tokens" },
23
+ totals: { type: "object", description: "Aggregate cost totals and extremes" },
24
+ error: { type: "string", description: "Present if tokscale is unavailable" },
25
+ },
26
+ },
27
+ };
28
+
29
+ export async function handleTokscaleCostAnalysis() {
30
+ return await tokscaleCostAnalysis();
31
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * tools/tokscale-developer-profile.mjs — tokscale_developer_profile tool.
3
+ */
4
+
5
+ import { tokscaleDeveloperProfile } from "../tokscale_analytics.mjs";
6
+ import { ANNOTATIONS } from "./_schemas.mjs";
7
+
8
+ export const TOOL_DEF = {
9
+ name: "tokscale_developer_profile",
10
+ description:
11
+ "Per-developer usage profile across all 20+ AI tools detected by tokscale on this machine. For each tool: model mix (per-model tokens/cost/messages/performance), token pillars (input/output/cache_read/cache_write/reasoning), cache_read_pct, session count, scan path (redacted to ~), workspace breakdown, and headless support flag. Returns a summary with tool_count, total_cost, dominant_tool. All filesystem paths are redacted (home dir → ~). Use this to understand your full AI tool footprint — which tools you use, which models per tool, and how your usage is distributed. Do NOT use this for cost-only analysis — use tokscale_cost_analysis for that.",
12
+ annotations: { title: "Developer usage profile", ...ANNOTATIONS.readOnlyHint, ...ANNOTATIONS.openWorldHint },
13
+ inputSchema: {
14
+ type: "object",
15
+ properties: {},
16
+ description: "No parameters. Profiles all locally-detected AI tools via tokscale.",
17
+ },
18
+ outputSchema: {
19
+ type: "object",
20
+ properties: {
21
+ tools: {
22
+ type: "array",
23
+ description: "Per-tool profile with model mix, token pillars, session counts, workspaces",
24
+ },
25
+ summary: {
26
+ type: "object",
27
+ description: "Aggregate summary: { tool_count, total_cost, total_tokens, total_messages, avg_cost_per_tool, dominant_tool }",
28
+ },
29
+ error: { type: "string", description: "Present if tokscale is unavailable" },
30
+ },
31
+ },
32
+ };
33
+
34
+ export async function handleTokscaleDeveloperProfile() {
35
+ return await tokscaleDeveloperProfile();
36
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * tools/tokscale-device-profile.mjs — tokscale_device_profile tool.
3
+ */
4
+
5
+ import { tokscaleDeviceProfile } from "../tokscale_analytics.mjs";
6
+ import { ANNOTATIONS } from "./_schemas.mjs";
7
+
8
+ export const TOOL_DEF = {
9
+ name: "tokscale_device_profile",
10
+ description:
11
+ "Device fingerprinting: profiles this machine's AI tool footprint — which AI tools are installed, where their session logs live (paths redacted to ~), how many sessions and messages each has, when the machine was active (daily activity + day-of-week distribution), session concurrency, and longest continuous session. Combines tokscale clients + graph data. All filesystem paths are redacted so no local username leaks. Use this to audit your own machine's AI tool installation and activity pattern. This is local-only — it profiles the current machine, not remote devices.",
12
+ annotations: { title: "Device profile", ...ANNOTATIONS.readOnlyHint, ...ANNOTATIONS.openWorldHint },
13
+ inputSchema: {
14
+ type: "object",
15
+ properties: {},
16
+ description: "No parameters. Profiles the local machine via tokscale.",
17
+ },
18
+ outputSchema: {
19
+ type: "object",
20
+ properties: {
21
+ installed_tools: { type: "array", description: "Detected AI tools with redacted session paths and message counts" },
22
+ installed_tool_count: { type: "integer" },
23
+ active_tool_count: { type: "integer", description: "Tools whose session path exists on disk" },
24
+ date_range: { type: "object", description: "{ start, end } of the activity data" },
25
+ activity: { type: "object", description: "Daily activity + day-of-week token distribution" },
26
+ sessions: { type: "object", description: "Session metrics: count, total/longest active time, max concurrent" },
27
+ summary: { type: "object", description: "Cost summary from graph: total_tokens, total_cost, avg_per_day, max_single_day" },
28
+ error: { type: "string", description: "Present if tokscale is unavailable" },
29
+ },
30
+ },
31
+ };
32
+
33
+ export async function handleTokscaleDeviceProfile() {
34
+ return await tokscaleDeviceProfile();
35
+ }