@indigoai-us/hq-cli 5.5.0 → 5.5.1

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/src/index.ts CHANGED
@@ -13,6 +13,7 @@ import { registerCloudCommands } from "./commands/cloud.js";
13
13
  import { registerLoginCommand } from "./commands/login.js";
14
14
  import { registerLogoutCommand } from "./commands/logout.js";
15
15
  import { registerWhoamiCommand } from "./commands/whoami.js";
16
+ import { registerOnboardCommand } from "./commands/onboard.js";
16
17
  import { registerPackageInstallCommand } from "./commands/pkg-install.js";
17
18
  import { registerPackageRemoveCommand } from "./commands/pkg-remove.js";
18
19
  import { registerPackageUpdateCommand } from "./commands/pkg-update.js";
@@ -63,10 +64,13 @@ registerCloudCommands(syncCmd);
63
64
  // Team commands (top-level)
64
65
  registerTeamSyncCommand(program);
65
66
 
66
- // Auth commands (top-level)
67
+ // Auth commands (top-level — registry auth via Clerk, separate from Cognito)
67
68
  registerLoginCommand(program);
68
69
  registerLogoutCommand(program);
69
70
  registerWhoamiCommand(program);
70
71
  registerAuthCommands(program);
71
72
 
73
+ // Onboarding (top-level — Cognito + vault-service provisioning)
74
+ registerOnboardCommand(program);
75
+
72
76
  program.parse();
@@ -1,41 +1,56 @@
1
1
  /**
2
2
  * Shared Cognito session helpers for hq-cli commands.
3
3
  *
4
- * Consumed by `hq auth refresh` and the standalone `hq-auth-refresh` bin
5
- * invoked by the deploy skill (.claude/skills/deploy/SKILL.md step 4).
4
+ * Consumed by:
5
+ * - `hq onboard` and `hq sync push|pull` (need token + VaultServiceConfig)
6
+ * - `hq auth refresh` and the standalone `hq-auth-refresh` bin invoked by
7
+ * the deploy skill (.claude/skills/deploy/SKILL.md step 4)
6
8
  *
7
- * Defaults point at the shared hq-vault-dev Cognito pool. Override via env:
9
+ * Defaults point at the shared hq-vault-dev Cognito pool. They mirror
10
+ * tools/vlt-e2e/e2e-create-company-smoke.ts so the CLI and the in-tree demo script
11
+ * stay drift-free. Override any of them via env:
8
12
  *
9
13
  * AWS_REGION — e.g. us-east-1
10
14
  * HQ_COGNITO_DOMAIN — Cognito User Pool domain prefix
11
15
  * HQ_COGNITO_CLIENT_ID — App Client ID
12
16
  * HQ_COGNITO_CALLBACK_PORT — Loopback OAuth callback port
17
+ * HQ_VAULT_API_URL — vault-service API Gateway URL
13
18
  */
14
19
 
20
+ import * as os from "os";
21
+ import * as path from "path";
22
+ import chalk from "chalk";
15
23
  import {
16
24
  loadCachedTokens,
17
25
  isExpiring,
18
26
  refreshTokens,
19
27
  browserLogin,
20
28
  type CognitoAuthConfig,
29
+ type VaultServiceConfig,
21
30
  } from "@indigoai-us/hq-cloud";
22
31
 
23
32
  export const DEFAULT_COGNITO: CognitoAuthConfig = {
24
33
  region: process.env.AWS_REGION ?? "us-east-1",
25
34
  userPoolDomain: process.env.HQ_COGNITO_DOMAIN ?? "hq-vault-dev",
26
- clientId:
27
- process.env.HQ_COGNITO_CLIENT_ID ?? "4mmujmjq3srakdueg656b9m0mp",
35
+ clientId: process.env.HQ_COGNITO_CLIENT_ID ?? "4mmujmjq3srakdueg656b9m0mp",
28
36
  port: process.env.HQ_COGNITO_CALLBACK_PORT
29
37
  ? Number(process.env.HQ_COGNITO_CALLBACK_PORT)
30
38
  : 8765,
31
39
  };
32
40
 
41
+ export const DEFAULT_VAULT_API_URL =
42
+ process.env.HQ_VAULT_API_URL ??
43
+ "https://tqdwdqxv75.execute-api.us-east-1.amazonaws.com";
44
+
45
+ export const DEFAULT_HQ_ROOT = path.join(os.homedir(), "hq");
46
+
33
47
  /**
34
48
  * Return a non-expired Cognito access token, refreshing or browser-logging-in
35
49
  * as needed. Cache lives at ~/.hq/cognito-tokens.json.
36
50
  *
37
- * Pass `interactive: false` from automated contexts where failing fast is
38
- * better than opening a browser.
51
+ * Pass `interactive: false` from automated contexts (e.g. the `hq-auth-refresh`
52
+ * bin invoked by the deploy skill) where failing fast is better than opening
53
+ * a browser.
39
54
  */
40
55
  export async function ensureCognitoToken(options: {
41
56
  interactive?: boolean;
@@ -49,13 +64,19 @@ export async function ensureCognitoToken(options: {
49
64
 
50
65
  if (cached) {
51
66
  try {
52
- const refreshed = await refreshTokens(
53
- DEFAULT_COGNITO,
54
- cached.refreshToken,
55
- );
67
+ if (interactive) {
68
+ console.log(chalk.dim(" Refreshing expiring HQ session..."));
69
+ }
70
+ const refreshed = await refreshTokens(DEFAULT_COGNITO, cached.refreshToken);
56
71
  return refreshed.accessToken;
57
- } catch {
58
- // fall through to browser login
72
+ } catch (err) {
73
+ if (interactive) {
74
+ console.log(
75
+ chalk.dim(
76
+ ` Refresh failed (${err instanceof Error ? err.message : err}), falling back to browser login`,
77
+ ),
78
+ );
79
+ }
59
80
  }
60
81
  }
61
82
 
@@ -65,14 +86,25 @@ export async function ensureCognitoToken(options: {
65
86
  );
66
87
  }
67
88
 
89
+ console.log(chalk.cyan(" No cached HQ session — launching browser sign-in..."));
68
90
  const tokens = await browserLogin(DEFAULT_COGNITO);
69
91
  return tokens.accessToken;
70
92
  }
71
93
 
94
+ /** Build a VaultServiceConfig with the given access token. */
95
+ export function buildVaultConfig(authToken: string): VaultServiceConfig {
96
+ return {
97
+ apiUrl: DEFAULT_VAULT_API_URL,
98
+ authToken,
99
+ region: DEFAULT_COGNITO.region,
100
+ };
101
+ }
102
+
72
103
  /**
73
104
  * Refresh the cached Cognito session once and return the result. Used by
74
105
  * `hq auth refresh` and the `hq-auth-refresh` bin. Never opens a browser —
75
- * if no cached tokens exist or the refresh fails, throws.
106
+ * if no cached tokens exist or the refresh fails, returns `refreshed: false`
107
+ * with a reason string so the caller can decide what to do.
76
108
  */
77
109
  export async function refreshCachedSession(): Promise<{
78
110
  refreshed: boolean;