@catamorphic/git 0.1.0-alpha.38 → 0.1.0-alpha.41

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,170 @@
1
+ import type { DraftChange } from "./origin-draft.js";
2
+ /**
3
+ * Saving a sandbox's workspace (ADRs 0343, 0344). The sandbox packs the
4
+ * files that changed since the last save, with a manifest naming each path,
5
+ * its Git mode and its blob, and the commits its branch gained, into one
6
+ * Git pack. Everything read here came from the sandbox and is treated as
7
+ * hostile: the pack is indexed in a repository of its own that is thrown
8
+ * away, every path and every tree entry is checked before anything is
9
+ * written, and no write ever follows a link.
10
+ */
11
+ /** A save that was refused, or whose pack or manifest could not be read. */
12
+ export declare class WorkspaceSaveError extends Error {
13
+ constructor(message: string, options?: ErrorOptions);
14
+ }
15
+ /** One change of a save: a deletion, a file with its mode, or a link. */
16
+ export type SavedChange = {
17
+ path: string;
18
+ kind: "deleted";
19
+ } | {
20
+ path: string;
21
+ kind: "file";
22
+ mode: "100644" | "100755";
23
+ oid: string;
24
+ } | {
25
+ path: string;
26
+ kind: "link";
27
+ oid: string;
28
+ };
29
+ /**
30
+ * Refuse a path a save may never name: one that is absolute, leaves the
31
+ * checkout, or passes through a Git directory. Git writes none of these
32
+ * into a tree, so a manifest holding one was not made by Git.
33
+ */
34
+ export declare function assertSavedPath(filePath: string): void;
35
+ /**
36
+ * Read a save's manifest: the NUL-separated records of
37
+ * `git diff-tree -r --no-renames --raw --no-abbrev -z` between the last
38
+ * saved tree and the snapshot. Throws {@link WorkspaceSaveError} for a
39
+ * record Git would not write or a path a save may not name. Nested
40
+ * repositories (gitlinks) have no blob and are left out.
41
+ */
42
+ export declare function parseSavedChanges(manifest: Uint8Array): SavedChange[];
43
+ /**
44
+ * Refuse a tree a saved commit may not hold: an entry whose name is not one
45
+ * path segment a checkout may contain, or whose mode is not a folder, a
46
+ * file, a link or a nested repository. Git's own trees never hold one.
47
+ */
48
+ export declare function assertSavedTree(input: {
49
+ /** The tree object's raw content: `<mode> <name>NUL<id>` per entry. */
50
+ tree: Uint8Array;
51
+ /** Bytes of each entry's id: 20 (SHA-1) or 32 (SHA-256). */
52
+ idBytes: 20 | 32;
53
+ }): void;
54
+ /**
55
+ * A pack a sandbox sent, indexed in a repository of its own under the
56
+ * host's temporary directory. Native Git verifies the pack's checksum and
57
+ * every object's id as it indexes, so bytes damaged or cut short on the
58
+ * way are refused, never saved. Dispose it when the save is done.
59
+ */
60
+ export declare class ReceivedPack {
61
+ private readonly directory;
62
+ /** Bytes of an object id in the sandbox's repository. */
63
+ private readonly idBytes;
64
+ private reader;
65
+ private constructor();
66
+ /** Index the pack arriving as `chunks`, in order. */
67
+ static receive(input: {
68
+ /** The sandbox repository's object format, by its ids' length. */
69
+ objectFormat: "sha1" | "sha256";
70
+ chunks: AsyncIterable<Uint8Array>;
71
+ /**
72
+ * A repository on this machine whose objects the pack's commits may
73
+ * build on (the session's copy): read through, never written.
74
+ */
75
+ borrow?: string;
76
+ }): Promise<ReceivedPack>;
77
+ /**
78
+ * Make sure every id names a file's content in the pack, and that
79
+ * together they hold at most `maxBytes`, before anything is written.
80
+ */
81
+ assertBlobs(input: {
82
+ oids: readonly string[];
83
+ maxBytes: number;
84
+ }): Promise<void>;
85
+ /**
86
+ * Check the commits a save says its branch gained (ADR 0344), before any
87
+ * of them is kept: `head` and everything it reaches that `known` (the
88
+ * workspace's base and its last saved head) does not. Every commit must
89
+ * be here whole, with history that ends at `known`; every tree may name
90
+ * only what a checkout may hold; and together they are bounded. Returns
91
+ * the new commits, newest first.
92
+ */
93
+ assertHistory(input: {
94
+ head: string;
95
+ known: readonly string[];
96
+ maxCommits: number;
97
+ maxBytes: number;
98
+ }): Promise<{
99
+ commits: string[];
100
+ }>;
101
+ /**
102
+ * Keep checked commits (ADR 0344): `head` and what it reaches beyond
103
+ * `known`, unpacked loose into the repository at `repoPath`, so no pack
104
+ * stays there. Git checks each object and its links again as it writes.
105
+ */
106
+ unpackHistory(input: {
107
+ repoPath: string;
108
+ head: string;
109
+ known: readonly string[];
110
+ }): Promise<void>;
111
+ /**
112
+ * Build the checkpoint tree from its previous tree and checked file
113
+ * changes. Git's private index keeps paths, modes and bytes without
114
+ * re-reading a host working tree or applying a second set of filters.
115
+ */
116
+ snapshotTree(input: {
117
+ repoPath: string;
118
+ previous: string;
119
+ changes: readonly SavedChange[];
120
+ containLinks: boolean;
121
+ }): Promise<string>;
122
+ private unpack;
123
+ /** One blob's bytes, refused when larger than `maxBytes`. */
124
+ read(input: {
125
+ oid: string;
126
+ maxBytes: number;
127
+ }): Promise<Uint8Array>;
128
+ /** One object's bytes, refused when it is not of `type`. */
129
+ private readObject;
130
+ /** Stream one blob's bytes to `write`, in order. */
131
+ copy(input: {
132
+ oid: string;
133
+ write: (chunk: Uint8Array) => Promise<void>;
134
+ }): Promise<void>;
135
+ private stream;
136
+ /** The manifest blob, parsed and checked. */
137
+ changes(input: {
138
+ manifest: string;
139
+ }): Promise<SavedChange[]>;
140
+ dispose(): Promise<void>;
141
+ }
142
+ /**
143
+ * Apply a save to a checkout on this machine, exactly: each file's bytes
144
+ * and executable bit, each link as a link, each deletion. Deletions go
145
+ * first, so a file may take a folder's place and a folder a file's. Nothing
146
+ * is written outside `repoPath`: parents are real folders or the save is
147
+ * refused, and what stands at a path is removed, never opened, so a link
148
+ * saved earlier cannot redirect a later write.
149
+ */
150
+ export declare function writeSavedChanges(input: {
151
+ repoPath: string;
152
+ changes: readonly SavedChange[];
153
+ pack: ReceivedPack;
154
+ /**
155
+ * The checkout's file APIs follow links (a person's own folder): a link
156
+ * that could lead outside it is refused, so nothing read or written
157
+ * there later goes where the sandbox pointed.
158
+ */
159
+ containLinks?: boolean;
160
+ }): Promise<void>;
161
+ /**
162
+ * A save as changes to a member's draft in the origin (ADR 0191): the same
163
+ * bytes, modes and links, written as Git objects. Pass them to
164
+ * `OriginDraftRepo.write` with `replaceLinks`.
165
+ */
166
+ export declare function savedDraftChanges(input: {
167
+ changes: readonly SavedChange[];
168
+ pack: ReceivedPack;
169
+ }): Promise<DraftChange[]>;
170
+ //# sourceMappingURL=workspace-save.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace-save.d.ts","sourceRoot":"","sources":["../src/workspace-save.ts"],"names":[],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@catamorphic/git",
3
- "version": "0.1.0-alpha.38",
3
+ "version": "0.1.0-alpha.41",
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.38",
27
- "diff3": "0.0.3",
28
- "ignore": "^5.3.2",
29
- "isomorphic-git": "^1.38.6"
26
+ "@catamorphic/workflow": "0.1.0-alpha.41",
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.1.1"
32
+ "@types/node": "^26.6.6"
33
33
  },
