dsh-tg-bridge 1.38.7 → 1.38.8
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 +11 -0
- package/package.json +1 -1
- package/say.mjs +44 -11
package/docs/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# CHANGELOG — DSH Telegram bridge
|
|
2
2
|
|
|
3
|
+
## 1.38.8
|
|
4
|
+
|
|
5
|
+
- **A 💭 line is no longer lost when the sandbox forbids the write.** A turn that
|
|
6
|
+
runs in a project folder may have `~/.dsh` outside its writable area: the note
|
|
7
|
+
file refused the append with `EPERM`, `say.mjs --thought` exited 6, and the
|
|
8
|
+
decision never reached the chat. It now falls back to sending the line as a
|
|
9
|
+
real `💭` message — the person sees it, the stderr line says why it did not go
|
|
10
|
+
into the card, and the exit code is a failure only when both paths fail.
|
|
11
|
+
- `DSH_TG_THOUGHTS` overrides the thoughts directory, so the fallback is
|
|
12
|
+
testable without breaking a real installation.
|
|
13
|
+
|
|
3
14
|
## 1.38.7
|
|
4
15
|
|
|
5
16
|
- **The turn card is now a choice, not a wall.** Every turn ends with one card,
|
package/package.json
CHANGED
package/say.mjs
CHANGED
|
@@ -26,7 +26,7 @@ import { join } from 'node:path';
|
|
|
26
26
|
const DSH_HOME = process.env.DSH_HOME || join(homedir(), '.dsh');
|
|
27
27
|
const STEER = join(DSH_HOME, 'tg-bridge', 'steer');
|
|
28
28
|
const ACKS = join(STEER, 'acks');
|
|
29
|
-
const THOUGHTS = join(DSH_HOME, 'tg-bridge', 'thoughts');
|
|
29
|
+
const THOUGHTS = (process.env.DSH_TG_THOUGHTS || '').trim() || join(DSH_HOME, 'tg-bridge', 'thoughts');
|
|
30
30
|
|
|
31
31
|
function findToken() {
|
|
32
32
|
const env = (process.env.DSH_TELEGRAM_BOT_TOKEN || '').trim();
|
|
@@ -85,6 +85,31 @@ function activeThoughtFile() {
|
|
|
85
85
|
return { chatId, threadId: Number(base.slice(cut + 1)) || 0 };
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Send one plain chat line and report the message id, or null.
|
|
90
|
+
*
|
|
91
|
+
* Used by the thought fallback: a 💭 line that cannot be written into the card
|
|
92
|
+
* file still has to arrive somewhere, and a failed send must not look like a
|
|
93
|
+
* successful one.
|
|
94
|
+
*/
|
|
95
|
+
async function sendLine(chatId, threadId, text) {
|
|
96
|
+
const token = findToken();
|
|
97
|
+
if (!token) return null;
|
|
98
|
+
const body = { chat_id: chatId, text, disable_web_page_preview: true };
|
|
99
|
+
if (threadId > 0) body.message_thread_id = threadId;
|
|
100
|
+
try {
|
|
101
|
+
const res = await fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
|
|
102
|
+
method: 'POST',
|
|
103
|
+
headers: { 'content-type': 'application/json' },
|
|
104
|
+
body: JSON.stringify(body),
|
|
105
|
+
});
|
|
106
|
+
const data = await res.json().catch(() => ({}));
|
|
107
|
+
return data.ok ? data.result.message_id : null;
|
|
108
|
+
} catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
88
113
|
async function main() {
|
|
89
114
|
const args = parse(process.argv.slice(2));
|
|
90
115
|
if (!args.text) usage();
|
|
@@ -121,6 +146,11 @@ async function main() {
|
|
|
121
146
|
if (!chatId) usage();
|
|
122
147
|
|
|
123
148
|
if (args.thought) {
|
|
149
|
+
const explicit = (process.env.DSH_TG_THOUGHT || '').trim();
|
|
150
|
+
const own = explicit && explicit.split(/[\\/]/).pop()?.startsWith(`${chatId}_${threadId || 0}_`)
|
|
151
|
+
? explicit
|
|
152
|
+
: '';
|
|
153
|
+
const file = own || join(THOUGHTS, `${chatId}_${threadId || 0}.jsonl`);
|
|
124
154
|
try {
|
|
125
155
|
mkdirSync(THOUGHTS, { recursive: true });
|
|
126
156
|
// The turn's own file when the bridge exported one: two turns in the same
|
|
@@ -128,18 +158,22 @@ async function main() {
|
|
|
128
158
|
// per-topic name stays the fallback for a shell that lost the env, and the
|
|
129
159
|
// panel reads both — so a note never lands in a file nobody reads, which
|
|
130
160
|
// is exactly what made 💭 stay empty while the file on disk kept growing.
|
|
131
|
-
const explicit = (process.env.DSH_TG_THOUGHT || '').trim();
|
|
132
|
-
const own = explicit && explicit.split(/[\\/]/).pop()?.startsWith(`${chatId}_${threadId || 0}_`)
|
|
133
|
-
? explicit
|
|
134
|
-
: '';
|
|
135
|
-
const file = own || join(THOUGHTS, `${chatId}_${threadId || 0}.jsonl`);
|
|
136
161
|
appendFileSync(file, `${JSON.stringify({ at: Date.now(), text: args.text })}\n`, 'utf8');
|
|
137
162
|
console.log(file);
|
|
163
|
+
return;
|
|
138
164
|
} catch (error) {
|
|
139
|
-
|
|
140
|
-
|
|
165
|
+
// A workspace sandbox can forbid writes under ~/.dsh while the turn runs
|
|
166
|
+
// in a project folder. The line must still reach the person: fall back to
|
|
167
|
+
// a real 💭 message and say why, instead of losing the decision silently.
|
|
168
|
+
const why = String(error?.message ?? error).replace(/\s+/g, ' ').slice(0, 120);
|
|
169
|
+
const sent = await sendLine(chatId, threadId, `💭 ${args.text}`);
|
|
170
|
+
if (!sent) {
|
|
171
|
+
console.error(`${why}; and the fallback message did not go through`);
|
|
172
|
+
process.exit(6);
|
|
173
|
+
}
|
|
174
|
+
console.error(`${why}; sent as a 💭 message instead of a card line`);
|
|
175
|
+
return;
|
|
141
176
|
}
|
|
142
|
-
return;
|
|
143
177
|
}
|
|
144
178
|
|
|
145
179
|
const token = findToken();
|
|
@@ -159,8 +193,7 @@ async function main() {
|
|
|
159
193
|
if (!data.ok) {
|
|
160
194
|
console.error(`telegram: ${data.description || res.status}`);
|
|
161
195
|
process.exit(4);
|
|
162
|
-
}
|
|
163
|
-
if (args.steer) {
|
|
196
|
+
} if (args.steer) {
|
|
164
197
|
try {
|
|
165
198
|
mkdirSync(ACKS, { recursive: true });
|
|
166
199
|
writeFileSync(join(ACKS, `${args.steer}.json`), JSON.stringify({ at: Date.now(), messageId: data.result.message_id, job: jobPath }), 'utf8');
|