This commit is contained in:
Raven Scott
2026-04-21 20:05:57 -04:00
parent 064c2a9338
commit 17af3ac65f
41 changed files with 1428 additions and 47 deletions
+68
View File
@@ -0,0 +1,68 @@
/**
* Swarm chat CLI — uses ctx.bareOsChat* when the booter exposes swarm chat (bare-os-chat-v1).
*/
async function run(ctx, argv) {
const cs = ctx.bareOsChatSend
const sub = argv[1] || ''
const rest = argv.slice(2).join(' ').trim()
if (sub === 'send' && rest) {
if (typeof cs !== 'function') {
ctx.console.error(
'chat: bareOsChatSend unavailable — stock hosts enable swarm chat unless BARE_OS_PROTOMUX_CHAT_CHANNEL=0'
)
ctx.exitCode = 1
return
}
const r = cs.call(ctx, rest)
if (r && r.ok === false) ctx.exitCode = 1
return
}
if (sub === 'history') {
const n = argv[2] ? Number.parseInt(argv[2], 10) : 20
const hist =
typeof ctx.vfs?.readFile === 'function'
? await ctx.vfs.readFile('/proc/bare_os/chat.json')
: null
if (hist) ctx.console.log(ctx.b4a.toString(hist).trimEnd())
else if (typeof ctx.bareOsReadProcMetricsLive === 'function') {
ctx.console.log(JSON.stringify(ctx.bareOsReadProcMetricsLive(), null, 2))
}
void n
return
}
if (sub === 'who') {
ctx.console.log(JSON.stringify(ctx.bareOsChatPresence?.() ?? {}, null, 2))
return
}
if (sub === 'join') {
ctx.console.log(
'chat join: only the general room is implemented; you are already in general when chat is enabled.'
)
return
}
if (typeof ctx.readLine !== 'function' || typeof cs !== 'function') {
ctx.console.error(
'chat: interactive mode requires bareOsChatSend and readLine (host booter; chat off if BARE_OS_PROTOMUX_CHAT_CHANNEL=0)'
)
ctx.exitCode = 1
return
}
ctx.console.log('[chat] general room — type a line; /quit to exit')
while (true) {
const line = await ctx.readLine('chat> ')
if (line == null) break
const t = line.trim()
if (t === '/quit' || t === '/exit') break
if (!t) continue
const r = cs.call(ctx, t)
if (r && r.ok === false) {
ctx.console.error('chat: send failed')
}
}
}