@linxin666/dsh-win-bash 0.4.7 → 0.4.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/README.i18n.yaml +2 -2
- package/README.md +7 -0
- package/README.zh.md +4 -0
- package/lib/index.js +63 -4
- package/lib/types/index.d.ts +1 -1
- package/lib/types/tool.d.ts +16 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/tool.ts +67 -3
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# node scripts/verify-docs.mjs --write <dir>
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: 72ffe20a242382e5b7f93004a4fdbf0e600c3977
|
|
6
|
+
README.zh.md: 5bb459bfa258ebf3da9a6fa81b27e57d16fbcb85
|
package/README.md
CHANGED
|
@@ -31,6 +31,13 @@ session is what makes that true.
|
|
|
31
31
|
separated streams, and the command's real exit code. Output past the budget
|
|
32
32
|
is reported as truncated, in the text the model reads, rather than being cut
|
|
33
33
|
silently.
|
|
34
|
+
- Renders terminal escapes out of that text. On Windows, colour libraries
|
|
35
|
+
decide on the platform rather than on whether a terminal is attached, so a
|
|
36
|
+
piped `vitest` or `pnpm` run still emits colour codes; the tool carries the
|
|
37
|
+
bytes through and drops them where the text is rendered, so a caller reads
|
|
38
|
+
the message instead of `ESC [ 3 3 m`. A line a progress renderer repainted in
|
|
39
|
+
place shows the frame it finished on. The streams and the spill files keep
|
|
40
|
+
the exact bytes.
|
|
34
41
|
- Optionally runs a command as a background job in its own pinned bash process
|
|
35
42
|
and returns a job id at once, so a long build or watch does not hold the call
|
|
36
43
|
open or die with the session's shell. See [Background commands](#background-commands).
|
package/README.zh.md
CHANGED
|
@@ -24,6 +24,10 @@ shell 必须持久,因为 shell 是有状态的:一条命令 `cd` 过、expo
|
|
|
24
24
|
历史在该会话的多次调用之间保留,且不与其它会话共享。
|
|
25
25
|
- 每次调用都是前台命令:stdout 与 stderr 分离、各有字节上限、返回命令真实的退出码。
|
|
26
26
|
超出上限的输出会在模型读到的文本里被标记为截断,而不是被无声切掉。
|
|
27
|
+
- 在渲染出的文本里剥掉终端转义序列。Windows 上的着色库按平台而不是按「有没有接终端」
|
|
28
|
+
判断,所以管道里的 `vitest`、`pnpm` 照样吐颜色码;本工具把字节原样带回来,在渲染
|
|
29
|
+
成文本这一步丢掉它们,于是读到的是消息本身而不是 `ESC [ 3 3 m`。被进度条原地重绘
|
|
30
|
+
的那一行只保留它最后停在的那一帧。原始流与 spill 文件仍保留精确字节。
|
|
27
31
|
- 可选地把命令作为后台任务放进它自己的钉死 bash 进程,立即返回 job id,
|
|
28
32
|
于是长构建或 watch 既不占住这次调用,也不会随会话 shell 一起死。见
|
|
29
33
|
[后台命令](#后台命令)。
|
package/lib/index.js
CHANGED
|
@@ -2358,6 +2358,57 @@ function byteLength(text) {
|
|
|
2358
2358
|
return Buffer.byteLength(text, "utf8");
|
|
2359
2359
|
}
|
|
2360
2360
|
/**
|
|
2361
|
+
* The CSI escape sequences a Windows child process emits with no terminal
|
|
2362
|
+
* attached: colour (SGR) and the cursor/erase families a progress renderer
|
|
2363
|
+
* uses. OSC, which Windows Terminal uses for JSON semantic-prompt marks, is
|
|
2364
|
+
* matched as a whole so its embedded JSON never leaks into the text.
|
|
2365
|
+
*
|
|
2366
|
+
* WHY THIS IS STRIPPED HERE AND NOWHERE ELSE. The colour libraries a build
|
|
2367
|
+
* tool uses (`picocolors`, `tinyrainbow`) short-circuit the "no TTY means no
|
|
2368
|
+
* colour" rule on Windows itself — `platform === 'win32' ||` is one of their
|
|
2369
|
+
* disjuncts — so `TERM=dumb`, which {@link shellEnvironment} already sets, does
|
|
2370
|
+
* not turn them off, and neither does piping. The bytes below arrive in
|
|
2371
|
+
* ordinary vitest and pnpm output on this very platform. This tool passes raw
|
|
2372
|
+
* bytes through on purpose (that is what the pipe model buys); rendering them
|
|
2373
|
+
* as text is the step that makes ``\u001b[33m`` and ``\u001b[1m`` legible to
|
|
2374
|
+
* nobody. Both streams go through it, since a red error message is as
|
|
2375
|
+
* unreadable as a red test summary. The loss is confined to this rendered view:
|
|
2376
|
+
* the byte budgets, the exit code and any spill file still describe the exact
|
|
2377
|
+
* stream, because colour is not information the text was carrying.
|
|
2378
|
+
*/
|
|
2379
|
+
const ANSI_SEQUENCE = /\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][\s\S]*?(?:\u0007|\u001b\\)/g;
|
|
2380
|
+
/**
|
|
2381
|
+
* Keep only the frame a repainting line ended on.
|
|
2382
|
+
*
|
|
2383
|
+
* A progress renderer overwrites one line with carriage returns instead of
|
|
2384
|
+
* writing new ones, so the raw stream holds every frame glued together. A
|
|
2385
|
+
* terminal shows the last one; text shows all of them. CRLF is not a repaint —
|
|
2386
|
+
* it is how a Windows command ends a line — so a pair is left exactly as it
|
|
2387
|
+
* was written.
|
|
2388
|
+
* @param text - the text whose lines may have been repainted in place.
|
|
2389
|
+
* @returns the text where each line shows the frame it finished on.
|
|
2390
|
+
*/
|
|
2391
|
+
function collapseRepaints(text) {
|
|
2392
|
+
if (!text.includes("\r")) return text;
|
|
2393
|
+
const lines = text.split("\n");
|
|
2394
|
+
return lines.map((line, index) => {
|
|
2395
|
+
const endsLine = index < lines.length - 1 && line.endsWith("\r");
|
|
2396
|
+
const body = endsLine ? line.slice(0, -1) : line;
|
|
2397
|
+
const cut = body.lastIndexOf("\r");
|
|
2398
|
+
const kept = cut === -1 ? body : body.slice(cut + 1);
|
|
2399
|
+
return endsLine ? kept + "\r" : kept;
|
|
2400
|
+
}).join("\n");
|
|
2401
|
+
}
|
|
2402
|
+
/**
|
|
2403
|
+
* Make a rendered string readable: drop the escape sequences, then let each
|
|
2404
|
+
* repainted line show the frame it ended on.
|
|
2405
|
+
* @param text - the string about to be shown to a caller.
|
|
2406
|
+
* @returns the text with escapes stripped and overwritten frames collapsed.
|
|
2407
|
+
*/
|
|
2408
|
+
function stripTerminalEscapes(text) {
|
|
2409
|
+
return collapseRepaints(text.includes("\x1B") ? text.replace(ANSI_SEQUENCE, "") : text);
|
|
2410
|
+
}
|
|
2411
|
+
/**
|
|
2361
2412
|
* The line that tells the model its view of one stream is incomplete.
|
|
2362
2413
|
*
|
|
2363
2414
|
* WHY THIS IS NOT DECORATION. The visible text is the TAIL of the stream: the
|
|
@@ -2380,12 +2431,20 @@ function truncationNotice(stream, visible, flags, spillPath) {
|
|
|
2380
2431
|
parts.push("]");
|
|
2381
2432
|
return parts.join("");
|
|
2382
2433
|
}
|
|
2383
|
-
/**
|
|
2434
|
+
/**
|
|
2435
|
+
* Render one result the way the host's own shell tools render theirs.
|
|
2436
|
+
*
|
|
2437
|
+
* This is where the raw stream becomes something a caller can read: escape
|
|
2438
|
+
* sequences are stripped (see {@link stripTerminalEscapes}), so a Windows build
|
|
2439
|
+
* tool that colours its piped output does not hand back a wall of ``\u001b[1m``
|
|
2440
|
+
* to the model and to the terminal card. The truncation notices below are this
|
|
2441
|
+
* tool's own text and are appended AFTER stripping, so they survive intact.
|
|
2442
|
+
*/
|
|
2384
2443
|
function renderResult(value) {
|
|
2385
|
-
let body = value.stdout;
|
|
2444
|
+
let body = stripTerminalEscapes(value.stdout);
|
|
2386
2445
|
if (value.stderr !== "") {
|
|
2387
2446
|
if (body !== "" && !body.endsWith("\n")) body += "\n";
|
|
2388
|
-
body += "[stderr]\n" + value.stderr;
|
|
2447
|
+
body += "[stderr]\n" + stripTerminalEscapes(value.stderr);
|
|
2389
2448
|
}
|
|
2390
2449
|
if (body === "") body = "(no output)";
|
|
2391
2450
|
const parts = [body];
|
|
@@ -2694,4 +2753,4 @@ function apply(ctx, config) {
|
|
|
2694
2753
|
});
|
|
2695
2754
|
}
|
|
2696
2755
|
//#endregion
|
|
2697
|
-
export { BACKGROUND_JOB_KIND, CONFIG_DEFAULTS, Config, DEFAULT_DESCRIPTION, DEFAULT_ENABLE_RUN_IN_BACKGROUND, DEFAULT_REPLACE_PWSH, DEFAULT_SYNC_WITH_LIANGSHEN, GATE_DECLARATION_WAIT_MS, GATE_POLL_INTERVAL_MS, GATE_READ_TIMEOUT_MS, GATE_SETTLE_TIMEOUT_MS, HOST_PWSH_TOOL, LIANGSHEN_PRESET_ID, SERVING_MODE, ShellRegistry, ShellUnavailableError, WIN_BASH_TOOL, apply, bashPath, buildFrame, declaresLiangShen, gateRefusalMessage, inject, installPwshReplacement, markerFor, mountWithGate, name, parseChecksums, parseFrame, readJobRegistry, readPresetRegistry, registerWinBash, renderResult, resolveRuntime, runtimeRoot, settleHostTree, shPath, shellArgv, shellEnvironment, shellTempDir, startBackgroundJob, startLiangShenGate, truncationNotice, validateConfig, verifyPayload };
|
|
2756
|
+
export { BACKGROUND_JOB_KIND, CONFIG_DEFAULTS, Config, DEFAULT_DESCRIPTION, DEFAULT_ENABLE_RUN_IN_BACKGROUND, DEFAULT_REPLACE_PWSH, DEFAULT_SYNC_WITH_LIANGSHEN, GATE_DECLARATION_WAIT_MS, GATE_POLL_INTERVAL_MS, GATE_READ_TIMEOUT_MS, GATE_SETTLE_TIMEOUT_MS, HOST_PWSH_TOOL, LIANGSHEN_PRESET_ID, SERVING_MODE, ShellRegistry, ShellUnavailableError, WIN_BASH_TOOL, apply, bashPath, buildFrame, declaresLiangShen, gateRefusalMessage, inject, installPwshReplacement, markerFor, mountWithGate, name, parseChecksums, parseFrame, readJobRegistry, readPresetRegistry, registerWinBash, renderResult, resolveRuntime, runtimeRoot, settleHostTree, shPath, shellArgv, shellEnvironment, shellTempDir, startBackgroundJob, startLiangShenGate, stripTerminalEscapes, truncationNotice, validateConfig, verifyPayload };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export { Config };
|
|
|
47
47
|
export type { WinBashConfig, WinBashConfigInput };
|
|
48
48
|
export { CONFIG_DEFAULTS, DEFAULT_DESCRIPTION, DEFAULT_ENABLE_RUN_IN_BACKGROUND, DEFAULT_REPLACE_PWSH, DEFAULT_SYNC_WITH_LIANGSHEN, validateConfig, } from './config.ts';
|
|
49
49
|
export { HOST_PWSH_TOOL, SERVING_MODE, installPwshReplacement, type PwshReplacementOptions, type ScopedRestrictor, type SessionPolicyReader, } from './pwsh-replacement.ts';
|
|
50
|
-
export { WIN_BASH_TOOL, renderResult, readJobRegistry, truncationNotice } from './tool.ts';
|
|
50
|
+
export { WIN_BASH_TOOL, renderResult, readJobRegistry, stripTerminalEscapes, truncationNotice } from './tool.ts';
|
|
51
51
|
export type { RenderFacts } from './tool.ts';
|
|
52
52
|
export { ShellRegistry, ShellUnavailableError, shellArgv, shellEnvironment, shellTempDir, } from './shell.ts';
|
|
53
53
|
export { buildFrame, markerFor, parseFrame } from './protocol.ts';
|
package/lib/types/tool.d.ts
CHANGED
|
@@ -64,6 +64,13 @@ export interface RenderFacts {
|
|
|
64
64
|
/** Host path of the complete stderr, when the provider spilled it. */
|
|
65
65
|
stderrSpillPath?: string;
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Make a rendered string readable: drop the escape sequences, then let each
|
|
69
|
+
* repainted line show the frame it ended on.
|
|
70
|
+
* @param text - the string about to be shown to a caller.
|
|
71
|
+
* @returns the text with escapes stripped and overwritten frames collapsed.
|
|
72
|
+
*/
|
|
73
|
+
export declare function stripTerminalEscapes(text: string): string;
|
|
67
74
|
/**
|
|
68
75
|
* The line that tells the model its view of one stream is incomplete.
|
|
69
76
|
*
|
|
@@ -83,7 +90,15 @@ export declare function truncationNotice(stream: 'stdout' | 'stderr', visible: s
|
|
|
83
90
|
lostHead: boolean;
|
|
84
91
|
overflow: boolean;
|
|
85
92
|
}, spillPath?: string): string | undefined;
|
|
86
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Render one result the way the host's own shell tools render theirs.
|
|
95
|
+
*
|
|
96
|
+
* This is where the raw stream becomes something a caller can read: escape
|
|
97
|
+
* sequences are stripped (see {@link stripTerminalEscapes}), so a Windows build
|
|
98
|
+
* tool that colours its piped output does not hand back a wall of ``\u001b[1m``
|
|
99
|
+
* to the model and to the terminal card. The truncation notices below are this
|
|
100
|
+
* tool's own text and are appended AFTER stripping, so they survive intact.
|
|
101
|
+
*/
|
|
87
102
|
export declare function renderResult(value: RenderFacts): string;
|
|
88
103
|
/**
|
|
89
104
|
* The deployment's background job registry, read without letting a refused
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linxin666/dsh-win-bash",
|
|
3
3
|
"description": "Pinned private bash for Windows x64 DSH sessions: one persistent bash process per session behind the win_bash tool, carrying a digested Git for Windows MinGit payload and no PATH fallback.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"types": "lib/types/index.d.ts",
|
package/src/index.ts
CHANGED
|
@@ -79,7 +79,7 @@ export {
|
|
|
79
79
|
type ScopedRestrictor,
|
|
80
80
|
type SessionPolicyReader,
|
|
81
81
|
} from './pwsh-replacement.ts'
|
|
82
|
-
export { WIN_BASH_TOOL, renderResult, readJobRegistry, truncationNotice } from './tool.ts'
|
|
82
|
+
export { WIN_BASH_TOOL, renderResult, readJobRegistry, stripTerminalEscapes, truncationNotice } from './tool.ts'
|
|
83
83
|
export type { RenderFacts } from './tool.ts'
|
|
84
84
|
export {
|
|
85
85
|
ShellRegistry,
|
package/src/tool.ts
CHANGED
|
@@ -140,6 +140,62 @@ function byteLength(text: string): number {
|
|
|
140
140
|
return Buffer.byteLength(text, 'utf8')
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* The CSI escape sequences a Windows child process emits with no terminal
|
|
145
|
+
* attached: colour (SGR) and the cursor/erase families a progress renderer
|
|
146
|
+
* uses. OSC, which Windows Terminal uses for JSON semantic-prompt marks, is
|
|
147
|
+
* matched as a whole so its embedded JSON never leaks into the text.
|
|
148
|
+
*
|
|
149
|
+
* WHY THIS IS STRIPPED HERE AND NOWHERE ELSE. The colour libraries a build
|
|
150
|
+
* tool uses (`picocolors`, `tinyrainbow`) short-circuit the "no TTY means no
|
|
151
|
+
* colour" rule on Windows itself — `platform === 'win32' ||` is one of their
|
|
152
|
+
* disjuncts — so `TERM=dumb`, which {@link shellEnvironment} already sets, does
|
|
153
|
+
* not turn them off, and neither does piping. The bytes below arrive in
|
|
154
|
+
* ordinary vitest and pnpm output on this very platform. This tool passes raw
|
|
155
|
+
* bytes through on purpose (that is what the pipe model buys); rendering them
|
|
156
|
+
* as text is the step that makes ``\u001b[33m`` and ``\u001b[1m`` legible to
|
|
157
|
+
* nobody. Both streams go through it, since a red error message is as
|
|
158
|
+
* unreadable as a red test summary. The loss is confined to this rendered view:
|
|
159
|
+
* the byte budgets, the exit code and any spill file still describe the exact
|
|
160
|
+
* stream, because colour is not information the text was carrying.
|
|
161
|
+
*/
|
|
162
|
+
// eslint-disable-next-line no-control-regex -- matching control characters IS the job
|
|
163
|
+
const ANSI_SEQUENCE = /\u001b\[[0-9;?]*[ -/]*[@-~]|\u001b\][\s\S]*?(?:\u0007|\u001b\\)/g
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Keep only the frame a repainting line ended on.
|
|
167
|
+
*
|
|
168
|
+
* A progress renderer overwrites one line with carriage returns instead of
|
|
169
|
+
* writing new ones, so the raw stream holds every frame glued together. A
|
|
170
|
+
* terminal shows the last one; text shows all of them. CRLF is not a repaint —
|
|
171
|
+
* it is how a Windows command ends a line — so a pair is left exactly as it
|
|
172
|
+
* was written.
|
|
173
|
+
* @param text - the text whose lines may have been repainted in place.
|
|
174
|
+
* @returns the text where each line shows the frame it finished on.
|
|
175
|
+
*/
|
|
176
|
+
function collapseRepaints(text: string): string {
|
|
177
|
+
if (!text.includes('\r')) return text
|
|
178
|
+
const lines = text.split('\n')
|
|
179
|
+
return lines.map((line, index) => {
|
|
180
|
+
const endsLine = index < lines.length - 1 && line.endsWith('\r')
|
|
181
|
+
const body = endsLine ? line.slice(0, -1) : line
|
|
182
|
+
const cut = body.lastIndexOf('\r')
|
|
183
|
+
const kept = cut === -1 ? body : body.slice(cut + 1)
|
|
184
|
+
return endsLine ? kept + '\r' : kept
|
|
185
|
+
}).join('\n')
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Make a rendered string readable: drop the escape sequences, then let each
|
|
190
|
+
* repainted line show the frame it ended on.
|
|
191
|
+
* @param text - the string about to be shown to a caller.
|
|
192
|
+
* @returns the text with escapes stripped and overwritten frames collapsed.
|
|
193
|
+
*/
|
|
194
|
+
export function stripTerminalEscapes(text: string): string {
|
|
195
|
+
const unescaped = text.includes('\u001b') ? text.replace(ANSI_SEQUENCE, '') : text
|
|
196
|
+
return collapseRepaints(unescaped)
|
|
197
|
+
}
|
|
198
|
+
|
|
143
199
|
/**
|
|
144
200
|
* The line that tells the model its view of one stream is incomplete.
|
|
145
201
|
*
|
|
@@ -171,12 +227,20 @@ export function truncationNotice(
|
|
|
171
227
|
return parts.join('')
|
|
172
228
|
}
|
|
173
229
|
|
|
174
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* Render one result the way the host's own shell tools render theirs.
|
|
232
|
+
*
|
|
233
|
+
* This is where the raw stream becomes something a caller can read: escape
|
|
234
|
+
* sequences are stripped (see {@link stripTerminalEscapes}), so a Windows build
|
|
235
|
+
* tool that colours its piped output does not hand back a wall of ``\u001b[1m``
|
|
236
|
+
* to the model and to the terminal card. The truncation notices below are this
|
|
237
|
+
* tool's own text and are appended AFTER stripping, so they survive intact.
|
|
238
|
+
*/
|
|
175
239
|
export function renderResult(value: RenderFacts): string {
|
|
176
|
-
let body = value.stdout
|
|
240
|
+
let body = stripTerminalEscapes(value.stdout)
|
|
177
241
|
if (value.stderr !== '') {
|
|
178
242
|
if (body !== '' && !body.endsWith('\n')) body += '\n'
|
|
179
|
-
body += '[stderr]\n' + value.stderr
|
|
243
|
+
body += '[stderr]\n' + stripTerminalEscapes(value.stderr)
|
|
180
244
|
}
|
|
181
245
|
if (body === '') body = '(no output)'
|
|
182
246
|
const parts = [body]
|