dsh-git-desk 0.18.1 → 0.20.0
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.md +11 -0
- package/client.js +5 -4847
- package/dist/contract.js +5 -0
- package/{index.js → dist/host/index.js} +4 -5
- package/dist/host/lib/ai.js +266 -0
- package/dist/host/lib/exec.js +193 -0
- package/dist/host/lib/git.js +1317 -0
- package/dist/host/lib/http.js +168 -0
- package/dist/host/lib/parse.js +381 -0
- package/dist/host/lib/rpc.js +316 -0
- package/dist/host/lib/types.js +1 -0
- package/package.json +18 -4
- package/lib/ai.js +0 -187
- package/lib/exec.js +0 -168
- package/lib/git.js +0 -1037
- package/lib/http.js +0 -139
- package/lib/parse.js +0 -319
- package/lib/rpc.js +0 -266
package/lib/exec.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { lstat, readFile, readdir, realpath, stat, writeFile } from 'node:fs/promises';
|
|
2
|
-
|
|
3
|
-
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
4
|
-
const NETWORK_TIMEOUT_MS = 180_000;
|
|
5
|
-
|
|
6
|
-
export class GitError extends Error {
|
|
7
|
-
constructor(code, message, details = {}) {
|
|
8
|
-
super(message);
|
|
9
|
-
this.name = 'GitError';
|
|
10
|
-
this.code = code;
|
|
11
|
-
this.details = details;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Run one managed child process and collect both streams.
|
|
17
|
-
* The provider owns cancellation. This wrapper only adds a wall clock and
|
|
18
|
-
* folds a spawn failure into a normal command result so callers can show it.
|
|
19
|
-
*/
|
|
20
|
-
export function createRuntime(subprocess) {
|
|
21
|
-
let gitPath;
|
|
22
|
-
let gitPathError;
|
|
23
|
-
|
|
24
|
-
async function resolveGit() {
|
|
25
|
-
if (gitPath !== undefined) return gitPath;
|
|
26
|
-
if (gitPathError !== undefined) throw gitPathError;
|
|
27
|
-
try {
|
|
28
|
-
gitPath = await subprocess.resolveExecutable('git');
|
|
29
|
-
return gitPath;
|
|
30
|
-
} catch (error) {
|
|
31
|
-
gitPathError = new GitError('git/not-installed', 'Git is not installed or is not on PATH.', {
|
|
32
|
-
cause: error instanceof Error ? error.message : String(error),
|
|
33
|
-
});
|
|
34
|
-
throw gitPathError;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function run(cwd, args, options = {}) {
|
|
39
|
-
const executable = await resolveGit();
|
|
40
|
-
const timeoutMs = options.timeoutMs ?? (options.network ? NETWORK_TIMEOUT_MS : DEFAULT_TIMEOUT_MS);
|
|
41
|
-
const timeout = AbortSignal.timeout(timeoutMs);
|
|
42
|
-
const signal = options.signal === undefined ? timeout : AbortSignal.any([timeout, options.signal]);
|
|
43
|
-
const env = {
|
|
44
|
-
...process.env,
|
|
45
|
-
LC_ALL: 'C',
|
|
46
|
-
LANG: 'C',
|
|
47
|
-
GIT_TERMINAL_PROMPT: '0',
|
|
48
|
-
GIT_OPTIONAL_LOCKS: '0',
|
|
49
|
-
GIT_PAGER: 'cat',
|
|
50
|
-
PAGER: 'cat',
|
|
51
|
-
};
|
|
52
|
-
let handle;
|
|
53
|
-
try {
|
|
54
|
-
handle = subprocess.spawn({
|
|
55
|
-
argv: [executable, ...args],
|
|
56
|
-
cwd,
|
|
57
|
-
stdio: {
|
|
58
|
-
stdin: options.input === undefined ? 'ignore' : { data: options.input },
|
|
59
|
-
stdout: { maxBytes: 64 * 1024 * 1024, spill: { maxBytes: 128 * 1024 * 1024 } },
|
|
60
|
-
stderr: { maxBytes: 8 * 1024 * 1024 },
|
|
61
|
-
},
|
|
62
|
-
graceMs: 2000,
|
|
63
|
-
signal,
|
|
64
|
-
env,
|
|
65
|
-
});
|
|
66
|
-
} catch (error) {
|
|
67
|
-
if (signal.aborted) throw new GitError('git/cancelled', 'The Git command was cancelled.', { args });
|
|
68
|
-
throw new GitError('git/spawn-failed', 'Git could not start.', {
|
|
69
|
-
args,
|
|
70
|
-
cause: error instanceof Error ? error.message : String(error),
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let outcome;
|
|
75
|
-
try {
|
|
76
|
-
outcome = await handle.done;
|
|
77
|
-
} catch (error) {
|
|
78
|
-
if (timeout.aborted) {
|
|
79
|
-
throw new GitError('git/timeout', `Git did not finish within ${Math.round(timeoutMs / 1000)} seconds.`, {
|
|
80
|
-
args,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
if (options.signal?.aborted) throw new GitError('git/cancelled', 'The Git command was cancelled.', { args });
|
|
84
|
-
throw new GitError('git/failed', 'Git failed to run.', {
|
|
85
|
-
args,
|
|
86
|
-
cause: error instanceof Error ? error.message : String(error),
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const stdout = handle.collected.stdout?.readFrom(0);
|
|
91
|
-
const stderr = handle.collected.stderr?.readFrom(0);
|
|
92
|
-
if (stdout?.lossy) {
|
|
93
|
-
throw new GitError('git/output-too-large', 'Git returned more output than the panel can read.', {
|
|
94
|
-
args,
|
|
95
|
-
spillPath: stdout.spillPath,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
code: outcome.exitCode ?? (outcome.signal === null ? 0 : 1),
|
|
100
|
-
stdout: stdout?.text ?? '',
|
|
101
|
-
stderr: stderr?.text ?? '',
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async function readText(path) {
|
|
106
|
-
try {
|
|
107
|
-
const bytes = await readFile(path);
|
|
108
|
-
const text = bytes.toString('utf8');
|
|
109
|
-
return {
|
|
110
|
-
text,
|
|
111
|
-
binary: bytes.includes(0) || !Buffer.from(text, 'utf8').equals(bytes),
|
|
112
|
-
size: bytes.length,
|
|
113
|
-
};
|
|
114
|
-
} catch (error) {
|
|
115
|
-
if (error && (error.code === 'ENOENT' || error.code === 'EISDIR' || error.code === 'ENOTDIR')) return null;
|
|
116
|
-
throw new GitError('git/read-failed', `Could not read ${path}.`, {
|
|
117
|
-
path,
|
|
118
|
-
cause: error instanceof Error ? error.message : String(error),
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async function readBuffer(path) {
|
|
124
|
-
try {
|
|
125
|
-
return await readFile(path);
|
|
126
|
-
} catch (error) {
|
|
127
|
-
if (error && (error.code === 'ENOENT' || error.code === 'EISDIR' || error.code === 'ENOTDIR')) return null;
|
|
128
|
-
throw new GitError('git/read-failed', `Could not read ${path}.`, {
|
|
129
|
-
path,
|
|
130
|
-
cause: error instanceof Error ? error.message : String(error),
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async function writeText(path, text) {
|
|
136
|
-
await writeFile(path, text, 'utf8');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async function statPath(path) {
|
|
140
|
-
try {
|
|
141
|
-
return await stat(path);
|
|
142
|
-
} catch {
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async function lstatPath(path) {
|
|
148
|
-
try {
|
|
149
|
-
return await lstat(path);
|
|
150
|
-
} catch {
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
async function readdirPath(path) {
|
|
156
|
-
try {
|
|
157
|
-
return await readdir(path, { withFileTypes: true });
|
|
158
|
-
} catch {
|
|
159
|
-
return [];
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
async function realpathPath(path) {
|
|
164
|
-
return realpath(path);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return { run, readText, readBuffer, writeText, statPath, lstatPath, readdir: readdirPath, realpath: realpathPath };
|
|
168
|
-
}
|