@gonzih/cc-tg 0.3.1 → 0.3.3

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/claude.js CHANGED
@@ -13,7 +13,7 @@ export class ClaudeProcess extends EventEmitter {
13
13
  constructor(opts = {}) {
14
14
  super();
15
15
  const args = [
16
- "--no-session-persistence",
16
+ "--continue",
17
17
  "--output-format", "stream-json",
18
18
  "--input-format", "stream-json",
19
19
  "--print",
package/dist/index.js CHANGED
@@ -14,31 +14,46 @@
14
14
  * GROUP_CHAT_IDS — comma-separated Telegram group/supergroup chat IDs (leave empty to allow all groups)
15
15
  * CWD — working directory for Claude Code (default: process.cwd())
16
16
  */
17
- import { existsSync, writeFileSync, unlinkSync, readFileSync } from "fs";
17
+ import { createServer, createConnection } from "net";
18
+ import { unlinkSync } from "fs";
18
19
  import { tmpdir } from "os";
19
20
  import { join } from "path";
20
21
  import { CcTgBot } from "./bot.js";
21
- const LOCK_FILE = join(tmpdir(), "cc-tg.lock");
22
+ const LOCK_SOCKET = join(tmpdir(), "cc-tg.sock");
22
23
  function acquireLock() {
23
- if (existsSync(LOCK_FILE)) {
24
- try {
25
- const pid = parseInt(readFileSync(LOCK_FILE, "utf8").trim());
26
- process.kill(pid, 0);
27
- console.error(`[cc-tg] Another instance is already running (PID ${pid}). Exiting.`);
28
- return false;
29
- }
30
- catch {
31
- // PID is dead — stale lock, take over
32
- }
33
- }
34
- writeFileSync(LOCK_FILE, String(process.pid));
35
- process.on("exit", () => { try {
36
- unlinkSync(LOCK_FILE);
37
- }
38
- catch { } });
39
- return true;
24
+ return new Promise((resolve) => {
25
+ const server = createServer();
26
+ server.listen(LOCK_SOCKET, () => {
27
+ // Bound successfully — we own the lock. Socket auto-released on any exit incl. SIGKILL.
28
+ resolve(true);
29
+ });
30
+ server.on("error", (err) => {
31
+ if (err.code !== "EADDRINUSE") {
32
+ resolve(true); // unrelated error, proceed
33
+ return;
34
+ }
35
+ // Socket path exists — probe if anything is actually listening
36
+ const probe = createConnection(LOCK_SOCKET);
37
+ probe.on("connect", () => {
38
+ probe.destroy();
39
+ console.error("[cc-tg] Another instance is already running. Exiting.");
40
+ resolve(false);
41
+ });
42
+ probe.on("error", () => {
43
+ // Nothing listening — stale socket, remove and retry
44
+ try {
45
+ unlinkSync(LOCK_SOCKET);
46
+ }
47
+ catch { }
48
+ const retry = createServer();
49
+ retry.listen(LOCK_SOCKET, () => resolve(true));
50
+ retry.on("error", () => resolve(true)); // give up on lock, just start
51
+ });
52
+ });
53
+ });
40
54
  }
41
- if (!acquireLock()) {
55
+ const lockAcquired = await acquireLock();
56
+ if (!lockAcquired) {
42
57
  process.exit(1);
43
58
  }
44
59
  function required(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gonzih/cc-tg",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Claude Code Telegram bot — chat with Claude Code via Telegram",
5
5
  "type": "module",
6
6
  "bin": {