@eliya-oss/agent-diff 0.1.0-alpha.216 → 0.1.0-alpha.218

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 (60) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +1 -1
  3. package/dist/main.js +9 -5
  4. package/dist/web/nitro.json +1 -1
  5. package/dist/web/public/assets/index-BCc7tdE9.js +12 -0
  6. package/dist/web/public/assets/index-Bh4VvgUA.css +2 -0
  7. package/dist/web/public/assets/{rolldown-runtime-XKyaHtl9.js → jsx-runtime-EIAPxkjE.js} +1 -1
  8. package/dist/web/public/assets/review-CLHgc7OK.js +44 -0
  9. package/dist/web/public/assets/routes-CS6_XKJl.js +1 -0
  10. package/dist/web/server/_libs/@base-ui/react+[...].mjs +2686 -4472
  11. package/dist/web/server/_libs/@tanstack/react-router+[...].mjs +1 -107
  12. package/dist/web/server/_libs/lucide-react.mjs +93 -268
  13. package/dist/web/server/_libs/react-markdown+[...].mjs +1 -1
  14. package/dist/web/server/_libs/valibot.mjs +1 -59
  15. package/dist/web/server/_ssr/highlight.server-Ch_kPZFd.mjs +199 -0
  16. package/dist/web/server/_ssr/{listener.functions-DygHonX4.mjs → listener.functions-r5sy6slm.mjs} +7 -7
  17. package/dist/web/server/_ssr/{listener.server-BUJSjrgf.mjs → listener.server-Ch_E4TJ7.mjs} +3 -2
  18. package/dist/web/server/_ssr/{review-block-DusFmCX_.mjs → review-CXA8hOed.mjs} +5200 -5492
  19. package/dist/web/server/_ssr/review-folder.server-DrhuBcAc.mjs +354 -0
  20. package/dist/web/server/_ssr/{adhoc.functions-CDadmCcu.mjs → review-link.functions-BvcyZSk2.mjs} +12 -11
  21. package/dist/web/server/_ssr/review-link.server-XUXU8Jjl.mjs +180 -0
  22. package/dist/web/server/_ssr/{review-parts.server-j_3LS0HZ.mjs → review-parts.server-CSSa-ZRv.mjs} +2 -2
  23. package/dist/web/server/_ssr/review-read.functions-Da-f7qpe.mjs +37 -0
  24. package/dist/web/server/_ssr/{live-schema-BYm_IvNp.mjs → review-schema-C0qXng9-.mjs} +5 -64
  25. package/dist/web/server/_ssr/review-target.server-C8IXgmE-.mjs +18 -0
  26. package/dist/web/server/_ssr/{review.functions-Cvig5BYP.mjs → review.functions-BYEhPk_l.mjs} +19 -17
  27. package/dist/web/server/_ssr/review.server-DFe2jCWt.mjs +847 -0
  28. package/dist/web/server/_ssr/{router-CpBxvGJX.mjs → router-DqvyAgJl.mjs} +119 -257
  29. package/dist/web/server/_ssr/routes-6k-4pwuW.mjs +20 -0
  30. package/dist/web/server/_ssr/ssr.mjs +36 -72
  31. package/dist/web/server/_ssr/{thread-code-BWhoBW-5.mjs → thread-code-CYNB3wg5.mjs} +2 -3
  32. package/dist/web/server/_ssr/{type-hover-DSq-tkS_.mjs → type-hover-BWVNL2Vt.mjs} +2 -3
  33. package/dist/web/server/_ssr/{type-hover.functions-B_9iC3Xs.mjs → type-hover.functions-oAqPixru.mjs} +6 -5
  34. package/dist/web/server/_tanstack-start-manifest_v-BBV9HPN6.mjs +30 -0
  35. package/dist/web/server/index.mjs +25 -88
  36. package/package.json +1 -1
  37. package/skills/adiff-web/SKILL.md +2 -2
  38. package/dist/web/public/assets/_deck-BmRfIUSA.js +0 -1
  39. package/dist/web/public/assets/_point-BVE7ChTL.js +0 -1
  40. package/dist/web/public/assets/adhoc.functions-C2dHzbMd.js +0 -1
  41. package/dist/web/public/assets/decks.functions-tXNTG2sC.js +0 -2
  42. package/dist/web/public/assets/index-B1ZY8zdK.css +0 -2
  43. package/dist/web/public/assets/index-aVNw-2pB.js +0 -11
  44. package/dist/web/public/assets/preload-helper-D5PXivxI.js +0 -1
  45. package/dist/web/public/assets/review-block-BEAsY2QM.js +0 -47
  46. package/dist/web/public/assets/review-w-sdAG51.js +0 -1
  47. package/dist/web/public/assets/routes-BvjPl7Jk.js +0 -1
  48. package/dist/web/public/assets/shortcuts-BsNWbUaT.js +0 -1
  49. package/dist/web/public/assets/use-window-event-BDUVK1pJ.js +0 -1
  50. package/dist/web/public/assets/viewed-store-Cwoyp53w.js +0 -1
  51. package/dist/web/server/_deck-DFij1FXC.mjs +0 -387
  52. package/dist/web/server/_libs/yaml.mjs +0 -6585
  53. package/dist/web/server/_point-CIICFuLm.mjs +0 -1528
  54. package/dist/web/server/_ssr/decks.functions-BHxu668D.mjs +0 -1073
  55. package/dist/web/server/_ssr/review-DBgvCWDX.mjs +0 -58
  56. package/dist/web/server/_ssr/review-target.server-DA41RDao.mjs +0 -1779
  57. package/dist/web/server/_ssr/routes-pAqxw-ZQ.mjs +0 -27
  58. package/dist/web/server/_ssr/shortcuts-B7llaLLc.mjs +0 -228
  59. package/dist/web/server/_ssr/viewed-store-CyYRWeAX.mjs +0 -198
  60. package/dist/web/server/_tanstack-start-manifest_v-Bf1fW3Lx.mjs +0 -56
