@thothdev/pink 1.0.33 → 1.0.34

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/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  O Pink é um fork do Pi (MIT, veja `LICENSE-PI.txt` e `NOTICE.md`). Aqui só entra o que mudou no Pink; a base de cada
4
4
  versão está no campo `upstream` do `rebrand.json` do repositório.
5
5
 
6
+ ## [1.0.34] - 2026-11-29
7
+
8
+ - Enquanto trabalha, só a etapa atual anima e traz o tempo e os tokens; a linha "Trabalhando" de baixo saiu (modelo logado e `/agente`).
9
+ - A etapa mostra só o nome; o comando ou arquivo fica na linha da ferramenta, sem repetir.
10
+ - Comando que termina com código de saída diferente de 0 aparece com "erro" e a etapa fica com ✗, também no `/agente` (OpenCode e ACP mandam "Exit code" no texto).
11
+
6
12
  ## [1.0.33] - 2026-11-29
7
13
 
8
14
  - Reabrir uma sessão com conversa só do `/agente` abre direto na conversa, com a caixa de digitar embaixo, em vez da tela inicial.
@@ -11,7 +11,7 @@ import os from "node:os";
11
11
  import path from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
13
  import { closeKept, externalAgents, listModels, pinkExtras, runExternal, subagentEnd, warmKept } from "../examples/extensions/subagent/external.ts";
14
- import { bulleted, elapsedLabel, fit, runLabel, shortModel, stallNote, streamedTokens, thinkingLabel, cleanLine as clean, tailLine, thinkingNow, stripThothRules, thothConfigured, toolSummary, userLines, workingLabel, clearDone, showDone, stageLines, trailOf, framedAsk, outputTail, tailRows } from "./pink-ui.ts";
14
+ import { bulleted, elapsedLabel, fit, runLabel, shortModel, stallNote, streamedTokens, thinkingLabel, cleanLine as clean, tailLine, thinkingNow, stripThothRules, thothConfigured, toolSummary, userLines, workingLabel, clearDone, showDone, stageLines, trailOf, framedAsk, outputTail, tailRows, exitFailed } from "./pink-ui.ts";
15
15
 
16
16
  // reabrir o Pink volta ao último usado, modelo logado ou agente (owner 2026-11-28). O agente fica neste arquivo; o modelo
17
17
  // logado o motor grava como padrão a cada troca (rebrand.json, remember-last-model-module)
@@ -217,7 +217,6 @@ export const lastAgentSession = (entries: any[] | undefined, name: string): stri
217
217
  [...(entries ?? [])].reverse().find((e) => e?.type === "custom_message" && e.customType === "pink-agente" && e.details?.agent === name && typeof e.details?.session === "string" && e.details.session)?.details.session;
218
218
  // fila como no Claude Code (owner 2026-11-24): cada mensagem esperando aparece em cinza acima da caixa, numa linha
219
219
  export const queueLines = (queue: string[], width: number) => queue.map((text) => fit(`> ${String(text).replace(/\s+/g, " ").trim()}`, width));
220
- const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
221
220
  const THOUGHT_MAX = 8000; // o pensamento guardado na sessão, por passo
222
221
  // como o OpenCode: o trabalho antes da resposta vira uma linha "+ 4 comandos, 4 pensamentos" que abre com clique
223
222
  export function workSummary(list: any[]) {
@@ -302,8 +301,11 @@ export function steps(result: any, cwd = "") {
302
301
  else if (part.type === "toolCall") {
303
302
  const child = result.subagents?.[part.id]; // lançamento de subagente: bloco próprio com nome e tarefa
304
303
  // o fim da saída (⎿), como no modelo logado: só de comando ou de ferramenta que falhou
305
- const tail = part.failed || ["bash", "powershell", "shell"].includes(String(part.name).toLowerCase()) ? outputTail(part.output) : undefined;
306
- out.push(child ? { kind: "agents", list: [{ agent: child.agent, task: child.task }] } : { kind: "tool", line: pinkTool(part, cwd), ...(tail?.lines.length ? { tail, failed: Boolean(part.failed) } : {}) });
304
+ const shell = ["bash", "powershell", "shell"].includes(String(part.name).toLowerCase());
305
+ const failed = Boolean(part.failed) || (shell && exitFailed(part.output));
306
+ const tail = failed || shell ? outputTail(part.output) : undefined;
307
+ const line = pinkTool(part, cwd) + (failed ? ` · ${t("erro", "error", "error")}` : "");
308
+ out.push(child ? { kind: "agents", list: [{ agent: child.agent, task: child.task }] } : { kind: "tool", line, ...(tail?.lines.length ? { tail, failed } : {}) });
307
309
  }
308
310
  }
309
311
  }
