@linxin666/dsh-win-bash 0.4.13 → 0.4.15
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 +45 -2
- package/README.zh.md +29 -1
- package/lib/index.js +666 -38
- package/lib/types/background.d.ts +8 -1
- package/lib/types/dsh-home.d.ts +16 -0
- package/lib/types/gate.d.ts +1 -1
- package/lib/types/index.d.ts +14 -2
- package/lib/types/integrity.d.ts +81 -0
- package/lib/types/runtime.d.ts +170 -10
- package/lib/types/shell.d.ts +53 -1
- package/package.json +9 -9
- package/src/background.ts +20 -3
- package/src/dsh-home.ts +42 -0
- package/src/gate.ts +1 -1
- package/src/index.ts +62 -3
- package/src/integrity.ts +161 -0
- package/src/runtime.ts +477 -26
- package/src/shell.ts +182 -6
- package/src/tool.ts +3 -1
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* STRUCTURALLY: a leaf plugin takes no dependency on @deepseek-ai/dsh-jobs to
|
|
16
16
|
* call one method on an optional service, and the same decision keeps this
|
|
17
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.
|
|
18
|
+
* mirrored from the published declaration of @deepseek-ai/dsh-jobs@0.2.2-rc.1:
|
|
19
19
|
*
|
|
20
20
|
* lib/types/index.d.ts
|
|
21
21
|
* abstract class JobRegistry {
|
|
@@ -129,6 +129,13 @@ export interface BackgroundCommand {
|
|
|
129
129
|
readonly cwd: string;
|
|
130
130
|
/** Environment entries for the process. */
|
|
131
131
|
readonly env: NodeJS.ProcessEnv;
|
|
132
|
+
/**
|
|
133
|
+
* The private temp directory this job owns, when the caller created one (it is
|
|
134
|
+
* the TMP/TEMP/TMPDIR in {@link env}). Reclaimed when the job settles, on every
|
|
135
|
+
* path: the process's own exit, a kill through the hooks, and a starter that
|
|
136
|
+
* never spawned.
|
|
137
|
+
*/
|
|
138
|
+
readonly temp?: string;
|
|
132
139
|
/** Label shown for this job. */
|
|
133
140
|
readonly label: string;
|
|
134
141
|
/** In-memory capture ceiling for stdout, in bytes. */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSH_HOME resolution shared by the plugin family's Host halves: the
|
|
3
|
+
* environment override wins, the platform home fallback follows. Mirrors
|
|
4
|
+
* what dsh-pet and dsh-liangshen each used to implement locally.
|
|
5
|
+
*/
|
|
6
|
+
/** Expand a leading ~ (or ~user) in a path, platform-style. */
|
|
7
|
+
export declare function expandHome(path: string, home?: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the DSH home directory.
|
|
10
|
+
* @param env - process environment to read DSH_HOME from.
|
|
11
|
+
* @param home - platform home directory fallback (test seam).
|
|
12
|
+
* @returns the absolute DSH home path.
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveDshHome(env?: NodeJS.ProcessEnv, home?: string): string;
|
|
15
|
+
/** Resolve the DSH home directory from the live environment. */
|
|
16
|
+
export declare function dshHome(): string;
|
package/lib/types/gate.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* on @deepseek-ai/dsh-agent-preset-registry (a leaf plugin takes no SDK
|
|
13
13
|
* dependency to read one optional service), so the single method consumed is
|
|
14
14
|
* mirrored from the published declaration of
|
|
15
|
-
* @deepseek-ai/dsh-agent-preset-registry@0.2.
|
|
15
|
+
* @deepseek-ai/dsh-agent-preset-registry@0.2.2-rc.1, lib/types/index.d.ts:
|
|
16
16
|
*
|
|
17
17
|
* export declare class AgentPresetRegistry {
|
|
18
18
|
* list(): Promise<AgentPreset[]>
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,6 +13,18 @@
|
|
|
13
13
|
* and on a Windows host that is not x64, because no PATH bash is ever used as
|
|
14
14
|
* a substitute.
|
|
15
15
|
*
|
|
16
|
+
* Mount-time publication: the tree that is spawned is a verified copy outside
|
|
17
|
+
* this package, not the tree inside node_modules. A persistent shell holds its
|
|
18
|
+
* own executable open, and Windows refuses to rename a directory that holds a
|
|
19
|
+
* running executable, so a shell started inside the package makes pnpm's
|
|
20
|
+
* import of this package fail with ERR_PNPM_EPERM. Publishing the payload
|
|
21
|
+
* outside the package is what lets an update or uninstall run while sessions
|
|
22
|
+
* are live. The copy's mandatory integrity label is checked before reuse and
|
|
23
|
+
* before execution: a Low-labelled cache is abandoned for an isolated root
|
|
24
|
+
* instead of starting a Low-integrity shell. A cache that cannot be written,
|
|
25
|
+
* or no safe root at all, keeps the tool working from the packaged tree and
|
|
26
|
+
* logs that updates will need this host stopped.
|
|
27
|
+
*
|
|
16
28
|
* Availability gate: win_bash serves sessions that run the LiangShen (梁神)
|
|
17
29
|
* preset, so its registration follows that preset's DECLARATION in the
|
|
18
30
|
* harness's agent-preset registry — declared means registered, undeclared
|
|
@@ -49,10 +61,10 @@ export { CONFIG_DEFAULTS, DEFAULT_DESCRIPTION, DEFAULT_ENABLE_RUN_IN_BACKGROUND,
|
|
|
49
61
|
export { HOST_PWSH_TOOL, SERVING_MODE, installPwshReplacement, type PwshReplacementOptions, type ScopedRestrictor, type SessionPolicyReader, } from './pwsh-replacement.ts';
|
|
50
62
|
export { WIN_BASH_TOOL, renderResult, readJobRegistry, stripTerminalEscapes, truncationNotice } from './tool.ts';
|
|
51
63
|
export type { RenderFacts } from './tool.ts';
|
|
52
|
-
export { ShellRegistry, ShellUnavailableError, shellArgv, shellEnvironment, shellTempDir, } from './shell.ts';
|
|
64
|
+
export { SHELL_TEMP_PREFIX, ShellRegistry, ShellUnavailableError, removeShellTempDir, shellArgv, shellEnvironment, shellTempDir, sweepOrphanShellTempDirs, type ShellTempSweep, type ShellTempSweepOptions, } from './shell.ts';
|
|
53
65
|
export { buildFrame, markerFor, parseFrame } from './protocol.ts';
|
|
54
66
|
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';
|
|
67
|
+
export { CACHE_DIR_PARTS, CACHE_STAGING_PREFIX, ISOLATED_CACHE_DIR_PARTS, RUNTIME_ROOT_ENV, bashIn, bashPath, binIn, cacheRoot, isolatedCacheRoot, parseChecksums, payloadKey, prepareRuntime, resolveRuntime, runtimeRoot, shIn, shPath, verifyPayload, verifyPayloadRoot, type CopyTree, type PrepareRuntimeOptions, } from './runtime.ts';
|
|
56
68
|
/** Cordis plugin name; also the loader row id this package mounts under. */
|
|
57
69
|
export declare const name = "dsh-win-bash";
|
|
58
70
|
/** Required services: the tool registry and the managed subprocess seam. */
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows mandatory-integrity-label inspection for the published payload cache.
|
|
3
|
+
*
|
|
4
|
+
* A cache under a data tree that carries an inheritable Low Mandatory Level ACE
|
|
5
|
+
* produces a bash.exe that inherits that label. Windows then starts a
|
|
6
|
+
* Low-integrity process even from a Medium-integrity runner
|
|
7
|
+
* (TOKEN_MANDATORY_POLICY_NEW_PROCESS_MIN takes the LOWER of parent token and
|
|
8
|
+
* executable image), and a Low process cannot write an ordinary Medium
|
|
9
|
+
* workspace or temp directory. The bytes and SHA256 manifest are identical, so
|
|
10
|
+
* a checksum-only cache check cannot see this: the defect is in the security
|
|
11
|
+
* descriptor, not the file content.
|
|
12
|
+
*
|
|
13
|
+
* Node's fs API cannot read a SACL. The Windows built-in `icacls <path> /save`
|
|
14
|
+
* writes a security descriptor as language-independent SDDL in UTF-16LE;
|
|
15
|
+
* `S:...` carries the mandatory label ACEs, e.g. `(ML;OICI;NW;;;LW)` for an
|
|
16
|
+
* inheritable Low label or `(ML;ID;NW;;;LW)` for an inherited one. `LW` is
|
|
17
|
+
* the SDDL abbreviation of S-1-16-4096 (Low); Untrusted is S-1-16-0. Anything
|
|
18
|
+
* below Medium (S-1-16-8192) can downgrade the spawned shell.
|
|
19
|
+
*
|
|
20
|
+
* The binary is addressed by absolute path under SystemRoot, never through
|
|
21
|
+
* PATH. This module only reads; it never changes a label, a DACL, a token or a
|
|
22
|
+
* user's data directory.
|
|
23
|
+
* @module @linxin666/dsh-win-bash/integrity
|
|
24
|
+
*/
|
|
25
|
+
/** Integrity RID of Medium; a label below it downgrades a spawned process. */
|
|
26
|
+
export declare const MEDIUM_INTEGRITY_RID = 8192;
|
|
27
|
+
/** Wall-clock bound on one icacls query for a security descriptor. */
|
|
28
|
+
export declare const READ_LABEL_TIMEOUT_MS = 5000;
|
|
29
|
+
/** What one mandatory-integrity-label inspection established. */
|
|
30
|
+
export type IntegrityLabel = 'medium-or-higher' | 'low-or-untrusted' | 'unknown';
|
|
31
|
+
/**
|
|
32
|
+
* A reader for one path's mandatory integrity label. The seam exists so tests
|
|
33
|
+
* can drive Low/Unknown verdicts without touching the host's ACLs.
|
|
34
|
+
*/
|
|
35
|
+
export type LabelReader = (target: string) => IntegrityLabel;
|
|
36
|
+
/**
|
|
37
|
+
* Classify the mandatory label ACEs of one icacls /save SDDL blob.
|
|
38
|
+
*
|
|
39
|
+
* A missing SACL means the object has no explicit label and inherits Medium by
|
|
40
|
+
* default. High/System/Medium labels are harmless here; only Low or Untrusted
|
|
41
|
+
* can turn a Medium runner's child into a Low process.
|
|
42
|
+
* @param sddl - the UTF-16LE-decoded contents of an icacls /save file.
|
|
43
|
+
* @returns the label verdict. `unknown` is reserved for the reader that could
|
|
44
|
+
* not obtain or trust a descriptor at all; a parsed blob always decides.
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseIntegritySddl(sddl: string): IntegrityLabel;
|
|
47
|
+
/**
|
|
48
|
+
* Read one existing path's mandatory integrity label.
|
|
49
|
+
*
|
|
50
|
+
* On a POSIX host there is no Windows mandatory integrity control (and this
|
|
51
|
+
* package does not mount there), so the label cannot downgrade anything. A
|
|
52
|
+
* missing icacls, a failed query or an unreadable descriptor is reported as
|
|
53
|
+
* `unknown` rather than guessed: the caller decides whether to fall back.
|
|
54
|
+
* @param target - an existing file or directory to inspect.
|
|
55
|
+
* @param env - environment supplying SystemRoot; the live one by default.
|
|
56
|
+
* @returns the label verdict.
|
|
57
|
+
*/
|
|
58
|
+
export declare function readMandatoryLabel(target: string, env?: NodeJS.ProcessEnv): IntegrityLabel;
|
|
59
|
+
/**
|
|
60
|
+
* The nearest existing path at or above `path`.
|
|
61
|
+
*
|
|
62
|
+
* A directory that does not exist yet has no descriptor of its own; a new file
|
|
63
|
+
* created below it inherits the label of the closest existing ancestor. That
|
|
64
|
+
* ancestor is what a pre-publication check has to inspect.
|
|
65
|
+
* @param path - the prospective path.
|
|
66
|
+
* @returns itself when it exists, otherwise its closest existing ancestor.
|
|
67
|
+
*/
|
|
68
|
+
export declare function nearestExistingAncestor(path: string): string;
|
|
69
|
+
/** Bound on the directory chain walked, so a pathological path cannot spin. */
|
|
70
|
+
export declare const MAX_ANCESTOR_DEPTH = 32;
|
|
71
|
+
/**
|
|
72
|
+
* Every existing path from `path` up to the volume root.
|
|
73
|
+
*
|
|
74
|
+
* A cache root can sit several levels below the data tree that a workspace
|
|
75
|
+
* sandbox labelled Low, and an inheritable ACE on ANY of those ancestors can
|
|
76
|
+
* still be propagated onto existing children later. Checking only the nearest
|
|
77
|
+
* existing ancestor would miss that, so the whole chain is inspected.
|
|
78
|
+
* @param path - the prospective path (it need not exist yet).
|
|
79
|
+
* @returns the existing ancestors, nearest first.
|
|
80
|
+
*/
|
|
81
|
+
export declare function existingAncestors(path: string): string[];
|
package/lib/types/runtime.d.ts
CHANGED
|
@@ -5,12 +5,33 @@
|
|
|
5
5
|
* The package ships its own Git for Windows MinGit extraction under
|
|
6
6
|
* runtime/win32-x64/: the tool must NEVER fall back to a bash found on PATH
|
|
7
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.
|
|
8
|
+
* point of vendoring is a shell whose version and bytes are pinned. Four
|
|
9
9
|
* invariants implement that:
|
|
10
10
|
*
|
|
11
|
-
* 1. the binary is addressed by absolute path
|
|
11
|
+
* 1. the binary is addressed by absolute path, never by name,
|
|
12
12
|
* 2. every vendored byte is checked against the SHA256 manifest generated at
|
|
13
|
-
* packaging time before
|
|
13
|
+
* packaging time before it is used at all, and
|
|
14
|
+
* 3. the tree that RUNS is a published copy under the DSH home, not the tree
|
|
15
|
+
* inside the package.
|
|
16
|
+
* 4. the copy's Windows mandatory integrity label is checked before it is
|
|
17
|
+
* reused or before a freshly published copy is spawned. A Low (or lower)
|
|
18
|
+
* label on the executable image makes Windows start a Low-integrity process
|
|
19
|
+
* even from a Medium runner, and that process cannot write an ordinary
|
|
20
|
+
* Medium workspace or temp directory. Such a tree is never used: the payload
|
|
21
|
+
* is published into an isolated cache root instead, and if no candidate root
|
|
22
|
+
* is safe the mount is refused with a specific diagnosis.
|
|
23
|
+
*
|
|
24
|
+
* The third invariant is why this module publishes a cache: Windows refuses to
|
|
25
|
+
* rename a directory whose executable is running, and pnpm imports a package by
|
|
26
|
+
* renaming a staging directory over it, so a shell spawned from inside
|
|
27
|
+
* node_modules makes every later update or uninstall of this package fail with
|
|
28
|
+
* ERR_PNPM_EPERM until the host stops. A persistent shell is this package's
|
|
29
|
+
* whole point, so the payload moves out of the package instead of the process
|
|
30
|
+
* moving out of the payload. The copy is content-addressed by the shipped
|
|
31
|
+
* manifest: the directory name is a digest of the payload's file identities, so
|
|
32
|
+
* a release that changes only JavaScript reuses the copy already published, and
|
|
33
|
+
* a copy whose bytes or manifest disagree with the shipped identity is never
|
|
34
|
+
* used.
|
|
14
35
|
*
|
|
15
36
|
* A mismatch refuses the mount with a specific message. The alternative —
|
|
16
37
|
* mounting and hoping — would let a tampered or half-installed payload run
|
|
@@ -18,6 +39,7 @@
|
|
|
18
39
|
* prevent.
|
|
19
40
|
* @module @linxin666/dsh-win-bash/runtime
|
|
20
41
|
*/
|
|
42
|
+
import { type LabelReader } from './integrity.ts';
|
|
21
43
|
/** Directory holding the shipped payload, relative to the package root. */
|
|
22
44
|
export declare const RUNTIME_DIR = "runtime/win32-x64";
|
|
23
45
|
/** Manifest file name inside {@link RUNTIME_DIR}. */
|
|
@@ -26,16 +48,76 @@ export declare const CHECKSUM_FILE = "checksums.sha256";
|
|
|
26
48
|
export declare const RUNTIME_PLATFORM = "win32";
|
|
27
49
|
/** The one architecture this payload supports. */
|
|
28
50
|
export declare const RUNTIME_ARCH = "x64";
|
|
51
|
+
/**
|
|
52
|
+
* Payload cache directories under the DSH home, in order.
|
|
53
|
+
*
|
|
54
|
+
* The cache lives OUTSIDE the package on purpose: a running shell holds its own
|
|
55
|
+
* executable open, Windows refuses to rename a directory that holds a running
|
|
56
|
+
* executable, and pnpm imports a package by renaming over it. A copy here is
|
|
57
|
+
* also why a release that only changes JavaScript never has to move 16 MiB.
|
|
58
|
+
*/
|
|
59
|
+
export declare const CACHE_DIR_PARTS: readonly ["win-bash", "runtime"];
|
|
60
|
+
/**
|
|
61
|
+
* Directory parts of the isolated fallback cache, used only when the preferred
|
|
62
|
+
* cache root carries a Low mandatory integrity label. It lives outside the DSH
|
|
63
|
+
* data tree, which a workspace sandbox can label Low with an inheritable ACE.
|
|
64
|
+
*/
|
|
65
|
+
export declare const ISOLATED_CACHE_DIR_PARTS: readonly ["dsh-win-bash", "runtime"];
|
|
66
|
+
/**
|
|
67
|
+
* Optional environment override for the isolated cache root's parent. An
|
|
68
|
+
* operator whose local app data is itself labelled Low can point this at a
|
|
69
|
+
* directory they have verified is Medium; it is not needed on a normal host.
|
|
70
|
+
*/
|
|
71
|
+
export declare const RUNTIME_ROOT_ENV = "DSH_WIN_BASH_RUNTIME_HOME";
|
|
72
|
+
/**
|
|
73
|
+
* Name prefix of the staging directory one cache copy is built in. The rest of
|
|
74
|
+
* the name is the payload key, this process's id and a random suffix, so a
|
|
75
|
+
* half-written directory is never mistaken for a published payload.
|
|
76
|
+
*/
|
|
77
|
+
export declare const CACHE_STAGING_PREFIX = ".staging-";
|
|
29
78
|
/** Absolute package root (the directory holding package.json). */
|
|
30
79
|
export declare const PACKAGE_ROOT: string;
|
|
31
|
-
/** Absolute payload root. */
|
|
80
|
+
/** Absolute payload root inside one package root. */
|
|
32
81
|
export declare function runtimeRoot(packageRoot?: string): string;
|
|
33
|
-
/** Absolute path of the vendored shell. */
|
|
82
|
+
/** Absolute path of the vendored shell inside one payload root. */
|
|
83
|
+
export declare function bashIn(root: string): string;
|
|
84
|
+
/** Absolute path of the vendored POSIX-shell alias inside one payload root. */
|
|
85
|
+
export declare function shIn(root: string): string;
|
|
86
|
+
/** Absolute path of one payload root's usr/bin directory. */
|
|
87
|
+
export declare function binIn(root: string): string;
|
|
88
|
+
/** Absolute path of the packaged payload's shell. */
|
|
34
89
|
export declare function bashPath(packageRoot?: string): string;
|
|
35
|
-
/** Absolute path of the
|
|
90
|
+
/** Absolute path of the packaged payload's POSIX-shell alias. */
|
|
36
91
|
export declare function shPath(packageRoot?: string): string;
|
|
37
|
-
/** Absolute path of the
|
|
92
|
+
/** Absolute path of the packaged payload's usr/bin directory. */
|
|
38
93
|
export declare function binDir(packageRoot?: string): string;
|
|
94
|
+
/**
|
|
95
|
+
* Absolute root of the per-user payload cache.
|
|
96
|
+
*
|
|
97
|
+
* It follows the DSH home rather than the package, so an isolated
|
|
98
|
+
* `DSH_HOME` (a probe instance, a test run) gets its own cache, and an update or
|
|
99
|
+
* uninstall of this package never touches a byte the cache holds.
|
|
100
|
+
* @param env - environment to read DSH_HOME from; the live one by default.
|
|
101
|
+
* @returns the directory payload copies are published under.
|
|
102
|
+
*/
|
|
103
|
+
export declare function cacheRoot(env?: NodeJS.ProcessEnv): string;
|
|
104
|
+
/**
|
|
105
|
+
* Absolute root of the isolated fallback payload cache.
|
|
106
|
+
*
|
|
107
|
+
* The DSH home is a data tree a workspace sandbox may have labelled Low with
|
|
108
|
+
* an inheritable ACE. A copy published below it then inherits that label and
|
|
109
|
+
* starts a Low-integrity bash, which cannot write a Medium workspace or temp
|
|
110
|
+
* directory. This root deliberately lives OUTSIDE the DSH home, under the
|
|
111
|
+
* per-user application-data (or cache) directory instead.
|
|
112
|
+
*
|
|
113
|
+
* It still follows the probe-isolation convention: the final path component is
|
|
114
|
+
* derived from the DSH home, so an isolated `DSH_HOME` gets its own isolated
|
|
115
|
+
* cache too. Operators whose application-data tree is itself labelled Low can
|
|
116
|
+
* point {@link RUNTIME_ROOT_ENV} at a directory they have verified.
|
|
117
|
+
* @param env - environment to read the override, app-data root and DSH home from.
|
|
118
|
+
* @returns the directory the fallback payload copies are published under.
|
|
119
|
+
*/
|
|
120
|
+
export declare function isolatedCacheRoot(env?: NodeJS.ProcessEnv): string;
|
|
39
121
|
/** One manifest row: a payload-relative path and its digest. */
|
|
40
122
|
export interface ChecksumEntry {
|
|
41
123
|
/** Payload-relative path, using forward slashes. */
|
|
@@ -70,6 +152,16 @@ export interface ChecksumReport {
|
|
|
70
152
|
}
|
|
71
153
|
/** SHA256 of a buffer or string, lowercase hex. */
|
|
72
154
|
export declare function sha256(bytes: Buffer | string): string;
|
|
155
|
+
/**
|
|
156
|
+
* The content key of one payload: a digest over its manifest's file identities.
|
|
157
|
+
*
|
|
158
|
+
* Manifest formatting and row order do not move it, and any change to a
|
|
159
|
+
* payload file does. That is what makes a cache directory name a statement
|
|
160
|
+
* about the bytes inside it rather than about the release that shipped them.
|
|
161
|
+
* @param entries - the parsed manifest rows.
|
|
162
|
+
* @returns the 16-character key that names the cache directory.
|
|
163
|
+
*/
|
|
164
|
+
export declare function payloadKey(entries: readonly ChecksumEntry[]): string;
|
|
73
165
|
/**
|
|
74
166
|
* Verify every registered payload file against the shipped manifest.
|
|
75
167
|
*
|
|
@@ -81,19 +173,34 @@ export declare function sha256(bytes: Buffer | string): string;
|
|
|
81
173
|
* @throws when the manifest itself is unreadable or malformed.
|
|
82
174
|
*/
|
|
83
175
|
export declare function verifyPayload(packageRoot?: string): ChecksumReport;
|
|
176
|
+
/**
|
|
177
|
+
* Verify every payload file of one payload root against that root's manifest.
|
|
178
|
+
*
|
|
179
|
+
* The root is the directory holding `usr/` and `checksums.sha256`, which is
|
|
180
|
+
* either the packaged payload or a published cache copy, so both go through the
|
|
181
|
+
* same pass.
|
|
182
|
+
* @param root - the payload root to verify.
|
|
183
|
+
* @returns the count of verified files and every mismatch found.
|
|
184
|
+
* @throws when the manifest itself is unreadable or malformed.
|
|
185
|
+
*/
|
|
186
|
+
export declare function verifyPayloadRoot(root: string): ChecksumReport;
|
|
84
187
|
/** Why this deployment cannot serve the vendored shell. */
|
|
85
188
|
export interface RuntimeRejection {
|
|
86
189
|
/** Machine-readable reason. */
|
|
87
|
-
readonly code: 'unsupported-platform' | 'unsupported-arch' | 'missing-binary' | 'checksum-mismatch' | 'manifest-unreadable';
|
|
190
|
+
readonly code: 'unsupported-platform' | 'unsupported-arch' | 'missing-binary' | 'checksum-mismatch' | 'manifest-unreadable' | 'unsafe-integrity';
|
|
88
191
|
/** One-sentence, operator-facing explanation. */
|
|
89
192
|
readonly message: string;
|
|
90
193
|
}
|
|
91
194
|
/** Successful payload resolution. */
|
|
92
195
|
export interface RuntimeReady {
|
|
93
|
-
/** Absolute path of the vendored bash.exe. */
|
|
196
|
+
/** Absolute path of the vendored bash.exe that will be spawned. */
|
|
94
197
|
readonly bash: string;
|
|
95
198
|
/** Absolute path of the payload's usr/bin. */
|
|
96
199
|
readonly bin: string;
|
|
200
|
+
/** Absolute payload root both paths above live in. */
|
|
201
|
+
readonly payloadRoot: string;
|
|
202
|
+
/** Whether that root is the published cache copy or the packaged tree. */
|
|
203
|
+
readonly source: 'cache' | 'package';
|
|
97
204
|
}
|
|
98
205
|
/** Whether the running host can serve this payload at all. */
|
|
99
206
|
export interface HostPlatform {
|
|
@@ -103,13 +210,66 @@ export interface HostPlatform {
|
|
|
103
210
|
readonly arch: string;
|
|
104
211
|
}
|
|
105
212
|
/**
|
|
106
|
-
* Resolve the
|
|
213
|
+
* Resolve the PACKAGED shell for one host, or refuse the mount.
|
|
107
214
|
*
|
|
108
215
|
* The order is deliberate: platform, then architecture, then presence, then
|
|
109
216
|
* integrity. A checksum failure names the first mismatching path so an
|
|
110
217
|
* operator can act on it, and no path here ever consults PATH.
|
|
218
|
+
*
|
|
219
|
+
* This is the packaged tree, not the cache: callers that intend to RUN the
|
|
220
|
+
* shell want {@link prepareRuntime}, which publishes a copy first.
|
|
111
221
|
* @param host - the running host's platform facts.
|
|
112
222
|
* @param packageRoot - package root holding the payload.
|
|
113
223
|
* @returns the resolved shell paths, or the rejection reason.
|
|
114
224
|
*/
|
|
115
225
|
export declare function resolveRuntime(host: HostPlatform, packageRoot?: string): RuntimeReady | RuntimeRejection;
|
|
226
|
+
/** One tree copy: the source payload root, the directory to fill. */
|
|
227
|
+
export type CopyTree = (source: string, target: string) => void;
|
|
228
|
+
/** Where payload publication can be redirected, and what it reports. */
|
|
229
|
+
export interface PrepareRuntimeOptions {
|
|
230
|
+
/** The running host's platform facts; this process's by default. */
|
|
231
|
+
readonly host?: HostPlatform;
|
|
232
|
+
/** Package root holding runtime/win32-x64; this package's own by default. */
|
|
233
|
+
readonly packageRoot?: string;
|
|
234
|
+
/** Cache root to publish into; the DSH home's own by default. */
|
|
235
|
+
readonly cacheRoot?: string;
|
|
236
|
+
/** Isolated fallback root; the per-user app-data cache by default. */
|
|
237
|
+
readonly isolatedCacheRoot?: string;
|
|
238
|
+
/** Environment the default roots resolve from; process.env by default. */
|
|
239
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
240
|
+
/** Mandatory-integrity-label reader; the Windows icacls reader by default. */
|
|
241
|
+
readonly readLabel?: LabelReader;
|
|
242
|
+
/** Operator-facing notes; a copy that could not be published is reported here. */
|
|
243
|
+
readonly warn?: (message: string) => void;
|
|
244
|
+
/** The copy itself; a real recursive copy by default. */
|
|
245
|
+
readonly copy?: CopyTree;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Resolve the shell one host runs, publishing the payload outside the package.
|
|
249
|
+
*
|
|
250
|
+
* Two independent proofs gate every tree that can be spawned: the shipped
|
|
251
|
+
* SHA256 manifest proves its BYTES, and a mandatory-integrity-label check
|
|
252
|
+
* proves its SECURITY DESCRIPTOR cannot downgrade a Medium runner to a Low
|
|
253
|
+
* process. A label check runs before a published copy is reused, before a new
|
|
254
|
+
* copy is published, and again after publication (the decisive check is on the
|
|
255
|
+
* bash.exe that will actually be spawned). A tree carrying Low or Untrusted is
|
|
256
|
+
* never reused and never spawned from, so a hash match alone can no longer keep
|
|
257
|
+
* a broken cache alive across restarts and updates.
|
|
258
|
+
*
|
|
259
|
+
* Candidate roots are tried in order. The DSH home cache keeps the #1996 fix;
|
|
260
|
+
* when its data tree is labelled Low, the payload is published into an isolated
|
|
261
|
+
* per-user application-data root instead, still OUTSIDE the package. An old Low
|
|
262
|
+
* cache under the DSH home is therefore migrated by abandonment, not by a
|
|
263
|
+
* one-off repair of one payload-key directory.
|
|
264
|
+
*
|
|
265
|
+
* When no candidate can be written or verified, the verified packaged tree runs
|
|
266
|
+
* instead and the caller is told, through {@link PrepareRuntimeOptions.warn},
|
|
267
|
+
* that updates will need this host stopped. But if a Low label was observed and
|
|
268
|
+
* even the packaged image is not proven clean, the mount is REFUSED with
|
|
269
|
+
* `unsafe-integrity` rather than silently executing a shell that cannot write
|
|
270
|
+
* the session's workspace. A payload that fails its manifest is always a
|
|
271
|
+
* refusal, cache or no cache.
|
|
272
|
+
* @param options - host facts, roots, and the seams tests drive.
|
|
273
|
+
* @returns the shell paths to run, or the rejection reason.
|
|
274
|
+
*/
|
|
275
|
+
export declare function prepareRuntime(options?: PrepareRuntimeOptions): RuntimeReady | RuntimeRejection;
|
package/lib/types/shell.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ export declare const SHELL_STDERR_CAPTURE_BYTES: number;
|
|
|
33
33
|
export declare const TIMEOUT_EXIT_CODE = 124;
|
|
34
34
|
/** Environment variable names carrying the per-shell private temp directory. */
|
|
35
35
|
export declare const TEMP_ENV_KEYS: readonly ["TMPDIR", "TMP", "TEMP"];
|
|
36
|
+
/**
|
|
37
|
+
* Name prefix of every private per-shell temp directory. The rest of the name
|
|
38
|
+
* is the owning process id plus a random suffix, which is what lets a later
|
|
39
|
+
* start tell an orphan from a directory a live shell is still using.
|
|
40
|
+
*/
|
|
41
|
+
export declare const SHELL_TEMP_PREFIX = "dsh-win-bash-";
|
|
36
42
|
/**
|
|
37
43
|
* The argv of one pinned shell: the payload's own bash by absolute path, no rc
|
|
38
44
|
* file and no profile, reading its commands from stdin. This tool never
|
|
@@ -57,9 +63,55 @@ export declare function shellEnvironment(runtime: {
|
|
|
57
63
|
}, temp: string, base?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
58
64
|
/**
|
|
59
65
|
* Create one shell process's private temp directory.
|
|
66
|
+
* @param base - the temp root to create it under; the machine's own by default.
|
|
60
67
|
* @returns the absolute directory, created if absent.
|
|
61
68
|
*/
|
|
62
|
-
export declare function shellTempDir(): string;
|
|
69
|
+
export declare function shellTempDir(base?: string): string;
|
|
70
|
+
/**
|
|
71
|
+
* Delete one private temp directory, never letting the attempt throw.
|
|
72
|
+
*
|
|
73
|
+
* Teardown must not fail because a directory could not be reclaimed: the shell
|
|
74
|
+
* is already gone, and whatever is left is named for this process's own pid, so
|
|
75
|
+
* the next start's {@link sweepOrphanShellTempDirs} collects it once that pid is
|
|
76
|
+
* gone.
|
|
77
|
+
* @param temp - the directory that shell owned.
|
|
78
|
+
*/
|
|
79
|
+
export declare function removeShellTempDir(temp: string): Promise<void>;
|
|
80
|
+
/** What one orphan sweep found and did, for logging and for tests. */
|
|
81
|
+
export interface ShellTempSweep {
|
|
82
|
+
/** Directories this sweep deleted. */
|
|
83
|
+
readonly removed: string[];
|
|
84
|
+
/** Directories whose owning process is still alive. */
|
|
85
|
+
readonly kept: string[];
|
|
86
|
+
/** Directories that could not be deleted; the next start tries again. */
|
|
87
|
+
readonly failed: string[];
|
|
88
|
+
}
|
|
89
|
+
/** The seams one orphan sweep runs against. */
|
|
90
|
+
export interface ShellTempSweepOptions {
|
|
91
|
+
/** The temp root to scan; the machine's own by default. */
|
|
92
|
+
readonly root?: string;
|
|
93
|
+
/** Whether the process that owned a directory still exists. */
|
|
94
|
+
readonly isAlive?: (pid: number) => boolean;
|
|
95
|
+
/** How one directory is deleted; a rejection marks it failed. */
|
|
96
|
+
readonly remove?: (dir: string) => Promise<void>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Reclaim the private temp directories of shells that no longer exist.
|
|
100
|
+
*
|
|
101
|
+
* A crash or a hard kill ends this process before it can delete what its live
|
|
102
|
+
* shells owned, and those directories are not small: whatever a command wrote
|
|
103
|
+
* under TMP/TEMP/TMPDIR is still in them. Every name carries the pid that owned
|
|
104
|
+
* it, so the ones whose pid is gone are garbage by construction, and the ones
|
|
105
|
+
* whose pid still runs may belong to a live shell in this very process or to
|
|
106
|
+
* another instance sharing the temp root - those are kept.
|
|
107
|
+
*
|
|
108
|
+
* One directory that cannot be deleted is reported and skipped; it must not
|
|
109
|
+
* stop the round, because the usual cause (a long path, a locked file) is local
|
|
110
|
+
* to that directory.
|
|
111
|
+
* @param options - the seams; production passes none.
|
|
112
|
+
* @returns what was removed, kept and failed.
|
|
113
|
+
*/
|
|
114
|
+
export declare function sweepOrphanShellTempDirs(options?: ShellTempSweepOptions): Promise<ShellTempSweep>;
|
|
63
115
|
/** One command's complete result, as the tool consumes it. */
|
|
64
116
|
export interface ShellResult {
|
|
65
117
|
/** The command's stdout, bounded to the visible budget. */
|
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.15",
|
|
5
5
|
"icon": "icon.svg",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|
|
@@ -18,22 +18,22 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dsh": {
|
|
20
20
|
"engines": {
|
|
21
|
-
"dsh": ">=0.2.
|
|
21
|
+
"dsh": ">=0.2.2-rc.1"
|
|
22
22
|
},
|
|
23
23
|
"bundle": {
|
|
24
24
|
"patch": "./cordis.patch.yml"
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@deepseek-ai/dsh": ">=0.2.
|
|
28
|
+
"@deepseek-ai/dsh": ">=0.2.2-rc.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@deepseek-ai/cordis": "^4.0
|
|
32
|
-
"@deepseek-ai/dsh-agent": "^0.2.
|
|
33
|
-
"@deepseek-ai/dsh-sandbox": "^0.2.
|
|
34
|
-
"@deepseek-ai/dsh-subprocess": "^0.2.
|
|
35
|
-
"@deepseek-ai/dsh-tools": "^0.2.
|
|
36
|
-
"@deepseek-ai/schemastery": "^3.
|
|
31
|
+
"@deepseek-ai/cordis": "^4.1.0",
|
|
32
|
+
"@deepseek-ai/dsh-agent": "^0.2.2-rc.1",
|
|
33
|
+
"@deepseek-ai/dsh-sandbox": "^0.2.2-rc.1",
|
|
34
|
+
"@deepseek-ai/dsh-subprocess": "^0.2.2-rc.1",
|
|
35
|
+
"@deepseek-ai/dsh-tools": "^0.2.2-rc.1",
|
|
36
|
+
"@deepseek-ai/schemastery": "^3.19.0",
|
|
37
37
|
"@types/node": "^22.20.0",
|
|
38
38
|
"tsdown": "0.22.2",
|
|
39
39
|
"typescript": "~5.7.2",
|
package/src/background.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* STRUCTURALLY: a leaf plugin takes no dependency on @deepseek-ai/dsh-jobs to
|
|
16
16
|
* call one method on an optional service, and the same decision keeps this
|
|
17
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.
|
|
18
|
+
* mirrored from the published declaration of @deepseek-ai/dsh-jobs@0.2.2-rc.1:
|
|
19
19
|
*
|
|
20
20
|
* lib/types/index.d.ts
|
|
21
21
|
* abstract class JobRegistry {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
43
|
import type { SubprocessHandle, SubprocessRuntime } from '@deepseek-ai/dsh-subprocess'
|
|
44
|
-
import { DEFAULT_SPILL_BYTES, GRACE_MS, SHELL_STDERR_CAPTURE_BYTES } from './shell.ts'
|
|
44
|
+
import { DEFAULT_SPILL_BYTES, GRACE_MS, SHELL_STDERR_CAPTURE_BYTES, removeShellTempDir } from './shell.ts'
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Producer kind of every job this plugin starts. It namespaces the ids the
|
|
@@ -137,6 +137,13 @@ export interface BackgroundCommand {
|
|
|
137
137
|
readonly cwd: string
|
|
138
138
|
/** Environment entries for the process. */
|
|
139
139
|
readonly env: NodeJS.ProcessEnv
|
|
140
|
+
/**
|
|
141
|
+
* The private temp directory this job owns, when the caller created one (it is
|
|
142
|
+
* the TMP/TEMP/TMPDIR in {@link env}). Reclaimed when the job settles, on every
|
|
143
|
+
* path: the process's own exit, a kill through the hooks, and a starter that
|
|
144
|
+
* never spawned.
|
|
145
|
+
*/
|
|
146
|
+
readonly temp?: string
|
|
140
147
|
/** Label shown for this job. */
|
|
141
148
|
readonly label: string
|
|
142
149
|
/** In-memory capture ceiling for stdout, in bytes. */
|
|
@@ -230,7 +237,7 @@ export function startBackgroundJob(command: BackgroundCommand): string {
|
|
|
230
237
|
failedBeforeStart = messageOf(error)
|
|
231
238
|
}
|
|
232
239
|
const spawned = process
|
|
233
|
-
const
|
|
240
|
+
const settled: Promise<JobOutcomeLike> = spawned === undefined
|
|
234
241
|
? Promise.resolve(processOutcome(undefined, failedBeforeStart, false))
|
|
235
242
|
: spawned.done.then(
|
|
236
243
|
async (outcome) => {
|
|
@@ -251,6 +258,16 @@ export function startBackgroundJob(command: BackgroundCommand): string {
|
|
|
251
258
|
return processOutcome(undefined, failedBeforeStart, false)
|
|
252
259
|
},
|
|
253
260
|
)
|
|
261
|
+
// The job owned its private temp directory for exactly as long as it ran.
|
|
262
|
+
// This runs on all three endings - own exit, kill through the hooks, and a
|
|
263
|
+
// starter that never spawned - because each of them leaves the directory
|
|
264
|
+
// with nothing left to use it. A reclaim that fails is contained: the
|
|
265
|
+
// directory is named for this process's pid, so the next start's orphan
|
|
266
|
+
// sweep collects it.
|
|
267
|
+
const done: Promise<JobOutcomeLike> = settled.then(async (outcome) => {
|
|
268
|
+
if (command.temp !== undefined) await removeShellTempDir(command.temp)
|
|
269
|
+
return outcome
|
|
270
|
+
})
|
|
254
271
|
return {
|
|
255
272
|
cancel: () => {
|
|
256
273
|
if (terminated) return
|
package/src/dsh-home.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Generated by scripts/sync-shared.mjs from shared/host/dsh-home.ts. Do not edit this copy; edit the shared source and run "node scripts/sync-shared.mjs".
|
|
2
|
+
/**
|
|
3
|
+
* DSH_HOME resolution shared by the plugin family's Host halves: the
|
|
4
|
+
* environment override wins, the platform home fallback follows. Mirrors
|
|
5
|
+
* what dsh-pet and dsh-liangshen each used to implement locally.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { homedir } from 'node:os'
|
|
9
|
+
import { isAbsolute, join } from 'node:path'
|
|
10
|
+
import { isAbsolute as posixIsAbsolute, join as posixJoin } from 'node:path/posix'
|
|
11
|
+
|
|
12
|
+
/** Expand a leading ~ (or ~user) in a path, platform-style. */
|
|
13
|
+
export function expandHome(path: string, home: string = homedir()): string {
|
|
14
|
+
const isPosix = home.startsWith('/')
|
|
15
|
+
const j = isPosix ? posixJoin : join
|
|
16
|
+
if (path === '~') return home
|
|
17
|
+
if (path.startsWith('~/') || path.startsWith('~\\')) return j(home, path.slice(2))
|
|
18
|
+
return path
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Resolve the DSH home directory.
|
|
23
|
+
* @param env - process environment to read DSH_HOME from.
|
|
24
|
+
* @param home - platform home directory fallback (test seam).
|
|
25
|
+
* @returns the absolute DSH home path.
|
|
26
|
+
*/
|
|
27
|
+
export function resolveDshHome(env: NodeJS.ProcessEnv = process.env, home: string = homedir()): string {
|
|
28
|
+
const isPosix = home.startsWith('/')
|
|
29
|
+
const j = isPosix ? posixJoin : join
|
|
30
|
+
const isAbs = isPosix ? posixIsAbsolute : isAbsolute
|
|
31
|
+
const raw = env.DSH_HOME
|
|
32
|
+
if (raw !== undefined && raw.trim() !== '') {
|
|
33
|
+
const expanded = expandHome(raw.trim(), home)
|
|
34
|
+
return isAbs(expanded) ? expanded : j(process.cwd(), expanded)
|
|
35
|
+
}
|
|
36
|
+
return j(home, '.dsh')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Resolve the DSH home directory from the live environment. */
|
|
40
|
+
export function dshHome(): string {
|
|
41
|
+
return resolveDshHome()
|
|
42
|
+
}
|
package/src/gate.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* on @deepseek-ai/dsh-agent-preset-registry (a leaf plugin takes no SDK
|
|
13
13
|
* dependency to read one optional service), so the single method consumed is
|
|
14
14
|
* mirrored from the published declaration of
|
|
15
|
-
* @deepseek-ai/dsh-agent-preset-registry@0.2.
|
|
15
|
+
* @deepseek-ai/dsh-agent-preset-registry@0.2.2-rc.1, lib/types/index.d.ts:
|
|
16
16
|
*
|
|
17
17
|
* export declare class AgentPresetRegistry {
|
|
18
18
|
* list(): Promise<AgentPreset[]>
|