@radnine/claude-session-daemon 0.7.0 → 0.7.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.
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.2",
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 };
package/src/config.js CHANGED
@@ -23,7 +23,7 @@ function loadConfig() {
23
23
  workingDir: env.CLAUDE_WORKING_DIR || process.cwd(),
24
24
 
25
25
  // Maximum concurrent sessions
26
- maxSessions: intEnv(env.CLAUDE_MAX_SESSIONS, 10),
26
+ maxSessions: intEnv(env.CLAUDE_MAX_SESSIONS, 15),
27
27
 
28
28
  // Anthropic API key passed through to Claude CLI
29
29
  anthropicApiKey: env.ANTHROPIC_API_KEY || null,
@@ -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
 
@@ -853,7 +858,9 @@ class ActionCableClient extends BaseConnection {
853
858
 
854
859
  try {
855
860
  await this._daemon.terminateSession(sessionId);
856
- this._sendSessionStateUpdate(sessionId, { status: 'deactivated' });
861
+ // Rails Session#status only allows active/paused/terminated — sending
862
+ // 'deactivated' here raises RecordInvalid on the server.
863
+ this._sendSessionStateUpdate(sessionId, { status: 'terminated' });
857
864
  } catch (err) {
858
865
  this._logger.error('Failed to deactivate session', { sessionId, error: err.message });
859
866
  }
@@ -1102,7 +1109,10 @@ class ActionCableClient extends BaseConnection {
1102
1109
  * Send a heartbeat message to the server.
1103
1110
  */
1104
1111
  async _sendHeartbeat() {
1105
- const gitContext = await this._getGitContext();
1112
+ const [gitContext, claudeAccount] = await Promise.all([
1113
+ this._getGitContext(),
1114
+ this._getClaudeAccount(),
1115
+ ]);
1106
1116
 
1107
1117
  this.sendDaemonMessage({
1108
1118
  type: 'heartbeat',
@@ -1112,6 +1122,7 @@ class ActionCableClient extends BaseConnection {
1112
1122
  session_summary: this._getSessionSummary(),
1113
1123
  resource_usage: this._getResourceUsage(),
1114
1124
  git_context: gitContext,
1125
+ claude_account: claudeAccount,
1115
1126
  timestamp: new Date().toISOString(),
1116
1127
  });
1117
1128
  }
@@ -1129,6 +1140,18 @@ class ActionCableClient extends BaseConnection {
1129
1140
  }
1130
1141
  }
1131
1142
 
1143
+ /**
1144
+ * Get the currently logged-in Claude account from ~/.claude.json (60s cache).
1145
+ */
1146
+ async _getClaudeAccount() {
1147
+ try {
1148
+ return await getClaudeAccount();
1149
+ } catch (err) {
1150
+ this._logger.warn('Failed to read Claude account', { error: err.message });
1151
+ return null;
1152
+ }
1153
+ }
1154
+
1132
1155
  /**
1133
1156
  * Get a summary of daemon sessions from the daemon health check.
1134
1157
  * @returns {object}