@@ -445,7 +447,9 @@ export default function (pink: any, list: typeof externalAgents = externalAgents
445
447
  };
446
448
  // a fila em cinza fica em cima do "Trabalhando" e uma linha vazia o separa da caixa (owner 2026-11-25, como o Claude Code)
447
449
  const around = (lines: string[], width: number, theme: any) => [...queueLines(active?.queue ?? [], width).map((line) => theme.fg("dim", line)), ...lines, ""];
448
- const busy = (ui: any, output: () => number, doing: (width: number, theme?: any) => string[] = () => []) => {
450
+ // a etapa atual leva o tempo e os tokens e é a única linha animada (owner 2026-11-29): o Loader segue vivo só para
451
+ // redesenhar a tela, sem a linha "Trabalhando" embaixo
452
+ const busy = (ui: any, output: () => number, doing: (width: number, theme: any, status: string) => string[]) => {
449
453
  idle();
450
454
  lastUi = ui;
451
455
  if (!ui?.setWidget) return;
@@ -458,6 +462,11 @@ export default function (pink: any, list: typeof externalAgents = externalAgents
458
462
  if (out !== seen) (seen = out), (since = now);
459
463
  return workingLabel({ ms: now - started, output: out }) + stallNote(now - since);
460
464
  };
465
+ const status = () => {
466
+ const now = Date.now(), out = output();
467
+ if (out !== seen) (seen = out), (since = now);
468
+ return runLabel({ ms: now - started, output: out }) + stallNote(now - since);
469
+ };
461
470
  (globalThis as any).__pinkAgentBusy = true; // a caixa mostra "esc interromper · ctrl+enter envia agora" (pink-ui)
462
471
  // a área dos widgets já deixa uma linha em branco antes: a linha vazia do topo do Loader sai
463
472
  if (tui?.Loader) {
@@ -466,14 +475,13 @@ export default function (pink: any, list: typeof externalAgents = externalAgents
466
475
  loader?.stop?.(); // a fábrica pode ser chamada de novo: o Loader anterior para de girar
467
476
  loader = new tui.Loader(screen, (s: string) => theme.fg("accent", s), (s: string) => theme.fg("muted", s), message());
468
477
  const own = loader;
469
- return { render: (width: number) => around([...doing(width, theme).map((line) => theme.fg("muted", tui.truncateToWidth?.(line, width) ?? line)), ...own.render(width).slice(1)], width, theme), invalidate: () => own.invalidate?.() };
478
+ return { render: (width: number) => around(doing(width, theme, status()).map((line) => theme.fg("muted", tui.truncateToWidth?.(line, width) ?? line)), width, theme), invalidate: () => own.invalidate?.() };
470
479
  }, { placement: "aboveEditor" });
471
480
  ticker = setInterval(() => loader?.setMessage?.(message()), 1000);
472
481
  } else {
473
- let frame = 0;
474
- const draw = () => ui.setWidget(WIDGET, (screen: any, theme: any) => ((screenRef = screen), { render: (width: number) => around([...doing(width, theme).map((line) => tui?.truncateToWidth?.(line, width) ?? line), ` ${FRAMES[frame % FRAMES.length]} ${message()}`], width, theme), invalidate() {} }), { placement: "aboveEditor" });
482
+ const draw = () => ui.setWidget(WIDGET, (screen: any, theme: any) => ((screenRef = screen), { render: (width: number) => around(doing(width, theme, status()).map((line) => tui?.truncateToWidth?.(line, width) ?? line), width, theme), invalidate() {} }), { placement: "aboveEditor" });
475
483
  draw();
476
- ticker = setInterval(() => (frame++, draw()), 120);
484
+ ticker = setInterval(draw, 83);
477
485
  }
478
486
  ticker.unref?.();
479
487
  };
