@askance/cli 0.2.2 → 0.2.3

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.
Files changed (2) hide show
  1. package/dist/cli/index.js +30 -11
  2. package/package.json +1 -1
package/dist/cli/index.js CHANGED
@@ -338,7 +338,14 @@ async function setupProject() {
338
338
  // Fetch existing projects
339
339
  const projectsResult = await (0, api_client_1.apiGet)("/api/projects");
340
340
  if (!projectsResult.ok || !projectsResult.data) {
341
- console.log(" Could not fetch projects. You can link a project later via the dashboard.");
341
+ if (projectsResult.status === 401) {
342
+ console.log(" Session expired. Please re-login:");
343
+ console.log(" Delete .askance/credentials and run: npx askance login");
344
+ }
345
+ else {
346
+ console.log(` Could not fetch projects (${projectsResult.error ?? `HTTP ${projectsResult.status}`}).`);
347
+ console.log(" You can link a project later via the dashboard.");
348
+ }
342
349
  return;
343
350
  }
344
351
  const projects = projectsResult.data;
@@ -440,23 +447,35 @@ async function login() {
440
447
  }
441
448
  catch { }
442
449
  }
443
- // Check if a project is linked if not, set one up
444
- if (!config.projectId) {
445
- console.log("\n No project linked. Setting up project...");
446
- await setupProject();
450
+ // Verify the token is still valid (hit /api/auth/me)
451
+ const meResult = await (0, api_client_1.apiGet)("/api/auth/me");
452
+ if (!meResult.ok) {
453
+ console.log("\n Session expired. Clearing credentials and starting fresh login...");
454
+ const askanceDir = path_1.default.join(projectDir, ".askance");
455
+ const cPath = path_1.default.join(askanceDir, "credentials");
456
+ if (fs_1.default.existsSync(cPath))
457
+ fs_1.default.unlinkSync(cPath);
458
+ (0, api_client_1.clearConfigCache)();
459
+ // Fall through to the login flow below
447
460
  }
448
461
  else {
449
- console.log(` Project: ${config.projectId}`);
462
+ // Token is valid — check if a project is linked
463
+ if (!config.projectId) {
464
+ console.log("\n No project linked. Setting up project...");
465
+ await setupProject();
466
+ }
467
+ else {
468
+ console.log(` Project: ${config.projectId}`);
469
+ }
470
+ console.log("\n To log in as a different user, delete .askance/credentials and run login again.");
471
+ return;
450
472
  }
451
- console.log("\n To log in as a different user, delete .askance/credentials and run login again.");
452
- return;
453
473
  }
454
474
  // Generate a device code / CLI login token
455
475
  console.log("[askance] Logging in to Askance...");
456
476
  console.log(` API: ${apiUrl}`);
457
477
  // Request a CLI login session from the backend
458
- const { apiPost, apiGet } = await Promise.resolve().then(() => __importStar(require("../common/api-client")));
459
- const startResult = await apiPost("/api/auth/cli/start");
478
+ const startResult = await (0, api_client_1.apiPost)("/api/auth/cli/start");
460
479
  if (!startResult.ok || !startResult.data) {
461
480
  console.error("[askance] Failed to start login. Is the API running?");
462
481
  console.error(` URL: ${apiUrl}`);
@@ -486,7 +505,7 @@ async function login() {
486
505
  const startTime = Date.now();
487
506
  while (Date.now() - startTime < maxWait) {
488
507
  await new Promise((r) => setTimeout(r, pollInterval));
489
- const pollResult = await apiGet(`/api/auth/cli/poll/${loginId}`);
508
+ const pollResult = await (0, api_client_1.apiGet)(`/api/auth/cli/poll/${loginId}`);
490
509
  if (pollResult.ok && pollResult.data) {
491
510
  if (pollResult.data.status === "completed" && pollResult.data.token) {
492
511
  // Save credentials
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askance/cli",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Askance CLI — Tool call interception & approval management for AI coding agents",
5
5
  "license": "MIT",
6
6
  "homepage": "https://askance.app",