@moxt-ai/mobius 0.0.456 → 0.0.457

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 (33) hide show
  1. package/THIRD-PARTY-NOTICES.txt +27 -0
  2. package/dist/{chunk-H3JQ3BX5.js → chunk-SWSQPASF.js} +3 -2
  3. package/dist/{chunk-H3JQ3BX5.js.map → chunk-SWSQPASF.js.map} +2 -2
  4. package/dist/{chunk-GUE7ZQI6.js → chunk-VDTIJC4T.js} +1525 -71
  5. package/dist/{chunk-GUE7ZQI6.js.map → chunk-VDTIJC4T.js.map} +4 -4
  6. package/dist/{cli-E4GLG6NB.js → cli-IDWRMTMI.js} +3 -3
  7. package/dist/cli.js +2 -2
  8. package/dist/engine/acp/adapter/antigravity/background-wakeup.d.ts.map +1 -1
  9. package/dist/engine/acp/adapter/antigravity/background-wakeup.js +58 -6
  10. package/dist/engine/acp/adapter/antigravity/background-wakeup.js.map +1 -1
  11. package/dist/engine/runtime/command/registry/index.d.ts.map +1 -1
  12. package/dist/engine/runtime/command/registry/index.js +3 -0
  13. package/dist/engine/runtime/command/registry/index.js.map +1 -1
  14. package/dist/engine/runtime/command/registry/runtime.d.ts.map +1 -1
  15. package/dist/engine/runtime/command/registry/runtime.js +1 -0
  16. package/dist/engine/runtime/command/registry/runtime.js.map +1 -1
  17. package/dist/engine/runtime/command/registry/workspace-files.d.ts +4 -0
  18. package/dist/engine/runtime/command/registry/workspace-files.d.ts.map +1 -0
  19. package/dist/engine/runtime/command/registry/workspace-files.js +77 -0
  20. package/dist/engine/runtime/command/registry/workspace-files.js.map +1 -0
  21. package/dist/engine/session/content/session-files.d.ts +6 -1
  22. package/dist/engine/session/content/session-files.d.ts.map +1 -1
  23. package/dist/engine/session/content/session-files.js +37 -24
  24. package/dist/engine/session/content/session-files.js.map +1 -1
  25. package/dist/engine/storage/files/local-files.d.ts +1 -2
  26. package/dist/engine/storage/files/local-files.d.ts.map +1 -1
  27. package/dist/engine/storage/files/workspace-files.d.ts +40 -0
  28. package/dist/engine/storage/files/workspace-files.d.ts.map +1 -0
  29. package/dist/engine/storage/files/workspace-files.js +500 -0
  30. package/dist/engine/storage/files/workspace-files.js.map +1 -0
  31. package/dist/engine.js +2 -2
  32. package/package.json +3 -2
  33. /package/dist/{cli-E4GLG6NB.js.map → cli-IDWRMTMI.js.map} +0 -0
