@yaks/git 0.0.0-stage → 0.2.36
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 +202 -0
- package/README.md +754 -2
- package/_dist/address.d.ts +6 -0
- package/_dist/address.d.ts.map +1 -0
- package/_dist/checkout_vocab.d.ts +3 -0
- package/_dist/checkout_vocab.d.ts.map +1 -0
- package/_dist/cites.d.ts +48 -0
- package/_dist/cites.d.ts.map +1 -0
- package/_dist/commit.d.ts +36 -0
- package/_dist/commit.d.ts.map +1 -0
- package/_dist/comp.d.ts +29 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/door.d.ts +29 -0
- package/_dist/door.d.ts.map +1 -0
- package/_dist/format.d.ts +2 -0
- package/_dist/format.d.ts.map +1 -0
- package/_dist/hold.d.ts +6 -0
- package/_dist/hold.d.ts.map +1 -0
- package/_dist/host.d.ts +126 -0
- package/_dist/host.d.ts.map +1 -0
- package/_dist/http.d.ts +33 -0
- package/_dist/http.d.ts.map +1 -0
- package/_dist/import.d.ts +13 -0
- package/_dist/import.d.ts.map +1 -0
- package/_dist/index.d.ts +80 -0
- package/_dist/index.d.ts.map +1 -0
- package/_dist/land.d.ts +77 -0
- package/_dist/land.d.ts.map +1 -0
- package/_dist/mod.d.ts +73 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/objects.d.ts +40 -0
- package/_dist/objects.d.ts.map +1 -0
- package/_dist/oid.d.ts +24 -0
- package/_dist/oid.d.ts.map +1 -0
- package/_dist/pack-store.d.ts +9 -0
- package/_dist/pack-store.d.ts.map +1 -0
- package/_dist/pack.d.ts +26 -0
- package/_dist/pack.d.ts.map +1 -0
- package/_dist/pkt.d.ts +14 -0
- package/_dist/pkt.d.ts.map +1 -0
- package/_dist/placement.d.ts +4 -0
- package/_dist/placement.d.ts.map +1 -0
- package/_dist/plugin.d.ts +43 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/project.d.ts +20 -0
- package/_dist/project.d.ts.map +1 -0
- package/_dist/push.d.ts +42 -0
- package/_dist/push.d.ts.map +1 -0
- package/_dist/refs.d.ts +81 -0
- package/_dist/refs.d.ts.map +1 -0
- package/_dist/rewrite.d.ts +35 -0
- package/_dist/rewrite.d.ts.map +1 -0
- package/_dist/service.d.ts +35 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/sha1.d.ts +11 -0
- package/_dist/sha1.d.ts.map +1 -0
- package/_dist/source.d.ts +12 -0
- package/_dist/source.d.ts.map +1 -0
- package/_dist/tools.d.ts +11 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/tree.d.ts +28 -0
- package/_dist/tree.d.ts.map +1 -0
- package/_dist/unpack.d.ts +5 -0
- package/_dist/unpack.d.ts.map +1 -0
- package/_dist/vocab.d.ts +8 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/workspace.d.ts +17 -0
- package/_dist/workspace.d.ts.map +1 -0
- package/address.js +9 -0
- package/address.js.map +1 -0
- package/address.ts +15 -0
- package/cache.js +9 -0
- package/cache.js.map +1 -0
- package/cache.ts +6 -0
- package/checkout.js +18 -0
- package/checkout.js.map +1 -0
- package/checkout.ts +24 -0
- package/checkout_vocab.js +14 -0
- package/checkout_vocab.js.map +1 -0
- package/checkout_vocab.ts +11 -0
- package/cites.js +189 -0
- package/cites.js.map +1 -0
- package/cites.ts +206 -0
- package/commit.js +128 -0
- package/commit.js.map +1 -0
- package/commit.ts +183 -0
- package/comp.js +94 -0
- package/comp.js.map +1 -0
- package/comp.ts +111 -0
- package/deno.json +1 -0
- package/door.js +88 -0
- package/door.js.map +1 -0
- package/door.ts +142 -0
- package/format.js +43 -0
- package/format.js.map +1 -0
- package/format.ts +49 -0
- package/hold.js +17 -0
- package/hold.js.map +1 -0
- package/hold.ts +21 -0
- package/host.js +1024 -0
- package/host.js.map +1 -0
- package/host.ts +1140 -0
- package/http.js +268 -0
- package/http.js.map +1 -0
- package/http.ts +329 -0
- package/import.js +141 -0
- package/import.js.map +1 -0
- package/import.ts +128 -0
- package/index.js +496 -0
- package/index.js.map +1 -0
- package/index.ts +634 -0
- package/land.js +788 -0
- package/land.js.map +1 -0
- package/land.ts +871 -0
- package/mod.js +73 -0
- package/mod.js.map +1 -0
- package/mod.ts +74 -0
- package/objects.js +331 -0
- package/objects.js.map +1 -0
- package/objects.ts +390 -0
- package/oid.js +50 -0
- package/oid.js.map +1 -0
- package/oid.ts +83 -0
- package/pack-index.js +103 -0
- package/pack-index.js.map +1 -0
- package/pack-index.ts +104 -0
- package/pack-store.js +216 -0
- package/pack-store.js.map +1 -0
- package/pack-store.ts +292 -0
- package/pack.js +121 -0
- package/pack.js.map +1 -0
- package/pack.ts +146 -0
- package/package.json +78 -4
- package/pkt.js +73 -0
- package/pkt.js.map +1 -0
- package/pkt.ts +93 -0
- package/placement.js +44 -0
- package/placement.js.map +1 -0
- package/placement.ts +38 -0
- package/plugin.js +66 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +88 -0
- package/process-cwd.py +57 -0
- package/project.js +142 -0
- package/project.js.map +1 -0
- package/project.ts +151 -0
- package/push.js +401 -0
- package/push.js.map +1 -0
- package/push.ts +451 -0
- package/refs.js +176 -0
- package/refs.js.map +1 -0
- package/refs.ts +285 -0
- package/rewrite.js +176 -0
- package/rewrite.js.map +1 -0
- package/rewrite.ts +173 -0
- package/service.js +104 -0
- package/service.js.map +1 -0
- package/service.ts +194 -0
- package/sha1.js +115 -0
- package/sha1.js.map +1 -0
- package/sha1.ts +146 -0
- package/source.js +100 -0
- package/source.js.map +1 -0
- package/source.ts +116 -0
- package/spare.js +108 -0
- package/spare.js.map +1 -0
- package/spare.ts +94 -0
- package/tools.js +278 -0
- package/tools.js.map +1 -0
- package/tools.ts +310 -0
- package/tree.js +105 -0
- package/tree.js.map +1 -0
- package/tree.ts +132 -0
- package/unpack.js +207 -0
- package/unpack.js.map +1 -0
- package/unpack.ts +210 -0
- package/vocab.js +20 -0
- package/vocab.js.map +1 -0
- package/vocab.json +386 -0
- package/vocab.ts +22 -0
- package/workspace.js +449 -0
- package/workspace.js.map +1 -0
- package/workspace.ts +445 -0
package/README.md
CHANGED
|
@@ -1,3 +1,755 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yaks/git
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Builds Git objects out of a file manifest, stores them as graph entities, and
|
|
4
|
+
serves clones and receives pushes over Git smart HTTP. A second entry point,
|
|
5
|
+
`@yaks/git/host`, tracks the Git checkouts on the machine it runs on, and a
|
|
6
|
+
third, `@yaks/git/land`, merges a branch in one of them.
|
|
7
|
+
|
|
8
|
+
The package separates Git object bytes from the graph data used to find and walk
|
|
9
|
+
them. File, tree, and commit bodies live in an `@yaks/blob` store. Graph
|
|
10
|
+
entities hold object type, size, byte-store address, tree entries, commit
|
|
11
|
+
parents, and refs.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
deno add jsr:@yaks/git
|
|
17
|
+
# or: npx jsr add @yaks/git
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Entry points:
|
|
21
|
+
|
|
22
|
+
- `@yaks/git`: object builders and storage, refs, packfiles, smart HTTP, and the
|
|
23
|
+
commit plugin.
|
|
24
|
+
- `@yaks/git/door`: a repository's door, the clone and fetch addresses of
|
|
25
|
+
repositories its host finds by name, with the credential challenge and the
|
|
26
|
+
refusals.
|
|
27
|
+
- `@yaks/git/workspace`: explicit filesystem transport discovery, creation and
|
|
28
|
+
reclamation.
|
|
29
|
+
- `@yaks/git/host`: local checkout discovery, and creating, taking back and
|
|
30
|
+
re-creating worktrees, using the `git` subprocess.
|
|
31
|
+
- `@yaks/git/service`: while a process is up, takes back the idle worktrees that
|
|
32
|
+
hold nothing, in every repository the graph knows.
|
|
33
|
+
- `@yaks/git/land`: the filesystem-based branch landing operation.
|
|
34
|
+
- `@yaks/git/cites`: how a citation stands against the code it names, derived
|
|
35
|
+
from Git.
|
|
36
|
+
- `@yaks/git/tools`: graph-tool implementations — `land`, `cites check` and
|
|
37
|
+
`cites verify`.
|
|
38
|
+
- `@yaks/git/vocab`: vocabulary documents without runtime behavior.
|
|
39
|
+
|
|
40
|
+
## The idea
|
|
41
|
+
|
|
42
|
+
A file manifest maps `path → sha256` for bytes already in an
|
|
43
|
+
[@yaks/blob](https://jsr.io/@yaks/blob) store. Git describes the same set of
|
|
44
|
+
files as blobs, trees and a commit, and names each of those by the digest of its
|
|
45
|
+
own bytes. So the object id is the entity id, and no separate lookup is needed:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { graph } from '@yaks/graph'
|
|
49
|
+
import { ram } from '@yaks/ram'
|
|
50
|
+
import { loadVocab } from '@yaks/vocab'
|
|
51
|
+
import { edgeDoc, edgeKeywords, edges } from '@yaks/edge'
|
|
52
|
+
import { keyDoc, keyKeywords, keys } from '@yaks/key'
|
|
53
|
+
import { address, encode, memoryBlobs } from '@yaks/blob'
|
|
54
|
+
import { gitDoc, index } from '@yaks/git'
|
|
55
|
+
|
|
56
|
+
let vocab = loadVocab([edgeDoc, keyDoc, gitDoc], [edgeKeywords, keyKeywords])
|
|
57
|
+
let plugins = [edges(vocab), keys(vocab)]
|
|
58
|
+
let g = graph({ storage: ram(vocab), vocab, plugins })
|
|
59
|
+
|
|
60
|
+
// Two files already in the byte store, named by their SHA-256.
|
|
61
|
+
let store = memoryBlobs()
|
|
62
|
+
let put = (text: string) => {
|
|
63
|
+
store.put(address(text), encode(text))
|
|
64
|
+
return address(text)
|
|
65
|
+
}
|
|
66
|
+
let sha = put('<h1>Hello</h1>\n')
|
|
67
|
+
let other = put('export let hello = 1\n')
|
|
68
|
+
let deployedAt = '2026-09-25T12:00:00Z'
|
|
69
|
+
|
|
70
|
+
let git = index(g, store)
|
|
71
|
+
|
|
72
|
+
let tree = await git.files({ 'index.html': sha, 'lib/app.js': other })
|
|
73
|
+
let head = await git.commit({
|
|
74
|
+
tree,
|
|
75
|
+
author: { name: 'Example User', email: 'user@example.com', at: deployedAt },
|
|
76
|
+
committer: {
|
|
77
|
+
name: 'Build Service',
|
|
78
|
+
email: 'build@example.com',
|
|
79
|
+
at: deployedAt,
|
|
80
|
+
},
|
|
81
|
+
message: 'deploy 7',
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
head.oid // the Git object id, 40 hex digits, and the entity id
|
|
85
|
+
head.oid256 // the same commit's SHA-256 object id
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Writing the same manifest again produces the same ids, which are the same rows:
|
|
89
|
+
an object is stored once no matter how many versions, apps or runs mention it.
|
|
90
|
+
|
|
91
|
+
## Consequences
|
|
92
|
+
|
|
93
|
+
- **An object's entity id is its Git object id.** There is no `sha` property, no
|
|
94
|
+
uniqueness constraint and nothing to reconcile: a `want` line in a fetch
|
|
95
|
+
request is a lookup by primary key.
|
|
96
|
+
- **Every object also has a SHA-256 object id, from the first write.** `oid256`
|
|
97
|
+
is the same object with its children's ids translated, stored as an @yaks/key
|
|
98
|
+
of kind `compat` (Git's term for the id under the other hash function). The
|
|
99
|
+
current HTTP server advertises and serves SHA-1 repositories only; the
|
|
100
|
+
compatibility key is available to storage and application code.
|
|
101
|
+
- **Object bodies and traversal data use separate storage.** A tree or commit
|
|
102
|
+
body is stored unchanged in the byte store because Git hashes those bytes. The
|
|
103
|
+
graph stores `gitobj{type, size}`, `blob{sha}` and `parent` edges (commit →
|
|
104
|
+
commit). Tree children are read from the body. The SHA-256-format tree is
|
|
105
|
+
stored with its Git header under its SHA-256 object id; reading both formats
|
|
106
|
+
supplies both child ids without looking up each child.
|
|
107
|
+
- **A Git blob is the blob you already have.** The bytes are already in the
|
|
108
|
+
store under their SHA-256 address; the Git object is those same bytes with a
|
|
109
|
+
header hashed over them. Nothing is re-encoded, and naming the same file twice
|
|
110
|
+
costs one indexed read (`blob.sha`) and no read of the bytes.
|
|
111
|
+
- **A release reads and writes what it changed.** `files(manifest, base)` folds
|
|
112
|
+
a manifest against the commit before it: `base` is that commit's tree and the
|
|
113
|
+
manifest it was made from. A directory whose files all stand is the old tree
|
|
114
|
+
again, read and written nowhere; a changed one reads its old entries and names
|
|
115
|
+
only the files that moved. An object already stored is not written again.
|
|
116
|
+
|
|
117
|
+
A tree holding only its SHA-1-format body resolves its children's SHA-256 ids
|
|
118
|
+
through their compatibility keys when it is rebuilt. It stays unchanged in
|
|
119
|
+
storage; newly minted trees hold both formats.
|
|
120
|
+
|
|
121
|
+
## The components
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
gitobj{type, size} one Git object — entity id = its SHA-1 object id
|
|
125
|
+
blob{sha} where its bytes are, in the @yaks/blob store
|
|
126
|
+
tree_entry{name, mode} retained tree-to-child links
|
|
127
|
+
parent @yaks/edge relation: a commit follows a commit
|
|
128
|
+
compat @yaks/key kind: the same object's SHA-256 object id
|
|
129
|
+
ref{app, name, commit} where one branch of one repository points
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The tree-to-child relation is called `tree_entry` rather than `entry` because
|
|
133
|
+
@yaks/session already declares an `entry` component for a transcript line.
|
|
134
|
+
|
|
135
|
+
`@yaks/git/vocab` exports these declarations on their own, with no storage and
|
|
136
|
+
no runtime behind them, for code that only needs to read the schema.
|
|
137
|
+
|
|
138
|
+
Components for source code, as the rest of a graph refers to it:
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
repository{common, origin} a local object database, and its remote
|
|
142
|
+
worktree{repository, path, branch,…} a checkout: where it is, what it is on
|
|
143
|
+
commit{target, repo, message} a landed commit, attached to its work
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
A repository is the root of its files: a file in one is [@yaks/file](../file)'s
|
|
147
|
+
`file{path, root}` with the repository as its root, a path in its tree at any
|
|
148
|
+
commit, identified by both.
|
|
149
|
+
|
|
150
|
+
A `commit` stores the whole commit message, not just its first line, and its
|
|
151
|
+
entity id is the commit sha — so recording the same commit twice produces one
|
|
152
|
+
entity, and it carries no `sha` property that could disagree with its own id.
|
|
153
|
+
The `land` tool records each commit it lands this way, created through the
|
|
154
|
+
caller's session, its target the task its first line names (`T-12`), so a
|
|
155
|
+
failure a commit caused can find the session that landed it (bench/ci.ts).
|
|
156
|
+
|
|
157
|
+
## Citations
|
|
158
|
+
|
|
159
|
+
A document that quotes code goes out of date when the code moves, and nothing
|
|
160
|
+
says so. A **citation** is that reference written down: an edge `A cites B`.
|
|
161
|
+
What `B` is names the place: a `file` for a whole file, a **place** for some
|
|
162
|
+
lines of one (an entity wearing @yaks/file's `lines{file, start, end}`, with the
|
|
163
|
+
text it quoted as its `content{body}`), a [@yaks/code](../code) `symbol` for a
|
|
164
|
+
definition, and any entity at all otherwise.
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
cites{hash?} @yaks/kernel relation: A refers to B; a graph
|
|
168
|
+
target's verified content hash
|
|
169
|
+
revision{commit} the commit it was last checked against
|
|
170
|
+
verified{at, by, via} @yaks/kernel's mark: somebody checked and it holds
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Each fact is a component of its own because each is independent: the commit
|
|
174
|
+
moves whatever the citation points at. A definition is cited by pointing at its
|
|
175
|
+
`symbol` entity, which survives the file moving around it. Writing the same
|
|
176
|
+
citation twice writes one entity, because an edge's id is derived from
|
|
177
|
+
`from | cites | to` ([@yaks/edge](../edge)).
|
|
178
|
+
|
|
179
|
+
For a file of a repository, a place in one or a symbol, currentness is derived
|
|
180
|
+
from Git, in a checkout of that repository, by asking which commits after
|
|
181
|
+
`revision.commit` touched the place the citation names. For any other entity, a
|
|
182
|
+
file on a volume or the lines of one included, [@yaks/kernel](../kernel)
|
|
183
|
+
compares its content with the hash recorded when the citation was verified.
|
|
184
|
+
Server stamps do not affect that hash. Editing the cited content leaves the old
|
|
185
|
+
mark and hash in place, so the citation reads moved until checked again.
|
|
186
|
+
|
|
187
|
+
`@yaks/git/cites` derives that answer:
|
|
188
|
+
`status(cite, to, { checkout: { cwd, repository }, vocab }, file)` reads the
|
|
189
|
+
checkout at `cwd`, when `repository` is the root of `file`, and says one of
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
{ state: 'current' }
|
|
193
|
+
{ state: 'moved', changes: ['b8b0f89'] } what moved under it
|
|
194
|
+
{ state: 'unverified' } nobody has checked it yet
|
|
195
|
+
{ state: 'unknown', why: '…' } nothing could establish an answer
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The question put to Git is `git log <revision.commit>..HEAD`, narrowed to
|
|
199
|
+
`-L :<symbol.name>:<path>` when it points at a definition (the path is its
|
|
200
|
+
module's) or `-L <lines.start>,<lines.end>:<path>` when it points at a place, so
|
|
201
|
+
a commit elsewhere in the same file is not reported. The commit is checked with
|
|
202
|
+
`cat-file` first: one this checkout does not have — rebased away, or from
|
|
203
|
+
another clone — reads `unknown`, never `current`. So does a file of another
|
|
204
|
+
repository than the checkout's. `tracked(to, get)` answers which file of a
|
|
205
|
+
repository, if any, a citation of `to` is checked against.
|
|
206
|
+
|
|
207
|
+
A citation of an entity uses the kernel's `status(cite, target, vocab)` and
|
|
208
|
+
needs no checkout or journal. An older verified edge without a content hash
|
|
209
|
+
reads `unknown` until it is verified again.
|
|
210
|
+
|
|
211
|
+
## Checking and verifying citations
|
|
212
|
+
|
|
213
|
+
`@yaks/git/tools` puts the two verbs on the command line, reading the checkout
|
|
214
|
+
the command runs in:
|
|
215
|
+
|
|
216
|
+
```sh
|
|
217
|
+
yak cites check # every citation that moved or was never checked
|
|
218
|
+
yak cites check D-295 # …only the ones that record makes
|
|
219
|
+
yak cites check --path=src/db.ts # …only citations of one file, its lines or symbols
|
|
220
|
+
yak cites verify <citation> # checked and it holds: mark it, at this commit
|
|
221
|
+
yak cites verify --of=D-295 # …every citation that record makes
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
`--path` names a file of the repository the command runs in, so the same path in
|
|
225
|
+
another repository is not reported.
|
|
226
|
+
|
|
227
|
+
`check` is a health check — a tool whose verb is `check`
|
|
228
|
+
([@yaks/tools](../tools/README.md#health-checks)) — so a citation that moved is
|
|
229
|
+
a `fail` finding, one nobody has checked and one nothing could establish an
|
|
230
|
+
answer for are `warn`, and a run with nothing to report still answers. It
|
|
231
|
+
enforces nothing: a document whose code moved is work somebody has to do, not a
|
|
232
|
+
transaction to reject.
|
|
233
|
+
|
|
234
|
+
`verify` writes `verified{}` and, for a file of a repository, a place in one or
|
|
235
|
+
a symbol, `revision{commit}` for the commit the checkout is on; it refuses a
|
|
236
|
+
file of another repository than the checkout's. For another entity it records
|
|
237
|
+
`cites.hash` from the cited content. The mark is written empty because `at`,
|
|
238
|
+
`by` and `via` are the graph's to stamp.
|
|
239
|
+
|
|
240
|
+
Load the components beside the packages whose mechanisms and words they use:
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
import { graph } from '@yaks/graph'
|
|
244
|
+
import { ram } from '@yaks/ram'
|
|
245
|
+
import { loadVocab } from '@yaks/vocab'
|
|
246
|
+
import { edgeDoc, edgeKeywords, edges } from '@yaks/edge'
|
|
247
|
+
import { keyDoc, keyKeywords, keys } from '@yaks/key'
|
|
248
|
+
import { kernelDoc } from '@yaks/kernel'
|
|
249
|
+
import { fileDoc } from '@yaks/file/vocab'
|
|
250
|
+
import { gitDoc } from '@yaks/git'
|
|
251
|
+
|
|
252
|
+
let vocab = loadVocab([kernelDoc, edgeDoc, keyDoc, fileDoc, gitDoc], [
|
|
253
|
+
edgeKeywords,
|
|
254
|
+
keyKeywords,
|
|
255
|
+
])
|
|
256
|
+
let storage = ram(vocab)
|
|
257
|
+
let g = graph({ storage, vocab, plugins: [edges(vocab), keys(vocab)] })
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
A `ref` entity id is derived from `ref|<app>|<name>`, so moving a branch updates
|
|
261
|
+
the row that is already there.
|
|
262
|
+
|
|
263
|
+
Objects are global — an object is the digest of its own bytes, so the same file
|
|
264
|
+
in two repositories is one row — while a branch belongs to exactly one
|
|
265
|
+
repository. A server that decides read access per repository therefore keeps its
|
|
266
|
+
refs in the graph where that decision is made and its objects in a store of
|
|
267
|
+
their own, loading `refDoc` in the first and `gitDoc` in the second.
|
|
268
|
+
|
|
269
|
+
## A branch, and landing a release on it
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
import { graph, mint } from '@yaks/graph'
|
|
273
|
+
import { ram } from '@yaks/ram'
|
|
274
|
+
import { loadVocab } from '@yaks/vocab'
|
|
275
|
+
import { edgeDoc, edgeKeywords, edges } from '@yaks/edge'
|
|
276
|
+
import { keyDoc, keyKeywords, keys } from '@yaks/key'
|
|
277
|
+
import { address, encode, memoryBlobs } from '@yaks/blob'
|
|
278
|
+
import { commitOnto, gitDoc, refAt, refDoc } from '@yaks/git'
|
|
279
|
+
|
|
280
|
+
// The branches in one graph, the objects in another, their bytes in a store.
|
|
281
|
+
let refVocab = loadVocab([refDoc])
|
|
282
|
+
let refs = graph({ storage: ram(refVocab), vocab: refVocab })
|
|
283
|
+
let vocab = loadVocab([edgeDoc, keyDoc, gitDoc], [edgeKeywords, keyKeywords])
|
|
284
|
+
let plugins = [edges(vocab), keys(vocab)]
|
|
285
|
+
let objects = graph({ storage: ram(vocab), vocab, plugins })
|
|
286
|
+
let bytes = memoryBlobs()
|
|
287
|
+
bytes.put(address('<h1>Hello</h1>\n'), encode('<h1>Hello</h1>\n'))
|
|
288
|
+
|
|
289
|
+
let repo = { refs, objects, bytes }
|
|
290
|
+
let app = mint()
|
|
291
|
+
let who = { name: 'Build Service', email: 'build@example.com', at: 0 }
|
|
292
|
+
|
|
293
|
+
let head = await commitOnto(repo, {
|
|
294
|
+
app,
|
|
295
|
+
files: { 'index.html': address('<h1>Hello</h1>\n') },
|
|
296
|
+
author: who,
|
|
297
|
+
committer: who,
|
|
298
|
+
message: 'deploy 7\n',
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
await refAt(repo.refs, app) // head.oid
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
That writes every object and points the branch at the new commit. An optional
|
|
305
|
+
`was` answers the manifest a commit on the branch was made from,
|
|
306
|
+
`(commit) => Files | null`; given it, the new manifest is folded against the
|
|
307
|
+
branch's last commit, so only what changed is read or written. A **bundle** is
|
|
308
|
+
one entity's components represented as a JSON object. An optional `beside`
|
|
309
|
+
returns bundles about the commit —
|
|
310
|
+
`(oids) => [{ entity: { eid: oids.oid },
|
|
311
|
+
made: { release } }]` — that are
|
|
312
|
+
submitted with the ref update as one **batch**, a list of bundles applied in one
|
|
313
|
+
transaction. This package declares no component joining a commit to its
|
|
314
|
+
application input, because that input depends on the application; `beside` is
|
|
315
|
+
where the caller supplies those rows. The parent commit is read from the ref
|
|
316
|
+
rather than passed in, so a commit written the moment a release landed and a
|
|
317
|
+
commit written later by a repair pass end up on the same chain.
|
|
318
|
+
|
|
319
|
+
The same step is also available as a graph plugin, hooked on the `effect` phase:
|
|
320
|
+
|
|
321
|
+
```ts
|
|
322
|
+
import type { Bundle } from '@yaks/graph'
|
|
323
|
+
import { commits, type Released } from '@yaks/git'
|
|
324
|
+
|
|
325
|
+
declare let alreadyCommitted: (b: Bundle) => boolean
|
|
326
|
+
declare let landingFor: (b: Bundle) => Promise<Released>
|
|
327
|
+
|
|
328
|
+
let plugin = commits({
|
|
329
|
+
comp: 'deploy',
|
|
330
|
+
of: async (b, tx) => alreadyCommitted(b) ? null : landingFor(b),
|
|
331
|
+
})
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Everything specific to the application's release model — what a release is
|
|
335
|
+
called, where its manifest is, who authored it, which graphs and byte store hold
|
|
336
|
+
its objects and branches, and whether it has been committed already — is
|
|
337
|
+
answered by that one `of` function. An application with its own post-commit hook
|
|
338
|
+
registry can register `minting(…)` directly; the plugin adds the graph phase
|
|
339
|
+
registration.
|
|
340
|
+
|
|
341
|
+
## A clone is a packfile
|
|
342
|
+
|
|
343
|
+
`objects(g, store)` reads the objects a graph and byte store hold:
|
|
344
|
+
`reach([head.oid])` is every object a clone of `head` needs, and
|
|
345
|
+
`pack([head.oid], have)` is the same as a v2 packfile, streaming.
|
|
346
|
+
|
|
347
|
+
`reach` returns each reachable object once. It follows `parent` edges for
|
|
348
|
+
history and reads tree children from their immutable bodies for reachability. A
|
|
349
|
+
commit's own tree is read from the first line of its body.
|
|
350
|
+
|
|
351
|
+
A `have` line is handled by subtraction, not by negotiation: everything the
|
|
352
|
+
client reports it already holds is walked first, so those objects are simply
|
|
353
|
+
absent from the answer, and a `have` naming an object this graph never held is
|
|
354
|
+
ignored.
|
|
355
|
+
|
|
356
|
+
`pack` writes `PACK`, version 2, the object count, then each object's
|
|
357
|
+
type-and-size varint followed by its zlib-deflated body, then the SHA-1 of every
|
|
358
|
+
byte before it. Every object is stored whole rather than as a delta, which the
|
|
359
|
+
format permits. The entry header contains the uncompressed size, and the body
|
|
360
|
+
uses zlib through `CompressionStream('deflate')`, rather than raw deflate. The
|
|
361
|
+
pack is streamed; `./sha1.ts` updates the trailer digest as bytes pass, so only
|
|
362
|
+
one object's body is held in memory at a time.
|
|
363
|
+
|
|
364
|
+
## The byte-level builders
|
|
365
|
+
|
|
366
|
+
The builders do not touch a graph at all, and each one is tested against the
|
|
367
|
+
bytes Git itself produced for the same input:
|
|
368
|
+
|
|
369
|
+
```ts
|
|
370
|
+
import { commitBody, DIR, FILE, oid, oid256, treeBody } from '@yaks/git'
|
|
371
|
+
|
|
372
|
+
const fileOid = await oid('blob', new TextEncoder().encode('hello\n'))
|
|
373
|
+
// 'ce013625030ba8dba906f756967f9e9ca394464a'
|
|
374
|
+
|
|
375
|
+
const treeOid = await oid('tree', new Uint8Array())
|
|
376
|
+
treeBody([
|
|
377
|
+
{ name: 'a.txt', mode: FILE, oid: fileOid },
|
|
378
|
+
{ name: 'a', mode: DIR, oid: treeOid },
|
|
379
|
+
])
|
|
380
|
+
// a.txt sorts first: a directory sorts as though its name ended in `/`
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
A directory's mode is `40000` in the body, without the leading zero printed by
|
|
384
|
+
`git ls-tree` as `040000`. Directories sort as `name + '/'`, compared over UTF-8
|
|
385
|
+
bytes.
|
|
386
|
+
|
|
387
|
+
## Serving a clone over HTTP
|
|
388
|
+
|
|
389
|
+
```ts
|
|
390
|
+
import type { Graph } from '@yaks/graph'
|
|
391
|
+
import type { Blobs } from '@yaks/blob'
|
|
392
|
+
import { advertise, objects, uploadPack } from '@yaks/git'
|
|
393
|
+
|
|
394
|
+
// One repository's two doors: the graph and byte store holding its objects,
|
|
395
|
+
// and the commit its main branch points at.
|
|
396
|
+
let repository = (g: Graph, store: Blobs, main: string) => {
|
|
397
|
+
let refs = { list: async () => [{ name: 'refs/heads/main', oid: main }] }
|
|
398
|
+
return (req: Request) =>
|
|
399
|
+
req.method == 'GET'
|
|
400
|
+
? advertise(req) // <repo>/info/refs?service=git-upload-pack
|
|
401
|
+
: uploadPack(req, refs, objects(g, store)) // <repo>/git-upload-pack
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
This is Git's smart HTTP protocol, version 2, read-only. The response to the
|
|
406
|
+
`GET` advertises what this server supports and lists no refs at all — that is
|
|
407
|
+
what version 2 changed, and `ls-refs` is the command a client sends to get them.
|
|
408
|
+
The `fetch` command is answered with a packfile, side-band framed as version 2
|
|
409
|
+
requires, holding everything the `want` lines reach minus everything the `have`
|
|
410
|
+
lines reach.
|
|
411
|
+
|
|
412
|
+
A host can wrap its object reader with `storedPacks` and refresh it after its
|
|
413
|
+
main ref moves. A fast-forward writes a pack segment for the newly reachable
|
|
414
|
+
objects, plus the affected shards of an immutable reachability index. A clone
|
|
415
|
+
streams the segments as one Git pack. A fetch from the immediately preceding tip
|
|
416
|
+
can use the stored segment directly. Other fetches use the index to select the
|
|
417
|
+
objects the client needs. A history rewrite can discard the old segments and
|
|
418
|
+
rebuild from the rewritten ref.
|
|
419
|
+
|
|
420
|
+
Only what is implemented is advertised: `ls-refs`, `fetch`, `object-format=sha1`
|
|
421
|
+
and `server-option`. A client that is never told about shallow clones,
|
|
422
|
+
partial-clone filters or SHA-256 packs never asks for them. A `want` for an
|
|
423
|
+
object that no ref reaches is refused with an `ERR` line — the same rule as
|
|
424
|
+
Git's `uploadpack.allowAnySHA1InWant=false` — because serving an object to
|
|
425
|
+
whoever guesses its id would publish something nobody published.
|
|
426
|
+
|
|
427
|
+
Those two handlers do no routing. `@yaks/git/door` is the door that mounts them:
|
|
428
|
+
it answers a repository's addresses, `<name>.git/info/refs` and
|
|
429
|
+
`<name>.git/git-upload-pack`, and asks its host for the repository a name is, as
|
|
430
|
+
the request may see it. Where the refs and objects are kept, and who may read
|
|
431
|
+
them, are the host's.
|
|
432
|
+
|
|
433
|
+
```ts
|
|
434
|
+
import { door } from '@yaks/git/door'
|
|
435
|
+
import { objects } from '@yaks/git'
|
|
436
|
+
import type { Graph } from '@yaks/graph'
|
|
437
|
+
import type { Blobs } from '@yaks/blob'
|
|
438
|
+
|
|
439
|
+
let repositories = (g: Graph, store: Blobs, main: string) =>
|
|
440
|
+
door({
|
|
441
|
+
realm: 'example',
|
|
442
|
+
// `password` is what a Basic credential carried, or null.
|
|
443
|
+
find: async (name, _req, password) =>
|
|
444
|
+
name == 'recipes'
|
|
445
|
+
? {
|
|
446
|
+
reads: password == 'open sesame',
|
|
447
|
+
proven: password == 'open sesame',
|
|
448
|
+
refs: { list: async () => [{ name: 'refs/heads/main', oid: main }] },
|
|
449
|
+
objects: objects(g, store),
|
|
450
|
+
}
|
|
451
|
+
: null,
|
|
452
|
+
})
|
|
453
|
+
// repositories(g, store, main)(req) is a Response, or null for an address
|
|
454
|
+
// that is no repository's.
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
A repository the request may not read answers `401` with a Basic challenge while
|
|
458
|
+
nobody has proved who they are, which is what prompts git for a password, and
|
|
459
|
+
`403` once somebody has, which is final. A name the host does not find is `404`
|
|
460
|
+
to everyone.
|
|
461
|
+
|
|
462
|
+
A clone of the address a browser shows, `<name>/`, asks for the advertisement at
|
|
463
|
+
`<name>/info/refs?service=git-upload-pack`, and the door redirects it to
|
|
464
|
+
`<name>.git` with a 301. yaks.app mounts an app's deploy history this way, so
|
|
465
|
+
either address can be cloned:
|
|
466
|
+
|
|
467
|
+
```sh
|
|
468
|
+
git clone https://ada.yaks.app/recipes/
|
|
469
|
+
git clone https://ada.yaks.app/recipes.git # where the first one lands
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
The query string is what distinguishes a clone from a page request:
|
|
473
|
+
`?service=git-upload-pack` is something no browser sends, and Git follows that
|
|
474
|
+
first redirect and fetches from where it landed. A name holds no dot, so the two
|
|
475
|
+
addresses never overlap.
|
|
476
|
+
|
|
477
|
+
## Landing a branch
|
|
478
|
+
|
|
479
|
+
`@yaks/git/land` is a plain Git operation with no graph in it, and
|
|
480
|
+
`@yaks/git/tools` exposes that operation as a tool, so `yak land` works in a Git
|
|
481
|
+
checkout. The CLI opens the configured graph and merges the checkout at the
|
|
482
|
+
current working directory in the same process.
|
|
483
|
+
|
|
484
|
+
```sh
|
|
485
|
+
yak land # fast-forward this branch into the base
|
|
486
|
+
yak land --allow-revert=a.ts,b.ts # …and accept those files' rewind
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
Every coordinate comes from Git alone: the primary worktree is the shared
|
|
490
|
+
checkout to merge into, and the branch that checkout has checked out is the
|
|
491
|
+
base. One invocation does at most one of two things: fast-forward the branch
|
|
492
|
+
into the base and push if the base has an upstream; or, if the base moved,
|
|
493
|
+
rebase onto it and return without merging, printing the incorporated diff so the
|
|
494
|
+
caller can rerun tests and land again. The `--ff-only` merge is the
|
|
495
|
+
compare-and-swap that serializes concurrent landers. Everything landing writes
|
|
496
|
+
in the shared checkout happens while it holds that checkout's `land.lock` (in
|
|
497
|
+
its Git directory) exclusively, since Git refuses a second writer of the index
|
|
498
|
+
rather than waiting for it; `hold(gitdir, exclusive)` takes the lock, and a
|
|
499
|
+
reader that needs the checkout whole, such as the CLI's runtime snapshot, holds
|
|
500
|
+
it shared. No test suite is run here, and this operation knows of none.
|
|
501
|
+
|
|
502
|
+
If publishing fails and the upstream has advanced, landing brings the base up to
|
|
503
|
+
the fetched commit under the same lock. Unpublished base commits are rebased
|
|
504
|
+
onto it, then the caller's branch rebases onto the base and returns for
|
|
505
|
+
retesting. Before a fast-forward, Git checks whether the incoming files would
|
|
506
|
+
overwrite local edits in the shared checkout. Landing saves the blocking staged,
|
|
507
|
+
unstaged and untracked edits in a named Git stash and leaves unrelated paths in
|
|
508
|
+
place. Replaying unpublished base commits saves all staged, unstaged and
|
|
509
|
+
untracked edits first. The saved edits are available through `git stash list`. A
|
|
510
|
+
conflicting replay is aborted before the lock is released, restoring the base
|
|
511
|
+
and returning Git's conflict output to the caller.
|
|
512
|
+
|
|
513
|
+
Before merging, landing runs `deno fmt` on changed regular files of a checkout
|
|
514
|
+
with a `deno.json` or `deno.jsonc`, using its formatting configuration and
|
|
515
|
+
Deno's supported file types; a checkout without one is never formatted.
|
|
516
|
+
Formatting passes global `exclude` and `fmt.exclude` patterns through Deno's
|
|
517
|
+
`--ignore`, so explicitly named files retain their exclusions in JSON and JSONC
|
|
518
|
+
configs. Its edits amend the branch's last commit with its message preserved.
|
|
519
|
+
Deleted files, symlinks and submodules are skipped. A formatter error is printed
|
|
520
|
+
and landing continues, keeping any files it formatted successfully. When the
|
|
521
|
+
branch changes a `package.json` or `pnpm-workspace.yaml` in a checkout that
|
|
522
|
+
tracks `pnpm-lock.yaml`, landing runs `pnpm install --lockfile-only` and amends
|
|
523
|
+
the updated lockfile into the same commit, so the base never takes a manifest
|
|
524
|
+
without its lockfile. A pnpm failure is printed and reported, and landing
|
|
525
|
+
continues.
|
|
526
|
+
|
|
527
|
+
Before the fast-forward, `reverts` detects a rebase that restores earlier base
|
|
528
|
+
content. It finds files changed by `base...HEAD` that no branch commit touched,
|
|
529
|
+
and added lines whose content appeared earlier at the same path in base history.
|
|
530
|
+
Either condition refuses the landing and reports the files, the diff, and the
|
|
531
|
+
override flag. Only added lines can restore old content; a hunk that only
|
|
532
|
+
removes lines is treated as a deletion.
|
|
533
|
+
|
|
534
|
+
`land` operates on the filesystem rather than on the graph: the checkout at the
|
|
535
|
+
`cwd` argument. The CLI supplies its current directory; an MCP caller supplies
|
|
536
|
+
its own absolute checkout path, including a sub-agent sharing a connection. A
|
|
537
|
+
session’s recorded directory never selects the checkout. A diverged base comes
|
|
538
|
+
back as a refusal, so the exit code tells you whether anything landed.
|
|
539
|
+
|
|
540
|
+
## Receiving pushes
|
|
541
|
+
|
|
542
|
+
The HTTP door advertises receive-pack when the host supplies a receiver.
|
|
543
|
+
Receive-pack accepts an update to the receiver’s branch, checks its old tip and
|
|
544
|
+
ancestry, and unpacks whole objects, offset deltas and thin reference deltas. It
|
|
545
|
+
advertises `no-thin`, so a client carries every delta base in its pack. Existing
|
|
546
|
+
objects used by a push must be reachable from the repository’s refs. Each is
|
|
547
|
+
proven first from the trees the push replaced, read a level at a time along the
|
|
548
|
+
paths it changed; only an object found nowhere near them is looked for in the
|
|
549
|
+
tips' whole snapshots, then their history. `kind` says what such an object is
|
|
550
|
+
from the tree that names it, without reading it. The trees a push carried, and
|
|
551
|
+
those its advertisement read where the host gives the door `hold` (each tip's
|
|
552
|
+
commit, its root tree and the trees directly in it, `warm`), are read from the
|
|
553
|
+
isolate's memory while the client packs. The host can keep the original objects
|
|
554
|
+
with `importPush` and update its ref with `advancing` in the same directory
|
|
555
|
+
transaction as its own changes.
|
|
556
|
+
|
|
557
|
+
The receive endpoint accepts requests up to 24 MiB and bounds expanded pack data
|
|
558
|
+
to 48 MiB. It uses `node:zlib` to decode Git’s zlib streams. Clone and the
|
|
559
|
+
object formats use web APIs. Upload-pack sends whole objects and supports full
|
|
560
|
+
clones and incremental fetches.
|
|
561
|
+
|
|
562
|
+
## Checkouts on one machine
|
|
563
|
+
|
|
564
|
+
Here a **host** is the process that opened the graph and runs these operations.
|
|
565
|
+
`@yaks/git/host` adds `discover`, `checkoutAt`, `createWorktree`, `keepSpare`,
|
|
566
|
+
`holds`, `reclaim`, `lost`, `idleFor`, `linked`, `locate`, `reconcile`,
|
|
567
|
+
`restore`, `processCwds`, `processPaths` and `inUse`, which run `git` as a
|
|
568
|
+
subprocess and therefore need Deno. They are kept out of the main entry point,
|
|
569
|
+
which still type-checks with only the web platform in scope. Load `checkoutDoc`
|
|
570
|
+
to get just the four components below — `repository`, `worktree`, `ref` and
|
|
571
|
+
`checkout` — without the Git object components.
|
|
572
|
+
|
|
573
|
+
Git is authoritative here; the graph holds an observation of it that can be
|
|
574
|
+
refreshed at any time without changing anything.
|
|
575
|
+
|
|
576
|
+
- `repository{workspace,common,origin}` identifies an object database by its
|
|
577
|
+
stable filesystem workspace and canonical common Git directory. The workspace
|
|
578
|
+
is the sandbox itself or the computer’s canonical root workspace, never a
|
|
579
|
+
linked checkout or a convenience directory. Independent clones are different
|
|
580
|
+
repositories.
|
|
581
|
+
- `worktree{repository,gitdir,head,branch,managed}` with
|
|
582
|
+
`workspace{machine,root,sandbox}` is a checkout. Its entity id is derived from
|
|
583
|
+
the repository plus the canonical checkout root path, so the branch and head
|
|
584
|
+
can change without changing its identity, and paths that differ only by a
|
|
585
|
+
symlink resolve to the same entity. Moving a checkout gives it a new identity;
|
|
586
|
+
this deliberately avoids depending on Git's linked-worktree administrative
|
|
587
|
+
directory names, which Git may reuse. These identities are local to one
|
|
588
|
+
machine, not portable between clones.
|
|
589
|
+
- The existing `ref{app,name,commit}` component is reused: `app` may name the
|
|
590
|
+
repository entity, and `refEid(repository, fullName)` stays stable as the
|
|
591
|
+
branch moves. Observing a repository on this machine adds `oid` (the raw
|
|
592
|
+
target, which for an annotated tag is the tag object), `target` (the full name
|
|
593
|
+
a symbolic ref points at) and `present`. A deleted ref is marked absent rather
|
|
594
|
+
than deleted, so recreating it reuses the same entity. There is no separate
|
|
595
|
+
branch component competing with `ref`.
|
|
596
|
+
- HEAD belongs to each worktree: `head` is its resolved object id, and `branch`
|
|
597
|
+
names the shared ref entity, or is absent for a detached HEAD. A branch that
|
|
598
|
+
has no commits yet gets a ref row marked absent, with the same stable id it
|
|
599
|
+
will keep once it exists. Discovery refreshes refs when it is called; there is
|
|
600
|
+
no watcher, and it does not import commit bodies into the graph.
|
|
601
|
+
- `checkout` records the intent to create a worktree, stored on the entity that
|
|
602
|
+
worktree will have: the requested base, the commit that base resolved to, the
|
|
603
|
+
branch, how far preparation got, and the error if it failed. Creation is
|
|
604
|
+
serialized per path within the process, and across processes by an advisory
|
|
605
|
+
lock file in the repository, which the kernel releases if a process dies. A
|
|
606
|
+
retry reconciles the case where Git succeeded but the graph was not updated.
|
|
607
|
+
When Git fails, the intent row stays visible; preparation does not select a
|
|
608
|
+
different checkout.
|
|
609
|
+
|
|
610
|
+
Creating a worktree defaults to a detached HEAD at the source checkout's
|
|
611
|
+
committed HEAD. Uncommitted files in the source are not copied, committed, reset
|
|
612
|
+
or stashed. Passing a short branch name creates a new branch instead. An
|
|
613
|
+
existing checkout has to be discovered and attached explicitly; creation refuses
|
|
614
|
+
to adopt a directory that is already there. Nothing is merged, pruned or deleted
|
|
615
|
+
automatically the moment an agent finishes. A managed directory that has gone
|
|
616
|
+
missing is an error, not permission to recreate it and lose whatever was
|
|
617
|
+
uncommitted in it.
|
|
618
|
+
|
|
619
|
+
A checkout cut whole writes every file, and the repository's post-checkout hook
|
|
620
|
+
then installs its dependencies: several seconds in a large repository. A request
|
|
621
|
+
with `spare: true` is made from the spare checkout beside its path instead, when
|
|
622
|
+
there is one: Git moves the spare to the path, which takes it, and checks it out
|
|
623
|
+
to the requested branch and commit, which rewrites only the files that differ,
|
|
624
|
+
in about a second. `keepSpare(source, path, base)` cuts that spare, at `.spare`
|
|
625
|
+
in the directory of `path`, unless one is there; it is cut under a name of its
|
|
626
|
+
own and moved once whole, so nothing takes it half made. Its Git registration
|
|
627
|
+
stays locked through both moves, until the claimed checkout is registered at its
|
|
628
|
+
final path, so concurrent pruning cannot remove it. Publication and claims share
|
|
629
|
+
an exclusive lock. @yaks/spawn keeps one beside its runs' checkouts.
|
|
630
|
+
|
|
631
|
+
Taking a worktree back is a separate, explicit step. `holds(path)` says what a
|
|
632
|
+
worktree still holds: `dirty` for uncommitted files, `unlanded` when its HEAD is
|
|
633
|
+
on no branch but its own (a path that is not a checkout counts as that too), or
|
|
634
|
+
nothing. `reclaim(path)` removes a worktree and the branch it was created on
|
|
635
|
+
only when it holds nothing, and never with `--force`, so Git's own refusal
|
|
636
|
+
stands behind that test; it returns what kept it, `failed` included. Ignored
|
|
637
|
+
files other than dependency/build caches and declared scratch move to private
|
|
638
|
+
filesystem trash before a checkout is removed, including `.env` files. Their
|
|
639
|
+
records retain the original path for restoration with `@yaks/process/trash`.
|
|
640
|
+
Reclaiming an unused checkout clears its ignored `.scratch/` directory even when
|
|
641
|
+
uncommitted changes or unlanded commits keep the checkout itself. Pass a full
|
|
642
|
+
local branch ref as the second argument to `holds` or `reclaim` to require
|
|
643
|
+
landing there: `reclaim(path, "refs/heads/main")`. The branch reflog must also
|
|
644
|
+
prove the branch committed work still contained in HEAD; a fresh branch, a
|
|
645
|
+
branch only fast-forwarded from main, or missing evidence keeps the checkout. A
|
|
646
|
+
worktree whose gitdir Git has lost (`lost(path)`) is always kept, because
|
|
647
|
+
neither its cleanliness nor its landing can be proved. `restore(g, row)` creates
|
|
648
|
+
a worktree again at the path, branch and commit its row recorded, so run
|
|
649
|
+
`discover` on it before taking it back. `linked(common)` names a repository's
|
|
650
|
+
linked worktrees, and `idleFor(path)` says how long since Git last moved one's
|
|
651
|
+
HEAD, read from its reflog's last entry rather than the file's mtime, which
|
|
652
|
+
`git gc` rewrites in every worktree whenever it expires reflogs.
|
|
653
|
+
|
|
654
|
+
`holds` also returns `busy` for a worktree with a Git lock or an unfinished Git
|
|
655
|
+
operation. The collector checks it again on a later pass, even when it is old
|
|
656
|
+
enough to shelve.
|
|
657
|
+
|
|
658
|
+
`processPaths()` reads the working directories and open file paths of this
|
|
659
|
+
user's live Linux processes, so agents outside the graph also keep their
|
|
660
|
+
worktrees. A process that cannot be read holds nothing. It reads them through
|
|
661
|
+
`Procs`, `procfs` by default, so a test hands it processes as data. Non-dumpable
|
|
662
|
+
processes require a privileged read through a root-owned helper, launched by the
|
|
663
|
+
systemd user manager once per scan. The helper checks that each positive PID
|
|
664
|
+
belongs to the sudo caller and returns its cwd and absolute open file paths.
|
|
665
|
+
Install it from this package as root:
|
|
666
|
+
|
|
667
|
+
```sh
|
|
668
|
+
install -D -o root -g root -m 0755 packages/git/process-cwd.py /usr/local/libexec/yak-process-cwd
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
Grant the collecting user passwordless sudo for exactly that helper, with a
|
|
672
|
+
trailing `*` for its argument. For a user named `collector`, the sudoers entry
|
|
673
|
+
is `collector ALL=(root) NOPASSWD: /usr/local/libexec/yak-process-cwd *`. The
|
|
674
|
+
helper omits unreadable processes and other users' processes. It rejects
|
|
675
|
+
arguments that are not positive PIDs. Enable the user's systemd manager with
|
|
676
|
+
`loginctl enable-linger
|
|
677
|
+
collector`. Without the helper or manager, a
|
|
678
|
+
non-dumpable process holds nothing, as does one the helper refuses (a deleted
|
|
679
|
+
cwd). `processCwds()` remains available for callers needing only directories.
|
|
680
|
+
|
|
681
|
+
`@yaks/git/service` collects explicitly managed checkouts in the local
|
|
682
|
+
filesystem, and unmanaged ones under its `roots`: directories where agents cut
|
|
683
|
+
checkouts of their own, by default Claude Code's `.claude/worktrees` inside the
|
|
684
|
+
primary checkout. A relative root is resolved there. Other unmanaged
|
|
685
|
+
observations, foreign filesystem contexts and unknown placement never authorize
|
|
686
|
+
removal. It checks idle time, dirty files, unlanded commits, session homes,
|
|
687
|
+
launch workspaces and local process paths. A session's home keeps its checkout
|
|
688
|
+
until the session settles, stops or fails. A home change alone does not remove
|
|
689
|
+
files. A worktree that still holds work (uncommitted files or unlanded commits)
|
|
690
|
+
once Git has left it alone for `stale` (three days) is shelved by `shelve`: its
|
|
691
|
+
uncommitted files are committed onto its branch, a detached HEAD gets a
|
|
692
|
+
`shelf/<name>` branch, and the checkout is removed while the branch stays. One
|
|
693
|
+
holding an untracked file of a megabyte or more is kept. Managed observations
|
|
694
|
+
remain available to `restore`, which cuts a shelved checkout again from its
|
|
695
|
+
branch. The `idle`, `stale` and `every` options set the idle threshold, the
|
|
696
|
+
shelving threshold and the pass interval.
|
|
697
|
+
|
|
698
|
+
`locate(cwd)` reads the canonical checkout root, common Git directory and
|
|
699
|
+
worktree Git directory without writing to the graph. It returns no observation
|
|
700
|
+
when the directory is missing or is not a checkout; other failures remain
|
|
701
|
+
errors. `primary(g)` lists current primary checkouts on this filesystem,
|
|
702
|
+
checking observations against Git without changing the graph.
|
|
703
|
+
`reconcile(g, common)` removes the `worktree` component from unmanaged checkouts
|
|
704
|
+
whose directory or Git metadata is gone, keeping their entities and other
|
|
705
|
+
components. Managed rows retain the history `restore` needs. The service
|
|
706
|
+
reconciles each repository before collecting its idle worktrees, including
|
|
707
|
+
repositories whose common directory disappeared, and reports unexpected failures
|
|
708
|
+
through the host with the repository path.
|
|
709
|
+
|
|
710
|
+
Host-local locking assumes one filesystem and one shared graph, used by
|
|
711
|
+
cooperating processes on that machine. A checkout moved on disk, or changed by
|
|
712
|
+
Git outside this package, is noticed the next time discovery runs; the service
|
|
713
|
+
reconciles missing unmanaged checkouts on each pass.
|
|
714
|
+
|
|
715
|
+
## Reading a commit's source paths
|
|
716
|
+
|
|
717
|
+
`@yaks/git/source` exports `trees(cwd)`, a reader whose `(commit, paths)` maps
|
|
718
|
+
regular-file paths to their Git blob ids. It accepts a full object id, verifies
|
|
719
|
+
it as a commit, uses literal repository-relative paths and leaves unknown
|
|
720
|
+
revisions, symlinks and submodules unresolved. It never reads the checkout's
|
|
721
|
+
files. A commit never changes, so each path is asked of Git once per commit, for
|
|
722
|
+
the 16 commits read most recently (`keep`), and callers asking at once share one
|
|
723
|
+
read; a read Git refused is asked again. `rootsOf(common)` lists the
|
|
724
|
+
repository's primary and linked checkout roots without pruning or changing Git
|
|
725
|
+
state.
|
|
726
|
+
|
|
727
|
+
### Explicit workspace Git
|
|
728
|
+
|
|
729
|
+
`@yaks/git/workspace` provides `workspaceGit(g, workspace, transport)`. A
|
|
730
|
+
**filesystem context** is the sandbox interpreting the paths, or the canonical
|
|
731
|
+
root workspace of a computer. Two directory defaults in that context share
|
|
732
|
+
repository identity; identical paths on two computers or sandboxes do not. The
|
|
733
|
+
caller connects the selected filesystem with its configured connector or sandbox
|
|
734
|
+
adapter. Missing placement and connector failures never select the host
|
|
735
|
+
filesystem. `discover` and `create` run Git, realpath and advisory locks through
|
|
736
|
+
that transport and write checkout observations with `workspace.root`.
|
|
737
|
+
|
|
738
|
+
This example needs a connected transport, so it does not run as a doctest:
|
|
739
|
+
|
|
740
|
+
```ts ignore
|
|
741
|
+
import { workspaceGit } from '@yaks/git/workspace'
|
|
742
|
+
|
|
743
|
+
let git = await workspaceGit(graph, selectedWorkspace, transport)
|
|
744
|
+
let checkout = await git.discover()
|
|
745
|
+
let own = await git.create({ path: '/repo-task', branch: 'task' })
|
|
746
|
+
// Explicit disposal refuses unmanaged checkouts and keeps live references.
|
|
747
|
+
let kept = await git.reclaim(own.entity.eid)
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
`reclaim` keeps dirty and unlanded checkouts, homes of unsettled sessions
|
|
751
|
+
referring to the checkout or its descendants, and processes whose launch
|
|
752
|
+
workspace remains there. It never treats a sandbox disposal or a home switch as
|
|
753
|
+
a Git cleanup request. Callers must also establish that the target has no
|
|
754
|
+
untracked external users; connectors do not make graph references a complete
|
|
755
|
+
process inventory.
|