**Motivations:** - Clone or load repos under /home/ncantu/code with AnythingLLM workspace ensure/create from the editor **Root causes:** - N/A (new capability) **Correctifs:** - N/A **Evolutions:** - services/repos-devtools-server: POST /repos-clone, GET /repos-list, POST /repos-load (Bearer REPOS_DEVTOOLS_TOKEN) - Extension: Webview panel, slash commands, workspaceEnsure + POST /api/v1/workspace/new - Docs: feature note and index links **Pages affectées:** - services/repos-devtools-server/* - extensions/anythingllm-workspaces/* - docs/README.md - docs/features/repos-devtools-server-and-dev-panel.md - docs/features/anythingllm-vscode-extension.md
35 lines
867 B
TypeScript
35 lines
867 B
TypeScript
import { spawn } from "node:child_process";
|
|
|
|
export interface GitSpawnResult {
|
|
readonly code: number;
|
|
readonly stdout: string;
|
|
readonly stderr: string;
|
|
}
|
|
|
|
export const runGit = (args: readonly string[], cwd: string): Promise<GitSpawnResult> => {
|
|
return new Promise((resolve, reject) => {
|
|
const child = spawn("git", [...args], {
|
|
cwd,
|
|
env: process.env,
|
|
});
|
|
const out: Buffer[] = [];
|
|
const err: Buffer[] = [];
|
|
child.stdout.on("data", (chunk: Buffer) => {
|
|
out.push(chunk);
|
|
});
|
|
child.stderr.on("data", (chunk: Buffer) => {
|
|
err.push(chunk);
|
|
});
|
|
child.on("error", (e) => {
|
|
reject(e);
|
|
});
|
|
child.on("close", (code) => {
|
|
resolve({
|
|
code: code ?? 1,
|
|
stdout: Buffer.concat(out).toString("utf8"),
|
|
stderr: Buffer.concat(err).toString("utf8"),
|
|
});
|
|
});
|
|
});
|
|
};
|