@bonginkan/maria 4.2.10 → 4.2.13

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/cli.cjs CHANGED
@@ -876,6 +876,7 @@ var init_AuthenticationManager = __esm({
876
876
  this.clientId = config2.clientId;
877
877
  this.initialized = true;
878
878
  } catch (error2) {
879
+ console.warn("Auth config initialization failed, using fallbacks:", error2);
879
880
  this.authBase = this.getAuthBaseUrl();
880
881
  this.apiBase = this.getApiBaseUrl();
881
882
  this.clientId = process.env.MARIA_CLIENT_ID || "maria-cli";
@@ -922,7 +923,8 @@ var init_AuthenticationManager = __esm({
922
923
  return await this.refreshToken();
923
924
  }
924
925
  return true;
925
- } catch {
926
+ } catch (error2) {
927
+ console.error("isAuthenticated failed:", error2);
926
928
  return false;
927
929
  }
928
930
  }
@@ -986,6 +988,7 @@ var init_AuthenticationManager = __esm({
986
988
  if (error2 instanceof AuthenticationRequiredError || error2 instanceof QuotaExceededError) {
987
989
  throw error2;
988
990
  }
991
+ console.error("getCurrentUser failed:", error2);
989
992
  throw new Error(ERROR_MESSAGES.NETWORK_ERROR);
990
993
  }
991
994
  }
@@ -1003,12 +1006,17 @@ var init_AuthenticationManager = __esm({
1003
1006
  return await this.loginWithLocalMock();
1004
1007
  }
1005
1008
  let tokens;
1006
- if (options.device) {
1009
+ const forceDevice = options.device || process.env.MARIA_AUTH_DEVICE_FLOW === "true" || !this.canLaunchBrowser();
1010
+ if (forceDevice) {
1011
+ if (!options.device) {
1012
+ console.warn("PKCE is unavailable in this environment; using device flow.");
1013
+ }
1007
1014
  tokens = await this.loginWithDeviceFlow();
1008
1015
  } else {
1009
1016
  try {
1010
1017
  tokens = await this.loginWithPKCEFlow();
1011
1018
  } catch (error2) {
1019
+ console.error("PKCE flow error:", error2);
1012
1020
  if (error2.message?.includes("ECONNREFUSED") || error2.message?.includes("fetch failed")) {
1013
1021
  console.error("\n\u274C Authentication service is currently unavailable");
1014
1022
  console.error("Please try one of the following:");
@@ -1030,6 +1038,7 @@ var init_AuthenticationManager = __esm({
1030
1038
  const user = await this.getCurrentUser();
1031
1039
  return { success: true, user, tokens };
1032
1040
  } catch (error2) {
1041
+ console.error("Login failed:", error2);
1033
1042
  return {
1034
1043
  success: false,
1035
1044
  error: error2.message || "Login failed"
@@ -1121,7 +1130,8 @@ var init_AuthenticationManager = __esm({
1121
1130
  };
1122
1131
  await this.tokenStorage.save(updatedTokens);
1123
1132
  return true;
1124
- } catch {
1133
+ } catch (error2) {
1134
+ console.error("Token refresh failed:", error2);
1125
1135
  return false;
1126
1136
  }
1127
1137
  }
@@ -1163,6 +1173,7 @@ var init_AuthenticationManager = __esm({
1163
1173
  await open__default.default(authUrl);
1164
1174
  } catch (error2) {
1165
1175
  server.close();
1176
+ console.error("Failed to open browser for authentication:", error2);
1166
1177
  throw new Error("Failed to open browser");
1167
1178
  }
1168
1179
  const authCode = await this.waitForCallback(server, pkceParams.state);
@@ -1186,57 +1197,62 @@ var init_AuthenticationManager = __esm({
1186
1197
  * Login with device flow (fallback)
1187
1198
  */
1188
1199
  async loginWithDeviceFlow() {
1189
- const response2 = await fetch(`${this.authBase}/oauth/device/start`, {
1190
- method: "POST",
1191
- headers: { "Content-Type": "application/json" },
1192
- body: JSON.stringify({
1193
- client_id: this.clientId,
1194
- scope: "user:profile user:inference org:create_api_key"
1195
- })
1196
- });
1197
- if (!response2.ok) {
1198
- throw new Error(`Device flow start failed: ${response2.statusText}`);
1199
- }
1200
- const raw = await response2.json();
1201
- const deviceResponse = {
1202
- verificationUri: raw.verification_uri || raw.verificationUri || "https://auth.maria-code.ai/device",
1203
- userCode: raw.user_code || raw.userCode || "",
1204
- deviceCode: raw.device_code || raw.deviceCode || "",
1205
- interval: (typeof raw.interval === "number" ? raw.interval : parseInt(String(raw.interval || 5), 10)) || 5,
1206
- expiresIn: (typeof raw.expires_in === "number" ? raw.expires_in : parseInt(String(raw.expires_in || raw.expiresIn || 600), 10)) || 600
1207
- };
1208
- const verificationUrl = deviceResponse.verificationUri;
1209
- console.log(`\u{1F510} Device Login`);
1210
- console.log(`Open: ${verificationUrl}`);
1211
- console.log(`Code: ${deviceResponse.userCode}`);
1212
- const deadline = Date.now() + deviceResponse.expiresIn * 1e3;
1213
- const intervalMs = Math.max(1500, deviceResponse.interval * 1e3);
1214
- while (Date.now() < deadline) {
1215
- await this.sleep(intervalMs);
1216
- const finishResponse = await fetch(`${this.authBase}/oauth/device/finish`, {
1200
+ try {
1201
+ const response2 = await fetch(`${this.authBase}/oauth/device/start`, {
1217
1202
  method: "POST",
1218
1203
  headers: { "Content-Type": "application/json" },
1219
1204
  body: JSON.stringify({
1220
1205
  client_id: this.clientId,
1221
- device_code: deviceResponse.deviceCode
1206
+ scope: "user:profile user:inference org:create_api_key"
1222
1207
  })
1223
1208
  });
1224
- if (finishResponse.status === 428 || finishResponse.status === 400) {
1225
- continue;
1226
- }
1227
- if (!finishResponse.ok) {
1228
- throw new Error(`Device flow failed: ${finishResponse.statusText}`);
1229
- }
1230
- const tokens = await finishResponse.json();
1231
- return {
1232
- idToken: tokens.id_token || tokens.access_token || "",
1233
- accessToken: tokens.access_token || tokens.id_token || "",
1234
- refreshToken: tokens.refresh_token || "",
1235
- customToken: tokens.custom_token,
1236
- expiresAt: Date.now() + (tokens.expires_in ? Number(tokens.expires_in) : 600) * 1e3
1209
+ if (!response2.ok) {
1210
+ throw new Error(`Device flow start failed: ${response2.statusText}`);
1211
+ }
1212
+ const raw = await response2.json();
1213
+ const deviceResponse = {
1214
+ verificationUri: raw.verification_uri || raw.verificationUri || "https://auth.maria-code.ai/device",
1215
+ userCode: raw.user_code || raw.userCode || "",
1216
+ deviceCode: raw.device_code || raw.deviceCode || "",
1217
+ interval: (typeof raw.interval === "number" ? raw.interval : parseInt(String(raw.interval || 5), 10)) || 5,
1218
+ expiresIn: (typeof raw.expires_in === "number" ? raw.expires_in : parseInt(String(raw.expires_in || raw.expiresIn || 600), 10)) || 600
1237
1219
  };
1220
+ const verificationUrl = deviceResponse.verificationUri || `${this.authBase}/device`;
1221
+ console.log(`\u{1F510} Device Login`);
1222
+ console.log(`Open: ${verificationUrl}`);
1223
+ console.log(`Code: ${deviceResponse.userCode}`);
1224
+ const deadline = Date.now() + deviceResponse.expiresIn * 1e3;
1225
+ const intervalMs = Math.max(1500, deviceResponse.interval * 1e3);
1226
+ while (Date.now() < deadline) {
1227
+ await this.sleep(intervalMs);
1228
+ const finishResponse = await fetch(`${this.authBase}/oauth/device/finish`, {
1229
+ method: "POST",
1230
+ headers: { "Content-Type": "application/json" },
1231
+ body: JSON.stringify({
1232
+ client_id: this.clientId,
1233
+ device_code: deviceResponse.deviceCode
1234
+ })
1235
+ });
1236
+ if (finishResponse.status === 428 || finishResponse.status === 400) {
1237
+ continue;
1238
+ }
1239
+ if (!finishResponse.ok) {
1240
+ throw new Error(`Device flow failed: ${finishResponse.statusText}`);
1241
+ }
1242
+ const tokens = await finishResponse.json();
1243
+ return {
1244
+ idToken: tokens.id_token || tokens.access_token || "",
1245
+ accessToken: tokens.access_token || tokens.id_token || "",
1246
+ refreshToken: tokens.refresh_token || "",
1247
+ customToken: tokens.custom_token,
1248
+ expiresAt: Date.now() + (tokens.expires_in ? Number(tokens.expires_in) : 600) * 1e3
1249
+ };
1250
+ }
1251
+ throw new Error(ERROR_MESSAGES.LOGIN_TIMEOUT);
1252
+ } catch (error2) {
1253
+ console.error("Device flow error:", error2);
1254
+ throw error2;
1238
1255
  }
1239
- throw new Error(ERROR_MESSAGES.LOGIN_TIMEOUT);
1240
1256
  }
1241
1257
  /**
1242
1258
  * Generate PKCE parameters
@@ -1275,8 +1291,10 @@ var init_AuthenticationManager = __esm({
1275
1291
  } catch (error2) {
1276
1292
  lastError = error2;
1277
1293
  if (error2.code !== "EADDRINUSE") {
1294
+ console.error("Failed to start callback server:", error2);
1278
1295
  throw error2;
1279
1296
  }
1297
+ console.warn("Callback server port in use, retrying...", error2?.message || error2);
1280
1298
  }
1281
1299
  }
1282
1300
  throw lastError || new Error("Failed to find available port");
@@ -1308,6 +1326,7 @@ var init_AuthenticationManager = __esm({
1308
1326
  return new Promise((resolve4, reject) => {
1309
1327
  const timeout = setTimeout(() => {
1310
1328
  server.close();
1329
+ console.error("OAuth callback timed out");
1311
1330
  reject(new Error(ERROR_MESSAGES.LOGIN_TIMEOUT));
1312
1331
  }, 5 * 60 * 1e3);
1313
1332
  server.on("request", (req, res) => {
@@ -1320,6 +1339,7 @@ var init_AuthenticationManager = __esm({
1320
1339
  res.writeHead(400, { "Content-Type": "text/html" });
1321
1340
  res.end(this.getErrorPage(error2));
1322
1341
  clearTimeout(timeout);
1342
+ console.error("OAuth callback returned error:", error2);
1323
1343
  reject(new Error(error2));
1324
1344
  return;
1325
1345
  }
@@ -1327,6 +1347,7 @@ var init_AuthenticationManager = __esm({
1327
1347
  res.writeHead(400, { "Content-Type": "text/html" });
1328
1348
  res.end(this.getErrorPage("Invalid state parameter"));
1329
1349
  clearTimeout(timeout);
1350
+ console.error("OAuth callback invalid state", { received: state, expected: expectedState });
1330
1351
  reject(new Error(ERROR_MESSAGES.INVALID_STATE));
1331
1352
  return;
1332
1353
  }
@@ -1344,28 +1365,39 @@ var init_AuthenticationManager = __esm({
1344
1365
  * Exchange authorization code for tokens
1345
1366
  */
1346
1367
  async exchangeCodeForTokens(code, codeVerifier, redirectUri) {
1347
- const response2 = await fetch(`${this.authBase}/oauth/token`, {
1348
- method: "POST",
1349
- headers: { "Content-Type": "application/json" },
1350
- body: JSON.stringify({
1351
- grant_type: "authorization_code",
1352
- client_id: this.clientId,
1353
- code,
1354
- code_verifier: codeVerifier,
1355
- redirect_uri: redirectUri
1356
- })
1357
- });
1358
- if (!response2.ok) {
1359
- throw new Error(`Token exchange failed: ${response2.statusText}`);
1368
+ try {
1369
+ const response2 = await fetch(`${this.authBase}/oauth/token`, {
1370
+ method: "POST",
1371
+ headers: { "Content-Type": "application/json" },
1372
+ body: JSON.stringify({
1373
+ grant_type: "authorization_code",
1374
+ client_id: this.clientId,
1375
+ code,
1376
+ code_verifier: codeVerifier,
1377
+ redirect_uri: redirectUri
1378
+ })
1379
+ });
1380
+ if (!response2.ok) {
1381
+ let bodyText = "";
1382
+ try {
1383
+ bodyText = await response2.text();
1384
+ } catch {
1385
+ }
1386
+ console.error("Token exchange failed:", response2.status, response2.statusText, bodyText);
1387
+ throw new Error(`Token exchange failed: ${response2.status} ${response2.statusText}`);
1388
+ }
1389
+ const tokens = await response2.json();
1390
+ return {
1391
+ idToken: tokens.id_token,
1392
+ accessToken: tokens.access_token,
1393
+ refreshToken: tokens.refresh_token,
1394
+ customToken: tokens.custom_token,
1395
+ expiresAt: Date.now() + tokens.expires_in * 1e3
1396
+ };
1397
+ } catch (error2) {
1398
+ console.error("Token exchange request error:", error2);
1399
+ throw error2;
1360
1400
  }
1361
- const tokens = await response2.json();
1362
- return {
1363
- idToken: tokens.id_token,
1364
- accessToken: tokens.access_token,
1365
- refreshToken: tokens.refresh_token,
1366
- customToken: tokens.custom_token,
1367
- expiresAt: Date.now() + tokens.expires_in * 1e3
1368
- };
1369
1401
  }
1370
1402
  /**
1371
1403
  * Revoke tokens on server
@@ -31627,8 +31659,8 @@ var init_package = __esm({
31627
31659
  "package.json"() {
31628
31660
  package_default = {
31629
31661
  name: "@bonginkan/maria",
31630
- version: "4.2.10",
31631
- description: "\u{1F680} MARIA v4.2.10 - Enterprise AI Development Platform with 100% Command Availability. Features 74 production-ready commands with comprehensive fallback implementation, local LLM support, and zero external dependencies. Includes natural language coding, AI safety evaluation, intelligent evolution system, episodic memory with PII masking, and real-time monitoring dashboard. Built with TypeScript AST-powered code generation, OAuth2.0 + PKCE authentication, quantum-resistant cryptography, and enterprise-grade performance.",
31662
+ version: "4.2.13",
31663
+ description: "\u{1F680} MARIA v4.2.13 - Enterprise AI Development Platform with 100% Command Availability. Features 74 production-ready commands with comprehensive fallback implementation, local LLM support, and zero external dependencies. Includes natural language coding, AI safety evaluation, intelligent evolution system, episodic memory with PII masking, and real-time monitoring dashboard. Built with TypeScript AST-powered code generation, OAuth2.0 + PKCE authentication, quantum-resistant cryptography, and enterprise-grade performance.",
31632
31664
  keywords: [
31633
31665
  "ai",
31634
31666
  "cli",