@@ -0,0 +1,354 @@
1
+ import { READ_ONLY_GIT, getRealWorktree, getWorktreeMark } from "./review-link.server-XUXU8Jjl.mjs";
2
+ import { accessSync, constants, readdirSync, realpathSync, statSync } from "node:fs";
3
+ import { delimiter, join } from "node:path";
4
+ import { execFileSync, spawn } from "node:child_process";
5
+ import { homedir } from "node:os";
6
+ import { once } from "node:events";
7
+ import { createInterface } from "node:readline";
8
+ // node_modules/.nitro/vite/services/ssr/assets/review-folder.server-DrhuBcAc.js
9
+ /**
10
+ * The oldest adiff the page runs. The page draws what adiff decides, and before 0.1.0-alpha.203
11
+ * adiff does not say which rows a layer keeps in place as quiet lines, so the page would fold them;
12
+ * before 0.1.0-alpha.200 it does not answer the mark on each line or how many settled threads a
13
+ * file and a line hold, and rewrites the branch's state without what newer versions keep there.
14
+ */
15
+ var OLDEST = "0.1.0-alpha.203";
16
+ /** How long a refusal stands before the version is read again, so an update takes effect. */
17
+ var RECHECK_MS = 3e4;
18
+ /** The parts of a version to compare in order: 0.1.0-alpha.195 is [0, 1, 0, 195]. */
19
+ var partsOf = (version) => (version.match(/\d+/gu) ?? []).map(Number);
20
+ var isOlder = (version, than) => {
21
+ const mine = partsOf(version);
22
+ const theirs = partsOf(than);
23
+ const at = mine.findIndex((part, index) => part !== (theirs[index] ?? 0));
24
+ return at === -1 ? mine.length < theirs.length && version.includes("-") : (mine[at] ?? 0) < (theirs[at] ?? 0);
25
+ };
26
+ /** Where a bare command name resolves on PATH, as the spawn will find it. */
27
+ var resolve$1 = (bin) => {
28
+ if (bin.includes("/")) return bin;
29
+ const found = (process.env["PATH"] ?? "").split(delimiter).find((dir) => {
30
+ try {
31
+ accessSync(join(dir, bin), constants.X_OK);
32
+ return true;
33
+ } catch {
34
+ return false;
35
+ }
36
+ });
37
+ return found === void 0 ? bin : join(found, bin);
38
+ };
39
+ var readVersion = (command) => {
40
+ const [bin = "adiff", ...lead] = command;
41
+ try {
42
+ return execFileSync(bin, [...lead, "--version"], { stdio: [
43
+ "ignore",
44
+ "pipe",
45
+ "ignore"
46
+ ] }).toString().trim();
47
+ } catch {
48
+ return null;
49
+ }
50
+ };
51
+ var checked = {
52
+ at: -Infinity,
53
+ refusal: null
54
+ };
55
+ var refusalFor = (command) => {
56
+ const version = readVersion(command);
57
+ return version !== null && isOlder(version, OLDEST) ? `${resolve$1(command[0] ?? "adiff")} is adiff ${version}; the page needs ${OLDEST} or later. Install the newest release, or point ADIFF_BIN at it.` : null;
58
+ };
59
+ /**
60
+ * Why the page will not run this adiff, else null: read once, and again every 30 seconds while
61
+ * it refuses. An adiff whose version cannot be read is left to fail on its own. The refusal is
62
+ * the error every review call answers with, so the page shows it.
63
+ */
64
+ var getRefusal = (command) => {
65
+ if (checked.refusal === null && checked.at > -Infinity || Date.now() - checked.at < RECHECK_MS) return checked.refusal;
66
+ checked.at = Date.now();
67
+ checked.refusal = refusalFor(command);
68
+ return checked.refusal;
69
+ };
70
+ var RETRY_MS = 3e4;
71
+ var SHARED = Symbol.for("adiff-web.serve");
72
+ /**
73
+ * One adiff serve for the whole server, held on the global object rather than in this module:
74
+ * Vite runs the module again after an edit in dev, and a copy with its own state started another
75
+ * serve each time, leaving the old ones running for as long as the server did.
76
+ */
77
+ var shared = globalThis;
78
+ shared[SHARED] ??= {
79
+ served: null,
80
+ downUntil: 0,
81
+ nextId: 0
82
+ };
83
+ var state = shared[SHARED];
84
+ var getCommand = () => (process.env["ADIFF_BIN"] ?? "adiff").split(" ").filter(Boolean);
85
+ var isObject = (value) => typeof value === "object" && value !== null;
86
+ var readLine = (line) => {
87
+ try {
88
+ const parsed = JSON.parse(line);
89
+ return isObject(parsed) && typeof parsed["id"] === "number" ? parsed : null;
90
+ } catch {
91
+ return null;
92
+ }
93
+ };
94
+ var hear = (current, line) => {
95
+ const heard = readLine(line);
96
+ const id = Number(heard?.["id"]);
97
+ if (heard === null) return;
98
+ if (heard["event"] === "changed") {
99
+ const what = Array.isArray(heard["what"]) ? heard["what"].map(String) : ["other"];
100
+ current.watchers.get(id)?.onChange(what);
101
+ return;
102
+ }
103
+ current.pending.get(id)?.resolve({
104
+ exit: Number(heard["exit"] ?? 1),
105
+ answer: heard["answer"]
106
+ });
107
+ current.pending.delete(id);
108
+ };
109
+ var lose = (current) => {
110
+ if (state.served === current) {
111
+ state.served = null;
112
+ state.downUntil = Date.now() + RETRY_MS;
113
+ }
114
+ current.pending.forEach((waiting) => {
115
+ waiting.reject(/* @__PURE__ */ new Error("adiff serve stopped"));
116
+ });
117
+ current.pending.clear();
118
+ const lost = [...current.watchers.values()];
119
+ current.watchers.clear();
120
+ lost.forEach((watcher) => {
121
+ watcher.onLost();
122
+ });
123
+ };
124
+ var spawnServed = () => {
125
+ const [bin = "adiff", ...lead] = getCommand();
126
+ const child = spawn(bin, [...lead, "serve"], {
127
+ env: READ_ONLY_GIT,
128
+ stdio: [
129
+ "pipe",
130
+ "pipe",
131
+ "pipe"
132
+ ]
133
+ });
134
+ const current = {
135
+ child,
136
+ pending: /* @__PURE__ */ new Map(),
137
+ watchers: /* @__PURE__ */ new Map()
138
+ };
139
+ createInterface({ input: child.stdout }).on("line", (line) => {
140
+ hear(current, line);
141
+ });
142
+ child.on("exit", () => {
143
+ lose(current);
144
+ });
145
+ child.on("error", () => {
146
+ lose(current);
147
+ });
148
+ child.stdin.on("error", () => {
149
+ lose(current);
150
+ });
151
+ return current;
152
+ };
153
+ var start = () => {
154
+ if (state.served === null && Date.now() >= state.downUntil) state.served = spawnServed();
155
+ return state.served;
156
+ };
157
+ var send = (current, request) => {
158
+ current.child.stdin.write(`${JSON.stringify(request)}\n`);
159
+ };
160
+ var lastJson = (said) => said.split("\n").findLast((candidate) => candidate.startsWith("{")) ?? "{}";
161
+ var toAnswered = (said, exit) => {
162
+ try {
163
+ return {
164
+ exit,
165
+ answer: JSON.parse(lastJson(said))
166
+ };
167
+ } catch {
168
+ return {
169
+ exit: 1,
170
+ answer: {
171
+ ok: false,
172
+ error: {
173
+ type: "AdiffFailed",
174
+ suggestion: said
175
+ }
176
+ }
177
+ };
178
+ }
179
+ };
180
+ var collect = (stream) => {
181
+ const chunks = [];
182
+ stream.setEncoding("utf8");
183
+ stream.on("data", (chunk) => {
184
+ chunks.push(chunk);
185
+ });
186
+ return chunks;
187
+ };
188
+ var spawned = async (args) => {
189
+ const [bin = "adiff", ...lead] = getCommand();
190
+ const child = spawn(bin, [...lead, ...args], {
191
+ env: READ_ONLY_GIT,
192
+ stdio: [
193
+ "ignore",
194
+ "pipe",
195
+ "pipe"
196
+ ]
197
+ });
198
+ const stdout = collect(child.stdout);
199
+ const stderr = collect(child.stderr);
200
+ const closed = await once(child, "close");
201
+ const exit = Number(closed[0] ?? 1);
202
+ return toAnswered((exit === 0 ? stdout : stderr).join(""), exit);
203
+ };
204
+ var isNotServed = (answered) => isObject(answered.answer) && isObject(answered.answer["error"]) && ["UnknownCommand", "NotServed"].includes(String(answered.answer["error"]["type"]));
205
+ var takeId = () => {
206
+ state.nextId += 1;
207
+ return state.nextId;
208
+ };
209
+ var askServed = (current, args) => {
210
+ const id = takeId();
211
+ const waiting = Promise.withResolvers();
212
+ current.pending.set(id, waiting);
213
+ send(current, {
214
+ id,
215
+ args
216
+ });
217
+ return waiting.promise;
218
+ };
219
+ var ask = async (args) => {
220
+ const refusal = getRefusal(getCommand());
221
+ if (refusal !== null) return {
222
+ exit: 1,
223
+ answer: {
224
+ ok: false,
225
+ error: {
226
+ type: "AdiffTooOld",
227
+ suggestion: refusal
228
+ }
229
+ }
230
+ };
231
+ const current = start();
232
+ if (current === null) return spawned(args);
233
+ try {
234
+ const answered = await askServed(current, args);
235
+ return isNotServed(answered) ? await spawned(args) : answered;
236
+ } catch {
237
+ return spawned(args);
238
+ }
239
+ };
240
+ var watch$1 = (address, handlers) => {
241
+ const current = getRefusal(getCommand()) === null ? start() : null;
242
+ if (current === null) return null;
243
+ const id = takeId();
244
+ current.watchers.set(id, handlers);
245
+ send(current, {
246
+ id,
247
+ watch: address
248
+ });
249
+ return () => {
250
+ current.watchers.delete(id);
251
+ if (state.served === current) send(current, {
252
+ id,
253
+ unwatch: true
254
+ });
255
+ };
256
+ };
257
+ /** The file a listening agent rewrites every half second: it says nothing about the review. */
258
+ var HEARTBEAT = "watch.json";
259
+ var getAdiffRoot = () => process.env["ADIFF_ROOT"] ?? join(homedir(), ".adiff");
260
+ /** Adiff keys a review by `<git common dir>#<branch>`, each run of other characters as "-". */
261
+ var getReviewKey = (address) => {
262
+ const common = execFileSync("git", [
263
+ "-C",
264
+ address.repo,
265
+ "rev-parse",
266
+ "--path-format=absolute",
267
+ "--git-common-dir"
268
+ ], {
269
+ env: READ_ONLY_GIT,
270
+ stdio: [
271
+ "ignore",
272
+ "pipe",
273
+ "ignore"
274
+ ]
275
+ }).toString().trim();
276
+ return `${realpathSync(common)}#${address.branch}`.replaceAll(/[^a-zA-Z0-9]+/gu, "-");
277
+ };
278
+ /** Where adiff keeps a review's comments, marks, layers and drafts, or null when git cannot say. */
279
+ var getReviewFolder = (address) => {
280
+ try {
281
+ return join(getAdiffRoot(), "branches", getReviewKey(address));
282
+ } catch {
283
+ return null;
284
+ }
285
+ };
286
+ var markOf = (folder, name) => {
287
+ try {
288
+ const { mtimeMs, size } = statSync(join(folder, name));
289
+ return `${name}:${String(mtimeMs)}:${String(size)}`;
290
+ } catch {
291
+ return `${name}:gone`;
292
+ }
293
+ };
294
+ /**
295
+ * A cheap mark of the review's files, the heartbeat aside, which says whether an outline read is
296
+ * still current. A folder that is not there yet has the empty mark.
297
+ */
298
+ var getFolderMark = (folder) => {
299
+ try {
300
+ return readdirSync(folder).filter((name) => name !== HEARTBEAT).toSorted().map((name) => markOf(folder, name)).join("\n");
301
+ } catch {
302
+ return "";
303
+ }
304
+ };
305
+ var places = /* @__PURE__ */ new Map();
306
+ var placesOf = (address) => {
307
+ const key = `${address.repo}|${address.branch}`;
308
+ const known = places.get(key) ?? {
309
+ folder: getReviewFolder(address),
310
+ worktree: getRealWorktree(address)
311
+ };
312
+ places.set(key, known);
313
+ return known;
314
+ };
315
+ /**
316
+ * What a read of the review depends on: the branch head, the times of adiff's files for it, and the
317
+ * worktree's uncommitted files.
318
+ */
319
+ var signOf = (address, head) => {
320
+ const { folder, worktree } = placesOf(address);
321
+ return [
322
+ head,
323
+ folder === null ? "" : getFolderMark(folder),
324
+ worktree === null ? "" : getWorktreeMark(worktree)
325
+ ].join("\n");
326
+ };
327
+ /** How long a whole read answers the next request for a fresh one, when nothing moved since. */
328
+ var JUST_READ_MS = 2e3;
329
+ var justRead = /* @__PURE__ */ new Map();
330
+ var noteRead = (key, sign) => {
331
+ justRead.set(key, {
332
+ sign,
333
+ at: Date.now()
334
+ });
335
+ };
336
+ /**
337
+ * A page that opens asks for the outline it can have at once, then for a fresh one. When the first
338
+ * had to be read, the second would read the same thing again, seconds of adiff on a large branch,
339
+ * so a whole read that has just ended answers it while the head and adiff's files are as they were.
340
+ */
341
+ var isJustRead = (key, sign) => {
342
+ const read = justRead.get(key);
343
+ return read !== void 0 && Date.now() - read.at < JUST_READ_MS && read.sign === sign;
344
+ };
345
+ /** Nothing the outline was read from has moved since: the head, adiff's files and the worktree. */
346
+ var isStillRead = (key, sign) => justRead.get(key)?.sign === sign;
347
+ /** Tells `onChange` what changed in the review, as adiff's watch names it, until the watch is lost. */
348
+ var watchReview = (address, handlers) => watch$1([
349
+ "--repo",
350
+ address.repo,
351
+ "--branch",
352
+ address.branch
353
+ ], handlers);
354
+ export { ask, getAdiffRoot, getReviewKey, isJustRead, isStillRead, noteRead, signOf, watchReview };
@@ -1,9 +1,10 @@
1
1
  import { createServerRpc } from "./createServerRpc-Xq42ilNx.mjs";
