@thothdev/pink 1.0.16 → 1.0.27
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 +63 -0
- package/README.md +155 -54
- package/dist/bundle/chunks/chunk-T726RZZU.js +1 -1
- package/dist/mux/pink.mjs +153 -72
- package/examples/extensions/subagent/agents.ts +1 -1
- package/examples/extensions/subagent/background.ts +15 -10
- package/examples/extensions/subagent/external.ts +102 -14
- package/examples/extensions/subagent/pink-i18n.ts +24 -1
- package/extensions/pink-agente.ts +118 -13
- package/extensions/pink-context.ts +3 -3
- package/extensions/pink-hooks.ts +3 -3
- package/extensions/pink-i18n.ts +24 -1
- package/extensions/pink-loop.ts +5 -2
- package/extensions/pink-mcp-server.mjs +1 -1
- package/extensions/pink-memory.ts +2 -1
- package/extensions/pink-microfone.ts +2 -1
- package/extensions/pink-natives.ts +3 -3
- package/extensions/pink-notify.ts +3 -3
- package/extensions/pink-permissions.ts +22 -4
- package/extensions/pink-review.ts +19 -4
- package/extensions/pink-rules.ts +2 -2
- package/extensions/pink-sandbox.ts +2 -1
- package/extensions/pink-sessions-bus.ts +4 -4
- package/extensions/pink-shell-bg.ts +15 -10
- package/extensions/pink-skill-propose.ts +1 -0
- package/extensions/pink-skills.ts +3 -3
- package/extensions/pink-tela.ts +2 -1
- package/extensions/pink-ui.ts +213 -116
- package/extensions/pink-web.ts +26 -3
- package/package.json +16 -4
package/dist/mux/pink.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// resto da tela é a sessão ativa. O modo interativo do Pink segura uma sessão por vez, então cada sessão é um Pink filho num
|
|
4
4
|
// terminal virtual (node-pty + @xterm/headless) e este processo só desenha a lateral, a tela do filho ativo e repassa o teclado.
|
|
5
5
|
// Sem terminal interativo, com comando de uma vez (-p, --help, install...) ou sem node-pty, roda o Pink normal, sem lateral.
|
|
6
|
-
import { execFile } from "node:child_process";
|
|
6
|
+
import { execFile, spawnSync } from "node:child_process";
|
|
7
7
|
import { appendFileSync, closeSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, realpathSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { homedir, tmpdir } from "node:os";
|
|
9
9
|
import path from "node:path";
|
|
@@ -32,6 +32,28 @@ const SPIN = ["◜", "◠", "◝", "◞", "◡", "◟"]; // arco girando, como u
|
|
|
32
32
|
const CARD_BG = "48;2;32;30;38"; // fundo do card das outras sessões (a ativa usa ACTIVE_BG)
|
|
33
33
|
const PINK = "38;2;255;110;180";
|
|
34
34
|
|
|
35
|
+
// idioma da lateral: a mesma escolha de extensions/pink-i18n.ts (PINK_LANG, idioma de exibição do Windows, LANG, locale)
|
|
36
|
+
// shortcut: cópia curta do detect(): este arquivo roda antes do Pink e não importa .ts; mudou lá, mude aqui
|
|
37
|
+
function detectLang(vars = process.env) {
|
|
38
|
+
const pick = (tag) => { const base = String(tag ?? "").trim().toLowerCase().split(/[-_.]/)[0]; return base === "pt" || base === "es" ? base : "en"; };
|
|
39
|
+
if (vars.PINK_LANG) return pick(vars.PINK_LANG);
|
|
40
|
+
if (process.platform === "win32") {
|
|
41
|
+
try {
|
|
42
|
+
const out = String(spawnSync(`${vars.SystemRoot || "C:\\Windows"}\\System32\\reg.exe`, ["query", "HKCU\\Control Panel\\International\\User Profile", "/v", "Languages"], { windowsHide: true, timeout: 3000, encoding: "utf8" }).stdout ?? "");
|
|
43
|
+
const first = out.match(/REG_MULTI_SZ\s+([A-Za-z]{2,3}(?:-[A-Za-z0-9]+)*)/)?.[1];
|
|
44
|
+
if (first) return pick(first);
|
|
45
|
+
} catch { /* sem registro: segue */ }
|
|
46
|
+
}
|
|
47
|
+
const posix = vars.LC_ALL || vars.LC_MESSAGES || vars.LANG;
|
|
48
|
+
if (posix && !/^(C|POSIX)(\.|$)/.test(posix)) return pick(posix);
|
|
49
|
+
return pick(Intl.DateTimeFormat().resolvedOptions().locale);
|
|
50
|
+
}
|
|
51
|
+
const LANG = detectLang();
|
|
52
|
+
const t = (pt, es, en) => (LANG === "pt" ? pt : LANG === "es" ? es : en);
|
|
53
|
+
const sessionName = (index) => `${t("Sessão", "Sesión", "Session")} ${index + 1}`;
|
|
54
|
+
const YES = t("[ sim ]", "[ sí ]", "[ yes ]");
|
|
55
|
+
const NO = t("[ não ]", "[ no ]", "[ no ]");
|
|
56
|
+
|
|
35
57
|
// o lançador põe "--provider thoth --model thoth" antes de tudo; o Pink só reconhece subcomando como 1º argumento
|
|
36
58
|
export function subcommandFirst(argv) {
|
|
37
59
|
let i = 0;
|
|
@@ -109,7 +131,7 @@ export function shortTitle(title, index) {
|
|
|
109
131
|
// o título vem do processo da sessão: sem caracteres de controle ele não consegue mexer no terminal ao ser desenhado
|
|
110
132
|
const clean = (title ?? "").replace(/[\u0000-\u001f\u007f-\u009f]|\p{Cf}/gu, "").replace(/^\s*p(?:i|ink)\s*-\s*/i, "").replace(/^#+\s+/, "").trim(); // "# Missão" do markdown vira "Missão"
|
|
111
133
|
// só o nome do programa (antes da pasta ser confiável o Pink ainda não pôs a pasta no título) conta como vazio
|
|
112
|
-
return clean && !/^p(?:i|ink)$/i.test(clean) ? clean :
|
|
134
|
+
return clean && !/^p(?:i|ink)$/i.test(clean) ? clean : sessionName(index);
|
|
113
135
|
}
|
|
114
136
|
|
|
115
137
|
// estado de uma sessão a partir dos sinais do Pink filho: progresso (OSC 9;4) = trabalhando; fim do progresso ou sino numa
|
|
@@ -118,7 +140,17 @@ export function shortTitle(title, index) {
|
|
|
118
140
|
// 0xC0000005/0xC0000409 = queda do processo, 1 = erro tratado), e é ele que diz a causa
|
|
119
141
|
export function exitCodeText(code) {
|
|
120
142
|
const n = Number(code);
|
|
121
|
-
return Number.isFinite(n) && n > 255 ? `0x${(n >>> 0).toString(16).toUpperCase()}` : String(code);
|
|
143
|
+
return Number.isFinite(n) && (n > 255 || n < -255) ? `0x${(n >>> 0).toString(16).toUpperCase()}` : String(code);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// queda do processo (não é saída pedida nem erro tratado): código NTSTATUS de erro no Windows, ou sinal de falha fora dele.
|
|
147
|
+
// A sessão é reaberta sozinha, no máximo 3 vezes em 10 minutos, para uma falha que se repete não virar um laço
|
|
148
|
+
const CRASH_SIGNALS = new Set([4, 6, 7, 8, 11]); // ILL, ABRT, BUS, FPE, SEGV
|
|
149
|
+
export function crashRestarts(code, signal, previous = [], now = Date.now()) {
|
|
150
|
+
const status = Number(code) >>> 0;
|
|
151
|
+
if (!(CRASH_SIGNALS.has(signal) || (status >= 0xc0000000 && status !== 0xc000013a))) return undefined; // 0xC000013A = Ctrl+C
|
|
152
|
+
const recent = previous.filter((at) => now - at < 600_000);
|
|
153
|
+
return recent.length < 3 ? [...recent, now] : undefined;
|
|
122
154
|
}
|
|
123
155
|
export function logChildExit(session, exitCode, signal, env = process.env, write = appendFileSync) {
|
|
124
156
|
try {
|
|
@@ -222,11 +254,11 @@ export function sidebarWidth(columns) {
|
|
|
222
254
|
// o Pink põe no título "pink - nome - pasta" ou "pink - pasta"; a pasta conhecida vem antes, porque pode ter " - " no nome
|
|
223
255
|
export function sessionLabel(title, index, folder = "") {
|
|
224
256
|
const text = shortTitle(title, index);
|
|
225
|
-
if (folder && text === folder) return { name:
|
|
257
|
+
if (folder && text === folder) return { name: sessionName(index), folder };
|
|
226
258
|
if (folder && text.endsWith(` - ${folder}`)) return { name: text.slice(0, -folder.length - 3), folder };
|
|
227
259
|
const parts = text.split(" - ");
|
|
228
260
|
if (parts.length > 1) return { name: parts.slice(0, -1).join(" - "), folder: parts.at(-1) };
|
|
229
|
-
return { name:
|
|
261
|
+
return { name: sessionName(index), folder: text === sessionName(index) ? folder : text };
|
|
230
262
|
}
|
|
231
263
|
|
|
232
264
|
// o que roda em segundo plano na sessão: subagentes (OSC 9;pink-subagents=N) e comandos (OSC 9;pink-jobs=N)
|
|
@@ -238,16 +270,17 @@ export function backgroundSignal(data) {
|
|
|
238
270
|
function status(session, folder) {
|
|
239
271
|
const text = baseStatus(session, folder);
|
|
240
272
|
const count = (session.subagents ?? 0) + (session.jobs ?? 0);
|
|
241
|
-
return count && !session.exited ? `${text} · ${count} em 2º plano` : text;
|
|
273
|
+
return count && !session.exited ? `${text} · ${count} ${t("em 2º plano", "en 2º plano", "in background")}` : text;
|
|
242
274
|
}
|
|
243
275
|
|
|
244
276
|
function baseStatus(session, folder) {
|
|
245
|
-
if (session.exited) return "encerrada";
|
|
246
|
-
if (session.program?.state === "blocked") return session.program.kind === "permission" ? "pede permissão · espera você" : "pergunta · espera você";
|
|
247
|
-
if (session.program?.state === "error") return "parou com erro";
|
|
248
|
-
if (session
|
|
249
|
-
if (
|
|
250
|
-
return
|
|
277
|
+
if (session.exited) return t("encerrada", "cerrada", "closed");
|
|
278
|
+
if (session.program?.state === "blocked") return session.program.kind === "permission" ? t("pede permissão · espera você", "pide permiso · te espera", "needs permission · your turn") : t("pergunta · espera você", "pregunta · te espera", "question · your turn");
|
|
279
|
+
if (session.program?.state === "error") return t("parou com erro", "se detuvo con error", "stopped with error");
|
|
280
|
+
if (isWorking(session)) return t("trabalhando…", "trabajando…", "working…");
|
|
281
|
+
if (session.crashes?.length && session.attention) return t("caiu e foi reaberta", "cayó y se reabrió", "crashed, reopened");
|
|
282
|
+
if (session.attention) return t("terminou · espera você", "terminó · te espera", "done · your turn");
|
|
283
|
+
return folder || t("pronta", "lista", "ready");
|
|
251
284
|
}
|
|
252
285
|
|
|
253
286
|
export function hitAt(hits, x, y) {
|
|
@@ -260,7 +293,7 @@ export function sidebar({ sessions, active, width, rows, frame = 0, confirm, fol
|
|
|
260
293
|
const plain = (text) => fit(text, width);
|
|
261
294
|
const paint = (code, text) => `\x1b[${code}m${plain(text)}\x1b[0m`;
|
|
262
295
|
const compact = width < SIDEBAR;
|
|
263
|
-
const lines = [paint(`1;${PINK}`, compact ? " Pk" : " SESSÕES"), plain("")];
|
|
296
|
+
const lines = [paint(`1;${PINK}`, compact ? " Pk" : t(" SESSÕES", " SESIONES", " SESSIONS")), plain("")];
|
|
264
297
|
const hits = [];
|
|
265
298
|
const hit = (action, from = 0, to = width) => hits.push({ y: lines.length, from, to, action });
|
|
266
299
|
const asking = confirm && !compact ? wrap(confirm, width - 1) : [];
|
|
@@ -306,17 +339,17 @@ export function sidebar({ sessions, active, width, rows, frame = 0, confirm, fol
|
|
|
306
339
|
hits.splice(0, hits.length, ...hits.filter((item) => item.y < lines.length));
|
|
307
340
|
}
|
|
308
341
|
hit("new");
|
|
309
|
-
lines.push(paint(`1;${PINK}`, compact ? " +" : " + nova sessão"));
|
|
342
|
+
lines.push(paint(`1;${PINK}`, compact ? " +" : t(" + nova sessão", " + nueva sesión", " + new session")));
|
|
310
343
|
while (lines.length < top) lines.push(plain(""));
|
|
311
344
|
const out = lines.slice(0, top);
|
|
312
345
|
const kept = hits.filter((item) => item.y < top);
|
|
313
346
|
if (asking.length) {
|
|
314
347
|
for (const line of asking) out.push(paint(`1;${PINK}`, ` ${line}`));
|
|
315
|
-
kept.push({ y: out.length, from: 2, to:
|
|
316
|
-
out.push(paint("1",
|
|
348
|
+
kept.push({ y: out.length, from: 2, to: 2 + YES.length, action: "yes" }, { y: out.length, from: 4 + YES.length, to: 4 + YES.length + NO.length, action: "no" });
|
|
349
|
+
out.push(paint("1", ` ${YES} ${NO}`));
|
|
317
350
|
} else if (!compact) {
|
|
318
351
|
kept.push({ y: out.length, from: 0, to: width, action: "quit" });
|
|
319
|
-
out.push(paint("2", " sair do Pink"));
|
|
352
|
+
out.push(paint("2", t(" sair do Pink", " salir de Pink", " quit Pink")));
|
|
320
353
|
}
|
|
321
354
|
return { lines: out.slice(0, rows), hits: kept.filter((item) => item.y < rows) };
|
|
322
355
|
}
|
|
@@ -337,34 +370,52 @@ export function sessionsDir(env = process.env, home = homedir()) {
|
|
|
337
370
|
return path.join(env.PINK_CODING_AGENT_DIR || path.join(home, ".pink", "agent"), "sessions");
|
|
338
371
|
}
|
|
339
372
|
|
|
340
|
-
// cabeçalho (cwd), nome (/name) e primeira mensagem de uma sessão
|
|
341
|
-
//
|
|
342
|
-
|
|
373
|
+
// cabeçalho (cwd), nome (/name) e primeira mensagem de uma sessão. A 1ª mensagem vem depois do contexto do sistema, que
|
|
374
|
+
// passa de centenas de KB: lê em blocos até achá-la (no máximo 4 MB) e procura o nome também no fim do arquivo
|
|
375
|
+
// shortcut: um /name gravado no meio de um arquivo grande não aparece, fica a 1ª mensagem
|
|
376
|
+
const BLOCK = Buffer.alloc(262144);
|
|
343
377
|
function readHead(file) {
|
|
344
|
-
let text = "";
|
|
345
|
-
try {
|
|
346
|
-
const fd = openSync(file, "r");
|
|
347
|
-
try {
|
|
348
|
-
text = HEAD.toString("utf8", 0, readSync(fd, HEAD, 0, HEAD.length, 0));
|
|
349
|
-
} finally {
|
|
350
|
-
closeSync(fd);
|
|
351
|
-
}
|
|
352
|
-
} catch {
|
|
353
|
-
return {};
|
|
354
|
-
}
|
|
355
378
|
let cwd;
|
|
356
379
|
let name = "";
|
|
357
380
|
let first = "";
|
|
358
|
-
|
|
381
|
+
const take = (line) => {
|
|
359
382
|
let entry;
|
|
360
383
|
try {
|
|
361
384
|
entry = JSON.parse(line);
|
|
362
385
|
} catch {
|
|
363
|
-
|
|
386
|
+
return; // linha cortada pelo começo ou fim do bloco
|
|
364
387
|
}
|
|
365
388
|
if (entry?.type === "session" && !cwd && typeof entry.cwd === "string" && entry.cwd) cwd = entry.cwd;
|
|
366
389
|
else if (entry?.type === "session_info" && entry.name) name = oneLine(entry.name);
|
|
367
390
|
else if (!first && entry?.type === "message" && entry.message?.role === "user") first = oneLine(textOf(entry.message.content));
|
|
391
|
+
};
|
|
392
|
+
try {
|
|
393
|
+
const fd = openSync(file, "r");
|
|
394
|
+
try {
|
|
395
|
+
const size = statSync(file).size;
|
|
396
|
+
let at = 0;
|
|
397
|
+
let rest = Buffer.alloc(0);
|
|
398
|
+
while (at < size && at < 4 << 20 && !(cwd && first)) {
|
|
399
|
+
const read = readSync(fd, BLOCK, 0, BLOCK.length, at);
|
|
400
|
+
if (!read) break;
|
|
401
|
+
at += read;
|
|
402
|
+
let data = Buffer.concat([rest, BLOCK.subarray(0, read)]);
|
|
403
|
+
for (let end = data.indexOf(10); end >= 0; end = data.indexOf(10)) {
|
|
404
|
+
take(data.toString("utf8", 0, end));
|
|
405
|
+
data = data.subarray(end + 1);
|
|
406
|
+
}
|
|
407
|
+
rest = Buffer.from(data);
|
|
408
|
+
}
|
|
409
|
+
if (at >= size && rest.length) take(rest.toString("utf8"));
|
|
410
|
+
if (at < size) {
|
|
411
|
+
const read = readSync(fd, BLOCK, 0, BLOCK.length, Math.max(at, size - BLOCK.length));
|
|
412
|
+
for (const line of BLOCK.toString("utf8", 0, read).split("\n")) if (line.includes("session_info")) take(line);
|
|
413
|
+
}
|
|
414
|
+
} finally {
|
|
415
|
+
closeSync(fd);
|
|
416
|
+
}
|
|
417
|
+
} catch {
|
|
418
|
+
return {};
|
|
368
419
|
}
|
|
369
420
|
return { cwd, name: name || first };
|
|
370
421
|
}
|
|
@@ -454,44 +505,51 @@ const when = (ms) => {
|
|
|
454
505
|
|
|
455
506
|
// o seletor na área da sessão: linhas com `width` colunas e onde cada clique cai (base 0): cancel, folder:N, input,
|
|
456
507
|
// resume:N, delete:N. `saved[i].open` = a sessão está aberta agora (não exclui; clicar mostra ela)
|
|
457
|
-
export function pickerView({ folders, saved, input = "", width, rows, scroll = 0, error = "", current = "" }) {
|
|
508
|
+
export function pickerView({ folders, saved, input = "", width, rows, scroll = 0, error = "", current = "", asking }) {
|
|
458
509
|
const plain = (text) => fit(text, width);
|
|
459
510
|
const paint = (code, text) => `\x1b[${code}m${plain(text)}\x1b[0m`;
|
|
460
511
|
const lines = [];
|
|
461
512
|
const hits = [];
|
|
462
513
|
const hit = (action, from = 0, to = width) => hits.push({ y: lines.length, from, to, action });
|
|
463
|
-
const cancel = "[ cancelar ]";
|
|
514
|
+
const cancel = t("[ cancelar ]", "[ cancelar ]", "[ cancel ]");
|
|
464
515
|
hit("cancel", Math.max(0, width - cancel.length - 1), width);
|
|
465
|
-
lines.push(`\x1b[1;${PINK}m${fit(" Nova sessão", width - cancel.length - 1)}\x1b[0m\x1b[2m${cancel} \x1b[0m`);
|
|
466
|
-
lines.push(plain(""), paint("1", " Abrir numa pasta"));
|
|
516
|
+
lines.push(`\x1b[1;${PINK}m${fit(t(" Nova sessão", " Nueva sesión", " New session"), width - cancel.length - 1)}\x1b[0m\x1b[2m${cancel} \x1b[0m`);
|
|
517
|
+
lines.push(plain(""), paint("1", t(" Abrir numa pasta", " Abrir en una carpeta", " Open in a folder")));
|
|
467
518
|
folders.forEach((folder, index) => {
|
|
468
519
|
hit(`folder:${index}`);
|
|
469
|
-
const tag = samePath(folder, current) ? "(atual)" : "";
|
|
520
|
+
const tag = samePath(folder, current) ? t("(atual)", "(actual)", "(current)") : "";
|
|
470
521
|
// o cwd vem do arquivo da sessão: sem códigos de controle na tela
|
|
471
522
|
lines.push(plain(` ▸ ${fit(oneLine(path.basename(folder) || folder), 20)} ${fit(tag, 8)}${oneLine(folder)}`));
|
|
472
523
|
});
|
|
473
|
-
const label = " Outra pasta: ";
|
|
524
|
+
const label = t(" Outra pasta: ", " Otra carpeta: ", " Other folder: ");
|
|
474
525
|
hit("input");
|
|
475
526
|
const caret = { y: lines.length, x: Math.min(width - 1, charsWidth(label) + charsWidth(input)) };
|
|
476
527
|
const field = Math.max(1, width - charsWidth(label) - 1);
|
|
477
528
|
lines.push(`${label}\x1b[48;2;60;60;70m${fit(input.length > field ? input.slice(-field) : input, field)}\x1b[0m `);
|
|
478
|
-
lines.push(error ? paint("38;2;255;120;120", ` ${error}`) : paint("2", " digite o caminho e Enter · Esc fecha"));
|
|
479
|
-
lines.push(plain(""), paint("1", ` Sessões anteriores, de todas as pastas (${saved.length})`));
|
|
529
|
+
lines.push(error ? paint("38;2;255;120;120", ` ${error}`) : paint("2", t(" digite o caminho e Enter · Esc fecha", " escribe la ruta y Enter · Esc cierra", " type the path and Enter · Esc closes")));
|
|
530
|
+
lines.push(plain(""), paint("1", t(` Sessões anteriores, de todas as pastas (${saved.length})`, ` Sesiones anteriores, de todas las carpetas (${saved.length})`, ` Previous sessions, from all folders (${saved.length})`)));
|
|
480
531
|
const top = lines.length;
|
|
481
532
|
const room = Math.max(0, rows - top - 1);
|
|
482
533
|
const start = Math.max(0, Math.min(scroll, saved.length - Math.max(1, room)));
|
|
483
|
-
const del = " excluir ";
|
|
534
|
+
const del = t(" excluir ", " borrar ", " delete ");
|
|
535
|
+
const ASK = `${t(" excluir?", " ¿borrar?", " delete?")} ${YES} ${NO} `;
|
|
484
536
|
saved.slice(start, start + room).forEach((item, offset) => {
|
|
485
537
|
const index = start + offset;
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
538
|
+
const confirming = asking === item.file && !item.open;
|
|
539
|
+
const tail = confirming ? ASK : item.open ? t(" aberta ", " abierta ", " open ") : del;
|
|
540
|
+
hit(`resume:${index}`, 0, width - tail.length);
|
|
541
|
+
if (confirming) {
|
|
542
|
+
const yes = width - tail.length + tail.indexOf(YES);
|
|
543
|
+
const no = width - tail.length + tail.indexOf(NO);
|
|
544
|
+
hit(`yes:${index}`, yes, yes + YES.length);
|
|
545
|
+
hit(`no:${index}`, no, no + NO.length);
|
|
546
|
+
} else if (!item.open) hit(`delete:${index}`, width - del.length);
|
|
547
|
+
const text = ` ${when(item.mtime)} ${fit(oneLine(path.basename(item.cwd) || item.cwd), 18)} ${item.name || t("(sem mensagens)", "(sin mensajes)", "(no messages)")}`;
|
|
548
|
+
lines.push(`${fit(text, width - tail.length)}\x1b[${confirming ? `1;${PINK}` : item.open ? "2" : "38;2;255;140;140"}m${tail}\x1b[0m`);
|
|
491
549
|
});
|
|
492
|
-
if (!saved.length) lines.push(paint("2", " nenhuma sessão salva ainda"));
|
|
550
|
+
if (!saved.length) lines.push(paint("2", t(" nenhuma sessão salva ainda", " ninguna sesión guardada todavía", " no saved sessions yet")));
|
|
493
551
|
while (lines.length < rows - 1) lines.push(plain(""));
|
|
494
|
-
const more = room && saved.length > room ? ` ${start + 1}-${Math.min(saved.length, start + room)} de ${saved.length} · role com a roda do mouse` : "";
|
|
552
|
+
const more = room && saved.length > room ? ` ${start + 1}-${Math.min(saved.length, start + room)} ${t("de", "de", "of")} ${saved.length} · ${t("role com a roda do mouse", "desplaza con la rueda", "scroll with the mouse wheel")}` : "";
|
|
495
553
|
lines.push(paint("2", more));
|
|
496
554
|
return { lines: lines.slice(0, rows), hits: hits.filter((item) => item.y < rows), caret, scroll: start, room };
|
|
497
555
|
}
|
|
@@ -662,7 +720,7 @@ async function main() {
|
|
|
662
720
|
const right = view ? view.lines[y] ?? " ".repeat(inner) : buffer ? serializeLine(buffer.getLine(buffer.viewportY + y), inner, current.scratch) : " ".repeat(inner);
|
|
663
721
|
const full = `${lines[y] ?? " ".repeat(side)}\x1b[2;${PINK}m│\x1b[0m${right}`;
|
|
664
722
|
// lateral estreita não cabe a pergunta: ela ocupa a última linha da tela inteira
|
|
665
|
-
const shown = confirm && side < SIDEBAR && y === rows - 1 ? `\x1b[1;${PINK}m${fit(` ${confirm.text} s = sim · n = não`, side + 1 + inner)}\x1b[0m` : full;
|
|
723
|
+
const shown = confirm && side < SIDEBAR && y === rows - 1 ? `\x1b[1;${PINK}m${fit(` ${confirm.text} ${t("s = sim · n = não", "s = sí · n = no", "y = yes · n = no")}`, side + 1 + inner)}\x1b[0m` : full;
|
|
666
724
|
if (cache[y] !== shown) text += `\x1b[${y + 1};1H${shown}`;
|
|
667
725
|
cache[y] = shown;
|
|
668
726
|
}
|
|
@@ -739,6 +797,19 @@ async function main() {
|
|
|
739
797
|
if (!session.closing && exitCode !== 0) logChildExit(session, exitCode, signal);
|
|
740
798
|
const index = sessions.indexOf(session);
|
|
741
799
|
if (index < 0) return;
|
|
800
|
+
const crashes = !session.closing && !quittingAll && !finished && session.file && existsSync(session.file) ? crashRestarts(exitCode, signal, session.crashes) : undefined;
|
|
801
|
+
if (crashes) {
|
|
802
|
+
const was = active;
|
|
803
|
+
try {
|
|
804
|
+
open([...laterArgs(argv), "--session", session.file], session.cwd, session.file);
|
|
805
|
+
const fresh = sessions.pop();
|
|
806
|
+
Object.assign(fresh, { crashes, title: session.title, attention: true });
|
|
807
|
+
sessions.splice(index, 1, fresh); // no lugar da que caiu
|
|
808
|
+
term.dispose();
|
|
809
|
+
cache = [];
|
|
810
|
+
return select(was); // ver a sessão tira o aviso
|
|
811
|
+
} catch { /* não reabriu: segue como queda sem volta */ }
|
|
812
|
+
}
|
|
742
813
|
sessions.splice(index, 1);
|
|
743
814
|
// só fechar de propósito (×, /quit: código 0) tira da lista; erro ou morte (rede, janela fechada) mantém
|
|
744
815
|
if (session.closing || exitCode === 0) saveOpen();
|
|
@@ -806,15 +877,15 @@ async function main() {
|
|
|
806
877
|
if (action.startsWith("close:") && sessions[index]) {
|
|
807
878
|
const target = sessions[index];
|
|
808
879
|
const close = () => quitGently(target);
|
|
809
|
-
return target.working ? ask(`Encerrar "${sessionLabel(target.title, index, folder).name}"? Ela está trabalhando.`, close) : close();
|
|
880
|
+
return target.working ? ask(t(`Encerrar "${sessionLabel(target.title, index, folder).name}"? Ela está trabalhando.`, `¿Cerrar "${sessionLabel(target.title, index, folder).name}"? Está trabajando.`, `Close "${sessionLabel(target.title, index, folder).name}"? It is working.`), close) : close();
|
|
810
881
|
}
|
|
811
882
|
if (action === "quit") {
|
|
812
883
|
const all = () => {
|
|
813
884
|
quittingAll = true;
|
|
814
885
|
[...sessions].forEach(quitGently);
|
|
815
886
|
};
|
|
816
|
-
if (sessions.length > 1) return ask(`Sair do Pink com ${sessions.length} sessões abertas?`, all);
|
|
817
|
-
return current?.working ? ask("Sair do Pink? A sessão está trabalhando.", all) : all();
|
|
887
|
+
if (sessions.length > 1) return ask(t(`Sair do Pink com ${sessions.length} sessões abertas?`, `¿Salir de Pink con ${sessions.length} sesiones abiertas?`, `Quit Pink with ${sessions.length} sessions open?`), all);
|
|
888
|
+
return current?.working ? ask(t("Sair do Pink? A sessão está trabalhando.", "¿Salir de Pink? La sesión está trabajando.", "Quit Pink? The session is working."), all) : all();
|
|
818
889
|
}
|
|
819
890
|
};
|
|
820
891
|
|
|
@@ -836,7 +907,7 @@ async function main() {
|
|
|
836
907
|
try {
|
|
837
908
|
open([...laterArgs(argv), ...extra], cwd, file);
|
|
838
909
|
} catch {
|
|
839
|
-
picker = { ...back, error: "A sessão não abriu nesta pasta." }; // as abertas seguem
|
|
910
|
+
picker = { ...back, error: t("A sessão não abriu nesta pasta.", "La sesión no se abrió en esta carpeta.", "The session did not open in this folder.") }; // as abertas seguem
|
|
840
911
|
}
|
|
841
912
|
schedule();
|
|
842
913
|
};
|
|
@@ -844,6 +915,10 @@ async function main() {
|
|
|
844
915
|
const index = Number(action.split(":")[1]);
|
|
845
916
|
const item = picker.saved[index];
|
|
846
917
|
if (action === "cancel") return closePicker();
|
|
918
|
+
const asked = picker.asking;
|
|
919
|
+
picker.asking = undefined; // qualquer outro clique desiste da exclusão
|
|
920
|
+
if (action.startsWith("no:")) return schedule();
|
|
921
|
+
if (action.startsWith("yes:") && item && item.file === asked && !isOpen(item)) return removeSaved(item);
|
|
847
922
|
if (action.startsWith("folder:")) return startIn(picker.folders[index]);
|
|
848
923
|
if (action.startsWith("resume:") && item) {
|
|
849
924
|
if (isOpen(item)) {
|
|
@@ -853,27 +928,27 @@ async function main() {
|
|
|
853
928
|
return select(shown);
|
|
854
929
|
}
|
|
855
930
|
if (!existsSync(item.cwd)) {
|
|
856
|
-
picker.error = `A pasta desta sessão não existe mais: ${oneLine(item.cwd)}
|
|
931
|
+
picker.error = t(`A pasta desta sessão não existe mais: ${oneLine(item.cwd)}`, `La carpeta de esta sesión ya no existe: ${oneLine(item.cwd)}`, `The folder of this session no longer exists: ${oneLine(item.cwd)}`);
|
|
857
932
|
return schedule();
|
|
858
933
|
}
|
|
859
934
|
return startIn(item.cwd, ["--session", item.file], item.file);
|
|
860
935
|
}
|
|
861
|
-
if (action.startsWith("delete:") && item && !isOpen(item))
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
}
|
|
936
|
+
if (action.startsWith("delete:") && item && !isOpen(item)) picker.asking = item.file;
|
|
937
|
+
schedule();
|
|
938
|
+
};
|
|
939
|
+
const removeSaved = (item) => {
|
|
940
|
+
const shown = picker;
|
|
941
|
+
shown.saved = shown.saved.filter((other) => other !== item); // some da lista já; volta se a lixeira falhar
|
|
942
|
+
shown.hits = []; // os cliques antigos apontariam para o item seguinte até o próximo desenho
|
|
943
|
+
shown.error = "";
|
|
944
|
+
schedule();
|
|
945
|
+
trashFile(item.file, sessionsDir()).then((ok) => {
|
|
946
|
+
if (ok) return;
|
|
947
|
+
shown.saved = [item, ...shown.saved].sort((a, b) => b.mtime - a.mtime);
|
|
948
|
+
shown.error = t("Não deu para mandar a sessão para a lixeira.", "No se pudo enviar la sesión a la papelera.", "Could not move the session to the trash.");
|
|
949
|
+
cache = [];
|
|
950
|
+
schedule();
|
|
951
|
+
});
|
|
877
952
|
};
|
|
878
953
|
const submitPicker = () => {
|
|
879
954
|
// pasta arrastada para o terminal: aspas duplas (Windows), simples (Linux) ou espaços com \ (Mac)
|
|
@@ -886,12 +961,18 @@ async function main() {
|
|
|
886
961
|
folderOk = statSync(target).isDirectory();
|
|
887
962
|
} catch { /* não existe */ }
|
|
888
963
|
if (!folderOk) {
|
|
889
|
-
picker.error = `Pasta não encontrada: ${oneLine(target)}
|
|
964
|
+
picker.error = t(`Pasta não encontrada: ${oneLine(target)}`, `Carpeta no encontrada: ${oneLine(target)}`, `Folder not found: ${oneLine(target)}`);
|
|
890
965
|
return schedule();
|
|
891
966
|
}
|
|
892
967
|
return startIn(target);
|
|
893
968
|
};
|
|
894
969
|
const typeIntoPicker = (text) => {
|
|
970
|
+
if (picker.asking) {
|
|
971
|
+
const item = picker.saved.find((other) => other.file === picker.asking);
|
|
972
|
+
picker.asking = undefined;
|
|
973
|
+
if (/^[sSyY]$/.test(text) && item && !isOpen(item)) return removeSaved(item);
|
|
974
|
+
return schedule();
|
|
975
|
+
}
|
|
895
976
|
if (text === "\x1b") return closePicker();
|
|
896
977
|
const clean = text.replace(/\x1b\[20[01]~/g, "").replace(/\x1b(?:\[[0-9;?]*[A-Za-z~]|O.)/g, "");
|
|
897
978
|
picker.error = "";
|
|
@@ -147,7 +147,7 @@ export function discoverAgents(cwd: string, scope: AgentScope): AgentDiscoveryRe
|
|
|
147
147
|
// Pink: personas do Thoth (o thoth-client grava ~/.claude/agents/thoth-*.md) pelo nome curto: "tifa", "cloud"... Um
|
|
148
148
|
// agents/tifa.md vence. O model de lá (haiku, sonnet) é apelido do Claude: aqui vale o da sessão (owner 2026-11-25)
|
|
149
149
|
const home = process.env.USERPROFILE || process.env.HOME;
|
|
150
|
-
if (home && scope !== "project") for (const persona of loadAgentsFromDir(path.join(home, ".claude", "agents"), "user")) {
|
|
150
|
+
if (home && scope !== "project" && Reflect.get(globalThis, "__pinkThothConfigured")?.()) for (const persona of loadAgentsFromDir(path.join(home, ".claude", "agents"), "user")) {
|
|
151
151
|
const name = persona.name.startsWith("thoth-") ? persona.name.slice(6) : "";
|
|
152
152
|
if (name && !agentMap.has(name)) agentMap.set(name, { ...persona, name, model: undefined, description: `Persona ${name} do Thoth: ${persona.description}` });
|
|
153
153
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// a sessão (session_shutdown) os filhos são abortados e nada é entregue: o resultado nunca cai em outra conversa.
|
|
5
5
|
// Copiado para examples/extensions/subagent/background.ts pelo build (rebrand.json); o index.ts do subagente o importa.
|
|
6
6
|
|
|
7
|
-
import { choose, t } from "./pink-i18n.ts";
|
|
7
|
+
import { type Choice, choose, completeFrom, t, unknown } from "./pink-i18n.ts";
|
|
8
8
|
export const MAX_BACKGROUND = 4;
|
|
9
9
|
const OUTPUT_CAP = 50 * 1024;
|
|
10
10
|
const WIDGET = "pink-subagents";
|
|
@@ -117,26 +117,31 @@ export function createBackground(pink: any, { now = Date.now, write = muxWrite }
|
|
|
117
117
|
return targets.length;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
const none = () => t("Nenhum subagente em segundo plano. Peça ao agente para rodar um subagente em segundo plano.", "No hay subagentes en segundo plano. Pide al agente que ejecute un subagente en segundo plano.", "No background subagents. Ask the agent to run a background subagent.");
|
|
121
|
+
const options = (): Choice[] => [
|
|
122
|
+
{ value: "listar", description: jobs.size ? t("mostra os que estão rodando", "muestra los que están corriendo", "shows the running ones") : t("nada rodando agora", "nada corriendo ahora", "nothing running now") },
|
|
123
|
+
...(jobs.size ? [{ value: "cancelar todos", description: t("cancela todos", "cancela todos", "cancels all") }] : []),
|
|
124
|
+
...[...jobs.keys()].map((id) => ({ value: `cancelar ${id}` })),
|
|
125
|
+
];
|
|
120
126
|
pink.registerCommand("subagentes", {
|
|
121
127
|
description: t("Subagentes em segundo plano: lista; 'cancelar <n>' ou 'cancelar todos'", "Subagentes en segundo plano: lista; 'cancelar <n>' o 'cancelar todos'", "Background subagents: list; 'cancel <n>' or 'cancel all'"),
|
|
122
|
-
getArgumentCompletions: (
|
|
123
|
-
["cancelar todos", ...[...jobs.keys()].map((id) => `cancelar ${id}`)].filter((item) => item.startsWith(prefix)).map((value) => ({ value, label: value })),
|
|
128
|
+
getArgumentCompletions: completeFrom(options),
|
|
124
129
|
handler: async (args: string, ctx: any) => {
|
|
125
130
|
if (!args.trim() && jobs.size) {
|
|
126
|
-
const choice = await choose(ctx, "/subagentes",
|
|
127
|
-
{ value: "listar", description: t("mostra os que estão rodando", "muestra los que están corriendo", "shows the running ones") },
|
|
128
|
-
...["cancelar todos", ...[...jobs.keys()].map((id) => `cancelar ${id}`)].map((value) => ({ value })),
|
|
129
|
-
]);
|
|
131
|
+
const choice = await choose(ctx, "/subagentes", options());
|
|
130
132
|
if (choice === undefined) return;
|
|
131
|
-
args = choice
|
|
133
|
+
args = choice;
|
|
132
134
|
}
|
|
133
135
|
const [verb, target] = args.trim().split(/\s+/);
|
|
136
|
+
if (verb && !["listar", "list", "cancelar", "cancel"].includes(verb)) return unknown(ctx, "/subagentes", args.trim(), options());
|
|
137
|
+
if ((verb === "cancelar" || verb === "cancel") && !jobs.size) return void ctx.ui.notify(none(), "warning");
|
|
134
138
|
if (verb === "cancelar" || verb === "cancel") {
|
|
135
139
|
const count = target ? cancel(target) : 0;
|
|
136
|
-
|
|
140
|
+
if (!count) return unknown(ctx, "/subagentes", args.trim(), options());
|
|
141
|
+
ctx.ui.notify(t(`Cancelando ${count} subagente(s).`, `Cancelando ${count} subagente(s).`, `Cancelling ${count} subagent(s).`), "info");
|
|
137
142
|
return;
|
|
138
143
|
}
|
|
139
|
-
ctx.ui.notify(jobs.size ? lines().slice(0, -1).join("\n") :
|
|
144
|
+
ctx.ui.notify(jobs.size ? lines().slice(0, -1).join("\n") : none(), "info");
|
|
140
145
|
},
|
|
141
146
|
});
|
|
142
147
|
|