@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.
Files changed (118) hide show
  1. package/LICENSE +202 -0
  2. package/PROVENANCE.md +215 -0
  3. package/README.i18n.yaml +6 -0
  4. package/README.md +264 -2
  5. package/README.zh.md +221 -0
  6. package/cordis.patch.yml +13 -0
  7. package/lib/index.js +2756 -0
  8. package/lib/types/background.d.ts +169 -0
  9. package/lib/types/config.d.ts +130 -0
  10. package/lib/types/gate.d.ts +179 -0
  11. package/lib/types/index.d.ts +104 -0
  12. package/lib/types/protocol.d.ts +90 -0
  13. package/lib/types/pwsh-replacement.d.ts +140 -0
  14. package/lib/types/runtime.d.ts +115 -0
  15. package/lib/types/shell.d.ts +184 -0
  16. package/lib/types/tool.d.ts +123 -0
  17. package/package.json +58 -3
  18. package/runtime/win32-x64/checksums.sha256 +91 -0
  19. package/runtime/win32-x64/etc/bash.bashrc +69 -0
  20. package/runtime/win32-x64/etc/fstab +6 -0
  21. package/runtime/win32-x64/etc/msystem +27 -0
  22. package/runtime/win32-x64/etc/msystem.d/CLANG64 +7 -0
  23. package/runtime/win32-x64/etc/msystem.d/CLANGARM64 +7 -0
  24. package/runtime/win32-x64/etc/msystem.d/MINGW32 +7 -0
  25. package/runtime/win32-x64/etc/msystem.d/MINGW64 +7 -0
  26. package/runtime/win32-x64/etc/msystem.d/MSYS +4 -0
  27. package/runtime/win32-x64/etc/msystem.d/UCRT64 +7 -0
  28. package/runtime/win32-x64/etc/nsswitch.conf +12 -0
  29. package/runtime/win32-x64/etc/package-versions.txt +67 -0
  30. package/runtime/win32-x64/etc/profile +146 -0
  31. package/runtime/win32-x64/etc/profile.d/bash_profile.sh +11 -0
  32. package/runtime/win32-x64/etc/profile.d/lang.sh +19 -0
  33. package/runtime/win32-x64/licenses/GPL-2.0.txt +338 -0
  34. package/runtime/win32-x64/licenses/GPL-3.0.txt +674 -0
  35. package/runtime/win32-x64/licenses/LGPL-2.1.txt +501 -0
  36. package/runtime/win32-x64/licenses/LGPL-3.0.txt +165 -0
  37. package/runtime/win32-x64/licenses/expat-COPYING.txt +21 -0
  38. package/runtime/win32-x64/licenses/gcc-libs-RUNTIME.LIBRARY.EXCEPTION.txt +73 -0
  39. package/runtime/win32-x64/licenses/gettext-runtime-COPYING.LIB.txt +501 -0
  40. package/runtime/win32-x64/licenses/gettext-runtime-COPYING.txt +13 -0
  41. package/runtime/win32-x64/licenses/git-for-windows-LICENSE.txt +360 -0
  42. package/runtime/win32-x64/licenses/heimdal-LICENSE.txt +33 -0
  43. package/runtime/win32-x64/licenses/libcbor-LICENSE.md +21 -0
  44. package/runtime/win32-x64/licenses/libffi-LICENSE.txt +21 -0
  45. package/runtime/win32-x64/licenses/libfido2-LICENSE.txt +26 -0
  46. package/runtime/win32-x64/licenses/libiconv-COPYING.LIB.txt +501 -0
  47. package/runtime/win32-x64/licenses/libiconv-COPYING.txt +674 -0
  48. package/runtime/win32-x64/licenses/libopenssl-LICENSE.txt +177 -0
  49. package/runtime/win32-x64/licenses/libpcre-LICENCE.txt +93 -0
  50. package/runtime/win32-x64/licenses/libsqlite-LICENSE +25 -0
  51. package/runtime/win32-x64/licenses/ncurses-LICENSE +29 -0
  52. package/runtime/win32-x64/licenses/openssh-LICENCE.txt +412 -0
  53. package/runtime/win32-x64/licenses/zlib-LICENSE +22 -0
  54. package/runtime/win32-x64/usr/bin/awk.exe +0 -0
  55. package/runtime/win32-x64/usr/bin/b2sum.exe +0 -0
  56. package/runtime/win32-x64/usr/bin/basename.exe +0 -0
  57. package/runtime/win32-x64/usr/bin/basenc.exe +0 -0
  58. package/runtime/win32-x64/usr/bin/bash.exe +0 -0
  59. package/runtime/win32-x64/usr/bin/cat.exe +0 -0
  60. package/runtime/win32-x64/usr/bin/cmp.exe +0 -0
  61. package/runtime/win32-x64/usr/bin/comm.exe +0 -0
  62. package/runtime/win32-x64/usr/bin/cp.exe +0 -0
  63. package/runtime/win32-x64/usr/bin/cut.exe +0 -0
  64. package/runtime/win32-x64/usr/bin/dash.exe +0 -0
  65. package/runtime/win32-x64/usr/bin/date.exe +0 -0
  66. package/runtime/win32-x64/usr/bin/diff.exe +0 -0
  67. package/runtime/win32-x64/usr/bin/diff3.exe +0 -0
  68. package/runtime/win32-x64/usr/bin/dirname.exe +0 -0
  69. package/runtime/win32-x64/usr/bin/echo.exe +0 -0
  70. package/runtime/win32-x64/usr/bin/env.exe +0 -0
  71. package/runtime/win32-x64/usr/bin/expr.exe +0 -0
  72. package/runtime/win32-x64/usr/bin/false.exe +0 -0
  73. package/runtime/win32-x64/usr/bin/find.exe +0 -0
  74. package/runtime/win32-x64/usr/bin/grep.exe +0 -0
  75. package/runtime/win32-x64/usr/bin/head.exe +0 -0
  76. package/runtime/win32-x64/usr/bin/ls.exe +0 -0
  77. package/runtime/win32-x64/usr/bin/mkdir.exe +0 -0
  78. package/runtime/win32-x64/usr/bin/mktemp.exe +0 -0
  79. package/runtime/win32-x64/usr/bin/msys-2.0.dll +0 -0
  80. package/runtime/win32-x64/usr/bin/msys-gcc_s-seh-1.dll +0 -0
  81. package/runtime/win32-x64/usr/bin/msys-gmp-10.dll +0 -0
  82. package/runtime/win32-x64/usr/bin/msys-iconv-2.dll +0 -0
  83. package/runtime/win32-x64/usr/bin/msys-intl-8.dll +0 -0
  84. package/runtime/win32-x64/usr/bin/msys-mpfr-6.dll +0 -0
  85. package/runtime/win32-x64/usr/bin/msys-ncursesw6.dll +0 -0
  86. package/runtime/win32-x64/usr/bin/msys-pcre-1.dll +0 -0
  87. package/runtime/win32-x64/usr/bin/msys-readline8.dll +0 -0
  88. package/runtime/win32-x64/usr/bin/mv.exe +0 -0
  89. package/runtime/win32-x64/usr/bin/pathchk.exe +0 -0
  90. package/runtime/win32-x64/usr/bin/printf.exe +0 -0
  91. package/runtime/win32-x64/usr/bin/pwd.exe +0 -0
  92. package/runtime/win32-x64/usr/bin/readlink.exe +0 -0
  93. package/runtime/win32-x64/usr/bin/rm.exe +0 -0
  94. package/runtime/win32-x64/usr/bin/rmdir.exe +0 -0
  95. package/runtime/win32-x64/usr/bin/sdiff.exe +0 -0
  96. package/runtime/win32-x64/usr/bin/sed.exe +0 -0
  97. package/runtime/win32-x64/usr/bin/seq.exe +0 -0
  98. package/runtime/win32-x64/usr/bin/sh.exe +0 -0
  99. package/runtime/win32-x64/usr/bin/sleep.exe +0 -0
  100. package/runtime/win32-x64/usr/bin/sort.exe +0 -0
  101. package/runtime/win32-x64/usr/bin/tail.exe +0 -0
  102. package/runtime/win32-x64/usr/bin/test.exe +0 -0
  103. package/runtime/win32-x64/usr/bin/touch.exe +0 -0
  104. package/runtime/win32-x64/usr/bin/tr.exe +0 -0
  105. package/runtime/win32-x64/usr/bin/true.exe +0 -0
  106. package/runtime/win32-x64/usr/bin/uname.exe +0 -0
  107. package/runtime/win32-x64/usr/bin/uniq.exe +0 -0
  108. package/runtime/win32-x64/usr/bin/wc.exe +0 -0
  109. package/runtime/win32-x64/usr/bin/xargs.exe +0 -0
  110. package/src/background.ts +270 -0
  111. package/src/config.ts +209 -0
  112. package/src/gate.ts +308 -0
  113. package/src/index.ts +277 -0
  114. package/src/protocol.ts +130 -0
  115. package/src/pwsh-replacement.ts +435 -0
  116. package/src/runtime.ts +240 -0
  117. package/src/shell.ts +630 -0
  118. package/src/tool.ts +481 -0
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Host pwsh replacement: while this plugin's win_bash tool actually SERVES a
3
+ * session, the host's own PowerShell tool comes off that session's
4
+ * model-facing surface.
5
+ *
6
+ * WHY. The session then carries two shells, and nothing in either tool's
7
+ * schema says which one to reach for first: a model defaults to the shell it
8
+ * knows, which on Windows is pwsh, so bash-syntax commands keep arriving at a
9
+ * PowerShell that answers them with a syntax error. Hiding pwsh is what makes
10
+ * the preference structural instead of advisory — the ladder is win_bash
11
+ * first, and pwsh stays the fallback for the Windows-native work only it can
12
+ * do.
13
+ *
14
+ * WITHDRAWN ONLY WHERE WIN_BASH CAN SERVE. The precondition is "win_bash can
15
+ * serve this session", never "win_bash is mounted". win_bash runs only in a
16
+ * danger-full-access session (see ./tool.ts and the measured MSYS limitation in
17
+ * the package README): under any restricted mode it refuses every call before a
18
+ * process is started. Taking pwsh away there would leave the session with NO
19
+ * shell at all — win_bash refuses, and the shell that would have run the
20
+ * command is gone - which is precisely the capability loss this module exists
21
+ * to prevent. So a session keeps its pwsh unless its OWN policy reads
22
+ * danger-full-access.
23
+ *
24
+ * AN UNREADABLE POLICY IS NOT A YES. When the deployment composes no sandbox
25
+ * policy service, when the service throws, when it answers with a mode outside
26
+ * the closed vocabulary, or when the agent exposes no session to ask about,
27
+ * this module does NOT withdraw: win_bash refuses to run in exactly those
28
+ * deployments, so the session would lose its only usable shell on the strength
29
+ * of a guess that cannot be verified. The failure direction is deliberate and
30
+ * one-way — a session that keeps a shell it did not need is a preference not
31
+ * yet applied; a session that loses the only shell it had cannot run anything.
32
+ *
33
+ * THE MODE CAN CHANGE MID-SESSION. A permission-preset switch appends one
34
+ * `sandbox/mode` event to that session's log, so "can win_bash serve this
35
+ * session" is not a boot-time fact. The module re-evaluates on the same
36
+ * `internal/dispatch` seam terminal-bash uses for the identical purpose:
37
+ * entering a restricted mode releases the restriction immediately, and
38
+ * returning to danger-full-access withdraws again. The listener is registered
39
+ * with `{ global: true }` because a session's own log event is not dispatched to
40
+ * this plugin's scope, and it re-evaluates synchronously — no poll, no timer,
41
+ * nothing on a boot path.
42
+ *
43
+ * WINDOWS ONLY. The ladder this module encodes is a Windows fact: win_bash is
44
+ * the pinned MSYS2 shell a Windows session gets, and the host shell beside it
45
+ * is PowerShell. POSIX sessions keep exactly the behavior they had — the
46
+ * host's shell there is bash, which is not on the deny list in any case, and
47
+ * this module returns before it reads, listens to, or restricts anything.
48
+ *
49
+ * VISIBILITY ONLY, DELIBERATELY. This module withdraws the tool from the wire
50
+ * and from the generated SDK; it installs no execution guard and no
51
+ * pre-execute denial. A model that has a reason to call pwsh anyway — a
52
+ * Windows-native cmdlet, or a fallback after win_bash failed - must still
53
+ * reach it, which is the ladder's lower rung. A hard refusal here would trade
54
+ * a preference for a capability loss.
55
+ *
56
+ * SCOPED, NEVER GLOBAL. The restriction is installed through each agent's own
57
+ * scoped tools view (`agent.ctx.tools.restrict`), so it covers exactly the
58
+ * sessions win_bash serves and nothing else in the process. A deployment that
59
+ * mounts no win_bash (a refused gate, a missing payload, a non-Windows host,
60
+ * or `replacePwsh: false`) never calls this module at all.
61
+ *
62
+ * TIMING. The host's pwsh is registered by the host's own composition, whose
63
+ * group can settle after this plugin mounts, so a name that is not on the
64
+ * readable surface yet is not a verdict: the registry's own `tools/change`
65
+ * event retries every agent this module watches. Nothing here waits, polls, or
66
+ * holds a boot path open.
67
+ *
68
+ * LIFECYCLE. Every restriction is remembered per agent scope and lifted when
69
+ * that agent is disposed or when this plugin unloads, one isolated callback at
70
+ * a time: a throwing lift must not leave the remaining sessions with a shell
71
+ * they cannot see, and it must not leave the map holding a dead scope.
72
+ * @module @linxin666/dsh-win-bash/pwsh-replacement
73
+ */
74
+ import type { Context } from '@deepseek-ai/cordis';
75
+ import type { SandboxMode } from '@deepseek-ai/dsh-sandbox';
76
+ /** The host tool this module withdraws while win_bash serves a session. */
77
+ export declare const HOST_PWSH_TOOL = "pwsh";
78
+ /** The one session mode win_bash can actually serve; every other mode refuses. */
79
+ export declare const SERVING_MODE: SandboxMode;
80
+ /** The scoped restriction call this module consumes from an agent's tools view. */
81
+ export interface ScopedRestrictor {
82
+ /**
83
+ * Mask global tool names for the calling agent scope.
84
+ * @param filter - the mask; only deny is used here.
85
+ * @returns the exact disposer that lifts the restriction.
86
+ */
87
+ restrict(filter: {
88
+ deny: readonly string[];
89
+ }): () => void;
90
+ }
91
+ /** The policy read this module consumes from the sandbox-policy service. */
92
+ export interface SessionPolicyReader {
93
+ /**
94
+ * Resolve one session's effective execution policy.
95
+ * @param request - the session whose own `sandbox/mode` log outranks the
96
+ * deployment default; omitting it answers for the deployment.
97
+ * @returns the policy whose mode decides whether win_bash can serve it.
98
+ */
99
+ resolve(request?: {
100
+ session?: unknown;
101
+ mode?: SandboxMode;
102
+ }): {
103
+ mode: SandboxMode;
104
+ };
105
+ }
106
+ /** What one install run reports and where. */
107
+ export interface PwshReplacementOptions {
108
+ /**
109
+ * The host platform this run may act on; defaults to `process.platform`.
110
+ * Any value other than `win32` makes the call a total no-op, so no POSIX
111
+ * deployment can acquire a restriction, a listener, or a disposer from this
112
+ * module. Tests pass it explicitly instead of depending on the runner's own
113
+ * platform.
114
+ */
115
+ readonly platform?: string;
116
+ /** Tool names to withdraw; defaults to {@link HOST_PWSH_TOOL}. */
117
+ readonly denied?: readonly string[];
118
+ /**
119
+ * One-time warning sink. The default writes through the plugin logger; a
120
+ * caller may replace it so a host with no logger still sees the message.
121
+ */
122
+ readonly warn?: (message: string) => void;
123
+ /**
124
+ * The authority that decides whether win_bash can serve a session; defaults
125
+ * to the deployment's `sandboxPolicy` service. Injectable so a host can hand
126
+ * over an equivalent authority, and so a test can pin the decision without
127
+ * composing a service.
128
+ */
129
+ readonly policy?: SessionPolicyReader;
130
+ }
131
+ /**
132
+ * Withdraw {@link HOST_PWSH_TOOL} from every session this plugin can serve,
133
+ * and remember how to give it back.
134
+ *
135
+ * Called from the mount path ONLY after win_bash itself registered, so a
136
+ * deployment that ends up without win_bash keeps the host's shell untouched.
137
+ * @param ctx - context carrying tools and the agent registry.
138
+ * @param options - the names to withdraw, the warning sink, and the policy authority.
139
+ */
140
+ export declare function installPwshReplacement(ctx: Context, options?: PwshReplacementOptions): void;
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Payload resolution and load-time integrity verification for the vendored
3
+ * bash runtime.
4
+ *
5
+ * The package ships its own Git for Windows MinGit extraction under
6
+ * runtime/win32-x64/: the tool must NEVER fall back to a bash found on PATH
7
+ * (a host Git for Windows install, WSL, or a stray MSYS), because the whole
8
+ * point of vendoring is a shell whose version and bytes are pinned. Two
9
+ * invariants implement that:
10
+ *
11
+ * 1. the binary is addressed by absolute path inside the package, and
12
+ * 2. every vendored byte is checked against the SHA256 manifest generated at
13
+ * packaging time before the tool is mounted at all.
14
+ *
15
+ * A mismatch refuses the mount with a specific message. The alternative —
16
+ * mounting and hoping — would let a tampered or half-installed payload run
17
+ * model-authored commands, which is the one outcome the manifest exists to
18
+ * prevent.
19
+ * @module @linxin666/dsh-win-bash/runtime
20
+ */
21
+ /** Directory holding the shipped payload, relative to the package root. */
22
+ export declare const RUNTIME_DIR = "runtime/win32-x64";
23
+ /** Manifest file name inside {@link RUNTIME_DIR}. */
24
+ export declare const CHECKSUM_FILE = "checksums.sha256";
25
+ /** The one platform this payload supports. */
26
+ export declare const RUNTIME_PLATFORM = "win32";
27
+ /** The one architecture this payload supports. */
28
+ export declare const RUNTIME_ARCH = "x64";
29
+ /** Absolute package root (the directory holding package.json). */
30
+ export declare const PACKAGE_ROOT: string;
31
+ /** Absolute payload root. */
32
+ export declare function runtimeRoot(packageRoot?: string): string;
33
+ /** Absolute path of the vendored shell. */
34
+ export declare function bashPath(packageRoot?: string): string;
35
+ /** Absolute path of the vendored POSIX-shell alias of the same binary. */
36
+ export declare function shPath(packageRoot?: string): string;
37
+ /** Absolute path of the vendored payload's usr/bin directory. */
38
+ export declare function binDir(packageRoot?: string): string;
39
+ /** One manifest row: a payload-relative path and its digest. */
40
+ export interface ChecksumEntry {
41
+ /** Payload-relative path, using forward slashes. */
42
+ readonly path: string;
43
+ /** Lowercase hex SHA256 of the file's bytes. */
44
+ readonly sha256: string;
45
+ }
46
+ /**
47
+ * Parse a sha256sum-style manifest: '<64 hex> <path>' per line. Blank lines
48
+ * and '#' comments are skipped, so the file stays a valid 'sha256sum -c'
49
+ * input while carrying a human-readable header.
50
+ * @param text - the manifest's contents.
51
+ * @returns parsed entries in file order.
52
+ * @throws when a non-comment line does not match the two-column shape.
53
+ */
54
+ export declare function parseChecksums(text: string): ChecksumEntry[];
55
+ /** One payload file whose bytes did not match the manifest. */
56
+ export interface ChecksumMismatch {
57
+ /** Payload-relative path. */
58
+ readonly path: string;
59
+ /** What the manifest records. */
60
+ readonly expected: string;
61
+ /** What is on disk, or 'missing' when the file is absent. */
62
+ readonly actual: string;
63
+ }
64
+ /** Outcome of a full payload verification pass. */
65
+ export interface ChecksumReport {
66
+ /** Registered payload files that hashed correctly. */
67
+ readonly verified: number;
68
+ /** Every file whose bytes or presence disagreed with the manifest. */
69
+ readonly mismatches: readonly ChecksumMismatch[];
70
+ }
71
+ /** SHA256 of a buffer or string, lowercase hex. */
72
+ export declare function sha256(bytes: Buffer | string): string;
73
+ /**
74
+ * Verify every registered payload file against the shipped manifest.
75
+ *
76
+ * Reads and hashes the whole payload (about 16 MiB after the curated
77
+ * extraction), which is why callers do it once at mount time rather than per
78
+ * command.
79
+ * @param packageRoot - package root holding runtime/win32-x64.
80
+ * @returns the count of verified files and every mismatch found.
81
+ * @throws when the manifest itself is unreadable or malformed.
82
+ */
83
+ export declare function verifyPayload(packageRoot?: string): ChecksumReport;
84
+ /** Why this deployment cannot serve the vendored shell. */
85
+ export interface RuntimeRejection {
86
+ /** Machine-readable reason. */
87
+ readonly code: 'unsupported-platform' | 'unsupported-arch' | 'missing-binary' | 'checksum-mismatch' | 'manifest-unreadable';
88
+ /** One-sentence, operator-facing explanation. */
89
+ readonly message: string;
90
+ }
91
+ /** Successful payload resolution. */
92
+ export interface RuntimeReady {
93
+ /** Absolute path of the vendored bash.exe. */
94
+ readonly bash: string;
95
+ /** Absolute path of the payload's usr/bin. */
96
+ readonly bin: string;
97
+ }
98
+ /** Whether the running host can serve this payload at all. */
99
+ export interface HostPlatform {
100
+ /** process.platform. */
101
+ readonly platform: string;
102
+ /** process.arch. */
103
+ readonly arch: string;
104
+ }
105
+ /**
106
+ * Resolve the vendored shell for one host, or refuse the mount.
107
+ *
108
+ * The order is deliberate: platform, then architecture, then presence, then
109
+ * integrity. A checksum failure names the first mismatching path so an
110
+ * operator can act on it, and no path here ever consults PATH.
111
+ * @param host - the running host's platform facts.
112
+ * @param packageRoot - package root holding the payload.
113
+ * @returns the resolved shell paths, or the rejection reason.
114
+ */
115
+ export declare function resolveRuntime(host: HostPlatform, packageRoot?: string): RuntimeReady | RuntimeRejection;
@@ -0,0 +1,184 @@
1
+ /**
2
+ * One persistent bash process per calling agent, driven over piped stdio.
3
+ *
4
+ * Why pipes and not the host's terminal seam: this tool needs a persistent
5
+ * SHELL, not a terminal emulator. What must survive across calls is the shell
6
+ * process state (its current directory, exported variables, functions and
7
+ * aliases) plus exact stdout/stderr bytes and an exact exit code — all of
8
+ * which the subprocess seam's collected streams give directly. A PTY would add
9
+ * echoing and escape sequences this tool would then have to strip again, and
10
+ * would not change the state model.
11
+ *
12
+ * Recovery policy: a shell that exits, wedges or fails its handshake is torn
13
+ * down and the CURRENT call fails with a specific message; the NEXT call
14
+ * starts a fresh shell. State loss is reported rather than hidden, because a
15
+ * silent fresh shell would run the model's next command in the wrong directory
16
+ * with no signal that the previous call's cd/export vanished.
17
+ * @module @linxin666/dsh-win-bash/shell
18
+ */
19
+ import type { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess';
20
+ /** Command stdout budget, in bytes, for one call. */
21
+ export declare const DEFAULT_MAX_STDOUT_BYTES: number;
22
+ /** Command stderr budget, in bytes, for one call. */
23
+ export declare const DEFAULT_MAX_STDERR_BYTES: number;
24
+ /** Spill-file byte cap per stream, so a runaway command cannot fill the disk. */
25
+ export declare const DEFAULT_SPILL_BYTES: number;
26
+ /** Grace period handed to the subprocess seam for range teardown. */
27
+ export declare const GRACE_MS = 5000;
28
+ /** Ceiling on the bytes buffered while looking for a frame's end marker. */
29
+ export declare const FRAME_WATCH_BYTES: number;
30
+ /** In-memory capture ceiling for one shell's stderr, in bytes. */
31
+ export declare const SHELL_STDERR_CAPTURE_BYTES: number;
32
+ /** Exit status reported for a call the tool itself gave up on. */
33
+ export declare const TIMEOUT_EXIT_CODE = 124;
34
+ /** Environment variable names carrying the per-shell private temp directory. */
35
+ export declare const TEMP_ENV_KEYS: readonly ["TMPDIR", "TMP", "TEMP"];
36
+ /**
37
+ * The argv of one pinned shell: the payload's own bash by absolute path, no rc
38
+ * file and no profile, reading its commands from stdin. This tool never
39
+ * consults PATH, and every shell it starts — the session's persistent one and
40
+ * every background job — is built from this one function so the two can never
41
+ * drift into different shells.
42
+ * @param runtime - the verified payload paths.
43
+ * @returns the argv to spawn.
44
+ */
45
+ export declare function shellArgv(runtime: {
46
+ bash: string;
47
+ }): string[];
48
+ /**
49
+ * The environment contract every pinned shell starts with.
50
+ * @param runtime - the verified payload paths.
51
+ * @param temp - the private temp directory that shell owns.
52
+ * @param base - the ambient environment the PATH is appended to.
53
+ * @returns the entries this tool sets explicitly.
54
+ */
55
+ export declare function shellEnvironment(runtime: {
56
+ bin: string;
57
+ }, temp: string, base?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
58
+ /**
59
+ * Create one shell process's private temp directory.
60
+ * @returns the absolute directory, created if absent.
61
+ */
62
+ export declare function shellTempDir(): string;
63
+ /** One command's complete result, as the tool consumes it. */
64
+ export interface ShellResult {
65
+ /** The command's stdout, bounded to the visible budget. */
66
+ readonly stdout: string;
67
+ /** The command's stderr, bounded to the visible budget. */
68
+ readonly stderr: string;
69
+ /** The command's exit status. */
70
+ readonly exitCode: number;
71
+ /** True when visible stdout hit its byte budget. */
72
+ readonly stdoutTruncated: boolean;
73
+ /** True when visible stderr hit its byte budget. */
74
+ readonly stderrTruncated: boolean;
75
+ /** True when the retained stdout lost its head (marker or budget). */
76
+ readonly stdoutLostHead: boolean;
77
+ /** True when the retained stderr lost its head. */
78
+ readonly stderrLostHead: boolean;
79
+ /** The complete stdout, when it was truncated and the provider spilled it. */
80
+ readonly stdoutSpillPath?: string;
81
+ /** The complete stderr, when it was truncated and the provider spilled it. */
82
+ readonly stderrSpillPath?: string;
83
+ /** True when stdout overflowed the frame window, so the middle was dropped. */
84
+ readonly frameOverflow: boolean;
85
+ }
86
+ /**
87
+ * The fallback every failure here points at.
88
+ *
89
+ * win_bash is the PREFERRED shell on Windows, not the only one: whenever it
90
+ * cannot serve a call the native shell tool takes over, and a failure that did
91
+ * not say so would leave the model retrying a shell that is not coming back
92
+ * instead of switching to the one that works.
93
+ */
94
+ export declare const NATIVE_FALLBACK_HINT: string;
95
+ /** Failure raised when the shell cannot serve a call. */
96
+ export declare class ShellUnavailableError extends Error {
97
+ /** Stable machine-readable reason. */
98
+ readonly code: string;
99
+ /**
100
+ * @param code - stable reason code.
101
+ * @param message - explanation safe to show the model.
102
+ */
103
+ constructor(code: string, message: string);
104
+ }
105
+ /** Budgets and deadline for one {@link ShellRegistry.run} call. */
106
+ export interface RunBudget {
107
+ /** Visible stdout byte budget. */
108
+ readonly stdoutBytes: number;
109
+ /** Visible stderr byte budget. */
110
+ readonly stderrBytes: number;
111
+ /** Whole-call deadline in milliseconds. */
112
+ readonly timeoutMs: number;
113
+ /** Caller cancellation. */
114
+ readonly signal?: AbortSignal | undefined;
115
+ }
116
+ /**
117
+ * Keep the LAST budget bytes of a string, reporting whether it dropped any.
118
+ * @param text - the full text.
119
+ * @param budget - the visible byte budget.
120
+ * @returns the visible text and whether it was cut.
121
+ */
122
+ export declare function tailBytes(text: string, budget: number): {
123
+ text: string;
124
+ truncated: boolean;
125
+ };
126
+ /**
127
+ * The persistent shells of one plugin instance, keyed by calling agent.
128
+ *
129
+ * The keys are the live agent objects and the map is plain, so an agent's
130
+ * shell is dropped by that agent's own disposal hook rather than by a weak
131
+ * reference that decides for itself when to act.
132
+ */
133
+ export declare class ShellRegistry {
134
+ private readonly subprocess;
135
+ private readonly now;
136
+ private readonly shells;
137
+ /**
138
+ * @param subprocess - the host's managed subprocess seam.
139
+ * @param now - clock, injected so tests run without real waiting.
140
+ */
141
+ constructor(subprocess: SubprocessRuntime, now?: () => number);
142
+ /** Live shell count, for teardown assertions. */
143
+ get size(): number;
144
+ /** Whether the given owner currently holds a live shell. */
145
+ has(owner: object): boolean;
146
+ /**
147
+ * Run one command in the owner's persistent shell, starting it on first use.
148
+ * @param owner - the calling agent (the shell lifetime key).
149
+ * @param runtime - absolute shell and payload paths.
150
+ * @param cwd - the session workspace a newly started shell begins in.
151
+ * @param command - the command to run.
152
+ * @param budget - output budgets and the call deadline.
153
+ * @returns the command's complete result.
154
+ */
155
+ run(owner: object, runtime: {
156
+ bash: string;
157
+ bin: string;
158
+ }, cwd: string, command: string, budget: RunBudget): Promise<ShellResult>;
159
+ /**
160
+ * Get the owner's live shell, starting one when absent.
161
+ * @param owner - calling agent identity.
162
+ * @param runtime - absolute shell and payload paths.
163
+ * @param cwd - the session workspace a new shell starts in.
164
+ * @param signal - cancellation while the shell starts.
165
+ * @returns the live shell record.
166
+ */
167
+ private ensure;
168
+ /**
169
+ * Confirm a fresh shell answers before the first real command runs, so a
170
+ * payload that cannot start surfaces as one clear failure instead of as a
171
+ * mysterious empty result on the model's command.
172
+ */
173
+ private handshake;
174
+ /**
175
+ * Stop one owner's shell and forget it. Termination goes through the seam's
176
+ * managed-process range, so a background job the command left behind is torn
177
+ * down with the shell rather than surviving the plugin.
178
+ * @param owner - calling agent identity.
179
+ * @param reason - recorded by the provider for diagnostics.
180
+ */
181
+ dispose(owner: object, reason: string): Promise<void>;
182
+ /** Stop every shell this registry owns; used on plugin unload. */
183
+ disposeAll(reason: string): Promise<void>;
184
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * The model-facing win_bash tool.
3
+ *
4
+ * Named win_bash and not bash on purpose: the host already mounts its own
5
+ * bash-family tools (bash, pwsh), and a name collision would either be a
6
+ * duplicate-registration failure or, worse, silently replace the host's tool.
7
+ * This tool is additional capability, not a replacement.
8
+ *
9
+ * Permission: the sandbox-policy service is read for the CALLING SESSION, since
10
+ * a session's own mode log outranks the deployment default. A session in a
11
+ * restricted mode is refused outright rather than confined — see
12
+ * {@link assertUnconfined} for the measured reason.
13
+ * @module @linxin666/dsh-win-bash/tool
14
+ */
15
+ import type { Context } from '@deepseek-ai/cordis';
16
+ import type { ToolDefinition } from '@deepseek-ai/dsh-tools';
17
+ import type { JobRegistryLike } from './background.ts';
18
+ import type { WinBashConfig } from './config.ts';
19
+ import { type ShellRegistry } from './shell.ts';
20
+ /** The registered tool name. Deliberately not bash. */
21
+ export declare const WIN_BASH_TOOL = "win_bash";
22
+ /**
23
+ * Single-quote one value for the shell, escaping embedded single quotes.
24
+ * @param value - the raw value.
25
+ * @returns a POSIX single-quoted literal.
26
+ */
27
+ export declare function shellQuote(value: string): string;
28
+ /**
29
+ * Normalize a Windows path into the spelling MSYS accepts without escaping:
30
+ * a backslash is also the shell's escape character, so a path handed to cd is
31
+ * converted to forward slashes before it is quoted.
32
+ * @param path - the caller-supplied working directory.
33
+ * @returns the same path with backslashes replaced.
34
+ */
35
+ export declare function normalizeWorkdir(path: string): string;
36
+ /**
37
+ * Clamp a per-call deadline to the configured ceiling.
38
+ * @param requested - the model's timeoutMs, if any.
39
+ * @param configured - the plugin's configured default and ceiling.
40
+ * @returns the effective deadline in milliseconds.
41
+ * @throws when the requested value is not a positive whole number.
42
+ */
43
+ export declare function clampTimeout(requested: number | undefined, configured: number): number;
44
+ /** The truncation facts a rendered result reports to the model. */
45
+ export interface RenderFacts {
46
+ /** Visible stdout, already cut to its byte budget. */
47
+ stdout: string;
48
+ /** Visible stderr, already cut to its byte budget. */
49
+ stderr: string;
50
+ /** The command's exit status. */
51
+ exitCode: number;
52
+ /** True when visible stdout hit its byte budget. */
53
+ stdoutTruncated?: boolean;
54
+ /** True when visible stderr hit its byte budget. */
55
+ stderrTruncated?: boolean;
56
+ /** True when the retained stdout lost its head. */
57
+ stdoutLostHead?: boolean;
58
+ /** True when the retained stderr lost its head. */
59
+ stderrLostHead?: boolean;
60
+ /** True when the frame watch window dropped the middle of stdout. */
61
+ frameOverflow?: boolean;
62
+ /** Host path of the complete stdout, when the provider spilled it. */
63
+ stdoutSpillPath?: string;
64
+ /** Host path of the complete stderr, when the provider spilled it. */
65
+ stderrSpillPath?: string;
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;
74
+ /**
75
+ * The line that tells the model its view of one stream is incomplete.
76
+ *
77
+ * WHY THIS IS NOT DECORATION. The visible text is the TAIL of the stream: the
78
+ * head was already cut to fit the byte budget, so the first thing the model
79
+ * reads can be the middle of a line with nothing marking the cut. Without this
80
+ * line a partial result is indistinguishable from a short one, and a model
81
+ * reading a truncated listing draws conclusions from data it never saw.
82
+ * @param stream - stream label.
83
+ * @param visible - the bytes actually shown.
84
+ * @param flags - which cuts happened.
85
+ * @param spillPath - complete-stream file, when the provider kept one.
86
+ * @returns the notice, or undefined when that stream was shown in full.
87
+ */
88
+ export declare function truncationNotice(stream: 'stdout' | 'stderr', visible: string, flags: {
89
+ truncated: boolean;
90
+ lostHead: boolean;
91
+ overflow: boolean;
92
+ }, spillPath?: string): string | undefined;
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
+ */
102
+ export declare function renderResult(value: RenderFacts): string;
103
+ /**
104
+ * The deployment's background job registry, read without letting a refused
105
+ * lookup escape: a cordis service proxy throws for a name it cannot resolve,
106
+ * and "this deployment composes no job registry" is an ordinary state here,
107
+ * not an error.
108
+ * @param ctx - the plugin context.
109
+ * @returns the registry, or undefined when this deployment has none.
110
+ */
111
+ export declare function readJobRegistry(ctx: Context): JobRegistryLike | undefined;
112
+ /**
113
+ * Build the win_bash tool bound to one payload and one shell registry.
114
+ * @param ctx - host context carrying the optional sandbox and job services.
115
+ * @param config - the resolved plugin configuration.
116
+ * @param runtime - absolute shell and payload paths.
117
+ * @param shells - the registry owning this plugin instance's shells.
118
+ * @returns the tool definition, ready for the tools registry.
119
+ */
120
+ export declare function buildWinBashTool(ctx: Context, config: WinBashConfig, runtime: {
121
+ bash: string;
122
+ bin: string;
123
+ }, shells: ShellRegistry): ToolDefinition;
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@linxin666/dsh-win-bash",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
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.8",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "types": "lib/types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/types/index.d.ts",
11
+ "default": "./lib/index.js"
12
+ },
13
+ "./src/*": "./src/*",
14
+ "./package.json": "./package.json"
15
+ },
16
+ "dsh": {
17
+ "engines": {
18
+ "dsh": ">=0.2.1-rc.2"
19
+ },
20
+ "bundle": {
21
+ "patch": "./cordis.patch.yml"
22
+ }
23
+ },
24
+ "peerDependencies": {
25
+ "@deepseek-ai/dsh": ">=0.2.1-rc.2"
26
+ },
27
+ "devDependencies": {
28
+ "@deepseek-ai/cordis": "^4.0.5",
29
+ "@deepseek-ai/dsh-agent": "^0.2.1-rc.2",
30
+ "@deepseek-ai/dsh-sandbox": "^0.2.1-rc.2",
31
+ "@deepseek-ai/dsh-subprocess": "^0.2.1-rc.2",
32
+ "@deepseek-ai/dsh-tools": "^0.2.1-rc.2",
33
+ "@deepseek-ai/schemastery": "^3.18.5",
34
+ "@types/node": "^22.20.0",
35
+ "tsdown": "0.22.2",
36
+ "typescript": "~5.7.2",
37
+ "vitest": "^4.1.8"
38
+ },
39
+ "files": [
40
+ "lib/**/*.js",
41
+ "lib/**/*.d.ts",
42
+ "src",
43
+ "runtime/win32-x64",
44
+ "cordis.patch.yml",
45
+ "PROVENANCE.md",
46
+ "README.md",
47
+ "README.zh.md",
48
+ "README.i18n.yaml"
49
+ ],
50
+ "license": "Apache-2.0",
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "https://github.com/zhu1090093659/dsh-web.git"
54
+ },
55
+ "scripts": {
56
+ "build": "tsc -p tsconfig.build.json && tsdown",
57
+ "watch": "tsdown --watch",
58
+ "test": "vitest run",
59
+ "typecheck": "tsgo --noEmit"
60
+ }
6
61
  }