2
2
  import { createServerFn } from "./ssr.mjs";
3
- import { keptTargetOutline, openTargetOutline, resolveAdhocReview } from "./review-target.server-DA41RDao.mjs";
3
+ import { resolveReview } from "./review-link.server-XUXU8Jjl.mjs";
4
+ import { keptTargetOutline, openTargetOutline } from "./review-target.server-C8IXgmE-.mjs";
4
5
  import { object, optional, string } from "../_libs/valibot.mjs";
5
- // node_modules/.nitro/vite/services/ssr/assets/adhoc.functions-CDadmCcu.js
6
- var adhocLinkSchema = object({
6
+ // node_modules/.nitro/vite/services/ssr/assets/review-link.functions-BvcyZSk2.js
7
+ var reviewLinkSchema = object({
7
8
  repo: optional(string()),
8
9
  worktree: optional(string()),
9
10
  branch: optional(string()),
@@ -29,7 +30,7 @@ var resolveOnce = (data) => {
29
30
  ...known.link,
30
31
  outline: keptTargetOutline(known.link)
31
32
  };
32
- const link = resolveAdhocReview(data);
33
+ const link = resolveReview(data);
33
34
  resolved.set(key, {
34
35
  at: Date.now(),
35
36
  link
@@ -40,12 +41,12 @@ var resolveOnce = (data) => {
40
41
  outline: openTargetOutline(link)
41
42
  };
42
43
  };
43
- var resolveAdhocLink_createServerFn_handler = createServerRpc({
44
- id: "4ced24c8b3987d8dc56edb1dc284f78c81937737b2253db0256f0233e3bb52eb",
45
- name: "resolveAdhocLink",
46
- filename: "src/lib/adhoc.functions.ts"
47
- }, (opts) => resolveAdhocLink.__executeServer(opts));
48
- var resolveAdhocLink = createServerFn({ method: "GET" }).validator(adhocLinkSchema).handler(resolveAdhocLink_createServerFn_handler, ({ data }) => {
44
+ var resolveReviewLink_createServerFn_handler = createServerRpc({
45
+ id: "5e430d6a83bf3c8d7ce13e5a21b0d9a07c039ac24a163de2eefc4ace52c9ead6",
46
+ name: "resolveReviewLink",
47
+ filename: "src/lib/review-link.functions.ts"
48
+ }, (opts) => resolveReviewLink.__executeServer(opts));
49
+ var resolveReviewLink = createServerFn({ method: "GET" }).validator(reviewLinkSchema).handler(resolveReviewLink_createServerFn_handler, ({ data }) => {
49
50
  try {
50
51
  return resolveOnce(data);
51
52
  } catch (error) {
@@ -55,4 +56,4 @@ var resolveAdhocLink = createServerFn({ method: "GET" }).validator(adhocLinkSche
55
56
  };
56
57
  }
57
58
  });
58
- export { resolveAdhocLink_createServerFn_handler };
59
+ export { resolveReviewLink_createServerFn_handler };
@@ -0,0 +1,180 @@
1
+ import { realpathSync, statSync, watch } from "node:fs";
2
+ import { dirname, join, sep } from "node:path";
3
+ import { execFileSync } from "node:child_process";
4
+ import { homedir } from "node:os";
5
+ // node_modules/.nitro/vite/services/ssr/assets/review-link.server-XUXU8Jjl.js
6
+ /**
7
+ * The environment for the git the page runs, and for adiff, which runs git too. Every such call
8
+ * only reads, and `git status` otherwise refreshes the index under index.lock, so an agent that
9
+ * commits in the worktree while the page polls fails with "index.lock exists".
10
+ */
11
+ var READ_ONLY_GIT = {
12
+ ...process.env,
13
+ GIT_OPTIONAL_LOCKS: "0"
14
+ };
15
+ var MAX_BUFFER = 67108864;
16
+ /** A porcelain status entry is two status letters, a space, then the path. */
17
+ var STATUS_WIDTH = 2;
18
+ var PATH_AT = 3;
19
+ /** How long the files must be still before the worktree is looked at again. */
20
+ var SETTLE_MS = 300;
21
+ var git = (repo, args) => execFileSync("git", [
22
+ "-C",
23
+ repo,
24
+ ...args
25
+ ], {
26
+ maxBuffer: MAX_BUFFER,
27
+ env: READ_ONLY_GIT,
28
+ stdio: [
29
+ "ignore",
30
+ "pipe",
31
+ "ignore"
32
+ ]
33
+ });
34
+ var getWorktree = (address) => {
35
+ return git(address.repo, [
36
+ "worktree",
37
+ "list",
38
+ "--porcelain"
39
+ ]).toString().split("\n\n").find((candidate) => candidate.split("\n").includes(`branch refs/heads/${address.branch}`))?.split("\n")[0]?.replace(/^worktree /u, "") ?? null;
40
+ };
41
+ var getRealWorktree = (address) => {
42
+ try {
43
+ const worktree = getWorktree(address);
44
+ return worktree === null ? null : realpathSync(worktree);
45
+ } catch {
46
+ return null;
47
+ }
48
+ };
49
+ var statOf = (worktree, path) => {
50
+ try {
51
+ const { mtimeMs, size } = statSync(join(worktree, path));
52
+ return `${path}:${String(mtimeMs)}:${String(size)}`;
53
+ } catch {
54
+ return `${path}:gone`;
55
+ }
56
+ };
57
+ /**
58
+ * A cheap mark of what the worktree holds beyond its last commit: every file git calls changed or
59
+ * new, with its time and size. It moves when an uncommitted file is written again, which git's
60
+ * status alone would not show. Ignored files never count.
61
+ */
62
+ var getWorktreeMark = (worktree) => {
63
+ try {
64
+ return git(worktree, [
65
+ "status",
66
+ "--porcelain=v1",
67
+ "-z",
68
+ "--untracked-files=all"
69
+ ]).toString().split("\0").filter(Boolean).map((entry) => `${entry.slice(0, STATUS_WIDTH)} ${statOf(worktree, entry.slice(PATH_AT))}`).join("\n");
70
+ } catch {
71
+ return "";
72
+ }
73
+ };
74
+ var isInsideGit = (name) => name === null || name === ".git" || name.startsWith(`.git/`) || name.includes("node_modules/");
75
+ var startWatch = (worktree, onEvent) => {
76
+ try {
77
+ return watch(worktree, { recursive: true }, (_event, name) => {
78
+ onEvent(name);
79
+ });
80
+ } catch {
81
+ return null;
82
+ }
83
+ };
84
+ /**
85
+ * Calls `onChange` when the worktree's uncommitted files change: written, added, removed or reverted.
86
+ * The file system says something moved, then the mark decides, so a build writing ignored files or
87
+ * git rewriting its own folder tells nobody. Returns the stop, or null when the folder cannot be
88
+ * watched.
89
+ */
90
+ var watchWorktree = (worktree, onChange) => {
91
+ const kept = {
92
+ mark: getWorktreeMark(worktree),
93
+ timer: void 0
94
+ };
95
+ const look = () => {
96
+ const now = getWorktreeMark(worktree);
97
+ if (now !== kept.mark) {
98
+ kept.mark = now;
99
+ onChange();
100
+ }
101
+ };
102
+ const watcher = startWatch(worktree, (name) => {
103
+ if (isInsideGit(name)) return;
104
+ clearTimeout(kept.timer);
105
+ kept.timer = setTimeout(look, SETTLE_MS);
106
+ });
107
+ if (watcher === null) return null;
108
+ watcher.on("error", () => {
109
+ watcher.close();
110
+ });
111
+ return () => {
112
+ clearTimeout(kept.timer);
113
+ watcher.close();
114
+ };
115
+ };
116
+ /** The repository and base a review reads, in one string that a link and a key can carry. */
117
+ var toPlace = ({ repo, base }) => new URLSearchParams(base === void 0 ? { repo } : {
118
+ repo,
119
+ base
120
+ }).toString();
121
+ var readPlace = (place) => {
122
+ const query = new URLSearchParams(place);
123
+ return {
124
+ repo: query.get("repo") ?? "",
125
+ base: query.get("base") ?? void 0
126
+ };
127
+ };
128
+ var expandHome = (path) => path.replace(/^~(?=$|\/)/u, homedir());
129
+ var getRepoRoots = () => (process.env["REVIEW_REPO_ROOTS"] ?? homedir()).split(":").filter(Boolean).map((root) => realpathSync(expandHome(root)));
130
+ var isUnder = (path, root) => path === root || path.startsWith(`${root}${sep}`);
131
+ var findReviewAddress = ({ place, branch }) => {
132
+ const { repo, base } = readPlace(place);
133
+ const real = realpathSync(repo);
134
+ if (!getRepoRoots().some((root) => isUnder(real, root))) throw new Error(`${repo} is outside REVIEW_REPO_ROOTS`);
135
+ return {
136
+ repo: real,
137
+ branch,
138
+ base
139
+ };
140
+ };
141
+ var readGit = (dir, args) => execFileSync("git", [
142
+ "-C",
143
+ dir,
144
+ ...args
145
+ ], {
146
+ env: READ_ONLY_GIT,
147
+ stdio: [
148
+ "ignore",
149
+ "pipe",
150
+ "pipe"
151
+ ]
152
+ }).toString().trim();
153
+ var resolveReview = (link) => {
154
+ const dir = link.worktree ?? link.repo;
155
+ if (dir === void 0) throw new Error("The link names neither a repo nor a worktree");
156
+ const opened = expandHome(dir);
157
+ const common = readGit(opened, [
158
+ "rev-parse",
159
+ "--path-format=absolute",
160
+ "--git-common-dir"
161
+ ]);
162
+ const branch = link.branch ?? readGit(opened, [
163
+ "symbolic-ref",
164
+ "--short",
165
+ "HEAD"
166
+ ]);
167
+ const place = toPlace({
168
+ repo: dirname(common),
169
+ base: link.base
170
+ });
171
+ findReviewAddress({
172
+ place,
173
+ branch
174
+ });
175
+ return {
176
+ place,
177
+ branch
178
+ };
179
+ };
180
+ export { READ_ONLY_GIT, findReviewAddress, getRealWorktree, getWorktree, getWorktreeMark, git, resolveReview, watchWorktree };
@@ -1,5 +1,5 @@
1
- import { AdiffFailureError, getBranchHead, getLayers, getProgress, getThreads, hash, layersRaw, listRaw, openFirst, outlineKey, outlines, progressRaw, retagged, toCommentFields, toLayerFields } from "./review-target.server-DA41RDao.mjs";
2
- // node_modules/.nitro/vite/services/ssr/assets/review-parts.server-j_3LS0HZ.js
1
+ import { AdiffFailureError, getBranchHead, getLayers, getProgress, getThreads, hash, layersRaw, listRaw, openFirst, outlineKey, outlines, progressRaw, retagged, toCommentFields, toLayerFields } from "./review.server-DFe2jCWt.mjs";
2
+ // node_modules/.nitro/vite/services/ssr/assets/review-parts.server-CSSa-ZRv.js
3
3
  var PARTS = [
4
4
  "comments",
5
5
  "state",
@@ -0,0 +1,37 @@
1
+ import { createServerRpc } from "./createServerRpc-Xq42ilNx.mjs";
2
+ import { createServerFn } from "./ssr.mjs";
3
+ import { getReviewFile, getSinceFile, markReviewed } from "./review.server-DFe2jCWt.mjs";
4
+ import { findReviewAddress } from "./review-link.server-XUXU8Jjl.mjs";
5
+ import { reviewFileSchema, reviewMarkSchema, reviewOutlineSchema, reviewSinceSchema } from "./review-schema-C0qXng9-.mjs";
6
+ import { getTargetOutline } from "./review-target.server-C8IXgmE-.mjs";
7
+ // node_modules/.nitro/vite/services/ssr/assets/review-read.functions-Da-f7qpe.js
8
+ var markReviewFile_createServerFn_handler = createServerRpc({
9
+ id: "bc42f104a022623469410d19573fe9714a7aed7a344f808479517ee6742bfaae",
10
+ name: "markReviewFile",
11
+ filename: "src/lib/review-read.functions.ts"
12
+ }, (opts) => markReviewFile.__executeServer(opts));
13
+ var markReviewFile = createServerFn({ method: "POST" }).validator(reviewMarkSchema).handler(markReviewFile_createServerFn_handler, async ({ data }) => {
14
+ return {
15
+ ok: true,
16
+ told: await markReviewed(findReviewAddress(data), data)
17
+ };
18
+ });
19
+ var loadReviewOutline_createServerFn_handler = createServerRpc({
20
+ id: "9efdcbe2ace17d0836d7df7bc9aff104b4868682ca79516ddb6927a8ed223691",
21
+ name: "loadReviewOutline",
22
+ filename: "src/lib/review-read.functions.ts"
23
+ }, (opts) => loadReviewOutline.__executeServer(opts));
24
+ var loadReviewOutline = createServerFn({ method: "GET" }).validator(reviewOutlineSchema).handler(loadReviewOutline_createServerFn_handler, ({ data }) => getTargetOutline(data, data));
25
+ var loadReviewFile_createServerFn_handler = createServerRpc({
26
+ id: "1e0b1bc8f9718ae1ef49c47aa55a9e44518eaa93e3b317cf1b521d87b3f6e983",
27
+ name: "loadReviewFile",
28
+ filename: "src/lib/review-read.functions.ts"
29
+ }, (opts) => loadReviewFile.__executeServer(opts));
30
+ var loadReviewFile = createServerFn({ method: "GET" }).validator(reviewFileSchema).handler(loadReviewFile_createServerFn_handler, ({ data }) => getReviewFile(findReviewAddress(data), data));
31
+ var loadSinceFile_createServerFn_handler = createServerRpc({
32
+ id: "e21610e432516c6914db00010e8bedfa8f3b53f243b609befdc905f0d0717d60",
33
+ name: "loadSinceFile",
34
+ filename: "src/lib/review-read.functions.ts"
35
+ }, (opts) => loadSinceFile.__executeServer(opts));
36
+ var loadSinceFile = createServerFn({ method: "GET" }).validator(reviewSinceSchema).handler(loadSinceFile_createServerFn_handler, ({ data }) => getSinceFile(findReviewAddress(data), data));
37
+ export { loadReviewFile_createServerFn_handler, loadReviewOutline_createServerFn_handler, loadSinceFile_createServerFn_handler, markReviewFile_createServerFn_handler };