sprag-cli 3.80.1 → 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/README.ko.md CHANGED
@@ -258,7 +258,7 @@ sprag feedback "Bedrock에서 5m TTL 칩이 사라지지 않아요"
258
258
 
259
259
  ## 팀
260
260
 
261
- CLI는 무료이고 컴퓨터 한 대에서 혼자 동작합니다. 조직에는 **Sprag Pro** 와 **Sprag Enterprise** 가 같은 로컬 세션 로그로 만든 공용 대시보드를 더해 줍니다. 도입은 [sales@sprag.io](mailto:sales@sprag.io)로 문의해 주세요.
261
+ CLI는 무료이고 컴퓨터 한 대에서 혼자 동작합니다. 조직에는 **Sprag Pro** 와 **Sprag Enterprise** 가 같은 로컬 세션 로그로 만든 공용 대시보드를 더해 줍니다. 도입은 [support@sprag.io](mailto:support@sprag.io)로 문의해 주세요.
262
262
 
263
263
  ### Pro: 팀 대시보드
264
264
 
package/README.md CHANGED
@@ -312,7 +312,7 @@ For a bug, please include the tool version (`sprag --version`) and your OS. For
312
312
 
313
313
  ## Teams
314
314
 
315
- The CLI is free and works on its own on one machine. For organizations, **Sprag Pro** and **Sprag Enterprise** add a shared dashboard built from the same local session logs. To start, write to [sales@sprag.io](mailto:sales@sprag.io).
315
+ The CLI is free and works on its own on one machine. For organizations, **Sprag Pro** and **Sprag Enterprise** add a shared dashboard built from the same local session logs. To start, write to [support@sprag.io](mailto:support@sprag.io).
316
316
 
317
317
  ### Pro: team dashboard
318
318
 