@@ -1,9 +1,811 @@
1
1
  import {
2
2
  __callDispose,
3
+ __commonJS,
3
4
  __export,
5
+ __toESM,
4
6
  __using,
5
7
  package_default
6
- } from "./chunk-H3JQ3BX5.js";
8
+ } from "./chunk-SWSQPASF.js";
9
+
10
+ // ../../node_modules/.pnpm/ignore@7.0.9/node_modules/ignore/index.js
11
+ var require_ignore = __commonJS({
12
+ "../../node_modules/.pnpm/ignore@7.0.9/node_modules/ignore/index.js"(exports, module) {
13
+ function makeArray(subject) {
14
+ return Array.isArray(subject) ? subject : [subject];
15
+ }
16
+ var UNDEFINED = void 0;
17
+ var EMPTY = "";
18
+ var SPACE = " ";
19
+ var ESCAPE = "\\";
20
+ var REGEX_LITERAL_SPECIAL = /[.*+?()[\]{}^$|\\/]/;
21
+ var REGEX_TEST_BLANK_LINE = /^\uFEFF? *$/;
22
+ var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
23
+ var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
24
+ var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
25
+ var REGEX_SPLITALL_CRLF = /\r?\n/g;
26
+ var DOUBLE_SLASH = "//";
27
+ var SLASH_CODE = 47;
28
+ var DOT_CODE = 46;
29
+ var SLASH = "/";
30
+ var TMP_KEY_IGNORE = "node-ignore";
31
+ if (typeof Symbol !== "undefined") {
32
+ TMP_KEY_IGNORE = /* @__PURE__ */ Symbol.for("node-ignore");
33
+ }
34
+ var KEY_IGNORE = TMP_KEY_IGNORE;
35
+ var define2 = (object2, key, value) => {
36
+ Object.defineProperty(object2, key, { value });
37
+ return value;
38
+ };
39
+ var RETURN_FALSE = () => false;
40
+ var cleanRangeBackSlash = (slashes) => {
41
+ const { length } = slashes;
42
+ return slashes.slice(0, length - length % 2);
43
+ };
44
+ var POSIX_CLASSES = {
45
+ alnum: "0-9A-Za-z",
46
+ alpha: "A-Za-z",
47
+ blank: " \\t",
48
+ cntrl: "\\x00-\\x1f\\x7f",
49
+ digit: "0-9",
50
+ graph: "!-.0-~",
51
+ lower: "a-z",
52
+ print: " -.0-~",
53
+ punct: "!-.:-@\\[-`{-~",
54
+ // git's `sane-ctype.h` classifies \v and \f as control, not space,
55
+ // unlike C's `isspace`
56
+ space: " \\t\\n\\r",
57
+ upper: "A-Z",
58
+ xdigit: "0-9A-Fa-f"
59
+ };
60
+ var CLASS_MEMBERS_TO_ESCAPE = "\\]^-[";
61
+ var escapeMember = (char) => CLASS_MEMBERS_TO_ESCAPE.indexOf(char) < 0 ? char : ESCAPE + char;
62
+ var NON_SLASH = "(?!\\/)";
63
+ var classSource = (negated, body) => {
64
+ if (negated) {
65
+ return `[^\\/${body}]`;
66
+ }
67
+ const source = `[${body}]`;
68
+ return new RegExp(source).test("/") ? NON_SLASH + source : source;
69
+ };
70
+ var scanBracket = (pattern, start) => {
71
+ const { length } = pattern;
72
+ let index2 = start + 1;
73
+ let negated = EMPTY;
74
+ const lead = pattern[index2];
75
+ if (lead === "!" || lead === "^") {
76
+ negated = "^";
77
+ index2++;
78
+ }
79
+ let body = EMPTY;
80
+ let prev = EMPTY;
81
+ for (; ; ) {
82
+ const char = pattern[index2];
83
+ if (char === UNDEFINED) {
84
+ return null;
85
+ }
86
+ if (char === ESCAPE) {
87
+ const escaped = pattern[index2 + 1];
88
+ if (escaped === UNDEFINED) {
89
+ return null;
90
+ }
91
+ body += escapeMember(escaped);
92
+ prev = escaped;
93
+ index2++;
94
+ } else if (char === "-" && prev && index2 + 1 < length && pattern[index2 + 1] !== "]") {
95
+ index2++;
96
+ let to2 = pattern[index2];
97
+ if (to2 === ESCAPE) {
98
+ to2 = pattern[index2 += 1];
99
+ }
100
+ if (prev <= to2) {
101
+ body += `-${escapeMember(to2)}`;
102
+ }
103
+ prev = EMPTY;
104
+ } else if (char === "[" && pattern[index2 + 1] === ":") {
105
+ const nameStart = index2 + 2;
106
+ let end = nameStart;
107
+ while (end < length && pattern[end] !== "]") {
108
+ end++;
109
+ }
110
+ if (end === length) {
111
+ return null;
112
+ }
113
+ if (end > nameStart && pattern[end - 1] === ":") {
114
+ const expanded = POSIX_CLASSES[pattern.slice(nameStart, end - 1)];
115
+ if (expanded === UNDEFINED) {
116
+ return null;
117
+ }
118
+ body += expanded;
119
+ prev = EMPTY;
120
+ index2 = end;
121
+ } else {
122
+ body += escapeMember("[");
123
+ prev = "[";
124
+ index2 = nameStart - 2;
125
+ }
126
+ } else {
127
+ body += escapeMember(char);
128
+ prev = char;
129
+ }
130
+ index2++;
131
+ if (pattern[index2] === "]") {
132
+ return {
133
+ end: index2,
134
+ source: classSource(negated, body)
135
+ };
136
+ }
137
+ }
138
+ };
139
+ var NEVER_MATCH = "[]";
140
+ var PLACEHOLDER = "\0";
141
+ var REGEX_RESTORE_PLACEHOLDER = new RegExp(
142
+ `${PLACEHOLDER}(\\d+)${PLACEHOLDER}`,
143
+ "g"
144
+ );
145
+ var TRAILING_WILDCARD = "\uE000";
146
+ var extractBrackets = (pattern) => {
147
+ const sources = [];
148
+ const hold = (source) => `${PLACEHOLDER}${sources.push(source) - 1}${PLACEHOLDER}`;
149
+ const { length } = pattern;
150
+ let out2 = EMPTY;
151
+ let index2 = 0;
152
+ while (index2 < length) {
153
+ const char = pattern[index2];
154
+ if (char === ESCAPE) {
155
+ const escaped = pattern[index2 + 1];
156
+ if (escaped === "*" || escaped === "[" || escaped === SPACE || escaped === ESCAPE) {
157
+ out2 += pattern.slice(index2, index2 + 2);
158
+ } else {
159
+ out2 += hold(
160
+ REGEX_LITERAL_SPECIAL.test(escaped) ? ESCAPE + escaped : escaped
161
+ );
162
+ }
163
+ index2 += 2;
164
+ } else if (char === PLACEHOLDER) {
165
+ out2 += hold(`[${PLACEHOLDER}]`);
166
+ index2++;
167
+ } else if (char === "[") {
168
+ const scanned = scanBracket(pattern, index2);
169
+ if (scanned === null) {
170
+ out2 += hold(NEVER_MATCH);
171
+ index2 = length;
172
+ } else {
173
+ out2 += hold(scanned.source);
174
+ index2 = scanned.end + 1;
175
+ }
176
+ } else {
177
+ out2 += char;
178
+ index2++;
179
+ }
180
+ }
181
+ return {
182
+ source: out2,
183
+ sources
184
+ };
185
+ };
186
+ var DIRECT = null;
187
+ var REGEX_INNER_SLASH = /\/(?!$)/;
188
+ var REPLACERS = [
189
+ [
190
+ // Remove BOM
191
+ // TODO:
192
+ // Other similar zero-width characters?
193
+ /^\uFEFF/,
194
+ () => EMPTY,
195
+ "\uFEFF"
196
+ ],
197
+ [
198
+ // A trailing line terminator, left on when a whole file's contents are
199
+ // added as one pattern rather than split into lines. git never sees one
200
+ // -- it reads a `.gitignore` line by line -- so it is not part of the
201
+ // pattern and is dropped here, apart from the trailing-space trimming,
202
+ // which follows git in touching spaces and nothing else.
203
+ /[\r\n]+$/,
204
+ () => EMPTY
205
+ ],
206
+ // > Trailing spaces are ignored unless they are quoted with backslash ("\")
207
+ [
208
+ // Only spaces, never tabs or other whitespace: git trims a trailing run
209
+ // of `' '` and nothing else (dir.c, `trim_trailing_spaces`, a single
210
+ // `case ' '`), so a pattern ending in a tab keeps it as a literal.
211
+ // (a\ ) -> (a )
212
+ // (a ) -> (a)
213
+ // (a ) -> (a)
214
+ // (a \ ) -> (a )
215
+ /((?:\\\\)*?)(\\? +)$/,
216
+ (_, m12, m22) => m12 + (m22.indexOf("\\") === 0 ? SPACE : EMPTY)
217
+ ],
218
+ // Replace (\ ) with ' '
219
+ // Only a space: an escaped tab or other whitespace is already a literal by
220
+ // the time it reaches here, and a bare tab must be left as one, not turned
221
+ // into a space.
222
+ // (\ ) -> ' '
223
+ // (\\ ) -> '\\ '
224
+ // (\\\ ) -> '\\ '
225
+ [
226
+ /(\\+?) /g,
227
+ (_, m12) => {
228
+ const { length } = m12;
229
+ return m12.slice(0, length - length % 2) + SPACE;
230
+ }
231
+ ],
232
+ // Escape metacharacters
233
+ // which is written down by users but means special for regular expressions.
234
+ // > There are 12 characters with special meanings:
235
+ // > - the backslash \,
236
+ // > - the caret ^,
237
+ // > - the dollar sign $,
238
+ // > - the period or dot .,
239
+ // > - the vertical bar or pipe symbol |,
240
+ // > - the question mark ?,
241
+ // > - the asterisk or star *,
242
+ // > - the plus sign +,
243
+ // > - the opening parenthesis (,
244
+ // > - the closing parenthesis ),
245
+ // > - and the opening square bracket [,
246
+ // > - the opening curly brace {,
247
+ // > These special characters are often called "metacharacters".
248
+ [
249
+ /[\\$.|*+(){^]/g,
250
+ (match) => `\\${match}`
251
+ ],
252
+ [
253
+ // > a question mark (?) matches a single character
254
+ /(?!\\)\?/g,
255
+ () => "[^/]",
256
+ "?"
257
+ ],
258
+ // leading slash
259
+ [
260
+ // > A leading slash matches the beginning of the pathname.
261
+ // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
262
+ // A leading slash matches the beginning of the pathname
263
+ /^\//,
264
+ () => "^",
265
+ SLASH
266
+ ],
267
+ // replace special metacharacter slash after the leading slash
268
+ [
269
+ /\//g,
270
+ () => "\\/",
271
+ SLASH
272
+ ],
273
+ [
274
+ // > A leading "**" followed by a slash means match in all directories.
275
+ // > For example, "**/foo" matches file or directory "foo" anywhere,
276
+ // > the same as pattern "foo".
277
+ // > "**/foo/bar" matches file or directory "bar" anywhere that is directly
278
+ // > under directory "foo".
279
+ // Notice that the '*'s have been replaced as '\\*'
280
+ /^\^*(?:\\\*\\\*\\\/)+/,
281
+ // '**/foo' <-> 'foo'
282
+ () => "^(?:.*\\/)?",
283
+ "*"
284
+ ],
285
+ // starting
286
+ [
287
+ // there will be no leading '/'
288
+ // (which has been replaced by section "leading slash")
289
+ // If starts with '**', adding a '^' to the regular expression also works
290
+ DIRECT,
291
+ (source, pattern) => {
292
+ if (!source || source[0] === "^") {
293
+ return source;
294
+ }
295
+ const anchor2 = !REGEX_INNER_SLASH.test(pattern) ? "(?:^|\\/)" : "^";
296
+ return anchor2 + source;
297
+ }
298
+ ],
299
+ // two globstars
300
+ [
301
+ // Use lookahead assertions so that we could match more than one `'/**'`
302
+ /\\\/\\\*\\\*(?=\\\/|$)/g,
303
+ // Zero, one or several directories
304
+ // should not use '*', or it will be replaced by the next replacer
305
+ // Check if it is not the last `'/**'`
306
+ (_, index2, str) => index2 + 6 < str.length ? str.slice(index2 + 6) === "\\/" ? "(?:\\/[^\\/]+)+" : "(?:\\/[^\\/]+)*" : "\\/.+",
307
+ "*"
308
+ ],
309
+ // normal intermediate wildcards
310
+ [
311
+ // Never replace escaped '*'
312
+ // ignore rule '\*' will match the path '*'
313
+ // 'abc.*/' -> go
314
+ // 'abc.*' -> skip this rule,
315
+ // coz trailing single wildcard will be handed by [trailing wildcard]
316
+ /(^|[^\\]+)(\\\*)+(?=.+)/g,
317
+ // '*.js' matches '.js'
318
+ // '*.js' doesn't match 'abc'
319
+ (_, p12, p22) => {
320
+ const unescaped = p22.replace(/\\\*/g, "[^\\/]*");
321
+ return p12 + unescaped;
322
+ },
323
+ "*"
324
+ ],
325
+ // trailing wildcard, held apart from a literal star
326
+ [
327
+ // The step above leaves a trailing `*` alone, so a single `\*` is all that
328
+ // can be left at the end here. Whether it is a wildcard or a literal
329
+ // turns on the backslashes the user put in front of it: the escaper has
330
+ // since doubled every one, so what stands here is those `2N` doubled
331
+ // backslashes and then the star's own escape. An even number of the
332
+ // original `N` leaves the star unescaped -- a wildcard -- and an odd
333
+ // number escapes it -- a literal. This runs while the two are still
334
+ // distinct, before the unescape steps below collapse the literal onto
335
+ // the very `\*` a wildcard leaves behind.
336
+ /(^|[^\\])((?:\\\\)*)\\\*$/,
337
+ (match, p12, p22) => (
338
+ // `p2` holds the doubled user backslashes; half of them is `N`.
339
+ p22.length / 2 % 2 === 0 ? p12 + p22 + TRAILING_WILDCARD : match
340
+ ),
341
+ "*"
342
+ ],
343
+ [
344
+ // unescape, revert step 3 except for back slash
345
+ // For example, if a user escape a '\\*',
346
+ // after step 3, the result will be '\\\\\\*'
347
+ /\\\\\\(?=[$.|*+(){^])/g,
348
+ () => ESCAPE,
349
+ ESCAPE + ESCAPE
350
+ ],
351
+ [
352
+ // '\\\\' -> '\\'
353
+ /\\\\/g,
354
+ () => ESCAPE,
355
+ ESCAPE + ESCAPE
356
+ ],
357
+ [
358
+ // Every real bracket expression -- POSIX classes included -- has already
359
+ // been held aside by `extractBrackets`, so the only `[` left in the
360
+ // pattern is an escaped, literal one.
361
+ // `\` is escaped by step 3
362
+ /\\\[([^\]/]*?)(\\*)($|\])/g,
363
+ // '\\[bar]' -> '\\\\[bar\\]'
364
+ (match, range, endEscape, close) => `\\[${range}${cleanRangeBackSlash(endEscape)}${close}`,
365
+ "["
366
+ ],
367
+ // ending
368
+ [
369
+ // 'js' will not match 'js.'
370
+ // 'ab' will not match 'abc'
371
+ DIRECT,
372
+ // WTF!
373
+ // https://git-scm.com/docs/gitignore
374
+ // changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
375
+ // which re-fixes #24, #38
376
+ // > If there is a separator at the end of the pattern then the pattern
377
+ // > will only match directories, otherwise the pattern can match both
378
+ // > files and directories.
379
+ // 'js*' will not match 'a.js'
380
+ // 'js/' will not match 'a.js'
381
+ // 'js' will match 'a.js' and 'a.js/'
382
+ (source) => {
383
+ const last = source[source.length - 1];
384
+ if (!last || last === TRAILING_WILDCARD) {
385
+ return source;
386
+ }
387
+ return last === SLASH ? `${source}$` : `${source}(?=$|\\/$)`;
388
+ }
389
+ ]
390
+ ];
391
+ var REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\uE000$/;
392
+ var MODE_IGNORE = "regex";
393
+ var MODE_CHECK_IGNORE = "checkRegex";
394
+ var UNDERSCORE = "_";
395
+ var TRAILING_WILD_CARD_REPLACERS = {
396
+ [MODE_IGNORE](_, p12) {
397
+ const prefix = p12 ? `${p12}[^/]+` : "[^/]*";
398
+ return `${prefix}(?=$|\\/$)`;
399
+ },
400
+ [MODE_CHECK_IGNORE](_, p12) {
401
+ const prefix = p12 ? `${p12}[^/]*` : "[^/]*";
402
+ return `${prefix}(?=$|\\/$)`;
403
+ }
404
+ };
405
+ var WILDCARD = "[^\\/]*";
406
+ var pinWildcards = (source) => {
407
+ if (source.indexOf(WILDCARD) < 0) {
408
+ return source;
409
+ }
410
+ const tokens = [];
411
+ const { length } = source;
412
+ let index2 = 0;
413
+ while (index2 < length) {
414
+ const char = source[index2];
415
+ if (source.startsWith(WILDCARD, index2)) {
416
+ tokens.push({ wildcard: true });
417
+ index2 += WILDCARD.length;
418
+ } else if (char === "[") {
419
+ let end = index2 + 1;
420
+ if (source[end] === "^") {
421
+ end++;
422
+ }
423
+ if (source[end] === "]") {
424
+ end++;
425
+ }
426
+ while (end < length && source[end] !== "]") {
427
+ end += source[end] === ESCAPE ? 2 : 1;
428
+ }
429
+ end++;
430
+ tokens.push({ single: source.slice(index2, end) });
431
+ index2 = end;
432
+ } else if (char === ESCAPE) {
433
+ tokens.push({ single: source.slice(index2, index2 + 2) });
434
+ index2 += 2;
435
+ } else if (char === "(") {
436
+ let depth = 0;
437
+ let end = index2;
438
+ do {
439
+ if (source[end] === ESCAPE) {
440
+ end++;
441
+ } else if (source[end] === "(") {
442
+ depth++;
443
+ } else if (source[end] === ")") {
444
+ depth--;
445
+ }
446
+ end++;
447
+ } while (end < length && depth > 0);
448
+ if ("*+?".indexOf(source[end]) >= 0) {
449
+ end++;
450
+ }
451
+ tokens.push({ boundary: source.slice(index2, end) });
452
+ index2 = end;
453
+ } else if (char === "^" || char === "$") {
454
+ tokens.push({ boundary: char });
455
+ index2++;
456
+ } else {
457
+ tokens.push({ single: char });
458
+ index2++;
459
+ }
460
+ }
461
+ let out2 = EMPTY;
462
+ let run = [];
463
+ const flush = () => {
464
+ let lastWildcard;
465
+ run.forEach((token, at2) => {
466
+ if (token.wildcard) {
467
+ lastWildcard = at2;
468
+ }
469
+ });
470
+ run.forEach((token, at2) => {
471
+ if (!token.wildcard) {
472
+ out2 += token.single;
473
+ return;
474
+ }
475
+ out2 += at2 === lastWildcard ? WILDCARD : `(?:(?!${run[at2 + 1].single})[^\\/])*`;
476
+ });
477
+ run = [];
478
+ };
479
+ tokens.forEach((token) => {
480
+ if (token.boundary === void 0) {
481
+ run.push(token);
482
+ return;
483
+ }
484
+ flush();
485
+ out2 += token.boundary;
486
+ });
487
+ flush();
488
+ return out2;
489
+ };
490
+ var makeRegexPrefix = (pattern) => {
491
+ const { source, sources } = extractBrackets(pattern);
492
+ const replaced = REPLACERS.reduce(
493
+ // A pass whose matcher finds nothing hands back the very string it was
494
+ // given, so asking first costs a search and saves a rewrite. Ten of the
495
+ // fifteen passes never fire for a typical .gitignore line, and between
496
+ // them they were 45% of this chain.
497
+ (prev, [matcher, replacer, required2]) => {
498
+ if (matcher === DIRECT) {
499
+ return replacer(prev, pattern);
500
+ }
501
+ if (required2 !== UNDEFINED && prev.indexOf(required2) < 0) {
502
+ return prev;
503
+ }
504
+ return matcher.test(prev) ? prev.replace(matcher, replacer.bind(pattern)) : prev;
505
+ },
506
+ source
507
+ );
508
+ return sources.length ? replaced.replace(
509
+ REGEX_RESTORE_PLACEHOLDER,
510
+ (match, index2) => sources[index2]
511
+ ) : replaced;
512
+ };
513
+ var matchesBasename = (body) => {
514
+ const index2 = body.indexOf(SLASH);
515
+ return index2 < 0 || index2 === body.length - 1;
516
+ };
517
+ var basenameOf = (path6) => {
518
+ const end = path6.length - 1;
519
+ const index2 = path6.lastIndexOf(
520
+ SLASH,
521
+ path6[end] === SLASH ? end - 1 : end
522
+ );
523
+ return index2 < 0 ? path6 : path6.slice(index2 + 1);
524
+ };
525
+ var parentOf = (path6) => {
526
+ if (path6.charCodeAt(0) === SLASH_CODE || path6.indexOf(DOUBLE_SLASH) >= 0) {
527
+ const slices = path6.split(SLASH).filter(Boolean);
528
+ slices.pop();
529
+ return slices.length ? slices.join(SLASH) + SLASH : EMPTY;
530
+ }
531
+ const end = path6.length - 1;
532
+ const cut = path6.lastIndexOf(
533
+ SLASH,
534
+ path6.charCodeAt(end) === SLASH_CODE ? end - 1 : end
535
+ );
536
+ return cut < 0 ? EMPTY : path6.slice(0, cut + 1);
537
+ };
538
+ var isString = (subject) => typeof subject === "string";
539
+ var checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_TEST_BLANK_LINE.test(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern) && pattern.indexOf("#") !== 0;
540
+ var splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
541
+ var IgnoreRule = class {
542
+ constructor(pattern, mark, body, ignoreCase, negative, prefix) {
543
+ this.pattern = pattern;
544
+ this.mark = mark;
545
+ this.negative = negative;
546
+ define2(this, "body", body);
547
+ define2(this, "ignoreCase", ignoreCase);
548
+ define2(this, "regexPrefix", prefix);
549
+ }
550
+ // Worked out on first use and kept behind an own property, the way `regex`
551
+ // caches itself in `_regex`. Deciding it in the constructor instead would
552
+ // add a fourth `defineProperty` to every rule ever built, which cost 4% of
553
+ // every compile -- including the compiles of rules that are never matched
554
+ // against anything.
555
+ get _basenameOnly() {
556
+ return define2(this, "_basenameOnly", matchesBasename(this.body));
557
+ }
558
+ get regex() {
559
+ const key = UNDERSCORE + MODE_IGNORE;
560
+ if (this[key]) {
561
+ return this[key];
562
+ }
563
+ return this._make(MODE_IGNORE, key);
564
+ }
565
+ get checkRegex() {
566
+ const key = UNDERSCORE + MODE_CHECK_IGNORE;
567
+ if (this[key]) {
568
+ return this[key];
569
+ }
570
+ return this._make(MODE_CHECK_IGNORE, key);
571
+ }
572
+ _make(mode, key) {
573
+ const str = pinWildcards(this.regexPrefix.replace(
574
+ REGEX_REPLACE_TRAILING_WILDCARD,
575
+ // It does not need to bind pattern
576
+ TRAILING_WILD_CARD_REPLACERS[mode]
577
+ ));
578
+ const regex = this.ignoreCase ? new RegExp(str, "i") : new RegExp(str);
579
+ return define2(this, key, regex);
580
+ }
581
+ };
582
+ var createRule = ({
583
+ pattern,
584
+ mark
585
+ }, ignoreCase) => {
586
+ let negative = false;
587
+ let body = pattern;
588
+ if (body.indexOf("!") === 0) {
589
+ negative = true;
590
+ body = body.substr(1);
591
+ }
592
+ body = body.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, "!").replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, "#");
593
+ const regexPrefix = makeRegexPrefix(body);
594
+ return new IgnoreRule(
595
+ pattern,
596
+ mark,
597
+ body,
598
+ ignoreCase,
599
+ negative,
600
+ regexPrefix
601
+ );
602
+ };
603
+ var RuleManager = class {
604
+ constructor(ignoreCase) {
605
+ this._ignoreCase = ignoreCase;
606
+ this._rules = [];
607
+ this._basenameCount = 0;
608
+ }
609
+ _add(pattern) {
610
+ if (pattern && pattern[KEY_IGNORE]) {
611
+ this._rules = this._rules.concat(pattern._rules._rules);
612
+ this._basenameCount += pattern._rules._basenameCount;
613
+ this._added = true;
614
+ return;
615
+ }
616
+ if (isString(pattern)) {
617
+ pattern = {
618
+ pattern
619
+ };
620
+ }
621
+ if (checkPattern(pattern.pattern)) {
622
+ const rule = createRule(pattern, this._ignoreCase);
623
+ this._added = true;
624
+ this._rules.push(rule);
625
+ if (matchesBasename(rule.body)) {
626
+ this._basenameCount++;
627
+ }
628
+ }
629
+ }
630
+ // @param {Array<string> | string | Ignore} pattern
631
+ add(pattern) {
632
+ this._added = false;
633
+ makeArray(
634
+ isString(pattern) ? splitPattern(pattern) : pattern
635
+ ).forEach(this._add, this);
636
+ return this._added;
637
+ }
638
+ // Test one single path without recursively checking parent directories
639
+ //
640
+ // - checkUnignored `boolean` whether should check if the path is unignored,
641
+ // setting `checkUnignored` to `false` could reduce additional
642
+ // path matching.
643
+ // - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
644
+ // @returns {TestResult} true if a file is ignored
645
+ test(path6, checkUnignored, mode) {
646
+ let ignored = false;
647
+ let unignored = false;
648
+ let matchedRule;
649
+ const rules = this._rules;
650
+ const { length } = rules;
651
+ const shortcut = this._basenameCount * 2 >= length;
652
+ const basename11 = shortcut ? basenameOf(path6) : path6;
653
+ for (let index2 = 0; index2 < length; index2++) {
654
+ const rule = rules[index2];
655
+ const { negative } = rule;
656
+ const skip = unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored;
657
+ if (!skip && rule[mode].test(
658
+ shortcut && rule._basenameOnly ? basename11 : path6
659
+ )) {
660
+ ignored = !negative;
661
+ unignored = negative;
662
+ matchedRule = negative ? UNDEFINED : rule;
663
+ }
664
+ }
665
+ const ret2 = {
666
+ ignored,
667
+ unignored
668
+ };
669
+ if (matchedRule) {
670
+ ret2.rule = matchedRule;
671
+ }
672
+ return ret2;
673
+ }
674
+ };
675
+ var throwError = (message, Ctor) => {
676
+ throw new Ctor(message);
677
+ };
678
+ var checkPath = (path6, originalPath, doThrow) => {
679
+ if (!isString(path6)) {
680
+ return doThrow(
681
+ `path must be a string, but got \`${originalPath}\``,
682
+ TypeError
683
+ );
684
+ }
685
+ if (!path6) {
686
+ return doThrow(`path must not be empty`, TypeError);
687
+ }
688
+ if (checkPath.isNotRelative(path6)) {
689
+ const r = "`path.relative()`d";
690
+ return doThrow(
691
+ `path should be a ${r} string, but got "${originalPath}"`,
692
+ RangeError
693
+ );
694
+ }
695
+ return true;
696
+ };
697
+ var isNotRelative = (path6) => {
698
+ const first = path6.charCodeAt(0);
699
+ if (first === SLASH_CODE) {
700
+ return true;
701
+ }
702
+ if (first !== DOT_CODE) {
703
+ return false;
704
+ }
705
+ if (path6.length === 1) {
706
+ return true;
707
+ }
708
+ const second = path6.charCodeAt(1);
709
+ if (second === SLASH_CODE) {
710
+ return true;
711
+ }
712
+ if (second !== DOT_CODE) {
713
+ return false;
714
+ }
715
+ return path6.length === 2 || path6.charCodeAt(2) === SLASH_CODE;
716
+ };
717
+ checkPath.isNotRelative = isNotRelative;
718
+ checkPath.convert = (p) => p;
719
+ var Ignore = class {
720
+ constructor({
721
+ ignorecase = true,
722
+ ignoreCase = ignorecase,
723
+ allowRelativePaths = false
724
+ } = {}) {
725
+ define2(this, KEY_IGNORE, true);
726
+ this._rules = new RuleManager(ignoreCase);
727
+ this._strictPathCheck = !allowRelativePaths;
728
+ this._initCache();
729
+ }
730
+ _initCache() {
731
+ this._ignoreCache = /* @__PURE__ */ Object.create(null);
732
+ this._testCache = /* @__PURE__ */ Object.create(null);
733
+ }
734
+ add(pattern) {
735
+ if (this._rules.add(pattern)) {
736
+ this._initCache();
737
+ }
738
+ return this;
739
+ }
740
+ // legacy
741
+ addPattern(pattern) {
742
+ return this.add(pattern);
743
+ }
744
+ // @returns {TestResult}
745
+ _test(originalPath, cache, checkUnignored) {
746
+ const path6 = originalPath && checkPath.convert(originalPath);
747
+ checkPath(
748
+ path6,
749
+ originalPath,
750
+ this._strictPathCheck ? throwError : RETURN_FALSE
751
+ );
752
+ return this._t(path6, cache, checkUnignored);
753
+ }
754
+ checkIgnore(path6) {
755
+ if (path6.charCodeAt(path6.length - 1) !== SLASH_CODE) {
756
+ return this.test(path6);
757
+ }
758
+ const parentPath = parentOf(path6);
759
+ if (parentPath) {
760
+ const parent = this._t(parentPath, this._testCache, true);
761
+ if (parent.ignored) {
762
+ return parent;
763
+ }
764
+ }
765
+ return this._rules.test(path6, false, MODE_CHECK_IGNORE);
766
+ }
767
+ _t(path6, cache, checkUnignored) {
768
+ if (path6 in cache) {
769
+ return cache[path6];
770
+ }
771
+ const parentPath = parentOf(path6);
772
+ const parent = parentPath ? this._t(parentPath, cache, checkUnignored) : UNDEFINED;
773
+ return cache[path6] = parent && parent.ignored ? parent : this._rules.test(path6, checkUnignored, MODE_IGNORE);
774
+ }
775
+ ignores(path6) {
776
+ return this._test(path6, this._ignoreCache, false).ignored;
777
+ }
778
+ createFilter() {
779
+ return (path6) => !this.ignores(path6);
780
+ }
781
+ filter(paths) {
782
+ return makeArray(paths).filter(this.createFilter());
783
+ }
784
+ // @returns {TestResult}
785
+ test(path6) {
786
+ return this._test(path6, this._testCache, true);
787
+ }
788
+ };
789
+ var factory = (options) => new Ignore(options);
790
+ var isPathValid = (path6) => checkPath(path6 && checkPath.convert(path6), path6, RETURN_FALSE);
791
+ var setupWindows = () => {
792
+ const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
793
+ checkPath.convert = makePosix;
794
+ const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
795
+ checkPath.isNotRelative = (path6) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path6) || isNotRelative(path6);
796
+ };
797
+ if (
798
+ // Detect `process` so that it can run in browsers.
799
+ typeof process !== "undefined" && process.platform === "win32"
800
+ ) {
801
+ setupWindows();
802
+ }
803
+ module.exports = factory;
804
+ factory.default = factory;
805
+ module.exports.isPathValid = isPathValid;
806
+ define2(module.exports, /* @__PURE__ */ Symbol.for("setupWindows"), setupWindows);
807
+ }
808
+ });
7
809
 
