@1presence/bridge 0.30.0 → 0.31.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/dist/claude.js +41 -2
- package/package.json +1 -1
package/dist/claude.js
CHANGED
|
@@ -76,6 +76,33 @@ function debugBlock(label, colorCode, body) {
|
|
|
76
76
|
const rule = `── ${label} `.padEnd(64, '─');
|
|
77
77
|
process.stderr.write(`\n${paint(colorCode, rule)}\n${body.trimEnd()}\n`);
|
|
78
78
|
}
|
|
79
|
+
// Render one replayed-history content block as a single readable line for the
|
|
80
|
+
// debug transcript. Tool calls and results are inlined so a history turn shows
|
|
81
|
+
// exactly what the model received — text, the tools it ran, and what they
|
|
82
|
+
// returned (including error flags) — not just an opaque "(replaying N turns)".
|
|
83
|
+
function summariseHistoryBlock(block) {
|
|
84
|
+
if (block.type === 'text')
|
|
85
|
+
return block.text.trimEnd();
|
|
86
|
+
if (block.type === 'tool_use') {
|
|
87
|
+
return `→ ${block.name} ${formatPayload(block.input)}`;
|
|
88
|
+
}
|
|
89
|
+
// tool_result
|
|
90
|
+
const body = typeof block.content === 'string'
|
|
91
|
+
? block.content
|
|
92
|
+
: block.content.map((c) => c.text).join('');
|
|
93
|
+
const errFlag = block.is_error ? ' [error]' : '';
|
|
94
|
+
return `← ${block.tool_use_id}${errFlag} ${body}`;
|
|
95
|
+
}
|
|
96
|
+
// Render a full replayed-history message with its role colour so the operator
|
|
97
|
+
// can tell user turns from assistant turns at a glance — the missing
|
|
98
|
+
// distinction that made replayed context unreadable in --debug.
|
|
99
|
+
function renderHistoryMessage(msg) {
|
|
100
|
+
const color = msg.role === 'user' ? DEBUG_COLORS.user : DEBUG_COLORS.assistant;
|
|
101
|
+
const body = typeof msg.content === 'string'
|
|
102
|
+
? msg.content
|
|
103
|
+
: msg.content.map(summariseHistoryBlock).join('\n');
|
|
104
|
+
debugBlock(`${msg.role} · history`, color, body);
|
|
105
|
+
}
|
|
79
106
|
// ─── Active processes ─────────────────────────────────────────────────────────
|
|
80
107
|
const active = new Map();
|
|
81
108
|
// ─── Spawn ────────────────────────────────────────────────────────────────────
|
|
@@ -97,8 +124,20 @@ function spawnClaude(params) {
|
|
|
97
124
|
// id (correlates with the chat URL / Firestore session doc) and a hint at
|
|
98
125
|
// how much prior context is being replayed.
|
|
99
126
|
if (debug) {
|
|
100
|
-
|
|
101
|
-
|
|
127
|
+
process.stderr.write(`\n${paint('1', `══ session ${presenceSessionId} ══`)}\n`);
|
|
128
|
+
// `history` already ends with the new user prompt (gateway-appended). Render
|
|
129
|
+
// every PRIOR message with its role colour so what the model saw as context
|
|
130
|
+
// is auditable — then the live turn is shown via the clean `text` below and
|
|
131
|
+
// streams in beneath it. Defensive: if the tail isn't the current user turn
|
|
132
|
+
// (unexpected), render the whole history rather than dropping a message.
|
|
133
|
+
const tail = history[history.length - 1];
|
|
134
|
+
const prior = tail?.role === 'user' ? history.slice(0, -1) : history;
|
|
135
|
+
if (prior.length > 0) {
|
|
136
|
+
process.stderr.write(paint('90', ` replaying ${prior.length} prior message${prior.length === 1 ? '' : 's'}:\n`));
|
|
137
|
+
for (const msg of prior)
|
|
138
|
+
renderHistoryMessage(msg);
|
|
139
|
+
}
|
|
140
|
+
debugBlock('user · this turn', DEBUG_COLORS.user, text);
|
|
102
141
|
}
|
|
103
142
|
else if (!verbose) {
|
|
104
143
|
// Default mode is quiet, but always surface the session id once per turn so
|