@cliphijack/santaclaude 0.2.0 → 0.4.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 +1 -1
- package/santaclaude.js +36 -7
package/package.json
CHANGED
package/santaclaude.js
CHANGED
|
@@ -35,14 +35,21 @@ function inject(pane, message) {
|
|
|
35
35
|
execFileSync('tmux', ['send-keys', '-t', pane, '-l', oneLine]);
|
|
36
36
|
setTimeout(() => { try { execFileSync('tmux', ['send-keys', '-t', pane, 'Enter']); } catch (e) {} }, 350);
|
|
37
37
|
}
|
|
38
|
-
//
|
|
39
|
-
function spawnClaude(session, cmd) {
|
|
40
|
-
|
|
38
|
+
// tmux 세션 새로 만들고 그 안에 claude 자동 실행 (cwd 지정 시 그 폴더에서 = 프로젝트별 분리)
|
|
39
|
+
function spawnClaude(session, cmd, cwd) {
|
|
40
|
+
const a = ['new-session', '-d', '-s', session];
|
|
41
|
+
if (cwd) a.push('-c', cwd);
|
|
42
|
+
execFileSync('tmux', a);
|
|
41
43
|
try { execFileSync('sh', ['-c', 'sleep 1']); } catch (e) {} // 셸 초기화 대기
|
|
42
44
|
execFileSync('tmux', ['send-keys', '-t', session, '-l', cmd]);
|
|
43
45
|
try { execFileSync('sh', ['-c', 'sleep 0.3']); } catch (e) {}
|
|
44
46
|
execFileSync('tmux', ['send-keys', '-t', session, 'Enter']);
|
|
45
47
|
}
|
|
48
|
+
// 살아있는 tmux 세션 목록
|
|
49
|
+
function listSessions() {
|
|
50
|
+
try { return execFileSync('tmux', ['list-sessions', '-F', '#{session_name}'], { encoding: 'utf8' }).trim().split('\n').filter(Boolean); }
|
|
51
|
+
catch (e) { return []; }
|
|
52
|
+
}
|
|
46
53
|
|
|
47
54
|
async function post(api, p, body) {
|
|
48
55
|
const r = await fetch(api + p, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
|
@@ -70,15 +77,37 @@ async function run(conf) {
|
|
|
70
77
|
console.warn(` ⚠️ tmux "${session}" 세션 없음 (--no-spawn) — 직접 띄워줘.`);
|
|
71
78
|
}
|
|
72
79
|
|
|
80
|
+
function runControl(cmd) {
|
|
81
|
+
try {
|
|
82
|
+
if (cmd.action === 'create') {
|
|
83
|
+
if (paneExists(cmd.name)) { console.log(` 🦌 "${cmd.name}" 이미 있어 — 새로 안 띄움`); return; }
|
|
84
|
+
spawnClaude(cmd.name, claudeCmd, cmd.cwd || undefined);
|
|
85
|
+
console.log(` 🦌 새 루돌프 "${cmd.name}"${cmd.cwd ? ' @' + cmd.cwd : ''} 띄움 (tmux attach -t ${cmd.name} 로 로그인 1회)`);
|
|
86
|
+
} else if (cmd.action === 'kill') {
|
|
87
|
+
execFileSync('tmux', ['kill-session', '-t', cmd.name]);
|
|
88
|
+
console.log(` 💤 루돌프 "${cmd.name}" 닫음`);
|
|
89
|
+
}
|
|
90
|
+
} catch (e) { console.warn(` ⚠️ 제어 실패(${cmd.action} ${cmd.name}): ${e.message}`); }
|
|
91
|
+
}
|
|
92
|
+
|
|
73
93
|
async function tick() {
|
|
74
94
|
try {
|
|
75
|
-
post(api, '/api/heartbeat', { token, pane }).catch(() => {});
|
|
95
|
+
post(api, '/api/heartbeat', { token, pane, sessions: listSessions() }).catch(() => {});
|
|
96
|
+
post(api, '/api/control/claim', { token }).then((c) => { for (const cmd of (c && c.commands) || []) runControl(cmd); }).catch(() => {});
|
|
76
97
|
const d = await post(api, '/api/jobs/claim', { token });
|
|
77
98
|
for (const j of (d.jobs || [])) {
|
|
78
|
-
|
|
99
|
+
// 잡의 대상 세션 우선, 없으면 기본 pane. 대상 세션이 없으면 기본 pane으로 폴백
|
|
100
|
+
let tpane = (j.target && String(j.target).trim()) || pane;
|
|
101
|
+
if (!paneExists(tpane)) {
|
|
102
|
+
if (conf.spawn !== false && tpane !== pane) {
|
|
103
|
+
try { spawnClaude(String(tpane).split(':')[0], claudeCmd); console.log(` 🦌 대상 "${tpane}" 세션이 없어서 새로 띄웠어 (tmux attach 로 로그인 1회).`); }
|
|
104
|
+
catch (e) { tpane = pane; }
|
|
105
|
+
} else if (!paneExists(tpane)) { tpane = pane; }
|
|
106
|
+
}
|
|
107
|
+
if (!paneExists(tpane)) { if (!warned) { console.warn(` ⚠️ 주입할 세션 "${tpane}" 없음 — 보류`); warned = true; } continue; }
|
|
79
108
|
warned = false;
|
|
80
|
-
console.log(`[발사] ${new Date().toISOString()} → ${
|
|
81
|
-
inject(
|
|
109
|
+
console.log(`[발사] ${new Date().toISOString()} → ${tpane}: ${String(j.message).slice(0, 60)}`);
|
|
110
|
+
inject(tpane, '[SantaClaude] ' + j.message);
|
|
82
111
|
}
|
|
83
112
|
} catch (e) { console.error('[폴링 오류]', e.message); }
|
|
84
113
|
}
|