@ipv9/tokentracker-cli 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/LICENSE +21 -0
  2. package/README.ja.md +464 -0
  3. package/README.ko.md +464 -0
  4. package/README.md +476 -0
  5. package/README.zh-CN.md +469 -0
  6. package/bin/tracker.js +52 -0
  7. package/dashboard/dist/app-icon.png +0 -0
  8. package/dashboard/dist/apple-touch-icon.png +0 -0
  9. package/dashboard/dist/assets/ActivityHeatmap-BxBGHY1z.js +42 -0
  10. package/dashboard/dist/assets/Card-GROxUc_6.js +1 -0
  11. package/dashboard/dist/assets/DashboardPage-BZ5VFoBk.js +19 -0
  12. package/dashboard/dist/assets/DevicePage-CQts7ivB.js +1 -0
  13. package/dashboard/dist/assets/DialogTitle-DqFsk26U.js +1 -0
  14. package/dashboard/dist/assets/FadeIn-HBBXW_3q.js +1 -0
  15. package/dashboard/dist/assets/HeaderGithubStar-COD2HfaF.js +1 -0
  16. package/dashboard/dist/assets/IpCheckPage-Cn0l8-BQ.js +15 -0
  17. package/dashboard/dist/assets/LandingPage-CmV1BMU4.js +4356 -0
  18. package/dashboard/dist/assets/LeaderboardAvatar-CiIpWZwb.js +1 -0
  19. package/dashboard/dist/assets/LeaderboardPage-BU0mlR3g.js +6 -0
  20. package/dashboard/dist/assets/LeaderboardProfileModal-C49_3Xm9.js +72 -0
  21. package/dashboard/dist/assets/LeaderboardProfilePage-Bh1n0BAM.js +1 -0
  22. package/dashboard/dist/assets/LimitsPage-fZAmwLWT.js +2 -0
  23. package/dashboard/dist/assets/LocalOnlyNotice-D3rQdA-P.js +1 -0
  24. package/dashboard/dist/assets/LoginPage-enO4XP-c.js +1 -0
  25. package/dashboard/dist/assets/PopoverPopup-pitJEpN1.js +1 -0
  26. package/dashboard/dist/assets/Select-tT9x4ntD.js +1 -0
  27. package/dashboard/dist/assets/SelectItemText-C7F7eIm0.js +1 -0
  28. package/dashboard/dist/assets/SettingsPage-pDasZNU2.js +1 -0
  29. package/dashboard/dist/assets/SkillsPage-DEu7FY-2.js +1 -0
  30. package/dashboard/dist/assets/WidgetsPage-DGcO7rbp.js +1 -0
  31. package/dashboard/dist/assets/WrappedPage-D_1ID213.js +1 -0
  32. package/dashboard/dist/assets/agent-logos-DXQVg1xy.js +1 -0
  33. package/dashboard/dist/assets/arrow-up-right-DNLo92Ba.js +1 -0
  34. package/dashboard/dist/assets/download-DbBBBpJF.js +1 -0
  35. package/dashboard/dist/assets/geist-mono-cyrillic-400-normal-BPBWmzPh.woff +0 -0
  36. package/dashboard/dist/assets/geist-mono-cyrillic-400-normal-Ce5q_31Z.woff2 +0 -0
  37. package/dashboard/dist/assets/geist-mono-cyrillic-500-normal-CJBLNVQT.woff2 +0 -0
  38. package/dashboard/dist/assets/geist-mono-cyrillic-500-normal-mNhfPmgl.woff +0 -0
  39. package/dashboard/dist/assets/geist-mono-cyrillic-700-normal-DH5Q319x.woff +0 -0
  40. package/dashboard/dist/assets/geist-mono-cyrillic-700-normal-VCNRadI3.woff2 +0 -0
  41. package/dashboard/dist/assets/geist-mono-cyrillic-900-normal-BKC3PZkM.woff +0 -0
  42. package/dashboard/dist/assets/geist-mono-cyrillic-900-normal-DdrQ8KBw.woff2 +0 -0
  43. package/dashboard/dist/assets/geist-mono-latin-400-normal-CoULgQGM.woff +0 -0
  44. package/dashboard/dist/assets/geist-mono-latin-400-normal-LC9RFr9I.woff2 +0 -0
  45. package/dashboard/dist/assets/geist-mono-latin-500-normal-D3o2eNa9.woff2 +0 -0
  46. package/dashboard/dist/assets/geist-mono-latin-500-normal-DOxI7kZ4.woff +0 -0
  47. package/dashboard/dist/assets/geist-mono-latin-700-normal-D6izGJRP.woff2 +0 -0
  48. package/dashboard/dist/assets/geist-mono-latin-700-normal-QGw08Lff.woff +0 -0
  49. package/dashboard/dist/assets/geist-mono-latin-900-normal-CmoKXrdK.woff +0 -0
  50. package/dashboard/dist/assets/geist-mono-latin-900-normal-Cu5MFKsu.woff2 +0 -0
  51. package/dashboard/dist/assets/geist-mono-latin-ext-400-normal-Cgks_Qgx.woff2 +0 -0
  52. package/dashboard/dist/assets/geist-mono-latin-ext-400-normal-CxNRRMGd.woff +0 -0
  53. package/dashboard/dist/assets/geist-mono-latin-ext-500-normal-CQcGuCNt.woff2 +0 -0
  54. package/dashboard/dist/assets/geist-mono-latin-ext-500-normal-diTenJ8L.woff +0 -0
  55. package/dashboard/dist/assets/geist-mono-latin-ext-700-normal-BX9f1BHp.woff +0 -0
  56. package/dashboard/dist/assets/geist-mono-latin-ext-700-normal-YOllDaLV.woff2 +0 -0
  57. package/dashboard/dist/assets/geist-mono-latin-ext-900-normal-Br6WNUGb.woff +0 -0
  58. package/dashboard/dist/assets/geist-mono-latin-ext-900-normal-CrmBTzU2.woff2 +0 -0
  59. package/dashboard/dist/assets/index-BeoRn2gJ.js +2 -0
  60. package/dashboard/dist/assets/info-Bh5qTz6k.js +1 -0
  61. package/dashboard/dist/assets/main-BIY3Nj6I.js +969 -0
  62. package/dashboard/dist/assets/main-G_F9Iu_x.css +1 -0
  63. package/dashboard/dist/assets/use-limits-display-prefs-B4iJ-bBc.js +1 -0
  64. package/dashboard/dist/assets/use-native-settings-DHjPFDv8.js +1 -0
  65. package/dashboard/dist/assets/use-usage-limits-odqe9OY7.js +1 -0
  66. package/dashboard/dist/assets/useCurrency-BsSZiZMP.js +1 -0
  67. package/dashboard/dist/assets/useOpenInteractionType-BQhgq4rv.js +12 -0
  68. package/dashboard/dist/brand-logos/antigravity.svg +1 -0
  69. package/dashboard/dist/brand-logos/claude-code.svg +1 -0
  70. package/dashboard/dist/brand-logos/codebuddy.svg +1 -0
  71. package/dashboard/dist/brand-logos/codex.svg +15 -0
  72. package/dashboard/dist/brand-logos/copilot.svg +1 -0
  73. package/dashboard/dist/brand-logos/cursor.svg +1 -0
  74. package/dashboard/dist/brand-logos/gemini.svg +1 -0
  75. package/dashboard/dist/brand-logos/grok.svg +1 -0
  76. package/dashboard/dist/brand-logos/hermes.svg +1 -0
  77. package/dashboard/dist/brand-logos/kilo.svg +4 -0
  78. package/dashboard/dist/brand-logos/kimi.svg +1 -0
  79. package/dashboard/dist/brand-logos/kiro.svg +1 -0
  80. package/dashboard/dist/brand-logos/openclaw.svg +22 -0
  81. package/dashboard/dist/brand-logos/opencode.svg +3 -0
  82. package/dashboard/dist/clawd/happy.svg +161 -0
  83. package/dashboard/dist/clawd/idle/collapse.svg +101 -0
  84. package/dashboard/dist/clawd/idle/doze.svg +72 -0
  85. package/dashboard/dist/clawd/idle/follow.svg +64 -0
  86. package/dashboard/dist/clawd/idle/living.svg +196 -0
  87. package/dashboard/dist/clawd/idle/look.svg +115 -0
  88. package/dashboard/dist/clawd/idle/yawn.svg +158 -0
  89. package/dashboard/dist/clawd/mini/alert.svg +129 -0
  90. package/dashboard/dist/clawd/mini/crabwalk.svg +76 -0
  91. package/dashboard/dist/clawd/mini/enter-sleep.svg +65 -0
  92. package/dashboard/dist/clawd/mini/enter.svg +115 -0
  93. package/dashboard/dist/clawd/mini/happy.svg +124 -0
  94. package/dashboard/dist/clawd/mini/idle-tight.svg +15 -0
  95. package/dashboard/dist/clawd/mini/idle.svg +83 -0
  96. package/dashboard/dist/clawd/mini/peek.svg +82 -0
  97. package/dashboard/dist/clawd/mini/sleep.svg +112 -0
  98. package/dashboard/dist/clawd/react/double.svg +108 -0
  99. package/dashboard/dist/clawd/react/drag.svg +102 -0
  100. package/dashboard/dist/clawd/react/left.svg +102 -0
  101. package/dashboard/dist/clawd/react/right.svg +102 -0
  102. package/dashboard/dist/clawd/sleep/collapse-sleep.svg +247 -0
  103. package/dashboard/dist/clawd/sleep/sleeping.svg +118 -0
  104. package/dashboard/dist/clawd/sleep/wake.svg +277 -0
  105. package/dashboard/dist/clawd/static-base.svg +21 -0
  106. package/dashboard/dist/clawd/status/disconnected.svg +136 -0
  107. package/dashboard/dist/clawd/status/error.svg +94 -0
  108. package/dashboard/dist/clawd/status/notification.svg +134 -0
  109. package/dashboard/dist/clawd/working/building.svg +231 -0
  110. package/dashboard/dist/clawd/working/carrying.svg +107 -0
  111. package/dashboard/dist/clawd/working/conducting.svg +118 -0
  112. package/dashboard/dist/clawd/working/confused.svg +113 -0
  113. package/dashboard/dist/clawd/working/debugger.svg +91 -0
  114. package/dashboard/dist/clawd/working/juggling.svg +82 -0
  115. package/dashboard/dist/clawd/working/overheated.svg +75 -0
  116. package/dashboard/dist/clawd/working/pushing.svg +125 -0
  117. package/dashboard/dist/clawd/working/sweeping.svg +79 -0
  118. package/dashboard/dist/clawd/working/thinking.svg +119 -0
  119. package/dashboard/dist/clawd/working/typing.svg +153 -0
  120. package/dashboard/dist/clawd/working/ultrathink.svg +166 -0
  121. package/dashboard/dist/clawd/working/wizard.svg +98 -0
  122. package/dashboard/dist/dashboard-dark.png +0 -0
  123. package/dashboard/dist/favicon-16.png +0 -0
  124. package/dashboard/dist/favicon-32.png +0 -0
  125. package/dashboard/dist/favicon.ico +0 -0
  126. package/dashboard/dist/feed.xml +34 -0
  127. package/dashboard/dist/icon-192.png +0 -0
  128. package/dashboard/dist/icon-512.png +0 -0
  129. package/dashboard/dist/index.html +355 -0
  130. package/dashboard/dist/llms.txt +53 -0
  131. package/dashboard/dist/neon_bg.png +0 -0
  132. package/dashboard/dist/robots.txt +7 -0
  133. package/dashboard/dist/share.html +140 -0
  134. package/dashboard/dist/sitemap.xml +27 -0
  135. package/dashboard/dist/widgets-overview.png +0 -0
  136. package/package.json +78 -0
  137. package/scripts/install-local-service.sh +140 -0
  138. package/scripts/uninstall-local-service.sh +21 -0
  139. package/src/cli.js +95 -0
  140. package/src/commands/device-login.js +161 -0
  141. package/src/commands/diagnostics.js +38 -0
  142. package/src/commands/doctor.js +96 -0
  143. package/src/commands/init.js +1195 -0
  144. package/src/commands/serve.js +351 -0
  145. package/src/commands/status.js +609 -0
  146. package/src/commands/sync.js +2285 -0
  147. package/src/commands/uninstall.js +189 -0
  148. package/src/commands/wrapped.js +150 -0
  149. package/src/lib/antigravity-paths.js +48 -0
  150. package/src/lib/browser-auth.js +281 -0
  151. package/src/lib/categorizer-utils.js +232 -0
  152. package/src/lib/claude-categorizer.js +1319 -0
  153. package/src/lib/claude-config.js +204 -0
  154. package/src/lib/cli-ui.js +179 -0
  155. package/src/lib/codex-config.js +350 -0
  156. package/src/lib/codex-context-breakdown.js +400 -0
  157. package/src/lib/codex-rollout-parser.js +623 -0
  158. package/src/lib/codex-token-refresh.js +112 -0
  159. package/src/lib/cursor-config.js +425 -0
  160. package/src/lib/debug-flags.js +7 -0
  161. package/src/lib/diagnostics.js +272 -0
  162. package/src/lib/doctor.js +338 -0
  163. package/src/lib/fs.js +91 -0
  164. package/src/lib/gemini-config.js +288 -0
  165. package/src/lib/grok-hook.js +351 -0
  166. package/src/lib/init-flow.js +42 -0
  167. package/src/lib/local-api.js +1861 -0
  168. package/src/lib/openclaw-hook.js +420 -0
  169. package/src/lib/openclaw-session-plugin.js +520 -0
  170. package/src/lib/opencode-config.js +99 -0
  171. package/src/lib/passive-mode.js +185 -0
  172. package/src/lib/pricing/curated-overrides.json +79 -0
  173. package/src/lib/pricing/index.js +143 -0
  174. package/src/lib/pricing/litellm-fetcher.js +172 -0
  175. package/src/lib/pricing/matcher.js +255 -0
  176. package/src/lib/pricing/seed-snapshot.json +1 -0
  177. package/src/lib/progress.js +76 -0
  178. package/src/lib/project-usage-purge.js +106 -0
  179. package/src/lib/prompt.js +24 -0
  180. package/src/lib/proxy-env.js +131 -0
  181. package/src/lib/rollout.js +8442 -0
  182. package/src/lib/runtime-config.js +122 -0
  183. package/src/lib/skill-usage.js +267 -0
  184. package/src/lib/skills-manager.js +1127 -0
  185. package/src/lib/source-metadata.js +48 -0
  186. package/src/lib/sqlite-reader.js +136 -0
  187. package/src/lib/static-server.js +59 -0
  188. package/src/lib/subscriptions.js +453 -0
  189. package/src/lib/tracker-paths.js +16 -0
  190. package/src/lib/upload-throttle.js +148 -0
  191. package/src/lib/usage-limits.js +1806 -0
  192. package/src/lib/wrapped-aggregator.js +225 -0
