krnell 0.0.0-stage → 3.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.
Files changed (51) hide show
  1. package/Iniciar_Linux.sh +129 -0
  2. package/Instalar_Atalho_Windows.cmd +40 -0
  3. package/Instalar_Ubuntu.sh +95 -0
  4. package/Painel.cmd +138 -0
  5. package/README.md +82 -2
  6. package/atualizador.py +148 -0
  7. package/bin/krnell.mjs +159 -0
  8. package/bridge.py +5280 -0
  9. package/config.example.json +57 -0
  10. package/contexto.py +204 -0
  11. package/dashboard_web.py +308 -0
  12. package/dns_duck.py +227 -0
  13. package/ferramentas/Liberar_Firewall.ps1 +96 -0
  14. package/ferramentas/firewall_linux.sh +67 -0
  15. package/ferramentas/install_windows.py +482 -0
  16. package/ferramentas/selecionar_provedor.py +76 -0
  17. package/iniciar.sh +255 -0
  18. package/keys.example.env +3 -0
  19. package/kimi.py +567 -0
  20. package/opencode_sync.py +265 -0
  21. package/package.json +68 -4
  22. package/painel.py +5612 -0
  23. package/painel_web.py +367 -0
  24. package/plugins/system-prompt/index.ts +409 -0
  25. package/provedores/kimi/bridge.mjs +4349 -0
  26. package/provedores/kimi/package.json +10 -0
  27. package/provedores_catalogo.py +27 -0
  28. package/tls_proxy.py +205 -0
  29. package/tui_core.py +604 -0
  30. package/web/dist/.vite/manifest.json +84 -0
  31. package/web/dist/assets/LogsPage-DkXN-I7o.js +2 -0
  32. package/web/dist/assets/LogsPage-OsSvuqxQ.js +2 -0
  33. package/web/dist/assets/TerminalPage-CZTPxVyx.js +1 -0
  34. package/web/dist/assets/TerminalPage-D208X99P.js +1 -0
  35. package/web/dist/assets/TerminalPage-DYGPu4ux.css +1 -0
  36. package/web/dist/assets/index-B5rIwous.js +1 -0
  37. package/web/dist/assets/index-CJE_a_Tn.js +27 -0
  38. package/web/dist/assets/index-COlDAcsY.js +1 -0
  39. package/web/dist/assets/index-Dzc8Obwp.css +1 -0
  40. package/web/dist/assets/index-LZadV7rx.js +27 -0
  41. package/web/dist/assets/index-o8xT03ZV.css +1 -0
  42. package/web/dist/assets/press-start-2p-2BZhbCiP.ttf +0 -0
  43. package/web/dist/assets/react-vendor-C475ILlI.js +49 -0
  44. package/web/dist/assets/terminal-vendor-DOrYoP_4.css +32 -0
  45. package/web/dist/assets/terminal-vendor-Dp03d74L.js +38 -0
  46. package/web/dist/assets/terminal-webgl-BRBWwLY7.js +75 -0
  47. package/web/dist/favicon.svg +1 -0
  48. package/web/dist/fonts/OFL.txt +93 -0
  49. package/web/dist/fonts/press-start-2p.ttf +0 -0
  50. package/web/dist/index.html +18 -0
  51. package/workbuddy.py +1965 -0
