@catamorphic/git 0.1.0-alpha.38 → 0.1.0-alpha.39
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/dist/index.js +107 -17
- package/dist/index.js.map +5 -5
- package/dist/native-project-repo.d.ts +1 -0
- package/dist/native-project-repo.d.ts.map +1 -1
- package/dist/project-manager.d.ts +1 -1
- package/dist/project-repo.d.ts +2 -0
- package/dist/project-repo.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/native-project-repo.ts +148 -16
- package/src/project-manager.ts +1 -1
- package/src/project-repo.ts +8 -2
|
@@ -6,6 +6,7 @@ export declare class NativeProjectRepo extends ProjectRepoImpl {
|
|
|
6
6
|
protected readonly followsSymlinks = true;
|
|
7
7
|
readFileBytes(filePath: string): Promise<Uint8Array | null>;
|
|
8
8
|
readAllFiles(options?: FileReadOptions): Promise<Record<string, string>>;
|
|
9
|
+
private readSnapshot;
|
|
9
10
|
listFiles(opts?: {
|
|
10
11
|
prefix?: string;
|
|
11
12
|
}): Promise<string[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-project-repo.d.ts","sourceRoot":"","sources":["../src/native-project-repo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"native-project-repo.d.ts","sourceRoot":"","sources":["../src/native-project-repo.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,eAAe,EAAoB,MAAM,iBAAiB,CAAC;AAMzE,OAAO,EAEL,eAAe,EAGhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAiIhF,uGAAuG;AACvG,qBAAa,iBAAkB,SAAQ,eAAe;IACpD,mBAA4B,eAAe,QAAQ;IAEpC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAqBzE;IAEc,YA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;CA4BpC"}
|
|
@@ -3,7 +3,7 @@ import type { DraftSupport, GitCredentials, ProjectPathResolver, ProjectRepo, Re
|
|
|
3
3
|
import { type BaseMoveOutcome } from "./workspace-mirror.js";
|
|
4
4
|
/**
|
|
5
5
|
* Seeded into every new project (unless one exists): mirrors the
|
|
6
|
-
* checkpoint walker's
|
|
6
|
+
* checkpoint walker's WALK_SKIPPED_DIRS so git status and the walker agree on
|
|
7
7
|
* what a project's history never contains.
|
|
8
8
|
*/
|
|
9
9
|
export declare const PROJECT_GITIGNORE = "/app-data/\nnode_modules/\ndist/\n.turbo/\n.DS_Store\n";
|
package/dist/project-repo.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type Ignore } from "ignore";
|
|
2
2
|
import { type FileReadOptions } from "./file-reads.js";
|
|
3
3
|
import type { BranchInfo, CommitInfo, DiffEntry, ProjectRepo, RepoStatus } from "./types.js";
|
|
4
|
+
/** Directories a walk never enters. */
|
|
5
|
+
export declare const WALK_SKIPPED_DIRS: ReadonlySet<string>;
|
|
4
6
|
export declare function assertSafePath(filePath: string): void;
|
|
5
7
|
export declare function walkDirectory(dir: string, base: string, options?: {
|
|
6
8
|
excludeNestedRepositories?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project-repo.d.ts","sourceRoot":"","sources":["../src/project-repo.ts"],"names":[],"mappings":"AAOA,OAAe,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE7C,OAAO,EAAE,KAAK,eAAe,EAAoB,MAAM,iBAAiB,CAAC;AAGzE,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACX,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"project-repo.d.ts","sourceRoot":"","sources":["../src/project-repo.ts"],"names":[],"mappings":"AAOA,OAAe,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE7C,OAAO,EAAE,KAA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,CAAC,SAAS,EAAE,CAAC,CA+DrE;IAEK,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQzD;IAEK,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAkBtC;IAEK,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAE7B;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@catamorphic/git",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.39",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -23,13 +23,13 @@
|
|
|
23
23
|
]
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@catamorphic/workflow": "0.1.0-alpha.
|
|
27
|
-
"diff3": "0.0.
|
|
28
|
-
"ignore": "^
|
|
29
|
-
"isomorphic-git": "^1.
|
|
26
|
+
"@catamorphic/workflow": "0.1.0-alpha.39",
|
|
27
|
+
"diff3": "0.0.4",
|
|
28
|
+
"ignore": "^7.0.14",
|
|
29
|
+
"isomorphic-git": "^1.44.12"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "^26.
|
|
32
|
+
"@types/node": "^26.6.6"
|
|
33
33
|
},
|
|
34
34
|
"license": "Apache-2.0",
|
|
35
35
|
"repository": {
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
PROJECT_PERSONAL_DIR,
|
|
6
6
|
publishedRef,
|
|
7
7
|
} from "@catamorphic/workflow/project-layout";
|
|
8
|
+
import ignore, { type Ignore } from "ignore";
|
|
8
9
|
import { type FileReadOptions, readFileSnapshot } from "./file-reads.js";
|
|
9
10
|
import { hasLocalGit, nativeGit, nativeGitBytes } from "./native-git.js";
|
|
10
11
|
import {
|
|
@@ -14,10 +15,138 @@ import {
|
|
|
14
15
|
import {
|
|
15
16
|
assertSafePath,
|
|
16
17
|
ProjectRepoImpl,
|
|
18
|
+
WALK_SKIPPED_DIRS,
|
|
17
19
|
walkDirectory,
|
|
18
20
|
} from "./project-repo.js";
|
|
19
21
|
import type { BranchInfo, CommitInfo, DiffEntry, RepoStatus } from "./types.js";
|
|
20
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Walks of folders without Git, by root and folder: the one running and the
|
|
25
|
+
* one queued behind it. A new chat asks for the same listing from several
|
|
26
|
+
* services at once (agents, skills, apps, workflows). A caller never shares
|
|
27
|
+
* a walk that started before it asked, so it sees every file written before
|
|
28
|
+
* its call; callers arriving during a walk share the single next one.
|
|
29
|
+
*/
|
|
30
|
+
interface UnversionedWalk {
|
|
31
|
+
running: Promise<string[]>;
|
|
32
|
+
queued: Promise<string[]> | null;
|
|
33
|
+
}
|
|
34
|
+
const unversionedWalks = new Map<string, UnversionedWalk>();
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Every file under `folder` (relative, `""` for the whole tree, else ending
|
|
38
|
+
* in `/`) of a folder without Git, as a whole-tree walk would list them:
|
|
39
|
+
* nothing under an ignored directory or a nested repository on the way.
|
|
40
|
+
*/
|
|
41
|
+
function walkUnversioned(root: string, folder: string): Promise<string[]> {
|
|
42
|
+
const key = `${root}\0${folder}`;
|
|
43
|
+
const current = unversionedWalks.get(key);
|
|
44
|
+
if (!current) return startWalk(key, root, folder);
|
|
45
|
+
current.queued ??= current.running
|
|
46
|
+
.catch(() => {})
|
|
47
|
+
.then(() => startWalk(key, root, folder));
|
|
48
|
+
return current.queued;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function startWalk(
|
|
52
|
+
key: string,
|
|
53
|
+
root: string,
|
|
54
|
+
folder: string,
|
|
55
|
+
): Promise<string[]> {
|
|
56
|
+
const entry: UnversionedWalk = {
|
|
57
|
+
running: walkFolder(root, folder),
|
|
58
|
+
queued: null,
|
|
59
|
+
};
|
|
60
|
+
unversionedWalks.set(key, entry);
|
|
61
|
+
void entry.running
|
|
62
|
+
.finally(() => {
|
|
63
|
+
if (unversionedWalks.get(key) === entry) unversionedWalks.delete(key);
|
|
64
|
+
})
|
|
65
|
+
.catch(() => {});
|
|
66
|
+
return entry.running;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function walkFolder(root: string, folder: string): Promise<string[]> {
|
|
70
|
+
const rules: Array<{ base: string; matcher: Ignore }> = [];
|
|
71
|
+
const options = {
|
|
72
|
+
includeHidden: true,
|
|
73
|
+
excludeNestedRepositories: true,
|
|
74
|
+
tracked: new Set<string>(),
|
|
75
|
+
trackedDirectories: new Set<string>(),
|
|
76
|
+
rules,
|
|
77
|
+
};
|
|
78
|
+
// A missing project folder fails as the whole-tree walk does.
|
|
79
|
+
if (!folder || !(await fs.stat(root)).isDirectory())
|
|
80
|
+
return walkDirectory(root, root, options);
|
|
81
|
+
// What the whole-tree walk would decide on the way down to `folder`:
|
|
82
|
+
// its ignore rules, ignored and private directories, nested repositories.
|
|
83
|
+
// A folder it would never reach, or that does not exist, lists nothing.
|
|
84
|
+
let current = root;
|
|
85
|
+
for (const segment of folder.slice(0, -1).split("/")) {
|
|
86
|
+
if (!segment || segment === "." || segment === "..") return [];
|
|
87
|
+
const content = await fs
|
|
88
|
+
.readFile(path.join(current, ".gitignore"), "utf8")
|
|
89
|
+
.catch(() => "");
|
|
90
|
+
if (content) rules.push({ base: current, matcher: ignore().add(content) });
|
|
91
|
+
const next = path.join(current, segment);
|
|
92
|
+
if (
|
|
93
|
+
WALK_SKIPPED_DIRS.has(segment) ||
|
|
94
|
+
isPersonalFile(path.relative(root, next)) ||
|
|
95
|
+
isIgnoredDirectory(rules, next)
|
|
96
|
+
)
|
|
97
|
+
return [];
|
|
98
|
+
// The whole-tree walk lists a linked folder as an entry, never its files.
|
|
99
|
+
const stat = await fs.lstat(next).catch(() => undefined);
|
|
100
|
+
if (!stat?.isDirectory()) return [];
|
|
101
|
+
current = next;
|
|
102
|
+
if (
|
|
103
|
+
await fs.stat(path.join(current, ".git")).then(
|
|
104
|
+
() => true,
|
|
105
|
+
() => false,
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
// Errors inside the folder propagate, as from a whole-tree walk.
|
|
111
|
+
return walkDirectory(current, root, options);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function isIgnoredDirectory(
|
|
115
|
+
rules: ReadonlyArray<{ base: string; matcher: Ignore }>,
|
|
116
|
+
directory: string,
|
|
117
|
+
): boolean {
|
|
118
|
+
let ignored = false;
|
|
119
|
+
for (const rule of rules) {
|
|
120
|
+
const result = rule.matcher.test(`${path.relative(rule.base, directory)}/`);
|
|
121
|
+
if (result.ignored) ignored = true;
|
|
122
|
+
if (result.unignored) ignored = false;
|
|
123
|
+
}
|
|
124
|
+
return ignored;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The deepest folder a path prefix names entirely: `a/b/` for `a/b/c`. */
|
|
128
|
+
function folderOf(prefix: string): string {
|
|
129
|
+
const cut = prefix.lastIndexOf("/");
|
|
130
|
+
return cut < 0 ? "" : prefix.slice(0, cut + 1);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** The folder every glob starts in before its first wildcard, or `""`. */
|
|
134
|
+
function literalFolder(globs: readonly string[]): string {
|
|
135
|
+
const folders = globs.map((glob) => {
|
|
136
|
+
const wild = glob.search(/[*?[{]/);
|
|
137
|
+
return folderOf(wild < 0 ? glob : glob.slice(0, wild));
|
|
138
|
+
});
|
|
139
|
+
if (folders.length === 0) return "";
|
|
140
|
+
return folders.reduce((common, folder) => {
|
|
141
|
+
let end = 0;
|
|
142
|
+
for (let i = 0; i < Math.min(common.length, folder.length); i++) {
|
|
143
|
+
if (common[i] !== folder[i]) break;
|
|
144
|
+
if (common[i] === "/") end = i + 1;
|
|
145
|
+
}
|
|
146
|
+
return common.slice(0, end);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
21
150
|
/** Local-checkout adapter. File IO stays shared; Git honors the user's repository format and tools. */
|
|
22
151
|
export class NativeProjectRepo extends ProjectRepoImpl {
|
|
23
152
|
protected override readonly followsSymlinks = true;
|
|
@@ -47,9 +176,16 @@ export class NativeProjectRepo extends ProjectRepoImpl {
|
|
|
47
176
|
|
|
48
177
|
override async readAllFiles(
|
|
49
178
|
options: FileReadOptions = {},
|
|
179
|
+
): Promise<Record<string, string>> {
|
|
180
|
+
return this.readSnapshot(await this.listFiles(), options);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private readSnapshot(
|
|
184
|
+
paths: string[],
|
|
185
|
+
options: FileReadOptions,
|
|
50
186
|
): Promise<Record<string, string>> {
|
|
51
187
|
return readFileSnapshot({
|
|
52
|
-
paths
|
|
188
|
+
paths,
|
|
53
189
|
options: { maxFileBytes: 2 * 1024 * 1024, ...options },
|
|
54
190
|
read: async (file, maxBytes) => {
|
|
55
191
|
const stat = await fs.lstat(path.join(this.repoPath, file));
|
|
@@ -68,16 +204,9 @@ export class NativeProjectRepo extends ProjectRepoImpl {
|
|
|
68
204
|
override async listFiles(opts?: { prefix?: string }): Promise<string[]> {
|
|
69
205
|
if (!(await hasLocalGit({ path: this.repoPath }))) {
|
|
70
206
|
if (opts?.prefix) assertSafePath(opts.prefix);
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
tracked: new Set(),
|
|
75
|
-
trackedDirectories: new Set(),
|
|
76
|
-
rules: [],
|
|
77
|
-
});
|
|
78
|
-
return files
|
|
79
|
-
.filter((file) => !opts?.prefix || file.startsWith(opts.prefix))
|
|
80
|
-
.sort();
|
|
207
|
+
const prefix = opts?.prefix ?? "";
|
|
208
|
+
const files = await walkUnversioned(this.repoPath, folderOf(prefix));
|
|
209
|
+
return files.filter((file) => file.startsWith(prefix)).sort();
|
|
81
210
|
}
|
|
82
211
|
const pathspec = opts?.prefix ? ["--", opts.prefix] : [];
|
|
83
212
|
const [output, removed] = await Promise.all([
|
|
@@ -115,11 +244,14 @@ export class NativeProjectRepo extends ProjectRepoImpl {
|
|
|
115
244
|
const excludes = input.globs
|
|
116
245
|
.filter((glob) => glob.startsWith(":!"))
|
|
117
246
|
.map((glob) => glob.slice(2));
|
|
118
|
-
const files = await this.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
247
|
+
const files = await this.readSnapshot(
|
|
248
|
+
await this.listFiles({ prefix: literalFolder(includes) }),
|
|
249
|
+
{
|
|
250
|
+
filter: (file) =>
|
|
251
|
+
includes.some((glob) => matches(file, glob)) &&
|
|
252
|
+
!excludes.some((glob) => matches(file, glob)),
|
|
253
|
+
},
|
|
254
|
+
);
|
|
123
255
|
return Object.entries(files)
|
|
124
256
|
.filter(([, content]) => content.includes(input.text))
|
|
125
257
|
.map(([file]) => file);
|
package/src/project-manager.ts
CHANGED
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Seeded into every new project (unless one exists): mirrors the
|
|
38
|
-
* checkpoint walker's
|
|
38
|
+
* checkpoint walker's WALK_SKIPPED_DIRS so git status and the walker agree on
|
|
39
39
|
* what a project's history never contains.
|
|
40
40
|
*/
|
|
41
41
|
export const PROJECT_GITIGNORE = `/app-data/
|
package/src/project-repo.ts
CHANGED
|
@@ -18,7 +18,13 @@ import type {
|
|
|
18
18
|
RepoStatus,
|
|
19
19
|
} from "./types.js";
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
/** Directories a walk never enters. */
|
|
22
|
+
export const WALK_SKIPPED_DIRS: ReadonlySet<string> = new Set([
|
|
23
|
+
"node_modules",
|
|
24
|
+
".git",
|
|
25
|
+
"dist",
|
|
26
|
+
".turbo",
|
|
27
|
+
]);
|
|
22
28
|
// git.add processes array inputs concurrently, even with parallel: false.
|
|
23
29
|
// Bound file reads while amortizing full-index serialization across each batch.
|
|
24
30
|
const STAGING_BATCH_SIZE = 128;
|
|
@@ -108,7 +114,7 @@ export async function walkDirectory(
|
|
|
108
114
|
const results: string[] = [];
|
|
109
115
|
|
|
110
116
|
for (const entry of entries) {
|
|
111
|
-
if (
|
|
117
|
+
if (WALK_SKIPPED_DIRS.has(entry.name)) continue;
|
|
112
118
|
if (
|
|
113
119
|
!options?.includeHidden &&
|
|
114
120
|
entry.name.startsWith(".") &&
|