@cliphijack/santaclaude 0.9.5 → 1.0.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 +63 -16
package/package.json
CHANGED
package/santaclaude.js
CHANGED
|
@@ -186,29 +186,76 @@ async function run(conf) {
|
|
|
186
186
|
execFileSync('tmux', ['send-keys', '-t', w, '-l', String(cmd.text || '')]);
|
|
187
187
|
setTimeout(() => { try { execFileSync('tmux', ['send-keys', '-t', w, 'Enter']); } catch (e) {} }, 300);
|
|
188
188
|
console.log(` ⌨️ 입력 → ${w}: ${String(cmd.text || '').slice(0, 50)}`);
|
|
189
|
+
} else if (cmd.action === 'key') {
|
|
190
|
+
// 플로팅 컨트롤 — 특수키 그대로 전달 (Escape, C-c, Up 등)
|
|
191
|
+
const w = (cmd.name && windowExists(session, cmd.name)) ? (session + ':' + cmd.name) : pane;
|
|
192
|
+
execFileSync('tmux', ['send-keys', '-t', w, String(cmd.key || '')]);
|
|
193
|
+
console.log(` ⌨️ 키 → ${w}: ${cmd.key}`);
|
|
189
194
|
}
|
|
190
195
|
} catch (e) { console.warn(` ⚠️ 제어 실패(${cmd.action} ${cmd.name}): ${e.message}`); }
|
|
191
196
|
}
|
|
192
197
|
|
|
193
|
-
|
|
198
|
+
// 스킬 클린등록 수거 — claude가 ~/.santaclaude/publish/<name>/ + READY 만들면 마켓에 자동 등록
|
|
199
|
+
const PUBDIR = path.join(os.homedir(), '.santaclaude', 'publish');
|
|
200
|
+
function readDirFiles(dir, base) {
|
|
201
|
+
let out = [];
|
|
202
|
+
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
203
|
+
if (e.name === 'READY') continue;
|
|
204
|
+
const fp = path.join(dir, e.name);
|
|
205
|
+
if (e.isDirectory()) out = out.concat(readDirFiles(fp, base));
|
|
206
|
+
else { try { out.push({ path: path.relative(base, fp).replace(/\\/g, '/'), content: fs.readFileSync(fp, 'utf8') }); } catch (e) {} }
|
|
207
|
+
}
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
async function scanPublish() {
|
|
194
211
|
try {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (!
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
212
|
+
if (!fs.existsSync(PUBDIR)) return;
|
|
213
|
+
for (const name of fs.readdirSync(PUBDIR)) {
|
|
214
|
+
const d = path.join(PUBDIR, name);
|
|
215
|
+
try { if (!fs.statSync(d).isDirectory()) continue; } catch (e) { continue; }
|
|
216
|
+
if (!fs.existsSync(path.join(d, 'READY'))) continue; // claude가 다 끝냈다는 신호
|
|
217
|
+
const files = readDirFiles(d, d);
|
|
218
|
+
if (!files.length) { try { fs.rmSync(d, { recursive: true, force: true }); } catch (e) {} continue; }
|
|
219
|
+
const publisher = conf.publisher || (String(token).replace(/^sc_/, '').slice(0, 8)) || 'me';
|
|
220
|
+
try {
|
|
221
|
+
const r = await fetch(api + '/api/skill', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token, name, publisher, files, public: true }) });
|
|
222
|
+
const j = await r.json();
|
|
223
|
+
if (j.ok) {
|
|
224
|
+
console.log(` 🏪 스킬 "${name}" 마켓 클린등록 완료`);
|
|
225
|
+
try { fs.rmSync(d, { recursive: true, force: true }); } catch (e) {}
|
|
226
|
+
execFileSync('tmux', ['send-keys', '-t', pane, '-l', '🏪 "' + name + '" 마켓에 클린 등록됐어!']);
|
|
227
|
+
setTimeout(() => { try { execFileSync('tmux', ['send-keys', '-t', pane, 'Enter']); } catch (e) {} }, 300);
|
|
228
|
+
} else { console.warn(` 스킬 등록 실패(${name}): ${j.error}`); try { fs.unlinkSync(path.join(d, 'READY')); } catch (e) {} }
|
|
229
|
+
} catch (e) { console.error('[scan fetch err]', e.message); }
|
|
206
230
|
}
|
|
207
|
-
} catch (e) { console.error('[
|
|
231
|
+
} catch (e) { console.error('[scan err]', e.message); }
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// 예약 발사(job) → 해당 탭에 주입
|
|
235
|
+
function onJob(j) {
|
|
236
|
+
if (!paneExists(session)) { if (!warned) { console.warn(` ⚠️ 작업장 "${session}" 없음 — 보류`); warned = true; } return; }
|
|
237
|
+
warned = false;
|
|
238
|
+
const tname = j.target && String(j.target).trim();
|
|
239
|
+
const tgt = (tname && windowExists(session, tname)) ? (session + ':' + tname) : pane;
|
|
240
|
+
console.log(`[발사] ${new Date().toISOString()} → ${tgt}: ${String(j.message).slice(0, 60)}`);
|
|
241
|
+
try { inject(tgt, '[SantaClaude] ' + j.message); } catch (e) { console.warn(` 주입 실패(${tgt}): ${e.message}`); }
|
|
242
|
+
}
|
|
243
|
+
function sendHb() { if (ws && ws.readyState === 1) { try { ws.send(JSON.stringify({ type: 'hb', pane, sessions: listWindows(session), screens: captureAll(session) })); } catch (e) {} } }
|
|
244
|
+
|
|
245
|
+
// ── WebSocket 상시 연결 (폴링 제거 — DO가 예약/명령을 push) ──
|
|
246
|
+
const wsUrl = api.replace(/^http/, 'ws') + '/ws?token=' + encodeURIComponent(token);
|
|
247
|
+
let ws = null, hbIv = null;
|
|
248
|
+
function connectWS() {
|
|
249
|
+
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); });
|
|
251
|
+
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); });
|
|
253
|
+
ws.addEventListener('error', () => { try { ws.close(); } catch (e) {} });
|
|
208
254
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
255
|
+
if (typeof WebSocket === 'undefined') { console.error(' ⚠️ 이 node는 WebSocket 미지원(18+ 필요). node 버전 확인.'); process.exit(1); }
|
|
256
|
+
connectWS();
|
|
257
|
+
const scanIv = setInterval(scanPublish, Math.max(every, 10000)); // 로컬 클린등록 폴더 감지(주기)
|
|
258
|
+
process.on('SIGINT', () => { clearInterval(hbIv); clearInterval(scanIv); try { ws && ws.close(); } catch (e) {} console.log('\n🛷 커넥터 종료. 너의 루돌프들은 자러 간다.'); process.exit(0); });
|
|
212
259
|
}
|
|
213
260
|
|
|
214
261
|
async function main() {
|