package/bin/krnell.mjs ADDED
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Krnell CLI — comando global `krnell` (Termux, Linux, Ubuntu, macOS e Windows).
4
+ *
5
+ * Uso:
6
+ * krnell abre a TUI estilo OpenCode
7
+ * krnell --headless sobe apenas o bridge HTTP (sem TUI)
8
+ * krnell --opencode instala plugin system-prompt + modelos no OpenCode
9
+ * krnell --instalar instala/verifica dependencias locais (Python/rich/Playwright)
10
+ * krnell --once mostra retrato rapido de status e sai
11
+ * krnell --repl modo texto simples
12
+ * krnell upgrade atualiza o pacote via npm (`npm i -g krnell@latest`)
13
+ * krnell --version exibe versao do Krnell
14
+ */
15
+ import { spawnSync } from 'node:child_process';
16
+ import fs from 'node:fs';
17
+ import path from 'node:path';
18
+ import { fileURLToPath } from 'node:url';
19
+
20
+ const __filename = fileURLToPath(import.meta.url);
21
+ const __dirname = path.dirname(__filename);
22
+ let ROOT = path.resolve(__dirname, '..');
23
+ const args = process.argv.slice(2);
24
+
25
+ // Instalação global: nunca grava contas/chaves dentro de node_modules. Copia o
26
+ // programa para uma pasta persistente do usuário e preserva config.json/keys.env
27
+ // e logins entre upgrades do pacote npm.
28
+ function prepararPastaUsuario() {
29
+ if (!ROOT.includes(`${path.sep}node_modules${path.sep}`)) return;
30
+ const destino = process.env.KRNELL_HOME || process.env.NYXO_HOME || (process.platform === 'win32'
31
+ ? path.join(process.env.LOCALAPPDATA || path.join(process.env.USERPROFILE || '', 'AppData', 'Local'), 'Krnell')
32
+ : path.join(process.env.XDG_DATA_HOME || path.join(process.env.HOME || '', '.local', 'share'), 'krnell'));
33
+ // Migra dados existentes de uma instalação antiga (`nyxo`) sem perder contas/chaves
34
+ const legado = process.platform === 'win32'
35
+ ? path.join(process.env.LOCALAPPDATA || path.join(process.env.USERPROFILE || '', 'AppData', 'Local'), 'Nyxo')
36
+ : path.join(process.env.XDG_DATA_HOME || path.join(process.env.HOME || '', '.local', 'share'), 'nyxo');
37
+ fs.mkdirSync(destino, { recursive: true });
38
+ const preservar = new Set([
39
+ 'config.json', 'keys.env', 'workbuddy_contas.json', 'workbuddy_limites.json',
40
+ 'workbuddy_sem_creditos.json', 'antigravity.json', 'antigravity-usage.json',
41
+ ]);
42
+ const migrarRelativos = [
43
+ ...preservar,
44
+ path.join('provedores', 'kimi', 'antigravity.json'),
45
+ path.join('provedores', 'kimi', 'antigravity-usage.json'),
46
+ ];
47
+ if (fs.existsSync(legado) && legado !== destino) {
48
+ for (const rel of migrarRelativos) {
49
+ const src = path.join(legado, rel);
50
+ const dst = path.join(destino, rel);
51
+ if (fs.existsSync(src) && !fs.existsSync(dst)) {
52
+ try {
53
+ fs.mkdirSync(path.dirname(dst), { recursive: true });
54
+ fs.copyFileSync(src, dst);
55
+ } catch {}
56
+ }
57
+ }
58
+ }
59
+ fs.cpSync(ROOT, destino, {
60
+ recursive: true,
61
+ filter: (src, dst) => {
62
+ const rel = path.relative(ROOT, src);
63
+ if (!rel) return true;
64
+ const partes = rel.split(path.sep);
65
+ if (partes.includes('node_modules') || partes.includes('.git') || partes.includes('logs') || partes.includes('__pycache__')) return false;
66
+ if (partes[0] === 'provedores' && partes[1] === 'kimi' && partes[2] === 'profile') return false;
67
+ // Credenciais e configurações existentes nunca são sobrescritas.
68
+ if (preservar.has(partes[partes.length - 1]) && fs.existsSync(dst)) return false;
69
+ return true;
70
+ },
71
+ });
72
+ ROOT = destino;
73
+ }
74
+
75
+ prepararPastaUsuario();
76
+
77
+ function lerVersao() {
78
+ try {
79
+ const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
80
+ return pkg.version || '3.0.2';
81
+ } catch {
82
+ return '3.0.2';
83
+ }
84
+ }
85
+
86
+ if (args.includes('-v') || args.includes('--version')) {
87
+ console.log(`krnell v${lerVersao()}`);
88
+ process.exit(0);
89
+ }
90
+
91
+ if (args.includes('-h') || args.includes('--help')) {
92
+ console.log(`◈ krnell v${lerVersao()} — Bridge Multi-Provedor + TUI estilo OpenCode
93
+
94
+ Uso:
95
+ krnell abre a TUI interativa (auto-verifica dependencias)
96
+ krnell --headless roda apenas o servidor HTTP (porta 8765)
97
+ krnell --opencode sincroniza modelos + plugin system-prompt no OpenCode
98
+ krnell --instalar instala Python/rich/motor NVIDIA/Antigravity
99
+ krnell --once imprime status atual e encerra
100
+ krnell --repl modo linha a linha
101
+ krnell upgrade atualiza via npm (npm i -g krnell@latest)
102
+ krnell --version mostra a versao
103
+ `);
104
+ process.exit(0);
105
+ }
106
+
107
+ if (args[0] === 'upgrade' || args[0] === 'update') {
108
+ const pkgName = (() => {
109
+ try {
110
+ return JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')).name || 'krnell';
111
+ } catch {
112
+ return 'krnell';
113
+ }
114
+ })();
115
+ console.log(`◈ krnell: atualizando ${pkgName}@latest via npm...`);
116
+ const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
117
+ const r = spawnSync(npmCmd, ['install', '-g', `${pkgName}@latest`], { stdio: 'inherit' });
118
+ process.exit(r.status ?? 1);
119
+ }
120
+
121
+ if (process.platform === 'win32') {
122
+ // No Windows delega para o Painel.cmd ou python direto conforme a flag
123
+ const first = args[0] || '';
124
+ if (!first || first === '--tui') {
125
+ const r = spawnSync('cmd.exe', ['/c', path.join(ROOT, 'Painel.cmd')], {
126
+ cwd: ROOT,
127
+ stdio: 'inherit',
128
+ });
129
+ process.exit(r.status ?? 0);
130
+ }
131
+ const py = ['python', 'python3', 'py'].find((cmd) => {
132
+ const chk = spawnSync(cmd, ['-c', 'import sys; sys.exit(0 if sys.version_info >= (3,10) else 1)'], { stdio: 'ignore' });
133
+ return chk.status === 0;
134
+ });
135
+ if (!py) {
136
+ console.error('ERRO: Python 3.10+ nao encontrado no PATH.');
137
+ process.exit(1);
138
+ }
139
+ if (first === '--headless' || first === '--server') {
140
+ const r = spawnSync(py, ['-B', path.join(ROOT, 'bridge.py'), '--config', path.join(ROOT, 'config.json')], {
141
+ cwd: ROOT,
142
+ stdio: 'inherit',
143
+ });
144
+ process.exit(r.status ?? 0);
145
+ }
146
+ if (first === '--opencode' || first === '--sync') {
147
+ const code = `import opencode_sync, pathlib, json; p=pathlib.Path(${JSON.stringify(ROOT)}); cfg=json.loads((p/'config.json').read_text(encoding='utf-8-sig')) if (p/'config.json').exists() else {}; res=opencode_sync.configurar_opencode(p, porta=int(cfg.get('port') or 8765)); print('OpenCode sincronizado:', res['config'], '->', res['base_url'])`;
148
+ const r = spawnSync(py, ['-B', '-c', code], { cwd: ROOT, stdio: 'inherit' });
149
+ process.exit(r.status ?? 0);
150
+ }
151
+ const r = spawnSync(py, ['-B', path.join(ROOT, 'painel.py'), ...args], { cwd: ROOT, stdio: 'inherit' });
152
+ process.exit(r.status ?? 0);
153
+ } else {
154
+ const r = spawnSync('bash', [path.join(ROOT, 'iniciar.sh'), ...args], {
155
+ cwd: ROOT,
156
+ stdio: 'inherit',
157
+ });
158
+ process.exit(r.status ?? 0);
159
+ }