@brianli/kimaki 0.4.73-brianli.1 → 0.4.73-brianli.2

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 (3) hide show
  1. package/dist/cli.js +14 -3
  2. package/package.json +1 -1
  3. package/src/cli.ts +18 -3
package/dist/cli.js CHANGED
@@ -43,6 +43,8 @@ const KIMAKI_GATEWAY_PROXY_URL = process.env.KIMAKI_GATEWAY_PROXY_URL ||
43
43
  const KIMAKI_GATEWAY_PROXY_REST_BASE_URL = getGatewayProxyRestBaseUrl({
44
44
  gatewayUrl: KIMAKI_GATEWAY_PROXY_URL,
45
45
  });
46
+ const KIMAKI_CLIENT_ID = process.env.KIMAKI_CLIENT_ID?.trim() || undefined;
47
+ const KIMAKI_CLIENT_SECRET = process.env.KIMAKI_CLIENT_SECRET?.trim() || undefined;
46
48
  // Strip bracketed paste escape sequences from terminal input.
47
49
  // iTerm2 and other terminals wrap pasted content with \x1b[200~ and \x1b[201~
48
50
  // which can cause validation to fail on macOS. See: https://github.com/remorses/kimaki/issues/18
@@ -903,9 +905,18 @@ async function run({ restartOnboarding, addChannels, useWorktrees, enableVoiceCh
903
905
  cliLogger.error('Gateway mode is not available yet. KIMAKI_SHARED_APP_ID is not configured.');
904
906
  process.exit(EXIT_NO_RESTART);
905
907
  }
906
- // Generate client credentials
907
- const clientId = crypto.randomUUID();
908
- const clientSecret = crypto.randomBytes(32).toString('hex');
908
+ const hasGatewayClientId = Boolean(KIMAKI_CLIENT_ID);
909
+ const hasGatewayClientSecret = Boolean(KIMAKI_CLIENT_SECRET);
910
+ if (hasGatewayClientId !== hasGatewayClientSecret) {
911
+ cliLogger.error('Gateway credential env vars must be set together: KIMAKI_CLIENT_ID and KIMAKI_CLIENT_SECRET.');
912
+ process.exit(EXIT_NO_RESTART);
913
+ }
914
+ const clientId = KIMAKI_CLIENT_ID || crypto.randomUUID();
915
+ const clientSecret = KIMAKI_CLIENT_SECRET
916
+ || crypto.randomBytes(32).toString('hex');
917
+ if (KIMAKI_CLIENT_ID && KIMAKI_CLIENT_SECRET) {
918
+ cliLogger.log('Using KIMAKI_CLIENT_ID and KIMAKI_CLIENT_SECRET from environment for gateway mode.');
919
+ }
909
920
  const statePayload = JSON.stringify({ clientId, clientSecret });
910
921
  const oauthUrl = generateBotInstallUrl({
911
922
  clientId: KIMAKI_SHARED_APP_ID,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@brianli/kimaki",
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
- "version": "0.4.73-brianli.1",
5
+ "version": "0.4.73-brianli.2",
6
6
  "repository": "https://github.com/remorses/kimaki",
7
7
  "bin": "bin.js",
8
8
  "files": [
package/src/cli.ts CHANGED
@@ -133,6 +133,8 @@ const KIMAKI_GATEWAY_PROXY_URL =
133
133
  const KIMAKI_GATEWAY_PROXY_REST_BASE_URL = getGatewayProxyRestBaseUrl({
134
134
  gatewayUrl: KIMAKI_GATEWAY_PROXY_URL,
135
135
  })
136
+ const KIMAKI_CLIENT_ID = process.env.KIMAKI_CLIENT_ID?.trim() || undefined
137
+ const KIMAKI_CLIENT_SECRET = process.env.KIMAKI_CLIENT_SECRET?.trim() || undefined
136
138
 
137
139
  // Strip bracketed paste escape sequences from terminal input.
138
140
  // iTerm2 and other terminals wrap pasted content with \x1b[200~ and \x1b[201~
@@ -1303,9 +1305,22 @@ async function run({
1303
1305
  process.exit(EXIT_NO_RESTART)
1304
1306
  }
1305
1307
 
1306
- // Generate client credentials
1307
- const clientId = crypto.randomUUID()
1308
- const clientSecret = crypto.randomBytes(32).toString('hex')
1308
+ const hasGatewayClientId = Boolean(KIMAKI_CLIENT_ID)
1309
+ const hasGatewayClientSecret = Boolean(KIMAKI_CLIENT_SECRET)
1310
+ if (hasGatewayClientId !== hasGatewayClientSecret) {
1311
+ cliLogger.error(
1312
+ 'Gateway credential env vars must be set together: KIMAKI_CLIENT_ID and KIMAKI_CLIENT_SECRET.',
1313
+ )
1314
+ process.exit(EXIT_NO_RESTART)
1315
+ }
1316
+ const clientId = KIMAKI_CLIENT_ID || crypto.randomUUID()
1317
+ const clientSecret = KIMAKI_CLIENT_SECRET
1318
+ || crypto.randomBytes(32).toString('hex')
1319
+ if (KIMAKI_CLIENT_ID && KIMAKI_CLIENT_SECRET) {
1320
+ cliLogger.log(
1321
+ 'Using KIMAKI_CLIENT_ID and KIMAKI_CLIENT_SECRET from environment for gateway mode.',
1322
+ )
1323
+ }
1309
1324
 
1310
1325
  const statePayload = JSON.stringify({ clientId, clientSecret } satisfies GatewayOAuthState)
1311
1326
  const oauthUrl = generateBotInstallUrl({