@radnine/claude-session-daemon 0.7.0 → 0.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radnine/claude-session-daemon",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Node.js daemon for managing Claude CLI sessions",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs').promises;
4
+ const os = require('node:os');
5
+ const path = require('node:path');
6
+
7
+ const CACHE_TTL_MS = 60_000;
8
+ let _cache = null; // { value, expiresAt }
9
+
10
+ /**
11
+ * Read the logged-in Claude account from ~/.claude.json.
12
+ *
13
+ * The Claude CLI persists the active OAuth account at `oauthAccount.emailAddress`.
14
+ * We surface email + account/org UUIDs so the UI can warn when the user is logged
15
+ * into a different account than they expect (different rate limits).
16
+ *
17
+ * Cached for 60s; returns null if the file is missing/malformed or the field is absent.
18
+ *
19
+ * @param {string} [filePath] - Override path for tests.
20
+ * @returns {Promise<{email: string, account_uuid: string|null, organization_uuid: string|null}|null>}
21
+ */
22
+ async function getClaudeAccount(filePath) {
23
+ const now = Date.now();
24
+ if (!filePath && _cache && _cache.expiresAt > now) {
25
+ return _cache.value;
26
+ }
27
+
28
+ const target = filePath || path.join(os.homedir(), '.claude.json');
29
+ let value = null;
30
+
31
+ try {
32
+ const raw = await fs.readFile(target, 'utf8');
33
+ const parsed = JSON.parse(raw);
34
+ const oauth = parsed && parsed.oauthAccount;
35
+ if (oauth && typeof oauth.emailAddress === 'string' && oauth.emailAddress.length > 0) {
36
+ value = {
37
+ email: oauth.emailAddress,
38
+ account_uuid: oauth.accountUuid || null,
39
+ organization_uuid: oauth.organizationUuid || null,
40
+ };
41
+ }
42
+ } catch (_) {
43
+ value = null;
44
+ }
45
+
46
+ if (!filePath) {
47
+ _cache = { value, expiresAt: now + CACHE_TTL_MS };
48
+ }
49
+ return value;
50
+ }
51
+
52
+ function _resetCacheForTests() {
53
+ _cache = null;
54
+ }
55
+
56
+ module.exports = { getClaudeAccount, _resetCacheForTests };
@@ -7,6 +7,7 @@ const fs = require('node:fs').promises;
7
7
  const WebSocket = require('ws');
8
8
  const { BaseConnection } = require('./base-connection');
9
9
  const { getGitContext } = require('../git-context');
10
+ const { getClaudeAccount } = require('../claude-account');
10
11
  const daemonPkg = require('../../package.json');
11
12
 
12
13
  /**
@@ -562,7 +563,10 @@ class ActionCableClient extends BaseConnection {
562
563
  async _sendDaemonRegistration() {
563
564
  this._logger.info('Sending daemon registration');
564
565
 
565
- const gitContext = await this._getGitContext();
566
+ const [gitContext, claudeAccount] = await Promise.all([
567
+ this._getGitContext(),
568
+ this._getClaudeAccount(),
569
+ ]);
566
570
 
567
571
  this.sendDaemonMessage({
568
572
  type: 'pilot_connect',
@@ -579,6 +583,7 @@ class ActionCableClient extends BaseConnection {
579
583
  working_directory: this._workingDir,
580
584
  },
581
585
  git_context: gitContext,
586
+ claude_account: claudeAccount,
582
587
  });
583
588
  }
584
589
 
@@ -1102,7 +1107,10 @@ class ActionCableClient extends BaseConnection {
1102
1107
  * Send a heartbeat message to the server.
1103
1108
  */
1104
1109
  async _sendHeartbeat() {
1105
- const gitContext = await this._getGitContext();
1110
+ const [gitContext, claudeAccount] = await Promise.all([
1111
+ this._getGitContext(),
1112
+ this._getClaudeAccount(),
1113
+ ]);
1106
1114
 
1107
1115
  this.sendDaemonMessage({
1108
1116
  type: 'heartbeat',
@@ -1112,6 +1120,7 @@ class ActionCableClient extends BaseConnection {
1112
1120
  session_summary: this._getSessionSummary(),
1113
1121
  resource_usage: this._getResourceUsage(),
1114
1122
  git_context: gitContext,
1123
+ claude_account: claudeAccount,
1115
1124
  timestamp: new Date().toISOString(),
1116
1125
  });
1117
1126
  }
@@ -1129,6 +1138,18 @@ class ActionCableClient extends BaseConnection {
1129
1138
  }
1130
1139
  }
1131
1140
 
1141
+ /**
1142
+ * Get the currently logged-in Claude account from ~/.claude.json (60s cache).
1143
+ */
1144
+ async _getClaudeAccount() {
1145
+ try {
1146
+ return await getClaudeAccount();
1147
+ } catch (err) {
1148
+ this._logger.warn('Failed to read Claude account', { error: err.message });
1149
+ return null;
1150
+ }
1151
+ }
1152
+
1132
1153
  /**
1133
1154
  * Get a summary of daemon sessions from the daemon health check.
1134
1155
  * @returns {object}