@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.
Files changed (183) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +754 -2
  3. package/_dist/address.d.ts +6 -0
  4. package/_dist/address.d.ts.map +1 -0
  5. package/_dist/checkout_vocab.d.ts +3 -0
  6. package/_dist/checkout_vocab.d.ts.map +1 -0
  7. package/_dist/cites.d.ts +48 -0
  8. package/_dist/cites.d.ts.map +1 -0
  9. package/_dist/commit.d.ts +36 -0
  10. package/_dist/commit.d.ts.map +1 -0
  11. package/_dist/comp.d.ts +29 -0
  12. package/_dist/comp.d.ts.map +1 -0
  13. package/_dist/door.d.ts +29 -0
  14. package/_dist/door.d.ts.map +1 -0
  15. package/_dist/format.d.ts +2 -0
  16. package/_dist/format.d.ts.map +1 -0
  17. package/_dist/hold.d.ts +6 -0
  18. package/_dist/hold.d.ts.map +1 -0
  19. package/_dist/host.d.ts +126 -0
  20. package/_dist/host.d.ts.map +1 -0
  21. package/_dist/http.d.ts +33 -0
  22. package/_dist/http.d.ts.map +1 -0
  23. package/_dist/import.d.ts +13 -0
  24. package/_dist/import.d.ts.map +1 -0
  25. package/_dist/index.d.ts +80 -0
  26. package/_dist/index.d.ts.map +1 -0
  27. package/_dist/land.d.ts +77 -0
  28. package/_dist/land.d.ts.map +1 -0
  29. package/_dist/mod.d.ts +73 -0
  30. package/_dist/mod.d.ts.map +1 -0
  31. package/_dist/objects.d.ts +40 -0
  32. package/_dist/objects.d.ts.map +1 -0
  33. package/_dist/oid.d.ts +24 -0
  34. package/_dist/oid.d.ts.map +1 -0
  35. package/_dist/pack-store.d.ts +9 -0
  36. package/_dist/pack-store.d.ts.map +1 -0
  37. package/_dist/pack.d.ts +26 -0
  38. package/_dist/pack.d.ts.map +1 -0
  39. package/_dist/pkt.d.ts +14 -0
  40. package/_dist/pkt.d.ts.map +1 -0
  41. package/_dist/placement.d.ts +4 -0
  42. package/_dist/placement.d.ts.map +1 -0
  43. package/_dist/plugin.d.ts +43 -0
  44. package/_dist/plugin.d.ts.map +1 -0
  45. package/_dist/project.d.ts +20 -0
  46. package/_dist/project.d.ts.map +1 -0
  47. package/_dist/push.d.ts +42 -0
  48. package/_dist/push.d.ts.map +1 -0
  49. package/_dist/refs.d.ts +81 -0
  50. package/_dist/refs.d.ts.map +1 -0
  51. package/_dist/rewrite.d.ts +35 -0
  52. package/_dist/rewrite.d.ts.map +1 -0
  53. package/_dist/service.d.ts +35 -0
  54. package/_dist/service.d.ts.map +1 -0
  55. package/_dist/sha1.d.ts +11 -0
  56. package/_dist/sha1.d.ts.map +1 -0
  57. package/_dist/source.d.ts +12 -0
  58. package/_dist/source.d.ts.map +1 -0
  59. package/_dist/tools.d.ts +11 -0
  60. package/_dist/tools.d.ts.map +1 -0
  61. package/_dist/tree.d.ts +28 -0
  62. package/_dist/tree.d.ts.map +1 -0
  63. package/_dist/unpack.d.ts +5 -0
  64. package/_dist/unpack.d.ts.map +1 -0
  65. package/_dist/vocab.d.ts +8 -0
  66. package/_dist/vocab.d.ts.map +1 -0
  67. package/_dist/workspace.d.ts +17 -0
  68. package/_dist/workspace.d.ts.map +1 -0
  69. package/address.js +9 -0
  70. package/address.js.map +1 -0
  71. package/address.ts +15 -0
  72. package/cache.js +9 -0
  73. package/cache.js.map +1 -0
  74. package/cache.ts +6 -0
  75. package/checkout.js +18 -0
  76. package/checkout.js.map +1 -0
  77. package/checkout.ts +24 -0
  78. package/checkout_vocab.js +14 -0
  79. package/checkout_vocab.js.map +1 -0
  80. package/checkout_vocab.ts +11 -0
  81. package/cites.js +189 -0
  82. package/cites.js.map +1 -0
  83. package/cites.ts +206 -0
  84. package/commit.js +128 -0
  85. package/commit.js.map +1 -0
  86. package/commit.ts +183 -0
  87. package/comp.js +94 -0
  88. package/comp.js.map +1 -0
  89. package/comp.ts +111 -0
  90. package/deno.json +1 -0
  91. package/door.js +88 -0
  92. package/door.js.map +1 -0
  93. package/door.ts +142 -0
  94. package/format.js +43 -0
  95. package/format.js.map +1 -0
  96. package/format.ts +49 -0
  97. package/hold.js +17 -0
  98. package/hold.js.map +1 -0
  99. package/hold.ts +21 -0
  100. package/host.js +1024 -0
  101. package/host.js.map +1 -0
  102. package/host.ts +1140 -0
  103. package/http.js +268 -0
  104. package/http.js.map +1 -0
  105. package/http.ts +329 -0
  106. package/import.js +141 -0
  107. package/import.js.map +1 -0
  108. package/import.ts +128 -0
  109. package/index.js +496 -0
  110. package/index.js.map +1 -0
  111. package/index.ts +634 -0
  112. package/land.js +788 -0
  113. package/land.js.map +1 -0
  114. package/land.ts +871 -0
  115. package/mod.js +73 -0
  116. package/mod.js.map +1 -0
  117. package/mod.ts +74 -0
  118. package/objects.js +331 -0
  119. package/objects.js.map +1 -0
  120. package/objects.ts +390 -0
  121. package/oid.js +50 -0
  122. package/oid.js.map +1 -0
  123. package/oid.ts +83 -0
  124. package/pack-index.js +103 -0
  125. package/pack-index.js.map +1 -0
  126. package/pack-index.ts +104 -0
  127. package/pack-store.js +216 -0
  128. package/pack-store.js.map +1 -0
  129. package/pack-store.ts +292 -0
  130. package/pack.js +121 -0
  131. package/pack.js.map +1 -0
  132. package/pack.ts +146 -0
  133. package/package.json +78 -4
  134. package/pkt.js +73 -0
  135. package/pkt.js.map +1 -0
  136. package/pkt.ts +93 -0
  137. package/placement.js +44 -0
  138. package/placement.js.map +1 -0
  139. package/placement.ts +38 -0
  140. package/plugin.js +66 -0
  141. package/plugin.js.map +1 -0
  142. package/plugin.ts +88 -0
  143. package/process-cwd.py +57 -0
  144. package/project.js +142 -0
  145. package/project.js.map +1 -0
  146. package/project.ts +151 -0
  147. package/push.js +401 -0
  148. package/push.js.map +1 -0
  149. package/push.ts +451 -0
  150. package/refs.js +176 -0
  151. package/refs.js.map +1 -0
  152. package/refs.ts +285 -0
  153. package/rewrite.js +176 -0
  154. package/rewrite.js.map +1 -0
  155. package/rewrite.ts +173 -0
  156. package/service.js +104 -0
  157. package/service.js.map +1 -0
  158. package/service.ts +194 -0
  159. package/sha1.js +115 -0
  160. package/sha1.js.map +1 -0
  161. package/sha1.ts +146 -0
  162. package/source.js +100 -0
  163. package/source.js.map +1 -0
  164. package/source.ts +116 -0
  165. package/spare.js +108 -0
  166. package/spare.js.map +1 -0
  167. package/spare.ts +94 -0
  168. package/tools.js +278 -0
  169. package/tools.js.map +1 -0
  170. package/tools.ts +310 -0
  171. package/tree.js +105 -0
  172. package/tree.js.map +1 -0
  173. package/tree.ts +132 -0
  174. package/unpack.js +207 -0
  175. package/unpack.js.map +1 -0
  176. package/unpack.ts +210 -0
  177. package/vocab.js +20 -0
  178. package/vocab.js.map +1 -0
  179. package/vocab.json +386 -0
  180. package/vocab.ts +22 -0
  181. package/workspace.js +449 -0
  182. package/workspace.js.map +1 -0
  183. package/workspace.ts +445 -0
