claude-telegram-bot 0.3.27 → 0.3.29
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 +24 -2
- package/package.json +1 -1
package/bot.mjs
CHANGED
|
@@ -570,12 +570,33 @@ function classifyClaudeError(raw, code) {
|
|
|
570
570
|
return `Execution error (exit ${code}):\n${raw}`;
|
|
571
571
|
}
|
|
572
572
|
|
|
573
|
+
// ── Claude CLI 버전 탐지 ──────────────────────────────────────────────────
|
|
574
|
+
// --print=<value> 는 구버전 CLI에 없음. 시작 시 한 번 probe해서 폴백 결정.
|
|
575
|
+
let claudePrintStyle = "new"; // "new" = --print=<val> | "old" = -p <val>
|
|
576
|
+
|
|
577
|
+
function probeClaude() {
|
|
578
|
+
return new Promise((resolve) => {
|
|
579
|
+
const bin = cfg.claudeBin || "claude";
|
|
580
|
+
const child = spawn(bin, ["--help"], { env: process.env });
|
|
581
|
+
let out = "";
|
|
582
|
+
child.stdout.on("data", (d) => (out += d));
|
|
583
|
+
child.stderr.on("data", (d) => (out += d));
|
|
584
|
+
child.on("close", () => {
|
|
585
|
+
claudePrintStyle = out.includes("--print") ? "new" : "old";
|
|
586
|
+
if (claudePrintStyle === "old")
|
|
587
|
+
console.warn(`[warn] claude CLI does not support --print; falling back to -p (messages starting with '-' may fail)`);
|
|
588
|
+
resolve();
|
|
589
|
+
});
|
|
590
|
+
child.on("error", () => resolve()); // 탐지 실패 시 기본값(new) 유지
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
|
|
573
594
|
// ── Claude 실행 ───────────────────────────────────────────────────────────
|
|
574
595
|
function runClaude(prompt, sessionId, opts = {}) {
|
|
575
596
|
return new Promise((resolve) => {
|
|
597
|
+
const printArgs = claudePrintStyle === "new" ? [`--print=${prompt}`] : ["-p", prompt];
|
|
576
598
|
const args = [
|
|
577
|
-
|
|
578
|
-
prompt,
|
|
599
|
+
...printArgs,
|
|
579
600
|
"--output-format",
|
|
580
601
|
"json",
|
|
581
602
|
"--permission-mode",
|
|
@@ -1264,6 +1285,7 @@ function dispatch(msg) {
|
|
|
1264
1285
|
// ── 롱폴링 루프 ───────────────────────────────────────────────────────────
|
|
1265
1286
|
async function main() {
|
|
1266
1287
|
console.log("Bot started. Polling Telegram...");
|
|
1288
|
+
await probeClaude();
|
|
1267
1289
|
// /restart 로 재시작했으면 완료 알림 1회 (플래그는 즉시 비움)
|
|
1268
1290
|
if (state.restartNotify) {
|
|
1269
1291
|
const to = state.restartNotify;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-telegram-bot",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.29",
|
|
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": {
|