@aigne/afs-git 1.11.0-beta → 1.11.0-beta.1

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/LICENSE.md CHANGED
@@ -1,93 +1,26 @@
1
- Elastic License 2.0
1
+ # Proprietary License
2
2
 
3
- URL: https://www.elastic.co/licensing/elastic-license
3
+ Copyright (c) 2024-2025 ArcBlock, Inc. All Rights Reserved.
4
4
 
5
- ## Acceptance
5
+ This software and associated documentation files (the "Software") are proprietary
6
+ and confidential. Unauthorized copying, modification, distribution, or use of
7
+ this Software, via any medium, is strictly prohibited.
6
8
 
7
- By using the software, you agree to all of the terms and conditions below.
9
+ The Software is provided for internal use only within ArcBlock, Inc. and its
10
+ authorized affiliates.
8
11
 
9
- ## Copyright License
12
+ ## No License Granted
10
13
 
11
- The licensor grants you a non-exclusive, royalty-free, worldwide,
12
- non-sublicensable, non-transferable license to use, copy, distribute, make
13
- available, and prepare derivative works of the software, in each case subject to
14
- the limitations and conditions below.
14
+ No license, express or implied, is granted to any party for any purpose.
15
+ All rights are reserved by ArcBlock, Inc.
15
16
 
16
- ## Limitations
17
+ ## Public Artifact Distribution
17
18
 
18
- You may not provide the software to third parties as a hosted or managed
19
- service, where the service provides users with access to any substantial set of
20
- the features or functionality of the software.
19
+ Portions of this Software may be released publicly under separate open-source
20
+ licenses (such as MIT License) through designated public repositories. Such
21
+ public releases are governed by their respective licenses and do not affect
22
+ the proprietary nature of this repository.
21
23
 
22
- You may not move, change, disable, or circumvent the license key functionality
23
- in the software, and you may not remove or obscure any functionality in the
24
- software that is protected by the license key.
24
+ ## Contact
25
25
 
26
- You may not alter, remove, or obscure any licensing, copyright, or other notices
27
- of the licensor in the software. Any use of the licensor’s trademarks is subject
28
- to applicable law.
29
-
30
- ## Patents
31
-
32
- The licensor grants you a license, under any patent claims the licensor can
33
- license, or becomes able to license, to make, have made, use, sell, offer for
34
- sale, import and have imported the software, in each case subject to the
35
- limitations and conditions in this license. This license does not cover any
36
- patent claims that you cause to be infringed by modifications or additions to
37
- the software. If you or your company make any written claim that the software
38
- infringes or contributes to infringement of any patent, your patent license for
39
- the software granted under these terms ends immediately. If your company makes
40
- such a claim, your patent license ends immediately for work on behalf of your
41
- company.
42
-
43
- ## Notices
44
-
45
- You must ensure that anyone who gets a copy of any part of the software from you
46
- also gets a copy of these terms.
47
-
48
- If you modify the software, you must include in any modified copies of the
49
- software prominent notices stating that you have modified the software.
50
-
51
- ## No Other Rights
52
-
53
- These terms do not imply any licenses other than those expressly granted in
54
- these terms.
55
-
56
- ## Termination
57
-
58
- If you use the software in violation of these terms, such use is not licensed,
59
- and your licenses will automatically terminate. If the licensor provides you
60
- with a notice of your violation, and you cease all violation of this license no
61
- later than 30 days after you receive that notice, your licenses will be
62
- reinstated retroactively. However, if you violate these terms after such
63
- reinstatement, any additional violation of these terms will cause your licenses
64
- to terminate automatically and permanently.
65
-
66
- ## No Liability
67
-
68
- *As far as the law allows, the software comes as is, without any warranty or
69
- condition, and the licensor will not be liable to you for any damages arising
70
- out of these terms or the use or nature of the software, under any kind of
71
- legal claim.*
72
-
73
- ## Definitions
74
-
75
- The **licensor** is the entity offering these terms, and the **software** is the
76
- software the licensor makes available under these terms, including any portion
77
- of it.
78
-
79
- **you** refers to the individual or entity agreeing to these terms.
80
-
81
- **your company** is any legal entity, sole proprietorship, or other kind of
82
- organization that you work for, plus all organizations that have control over,
83
- are under the control of, or are under common control with that
84
- organization. **control** means ownership of substantially all the assets of an
85
- entity, or the power to direct its management and policies by vote, contract, or
86
- otherwise. Control can be direct or indirect.
87
-
88
- **your licenses** are all the licenses granted to you for the software under
89
- these terms.
90
-
91
- **use** means anything you do with the software requiring one of your licenses.
92
-
93
- **trademark** means trademarks, service marks, and similar rights.
26
+ For licensing inquiries, contact: legal@arcblock.io
package/README.md CHANGED
@@ -226,7 +226,3 @@ await aigne.invoke(agent, {
226
226
  message: "Review the authentication code in src/auth/",
227
227
  });
