remotelink 0.4.7 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -59,54 +59,54 @@ var require_polyfills = __commonJS({
59
59
  }
60
60
  var chdir;
61
61
  module.exports = patch;
62
- function patch(fs8) {
62
+ function patch(fs9) {
63
63
  if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
64
- patchLchmod(fs8);
65
- }
66
- if (!fs8.lutimes) {
67
- patchLutimes(fs8);
68
- }
69
- fs8.chown = chownFix(fs8.chown);
70
- fs8.fchown = chownFix(fs8.fchown);
71
- fs8.lchown = chownFix(fs8.lchown);
72
- fs8.chmod = chmodFix(fs8.chmod);
73
- fs8.fchmod = chmodFix(fs8.fchmod);
74
- fs8.lchmod = chmodFix(fs8.lchmod);
75
- fs8.chownSync = chownFixSync(fs8.chownSync);
76
- fs8.fchownSync = chownFixSync(fs8.fchownSync);
77
- fs8.lchownSync = chownFixSync(fs8.lchownSync);
78
- fs8.chmodSync = chmodFixSync(fs8.chmodSync);
79
- fs8.fchmodSync = chmodFixSync(fs8.fchmodSync);
80
- fs8.lchmodSync = chmodFixSync(fs8.lchmodSync);
81
- fs8.stat = statFix(fs8.stat);
82
- fs8.fstat = statFix(fs8.fstat);
83
- fs8.lstat = statFix(fs8.lstat);
84
- fs8.statSync = statFixSync(fs8.statSync);
85
- fs8.fstatSync = statFixSync(fs8.fstatSync);
86
- fs8.lstatSync = statFixSync(fs8.lstatSync);
87
- if (fs8.chmod && !fs8.lchmod) {
88
- fs8.lchmod = function(path8, mode, cb) {
64
+ patchLchmod(fs9);
65
+ }
66
+ if (!fs9.lutimes) {
67
+ patchLutimes(fs9);
68
+ }
69
+ fs9.chown = chownFix(fs9.chown);
70
+ fs9.fchown = chownFix(fs9.fchown);
71
+ fs9.lchown = chownFix(fs9.lchown);
72
+ fs9.chmod = chmodFix(fs9.chmod);
73
+ fs9.fchmod = chmodFix(fs9.fchmod);
74
+ fs9.lchmod = chmodFix(fs9.lchmod);
75
+ fs9.chownSync = chownFixSync(fs9.chownSync);
76
+ fs9.fchownSync = chownFixSync(fs9.fchownSync);
77
+ fs9.lchownSync = chownFixSync(fs9.lchownSync);
78
+ fs9.chmodSync = chmodFixSync(fs9.chmodSync);
79
+ fs9.fchmodSync = chmodFixSync(fs9.fchmodSync);
80
+ fs9.lchmodSync = chmodFixSync(fs9.lchmodSync);
81
+ fs9.stat = statFix(fs9.stat);
82
+ fs9.fstat = statFix(fs9.fstat);
83
+ fs9.lstat = statFix(fs9.lstat);
84
+ fs9.statSync = statFixSync(fs9.statSync);
85
+ fs9.fstatSync = statFixSync(fs9.fstatSync);
86
+ fs9.lstatSync = statFixSync(fs9.lstatSync);
87
+ if (fs9.chmod && !fs9.lchmod) {
88
+ fs9.lchmod = function(path9, mode, cb) {
89
89
  if (cb) process.nextTick(cb);
90
90
  };
91
- fs8.lchmodSync = function() {
91
+ fs9.lchmodSync = function() {
92
92
  };
93
93
  }
94
- if (fs8.chown && !fs8.lchown) {
95
- fs8.lchown = function(path8, uid, gid, cb) {
94
+ if (fs9.chown && !fs9.lchown) {
95
+ fs9.lchown = function(path9, uid, gid, cb) {
96
96
  if (cb) process.nextTick(cb);
97
97
  };
98
- fs8.lchownSync = function() {
98
+ fs9.lchownSync = function() {
99
99
  };
100
100
  }
101
101
  if (platform === "win32") {
102
- fs8.rename = typeof fs8.rename !== "function" ? fs8.rename : (function(fs$rename) {
102
+ fs9.rename = typeof fs9.rename !== "function" ? fs9.rename : (function(fs$rename) {
103
103
  function rename(from, to, cb) {
104
104
  var start = Date.now();
105
105
  var backoff = 0;
106
106
  fs$rename(from, to, function CB(er) {
107
107
  if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 6e4) {
108
108
  setTimeout(function() {
109
- fs8.stat(to, function(stater, st) {
109
+ fs9.stat(to, function(stater, st) {
110
110
  if (stater && stater.code === "ENOENT")
111
111
  fs$rename(from, to, CB);
112
112
  else
@@ -122,9 +122,9 @@ var require_polyfills = __commonJS({
122
122
  }
123
123
  if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
124
124
  return rename;
125
- })(fs8.rename);
125
+ })(fs9.rename);
126
126
  }
127
- fs8.read = typeof fs8.read !== "function" ? fs8.read : (function(fs$read) {
127
+ fs9.read = typeof fs9.read !== "function" ? fs9.read : (function(fs$read) {
128
128
  function read(fd, buffer, offset, length, position, callback_) {
129
129
  var callback;
130
130
  if (callback_ && typeof callback_ === "function") {
@@ -132,22 +132,22 @@ var require_polyfills = __commonJS({
132
132
  callback = function(er, _, __) {
133
133
  if (er && er.code === "EAGAIN" && eagCounter < 10) {
134
134
  eagCounter++;
135
- return fs$read.call(fs8, fd, buffer, offset, length, position, callback);
135
+ return fs$read.call(fs9, fd, buffer, offset, length, position, callback);
136
136
  }
137
137
  callback_.apply(this, arguments);
138
138
  };
139
139
  }
140
- return fs$read.call(fs8, fd, buffer, offset, length, position, callback);
140
+ return fs$read.call(fs9, fd, buffer, offset, length, position, callback);
141
141
  }
142
142
  if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
143
143
  return read;
144
- })(fs8.read);
145
- fs8.readSync = typeof fs8.readSync !== "function" ? fs8.readSync : /* @__PURE__ */ (function(fs$readSync) {
144
+ })(fs9.read);
145
+ fs9.readSync = typeof fs9.readSync !== "function" ? fs9.readSync : /* @__PURE__ */ (function(fs$readSync) {
146
146
  return function(fd, buffer, offset, length, position) {
147
147
  var eagCounter = 0;
148
148
  while (true) {
149
149
  try {
150
- return fs$readSync.call(fs8, fd, buffer, offset, length, position);
150
+ return fs$readSync.call(fs9, fd, buffer, offset, length, position);
151
151
  } catch (er) {
152
152
  if (er.code === "EAGAIN" && eagCounter < 10) {
153
153
  eagCounter++;
@@ -157,11 +157,11 @@ var require_polyfills = __commonJS({
157
157
  }
158
158
  }
159
159
  };
160
- })(fs8.readSync);
161
- function patchLchmod(fs9) {
162
- fs9.lchmod = function(path8, mode, callback) {
163
- fs9.open(
164
- path8,
160
+ })(fs9.readSync);
161
+ function patchLchmod(fs10) {
162
+ fs10.lchmod = function(path9, mode, callback) {
163
+ fs10.open(
164
+ path9,
165
165
  constants.O_WRONLY | constants.O_SYMLINK,
166
166
  mode,
167
167
  function(err, fd) {
@@ -169,80 +169,80 @@ var require_polyfills = __commonJS({
169
169
  if (callback) callback(err);
170
170
  return;
171
171
  }
172
- fs9.fchmod(fd, mode, function(err2) {
173
- fs9.close(fd, function(err22) {
172
+ fs10.fchmod(fd, mode, function(err2) {
173
+ fs10.close(fd, function(err22) {
174
174
  if (callback) callback(err2 || err22);
175
175
  });
176
176
  });
177
177
  }
178
178
  );
179
179
  };
180
- fs9.lchmodSync = function(path8, mode) {
181
- var fd = fs9.openSync(path8, constants.O_WRONLY | constants.O_SYMLINK, mode);
180
+ fs10.lchmodSync = function(path9, mode) {
181
+ var fd = fs10.openSync(path9, constants.O_WRONLY | constants.O_SYMLINK, mode);
182
182
  var threw = true;
183
183
  var ret;
184
184
  try {
185
- ret = fs9.fchmodSync(fd, mode);
185
+ ret = fs10.fchmodSync(fd, mode);
186
186
  threw = false;
187
187
  } finally {
188
188
  if (threw) {
189
189
  try {
190
- fs9.closeSync(fd);
190
+ fs10.closeSync(fd);
191
191
  } catch (er) {
192
192
  }
193
193
  } else {
194
- fs9.closeSync(fd);
194
+ fs10.closeSync(fd);
195
195
  }
196
196
  }
197
197
  return ret;
198
198
  };
199
199
  }
200
- function patchLutimes(fs9) {
201
- if (constants.hasOwnProperty("O_SYMLINK") && fs9.futimes) {
202
- fs9.lutimes = function(path8, at, mt, cb) {
203
- fs9.open(path8, constants.O_SYMLINK, function(er, fd) {
200
+ function patchLutimes(fs10) {
201
+ if (constants.hasOwnProperty("O_SYMLINK") && fs10.futimes) {
202
+ fs10.lutimes = function(path9, at, mt, cb) {
203
+ fs10.open(path9, constants.O_SYMLINK, function(er, fd) {
204
204
  if (er) {
205
205
  if (cb) cb(er);
206
206
  return;
207
207
  }
208
- fs9.futimes(fd, at, mt, function(er2) {
209
- fs9.close(fd, function(er22) {
208
+ fs10.futimes(fd, at, mt, function(er2) {
209
+ fs10.close(fd, function(er22) {
210
210
  if (cb) cb(er2 || er22);
211
211
  });
212
212
  });
213
213
  });
214
214
  };
215
- fs9.lutimesSync = function(path8, at, mt) {
216
- var fd = fs9.openSync(path8, constants.O_SYMLINK);
215
+ fs10.lutimesSync = function(path9, at, mt) {
216
+ var fd = fs10.openSync(path9, constants.O_SYMLINK);
217
217
  var ret;
218
218
  var threw = true;
219
219
  try {
220
- ret = fs9.futimesSync(fd, at, mt);
220
+ ret = fs10.futimesSync(fd, at, mt);
221
221
  threw = false;
222
222
  } finally {
223
223
  if (threw) {
224
224
  try {
225
- fs9.closeSync(fd);
225
+ fs10.closeSync(fd);
226
226
  } catch (er) {
227
227
  }
228
228
  } else {
229
- fs9.closeSync(fd);
229
+ fs10.closeSync(fd);
230
230
  }
231
231
  }
232
232
  return ret;
233
233
  };
234
- } else if (fs9.futimes) {
235
- fs9.lutimes = function(_a, _b, _c, cb) {
234
+ } else if (fs10.futimes) {
235
+ fs10.lutimes = function(_a, _b, _c, cb) {
236
236
  if (cb) process.nextTick(cb);
237
237
  };
238
- fs9.lutimesSync = function() {
238
+ fs10.lutimesSync = function() {
239
239
  };
240
240
  }
241
241
  }
242
242
  function chmodFix(orig) {
243
243
  if (!orig) return orig;
244
244
  return function(target, mode, cb) {
245
- return orig.call(fs8, target, mode, function(er) {
245
+ return orig.call(fs9, target, mode, function(er) {
246
246
  if (chownErOk(er)) er = null;
247
247
  if (cb) cb.apply(this, arguments);
248
248
  });
@@ -252,7 +252,7 @@ var require_polyfills = __commonJS({
252
252
  if (!orig) return orig;
253
253
  return function(target, mode) {
254
254
  try {
255
- return orig.call(fs8, target, mode);
255
+ return orig.call(fs9, target, mode);
256
256
  } catch (er) {
257
257
  if (!chownErOk(er)) throw er;
258
258
  }
@@ -261,7 +261,7 @@ var require_polyfills = __commonJS({
261
261
  function chownFix(orig) {
262
262
  if (!orig) return orig;
263
263
  return function(target, uid, gid, cb) {
264
- return orig.call(fs8, target, uid, gid, function(er) {
264
+ return orig.call(fs9, target, uid, gid, function(er) {
265
265
  if (chownErOk(er)) er = null;
266
266
  if (cb) cb.apply(this, arguments);
267
267
  });
@@ -271,7 +271,7 @@ var require_polyfills = __commonJS({
271
271
  if (!orig) return orig;
272
272
  return function(target, uid, gid) {
273
273
  try {
274
- return orig.call(fs8, target, uid, gid);
274
+ return orig.call(fs9, target, uid, gid);
275
275
  } catch (er) {
276
276
  if (!chownErOk(er)) throw er;
277
277
  }
@@ -291,13 +291,13 @@ var require_polyfills = __commonJS({
291
291
  }
292
292
  if (cb) cb.apply(this, arguments);
293
293
  }
294
- return options ? orig.call(fs8, target, options, callback) : orig.call(fs8, target, callback);
294
+ return options ? orig.call(fs9, target, options, callback) : orig.call(fs9, target, callback);
295
295
  };
296
296
  }
297
297
  function statFixSync(orig) {
298
298
  if (!orig) return orig;
299
299
  return function(target, options) {
300
- var stats = options ? orig.call(fs8, target, options) : orig.call(fs8, target);
300
+ var stats = options ? orig.call(fs9, target, options) : orig.call(fs9, target);
301
301
  if (stats) {
302
302
  if (stats.uid < 0) stats.uid += 4294967296;
303
303
  if (stats.gid < 0) stats.gid += 4294967296;
@@ -327,16 +327,16 @@ var require_legacy_streams = __commonJS({
327
327
  "use strict";
328
328
  var Stream = __require("stream").Stream;
329
329
  module.exports = legacy;
330
- function legacy(fs8) {
330
+ function legacy(fs9) {
331
331
  return {
332
332
  ReadStream,
333
333
  WriteStream
334
334
  };
335
- function ReadStream(path8, options) {
336
- if (!(this instanceof ReadStream)) return new ReadStream(path8, options);
335
+ function ReadStream(path9, options) {
336
+ if (!(this instanceof ReadStream)) return new ReadStream(path9, options);
337
337
  Stream.call(this);
338
338
  var self = this;
339
- this.path = path8;
339
+ this.path = path9;
340
340
  this.fd = null;
341
341
  this.readable = true;
342
342
  this.paused = false;
@@ -370,7 +370,7 @@ var require_legacy_streams = __commonJS({
370
370
  });
371
371
  return;
372
372
  }
373
- fs8.open(this.path, this.flags, this.mode, function(err, fd) {
373
+ fs9.open(this.path, this.flags, this.mode, function(err, fd) {
374
374
  if (err) {
375
375
  self.emit("error", err);
376
376
  self.readable = false;
@@ -381,10 +381,10 @@ var require_legacy_streams = __commonJS({
381
381
  self._read();
382
382
  });
383
383
  }
384
- function WriteStream(path8, options) {
385
- if (!(this instanceof WriteStream)) return new WriteStream(path8, options);
384
+ function WriteStream(path9, options) {
385
+ if (!(this instanceof WriteStream)) return new WriteStream(path9, options);
386
386
  Stream.call(this);
387
- this.path = path8;
387
+ this.path = path9;
388
388
  this.fd = null;
389
389
  this.writable = true;
390
390
  this.flags = "w";
@@ -409,7 +409,7 @@ var require_legacy_streams = __commonJS({
409
409
  this.busy = false;
410
410
  this._queue = [];
411
411
  if (this.fd === null) {
412
- this._open = fs8.open;
412
+ this._open = fs9.open;
413
413
  this._queue.push([this._open, this.path, this.flags, this.mode, void 0]);
414
414
  this.flush();
415
415
  }
@@ -445,7 +445,7 @@ var require_clone = __commonJS({
445
445
  var require_graceful_fs = __commonJS({
446
446
  "../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/graceful-fs.js"(exports, module) {
447
447
  "use strict";
448
- var fs8 = __require("fs");
448
+ var fs9 = __require("fs");
449
449
  var polyfills = require_polyfills();
450
450
  var legacy = require_legacy_streams();
451
451
  var clone = require_clone();
@@ -477,12 +477,12 @@ var require_graceful_fs = __commonJS({
477
477
  m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
478
478
  console.error(m);
479
479
  };
480
- if (!fs8[gracefulQueue]) {
480
+ if (!fs9[gracefulQueue]) {
481
481
  queue = global[gracefulQueue] || [];
482
- publishQueue(fs8, queue);
483
- fs8.close = (function(fs$close) {
482
+ publishQueue(fs9, queue);
483
+ fs9.close = (function(fs$close) {
484
484
  function close(fd, cb) {
485
- return fs$close.call(fs8, fd, function(err) {
485
+ return fs$close.call(fs9, fd, function(err) {
486
486
  if (!err) {
487
487
  resetQueue();
488
488
  }
@@ -494,48 +494,48 @@ var require_graceful_fs = __commonJS({
494
494
  value: fs$close
495
495
  });
496
496
  return close;
497
- })(fs8.close);
498
- fs8.closeSync = (function(fs$closeSync) {
497
+ })(fs9.close);
498
+ fs9.closeSync = (function(fs$closeSync) {
499
499
  function closeSync2(fd) {
500
- fs$closeSync.apply(fs8, arguments);
500
+ fs$closeSync.apply(fs9, arguments);
501
501
  resetQueue();
502
502
  }
503
503
  Object.defineProperty(closeSync2, previousSymbol, {
504
504
  value: fs$closeSync
505
505
  });
506
506
  return closeSync2;
507
- })(fs8.closeSync);
507
+ })(fs9.closeSync);
508
508
  if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
509
509
  process.on("exit", function() {
510
- debug(fs8[gracefulQueue]);
511
- __require("assert").equal(fs8[gracefulQueue].length, 0);
510
+ debug(fs9[gracefulQueue]);
511
+ __require("assert").equal(fs9[gracefulQueue].length, 0);
512
512
  });
513
513
  }
514
514
  }
515
515
  var queue;
516
516
  if (!global[gracefulQueue]) {
517
- publishQueue(global, fs8[gracefulQueue]);
518
- }
519
- module.exports = patch(clone(fs8));
520
- if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs8.__patched) {
521
- module.exports = patch(fs8);
522
- fs8.__patched = true;
523
- }
524
- function patch(fs9) {
525
- polyfills(fs9);
526
- fs9.gracefulify = patch;
527
- fs9.createReadStream = createReadStream2;
528
- fs9.createWriteStream = createWriteStream;
529
- var fs$readFile = fs9.readFile;
530
- fs9.readFile = readFile;
531
- function readFile(path8, options, cb) {
517
+ publishQueue(global, fs9[gracefulQueue]);
518
+ }
519
+ module.exports = patch(clone(fs9));
520
+ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs9.__patched) {
521
+ module.exports = patch(fs9);
522
+ fs9.__patched = true;
523
+ }
524
+ function patch(fs10) {
525
+ polyfills(fs10);
526
+ fs10.gracefulify = patch;
527
+ fs10.createReadStream = createReadStream2;
528
+ fs10.createWriteStream = createWriteStream;
529
+ var fs$readFile = fs10.readFile;
530
+ fs10.readFile = readFile;
531
+ function readFile(path9, options, cb) {
532
532
  if (typeof options === "function")
533
533
  cb = options, options = null;
534
- return go$readFile(path8, options, cb);
535
- function go$readFile(path9, options2, cb2, startTime) {
536
- return fs$readFile(path9, options2, function(err) {
534
+ return go$readFile(path9, options, cb);
535
+ function go$readFile(path10, options2, cb2, startTime) {
536
+ return fs$readFile(path10, options2, function(err) {
537
537
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
538
- enqueue([go$readFile, [path9, options2, cb2], err, startTime || Date.now(), Date.now()]);
538
+ enqueue([go$readFile, [path10, options2, cb2], err, startTime || Date.now(), Date.now()]);
539
539
  else {
540
540
  if (typeof cb2 === "function")
541
541
  cb2.apply(this, arguments);
@@ -543,16 +543,16 @@ var require_graceful_fs = __commonJS({
543
543
  });
544
544
  }
545
545
  }
546
- var fs$writeFile = fs9.writeFile;
547
- fs9.writeFile = writeFile;
548
- function writeFile(path8, data, options, cb) {
546
+ var fs$writeFile = fs10.writeFile;
547
+ fs10.writeFile = writeFile;
548
+ function writeFile(path9, data, options, cb) {
549
549
  if (typeof options === "function")
550
550
  cb = options, options = null;
551
- return go$writeFile(path8, data, options, cb);
552
- function go$writeFile(path9, data2, options2, cb2, startTime) {
553
- return fs$writeFile(path9, data2, options2, function(err) {
551
+ return go$writeFile(path9, data, options, cb);
552
+ function go$writeFile(path10, data2, options2, cb2, startTime) {
553
+ return fs$writeFile(path10, data2, options2, function(err) {
554
554
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
555
- enqueue([go$writeFile, [path9, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
555
+ enqueue([go$writeFile, [path10, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
556
556
  else {
557
557
  if (typeof cb2 === "function")
558
558
  cb2.apply(this, arguments);
@@ -560,17 +560,17 @@ var require_graceful_fs = __commonJS({
560
560
  });
561
561
  }
562
562
  }
563
- var fs$appendFile = fs9.appendFile;
563
+ var fs$appendFile = fs10.appendFile;
564
564
  if (fs$appendFile)
565
- fs9.appendFile = appendFile;
566
- function appendFile(path8, data, options, cb) {
565
+ fs10.appendFile = appendFile;
566
+ function appendFile(path9, data, options, cb) {
567
567
  if (typeof options === "function")
568
568
  cb = options, options = null;
569
- return go$appendFile(path8, data, options, cb);
570
- function go$appendFile(path9, data2, options2, cb2, startTime) {
571
- return fs$appendFile(path9, data2, options2, function(err) {
569
+ return go$appendFile(path9, data, options, cb);
570
+ function go$appendFile(path10, data2, options2, cb2, startTime) {
571
+ return fs$appendFile(path10, data2, options2, function(err) {
572
572
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
573
- enqueue([go$appendFile, [path9, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
573
+ enqueue([go$appendFile, [path10, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
574
574
  else {
575
575
  if (typeof cb2 === "function")
576
576
  cb2.apply(this, arguments);
@@ -578,9 +578,9 @@ var require_graceful_fs = __commonJS({
578
578
  });
579
579
  }
580
580
  }
581
- var fs$copyFile = fs9.copyFile;
581
+ var fs$copyFile = fs10.copyFile;
582
582
  if (fs$copyFile)
583
- fs9.copyFile = copyFile;
583
+ fs10.copyFile = copyFile;
584
584
  function copyFile(src, dest, flags, cb) {
585
585
  if (typeof flags === "function") {
586
586
  cb = flags;
@@ -598,34 +598,34 @@ var require_graceful_fs = __commonJS({
598
598
  });
599
599
  }
600
600
  }
601
- var fs$readdir = fs9.readdir;
602
- fs9.readdir = readdir;
601
+ var fs$readdir = fs10.readdir;
602
+ fs10.readdir = readdir;
603
603
  var noReaddirOptionVersions = /^v[0-5]\./;
604
- function readdir(path8, options, cb) {
604
+ function readdir(path9, options, cb) {
605
605
  if (typeof options === "function")
606
606
  cb = options, options = null;
607
- var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path9, options2, cb2, startTime) {
608
- return fs$readdir(path9, fs$readdirCallback(
609
- path9,
607
+ var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path10, options2, cb2, startTime) {
608
+ return fs$readdir(path10, fs$readdirCallback(
609
+ path10,
610
610
  options2,
611
611
  cb2,
612
612
  startTime
613
613
  ));
614
- } : function go$readdir2(path9, options2, cb2, startTime) {
615
- return fs$readdir(path9, options2, fs$readdirCallback(
616
- path9,
614
+ } : function go$readdir2(path10, options2, cb2, startTime) {
615
+ return fs$readdir(path10, options2, fs$readdirCallback(
616
+ path10,
617
617
  options2,
618
618
  cb2,
619
619
  startTime
620
620
  ));
621
621
  };
622
- return go$readdir(path8, options, cb);
623
- function fs$readdirCallback(path9, options2, cb2, startTime) {
622
+ return go$readdir(path9, options, cb);
623
+ function fs$readdirCallback(path10, options2, cb2, startTime) {
624
624
  return function(err, files) {
625
625
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
626
626
  enqueue([
627
627
  go$readdir,
628
- [path9, options2, cb2],
628
+ [path10, options2, cb2],
629
629
  err,
630
630
  startTime || Date.now(),
631
631
  Date.now()
@@ -640,21 +640,21 @@ var require_graceful_fs = __commonJS({
640
640
  }
641
641
  }
642
642
  if (process.version.substr(0, 4) === "v0.8") {
643
- var legStreams = legacy(fs9);
643
+ var legStreams = legacy(fs10);
644
644
  ReadStream = legStreams.ReadStream;
645
645
  WriteStream = legStreams.WriteStream;
646
646
  }
647
- var fs$ReadStream = fs9.ReadStream;
647
+ var fs$ReadStream = fs10.ReadStream;
648
648
  if (fs$ReadStream) {
649
649
  ReadStream.prototype = Object.create(fs$ReadStream.prototype);
650
650
  ReadStream.prototype.open = ReadStream$open;
651
651
  }
652
- var fs$WriteStream = fs9.WriteStream;
652
+ var fs$WriteStream = fs10.WriteStream;
653
653
  if (fs$WriteStream) {
654
654
  WriteStream.prototype = Object.create(fs$WriteStream.prototype);
655
655
  WriteStream.prototype.open = WriteStream$open;
656
656
  }
657
- Object.defineProperty(fs9, "ReadStream", {
657
+ Object.defineProperty(fs10, "ReadStream", {
658
658
  get: function() {
659
659
  return ReadStream;
660
660
  },
@@ -664,7 +664,7 @@ var require_graceful_fs = __commonJS({
664
664
  enumerable: true,
665
665
  configurable: true
666
666
  });
667
- Object.defineProperty(fs9, "WriteStream", {
667
+ Object.defineProperty(fs10, "WriteStream", {
668
668
  get: function() {
669
669
  return WriteStream;
670
670
  },
@@ -675,7 +675,7 @@ var require_graceful_fs = __commonJS({
675
675
  configurable: true
676
676
  });
677
677
  var FileReadStream = ReadStream;
678
- Object.defineProperty(fs9, "FileReadStream", {
678
+ Object.defineProperty(fs10, "FileReadStream", {
679
679
  get: function() {
680
680
  return FileReadStream;
681
681
  },
@@ -686,7 +686,7 @@ var require_graceful_fs = __commonJS({
686
686
  configurable: true
687
687
  });
688
688
  var FileWriteStream = WriteStream;
689
- Object.defineProperty(fs9, "FileWriteStream", {
689
+ Object.defineProperty(fs10, "FileWriteStream", {
690
690
  get: function() {
691
691
  return FileWriteStream;
692
692
  },
@@ -696,7 +696,7 @@ var require_graceful_fs = __commonJS({
696
696
  enumerable: true,
697
697
  configurable: true
698
698
  });
699
- function ReadStream(path8, options) {
699
+ function ReadStream(path9, options) {
700
700
  if (this instanceof ReadStream)
701
701
  return fs$ReadStream.apply(this, arguments), this;
702
702
  else
@@ -716,7 +716,7 @@ var require_graceful_fs = __commonJS({
716
716
  }
717
717
  });
718
718
  }
719
- function WriteStream(path8, options) {
719
+ function WriteStream(path9, options) {
720
720
  if (this instanceof WriteStream)
721
721
  return fs$WriteStream.apply(this, arguments), this;
722
722
  else
@@ -734,22 +734,22 @@ var require_graceful_fs = __commonJS({
734
734
  }
735
735
  });
736
736
  }
737
- function createReadStream2(path8, options) {
738
- return new fs9.ReadStream(path8, options);
737
+ function createReadStream2(path9, options) {
738
+ return new fs10.ReadStream(path9, options);
739
739
  }
740
- function createWriteStream(path8, options) {
741
- return new fs9.WriteStream(path8, options);
740
+ function createWriteStream(path9, options) {
741
+ return new fs10.WriteStream(path9, options);
742
742
  }
743
- var fs$open = fs9.open;
744
- fs9.open = open;
745
- function open(path8, flags, mode, cb) {
743
+ var fs$open = fs10.open;
744
+ fs10.open = open;
745
+ function open(path9, flags, mode, cb) {
746
746
  if (typeof mode === "function")
747
747
  cb = mode, mode = null;
748
- return go$open(path8, flags, mode, cb);
749
- function go$open(path9, flags2, mode2, cb2, startTime) {
750
- return fs$open(path9, flags2, mode2, function(err, fd) {
748
+ return go$open(path9, flags, mode, cb);
749
+ function go$open(path10, flags2, mode2, cb2, startTime) {
750
+ return fs$open(path10, flags2, mode2, function(err, fd) {
751
751
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
752
- enqueue([go$open, [path9, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
752
+ enqueue([go$open, [path10, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
753
753
  else {
754
754
  if (typeof cb2 === "function")
755
755
  cb2.apply(this, arguments);
@@ -757,20 +757,20 @@ var require_graceful_fs = __commonJS({
757
757
  });
758
758
  }
759
759
  }
760
- return fs9;
760
+ return fs10;
761
761
  }
762
762
  function enqueue(elem) {
763
763
  debug("ENQUEUE", elem[0].name, elem[1]);
764
- fs8[gracefulQueue].push(elem);
764
+ fs9[gracefulQueue].push(elem);
765
765
  retry();
766
766
  }
767
767
  var retryTimer;
768
768
  function resetQueue() {
769
769
  var now = Date.now();
770
- for (var i = 0; i < fs8[gracefulQueue].length; ++i) {
771
- if (fs8[gracefulQueue][i].length > 2) {
772
- fs8[gracefulQueue][i][3] = now;
773
- fs8[gracefulQueue][i][4] = now;
770
+ for (var i = 0; i < fs9[gracefulQueue].length; ++i) {
771
+ if (fs9[gracefulQueue][i].length > 2) {
772
+ fs9[gracefulQueue][i][3] = now;
773
+ fs9[gracefulQueue][i][4] = now;
774
774
  }
775
775
  }
776
776
  retry();
@@ -778,9 +778,9 @@ var require_graceful_fs = __commonJS({
778
778
  function retry() {
779
779
  clearTimeout(retryTimer);
780
780
  retryTimer = void 0;
781
- if (fs8[gracefulQueue].length === 0)
781
+ if (fs9[gracefulQueue].length === 0)
782
782
  return;
783
- var elem = fs8[gracefulQueue].shift();
783
+ var elem = fs9[gracefulQueue].shift();
784
784
  var fn = elem[0];
785
785
  var args = elem[1];
786
786
  var err = elem[2];
@@ -802,7 +802,7 @@ var require_graceful_fs = __commonJS({
802
802
  debug("RETRY", fn.name, args);
803
803
  fn.apply(null, args.concat([startTime]));
804
804
  } else {
805
- fs8[gracefulQueue].push(elem);
805
+ fs9[gracefulQueue].push(elem);
806
806
  }
807
807
  }
808
808
  if (retryTimer === void 0) {
@@ -1242,10 +1242,10 @@ var require_mtime_precision = __commonJS({
1242
1242
  "../../node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/mtime-precision.js"(exports, module) {
1243
1243
  "use strict";
1244
1244
  var cacheSymbol = /* @__PURE__ */ Symbol();
1245
- function probe(file, fs8, callback) {
1246
- const cachedPrecision = fs8[cacheSymbol];
1245
+ function probe(file, fs9, callback) {
1246
+ const cachedPrecision = fs9[cacheSymbol];
1247
1247
  if (cachedPrecision) {
1248
- return fs8.stat(file, (err, stat) => {
1248
+ return fs9.stat(file, (err, stat) => {
1249
1249
  if (err) {
1250
1250
  return callback(err);
1251
1251
  }
@@ -1253,16 +1253,16 @@ var require_mtime_precision = __commonJS({
1253
1253
  });
1254
1254
  }
1255
1255
  const mtime = new Date(Math.ceil(Date.now() / 1e3) * 1e3 + 5);
1256
- fs8.utimes(file, mtime, mtime, (err) => {
1256
+ fs9.utimes(file, mtime, mtime, (err) => {
1257
1257
  if (err) {
1258
1258
  return callback(err);
1259
1259
  }
1260
- fs8.stat(file, (err2, stat) => {
1260
+ fs9.stat(file, (err2, stat) => {
1261
1261
  if (err2) {
1262
1262
  return callback(err2);
1263
1263
  }
1264
1264
  const precision = stat.mtime.getTime() % 1e3 === 0 ? "s" : "ms";
1265
- Object.defineProperty(fs8, cacheSymbol, { value: precision });
1265
+ Object.defineProperty(fs9, cacheSymbol, { value: precision });
1266
1266
  callback(null, stat.mtime, precision);
1267
1267
  });
1268
1268
  });
@@ -1283,8 +1283,8 @@ var require_mtime_precision = __commonJS({
1283
1283
  var require_lockfile = __commonJS({
1284
1284
  "../../node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/lockfile.js"(exports, module) {
1285
1285
  "use strict";
1286
- var path8 = __require("path");
1287
- var fs8 = require_graceful_fs();
1286
+ var path9 = __require("path");
1287
+ var fs9 = require_graceful_fs();
1288
1288
  var retry = require_retry2();
1289
1289
  var onExit = require_signal_exit();
1290
1290
  var mtimePrecision = require_mtime_precision();
@@ -1294,7 +1294,7 @@ var require_lockfile = __commonJS({
1294
1294
  }
1295
1295
  function resolveCanonicalPath(file, options, callback) {
1296
1296
  if (!options.realpath) {
1297
- return callback(null, path8.resolve(file));
1297
+ return callback(null, path9.resolve(file));
1298
1298
  }
1299
1299
  options.fs.realpath(file, callback);
1300
1300
  }
@@ -1415,7 +1415,7 @@ var require_lockfile = __commonJS({
1415
1415
  update: null,
1416
1416
  realpath: true,
1417
1417
  retries: 0,
1418
- fs: fs8,
1418
+ fs: fs9,
1419
1419
  onCompromised: (err) => {
1420
1420
  throw err;
1421
1421
  },
@@ -1459,7 +1459,7 @@ var require_lockfile = __commonJS({
1459
1459
  }
1460
1460
  function unlock(file, options, callback) {
1461
1461
  options = {
1462
- fs: fs8,
1462
+ fs: fs9,
1463
1463
  realpath: true,
1464
1464
  ...options
1465
1465
  };
@@ -1481,7 +1481,7 @@ var require_lockfile = __commonJS({
1481
1481
  options = {
1482
1482
  stale: 1e4,
1483
1483
  realpath: true,
1484
- fs: fs8,
1484
+ fs: fs9,
1485
1485
  ...options
1486
1486
  };
1487
1487
  options.stale = Math.max(options.stale || 0, 2e3);
@@ -1520,16 +1520,16 @@ var require_lockfile = __commonJS({
1520
1520
  var require_adapter = __commonJS({
1521
1521
  "../../node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/adapter.js"(exports, module) {
1522
1522
  "use strict";
1523
- var fs8 = require_graceful_fs();
1524
- function createSyncFs(fs9) {
1523
+ var fs9 = require_graceful_fs();
1524
+ function createSyncFs(fs10) {
1525
1525
  const methods = ["mkdir", "realpath", "stat", "rmdir", "utimes"];
1526
- const newFs = { ...fs9 };
1526
+ const newFs = { ...fs10 };
1527
1527
  methods.forEach((method) => {
1528
1528
  newFs[method] = (...args) => {
1529
1529
  const callback = args.pop();
1530
1530
  let ret;
1531
1531
  try {
1532
- ret = fs9[`${method}Sync`](...args);
1532
+ ret = fs10[`${method}Sync`](...args);
1533
1533
  } catch (err) {
1534
1534
  return callback(err);
1535
1535
  }
@@ -1567,7 +1567,7 @@ var require_adapter = __commonJS({
1567
1567
  }
1568
1568
  function toSyncOptions(options) {
1569
1569
  options = { ...options };
1570
- options.fs = createSyncFs(options.fs || fs8);
1570
+ options.fs = createSyncFs(options.fs || fs9);
1571
1571
  if (typeof options.retries === "number" && options.retries > 0 || options.retries && typeof options.retries.retries === "number" && options.retries.retries > 0) {
1572
1572
  throw Object.assign(new Error("Cannot use retries with the sync api"), { code: "ESYNC" });
1573
1573
  }
@@ -3856,7 +3856,7 @@ var require_websocket = __commonJS({
3856
3856
  var http = __require("http");
3857
3857
  var net = __require("net");
3858
3858
  var tls = __require("tls");
3859
- var { randomBytes, createHash } = __require("crypto");
3859
+ var { randomBytes, createHash: createHash2 } = __require("crypto");
3860
3860
  var { Duplex, Readable } = __require("stream");
3861
3861
  var { URL: URL2 } = __require("url");
3862
3862
  var PerMessageDeflate2 = require_permessage_deflate();
@@ -4524,8 +4524,8 @@ var require_websocket = __commonJS({
4524
4524
  abortHandshake(websocket, socket, "Invalid Upgrade header");
4525
4525
  return;
4526
4526
  }
4527
- const digest = createHash("sha1").update(key + GUID).digest("base64");
4528
- if (res.headers["sec-websocket-accept"] !== digest) {
4527
+ const digest2 = createHash2("sha1").update(key + GUID).digest("base64");
4528
+ if (res.headers["sec-websocket-accept"] !== digest2) {
4529
4529
  abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
4530
4530
  return;
4531
4531
  }
@@ -4893,7 +4893,7 @@ var require_websocket_server = __commonJS({
4893
4893
  var EventEmitter = __require("events");
4894
4894
  var http = __require("http");
4895
4895
  var { Duplex } = __require("stream");
4896
- var { createHash } = __require("crypto");
4896
+ var { createHash: createHash2 } = __require("crypto");
4897
4897
  var extension2 = require_extension();
4898
4898
  var PerMessageDeflate2 = require_permessage_deflate();
4899
4899
  var subprotocol2 = require_subprotocol();
@@ -5200,12 +5200,12 @@ var require_websocket_server = __commonJS({
5200
5200
  );
5201
5201
  }
5202
5202
  if (this._state > RUNNING) return abortHandshake(socket, 503);
5203
- const digest = createHash("sha1").update(key + GUID).digest("base64");
5203
+ const digest2 = createHash2("sha1").update(key + GUID).digest("base64");
5204
5204
  const headers = [
5205
5205
  "HTTP/1.1 101 Switching Protocols",
5206
5206
  "Upgrade: websocket",
5207
5207
  "Connection: Upgrade",
5208
- `Sec-WebSocket-Accept: ${digest}`
5208
+ `Sec-WebSocket-Accept: ${digest2}`
5209
5209
  ];
5210
5210
  const ws = new this.options.WebSocket(null, void 0, this.options);
5211
5211
  if (protocols.size) {
@@ -5287,8 +5287,252 @@ var require_websocket_server = __commonJS({
5287
5287
  }
5288
5288
  });
5289
5289
 
5290
+ // src/go-launcher.ts
5291
+ import os from "os";
5292
+ import path from "path";
5293
+ import fs from "fs/promises";
5294
+ import { createHash, randomUUID } from "crypto";
5295
+ import { spawn, spawnSync } from "child_process";
5296
+ import { fileURLToPath } from "url";
5297
+
5298
+ // package.json
5299
+ var package_default = {
5300
+ name: "remotelink",
5301
+ version: "0.5.0",
5302
+ description: "Controlled remote computer access for AI across computers you own.",
5303
+ type: "module",
5304
+ bin: {
5305
+ remotelink: "dist/index.js",
5306
+ "remote-link": "dist/index.js",
5307
+ "remote-arc": "dist/index.js"
5308
+ },
5309
+ files: [
5310
+ "dist",
5311
+ "README.md",
5312
+ "LICENSE"
5313
+ ],
5314
+ engines: {
5315
+ node: ">=20"
5316
+ },
5317
+ scripts: {
5318
+ build: "tsup",
5319
+ typecheck: "tsc --noEmit",
5320
+ prepublishOnly: "node ../../scripts/sync-release-docs.mjs --write && pnpm build && node ../../scripts/build-device.mjs --release"
5321
+ },
5322
+ dependencies: {
5323
+ "proper-lockfile": "^4.1.2",
5324
+ ws: "^8.18.3"
5325
+ },
5326
+ devDependencies: {
5327
+ "@remotearc/execution-core": "workspace:*",
5328
+ "@types/node": "^24.13.6",
5329
+ "@types/proper-lockfile": "^4.1.4",
5330
+ "@types/ws": "^8.18.1",
5331
+ tsup: "^8.5.0",
5332
+ typescript: "^6.0.3"
5333
+ },
5334
+ license: "UNLICENSED",
5335
+ homepage: "https://remotearc.app",
5336
+ repository: {
5337
+ type: "git",
5338
+ url: "git+https://github.com/yaohuangguan/remote-arc.git",
5339
+ directory: "packages/cli"
5340
+ },
5341
+ bugs: {
5342
+ url: "https://github.com/yaohuangguan/remote-arc/issues"
5343
+ },
5344
+ keywords: [
5345
+ "mcp",
5346
+ "chatgpt",
5347
+ "claude",
5348
+ "codex",
5349
+ "remote-computer",
5350
+ "developer-tools"
5351
+ ]
5352
+ };
5353
+
5354
+ // src/go-launcher.ts
5355
+ var GO_VERSION = package_default.version;
5356
+ var platforms = {
5357
+ win32: "windows",
5358
+ darwin: "darwin",
5359
+ linux: "linux"
5360
+ };
5361
+ var architectures = { x64: "amd64", arm64: "arm64" };
5362
+ function goAsset(platform = process.platform, arch = process.arch) {
5363
+ const target = platforms[platform], cpu = architectures[arch];
5364
+ if (!target || !cpu)
5365
+ throw new Error(
5366
+ `Go agent binaries are unavailable for ${platform}/${arch}.`
5367
+ );
5368
+ return `remotelink-go-v${GO_VERSION}-${target}-${cpu}${platform === "win32" ? ".exe" : ""}`;
5369
+ }
5370
+ function digest(b) {
5371
+ return createHash("sha256").update(b).digest("hex");
5372
+ }
5373
+ async function exists(file) {
5374
+ try {
5375
+ return (await fs.stat(file)).isFile();
5376
+ } catch {
5377
+ return false;
5378
+ }
5379
+ }
5380
+ function verifyVersion(binary) {
5381
+ const child = spawnSync(binary, ["--version"], {
5382
+ windowsHide: true,
5383
+ encoding: "utf8",
5384
+ timeout: 1e4,
5385
+ maxBuffer: 4096
5386
+ });
5387
+ if (child.error || child.status !== 0 || child.stdout.trim() !== GO_VERSION)
5388
+ throw new Error(
5389
+ `The Go agent must match remotelink ${GO_VERSION}. Build the matching binary or reinstall this release.`
5390
+ );
5391
+ }
5392
+ async function resolveGoBinary() {
5393
+ const explicit = process.env.REMOTEARC_GO_BINARY;
5394
+ if (explicit) {
5395
+ if (!path.isAbsolute(explicit) || !await exists(explicit))
5396
+ throw new Error(
5397
+ "REMOTEARC_GO_BINARY must be an absolute path to a Go agent binary."
5398
+ );
5399
+ verifyVersion(explicit);
5400
+ return explicit;
5401
+ }
5402
+ const asset = goAsset();
5403
+ const manifestPath = fileURLToPath(
5404
+ new URL("./go-binaries.json", import.meta.url)
5405
+ );
5406
+ let manifest;
5407
+ try {
5408
+ manifest = JSON.parse(await fs.readFile(manifestPath, "utf8"));
5409
+ } catch {
5410
+ throw new Error(
5411
+ "This npm release has no Go binary manifest. Use REMOTEARC_GO_BINARY with a matching local build, or install a native Go release."
5412
+ );
5413
+ }
5414
+ const checksum = manifest.version === GO_VERSION ? manifest.checksums[asset] : void 0;
5415
+ if (!checksum || !/^[a-f0-9]{64}$/.test(checksum))
5416
+ throw new Error(
5417
+ "No verified Go binary is listed for this platform in the installed release."
5418
+ );
5419
+ const home = process.env.REMOTEARC_HOME || os.homedir();
5420
+ const dir = path.join(home, ".remotearc", "agent", "downloads", GO_VERSION);
5421
+ const binary = path.join(dir, asset);
5422
+ const bundled = fileURLToPath(new URL(`./bin/${asset}`, import.meta.url));
5423
+ for (const candidate of [bundled, binary]) {
5424
+ if (await exists(candidate) && digest(await fs.readFile(candidate)) === checksum) {
5425
+ verifyVersion(candidate);
5426
+ return candidate;
5427
+ }
5428
+ }
5429
+ const releaseURL = `https://github.com/yaohuangguan/remote-arc/releases/download/go-agent-v${GO_VERSION}/${asset}`;
5430
+ const response = await fetch(releaseURL, {
5431
+ signal: AbortSignal.timeout(12e4)
5432
+ });
5433
+ if (!response.ok || !response.body)
5434
+ throw new Error(
5435
+ `Cannot download the Go agent (HTTP ${response.status}). The TS agent remains available with --ts.`
5436
+ );
5437
+ const reader = response.body.getReader();
5438
+ const chunks = [];
5439
+ let size = 0;
5440
+ for (; ; ) {
5441
+ const { value, done } = await reader.read();
5442
+ if (done) break;
5443
+ size += value.length;
5444
+ if (size > 100 * 1024 * 1024) {
5445
+ await reader.cancel();
5446
+ throw new Error("Go binary exceeds the download size limit.");
5447
+ }
5448
+ chunks.push(Buffer.from(value));
5449
+ }
5450
+ const bytes = Buffer.concat(chunks);
5451
+ if (digest(bytes) !== checksum)
5452
+ throw new Error(
5453
+ "Go binary checksum does not match the installed npm release."
5454
+ );
5455
+ await fs.mkdir(dir, { recursive: true, mode: 448 });
5456
+ const temporary = binary + "." + randomUUID() + ".tmp";
5457
+ try {
5458
+ await fs.writeFile(temporary, bytes, { mode: 448, flag: "wx" });
5459
+ verifyVersion(temporary);
5460
+ try {
5461
+ await fs.rename(temporary, binary);
5462
+ } catch (error) {
5463
+ if (!await exists(binary) || digest(await fs.readFile(binary)) !== checksum)
5464
+ throw error;
5465
+ }
5466
+ } finally {
5467
+ await fs.rm(temporary, { force: true });
5468
+ }
5469
+ verifyVersion(binary);
5470
+ return binary;
5471
+ }
5472
+ async function launchGo(args) {
5473
+ const binary = await resolveGoBinary();
5474
+ const child = spawn(binary, args, { stdio: "inherit", windowsHide: true });
5475
+ const stop = (signal) => {
5476
+ if (process.platform === "win32") {
5477
+ void localGoControl("POST", "/stop", child.pid).catch(() => void 0);
5478
+ } else child.kill(signal);
5479
+ };
5480
+ const interrupt = () => stop("SIGINT"), terminate = () => stop("SIGTERM");
5481
+ process.on("SIGINT", interrupt);
5482
+ process.on("SIGTERM", terminate);
5483
+ try {
5484
+ const code = await new Promise((resolve, reject) => {
5485
+ child.once("error", reject);
5486
+ child.once("exit", (code2, signal) => resolve(code2 ?? (signal ? 1 : 0)));
5487
+ });
5488
+ process.exitCode = code;
5489
+ } finally {
5490
+ process.off("SIGINT", interrupt);
5491
+ process.off("SIGTERM", terminate);
5492
+ }
5493
+ }
5494
+ async function localGoControl(method, endpoint, expectedPid) {
5495
+ const home = process.env.REMOTEARC_HOME || os.homedir();
5496
+ const config = JSON.parse(
5497
+ await fs.readFile(
5498
+ path.join(home, ".remotearc", "agent", "control.json"),
5499
+ "utf8"
5500
+ )
5501
+ );
5502
+ const url = new URL(config.url);
5503
+ if (config.engine !== "go" || url.protocol !== "http:" || url.hostname !== "127.0.0.1" || !url.port || url.username || url.password || url.pathname !== "/" || url.search || url.hash || !/^[a-f0-9]{64}$/.test(config.token) || expectedPid !== void 0 && config.pid !== expectedPid)
5504
+ throw new Error("Invalid local Go control endpoint.");
5505
+ const response = await fetch(new URL(endpoint, url), {
5506
+ method,
5507
+ headers: { Authorization: "Bearer " + config.token },
5508
+ signal: AbortSignal.timeout(3e3),
5509
+ redirect: "error"
5510
+ });
5511
+ if (!response.ok) throw new Error("Local Go agent control request failed.");
5512
+ return response.json();
5513
+ }
5514
+ async function assertTSOwnership(args) {
5515
+ if (args.some((arg) => ["--help", "-h", "--version", "-v"].includes(arg)))
5516
+ return;
5517
+ const home = process.env.REMOTEARC_HOME || os.homedir();
5518
+ try {
5519
+ const lock2 = await fs.stat(
5520
+ path.join(home, ".remotearc", "agent", "execution.lock")
5521
+ );
5522
+ if (Date.now() - lock2.mtimeMs > 15e3) return;
5523
+ const status = await localGoControl("GET", "/status").catch(() => null);
5524
+ if (status?.engine === "go")
5525
+ throw new Error(
5526
+ "A Go agent owns execution. Use --go --stop before launching --ts; pairing and active operations have been preserved."
5527
+ );
5528
+ } catch (error) {
5529
+ if (error.code === "ENOENT") return;
5530
+ throw error;
5531
+ }
5532
+ }
5533
+
5290
5534
  // src/keep-awake.ts
5291
- import { spawn } from "child_process";
5535
+ import { spawn as spawn2 } from "child_process";
5292
5536
  var HELPER_SECONDS = 210;
5293
5537
  var windowsScript = `
5294
5538
  Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public static class RemoteArcPower { [DllImport("kernel32.dll")] public static extern uint SetThreadExecutionState(uint flags); }'
@@ -5298,7 +5542,7 @@ try { Start-Sleep -Seconds ${HELPER_SECONDS} } finally { [RemoteArcPower]::SetTh
5298
5542
  function createTaskKeepAwakeManager(options = {}) {
5299
5543
  const platform = options.platform || process.platform;
5300
5544
  const clock = options.now || Date.now;
5301
- const launch = options.spawn || spawn;
5545
+ const launch = options.spawn || spawn2;
5302
5546
  const leases = /* @__PURE__ */ new Map();
5303
5547
  let helper = null;
5304
5548
  let helperUntil = 0;
@@ -5365,15 +5609,15 @@ function createTaskKeepAwakeManager(options = {}) {
5365
5609
  }
5366
5610
 
5367
5611
  // src/goal-workspace.ts
5368
- import fs4 from "fs/promises";
5369
- import path4 from "path";
5612
+ import fs5 from "fs/promises";
5613
+ import path5 from "path";
5370
5614
  import { execFile as execFile2 } from "child_process";
5371
5615
  import { promisify } from "util";
5372
5616
 
5373
5617
  // ../execution-core/src/filesystem.ts
5374
5618
  import crypto from "crypto";
5375
- import fs from "fs/promises";
5376
- import path from "path";
5619
+ import fs2 from "fs/promises";
5620
+ import path2 from "path";
5377
5621
  var MAX_DIRECTORY_ENTRIES = 2e3;
5378
5622
  var DEFAULT_READ_LINES = 240;
5379
5623
  var MAX_TEXT_FILE_BYTES = 20 * 1024 * 1024;
@@ -5389,14 +5633,14 @@ async function listDirectory(targetPath, depth = 2, canReveal) {
5389
5633
  let protectedEntries = 0;
5390
5634
  async function walk(directory, level, prefix) {
5391
5635
  if (entriesSeen >= MAX_DIRECTORY_ENTRIES) return;
5392
- const entries = await fs.readdir(directory, { withFileTypes: true });
5636
+ const entries = await fs2.readdir(directory, { withFileTypes: true });
5393
5637
  entries.sort((a, b) => {
5394
5638
  if (a.isDirectory() !== b.isDirectory()) return a.isDirectory() ? -1 : 1;
5395
5639
  return a.name.localeCompare(b.name);
5396
5640
  });
5397
5641
  for (const entry of entries) {
5398
5642
  if (entriesSeen >= MAX_DIRECTORY_ENTRIES) break;
5399
- const absolute = path.join(directory, entry.name);
5643
+ const absolute = path2.join(directory, entry.name);
5400
5644
  if (canReveal && !await canReveal(absolute)) {
5401
5645
  protectedEntries += 1;
5402
5646
  continue;
@@ -5409,7 +5653,7 @@ async function listDirectory(targetPath, depth = 2, canReveal) {
5409
5653
  }
5410
5654
  }
5411
5655
  }
5412
- const stat = await fs.stat(targetPath);
5656
+ const stat = await fs2.stat(targetPath);
5413
5657
  if (!stat.isDirectory()) throw new Error("Path is not a directory: " + targetPath);
5414
5658
  await walk(targetPath, 1, "");
5415
5659
  if (entriesSeen >= MAX_DIRECTORY_ENTRIES) {
@@ -5424,14 +5668,14 @@ Depth: ${maxDepth}
5424
5668
  ${lines.join("\n") || "(empty)"}${protectionNote}`;
5425
5669
  }
5426
5670
  async function readTextFile(targetPath, offset, length) {
5427
- const stat = await fs.stat(targetPath);
5671
+ const stat = await fs2.stat(targetPath);
5428
5672
  if (!stat.isFile()) throw new Error("Path is not a file: " + targetPath);
5429
5673
  if (stat.size > MAX_TEXT_FILE_BYTES) {
5430
5674
  throw new Error(
5431
5675
  `File is too large for read_file (${printableSize(stat.size)} > 20 MB). Use a terminal command or a more targeted tool instead.`
5432
5676
  );
5433
5677
  }
5434
- const buffer = await fs.readFile(targetPath);
5678
+ const buffer = await fs2.readFile(targetPath);
5435
5679
  const sample = buffer.subarray(0, Math.min(buffer.length, 8192));
5436
5680
  if (sample.includes(0)) {
5437
5681
  throw new Error("Binary file detected. read_file currently supports text files only.");
@@ -5461,7 +5705,7 @@ function assertBinaryRevision(expected, actual) {
5461
5705
  }
5462
5706
  }
5463
5707
  function binaryMimeType(targetPath, header) {
5464
- const extension2 = path.extname(targetPath).toLowerCase();
5708
+ const extension2 = path2.extname(targetPath).toLowerCase();
5465
5709
  const office = {
5466
5710
  ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
5467
5711
  ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
@@ -5502,7 +5746,7 @@ function binaryMimeType(targetPath, header) {
5502
5746
  return known[extension2] || "application/octet-stream";
5503
5747
  }
5504
5748
  async function readBinaryFile(targetPath, offset = 0, length = BINARY_DEFAULT_BYTES, expectedRevision) {
5505
- const stat = await fs.stat(targetPath);
5749
+ const stat = await fs2.stat(targetPath);
5506
5750
  if (!stat.isFile()) throw new Error("Path is not a file: " + targetPath);
5507
5751
  const fileRevision = binaryFileRevision(stat);
5508
5752
  assertBinaryRevision(expectedRevision, fileRevision);
@@ -5527,7 +5771,7 @@ async function readBinaryFile(targetPath, offset = 0, length = BINARY_DEFAULT_BY
5527
5771
  };
5528
5772
  }
5529
5773
  const toRead = Math.min(requested, stat.size - byteOffset);
5530
- const handle = await fs.open(targetPath, "r");
5774
+ const handle = await fs2.open(targetPath, "r");
5531
5775
  try {
5532
5776
  const headerBuffer = Buffer.allocUnsafe(Math.min(16, stat.size));
5533
5777
  const headerResult = await handle.read(
@@ -5540,7 +5784,7 @@ async function readBinaryFile(targetPath, offset = 0, length = BINARY_DEFAULT_BY
5540
5784
  const buffer = Buffer.allocUnsafe(toRead);
5541
5785
  const result = await handle.read(buffer, 0, toRead, byteOffset);
5542
5786
  const chunk = buffer.subarray(0, result.bytesRead);
5543
- const afterStat = await fs.stat(targetPath);
5787
+ const afterStat = await fs2.stat(targetPath);
5544
5788
  const afterRevision = binaryFileRevision(afterStat);
5545
5789
  if (afterRevision !== fileRevision) {
5546
5790
  throw new Error(
@@ -5564,7 +5808,7 @@ async function readBinaryFile(targetPath, offset = 0, length = BINARY_DEFAULT_BY
5564
5808
  }
5565
5809
  }
5566
5810
  async function getFileInfo(targetPath) {
5567
- const stat = await fs.lstat(targetPath);
5811
+ const stat = await fs2.lstat(targetPath);
5568
5812
  return {
5569
5813
  path: targetPath,
5570
5814
  type: stat.isFile() ? "file" : stat.isDirectory() ? "directory" : stat.isSymbolicLink() ? "symlink" : "other",
@@ -5577,27 +5821,27 @@ async function getFileInfo(targetPath) {
5577
5821
  };
5578
5822
  }
5579
5823
  async function atomicWriteText(targetPath, content) {
5580
- const directory = path.dirname(targetPath);
5581
- await fs.mkdir(directory, { recursive: true });
5582
- const temporary = path.join(
5824
+ const directory = path2.dirname(targetPath);
5825
+ await fs2.mkdir(directory, { recursive: true });
5826
+ const temporary = path2.join(
5583
5827
  directory,
5584
- "." + path.basename(targetPath) + ".remotearc-" + crypto.randomUUID() + ".tmp"
5828
+ "." + path2.basename(targetPath) + ".remotearc-" + crypto.randomUUID() + ".tmp"
5585
5829
  );
5586
5830
  try {
5587
- await fs.writeFile(temporary, content, "utf8");
5588
- await fs.rename(temporary, targetPath);
5831
+ await fs2.writeFile(temporary, content, "utf8");
5832
+ await fs2.rename(temporary, targetPath);
5589
5833
  } finally {
5590
- await fs.rm(temporary, { force: true }).catch(() => void 0);
5834
+ await fs2.rm(temporary, { force: true }).catch(() => void 0);
5591
5835
  }
5592
5836
  }
5593
5837
  async function writeTextFile(targetPath, content, mode = "rewrite") {
5594
- await fs.mkdir(path.dirname(targetPath), { recursive: true });
5838
+ await fs2.mkdir(path2.dirname(targetPath), { recursive: true });
5595
5839
  if (mode === "append") {
5596
- await fs.appendFile(targetPath, content, "utf8");
5840
+ await fs2.appendFile(targetPath, content, "utf8");
5597
5841
  } else {
5598
5842
  await atomicWriteText(targetPath, content);
5599
5843
  }
5600
- const stat = await fs.stat(targetPath);
5844
+ const stat = await fs2.stat(targetPath);
5601
5845
  return {
5602
5846
  path: targetPath,
5603
5847
  mode,
@@ -5608,7 +5852,7 @@ async function writeTextFile(targetPath, content, mode = "rewrite") {
5608
5852
  }
5609
5853
  async function editTextBlock(filePath, oldString, newString, expectedReplacements = 1) {
5610
5854
  if (!oldString) throw new Error("old_string cannot be empty.");
5611
- const current = await fs.readFile(filePath, "utf8");
5855
+ const current = await fs2.readFile(filePath, "utf8");
5612
5856
  const parts = current.split(oldString);
5613
5857
  const replacements = parts.length - 1;
5614
5858
  if (replacements !== expectedReplacements) {
@@ -5627,14 +5871,14 @@ async function editTextBlock(filePath, oldString, newString, expectedReplacement
5627
5871
  };
5628
5872
  }
5629
5873
  async function browseDirectories(targetPath, canReveal) {
5630
- const stat = await fs.stat(targetPath);
5874
+ const stat = await fs2.stat(targetPath);
5631
5875
  if (!stat.isDirectory()) throw new Error("Path is not a directory: " + targetPath);
5632
- const entries = await fs.readdir(targetPath, { withFileTypes: true });
5876
+ const entries = await fs2.readdir(targetPath, { withFileTypes: true });
5633
5877
  const directories = [];
5634
5878
  let protectedEntries = 0;
5635
5879
  for (const entry of entries) {
5636
5880
  if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
5637
- const absolute = path.join(targetPath, entry.name);
5881
+ const absolute = path2.join(targetPath, entry.name);
5638
5882
  if (canReveal && !await canReveal(absolute)) {
5639
5883
  protectedEntries += 1;
5640
5884
  continue;
@@ -5649,7 +5893,7 @@ async function browseDirectories(targetPath, canReveal) {
5649
5893
  directories.sort((a, b) => a.name.localeCompare(b.name));
5650
5894
  return {
5651
5895
  path: targetPath,
5652
- parent: path.dirname(targetPath) === targetPath ? null : path.dirname(targetPath),
5896
+ parent: path2.dirname(targetPath) === targetPath ? null : path2.dirname(targetPath),
5653
5897
  directories,
5654
5898
  protected_entries_omitted: protectedEntries,
5655
5899
  truncated: directories.length >= 300
@@ -5657,7 +5901,7 @@ async function browseDirectories(targetPath, canReveal) {
5657
5901
  }
5658
5902
 
5659
5903
  // ../execution-core/src/process.ts
5660
- import { execFile, spawn as spawn2 } from "child_process";
5904
+ import { execFile, spawn as spawn3 } from "child_process";
5661
5905
  import crypto2 from "crypto";
5662
5906
  import process2 from "process";
5663
5907
  var MAX_CAPTURE_BYTES = 2 * 1024 * 1024;
@@ -5687,7 +5931,7 @@ async function terminateTree(child) {
5687
5931
  if (!child.pid) return;
5688
5932
  if (process2.platform === "win32") {
5689
5933
  await new Promise((resolve) => {
5690
- const killer = spawn2(
5934
+ const killer = spawn3(
5691
5935
  "taskkill.exe",
5692
5936
  ["/PID", String(child.pid), "/T", "/F"],
5693
5937
  { windowsHide: true, stdio: "ignore" }
@@ -5713,7 +5957,7 @@ async function runShellCommand(command, timeoutMs = 5e3, cwd) {
5713
5957
  const timeout = Math.max(100, Math.min(12e4, Math.trunc(timeoutMs || 5e3)));
5714
5958
  const startedAt = Date.now();
5715
5959
  return await new Promise((resolve, reject) => {
5716
- const child = spawn2(command, {
5960
+ const child = spawn3(command, {
5717
5961
  shell: true,
5718
5962
  cwd,
5719
5963
  windowsHide: true,
@@ -5782,7 +6026,7 @@ async function startBackgroundProcess(command, cwd, maxDurationSeconds) {
5782
6026
  "Remote Arc already has the maximum number of managed background processes on this device."
5783
6027
  );
5784
6028
  }
5785
- const child = spawn2(command, {
6029
+ const child = spawn3(command, {
5786
6030
  shell: true,
5787
6031
  cwd,
5788
6032
  windowsHide: true,
@@ -5916,20 +6160,20 @@ function listManagedProcesses() {
5916
6160
  // ../execution-core/src/safety.ts
5917
6161
  import crypto3 from "crypto";
5918
6162
  import { createReadStream } from "fs";
5919
- import fs2 from "fs/promises";
5920
- import os from "os";
5921
- import path2 from "path";
6163
+ import fs3 from "fs/promises";
6164
+ import os2 from "os";
6165
+ import path3 from "path";
5922
6166
  var RETENTION_MS = 7 * 24 * 60 * 60 * 1e3;
5923
6167
  var MAX_SNAPSHOT_BYTES = 20 * 1024 * 1024;
5924
6168
  var MAX_UNDO_BYTES = 200 * 1024 * 1024;
5925
- var undoRoot = () => process.env.REMOTEARC_UNDO_ROOT || path2.join(os.homedir(), ".remotearc", "undo");
6169
+ var undoRoot = () => process.env.REMOTEARC_UNDO_ROOT || path3.join(os2.homedir(), ".remotearc", "undo");
5926
6170
  async function ensureUndoRoot() {
5927
- await fs2.mkdir(undoRoot(), { recursive: true, mode: 448 });
6171
+ await fs3.mkdir(undoRoot(), { recursive: true, mode: 448 });
5928
6172
  }
5929
6173
  async function readManifest(directory) {
5930
6174
  try {
5931
6175
  return JSON.parse(
5932
- await fs2.readFile(path2.join(directory, "manifest.json"), "utf8")
6176
+ await fs3.readFile(path3.join(directory, "manifest.json"), "utf8")
5933
6177
  );
5934
6178
  } catch {
5935
6179
  return null;
@@ -5937,8 +6181,8 @@ async function readManifest(directory) {
5937
6181
  }
5938
6182
  async function snapshotDirectories() {
5939
6183
  await ensureUndoRoot();
5940
- const entries = await fs2.readdir(undoRoot(), { withFileTypes: true });
5941
- return entries.filter((entry) => entry.isDirectory()).map((entry) => path2.join(undoRoot(), entry.name));
6184
+ const entries = await fs3.readdir(undoRoot(), { withFileTypes: true });
6185
+ return entries.filter((entry) => entry.isDirectory()).map((entry) => path3.join(undoRoot(), entry.name));
5942
6186
  }
5943
6187
  async function cleanupUndoStore() {
5944
6188
  const now = Date.now();
@@ -5946,12 +6190,12 @@ async function cleanupUndoStore() {
5946
6190
  for (const directory of await snapshotDirectories()) {
5947
6191
  const manifest = await readManifest(directory);
5948
6192
  if (!manifest) {
5949
- await fs2.rm(directory, { recursive: true, force: true }).catch(() => void 0);
6193
+ await fs3.rm(directory, { recursive: true, force: true }).catch(() => void 0);
5950
6194
  continue;
5951
6195
  }
5952
6196
  const created = Date.parse(manifest.createdAt);
5953
6197
  if (!Number.isFinite(created) || now - created > RETENTION_MS) {
5954
- await fs2.rm(directory, { recursive: true, force: true }).catch(() => void 0);
6198
+ await fs3.rm(directory, { recursive: true, force: true }).catch(() => void 0);
5955
6199
  continue;
5956
6200
  }
5957
6201
  snapshots.push({ directory, manifest });
@@ -5962,7 +6206,7 @@ async function cleanupUndoStore() {
5962
6206
  let total = snapshots.reduce((sum, item) => sum + item.manifest.bytes, 0);
5963
6207
  for (const item of snapshots) {
5964
6208
  if (total <= MAX_UNDO_BYTES) break;
5965
- await fs2.rm(item.directory, { recursive: true, force: true }).catch(() => void 0);
6209
+ await fs3.rm(item.directory, { recursive: true, force: true }).catch(() => void 0);
5966
6210
  total -= item.manifest.bytes;
5967
6211
  }
5968
6212
  }
@@ -5979,22 +6223,22 @@ async function createUndoSnapshot(tool, args) {
5979
6223
  let bytes = 0;
5980
6224
  let original = null;
5981
6225
  try {
5982
- const stat = await fs2.stat(targetPath);
6226
+ const stat = await fs3.stat(targetPath);
5983
6227
  if (!stat.isFile()) return null;
5984
6228
  existed = true;
5985
6229
  mode = stat.mode;
5986
6230
  bytes = stat.size;
5987
6231
  if (bytes > MAX_SNAPSHOT_BYTES) return null;
5988
- original = await fs2.readFile(targetPath);
6232
+ original = await fs3.readFile(targetPath);
5989
6233
  } catch (error) {
5990
6234
  const code = error && typeof error === "object" && "code" in error ? String(error.code) : "";
5991
6235
  if (code !== "ENOENT") throw error;
5992
6236
  }
5993
6237
  const id = `${Date.now()}-${crypto3.randomUUID().slice(0, 8)}`;
5994
- const directory = path2.join(undoRoot(), id);
5995
- await fs2.mkdir(directory, { recursive: true, mode: 448 });
6238
+ const directory = path3.join(undoRoot(), id);
6239
+ await fs3.mkdir(directory, { recursive: true, mode: 448 });
5996
6240
  if (original) {
5997
- await fs2.writeFile(path2.join(directory, "content.bin"), original, { mode: 384 });
6241
+ await fs3.writeFile(path3.join(directory, "content.bin"), original, { mode: 384 });
5998
6242
  }
5999
6243
  const manifest = {
6000
6244
  id,
@@ -6005,8 +6249,8 @@ async function createUndoSnapshot(tool, args) {
6005
6249
  ...mode !== void 0 ? { mode } : {},
6006
6250
  bytes
6007
6251
  };
6008
- await fs2.writeFile(
6009
- path2.join(directory, "manifest.json"),
6252
+ await fs3.writeFile(
6253
+ path3.join(directory, "manifest.json"),
6010
6254
  JSON.stringify(manifest, null, 2) + "\n",
6011
6255
  { mode: 384 }
6012
6256
  );
@@ -6022,8 +6266,8 @@ async function finalizeUndoSnapshot(snapshot) {
6022
6266
  if (!snapshot) return false;
6023
6267
  try {
6024
6268
  snapshot.manifest.postChangeHash = await hashFile(snapshot.manifest.targetPath);
6025
- await fs2.writeFile(
6026
- path2.join(snapshot.directory, "manifest.json"),
6269
+ await fs3.writeFile(
6270
+ path3.join(snapshot.directory, "manifest.json"),
6027
6271
  JSON.stringify(snapshot.manifest, null, 2) + "\n",
6028
6272
  { mode: 384 }
6029
6273
  );
@@ -6035,7 +6279,7 @@ async function finalizeUndoSnapshot(snapshot) {
6035
6279
  }
6036
6280
  async function discardUndoSnapshot(snapshot) {
6037
6281
  if (!snapshot) return;
6038
- await fs2.rm(snapshot.directory, { recursive: true, force: true }).catch(() => void 0);
6282
+ await fs3.rm(snapshot.directory, { recursive: true, force: true }).catch(() => void 0);
6039
6283
  }
6040
6284
  async function undoCandidates() {
6041
6285
  await cleanupUndoStore();
@@ -6100,16 +6344,16 @@ async function restoreUndoCandidate(candidate) {
6100
6344
  );
6101
6345
  }
6102
6346
  if (manifest.existed) {
6103
- const original = await fs2.readFile(path2.join(directory, "content.bin"));
6104
- await fs2.mkdir(path2.dirname(manifest.targetPath), { recursive: true });
6105
- await fs2.writeFile(manifest.targetPath, original);
6347
+ const original = await fs3.readFile(path3.join(directory, "content.bin"));
6348
+ await fs3.mkdir(path3.dirname(manifest.targetPath), { recursive: true });
6349
+ await fs3.writeFile(manifest.targetPath, original);
6106
6350
  if (manifest.mode !== void 0) {
6107
- await fs2.chmod(manifest.targetPath, manifest.mode).catch(() => void 0);
6351
+ await fs3.chmod(manifest.targetPath, manifest.mode).catch(() => void 0);
6108
6352
  }
6109
6353
  } else {
6110
- await fs2.rm(manifest.targetPath, { force: true });
6354
+ await fs3.rm(manifest.targetPath, { force: true });
6111
6355
  }
6112
- await fs2.rm(directory, { recursive: true, force: true });
6356
+ await fs3.rm(directory, { recursive: true, force: true });
6113
6357
  return {
6114
6358
  restored: true,
6115
6359
  action_id: manifest.id,
@@ -6175,9 +6419,9 @@ function assertCommandAllowed(command) {
6175
6419
  }
6176
6420
 
6177
6421
  // ../execution-core/src/policy.ts
6178
- import fs3 from "fs/promises";
6179
- import os2 from "os";
6180
- import path3 from "path";
6422
+ import fs4 from "fs/promises";
6423
+ import os3 from "os";
6424
+ import path4 from "path";
6181
6425
  var SENSITIVE_BASENAMES = /* @__PURE__ */ new Set([
6182
6426
  ".npmrc",
6183
6427
  ".pypirc",
@@ -6189,75 +6433,75 @@ var SENSITIVE_BASENAMES = /* @__PURE__ */ new Set([
6189
6433
  ]);
6190
6434
  var expandPath = (value) => {
6191
6435
  const trimmed = value.trim();
6192
- if (trimmed === "~") return os2.homedir();
6436
+ if (trimmed === "~") return os3.homedir();
6193
6437
  if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) {
6194
- return path3.join(os2.homedir(), trimmed.slice(2));
6438
+ return path4.join(os3.homedir(), trimmed.slice(2));
6195
6439
  }
6196
- return trimmed.replace(/%USERPROFILE%/gi, os2.homedir()).replace(/\$HOME\b/g, os2.homedir());
6440
+ return trimmed.replace(/%USERPROFILE%/gi, os3.homedir()).replace(/\$HOME\b/g, os3.homedir());
6197
6441
  };
6198
6442
  var comparePath = (value) => {
6199
- const resolved = path3.resolve(expandPath(value));
6443
+ const resolved = path4.resolve(expandPath(value));
6200
6444
  return process.platform === "win32" ? resolved.toLowerCase() : resolved;
6201
6445
  };
6202
6446
  async function canonicalTarget(targetPath) {
6203
- const expanded = path3.resolve(expandPath(targetPath));
6447
+ const expanded = path4.resolve(expandPath(targetPath));
6204
6448
  try {
6205
- return comparePath(await fs3.realpath(expanded));
6449
+ return comparePath(await fs4.realpath(expanded));
6206
6450
  } catch {
6207
6451
  const missing = [];
6208
6452
  let cursor = expanded;
6209
6453
  while (true) {
6210
6454
  try {
6211
- const realParent = await fs3.realpath(cursor);
6212
- return comparePath(path3.join(realParent, ...missing.reverse()));
6455
+ const realParent = await fs4.realpath(cursor);
6456
+ return comparePath(path4.join(realParent, ...missing.reverse()));
6213
6457
  } catch {
6214
- const parent = path3.dirname(cursor);
6458
+ const parent = path4.dirname(cursor);
6215
6459
  if (parent === cursor) return comparePath(expanded);
6216
- missing.push(path3.basename(cursor));
6460
+ missing.push(path4.basename(cursor));
6217
6461
  cursor = parent;
6218
6462
  }
6219
6463
  }
6220
6464
  }
6221
6465
  }
6222
6466
  var isInside = (target, root) => {
6223
- const relative = path3.relative(root, target);
6224
- return relative === "" || !relative.startsWith("..") && !path3.isAbsolute(relative);
6467
+ const relative = path4.relative(root, target);
6468
+ return relative === "" || !relative.startsWith("..") && !path4.isAbsolute(relative);
6225
6469
  };
6226
6470
  function defaultSensitiveRoots() {
6227
- const home = os2.homedir();
6471
+ const home = os3.homedir();
6228
6472
  const roots = [
6229
- path3.join(home, ".ssh"),
6230
- path3.join(home, ".aws"),
6231
- path3.join(home, ".gnupg"),
6232
- path3.join(home, ".azure"),
6233
- path3.join(home, ".kube"),
6234
- path3.join(home, ".docker"),
6235
- path3.join(home, ".config", "gcloud")
6473
+ path4.join(home, ".ssh"),
6474
+ path4.join(home, ".aws"),
6475
+ path4.join(home, ".gnupg"),
6476
+ path4.join(home, ".azure"),
6477
+ path4.join(home, ".kube"),
6478
+ path4.join(home, ".docker"),
6479
+ path4.join(home, ".config", "gcloud")
6236
6480
  ];
6237
6481
  if (process.platform === "darwin") {
6238
6482
  roots.push(
6239
- path3.join(home, "Library", "Application Support", "Google", "Chrome"),
6240
- path3.join(home, "Library", "Application Support", "Microsoft Edge"),
6241
- path3.join(home, "Library", "Application Support", "Firefox")
6483
+ path4.join(home, "Library", "Application Support", "Google", "Chrome"),
6484
+ path4.join(home, "Library", "Application Support", "Microsoft Edge"),
6485
+ path4.join(home, "Library", "Application Support", "Firefox")
6242
6486
  );
6243
6487
  }
6244
6488
  if (process.platform === "win32") {
6245
6489
  const appData = process.env.APPDATA;
6246
6490
  const localAppData = process.env.LOCALAPPDATA;
6247
6491
  if (appData) {
6248
- roots.push(path3.join(appData, "Mozilla", "Firefox"));
6492
+ roots.push(path4.join(appData, "Mozilla", "Firefox"));
6249
6493
  }
6250
6494
  if (localAppData) {
6251
6495
  roots.push(
6252
- path3.join(localAppData, "Google", "Chrome", "User Data"),
6253
- path3.join(localAppData, "Microsoft", "Edge", "User Data")
6496
+ path4.join(localAppData, "Google", "Chrome", "User Data"),
6497
+ path4.join(localAppData, "Microsoft", "Edge", "User Data")
6254
6498
  );
6255
6499
  }
6256
6500
  }
6257
6501
  return roots;
6258
6502
  }
6259
6503
  function looksLikeSensitiveFile(target) {
6260
- const basename = path3.basename(target).toLowerCase();
6504
+ const basename = path4.basename(target).toLowerCase();
6261
6505
  if (basename === ".env" || basename.startsWith(".env.")) return true;
6262
6506
  if (SENSITIVE_BASENAMES.has(basename)) return true;
6263
6507
  const normalized = target.replace(/\\/g, "/").toLowerCase();
@@ -6752,7 +6996,7 @@ var RemoteArcExecutionCore = class {
6752
6996
  // src/goal-workspace.ts
6753
6997
  var run = promisify(execFile2);
6754
6998
  var pending = /* @__PURE__ */ new Map();
6755
- var samePath = (a, b) => process.platform === "win32" ? path4.resolve(a).toLowerCase() === path4.resolve(b).toLowerCase() : path4.resolve(a) === path4.resolve(b);
6999
+ var samePath = (a, b) => process.platform === "win32" ? path5.resolve(a).toLowerCase() === path5.resolve(b).toLowerCase() : path5.resolve(a) === path5.resolve(b);
6756
7000
  var git = async (cwd, args) => (await run("git", ["-c", "core.hooksPath=", "-c", "commit.gpgSign=false", "-C", cwd, ...args], { windowsHide: true, timeout: 2e4, maxBuffer: 1e6, env: { ...process.env, GIT_TERMINAL_PROMPT: "0", GIT_AUTHOR_NAME: "Remote Arc", GIT_AUTHOR_EMAIL: "task@remotearc.local", GIT_COMMITTER_NAME: "Remote Arc", GIT_COMMITTER_EMAIL: "task@remotearc.local" } })).stdout.trim();
6757
7001
  async function goalWorkspace(args, policy = {}) {
6758
7002
  const id = String(args.task_id || ""), operation = String(args.operation_id || ""), action = String(args.action || "");
@@ -6760,12 +7004,12 @@ async function goalWorkspace(args, policy = {}) {
6760
7004
  const prior = pending.get(id) || Promise.resolve();
6761
7005
  const next = prior.catch(() => void 0).then(async () => {
6762
7006
  const root = await enforcePathPolicy(String(args.workspace || ""), policy);
6763
- const canonical = await fs4.realpath(root);
6764
- const directory = await enforcePathPolicy(path4.join(canonical, ".remotearc-goals", id), policy);
6765
- const file = path4.join(directory, "state.json");
7007
+ const canonical = await fs5.realpath(root);
7008
+ const directory = await enforcePathPolicy(path5.join(canonical, ".remotearc-goals", id), policy);
7009
+ const file = path5.join(directory, "state.json");
6766
7010
  let state;
6767
7011
  try {
6768
- state = JSON.parse(await fs4.readFile(file, "utf8"));
7012
+ state = JSON.parse(await fs5.readFile(file, "utf8"));
6769
7013
  } catch (e) {
6770
7014
  if (e.code !== "ENOENT") throw e;
6771
7015
  }
@@ -6773,28 +7017,28 @@ async function goalWorkspace(args, policy = {}) {
6773
7017
  const result = (s) => ({ root: s.root, path: s.path, frontier: s.frontier, generation: s.generation });
6774
7018
  const save = async (s) => {
6775
7019
  const temp = file + ".next";
6776
- await fs4.writeFile(temp, JSON.stringify(s), { encoding: "utf8", mode: 384 });
6777
- await fs4.rename(temp, file);
7020
+ await fs5.writeFile(temp, JSON.stringify(s), { encoding: "utf8", mode: 384 });
7021
+ await fs5.rename(temp, file);
6778
7022
  };
6779
7023
  if (state?.operations[operation] && !["status", "fingerprint"].includes(action)) return state.operations[operation];
6780
7024
  if (!state) {
6781
7025
  if (action !== "create") throw new Error("No owned goal workspace. Update the device CLI if this tool is unavailable.");
6782
- const top = await fs4.realpath(await git(canonical, ["rev-parse", "--show-toplevel"]));
7026
+ const top = await fs5.realpath(await git(canonical, ["rev-parse", "--show-toplevel"]));
6783
7027
  if (!samePath(top, canonical)) throw new Error("Quality isolation requires the repository root.");
6784
7028
  if (await git(canonical, ["status", "--porcelain", "--", ".", ":!.remotearc-goals"])) throw new Error("Quality baseline requires a clean checkout; preserve user edits before starting.");
6785
7029
  const frontier = await git(canonical, ["rev-parse", "HEAD"]);
6786
- await fs4.mkdir(directory, { recursive: true });
6787
- const candidate = await enforcePathPolicy(path4.join(directory, "candidate-0"), policy);
7030
+ await fs5.mkdir(directory, { recursive: true });
7031
+ const candidate = await enforcePathPolicy(path5.join(directory, "candidate-0"), policy);
6788
7032
  await git(canonical, ["worktree", "add", "--detach", candidate, frontier]);
6789
7033
  state = { version: 1, task_id: id, root: canonical, path: candidate, frontier, generation: 0, operations: {} };
6790
7034
  } else {
6791
- const expected = path4.join(directory, "candidate-" + state.generation);
6792
- if (!samePath(state.path, expected) || !samePath(await fs4.realpath(state.path), expected)) throw new Error("Candidate ownership path changed.");
7035
+ const expected = path5.join(directory, "candidate-" + state.generation);
7036
+ if (!samePath(state.path, expected) || !samePath(await fs5.realpath(state.path), expected)) throw new Error("Candidate ownership path changed.");
6793
7037
  await enforcePathPolicy(state.path, policy);
6794
- const marker = await fs4.lstat(path4.join(state.path, ".git"));
7038
+ const marker = await fs5.lstat(path5.join(state.path, ".git"));
6795
7039
  if (!marker.isFile() || marker.isSymbolicLink()) throw new Error("Candidate Git identity changed.");
6796
- const common = await fs4.realpath(await git(state.path, ["rev-parse", "--path-format=absolute", "--git-common-dir"]));
6797
- const original = await fs4.realpath(await git(canonical, ["rev-parse", "--path-format=absolute", "--git-common-dir"]));
7040
+ const common = await fs5.realpath(await git(state.path, ["rev-parse", "--path-format=absolute", "--git-common-dir"]));
7041
+ const original = await fs5.realpath(await git(canonical, ["rev-parse", "--path-format=absolute", "--git-common-dir"]));
6798
7042
  if (!samePath(common, original)) throw new Error("Candidate belongs to another repository.");
6799
7043
  if (action === "capture") {
6800
7044
  if (args.expected_frontier !== state.frontier) throw new Error("Accepted checkpoint changed. Read context again.");
@@ -6808,7 +7052,7 @@ async function goalWorkspace(args, policy = {}) {
6808
7052
  }
6809
7053
  if (action === "reject") {
6810
7054
  if (args.expected_frontier !== state.frontier) throw new Error("Accepted checkpoint changed. Read context again.");
6811
- const candidate = await enforcePathPolicy(path4.join(directory, "candidate-" + (state.generation + 1)), policy);
7055
+ const candidate = await enforcePathPolicy(path5.join(directory, "candidate-" + (state.generation + 1)), policy);
6812
7056
  await git(canonical, ["worktree", "add", "--detach", candidate, state.frontier]);
6813
7057
  state.generation++;
6814
7058
  state.path = candidate;
@@ -6834,21 +7078,21 @@ async function goalWorkspace(args, policy = {}) {
6834
7078
 
6835
7079
  // src/agent-runtime.ts
6836
7080
  var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
6837
- import fs5 from "fs/promises";
7081
+ import fs6 from "fs/promises";
6838
7082
  import { appendFileSync, mkdirSync, renameSync, statSync, openSync, closeSync } from "fs";
6839
- import path5 from "path";
6840
- import { spawn as spawn3 } from "child_process";
7083
+ import path6 from "path";
7084
+ import { spawn as spawn4 } from "child_process";
6841
7085
  var AGENT_LEASE_STALE_MS = 15e3;
6842
7086
  async function agentLeaseActive(directory) {
6843
- return (0, import_proper_lockfile.check)(path5.join(directory, "execution"), {
7087
+ return (0, import_proper_lockfile.check)(path6.join(directory, "execution"), {
6844
7088
  realpath: false,
6845
7089
  stale: AGENT_LEASE_STALE_MS
6846
7090
  });
6847
7091
  }
6848
7092
  async function tryAgentLease(directory, role = "execution") {
6849
- await fs5.mkdir(directory, { recursive: true, mode: 448 });
7093
+ await fs6.mkdir(directory, { recursive: true, mode: 448 });
6850
7094
  try {
6851
- return await (0, import_proper_lockfile.lock)(path5.join(directory, role), {
7095
+ return await (0, import_proper_lockfile.lock)(path6.join(directory, role), {
6852
7096
  realpath: false,
6853
7097
  stale: AGENT_LEASE_STALE_MS,
6854
7098
  update: 3e3,
@@ -6862,7 +7106,7 @@ async function tryAgentLease(directory, role = "execution") {
6862
7106
  function appendAgentEvent(directory, line) {
6863
7107
  try {
6864
7108
  mkdirSync(directory, { recursive: true, mode: 448 });
6865
- const file = path5.join(directory, "events.log");
7109
+ const file = path6.join(directory, "events.log");
6866
7110
  if ((statSync(file, { throwIfNoEntry: false })?.size ?? 0) > 5 * 1024 * 1024) {
6867
7111
  renameSync(file, file + ".1");
6868
7112
  }
@@ -6871,10 +7115,10 @@ function appendAgentEvent(directory, line) {
6871
7115
  }
6872
7116
  }
6873
7117
  async function readAgentEvents(directory, cursor) {
6874
- const file = path5.join(directory, "events.log");
7118
+ const file = path6.join(directory, "events.log");
6875
7119
  let handle;
6876
7120
  try {
6877
- handle = await fs5.open(file, "r");
7121
+ handle = await fs6.open(file, "r");
6878
7122
  const size = (await handle.stat()).size;
6879
7123
  const start = cursor === null ? Math.max(0, size - 16384) : cursor > size ? 0 : cursor;
6880
7124
  const buffer = Buffer.alloc(Math.min(size - start, 64 * 1024));
@@ -6890,6 +7134,38 @@ async function readAgentEvents(directory, cursor) {
6890
7134
  await handle?.close();
6891
7135
  }
6892
7136
  }
7137
+ async function readAgentEventTail(directory, requestedLimit = 100) {
7138
+ const limit = Math.max(20, Math.min(200, Math.trunc(requestedLimit || 100)));
7139
+ const file = path6.join(directory, "events.log");
7140
+ let handle;
7141
+ try {
7142
+ handle = await fs6.open(file, "r");
7143
+ const stat = await handle.stat();
7144
+ const start = Math.max(0, stat.size - 128 * 1024);
7145
+ const buffer = Buffer.alloc(Math.min(stat.size - start, 128 * 1024));
7146
+ const { bytesRead } = await handle.read(buffer, 0, buffer.length, start);
7147
+ let lines = buffer.subarray(0, bytesRead).toString("utf8").split("\n");
7148
+ if (start > 0) lines = lines.slice(1);
7149
+ lines = lines.map((line) => line.trimEnd()).filter(Boolean);
7150
+ return {
7151
+ source: "local-device",
7152
+ lines: lines.slice(-limit),
7153
+ total_bytes: stat.size,
7154
+ truncated: start > 0 || lines.length > limit,
7155
+ updated_at: stat.mtime.toISOString()
7156
+ };
7157
+ } catch {
7158
+ return {
7159
+ source: "local-device",
7160
+ lines: [],
7161
+ total_bytes: 0,
7162
+ truncated: false,
7163
+ updated_at: null
7164
+ };
7165
+ } finally {
7166
+ await handle?.close();
7167
+ }
7168
+ }
6893
7169
  async function superviseAgent(options) {
6894
7170
  let delay = options.delayMs ?? 1e3;
6895
7171
  while (!options.signal.aborted && await options.enabled()) {
@@ -6918,28 +7194,28 @@ async function superviseAgent(options) {
6918
7194
  }
6919
7195
  }
6920
7196
  function startSupervisedAgent(node, bundle, logs) {
6921
- if (!logs) return spawn3(node, [bundle, "--agent"], { stdio: "inherit", windowsHide: true });
7197
+ if (!logs) return spawn4(node, [bundle, "--agent"], { stdio: "inherit", windowsHide: true });
6922
7198
  mkdirSync(logs, { recursive: true, mode: 448 });
6923
- const out = openSync(path5.join(logs, "agent.log"), "a", 384);
7199
+ const out = openSync(path6.join(logs, "agent.log"), "a", 384);
6924
7200
  let err;
6925
7201
  try {
6926
- err = openSync(path5.join(logs, "agent-error.log"), "a", 384);
6927
- return spawn3(node, [bundle, "--agent"], { stdio: ["ignore", out, err], windowsHide: true });
7202
+ err = openSync(path6.join(logs, "agent-error.log"), "a", 384);
7203
+ return spawn4(node, [bundle, "--agent"], { stdio: ["ignore", out, err], windowsHide: true });
6928
7204
  } finally {
6929
7205
  closeSync(out);
6930
7206
  if (err !== void 0) closeSync(err);
6931
7207
  }
6932
7208
  }
6933
7209
 
6934
- // src/index.ts
6935
- import os4 from "os";
6936
- import path7 from "path";
6937
- import fs7 from "fs/promises";
6938
- import { spawn as spawn5 } from "child_process";
6939
- import { randomUUID } from "crypto";
7210
+ // src/legacy.ts
7211
+ import os5 from "os";
7212
+ import path8 from "path";
7213
+ import fs8 from "fs/promises";
7214
+ import { spawn as spawn6 } from "child_process";
7215
+ import { randomUUID as randomUUID2 } from "crypto";
6940
7216
  import process3 from "process";
6941
7217
  import { createInterface } from "readline/promises";
6942
- import { fileURLToPath } from "url";
7218
+ import { fileURLToPath as fileURLToPath2 } from "url";
6943
7219
 
6944
7220
  // ../../node_modules/.pnpm/ws@8.21.3/node_modules/ws/wrapper.mjs
6945
7221
  var import_stream = __toESM(require_stream(), 1);
@@ -6953,10 +7229,10 @@ var import_websocket_server = __toESM(require_websocket_server(), 1);
6953
7229
  var wrapper_default = import_websocket.default;
6954
7230
 
6955
7231
  // src/background.ts
6956
- import os3 from "os";
6957
- import path6 from "path";
6958
- import fs6 from "fs/promises";
6959
- import { spawn as spawn4 } from "child_process";
7232
+ import os4 from "os";
7233
+ import path7 from "path";
7234
+ import fs7 from "fs/promises";
7235
+ import { spawn as spawn5 } from "child_process";
6960
7236
  var LegacyBackgroundAgentError = class extends Error {
6961
7237
  };
6962
7238
  function parseReleaseVersion(value) {
@@ -6979,7 +7255,7 @@ function windowsSupervisorLaunchScript(node, bundle) {
6979
7255
  }
6980
7256
  async function run2(command, args, options = {}) {
6981
7257
  return new Promise((resolve, reject) => {
6982
- const child = spawn4(command, args, {
7258
+ const child = spawn5(command, args, {
6983
7259
  stdio: ["ignore", "pipe", "pipe"],
6984
7260
  windowsHide: true
6985
7261
  });
@@ -7022,17 +7298,17 @@ async function run2(command, args, options = {}) {
7022
7298
  }
7023
7299
  function createBackgroundController(options = {}) {
7024
7300
  const platform = options.platform ?? process.platform;
7025
- const home = options.home ?? os3.homedir();
7301
+ const home = options.home ?? os4.homedir();
7026
7302
  const nodePath = options.nodePath ?? process.execPath;
7027
- const uid = options.uid ?? process.getuid?.() ?? os3.userInfo().uid;
7303
+ const uid = options.uid ?? process.getuid?.() ?? os4.userInfo().uid;
7028
7304
  const runCommand = options.run ?? run2;
7029
7305
  const wait = options.wait ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
7030
7306
  const leaseActive = options.leaseActive ?? agentLeaseActive;
7031
- const CONFIG_DIR2 = path6.join(home, ".remotearc");
7032
- const AGENT_DIR = path6.join(CONFIG_DIR2, "agent");
7033
- const LOG_DIR = path6.join(CONFIG_DIR2, "logs");
7034
- const AGENT_BUNDLE = path6.join(AGENT_DIR, "remotelink.mjs");
7035
- const AGENT_VERSION_FILE = path6.join(AGENT_DIR, "version");
7307
+ const CONFIG_DIR2 = path7.join(home, ".remotearc");
7308
+ const AGENT_DIR = path7.join(CONFIG_DIR2, "agent");
7309
+ const LOG_DIR = path7.join(CONFIG_DIR2, "logs");
7310
+ const AGENT_BUNDLE = path7.join(AGENT_DIR, "remotelink.mjs");
7311
+ const AGENT_VERSION_FILE = path7.join(AGENT_DIR, "version");
7036
7312
  const MAC_LABEL = "app.remotearc.agent";
7037
7313
  const WINDOWS_RUN_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
7038
7314
  const WINDOWS_RUN_VALUE = "Remote Arc Agent";
@@ -7047,35 +7323,35 @@ function createBackgroundController(options = {}) {
7047
7323
  return JSON.stringify(value).replaceAll("%", "%%");
7048
7324
  }
7049
7325
  async function ensureBundle(sourcePath, version) {
7050
- await fs6.mkdir(AGENT_DIR, { recursive: true });
7051
- await fs6.mkdir(LOG_DIR, { recursive: true });
7052
- if (path6.resolve(sourcePath) !== path6.resolve(AGENT_BUNDLE)) {
7326
+ await fs7.mkdir(AGENT_DIR, { recursive: true });
7327
+ await fs7.mkdir(LOG_DIR, { recursive: true });
7328
+ if (path7.resolve(sourcePath) !== path7.resolve(AGENT_BUNDLE)) {
7053
7329
  const staging = AGENT_BUNDLE + "." + process.pid + ".tmp";
7054
- await fs6.copyFile(sourcePath, staging);
7055
- await fs6.rename(staging, AGENT_BUNDLE);
7330
+ await fs7.copyFile(sourcePath, staging);
7331
+ await fs7.rename(staging, AGENT_BUNDLE);
7056
7332
  if (platform !== "win32") {
7057
- await fs6.chmod(AGENT_BUNDLE, 448).catch(() => void 0);
7333
+ await fs7.chmod(AGENT_BUNDLE, 448).catch(() => void 0);
7058
7334
  }
7059
7335
  }
7060
7336
  if (version) {
7061
- await fs6.writeFile(AGENT_VERSION_FILE, version + "\n", { mode: 384 });
7337
+ await fs7.writeFile(AGENT_VERSION_FILE, version + "\n", { mode: 384 });
7062
7338
  }
7063
7339
  }
7064
7340
  async function backgroundBundleVersion() {
7065
- return fs6.readFile(AGENT_VERSION_FILE, "utf8").then((value) => value.trim() || null).catch(() => null);
7341
+ return fs7.readFile(AGENT_VERSION_FILE, "utf8").then((value) => value.trim() || null).catch(() => null);
7066
7342
  }
7067
7343
  function macPlistPath() {
7068
- return path6.join(home, "Library", "LaunchAgents", MAC_LABEL + ".plist");
7344
+ return path7.join(home, "Library", "LaunchAgents", MAC_LABEL + ".plist");
7069
7345
  }
7070
7346
  function linuxUnitPath() {
7071
- return path6.join(home, ".config", "systemd", "user", LINUX_UNIT);
7347
+ return path7.join(home, ".config", "systemd", "user", LINUX_UNIT);
7072
7348
  }
7073
7349
  async function enableMac(sourcePath, preserveCurrent, version) {
7074
7350
  await ensureBundle(sourcePath, version);
7075
7351
  const plistPath = macPlistPath();
7076
- await fs6.mkdir(path6.dirname(plistPath), { recursive: true });
7077
- const stdoutPath = path6.join(LOG_DIR, "agent.log");
7078
- const stderrPath = path6.join(LOG_DIR, "agent-error.log");
7352
+ await fs7.mkdir(path7.dirname(plistPath), { recursive: true });
7353
+ const stdoutPath = path7.join(LOG_DIR, "agent.log");
7354
+ const stderrPath = path7.join(LOG_DIR, "agent-error.log");
7079
7355
  const plist = `<?xml version="1.0" encoding="UTF-8"?>
7080
7356
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
7081
7357
  <plist version="1.0">
@@ -7104,7 +7380,7 @@ function createBackgroundController(options = {}) {
7104
7380
  </dict>
7105
7381
  </plist>
7106
7382
  `;
7107
- await fs6.writeFile(plistPath, plist, { mode: 384 });
7383
+ await fs7.writeFile(plistPath, plist, { mode: 384 });
7108
7384
  const domain = `gui/${uid}`;
7109
7385
  const loaded = await runCommand(
7110
7386
  "launchctl",
@@ -7144,7 +7420,7 @@ function createBackgroundController(options = {}) {
7144
7420
  await runCommand("launchctl", ["disable", domain + "/" + MAC_LABEL], {
7145
7421
  ignoreFailure: true
7146
7422
  });
7147
- await fs6.rm(plistPath, { force: true });
7423
+ await fs7.rm(plistPath, { force: true });
7148
7424
  if (stopCurrent) {
7149
7425
  await runCommand("launchctl", ["bootout", domain + "/" + MAC_LABEL], {
7150
7426
  ignoreFailure: true
@@ -7154,7 +7430,7 @@ function createBackgroundController(options = {}) {
7154
7430
  }
7155
7431
  async function statusMac() {
7156
7432
  const plistPath = macPlistPath();
7157
- const installed = await fs6.access(plistPath).then(() => true).catch(() => false);
7433
+ const installed = await fs7.access(plistPath).then(() => true).catch(() => false);
7158
7434
  const domain = "gui/" + uid;
7159
7435
  const result = await runCommand(
7160
7436
  "launchctl",
@@ -7182,7 +7458,7 @@ function createBackgroundController(options = {}) {
7182
7458
  async function enableLinux(sourcePath, preserveCurrent, version) {
7183
7459
  await ensureBundle(sourcePath, version);
7184
7460
  const unitPath = linuxUnitPath();
7185
- await fs6.mkdir(path6.dirname(unitPath), { recursive: true });
7461
+ await fs7.mkdir(path7.dirname(unitPath), { recursive: true });
7186
7462
  const unit = `[Unit]
7187
7463
  Description=Remote Arc background agent
7188
7464
  After=network-online.target
@@ -7200,7 +7476,7 @@ Environment=${unitQuote("HOME=" + home)}
7200
7476
  [Install]
7201
7477
  WantedBy=default.target
7202
7478
  `;
7203
- await fs6.writeFile(unitPath, unit, { mode: 384 });
7479
+ await fs7.writeFile(unitPath, unit, { mode: 384 });
7204
7480
  await runCommand("systemctl", ["--user", "daemon-reload"]);
7205
7481
  await runCommand("systemctl", ["--user", "enable", "--now", LINUX_UNIT]);
7206
7482
  return backgroundAgentStatus2();
@@ -7211,7 +7487,7 @@ WantedBy=default.target
7211
7487
  stopCurrent ? ["--user", "disable", "--now", LINUX_UNIT] : ["--user", "disable", LINUX_UNIT],
7212
7488
  { ignoreFailure: true }
7213
7489
  );
7214
- await fs6.rm(linuxUnitPath(), { force: true });
7490
+ await fs7.rm(linuxUnitPath(), { force: true });
7215
7491
  if (stopCurrent) {
7216
7492
  await runCommand("systemctl", ["--user", "daemon-reload"], {
7217
7493
  ignoreFailure: true
@@ -7432,13 +7708,13 @@ var {
7432
7708
  disableBackgroundAgent
7433
7709
  } = createBackgroundController();
7434
7710
 
7435
- // src/index.ts
7436
- var VERSION = "0.4.7";
7711
+ // src/legacy.ts
7712
+ var VERSION = package_default.version;
7437
7713
  var DEFAULT_ORIGIN = "https://mcp.remotearc.app";
7438
- var CONFIG_DIR = path7.join(os4.homedir(), ".remotearc");
7439
- var CONFIG_PATH = path7.join(CONFIG_DIR, "config.json");
7440
- var LEGACY_CONFIG_PATH = path7.join(os4.homedir(), ".remote-link", "config.json");
7441
- var SELF_PATH = fileURLToPath(import.meta.url);
7714
+ var CONFIG_DIR = path8.join(os5.homedir(), ".remotearc");
7715
+ var CONFIG_PATH = path8.join(CONFIG_DIR, "config.json");
7716
+ var LEGACY_CONFIG_PATH = path8.join(os5.homedir(), ".remote-link", "config.json");
7717
+ var SELF_PATH = fileURLToPath2(import.meta.url);
7442
7718
  var RevokedDeviceCredentialError = class extends Error {
7443
7719
  constructor() {
7444
7720
  super("Saved device credential has been revoked.");
@@ -7552,7 +7828,7 @@ function logLine(level, message) {
7552
7828
  const icon = level === "success" ? green("\u2713") : level === "warn" ? yellow("!") : level === "error" ? red("\xD7") : level === "event" ? cyan("\u2192") : cyan("\u2022");
7553
7829
  process3.stdout.write(`${dim(nowTime())} ${icon} ${message}
7554
7830
  `);
7555
- appendAgentEvent(path7.join(CONFIG_DIR, "logs"), `${nowTime()} ${level} ${message}
7831
+ appendAgentEvent(path8.join(CONFIG_DIR, "logs"), `${nowTime()} ${level} ${message}
7556
7832
  `);
7557
7833
  }
7558
7834
  function banner() {
@@ -7575,11 +7851,11 @@ function modeLabel(mode) {
7575
7851
  }
7576
7852
  async function readConfig() {
7577
7853
  try {
7578
- return JSON.parse(await fs7.readFile(CONFIG_PATH, "utf8"));
7854
+ return JSON.parse(await fs8.readFile(CONFIG_PATH, "utf8"));
7579
7855
  } catch {
7580
7856
  try {
7581
7857
  const legacy = JSON.parse(
7582
- await fs7.readFile(LEGACY_CONFIG_PATH, "utf8")
7858
+ await fs8.readFile(LEGACY_CONFIG_PATH, "utf8")
7583
7859
  );
7584
7860
  await writeConfig(legacy);
7585
7861
  logLine("success", "Migrated existing Remote Link pairing to Remote Arc.");
@@ -7590,33 +7866,33 @@ async function readConfig() {
7590
7866
  }
7591
7867
  }
7592
7868
  async function writeConfig(config) {
7593
- await fs7.mkdir(CONFIG_DIR, { recursive: true, mode: 448 });
7594
- const staging = CONFIG_PATH + "." + randomUUID() + ".tmp";
7869
+ await fs8.mkdir(CONFIG_DIR, { recursive: true, mode: 448 });
7870
+ const staging = CONFIG_PATH + "." + randomUUID2() + ".tmp";
7595
7871
  try {
7596
- await fs7.writeFile(staging, JSON.stringify(config, null, 2) + "\n", { mode: 384 });
7597
- await fs7.rename(staging, CONFIG_PATH);
7872
+ await fs8.writeFile(staging, JSON.stringify(config, null, 2) + "\n", { mode: 384 });
7873
+ await fs8.rename(staging, CONFIG_PATH);
7598
7874
  } finally {
7599
- await fs7.rm(staging, { force: true });
7875
+ await fs8.rm(staging, { force: true });
7600
7876
  }
7601
7877
  }
7602
7878
  async function resetConfig() {
7603
7879
  await Promise.all([
7604
- fs7.rm(CONFIG_PATH, { force: true }),
7605
- fs7.rm(LEGACY_CONFIG_PATH, { force: true })
7880
+ fs8.rm(CONFIG_PATH, { force: true }),
7881
+ fs8.rm(LEGACY_CONFIG_PATH, { force: true })
7606
7882
  ]);
7607
7883
  logLine("success", "Removed saved device credentials.");
7608
7884
  }
7609
7885
  function openBrowser(url) {
7610
7886
  const command = process3.platform === "win32" ? "cmd" : process3.platform === "darwin" ? "open" : "xdg-open";
7611
7887
  const args = process3.platform === "win32" ? ["/c", "start", "", url] : [url];
7612
- const child = spawn5(command, args, {
7888
+ const child = spawn6(command, args, {
7613
7889
  detached: true,
7614
7890
  stdio: "ignore"
7615
7891
  });
7616
7892
  child.unref();
7617
7893
  }
7618
7894
  async function pair(origin, mode) {
7619
- const deviceName = os4.hostname();
7895
+ const deviceName = os5.hostname();
7620
7896
  const response = await fetch(origin + "/api/device/start", {
7621
7897
  method: "POST",
7622
7898
  headers: { "content-type": "application/json" },
@@ -7624,7 +7900,7 @@ async function pair(origin, mode) {
7624
7900
  device_name: deviceName,
7625
7901
  platform: process3.platform,
7626
7902
  arch: process3.arch,
7627
- hostname: os4.hostname()
7903
+ hostname: os5.hostname()
7628
7904
  })
7629
7905
  });
7630
7906
  if (!response.ok) {
@@ -7698,7 +7974,7 @@ async function connectAgent(config) {
7698
7974
  `Permission profile: ${isLocalSafeMode(config.mode) ? green("safe local cap") : cyan("dashboard-managed")}`
7699
7975
  );
7700
7976
  const tools = await core.tools();
7701
- const internalTools = ["background_agent_status", "set_background_agent", "set_task_keep_awake", "goal_workspace"];
7977
+ const internalTools = ["background_agent_status", "set_background_agent", "set_task_keep_awake", "goal_workspace", "agent_execution_log"];
7702
7978
  let keepAwake = createTaskKeepAwakeManager();
7703
7979
  logLine("success", `Local tools ready: ${tools.length} exposed`);
7704
7980
  process3.stdout.write(" " + dim(tools.map((tool) => tool.name).join(" \xB7 ")) + "\n");
@@ -7798,7 +8074,7 @@ async function connectAgent(config) {
7798
8074
  name: config.deviceName,
7799
8075
  platform: process3.platform,
7800
8076
  arch: process3.arch,
7801
- hostname: os4.hostname(),
8077
+ hostname: os5.hostname(),
7802
8078
  agentVersion: VERSION,
7803
8079
  pid: process3.pid,
7804
8080
  backgroundProcess: argFlag("--agent"),
@@ -7900,6 +8176,11 @@ async function connectAgent(config) {
7900
8176
  enabled: status.enabled,
7901
8177
  desired_enabled: config.backgroundEnabled ?? null
7902
8178
  };
8179
+ } else if (message.tool === "agent_execution_log") {
8180
+ result = await readAgentEventTail(
8181
+ path8.join(CONFIG_DIR, "logs"),
8182
+ Number(message.arguments?.limit || 100)
8183
+ );
7903
8184
  } else if (message.tool === "set_background_agent") {
7904
8185
  const enabled = message.arguments?.enabled;
7905
8186
  if (typeof enabled !== "boolean") {
@@ -8021,6 +8302,8 @@ async function main() {
8021
8302
  " npx remotelink",
8022
8303
  "",
8023
8304
  "Options:",
8305
+ " --go Select the complete native Go device runtime",
8306
+ " --ts Select the TS device runtime (transition default)",
8024
8307
  " --safe Hard local read-only cap; dashboard cannot enable write tools",
8025
8308
  " --developer Legacy alias for dashboard-managed capabilities",
8026
8309
  " --foreground Stay attached without installing or repairing recovery",
@@ -8083,7 +8366,7 @@ async function main() {
8083
8366
  }
8084
8367
  logLine("info", `Using paired device identity ${dim(config.deviceId.slice(0, 8))}\u2026`);
8085
8368
  if (supervisorMode) {
8086
- const release2 = await tryAgentLease(path7.join(CONFIG_DIR, "agent"), "supervisor");
8369
+ const release2 = await tryAgentLease(path8.join(CONFIG_DIR, "agent"), "supervisor");
8087
8370
  if (!release2) return;
8088
8371
  const abort2 = new AbortController();
8089
8372
  const stop = () => abort2.abort();
@@ -8093,7 +8376,7 @@ async function main() {
8093
8376
  await superviseAgent({
8094
8377
  enabled: async () => (await readConfig())?.backgroundEnabled === true,
8095
8378
  signal: abort2.signal,
8096
- start: () => startSupervisedAgent(process3.execPath, SELF_PATH, path7.join(CONFIG_DIR, "logs"))
8379
+ start: () => startSupervisedAgent(process3.execPath, SELF_PATH, path8.join(CONFIG_DIR, "logs"))
8097
8380
  });
8098
8381
  } finally {
8099
8382
  process3.off("SIGINT", stop);
@@ -8154,7 +8437,7 @@ async function main() {
8154
8437
  try {
8155
8438
  while (!abort.signal.aborted && !release) {
8156
8439
  if (agentMode && (await readConfig())?.backgroundEnabled !== true) return;
8157
- release = await tryAgentLease(path7.join(CONFIG_DIR, "agent"));
8440
+ release = await tryAgentLease(path8.join(CONFIG_DIR, "agent"));
8158
8441
  if (release) break;
8159
8442
  if (!agentMode && (argFlag("--safe") || argFlag("--developer"))) {
8160
8443
  logLine("error", "Another Agent owns execution. Stop it locally before changing the local permission profile.");
@@ -8166,7 +8449,7 @@ async function main() {
8166
8449
  logLine("info", "An Agent already owns execution. Following its operation log; Ctrl+C closes this viewer.");
8167
8450
  announced = true;
8168
8451
  }
8169
- const events = await readAgentEvents(path7.join(CONFIG_DIR, "logs"), cursor);
8452
+ const events = await readAgentEvents(path8.join(CONFIG_DIR, "logs"), cursor);
8170
8453
  cursor = events.cursor;
8171
8454
  if (events.text) process3.stdout.write(events.text);
8172
8455
  if (Date.now() - lastApprovalPoll >= 4e3) {
@@ -8196,11 +8479,28 @@ async function main() {
8196
8479
  config = null;
8197
8480
  }
8198
8481
  }
8199
- main().catch((error) => {
8200
- logLine(
8201
- "error",
8202
- "Fatal: " + (error instanceof Error ? error.message : String(error))
8482
+ async function runLegacy() {
8483
+ await main();
8484
+ }
8485
+
8486
+ // src/index.ts
8487
+ async function main2() {
8488
+ const args = process.argv.slice(2);
8489
+ if (args.includes("--go") && args.includes("--ts"))
8490
+ throw new Error("Choose one agent runtime: --go or --ts.");
8491
+ const go = args.includes("--go");
8492
+ const forwarded = args.filter(
8493
+ (argument) => argument !== "--go" && argument !== "--ts"
8494
+ );
8495
+ if (go) return launchGo(forwarded);
8496
+ await assertTSOwnership(forwarded);
8497
+ process.argv = [...process.argv.slice(0, 2), ...forwarded];
8498
+ await runLegacy();
8499
+ }
8500
+ main2().catch((error) => {
8501
+ process.stderr.write(
8502
+ "Remote Arc: " + (error instanceof Error ? error.message : String(error)) + "\n"
8203
8503
  );
8204
- process3.exit(1);
8504
+ process.exitCode = 1;
8205
8505
  });
8206
8506
  //# sourceMappingURL=index.js.map