tokenusage-cli 0.1.0 → 0.2.1
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/CHANGELOG.md +46 -19
- package/LICENSE +22 -22
- package/README.md +123 -94
- package/THIRD_PARTY_NOTICES.md +140 -140
- package/bin/tokenusage.js +69 -69
- package/package.json +59 -59
- package/src/cli.js +146 -134
- package/src/commands/device-login.js +205 -205
- package/src/commands/diagnostics.js +38 -38
- package/src/commands/doctor.js +110 -110
- package/src/commands/init.js +2484 -2436
- package/src/commands/pause.js +77 -0
- package/src/commands/sessions.js +29 -29
- package/src/commands/status.js +1758 -1747
- package/src/commands/sync.js +8048 -7934
- package/src/commands/uninstall.js +322 -312
- package/src/lib/account-usage-dedup.js +267 -267
- package/src/lib/antigravity-paths.js +48 -48
- package/src/lib/ark-agent-plan-limits.js +438 -438
- package/src/lib/ark-coding-plan-limits.js +537 -537
- package/src/lib/async-queue-reader.js +138 -138
- package/src/lib/atomic-json.js +27 -27
- package/src/lib/bearer-token.js +11 -11
- package/src/lib/categorizer-utils.js +232 -232
- package/src/lib/claude-categorizer.js +1343 -1343
- package/src/lib/claude-config.js +279 -279
- package/src/lib/claude-user-identity.js +56 -56
- package/src/lib/cli-ui.js +179 -179
- package/src/lib/cloud-account.js +541 -541
- package/src/lib/cloud-device-token.js +141 -141
- package/src/lib/cloud-sync-prefs.js +14 -14
- package/src/lib/cloud-usage-reset.js +115 -115
- package/src/lib/codex-config.js +595 -595
- package/src/lib/codex-context-breakdown.js +806 -806
- package/src/lib/codex-model-attribution.js +128 -128
- package/src/lib/codex-rollout-parser.js +1471 -1471
- package/src/lib/codex-service-tier.js +49 -49
- package/src/lib/codex-token-refresh.js +140 -140
- package/src/lib/codex-token-usage.js +195 -195
- package/src/lib/codex-usage-record.js +195 -195
- package/src/lib/collection-pause.js +77 -0
- package/src/lib/command-runner.js +313 -313
- package/src/lib/commandcode-limits.js +317 -317
- package/src/lib/context-health.js +124 -124
- package/src/lib/cursor-config.js +605 -605
- package/src/lib/cursor-store.js +1918 -1918
- package/src/lib/debug-flags.js +7 -7
- package/src/lib/devin-limits.js +249 -249
- package/src/lib/devin-usage.js +212 -212
- package/src/lib/diagnostics.js +383 -383
- package/src/lib/doctor.js +385 -385
- package/src/lib/dumate.js +95 -95
- package/src/lib/fs.js +455 -455
- package/src/lib/function-url.js +14 -14
- package/src/lib/gemini-config.js +291 -291
- package/src/lib/git-outcomes.js +243 -243
- package/src/lib/grok-context-breakdown.js +890 -890
- package/src/lib/grok-hook.js +360 -360
- package/src/lib/grok-limits.js +865 -865
- package/src/lib/grok-usage.js +98 -98
- package/src/lib/heatmap-compact.js +114 -114
- package/src/lib/ingest-sanitize.js +41 -41
- package/src/lib/init-flow.js +42 -42
- package/src/lib/install-resolver.js +170 -170
- package/src/lib/jsonl-lines.js +134 -134
- package/src/lib/kimi-model-repair.js +173 -173
- package/src/lib/kimi-profile.js +61 -61
- package/src/lib/kimi-session.js +216 -216
- package/src/lib/local-api.js +3588 -3588
- package/src/lib/machine-id.js +238 -238
- package/src/lib/multi-install-parser.js +113 -113
- package/src/lib/notify-command.js +38 -38
- package/src/lib/omp-hook.js +589 -589
- package/src/lib/openclaw-cli.js +104 -104
- package/src/lib/openclaw-hook.js +375 -375
- package/src/lib/openclaw-session-plugin.js +560 -560
- package/src/lib/opencode-config.js +121 -121
- package/src/lib/opencode-go-limits.js +807 -807
- package/src/lib/outcomes-engine.js +253 -253
- package/src/lib/passive-mode.js +219 -219
- package/src/lib/pet-packages.js +722 -722
- package/src/lib/pricing/curated-overrides.json +822 -822
- package/src/lib/pricing/index.js +379 -379
- package/src/lib/pricing/litellm-fetcher.js +172 -172
- package/src/lib/pricing/matcher.js +456 -456
- package/src/lib/pricing/seed-snapshot.json +1 -1
- package/src/lib/progress.js +76 -76
- package/src/lib/project-usage-purge.js +117 -117
- package/src/lib/prompt.js +24 -24
- package/src/lib/provider-status.js +104 -104
- package/src/lib/proxy-env.js +489 -489
- package/src/lib/proxy-settings.js +163 -163
- package/src/lib/qoder-cn-cli-limits.js +119 -119
- package/src/lib/qoder-limits.js +880 -880
- package/src/lib/quiet-warnings.js +26 -26
- package/src/lib/rollout.js +26005 -25966
- package/src/lib/runtime-config.js +9 -4
- package/src/lib/scan-roots.js +277 -277
- package/src/lib/scheduled-task.js +145 -0
- package/src/lib/sentry.js +231 -231
- package/src/lib/session-analytics.js +2972 -2972
- package/src/lib/session-performance.js +237 -237
- package/src/lib/session-upload.js +379 -379
- package/src/lib/skill-usage.js +267 -267
- package/src/lib/skills-manager.js +1591 -1591
- package/src/lib/source-metadata.js +48 -48
- package/src/lib/sqlite-reader.js +215 -215
- package/src/lib/star-cta.js +73 -73
- package/src/lib/subscription-manager.js +293 -293
- package/src/lib/subscriptions.js +508 -508
- package/src/lib/sync-report.js +138 -0
- package/src/lib/telemetry.js +193 -193
- package/src/lib/tracker-paths.js +16 -16
- package/src/lib/trae-cn-config.js +548 -548
- package/src/lib/trae-db.js +127 -127
- package/src/lib/trae-snapshot.js +230 -230
- package/src/lib/trae-sqlite.js +143 -143
- package/src/lib/trae-usage.js +121 -121
- package/src/lib/upload-queue.js +134 -134
- package/src/lib/upload-throttle.js +171 -171
- package/src/lib/usage-limits.js +4552 -4552
- package/src/lib/wrapped-aggregator.js +236 -236
- package/src/lib/wsl-probe.js +281 -281
- package/src/lib/zcode-limits.js +1172 -1172
- package/src/lib/zcode-reset-credits.js +66 -66
- package/test/audit-fixes.test.js +200 -0
- package/test/cli-smoke.test.js +53 -53
- package/test/collection-controls.test.js +210 -0
- package/test/ingest-sanitize.test.js +162 -162
- package/test/quiet-warnings.test.js +53 -53
- package/test/session-upload.test.js +427 -427
|
@@ -1,312 +1,322 @@
|
|
|
1
|
-
const os = require("node:os");
|
|
2
|
-
const path = require("node:path");
|
|
3
|
-
const fs = require("node:fs/promises");
|
|
4
|
-
const { expandHome } = require("../lib/scan-roots");
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
restoreCodexNotify,
|
|
8
|
-
restoreAcodeNotify,
|
|
9
|
-
restoreEveryCodeNotify,
|
|
10
|
-
buildCodexNotifyCmd,
|
|
11
|
-
buildAcodeNotifyCmd,
|
|
12
|
-
buildEveryCodeNotifyCmd,
|
|
13
|
-
} = require("../lib/codex-config");
|
|
14
|
-
const {
|
|
15
|
-
removeClaudeHook,
|
|
16
|
-
removeClaudeUsageHooks,
|
|
17
|
-
buildClaudeHookCommand,
|
|
18
|
-
buildHookCommand,
|
|
19
|
-
} = require("../lib/claude-config");
|
|
20
|
-
const {
|
|
21
|
-
resolveGeminiConfigDir,
|
|
22
|
-
resolveGeminiSettingsPath,
|
|
23
|
-
buildGeminiHookCommand,
|
|
24
|
-
removeGeminiHook,
|
|
25
|
-
} = require("../lib/gemini-config");
|
|
26
|
-
const { resolveOpencodeConfigDir, removeOpencodePlugin } = require("../lib/opencode-config");
|
|
27
|
-
const { removeOpenclawHookConfig } = require("../lib/openclaw-hook");
|
|
28
|
-
const { removeOpenclawSessionPluginConfig } = require("../lib/openclaw-session-plugin");
|
|
29
|
-
const { removeGrokHook } = require("../lib/grok-hook");
|
|
30
|
-
const { removeOmpHook } = require("../lib/omp-hook");
|
|
31
|
-
const { resolveTrackerPaths } = require("../lib/tracker-paths");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
: "-
|
|
191
|
-
: "-
|
|
192
|
-
|
|
193
|
-
?
|
|
194
|
-
? `-
|
|
195
|
-
:
|
|
196
|
-
? "-
|
|
197
|
-
: "-
|
|
198
|
-
: "-
|
|
199
|
-
|
|
200
|
-
?
|
|
201
|
-
? `-
|
|
202
|
-
:
|
|
203
|
-
? "-
|
|
204
|
-
: "-
|
|
205
|
-
: "-
|
|
206
|
-
|
|
207
|
-
?
|
|
208
|
-
? `- WorkBuddy
|
|
209
|
-
:
|
|
210
|
-
? "- WorkBuddy
|
|
211
|
-
: "- WorkBuddy
|
|
212
|
-
: "- WorkBuddy
|
|
213
|
-
|
|
214
|
-
?
|
|
215
|
-
? `-
|
|
216
|
-
:
|
|
217
|
-
? "-
|
|
218
|
-
: "-
|
|
219
|
-
:
|
|
220
|
-
|
|
221
|
-
?
|
|
222
|
-
? `-
|
|
223
|
-
:
|
|
224
|
-
? "-
|
|
225
|
-
:
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
return
|
|
277
|
-
}
|
|
278
|
-
if (reason === "
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
return
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
1
|
+
const os = require("node:os");
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
const fs = require("node:fs/promises");
|
|
4
|
+
const { expandHome } = require("../lib/scan-roots");
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
restoreCodexNotify,
|
|
8
|
+
restoreAcodeNotify,
|
|
9
|
+
restoreEveryCodeNotify,
|
|
10
|
+
buildCodexNotifyCmd,
|
|
11
|
+
buildAcodeNotifyCmd,
|
|
12
|
+
buildEveryCodeNotifyCmd,
|
|
13
|
+
} = require("../lib/codex-config");
|
|
14
|
+
const {
|
|
15
|
+
removeClaudeHook,
|
|
16
|
+
removeClaudeUsageHooks,
|
|
17
|
+
buildClaudeHookCommand,
|
|
18
|
+
buildHookCommand,
|
|
19
|
+
} = require("../lib/claude-config");
|
|
20
|
+
const {
|
|
21
|
+
resolveGeminiConfigDir,
|
|
22
|
+
resolveGeminiSettingsPath,
|
|
23
|
+
buildGeminiHookCommand,
|
|
24
|
+
removeGeminiHook,
|
|
25
|
+
} = require("../lib/gemini-config");
|
|
26
|
+
const { resolveOpencodeConfigDir, removeOpencodePlugin } = require("../lib/opencode-config");
|
|
27
|
+
const { removeOpenclawHookConfig } = require("../lib/openclaw-hook");
|
|
28
|
+
const { removeOpenclawSessionPluginConfig } = require("../lib/openclaw-session-plugin");
|
|
29
|
+
const { removeGrokHook } = require("../lib/grok-hook");
|
|
30
|
+
const { removeOmpHook } = require("../lib/omp-hook");
|
|
31
|
+
const { resolveTrackerPaths } = require("../lib/tracker-paths");
|
|
32
|
+
const { deleteWindowsScheduledTask, TASK_NAME } = require("../lib/scheduled-task");
|
|
33
|
+
|
|
34
|
+
async function cmdUninstall(argv) {
|
|
35
|
+
const opts = parseArgs(argv);
|
|
36
|
+
const home = os.homedir();
|
|
37
|
+
const { trackerDir, binDir } = await resolveTrackerPaths({ home });
|
|
38
|
+
const codexHome = process.env.CODEX_HOME || path.join(home, ".codex");
|
|
39
|
+
const codexConfigPath = path.join(codexHome, "config.toml");
|
|
40
|
+
const acodeHome = process.env.TOKENUSAGE_ACODE_HOME || path.join(home, ".acode");
|
|
41
|
+
const acodeConfigPath = path.join(acodeHome, "config.toml");
|
|
42
|
+
const codeHome = process.env.CODE_HOME || path.join(home, ".code");
|
|
43
|
+
const codeConfigPath = path.join(codeHome, "config.toml");
|
|
44
|
+
const claudeSettingsPath = path.join(home, ".claude", "settings.json");
|
|
45
|
+
const codebuddyDir = process.env.CODEBUDDY_HOME || path.join(home, ".codebuddy");
|
|
46
|
+
const codebuddySettingsPath = path.join(codebuddyDir, "settings.json");
|
|
47
|
+
const workbuddyDir = process.env.WORKBUDDY_HOME || path.join(home, ".workbuddy");
|
|
48
|
+
const workbuddySettingsPath = path.join(workbuddyDir, "settings.json");
|
|
49
|
+
// WorkBuddy AI — international build, sibling home (~/.workbuddy-ai).
|
|
50
|
+
const workbuddyAiDir = expandHome(process.env.WORKBUDDY_AI_HOME, home) || path.join(home, ".workbuddy-ai");
|
|
51
|
+
const workbuddyAiSettingsPath = path.join(workbuddyAiDir, "settings.json");
|
|
52
|
+
const geminiConfigDir = resolveGeminiConfigDir({ home, env: process.env });
|
|
53
|
+
const geminiSettingsPath = resolveGeminiSettingsPath({ configDir: geminiConfigDir });
|
|
54
|
+
const opencodeConfigDir = resolveOpencodeConfigDir({ home, env: process.env });
|
|
55
|
+
const notifyPath = path.join(binDir, "notify.cjs");
|
|
56
|
+
const notifyOriginalPath = path.join(trackerDir, "codex_notify_original.json");
|
|
57
|
+
const acodeNotifyOriginalPath = path.join(trackerDir, "acode_notify_original.json");
|
|
58
|
+
const codeNotifyOriginalPath = path.join(trackerDir, "code_notify_original.json");
|
|
59
|
+
const codexNotifyCmd = buildCodexNotifyCmd(notifyPath);
|
|
60
|
+
const acodeNotifyCmd = buildAcodeNotifyCmd(notifyPath);
|
|
61
|
+
const codeNotifyCmd = buildEveryCodeNotifyCmd(notifyPath);
|
|
62
|
+
const claudeHookCommand = buildClaudeHookCommand(notifyPath);
|
|
63
|
+
const codebuddyHookCommand = buildHookCommand(notifyPath, "codebuddy");
|
|
64
|
+
const workbuddyHookCommand = buildHookCommand(notifyPath, "workbuddy");
|
|
65
|
+
const workbuddyAiHookCommand = buildHookCommand(notifyPath, "workbuddy-ai");
|
|
66
|
+
const geminiHookCommand = buildGeminiHookCommand(notifyPath);
|
|
67
|
+
|
|
68
|
+
const codexConfigExists = await isFile(codexConfigPath);
|
|
69
|
+
const acodeConfigExists = await isFile(acodeConfigPath);
|
|
70
|
+
const codeConfigExists = await isFile(codeConfigPath);
|
|
71
|
+
const claudeConfigExists = await isFile(claudeSettingsPath);
|
|
72
|
+
const codebuddyConfigExists = await isFile(codebuddySettingsPath);
|
|
73
|
+
const workbuddyConfigExists = await isFile(workbuddySettingsPath);
|
|
74
|
+
const workbuddyAiConfigExists = await isFile(workbuddyAiSettingsPath);
|
|
75
|
+
const geminiConfigExists = await isDir(geminiConfigDir);
|
|
76
|
+
const opencodeConfigExists = await isDir(opencodeConfigDir);
|
|
77
|
+
const codexRestore = codexConfigExists
|
|
78
|
+
? await restoreCodexNotify({
|
|
79
|
+
codexConfigPath,
|
|
80
|
+
notifyOriginalPath,
|
|
81
|
+
notifyCmd: codexNotifyCmd,
|
|
82
|
+
})
|
|
83
|
+
: { restored: false, skippedReason: "config-missing" };
|
|
84
|
+
const acodeRestore = acodeConfigExists
|
|
85
|
+
? await restoreAcodeNotify({
|
|
86
|
+
acodeConfigPath,
|
|
87
|
+
notifyOriginalPath: acodeNotifyOriginalPath,
|
|
88
|
+
notifyCmd: acodeNotifyCmd,
|
|
89
|
+
})
|
|
90
|
+
: { restored: false, skippedReason: "config-missing" };
|
|
91
|
+
const codeRestore = codeConfigExists
|
|
92
|
+
? await restoreEveryCodeNotify({
|
|
93
|
+
codeConfigPath,
|
|
94
|
+
notifyOriginalPath: codeNotifyOriginalPath,
|
|
95
|
+
notifyCmd: codeNotifyCmd,
|
|
96
|
+
})
|
|
97
|
+
: { restored: false, skippedReason: "config-missing" };
|
|
98
|
+
const claudeRemove = claudeConfigExists
|
|
99
|
+
? await removeClaudeUsageHooks({
|
|
100
|
+
settingsPath: claudeSettingsPath,
|
|
101
|
+
hookCommand: claudeHookCommand,
|
|
102
|
+
})
|
|
103
|
+
: { removed: false, skippedReason: "config-missing" };
|
|
104
|
+
const codebuddyRemove = codebuddyConfigExists
|
|
105
|
+
? await removeClaudeHook({
|
|
106
|
+
settingsPath: codebuddySettingsPath,
|
|
107
|
+
hookCommand: codebuddyHookCommand,
|
|
108
|
+
})
|
|
109
|
+
: { removed: false, skippedReason: "config-missing" };
|
|
110
|
+
const workbuddyRemove = workbuddyConfigExists
|
|
111
|
+
? await removeClaudeHook({
|
|
112
|
+
settingsPath: workbuddySettingsPath,
|
|
113
|
+
hookCommand: workbuddyHookCommand,
|
|
114
|
+
})
|
|
115
|
+
: { removed: false, skippedReason: "config-missing" };
|
|
116
|
+
const workbuddyAiRemove = workbuddyAiConfigExists
|
|
117
|
+
? await removeClaudeHook({
|
|
118
|
+
settingsPath: workbuddyAiSettingsPath,
|
|
119
|
+
hookCommand: workbuddyAiHookCommand,
|
|
120
|
+
})
|
|
121
|
+
: { removed: false, skippedReason: "config-missing" };
|
|
122
|
+
const geminiRemove = geminiConfigExists
|
|
123
|
+
? await removeGeminiHook({ settingsPath: geminiSettingsPath, hookCommand: geminiHookCommand })
|
|
124
|
+
: { removed: false, skippedReason: "config-missing" };
|
|
125
|
+
const opencodeRemove = opencodeConfigExists
|
|
126
|
+
? await removeOpencodePlugin({ configDir: opencodeConfigDir })
|
|
127
|
+
: { removed: false, skippedReason: "config-missing" };
|
|
128
|
+
const openclawSessionPluginRemove = await removeOpenclawSessionPluginConfig({
|
|
129
|
+
home,
|
|
130
|
+
trackerDir,
|
|
131
|
+
env: process.env,
|
|
132
|
+
});
|
|
133
|
+
const openclawHookRemove = await removeOpenclawHookConfig({ home, trackerDir, env: process.env });
|
|
134
|
+
const grokHookRemove = await removeGrokHook({ home, trackerDir, env: process.env });
|
|
135
|
+
const ompHookRemove = await removeOmpHook({ home, trackerDir, env: process.env });
|
|
136
|
+
|
|
137
|
+
// Remove installed notify handler.
|
|
138
|
+
await fs.unlink(notifyPath).catch(() => {});
|
|
139
|
+
|
|
140
|
+
// Remove the hidden-runner wrapper and the hourly scheduled task init
|
|
141
|
+
// registered (0.2.0). Both best-effort: a machine that never registered
|
|
142
|
+
// them simply reports no change.
|
|
143
|
+
await fs.unlink(path.join(binDir, "run-sync-hidden.vbs")).catch(() => {});
|
|
144
|
+
const taskDelete = deleteWindowsScheduledTask();
|
|
145
|
+
|
|
146
|
+
// Remove local app runtime (installed by init for notify-driven sync).
|
|
147
|
+
await fs.rm(path.join(trackerDir, "app"), { recursive: true, force: true }).catch(() => {});
|
|
148
|
+
|
|
149
|
+
// Deliberately NOT removed by --purge: the machine-identity seed lets a
|
|
150
|
+
// reinstall reuse the same cloud device row instead of double-counting the
|
|
151
|
+
// replayed history under a new device (issue #176).
|
|
152
|
+
const machineIdSeedPath = path.join(home, ".config", "tokenusage", "machine-id");
|
|
153
|
+
let machineIdSeedKept = false;
|
|
154
|
+
if (opts.purge) {
|
|
155
|
+
await fs.rm(path.join(home, ".tokenusage"), { recursive: true, force: true }).catch(() => {});
|
|
156
|
+
machineIdSeedKept = await fs.access(machineIdSeedPath).then(
|
|
157
|
+
() => true,
|
|
158
|
+
() => false,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
process.stdout.write(
|
|
163
|
+
[
|
|
164
|
+
"Uninstalled:",
|
|
165
|
+
codexConfigExists
|
|
166
|
+
? codexRestore?.restored
|
|
167
|
+
? `- Codex notify restored: ${codexConfigPath}`
|
|
168
|
+
: codexRestore?.skippedReason === "no-backup-not-installed"
|
|
169
|
+
? "- Codex notify: skipped (no backup; not installed)"
|
|
170
|
+
: codexRestore?.skippedReason === "current-not-managed"
|
|
171
|
+
? "- Codex notify: skipped (current notify is not managed by tokenusage)"
|
|
172
|
+
: "- Codex notify: no change"
|
|
173
|
+
: "- Codex notify: skipped (config.toml not found)",
|
|
174
|
+
acodeConfigExists
|
|
175
|
+
? acodeRestore?.restored
|
|
176
|
+
? `- AStudio notify restored: ${acodeConfigPath}`
|
|
177
|
+
: acodeRestore?.skippedReason === "no-backup-not-installed"
|
|
178
|
+
? "- AStudio notify: skipped (no backup; not installed)"
|
|
179
|
+
: acodeRestore?.skippedReason === "current-not-managed"
|
|
180
|
+
? "- AStudio notify: skipped (current notify is not managed by tokenusage)"
|
|
181
|
+
: "- AStudio notify: no change"
|
|
182
|
+
: "- AStudio notify: skipped (config.toml not found)",
|
|
183
|
+
codeConfigExists
|
|
184
|
+
? codeRestore?.restored
|
|
185
|
+
? `- Every Code notify restored: ${codeConfigPath}`
|
|
186
|
+
: codeRestore?.skippedReason === "no-backup-not-installed"
|
|
187
|
+
? "- Every Code notify: skipped (no backup; not installed)"
|
|
188
|
+
: codeRestore?.skippedReason === "current-not-managed"
|
|
189
|
+
? "- Every Code notify: skipped (current notify is not managed by tokenusage)"
|
|
190
|
+
: "- Every Code notify: no change"
|
|
191
|
+
: "- Every Code notify: skipped (config.toml not found)",
|
|
192
|
+
claudeConfigExists
|
|
193
|
+
? claudeRemove?.removed
|
|
194
|
+
? `- Claude hooks removed: ${claudeSettingsPath}`
|
|
195
|
+
: claudeRemove?.skippedReason === "hook-missing"
|
|
196
|
+
? "- Claude hooks: no change"
|
|
197
|
+
: "- Claude hooks: skipped"
|
|
198
|
+
: "- Claude hooks: skipped (settings.json not found)",
|
|
199
|
+
codebuddyConfigExists
|
|
200
|
+
? codebuddyRemove?.removed
|
|
201
|
+
? `- CodeBuddy hooks removed: ${codebuddySettingsPath}`
|
|
202
|
+
: codebuddyRemove?.skippedReason === "hook-missing"
|
|
203
|
+
? "- CodeBuddy hooks: no change"
|
|
204
|
+
: "- CodeBuddy hooks: skipped"
|
|
205
|
+
: "- CodeBuddy hooks: skipped (settings.json not found)",
|
|
206
|
+
workbuddyConfigExists
|
|
207
|
+
? workbuddyRemove?.removed
|
|
208
|
+
? `- WorkBuddy hooks removed: ${workbuddySettingsPath}`
|
|
209
|
+
: workbuddyRemove?.skippedReason === "hook-missing"
|
|
210
|
+
? "- WorkBuddy hooks: no change"
|
|
211
|
+
: "- WorkBuddy hooks: skipped"
|
|
212
|
+
: "- WorkBuddy hooks: skipped (settings.json not found)",
|
|
213
|
+
workbuddyAiConfigExists
|
|
214
|
+
? workbuddyAiRemove?.removed
|
|
215
|
+
? `- WorkBuddy AI hooks removed: ${workbuddyAiSettingsPath}`
|
|
216
|
+
: workbuddyAiRemove?.skippedReason === "hook-missing"
|
|
217
|
+
? "- WorkBuddy AI hooks: no change"
|
|
218
|
+
: "- WorkBuddy AI hooks: skipped"
|
|
219
|
+
: "- WorkBuddy AI hooks: skipped (settings.json not found)",
|
|
220
|
+
geminiConfigExists
|
|
221
|
+
? geminiRemove?.removed
|
|
222
|
+
? `- Gemini hooks removed: ${geminiSettingsPath}`
|
|
223
|
+
: geminiRemove?.skippedReason === "hook-missing"
|
|
224
|
+
? "- Gemini hooks: no change"
|
|
225
|
+
: "- Gemini hooks: skipped"
|
|
226
|
+
: `- Gemini hooks: skipped (${geminiConfigDir} not found)`,
|
|
227
|
+
opencodeConfigExists
|
|
228
|
+
? opencodeRemove?.removed
|
|
229
|
+
? `- Opencode plugin removed: ${opencodeConfigDir}`
|
|
230
|
+
: opencodeRemove?.skippedReason === "plugin-missing"
|
|
231
|
+
? "- Opencode plugin: no change"
|
|
232
|
+
: opencodeRemove?.skippedReason === "unexpected-content"
|
|
233
|
+
? "- Opencode plugin: skipped (unexpected content)"
|
|
234
|
+
: "- Opencode plugin: skipped"
|
|
235
|
+
: `- Opencode plugin: skipped (${opencodeConfigDir} not found)`,
|
|
236
|
+
openclawSessionPluginRemove?.removed
|
|
237
|
+
? `- OpenClaw session plugin removed: ${openclawSessionPluginRemove.openclawConfigPath}`
|
|
238
|
+
: openclawSessionPluginRemove?.skippedReason === "openclaw-config-missing"
|
|
239
|
+
? "- OpenClaw session plugin: skipped (openclaw config not found)"
|
|
240
|
+
: "- OpenClaw session plugin: no change",
|
|
241
|
+
openclawHookRemove?.removed
|
|
242
|
+
? `- OpenClaw hook (legacy) removed: ${openclawHookRemove.openclawConfigPath}`
|
|
243
|
+
: openclawHookRemove?.skippedReason === "openclaw-config-missing"
|
|
244
|
+
? "- OpenClaw hook (legacy): skipped (openclaw config not found)"
|
|
245
|
+
: "- OpenClaw hook (legacy): no change",
|
|
246
|
+
grokHookRemove?.removed
|
|
247
|
+
? `- Grok Build hook removed: ${grokHookRemove.hookPath}`
|
|
248
|
+
: "- Grok Build hook: no change",
|
|
249
|
+
formatOmpHookRemoveLine(ompHookRemove),
|
|
250
|
+
taskDelete.deleted
|
|
251
|
+
? `- Scheduled task deleted: ${TASK_NAME}`
|
|
252
|
+
: "- Scheduled task: none",
|
|
253
|
+
opts.purge ? `- Purged: ${path.join(home, ".tokenusage")}` : "- Purge: skipped (use --purge)",
|
|
254
|
+
...(machineIdSeedKept
|
|
255
|
+
? [`- Kept: ${machineIdSeedPath} (cloud device identity — a reinstall reuses the same device; delete it to fully reset)`]
|
|
256
|
+
: []),
|
|
257
|
+
"",
|
|
258
|
+
].join("\n"),
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function formatOmpHookRemoveLine(ompHookRemove) {
|
|
263
|
+
if (ompHookRemove?.removed) {
|
|
264
|
+
return `- oh-my-pi notify extension removed: ${ompHookRemove.extensionPath}`;
|
|
265
|
+
}
|
|
266
|
+
const reason = ompHookRemove?.skippedReason;
|
|
267
|
+
const residualPath = ompHookRemove?.stagedPath || ompHookRemove?.extensionPath;
|
|
268
|
+
const residual = residualPath
|
|
269
|
+
? ` (left in place: ${residualPath})`
|
|
270
|
+
: "";
|
|
271
|
+
if (reason === "unmanaged") {
|
|
272
|
+
return `- oh-my-pi notify extension: skipped (unmanaged file)${residual}`;
|
|
273
|
+
}
|
|
274
|
+
if (reason === "unlink-failed") {
|
|
275
|
+
const detail = ompHookRemove?.error ? `: ${ompHookRemove.error}` : "";
|
|
276
|
+
return `- oh-my-pi notify extension: failed to remove${detail}${residual}`;
|
|
277
|
+
}
|
|
278
|
+
if (reason === "extension-read-failed") {
|
|
279
|
+
const detail = ompHookRemove?.error ? `: ${ompHookRemove.error}` : "";
|
|
280
|
+
return `- oh-my-pi notify extension: failed to read${detail}${residual}`;
|
|
281
|
+
}
|
|
282
|
+
if (reason === "identity-changed") {
|
|
283
|
+
return `- oh-my-pi notify extension: skipped (file changed during uninstall)${residual}`;
|
|
284
|
+
}
|
|
285
|
+
if (reason === "omp-agent-dir-unresolved") {
|
|
286
|
+
return "- oh-my-pi notify extension: skipped (omp agent dir unresolved)";
|
|
287
|
+
}
|
|
288
|
+
if (reason === "missing") {
|
|
289
|
+
return "- oh-my-pi notify extension: no change";
|
|
290
|
+
}
|
|
291
|
+
return "- oh-my-pi notify extension: no change";
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function parseArgs(argv) {
|
|
295
|
+
const out = { purge: false };
|
|
296
|
+
for (let i = 0; i < argv.length; i++) {
|
|
297
|
+
const a = argv[i];
|
|
298
|
+
if (a === "--purge") out.purge = true;
|
|
299
|
+
else throw new Error(`Unknown option: ${a}`);
|
|
300
|
+
}
|
|
301
|
+
return out;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
module.exports = { cmdUninstall, formatOmpHookRemoveLine };
|
|
305
|
+
|
|
306
|
+
async function isFile(p) {
|
|
307
|
+
try {
|
|
308
|
+
const st = await fs.stat(p);
|
|
309
|
+
return st.isFile();
|
|
310
|
+
} catch (_e) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async function isDir(p) {
|
|
316
|
+
try {
|
|
317
|
+
const st = await fs.stat(p);
|
|
318
|
+
return st.isDirectory();
|
|
319
|
+
} catch (_e) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
}
|