agentapprove 0.1.44 → 0.1.56
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/README.md +55 -0
- package/dist/cli.js +764 -494
- package/package.json +1 -2
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
2
|
var __create = Object.create;
|
|
4
3
|
var __getProtoOf = Object.getPrototypeOf;
|
|
5
4
|
var __defProp = Object.defineProperty;
|
|
@@ -19,22 +18,23 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
19
18
|
return cached;
|
|
20
19
|
}
|
|
21
20
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
22
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
if (mod && typeof mod === "object" || typeof mod === "function") {
|
|
23
|
+
for (let key of __getOwnPropNames(mod))
|
|
24
|
+
if (!__hasOwnProp.call(to, key))
|
|
25
|
+
__defProp(to, key, {
|
|
26
|
+
get: __accessProp.bind(mod, key),
|
|
27
|
+
enumerable: true
|
|
28
|
+
});
|
|
29
|
+
}
|
|
29
30
|
if (canCache)
|
|
30
31
|
cache.set(mod, to);
|
|
31
32
|
return to;
|
|
32
33
|
};
|
|
33
34
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
34
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
35
35
|
|
|
36
36
|
// ../../node_modules/.bun/sisteransi@1.0.5/node_modules/sisteransi/src/index.js
|
|
37
|
-
var require_src = __commonJS((exports, module)
|
|
37
|
+
var require_src = __commonJS(function(exports, module) {
|
|
38
38
|
var ESC = "\x1B";
|
|
39
39
|
var CSI = `${ESC}[`;
|
|
40
40
|
var beep = "\x07";
|
|
@@ -92,7 +92,7 @@ var require_src = __commonJS((exports, module) => {
|
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
// ../../node_modules/.bun/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
95
|
-
var require_picocolors = __commonJS((exports, module)
|
|
95
|
+
var require_picocolors = __commonJS(function(exports, module) {
|
|
96
96
|
var p = process || {};
|
|
97
97
|
var argv = p.argv || [];
|
|
98
98
|
var env = p.env || {};
|
|
@@ -162,7 +162,7 @@ var require_picocolors = __commonJS((exports, module) => {
|
|
|
162
162
|
});
|
|
163
163
|
|
|
164
164
|
// ../../node_modules/.bun/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/vendor/QRCode/QRMode.js
|
|
165
|
-
var require_QRMode = __commonJS((exports, module)
|
|
165
|
+
var require_QRMode = __commonJS(function(exports, module) {
|
|
166
166
|
module.exports = {
|
|
167
167
|
MODE_NUMBER: 1 << 0,
|
|
168
168
|
MODE_ALPHA_NUM: 1 << 1,
|
|
@@ -172,7 +172,7 @@ var require_QRMode = __commonJS((exports, module) => {
|
|
|
172
172
|
});
|
|
173
173
|
|
|
174
174
|
// ../../node_modules/.bun/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/vendor/QRCode/QR8bitByte.js
|
|
175
|
-
var require_QR8bitByte = __commonJS((exports, module)
|
|
175
|
+
var require_QR8bitByte = __commonJS(function(exports, module) {
|
|
176
176
|
var QRMode = require_QRMode();
|
|
177
177
|
function QR8bitByte(data) {
|
|
178
178
|
this.mode = QRMode.MODE_8BIT_BYTE;
|
|
@@ -192,7 +192,7 @@ var require_QR8bitByte = __commonJS((exports, module) => {
|
|
|
192
192
|
});
|
|
193
193
|
|
|
194
194
|
// ../../node_modules/.bun/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/vendor/QRCode/QRMath.js
|
|
195
|
-
var require_QRMath = __commonJS((exports, module)
|
|
195
|
+
var require_QRMath = __commonJS(function(exports, module) {
|
|
196
196
|
var QRMath = {
|
|
197
197
|
glog: function(n) {
|
|
198
198
|
if (n < 1) {
|
|
@@ -228,7 +228,7 @@ var require_QRMath = __commonJS((exports, module) => {
|
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
// ../../node_modules/.bun/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/vendor/QRCode/QRPolynomial.js
|
|
231
|
-
var require_QRPolynomial = __commonJS((exports, module)
|
|
231
|
+
var require_QRPolynomial = __commonJS(function(exports, module) {
|
|
232
232
|
var QRMath = require_QRMath();
|
|
233
233
|
function QRPolynomial(num, shift) {
|
|
234
234
|
if (num.length === undefined) {
|
|
@@ -250,35 +250,35 @@ var require_QRPolynomial = __commonJS((exports, module) => {
|
|
|
250
250
|
getLength: function() {
|
|
251
251
|
return this.num.length;
|
|
252
252
|
},
|
|
253
|
-
multiply: function(
|
|
254
|
-
var num = new Array(this.getLength() +
|
|
253
|
+
multiply: function(e) {
|
|
254
|
+
var num = new Array(this.getLength() + e.getLength() - 1);
|
|
255
255
|
for (var i = 0;i < this.getLength(); i++) {
|
|
256
|
-
for (var
|
|
257
|
-
num[i +
|
|
256
|
+
for (var j = 0;j < e.getLength(); j++) {
|
|
257
|
+
num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i)) + QRMath.glog(e.get(j)));
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
260
|
return new QRPolynomial(num, 0);
|
|
261
261
|
},
|
|
262
|
-
mod: function(
|
|
263
|
-
if (this.getLength() -
|
|
262
|
+
mod: function(e) {
|
|
263
|
+
if (this.getLength() - e.getLength() < 0) {
|
|
264
264
|
return this;
|
|
265
265
|
}
|
|
266
|
-
var ratio = QRMath.glog(this.get(0)) - QRMath.glog(
|
|
266
|
+
var ratio = QRMath.glog(this.get(0)) - QRMath.glog(e.get(0));
|
|
267
267
|
var num = new Array(this.getLength());
|
|
268
268
|
for (var i = 0;i < this.getLength(); i++) {
|
|
269
269
|
num[i] = this.get(i);
|
|
270
270
|
}
|
|
271
|
-
for (var
|
|
272
|
-
num[
|
|
271
|
+
for (var x = 0;x < e.getLength(); x++) {
|
|
272
|
+
num[x] ^= QRMath.gexp(QRMath.glog(e.get(x)) + ratio);
|
|
273
273
|
}
|
|
274
|
-
return new QRPolynomial(num, 0).mod(
|
|
274
|
+
return new QRPolynomial(num, 0).mod(e);
|
|
275
275
|
}
|
|
276
276
|
};
|
|
277
277
|
module.exports = QRPolynomial;
|
|
278
278
|
});
|
|
279
279
|
|
|
280
280
|
// ../../node_modules/.bun/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/vendor/QRCode/QRMaskPattern.js
|
|
281
|
-
var require_QRMaskPattern = __commonJS((exports, module)
|
|
281
|
+
var require_QRMaskPattern = __commonJS(function(exports, module) {
|
|
282
282
|
module.exports = {
|
|
283
283
|
PATTERN000: 0,
|
|
284
284
|
PATTERN001: 1,
|
|
@@ -292,7 +292,7 @@ var require_QRMaskPattern = __commonJS((exports, module) => {
|
|
|
292
292
|
});
|
|
293
293
|
|
|
294
294
|
// ../../node_modules/.bun/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/vendor/QRCode/QRUtil.js
|
|
295
|
-
var require_QRUtil = __commonJS((exports, module)
|
|
295
|
+
var require_QRUtil = __commonJS(function(exports, module) {
|
|
296
296
|
var QRMode = require_QRMode();
|
|
297
297
|
var QRPolynomial = require_QRPolynomial();
|
|
298
298
|
var QRMath = require_QRMath();
|
|
@@ -344,18 +344,18 @@ var require_QRUtil = __commonJS((exports, module) => {
|
|
|
344
344
|
G18: 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0,
|
|
345
345
|
G15_MASK: 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1,
|
|
346
346
|
getBCHTypeInfo: function(data) {
|
|
347
|
-
var
|
|
348
|
-
while (QRUtil.getBCHDigit(
|
|
349
|
-
|
|
347
|
+
var d = data << 10;
|
|
348
|
+
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
|
|
349
|
+
d ^= QRUtil.G15 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15);
|
|
350
350
|
}
|
|
351
|
-
return (data << 10 |
|
|
351
|
+
return (data << 10 | d) ^ QRUtil.G15_MASK;
|
|
352
352
|
},
|
|
353
353
|
getBCHTypeNumber: function(data) {
|
|
354
|
-
var
|
|
355
|
-
while (QRUtil.getBCHDigit(
|
|
356
|
-
|
|
354
|
+
var d = data << 12;
|
|
355
|
+
while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
|
|
356
|
+
d ^= QRUtil.G18 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18);
|
|
357
357
|
}
|
|
358
|
-
return data << 12 |
|
|
358
|
+
return data << 12 | d;
|
|
359
359
|
},
|
|
360
360
|
getBCHDigit: function(data) {
|
|
361
361
|
var digit = 0;
|
|
@@ -368,34 +368,34 @@ var require_QRUtil = __commonJS((exports, module) => {
|
|
|
368
368
|
getPatternPosition: function(typeNumber) {
|
|
369
369
|
return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];
|
|
370
370
|
},
|
|
371
|
-
getMask: function(maskPattern, i,
|
|
371
|
+
getMask: function(maskPattern, i, j) {
|
|
372
372
|
switch (maskPattern) {
|
|
373
373
|
case QRMaskPattern.PATTERN000:
|
|
374
|
-
return (i +
|
|
374
|
+
return (i + j) % 2 === 0;
|
|
375
375
|
case QRMaskPattern.PATTERN001:
|
|
376
376
|
return i % 2 === 0;
|
|
377
377
|
case QRMaskPattern.PATTERN010:
|
|
378
|
-
return
|
|
378
|
+
return j % 3 === 0;
|
|
379
379
|
case QRMaskPattern.PATTERN011:
|
|
380
|
-
return (i +
|
|
380
|
+
return (i + j) % 3 === 0;
|
|
381
381
|
case QRMaskPattern.PATTERN100:
|
|
382
|
-
return (Math.floor(i / 2) + Math.floor(
|
|
382
|
+
return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
|
|
383
383
|
case QRMaskPattern.PATTERN101:
|
|
384
|
-
return i *
|
|
384
|
+
return i * j % 2 + i * j % 3 === 0;
|
|
385
385
|
case QRMaskPattern.PATTERN110:
|
|
386
|
-
return (i *
|
|
386
|
+
return (i * j % 2 + i * j % 3) % 2 === 0;
|
|
387
387
|
case QRMaskPattern.PATTERN111:
|
|
388
|
-
return (i *
|
|
388
|
+
return (i * j % 3 + (i + j) % 2) % 2 === 0;
|
|
389
389
|
default:
|
|
390
390
|
throw new Error("bad maskPattern:" + maskPattern);
|
|
391
391
|
}
|
|
392
392
|
},
|
|
393
393
|
getErrorCorrectPolynomial: function(errorCorrectLength) {
|
|
394
|
-
var
|
|
394
|
+
var a = new QRPolynomial([1], 0);
|
|
395
395
|
for (var i = 0;i < errorCorrectLength; i++) {
|
|
396
|
-
|
|
396
|
+
a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0));
|
|
397
397
|
}
|
|
398
|
-
return
|
|
398
|
+
return a;
|
|
399
399
|
},
|
|
400
400
|
getLengthInBits: function(mode, type) {
|
|
401
401
|
if (1 <= type && type < 10) {
|
|
@@ -450,18 +450,18 @@ var require_QRUtil = __commonJS((exports, module) => {
|
|
|
450
450
|
for (col = 0;col < moduleCount; col++) {
|
|
451
451
|
var sameCount = 0;
|
|
452
452
|
var dark = qrCode.isDark(row, col);
|
|
453
|
-
for (var
|
|
454
|
-
if (row +
|
|
453
|
+
for (var r = -1;r <= 1; r++) {
|
|
454
|
+
if (row + r < 0 || moduleCount <= row + r) {
|
|
455
455
|
continue;
|
|
456
456
|
}
|
|
457
457
|
for (var c = -1;c <= 1; c++) {
|
|
458
458
|
if (col + c < 0 || moduleCount <= col + c) {
|
|
459
459
|
continue;
|
|
460
460
|
}
|
|
461
|
-
if (
|
|
461
|
+
if (r === 0 && c === 0) {
|
|
462
462
|
continue;
|
|
463
463
|
}
|
|
464
|
-
if (dark === qrCode.isDark(row +
|
|
464
|
+
if (dark === qrCode.isDark(row + r, col + c)) {
|
|
465
465
|
sameCount++;
|
|
466
466
|
}
|
|
467
467
|
}
|
|
@@ -518,7 +518,7 @@ var require_QRUtil = __commonJS((exports, module) => {
|
|
|
518
518
|
});
|
|
519
519
|
|
|
520
520
|
// ../../node_modules/.bun/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js
|
|
521
|
-
var require_QRErrorCorrectLevel = __commonJS((exports, module)
|
|
521
|
+
var require_QRErrorCorrectLevel = __commonJS(function(exports, module) {
|
|
522
522
|
module.exports = {
|
|
523
523
|
L: 1,
|
|
524
524
|
M: 0,
|
|
@@ -528,7 +528,7 @@ var require_QRErrorCorrectLevel = __commonJS((exports, module) => {
|
|
|
528
528
|
});
|
|
529
529
|
|
|
530
530
|
// ../../node_modules/.bun/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/vendor/QRCode/QRRSBlock.js
|
|
531
|
-
var require_QRRSBlock = __commonJS((exports, module)
|
|
531
|
+
var require_QRRSBlock = __commonJS(function(exports, module) {
|
|
532
532
|
var QRErrorCorrectLevel = require_QRErrorCorrectLevel();
|
|
533
533
|
function QRRSBlock(totalCount, dataCount) {
|
|
534
534
|
this.totalCount = totalCount;
|
|
@@ -707,7 +707,7 @@ var require_QRRSBlock = __commonJS((exports, module) => {
|
|
|
707
707
|
var count = rsBlock[i * 3 + 0];
|
|
708
708
|
var totalCount = rsBlock[i * 3 + 1];
|
|
709
709
|
var dataCount = rsBlock[i * 3 + 2];
|
|
710
|
-
for (var
|
|
710
|
+
for (var j = 0;j < count; j++) {
|
|
711
711
|
list.push(new QRRSBlock(totalCount, dataCount));
|
|
712
712
|
}
|
|
713
713
|
}
|
|
@@ -731,7 +731,7 @@ var require_QRRSBlock = __commonJS((exports, module) => {
|
|
|
731
731
|
});
|
|
732
732
|
|
|
733
733
|
// ../../node_modules/.bun/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/vendor/QRCode/QRBitBuffer.js
|
|
734
|
-
var require_QRBitBuffer = __commonJS((exports, module)
|
|
734
|
+
var require_QRBitBuffer = __commonJS(function(exports, module) {
|
|
735
735
|
function QRBitBuffer() {
|
|
736
736
|
this.buffer = [];
|
|
737
737
|
this.length = 0;
|
|
@@ -764,7 +764,7 @@ var require_QRBitBuffer = __commonJS((exports, module) => {
|
|
|
764
764
|
});
|
|
765
765
|
|
|
766
766
|
// ../../node_modules/.bun/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/vendor/QRCode/index.js
|
|
767
|
-
var require_QRCode = __commonJS((exports, module)
|
|
767
|
+
var require_QRCode = __commonJS(function(exports, module) {
|
|
768
768
|
var QR8bitByte = require_QR8bitByte();
|
|
769
769
|
var QRUtil = require_QRUtil();
|
|
770
770
|
var QRPolynomial = require_QRPolynomial();
|
|
@@ -803,8 +803,8 @@ var require_QRCode = __commonJS((exports, module) => {
|
|
|
803
803
|
for (var i = 0;i < rsBlocks.length; i++) {
|
|
804
804
|
totalDataCount += rsBlocks[i].dataCount;
|
|
805
805
|
}
|
|
806
|
-
for (var
|
|
807
|
-
var data = this.dataList[
|
|
806
|
+
for (var x = 0;x < this.dataList.length; x++) {
|
|
807
|
+
var data = this.dataList[x];
|
|
808
808
|
buffer.put(data.mode, 4);
|
|
809
809
|
buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber));
|
|
810
810
|
data.write(buffer);
|
|
@@ -840,16 +840,16 @@ var require_QRCode = __commonJS((exports, module) => {
|
|
|
840
840
|
this.mapData(this.dataCache, maskPattern);
|
|
841
841
|
},
|
|
842
842
|
setupPositionProbePattern: function(row, col) {
|
|
843
|
-
for (var
|
|
844
|
-
if (row +
|
|
843
|
+
for (var r = -1;r <= 7; r++) {
|
|
844
|
+
if (row + r <= -1 || this.moduleCount <= row + r)
|
|
845
845
|
continue;
|
|
846
846
|
for (var c = -1;c <= 7; c++) {
|
|
847
847
|
if (col + c <= -1 || this.moduleCount <= col + c)
|
|
848
848
|
continue;
|
|
849
|
-
if (0 <=
|
|
850
|
-
this.modules[row +
|
|
849
|
+
if (0 <= r && r <= 6 && (c === 0 || c === 6) || 0 <= c && c <= 6 && (r === 0 || r === 6) || 2 <= r && r <= 4 && 2 <= c && c <= 4) {
|
|
850
|
+
this.modules[row + r][col + c] = true;
|
|
851
851
|
} else {
|
|
852
|
-
this.modules[row +
|
|
852
|
+
this.modules[row + r][col + c] = false;
|
|
853
853
|
}
|
|
854
854
|
}
|
|
855
855
|
}
|
|
@@ -872,16 +872,16 @@ var require_QRCode = __commonJS((exports, module) => {
|
|
|
872
872
|
var cs = 1;
|
|
873
873
|
this.make();
|
|
874
874
|
for (var row = 0;row < this.modules.length; row++) {
|
|
875
|
-
var
|
|
875
|
+
var y = row * cs;
|
|
876
876
|
for (var col = 0;col < this.modules[row].length; col++) {
|
|
877
|
-
var
|
|
877
|
+
var x = col * cs;
|
|
878
878
|
var dark = this.modules[row][col];
|
|
879
879
|
if (dark) {
|
|
880
880
|
qr_mc.beginFill(0, 100);
|
|
881
|
-
qr_mc.moveTo(
|
|
882
|
-
qr_mc.lineTo(
|
|
883
|
-
qr_mc.lineTo(
|
|
884
|
-
qr_mc.lineTo(
|
|
881
|
+
qr_mc.moveTo(x, y);
|
|
882
|
+
qr_mc.lineTo(x + cs, y);
|
|
883
|
+
qr_mc.lineTo(x + cs, y + cs);
|
|
884
|
+
qr_mc.lineTo(x, y + cs);
|
|
885
885
|
qr_mc.endFill();
|
|
886
886
|
}
|
|
887
887
|
}
|
|
@@ -889,11 +889,11 @@ var require_QRCode = __commonJS((exports, module) => {
|
|
|
889
889
|
return qr_mc;
|
|
890
890
|
},
|
|
891
891
|
setupTimingPattern: function() {
|
|
892
|
-
for (var
|
|
893
|
-
if (this.modules[
|
|
892
|
+
for (var r = 8;r < this.moduleCount - 8; r++) {
|
|
893
|
+
if (this.modules[r][6] !== null) {
|
|
894
894
|
continue;
|
|
895
895
|
}
|
|
896
|
-
this.modules[
|
|
896
|
+
this.modules[r][6] = r % 2 === 0;
|
|
897
897
|
}
|
|
898
898
|
for (var c = 8;c < this.moduleCount - 8; c++) {
|
|
899
899
|
if (this.modules[6][c] !== null) {
|
|
@@ -905,18 +905,18 @@ var require_QRCode = __commonJS((exports, module) => {
|
|
|
905
905
|
setupPositionAdjustPattern: function() {
|
|
906
906
|
var pos = QRUtil.getPatternPosition(this.typeNumber);
|
|
907
907
|
for (var i = 0;i < pos.length; i++) {
|
|
908
|
-
for (var
|
|
908
|
+
for (var j = 0;j < pos.length; j++) {
|
|
909
909
|
var row = pos[i];
|
|
910
|
-
var col = pos[
|
|
910
|
+
var col = pos[j];
|
|
911
911
|
if (this.modules[row][col] !== null) {
|
|
912
912
|
continue;
|
|
913
913
|
}
|
|
914
|
-
for (var
|
|
914
|
+
for (var r = -2;r <= 2; r++) {
|
|
915
915
|
for (var c = -2;c <= 2; c++) {
|
|
916
|
-
if (Math.abs(
|
|
917
|
-
this.modules[row +
|
|
916
|
+
if (Math.abs(r) === 2 || Math.abs(c) === 2 || r === 0 && c === 0) {
|
|
917
|
+
this.modules[row + r][col + c] = true;
|
|
918
918
|
} else {
|
|
919
|
-
this.modules[row +
|
|
919
|
+
this.modules[row + r][col + c] = false;
|
|
920
920
|
}
|
|
921
921
|
}
|
|
922
922
|
}
|
|
@@ -930,33 +930,33 @@ var require_QRCode = __commonJS((exports, module) => {
|
|
|
930
930
|
mod = !test && (bits >> i & 1) === 1;
|
|
931
931
|
this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod;
|
|
932
932
|
}
|
|
933
|
-
for (var
|
|
934
|
-
mod = !test && (bits >>
|
|
935
|
-
this.modules[
|
|
933
|
+
for (var x = 0;x < 18; x++) {
|
|
934
|
+
mod = !test && (bits >> x & 1) === 1;
|
|
935
|
+
this.modules[x % 3 + this.moduleCount - 8 - 3][Math.floor(x / 3)] = mod;
|
|
936
936
|
}
|
|
937
937
|
},
|
|
938
938
|
setupTypeInfo: function(test, maskPattern) {
|
|
939
939
|
var data = this.errorCorrectLevel << 3 | maskPattern;
|
|
940
940
|
var bits = QRUtil.getBCHTypeInfo(data);
|
|
941
941
|
var mod;
|
|
942
|
-
for (var
|
|
943
|
-
mod = !test && (bits >>
|
|
944
|
-
if (
|
|
945
|
-
this.modules[
|
|
946
|
-
} else if (
|
|
947
|
-
this.modules[
|
|
942
|
+
for (var v = 0;v < 15; v++) {
|
|
943
|
+
mod = !test && (bits >> v & 1) === 1;
|
|
944
|
+
if (v < 6) {
|
|
945
|
+
this.modules[v][8] = mod;
|
|
946
|
+
} else if (v < 8) {
|
|
947
|
+
this.modules[v + 1][8] = mod;
|
|
948
948
|
} else {
|
|
949
|
-
this.modules[this.moduleCount - 15 +
|
|
949
|
+
this.modules[this.moduleCount - 15 + v][8] = mod;
|
|
950
950
|
}
|
|
951
951
|
}
|
|
952
|
-
for (var
|
|
953
|
-
mod = !test && (bits >>
|
|
954
|
-
if (
|
|
955
|
-
this.modules[8][this.moduleCount -
|
|
956
|
-
} else if (
|
|
957
|
-
this.modules[8][15 -
|
|
952
|
+
for (var h = 0;h < 15; h++) {
|
|
953
|
+
mod = !test && (bits >> h & 1) === 1;
|
|
954
|
+
if (h < 8) {
|
|
955
|
+
this.modules[8][this.moduleCount - h - 1] = mod;
|
|
956
|
+
} else if (h < 9) {
|
|
957
|
+
this.modules[8][15 - h - 1 + 1] = mod;
|
|
958
958
|
} else {
|
|
959
|
-
this.modules[8][15 -
|
|
959
|
+
this.modules[8][15 - h - 1] = mod;
|
|
960
960
|
}
|
|
961
961
|
}
|
|
962
962
|
this.modules[this.moduleCount - 8][8] = !test;
|
|
@@ -1010,8 +1010,8 @@ var require_QRCode = __commonJS((exports, module) => {
|
|
|
1010
1010
|
data.write(buffer);
|
|
1011
1011
|
}
|
|
1012
1012
|
var totalDataCount = 0;
|
|
1013
|
-
for (var
|
|
1014
|
-
totalDataCount += rsBlocks[
|
|
1013
|
+
for (var x = 0;x < rsBlocks.length; x++) {
|
|
1014
|
+
totalDataCount += rsBlocks[x].dataCount;
|
|
1015
1015
|
}
|
|
1016
1016
|
if (buffer.getLengthInBits() > totalDataCount * 8) {
|
|
1017
1017
|
throw new Error("code length overflow. (" + buffer.getLengthInBits() + ">" + totalDataCount * 8 + ")");
|
|
@@ -1040,35 +1040,35 @@ var require_QRCode = __commonJS((exports, module) => {
|
|
|
1040
1040
|
var maxEcCount = 0;
|
|
1041
1041
|
var dcdata = new Array(rsBlocks.length);
|
|
1042
1042
|
var ecdata = new Array(rsBlocks.length);
|
|
1043
|
-
for (var
|
|
1044
|
-
var dcCount = rsBlocks[
|
|
1045
|
-
var ecCount = rsBlocks[
|
|
1043
|
+
for (var r = 0;r < rsBlocks.length; r++) {
|
|
1044
|
+
var dcCount = rsBlocks[r].dataCount;
|
|
1045
|
+
var ecCount = rsBlocks[r].totalCount - dcCount;
|
|
1046
1046
|
maxDcCount = Math.max(maxDcCount, dcCount);
|
|
1047
1047
|
maxEcCount = Math.max(maxEcCount, ecCount);
|
|
1048
|
-
dcdata[
|
|
1049
|
-
for (var i = 0;i < dcdata[
|
|
1050
|
-
dcdata[
|
|
1048
|
+
dcdata[r] = new Array(dcCount);
|
|
1049
|
+
for (var i = 0;i < dcdata[r].length; i++) {
|
|
1050
|
+
dcdata[r][i] = 255 & buffer.buffer[i + offset];
|
|
1051
1051
|
}
|
|
1052
1052
|
offset += dcCount;
|
|
1053
1053
|
var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
|
|
1054
|
-
var rawPoly = new QRPolynomial(dcdata[
|
|
1054
|
+
var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
|
|
1055
1055
|
var modPoly = rawPoly.mod(rsPoly);
|
|
1056
|
-
ecdata[
|
|
1057
|
-
for (var
|
|
1058
|
-
var modIndex =
|
|
1059
|
-
ecdata[
|
|
1056
|
+
ecdata[r] = new Array(rsPoly.getLength() - 1);
|
|
1057
|
+
for (var x = 0;x < ecdata[r].length; x++) {
|
|
1058
|
+
var modIndex = x + modPoly.getLength() - ecdata[r].length;
|
|
1059
|
+
ecdata[r][x] = modIndex >= 0 ? modPoly.get(modIndex) : 0;
|
|
1060
1060
|
}
|
|
1061
1061
|
}
|
|
1062
1062
|
var totalCodeCount = 0;
|
|
1063
|
-
for (var
|
|
1064
|
-
totalCodeCount += rsBlocks[
|
|
1063
|
+
for (var y = 0;y < rsBlocks.length; y++) {
|
|
1064
|
+
totalCodeCount += rsBlocks[y].totalCount;
|
|
1065
1065
|
}
|
|
1066
1066
|
var data = new Array(totalCodeCount);
|
|
1067
1067
|
var index = 0;
|
|
1068
|
-
for (var
|
|
1068
|
+
for (var z = 0;z < maxDcCount; z++) {
|
|
1069
1069
|
for (var s = 0;s < rsBlocks.length; s++) {
|
|
1070
|
-
if (
|
|
1071
|
-
data[index++] = dcdata[s][
|
|
1070
|
+
if (z < dcdata[s].length) {
|
|
1071
|
+
data[index++] = dcdata[s][z];
|
|
1072
1072
|
}
|
|
1073
1073
|
}
|
|
1074
1074
|
}
|
|
@@ -1085,7 +1085,7 @@ var require_QRCode = __commonJS((exports, module) => {
|
|
|
1085
1085
|
});
|
|
1086
1086
|
|
|
1087
1087
|
// ../../node_modules/.bun/qrcode-terminal@0.12.0/node_modules/qrcode-terminal/lib/main.js
|
|
1088
|
-
var require_main = __commonJS((exports, module)
|
|
1088
|
+
var require_main = __commonJS(function(exports, module) {
|
|
1089
1089
|
var QRCode = require_QRCode();
|
|
1090
1090
|
var QRErrorCorrectLevel = require_QRErrorCorrectLevel();
|
|
1091
1091
|
var black = "\x1B[40m \x1B[0m";
|
|
@@ -1159,9 +1159,9 @@ var require_main = __commonJS((exports, module) => {
|
|
|
1159
1159
|
var border = repeat(white).times(qrcode.getModuleCount() + 3);
|
|
1160
1160
|
output += border + `
|
|
1161
1161
|
`;
|
|
1162
|
-
qrcode.modules.forEach(function(
|
|
1162
|
+
qrcode.modules.forEach(function(row) {
|
|
1163
1163
|
output += white;
|
|
1164
|
-
output +=
|
|
1164
|
+
output += row.map(toCell).join("");
|
|
1165
1165
|
output += white + `
|
|
1166
1166
|
`;
|
|
1167
1167
|
});
|
|
@@ -1636,13 +1636,13 @@ var y2 = (s) => {
|
|
|
1636
1636
|
}
|
|
1637
1637
|
};
|
|
1638
1638
|
var E = (s) => {
|
|
1639
|
-
const { cursor: n, options: t, style: i } = s,
|
|
1640
|
-
let
|
|
1641
|
-
n >=
|
|
1642
|
-
const
|
|
1643
|
-
return t.slice(
|
|
1644
|
-
const
|
|
1645
|
-
return
|
|
1639
|
+
const { cursor: n, options: t, style: i } = s, r = s.maxItems ?? 1 / 0, o = Math.max(process.stdout.rows - 4, 0), c = Math.min(o, Math.max(r, 5));
|
|
1640
|
+
let l = 0;
|
|
1641
|
+
n >= l + c - 3 ? l = Math.max(Math.min(n - c + 3, t.length - c), 0) : n < l + 2 && (l = Math.max(n - 2, 0));
|
|
1642
|
+
const d = c < t.length && l > 0, p = c < t.length && l + c < t.length;
|
|
1643
|
+
return t.slice(l, l + c).map((S, f, x) => {
|
|
1644
|
+
const g = f === 0 && d, m = f === x.length - 1 && p;
|
|
1645
|
+
return g || m ? import_picocolors.default.dim("...") : i(S, f + l === n);
|
|
1646
1646
|
});
|
|
1647
1647
|
};
|
|
1648
1648
|
var ce = (s) => {
|
|
@@ -1650,12 +1650,12 @@ var ce = (s) => {
|
|
|
1650
1650
|
return new BD({ active: n, inactive: t, initialValue: s.initialValue ?? true, render() {
|
|
1651
1651
|
const i = `${import_picocolors.default.gray(a2)}
|
|
1652
1652
|
${y2(this.state)} ${s.message}
|
|
1653
|
-
`,
|
|
1653
|
+
`, r = this.value ? n : t;
|
|
1654
1654
|
switch (this.state) {
|
|
1655
1655
|
case "submit":
|
|
1656
|
-
return `${i}${import_picocolors.default.gray(a2)} ${import_picocolors.default.dim(
|
|
1656
|
+
return `${i}${import_picocolors.default.gray(a2)} ${import_picocolors.default.dim(r)}`;
|
|
1657
1657
|
case "cancel":
|
|
1658
|
-
return `${i}${import_picocolors.default.gray(a2)} ${import_picocolors.default.strikethrough(import_picocolors.default.dim(
|
|
1658
|
+
return `${i}${import_picocolors.default.gray(a2)} ${import_picocolors.default.strikethrough(import_picocolors.default.dim(r))}
|
|
1659
1659
|
${import_picocolors.default.gray(a2)}`;
|
|
1660
1660
|
default:
|
|
1661
1661
|
return `${i}${import_picocolors.default.cyan(a2)} ${this.value ? `${import_picocolors.default.green(I2)} ${n}` : `${import_picocolors.default.dim(T2)} ${import_picocolors.default.dim(n)}`} ${import_picocolors.default.dim("/")} ${this.value ? `${import_picocolors.default.dim(T2)} ${import_picocolors.default.dim(t)}` : `${import_picocolors.default.green(I2)} ${t}`}
|
|
@@ -1666,16 +1666,16 @@ ${import_picocolors.default.cyan($2)}
|
|
|
1666
1666
|
};
|
|
1667
1667
|
var le = (s) => {
|
|
1668
1668
|
const n = (t, i) => {
|
|
1669
|
-
const
|
|
1669
|
+
const r = t.label ?? String(t.value);
|
|
1670
1670
|
switch (i) {
|
|
1671
1671
|
case "selected":
|
|
1672
|
-
return `${import_picocolors.default.dim(
|
|
1672
|
+
return `${import_picocolors.default.dim(r)}`;
|
|
1673
1673
|
case "active":
|
|
1674
|
-
return `${import_picocolors.default.green(I2)} ${
|
|
1674
|
+
return `${import_picocolors.default.green(I2)} ${r} ${t.hint ? import_picocolors.default.dim(`(${t.hint})`) : ""}`;
|
|
1675
1675
|
case "cancelled":
|
|
1676
|
-
return `${import_picocolors.default.strikethrough(import_picocolors.default.dim(
|
|
1676
|
+
return `${import_picocolors.default.strikethrough(import_picocolors.default.dim(r))}`;
|
|
1677
1677
|
default:
|
|
1678
|
-
return `${import_picocolors.default.dim(T2)} ${import_picocolors.default.dim(
|
|
1678
|
+
return `${import_picocolors.default.dim(T2)} ${import_picocolors.default.dim(r)}`;
|
|
1679
1679
|
}
|
|
1680
1680
|
};
|
|
1681
1681
|
return new $D({ options: s.options, initialValue: s.initialValue, render() {
|
|
@@ -1689,7 +1689,7 @@ ${y2(this.state)} ${s.message}
|
|
|
1689
1689
|
return `${t}${import_picocolors.default.gray(a2)} ${n(this.options[this.cursor], "cancelled")}
|
|
1690
1690
|
${import_picocolors.default.gray(a2)}`;
|
|
1691
1691
|
default:
|
|
1692
|
-
return `${t}${import_picocolors.default.cyan(a2)} ${E({ cursor: this.cursor, options: this.options, maxItems: s.maxItems, style: (i,
|
|
1692
|
+
return `${t}${import_picocolors.default.cyan(a2)} ${E({ cursor: this.cursor, options: this.options, maxItems: s.maxItems, style: (i, r) => n(i, r ? "active" : "inactive") }).join(`
|
|
1693
1693
|
${import_picocolors.default.cyan(a2)} `)}
|
|
1694
1694
|
${import_picocolors.default.cyan($2)}
|
|
1695
1695
|
`;
|
|
@@ -1698,8 +1698,8 @@ ${import_picocolors.default.cyan($2)}
|
|
|
1698
1698
|
};
|
|
1699
1699
|
var $e = (s) => {
|
|
1700
1700
|
const n = (t, i) => {
|
|
1701
|
-
const
|
|
1702
|
-
return i === "active" ? `${import_picocolors.default.cyan(j2)} ${
|
|
1701
|
+
const r = t.label ?? String(t.value);
|
|
1702
|
+
return i === "active" ? `${import_picocolors.default.cyan(j2)} ${r} ${t.hint ? import_picocolors.default.dim(`(${t.hint})`) : ""}` : i === "selected" ? `${import_picocolors.default.green(b2)} ${import_picocolors.default.dim(r)}` : i === "cancelled" ? `${import_picocolors.default.strikethrough(import_picocolors.default.dim(r))}` : i === "active-selected" ? `${import_picocolors.default.green(b2)} ${r} ${t.hint ? import_picocolors.default.dim(`(${t.hint})`) : ""}` : i === "submitted" ? `${import_picocolors.default.dim(r)}` : `${import_picocolors.default.dim(B)} ${import_picocolors.default.dim(r)}`;
|
|
1703
1703
|
};
|
|
1704
1704
|
return new vD({ options: s.options, initialValues: s.initialValues, required: s.required ?? true, cursorAt: s.cursorAt, validate(t) {
|
|
1705
1705
|
if (this.required && t.length === 0)
|
|
@@ -1709,25 +1709,25 @@ ${import_picocolors.default.reset(import_picocolors.default.dim(`Press ${import_
|
|
|
1709
1709
|
let t = `${import_picocolors.default.gray(a2)}
|
|
1710
1710
|
${y2(this.state)} ${s.message}
|
|
1711
1711
|
`;
|
|
1712
|
-
const i = (
|
|
1713
|
-
const c = this.value.includes(
|
|
1714
|
-
return o && c ? n(
|
|
1712
|
+
const i = (r, o) => {
|
|
1713
|
+
const c = this.value.includes(r.value);
|
|
1714
|
+
return o && c ? n(r, "active-selected") : c ? n(r, "selected") : n(r, o ? "active" : "inactive");
|
|
1715
1715
|
};
|
|
1716
1716
|
switch (this.state) {
|
|
1717
1717
|
case "submit":
|
|
1718
|
-
return `${t}${import_picocolors.default.gray(a2)} ${this.options.filter(({ value:
|
|
1718
|
+
return `${t}${import_picocolors.default.gray(a2)} ${this.options.filter(({ value: r }) => this.value.includes(r)).map((r) => n(r, "submitted")).join(import_picocolors.default.dim(", ")) || import_picocolors.default.dim("none")}`;
|
|
1719
1719
|
case "cancel": {
|
|
1720
|
-
const
|
|
1721
|
-
return `${t}${import_picocolors.default.gray(a2)} ${
|
|
1720
|
+
const r = this.options.filter(({ value: o }) => this.value.includes(o)).map((o) => n(o, "cancelled")).join(import_picocolors.default.dim(", "));
|
|
1721
|
+
return `${t}${import_picocolors.default.gray(a2)} ${r.trim() ? `${r}
|
|
1722
1722
|
${import_picocolors.default.gray(a2)}` : ""}`;
|
|
1723
1723
|
}
|
|
1724
1724
|
case "error": {
|
|
1725
|
-
const
|
|
1725
|
+
const r = this.error.split(`
|
|
1726
1726
|
`).map((o, c) => c === 0 ? `${import_picocolors.default.yellow($2)} ${import_picocolors.default.yellow(o)}` : ` ${o}`).join(`
|
|
1727
1727
|
`);
|
|
1728
1728
|
return t + import_picocolors.default.yellow(a2) + " " + E({ options: this.options, cursor: this.cursor, maxItems: s.maxItems, style: i }).join(`
|
|
1729
1729
|
${import_picocolors.default.yellow(a2)} `) + `
|
|
1730
|
-
` +
|
|
1730
|
+
` + r + `
|
|
1731
1731
|
`;
|
|
1732
1732
|
}
|
|
1733
1733
|
default:
|
|
@@ -1743,12 +1743,12 @@ var me = (s = "", n = "") => {
|
|
|
1743
1743
|
const t = `
|
|
1744
1744
|
${s}
|
|
1745
1745
|
`.split(`
|
|
1746
|
-
`), i = R2(n).length,
|
|
1746
|
+
`), i = R2(n).length, r = Math.max(t.reduce((c, l) => (l = R2(l), l.length > c ? l.length : c), 0), i) + 2, o = t.map((c) => `${import_picocolors.default.gray(a2)} ${import_picocolors.default.dim(c)}${" ".repeat(r - R2(c).length)}${import_picocolors.default.gray(a2)}`).join(`
|
|
1747
1747
|
`);
|
|
1748
1748
|
process.stdout.write(`${import_picocolors.default.gray(a2)}
|
|
1749
|
-
${import_picocolors.default.green(M2)} ${import_picocolors.default.reset(n)} ${import_picocolors.default.gray(G.repeat(Math.max(
|
|
1749
|
+
${import_picocolors.default.green(M2)} ${import_picocolors.default.reset(n)} ${import_picocolors.default.gray(G.repeat(Math.max(r - i - 1, 1)) + H)}
|
|
1750
1750
|
${o}
|
|
1751
|
-
${import_picocolors.default.gray(ee + G.repeat(
|
|
1751
|
+
${import_picocolors.default.gray(ee + G.repeat(r + 2) + te)}
|
|
1752
1752
|
`);
|
|
1753
1753
|
};
|
|
1754
1754
|
var he = (s = "") => {
|
|
@@ -1769,9 +1769,9 @@ ${import_picocolors.default.gray($2)} ${s}
|
|
|
1769
1769
|
var v2 = { message: (s = "", { symbol: n = import_picocolors.default.gray(a2) } = {}) => {
|
|
1770
1770
|
const t = [`${import_picocolors.default.gray(a2)}`];
|
|
1771
1771
|
if (s) {
|
|
1772
|
-
const [i, ...
|
|
1772
|
+
const [i, ...r] = s.split(`
|
|
1773
1773
|
`);
|
|
1774
|
-
t.push(`${n} ${i}`, ...
|
|
1774
|
+
t.push(`${n} ${i}`, ...r.map((o) => `${import_picocolors.default.gray(a2)} ${o}`));
|
|
1775
1775
|
}
|
|
1776
1776
|
process.stdout.write(`${t.join(`
|
|
1777
1777
|
`)}
|
|
@@ -1791,30 +1791,30 @@ var v2 = { message: (s = "", { symbol: n = import_picocolors.default.gray(a2) }
|
|
|
1791
1791
|
} };
|
|
1792
1792
|
var _2 = () => {
|
|
1793
1793
|
const s = C ? ["◒", "◐", "◓", "◑"] : ["•", "o", "O", "0"], n = C ? 80 : 120;
|
|
1794
|
-
let t, i,
|
|
1795
|
-
const c = (
|
|
1796
|
-
const
|
|
1797
|
-
|
|
1798
|
-
},
|
|
1799
|
-
process.on("uncaughtExceptionMonitor",
|
|
1800
|
-
},
|
|
1801
|
-
process.removeListener("uncaughtExceptionMonitor",
|
|
1802
|
-
},
|
|
1803
|
-
|
|
1794
|
+
let t, i, r = false, o = "";
|
|
1795
|
+
const c = (g) => {
|
|
1796
|
+
const m = g > 1 ? "Something went wrong" : "Canceled";
|
|
1797
|
+
r && x(m, g);
|
|
1798
|
+
}, l = () => c(2), d = () => c(1), p = () => {
|
|
1799
|
+
process.on("uncaughtExceptionMonitor", l), process.on("unhandledRejection", l), process.on("SIGINT", d), process.on("SIGTERM", d), process.on("exit", c);
|
|
1800
|
+
}, S = () => {
|
|
1801
|
+
process.removeListener("uncaughtExceptionMonitor", l), process.removeListener("unhandledRejection", l), process.removeListener("SIGINT", d), process.removeListener("SIGTERM", d), process.removeListener("exit", c);
|
|
1802
|
+
}, f = (g = "") => {
|
|
1803
|
+
r = true, t = OD(), o = g.replace(/\.+$/, ""), process.stdout.write(`${import_picocolors.default.gray(a2)}
|
|
1804
1804
|
`);
|
|
1805
|
-
let
|
|
1805
|
+
let m = 0, w = 0;
|
|
1806
1806
|
p(), i = setInterval(() => {
|
|
1807
|
-
const
|
|
1808
|
-
process.stdout.write(import_sisteransi2.cursor.move(-999, 0)), process.stdout.write(import_sisteransi2.erase.down(1)), process.stdout.write(`${
|
|
1807
|
+
const L = import_picocolors.default.magenta(s[m]), O = ".".repeat(Math.floor(w)).slice(0, 3);
|
|
1808
|
+
process.stdout.write(import_sisteransi2.cursor.move(-999, 0)), process.stdout.write(import_sisteransi2.erase.down(1)), process.stdout.write(`${L} ${o}${O}`), m = m + 1 < s.length ? m + 1 : 0, w = w < s.length ? w + 0.125 : 0;
|
|
1809
1809
|
}, n);
|
|
1810
|
-
},
|
|
1811
|
-
o =
|
|
1812
|
-
const
|
|
1813
|
-
process.stdout.write(import_sisteransi2.cursor.move(-999, 0)), process.stdout.write(import_sisteransi2.erase.down(1)), process.stdout.write(`${
|
|
1814
|
-
`),
|
|
1810
|
+
}, x = (g = "", m = 0) => {
|
|
1811
|
+
o = g ?? o, r = false, clearInterval(i);
|
|
1812
|
+
const w = m === 0 ? import_picocolors.default.green(M2) : m === 1 ? import_picocolors.default.red(P2) : import_picocolors.default.red(V2);
|
|
1813
|
+
process.stdout.write(import_sisteransi2.cursor.move(-999, 0)), process.stdout.write(import_sisteransi2.erase.down(1)), process.stdout.write(`${w} ${o}
|
|
1814
|
+
`), S(), t();
|
|
1815
1815
|
};
|
|
1816
|
-
return { start:
|
|
1817
|
-
o =
|
|
1816
|
+
return { start: f, stop: x, message: (g = "") => {
|
|
1817
|
+
o = g ?? o;
|
|
1818
1818
|
} };
|
|
1819
1819
|
};
|
|
1820
1820
|
function ye() {
|
|
@@ -1822,6 +1822,90 @@ function ye() {
|
|
|
1822
1822
|
return new RegExp(s, "g");
|
|
1823
1823
|
}
|
|
1824
1824
|
|
|
1825
|
+
// src/cursor-hook-config.ts
|
|
1826
|
+
function cursorHookEntry(name, command, isApproval = false) {
|
|
1827
|
+
if (name === "stop" || name === "subagentStop")
|
|
1828
|
+
return { command, timeout: 600, loop_limit: 10 };
|
|
1829
|
+
if (isApproval)
|
|
1830
|
+
return { command, timeout: 300 };
|
|
1831
|
+
if (name === "sessionEnd")
|
|
1832
|
+
return { command, timeout: 10 };
|
|
1833
|
+
return { command };
|
|
1834
|
+
}
|
|
1835
|
+
function upsertCursorHook(existing, entry) {
|
|
1836
|
+
const entries = (Array.isArray(existing) ? existing : existing ? [existing] : []).map((value) => typeof value === "string" ? { command: value } : value);
|
|
1837
|
+
const index = entries.findIndex((value) => value && typeof value === "object" && ("command" in value) && typeof value.command === "string" && value.command.includes("agentapprove"));
|
|
1838
|
+
if (index < 0)
|
|
1839
|
+
entries.push(entry);
|
|
1840
|
+
else
|
|
1841
|
+
entries[index] = entry;
|
|
1842
|
+
return entries;
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
// src/openclaw-install.ts
|
|
1846
|
+
import { spawnSync } from "node:child_process";
|
|
1847
|
+
var CONVERSATION_ACCESS_NOTICE = "OpenClaw setup includes access to prompts, responses, and completed conversations for monitoring and mobile follow-up. Your privacy and encryption settings still apply. OpenClaw will review any required plugin permissions during installation.";
|
|
1848
|
+
function runOpenClaw(args) {
|
|
1849
|
+
const result = spawnSync("openclaw", args, { stdio: "inherit", shell: process.platform === "win32" });
|
|
1850
|
+
return !result.error && result.status === 0;
|
|
1851
|
+
}
|
|
1852
|
+
function mergeOpenClawConfig(config, conversationAccess) {
|
|
1853
|
+
const plugins = config.plugins ?? {};
|
|
1854
|
+
const entries = plugins.entries ?? {};
|
|
1855
|
+
const entry = entries.openclaw ?? {};
|
|
1856
|
+
return {
|
|
1857
|
+
...config,
|
|
1858
|
+
plugins: {
|
|
1859
|
+
...plugins,
|
|
1860
|
+
entries: {
|
|
1861
|
+
...entries,
|
|
1862
|
+
openclaw: {
|
|
1863
|
+
...entry,
|
|
1864
|
+
hooks: { ...entry.hooks, allowConversationAccess: conversationAccess },
|
|
1865
|
+
config: { ...entry.config }
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
},
|
|
1869
|
+
hooks: { ...config.hooks, internal: { enabled: true, ...config.hooks?.internal } }
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
async function installOpenClaw(options) {
|
|
1873
|
+
const run = options.run ?? runOpenClaw;
|
|
1874
|
+
const fail = (error) => ({ success: false, label: "Agent Approve plugin", error });
|
|
1875
|
+
try {
|
|
1876
|
+
options.readConfig();
|
|
1877
|
+
} catch {
|
|
1878
|
+
return fail("Could not read OpenClaw configuration as JSON. No plugin installation or permission changes were made. Check the config before retrying.");
|
|
1879
|
+
}
|
|
1880
|
+
const installed = options.readVersion();
|
|
1881
|
+
if (installed !== options.version) {
|
|
1882
|
+
const args = ["plugins", "install", options.spec];
|
|
1883
|
+
if (installed !== null) {
|
|
1884
|
+
if (!await options.confirmReplacement(`Replace Agent Approve ${installed} with ${options.spec}? This npm source is outside ClawHub review and trust metadata. Only continue if you trust this package. OpenClaw will separately review its capabilities.`)) {
|
|
1885
|
+
return fail("Plugin replacement declined; the existing install was kept.");
|
|
1886
|
+
}
|
|
1887
|
+
args.push("--force");
|
|
1888
|
+
}
|
|
1889
|
+
if (!run(args))
|
|
1890
|
+
return fail("OpenClaw installation was declined or failed. Review the host output above; no permissions were automatically accepted.");
|
|
1891
|
+
const actual = options.readVersion();
|
|
1892
|
+
if (actual !== options.version)
|
|
1893
|
+
return fail(`OpenClaw installed ${actual ?? "an unverified version"}, expected ${options.version}.`);
|
|
1894
|
+
}
|
|
1895
|
+
try {
|
|
1896
|
+
options.writeConfig(mergeOpenClawConfig(options.readConfig(), true));
|
|
1897
|
+
} catch {
|
|
1898
|
+
return fail("Could not read or save OpenClaw configuration. The plugin package is present; check the config and retry setup before using it.");
|
|
1899
|
+
}
|
|
1900
|
+
const action = options.mode === "approval" ? "enable" : "disable";
|
|
1901
|
+
if (!run(["plugins", action, "openclaw"]))
|
|
1902
|
+
return fail(`OpenClaw ${action} was declined or failed. Settings were saved; activation remains controlled by OpenClaw.`);
|
|
1903
|
+
return {
|
|
1904
|
+
success: true,
|
|
1905
|
+
label: `Agent Approve plugin v${options.version} (conversation access included)`
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1825
1909
|
// src/env-preserve.ts
|
|
1826
1910
|
var MANAGED_ENV_KEYS = new Set([
|
|
1827
1911
|
"AGENTAPPROVE_API",
|
|
@@ -1835,13 +1919,15 @@ var MANAGED_ENV_KEYS = new Set([
|
|
|
1835
1919
|
"AGENTAPPROVE_FAIL_BEHAVIOR"
|
|
1836
1920
|
]);
|
|
1837
1921
|
var ACCOUNT_SYNCED_UNMANAGED_KEYS = new Set([
|
|
1922
|
+
"AGENTAPPROVE_FILTER_BACKGROUND_ACTIVITY",
|
|
1923
|
+
"AGENTAPPROVE_BACKGROUND_FILTER_SYNC_PENDING",
|
|
1838
1924
|
"AGENTAPPROVE_QUESTION_INPUT_MODE",
|
|
1839
1925
|
"AGENTAPPROVE_TIMEOUT"
|
|
1840
1926
|
]);
|
|
1841
1927
|
var ENV_KEY_PATTERN = /^AGENTAPPROVE_[A-Z0-9_]+$/;
|
|
1842
1928
|
function isPreservedEnvKey(key) {
|
|
1843
|
-
const
|
|
1844
|
-
return ENV_KEY_PATTERN.test(
|
|
1929
|
+
const k = key.trim();
|
|
1930
|
+
return ENV_KEY_PATTERN.test(k) && !MANAGED_ENV_KEYS.has(k);
|
|
1845
1931
|
}
|
|
1846
1932
|
function renderPreservedEnvSection(preserved) {
|
|
1847
1933
|
if (!preserved)
|
|
@@ -1858,8 +1944,8 @@ ${lines.join(`
|
|
|
1858
1944
|
`;
|
|
1859
1945
|
}
|
|
1860
1946
|
function normalizeEmail(value) {
|
|
1861
|
-
const
|
|
1862
|
-
return
|
|
1947
|
+
const v = value?.trim().toLowerCase();
|
|
1948
|
+
return v ? v : undefined;
|
|
1863
1949
|
}
|
|
1864
1950
|
function resolvePreservation(input) {
|
|
1865
1951
|
const existing = input.existing ?? undefined;
|
|
@@ -1872,9 +1958,9 @@ function resolvePreservation(input) {
|
|
|
1872
1958
|
case "refresh":
|
|
1873
1959
|
case "repair":
|
|
1874
1960
|
case "pair": {
|
|
1875
|
-
const
|
|
1876
|
-
const
|
|
1877
|
-
if (
|
|
1961
|
+
const a = normalizeEmail(input.verifiedEmail);
|
|
1962
|
+
const b = normalizeEmail(input.pairedEmail);
|
|
1963
|
+
if (a && b && a === b) {
|
|
1878
1964
|
return { preserved: existing.preserved, letAccountWin: false };
|
|
1879
1965
|
}
|
|
1880
1966
|
return { preserved: machineLocalOnly(existing.preserved), letAccountWin: true };
|
|
@@ -2401,10 +2487,10 @@ var source_default = chalk;
|
|
|
2401
2487
|
|
|
2402
2488
|
// src/cli.ts
|
|
2403
2489
|
var import_qrcode_terminal = __toESM(require_main(), 1);
|
|
2404
|
-
import { existsSync as existsSync2, readFileSync, writeFileSync, mkdirSync, mkdtempSync, copyFileSync, renameSync, readdirSync as readdirSync2, statSync, lstatSync, realpathSync as realpathSync2, rmSync as rmSync2 } from "fs";
|
|
2490
|
+
import { existsSync as existsSync2, readFileSync, writeFileSync, mkdirSync, mkdtempSync, copyFileSync, renameSync as renameSync2, readdirSync as readdirSync2, statSync, lstatSync, realpathSync as realpathSync2, rmSync as rmSync2 } from "fs";
|
|
2405
2491
|
import { homedir, hostname, platform, tmpdir } from "os";
|
|
2406
2492
|
import { join, dirname as dirname2, sep as sep2 } from "path";
|
|
2407
|
-
import { execSync, spawnSync } from "child_process";
|
|
2493
|
+
import { execSync, spawnSync as spawnSync2 } from "child_process";
|
|
2408
2494
|
import { randomBytes, createHash } from "crypto";
|
|
2409
2495
|
|
|
2410
2496
|
// src/uninstall-utils.ts
|
|
@@ -2577,6 +2663,7 @@ function getManagedStateTargets(agentApproveDir) {
|
|
|
2577
2663
|
const reversible = [
|
|
2578
2664
|
safeJoinWithinBase(agentApproveDir, "env"),
|
|
2579
2665
|
safeJoinWithinBase(agentApproveDir, "env.disabled"),
|
|
2666
|
+
safeJoinWithinBase(agentApproveDir, "setup-agents.json"),
|
|
2580
2667
|
safeJoinWithinBase(agentApproveDir, "hook-debug.log"),
|
|
2581
2668
|
safeJoinWithinBase(agentApproveDir, "hooks"),
|
|
2582
2669
|
safeJoinWithinBase(agentApproveDir, "install.sh"),
|
|
@@ -2689,8 +2776,8 @@ function removeAgentApproveHookEntries(hooksConfig, hookNames) {
|
|
|
2689
2776
|
if (!hookEntry)
|
|
2690
2777
|
continue;
|
|
2691
2778
|
if (Array.isArray(hookEntry)) {
|
|
2692
|
-
const filtered = hookEntry.filter((
|
|
2693
|
-
const str = JSON.stringify(
|
|
2779
|
+
const filtered = hookEntry.filter((e) => {
|
|
2780
|
+
const str = JSON.stringify(e);
|
|
2694
2781
|
return !str.includes("agentapprove");
|
|
2695
2782
|
});
|
|
2696
2783
|
if (filtered.length !== hookEntry.length) {
|
|
@@ -2997,11 +3084,11 @@ async function validateExistingToken(token, apiUrl, apiVersion, options = {}) {
|
|
|
2997
3084
|
}
|
|
2998
3085
|
const status = response.status;
|
|
2999
3086
|
if (response.ok) {
|
|
3000
|
-
const
|
|
3087
|
+
const body = await safeReadText(response);
|
|
3001
3088
|
return {
|
|
3002
3089
|
kind: "valid",
|
|
3003
3090
|
summary: "verified - token is valid",
|
|
3004
|
-
cachedContent:
|
|
3091
|
+
cachedContent: body,
|
|
3005
3092
|
status
|
|
3006
3093
|
};
|
|
3007
3094
|
}
|
|
@@ -3067,6 +3154,8 @@ async function validateExistingToken(token, apiUrl, apiVersion, options = {}) {
|
|
|
3067
3154
|
function classifyHookDownloadFailure(status, body) {
|
|
3068
3155
|
const parsed = parseErrorBody(body);
|
|
3069
3156
|
const code = parsed?.code;
|
|
3157
|
+
if (status === 429)
|
|
3158
|
+
return "rate_limited";
|
|
3070
3159
|
if (status === 401 && code === "TOKEN_EXPIRED")
|
|
3071
3160
|
return "token_expired";
|
|
3072
3161
|
if (status === 401 && code === "INVALID_TOKEN")
|
|
@@ -3084,42 +3173,99 @@ function classifyHookDownloadFailure(status, body) {
|
|
|
3084
3173
|
|
|
3085
3174
|
// src/copy-hook-scripts.ts
|
|
3086
3175
|
import { writeFileSync as fsWriteFileSync } from "fs";
|
|
3176
|
+
import { renameSync } from "fs";
|
|
3177
|
+
import { randomUUID } from "crypto";
|
|
3178
|
+
|
|
3179
|
+
// src/background-filters.ts
|
|
3180
|
+
var BACKGROUND_FILTER_FILES = ["background-filter.js", "background-filters.json"];
|
|
3181
|
+
function validBackgroundFilters(content) {
|
|
3182
|
+
if (Buffer.byteLength(content) > 64 * 1024)
|
|
3183
|
+
return false;
|
|
3184
|
+
try {
|
|
3185
|
+
const c = JSON.parse(content);
|
|
3186
|
+
return c?.schemaVersion === 1 && typeof c.revision === "string" && c.revision.length <= 128 && Array.isArray(c.filters) && c.filters.length <= 100 && c.filters.every((f) => typeof f.id === "string" && /^[a-z0-9_-]{1,100}$/.test(f.id) && typeof f.agent === "string" && /^[a-z0-9_-]{1,40}$/.test(f.agent) && typeof f.promptPrefix === "string" && f.promptPrefix.trim().length >= 20 && f.promptPrefix.length <= 2000 && Array.isArray(f.promptContains) && f.promptContains.length >= 1 && f.promptContains.length <= 10 && f.promptContains.every((s) => typeof s === "string" && s.trim().length > 0 && s.length <= 2000));
|
|
3187
|
+
} catch {
|
|
3188
|
+
return false;
|
|
3189
|
+
}
|
|
3190
|
+
}
|
|
3191
|
+
|
|
3192
|
+
// src/copy-hook-scripts.ts
|
|
3087
3193
|
import { join as pathJoin } from "path";
|
|
3194
|
+
function retryDelay(response) {
|
|
3195
|
+
const value = response.headers.get("Retry-After")?.trim();
|
|
3196
|
+
if (!value)
|
|
3197
|
+
return 60250;
|
|
3198
|
+
const seconds = /^\d+(?:\.\d+)?$/.test(value) ? Number(value) : NaN;
|
|
3199
|
+
const delay = Number.isFinite(seconds) ? seconds * 1000 : Date.parse(value) - Date.now();
|
|
3200
|
+
return Number.isFinite(delay) ? Math.max(1000, delay) + 250 : 60250;
|
|
3201
|
+
}
|
|
3088
3202
|
async function copyHookScripts(hooksDir, token, files, options) {
|
|
3089
3203
|
const fetchImpl = options.fetchImpl || fetch;
|
|
3090
3204
|
const writeFile = options.writeFileSync || fsWriteFileSync;
|
|
3091
3205
|
const join = options.joinPath || pathJoin;
|
|
3206
|
+
const sleep = options.sleep || ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
3207
|
+
let retryBudgetMs = 125000;
|
|
3208
|
+
const staged = [];
|
|
3092
3209
|
let downloaded = 0;
|
|
3093
3210
|
const failed = [];
|
|
3211
|
+
const optionalFailed = [];
|
|
3212
|
+
const optional = new Set(options.optionalFiles || []);
|
|
3213
|
+
const recordFailure = (file, detail) => {
|
|
3214
|
+
(optional.has(file) ? optionalFailed : failed).push(`${file} (${detail})`);
|
|
3215
|
+
};
|
|
3094
3216
|
for (const file of files) {
|
|
3095
3217
|
if (!/^[a-z0-9._-]+\.(sh|js|json)$/i.test(file) || file.includes("..")) {
|
|
3096
|
-
|
|
3218
|
+
recordFailure(file, "invalid filename");
|
|
3097
3219
|
continue;
|
|
3098
3220
|
}
|
|
3099
3221
|
try {
|
|
3100
|
-
const
|
|
3222
|
+
const download = () => fetchImpl(`${options.apiUrl}/${options.apiVersion}/hooks/${file}?format=raw`, {
|
|
3101
3223
|
headers: {
|
|
3102
3224
|
Authorization: `Bearer ${token}`
|
|
3103
3225
|
}
|
|
3104
3226
|
});
|
|
3227
|
+
let response = await download();
|
|
3228
|
+
for (let retry = 0;response.status === 429 && retry < 2; retry++) {
|
|
3229
|
+
const delay = retryDelay(response);
|
|
3230
|
+
if (delay > retryBudgetMs)
|
|
3231
|
+
break;
|
|
3232
|
+
retryBudgetMs -= delay;
|
|
3233
|
+
await response.body?.cancel();
|
|
3234
|
+
options.onRateLimit?.(file, Math.ceil(delay / 1000));
|
|
3235
|
+
await sleep(delay);
|
|
3236
|
+
response = await download();
|
|
3237
|
+
}
|
|
3105
3238
|
if (response.ok) {
|
|
3106
3239
|
const content = await response.text();
|
|
3240
|
+
if (file === "background-filters.json") {
|
|
3241
|
+
if (!validBackgroundFilters(content)) {
|
|
3242
|
+
recordFailure(file, "invalid catalog; previous copy retained");
|
|
3243
|
+
continue;
|
|
3244
|
+
}
|
|
3245
|
+
staged.push({ file, content, mode: 384 });
|
|
3246
|
+
downloaded++;
|
|
3247
|
+
continue;
|
|
3248
|
+
}
|
|
3107
3249
|
const isShellScript = content.startsWith("#!/") || content.startsWith("# ");
|
|
3108
3250
|
const isJsBundle = file.endsWith(".js") && (content.startsWith("//") || content.startsWith("import ") || content.startsWith("var ") || content.startsWith("const ") || content.startsWith("export "));
|
|
3109
3251
|
if (isShellScript || isJsBundle) {
|
|
3110
|
-
|
|
3111
|
-
writeFile(filePath, content, { mode: isShellScript ? 493 : 420 });
|
|
3252
|
+
staged.push({ file, content, mode: isShellScript ? 493 : 420 });
|
|
3112
3253
|
downloaded++;
|
|
3113
3254
|
} else {
|
|
3114
|
-
|
|
3255
|
+
recordFailure(file, "invalid content");
|
|
3115
3256
|
}
|
|
3116
3257
|
} else {
|
|
3117
3258
|
const body = await response.text().catch(() => "");
|
|
3118
3259
|
const failureKind = classifyHookDownloadFailure(response.status, body);
|
|
3260
|
+
if (optional.has(file) && (failureKind === "rate_limited" || failureKind === "validation_unavailable")) {
|
|
3261
|
+
recordFailure(file, String(response.status));
|
|
3262
|
+
continue;
|
|
3263
|
+
}
|
|
3119
3264
|
if (failureKind !== "recoverable") {
|
|
3120
3265
|
return {
|
|
3121
3266
|
downloaded,
|
|
3122
3267
|
failed,
|
|
3268
|
+
optionalFailed,
|
|
3123
3269
|
terminalFailure: {
|
|
3124
3270
|
kind: failureKind,
|
|
3125
3271
|
file,
|
|
@@ -3127,13 +3273,58 @@ async function copyHookScripts(hooksDir, token, files, options) {
|
|
|
3127
3273
|
}
|
|
3128
3274
|
};
|
|
3129
3275
|
}
|
|
3130
|
-
|
|
3276
|
+
recordFailure(file, String(response.status));
|
|
3131
3277
|
}
|
|
3132
3278
|
} catch (err) {
|
|
3133
|
-
|
|
3279
|
+
recordFailure(file, err instanceof Error ? err.message : "network error");
|
|
3134
3280
|
}
|
|
3135
3281
|
}
|
|
3136
|
-
|
|
3282
|
+
if (failed.length === 0) {
|
|
3283
|
+
const replacements = [];
|
|
3284
|
+
for (const { file, content, mode } of staged) {
|
|
3285
|
+
if (optionalFailed.length && optional.has(file))
|
|
3286
|
+
continue;
|
|
3287
|
+
try {
|
|
3288
|
+
const filePath = join(hooksDir, file);
|
|
3289
|
+
if (options.writeFileSync)
|
|
3290
|
+
writeFile(filePath, content, { mode });
|
|
3291
|
+
else {
|
|
3292
|
+
const temporary = `${filePath}.${randomUUID()}.tmp`;
|
|
3293
|
+
writeFile(temporary, content, { mode });
|
|
3294
|
+
replacements.push({ temporary, filePath, file });
|
|
3295
|
+
}
|
|
3296
|
+
} catch {
|
|
3297
|
+
failed.push(`${file} (could not save hook file)`);
|
|
3298
|
+
break;
|
|
3299
|
+
}
|
|
3300
|
+
}
|
|
3301
|
+
if (failed.length === 0) {
|
|
3302
|
+
for (const { temporary, filePath, file } of replacements) {
|
|
3303
|
+
try {
|
|
3304
|
+
renameSync(temporary, filePath);
|
|
3305
|
+
} catch {
|
|
3306
|
+
failed.push(`${file} (could not replace hook file)`);
|
|
3307
|
+
break;
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
}
|
|
3311
|
+
}
|
|
3312
|
+
return { downloaded, failed, optionalFailed };
|
|
3313
|
+
}
|
|
3314
|
+
|
|
3315
|
+
// src/hermes-follow-up.ts
|
|
3316
|
+
import { execFileSync } from "child_process";
|
|
3317
|
+
function enableHermesFollowUp(profile, run = (file, args) => execFileSync(file, args, { stdio: "pipe", timeout: 30000 })) {
|
|
3318
|
+
if (!/^[a-z0-9][a-z0-9_-]{0,63}$/.test(profile)) {
|
|
3319
|
+
throw new Error("Invalid Hermes profile name");
|
|
3320
|
+
}
|
|
3321
|
+
run("hermes", [
|
|
3322
|
+
...profile === "default" ? [] : ["-p", profile],
|
|
3323
|
+
"config",
|
|
3324
|
+
"set",
|
|
3325
|
+
"plugins.entries.agentapprove.allow_gateway_injection",
|
|
3326
|
+
"true"
|
|
3327
|
+
]);
|
|
3137
3328
|
}
|
|
3138
3329
|
|
|
3139
3330
|
// src/pairing-api-url.ts
|
|
@@ -3157,8 +3348,67 @@ function resolvePairingApiBaseUrl(options) {
|
|
|
3157
3348
|
return options.processDefaultApiUrl;
|
|
3158
3349
|
}
|
|
3159
3350
|
|
|
3351
|
+
// src/setup-check.ts
|
|
3352
|
+
function checkHookConfiguration(agent, config, hooksKey, hooks, mode, fileReady, expectedCommand = (file) => `~/.agentapprove/hooks/${file}`) {
|
|
3353
|
+
const result = (status, reason) => ({ agent, status, reason });
|
|
3354
|
+
const expected = hooks.filter((h) => !h.isPlugin && !(mode === "observe" && h.isApprovalHook));
|
|
3355
|
+
if (!expected.length)
|
|
3356
|
+
return result("manual", "manual_step");
|
|
3357
|
+
const map = hooksKey ? config[hooksKey] : config;
|
|
3358
|
+
if (!map || typeof map !== "object")
|
|
3359
|
+
return result("failed", "not_configured");
|
|
3360
|
+
if (map.enabled === false)
|
|
3361
|
+
return result("failed", "disabled");
|
|
3362
|
+
for (const hook of expected) {
|
|
3363
|
+
if (!hookCommands(map[hook.name]).includes(expectedCommand(hook.file, hook.name)))
|
|
3364
|
+
return result("failed", "not_configured");
|
|
3365
|
+
if (!fileReady(hook.file))
|
|
3366
|
+
return result("failed", "missing_files");
|
|
3367
|
+
}
|
|
3368
|
+
return result("ready", "verified");
|
|
3369
|
+
}
|
|
3370
|
+
function hookCommands(value) {
|
|
3371
|
+
if (typeof value === "string")
|
|
3372
|
+
return [value];
|
|
3373
|
+
if (Array.isArray(value))
|
|
3374
|
+
return value.flatMap(hookCommands);
|
|
3375
|
+
if (!value || typeof value !== "object")
|
|
3376
|
+
return [];
|
|
3377
|
+
const item = value;
|
|
3378
|
+
if (item.enabled === false || item.disabled === true)
|
|
3379
|
+
return [];
|
|
3380
|
+
return [...hookCommands(item.command), ...hookCommands(item.bash), ...hookCommands(item.hooks)];
|
|
3381
|
+
}
|
|
3382
|
+
function installOutro(integrations) {
|
|
3383
|
+
const ready = integrations.filter((item) => item.status === "ready").map((item) => item.agent);
|
|
3384
|
+
if (!ready.length) {
|
|
3385
|
+
return "No integration is ready yet. Fix the problems listed above, then run npx agentapprove again. Nothing on your phone is waiting on this.";
|
|
3386
|
+
}
|
|
3387
|
+
return "";
|
|
3388
|
+
}
|
|
3389
|
+
function formatNextSteps(steps) {
|
|
3390
|
+
return steps.map((step, index) => `${index + 1}. ${step}`).join(`
|
|
3391
|
+
|
|
3392
|
+
`);
|
|
3393
|
+
}
|
|
3394
|
+
function checkSummary(integrations) {
|
|
3395
|
+
if (!integrations.length) {
|
|
3396
|
+
return { lines: ["No integrations found. Run npx agentapprove to install one."], failed: true };
|
|
3397
|
+
}
|
|
3398
|
+
const lines = integrations.map((item) => ` ${item.agent}: ${item.status} (${item.reason})`);
|
|
3399
|
+
const ready = integrations.filter((item) => item.status === "ready").map((item) => item.agent);
|
|
3400
|
+
if (!ready.length) {
|
|
3401
|
+
lines.push("No integration is ready. Repair the problems above with npx agentapprove, then run this again.");
|
|
3402
|
+
return { lines, failed: true };
|
|
3403
|
+
}
|
|
3404
|
+
lines.push(`
|
|
3405
|
+
Configured on this computer: ${ready.join(", ")}. Nothing was changed.`);
|
|
3406
|
+
lines.push("This checks configuration on this computer only. Open a new session in one of these agents and give it a normal task to see activity on your phone.");
|
|
3407
|
+
return { lines, failed: false };
|
|
3408
|
+
}
|
|
3409
|
+
|
|
3160
3410
|
// src/cli.ts
|
|
3161
|
-
var VERSION = "0.1.
|
|
3411
|
+
var VERSION = "0.1.56";
|
|
3162
3412
|
function getApiUrl() {
|
|
3163
3413
|
return process.env.AGENTAPPROVE_API || "https://api.agentapprove.com";
|
|
3164
3414
|
}
|
|
@@ -3230,14 +3480,14 @@ function getCommand() {
|
|
|
3230
3480
|
}
|
|
3231
3481
|
return filtered[0] || "install";
|
|
3232
3482
|
}
|
|
3233
|
-
var OPENCODE_PLUGIN_VERSION = "0.1.
|
|
3483
|
+
var OPENCODE_PLUGIN_VERSION = "0.1.26";
|
|
3234
3484
|
var OPENCODE_PLUGIN_SPEC = `@agentapprove/opencode@${OPENCODE_PLUGIN_VERSION}`;
|
|
3235
|
-
var OPENCLAW_PLUGIN_VERSION = "0.2.
|
|
3485
|
+
var OPENCLAW_PLUGIN_VERSION = "0.2.21";
|
|
3236
3486
|
var OPENCLAW_PLUGIN_SPEC = `@agentapprove/openclaw@${OPENCLAW_PLUGIN_VERSION}`;
|
|
3237
|
-
var PI_PLUGIN_VERSION = "0.1.
|
|
3487
|
+
var PI_PLUGIN_VERSION = "0.1.14";
|
|
3238
3488
|
var PI_PLUGIN_SPEC = `npm:@agentapprove/pi@${PI_PLUGIN_VERSION}`;
|
|
3239
3489
|
var PI_STATUS_TIMEOUT_MS = 5000;
|
|
3240
|
-
var HERMES_PLUGIN_VERSION = "0.1.
|
|
3490
|
+
var HERMES_PLUGIN_VERSION = "0.1.16";
|
|
3241
3491
|
var HERMES_PIP_DEPS = ["cryptography>=44.0,<46", "httpx>=0.27,<0.29"];
|
|
3242
3492
|
var AGENTS = {
|
|
3243
3493
|
"claude-code": {
|
|
@@ -3251,6 +3501,8 @@ var AGENTS = {
|
|
|
3251
3501
|
{ name: "PermissionRequest", file: "notify-hook.sh", description: "Permission requests", hasMatcher: true, isApprovalHook: true, timeout: 300 },
|
|
3252
3502
|
{ name: "UserPromptSubmit", file: "claude-user-prompt.sh", description: "User prompt submitted", hasMatcher: false },
|
|
3253
3503
|
{ name: "Stop", file: "claude-stop.sh", description: "Session/task completed", hasMatcher: false, timeout: 600 },
|
|
3504
|
+
{ name: "SubagentStart", file: "claude-subagent-start.sh", description: "Subagent started", hasMatcher: true },
|
|
3505
|
+
{ name: "SubagentStop", file: "claude-subagent-stop.sh", description: "Subagent completed", hasMatcher: true },
|
|
3254
3506
|
{ name: "SessionStart", file: "claude-session-start.sh", description: "Session started", hasMatcher: false },
|
|
3255
3507
|
{ name: "SessionEnd", file: "claude-session-end.sh", description: "Session ended", hasMatcher: false }
|
|
3256
3508
|
]
|
|
@@ -3375,6 +3627,8 @@ var AGENTS = {
|
|
|
3375
3627
|
configPath: join(homedir(), ".codex", "hooks.json"),
|
|
3376
3628
|
hooksKey: "hooks",
|
|
3377
3629
|
hooks: [
|
|
3630
|
+
{ name: "SubagentStart", file: "codex-subagent-start.sh", description: "Subagent started", hasMatcher: true },
|
|
3631
|
+
{ name: "SubagentStop", file: "codex-subagent-stop.sh", description: "Subagent completed", hasMatcher: true },
|
|
3378
3632
|
{ name: "SessionStart", file: "codex-session-start.sh", description: "Session started", hasMatcher: true },
|
|
3379
3633
|
{ name: "PreToolUse", file: "codex-pre-tool.sh", description: "Tool approval", hasMatcher: true, isApprovalHook: true, timeout: 300 },
|
|
3380
3634
|
{ name: "PostToolUse", file: "codex-post-tool.sh", description: "Tool completion logging", hasMatcher: true },
|
|
@@ -3453,7 +3707,7 @@ var SUPPORTED_AGENT_COPY = [
|
|
|
3453
3707
|
"Windsurf"
|
|
3454
3708
|
].join(", ");
|
|
3455
3709
|
var HIGHLIGHTED_AGENT_COPY = "Antigravity, Hermes, Pi, OpenClaw, OpenCode, and OpenHands";
|
|
3456
|
-
var SHARED_HOOK_FILES = ["common.sh"];
|
|
3710
|
+
var SHARED_HOOK_FILES = ["common.sh", ...BACKGROUND_FILTER_FILES];
|
|
3457
3711
|
var STATUS_FIELD_LABELS = {
|
|
3458
3712
|
AGENTAPPROVE_API: "API URL",
|
|
3459
3713
|
AGENTAPPROVE_TOKEN: "Token",
|
|
@@ -3546,7 +3800,7 @@ function findGitBash() {
|
|
|
3546
3800
|
}
|
|
3547
3801
|
function toGitBashPath(windowsPath) {
|
|
3548
3802
|
let result = windowsPath.replace(/\\/g, "/");
|
|
3549
|
-
result = result.replace(/^([A-Za-z]):\//, (
|
|
3803
|
+
result = result.replace(/^([A-Za-z]):\//, (_, drive) => `/${drive.toLowerCase()}/`);
|
|
3550
3804
|
return result;
|
|
3551
3805
|
}
|
|
3552
3806
|
function buildHookCommand(hookScriptPath, agentId) {
|
|
@@ -3580,7 +3834,7 @@ function getAntigravityPluginManifest() {
|
|
|
3580
3834
|
}
|
|
3581
3835
|
function buildAntigravityHooksJson(agentId, hooksDir, mode) {
|
|
3582
3836
|
const agent = AGENTS[agentId];
|
|
3583
|
-
const hooksToInstall = mode === "observe" ? agent.hooks.filter((
|
|
3837
|
+
const hooksToInstall = mode === "observe" ? agent.hooks.filter((h) => h.name !== "Stop") : agent.hooks;
|
|
3584
3838
|
const bundle = { enabled: true };
|
|
3585
3839
|
for (const hook of hooksToInstall) {
|
|
3586
3840
|
const hookPath = join(hooksDir, hook.file);
|
|
@@ -3622,7 +3876,7 @@ function installAntigravityPluginBundle(agentId, hooksDir, mode) {
|
|
|
3622
3876
|
error: err instanceof Error ? err.message : String(err)
|
|
3623
3877
|
};
|
|
3624
3878
|
}
|
|
3625
|
-
const installedHooks = (mode === "observe" ? agent.hooks.filter((
|
|
3879
|
+
const installedHooks = (mode === "observe" ? agent.hooks.filter((h) => h.name !== "Stop") : agent.hooks).map((hook) => hook.name);
|
|
3626
3880
|
return { success: true, backupPath, hooks: installedHooks };
|
|
3627
3881
|
}
|
|
3628
3882
|
function getVSCodeSettingsPaths() {
|
|
@@ -3921,7 +4175,7 @@ function describeFailBehavior(value) {
|
|
|
3921
4175
|
return "Block all commands until the service is restored.";
|
|
3922
4176
|
case "ask":
|
|
3923
4177
|
default:
|
|
3924
|
-
return "
|
|
4178
|
+
return "Use the agent's approval dialog when supported; otherwise block until approval is available.";
|
|
3925
4179
|
}
|
|
3926
4180
|
}
|
|
3927
4181
|
function describeInstallMode(value) {
|
|
@@ -4160,7 +4414,7 @@ function discoverE2EKeys() {
|
|
|
4160
4414
|
} catch {}
|
|
4161
4415
|
}
|
|
4162
4416
|
try {
|
|
4163
|
-
const files = readdirSync2(dir).filter((
|
|
4417
|
+
const files = readdirSync2(dir).filter((f) => f.startsWith("e2e-key.") && f.endsWith(".bak"));
|
|
4164
4418
|
for (const file of files) {
|
|
4165
4419
|
const fullPath = join(dir, file);
|
|
4166
4420
|
try {
|
|
@@ -4442,16 +4696,16 @@ function copyToClipboard(text) {
|
|
|
4442
4696
|
{ cmd: "xclip", args: ["-selection", "clipboard"] },
|
|
4443
4697
|
{ cmd: "xsel", args: ["--clipboard", "--input"] }
|
|
4444
4698
|
]) {
|
|
4445
|
-
const
|
|
4699
|
+
const result = spawnSync2(candidate.cmd, candidate.args, {
|
|
4446
4700
|
input: text,
|
|
4447
4701
|
stdio: ["pipe", "ignore", "ignore"]
|
|
4448
4702
|
});
|
|
4449
|
-
if (
|
|
4703
|
+
if (result.status === 0 && !result.error)
|
|
4450
4704
|
return true;
|
|
4451
4705
|
}
|
|
4452
4706
|
return false;
|
|
4453
4707
|
}
|
|
4454
|
-
const result =
|
|
4708
|
+
const result = spawnSync2(cmd, args, {
|
|
4455
4709
|
input: text,
|
|
4456
4710
|
stdio: ["pipe", "ignore", "ignore"]
|
|
4457
4711
|
});
|
|
@@ -4511,6 +4765,12 @@ async function showPairingPresentation(params) {
|
|
|
4511
4765
|
function saveEnvConfig(config) {
|
|
4512
4766
|
const envPath = join(getAgentApproveDir(), "env");
|
|
4513
4767
|
const configSetAt = config.configSetAt ?? Math.floor(Date.now() / 1000);
|
|
4768
|
+
const hasBackgroundPreference = config.preserved?.AGENTAPPROVE_FILTER_BACKGROUND_ACTIVITY !== undefined;
|
|
4769
|
+
const preserved = {
|
|
4770
|
+
AGENTAPPROVE_FILTER_BACKGROUND_ACTIVITY: "true",
|
|
4771
|
+
...!hasBackgroundPreference ? { AGENTAPPROVE_BACKGROUND_FILTER_SYNC_PENDING: "true" } : {},
|
|
4772
|
+
...config.preserved
|
|
4773
|
+
};
|
|
4514
4774
|
const retentionDisplay = `${config.retentionDays ?? 30}`;
|
|
4515
4775
|
const e2eEnabled = config.e2eEnabled !== false;
|
|
4516
4776
|
const content = `# Agent Approve Configuration
|
|
@@ -4540,7 +4800,7 @@ AGENTAPPROVE_E2E_ENABLED=${e2eEnabled ? "true" : "false"}
|
|
|
4540
4800
|
|
|
4541
4801
|
# Hook behavior when API is unreachable: "allow" | "deny" | "ask"
|
|
4542
4802
|
AGENTAPPROVE_FAIL_BEHAVIOR=${config.failBehavior || "ask"}
|
|
4543
|
-
${renderPreservedEnvSection(
|
|
4803
|
+
${renderPreservedEnvSection(preserved)}
|
|
4544
4804
|
# Settings in this file sync from your Agent Approve account settings, so
|
|
4545
4805
|
# manual edits here are overwritten on the next config sync.
|
|
4546
4806
|
# To change settings, run: npx agentapprove install
|
|
@@ -4569,14 +4829,14 @@ function isCredentialManagerAvailable() {
|
|
|
4569
4829
|
async function storeTokenInKeychain(token, options) {
|
|
4570
4830
|
if (isKeychainAvailable()) {
|
|
4571
4831
|
try {
|
|
4572
|
-
|
|
4832
|
+
spawnSync2("security", [
|
|
4573
4833
|
"delete-generic-password",
|
|
4574
4834
|
"-s",
|
|
4575
4835
|
KEYCHAIN_SERVICE,
|
|
4576
4836
|
"-a",
|
|
4577
4837
|
KEYCHAIN_ACCOUNT
|
|
4578
4838
|
], { stdio: "ignore" });
|
|
4579
|
-
const addResult =
|
|
4839
|
+
const addResult = spawnSync2("security", [
|
|
4580
4840
|
"add-generic-password",
|
|
4581
4841
|
"-s",
|
|
4582
4842
|
KEYCHAIN_SERVICE,
|
|
@@ -4600,8 +4860,8 @@ async function storeTokenInKeychain(token, options) {
|
|
|
4600
4860
|
}
|
|
4601
4861
|
if (isCredentialManagerAvailable()) {
|
|
4602
4862
|
try {
|
|
4603
|
-
|
|
4604
|
-
const addResult =
|
|
4863
|
+
spawnSync2("cmdkey", [`/delete:${CREDENTIAL_TARGET}`], { stdio: "ignore" });
|
|
4864
|
+
const addResult = spawnSync2("cmdkey", [
|
|
4605
4865
|
`/generic:${CREDENTIAL_TARGET}`,
|
|
4606
4866
|
"/user:agentapprove",
|
|
4607
4867
|
`/pass:${token}`
|
|
@@ -4624,7 +4884,7 @@ function readTokenFromKeychain() {
|
|
|
4624
4884
|
if (!isKeychainAvailable())
|
|
4625
4885
|
return null;
|
|
4626
4886
|
try {
|
|
4627
|
-
const result =
|
|
4887
|
+
const result = spawnSync2("security", [
|
|
4628
4888
|
"find-generic-password",
|
|
4629
4889
|
"-s",
|
|
4630
4890
|
KEYCHAIN_SERVICE,
|
|
@@ -4707,39 +4967,27 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4707
4967
|
const hooksConfig = useTopLevelHooks ? config : config[agent.hooksKey];
|
|
4708
4968
|
const installedHooks = [];
|
|
4709
4969
|
if (agentId === "openclaw") {
|
|
4710
|
-
const
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
|
|
4728
|
-
failBehavior: "ask",
|
|
4729
|
-
privacyTier: "full"
|
|
4970
|
+
const result = await installOpenClaw({
|
|
4971
|
+
spec: OPENCLAW_PLUGIN_SPEC,
|
|
4972
|
+
version: OPENCLAW_PLUGIN_VERSION,
|
|
4973
|
+
mode,
|
|
4974
|
+
readVersion: readOpenClawInstalledVersion,
|
|
4975
|
+
readConfig: () => {
|
|
4976
|
+
if (!existsSync2(agent.configPath))
|
|
4977
|
+
return {};
|
|
4978
|
+
const current = JSON.parse(readFileSync(agent.configPath, "utf8"));
|
|
4979
|
+
if (!current || typeof current !== "object" || Array.isArray(current)) {
|
|
4980
|
+
throw new Error("OpenClaw configuration must be a JSON object; no settings were overwritten.");
|
|
4981
|
+
}
|
|
4982
|
+
return current;
|
|
4983
|
+
},
|
|
4984
|
+
writeConfig: (updated) => writeJsonConfig(agent.configPath, updated),
|
|
4985
|
+
confirmReplacement: async (message) => {
|
|
4986
|
+
const answer = await ce({ message, initialValue: false });
|
|
4987
|
+
return !lD(answer) && answer === true;
|
|
4730
4988
|
}
|
|
4731
|
-
};
|
|
4732
|
-
|
|
4733
|
-
config.hooks = {};
|
|
4734
|
-
}
|
|
4735
|
-
const hooks = config.hooks;
|
|
4736
|
-
if (!hooks.internal) {
|
|
4737
|
-
hooks.internal = {};
|
|
4738
|
-
}
|
|
4739
|
-
hooks.internal.enabled = true;
|
|
4740
|
-
writeJsonConfig(agent.configPath, config);
|
|
4741
|
-
installedHooks.push(installResult.label);
|
|
4742
|
-
return { success: true, backupPath, hooks: installedHooks };
|
|
4989
|
+
});
|
|
4990
|
+
return { ...result, backupPath, hooks: result.success ? [result.label] : [] };
|
|
4743
4991
|
}
|
|
4744
4992
|
if (agentId === "opencode") {
|
|
4745
4993
|
const installResult = installOpenCodePluginViaCli();
|
|
@@ -4779,7 +5027,7 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4779
5027
|
installedHooks.push(installResult.label);
|
|
4780
5028
|
return { success: true, backupPath, hooks: installedHooks };
|
|
4781
5029
|
}
|
|
4782
|
-
const hooksToInstall = mode === "observe" ? agent.hooks.filter((
|
|
5030
|
+
const hooksToInstall = mode === "observe" ? agent.hooks.filter((h) => !h.isApprovalHook) : agent.hooks;
|
|
4783
5031
|
for (const hook of hooksToInstall) {
|
|
4784
5032
|
const hookPath = join(hooksDir, hook.file);
|
|
4785
5033
|
const hookCommand = buildHookCommand(hookPath, agentId);
|
|
@@ -4790,7 +5038,7 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4790
5038
|
const hookArray = hooksConfig[hook.name];
|
|
4791
5039
|
const hasMatcher = hook.hasMatcher ?? true;
|
|
4792
5040
|
const hookTimeout = hook.timeout;
|
|
4793
|
-
const existingIdx = hookArray.findIndex((
|
|
5041
|
+
const existingIdx = hookArray.findIndex((h) => h.hooks?.some((hookScript) => {
|
|
4794
5042
|
if (typeof hookScript === "string")
|
|
4795
5043
|
return hookScript.includes("agentapprove");
|
|
4796
5044
|
if (typeof hookScript === "object" && hookScript.command)
|
|
@@ -4814,7 +5062,7 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4814
5062
|
const hookArray = hooksConfig[hook.name];
|
|
4815
5063
|
const hasMatcher = hook.hasMatcher ?? true;
|
|
4816
5064
|
const hookTimeout = hook.timeout;
|
|
4817
|
-
const existingIdx = hookArray.findIndex((
|
|
5065
|
+
const existingIdx = hookArray.findIndex((h) => h.hooks?.some((hookScript) => {
|
|
4818
5066
|
if (typeof hookScript === "string")
|
|
4819
5067
|
return hookScript.includes("agentapprove");
|
|
4820
5068
|
if (typeof hookScript === "object" && hookScript.command)
|
|
@@ -4839,56 +5087,13 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4839
5087
|
if (typeof config["version"] !== "number") {
|
|
4840
5088
|
config["version"] = 1;
|
|
4841
5089
|
}
|
|
4842
|
-
|
|
4843
|
-
const needsStopTimeout = hook.name === "stop" || hook.name === "subagentStop";
|
|
4844
|
-
const isApproval = hook.isApprovalHook;
|
|
4845
|
-
const hookEntry = { command: hookCommand };
|
|
4846
|
-
if (needsStopTimeout) {
|
|
4847
|
-
hookEntry.timeout = 600;
|
|
4848
|
-
hookEntry.loop_limit = 10;
|
|
4849
|
-
} else if (isApproval) {
|
|
4850
|
-
hookEntry.timeout = 300;
|
|
4851
|
-
}
|
|
4852
|
-
if (!existing) {
|
|
4853
|
-
hooksConfig[hook.name] = [hookEntry];
|
|
4854
|
-
} else if (Array.isArray(existing)) {
|
|
4855
|
-
const ourIdx = existing.findIndex((h2) => {
|
|
4856
|
-
if (typeof h2 === "object" && h2 !== null && "command" in h2) {
|
|
4857
|
-
return h2.command.includes("agentapprove");
|
|
4858
|
-
}
|
|
4859
|
-
if (typeof h2 === "string")
|
|
4860
|
-
return h2.includes("agentapprove");
|
|
4861
|
-
return false;
|
|
4862
|
-
});
|
|
4863
|
-
if (ourIdx >= 0) {
|
|
4864
|
-
existing[ourIdx] = hookEntry;
|
|
4865
|
-
} else {
|
|
4866
|
-
existing.push(hookEntry);
|
|
4867
|
-
}
|
|
4868
|
-
hooksConfig[hook.name] = existing.map((h2) => {
|
|
4869
|
-
if (typeof h2 === "string")
|
|
4870
|
-
return { command: h2 };
|
|
4871
|
-
return h2;
|
|
4872
|
-
});
|
|
4873
|
-
} else if (typeof existing === "object" && existing !== null) {
|
|
4874
|
-
if ("command" in existing && existing.command.includes("agentapprove")) {
|
|
4875
|
-
hooksConfig[hook.name] = [hookEntry];
|
|
4876
|
-
} else {
|
|
4877
|
-
hooksConfig[hook.name] = [existing, hookEntry];
|
|
4878
|
-
}
|
|
4879
|
-
} else if (typeof existing === "string") {
|
|
4880
|
-
if (existing.includes("agentapprove")) {
|
|
4881
|
-
hooksConfig[hook.name] = [hookEntry];
|
|
4882
|
-
} else {
|
|
4883
|
-
hooksConfig[hook.name] = [{ command: existing }, hookEntry];
|
|
4884
|
-
}
|
|
4885
|
-
}
|
|
5090
|
+
hooksConfig[hook.name] = upsertCursorHook(hooksConfig[hook.name], cursorHookEntry(hook.name, hookCommand, hook.isApprovalHook));
|
|
4886
5091
|
installedHooks.push(hook.name);
|
|
4887
5092
|
} else if (agentId === "windsurf") {
|
|
4888
5093
|
const existing = hooksConfig[hook.name];
|
|
4889
5094
|
const existingArray = Array.isArray(existing) ? existing : existing && typeof existing === "object" ? [existing] : typeof existing === "string" ? [{ command: existing }] : [];
|
|
4890
|
-
const cleanedArray = existingArray.filter((
|
|
4891
|
-
const command =
|
|
5095
|
+
const cleanedArray = existingArray.filter((h) => {
|
|
5096
|
+
const command = h.command || h.powershell || "";
|
|
4892
5097
|
return !command.includes("agentapprove");
|
|
4893
5098
|
});
|
|
4894
5099
|
cleanedArray.push({
|
|
@@ -4902,10 +5107,10 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4902
5107
|
hooksConfig[hook.name] = [];
|
|
4903
5108
|
}
|
|
4904
5109
|
const hookArray = hooksConfig[hook.name];
|
|
4905
|
-
const cleanedArray = hookArray.filter((
|
|
4906
|
-
if (!
|
|
5110
|
+
const cleanedArray = hookArray.filter((h) => {
|
|
5111
|
+
if (!h.hooks || !Array.isArray(h.hooks))
|
|
4907
5112
|
return true;
|
|
4908
|
-
return !
|
|
5113
|
+
return !h.hooks.some((hookScript) => {
|
|
4909
5114
|
if (typeof hookScript === "string")
|
|
4910
5115
|
return hookScript.includes("agentapprove");
|
|
4911
5116
|
if (typeof hookScript === "object" && hookScript !== null && "command" in hookScript) {
|
|
@@ -4925,8 +5130,8 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4925
5130
|
hooksConfig[hook.name] = [];
|
|
4926
5131
|
}
|
|
4927
5132
|
const hookArray = hooksConfig[hook.name];
|
|
4928
|
-
const cleanedArray = hookArray.filter((
|
|
4929
|
-
return !(
|
|
5133
|
+
const cleanedArray = hookArray.filter((h) => {
|
|
5134
|
+
return !(h.command || "").includes("agentapprove");
|
|
4930
5135
|
});
|
|
4931
5136
|
const hookEntry = {
|
|
4932
5137
|
type: "command",
|
|
@@ -4952,7 +5157,7 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4952
5157
|
const hookArray = hooksConfig[hook.name];
|
|
4953
5158
|
const hookTimeout = hook.timeout;
|
|
4954
5159
|
const isApproval = hook.isApprovalHook;
|
|
4955
|
-
const existingIdx = hookArray.findIndex((
|
|
5160
|
+
const existingIdx = hookArray.findIndex((h) => h.hooks?.some((hookScript) => {
|
|
4956
5161
|
if (typeof hookScript === "string")
|
|
4957
5162
|
return hookScript.includes("agentapprove");
|
|
4958
5163
|
if (typeof hookScript === "object" && hookScript.command)
|
|
@@ -4988,8 +5193,8 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4988
5193
|
hooksConfig[hook.name] = [];
|
|
4989
5194
|
}
|
|
4990
5195
|
const hookArray = hooksConfig[hook.name];
|
|
4991
|
-
const cleanedArray = hookArray.filter((
|
|
4992
|
-
const cmd =
|
|
5196
|
+
const cleanedArray = hookArray.filter((h) => {
|
|
5197
|
+
const cmd = h.bash || h.command || "";
|
|
4993
5198
|
return !cmd.includes("agentapprove");
|
|
4994
5199
|
});
|
|
4995
5200
|
const hookEntry = {
|
|
@@ -5009,16 +5214,16 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
5009
5214
|
}
|
|
5010
5215
|
}
|
|
5011
5216
|
if (mode === "observe") {
|
|
5012
|
-
const approvalHooks = agent.hooks.filter((
|
|
5217
|
+
const approvalHooks = agent.hooks.filter((h) => h.isApprovalHook);
|
|
5013
5218
|
for (const hook of approvalHooks) {
|
|
5014
5219
|
if (hooksConfig[hook.name]) {
|
|
5015
5220
|
if (agentId === "claude-code" || agentId === "gemini-cli" || agentId === "codex" || agentId === "openhands") {
|
|
5016
5221
|
const hookArray = hooksConfig[hook.name];
|
|
5017
5222
|
if (Array.isArray(hookArray)) {
|
|
5018
|
-
const cleaned = hookArray.filter((
|
|
5019
|
-
if (!
|
|
5223
|
+
const cleaned = hookArray.filter((h) => {
|
|
5224
|
+
if (!h.hooks || !Array.isArray(h.hooks))
|
|
5020
5225
|
return true;
|
|
5021
|
-
return !
|
|
5226
|
+
return !h.hooks.some((hs) => {
|
|
5022
5227
|
if (typeof hs === "string")
|
|
5023
5228
|
return hs.includes("agentapprove");
|
|
5024
5229
|
if (typeof hs === "object" && hs !== null && "command" in hs) {
|
|
@@ -5036,7 +5241,7 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
5036
5241
|
} else if (agentId === "vscode-agent") {
|
|
5037
5242
|
const hookArray = hooksConfig[hook.name];
|
|
5038
5243
|
if (Array.isArray(hookArray)) {
|
|
5039
|
-
const cleaned = hookArray.filter((
|
|
5244
|
+
const cleaned = hookArray.filter((h) => !(h.command || "").includes("agentapprove"));
|
|
5040
5245
|
if (cleaned.length === 0) {
|
|
5041
5246
|
delete hooksConfig[hook.name];
|
|
5042
5247
|
} else {
|
|
@@ -5046,8 +5251,8 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
5046
5251
|
} else if (agentId === "copilot-cli") {
|
|
5047
5252
|
const hookArray = hooksConfig[hook.name];
|
|
5048
5253
|
if (Array.isArray(hookArray)) {
|
|
5049
|
-
const cleaned = hookArray.filter((
|
|
5050
|
-
const cmd =
|
|
5254
|
+
const cleaned = hookArray.filter((h) => {
|
|
5255
|
+
const cmd = h.bash || h.command || "";
|
|
5051
5256
|
return !cmd.includes("agentapprove");
|
|
5052
5257
|
});
|
|
5053
5258
|
if (cleaned.length === 0) {
|
|
@@ -5059,12 +5264,12 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
5059
5264
|
} else if (agentId === "cursor") {
|
|
5060
5265
|
const existing = hooksConfig[hook.name];
|
|
5061
5266
|
if (Array.isArray(existing)) {
|
|
5062
|
-
const cleaned = existing.filter((
|
|
5063
|
-
if (typeof
|
|
5064
|
-
return !
|
|
5267
|
+
const cleaned = existing.filter((h) => {
|
|
5268
|
+
if (typeof h === "object" && h !== null && "command" in h) {
|
|
5269
|
+
return !h.command.includes("agentapprove");
|
|
5065
5270
|
}
|
|
5066
|
-
if (typeof
|
|
5067
|
-
return !
|
|
5271
|
+
if (typeof h === "string")
|
|
5272
|
+
return !h.includes("agentapprove");
|
|
5068
5273
|
return true;
|
|
5069
5274
|
});
|
|
5070
5275
|
if (cleaned.length === 0) {
|
|
@@ -5076,13 +5281,13 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
5076
5281
|
} else if (agentId === "windsurf") {
|
|
5077
5282
|
const existing = hooksConfig[hook.name];
|
|
5078
5283
|
if (Array.isArray(existing)) {
|
|
5079
|
-
const cleaned = existing.filter((
|
|
5080
|
-
if (typeof
|
|
5081
|
-
const cmd =
|
|
5284
|
+
const cleaned = existing.filter((h) => {
|
|
5285
|
+
if (typeof h === "object" && h !== null) {
|
|
5286
|
+
const cmd = h.command || h.powershell || "";
|
|
5082
5287
|
return !cmd.includes("agentapprove");
|
|
5083
5288
|
}
|
|
5084
|
-
if (typeof
|
|
5085
|
-
return !
|
|
5289
|
+
if (typeof h === "string")
|
|
5290
|
+
return !h.includes("agentapprove");
|
|
5086
5291
|
return true;
|
|
5087
5292
|
});
|
|
5088
5293
|
if (cleaned.length === 0) {
|
|
@@ -5163,15 +5368,7 @@ codex_hooks = true`;
|
|
|
5163
5368
|
for (const hook of agent.hooks) {
|
|
5164
5369
|
const hookPath = join(hooksDir, hook.file);
|
|
5165
5370
|
const hookCmd = buildHookCommand(hookPath, agentId);
|
|
5166
|
-
const
|
|
5167
|
-
const isApproval = hook.isApprovalHook;
|
|
5168
|
-
const entry = { command: hookCmd };
|
|
5169
|
-
if (needsStopTimeout) {
|
|
5170
|
-
entry.timeout = 600;
|
|
5171
|
-
entry.loop_limit = 10;
|
|
5172
|
-
} else if (isApproval) {
|
|
5173
|
-
entry.timeout = 300;
|
|
5174
|
-
}
|
|
5371
|
+
const entry = cursorHookEntry(hook.name, hookCmd, hook.isApprovalHook);
|
|
5175
5372
|
hooksObj[hook.name] = [entry];
|
|
5176
5373
|
}
|
|
5177
5374
|
return JSON.stringify({ version: 1, hooks: hooksObj }, null, 2);
|
|
@@ -5264,14 +5461,8 @@ codex_hooks = true`;
|
|
|
5264
5461
|
plugins: {
|
|
5265
5462
|
entries: {
|
|
5266
5463
|
openclaw: {
|
|
5267
|
-
|
|
5268
|
-
config: {
|
|
5269
|
-
apiUrl: API_URL,
|
|
5270
|
-
apiVersion: "v001",
|
|
5271
|
-
timeout: 300,
|
|
5272
|
-
failBehavior: "ask",
|
|
5273
|
-
privacyTier: "full"
|
|
5274
|
-
}
|
|
5464
|
+
hooks: { allowConversationAccess: true },
|
|
5465
|
+
config: {}
|
|
5275
5466
|
}
|
|
5276
5467
|
}
|
|
5277
5468
|
},
|
|
@@ -5284,10 +5475,15 @@ codex_hooks = true`;
|
|
|
5284
5475
|
"",
|
|
5285
5476
|
` openclaw plugins install ${OPENCLAW_PLUGIN_SPEC}`,
|
|
5286
5477
|
"",
|
|
5287
|
-
"
|
|
5478
|
+
"Review the source and capabilities in the terminal; declining stops installation.",
|
|
5479
|
+
"Merge the following settings into your OpenClaw config, preserving existing entries and permissions:",
|
|
5288
5480
|
"",
|
|
5289
5481
|
configJson,
|
|
5290
5482
|
"",
|
|
5483
|
+
CONVERSATION_ACCESS_NOTICE,
|
|
5484
|
+
"Then run: openclaw plugins enable openclaw (review any capabilities requested).",
|
|
5485
|
+
"",
|
|
5486
|
+
"Settings follow ~/.agentapprove/env. Existing explicit OpenClaw config overrides take precedence and are preserved.",
|
|
5291
5487
|
'Hosted installs can also set config.token/config.apiUrl/etc. with OpenClaw env substitution such as "${AGENTAPPROVE_TOKEN}".',
|
|
5292
5488
|
"",
|
|
5293
5489
|
"Restart the OpenClaw gateway to activate."
|
|
@@ -5337,6 +5533,7 @@ codex_hooks = true`;
|
|
|
5337
5533
|
" pip install --user cryptography httpx",
|
|
5338
5534
|
" # On uv-managed Python (PEP 668 EXTERNALLY-MANAGED): instead run",
|
|
5339
5535
|
" # uv pip install --system --break-system-packages --python $(which python3.12) cryptography httpx",
|
|
5536
|
+
" hermes config set plugins.entries.agentapprove.allow_gateway_injection true",
|
|
5340
5537
|
" hermes plugins enable agentapprove",
|
|
5341
5538
|
"",
|
|
5342
5539
|
"The plugin reads your existing Agent Approve config from ~/.agentapprove/env.",
|
|
@@ -5349,6 +5546,8 @@ codex_hooks = true`;
|
|
|
5349
5546
|
}
|
|
5350
5547
|
function describeDownloadTerminalFailure(kind) {
|
|
5351
5548
|
switch (kind) {
|
|
5549
|
+
case "rate_limited":
|
|
5550
|
+
return "Hook download limit reached. Please wait a few minutes, then rerun the installer. Existing hook files were kept.";
|
|
5352
5551
|
case "token_expired":
|
|
5353
5552
|
return "Hook download stopped: your saved token has expired. Run `npx agentapprove refresh` to re-pair, or run the installer again to choose Refresh / Re-pair.";
|
|
5354
5553
|
case "token_invalid":
|
|
@@ -5366,95 +5565,37 @@ function describeDownloadTerminalFailure(kind) {
|
|
|
5366
5565
|
async function copyHookScripts2(hooksDir, token, files, options = {}) {
|
|
5367
5566
|
return copyHookScripts(hooksDir, token, files, {
|
|
5368
5567
|
apiUrl: options.apiUrl || API_URL,
|
|
5369
|
-
apiVersion: API_VERSION
|
|
5568
|
+
apiVersion: API_VERSION,
|
|
5569
|
+
onRateLimit: options.onRateLimit,
|
|
5570
|
+
optionalFiles: options.optionalFiles
|
|
5370
5571
|
});
|
|
5371
5572
|
}
|
|
5372
5573
|
function readOpenClawInstalledVersion() {
|
|
5373
|
-
|
|
5574
|
+
try {
|
|
5575
|
+
const result = spawnSync2("openclaw", ["plugins", "inspect", "openclaw", "--json"], {
|
|
5576
|
+
encoding: "utf8",
|
|
5577
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
5578
|
+
timeout: 30000,
|
|
5579
|
+
shell: process.platform === "win32"
|
|
5580
|
+
});
|
|
5581
|
+
if (result.status === 0) {
|
|
5582
|
+
const metadata = JSON.parse(result.stdout);
|
|
5583
|
+
if (metadata.plugin?.packageName === "@agentapprove/openclaw" && typeof metadata.plugin.rootDir === "string") {
|
|
5584
|
+
return readJsonPackageVersion(join(metadata.plugin.rootDir, "package.json"));
|
|
5585
|
+
}
|
|
5586
|
+
return null;
|
|
5587
|
+
}
|
|
5588
|
+
} catch {}
|
|
5589
|
+
for (const packagePath of [
|
|
5374
5590
|
join(homedir(), ".openclaw", "npm", "node_modules", "@agentapprove", "openclaw", "package.json"),
|
|
5375
5591
|
join(homedir(), ".openclaw", "extensions", "openclaw", "package.json")
|
|
5376
|
-
]
|
|
5377
|
-
|
|
5378
|
-
if (
|
|
5379
|
-
|
|
5380
|
-
}
|
|
5381
|
-
try {
|
|
5382
|
-
const pkg = JSON.parse(readFileSync(packagePath, "utf-8"));
|
|
5383
|
-
if (typeof pkg.version === "string") {
|
|
5384
|
-
return pkg.version;
|
|
5385
|
-
}
|
|
5386
|
-
} catch {}
|
|
5592
|
+
]) {
|
|
5593
|
+
const version = readJsonPackageVersion(packagePath);
|
|
5594
|
+
if (version)
|
|
5595
|
+
return version;
|
|
5387
5596
|
}
|
|
5388
5597
|
return null;
|
|
5389
5598
|
}
|
|
5390
|
-
function isOpenClawAlreadyExistsError(err) {
|
|
5391
|
-
if (!err || typeof err !== "object")
|
|
5392
|
-
return false;
|
|
5393
|
-
const e2 = err;
|
|
5394
|
-
const blob = [
|
|
5395
|
-
Buffer.isBuffer(e2.stderr) ? e2.stderr.toString() : String(e2.stderr || ""),
|
|
5396
|
-
Buffer.isBuffer(e2.stdout) ? e2.stdout.toString() : String(e2.stdout || ""),
|
|
5397
|
-
String(e2.message || "")
|
|
5398
|
-
].join(`
|
|
5399
|
-
`);
|
|
5400
|
-
return /plugin already exists|delete it first|use .*plugins update/i.test(blob);
|
|
5401
|
-
}
|
|
5402
|
-
function installOpenClawPluginViaCli() {
|
|
5403
|
-
const installCmd = (force) => `openclaw plugins install ${OPENCLAW_PLUGIN_SPEC}${force ? " --force" : ""}`;
|
|
5404
|
-
const tryInstall = (force) => {
|
|
5405
|
-
try {
|
|
5406
|
-
execSync(installCmd(force), { stdio: "pipe" });
|
|
5407
|
-
return { ok: true };
|
|
5408
|
-
} catch (err) {
|
|
5409
|
-
return { ok: false, err };
|
|
5410
|
-
}
|
|
5411
|
-
};
|
|
5412
|
-
let firstAttempt = tryInstall(false);
|
|
5413
|
-
if (!firstAttempt.ok && isOpenClawAlreadyExistsError(firstAttempt.err)) {
|
|
5414
|
-
const existingVersion = readOpenClawInstalledVersion();
|
|
5415
|
-
if (existingVersion === OPENCLAW_PLUGIN_VERSION) {
|
|
5416
|
-
return {
|
|
5417
|
-
success: true,
|
|
5418
|
-
version: existingVersion,
|
|
5419
|
-
label: `Agent Approve plugin v${existingVersion} (already installed)`
|
|
5420
|
-
};
|
|
5421
|
-
}
|
|
5422
|
-
const forceAttempt = tryInstall(true);
|
|
5423
|
-
if (!forceAttempt.ok) {
|
|
5424
|
-
const message = forceAttempt.err instanceof Error ? forceAttempt.err.message : "unknown error";
|
|
5425
|
-
return { success: false, error: message, label: "Agent Approve plugin" };
|
|
5426
|
-
}
|
|
5427
|
-
firstAttempt = { ok: true };
|
|
5428
|
-
}
|
|
5429
|
-
if (!firstAttempt.ok) {
|
|
5430
|
-
const message = firstAttempt.err instanceof Error ? firstAttempt.err.message : "unknown error";
|
|
5431
|
-
return { success: false, error: message, label: "Agent Approve plugin" };
|
|
5432
|
-
}
|
|
5433
|
-
try {
|
|
5434
|
-
const installedVersion = readOpenClawInstalledVersion();
|
|
5435
|
-
if (!installedVersion) {
|
|
5436
|
-
return {
|
|
5437
|
-
success: true,
|
|
5438
|
-
label: "Agent Approve plugin (version not verified)"
|
|
5439
|
-
};
|
|
5440
|
-
}
|
|
5441
|
-
if (installedVersion !== OPENCLAW_PLUGIN_VERSION) {
|
|
5442
|
-
return {
|
|
5443
|
-
success: false,
|
|
5444
|
-
error: `OpenClaw installed ${installedVersion}, expected ${OPENCLAW_PLUGIN_VERSION}. Re-run after updating the published installer package.`,
|
|
5445
|
-
label: "Agent Approve plugin"
|
|
5446
|
-
};
|
|
5447
|
-
}
|
|
5448
|
-
return {
|
|
5449
|
-
success: true,
|
|
5450
|
-
version: installedVersion,
|
|
5451
|
-
label: `Agent Approve plugin v${installedVersion}`
|
|
5452
|
-
};
|
|
5453
|
-
} catch (err) {
|
|
5454
|
-
const message = err instanceof Error ? err.message : "unknown error";
|
|
5455
|
-
return { success: false, error: message, label: "Agent Approve plugin" };
|
|
5456
|
-
}
|
|
5457
|
-
}
|
|
5458
5599
|
function readJsonPackageVersion(packagePath) {
|
|
5459
5600
|
if (!existsSync2(packagePath)) {
|
|
5460
5601
|
return null;
|
|
@@ -5490,7 +5631,7 @@ function readOpenCodeInstalledVersion() {
|
|
|
5490
5631
|
}
|
|
5491
5632
|
function installOpenCodePluginViaCli() {
|
|
5492
5633
|
try {
|
|
5493
|
-
const result =
|
|
5634
|
+
const result = spawnSync2("opencode", ["plugin", OPENCODE_PLUGIN_SPEC, "--global", "--force"], {
|
|
5494
5635
|
encoding: "utf8",
|
|
5495
5636
|
stdio: ["ignore", "pipe", "pipe"]
|
|
5496
5637
|
});
|
|
@@ -5597,7 +5738,7 @@ function removePiPluginViaCli() {
|
|
|
5597
5738
|
};
|
|
5598
5739
|
}
|
|
5599
5740
|
}
|
|
5600
|
-
var HERMES_BUNDLE_SHA256 = "
|
|
5741
|
+
var HERMES_BUNDLE_SHA256 = "7a4b063c78bbbb9e5b60f34c7ac6eddf4715df47ef474e98367706947b3bd1db";
|
|
5601
5742
|
var HERMES_BUNDLE_FILENAME = `agentapprove-hermes-${HERMES_PLUGIN_VERSION}.tar.gz`;
|
|
5602
5743
|
var HERMES_PLUGIN_DIR = join(homedir(), ".hermes", "plugins", "agentapprove");
|
|
5603
5744
|
function findPython() {
|
|
@@ -5761,17 +5902,17 @@ function uvAvailable() {
|
|
|
5761
5902
|
function isExternallyManagedError(err) {
|
|
5762
5903
|
if (!err || typeof err !== "object")
|
|
5763
5904
|
return false;
|
|
5764
|
-
const
|
|
5765
|
-
const stderr = Buffer.isBuffer(
|
|
5766
|
-
const stdout = Buffer.isBuffer(
|
|
5767
|
-
const message = String(
|
|
5905
|
+
const e = err;
|
|
5906
|
+
const stderr = Buffer.isBuffer(e.stderr) ? e.stderr.toString() : String(e.stderr || "");
|
|
5907
|
+
const stdout = Buffer.isBuffer(e.stdout) ? e.stdout.toString() : String(e.stdout || "");
|
|
5908
|
+
const message = String(e.message || "");
|
|
5768
5909
|
const blob = `${stderr}
|
|
5769
5910
|
${stdout}
|
|
5770
5911
|
${message}`;
|
|
5771
5912
|
return /externally-managed-environment|PEP 668|managed by uv/i.test(blob);
|
|
5772
5913
|
}
|
|
5773
5914
|
function installHermesDepsAdaptive(pythonCommand, deps) {
|
|
5774
|
-
const depsArg = deps.map((
|
|
5915
|
+
const depsArg = deps.map((d) => `"${d}"`).join(" ");
|
|
5775
5916
|
try {
|
|
5776
5917
|
execSync(`${pythonCommand} -m pip install --user --quiet ${depsArg}`, { stdio: "pipe" });
|
|
5777
5918
|
return { ok: true };
|
|
@@ -5841,14 +5982,14 @@ function stageHermesBundle(bytes, targetDir) {
|
|
|
5841
5982
|
mkdirSync(dirname2(targetDir), { recursive: true });
|
|
5842
5983
|
if (existsSync2(targetDir)) {
|
|
5843
5984
|
backupPath = `${targetDir}.bak-${Date.now()}`;
|
|
5844
|
-
|
|
5985
|
+
renameSync2(targetDir, backupPath);
|
|
5845
5986
|
}
|
|
5846
5987
|
try {
|
|
5847
|
-
|
|
5988
|
+
renameSync2(stagedDir, targetDir);
|
|
5848
5989
|
} catch (err) {
|
|
5849
5990
|
if (backupPath) {
|
|
5850
5991
|
try {
|
|
5851
|
-
|
|
5992
|
+
renameSync2(backupPath, targetDir);
|
|
5852
5993
|
backupPath = null;
|
|
5853
5994
|
} catch {}
|
|
5854
5995
|
}
|
|
@@ -5864,7 +6005,7 @@ function stageHermesBundle(bytes, targetDir) {
|
|
|
5864
6005
|
if (backupPath) {
|
|
5865
6006
|
try {
|
|
5866
6007
|
rmSync2(targetDir, { recursive: true, force: true });
|
|
5867
|
-
|
|
6008
|
+
renameSync2(backupPath, targetDir);
|
|
5868
6009
|
backupPath = null;
|
|
5869
6010
|
} catch {}
|
|
5870
6011
|
}
|
|
@@ -5879,6 +6020,7 @@ function stageHermesBundle(bytes, targetDir) {
|
|
|
5879
6020
|
}
|
|
5880
6021
|
function enableHermesPluginForProfile(profile) {
|
|
5881
6022
|
try {
|
|
6023
|
+
enableHermesFollowUp(profile);
|
|
5882
6024
|
execSync(hermesEnableCmd(profile), { stdio: "pipe" });
|
|
5883
6025
|
return { success: true };
|
|
5884
6026
|
} catch (err) {
|
|
@@ -5950,10 +6092,10 @@ async function installHermesPluginViaCli() {
|
|
|
5950
6092
|
function isHermesDisableNoOp(err) {
|
|
5951
6093
|
if (!err || typeof err !== "object")
|
|
5952
6094
|
return false;
|
|
5953
|
-
const
|
|
5954
|
-
const stderr = Buffer.isBuffer(
|
|
5955
|
-
const stdout = Buffer.isBuffer(
|
|
5956
|
-
const haystack = `${
|
|
6095
|
+
const e = err;
|
|
6096
|
+
const stderr = Buffer.isBuffer(e.stderr) ? e.stderr.toString() : String(e.stderr || "");
|
|
6097
|
+
const stdout = Buffer.isBuffer(e.stdout) ? e.stdout.toString() : String(e.stdout || "");
|
|
6098
|
+
const haystack = `${e.message || ""}
|
|
5957
6099
|
${stderr}
|
|
5958
6100
|
${stdout}`.toLowerCase();
|
|
5959
6101
|
return haystack.includes("not enabled") || haystack.includes("not installed") || haystack.includes("is not enabled") || haystack.includes("plugin agentapprove not found") || haystack.includes("plugin 'agentapprove' not found");
|
|
@@ -5994,8 +6136,8 @@ function hermesProfilePluginStatus(profile) {
|
|
|
5994
6136
|
if (installed) {
|
|
5995
6137
|
try {
|
|
5996
6138
|
const configPy = readFileSync(join(dir, "config.py"), "utf-8");
|
|
5997
|
-
const
|
|
5998
|
-
version =
|
|
6139
|
+
const m = configPy.match(/^PLUGIN_VERSION\s*=\s*["']([^"']+)["']/m);
|
|
6140
|
+
version = m ? m[1] : null;
|
|
5999
6141
|
} catch {}
|
|
6000
6142
|
}
|
|
6001
6143
|
return { name: profile, isDefault: profile === HERMES_DEFAULT_PROFILE, installed, version };
|
|
@@ -6012,7 +6154,7 @@ function listHermesProfiles() {
|
|
|
6012
6154
|
}
|
|
6013
6155
|
}
|
|
6014
6156
|
} catch {}
|
|
6015
|
-
return [...names].sort((
|
|
6157
|
+
return [...names].sort((a, b) => a === HERMES_DEFAULT_PROFILE ? -1 : b === HERMES_DEFAULT_PROFILE ? 1 : a.localeCompare(b)).map(hermesProfilePluginStatus);
|
|
6016
6158
|
}
|
|
6017
6159
|
async function syncHermesProfiles(targetProfiles) {
|
|
6018
6160
|
try {
|
|
@@ -6060,7 +6202,7 @@ async function syncHermesProfiles(targetProfiles) {
|
|
|
6060
6202
|
const enabled = enableHermesPluginForProfile(profile);
|
|
6061
6203
|
results.push({ profile, success: enabled.success, error: enabled.error });
|
|
6062
6204
|
}
|
|
6063
|
-
return { ok: results.every((
|
|
6205
|
+
return { ok: results.every((r) => r.success), results };
|
|
6064
6206
|
}
|
|
6065
6207
|
var SYSTEM_DEPS = [
|
|
6066
6208
|
{
|
|
@@ -6193,7 +6335,7 @@ async function checkSystemDependencies() {
|
|
|
6193
6335
|
return true;
|
|
6194
6336
|
const pm = detectPackageManager();
|
|
6195
6337
|
const pmLabel = pm === "macos" ? "macOS (Homebrew)" : pm === "windows" ? "Windows" : pm === "apt" ? "apt (Debian/Ubuntu)" : pm === "dnf" ? "dnf (Fedora/RHEL)" : "apk (Alpine)";
|
|
6196
|
-
const requiredMissing = missing.filter((
|
|
6338
|
+
const requiredMissing = missing.filter((d) => d.required);
|
|
6197
6339
|
const lines = missing.map((dep) => {
|
|
6198
6340
|
const cmd = dep.install[pm];
|
|
6199
6341
|
return `${source_default.red("x")} ${source_default.bold(dep.name)} - ${dep.description}
|
|
@@ -6215,18 +6357,18 @@ async function checkSystemDependencies() {
|
|
|
6215
6357
|
const allSamePrefix = uniqueCommands.every((c) => c.startsWith("sudo apt-get") || c.startsWith("sudo dnf") || c.startsWith("apk") || c.startsWith("brew") || c.startsWith("winget"));
|
|
6216
6358
|
let combinedCommand = "";
|
|
6217
6359
|
if (allSamePrefix && pm === "apt") {
|
|
6218
|
-
combinedCommand = `sudo apt-get install -y ${requiredMissing.map((
|
|
6360
|
+
combinedCommand = `sudo apt-get install -y ${requiredMissing.map((d) => d.name === "base64" ? "coreutils" : d.name === "xxd" ? "xxd" : d.name).join(" ")}`;
|
|
6219
6361
|
} else if (allSamePrefix && pm === "dnf") {
|
|
6220
|
-
combinedCommand = `sudo dnf install -y ${requiredMissing.map((
|
|
6362
|
+
combinedCommand = `sudo dnf install -y ${requiredMissing.map((d) => d.name === "base64" ? "coreutils" : d.name === "xxd" ? "vim-common" : d.name).join(" ")}`;
|
|
6221
6363
|
} else if (allSamePrefix && pm === "alpine") {
|
|
6222
|
-
combinedCommand = `apk add ${requiredMissing.map((
|
|
6364
|
+
combinedCommand = `apk add ${requiredMissing.map((d) => d.name === "base64" ? "coreutils" : d.name === "xxd" ? "vim" : d.name).join(" ")}`;
|
|
6223
6365
|
} else if (allSamePrefix && pm === "macos") {
|
|
6224
|
-
const brewPkgs = requiredMissing.filter((
|
|
6366
|
+
const brewPkgs = requiredMissing.filter((d) => d.install.macos !== "included with macOS").map((d) => d.name === "xxd" ? "vim" : d.name);
|
|
6225
6367
|
if (brewPkgs.length > 0) {
|
|
6226
6368
|
combinedCommand = `brew install ${brewPkgs.join(" ")}`;
|
|
6227
6369
|
}
|
|
6228
6370
|
} else if (pm === "windows") {
|
|
6229
|
-
const winPkgs = requiredMissing.filter((
|
|
6371
|
+
const winPkgs = requiredMissing.filter((d) => d.install.windows !== "included with Git Bash").map((d) => d.install.windows);
|
|
6230
6372
|
if (winPkgs.length > 0) {
|
|
6231
6373
|
combinedCommand = winPkgs.join(" && ");
|
|
6232
6374
|
}
|
|
@@ -6249,9 +6391,9 @@ async function checkSystemDependencies() {
|
|
|
6249
6391
|
try {
|
|
6250
6392
|
execSync(combinedCommand, { stdio: "pipe" });
|
|
6251
6393
|
installSpinner.stop("Dependencies installed");
|
|
6252
|
-
const stillMissing = requiredMissing.filter((
|
|
6394
|
+
const stillMissing = requiredMissing.filter((d) => !checkCommand(d.name));
|
|
6253
6395
|
if (stillMissing.length > 0) {
|
|
6254
|
-
v2.warn(`Could not verify: ${stillMissing.map((
|
|
6396
|
+
v2.warn(`Could not verify: ${stillMissing.map((d) => d.name).join(", ")}. Continuing anyway.`);
|
|
6255
6397
|
}
|
|
6256
6398
|
} catch (err) {
|
|
6257
6399
|
installSpinner.stop("Installation failed");
|
|
@@ -6332,7 +6474,7 @@ function describeExistingTokenStatus(preflight) {
|
|
|
6332
6474
|
}
|
|
6333
6475
|
async function promptTokenRecoveryAction(preflight) {
|
|
6334
6476
|
if (preflight.kind === "expired") {
|
|
6335
|
-
const
|
|
6477
|
+
const choice = await le({
|
|
6336
6478
|
message: "Your saved token has expired. How would you like to continue?",
|
|
6337
6479
|
options: [
|
|
6338
6480
|
{ value: "refresh", label: "Refresh token", hint: "Keeps the existing encryption key; settings resync from your account on the next event" },
|
|
@@ -6340,9 +6482,9 @@ async function promptTokenRecoveryAction(preflight) {
|
|
|
6340
6482
|
{ value: "cancel", label: "Cancel", hint: "Exit the installer" }
|
|
6341
6483
|
]
|
|
6342
6484
|
});
|
|
6343
|
-
if (lD(
|
|
6485
|
+
if (lD(choice))
|
|
6344
6486
|
return "cancel";
|
|
6345
|
-
return
|
|
6487
|
+
return choice;
|
|
6346
6488
|
}
|
|
6347
6489
|
const choice = await le({
|
|
6348
6490
|
message: "Your saved token is no longer valid. How would you like to continue?",
|
|
@@ -6375,9 +6517,9 @@ async function installCommand() {
|
|
|
6375
6517
|
let existingKeyId = null;
|
|
6376
6518
|
if (existingConfig) {
|
|
6377
6519
|
existingTokenPreview = hasExistingToken ? existingConfig.token.slice(0, 15) + "..." : "Not set";
|
|
6378
|
-
const
|
|
6379
|
-
if (existsSync2(
|
|
6380
|
-
const keyHex = readFileSync(
|
|
6520
|
+
const e2eKeyPath = join(getAgentApproveDir(), "e2e-key");
|
|
6521
|
+
if (existsSync2(e2eKeyPath)) {
|
|
6522
|
+
const keyHex = readFileSync(e2eKeyPath, "utf-8").trim();
|
|
6381
6523
|
existingKeyId = createHash("sha256").update(Buffer.from(keyHex, "hex")).digest("hex").slice(0, 8);
|
|
6382
6524
|
}
|
|
6383
6525
|
}
|
|
@@ -6405,6 +6547,9 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6405
6547
|
he("Installation cancelled");
|
|
6406
6548
|
process.exit(0);
|
|
6407
6549
|
}
|
|
6550
|
+
if (selectedAgents.includes("openclaw")) {
|
|
6551
|
+
v2.info(CONVERSATION_ACCESS_NOTICE);
|
|
6552
|
+
}
|
|
6408
6553
|
const setupProfileSummary = existingConfig ? formatSetupProfileBlock("Existing config", getInitialInstallConfig("existing-config", existingConfig), [
|
|
6409
6554
|
`Connection token: ${existingTokenPreview} - ${describeExistingTokenStatus(existingTokenPreflight)}.`,
|
|
6410
6555
|
...existingKeyId ? [`Encryption key ID: ${existingKeyId} - already installed for this computer.`] : []
|
|
@@ -6474,7 +6619,7 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6474
6619
|
message: "If Agent Approve is unreachable, hooks should:",
|
|
6475
6620
|
initialValue: failBehavior,
|
|
6476
6621
|
options: [
|
|
6477
|
-
{ value: "ask", label: "Ask", hint: "
|
|
6622
|
+
{ value: "ask", label: "Ask", hint: "Ask locally when supported; otherwise block (recommended)" },
|
|
6478
6623
|
{ value: "deny", label: "Deny", hint: "Block all commands until service is restored" },
|
|
6479
6624
|
{ value: "allow", label: "Allow", hint: "Allow all commands to proceed without approval" }
|
|
6480
6625
|
]
|
|
@@ -6640,7 +6785,7 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6640
6785
|
} else if (shouldCreateFreshPairing(connectionMethod)) {
|
|
6641
6786
|
const pairingMethod = connectionMethod;
|
|
6642
6787
|
if (backupOldKeyTo) {
|
|
6643
|
-
|
|
6788
|
+
renameSync2(existingKeyPath, backupOldKeyTo);
|
|
6644
6789
|
v2.success(`Old key backed up to ${backupOldKeyTo}`);
|
|
6645
6790
|
backupOldKeyTo = null;
|
|
6646
6791
|
}
|
|
@@ -6685,7 +6830,9 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6685
6830
|
process.exit(0);
|
|
6686
6831
|
} else if (result) {
|
|
6687
6832
|
token = result.token;
|
|
6688
|
-
|
|
6833
|
+
if (["minimal", "summary", "full"].includes(result.privacy)) {
|
|
6834
|
+
finalPrivacy = result.privacy;
|
|
6835
|
+
}
|
|
6689
6836
|
email = result.email;
|
|
6690
6837
|
apiUrl = result.apiUrl || pairingApiBase;
|
|
6691
6838
|
if (e2eUserKey && e2eKeyId) {
|
|
@@ -6745,19 +6892,28 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6745
6892
|
if (hookDownloadPlan.files.length > 0) {
|
|
6746
6893
|
const downloadSpinner = _2();
|
|
6747
6894
|
downloadSpinner.start("Downloading hook scripts");
|
|
6748
|
-
const downloadResult = await copyHookScripts2(hooksDir, token, hookDownloadPlan.files, {
|
|
6895
|
+
const downloadResult = await copyHookScripts2(hooksDir, token, hookDownloadPlan.files, {
|
|
6896
|
+
apiUrl,
|
|
6897
|
+
optionalFiles: BACKGROUND_FILTER_FILES,
|
|
6898
|
+
onRateLimit: (_file, seconds) => downloadSpinner.message(`Download limit reached. Retrying in ${seconds}s…`)
|
|
6899
|
+
});
|
|
6749
6900
|
const summary = formatHookDownloadSummary(hookDownloadPlan);
|
|
6750
6901
|
if (downloadResult.terminalFailure) {
|
|
6751
|
-
downloadSpinner.stop(`
|
|
6902
|
+
downloadSpinner.stop(`Fetched ${downloadResult.downloaded} of ${hookDownloadPlan.files.length} hook files; no changes saved`);
|
|
6752
6903
|
const message = describeDownloadTerminalFailure(downloadResult.terminalFailure.kind);
|
|
6753
6904
|
v2.error(message);
|
|
6754
6905
|
he("Hook download stopped before completion.");
|
|
6755
6906
|
process.exit(1);
|
|
6756
6907
|
} else if (downloadResult.failed.length > 0) {
|
|
6757
|
-
downloadSpinner.stop(`
|
|
6758
|
-
v2.warn(`
|
|
6908
|
+
downloadSpinner.stop(`Hook installation incomplete (${downloadResult.downloaded} files fetched)`);
|
|
6909
|
+
v2.warn(`Could not install: ${downloadResult.failed.join(", ")}`);
|
|
6910
|
+
he("Required hook downloads are incomplete. Please rerun the installer.");
|
|
6911
|
+
process.exit(1);
|
|
6759
6912
|
} else {
|
|
6760
|
-
downloadSpinner.stop(`Hook
|
|
6913
|
+
downloadSpinner.stop(`Hook files fetched (${downloadResult.downloaded} files: ${summary})`);
|
|
6914
|
+
if (downloadResult.optionalFailed.length) {
|
|
6915
|
+
v2.warn("Background activity filters could not be refreshed. Any previous copy is retained; required hooks are ready.");
|
|
6916
|
+
}
|
|
6761
6917
|
}
|
|
6762
6918
|
} else {
|
|
6763
6919
|
v2.success("No hook scripts needed for the selected agents");
|
|
@@ -6797,6 +6953,8 @@ AGENTAPPROVE_E2E_MODE=${installMode}
|
|
|
6797
6953
|
he("Installation cancelled");
|
|
6798
6954
|
process.exit(0);
|
|
6799
6955
|
}
|
|
6956
|
+
const failedSetupAgents = new Set;
|
|
6957
|
+
const nextSteps = [];
|
|
6800
6958
|
if (installMethod === "auto") {
|
|
6801
6959
|
const filesToModify = [];
|
|
6802
6960
|
for (const agentId of selectedAgents) {
|
|
@@ -6808,16 +6966,16 @@ AGENTAPPROVE_E2E_MODE=${installMode}
|
|
|
6808
6966
|
filesToModify.push(join(homedir(), ".codex", "config.toml"));
|
|
6809
6967
|
}
|
|
6810
6968
|
if (agentId === "opencode") {
|
|
6811
|
-
filesToModify.push(
|
|
6969
|
+
filesToModify.push("OpenCode plugin cache");
|
|
6812
6970
|
}
|
|
6813
6971
|
if (agentId === "openclaw") {
|
|
6814
|
-
filesToModify.push(
|
|
6972
|
+
filesToModify.push("OpenClaw plugin registry");
|
|
6815
6973
|
}
|
|
6816
6974
|
if (agentId === "pi") {
|
|
6817
|
-
filesToModify.push("Pi package registry
|
|
6975
|
+
filesToModify.push("Pi package registry");
|
|
6818
6976
|
}
|
|
6819
6977
|
if (agentId === "hermes") {
|
|
6820
|
-
filesToModify.push(
|
|
6978
|
+
filesToModify.push("~/.hermes/plugins/agentapprove/ (plugin update; mobile follow-up enabled)");
|
|
6821
6979
|
}
|
|
6822
6980
|
if (agentId === "vscode-agent") {
|
|
6823
6981
|
const vsCodeVariants = findInstalledVSCodeVariants();
|
|
@@ -6826,10 +6984,13 @@ AGENTAPPROVE_E2E_MODE=${installMode}
|
|
|
6826
6984
|
}
|
|
6827
6985
|
}
|
|
6828
6986
|
}
|
|
6829
|
-
|
|
6987
|
+
const homePrefix = `${homedir()}/`;
|
|
6988
|
+
const fileSummary = filesToModify.map((path) => path.startsWith(homePrefix) ? `~/${path.slice(homePrefix.length)}` : path);
|
|
6989
|
+
v2.step("Files to be modified");
|
|
6990
|
+
v2.message(`${fileSummary.join(`
|
|
6830
6991
|
`)}
|
|
6831
6992
|
|
|
6832
|
-
|
|
6993
|
+
Timestamped backups will be created.`);
|
|
6833
6994
|
const confirm = await ce({
|
|
6834
6995
|
message: "Proceed with automatic installation?"
|
|
6835
6996
|
});
|
|
@@ -6841,13 +7002,17 @@ Backups will be created with timestamp`, "Files to be modified");
|
|
|
6841
7002
|
const agent = AGENTS[agentId];
|
|
6842
7003
|
const spinner = _2();
|
|
6843
7004
|
const spinnerMsg = agentId === "pi" ? `Installing ${agent.name} extension` : agentId === "openclaw" || agentId === "hermes" ? `Installing ${agent.name} plugin` : `Configuring ${agent.name}`;
|
|
6844
|
-
|
|
7005
|
+
if (agentId !== "openclaw")
|
|
7006
|
+
spinner.start(spinnerMsg);
|
|
6845
7007
|
const result = await installHooksForAgent(agentId, hooksDir, installMode);
|
|
6846
7008
|
if (result.success) {
|
|
6847
7009
|
const installedHookNames = result.hooks.join(", ");
|
|
6848
7010
|
const backupMsg = result.backupPath ? source_default.dim(` (backup created)`) : "";
|
|
6849
7011
|
const agentName = source_default.cyan(agent.name);
|
|
6850
|
-
|
|
7012
|
+
if (agentId === "openclaw")
|
|
7013
|
+
v2.success(`${agentName}: ${installedHookNames}${backupMsg}`);
|
|
7014
|
+
else
|
|
7015
|
+
spinner.stop(`${agentName}: ${installedHookNames}${backupMsg}`);
|
|
6851
7016
|
if (agentId === "vscode-agent") {
|
|
6852
7017
|
const vsCodeSpinner = _2();
|
|
6853
7018
|
vsCodeSpinner.start("Registering hook path in VS Code settings");
|
|
@@ -6865,10 +7030,12 @@ Backups will be created with timestamp`, "Files to be modified");
|
|
|
6865
7030
|
}
|
|
6866
7031
|
if (agentId === "codex") {
|
|
6867
7032
|
v2.info(source_default.dim(" Updated ~/.codex/config.toml to enable codex_hooks"));
|
|
7033
|
+
nextSteps.push(`Turn on the Codex hooks in ChatGPT settings. Codex leaves each one off until you do.
|
|
7034
|
+
` + ` https://www.agentapprove.com/docs/integrations/setup-by-agent`);
|
|
6868
7035
|
}
|
|
6869
7036
|
if (agentId === "copilot-cli") {
|
|
6870
|
-
|
|
6871
|
-
` + `
|
|
7037
|
+
nextSteps.push(`Copy the GitHub Copilot CLI hooks into each repository you want covered.
|
|
7038
|
+
` + ` cp ${agent.configPath} .github/hooks/agentapprove.json`);
|
|
6872
7039
|
}
|
|
6873
7040
|
if (agentId === "hermes") {
|
|
6874
7041
|
try {
|
|
@@ -6876,14 +7043,18 @@ Backups will be created with timestamp`, "Files to be modified");
|
|
|
6876
7043
|
if (others.length > 0) {
|
|
6877
7044
|
const lines = others.map((pr) => ` ${pr.name.padEnd(20)} ${pr.installed ? `installed v${pr.version ?? "?"}` : "not installed"}`).join(`
|
|
6878
7045
|
`);
|
|
6879
|
-
|
|
7046
|
+
nextSteps.push(`Add Agent Approve to your other Hermes profiles. Only the default one was set up.
|
|
6880
7047
|
` + `${lines}
|
|
6881
|
-
` + `
|
|
7048
|
+
` + ` Run: npx agentapprove profiles`);
|
|
6882
7049
|
}
|
|
6883
7050
|
} catch {}
|
|
6884
7051
|
}
|
|
6885
7052
|
} else {
|
|
6886
|
-
|
|
7053
|
+
failedSetupAgents.add(agentId);
|
|
7054
|
+
if (agentId === "openclaw")
|
|
7055
|
+
v2.error(`${agent.name} configuration failed`);
|
|
7056
|
+
else
|
|
7057
|
+
spinner.stop(`${agent.name} configuration failed`);
|
|
6887
7058
|
if (agentId === "openclaw") {
|
|
6888
7059
|
v2.warn(`Could not install ${OPENCLAW_PLUGIN_SPEC} via OpenClaw CLI.
|
|
6889
7060
|
` + ` Error: ${result.error || "unknown"}
|
|
@@ -6904,7 +7075,8 @@ Backups will be created with timestamp`, "Files to be modified");
|
|
|
6904
7075
|
` + ` 4. Write the SHA-256 to ~/.hermes/plugins/agentapprove/.bundle-hash
|
|
6905
7076
|
` + ` 5. pip install --user cryptography httpx
|
|
6906
7077
|
` + ` (uv-managed Python: uv pip install --system --break-system-packages --python $(which python3.12) cryptography httpx)
|
|
6907
|
-
` + ` 6. hermes
|
|
7078
|
+
` + ` 6. hermes config set plugins.entries.agentapprove.allow_gateway_injection true
|
|
7079
|
+
` + ` 7. hermes plugins enable agentapprove
|
|
6908
7080
|
` + ` Then re-run: npx agentapprove`);
|
|
6909
7081
|
}
|
|
6910
7082
|
}
|
|
@@ -6919,17 +7091,105 @@ Backups will be created with timestamp`, "Files to be modified");
|
|
|
6919
7091
|
message: "Press Enter when done"
|
|
6920
7092
|
});
|
|
6921
7093
|
}
|
|
7094
|
+
const integrationChecks = inspectSetup(selectedAgents).map((item) => failedSetupAgents.has(item.agent) ? { ...item, status: "failed", reason: "invalid_config" } : item);
|
|
7095
|
+
writeFileSync(join(getAgentApproveDir(), "setup-agents.json"), JSON.stringify(selectedAgents), { mode: 384 });
|
|
6922
7096
|
const modeDesc = hasE2EKey ? installMode === "observe" ? source_default.cyan("E2E Observe Mode") + " - All events encrypted, no approval hooks" : source_default.green("E2E Approval Mode") + " - Commands sent via encrypted channel for policy evaluation" : "Standard mode (no E2E keys found)";
|
|
6923
7097
|
me(`Mode: ${modeDesc}
|
|
6924
7098
|
|
|
6925
7099
|
npx agentapprove pair Link a new iOS device
|
|
7100
|
+
npx agentapprove check Re-check this computer's configuration (local only, changes nothing)
|
|
6926
7101
|
npx agentapprove status Show current configuration
|
|
6927
7102
|
npx agentapprove profiles Manage Agent Approve across Hermes profiles
|
|
6928
7103
|
npx agentapprove disable Deregister hooks/plugins, keep local state
|
|
6929
7104
|
npx agentapprove uninstall Remove hooks/plugins and keep local state
|
|
6930
7105
|
npx agentapprove purge Remove hooks/plugins and delete local state
|
|
6931
7106
|
npx agentapprove restore Restore original configs`, "Useful commands");
|
|
6932
|
-
|
|
7107
|
+
if (nextSteps.length > 0) {
|
|
7108
|
+
me(formatNextSteps(nextSteps), "Next steps");
|
|
7109
|
+
}
|
|
7110
|
+
ge(installOutro(integrationChecks) || "Open Agent Approve on your iPhone and finish setting up.");
|
|
7111
|
+
}
|
|
7112
|
+
function inspectSetup(agentIds) {
|
|
7113
|
+
const existing = readExistingConfig();
|
|
7114
|
+
return agentIds.map((agentId) => {
|
|
7115
|
+
const agent = AGENTS[agentId];
|
|
7116
|
+
const result = (status, reason) => ({ agent: agentId, status, reason });
|
|
7117
|
+
if (!agent)
|
|
7118
|
+
return result("manual", "manual_step");
|
|
7119
|
+
if (!existing?.token)
|
|
7120
|
+
return result("failed", "not_configured");
|
|
7121
|
+
if (existsSync2(join(getAgentApproveDir(), DISABLED_STATE_FILENAME)))
|
|
7122
|
+
return result("failed", "disabled");
|
|
7123
|
+
try {
|
|
7124
|
+
if (existing.e2eEnabled !== false) {
|
|
7125
|
+
const keyPath = join(getAgentApproveDir(), "e2e-key");
|
|
7126
|
+
if (!existsSync2(keyPath))
|
|
7127
|
+
return result("failed", "missing_files");
|
|
7128
|
+
if (!/^[a-fA-F0-9]{64}$/.test(readFileSync(keyPath, "utf8").trim()))
|
|
7129
|
+
return result("failed", "invalid_config");
|
|
7130
|
+
}
|
|
7131
|
+
if (agentId === "pi" || agentId === "hermes") {
|
|
7132
|
+
const output = execSync(agentId === "pi" ? "pi list" : "hermes plugins list", { encoding: "utf8", timeout: 5000, stdio: ["ignore", "pipe", "ignore"] });
|
|
7133
|
+
const ready = agentId === "pi" ? output.includes("@agentapprove/pi") : /^.*agentapprove.*enabled/im.test(output);
|
|
7134
|
+
return result(ready ? "ready" : "failed", ready ? "verified" : "not_configured");
|
|
7135
|
+
}
|
|
7136
|
+
const configPath = agentId === "copilot-cli" ? join(process.cwd(), ".github/hooks/agentapprove.json") : agent.configPath;
|
|
7137
|
+
if (agentId === "copilot-cli" && !existsSync2(configPath))
|
|
7138
|
+
return result("manual", "manual_step");
|
|
7139
|
+
const config = readJsonConfig(configPath);
|
|
7140
|
+
if (agentId === "opencode") {
|
|
7141
|
+
const ready = Array.isArray(config.plugin) && config.plugin.some((p) => typeof p === "string" && p.includes("@agentapprove/opencode"));
|
|
7142
|
+
return result(ready ? "ready" : "failed", ready ? "verified" : "not_configured");
|
|
7143
|
+
}
|
|
7144
|
+
if (agentId === "openclaw") {
|
|
7145
|
+
const plugins = config.plugins;
|
|
7146
|
+
const ready = plugins?.enabled !== false && plugins?.entries?.openclaw?.enabled === true;
|
|
7147
|
+
return result(ready ? "ready" : "failed", ready ? "verified" : "not_configured");
|
|
7148
|
+
}
|
|
7149
|
+
if (agentId === "vscode-agent") {
|
|
7150
|
+
const registered = findInstalledVSCodeVariants().some(({ path }) => {
|
|
7151
|
+
const locations = readJsoncConfig(path)["chat.hookFilesLocations"];
|
|
7152
|
+
return locations?.["~/.agentapprove/hooks"] === true || locations?.[join(getAgentApproveDir(), "hooks")] === true;
|
|
7153
|
+
});
|
|
7154
|
+
if (!registered)
|
|
7155
|
+
return result("manual", "manual_step");
|
|
7156
|
+
}
|
|
7157
|
+
if (agentId === "codex" && !/codex_hooks\s*=\s*true/.test(readFileSync(join(homedir(), ".codex/config.toml"), "utf8")))
|
|
7158
|
+
return result("failed", "not_configured");
|
|
7159
|
+
const filesReady = (file) => {
|
|
7160
|
+
const path = join(getAgentApproveDir(), "hooks", file);
|
|
7161
|
+
return existsSync2(path) && statSync(path).size > 0 && (!file.endsWith(".sh") || (statSync(path).mode & 73) !== 0);
|
|
7162
|
+
};
|
|
7163
|
+
if (!SHARED_HOOK_FILES.filter((file) => !BACKGROUND_FILTER_FILES.includes(file)).every(filesReady))
|
|
7164
|
+
return result("failed", "missing_files");
|
|
7165
|
+
if (spawnSync2("bash", ["-c", "command -v curl >/dev/null && command -v jq >/dev/null && command -v openssl >/dev/null"], { timeout: 5000 }).status !== 0)
|
|
7166
|
+
return result("failed", "missing_dependency");
|
|
7167
|
+
if (isAntigravityAgent(agentId)) {
|
|
7168
|
+
if (!existsSync2(join(getAntigravityPluginRoot(agentId), "plugin.json")))
|
|
7169
|
+
return result("failed", "missing_files");
|
|
7170
|
+
const mode = existing.e2eMode ?? "approval";
|
|
7171
|
+
const hooks = mode === "observe" ? agent.hooks.filter((h) => h.name !== "Stop") : agent.hooks;
|
|
7172
|
+
return checkHookConfiguration(agentId, config, "agentapprove", hooks, "approval", filesReady, (file, name) => buildAntigravityHookCommand(join(getAgentApproveDir(), "hooks", file), agentId, name, mode));
|
|
7173
|
+
}
|
|
7174
|
+
return checkHookConfiguration(agentId, config, agent.hooksKey, agent.hooks, existing.e2eMode ?? "approval", filesReady, (file) => buildHookCommand(join(getAgentApproveDir(), "hooks", file), agentId));
|
|
7175
|
+
} catch {
|
|
7176
|
+
return result("failed", "invalid_config");
|
|
7177
|
+
}
|
|
7178
|
+
});
|
|
7179
|
+
}
|
|
7180
|
+
async function checkSetupCommand() {
|
|
7181
|
+
const selectionFile = join(getAgentApproveDir(), "setup-agents.json");
|
|
7182
|
+
let agents;
|
|
7183
|
+
try {
|
|
7184
|
+
agents = JSON.parse(readFileSync(selectionFile, "utf8")).filter((id) => typeof id === "string" && (id in AGENTS));
|
|
7185
|
+
} catch {
|
|
7186
|
+
agents = detectInstalledAgents();
|
|
7187
|
+
}
|
|
7188
|
+
const { lines, failed } = checkSummary(inspectSetup(agents));
|
|
7189
|
+
for (const line of lines)
|
|
7190
|
+
(failed ? console.error : console.log)(line);
|
|
7191
|
+
if (failed)
|
|
7192
|
+
process.exitCode = 1;
|
|
6933
7193
|
}
|
|
6934
7194
|
async function profilesCommand() {
|
|
6935
7195
|
console.clear();
|
|
@@ -6991,6 +7251,8 @@ async function profilesCommand() {
|
|
|
6991
7251
|
toUpdate.length ? `Update to v${HERMES_PLUGIN_VERSION}: ${toUpdate.join(", ")}` : null,
|
|
6992
7252
|
toRemove.length ? `Remove from: ${toRemove.join(", ")}` : null
|
|
6993
7253
|
].filter(Boolean);
|
|
7254
|
+
if (toSync.length)
|
|
7255
|
+
planLines.push("Allow mobile follow-up replies in the selected Hermes profiles.");
|
|
6994
7256
|
me(planLines.join(`
|
|
6995
7257
|
`), "Planned changes");
|
|
6996
7258
|
const confirm = await ce({ message: "Apply these changes?" });
|
|
@@ -7009,20 +7271,20 @@ async function profilesCommand() {
|
|
|
7009
7271
|
process.exit(1);
|
|
7010
7272
|
}
|
|
7011
7273
|
s.stop(sync.ok ? "Done" : "Done (some profiles failed)");
|
|
7012
|
-
for (const
|
|
7013
|
-
const action = toUpdate.includes(
|
|
7014
|
-
if (
|
|
7015
|
-
v2.success(`${
|
|
7274
|
+
for (const r of sync.results) {
|
|
7275
|
+
const action = toUpdate.includes(r.profile) ? "updated to" : "installed";
|
|
7276
|
+
if (r.success)
|
|
7277
|
+
v2.success(`${r.profile}: Agent Approve ${action} v${HERMES_PLUGIN_VERSION}`);
|
|
7016
7278
|
else
|
|
7017
|
-
v2.error(`${
|
|
7279
|
+
v2.error(`${r.profile}: ${r.error ?? "failed"}`);
|
|
7018
7280
|
}
|
|
7019
7281
|
}
|
|
7020
7282
|
for (const profile of toRemove) {
|
|
7021
|
-
const
|
|
7022
|
-
if (
|
|
7283
|
+
const r = removeHermesPluginFromProfile(profile);
|
|
7284
|
+
if (r.success)
|
|
7023
7285
|
v2.success(`${profile}: Agent Approve removed`);
|
|
7024
7286
|
else
|
|
7025
|
-
v2.warn(`${profile}: removal partial (${
|
|
7287
|
+
v2.warn(`${profile}: removal partial (${r.error ?? "unknown"})`);
|
|
7026
7288
|
}
|
|
7027
7289
|
ge("Hermes profiles updated.");
|
|
7028
7290
|
}
|
|
@@ -7121,27 +7383,27 @@ async function statusCommand() {
|
|
|
7121
7383
|
if (isAntigravityAgent(agentId)) {
|
|
7122
7384
|
const bundle = config.agentapprove;
|
|
7123
7385
|
if (bundle) {
|
|
7124
|
-
const installedHooks = agent.hooks.filter((
|
|
7125
|
-
const hookEntry = bundle[
|
|
7386
|
+
const installedHooks = agent.hooks.filter((h) => {
|
|
7387
|
+
const hookEntry = bundle[h.name];
|
|
7126
7388
|
return !!hookEntry && JSON.stringify(hookEntry).includes("agentapprove");
|
|
7127
7389
|
});
|
|
7128
7390
|
if (installedHooks.length > 0) {
|
|
7129
|
-
console.log(` ${source_default.green("✓")} ${agent.name}: ${installedHooks.map((
|
|
7391
|
+
console.log(` ${source_default.green("✓")} ${agent.name}: ${installedHooks.map((h) => formatHookStatusLabel(h.name)).join(", ")}`);
|
|
7130
7392
|
}
|
|
7131
7393
|
}
|
|
7132
7394
|
continue;
|
|
7133
7395
|
}
|
|
7134
7396
|
const hooksConfig = agent.hooksKey === "" ? config : config[agent.hooksKey];
|
|
7135
7397
|
if (hooksConfig) {
|
|
7136
|
-
const installedHooks = agent.hooks.filter((
|
|
7137
|
-
const hookEntry = hooksConfig[
|
|
7398
|
+
const installedHooks = agent.hooks.filter((h) => {
|
|
7399
|
+
const hookEntry = hooksConfig[h.name];
|
|
7138
7400
|
if (!hookEntry)
|
|
7139
7401
|
return false;
|
|
7140
7402
|
const str = JSON.stringify(hookEntry);
|
|
7141
7403
|
return str.includes("agentapprove");
|
|
7142
7404
|
});
|
|
7143
7405
|
if (installedHooks.length > 0) {
|
|
7144
|
-
console.log(` ${source_default.green("✓")} ${agent.name}: ${installedHooks.map((
|
|
7406
|
+
console.log(` ${source_default.green("✓")} ${agent.name}: ${installedHooks.map((h) => formatHookStatusLabel(h.name)).join(", ")}`);
|
|
7145
7407
|
}
|
|
7146
7408
|
}
|
|
7147
7409
|
}
|
|
@@ -7235,7 +7497,7 @@ async function disableCommand() {
|
|
|
7235
7497
|
const tmpPath = `${statePath}.tmp-${process.pid}`;
|
|
7236
7498
|
writeFileSync(tmpPath, JSON.stringify(merged, null, 2) + `
|
|
7237
7499
|
`, { mode: 384 });
|
|
7238
|
-
|
|
7500
|
+
renameSync2(tmpPath, statePath);
|
|
7239
7501
|
failed = false;
|
|
7240
7502
|
} catch {
|
|
7241
7503
|
failed = true;
|
|
@@ -7375,7 +7637,7 @@ async function enableCommand() {
|
|
|
7375
7637
|
const legacyDisabledPath = join(aaDir, "env.disabled");
|
|
7376
7638
|
const statePath = join(aaDir, DISABLED_STATE_FILENAME);
|
|
7377
7639
|
if (!existsSync2(envPath) && existsSync2(legacyDisabledPath)) {
|
|
7378
|
-
|
|
7640
|
+
renameSync2(legacyDisabledPath, envPath);
|
|
7379
7641
|
console.log(source_default.green(`
|
|
7380
7642
|
✓ Restored ~/.agentapprove/env (legacy disable).`));
|
|
7381
7643
|
}
|
|
@@ -7662,16 +7924,16 @@ async function restoreCommand() {
|
|
|
7662
7924
|
console.log(source_default.cyan(`
|
|
7663
7925
|
Restoring original configurations...
|
|
7664
7926
|
`));
|
|
7665
|
-
const { readdirSync
|
|
7927
|
+
const { readdirSync, copyFileSync } = await import("fs");
|
|
7666
7928
|
for (const [agentId, agent] of Object.entries(AGENTS)) {
|
|
7667
7929
|
const configDir = dirname2(agent.configPath);
|
|
7668
7930
|
if (!existsSync2(configDir))
|
|
7669
7931
|
continue;
|
|
7670
|
-
const files =
|
|
7671
|
-
const backups = files.filter((
|
|
7932
|
+
const files = readdirSync(configDir);
|
|
7933
|
+
const backups = files.filter((f) => f.startsWith(agent.configPath.split("/").pop()) && f.includes(".backup.")).sort().reverse();
|
|
7672
7934
|
if (backups.length > 0) {
|
|
7673
7935
|
const latestBackup = join(configDir, backups[0]);
|
|
7674
|
-
|
|
7936
|
+
copyFileSync(latestBackup, agent.configPath);
|
|
7675
7937
|
console.log(` ${source_default.green("✓")} ${agent.name} restored from ${backups[0]}`);
|
|
7676
7938
|
}
|
|
7677
7939
|
}
|
|
@@ -7745,6 +8007,7 @@ ${source_default.yellow("Commands:")}
|
|
|
7745
8007
|
${source_default.green("pair")} Link a new iOS device or repair E2E pairing
|
|
7746
8008
|
${source_default.green("refresh")} Generate a new token and reuse current pairing context
|
|
7747
8009
|
${source_default.green("init-repo")} Add GitHub Copilot CLI hooks to current repo (.github/hooks/)
|
|
8010
|
+
${source_default.green("check")} Re-check this computer's configuration (local only, changes nothing)
|
|
7748
8011
|
${source_default.green("status")} Show current configuration and installed hooks
|
|
7749
8012
|
${source_default.green("profiles")} Install/remove Agent Approve across Hermes profiles
|
|
7750
8013
|
${source_default.green("disable")} Deregister hooks/plugins from all agents, keep local state
|
|
@@ -7940,11 +8203,11 @@ async function pairCommand() {
|
|
|
7940
8203
|
v2.info("E2E encryption disabled — event content will be visible on the web dashboard");
|
|
7941
8204
|
updateEnvValue("AGENTAPPROVE_E2E_ENABLED", "false");
|
|
7942
8205
|
} else if (selectedKeyId === "__generate__") {
|
|
7943
|
-
const currentKey = keys.find((
|
|
8206
|
+
const currentKey = keys.find((k) => k.isCurrent);
|
|
7944
8207
|
if (currentKey) {
|
|
7945
|
-
const
|
|
7946
|
-
const backupPath = join(
|
|
7947
|
-
|
|
8208
|
+
const agentApproveDir = getAgentApproveDir();
|
|
8209
|
+
const backupPath = join(agentApproveDir, `e2e-key.${currentKey.keyId}.bak`);
|
|
8210
|
+
renameSync2(currentKey.path, backupPath);
|
|
7948
8211
|
v2.info(`Previous key backed up (${currentKey.keyId})`);
|
|
7949
8212
|
}
|
|
7950
8213
|
e2eUserKey = randomBytes(32).toString("hex");
|
|
@@ -7961,7 +8224,7 @@ async function pairCommand() {
|
|
|
7961
8224
|
});
|
|
7962
8225
|
v2.success(`New key generated (${e2eKeyId})`);
|
|
7963
8226
|
} else {
|
|
7964
|
-
const selectedKey = keys.find((
|
|
8227
|
+
const selectedKey = keys.find((k) => k.keyId === selectedKeyId);
|
|
7965
8228
|
if (!selectedKey) {
|
|
7966
8229
|
v2.error("Selected key not found.");
|
|
7967
8230
|
process.exit(1);
|
|
@@ -8077,6 +8340,10 @@ async function updateHookScriptsWithToken(token, apiUrl) {
|
|
|
8077
8340
|
if (!existsSync2(hooksDir)) {
|
|
8078
8341
|
throw new Error("Hooks directory not found");
|
|
8079
8342
|
}
|
|
8343
|
+
const filters = await copyHookScripts2(hooksDir, token, BACKGROUND_FILTER_FILES, { apiUrl });
|
|
8344
|
+
if (filters.failed.length || filters.terminalFailure) {
|
|
8345
|
+
v2.warn("Background activity filters could not be refreshed. The previous copy is retained.");
|
|
8346
|
+
}
|
|
8080
8347
|
const hookFiles = [
|
|
8081
8348
|
"claude-pre-tool.sh",
|
|
8082
8349
|
"claude-post-tool.sh",
|
|
@@ -8120,6 +8387,9 @@ async function main() {
|
|
|
8120
8387
|
case "pair":
|
|
8121
8388
|
await pairCommand();
|
|
8122
8389
|
break;
|
|
8390
|
+
case "check":
|
|
8391
|
+
await checkSetupCommand();
|
|
8392
|
+
break;
|
|
8123
8393
|
case "status":
|
|
8124
8394
|
await statusCommand();
|
|
8125
8395
|
break;
|
|
@@ -8158,7 +8428,7 @@ async function main() {
|
|
|
8158
8428
|
}
|
|
8159
8429
|
}
|
|
8160
8430
|
main().then(() => {
|
|
8161
|
-
process.exit(0);
|
|
8431
|
+
process.exit(process.exitCode ?? 0);
|
|
8162
8432
|
}).catch((error) => {
|
|
8163
8433
|
console.error(source_default.red("Error:"), error.message);
|
|
8164
8434
|
process.exit(1);
|