34
34
  "license": "Apache-2.0",
35
35
  "repository": {
package/src/git-sync.ts CHANGED
@@ -37,6 +37,8 @@ export interface PushOpts {
37
37
  remoteBranch?: string;
38
38
  /** SHA on the dev side to push. Defaults to the tip of the current branch. */
39
39
  localSha?: string;
40
+ /** The published ref from which this update was prepared, when known. */
41
+ expected?: string;
40
42
  /**
41
43
  * Move the branch even when it is not a fast-forward. Only for branches
42
44
  * Work owns outright, such as a session's `sessions/<id>` whose base moved.
@@ -76,6 +78,11 @@ export async function push(opts: PushOpts): Promise<{ sha: string }> {
76
78
  return { sha: localSha };
77
79
  }
78
80
 
81
+ if (opts.expected !== undefined && currentRemote !== opts.expected)
82
+ throw new Error(
83
+ "The workspace checkpoint changed before it could be published.",
84
+ );
85
+
79
86
  if (currentRemote && !opts.force) {
80
87
  const fastForward = await isAncestor({
81
88
  dev: opts.dev,
package/src/index.ts CHANGED
@@ -23,6 +23,8 @@ export {
23
23
  cloneFromRemote,
24
24
  fetchFromRemote,
25
25
  isManagedBranch,
26
+ type PushedBranch,
27
+ pushOwnBranch,
26
28
  pushToRemote,
27
29
  type RemoteOwnership,
28
30
  RemotePushRefusedError,
@@ -76,6 +78,14 @@ export {
76
78
  InvalidRefNameError,
77
79
  isValidRefName,
78
80
  } from "./ref-names.js";
81
+ export {
82
+ currentSessionWork,
83
+ isSessionBranchName,
84
+ parseCheckpointMessage,
85
+ readSessionWork,
86
+ type SessionWork,
87
+ sessionBranchName,
88
+ } from "./session-checkpoint.js";
79
89
  export type {
80
90
  BranchInfo,
81
91
  CloneSource,
@@ -108,3 +118,13 @@ export {
108
118
  unpinMirrorRef,
109
119
  type WorkspaceBase,
110
120
  } from "./workspace-mirror.js";
121
+ export {
122
+ assertSavedPath,
123
+ assertSavedTree,
124
+ parseSavedChanges,
125
+ ReceivedPack,
126
+ type SavedChange,
127
+ savedDraftChanges,
128
+ WorkspaceSaveError,
129
+ writeSavedChanges,
130
+ } from "./workspace-save.js";
@@ -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: await this.listFiles(),
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 files = await walkDirectory(this.repoPath, this.repoPath, {
72
- includeHidden: true,
73
- excludeNestedRepositories: true,
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.readAllFiles({
119
- filter: (file) =>
120
- includes.some((glob) => matches(file, glob)) &&
121
- !excludes.some((glob) => matches(file, glob)),
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);