@lanonasis/cli 3.9.6 → 3.9.8

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/index.js CHANGED
@@ -11,6 +11,7 @@ import { orgCommands } from './commands/organization.js';
11
11
  import { mcpCommands } from './commands/mcp.js';
12
12
  import apiKeysCommand from './commands/api-keys.js';
13
13
  import { CLIConfig } from './utils/config.js';
14
+ import { APIClient } from './utils/api.js';
14
15
  import { getMCPClient } from './utils/mcp-client.js';
15
16
  import { dirname, join } from 'path';
16
17
  import { createOnboardingFlow } from './ux/index.js';
@@ -253,29 +254,77 @@ authCmd
253
254
  .description('Show authentication status')
254
255
  .action(async () => {
255
256
  const isAuth = await cliConfig.isAuthenticated();
256
- const user = await cliConfig.getCurrentUser();
257
257
  const failureCount = cliConfig.getFailureCount();
258
258
  const lastFailure = cliConfig.getLastAuthFailure();
259
259
  const authMethod = cliConfig.get('authMethod');
260
260
  const lastValidated = cliConfig.get('lastValidated');
261
261
  console.log(chalk.blue.bold('🔐 Authentication Status'));
262
262
  console.log('━'.repeat(40));
263
- if (isAuth && user) {
263
+ if (isAuth) {
264
264
  console.log(chalk.green('✓ Authenticated'));
265
- console.log(`Email: ${user.email}`);
266
- console.log(`Organization: ${user.organization_id}`);
267
- console.log(`Plan: ${user.plan}`);
268
265
  if (authMethod) {
269
266
  console.log(`Method: ${authMethod}`);
270
267
  }
271
268
  if (lastValidated) {
272
- const validatedDate = new Date(lastValidated);
273
- console.log(`Last validated: ${validatedDate.toLocaleString()}`);
269
+ console.log(`Last validated: ${new Date(lastValidated).toLocaleString()}`);
270
+ }
271
+ // Fetch live profile from auth gateway
272
+ try {
273
+ const profileClient = new APIClient();
274
+ profileClient.noExit = true;
275
+ const profile = await profileClient.getUserProfile();
276
+ console.log(`Email: ${profile.email}`);
277
+ if (profile.name)
278
+ console.log(`Name: ${profile.name}`);
279
+ console.log(`Role: ${profile.role}`);
280
+ if (profile.provider)
281
+ console.log(`Provider: ${profile.provider}`);
282
+ if (profile.last_sign_in_at) {
283
+ console.log(`Last sign-in: ${new Date(profile.last_sign_in_at).toLocaleString()}`);
284
+ }
285
+ }
286
+ catch {
287
+ // Profile fetch failed (e.g. auth gateway offline) — show cached info if available
288
+ const cached = await cliConfig.getCurrentUser();
289
+ if (cached?.email)
290
+ console.log(`Email: ${cached.email} (cached)`);
274
291
  }
275
292
  }
276
293
  else {
277
294
  console.log(chalk.red('✖ Not authenticated'));
278
- console.log(chalk.yellow('Run:'), chalk.white('memory login'));
295
+ console.log(chalk.yellow('Run:'), chalk.white('lanonasis auth login'));
296
+ }
297
+ // Warn when manual endpoint overrides are active
298
+ if (cliConfig.hasManualEndpointOverrides()) {
299
+ console.log();
300
+ console.log(chalk.yellow('⚠️ Manual endpoint overrides are active (manualEndpointOverrides=true)'));
301
+ const services = cliConfig.get('discoveredServices');
302
+ if (services) {
303
+ console.log(chalk.gray(` auth: ${services['auth_base']}`));
304
+ console.log(chalk.gray(` memory: ${services['memory_base']}`));
305
+ }
306
+ console.log(chalk.gray(' Run: lanonasis config clear-overrides to restore auto-discovery'));
307
+ }
308
+ // Live memory API probe — shows whether credentials actually work end-to-end
309
+ if (isAuth) {
310
+ console.log();
311
+ process.stdout.write('Memory API access: ');
312
+ try {
313
+ const apiClient = new APIClient();
314
+ apiClient.noExit = true; // catch 401 in our try/catch below instead of process.exit
315
+ await apiClient.getMemories({ limit: 1 });
316
+ console.log(chalk.green('✓ accessible'));
317
+ }
318
+ catch (err) {
319
+ const status = err?.response?.status;
320
+ if (status === 401 || status === 403) {
321
+ console.log(chalk.red(`✖ rejected (${status}) — credentials are stale or revoked`));
322
+ console.log(chalk.yellow(' Run: lanonasis auth login'));
323
+ }
324
+ else {
325
+ console.log(chalk.yellow(`⚠ reachable (status: ${status ?? 'network error'})`));
326
+ }
327
+ }
279
328
  }
280
329
  // Show failure tracking information
281
330
  if (failureCount > 0) {
@@ -645,16 +694,72 @@ program
645
694
  console.log(`Verified via: ${verification.endpoint}`);
646
695
  }
647
696
  if (isAuth) {
648
- const user = await cliConfig.getCurrentUser();
649
- if (user) {
650
- console.log(`User: ${user.email}`);
651
- console.log(`Plan: ${user.plan}`);
697
+ try {
698
+ const profileClient = new APIClient();
699
+ profileClient.noExit = true;
700
+ const profile = await profileClient.getUserProfile();
701
+ console.log(`User: ${profile.email}`);
702
+ if (profile.name)
703
+ console.log(`Name: ${profile.name}`);
704
+ console.log(`Role: ${profile.role}`);
705
+ }
706
+ catch {
707
+ const cached = await cliConfig.getCurrentUser();
708
+ if (cached?.email)
709
+ console.log(`User: ${cached.email} (cached)`);
652
710
  }
653
711
  return;
654
712
  }
655
713
  console.log(chalk.yellow(`Auth check: ${verification.reason || 'Credential validation failed'}`));
656
714
  console.log(chalk.yellow('Please run:'), chalk.white('lanonasis auth login'));
657
715
  });
716
+ // Whoami command — live profile from auth gateway
717
+ program
718
+ .command('whoami')
719
+ .description('Show the currently authenticated user profile')
720
+ .action(async () => {
721
+ await cliConfig.init();
722
+ const isAuth = await cliConfig.isAuthenticated();
723
+ if (!isAuth) {
724
+ console.log(chalk.red('✖ Not authenticated'));
725
+ console.log(chalk.yellow('Run:'), chalk.white('lanonasis auth login'));
726
+ process.exit(1);
727
+ }
728
+ try {
729
+ const profileClient = new APIClient();
730
+ profileClient.noExit = true;
731
+ const profile = await profileClient.getUserProfile();
732
+ console.log(chalk.blue.bold('👤 Current User'));
733
+ console.log('━'.repeat(40));
734
+ console.log(`Email: ${chalk.white(profile.email)}`);
735
+ if (profile.name) {
736
+ console.log(`Name: ${chalk.white(profile.name)}`);
737
+ }
738
+ console.log(`Role: ${chalk.white(profile.role)}`);
739
+ if (profile.provider) {
740
+ console.log(`Provider: ${chalk.white(profile.provider)}`);
741
+ }
742
+ if (profile.project_scope) {
743
+ console.log(`Scope: ${chalk.white(profile.project_scope)}`);
744
+ }
745
+ if (profile.last_sign_in_at) {
746
+ console.log(`Last login: ${chalk.white(new Date(profile.last_sign_in_at).toLocaleString())}`);
747
+ }
748
+ if (profile.created_at) {
749
+ console.log(`Member since: ${chalk.white(new Date(profile.created_at).toLocaleString())}`);
750
+ }
751
+ }
752
+ catch (err) {
753
+ const status = err?.response?.status;
754
+ if (status === 401 || status === 403) {
755
+ console.log(chalk.red('✖ Session expired — please log in again'));
756
+ console.log(chalk.yellow('Run:'), chalk.white('lanonasis auth login'));
757
+ process.exit(1);
758
+ }
759
+ console.error(chalk.red('✖ Failed to fetch profile:'), err instanceof Error ? err.message : String(err));
760
+ process.exit(1);
761
+ }
762
+ });
658
763
  // Health command using the healthCheck function
659
764
  program
660
765
  .command('health')