@linxin666/dsh-win-bash 0.0.0-stage → 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/LICENSE +202 -0
- package/PROVENANCE.md +215 -0
- package/README.i18n.yaml +6 -0
- package/README.md +264 -2
- package/README.zh.md +221 -0
- package/cordis.patch.yml +13 -0
- package/lib/index.js +2756 -0
- package/lib/types/background.d.ts +169 -0
- package/lib/types/config.d.ts +130 -0
- package/lib/types/gate.d.ts +179 -0
- package/lib/types/index.d.ts +104 -0
- package/lib/types/protocol.d.ts +90 -0
- package/lib/types/pwsh-replacement.d.ts +140 -0
- package/lib/types/runtime.d.ts +115 -0
- package/lib/types/shell.d.ts +184 -0
- package/lib/types/tool.d.ts +123 -0
- package/package.json +58 -3
- package/runtime/win32-x64/checksums.sha256 +91 -0
- package/runtime/win32-x64/etc/bash.bashrc +69 -0
- package/runtime/win32-x64/etc/fstab +6 -0
- package/runtime/win32-x64/etc/msystem +27 -0
- package/runtime/win32-x64/etc/msystem.d/CLANG64 +7 -0
- package/runtime/win32-x64/etc/msystem.d/CLANGARM64 +7 -0
- package/runtime/win32-x64/etc/msystem.d/MINGW32 +7 -0
- package/runtime/win32-x64/etc/msystem.d/MINGW64 +7 -0
- package/runtime/win32-x64/etc/msystem.d/MSYS +4 -0
- package/runtime/win32-x64/etc/msystem.d/UCRT64 +7 -0
- package/runtime/win32-x64/etc/nsswitch.conf +12 -0
- package/runtime/win32-x64/etc/package-versions.txt +67 -0
- package/runtime/win32-x64/etc/profile +146 -0
- package/runtime/win32-x64/etc/profile.d/bash_profile.sh +11 -0
- package/runtime/win32-x64/etc/profile.d/lang.sh +19 -0
- package/runtime/win32-x64/licenses/GPL-2.0.txt +338 -0
- package/runtime/win32-x64/licenses/GPL-3.0.txt +674 -0
- package/runtime/win32-x64/licenses/LGPL-2.1.txt +501 -0
- package/runtime/win32-x64/licenses/LGPL-3.0.txt +165 -0
- package/runtime/win32-x64/licenses/expat-COPYING.txt +21 -0
- package/runtime/win32-x64/licenses/gcc-libs-RUNTIME.LIBRARY.EXCEPTION.txt +73 -0
- package/runtime/win32-x64/licenses/gettext-runtime-COPYING.LIB.txt +501 -0
- package/runtime/win32-x64/licenses/gettext-runtime-COPYING.txt +13 -0
- package/runtime/win32-x64/licenses/git-for-windows-LICENSE.txt +360 -0
- package/runtime/win32-x64/licenses/heimdal-LICENSE.txt +33 -0
- package/runtime/win32-x64/licenses/libcbor-LICENSE.md +21 -0
- package/runtime/win32-x64/licenses/libffi-LICENSE.txt +21 -0
- package/runtime/win32-x64/licenses/libfido2-LICENSE.txt +26 -0
- package/runtime/win32-x64/licenses/libiconv-COPYING.LIB.txt +501 -0
- package/runtime/win32-x64/licenses/libiconv-COPYING.txt +674 -0
- package/runtime/win32-x64/licenses/libopenssl-LICENSE.txt +177 -0
- package/runtime/win32-x64/licenses/libpcre-LICENCE.txt +93 -0
- package/runtime/win32-x64/licenses/libsqlite-LICENSE +25 -0
- package/runtime/win32-x64/licenses/ncurses-LICENSE +29 -0
- package/runtime/win32-x64/licenses/openssh-LICENCE.txt +412 -0
- package/runtime/win32-x64/licenses/zlib-LICENSE +22 -0
- package/runtime/win32-x64/usr/bin/awk.exe +0 -0
- package/runtime/win32-x64/usr/bin/b2sum.exe +0 -0
- package/runtime/win32-x64/usr/bin/basename.exe +0 -0
- package/runtime/win32-x64/usr/bin/basenc.exe +0 -0
- package/runtime/win32-x64/usr/bin/bash.exe +0 -0
- package/runtime/win32-x64/usr/bin/cat.exe +0 -0
- package/runtime/win32-x64/usr/bin/cmp.exe +0 -0
- package/runtime/win32-x64/usr/bin/comm.exe +0 -0
- package/runtime/win32-x64/usr/bin/cp.exe +0 -0
- package/runtime/win32-x64/usr/bin/cut.exe +0 -0
- package/runtime/win32-x64/usr/bin/dash.exe +0 -0
- package/runtime/win32-x64/usr/bin/date.exe +0 -0
- package/runtime/win32-x64/usr/bin/diff.exe +0 -0
- package/runtime/win32-x64/usr/bin/diff3.exe +0 -0
- package/runtime/win32-x64/usr/bin/dirname.exe +0 -0
- package/runtime/win32-x64/usr/bin/echo.exe +0 -0
- package/runtime/win32-x64/usr/bin/env.exe +0 -0
- package/runtime/win32-x64/usr/bin/expr.exe +0 -0
- package/runtime/win32-x64/usr/bin/false.exe +0 -0
- package/runtime/win32-x64/usr/bin/find.exe +0 -0
- package/runtime/win32-x64/usr/bin/grep.exe +0 -0
- package/runtime/win32-x64/usr/bin/head.exe +0 -0
- package/runtime/win32-x64/usr/bin/ls.exe +0 -0
- package/runtime/win32-x64/usr/bin/mkdir.exe +0 -0
- package/runtime/win32-x64/usr/bin/mktemp.exe +0 -0
- package/runtime/win32-x64/usr/bin/msys-2.0.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-gcc_s-seh-1.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-gmp-10.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-iconv-2.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-intl-8.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-mpfr-6.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-ncursesw6.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-pcre-1.dll +0 -0
- package/runtime/win32-x64/usr/bin/msys-readline8.dll +0 -0
- package/runtime/win32-x64/usr/bin/mv.exe +0 -0
- package/runtime/win32-x64/usr/bin/pathchk.exe +0 -0
- package/runtime/win32-x64/usr/bin/printf.exe +0 -0
- package/runtime/win32-x64/usr/bin/pwd.exe +0 -0
- package/runtime/win32-x64/usr/bin/readlink.exe +0 -0
- package/runtime/win32-x64/usr/bin/rm.exe +0 -0
- package/runtime/win32-x64/usr/bin/rmdir.exe +0 -0
- package/runtime/win32-x64/usr/bin/sdiff.exe +0 -0
- package/runtime/win32-x64/usr/bin/sed.exe +0 -0
- package/runtime/win32-x64/usr/bin/seq.exe +0 -0
- package/runtime/win32-x64/usr/bin/sh.exe +0 -0
- package/runtime/win32-x64/usr/bin/sleep.exe +0 -0
- package/runtime/win32-x64/usr/bin/sort.exe +0 -0
- package/runtime/win32-x64/usr/bin/tail.exe +0 -0
- package/runtime/win32-x64/usr/bin/test.exe +0 -0
- package/runtime/win32-x64/usr/bin/touch.exe +0 -0
- package/runtime/win32-x64/usr/bin/tr.exe +0 -0
- package/runtime/win32-x64/usr/bin/true.exe +0 -0
- package/runtime/win32-x64/usr/bin/uname.exe +0 -0
- package/runtime/win32-x64/usr/bin/uniq.exe +0 -0
- package/runtime/win32-x64/usr/bin/wc.exe +0 -0
- package/runtime/win32-x64/usr/bin/xargs.exe +0 -0
- package/src/background.ts +270 -0
- package/src/config.ts +209 -0
- package/src/gate.ts +308 -0
- package/src/index.ts +277 -0
- package/src/protocol.ts +130 -0
- package/src/pwsh-replacement.ts +435 -0
- package/src/runtime.ts +240 -0
- package/src/shell.ts +630 -0
- package/src/tool.ts +481 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Background execution for win_bash: one command in its OWN pinned bash
|
|
3
|
+
* process, registered with the host's job registry (`ctx.jobs`) so the model
|
|
4
|
+
* can collect it with `job_output` and stop it with `job_kill`.
|
|
5
|
+
*
|
|
6
|
+
* WHY A SEPARATE PROCESS AND NOT A SHELL '&'. The session's persistent shell
|
|
7
|
+
* lives inside the subprocess provider's managed process range, and disposing
|
|
8
|
+
* that range terminates every process still running in it. A job started with
|
|
9
|
+
* a trailing '&' is therefore bound to the shell that started it: the next
|
|
10
|
+
* call's timeout, its abort, or the agent's disposal kills the background work
|
|
11
|
+
* with the shell, and nothing says so. A background job must own its own
|
|
12
|
+
* process, which is what this module starts.
|
|
13
|
+
*
|
|
14
|
+
* SHAPE, NOT IMPORT. Like ./gate.ts, this module consumes the job registry
|
|
15
|
+
* STRUCTURALLY: a leaf plugin takes no dependency on @deepseek-ai/dsh-jobs to
|
|
16
|
+
* call one method on an optional service, and the same decision keeps this
|
|
17
|
+
* package out of the job registry's implementation. The members below are
|
|
18
|
+
* mirrored from the published declaration of @deepseek-ai/dsh-jobs@0.2.1-rc.2:
|
|
19
|
+
*
|
|
20
|
+
* lib/types/index.d.ts
|
|
21
|
+
* abstract class JobRegistry {
|
|
22
|
+
* abstract start(spec: JobSpec): JobId
|
|
23
|
+
* }
|
|
24
|
+
* lib/types/types.d.ts
|
|
25
|
+
* interface JobSpec {
|
|
26
|
+
* kind: JobKind
|
|
27
|
+
* label: string
|
|
28
|
+
* owner?: SessionId
|
|
29
|
+
* outputLimitBytes?: number
|
|
30
|
+
* output?: readonly JobOutputSource[] // { channel?, read(fromByte): JobSourceRead }
|
|
31
|
+
* run(job: JobHandle): JobHooks
|
|
32
|
+
* }
|
|
33
|
+
* interface JobHooks { cancel(reason?: string): void; done: Promise<JobOutcome> }
|
|
34
|
+
* interface JobOutcome { status: 'completed' | 'killed' | 'failed'; detail?: string; result?: string }
|
|
35
|
+
*
|
|
36
|
+
* The registry pumps the pull sources it is given into one bounded per-job
|
|
37
|
+
* output ring at its own cadence, so this module never buffers a stream
|
|
38
|
+
* itself: it hands over the process's own offset-based collected readers and
|
|
39
|
+
* lets the ring's retention be the only bound.
|
|
40
|
+
* @module @linxin666/dsh-win-bash/background
|
|
41
|
+
*/
|
|
42
|
+
import type { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess';
|
|
43
|
+
/**
|
|
44
|
+
* Producer kind of every job this plugin starts. It namespaces the ids the
|
|
45
|
+
* registry issues (`win-bash-1`), so a background command from this tool is
|
|
46
|
+
* never confused with the host's own `bash` job in `job_list`.
|
|
47
|
+
*/
|
|
48
|
+
export declare const BACKGROUND_JOB_KIND = "win-bash";
|
|
49
|
+
/** One incremental read from a job pull source, as this module produces it. */
|
|
50
|
+
export interface JobSourceReadLike {
|
|
51
|
+
/** Text captured since the requested offset. */
|
|
52
|
+
readonly text: string;
|
|
53
|
+
/** Whole-stream offset to resume from on the next read. */
|
|
54
|
+
readonly nextOffset: number;
|
|
55
|
+
/** True when the requested offset slid out of the source's retained window. */
|
|
56
|
+
readonly lossy: boolean;
|
|
57
|
+
/** Host path of a file holding the complete stream, when one is kept. */
|
|
58
|
+
readonly spillPath?: string;
|
|
59
|
+
}
|
|
60
|
+
/** One pull source the registry pumps into a job's output ring. */
|
|
61
|
+
export interface JobOutputSourceLike {
|
|
62
|
+
/** Stream label attached to every chunk this source yields. */
|
|
63
|
+
readonly channel?: 'stdout' | 'stderr';
|
|
64
|
+
/** Read everything captured since `fromByte` without consuming it. */
|
|
65
|
+
read(fromByte: number): JobSourceReadLike;
|
|
66
|
+
}
|
|
67
|
+
/** The terminal outcome a producer reports to the registry. */
|
|
68
|
+
export interface JobOutcomeLike {
|
|
69
|
+
/** How the job ended. */
|
|
70
|
+
readonly status: 'completed' | 'killed' | 'failed';
|
|
71
|
+
/** Terminal reason rendered into the model's status line. */
|
|
72
|
+
readonly detail?: string;
|
|
73
|
+
}
|
|
74
|
+
/** The producer face the registry hands to the starter. */
|
|
75
|
+
export interface JobHandleLike {
|
|
76
|
+
/** The registry-issued id (`<kind>-N`). */
|
|
77
|
+
readonly id: string;
|
|
78
|
+
/** Append one chunk to the output ring. */
|
|
79
|
+
append(text: string, options?: {
|
|
80
|
+
readonly channel?: 'stdout' | 'stderr' | 'log';
|
|
81
|
+
readonly gapBefore?: true;
|
|
82
|
+
}): void;
|
|
83
|
+
}
|
|
84
|
+
/** The controls the runtime observes producer work through. */
|
|
85
|
+
export interface JobHooksLike {
|
|
86
|
+
/** Request termination; synchronous, idempotent, and eventually settles `done`. */
|
|
87
|
+
cancel(reason?: string): void;
|
|
88
|
+
/** Resolves after the producer released its resources. */
|
|
89
|
+
readonly done: Promise<JobOutcomeLike>;
|
|
90
|
+
}
|
|
91
|
+
/** One production declaration, as much of it as this plugin uses. */
|
|
92
|
+
export interface JobSpecLike {
|
|
93
|
+
/** Producer kind, also the id prefix. */
|
|
94
|
+
kind: string;
|
|
95
|
+
/** One-line model-facing label. */
|
|
96
|
+
label: string;
|
|
97
|
+
/** Owning session; access to the job is fenced by it. */
|
|
98
|
+
owner?: string;
|
|
99
|
+
/** Pull sources the registry pumps into the ring. */
|
|
100
|
+
output?: readonly JobOutputSourceLike[];
|
|
101
|
+
/** Starts the work and synchronously returns its hooks. */
|
|
102
|
+
run(job: JobHandleLike): JobHooksLike;
|
|
103
|
+
}
|
|
104
|
+
/** The one registry method this module consumes. */
|
|
105
|
+
export interface JobRegistryLike {
|
|
106
|
+
/** Preflight, then atomically register the work. */
|
|
107
|
+
start(spec: JobSpecLike): string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* One command to run in its own pinned bash process.
|
|
111
|
+
*
|
|
112
|
+
* Both halves of the process contract are supplied by the caller: `argv` is
|
|
113
|
+
* the same pinned payload argv the session's persistent shell uses (this tool
|
|
114
|
+
* never consults PATH, and it refuses restricted sessions outright rather than
|
|
115
|
+
* confining them — see ./tool.ts), and `env` is the same environment.
|
|
116
|
+
*/
|
|
117
|
+
export interface BackgroundCommand {
|
|
118
|
+
/** The host's managed subprocess seam. */
|
|
119
|
+
readonly subprocess: SubprocessRuntime;
|
|
120
|
+
/** The job registry publishing this command's lifecycle. */
|
|
121
|
+
readonly jobs: JobRegistryLike;
|
|
122
|
+
/** The owning session id, so the job is collectable by that session alone. */
|
|
123
|
+
readonly owner?: string;
|
|
124
|
+
/** The command, exactly as the model wrote it (after any workdir prefix). */
|
|
125
|
+
readonly script: string;
|
|
126
|
+
/** The executable and its arguments: the pinned payload bash. */
|
|
127
|
+
readonly argv: readonly string[];
|
|
128
|
+
/** Working directory for the process. */
|
|
129
|
+
readonly cwd: string;
|
|
130
|
+
/** Environment entries for the process. */
|
|
131
|
+
readonly env: NodeJS.ProcessEnv;
|
|
132
|
+
/** Label shown for this job. */
|
|
133
|
+
readonly label: string;
|
|
134
|
+
/** In-memory capture ceiling for stdout, in bytes. */
|
|
135
|
+
readonly stdoutBytes: number;
|
|
136
|
+
/** In-memory capture ceiling for stderr, in bytes. */
|
|
137
|
+
readonly stderrBytes: number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Map a settled process onto the job-outcome vocabulary.
|
|
141
|
+
*
|
|
142
|
+
* A nonzero command exit is reported, not failed: the model reads the exit
|
|
143
|
+
* code in the job's detail line exactly as it reads one from a foreground
|
|
144
|
+
* call. `killed` is reserved for a process this tool terminated, which is the
|
|
145
|
+
* one case where the work did not reach its own end.
|
|
146
|
+
* @param outcome - the process exit facts.
|
|
147
|
+
* @param failedBeforeStart - the starter's failure, when nothing ran.
|
|
148
|
+
* @param terminated - whether this tool terminated the process.
|
|
149
|
+
* @returns the outcome for the registry.
|
|
150
|
+
*/
|
|
151
|
+
export declare function processOutcome(outcome: {
|
|
152
|
+
exitCode: number | null;
|
|
153
|
+
signal: NodeJS.Signals | null;
|
|
154
|
+
} | undefined, failedBeforeStart: string | undefined, terminated: boolean): JobOutcomeLike;
|
|
155
|
+
/**
|
|
156
|
+
* Register one command as a background job and return the registry's id.
|
|
157
|
+
*
|
|
158
|
+
* The process is spawned INSIDE the starter, after the registry's own
|
|
159
|
+
* admission: a refused registration (the owner's job limit, no attached
|
|
160
|
+
* controller) therefore leaves no process behind, and this function's caller
|
|
161
|
+
* has nothing to clean up on that path.
|
|
162
|
+
* @param command - the process, its wiring, and the registry to register with.
|
|
163
|
+
* @returns the job id the model collects it by.
|
|
164
|
+
*/
|
|
165
|
+
export declare function startBackgroundJob(command: BackgroundCommand): string;
|
|
166
|
+
/** Capture ceilings for one job's streams; exported so the tool and tests agree. */
|
|
167
|
+
export declare const BACKGROUND_STDOUT_BYTES: number;
|
|
168
|
+
/** In-memory stderr ceiling for one background job. */
|
|
169
|
+
export declare const BACKGROUND_STDERR_BYTES: number;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin configuration: the win_bash tool's budgets and description.
|
|
3
|
+
*
|
|
4
|
+
* Every field is optional in the profile patch and defaulted here, so a row
|
|
5
|
+
* with no config block still mounts a working tool. The schema is also the
|
|
6
|
+
* settings page: the Host renders one form per profile entry from this same
|
|
7
|
+
* Config, which is why the defaults are stated in the field comments as well
|
|
8
|
+
* as in the schema.
|
|
9
|
+
* @module @linxin666/dsh-win-bash/config
|
|
10
|
+
*/
|
|
11
|
+
import z from '@deepseek-ai/schemastery';
|
|
12
|
+
/** Whole-call deadline floor, in milliseconds. */
|
|
13
|
+
export declare const TIMEOUT_MIN_MS = 1000;
|
|
14
|
+
/** Whole-call deadline ceiling, in milliseconds. */
|
|
15
|
+
export declare const TIMEOUT_MAX_MS = 3600000;
|
|
16
|
+
/** Default whole-call deadline, matching the host's own persistent shell. */
|
|
17
|
+
export declare const DEFAULT_TIMEOUT_MS = 300000;
|
|
18
|
+
/** Visible stdout budget floor, in bytes. */
|
|
19
|
+
export declare const STDOUT_MIN_BYTES = 1024;
|
|
20
|
+
/** Visible stdout budget ceiling, in bytes. */
|
|
21
|
+
export declare const STDOUT_MAX_BYTES: number;
|
|
22
|
+
/** Visible stderr budget floor, in bytes. */
|
|
23
|
+
export declare const STDERR_MIN_BYTES = 1024;
|
|
24
|
+
/** Visible stderr budget ceiling, in bytes. */
|
|
25
|
+
export declare const STDERR_MAX_BYTES: number;
|
|
26
|
+
/**
|
|
27
|
+
* Whether win_bash follows the LiangShen agent preset's declaration by
|
|
28
|
+
* default. When true (the shipped setting) the tool registers only for a
|
|
29
|
+
* deployment that declares the `liangshen` preset; false skips the gate and
|
|
30
|
+
* always registers, which is the escape hatch for a session that wants this
|
|
31
|
+
* shell without the preset.
|
|
32
|
+
*/
|
|
33
|
+
export declare const DEFAULT_SYNC_WITH_LIANGSHEN = true;
|
|
34
|
+
/**
|
|
35
|
+
* Model-facing tool description. Active voice; states the shell preference and
|
|
36
|
+
* the persistence guarantee, so a model knows which shell to reach for before
|
|
37
|
+
* it knows anything else about this tool.
|
|
38
|
+
*
|
|
39
|
+
* The preference is a TRUNCATION CONTRACT, not a flourish: a preset that
|
|
40
|
+
* curates its catalog caps each uncurated line at 200 characters, so whatever
|
|
41
|
+
* sentence states which shell to use must fit in that window. The first
|
|
42
|
+
* sentence therefore carries it alone, and the qualification that follows
|
|
43
|
+
* explains the ladder without restating it.
|
|
44
|
+
*/
|
|
45
|
+
export declare const DEFAULT_DESCRIPTION: string;
|
|
46
|
+
/**
|
|
47
|
+
* Whether win_bash may run a command as a background job, by default.
|
|
48
|
+
*
|
|
49
|
+
* The shipped setting is true, matching the host's own bash tool. The flag is
|
|
50
|
+
* one half of a pair: the background surface is only advertised when this is
|
|
51
|
+
* true AND the deployment composes a job registry, because a tool that
|
|
52
|
+
* advertises a capability its deployment cannot honour teaches the model
|
|
53
|
+
* something false about the session.
|
|
54
|
+
*/
|
|
55
|
+
export declare const DEFAULT_ENABLE_RUN_IN_BACKGROUND = true;
|
|
56
|
+
/**
|
|
57
|
+
* Whether the host's pwsh tool is withdrawn from a session this plugin serves,
|
|
58
|
+
* by default.
|
|
59
|
+
*
|
|
60
|
+
* The shipped setting is true: with win_bash registered the session's command
|
|
61
|
+
* work belongs to bash, and leaving pwsh on the wire beside it is what makes a
|
|
62
|
+
* model pick the shell it already knows. The withdrawal is visibility only (a
|
|
63
|
+
* deliberate pwsh call still runs), so false is the escape hatch for an
|
|
64
|
+
* operator who wants both shells listed.
|
|
65
|
+
*/
|
|
66
|
+
export declare const DEFAULT_REPLACE_PWSH = true;
|
|
67
|
+
/** Config shape a profile row may supply; every field is optional. */
|
|
68
|
+
export interface WinBashConfigInput {
|
|
69
|
+
/** Whole-call deadline in milliseconds. */
|
|
70
|
+
timeoutMs?: number;
|
|
71
|
+
/** Visible stdout byte budget. */
|
|
72
|
+
maxStdoutBytes?: number;
|
|
73
|
+
/** Visible stderr byte budget. */
|
|
74
|
+
maxStderrBytes?: number;
|
|
75
|
+
/** Model-facing tool description override. */
|
|
76
|
+
description?: string;
|
|
77
|
+
/** Whether the tool's availability follows the LiangShen preset declaration. */
|
|
78
|
+
syncWithLiangShen?: boolean;
|
|
79
|
+
/** Whether the host's pwsh tool is hidden while win_bash is registered. */
|
|
80
|
+
replacePwsh?: boolean;
|
|
81
|
+
/** Whether run_in_background is available (also requires a job registry). */
|
|
82
|
+
enableRunInBackground?: boolean;
|
|
83
|
+
}
|
|
84
|
+
/** Config shape the plugin runs with; every field resolved. */
|
|
85
|
+
export interface WinBashConfig {
|
|
86
|
+
/** Whole-call deadline in milliseconds. */
|
|
87
|
+
timeoutMs: number;
|
|
88
|
+
/** Visible stdout byte budget. */
|
|
89
|
+
maxStdoutBytes: number;
|
|
90
|
+
/** Visible stderr byte budget. */
|
|
91
|
+
maxStderrBytes: number;
|
|
92
|
+
/** Model-facing tool description. */
|
|
93
|
+
description: string;
|
|
94
|
+
/** Whether the tool's availability follows the LiangShen preset declaration. */
|
|
95
|
+
syncWithLiangShen: boolean;
|
|
96
|
+
/** Whether the host's pwsh tool is hidden while win_bash is registered. */
|
|
97
|
+
replacePwsh: boolean;
|
|
98
|
+
/** Whether run_in_background is available (also requires a job registry). */
|
|
99
|
+
enableRunInBackground: boolean;
|
|
100
|
+
}
|
|
101
|
+
/** Runtime configuration schema for the win_bash tool. */
|
|
102
|
+
export declare const Config: z<WinBashConfigInput, WinBashConfig>;
|
|
103
|
+
/** The values an omitted field takes. */
|
|
104
|
+
export declare const CONFIG_DEFAULTS: WinBashConfig;
|
|
105
|
+
/** One rejected configuration field. */
|
|
106
|
+
export interface ConfigViolation {
|
|
107
|
+
/** Field name. */
|
|
108
|
+
readonly field: string;
|
|
109
|
+
/** Why the value cannot be used. */
|
|
110
|
+
readonly message: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Resolve a raw config object into the running configuration.
|
|
114
|
+
*
|
|
115
|
+
* The Host validates the row through {@link Config} before apply runs, so this
|
|
116
|
+
* is the second gate: it exists because tests and hand-built contexts call the
|
|
117
|
+
* plugin's apply directly, and because a bounded integer is a contract the
|
|
118
|
+
* shell's budgets depend on (a NaN budget would make every output look
|
|
119
|
+
* truncated).
|
|
120
|
+
* @param input - the raw config, or undefined.
|
|
121
|
+
* @returns the resolved configuration.
|
|
122
|
+
* @throws when a supplied value is outside its contract.
|
|
123
|
+
*/
|
|
124
|
+
export declare function resolveConfig(input: WinBashConfigInput | undefined): WinBashConfig;
|
|
125
|
+
/**
|
|
126
|
+
* Check every field of a resolved configuration.
|
|
127
|
+
* @param config - the candidate configuration.
|
|
128
|
+
* @returns one entry per rejected field; empty means accepted.
|
|
129
|
+
*/
|
|
130
|
+
export declare function validateConfig(config: WinBashConfig): ConfigViolation[];
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LiangShen availability gate for the win_bash tool.
|
|
3
|
+
*
|
|
4
|
+
* win_bash serves sessions that run the LiangShen (梁神) preset, so its
|
|
5
|
+
* availability follows that preset's DECLARATION: this gate asks the harness's
|
|
6
|
+
* agent-preset registry whether a preset with id liangshen is declared, and the
|
|
7
|
+
* entry registers no tool at all when it is not. The alternative — mounting a
|
|
8
|
+
* tool whose every call refuses — teaches the model a capability the session
|
|
9
|
+
* does not have, which is worse than an honest absence.
|
|
10
|
+
*
|
|
11
|
+
* The registry read is STRUCTURAL, not an import: this package does not depend
|
|
12
|
+
* on @deepseek-ai/dsh-agent-preset-registry (a leaf plugin takes no SDK
|
|
13
|
+
* dependency to read one optional service), so the single method consumed is
|
|
14
|
+
* mirrored from the published declaration of
|
|
15
|
+
* @deepseek-ai/dsh-agent-preset-registry@0.2.1-rc.2, lib/types/index.d.ts:
|
|
16
|
+
*
|
|
17
|
+
* export declare class AgentPresetRegistry {
|
|
18
|
+
* list(): Promise<AgentPreset[]>
|
|
19
|
+
* }
|
|
20
|
+
* export interface AgentPreset {
|
|
21
|
+
* readonly id: string
|
|
22
|
+
* readonly name?: string
|
|
23
|
+
* readonly broken?: string
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* list() is the registry's public DEFINITION roster: it resolves every declared
|
|
27
|
+
* definition, including activation failures (which each row reports), so it
|
|
28
|
+
* answers exactly the "is this preset declared here" question. The narrower
|
|
29
|
+
* resolve(id) cannot: it REJECTS for an undeclared id, so a probe built on it
|
|
30
|
+
* would have to read a rejection as "absent" and could not tell that apart from
|
|
31
|
+
* a real failure of a preset that IS declared.
|
|
32
|
+
*
|
|
33
|
+
* The service is read with ctx.get, never a hard inject: a deployment may
|
|
34
|
+
* compose no preset registry at all, and waiting on one would pend this row
|
|
35
|
+
* forever — which under the Host's boot gate fails the whole web boot rather
|
|
36
|
+
* than this one plugin (the trap dsh-liangshen documents as issue #1712).
|
|
37
|
+
*
|
|
38
|
+
* Timing. Two facts about the pieces this talks to shape the verdict:
|
|
39
|
+
*
|
|
40
|
+
* 1. Rows in one loader group mount concurrently (the loader starts every entry
|
|
41
|
+
* of a group in the same tick), so this row cannot assume the LiangShen row
|
|
42
|
+
* ran first. The verdict therefore waits for the Host plugin tree to settle
|
|
43
|
+
* before its first read, rather than reading during the boot race.
|
|
44
|
+
* 2. The declaration does not arrive with that row's activation return: the
|
|
45
|
+
* declaring plugin schedules it on its own detached promise chain (it
|
|
46
|
+
* persists module rows, so it cannot block activation on the mount). The
|
|
47
|
+
* tree can therefore settle one or more turns BEFORE the registry holds the
|
|
48
|
+
* definition, and a single read would answer "not declared" for a
|
|
49
|
+
* deployment that is about to declare it.
|
|
50
|
+
*
|
|
51
|
+
* So a read that already sees the declaration decides immediately and costs
|
|
52
|
+
* nothing; a read that does not re-reads on a bounded schedule until the
|
|
53
|
+
* declaration appears or the deadline passes. The wait is never paid in the
|
|
54
|
+
* common case, and it never turns a late declaration into a refusal. It runs
|
|
55
|
+
* entirely off the plugin's activation path (see the entry), so it delays no
|
|
56
|
+
* boot work; it only decides when win_bash becomes available.
|
|
57
|
+
*
|
|
58
|
+
* The registry exposes NO declaration-change event. Its only declared preset
|
|
59
|
+
* event is agent-preset/selected, which records one SESSION's committed preset
|
|
60
|
+
* to that session's durable log (lib/types/types.d.ts) and says nothing about
|
|
61
|
+
* the roster. The verdict is therefore decided once per mount, and a switch
|
|
62
|
+
* toggle takes effect through the plugin manager's row refresh, which remounts
|
|
63
|
+
* this row and re-runs the gate — the same freshness model the family's row
|
|
64
|
+
* ledger uses.
|
|
65
|
+
* @module @linxin666/dsh-win-bash/gate
|
|
66
|
+
*/
|
|
67
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
68
|
+
/** Preset id whose declaration makes win_bash available. */
|
|
69
|
+
export declare const LIANGSHEN_PRESET_ID = "liangshen";
|
|
70
|
+
/** Upper bound on the wait for the Host plugin tree to settle, in milliseconds. */
|
|
71
|
+
export declare const GATE_SETTLE_TIMEOUT_MS = 10000;
|
|
72
|
+
/** Upper bound on one registry roster read, in milliseconds. */
|
|
73
|
+
export declare const GATE_READ_TIMEOUT_MS = 10000;
|
|
74
|
+
/**
|
|
75
|
+
* How long a roster that does not yet declare LiangShen keeps being re-read,
|
|
76
|
+
* in milliseconds. See the module header: the declaring plugin publishes the
|
|
77
|
+
* definition on a detached chain, so the tree can settle first. Only paid when
|
|
78
|
+
* the declaration is genuinely absent, since a visible one returns at once.
|
|
79
|
+
*/
|
|
80
|
+
export declare const GATE_DECLARATION_WAIT_MS = 5000;
|
|
81
|
+
/** Re-read cadence during {@link GATE_DECLARATION_WAIT_MS}, in milliseconds. */
|
|
82
|
+
export declare const GATE_POLL_INTERVAL_MS = 250;
|
|
83
|
+
/**
|
|
84
|
+
* The deadlines and cadence one gate run uses. The defaults are the shipped
|
|
85
|
+
* values; tests pass small ones so a bounded wait is exercised without a slow
|
|
86
|
+
* suite.
|
|
87
|
+
*/
|
|
88
|
+
export interface GateOptions {
|
|
89
|
+
/** Bound on the Host plugin-tree settle wait, in milliseconds. */
|
|
90
|
+
settleTimeoutMs?: number;
|
|
91
|
+
/** Bound on one registry roster read, in milliseconds. */
|
|
92
|
+
readTimeoutMs?: number;
|
|
93
|
+
/** Total time a late declaration may take to appear, in milliseconds. */
|
|
94
|
+
declarationWaitMs?: number;
|
|
95
|
+
/** Re-read cadence during that wait, in milliseconds. */
|
|
96
|
+
pollIntervalMs?: number;
|
|
97
|
+
}
|
|
98
|
+
/** One roster row, as much of it as this gate reads. */
|
|
99
|
+
export interface PresetRosterRow {
|
|
100
|
+
/** Stable preset identifier. */
|
|
101
|
+
readonly id: string;
|
|
102
|
+
}
|
|
103
|
+
/** The one registry method this gate consumes. */
|
|
104
|
+
export interface PresetRosterReader {
|
|
105
|
+
/** Read every declared preset, including activation failures. */
|
|
106
|
+
list(): Promise<readonly PresetRosterRow[]>;
|
|
107
|
+
}
|
|
108
|
+
/** Why the gate reached its verdict. */
|
|
109
|
+
export type GateReason =
|
|
110
|
+
/** The registry declares the LiangShen preset. */
|
|
111
|
+
'declared'
|
|
112
|
+
/** The registry answered and declares no preset with the LiangShen id. */
|
|
113
|
+
| 'not-declared'
|
|
114
|
+
/** No agent-preset registry usable for this read is published. */
|
|
115
|
+
| 'registry-absent'
|
|
116
|
+
/** A registry is published, but its roster never answered. */
|
|
117
|
+
| 'registry-unreadable';
|
|
118
|
+
/** How far the Host plugin-tree settle got before the roster was read. */
|
|
119
|
+
export type SettleStatus =
|
|
120
|
+
/** Every Host loader entry and plugin lifecycle task finished. */
|
|
121
|
+
'settled'
|
|
122
|
+
/** No loader service is published, so there was nothing to settle. */
|
|
123
|
+
| 'unavailable'
|
|
124
|
+
/** The tree did not settle within the settle bound. */
|
|
125
|
+
| 'timed-out';
|
|
126
|
+
/** The gate's verdict: whether win_bash may register, and why. */
|
|
127
|
+
export interface GateOutcome {
|
|
128
|
+
/** True only for {@link GateReason} declared. */
|
|
129
|
+
readonly allowed: boolean;
|
|
130
|
+
/** The reason, for the caller's log line. */
|
|
131
|
+
readonly reason: GateReason;
|
|
132
|
+
/** Whether the Host tree settled before the roster was read. */
|
|
133
|
+
readonly settled: SettleStatus;
|
|
134
|
+
/** How many roster reads the verdict cost. */
|
|
135
|
+
readonly reads: number;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Whether a roster declares the preset this tool follows.
|
|
139
|
+
* @param presets - rows as {@link PresetRosterReader.list} returns them.
|
|
140
|
+
* @returns true when one row carries the LiangShen id.
|
|
141
|
+
*/
|
|
142
|
+
export declare function declaresLiangShen(presets: readonly PresetRosterRow[]): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* The published registry, when this deployment has one shaped like the one this
|
|
145
|
+
* gate consumes.
|
|
146
|
+
* @param ctx - the plugin context.
|
|
147
|
+
* @returns the reader, or undefined when no usable registry is published.
|
|
148
|
+
*/
|
|
149
|
+
export declare function readPresetRegistry(ctx: Context): PresetRosterReader | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* Wait until the Host loader tree has no pending import or lifecycle work.
|
|
152
|
+
*
|
|
153
|
+
* Waiting for the whole tree rather than this row's neighbours is deliberate:
|
|
154
|
+
* the roster belongs to the deployment, not to one group, and the loader's own
|
|
155
|
+
* await() is the only predicate that means "every row has been applied". A row
|
|
156
|
+
* merely waiting for a service it will never get carries no pending task, so it
|
|
157
|
+
* cannot hold this wait open; one that is genuinely mid-activation can, which is
|
|
158
|
+
* exactly the case the bound covers.
|
|
159
|
+
* @param ctx - the plugin context.
|
|
160
|
+
* @param options - the deadlines for this run.
|
|
161
|
+
* @returns how far the settle got.
|
|
162
|
+
*/
|
|
163
|
+
export declare function settleHostTree(ctx: Context, options?: GateOptions): Promise<SettleStatus>;
|
|
164
|
+
/**
|
|
165
|
+
* Decide whether the LiangShen preset is declared in this deployment.
|
|
166
|
+
*
|
|
167
|
+
* Call this OFF the plugin's activation path — never awaited from a plugin
|
|
168
|
+
* apply. list() is not a leaf read: it audits every declared preset and, for one
|
|
169
|
+
* whose mounted subtree still has pending rows, awaits the Host loader tree
|
|
170
|
+
* (agent-preset-registry lib/index.js diagnostic). A plugin whose activation
|
|
171
|
+
* awaited this would wait on the loader tree while its OWN activation is among
|
|
172
|
+
* the tasks that tree is waiting for, and neither wait would ever settle. The
|
|
173
|
+
* entry calls this after its synchronous activation returned, which is what
|
|
174
|
+
* keeps this a wait and not a deadlock.
|
|
175
|
+
* @param ctx - the plugin context.
|
|
176
|
+
* @param options - the deadlines and cadence for this run.
|
|
177
|
+
* @returns the verdict, with the reason for the caller's log line.
|
|
178
|
+
*/
|
|
179
|
+
export declare function startLiangShenGate(ctx: Context, options?: GateOptions): Promise<GateOutcome>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-half entry for the dsh-win-bash plugin.
|
|
3
|
+
*
|
|
4
|
+
* The plugin owns exactly one model-facing capability — the win_bash tool over
|
|
5
|
+
* a per-session persistent bash process — and nothing else. It registers no
|
|
6
|
+
* settings section, no HTTP route and no browser half: the Host renders the
|
|
7
|
+
* configuration form for this row from the exported Config schema.
|
|
8
|
+
*
|
|
9
|
+
* Mount-time integrity: before the tool is registered at all, the vendored
|
|
10
|
+
* payload is checked against its shipped SHA256 manifest. A mismatch refuses
|
|
11
|
+
* the mount with a specific message rather than running commands through
|
|
12
|
+
* bytes nobody verified. The tool is also refused on every non-Windows host
|
|
13
|
+
* and on a Windows host that is not x64, because no PATH bash is ever used as
|
|
14
|
+
* a substitute.
|
|
15
|
+
*
|
|
16
|
+
* Availability gate: win_bash serves sessions that run the LiangShen (梁神)
|
|
17
|
+
* preset, so its registration follows that preset's DECLARATION in the
|
|
18
|
+
* harness's agent-preset registry — declared means registered, undeclared
|
|
19
|
+
* means the tool is never registered and one info line says why. The gate's
|
|
20
|
+
* config escape hatch is syncWithLiangShen: false, which skips it and always
|
|
21
|
+
* registers. See ./gate.ts for the API the gate reads and the timing
|
|
22
|
+
* constraints it satisfies.
|
|
23
|
+
*
|
|
24
|
+
* Host shell replacement: once win_bash is registered, the host's own pwsh
|
|
25
|
+
* tool is withdrawn from each session win_bash can actually SERVE - the
|
|
26
|
+
* sessions whose own sandbox mode is danger-full-access - so their command work
|
|
27
|
+
* goes to bash rather than to the shell a model already knows. A session in any
|
|
28
|
+
* other mode keeps its pwsh, because win_bash refuses to run there and pwsh is
|
|
29
|
+
* then the only shell it has. Windows only, visibility only, per agent scope,
|
|
30
|
+
* and re-evaluated when a session switches mode; see ./pwsh-replacement.ts for
|
|
31
|
+
* why it is neither global nor an execution denial.
|
|
32
|
+
*
|
|
33
|
+
* Lifecycle: one shell process per calling agent, released when that agent is
|
|
34
|
+
* disposed and when the plugin fiber unloads. The pwsh restriction follows the
|
|
35
|
+
* same lifecycle, lifted with the agent and with the fiber. apply() returns as
|
|
36
|
+
* soon as the plugin is configured: the gate decides in mountWithGate, whose
|
|
37
|
+
* promise is deliberately NOT returned from apply (see that function).
|
|
38
|
+
* @module @linxin666/dsh-win-bash
|
|
39
|
+
*/
|
|
40
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
41
|
+
import { Config, type WinBashConfig, type WinBashConfigInput } from './config.ts';
|
|
42
|
+
import { type GateOptions, type GateOutcome } from './gate.ts';
|
|
43
|
+
import { type RuntimeReady } from './runtime.ts';
|
|
44
|
+
export { BACKGROUND_JOB_KIND, startBackgroundJob } from './background.ts';
|
|
45
|
+
export type { BackgroundCommand, JobHandleLike, JobHooksLike, JobOutcomeLike, JobOutputSourceLike, JobRegistryLike, JobSourceReadLike, } from './background.ts';
|
|
46
|
+
export { Config };
|
|
47
|
+
export type { WinBashConfig, WinBashConfigInput };
|
|
48
|
+
export { CONFIG_DEFAULTS, DEFAULT_DESCRIPTION, DEFAULT_ENABLE_RUN_IN_BACKGROUND, DEFAULT_REPLACE_PWSH, DEFAULT_SYNC_WITH_LIANGSHEN, validateConfig, } from './config.ts';
|
|
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, stripTerminalEscapes, truncationNotice } from './tool.ts';
|
|
51
|
+
export type { RenderFacts } from './tool.ts';
|
|
52
|
+
export { ShellRegistry, ShellUnavailableError, shellArgv, shellEnvironment, shellTempDir, } from './shell.ts';
|
|
53
|
+
export { buildFrame, markerFor, parseFrame } from './protocol.ts';
|
|
54
|
+
export { GATE_DECLARATION_WAIT_MS, GATE_POLL_INTERVAL_MS, GATE_READ_TIMEOUT_MS, GATE_SETTLE_TIMEOUT_MS, LIANGSHEN_PRESET_ID, declaresLiangShen, readPresetRegistry, settleHostTree, startLiangShenGate, type GateOptions, type GateOutcome, type GateReason, type PresetRosterReader, type PresetRosterRow, type SettleStatus, } from './gate.ts';
|
|
55
|
+
export { bashPath, parseChecksums, resolveRuntime, runtimeRoot, shPath, verifyPayload, } from './runtime.ts';
|
|
56
|
+
/** Cordis plugin name; also the loader row id this package mounts under. */
|
|
57
|
+
export declare const name = "dsh-win-bash";
|
|
58
|
+
/** Required services: the tool registry and the managed subprocess seam. */
|
|
59
|
+
export declare const inject: string[];
|
|
60
|
+
/**
|
|
61
|
+
* One human-readable line explaining a refused gate verdict.
|
|
62
|
+
* @param outcome - the gate's verdict.
|
|
63
|
+
* @returns the message the entry logs.
|
|
64
|
+
*/
|
|
65
|
+
export declare function gateRefusalMessage(outcome: GateOutcome): string;
|
|
66
|
+
/**
|
|
67
|
+
* Register the win_bash tool and its per-session shell registry on the calling
|
|
68
|
+
* fiber. Called only once per fiber: the caller decides whether to call at all.
|
|
69
|
+
*
|
|
70
|
+
* The host pwsh replacement is installed from HERE and not from the gate or
|
|
71
|
+
* apply, because its precondition is exactly "win_bash is now on the wire": a
|
|
72
|
+
* deployment whose gate refused, whose payload failed verification, or that
|
|
73
|
+
* runs on a POSIX host never reaches this function and therefore never touches
|
|
74
|
+
* the host's shell.
|
|
75
|
+
* @param ctx - context carrying tools and subprocess.
|
|
76
|
+
* @param config - the resolved configuration.
|
|
77
|
+
* @param runtime - the verified payload paths.
|
|
78
|
+
*/
|
|
79
|
+
export declare function registerWinBash(ctx: Context, config: WinBashConfig, runtime: RuntimeReady): void;
|
|
80
|
+
/**
|
|
81
|
+
* Apply the availability gate, then register the tool when it allows it.
|
|
82
|
+
*
|
|
83
|
+
* The returned promise is deliberately NOT awaited by apply: the gate's roster
|
|
84
|
+
* read audits every declared preset and can await the Host loader tree, which
|
|
85
|
+
* still counts this very activation among its pending tasks — awaiting it from
|
|
86
|
+
* inside the activation would make the two waits depend on each other and
|
|
87
|
+
* neither would settle. Keeping the decision off the activation path also
|
|
88
|
+
* keeps the loader entry's own inertia free of it, so the tree can settle.
|
|
89
|
+
*
|
|
90
|
+
* A fiber disposed while the gate was deciding registers nothing: its tool
|
|
91
|
+
* effect would be refused anyway, and its shells would outlive it.
|
|
92
|
+
* @param ctx - context carrying tools and subprocess.
|
|
93
|
+
* @param config - the resolved configuration.
|
|
94
|
+
* @param runtime - the verified payload paths.
|
|
95
|
+
* @param options - gate deadlines; the defaults are the shipped bounds.
|
|
96
|
+
* @returns the decision, for the caller to observe (never rejects).
|
|
97
|
+
*/
|
|
98
|
+
export declare function mountWithGate(ctx: Context, config: WinBashConfig, runtime: RuntimeReady, options?: GateOptions): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Mount the plugin.
|
|
101
|
+
* @param ctx - context carrying tools and subprocess.
|
|
102
|
+
* @param config - the row's config, validated by {@link Config}.
|
|
103
|
+
*/
|
|
104
|
+
export declare function apply(ctx: Context, config?: WinBashConfigInput): void;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire protocol for the session's persistent bash shell.
|
|
3
|
+
*
|
|
4
|
+
* The shell is one long-lived 'bash -s' process per session, so every tool
|
|
5
|
+
* call must (a) inject its command without racing the previous one and (b)
|
|
6
|
+
* find the exact end of that command's output and its exit status inside one
|
|
7
|
+
* continuous byte stream. Both jobs ride this module and nothing else, so the
|
|
8
|
+
* framing is unit-testable without a process.
|
|
9
|
+
*
|
|
10
|
+
* Frame shape, written on stdin for each call:
|
|
11
|
+
*
|
|
12
|
+
* printf '\n%s\n' '<M>BEGIN'
|
|
13
|
+
* . /dev/stdin <<'<M>END'
|
|
14
|
+
* <the model's command, verbatim, any number of lines>
|
|
15
|
+
* <M>END
|
|
16
|
+
* __dsh_win_bash_status=$?
|
|
17
|
+
* printf '\n%s%d\n' '<M>END' "$__dsh_win_bash_status"
|
|
18
|
+
*
|
|
19
|
+
* Why a heredoc and not a plain brace-group: the shell parses a brace group
|
|
20
|
+
* one command at a time, so a syntactic error inside it aborts the REST of the
|
|
21
|
+
* group — a model line with an unterminated quote would swallow the end marker
|
|
22
|
+
* and leave the call (and the shell) wedged forever. The command is therefore
|
|
23
|
+
* read through a heredoc into the source builtin, which the shell parses as
|
|
24
|
+
* ONE unit: a syntax error is reported and the shell moves on to the next
|
|
25
|
+
* line, where the status capture and the end marker still run. Measured on the
|
|
26
|
+
* vendored bash: an unterminated quote produces 'unexpected EOF while looking
|
|
27
|
+
* for matching' on stderr, and the very next call succeeds on the same
|
|
28
|
+
* process.
|
|
29
|
+
*
|
|
30
|
+
* The begin/end markers carry a per-call nonce, so a command cannot forge the
|
|
31
|
+
* end of its own frame even if it echoes marker-shaped text.
|
|
32
|
+
* @module @linxin666/dsh-win-bash/protocol
|
|
33
|
+
*/
|
|
34
|
+
/** Literal prefix of every frame marker; the nonce follows it. */
|
|
35
|
+
export declare const MARKER_PREFIX = "__DSH_WIN_BASH_";
|
|
36
|
+
/** Suffix closing the nonce, keeping the marker a single shell word. */
|
|
37
|
+
export declare const MARKER_SUFFIX = "__";
|
|
38
|
+
/** Begin/end marker pair for one call. */
|
|
39
|
+
export interface FrameMarker {
|
|
40
|
+
/** Printed before the command runs; the command's output follows it. */
|
|
41
|
+
readonly begin: string;
|
|
42
|
+
/** Printed after the command's status is captured; the digits follow it. */
|
|
43
|
+
readonly end: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build the marker pair for one call. The nonce is stripped to alphanumerics
|
|
47
|
+
* so the markers stay valid heredoc delimiters and single shell words.
|
|
48
|
+
* @param nonce - caller-supplied uniqueness source (a UUID).
|
|
49
|
+
* @returns the begin/end markers, both printable and both nonce-bearing.
|
|
50
|
+
*/
|
|
51
|
+
export declare function markerFor(nonce: string): FrameMarker;
|
|
52
|
+
/**
|
|
53
|
+
* Render the stdin frame for one command. The command is inserted verbatim:
|
|
54
|
+
* the heredoc is quoted, so the shell performs no expansion on it while
|
|
55
|
+
* reading, and the sourced text is executed exactly as the model wrote it.
|
|
56
|
+
* @param command - the model's command, any number of lines.
|
|
57
|
+
* @param marker - the markers for this call.
|
|
58
|
+
* @returns the text to write to the shell's stdin, newline-terminated.
|
|
59
|
+
*/
|
|
60
|
+
export declare function buildFrame(command: string, marker: FrameMarker): string;
|
|
61
|
+
/** One complete command frame recovered from the output stream. */
|
|
62
|
+
export interface FrameOutcome {
|
|
63
|
+
/** The command's stdout: everything between the two markers, verbatim. */
|
|
64
|
+
readonly stdout: string;
|
|
65
|
+
/** The command's exit status. */
|
|
66
|
+
readonly exitCode: number;
|
|
67
|
+
/**
|
|
68
|
+
* Whether the begin marker had already slid out of the retained output
|
|
69
|
+
* window, so 'stdout' is a suffix of the real output rather than all of it.
|
|
70
|
+
*/
|
|
71
|
+
readonly lostPrefix: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Recover one command's stdout and exit status from accumulated output.
|
|
75
|
+
* Unframed or still-running text returns undefined, so the caller keeps
|
|
76
|
+
* waiting instead of reporting a truncated result.
|
|
77
|
+
* @param text - accumulated stdout for the current call.
|
|
78
|
+
* @param marker - the markers for this call.
|
|
79
|
+
* @param sawBegin - whether the begin marker was observed before the window slid.
|
|
80
|
+
* @returns the outcome once the end marker and its digits arrived.
|
|
81
|
+
*/
|
|
82
|
+
export declare function parseFrame(text: string, marker: FrameMarker, sawBegin: boolean): FrameOutcome | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Whether a frame's END marker is already visible in the accumulated text.
|
|
85
|
+
* A cheap pre-check used to decide when to run the full parse.
|
|
86
|
+
* @param text - accumulated stdout for the current call.
|
|
87
|
+
* @param marker - the markers for this call.
|
|
88
|
+
* @returns true once the end marker appears.
|
|
89
|
+
*/
|
|
90
|
+
export declare function hasEndMarker(text: string, marker: FrameMarker): boolean;
|