claude-usage-limits 1.11.7 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -144,13 +144,14 @@ function planOn(settings, state, options) {
144
144
  const opts = options || {};
145
145
  const launcher = opts.launcher || launcherFile();
146
146
  const existing = current.statusLine === undefined ? null : current.statusLine;
147
- // A second "on" must not record our own launcher as the thing to restore.
148
- const previous =
149
- state && Object.prototype.hasOwnProperty.call(state, 'previous')
150
- ? state.previous
151
- : isOurs(existing, launcher)
152
- ? null
153
- : existing;
147
+ // What "off" must put back is whatever is in the settings right now that is
148
+ // not ours. A second "on" must not record our own launcher as that thing -
149
+ // but it must not keep an old memory either: a status line the user set
150
+ // between two "on" runs was being overwritten and lost, because the first
151
+ // run's record was trusted over the file in front of us.
152
+ const remembered =
153
+ state && Object.prototype.hasOwnProperty.call(state, 'previous') ? state.previous : null;
154
+ const previous = isOurs(existing, launcher) ? remembered : existing;
154
155
  const command = 'node ' + JSON.stringify(launcher);
155
156
  const statusLine = { type: 'command', command };
156
157
  if (Number.isFinite(opts.refresh) && opts.refresh >= 1) statusLine.refreshInterval = Math.floor(opts.refresh);
@@ -46,15 +46,14 @@ function readState() {
46
46
  }
47
47
  }
48
48
 
49
+ // Atomic, because this file is read, changed and written back by the Stop hook
50
+ // of every session at once. A torn read here did not just lose one total: the
51
+ // reader parsed nothing, then wrote its own slot back as the whole file, and
52
+ // every other session's tally went with it.
49
53
  function writeState(all) {
50
- try {
51
- const file = stateFile();
52
- fs.mkdirSync(path.dirname(file), { recursive: true });
53
- fs.writeFileSync(file, JSON.stringify(all), 'utf8');
54
- } catch (err) {
55
- // Losing the total costs one re-read of the transcript. Failing the hook
56
- // that runs after every reply is not worth avoiding that.
57
- }
54
+ // Never throws: losing the total costs one re-read of the transcript, and
55
+ // failing the hook that runs after every reply is not worth avoiding that.
56
+ usage.writeJsonAtomic(stateFile(), all);
58
57
  }
59
58
 
60
59
  function isSession(value) {