8
810
  // src/engine/runtime/relay/runtime-revocation.ts
9
811
  var runtimeRevocationCloseCode = 1008;
@@ -19997,13 +20799,15 @@ function decodeRuntimePongEvent(encoded) {
19997
20799
  const scopedFileRead = Reflect.get(value, "scopedFileRead");
19998
20800
  const promptSuggestions = Reflect.get(value, "promptSuggestions");
19999
20801
  const usageQuota = Reflect.get(value, "usageQuota");
20802
+ const workspaceFiles = Reflect.get(value, "workspaceFiles");
20000
20803
  return {
20001
20804
  kind: RUNTIME_PONG_KIND,
20002
20805
  ...Reflect.get(value, "sessionTitleGeneration") === true ? { sessionTitleGeneration: true } : {},
20003
20806
  ...typeof promptSuggestions === "boolean" ? { promptSuggestions } : {},
20004
20807
  requestId: readIdentifier(value, "requestId"),
20005
20808
  ...typeof scopedFileRead === "boolean" ? { scopedFileRead } : {},
20006
- ...typeof usageQuota === "boolean" ? { usageQuota } : {}
20809
+ ...typeof usageQuota === "boolean" ? { usageQuota } : {},
20810
+ ...typeof workspaceFiles === "boolean" ? { workspaceFiles } : {}
20007
20811
  };
20008
20812
  }
