zames_pro 2.29.4 → 2.29.5
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/commands.js +88 -33
- package/dist/index.js +7 -1
- package/package.json +1 -1
package/dist/commands.js
CHANGED
|
@@ -197,60 +197,115 @@ export function resolveExtraDir(input, workdir) {
|
|
|
197
197
|
}
|
|
198
198
|
return { path: abs };
|
|
199
199
|
}
|
|
200
|
-
/** How many
|
|
200
|
+
/** How many messages of the dialogue are printed by default. */
|
|
201
201
|
export const RESTORED_HISTORY_LIMIT = 20;
|
|
202
202
|
/**
|
|
203
|
-
*
|
|
203
|
+
* DeepSeek stores the assistant turn VERBATIM: either a raw tool-call JSON
|
|
204
|
+
* ({"tool":"Read","args":{...}}, frequently dirty/truncated) or a `respond`
|
|
205
|
+
* call that carries the real message for the operator
|
|
206
|
+
* ({"tool":"respond","args":{"message":"..."}}). The operator only wants the
|
|
207
|
+
* `respond` message (and plain-text answers) — a tool-call is protocol noise.
|
|
204
208
|
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* "You stopped after a tool result..." nudges, and the agent's <system> notes.
|
|
209
|
-
* We keep only real user turns and real assistant answers.
|
|
209
|
+
* Returns the tool name and, for `respond`, the unwrapped message. Tolerant on
|
|
210
|
+
* purpose: the stored JSON is often dirty (a stray `}}`, a missing "args"
|
|
211
|
+
* wrapper), so a bare JSON.parse is not enough.
|
|
210
212
|
*/
|
|
211
|
-
export function
|
|
213
|
+
export function parseAssistantToolCall(text) {
|
|
214
|
+
const t = String(text || '').trim();
|
|
215
|
+
if (!t)
|
|
216
|
+
return null;
|
|
217
|
+
// Broken heads like `<|tool": ...` or `tool": "Bash"` are tolerated.
|
|
218
|
+
const m = t.match(/tool"?\s*:\s*"([^"\s]+)"/);
|
|
219
|
+
if (!m)
|
|
220
|
+
return null;
|
|
221
|
+
const tool = m[1];
|
|
222
|
+
if (tool !== 'respond')
|
|
223
|
+
return { tool };
|
|
224
|
+
const greedy = t.match(/"message"\s*:\s*"([\s\S]*)"\s*\}*\s*$/);
|
|
225
|
+
let raw = greedy ? greedy[1] : '';
|
|
226
|
+
if (!greedy) {
|
|
227
|
+
const idx = t.indexOf('"message"');
|
|
228
|
+
if (idx >= 0)
|
|
229
|
+
raw = t.slice(idx + 9).replace(/^\s*:\s*"/, '');
|
|
230
|
+
}
|
|
231
|
+
return { tool, message: unescapeJsonString(raw) };
|
|
232
|
+
}
|
|
233
|
+
/** Decode the JSON escape sequences that appear inside a captured string. */
|
|
234
|
+
export function unescapeJsonString(s) {
|
|
235
|
+
return String(s || '')
|
|
236
|
+
.replace(/\\u([0-9a-fA-F]{4})/g, (_x, h) => String.fromCharCode(parseInt(h, 16)))
|
|
237
|
+
.replace(/\\n/g, NL)
|
|
238
|
+
.replace(/\\r/g, String.fromCharCode(13))
|
|
239
|
+
.replace(/\\t/g, String.fromCharCode(9))
|
|
240
|
+
.replace(/\\"/g, '"')
|
|
241
|
+
.replace(/\\\\/g, '\\');
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Normalize one restored message for display:
|
|
245
|
+
* - USER: drop the protocol noise (system-prompt, tool results, nudges) — it
|
|
246
|
+
* is not the operator's words.
|
|
247
|
+
* - ASSISTANT: unwrap a `respond` call to its message; drop any other
|
|
248
|
+
* tool-call (protocol noise); keep plain-text answers.
|
|
249
|
+
* Returns null when the message must not be shown.
|
|
250
|
+
*/
|
|
251
|
+
export function normalizeRestoredMessage(m) {
|
|
212
252
|
const text = String((m && m.text) || '').trim();
|
|
213
253
|
if (!text)
|
|
214
|
-
return
|
|
254
|
+
return null;
|
|
215
255
|
if (text.length > 100_000)
|
|
216
|
-
return
|
|
256
|
+
return null; // the system-prompt / a giant blob
|
|
217
257
|
if (m.role === 'user') {
|
|
218
|
-
// Tool output, the system-prompt and the corrective nudges are not the
|
|
219
|
-
// operator's words.
|
|
220
258
|
if (/^Tool result for /.test(text))
|
|
221
|
-
return
|
|
259
|
+
return null;
|
|
222
260
|
if (/^You are a coding agent running in a terminal/.test(text))
|
|
223
|
-
return
|
|
261
|
+
return null;
|
|
224
262
|
if (/^You stopped after a tool result/.test(text))
|
|
225
|
-
return
|
|
263
|
+
return null;
|
|
226
264
|
if (/^\[system\]/.test(text))
|
|
227
|
-
return
|
|
265
|
+
return null;
|
|
228
266
|
if (/^The user ran \//.test(text))
|
|
229
|
-
return
|
|
230
|
-
return
|
|
267
|
+
return null;
|
|
268
|
+
return { role: 'user', text };
|
|
231
269
|
}
|
|
232
|
-
// Assistant: a tool-call (JSON or DSML) is not an answer to show. The
|
|
233
|
-
// DSML markers use FULL-WIDTH vertical bars (||DSML), so the regex must
|
|
234
|
-
// match them, not the ASCII pipe.
|
|
235
270
|
if (/DSML/i.test(text))
|
|
236
|
-
return
|
|
271
|
+
return null;
|
|
237
272
|
if (/^<system>/i.test(text))
|
|
238
|
-
return
|
|
239
|
-
|
|
240
|
-
|
|
273
|
+
return null;
|
|
274
|
+
// The model sometimes emits its own safety-classification block as a plain
|
|
275
|
+
// "answer"; it is not for the operator.
|
|
276
|
+
if (/<ds_safety>/i.test(text))
|
|
277
|
+
return null;
|
|
278
|
+
if (/^Safe$/i.test(text))
|
|
279
|
+
return null;
|
|
280
|
+
const call = parseAssistantToolCall(text);
|
|
281
|
+
if (call) {
|
|
282
|
+
if (call.tool !== 'respond')
|
|
283
|
+
return null;
|
|
284
|
+
const msg = (call.message || '').trim();
|
|
285
|
+
if (!msg)
|
|
286
|
+
return null;
|
|
287
|
+
return { role: 'assistant', text: msg };
|
|
241
288
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
289
|
+
// A plain-text answer (written without the respond wrapper) — show as-is.
|
|
290
|
+
return { role: 'assistant', text };
|
|
291
|
+
}
|
|
292
|
+
/** Back-compat predicate: is the message worth showing at all? */
|
|
293
|
+
export function isDisplayableMessage(m) {
|
|
294
|
+
return normalizeRestoredMessage(m) !== null;
|
|
246
295
|
}
|
|
247
296
|
/**
|
|
248
|
-
* Keep only the last `limit` messages
|
|
249
|
-
*
|
|
250
|
-
* filtered out here so the terminal output stays readable.
|
|
297
|
+
* Keep only the last `limit` messages, dropping protocol noise and UNWRAPPING
|
|
298
|
+
* the assistant `respond` calls to their operator-facing text.
|
|
251
299
|
*/
|
|
252
300
|
export function trimRestoredMessages(messages, limit = RESTORED_HISTORY_LIMIT) {
|
|
253
|
-
const clean =
|
|
301
|
+
const clean = [];
|
|
302
|
+
for (const m of messages || []) {
|
|
303
|
+
if (!m || typeof m.text !== 'string')
|
|
304
|
+
continue;
|
|
305
|
+
const n = normalizeRestoredMessage(m);
|
|
306
|
+
if (n)
|
|
307
|
+
clean.push(n);
|
|
308
|
+
}
|
|
254
309
|
if (limit > 0 && clean.length > limit)
|
|
255
310
|
return clean.slice(clean.length - limit);
|
|
256
311
|
return clean;
|
package/dist/index.js
CHANGED
|
@@ -828,6 +828,12 @@ async function printRestoredHistory(browser, ui, chatId = null) {
|
|
|
828
828
|
all = await browser.readChatMessages().catch(() => []);
|
|
829
829
|
domCount = all.length;
|
|
830
830
|
}
|
|
831
|
+
// `all` is the raw history (mostly protocol noise). `displayable` is what
|
|
832
|
+
// survives normalization; `messages` is the last RESTORED_HISTORY_LIMIT of
|
|
833
|
+
// those. The "truncated" note must compare the DISPLAYABLE count with the
|
|
834
|
+
// limit (comparing `all.length` always fired, because tool-calls are
|
|
835
|
+
// dropped and the raw history is always longer).
|
|
836
|
+
const displayable = trimRestoredMessages(all, 0);
|
|
831
837
|
const messages = trimRestoredMessages(all);
|
|
832
838
|
// Always surface the diagnostic line when the history could not be turned
|
|
833
839
|
// into anything printable — otherwise "the dialogue is empty" is a dead end
|
|
@@ -868,7 +874,7 @@ async function printRestoredHistory(browser, ui, chatId = null) {
|
|
|
868
874
|
NL);
|
|
869
875
|
}
|
|
870
876
|
}
|
|
871
|
-
if (
|
|
877
|
+
if (displayable.length > messages.length) {
|
|
872
878
|
out(theme.dim(t('chats.history_truncated', { n: String(RESTORED_HISTORY_LIMIT) })));
|
|
873
879
|
}
|
|
874
880
|
}
|