@radnine/claude-session-daemon 0.7.4 → 0.8.0

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.4",
3
+ "version": "0.8.0",
4
4
  "description": "Node.js daemon for managing Claude CLI sessions",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -31,6 +31,7 @@ class ClaudeProcess extends EventEmitter {
31
31
  * @param {Function} [options._spawnFn] - For testing: replacement for child_process.spawn
32
32
  * @param {object} [options.sessionEnv] - Extra env vars to inject into the spawned process
33
33
  * @param {string} [options.systemPrompt] - Appended to Claude's default system prompt at spawn time via --append-system-prompt
34
+ * @param {string} [options.model] - Claude model id passed to the CLI via --model (e.g. claude-opus-4-8)
34
35
  */
35
36
  constructor(sessionId, options = {}) {
36
37
  super();
@@ -46,6 +47,8 @@ class ClaudeProcess extends EventEmitter {
46
47
  this._spawnFn = options._spawnFn || defaultSpawn;
47
48
  this._sessionEnv = options.sessionEnv || {};
48
49
  this._systemPrompt = options.systemPrompt || null;
50
+ this._model = options.model || null;
51
+ this._effort = options.effort || null;
49
52
 
50
53
  this._state = 'idle';
51
54
  this._child = null;
@@ -89,6 +92,14 @@ class ClaudeProcess extends EventEmitter {
89
92
 
90
93
  args.push('--replay-user-messages');
91
94
 
95
+ if (this._model) {
96
+ args.push('--model', this._model);
97
+ }
98
+
99
+ if (this._effort) {
100
+ args.push('--effort', this._effort);
101
+ }
102
+
92
103
  if (this._systemPrompt) {
93
104
  args.push('--append-system-prompt', this._systemPrompt);
94
105
  }
@@ -8,6 +8,7 @@ const WebSocket = require('ws');
8
8
  const { BaseConnection } = require('./base-connection');
9
9
  const { getGitContext } = require('../git-context');
10
10
  const { getClaudeAccount } = require('../claude-account');
11
+ const { getMachineEffort } = require('../machine-effort');
11
12
  const { scanPersonas, readPersonaBody } = require('../persona-scanner');
12
13
  const daemonPkg = require('../../package.json');
13
14
 
@@ -564,13 +565,15 @@ class ActionCableClient extends BaseConnection {
564
565
  async _sendDaemonRegistration() {
565
566
  this._logger.info('Sending daemon registration');
566
567
 
567
- const [gitContext, claudeAccount] = await Promise.all([
568
+ const [gitContext, claudeAccount, machineEffort] = await Promise.all([
568
569
  this._getGitContext(),
569
570
  this._getClaudeAccount(),
571
+ this._getMachineEffort(),
570
572
  ]);
571
573
 
572
574
  this.sendDaemonMessage({
573
575
  type: 'pilot_connect',
576
+ machine_effort: machineEffort,
574
577
  version: daemonPkg.version,
575
578
  auth: {
576
579
  token: this._authToken,
@@ -652,6 +655,8 @@ class ActionCableClient extends BaseConnection {
652
655
  const claudeSessionId = message.claude_session_id || undefined;
653
656
  const resetGit = !!message.reset_git_state;
654
657
  const systemPromptPath = message.system_prompt_path || undefined;
658
+ const model = message.model || undefined;
659
+ const effort = message.reasoning_effort || undefined;
655
660
  let systemPrompt = message.system_prompt || undefined;
656
661
 
657
662
  if (systemPromptPath) {
@@ -682,6 +687,8 @@ class ActionCableClient extends BaseConnection {
682
687
  claudeSessionId,
683
688
  resetGit,
684
689
  systemPrompt,
690
+ model,
691
+ effort,
685
692
  });
686
693
 
687
694
  this.sendDaemonMessage({
@@ -1145,10 +1152,11 @@ class ActionCableClient extends BaseConnection {
1145
1152
  * Send a heartbeat message to the server.
1146
1153
  */
1147
1154
  async _sendHeartbeat() {
1148
- const [gitContext, claudeAccount, personas] = await Promise.all([
1155
+ const [gitContext, claudeAccount, personas, machineEffort] = await Promise.all([
1149
1156
  this._getGitContext(),
1150
1157
  this._getClaudeAccount(),
1151
1158
  this._getPersonas(),
1159
+ this._getMachineEffort(),
1152
1160
  ]);
1153
1161
 
1154
1162
  this.sendDaemonMessage({
@@ -1160,6 +1168,7 @@ class ActionCableClient extends BaseConnection {
1160
1168
  resource_usage: this._getResourceUsage(),
1161
1169
  git_context: gitContext,
1162
1170
  claude_account: claudeAccount,
1171
+ machine_effort: machineEffort,
1163
1172
  personas,
1164
1173
  timestamp: new Date().toISOString(),
1165
1174
  });
@@ -1210,6 +1219,19 @@ class ActionCableClient extends BaseConnection {
1210
1219
  }
1211
1220
  }
1212
1221
 
1222
+ /**
1223
+ * Get this machine's effective default reasoning effort (CLAUDE_EFFORT env or
1224
+ * ~/.claude/settings.json `effort`). Returns null when unknown. 60s cache.
1225
+ */
1226
+ async _getMachineEffort() {
1227
+ try {
1228
+ return await getMachineEffort();
1229
+ } catch (err) {
1230
+ this._logger.warn('Failed to read machine effort', { error: err.message });
1231
+ return null;
1232
+ }
1233
+ }
1234
+
1213
1235
  /**
1214
1236
  * Get a summary of daemon sessions from the daemon health check.
1215
1237
  * @returns {object}
package/src/daemon.js CHANGED
@@ -180,6 +180,8 @@ class Daemon extends EventEmitter {
180
180
  permissionPort: this._permissionPort || null,
181
181
  sessionEnv: options.sessionEnv || {},
182
182
  systemPrompt: options.systemPrompt,
183
+ model: options.model,
184
+ effort: options.effort,
183
185
  logger: this._logger.child(`Session:${sessionId}`),
184
186
  });
185
187
 
@@ -0,0 +1,62 @@
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
+ // The reasoning-effort levels the Claude CLI accepts (`claude --effort <level>`).
11
+ // Anything outside this set is treated as unknown.
12
+ const ALLOWED_EFFORTS = ['low', 'medium', 'high', 'xhigh', 'max'];
13
+
14
+ /**
15
+ * Read this machine's effective default reasoning effort.
16
+ *
17
+ * The Claude CLI does not report its effective effort anywhere observable, so
18
+ * the daemon — which legitimately owns machine config — reads it directly.
19
+ * Precedence: the `CLAUDE_EFFORT` env var (the CLI's runtime override), then
20
+ * the `effort` key in `~/.claude/settings.json`. Returns null ("unknown") when
21
+ * neither source provides a valid level — never a fabricated default.
22
+ *
23
+ * Cached for 60s; returns null if the settings file is missing/malformed.
24
+ *
25
+ * @param {string} [filePath] - Override settings.json path for tests.
26
+ * @returns {Promise<string|null>}
27
+ */
28
+ async function getMachineEffort(filePath) {
29
+ const now = Date.now();
30
+ if (!filePath && _cache && _cache.expiresAt > now) {
31
+ return _cache.value;
32
+ }
33
+
34
+ let value = null;
35
+
36
+ const fromEnv = process.env.CLAUDE_EFFORT;
37
+ if (ALLOWED_EFFORTS.includes(fromEnv)) {
38
+ value = fromEnv;
39
+ } else {
40
+ const target = filePath || path.join(os.homedir(), '.claude', 'settings.json');
41
+ try {
42
+ const raw = await fs.readFile(target, 'utf8');
43
+ const parsed = JSON.parse(raw);
44
+ if (parsed && ALLOWED_EFFORTS.includes(parsed.effort)) {
45
+ value = parsed.effort;
46
+ }
47
+ } catch (_) {
48
+ value = null;
49
+ }
50
+ }
51
+
52
+ if (!filePath) {
53
+ _cache = { value, expiresAt: now + CACHE_TTL_MS };
54
+ }
55
+ return value;
56
+ }
57
+
58
+ function _resetCacheForTests() {
59
+ _cache = null;
60
+ }
61
+
62
+ module.exports = { getMachineEffort, ALLOWED_EFFORTS, _resetCacheForTests };