@@ -667,7 +675,7 @@ export default function (pink: any, list: typeof externalAgents = externalAgents
667
675
  };
668
676
  status();
669
677
  // o rastro de etapas do modelo logado, em cima dos passos do agente; o fechamento do pedido anterior sai
670
- if (ctx.hasUI) clearDone(ctx.ui), busy(ctx.ui, () => outputOf(result), (width, theme) => [...stageLines(theme ?? { fg: (_name: string, text: string) => text }, trailOf(result), { width }), ...liveLines(result, width, ctx.cwd)]);
678
+ if (ctx.hasUI) clearDone(ctx.ui), busy(ctx.ui, () => outputOf(result), (width, theme, status) => [...stageLines(theme ?? { fg: (_name: string, text: string) => text }, trailOf(result), { width, status }), ...liveLines(result, width, ctx.cwd)]);
671
679
  if (ctx.hasUI) watchChildren(ctx.ui);
672
680
  // "permitir tudo" (/permissoes): o que o agente pede é aceito sem perguntar
673
681
  (globalThis as any).__pinkExternalAsk = ctx.hasUI ? (title: string, body: string) => ((globalThis as any).__pinkPermissionMode === "all" ? Promise.resolve(true) : ctx.ui.confirm(title, ctx.mode === "tui" ? framedAsk(title, body) : body)) : undefined;
@@ -411,6 +411,10 @@ export function stageOf(toolName, input = {}) {
411
411
  return { key: "investigate", detail: tool };
412
412
  }
413
413
 
414
+ // comando que terminou com código diferente de 0 é falha, mesmo quando a ferramenta não marca erro (o OpenCode e o ACP
415
+ // devolvem "Exit code: 1" no texto; owner 2026-11-29)
416
+ export const exitFailed = (text) => /(?:^|\n)\s*(?:exit code|exit status|código de saída)\s*[:=]?\s*-?[1-9]\d*\s*$/im.test(String(text ?? "").slice(-2000));
417
+
414
418
  // a mesma etapa seguida não repete a linha: troca o detalhe; só as 6 últimas ficam na tela
