@gonzih/cc-tg 0.2.20 → 0.2.21

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/dist/bot.js CHANGED
@@ -460,7 +460,12 @@ export class CcTgBot {
460
460
  });
461
461
  }
462
462
  // Hybrid file upload: find files mentioned in result text that Claude actually wrote
463
- this.uploadMentionedFiles(chatId, text, session);
463
+ try {
464
+ this.uploadMentionedFiles(chatId, text, session);
465
+ }
466
+ catch (err) {
467
+ console.error(`[tg:${chatId}] uploadMentionedFiles error:`, err.message);
468
+ }
464
469
  }
465
470
  trackWrittenFiles(msg, session, cwd) {
466
471
  // Only look at assistant messages with tool_use blocks
@@ -614,7 +619,13 @@ export class CcTgBot {
614
619
  console.log(`[claude:files] skipping sensitive file: ${filePath}`);
615
620
  continue;
616
621
  }
617
- const fileSize = statSync(filePath).size;
622
+ let fileSize;
623
+ try {
624
+ fileSize = statSync(filePath).size;
625
+ }
626
+ catch {
627
+ continue; // file disappeared between existsSync and statSync
628
+ }
618
629
  const MAX_TG_FILE_BYTES = 50 * 1024 * 1024;
619
630
  if (fileSize > MAX_TG_FILE_BYTES) {
620
631
  const mb = (fileSize / (1024 * 1024)).toFixed(1);
@@ -666,7 +677,13 @@ export class CcTgBot {
666
677
  output += text;
667
678
  const result = output.trim();
668
679
  if (result) {
669
- const footer = formatCronCostFooter(cronUsage);
680
+ let footer = "";
681
+ try {
682
+ footer = formatCronCostFooter(cronUsage);
683
+ }
684
+ catch (err) {
685
+ console.error(`[cron] cost footer error:`, err.message);
686
+ }
670
687
  const chunks = splitMessage(`🕐 ${result}${footer}`);
671
688
  (async () => {
672
689
  for (const chunk of chunks) {
package/dist/claude.js CHANGED
@@ -107,38 +107,40 @@ export class ClaudeProcess extends EventEmitter {
107
107
  for (const line of lines) {
108
108
  if (!line.trim())
109
109
  continue;
110
+ let raw;
110
111
  try {
111
- const raw = JSON.parse(line);
112
- // Emit usage events from Anthropic API stream events passed through by Claude CLI
113
- if (raw.type === "message_start") {
114
- const usage = (raw.message?.usage);
115
- if (usage) {
116
- this.emit("usage", {
117
- inputTokens: usage.input_tokens ?? 0,
118
- outputTokens: 0, // output_tokens at message_start is always 0
119
- cacheReadTokens: usage.cache_read_input_tokens ?? 0,
120
- cacheWriteTokens: usage.cache_creation_input_tokens ?? 0,
121
- });
122
- }
123
- }
124
- else if (raw.type === "message_delta") {
125
- const usage = raw.usage;
126
- if (usage?.output_tokens) {
127
- this.emit("usage", {
128
- inputTokens: 0,
129
- outputTokens: usage.output_tokens,
130
- cacheReadTokens: 0,
131
- cacheWriteTokens: 0,
132
- });
133
- }
134
- }
135
- const msg = this.parseMessage(raw);
136
- if (msg)
137
- this.emit("message", msg);
112
+ raw = JSON.parse(line);
138
113
  }
139
114
  catch {
140
115
  // Non-JSON line (startup noise etc.) — ignore
116
+ continue;
117
+ }
118
+ // Emit usage events from Anthropic API stream events passed through by Claude CLI
119
+ if (raw.type === "message_start") {
120
+ const usage = (raw.message?.usage);
121
+ if (usage) {
122
+ this.emit("usage", {
123
+ inputTokens: usage.input_tokens ?? 0,
124
+ outputTokens: 0, // output_tokens at message_start is always 0
125
+ cacheReadTokens: usage.cache_read_input_tokens ?? 0,
126
+ cacheWriteTokens: usage.cache_creation_input_tokens ?? 0,
127
+ });
128
+ }
129
+ }
130
+ else if (raw.type === "message_delta") {
131
+ const usage = raw.usage;
132
+ if (usage?.output_tokens) {
133
+ this.emit("usage", {
134
+ inputTokens: 0,
135
+ outputTokens: usage.output_tokens,
136
+ cacheReadTokens: 0,
137
+ cacheWriteTokens: 0,
138
+ });
139
+ }
141
140
  }
141
+ const msg = this.parseMessage(raw);
142
+ if (msg)
143
+ this.emit("message", msg);
142
144
  }
143
145
  }
144
146
  parseMessage(raw) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gonzih/cc-tg",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "Claude Code Telegram bot — chat with Claude Code via Telegram",
5
5
  "type": "module",
6
6
  "bin": {