terminal-smart-cli 0.78.0 → 0.80.0
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/bin/ts.js +19 -5
- package/lib/core.js +31 -1
- package/package.json +1 -1
package/bin/ts.js
CHANGED
|
@@ -41,14 +41,21 @@ async function askDestructive(cmd, { en = false, warning = null } = {}) {
|
|
|
41
41
|
const raw = String(cmd || '');
|
|
42
42
|
const { shown, hidden } = ui.cmdSummary(raw);
|
|
43
43
|
const more = hidden > 0 ? C.dim(` … +${hidden} ${en ? 'lines' : 'linhas'}`) : '';
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const desc = require('../lib/core').describeDestructive(raw, { en }); // o que a ação FAZ, em linguagem natural
|
|
45
|
+
let first = true;
|
|
46
46
|
for (;;) {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
if (first) {
|
|
48
|
+
// pergunta em LINGUAGEM NATURAL + o comando resumido em amarelo + opções claras
|
|
49
|
+
console.log('');
|
|
50
|
+
console.log(C.warn(' ▲ ') + C.bold(en ? `This action will ${desc}. Continue?` : `Essa ação vai ${desc}. Podemos continuar?`));
|
|
51
|
+
console.log(' ' + C.warn(shown) + more);
|
|
52
|
+
if (warning) console.log(' ' + C.dim((en ? 'note: ' : 'obs: ') + warning));
|
|
53
|
+
first = false;
|
|
54
|
+
}
|
|
55
|
+
const q = C.dim(en ? ' (S) Yes · (N) No · (A) Always · (V) View command › ' : ' (S) Sim · (N) Não · (A) Sim sempre · (V) Ver comando › ');
|
|
49
56
|
const a = String(await ui.ask(q)).trim().toLowerCase();
|
|
50
57
|
if (['v', 'ver', 'view'].includes(a)) { console.log('\n' + raw.split('\n').map(l => ' ' + C.dim(l)).join('\n') + '\n'); continue; }
|
|
51
|
-
if (['a', 'all', 'tudo'].includes(a)) return 'all';
|
|
58
|
+
if (['a', 'all', 'tudo', 'sempre', 'always'].includes(a)) return 'all';
|
|
52
59
|
return ['s', 'sim', 'y', 'yes'].includes(a);
|
|
53
60
|
}
|
|
54
61
|
}
|
|
@@ -517,6 +524,13 @@ async function chatRepl() {
|
|
|
517
524
|
const _pp = require('path'), _oo = require('os'), _ff = require('fs');
|
|
518
525
|
let agentCwd = process.cwd();
|
|
519
526
|
console.log(' ' + C.dim((cfg.lang === 'en' ? 'working folder: ' : 'pasta de trabalho: ') + agentCwd) + C.dim(cfg.lang === 'en' ? ' · cd <folder> to change' : ' · cd <pasta> pra trocar') + '\n');
|
|
527
|
+
// `ts --continuar`: avisa que a PRÓXIMA mensagem retoma a sessão anterior desta pasta
|
|
528
|
+
// (o agentCmd lê --continuar do argv e carrega o histórico). REPL interativo → não cai no shell.
|
|
529
|
+
if (process.argv.includes('--continuar') || process.argv.includes('-c')) {
|
|
530
|
+
console.log(' ' + C.cyan('↻ ') + C.dim(cfg.lang === 'en'
|
|
531
|
+
? 'continue mode — your next message resumes this folder\'s previous session.'
|
|
532
|
+
: 'modo continuar — sua próxima mensagem retoma a sessão anterior desta pasta.') + '\n');
|
|
533
|
+
}
|
|
520
534
|
|
|
521
535
|
for (;;) {
|
|
522
536
|
const raw = await ask1(prompt);
|
package/lib/core.js
CHANGED
|
@@ -39,6 +39,36 @@ function globalStateWarning(cmd) {
|
|
|
39
39
|
return null;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// Descrição em LINGUAGEM NATURAL do que um comando destrutivo faz — pra a aprovação dizer
|
|
43
|
+
// "Essa ação vai APAGAR ARQUIVOS" em vez de só despejar o comando cru. Bilíngue.
|
|
44
|
+
const _DESTR_DESC = [
|
|
45
|
+
[/\bmkfs\b|\bdd\s+if=|(?:^|[\s&;|])format\s+[a-z]:|\bdiskpart\b|>\s?\/dev\/sd/i, ['formatar ou sobrescrever um disco', 'format or overwrite a disk']],
|
|
46
|
+
[/\bDROP\s+DATABASE\b/i, ['apagar um banco de dados INTEIRO', 'delete an ENTIRE database']],
|
|
47
|
+
[/\bDROP\s+TABLE\b/i, ['apagar uma tabela do banco', 'delete a database table']],
|
|
48
|
+
[/\bTRUNCATE\b/i, ['esvaziar uma tabela do banco', 'empty a database table']],
|
|
49
|
+
[/\bDELETE\s+FROM\b/i, ['apagar registros de uma tabela', 'delete rows from a table']],
|
|
50
|
+
[/\bALTER\s+USER\b[^;]*IDENTIFIED|(\bSET\s+PASSWORD|GRANT\s+ALL\s+PRIVILEGES)\b/i, ['mudar credenciais/permissões do banco (afeta tudo que usa esse acesso)', "change DB credentials/permissions (affects everything using that access)"]],
|
|
51
|
+
[/\bDROP\s+USER\b/i, ['remover um usuário do banco', 'remove a database user']],
|
|
52
|
+
[/\/etc\/ssh\/sshd_config/i, ['editar a config do SSH (pode te trancar pra fora)', 'edit the SSH config (may lock you out)']],
|
|
53
|
+
[/\b(ufw|iptables)\b/i, ['mexer no firewall (pode cortar seu acesso)', 'change the firewall (may cut your access)']],
|
|
54
|
+
[/\b(shutdown|reboot|halt|poweroff)\b/i, ['desligar ou reiniciar a máquina', 'shut down or reboot the machine']],
|
|
55
|
+
[/\b(pkill|killall)\b|taskkill\b[^\n]*\/im|Stop-Process\b[^|;&]*-Name/i, ['encerrar processos pelo NOME (todos com esse nome)', 'kill processes by NAME (all of them)']],
|
|
56
|
+
[/\b(kill|taskkill)\b/i, ['encerrar um processo', 'kill a process']],
|
|
57
|
+
[/\bsystemctl\s+(stop|disable|mask)\b/i, ['parar ou desabilitar um serviço do sistema', 'stop or disable a system service']],
|
|
58
|
+
[/\bdocker\s+(rm|rmi|system\s+prune|volume\s+rm)\b/i, ['remover containers, imagens ou volumes do Docker', 'remove Docker containers, images or volumes']],
|
|
59
|
+
[/\bgit\s+push\s+.*--force(?!-with-lease)/i, ['sobrescrever o histórico remoto do git', 'overwrite remote git history']],
|
|
60
|
+
[/\bgit\s+reset\s+--hard/i, ['descartar mudanças locais do git', 'discard local git changes']],
|
|
61
|
+
[/\bchmod\s+(-R\s+)?777\b/i, ['dar permissão TOTAL a arquivos (inseguro)', 'grant FULL permissions to files (insecure)']],
|
|
62
|
+
[/\b(curl|wget)\b[^|]*\|\s*(sudo\s+)?(ba)?sh/i, ['baixar e EXECUTAR um script da internet', 'download and RUN a script from the internet']],
|
|
63
|
+
[/\brm\s+(-[a-z]*[rf]|.*\*)|\brmdir\b|\bdel\s+\/[sq]|\brd\s+\/s|Remove-Item[^\n]*-Recurse/i, ['apagar arquivos ou pastas', 'delete files or folders']],
|
|
64
|
+
[/\buserdel\b|\bpasswd\b|\/etc\/sudoers|\bvisudo\b|\busermod\b/i, ['mexer em usuários/permissões do sistema', 'change system users/permissions']],
|
|
65
|
+
];
|
|
66
|
+
function describeDestructive(cmd, opts = {}) {
|
|
67
|
+
const en = !!opts.en, s = String(cmd || '');
|
|
68
|
+
for (const [re, [pt, eng]] of _DESTR_DESC) if (re.test(s)) return en ? eng : pt;
|
|
69
|
+
return en ? 'make a change that is hard to undo' : 'fazer uma alteração difícil de desfazer';
|
|
70
|
+
}
|
|
71
|
+
|
|
42
72
|
// Padrões de comando destrutivo/irreversível — SEMPRE pedem aprovação humana.
|
|
43
73
|
// (fonte única: antes vivia em tools.js; App e Web tinham cópias divergentes.)
|
|
44
74
|
const DESTRUCTIVE = [
|
|
@@ -166,7 +196,7 @@ function classifyToolResult(raw) {
|
|
|
166
196
|
|
|
167
197
|
module.exports = {
|
|
168
198
|
DESTRUCTIVE, isDestructive, touchesTsConfig,
|
|
169
|
-
GLOBAL_STATE, globalStateWarning,
|
|
199
|
+
GLOBAL_STATE, globalStateWarning, describeDestructive,
|
|
170
200
|
MODEL_WINDOWS, CTX_WINDOW_DEFAULT, DEFAULT_EXECUTOR, COMPACT_AT, KEEP_TAIL, winFor, estMsgsTok,
|
|
171
201
|
AgentEvents, EVENT_TYPES,
|
|
172
202
|
ERROR_CLASSES, RETRYABLE_CLASSES, classifyError, classifyToolResult,
|