package/source.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.js","sources":["./source.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8EAA8E;AAE9E,SAAmB,GAAG,oBAAmB;AAEzC,oCAAoC;AACpC,IAAI,SAAS;AAEb,OAAO,IAAI,WAAW,CAAC,OACrB,CAAC,CAAC,QAAQ,CAAC,KAAK,UAAU,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,SAChD,KAAK,KAAK,CAAC,KAAK,KAAK,CAAC,CAAC,OAAS,CAAC,CAAC,QAAQ,QAAQ,OAAO,QAAQ,MAAK;AAExE,0EAA0E;AAC1E,IAAI,SAAS,OACX,KACA,QACA,OACA;EAEA,IAAI,MAAM,MAAM,IAAI;IAClB;IACA;IACA;IACA,GAAG,OAAO,SAAS,CAAC;IACpB;OACG;GACJ,EAAE;EACH,IAAI,CAAC,IAAI,EAAE,EAAE;EACb,IAAI,MAAM,IAAI;EACd,KAAK,IAAI,SAAS,IAAI,GAAG,CAAC,KAAK,CAAC,MAAO;IACrC,IAAI,QAAQ,MAAM,KAAK,CAAC;IACxB,IAAI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AEqE,GACrE,OAAO,IAAI,YAAY,OACrB,KACA,KACA,MAAW,GAAG;EAEd,IAAI,CAAC,mBAAmB,IAAI,CAAC,MAAM,OAAO,EAAE;EAC5C,IAAI,SAAS,CAAC,KACZ,IAAI;MAAC;MAAa;MAAY;MAAW,GAAG,GAAG,SAAS,CAAC;KAAC,EAAE;EAC9D,IAAI,MAAM,MAAM,OAAO;EACvB,IAAI,IAAI,EAAE,EAAE,OAAO;IAAC,IAAI,GAAG,CAAC,IAAI;GAAG;EACnC,yEAAyE;EACzE,gDAAgD;EAChD,IAAI,MAAM,MAAM,IAAI;IAAC;IAAa,CAAC,eAAe,EAAE,KAAK;GAAC,EAAE;EAC5D,IAAI,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE;EACtB,IAAI,SAAS,MAAM,QAAQ,GAAG,CAC5B,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,MAAM,CAAC,SAAS,GAAG,CAAC;EAE1C,OAAO;OAAI,IAAI,IAAI,OAAO,MAAM,CAAC,CAAC,IAAM,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC,IAAM,EAAE,GAAG,CAAC,IAAI;GAAK;AAC1E,EAAC;AAED,6EAA6E,GAC7E,OAAO,IAAI,UAAU,OACnB,QACA,MAAW,GAAG;EAEd,IAAI,MAAM,MAAM,IAAI;IAClB,eAAe;IACf;IACA;IACA;GACD,EAAE;EACH,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,MAAM,IAAI,GAAG,CAAC,IAAI;EACrC,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,MAAM,CAAC,CAAC,IAAM,EAAE,UAAU,CAAC,cACnD,GAAG,CAAC,CAAC,IAAM,EAAE,KAAK,CAAC,YAAY,MAAM;AAC1C,EAAC"}
package/source.ts ADDED
@@ -0,0 +1,116 @@
1
+ // Read a commit's regular-file blobs, never the checkout's mutable files.
2
+ // Paths and revisions are data, restricted before they reach Git's arguments.
3
+
4
+ import { type Run, run } from './land.js'
5
+
6
+ // deno-lint-ignore no-control-regex
7
+ let unsafe = /[\\\x00-\x1f\x7f]/
8
+
9
+ export let repoPath = (path: string): boolean =>
10
+ !!path && !path.startsWith('/') && !unsafe.test(path) &&
11
+ path.split('/').every((part) => !!part && part != '.' && part != '..')
12
+
13
+ // What a commit holds at each path, or undefined where Git could not say.
14
+ let listed = async (
15
+ cwd: string,
16
+ commit: string,
17
+ paths: string[],
18
+ ask: Run,
19
+ ): Promise<Map<string, string> | undefined> => {
20
+ let got = await ask([
21
+ '--literal-pathspecs',
22
+ 'ls-tree',
23
+ '-z',
24
+ `${commit}^{commit}`,
25
+ '--',
26
+ ...paths,
27
+ ], cwd)
28
+ if (!got.ok) return
29
+ let out = new Map<string, string>()
30
+ for (let entry of got.out.split('\0')) {
31
+ let match = entry.match(/^100(?:644|755) blob ([a-f0-9]+)\t(.+)$/)
32
+ if (match && paths.includes(match[2])) out.set(match[2], match[1])
33
+ }
34
+ return out
35
+ }
36
+
37
+ /** A commit's regular-file blobs: `(commit, paths)` maps each path the commit
38
+ * holds as a regular file to its blob id. A commit never changes, so each path
39
+ * is asked of Git once while its commit is among the `keep` read most
40
+ * recently, however many callers ask at once; a read Git refused is asked
41
+ * again next time. */
42
+ export let trees = (
43
+ cwd: string,
44
+ { keep = 16, ask = run }: { keep?: number; ask?: Run } = {},
45
+ ): (commit: string, paths: string[]) => Promise<Map<string, string>> => {
46
+ let commits = new Map<string, Map<string, Promise<string | undefined>>>()
47
+ return async (commit, paths) => {
48
+ let out = new Map<string, string>()
49
+ if (!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(commit)) return out
50
+ let safe = [...new Set(paths.filter(repoPath))]
51
+ if (!safe.length) return out
52
+ let seen = commits.get(commit) ?? new Map()
53
+ commits.delete(commit)
54
+ commits.set(commit, seen)
55
+ for (let old of commits.keys()) {
56
+ if (commits.size <= keep) break
57
+ commits.delete(old)
58
+ }
59
+ let missing = safe.filter((p) => !seen.has(p))
60
+ if (missing.length) {
61
+ let asked = listed(cwd, commit, missing, ask)
62
+ for (let path of missing) {
63
+ let blob = asked.then((got) => {
64
+ if (!got && seen.get(path) == blob) seen.delete(path)
65
+ return got?.get(path)
66
+ })
67
+ seen.set(path, blob)
68
+ }
69
+ }
70
+ for (let path of safe) {
71
+ let blob = await seen.get(path)
72
+ if (blob) out.set(path, blob)
73
+ }
74
+ return out
75
+ }
76
+ }
77
+
78
+ /// await commitsOf('.', 'zz') -> []
79
+ /** Every commit an abbreviated or full sha names in the repository at `cwd`,
80
+ * by its full sha, as Git reads one: the one it names, none, or each of
81
+ * several that start that way, which Git refuses to choose between. */
82
+ export let commitsOf = async (
83
+ cwd: string,
84
+ sha: string,
85
+ ask: Run = run,
86
+ ): Promise<string[]> => {
87
+ if (!/^[0-9a-f]{4,64}$/.test(sha)) return []
88
+ let commit = (id: string) =>
89
+ ask(['rev-parse', '--verify', '--quiet', `${id}^{commit}`], cwd)
90
+ let one = await commit(sha)
91
+ if (one.ok) return [one.out.trim()]
92
+ // A prefix Git would not read lists every object it starts, of any type;
93
+ // the commits among them are the ones it names.
94
+ let all = await ask(['rev-parse', `--disambiguate=${sha}`], cwd)
95
+ if (!all.ok) return []
96
+ let peeled = await Promise.all(
97
+ all.out.split('\n').filter(Boolean).map(commit),
98
+ )
99
+ return [...new Set(peeled.filter((p) => p.ok).map((p) => p.out.trim()))]
100
+ }
101
+
102
+ /** All checkout roots, including the primary; observation never prunes Git. */
103
+ export let rootsOf = async (
104
+ common: string,
105
+ ask: Run = run,
106
+ ): Promise<string[]> => {
107
+ let got = await ask([
108
+ '--git-dir=' + common,
109
+ 'worktree',
110
+ 'list',
111
+ '--porcelain',
112
+ ], common)
113
+ if (!got.ok) throw Error(got.err.trim())
114
+ return got.out.split('\n').filter((l) => l.startsWith('worktree '))
115
+ .map((l) => l.slice('worktree '.length))
116
+ }
package/spare.js ADDED
@@ -0,0 +1,108 @@
1
+ /** Git operations and filesystem observations at the worktree boundary. */ let beside = (path)=>path.slice(0, path.lastIndexOf('/')) + '/.spare';
2
+ /** Spare publication and claims share a lock. Git's own lock stays on the
3
+ * registration across each move: even Git renames before updating `gitdir`,
4
+ * so a concurrent prune must see the lock until the final path is registered. */ export let spares = (host)=>{
5
+ let git = host.git;
6
+ let quiet = (source, args)=>git(source, args, true).catch(()=>undefined);
7
+ // Also protect a spare left by an older process, which did not keep it locked.
8
+ let protect = async (source, path)=>{
9
+ let trees = await git(source, [
10
+ 'worktree',
11
+ 'list',
12
+ '--porcelain'
13
+ ]);
14
+ let tree = trees?.split('\n\n').find((tree)=>tree.startsWith(`worktree ${path}\n`));
15
+ if (!tree?.split('\n').some((line)=>/^locked(?: |$)/.test(line))) {
16
+ await git(source, [
17
+ 'worktree',
18
+ 'lock',
19
+ path
20
+ ]);
21
+ }
22
+ };
23
+ let move = (source, from, to)=>git(source, [
24
+ 'worktree',
25
+ 'move',
26
+ '--force',
27
+ '--force',
28
+ from,
29
+ to
30
+ ]);
31
+ let add = async (source, path, flags, target, spare)=>{
32
+ let at = beside(path);
33
+ let taken = spare && await host.lock(source, at, async ()=>{
34
+ if (!await host.exists(at)) return false;
35
+ await protect(source, at);
36
+ await move(source, at, path);
37
+ await git(source, [
38
+ 'worktree',
39
+ 'unlock',
40
+ path
41
+ ]);
42
+ return true;
43
+ });
44
+ if (!taken) {
45
+ await git(source, [
46
+ 'worktree',
47
+ 'add',
48
+ ...flags,
49
+ path,
50
+ target
51
+ ]);
52
+ return;
53
+ }
54
+ try {
55
+ await git(path, [
56
+ 'checkout',
57
+ '--quiet',
58
+ ...flags,
59
+ target
60
+ ]);
61
+ } catch (failure) {
62
+ await quiet(source, [
63
+ 'worktree',
64
+ 'remove',
65
+ '--force',
66
+ path
67
+ ]);
68
+ throw failure;
69
+ }
70
+ };
71
+ let keep = async (source, path, base)=>{
72
+ let at = beside(path);
73
+ await host.lock(source, at, async ()=>{
74
+ if (await host.exists(at)) {
75
+ await protect(source, at);
76
+ return;
77
+ }
78
+ let dir = at.slice(0, at.lastIndexOf('/'));
79
+ for await (let e of host.entries(dir)){
80
+ if (!e.name.startsWith('.spare-')) continue;
81
+ let left = `${dir}/${e.name}`;
82
+ await quiet(source, [
83
+ 'worktree',
84
+ 'remove',
85
+ '--force',
86
+ '--force',
87
+ left
88
+ ]);
89
+ await host.remove(left);
90
+ }
91
+ let cut = `${at}-${crypto.randomUUID()}`;
92
+ await git(source, [
93
+ 'worktree',
94
+ 'add',
95
+ '--detach',
96
+ '--lock',
97
+ cut,
98
+ base
99
+ ]);
100
+ await move(source, cut, at);
101
+ });
102
+ };
103
+ return {
104
+ add,
105
+ keep
106
+ };
107
+ };
108
+ //# sourceMappingURL=spare.js.map
package/spare.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spare.js","sources":["./spare.ts"],"names":[],"mappings":"AAAA,yEAAyE,GAiBzE,IAAI,SAAS,CAAC,OAAiB,KAAK,KAAK,CAAC,GAAG,KAAK,WAAW,CAAC,QAAQ;AAEtE;;+EAE+E,GAC/E,OAAO,IAAI,SAAS,CAAC;EAUnB,IAAI,MAAM,KAAK,GAAG;EAClB,IAAI,QAAQ,CAAC,QAAgB,OAC3B,IAAI,QAAQ,MAAM,MAAM,KAAK,CAAC,IAAM;EACtC,+EAA+E;EAC/E,IAAI,UAAU,OAAO,QAAgB;IACnC,IAAI,QAAQ,MAAM,IAAI,QAAQ;MAAC;MAAY;MAAQ;KAAc;IACjE,IAAI,OAAO,OAAO,MAAM,QAAQ,KAAK,CAAC,OACpC,KAAK,UAAU,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC;IAEtC,IAAI,CAAC,MAAM,MAAM,MAAM,KAAK,CAAC,OAAS,iBAAiB,IAAI,CAAC,QAAQ;MAClE,MAAM,IAAI,QAAQ;QAAC;QAAY;QAAQ;OAAK;IAC9C;EACF;EACA,IAAI,OAAO,CAAC,QAAgB,MAAc,KACxC,IAAI,QAAQ;MAAC;MAAY;MAAQ;MAAW;MAAW;MAAM;KAAG;EAClE,IAAI,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F;EACA,OAAO;IAAE;IAAK;EAAK;AACrB,EAAC"}
package/spare.ts ADDED
@@ -0,0 +1,94 @@
1
+ /** Git operations and filesystem observations at the worktree boundary. */
2
+ export type Host = {
3
+ git: (
4
+ cwd: string,
5
+ args: string[],
6
+ optional?: boolean,
7
+ ) => Promise<string | undefined>
8
+ exists: (path: string) => Promise<boolean>
9
+ entries: (path: string) => AsyncIterable<{ name: string }>
10
+ remove: (path: string) => Promise<void>
11
+ lock: <T>(
12
+ source: string,
13
+ path: string,
14
+ change: () => Promise<T>,
15
+ ) => Promise<T>
16
+ }
17
+
18
+ let beside = (path: string) => path.slice(0, path.lastIndexOf('/')) + '/.spare'
19
+
20
+ /** Spare publication and claims share a lock. Git's own lock stays on the
21
+ * registration across each move: even Git renames before updating `gitdir`,
22
+ * so a concurrent prune must see the lock until the final path is registered. */
23
+ export let spares = (host: Host): {
24
+ add: (
25
+ source: string,
26
+ path: string,
27
+ flags: string[],
28
+ target: string,
29
+ spare?: boolean,
30
+ ) => Promise<void>
31
+ keep: (source: string, path: string, base: string) => Promise<void>
32
+ } => {
33
+ let git = host.git
34
+ let quiet = (source: string, args: string[]) =>
35
+ git(source, args, true).catch(() => undefined)
36
+ // Also protect a spare left by an older process, which did not keep it locked.
37
+ let protect = async (source: string, path: string) => {
38
+ let trees = await git(source, ['worktree', 'list', '--porcelain'])
39
+ let tree = trees?.split('\n\n').find((tree) =>
40
+ tree.startsWith(`worktree ${path}\n`)
41
+ )
42
+ if (!tree?.split('\n').some((line) => /^locked(?: |$)/.test(line))) {
43
+ await git(source, ['worktree', 'lock', path])
44
+ }
45
+ }
46
+ let move = (source: string, from: string, to: string) =>
47
+ git(source, ['worktree', 'move', '--force', '--force', from, to])
48
+ let add = async (
49
+ source: string,
50
+ path: string,
51
+ flags: string[],
52
+ target: string,
53
+ spare?: boolean,
54
+ ) => {
55
+ let at = beside(path)
56
+ let taken = spare && await host.lock(source, at, async () => {
57
+ if (!await host.exists(at)) return false
58
+ await protect(source, at)
59
+ await move(source, at, path)
60
+ await git(source, ['worktree', 'unlock', path])
61
+ return true
62
+ })
63
+ if (!taken) {
64
+ await git(source, ['worktree', 'add', ...flags, path, target])
65
+ return
66
+ }
67
+ try {
68
+ await git(path, ['checkout', '--quiet', ...flags, target])
69
+ } catch (failure) {
70
+ await quiet(source, ['worktree', 'remove', '--force', path])
71
+ throw failure
72
+ }
73
+ }
74
+ let keep = async (source: string, path: string, base: string) => {
75
+ let at = beside(path)
76
+ await host.lock(source, at, async () => {
77
+ if (await host.exists(at)) {
78
+ await protect(source, at)
79
+ return
80
+ }
81
+ let dir = at.slice(0, at.lastIndexOf('/'))
82
+ for await (let e of host.entries(dir)) {
83
+ if (!e.name.startsWith('.spare-')) continue
84
+ let left = `${dir}/${e.name}`
85
+ await quiet(source, ['worktree', 'remove', '--force', '--force', left])
86
+ await host.remove(left)
87
+ }
88
+ let cut = `${at}-${crypto.randomUUID()}`
89
+ await git(source, ['worktree', 'add', '--detach', '--lock', cut, base])
90
+ await move(source, cut, at)
91
+ })
92
+ }
93
+ return { add, keep }
94
+ }
package/tools.js ADDED
@@ -0,0 +1,278 @@
1
+ // The implementations behind the `tool: true` declarations in ./vocab.json,
2
+ // exported as `@yaks/git/tools`.
3
+ //
4
+ // File tools read the machine running the call. `land` takes its checkout
5
+ // explicitly as `cwd`: the CLI fills its current directory, and an MCP
6
+ // caller names its own, even when sub-agents share the connection.
7
+ //
8
+ // A landing refused for the caller's own state is an expected invocation
9
+ // failure: a moved base is returned as a divergence, which becomes a
10
+ // `CallError` carrying Git's whole account, and a worktree that is dirty,
11
+ // detached or on the base, or a revert the guard caught, is a `LandError`,
12
+ // which is one already. The tool
13
+ // runner records either as a failed call and a command line reports it as
14
+ // exit 1. An unexpected Git command failure escapes as a plain error, for the
15
+ // runner to report as the fault it is.
16
+ //
17
+ // `cites check` is a check — a tool whose verb is `check`, which is all a
18
+ // doctor is (@yaks/tools ./check.ts) — so a citation that moved is a finding
19
+ // in a report, never a refused write. It enforces nothing, on purpose: a
20
+ // document whose code moved is work somebody has to do, not a transaction to
21
+ // reject. `cites verify` is the only thing that writes the `verified` mark,
22
+ // which is what keeps the mark meaning "somebody looked" rather than
23
+ // "somebody edited this".
24
+ //
25
+ import { argsOf } from "@yaks/graph/call";
26
+ import { Refused } from "@yaks/graph/errors";
27
+ import { and, present, want } from "@yaks/query";
28
+ import { human, idsIn, parse, prefixOf } from "@yaks/id";
29
+ import { verify as entityVerify } from "@yaks/kernel";
30
+ import { once } from "@yaks/fp";
31
+ import { CallError } from "@yaks/tools/errors";
32
+ import { checked } from "@yaks/tools/check";
33
+ import { land, run as git } from "./land.js";
34
+ import { localFilesystem, locate, repositoryEid } from "./host.js";
35
+ import { CITES, FILE, LINES, REVISION, status, SYMBOL, tracked, VERIFIED, within } from "./cites.js";
36
+ let str = (v)=>v == null ? '' : String(v);
37
+ let comp = (b, name)=>b?.[name];
38
+ let count = (v)=>typeof v == 'number' && Number.isFinite(v) ? v : undefined;
39
+ // Every citation, with the marks its state is derived from: a read names each
40
+ // component it wants, so one left out reads as never written.
41
+ let citations = async (graph)=>await graph.read(and(present(CITES), want('edge'), want(VERIFIED), want(REVISION)));
42
+ // Every entity the citations reach: both ends, the file a cited symbol or
43
+ // place is in, and the root each file is read in.
44
+ let reach = async (graph, cites)=>{
45
+ let at = new Map();
46
+ let add = async (eids)=>{
47
+ let more = [
48
+ ...new Set(eids.map(str))
49
+ ].filter((eid)=>eid && !at.has(eid));
50
+ if (!more.length) return;
51
+ for (let b of (await graph.get(more)))at.set(b.entity.eid, b);
52
+ };
53
+ await add(cites.flatMap((b)=>[
54
+ comp(b, 'edge')?.from,
55
+ comp(b, 'edge')?.to
56
+ ]));
57
+ await add([
58
+ ...at.values()
59
+ ].map(within));
60
+ await add([
61
+ ...at.values()
62
+ ].map((b)=>comp(b, FILE)?.root));
63
+ return at;
64
+ };
65
+ let cwdOf = (call, verb)=>{
66
+ let cwd = comp(call, 'process')?.cwd;
67
+ if (!cwd) {
68
+ throw new CallError('cwd', `${verb} reads a checkout, and this graph runs nowhere in particular`);
69
+ }
70
+ return String(cwd);
71
+ };
72
+ // The checkout holding `cwd`, at its top, and the repository it is a checkout
73
+ // of on this computer's filesystem. Nothing when `cwd` is in no checkout.
74
+ let checkoutOf = async (graph, cwd)=>{
75
+ let found = await locate(cwd);
76
+ if (!found) return undefined;
77
+ let workspace = (await localFilesystem(graph)).entity.eid;
78
+ return {
79
+ cwd: found.path,
80
+ repository: repositoryEid(found.common, workspace)
81
+ };
82
+ };
83
+ // Where a citation points, in one phrase: the file and the place in it, or the
84
+ // entity it names.
85
+ let where = (to, file, id)=>{
86
+ let path = str(comp(file, FILE)?.path);
87
+ if (!path) return id(to);
88
+ let name = str(comp(to, SYMBOL)?.name);
89
+ if (name) return `${path}:${name}`;
90
+ let start = count(comp(to, LINES)?.start);
91
+ if (start == null) return path;
92
+ return `${path}:${start}-${count(comp(to, LINES)?.end) ?? start}`;
93
+ };
94
+ // How a state reads in a report. A citation that moved is a measured fact, so
95
+ // it fails; one nobody has checked, or one nothing could establish an answer
96
+ // for, is a warning — the check could not vouch either way.
97
+ let verdict = (got)=>got.state == 'moved' ? [
98
+ 'fail',
99
+ got.changes?.length ? `moved by ${got.changes.join(', ')}` : 'cited content changed'
100
+ ] : got.state == 'unverified' ? [
101
+ 'warn',
102
+ 'never checked'
103
+ ] : [
104
+ 'warn',
105
+ `no answer: ${got.why}`
106
+ ];
107
+ /** Landing with Git supplied at the effect boundary. Each commit that landed
108
+ * is recorded as `commit{target, message}`, its eid the sha, created through
109
+ * the caller's session; its target is the task its first line names. */ export let landing = (run, report)=>async (call, graph)=>{
110
+ let args = argsOf(call);
111
+ let cwd = str(args.cwd);
112
+ // Git's output, exactly as Git wrote it, collected in the order it
113
+ // arrived: what the caller reads is Git's own account, not a summary of
114
+ // it.
115
+ let said = [];
116
+ let outcome = await run({
117
+ cwd,
118
+ allow: str(args['allow-revert']).split(',').filter(Boolean),
119
+ report,
120
+ write: (text)=>{
121
+ let line = text.trimEnd();
122
+ if (line) said.push(line);
123
+ }
124
+ });
125
+ if (!('landed' in outcome)) {
126
+ throw new CallError('diverged', said.join('\n'));
127
+ }
128
+ // A graph without commit vocabulary records nothing.
129
+ let landed = graph?.vocab.comp('commit') ? outcome.commits : [];
130
+ // The task a commit's first line names (T-12), as the graph addresses it.
131
+ let series = landed.length ? prefixOf(graph.vocab)('task') : '';
132
+ let named = landed.map((c)=>idsIn(c.message.split('\n')[0]).find((id)=>parse(id)?.prefix == series));
133
+ let ids = [
134
+ ...new Set(named.filter((id)=>!!id))
135
+ ];
136
+ let at = ids.length ? await graph.address(ids) : new Map();
137
+ return [
138
+ {
139
+ entity: {
140
+ eid: '$landed'
141
+ },
142
+ content: {
143
+ body: [
144
+ ...said,
145
+ `landed ${outcome.landed}`
146
+ ].join('\n')
147
+ },
148
+ output: {
149
+ source: call.entity.eid
150
+ }
151
+ },
152
+ ...landed.map((c, i)=>({
153
+ entity: {
154
+ eid: c.sha
155
+ },
156
+ commit: {
157
+ message: c.message,
158
+ ...at.get(named[i] ?? '') ? {
159
+ target: at.get(named[i])
160
+ } : {}
161
+ }
162
+ }))
163
+ ];
164
+ };
165
+ /** The implementations of the tools ./vocab.json declares. The host's
166
+ * `report` hears a failure land catches and carries on past. */ export let runs = (host)=>({
167
+ land: landing(land, host?.report),
168
+ cites_check: async (call, graph)=>{
169
+ let args = argsOf(call);
170
+ let cwd = str(comp(call, 'process')?.cwd) || undefined;
171
+ let id = human(graph.vocab);
172
+ let of = str(args.of);
173
+ let scope = of || undefined;
174
+ let path = str(args.path);
175
+ let cites = await citations(graph);
176
+ let at = await reach(graph, cites);
177
+ // The checkout the call was made in: asked once, and only when a citation
178
+ // of a file needs it.
179
+ let ours = once(async ()=>cwd ? await checkoutOf(graph, cwd) : undefined);
180
+ // The path names a file of this checkout's repository, when there is one.
181
+ let named = async (file)=>{
182
+ if (str(comp(file, FILE)?.path) != path) return false;
183
+ let repository = (await ours())?.repository;
184
+ return !repository || str(comp(file, FILE)?.root) == repository;
185
+ };
186
+ let found = [];
187
+ for (let cite of cites){
188
+ let edge = comp(cite, 'edge');
189
+ let from = at.get(str(edge?.from));
190
+ let to = at.get(str(edge?.to));
191
+ if (!from) continue;
192
+ if (scope && from.entity.eid != scope) continue;
193
+ if (!to) {
194
+ if (path) continue;
195
+ found.push({
196
+ level: 'fail',
197
+ text: `${id(from)} cites ${str(edge?.to)} — cited entity is gone`
198
+ });
199
+ continue;
200
+ }
201
+ let file = tracked(to, (eid)=>at.get(eid));
202
+ if (path && !await named(file)) continue;
203
+ let checkout = file ? await ours() : undefined;
204
+ let got = await status(cite, to, {
205
+ checkout,
206
+ vocab: graph.vocab
207
+ }, file);
208
+ if (got.state == 'current') continue;
209
+ let [level, why] = verdict(got);
210
+ found.push({
211
+ level,
212
+ text: `${id(from)} cites ${where(to, file, id)} — ${why}`
213
+ });
214
+ }
215
+ return checked(call.entity.eid, 'every citation still holds', found);
216
+ },
217
+ cites_verify: async (call, graph)=>{
218
+ let args = argsOf(call);
219
+ let cite = str(args.cite);
220
+ let of = str(args.of);
221
+ if (!cite && !of) {
222
+ throw new Refused('verify needs a citation, or an entity whose citations to verify');
223
+ }
224
+ let asked = cite || of;
225
+ let found = cite ? (await graph.get([
226
+ asked
227
+ ])).filter((b)=>b[CITES]) : (await citations(graph)).filter((b)=>str(comp(b, 'edge')?.from) == asked);
228
+ if (!found.length) {
229
+ throw new Refused(cite ? `${cite} is not a citation` : `${of} makes no citations to verify`);
230
+ }
231
+ let at = await reach(graph, found);
232
+ let toOf = (b)=>at.get(str(comp(b, 'edge')?.to));
233
+ // The file of a repository a citation is checked against in Git, if any.
234
+ let gitFile = (b)=>{
235
+ let to = toOf(b);
236
+ return to && tracked(to, (eid)=>at.get(eid));
237
+ };
238
+ for (let b of found){
239
+ let to = toOf(b);
240
+ if (to && comp(to, SYMBOL) && !gitFile(b)) {
241
+ throw new Refused(`the cited symbol ${to.entity.eid} has no file to check`);
242
+ }
243
+ }
244
+ let files = found.map(gitFile).filter((f)=>!!f);
245
+ let commit = '';
246
+ if (files.length) {
247
+ let cwd = cwdOf(call, 'verifying a file citation');
248
+ let checkout = await checkoutOf(graph, cwd);
249
+ if (!checkout) throw new CallError('cwd', `${cwd} is in no checkout`);
250
+ let other = files.find((f)=>str(comp(f, FILE)?.root) != checkout.repository);
251
+ if (other) {
252
+ throw new CallError('cwd', `${str(comp(other, FILE)?.path)} is a file of another repository ` + 'than this checkout; verify it in a checkout of its own');
253
+ }
254
+ let head = await git([
255
+ 'rev-parse',
256
+ 'HEAD'
257
+ ], checkout.cwd);
258
+ if (!head.ok) {
259
+ throw new CallError('head', head.err.trim() || 'this checkout is on no commit');
260
+ }
261
+ commit = head.out.trim();
262
+ }
263
+ return found.map((b)=>{
264
+ let to = toOf(b);
265
+ if (!to) throw new Refused(`citation ${b.entity.eid} names no entity`);
266
+ return gitFile(b) ? {
267
+ entity: {
268
+ eid: b.entity.eid
269
+ },
270
+ [VERIFIED]: {},
271
+ [REVISION]: {
272
+ commit
273
+ }
274
+ } : entityVerify(b, to, graph.vocab);
275
+ });
276
+ }
277
+ });
278
+ //# sourceMappingURL=tools.js.map
package/tools.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sources":["./tools.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,iCAAiC;AACjC,EAAE;AACF,0EAA0E;AAC1E,uEAAuE;AACvE,mEAAmE;AACnE,EAAE;AACF,yEAAyE;AACzE,qEAAqE;AACrE,0EAA0E;AAC1E,2EAA2E;AAC3E,iCAAiC;AACjC,0EAA0E;AAC1E,8EAA8E;AAC9E,uCAAuC;AACvC,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,yEAAyE;AACzE,6EAA6E;AAC7E,4EAA4E;AAC5E,qEAAqE;AACrE,0BAA0B;AAC1B,EAAE;AAEF,SAAS,MAAM,gCAAqC;AACpD,SAAS,OAAO,kCAAuC;AAEvD,SAAS,GAAG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