kafox-cli 0.9.7 → 0.9.8

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/tui.js +15 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kafox-cli",
3
- "version": "0.9.7",
3
+ "version": "0.9.8",
4
4
  "description": "Kafox CLI: TUI com streaming, thinking, edit com diff, agent tools (files/shell), MCP e temas",
5
5
  "bin": {
6
6
  "kafox": "bin/kafox.js"
package/src/tui.js CHANGED
@@ -489,6 +489,9 @@ function initialState() {
489
489
  messages: [],
490
490
  context: [],
491
491
  streaming: null,
492
+ // Texto ja comitado em finishStreaming() neste turno: usado para nao
493
+ // duplicar a resposta quando runAgent devolve o texto no final.
494
+ streamedText: "",
492
495
  approval: null,
493
496
  autoApprove: false,
494
497
  busy: false,
@@ -1950,13 +1953,16 @@ async function runTUI({
1950
1953
  if (result.messages) state.context = result.messages;
1951
1954
  } else if (result.ok) {
1952
1955
  const text = String(result.text || "").trim();
1953
- if (text) {
1956
+ // O stream ja foi commitado em finishStreaming(): so empurra aqui se for
1957
+ // texto novo (ou se nao houve streaming, ex.: resposta sem onText).
1958
+ if (text && !state.streamedText.includes(text)) {
1954
1959
  state.messages.push({
1955
1960
  role: "assistant",
1956
1961
  text,
1957
1962
  ms: result.ms,
1958
1963
  });
1959
1964
  }
1965
+ state.streamedText = "";
1960
1966
  if (result.messages) state.context = result.messages;
1961
1967
  } else {
1962
1968
  state.messages.push({
@@ -1984,7 +1990,14 @@ async function runTUI({
1984
1990
  });
1985
1991
  }
1986
1992
  if (streaming.text.trim()) {
1987
- state.messages.push({ role: "assistant", text: streaming.text.trim() });
1993
+ const text = streaming.text.trim();
1994
+ // Evita repetir o texto quando o mesmo trecho ja foi commitado (retry
1995
+ // que repetiu tokens ou onToolStart chamado duas vezes).
1996
+ const previous = [...state.messages].reverse().find((message) => message.role === "assistant");
1997
+ if (!previous || previous.text !== text) {
1998
+ state.messages.push({ role: "assistant", text });
1999
+ state.streamedText += text;
2000
+ }
1988
2001
  }
1989
2002
  state.streaming = { text: "", reasoning: "", thinkingStartedAt: 0 };
1990
2003
  }