thinkpool-pair 0.6.25 → 0.6.27
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 +10 -6
- package/package.json +1 -1
package/bridge.mjs
CHANGED
|
@@ -330,7 +330,7 @@ const announce = () =>
|
|
|
330
330
|
...[...terms.entries()].map(([id, t]) => ({ id, cmd: t.cmd, alive: true, cols: t.term.cols, rows: t.term.rows })),
|
|
331
331
|
// Structured sessions advertise kind:'structured' so the web renders the
|
|
332
332
|
// reader (not xterm) and drives them with code-turn / code-perm.
|
|
333
|
-
...[...sessions.entries()].map(([id, s]) => ({ id, cmd: s.cmd, kind: 'structured', alive: true })),
|
|
333
|
+
...[...sessions.entries()].map(([id, s]) => ({ id, cmd: s.cmd, kind: 'structured', alive: true, commands: s.commands })),
|
|
334
334
|
],
|
|
335
335
|
})
|
|
336
336
|
|
|
@@ -445,12 +445,12 @@ function printLocal(evt) {
|
|
|
445
445
|
// relay STRUCTURED events. onEvent → broadcast `code-event` + print locally +
|
|
446
446
|
// persist to the host file; tool calls round-trip through the perm card; the
|
|
447
447
|
// rolling log replays to joiners and survives bridge restarts (session-store).
|
|
448
|
-
function openStructured({ id, model, resume, log }) {
|
|
448
|
+
function openStructured({ id, model, resume, log, commands }) {
|
|
449
449
|
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 }
|
|
450
|
+
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
451
|
sessions.set(id, entry)
|
|
452
452
|
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 })
|
|
453
|
+
const persist = () => saveSession(room, id, { sessionId: entry.session?.sessionId || resume || null, log: entry.log, commands: entry.commands })
|
|
454
454
|
entry.session = startClaudeSession({
|
|
455
455
|
cwd: process.cwd(), model, resume,
|
|
456
456
|
onEvent: (evt) => {
|
|
@@ -461,7 +461,7 @@ function openStructured({ id, model, resume, log }) {
|
|
|
461
461
|
process.stderr.write(`\n ◆ saved session expired — starting fresh (transcript kept).\n`)
|
|
462
462
|
try { entry.session?.end() } catch { /* noop */ }
|
|
463
463
|
sessions.delete(id)
|
|
464
|
-
openStructured({ id, model, log: entry.log })
|
|
464
|
+
openStructured({ id, model, log: entry.log, commands: entry.commands })
|
|
465
465
|
return
|
|
466
466
|
}
|
|
467
467
|
// Stamp a wall-clock ts on every transcript event so the web client can
|
|
@@ -469,6 +469,10 @@ function openStructured({ id, model, resume, log }) {
|
|
|
469
469
|
// (the client merges the replayed log with persisted human lines). Used
|
|
470
470
|
// for ordering only — agent timestamps are never displayed.
|
|
471
471
|
if (typeof evt.ts !== 'number') evt.ts = Date.now()
|
|
472
|
+
// The init system event carries the session's slash command list. Stash it
|
|
473
|
+
// on the entry so the ANNOUNCE can hand it to clients that connect/reload
|
|
474
|
+
// 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(); persist() }
|
|
472
476
|
// Chrome events (mode / usage / clear) are transient state, not transcript —
|
|
473
477
|
// broadcast + print them, but keep them out of the persisted/replayed log.
|
|
474
478
|
const chrome = evt.kind === 'mode' || evt.kind === 'usage' || evt.kind === 'clear'
|
|
@@ -687,7 +691,7 @@ channel
|
|
|
687
691
|
// replay its transcript + resume the live SDK context if recent enough.
|
|
688
692
|
if (wantStructured(attachedCmd)) {
|
|
689
693
|
const prev = loadLatest(room)
|
|
690
|
-
if (prev && (prev.log?.length || prev.sessionId)) openStructured({ id: prev.id, resume: canResume(prev) ? prev.sessionId : undefined, log: prev.log })
|
|
694
|
+
if (prev && (prev.log?.length || prev.sessionId)) openStructured({ id: prev.id, resume: canResume(prev) ? prev.sessionId : undefined, log: prev.log, commands: prev.commands })
|
|
691
695
|
else openStructured({ id: randomUUID() })
|
|
692
696
|
}
|
|
693
697
|
else openTerm({ id: randomUUID(), cmd: attachedCmd, args: attachedArgs, attached: true })
|