228
228
  ```
229
-
230
- ## License
231
-
232
- This project is licensed under the [Elastic-2.0](../../LICENSE.md) License.
package/dist/index.cjs CHANGED
@@ -9,11 +9,12 @@ let simple_git = require("simple-git");
9
9
  let zod = require("zod");
10
10
 
11
11
  //#region src/index.ts
12
- const execFileAsync = (0, node_util.promisify)(node_child_process.execFile);
13
12
  const LIST_MAX_LIMIT = 1e3;
13
+ const execFileAsync = (0, node_util.promisify)(node_child_process.execFile);
14
14
  const afsGitOptionsSchema = (0, _aigne_afs_utils_zod.camelize)(zod.z.object({
15
15
  name: (0, _aigne_afs_utils_zod.optionalize)(zod.z.string()),
16
- repoPath: zod.z.string().describe("The path to the git repository"),
16
+ repoPath: (0, _aigne_afs_utils_zod.optionalize)(zod.z.string().describe("The path to the git repository")),
17
+ remoteUrl: (0, _aigne_afs_utils_zod.optionalize)(zod.z.string().describe("Remote repository URL (https or git protocol)")),
17
18
  description: (0, _aigne_afs_utils_zod.optionalize)(zod.z.string().describe("A description of the repository")),
18
19
  branches: (0, _aigne_afs_utils_zod.optionalize)(zod.z.array(zod.z.string()).describe("List of branches to expose")),
19
20
  accessMode: (0, _aigne_afs_utils_zod.optionalize)(zod.z.enum(["readonly", "readwrite"]).describe("Access mode for this module")),
@@ -21,35 +22,107 @@ const afsGitOptionsSchema = (0, _aigne_afs_utils_zod.camelize)(zod.z.object({
21
22
  commitAuthor: (0, _aigne_afs_utils_zod.optionalize)(zod.z.object({
22
23
  name: zod.z.string(),
23
24
  email: zod.z.string()
24
- }))
25
- }));
25
+ })),
26
+ depth: (0, _aigne_afs_utils_zod.optionalize)(zod.z.number().describe("Clone depth for shallow clone")),
27
+ autoCleanup: (0, _aigne_afs_utils_zod.optionalize)(zod.z.boolean().describe("Automatically clean up cloned repository on cleanup()")),
28
+ cloneOptions: (0, _aigne_afs_utils_zod.optionalize)(zod.z.object({ auth: (0, _aigne_afs_utils_zod.optionalize)(zod.z.object({
29
+ username: (0, _aigne_afs_utils_zod.optionalize)(zod.z.string()),
30
+ password: (0, _aigne_afs_utils_zod.optionalize)(zod.z.string())
31
+ })) }))
32
+ }).refine((data) => data.repoPath || data.remoteUrl, { message: "Either repoPath or remoteUrl must be provided" }));
26
33
  var AFSGit = class AFSGit {
27
34
  static schema() {
28
35
  return afsGitOptionsSchema;
29
36
  }
30
37
  static async load({ filepath, parsed }) {
31
- return new AFSGit({
38
+ const instance = new AFSGit({
32
39
  ...await AFSGit.schema().parseAsync(parsed),
33
40
  cwd: (0, node_path.dirname)(filepath)
34
41
  });
42
+ await instance.ready();
43
+ return instance;
35
44
  }
45
+ initPromise;
36
46
  git;
37
47
  tempBase;
38
48
  worktrees = /* @__PURE__ */ new Map();
39
49
  repoHash;
50
+ isAutoCloned = false;
51
+ clonedPath;
52
+ repoPath;
40
53
  constructor(options) {
41
54
  this.options = options;
42
55
  (0, _aigne_afs_utils_zod.zodParse)(afsGitOptionsSchema, options);
43
56
  let repoPath;
44
- if ((0, node_path.isAbsolute)(options.repoPath)) repoPath = options.repoPath;
45
- else repoPath = (0, node_path.join)(options.cwd || process.cwd(), options.repoPath);
46
- this.options.repoPath = repoPath;
47
- this.name = options.name || (0, node_path.basename)(repoPath) || "git";
57
+ let repoName;
58
+ if (options.repoPath) {
59
+ repoPath = (0, node_path.isAbsolute)(options.repoPath) ? options.repoPath : (0, node_path.join)(options.cwd || process.cwd(), options.repoPath);
60
+ repoName = (0, node_path.basename)(repoPath);
61
+ } else if (options.remoteUrl) {
62
+ const urlParts = options.remoteUrl.split("/");
63
+ repoName = urlParts[urlParts.length - 1]?.replace(/\.git$/, "") || "git";
64
+ const repoHash = (0, node_crypto.createHash)("md5").update(options.remoteUrl).digest("hex").substring(0, 8);
65
+ repoPath = (0, node_path.join)((0, node_os.tmpdir)(), `afs-git-remote-${repoHash}`);
66
+ } else throw new Error("Either repoPath or remoteUrl must be provided");
67
+ this.repoPath = repoPath;
68
+ this.name = options.name || repoName;
48
69
  this.description = options.description;
49
70
  this.accessMode = options.accessMode ?? "readonly";
50
- this.git = (0, simple_git.simpleGit)(repoPath);
51
71
  this.repoHash = (0, node_crypto.createHash)("md5").update(repoPath).digest("hex").substring(0, 8);
52
72
  this.tempBase = (0, node_path.join)((0, node_os.tmpdir)(), `afs-git-${this.repoHash}`);
73
+ this.git = null;
74
+ this.initPromise = this.initialize();
75
+ }
76
+ /**
77
+ * Wait for async initialization to complete
78
+ */
79
+ async ready() {
80
+ await this.initPromise;
81
+ }
82
+ /**
83
+ * Async initialization logic (runs in constructor)
84
+ * Handles cloning remote repositories if needed
85
+ */
86
+ async initialize() {
87
+ const options = this.options;
88
+ if (options.remoteUrl) {
89
+ const targetPath = options.repoPath ? (0, node_path.isAbsolute)(options.repoPath) ? options.repoPath : (0, node_path.join)(options.cwd || process.cwd(), options.repoPath) : this.repoPath;
90
+ if (!options.repoPath) this.isAutoCloned = true;
91
+ if (!await (0, node_fs_promises.stat)(targetPath).then(() => true).catch(() => false)) {
92
+ const singleBranch = options.branches?.length === 1 ? options.branches[0] : void 0;
93
+ await AFSGit.cloneRepository(options.remoteUrl, targetPath, {
94
+ depth: options.depth ?? 1,
95
+ branch: singleBranch,
96
+ auth: options.cloneOptions?.auth
97
+ });
98
+ }
99
+ if (targetPath !== this.repoPath) {
100
+ this.repoPath = targetPath;
101
+ this.repoHash = (0, node_crypto.createHash)("md5").update(targetPath).digest("hex").substring(0, 8);
102
+ this.tempBase = (0, node_path.join)((0, node_os.tmpdir)(), `afs-git-${this.repoHash}`);
103
+ }
104
+ this.clonedPath = this.isAutoCloned ? targetPath : void 0;
105
+ }
106
+ this.git = (0, simple_git.simpleGit)(this.repoPath);
107
+ }
108
+ /**
109
+ * Clone a remote repository to local path
110
+ */
111
+ static async cloneRepository(remoteUrl, targetPath, options = {}) {
112
+ const git = (0, simple_git.simpleGit)();
113
+ const cloneArgs = [];
114
+ if (options.depth) cloneArgs.push("--depth", options.depth.toString());
115
+ if (options.branch) cloneArgs.push("--branch", options.branch, "--single-branch");
116
+ let cloneUrl = remoteUrl;
117
+ if (options.auth?.username && options.auth?.password) {
118
+ if (remoteUrl.startsWith("https://")) {
119
+ const url = new URL(remoteUrl);
120
+ url.username = encodeURIComponent(options.auth.username);
121
+ url.password = encodeURIComponent(options.auth.password);
122
+ cloneUrl = url.toString();
123
+ }
124
+ }
125
+ await git.clone(cloneUrl, targetPath, cloneArgs);
53
126
  }
54
127
  name;
55
128
  description;
@@ -136,8 +209,8 @@ var AFSGit = class AFSGit {
136
209
  async ensureWorktree(branch) {
137
210
  if (this.worktrees.has(branch)) return this.worktrees.get(branch);
138
211
  if ((await this.git.revparse(["--abbrev-ref", "HEAD"])).trim() === branch) {
139
- this.worktrees.set(branch, this.options.repoPath);
140
- return this.options.repoPath;
212
+ this.worktrees.set(branch, this.repoPath);
213
+ return this.repoPath;
141
214
  }
142
215
  const worktreePath = (0, node_path.join)(this.tempBase, branch);
143
216
  if (!await (0, node_fs_promises.stat)(worktreePath).then(() => true).catch(() => false)) {
@@ -242,6 +315,7 @@ var AFSGit = class AFSGit {
242
315
  return `/${encodedBranch}/${filePath}`;
243
316
  }
244
317
  async list(path, options) {
318
+ await this.ready();
245
319
  const { branch, filePath } = this.parsePath(path);
246
320
  if (!branch) return { data: (await this.getBranches()).map((name) => {
247
321
  const encodedPath = this.buildPath(name);
@@ -254,6 +328,7 @@ var AFSGit = class AFSGit {
254
328
  return this.listWithGitLsTree(branch, filePath, options);
255
329
  }
256
330
  async read(path, _options) {
331
+ await this.ready();
257
332
  const { branch, filePath } = this.parsePath(path);
258
333
  if (!branch) return { data: {
259
334
  id: "/",
@@ -322,6 +397,7 @@ var AFSGit = class AFSGit {
322
397
  }
323
398
  }
324
399
  async write(path, entry, options) {
400
+ await this.ready();
325
401
  const { branch, filePath } = this.parsePath(path);
326
402
  if (!branch || !filePath) throw new Error("Cannot write to root or branch root");
327
403
  const worktreePath = await this.ensureWorktree(branch);
@@ -366,6 +442,7 @@ var AFSGit = class AFSGit {
366
442
  } };
367
443
  }
368
444
  async delete(path, options) {
445
+ await this.ready();
369
446
  const { branch, filePath } = this.parsePath(path);
370
447
  if (!branch || !filePath) throw new Error("Cannot delete root or branch root");
371
448
  const worktreePath = await this.ensureWorktree(branch);
@@ -388,6 +465,7 @@ var AFSGit = class AFSGit {
388
465
  return { message: `Successfully deleted: ${path}` };
389
466
  }
390
467
  async rename(oldPath, newPath, options) {
468
+ await this.ready();
391
469
  const { branch: oldBranch, filePath: oldFilePath } = this.parsePath(oldPath);
392
470
  const { branch: newBranch, filePath: newFilePath } = this.parsePath(newPath);
393
471
  if (!oldBranch || !oldFilePath) throw new Error("Cannot rename from root or branch root");
@@ -418,6 +496,7 @@ var AFSGit = class AFSGit {
418
496
  return { message: `Successfully renamed '${oldPath}' to '${newPath}'` };
419
497
  }
420
498
  async search(path, query, options) {
499
+ await this.ready();
421
500
  const { branch, filePath } = this.parsePath(path);
422
501
  if (!branch) return {
423
502
  data: [],
@@ -476,9 +555,32 @@ var AFSGit = class AFSGit {
476
555
  }
477
556
  }
478
557
  /**
558
+ * Fetch latest changes from remote
559
+ */
560
+ async fetch() {
561
+ await this.ready();
562
+ await this.git.fetch();
563
+ }
564
+ /**
565
+ * Pull latest changes from remote for current branch
566
+ */
567
+ async pull() {
568
+ await this.ready();
569
+ await this.git.pull();
570
+ }
571
+ /**
572
+ * Push local changes to remote
573
+ */
574
+ async push(branch) {
575
+ await this.ready();
576
+ if (branch) await this.git.push("origin", branch);
577
+ else await this.git.push();
578
+ }
579
+ /**
479
580
  * Cleanup all worktrees (useful when unmounting)
480
581
  */
481
582
  async cleanup() {
583
+ await this.ready();
482
584
  for (const [_branch, worktreePath] of this.worktrees) try {
483
585
  await this.git.raw([
484
586
  "worktree",
@@ -494,6 +596,13 @@ var AFSGit = class AFSGit {
494
596
  force: true
495
597
  });
496
598
  } catch {}
599
+ const autoCleanup = this.options.autoCleanup ?? true;
600
+ if (this.isAutoCloned && autoCleanup && this.clonedPath) try {
601
+ await (0, node_fs_promises.rm)(this.clonedPath, {
602
+ recursive: true,
603
+ force: true
604
+ });
605
+ } catch {}
497
606
  }
498
607
  };
499
608
 
package/dist/index.d.cts CHANGED
@@ -4,8 +4,28 @@ import { z } from "zod";
4
4
  //#region src/index.d.ts
5
5
  interface AFSGitOptions {
6
6
  name?: string;
7
- repoPath: string;
7
+ /**
8
+ * Local path to git repository.
9
+ * If remoteUrl is provided and repoPath doesn't exist, will clone to this path.
10
+ * If remoteUrl is provided and repoPath is not specified, clones to temp directory.
11
+ */
12
+ repoPath?: string;
13
+ /**
14
+ * Remote repository URL (https or git protocol).
15
+ * If provided, will clone the repository if repoPath doesn't exist.
16
+ * Examples:
17
+ * - https://github.com/user/repo.git
18
+ * - git@github.com:user/repo.git
19
+ */
20
+ remoteUrl?: string;
8
21
  description?: string;
22
+ /**
23
+ * List of branches to expose/access.
24
+ * Also used for clone optimization when cloning from remoteUrl:
25
+ * - Single branch (e.g., ['main']): Uses --single-branch for faster clone
26
+ * - Multiple branches: Clones all branches, filters access to specified ones
27
+ * - Not specified: All branches are accessible
28
+ */
9
29
  branches?: string[];
10
30
  /**
11
31
  * Access mode for this module.
@@ -26,14 +46,38 @@ interface AFSGitOptions {
26
46
  name: string;
27
47
  email: string;
28
48
  };
49
+ /**
50
+ * Clone depth for shallow clone (only used when cloning from remoteUrl)
51
+ * @default 1
52
+ */
53
+ depth?: number;
54
+ /**
55
+ * Automatically clean up cloned repository on cleanup()
56
+ * Only applies when repository was auto-cloned to temp directory
57
+ * @default true
58
+ */
59
+ autoCleanup?: boolean;
60
+ /**
61
+ * Git clone options (only used when cloning from remoteUrl)
62
+ */
63
+ cloneOptions?: {
64
+ /**
65
+ * Authentication credentials for private repositories
66
+ */
67
+ auth?: {
68
+ username?: string;
69
+ password?: string;
70
+ };
71
+ };
29
72
  }
30
73
  declare class AFSGit implements AFSModule {
31
74
  options: AFSGitOptions & {
32
75
  cwd?: string;
33
76
  };
34
- static schema(): z.ZodEffects<z.ZodObject<{
77
+ static schema(): z.ZodEffects<z.ZodEffects<z.ZodObject<{
35
78
  name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
36
- repoPath: z.ZodString;
79
+ repoPath: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
80
+ remoteUrl: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
37
81
  description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
38
82
  branches: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
39
83
  accessMode: z.ZodType<"readonly" | "readwrite" | undefined, z.ZodTypeDef, "readonly" | "readwrite" | undefined>;
@@ -45,9 +89,23 @@ declare class AFSGit implements AFSModule {
45
89
  name: string;
46
90
  email: string;
47
91
  } | undefined>;
92
+ depth: z.ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
93
+ autoCleanup: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
94
+ cloneOptions: z.ZodType<{
95
+ auth?: {
96
+ username?: string | undefined;
97
+ password?: string | undefined;
98
+ } | undefined;
99
+ } | undefined, z.ZodTypeDef, {
100
+ auth?: {
101
+ username?: string | undefined;
102
+ password?: string | undefined;
103
+ } | undefined;
104
+ } | undefined>;
48
105
  }, "strip", z.ZodTypeAny, {
49
- repoPath: string;
50
106
  name?: string | undefined;
107
+ repoPath?: string | undefined;
108
+ remoteUrl?: string | undefined;
51
109
  description?: string | undefined;
52
110
  branches?: string[] | undefined;
53
111
  accessMode?: "readonly" | "readwrite" | undefined;
@@ -56,9 +114,18 @@ declare class AFSGit implements AFSModule {
56
114
  name: string;
57
115
  email: string;
58
116
  } | undefined;
117
+ depth?: number | undefined;
118
+ autoCleanup?: boolean | undefined;
119
+ cloneOptions?: {
120
+ auth?: {
121
+ username?: string | undefined;
122
+ password?: string | undefined;
123
+ } | undefined;
124
+ } | undefined;
59
125
  }, {
60
- repoPath: string;
61
126
  name?: string | undefined;
127
+ repoPath?: string | undefined;
128
+ remoteUrl?: string | undefined;
62
129
  description?: string | undefined;
63
130
  branches?: string[] | undefined;
64
131
  accessMode?: "readonly" | "readwrite" | undefined;
@@ -67,9 +134,18 @@ declare class AFSGit implements AFSModule {
67
134
  name: string;
68
135
  email: string;
69
136
  } | undefined;
137
+ depth?: number | undefined;
138
+ autoCleanup?: boolean | undefined;
139
+ cloneOptions?: {
140
+ auth?: {
141
+ username?: string | undefined;
142
+ password?: string | undefined;
143
+ } | undefined;
144
+ } | undefined;
70
145
  }>, {
71
- repoPath: string;
72
146
  name?: string | undefined;
147
+ repoPath?: string | undefined;
148
+ remoteUrl?: string | undefined;
73
149
  description?: string | undefined;
74
150
  branches?: string[] | undefined;
75
151
  accessMode?: "readonly" | "readwrite" | undefined;
@@ -78,18 +154,83 @@ declare class AFSGit implements AFSModule {
78
154
  name: string;
79
155
  email: string;
80
156
  } | undefined;
157
+ depth?: number | undefined;
158
+ autoCleanup?: boolean | undefined;
159
+ cloneOptions?: {
160
+ auth?: {
161
+ username?: string | undefined;
162
+ password?: string | undefined;
163
+ } | undefined;
164
+ } | undefined;
165
+ }, {
166
+ name?: string | undefined;
167
+ repoPath?: string | undefined;
168
+ remoteUrl?: string | undefined;
169
+ description?: string | undefined;
170
+ branches?: string[] | undefined;
171
+ accessMode?: "readonly" | "readwrite" | undefined;
172
+ autoCommit?: boolean | undefined;
173
+ commitAuthor?: {
174
+ name: string;
175
+ email: string;
176
+ } | undefined;
177
+ depth?: number | undefined;
178
+ autoCleanup?: boolean | undefined;
179
+ cloneOptions?: {
180
+ auth?: {
181
+ username?: string | undefined;
182
+ password?: string | undefined;
183
+ } | undefined;
184
+ } | undefined;
185
+ }>, {
186
+ name?: string | undefined;
187
+ repoPath?: string | undefined;
188
+ remoteUrl?: string | undefined;
189
+ description?: string | undefined;
190
+ branches?: string[] | undefined;
191
+ accessMode?: "readonly" | "readwrite" | undefined;
192
+ autoCommit?: boolean | undefined;
193
+ commitAuthor?: {
194
+ name: string;
195
+ email: string;
196
+ } | undefined;
197
+ depth?: number | undefined;
198
+ autoCleanup?: boolean | undefined;
199
+ cloneOptions?: {
200
+ auth?: {
201
+ username?: string | undefined;
202
+ password?: string | undefined;
203
+ } | undefined;
204
+ } | undefined;
81
205
  }, any>;
82
206
  static load({
83
207
  filepath,
84
208
  parsed
85
209
  }: AFSModuleLoadParams): Promise<AFSGit>;
210
+ private initPromise;
86
211
  private git;
87
212
  private tempBase;
88
213
  private worktrees;
89
214
  private repoHash;
215
+ private isAutoCloned;
216
+ private clonedPath?;
217
+ private repoPath;
90
218
  constructor(options: AFSGitOptions & {
91
219
  cwd?: string;
92
220
  });
221
+ /**
222
+ * Wait for async initialization to complete
223
+ */
224
+ ready(): Promise<void>;
225
+ /**
226
+ * Async initialization logic (runs in constructor)
227
+ * Handles cloning remote repositories if needed
228
+ */
229
+ private initialize;
230
+ /**
231
+ * Clone a remote repository to local path
232
+ */
233
+ private static cloneRepository;
93
234
  name: string;
94
235
  description?: string;
95
236
  accessMode: AFSAccessMode;
@@ -138,6 +279,18 @@ declare class AFSGit implements AFSModule {
138
279
  message?: string;
139
280
  }>;
140
281
  search(path: string, query: string, options?: AFSSearchOptions): Promise<AFSSearchResult>;
282
+ /**
283
+ * Fetch latest changes from remote
284
+ */
285
+ fetch(): Promise<void>;
286
+ /**
287
+ * Pull latest changes from remote for current branch
288
+ */
289
+ pull(): Promise<void>;
290
+ /**
291
+ * Push local changes to remote
292
+ */
293
+ push(branch?: string): Promise<void>;
141
294
  /**
142
295
  * Cleanup all worktrees (useful when unmounting)
143
296
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;UAkCiB,aAAA;EAAA,IAAA;EAAA,QAAA;EAAA,WAAA;EAAA,QAAA;EAAA;AA+CjB;;;;;EA/CiB,UAAA,GAWF,aAAA;EAAA;AAoCf;;;EApCe,UAAA;EAAA;AAoCf;;EApCe,YAAA;IAAA,IAAA;IAAA,KAAA;EAAA;AAAA;AAAA,cAoCF,MAAA,YAAkB,SAAA;EAAA,OAAA,EAeD,aAAA;IAAA,GAAA;EAAA;EA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,SAAA;EAAA,KAAA,IAAA,UAAA,OAAA,GA8PuB,cAAA,GAAiB,OAAA,CAAQ,aAAA;EAAA,KAAA,IAAA,UAAA,QAAA,GAyBxB,cAAA,GAAiB,OAAA,CAAQ,aAAA;EAAA,MAAA,IAAA,UAAA,KAAA,EAgGpD,oBAAA,EAAA,OAAA,GACG,eAAA,GACT,OAAA,CAAQ,cAAA;EAAA,OAAA,IAAA,UAAA,OAAA,GA2E0B,gBAAA,GAAmB,OAAA,CAAQ,eAAA;EAAA,OAAA,OAAA,UAAA,OAAA,UAAA,OAAA,GAoDpD,gBAAA,GACT,OAAA;IAAA,OAAA;EAAA;EAAA,OAAA,IAAA,UAAA,KAAA,UAAA,OAAA,GAyEiD,gBAAA,GAAmB,OAAA,CAAQ,eAAA;EAAA;;;EAAA,MAAA,GAuFhE,OAAA;EAAA;;;EAAA,KAAA,GAQD,OAAA;EAAA;;;EAAA,KAAA,MAAA,YAQe,OAAA;EAAA;;;EAAA,QAAA,GAYZ,OAAA;AAAA"}
package/dist/index.d.mts CHANGED
@@ -4,8 +4,28 @@ import { AFSAccessMode, AFSDeleteOptions, AFSDeleteResult, AFSListOptions, AFSLi
4
4
  //#region src/index.d.ts
5
5
  interface AFSGitOptions {
6
6
  name?: string;
7
- repoPath: string;
7
+ /**
8
+ * Local path to git repository.
9
+ * If remoteUrl is provided and repoPath doesn't exist, will clone to this path.
10
+ * If remoteUrl is provided and repoPath is not specified, clones to temp directory.
11
+ */
12
+ repoPath?: string;
13
+ /**
14
+ * Remote repository URL (https or git protocol).
15
+ * If provided, will clone the repository if repoPath doesn't exist.
16
+ * Examples:
17
+ * - https://github.com/user/repo.git
18
+ * - git@github.com:user/repo.git
19
+ */
20
+ remoteUrl?: string;
8
21
  description?: string;
22
+ /**
23
+ * List of branches to expose/access.
24
+ * Also used for clone optimization when cloning from remoteUrl:
25
+ * - Single branch (e.g., ['main']): Uses --single-branch for faster clone
26
+ * - Multiple branches: Clones all branches, filters access to specified ones
27
+ * - Not specified: All branches are accessible
28
+ */
9
29
  branches?: string[];
10
30
  /**
11
31
  * Access mode for this module.
@@ -26,14 +46,38 @@ interface AFSGitOptions {
26
46
  name: string;
27
47
  email: string;
28
48
  };
49
+ /**
50
+ * Clone depth for shallow clone (only used when cloning from remoteUrl)
51
+ * @default 1
52
+ */
53
+ depth?: number;
54
+ /**
55
+ * Automatically clean up cloned repository on cleanup()
56
+ * Only applies when repository was auto-cloned to temp directory
57
+ * @default true
58
+ */
59
+ autoCleanup?: boolean;
60
+ /**
61
+ * Git clone options (only used when cloning from remoteUrl)
62
+ */
63
+ cloneOptions?: {
64
+ /**
65
+ * Authentication credentials for private repositories
66
+ */
67
+ auth?: {
68
+ username?: string;
69
+ password?: string;
70
+ };
71
+ };
29
72
  }
30
73
  declare class AFSGit implements AFSModule {
31
74
  options: AFSGitOptions & {
32
75
  cwd?: string;
33
76
  };
34
- static schema(): z.ZodEffects<z.ZodObject<{
77
+ static schema(): z.ZodEffects<z.ZodEffects<z.ZodObject<{
35
78
  name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
36
- repoPath: z.ZodString;
79
+ repoPath: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
80
+ remoteUrl: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
37
81
  description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
38
82
  branches: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
39
83
  accessMode: z.ZodType<"readonly" | "readwrite" | undefined, z.ZodTypeDef, "readonly" | "readwrite" | undefined>;
@@ -45,9 +89,23 @@ declare class AFSGit implements AFSModule {
45
89
  name: string;
46
90
  email: string;
47
91
  } | undefined>;
92
+ depth: z.ZodType<number | undefined, z.ZodTypeDef, number | undefined>;
93
+ autoCleanup: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
94
+ cloneOptions: z.ZodType<{
95
+ auth?: {
96
+ username?: string | undefined;
97
+ password?: string | undefined;
98
+ } | undefined;
99
+ } | undefined, z.ZodTypeDef, {
100
+ auth?: {
101
+ username?: string | undefined;
102
+ password?: string | undefined;
103
+ } | undefined;
104
+ } | undefined>;
48
105
  }, "strip", z.ZodTypeAny, {
49
- repoPath: string;
50
106
  name?: string | undefined;
107
+ repoPath?: string | undefined;
108
+ remoteUrl?: string | undefined;
51
109
  description?: string | undefined;
52
110
  branches?: string[] | undefined;
53
111
  accessMode?: "readonly" | "readwrite" | undefined;
@@ -56,9 +114,18 @@ declare class AFSGit implements AFSModule {
56
114
  name: string;
57
115
  email: string;
58
116
  } | undefined;
117
+ depth?: number | undefined;
118
+ autoCleanup?: boolean | undefined;
119
+ cloneOptions?: {
120
+ auth?: {
121
+ username?: string | undefined;
122
+ password?: string | undefined;
123
+ } | undefined;
124
+ } | undefined;
59
125
  }, {
60
- repoPath: string;
61
126
  name?: string | undefined;
127
+ repoPath?: string | undefined;
128
+ remoteUrl?: string | undefined;
62
129
  description?: string | undefined;
63
130
  branches?: string[] | undefined;
64
131
  accessMode?: "readonly" | "readwrite" | undefined;
@@ -67,9 +134,18 @@ declare class AFSGit implements AFSModule {
67
134
  name: string;
68
135
  email: string;
69
136
  } | undefined;
137
+ depth?: number | undefined;
138
+ autoCleanup?: boolean | undefined;
139
+ cloneOptions?: {
140
+ auth?: {
141
+ username?: string | undefined;
142
+ password?: string | undefined;
143
+ } | undefined;
144
+ } | undefined;
70
145
  }>, {
71
- repoPath: string;
72
146
  name?: string | undefined;
147
+ repoPath?: string | undefined;
148
+ remoteUrl?: string | undefined;
73
149
  description?: string | undefined;
74
150
  branches?: string[] | undefined;
75
151
  accessMode?: "readonly" | "readwrite" | undefined;
@@ -78,18 +154,83 @@ declare class AFSGit implements AFSModule {
78
154
  name: string;
79
155
  email: string;
80
156
  } | undefined;
157
+ depth?: number | undefined;
158
+ autoCleanup?: boolean | undefined;
159
+ cloneOptions?: {
160
+ auth?: {
161
+ username?: string | undefined;
162
+ password?: string | undefined;
163
+ } | undefined;
164
+ } | undefined;
165
+ }, {
166
+ name?: string | undefined;
167
+ repoPath?: string | undefined;
168
+ remoteUrl?: string | undefined;
169
+ description?: string | undefined;
170
+ branches?: string[] | undefined;
171
+ accessMode?: "readonly" | "readwrite" | undefined;
172
+ autoCommit?: boolean | undefined;
173
+ commitAuthor?: {
174
+ name: string;
175
+ email: string;
176
+ } | undefined;
177
+ depth?: number | undefined;
178
+ autoCleanup?: boolean | undefined;
179
+ cloneOptions?: {
180
+ auth?: {
181
+ username?: string | undefined;
182
+ password?: string | undefined;
183
+ } | undefined;
184
+ } | undefined;
185
+ }>, {
186
+ name?: string | undefined;
187
+ repoPath?: string | undefined;
188
+ remoteUrl?: string | undefined;
189
+ description?: string | undefined;
190
+ branches?: string[] | undefined;
191
+ accessMode?: "readonly" | "readwrite" | undefined;
192
+ autoCommit?: boolean | undefined;
193
+ commitAuthor?: {
194
+ name: string;
195
+ email: string;
196
+ } | undefined;
197
+ depth?: number | undefined;
198
+ autoCleanup?: boolean | undefined;
199
+ cloneOptions?: {
200
+ auth?: {
201
+ username?: string | undefined;
202
+ password?: string | undefined;
203
+ } | undefined;
204
+ } | undefined;
81
205
  }, any>;
82
206
  static load({
83
207
  filepath,
84
208
  parsed
85
209
  }: AFSModuleLoadParams): Promise<AFSGit>;
210
+ private initPromise;
86
211
  private git;
87
212
  private tempBase;
88
213
  private worktrees;
89
214
  private repoHash;
215
+ private isAutoCloned;
216
+ private clonedPath?;
217
+ private repoPath;
90
218
  constructor(options: AFSGitOptions & {
91
219
  cwd?: string;
92
220
  });
221
+ /**
222
+ * Wait for async initialization to complete
223
+ */
224
+ ready(): Promise<void>;
225
+ /**
226
+ * Async initialization logic (runs in constructor)
227
+ * Handles cloning remote repositories if needed
228
+ */
229
+ private initialize;
230
+ /**
231
+ * Clone a remote repository to local path
232
+ */
233
+ private static cloneRepository;
93
234
  name: string;
94
235
  description?: string;
95
236
  accessMode: AFSAccessMode;
@@ -138,6 +279,18 @@ declare class AFSGit implements AFSModule {
138
279
  message?: string;
139
280
  }>;
140
281
  search(path: string, query: string, options?: AFSSearchOptions): Promise<AFSSearchResult>;
282
+ /**
283
+ * Fetch latest changes from remote
284
+ */
285
+ fetch(): Promise<void>;
286
+ /**
287
+ * Pull latest changes from remote for current branch
288
+ */
289
+ pull(): Promise<void>;
290
+ /**
291
+ * Push local changes to remote
292
+ */
293
+ push(branch?: string): Promise<void>;
141
294
  /**
142
295
  * Cleanup all worktrees (useful when unmounting)
143
296
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;UAkCiB,aAAA;EAAA,IAAA;EAAA,QAAA;EAAA,WAAA;EAAA,QAAA;EAAA;AA+CjB;;;;;EA/CiB,UAAA,GAWF,aAAA;EAAA;AAoCf;;;EApCe,UAAA;EAAA;AAoCf;;EApCe,YAAA;IAAA,IAAA;IAAA,KAAA;EAAA;AAAA;AAAA,cAoCF,MAAA,YAAkB,SAAA;EAAA,OAAA,EAeD,aAAA;IAAA,GAAA;EAAA;EAAA,OAAA,OAAA,GAdf,CAAA,CAAA,UAAA,CAAA,CAAA,CAAA,SAAA;IAAA,IAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAI2B,mBAAA,GAAmB,OAAA,CAAA,MAAA;EAAA,QAAA,GAAA;EAAA,QAAA,QAAA;EAAA,QAAA,SAAA;EAAA,QAAA,QAAA;EAAA,YAAA,OAAA,EAU/B,aAAA;IAAA,GAAA;EAAA;EAAA,IAAA;EAAA,WAAA;EAAA,UAAA,EAwBhB,aAAA;EAAA;;;;;;;;;EAAA,QAAA,SAAA;EAAA;;;EAAA,QAAA,WAAA;EAAA;;;EAAA,QAAA,YAAA;EAAA;;;EAAA,QAAA,WAAA;EAAA;;;EAAA,QAAA,cAAA;EAAA;;;EAAA,QAAA,iBAAA;EAAA;;;;;;EAAA,QAAA,SAAA;EAAA,KAAA,IAAA,UAAA,OAAA,GA8PuB,cAAA,GAAi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AA;;;EAAA,QAAA,GAYZ,OAAA;AAAA"}
package/dist/index.mjs CHANGED
@@ -9,11 +9,12 @@ import { simpleGit } from "simple-git";
9
9
  import { z } from "zod";
10
10
 
11
11
  //#region src/index.ts
12
- const execFileAsync = promisify(execFile);
13
12
  const LIST_MAX_LIMIT = 1e3;
13
+ const execFileAsync = promisify(execFile);
14
14
  const afsGitOptionsSchema = camelize(z.object({
15
15
  name: optionalize(z.string()),
16
- repoPath: z.string().describe("The path to the git repository"),
16
+ repoPath: optionalize(z.string().describe("The path to the git repository")),
17
+ remoteUrl: optionalize(z.string().describe("Remote repository URL (https or git protocol)")),
17
18
  description: optionalize(z.string().describe("A description of the repository")),
18
19
  branches: optionalize(z.array(z.string()).describe("List of branches to expose")),
19
20
  accessMode: optionalize(z.enum(["readonly", "readwrite"]).describe("Access mode for this module")),
@@ -21,35 +22,107 @@ const afsGitOptionsSchema = camelize(z.object({
21
22
  commitAuthor: optionalize(z.object({
22
23
  name: z.string(),
23
24
  email: z.string()
24
- }))
25
- }));
25
+ })),
26
+ depth: optionalize(z.number().describe("Clone depth for shallow clone")),
27
+ autoCleanup: optionalize(z.boolean().describe("Automatically clean up cloned repository on cleanup()")),
28
+ cloneOptions: optionalize(z.object({ auth: optionalize(z.object({
29
+ username: optionalize(z.string()),
30
+ password: optionalize(z.string())
31
+ })) }))
32
+ }).refine((data) => data.repoPath || data.remoteUrl, { message: "Either repoPath or remoteUrl must be provided" }));
26
33
  var AFSGit = class AFSGit {
27
34
  static schema() {
28
35
  return afsGitOptionsSchema;
29
36
  }
30
37
  static async load({ filepath, parsed }) {
31
- return new AFSGit({
38
+ const instance = new AFSGit({
32
39
  ...await AFSGit.schema().parseAsync(parsed),
33
40
  cwd: dirname(filepath)
34
41
  });
42
+ await instance.ready();
43
+ return instance;
35
44
  }
45
+ initPromise;
36
46
  git;
37
47
  tempBase;
38
48
  worktrees = /* @__PURE__ */ new Map();
39
49
  repoHash;
50
+ isAutoCloned = false;
51
+ clonedPath;
52
+ repoPath;
40
53
  constructor(options) {
41
54
  this.options = options;
42
55
  zodParse(afsGitOptionsSchema, options);
43
56
  let repoPath;
44
- if (isAbsolute(options.repoPath)) repoPath = options.repoPath;
45
- else repoPath = join(options.cwd || process.cwd(), options.repoPath);
46
- this.options.repoPath = repoPath;
47
- this.name = options.name || basename(repoPath) || "git";
57
+ let repoName;
58
+ if (options.repoPath) {
59
+ repoPath = isAbsolute(options.repoPath) ? options.repoPath : join(options.cwd || process.cwd(), options.repoPath);
60
+ repoName = basename(repoPath);
61
+ } else if (options.remoteUrl) {
62
+ const urlParts = options.remoteUrl.split("/");
63
+ repoName = urlParts[urlParts.length - 1]?.replace(/\.git$/, "") || "git";
64
+ const repoHash = createHash("md5").update(options.remoteUrl).digest("hex").substring(0, 8);
65
+ repoPath = join(tmpdir(), `afs-git-remote-${repoHash}`);
66
+ } else throw new Error("Either repoPath or remoteUrl must be provided");
67
+ this.repoPath = repoPath;
68
+ this.name = options.name || repoName;
48
69
  this.description = options.description;
49
70
  this.accessMode = options.accessMode ?? "readonly";
50
- this.git = simpleGit(repoPath);
51
71
  this.repoHash = createHash("md5").update(repoPath).digest("hex").substring(0, 8);
52
72
  this.tempBase = join(tmpdir(), `afs-git-${this.repoHash}`);
73
+ this.git = null;
74
+ this.initPromise = this.initialize();
75
+ }
76
+ /**
77
+ * Wait for async initialization to complete
78
+ */
79
+ async ready() {
80
+ await this.initPromise;
81
+ }
82
+ /**
83
+ * Async initialization logic (runs in constructor)
84
+ * Handles cloning remote repositories if needed
85
+ */
86
+ async initialize() {
87
+ const options = this.options;
88
+ if (options.remoteUrl) {
89
+ const targetPath = options.repoPath ? isAbsolute(options.repoPath) ? options.repoPath : join(options.cwd || process.cwd(), options.repoPath) : this.repoPath;
90
+ if (!options.repoPath) this.isAutoCloned = true;
91
+ if (!await stat(targetPath).then(() => true).catch(() => false)) {
92
+ const singleBranch = options.branches?.length === 1 ? options.branches[0] : void 0;
93
+ await AFSGit.cloneRepository(options.remoteUrl, targetPath, {
94
+ depth: options.depth ?? 1,
95
+ branch: singleBranch,
96
+ auth: options.cloneOptions?.auth
97
+ });
98
+ }
99
+ if (targetPath !== this.repoPath) {
100
+ this.repoPath = targetPath;
101
+ this.repoHash = createHash("md5").update(targetPath).digest("hex").substring(0, 8);
102
+ this.tempBase = join(tmpdir(), `afs-git-${this.repoHash}`);
103
+ }
104
+ this.clonedPath = this.isAutoCloned ? targetPath : void 0;
105
+ }
106
+ this.git = simpleGit(this.repoPath);
107
+ }
108
+ /**
109
+ * Clone a remote repository to local path
110
+ */
111
+ static async cloneRepository(remoteUrl, targetPath, options = {}) {
112
+ const git = simpleGit();
113
+ const cloneArgs = [];
114
+ if (options.depth) cloneArgs.push("--depth", options.depth.toString());
115
+ if (options.branch) cloneArgs.push("--branch", options.branch, "--single-branch");
116
+ let cloneUrl = remoteUrl;
117
+ if (options.auth?.username && options.auth?.password) {
118
+ if (remoteUrl.startsWith("https://")) {
119
+ const url = new URL(remoteUrl);
120
+ url.username = encodeURIComponent(options.auth.username);
121
+ url.password = encodeURIComponent(options.auth.password);
122
+ cloneUrl = url.toString();
123
+ }
124
+ }
125
+ await git.clone(cloneUrl, targetPath, cloneArgs);
53
126
  }
54
127
  name;
55
128
  description;
@@ -136,8 +209,8 @@ var AFSGit = class AFSGit {
136
209
  async ensureWorktree(branch) {
137
210
  if (this.worktrees.has(branch)) return this.worktrees.get(branch);
138
211
  if ((await this.git.revparse(["--abbrev-ref", "HEAD"])).trim() === branch) {
139
- this.worktrees.set(branch, this.options.repoPath);
140
- return this.options.repoPath;
212
+ this.worktrees.set(branch, this.repoPath);
213
+ return this.repoPath;
141
214
  }
142
215
  const worktreePath = join(this.tempBase, branch);
143
216
  if (!await stat(worktreePath).then(() => true).catch(() => false)) {
@@ -242,6 +315,7 @@ var AFSGit = class AFSGit {
242
315
  return `/${encodedBranch}/${filePath}`;
243
316
  }
244
317
  async list(path, options) {
318
+ await this.ready();
245
319
  const { branch, filePath } = this.parsePath(path);
246
320
  if (!branch) return { data: (await this.getBranches()).map((name) => {
247
321
  const encodedPath = this.buildPath(name);
@@ -254,6 +328,7 @@ var AFSGit = class AFSGit {
254
328
  return this.listWithGitLsTree(branch, filePath, options);
255
329
  }
256
330
  async read(path, _options) {
331
+ await this.ready();
257
332
  const { branch, filePath } = this.parsePath(path);
258
333
  if (!branch) return { data: {
259
334
  id: "/",
@@ -322,6 +397,7 @@ var AFSGit = class AFSGit {
322
397
  }
323
398
  }
324
399
  async write(path, entry, options) {
400
+ await this.ready();
325
401
  const { branch, filePath } = this.parsePath(path);
326
402
  if (!branch || !filePath) throw new Error("Cannot write to root or branch root");
327
403
  const worktreePath = await this.ensureWorktree(branch);
@@ -366,6 +442,7 @@ var AFSGit = class AFSGit {
366
442
  } };
367
443
  }
368
444
  async delete(path, options) {
445
+ await this.ready();
369
446
  const { branch, filePath } = this.parsePath(path);
370
447
  if (!branch || !filePath) throw new Error("Cannot delete root or branch root");
371
448
  const worktreePath = await this.ensureWorktree(branch);
@@ -388,6 +465,7 @@ var AFSGit = class AFSGit {
388
465
  return { message: `Successfully deleted: ${path}` };
389
466
  }
390
467
  async rename(oldPath, newPath, options) {
468
+ await this.ready();
391
469
  const { branch: oldBranch, filePath: oldFilePath } = this.parsePath(oldPath);
392
470
  const { branch: newBranch, filePath: newFilePath } = this.parsePath(newPath);
393
471
  if (!oldBranch || !oldFilePath) throw new Error("Cannot rename from root or branch root");
@@ -418,6 +496,7 @@ var AFSGit = class AFSGit {
418
496
  return { message: `Successfully renamed '${oldPath}' to '${newPath}'` };
419
497
  }
420
498
  async search(path, query, options) {
499
+ await this.ready();
421
500
  const { branch, filePath } = this.parsePath(path);
422
501
  if (!branch) return {
423
502
  data: [],
@@ -476,9 +555,32 @@ var AFSGit = class AFSGit {
476
555
  }
477
556
  }
478
557
  /**
558
+ * Fetch latest changes from remote
559
+ */
560
+ async fetch() {
561
+ await this.ready();
562
+ await this.git.fetch();
563
+ }
564
+ /**
565
+ * Pull latest changes from remote for current branch
566
+ */
567
+ async pull() {
568
+ await this.ready();
569
+ await this.git.pull();
570
+ }
571
+ /**
572
+ * Push local changes to remote
573
+ */
574
+ async push(branch) {
575
+ await this.ready();
576
+ if (branch) await this.git.push("origin", branch);
577
+ else await this.git.push();
578
+ }
579
+ /**
479
580
  * Cleanup all worktrees (useful when unmounting)
480
581
  */
481
582
  async cleanup() {
583
+ await this.ready();
482
584
  for (const [_branch, worktreePath] of this.worktrees) try {
483
585
  await this.git.raw([
484
586
  "worktree",
@@ -494,6 +596,13 @@ var AFSGit = class AFSGit {
494
596
  force: true
495
597
  });
496
598
  } catch {}
599
+ const autoCleanup = this.options.autoCleanup ?? true;
600
+ if (this.isAutoCloned && autoCleanup && this.clonedPath) try {
601
+ await rm(this.clonedPath, {
602
+ recursive: true,
603
+ force: true
604
+ });
605
+ } catch {}
497
606
  }
498
607
  };
499
608
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["afsPath"],"sources":["../src/index.ts"],"sourcesContent":["import { execFile } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport { mkdir, rename, rm, stat, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { basename, dirname, isAbsolute, join } from \"node:path\";\nimport { promisify } from \"node:util\";\n\nconst execFileAsync = promisify(execFile);\n\nimport type {\n AFSAccessMode,\n AFSDeleteOptions,\n AFSDeleteResult,\n AFSEntry,\n AFSListOptions,\n AFSListResult,\n AFSModule,\n AFSModuleClass,\n AFSModuleLoadParams,\n AFSReadOptions,\n AFSReadResult,\n AFSRenameOptions,\n AFSSearchOptions,\n AFSSearchResult,\n AFSWriteEntryPayload,\n AFSWriteOptions,\n AFSWriteResult,\n} from \"@aigne/afs\";\nimport { camelize, optionalize, zodParse } from \"@aigne/afs/utils/zod\";\nimport { type SimpleGit, simpleGit } from \"simple-git\";\nimport { z } from \"zod\";\n\nconst LIST_MAX_LIMIT = 1000;\n\nexport interface AFSGitOptions {\n name?: string;\n repoPath: string;\n description?: string;\n branches?: string[];\n /**\n * Access mode for this module.\n * - \"readonly\": Only read operations are allowed, uses git commands (no worktree)\n * - \"readwrite\": All operations are allowed, creates worktrees as needed\n * @default \"readonly\"\n */\n accessMode?: AFSAccessMode;\n /**\n * Automatically commit changes after write operations\n * @default false\n */\n autoCommit?: boolean;\n /**\n * Author information for commits when autoCommit is enabled\n */\n commitAuthor?: {\n name: string;\n email: string;\n };\n}\n\nconst afsGitOptionsSchema = camelize(\n z.object({\n name: optionalize(z.string()),\n repoPath: z.string().describe(\"The path to the git repository\"),\n description: optionalize(z.string().describe(\"A description of the repository\")),\n branches: optionalize(z.array(z.string()).describe(\"List of branches to expose\")),\n accessMode: optionalize(\n z.enum([\"readonly\", \"readwrite\"]).describe(\"Access mode for this module\"),\n ),\n autoCommit: optionalize(\n z.boolean().describe(\"Automatically commit changes after write operations\"),\n ),\n commitAuthor: optionalize(\n z.object({\n name: z.string(),\n email: z.string(),\n }),\n ),\n }),\n);\n\nexport class AFSGit implements AFSModule {\n static schema() {\n return afsGitOptionsSchema;\n }\n\n static async load({ filepath, parsed }: AFSModuleLoadParams) {\n const valid = await AFSGit.schema().parseAsync(parsed);\n return new AFSGit({ ...valid, cwd: dirname(filepath) });\n }\n\n private git: SimpleGit;\n private tempBase: string;\n private worktrees: Map<string, string> = new Map();\n private repoHash: string;\n\n constructor(public options: AFSGitOptions & { cwd?: string }) {\n zodParse(afsGitOptionsSchema, options);\n\n let repoPath: string;\n if (isAbsolute(options.repoPath)) {\n repoPath = options.repoPath;\n } else {\n repoPath = join(options.cwd || process.cwd(), options.repoPath);\n }\n\n this.options.repoPath = repoPath;\n this.name = options.name || basename(repoPath) || \"git\";\n this.description = options.description;\n this.accessMode = options.accessMode ?? \"readonly\";\n\n this.git = simpleGit(repoPath);\n\n // Create a hash of the repo path for unique temp directory\n this.repoHash = createHash(\"md5\").update(repoPath).digest(\"hex\").substring(0, 8);\n this.tempBase = join(tmpdir(), `afs-git-${this.repoHash}`);\n }\n\n name: string;\n description?: string;\n accessMode: AFSAccessMode;\n\n /**\n * Parse AFS path into branch and file path\n * Branch names may contain slashes and are encoded with ~ in paths\n * Examples:\n * \"/\" -> { branch: undefined, filePath: \"\" }\n * \"/main\" -> { branch: \"main\", filePath: \"\" }\n * \"/feature~new-feature\" -> { branch: \"feature/new-feature\", filePath: \"\" }\n * \"/main/src/index.ts\" -> { branch: \"main\", filePath: \"src/index.ts\" }\n */\n private parsePath(path: string): { branch?: string; filePath: string } {\n const normalized = join(\"/\", path); // Ensure leading slash\n const segments = normalized.split(\"/\").filter(Boolean);\n\n if (segments.length === 0) {\n return { branch: undefined, filePath: \"\" };\n }\n\n // Decode branch name (first segment): replace ~ with /\n const branch = segments[0]!.replace(/~/g, \"/\");\n const filePath = segments.slice(1).join(\"/\");\n\n return { branch, filePath };\n }\n\n /**\n * Detect MIME type based on file extension\n */\n private getMimeType(filePath: string): string {\n const ext = filePath.split(\".\").pop()?.toLowerCase();\n const mimeTypes: Record<string, string> = {\n // Images\n png: \"image/png\",\n jpg: \"image/jpeg\",\n jpeg: \"image/jpeg\",\n gif: \"image/gif\",\n bmp: \"image/bmp\",\n webp: \"image/webp\",\n svg: \"image/svg+xml\",\n ico: \"image/x-icon\",\n // Documents\n pdf: \"application/pdf\",\n txt: \"text/plain\",\n md: \"text/markdown\",\n // Code\n js: \"text/javascript\",\n ts: \"text/typescript\",\n json: \"application/json\",\n html: \"text/html\",\n css: \"text/css\",\n xml: \"text/xml\",\n };\n return mimeTypes[ext || \"\"] || \"application/octet-stream\";\n }\n\n /**\n * Check if file is likely binary based on extension\n */\n private isBinaryFile(filePath: string): boolean {\n const ext = filePath.split(\".\").pop()?.toLowerCase();\n const binaryExtensions = [\n \"png\",\n \"jpg\",\n \"jpeg\",\n \"gif\",\n \"bmp\",\n \"webp\",\n \"ico\",\n \"pdf\",\n \"zip\",\n \"tar\",\n \"gz\",\n \"exe\",\n \"dll\",\n \"so\",\n \"dylib\",\n \"wasm\",\n ];\n return binaryExtensions.includes(ext || \"\");\n }\n\n /**\n * Get list of available branches\n */\n private async getBranches(): Promise<string[]> {\n const branchSummary = await this.git.branchLocal();\n const allBranches = branchSummary.all;\n\n // Filter by allowed branches if specified\n if (this.options.branches && this.options.branches.length > 0) {\n return allBranches.filter((branch) => this.options.branches!.includes(branch));\n }\n\n return allBranches;\n }\n\n /**\n * Ensure worktree exists for a branch (lazy creation)\n */\n private async ensureWorktree(branch: string): Promise<string> {\n if (this.worktrees.has(branch)) {\n return this.worktrees.get(branch)!;\n }\n\n // Check if this is the current branch in the main repo\n const currentBranch = await this.git.revparse([\"--abbrev-ref\", \"HEAD\"]);\n if (currentBranch.trim() === branch) {\n // Use the main repo path for the current branch\n this.worktrees.set(branch, this.options.repoPath);\n return this.options.repoPath;\n }\n\n const worktreePath = join(this.tempBase, branch);\n\n // Check if worktree directory already exists\n const exists = await stat(worktreePath)\n .then(() => true)\n .catch(() => false);\n\n if (!exists) {\n await mkdir(this.tempBase, { recursive: true });\n await this.git.raw([\"worktree\", \"add\", worktreePath, branch]);\n }\n\n this.worktrees.set(branch, worktreePath);\n return worktreePath;\n }\n\n /**\n * List files using git ls-tree (no worktree needed)\n */\n private async listWithGitLsTree(\n branch: string,\n path: string,\n options?: AFSListOptions,\n ): Promise<AFSListResult> {\n const maxDepth = options?.maxDepth ?? 1;\n const limit = Math.min(options?.limit || LIST_MAX_LIMIT, LIST_MAX_LIMIT);\n\n const entries: AFSEntry[] = [];\n const targetPath = path || \"\";\n const treeish = targetPath ? `${branch}:${targetPath}` : branch;\n\n try {\n // Check if the path exists and is a directory\n const pathType = await this.git\n .raw([\"cat-file\", \"-t\", treeish])\n .then((t) => t.trim())\n .catch(() => null);\n\n if (pathType === null) {\n // Path doesn't exist\n return { data: [] };\n }\n\n // If it's a file, just return it\n if (pathType === \"blob\") {\n const size = await this.git\n .raw([\"cat-file\", \"-s\", treeish])\n .then((s) => Number.parseInt(s.trim(), 10));\n\n const afsPath = this.buildPath(branch, path);\n entries.push({\n id: afsPath,\n path: afsPath,\n metadata: {\n type: \"file\",\n size,\n },\n });\n\n return { data: entries };\n }\n\n // It's a directory, list its contents\n interface QueueItem {\n path: string;\n depth: number;\n }\n\n const queue: QueueItem[] = [{ path: targetPath, depth: 0 }];\n\n while (queue.length > 0) {\n const item = queue.shift()!;\n const { path: itemPath, depth } = item;\n\n // List directory contents\n const itemTreeish = itemPath ? `${branch}:${itemPath}` : branch;\n const output = await this.git.raw([\"ls-tree\", \"-l\", itemTreeish]);\n\n const lines = output\n .split(\"\\n\")\n .filter((line) => line.trim())\n .slice(0, limit - entries.length);\n\n for (const line of lines) {\n // Format: <mode> <type> <hash> <size (with padding)> <name>\n // Example: 100644 blob abc123 1234\\tREADME.md\n // Note: size is \"-\" for trees/directories, and there can be multiple spaces/tabs before name\n const match = line.match(/^(\\d+)\\s+(blob|tree)\\s+(\\w+)\\s+(-|\\d+)\\s+(.+)$/);\n if (!match) continue;\n\n const type = match[2]!;\n const sizeStr = match[4]!;\n const name = match[5]!;\n const isDirectory = type === \"tree\";\n const size = sizeStr === \"-\" ? undefined : Number.parseInt(sizeStr, 10);\n\n const fullPath = itemPath ? `${itemPath}/${name}` : name;\n const afsPath = this.buildPath(branch, fullPath);\n\n entries.push({\n id: afsPath,\n path: afsPath,\n metadata: {\n type: isDirectory ? \"directory\" : \"file\",\n size,\n },\n });\n\n // Add to queue if it's a directory and we haven't reached max depth\n if (isDirectory && depth + 1 < maxDepth) {\n queue.push({ path: fullPath, depth: depth + 1 });\n }\n\n // Check limit\n if (entries.length >= limit) {\n return { data: entries };\n }\n }\n }\n\n return { data: entries };\n } catch (error) {\n return { data: [], message: (error as Error).message };\n }\n }\n\n /**\n * Build AFS path with encoded branch name\n * Branch names with slashes are encoded by replacing / with ~\n * @param branch Branch name (may contain slashes)\n * @param filePath File path within branch\n */\n private buildPath(branch: string, filePath?: string): string {\n // Replace / with ~ in branch name\n const encodedBranch = branch.replace(/\\//g, \"~\");\n if (!filePath) {\n return `/${encodedBranch}`;\n }\n return `/${encodedBranch}/${filePath}`;\n }\n\n async list(path: string, options?: AFSListOptions): Promise<AFSListResult> {\n const { branch, filePath } = this.parsePath(path);\n\n // Root path - list branches\n if (!branch) {\n const branches = await this.getBranches();\n return {\n data: branches.map((name) => {\n const encodedPath = this.buildPath(name);\n return {\n id: encodedPath,\n path: encodedPath,\n metadata: {\n type: \"directory\",\n },\n };\n }),\n };\n }\n\n // List files in branch using git ls-tree\n return this.listWithGitLsTree(branch, filePath, options);\n }\n\n async read(path: string, _options?: AFSReadOptions): Promise<AFSReadResult> {\n const { branch, filePath } = this.parsePath(path);\n\n if (!branch) {\n return {\n data: {\n id: \"/\",\n path: \"/\",\n metadata: { type: \"directory\" },\n },\n };\n }\n\n if (!filePath) {\n const branchPath = this.buildPath(branch);\n return {\n data: {\n id: branchPath,\n path: branchPath,\n metadata: { type: \"directory\" },\n },\n };\n }\n\n try {\n // Check if path is a blob (file) or tree (directory)\n const objectType = await this.git\n .raw([\"cat-file\", \"-t\", `${branch}:${filePath}`])\n .then((t) => t.trim());\n\n if (objectType === \"tree\") {\n // It's a directory\n const afsPath = this.buildPath(branch, filePath);\n return {\n data: {\n id: afsPath,\n path: afsPath,\n metadata: {\n type: \"directory\",\n },\n },\n };\n }\n\n // It's a file, get content\n const size = await this.git\n .raw([\"cat-file\", \"-s\", `${branch}:${filePath}`])\n .then((s) => Number.parseInt(s.trim(), 10));\n\n // Determine mimeType based on file extension\n const mimeType = this.getMimeType(filePath);\n const isBinary = this.isBinaryFile(filePath);\n\n let content: string;\n const metadata: Record<string, any> = {\n type: \"file\",\n size,\n mimeType,\n };\n\n if (isBinary) {\n // For binary files, use execFileAsync to get raw buffer\n const { stdout } = await execFileAsync(\"git\", [\"cat-file\", \"-p\", `${branch}:${filePath}`], {\n cwd: this.options.repoPath,\n encoding: \"buffer\",\n maxBuffer: 10 * 1024 * 1024, // 10MB max\n });\n // Store only base64 string without data URL prefix\n content = (stdout as Buffer).toString(\"base64\");\n // Mark content as base64 in metadata\n metadata.contentType = \"base64\";\n } else {\n // For text files, use git.show\n content = await this.git.show([`${branch}:${filePath}`]);\n }\n\n const afsPath = this.buildPath(branch, filePath);\n return {\n data: {\n id: afsPath,\n path: afsPath,\n content,\n metadata,\n },\n };\n } catch (error) {\n return {\n data: undefined,\n message: (error as Error).message,\n };\n }\n }\n\n async write(\n path: string,\n entry: AFSWriteEntryPayload,\n options?: AFSWriteOptions,\n ): Promise<AFSWriteResult> {\n const { branch, filePath } = this.parsePath(path);\n\n if (!branch || !filePath) {\n throw new Error(\"Cannot write to root or branch root\");\n }\n\n // Create worktree for write operations\n const worktreePath = await this.ensureWorktree(branch);\n const fullPath = join(worktreePath, filePath);\n const append = options?.append ?? false;\n\n // Ensure parent directory exists\n const parentDir = dirname(fullPath);\n await mkdir(parentDir, { recursive: true });\n\n // Write content\n if (entry.content !== undefined) {\n let contentToWrite: string;\n if (typeof entry.content === \"string\") {\n contentToWrite = entry.content;\n } else {\n contentToWrite = JSON.stringify(entry.content, null, 2);\n }\n await writeFile(fullPath, contentToWrite, {\n encoding: \"utf8\",\n flag: append ? \"a\" : \"w\",\n });\n }\n\n // Auto commit if enabled\n if (this.options.autoCommit) {\n const gitInstance = simpleGit(worktreePath);\n await gitInstance.add(filePath);\n\n if (this.options.commitAuthor) {\n await gitInstance.addConfig(\n \"user.name\",\n this.options.commitAuthor.name,\n undefined,\n \"local\",\n );\n await gitInstance.addConfig(\n \"user.email\",\n this.options.commitAuthor.email,\n undefined,\n \"local\",\n );\n }\n\n await gitInstance.commit(`Update ${filePath}`);\n }\n\n // Get file stats\n const stats = await stat(fullPath);\n\n const afsPath = this.buildPath(branch, filePath);\n const writtenEntry: AFSEntry = {\n id: afsPath,\n path: afsPath,\n content: entry.content,\n summary: entry.summary,\n createdAt: stats.birthtime,\n updatedAt: stats.mtime,\n metadata: {\n ...entry.metadata,\n type: stats.isDirectory() ? \"directory\" : \"file\",\n size: stats.size,\n },\n userId: entry.userId,\n sessionId: entry.sessionId,\n linkTo: entry.linkTo,\n };\n\n return { data: writtenEntry };\n }\n\n async delete(path: string, options?: AFSDeleteOptions): Promise<AFSDeleteResult> {\n const { branch, filePath } = this.parsePath(path);\n\n if (!branch || !filePath) {\n throw new Error(\"Cannot delete root or branch root\");\n }\n\n // Create worktree for delete operations\n const worktreePath = await this.ensureWorktree(branch);\n const fullPath = join(worktreePath, filePath);\n const recursive = options?.recursive ?? false;\n\n const stats = await stat(fullPath);\n\n if (stats.isDirectory() && !recursive) {\n throw new Error(\n `Cannot delete directory '${path}' without recursive option. Set recursive: true to delete directories.`,\n );\n }\n\n await rm(fullPath, { recursive, force: true });\n\n // Auto commit if enabled\n if (this.options.autoCommit) {\n const gitInstance = simpleGit(worktreePath);\n await gitInstance.add(filePath);\n\n if (this.options.commitAuthor) {\n await gitInstance.addConfig(\n \"user.name\",\n this.options.commitAuthor.name,\n undefined,\n \"local\",\n );\n await gitInstance.addConfig(\n \"user.email\",\n this.options.commitAuthor.email,\n undefined,\n \"local\",\n );\n }\n\n await gitInstance.commit(`Delete ${filePath}`);\n }\n\n return { message: `Successfully deleted: ${path}` };\n }\n\n async rename(\n oldPath: string,\n newPath: string,\n options?: AFSRenameOptions,\n ): Promise<{ message?: string }> {\n const { branch: oldBranch, filePath: oldFilePath } = this.parsePath(oldPath);\n const { branch: newBranch, filePath: newFilePath } = this.parsePath(newPath);\n\n if (!oldBranch || !oldFilePath) {\n throw new Error(\"Cannot rename from root or branch root\");\n }\n\n if (!newBranch || !newFilePath) {\n throw new Error(\"Cannot rename to root or branch root\");\n }\n\n if (oldBranch !== newBranch) {\n throw new Error(\"Cannot rename across branches\");\n }\n\n // Create worktree for rename operations\n const worktreePath = await this.ensureWorktree(oldBranch);\n const oldFullPath = join(worktreePath, oldFilePath);\n const newFullPath = join(worktreePath, newFilePath);\n const overwrite = options?.overwrite ?? false;\n\n // Check if source exists\n await stat(oldFullPath);\n\n // Check if destination exists\n try {\n await stat(newFullPath);\n if (!overwrite) {\n throw new Error(\n `Destination '${newPath}' already exists. Set overwrite: true to replace it.`,\n );\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw error;\n }\n }\n\n // Ensure parent directory exists\n const newParentDir = dirname(newFullPath);\n await mkdir(newParentDir, { recursive: true });\n\n // Perform rename\n await rename(oldFullPath, newFullPath);\n\n // Auto commit if enabled\n if (this.options.autoCommit) {\n const gitInstance = simpleGit(worktreePath);\n await gitInstance.add([oldFilePath, newFilePath]);\n\n if (this.options.commitAuthor) {\n await gitInstance.addConfig(\n \"user.name\",\n this.options.commitAuthor.name,\n undefined,\n \"local\",\n );\n await gitInstance.addConfig(\n \"user.email\",\n this.options.commitAuthor.email,\n undefined,\n \"local\",\n );\n }\n\n await gitInstance.commit(`Rename ${oldFilePath} to ${newFilePath}`);\n }\n\n return { message: `Successfully renamed '${oldPath}' to '${newPath}'` };\n }\n\n async search(path: string, query: string, options?: AFSSearchOptions): Promise<AFSSearchResult> {\n const { branch, filePath } = this.parsePath(path);\n\n if (!branch) {\n return { data: [], message: \"Search requires a branch path\" };\n }\n\n const limit = Math.min(options?.limit || LIST_MAX_LIMIT, LIST_MAX_LIMIT);\n\n try {\n // Use git grep for searching (no worktree needed)\n const args = [\"grep\", \"-n\", \"-I\"]; // -n for line numbers, -I to skip binary files\n\n if (options?.caseSensitive === false) {\n args.push(\"-i\");\n }\n\n args.push(query, branch);\n\n // Add path filter if specified\n if (filePath) {\n args.push(\"--\", filePath);\n }\n\n const output = await this.git.raw(args);\n const lines = output.split(\"\\n\").filter((line) => line.trim());\n\n const entries: AFSEntry[] = [];\n const processedFiles = new Set<string>();\n\n for (const line of lines) {\n // Format when searching in branch: branch:path:linenum:content\n // Try the format with branch prefix first\n let matchPath: string;\n let lineNum: string;\n let content: string;\n\n const matchWithBranch = line.match(/^[^:]+:([^:]+):(\\d+):(.+)$/);\n if (matchWithBranch) {\n matchPath = matchWithBranch[1]!;\n lineNum = matchWithBranch[2]!;\n content = matchWithBranch[3]!;\n } else {\n // Try format without branch: path:linenum:content\n const matchNoBranch = line.match(/^([^:]+):(\\d+):(.+)$/);\n if (!matchNoBranch) continue;\n matchPath = matchNoBranch[1]!;\n lineNum = matchNoBranch[2]!;\n content = matchNoBranch[3]!;\n }\n\n const afsPath = this.buildPath(branch, matchPath);\n\n if (processedFiles.has(afsPath)) continue;\n processedFiles.add(afsPath);\n\n entries.push({\n id: afsPath,\n path: afsPath,\n summary: `Line ${lineNum}: ${content}`,\n metadata: {\n type: \"file\",\n },\n });\n\n if (entries.length >= limit) {\n break;\n }\n }\n\n return {\n data: entries,\n message: entries.length >= limit ? `Results truncated to limit ${limit}` : undefined,\n };\n } catch (error) {\n // git grep returns exit code 1 if no matches found\n if ((error as Error).message.includes(\"did not match any file(s)\")) {\n return { data: [] };\n }\n return { data: [], message: (error as Error).message };\n }\n }\n\n /**\n * Cleanup all worktrees (useful when unmounting)\n */\n async cleanup(): Promise<void> {\n for (const [_branch, worktreePath] of this.worktrees) {\n try {\n await this.git.raw([\"worktree\", \"remove\", worktreePath, \"--force\"]);\n } catch (_error) {\n // Ignore errors during cleanup\n }\n }\n this.worktrees.clear();\n\n // Remove temp directory\n try {\n await rm(this.tempBase, { recursive: true, force: true });\n } catch {\n // Ignore errors\n }\n }\n}\n\nconst _typeCheck: AFSModuleClass<AFSGit, AFSGitOptions> = AFSGit;\n"],"mappings":";;;;;;;;;;;AAOA,MAAM,gBAAgB,UAAU,SAAS;AAyBzC,MAAM,iBAAiB;AA4BvB,MAAM,sBAAsB,SAC1B,EAAE,OAAO;CACP,MAAM,YAAY,EAAE,QAAQ,CAAC;CAC7B,UAAU,EAAE,QAAQ,CAAC,SAAS,iCAAiC;CAC/D,aAAa,YAAY,EAAE,QAAQ,CAAC,SAAS,kCAAkC,CAAC;CAChF,UAAU,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,SAAS,6BAA6B,CAAC;CACjF,YAAY,YACV,EAAE,KAAK,CAAC,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createHash } from \"node:crypto\";\nimport { mkdir, rename, rm, stat, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { basename, dirname, isAbsolute, join } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport type {\n AFSAccessMode,\n AFSDeleteOptions,\n AFSDeleteResult,\n AFSEntry,\n AFSListOptions,\n AFSListResult,\n AFSModule,\n AFSModuleClass,\n AFSModuleLoadParams,\n AFSReadOptions,\n AFSReadResult,\n AFSRenameOptions,\n AFSSearchOptions,\n AFSSearchResult,\n AFSWriteEntryPayload,\n AFSWriteOptions,\n AFSWriteResult,\n} from \"@aigne/afs\";\nimport { camelize, optionalize, zodParse } from \"@aigne/afs/utils/zod\";\nimport { type SimpleGit, simpleGit } from \"simple-git\";\nimport { z } from \"zod\";\n\nconst LIST_MAX_LIMIT = 1000;\n\nconst execFileAsync = promisify(execFile);\n\nexport interface AFSGitOptions {\n name?: string;\n /**\n * Local path to git repository.\n * If remoteUrl is provided and repoPath doesn't exist, will clone to this path.\n * If remoteUrl is provided and repoPath is not specified, clones to temp directory.\n */\n repoPath?: string;\n /**\n * Remote repository URL (https or git protocol).\n * If provided, will clone the repository if repoPath doesn't exist.\n * Examples:\n * - https://github.com/user/repo.git\n * - git@github.com:user/repo.git\n */\n remoteUrl?: string;\n description?: string;\n /**\n * List of branches to expose/access.\n * Also used for clone optimization when cloning from remoteUrl:\n * - Single branch (e.g., ['main']): Uses --single-branch for faster clone\n * - Multiple branches: Clones all branches, filters access to specified ones\n * - Not specified: All branches are accessible\n */\n branches?: string[];\n /**\n * Access mode for this module.\n * - \"readonly\": Only read operations are allowed, uses git commands (no worktree)\n * - \"readwrite\": All operations are allowed, creates worktrees as needed\n * @default \"readonly\"\n */\n accessMode?: AFSAccessMode;\n /**\n * Automatically commit changes after write operations\n * @default false\n */\n autoCommit?: boolean;\n /**\n * Author information for commits when autoCommit is enabled\n */\n commitAuthor?: {\n name: string;\n email: string;\n };\n /**\n * Clone depth for shallow clone (only used when cloning from remoteUrl)\n * @default 1\n */\n depth?: number;\n /**\n * Automatically clean up cloned repository on cleanup()\n * Only applies when repository was auto-cloned to temp directory\n * @default true\n */\n autoCleanup?: boolean;\n /**\n * Git clone options (only used when cloning from remoteUrl)\n */\n cloneOptions?: {\n /**\n * Authentication credentials for private repositories\n */\n auth?: {\n username?: string;\n password?: string;\n };\n };\n}\n\nconst afsGitOptionsSchema = camelize(\n z\n .object({\n name: optionalize(z.string()),\n repoPath: optionalize(z.string().describe(\"The path to the git repository\")),\n remoteUrl: optionalize(z.string().describe(\"Remote repository URL (https or git protocol)\")),\n description: optionalize(z.string().describe(\"A description of the repository\")),\n branches: optionalize(z.array(z.string()).describe(\"List of branches to expose\")),\n accessMode: optionalize(\n z.enum([\"readonly\", \"readwrite\"]).describe(\"Access mode for this module\"),\n ),\n autoCommit: optionalize(\n z.boolean().describe(\"Automatically commit changes after write operations\"),\n ),\n commitAuthor: optionalize(\n z.object({\n name: z.string(),\n email: z.string(),\n }),\n ),\n depth: optionalize(z.number().describe(\"Clone depth for shallow clone\")),\n autoCleanup: optionalize(\n z.boolean().describe(\"Automatically clean up cloned repository on cleanup()\"),\n ),\n cloneOptions: optionalize(\n z.object({\n auth: optionalize(\n z.object({\n username: optionalize(z.string()),\n password: optionalize(z.string()),\n }),\n ),\n }),\n ),\n })\n .refine((data) => data.repoPath || data.remoteUrl, {\n message: \"Either repoPath or remoteUrl must be provided\",\n }),\n);\n\nexport class AFSGit implements AFSModule {\n static schema() {\n return afsGitOptionsSchema;\n }\n\n static async load({ filepath, parsed }: AFSModuleLoadParams) {\n const valid = await AFSGit.schema().parseAsync(parsed);\n const instance = new AFSGit({ ...valid, cwd: dirname(filepath) });\n await instance.ready();\n return instance;\n }\n\n private initPromise: Promise<void>;\n private git: SimpleGit;\n private tempBase: string;\n private worktrees: Map<string, string> = new Map();\n private repoHash: string;\n private isAutoCloned = false;\n private clonedPath?: string;\n private repoPath: string;\n\n constructor(public options: AFSGitOptions & { cwd?: string }) {\n zodParse(afsGitOptionsSchema, options);\n\n // Synchronously determine repoPath to initialize name\n let repoPath: string;\n let repoName: string;\n\n if (options.repoPath) {\n // Use provided repoPath\n repoPath = isAbsolute(options.repoPath)\n ? options.repoPath\n : join(options.cwd || process.cwd(), options.repoPath);\n repoName = basename(repoPath);\n } else if (options.remoteUrl) {\n // Extract repo name from URL for temporary name\n const urlParts = options.remoteUrl.split(\"/\");\n const lastPart = urlParts[urlParts.length - 1];\n repoName = lastPart?.replace(/\\.git$/, \"\") || \"git\";\n\n // Will be updated during async init, use temp path for now\n const repoHash = createHash(\"md5\").update(options.remoteUrl).digest(\"hex\").substring(0, 8);\n repoPath = join(tmpdir(), `afs-git-remote-${repoHash}`);\n } else {\n // This should never happen due to schema validation\n throw new Error(\"Either repoPath or remoteUrl must be provided\");\n }\n\n // Initialize basic properties immediately\n this.repoPath = repoPath;\n this.name = options.name || repoName;\n this.description = options.description;\n this.accessMode = options.accessMode ?? \"readonly\";\n\n // Calculate hash for temp directories\n this.repoHash = createHash(\"md5\").update(repoPath).digest(\"hex\").substring(0, 8);\n this.tempBase = join(tmpdir(), `afs-git-${this.repoHash}`);\n\n // Note: git and other properties will be initialized in initialize() after cloning\n // We need to delay simpleGit() initialization until the directory exists\n this.git = null as any; // Will be set in initialize()\n\n // Start async initialization (cloning if needed)\n this.initPromise = this.initialize();\n }\n\n /**\n * Wait for async initialization to complete\n */\n async ready(): Promise<void> {\n await this.initPromise;\n }\n\n /**\n * Async initialization logic (runs in constructor)\n * Handles cloning remote repositories if needed\n */\n private async initialize(): Promise<void> {\n const options = this.options;\n\n // If remoteUrl is provided, handle cloning\n if (options.remoteUrl) {\n const targetPath = options.repoPath\n ? isAbsolute(options.repoPath)\n ? options.repoPath\n : join(options.cwd || process.cwd(), options.repoPath)\n : this.repoPath; // Use temp path set in constructor\n\n // Mark as auto-cloned if we're using temp directory\n if (!options.repoPath) {\n this.isAutoCloned = true;\n }\n\n // Check if repoPath exists, if not, clone to it\n const exists = await stat(targetPath)\n .then(() => true)\n .catch(() => false);\n\n if (!exists) {\n // Determine if single-branch optimization should be used\n const singleBranch = options.branches?.length === 1 ? options.branches[0] : undefined;\n\n await AFSGit.cloneRepository(options.remoteUrl, targetPath, {\n depth: options.depth ?? 1,\n branch: singleBranch,\n auth: options.cloneOptions?.auth,\n });\n }\n\n // Update properties if targetPath differs from constructor initialization\n if (targetPath !== this.repoPath) {\n this.repoPath = targetPath;\n this.repoHash = createHash(\"md5\").update(targetPath).digest(\"hex\").substring(0, 8);\n this.tempBase = join(tmpdir(), `afs-git-${this.repoHash}`);\n }\n\n this.clonedPath = this.isAutoCloned ? targetPath : undefined;\n }\n\n // Now that the directory exists (either it was there or we cloned it), initialize git\n this.git = simpleGit(this.repoPath);\n }\n\n /**\n * Clone a remote repository to local path\n */\n private static async cloneRepository(\n remoteUrl: string,\n targetPath: string,\n options: {\n depth?: number;\n branch?: string;\n auth?: { username?: string; password?: string };\n } = {},\n ): Promise<void> {\n const git = simpleGit();\n\n // Build clone options\n const cloneArgs: string[] = [];\n\n if (options.depth) {\n cloneArgs.push(\"--depth\", options.depth.toString());\n }\n\n if (options.branch) {\n cloneArgs.push(\"--branch\", options.branch, \"--single-branch\");\n }\n\n // Handle authentication in URL if provided\n let cloneUrl = remoteUrl;\n if (options.auth?.username && options.auth?.password) {\n // Insert credentials into HTTPS URL\n if (remoteUrl.startsWith(\"https://\")) {\n const url = new URL(remoteUrl);\n url.username = encodeURIComponent(options.auth.username);\n url.password = encodeURIComponent(options.auth.password);\n cloneUrl = url.toString();\n }\n }\n\n await git.clone(cloneUrl, targetPath, cloneArgs);\n }\n\n name: string;\n description?: string;\n accessMode: AFSAccessMode;\n\n /**\n * Parse AFS path into branch and file path\n * Branch names may contain slashes and are encoded with ~ in paths\n * Examples:\n * \"/\" -> { branch: undefined, filePath: \"\" }\n * \"/main\" -> { branch: \"main\", filePath: \"\" }\n * \"/feature~new-feature\" -> { branch: \"feature/new-feature\", filePath: \"\" }\n * \"/main/src/index.ts\" -> { branch: \"main\", filePath: \"src/index.ts\" }\n */\n private parsePath(path: string): { branch?: string; filePath: string } {\n const normalized = join(\"/\", path); // Ensure leading slash\n const segments = normalized.split(\"/\").filter(Boolean);\n\n if (segments.length === 0) {\n return { branch: undefined, filePath: \"\" };\n }\n\n // Decode branch name (first segment): replace ~ with /\n const branch = segments[0]!.replace(/~/g, \"/\");\n const filePath = segments.slice(1).join(\"/\");\n\n return { branch, filePath };\n }\n\n /**\n * Detect MIME type based on file extension\n */\n private getMimeType(filePath: string): string {\n const ext = filePath.split(\".\").pop()?.toLowerCase();\n const mimeTypes: Record<string, string> = {\n // Images\n png: \"image/png\",\n jpg: \"image/jpeg\",\n jpeg: \"image/jpeg\",\n gif: \"image/gif\",\n bmp: \"image/bmp\",\n webp: \"image/webp\",\n svg: \"image/svg+xml\",\n ico: \"image/x-icon\",\n // Documents\n pdf: \"application/pdf\",\n txt: \"text/plain\",\n md: \"text/markdown\",\n // Code\n js: \"text/javascript\",\n ts: \"text/typescript\",\n json: \"application/json\",\n html: \"text/html\",\n css: \"text/css\",\n xml: \"text/xml\",\n };\n return mimeTypes[ext || \"\"] || \"application/octet-stream\";\n }\n\n /**\n * Check if file is likely binary based on extension\n */\n private isBinaryFile(filePath: string): boolean {\n const ext = filePath.split(\".\").pop()?.toLowerCase();\n const binaryExtensions = [\n \"png\",\n \"jpg\",\n \"jpeg\",\n \"gif\",\n \"bmp\",\n \"webp\",\n \"ico\",\n \"pdf\",\n \"zip\",\n \"tar\",\n \"gz\",\n \"exe\",\n \"dll\",\n \"so\",\n \"dylib\",\n \"wasm\",\n ];\n return binaryExtensions.includes(ext || \"\");\n }\n\n /**\n * Get list of available branches\n */\n private async getBranches(): Promise<string[]> {\n const branchSummary = await this.git.branchLocal();\n const allBranches = branchSummary.all;\n\n // Filter by allowed branches if specified\n if (this.options.branches && this.options.branches.length > 0) {\n return allBranches.filter((branch) => this.options.branches!.includes(branch));\n }\n\n return allBranches;\n }\n\n /**\n * Ensure worktree exists for a branch (lazy creation)\n */\n private async ensureWorktree(branch: string): Promise<string> {\n if (this.worktrees.has(branch)) {\n return this.worktrees.get(branch)!;\n }\n\n // Check if this is the current branch in the main repo\n const currentBranch = await this.git.revparse([\"--abbrev-ref\", \"HEAD\"]);\n if (currentBranch.trim() === branch) {\n // Use the main repo path for the current branch\n this.worktrees.set(branch, this.repoPath);\n return this.repoPath;\n }\n\n const worktreePath = join(this.tempBase, branch);\n\n // Check if worktree directory already exists\n const exists = await stat(worktreePath)\n .then(() => true)\n .catch(() => false);\n\n if (!exists) {\n await mkdir(this.tempBase, { recursive: true });\n await this.git.raw([\"worktree\", \"add\", worktreePath, branch]);\n }\n\n this.worktrees.set(branch, worktreePath);\n return worktreePath;\n }\n\n /**\n * List files using git ls-tree (no worktree needed)\n */\n private async listWithGitLsTree(\n branch: string,\n path: string,\n options?: AFSListOptions,\n ): Promise<AFSListResult> {\n const maxDepth = options?.maxDepth ?? 1;\n const limit = Math.min(options?.limit || LIST_MAX_LIMIT, LIST_MAX_LIMIT);\n\n const entries: AFSEntry[] = [];\n const targetPath = path || \"\";\n const treeish = targetPath ? `${branch}:${targetPath}` : branch;\n\n try {\n // Check if the path exists and is a directory\n const pathType = await this.git\n .raw([\"cat-file\", \"-t\", treeish])\n .then((t) => t.trim())\n .catch(() => null);\n\n if (pathType === null) {\n // Path doesn't exist\n return { data: [] };\n }\n\n // If it's a file, just return it\n if (pathType === \"blob\") {\n const size = await this.git\n .raw([\"cat-file\", \"-s\", treeish])\n .then((s) => Number.parseInt(s.trim(), 10));\n\n const afsPath = this.buildPath(branch, path);\n entries.push({\n id: afsPath,\n path: afsPath,\n metadata: {\n type: \"file\",\n size,\n },\n });\n\n return { data: entries };\n }\n\n // It's a directory, list its contents\n interface QueueItem {\n path: string;\n depth: number;\n }\n\n const queue: QueueItem[] = [{ path: targetPath, depth: 0 }];\n\n while (queue.length > 0) {\n const item = queue.shift()!;\n const { path: itemPath, depth } = item;\n\n // List directory contents\n const itemTreeish = itemPath ? `${branch}:${itemPath}` : branch;\n const output = await this.git.raw([\"ls-tree\", \"-l\", itemTreeish]);\n\n const lines = output\n .split(\"\\n\")\n .filter((line) => line.trim())\n .slice(0, limit - entries.length);\n\n for (const line of lines) {\n // Format: <mode> <type> <hash> <size (with padding)> <name>\n // Example: 100644 blob abc123 1234\\tREADME.md\n // Note: size is \"-\" for trees/directories, and there can be multiple spaces/tabs before name\n const match = line.match(/^(\\d+)\\s+(blob|tree)\\s+(\\w+)\\s+(-|\\d+)\\s+(.+)$/);\n if (!match) continue;\n\n const type = match[2]!;\n const sizeStr = match[4]!;\n const name = match[5]!;\n const isDirectory = type === \"tree\";\n const size = sizeStr === \"-\" ? undefined : Number.parseInt(sizeStr, 10);\n\n const fullPath = itemPath ? `${itemPath}/${name}` : name;\n const afsPath = this.buildPath(branch, fullPath);\n\n entries.push({\n id: afsPath,\n path: afsPath,\n metadata: {\n type: isDirectory ? \"directory\" : \"file\",\n size,\n },\n });\n\n // Add to queue if it's a directory and we haven't reached max depth\n if (isDirectory && depth + 1 < maxDepth) {\n queue.push({ path: fullPath, depth: depth + 1 });\n }\n\n // Check limit\n if (entries.length >= limit) {\n return { data: entries };\n }\n }\n }\n\n return { data: entries };\n } catch (error) {\n return { data: [], message: (error as Error).message };\n }\n }\n\n /**\n * Build AFS path with encoded branch name\n * Branch names with slashes are encoded by replacing / with ~\n * @param branch Branch name (may contain slashes)\n * @param filePath File path within branch\n */\n private buildPath(branch: string, filePath?: string): string {\n // Replace / with ~ in branch name\n const encodedBranch = branch.replace(/\\//g, \"~\");\n if (!filePath) {\n return `/${encodedBranch}`;\n }\n return `/${encodedBranch}/${filePath}`;\n }\n\n async list(path: string, options?: AFSListOptions): Promise<AFSListResult> {\n await this.ready();\n const { branch, filePath } = this.parsePath(path);\n\n // Root path - list branches\n if (!branch) {\n const branches = await this.getBranches();\n return {\n data: branches.map((name) => {\n const encodedPath = this.buildPath(name);\n return {\n id: encodedPath,\n path: encodedPath,\n metadata: {\n type: \"directory\",\n },\n };\n }),\n };\n }\n\n // List files in branch using git ls-tree\n return this.listWithGitLsTree(branch, filePath, options);\n }\n\n async read(path: string, _options?: AFSReadOptions): Promise<AFSReadResult> {\n await this.ready();\n const { branch, filePath } = this.parsePath(path);\n\n if (!branch) {\n return {\n data: {\n id: \"/\",\n path: \"/\",\n metadata: { type: \"directory\" },\n },\n };\n }\n\n if (!filePath) {\n const branchPath = this.buildPath(branch);\n return {\n data: {\n id: branchPath,\n path: branchPath,\n metadata: { type: \"directory\" },\n },\n };\n }\n\n try {\n // Check if path is a blob (file) or tree (directory)\n const objectType = await this.git\n .raw([\"cat-file\", \"-t\", `${branch}:${filePath}`])\n .then((t) => t.trim());\n\n if (objectType === \"tree\") {\n // It's a directory\n const afsPath = this.buildPath(branch, filePath);\n return {\n data: {\n id: afsPath,\n path: afsPath,\n metadata: {\n type: \"directory\",\n },\n },\n };\n }\n\n // It's a file, get content\n const size = await this.git\n .raw([\"cat-file\", \"-s\", `${branch}:${filePath}`])\n .then((s) => Number.parseInt(s.trim(), 10));\n\n // Determine mimeType based on file extension\n const mimeType = this.getMimeType(filePath);\n const isBinary = this.isBinaryFile(filePath);\n\n let content: string;\n const metadata: Record<string, any> = {\n type: \"file\",\n size,\n mimeType,\n };\n\n if (isBinary) {\n // For binary files, use execFileAsync to get raw buffer\n const { stdout } = await execFileAsync(\"git\", [\"cat-file\", \"-p\", `${branch}:${filePath}`], {\n cwd: this.options.repoPath,\n encoding: \"buffer\",\n maxBuffer: 10 * 1024 * 1024, // 10MB max\n });\n // Store only base64 string without data URL prefix\n content = (stdout as Buffer).toString(\"base64\");\n // Mark content as base64 in metadata\n metadata.contentType = \"base64\";\n } else {\n // For text files, use git.show\n content = await this.git.show([`${branch}:${filePath}`]);\n }\n\n const afsPath = this.buildPath(branch, filePath);\n return {\n data: {\n id: afsPath,\n path: afsPath,\n content,\n metadata,\n },\n };\n } catch (error) {\n return {\n data: undefined,\n message: (error as Error).message,\n };\n }\n }\n\n async write(\n path: string,\n entry: AFSWriteEntryPayload,\n options?: AFSWriteOptions,\n ): Promise<AFSWriteResult> {\n await this.ready();\n const { branch, filePath } = this.parsePath(path);\n\n if (!branch || !filePath) {\n throw new Error(\"Cannot write to root or branch root\");\n }\n\n // Create worktree for write operations\n const worktreePath = await this.ensureWorktree(branch);\n const fullPath = join(worktreePath, filePath);\n const append = options?.append ?? false;\n\n // Ensure parent directory exists\n const parentDir = dirname(fullPath);\n await mkdir(parentDir, { recursive: true });\n\n // Write content\n if (entry.content !== undefined) {\n let contentToWrite: string;\n if (typeof entry.content === \"string\") {\n contentToWrite = entry.content;\n } else {\n contentToWrite = JSON.stringify(entry.content, null, 2);\n }\n await writeFile(fullPath, contentToWrite, { encoding: \"utf8\", flag: append ? \"a\" : \"w\" });\n }\n\n // Auto commit if enabled\n if (this.options.autoCommit) {\n const gitInstance = simpleGit(worktreePath);\n await gitInstance.add(filePath);\n\n if (this.options.commitAuthor) {\n await gitInstance.addConfig(\n \"user.name\",\n this.options.commitAuthor.name,\n undefined,\n \"local\",\n );\n await gitInstance.addConfig(\n \"user.email\",\n this.options.commitAuthor.email,\n undefined,\n \"local\",\n );\n }\n\n await gitInstance.commit(`Update ${filePath}`);\n }\n\n // Get file stats\n const stats = await stat(fullPath);\n\n const afsPath = this.buildPath(branch, filePath);\n const writtenEntry: AFSEntry = {\n id: afsPath,\n path: afsPath,\n content: entry.content,\n summary: entry.summary,\n createdAt: stats.birthtime,\n updatedAt: stats.mtime,\n metadata: {\n ...entry.metadata,\n type: stats.isDirectory() ? \"directory\" : \"file\",\n size: stats.size,\n },\n userId: entry.userId,\n sessionId: entry.sessionId,\n linkTo: entry.linkTo,\n };\n\n return { data: writtenEntry };\n }\n\n async delete(path: string, options?: AFSDeleteOptions): Promise<AFSDeleteResult> {\n await this.ready();\n const { branch, filePath } = this.parsePath(path);\n\n if (!branch || !filePath) {\n throw new Error(\"Cannot delete root or branch root\");\n }\n\n // Create worktree for delete operations\n const worktreePath = await this.ensureWorktree(branch);\n const fullPath = join(worktreePath, filePath);\n const recursive = options?.recursive ?? false;\n\n const stats = await stat(fullPath);\n\n if (stats.isDirectory() && !recursive) {\n throw new Error(\n `Cannot delete directory '${path}' without recursive option. Set recursive: true to delete directories.`,\n );\n }\n\n await rm(fullPath, { recursive, force: true });\n\n // Auto commit if enabled\n if (this.options.autoCommit) {\n const gitInstance = simpleGit(worktreePath);\n await gitInstance.add(filePath);\n\n if (this.options.commitAuthor) {\n await gitInstance.addConfig(\n \"user.name\",\n this.options.commitAuthor.name,\n undefined,\n \"local\",\n );\n await gitInstance.addConfig(\n \"user.email\",\n this.options.commitAuthor.email,\n undefined,\n \"local\",\n );\n }\n\n await gitInstance.commit(`Delete ${filePath}`);\n }\n\n return { message: `Successfully deleted: ${path}` };\n }\n\n async rename(\n oldPath: string,\n newPath: string,\n options?: AFSRenameOptions,\n ): Promise<{ message?: string }> {\n await this.ready();\n const { branch: oldBranch, filePath: oldFilePath } = this.parsePath(oldPath);\n const { branch: newBranch, filePath: newFilePath } = this.parsePath(newPath);\n\n if (!oldBranch || !oldFilePath) {\n throw new Error(\"Cannot rename from root or branch root\");\n }\n\n if (!newBranch || !newFilePath) {\n throw new Error(\"Cannot rename to root or branch root\");\n }\n\n if (oldBranch !== newBranch) {\n throw new Error(\"Cannot rename across branches\");\n }\n\n // Create worktree for rename operations\n const worktreePath = await this.ensureWorktree(oldBranch);\n const oldFullPath = join(worktreePath, oldFilePath);\n const newFullPath = join(worktreePath, newFilePath);\n const overwrite = options?.overwrite ?? false;\n\n // Check if source exists\n await stat(oldFullPath);\n\n // Check if destination exists\n try {\n await stat(newFullPath);\n if (!overwrite) {\n throw new Error(\n `Destination '${newPath}' already exists. Set overwrite: true to replace it.`,\n );\n }\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw error;\n }\n }\n\n // Ensure parent directory exists\n const newParentDir = dirname(newFullPath);\n await mkdir(newParentDir, { recursive: true });\n\n // Perform rename\n await rename(oldFullPath, newFullPath);\n\n // Auto commit if enabled\n if (this.options.autoCommit) {\n const gitInstance = simpleGit(worktreePath);\n await gitInstance.add([oldFilePath, newFilePath]);\n\n if (this.options.commitAuthor) {\n await gitInstance.addConfig(\n \"user.name\",\n this.options.commitAuthor.name,\n undefined,\n \"local\",\n );\n await gitInstance.addConfig(\n \"user.email\",\n this.options.commitAuthor.email,\n undefined,\n \"local\",\n );\n }\n\n await gitInstance.commit(`Rename ${oldFilePath} to ${newFilePath}`);\n }\n\n return { message: `Successfully renamed '${oldPath}' to '${newPath}'` };\n }\n\n async search(path: string, query: string, options?: AFSSearchOptions): Promise<AFSSearchResult> {\n await this.ready();\n const { branch, filePath } = this.parsePath(path);\n\n if (!branch) {\n return { data: [], message: \"Search requires a branch path\" };\n }\n\n const limit = Math.min(options?.limit || LIST_MAX_LIMIT, LIST_MAX_LIMIT);\n\n try {\n // Use git grep for searching (no worktree needed)\n const args = [\"grep\", \"-n\", \"-I\"]; // -n for line numbers, -I to skip binary files\n\n if (options?.caseSensitive === false) {\n args.push(\"-i\");\n }\n\n args.push(query, branch);\n\n // Add path filter if specified\n if (filePath) {\n args.push(\"--\", filePath);\n }\n\n const output = await this.git.raw(args);\n const lines = output.split(\"\\n\").filter((line) => line.trim());\n\n const entries: AFSEntry[] = [];\n const processedFiles = new Set<string>();\n\n for (const line of lines) {\n // Format when searching in branch: branch:path:linenum:content\n // Try the format with branch prefix first\n let matchPath: string;\n let lineNum: string;\n let content: string;\n\n const matchWithBranch = line.match(/^[^:]+:([^:]+):(\\d+):(.+)$/);\n if (matchWithBranch) {\n matchPath = matchWithBranch[1]!;\n lineNum = matchWithBranch[2]!;\n content = matchWithBranch[3]!;\n } else {\n // Try format without branch: path:linenum:content\n const matchNoBranch = line.match(/^([^:]+):(\\d+):(.+)$/);\n if (!matchNoBranch) continue;\n matchPath = matchNoBranch[1]!;\n lineNum = matchNoBranch[2]!;\n content = matchNoBranch[3]!;\n }\n\n const afsPath = this.buildPath(branch, matchPath);\n\n if (processedFiles.has(afsPath)) continue;\n processedFiles.add(afsPath);\n\n entries.push({\n id: afsPath,\n path: afsPath,\n summary: `Line ${lineNum}: ${content}`,\n metadata: {\n type: \"file\",\n },\n });\n\n if (entries.length >= limit) {\n break;\n }\n }\n\n return {\n data: entries,\n message: entries.length >= limit ? `Results truncated to limit ${limit}` : undefined,\n };\n } catch (error) {\n // git grep returns exit code 1 if no matches found\n if ((error as Error).message.includes(\"did not match any file(s)\")) {\n return { data: [] };\n }\n return { data: [], message: (error as Error).message };\n }\n }\n\n /**\n * Fetch latest changes from remote\n */\n async fetch(): Promise<void> {\n await this.ready();\n await this.git.fetch();\n }\n\n /**\n * Pull latest changes from remote for current branch\n */\n async pull(): Promise<void> {\n await this.ready();\n await this.git.pull();\n }\n\n /**\n * Push local changes to remote\n */\n async push(branch?: string): Promise<void> {\n await this.ready();\n if (branch) {\n await this.git.push(\"origin\", branch);\n } else {\n await this.git.push();\n }\n }\n\n /**\n * Cleanup all worktrees (useful when unmounting)\n */\n async cleanup(): Promise<void> {\n await this.ready();\n for (const [_branch, worktreePath] of this.worktrees) {\n try {\n await this.git.raw([\"worktree\", \"remove\", worktreePath, \"--force\"]);\n } catch (_error) {\n // Ignore errors during cleanup\n }\n }\n this.worktrees.clear();\n\n // Remove temp directory\n try {\n await rm(this.tempBase, { recursive: true, force: true });\n } catch {\n // Ignore errors\n }\n\n // Cleanup cloned repository if auto-cloned and autoCleanup enabled\n const autoCleanup = this.options.autoCleanup ?? true;\n if (this.isAutoCloned && autoCleanup && this.clonedPath) {\n try {\n await rm(this.clonedPath, { recursive: true, force: true });\n } catch {\n // Ignore cleanup errors\n }\n }\n }\n}\n\nconst _typeCheck: AFSModuleClass<AFSGit, AFSGitOptions> = AFSGit;\n"],"mappings":";;;;;;;;;;;AA6BA,MAAM,iBAAiB;AAEvB,MAAM,gBAAgB,UAAU,SAAS;AAuEzC,MAAM,sBAAsB,SAC1B,EACG,OAAO;CAC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AAClB,MAAI,OACF,OAAM,KAAK,IAAI,KAAK,UAAU,OAAO;MAErC,OAAM,KAAK,IAAI,MAAM;;;;;CAOzB,MAAM,UAAyB;AAC7B,QAAM,KAAK,OAAO;AAClB,OAAK,MAAM,CAAC,SAAS,iBAAiB,KAAK,UACzC,KAAI;AACF,SAAM,KAAK,IAAI,IAAI;IAAC;IAAY;IAAU;IAAc;IAAU,CAAC;WAC5D,QAAQ;AAInB,OAAK,UAAU,OAAO;AAGtB,MAAI;AACF,SAAM,GAAG,KAAK,UAAU;IAAE,WAAW;IAAM,OAAO;IAAM,CAAC;UACnD;EAKR,MAAM,cAAc,KAAK,QAAQ,eAAe;AAChD,MAAI,KAAK,gBAAgB,eAAe,KAAK,WAC3C,KAAI;AACF,SAAM,GAAG,KAAK,YAAY;IAAE,WAAW;IAAM,OAAO;IAAM,CAAC;UACrD"}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@aigne/afs-git",
3
- "version": "1.11.0-beta",
3
+ "version": "1.11.0-beta.1",
4
4
  "description": "AIGNE AFS module for git storage",
5
- "license": "Elastic-2.0",
5
+ "license": "UNLICENSED",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
@@ -35,7 +35,7 @@
35
35
  "dependencies": {
36
36
  "simple-git": "^3.27.0",
37
37
  "zod": "^3.25.67",
38
- "@aigne/afs": "^1.11.0-beta"
38
+ "@aigne/afs": "^1.11.0-beta.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/bun": "^1.3.6",