limitcast 0.9.1 → 0.9.2

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/README.md CHANGED
@@ -51,7 +51,7 @@ limitcast doctor
51
51
  |---|---|
52
52
  | `limitcast status [--json]` | Used, burn rate, runout time and reset for each window, and today's share of each weekly one. **Pro** also lists your other Claude accounts |
53
53
  | `limitcast trim --codex [--apply / --undo]` | Codex: AGENTS.md size and MCP servers in `~/.codex/config.toml` you haven't used. **Pro** names them and turns them off (`enabled = false`; `--undo` restores the file exactly) |
54
- | `limitcast notify on/off/test` | **Pro.** A desktop notification when a Claude window turns NEAR, AT_RISK or HIT, and when it resets after a HIT |
54
+ | `limitcast notify on/off/test` | **Pro.** A desktop notification when a Claude window turns NEAR, AT_RISK or HIT, and when it resets after a HIT. On macOS they come from a tiny limitcast notifier app, listed as "limitcast" in System Settings → Notifications |
55
55
  | `limitcast after-reset [--src claude/codex] [--window 5h/7d] [--detach] -- <cmd>` | **Pro.** Wait for the window to reset, then run the command |
56
56
  | `limitcast results --html [--out FILE]` | **Pro.** Results, current windows and the burn report on one page, opened in your browser |
57
57
  | `limitcast install [--guard] [--alerts]` / `uninstall` | Wire into Claude Code / restore your settings |
package/bin/limitcast.mjs CHANGED
@@ -23,7 +23,7 @@ import { accountForecasts, compactHint, headroom, lastCallTokens } from '../src/
23
23
  import { htmlPage } from '../src/html.mjs';
24
24
  import { doctor, install, readSettings, settingsPath, uninstall } from '../src/install.mjs';
25
25
  import { activate, currentLicense, isPro, UPGRADE_URL } from '../src/license.mjs';
26
- import { notifyChanges, notifyEnabled, send, setNotify } from '../src/notify.mjs';
26
+ import { buildNotifierApp, notifierApp, notifyChanges, notifyEnabled, send, setNotify } from '../src/notify.mjs';
27
27
  import { driftMessage, loadOverhead, recordOverhead, savedPerSession, savedSummary, snapshot } from '../src/overhead.mjs';
28
28
  import { activatePolar, deactivatePolar, refreshDue, refreshPolar } from '../src/polar.mjs';
29
29
  import { burnReport } from '../src/report.mjs';
@@ -362,12 +362,22 @@ if (cmd === 'status') {
362
362
  }
363
363
  const what = args[0];
364
364
  if (what === 'on' || what === 'off') setNotify(what === 'on');
365
- if (what === 'test') send('limitcast notifications work.');
365
+ // macOS: limitcast's own notifier app, so it shows up as "limitcast" in System Settings → Notifications.
366
+ const mac = process.platform === 'darwin';
367
+ const app = mac && (what === 'on' || what === 'test') && !existsSync(notifierApp()) ? buildNotifierApp() : mac && existsSync(notifierApp());
368
+ if (mac && (what === 'on' || what === 'test') && !app) console.log('Could not build the notifier app; falling back to osascript.');
369
+ if (what === 'on' || what === 'test') send('limitcast notifications work.');
366
370
  console.log(
367
- what === 'test'
368
- ? 'Sent a test notification. Nothing showed up? Allow notifications for Script Editor (macOS) or install notify-send (Linux).'
369
- : `Notifications are ${notifyEnabled() ? 'on: you get one when a Claude window turns NEAR, AT_RISK or HIT, and when it resets after a HIT' : 'off'}. (limitcast notify on|off|test)`,
371
+ what === 'test' || what === 'on'
372
+ ? mac
373
+ ? 'Sent a test notification. The first one asks to allow notifications from "limitcast"; if you missed it, turn it on in System Settings → Notifications → limitcast.'
374
+ : 'Sent a test notification. Nothing showed up? Install notify-send.'
375
+ : '',
370
376
  );
