sprag-cli 3.80.2 → 3.81.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/package.json +1 -1
- package/src/commands/feedback.js +2 -0
- package/src/system-ca.js +81 -0
- package/src/team-sync.js +3 -0
- package/src/update-check.js +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sprag-cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.81.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/feedback.js
CHANGED
|
@@ -24,6 +24,7 @@ import { writeFileSync, mkdirSync } from 'node:fs';
|
|
|
24
24
|
import { join } from 'node:path';
|
|
25
25
|
import os from 'node:os';
|
|
26
26
|
import { debug } from '../debug.js';
|
|
27
|
+
import { trustSystemCA } from '../system-ca.js';
|
|
27
28
|
|
|
28
29
|
const REPO = 'rootstudioyaml/sprag';
|
|
29
30
|
const ISSUES_URL = `https://github.com/${REPO}/issues`;
|
|
@@ -64,6 +65,7 @@ function tryGhCli(title, body) {
|
|
|
64
65
|
|
|
65
66
|
async function tryForm(title, body, meta) {
|
|
66
67
|
if (!FORM) return null;
|
|
68
|
+
trustSystemCA();
|
|
67
69
|
try {
|
|
68
70
|
const params = new URLSearchParams();
|
|
69
71
|
params.set(FORM.message, `${title}\n\n${body}`);
|
package/src/system-ca.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trust the operating system's certificate store for Sprag's own requests.
|
|
3
|
+
*
|
|
4
|
+
* Node verifies TLS against the Mozilla bundle compiled into it, plus
|
|
5
|
+
* NODE_EXTRA_CA_CERTS. A machine behind a corporate proxy that re-signs
|
|
6
|
+
* traffic with a root installed only in the macOS Keychain, the Windows
|
|
7
|
+
* store or /etc/ssl fails every fetch with UNABLE_TO_GET_ISSUER_CERT_LOCALLY,
|
|
8
|
+
* and the update check, preset sync and team sync go quiet.
|
|
9
|
+
*
|
|
10
|
+
* Node 22.19 and 24.5 carry both tls.getCACertificates('system') and
|
|
11
|
+
* tls.setDefaultCACertificates(). With both present, the default
|
|
12
|
+
* list becomes its current entries (bundled, extra, anything set before) plus
|
|
13
|
+
* the system store, so nothing that verified before stops verifying. Older
|
|
14
|
+
* Node has neither and keeps its old behaviour.
|
|
15
|
+
*
|
|
16
|
+
* Reading the system store costs about 30ms on macOS (a Keychain query), so
|
|
17
|
+
* this runs once, right before the first request, and never on the
|
|
18
|
+
* statusline render path. Each fetch site calls trustSystemCA() first.
|
|
19
|
+
*
|
|
20
|
+
* SPRAG_SYSTEM_CA=0 turns it off. NODE_USE_SYSTEM_CA=1 or --use-system-ca
|
|
21
|
+
* means Node already merged the store, so nothing is read again.
|
|
22
|
+
*/
|
|
23
|
+
import { createRequire } from 'node:module';
|
|
24
|
+
import { envVar } from './env.js';
|
|
25
|
+
import { debug } from './debug.js';
|
|
26
|
+
|
|
27
|
+
// node:tls loads on first use: the update check imports this module on the
|
|
28
|
+
// statusline path, which never makes a request.
|
|
29
|
+
const require = createRequire(import.meta.url);
|
|
30
|
+
|
|
31
|
+
/** True when Node itself was told to load the system store at startup. */
|
|
32
|
+
export function nodeLoadsSystemCA({ env = process.env, execArgv = process.execArgv } = {}) {
|
|
33
|
+
if (env.NODE_USE_SYSTEM_CA === '1') return true;
|
|
34
|
+
if (execArgv.includes('--use-system-ca')) return true;
|
|
35
|
+
return /(^|\s)--use-system-ca(\s|$)/.test(env.NODE_OPTIONS || '');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const key = (pem) => String(pem).replace(/\r\n/g, '\n').trim();
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Merge the system store into the default CA list once.
|
|
42
|
+
*
|
|
43
|
+
* Returns what happened, for tests:
|
|
44
|
+
* 'applied' the default list now includes system roots it lacked
|
|
45
|
+
* 'unchanged' every system root was already in the default list
|
|
46
|
+
* 'off' SPRAG_SYSTEM_CA=0
|
|
47
|
+
* 'native' Node loaded the store itself (NODE_USE_SYSTEM_CA, --use-system-ca)
|
|
48
|
+
* 'unsupported' this Node lacks getCACertificates or setDefaultCACertificates
|
|
49
|
+
* 'error' reading or setting threw; the default list is left as it was
|
|
50
|
+
*/
|
|
51
|
+
export function applySystemCA({ tls = require('node:tls'), env = process.env, execArgv = process.execArgv } = {}) {
|
|
52
|
+
if (envVar('SYSTEM_CA', env) === '0') return 'off';
|
|
53
|
+
if (nodeLoadsSystemCA({ env, execArgv })) return 'native';
|
|
54
|
+
if (typeof tls.getCACertificates !== 'function' || typeof tls.setDefaultCACertificates !== 'function') {
|
|
55
|
+
return 'unsupported';
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const current = tls.getCACertificates('default');
|
|
59
|
+
const seen = new Set(current.map(key));
|
|
60
|
+
const added = tls.getCACertificates('system').filter((pem) => {
|
|
61
|
+
const k = key(pem);
|
|
62
|
+
if (seen.has(k)) return false;
|
|
63
|
+
seen.add(k);
|
|
64
|
+
return true;
|
|
65
|
+
});
|
|
66
|
+
if (added.length === 0) return 'unchanged';
|
|
67
|
+
tls.setDefaultCACertificates([...current, ...added]);
|
|
68
|
+
return 'applied';
|
|
69
|
+
} catch (e) {
|
|
70
|
+
debug('system-ca', e);
|
|
71
|
+
return 'error';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let outcome = null;
|
|
76
|
+
|
|
77
|
+
/** applySystemCA() for the process, at most once; later calls return the first outcome. */
|
|
78
|
+
export function trustSystemCA(opts) {
|
|
79
|
+
if (outcome === null) outcome = applySystemCA(opts);
|
|
80
|
+
return outcome;
|
|
81
|
+
}
|
package/src/team-sync.js
CHANGED
|
@@ -31,6 +31,7 @@ import { writeStateFile } from './state-file.js';
|
|
|
31
31
|
import { memberId, readMemberId } from './member-id.js';
|
|
32
32
|
import { userLanguage } from './config.js';
|
|
33
33
|
import { debug } from './debug.js';
|
|
34
|
+
import { trustSystemCA } from './system-ca.js';
|
|
34
35
|
import { loadLedger, modelFamily, roundUsd } from './savings-ledger.js';
|
|
35
36
|
import { sessionCost, pricedParts } from './claude-price.js';
|
|
36
37
|
import { uploadPrompts, dropOffsets, promptOffsetsExist } from './team-prompts.js';
|
|
@@ -194,6 +195,7 @@ async function ledgerUpsert({ memberKey, rows, version, dir, fetch }) {
|
|
|
194
195
|
export async function rpc(fn, params, {
|
|
195
196
|
fetch = globalThis.fetch, timeoutMs = 8000, url = teamApiUrl(), key = teamAnonKey(),
|
|
196
197
|
} = {}) {
|
|
198
|
+
trustSystemCA();
|
|
197
199
|
const ctl = new AbortController();
|
|
198
200
|
const timer = setTimeout(() => ctl.abort(), timeoutMs);
|
|
199
201
|
try {
|
|
@@ -225,6 +227,7 @@ export async function rpc(fn, params, {
|
|
|
225
227
|
* lives in memory: it is never written to disk or printed.
|
|
226
228
|
*/
|
|
227
229
|
async function apiJson(path, { body, accessToken, label, fetch = globalThis.fetch, timeoutMs = 8000, url = teamApiUrl(), key = teamAnonKey(), prefer } = {}) {
|
|
230
|
+
trustSystemCA();
|
|
228
231
|
const ctl = new AbortController();
|
|
229
232
|
const timer = setTimeout(() => ctl.abort(), timeoutMs);
|
|
230
233
|
try {
|
package/src/update-check.js
CHANGED
|
@@ -47,6 +47,7 @@ import { join, dirname, sep } from 'node:path';
|
|
|
47
47
|
import { fileURLToPath } from 'node:url';
|
|
48
48
|
import { userDataDir } from './paths.js';
|
|
49
49
|
import { debug } from './debug.js';
|
|
50
|
+
import { trustSystemCA } from './system-ca.js';
|
|
50
51
|
|
|
51
52
|
// This copy may be installed under the canonical name or under the legacy one.
|
|
52
53
|
// Releases go out under the canonical name, so that is the entry the registry
|
|
@@ -391,6 +392,7 @@ export function latestUrl(registry) {
|
|
|
391
392
|
* highlights, and the notice still goes out.
|
|
392
393
|
*/
|
|
393
394
|
export async function fetchHighlights(version, { timeoutMs = FETCH_TIMEOUT_MS, lang = 'en' } = {}) {
|
|
395
|
+
trustSystemCA();
|
|
394
396
|
const controller = new AbortController();
|
|
395
397
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
396
398
|
try {
|
|
@@ -420,6 +422,7 @@ export async function fetchHighlights(version, { timeoutMs = FETCH_TIMEOUT_MS, l
|
|
|
420
422
|
* and the explicit `update-check --refresh` command call this.
|
|
421
423
|
*/
|
|
422
424
|
export async function refreshUpdateState(currentVersion, { env, home } = {}) {
|
|
425
|
+
trustSystemCA();
|
|
423
426
|
const controller = new AbortController();
|
|
424
427
|
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
425
428
|
try {
|