Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

1.2 KB
Raw Blame
// Delete an agent over the daemon's WebSocket. Usage: node dsh-delete.mjs <agentId>
import ws_ from '../../cli/node_modules/ws/index.js'
const { WebSocket } = ws_
import { CREDENTIAL_REFUSED, openDaemonBridge } from './local-credential.mjs'
const [agentId] = process.argv.slice(2)
const machineId = process.argv[3] ?? (() => { console.error('usage: node dsh-delete.mjs <agentId> <machineId>'); process.exit(2) })()
const ws = openDaemonBridge(WebSocket)
ws.on('unexpected-response', (_req, res) => { console.error(res.statusCode === 401 ? CREDENTIAL_REFUSED : `Unexpected server response: ${res.statusCode}`); process.exit(1) })
ws.on('open', () => {
  ws.send(JSON.stringify({ type: 'machine_select', payload: { machineId, localProtocolVersion: 1 } }))
  ws.once('message', (raw) => {
    const f = JSON.parse(raw.toString()); console.log('handshake', f.type)
    ws.send(JSON.stringify({ type: 'agent_delete', payload: { agentId } }))
    setTimeout(() => { ws.close(); process.exit(0) }, 4000)
  })
})
ws.on('message', (raw) => { const f = JSON.parse(raw.toString()); if (f.type === 'agent_deleted' || f.type === 'agent_delete_result') console.log(f.type, JSON.stringify(f.payload).slice(0, 120)) })
ws.on('error', (e) => { console.error(e.message); process.exit(1) })