@linxin666/dsh-win-bash 0.4.21 → 0.4.23
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 +17 -0
- package/README.zh.md +14 -0
- package/lib/index.js +455 -28
- package/lib/types/dsh-home.d.ts +13 -3
- package/lib/types/environment.d.ts +162 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/pwsh-replacement.d.ts +16 -4
- package/package.json +9 -9
- package/src/dsh-home.ts +35 -12
- package/src/environment.ts +516 -0
- package/src/index.ts +11 -0
- package/src/pwsh-replacement.ts +78 -14
- package/src/tool.ts +54 -5
package/lib/types/dsh-home.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* DSH_HOME resolution shared by the plugin family's Host
|
|
3
|
-
* environment
|
|
4
|
-
*
|
|
2
|
+
* DSH_HOME and DSH_AGENTS_HOME resolution shared by the plugin family's Host
|
|
3
|
+
* halves: environment overrides win (blank values treated as unset), then the
|
|
4
|
+
* platform home fallbacks follow — mirroring `@deepseek-ai/dsh-home-paths`.
|
|
5
5
|
*/
|
|
6
6
|
/** Expand a leading ~ (or ~user) in a path, platform-style. */
|
|
7
7
|
export declare function expandHome(path: string, home?: string): string;
|
|
@@ -14,3 +14,13 @@ export declare function expandHome(path: string, home?: string): string;
|
|
|
14
14
|
export declare function resolveDshHome(env?: NodeJS.ProcessEnv, home?: string): string;
|
|
15
15
|
/** Resolve the DSH home directory from the live environment. */
|
|
16
16
|
export declare function dshHome(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the shared agent configuration root (`$DSH_AGENTS_HOME`, defaulting
|
|
19
|
+
* to `<home>/.agents`), matching `@deepseek-ai/dsh-home-paths`'s `resolveAgentsHome`.
|
|
20
|
+
* @param env - process environment to read DSH_AGENTS_HOME from.
|
|
21
|
+
* @param home - platform home directory fallback (test seam).
|
|
22
|
+
* @returns the absolute shared agents home path.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveAgentsHome(env?: NodeJS.ProcessEnv, home?: string): string;
|
|
25
|
+
/** Resolve the shared agent configuration root from the live environment. */
|
|
26
|
+
export declare function agentsHome(): string;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote execution environment forwarding for `win_bash` (DSH 0.2.3-alpha.4+).
|
|
3
|
+
*
|
|
4
|
+
* When a call carries `exec.environment`, `win_bash` forwards the command to
|
|
5
|
+
* the host's optional `environments` registry (`ctx.environments`) as a
|
|
6
|
+
* self-contained daemon function invoking `/usr/bin/env bash -c <command>`.
|
|
7
|
+
* Unlike the local Windows MSYS2 persistent shell (which runs only under
|
|
8
|
+
* `danger-full-access` due to `NtCreateDirectoryObject 0xC0000022`), remote
|
|
9
|
+
* POSIX environments enforce the resolved session sandbox policy (`read-only`,
|
|
10
|
+
* `workspace-write`, or `danger-full-access`) through `remoteSandboxPolicy`.
|
|
11
|
+
* Each remote call runs an ephemeral `bash -c` invocation (matching upstream
|
|
12
|
+
* `@deepseek-ai/dsh-tool-bash/environment`).
|
|
13
|
+
*
|
|
14
|
+
* SHAPE, NOT IMPORT: consumes `ctx.environments` structurally (the same leaf
|
|
15
|
+
* discipline as `./background.ts`), requiring no runtime dependency on
|
|
16
|
+
* `@deepseek-ai/dsh-environment` or `zod`.
|
|
17
|
+
* @module @linxin666/dsh-win-bash/environment
|
|
18
|
+
*/
|
|
19
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
20
|
+
import { type SandboxExecutionPolicy, type SandboxMode } from '@deepseek-ai/dsh-sandbox';
|
|
21
|
+
import { type ToolEnvironmentTarget } from '@deepseek-ai/dsh-tools';
|
|
22
|
+
import { type JobRegistryLike } from './background.ts';
|
|
23
|
+
/** Request object structured-cloned to the remote daemon function. */
|
|
24
|
+
export interface RemoteBashRequest {
|
|
25
|
+
readonly command: string;
|
|
26
|
+
readonly cwd: string | undefined;
|
|
27
|
+
readonly workdir: string | undefined;
|
|
28
|
+
readonly maxStdoutBytes: number;
|
|
29
|
+
readonly maxStderrBytes: number;
|
|
30
|
+
}
|
|
31
|
+
/** Captured stream tail from the remote daemon. */
|
|
32
|
+
export interface RemoteStreamCapture {
|
|
33
|
+
readonly text: string;
|
|
34
|
+
readonly truncated: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** Optional sandbox report returned by the remote daemon. */
|
|
37
|
+
export interface RemoteSandboxReport {
|
|
38
|
+
readonly mode: SandboxMode;
|
|
39
|
+
readonly enforcement?: 'full' | 'none';
|
|
40
|
+
readonly denied: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** Discriminated outcome returned by {@link remoteEnvironmentBash}. */
|
|
43
|
+
export type RemoteBashOutcome = {
|
|
44
|
+
readonly kind: 'exited';
|
|
45
|
+
readonly cwd: string;
|
|
46
|
+
readonly exitCode: number | null;
|
|
47
|
+
readonly signal: string | null;
|
|
48
|
+
readonly stdout: RemoteStreamCapture;
|
|
49
|
+
readonly stderr: RemoteStreamCapture;
|
|
50
|
+
readonly sandbox?: RemoteSandboxReport;
|
|
51
|
+
} | {
|
|
52
|
+
readonly kind: 'workdir';
|
|
53
|
+
readonly cwd: string;
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: 'platform';
|
|
56
|
+
readonly platform: string;
|
|
57
|
+
};
|
|
58
|
+
/** Minimal daemon-side `env` surface provided by `@deepseek-ai/dsh-environment`. */
|
|
59
|
+
export interface RemoteEnvironmentContextLike {
|
|
60
|
+
readonly platform: string;
|
|
61
|
+
readonly cwd: string;
|
|
62
|
+
readonly limits: {
|
|
63
|
+
readonly maxMessageBytes: number;
|
|
64
|
+
};
|
|
65
|
+
readonly path: {
|
|
66
|
+
resolve(base: string, target: string): string;
|
|
67
|
+
};
|
|
68
|
+
readonly fs: {
|
|
69
|
+
stat(path: string): Promise<{
|
|
70
|
+
isDirectory(): boolean;
|
|
71
|
+
}>;
|
|
72
|
+
};
|
|
73
|
+
exec(argv: readonly string[], options: {
|
|
74
|
+
readonly cwd: string;
|
|
75
|
+
}): Promise<{
|
|
76
|
+
readonly exitCode: number | null;
|
|
77
|
+
readonly signal: string | null;
|
|
78
|
+
readonly stdout: string;
|
|
79
|
+
readonly stderr: string;
|
|
80
|
+
readonly stdoutTruncated: boolean;
|
|
81
|
+
readonly stderrTruncated: boolean;
|
|
82
|
+
readonly sandbox?: RemoteSandboxReport;
|
|
83
|
+
}>;
|
|
84
|
+
}
|
|
85
|
+
/** Structural result parser compatible with `EnvironmentRegistry.define`'s `safeParse` contract. */
|
|
86
|
+
export interface ResultValidatorLike<T> {
|
|
87
|
+
safeParse(value: unknown): {
|
|
88
|
+
readonly success: true;
|
|
89
|
+
readonly data: T;
|
|
90
|
+
} | {
|
|
91
|
+
readonly success: false;
|
|
92
|
+
readonly error: {
|
|
93
|
+
readonly message: string;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Runner returned by `EnvironmentRegistry.define`. */
|
|
98
|
+
export type EnvironmentRunnerLike<A, T> = (handle: unknown, args: A, options: {
|
|
99
|
+
readonly signal: AbortSignal;
|
|
100
|
+
readonly awaitStop?: boolean;
|
|
101
|
+
readonly sandbox?: unknown;
|
|
102
|
+
}) => Promise<T>;
|
|
103
|
+
/** Structural face of the optional `environments` host service (`EnvironmentRegistry`). */
|
|
104
|
+
export interface EnvironmentRegistryLike {
|
|
105
|
+
handle(value: string): unknown;
|
|
106
|
+
capabilities(handle: unknown, options: {
|
|
107
|
+
readonly signal: AbortSignal;
|
|
108
|
+
}): Promise<{
|
|
109
|
+
readonly cwd: string;
|
|
110
|
+
}>;
|
|
111
|
+
define<A, T>(fn: (request: A, env: RemoteEnvironmentContextLike) => Promise<T>, options: {
|
|
112
|
+
readonly result: ResultValidatorLike<T>;
|
|
113
|
+
}): EnvironmentRunnerLike<A, T>;
|
|
114
|
+
}
|
|
115
|
+
/** Foreground return payload matching `win_bash`'s canonical output schema. */
|
|
116
|
+
export interface RemoteForegroundResult {
|
|
117
|
+
readonly stdout: string;
|
|
118
|
+
readonly stderr: string;
|
|
119
|
+
readonly exitCode: number;
|
|
120
|
+
readonly stdoutTruncated: boolean;
|
|
121
|
+
readonly stderrTruncated: boolean;
|
|
122
|
+
readonly stdoutLostHead: boolean;
|
|
123
|
+
readonly stderrLostHead: boolean;
|
|
124
|
+
readonly frameOverflow: boolean;
|
|
125
|
+
}
|
|
126
|
+
/** Validate a raw structured-cloned reply returned from a remote environment daemon. */
|
|
127
|
+
export declare const remoteBashOutcomeValidator: ResultValidatorLike<RemoteBashOutcome>;
|
|
128
|
+
/**
|
|
129
|
+
* Daemon-side command function sent via `fn.toString()`.
|
|
130
|
+
* Must remain strictly self-contained: no module-scope closures or helper imports.
|
|
131
|
+
*/
|
|
132
|
+
export declare function remoteEnvironmentBash(request: RemoteBashRequest, env: RemoteEnvironmentContextLike): Promise<RemoteBashOutcome>;
|
|
133
|
+
/** Remote runner bound to one plugin context's optional `environments` registry. */
|
|
134
|
+
export interface RemoteWinBashRunner {
|
|
135
|
+
runForeground(input: {
|
|
136
|
+
readonly target: ToolEnvironmentTarget;
|
|
137
|
+
readonly signal: AbortSignal;
|
|
138
|
+
readonly command: string;
|
|
139
|
+
readonly workdir: string | undefined;
|
|
140
|
+
readonly timeoutMs: number;
|
|
141
|
+
readonly maxStdoutBytes: number;
|
|
142
|
+
readonly maxStderrBytes: number;
|
|
143
|
+
readonly policy: SandboxExecutionPolicy;
|
|
144
|
+
}): Promise<RemoteForegroundResult>;
|
|
145
|
+
startBackground(input: {
|
|
146
|
+
readonly jobs: JobRegistryLike;
|
|
147
|
+
readonly owner: string | undefined;
|
|
148
|
+
readonly target: ToolEnvironmentTarget;
|
|
149
|
+
readonly command: string;
|
|
150
|
+
readonly workdir: string | undefined;
|
|
151
|
+
readonly maxStdoutBytes: number;
|
|
152
|
+
readonly maxStderrBytes: number;
|
|
153
|
+
readonly policy: SandboxExecutionPolicy;
|
|
154
|
+
}): string;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Create the optional `ctx.environments` forwarding runner for `win_bash`.
|
|
158
|
+
* Tracks registry load/unload through `ctx.inject(['environments'], ...)` when
|
|
159
|
+
* available, and falls back to lazy `ctx.get('environments')` lookup keyed per
|
|
160
|
+
* registry instance so synchronous host stubs work without waiting a microtask.
|
|
161
|
+
*/
|
|
162
|
+
export declare function createRemoteWinBashRunner(ctx: Context): RemoteWinBashRunner;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export { CONFIG_DEFAULTS, DEFAULT_DESCRIPTION, DEFAULT_ENABLE_RUN_IN_BACKGROUND,
|
|
|
60
60
|
export { HOST_PWSH_TOOL, SERVING_MODE, installPwshReplacement, type PwshReplacementOptions, type ScopedRestrictor, type SessionPolicyReader, } from './pwsh-replacement.ts';
|
|
61
61
|
export { WIN_BASH_TOOL, renderResult, readJobRegistry, stripTerminalEscapes, truncationNotice } from './tool.ts';
|
|
62
62
|
export type { RenderFacts } from './tool.ts';
|
|
63
|
+
export { createRemoteWinBashRunner, remoteBashOutcomeValidator, remoteEnvironmentBash, type EnvironmentRegistryLike, type RemoteBashOutcome, type RemoteBashRequest, type RemoteEnvironmentContextLike, type RemoteForegroundResult, type RemoteWinBashRunner, } from './environment.ts';
|
|
63
64
|
export { SHELL_TEMP_PREFIX, ShellRegistry, ShellUnavailableError, removeShellTempDir, shellArgv, shellEnvironment, shellTempDir, sweepOrphanShellTempDirs, type ShellTempSweep, type ShellTempSweepOptions, } from './shell.ts';
|
|
64
65
|
export { buildFrame, markerFor, parseFrame } from './protocol.ts';
|
|
65
66
|
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';
|
|
@@ -37,8 +37,18 @@
|
|
|
37
37
|
* entering a restricted mode releases the restriction immediately, and
|
|
38
38
|
* returning to danger-full-access withdraws again. The listener is registered
|
|
39
39
|
* with `{ global: true }` because a session's own log event is not dispatched to
|
|
40
|
-
* this plugin's scope
|
|
41
|
-
*
|
|
40
|
+
* this plugin's scope. `internal/dispatch` fires while the event is still being
|
|
41
|
+
* validated, BEFORE the session log and the policy's mode projection see it, so
|
|
42
|
+
* a read made inside the listener answers with the OLD mode (issue #2096); the
|
|
43
|
+
* re-evaluation is therefore queued as one microtask, which runs once the
|
|
44
|
+
* synchronous append has committed — no poll, no timer, nothing on a boot path.
|
|
45
|
+
*
|
|
46
|
+
* THE POLICY SERVICE CAN ARRIVE AFTER THIS MODULE. On a cold start the
|
|
47
|
+
* `sandboxPolicy` service may not be registered yet when win_bash mounts, so
|
|
48
|
+
* the authority is resolved on every evaluation instead of being captured
|
|
49
|
+
* once at install time (a captured `undefined` made every later verdict
|
|
50
|
+
* 'unknown' forever, issue #2096), and its registration (`internal/service`)
|
|
51
|
+
* re-evaluates every watched scope.
|
|
42
52
|
*
|
|
43
53
|
* WINDOWS ONLY. The ladder this module encodes is a Windows fact: win_bash is
|
|
44
54
|
* the pinned MSYS2 shell a Windows session gets, and the host shell beside it
|
|
@@ -116,8 +126,10 @@ export interface PwshReplacementOptions {
|
|
|
116
126
|
/** Tool names to withdraw; defaults to {@link HOST_PWSH_TOOL}. */
|
|
117
127
|
readonly denied?: readonly string[];
|
|
118
128
|
/**
|
|
119
|
-
* One-time warning sink. The default writes through the plugin logger
|
|
120
|
-
*
|
|
129
|
+
* One-time warning sink. The default writes through the plugin logger AND to
|
|
130
|
+
* stderr: the `dsh web` boot exporter keeps logger warnings in memory only, so
|
|
131
|
+
* a logger-only warning never reaches the operator's terminal (issue #2096).
|
|
132
|
+
* A caller may replace it.
|
|
121
133
|
*/
|
|
122
134
|
readonly warn?: (message: string) => void;
|
|
123
135
|
/**
|
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.23",
|
|
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.3-alpha.4"
|
|
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.3-alpha.4"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@deepseek-ai/cordis": "
|
|
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": "
|
|
31
|
+
"@deepseek-ai/cordis": "~4.2.0-alpha.3",
|
|
32
|
+
"@deepseek-ai/dsh-agent": "^0.2.3-alpha.4",
|
|
33
|
+
"@deepseek-ai/dsh-sandbox": "^0.2.3-alpha.4",
|
|
34
|
+
"@deepseek-ai/dsh-subprocess": "^0.2.3-alpha.4",
|
|
35
|
+
"@deepseek-ai/dsh-tools": "^0.2.3-alpha.4",
|
|
36
|
+
"@deepseek-ai/schemastery": "~3.20.0-alpha.3",
|
|
37
37
|
"@types/node": "^22.20.0",
|
|
38
38
|
"tsdown": "0.22.2",
|
|
39
39
|
"typescript": "~5.7.2",
|
package/src/dsh-home.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
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
2
|
/**
|
|
3
|
-
* DSH_HOME resolution shared by the plugin family's Host
|
|
4
|
-
* environment
|
|
5
|
-
*
|
|
3
|
+
* DSH_HOME and DSH_AGENTS_HOME resolution shared by the plugin family's Host
|
|
4
|
+
* halves: environment overrides win (blank values treated as unset), then the
|
|
5
|
+
* platform home fallbacks follow — mirroring `@deepseek-ai/dsh-home-paths`.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { homedir } from 'node:os'
|
|
@@ -18,6 +18,21 @@ export function expandHome(path: string, home: string = homedir()): string {
|
|
|
18
18
|
return path
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
function resolveUserRoot(
|
|
22
|
+
envValue: string | undefined,
|
|
23
|
+
defaultDirName: string,
|
|
24
|
+
home: string,
|
|
25
|
+
): string {
|
|
26
|
+
const isPosix = home.startsWith('/')
|
|
27
|
+
const j = isPosix ? posixJoin : join
|
|
28
|
+
const isAbs = isPosix ? posixIsAbsolute : isAbsolute
|
|
29
|
+
if (envValue !== undefined && envValue.trim() !== '') {
|
|
30
|
+
const expanded = expandHome(envValue.trim(), home)
|
|
31
|
+
return isAbs(expanded) ? expanded : j(process.cwd(), expanded)
|
|
32
|
+
}
|
|
33
|
+
return j(home, defaultDirName)
|
|
34
|
+
}
|
|
35
|
+
|
|
21
36
|
/**
|
|
22
37
|
* Resolve the DSH home directory.
|
|
23
38
|
* @param env - process environment to read DSH_HOME from.
|
|
@@ -25,18 +40,26 @@ export function expandHome(path: string, home: string = homedir()): string {
|
|
|
25
40
|
* @returns the absolute DSH home path.
|
|
26
41
|
*/
|
|
27
42
|
export function resolveDshHome(env: NodeJS.ProcessEnv = process.env, home: string = homedir()): string {
|
|
28
|
-
|
|
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')
|
|
43
|
+
return resolveUserRoot(env.DSH_HOME, '.dsh', home)
|
|
37
44
|
}
|
|
38
45
|
|
|
39
46
|
/** Resolve the DSH home directory from the live environment. */
|
|
40
47
|
export function dshHome(): string {
|
|
41
48
|
return resolveDshHome()
|
|
42
49
|
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Resolve the shared agent configuration root (`$DSH_AGENTS_HOME`, defaulting
|
|
53
|
+
* to `<home>/.agents`), matching `@deepseek-ai/dsh-home-paths`'s `resolveAgentsHome`.
|
|
54
|
+
* @param env - process environment to read DSH_AGENTS_HOME from.
|
|
55
|
+
* @param home - platform home directory fallback (test seam).
|
|
56
|
+
* @returns the absolute shared agents home path.
|
|
57
|
+
*/
|
|
58
|
+
export function resolveAgentsHome(env: NodeJS.ProcessEnv = process.env, home: string = homedir()): string {
|
|
59
|
+
return resolveUserRoot(env.DSH_AGENTS_HOME, '.agents', home)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Resolve the shared agent configuration root from the live environment. */
|
|
63
|
+
export function agentsHome(): string {
|
|
64
|
+
return resolveAgentsHome()
|
|
65
|
+
}
|