dsh-ssh-tui 0.7.2 → 0.7.4
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/README.en.md +113 -27
- package/README.md +90 -27
- package/cordis.patch.yml +15 -0
- package/docs/remote-ops.md +27 -1
- package/docs/terminals.md +126 -0
- package/docs/windows.md +128 -0
- package/lib/attach.js +14 -1
- package/lib/attach.js.map +1 -1
- package/lib/commands.js +1 -0
- package/lib/commands.js.map +1 -1
- package/lib/copy-text.js +2 -0
- package/lib/copy-text.js.map +1 -1
- package/lib/diag.js +38 -0
- package/lib/diag.js.map +1 -1
- package/lib/dialogs.js.map +1 -1
- package/lib/display-sock.js +572 -44
- package/lib/display-sock.js.map +1 -1
- package/lib/doctor.js +71 -37
- package/lib/doctor.js.map +1 -1
- package/lib/dsh-compat.js +252 -88
- package/lib/dsh-compat.js.map +1 -1
- package/lib/footer.js +4 -2
- package/lib/footer.js.map +1 -1
- package/lib/i18n/en.js +54 -10
- package/lib/i18n/en.js.map +1 -1
- package/lib/i18n/index.js +18 -7
- package/lib/i18n/index.js.map +1 -1
- package/lib/i18n/zh.js +54 -10
- package/lib/i18n/zh.js.map +1 -1
- package/lib/index.js +111 -26
- package/lib/index.js.map +1 -1
- package/lib/line-mode.js +4 -0
- package/lib/line-mode.js.map +1 -1
- package/lib/paint.js +37 -3
- package/lib/paint.js.map +1 -1
- package/lib/picker.js +109 -18
- package/lib/picker.js.map +1 -1
- package/lib/plan.js +8 -0
- package/lib/plan.js.map +1 -1
- package/lib/platform.js +377 -11
- package/lib/platform.js.map +1 -1
- package/lib/preset-authoring.js +10 -14
- package/lib/preset-authoring.js.map +1 -1
- package/lib/preset-compat.js +100 -0
- package/lib/preset-compat.js.map +1 -0
- package/lib/preset-picker.js +5 -1
- package/lib/preset-picker.js.map +1 -1
- package/lib/preset-rows.js +119 -19
- package/lib/preset-rows.js.map +1 -1
- package/lib/provider-catalog.js +4 -4
- package/lib/question-wait.js +418 -0
- package/lib/question-wait.js.map +1 -0
- package/lib/route-memory.js +3 -3
- package/lib/route-memory.js.map +1 -1
- package/lib/selection.js +26 -8
- package/lib/selection.js.map +1 -1
- package/lib/session-index.js +5 -0
- package/lib/session-index.js.map +1 -1
- package/lib/session-lock.js +4 -1
- package/lib/session-lock.js.map +1 -1
- package/lib/session-route.js +3 -0
- package/lib/session-route.js.map +1 -1
- package/lib/settings-routes.js +10 -0
- package/lib/settings-routes.js.map +1 -0
- package/lib/settings-subagent.js +10 -0
- package/lib/settings-subagent.js.map +1 -0
- package/lib/subagent-model.js +5 -5
- package/lib/subagent-model.js.map +1 -1
- package/lib/supergrok-token.js +4 -0
- package/lib/supergrok-token.js.map +1 -1
- package/lib/term-text.js +79 -8
- package/lib/term-text.js.map +1 -1
- package/lib/terminal-caps.js +358 -0
- package/lib/terminal-caps.js.map +1 -0
- package/lib/terminal-input.js +13 -0
- package/lib/terminal-input.js.map +1 -1
- package/lib/tui.js +775 -165
- package/lib/tui.js.map +1 -1
- package/lib/types/attach.d.ts +8 -0
- package/lib/types/commands.d.ts +3 -0
- package/lib/types/diag.d.ts +20 -1
- package/lib/types/dialogs.d.ts +16 -0
- package/lib/types/display-sock.d.ts +141 -24
- package/lib/types/doctor.d.ts +8 -1
- package/lib/types/dsh-compat.d.ts +173 -44
- package/lib/types/footer.d.ts +3 -1
- package/lib/types/i18n/index.d.ts +31 -15
- package/lib/types/index.d.ts +45 -0
- package/lib/types/paint.d.ts +21 -0
- package/lib/types/picker.d.ts +25 -0
- package/lib/types/platform.d.ts +197 -10
- package/lib/types/preset-authoring.d.ts +8 -14
- package/lib/types/preset-compat.d.ts +58 -0
- package/lib/types/preset-picker.d.ts +1 -1
- package/lib/types/preset-rows.d.ts +63 -13
- package/lib/types/question-wait.d.ts +221 -0
- package/lib/types/selection.d.ts +12 -4
- package/lib/types/settings-routes.d.ts +16 -0
- package/lib/types/settings-subagent.d.ts +24 -0
- package/lib/types/subagent-model.d.ts +10 -10
- package/lib/types/term-text.d.ts +14 -0
- package/lib/types/terminal-caps.d.ts +105 -0
- package/lib/types/terminal-input.d.ts +10 -0
- package/lib/types/transcript-types.d.ts +22 -0
- package/lib/types/tui.d.ts +167 -10
- package/lib/types/update-check.d.ts +19 -4
- package/lib/types/workspace-changes.d.ts +135 -0
- package/lib/update-check.js +25 -8
- package/lib/update-check.js.map +1 -1
- package/lib/workspace-changes.js +120 -0
- package/lib/workspace-changes.js.map +1 -0
- package/package.json +124 -59
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a question does while nobody is attached to answer it.
|
|
3
|
+
*
|
|
4
|
+
* A dropped SSH link leaves the question queued in memory, and the only trace of
|
|
5
|
+
* it used to be a transcript line written *after* the user reconnected — which is
|
|
6
|
+
* how a turn spent waiting for an answer went unnoticed until then. Two signals
|
|
7
|
+
* exist before that:
|
|
8
|
+
*
|
|
9
|
+
* - a marker file under `$DSH_HOME/tui-socks/`, so logging back into the jump
|
|
10
|
+
* host shows a session waiting on an answer before the TUI is even open;
|
|
11
|
+
* - one command the user configured, run once, carrying the question in its
|
|
12
|
+
* environment. Mail and WeCom are presets of that command rather than clients
|
|
13
|
+
* of their own: a jump host has whichever of them it already has, and neither
|
|
14
|
+
* belongs in this plugin's dependency tree.
|
|
15
|
+
* @module dsh-ssh-tui/question-wait
|
|
16
|
+
*/
|
|
17
|
+
import { spawn } from 'node:child_process';
|
|
18
|
+
import { mkdir, unlink, writeFile } from 'node:fs/promises';
|
|
19
|
+
import { basename, dirname, join } from 'node:path';
|
|
20
|
+
import { sessionErrPath, sessionSockDir } from './display-sock.js';
|
|
21
|
+
import { t } from './i18n/index.js';
|
|
22
|
+
import { restrictPathToUser } from './platform.js';
|
|
23
|
+
/** How long a notify command may run before it is killed. It must not stall the turn. */
|
|
24
|
+
const NOTIFY_TIMEOUT_MS = 10_000;
|
|
25
|
+
/**
|
|
26
|
+
* The marker for one session.
|
|
27
|
+
*
|
|
28
|
+
* Beside the session's stderr log, under the same digested label, so a long id
|
|
29
|
+
* stays inside a Windows path and two ids that sanitize to the same stem do not
|
|
30
|
+
* share a file. `.waiting` rather than a dotfile: the point is that `ls` shows it.
|
|
31
|
+
* @param sessionId - the session that is waiting.
|
|
32
|
+
* @param dshHome - the harness home; defaults to the process one.
|
|
33
|
+
* @returns the marker path.
|
|
34
|
+
*/
|
|
35
|
+
export function waitingMarkerPath(sessionId, dshHome) {
|
|
36
|
+
const dir = dshHome === undefined ? sessionSockDir() : sessionSockDir(dshHome);
|
|
37
|
+
const err = dshHome === undefined ? sessionErrPath(sessionId) : sessionErrPath(sessionId, dshHome);
|
|
38
|
+
// The stderr log's own stem, so the marker can never drift onto a name that
|
|
39
|
+
// log does not already occupy. `basename` and `join` carry the separators of
|
|
40
|
+
// the running platform, so the marker is a real sibling on Windows too rather
|
|
41
|
+
// than a mixed `\\dir/name` — which is what hand-splitting on `/` produced.
|
|
42
|
+
return join(dir, `${basename(err, '.err')}.waiting`);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Write the marker, replacing one already there.
|
|
46
|
+
*
|
|
47
|
+
* The question text is the only sensitive part, so the file is owner-only. A
|
|
48
|
+
* failure to write is reported as `false` and never thrown: the question is
|
|
49
|
+
* still queued, and a marker is not worth failing it over.
|
|
50
|
+
*
|
|
51
|
+
* Deliberately a plain `writeFile`, not a staged sibling renamed into place.
|
|
52
|
+
* The rename is atomic on POSIX, but Windows refuses to replace a file another
|
|
53
|
+
* process has open — and the whole point of this marker is that something else
|
|
54
|
+
* polls it (a jump-host `cat` in a loop), so the "atomic" version stops updating
|
|
55
|
+
* exactly while it is being read. The cost of the plain write is a window
|
|
56
|
+
* between the create and the first byte where a reader sees an empty file; the
|
|
57
|
+
* marker is rewritten on every change, so that window is what a consumer has to
|
|
58
|
+
* tolerate rather than something the writer can hide.
|
|
59
|
+
* @param question - the question that just started waiting.
|
|
60
|
+
* @param dshHome - the harness home; defaults to the process one.
|
|
61
|
+
* @returns whether the marker is on disk.
|
|
62
|
+
*/
|
|
63
|
+
export async function writeWaitingMarker(question, dshHome) {
|
|
64
|
+
const path = waitingMarkerPath(question.sessionId, dshHome);
|
|
65
|
+
const body = [
|
|
66
|
+
`session=${question.sessionId}`,
|
|
67
|
+
`waiting=${question.count}`,
|
|
68
|
+
`since=${new Date(question.since).toISOString()}`,
|
|
69
|
+
`question=${question.question.replaceAll('\n', ' ')}`,
|
|
70
|
+
'',
|
|
71
|
+
].join('\n');
|
|
72
|
+
try {
|
|
73
|
+
await mkdir(dirname(path), { recursive: true });
|
|
74
|
+
await restrictPathToUser(dirname(path), { mode: 0o700, directory: true });
|
|
75
|
+
await writeFile(path, body, { mode: 0o600 });
|
|
76
|
+
await restrictPathToUser(path, { mode: 0o600 });
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Remove the marker. Missing is fine: the question may have been answered, or
|
|
85
|
+
* the marker may never have been written.
|
|
86
|
+
* @param sessionId - the session whose wait ended.
|
|
87
|
+
* @param dshHome - the harness home; defaults to the process one.
|
|
88
|
+
*/
|
|
89
|
+
export async function clearWaitingMarker(sessionId, dshHome) {
|
|
90
|
+
try {
|
|
91
|
+
await unlink(waitingMarkerPath(sessionId, dshHome));
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// Already gone, or never written.
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The command to run when a question starts waiting, if the user configured one.
|
|
99
|
+
*
|
|
100
|
+
* The environment wins over settings, the same order `/disconnect` uses, so a
|
|
101
|
+
* one-off invocation can point somewhere else without editing the profile.
|
|
102
|
+
* Empty and whitespace are "not configured".
|
|
103
|
+
* @param env - the process environment.
|
|
104
|
+
* @param saved - the `ssh-tui.notify` value, when settings has one.
|
|
105
|
+
* @returns the command, or undefined when notifications are off.
|
|
106
|
+
*/
|
|
107
|
+
export function notifyCommand(env = process.env, saved) {
|
|
108
|
+
const fromEnv = (env.DSH_TUI_NOTIFY ?? '').trim();
|
|
109
|
+
if (fromEnv !== '')
|
|
110
|
+
return fromEnv;
|
|
111
|
+
const fromSaved = (saved ?? '').trim();
|
|
112
|
+
return fromSaved === '' ? undefined : fromSaved;
|
|
113
|
+
}
|
|
114
|
+
const SMTP_PORT_DEFAULT = 587;
|
|
115
|
+
const LOCAL_PORT_DEFAULT = 25;
|
|
116
|
+
/**
|
|
117
|
+
* Parse one `/notify` argument into a target.
|
|
118
|
+
*
|
|
119
|
+
* Four shapes, deliberately small:
|
|
120
|
+
*
|
|
121
|
+
* - empty, `off`, `none` — turn it off;
|
|
122
|
+
* - `mail you@example.com` — the local mailer;
|
|
123
|
+
* - `smtp host[:port] from to [user [password]]` — an SMTP server, port 587
|
|
124
|
+
* when omitted, authenticated only when a user is given;
|
|
125
|
+
* - `local [port] from to` — the machine's own mailer on 25, or another port.
|
|
126
|
+
*
|
|
127
|
+
* @param raw - everything after `/notify`.
|
|
128
|
+
* @returns the target, or undefined when the shape is not one of those.
|
|
129
|
+
*/
|
|
130
|
+
export function parseNotifyTarget(raw) {
|
|
131
|
+
const parts = raw.trim().split(/\s+/u).filter(part => part !== '');
|
|
132
|
+
if (parts.length === 0)
|
|
133
|
+
return { kind: 'off' };
|
|
134
|
+
const head = (parts[0] ?? '').toLowerCase();
|
|
135
|
+
if (head === 'off' || head === 'none')
|
|
136
|
+
return parts.length === 1 ? { kind: 'off' } : undefined;
|
|
137
|
+
if (head === 'mail') {
|
|
138
|
+
const address = parts[1];
|
|
139
|
+
if (parts.length !== 2 || address === undefined || !address.includes('@'))
|
|
140
|
+
return undefined;
|
|
141
|
+
return { kind: 'mail', address };
|
|
142
|
+
}
|
|
143
|
+
if (head === 'smtp')
|
|
144
|
+
return parseSmtpTarget(parts.slice(1));
|
|
145
|
+
if (head === 'local')
|
|
146
|
+
return parseLocalTarget(parts.slice(1));
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
/** `host[:port] from to [user [password]]`, port defaulting to submission. */
|
|
150
|
+
function parseSmtpTarget(parts) {
|
|
151
|
+
const server = splitHostPort(parts[0] ?? '', SMTP_PORT_DEFAULT);
|
|
152
|
+
const from = parts[1];
|
|
153
|
+
const to = parts[2];
|
|
154
|
+
if (server === undefined || from === undefined || to === undefined)
|
|
155
|
+
return undefined;
|
|
156
|
+
if (!from.includes('@') || !to.includes('@'))
|
|
157
|
+
return undefined;
|
|
158
|
+
if (parts.length > 5)
|
|
159
|
+
return undefined;
|
|
160
|
+
const user = parts[3];
|
|
161
|
+
const password = parts[4];
|
|
162
|
+
return {
|
|
163
|
+
kind: 'smtp',
|
|
164
|
+
host: server.host,
|
|
165
|
+
port: server.port,
|
|
166
|
+
from,
|
|
167
|
+
to,
|
|
168
|
+
...(user === undefined ? {} : { user }),
|
|
169
|
+
...(password === undefined ? {} : { password }),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/** `[port] from to`, the port defaulting to 25. */
|
|
173
|
+
function parseLocalTarget(parts) {
|
|
174
|
+
const leadingPort = parts.length === 3 && /^\d{1,5}$/u.test(parts[0] ?? '');
|
|
175
|
+
const port = leadingPort ? Number(parts[0]) : LOCAL_PORT_DEFAULT;
|
|
176
|
+
const from = parts[leadingPort ? 1 : 0];
|
|
177
|
+
const to = parts[leadingPort ? 2 : 1];
|
|
178
|
+
if (parts.length !== (leadingPort ? 3 : 2))
|
|
179
|
+
return undefined;
|
|
180
|
+
if (from === undefined || to === undefined || !from.includes('@') || !to.includes('@'))
|
|
181
|
+
return undefined;
|
|
182
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
183
|
+
return undefined;
|
|
184
|
+
return { kind: 'local', port, from, to };
|
|
185
|
+
}
|
|
186
|
+
/** `host`, `host:587`, or `[::1]:25`. */
|
|
187
|
+
function splitHostPort(text, fallback) {
|
|
188
|
+
const trimmed = text.trim();
|
|
189
|
+
if (trimmed === '')
|
|
190
|
+
return undefined;
|
|
191
|
+
const bracketed = /^\[([^\]]+)\](?::(\d{1,5}))?$/u.exec(trimmed);
|
|
192
|
+
if (bracketed !== null) {
|
|
193
|
+
const port = bracketed[2] === undefined ? fallback : Number(bracketed[2]);
|
|
194
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
195
|
+
return undefined;
|
|
196
|
+
return { host: bracketed[1] ?? '', port };
|
|
197
|
+
}
|
|
198
|
+
const colon = trimmed.lastIndexOf(':');
|
|
199
|
+
if (colon > 0 && /^\d{1,5}$/u.test(trimmed.slice(colon + 1))) {
|
|
200
|
+
const port = Number(trimmed.slice(colon + 1));
|
|
201
|
+
if (port < 1 || port > 65535)
|
|
202
|
+
return undefined;
|
|
203
|
+
return { host: trimmed.slice(0, colon), port };
|
|
204
|
+
}
|
|
205
|
+
return { host: trimmed, port: fallback };
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The shell command one target runs.
|
|
209
|
+
*
|
|
210
|
+
* SMTP and the local mailer both go through Python's stdlib `smtplib`, which
|
|
211
|
+
* is present on every jump host this plugin runs on (Node itself is). The
|
|
212
|
+
* password, when there is one, is read from `DSH_TUI_NOTIFY_SMTP_PASSWORD` at
|
|
213
|
+
* send time rather than written into the command, so it never lands in the
|
|
214
|
+
* settings file or the process list. The message text arrives on stdin.
|
|
215
|
+
* @param target - a parsed target other than `off`.
|
|
216
|
+
* @returns the command `/notify` stores.
|
|
217
|
+
*/
|
|
218
|
+
/**
|
|
219
|
+
* What `/notify` confirms back: the target in the user's own words, without the
|
|
220
|
+
* password.
|
|
221
|
+
* @param target - a parsed target other than `off`.
|
|
222
|
+
* @returns a short label.
|
|
223
|
+
*/
|
|
224
|
+
export function notifyTargetLabel(target) {
|
|
225
|
+
if (target.kind === 'mail')
|
|
226
|
+
return `mail ${target.address}`;
|
|
227
|
+
if (target.kind === 'local')
|
|
228
|
+
return `127.0.0.1:${target.port} → ${target.to}`;
|
|
229
|
+
const auth = target.user === undefined ? '' : ` (${target.user})`;
|
|
230
|
+
return `${target.host}:${target.port}${auth} → ${target.to}`;
|
|
231
|
+
}
|
|
232
|
+
export function notifyTargetCommand(target) {
|
|
233
|
+
if (target.kind === 'mail')
|
|
234
|
+
return mailNotifyCommand(target.address);
|
|
235
|
+
const host = target.kind === 'local' ? '127.0.0.1' : target.host;
|
|
236
|
+
return `python3 -c ${shellWord(smtpBridge(target.kind === 'smtp'))} ${shellWord(host)} ${String(target.port)} ${shellWord(target.from)} ${shellWord(target.to)}`;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* The Python that reads the notice on stdin and hands it to `smtplib`.
|
|
240
|
+
*
|
|
241
|
+
* One script for both targets: the local mailer is the same call with no login.
|
|
242
|
+
* Authentication happens only when the environment holds a password, so a
|
|
243
|
+
* server that accepts unauthenticated submission needs nothing else.
|
|
244
|
+
* @param authenticated - whether this target may log in.
|
|
245
|
+
* @returns the script, with no host-specific data in it.
|
|
246
|
+
*/
|
|
247
|
+
function smtpBridge(authenticated) {
|
|
248
|
+
const login = authenticated
|
|
249
|
+
? [
|
|
250
|
+
' user=os.environ.get("DSH_TUI_NOTIFY_SMTP_USER","")',
|
|
251
|
+
' password=os.environ.get("DSH_TUI_NOTIFY_SMTP_PASSWORD","")',
|
|
252
|
+
' if user and password:',
|
|
253
|
+
' try:',
|
|
254
|
+
' s.login(user,password)',
|
|
255
|
+
' except smtplib.SMTPNotSupportedError:',
|
|
256
|
+
' pass',
|
|
257
|
+
].join('\n')
|
|
258
|
+
: '';
|
|
259
|
+
return [
|
|
260
|
+
'import os,smtplib,sys',
|
|
261
|
+
'host,port,sender,recipient=sys.argv[1],int(sys.argv[2]),sys.argv[3],sys.argv[4]',
|
|
262
|
+
'body=sys.stdin.read()',
|
|
263
|
+
'subject=os.environ.get("DSH_TUI_NOTIFY_SUBJECT","dsh")',
|
|
264
|
+
'msg="Subject: "+subject+"\\r\\nContent-Type: text/plain; charset=utf-8\\r\\n\\r\\n"+body',
|
|
265
|
+
's=smtplib.SMTP(host,port,timeout=10)',
|
|
266
|
+
'try:',
|
|
267
|
+
login.trimEnd(),
|
|
268
|
+
' s.sendmail(sender,[recipient],msg.encode("utf-8"))',
|
|
269
|
+
'finally:',
|
|
270
|
+
' s.quit()',
|
|
271
|
+
].filter(line => line !== '').join('\n');
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* A mail command for an address, using whichever sender the host has.
|
|
275
|
+
*
|
|
276
|
+
* `mail` (or `mailx`) is on most jump hosts and speaks SMTP for them; no
|
|
277
|
+
* provider, token, or library joins this plugin. The body arrives on stdin, so
|
|
278
|
+
* the question text is never a shell argument.
|
|
279
|
+
* @param address - where the mail goes.
|
|
280
|
+
* @returns the command.
|
|
281
|
+
*/
|
|
282
|
+
export function mailNotifyCommand(address) {
|
|
283
|
+
return `mail -s ${shellWord(t('notify.mailSubject'))} -- ${shellWord(address)}`;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* A WeCom group-robot command for one webhook key.
|
|
287
|
+
*
|
|
288
|
+
* The payload is assembled by the caller and sent with `curl`, which a jump
|
|
289
|
+
* host already has. The key is the only secret, and it stays in the command the
|
|
290
|
+
* user configured rather than in this repo.
|
|
291
|
+
* @param key - the robot's webhook key.
|
|
292
|
+
* @returns the command.
|
|
293
|
+
*/
|
|
294
|
+
export function wecomNotifyCommand(key) {
|
|
295
|
+
const endpoint = `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${encodeURIComponent(key)}`;
|
|
296
|
+
return `curl -fsS -m 10 -X POST -H "Content-Type: application/json" --data-binary @- ${shellWord(endpoint)}`;
|
|
297
|
+
}
|
|
298
|
+
/** One single-quoted shell word, so an address or URL survives the command line. */
|
|
299
|
+
function shellWord(value) {
|
|
300
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* The text a notification shows. Short on purpose: a mail subject and a WeCom
|
|
304
|
+
* message both get truncated by their carrier, so the resume command has to fit.
|
|
305
|
+
* @param context - the question being announced.
|
|
306
|
+
* @returns the message, one fact per line.
|
|
307
|
+
*/
|
|
308
|
+
export function notifyMessage(context) {
|
|
309
|
+
return [
|
|
310
|
+
t('notify.body', {
|
|
311
|
+
session: context.sessionId,
|
|
312
|
+
count: context.count,
|
|
313
|
+
waited: formatWaited(context.waitedMs),
|
|
314
|
+
}),
|
|
315
|
+
context.question,
|
|
316
|
+
t('notify.resume', { command: context.resumeCommand }),
|
|
317
|
+
].join('\n');
|
|
318
|
+
}
|
|
319
|
+
/** `45s`, `3m`, `2h` — coarse, since the carrier will not show seconds anyway. */
|
|
320
|
+
function formatWaited(ms) {
|
|
321
|
+
const seconds = Math.max(0, Math.round(ms / 1000));
|
|
322
|
+
if (seconds < 60)
|
|
323
|
+
return `${seconds}s`;
|
|
324
|
+
const minutes = Math.round(seconds / 60);
|
|
325
|
+
if (minutes < 60)
|
|
326
|
+
return `${minutes}m`;
|
|
327
|
+
return `${Math.round(minutes / 60)}h`;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* The body a WeCom robot expects: a text message whose content is the notice.
|
|
331
|
+
* @param context - the question being announced.
|
|
332
|
+
* @returns JSON.
|
|
333
|
+
*/
|
|
334
|
+
export function wecomPayload(context) {
|
|
335
|
+
return JSON.stringify({ msgtype: 'text', text: { content: notifyMessage(context) } });
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Run the user's notify command once.
|
|
339
|
+
*
|
|
340
|
+
* The message goes to stdin and the facts go to the environment, so a command
|
|
341
|
+
* can be either `mail` (reads stdin) or anything that reads the variables. The
|
|
342
|
+
* command runs through a shell because it is a shell command by nature — the
|
|
343
|
+
* user wrote it as one — and the platform's own shell, so a Windows host uses
|
|
344
|
+
* `cmd`. Nothing it prints or fails with comes back: a notification that errors
|
|
345
|
+
* must not surface in the transcript or delay the question.
|
|
346
|
+
* @param command - the configured command.
|
|
347
|
+
* @param context - the question being announced.
|
|
348
|
+
* @param deps - injectable process spawn and clock, for tests.
|
|
349
|
+
* @returns once the command has exited, timed out, or failed to start.
|
|
350
|
+
*/
|
|
351
|
+
export async function runNotify(command, context, deps = {}) {
|
|
352
|
+
const spawnFn = deps.spawnFn ?? spawn;
|
|
353
|
+
const message = notifyMessage(context);
|
|
354
|
+
const shell = notifyShell(deps.platform);
|
|
355
|
+
const env = {
|
|
356
|
+
...process.env,
|
|
357
|
+
DSH_TUI_NOTIFY_SESSION: context.sessionId,
|
|
358
|
+
DSH_TUI_NOTIFY_COUNT: String(context.count),
|
|
359
|
+
DSH_TUI_NOTIFY_QUESTION: context.question,
|
|
360
|
+
DSH_TUI_NOTIFY_WAITED_MS: String(Math.max(0, context.waitedMs)),
|
|
361
|
+
DSH_TUI_NOTIFY_RESUME: context.resumeCommand,
|
|
362
|
+
DSH_TUI_NOTIFY_SUBJECT: t('notify.mailSubject'),
|
|
363
|
+
...(context.smtpUser === undefined ? {} : { DSH_TUI_NOTIFY_SMTP_USER: context.smtpUser }),
|
|
364
|
+
...(context.smtpPassword === undefined ? {} : { DSH_TUI_NOTIFY_SMTP_PASSWORD: context.smtpPassword }),
|
|
365
|
+
};
|
|
366
|
+
await new Promise(resolve => {
|
|
367
|
+
let child;
|
|
368
|
+
try {
|
|
369
|
+
child = spawnFn(shell.command, [shell.flag, command], {
|
|
370
|
+
env,
|
|
371
|
+
stdio: ['pipe', 'ignore', 'ignore'],
|
|
372
|
+
windowsHide: true,
|
|
373
|
+
detached: false,
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
resolve();
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
let settled = false;
|
|
381
|
+
const finish = () => {
|
|
382
|
+
if (settled)
|
|
383
|
+
return;
|
|
384
|
+
settled = true;
|
|
385
|
+
clearTimeout(timer);
|
|
386
|
+
resolve();
|
|
387
|
+
};
|
|
388
|
+
const timer = setTimeout(() => {
|
|
389
|
+
try {
|
|
390
|
+
child.kill();
|
|
391
|
+
}
|
|
392
|
+
catch { /* already gone */ }
|
|
393
|
+
finish();
|
|
394
|
+
}, deps.timeoutMs ?? NOTIFY_TIMEOUT_MS);
|
|
395
|
+
timer.unref?.();
|
|
396
|
+
child.on('error', finish);
|
|
397
|
+
child.on('exit', finish);
|
|
398
|
+
child.stdin?.on('error', finish);
|
|
399
|
+
try {
|
|
400
|
+
child.stdin?.end(message);
|
|
401
|
+
}
|
|
402
|
+
catch {
|
|
403
|
+
finish();
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* The shell that runs a notify command, and the flag that precedes it.
|
|
409
|
+
*
|
|
410
|
+
* A jump host means `sh -c`. Windows has no `sh` on PATH as a rule, so there
|
|
411
|
+
* the command runs under `cmd /c` and the user writes it for `cmd`.
|
|
412
|
+
* @param platform - injectable so the Windows shape is testable from POSIX.
|
|
413
|
+
* @returns the executable and its command flag.
|
|
414
|
+
*/
|
|
415
|
+
export function notifyShell(platform = process.platform) {
|
|
416
|
+
return platform === 'win32' ? { command: 'cmd', flag: '/c' } : { command: 'sh', flag: '-c' };
|
|
417
|
+
}
|
|
418
|
+
//# sourceMappingURL=question-wait.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"question-wait.js","sourceRoot":"","sources":["../src/question-wait.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAA;AACnC,OAAO,EAAE,kBAAkB,EAAE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,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;AAC9F,CAAC"}
|
package/lib/route-memory.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* routes without wiping the previous provider's choice.
|
|
4
4
|
*/
|
|
5
5
|
import z from '@deepseek-ai/schemastery';
|
|
6
|
-
import { installSettingsSection, settingsNamespace } from './dsh-compat.js';
|
|
6
|
+
import { installSettingsSection, liveField, settingsNamespace } from './dsh-compat.js';
|
|
7
7
|
export const ROUTE_MEMORY_NAMESPACE = settingsNamespace('ssh-tui-routes');
|
|
8
8
|
/**
|
|
9
9
|
* Settings schema for `$DSH_HOME/settings.yaml` under ssh-tui-routes.
|
|
@@ -14,11 +14,11 @@ export const ROUTE_MEMORY_NAMESPACE = settingsNamespace('ssh-tui-routes');
|
|
|
14
14
|
* with TS2742 on any layout that does not match this machine's.
|
|
15
15
|
*/
|
|
16
16
|
export const ROUTE_MEMORY_SCHEMA = z.object({
|
|
17
|
-
providers: z.dict(z.object({
|
|
17
|
+
providers: liveField(z.dict(z.object({
|
|
18
18
|
model: z.string(),
|
|
19
19
|
reasoningEffort: z.string().default(''),
|
|
20
20
|
updatedAt: z.number(),
|
|
21
|
-
})).default({}),
|
|
21
|
+
})).default({})),
|
|
22
22
|
});
|
|
23
23
|
export function parseRouteMemory(raw) {
|
|
24
24
|
if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
|
package/lib/route-memory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-memory.js","sourceRoot":"","sources":["../src/route-memory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,CAAC,MAAM,0BAA0B,CAAA;AAExC,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"route-memory.js","sourceRoot":"","sources":["../src/route-memory.ts"],"names":[],"mappings":"A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AK,EAAE,QAAQ,EAAE,CAAA;QAC/B,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC7C,sBAAsB,CAAC,GAAG,EAAE,sBAAsB,EAAE,mBAAmB,EAAE;QACvE,SAAS,EAAE,EAAE;KACd,EAAE;QACD,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;QACnB,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;KACnB,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,MAAsB,EACtB,QAAgB,EAChB,KAAsB;IAEtB,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAA;IAC1B,IAAI,EAAE,KAAK,EAAE,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,MAAM,CAAA;IACzD,OAAO;QACL,GAAG,MAAM;QACT,CAAC,EAAE,CAAC,EAAE;YACJ,GAAG,CAAC,KAAK,CAAC,eAAe,KAAK,SAAS,IAAI,KAAK,CAAC,eAAe,KAAK,EAAE;gBACrE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE;gBACxB,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,eAAe,EAAE,CAAC;YACnE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB;KACF,CAAA;AACH,CAAC"}
|
package/lib/selection.js
CHANGED
|
@@ -9,16 +9,26 @@
|
|
|
9
9
|
* OSC 52 (the channel `/copy` already uses).
|
|
10
10
|
*
|
|
11
11
|
* Only **model replies** are freely selectable. Everything here is pure: the
|
|
12
|
-
* caller passes the painted lines (plain text
|
|
13
|
-
* reply
|
|
14
|
-
* reverse video, and the text to copy.
|
|
15
|
-
* stays in `tui.ts`.
|
|
12
|
+
* caller passes the painted lines (plain text, whether each one came from a
|
|
13
|
+
* reply, and how many leading cells are chrome) and gets back the ordered
|
|
14
|
+
* selection, the cell spans to paint in reverse video, and the text to copy.
|
|
15
|
+
* The IO — mouse reports, OSC 52, notices — stays in `tui.ts`.
|
|
16
16
|
*
|
|
17
17
|
* Columns are **cells**, not characters: a CJK glyph is two cells wide, and a
|
|
18
18
|
* selection that touches either half includes the whole glyph. Surrogate pairs
|
|
19
19
|
* (emoji) are treated the same way.
|
|
20
20
|
*/
|
|
21
21
|
import { displayWidth } from './term-text.js';
|
|
22
|
+
/**
|
|
23
|
+
* Characters at the start of a line that cover its gutter.
|
|
24
|
+
*
|
|
25
|
+
* Cells and characters differ (`▶` is one character and two cells wide), so the
|
|
26
|
+
* cut is found by measuring the way the painter measures, and a selection's
|
|
27
|
+
* offsets are then computed inside the content that follows it.
|
|
28
|
+
*/
|
|
29
|
+
function gutterCut(text, gutter) {
|
|
30
|
+
return gutter <= 0 ? 0 : offsetAtColumn(text, gutter);
|
|
31
|
+
}
|
|
22
32
|
/** Order two dragged points, whichever way the drag went. */
|
|
23
33
|
export function orderPoints(anchor, extent) {
|
|
24
34
|
const before = anchor.line < extent.line
|
|
@@ -125,7 +135,12 @@ export function selectionSpans(lines, selection) {
|
|
|
125
135
|
for (let line = selection.from.line; line <= selection.to.line; line += 1) {
|
|
126
136
|
const text = lines[line]?.text ?? '';
|
|
127
137
|
const width = lineWidth(text);
|
|
128
|
-
const
|
|
138
|
+
const gutter = Math.min(width, Math.max(0, lines[line]?.gutter ?? 0));
|
|
139
|
+
// The marker is never part of the selection: it says which row is focused,
|
|
140
|
+
// it is not content, and inverting it made the marker look selected too.
|
|
141
|
+
const start = line === selection.from.line
|
|
142
|
+
? Math.max(gutter, Math.min(selection.from.column, width))
|
|
143
|
+
: gutter;
|
|
129
144
|
const end = line === selection.to.line ? Math.min(selection.to.column, width) : width;
|
|
130
145
|
if (end > start)
|
|
131
146
|
spans.push({ line, start, end });
|
|
@@ -140,14 +155,17 @@ export function selectionText(lines, selection) {
|
|
|
140
155
|
const parts = [];
|
|
141
156
|
for (let line = selection.from.line; line <= selection.to.line; line += 1) {
|
|
142
157
|
const text = lines[line]?.text ?? '';
|
|
143
|
-
const
|
|
144
|
-
const
|
|
158
|
+
const gutter = Math.max(0, lines[line]?.gutter ?? 0);
|
|
159
|
+
const cut = gutterCut(text, gutter);
|
|
160
|
+
const body = text.slice(cut);
|
|
161
|
+
const startOffset = line === selection.from.line ? offsetAtColumn(body, selection.from.column - gutter) : 0;
|
|
162
|
+
const endOffset = line === selection.to.line ? offsetAfterColumn(body, selection.to.column - gutter) : body.length;
|
|
145
163
|
if (endOffset <= startOffset) {
|
|
146
164
|
// A drag that stops at a line's first cell still selects that line's break.
|
|
147
165
|
parts.push('');
|
|
148
166
|
continue;
|
|
149
167
|
}
|
|
150
|
-
parts.push(
|
|
168
|
+
parts.push(body.slice(startOffset, endOffset).replace(/\s+$/u, ''));
|
|
151
169
|
}
|
|
152
170
|
return parts.join('\n').replace(/\n+$/u, '');
|
|
153
171
|
}
|
package/lib/selection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.js","sourceRoot":"","sources":["../src/selection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"selection.js","sourceRoot":"","sources":["../src/selection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAkB7C;;;;;;GAMG;AACH,SAAS,SAAS,CAAC,IAAY,EAAE,MAAc;IAC7C,OAAO,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AACvD,CAAC;AAqBD,6DAA6D;AAC7D,MAAM,UAAU,WAAW,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
5
|
import { resolveDshHome } from './display-sock.js';
|
|
6
|
+
import { restrictPathToUser } from './platform.js';
|
|
6
7
|
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
7
8
|
import { dirname, join } from 'node:path';
|
|
8
9
|
import { statSync } from 'node:fs';
|
|
@@ -65,10 +66,14 @@ export async function saveSessionIndex(path, entries) {
|
|
|
65
66
|
await mkdir(dirname(path), { recursive: true });
|
|
66
67
|
await writeFile(tmp, body, { encoding: 'utf8', mode: 0o600 });
|
|
67
68
|
await rename(tmp, path);
|
|
69
|
+
// `mode` is a POSIX-only promise: on Windows the intent is an ACL, and the
|
|
70
|
+
// index names every session on the machine.
|
|
71
|
+
await restrictPathToUser(path, { mode: 0o600 });
|
|
68
72
|
}
|
|
69
73
|
catch {
|
|
70
74
|
try {
|
|
71
75
|
await writeFile(path, body, { encoding: 'utf8', mode: 0o600 });
|
|
76
|
+
await restrictPathToUser(path, { mode: 0o600 });
|
|
72
77
|
}
|
|
73
78
|
catch { /* best-effort */ }
|
|
74
79
|
}
|
package/lib/session-index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-index.js","sourceRoot":"","sources":["../src/session-index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAErE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAoBnD,6EAA6E;AAC7E,+EAA+E;AAC/E,4BAA4B;AAC5B,MAAM,aAAa,GAAG,CAAC,CAAA;AAEvB,8EAA8E;AAC9E,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAA;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O,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IAC1C,CAAC;AACH,CAAC"}
|
package/lib/session-lock.js
CHANGED
|
@@ -9,6 +9,7 @@ import { readFileSync } from 'node:fs';
|
|
|
9
9
|
import { execFile } from 'node:child_process';
|
|
10
10
|
import { dirname, join } from 'node:path';
|
|
11
11
|
import { t } from './i18n/index.js';
|
|
12
|
+
import { restrictPathToUser, usesProcessIdentity } from './platform.js';
|
|
12
13
|
import { displaySockExists, isPipePath, resolveDshHome, sessionLabel, sessionSockLookupPaths, sessionSockPath } from './display-sock.js';
|
|
13
14
|
export class SessionLockHeldError extends Error {
|
|
14
15
|
lock;
|
|
@@ -290,7 +291,7 @@ export async function lockOwnerIsAlive(lock) {
|
|
|
290
291
|
return false;
|
|
291
292
|
if (!processIsAlive(pid))
|
|
292
293
|
return false;
|
|
293
|
-
if (
|
|
294
|
+
if (usesProcessIdentity()) {
|
|
294
295
|
return windowsProcessMatchesLock(lock, await windowsProcessIdentity(lock));
|
|
295
296
|
}
|
|
296
297
|
if (lock.bootId !== undefined && lock.pidStart !== undefined) {
|
|
@@ -324,7 +325,9 @@ export async function readSessionLock(sessionId, dshHome = resolveDshHome()) {
|
|
|
324
325
|
}
|
|
325
326
|
export async function writeSessionLock(path, info) {
|
|
326
327
|
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
328
|
+
await restrictPathToUser(dirname(path), { mode: 0o700, directory: true });
|
|
327
329
|
await writeFile(path, `${JSON.stringify(info, null, 2)}\n`, { mode: 0o600 });
|
|
330
|
+
await restrictPathToUser(path, { mode: 0o600 });
|
|
328
331
|
}
|
|
329
332
|
export async function acquireSessionLock(sessionId, options = {}) {
|
|
330
333
|
const dshHome = options.dshHome ?? resolveDshHome();
|