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
|
@@ -58,11 +58,11 @@ const CFG = {
|
|
|
58
58
|
// Otimizacao NVIDIA/hCaptcha:
|
|
59
59
|
// - captchaWorkers: quantidade de contextos isolados (cada um com cookie jar proprio)
|
|
60
60
|
// - captchaWidgetsPerWorker: widgets hCaptcha paralelos por contexto
|
|
61
|
-
// - captchaPoolSize: buffer de tokens frescos pre-mintados
|
|
61
|
+
// - captchaPoolSize: buffer de tokens frescos pre-mintados (sobe sob rajada ate burstPool)
|
|
62
62
|
// - browserIdleCloseMs: fecha o browser apos ocioso (0 MB RAM sem uso NVIDIA)
|
|
63
|
-
captchaWorkers:
|
|
63
|
+
captchaWorkers: 3,
|
|
64
64
|
captchaWidgetsPerWorker: 2,
|
|
65
|
-
captchaPoolSize:
|
|
65
|
+
captchaPoolSize: 6,
|
|
66
66
|
browserIdleCloseMs: 120000,
|
|
67
67
|
locale: 'en-US',
|
|
68
68
|
answerMarker: '**[ENI]**',
|
|
@@ -812,88 +812,12 @@ ${opencodeModelsBlock(' ')}
|
|
|
812
812
|
}
|
|
813
813
|
|
|
814
814
|
// ---------- autostart ----------
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
815
|
+
// Autostart no boot removido por segurança/controle: o Krnell agora sobe sob
|
|
816
|
+
// demanda (pelo `krnell` ou inteligentemente pelo plugin do OpenCode somente
|
|
817
|
+
// quando o usuário usa um modelo Krnell/KimiBridge ou clica no botão do footer).
|
|
819
818
|
async function installAutostart() {
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
const script = path.join(APP_DIR, 'bridge.mjs');
|
|
823
|
-
const winNode = path.join(APP_DIR, 'node', 'node.exe');
|
|
824
|
-
const nodePath = IS_WIN && fs.existsSync(winNode) ? winNode : process.execPath;
|
|
825
|
-
try {
|
|
826
|
-
if (IS_WIN) {
|
|
827
|
-
const dir = startupDir();
|
|
828
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
829
|
-
const vbs = path.join(dir, 'KimiBridge.vbs');
|
|
830
|
-
if (!fs.existsSync(vbs)) {
|
|
831
|
-
const bootBat = path.join(APP_DIR, 'iniciar_oculto.bat');
|
|
832
|
-
fs.writeFileSync(bootBat, `@echo off\r\ncd /d "${APP_DIR}"\r\n"${nodePath}" "${script}" >> "${path.join(LOG_DIR, 'boot.log')}" 2>&1\r\n`);
|
|
833
|
-
fs.writeFileSync(vbs, `Set sh = CreateObject("WScript.Shell")\r\nsh.Run """${bootBat}""", 0, False\r\n`);
|
|
834
|
-
log('autostart: Windows (atalho oculto na inicializacao)');
|
|
835
|
-
}
|
|
836
|
-
} else {
|
|
837
|
-
let done = false;
|
|
838
|
-
if (!IS_TERMUX) {
|
|
839
|
-
try {
|
|
840
|
-
const r = await run('systemctl', ['--user', 'is-system-running']);
|
|
841
|
-
if (/running|degraded/.test(r.stdout)) {
|
|
842
|
-
const svcDir = path.join(HOME, '.config', 'systemd', 'user');
|
|
843
|
-
fs.mkdirSync(svcDir, { recursive: true });
|
|
844
|
-
const unit = path.join(svcDir, 'kimi-bridge.service');
|
|
845
|
-
if (!fs.existsSync(unit)) {
|
|
846
|
-
fs.writeFileSync(unit, `[Unit]
|
|
847
|
-
Description=Kimi Bridge
|
|
848
|
-
After=network-online.target
|
|
849
|
-
|
|
850
|
-
[Service]
|
|
851
|
-
Type=simple
|
|
852
|
-
WorkingDirectory=${APP_DIR}
|
|
853
|
-
ExecStart=${nodePath} ${script}
|
|
854
|
-
Restart=on-failure
|
|
855
|
-
RestartSec=10
|
|
856
|
-
|
|
857
|
-
[Install]
|
|
858
|
-
WantedBy=default.target
|
|
859
|
-
`);
|
|
860
|
-
await run('systemctl', ['--user', 'daemon-reload']);
|
|
861
|
-
await run('systemctl', ['--user', 'enable', 'kimi-bridge.service']);
|
|
862
|
-
log('autostart: servico systemd de usuario');
|
|
863
|
-
}
|
|
864
|
-
done = true;
|
|
865
|
-
}
|
|
866
|
-
} catch {}
|
|
867
|
-
}
|
|
868
|
-
if (!done && !IS_TERMUX && (await commandExists('crontab'))) {
|
|
869
|
-
const current = (await run('crontab', ['-l'])).stdout || '';
|
|
870
|
-
if (!current.includes(APP_DIR)) {
|
|
871
|
-
const line = `@reboot cd ${APP_DIR} && ${nodePath} ${script} >> ${path.join(LOG_DIR, 'boot.log')} 2>&1`;
|
|
872
|
-
await run('sh', ['-c', `(crontab -l 2>/dev/null; echo "${line}") | crontab -`]);
|
|
873
|
-
log('autostart: cron @reboot');
|
|
874
|
-
}
|
|
875
|
-
done = true;
|
|
876
|
-
}
|
|
877
|
-
if (!done) {
|
|
878
|
-
const prof = path.join(HOME, '.profile');
|
|
879
|
-
const txt = fs.existsSync(prof) ? fs.readFileSync(prof, 'utf8') : '';
|
|
880
|
-
if (!txt.includes('# kimi-bridge autostart')) {
|
|
881
|
-
const sh = path.join(APP_DIR, 'iniciar.sh');
|
|
882
|
-
const agFile = path.join(APP_DIR, 'antigravity.json');
|
|
883
|
-
const bootLog = path.join(LOG_DIR, 'boot.log');
|
|
884
|
-
fs.appendFileSync(
|
|
885
|
-
prof,
|
|
886
|
-
`\n# kimi-bridge autostart\nif ! curl -sf http://${CFG.host}:${CFG.port}/healthz >/dev/null 2>&1; then\n if [ -t 0 ] && [ ! -s "${agFile}" ]; then\n bash "${sh}"\n else\n nohup bash "${sh}" --background >> "${bootLog}" 2>&1 &\n fi\nfi\n`
|
|
887
|
-
);
|
|
888
|
-
log('autostart: login do shell (~/.profile)');
|
|
889
|
-
}
|
|
890
|
-
done = true;
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
} catch (e) {
|
|
894
|
-
log('autostart nao instalado:', e.message);
|
|
895
|
-
}
|
|
896
|
-
try { fs.writeFileSync(marker, new Date().toISOString()); } catch {}
|
|
819
|
+
// Não grava nada em Startup, systemd, crontab ou ~/.profile.
|
|
820
|
+
return;
|
|
897
821
|
}
|
|
898
822
|
|
|
899
823
|
// ---------- estado do browser/captcha (pool paralelo + auto-hibernacao) ----------
|
|
@@ -906,11 +830,11 @@ WantedBy=default.target
|
|
|
906
830
|
// - buffer de tokens frescos + fila com respeito a AbortSignal;
|
|
907
831
|
// - fecha o browser automaticamente apos browserIdleCloseMs sem uso NVIDIA
|
|
908
832
|
// (0 MB de RAM quando voce so esta usando Antigravity ou parado).
|
|
909
|
-
const CAPTCHA_WORKERS = Math.max(1, Math.min(8, Number(CFG.captchaWorkers) ||
|
|
833
|
+
const CAPTCHA_WORKERS = Math.max(1, Math.min(8, Number(CFG.captchaWorkers) || 3));
|
|
910
834
|
const CAPTCHA_WIDGETS_PER_WORKER = Math.max(1, Math.min(4, Number(CFG.captchaWidgetsPerWorker) || 2));
|
|
911
|
-
const CAPTCHA_POOL_TARGET = Math.max(1, Math.min(
|
|
912
|
-
const CAPTCHA_TOKEN_TTL_MS =
|
|
913
|
-
const CAPTCHA_ROTATE_AFTER =
|
|
835
|
+
const CAPTCHA_POOL_TARGET = Math.max(1, Math.min(16, Number(CFG.captchaPoolSize) || 6));
|
|
836
|
+
const CAPTCHA_TOKEN_TTL_MS = 85000;
|
|
837
|
+
const CAPTCHA_ROTATE_AFTER = 12; // gira o BrowserContext (cookies novos + libera RAM) a cada 12 mints
|
|
914
838
|
const BROWSER_IDLE_CLOSE_MS = Math.max(30000, Number(CFG.browserIdleCloseMs) || 120000);
|
|
915
839
|
|
|
916
840
|
const state = {
|
|
@@ -1985,15 +1909,12 @@ function agBootstrapHeaders(accessToken) {
|
|
|
1985
1909
|
|
|
1986
1910
|
function agFormatDuration(sec) {
|
|
1987
1911
|
if (sec === null || sec === undefined || !Number.isFinite(sec)) return null;
|
|
1988
|
-
if (sec <= 0) return '
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
if (h > 0) return `${h}h ${m}m`;
|
|
1995
|
-
if (m > 0) return `${m}m ${s}s`;
|
|
1996
|
-
return `${s}s`;
|
|
1912
|
+
if (sec <= 0) return '0s';
|
|
1913
|
+
// Unidade principal única: dias (>=24h), horas (<24h), minutos (<1h), segundos (<1m).
|
|
1914
|
+
if (sec >= 86400) return `${Math.floor(sec / 86400)}d`;
|
|
1915
|
+
if (sec >= 3600) return `${Math.floor(sec / 3600)}h`;
|
|
1916
|
+
if (sec >= 60) return `${Math.floor(sec / 60)}m`;
|
|
1917
|
+
return `${Math.max(1, Math.floor(sec))}s`;
|
|
1997
1918
|
}
|
|
1998
1919
|
|
|
1999
1920
|
function agQuotaBucketKey(modelOrWire) {
|
|
@@ -2054,6 +1975,54 @@ function agMarkCooldown(acct, model, wire, untilMs, reason = 'quota') {
|
|
|
2054
1975
|
}
|
|
2055
1976
|
}
|
|
2056
1977
|
|
|
1978
|
+
function agQuotaWindowLabel(acct, bucket, reason = '', untilMs = 0) {
|
|
1979
|
+
const rt = acct ? agRuntime(acct) : null;
|
|
1980
|
+
const now = Date.now();
|
|
1981
|
+
const isFree = /free/i.test(String(acct?.paidTier || '')) || (!acct?.paidTier && /free/i.test(String(acct?.tier || '')));
|
|
1982
|
+
if (rt) {
|
|
1983
|
+
for (const g of rt.quota.groups || []) {
|
|
1984
|
+
if (!agGroupMatchesBucket(g.displayName, bucket)) continue;
|
|
1985
|
+
for (const b of g.buckets || []) {
|
|
1986
|
+
const frac = typeof b.remainingFraction === 'number' ? b.remainingFraction : (b.resetTime ? 0 : null);
|
|
1987
|
+
if (frac !== null && frac <= 0) {
|
|
1988
|
+
const w = String(b.window || b.bucketId || '').toLowerCase();
|
|
1989
|
+
if (w.includes('week')) return 'semanal';
|
|
1990
|
+
if (w.includes('5h')) return 'diária (5h)';
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
const r = String(reason || '').toLowerCase();
|
|
1996
|
+
if (r.includes('week')) return 'semanal';
|
|
1997
|
+
if (r.includes('5h')) return 'diária (5h)';
|
|
1998
|
+
if (isFree) return 'semanal';
|
|
1999
|
+
if (untilMs && untilMs - now > 6 * 3600 * 1000) return 'semanal';
|
|
2000
|
+
return 'diária (5h)';
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
function agFormatExhaustedMessage(modelOrWire, exhaustedList) {
|
|
2004
|
+
const now = Date.now();
|
|
2005
|
+
const list = Array.isArray(exhaustedList) ? exhaustedList.slice() : [];
|
|
2006
|
+
list.sort((a, b) => (a.until || Infinity) - (b.until || Infinity));
|
|
2007
|
+
const earliest = list[0];
|
|
2008
|
+
const bucket = agQuotaBucketKey(modelOrWire);
|
|
2009
|
+
const tipo = earliest ? agQuotaWindowLabel(earliest.acct, bucket, earliest.reason, earliest.until) : 'diária (5h)';
|
|
2010
|
+
const sec = earliest && earliest.until ? Math.max(0, Math.round((earliest.until - now) / 1000)) : null;
|
|
2011
|
+
const falta = sec !== null ? agFormatDuration(sec) : null;
|
|
2012
|
+
const prefixo = tipo === 'semanal'
|
|
2013
|
+
? 'Sua quota semanal acabou'
|
|
2014
|
+
: 'Sua quota diária (5h) acabou';
|
|
2015
|
+
if (agStore.accounts.length <= 1) {
|
|
2016
|
+
return falta
|
|
2017
|
+
? `${prefixo} para ${modelOrWire}. Reseta em ${falta}.`
|
|
2018
|
+
: `${prefixo} para ${modelOrWire}. Aguarde o reset da janela.`;
|
|
2019
|
+
}
|
|
2020
|
+
const conta = earliest?.acct?.email || earliest?.acct?.id || '';
|
|
2021
|
+
return falta
|
|
2022
|
+
? `${prefixo} em todas as ${agStore.accounts.length} contas Antigravity para ${modelOrWire}. Reseta em ${falta}${conta ? ` (${conta})` : ''}.`
|
|
2023
|
+
: `${prefixo} em todas as ${agStore.accounts.length} contas Antigravity para ${modelOrWire}.`;
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2057
2026
|
function agAccountAvailability(acct, model, wire) {
|
|
2058
2027
|
const now = Date.now();
|
|
2059
2028
|
const rt = agRuntime(acct);
|
|
@@ -3295,13 +3264,7 @@ async function handleAntigravityChat(body, model, res, reqAbort, preferredHint =
|
|
|
3295
3264
|
}
|
|
3296
3265
|
|
|
3297
3266
|
if (!available.length) {
|
|
3298
|
-
|
|
3299
|
-
const earliest = exhausted[0];
|
|
3300
|
-
const sec = earliest && earliest.until ? Math.max(0, Math.round((earliest.until - Date.now()) / 1000)) : null;
|
|
3301
|
-
const when = earliest && earliest.until
|
|
3302
|
-
? `${earliest.acct.email || earliest.acct.id} em ${agFormatDuration(sec)} (${new Date(earliest.until).toISOString()})`
|
|
3303
|
-
: 'aguarde o reset da janela';
|
|
3304
|
-
const msg = `Todas as ${agStore.accounts.length} conta(s) Antigravity estao sem quota para ${wire}. Proximo reset: ${when}.`;
|
|
3267
|
+
const msg = agFormatExhaustedMessage(wire, exhausted);
|
|
3305
3268
|
log(`antigravity: ${msg}`);
|
|
3306
3269
|
return sendJson(429, { error: { message: msg, type: 'antigravity_quota_exhausted', code: 429 } });
|
|
3307
3270
|
}
|
|
@@ -3371,6 +3334,12 @@ async function handleAntigravityChat(body, model, res, reqAbort, preferredHint =
|
|
|
3371
3334
|
continue;
|
|
3372
3335
|
}
|
|
3373
3336
|
log(`req ${id}: erro upstream`, String(up.errorText || '').slice(0, 400));
|
|
3337
|
+
if (up.status === 429) {
|
|
3338
|
+
const msg = agFormatExhaustedMessage(envelope.model, [{ acct, until: up.resetUntil, reason: 'hard_429' }]);
|
|
3339
|
+
return sendJson(429, {
|
|
3340
|
+
error: { message: msg, type: 'antigravity_quota_exhausted', code: 429 },
|
|
3341
|
+
});
|
|
3342
|
+
}
|
|
3374
3343
|
return sendJson(up.status || 400, {
|
|
3375
3344
|
error: { message: String(up.errorText || 'upstream error').slice(0, 1200), type: 'upstream_error', code: up.status || 400 },
|
|
3376
3345
|
});
|
package/tui_core.py
CHANGED
|
@@ -453,12 +453,21 @@ def desenhar_overlay_centrado(
|
|
|
453
453
|
for offset, linha_box in enumerate(caixa_linhas):
|
|
454
454
|
y = top + offset
|
|
455
455
|
if 0 <= y < len(linhas):
|
|
456
|
-
#
|
|
457
|
-
#
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
456
|
+
# Composição em uma única passada sem CSI G sobreposto: evita
|
|
457
|
+
# vazamento de linha do fundo atravessando o diálogo no Termux.
|
|
458
|
+
# Não usa truncate_vis porque ele coloca "…" quando corta espaços em branco.
|
|
459
|
+
fundo_limpo = strip_ansi(linhas[y])
|
|
460
|
+
pedacos, cols = [], 0
|
|
461
|
+
for ch in fundo_limpo:
|
|
462
|
+
w_ch = vis_len(ch)
|
|
463
|
+
if cols + w_ch > left:
|
|
464
|
+
break
|
|
465
|
+
pedacos.append(ch)
|
|
466
|
+
cols += w_ch
|
|
467
|
+
esq = ''.join(pedacos)
|
|
468
|
+
pad_esq = ' ' * max(0, left - cols)
|
|
469
|
+
prefixo = f'\x1b[2m{esq}{pad_esq}\x1b[0m' if esmaecer_fundo else f'{esq}{pad_esq}'
|
|
470
|
+
linhas[y] = f'{prefixo}{cor_fundo_ansi}{linha_box}\x1b[0m'
|
|
462
471
|
return linhas, top, left
|
|
463
472
|
|
|
464
473
|
|