tokenusage-cli 0.1.0 → 0.2.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 (131) hide show
  1. package/CHANGELOG.md +39 -19
  2. package/LICENSE +22 -22
  3. package/README.md +94 -94
  4. package/THIRD_PARTY_NOTICES.md +140 -140
  5. package/bin/tokenusage.js +69 -69
  6. package/package.json +59 -59
  7. package/src/cli.js +146 -134
  8. package/src/commands/device-login.js +205 -205
  9. package/src/commands/diagnostics.js +38 -38
  10. package/src/commands/doctor.js +110 -110
  11. package/src/commands/init.js +2484 -2436
  12. package/src/commands/pause.js +77 -0
  13. package/src/commands/sessions.js +29 -29
  14. package/src/commands/status.js +1758 -1747
  15. package/src/commands/sync.js +8048 -7934
  16. package/src/commands/uninstall.js +322 -312
  17. package/src/lib/account-usage-dedup.js +267 -267
  18. package/src/lib/antigravity-paths.js +48 -48
  19. package/src/lib/ark-agent-plan-limits.js +438 -438
  20. package/src/lib/ark-coding-plan-limits.js +537 -537
  21. package/src/lib/async-queue-reader.js +138 -138
  22. package/src/lib/atomic-json.js +27 -27
  23. package/src/lib/bearer-token.js +11 -11
  24. package/src/lib/categorizer-utils.js +232 -232
  25. package/src/lib/claude-categorizer.js +1343 -1343
  26. package/src/lib/claude-config.js +279 -279
  27. package/src/lib/claude-user-identity.js +56 -56
  28. package/src/lib/cli-ui.js +179 -179
  29. package/src/lib/cloud-account.js +541 -541
  30. package/src/lib/cloud-device-token.js +141 -141
  31. package/src/lib/cloud-sync-prefs.js +14 -14
  32. package/src/lib/cloud-usage-reset.js +115 -115
  33. package/src/lib/codex-config.js +595 -595
  34. package/src/lib/codex-context-breakdown.js +806 -806
  35. package/src/lib/codex-model-attribution.js +128 -128
  36. package/src/lib/codex-rollout-parser.js +1471 -1471
  37. package/src/lib/codex-service-tier.js +49 -49
  38. package/src/lib/codex-token-refresh.js +140 -140
  39. package/src/lib/codex-token-usage.js +195 -195
  40. package/src/lib/codex-usage-record.js +195 -195
  41. package/src/lib/collection-pause.js +77 -0
  42. package/src/lib/command-runner.js +313 -313
  43. package/src/lib/commandcode-limits.js +317 -317
  44. package/src/lib/context-health.js +124 -124
  45. package/src/lib/cursor-config.js +605 -605
  46. package/src/lib/cursor-store.js +1918 -1918
  47. package/src/lib/debug-flags.js +7 -7
  48. package/src/lib/devin-limits.js +249 -249
  49. package/src/lib/devin-usage.js +212 -212
  50. package/src/lib/diagnostics.js +383 -383
  51. package/src/lib/doctor.js +385 -385
  52. package/src/lib/dumate.js +95 -95
  53. package/src/lib/fs.js +455 -455
  54. package/src/lib/function-url.js +14 -14
  55. package/src/lib/gemini-config.js +291 -291
  56. package/src/lib/git-outcomes.js +243 -243
  57. package/src/lib/grok-context-breakdown.js +890 -890
  58. package/src/lib/grok-hook.js +360 -360
  59. package/src/lib/grok-limits.js +865 -865
  60. package/src/lib/grok-usage.js +98 -98
  61. package/src/lib/heatmap-compact.js +114 -114
  62. package/src/lib/ingest-sanitize.js +41 -41
  63. package/src/lib/init-flow.js +42 -42
  64. package/src/lib/install-resolver.js +170 -170
  65. package/src/lib/jsonl-lines.js +134 -134
  66. package/src/lib/kimi-model-repair.js +173 -173
  67. package/src/lib/kimi-profile.js +61 -61
  68. package/src/lib/kimi-session.js +216 -216
  69. package/src/lib/local-api.js +3588 -3588
  70. package/src/lib/machine-id.js +238 -238
  71. package/src/lib/multi-install-parser.js +113 -113
  72. package/src/lib/notify-command.js +38 -38
  73. package/src/lib/omp-hook.js +589 -589
  74. package/src/lib/openclaw-cli.js +104 -104
  75. package/src/lib/openclaw-hook.js +375 -375
  76. package/src/lib/openclaw-session-plugin.js +560 -560
  77. package/src/lib/opencode-config.js +121 -121
  78. package/src/lib/opencode-go-limits.js +807 -807
  79. package/src/lib/outcomes-engine.js +253 -253
  80. package/src/lib/passive-mode.js +219 -219
  81. package/src/lib/pet-packages.js +722 -722
  82. package/src/lib/pricing/curated-overrides.json +822 -822
  83. package/src/lib/pricing/index.js +379 -379
  84. package/src/lib/pricing/litellm-fetcher.js +172 -172
  85. package/src/lib/pricing/matcher.js +456 -456
  86. package/src/lib/pricing/seed-snapshot.json +1 -1
  87. package/src/lib/progress.js +76 -76
  88. package/src/lib/project-usage-purge.js +117 -117
  89. package/src/lib/prompt.js +24 -24
  90. package/src/lib/provider-status.js +104 -104
  91. package/src/lib/proxy-env.js +489 -489
  92. package/src/lib/proxy-settings.js +163 -163
  93. package/src/lib/qoder-cn-cli-limits.js +119 -119
  94. package/src/lib/qoder-limits.js +880 -880
  95. package/src/lib/quiet-warnings.js +26 -26
  96. package/src/lib/rollout.js +26005 -25966
  97. package/src/lib/runtime-config.js +9 -4
  98. package/src/lib/scan-roots.js +277 -277
  99. package/src/lib/scheduled-task.js +145 -0
  100. package/src/lib/sentry.js +231 -231
  101. package/src/lib/session-analytics.js +2972 -2972
  102. package/src/lib/session-performance.js +237 -237
  103. package/src/lib/session-upload.js +379 -379
  104. package/src/lib/skill-usage.js +267 -267
  105. package/src/lib/skills-manager.js +1591 -1591
  106. package/src/lib/source-metadata.js +48 -48
  107. package/src/lib/sqlite-reader.js +215 -215
  108. package/src/lib/star-cta.js +73 -73
  109. package/src/lib/subscription-manager.js +293 -293
  110. package/src/lib/subscriptions.js +508 -508
  111. package/src/lib/sync-report.js +138 -0
  112. package/src/lib/telemetry.js +193 -193
  113. package/src/lib/tracker-paths.js +16 -16
  114. package/src/lib/trae-cn-config.js +548 -548
  115. package/src/lib/trae-db.js +127 -127
  116. package/src/lib/trae-snapshot.js +230 -230
  117. package/src/lib/trae-sqlite.js +143 -143
  118. package/src/lib/trae-usage.js +121 -121
  119. package/src/lib/upload-queue.js +134 -134
  120. package/src/lib/upload-throttle.js +171 -171
  121. package/src/lib/usage-limits.js +4552 -4552
  122. package/src/lib/wrapped-aggregator.js +236 -236
  123. package/src/lib/wsl-probe.js +281 -281
  124. package/src/lib/zcode-limits.js +1172 -1172
  125. package/src/lib/zcode-reset-credits.js +66 -66
  126. package/test/audit-fixes.test.js +200 -0
  127. package/test/cli-smoke.test.js +53 -53
  128. package/test/collection-controls.test.js +181 -0
  129. package/test/ingest-sanitize.test.js +162 -162
  130. package/test/quiet-warnings.test.js +53 -53
  131. package/test/session-upload.test.js +427 -427
