@aigne/afs-git 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,129 @@
1
+ import type { AFSAccessMode, AFSDeleteOptions, AFSDeleteResult, AFSListOptions, AFSListResult, AFSModule, AFSModuleLoadParams, AFSReadOptions, AFSReadResult, AFSRenameOptions, AFSSearchOptions, AFSSearchResult, AFSWriteEntryPayload, AFSWriteOptions, AFSWriteResult } from "@aigne/afs";
2
+ import { z } from "zod";
3
+ export interface AFSGitOptions {
4
+ name?: string;
5
+ repoPath: string;
6
+ description?: string;
7
+ branches?: string[];
8
+ /**
9
+ * Access mode for this module.
10
+ * - "readonly": Only read operations are allowed, uses git commands (no worktree)
11
+ * - "readwrite": All operations are allowed, creates worktrees as needed
12
+ * @default "readonly"
13
+ */
14
+ accessMode?: AFSAccessMode;
15
+ /**
16
+ * Automatically commit changes after write operations
17
+ * @default false
18
+ */
19
+ autoCommit?: boolean;
20
+ /**
21
+ * Author information for commits when autoCommit is enabled
22
+ */
23
+ commitAuthor?: {
24
+ name: string;
25
+ email: string;
26
+ };
27
+ }
28
+ export declare class AFSGit implements AFSModule {
29
+ options: AFSGitOptions & {
30
+ cwd?: string;
31
+ };
32
+ static schema(): z.ZodObject<{
33
+ name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
34
+ repoPath: z.ZodString;
35
+ description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
36
+ branches: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
37
+ accessMode: z.ZodType<"readonly" | "readwrite" | undefined, z.ZodTypeDef, "readonly" | "readwrite" | undefined>;
38
+ autoCommit: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
39
+ commitAuthor: z.ZodType<{
40
+ name: string;
41
+ email: string;
42
+ } | undefined, z.ZodTypeDef, {
43
+ name: string;
44
+ email: string;
45
+ } | undefined>;
46
+ }, "strip", z.ZodTypeAny, {
47
+ repoPath: string;
48
+ name?: string | undefined;
49
+ description?: string | undefined;
50
+ branches?: string[] | undefined;
51
+ accessMode?: "readonly" | "readwrite" | undefined;
52
+ autoCommit?: boolean | undefined;
53
+ commitAuthor?: {
54
+ name: string;
55
+ email: string;
56
+ } | undefined;
57
+ }, {
58
+ repoPath: string;
59
+ name?: string | undefined;
60
+ description?: string | undefined;
61
+ branches?: string[] | undefined;
62
+ accessMode?: "readonly" | "readwrite" | undefined;
63
+ autoCommit?: boolean | undefined;
64
+ commitAuthor?: {
65
+ name: string;
66
+ email: string;
67
+ } | undefined;
68
+ }>;
69
+ static load({ filepath, parsed }: AFSModuleLoadParams): Promise<AFSGit>;
70
+ private git;
71
+ private tempBase;
72
+ private worktrees;
73
+ private repoHash;
74
+ constructor(options: AFSGitOptions & {
75
+ cwd?: string;
76
+ });
77
+ name: string;
78
+ description?: string;
79
+ accessMode: AFSAccessMode;
80
+ /**
81
+ * Parse AFS path into branch and file path
82
+ * Branch names may contain slashes and are encoded with ~ in paths
83
+ * Examples:
84
+ * "/" -> { branch: undefined, filePath: "" }
85
+ * "/main" -> { branch: "main", filePath: "" }
86
+ * "/feature~new-feature" -> { branch: "feature/new-feature", filePath: "" }
87
+ * "/main/src/index.ts" -> { branch: "main", filePath: "src/index.ts" }
88
+ */
89
+ private parsePath;
90
+ /**
91
+ * Detect MIME type based on file extension
92
+ */
93
+ private getMimeType;
94
+ /**
95
+ * Check if file is likely binary based on extension
96
+ */
97
+ private isBinaryFile;
98
+ /**
99
+ * Get list of available branches
100
+ */
101
+ private getBranches;
102
+ /**
103
+ * Ensure worktree exists for a branch (lazy creation)
104
+ */
105
+ private ensureWorktree;
106
+ /**
107
+ * List files using git ls-tree (no worktree needed)
108
+ */
109
+ private listWithGitLsTree;
110
+ /**
111
+ * Build AFS path with encoded branch name
112
+ * Branch names with slashes are encoded by replacing / with ~
113
+ * @param branch Branch name (may contain slashes)
114
+ * @param filePath File path within branch
115
+ */
116
+ private buildPath;
117
+ list(path: string, options?: AFSListOptions): Promise<AFSListResult>;
118
+ read(path: string, _options?: AFSReadOptions): Promise<AFSReadResult>;
119
+ write(path: string, entry: AFSWriteEntryPayload, options?: AFSWriteOptions): Promise<AFSWriteResult>;
120
+ delete(path: string, options?: AFSDeleteOptions): Promise<AFSDeleteResult>;
121
+ rename(oldPath: string, newPath: string, options?: AFSRenameOptions): Promise<{
122
+ message?: string;
123
+ }>;
124
+ search(path: string, query: string, options?: AFSSearchOptions): Promise<AFSSearchResult>;
125
+ /**
126
+ * Cleanup all worktrees (useful when unmounting)
127
+ */
128
+ cleanup(): Promise<void>;
129
+ }
@@ -0,0 +1,129 @@
1
+ import type { AFSAccessMode, AFSDeleteOptions, AFSDeleteResult, AFSListOptions, AFSListResult, AFSModule, AFSModuleLoadParams, AFSReadOptions, AFSReadResult, AFSRenameOptions, AFSSearchOptions, AFSSearchResult, AFSWriteEntryPayload, AFSWriteOptions, AFSWriteResult } from "@aigne/afs";
2
+ import { z } from "zod";
3
+ export interface AFSGitOptions {
4
+ name?: string;
5
+ repoPath: string;
6
+ description?: string;
7
+ branches?: string[];
8
+ /**
9
+ * Access mode for this module.
10
+ * - "readonly": Only read operations are allowed, uses git commands (no worktree)
11
+ * - "readwrite": All operations are allowed, creates worktrees as needed
12
+ * @default "readonly"
13
+ */
14
+ accessMode?: AFSAccessMode;
15
+ /**
16
+ * Automatically commit changes after write operations
17
+ * @default false
18
+ */
19
+ autoCommit?: boolean;
20
+ /**
21
+ * Author information for commits when autoCommit is enabled
22
+ */
23
+ commitAuthor?: {
24
+ name: string;
25
+ email: string;
26
+ };
27
+ }
28
+ export declare class AFSGit implements AFSModule {
29
+ options: AFSGitOptions & {
30
+ cwd?: string;
31
+ };
32
+ static schema(): z.ZodObject<{
33
+ name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
34
+ repoPath: z.ZodString;
35
+ description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
36
+ branches: z.ZodType<string[] | undefined, z.ZodTypeDef, string[] | undefined>;
37
+ accessMode: z.ZodType<"readonly" | "readwrite" | undefined, z.ZodTypeDef, "readonly" | "readwrite" | undefined>;
38
+ autoCommit: z.ZodType<boolean | undefined, z.ZodTypeDef, boolean | undefined>;
39
+ commitAuthor: z.ZodType<{
40
+ name: string;
41
+ email: string;
42
+ } | undefined, z.ZodTypeDef, {
43
+ name: string;
44
+ email: string;
45
+ } | undefined>;
46
+ }, "strip", z.ZodTypeAny, {
47
+ repoPath: string;
48
+ name?: string | undefined;
49
+ description?: string | undefined;
50
+ branches?: string[] | undefined;
51
+ accessMode?: "readonly" | "readwrite" | undefined;
52
+ autoCommit?: boolean | undefined;
53
+ commitAuthor?: {
54
+ name: string;
55
+ email: string;
56
+ } | undefined;
57
+ }, {
58
+ repoPath: string;
59
+ name?: string | undefined;
60
+ description?: string | undefined;
61
+ branches?: string[] | undefined;
62
+ accessMode?: "readonly" | "readwrite" | undefined;
63
+ autoCommit?: boolean | undefined;
64
+ commitAuthor?: {
65
+ name: string;
66
+ email: string;
67
+ } | undefined;
68
+ }>;
69
+ static load({ filepath, parsed }: AFSModuleLoadParams): Promise<AFSGit>;
70
+ private git;
71
+ private tempBase;
72
+ private worktrees;
73
+ private repoHash;
74
+ constructor(options: AFSGitOptions & {
75
+ cwd?: string;
76
+ });
77
+ name: string;
78
+ description?: string;
79
+ accessMode: AFSAccessMode;
80
+ /**
81
+ * Parse AFS path into branch and file path
82
+ * Branch names may contain slashes and are encoded with ~ in paths
83
+ * Examples:
84
+ * "/" -> { branch: undefined, filePath: "" }
85
+ * "/main" -> { branch: "main", filePath: "" }
86
+ * "/feature~new-feature" -> { branch: "feature/new-feature", filePath: "" }
87
+ * "/main/src/index.ts" -> { branch: "main", filePath: "src/index.ts" }
88
+ */
89
+ private parsePath;
90
+ /**
91
+ * Detect MIME type based on file extension
92
+ */
93
+ private getMimeType;
94
+ /**
95
+ * Check if file is likely binary based on extension
96
+ */
97
+ private isBinaryFile;
98
+ /**
99
+ * Get list of available branches
100
+ */
101
+ private getBranches;
102
+ /**
103
+ * Ensure worktree exists for a branch (lazy creation)
104
+ */
105
+ private ensureWorktree;
106
+ /**
107
+ * List files using git ls-tree (no worktree needed)
108
+ */
109
+ private listWithGitLsTree;
110
+ /**
111
+ * Build AFS path with encoded branch name
112
+ * Branch names with slashes are encoded by replacing / with ~
113
+ * @param branch Branch name (may contain slashes)
114
+ * @param filePath File path within branch
115
+ */
116
+ private buildPath;
117
+ list(path: string, options?: AFSListOptions): Promise<AFSListResult>;
118
+ read(path: string, _options?: AFSReadOptions): Promise<AFSReadResult>;
119
+ write(path: string, entry: AFSWriteEntryPayload, options?: AFSWriteOptions): Promise<AFSWriteResult>;
120
+ delete(path: string, options?: AFSDeleteOptions): Promise<AFSDeleteResult>;
121
+ rename(oldPath: string, newPath: string, options?: AFSRenameOptions): Promise<{
122
+ message?: string;
123
+ }>;
124
+ search(path: string, query: string, options?: AFSSearchOptions): Promise<AFSSearchResult>;
125
+ /**
126
+ * Cleanup all worktrees (useful when unmounting)
127
+ */
128
+ cleanup(): Promise<void>;
129
+ }