krnell 0.0.0-stage → 3.0.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.
Files changed (50) 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 +70 -2
  6. package/bin/nyxo.mjs +138 -0
  7. package/bridge.py +5196 -0
  8. package/config.example.json +57 -0
  9. package/contexto.py +184 -0
  10. package/dashboard_web.py +308 -0
  11. package/dns_duck.py +227 -0
  12. package/ferramentas/Liberar_Firewall.ps1 +96 -0
  13. package/ferramentas/firewall_linux.sh +67 -0
  14. package/ferramentas/install_windows.py +482 -0
  15. package/ferramentas/selecionar_provedor.py +70 -0
  16. package/iniciar.sh +255 -0
  17. package/keys.example.env +3 -0
  18. package/kimi.py +482 -0
  19. package/opencode_sync.py +239 -0
  20. package/package.json +69 -4
  21. package/painel.py +5227 -0
  22. package/painel_web.py +367 -0
  23. package/plugins/system-prompt/index.ts +409 -0
  24. package/provedores/kimi/bridge.mjs +4280 -0
  25. package/provedores/kimi/package.json +10 -0
  26. package/provedores_catalogo.py +155 -0
  27. package/tls_proxy.py +205 -0
  28. package/tui_core.py +600 -0
  29. package/web/dist/.vite/manifest.json +84 -0
  30. package/web/dist/assets/LogsPage-DkXN-I7o.js +2 -0
  31. package/web/dist/assets/LogsPage-OsSvuqxQ.js +2 -0
  32. package/web/dist/assets/TerminalPage-CZTPxVyx.js +1 -0
  33. package/web/dist/assets/TerminalPage-D208X99P.js +1 -0
  34. package/web/dist/assets/TerminalPage-DYGPu4ux.css +1 -0
  35. package/web/dist/assets/index-B5rIwous.js +1 -0
  36. package/web/dist/assets/index-CJE_a_Tn.js +27 -0
  37. package/web/dist/assets/index-COlDAcsY.js +1 -0
  38. package/web/dist/assets/index-Dzc8Obwp.css +1 -0
  39. package/web/dist/assets/index-LZadV7rx.js +27 -0
  40. package/web/dist/assets/index-o8xT03ZV.css +1 -0
  41. package/web/dist/assets/press-start-2p-2BZhbCiP.ttf +0 -0
  42. package/web/dist/assets/react-vendor-C475ILlI.js +49 -0
  43. package/web/dist/assets/terminal-vendor-DOrYoP_4.css +32 -0
  44. package/web/dist/assets/terminal-vendor-Dp03d74L.js +38 -0
  45. package/web/dist/assets/terminal-webgl-BRBWwLY7.js +75 -0
  46. package/web/dist/favicon.svg +1 -0
  47. package/web/dist/fonts/OFL.txt +93 -0
  48. package/web/dist/fonts/press-start-2p.ttf +0 -0
  49. package/web/dist/index.html +18 -0
  50. package/workbuddy.py +1965 -0
