repowise 0.1.70 → 0.1.72

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.
@@ -1450,16 +1450,20 @@ async function clearCredentials() {
1450
1450
  if (err.code !== "ENOENT") throw err;
1451
1451
  }
1452
1452
  }
1453
- async function getValidCredentials2() {
1453
+ async function getValidCredentials2(opts) {
1454
1454
  const creds = await getStoredCredentials2();
1455
1455
  if (!creds) return null;
1456
- if (Date.now() > creds.expiresAt - 5 * 60 * 1e3) {
1456
+ const needsRefresh = opts?.forceRefresh || Date.now() > creds.expiresAt - 5 * 60 * 1e3;
1457
+ if (needsRefresh) {
1457
1458
  try {
1458
1459
  const refreshed = await refreshTokens2(creds.refreshToken);
1459
1460
  refreshed.cognito = creds.cognito;
1460
1461
  await storeCredentials2(refreshed);
1461
1462
  return refreshed;
1462
1463
  } catch {
1464
+ if (Date.now() < creds.expiresAt) {
1465
+ return creds;
1466
+ }
1463
1467
  await clearCredentials();
1464
1468
  return null;
1465
1469
  }
@@ -1547,7 +1551,7 @@ async function apiRequest(path, options) {
1547
1551
  if (!credentials) {
1548
1552
  throw new Error("Not logged in. Run `repowise login` first.");
1549
1553
  }
1550
- const response = await fetch(`${getApiUrl()}${path}`, {
1554
+ let response = await fetch(`${getApiUrl()}${path}`, {
1551
1555
  ...options,
1552
1556
  headers: {
1553
1557
  "Content-Type": "application/json",
@@ -1556,8 +1560,21 @@ async function apiRequest(path, options) {
1556
1560
  }
1557
1561
  });
1558
1562
  if (response.status === 401) {
1559
- await clearCredentials();
1560
- throw new Error("Session expired. Run `repowise login` again.");
1563
+ const refreshed = await getValidCredentials2({ forceRefresh: true });
1564
+ if (refreshed) {
1565
+ response = await fetch(`${getApiUrl()}${path}`, {
1566
+ ...options,
1567
+ headers: {
1568
+ "Content-Type": "application/json",
1569
+ Authorization: `Bearer ${refreshed.accessToken}`,
1570
+ ...options?.headers
1571
+ }
1572
+ });
1573
+ }
1574
+ if (!refreshed || response.status === 401) {
1575
+ await clearCredentials();
1576
+ throw new Error("Session expired. Run `repowise login` again.");
1577
+ }
1561
1578
  }
1562
1579
  if (response.status === 402) {
1563
1580
  let message = "Your subscription is inactive.";
@@ -1944,7 +1961,7 @@ var PERSONA_LABELS = {
1944
1961
  };
1945
1962
  function computeOverallProgress(syncResult) {
1946
1963
  const stepNumber = syncResult.stepNumber ?? 1;
1947
- const totalSteps = syncResult.totalSteps ?? 6;
1964
+ const totalSteps = syncResult.totalSteps ?? 7;
1948
1965
  const stepPct = syncResult.progressPercentage ?? 0;
1949
1966
  return Math.min(100, Math.round(((stepNumber - 1) * 100 + stepPct) / totalSteps));
1950
1967
  }
@@ -2349,23 +2366,27 @@ async function create() {
2349
2366
  process.exitCode = 1;
2350
2367
  return;
2351
2368
  }
2369
+ let useFreeRescan = false;
2352
2370
  try {
2353
- const pricing = await apiRequest(
2354
- `/v1/repos/${repoId}/rescan-pricing`
2355
- );
2371
+ const pricing = await apiRequest(`/v1/repos/${repoId}/rescan-pricing`);
2356
2372
  if (pricing.lastFullScanAt) {
2357
- spinner.fail(chalk5.red("This repository already has context generated."));
2358
- console.log(
2359
- chalk5.cyan(
2360
- `
2373
+ if (pricing.allowed && pricing.isFree) {
2374
+ spinner.succeed(chalk5.cyan("Free rescan available. Will trigger a full rescan."));
2375
+ useFreeRescan = true;
2376
+ } else {
2377
+ spinner.fail(chalk5.red("This repository already has context generated."));
2378
+ console.log(
2379
+ chalk5.cyan(
2380
+ `
2361
2381
  To trigger a new full scan, visit the dashboard:
2362
2382
  https://app.repowise.ai/repos/${repoId}
2363
2383
  `
2364
- )
2365
- );
2366
- console.log(chalk5.dim(" To sync recent changes, use: repowise sync\n"));
2367
- process.exitCode = 1;
2368
- return;
2384
+ )
2385
+ );
2386
+ console.log(chalk5.dim(" To sync recent changes, use: repowise sync\n"));
2387
+ process.exitCode = 1;
2388
+ return;
2389
+ }
2369
2390
  }
2370
2391
  } catch {
2371
2392
  }
@@ -2388,9 +2409,10 @@ async function create() {
2388
2409
  spinner.start("Starting context generation pipeline...");
2389
2410
  let syncId;
2390
2411
  try {
2391
- const triggerResult = await apiRequest(`/v1/repos/${repoId}/sync`, {
2412
+ const endpoint = useFreeRescan ? `/v1/repos/${repoId}/full-rescan` : `/v1/repos/${repoId}/sync`;
2413
+ const triggerResult = await apiRequest(endpoint, {
2392
2414
  method: "POST",
2393
- body: JSON.stringify({ scanType: "full", contextStorage })
2415
+ body: useFreeRescan ? void 0 : JSON.stringify({ scanType: "full", contextStorage })
2394
2416
  });
2395
2417
  syncId = triggerResult.syncId;
2396
2418
  } catch (triggerErr) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repowise",
3
- "version": "0.1.70",
3
+ "version": "0.1.72",
4
4
  "type": "module",
5
5
  "description": "AI-optimized codebase context generator",
6
6
  "bin": {