limitcast 0.15.0 → 0.17.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.
- package/LICENSE +21 -95
- package/README.md +61 -48
- package/bin/limitcast.mjs +143 -212
- package/package.json +2 -2
- package/src/grok.mjs +245 -6
- package/src/guard.mjs +10 -2
- package/src/insights.mjs +127 -0
- package/src/install.mjs +6 -14
- package/src/license.mjs +2 -1
- package/src/notify.mjs +1 -2
- package/src/onboarding.mjs +46 -0
- package/src/pilot.mjs +92 -0
- package/src/results.mjs +31 -15
- package/src/trim.mjs +9 -4
- package/src/value.mjs +37 -11
package/bin/limitcast.mjs
CHANGED
|
@@ -30,6 +30,8 @@ import {
|
|
|
30
30
|
getGrokBudget,
|
|
31
31
|
grokConfigPath,
|
|
32
32
|
grokPresent,
|
|
33
|
+
grokQuotaDue,
|
|
34
|
+
grokQuotaEnabled,
|
|
33
35
|
grokSamples,
|
|
34
36
|
grokServers,
|
|
35
37
|
grokSessionLine,
|
|
@@ -37,19 +39,23 @@ import {
|
|
|
37
39
|
grokStartup,
|
|
38
40
|
grokTrimReport,
|
|
39
41
|
grokUsedServers,
|
|
42
|
+
readGrokQuota,
|
|
43
|
+
refreshGrokQuota,
|
|
40
44
|
setGrokBudget,
|
|
45
|
+
setGrokQuota,
|
|
46
|
+
touchGrokQuota,
|
|
41
47
|
undoGrokTrim,
|
|
42
48
|
} from '../src/grok.mjs';
|
|
43
49
|
import { runGuard } from '../src/guard.mjs';
|
|
44
50
|
import { accountForecasts, bindingLine, compactHint, headroom, lastCall, lastCallTokens } from '../src/hints.mjs';
|
|
45
51
|
import { htmlPage } from '../src/html.mjs';
|
|
52
|
+
import { insightsReport, insightsShare, periodInsights } from '../src/insights.mjs';
|
|
46
53
|
import { doctor, install, installedFeatures, readSettings, settingsPath, uninstall } from '../src/install.mjs';
|
|
47
|
-
import { activate, currentLicense, isPro, startTrial, trialStatus, UPGRADE_URL } from '../src/license.mjs';
|
|
48
54
|
import { memoryCheck, memoryDir, memoryReport, scanMemory } from '../src/memory.mjs';
|
|
49
55
|
import { buildNotifierApp, loadChannels, notifierApp, notifyChanges, notifyEnabled, send, setChannel, setNotify } from '../src/notify.mjs';
|
|
56
|
+
import { onboardingReport } from '../src/onboarding.mjs';
|
|
50
57
|
import { driftMessage, loadOverhead, recordOverhead, savedPerSession, savedSummary, snapshot } from '../src/overhead.mjs';
|
|
51
58
|
import { advise, getPlan, loadPeaks, PLANS, planPrices, planStats, recordPeaks, setPlan } from '../src/plan.mjs';
|
|
52
|
-
import { activatePolar, deactivatePolar, refreshDue, refreshPolar } from '../src/polar.mjs';
|
|
53
59
|
import { costOf, fmtUsd } from '../src/prices.mjs';
|
|
54
60
|
import { burnReport } from '../src/report.mjs';
|
|
55
61
|
import { loadBlocks, logBlock, resultsReport, resultsShare, resultsStats, weeklyDue, weeklyLine } from '../src/results.mjs';
|
|
@@ -75,27 +81,27 @@ import { forTerminal } from '../src/term.mjs';
|
|
|
75
81
|
import { firstFlag, toolKey, toolNotice } from '../src/toolcheck.mjs';
|
|
76
82
|
import { baseline, contributors, measuredSavings, shareSummary, startupReport, trimReport } from '../src/trim.mjs';
|
|
77
83
|
import { claudeRoot, grokRoot, readUsage } from '../src/usage.mjs';
|
|
78
|
-
import { dailyDue, foldEvents, loadValue, saveValue, scanSessions, valueSection, valueTotals } from '../src/value.mjs';
|
|
84
|
+
import { dailyDue, foldEvents, loadValue, saveValue, scanSessions, valuePeriod, valueSection, valueTotals } from '../src/value.mjs';
|
|
79
85
|
import { attribute, jobsReport, whyReport, whySessions } from '../src/where.mjs';
|
|
80
86
|
|
|
81
87
|
const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
82
88
|
const HELP = `limitcast ${VERSION}: stretch your Claude Code, Codex and Grok plans
|
|
83
89
|
|
|
90
|
+
limitcast onboard read-only setup checks and a guided first useful result
|
|
84
91
|
limitcast install [--guard] wire limitcast into Claude Code (and, with --guard, Codex and Grok); backs up settings
|
|
85
|
-
(without Pro the guard is a preview: it records what it would block, never blocks)
|
|
86
92
|
limitcast uninstall remove it and restore your original status line
|
|
87
93
|
limitcast doctor [--fix] check the setup (--fix: re-install with this Node, e.g. after a Node upgrade)
|
|
88
|
-
limitcast trial Pro free for 7 days on this computer, no card
|
|
89
94
|
limitcast status [--json] used, burn rate, runout time, reset, and today's share of each weekly window
|
|
90
95
|
limitcast trim [--share] tokens every session loads before you type, and how much you never use
|
|
91
96
|
limitcast trim --codex the same for Codex: AGENTS.md size and MCP servers you haven't used
|
|
92
97
|
limitcast trim --grok the same for Grok: system prompt size and MCP servers you haven't used
|
|
98
|
+
limitcast grok-usage [on|off] Grok's weekly % used, from grok.com with the login Grok holds (off by default)
|
|
93
99
|
limitcast memory [dir] check this project's auto-memory: load cap, broken links, unlinked and oversized files
|
|
94
100
|
limitcast results [--days N] limits you reached, how far ahead limitcast warned, what the guard blocked
|
|
95
101
|
[--share] totals only, safe to post
|
|
96
|
-
limitcast license show the license
|
|
102
|
+
limitcast license show the MIT license status
|
|
97
103
|
|
|
98
|
-
|
|
104
|
+
All features are free (MIT License)
|
|
99
105
|
limitcast trim [--days N] [--share] names what to cut and what each costs
|
|
100
106
|
(--share: totals only, no names, safe to post)
|
|
101
107
|
limitcast trim --apply / --undo hide those skills and turn off those MCP servers (backed up, reversible)
|
|
@@ -128,16 +134,14 @@ const HELP = `limitcast ${VERSION}: stretch your Claude Code, Codex and Grok pla
|
|
|
128
134
|
limitcast report [--days N] [--out FILE] tokens by tool, day, project, model and session
|
|
129
135
|
limitcast report --why [--days N] where the new tokens went: subagents, session starts, cache rebuilds, tool results
|
|
130
136
|
limitcast report --jobs [--days N] the scheduled (headless) jobs that spend the most tokens just starting
|
|
131
|
-
(status line
|
|
132
|
-
limitcast activate <license-key> unlock Pro on this computer (online once; then a weekly check, offline up to 30 days)
|
|
133
|
-
limitcast deactivate free this computer's activation to use the key elsewhere
|
|
137
|
+
(status line: points to another account with room, and suggests /compact past ~150k tokens a call)
|
|
134
138
|
|
|
135
139
|
Used by Claude Code, Codex and Grok (set up by install)
|
|
136
140
|
limitcast statusline [-- <cmd...>] record limit readings, then run your status-line command
|
|
137
|
-
limitcast guard PreToolUse hook
|
|
138
|
-
limitcast prompt-check UserPromptSubmit hook: the cold-cache warning
|
|
139
|
-
limitcast subagent-receipt SubagentStop hook: what the subagent cost
|
|
140
|
-
limitcast drift [--hook] SessionStart hook: compare starting context with the last session
|
|
141
|
+
limitcast guard PreToolUse hook
|
|
142
|
+
limitcast prompt-check UserPromptSubmit hook: the cold-cache warning
|
|
143
|
+
limitcast subagent-receipt SubagentStop hook: what the subagent cost
|
|
144
|
+
limitcast drift [--hook] SessionStart hook: compare starting context with the last session
|
|
141
145
|
`;
|
|
142
146
|
|
|
143
147
|
const [cmd, ...args] = process.argv.slice(2);
|
|
@@ -146,26 +150,32 @@ const flag = (/** @type {string} */ name) => {
|
|
|
146
150
|
const i = args.indexOf(name);
|
|
147
151
|
return i >= 0 ? args[i + 1] : undefined;
|
|
148
152
|
};
|
|
149
|
-
const days = () =>
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
153
|
+
const days = () => {
|
|
154
|
+
const n = Number(flag('--days') ?? 7);
|
|
155
|
+
if (!Number.isFinite(n) || n <= 0 || !Number.isFinite(new Date(now - n * 86400_000).getTime())) {
|
|
156
|
+
console.error('--days must be a finite positive number.');
|
|
157
|
+
process.exit(1);
|
|
158
|
+
}
|
|
159
|
+
return Math.max(1, n);
|
|
160
|
+
};
|
|
155
161
|
|
|
156
162
|
if (cmd === 'status') {
|
|
163
|
+
if (grokQuotaEnabled() && grokPresent()) await refreshGrokQuota(now);
|
|
157
164
|
const rows = forecastAll(oneClaudeAccount([...load(now - KEEP_MS), ...(await readCodex(now - KEEP_MS)), ...grokSamples(now)]), now);
|
|
158
165
|
if (args.includes('--json')) console.log(JSON.stringify(rows, null, 2));
|
|
159
166
|
else {
|
|
160
167
|
console.log(rows.length ? table(rows) : 'No data yet. Run `limitcast install`, then send a message in Claude Code, Codex or Grok.');
|
|
161
168
|
const binds = bindingLine(rows, getGrokBudget(), clock);
|
|
162
169
|
if (binds) console.log(`\n${binds}`);
|
|
163
|
-
//
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
170
|
+
// the other Claude accounts limitcast has current readings for (the table shows the latest one).
|
|
171
|
+
for (const a of accountForecasts(load(now - KEEP_MS), now).slice(1))
|
|
172
|
+
console.log(
|
|
173
|
+
`other Claude account (last used ${clock(a.lastSeen)}): ${a.rows.map((f) => `${f.win} ${f.verdict === 'RESET' ? 0 : Math.round(f.pct)}%${f.verdict === 'OK' || f.verdict === 'RESET' ? '' : ` ${f.verdict}`}`).join(' · ')}`,
|
|
174
|
+
);
|
|
175
|
+
const gq = grokQuotaEnabled() ? readGrokQuota() : null;
|
|
176
|
+
if (gq && !gq.ok) console.log(`grok: weekly usage unavailable (${gq.error ?? 'no reading yet'})`);
|
|
177
|
+
else if (gq?.label && gq.label !== 'Weekly')
|
|
178
|
+
console.log(`grok: your plan reports ${gq.label.toLowerCase()} usage (${Math.round(gq.pct ?? 0)}% used), which limitcast does not forecast`);
|
|
169
179
|
const spend = grokSpendLine(now);
|
|
170
180
|
if (spend) console.log(spend);
|
|
171
181
|
else if (existsSync(grokRoot()) && !rows.some((f) => f.src === 'grok'))
|
|
@@ -183,13 +193,11 @@ if (cmd === 'status') {
|
|
|
183
193
|
sid = feed?.session_id;
|
|
184
194
|
record(claudeSamples(feed, now));
|
|
185
195
|
saveFeedShape(feed);
|
|
186
|
-
// Hook-only Pro users never run an interactive command, so the weekly Polar check starts here, detached.
|
|
187
|
-
if (refreshDue(now)) spawn(process.execPath, [fileURLToPath(import.meta.url), 'license'], { detached: true, stdio: 'ignore' }).unref();
|
|
188
196
|
// Readings are kept 8 days; the daily rollup folds what they showed into the long-term value record.
|
|
189
197
|
if (dailyDue(now)) spawn(process.execPath, [fileURLToPath(import.meta.url), 'rollup'], { detached: true, stdio: 'ignore' }).unref();
|
|
190
198
|
const health = healthHint();
|
|
191
199
|
if (health) hints.push(health);
|
|
192
|
-
|
|
200
|
+
{
|
|
193
201
|
const samples = load(now - KEEP_MS);
|
|
194
202
|
if (notifyEnabled()) notifyChanges(forecastAll(oneClaudeAccount([...samples, ...grokSamples(now)], sid), now), clock);
|
|
195
203
|
const room = headroom(samples, sid, now);
|
|
@@ -200,9 +208,15 @@ if (cmd === 'status') {
|
|
|
200
208
|
const ctx = compactHint(lastCallTokens(feed.transcript_path));
|
|
201
209
|
if (ctx) hints.push(ctx);
|
|
202
210
|
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
211
|
+
}
|
|
212
|
+
} catch {
|
|
213
|
+
/* never break the status line */
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
// Grok's weekly % comes from grok.com (opt-in); refresh it in the background so no status line waits on the network.
|
|
217
|
+
if (grokQuotaDue(now)) {
|
|
218
|
+
touchGrokQuota(now);
|
|
219
|
+
spawn(process.execPath, [fileURLToPath(import.meta.url), 'grok-usage', '--refresh'], { detached: true, stdio: 'ignore' }).unref();
|
|
206
220
|
}
|
|
207
221
|
} catch {
|
|
208
222
|
/* never break the status line */
|
|
@@ -230,10 +244,10 @@ if (cmd === 'status') {
|
|
|
230
244
|
if (grokOwn) console.log(grokOwn);
|
|
231
245
|
console.log(`limitcast: ${line}`);
|
|
232
246
|
} else if (cmd === 'guard') {
|
|
233
|
-
//
|
|
247
|
+
// The installed guard protects all users; LIMITCAST_ALLOW=1 remains the explicit override.
|
|
234
248
|
if (process.env.LIMITCAST_ALLOW === '1') process.exit(0);
|
|
235
249
|
try {
|
|
236
|
-
const d = await runGuard(JSON.parse(readStdin()), now, Number(process.env.LIMITCAST_GUARD_MINUTES ?? 30), { preview:
|
|
250
|
+
const d = await runGuard(JSON.parse(readStdin()), now, Number(process.env.LIMITCAST_GUARD_MINUTES ?? 30), { preview: false });
|
|
237
251
|
if (typeof d === 'string') {
|
|
238
252
|
console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: d } }));
|
|
239
253
|
} else if (d && 'notice' in d) {
|
|
@@ -258,14 +272,14 @@ if (cmd === 'status') {
|
|
|
258
272
|
}
|
|
259
273
|
} else if (cmd === 'prompt-check') {
|
|
260
274
|
// UserPromptSubmit hook: hold the first message after the prompt cache expired, once, with its cost.
|
|
261
|
-
//
|
|
275
|
+
// The opt-in hook warns once and fails open on errors.
|
|
262
276
|
try {
|
|
263
277
|
const hook = JSON.parse(readStdin());
|
|
264
278
|
const path = hook?.transcript_path;
|
|
265
279
|
const last = process.env.LIMITCAST_ALLOW !== '1' && typeof path === 'string' && existsSync(path) ? lastCall(path) : null;
|
|
266
280
|
const c = coldCost(hook?.prompt, last, now, { minutes: Number(process.env.LIMITCAST_CACHE_MINUTES ?? 60), calib: loadValue().calib });
|
|
267
281
|
if (c && last && firstWarning(String(hook.session_id), last.t)) {
|
|
268
|
-
const pro =
|
|
282
|
+
const pro = true;
|
|
269
283
|
logBlock({
|
|
270
284
|
t: now,
|
|
271
285
|
kind: 'cold',
|
|
@@ -284,10 +298,10 @@ if (cmd === 'status') {
|
|
|
284
298
|
/* a hook must never stop a prompt by failing */
|
|
285
299
|
}
|
|
286
300
|
} else if (cmd === 'tool-check') {
|
|
287
|
-
// PostToolUse hook (
|
|
301
|
+
// PostToolUse hook (installed with --alerts): tell the user, once per tool per session, about a very large tool
|
|
288
302
|
// result and what to ask for next time. Never reaches the model.
|
|
289
303
|
try {
|
|
290
|
-
|
|
304
|
+
{
|
|
291
305
|
const hook = JSON.parse(readStdin());
|
|
292
306
|
const name = String(hook?.tool_name ?? '');
|
|
293
307
|
const notice = name ? toolNotice(name, hook?.tool_response, loadValue().calib, Number(process.env.LIMITCAST_TOOL_TOKENS) || undefined) : null;
|
|
@@ -317,19 +331,13 @@ if (cmd === 'status') {
|
|
|
317
331
|
read: u.read,
|
|
318
332
|
...(pct === null ? {} : { pct }),
|
|
319
333
|
});
|
|
320
|
-
|
|
334
|
+
console.log(JSON.stringify({ systemMessage: receiptMessage(hook.agent_type, u, pct) }));
|
|
321
335
|
}
|
|
322
336
|
}
|
|
323
337
|
} catch {
|
|
324
338
|
/* a hook must never break the session */
|
|
325
339
|
}
|
|
326
340
|
} else if (cmd === 'plan') {
|
|
327
|
-
if (!isPro()) {
|
|
328
|
-
console.log(
|
|
329
|
-
`\`limitcast plan\` is part of limitcast Pro: ${UPGRADE_URL}\nTry it free for 7 days: limitcast trial. Already bought it? limitcast activate <license-key>`,
|
|
330
|
-
);
|
|
331
|
-
process.exit(2);
|
|
332
|
-
}
|
|
333
341
|
if (args[0] === 'set') {
|
|
334
342
|
const id = args[1];
|
|
335
343
|
if (id !== 'off' && !(id in PLANS)) {
|
|
@@ -368,10 +376,6 @@ if (cmd === 'status') {
|
|
|
368
376
|
console.log(forTerminal(out.join('\n')));
|
|
369
377
|
process.exit(0);
|
|
370
378
|
} else if (cmd === 'subagent-model') {
|
|
371
|
-
if (!isPro()) {
|
|
372
|
-
console.log(`Per-type subagent models are part of limitcast Pro: ${UPGRADE_URL}`);
|
|
373
|
-
process.exit(2);
|
|
374
|
-
}
|
|
375
379
|
const [type, model] = args;
|
|
376
380
|
if (type && (model === undefined || (model !== 'off' && !validModel(model)))) {
|
|
377
381
|
console.log(
|
|
@@ -403,10 +407,6 @@ if (cmd === 'status') {
|
|
|
403
407
|
} else console.log('\nExample: limitcast subagent-model Explore haiku');
|
|
404
408
|
process.exit(0);
|
|
405
409
|
} else if (cmd === 'budget') {
|
|
406
|
-
if (!isPro()) {
|
|
407
|
-
console.log(`Budgets are part of limitcast Pro: ${UPGRADE_URL}`);
|
|
408
|
-
process.exit(2);
|
|
409
|
-
}
|
|
410
410
|
if (args[0] === 'grok') {
|
|
411
411
|
const win = args[1] === '7d' || args[1] === '5h' ? args[1] : '5h';
|
|
412
412
|
const value = args[1] === '7d' || args[1] === '5h' ? args[2] : args[1];
|
|
@@ -467,13 +467,7 @@ if (cmd === 'status') {
|
|
|
467
467
|
} else if (cmd === 'install') {
|
|
468
468
|
const wantGuard = args.includes('--guard');
|
|
469
469
|
const wantAlerts = args.includes('--alerts');
|
|
470
|
-
|
|
471
|
-
console.log(
|
|
472
|
-
`Without Pro the subagent guard runs as a preview: it never blocks, it records what Pro would have blocked (see \`limitcast results\`). Pro: ${UPGRADE_URL}`,
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
if (wantAlerts && !isPro()) console.log(`Alerts and the weekly summary are part of limitcast Pro (${UPGRADE_URL}). Skipping them.`);
|
|
476
|
-
for (const c of install({ guard: wantGuard, alerts: wantAlerts && isPro() })) console.log(`✓ ${c}`);
|
|
470
|
+
for (const c of install({ guard: wantGuard, alerts: wantAlerts })) console.log(`✓ ${c}`);
|
|
477
471
|
console.log('Restart Claude Code, Codex and Grok to load it. Then: limitcast doctor');
|
|
478
472
|
if (wantGuard && grokPresent() && !getGrokBudget())
|
|
479
473
|
console.log('Grok stores spend, not a % used. Set a 5-hour dollar cap so the guard can block: limitcast budget grok <usd>');
|
|
@@ -500,19 +494,40 @@ if (cmd === 'status') {
|
|
|
500
494
|
} catch {
|
|
501
495
|
/* no transcripts yet */
|
|
502
496
|
}
|
|
503
|
-
console.log(
|
|
504
|
-
`In a week, \`limitcast results\` shows every limit you hit and how far ahead limitcast warned you.${isPro() ? '' : ' Try Pro free for 7 days, no card: limitcast trial'}`,
|
|
505
|
-
);
|
|
497
|
+
console.log(`In a week, \`limitcast results\` shows every limit you hit and how far ahead limitcast warned you.`);
|
|
506
498
|
} else if (cmd === 'uninstall') {
|
|
507
499
|
const changes = uninstall();
|
|
508
500
|
console.log(changes.length ? changes.map((c) => `✓ ${c}`).join('\n') : 'Nothing to remove.');
|
|
501
|
+
} else if (cmd === 'onboard') {
|
|
502
|
+
const checks = await healthChecks();
|
|
503
|
+
let features = { statusLine: false, guard: false, alerts: false };
|
|
504
|
+
try {
|
|
505
|
+
features = installedFeatures();
|
|
506
|
+
} catch {
|
|
507
|
+
/* invalid settings are explained by doctor */
|
|
508
|
+
}
|
|
509
|
+
const latest = await latestInteractiveTranscript(claudeRoot());
|
|
510
|
+
const providers = [];
|
|
511
|
+
if (existsSync(settingsPath()) || latest) providers.push('Claude Code');
|
|
512
|
+
if (existsSync(codexConfigPath())) providers.push('Codex');
|
|
513
|
+
if (grokPresent()) providers.push('Grok');
|
|
514
|
+
console.log(
|
|
515
|
+
forTerminal(
|
|
516
|
+
onboardingReport({
|
|
517
|
+
checks,
|
|
518
|
+
features,
|
|
519
|
+
providers,
|
|
520
|
+
contextTokens: latest ? latest.pieces.reduce((n, p) => n + p.chars, 0) / 4 : null,
|
|
521
|
+
}),
|
|
522
|
+
),
|
|
523
|
+
);
|
|
509
524
|
} else if (cmd === 'doctor') {
|
|
510
525
|
if (args.includes('--fix')) {
|
|
511
526
|
// Re-install what is installed, with this Node and this copy of limitcast (after a Node upgrade, say).
|
|
512
527
|
const f = installedFeatures();
|
|
513
528
|
if (!f.statusLine) console.log('limitcast is not installed. Run `limitcast install` first.');
|
|
514
529
|
else {
|
|
515
|
-
for (const c of install({ guard: f.guard
|
|
530
|
+
for (const c of install({ guard: f.guard, alerts: f.alerts })) console.log(`✓ ${c}`);
|
|
516
531
|
console.log('Restart Claude Code, Codex and Grok to load it. Codex asks you to approve the guard again: start Codex and accept it.');
|
|
517
532
|
}
|
|
518
533
|
}
|
|
@@ -523,17 +538,38 @@ if (cmd === 'status') {
|
|
|
523
538
|
if (mem) checks.push(mem);
|
|
524
539
|
for (const c of checks) console.log(`${c.ok ? '✓' : '✗'} ${c.line}`);
|
|
525
540
|
process.exit(checks.every((c) => c.ok) ? 0 : 1);
|
|
541
|
+
} else if (cmd === 'grok-usage') {
|
|
542
|
+
const arg = args.find((a) => !a.startsWith('-'));
|
|
543
|
+
if (args.includes('--refresh')) {
|
|
544
|
+
await refreshGrokQuota(now, { force: true }); // the background refresh the status line starts
|
|
545
|
+
} else if (arg && arg !== 'on' && arg !== 'off') {
|
|
546
|
+
console.log('usage: limitcast grok-usage [on|off]');
|
|
547
|
+
process.exit(2);
|
|
548
|
+
} else if (arg === 'on' && !grokPresent()) {
|
|
549
|
+
console.log('Grok is not installed here (no ~/.grok), so there is no usage to read.');
|
|
550
|
+
process.exit(1);
|
|
551
|
+
} else {
|
|
552
|
+
if (arg) setGrokQuota(arg === 'on');
|
|
553
|
+
if (arg === 'on')
|
|
554
|
+
console.log(
|
|
555
|
+
'Grok weekly usage is on. About every 5 minutes limitcast reads the login Grok keeps in ~/.grok/auth.json and asks grok.com for your usage, the way Grok Build does. The login goes only to grok.com and is never stored or logged. Turn it off: limitcast grok-usage off',
|
|
556
|
+
);
|
|
557
|
+
if (arg === 'off') console.log('Grok weekly usage is off. limitcast no longer reads your Grok login or contacts grok.com.');
|
|
558
|
+
else if (grokQuotaEnabled()) {
|
|
559
|
+
const q = await refreshGrokQuota(now, { force: arg === 'on' });
|
|
560
|
+
console.log(
|
|
561
|
+
q.ok
|
|
562
|
+
? `Grok ${q.label?.toLowerCase()}: ${Math.round(q.pct ?? 0)}% used${q.reset ? `, resets ${new Date(q.reset * 1000).toLocaleString()}` : ''}`
|
|
563
|
+
: `Grok usage unavailable: ${q.error ?? 'no reading yet'}`,
|
|
564
|
+
);
|
|
565
|
+
if (!q.ok) process.exit(1);
|
|
566
|
+
} else console.log('Grok weekly usage is off. Turn it on: limitcast grok-usage on');
|
|
567
|
+
}
|
|
526
568
|
} else if (cmd === 'memory') {
|
|
527
569
|
const dir = args.find((a) => !a.startsWith('-')) ?? memoryDir();
|
|
528
570
|
console.log(memoryReport(scanMemory(dir), dir));
|
|
529
571
|
} else if (cmd === 'report' || cmd === 'trim') {
|
|
530
|
-
const pro =
|
|
531
|
-
if (!pro && cmd === 'report') {
|
|
532
|
-
console.log(
|
|
533
|
-
`\`limitcast ${cmd}\` is part of limitcast Pro: ${UPGRADE_URL}\nTry it free for 7 days: limitcast trial. Already bought it? limitcast activate <license-key>`,
|
|
534
|
-
);
|
|
535
|
-
process.exit(2);
|
|
536
|
-
}
|
|
572
|
+
const pro = true;
|
|
537
573
|
const since = now - days() * 86400_000;
|
|
538
574
|
if (cmd === 'trim' && args[0] === 'keep') {
|
|
539
575
|
// The keep-list: servers and skills `trim --apply` never touches (Claude, Codex and Grok). Free to manage; apply is Pro.
|
|
@@ -550,11 +586,7 @@ if (cmd === 'status') {
|
|
|
550
586
|
process.exit(0);
|
|
551
587
|
}
|
|
552
588
|
if (cmd === 'trim' && args.includes('--codex')) {
|
|
553
|
-
// Codex: AGENTS.md and the MCP servers in ~/.codex/config.toml.
|
|
554
|
-
if ((args.includes('--apply') || args.includes('--undo')) && !pro) {
|
|
555
|
-
console.log(`\`limitcast trim --codex --apply\` is part of limitcast Pro: ${UPGRADE_URL}`);
|
|
556
|
-
process.exit(2);
|
|
557
|
-
}
|
|
589
|
+
// Codex: AGENTS.md and the MCP servers in ~/.codex/config.toml.
|
|
558
590
|
if (args.includes('--undo')) {
|
|
559
591
|
const e = undoCodexTrim();
|
|
560
592
|
console.log(
|
|
@@ -579,10 +611,6 @@ if (cmd === 'status') {
|
|
|
579
611
|
process.exit(0);
|
|
580
612
|
}
|
|
581
613
|
if (cmd === 'trim' && args.includes('--grok')) {
|
|
582
|
-
if ((args.includes('--apply') || args.includes('--undo')) && !pro) {
|
|
583
|
-
console.log(`\`limitcast trim --grok --apply\` is part of limitcast Pro: ${UPGRADE_URL}`);
|
|
584
|
-
process.exit(2);
|
|
585
|
-
}
|
|
586
614
|
if (args.includes('--undo')) {
|
|
587
615
|
const e = undoGrokTrim();
|
|
588
616
|
console.log(
|
|
@@ -626,27 +654,15 @@ if (cmd === 'status') {
|
|
|
626
654
|
// Prefer the measured starting context of the latest interactive session; older Claude Code logs fall back to estimates.
|
|
627
655
|
const latest = await latestInteractiveTranscript(claudeRoot());
|
|
628
656
|
if (latest) recordOverhead(snapshot(latest));
|
|
629
|
-
//
|
|
630
|
-
if (!pro && !latest) {
|
|
631
|
-
console.log(`\`limitcast trim\` needs one Claude Code session first. Naming what to cut is Pro: ${UPGRADE_URL}`);
|
|
632
|
-
process.exit(2);
|
|
633
|
-
}
|
|
657
|
+
// The share view omits private names; the local view includes actionable detail.
|
|
634
658
|
if (args.includes('--apply') || args.includes('--undo')) {
|
|
635
|
-
if (!pro) {
|
|
636
|
-
console.log(
|
|
637
|
-
`\`limitcast trim --apply\` is part of limitcast Pro: ${UPGRADE_URL}\nTry it free for 7 days: limitcast trial. Already bought it? limitcast activate <license-key>`,
|
|
638
|
-
);
|
|
639
|
-
process.exit(2);
|
|
640
|
-
}
|
|
641
659
|
console.log(args.includes('--undo') ? undoMessage(undoTrim()) : applyMessage(latest, used));
|
|
642
660
|
process.exit(0);
|
|
643
661
|
}
|
|
644
662
|
const keep = getKeep();
|
|
645
|
-
if (latest &&
|
|
663
|
+
if (latest && args.includes('--share')) text = shareSummary(baseline(usage), latest, used, days(), keep);
|
|
646
664
|
else text = latest ? startupReport(baseline(usage), latest, used, days(), keep) : trimReport(baseline(usage), contributors(), used, days());
|
|
647
|
-
if (!
|
|
648
|
-
text += `\n\nPro names each item and what it costs, so you can cut it: ${UPGRADE_URL}\nTry it free for 7 days: limitcast trial. Already bought it? limitcast activate <license-key>`;
|
|
649
|
-
else if (latest && !args.includes('--share')) {
|
|
665
|
+
if (latest && !args.includes('--share')) {
|
|
650
666
|
const still = stillLoading(latest);
|
|
651
667
|
text += still.length
|
|
652
668
|
? `\n\nStill loading after \`trim --apply\`: ${still.join(', ')}. A Claude Code session that was running may have rewritten ~/.claude.json; quit Claude Code and run \`limitcast trim --apply\` again.`
|
|
@@ -663,10 +679,6 @@ if (cmd === 'status') {
|
|
|
663
679
|
} else if (cmd === 'drift') {
|
|
664
680
|
// SessionStart hook: tells the user (systemMessage, never the model's context) when starting context grew.
|
|
665
681
|
const hook = args.includes('--hook');
|
|
666
|
-
if (!isPro()) {
|
|
667
|
-
if (!hook) console.log(`\`limitcast drift\` is part of limitcast Pro: ${UPGRADE_URL}`);
|
|
668
|
-
process.exit(hook ? 0 : 2);
|
|
669
|
-
}
|
|
670
682
|
try {
|
|
671
683
|
const latest = await latestInteractiveTranscript(claudeRoot());
|
|
672
684
|
const d = latest ? recordOverhead(snapshot(latest)) : null;
|
|
@@ -684,13 +696,9 @@ if (cmd === 'status') {
|
|
|
684
696
|
const samples = [...load(since), ...(await readCodex(since))];
|
|
685
697
|
const s = loadOverhead();
|
|
686
698
|
// The daily rollup keeps the value record current; a session-start hook must not scan transcripts itself.
|
|
687
|
-
const week =
|
|
699
|
+
const week = valuePeriod(loadValue(), since, now);
|
|
688
700
|
lines.push(
|
|
689
|
-
weeklyLine(
|
|
690
|
-
resultsStats({ now, days: 7, samples, blocks: loadBlocks(since), pro: true }),
|
|
691
|
-
s ? savedPerSession(s) : null,
|
|
692
|
-
week.reduce((a, x) => a + x.turns * x.savedPerTurn, 0),
|
|
693
|
-
),
|
|
701
|
+
weeklyLine(resultsStats({ now, days: 7, samples, blocks: loadBlocks(since), pro: true }), s ? savedPerSession(s) : null, week.tokens),
|
|
694
702
|
);
|
|
695
703
|
}
|
|
696
704
|
if (lines.length) console.log(JSON.stringify({ systemMessage: lines.join('\n') }));
|
|
@@ -701,10 +709,6 @@ if (cmd === 'status') {
|
|
|
701
709
|
if (!hook) throw e; // a hook must never break session start
|
|
702
710
|
}
|
|
703
711
|
} else if (cmd === 'saved') {
|
|
704
|
-
if (!isPro()) {
|
|
705
|
-
console.log(`\`limitcast saved\` is part of limitcast Pro: ${UPGRADE_URL}`);
|
|
706
|
-
process.exit(2);
|
|
707
|
-
}
|
|
708
712
|
const latest = await latestInteractiveTranscript(claudeRoot());
|
|
709
713
|
if (latest) recordOverhead(snapshot(latest));
|
|
710
714
|
const s = loadOverhead();
|
|
@@ -712,10 +716,10 @@ if (cmd === 'status') {
|
|
|
712
716
|
forTerminal(s ? savedSummary(s, await countInteractiveSince(claudeRoot(), s.first.at)) : 'Nothing measured yet. Run `limitcast trim` first.'),
|
|
713
717
|
);
|
|
714
718
|
} else if (cmd === 'results') {
|
|
715
|
-
//
|
|
716
|
-
const pro =
|
|
719
|
+
// Historical previews remain separate from applied controls.
|
|
720
|
+
const pro = true;
|
|
717
721
|
const since = now - days() * 86400_000;
|
|
718
|
-
let saved =
|
|
722
|
+
let saved = '';
|
|
719
723
|
let perSession = null;
|
|
720
724
|
if (pro) {
|
|
721
725
|
const latest = await latestInteractiveTranscript(claudeRoot());
|
|
@@ -729,7 +733,9 @@ if (cmd === 'status') {
|
|
|
729
733
|
}
|
|
730
734
|
const samples = [...load(since), ...(await readCodex(since))];
|
|
731
735
|
const blocks = loadBlocks(since);
|
|
732
|
-
const
|
|
736
|
+
const value = await refreshValue();
|
|
737
|
+
const totals = valueTotals(value);
|
|
738
|
+
const insight = periodInsights({ value, usage: await readUsage(since - days() * 86400_000, {}), blocks, since, until: now });
|
|
733
739
|
if (args.includes('--share'))
|
|
734
740
|
console.log(
|
|
735
741
|
resultsShare(resultsStats({ now, days: days(), samples, blocks, pro }), {
|
|
@@ -737,17 +743,16 @@ if (cmd === 'status') {
|
|
|
737
743
|
pro,
|
|
738
744
|
savedPerSession: perSession,
|
|
739
745
|
notResent: totals.tokens,
|
|
740
|
-
})
|
|
746
|
+
}) +
|
|
747
|
+
'\n' +
|
|
748
|
+
insightsShare(insight, pro),
|
|
741
749
|
);
|
|
742
750
|
else if (args.includes('--html')) {
|
|
743
|
-
//
|
|
744
|
-
if (!pro) {
|
|
745
|
-
console.log(`The HTML dashboard is part of limitcast Pro: ${UPGRADE_URL}`);
|
|
746
|
-
process.exit(2);
|
|
747
|
-
}
|
|
751
|
+
// results, the current windows and the burn report on one page, opened in the browser.
|
|
748
752
|
const rows = forecastAll(oneClaudeAccount([...load(now - KEEP_MS), ...(await readCodex(now - KEEP_MS))]), now);
|
|
749
753
|
const burn = burnReport(await readUsage(since, {}), { since, now }).replace(/^(#{1,2}) /gm, '#$1 ');
|
|
750
754
|
const md = [
|
|
755
|
+
insightsReport(insight, pro),
|
|
751
756
|
resultsReport({ now, days: days(), samples, blocks, pro, saved, value: valueSection(totals, { now, pro }), subagents: loadSubagents(since) }),
|
|
752
757
|
'## Right now',
|
|
753
758
|
'```',
|
|
@@ -766,15 +771,23 @@ if (cmd === 'status') {
|
|
|
766
771
|
} else
|
|
767
772
|
console.log(
|
|
768
773
|
forTerminal(
|
|
769
|
-
|
|
774
|
+
[
|
|
775
|
+
insightsReport(insight, pro),
|
|
776
|
+
resultsReport({
|
|
777
|
+
now,
|
|
778
|
+
days: days(),
|
|
779
|
+
samples,
|
|
780
|
+
blocks,
|
|
781
|
+
pro,
|
|
782
|
+
saved,
|
|
783
|
+
value: valueSection(totals, { now, pro }),
|
|
784
|
+
subagents: loadSubagents(since),
|
|
785
|
+
}),
|
|
786
|
+
].join('\n\n'),
|
|
770
787
|
),
|
|
771
788
|
);
|
|
772
789
|
} else if (cmd === 'notify') {
|
|
773
790
|
// Desktop notifications from the status line (Pro, opt-in).
|
|
774
|
-
if (!isPro()) {
|
|
775
|
-
console.log(`Desktop notifications are part of limitcast Pro: ${UPGRADE_URL}`);
|
|
776
|
-
process.exit(2);
|
|
777
|
-
}
|
|
778
791
|
const what = args[0];
|
|
779
792
|
if (what === 'ntfy' || what === 'webhook') {
|
|
780
793
|
// Phone (ntfy) or Slack/Discord: every notification also goes there; setting one turns notifications on.
|
|
@@ -814,10 +827,6 @@ if (cmd === 'status') {
|
|
|
814
827
|
);
|
|
815
828
|
} else if (cmd === 'after-reset') {
|
|
816
829
|
// Run a command once a window has reset: queue the heavy job instead of watching the clock.
|
|
817
|
-
if (!isPro()) {
|
|
818
|
-
console.log(`\`limitcast after-reset\` is part of limitcast Pro: ${UPGRADE_URL}`);
|
|
819
|
-
process.exit(2);
|
|
820
|
-
}
|
|
821
830
|
const sep = args.indexOf('--');
|
|
822
831
|
const command = sep >= 0 ? args.slice(sep + 1) : [];
|
|
823
832
|
const src = flag('--src') ?? 'claude';
|
|
@@ -860,41 +869,8 @@ if (cmd === 'status') {
|
|
|
860
869
|
} catch {
|
|
861
870
|
/* next time */
|
|
862
871
|
}
|
|
863
|
-
} else if (
|
|
864
|
-
|
|
865
|
-
const key = args[0] ?? '';
|
|
866
|
-
const res = key.startsWith('LC1.') ? activate(key) : await activatePolar(key);
|
|
867
|
-
console.log(res.ok ? `✓ limitcast Pro activated${res.claims.e ? ` for ${res.claims.e}` : ''}` : `✗ ${res.reason}`);
|
|
868
|
-
process.exit(res.ok ? 0 : 1);
|
|
869
|
-
} else if (cmd === 'deactivate') {
|
|
870
|
-
const res = await deactivatePolar();
|
|
871
|
-
console.log(res.ok ? '✓ This machine is deactivated; the key can be used on another computer.' : `✗ ${res.reason}`);
|
|
872
|
-
process.exit(res.ok ? 0 : 1);
|
|
873
|
-
} else if (cmd === 'license') {
|
|
874
|
-
const l = currentLicense();
|
|
875
|
-
console.log(l === null ? trialLine() : l.ok ? `Pro: ${l.claims.e}` : `License problem: ${l.reason}`);
|
|
876
|
-
} else if (cmd === 'trial') {
|
|
877
|
-
// Pro for 7 days on this machine, no card, once.
|
|
878
|
-
if (currentLicense()?.ok) {
|
|
879
|
-
console.log('You already have Pro.');
|
|
880
|
-
process.exit(0);
|
|
881
|
-
}
|
|
882
|
-
const t = startTrial(now);
|
|
883
|
-
if (!t.ok) {
|
|
884
|
-
console.log(t.active ? `Your Pro trial is already running, until ${clock(t.ends)}.` : trialLine());
|
|
885
|
-
process.exit(t.active ? 0 : 2);
|
|
886
|
-
}
|
|
887
|
-
console.log(
|
|
888
|
-
[
|
|
889
|
-
`✓ Pro trial on: 7 days, until ${new Date(t.ends).toLocaleDateString()}. No card, nothing to cancel.`,
|
|
890
|
-
'Try it:',
|
|
891
|
-
' limitcast install --guard --alerts block runaway subagents, move them to Sonnet when a window is tight',
|
|
892
|
-
' limitcast trim --apply cut the context you never use (limitcast trim --undo reverses it)',
|
|
893
|
-
' limitcast notify on a desktop notification before you hit a limit',
|
|
894
|
-
' limitcast results what it did for you, any time',
|
|
895
|
-
`Keep Pro after the trial: ${UPGRADE_URL}`,
|
|
896
|
-
].join('\n'),
|
|
897
|
-
);
|
|
872
|
+
} else if (['activate', 'deactivate', 'license', 'trial'].includes(cmd)) {
|
|
873
|
+
console.log('limitcast is free and open source under the MIT License. All features are available; no license key, account or trial is required.');
|
|
898
874
|
} else if (cmd === '--version' || cmd === '-v') {
|
|
899
875
|
console.log(VERSION);
|
|
900
876
|
} else {
|
|
@@ -902,7 +878,7 @@ if (cmd === 'status') {
|
|
|
902
878
|
process.exit(cmd && !['help', '--help', '-h'].includes(cmd) ? 1 : 0);
|
|
903
879
|
}
|
|
904
880
|
|
|
905
|
-
/** Everything `doctor` checks: setup, data freshness,
|
|
881
|
+
/** Everything `doctor` checks: setup, data freshness, and whether each tool's logs still parse. */
|
|
906
882
|
async function healthChecks() {
|
|
907
883
|
// Readings are only stored when they change, so freshness comes from the last feed the status line saw.
|
|
908
884
|
let latest = 0;
|
|
@@ -911,9 +887,7 @@ async function healthChecks() {
|
|
|
911
887
|
} catch {
|
|
912
888
|
/* never fed */
|
|
913
889
|
}
|
|
914
|
-
const
|
|
915
|
-
const checks = doctor({ samplesAgeMs: latest ? now - latest : null, license });
|
|
916
|
-
if (license === null && trialStatus(now)) checks.push({ ok: true, line: trialLine() });
|
|
890
|
+
const checks = doctor({ samplesAgeMs: latest ? now - latest : null });
|
|
917
891
|
return [...checks, ...(await formatChecks())];
|
|
918
892
|
}
|
|
919
893
|
|
|
@@ -934,53 +908,10 @@ function saveHealth(checks) {
|
|
|
934
908
|
mkdirSync(stateDir(), { recursive: true });
|
|
935
909
|
writeFileSync(file, JSON.stringify({ at: now, failed }));
|
|
936
910
|
const fresh = failed.filter((l) => !before.includes(l));
|
|
937
|
-
if (fresh.length &&
|
|
911
|
+
if (fresh.length && notifyEnabled()) send(`limitcast needs a fix: ${fresh[0]} Run: limitcast doctor`);
|
|
938
912
|
return failed;
|
|
939
913
|
}
|
|
940
914
|
|
|
941
|
-
/**
|
|
942
|
-
* Free installs: for one day a week, what the guard preview saw Pro would have done, e.g.
|
|
943
|
-
* "this week Pro would have stopped 2 subagents and moved 5 to Sonnet · limitcast trial". Silent when it's nothing.
|
|
944
|
-
* @param {number} t epoch ms
|
|
945
|
-
*/
|
|
946
|
-
function freeWeeklyHint(t) {
|
|
947
|
-
const file = join(stateDir(), 'free-weekly.json');
|
|
948
|
-
let from = 0;
|
|
949
|
-
try {
|
|
950
|
-
from = JSON.parse(readFileSync(file, 'utf8')).from ?? 0;
|
|
951
|
-
} catch {
|
|
952
|
-
/* first run: start the clock */
|
|
953
|
-
}
|
|
954
|
-
const WEEK = 7 * 86400_000;
|
|
955
|
-
if (!from || t >= from + 86400_000) {
|
|
956
|
-
// First run starts a week out; afterwards the next day-long showing is a week after this one.
|
|
957
|
-
from = from ? from + Math.ceil((t - from - 86400_000 + 1) / WEEK) * WEEK : t + WEEK;
|
|
958
|
-
mkdirSync(stateDir(), { recursive: true });
|
|
959
|
-
writeFileSync(file, JSON.stringify({ from }));
|
|
960
|
-
}
|
|
961
|
-
if (t < from) return null;
|
|
962
|
-
const preview = loadBlocks(t - WEEK).filter((b) => b.shadow);
|
|
963
|
-
const stopped = preview.filter((b) => !b.kind || b.kind === 'budget' || b.kind === 'today').length;
|
|
964
|
-
const moved = preview.filter((b) => b.kind === 'switch').length;
|
|
965
|
-
const cold = preview.filter((b) => b.kind === 'cold').length;
|
|
966
|
-
if (!stopped && !moved && !cold) return null;
|
|
967
|
-
const parts = [
|
|
968
|
-
stopped ? `stopped ${stopped} subagent${stopped === 1 ? '' : 's'}` : '',
|
|
969
|
-
moved ? `moved ${moved} to Sonnet` : '',
|
|
970
|
-
cold ? `caught ${cold} cold-cache message${cold === 1 ? '' : 's'}` : '',
|
|
971
|
-
].filter(Boolean);
|
|
972
|
-
return `this week Pro would have ${parts.join(' and ')} · limitcast trial`;
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
/** Free tier, a running trial, or an ended one, in one line. */
|
|
976
|
-
function trialLine() {
|
|
977
|
-
const t = trialStatus(now);
|
|
978
|
-
if (!t) return `Free tier. Try Pro free for 7 days, no card: limitcast trial. Buy: ${UPGRADE_URL}`;
|
|
979
|
-
if (t.active)
|
|
980
|
-
return `Pro trial: ${Math.ceil((t.ends - now) / 86400_000)} days left (until ${new Date(t.ends).toLocaleDateString()}). Keep Pro: ${UPGRADE_URL}`;
|
|
981
|
-
return `Pro trial ended ${new Date(t.ends).toLocaleDateString()}. Keep Pro: ${UPGRADE_URL}`;
|
|
982
|
-
}
|
|
983
|
-
|
|
984
915
|
/** The status-line hint while the last health check found something to fix. */
|
|
985
916
|
function healthHint() {
|
|
986
917
|
try {
|
|
@@ -1018,7 +949,7 @@ async function refreshValue() {
|
|
|
1018
949
|
const change = limitChange(v.calibHistory ?? []);
|
|
1019
950
|
if (change && (!v.limitChange || now - v.limitChange.at > 7 * 86400_000)) {
|
|
1020
951
|
v.limitChange = { ...change, at: now };
|
|
1021
|
-
if (
|
|
952
|
+
if (notifyEnabled()) send(limitChangeMessage(change));
|
|
1022
953
|
}
|
|
1023
954
|
saveValue(v);
|
|
1024
955
|
return v;
|