@@ -0,0 +1,232 @@
1
+ // Shared helpers for claude-categorizer.js and codex-context-breakdown.js.
2
+ // Extracted to eliminate copy-paste between the two files.
3
+
4
+ "use strict";
5
+
6
+ const path = require("node:path");
7
+
8
+ // ---------------------------------------------------------------------------
9
+ // Tool categorizer
10
+ // ---------------------------------------------------------------------------
11
+
12
+ function categorizeTool(name) {
13
+ if (name === "text_response") return "Text Response";
14
+ if (name === "Malformed") return "Malformed";
15
+
16
+ if (name.startsWith("mcp__")) {
17
+ const parts = name.split("__");
18
+ if (parts.length >= 3) {
19
+ const serverRaw = parts[1];
20
+ let server;
21
+ const pluginMatch = serverRaw.match(/^plugin_(.+)$/);
22
+ if (pluginMatch) {
23
+ const inner = pluginMatch[1];
24
+ const segments = inner.split("_");
25
+ const half = Math.floor(segments.length / 2);
26
+ const firstHalf = segments.slice(0, half).join("_");
27
+ const secondHalf = segments.slice(half).join("_");
28
+ if (firstHalf && firstHalf === secondHalf) {
29
+ server = firstHalf;
30
+ } else {
31
+ server = inner;
32
+ }
33
+ } else {
34
+ server = serverRaw;
35
+ }
36
+ server = server.replace(/_/g, "-");
37
+ return `MCP: ${server}`;
38
+ }
39
+ return "MCP: Unknown";
40
+ }
41
+
42
+ if (/^Task(Create|Update|Get|List|Output|Stop)$/.test(name)) return "Task Mgmt";
43
+ if (/^Todo/.test(name)) return "Task Mgmt";
44
+ if (/Plan/.test(name)) return "Planning";
45
+ if (name === "Agent") return "Agent";
46
+ if (/^Web(Fetch|Search)$/.test(name)) return "Web";
47
+ if (name === "Skill") return "Skill";
48
+ if (name === "LSP") return "IDE";
49
+ if (name === "AskUserQuestion") return "Interaction";
50
+
51
+ if (name === "exec_command" || name === "write_stdin") return "Execution";
52
+ if (name === "update_plan") return "Planning";
53
+ if (/_agent$/.test(name)) return "Agent";
54
+ if (/^list_mcp/.test(name)) return "MCP Mgmt";
55
+ if (
56
+ /^(navigate_page|click|select_page|new_page|take_snapshot|take_screenshot|evaluate_script|list_pages|list_console_messages|view_image|emulate|resize_page|wait_for|close_page|get_console_message|get_network_request|list_network_requests|performance_)/.test(
57
+ name,
58
+ )
59
+ )
60
+ return "Browser";
61
+
62
+ // Claude Code built-in tools (also harmless to match from Codex side).
63
+ if (/^(Read|Write|Edit|Glob)$/.test(name)) return "File Ops";
64
+ if (name === "Grep") return "Search";
65
+ if (name === "Bash") return "Execution";
66
+
67
+ if (name.includes("<tool_call>") || name.includes("<arg_")) return "Malformed";
68
+
69
+ return "Other";
70
+ }
71
+
72
+ // ---------------------------------------------------------------------------
73
+ // Shell command helpers
74
+ // ---------------------------------------------------------------------------
75
+
76
+ function inferExecCommandKind(command) {
77
+ const cmd = String(command || "").trim();
78
+ if (/^(npm|yarn|pnpm)\s+(run\s+)?(build|build:|.*:build\b)/.test(cmd)) return "build";
79
+ if (/^(npm|yarn|pnpm)\s+(test|run\s+test\b|run\s+.*test\b)/.test(cmd)) return "test";
80
+ if (/^(npm|yarn|pnpm)\s+run\s+typecheck\b/.test(cmd)) return "typecheck";
81
+ if (/^(npm|yarn|pnpm)\s+(install|add|ci)\b/.test(cmd)) return "dependency";
82
+ if (/^(npm|yarn|pnpm)\s+(pack|publish|version)\b/.test(cmd)) return "package";
83
+ if (/^(npm|yarn|pnpm)\s+run\s+(dev|serve|start|.*dev.*)\b/.test(cmd)) return "dev_server";
84
+ if (/^node\s+--check\b/.test(cmd) || /\bnode\s+--check\b/.test(cmd)) return "syntax_check";
85
+ if (/^node\s+--input-type=module\s+-e\b/.test(cmd) || /^node\s+-e\b/.test(cmd)) return "node_eval";
86
+ if (/^node\s+.*\b(query|analyze|report)\b/.test(cmd)) return "node_cli";
87
+ if (/^git\s+status\b/.test(cmd)) return "git_status";
88
+ if (/^git\s+(push|pull|fetch|clone)\b/.test(cmd) || /\bgit\s+(push|pull|fetch|clone)\b/.test(cmd)) return "git_remote";
89
+ if (/^git\s+(add|commit|branch|config|remote|restore)\b/.test(cmd) || /\bgit\s+(add|commit|branch|config|remote|restore)\b/.test(cmd)) return "git_local";
90
+ if (/^(curl|wget)\b/.test(cmd) || /\b(curl|wget)\b/.test(cmd)) return "http";
91
+ if (/^(ps|pgrep|pkill|kill|lsof)\b/.test(cmd)) return "process";
92
+ if (/^tmux\b/.test(cmd)) return "terminal";
93
+ if (/^(open|osascript)\b/.test(cmd)) return "browser_control";
94
+ if (/^(rm|mkdir|touch|chmod|cp|mv)\b/.test(cmd)) return "file_mutation";
95
+ if (/^(pwd|ls|test)\b/.test(cmd) || /^(pwd|ls)\s*[;&|]/.test(cmd)) return "shell_inspect";
96
+ if (/[;&|]{1,2}/.test(cmd)) return "compound";
97
+ return "unknown";
98
+ }
99
+
100
+ function shellWords(command) {
101
+ const out = [];
102
+ const re = /"([^"\\]*(?:\\.[^"\\]*)*)"|'([^']*)'|(\S+)/g;
103
+ let match;
104
+ while ((match = re.exec(String(command || ""))) !== null) {
105
+ out.push(match[1] ?? match[2] ?? match[3] ?? "");
106
+ }
107
+ return out.filter(Boolean);
108
+ }
109
+
110
+ function unwrapShellCommand(words) {
111
+ if (words.length >= 3 && /^(bash|sh|zsh|fish)$/.test(words[0]) && words[1] === "-lc") {
112
+ return shellWords(words.slice(2).join(" "));
113
+ }
114
+ if (words.length >= 3 && /^(rtk|env|command|xcrun)$/.test(words[0])) {
115
+ return unwrapShellCommand(words.slice(1));
116
+ }
117
+ return words;
118
+ }
119
+
120
+ function sanitizeCommandSignature(command) {
121
+ const words = unwrapShellCommand(shellWords(command));
122
+ if (words.length === 0) return "unknown";
123
+ const executable = path.basename(words[0] || "unknown");
124
+ const subcommand = words.find((word, idx) => {
125
+ if (idx === 0) return false;
126
+ if (!word || word.startsWith("-")) return false;
127
+ if (/^[A-Z_][A-Z0-9_]*=/.test(word)) return false;
128
+ return true;
129
+ });
130
+ return subcommand ? `${executable} ${subcommand}` : executable;
131
+ }
132
+
133
+ function getExecutableName(command) {
134
+ const words = unwrapShellCommand(shellWords(command));
135
+ if (words.length === 0) return "unknown";
136
+ return path.basename(words[0] || "unknown") || "unknown";
137
+ }
138
+
139
+ // ---------------------------------------------------------------------------
140
+ // Token totals helpers
141
+ // ---------------------------------------------------------------------------
142
+
143
+ function emptyTotals() {
144
+ return {
145
+ input_tokens: 0,
146
+ cached_input_tokens: 0,
147
+ cache_creation_input_tokens: 0,
148
+ output_tokens: 0,
149
+ reasoning_output_tokens: 0,
150
+ total_tokens: 0,
151
+ };
152
+ }
153
+
154
+ function addInto(target, source) {
155
+ target.input_tokens += source.input_tokens || 0;
156
+ target.cached_input_tokens += source.cached_input_tokens || 0;
157
+ target.cache_creation_input_tokens += source.cache_creation_input_tokens || 0;
158
+ target.output_tokens += source.output_tokens || 0;
159
+ target.reasoning_output_tokens += source.reasoning_output_tokens || 0;
160
+ target.total_tokens += source.total_tokens || 0;
161
+ }
162
+
163
+ function roundTotals(totals) {
164
+ return {
165
+ input_tokens: Math.round(totals?.input_tokens || 0),
166
+ cached_input_tokens: Math.round(totals?.cached_input_tokens || 0),
167
+ cache_creation_input_tokens: Math.round(totals?.cache_creation_input_tokens || 0),
168
+ output_tokens: Math.round(totals?.output_tokens || 0),
169
+ reasoning_output_tokens: Math.round(totals?.reasoning_output_tokens || 0),
170
+ total_tokens: Math.round(totals?.total_tokens || 0),
171
+ };
172
+ }
173
+
174
+ function buildExecStatsEntry() {
175
+ return {
176
+ calls: 0,
177
+ failures: 0,
178
+ duration_ms: 0,
179
+ max_duration_ms: 0,
180
+ output_chars: 0,
181
+ output_lines: 0,
182
+ totals: emptyTotals(),
183
+ };
184
+ }
185
+
186
+ // ---------------------------------------------------------------------------
187
+ // Integer allocation
188
+ // ---------------------------------------------------------------------------
189
+
190
+ function allocateByLargestRemainder(total, weights, order) {
191
+ const out = {};
192
+ if (!Number.isFinite(total) || total <= 0) {
193
+ for (const key of order) out[key] = 0;
194
+ return out;
195
+ }
196
+
197
+ let totalWeight = 0;
198
+ for (const key of order) {
199
+ const w = Number(weights[key] || 0);
200
+ if (Number.isFinite(w) && w > 0) totalWeight += w;
201
+ }
202
+
203
+ if (totalWeight <= 0) {
204
+ for (const key of order) out[key] = 0;
205
+ return out;
206
+ }
207
+
208
+ const exact = order.map((key) => (Number(weights[key] || 0) / totalWeight) * total);
209
+ const floored = exact.map((x) => Math.floor(x));
210
+ const remainder = total - floored.reduce((a, b) => a + b, 0);
211
+ const remainders = exact
212
+ .map((x, i) => ({ i, frac: x - Math.floor(x) }))
213
+ .sort((a, b) => b.frac - a.frac);
214
+ for (let k = 0; k < remainder; k++) floored[remainders[k % order.length].i] += 1;
215
+
216
+ for (let i = 0; i < order.length; i++) out[order[i]] = floored[i];
217
+ return out;
218
+ }
219
+
220
+ module.exports = {
221
+ categorizeTool,
222
+ inferExecCommandKind,
223
+ shellWords,
224
+ unwrapShellCommand,
225
+ sanitizeCommandSignature,
226
+ getExecutableName,
227
+ emptyTotals,
228
+ addInto,
229
+ roundTotals,
230
+ buildExecStatsEntry,
231
+ allocateByLargestRemainder,
232
+ };