dsh-tg-bridge 1.50.0 β 1.51.1
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/chat/handle-message.mjs +2 -2
- package/core/paths.mjs +6 -2
- package/docs/CHANGELOG.md +34 -0
- package/package.json +1 -1
- package/say.mjs +7 -3
- package/turn/active.mjs +56 -9
package/chat/handle-message.mjs
CHANGED
|
@@ -22,7 +22,7 @@ import { mediaPrompt } from './media.mjs';
|
|
|
22
22
|
import { keyboardCommand } from './menu-card.mjs';
|
|
23
23
|
import { replyText } from './reply-guard.mjs';
|
|
24
24
|
import { QUIET_MS, quietGuard } from './quiet-guard.mjs';
|
|
25
|
-
import { DIR, GOAL_CMD, THOUGHT_DIR } from '../core/paths.mjs';
|
|
25
|
+
import { DIR, GOAL_CMD, SAY, THOUGHT_DIR } from '../core/paths.mjs';
|
|
26
26
|
import { renderPrices } from '../model/prices.mjs';
|
|
27
27
|
import { settingsChipOf, turnPlan } from '../profile/profile-view.mjs';
|
|
28
28
|
import { startProgress } from '../turn/progress.mjs';
|
|
@@ -341,7 +341,7 @@ ${helpLines((k, vars) => t(lang, k, vars)).join('\n')}`,
|
|
|
341
341
|
// differently when it lands in the chat as a message of its own.
|
|
342
342
|
const notesMode = reasoningMode(state, config, key);
|
|
343
343
|
if (notesMode !== 'off') {
|
|
344
|
-
const prompt = t(lang, 'prompt.reasoning', { say:
|
|
344
|
+
const prompt = t(lang, 'prompt.reasoning', { say: SAY });
|
|
345
345
|
const note = notesMode === 'chat' ? `\n\n${t(lang, 'prompt.reasoningChat')}` : '';
|
|
346
346
|
text = `${prompt}${note}\n\n---\n\n${text}`;
|
|
347
347
|
}
|
package/core/paths.mjs
CHANGED
|
@@ -26,8 +26,12 @@ export const PENDING_DIR = join(DIR, 'pending');
|
|
|
26
26
|
export const STEER_DIR = join(DIR, 'steer');
|
|
27
27
|
export const THOUGHT_DIR = join(DIR, 'thoughts');
|
|
28
28
|
// The helper the agent calls to confirm an addition in the chat while the turn
|
|
29
|
-
// is still running. Lives next to the bridge
|
|
30
|
-
|
|
29
|
+
// is still running. Lives next to the bridge's code, like GOAL_CMD above: a
|
|
30
|
+
// second instance keeps its state in DSH_TG_HOME, and pointing at DIR there
|
|
31
|
+
// named a file that does not exist β the agent's first π line failed with
|
|
32
|
+
// MODULE_NOT_FOUND, and the turn went off to repair the bridge instead of
|
|
33
|
+
// answering the person.
|
|
34
|
+
export const SAY = join(SELF_DIR, 'say.mjs');
|
|
31
35
|
export const DONE_FILE = join(DIR, 'done.json');
|
|
32
36
|
export const RESTART_MARKER = join(DIR, 'restart.pending');
|
|
33
37
|
// `/restart confirm` leaves a note here for the process that replaces it: the
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# CHANGELOG β DSH Telegram bridge
|
|
2
2
|
|
|
3
|
+
## 1.51.1
|
|
4
|
+
|
|
5
|
+
- **Stale turn markers are swept, not left behind.** A marker named a turn that
|
|
6
|
+
was over, and `say.mjs` reads two live markers in one folder as ambiguous and
|
|
7
|
+
refuses to place a line. The old check ran only for the folder that asked, so
|
|
8
|
+
a marker left by a turn in another folder stayed forever; and a marker whose
|
|
9
|
+
pid Windows had handed to some other process looked alive, because the only
|
|
10
|
+
test was `process.kill(pid, 0)`. Eight such markers had piled up in one bot's
|
|
11
|
+
folder before anyone looked. `sweep()` now runs on every marker write and
|
|
12
|
+
every read, drops a marker whose process is gone or whose file is older than
|
|
13
|
+
any turn could be (12 h β the age limit exists for pid reuse, not for long
|
|
14
|
+
turns), and deletes the file it read rather than the file its pid names: the
|
|
15
|
+
two are the same until one of them is wrong, and then a sweep would take a
|
|
16
|
+
live turn with it. 4 tests.
|
|
17
|
+
|
|
18
|
+
## 1.51.0
|
|
19
|
+
|
|
20
|
+
- **A second instance keeps its own π lines, markers and steer files.**
|
|
21
|
+
`DSH_TG_HOME` already moved the state folder, but four paths were still built
|
|
22
|
+
from `~/.dsh/tg-bridge`. The turn preamble named the agent
|
|
23
|
+
`<state>/say.mjs` β `chat/handle-message.mjs` built the path from `DIR`
|
|
24
|
+
instead of the `SAY` that `core/paths.mjs` already exported β so a second
|
|
25
|
+
instance's very first step failed with `MODULE_NOT_FOUND`, and a turn asked
|
|
26
|
+
to greet a person went off to repair the bridge instead of answering: the
|
|
27
|
+
word "ΠΡΠΈΠ²Π΅Ρ" cost nine tool calls and two minutes. `say.mjs` itself took its
|
|
28
|
+
`active/`, `thoughts/` and `steer/` folders from `~/.dsh/tg-bridge` whatever
|
|
29
|
+
the instance was, so the adviser bot's lines landed in the first bot's
|
|
30
|
+
thoughts folder β a file nobody reads, and the card stayed empty. And two
|
|
31
|
+
bots running turns in the same folder both wrote a marker into one shared
|
|
32
|
+
`active/` folder, which `say.mjs` reads as "more than one live turn here" and
|
|
33
|
+
refuses to place a line at all. Markers now live under `DIR`, `say.mjs` takes
|
|
34
|
+
its folders from `DSH_TG_HOME`, and `SAY` is built from `SELF_DIR` the way
|
|
35
|
+
`GOAL_CMD` already was. A single instance behaves exactly as before. 2 tests.
|
|
36
|
+
|
|
3
37
|
## 1.50.0
|
|
4
38
|
|
|
5
39
|
- **β» β the last answer, asked again.** Every finished turn's card now opens a
|
package/package.json
CHANGED
package/say.mjs
CHANGED
|
@@ -24,9 +24,13 @@ import { homedir } from 'node:os';
|
|
|
24
24
|
import { join } from 'node:path';
|
|
25
25
|
|
|
26
26
|
const DSH_HOME = process.env.DSH_HOME || join(homedir(), '.dsh');
|
|
27
|
-
|
|
27
|
+
// A second bridge instance keeps its state in its own folder (`DSH_TG_HOME`,
|
|
28
|
+
// see core/paths.mjs). Without this the adviser's π lines landed in the first
|
|
29
|
+
// bot's thoughts folder β a file nobody reads, so the card stayed empty.
|
|
30
|
+
const TG_DIR = (process.env.DSH_TG_HOME || '').trim() || join(DSH_HOME, 'tg-bridge');
|
|
31
|
+
const STEER = join(TG_DIR, 'steer');
|
|
28
32
|
const ACKS = join(STEER, 'acks');
|
|
29
|
-
const THOUGHTS = (process.env.DSH_TG_THOUGHTS || '').trim() || join(
|
|
33
|
+
const THOUGHTS = (process.env.DSH_TG_THOUGHTS || '').trim() || join(TG_DIR, 'thoughts');
|
|
30
34
|
|
|
31
35
|
function findToken() {
|
|
32
36
|
const env = (process.env.DSH_TELEGRAM_BOT_TOKEN || '').trim();
|
|
@@ -95,7 +99,7 @@ function activeThoughtFile() {
|
|
|
95
99
|
*/
|
|
96
100
|
function activeMarker() {
|
|
97
101
|
try {
|
|
98
|
-
const dir = join(
|
|
102
|
+
const dir = join(TG_DIR, 'active');
|
|
99
103
|
const want = process.cwd().toLowerCase();
|
|
100
104
|
const hits = [];
|
|
101
105
|
for (const name of readdirSync(dir)) {
|
package/turn/active.mjs
CHANGED
|
@@ -12,11 +12,18 @@
|
|
|
12
12
|
// zero or two match: an ambiguous answer is the one thing worse than none.
|
|
13
13
|
import { mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
14
14
|
import { join } from 'node:path';
|
|
15
|
-
import {
|
|
15
|
+
import { DIR } from '../core/paths.mjs';
|
|
16
16
|
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Where the markers live: next to the thoughts they name.
|
|
19
|
+
*
|
|
20
|
+
* Under `DIR`, not a fixed `~/.dsh/tg-bridge`: a second bridge instance (the
|
|
21
|
+
* adviser bot) has its own state folder, and both bots run turns in the same
|
|
22
|
+
* workspace. Sharing one marker folder made each of them see two live turns in
|
|
23
|
+
* that folder and refuse to place a π line at all.
|
|
24
|
+
*/
|
|
18
25
|
export function activeDir() {
|
|
19
|
-
return join(
|
|
26
|
+
return join(DIR, 'active');
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
/**
|
|
@@ -28,6 +35,7 @@ export function activeDir() {
|
|
|
28
35
|
export function markActive({ pid, key, chatId, threadId, cwd, thought }) {
|
|
29
36
|
try {
|
|
30
37
|
mkdirSync(activeDir(), { recursive: true });
|
|
38
|
+
sweep();
|
|
31
39
|
const path = join(activeDir(), `${pid}.json`);
|
|
32
40
|
const record = {
|
|
33
41
|
pid,
|
|
@@ -55,12 +63,14 @@ export function clearActive(pid) {
|
|
|
55
63
|
/**
|
|
56
64
|
* Live markers for one folder, ignoring files whose process is gone.
|
|
57
65
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
66
|
+
* The whole folder is swept first, not just the entries this folder would use:
|
|
67
|
+
* a marker from another folder is still a marker nobody clears. Eight of them
|
|
68
|
+
* had piled up in one bot's folder before anyone looked.
|
|
60
69
|
*/
|
|
61
70
|
export function activeTargets(cwd) {
|
|
62
71
|
const want = String(cwd || '').trim().toLowerCase();
|
|
63
72
|
if (!want) return [];
|
|
73
|
+
sweep();
|
|
64
74
|
let names = [];
|
|
65
75
|
try {
|
|
66
76
|
names = readdirSync(activeDir()).filter((name) => name.endsWith('.json'));
|
|
@@ -73,16 +83,53 @@ export function activeTargets(cwd) {
|
|
|
73
83
|
const record = JSON.parse(readFileSync(join(activeDir(), name), 'utf8'));
|
|
74
84
|
if (!record?.chatId) continue;
|
|
75
85
|
if (String(record.cwd || '').trim().toLowerCase() !== want) continue;
|
|
76
|
-
if (!alive(record.pid)) {
|
|
77
|
-
clearActive(record.pid);
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
86
|
found.push(record);
|
|
81
87
|
} catch {}
|
|
82
88
|
}
|
|
83
89
|
return found;
|
|
84
90
|
}
|
|
85
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Drop every marker whose turn is over. A handful of small files, so: on read.
|
|
94
|
+
*
|
|
95
|
+
* Deletes the file it read, not the file its pid names: the two are the same
|
|
96
|
+
* until one of them is wrong, and then the sweep would take a live turn with it.
|
|
97
|
+
*/
|
|
98
|
+
export function sweep() {
|
|
99
|
+
let names = [];
|
|
100
|
+
try {
|
|
101
|
+
names = readdirSync(activeDir()).filter((name) => name.endsWith('.json'));
|
|
102
|
+
} catch {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
for (const name of names) {
|
|
106
|
+
let record = null;
|
|
107
|
+
try {
|
|
108
|
+
record = JSON.parse(readFileSync(join(activeDir(), name), 'utf8'));
|
|
109
|
+
} catch {}
|
|
110
|
+
if (record && !stale(record)) continue;
|
|
111
|
+
try {
|
|
112
|
+
rmSync(join(activeDir(), name), { force: true });
|
|
113
|
+
} catch {}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Is this marker from a turn that is over?
|
|
119
|
+
*
|
|
120
|
+
* Two ways to be over: the process is gone, or the file is older than any turn
|
|
121
|
+
* could be. The age limit is not about long turns β it is about pid reuse.
|
|
122
|
+
* Windows hands the same number out again, and a marker from yesterday then
|
|
123
|
+
* looks alive because a browser now owns that pid.
|
|
124
|
+
*/
|
|
125
|
+
const MAX_TURN_MS = 12 * 60 * 60 * 1000;
|
|
126
|
+
|
|
127
|
+
function stale(record) {
|
|
128
|
+
const at = Number(record?.at || 0);
|
|
129
|
+
if (at > 0 && Date.now() - at > MAX_TURN_MS) return true;
|
|
130
|
+
return !alive(record?.pid);
|
|
131
|
+
}
|
|
132
|
+
|
|
86
133
|
/** Is that process still there? A shell cannot see a child it did not start. */
|
|
87
134
|
function alive(pid) {
|
|
88
135
|
const id = Number(pid);
|