package/docs/TEAM.ko.md CHANGED
@@ -102,14 +102,14 @@ Sprag 은 룰을 `~/.claude/ratchet-team.md`(Codex 는 `<CODEX_HOME>/ratchet-tea
102
102
 
103
103
  ## 조직과 좌석
104
104
 
105
- 모든 팀은 조직에 속하고, 좌석은 팀이 아니라 조직 단위로 구매합니다. 조직은 Sprag만 개설합니다. sales@sprag.io 로 문의하면 슈퍼유저가 sprag.io/ops/ 에서 조직을 열고 첫 오너를 이메일로 지정하며, 그다음부터 오너와 어드민이 그 안에 팀을 만듭니다. 오너 이메일은 필수이고 계정이 미리 없어도 됩니다. 한 번도 로그인한 적 없는 이메일이면 Sprag가 초대로 보관해 두었다가, 그 사람이 https://sprag.io/team/ 에 그 이메일로 처음 로그인하는 순간 오너가 됩니다.
105
+ 모든 팀은 조직에 속하고, 좌석은 팀이 아니라 조직 단위로 구매합니다. 조직은 Sprag만 개설합니다. support@sprag.io 로 문의하면 슈퍼유저가 sprag.io/ops/ 에서 조직을 열고 첫 오너를 이메일로 지정하며, 그다음부터 오너와 어드민이 그 안에 팀을 만듭니다. 오너 이메일은 필수이고 계정이 미리 없어도 됩니다. 한 번도 로그인한 적 없는 이메일이면 Sprag가 초대로 보관해 두었다가, 그 사람이 https://sprag.io/team/ 에 그 이메일로 처음 로그인하는 순간 오너가 됩니다.
106
106
 
107
107
  컴퓨터 한 대는 조직마다 좌석 하나를 씁니다. `sprag team leave` 뒤에 다시 참여하거나, 재설치하거나, 같은 조직의 다른 팀 초대로 참여해도 서버가 기기 ID로 예전 행을 찾아 초대받은 팀으로 옮기고 멤버 키만 새로 발급합니다. 행도 좌석도 두 개가 되지 않습니다. 다른 조직에 참여하면 그 조직의 좌석을 따로 씁니다.
108
108
 
109
109
  - **좌석이란.** 팀을 떠나지 않았고, 최근 30일 안에 무엇이든 보냈거나 업로드를 멈춘 상태인 컴퓨터 한 대(멤버 키 하나)입니다. 멈추지 않았는데 30일 넘게 연락이 없는 컴퓨터는 좌석을 차지하지 않습니다. 떠난 멤버도 세지 않습니다.
110
110
  - **두 번째 컴퓨터.** 같은 사람이 컴퓨터 두 대를 쓰면 오너나 어드민이 두 번째 컴퓨터를 첫 번째에 합쳐 좌석 하나를 같이 쓰게 할 수 있습니다. 대시보드의 멤버 행에서 "좌석 합치기"를 누르고, "합치기 해제"를 누르면 다시 따로 셉니다. 합쳐진 행에는 "OO님과 자리를 같이 씁니다"가 보입니다.
111
111
  - **한도.** 조직마다 좌석 한도가 있고, 한도를 넘는 참여는 거절됩니다. `sprag team join` 은 "이 조직에 남은 좌석이 없습니다. 조직 오너나 어드민에게 좌석 추가를 요청한 뒤 다시 참여하세요"를 출력하고 종료 코드 1로 끝납니다. 환경 변수로 하는 자동 참여는 조용히 넘어갔다가 다음 세션 시작 때 다시 시도합니다. 한도를 현재 사용량보다 낮춰도 기존 멤버는 그대로 쓰고, Sprag가 다시 올릴 때까지 새 참여만 거절됩니다.
112
- - **역할.** 권한 단계는 세 가지입니다. 슈퍼유저는 Sprag 직원이며 요금제와 좌석 한도를 정하고, 조직을 정지하고, 이메일로 오너를 추가하고(계정이 없으면 초대로 처리), sprag.io/ops/ 에서 모든 조직을 봅니다. 오너는 회사의 최상위 단계로, 어드민을 이메일로 지정하거나 해제하고(계정이 없으면 초대되며, 오너가 취소하거나 본인이 처음 로그인할 때까지 "첫 로그인 대기"로 표시됩니다) 어드민이 하는 일을 모두 합니다. 어드민은 회사의 관리 단계로, 팀을 만들고 구성원과 룰과 좌석을 관리합니다. 팀을 만든 사람에게도 특별한 권한이 없으며, 팀은 조직의 오너와 어드민, 그리고 슈퍼유저만 관리합니다. 오너와 어드민은 대시보드에서 좌석 한도를 볼 수 있습니다. 좌석을 늘리려면 sales@sprag.io 로 문의합니다.
112
+ - **역할.** 권한 단계는 세 가지입니다. 슈퍼유저는 Sprag 직원이며 요금제와 좌석 한도를 정하고, 조직을 정지하고, 이메일로 오너를 추가하고(계정이 없으면 초대로 처리), sprag.io/ops/ 에서 모든 조직을 봅니다. 오너는 회사의 최상위 단계로, 어드민을 이메일로 지정하거나 해제하고(계정이 없으면 초대되며, 오너가 취소하거나 본인이 처음 로그인할 때까지 "첫 로그인 대기"로 표시됩니다) 어드민이 하는 일을 모두 합니다. 어드민은 회사의 관리 단계로, 팀을 만들고 구성원과 룰과 좌석을 관리합니다. 팀을 만든 사람에게도 특별한 권한이 없으며, 팀은 조직의 오너와 어드민, 그리고 슈퍼유저만 관리합니다. 오너와 어드민은 대시보드에서 좌석 한도를 볼 수 있습니다. 좌석을 늘리려면 support@sprag.io 로 문의합니다.
113
113
 
114
114
  관리하는 조직 안에 팀을 만들려면 `sprag team create --org <조직 ID>` 를 씁니다. 조직은 Sprag만 개설하므로 `--org` 없이 실행하면 서버가 거절합니다. 명령은 조직 이름과 사용 중인 좌석 수를 함께 출력하고, `sprag team status` 는 조직 이름을 보여 줍니다.
115
115
 
@@ -119,7 +119,7 @@ Sprag 은 룰을 `~/.claude/ratchet-team.md`(Codex 는 `<CODEX_HOME>/ratchet-tea
119
119
 
120
120
  ## 대시보드
121
121
 
122
- https://sprag.io/team/ 에서 등록된 오너나 어드민이 이메일 코드로 로그인하고, 팀을 만들고, 초대 토큰을 받습니다. 새 조직은 sales@sprag.io 로 문의합니다. 오너, 어드민, 초대 대기 중 어느 쪽에도 없는 이메일은 코드를 보내기 전에 거절하며, 조직 오너에게 추가를 요청하라고 안내합니다. 초대받은 사람은 처음 로그인할 때 자동으로 오너나 어드민이 됩니다. 여기서 구성원별 지출과 절감액을 보고, 규칙 탭에서 조직 룰과 팀 룰을 관리하고, 구성원을 내보낼 수 있습니다. 조직 패널에는 요금제, 한도 대비 사용 좌석, 어드민, 전체 팀이 보입니다. 슈퍼유저는 sprag.io/ops/ 에서 모든 조직을 봅니다.
122
+ https://sprag.io/team/ 에서 등록된 오너나 어드민이 이메일 코드로 로그인하고, 팀을 만들고, 초대 토큰을 받습니다. 새 조직은 support@sprag.io 로 문의합니다. 오너, 어드민, 초대 대기 중 어느 쪽에도 없는 이메일은 코드를 보내기 전에 거절하며, 조직 오너에게 추가를 요청하라고 안내합니다. 초대받은 사람은 처음 로그인할 때 자동으로 오너나 어드민이 됩니다. 여기서 구성원별 지출과 절감액을 보고, 규칙 탭에서 조직 룰과 팀 룰을 관리하고, 구성원을 내보낼 수 있습니다. 조직 패널에는 요금제, 한도 대비 사용 좌석, 어드민, 전체 팀이 보입니다. 슈퍼유저는 sprag.io/ops/ 에서 모든 조직을 봅니다.
123
123
 
124
124
  대시보드 맨 위의 기간 선택(7일, 30일, 90일, 이번 달, 지난 달, 직접 선택)이 멤버 표, 사용량 차트, 프롬프트 사용량 탭의 기간을 정합니다. 기본값은 최근 30일이고, 내 컴퓨터의 달력 날짜를 쓰며 종료일도 포함합니다. 최대 365일까지 고를 수 있습니다. 고른 기간은 주소(`?from=2026-10-01&to=2026-10-18`)에 남으므로 새로고침하거나 링크를 공유해도 같은 기간이 보입니다. sprag.io/ops/ 슈퍼유저 콘솔에도 같은 선택이 있어 조직 표, 조직 머리말, 조직의 프롬프트 사용량에 적용됩니다.
125
125
 
@@ -142,7 +142,7 @@ https://sprag.io/team/ 에서 등록된 오너나 어드민이 이메일 코드
142
142
 
143
143
  ## 플랜
144
144
 
145
- Free, 프로(좌석당 월 $5), 엔터프라이즈(좌석당 월 $10, 프롬프트 수집과 사용자별 프롬프트 사용량 포함)가 있습니다. 대량 구매나 연간 청구는 맞춤 계약이며 sales@sprag.io 로 문의합니다. 자세한 내용은 https://sprag.io/pricing/ 에 있습니다.
145
+ Free, 프로(좌석당 월 $5), 엔터프라이즈(좌석당 월 $10, 프롬프트 수집과 사용자별 프롬프트 사용량 포함)가 있습니다. 대량 구매나 연간 청구는 맞춤 계약이며 support@sprag.io 로 문의합니다. 자세한 내용은 https://sprag.io/pricing/ 에 있습니다.
146
146
 
147
147
  ## 프롬프트 사용량 (엔터프라이즈)
148
148
 
package/docs/TEAM.md CHANGED
@@ -102,14 +102,14 @@ Sprag writes the rules to `~/.claude/ratchet-team.md` (Codex: `<CODEX_HOME>/ratc
102
102
 
103
103
  ## Organizations and seats
104
104
 
105
- Every team belongs to an organization, and seats are bought per organization, not per team. Only Sprag opens organizations: write to sales@sprag.io, and the superuser opens one at sprag.io/ops/ and names its first owner by email. The owner email is required, and the owner does not need an account yet: if the email has never signed in, Sprag keeps it as an invite, and the person becomes the owner the first time they sign in at https://sprag.io/team/ with that email. Owners and admins then create teams inside it.
105
+ Every team belongs to an organization, and seats are bought per organization, not per team. Only Sprag opens organizations: write to support@sprag.io, and the superuser opens one at sprag.io/ops/ and names its first owner by email. The owner email is required, and the owner does not need an account yet: if the email has never signed in, Sprag keeps it as an invite, and the person becomes the owner the first time they sign in at https://sprag.io/team/ with that email. Owners and admins then create teams inside it.
106
106
 
107
107
  A machine holds one seat per organization. When it joins again, with `sprag team join` after `sprag team leave`, after a reinstall, or with the invite of another team in the same organization, the server finds its earlier row by the machine ID, moves it to the invited team and issues a new member key; no second row and no second seat appear. Joins to a different organization take a seat there.
108
108
 
109
109
  - **What a seat is.** One machine (one member key) that has not left and either sent anything in the last 30 days or is paused. A machine that has been silent for 30 days or more without being paused holds no seat. Members who left are not counted.
110
110
  - **Second machine.** When the same person uses two machines, an owner or admin can merge the second one into the first so the two share one seat. In the dashboard, use "Merge seat" on the member row; "Unmerge" gives it its own seat back. A merged row shows "shares a seat with <name>".
111
111
  - **The limit.** Each organization has a seat limit. A join past the limit is refused: `sprag team join` exits 1 with "This organization has no free seat. Ask your organization owner or admin to add seats", and an environment auto-join stays silent and tries again at a later session start. Lowering the limit below current use never removes anyone; it only refuses new joins until Sprag raises it again.
112
- - **Roles.** There are three permission levels. The superuser is Sprag staff: it sets the plan and the seat limit, suspends organizations, adds owners by email (an email without an account is invited), and sees every organization at sprag.io/ops/. An owner is a company's top level: it appoints and removes admins by email (an email without an account is invited and shown as waiting for its first sign-in until the owner cancels it or the person signs in), and does everything an admin does. An admin is a company's management level: it creates teams and manages members, rules and seats. The person who created a team has no special rights over it; only the organization's owners and admins and the superuser manage teams. Owners and admins see the seat limit in the dashboard. To add seats, write to sales@sprag.io.
112
+ - **Roles.** There are three permission levels. The superuser is Sprag staff: it sets the plan and the seat limit, suspends organizations, adds owners by email (an email without an account is invited), and sees every organization at sprag.io/ops/. An owner is a company's top level: it appoints and removes admins by email (an email without an account is invited and shown as waiting for its first sign-in until the owner cancels it or the person signs in), and does everything an admin does. An admin is a company's management level: it creates teams and manages members, rules and seats. The person who created a team has no special rights over it; only the organization's owners and admins and the superuser manage teams. Owners and admins see the seat limit in the dashboard. To add seats, write to support@sprag.io.
113
113
  - **The plan.** Sprag sets the plan (`pro` or `enterprise`) on the organization; owners and admins cannot change it. Prompt capture can be switched on only while the organization is on Enterprise. To change the plan, contact us.
114
114
 
115
115
  Create a team inside an organization you administer from the CLI with `sprag team create --org <org-id>`; without `--org` the server refuses, because only Sprag opens organizations. The command prints the organization name and how many seats are used. `sprag team status` shows the organization name.
@@ -120,7 +120,7 @@ Create a team inside an organization you administer from the CLI with `sprag tea
120
120
 
121
121
  ## The dashboard
122
122
 
123
- https://sprag.io/team/ is where a registered owner or admin signs in with an email code, creates a team and gets the invite token. A new organization starts by writing to sales@sprag.io. An email that is not an owner, an admin or a pending invite is refused before any code is sent, with a message to ask the organization's owner to add it. Invited people become owner or admin automatically on their first sign-in. From there they see per-member spend and savings, manage organization and team rules on the Rules tab, and remove members. The organization panel shows the plan, seats used against the limit, admins and every team. The superuser sees every organization at sprag.io/ops/.
123
+ https://sprag.io/team/ is where a registered owner or admin signs in with an email code, creates a team and gets the invite token. A new organization starts by writing to support@sprag.io. An email that is not an owner, an admin or a pending invite is refused before any code is sent, with a message to ask the organization's owner to add it. Invited people become owner or admin automatically on their first sign-in. From there they see per-member spend and savings, manage organization and team rules on the Rules tab, and remove members. The organization panel shows the plan, seats used against the limit, admins and every team. The superuser sees every organization at sprag.io/ops/.
124
124
 
125
125
  A date range control at the top of the dashboard (7d, 30d, 90d, This month, Last month or Custom) sets the period for the members table, the Usage chart and the prompt usage tab. It defaults to the last 30 days, uses your local calendar days with the end date included, and allows 365 days at most. The choice is kept in the page address (`?from=2026-10-01&to=2026-10-18`), so a reload or a shared link shows the same period. The superuser console at /ops/ has the same control for the organization table, the organization header and its prompt usage.
126
126
 
@@ -143,7 +143,7 @@ Below the roster, an activity log lists joined, paused, resumed, left, removed,
143
143
 
144
144
  ## Plans
145
145
 
146
- Free, Pro ($5 per seat per month) and Enterprise ($10 per seat per month, with prompt capture and per-user prompt usage). Volume or annual invoicing is a custom agreement; write to sales@sprag.io. Details are on https://sprag.io/pricing/.
146
+ Free, Pro ($5 per seat per month) and Enterprise ($10 per seat per month, with prompt capture and per-user prompt usage). Volume or annual invoicing is a custom agreement; write to support@sprag.io. Details are on https://sprag.io/pricing/.
147
147
 
148
148
  ## Prompt usage (Enterprise)
149
149
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprag-cli",
3
- "version": "3.80.1",
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": {
@@ -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}`);
@@ -40,12 +40,12 @@ const T = {
40
40
  aborted: 'Not joined.',
41
41
  joined: (n) => `Joined team "${n}". Check it with: sprag team status`,
42
42
  seatLimit: 'This organization has no free seat. Ask your organization owner or admin to add seats, then join again.',
43
- orgExpired: "This organization's paid term has ended, so the server no longer accepts uploads or joins. Ask your organization owner to renew it (sales@sprag.io).",
43
+ orgExpired: "This organization's paid term has ended, so the server no longer accepts uploads or joins. Ask your organization owner to renew it (support@sprag.io).",
44
44
  org: 'Organization',
45
45
  seats: (u, l) => `${u}/${l} seats used`,
46
46
  orgCreated: (n, u, l) => `Organization: ${n}${u != null && l != null ? ` (${u}/${l} seats used)` : ''}`,
47
47
  badOrg: '--org needs an organization id.',
48
- noOrgCreate: 'Only Sprag opens new organizations. Pass --org <id> for an organization you administer (the id is on the dashboard), or write to sales@sprag.io to open one.',
48
+ noOrgCreate: 'Only Sprag opens new organizations. Pass --org <id> for an organization you administer (the id is on the dashboard), or write to support@sprag.io to open one.',
49
49
  left: 'Left the team. Nothing is uploaded any more.',
50
50
  notJoined: 'Not in a team. Join with: sprag team join <token>',
51
51
  team: 'Team', plan: 'Plan', capture: 'Prompt capture', name: 'Display name',
@@ -106,12 +106,12 @@ const T = {
106
106
  aborted: '참여하지 않았습니다.',
107
107
  joined: (n) => `팀 "${n}" 에 참여했습니다. 확인: sprag team status`,
108
108
  seatLimit: '이 조직에 남은 좌석이 없습니다. 조직 오너나 어드민에게 좌석 추가를 요청한 뒤 다시 참여하세요',
109
- orgExpired: '조직의 이용 기간이 끝나 서버가 업로드와 참여를 받지 않습니다. 조직 오너에게 연장을 요청하세요(sales@sprag.io)',
109
+ orgExpired: '조직의 이용 기간이 끝나 서버가 업로드와 참여를 받지 않습니다. 조직 오너에게 연장을 요청하세요(support@sprag.io)',
110
110
  org: '조직',
111
111
  seats: (u, l) => `좌석 ${u}/${l} 사용 중`,
112
112
  orgCreated: (n, u, l) => `조직: ${n}${u != null && l != null ? ` (좌석 ${u}/${l} 사용 중)` : ''}`,
113
113
  badOrg: '--org 에는 조직 ID 가 필요합니다',
114
- noOrgCreate: '새 조직은 Sprag가 개설합니다. 관리하는 조직이 있으면 --org <ID> 를 붙여 주세요(ID 는 대시보드에 있습니다). 조직 개설은 sales@sprag.io 로 문의해 주세요.',
114
+ noOrgCreate: '새 조직은 Sprag가 개설합니다. 관리하는 조직이 있으면 --org <ID> 를 붙여 주세요(ID 는 대시보드에 있습니다). 조직 개설은 support@sprag.io 로 문의해 주세요.',
115
115
  left: '팀에서 나왔습니다. 이제 아무것도 업로드하지 않습니다.',
116
116
  notJoined: '참여한 팀이 없습니다. 참여하려면: sprag team join <토큰>',
117
117
  team: '팀', plan: '플랜', capture: '프롬프트 수집', name: '표시 이름',
@@ -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 {
@@ -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 {