// abctl.js — one-shot client for the M4 autobase daemon (ceremony + polling).
// usage: bare abctl.js <client-sock> "<protocol line>"
// Prints the daemon's single reply line (nothing for fire-and-forget `store`).
import net from 'bare-net'
import process from 'bare-process'
const sock = process.argv[2]
const line = process.argv[3]
if (!sock || line === undefined) { console.error('usage: abctl.js <sock> "<line>"'); process.exit(1) }
const noReply = line.startsWith('store ')
const c = net.createConnection(sock)
let buf = ''
c.on('connect', () => {
c.write(line + '\n')
if (noReply) setTimeout(() => { c.destroy(); process.exit(0) }, 60)
})
c.on('data', (d) => {
buf += d.toString()
const nl = buf.indexOf('\n')
if (nl !== -1) { console.log(buf.slice(0, nl)); c.destroy(); process.exit(0) }
})
c.on('error', (e) => { console.error('ERR ' + e.message); process.exit(2) })