krnell 3.0.5 → 3.0.7
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/atualizador.py +11 -2
- package/bin/krnell.mjs +63 -15
- package/bridge.py +133 -21
- package/dashboard_web.py +1 -1
- package/iniciar.sh +1 -1
- package/opencode_sync.py +157 -27
- package/package.json +1 -1
- package/painel.py +387 -74
- package/plugins/system-prompt/index.ts +713 -11
- package/plugins/system-prompt/package.json +10 -0
- package/plugins/system-prompt/tui.tsx +641 -0
- package/provedores/kimi/bridge.mjs +73 -104
- package/tui_core.py +15 -6
package/opencode_sync.py
CHANGED
|
@@ -65,16 +65,7 @@ def candidatos_config_opencode() -> list[Path]:
|
|
|
65
65
|
return lista
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
def
|
|
69
|
-
modelos = [
|
|
70
|
-
('kimi-k3.1-pro', 'Kimi K3.1 Pro (NVIDIA)', 400000, 65536, ['text', 'image'], ['low', 'medium', 'high', 'max'], 'max'),
|
|
71
|
-
('minimax-m3.1-flash', 'MiniMax M3.1 Flash (NVIDIA)', 400000, 65536, ['text', 'image'], ['low', 'medium', 'high', 'max'], 'max'),
|
|
72
|
-
('claude-opus-5-5', 'Claude Opus 5.5 (Antigravity)', 1000000, 128000, ['text', 'image'], ['low', 'medium', 'high'], 'high'),
|
|
73
|
-
('claude-sonnet-5-5', 'Claude Sonnet 5.5 (Antigravity)', 1000000, 128000, ['text', 'image'], ['low', 'medium', 'high'], 'high'),
|
|
74
|
-
('gemini-4-hydrogen', 'Gemini 4 Hydrogen (Antigravity)', 1000000, 262144, ['text', 'image', 'audio', 'video', 'pdf'], ['low', 'medium', 'high', 'xhigh'], 'xhigh'),
|
|
75
|
-
('gemini-4-neon', 'Gemini 4 Neon (Antigravity)', 1000000, 262144, ['text', 'image', 'audio', 'video', 'pdf'], ['low', 'medium', 'high', 'xhigh'], 'xhigh'),
|
|
76
|
-
('krnell', 'Krnell Active (dynamic route)', 1000000, 65536, ['text', 'image'], ['low', 'medium', 'high', 'xhigh', 'max'], 'max'),
|
|
77
|
-
]
|
|
68
|
+
def _bloco_modelos_lista(modelos: list[tuple], indent: str = ' ') -> str:
|
|
78
69
|
partes = []
|
|
79
70
|
for mid, nome, ctx, out, inp, efforts, default_eff in modelos:
|
|
80
71
|
variants = ', '.join(
|
|
@@ -102,6 +93,45 @@ def _bloco_modelos_krnell(indent: str = ' ') -> str:
|
|
|
102
93
|
return ',\n'.join(partes)
|
|
103
94
|
|
|
104
95
|
|
|
96
|
+
def _bloco_modelos_krnell(indent: str = ' ') -> str:
|
|
97
|
+
# Apenas os modelos gratuitos do NVIDIA Playground (sem login/API key).
|
|
98
|
+
# O nome do provedor ("NVIDIA Free") já aparece ao lado no /model.
|
|
99
|
+
modelos = [
|
|
100
|
+
('kimi-k3.1-pro', 'Kimi K3.1 Pro', 400000, 65536, ['text', 'image'], ['low', 'medium', 'high', 'max'], 'max'),
|
|
101
|
+
('minimax-m3.1-flash', 'MiniMax M3.1 Flash', 400000, 65536, ['text', 'image'], ['low', 'medium', 'high', 'max'], 'max'),
|
|
102
|
+
]
|
|
103
|
+
return _bloco_modelos_lista(modelos, indent)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _bloco_modelos_antigravity(indent: str = ' ') -> str:
|
|
107
|
+
modelos = [
|
|
108
|
+
('claude-opus-5-5', 'Claude Opus 5.5', 1000000, 128000, ['text', 'image'], ['low', 'medium', 'high'], 'high'),
|
|
109
|
+
('claude-sonnet-5-5', 'Claude Sonnet 5.5', 1000000, 128000, ['text', 'image'], ['low', 'medium', 'high'], 'high'),
|
|
110
|
+
('gemini-4-hydrogen', 'Gemini 4 Hydrogen', 1000000, 262144, ['text', 'image', 'audio', 'video', 'pdf'], ['low', 'medium', 'high', 'xhigh'], 'xhigh'),
|
|
111
|
+
('gemini-4-neon', 'Gemini 4 Neon', 1000000, 262144, ['text', 'image', 'audio', 'video', 'pdf'], ['low', 'medium', 'high', 'xhigh'], 'xhigh'),
|
|
112
|
+
]
|
|
113
|
+
return _bloco_modelos_lista(modelos, indent)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _bloco_modelos_workbuddy(indent: str = ' ') -> str:
|
|
117
|
+
modelos = [
|
|
118
|
+
('deepseek-v4.1-flash', 'DeepSeek V4.1 Flash', 1000000, 128000, ['text', 'image'], ['low', 'medium', 'high', 'max'], 'max'),
|
|
119
|
+
('minimax-m3.1-flash', 'MiniMax M3.1 Flash', 1000000, 128000, ['text', 'image'], ['low', 'medium', 'high', 'max'], 'max'),
|
|
120
|
+
('kimi-k3', 'Kimi K3', 1000000, 32000, ['text', 'image'], ['low', 'medium', 'high'], 'high'),
|
|
121
|
+
('glm-5.3-flash', 'GLM 5.3 Flash', 1000000, 32000, ['text', 'image'], ['low', 'medium', 'high'], 'high'),
|
|
122
|
+
('grok-4.7', 'Grok 4.7', 500000, 128000, ['text', 'image'], ['low', 'medium', 'high'], 'high'),
|
|
123
|
+
('gemini-3.8-flash', 'Gemini 3.8 Flash', 1000000, 65536, ['text', 'image'], ['low', 'medium', 'high'], 'high'),
|
|
124
|
+
]
|
|
125
|
+
return _bloco_modelos_lista(modelos, indent)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _bloco_modelos_tokenharbor(indent: str = ' ') -> str:
|
|
129
|
+
modelos = [
|
|
130
|
+
('deepseek-v4.1-flash:free', 'DeepSeek V4.1 Flash Free', 200000, 32768, ['text'], ['low', 'medium', 'high', 'max'], 'max'),
|
|
131
|
+
]
|
|
132
|
+
return _bloco_modelos_lista(modelos, indent)
|
|
133
|
+
|
|
134
|
+
|
|
105
135
|
def _garantir_plugin_no_texto(texto: str, plugin_dir: str) -> tuple[str, bool]:
|
|
106
136
|
lit = json.dumps(plugin_dir)
|
|
107
137
|
if lit in texto or 'plugins/system-prompt' in texto or 'plugins\\\\system-prompt' in texto:
|
|
@@ -125,6 +155,55 @@ def _garantir_plugin_no_texto(texto: str, plugin_dir: str) -> tuple[str, bool]:
|
|
|
125
155
|
return texto, False
|
|
126
156
|
|
|
127
157
|
|
|
158
|
+
def _remover_provedor(texto: str, provider_id: str) -> tuple[str, bool]:
|
|
159
|
+
chave = f'"{provider_id}"'
|
|
160
|
+
idx = texto.find(chave)
|
|
161
|
+
if idx < 0:
|
|
162
|
+
return texto, False
|
|
163
|
+
brace = texto.find('{', idx)
|
|
164
|
+
if brace < 0:
|
|
165
|
+
return texto, False
|
|
166
|
+
prof = 0
|
|
167
|
+
in_str = False
|
|
168
|
+
esc = False
|
|
169
|
+
fim = -1
|
|
170
|
+
for i in range(brace, len(texto)):
|
|
171
|
+
ch = texto[i]
|
|
172
|
+
if in_str:
|
|
173
|
+
if esc:
|
|
174
|
+
esc = False
|
|
175
|
+
elif ch == '\\':
|
|
176
|
+
esc = True
|
|
177
|
+
elif ch == '"':
|
|
178
|
+
in_str = False
|
|
179
|
+
else:
|
|
180
|
+
if ch == '"':
|
|
181
|
+
in_str = True
|
|
182
|
+
elif ch == '{':
|
|
183
|
+
prof += 1
|
|
184
|
+
elif ch == '}':
|
|
185
|
+
prof -= 1
|
|
186
|
+
if prof == 0:
|
|
187
|
+
fim = i + 1
|
|
188
|
+
break
|
|
189
|
+
if fim <= brace:
|
|
190
|
+
return texto, False
|
|
191
|
+
lin_ini = texto.rfind('\n', 0, idx)
|
|
192
|
+
inicio = (lin_ini + 1) if (lin_ini >= 0 and not texto[lin_ini + 1:idx].strip()) else idx
|
|
193
|
+
depois = texto[fim:]
|
|
194
|
+
antes = texto[:inicio]
|
|
195
|
+
if depois.lstrip().startswith(','):
|
|
196
|
+
pos_v = depois.find(',')
|
|
197
|
+
depois = depois[pos_v + 1:]
|
|
198
|
+
if depois.startswith('\r\n'):
|
|
199
|
+
depois = depois[2:]
|
|
200
|
+
elif depois.startswith('\n'):
|
|
201
|
+
depois = depois[1:]
|
|
202
|
+
elif antes.rstrip().endswith(','):
|
|
203
|
+
antes = antes.rstrip()[:-1] + '\n'
|
|
204
|
+
return antes + depois, True
|
|
205
|
+
|
|
206
|
+
|
|
128
207
|
def _substituir_ou_inserir_provedor(texto: str, provider_id: str, bloco: str) -> tuple[str, bool]:
|
|
129
208
|
chave = f'"{provider_id}"'
|
|
130
209
|
if chave in texto:
|
|
@@ -156,10 +235,13 @@ def _substituir_ou_inserir_provedor(texto: str, provider_id: str, bloco: str) ->
|
|
|
156
235
|
fim = i + 1
|
|
157
236
|
break
|
|
158
237
|
if fim > brace:
|
|
159
|
-
#
|
|
238
|
+
# Substitui apenas o trecho `"provider_id": { ... }`, preservando
|
|
239
|
+
# qualquer texto na mesma linha antes da chave (ex.: JSON em 1 linha).
|
|
160
240
|
lin_ini = texto.rfind('\n', 0, idx)
|
|
161
|
-
|
|
162
|
-
|
|
241
|
+
prefixo_linha = texto[lin_ini + 1:idx] if lin_ini >= 0 else texto[:idx]
|
|
242
|
+
inicio = (lin_ini + 1) if (lin_ini >= 0 and not prefixo_linha.strip()) else idx
|
|
243
|
+
novo = texto[:inicio] + bloco.lstrip() if inicio == idx else texto[:inicio] + bloco
|
|
244
|
+
novo += texto[fim:]
|
|
163
245
|
return novo, novo != texto
|
|
164
246
|
m = re.search(r'"providers"\s*:\s*\{', texto)
|
|
165
247
|
if m:
|
|
@@ -212,7 +294,7 @@ def opencode_detectado() -> bool:
|
|
|
212
294
|
|
|
213
295
|
|
|
214
296
|
def opencode_ja_configurado(porta: int = 8765) -> bool:
|
|
215
|
-
"""True se opencode.json(c) já tem `krnell` atualizado na porta com visão NVIDIA."""
|
|
297
|
+
"""True se opencode.json(c) já tem `krnell` atualizado na porta com visão NVIDIA + plugin TUI."""
|
|
216
298
|
esperado = f'http://127.0.0.1:{int(porta)}/v1'
|
|
217
299
|
modelos_visao = ('kimi-k3.1-pro', 'minimax-m3.1-flash')
|
|
218
300
|
for arq in candidatos_config_opencode():
|
|
@@ -239,15 +321,56 @@ def opencode_ja_configurado(porta: int = 8765) -> bool:
|
|
|
239
321
|
modelos = bloco.get('models')
|
|
240
322
|
if not isinstance(modelos, dict):
|
|
241
323
|
continue
|
|
242
|
-
if all(
|
|
324
|
+
if not all(
|
|
243
325
|
isinstance(modelos.get(mid), dict)
|
|
244
326
|
and 'image' in ((modelos[mid].get('capabilities') or {}).get('input') or [])
|
|
245
327
|
for mid in modelos_visao
|
|
328
|
+
):
|
|
329
|
+
continue
|
|
330
|
+
# Exige também o plugin TUI instalado (tui.tsx + package.json) e registrado em cli.json
|
|
331
|
+
cfg_dir = arq.parent
|
|
332
|
+
plugin_dir = cfg_dir / 'plugins' / 'system-prompt'
|
|
333
|
+
if not ((plugin_dir / 'tui.tsx').is_file() and (plugin_dir / 'package.json').is_file()):
|
|
334
|
+
continue
|
|
335
|
+
cli_path = cfg_dir / 'cli.json'
|
|
336
|
+
if not cli_path.is_file():
|
|
337
|
+
continue
|
|
338
|
+
try:
|
|
339
|
+
cli_dados = json.loads(cli_path.read_text(encoding='utf-8'))
|
|
340
|
+
except Exception:
|
|
341
|
+
continue
|
|
342
|
+
lista_cli = cli_dados.get('plugins') if isinstance(cli_dados, dict) else None
|
|
343
|
+
alvo_dir = str(plugin_dir.resolve())
|
|
344
|
+
if isinstance(lista_cli, list) and any(
|
|
345
|
+
str(Path(x).resolve()) == alvo_dir for x in lista_cli if isinstance(x, str)
|
|
246
346
|
):
|
|
247
347
|
return True
|
|
248
348
|
return False
|
|
249
349
|
|
|
250
350
|
|
|
351
|
+
def _registrar_plugin_tui_cli_json(cfg_dir: Path, plugin_dir: str) -> None:
|
|
352
|
+
"""Adiciona o plugin TUI do Krnell em cli.json sem apagar preferências existentes."""
|
|
353
|
+
cli_path = cfg_dir / 'cli.json'
|
|
354
|
+
try:
|
|
355
|
+
dados = json.loads(cli_path.read_text(encoding='utf-8')) if cli_path.is_file() else {
|
|
356
|
+
'$schema': 'https://opencode.ai/v2/cli.json',
|
|
357
|
+
}
|
|
358
|
+
if not isinstance(dados, dict):
|
|
359
|
+
return
|
|
360
|
+
except Exception:
|
|
361
|
+
return
|
|
362
|
+
lista = dados.get('plugins')
|
|
363
|
+
if not isinstance(lista, list):
|
|
364
|
+
lista = []
|
|
365
|
+
if plugin_dir not in lista:
|
|
366
|
+
lista.append(plugin_dir)
|
|
367
|
+
dados['plugins'] = lista
|
|
368
|
+
try:
|
|
369
|
+
cli_path.write_text(json.dumps(dados, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
|
370
|
+
except OSError:
|
|
371
|
+
pass
|
|
372
|
+
|
|
373
|
+
|
|
251
374
|
def configurar_opencode(raiz: Path, porta: int = 8765, api_key: str = '') -> dict:
|
|
252
375
|
"""Instala o plugin system-prompt e registra o provedor `krnell` no OpenCode."""
|
|
253
376
|
raiz = Path(raiz).resolve()
|
|
@@ -256,15 +379,23 @@ def configurar_opencode(raiz: Path, porta: int = 8765, api_key: str = '') -> dic
|
|
|
256
379
|
cfg_dir = arq.parent
|
|
257
380
|
cfg_dir.mkdir(parents=True, exist_ok=True)
|
|
258
381
|
|
|
259
|
-
# 1) Plugin system-prompt
|
|
260
|
-
|
|
382
|
+
# 1) Plugin unificado (server: system-prompt + auto-start sob demanda; TUI:
|
|
383
|
+
# painel no slot session.composer.top, sem substituir abas/prompt do OpenCode)
|
|
384
|
+
src_plugin_dir = raiz / 'plugins' / 'system-prompt'
|
|
385
|
+
src_plugin = src_plugin_dir / 'index.ts'
|
|
261
386
|
dst_plugin_dir = cfg_dir / 'plugins' / 'system-prompt'
|
|
262
387
|
dst_plugin = dst_plugin_dir / 'index.ts'
|
|
263
388
|
plugin_instalado = False
|
|
264
389
|
if src_plugin.exists():
|
|
265
390
|
dst_plugin_dir.mkdir(parents=True, exist_ok=True)
|
|
266
|
-
|
|
391
|
+
for arq_p in ('index.ts', 'tui.tsx', 'package.json'):
|
|
392
|
+
origem_p = src_plugin_dir / arq_p
|
|
393
|
+
destino_p = dst_plugin_dir / arq_p
|
|
394
|
+
if origem_p.is_file() and origem_p.resolve() != destino_p.resolve():
|
|
395
|
+
shutil.copy2(origem_p, destino_p)
|
|
267
396
|
plugin_instalado = True
|
|
397
|
+
# Registra o plugin TUI também em cli.json (footer nativo + /krnell).
|
|
398
|
+
_registrar_plugin_tui_cli_json(cfg_dir, str(dst_plugin_dir))
|
|
268
399
|
|
|
269
400
|
# 2) AGENTS.md se existir na raiz e ainda nao existir no OpenCode
|
|
270
401
|
src_agents = raiz / 'AGENTS.md'
|
|
@@ -276,7 +407,7 @@ def configurar_opencode(raiz: Path, porta: int = 8765, api_key: str = '') -> dic
|
|
|
276
407
|
key_val = (api_key or 'local').strip()
|
|
277
408
|
bloco_krnell = (
|
|
278
409
|
f' "krnell": {{\n'
|
|
279
|
-
f' "name": "
|
|
410
|
+
f' "name": "NVIDIA Free",\n'
|
|
280
411
|
f' "package": "@opencode/ai/providers/openai-compatible",\n'
|
|
281
412
|
f' "settings": {{\n'
|
|
282
413
|
f' "baseURL": "{base_url}",\n'
|
|
@@ -309,14 +440,13 @@ def configurar_opencode(raiz: Path, porta: int = 8765, api_key: str = '') -> dic
|
|
|
309
440
|
texto, _ = _substituir_ou_inserir_provedor(texto, 'nyxo', bloco_krnell)
|
|
310
441
|
else:
|
|
311
442
|
texto, _ = _substituir_ou_inserir_provedor(texto, 'krnell', bloco_krnell)
|
|
312
|
-
#
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
)
|
|
443
|
+
# Remove blocos estáticos que antes forçavam Antigravity/WorkBuddy/TokenHarbor
|
|
444
|
+
# no /model mesmo sem login (agora o plugin os registra dinamicamente com
|
|
445
|
+
# activation:"auto", aparecendo no /connect e entrando em /model só quando
|
|
446
|
+
# há conta/chave conectada). Remove também o legado duplicado "kimibridge".
|
|
447
|
+
for pid in ('antigravity', 'workbuddy', 'tokenharbor', 'kimibridge'):
|
|
448
|
+
if f'"{pid}"' in texto:
|
|
449
|
+
texto, _ = _remover_provedor(texto, pid)
|
|
320
450
|
arq.write_text(texto, encoding='utf-8')
|
|
321
451
|
|
|
322
452
|
return {
|
package/package.json
CHANGED