@synkro-sh/cli 1.6.70 → 1.6.71

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/dist/bootstrap.js CHANGED
@@ -9687,11 +9687,12 @@ function captureClaudeSetupToken() {
9687
9687
  reject(new Error(`claude setup-token exited with code ${code}`));
9688
9688
  return;
9689
9689
  }
9690
+ const stripToToken = (s) => s.replace(/\x1B\[[0-9;?]*[a-zA-Z]/g, "").replace(/\x1B\][^\x07]*\x07/g, "").replace(/[\s\x00-\x1F\x7F]/g, "");
9690
9691
  const yellowRe = /\x1B\[38;2;255;193;7m([^\x1B]*)/g;
9691
9692
  let yellow = "";
9692
9693
  let m;
9693
9694
  while ((m = yellowRe.exec(raw)) !== null) yellow += m[1];
9694
- const yMatch = yellow.replace(/\s/g, "").match(/sk-ant-oat01-[A-Za-z0-9_-]+/);
9695
+ const yToken = stripToToken(yellow);
9695
9696
  let lineMatch = "";
9696
9697
  const clean = raw.replace(/\x1B\[[0-9;?]*[a-zA-Z]/g, "").replace(/\x1B\][^\x07]*\x07/g, "");
9697
9698
  const lines = clean.split("\n").map((l) => l.trim());
@@ -9703,13 +9704,13 @@ function captureClaudeSetupToken() {
9703
9704
  lineMatch = tok;
9704
9705
  break;
9705
9706
  }
9706
- const candidates = [yMatch ? yMatch[0] : "", lineMatch].filter((t) => /^sk-ant-oat01-[A-Za-z0-9_-]{20,}$/.test(t));
9707
- const best = candidates.sort((a, b) => b.length - a.length)[0];
9708
- if (!best) {
9709
- reject(new Error(`Could not find token in claude setup-token output (file=${raw.length}b, yellow=${yellow.length}b)`));
9707
+ const valid = (t) => /^sk-ant-oat01-[A-Za-z0-9_-]{40,}$/.test(t);
9708
+ const token = valid(yToken) ? yToken : valid(lineMatch) ? lineMatch : "";
9709
+ if (!token) {
9710
+ reject(new Error(`Could not capture a full token from claude setup-token output (file=${raw.length}b, yellow=${yellow.length}b, yToken=${yToken.length}b)`));
9710
9711
  return;
9711
9712
  }
9712
- resolve4(best);
9713
+ resolve4(token);
9713
9714
  });
9714
9715
  });
9715
9716
  }
