@thothdev/pink 1.0.0 → 1.0.2
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 +16 -0
- package/README.md +142 -95
- package/examples/extensions/subagent/external.ts +43 -3
- package/extensions/pink-agente.ts +147 -17
- package/extensions/pink-notify.ts +17 -0
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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.2] - 2026-11-24
|
|
7
|
+
|
|
8
|
+
- `/agente`: a conversa fica igual à do Pink: "> oi", "+ Pensou", "→ Rodou: ...", "→ Leu ...", "●" e o rodapé
|
|
9
|
+
"opencode · big-pickle · 7s · ↓ 49 tokens"; "Trabalhando · 2s · ↓ 0 tokens" acima da caixa, como o do Pink.
|
|
10
|
+
- `/agente` + espaço lista `off` e os agentes instalados; `/agente codex ` lista os modelos dele.
|
|
11
|
+
- Agentes ACP (opencode e outros): o comando e o arquivo de cada ferramenta, o pensamento e o modelo de verdade aparecem.
|
|
12
|
+
|
|
13
|
+
## [1.0.1] - 2026-11-23
|
|
14
|
+
|
|
15
|
+
- `/agente`: aparece "<agente> trabalhando · Ns" embaixo da caixa enquanto o agente responde; com um agente ligado, o
|
|
16
|
+
primeiro item do menu é "Voltar ao Pink" (o mesmo que `/agente off`); as mensagens aparecem como "Você → opencode" e
|
|
17
|
+
"opencode · modelo", em vez dos tipos crus `[pink-agente-pedido]` e `[pink-agente]`.
|
|
18
|
+
- README em inglês, com o logo e a tela.
|
|
19
|
+
- `/sugestao [texto]` abre a página de ideias do Pink (GitHub Discussions), com o texto como título. Doação pelo Ko-fi
|
|
20
|
+
(`npm fund @thothdev/pink` e o botão Sponsor do GitHub).
|
|
21
|
+
|
|
6
22
|
## [1.0.0] - 2026-11-23
|
|
7
23
|
|
|
8
24
|
Primeira versão pública: código aberto (MIT) em https://github.com/ricardopiresqa/pink e pacote `@thothdev/pink` no npm. As
|
package/README.md
CHANGED
|
@@ -1,95 +1,142 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
- **
|
|
54
|
-
- **
|
|
55
|
-
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/ricardopiresqa/pink/main/docs/images/pink-logo.png" alt="PINK" width="360">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<b>The coding agent for your terminal that works where you can see it.</b><br>
|
|
7
|
+
Plan, changed files and context on screen, many sessions side by side, a real undo,
|
|
8
|
+
and the agents you already pay for, all in one place.
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@thothdev/pink"><img src="https://img.shields.io/npm/v/@thothdev/pink?color=ff6eb4&label=npm" alt="npm"></a>
|
|
13
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-ff6eb4" alt="MIT license"></a>
|
|
14
|
+
<a href="https://pink.thothdev.ia.br"><img src="https://img.shields.io/badge/site-pink.thothdev.ia.br-ff6eb4" alt="website"></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<a href="https://ko-fi.com/thothdev">♥ Support Pink on Ko-fi</a>
|
|
19
|
+
·
|
|
20
|
+
<a href="https://github.com/ricardopiresqa/pink/discussions/new?category=ideas">💡 Suggest an idea</a>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
<p align="center">
|
|
24
|
+
<img src="https://raw.githubusercontent.com/ricardopiresqa/pink/main/docs/images/pink-screen.png" alt="Pink in the terminal: sessions on the left, the conversation in the middle, context, plan and changed files on the right" width="900">
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install -g @thothdev/pink
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Then run `pink` inside your project folder. Needs Node.js 22.19 or newer.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pink # interactive session
|
|
37
|
+
pink -p "explain this repository" # one-shot answer
|
|
38
|
+
pink --help
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## What only Pink does
|
|
42
|
+
|
|
43
|
+
| | |
|
|
44
|
+
|---|---|
|
|
45
|
+
| **Use the agents you already have** | `/agente claude`, `/agente codex`, `/agente opencode`... hands the session to Claude Code, Codex, opencode, Gemini, Qwen, Cline, Goose or Copilot, with their own login and plan. No new API key. A menu picks the model; `/agente off` comes back. |
|
|
46
|
+
| **Your rules come along** | The chosen agent gets Pink's MCP servers, `AGENTS.md` and skills, and can call Pink itself as an MCP tool (`pink_tarefa`). |
|
|
47
|
+
| **Sees and uses your screen** | On Windows, `/tela ligar` lets the agent see your windows and click or type in them. Seeing never asks; every click asks for your OK, and typing into a terminal asks twice. Off by default. |
|
|
48
|
+
| **Sessions side by side** | Each session runs in its own process in the left sidebar. If one hangs, the others keep going. A spinner shows who is working and `!` who is waiting for you. |
|
|
49
|
+
| **A real `/undo`** | Rolls back the last message, the replies and the file changes, and puts your text back in the box, without touching your git index, stash or commits. |
|
|
50
|
+
|
|
51
|
+
## Everything else
|
|
52
|
+
|
|
53
|
+
- **Build and Plan agents.** `tab` on an empty box switches. Plan only reads and plans: it asks before running a command and never edits files.
|
|
54
|
+
- **Subagents.** The `subagent` tool hands work to a separate `pink` process, alone, in parallel or in a chain. Custom agents live in `~/.pink/agent/agents/*.md`.
|
|
55
|
+
- **Guard before danger.** Destructive commands ask first; `.env`, `.git` and keys are protected. Rules go in `permissions.json` (`allow` / `ask` / `deny`), and hooks in `hooks.json` use the Claude Code format.
|
|
56
|
+
- **MCP and the web.** `/mcp` connects MCP servers. `web_search` and `web_fetch` work with no key and no extra server.
|
|
57
|
+
- **Compact transcript.** Each read, edit and command becomes one short line. `ctrl+o` opens the full tool output with the diff, `ctrl+t` opens the thinking.
|
|
58
|
+
- **Adapts to the width.** Three columns from 150 columns up, two from 115, just the conversation below that.
|
|
59
|
+
- **Questions with options**, a todo list in the sidebar, and a system notification when an answer finishes while the window is in the background.
|
|
60
|
+
|
|
61
|
+
## Keys and commands
|
|
62
|
+
|
|
63
|
+
| Key / command | What it does |
|
|
64
|
+
|---|---|
|
|
65
|
+
| `ctrl+p` | Command palette (also `/help`) |
|
|
66
|
+
| `tab` (empty box) | Switch between Build and Plan |
|
|
67
|
+
| `f2` / `shift+f2` | Next / previous model |
|
|
68
|
+
| `ctrl+t` / `ctrl+o` | Open thinking / full tool output |
|
|
69
|
+
| `ctrl+n` | New session |
|
|
70
|
+
| `/agente [name] [model]` | Talk to an installed agent; `/agente off` returns to Pink |
|
|
71
|
+
| `/tela ligar` | Let the agent see and use the screen (Windows) |
|
|
72
|
+
| `/undo` / `/redo` | Undo / redo the last message and its file changes |
|
|
73
|
+
| `/sessions`, `/themes`, `/mcp` | Switch session, pick a theme, manage MCP servers |
|
|
74
|
+
| `/lateral` | Hide or show the side columns |
|
|
75
|
+
| `/sugestao [text]` | Open the ideas page on GitHub, with your text as the title |
|
|
76
|
+
|
|
77
|
+
## Support and ideas
|
|
78
|
+
|
|
79
|
+
Pink is free and open source. If it saves you time, you can [buy us a coffee on Ko-fi](https://ko-fi.com/thothdev).
|
|
80
|
+
Ideas and requests go to [GitHub Discussions](https://github.com/ricardopiresqa/pink/discussions/categories/ideas), where others can vote on them; bugs go to [issues](https://github.com/ricardopiresqa/pink/issues).
|
|
81
|
+
|
|
82
|
+
## Configuration
|
|
83
|
+
|
|
84
|
+
- Settings live in `~/.pink/agent/` (or `$PINK_CODING_AGENT_DIR`) and in `.pink/` inside the project. Environment variables start with `PINK_`.
|
|
85
|
+
- Providers and models: `~/.pink/agent/models.json` (see `docs/models.md`).
|
|
86
|
+
- No sidebar of sessions: `pink --sem-sessoes` or `PINK_NO_MUX=1`. The sidebar needs the optional `node-pty`; without it Pink runs as a single session.
|
|
87
|
+
- Plain look without Pink's interface: `PINK_NO_BUILTIN_UI=1 pink --tui-mode regular`.
|
|
88
|
+
|
|
89
|
+
## Thoth in the sidebar (optional)
|
|
90
|
+
|
|
91
|
+
If [Thoth](https://thothdev.ia.br) runs on the same machine, the right column gets a **THOTH** section with the approvals waiting for you, the card in progress for this folder and the model that answered the last Thoth gateway call. It only reads, in the background, every 30 seconds. Without Thoth the section says it is unavailable and Pink works as usual.
|
|
92
|
+
|
|
93
|
+
## Privacy
|
|
94
|
+
|
|
95
|
+
Pink sends no install telemetry and checks no versions on third-party servers. What leaves your machine is what you send to your model provider.
|
|
96
|
+
|
|
97
|
+
<details>
|
|
98
|
+
<summary><b>Pink colors in Windows Terminal</b></summary>
|
|
99
|
+
|
|
100
|
+
Pink uses your terminal's background. For the dark `#100d13` of the screenshots, add this scheme to `"schemes"` in Windows Terminal's `settings.json` and pick **Pink** under Profile → Appearance → Color scheme.
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"name": "Pink",
|
|
105
|
+
"background": "#100D13",
|
|
106
|
+
"foreground": "#F2EDF4",
|
|
107
|
+
"cursorColor": "#FF6EB4",
|
|
108
|
+
"selectionBackground": "#49243D",
|
|
109
|
+
"black": "#17131B",
|
|
110
|
+
"red": "#E05555",
|
|
111
|
+
"green": "#8DE0B1",
|
|
112
|
+
"yellow": "#F0C487",
|
|
113
|
+
"blue": "#6AA6F8",
|
|
114
|
+
"purple": "#B7A4FF",
|
|
115
|
+
"cyan": "#56C2C9",
|
|
116
|
+
"white": "#D7CEDB",
|
|
117
|
+
"brightBlack": "#6B6170",
|
|
118
|
+
"brightRed": "#FF6E8A",
|
|
119
|
+
"brightGreen": "#A8F0C6",
|
|
120
|
+
"brightYellow": "#FFD9A3",
|
|
121
|
+
"brightBlue": "#8FBCFF",
|
|
122
|
+
"brightPurple": "#FF9BCE",
|
|
123
|
+
"brightCyan": "#7FDDE3",
|
|
124
|
+
"brightWhite": "#F2EDF4"
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
</details>
|
|
129
|
+
|
|
130
|
+
## Building from source
|
|
131
|
+
|
|
132
|
+
The fork is a reproducible patch (`rebrand.json`) over a pinned upstream tarball, not a copy of its code:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
python -X utf8 build_pink.py --out out # builds out/thothdev-pink-<version>.tgz
|
|
136
|
+
npm install -g out/thothdev-pink-*.tgz
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
Pink is a fork of [Pi](https://github.com/earendil-works/pi-mono) (MIT, copyright (c) 2025 Mario Zechner): the agent loop, providers, terminal UI, sessions and compaction come from it, with Pink's own interface, theme and extensions on top.
|
|
142
|
+
License: MIT (see `LICENSE`); the upstream license is in `LICENSE-PI.txt`, and `NOTICE.md` lists what changed.
|
|
@@ -188,17 +188,54 @@ export function codexUsage(tokenUsage: any, result: any): void {
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
// ---------- ACP: atualizações da sessão ----------
|
|
191
|
-
|
|
191
|
+
// o tipo da ferramenta no ACP vira o nome da ferramenta do Pink, para a linha sair igual ("Rodou: ...", "Leu ...")
|
|
192
|
+
const ACP_TOOLS: Record<string, string> = { execute: "bash", read: "read", edit: "edit", search: "grep", fetch: "web_fetch", delete: "delete", move: "move" };
|
|
193
|
+
function acpArgs(update: any, before: Record<string, unknown> = {}): Record<string, unknown> {
|
|
194
|
+
const input = update.rawInput && typeof update.rawInput === "object" ? update.rawInput : {};
|
|
195
|
+
const where = Array.isArray(update.locations) ? update.locations[0]?.path : undefined;
|
|
196
|
+
const args: Record<string, unknown> = { ...before };
|
|
197
|
+
if (update.title) args.title = String(update.title);
|
|
198
|
+
const pathArg = input.path ?? input.filePath ?? input.file_path ?? where;
|
|
199
|
+
if (pathArg) args.path = String(pathArg);
|
|
200
|
+
if (input.command) args.command = String(input.command);
|
|
201
|
+
if (input.pattern ?? input.query) args.pattern = String(input.pattern ?? input.query);
|
|
202
|
+
return args;
|
|
203
|
+
}
|
|
204
|
+
const flushThinking = (result: any, state: any) => {
|
|
205
|
+
if (state.thinking) push(result, [{ type: "thinking", thinking: state.thinking, ms: Date.now() - state.thoughtAt }]);
|
|
206
|
+
state.thinking = "";
|
|
207
|
+
state.thoughtAt = undefined;
|
|
208
|
+
};
|
|
209
|
+
export function applyAcpUpdate(update: any, result: any, state: { text: string; thinking?: string; thoughtAt?: number }, emit: () => void): void {
|
|
192
210
|
if (!update || typeof update !== "object") return;
|
|
211
|
+
if (update.sessionUpdate === "agent_thought_chunk" && update.content?.type === "text") {
|
|
212
|
+
state.thoughtAt ??= Date.now();
|
|
213
|
+
state.thinking = (state.thinking ?? "") + String(update.content.text ?? "");
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
193
216
|
if (update.sessionUpdate === "agent_message_chunk" && update.content?.type === "text") {
|
|
217
|
+
flushThinking(result, state);
|
|
194
218
|
state.text += String(update.content.text ?? "");
|
|
195
219
|
return;
|
|
196
220
|
}
|
|
197
221
|
if (update.sessionUpdate === "tool_call") {
|
|
222
|
+
flushThinking(result, state);
|
|
198
223
|
if (state.text) push(result, [{ type: "text", text: state.text }]), (state.text = "");
|
|
199
|
-
const name = typeof update.kind === "string" && update.kind !== "other" ? update.kind : "tool";
|
|
200
|
-
push(result, [tool(name,
|
|
224
|
+
const name = ACP_TOOLS[update.kind] ?? (typeof update.kind === "string" && update.kind !== "other" ? update.kind : "tool");
|
|
225
|
+
push(result, [tool(name, acpArgs(update), String(update.toolCallId ?? ""))]);
|
|
201
226
|
emit();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
// o opencode manda o comando e o arquivo só na atualização (o tool_call chega com título "shell" e entrada vazia)
|
|
230
|
+
if (update.sessionUpdate === "tool_call_update" && update.toolCallId) {
|
|
231
|
+
for (const message of result.messages) {
|
|
232
|
+
const part = message.content?.find((item: any) => item.type === "toolCall" && item.id === String(update.toolCallId));
|
|
233
|
+
if (!part) continue;
|
|
234
|
+
part.arguments = acpArgs(update, part.arguments);
|
|
235
|
+
if (part.name === "bash" && !part.arguments.command && update.title) part.arguments.command = String(update.title);
|
|
236
|
+
emit();
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
202
239
|
}
|
|
203
240
|
}
|
|
204
241
|
|
|
@@ -493,6 +530,9 @@ async function runAcp(child: any, name: string, task: string, cwd: string, resul
|
|
|
493
530
|
config = session.result?.configOptions ?? [];
|
|
494
531
|
}
|
|
495
532
|
if (resume && sessionId) resume.id = sessionId;
|
|
533
|
+
// sem escolha, o rodapé mostra o modelo que o agente usa de fato (ex.: opencode/big-pickle), não o nome do agente
|
|
534
|
+
const current = config.find((item: any) => item?.category === "model")?.currentValue;
|
|
535
|
+
if (!model && typeof current === "string" && current) result.model = current;
|
|
496
536
|
if (model && sessionId) {
|
|
497
537
|
const option = config.find((item: any) => item?.category === "model");
|
|
498
538
|
const set = option ? await client.request("session/set_config_option", { sessionId, configId: option.id, value: model }) : await client.request("session/set_model", { sessionId, modelId: model });
|
|
@@ -9,6 +9,7 @@ import os from "node:os";
|
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
11
|
import { externalAgents, listModels, pinkExtras, runExternal } from "../examples/extensions/subagent/external.ts";
|
|
12
|
+
import { bulleted, runLabel, shortModel, streamedTokens, thinkingLabel, toolSummary, userLines } from "./pink-ui.ts";
|
|
12
13
|
|
|
13
14
|
// o Pink junto (card 1dfwh7kgfjx): MCPs do mcp.json, AGENTS.md e skills do Pink, mais o próprio Pink como MCP
|
|
14
15
|
const readJson = (file: string) => {
|
|
@@ -36,51 +37,143 @@ export function gatherExtras(pink: any, dir = process.env.PINK_CODING_AGENT_DIR
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
const STATUS = "pink-agente";
|
|
40
|
+
const WIDGET = "pink-agente-trabalhando";
|
|
41
|
+
const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
39
42
|
|
|
40
43
|
const fresh = () => ({ messages: [] as any[], stderr: "", exitCode: 0, usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, contextTokens: 0, turns: 0 } });
|
|
41
44
|
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
// nomes e argumentos de cada agente (Claude: Read/file_path, Glob...) viram os do Pink, para a linha sair igual à nativa
|
|
46
|
+
const NAMES: Record<string, string> = { multiedit: "edit", glob: "find", notebookedit: "edit" };
|
|
47
|
+
export function pinkTool(part: any, cwd = "") {
|
|
48
|
+
const raw = String(part?.name ?? "tool");
|
|
49
|
+
const name = NAMES[raw.toLowerCase()] ?? raw.toLowerCase();
|
|
50
|
+
const args = { ...(part?.arguments ?? {}) };
|
|
51
|
+
const file = args.path ?? args.file_path ?? args.filePath ?? args.notebook_path;
|
|
52
|
+
if (file) args.path = cwd && path.isAbsolute(String(file)) ? path.relative(cwd, String(file)) || "." : String(file);
|
|
53
|
+
const line = toolSummary(name, args);
|
|
54
|
+
return line === name && args.title ? String(args.title) : line;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// os passos da resposta, na ordem: pensou, ferramentas e textos (o desenho usa; o modelo do Pink lê o texto puro)
|
|
58
|
+
export function steps(result: any, cwd = "") {
|
|
59
|
+
const out: any[] = [];
|
|
46
60
|
for (const message of result.messages) {
|
|
47
61
|
for (const part of message.content ?? []) {
|
|
48
|
-
if (part.type === "text")
|
|
49
|
-
else if (part.type === "
|
|
50
|
-
|
|
51
|
-
lines.push(`• ${part.name}${arg ? ` ${String(arg).split("\n")[0].slice(0, 120)}` : ""}`);
|
|
52
|
-
}
|
|
62
|
+
if (part.type === "text" && part.text?.trim()) out.push({ kind: "text", text: part.text });
|
|
63
|
+
else if (part.type === "thinking") out.push({ kind: "thinking", ms: part.ms >= 100 ? part.ms : 0 }); // o pensamento chega de uma vez: tempo quase 0 não diz nada
|
|
64
|
+
else if (part.type === "toolCall") out.push({ kind: "tool", line: pinkTool(part, cwd) });
|
|
53
65
|
}
|
|
54
66
|
}
|
|
55
|
-
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function render(result: any, cwd = ""): string {
|
|
71
|
+
const all = steps(result, cwd);
|
|
72
|
+
const tools = all.filter((step) => step.kind === "tool").map((step) => `→ ${step.line}`);
|
|
73
|
+
const answer = all.filter((step) => step.kind === "text").at(-1)?.text ?? "";
|
|
74
|
+
const body = [tools.join("\n"), answer].filter(Boolean).join("\n\n");
|
|
56
75
|
if (result.stopReason === "error") return [body, `⚠ ${result.errorMessage}`].filter(Boolean).join("\n\n");
|
|
57
76
|
return body || t("(sem resposta)", "(sin respuesta)", "(no answer)");
|
|
58
77
|
}
|
|
59
78
|
|
|
79
|
+
const outputOf = (result: any) => result.usage?.output || result.messages.reduce((sum: number, message: any) => sum + streamedTokens(message), 0);
|
|
80
|
+
|
|
60
81
|
const label = (agent: any) => (agent.model ? `${agent.name} · ${agent.model}` : agent.name);
|
|
61
82
|
|
|
62
|
-
|
|
83
|
+
const loadTui = () => Promise.all([import("@earendil-works/pi-tui"), import("@earendil-works/pi-coding-agent")]);
|
|
84
|
+
|
|
85
|
+
export default function (pink: any, list: typeof externalAgents = externalAgents, run: typeof runExternal = runExternal, models: typeof listModels = listModels, extras: () => any = () => gatherExtras(pink), load: () => Promise<any[]> = loadTui) {
|
|
63
86
|
let active: { agent: any; resume: { id?: string }; controller?: AbortController } | undefined;
|
|
87
|
+
let ticker: ReturnType<typeof setInterval> | undefined;
|
|
88
|
+
let lastUi: any;
|
|
89
|
+
|
|
90
|
+
// "⠴ Trabalhando · 2s · ↓ 0 tokens" acima da caixa, com o mesmo Loader do Pink: o dele só aparece quando o modelo do Pink
|
|
91
|
+
// responde, e este ocupa o mesmo lugar
|
|
92
|
+
let loader: any;
|
|
93
|
+
const idle = () => {
|
|
94
|
+
if (ticker) clearInterval(ticker);
|
|
95
|
+
ticker = undefined;
|
|
96
|
+
loader?.stop?.();
|
|
97
|
+
loader = undefined;
|
|
98
|
+
lastUi?.setWidget?.(WIDGET, undefined);
|
|
99
|
+
};
|
|
100
|
+
const busy = (ui: any, output: () => number) => {
|
|
101
|
+
idle();
|
|
102
|
+
lastUi = ui;
|
|
103
|
+
if (!ui?.setWidget) return;
|
|
104
|
+
const started = Date.now();
|
|
105
|
+
const message = () => `${t("Trabalhando", "Trabajando", "Working")} · ${runLabel({ ms: Date.now() - started, output: output() })}`;
|
|
106
|
+
if (tui?.Loader) {
|
|
107
|
+
ui.setWidget(WIDGET, (screen: any, theme: any) => (loader = new tui.Loader(screen, (s: string) => theme.fg("accent", s), (s: string) => theme.fg("muted", s), message())), { placement: "aboveEditor" });
|
|
108
|
+
ticker = setInterval(() => loader?.setMessage?.(message()), 1000);
|
|
109
|
+
} else {
|
|
110
|
+
let frame = 0;
|
|
111
|
+
const draw = () => ui.setWidget(WIDGET, ["", ` ${FRAMES[frame++ % FRAMES.length]} ${message()}`], { placement: "aboveEditor" });
|
|
112
|
+
draw();
|
|
113
|
+
ticker = setInterval(draw, 120);
|
|
114
|
+
}
|
|
115
|
+
ticker.unref?.();
|
|
116
|
+
};
|
|
64
117
|
|
|
65
118
|
const stop = (ctx?: any) => {
|
|
66
119
|
active?.controller?.abort();
|
|
67
120
|
active = undefined;
|
|
121
|
+
idle();
|
|
68
122
|
(globalThis as any).__pinkExternalAgent = undefined; // o rótulo da caixa volta a "Build · modelo" (pink-ui)
|
|
69
123
|
ctx?.ui?.setStatus?.(STATUS, undefined);
|
|
70
124
|
};
|
|
71
125
|
|
|
126
|
+
// mensagens desenhadas como as do Pink: "> oi", "+ Pensou · 0.4s", "→ Rodou: ...", "● resposta" e o rodapé
|
|
127
|
+
// "opencode · big-pickle · 7s · ↓ 49 tokens" (mesmas funções do pink-ui)
|
|
128
|
+
let tui: any;
|
|
129
|
+
let coding: any;
|
|
130
|
+
void load().then(([a, b]) => {
|
|
131
|
+
tui = a;
|
|
132
|
+
coding = b;
|
|
133
|
+
}).catch(() => undefined);
|
|
134
|
+
const textOf = (message: any) => (typeof message.content === "string" ? message.content : (message.content ?? []).map((part: any) => part.text ?? "").join(""));
|
|
135
|
+
const bold = (theme: any, text: string) => (theme.bold ? theme.bold(text) : text);
|
|
136
|
+
pink.registerMessageRenderer?.("pink-agente-pedido", (message: any, options: any, theme: any) => {
|
|
137
|
+
if (!tui || !coding?.getMarkdownTheme) return undefined;
|
|
138
|
+
const md = new tui.Markdown(String(message.details?.text ?? textOf(message)), options.outputPad, 1, coding.getMarkdownTheme(), { color: (s: string) => theme.fg("userMessageText", s), bgColor: (s: string) => theme.bg("userMessageBg", s) });
|
|
139
|
+
return { render: (width: number) => userLines(md.render(Math.max(1, width - 1)), theme.fg("muted", ">")), invalidate: () => md.invalidate?.() };
|
|
140
|
+
});
|
|
141
|
+
pink.registerMessageRenderer?.("pink-agente", (message: any, options: any, theme: any) => {
|
|
142
|
+
if (!tui || !coding?.getMarkdownTheme) return undefined;
|
|
143
|
+
const details = message.details ?? {};
|
|
144
|
+
const pad = options.outputPad ?? 1;
|
|
145
|
+
const box = new tui.Container();
|
|
146
|
+
const list = Array.isArray(details.steps) ? details.steps : [{ kind: "text", text: textOf(message) }];
|
|
147
|
+
for (const step of list) {
|
|
148
|
+
box.addChild(new tui.Spacer(1));
|
|
149
|
+
if (step.kind === "thinking") box.addChild(new tui.Text(theme.fg("thinkingText", thinkingLabel(step.ms)), pad, 0));
|
|
150
|
+
else if (step.kind === "tool") box.addChild(new tui.Text(theme.fg("muted", `→ ${step.line}`), pad, 0));
|
|
151
|
+
else box.addChild(bulleted(new tui.Markdown(String(step.text).trim(), pad, 0, coding.getMarkdownTheme())));
|
|
152
|
+
}
|
|
153
|
+
if (details.error) box.addChild(new tui.Spacer(1)), box.addChild(new tui.Text(theme.fg("error", `⚠ ${details.error}`), pad, 0));
|
|
154
|
+
const footer = [bold(theme, theme.fg("accent", details.agent ?? t("agente", "agente", "agent")))];
|
|
155
|
+
if (details.model) footer.push(theme.fg("text", shortModel(details.model)));
|
|
156
|
+
if (details.ms !== undefined) footer.push(theme.fg("muted", runLabel({ ms: details.ms, output: details.output ?? 0 })));
|
|
157
|
+
box.addChild(new tui.Spacer(1));
|
|
158
|
+
box.addChild(new tui.Text(footer.join(theme.fg("dim", " · ")), pad, 0));
|
|
159
|
+
return box;
|
|
160
|
+
});
|
|
161
|
+
|
|
72
162
|
const send = async (text: string, ctx: any) => {
|
|
73
163
|
const current = active!;
|
|
74
164
|
const controller = new AbortController();
|
|
75
165
|
current.controller = controller;
|
|
76
166
|
const name = current.agent.name;
|
|
77
|
-
pink.sendMessage({ customType: "pink-agente-pedido", display: true, content: `› ${name}: ${text}`, details: { agent: name } });
|
|
167
|
+
pink.sendMessage({ customType: "pink-agente-pedido", display: true, content: `› ${name}: ${text}`, details: { agent: name, text } });
|
|
78
168
|
const result = fresh();
|
|
169
|
+
const started = Date.now();
|
|
170
|
+
const lastTool = () => result.messages.at(-1)?.content?.find((part: any) => part.type === "toolCall")?.name;
|
|
79
171
|
const status = () => {
|
|
80
|
-
const last =
|
|
81
|
-
ctx.ui?.setStatus?.(STATUS, `${name} ${t("trabalhando", "trabajando", "working")}${last ? `: ${last
|
|
172
|
+
const last = lastTool();
|
|
173
|
+
ctx.ui?.setStatus?.(STATUS, `${name} ${t("trabalhando", "trabajando", "working")}${last ? `: ${last}` : "…"}`);
|
|
82
174
|
};
|
|
83
175
|
status();
|
|
176
|
+
if (ctx.hasUI) busy(ctx.ui, () => outputOf(result));
|
|
84
177
|
(globalThis as any).__pinkExternalAsk = ctx.hasUI ? (title: string, body: string) => ctx.ui.confirm(title, body) : undefined;
|
|
85
178
|
try {
|
|
86
179
|
await run(current.agent, text, ctx.cwd, controller.signal, result, status, undefined, undefined, current.resume);
|
|
@@ -89,12 +182,42 @@ export default function (pink: any, list: typeof externalAgents = externalAgents
|
|
|
89
182
|
result.errorMessage = controller.signal.aborted ? t("cancelado", "cancelado", "cancelled") : String(error?.message ?? error);
|
|
90
183
|
}
|
|
91
184
|
if (current.controller === controller) current.controller = undefined;
|
|
92
|
-
if (active === current
|
|
93
|
-
|
|
185
|
+
if (active === current || !active) idle();
|
|
186
|
+
if (active === current) {
|
|
187
|
+
ctx.ui?.setStatus?.(STATUS, `${t("agente", "agente", "agent")}: ${label(current.agent)}`);
|
|
188
|
+
// a caixa passa a mostrar o modelo que o agente usou de fato, em vez de "modelo padrão"
|
|
189
|
+
if (!current.agent.model && result.model && result.model !== name) (globalThis as any).__pinkExternalAgent = { name, model: result.model };
|
|
190
|
+
}
|
|
191
|
+
const error = result.stopReason === "error" ? String(result.errorMessage ?? t("erro", "error", "error")) : undefined;
|
|
192
|
+
pink.sendMessage({ customType: "pink-agente", display: true, content: render(result, ctx.cwd), details: { agent: name, model: result.model, usage: result.usage, error, steps: steps(result, ctx.cwd), ms: Date.now() - started, output: outputOf(result) } });
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// "/agente " lista as opções, como os outros comandos: off e os agentes; "/agente codex " lista os modelos dele
|
|
196
|
+
const modelCache = new Map<string, Promise<any[]>>();
|
|
197
|
+
const completions = async (prefix: string) => {
|
|
198
|
+
const text = String(prefix ?? "").replace(/^\s+/, "");
|
|
199
|
+
const space = text.indexOf(" ");
|
|
200
|
+
const agents = list();
|
|
201
|
+
if (space < 0) {
|
|
202
|
+
const items = [
|
|
203
|
+
...(active ? [{ value: "off", label: "off", description: t(`volta ao Pink (desliga o ${active.agent.name})`, `vuelve a Pink (apaga ${active.agent.name})`, `back to Pink (turns ${active.agent.name} off)`) }] : []),
|
|
204
|
+
...agents.map((agent) => ({ value: agent.name, label: agent.name, description: t(`conversar com o ${agent.name}, com o login dele`, `conversar con ${agent.name}, con su login`, `talk to ${agent.name}, with its own login`) })),
|
|
205
|
+
];
|
|
206
|
+
const hits = items.filter((item) => item.value.startsWith(text.toLowerCase()));
|
|
207
|
+
return hits.length ? hits : null;
|
|
208
|
+
}
|
|
209
|
+
const agent = agents.find((item) => item.name === text.slice(0, space).toLowerCase());
|
|
210
|
+
if (!agent) return null;
|
|
211
|
+
const wanted = text.slice(space + 1).trim();
|
|
212
|
+
if (!modelCache.has(agent.name)) modelCache.set(agent.name, models(agent, process.cwd()).catch(() => (modelCache.delete(agent.name), [])));
|
|
213
|
+
const choices = await modelCache.get(agent.name)!;
|
|
214
|
+
const hits = choices.filter((choice) => choice.id.startsWith(wanted) || String(choice.label).toLowerCase().startsWith(wanted.toLowerCase())).map((choice) => ({ value: `${agent.name} ${choice.id}`, label: choice.id, description: `${choice.label !== choice.id ? choice.label : ""}${choice.current ? ` (${t("padrão", "predeterminado", "default")})` : ""}`.trim() || undefined }));
|
|
215
|
+
return hits.length ? hits : null;
|
|
94
216
|
};
|
|
95
217
|
|
|
96
218
|
pink.registerCommand("agente", {
|
|
97
219
|
description: t("Conversa direto com um agente instalado (claude, codex, opencode...) com o login dele; /agente off volta ao Pink", "Conversa directo con un agente instalado (claude, codex, opencode...) con su login; /agente off vuelve a Pink", "Talk straight to an installed agent (claude, codex, opencode...) with its own login; /agente off returns to Pink"),
|
|
220
|
+
getArgumentCompletions: completions,
|
|
98
221
|
handler: async (args: string, ctx: any) => {
|
|
99
222
|
const [first = "", ...rest] = String(args ?? "").trim().split(/\s+/);
|
|
100
223
|
const wanted = first.toLowerCase();
|
|
@@ -109,8 +232,15 @@ export default function (pink: any, list: typeof externalAgents = externalAgents
|
|
|
109
232
|
let name = wanted;
|
|
110
233
|
if (!name) {
|
|
111
234
|
if (!agents.length) return ctx.ui?.notify?.(t("Nenhum agente instalado encontrado (claude, codex, opencode, cline, copilot, qwen, goose, gemini).", "No se encontró ningún agente instalado (claude, codex, opencode, cline, copilot, qwen, goose, gemini).", "No installed agent found (claude, codex, opencode, cline, copilot, qwen, goose, gemini)."), "warning");
|
|
112
|
-
|
|
235
|
+
// com um agente ligado, o primeiro item volta ao modelo/provedor do Pink (o mesmo que /agente off)
|
|
236
|
+
const back = active ? t(`Voltar ao Pink (desliga o ${active.agent.name})`, `Volver a Pink (apaga ${active.agent.name})`, `Back to Pink (turns ${active.agent.name} off)`) : undefined;
|
|
237
|
+
name = ctx.hasUI ? ((await ctx.ui.select(t("Conversar com qual agente?", "¿Con qué agente conversar?", "Talk to which agent?"), [...(back ? [back] : []), ...agents.map((agent) => agent.name)])) ?? "") : "";
|
|
113
238
|
if (!name) return;
|
|
239
|
+
if (name === back) {
|
|
240
|
+
const was = active?.agent.name;
|
|
241
|
+
stop(ctx);
|
|
242
|
+
return ctx.ui?.notify?.(t(`Voltou ao Pink (${was} desligado).`, `Volviste a Pink (${was} apagado).`, `Back to Pink (${was} off).`), "info");
|
|
243
|
+
}
|
|
114
244
|
}
|
|
115
245
|
const agent = agents.find((item) => item.name === name);
|
|
116
246
|
if (!agent) return ctx.ui?.notify?.(t(`${name} não está instalado. Disponíveis: ${agents.map((a) => a.name).join(", ") || "nenhum"}.`, `${name} no está instalado. Disponibles: ${agents.map((a) => a.name).join(", ") || "ninguno"}.`, `${name} is not installed. Available: ${agents.map((a) => a.name).join(", ") || "none"}.`), "warning");
|
|
@@ -99,9 +99,26 @@ export function notifyExtension(pink, deps = {}) {
|
|
|
99
99
|
ctx.ui.notify?.(on ? t("Notificações ligadas", "Notificaciones activadas", "Notifications on") : t("Notificações desligadas", "Notificaciones desactivadas", "Notifications off"), "info");
|
|
100
100
|
},
|
|
101
101
|
});
|
|
102
|
+
// /sugestao [texto]: abre a página de ideias do Pink no navegador, com o texto como título (owner 2026-11-23)
|
|
103
|
+
pink.registerCommand?.("sugestao", {
|
|
104
|
+
description: t("Abre a página de sugestões do Pink no GitHub; o texto depois do comando vira o título", "Abre la página de sugerencias de Pink en GitHub; el texto después del comando se vuelve el título", "Opens Pink's suggestions page on GitHub; the text after the command becomes the title"),
|
|
105
|
+
handler: async (args, ctx) => {
|
|
106
|
+
const url = ideaUrl(args);
|
|
107
|
+
const opener = platform === "win32" ? "explorer" : platform === "darwin" ? "open" : "xdg-open";
|
|
108
|
+
try { run(opener, [url], { windowsHide: true }, () => {}); } catch { /* sem navegador: o endereço fica na mensagem */ }
|
|
109
|
+
ctx.ui.notify?.(t(`Abrindo as sugestões do Pink: ${url}`, `Abriendo las sugerencias de Pink: ${url}`, `Opening Pink's suggestions: ${url}`), "info");
|
|
110
|
+
},
|
|
111
|
+
});
|
|
102
112
|
return { state, send, isOn: () => on };
|
|
103
113
|
}
|
|
104
114
|
|
|
115
|
+
export const IDEAS_URL = "https://github.com/ricardopiresqa/pink/discussions/new?category=ideas";
|
|
116
|
+
// o texto vai codificado na URL e como argumento (sem shell): não vira comando
|
|
117
|
+
export const ideaUrl = (text = "") => {
|
|
118
|
+
const title = String(text ?? "").trim().slice(0, 200);
|
|
119
|
+
return title ? `${IDEAS_URL}&title=${encodeURIComponent(title)}` : IDEAS_URL;
|
|
120
|
+
};
|
|
121
|
+
|
|
105
122
|
export default function (pink) {
|
|
106
123
|
notifyExtension(pink);
|
|
107
124
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thothdev/pink",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Pink: coding agent of the Thoth project, with a pink theme",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"piConfig": {
|
|
@@ -104,6 +104,10 @@
|
|
|
104
104
|
"bugs": {
|
|
105
105
|
"url": "https://github.com/ricardopiresqa/pink/issues"
|
|
106
106
|
},
|
|
107
|
+
"funding": {
|
|
108
|
+
"type": "ko-fi",
|
|
109
|
+
"url": "https://ko-fi.com/thothdev"
|
|
110
|
+
},
|
|
107
111
|
"publishConfig": {
|
|
108
112
|
"access": "public",
|
|
109
113
|
"tag": "latest"
|