sprag-cli 3.93.0 → 3.94.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/bin/cli.js CHANGED
@@ -217,7 +217,7 @@ Usage:
217
217
  sprag doc2md on|off|<file> convert documents to Markdown before the model reads them
218
218
  sprag delegate on|off|status add bounds and context to Task/Agent delegation prompts
219
219
  sprag compact-window audit or pin autoCompactWindow for 1M sessions
220
- sprag saved [reset|undo] show, reset or restore the saved-money counters (--agent codex for Codex)
220
+ sprag saved [reset|undo|keep] show, reset or restore the saved-money counters (--agent codex for Codex)
221
221
  sprag litellm-budget LiteLLM gateway key budget and spend
222
222
  sprag oauth-budget claude.ai usage-credit budget (Enterprise)
223
223
  sprag update-check is a newer version out?
@@ -428,7 +428,7 @@ async function main() {
428
428
  }
429
429
 
430
430
  // Subcommand: saved — stopwatch reset for the lifetime "saved" counters.
431
- // sprag saved | saved reset [routing|doc2md|all] | saved undo
431
+ // sprag saved | saved reset [routing|doc2md|all] | saved undo | saved keep
432
432
  if (args[0] === 'saved') {
433
433
  return (await import('../src/commands/saved.js')).run({ args, hasFlag });
434
434
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprag-cli",
3
- "version": "3.93.0",
3
+ "version": "3.94.0",
4
4
  "description": "Model-delegation router for Claude Code and Codex: lookups, checks and test runs go to cheaper models, documents go in as compact Markdown, and a live statusline shows spend and savings.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -4,6 +4,7 @@
4
4
  * sprag saved # totals since the last reset
5
5
  * sprag saved reset [routing|doc2md|all] # start counting from now
6
6
  * sprag saved undo # put the previous counters back
7
+ * sprag saved keep # decline this month's reset offer
7
8
  * (add --agent codex for the Codex counters: codex-routing, codex-docs)
8
9
  *
9
10
  * Nothing is deleted. A reset only records a timestamp, and the totals count
@@ -194,6 +195,17 @@ export async function run({ args, hasFlag, agent = 'claude', dir: dirArg, rescan
194
195
  return;
195
196
  }
196
197
 
198
+ // The "no" answer to the session-start reset offer (src/monthly-reset-offer.js).
199
+ // Without it the offer comes back at every fresh session this month.
200
+ if (sub === 'keep') {
201
+ const { declineMonthlyReset } = await import('../monthly-reset-offer.js');
202
+ const month = declineMonthlyReset({ dir });
203
+ console.log(ko
204
+ ? `${month} 에는 초기화 안내를 더 띄우지 않습니다. 카운터는 그대로 이어서 셉니다.`
205
+ : `No more reset offers for ${month}. The counters keep running.`);
206
+ return;
207
+ }
208
+
197
209
  if (sub === 'undo') {
198
210
  const undone = undoReset({ dir });
199
211
  if (!undone) {
@@ -214,7 +226,7 @@ export async function run({ args, hasFlag, agent = 'claude', dir: dirArg, rescan
214
226
  }
215
227
 
216
228
  console.error(ko
217
- ? `알 수 없는 하위 명령입니다: ${sub}. 사용법은 sprag saved [reset|undo] 입니다.`
218
- : `Unknown subcommand: ${sub}. Usage: sprag saved [reset|undo].`);
229
+ ? `알 수 없는 하위 명령입니다: ${sub}. 사용법은 sprag saved [reset|undo|keep] 입니다.`
230
+ : `Unknown subcommand: ${sub}. Usage: sprag saved [reset|undo|keep].`);
219
231
  process.exit(1);
220
232
  }
@@ -6,8 +6,12 @@
6
6
  * anything about the current month.
7
7
  *
8
8
  * The asking happens at session start for the same reason as the upgrade and
9
- * seed offers: a statusline cannot open a dialog. The state file makes it once
10
- * per calendar month, answered or not, so a declined offer never nags.
9
+ * seed offers: a statusline cannot open a dialog. The offer repeats at every
10
+ * fresh session until the user answers: yes runs `sprag saved reset all`, whose
11
+ * mark silences it; no runs `sprag saved keep`, which records the month as
12
+ * declined. Printing alone records nothing, because a session where nobody
13
+ * read the offer must not count as an answer (2026-11-01: a batch job got
14
+ * November's only ask under the old once-per-month rule).
11
15
  */
12
16
 
13
17
  import { readFileSync } from 'node:fs';
@@ -35,11 +39,16 @@ function readState(file) {
35
39
  /**
36
40
  * Whether a SessionStart with this `source` may carry the offer: a fresh
37
41
  * session only. The hook also fires on resume, clear and compact, and an offer
38
- * right after an auto-compact would interrupt work in progress and use up the
39
- * month's one ask there. A payload without `source` (older Claude Code, or a
40
- * manual run) counts as a fresh start.
42
+ * right after an auto-compact would interrupt work in progress. A payload
43
+ * without `source` (older Claude Code, or a manual run) counts as a fresh start.
44
+ *
45
+ * SDK sessions (`claude -p`, Agent SDK; CLAUDE_CODE_ENTRYPOINT `sdk-*`) are
46
+ * skipped too. They are mostly unattended batch jobs, so nobody would answer,
47
+ * and an offer that repeats until answered would ride every run and could leak
48
+ * a question into output a script parses.
41
49
  */
42
- export function offersOnSessionSource(source) {
50
+ export function offersOnSessionSource(source, entrypoint = process.env.CLAUDE_CODE_ENTRYPOINT) {
51
+ if (typeof entrypoint === 'string' && entrypoint.startsWith('sdk')) return false;
43
52
  return !source || source === 'startup';
44
53
  }
45
54
 
@@ -58,13 +67,13 @@ export function monthlyResetOffer({ dir = userDataDir(), now = Date.now(), lang
58
67
  const monthStart = new Date(today.getFullYear(), today.getMonth(), 1).getTime();
59
68
  const monthKey = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}`;
60
69
 
61
- // Already offered this month: never ask twice, whatever the answer was.
62
- const file = monthlyResetStatePath(dir);
63
- const state = readState(file);
64
- if (state && state.month === monthKey) return null;
70
+ // Declined this month: stay quiet until the next one. A state file from
71
+ // v3.91 to v3.93 holds only `offeredAt`, which was never an answer.
72
+ const state = readState(monthlyResetStatePath(dir));
73
+ if (state && state.month === monthKey && Number.isFinite(state.declinedAt)) return null;
65
74
 
66
- // Reset since the 1st: nothing to recommend, and no state written so a
67
- // later `undo` that brings the old mark back can still trigger the offer.
75
+ // Reset since the 1st: nothing to recommend. A later `undo` that brings the
76
+ // old mark back makes the offer due again.
68
77
  const marks = readResetMarks(dir);
69
78
  if (Number.isFinite(marks.routing) && marks.routing >= monthStart) return null;
70
79
 
@@ -90,20 +99,32 @@ export function monthlyResetOffer({ dir = userDataDir(), now = Date.now(), lang
90
99
  ? [
91
100
  `✇ [sprag monthly-reset] ${today.getMonth() + 1}월 1일 이후 절감 집계를 초기화한 적이 없습니다. 지금 보이는 값은 ${sinceText} 누적입니다: 라우팅 절감 ${formatMoney(routingOk)}, Doc2md 절감 ${formatMoney(docOk)}.`,
92
101
  '이번 달 기준으로 새로 보려면 초기화를 권장합니다. 초기화하면 라우팅 절감과 Doc2md 절감, Model used 비율이 지금부터 다시 집계됩니다. 기록은 지워지지 않고 `sprag saved undo` 로 되돌릴 수 있습니다.',
93
- '사용자에게 위 내용을 알리고 초기화할지 물어보십시오. 승낙한 경우에만 아래 명령을 실행하십시오. 거절하면 아무것도 실행하지 않으며, 이번 달에는 다시 묻지 않습니다.',
102
+ '사용자에게 위 내용을 알리고 초기화할지 물어보십시오. 승낙하면 첫째 명령을, 거절하면 둘째 명령을 실행하십시오. 둘 중 하나를 실행하기 전에는 새 세션을 열 때마다 이 안내가 다시 나옵니다. 거절하면 이번 달에는 더 묻지 않습니다.',
94
103
  ' sprag saved reset all',
104
+ ' sprag saved keep',
95
105
  ]
96
106
  : [
97
107
  `✇ [sprag monthly-reset] The saved counters have not been reset since ${MONTH_NAMES[today.getMonth()]} 1. The figures shown are cumulative ${sinceText}: routing saved ${formatMoney(routingOk)}, Doc2md saved ${formatMoney(docOk)}.`,
98
108
  'A reset is recommended to see this month on its own. It restarts routing savings, Doc2md savings and the Model used share from now. Nothing is deleted, and `sprag saved undo` puts it back.',
99
- 'Tell the user this and ask whether to reset. Run the command below only if they agree. If they decline, run nothing; this month they will not be asked again.',
109
+ 'Tell the user this and ask whether to reset. If they agree, run the first command; if they decline, run the second. Until one of them runs, this offer comes back at every new session. A decline keeps it quiet for the rest of the month.',
100
110
  ' sprag saved reset all',
111
+ ' sprag saved keep',
101
112
  ];
102
113
 
103
- writeStateFile(file, `${JSON.stringify({ version: 1, month: monthKey, offeredAt: now }, null, 2)}\n`);
104
114
  return block.join('\n');
105
115
  } catch (e) {
106
116
  debug('monthly-reset-offer', e);
107
117
  return null;
108
118
  }
109
119
  }
120
+
121
+ /**
122
+ * Record the user's "no" for the current calendar month (`sprag saved keep`).
123
+ * @returns {string} the month key, e.g. '2026-11'
124
+ */
125
+ export function declineMonthlyReset({ dir = userDataDir(), now = Date.now() } = {}) {
126
+ const today = new Date(now);
127
+ const monthKey = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}`;
128
+ writeStateFile(monthlyResetStatePath(dir), `${JSON.stringify({ version: 2, month: monthKey, declinedAt: now }, null, 2)}\n`);
129
+ return monthKey;
130
+ }