@volter/browser-toolbelt 0.1.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.
Files changed (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -0
  3. package/dist/browser-git-filesystem.d.ts +18 -0
  4. package/dist/browser-git-filesystem.d.ts.map +1 -0
  5. package/dist/browser-git-filesystem.js +84 -0
  6. package/dist/browser-git-filesystem.js.map +1 -0
  7. package/dist/browser-git-http.d.ts +32 -0
  8. package/dist/browser-git-http.d.ts.map +1 -0
  9. package/dist/browser-git-http.js +127 -0
  10. package/dist/browser-git-http.js.map +1 -0
  11. package/dist/browser-git.d.ts +38 -0
  12. package/dist/browser-git.d.ts.map +1 -0
  13. package/dist/browser-git.js +514 -0
  14. package/dist/browser-git.js.map +1 -0
  15. package/dist/browser-share-command.d.ts +11 -0
  16. package/dist/browser-share-command.d.ts.map +1 -0
  17. package/dist/browser-share-command.js +59 -0
  18. package/dist/browser-share-command.js.map +1 -0
  19. package/dist/browser-shell-filesystem.d.ts +39 -0
  20. package/dist/browser-shell-filesystem.d.ts.map +1 -0
  21. package/dist/browser-shell-filesystem.js +138 -0
  22. package/dist/browser-shell-filesystem.js.map +1 -0
  23. package/dist/browser-shell.d.ts +38 -0
  24. package/dist/browser-shell.d.ts.map +1 -0
  25. package/dist/browser-shell.js +412 -0
  26. package/dist/browser-shell.js.map +1 -0
  27. package/dist/github-device-auth.d.ts +56 -0
  28. package/dist/github-device-auth.d.ts.map +1 -0
  29. package/dist/github-device-auth.js +157 -0
  30. package/dist/github-device-auth.js.map +1 -0
  31. package/dist/index.d.ts +8 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +8 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/install.d.ts +17 -0
  36. package/dist/install.d.ts.map +1 -0
  37. package/dist/install.js +21 -0
  38. package/dist/install.js.map +1 -0
  39. package/package.json +27 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Volter Browser Substrate contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # `@volter/browser-toolbelt`
2
+
3
+ Optional developer commands for Browser Substrate: an AST shell, Git,
4
+ GitHub-device authentication, and project sharing. `installBrowserToolbelt`
5
+ registers them with an existing `BrowserRuntime`.
6
+
7
+ The package is deliberately separate from the kernel and execution engines. A
8
+ consumer can replace or omit these commands without changing workspace,
9
+ process, port, or preview behavior.
@@ -0,0 +1,18 @@
1
+ import type { BrowserFileSystem } from "@volter/browser-runtime/browser-filesystem.js";
2
+ import type { FsClient } from "isomorphic-git";
3
+ /** Promise-style Node fs subset backed directly by the shared browser VFS. */
4
+ export declare class BrowserGitFileSystem {
5
+ private readonly filesystem;
6
+ readonly client: FsClient;
7
+ constructor(filesystem: BrowserFileSystem);
8
+ private readFile;
9
+ private writeFile;
10
+ private unlink;
11
+ private readdir;
12
+ private mkdir;
13
+ private rmdir;
14
+ private stat;
15
+ private chmod;
16
+ private unsupportedLink;
17
+ }
18
+ //# sourceMappingURL=browser-git-filesystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-git-filesystem.d.ts","sourceRoot":"","sources":["../src/browser-git-filesystem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAK/C,8EAA8E;AAC9E,qBAAa,oBAAoB;IAGnB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFvC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;gBAEG,UAAU,EAAE,iBAAiB;YAkB5C,QAAQ;YAcR,SAAS;YAUT,MAAM;YACN,OAAO;YACP,KAAK;YACL,KAAK;YAEL,IAAI;YAIJ,KAAK;YAKL,eAAe;CAG9B"}
@@ -0,0 +1,84 @@
1
+ /** Promise-style Node fs subset backed directly by the shared browser VFS. */
2
+ export class BrowserGitFileSystem {
3
+ filesystem;
4
+ client;
5
+ constructor(filesystem) {
6
+ this.filesystem = filesystem;
7
+ this.client = {
8
+ promises: {
9
+ readFile: (path, options) => this.readFile(path, options),
10
+ writeFile: (path, data) => this.writeFile(path, data),
11
+ unlink: (path) => this.unlink(path),
12
+ readdir: (path) => this.readdir(path),
13
+ mkdir: (path) => this.mkdir(path),
14
+ rmdir: (path) => this.rmdir(path),
15
+ stat: (path) => this.stat(path),
16
+ lstat: (path) => this.stat(path),
17
+ readlink: (path) => this.unsupportedLink("readlink", path),
18
+ symlink: (_target, path) => this.unsupportedLink("symlink", path),
19
+ chmod: (path, mode) => this.chmod(path, mode),
20
+ },
21
+ };
22
+ }
23
+ async readFile(path, options) {
24
+ const bytes = this.filesystem.readFileSync(path);
25
+ const encoding = typeof options === "string" ? options : options?.encoding;
26
+ if (!encoding || encoding === "buffer")
27
+ return bytes;
28
+ if (encoding === "latin1" || encoding === "binary") {
29
+ let value = "";
30
+ for (let offset = 0; offset < bytes.byteLength; offset += 0x8000) {
31
+ value += String.fromCharCode(...bytes.subarray(offset, offset + 0x8000));
32
+ }
33
+ return value;
34
+ }
35
+ return new TextDecoder().decode(bytes);
36
+ }
37
+ async writeFile(path, data) {
38
+ const parent = dirname(path);
39
+ this.filesystem.mkdirSync(parent, { recursive: true });
40
+ if (typeof data === "string" || data instanceof Uint8Array) {
41
+ this.filesystem.writeFileSync(path, data);
42
+ return;
43
+ }
44
+ this.filesystem.writeFileSync(path, new Uint8Array(data.buffer, data.byteOffset, data.byteLength));
45
+ }
46
+ async unlink(path) { this.filesystem.unlinkSync(path); }
47
+ async readdir(path) { return this.filesystem.readdirSync(path); }
48
+ async mkdir(path) { this.filesystem.mkdirSync(path, { recursive: true }); }
49
+ async rmdir(path) { this.filesystem.rmdirSync(path); }
50
+ async stat(path) {
51
+ return gitStat(this.filesystem.statSync(path));
52
+ }
53
+ async chmod(path, mode) {
54
+ this.filesystem.statSync(path);
55
+ this.filesystem.chmodSync(path, mode);
56
+ }
57
+ async unsupportedLink(operation, path) {
58
+ throw Object.assign(new Error(`ENOSYS: ${operation} '${path}'`), { code: "ENOSYS", path });
59
+ }
60
+ }
61
+ function dirname(path) {
62
+ const normalized = path.replace(/\/+$/u, "");
63
+ const index = normalized.lastIndexOf("/");
64
+ return index <= 0 ? "/" : normalized.slice(0, index);
65
+ }
66
+ function gitStat(value) {
67
+ const mtimeMs = value.mtimeMs ?? Date.now();
68
+ return {
69
+ isFile: () => value.isFile(),
70
+ isDirectory: () => value.isDirectory(),
71
+ isSymbolicLink: () => false,
72
+ mode: value.mode ?? (value.isDirectory() ? 0o755 : 0o644),
73
+ size: value.size,
74
+ mtime: new Date(mtimeMs),
75
+ mtimeMs,
76
+ ctime: new Date(mtimeMs),
77
+ ctimeMs: mtimeMs,
78
+ uid: 1000,
79
+ gid: 1000,
80
+ ino: 0,
81
+ dev: 0,
82
+ };
83
+ }
84
+ //# sourceMappingURL=browser-git-filesystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-git-filesystem.js","sourceRoot":"","sources":["../src/browser-git-filesystem.ts"],"names":[],"mappings":"AAMA,8EAA8E;AAC9E,MAAM,OAAO,oBAAoB;IAGF;IAFpB,MAAM,CAAW;IAE1B,YAA6B,UAA6B;QAA7B,eAAU,GAAV,UAAU,CAAmB;QACxD,IAAI,CAAC,MAAM,GAAG;YACZ,QAAQ,EAAE;gBACR,QAAQ,EAAE,CAAC,IAAY,EAAE,OAAwB,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBAClF,SAAS,EAAE,CAAC,IAAY,EAAE,IAA2C,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC;gBACpG,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;gBAC3C,OAAO,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBAC7C,KAAK,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACzC,KAAK,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACzC,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;gBACvC,KAAK,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;gBACxC,QAAQ,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC;gBAClE,OAAO,EAAE,CAAC,OAAe,EAAE,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC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,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7F,CAAC;CACF;AAED,SAAS,OAAO,CAAC,IAAY;IAC3B,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,OAAO,CAAC,KAAgD;IAC/D,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IAC5C,OAAO;QACL,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE;QAC5B,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE;QACtC,cAAc,EAAE,GAAG,EAAE,CAAC,KAAK;QAC3B,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QACzD,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC;QACxB,OAAO;QACP,KAAK,EAAE,IAAI,IAAI,CAAC,OAAO,CAAC;QACxB,OAAO,EAAE,OAAO;QAChB,GAAG,EAAE,IAAI;QACT,GAAG,EAAE,IAAI;QACT,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;KACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { HttpClient } from "isomorphic-git";
2
+ export type GitAuthorizationProvider = () => Promise<string | undefined> | string | undefined;
3
+ export interface BrowserGitHttpOptions {
4
+ /**
5
+ * Git proxy endpoint accepting one encoded `url` query parameter: an
6
+ * absolute URL on the relay service, or a same-origin absolute path when the
7
+ * embedding page proxies the route itself. Defaults to `/api/git`.
8
+ */
9
+ proxyUrl?: string;
10
+ /** Exact HTTPS Git hosts the browser may ask that proxy to reach. */
11
+ allowedHosts?: readonly string[];
12
+ /**
13
+ * Supplies the `Authorization` header value for each request (for GitHub, a
14
+ * Basic credential built from a device-flow token). The proxy forwards it
15
+ * upstream unchanged and never holds it.
16
+ */
17
+ authorization?: GitAuthorizationProvider;
18
+ fetch?: typeof globalThis.fetch;
19
+ }
20
+ /** Smart-HTTP client over the relay service's Git proxy; the proxy owns the vendor allowlist. */
21
+ export declare class BrowserGitHttp {
22
+ readonly client: HttpClient;
23
+ private readonly allowedHosts;
24
+ private readonly proxyUrl;
25
+ private readonly authorization;
26
+ private readonly fetch;
27
+ constructor(options?: BrowserGitHttpOptions);
28
+ private request;
29
+ }
30
+ /** An absolute http(s) URL or a same-origin absolute path, without query or fragment. */
31
+ export declare function normalizeProxyUrl(value: string): string;
32
+ //# sourceMappingURL=browser-git-http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-git-http.d.ts","sourceRoot":"","sources":["../src/browser-git-http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmC,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAKlF,MAAM,MAAM,wBAAwB,GAAG,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAAC;AAE9F,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC;;;;OAIG;IACH,aAAa,CAAC,EAAE,wBAAwB,CAAC;IACzC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CACjC;AAED,iGAAiG;AACjG,qBAAa,cAAc;IACzB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAmD;IAC9E,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAuC;IACrE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA0B;gBAEpC,OAAO,GAAE,qBAA0B;YAUjC,OAAO;CAuCtB;AAED,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAavD"}
@@ -0,0 +1,127 @@
1
+ const MAXIMUM_BODY_BYTES = 32 * 1024 * 1024;
2
+ const FORWARDED_HEADERS = ["Accept", "Content-Type", "Git-Protocol"];
3
+ /** Smart-HTTP client over the relay service's Git proxy; the proxy owns the vendor allowlist. */
4
+ export class BrowserGitHttp {
5
+ client = { request: (request) => this.request(request) };
6
+ allowedHosts;
7
+ proxyUrl;
8
+ authorization;
9
+ fetch;
10
+ constructor(options = {}) {
11
+ this.allowedHosts = new Set(options.allowedHosts ?? ["github.com"]);
12
+ if (this.allowedHosts.size === 0 || [...this.allowedHosts].some((host) => !validHostname(host))) {
13
+ throw new Error("Browser Git requires at least one exact valid HTTPS hostname.");
14
+ }
15
+ this.proxyUrl = normalizeProxyUrl(options.proxyUrl ?? "/api/git");
16
+ this.authorization = options.authorization;
17
+ this.fetch = options.fetch ?? globalThis.fetch.bind(globalThis);
18
+ }
19
+ async request(request) {
20
+ const target = new URL(request.url);
21
+ if (target.protocol !== "https:" || !this.allowedHosts.has(target.hostname) || target.port) {
22
+ throw new Error("Browser Git target is not on the embedding's exact HTTPS host allowlist.");
23
+ }
24
+ const method = request.method ?? "GET";
25
+ const body = request.body ? await collect(request.body, MAXIMUM_BODY_BYTES) : undefined;
26
+ const proxied = `${this.proxyUrl}?url=${encodeURIComponent(target.href)}`;
27
+ const headers = {};
28
+ for (const name of FORWARDED_HEADERS) {
29
+ const value = request.headers?.[name] ?? request.headers?.[name.toLowerCase()];
30
+ if (value)
31
+ headers[name] = value;
32
+ }
33
+ const authorization = await this.authorization?.();
34
+ if (authorization)
35
+ headers.Authorization = authorization;
36
+ const response = await this.fetch(proxied, {
37
+ method,
38
+ headers,
39
+ body: body ? new Blob([Uint8Array.from(body)]) : null,
40
+ mode: "cors",
41
+ credentials: "omit",
42
+ redirect: "error",
43
+ });
44
+ const length = Number(response.headers.get("Content-Length"));
45
+ if (Number.isFinite(length) && length > MAXIMUM_BODY_BYTES) {
46
+ await response.body?.cancel();
47
+ throw new Error("Git smart-HTTP response exceeded the browser byte limit.");
48
+ }
49
+ const responseHeaders = {};
50
+ response.headers.forEach((value, key) => { responseHeaders[key] = value; });
51
+ return {
52
+ url: target.href,
53
+ method,
54
+ statusCode: response.status,
55
+ statusMessage: response.statusText,
56
+ headers: responseHeaders,
57
+ ...(response.body ? { body: boundedIterator(response.body, MAXIMUM_BODY_BYTES) } : {}),
58
+ };
59
+ }
60
+ }
61
+ /** An absolute http(s) URL or a same-origin absolute path, without query or fragment. */
62
+ export function normalizeProxyUrl(value) {
63
+ if (/[?#]/u.test(value))
64
+ throw new Error("Git proxyUrl must not carry a query or fragment.");
65
+ if (value.startsWith("/")) {
66
+ if (value.startsWith("//"))
67
+ throw new Error("Git proxyUrl path must be same-origin.");
68
+ return value;
69
+ }
70
+ let url;
71
+ try {
72
+ url = new URL(value);
73
+ }
74
+ catch {
75
+ throw new Error("Git proxyUrl must be an absolute URL or a same-origin absolute path.");
76
+ }
77
+ if ((url.protocol !== "https:" && url.protocol !== "http:") || url.username || url.password) {
78
+ throw new Error("Git proxyUrl must be an HTTP(S) URL without credentials.");
79
+ }
80
+ return url.href;
81
+ }
82
+ function validHostname(hostname) {
83
+ return hostname === hostname.toLowerCase()
84
+ && hostname.length <= 253
85
+ && !hostname.endsWith(".")
86
+ && hostname.split(".").every((label) => /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/u.test(label));
87
+ }
88
+ async function collect(body, maximum) {
89
+ const chunks = [];
90
+ let total = 0;
91
+ for await (const chunk of body) {
92
+ total += chunk.byteLength;
93
+ if (total > maximum)
94
+ throw new Error("Git smart-HTTP request exceeded the browser byte limit.");
95
+ chunks.push(chunk);
96
+ }
97
+ const output = new Uint8Array(total);
98
+ let offset = 0;
99
+ for (const chunk of chunks) {
100
+ output.set(chunk, offset);
101
+ offset += chunk.byteLength;
102
+ }
103
+ return output;
104
+ }
105
+ function boundedIterator(stream, maximum) {
106
+ const reader = stream.getReader();
107
+ let total = 0;
108
+ return {
109
+ async next() {
110
+ const result = await reader.read();
111
+ if (result.done)
112
+ return { done: true, value: undefined };
113
+ total += result.value.byteLength;
114
+ if (total > maximum) {
115
+ await reader.cancel("Git smart-HTTP response exceeded the browser byte limit.");
116
+ throw new Error("Git smart-HTTP response exceeded the browser byte limit.");
117
+ }
118
+ return { done: false, value: result.value };
119
+ },
120
+ async return() {
121
+ await reader.cancel();
122
+ return { done: true, value: undefined };
123
+ },
124
+ [Symbol.asyncIterator]() { return this; },
125
+ };
126
+ }
127
+ //# sourceMappingURL=browser-git-http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-git-http.js","sourceRoot":"","sources":["../src/browser-git-http.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAC5C,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,cAAc,EAAE,cAAc,CAAU,CAAC;AAsB9E,iGAAiG;AACjG,MAAM,OAAO,cAAc;IAChB,MAAM,GAAe,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;IAC7D,YAAY,CAAsB;IAClC,QAAQ,CAAS;IACjB,aAAa,CAAuC;IACpD,KAAK,CAA0B;IAEhD,YAAY,UAAiC,EAAE;QAC7C,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,YAAY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IAAI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;YACjC,IAAI,KAAK,GAAG,OAAO,EAAE,CAAC;gBACpB,MAAM,MAAM,CAAC,MAAM,CAAC,0DAA0D,CAAC,CAAC;gBAChF,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;YAC9E,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;QAC9C,CAAC;QACD,KAAK,CAAC,MAAM;YACV,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;YACtB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;QAC1C,CAAC;QACD,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;KAC1C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { BrowserFileSystem } from "@volter/browser-runtime/browser-filesystem.js";
2
+ import type { HttpClient } from "isomorphic-git";
3
+ import type { BrowserShellProgramRunner } from "./browser-shell.js";
4
+ export interface BrowserGitOptions {
5
+ /** Supply an embedding-owned smart-HTTP transport instead of the default edge client. */
6
+ http?: HttpClient;
7
+ }
8
+ /** Local Git CLI surface operating entirely on the shared browser VFS. */
9
+ export declare class BrowserGit {
10
+ private readonly filesystem;
11
+ readonly run: BrowserShellProgramRunner;
12
+ private readonly fs;
13
+ private readonly http;
14
+ constructor(filesystem: BrowserFileSystem, options?: BrowserGitOptions);
15
+ private execute;
16
+ private initialize;
17
+ private clone;
18
+ private status;
19
+ private add;
20
+ private remove;
21
+ private commit;
22
+ private config;
23
+ private log;
24
+ private branch;
25
+ private checkout;
26
+ private diff;
27
+ private entryContent;
28
+ private revParse;
29
+ private lsFiles;
30
+ private remote;
31
+ private fetch;
32
+ private pull;
33
+ private push;
34
+ private remoteUrl;
35
+ private repositoryRoot;
36
+ private removeTree;
37
+ }
38
+ //# sourceMappingURL=browser-git.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-git.d.ts","sourceRoot":"","sources":["../src/browser-git.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,KAAK,EAAE,UAAU,EAAe,MAAM,gBAAgB,CAAC;AAG9D,OAAO,KAAK,EACV,yBAAyB,EAG1B,MAAM,oBAAoB,CAAC;AAW5B,MAAM,WAAW,iBAAiB;IAChC,yFAAyF;IACzF,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,0EAA0E;AAC1E,qBAAa,UAAU;IAKT,OAAO,CAAC,QAAQ,CAAC,UAAU;IAJvC,QAAQ,CAAC,GAAG,EAAE,yBAAyB,CAAC;IACxC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;gBAEL,UAAU,EAAE,iBAAiB,EAAE,OAAO,GAAE,iBAAsB;YAM7E,OAAO;YAsCP,UAAU;YAeV,KAAK;YA0BL,MAAM;YAaN,GAAG;YAeH,MAAM;YAYN,MAAM;YAwBN,MAAM;YAYN,GAAG;YAeH,MAAM;YAeN,QAAQ;YASR,IAAI;YA8CJ,YAAY;YAQZ,QAAQ;YASR,OAAO;YAKP,MAAM;YA8BN,KAAK;YAkBL,IAAI;YAkBJ,IAAI;YA2BJ,SAAS;IAIvB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,UAAU;CAMnB"}