claude-telegram-bot 0.3.31 β 0.3.33
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/bot.mjs +18 -8
- package/package.json +1 -1
package/bot.mjs
CHANGED
|
@@ -150,6 +150,7 @@ const STR = {
|
|
|
150
150
|
compactOk: "ποΈ Context compacted. The conversation continues with a summary.",
|
|
151
151
|
compactFail: (m) => `β οΈ Compact failed: ${m}`,
|
|
152
152
|
compactNoSession: "No active session to compact. Just send a message to start one.",
|
|
153
|
+
autoCompact: "ποΈ Auto-compacted context (conversation was getting long).",
|
|
153
154
|
testFallbackDisabled: "β οΈ Ollama fallback is not enabled. Set `\"ollamaFallback\": true` in config.json.",
|
|
154
155
|
testFallbackFail: (m) => `β οΈ Ollama test failed: ${m}`,
|
|
155
156
|
ollamaOn: "π Ollama mode on. Messages will now go to Ollama. Your Claude session is preserved.",
|
|
@@ -292,6 +293,7 @@ const STR = {
|
|
|
292
293
|
compactOk: "ποΈ μ»¨ν
μ€νΈλ₯Ό μμΆνμ΅λλ€. λνκ° μμ½λ³ΈμΌλ‘ μ΄μ΄μ§λλ€.",
|
|
293
294
|
compactFail: (m) => `β οΈ compact μ€ν¨: ${m}`,
|
|
294
295
|
compactNoSession: "μμΆν νμ± μΈμ
μ΄ μμ΅λλ€. λ©μμ§λ₯Ό λ³΄λ΄ μΈμ
μ μμνμΈμ.",
|
|
296
|
+
autoCompact: "ποΈ λνκ° κΈΈμ΄μ Έ 컨ν
μ€νΈλ₯Ό μλ μμΆνμ΅λλ€.",
|
|
295
297
|
contextTooLong: "β οΈ ν둬ννΈκ° λ무 κΉλλ€. `/compact` λ‘ μ»¨ν
μ€νΈλ₯Ό μμΆνκ±°λ `/new` λ‘ μ μΈμ
μ μμνμΈμ.",
|
|
296
298
|
testFallbackDisabled: "β οΈ Ollama ν΄λ°±μ΄ λΉνμ±ν μνμ
λλ€. config.jsonμ `\"ollamaFallback\": true` λ₯Ό μΆκ°νμΈμ.",
|
|
297
299
|
testFallbackFail: (m) => `β οΈ Ollama ν
μ€νΈ μ€ν¨: ${m}`,
|
|
@@ -574,11 +576,8 @@ function classifyClaudeError(raw, code) {
|
|
|
574
576
|
function runClaude(prompt, sessionId, opts = {}) {
|
|
575
577
|
return new Promise((resolve) => {
|
|
576
578
|
const args = [
|
|
577
|
-
"-
|
|
578
|
-
"--
|
|
579
|
-
"json",
|
|
580
|
-
"--permission-mode",
|
|
581
|
-
cfg.permissionMode || "acceptEdits",
|
|
579
|
+
"--output-format", "json",
|
|
580
|
+
"--permission-mode", cfg.permissionMode || "acceptEdits",
|
|
582
581
|
];
|
|
583
582
|
const model = state.model || cfg.model; // /model λ‘ λ°κΎΈλ©΄ state.model μ°μ
|
|
584
583
|
const brevity =
|
|
@@ -596,8 +595,9 @@ function runClaude(prompt, sessionId, opts = {}) {
|
|
|
596
595
|
if (appendSys) args.push("--append-system-prompt", appendSys);
|
|
597
596
|
if (model) args.push("--model", model);
|
|
598
597
|
if (sessionId) args.push("--resume", sessionId);
|
|
599
|
-
// ν둬ννΈλ
|
|
600
|
-
|
|
598
|
+
// -pμ ν둬ννΈλ 맨 λμ β ν°λ―Έλ ν
μ€νΈμμ κ²μ¦λ μμ
|
|
599
|
+
// `--` ꡬλΆμλ‘ `-`λ‘ μμνλ ν둬ννΈλ μ΅μ
μΌλ‘ μ€ν΄ μ ν¨
|
|
600
|
+
args.push("-p", "--", prompt);
|
|
601
601
|
|
|
602
602
|
const child = spawn(cfg.claudeBin || "claude", args, {
|
|
603
603
|
cwd: cfg.projectDir,
|
|
@@ -625,7 +625,8 @@ function runClaude(prompt, sessionId, opts = {}) {
|
|
|
625
625
|
const text = j.is_error ? classifyClaudeError(rawErr, code) : (rawErr || "(empty response)");
|
|
626
626
|
const resetAt = j.is_error ? parseResetTime(rawErr) : null;
|
|
627
627
|
const canFallback = j.is_error && isFallbackError(rawErr, code);
|
|
628
|
-
|
|
628
|
+
const cacheTokens = j.usage?.cache_read_input_tokens || 0;
|
|
629
|
+
resolve({ ok: !j.is_error, text, sessionId: j.session_id, cost: j.total_cost_usd, cacheTokens, resetAt, canFallback });
|
|
629
630
|
} catch {
|
|
630
631
|
const raw = (err || out || "no output").slice(0, 3500);
|
|
631
632
|
resolve({ ok: false, text: classifyClaudeError(raw, code), resetAt: parseResetTime(raw), canFallback: isFallbackError(raw, code) });
|
|
@@ -1214,6 +1215,15 @@ async function handle(msg) {
|
|
|
1214
1215
|
} else {
|
|
1215
1216
|
const footer = `\n\nβ ${secs}s${res.cost ? ` Β· $${res.cost.toFixed(4)}` : ""}`;
|
|
1216
1217
|
if (!stopping) await send(chatId, res.text + footer);
|
|
1218
|
+
// μλ μ»΄ν©μ
: cache_read_input_tokens κ° μκ³κ° μ΄κ³Ό μ μλ /compact
|
|
1219
|
+
const compactThreshold = cfg.autoCompactThreshold ?? 100000;
|
|
1220
|
+
if (compactThreshold > 0 && res.cacheTokens > compactThreshold && state.sessionId && !stopping) {
|
|
1221
|
+
try {
|
|
1222
|
+
const cr = await runClaude("/compact", state.sessionId);
|
|
1223
|
+
if (cr.sessionId) { state.sessionId = cr.sessionId; saveState(state); }
|
|
1224
|
+
if (cr.ok !== false) await send(chatId, t(l, "autoCompact"));
|
|
1225
|
+
} catch {}
|
|
1226
|
+
}
|
|
1217
1227
|
}
|
|
1218
1228
|
} catch (e) {
|
|
1219
1229
|
if (!stopping) await send(chatId, t(l, "botError", e.message));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-telegram-bot",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.33",
|
|
4
4
|
"description": "Drive Claude Code from Telegram β messages run headless `claude -p` in a project dir and replies come back to the chat. Zero dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|