@radnine/claude-session-daemon 0.6.5 → 0.6.7
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 +1 -1
- package/src/connections/action-cable-client.js +5 -1
- package/src/daemon.js +4 -2
- package/src/git-reset.js +16 -9
package/package.json
CHANGED
|
@@ -635,7 +635,7 @@ class ActionCableClient extends BaseConnection {
|
|
|
635
635
|
this._logger.info('Received session_activate', { sessionId, userId, claudeSessionId, resetGit });
|
|
636
636
|
|
|
637
637
|
try {
|
|
638
|
-
await this._daemon.activateSession(sessionId, {
|
|
638
|
+
const proc = await this._daemon.activateSession(sessionId, {
|
|
639
639
|
workingDir: this._config.workingDir,
|
|
640
640
|
claudeSessionId,
|
|
641
641
|
resetGit,
|
|
@@ -644,6 +644,10 @@ class ActionCableClient extends BaseConnection {
|
|
|
644
644
|
this.sendDaemonMessage({
|
|
645
645
|
type: 'session_activated',
|
|
646
646
|
session_id: sessionId,
|
|
647
|
+
// Report the actual Claude CLI session ID back to Rails so it can be
|
|
648
|
+
// persisted. Without this, Rails has nothing to send on reconnect and
|
|
649
|
+
// the daemon spawns a fresh CLI — losing all conversation context.
|
|
650
|
+
claude_session_id: proc.claudeSessionId,
|
|
647
651
|
stream_config: {
|
|
648
652
|
buffer_mode: 'line',
|
|
649
653
|
max_message_size: 8192,
|
package/src/daemon.js
CHANGED
|
@@ -156,11 +156,13 @@ class Daemon extends EventEmitter {
|
|
|
156
156
|
const shouldResume = !!claudeSessionId;
|
|
157
157
|
this._cancelledSessionIds.delete(sessionId);
|
|
158
158
|
|
|
159
|
-
// Reset git state to clean main when requested (scheduled sessions)
|
|
159
|
+
// Reset git state to clean main when requested (scheduled sessions).
|
|
160
|
+
// Awaited so spawn waits for a clean tree, but async under the hood so the
|
|
161
|
+
// event loop keeps servicing ActionCable pings during the git commands.
|
|
160
162
|
if (options.resetGit) {
|
|
161
163
|
const cwd = options.workingDir || this._config.workingDir;
|
|
162
164
|
this._logger.info('Resetting git state before activation', { sessionId, cwd });
|
|
163
|
-
resetGitState(cwd, this._logger);
|
|
165
|
+
await resetGitState(cwd, this._logger);
|
|
164
166
|
}
|
|
165
167
|
|
|
166
168
|
// Create new process
|
package/src/git-reset.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const { execFile } = require('node:child_process');
|
|
4
|
+
const { promisify } = require('node:util');
|
|
5
|
+
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
4
7
|
|
|
5
8
|
const EXEC_TIMEOUT = 15000; // 15 seconds per git command
|
|
6
9
|
|
|
@@ -11,48 +14,52 @@ const EXEC_TIMEOUT = 15000; // 15 seconds per git command
|
|
|
11
14
|
* Each step logs its result. Failures are logged but never thrown —
|
|
12
15
|
* session activation must not be blocked by git problems.
|
|
13
16
|
*
|
|
17
|
+
* Uses async execFile (not execFileSync) so the Node.js event loop stays
|
|
18
|
+
* responsive to ActionCable pings while git commands are running. A blocked
|
|
19
|
+
* event loop causes the ping watchdog to fire and force a WebSocket reconnect.
|
|
20
|
+
*
|
|
14
21
|
* @param {string} workingDir - The repo directory to reset
|
|
15
22
|
* @param {object} logger - Logger with .info() and .warn() methods
|
|
16
|
-
* @returns {{ stash: boolean, checkout: boolean, pull: boolean }} step results
|
|
23
|
+
* @returns {Promise<{ stash: boolean, checkout: boolean, pull: boolean }>} step results
|
|
17
24
|
*/
|
|
18
|
-
function resetGitState(workingDir, logger) {
|
|
25
|
+
async function resetGitState(workingDir, logger) {
|
|
19
26
|
const results = { stash: false, checkout: false, pull: false };
|
|
20
27
|
|
|
21
28
|
// Step 1: stash uncommitted changes
|
|
22
29
|
try {
|
|
23
|
-
const
|
|
30
|
+
const { stdout } = await execFileAsync('git', ['stash', '--include-untracked'], {
|
|
24
31
|
cwd: workingDir,
|
|
25
32
|
timeout: EXEC_TIMEOUT,
|
|
26
33
|
encoding: 'utf8',
|
|
27
34
|
});
|
|
28
35
|
results.stash = true;
|
|
29
|
-
logger.info('git stash completed', { output:
|
|
36
|
+
logger.info('git stash completed', { output: stdout.trim() });
|
|
30
37
|
} catch (err) {
|
|
31
38
|
logger.warn('git stash failed (continuing)', { error: err.message });
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
// Step 2: checkout main
|
|
35
42
|
try {
|
|
36
|
-
const
|
|
43
|
+
const { stdout } = await execFileAsync('git', ['checkout', 'main'], {
|
|
37
44
|
cwd: workingDir,
|
|
38
45
|
timeout: EXEC_TIMEOUT,
|
|
39
46
|
encoding: 'utf8',
|
|
40
47
|
});
|
|
41
48
|
results.checkout = true;
|
|
42
|
-
logger.info('git checkout main completed', { output:
|
|
49
|
+
logger.info('git checkout main completed', { output: stdout.trim() });
|
|
43
50
|
} catch (err) {
|
|
44
51
|
logger.warn('git checkout main failed (continuing)', { error: err.message });
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
// Step 3: pull latest
|
|
48
55
|
try {
|
|
49
|
-
const
|
|
56
|
+
const { stdout } = await execFileAsync('git', ['pull', 'origin', 'main'], {
|
|
50
57
|
cwd: workingDir,
|
|
51
58
|
timeout: EXEC_TIMEOUT,
|
|
52
59
|
encoding: 'utf8',
|
|
53
60
|
});
|
|
54
61
|
results.pull = true;
|
|
55
|
-
logger.info('git pull completed', { output:
|
|
62
|
+
logger.info('git pull completed', { output: stdout.trim() });
|
|
56
63
|
} catch (err) {
|
|
57
64
|
logger.warn('git pull failed (continuing)', { error: err.message });
|
|
58
65
|
}
|