415
419
  export function pushStage(trail, stage) {
416
420
  const last = trail.at(-1);
@@ -422,7 +426,11 @@ export function pushStage(trail, stage) {
422
426
  export function trailOf(result) {
423
427
  let trail = [{ key: "interpret", count: 1 }];
424
428
  for (const message of result?.messages ?? []) {
425
- for (const part of message.content ?? []) if (part.type === "toolCall") trail = pushStage(trail, stageOf(part.name, part.arguments ?? {}));
429
+ for (const part of message.content ?? []) {
430
+ if (part.type !== "toolCall") continue;
431
+ trail = pushStage(trail, stageOf(part.name, part.arguments ?? {}));
432
+ if (part.failed || exitFailed(part.output)) trail[trail.length - 1] = { ...trail.at(-1), failed: true };
433
+ }
426
434
  }
427
435
  if (result?.partial?.kind === "text") trail = pushStage(trail, { key: "answer" });
428
436
  return trail;
@@ -451,19 +459,21 @@ export function showDone(ui, trail, summary = "") {
451
459
  // done: { at, summary } — fechamento (Renoir): os ✓ acendem em sequência (40 ms cada, até 300 ms) e "✓ Pronto · tempo ·
452
460
  // tokens" fica verde 2 s; depois só a linha de resumo, em cinza, até o próximo pedido
453
461
  export const DONE_GREEN_MS = 2000;
454
- export function stageLines(theme, trail, { now = Date.now(), still: stopped = still(), width = 80, done = undefined } = {}) {
462
+ // status: "15s · ↓ 739 tokens" vai na etapa atual, que é a única linha animada (owner 2026-11-29: o "Trabalhando" embaixo
463
+ // repetia o spinner); a etapa mostra só o nome, porque a linha da ferramenta logo abaixo já diz o comando ou o arquivo
464
+ export function stageLines(theme, trail, { now = Date.now(), still: stopped = still(), width = 80, done = undefined, status = "" } = {}) {
455
465
  setAppearance(theme);
456
466
  const ready = done ? `${t("Pronto", "Listo", "Done")}${done.summary ? ` · ${done.summary}` : ""}` : "";
457
467
  if (done && now - done.at >= DONE_GREEN_MS) return [fit(` ${theme.fg("muted", `✓ ${ready}`)}`, width)];
458
468
  const lit = done ? (stopped ? trail.length : Math.floor((now - done.at) / Math.min(40, 300 / Math.max(1, trail.length)))) : trail.length - 1;
469
+ const mark = (stage) => (stage.failed ? rgb(248, 113, 113)("✗") : GREEN("✓"));
459
470
  const lines = trail.map((stage, index) => {
460
471
  const spec = STAGES[stage.key] ?? STAGES.investigate;
461
- const detail = stage.detail ? theme.fg("dim", ` · ${stage.detail}${stage.count > 1 ? ` (+${stage.count - 1})` : ""}`) : "";
462
- if (done) return fit(` ${index < lit ? (stage.failed ? rgb(248, 113, 113)("✗") : GREEN("✓")) : theme.fg("dim", "·")} ${theme.fg("muted", spec.label)}${detail}`, width);
463
- if (index < lit) return fit(` ${stage.failed ? rgb(248, 113, 113)("✗") : GREEN("✓")} ${theme.fg("muted", spec.label)}${detail}`, width);
472
+ if (done) return fit(` ${index < lit ? mark(stage) : theme.fg("dim", "·")} ${theme.fg("muted", spec.label)}`, width);
473
+ if (index < lit) return fit(` ${mark(stage)} ${theme.fg("muted", spec.label)}`, width);
464
474
  const icon = spec.frames[stopped ? 0 : Math.floor(now / FRAME_MS) % spec.frames.length];
465
475
  const label = stopped ? spec.color(`${spec.label}...`) : `${shimmer(spec.label, spec.color.rgb, now)}${spec.color("...")}`;
466
- return fit(` ${spec.color(icon)} ${label}${detail}`, width);
476
+ return fit(` ${spec.color(icon)} ${label}${status ? theme.fg("dim", ` (${status})`) : ""}`, width);
467
477
  });
468
478
  return done ? [...lines, fit(` ${GREEN(`✓ ${ready}`)}`, width)] : lines;
469
479
  }
@@ -1636,7 +1646,9 @@ export function compactToolRenderer(toolName, next) {
1636
1646
  if (options.expanded) return wrap(base?.renderResult?.(result, options, theme, context) ?? output(result, theme, 0), context.outputPad);
1637
1647
  if (options.isPartial) return empty;
1638
1648
  const time = context.durationMs >= 100 ? theme.fg("dim", ` · ${(context.durationMs / 1000).toFixed(1)}s`) : "";
1639
- const summary = line(theme, context.outputPad, toolSummary(toolName, context.args ?? {}, result), `${time}${context.isError ? theme.fg("error", t(" · erro", " · error", " · error")) : ""}`);
1649
+ const shellText = (result?.content ?? []).filter((part) => part?.type === "text").map((part) => part.text).join("\n");
1650
+ const failed = context.isError || ((toolName === "bash" || toolName === "powershell") && exitFailed(shellText));
1651
+ const summary = line(theme, context.outputPad, toolSummary(toolName, context.args ?? {}, result), `${time}${failed ? theme.fg("error", t(" · erro", " · error", " · error")) : ""}`);
1640
1652
  // edit e write: o diff fica aberto sob a linha (como no Claude Code); o write mostra as primeiras 40 linhas
1641
1653
  const diff = context.isError ? "" : toolName === "edit" ? result?.details?.diff : toolName === "write" ? writeDiff(context.args?.content) : "";
1642
1654
  if (!diff) {
@@ -1645,7 +1657,7 @@ export function compactToolRenderer(toolName, next) {
1645
1657
  const text = shell || context.isError ? (result?.content ?? []).filter((part) => part?.type === "text").map((part) => part.text).join("\n") : "";
1646
1658
  const tail = outputTail(text);
1647
1659
  return grouped(theme, context.outputPad, context.toolCallId, !tail.lines.length ? summary : {
1648
- render: (width) => [...summary.render(width), ...tailRows(theme, tail, { width, pad: context.outputPad, error: context.isError })],
1660
+ render: (width) => [...summary.render(width), ...tailRows(theme, tail, { width, pad: context.outputPad, error: failed })],
1649
1661
  invalidate() {},
1650
1662
  });
1651
1663
  }
@@ -1928,7 +1940,14 @@ function registerOpenCodeFunctions(pink) {
1928
1940
  // as etapas (interpretar, mapear, investigar...) vão aqui, embaixo do "Trabalhando"; o spinner do motor já redesenha a tela
1929
1941
  PINK.stages = [{ key: "interpret", count: 1 }];
1930
1942
  clearDone();
1931
- ctx.ui.setWidget?.(ABOVE_BOX, (_tui, theme) => ({ render: (width) => [...stageLines(theme, PINK.stages ?? [], { width }), ""], invalidate() {} }), { placement: "aboveEditor" });
1943
+ // a etapa atual é a única linha animada e leva o tempo e os tokens: a linha "Trabalhando" do motor sai (owner
1944
+ // 2026-11-29); sem o spinner dele ninguém redesenha, então o redesenho vem daqui, a 12 quadros/s
1945
+ ctx.ui.setWorkingVisible?.(false);
1946
+ clearInterval(PINK.stageTimer);
1947
+ PINK.stageTimer = setInterval(() => { try { globalThis.__pinkMicTarget?.redraw?.(); } catch {} }, FRAME_MS);
1948
+ PINK.stageTimer.unref?.();
1949
+ const status = () => { try { return PINK.run ? runLabel(PINK.run.summary()) : ""; } catch { return ""; } };
1950
+ ctx.ui.setWidget?.(ABOVE_BOX, (_tui, theme) => ({ render: (width) => [...stageLines(theme, PINK.stages ?? [], { width, status: status() }), ""], invalidate() {} }), { placement: "aboveEditor" });
1932
1951
  ctx.ui.setWidget?.(BELOW_BOX, (_tui, theme) => ({
1933
1952
  render: (width) => belowBox(theme, width, { agents: [...runningSubagents(PINK.subagents), ...dagAgentsCached(ctx.cwd)], side: globalThis.__pinkRightOn === true }),
1934
1953
  invalidate() {},
@@ -1936,6 +1955,8 @@ function registerOpenCodeFunctions(pink) {
1936
1955
  });
1937
1956
  pink.on("agent_end", async (_event, ctx) => {
1938
1957
  clearInterval(PINK.runTimer);
1958
+ clearInterval(PINK.stageTimer);
1959
+ ctx.ui.setWorkingVisible?.(true);
1939
1960
  PINK.subagents.clear(); // ferramenta bloqueada ou interrompida não manda tool_result
1940
1961
  ctx.ui.setWorkingMessage?.();
1941
1962
  ctx.ui.setWidget?.(BELOW_BOX, undefined);
@@ -1991,7 +2012,8 @@ function registerOpenCodeFunctions(pink) {
1991
2012
  });
1992
2013
  pink.on("tool_result", async (event) => {
1993
2014
  trackSubagent(PINK.subagents, event);
1994
- if (event?.isError && PINK.stages?.length && PINK.stages.at(-1).key !== "answer") PINK.stages = [...PINK.stages.slice(0, -1), { ...PINK.stages.at(-1), failed: true }]; // ferramenta com erro: ✗ vermelho
2015
+ const shellFailed = ["bash", "powershell"].includes(event?.toolName) && exitFailed((event?.content ?? []).filter((part) => part?.type === "text").map((part) => part.text).join("\n"));
2016
+ if ((event?.isError || shellFailed) && PINK.stages?.length && PINK.stages.at(-1).key !== "answer") PINK.stages = [...PINK.stages.slice(0, -1), { ...PINK.stages.at(-1), failed: true }]; // ferramenta com erro: ✗ vermelho
1995
2017
  // Git Bash, docker e cia. mexem no modo do console do Windows: o teclado parava de chegar ao Pink ("trava")
1996
2018
  if (process.platform === "win32" && (event?.toolName === "bash" || event?.toolName === "powershell")) {
1997
2019
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thothdev/pink",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "description": "Open-source AI coding agent for the terminal that also drives Claude Code, Codex, OpenCode and other agents, with parallel sessions, visible plan and changes, and real undo.",
5
5
  "type": "module",
6
6
  "piConfig": {