claude-remote 0.1.6 → 0.1.8
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/server.js +47 -19
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -203,28 +203,32 @@ function maybeAttachHookSession(data, source) {
|
|
|
203
203
|
return;
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
206
|
+
const targetHasContent = fileLooksLikeTranscript(target.full);
|
|
207
|
+
|
|
208
|
+
if (source === 'session-start') {
|
|
209
|
+
// session-start is unreliable for --resume (fires twice, one is a
|
|
210
|
+
// snapshot-only session). Only accept when:
|
|
211
|
+
// 1. No session bound yet (first attach), OR
|
|
212
|
+
// 2. Expecting a switch (/clear), OR
|
|
213
|
+
// 3. Target has conversation content and current doesn't
|
|
214
|
+
if (currentSessionId && !expectingSwitch) {
|
|
214
215
|
const currentHasContent = transcriptPath && fileLooksLikeTranscript(transcriptPath);
|
|
215
|
-
if (
|
|
216
|
-
log(`Ignored
|
|
216
|
+
if (!targetHasContent || currentHasContent) {
|
|
217
|
+
log(`Ignored session-start: ${target.sessionId} (current=${currentSessionId} currentHasContent=${currentHasContent} targetHasContent=${targetHasContent})`);
|
|
217
218
|
return;
|
|
218
219
|
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
220
|
+
}
|
|
221
|
+
} else if (source === 'pre-tool-use') {
|
|
222
|
+
// pre-tool-use is the authoritative source — comes from the actually
|
|
223
|
+
// running Claude process. Always allow it to correct the session,
|
|
224
|
+
// as long as the target transcript has conversation content.
|
|
225
|
+
if (currentSessionId && currentSessionId !== target.sessionId && !targetHasContent) {
|
|
226
|
+
log(`Ignored pre-tool-use: ${target.sessionId} (no conversation content)`);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
// Other sources (e.g. stop) — only accept if matching current or no session
|
|
231
|
+
if (currentSessionId && currentSessionId !== target.sessionId && !expectingSwitch) {
|
|
228
232
|
log(`Ignored hook session from ${source}: ${target.sessionId} (current=${currentSessionId})`);
|
|
229
233
|
return;
|
|
230
234
|
}
|
|
@@ -953,6 +957,8 @@ function startTailing() {
|
|
|
953
957
|
markExpectingSwitch();
|
|
954
958
|
}
|
|
955
959
|
}
|
|
960
|
+
// Enrich Edit tool_use blocks with source file start line
|
|
961
|
+
enrichEditStartLines(event);
|
|
956
962
|
const record = { seq: ++eventSeq, event };
|
|
957
963
|
eventBuffer.push(record);
|
|
958
964
|
if (eventBuffer.length > EVENT_BUFFER_MAX) {
|
|
@@ -970,6 +976,28 @@ function startTailing() {
|
|
|
970
976
|
}, 300);
|
|
971
977
|
}
|
|
972
978
|
|
|
979
|
+
function enrichEditStartLines(event) {
|
|
980
|
+
const content = event.message && event.message.content;
|
|
981
|
+
if (!Array.isArray(content)) return;
|
|
982
|
+
for (const block of content) {
|
|
983
|
+
if (block.type !== 'tool_use' || block.name !== 'Edit') continue;
|
|
984
|
+
const input = block.input;
|
|
985
|
+
if (!input || !input.file_path || input.old_string === undefined) continue;
|
|
986
|
+
try {
|
|
987
|
+
const filePath = path.resolve(CWD, input.file_path);
|
|
988
|
+
const src = fs.readFileSync(filePath, 'utf8');
|
|
989
|
+
// Search for new_string first (edit likely already applied), fallback to old_string
|
|
990
|
+
const needle = input.new_string || input.old_string;
|
|
991
|
+
const idx = src.indexOf(needle);
|
|
992
|
+
if (idx >= 0) {
|
|
993
|
+
input._startLine = src.substring(0, idx).split('\n').length;
|
|
994
|
+
}
|
|
995
|
+
} catch {
|
|
996
|
+
// file not readable — skip enrichment
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
973
1001
|
function stopTailing() {
|
|
974
1002
|
if (tailTimer) { clearInterval(tailTimer); tailTimer = null; }
|
|
975
1003
|
if (switchWatcher) { clearInterval(switchWatcher); switchWatcher = null; }
|