@@ -0,0 +1,239 @@
1
+ """Integração do Nyxo Bridge com o OpenCode (modelos + plugin system-prompt)."""
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ import os
6
+ import re
7
+ import shutil
8
+ from pathlib import Path
9
+
10
+
11
+ def candidatos_config_opencode() -> list[Path]:
12
+ home = Path.home()
13
+ lista = [
14
+ home / '.config' / 'opencode' / 'opencode.jsonc',
15
+ home / '.config' / 'opencode' / 'opencode.json',
16
+ ]
17
+ if os.name == 'nt':
18
+ appdata = os.environ.get('APPDATA') or str(home / 'AppData' / 'Roaming')
19
+ lista.append(Path(appdata) / 'opencode' / 'opencode.jsonc')
20
+ return lista
21
+
22
+
23
+ def _bloco_modelos_nyxo(indent: str = ' ') -> str:
24
+ modelos = [
25
+ ('kimi-k3.1-pro', 'Kimi K3.1 Pro (NVIDIA)', 400000, 65536, ['text'], ['low', 'medium', 'high', 'max'], 'max'),
26
+ ('minimax-m3.1-flash', 'MiniMax M3.1 Flash (NVIDIA)', 400000, 65536, ['text'], ['low', 'medium', 'high', 'max'], 'max'),
27
+ ('claude-opus-5-5', 'Claude Opus 5.5 (Antigravity)', 200000, 32768, ['text', 'image'], ['low', 'medium', 'high'], 'high'),
28
+ ('claude-sonnet-5-5', 'Claude Sonnet 5.5 (Antigravity)', 200000, 32768, ['text', 'image'], ['low', 'medium', 'high'], 'high'),
29
+ ('gemini-4-hydrogen', 'Gemini 4 Hydrogen (Antigravity)', 1000000, 65536, ['text', 'image'], ['low', 'medium', 'high', 'xhigh'], 'xhigh'),
30
+ ('gemini-4-neon', 'Gemini 4 Neon (Antigravity)', 1000000, 65536, ['text', 'image'], ['low', 'medium', 'high', 'xhigh'], 'xhigh'),
31
+ ('nyxo', 'Nyxo Ativo (roteamento dinâmico)', 300000, 64000, ['text', 'image'], ['low', 'medium', 'high', 'max'], 'max'),
32
+ ]
33
+ partes = []
34
+ for mid, nome, ctx, out, inp, efforts, default_eff in modelos:
35
+ variants = ', '.join(
36
+ f'{{ "id": "{e}", "body": {{ "reasoning_effort": "{e}" }} }}'
37
+ for e in efforts
38
+ )
39
+ partes.append(
40
+ f'{indent}"{mid}": {{\n'
41
+ f'{indent} "name": "{nome}",\n'
42
+ f'{indent} "capabilities": {{\n'
43
+ f'{indent} "tools": true,\n'
44
+ f'{indent} "reasoning": {{ "supported": true, "effort": {json.dumps(efforts)} }},\n'
45
+ f'{indent} "input": {json.dumps(inp)},\n'
46
+ f'{indent} "output": ["text"]\n'
47
+ f'{indent} }},\n'
48
+ f'{indent} "limit": {{ "context": {ctx}, "output": {out} }},\n'
49
+ f'{indent} "compatibility": {{\n'
50
+ f'{indent} "reasoningField": "reasoning_content",\n'
51
+ f'{indent} "maxTokensField": "max_tokens"\n'
52
+ f'{indent} }},\n'
53
+ f'{indent} "body": {{ "reasoning_effort": "{default_eff}" }},\n'
54
+ f'{indent} "variants": [{variants}]\n'
55
+ f'{indent}}}'
56
+ )
57
+ return ',\n'.join(partes)
58
+
59
+
60
+ def _garantir_plugin_no_texto(texto: str, plugin_dir: str) -> tuple[str, bool]:
61
+ lit = json.dumps(plugin_dir)
62
+ if lit in texto or 'plugins/system-prompt' in texto or 'plugins\\\\system-prompt' in texto:
63
+ return texto, False
64
+ m = re.search(r'"plugins"\s*:\s*\[', texto)
65
+ if m:
66
+ pos = m.end()
67
+ vazio = texto[pos:].lstrip().startswith(']')
68
+ ins = lit if vazio else f'{lit}, '
69
+ return texto[:pos] + ins + texto[pos:], True
70
+ m2 = re.search(r'"\$schema"\s*:\s*"[^"]*"\s*,?[ \t]*\r?\n?', texto)
71
+ if m2:
72
+ fim = m2.end()
73
+ antes = texto[:fim]
74
+ if not antes.rstrip().endswith(','):
75
+ antes = antes.rstrip() + ',\n'
76
+ return antes + f' "plugins": [{lit}],\n' + texto[fim:], True
77
+ abre = texto.find('{')
78
+ if abre >= 0:
79
+ return texto[:abre + 1] + f'\n "plugins": [{lit}],' + texto[abre + 1:], True
80
+ return texto, False
81
+
82
+
83
+ def _substituir_ou_inserir_provedor(texto: str, provider_id: str, bloco: str) -> tuple[str, bool]:
84
+ chave = f'"{provider_id}"'
85
+ if chave in texto:
86
+ # Localiza o objeto do provider respeitando chaves balanceadas
87
+ idx = texto.find(chave)
88
+ brace = texto.find('{', idx)
89
+ if brace >= 0:
90
+ prof = 0
91
+ in_str = False
92
+ esc = False
93
+ fim = -1
94
+ for i in range(brace, len(texto)):
95
+ ch = texto[i]
96
+ if in_str:
97
+ if esc:
98
+ esc = False
99
+ elif ch == '\\':
100
+ esc = True
101
+ elif ch == '"':
102
+ in_str = False
103
+ else:
104
+ if ch == '"':
105
+ in_str = True
106
+ elif ch == '{':
107
+ prof += 1
108
+ elif ch == '}':
109
+ prof -= 1
110
+ if prof == 0:
111
+ fim = i + 1
112
+ break
113
+ if fim > brace:
114
+ # Mantém linha inicial limpa
115
+ lin_ini = texto.rfind('\n', 0, idx)
116
+ inicio = lin_ini + 1 if lin_ini >= 0 else idx
117
+ novo = texto[:inicio] + bloco + texto[fim:]
118
+ return novo, novo != texto
119
+ m = re.search(r'"providers"\s*:\s*\{', texto)
120
+ if m:
121
+ pos = m.end()
122
+ vazio = texto[pos:].lstrip().startswith('}')
123
+ sep = '\n' if vazio else ',\n'
124
+ return texto[:pos] + '\n' + bloco + sep + texto[pos:], True
125
+ abre = texto.find('{')
126
+ if abre >= 0:
127
+ return texto[:abre + 1] + f'\n "providers": {{\n{bloco}\n }},' + texto[abre + 1:], True
128
+ return texto, False
129
+
130
+
131
+ def opencode_detectado() -> bool:
132
+ """Detecta se o OpenCode está instalado (binário ou pasta de config)."""
133
+ if shutil.which('opencode'):
134
+ return True
135
+ home = Path.home()
136
+ for p in (
137
+ home / '.opencode' / 'bin' / 'opencode',
138
+ home / '.opencode' / 'bin' / 'opencode.exe',
139
+ home / '.config' / 'opencode',
140
+ ):
141
+ if p.exists():
142
+ return True
143
+ if os.name == 'nt':
144
+ appdata = os.environ.get('APPDATA') or str(home / 'AppData' / 'Roaming')
145
+ if (Path(appdata) / 'opencode').exists():
146
+ return True
147
+ return False
148
+
149
+
150
+ def opencode_ja_configurado(porta: int = 8765) -> bool:
151
+ """True se opencode.json(c) já tem o provedor `nyxo` apontando para a porta."""
152
+ esperado = f'http://127.0.0.1:{int(porta)}/v1'
153
+ for arq in candidatos_config_opencode():
154
+ if not arq.is_file():
155
+ continue
156
+ try:
157
+ txt = arq.read_text(encoding='utf-8')
158
+ except OSError:
159
+ continue
160
+ if '"nyxo"' in txt and esperado in txt:
161
+ return True
162
+ return False
163
+
164
+
165
+ def configurar_opencode(raiz: Path, porta: int = 8765, api_key: str = '') -> dict:
166
+ """Instala o plugin system-prompt e registra o provedor `nyxo` no OpenCode."""
167
+ raiz = Path(raiz).resolve()
168
+ cands = candidatos_config_opencode()
169
+ arq = next((p for p in cands if p.exists()), cands[0])
170
+ cfg_dir = arq.parent
171
+ cfg_dir.mkdir(parents=True, exist_ok=True)
172
+
173
+ # 1) Plugin system-prompt
174
+ src_plugin = raiz / 'plugins' / 'system-prompt' / 'index.ts'
175
+ dst_plugin_dir = cfg_dir / 'plugins' / 'system-prompt'
176
+ dst_plugin = dst_plugin_dir / 'index.ts'
177
+ plugin_instalado = False
178
+ if src_plugin.exists():
179
+ dst_plugin_dir.mkdir(parents=True, exist_ok=True)
180
+ shutil.copy2(src_plugin, dst_plugin)
181
+ plugin_instalado = True
182
+
183
+ # 2) AGENTS.md se existir na raiz do nyxo e ainda nao existir no OpenCode
184
+ src_agents = raiz / 'AGENTS.md'
185
+ dst_agents = cfg_dir / 'AGENTS.md'
186
+ if src_agents.exists() and not dst_agents.exists():
187
+ shutil.copy2(src_agents, dst_agents)
188
+
189
+ base_url = f'http://127.0.0.1:{int(porta)}/v1'
190
+ key_val = (api_key or 'local').strip()
191
+ bloco_nyxo = (
192
+ f' "nyxo": {{\n'
193
+ f' "name": "Nyxo Bridge (local)",\n'
194
+ f' "package": "@opencode/ai/providers/openai-compatible",\n'
195
+ f' "settings": {{\n'
196
+ f' "baseURL": "{base_url}",\n'
197
+ f' "apiKey": "{key_val}"\n'
198
+ f' }},\n'
199
+ f' "models": {{\n'
200
+ f'{_bloco_modelos_nyxo(" ")}\n'
201
+ f' }}\n'
202
+ f' }}'
203
+ )
204
+
205
+ if not arq.exists():
206
+ plugins_str = f'\n "plugins": [{json.dumps(str(dst_plugin_dir))}],' if plugin_instalado else ''
207
+ conteudo = (
208
+ '{\n'
209
+ ' "$schema": "https://opencode.ai/config.json",'
210
+ f'{plugins_str}\n'
211
+ ' "providers": {\n'
212
+ f'{bloco_nyxo}\n'
213
+ ' }\n'
214
+ '}\n'
215
+ )
216
+ arq.write_text(conteudo, encoding='utf-8')
217
+ else:
218
+ texto = arq.read_text(encoding='utf-8')
219
+ if plugin_instalado or dst_plugin.exists():
220
+ texto, _ = _garantir_plugin_no_texto(texto, str(dst_plugin_dir))
221
+ texto, _ = _substituir_ou_inserir_provedor(texto, 'nyxo', bloco_nyxo)
222
+ # Atualiza tambem o baseURL do kimibridge se existir, apontando pro nyxo
223
+ if '"kimibridge"' in texto:
224
+ texto = re.sub(
225
+ r'("kimibridge"[\s\S]{0,600}?"baseURL"\s*:\s*")[^"]*(")',
226
+ rf'\g<1>{base_url}\2',
227
+ texto,
228
+ count=1,
229
+ )
230
+ arq.write_text(texto, encoding='utf-8')
231
+
232
+ return {
233
+ 'ok': True,
234
+ 'config': str(arq),
235
+ 'plugin': str(dst_plugin) if (plugin_instalado or dst_plugin.exists()) else '',
236
+ 'plugin_instalado': bool(plugin_instalado or dst_plugin.exists()),
237
+ 'baseURL': base_url,
238
+ 'base_url': base_url,
239
+ }
package/package.json CHANGED
@@ -1,6 +1,71 @@
1
1
  {
2
2
  "name": "krnell",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "3.0.0",
4
+ "description": "Krnell — proxy multi-provedor local (NVIDIA Playground, Antigravity OAuth, WorkBuddy, OpenCode, 20+ APIs) com TUI estilo OpenCode",
5
+ "type": "module",
6
+ "bin": {
7
+ "krnell": "bin/nyxo.mjs",
8
+ "nyxo": "bin/nyxo.mjs"
9
+ },
10
+ "files": [
11
+ "bin/",
12
+ "bridge.py",
13
+ "painel.py",
14
+ "painel_web.py",
15
+ "tui_core.py",
16
+ "opencode_sync.py",
17
+ "provedores_catalogo.py",
18
+ "kimi.py",
19
+ "workbuddy.py",
20
+ "contexto.py",
21
+ "dashboard_web.py",
22
+ "tls_proxy.py",
23
+ "dns_duck.py",
24
+ "iniciar.sh",
25
+ "Painel.cmd",
26
+ "Instalar_Atalho_Windows.cmd",
27
+ "Iniciar_Linux.sh",
28
+ "Instalar_Ubuntu.sh",
29
+ "config.example.json",
30
+ "keys.example.env",
31
+ "plugins/",
32
+ "provedores/kimi/bridge.mjs",
33
+ "provedores/kimi/package.json",
34
+ "web/dist/",
35
+ "ferramentas/install_windows.py",
36
+ "ferramentas/selecionar_provedor.py",
37
+ "ferramentas/Liberar_Firewall.ps1",
38
+ "ferramentas/firewall_linux.sh",
39
+ "README.md",
40
+ "README-NPM.md"
41
+ ],
42
+ "engines": {
43
+ "node": ">=18.0.0"
44
+ },
45
+ "scripts": {
46
+ "start": "node bin/nyxo.mjs",
47
+ "build": "vite build --config vite.config.mjs",
48
+ "dev": "vite --config vite.config.mjs --host 127.0.0.1",
49
+ "lab": "node ferramentas/lab-dashboard.mjs",
50
+ "terminal": "node ferramentas/terminal-server.mjs",
51
+ "test:node": "node --test ferramentas/test-*.mjs",
52
+ "qa": "python -B ferramentas/qa_dashboard.py"
53
+ },
54
+ "dependencies": {},
55
+ "devDependencies": {
56
+ "vite": "7.1.7"
57
+ },
58
+ "keywords": [
59
+ "opencode",
60
+ "bridge",
61
+ "ai",
62
+ "nvidia",
63
+ "antigravity",
64
+ "claude",
65
+ "gemini",
66
+ "termux",
67
+ "tui",
68
+ "openai-compatible"
69
+ ],
70
+ "license": "MIT"
71
+ }