claude-telegram-bot 0.3.30 β†’ 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.
Files changed (2) hide show
  1. package/bot.mjs +18 -6
  2. 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
- "-p" + prompt, // λΆ™μ—¬μ“°κΈ°λ‘œ -둜 μ‹œμž‘ν•˜λŠ” 값도 ν”Œλž˜κ·Έλ‘œ μ˜€ν•΄ μ•ˆ 함
578
- "--output-format",
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,6 +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);
598
+ // -p와 ν”„λ‘¬ν”„νŠΈλŠ” 맨 끝에 β€” 터미널 ν…ŒμŠ€νŠΈμ—μ„œ κ²€μ¦λœ μˆœμ„œ
599
+ // `--` κ΅¬λΆ„μžλ‘œ `-`둜 μ‹œμž‘ν•˜λŠ” ν”„λ‘¬ν”„νŠΈλ„ μ˜΅μ…˜μœΌλ‘œ μ˜€ν•΄ μ•ˆ 함
600
+ args.push("-p", "--", prompt);
599
601
 
600
602
  const child = spawn(cfg.claudeBin || "claude", args, {
601
603
  cwd: cfg.projectDir,
@@ -623,7 +625,8 @@ function runClaude(prompt, sessionId, opts = {}) {
623
625
  const text = j.is_error ? classifyClaudeError(rawErr, code) : (rawErr || "(empty response)");
624
626
  const resetAt = j.is_error ? parseResetTime(rawErr) : null;
625
627
  const canFallback = j.is_error && isFallbackError(rawErr, code);
626
- resolve({ ok: !j.is_error, text, sessionId: j.session_id, cost: j.total_cost_usd, resetAt, canFallback });
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 });
627
630
  } catch {
628
631
  const raw = (err || out || "no output").slice(0, 3500);
629
632
  resolve({ ok: false, text: classifyClaudeError(raw, code), resetAt: parseResetTime(raw), canFallback: isFallbackError(raw, code) });
@@ -1212,6 +1215,15 @@ async function handle(msg) {
1212
1215
  } else {
1213
1216
  const footer = `\n\nβ€” ${secs}s${res.cost ? ` Β· $${res.cost.toFixed(4)}` : ""}`;
1214
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
+ }
1215
1227
  }
1216
1228
  } catch (e) {
1217
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.30",
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": {