@askance/cli 0.2.1 → 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 +33 -6
  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,15 +447,35 @@ async function login() {
440
447
  }
441
448
  catch { }
442
449
  }
443
- console.log("\n To log in as a different user, delete .askance/credentials and run login again.");
444
- return;
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
460
+ }
461
+ else {
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;
472
+ }
445
473
  }
446
474
  // Generate a device code / CLI login token
447
475
  console.log("[askance] Logging in to Askance...");
448
476
  console.log(` API: ${apiUrl}`);
449
477
  // Request a CLI login session from the backend
450
- const { apiPost, apiGet } = await Promise.resolve().then(() => __importStar(require("../common/api-client")));
451
- const startResult = await apiPost("/api/auth/cli/start");
478
+ const startResult = await (0, api_client_1.apiPost)("/api/auth/cli/start");
452
479
  if (!startResult.ok || !startResult.data) {
453
480
  console.error("[askance] Failed to start login. Is the API running?");
454
481
  console.error(` URL: ${apiUrl}`);
@@ -478,7 +505,7 @@ async function login() {
478
505
  const startTime = Date.now();
479
506
  while (Date.now() - startTime < maxWait) {
480
507
  await new Promise((r) => setTimeout(r, pollInterval));
481
- const pollResult = await apiGet(`/api/auth/cli/poll/${loginId}`);
508
+ const pollResult = await (0, api_client_1.apiGet)(`/api/auth/cli/poll/${loginId}`);
482
509
  if (pollResult.ok && pollResult.data) {
483
510
  if (pollResult.data.status === "completed" && pollResult.data.token) {
484
511
  // Save credentials
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askance/cli",
3
- "version": "0.2.1",
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",