dsh-tg-bridge 1.51.1 → 1.51.2

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/docs/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG — DSH Telegram bridge
2
2
 
3
+ ## 1.51.2
4
+
5
+ - **`say.mjs` sweeps stale markers too.** 1.51.1 taught the bridge to sweep, but
6
+ `say.mjs` runs as its own process and reads the marker folder itself: it does
7
+ not import `turn/active.mjs`, so the sweep never ran on the path that suffers
8
+ from a stale marker — two live markers in one folder is a refusal to place a
9
+ line, and a marker from yesterday is not live. The same rule now lives there,
10
+ with the same 12 h age limit for pid reuse, and it deletes the file it read.
11
+ 1 test.
12
+
3
13
  ## 1.51.1
4
14
 
5
15
  - **Stale turn markers are swept, not left behind.** A marker named a turn that
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-tg-bridge",
3
- "version": "1.51.1",
3
+ "version": "1.51.2",
4
4
  "description": "Drive DeepSeek Harness from Telegram: one project, model and session per forum topic",
5
5
  "type": "module",
6
6
  "main": "plugin-bridge.mjs",
package/say.mjs CHANGED
@@ -19,7 +19,7 @@
19
19
  //
20
20
  // With `--steer` the chat/thread come from the job file and an ack marker is
21
21
  // written, which suppresses the bridge's fallback line.
22
- import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
22
+ import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
23
23
  import { homedir } from 'node:os';
24
24
  import { join } from 'node:path';
25
25
 
@@ -106,9 +106,17 @@ function activeMarker() {
106
106
  if (!name.endsWith('.json')) continue;
107
107
  try {
108
108
  const record = JSON.parse(readFileSync(join(dir, name), 'utf8'));
109
+ // Swept on read, like the bridge does: this file runs after the turn and
110
+ // after the process that wrote the marker may be gone. Two live markers
111
+ // in one folder is a refusal, and a marker from yesterday is not live.
112
+ if (stale(record)) {
113
+ try {
114
+ unlinkSync(join(dir, name));
115
+ } catch {}
116
+ continue;
117
+ }
109
118
  if (!record?.chatId) continue;
110
119
  if (String(record.cwd || '').toLowerCase() !== want) continue;
111
- if (!alive(record.pid)) continue;
112
120
  hits.push(record);
113
121
  } catch {}
114
122
  }
@@ -136,6 +144,22 @@ function alive(pid) {
136
144
  }
137
145
  }
138
146
 
147
+ /**
148
+ * Is this marker from a turn that is over?
149
+ *
150
+ * Same rule as `turn/active.mjs`, and it has to be here too: this file runs as
151
+ * its own process and does not import the bridge's marker code. The age limit
152
+ * exists for pid reuse — Windows hands the same number out again, and a marker
153
+ * from yesterday then looks alive because a browser owns that pid.
154
+ */
155
+ const MAX_TURN_MS = 12 * 60 * 60 * 1000;
156
+
157
+ function stale(record) {
158
+ const at = Number(record?.at || 0);
159
+ if (at > 0 && Date.now() - at > MAX_TURN_MS) return true;
160
+ return !alive(record?.pid);
161
+ }
162
+
139
163
  /**
140
164
  * Send one plain chat line and report the message id, or null.
141
165
  *