thinkpool-pair 0.6.26 → 0.7.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/bridge.mjs +16 -7
- package/package.json +1 -1
package/bridge.mjs
CHANGED
|
@@ -41,6 +41,7 @@ import { saveSession, flushSession, loadLatest, canResume } from './session-stor
|
|
|
41
41
|
// Public client creds (the same anon values the web app ships — safe to embed).
|
|
42
42
|
// Override with TP_SUPABASE_URL / TP_SUPABASE_ANON if you ever need to.
|
|
43
43
|
const SUPABASE_URL = process.env.TP_SUPABASE_URL || 'https://daytvtakmlixpfbbqzjd.supabase.co'
|
|
44
|
+
const WEB_BASE = process.env.TP_WEB_BASE || 'https://thinkpool.io'
|
|
44
45
|
const SUPABASE_ANON = process.env.TP_SUPABASE_ANON || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImRheXR2dGFrbWxpeHBmYmJxempkIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzgwNTMxNzEsImV4cCI6MjA5MzYyOTE3MX0.zYmz8bHUNEY4STUr2JuXChAsKwxNwkwFHe1Hd0Betqo'
|
|
45
46
|
|
|
46
47
|
// Per-terminal rolling scrollback (raw chars). Replayed to joining clients.
|
|
@@ -134,8 +135,16 @@ if (argv[0] === 'install-service' || argv[0] === 'uninstall-service') {
|
|
|
134
135
|
process.exit(0)
|
|
135
136
|
}
|
|
136
137
|
|
|
138
|
+
// Account mode (Phase 1, docs/specs/2026-06-16-account-bridge.md): one bridge per
|
|
139
|
+
// ACCOUNT, not per room. `login` links this device; `bind <ROOM> <dir>` maps a
|
|
140
|
+
// session to a working dir on this machine; a bare invocation discovers + serves
|
|
141
|
+
// every session you're in (a headless child bridge per room, run in its dir).
|
|
142
|
+
if (argv[0] === 'login') { const { runLogin } = await import('./account.mjs'); await runLogin(SUPABASE_URL, SUPABASE_ANON, WEB_BASE) }
|
|
143
|
+
if (argv[0] === 'bind') { const { runBind } = await import('./account.mjs'); runBind(argv[1], argv[2]) }
|
|
144
|
+
if (!argv[0] || argv[0].startsWith('-')) { const { runAccount } = await import('./account.mjs'); await runAccount(SUPABASE_URL, SUPABASE_ANON) }
|
|
145
|
+
|
|
137
146
|
const room = (argv[0] || '').toUpperCase().trim()
|
|
138
|
-
if (!room
|
|
147
|
+
if (!room) { console.error('usage: npx thinkpool-pair <ROOM> [--headless] [--continue|--fresh] [-- <command…>] | npx thinkpool-pair (account mode)'); process.exit(1) }
|
|
139
148
|
// ── Supervisor mode (--supervise / --keep-alive): keep the bridge alive across
|
|
140
149
|
// crashes. We re-exec ourselves without the flag and respawn the child on any
|
|
141
150
|
// non-clean exit with exponential backoff. Zero-dependency, cross-platform. With
|
|
@@ -445,12 +454,12 @@ function printLocal(evt) {
|
|
|
445
454
|
// relay STRUCTURED events. onEvent → broadcast `code-event` + print locally +
|
|
446
455
|
// persist to the host file; tool calls round-trip through the perm card; the
|
|
447
456
|
// rolling log replays to joiners and survives bridge restarts (session-store).
|
|
448
|
-
function openStructured({ id, model, resume, log }) {
|
|
457
|
+
function openStructured({ id, model, resume, log, commands }) {
|
|
449
458
|
if (sessions.has(id)) return
|
|
450
|
-
const entry = { cmd: 'claude', kind: 'structured', log: Array.isArray(log) ? log.slice(-STRUCTURED_LOG_MAX) : [], pending: new Map(), session: null, recovered: false }
|
|
459
|
+
const entry = { cmd: 'claude', kind: 'structured', log: Array.isArray(log) ? log.slice(-STRUCTURED_LOG_MAX) : [], pending: new Map(), session: null, recovered: false, commands: Array.isArray(commands) ? commands : undefined }
|
|
451
460
|
sessions.set(id, entry)
|
|
452
461
|
if (entry.log.length) process.stderr.write(`\n ◆ restored ${entry.log.length} prior events (${id.slice(0, 8)})${resume ? ' + resuming live context' : ''}.\n`)
|
|
453
|
-
const persist = () => saveSession(room, id, { sessionId: entry.session?.sessionId || resume || null, log: entry.log })
|
|
462
|
+
const persist = () => saveSession(room, id, { sessionId: entry.session?.sessionId || resume || null, log: entry.log, commands: entry.commands })
|
|
454
463
|
entry.session = startClaudeSession({
|
|
455
464
|
cwd: process.cwd(), model, resume,
|
|
456
465
|
onEvent: (evt) => {
|
|
@@ -461,7 +470,7 @@ function openStructured({ id, model, resume, log }) {
|
|
|
461
470
|
process.stderr.write(`\n ◆ saved session expired — starting fresh (transcript kept).\n`)
|
|
462
471
|
try { entry.session?.end() } catch { /* noop */ }
|
|
463
472
|
sessions.delete(id)
|
|
464
|
-
openStructured({ id, model, log: entry.log })
|
|
473
|
+
openStructured({ id, model, log: entry.log, commands: entry.commands })
|
|
465
474
|
return
|
|
466
475
|
}
|
|
467
476
|
// Stamp a wall-clock ts on every transcript event so the web client can
|
|
@@ -472,7 +481,7 @@ function openStructured({ id, model, resume, log }) {
|
|
|
472
481
|
// The init system event carries the session's slash command list. Stash it
|
|
473
482
|
// on the entry so the ANNOUNCE can hand it to clients that connect/reload
|
|
474
483
|
// AFTER init (the one-time code-event would miss them), then re-announce.
|
|
475
|
-
if (evt.kind === 'system' && Array.isArray(evt.commands) && evt.commands.length && !entry.commands) { entry.commands = evt.commands; announce() }
|
|
484
|
+
if (evt.kind === 'system' && Array.isArray(evt.commands) && evt.commands.length && !entry.commands) { entry.commands = evt.commands; announce(); persist() }
|
|
476
485
|
// Chrome events (mode / usage / clear) are transient state, not transcript —
|
|
477
486
|
// broadcast + print them, but keep them out of the persisted/replayed log.
|
|
478
487
|
const chrome = evt.kind === 'mode' || evt.kind === 'usage' || evt.kind === 'clear'
|
|
@@ -691,7 +700,7 @@ channel
|
|
|
691
700
|
// replay its transcript + resume the live SDK context if recent enough.
|
|
692
701
|
if (wantStructured(attachedCmd)) {
|
|
693
702
|
const prev = loadLatest(room)
|
|
694
|
-
if (prev && (prev.log?.length || prev.sessionId)) openStructured({ id: prev.id, resume: canResume(prev) ? prev.sessionId : undefined, log: prev.log })
|
|
703
|
+
if (prev && (prev.log?.length || prev.sessionId)) openStructured({ id: prev.id, resume: canResume(prev) ? prev.sessionId : undefined, log: prev.log, commands: prev.commands })
|
|
695
704
|
else openStructured({ id: randomUUID() })
|
|
696
705
|
}
|
|
697
706
|
else openTerm({ id: randomUUID(), cmd: attachedCmd, args: attachedArgs, attached: true })
|