377
+ if (what !== 'test')
378
+ console.log(
379
+ `Notifications are ${notifyEnabled() ? 'on: you get one when a Claude window turns NEAR, AT_RISK or HIT, and when it resets after a HIT' : 'off'}. (limitcast notify on|off|test)`,
380
+ );
371
381
  } else if (cmd === 'after-reset') {
372
382
  // Run a command once a window has reset: queue the heavy job instead of watching the clock.
373
383
  if (!isPro()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "limitcast",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
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": { "limitcast": "bin/limitcast.mjs" },
package/src/notify.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // @ts-check
2
- import { spawn } from 'node:child_process';
3
- import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { spawn, spawnSync } from 'node:child_process';
3
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
4
4
  import { join } from 'node:path';
5
5
  import { stateDir } from './store.mjs';
6
6
 
@@ -74,15 +74,71 @@ export function notifyChanges(rows, clock) {
74
74
  }
75
75
 
76
76
  /**
77
- * Show a desktop notification: macOS through osascript, Linux through notify-send. Fire and forget.
77
+ * Show a desktop notification. macOS: through limitcast's own notifier app, so it is listed as "limitcast" in
78
+ * System Settings → Notifications (osascript's notifications are attributed to Script Editor, which may not be
79
+ * listed at all). Linux: notify-send. Fire and forget.
78
80
  * @param {string} message
79
81
  */
80
82
  export function send(message) {
81
- const [cmd, args] =
82
- process.platform === 'darwin'
83
- ? ['osascript', ['-e', `display notification ${JSON.stringify(message)} with title "limitcast"`]]
84
- : ['notify-send', ['limitcast', message]];
83
+ if (process.platform === 'darwin' && existsSync(notifierApp())) {
84
+ appendFileSync(queueFile(), `${message.replace(/\n/g, ' ')}\n`);
85
+ run('open', ['-g', '-a', notifierApp()]);
86
+ return;
87
+ }
88
+ if (process.platform === 'darwin') run('osascript', ['-e', `display notification ${JSON.stringify(message)} with title "limitcast"`]);
89
+ else run('notify-send', ['limitcast', message]);
90
+ }
91
+
92
+ /** @param {string} cmd @param {string[]} args */
93
+ function run(cmd, args) {
85
94
  const child = spawn(cmd, args, { detached: true, stdio: 'ignore' });
86
95
  child.on('error', () => {}); // no notifier installed: nothing to do
87
96
  child.unref();
88
97
  }
98
+
99
+ export const notifierApp = () => join(stateDir(), 'limitcast.app');
100
+ const queueFile = () => join(stateDir(), 'notify-queue.txt');
101
+
102
+ /**
103
+ * Build the macOS notifier: a tiny AppleScript app (bundle id dev.limitcast.notifier, no Dock icon) that shows
104
+ * every queued message and exits. Built with the tools macOS ships (osacompile, plutil, codesign); ad-hoc signed.
105
+ * @returns {boolean} whether the app is ready
106
+ */
107
+ export function buildNotifierApp() {
108
+ if (process.platform !== 'darwin') return false;
109
+ mkdirSync(stateDir(), { recursive: true });
110
+ const app = notifierApp();
111
+ const src = join(stateDir(), 'notifier.applescript');
112
+ const q = queueFile().replace(/\\/g, '\\\\').replace(/"/g, '\\"');
113
+ writeFileSync(
114
+ src,
115
+ [
116
+ 'on run',
117
+ `\tset q to "${q}"`,
118
+ '\ttry',
119
+ `\t\tset msgs to do shell script "f=" & quoted form of q & "; if [ -f \\"$f\\" ]; then cat \\"$f\\"; rm -f \\"$f\\"; fi"`,
120
+ '\ton error',
121
+ '\t\treturn',
122
+ '\tend try',
123
+ '\trepeat with m in paragraphs of msgs',
124
+ '\t\tif (length of (m as text)) > 0 then display notification (m as text) with title "limitcast"',
125
+ '\tend repeat',
126
+ '\tdelay 2', // let Notification Center take the messages before the app exits
127
+ 'end run',
128
+ '',
129
+ ].join('\n'),
130
+ );
131
+ rmSync(app, { recursive: true, force: true });
132
+ const plist = join(app, 'Contents', 'Info.plist');
133
+ const steps = [
134
+ ['osacompile', ['-o', app, src]],
135
+ ['plutil', ['-replace', 'CFBundleIdentifier', '-string', 'dev.limitcast.notifier', plist]],
136
+ ['plutil', ['-replace', 'CFBundleName', '-string', 'limitcast', plist]],
137
+ ['plutil', ['-replace', 'LSUIElement', '-bool', 'true', plist]],
138
+ ['codesign', ['--force', '--sign', '-', app]],
139
+ ];
140
+ for (const [cmd, args] of /** @type {[string, string[]][]} */ (steps)) {
141
+ if (spawnSync(cmd, args, { stdio: 'ignore' }).status !== 0) return false;
142
+ }
143
+ return existsSync(app);
144
+ }