limitcast 0.14.0 → 0.16.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 +103 -212
- package/package.json +2 -2
- 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/memory.mjs +122 -0
- 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 +11 -5
- package/src/value.mjs +37 -11
package/bin/limitcast.mjs
CHANGED
|
@@ -43,12 +43,13 @@ import {
|
|
|
43
43
|
import { runGuard } from '../src/guard.mjs';
|
|
44
44
|
import { accountForecasts, bindingLine, compactHint, headroom, lastCall, lastCallTokens } from '../src/hints.mjs';
|
|
45
45
|
import { htmlPage } from '../src/html.mjs';
|
|
46
|
+
import { insightsReport, insightsShare, periodInsights } from '../src/insights.mjs';
|
|
46
47
|
import { doctor, install, installedFeatures, readSettings, settingsPath, uninstall } from '../src/install.mjs';
|
|
47
|
-
import {
|
|
48
|
+
import { memoryCheck, memoryDir, memoryReport, scanMemory } from '../src/memory.mjs';
|
|
48
49
|
import { buildNotifierApp, loadChannels, notifierApp, notifyChanges, notifyEnabled, send, setChannel, setNotify } from '../src/notify.mjs';
|
|
50
|
+
import { onboardingReport } from '../src/onboarding.mjs';
|
|
49
51
|
import { driftMessage, loadOverhead, recordOverhead, savedPerSession, savedSummary, snapshot } from '../src/overhead.mjs';
|
|
50
52
|
import { advise, getPlan, loadPeaks, PLANS, planPrices, planStats, recordPeaks, setPlan } from '../src/plan.mjs';
|
|
51
|
-
import { activatePolar, deactivatePolar, refreshDue, refreshPolar } from '../src/polar.mjs';
|
|
52
53
|
import { costOf, fmtUsd } from '../src/prices.mjs';
|
|
53
54
|
import { burnReport } from '../src/report.mjs';
|
|
54
55
|
import { loadBlocks, logBlock, resultsReport, resultsShare, resultsStats, weeklyDue, weeklyLine } from '../src/results.mjs';
|
|
@@ -74,26 +75,26 @@ import { forTerminal } from '../src/term.mjs';
|
|
|
74
75
|
import { firstFlag, toolKey, toolNotice } from '../src/toolcheck.mjs';
|
|
75
76
|
import { baseline, contributors, measuredSavings, shareSummary, startupReport, trimReport } from '../src/trim.mjs';
|
|
76
77
|
import { claudeRoot, grokRoot, readUsage } from '../src/usage.mjs';
|
|
77
|
-
import { dailyDue, foldEvents, loadValue, saveValue, scanSessions, valueSection, valueTotals } from '../src/value.mjs';
|
|
78
|
+
import { dailyDue, foldEvents, loadValue, saveValue, scanSessions, valuePeriod, valueSection, valueTotals } from '../src/value.mjs';
|
|
78
79
|
import { attribute, jobsReport, whyReport, whySessions } from '../src/where.mjs';
|
|
79
80
|
|
|
80
81
|
const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
81
82
|
const HELP = `limitcast ${VERSION}: stretch your Claude Code, Codex and Grok plans
|
|
82
83
|
|
|
84
|
+
limitcast onboard read-only setup checks and a guided first useful result
|
|
83
85
|
limitcast install [--guard] wire limitcast into Claude Code (and, with --guard, Codex and Grok); backs up settings
|
|
84
|
-
(without Pro the guard is a preview: it records what it would block, never blocks)
|
|
85
86
|
limitcast uninstall remove it and restore your original status line
|
|
86
87
|
limitcast doctor [--fix] check the setup (--fix: re-install with this Node, e.g. after a Node upgrade)
|
|
87
|
-
limitcast trial Pro free for 7 days on this computer, no card
|
|
88
88
|
limitcast status [--json] used, burn rate, runout time, reset, and today's share of each weekly window
|
|
89
89
|
limitcast trim [--share] tokens every session loads before you type, and how much you never use
|
|
90
90
|
limitcast trim --codex the same for Codex: AGENTS.md size and MCP servers you haven't used
|
|
91
91
|
limitcast trim --grok the same for Grok: system prompt size and MCP servers you haven't used
|
|
92
|
+
limitcast memory [dir] check this project's auto-memory: load cap, broken links, unlinked and oversized files
|
|
92
93
|
limitcast results [--days N] limits you reached, how far ahead limitcast warned, what the guard blocked
|
|
93
94
|
[--share] totals only, safe to post
|
|
94
|
-
limitcast license show the license
|
|
95
|
+
limitcast license show the MIT license status
|
|
95
96
|
|
|
96
|
-
|
|
97
|
+
All features are free (MIT License)
|
|
97
98
|
limitcast trim [--days N] [--share] names what to cut and what each costs
|
|
98
99
|
(--share: totals only, no names, safe to post)
|
|
99
100
|
limitcast trim --apply / --undo hide those skills and turn off those MCP servers (backed up, reversible)
|
|
@@ -126,16 +127,14 @@ const HELP = `limitcast ${VERSION}: stretch your Claude Code, Codex and Grok pla
|
|
|
126
127
|
limitcast report [--days N] [--out FILE] tokens by tool, day, project, model and session
|
|
127
128
|
limitcast report --why [--days N] where the new tokens went: subagents, session starts, cache rebuilds, tool results
|
|
128
129
|
limitcast report --jobs [--days N] the scheduled (headless) jobs that spend the most tokens just starting
|
|
129
|
-
(status line
|
|
130
|
-
limitcast activate <license-key> unlock Pro on this computer (online once; then a weekly check, offline up to 30 days)
|
|
131
|
-
limitcast deactivate free this computer's activation to use the key elsewhere
|
|
130
|
+
(status line: points to another account with room, and suggests /compact past ~150k tokens a call)
|
|
132
131
|
|
|
133
132
|
Used by Claude Code, Codex and Grok (set up by install)
|
|
134
133
|
limitcast statusline [-- <cmd...>] record limit readings, then run your status-line command
|
|
135
|
-
limitcast guard PreToolUse hook
|
|
136
|
-
limitcast prompt-check UserPromptSubmit hook: the cold-cache warning
|
|
137
|
-
limitcast subagent-receipt SubagentStop hook: what the subagent cost
|
|
138
|
-
limitcast drift [--hook] SessionStart hook: compare starting context with the last session
|
|
134
|
+
limitcast guard PreToolUse hook
|
|
135
|
+
limitcast prompt-check UserPromptSubmit hook: the cold-cache warning
|
|
136
|
+
limitcast subagent-receipt SubagentStop hook: what the subagent cost
|
|
137
|
+
limitcast drift [--hook] SessionStart hook: compare starting context with the last session
|
|
139
138
|
`;
|
|
140
139
|
|
|
141
140
|
const [cmd, ...args] = process.argv.slice(2);
|
|
@@ -144,12 +143,14 @@ const flag = (/** @type {string} */ name) => {
|
|
|
144
143
|
const i = args.indexOf(name);
|
|
145
144
|
return i >= 0 ? args[i + 1] : undefined;
|
|
146
145
|
};
|
|
147
|
-
const days = () =>
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
146
|
+
const days = () => {
|
|
147
|
+
const n = Number(flag('--days') ?? 7);
|
|
148
|
+
if (!Number.isFinite(n) || n <= 0 || !Number.isFinite(new Date(now - n * 86400_000).getTime())) {
|
|
149
|
+
console.error('--days must be a finite positive number.');
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
return Math.max(1, n);
|
|
153
|
+
};
|
|
153
154
|
|
|
154
155
|
if (cmd === 'status') {
|
|
155
156
|
const rows = forecastAll(oneClaudeAccount([...load(now - KEEP_MS), ...(await readCodex(now - KEEP_MS)), ...grokSamples(now)]), now);
|
|
@@ -158,12 +159,11 @@ if (cmd === 'status') {
|
|
|
158
159
|
console.log(rows.length ? table(rows) : 'No data yet. Run `limitcast install`, then send a message in Claude Code, Codex or Grok.');
|
|
159
160
|
const binds = bindingLine(rows, getGrokBudget(), clock);
|
|
160
161
|
if (binds) console.log(`\n${binds}`);
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
);
|
|
162
|
+
// the other Claude accounts limitcast has current readings for (the table shows the latest one).
|
|
163
|
+
for (const a of accountForecasts(load(now - KEEP_MS), now).slice(1))
|
|
164
|
+
console.log(
|
|
165
|
+
`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(' · ')}`,
|
|
166
|
+
);
|
|
167
167
|
const spend = grokSpendLine(now);
|
|
168
168
|
if (spend) console.log(spend);
|
|
169
169
|
else if (existsSync(grokRoot()) && !rows.some((f) => f.src === 'grok'))
|
|
@@ -181,13 +181,11 @@ if (cmd === 'status') {
|
|
|
181
181
|
sid = feed?.session_id;
|
|
182
182
|
record(claudeSamples(feed, now));
|
|
183
183
|
saveFeedShape(feed);
|
|
184
|
-
// Hook-only Pro users never run an interactive command, so the weekly Polar check starts here, detached.
|
|
185
|
-
if (refreshDue(now)) spawn(process.execPath, [fileURLToPath(import.meta.url), 'license'], { detached: true, stdio: 'ignore' }).unref();
|
|
186
184
|
// Readings are kept 8 days; the daily rollup folds what they showed into the long-term value record.
|
|
187
185
|
if (dailyDue(now)) spawn(process.execPath, [fileURLToPath(import.meta.url), 'rollup'], { detached: true, stdio: 'ignore' }).unref();
|
|
188
186
|
const health = healthHint();
|
|
189
187
|
if (health) hints.push(health);
|
|
190
|
-
|
|
188
|
+
{
|
|
191
189
|
const samples = load(now - KEEP_MS);
|
|
192
190
|
if (notifyEnabled()) notifyChanges(forecastAll(oneClaudeAccount([...samples, ...grokSamples(now)], sid), now), clock);
|
|
193
191
|
const room = headroom(samples, sid, now);
|
|
@@ -198,9 +196,6 @@ if (cmd === 'status') {
|
|
|
198
196
|
const ctx = compactHint(lastCallTokens(feed.transcript_path));
|
|
199
197
|
if (ctx) hints.push(ctx);
|
|
200
198
|
}
|
|
201
|
-
} else {
|
|
202
|
-
const week = freeWeeklyHint(now);
|
|
203
|
-
if (week) hints.push(week);
|
|
204
199
|
}
|
|
205
200
|
} catch {
|
|
206
201
|
/* never break the status line */
|
|
@@ -228,10 +223,10 @@ if (cmd === 'status') {
|
|
|
228
223
|
if (grokOwn) console.log(grokOwn);
|
|
229
224
|
console.log(`limitcast: ${line}`);
|
|
230
225
|
} else if (cmd === 'guard') {
|
|
231
|
-
//
|
|
226
|
+
// The installed guard protects all users; LIMITCAST_ALLOW=1 remains the explicit override.
|
|
232
227
|
if (process.env.LIMITCAST_ALLOW === '1') process.exit(0);
|
|
233
228
|
try {
|
|
234
|
-
const d = await runGuard(JSON.parse(readStdin()), now, Number(process.env.LIMITCAST_GUARD_MINUTES ?? 30), { preview:
|
|
229
|
+
const d = await runGuard(JSON.parse(readStdin()), now, Number(process.env.LIMITCAST_GUARD_MINUTES ?? 30), { preview: false });
|
|
235
230
|
if (typeof d === 'string') {
|
|
236
231
|
console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: d } }));
|
|
237
232
|
} else if (d && 'notice' in d) {
|
|
@@ -256,14 +251,14 @@ if (cmd === 'status') {
|
|
|
256
251
|
}
|
|
257
252
|
} else if (cmd === 'prompt-check') {
|
|
258
253
|
// UserPromptSubmit hook: hold the first message after the prompt cache expired, once, with its cost.
|
|
259
|
-
//
|
|
254
|
+
// The opt-in hook warns once and fails open on errors.
|
|
260
255
|
try {
|
|
261
256
|
const hook = JSON.parse(readStdin());
|
|
262
257
|
const path = hook?.transcript_path;
|
|
263
258
|
const last = process.env.LIMITCAST_ALLOW !== '1' && typeof path === 'string' && existsSync(path) ? lastCall(path) : null;
|
|
264
259
|
const c = coldCost(hook?.prompt, last, now, { minutes: Number(process.env.LIMITCAST_CACHE_MINUTES ?? 60), calib: loadValue().calib });
|
|
265
260
|
if (c && last && firstWarning(String(hook.session_id), last.t)) {
|
|
266
|
-
const pro =
|
|
261
|
+
const pro = true;
|
|
267
262
|
logBlock({
|
|
268
263
|
t: now,
|
|
269
264
|
kind: 'cold',
|
|
@@ -282,10 +277,10 @@ if (cmd === 'status') {
|
|
|
282
277
|
/* a hook must never stop a prompt by failing */
|
|
283
278
|
}
|
|
284
279
|
} else if (cmd === 'tool-check') {
|
|
285
|
-
// PostToolUse hook (
|
|
280
|
+
// PostToolUse hook (installed with --alerts): tell the user, once per tool per session, about a very large tool
|
|
286
281
|
// result and what to ask for next time. Never reaches the model.
|
|
287
282
|
try {
|
|
288
|
-
|
|
283
|
+
{
|
|
289
284
|
const hook = JSON.parse(readStdin());
|
|
290
285
|
const name = String(hook?.tool_name ?? '');
|
|
291
286
|
const notice = name ? toolNotice(name, hook?.tool_response, loadValue().calib, Number(process.env.LIMITCAST_TOOL_TOKENS) || undefined) : null;
|
|
@@ -315,19 +310,13 @@ if (cmd === 'status') {
|
|
|
315
310
|
read: u.read,
|
|
316
311
|
...(pct === null ? {} : { pct }),
|
|
317
312
|
});
|
|
318
|
-
|
|
313
|
+
console.log(JSON.stringify({ systemMessage: receiptMessage(hook.agent_type, u, pct) }));
|
|
319
314
|
}
|
|
320
315
|
}
|
|
321
316
|
} catch {
|
|
322
317
|
/* a hook must never break the session */
|
|
323
318
|
}
|
|
324
319
|
} else if (cmd === 'plan') {
|
|
325
|
-
if (!isPro()) {
|
|
326
|
-
console.log(
|
|
327
|
-
`\`limitcast plan\` is part of limitcast Pro: ${UPGRADE_URL}\nTry it free for 7 days: limitcast trial. Already bought it? limitcast activate <license-key>`,
|
|
328
|
-
);
|
|
329
|
-
process.exit(2);
|
|
330
|
-
}
|
|
331
320
|
if (args[0] === 'set') {
|
|
332
321
|
const id = args[1];
|
|
333
322
|
if (id !== 'off' && !(id in PLANS)) {
|
|
@@ -366,10 +355,6 @@ if (cmd === 'status') {
|
|
|
366
355
|
console.log(forTerminal(out.join('\n')));
|
|
367
356
|
process.exit(0);
|
|
368
357
|
} else if (cmd === 'subagent-model') {
|
|
369
|
-
if (!isPro()) {
|
|
370
|
-
console.log(`Per-type subagent models are part of limitcast Pro: ${UPGRADE_URL}`);
|
|
371
|
-
process.exit(2);
|
|
372
|
-
}
|
|
373
358
|
const [type, model] = args;
|
|
374
359
|
if (type && (model === undefined || (model !== 'off' && !validModel(model)))) {
|
|
375
360
|
console.log(
|
|
@@ -401,10 +386,6 @@ if (cmd === 'status') {
|
|
|
401
386
|
} else console.log('\nExample: limitcast subagent-model Explore haiku');
|
|
402
387
|
process.exit(0);
|
|
403
388
|
} else if (cmd === 'budget') {
|
|
404
|
-
if (!isPro()) {
|
|
405
|
-
console.log(`Budgets are part of limitcast Pro: ${UPGRADE_URL}`);
|
|
406
|
-
process.exit(2);
|
|
407
|
-
}
|
|
408
389
|
if (args[0] === 'grok') {
|
|
409
390
|
const win = args[1] === '7d' || args[1] === '5h' ? args[1] : '5h';
|
|
410
391
|
const value = args[1] === '7d' || args[1] === '5h' ? args[2] : args[1];
|
|
@@ -465,13 +446,7 @@ if (cmd === 'status') {
|
|
|
465
446
|
} else if (cmd === 'install') {
|
|
466
447
|
const wantGuard = args.includes('--guard');
|
|
467
448
|
const wantAlerts = args.includes('--alerts');
|
|
468
|
-
|
|
469
|
-
console.log(
|
|
470
|
-
`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}`,
|
|
471
|
-
);
|
|
472
|
-
}
|
|
473
|
-
if (wantAlerts && !isPro()) console.log(`Alerts and the weekly summary are part of limitcast Pro (${UPGRADE_URL}). Skipping them.`);
|
|
474
|
-
for (const c of install({ guard: wantGuard, alerts: wantAlerts && isPro() })) console.log(`✓ ${c}`);
|
|
449
|
+
for (const c of install({ guard: wantGuard, alerts: wantAlerts })) console.log(`✓ ${c}`);
|
|
475
450
|
console.log('Restart Claude Code, Codex and Grok to load it. Then: limitcast doctor');
|
|
476
451
|
if (wantGuard && grokPresent() && !getGrokBudget())
|
|
477
452
|
console.log('Grok stores spend, not a % used. Set a 5-hour dollar cap so the guard can block: limitcast budget grok <usd>');
|
|
@@ -498,34 +473,55 @@ if (cmd === 'status') {
|
|
|
498
473
|
} catch {
|
|
499
474
|
/* no transcripts yet */
|
|
500
475
|
}
|
|
501
|
-
console.log(
|
|
502
|
-
`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'}`,
|
|
503
|
-
);
|
|
476
|
+
console.log(`In a week, \`limitcast results\` shows every limit you hit and how far ahead limitcast warned you.`);
|
|
504
477
|
} else if (cmd === 'uninstall') {
|
|
505
478
|
const changes = uninstall();
|
|
506
479
|
console.log(changes.length ? changes.map((c) => `✓ ${c}`).join('\n') : 'Nothing to remove.');
|
|
480
|
+
} else if (cmd === 'onboard') {
|
|
481
|
+
const checks = await healthChecks();
|
|
482
|
+
let features = { statusLine: false, guard: false, alerts: false };
|
|
483
|
+
try {
|
|
484
|
+
features = installedFeatures();
|
|
485
|
+
} catch {
|
|
486
|
+
/* invalid settings are explained by doctor */
|
|
487
|
+
}
|
|
488
|
+
const latest = await latestInteractiveTranscript(claudeRoot());
|
|
489
|
+
const providers = [];
|
|
490
|
+
if (existsSync(settingsPath()) || latest) providers.push('Claude Code');
|
|
491
|
+
if (existsSync(codexConfigPath())) providers.push('Codex');
|
|
492
|
+
if (grokPresent()) providers.push('Grok');
|
|
493
|
+
console.log(
|
|
494
|
+
forTerminal(
|
|
495
|
+
onboardingReport({
|
|
496
|
+
checks,
|
|
497
|
+
features,
|
|
498
|
+
providers,
|
|
499
|
+
contextTokens: latest ? latest.pieces.reduce((n, p) => n + p.chars, 0) / 4 : null,
|
|
500
|
+
}),
|
|
501
|
+
),
|
|
502
|
+
);
|
|
507
503
|
} else if (cmd === 'doctor') {
|
|
508
504
|
if (args.includes('--fix')) {
|
|
509
505
|
// Re-install what is installed, with this Node and this copy of limitcast (after a Node upgrade, say).
|
|
510
506
|
const f = installedFeatures();
|
|
511
507
|
if (!f.statusLine) console.log('limitcast is not installed. Run `limitcast install` first.');
|
|
512
508
|
else {
|
|
513
|
-
for (const c of install({ guard: f.guard
|
|
509
|
+
for (const c of install({ guard: f.guard, alerts: f.alerts })) console.log(`✓ ${c}`);
|
|
514
510
|
console.log('Restart Claude Code, Codex and Grok to load it. Codex asks you to approve the guard again: start Codex and accept it.');
|
|
515
511
|
}
|
|
516
512
|
}
|
|
517
513
|
const checks = await healthChecks();
|
|
518
514
|
saveHealth(checks);
|
|
515
|
+
// Memory is per project: shown here, but kept out of the saved health that the daily background check overwrites.
|
|
516
|
+
const mem = memoryCheck(scanMemory(memoryDir()));
|
|
517
|
+
if (mem) checks.push(mem);
|
|
519
518
|
for (const c of checks) console.log(`${c.ok ? '✓' : '✗'} ${c.line}`);
|
|
520
519
|
process.exit(checks.every((c) => c.ok) ? 0 : 1);
|
|
520
|
+
} else if (cmd === 'memory') {
|
|
521
|
+
const dir = args.find((a) => !a.startsWith('-')) ?? memoryDir();
|
|
522
|
+
console.log(memoryReport(scanMemory(dir), dir));
|
|
521
523
|
} else if (cmd === 'report' || cmd === 'trim') {
|
|
522
|
-
const pro =
|
|
523
|
-
if (!pro && cmd === 'report') {
|
|
524
|
-
console.log(
|
|
525
|
-
`\`limitcast ${cmd}\` is part of limitcast Pro: ${UPGRADE_URL}\nTry it free for 7 days: limitcast trial. Already bought it? limitcast activate <license-key>`,
|
|
526
|
-
);
|
|
527
|
-
process.exit(2);
|
|
528
|
-
}
|
|
524
|
+
const pro = true;
|
|
529
525
|
const since = now - days() * 86400_000;
|
|
530
526
|
if (cmd === 'trim' && args[0] === 'keep') {
|
|
531
527
|
// The keep-list: servers and skills `trim --apply` never touches (Claude, Codex and Grok). Free to manage; apply is Pro.
|
|
@@ -542,11 +538,7 @@ if (cmd === 'status') {
|
|
|
542
538
|
process.exit(0);
|
|
543
539
|
}
|
|
544
540
|
if (cmd === 'trim' && args.includes('--codex')) {
|
|
545
|
-
// Codex: AGENTS.md and the MCP servers in ~/.codex/config.toml.
|
|
546
|
-
if ((args.includes('--apply') || args.includes('--undo')) && !pro) {
|
|
547
|
-
console.log(`\`limitcast trim --codex --apply\` is part of limitcast Pro: ${UPGRADE_URL}`);
|
|
548
|
-
process.exit(2);
|
|
549
|
-
}
|
|
541
|
+
// Codex: AGENTS.md and the MCP servers in ~/.codex/config.toml.
|
|
550
542
|
if (args.includes('--undo')) {
|
|
551
543
|
const e = undoCodexTrim();
|
|
552
544
|
console.log(
|
|
@@ -571,10 +563,6 @@ if (cmd === 'status') {
|
|
|
571
563
|
process.exit(0);
|
|
572
564
|
}
|
|
573
565
|
if (cmd === 'trim' && args.includes('--grok')) {
|
|
574
|
-
if ((args.includes('--apply') || args.includes('--undo')) && !pro) {
|
|
575
|
-
console.log(`\`limitcast trim --grok --apply\` is part of limitcast Pro: ${UPGRADE_URL}`);
|
|
576
|
-
process.exit(2);
|
|
577
|
-
}
|
|
578
566
|
if (args.includes('--undo')) {
|
|
579
567
|
const e = undoGrokTrim();
|
|
580
568
|
console.log(
|
|
@@ -618,27 +606,15 @@ if (cmd === 'status') {
|
|
|
618
606
|
// Prefer the measured starting context of the latest interactive session; older Claude Code logs fall back to estimates.
|
|
619
607
|
const latest = await latestInteractiveTranscript(claudeRoot());
|
|
620
608
|
if (latest) recordOverhead(snapshot(latest));
|
|
621
|
-
//
|
|
622
|
-
if (!pro && !latest) {
|
|
623
|
-
console.log(`\`limitcast trim\` needs one Claude Code session first. Naming what to cut is Pro: ${UPGRADE_URL}`);
|
|
624
|
-
process.exit(2);
|
|
625
|
-
}
|
|
609
|
+
// The share view omits private names; the local view includes actionable detail.
|
|
626
610
|
if (args.includes('--apply') || args.includes('--undo')) {
|
|
627
|
-
if (!pro) {
|
|
628
|
-
console.log(
|
|
629
|
-
`\`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>`,
|
|
630
|
-
);
|
|
631
|
-
process.exit(2);
|
|
632
|
-
}
|
|
633
611
|
console.log(args.includes('--undo') ? undoMessage(undoTrim()) : applyMessage(latest, used));
|
|
634
612
|
process.exit(0);
|
|
635
613
|
}
|
|
636
614
|
const keep = getKeep();
|
|
637
|
-
if (latest &&
|
|
615
|
+
if (latest && args.includes('--share')) text = shareSummary(baseline(usage), latest, used, days(), keep);
|
|
638
616
|
else text = latest ? startupReport(baseline(usage), latest, used, days(), keep) : trimReport(baseline(usage), contributors(), used, days());
|
|
639
|
-
if (!
|
|
640
|
-
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>`;
|
|
641
|
-
else if (latest && !args.includes('--share')) {
|
|
617
|
+
if (latest && !args.includes('--share')) {
|
|
642
618
|
const still = stillLoading(latest);
|
|
643
619
|
text += still.length
|
|
644
620
|
? `\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.`
|
|
@@ -655,10 +631,6 @@ if (cmd === 'status') {
|
|
|
655
631
|
} else if (cmd === 'drift') {
|
|
656
632
|
// SessionStart hook: tells the user (systemMessage, never the model's context) when starting context grew.
|
|
657
633
|
const hook = args.includes('--hook');
|
|
658
|
-
if (!isPro()) {
|
|
659
|
-
if (!hook) console.log(`\`limitcast drift\` is part of limitcast Pro: ${UPGRADE_URL}`);
|
|
660
|
-
process.exit(hook ? 0 : 2);
|
|
661
|
-
}
|
|
662
634
|
try {
|
|
663
635
|
const latest = await latestInteractiveTranscript(claudeRoot());
|
|
664
636
|
const d = latest ? recordOverhead(snapshot(latest)) : null;
|
|
@@ -676,13 +648,9 @@ if (cmd === 'status') {
|
|
|
676
648
|
const samples = [...load(since), ...(await readCodex(since))];
|
|
677
649
|
const s = loadOverhead();
|
|
678
650
|
// The daily rollup keeps the value record current; a session-start hook must not scan transcripts itself.
|
|
679
|
-
const week =
|
|
651
|
+
const week = valuePeriod(loadValue(), since, now);
|
|
680
652
|
lines.push(
|
|
681
|
-
weeklyLine(
|
|
682
|
-
resultsStats({ now, days: 7, samples, blocks: loadBlocks(since), pro: true }),
|
|
683
|
-
s ? savedPerSession(s) : null,
|
|
684
|
-
week.reduce((a, x) => a + x.turns * x.savedPerTurn, 0),
|
|
685
|
-
),
|
|
653
|
+
weeklyLine(resultsStats({ now, days: 7, samples, blocks: loadBlocks(since), pro: true }), s ? savedPerSession(s) : null, week.tokens),
|
|
686
654
|
);
|
|
687
655
|
}
|
|
688
656
|
if (lines.length) console.log(JSON.stringify({ systemMessage: lines.join('\n') }));
|
|
@@ -693,10 +661,6 @@ if (cmd === 'status') {
|
|
|
693
661
|
if (!hook) throw e; // a hook must never break session start
|
|
694
662
|
}
|
|
695
663
|
} else if (cmd === 'saved') {
|
|
696
|
-
if (!isPro()) {
|
|
697
|
-
console.log(`\`limitcast saved\` is part of limitcast Pro: ${UPGRADE_URL}`);
|
|
698
|
-
process.exit(2);
|
|
699
|
-
}
|
|
700
664
|
const latest = await latestInteractiveTranscript(claudeRoot());
|
|
701
665
|
if (latest) recordOverhead(snapshot(latest));
|
|
702
666
|
const s = loadOverhead();
|
|
@@ -704,10 +668,10 @@ if (cmd === 'status') {
|
|
|
704
668
|
forTerminal(s ? savedSummary(s, await countInteractiveSince(claudeRoot(), s.first.at)) : 'Nothing measured yet. Run `limitcast trim` first.'),
|
|
705
669
|
);
|
|
706
670
|
} else if (cmd === 'results') {
|
|
707
|
-
//
|
|
708
|
-
const pro =
|
|
671
|
+
// Historical previews remain separate from applied controls.
|
|
672
|
+
const pro = true;
|
|
709
673
|
const since = now - days() * 86400_000;
|
|
710
|
-
let saved =
|
|
674
|
+
let saved = '';
|
|
711
675
|
let perSession = null;
|
|
712
676
|
if (pro) {
|
|
713
677
|
const latest = await latestInteractiveTranscript(claudeRoot());
|
|
@@ -721,7 +685,9 @@ if (cmd === 'status') {
|
|
|
721
685
|
}
|
|
722
686
|
const samples = [...load(since), ...(await readCodex(since))];
|
|
723
687
|
const blocks = loadBlocks(since);
|
|
724
|
-
const
|
|
688
|
+
const value = await refreshValue();
|
|
689
|
+
const totals = valueTotals(value);
|
|
690
|
+
const insight = periodInsights({ value, usage: await readUsage(since - days() * 86400_000, {}), blocks, since, until: now });
|
|
725
691
|
if (args.includes('--share'))
|
|
726
692
|
console.log(
|
|
727
693
|
resultsShare(resultsStats({ now, days: days(), samples, blocks, pro }), {
|
|
@@ -729,17 +695,16 @@ if (cmd === 'status') {
|
|
|
729
695
|
pro,
|
|
730
696
|
savedPerSession: perSession,
|
|
731
697
|
notResent: totals.tokens,
|
|
732
|
-
})
|
|
698
|
+
}) +
|
|
699
|
+
'\n' +
|
|
700
|
+
insightsShare(insight, pro),
|
|
733
701
|
);
|
|
734
702
|
else if (args.includes('--html')) {
|
|
735
|
-
//
|
|
736
|
-
if (!pro) {
|
|
737
|
-
console.log(`The HTML dashboard is part of limitcast Pro: ${UPGRADE_URL}`);
|
|
738
|
-
process.exit(2);
|
|
739
|
-
}
|
|
703
|
+
// results, the current windows and the burn report on one page, opened in the browser.
|
|
740
704
|
const rows = forecastAll(oneClaudeAccount([...load(now - KEEP_MS), ...(await readCodex(now - KEEP_MS))]), now);
|
|
741
705
|
const burn = burnReport(await readUsage(since, {}), { since, now }).replace(/^(#{1,2}) /gm, '#$1 ');
|
|
742
706
|
const md = [
|
|
707
|
+
insightsReport(insight, pro),
|
|
743
708
|
resultsReport({ now, days: days(), samples, blocks, pro, saved, value: valueSection(totals, { now, pro }), subagents: loadSubagents(since) }),
|
|
744
709
|
'## Right now',
|
|
745
710
|
'```',
|
|
@@ -758,15 +723,23 @@ if (cmd === 'status') {
|
|
|
758
723
|
} else
|
|
759
724
|
console.log(
|
|
760
725
|
forTerminal(
|
|
761
|
-
|
|
726
|
+
[
|
|
727
|
+
insightsReport(insight, pro),
|
|
728
|
+
resultsReport({
|
|
729
|
+
now,
|
|
730
|
+
days: days(),
|
|
731
|
+
samples,
|
|
732
|
+
blocks,
|
|
733
|
+
pro,
|
|
734
|
+
saved,
|
|
735
|
+
value: valueSection(totals, { now, pro }),
|
|
736
|
+
subagents: loadSubagents(since),
|
|
737
|
+
}),
|
|
738
|
+
].join('\n\n'),
|
|
762
739
|
),
|
|
763
740
|
);
|
|
764
741
|
} else if (cmd === 'notify') {
|
|
765
742
|
// Desktop notifications from the status line (Pro, opt-in).
|
|
766
|
-
if (!isPro()) {
|
|
767
|
-
console.log(`Desktop notifications are part of limitcast Pro: ${UPGRADE_URL}`);
|
|
768
|
-
process.exit(2);
|
|
769
|
-
}
|
|
770
743
|
const what = args[0];
|
|
771
744
|
if (what === 'ntfy' || what === 'webhook') {
|
|
772
745
|
// Phone (ntfy) or Slack/Discord: every notification also goes there; setting one turns notifications on.
|
|
@@ -806,10 +779,6 @@ if (cmd === 'status') {
|
|
|
806
779
|
);
|
|
807
780
|
} else if (cmd === 'after-reset') {
|
|
808
781
|
// Run a command once a window has reset: queue the heavy job instead of watching the clock.
|
|
809
|
-
if (!isPro()) {
|
|
810
|
-
console.log(`\`limitcast after-reset\` is part of limitcast Pro: ${UPGRADE_URL}`);
|
|
811
|
-
process.exit(2);
|
|
812
|
-
}
|
|
813
782
|
const sep = args.indexOf('--');
|
|
814
783
|
const command = sep >= 0 ? args.slice(sep + 1) : [];
|
|
815
784
|
const src = flag('--src') ?? 'claude';
|
|
@@ -852,41 +821,8 @@ if (cmd === 'status') {
|
|
|
852
821
|
} catch {
|
|
853
822
|
/* next time */
|
|
854
823
|
}
|
|
855
|
-
} else if (
|
|
856
|
-
|
|
857
|
-
const key = args[0] ?? '';
|
|
858
|
-
const res = key.startsWith('LC1.') ? activate(key) : await activatePolar(key);
|
|
859
|
-
console.log(res.ok ? `✓ limitcast Pro activated${res.claims.e ? ` for ${res.claims.e}` : ''}` : `✗ ${res.reason}`);
|
|
860
|
-
process.exit(res.ok ? 0 : 1);
|
|
861
|
-
} else if (cmd === 'deactivate') {
|
|
862
|
-
const res = await deactivatePolar();
|
|
863
|
-
console.log(res.ok ? '✓ This machine is deactivated; the key can be used on another computer.' : `✗ ${res.reason}`);
|
|
864
|
-
process.exit(res.ok ? 0 : 1);
|
|
865
|
-
} else if (cmd === 'license') {
|
|
866
|
-
const l = currentLicense();
|
|
867
|
-
console.log(l === null ? trialLine() : l.ok ? `Pro: ${l.claims.e}` : `License problem: ${l.reason}`);
|
|
868
|
-
} else if (cmd === 'trial') {
|
|
869
|
-
// Pro for 7 days on this machine, no card, once.
|
|
870
|
-
if (currentLicense()?.ok) {
|
|
871
|
-
console.log('You already have Pro.');
|
|
872
|
-
process.exit(0);
|
|
873
|
-
}
|
|
874
|
-
const t = startTrial(now);
|
|
875
|
-
if (!t.ok) {
|
|
876
|
-
console.log(t.active ? `Your Pro trial is already running, until ${clock(t.ends)}.` : trialLine());
|
|
877
|
-
process.exit(t.active ? 0 : 2);
|
|
878
|
-
}
|
|
879
|
-
console.log(
|
|
880
|
-
[
|
|
881
|
-
`✓ Pro trial on: 7 days, until ${new Date(t.ends).toLocaleDateString()}. No card, nothing to cancel.`,
|
|
882
|
-
'Try it:',
|
|
883
|
-
' limitcast install --guard --alerts block runaway subagents, move them to Sonnet when a window is tight',
|
|
884
|
-
' limitcast trim --apply cut the context you never use (limitcast trim --undo reverses it)',
|
|
885
|
-
' limitcast notify on a desktop notification before you hit a limit',
|
|
886
|
-
' limitcast results what it did for you, any time',
|
|
887
|
-
`Keep Pro after the trial: ${UPGRADE_URL}`,
|
|
888
|
-
].join('\n'),
|
|
889
|
-
);
|
|
824
|
+
} else if (['activate', 'deactivate', 'license', 'trial'].includes(cmd)) {
|
|
825
|
+
console.log('limitcast is free and open source under the MIT License. All features are available; no license key, account or trial is required.');
|
|
890
826
|
} else if (cmd === '--version' || cmd === '-v') {
|
|
891
827
|
console.log(VERSION);
|
|
892
828
|
} else {
|
|
@@ -894,7 +830,7 @@ if (cmd === 'status') {
|
|
|
894
830
|
process.exit(cmd && !['help', '--help', '-h'].includes(cmd) ? 1 : 0);
|
|
895
831
|
}
|
|
896
832
|
|
|
897
|
-
/** Everything `doctor` checks: setup, data freshness,
|
|
833
|
+
/** Everything `doctor` checks: setup, data freshness, and whether each tool's logs still parse. */
|
|
898
834
|
async function healthChecks() {
|
|
899
835
|
// Readings are only stored when they change, so freshness comes from the last feed the status line saw.
|
|
900
836
|
let latest = 0;
|
|
@@ -903,9 +839,7 @@ async function healthChecks() {
|
|
|
903
839
|
} catch {
|
|
904
840
|
/* never fed */
|
|
905
841
|
}
|
|
906
|
-
const
|
|
907
|
-
const checks = doctor({ samplesAgeMs: latest ? now - latest : null, license });
|
|
908
|
-
if (license === null && trialStatus(now)) checks.push({ ok: true, line: trialLine() });
|
|
842
|
+
const checks = doctor({ samplesAgeMs: latest ? now - latest : null });
|
|
909
843
|
return [...checks, ...(await formatChecks())];
|
|
910
844
|
}
|
|
911
845
|
|
|
@@ -926,53 +860,10 @@ function saveHealth(checks) {
|
|
|
926
860
|
mkdirSync(stateDir(), { recursive: true });
|
|
927
861
|
writeFileSync(file, JSON.stringify({ at: now, failed }));
|
|
928
862
|
const fresh = failed.filter((l) => !before.includes(l));
|
|
929
|
-
if (fresh.length &&
|
|
863
|
+
if (fresh.length && notifyEnabled()) send(`limitcast needs a fix: ${fresh[0]} Run: limitcast doctor`);
|
|
930
864
|
return failed;
|
|
931
865
|
}
|
|
932
866
|
|
|
933
|
-
/**
|
|
934
|
-
* Free installs: for one day a week, what the guard preview saw Pro would have done, e.g.
|
|
935
|
-
* "this week Pro would have stopped 2 subagents and moved 5 to Sonnet · limitcast trial". Silent when it's nothing.
|
|
936
|
-
* @param {number} t epoch ms
|
|
937
|
-
*/
|
|
938
|
-
function freeWeeklyHint(t) {
|
|
939
|
-
const file = join(stateDir(), 'free-weekly.json');
|
|
940
|
-
let from = 0;
|
|
941
|
-
try {
|
|
942
|
-
from = JSON.parse(readFileSync(file, 'utf8')).from ?? 0;
|
|
943
|
-
} catch {
|
|
944
|
-
/* first run: start the clock */
|
|
945
|
-
}
|
|
946
|
-
const WEEK = 7 * 86400_000;
|
|
947
|
-
if (!from || t >= from + 86400_000) {
|
|
948
|
-
// First run starts a week out; afterwards the next day-long showing is a week after this one.
|
|
949
|
-
from = from ? from + Math.ceil((t - from - 86400_000 + 1) / WEEK) * WEEK : t + WEEK;
|
|
950
|
-
mkdirSync(stateDir(), { recursive: true });
|
|
951
|
-
writeFileSync(file, JSON.stringify({ from }));
|
|
952
|
-
}
|
|
953
|
-
if (t < from) return null;
|
|
954
|
-
const preview = loadBlocks(t - WEEK).filter((b) => b.shadow);
|
|
955
|
-
const stopped = preview.filter((b) => !b.kind || b.kind === 'budget' || b.kind === 'today').length;
|
|
956
|
-
const moved = preview.filter((b) => b.kind === 'switch').length;
|
|
957
|
-
const cold = preview.filter((b) => b.kind === 'cold').length;
|
|
958
|
-
if (!stopped && !moved && !cold) return null;
|
|
959
|
-
const parts = [
|
|
960
|
-
stopped ? `stopped ${stopped} subagent${stopped === 1 ? '' : 's'}` : '',
|
|
961
|
-
moved ? `moved ${moved} to Sonnet` : '',
|
|
962
|
-
cold ? `caught ${cold} cold-cache message${cold === 1 ? '' : 's'}` : '',
|
|
963
|
-
].filter(Boolean);
|
|
964
|
-
return `this week Pro would have ${parts.join(' and ')} · limitcast trial`;
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
/** Free tier, a running trial, or an ended one, in one line. */
|
|
968
|
-
function trialLine() {
|
|
969
|
-
const t = trialStatus(now);
|
|
970
|
-
if (!t) return `Free tier. Try Pro free for 7 days, no card: limitcast trial. Buy: ${UPGRADE_URL}`;
|
|
971
|
-
if (t.active)
|
|
972
|
-
return `Pro trial: ${Math.ceil((t.ends - now) / 86400_000)} days left (until ${new Date(t.ends).toLocaleDateString()}). Keep Pro: ${UPGRADE_URL}`;
|
|
973
|
-
return `Pro trial ended ${new Date(t.ends).toLocaleDateString()}. Keep Pro: ${UPGRADE_URL}`;
|
|
974
|
-
}
|
|
975
|
-
|
|
976
867
|
/** The status-line hint while the last health check found something to fix. */
|
|
977
868
|
function healthHint() {
|
|
978
869
|
try {
|
|
@@ -1010,7 +901,7 @@ async function refreshValue() {
|
|
|
1010
901
|
const change = limitChange(v.calibHistory ?? []);
|
|
1011
902
|
if (change && (!v.limitChange || now - v.limitChange.at > 7 * 86400_000)) {
|
|
1012
903
|
v.limitChange = { ...change, at: now };
|
|
1013
|
-
if (
|
|
904
|
+
if (notifyEnabled()) send(limitChangeMessage(change));
|
|
1014
905
|
}
|
|
1015
906
|
saveValue(v);
|
|
1016
907
|
return v;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "limitcast",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Stretch your Claude Code plan: measure what every session loads before you type, cut what you never use, and stop runaway subagents before they burn your window.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"url": "git+https://github.com/SamStull9007/limitcast.git"
|
|
37
37
|
},
|
|
38
38
|
"author": "Sam Stull",
|
|
39
|
-
"license": "
|
|
39
|
+
"license": "MIT"
|
|
40
40
|
}
|