@cliphijack/santaclaude 1.0.0 → 1.0.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 +1 -1
- package/santaclaude.js +24 -7
package/package.json
CHANGED
package/santaclaude.js
CHANGED
|
@@ -240,22 +240,39 @@ async function run(conf) {
|
|
|
240
240
|
console.log(`[발사] ${new Date().toISOString()} → ${tgt}: ${String(j.message).slice(0, 60)}`);
|
|
241
241
|
try { inject(tgt, '[SantaClaude] ' + j.message); } catch (e) { console.warn(` 주입 실패(${tgt}): ${e.message}`); }
|
|
242
242
|
}
|
|
243
|
-
function sendHb() { if (ws && ws.readyState === 1) { try { ws.send(JSON.stringify({ type: 'hb', pane, sessions: listWindows(session)
|
|
243
|
+
function sendHb() { if (ws && ws.readyState === 1) { try { ws.send(JSON.stringify({ type: 'hb', pane, sessions: listWindows(session) })); } catch (e) {} } }
|
|
244
|
+
// 화면 미러 — 변경됐을 때만 전송(claude 멈추면 0). 2.5초 체크라 응답 직후 빠르게 반영
|
|
245
|
+
let lastScr = '';
|
|
246
|
+
function sendScreen() { if (!ws || ws.readyState !== 1) return; let cur; try { cur = JSON.stringify(captureAll(session)); } catch (e) { return; } if (cur === lastScr) return; lastScr = cur; try { ws.send(JSON.stringify({ type: 'screen', screens: JSON.parse(cur) })); } catch (e) {} }
|
|
244
247
|
|
|
245
248
|
// ── WebSocket 상시 연결 (폴링 제거 — DO가 예약/명령을 push) ──
|
|
246
249
|
const wsUrl = api.replace(/^http/, 'ws') + '/ws?token=' + encodeURIComponent(token);
|
|
247
|
-
let ws = null, hbIv = null;
|
|
250
|
+
let ws = null, hbIv = null, scrIv = null;
|
|
248
251
|
function connectWS() {
|
|
249
252
|
try { ws = new WebSocket(wsUrl); } catch (e) { console.error(' WebSocket 생성 실패:', e.message); setTimeout(connectWS, 5000); return; }
|
|
250
|
-
ws.addEventListener('open', () => { console.log(' 🔌 클라우드 연결됨 (WebSocket).'); sendHb(); clearInterval(hbIv); hbIv = setInterval(sendHb, every); });
|
|
253
|
+
ws.addEventListener('open', () => { console.log(' 🔌 클라우드 연결됨 (WebSocket).'); lastScr = ''; sendHb(); sendScreen(); clearInterval(hbIv); clearInterval(scrIv); hbIv = setInterval(sendHb, Math.max(every, 15000)); scrIv = setInterval(sendScreen, 2500); });
|
|
251
254
|
ws.addEventListener('message', (e) => { let m; try { m = JSON.parse(typeof e.data === 'string' ? e.data : e.data.toString()); } catch { return; } if (m.type === 'job') onJob(m); else if (m.type === 'ctl') runControl(m.cmd); });
|
|
252
|
-
ws.addEventListener('close', () => { clearInterval(hbIv); console.log(' 🔌 연결 끊김 — 5초 후 재연결'); setTimeout(connectWS, 5000); });
|
|
255
|
+
ws.addEventListener('close', () => { clearInterval(hbIv); clearInterval(scrIv); console.log(' 🔌 연결 끊김 — 5초 후 재연결'); setTimeout(connectWS, 5000); });
|
|
253
256
|
ws.addEventListener('error', () => { try { ws.close(); } catch (e) {} });
|
|
254
257
|
}
|
|
255
|
-
|
|
256
|
-
|
|
258
|
+
// 폴링 폴백 (node<21 = WebSocket 미지원) — 워커가 DO 백엔드라 폴링이어도 KV write 0
|
|
259
|
+
async function pollTick() {
|
|
260
|
+
try {
|
|
261
|
+
post(api, '/api/heartbeat', { token, pane, sessions: listWindows(session), screens: captureAll(session) }).catch(() => {});
|
|
262
|
+
post(api, '/api/control/claim', { token }).then((c) => { for (const cmd of (c && c.commands) || []) runControl(cmd); }).catch(() => {});
|
|
263
|
+
const d = await post(api, '/api/jobs/claim', { token });
|
|
264
|
+
for (const j of (d.jobs || [])) onJob(j);
|
|
265
|
+
} catch (e) {}
|
|
266
|
+
}
|
|
257
267
|
const scanIv = setInterval(scanPublish, Math.max(every, 10000)); // 로컬 클린등록 폴더 감지(주기)
|
|
258
|
-
|
|
268
|
+
if (typeof WebSocket !== 'undefined') {
|
|
269
|
+
connectWS();
|
|
270
|
+
process.on('SIGINT', () => { clearInterval(hbIv); clearInterval(scrIv); clearInterval(scanIv); try { ws && ws.close(); } catch (e) {} console.log('\n🛷 커넥터 종료. 너의 루돌프들은 자러 간다.'); process.exit(0); });
|
|
271
|
+
} else {
|
|
272
|
+
console.log(` ℹ️ 이 node는 WebSocket(21+) 미지원 — 폴링 모드로 동작 (DO 백엔드라 KV write 0 동일, 발사 ±${Math.round(every / 1000)}초). node 21+ 쓰면 자동 WebSocket.`);
|
|
273
|
+
await pollTick(); const pollIv = setInterval(pollTick, every);
|
|
274
|
+
process.on('SIGINT', () => { clearInterval(pollIv); clearInterval(scanIv); console.log('\n🛷 커넥터 종료. 너의 루돌프들은 자러 간다.'); process.exit(0); });
|
|
275
|
+
}
|
|
259
276
|
}
|
|
260
277
|
|
|
261
278
|
async function main() {
|