@optimuslabs/harness-map-staging 1.5.31 → 1.5.34

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.
@@ -10,6 +10,7 @@
10
10
  * gateway) is allowed here; blocking those is a separate level. So is one whose API key, auth
11
11
  * token, Bedrock or Vertex setting overrides an `oauthAccount` left behind by an earlier login:
12
12
  * Claude Code is not using that login, the same precedence as the backend's derive_auth_method.
13
+ * An API key Claude Code was asked about and turned down does not count: it keeps using the login.
13
14
  */
14
15
  import { existsSync, readFileSync } from 'node:fs';
15
16
  import { homedir } from 'node:os';
@@ -18,7 +19,6 @@ import { readCursorEmail, readCursorTeamIds, vscdbPath, } from './log_config_fil
18
19
  import { resolveSqlite3Binary } from './log_config_files/runtime/sqlite_binary.js';
19
20
  import { readCodexIdentity } from './log_config_files/collection/codex_token_usage_collector.js';
20
21
  import { readDesktopActiveLogin } from './log_config_files/collection/claude_desktop_orgs_collector.js';
21
- const CLAUDE_CREDENTIAL_ENV = ['ANTHROPIC_API_KEY', 'ANTHROPIC_AUTH_TOKEN'];
22
22
  const CLAUDE_PROVIDER_ENV = ['CLAUDE_CODE_USE_BEDROCK', 'CLAUDE_CODE_USE_VERTEX'];
23
23
  /** The `env` block of Claude Code's user settings.json, or {} when there is none to read. */
24
24
  function claudeSettingsEnv(configDir) {
@@ -33,13 +33,25 @@ function claudeSettingsEnv(configDir) {
33
33
  }
34
34
  }
35
35
  /**
36
- * Whether Claude Code authenticates with something other than its claude.ai login: an API key or
37
- * auth token, or Bedrock / Vertex, from the session's environment or settings.json's `env`.
36
+ * Whether Claude Code turned this API key down. It asks once about a key it finds in its
37
+ * environment and keeps the last 20 characters of each one it rejected in `.claude.json`'s
38
+ * `customApiKeyResponses.rejected`; a rejected key is not used, the claude.ai login is.
38
39
  */
39
- function claudeUsesOtherCredentials(env, configDir) {
40
+ function apiKeyRejected(claudeJson, apiKey) {
41
+ const responses = claudeJson.customApiKeyResponses;
42
+ return Array.isArray(responses?.rejected) && responses.rejected.includes(apiKey.slice(-20));
43
+ }
44
+ /**
45
+ * Whether Claude Code authenticates with something other than its claude.ai login: an API key it
46
+ * has not rejected, an auth token, or Bedrock / Vertex, from the session's environment or
47
+ * settings.json's `env`.
48
+ */
49
+ function claudeUsesOtherCredentials(env, configDir, claudeJson) {
40
50
  const settingsEnv = claudeSettingsEnv(configDir);
41
51
  const value = (name) => String(env[name] ?? settingsEnv[name] ?? '').trim();
42
- return (CLAUDE_CREDENTIAL_ENV.some((name) => value(name) !== '') ||
52
+ const apiKey = value('ANTHROPIC_API_KEY');
53
+ return ((apiKey !== '' && !apiKeyRejected(claudeJson, apiKey)) ||
54
+ value('ANTHROPIC_AUTH_TOKEN') !== '' ||
43
55
  CLAUDE_PROVIDER_ENV.some((name) => ['1', 'true', 'yes', 'on'].includes(value(name).toLowerCase())));
44
56
  }
45
57
  /** The claude.ai org this Claude Code session is signed into, or null when there is none to check. */
@@ -48,10 +60,12 @@ export function readClaudeSignedInTenant(env = process.env) {
48
60
  // directory is checked rather than the default one.
49
61
  const configDir = (env.CLAUDE_CONFIG_DIR || '').trim();
50
62
  const path = configDir ? join(configDir, '.claude.json') : join(homedir(), '.claude.json');
51
- if (!existsSync(path) || claudeUsesOtherCredentials(env, configDir))
63
+ if (!existsSync(path))
52
64
  return null;
53
65
  try {
54
66
  const parsed = JSON.parse(readFileSync(path, 'utf8'));
67
+ if (claudeUsesOtherCredentials(env, configDir, parsed ?? {}))
68
+ return null;
55
69
  const account = parsed?.oauthAccount;
56
70
  const tenantId = typeof account?.organizationUuid === 'string' ? account.organizationUuid.trim() : '';
57
71
  if (!tenantId)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimuslabs/harness-map-staging",
3
- "version": "1.5.31",
3
+ "version": "1.5.34",
4
4
  "description": "CLI helpers for logging hardware UUIDs and posting startup payloads to Optimus Security.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -49,17 +49,17 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^24.10.1",
52
- "@vitest/coverage-v8": "^4.1.8",
53
- "@vitest/ui": "^4.1.8",
52
+ "@vitest/coverage-v8": "^4.1.12",
53
+ "@vitest/ui": "^4.1.12",
54
54
  "ts-node": "^10.9.2",
55
55
  "typescript": "^5.4.5",
56
- "vitest": "^4.1.8"
56
+ "vitest": "^4.1.12"
57
57
  },
58
58
  "dependencies": {
59
59
  "@optimuslabs/tofu-staging": "^0.1.18",
60
60
  "axios": "^1.20.0",
61
61
  "canonicalize": "^2.1.0",
62
- "smol-toml": "^1.7.1"
62
+ "smol-toml": "^1.9.1"
63
63
  },
64
64
  "publishConfig": {
65
65
  "access": "public"