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 CHANGED
@@ -197,60 +197,115 @@ export function resolveExtraDir(input, workdir) {
197
197
  }
198
198
  return { path: abs };
199
199
  }
200
- /** How many characters of the dialogue are printed by default. */
200
+ /** How many messages of the dialogue are printed by default. */
201
201
  export const RESTORED_HISTORY_LIMIT = 20;
202
202
  /**
203
- * Is this message worth showing to the operator as part of the dialogue?
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
- * The chat history contains a lot of protocol noise that is meaningless in
206
- * the terminal: the system-prompt (a huge REQUEST), tool results
207
- * ("Tool result for ..."), the agent's raw tool-calls (JSON / DSML), the
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 isDisplayableMessage(m) {
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 false;
254
+ return null;
215
255
  if (text.length > 100_000)
216
- return false; // the system-prompt / a giant blob
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 false;
259
+ return null;
222
260
  if (/^You are a coding agent running in a terminal/.test(text))
223
- return false;
261
+ return null;
224
262
  if (/^You stopped after a tool result/.test(text))
225
- return false;
263
+ return null;
226
264
  if (/^\[system\]/.test(text))
227
- return false;
265
+ return null;
228
266
  if (/^The user ran \//.test(text))
229
- return false;
230
- return true;
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 false;
271
+ return null;
237
272
  if (/^<system>/i.test(text))
238
- return false;
239
- if (/"tool"\s*:/.test(text.slice(0, 600))) {
240
- return false;
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
- if (/^\s*[\[{]/.test(text) && /"args"\s*:/.test(text.slice(0, 600))) {
243
- return false;
244
- }
245
- return true;
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 and drop empties/service noise. The
249
- * source (network history or DOM) may contain protocol messages; they are
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 = (messages || []).filter((m) => m && typeof m.text === 'string' && isDisplayableMessage(m));
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 (all.length > messages.length) {
877
+ if (displayable.length > messages.length) {
872
878
  out(theme.dim(t('chats.history_truncated', { n: String(RESTORED_HISTORY_LIMIT) })));
873
879
  }
874
880
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zames_pro",
3
- "version": "2.29.4",
3
+ "version": "2.29.5",
4
4
  "description": "Terminal coding agent over chat.deepseek.com via Playwright",
5
5
  "type": "module",
6
6
  "bin": {