sprag-cli 3.93.0 → 3.95.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 +2 -2
- package/package.json +1 -1
- package/src/commands/saved.js +34 -7
- package/src/monthly-reset-offer.js +40 -19
- package/src/saved-reset.cjs +6 -4
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] [--month-start] | 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.
|
|
3
|
+
"version": "3.95.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": {
|
package/src/commands/saved.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* sprag saved # totals since the last reset
|
|
5
5
|
* sprag saved reset [routing|doc2md|all] # start counting from now
|
|
6
|
+
* --month-start # or from the 1st of this month, 00:00 local
|
|
6
7
|
* sprag saved undo # put the previous counters back
|
|
8
|
+
* sprag saved keep # decline this month's reset offer
|
|
7
9
|
* (add --agent codex for the Codex counters: codex-routing, codex-docs)
|
|
8
10
|
*
|
|
9
11
|
* Nothing is deleted. A reset only records a timestamp, and the totals count
|
|
@@ -165,7 +167,7 @@ export async function run({ args, hasFlag, agent = 'claude', dir: dirArg, rescan
|
|
|
165
167
|
}
|
|
166
168
|
|
|
167
169
|
if (sub === 'reset') {
|
|
168
|
-
const arg = args
|
|
170
|
+
const arg = args.slice(2).find((a) => !a.startsWith('-')) || 'all';
|
|
169
171
|
const base = agent === 'codex' ? { routing: 'codex-routing', doc2md: 'codex-docs' } : { routing: 'routing', doc2md: 'doc2md' };
|
|
170
172
|
let targets;
|
|
171
173
|
if (arg === 'all') targets = scopes;
|
|
@@ -177,13 +179,27 @@ export async function run({ args, hasFlag, agent = 'claude', dir: dirArg, rescan
|
|
|
177
179
|
: `Unknown scope: ${arg}. Valid scopes are ${scopes.join(', ')}, all.`);
|
|
178
180
|
process.exit(1);
|
|
179
181
|
}
|
|
182
|
+
// --month-start dates the mark to the 1st, 00:00 local, rather than now: the
|
|
183
|
+
// monthly offer is usually answered a day or more into the month (the 1st
|
|
184
|
+
// fell on a Sunday in 2026-11), and a mark at "now" would drop those days.
|
|
185
|
+
const now = Date.now();
|
|
186
|
+
const today = new Date(now);
|
|
187
|
+
const fromMonthStart = hasFlag('--month-start');
|
|
188
|
+
const mark = fromMonthStart ? new Date(today.getFullYear(), today.getMonth(), 1).getTime() : now;
|
|
180
189
|
const before = {};
|
|
181
190
|
for (const s of targets) before[s] = await currentTotals(s, dir);
|
|
182
|
-
resetSaved(targets, { dir });
|
|
191
|
+
resetSaved(targets, { dir, now, mark });
|
|
183
192
|
for (const s of targets) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
193
|
+
if (fromMonthStart) {
|
|
194
|
+
const after = await currentTotals(s, dir);
|
|
195
|
+
console.log(ko
|
|
196
|
+
? `${label(s)} 카운터를 ${today.getMonth() + 1}월 1일 0시부터 다시 셉니다. 이번 달 합계는 ${fmtTotal(after)}이고 이전 합계는 ${fmtTotal(before[s])}입니다.`
|
|
197
|
+
: `The ${label(s)} counter now counts from ${today.getMonth() + 1}/1 00:00. This month so far: ${fmtTotal(after)}. The previous total was ${fmtTotal(before[s])}.`);
|
|
198
|
+
} else {
|
|
199
|
+
console.log(ko
|
|
200
|
+
? `${label(s)} 카운터를 0으로 초기화했습니다. 이전 합계는 ${fmtTotal(before[s])}입니다.`
|
|
201
|
+
: `Reset the ${label(s)} counter to zero. The previous total was ${fmtTotal(before[s])}.`);
|
|
202
|
+
}
|
|
187
203
|
}
|
|
188
204
|
console.log(ko
|
|
189
205
|
? `원장 기록은 지우지 않았습니다. \`sprag saved undo${suffix}\`로 되돌릴 수 있습니다.`
|
|
@@ -194,6 +210,17 @@ export async function run({ args, hasFlag, agent = 'claude', dir: dirArg, rescan
|
|
|
194
210
|
return;
|
|
195
211
|
}
|
|
196
212
|
|
|
213
|
+
// The "no" answer to the session-start reset offer (src/monthly-reset-offer.js).
|
|
214
|
+
// Without it the offer comes back at every fresh session this month.
|
|
215
|
+
if (sub === 'keep') {
|
|
216
|
+
const { declineMonthlyReset } = await import('../monthly-reset-offer.js');
|
|
217
|
+
const month = declineMonthlyReset({ dir });
|
|
218
|
+
console.log(ko
|
|
219
|
+
? `${month} 에는 초기화 안내를 더 띄우지 않습니다. 카운터는 그대로 이어서 셉니다.`
|
|
220
|
+
: `No more reset offers for ${month}. The counters keep running.`);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
197
224
|
if (sub === 'undo') {
|
|
198
225
|
const undone = undoReset({ dir });
|
|
199
226
|
if (!undone) {
|
|
@@ -214,7 +241,7 @@ export async function run({ args, hasFlag, agent = 'claude', dir: dirArg, rescan
|
|
|
214
241
|
}
|
|
215
242
|
|
|
216
243
|
console.error(ko
|
|
217
|
-
? `알 수 없는 하위 명령입니다: ${sub}. 사용법은 sprag saved [reset|undo] 입니다.`
|
|
218
|
-
: `Unknown subcommand: ${sub}. Usage: sprag saved [reset|undo].`);
|
|
244
|
+
? `알 수 없는 하위 명령입니다: ${sub}. 사용법은 sprag saved [reset|undo|keep] 입니다.`
|
|
245
|
+
: `Unknown subcommand: ${sub}. Usage: sprag saved [reset|undo|keep].`);
|
|
219
246
|
process.exit(1);
|
|
220
247
|
}
|
|
@@ -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
|
|
10
|
-
*
|
|
9
|
+
* seed offers: a statusline cannot open a dialog. The offer repeats at every
|
|
10
|
+
* fresh session until the user answers: yes runs
|
|
11
|
+
* `sprag saved reset all --month-start`, whose mark (the 1st, 00:00) silences
|
|
12
|
+
* it; no runs `sprag saved keep`, which records the month as 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
|
|
39
|
-
*
|
|
40
|
-
*
|
|
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
|
-
//
|
|
62
|
-
|
|
63
|
-
const state = readState(
|
|
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
|
|
67
|
-
//
|
|
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
|
|
|
@@ -89,21 +98,33 @@ export function monthlyResetOffer({ dir = userDataDir(), now = Date.now(), lang
|
|
|
89
98
|
const block = ko
|
|
90
99
|
? [
|
|
91
100
|
`✇ [sprag monthly-reset] ${today.getMonth() + 1}월 1일 이후 절감 집계를 초기화한 적이 없습니다. 지금 보이는 값은 ${sinceText} 누적입니다: 라우팅 절감 ${formatMoney(routingOk)}, Doc2md 절감 ${formatMoney(docOk)}.`,
|
|
92
|
-
'이번 달 기준으로 새로 보려면 초기화를 권장합니다. 초기화하면 라우팅 절감과 Doc2md 절감, Model used
|
|
93
|
-
'사용자에게 위 내용을 알리고 초기화할지 물어보십시오.
|
|
94
|
-
' sprag saved reset all',
|
|
101
|
+
'이번 달 기준으로 새로 보려면 초기화를 권장합니다. 초기화하면 라우팅 절감과 Doc2md 절감, Model used 비율을 이번 달 1일 0시부터 다시 집계합니다. 기록은 지워지지 않고 `sprag saved undo` 로 되돌릴 수 있습니다.',
|
|
102
|
+
'사용자에게 위 내용을 알리고 초기화할지 물어보십시오. 승낙하면 첫째 명령을, 거절하면 둘째 명령을 실행하십시오. 둘 중 하나를 실행하기 전에는 새 세션을 열 때마다 이 안내가 다시 나옵니다. 거절하면 이번 달에는 더 묻지 않습니다.',
|
|
103
|
+
' sprag saved reset all --month-start',
|
|
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
|
-
'A reset is recommended to see this month on its own. It
|
|
99
|
-
'Tell the user this and ask whether to reset.
|
|
100
|
-
' sprag saved reset all',
|
|
108
|
+
'A reset is recommended to see this month on its own. It recounts routing savings, Doc2md savings and the Model used share from the 1st of this month, 00:00. Nothing is deleted, and `sprag saved undo` puts it back.',
|
|
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.',
|
|
110
|
+
' sprag saved reset all --month-start',
|
|
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
|
+
}
|
package/src/saved-reset.cjs
CHANGED
|
@@ -72,17 +72,19 @@ function readResetMarks(dir) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
|
-
* Reset the given scopes to `now
|
|
76
|
-
* ignored; the caller validates user input.
|
|
75
|
+
* Reset the given scopes to `mark` (default `now`). Returns the new marks.
|
|
76
|
+
* Unknown scopes are ignored; the caller validates user input. `mark` may lie
|
|
77
|
+
* before `now`: `sprag saved reset --month-start` dates it to the 1st so a
|
|
78
|
+
* reset made on the 2nd still counts the whole month.
|
|
77
79
|
*/
|
|
78
|
-
function resetSaved(scopes, { dir, now = Date.now() } = {}) {
|
|
80
|
+
function resetSaved(scopes, { dir, now = Date.now(), mark = now } = {}) {
|
|
79
81
|
const state = readState(dir);
|
|
80
82
|
const valid = [...new Set(scopes)].filter((s) => SCOPES.includes(s));
|
|
81
83
|
if (valid.length === 0) return state.marks;
|
|
82
84
|
const prev = {};
|
|
83
85
|
for (const s of valid) {
|
|
84
86
|
prev[s] = state.marks[s];
|
|
85
|
-
state.marks[s] =
|
|
87
|
+
state.marks[s] = mark;
|
|
86
88
|
}
|
|
87
89
|
state.history.push({ at: now, scopes: valid, prev });
|
|
88
90
|
if (state.history.length > MAX_HISTORY) state.history.splice(0, state.history.length - MAX_HISTORY);
|