@agentwares/agentguard 0.1.6 → 0.1.9
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/CHANGELOG.md +89 -0
- package/README.md +223 -16
- package/dist/audit-2YCMHMCP.js +17 -0
- package/dist/audit-2YCMHMCP.js.map +1 -0
- package/dist/chunk-3O6KWT3E.js +345 -0
- package/dist/chunk-3O6KWT3E.js.map +1 -0
- package/dist/chunk-5WRI5ZAA.js +31 -0
- package/dist/chunk-5WRI5ZAA.js.map +1 -0
- package/dist/chunk-6S7LYVOC.js +1033 -0
- package/dist/chunk-6S7LYVOC.js.map +1 -0
- package/dist/chunk-6TUQD666.js +828 -0
- package/dist/chunk-6TUQD666.js.map +1 -0
- package/dist/chunk-BKXXTWIS.js +119 -0
- package/dist/chunk-BKXXTWIS.js.map +1 -0
- package/dist/chunk-D66U3PVB.js +529 -0
- package/dist/chunk-D66U3PVB.js.map +1 -0
- package/dist/chunk-HPYZ3JDX.js +206 -0
- package/dist/chunk-HPYZ3JDX.js.map +1 -0
- package/dist/chunk-KRKZGAJ3.js +769 -0
- package/dist/chunk-KRKZGAJ3.js.map +1 -0
- package/dist/chunk-SUXQTT3X.js +1268 -0
- package/dist/chunk-SUXQTT3X.js.map +1 -0
- package/dist/chunk-TW5KJREH.js +190 -0
- package/dist/chunk-TW5KJREH.js.map +1 -0
- package/dist/chunk-VQWQ5TOM.js +113 -0
- package/dist/chunk-VQWQ5TOM.js.map +1 -0
- package/dist/chunk-X4M7YWQA.js +270 -0
- package/dist/chunk-X4M7YWQA.js.map +1 -0
- package/dist/chunk-ZSLWPKXI.js +1144 -0
- package/dist/chunk-ZSLWPKXI.js.map +1 -0
- package/dist/cli.js +8 -4725
- package/dist/cli.js.map +1 -1
- package/dist/fixtures/crm-server.js +6 -1272
- package/dist/fixtures/crm-server.js.map +1 -1
- package/dist/fixtures/demo-agent.js +4 -115
- package/dist/fixtures/demo-agent.js.map +1 -1
- package/dist/index.d.ts +76 -10
- package/dist/index.js +246 -5087
- package/dist/index.js.map +1 -1
- package/dist/init-CWROGV5I.js +15 -0
- package/dist/init-CWROGV5I.js.map +1 -0
- package/dist/proxy-3Z5YEZ4R.js +154 -0
- package/dist/proxy-3Z5YEZ4R.js.map +1 -0
- package/dist/tools-3LLDG3XQ.js +15 -0
- package/dist/tools-3LLDG3XQ.js.map +1 -0
- package/llms.txt +4 -0
- package/package.json +9 -3
- package/server.json +2 -2
|
@@ -0,0 +1,1268 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__commonJS,
|
|
3
|
+
__toESM
|
|
4
|
+
} from "./chunk-5WRI5ZAA.js";
|
|
5
|
+
|
|
6
|
+
// ../../node_modules/.pnpm/standardwebhooks@1.0.0/node_modules/standardwebhooks/dist/timing_safe_equal.js
|
|
7
|
+
var require_timing_safe_equal = __commonJS({
|
|
8
|
+
"../../node_modules/.pnpm/standardwebhooks@1.0.0/node_modules/standardwebhooks/dist/timing_safe_equal.js"(exports) {
|
|
9
|
+
"use strict";
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.timingSafeEqual = void 0;
|
|
12
|
+
function assert(expr, msg = "") {
|
|
13
|
+
if (!expr) {
|
|
14
|
+
throw new Error(msg);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function timingSafeEqual(a, b) {
|
|
18
|
+
if (a.byteLength !== b.byteLength) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (!(a instanceof DataView)) {
|
|
22
|
+
a = new DataView(ArrayBuffer.isView(a) ? a.buffer : a);
|
|
23
|
+
}
|
|
24
|
+
if (!(b instanceof DataView)) {
|
|
25
|
+
b = new DataView(ArrayBuffer.isView(b) ? b.buffer : b);
|
|
26
|
+
}
|
|
27
|
+
assert(a instanceof DataView);
|
|
28
|
+
assert(b instanceof DataView);
|
|
29
|
+
const length = a.byteLength;
|
|
30
|
+
let out = 0;
|
|
31
|
+
let i = -1;
|
|
32
|
+
while (++i < length) {
|
|
33
|
+
out |= a.getUint8(i) ^ b.getUint8(i);
|
|
34
|
+
}
|
|
35
|
+
return out === 0;
|
|
36
|
+
}
|
|
37
|
+
exports.timingSafeEqual = timingSafeEqual;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// ../../node_modules/.pnpm/@stablelib+base64@1.0.1/node_modules/@stablelib/base64/lib/base64.js
|
|
42
|
+
var require_base64 = __commonJS({
|
|
43
|
+
"../../node_modules/.pnpm/@stablelib+base64@1.0.1/node_modules/@stablelib/base64/lib/base64.js"(exports) {
|
|
44
|
+
"use strict";
|
|
45
|
+
var __extends = exports && exports.__extends || /* @__PURE__ */ (function() {
|
|
46
|
+
var extendStatics = function(d, b) {
|
|
47
|
+
extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
|
|
48
|
+
d2.__proto__ = b2;
|
|
49
|
+
} || function(d2, b2) {
|
|
50
|
+
for (var p in b2) if (b2.hasOwnProperty(p)) d2[p] = b2[p];
|
|
51
|
+
};
|
|
52
|
+
return extendStatics(d, b);
|
|
53
|
+
};
|
|
54
|
+
return function(d, b) {
|
|
55
|
+
extendStatics(d, b);
|
|
56
|
+
function __() {
|
|
57
|
+
this.constructor = d;
|
|
58
|
+
}
|
|
59
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
60
|
+
};
|
|
61
|
+
})();
|
|
62
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
|
+
var INVALID_BYTE = 256;
|
|
64
|
+
var Coder = (
|
|
65
|
+
/** @class */
|
|
66
|
+
(function() {
|
|
67
|
+
function Coder2(_paddingCharacter) {
|
|
68
|
+
if (_paddingCharacter === void 0) {
|
|
69
|
+
_paddingCharacter = "=";
|
|
70
|
+
}
|
|
71
|
+
this._paddingCharacter = _paddingCharacter;
|
|
72
|
+
}
|
|
73
|
+
Coder2.prototype.encodedLength = function(length) {
|
|
74
|
+
if (!this._paddingCharacter) {
|
|
75
|
+
return (length * 8 + 5) / 6 | 0;
|
|
76
|
+
}
|
|
77
|
+
return (length + 2) / 3 * 4 | 0;
|
|
78
|
+
};
|
|
79
|
+
Coder2.prototype.encode = function(data) {
|
|
80
|
+
var out = "";
|
|
81
|
+
var i = 0;
|
|
82
|
+
for (; i < data.length - 2; i += 3) {
|
|
83
|
+
var c = data[i] << 16 | data[i + 1] << 8 | data[i + 2];
|
|
84
|
+
out += this._encodeByte(c >>> 3 * 6 & 63);
|
|
85
|
+
out += this._encodeByte(c >>> 2 * 6 & 63);
|
|
86
|
+
out += this._encodeByte(c >>> 1 * 6 & 63);
|
|
87
|
+
out += this._encodeByte(c >>> 0 * 6 & 63);
|
|
88
|
+
}
|
|
89
|
+
var left = data.length - i;
|
|
90
|
+
if (left > 0) {
|
|
91
|
+
var c = data[i] << 16 | (left === 2 ? data[i + 1] << 8 : 0);
|
|
92
|
+
out += this._encodeByte(c >>> 3 * 6 & 63);
|
|
93
|
+
out += this._encodeByte(c >>> 2 * 6 & 63);
|
|
94
|
+
if (left === 2) {
|
|
95
|
+
out += this._encodeByte(c >>> 1 * 6 & 63);
|
|
96
|
+
} else {
|
|
97
|
+
out += this._paddingCharacter || "";
|
|
98
|
+
}
|
|
99
|
+
out += this._paddingCharacter || "";
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
};
|
|
103
|
+
Coder2.prototype.maxDecodedLength = function(length) {
|
|
104
|
+
if (!this._paddingCharacter) {
|
|
105
|
+
return (length * 6 + 7) / 8 | 0;
|
|
106
|
+
}
|
|
107
|
+
return length / 4 * 3 | 0;
|
|
108
|
+
};
|
|
109
|
+
Coder2.prototype.decodedLength = function(s) {
|
|
110
|
+
return this.maxDecodedLength(s.length - this._getPaddingLength(s));
|
|
111
|
+
};
|
|
112
|
+
Coder2.prototype.decode = function(s) {
|
|
113
|
+
if (s.length === 0) {
|
|
114
|
+
return new Uint8Array(0);
|
|
115
|
+
}
|
|
116
|
+
var paddingLength = this._getPaddingLength(s);
|
|
117
|
+
var length = s.length - paddingLength;
|
|
118
|
+
var out = new Uint8Array(this.maxDecodedLength(length));
|
|
119
|
+
var op = 0;
|
|
120
|
+
var i = 0;
|
|
121
|
+
var haveBad = 0;
|
|
122
|
+
var v0 = 0, v1 = 0, v2 = 0, v3 = 0;
|
|
123
|
+
for (; i < length - 4; i += 4) {
|
|
124
|
+
v0 = this._decodeChar(s.charCodeAt(i + 0));
|
|
125
|
+
v1 = this._decodeChar(s.charCodeAt(i + 1));
|
|
126
|
+
v2 = this._decodeChar(s.charCodeAt(i + 2));
|
|
127
|
+
v3 = this._decodeChar(s.charCodeAt(i + 3));
|
|
128
|
+
out[op++] = v0 << 2 | v1 >>> 4;
|
|
129
|
+
out[op++] = v1 << 4 | v2 >>> 2;
|
|
130
|
+
out[op++] = v2 << 6 | v3;
|
|
131
|
+
haveBad |= v0 & INVALID_BYTE;
|
|
132
|
+
haveBad |= v1 & INVALID_BYTE;
|
|
133
|
+
haveBad |= v2 & INVALID_BYTE;
|
|
134
|
+
haveBad |= v3 & INVALID_BYTE;
|
|
135
|
+
}
|
|
136
|
+
if (i < length - 1) {
|
|
137
|
+
v0 = this._decodeChar(s.charCodeAt(i));
|
|
138
|
+
v1 = this._decodeChar(s.charCodeAt(i + 1));
|
|
139
|
+
out[op++] = v0 << 2 | v1 >>> 4;
|
|
140
|
+
haveBad |= v0 & INVALID_BYTE;
|
|
141
|
+
haveBad |= v1 & INVALID_BYTE;
|
|
142
|
+
}
|
|
143
|
+
if (i < length - 2) {
|
|
144
|
+
v2 = this._decodeChar(s.charCodeAt(i + 2));
|
|
145
|
+
out[op++] = v1 << 4 | v2 >>> 2;
|
|
146
|
+
haveBad |= v2 & INVALID_BYTE;
|
|
147
|
+
}
|
|
148
|
+
if (i < length - 3) {
|
|
149
|
+
v3 = this._decodeChar(s.charCodeAt(i + 3));
|
|
150
|
+
out[op++] = v2 << 6 | v3;
|
|
151
|
+
haveBad |= v3 & INVALID_BYTE;
|
|
152
|
+
}
|
|
153
|
+
if (haveBad !== 0) {
|
|
154
|
+
throw new Error("Base64Coder: incorrect characters for decoding");
|
|
155
|
+
}
|
|
156
|
+
return out;
|
|
157
|
+
};
|
|
158
|
+
Coder2.prototype._encodeByte = function(b) {
|
|
159
|
+
var result = b;
|
|
160
|
+
result += 65;
|
|
161
|
+
result += 25 - b >>> 8 & 0 - 65 - 26 + 97;
|
|
162
|
+
result += 51 - b >>> 8 & 26 - 97 - 52 + 48;
|
|
163
|
+
result += 61 - b >>> 8 & 52 - 48 - 62 + 43;
|
|
164
|
+
result += 62 - b >>> 8 & 62 - 43 - 63 + 47;
|
|
165
|
+
return String.fromCharCode(result);
|
|
166
|
+
};
|
|
167
|
+
Coder2.prototype._decodeChar = function(c) {
|
|
168
|
+
var result = INVALID_BYTE;
|
|
169
|
+
result += (42 - c & c - 44) >>> 8 & -INVALID_BYTE + c - 43 + 62;
|
|
170
|
+
result += (46 - c & c - 48) >>> 8 & -INVALID_BYTE + c - 47 + 63;
|
|
171
|
+
result += (47 - c & c - 58) >>> 8 & -INVALID_BYTE + c - 48 + 52;
|
|
172
|
+
result += (64 - c & c - 91) >>> 8 & -INVALID_BYTE + c - 65 + 0;
|
|
173
|
+
result += (96 - c & c - 123) >>> 8 & -INVALID_BYTE + c - 97 + 26;
|
|
174
|
+
return result;
|
|
175
|
+
};
|
|
176
|
+
Coder2.prototype._getPaddingLength = function(s) {
|
|
177
|
+
var paddingLength = 0;
|
|
178
|
+
if (this._paddingCharacter) {
|
|
179
|
+
for (var i = s.length - 1; i >= 0; i--) {
|
|
180
|
+
if (s[i] !== this._paddingCharacter) {
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
paddingLength++;
|
|
184
|
+
}
|
|
185
|
+
if (s.length < 4 || paddingLength > 2) {
|
|
186
|
+
throw new Error("Base64Coder: incorrect padding");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return paddingLength;
|
|
190
|
+
};
|
|
191
|
+
return Coder2;
|
|
192
|
+
})()
|
|
193
|
+
);
|
|
194
|
+
exports.Coder = Coder;
|
|
195
|
+
var stdCoder = new Coder();
|
|
196
|
+
function encode(data) {
|
|
197
|
+
return stdCoder.encode(data);
|
|
198
|
+
}
|
|
199
|
+
exports.encode = encode;
|
|
200
|
+
function decode(s) {
|
|
201
|
+
return stdCoder.decode(s);
|
|
202
|
+
}
|
|
203
|
+
exports.decode = decode;
|
|
204
|
+
var URLSafeCoder = (
|
|
205
|
+
/** @class */
|
|
206
|
+
(function(_super) {
|
|
207
|
+
__extends(URLSafeCoder2, _super);
|
|
208
|
+
function URLSafeCoder2() {
|
|
209
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
210
|
+
}
|
|
211
|
+
URLSafeCoder2.prototype._encodeByte = function(b) {
|
|
212
|
+
var result = b;
|
|
213
|
+
result += 65;
|
|
214
|
+
result += 25 - b >>> 8 & 0 - 65 - 26 + 97;
|
|
215
|
+
result += 51 - b >>> 8 & 26 - 97 - 52 + 48;
|
|
216
|
+
result += 61 - b >>> 8 & 52 - 48 - 62 + 45;
|
|
217
|
+
result += 62 - b >>> 8 & 62 - 45 - 63 + 95;
|
|
218
|
+
return String.fromCharCode(result);
|
|
219
|
+
};
|
|
220
|
+
URLSafeCoder2.prototype._decodeChar = function(c) {
|
|
221
|
+
var result = INVALID_BYTE;
|
|
222
|
+
result += (44 - c & c - 46) >>> 8 & -INVALID_BYTE + c - 45 + 62;
|
|
223
|
+
result += (94 - c & c - 96) >>> 8 & -INVALID_BYTE + c - 95 + 63;
|
|
224
|
+
result += (47 - c & c - 58) >>> 8 & -INVALID_BYTE + c - 48 + 52;
|
|
225
|
+
result += (64 - c & c - 91) >>> 8 & -INVALID_BYTE + c - 65 + 0;
|
|
226
|
+
result += (96 - c & c - 123) >>> 8 & -INVALID_BYTE + c - 97 + 26;
|
|
227
|
+
return result;
|
|
228
|
+
};
|
|
229
|
+
return URLSafeCoder2;
|
|
230
|
+
})(Coder)
|
|
231
|
+
);
|
|
232
|
+
exports.URLSafeCoder = URLSafeCoder;
|
|
233
|
+
var urlSafeCoder = new URLSafeCoder();
|
|
234
|
+
function encodeURLSafe(data) {
|
|
235
|
+
return urlSafeCoder.encode(data);
|
|
236
|
+
}
|
|
237
|
+
exports.encodeURLSafe = encodeURLSafe;
|
|
238
|
+
function decodeURLSafe(s) {
|
|
239
|
+
return urlSafeCoder.decode(s);
|
|
240
|
+
}
|
|
241
|
+
exports.decodeURLSafe = decodeURLSafe;
|
|
242
|
+
exports.encodedLength = function(length) {
|
|
243
|
+
return stdCoder.encodedLength(length);
|
|
244
|
+
};
|
|
245
|
+
exports.maxDecodedLength = function(length) {
|
|
246
|
+
return stdCoder.maxDecodedLength(length);
|
|
247
|
+
};
|
|
248
|
+
exports.decodedLength = function(s) {
|
|
249
|
+
return stdCoder.decodedLength(s);
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// ../../node_modules/.pnpm/fast-sha256@1.3.0/node_modules/fast-sha256/sha256.js
|
|
255
|
+
var require_sha256 = __commonJS({
|
|
256
|
+
"../../node_modules/.pnpm/fast-sha256@1.3.0/node_modules/fast-sha256/sha256.js"(exports, module) {
|
|
257
|
+
"use strict";
|
|
258
|
+
(function(root, factory) {
|
|
259
|
+
var exports2 = {};
|
|
260
|
+
factory(exports2);
|
|
261
|
+
var sha256 = exports2["default"];
|
|
262
|
+
for (var k in exports2) {
|
|
263
|
+
sha256[k] = exports2[k];
|
|
264
|
+
}
|
|
265
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
266
|
+
module.exports = sha256;
|
|
267
|
+
} else if (typeof define === "function" && define.amd) {
|
|
268
|
+
define(function() {
|
|
269
|
+
return sha256;
|
|
270
|
+
});
|
|
271
|
+
} else {
|
|
272
|
+
root.sha256 = sha256;
|
|
273
|
+
}
|
|
274
|
+
})(exports, function(exports2) {
|
|
275
|
+
"use strict";
|
|
276
|
+
exports2.__esModule = true;
|
|
277
|
+
exports2.digestLength = 32;
|
|
278
|
+
exports2.blockSize = 64;
|
|
279
|
+
var K = new Uint32Array([
|
|
280
|
+
1116352408,
|
|
281
|
+
1899447441,
|
|
282
|
+
3049323471,
|
|
283
|
+
3921009573,
|
|
284
|
+
961987163,
|
|
285
|
+
1508970993,
|
|
286
|
+
2453635748,
|
|
287
|
+
2870763221,
|
|
288
|
+
3624381080,
|
|
289
|
+
310598401,
|
|
290
|
+
607225278,
|
|
291
|
+
1426881987,
|
|
292
|
+
1925078388,
|
|
293
|
+
2162078206,
|
|
294
|
+
2614888103,
|
|
295
|
+
3248222580,
|
|
296
|
+
3835390401,
|
|
297
|
+
4022224774,
|
|
298
|
+
264347078,
|
|
299
|
+
604807628,
|
|
300
|
+
770255983,
|
|
301
|
+
1249150122,
|
|
302
|
+
1555081692,
|
|
303
|
+
1996064986,
|
|
304
|
+
2554220882,
|
|
305
|
+
2821834349,
|
|
306
|
+
2952996808,
|
|
307
|
+
3210313671,
|
|
308
|
+
3336571891,
|
|
309
|
+
3584528711,
|
|
310
|
+
113926993,
|
|
311
|
+
338241895,
|
|
312
|
+
666307205,
|
|
313
|
+
773529912,
|
|
314
|
+
1294757372,
|
|
315
|
+
1396182291,
|
|
316
|
+
1695183700,
|
|
317
|
+
1986661051,
|
|
318
|
+
2177026350,
|
|
319
|
+
2456956037,
|
|
320
|
+
2730485921,
|
|
321
|
+
2820302411,
|
|
322
|
+
3259730800,
|
|
323
|
+
3345764771,
|
|
324
|
+
3516065817,
|
|
325
|
+
3600352804,
|
|
326
|
+
4094571909,
|
|
327
|
+
275423344,
|
|
328
|
+
430227734,
|
|
329
|
+
506948616,
|
|
330
|
+
659060556,
|
|
331
|
+
883997877,
|
|
332
|
+
958139571,
|
|
333
|
+
1322822218,
|
|
334
|
+
1537002063,
|
|
335
|
+
1747873779,
|
|
336
|
+
1955562222,
|
|
337
|
+
2024104815,
|
|
338
|
+
2227730452,
|
|
339
|
+
2361852424,
|
|
340
|
+
2428436474,
|
|
341
|
+
2756734187,
|
|
342
|
+
3204031479,
|
|
343
|
+
3329325298
|
|
344
|
+
]);
|
|
345
|
+
function hashBlocks(w, v, p, pos, len) {
|
|
346
|
+
var a, b, c, d, e, f, g, h, u, i, j, t1, t2;
|
|
347
|
+
while (len >= 64) {
|
|
348
|
+
a = v[0];
|
|
349
|
+
b = v[1];
|
|
350
|
+
c = v[2];
|
|
351
|
+
d = v[3];
|
|
352
|
+
e = v[4];
|
|
353
|
+
f = v[5];
|
|
354
|
+
g = v[6];
|
|
355
|
+
h = v[7];
|
|
356
|
+
for (i = 0; i < 16; i++) {
|
|
357
|
+
j = pos + i * 4;
|
|
358
|
+
w[i] = (p[j] & 255) << 24 | (p[j + 1] & 255) << 16 | (p[j + 2] & 255) << 8 | p[j + 3] & 255;
|
|
359
|
+
}
|
|
360
|
+
for (i = 16; i < 64; i++) {
|
|
361
|
+
u = w[i - 2];
|
|
362
|
+
t1 = (u >>> 17 | u << 32 - 17) ^ (u >>> 19 | u << 32 - 19) ^ u >>> 10;
|
|
363
|
+
u = w[i - 15];
|
|
364
|
+
t2 = (u >>> 7 | u << 32 - 7) ^ (u >>> 18 | u << 32 - 18) ^ u >>> 3;
|
|
365
|
+
w[i] = (t1 + w[i - 7] | 0) + (t2 + w[i - 16] | 0);
|
|
366
|
+
}
|
|
367
|
+
for (i = 0; i < 64; i++) {
|
|
368
|
+
t1 = (((e >>> 6 | e << 32 - 6) ^ (e >>> 11 | e << 32 - 11) ^ (e >>> 25 | e << 32 - 25)) + (e & f ^ ~e & g) | 0) + (h + (K[i] + w[i] | 0) | 0) | 0;
|
|
369
|
+
t2 = ((a >>> 2 | a << 32 - 2) ^ (a >>> 13 | a << 32 - 13) ^ (a >>> 22 | a << 32 - 22)) + (a & b ^ a & c ^ b & c) | 0;
|
|
370
|
+
h = g;
|
|
371
|
+
g = f;
|
|
372
|
+
f = e;
|
|
373
|
+
e = d + t1 | 0;
|
|
374
|
+
d = c;
|
|
375
|
+
c = b;
|
|
376
|
+
b = a;
|
|
377
|
+
a = t1 + t2 | 0;
|
|
378
|
+
}
|
|
379
|
+
v[0] += a;
|
|
380
|
+
v[1] += b;
|
|
381
|
+
v[2] += c;
|
|
382
|
+
v[3] += d;
|
|
383
|
+
v[4] += e;
|
|
384
|
+
v[5] += f;
|
|
385
|
+
v[6] += g;
|
|
386
|
+
v[7] += h;
|
|
387
|
+
pos += 64;
|
|
388
|
+
len -= 64;
|
|
389
|
+
}
|
|
390
|
+
return pos;
|
|
391
|
+
}
|
|
392
|
+
var Hash = (
|
|
393
|
+
/** @class */
|
|
394
|
+
(function() {
|
|
395
|
+
function Hash2() {
|
|
396
|
+
this.digestLength = exports2.digestLength;
|
|
397
|
+
this.blockSize = exports2.blockSize;
|
|
398
|
+
this.state = new Int32Array(8);
|
|
399
|
+
this.temp = new Int32Array(64);
|
|
400
|
+
this.buffer = new Uint8Array(128);
|
|
401
|
+
this.bufferLength = 0;
|
|
402
|
+
this.bytesHashed = 0;
|
|
403
|
+
this.finished = false;
|
|
404
|
+
this.reset();
|
|
405
|
+
}
|
|
406
|
+
Hash2.prototype.reset = function() {
|
|
407
|
+
this.state[0] = 1779033703;
|
|
408
|
+
this.state[1] = 3144134277;
|
|
409
|
+
this.state[2] = 1013904242;
|
|
410
|
+
this.state[3] = 2773480762;
|
|
411
|
+
this.state[4] = 1359893119;
|
|
412
|
+
this.state[5] = 2600822924;
|
|
413
|
+
this.state[6] = 528734635;
|
|
414
|
+
this.state[7] = 1541459225;
|
|
415
|
+
this.bufferLength = 0;
|
|
416
|
+
this.bytesHashed = 0;
|
|
417
|
+
this.finished = false;
|
|
418
|
+
return this;
|
|
419
|
+
};
|
|
420
|
+
Hash2.prototype.clean = function() {
|
|
421
|
+
for (var i = 0; i < this.buffer.length; i++) {
|
|
422
|
+
this.buffer[i] = 0;
|
|
423
|
+
}
|
|
424
|
+
for (var i = 0; i < this.temp.length; i++) {
|
|
425
|
+
this.temp[i] = 0;
|
|
426
|
+
}
|
|
427
|
+
this.reset();
|
|
428
|
+
};
|
|
429
|
+
Hash2.prototype.update = function(data, dataLength) {
|
|
430
|
+
if (dataLength === void 0) {
|
|
431
|
+
dataLength = data.length;
|
|
432
|
+
}
|
|
433
|
+
if (this.finished) {
|
|
434
|
+
throw new Error("SHA256: can't update because hash was finished.");
|
|
435
|
+
}
|
|
436
|
+
var dataPos = 0;
|
|
437
|
+
this.bytesHashed += dataLength;
|
|
438
|
+
if (this.bufferLength > 0) {
|
|
439
|
+
while (this.bufferLength < 64 && dataLength > 0) {
|
|
440
|
+
this.buffer[this.bufferLength++] = data[dataPos++];
|
|
441
|
+
dataLength--;
|
|
442
|
+
}
|
|
443
|
+
if (this.bufferLength === 64) {
|
|
444
|
+
hashBlocks(this.temp, this.state, this.buffer, 0, 64);
|
|
445
|
+
this.bufferLength = 0;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if (dataLength >= 64) {
|
|
449
|
+
dataPos = hashBlocks(this.temp, this.state, data, dataPos, dataLength);
|
|
450
|
+
dataLength %= 64;
|
|
451
|
+
}
|
|
452
|
+
while (dataLength > 0) {
|
|
453
|
+
this.buffer[this.bufferLength++] = data[dataPos++];
|
|
454
|
+
dataLength--;
|
|
455
|
+
}
|
|
456
|
+
return this;
|
|
457
|
+
};
|
|
458
|
+
Hash2.prototype.finish = function(out) {
|
|
459
|
+
if (!this.finished) {
|
|
460
|
+
var bytesHashed = this.bytesHashed;
|
|
461
|
+
var left = this.bufferLength;
|
|
462
|
+
var bitLenHi = bytesHashed / 536870912 | 0;
|
|
463
|
+
var bitLenLo = bytesHashed << 3;
|
|
464
|
+
var padLength = bytesHashed % 64 < 56 ? 64 : 128;
|
|
465
|
+
this.buffer[left] = 128;
|
|
466
|
+
for (var i = left + 1; i < padLength - 8; i++) {
|
|
467
|
+
this.buffer[i] = 0;
|
|
468
|
+
}
|
|
469
|
+
this.buffer[padLength - 8] = bitLenHi >>> 24 & 255;
|
|
470
|
+
this.buffer[padLength - 7] = bitLenHi >>> 16 & 255;
|
|
471
|
+
this.buffer[padLength - 6] = bitLenHi >>> 8 & 255;
|
|
472
|
+
this.buffer[padLength - 5] = bitLenHi >>> 0 & 255;
|
|
473
|
+
this.buffer[padLength - 4] = bitLenLo >>> 24 & 255;
|
|
474
|
+
this.buffer[padLength - 3] = bitLenLo >>> 16 & 255;
|
|
475
|
+
this.buffer[padLength - 2] = bitLenLo >>> 8 & 255;
|
|
476
|
+
this.buffer[padLength - 1] = bitLenLo >>> 0 & 255;
|
|
477
|
+
hashBlocks(this.temp, this.state, this.buffer, 0, padLength);
|
|
478
|
+
this.finished = true;
|
|
479
|
+
}
|
|
480
|
+
for (var i = 0; i < 8; i++) {
|
|
481
|
+
out[i * 4 + 0] = this.state[i] >>> 24 & 255;
|
|
482
|
+
out[i * 4 + 1] = this.state[i] >>> 16 & 255;
|
|
483
|
+
out[i * 4 + 2] = this.state[i] >>> 8 & 255;
|
|
484
|
+
out[i * 4 + 3] = this.state[i] >>> 0 & 255;
|
|
485
|
+
}
|
|
486
|
+
return this;
|
|
487
|
+
};
|
|
488
|
+
Hash2.prototype.digest = function() {
|
|
489
|
+
var out = new Uint8Array(this.digestLength);
|
|
490
|
+
this.finish(out);
|
|
491
|
+
return out;
|
|
492
|
+
};
|
|
493
|
+
Hash2.prototype._saveState = function(out) {
|
|
494
|
+
for (var i = 0; i < this.state.length; i++) {
|
|
495
|
+
out[i] = this.state[i];
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
Hash2.prototype._restoreState = function(from, bytesHashed) {
|
|
499
|
+
for (var i = 0; i < this.state.length; i++) {
|
|
500
|
+
this.state[i] = from[i];
|
|
501
|
+
}
|
|
502
|
+
this.bytesHashed = bytesHashed;
|
|
503
|
+
this.finished = false;
|
|
504
|
+
this.bufferLength = 0;
|
|
505
|
+
};
|
|
506
|
+
return Hash2;
|
|
507
|
+
})()
|
|
508
|
+
);
|
|
509
|
+
exports2.Hash = Hash;
|
|
510
|
+
var HMAC = (
|
|
511
|
+
/** @class */
|
|
512
|
+
(function() {
|
|
513
|
+
function HMAC2(key) {
|
|
514
|
+
this.inner = new Hash();
|
|
515
|
+
this.outer = new Hash();
|
|
516
|
+
this.blockSize = this.inner.blockSize;
|
|
517
|
+
this.digestLength = this.inner.digestLength;
|
|
518
|
+
var pad = new Uint8Array(this.blockSize);
|
|
519
|
+
if (key.length > this.blockSize) {
|
|
520
|
+
new Hash().update(key).finish(pad).clean();
|
|
521
|
+
} else {
|
|
522
|
+
for (var i = 0; i < key.length; i++) {
|
|
523
|
+
pad[i] = key[i];
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
for (var i = 0; i < pad.length; i++) {
|
|
527
|
+
pad[i] ^= 54;
|
|
528
|
+
}
|
|
529
|
+
this.inner.update(pad);
|
|
530
|
+
for (var i = 0; i < pad.length; i++) {
|
|
531
|
+
pad[i] ^= 54 ^ 92;
|
|
532
|
+
}
|
|
533
|
+
this.outer.update(pad);
|
|
534
|
+
this.istate = new Uint32Array(8);
|
|
535
|
+
this.ostate = new Uint32Array(8);
|
|
536
|
+
this.inner._saveState(this.istate);
|
|
537
|
+
this.outer._saveState(this.ostate);
|
|
538
|
+
for (var i = 0; i < pad.length; i++) {
|
|
539
|
+
pad[i] = 0;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
HMAC2.prototype.reset = function() {
|
|
543
|
+
this.inner._restoreState(this.istate, this.inner.blockSize);
|
|
544
|
+
this.outer._restoreState(this.ostate, this.outer.blockSize);
|
|
545
|
+
return this;
|
|
546
|
+
};
|
|
547
|
+
HMAC2.prototype.clean = function() {
|
|
548
|
+
for (var i = 0; i < this.istate.length; i++) {
|
|
549
|
+
this.ostate[i] = this.istate[i] = 0;
|
|
550
|
+
}
|
|
551
|
+
this.inner.clean();
|
|
552
|
+
this.outer.clean();
|
|
553
|
+
};
|
|
554
|
+
HMAC2.prototype.update = function(data) {
|
|
555
|
+
this.inner.update(data);
|
|
556
|
+
return this;
|
|
557
|
+
};
|
|
558
|
+
HMAC2.prototype.finish = function(out) {
|
|
559
|
+
if (this.outer.finished) {
|
|
560
|
+
this.outer.finish(out);
|
|
561
|
+
} else {
|
|
562
|
+
this.inner.finish(out);
|
|
563
|
+
this.outer.update(out, this.digestLength).finish(out);
|
|
564
|
+
}
|
|
565
|
+
return this;
|
|
566
|
+
};
|
|
567
|
+
HMAC2.prototype.digest = function() {
|
|
568
|
+
var out = new Uint8Array(this.digestLength);
|
|
569
|
+
this.finish(out);
|
|
570
|
+
return out;
|
|
571
|
+
};
|
|
572
|
+
return HMAC2;
|
|
573
|
+
})()
|
|
574
|
+
);
|
|
575
|
+
exports2.HMAC = HMAC;
|
|
576
|
+
function hash(data) {
|
|
577
|
+
var h = new Hash().update(data);
|
|
578
|
+
var digest = h.digest();
|
|
579
|
+
h.clean();
|
|
580
|
+
return digest;
|
|
581
|
+
}
|
|
582
|
+
exports2.hash = hash;
|
|
583
|
+
exports2["default"] = hash;
|
|
584
|
+
function hmac(key, data) {
|
|
585
|
+
var h = new HMAC(key).update(data);
|
|
586
|
+
var digest = h.digest();
|
|
587
|
+
h.clean();
|
|
588
|
+
return digest;
|
|
589
|
+
}
|
|
590
|
+
exports2.hmac = hmac;
|
|
591
|
+
function fillBuffer(buffer, hmac2, info, counter) {
|
|
592
|
+
var num = counter[0];
|
|
593
|
+
if (num === 0) {
|
|
594
|
+
throw new Error("hkdf: cannot expand more");
|
|
595
|
+
}
|
|
596
|
+
hmac2.reset();
|
|
597
|
+
if (num > 1) {
|
|
598
|
+
hmac2.update(buffer);
|
|
599
|
+
}
|
|
600
|
+
if (info) {
|
|
601
|
+
hmac2.update(info);
|
|
602
|
+
}
|
|
603
|
+
hmac2.update(counter);
|
|
604
|
+
hmac2.finish(buffer);
|
|
605
|
+
counter[0]++;
|
|
606
|
+
}
|
|
607
|
+
var hkdfSalt = new Uint8Array(exports2.digestLength);
|
|
608
|
+
function hkdf(key, salt, info, length) {
|
|
609
|
+
if (salt === void 0) {
|
|
610
|
+
salt = hkdfSalt;
|
|
611
|
+
}
|
|
612
|
+
if (length === void 0) {
|
|
613
|
+
length = 32;
|
|
614
|
+
}
|
|
615
|
+
var counter = new Uint8Array([1]);
|
|
616
|
+
var okm = hmac(salt, key);
|
|
617
|
+
var hmac_ = new HMAC(okm);
|
|
618
|
+
var buffer = new Uint8Array(hmac_.digestLength);
|
|
619
|
+
var bufpos = buffer.length;
|
|
620
|
+
var out = new Uint8Array(length);
|
|
621
|
+
for (var i = 0; i < length; i++) {
|
|
622
|
+
if (bufpos === buffer.length) {
|
|
623
|
+
fillBuffer(buffer, hmac_, info, counter);
|
|
624
|
+
bufpos = 0;
|
|
625
|
+
}
|
|
626
|
+
out[i] = buffer[bufpos++];
|
|
627
|
+
}
|
|
628
|
+
hmac_.clean();
|
|
629
|
+
buffer.fill(0);
|
|
630
|
+
counter.fill(0);
|
|
631
|
+
return out;
|
|
632
|
+
}
|
|
633
|
+
exports2.hkdf = hkdf;
|
|
634
|
+
function pbkdf2(password, salt, iterations, dkLen) {
|
|
635
|
+
var prf = new HMAC(password);
|
|
636
|
+
var len = prf.digestLength;
|
|
637
|
+
var ctr = new Uint8Array(4);
|
|
638
|
+
var t = new Uint8Array(len);
|
|
639
|
+
var u = new Uint8Array(len);
|
|
640
|
+
var dk = new Uint8Array(dkLen);
|
|
641
|
+
for (var i = 0; i * len < dkLen; i++) {
|
|
642
|
+
var c = i + 1;
|
|
643
|
+
ctr[0] = c >>> 24 & 255;
|
|
644
|
+
ctr[1] = c >>> 16 & 255;
|
|
645
|
+
ctr[2] = c >>> 8 & 255;
|
|
646
|
+
ctr[3] = c >>> 0 & 255;
|
|
647
|
+
prf.reset();
|
|
648
|
+
prf.update(salt);
|
|
649
|
+
prf.update(ctr);
|
|
650
|
+
prf.finish(u);
|
|
651
|
+
for (var j = 0; j < len; j++) {
|
|
652
|
+
t[j] = u[j];
|
|
653
|
+
}
|
|
654
|
+
for (var j = 2; j <= iterations; j++) {
|
|
655
|
+
prf.reset();
|
|
656
|
+
prf.update(u).finish(u);
|
|
657
|
+
for (var k = 0; k < len; k++) {
|
|
658
|
+
t[k] ^= u[k];
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
for (var j = 0; j < len && i * len + j < dkLen; j++) {
|
|
662
|
+
dk[i * len + j] = t[j];
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
for (var i = 0; i < len; i++) {
|
|
666
|
+
t[i] = u[i] = 0;
|
|
667
|
+
}
|
|
668
|
+
for (var i = 0; i < 4; i++) {
|
|
669
|
+
ctr[i] = 0;
|
|
670
|
+
}
|
|
671
|
+
prf.clean();
|
|
672
|
+
return dk;
|
|
673
|
+
}
|
|
674
|
+
exports2.pbkdf2 = pbkdf2;
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
// ../../node_modules/.pnpm/standardwebhooks@1.0.0/node_modules/standardwebhooks/dist/index.js
|
|
680
|
+
var require_dist = __commonJS({
|
|
681
|
+
"../../node_modules/.pnpm/standardwebhooks@1.0.0/node_modules/standardwebhooks/dist/index.js"(exports) {
|
|
682
|
+
"use strict";
|
|
683
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
684
|
+
exports.Webhook = exports.WebhookVerificationError = void 0;
|
|
685
|
+
var timing_safe_equal_1 = require_timing_safe_equal();
|
|
686
|
+
var base64 = require_base64();
|
|
687
|
+
var sha256 = require_sha256();
|
|
688
|
+
var WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60;
|
|
689
|
+
var ExtendableError = class _ExtendableError extends Error {
|
|
690
|
+
constructor(message) {
|
|
691
|
+
super(message);
|
|
692
|
+
Object.setPrototypeOf(this, _ExtendableError.prototype);
|
|
693
|
+
this.name = "ExtendableError";
|
|
694
|
+
this.stack = new Error(message).stack;
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
var WebhookVerificationError = class _WebhookVerificationError extends ExtendableError {
|
|
698
|
+
constructor(message) {
|
|
699
|
+
super(message);
|
|
700
|
+
Object.setPrototypeOf(this, _WebhookVerificationError.prototype);
|
|
701
|
+
this.name = "WebhookVerificationError";
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
exports.WebhookVerificationError = WebhookVerificationError;
|
|
705
|
+
var Webhook2 = class _Webhook {
|
|
706
|
+
constructor(secret, options) {
|
|
707
|
+
if (!secret) {
|
|
708
|
+
throw new Error("Secret can't be empty.");
|
|
709
|
+
}
|
|
710
|
+
if ((options === null || options === void 0 ? void 0 : options.format) === "raw") {
|
|
711
|
+
if (secret instanceof Uint8Array) {
|
|
712
|
+
this.key = secret;
|
|
713
|
+
} else {
|
|
714
|
+
this.key = Uint8Array.from(secret, (c) => c.charCodeAt(0));
|
|
715
|
+
}
|
|
716
|
+
} else {
|
|
717
|
+
if (typeof secret !== "string") {
|
|
718
|
+
throw new Error("Expected secret to be of type string");
|
|
719
|
+
}
|
|
720
|
+
if (secret.startsWith(_Webhook.prefix)) {
|
|
721
|
+
secret = secret.substring(_Webhook.prefix.length);
|
|
722
|
+
}
|
|
723
|
+
this.key = base64.decode(secret);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
verify(payload, headers_) {
|
|
727
|
+
const headers = {};
|
|
728
|
+
for (const key of Object.keys(headers_)) {
|
|
729
|
+
headers[key.toLowerCase()] = headers_[key];
|
|
730
|
+
}
|
|
731
|
+
const msgId = headers["webhook-id"];
|
|
732
|
+
const msgSignature = headers["webhook-signature"];
|
|
733
|
+
const msgTimestamp = headers["webhook-timestamp"];
|
|
734
|
+
if (!msgSignature || !msgId || !msgTimestamp) {
|
|
735
|
+
throw new WebhookVerificationError("Missing required headers");
|
|
736
|
+
}
|
|
737
|
+
const timestamp = this.verifyTimestamp(msgTimestamp);
|
|
738
|
+
const computedSignature = this.sign(msgId, timestamp, payload);
|
|
739
|
+
const expectedSignature = computedSignature.split(",")[1];
|
|
740
|
+
const passedSignatures = msgSignature.split(" ");
|
|
741
|
+
const encoder2 = new globalThis.TextEncoder();
|
|
742
|
+
for (const versionedSignature of passedSignatures) {
|
|
743
|
+
const [version3, signature] = versionedSignature.split(",");
|
|
744
|
+
if (version3 !== "v1") {
|
|
745
|
+
continue;
|
|
746
|
+
}
|
|
747
|
+
if ((0, timing_safe_equal_1.timingSafeEqual)(encoder2.encode(signature), encoder2.encode(expectedSignature))) {
|
|
748
|
+
return JSON.parse(payload.toString());
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
throw new WebhookVerificationError("No matching signature found");
|
|
752
|
+
}
|
|
753
|
+
sign(msgId, timestamp, payload) {
|
|
754
|
+
if (typeof payload === "string") {
|
|
755
|
+
} else if (payload.constructor.name === "Buffer") {
|
|
756
|
+
payload = payload.toString();
|
|
757
|
+
} else {
|
|
758
|
+
throw new Error("Expected payload to be of type string or Buffer.");
|
|
759
|
+
}
|
|
760
|
+
const encoder2 = new TextEncoder();
|
|
761
|
+
const timestampNumber = Math.floor(timestamp.getTime() / 1e3);
|
|
762
|
+
const toSign = encoder2.encode(`${msgId}.${timestampNumber}.${payload}`);
|
|
763
|
+
const expectedSignature = base64.encode(sha256.hmac(this.key, toSign));
|
|
764
|
+
return `v1,${expectedSignature}`;
|
|
765
|
+
}
|
|
766
|
+
verifyTimestamp(timestampHeader) {
|
|
767
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
768
|
+
const timestamp = parseInt(timestampHeader, 10);
|
|
769
|
+
if (isNaN(timestamp)) {
|
|
770
|
+
throw new WebhookVerificationError("Invalid Signature Headers");
|
|
771
|
+
}
|
|
772
|
+
if (now - timestamp > WEBHOOK_TOLERANCE_IN_SECONDS) {
|
|
773
|
+
throw new WebhookVerificationError("Message timestamp too old");
|
|
774
|
+
}
|
|
775
|
+
if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {
|
|
776
|
+
throw new WebhookVerificationError("Message timestamp too new");
|
|
777
|
+
}
|
|
778
|
+
return new Date(timestamp * 1e3);
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
exports.Webhook = Webhook2;
|
|
782
|
+
Webhook2.prefix = "whsec_";
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
// src/args.ts
|
|
787
|
+
var VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
788
|
+
"config",
|
|
789
|
+
"client",
|
|
790
|
+
"mode",
|
|
791
|
+
"port",
|
|
792
|
+
"host",
|
|
793
|
+
"agent",
|
|
794
|
+
"run-id",
|
|
795
|
+
"run",
|
|
796
|
+
"base",
|
|
797
|
+
"head",
|
|
798
|
+
"paths",
|
|
799
|
+
"format",
|
|
800
|
+
"by",
|
|
801
|
+
"note",
|
|
802
|
+
"allow",
|
|
803
|
+
"deny",
|
|
804
|
+
"writes",
|
|
805
|
+
"spend",
|
|
806
|
+
"tool-calls",
|
|
807
|
+
"deletes",
|
|
808
|
+
"emails",
|
|
809
|
+
"reason",
|
|
810
|
+
"url",
|
|
811
|
+
"timeout",
|
|
812
|
+
"out",
|
|
813
|
+
"upstream",
|
|
814
|
+
"command",
|
|
815
|
+
"fallback-config",
|
|
816
|
+
"since",
|
|
817
|
+
"repo",
|
|
818
|
+
"cache-dir",
|
|
819
|
+
"claude-dir",
|
|
820
|
+
"codex-dir",
|
|
821
|
+
"rules"
|
|
822
|
+
]);
|
|
823
|
+
function parseArgs(argv) {
|
|
824
|
+
const out = { command: void 0, positionals: [], flags: {} };
|
|
825
|
+
const push = (key, value) => {
|
|
826
|
+
const existing = out.flags[key];
|
|
827
|
+
if (existing === void 0) out.flags[key] = value;
|
|
828
|
+
else if (Array.isArray(existing)) existing.push(String(value));
|
|
829
|
+
else out.flags[key] = [String(existing), String(value)];
|
|
830
|
+
};
|
|
831
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
832
|
+
const arg = argv[i];
|
|
833
|
+
if (arg === "--") {
|
|
834
|
+
out.positionals.push(...argv.slice(i + 1));
|
|
835
|
+
break;
|
|
836
|
+
}
|
|
837
|
+
if (arg.startsWith("--")) {
|
|
838
|
+
const body = arg.slice(2);
|
|
839
|
+
const eq = body.indexOf("=");
|
|
840
|
+
if (eq >= 0) {
|
|
841
|
+
push(body.slice(0, eq), body.slice(eq + 1));
|
|
842
|
+
continue;
|
|
843
|
+
}
|
|
844
|
+
if (body.startsWith("no-")) {
|
|
845
|
+
push(body.slice(3), false);
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
const next = argv[i + 1];
|
|
849
|
+
if (VALUE_FLAGS.has(body) && next !== void 0 && !next.startsWith("--")) {
|
|
850
|
+
push(body, next);
|
|
851
|
+
i += 1;
|
|
852
|
+
} else push(body, true);
|
|
853
|
+
continue;
|
|
854
|
+
}
|
|
855
|
+
if (arg.startsWith("-") && arg.length === 2) {
|
|
856
|
+
const short = {
|
|
857
|
+
c: "config",
|
|
858
|
+
y: "yes",
|
|
859
|
+
h: "help",
|
|
860
|
+
v: "version",
|
|
861
|
+
j: "json",
|
|
862
|
+
a: "all"
|
|
863
|
+
};
|
|
864
|
+
const key = short[arg[1]] ?? arg[1];
|
|
865
|
+
const next = argv[i + 1];
|
|
866
|
+
if (VALUE_FLAGS.has(key) && next !== void 0 && !next.startsWith("-")) {
|
|
867
|
+
push(key, next);
|
|
868
|
+
i += 1;
|
|
869
|
+
} else push(key, true);
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
if (out.command === void 0) out.command = arg;
|
|
873
|
+
else out.positionals.push(arg);
|
|
874
|
+
}
|
|
875
|
+
return out;
|
|
876
|
+
}
|
|
877
|
+
function flagString(args, name) {
|
|
878
|
+
const v = args.flags[name];
|
|
879
|
+
if (Array.isArray(v)) return v[v.length - 1];
|
|
880
|
+
return typeof v === "string" ? v : void 0;
|
|
881
|
+
}
|
|
882
|
+
function flagList(args, name) {
|
|
883
|
+
const v = args.flags[name];
|
|
884
|
+
if (Array.isArray(v)) return v.flatMap((s) => s.split(","));
|
|
885
|
+
return typeof v === "string" ? v.split(",") : [];
|
|
886
|
+
}
|
|
887
|
+
function flagBool(args, name) {
|
|
888
|
+
const v = args.flags[name];
|
|
889
|
+
if (typeof v === "boolean") return v;
|
|
890
|
+
if (typeof v === "string") return v !== "false" && v !== "0";
|
|
891
|
+
return void 0;
|
|
892
|
+
}
|
|
893
|
+
function flagNumber(args, name) {
|
|
894
|
+
const s = flagString(args, name);
|
|
895
|
+
if (s === void 0) return void 0;
|
|
896
|
+
const n = Number(s);
|
|
897
|
+
return Number.isFinite(n) ? n : void 0;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// src/version.ts
|
|
901
|
+
import { readFileSync } from "fs";
|
|
902
|
+
var cached;
|
|
903
|
+
function version() {
|
|
904
|
+
if (cached !== void 0) return cached;
|
|
905
|
+
try {
|
|
906
|
+
cached = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
907
|
+
} catch {
|
|
908
|
+
cached = "0.0.0";
|
|
909
|
+
}
|
|
910
|
+
return cached;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// src/registration.ts
|
|
914
|
+
import { join } from "path";
|
|
915
|
+
function registrationPath(stateDir) {
|
|
916
|
+
return join(stateDir, "http.json");
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// ../../node_modules/.pnpm/postal-mime@2.7.5/node_modules/postal-mime/src/decode-strings.js
|
|
920
|
+
var textEncoder = new TextEncoder();
|
|
921
|
+
var base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
922
|
+
var base64Lookup = new Uint8Array(256);
|
|
923
|
+
for (let i = 0; i < base64Chars.length; i++) {
|
|
924
|
+
base64Lookup[base64Chars.charCodeAt(i)] = i;
|
|
925
|
+
}
|
|
926
|
+
var charsetAliases = /* @__PURE__ */ new Map([
|
|
927
|
+
["iso-8859-8-i", "iso-8859-8"],
|
|
928
|
+
["iso-8859-8-e", "iso-8859-8"]
|
|
929
|
+
]);
|
|
930
|
+
function getDecoder(charset) {
|
|
931
|
+
charset = (charset || "utf8").trim().toLowerCase();
|
|
932
|
+
charset = charsetAliases.get(charset) || charset;
|
|
933
|
+
let decoder;
|
|
934
|
+
try {
|
|
935
|
+
decoder = new TextDecoder(charset);
|
|
936
|
+
} catch (err) {
|
|
937
|
+
decoder = new TextDecoder("windows-1252");
|
|
938
|
+
}
|
|
939
|
+
return decoder;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// ../../node_modules/.pnpm/postal-mime@2.7.5/node_modules/postal-mime/src/mime-node.js
|
|
943
|
+
var defaultDecoder = getDecoder();
|
|
944
|
+
|
|
945
|
+
// ../../node_modules/.pnpm/postal-mime@2.7.5/node_modules/postal-mime/src/postal-mime.js
|
|
946
|
+
var MAX_HEADERS_SIZE = 2 * 1024 * 1024;
|
|
947
|
+
|
|
948
|
+
// ../../node_modules/.pnpm/resend@6.25.0/node_modules/resend/dist/index.mjs
|
|
949
|
+
var import_standardwebhooks = __toESM(require_dist(), 1);
|
|
950
|
+
var version2 = "6.25.0";
|
|
951
|
+
var defaultUserAgent = `resend-node:${version2}`;
|
|
952
|
+
|
|
953
|
+
// ../../packages/notify/dist/index.js
|
|
954
|
+
var palette = {
|
|
955
|
+
bg: "#f4f5f7",
|
|
956
|
+
card: "#ffffff",
|
|
957
|
+
text: "#111827",
|
|
958
|
+
muted: "#6b7280",
|
|
959
|
+
border: "#e5e7eb",
|
|
960
|
+
link: "#2563eb",
|
|
961
|
+
codeBg: "#f3f4f6",
|
|
962
|
+
red: "#b91c1c",
|
|
963
|
+
redBg: "#fef2f2",
|
|
964
|
+
green: "#15803d",
|
|
965
|
+
greenBg: "#f0fdf4",
|
|
966
|
+
amber: "#b45309",
|
|
967
|
+
amberBg: "#fffbeb",
|
|
968
|
+
gray: "#374151",
|
|
969
|
+
grayBg: "#f3f4f6"
|
|
970
|
+
};
|
|
971
|
+
var fontStack = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif";
|
|
972
|
+
var baseText = `font-family:${fontStack};font-size:15px;line-height:1.55;color:${palette.text};`;
|
|
973
|
+
var USER_AGENT = "agentwares-notify/0.1";
|
|
974
|
+
function errorMessage(e) {
|
|
975
|
+
if (e instanceof Error) return e.message;
|
|
976
|
+
return typeof e === "string" ? e : "unknown error";
|
|
977
|
+
}
|
|
978
|
+
async function readBody(res) {
|
|
979
|
+
try {
|
|
980
|
+
return (await res.text()).slice(0, 500);
|
|
981
|
+
} catch {
|
|
982
|
+
return "";
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
function defaultFetch() {
|
|
986
|
+
return typeof fetch === "function" ? (input, init) => fetch(input, init) : void 0;
|
|
987
|
+
}
|
|
988
|
+
async function postJson(url, body, headers, fetchImpl) {
|
|
989
|
+
if (!fetchImpl) return { error: "fetch is not available" };
|
|
990
|
+
try {
|
|
991
|
+
const res = await fetchImpl(url, {
|
|
992
|
+
method: "POST",
|
|
993
|
+
headers: { "Content-Type": "application/json", "User-Agent": USER_AGENT, ...headers },
|
|
994
|
+
body: typeof body === "string" ? body : JSON.stringify(body)
|
|
995
|
+
});
|
|
996
|
+
return { res, text: await readBody(res) };
|
|
997
|
+
} catch (e) {
|
|
998
|
+
return { error: errorMessage(e) };
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
async function sendSlack(webhookUrl, message, opts = {}) {
|
|
1002
|
+
const r = await postJson(webhookUrl, message, {}, opts.fetch ?? defaultFetch());
|
|
1003
|
+
if ("error" in r) return { ok: false, error: r.error };
|
|
1004
|
+
return r.res.ok ? { ok: true, status: r.res.status } : { ok: false, status: r.res.status, error: r.text || r.res.statusText || "slack error" };
|
|
1005
|
+
}
|
|
1006
|
+
var SIGNATURE_HEADER = "X-Agentwares-Signature";
|
|
1007
|
+
var encoder = new TextEncoder();
|
|
1008
|
+
function toHex(bytes) {
|
|
1009
|
+
return Array.from(new Uint8Array(bytes), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
1010
|
+
}
|
|
1011
|
+
async function hmacSha256Hex(secret, body) {
|
|
1012
|
+
const key = await crypto.subtle.importKey(
|
|
1013
|
+
"raw",
|
|
1014
|
+
encoder.encode(secret),
|
|
1015
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
1016
|
+
false,
|
|
1017
|
+
["sign"]
|
|
1018
|
+
);
|
|
1019
|
+
return toHex(await crypto.subtle.sign("HMAC", key, encoder.encode(body)));
|
|
1020
|
+
}
|
|
1021
|
+
async function sendWebhook(url, payload, opts = {}) {
|
|
1022
|
+
const body = JSON.stringify(payload);
|
|
1023
|
+
const headers = { ...opts.headers ?? {} };
|
|
1024
|
+
if (opts.secret) headers[SIGNATURE_HEADER] = `sha256=${await hmacSha256Hex(opts.secret, body)}`;
|
|
1025
|
+
const r = await postJson(url, body, headers, opts.fetch ?? defaultFetch());
|
|
1026
|
+
if ("error" in r) return { ok: false, error: r.error };
|
|
1027
|
+
return r.res.ok ? { ok: true, status: r.res.status } : { ok: false, status: r.res.status, error: r.text || r.res.statusText || "webhook error" };
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// src/notify.ts
|
|
1031
|
+
function approvalSlackMessage(event, url) {
|
|
1032
|
+
const a = event.approval;
|
|
1033
|
+
const argsText = JSON.stringify(a.args ?? {}, null, 2).slice(0, 1500);
|
|
1034
|
+
const text = `[agentguard] approval needed: ${a.tool} (run ${a.run_id}) \u2014 run \`agentguard approve ${a.id}\`${url ? ` or open ${url}` : ""}`;
|
|
1035
|
+
const blocks = [
|
|
1036
|
+
{ type: "header", text: { type: "plain_text", text: `Approval needed: ${a.tool}` } },
|
|
1037
|
+
{
|
|
1038
|
+
type: "section",
|
|
1039
|
+
text: {
|
|
1040
|
+
type: "mrkdwn",
|
|
1041
|
+
text: `*run* \`${a.run_id}\`${a.agent ? ` \xB7 *agent* \`${a.agent}\`` : ""}${a.upstream ? ` \xB7 *upstream* \`${a.upstream}\`` : ""}
|
|
1042
|
+
\`\`\`${argsText}\`\`\``
|
|
1043
|
+
}
|
|
1044
|
+
},
|
|
1045
|
+
{
|
|
1046
|
+
type: "context",
|
|
1047
|
+
elements: [
|
|
1048
|
+
{
|
|
1049
|
+
type: "mrkdwn",
|
|
1050
|
+
text: `Approve: \`agentguard approve ${a.id}\` \xB7 Deny: \`agentguard deny ${a.id}\` \xB7 expires ${a.expires_at}`
|
|
1051
|
+
}
|
|
1052
|
+
]
|
|
1053
|
+
}
|
|
1054
|
+
];
|
|
1055
|
+
if (url) {
|
|
1056
|
+
blocks.push({
|
|
1057
|
+
type: "actions",
|
|
1058
|
+
elements: [
|
|
1059
|
+
{ type: "button", text: { type: "plain_text", text: "Approve" }, style: "primary", url },
|
|
1060
|
+
{
|
|
1061
|
+
type: "button",
|
|
1062
|
+
text: { type: "plain_text", text: "Deny" },
|
|
1063
|
+
style: "danger",
|
|
1064
|
+
url: url.replace("/approve/", "/deny/")
|
|
1065
|
+
}
|
|
1066
|
+
]
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
return { text, blocks };
|
|
1070
|
+
}
|
|
1071
|
+
function haltSlackMessage(event) {
|
|
1072
|
+
const cause = event.error?.cause ?? "";
|
|
1073
|
+
const text = `[agentguard] ${event.type}: ${event.tool} (run ${event.runId}) \u2014 ${cause}`;
|
|
1074
|
+
return {
|
|
1075
|
+
text,
|
|
1076
|
+
blocks: [
|
|
1077
|
+
{
|
|
1078
|
+
type: "section",
|
|
1079
|
+
text: {
|
|
1080
|
+
type: "mrkdwn",
|
|
1081
|
+
text: `*${event.type}* on \`${event.tool}\` (run \`${event.runId}\`)
|
|
1082
|
+
${cause}`
|
|
1083
|
+
}
|
|
1084
|
+
},
|
|
1085
|
+
{
|
|
1086
|
+
type: "context",
|
|
1087
|
+
elements: [
|
|
1088
|
+
{
|
|
1089
|
+
type: "mrkdwn",
|
|
1090
|
+
text: `\`agentguard report --run ${event.runId}\` for the full picture${event.type === "KILLED" ? "" : " \xB7 `agentguard kill` to stop everything"}`
|
|
1091
|
+
}
|
|
1092
|
+
]
|
|
1093
|
+
}
|
|
1094
|
+
]
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
function createAlerter(opts) {
|
|
1098
|
+
const { policy } = opts;
|
|
1099
|
+
const log = opts.log ?? (() => void 0);
|
|
1100
|
+
const channel = { fetch: opts.fetch };
|
|
1101
|
+
return async (event) => {
|
|
1102
|
+
if (event.type === "APPROVAL_DECIDED") return;
|
|
1103
|
+
if (!policy.alerts.on.includes(event.type)) return;
|
|
1104
|
+
const slack = event.type === "APPROVAL_REQUIRED" ? policy.approval.notify.slack || policy.alerts.slack : policy.alerts.slack;
|
|
1105
|
+
const webhook = event.type === "APPROVAL_REQUIRED" ? policy.approval.notify.webhook || policy.alerts.webhook : policy.alerts.webhook;
|
|
1106
|
+
const url = event.approval ? opts.approvalUrl?.(event.approval) : void 0;
|
|
1107
|
+
const message = event.type === "APPROVAL_REQUIRED" && event.approval ? approvalSlackMessage(event, url) : haltSlackMessage(event);
|
|
1108
|
+
const jobs = [];
|
|
1109
|
+
if (slack) {
|
|
1110
|
+
jobs.push(
|
|
1111
|
+
sendSlack(slack, message, channel).then((r) => {
|
|
1112
|
+
if (!r.ok) log(`slack alert failed: ${r.error ?? r.status}`);
|
|
1113
|
+
})
|
|
1114
|
+
);
|
|
1115
|
+
}
|
|
1116
|
+
if (webhook) {
|
|
1117
|
+
jobs.push(
|
|
1118
|
+
sendWebhook(
|
|
1119
|
+
webhook,
|
|
1120
|
+
{
|
|
1121
|
+
event: event.type,
|
|
1122
|
+
product: "agentguard",
|
|
1123
|
+
subject: message.text,
|
|
1124
|
+
summary: event.error?.cause ?? "",
|
|
1125
|
+
occurredAt: event.at,
|
|
1126
|
+
data: {
|
|
1127
|
+
runId: event.runId,
|
|
1128
|
+
tool: event.tool,
|
|
1129
|
+
error: event.error,
|
|
1130
|
+
approval: event.approval,
|
|
1131
|
+
approveUrl: url
|
|
1132
|
+
}
|
|
1133
|
+
},
|
|
1134
|
+
channel
|
|
1135
|
+
).then((r) => {
|
|
1136
|
+
if (!r.ok) log(`webhook alert failed: ${r.error ?? r.status}`);
|
|
1137
|
+
})
|
|
1138
|
+
);
|
|
1139
|
+
}
|
|
1140
|
+
await Promise.all(jobs);
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// src/context.ts
|
|
1145
|
+
import { existsSync } from "fs";
|
|
1146
|
+
import { resolve } from "path";
|
|
1147
|
+
import { Guard } from "@agentwares/agentguard-core";
|
|
1148
|
+
import {
|
|
1149
|
+
FileApprovalStore,
|
|
1150
|
+
FileAuditSink,
|
|
1151
|
+
FileKillSwitch,
|
|
1152
|
+
FileStateStore,
|
|
1153
|
+
loadPolicyFile
|
|
1154
|
+
} from "@agentwares/agentguard-core/node";
|
|
1155
|
+
import { existsSync as exists, readFileSync as readFileSync2 } from "fs";
|
|
1156
|
+
import { homedir } from "os";
|
|
1157
|
+
var DEFAULT_POLICY_FILE = "agentguard.yaml";
|
|
1158
|
+
function readStdin(maxBytes = 16 * 1024 * 1024, timeoutMs = 1e4) {
|
|
1159
|
+
if (process.stdin.isTTY) return Promise.resolve("");
|
|
1160
|
+
return new Promise((resolveText) => {
|
|
1161
|
+
const chunks = [];
|
|
1162
|
+
let size = 0;
|
|
1163
|
+
const done = () => {
|
|
1164
|
+
clearTimeout(timer);
|
|
1165
|
+
process.stdin.removeAllListeners("data");
|
|
1166
|
+
process.stdin.removeAllListeners("end");
|
|
1167
|
+
process.stdin.pause();
|
|
1168
|
+
resolveText(Buffer.concat(chunks).toString("utf8"));
|
|
1169
|
+
};
|
|
1170
|
+
const timer = setTimeout(done, timeoutMs);
|
|
1171
|
+
process.stdin.on("data", (chunk) => {
|
|
1172
|
+
size += chunk.length;
|
|
1173
|
+
if (size <= maxBytes) chunks.push(chunk);
|
|
1174
|
+
});
|
|
1175
|
+
process.stdin.on("end", done);
|
|
1176
|
+
process.stdin.on("error", done);
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
function homeFrom(io) {
|
|
1180
|
+
return io.env.HOME ?? io.env.USERPROFILE ?? homedir();
|
|
1181
|
+
}
|
|
1182
|
+
function defaultIo() {
|
|
1183
|
+
return {
|
|
1184
|
+
out: (line) => process.stdout.write(line + "\n"),
|
|
1185
|
+
err: (line) => process.stderr.write(line + "\n"),
|
|
1186
|
+
cwd: process.cwd(),
|
|
1187
|
+
env: process.env,
|
|
1188
|
+
tty: process.stdout.isTTY === true,
|
|
1189
|
+
stdin: () => readStdin()
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
function policyPathFrom(args, io) {
|
|
1193
|
+
return resolve(
|
|
1194
|
+
io.cwd,
|
|
1195
|
+
flagString(args, "config") ?? io.env.AGENTGUARD_CONFIG ?? DEFAULT_POLICY_FILE
|
|
1196
|
+
);
|
|
1197
|
+
}
|
|
1198
|
+
function loadPolicyFor(args, io, opts = {}) {
|
|
1199
|
+
return loadPolicyFile(policyPathFrom(args, io), {
|
|
1200
|
+
env: io.env,
|
|
1201
|
+
allowMissingEnv: opts.allowMissingEnv
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
function createFileGuard(loaded, opts = {}) {
|
|
1205
|
+
const kill = new FileKillSwitch(loaded.killPath);
|
|
1206
|
+
const audit = new FileAuditSink(loaded.auditPath);
|
|
1207
|
+
const approvals = new FileApprovalStore(loaded.stateDir);
|
|
1208
|
+
const alerter = opts.alerts === false ? void 0 : createAlerter({ policy: loaded.policy, approvalUrl: opts.approvalUrl, log: opts.log });
|
|
1209
|
+
const guard = new Guard({
|
|
1210
|
+
policy: loaded.policy,
|
|
1211
|
+
state: new FileStateStore(loaded.stateDir),
|
|
1212
|
+
audit,
|
|
1213
|
+
kill,
|
|
1214
|
+
approvals,
|
|
1215
|
+
env: opts.env ?? process.env,
|
|
1216
|
+
approvalUrl: opts.approvalUrl,
|
|
1217
|
+
onEvent: async (event) => {
|
|
1218
|
+
await opts.onEvent?.(event);
|
|
1219
|
+
await alerter?.(event);
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
return { guard, kill, audit, approvals, loaded };
|
|
1223
|
+
}
|
|
1224
|
+
function readRegistration(loaded) {
|
|
1225
|
+
const file = registrationPath(loaded.stateDir);
|
|
1226
|
+
if (!exists(file)) return void 0;
|
|
1227
|
+
try {
|
|
1228
|
+
const reg = JSON.parse(readFileSync2(file, "utf8"));
|
|
1229
|
+
return reg;
|
|
1230
|
+
} catch {
|
|
1231
|
+
return void 0;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
function approvalUrlFor(reg) {
|
|
1235
|
+
if (!reg) return void 0;
|
|
1236
|
+
return (r) => `${reg.baseUrl}/approve/${r.id}?token=${reg.token}`;
|
|
1237
|
+
}
|
|
1238
|
+
function describeError(err) {
|
|
1239
|
+
if (err && typeof err === "object" && "code" in err && "cause" in err) {
|
|
1240
|
+
const e = err;
|
|
1241
|
+
return `${e.code}: ${e.cause}${e.fix ? `
|
|
1242
|
+
fix: ${e.fix}` : ""}`;
|
|
1243
|
+
}
|
|
1244
|
+
return err instanceof Error ? err.message : String(err);
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
export {
|
|
1248
|
+
parseArgs,
|
|
1249
|
+
flagString,
|
|
1250
|
+
flagList,
|
|
1251
|
+
flagBool,
|
|
1252
|
+
flagNumber,
|
|
1253
|
+
version,
|
|
1254
|
+
registrationPath,
|
|
1255
|
+
approvalSlackMessage,
|
|
1256
|
+
haltSlackMessage,
|
|
1257
|
+
createAlerter,
|
|
1258
|
+
DEFAULT_POLICY_FILE,
|
|
1259
|
+
homeFrom,
|
|
1260
|
+
defaultIo,
|
|
1261
|
+
policyPathFrom,
|
|
1262
|
+
loadPolicyFor,
|
|
1263
|
+
createFileGuard,
|
|
1264
|
+
readRegistration,
|
|
1265
|
+
approvalUrlFor,
|
|
1266
|
+
describeError
|
|
1267
|
+
};
|
|
1268
|
+
//# sourceMappingURL=chunk-SUXQTT3X.js.map
|