20009
20813
  function encodeRuntimeLivenessReadyEvent(message) {
@@ -21974,6 +22778,70 @@ function decodeAgentPromptResponse(value) {
21974
22778
  return result.data;
21975
22779
  }
21976
22780
 
22781
+ // ../mobius-sdk/src/protocol/session/workspace/files.ts
22782
+ var WORKSPACE_FILES_LIST_KIND = "workspace.files.list";
22783
+ var WORKSPACE_FILES_KIND = "workspace.files";
22784
+ var WORKSPACE_FILE_READ_KIND = "workspace.file.read";
22785
+ var WORKSPACE_FILE_REPLY_SESSION_ID = "runtime";
22786
+ var WORKSPACE_FILES_PAGE_MAX_ENTRIES = 200;
22787
+ var WORKSPACE_FILE_PATH_MAX_LENGTH = 1024;
22788
+ var WORKSPACE_FILE_CURSOR_MAX_LENGTH = 128;
22789
+ var WORKSPACE_FILE_NAME_MAX_LENGTH = 255;
22790
+ function isWorkspaceRelativePath(value) {
22791
+ if (value === ".") {
22792
+ return true;
22793
+ }
22794
+ if (value.length === 0 || value.length > WORKSPACE_FILE_PATH_MAX_LENGTH || /[\0\\]/u.test(value)) {
22795
+ return false;
22796
+ }
22797
+ return value.split("/").every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
22798
+ }
22799
+ var workspaceRelativePathSchema = external_exports.string().min(1).max(WORKSPACE_FILE_PATH_MAX_LENGTH).refine(isWorkspaceRelativePath, "The workspace path must stay within its directory");
22800
+ var workspaceFileListCommandSchema = external_exports.object({
22801
+ bindingId: identifierStringSchema,
22802
+ cursor: external_exports.string().min(1).max(WORKSPACE_FILE_CURSOR_MAX_LENGTH).optional(),
22803
+ directory: workspaceRelativePathSchema,
22804
+ directoryId: DIRECTORY_IDENTIFIER,
22805
+ kind: external_exports.literal(WORKSPACE_FILES_LIST_KIND),
22806
+ limit: external_exports.number().int().min(1).max(WORKSPACE_FILES_PAGE_MAX_ENTRIES),
22807
+ requestId: identifierStringSchema
22808
+ }).readonly();
22809
+ var workspaceFileEntrySchema = external_exports.discriminatedUnion("kind", [
22810
+ external_exports.object({
22811
+ kind: external_exports.literal("directory"),
22812
+ name: external_exports.string().min(1).max(WORKSPACE_FILE_NAME_MAX_LENGTH),
22813
+ path: workspaceRelativePathSchema
22814
+ }).readonly(),
22815
+ external_exports.object({
22816
+ kind: external_exports.literal("file"),
22817
+ name: external_exports.string().min(1).max(WORKSPACE_FILE_NAME_MAX_LENGTH),
22818
+ path: workspaceRelativePathSchema,
22819
+ size: external_exports.number().int().nonnegative()
22820
+ }).readonly()
22821
+ ]);
22822
+ var workspaceFilesEventSchema = external_exports.object({
22823
+ bindingId: identifierStringSchema,
22824
+ directoryId: DIRECTORY_IDENTIFIER,
22825
+ entries: external_exports.array(workspaceFileEntrySchema).max(WORKSPACE_FILES_PAGE_MAX_ENTRIES).readonly(),
22826
+ kind: external_exports.literal(WORKSPACE_FILES_KIND),
22827
+ nextCursor: external_exports.string().min(1).max(WORKSPACE_FILE_CURSOR_MAX_LENGTH).optional(),
22828
+ requestId: identifierStringSchema
22829
+ }).readonly();
22830
+ var workspaceFileReadCommandSchema = external_exports.object({
22831
+ bindingId: identifierStringSchema,
22832
+ directoryId: DIRECTORY_IDENTIFIER,
22833
+ kind: external_exports.literal(WORKSPACE_FILE_READ_KIND),
22834
+ maxBytes: external_exports.number().int().positive().max(128 * 1024 * 1024),
22835
+ path: workspaceRelativePathSchema.refine((path6) => path6 !== ".", "The workspace path must name a file"),
22836
+ requestId: identifierStringSchema
22837
+ }).readonly();
22838
+ var decodeWorkspaceFileListCommand = (encoded) => decodeZodMessage(encoded, workspaceFileListCommandSchema);
22839
+ var encodeWorkspaceFileListCommand = (message) => encodeZodMessage(message, workspaceFileListCommandSchema);
22840
+ var decodeWorkspaceFilesEvent = (encoded) => decodeZodMessage(encoded, workspaceFilesEventSchema);
22841
+ var encodeWorkspaceFilesEvent = (message) => encodeZodMessage(message, workspaceFilesEventSchema);
22842
+ var decodeWorkspaceFileReadCommand = (encoded) => decodeZodMessage(encoded, workspaceFileReadCommandSchema);
22843
+ var encodeWorkspaceFileReadCommand = (message) => encodeZodMessage(message, workspaceFileReadCommandSchema);
22844
+
21977
22845
  // ../mobius-sdk/src/protocol/session/workspace/index.ts
21978
22846
  var WORKSPACE_LIST_KIND = "workspace.list";
21979
22847
  var WORKSPACE_ENTRIES_KIND = "workspace.entries";
@@ -22152,6 +23020,16 @@ var serviceToDaemonSignatures = {
22152
23020
  WORKSPACE_LIST_KIND,
22153
23021
  encodeWorkspaceListCommand,
22154
23022
  decodeWorkspaceListCommand
23023
+ ),
23024
+ [WORKSPACE_FILES_LIST_KIND]: defineMessageSignature(
23025
+ WORKSPACE_FILES_LIST_KIND,
23026
+ encodeWorkspaceFileListCommand,
23027
+ decodeWorkspaceFileListCommand
23028
+ ),
23029
+ [WORKSPACE_FILE_READ_KIND]: defineMessageSignature(
23030
+ WORKSPACE_FILE_READ_KIND,
23031
+ encodeWorkspaceFileReadCommand,
23032
+ decodeWorkspaceFileReadCommand
22155
23033
  )
22156
23034
  };
22157
23035
  var serviceToDaemonRegistry = serviceToDaemonSignatures;
@@ -22308,6 +23186,11 @@ var daemonToServiceSignatures = {
22308
23186
  WORKSPACE_ENTRIES_KIND,
22309
23187
  encodeWorkspaceEntriesEvent,
22310
23188
  decodeWorkspaceEntriesEvent
23189
+ ),
23190
+ [WORKSPACE_FILES_KIND]: defineMessageSignature(
23191
+ WORKSPACE_FILES_KIND,
23192
+ encodeWorkspaceFilesEvent,
23193
+ decodeWorkspaceFilesEvent
22311
23194
  )
22312
23195
  };