@@ -10053,6 +10054,7 @@ var init_setupGithub = __esm({
10053
10054
  var install_exports = {};
10054
10055
  __export(install_exports, {
10055
10056
  detectGitRepo: () => detectGitRepo2,
10057
+ getOrMintCloudToken: () => getOrMintCloudToken,
10056
10058
  installCommand: () => installCommand,
10057
10059
  parseArgs: () => parseArgs,
10058
10060
  reconcileDeployLocation: () => reconcileDeployLocation,
@@ -10384,7 +10386,7 @@ function writeConfigEnv(opts) {
10384
10386
  `SYNKRO_CREDENTIALS_PATH=${shellQuoteSingle(credsPath)}`,
10385
10387
  `SYNKRO_TIER=${shellQuoteSingle(safeTier)}`,
10386
10388
  `SYNKRO_INFERENCE=${shellQuoteSingle(safeInference)}`,
10387
- `SYNKRO_VERSION=${shellQuoteSingle("1.6.70")}`
10389
+ `SYNKRO_VERSION=${shellQuoteSingle("1.6.71")}`
10388
10390
  ];
10389
10391
  if (safeSynkroBin) lines.push(`SYNKRO_CLI_BIN=${shellQuoteSingle(safeSynkroBin)}`);
10390
10392
  if (safeUserId) lines.push(`SYNKRO_USER_ID=${shellQuoteSingle(safeUserId)}`);
@@ -10404,6 +10406,38 @@ function writeConfigEnv(opts) {
10404
10406
  writeFileSync8(CONFIG_PATH2, lines.join("\n"), "utf-8");
10405
10407
  chmodSync2(CONFIG_PATH2, 384);
10406
10408
  }
10409
+ function jwtExpired(token) {
10410
+ try {
10411
+ const p = JSON.parse(Buffer.from(token.split(".")[1], "base64url").toString("utf-8"));
10412
+ if (!p?.exp) return true;
10413
+ return Date.now() > p.exp * 1e3 - 5 * 60 * 1e3;
10414
+ } catch {
10415
+ return true;
10416
+ }
10417
+ }
10418
+ async function getOrMintCloudToken(gatewayUrl) {
10419
+ assertGatewayAllowed(gatewayUrl);
10420
+ let stored = "";
10421
+ try {
10422
+ stored = readFileSync10(CLOUD_JWT_PATH, "utf-8").trim();
10423
+ } catch {
10424
+ }
10425
+ if (stored && !jwtExpired(stored)) return stored;
10426
+ await refreshToken().catch(() => false);
10427
+ const jwt2 = getAccessToken();
10428
+ if (!jwt2) throw new Error("Not authenticated \u2014 run `synkro login`");
10429
+ const resp = await fetch(`${gatewayUrl}/api/v1/cli/cloud-token`, {
10430
+ method: "POST",
10431
+ headers: { Authorization: `Bearer ${jwt2}`, "Content-Type": "application/json" }
10432
+ });
10433
+ if (!resp.ok) {
10434
+ const t = await resp.text().catch(() => "");
10435
+ throw new Error(`cloud-token mint failed (${resp.status}): ${t.slice(0, 200)}`);
10436
+ }
10437
+ const { token } = await resp.json();
10438
+ writeFileSync8(CLOUD_JWT_PATH, token + "\n", { mode: 384 });
10439
+ return token;
10440
+ }
10407
10441
  async function provisionCloudContainer(opts) {
10408
10442
  let setupToken;
10409
10443
  try {
@@ -10430,10 +10464,16 @@ async function provisionCloudContainer(opts) {
10430
10464
  } catch {
10431
10465
  }
10432
10466
  }
10467
+ let cloudJwt = opts.jwt;
10468
+ try {
10469
+ cloudJwt = await getOrMintCloudToken(opts.gatewayUrl);
10470
+ } catch (e) {
10471
+ console.warn(` (cloud token unavailable, using session token: ${e.message})`);
10472
+ }
10433
10473
  try {
10434
10474
  const resp = await fetch(`${opts.gatewayUrl}/api/v1/cli/cloud-provision`, {
10435
10475
  method: "POST",
10436
- headers: { "Authorization": `Bearer ${opts.jwt}`, "Content-Type": "application/json" },
10476
+ headers: { "Authorization": `Bearer ${cloudJwt}`, "Content-Type": "application/json" },
10437
10477
  body: JSON.stringify({
10438
10478
  org_id: opts.orgId,
10439
10479
  user_id: opts.userId,
@@ -11871,7 +11911,7 @@ async function syncTranscriptsBulk(gatewayUrl, token, repo) {
11871
11911
  }
11872
11912
  return { sessions: totalSessions, messages: totalMessages };
11873
11913
  }
11874
- var SYNKRO_DIR5, HOOKS_DIR, BIN_DIR, CONFIG_PATH2, MCP_STDIO_PROXY_SRC, OFFSETS_DIR;
11914
+ var SYNKRO_DIR5, HOOKS_DIR, BIN_DIR, CONFIG_PATH2, MCP_STDIO_PROXY_SRC, OFFSETS_DIR, CLOUD_JWT_PATH;
11875
11915
  var init_install = __esm({
11876
11916
  "cli/commands/install.ts"() {
11877
11917
  "use strict";
@@ -12005,6 +12045,7 @@ rl.on('line', async (line) => {
12005
12045
  });
12006
12046
  `;
12007
12047
  OFFSETS_DIR = join10(SYNKRO_DIR5, ".transcript-offsets");
12048
+ CLOUD_JWT_PATH = join10(SYNKRO_DIR5, ".cloud-jwt");
12008
12049
  }
12009
12050
  });
12010
12051
 
@@ -13978,7 +14019,7 @@ var args = process.argv.slice(2);
13978
14019
  var cmd = args[0] || "";
13979
14020
  var subArgs = args.slice(1);
13980
14021
  function printVersion() {
13981
- console.log("1.6.70");
14022
+ console.log("1.6.71");
13982
14023
  }
13983
14024
  function printHelp2() {
13984
14025
  console.log(`Synkro CLI \u2014 runtime safety for AI coding agents