project-cypher 0.6.0 → 0.6.1
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/bin/cypher.js +5 -1
- package/package.json +1 -1
package/bin/cypher.js
CHANGED
|
@@ -111,9 +111,13 @@ const cmds = {
|
|
|
111
111
|
const ws = new WebSocket(`${wsOf(c.server)}/agent?token=${encodeURIComponent(c.token)}`);
|
|
112
112
|
const tx = m => ws.readyState === 1 && ws.send(JSON.stringify(m));
|
|
113
113
|
ws.on('open', () => { ws.opened = true; retry = 1000; tx({ type: 'hello', name: os.hostname(), projects: c.projects.map(({ id, name }) => ({ id, name })) }); console.log(`connected as ${os.hostname()} with ${c.projects.length} project(s). Ctrl+C to stop.`); });
|
|
114
|
+
// pick up `cypher add` / `remove` while running: re-announce projects when the config changes
|
|
115
|
+
let sig = JSON.stringify(load().projects.map(p => p.id));
|
|
116
|
+
const watch = setInterval(() => { const n = JSON.stringify(load().projects.map(p => p.id)); if (n !== sig) { sig = n; const ps = load().projects; tx({ type: 'hello', name: os.hostname(), projects: ps.map(({ id, name }) => ({ id, name })) }); console.log(`projects updated: ${ps.length}`); } }, 2000);
|
|
117
|
+
ws.on('close', () => clearInterval(watch));
|
|
114
118
|
ws.on('message', raw => {
|
|
115
119
|
let m; try { m = JSON.parse(raw); } catch { return; }
|
|
116
|
-
const proj =
|
|
120
|
+
const proj = load().projects.find(p => p.id === m.projectId); const ctx = { reqId: m.reqId, projectId: m.projectId };
|
|
117
121
|
if (m.type === 'stop') return runs.get(m.projectId)?.kill('SIGINT');
|
|
118
122
|
if (m.type !== 'prompt') return;
|
|
119
123
|
if (!proj) return tx({ ...ctx, type: 'error', message: 'unknown project' });
|