@@ -1,219 +1,219 @@
1
- /**
2
- * Passive-mode detection.
3
- *
4
- * Token Tracker normally collects token usage by installing SessionEnd hooks
5
- * into supported CLIs (Claude Code, Codex CLI, Gemini CLI, …). The hook
6
- * fires `notify.cjs` after each turn → sync runs immediately → data is
7
- * fresh within seconds.
8
- *
9
- * On environments where hook installation fails — WSL with read-only mount,
10
- * UNC paths on Windows, locked `settings.json`, sandboxed processes —
11
- * SessionEnd hooks never fire, but the underlying CLIs *still* write
12
- * session logs (`~/.claude/projects/`, `~/.gemini/sessions/`, etc.). Our
13
- * parsers can read those logs directly without the hook; the only loss is
14
- * "data is fresh within seconds" → it's now "data is fresh after the next
15
- * scheduled `tracker sync`".
16
- *
17
- * This module surfaces that fact: for each hook-driven provider, decide
18
- * whether the local install is in **passive mode** (no hook + log dir
19
- * present). `tracker status` reports it, and the dashboard can show a
20
- * single banner asking the user whether to acknowledge & continue in
21
- * passive mode or attempt re-install (`tracker init`).
22
- *
23
- * Detection is purely best-effort — we never *fail* sync because hooks are
24
- * missing; we just label the source so users / AI agents know latency is
25
- * minutes, not seconds.
26
- */
27
- "use strict";
28
-
29
- const fs = require("node:fs");
30
- const path = require("node:path");
31
- const { expandHome } = require("./scan-roots");
32
-
33
- /**
34
- * @typedef {Object} PassiveProvider
35
- * @property {string} name - canonical provider name
36
- * @property {boolean} hook_expected - whether this provider supports hooks
37
- * @property {boolean} hook_installed - true when the hook is set
38
- * @property {boolean} logs_present - true when the provider's log dir
39
- * exists and contains at least one
40
- * session file we can parse
41
- * @property {boolean} passive - true iff hook_expected &&
42
- * !hook_installed && logs_present
43
- * @property {string|null} hook_failure_reason - if hook_expected and not
44
- * installed, why we think it failed
45
- * (e.g. "settings.json not writable",
46
- * "config dir not found")
47
- */
48
-
49
- function dirHasFile(dir, predicate) {
50
- if (!dir || !fs.existsSync(dir)) return false;
51
- let entries;
52
- try {
53
- entries = fs.readdirSync(dir, { withFileTypes: true });
54
- } catch (_e) {
55
- return false;
56
- }
57
- for (const entry of entries) {
58
- const full = path.join(dir, entry.name);
59
- // Let the predicate accept either a file OR a directory name (so
60
- // "sessions" or "tmp" as a bare subdirectory still counts).
61
- if (!predicate || predicate(full, entry.name, entry.isDirectory())) return true;
62
- if (entry.isDirectory()) {
63
- // Shallow recurse — at most 1 level (covers projects/<name>/*.jsonl)
64
- if (dirHasFile(full, predicate)) return true;
65
- }
66
- }
67
- return false;
68
- }
69
-
70
- function classifyWritableFailure(filePath) {
71
- if (!filePath) return "no path";
72
- try {
73
- fs.accessSync(filePath, fs.constants.W_OK);
74
- return "writable (hook may have been removed externally)";
75
- } catch (e) {
76
- if (e && e.code === "ENOENT") return "settings file missing";
77
- if (e && e.code === "EACCES") return "permission denied";
78
- if (e && e.code === "EROFS") return "read-only filesystem";
79
- return e?.code || "unknown";
80
- }
81
- }
82
-
83
- /**
84
- * Detect passive mode for each hook-driven provider.
85
- *
86
- * @param {Object} opts
87
- * @param {string} opts.home - user home directory
88
- * @param {Object} opts.hookStatus - per-provider hook-installed booleans
89
- * (already collected by status.js); shape: { claude, gemini, codex,
90
- * every_code, opencode, openclaw, codebuddy, workbuddy, grok }
91
- * @returns {PassiveProvider[]}
92
- */
93
- function detectPassiveProviders({ home, hookStatus, env = process.env }) {
94
- const out = [];
95
-
96
- // Claude Code — logs at ~/.claude/projects/<name>/*.jsonl
97
- out.push(buildEntry({
98
- name: "claude",
99
- hookExpected: true,
100
- hookInstalled: Boolean(hookStatus?.claude),
101
- logsDir: path.join(home, ".claude", "projects"),
102
- logsPredicate: (full) => full.endsWith(".jsonl"),
103
- settingsPath: path.join(home, ".claude", "settings.json"),
104
- }));
105
-
106
- // Gemini CLI — logs at ~/.gemini/tmp/<session-id>/logs.json
107
- // (path varies by version; presence of ~/.gemini/sessions or
108
- // ~/.gemini/tmp is enough to call it "active")
109
- out.push(buildEntry({
110
- name: "gemini",
111
- hookExpected: true,
112
- hookInstalled: Boolean(hookStatus?.gemini),
113
- logsDir: path.join(home, ".gemini"),
114
- logsPredicate: (_full, name, isDir) =>
115
- (isDir && (name === "tmp" || name === "sessions")) || name === "logs.json",
116
- settingsPath: path.join(home, ".gemini", "settings.json"),
117
- }));
118
-
119
- // Codex CLI — logs at ~/.codex/sessions/
120
- // Match either a "sessions" subdir (even if empty — the CLI created it)
121
- // or any *.jsonl session file.
122
- out.push(buildEntry({
123
- name: "codex",
124
- hookExpected: true,
125
- hookInstalled: Boolean(hookStatus?.codex_notify ?? hookStatus?.codex),
126
- logsDir: path.join(home, ".codex"),
127
- logsPredicate: (_full, name, isDir) =>
128
- (isDir && name === "sessions") || (!isDir && name.endsWith(".jsonl")),
129
- settingsPath: path.join(home, ".codex", "config.toml"),
130
- }));
131
-
132
- const acodeHome = env.TOKENUSAGE_ACODE_HOME || path.join(home, ".acode");
133
- out.push(buildEntry({
134
- name: "acode",
135
- hookExpected: true,
136
- hookInstalled: Boolean(hookStatus?.acode_notify ?? hookStatus?.acode),
137
- logsDir: acodeHome,
138
- logsPredicate: (_full, name, isDir) =>
139
- (isDir && (name === "sessions" || name === "archived_sessions")) ||
140
- (!isDir && name.endsWith(".jsonl")),
141
- settingsPath: path.join(acodeHome, "config.toml"),
142
- }));
143
-
144
- // Every Code — same shape as Codex, different home
145
- out.push(buildEntry({
146
- name: "every_code",
147
- hookExpected: true,
148
- hookInstalled: Boolean(hookStatus?.every_code_notify ?? hookStatus?.every_code),
149
- logsDir: path.join(home, ".code"),
150
- logsPredicate: (_full, name, isDir) =>
151
- (isDir && name === "sessions") || (!isDir && name.endsWith(".jsonl")),
152
- settingsPath: path.join(home, ".code", "config.toml"),
153
- }));
154
-
155
- // CodeBuddy — Claude-fork; hook in ~/.codebuddy/settings.json
156
- out.push(buildEntry({
157
- name: "codebuddy",
158
- hookExpected: true,
159
- hookInstalled: Boolean(hookStatus?.codebuddy),
160
- logsDir: path.join(home, ".codebuddy"),
161
- logsPredicate: (_full, name) => name === "projects" || name.endsWith(".jsonl"),
162
- settingsPath: path.join(home, ".codebuddy", "settings.json"),
163
- }));
164
-
165
- // WorkBuddy — sibling Claude-fork; hook in ~/.workbuddy/settings.json
166
- out.push(buildEntry({
167
- name: "workbuddy",
168
- hookExpected: true,
169
- hookInstalled: Boolean(hookStatus?.workbuddy),
170
- logsDir: path.join(home, ".workbuddy"),
171
- logsPredicate: (_full, name) => name === "projects" || name.endsWith(".jsonl"),
172
- settingsPath: path.join(home, ".workbuddy", "settings.json"),
173
- }));
174
-
175
- // WorkBuddy AI — international build; data + hooks in ~/.workbuddy-ai
176
- const workbuddyAiHome = expandHome(env.WORKBUDDY_AI_HOME, home) || path.join(home, ".workbuddy-ai");
177
- out.push(buildEntry({
178
- name: "workbuddy-ai",
179
- hookExpected: true,
180
- hookInstalled: Boolean(hookStatus?.["workbuddy-ai"]),
181
- logsDir: workbuddyAiHome,
182
- logsPredicate: (_full, name) => name === "projects" || name.endsWith(".jsonl"),
183
- settingsPath: path.join(workbuddyAiHome, "settings.json"),
184
- }));
185
-
186
- return out;
187
- }
188
-
189
- function buildEntry({ name, hookExpected, hookInstalled, logsDir, logsPredicate, settingsPath }) {
190
- const logsPresent = dirHasFile(logsDir, logsPredicate);
191
- const passive = hookExpected && !hookInstalled && logsPresent;
192
- let reason = null;
193
- if (hookExpected && !hookInstalled) {
194
- reason = classifyWritableFailure(settingsPath);
195
- }
196
- return {
197
- name,
198
- hook_expected: hookExpected,
199
- hook_installed: hookInstalled,
200
- logs_present: logsPresent,
201
- passive,
202
- hook_failure_reason: reason,
203
- };
204
- }
205
-
206
- /**
207
- * Convenience boolean: is at least one provider in passive mode?
208
- */
209
- function isPassiveModeActive(providers) {
210
- return providers.some((p) => p.passive);
211
- }
212
-
213
- module.exports = {
214
- detectPassiveProviders,
215
- isPassiveModeActive,
216
- // Exposed for unit testing
217
- dirHasFile,
218
- classifyWritableFailure,
219
- };
1
+ /**
2
+ * Passive-mode detection.
3
+ *
4
+ * Token Tracker normally collects token usage by installing SessionEnd hooks
5
+ * into supported CLIs (Claude Code, Codex CLI, Gemini CLI, …). The hook
6
+ * fires `notify.cjs` after each turn → sync runs immediately → data is
7
+ * fresh within seconds.
8
+ *
9
+ * On environments where hook installation fails — WSL with read-only mount,
10
+ * UNC paths on Windows, locked `settings.json`, sandboxed processes —
11
+ * SessionEnd hooks never fire, but the underlying CLIs *still* write
12
+ * session logs (`~/.claude/projects/`, `~/.gemini/sessions/`, etc.). Our
13
+ * parsers can read those logs directly without the hook; the only loss is
14
+ * "data is fresh within seconds" → it's now "data is fresh after the next
15
+ * scheduled `tracker sync`".
16
+ *
17
+ * This module surfaces that fact: for each hook-driven provider, decide
18
+ * whether the local install is in **passive mode** (no hook + log dir
19
+ * present). `tracker status` reports it, and the dashboard can show a
20
+ * single banner asking the user whether to acknowledge & continue in
21
+ * passive mode or attempt re-install (`tracker init`).
22
+ *
23
+ * Detection is purely best-effort — we never *fail* sync because hooks are
24
+ * missing; we just label the source so users / AI agents know latency is
25
+ * minutes, not seconds.
26
+ */
27
+ "use strict";
28
+
29
+ const fs = require("node:fs");
30
+ const path = require("node:path");
31
+ const { expandHome } = require("./scan-roots");
32
+
33
+ /**
34
+ * @typedef {Object} PassiveProvider
35
+ * @property {string} name - canonical provider name
36
+ * @property {boolean} hook_expected - whether this provider supports hooks
37
+ * @property {boolean} hook_installed - true when the hook is set
38
+ * @property {boolean} logs_present - true when the provider's log dir
39
+ * exists and contains at least one
40
+ * session file we can parse
41
+ * @property {boolean} passive - true iff hook_expected &&
42
+ * !hook_installed && logs_present
43
+ * @property {string|null} hook_failure_reason - if hook_expected and not
44
+ * installed, why we think it failed
45
+ * (e.g. "settings.json not writable",
46
+ * "config dir not found")
47
+ */
48
+
49
+ function dirHasFile(dir, predicate) {
50
+ if (!dir || !fs.existsSync(dir)) return false;
51
+ let entries;
52
+ try {
53
+ entries = fs.readdirSync(dir, { withFileTypes: true });
54
+ } catch (_e) {
55
+ return false;
56
+ }
57
+ for (const entry of entries) {
58
+ const full = path.join(dir, entry.name);
59
+ // Let the predicate accept either a file OR a directory name (so
60
+ // "sessions" or "tmp" as a bare subdirectory still counts).
61
+ if (!predicate || predicate(full, entry.name, entry.isDirectory())) return true;
62
+ if (entry.isDirectory()) {
63
+ // Shallow recurse — at most 1 level (covers projects/<name>/*.jsonl)
64
+ if (dirHasFile(full, predicate)) return true;
65
+ }
66
+ }
67
+ return false;
68
+ }
69
+
70
+ function classifyWritableFailure(filePath) {
71
+ if (!filePath) return "no path";
72
+ try {
73
+ fs.accessSync(filePath, fs.constants.W_OK);
74
+ return "writable (hook may have been removed externally)";
75
+ } catch (e) {
76
+ if (e && e.code === "ENOENT") return "settings file missing";
77
+ if (e && e.code === "EACCES") return "permission denied";
78
+ if (e && e.code === "EROFS") return "read-only filesystem";
79
+ return e?.code || "unknown";
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Detect passive mode for each hook-driven provider.
85
+ *
86
+ * @param {Object} opts
87
+ * @param {string} opts.home - user home directory
88
+ * @param {Object} opts.hookStatus - per-provider hook-installed booleans
89
+ * (already collected by status.js); shape: { claude, gemini, codex,
90
+ * every_code, opencode, openclaw, codebuddy, workbuddy, grok }
91
+ * @returns {PassiveProvider[]}
92
+ */
93
+ function detectPassiveProviders({ home, hookStatus, env = process.env }) {
94
+ const out = [];
95
+
96
+ // Claude Code — logs at ~/.claude/projects/<name>/*.jsonl
97
+ out.push(buildEntry({
98
+ name: "claude",
99
+ hookExpected: true,
100
+ hookInstalled: Boolean(hookStatus?.claude),
101
+ logsDir: path.join(home, ".claude", "projects"),
102
+ logsPredicate: (full) => full.endsWith(".jsonl"),
103
+ settingsPath: path.join(home, ".claude", "settings.json"),
104
+ }));
105
+
106
+ // Gemini CLI — logs at ~/.gemini/tmp/<session-id>/logs.json
107
+ // (path varies by version; presence of ~/.gemini/sessions or
108
+ // ~/.gemini/tmp is enough to call it "active")
109
+ out.push(buildEntry({
110
+ name: "gemini",
111
+ hookExpected: true,
112
+ hookInstalled: Boolean(hookStatus?.gemini),
113
+ logsDir: path.join(home, ".gemini"),
114
+ logsPredicate: (_full, name, isDir) =>
115
+ (isDir && (name === "tmp" || name === "sessions")) || name === "logs.json",
116
+ settingsPath: path.join(home, ".gemini", "settings.json"),
117
+ }));
118
+
119
+ // Codex CLI — logs at ~/.codex/sessions/
120
+ // Match either a "sessions" subdir (even if empty — the CLI created it)
121
+ // or any *.jsonl session file.
122
+ out.push(buildEntry({
123
+ name: "codex",
124
+ hookExpected: true,
125
+ hookInstalled: Boolean(hookStatus?.codex_notify ?? hookStatus?.codex),
126
+ logsDir: path.join(home, ".codex"),
127
+ logsPredicate: (_full, name, isDir) =>
128
+ (isDir && name === "sessions") || (!isDir && name.endsWith(".jsonl")),
129
+ settingsPath: path.join(home, ".codex", "config.toml"),
130
+ }));
131
+
132
+ const acodeHome = env.TOKENUSAGE_ACODE_HOME || path.join(home, ".acode");
133
+ out.push(buildEntry({
134
+ name: "acode",
135
+ hookExpected: true,
136
+ hookInstalled: Boolean(hookStatus?.acode_notify ?? hookStatus?.acode),
137
+ logsDir: acodeHome,
138
+ logsPredicate: (_full, name, isDir) =>
139
+ (isDir && (name === "sessions" || name === "archived_sessions")) ||
140
+ (!isDir && name.endsWith(".jsonl")),
141
+ settingsPath: path.join(acodeHome, "config.toml"),
142
+ }));
143
+
144
+ // Every Code — same shape as Codex, different home
145
+ out.push(buildEntry({
146
+ name: "every_code",
147
+ hookExpected: true,
148
+ hookInstalled: Boolean(hookStatus?.every_code_notify ?? hookStatus?.every_code),
149
+ logsDir: path.join(home, ".code"),
150
+ logsPredicate: (_full, name, isDir) =>
151
+ (isDir && name === "sessions") || (!isDir && name.endsWith(".jsonl")),
152
+ settingsPath: path.join(home, ".code", "config.toml"),
153
+ }));
154
+
155
+ // CodeBuddy — Claude-fork; hook in ~/.codebuddy/settings.json
156
+ out.push(buildEntry({
157
+ name: "codebuddy",
158
+ hookExpected: true,
159
+ hookInstalled: Boolean(hookStatus?.codebuddy),
160
+ logsDir: path.join(home, ".codebuddy"),
161
+ logsPredicate: (_full, name) => name === "projects" || name.endsWith(".jsonl"),
162
+ settingsPath: path.join(home, ".codebuddy", "settings.json"),
163
+ }));
164
+
165
+ // WorkBuddy — sibling Claude-fork; hook in ~/.workbuddy/settings.json
166
+ out.push(buildEntry({
167
+ name: "workbuddy",
168
+ hookExpected: true,
169
+ hookInstalled: Boolean(hookStatus?.workbuddy),
170
+ logsDir: path.join(home, ".workbuddy"),
171
+ logsPredicate: (_full, name) => name === "projects" || name.endsWith(".jsonl"),
172
+ settingsPath: path.join(home, ".workbuddy", "settings.json"),
173
+ }));
174
+
175
+ // WorkBuddy AI — international build; data + hooks in ~/.workbuddy-ai
176
+ const workbuddyAiHome = expandHome(env.WORKBUDDY_AI_HOME, home) || path.join(home, ".workbuddy-ai");
177
+ out.push(buildEntry({
178
+ name: "workbuddy-ai",
179
+ hookExpected: true,
180
+ hookInstalled: Boolean(hookStatus?.["workbuddy-ai"]),
181
+ logsDir: workbuddyAiHome,
182
+ logsPredicate: (_full, name) => name === "projects" || name.endsWith(".jsonl"),
183
+ settingsPath: path.join(workbuddyAiHome, "settings.json"),
184
+ }));
185
+
186
+ return out;
187
+ }
188
+
189
+ function buildEntry({ name, hookExpected, hookInstalled, logsDir, logsPredicate, settingsPath }) {
190
+ const logsPresent = dirHasFile(logsDir, logsPredicate);
191
+ const passive = hookExpected && !hookInstalled && logsPresent;
192
+ let reason = null;
193
+ if (hookExpected && !hookInstalled) {
194
+ reason = classifyWritableFailure(settingsPath);
195
+ }
196
+ return {
197
+ name,
198
+ hook_expected: hookExpected,
199
+ hook_installed: hookInstalled,
200
+ logs_present: logsPresent,
201
+ passive,
202
+ hook_failure_reason: reason,
203
+ };
204
+ }
205
+
206
+ /**
207
+ * Convenience boolean: is at least one provider in passive mode?
208
+ */
209
+ function isPassiveModeActive(providers) {
210
+ return providers.some((p) => p.passive);
211
+ }
212
+
213
+ module.exports = {
214
+ detectPassiveProviders,
215
+ isPassiveModeActive,
216
+ // Exposed for unit testing
217
+ dirHasFile,
218
+ classifyWritableFailure,
219
+ };