22313
23196
  function encodeDaemonToServiceMessage(message) {
@@ -28123,6 +29006,7 @@ var SESSION_UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-
28123
29006
  var SUBAGENT_CONVERSATION_ID_PATTERN = /"conversationId"\s*:\s*"([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})"/giu;
28124
29007
  var SUBAGENT_IDLE_ID_PATTERN = /\bSubagent ([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}) (?:has gone|went) idle\b/giu;
28125
29008
  var AGENT_EXECUTOR_ERROR_PATTERN = /^\s*⚠ agent executor error:\s*(.+?)\s*$/su;
29009
+ var TASK_RESULT_SENDER_PATTERN = /\bsender=([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/(task-\d+)\b/giu;
28126
29010
  var SUBAGENT_CREATED_MARKER = "Created the following subagent";
28127
29011
  var MAXIMUM_TOOL_DESCRIPTION_CHARS = 500;
28128
29012
  var transcriptStepSchema = external_exports.object({
@@ -28177,7 +29061,7 @@ async function readTranscriptTailState(launchEnvironment, sessionId, baselineSte
28177
29061
  return null;
28178
29062
  }
28179
29063
  if (tail.bytes.byteLength === 0) {
28180
- return { maxStepIndex: -1, settledStepIndex: null, steps: [] };
29064
+ return { firstStepIndex: -1, maxStepIndex: -1, settledStepIndex: null, steps: [] };
28181
29065
  }
28182
29066
  const text2 = new TextDecoder().decode(tail.bytes);
28183
29067
  const lines = text2.split("\n");
@@ -28200,11 +29084,13 @@ async function readTranscriptTailState(launchEnvironment, sessionId, baselineSte
28200
29084
  }
28201
29085
  }
28202
29086
  steps.sort((left, right) => left.step_index - right.step_index);
29087
+ const firstStepIndex = steps.at(0)?.step_index ?? -1;
28203
29088
  const maxStepIndex = steps.at(-1)?.step_index ?? -1;
28204
29089
  const settledStep = steps.find(
28205
29090
  (step) => step.step_index > baselineStepIndex && step.type === "PLANNER_RESPONSE" && step.status === "DONE" && (step.tool_calls === void 0 || step.tool_calls.length === 0)
28206
29091
  );
28207
29092
  return {
29093
+ firstStepIndex,
28208
29094
  maxStepIndex,
28209
29095
  settledStepIndex: settledStep?.step_index ?? null,
28210
29096
  steps
@@ -28402,6 +29288,8 @@ var AntigravityBackgroundWakeup = class {
28402
29288
  },
28403
29289
  toolMetadata: /* @__PURE__ */ new Map(),
28404
29290
  wakeupGeneration: 0,
29291
+ wakeupPendingTaskResults: 0,
29292
+ wakeupSettledStepIndex: null,
28405
29293
  wakeupStageSeq: 0
28406
29294
  };
28407
29295
  this.#sessions.set(sessionId, created);
@@ -28683,6 +29571,10 @@ var AntigravityBackgroundWakeup = class {
28683
29571
  }
28684
29572
  session.wakeupGeneration += 1;
28685
29573
  const generation = session.wakeupGeneration;
29574
+ session.wakeupPendingTaskResults = [...session.backgroundTasks.values()].filter(
29575
+ (task) => task.kind !== "subagent" && task.state === "awaiting-results"
29576
+ ).length;
29577
+ session.wakeupSettledStepIndex = null;
28686
29578
  this.#setWakeupAwaitingOutput(sessionId, session, generation, /* @__PURE__ */ new Set());
28687
29579
  notifications.push(
28688
29580
  makeMetaNotification(sessionId, AGENT_TURN_META, {
@@ -28784,9 +29676,11 @@ var AntigravityBackgroundWakeup = class {
28784
29676
  this.#syncSubagentCreations(current, tail.steps);
28785
29677
  }
28786
29678
  if (tail?.settledStepIndex !== null && tail?.settledStepIndex !== void 0) {
28787
- current.baselineStepIndex = Math.max(current.baselineStepIndex, tail.settledStepIndex);
28788
- this.#consumeSubagentIdlesThrough(current, tail.steps, tail.settledStepIndex);
28789
- this.#emitNotifications(this.#finishWakeup(sessionId, current, "end_turn", false));
29679
+ if (this.#settleWakeupReply(sessionId, current, tail, tail.settledStepIndex)) {
29680
+ this.#emitNotifications(this.#finishWakeup(sessionId, current, "end_turn", false));
29681
+ } else {
29682
+ this.#setWakeupAwaitingOutput(sessionId, current, generation, current.phase.openToolIds);
29683
+ }
28790
29684
  return;
28791
29685
  }
28792
29686
  if (currentStage.kind === "streaming" && currentStage.executorError !== void 0 && currentStage.executorErrorPolls >= 1) {
@@ -28798,6 +29692,34 @@ var AntigravityBackgroundWakeup = class {
28798
29692
  }
28799
29693
  this.#rescheduleTranscriptCheck(sessionId, current, generation, stageEpoch, currentStage);
28800
29694
  };
29695
+ /**
29696
+ * Records that the continuation's reply settled at `settledStepIndex` and counts the task results Antigravity
29697
+ * handed to it up to there. Answers whether the continuation ends: it goes on while results are still owed, since
29698
+ * Antigravity hands each to the run right after the reply it has, and the run continues from it.
29699
+ */
29700
+ #settleWakeupReply = (sessionId, session, tail, settledStepIndex) => {
29701
+ const sinceStepIndex = session.baselineStepIndex;
29702
+ session.baselineStepIndex = Math.max(session.baselineStepIndex, settledStepIndex);
29703
+ session.wakeupSettledStepIndex = settledStepIndex;
29704
+ this.#consumeSubagentIdlesThrough(session, tail.steps, settledStepIndex);
29705
+ if (tail.firstStepIndex > sinceStepIndex + 1) {
29706
+ session.wakeupPendingTaskResults = 0;
29707
+ return true;
29708
+ }
29709
+ const received = /* @__PURE__ */ new Set();
29710
+ for (const step of tail.steps) {
29711
+ if (step.step_index <= sinceStepIndex || step.step_index > settledStepIndex || step.type !== "SYSTEM_MESSAGE" || step.content === void 0) {
29712
+ continue;
29713
+ }
29714
+ for (const match of step.content.matchAll(TASK_RESULT_SENDER_PATTERN)) {
29715
+ if (match[1]?.toLowerCase() === sessionId.toLowerCase() && match[2] !== void 0) {
29716
+ received.add(match[2]);
29717
+ }
29718
+ }
29719
+ }
29720
+ session.wakeupPendingTaskResults = Math.max(0, session.wakeupPendingTaskResults - received.size);
29721
+ return session.wakeupPendingTaskResults === 0;
29722
+ };
28801
29723
  #handleWakeupTimeout = async (sessionId, generation, stageEpoch, message) => {
28802
29724
  if (this.#disposed) {
28803
29725
  return;
@@ -28831,8 +29753,11 @@ var AntigravityBackgroundWakeup = class {
28831
29753
  this.#syncSubagentCreations(current, tail.steps);
28832
29754
  }
28833
29755
  if (tail?.settledStepIndex !== null && tail?.settledStepIndex !== void 0) {
28834
- current.baselineStepIndex = Math.max(current.baselineStepIndex, tail.settledStepIndex);
28835
- this.#consumeSubagentIdlesThrough(current, tail.steps, tail.settledStepIndex);
29756
+ this.#settleWakeupReply(sessionId, current, tail, tail.settledStepIndex);
29757
+ this.#emitNotifications(this.#finishWakeup(sessionId, current, "end_turn", false));
29758
+ return;
29759
+ }
29760
+ if (current.wakeupSettledStepIndex !== null && (tail === null || tail.maxStepIndex <= current.wakeupSettledStepIndex)) {
28836
29761
  this.#emitNotifications(this.#finishWakeup(sessionId, current, "end_turn", false));
28837
29762
  return;
28838
29763
  }
@@ -28937,6 +29862,9 @@ var AntigravityBackgroundWakeup = class {
28937
29862
  const trackedExisting = session.backgroundTasks.get(toolCallId);
28938
29863
  if (trackedExisting !== void 0) {
28939
29864
  if (status === "completed") {
29865
+ if (trackedExisting.kind !== "subagent" && trackedExisting.state !== "awaiting-results") {
29866
+ session.wakeupPendingTaskResults += 1;
29867
+ }
28940
29868
  session.backgroundTasks.set(toolCallId, { ...trackedExisting, state: "awaiting-results" });
28941
29869
  const bg2 = this.#takeBackgroundTasksUpdate(sessionId, session);
28942
29870
  if (bg2 !== null) {
@@ -67659,8 +68587,8 @@ function inputPath(context, key) {
67659
68587
  return plainString(context.input[key]);
67660
68588
  }
67661
68589
  function isInside(directory, candidate) {
67662
- const relative4 = path.relative(path.resolve(directory), path.resolve(candidate));
67663
- return relative4 === "" || !relative4.startsWith(`..${path.sep}`) && relative4 !== "..";
68590
+ const relative5 = path.relative(path.resolve(directory), path.resolve(candidate));
68591
+ return relative5 === "" || !relative5.startsWith(`..${path.sep}`) && relative5 !== "..";
67664
68592
  }
67665
68593
  function hasSessionAllowRuleFor(changeSet, toolName) {
67666
68594
  return !!changeSet?.updates.some((update) => update.type === "addRules" && update.destination === "session" && update.behavior === "allow" && update.rules.some((rule) => rule.toolName === toolName));
@@ -68341,11 +69269,11 @@ function stripUsageBlock(text2) {
68341
69269
  if (!body.endsWith(USAGE_CLOSE)) {
68342
69270
  return text2;
68343
69271
  }
68344
- const open6 = body.lastIndexOf(USAGE_OPEN, body.length - USAGE_CLOSE.length - USAGE_OPEN.length);
68345
- if (open6 === -1) {
69272
+ const open7 = body.lastIndexOf(USAGE_OPEN, body.length - USAGE_CLOSE.length - USAGE_OPEN.length);
69273
+ if (open7 === -1) {
68346
69274
  return text2;
68347
69275
  }
68348
- return body.slice(0, open6 > 0 && body[open6 - 1] === "\n" ? open6 - 1 : open6);
69276
+ return body.slice(0, open7 > 0 && body[open7 - 1] === "\n" ? open7 - 1 : open7);
68349
69277
  }
68350
69278
  var AGENT_ID_LINE = /^agentId: [\w-]+ \([^)]*\)$/;
68351
69279
  function stripAgentIdLine(text2) {
@@ -76942,12 +77870,12 @@ var CodexOwnedAcpAgent = class {
76942
77870
  * cancellation), which clients merge idempotently. The wake rides the enqueued
76943
77871
  * emission so the waiting prompt's response never precedes the update. */
76944
77872
  #settleCompaction = (status, error62) => {
76945
- const open6 = this.#openCompaction;
76946
- if (open6 === null) {
77873
+ const open7 = this.#openCompaction;
77874
+ if (open7 === null) {
76947
77875
  return null;
76948
77876
  }
76949
77877
  const update = {
76950
- compactionId: open6.compactionId,
77878
+ compactionId: open7.compactionId,
76951
77879
  ...status === "failed" && error62 !== void 0 ? { error: error62 } : {},
76952
77880
  sessionUpdate: "compaction_update",
76953
77881
  status
@@ -76955,7 +77883,7 @@ var CodexOwnedAcpAgent = class {
76955
77883
  this.#finishCompaction(async () => {
76956
77884
  await this.#context.emit(update);
76957
77885
  });
76958
- return open6;
77886
+ return open7;
76959
77887
  };
76960
77888
  /** Clears the tracked compaction and emits the terminal update. Used by both
76961
77889
  * #settleCompaction and the item/completed handler, which emits its own
@@ -77023,8 +77951,8 @@ var CodexOwnedAcpAgent = class {
77023
77951
  ]);
77024
77952
  } catch (cause) {
77025
77953
  signal.throwIfAborted();
77026
- const open6 = this.#settleCompaction("failed", cause instanceof Error ? cause.message : String(cause));
77027
- if (open6 === null && !this.#turnSettledCompaction) {
77954
+ const open7 = this.#settleCompaction("failed", cause instanceof Error ? cause.message : String(cause));
77955
+ if (open7 === null && !this.#turnSettledCompaction) {
77028
77956
  const compactionId = randomUUID8();
77029
77957
  await this.#enqueue(async () => {
77030
77958
  await this.#context.emit({
@@ -79597,8 +80525,8 @@ var PiRpcProcess = class _PiRpcProcess {
79597
80525
  const sessionFile = typeof state?.sessionFile === "string" ? state.sessionFile : null;
79598
80526
  if (sessionFile) {
79599
80527
  const { mkdirSync: mkdirSync5 } = await import("node:fs");
79600
- const { dirname: dirname12 } = await import("node:path");
79601
- mkdirSync5(dirname12(sessionFile), { recursive: true });
80528
+ const { dirname: dirname13 } = await import("node:path");
80529
+ mkdirSync5(dirname13(sessionFile), { recursive: true });
79602
80530
  }
79603
80531
  } catch {
79604
80532
  }
@@ -81104,8 +82032,8 @@ var PiAcpSession = class {
81104
82032
  * without a matching start (e.g. replayed from a persisted session) has no
81105
82033
  * entity to patch, and fabricating an id would report a compaction the
81106
82034
  * client never saw open. */
81107
- compactionId(open6) {
81108
- if (!open6) {
82035
+ compactionId(open7) {
82036
+ if (!open7) {
81109
82037
  const settled = this.activeCompactionId;
81110
82038
  this.activeCompactionId = null;
81111
82039
  return settled;
@@ -88583,7 +89511,7 @@ function sql(strings, ...params) {
88583
89511
  return new SQL([new StringChunk(str)]);
88584
89512
  }
88585
89513
  _sql.raw = raw;
88586
- function join35(chunks, separator) {
89514
+ function join36(chunks, separator) {
88587
89515
  const result = [];
88588
89516
  for (const [i, chunk] of chunks.entries()) {
88589
89517
  if (i > 0 && separator !== void 0) result.push(separator);
@@ -88591,7 +89519,7 @@ function sql(strings, ...params) {
88591
89519
  }
88592
89520
  return new SQL(result);
88593
89521
  }
88594
- _sql.join = join35;
89522
+ _sql.join = join36;
88595
89523
  function identifier2(value) {
88596
89524
  return new Name(value);
88597
89525
  }
@@ -90736,7 +91664,7 @@ var SQLiteSelectBase = class extends TypedQueryBuilder {
90736
91664
  const baseTableName = this.tableName;
90737
91665
  const tableName = getTableLikeName(table);
90738
91666
  for (const item of extractUsedTable(table)) this.usedTables.add(item);
90739
- if (typeof tableName === "string" && this.config.joins?.some((join35) => join35.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
91667
+ if (typeof tableName === "string" && this.config.joins?.some((join36) => join36.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
90740
91668
  if (!this.isPartialSelect) {
90741
91669
  if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
90742
91670
  if (typeof tableName === "string" && !is(table, SQL)) {
@@ -91575,7 +92503,7 @@ var SQLiteDialect = class {
91575
92503
  if (!joins2) return;
91576
92504
  const withEntries = Object.entries(joins2).filter(([_, v]) => v);
91577
92505
  if (!withEntries.length) return;
91578
- return sql.join(withEntries.map(([k2, join35]) => {
92506
+ return sql.join(withEntries.map(([k2, join36]) => {
91579
92507
  const relation = tableConfig.relations[k2];
91580
92508
  const isSingle2 = is(relation, One2);
91581
92509
  const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
@@ -91586,7 +92514,7 @@ var SQLiteDialect = class {
91586
92514
  table: targetTable,
91587
92515
  mode: isSingle2 ? "first" : "many",
91588
92516
  schema,
91589
- queryConfig: join35,
92517
+ queryConfig: join36,
91590
92518
  tableConfig: schema[relation.targetTableName],
91591
92519
  relationWhere: filter,
91592
92520
  isNested: true,
@@ -91600,7 +92528,7 @@ var SQLiteDialect = class {
91600
92528
  key: k2,
91601
92529
  selection: innerQuery.selection,
91602
92530
  isArray: !isSingle2,
91603
- isOptional: (relation.optional ?? false) || join35 !== true && !!join35.where
92531
+ isOptional: (relation.optional ?? false) || join36 !== true && !!join36.where
91604
92532
  });
91605
92533
  const jsonColumns = sql.join(innerQuery.selection.map((s) => {
91606
92534
  return sql`${sql.raw(this.escapeString(s.key))}, ${s.selection ? sql`${jsonb}(${sql.identifier(s.key)})` : sql.identifier(s.key)}`;
@@ -92216,7 +93144,7 @@ var SQLiteUpdateBase = class {
92216
93144
  createJoin(joinType) {
92217
93145
  return ((table, on2) => {
92218
93146
  const tableName = getTableLikeName(table);
92219
- if (typeof tableName === "string" && this.config.joins.some((join35) => join35.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
93147
+ if (typeof tableName === "string" && this.config.joins.some((join36) => join36.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
92220
93148
  if (typeof on2 === "function") {
92221
93149
  const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
92222
93150
  on2 = on2(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
@@ -99957,7 +100885,7 @@ var RelayConnectionDiagnostics = class {
99957
100885
  };
99958
100886
 
99959
100887
  // src/engine/runtime/relay/run-relay-connection.ts
99960
- import { WebSocket as WebSocket9 } from "undici";
100888
+ import { WebSocket as WebSocket10 } from "undici";
99961
100889
 
99962
100890
  // src/engine/runtime/catalog/handle-agent-catalog-discovery.ts
99963
100891
  import { WebSocket as WebSocket3 } from "undici";
@@ -100708,8 +101636,441 @@ function createContentWriteCommands(context) {
100708
101636
  import { WebSocket as WebSocket5 } from "undici";
100709
101637
 
100710
101638
  // src/engine/session/content/session-files.ts
100711
- import { basename as basename9, extname as extname3, isAbsolute as isAbsolute17, join as join34, normalize as normalize3, resolve as resolve18 } from "node:path";
101639
+ import { basename as basename9, extname as extname3, isAbsolute as isAbsolute18, join as join35, normalize as normalize3, resolve as resolve18 } from "node:path";
100712
101640
  import { fileURLToPath as fileURLToPath2 } from "node:url";
101641
+
101642
+ // src/engine/storage/files/workspace-files.ts
101643
+ var import_ignore = __toESM(require_ignore(), 1);
101644
+ import { constants as constants6 } from "node:fs";
101645
+ import { lstat as lstat5, open as open6, readdir as readdir7, realpath as realpath8 } from "node:fs/promises";
101646
+ import { dirname as dirname12, isAbsolute as isAbsolute17, join as join34, relative as relative4, sep as sep6 } from "node:path";
101647
+ var MAXIMUM_NAME_LENGTH = 255;
101648
+ var MAXIMUM_PATH_LENGTH = 1024;
101649
+ var MAXIMUM_IGNORE_FILE_BYTES = 1024 * 1024;
101650
+ var IGNORE_FILE_READ_CHUNK_BYTES = 64 * 1024;
101651
+ var WORKSPACE_FILE_LIST_DEADLINE_MILLISECONDS = 2e4;
101652
+ var WORKSPACE_FILE_LIST_ATTEMPTS = 2;
101653
+ var WorkspaceFileError = class extends OperationError {
101654
+ code;
101655
+ constructor(code, message, options = {}) {
101656
+ super(code, message, options);
101657
+ this.code = code;
101658
+ this.name = "WorkspaceFileError";
101659
+ }
101660
+ };
101661
+ async function listWorkspaceFiles(root, directory, cursor, limit, signal, timer) {
101662
+ const offset = cursor === void 0 ? 0 : Number(cursor);
101663
+ if (cursor !== void 0 && (!/^(0|[1-9][0-9]{0,9})$/u.test(cursor) || !Number.isSafeInteger(offset))) {
101664
+ throw new WorkspaceFileError("invalid_cursor", "The workspace file cursor is invalid");
101665
+ }
101666
+ const resolved = await resolveWorkspaceDirectory(root, directory, signal);
101667
+ for (let attempt = 1; ; attempt += 1) {
101668
+ try {
101669
+ return await listResolvedDirectory(root, resolved, offset, limit, signal, timer);
101670
+ } catch (cause) {
101671
+ if (!(cause instanceof DirectoryChangedError) || attempt >= WORKSPACE_FILE_LIST_ATTEMPTS) {
101672
+ throw cause;
101673
+ }
101674
+ }
101675
+ }
101676
+ }
101677
+ async function listResolvedDirectory(root, resolved, offset, limit, signal, timer) {
101678
+ const target = resolved.path;
101679
+ const handle = await openValidatedDirectory(resolved);
101680
+ let task;
101681
+ const deadline = new AbortController();
101682
+ try {
101683
+ const ancestry = await recordAncestry(root, resolved);
101684
+ signal.throwIfAborted();
101685
+ task = timer.schedule(
101686
+ () => deadline.abort(new DOMException("Reading the workspace directory timed out", "TimeoutError")),
101687
+ WORKSPACE_FILE_LIST_DEADLINE_MILLISECONDS
101688
+ );
101689
+ const page = await readOpenedDirectory(
101690
+ root,
101691
+ target,
101692
+ handle,
101693
+ offset,
101694
+ limit,
101695
+ AbortSignal.any([signal, deadline.signal])
101696
+ );
101697
+ await verifyAncestryUnchanged(ancestry, resolved, handle);
101698
+ return page;
101699
+ } catch (cause) {
101700
+ signal.throwIfAborted();
101701
+ if (deadline.signal.aborted) {
101702
+ throw new WorkspaceFileError("read_timeout", "Reading the workspace directory timed out", { cause });
101703
+ }
101704
+ throw cause;
101705
+ } finally {
101706
+ task?.cancel();
101707
+ await handle.close();
101708
+ }
101709
+ }
101710
+ async function readOpenedDirectory(root, target, handle, offset, limit, signal) {
101711
+ const access4 = process.platform === "linux" ? `/proc/self/fd/${handle.fd}` : target;
101712
+ const matcher = await ignoreMatcher(root, target, target, signal);
101713
+ const children = await readdir7(access4, { withFileTypes: true }).catch((cause) => {
101714
+ if (isDenied(cause)) {
101715
+ throw new WorkspaceFileError("file_unavailable", "The workspace directory cannot be read", { cause });
101716
+ }
101717
+ throw cause;
101718
+ });
101719
+ signal.throwIfAborted();
101720
+ const visible = [];
101721
+ for (const entry of children) {
101722
+ if (entry.name.includes("\\") || entry.name.length > MAXIMUM_NAME_LENGTH) {
101723
+ continue;
101724
+ }
101725
+ const path6 = portable(relative4(root, join34(target, entry.name)));
101726
+ const matchedPath = entry.isDirectory() ? `${path6}/` : path6;
101727
+ if (path6.length > MAXIMUM_PATH_LENGTH || isGitPath(path6) || matcher.ignores(matchedPath)) {
101728
+ continue;
101729
+ }
101730
+ if (entry.isDirectory()) {
101731
+ visible.push({ entry, kind: "directory", path: path6 });
101732
+ } else if (entry.isFile()) {
101733
+ visible.push({ entry, kind: "file", path: path6 });
101734
+ }
101735
+ }
101736
+ visible.sort(
101737
+ (left, right) => left.kind === right.kind ? left.entry.name.localeCompare(right.entry.name, void 0, { numeric: true, sensitivity: "base" }) : left.kind === "directory" ? -1 : 1
101738
+ );
101739
+ const selected = visible.slice(offset, offset + limit);
101740
+ const entries = [];
101741
+ for (const { entry, kind, path: path6 } of selected) {
101742
+ if (kind === "directory") {
101743
+ entries.push({ kind, name: entry.name, path: path6 });
101744
+ continue;
101745
+ }
101746
+ try {
101747
+ const metadata = await lstat5(join34(access4, entry.name));
101748
+ signal.throwIfAborted();
101749
+ if (metadata.isFile()) {
101750
+ entries.push({ kind, name: entry.name, path: path6, size: metadata.size });
101751
+ }
101752
+ } catch (cause) {
101753
+ signal.throwIfAborted();
101754
+ if (!isMissing(cause)) {
101755
+ throw cause;
101756
+ }
101757
+ }
101758
+ }
101759
+ const nextOffset = offset + selected.length;
101760
+ return nextOffset < visible.length ? { entries, nextCursor: String(nextOffset) } : { entries };
101761
+ }
101762
+ async function withWorkspaceFile(root, path6, maximumBytes, signal, useFile) {
101763
+ const requested = requestedTarget(root, path6);
101764
+ const metadata = await lstatOrNotFound(requested);
101765
+ signal.throwIfAborted();
101766
+ if (metadata.isSymbolicLink() || !metadata.isFile()) {
101767
+ throw new WorkspaceFileError("file_unavailable", "The workspace path is not a regular file");
101768
+ }
101769
+ const canonical = await realpathOrNotFound(requested);
101770
+ signal.throwIfAborted();
101771
+ const rootPath = containedPath(root, canonical);
101772
+ const parent = dirname12(canonical);
101773
+ if (isGitPath(rootPath) || (await ignoreMatcher(root, parent, parent, signal)).ignores(rootPath)) {
101774
+ throw new WorkspaceFileError("file_ignored", "The workspace file is hidden by ignore rules");
101775
+ }
101776
+ try {
101777
+ await withScopedLocalFile(root, rootPath, maximumBytes, signal, useFile);
101778
+ } catch (cause) {
101779
+ signal.throwIfAborted();
101780
+ if (cause instanceof ScopedFileReadError) {
101781
+ throw new WorkspaceFileError(cause.code, "The workspace file is unavailable", { cause });
101782
+ }
101783
+ if (isMissing(cause)) {
101784
+ throw new WorkspaceFileError("file_not_found", "The workspace file does not exist", { cause });
101785
+ }
101786
+ throw cause;
101787
+ }
101788
+ }
101789
+ async function resolveWorkspaceDirectory(root, directory, signal) {
101790
+ let canonical = root;
101791
+ if (directory !== ".") {
101792
+ const requested = requestedTarget(root, directory);
101793
+ const metadata = await lstatOrNotFound(requested);
101794
+ signal.throwIfAborted();
101795
+ if (metadata.isSymbolicLink() || !metadata.isDirectory()) {
101796
+ throw new WorkspaceFileError("file_unavailable", "The workspace path is not a regular directory");
101797
+ }
101798
+ canonical = await realpathOrNotFound(requested);
101799
+ signal.throwIfAborted();
101800
+ if (isGitPath(containedPath(root, canonical))) {
101801
+ throw new WorkspaceFileError("file_ignored", "The workspace directory is hidden");
101802
+ }
101803
+ }
101804
+ const identity2 = await ancestorState(canonical);
101805
+ signal.throwIfAborted();
101806
+ return { path: canonical, device: identity2.device, inode: identity2.inode };
101807
+ }
101808
+ async function openValidatedDirectory(resolved) {
101809
+ let handle;
101810
+ try {
101811
+ handle = await open6(resolved.path, constants6.O_RDONLY | constants6.O_DIRECTORY | constants6.O_NOFOLLOW);
101812
+ } catch (cause) {
101813
+ if (hasCode(cause, "ELOOP") || hasCode(cause, "ENOTDIR")) {
101814
+ throw directoryChanged(cause);
101815
+ }
101816
+ if (isMissing(cause)) {
101817
+ throw new WorkspaceFileError("file_not_found", "The workspace path does not exist", { cause });
101818
+ }
101819
+ if (isDenied(cause)) {
101820
+ throw new WorkspaceFileError("file_unavailable", "The workspace directory cannot be read", { cause });
101821
+ }
101822
+ throw cause;
101823
+ }
101824
+ try {
101825
+ if (!sameDirectory(resolved, await handle.stat({ bigint: true }))) {
101826
+ throw directoryChanged();
101827
+ }
101828
+ return handle;
101829
+ } catch (cause) {
101830
+ await handle.close();
101831
+ throw cause;
101832
+ }
101833
+ }
101834
+ async function recordAncestry(root, resolved) {
101835
+ const top = dirname12(root);
101836
+ const below = relative4(top, resolved.path);
101837
+ const paths = [top];
101838
+ for (const segment of below === "" ? [] : below.split(sep6)) {
101839
+ paths.push(join34(paths[paths.length - 1] ?? top, segment));
101840
+ }
101841
+ const ancestry = [];
101842
+ for (const path6 of paths) {
101843
+ ancestry.push(await ancestorState(path6));
101844
+ }
101845
+ const listed = ancestry[ancestry.length - 1];
101846
+ if (listed === void 0 || listed.device !== resolved.device || listed.inode !== resolved.inode) {
101847
+ throw directoryChanged();
101848
+ }
101849
+ return ancestry;
101850
+ }
101851
+ async function verifyAncestryUnchanged(ancestry, resolved, handle) {
101852
+ if (!sameDirectory(resolved, await handle.stat({ bigint: true }))) {
101853
+ throw directoryChanged();
101854
+ }
101855
+ for (const before of ancestry) {
101856
+ const after = await ancestorState(before.path);
101857
+ if (after.device !== before.device || after.inode !== before.inode || after.changedAt !== before.changedAt || after.modifiedAt !== before.modifiedAt) {
101858
+ throw directoryChanged();
101859
+ }
101860
+ }
101861
+ try {
101862
+ if (await realpath8(resolved.path) !== resolved.path) {
101863
+ throw directoryChanged();
101864
+ }
101865
+ } catch (cause) {
101866
+ if (isMissing(cause) || hasCode(cause, "ELOOP")) {
101867
+ throw directoryChanged(cause);
101868
+ }
101869
+ throw cause;
101870
+ }
101871
+ }
101872
+ async function ancestorState(path6) {
101873
+ let metadata;
101874
+ try {
101875
+ metadata = await lstat5(path6, { bigint: true });
101876
+ } catch (cause) {
101877
+ if (isMissing(cause) || hasCode(cause, "ELOOP")) {
101878
+ throw directoryChanged(cause);
101879
+ }
101880
+ throw cause;
101881
+ }
101882
+ if (metadata.isSymbolicLink() || !metadata.isDirectory()) {
101883
+ throw directoryChanged();
101884
+ }
101885
+ return {
101886
+ path: path6,
101887
+ device: metadata.dev,
101888
+ inode: metadata.ino,
101889
+ changedAt: metadata.ctimeNs,
101890
+ modifiedAt: metadata.mtimeNs
101891
+ };
101892
+ }
101893
+ function sameDirectory(resolved, metadata) {
101894
+ return metadata.isDirectory() && metadata.dev === resolved.device && metadata.ino === resolved.inode;
101895
+ }
101896
+ var DirectoryChangedError = class extends WorkspaceFileError {
101897
+ constructor(options) {
101898
+ super("file_outside_scope", "The workspace directory changed while it was being read", options);
101899
+ this.name = "DirectoryChangedError";
101900
+ }
101901
+ };
101902
+ function directoryChanged(cause) {
101903
+ return new DirectoryChangedError(cause === void 0 ? {} : { cause });
101904
+ }
101905
+ function requestedTarget(root, path6) {
101906
+ const segments = path6.split("/");
101907
+ if (path6.length === 0 || path6.length > MAXIMUM_PATH_LENGTH || /[\0\\]/u.test(path6) || segments.some((segment) => segment.length === 0 || segment === "." || segment === "..")) {
101908
+ throw new WorkspaceFileError("file_outside_scope", "The workspace path leaves its directory");
101909
+ }
101910
+ return join34(root, ...segments);
101911
+ }
101912
+ function containedPath(root, canonical) {
101913
+ const child = relative4(root, canonical);
101914
+ if (child === "" || child === ".." || child.startsWith(`..${sep6}`) || isAbsolute17(child)) {
101915
+ throw new WorkspaceFileError("file_outside_scope", "The workspace path leaves its directory");
101916
+ }
101917
+ return portable(child);
101918
+ }
101919
+ async function ignoreMatcher(root, throughDirectory, explicitDirectory, signal) {
101920
+ const rules = [{ base: ".", matcher: (0, import_ignore.default)().add(".git/").add(".git/**") }];
101921
+ const through = relative4(root, throughDirectory);
101922
+ const segments = through === "" ? [] : through.split(sep6);
101923
+ let directory = root;
101924
+ for (let index2 = 0; index2 <= segments.length; index2 += 1) {
101925
+ const matcher = (0, import_ignore.default)();
101926
+ for (const name2 of [".gitignore", ".ignore"]) {
101927
+ matcher.add(await readIgnoreFile(join34(directory, name2), signal));
101928
+ }
101929
+ rules.push({ base: portable(relative4(root, directory)), matcher });
101930
+ const segment = segments[index2];
101931
+ if (segment !== void 0) {
101932
+ directory = join34(directory, segment);
101933
+ }
101934
+ }
101935
+ const explicit = portable(relative4(root, explicitDirectory));
101936
+ if (explicit !== ".") {
101937
+ for (const rule of rules) {
101938
+ const local = relativeTo(rule.base, explicit);
101939
+ if (local === void 0 || local === ".") {
101940
+ continue;
101941
+ }
101942
+ const localSegments = local.split("/").map(literalIgnorePattern);
101943
+ for (let index2 = 0; index2 < localSegments.length; index2 += 1) {
101944
+ rule.matcher.add([`!/${localSegments.slice(0, index2 + 1).join("/")}/`]);
101945
+ }
101946
+ }
101947
+ }
101948
+ return {
101949
+ ignores: (rootPath) => {
101950
+ let ignored = false;
101951
+ for (const rule of rules) {
101952
+ const local = relativeTo(rule.base, rootPath);
101953
+ if (local === void 0 || local === ".") {
101954
+ continue;
101955
+ }
101956
+ const result = rule.matcher.test(local);
101957
+ if (result.ignored) {
101958
+ ignored = true;
101959
+ }
101960
+ if (result.unignored) {
101961
+ ignored = false;
101962
+ }
101963
+ }
101964
+ return ignored;
101965
+ }
101966
+ };
101967
+ }
101968
+ async function readIgnoreFile(path6, signal) {
101969
+ let handle;
101970
+ try {
101971
+ handle = await open6(path6, constants6.O_RDONLY | constants6.O_NOFOLLOW | constants6.O_NONBLOCK);
101972
+ } catch (cause) {
101973
+ signal.throwIfAborted();
101974
+ if (isMissing(cause) || hasCode(cause, "ELOOP")) {
101975
+ return "";
101976
+ }
101977
+ throw ignoreRulesUnavailable(cause);
101978
+ }
101979
+ try {
101980
+ const metadata = await handle.stat();
101981
+ signal.throwIfAborted();
101982
+ if (!metadata.isFile()) {
101983
+ return "";
101984
+ }
101985
+ if (metadata.size > MAXIMUM_IGNORE_FILE_BYTES) {
101986
+ throw ignoreRulesUnavailable();
101987
+ }
101988
+ const buffer = Buffer.alloc(MAXIMUM_IGNORE_FILE_BYTES + 1);
101989
+ let length = 0;
101990
+ for (; ; ) {
101991
+ const { bytesRead } = await handle.read(
101992
+ buffer,
101993
+ length,
101994
+ Math.min(IGNORE_FILE_READ_CHUNK_BYTES, buffer.length - length),
101995
+ length
101996
+ );
101997
+ signal.throwIfAborted();
101998
+ if (bytesRead === 0) {
101999
+ break;
102000
+ }
102001
+ length += bytesRead;
102002
+ if (length > MAXIMUM_IGNORE_FILE_BYTES) {
102003
+ throw ignoreRulesUnavailable();
102004
+ }
102005
+ }
102006
+ return buffer.toString("utf8", 0, length);
102007
+ } catch (cause) {
102008
+ signal.throwIfAborted();
102009
+ if (cause instanceof WorkspaceFileError) {
102010
+ throw cause;
102011
+ }
102012
+ throw ignoreRulesUnavailable(cause);
102013
+ } finally {
102014
+ await handle.close();
102015
+ }
102016
+ }
102017
+ function ignoreRulesUnavailable(cause) {
102018
+ return new WorkspaceFileError(
102019
+ "ignore_rules_unavailable",
102020
+ "An ignore file in the workspace cannot be read",
102021
+ cause === void 0 ? {} : { cause }
102022
+ );
102023
+ }
102024
+ function literalIgnorePattern(segment) {
102025
+ return segment.replace(/[\\*?[\]!# ]/gu, (character) => `\\${character}`);
102026
+ }
102027
+ function relativeTo(base, path6) {
102028
+ if (base === ".") {
102029
+ return path6;
102030
+ }
102031
+ if (path6 === base) {
102032
+ return ".";
102033
+ }
102034
+ return path6.startsWith(`${base}/`) ? path6.slice(base.length + 1) : void 0;
102035
+ }
102036
+ function portable(path6) {
102037
+ const value = path6.split(sep6).join("/");
102038
+ return value === "" ? "." : value;
102039
+ }
102040
+ function isGitPath(path6) {
102041
+ return path6.split("/").includes(".git");
102042
+ }
102043
+ function isMissing(error62) {
102044
+ return error62 instanceof Error && "code" in error62 && (error62.code === "ENOENT" || error62.code === "ENOTDIR" || error62.code === "EISDIR");
102045
+ }
102046
+ function hasCode(error62, code) {
102047
+ return error62 instanceof Error && "code" in error62 && error62.code === code;
102048
+ }
102049
+ function isDenied(error62) {
102050
+ return error62 instanceof Error && "code" in error62 && (error62.code === "EACCES" || error62.code === "EPERM");
102051
+ }
102052
+ async function lstatOrNotFound(path6) {
102053
+ try {
102054
+ return await lstat5(path6);
102055
+ } catch (cause) {
102056
+ if (isMissing(cause)) {
102057
+ throw new WorkspaceFileError("file_not_found", "The workspace path does not exist", { cause });
102058
+ }
102059
+ throw cause;
102060
+ }
102061
+ }
102062
+ async function realpathOrNotFound(path6) {
102063
+ try {
102064
+ return await realpath8(path6);
102065
+ } catch (cause) {
102066
+ if (isMissing(cause)) {
102067
+ throw new WorkspaceFileError("file_not_found", "The workspace path does not exist", { cause });
102068
+ }
102069
+ throw cause;
102070
+ }
102071
+ }
102072
+
102073
+ // src/engine/session/content/session-files.ts
100713
102074
  function requestedPath(value) {
100714
102075
  if (value.includes("\0")) {
100715
102076
  return null;
@@ -100726,21 +102087,21 @@ function requestedPath(value) {
100726
102087
  }
100727
102088
  async function resolveFile(value, workingDirectory, signal) {
100728
102089
  const requested = requestedPath(value);
100729
- if (requested === null || !isAbsolute17(requested.path) && workingDirectory === null) {
102090
+ if (requested === null || !isAbsolute18(requested.path) && workingDirectory === null) {
100730
102091
  return null;
100731
102092
  }
100732
- if (isAbsolute17(requested.path) && normalize3(requested.path) !== requested.path) {
102093
+ if (isAbsolute18(requested.path) && normalize3(requested.path) !== requested.path) {
100733
102094
  return null;
100734
102095
  }
100735
- const candidates = requested.explicitUrl || workingDirectory === null ? [requested.path] : isAbsolute17(requested.path) ? [join34(workingDirectory, requested.path), requested.path] : [resolve18(workingDirectory, requested.path)];
102096
+ const candidates = requested.explicitUrl || workingDirectory === null ? [requested.path] : isAbsolute18(requested.path) ? [join35(workingDirectory, requested.path), requested.path] : [resolve18(workingDirectory, requested.path)];
100736
102097
  for (const candidate of candidates) {
100737
- if (!isAbsolute17(candidate) || normalize3(candidate) !== candidate) {
102098
+ if (!isAbsolute18(candidate) || normalize3(candidate) !== candidate) {
100738
102099
  continue;
100739
102100
  }
100740
102101
  try {
100741
102102
  const target = await canonicalPath(candidate);
100742
102103
  signal.throwIfAborted();
100743
- if (isAbsolute17(target) && normalize3(target) === target) {
102104
+ if (isAbsolute18(target) && normalize3(target) === target) {
100744
102105
  return target;
100745
102106
  }
100746
102107
  } catch {
@@ -100796,31 +102157,39 @@ async function streamScopedFile(command, send2, sendChunk, signal, workingDirect
100796
102157
  throw new ScopedFileReadError("file_outside_scope");
100797
102158
  }
100798
102159
  await withScopedLocalFile(workingDirectory, requested.path, command.maxBytes, signal, async (file2) => {
100799
- const header = await file2.readPrefix(16);
100800
- signal.throwIfAborted();
100801
- send2({
100802
- byteLength: file2.size,
100803
- kind: FILE_BEGIN_KIND,
100804
- mediaType: sniffRasterMime(header) ?? "application/octet-stream",
100805
- modifiedAt: file2.modifiedAt.toISOString(),
100806
- name: file2.name,
100807
- requestId: command.requestId,
100808
- sessionId: command.sessionId
100809
- });
100810
- let sequence = 0;
100811
- let received = 0;
100812
- for await (const bytes of file2.chunks(CONTENT_CHUNK_MAX_BYTES)) {
100813
- received += bytes.byteLength;
100814
- sendChunk(command.requestId, sequence, bytes);
100815
- sequence += 1;
100816
- }
100817
- if (received !== file2.size) {
100818
- throw new ScopedFileReadError("file_unavailable");
100819
- }
100820
- await file2.verifyUnchanged();
100821
- send2({ kind: FILE_END_KIND, requestId: command.requestId, sessionId: command.sessionId });
102160
+ await streamOpenedFile(file2, command.requestId, command.sessionId, send2, sendChunk, signal);
100822
102161
  });
100823
102162
  }
102163
+ async function streamWorkspaceFile(command, root, send2, sendChunk, signal) {
102164
+ await withWorkspaceFile(root, command.path, command.maxBytes, signal, async (file2) => {
102165
+ await streamOpenedFile(file2, command.requestId, WORKSPACE_FILE_REPLY_SESSION_ID, send2, sendChunk, signal);
102166
+ });
102167
+ }
102168
+ async function streamOpenedFile(file2, requestId, sessionId, send2, sendChunk, signal) {
102169
+ const header = await file2.readPrefix(16);
102170
+ signal.throwIfAborted();
102171
+ send2({
102172
+ byteLength: file2.size,
102173
+ kind: FILE_BEGIN_KIND,
102174
+ mediaType: sniffRasterMime(header) ?? "application/octet-stream",
102175
+ modifiedAt: file2.modifiedAt.toISOString(),
102176
+ name: file2.name,
102177
+ requestId,
102178
+ sessionId
102179
+ });
102180
+ let sequence = 0;
102181
+ let received = 0;
102182
+ for await (const bytes of file2.chunks(CONTENT_CHUNK_MAX_BYTES)) {
102183
+ received += bytes.byteLength;
102184
+ sendChunk(requestId, sequence, bytes);
102185
+ sequence += 1;
102186
+ }
102187
+ if (received !== file2.size) {
102188
+ throw new ScopedFileReadError("file_unavailable");
102189
+ }
102190
+ await file2.verifyUnchanged();
102191
+ send2({ kind: FILE_END_KIND, requestId, sessionId });
102192
+ }
100824
102193
 
100825
102194
  // src/engine/runtime/command/registry/file-read/index.ts
100826
102195
  var fileReadCommand = {
@@ -101738,7 +103107,8 @@ var runtimePingCommand = {
101738
103107
  sessionTitleGeneration: true,
101739
103108
  requestId: message.requestId,
101740
103109
  scopedFileRead: supportsScopedLocalFileRead(),
101741
- usageQuota: true
103110
+ usageQuota: true,
103111
+ workspaceFiles: supportsScopedLocalFileRead()
101742
103112
  });
101743
103113
  }
101744
103114
  };
@@ -102176,6 +103546,88 @@ var sessionConfigReadCommand = {
102176
103546
  }
102177
103547
  };
102178
103548
 
103549
+ // src/engine/runtime/command/registry/workspace-files.ts
103550
+ import { WebSocket as WebSocket8 } from "undici";
103551
+ async function workspaceRoot(context, command) {
103552
+ try {
103553
+ return await context.directories.resolve(command.bindingId, command.directoryId, context.signal);
103554
+ } catch (cause) {
103555
+ context.signal.throwIfAborted();
103556
+ if (cause instanceof LocalAuthorizationError) {
103557
+ throw new WorkspaceFileError("directory_unavailable", cause.message, { cause });
103558
+ }
103559
+ throw cause;
103560
+ }
103561
+ }
103562
+ async function executeWorkspaceFileList(context, command) {
103563
+ try {
103564
+ const root = await workspaceRoot(context, command);
103565
+ const page = await listWorkspaceFiles(
103566
+ root,
103567
+ command.directory,
103568
+ command.cursor,
103569
+ command.limit,
103570
+ context.signal,
103571
+ context.timer
103572
+ );
103573
+ send(context.socket, {
103574
+ bindingId: command.bindingId,
103575
+ directoryId: command.directoryId,
103576
+ entries: page.entries,
103577
+ kind: WORKSPACE_FILES_KIND,
103578
+ ...page.nextCursor === void 0 ? {} : { nextCursor: page.nextCursor },
103579
+ requestId: command.requestId
103580
+ });
103581
+ } catch (error62) {
103582
+ if (context.signal.aborted) {
103583
+ return;
103584
+ }
103585
+ reportOperationFailure(context.socket, command.requestId, "", error62);
103586
+ }
103587
+ }
103588
+ async function executeWorkspaceFileRead(context, command) {
103589
+ const { signal, socket } = context;
103590
+ try {
103591
+ const root = await workspaceRoot(context, command);
103592
+ await streamWorkspaceFile(
103593
+ command,
103594
+ root,
103595
+ (response) => send(socket, response),
103596
+ (requestId, sequence, bytes) => sendContentChunk(socket, requestId, sequence, bytes),
103597
+ signal
103598
+ );
103599
+ } catch (error62) {
103600
+ if (socket.readyState !== WebSocket8.OPEN || signal.aborted) {
103601
+ return;
103602
+ }
103603
+ send(socket, {
103604
+ code: error62 instanceof WorkspaceFileError ? error62.code : "file_unavailable",
103605
+ kind: FILE_FAILED_KIND,
103606
+ message: error62 instanceof WorkspaceFileError ? error62.message : "The local file is unavailable",
103607
+ requestId: command.requestId,
103608
+ sessionId: WORKSPACE_FILE_REPLY_SESSION_ID
103609
+ });
103610
+ }
103611
+ }
103612
+ var workspaceFileListCommand = {
103613
+ kind: WORKSPACE_FILES_LIST_KIND,
103614
+ handle: (context, message) => {
103615
+ if (message.kind !== WORKSPACE_FILES_LIST_KIND) {
103616
+ throw new Error("Command kind mismatch");
103617
+ }
103618
+ void executeWorkspaceFileList(context, message);
103619
+ }
103620
+ };
103621
+ var workspaceFileReadCommand = {
103622
+ kind: WORKSPACE_FILE_READ_KIND,
103623
+ handle: (context, message) => {
103624
+ if (message.kind !== WORKSPACE_FILE_READ_KIND) {
103625
+ throw new Error("Command kind mismatch");
103626
+ }
103627
+ void executeWorkspaceFileRead(context, message);
103628
+ }
103629
+ };
103630
+
102179
103631
  // src/engine/runtime/command/registry/index.ts
102180
103632
  function createCommandRegistry(context) {
102181
103633
  const contentWrites = createContentWriteCommands(context);
@@ -102196,6 +103648,8 @@ function createCommandRegistry(context) {
102196
103648
  sessionCloseCommand,
102197
103649
  promptDispositionCommand,
102198
103650
  workspaceListCommand,
103651
+ workspaceFileListCommand,
103652
+ workspaceFileReadCommand,
102199
103653
  sessionPrepareCommand,
102200
103654
  sessionConfigureCommand,
102201
103655
  sessionConfigReadCommand,
@@ -102244,7 +103698,7 @@ function createRuntimeCommandDispatcher(options) {
102244
103698
  }
102245
103699
 
102246
103700
  // src/engine/runtime/relay/connect.ts
102247
- import { WebSocket as WebSocket8 } from "undici";
103701
+ import { WebSocket as WebSocket9 } from "undici";
102248
103702
  var CONNECTION_TIMEOUT_MILLISECONDS = 6e4;
102249
103703
  var RelayConnectionError = class extends Error {
102250
103704
  code;
@@ -102309,7 +103763,7 @@ function connectRelay(url2, signal, transportFailed = () => void 0) {
102309
103763
  const endpoint = new URL(url2);
102310
103764
  const headers = relayAuthorization(endpoint);
102311
103765
  endpoint.searchParams.delete("token");
102312
- const socket = new WebSocket8(endpoint, {
103766
+ const socket = new WebSocket9(endpoint, {
102313
103767
  dispatcher,
102314
103768
  headers
102315
103769
  });
@@ -102554,7 +104008,7 @@ async function runRelayConnection({
102554
104008
  timer
102555
104009
  });
102556
104010
  void reportUpgradeAvailability((result) => {
102557
- if (socket.readyState === WebSocket9.OPEN) {
104011
+ if (socket.readyState === WebSocket10.OPEN) {
102558
104012
  send(socket, result);
102559
104013
  }
102560
104014
  }, signal).catch((cause) => {
@@ -102605,14 +104059,14 @@ async function runRelayConnection({
102605
104059
  };
102606
104060
  const connectionLiveness = new RelayConnectionLiveness(timer, {
102607
104061
  send: (message) => {
102608
- if (socket.readyState !== WebSocket9.OPEN) {
104062
+ if (socket.readyState !== WebSocket10.OPEN) {
102609
104063
  return false;
102610
104064
  }
102611
104065
  try {
102612
104066
  send(socket, message);
102613
104067
  return true;
102614
104068
  } catch (error62) {
102615
- if (socket.readyState !== WebSocket9.OPEN) {
104069
+ if (socket.readyState !== WebSocket10.OPEN) {
102616
104070
  return false;
102617
104071
  }
102618
104072
  throw error62;
@@ -102714,7 +104168,7 @@ async function runRelayConnection({
102714
104168
  }
102715
104169
 
102716
104170
  // src/engine/runtime/relay/session-event-publisher.ts
102717
- import { WebSocket as WebSocket10 } from "undici";
104171
+ import { WebSocket as WebSocket11 } from "undici";
102718
104172
  var MAX_BUFFERED_BYTES = 32 * 1024 * 1024;
102719
104173
  var MAX_PENDING_BYTES2 = 32 * 1024 * 1024;
102720
104174
  var MAX_EVENT_BATCH_BYTES = 1024 * 1024;
@@ -102769,7 +104223,7 @@ var RuntimeSessionEventPublisher = class {
102769
104223
  };
102770
104224
  #send = (message) => {
102771
104225
  const connection = this.#connection;
102772
- if (connection.kind !== "connected" || connection.socket.readyState !== WebSocket10.OPEN) {
104226
+ if (connection.kind !== "connected" || connection.socket.readyState !== WebSocket11.OPEN) {
102773
104227
  return;
102774
104228
  }
102775
104229
  const socket = connection.socket;
@@ -102831,7 +104285,7 @@ var RuntimeSessionEventPublisher = class {
102831
104285
  });
102832
104286
  }
102833
104287
  const connection = this.#connection;
102834
- if (connection.kind !== "connected" || connection.socket.readyState !== WebSocket10.OPEN) {
104288
+ if (connection.kind !== "connected" || connection.socket.readyState !== WebSocket11.OPEN) {
102835
104289
  return;
102836
104290
  }
102837
104291
  const socket = connection.socket;
@@ -102870,7 +104324,7 @@ var RuntimeSessionEventPublisher = class {
102870
104324
  flushEvents = (socket) => {
102871
104325
  this.cancelFlush();
102872
104326
  const connection = this.#connection;
102873
- if (connection.kind !== "connected" || connection.socket !== socket || socket.readyState !== WebSocket10.OPEN) {
104327
+ if (connection.kind !== "connected" || connection.socket !== socket || socket.readyState !== WebSocket11.OPEN) {
102874
104328
  return;
102875
104329
  }
102876
104330
  let sent = 0;
@@ -103372,4 +104826,4 @@ export {
103372
104826
  * MIT Licensed
103373
104827
  *)
103374
104828
  */
103375
- //# sourceMappingURL=chunk-GUE7ZQI6.js.map
104829
+ //# sourceMappingURL=chunk-VDTIJC4T.js.map