@pensar/apex 2.4.0 → 2.5.0-canary.0af37eb0
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/build/agent-2edb792c.js +12 -0
- package/build/agent-317v8mmz.js +12 -0
- package/build/agent-vzqc5vtn.js +14 -0
- package/build/{agent-5ejt5vpz.js → agent-y85zsera.js} +42 -42
- package/build/{apps-17wvz1d7.js → apps-qf8jww9t.js} +74 -43
- package/build/{auth-z3h9859n.js → auth-wf1r533f.js} +57 -61
- package/build/blackboxAgent-cb4na30e.js +12 -0
- package/build/blackboxPentest-bf7b9m36.js +58 -0
- package/build/{cli-9rhzhgx2.js → cli-079enner.js} +5 -5
- package/build/cli-4ptm7wgt.js +12188 -0
- package/build/{cli-tznv8pf1.js → cli-6hrf9z35.js} +4 -4
- package/build/{cli-mavved45.js → cli-80mx747a.js} +89 -96
- package/build/cli-8w8k4dph.js +15 -0
- package/build/{cli-2cbwdk78.js → cli-a4v5vwfw.js} +4 -4
- package/build/cli-ag6jtndp.js +32 -0
- package/build/cli-bb02pjt0.js +1485 -0
- package/build/{cli-k71t434r.js → cli-ec2hwkv3.js} +34 -76
- package/build/{cli-k8kc47pq.js → cli-f3sg3e9x.js} +118 -115
- package/build/{cli-bc05qbss.js → cli-h6y3bt60.js} +13 -21
- package/build/{cli-xshasbwe.js → cli-jzcsaygf.js} +31 -52
- package/build/{cli-vnynf0js.js → cli-k8hgxz61.js} +11 -5
- package/build/{cli-32z0017y.js → cli-kn55pk78.js} +36 -60
- package/build/{cli-tkc598ey.js → cli-q8pr0zqg.js} +10042 -7665
- package/build/{cli-j54qa6tm.js → cli-qktcyj48.js} +1 -1
- package/build/cli-retw3rw5.js +12 -0
- package/build/{cli-b1adytsy.js → cli-s2y86fd5.js} +67 -39
- package/build/{cli-vq52kp7j.js → cli-t6mngnwd.js} +150 -128
- package/build/cli-tjm77pmx.js +12075 -0
- package/build/{cli-dm0fc0bm.js → cli-v1sarr4y.js} +5 -9
- package/build/cli-wpmm960k.js +22 -0
- package/build/{cli-5k33webc.js → cli-x069hfr2.js} +355 -332
- package/build/{cli-ee3axgts.js → cli-xbhr5khz.js} +1 -1
- package/build/{cli-repbyhkk.js → cli-y212s0r8.js} +26315 -25555
- package/build/cli-z82n3qk1.js +6 -0
- package/build/{cli-gq40s5b3.js → cli-zky875st.js} +33 -46
- package/build/cli.js +696 -132
- package/build/{config-f1mj4nhd.js → config-g93k0986.js} +29 -29
- package/build/{doctor-ekneewa3.js → doctor-4fcx7g0h.js} +4 -9
- package/build/{fastStrike-8zka43xs.js → fastStrike-af31ggmt.js} +26 -28
- package/build/{fixes-b89s5haw.js → fixes-6kxes4g7.js} +22 -27
- package/build/getMachineId-bsd-zr67nd9p.js +36 -0
- package/build/getMachineId-darwin-fd1d562d.js +36 -0
- package/build/getMachineId-linux-kjmg243j.js +29 -0
- package/build/getMachineId-unsupported-n4r58vke.js +19 -0
- package/build/getMachineId-win-yzgpfsrb.js +38 -0
- package/build/{index-sf16jm0m.js → index-3dpcjj6e.js} +137 -162
- package/build/index-4b9nc9e8.js +36 -0
- package/build/index-9f0xagac.js +22 -0
- package/build/index-9y2bjhh2.js +100 -0
- package/build/index-a1bg29j1.js +1559 -0
- package/build/{index-cbwn03kz.js → index-a2xycbjs.js} +12 -31
- package/build/index-k1mb1edx.js +12 -0
- package/build/{index-psqjpw5m.js → index-nweqptgs.js} +7 -7
- package/build/{index-6d22pyxt.js → index-r8554acn.js} +3000 -2435
- package/build/index-rjmmakbh.js +17 -0
- package/build/index-yfcbhfc1.js +9 -0
- package/build/{issues-xx5bs4md.js → issues-vgfdw93j.js} +81 -35
- package/build/{logs-qtxe51w2.js → logs-czxxx0n0.js} +20 -25
- package/build/{multipart-parser-g2xxkezz.js → multipart-parser-vjjdbpd1.js} +10 -10
- package/build/{offesecAgent-b9e2xm6v.js → offesecAgent-jwnbnsqm.js} +6 -13
- package/build/{parse-rtccymzn.js → parse-cqecqrc5.js} +0 -4
- package/build/pentest-hbwbfw9w.js +21 -0
- package/build/{pentests-6ks3szc4.js → pentests-6pp1j1w5.js} +23 -28
- package/build/{targetedPentest-s1ptvq8e.js → targetedPentest-34zhke7a.js} +16 -20
- package/build/{targets-sxygyj87.js → targets-yvh0d0fr.js} +22 -27
- package/build/threatModel-r96hed1d.js +19 -0
- package/build/{token-3bbp59y6.js → token-n0tmq8n5.js} +2 -2
- package/build/{token-util-6xjme11b.js → token-util-bv80pj47.js} +1 -2
- package/build/{uninstall-tvsh81v8.js → uninstall-qdzsynrt.js} +7 -4
- package/build/{upload-7wdyyqmr.js → upload-twg8pvy7.js} +7 -13
- package/build/{utils-7fwdkqk6.js → utils-cnv9jj0h.js} +7 -29
- package/package.json +8 -2
- package/build/agent-mvpgvgks.js +0 -19
- package/build/agent-nhs1w5w0.js +0 -29
- package/build/authentication-3s97cpk4.js +0 -19
- package/build/blackboxAgent-gw0a1ca4.js +0 -19
- package/build/blackboxPentest-44333zss.js +0 -37
- package/build/cli-0n4r54hq.js +0 -414
- package/build/cli-72cvcqhg.js +0 -22
- package/build/cli-qqt4gj1w.js +0 -53
- package/build/cli-swpbx60z.js +0 -24441
- package/build/index-4ad3sdwk.js +0 -39
- package/build/index-ghwf5z3v.js +0 -12
- package/build/index-hqjdg6fg.js +0 -205
- package/build/index-mtq7kmxz.js +0 -12856
- package/build/index-rbzhk712.js +0 -33
- package/build/index-y5w6n3tb.js +0 -19
- package/build/main-mmjp338j.js +0 -324
- package/build/pentest-xtc1sjdw.js +0 -29
- package/build/threatModel-xsm6fwk5.js +0 -27
- /package/build/{cli-c8131c4q.js → cli-0wsh8j2t.js} +0 -0
- /package/build/{cli-e08r86zk.js → cli-b3dvxjgk.js} +0 -0
- /package/build/{cli-fw5r7pfj.js → cli-q126f6ef.js} +0 -0
- /package/build/{cli-9fsre5pt.js → cli-qba2x69h.js} +0 -0
package/build/cli.js
CHANGED
|
@@ -1,33 +1,369 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import"./cli-
|
|
3
|
+
import"./cli-wpmm960k.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
buildAuthConfig,
|
|
10
|
-
init_ai1 as init_ai,
|
|
5
|
+
endAllActiveRootSpans,
|
|
6
|
+
init_active_root_spans,
|
|
7
|
+
init_model_history,
|
|
11
8
|
init_models,
|
|
9
|
+
buildAuthConfig,
|
|
10
|
+
init_utils,
|
|
12
11
|
init_session,
|
|
12
|
+
createLogger,
|
|
13
|
+
logger,
|
|
13
14
|
init_structured,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
init_ai2
|
|
16
|
+
} from "./cli-q8pr0zqg.js";
|
|
17
|
+
import {
|
|
18
|
+
require_src,
|
|
19
|
+
require_src2,
|
|
20
|
+
require_src3,
|
|
21
|
+
require_src4,
|
|
22
|
+
require_index_node_http,
|
|
23
|
+
require_src5,
|
|
24
|
+
require_index_shim,
|
|
25
|
+
ActiveSpanProcessor
|
|
26
|
+
} from "./cli-4ptm7wgt.js";
|
|
27
|
+
import {
|
|
28
|
+
createThreatModelPrompt
|
|
29
|
+
} from "./cli-q126f6ef.js";
|
|
30
|
+
import"./cli-qktcyj48.js";
|
|
23
31
|
import {
|
|
24
32
|
init_package,
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
version,
|
|
34
|
+
package_default,
|
|
35
|
+
init_installation
|
|
36
|
+
} from "./cli-k8hgxz61.js";
|
|
37
|
+
import {
|
|
38
|
+
require_src6
|
|
39
|
+
} from "./cli-bb02pjt0.js";
|
|
27
40
|
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
__toESM,
|
|
42
|
+
__commonJS,
|
|
43
|
+
__require
|
|
44
|
+
} from "./cli-h6y3bt60.js";
|
|
45
|
+
|
|
46
|
+
// node_modules/dotenv/lib/main.js
|
|
47
|
+
var require_main = __commonJS(function(exports, module) {
|
|
48
|
+
var fs = __require("fs");
|
|
49
|
+
var path = __require("path");
|
|
50
|
+
var os = __require("os");
|
|
51
|
+
var crypto = __require("crypto");
|
|
52
|
+
var TIPS = [
|
|
53
|
+
"◈ encrypted .env [www.dotenvx.com]",
|
|
54
|
+
"◈ secrets for agents [www.dotenvx.com]",
|
|
55
|
+
"⌁ auth for agents [www.vestauth.com]",
|
|
56
|
+
"⌘ custom filepath { path: '/custom/path/.env' }",
|
|
57
|
+
"⌘ enable debugging { debug: true }",
|
|
58
|
+
"⌘ override existing { override: true }",
|
|
59
|
+
"⌘ suppress logs { quiet: true }",
|
|
60
|
+
"⌘ multiple files { path: ['.env.local', '.env'] }"
|
|
61
|
+
];
|
|
62
|
+
function _getRandomTip() {
|
|
63
|
+
return TIPS[Math.floor(Math.random() * TIPS.length)];
|
|
64
|
+
}
|
|
65
|
+
function parseBoolean(value) {
|
|
66
|
+
if (typeof value === "string") {
|
|
67
|
+
return !["false", "0", "no", "off", ""].includes(value.toLowerCase());
|
|
68
|
+
}
|
|
69
|
+
return Boolean(value);
|
|
70
|
+
}
|
|
71
|
+
function supportsAnsi() {
|
|
72
|
+
return process.stdout.isTTY;
|
|
73
|
+
}
|
|
74
|
+
function dim(text) {
|
|
75
|
+
return supportsAnsi() ? `\x1B[2m${text}\x1B[0m` : text;
|
|
76
|
+
}
|
|
77
|
+
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
78
|
+
function parse(src) {
|
|
79
|
+
const obj = {};
|
|
80
|
+
let lines = src.toString();
|
|
81
|
+
lines = lines.replace(/\r\n?/mg, `
|
|
82
|
+
`);
|
|
83
|
+
let match;
|
|
84
|
+
while ((match = LINE.exec(lines)) != null) {
|
|
85
|
+
const key = match[1];
|
|
86
|
+
let value = match[2] || "";
|
|
87
|
+
value = value.trim();
|
|
88
|
+
const maybeQuote = value[0];
|
|
89
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
|
90
|
+
if (maybeQuote === '"') {
|
|
91
|
+
value = value.replace(/\\n/g, `
|
|
92
|
+
`);
|
|
93
|
+
value = value.replace(/\\r/g, "\r");
|
|
94
|
+
}
|
|
95
|
+
obj[key] = value;
|
|
96
|
+
}
|
|
97
|
+
return obj;
|
|
98
|
+
}
|
|
99
|
+
function _parseVault(options) {
|
|
100
|
+
options = options || {};
|
|
101
|
+
const vaultPath = _vaultPath(options);
|
|
102
|
+
options.path = vaultPath;
|
|
103
|
+
const result = DotenvModule.configDotenv(options);
|
|
104
|
+
if (!result.parsed) {
|
|
105
|
+
const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
|
106
|
+
err.code = "MISSING_DATA";
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
const keys = _dotenvKey(options).split(",");
|
|
110
|
+
const length = keys.length;
|
|
111
|
+
let decrypted;
|
|
112
|
+
for (let i = 0;i < length; i++) {
|
|
113
|
+
try {
|
|
114
|
+
const key = keys[i].trim();
|
|
115
|
+
const attrs = _instructions(result, key);
|
|
116
|
+
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
|
117
|
+
break;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
if (i + 1 >= length) {
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return DotenvModule.parse(decrypted);
|
|
125
|
+
}
|
|
126
|
+
function _warn(message) {
|
|
127
|
+
console.error(`⚠ ${message}`);
|
|
128
|
+
}
|
|
129
|
+
function _debug(message) {
|
|
130
|
+
console.log(`┆ ${message}`);
|
|
131
|
+
}
|
|
132
|
+
function _log(message) {
|
|
133
|
+
console.log(`◇ ${message}`);
|
|
134
|
+
}
|
|
135
|
+
function _dotenvKey(options) {
|
|
136
|
+
if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
|
|
137
|
+
return options.DOTENV_KEY;
|
|
138
|
+
}
|
|
139
|
+
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
|
|
140
|
+
return process.env.DOTENV_KEY;
|
|
141
|
+
}
|
|
142
|
+
return "";
|
|
143
|
+
}
|
|
144
|
+
function _instructions(result, dotenvKey) {
|
|
145
|
+
let uri;
|
|
146
|
+
try {
|
|
147
|
+
uri = new URL(dotenvKey);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (error.code === "ERR_INVALID_URL") {
|
|
150
|
+
const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
|
|
151
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
152
|
+
throw err;
|
|
153
|
+
}
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
const key = uri.password;
|
|
157
|
+
if (!key) {
|
|
158
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing key part");
|
|
159
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
160
|
+
throw err;
|
|
161
|
+
}
|
|
162
|
+
const environment = uri.searchParams.get("environment");
|
|
163
|
+
if (!environment) {
|
|
164
|
+
const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
|
|
165
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
166
|
+
throw err;
|
|
167
|
+
}
|
|
168
|
+
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
|
|
169
|
+
const ciphertext = result.parsed[environmentKey];
|
|
170
|
+
if (!ciphertext) {
|
|
171
|
+
const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
|
172
|
+
err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
|
|
173
|
+
throw err;
|
|
174
|
+
}
|
|
175
|
+
return { ciphertext, key };
|
|
176
|
+
}
|
|
177
|
+
function _vaultPath(options) {
|
|
178
|
+
let possibleVaultPath = null;
|
|
179
|
+
if (options && options.path && options.path.length > 0) {
|
|
180
|
+
if (Array.isArray(options.path)) {
|
|
181
|
+
for (const filepath of options.path) {
|
|
182
|
+
if (fs.existsSync(filepath)) {
|
|
183
|
+
possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
|
|
191
|
+
}
|
|
192
|
+
if (fs.existsSync(possibleVaultPath)) {
|
|
193
|
+
return possibleVaultPath;
|
|
194
|
+
}
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
function _resolveHome(envPath) {
|
|
198
|
+
return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
|
|
199
|
+
}
|
|
200
|
+
function _configVault(options) {
|
|
201
|
+
const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || options && options.debug);
|
|
202
|
+
const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || options && options.quiet);
|
|
203
|
+
if (debug || !quiet) {
|
|
204
|
+
_log("loading env from encrypted .env.vault");
|
|
205
|
+
}
|
|
206
|
+
const parsed = DotenvModule._parseVault(options);
|
|
207
|
+
let processEnv = process.env;
|
|
208
|
+
if (options && options.processEnv != null) {
|
|
209
|
+
processEnv = options.processEnv;
|
|
210
|
+
}
|
|
211
|
+
DotenvModule.populate(processEnv, parsed, options);
|
|
212
|
+
return { parsed };
|
|
213
|
+
}
|
|
214
|
+
function configDotenv(options) {
|
|
215
|
+
const dotenvPath = path.resolve(process.cwd(), ".env");
|
|
216
|
+
let encoding = "utf8";
|
|
217
|
+
let processEnv = process.env;
|
|
218
|
+
if (options && options.processEnv != null) {
|
|
219
|
+
processEnv = options.processEnv;
|
|
220
|
+
}
|
|
221
|
+
let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || options && options.debug);
|
|
222
|
+
let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || options && options.quiet);
|
|
223
|
+
if (options && options.encoding) {
|
|
224
|
+
encoding = options.encoding;
|
|
225
|
+
} else {
|
|
226
|
+
if (debug) {
|
|
227
|
+
_debug("no encoding is specified (UTF-8 is used by default)");
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
let optionPaths = [dotenvPath];
|
|
231
|
+
if (options && options.path) {
|
|
232
|
+
if (!Array.isArray(options.path)) {
|
|
233
|
+
optionPaths = [_resolveHome(options.path)];
|
|
234
|
+
} else {
|
|
235
|
+
optionPaths = [];
|
|
236
|
+
for (const filepath of options.path) {
|
|
237
|
+
optionPaths.push(_resolveHome(filepath));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
let lastError;
|
|
242
|
+
const parsedAll = {};
|
|
243
|
+
for (const path of optionPaths) {
|
|
244
|
+
try {
|
|
245
|
+
const parsed = DotenvModule.parse(fs.readFileSync(path, { encoding }));
|
|
246
|
+
DotenvModule.populate(parsedAll, parsed, options);
|
|
247
|
+
} catch (e) {
|
|
248
|
+
if (debug) {
|
|
249
|
+
_debug(`failed to load ${path} ${e.message}`);
|
|
250
|
+
}
|
|
251
|
+
lastError = e;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const populated = DotenvModule.populate(processEnv, parsedAll, options);
|
|
255
|
+
debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
|
|
256
|
+
quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
|
|
257
|
+
if (debug || !quiet) {
|
|
258
|
+
const keysCount = Object.keys(populated).length;
|
|
259
|
+
const shortPaths = [];
|
|
260
|
+
for (const filePath of optionPaths) {
|
|
261
|
+
try {
|
|
262
|
+
const relative2 = path.relative(process.cwd(), filePath);
|
|
263
|
+
shortPaths.push(relative2);
|
|
264
|
+
} catch (e) {
|
|
265
|
+
if (debug) {
|
|
266
|
+
_debug(`failed to load ${filePath} ${e.message}`);
|
|
267
|
+
}
|
|
268
|
+
lastError = e;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
_log(`injected env (${keysCount}) from ${shortPaths.join(",")} ${dim(`// tip: ${_getRandomTip()}`)}`);
|
|
272
|
+
}
|
|
273
|
+
if (lastError) {
|
|
274
|
+
return { parsed: parsedAll, error: lastError };
|
|
275
|
+
} else {
|
|
276
|
+
return { parsed: parsedAll };
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function config(options) {
|
|
280
|
+
if (_dotenvKey(options).length === 0) {
|
|
281
|
+
return DotenvModule.configDotenv(options);
|
|
282
|
+
}
|
|
283
|
+
const vaultPath = _vaultPath(options);
|
|
284
|
+
if (!vaultPath) {
|
|
285
|
+
_warn(`you set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}`);
|
|
286
|
+
return DotenvModule.configDotenv(options);
|
|
287
|
+
}
|
|
288
|
+
return DotenvModule._configVault(options);
|
|
289
|
+
}
|
|
290
|
+
function decrypt(encrypted, keyStr) {
|
|
291
|
+
const key = Buffer.from(keyStr.slice(-64), "hex");
|
|
292
|
+
let ciphertext = Buffer.from(encrypted, "base64");
|
|
293
|
+
const nonce = ciphertext.subarray(0, 12);
|
|
294
|
+
const authTag = ciphertext.subarray(-16);
|
|
295
|
+
ciphertext = ciphertext.subarray(12, -16);
|
|
296
|
+
try {
|
|
297
|
+
const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
|
|
298
|
+
aesgcm.setAuthTag(authTag);
|
|
299
|
+
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
300
|
+
} catch (error) {
|
|
301
|
+
const isRange = error instanceof RangeError;
|
|
302
|
+
const invalidKeyLength = error.message === "Invalid key length";
|
|
303
|
+
const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
|
|
304
|
+
if (isRange || invalidKeyLength) {
|
|
305
|
+
const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
|
|
306
|
+
err.code = "INVALID_DOTENV_KEY";
|
|
307
|
+
throw err;
|
|
308
|
+
} else if (decryptionFailed) {
|
|
309
|
+
const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
|
|
310
|
+
err.code = "DECRYPTION_FAILED";
|
|
311
|
+
throw err;
|
|
312
|
+
} else {
|
|
313
|
+
throw error;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function populate(processEnv, parsed, options = {}) {
|
|
318
|
+
const debug = Boolean(options && options.debug);
|
|
319
|
+
const override = Boolean(options && options.override);
|
|
320
|
+
const populated = {};
|
|
321
|
+
if (typeof parsed !== "object") {
|
|
322
|
+
const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
|
|
323
|
+
err.code = "OBJECT_REQUIRED";
|
|
324
|
+
throw err;
|
|
325
|
+
}
|
|
326
|
+
for (const key of Object.keys(parsed)) {
|
|
327
|
+
if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
328
|
+
if (override === true) {
|
|
329
|
+
processEnv[key] = parsed[key];
|
|
330
|
+
populated[key] = parsed[key];
|
|
331
|
+
}
|
|
332
|
+
if (debug) {
|
|
333
|
+
if (override === true) {
|
|
334
|
+
_debug(`"${key}" is already defined and WAS overwritten`);
|
|
335
|
+
} else {
|
|
336
|
+
_debug(`"${key}" is already defined and was NOT overwritten`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
} else {
|
|
340
|
+
processEnv[key] = parsed[key];
|
|
341
|
+
populated[key] = parsed[key];
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return populated;
|
|
345
|
+
}
|
|
346
|
+
var DotenvModule = {
|
|
347
|
+
configDotenv,
|
|
348
|
+
_configVault,
|
|
349
|
+
_parseVault,
|
|
350
|
+
config,
|
|
351
|
+
decrypt,
|
|
352
|
+
parse,
|
|
353
|
+
populate
|
|
354
|
+
};
|
|
355
|
+
module.exports.configDotenv = DotenvModule.configDotenv;
|
|
356
|
+
module.exports._configVault = DotenvModule._configVault;
|
|
357
|
+
module.exports._parseVault = DotenvModule._parseVault;
|
|
358
|
+
module.exports.config = DotenvModule.config;
|
|
359
|
+
module.exports.decrypt = DotenvModule.decrypt;
|
|
360
|
+
module.exports.parse = DotenvModule.parse;
|
|
361
|
+
module.exports.populate = DotenvModule.populate;
|
|
362
|
+
module.exports = DotenvModule;
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
// src/cli.ts
|
|
366
|
+
var import_dotenv = __toESM(require_main(), 1);
|
|
31
367
|
// package.json
|
|
32
368
|
var package_default2 = {
|
|
33
369
|
author: "Pensar",
|
|
@@ -47,6 +383,10 @@ var package_default2 = {
|
|
|
47
383
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
48
384
|
"@openrouter/ai-sdk-provider": "^2.9.1",
|
|
49
385
|
"@opentelemetry/api": "^1.9.1",
|
|
386
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.221.0",
|
|
387
|
+
"@opentelemetry/otlp-exporter-base": "^0.221.0",
|
|
388
|
+
"@opentelemetry/otlp-transformer": "^0.221.0",
|
|
389
|
+
"@opentelemetry/resources": "^2.10.0",
|
|
50
390
|
"@opentui/core": "^0.1.107",
|
|
51
391
|
"@opentui/react": "^0.1.107",
|
|
52
392
|
"@pensar/surface": "0.3.0",
|
|
@@ -70,6 +410,8 @@ var package_default2 = {
|
|
|
70
410
|
description: "AI-powered penetration testing CLI tool with terminal UI",
|
|
71
411
|
devDependencies: {
|
|
72
412
|
"@biomejs/biome": "2.4.14",
|
|
413
|
+
"@opentelemetry/context-async-hooks": "^2.10.0",
|
|
414
|
+
"@opentelemetry/sdk-trace-base": "^2.10.0",
|
|
73
415
|
"@types/bun": "^1.3.14",
|
|
74
416
|
"@types/mailparser": "^3.4.6",
|
|
75
417
|
"@types/mime-types": "^3.0.1",
|
|
@@ -116,7 +458,7 @@ var package_default2 = {
|
|
|
116
458
|
url: "https://github.com/pensarai/apex.git"
|
|
117
459
|
},
|
|
118
460
|
scripts: {
|
|
119
|
-
build: "bun build src/cli.ts --outdir build --target node --format esm --splitting --external @opentui/core --external @opentui/react --external @opentui/react/* --external react --external react/jsx-runtime --external react/jsx-dev-runtime --external react-reconciler --external weave --external electron --external chromium-bidi --external camoufox-js",
|
|
461
|
+
build: "rm -rf build && bun build src/cli.ts --outdir build --target node --format esm --splitting --external @opentui/core --external @opentui/react --external @opentui/react/* --external react --external react/jsx-runtime --external react/jsx-dev-runtime --external react-reconciler --external weave --external electron --external chromium-bidi --external camoufox-js",
|
|
120
462
|
"build:binaries": "bun run generate:ascii && mkdir -p dist && bun run build:binary:macos-arm64 && bun run build:binary:macos-x64 && bun run build:binary:linux-x64 && bun run build:binary:linux-arm64",
|
|
121
463
|
"build:binary": "bun run generate:ascii && bun build src/cli.ts --compile --external electron --external chromium-bidi --external camoufox-js --outfile pensar",
|
|
122
464
|
"build:binary:linux-arm64": "bun build src/cli.ts --compile --external electron --external chromium-bidi --external camoufox-js --target=bun-linux-arm64 --outfile dist/pensar-linux-arm64",
|
|
@@ -144,14 +486,29 @@ var package_default2 = {
|
|
|
144
486
|
tsc: "tsc --noEmit"
|
|
145
487
|
},
|
|
146
488
|
type: "module",
|
|
147
|
-
version: "2.
|
|
489
|
+
version: "2.5.0-canary.0af37eb0"
|
|
148
490
|
};
|
|
149
491
|
|
|
150
492
|
// src/core/ai/index.ts
|
|
151
|
-
|
|
493
|
+
init_ai2();
|
|
494
|
+
init_model_history();
|
|
152
495
|
init_models();
|
|
153
496
|
init_utils();
|
|
154
497
|
|
|
498
|
+
// src/core/api/clientIdentity.ts
|
|
499
|
+
init_installation();
|
|
500
|
+
var currentCommand;
|
|
501
|
+
function setCurrentCommand(command) {
|
|
502
|
+
currentCommand = normalizeCommand(command);
|
|
503
|
+
}
|
|
504
|
+
var COMMAND_SHAPE = /^[a-z][a-z0-9-]{0,31}$/;
|
|
505
|
+
function normalizeCommand(command) {
|
|
506
|
+
if (!command)
|
|
507
|
+
return;
|
|
508
|
+
const trimmed = command.trim().toLowerCase();
|
|
509
|
+
return COMMAND_SHAPE.test(trimmed) ? trimmed : undefined;
|
|
510
|
+
}
|
|
511
|
+
|
|
155
512
|
// src/core/cli/logLevelArgs.ts
|
|
156
513
|
var VALID_LOG_LEVELS = new Set([
|
|
157
514
|
"DEBUG",
|
|
@@ -266,12 +623,12 @@ class AgentEventBus {
|
|
|
266
623
|
const p = payload;
|
|
267
624
|
const isLifecycle = forwardKey === "subagent-spawn" || forwardKey === "subagent-complete";
|
|
268
625
|
if (isLifecycle) {
|
|
269
|
-
const
|
|
626
|
+
const next = { ...p };
|
|
270
627
|
if (!p.parentSubagentId)
|
|
271
|
-
|
|
628
|
+
next.parentSubagentId = childSessionId;
|
|
272
629
|
if (!p.parentSessionId)
|
|
273
|
-
|
|
274
|
-
parent.emit(forwardKey,
|
|
630
|
+
next.parentSessionId = childSessionId;
|
|
631
|
+
parent.emit(forwardKey, next);
|
|
275
632
|
return;
|
|
276
633
|
}
|
|
277
634
|
const next = { ...p };
|
|
@@ -371,7 +728,7 @@ class AgentEventBus {
|
|
|
371
728
|
// src/core/installation/index.ts
|
|
372
729
|
init_package();
|
|
373
730
|
import { spawnSync } from "node:child_process";
|
|
374
|
-
function
|
|
731
|
+
function getCurrentVersion2() {
|
|
375
732
|
return package_default.version;
|
|
376
733
|
}
|
|
377
734
|
function isNewerVersion(current, latest) {
|
|
@@ -436,7 +793,7 @@ function getUpgradeCommandString(method) {
|
|
|
436
793
|
return `${cmd} ${args.join(" ")}`;
|
|
437
794
|
}
|
|
438
795
|
function runUpgrade(method, options) {
|
|
439
|
-
const currentVersion =
|
|
796
|
+
const currentVersion = getCurrentVersion2();
|
|
440
797
|
const { cmd, args } = getUpgradeCommand(method);
|
|
441
798
|
const interactive = options?.interactive ?? false;
|
|
442
799
|
const result = spawnSync(cmd, args, {
|
|
@@ -461,7 +818,7 @@ function runUpgrade(method, options) {
|
|
|
461
818
|
};
|
|
462
819
|
}
|
|
463
820
|
async function upgrade(options) {
|
|
464
|
-
const currentVersion =
|
|
821
|
+
const currentVersion = getCurrentVersion2();
|
|
465
822
|
let latestVersion;
|
|
466
823
|
try {
|
|
467
824
|
latestVersion = await getLatestVersion();
|
|
@@ -508,10 +865,203 @@ import os from "node:os";
|
|
|
508
865
|
import path from "node:path";
|
|
509
866
|
var ERROR_LOG_PATH = path.join(os.homedir(), ".pensar", "error.log");
|
|
510
867
|
|
|
868
|
+
// src/core/observability/runtime.ts
|
|
869
|
+
init_package();
|
|
870
|
+
init_structured();
|
|
871
|
+
init_active_root_spans();
|
|
872
|
+
var import_api = __toESM(require_src6(), 1);
|
|
873
|
+
var import_context_async_hooks = __toESM(require_src(), 1);
|
|
874
|
+
var import_exporter_trace_otlp_http = __toESM(require_src5(), 1);
|
|
875
|
+
var import_otlp_exporter_base = __toESM(require_src2(), 1);
|
|
876
|
+
var import_node_http = __toESM(require_index_node_http(), 1);
|
|
877
|
+
var import_otlp_transformer = __toESM(require_src4(), 1);
|
|
878
|
+
var import_resources = __toESM(require_src3(), 1);
|
|
879
|
+
var import_sdk_trace_base = __toESM(require_index_shim(), 1);
|
|
880
|
+
import { randomUUID } from "node:crypto";
|
|
881
|
+
var DEFAULT_SHUTDOWN_TIMEOUT_MS = 5000;
|
|
882
|
+
function withTimeout(promise, timeoutMs) {
|
|
883
|
+
return new Promise((resolve) => {
|
|
884
|
+
let settled = false;
|
|
885
|
+
const settle = (result) => {
|
|
886
|
+
if (settled)
|
|
887
|
+
return;
|
|
888
|
+
settled = true;
|
|
889
|
+
clearTimeout(timer);
|
|
890
|
+
resolve(result);
|
|
891
|
+
};
|
|
892
|
+
const timer = setTimeout(() => settle("timed-out"), timeoutMs);
|
|
893
|
+
promise.then(() => settle("completed"), () => settle("completed"));
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
var log = createLogger("observability");
|
|
897
|
+
var NOOP_RUNTIME = {
|
|
898
|
+
async forceFlush() {},
|
|
899
|
+
async shutdown() {
|
|
900
|
+
return "completed";
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
function isOtelSdkDisabled(env) {
|
|
904
|
+
return env.OTEL_SDK_DISABLED === "true";
|
|
905
|
+
}
|
|
906
|
+
function resolveTracesEndpoint(env) {
|
|
907
|
+
const specific = env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT?.trim();
|
|
908
|
+
if (specific)
|
|
909
|
+
return specific;
|
|
910
|
+
const generic = env.OTEL_EXPORTER_OTLP_ENDPOINT?.trim();
|
|
911
|
+
if (!generic)
|
|
912
|
+
return null;
|
|
913
|
+
return `${generic.endsWith("/") ? generic : `${generic}/`}v1/traces`;
|
|
914
|
+
}
|
|
915
|
+
function resolveTracesProtocol(env) {
|
|
916
|
+
const raw = (env.OTEL_EXPORTER_OTLP_TRACES_PROTOCOL ?? env.OTEL_EXPORTER_OTLP_PROTOCOL ?? "").trim();
|
|
917
|
+
return raw === "http/protobuf" ? "http/protobuf" : "http/json";
|
|
918
|
+
}
|
|
919
|
+
function parseResourceAttributes(env) {
|
|
920
|
+
const raw = env.OTEL_RESOURCE_ATTRIBUTES;
|
|
921
|
+
if (!raw)
|
|
922
|
+
return {};
|
|
923
|
+
const attrs = {};
|
|
924
|
+
for (const pair of raw.split(",")) {
|
|
925
|
+
const eq = pair.indexOf("=");
|
|
926
|
+
if (eq <= 0)
|
|
927
|
+
continue;
|
|
928
|
+
const key = pair.slice(0, eq).trim();
|
|
929
|
+
const value = pair.slice(eq + 1).trim();
|
|
930
|
+
if (key && value)
|
|
931
|
+
attrs[key] = value;
|
|
932
|
+
}
|
|
933
|
+
return attrs;
|
|
934
|
+
}
|
|
935
|
+
function buildResource(env) {
|
|
936
|
+
const resourceAttributes = parseResourceAttributes(env);
|
|
937
|
+
return import_resources.resourceFromAttributes({
|
|
938
|
+
"service.version": version,
|
|
939
|
+
"service.instance.id": randomUUID(),
|
|
940
|
+
...resourceAttributes,
|
|
941
|
+
"service.name": env.OTEL_SERVICE_NAME?.trim() || resourceAttributes["service.name"] || "apex"
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
function createTraceExporter(protocol) {
|
|
945
|
+
if (protocol === "http/json") {
|
|
946
|
+
return new import_exporter_trace_otlp_http.OTLPTraceExporter;
|
|
947
|
+
}
|
|
948
|
+
return new import_otlp_exporter_base.OTLPExporterBase(import_node_http.createOtlpHttpExportDelegate(import_node_http.convertLegacyHttpOptions({}, "TRACES", "v1/traces", {
|
|
949
|
+
"Content-Type": "application/x-protobuf"
|
|
950
|
+
}), import_otlp_transformer.ProtobufTraceSerializer, "otlp_http_span_exporter", import_otlp_transformer.TraceExporterMetricsHelper, undefined));
|
|
951
|
+
}
|
|
952
|
+
var activeRuntime = null;
|
|
953
|
+
function startObservabilityRuntime(env = process.env, opts) {
|
|
954
|
+
if (activeRuntime)
|
|
955
|
+
return activeRuntime;
|
|
956
|
+
if (isOtelSdkDisabled(env))
|
|
957
|
+
return NOOP_RUNTIME;
|
|
958
|
+
if (!resolveTracesEndpoint(env))
|
|
959
|
+
return NOOP_RUNTIME;
|
|
960
|
+
const shutdownTimeoutMs = opts?.shutdownTimeoutMs ?? DEFAULT_SHUTDOWN_TIMEOUT_MS;
|
|
961
|
+
const exporter = createTraceExporter(resolveTracesProtocol(env));
|
|
962
|
+
const activeSpans = new ActiveSpanProcessor;
|
|
963
|
+
const provider = new import_sdk_trace_base.BasicTracerProvider({
|
|
964
|
+
resource: buildResource(env),
|
|
965
|
+
spanProcessors: [
|
|
966
|
+
activeSpans,
|
|
967
|
+
...opts?.spanProcessors ?? [new import_sdk_trace_base.BatchSpanProcessor(exporter)]
|
|
968
|
+
]
|
|
969
|
+
});
|
|
970
|
+
const contextManager = new import_context_async_hooks.AsyncLocalStorageContextManager;
|
|
971
|
+
contextManager.enable();
|
|
972
|
+
const ownsTracerGlobal = import_api.trace.setGlobalTracerProvider(provider);
|
|
973
|
+
if (!ownsTracerGlobal) {
|
|
974
|
+
log.warn("OTel tracer provider already registered by the host — Apex stays embedded and will not register its own");
|
|
975
|
+
contextManager.disable();
|
|
976
|
+
provider.shutdown().catch((error) => log.warn("Orphaned provider shutdown failed", { error: String(error) }));
|
|
977
|
+
return NOOP_RUNTIME;
|
|
978
|
+
}
|
|
979
|
+
const ownsContextGlobal = import_api.context.setGlobalContextManager(contextManager);
|
|
980
|
+
if (!ownsContextGlobal) {
|
|
981
|
+
log.warn("OTel context manager already registered by the host — Apex reuses it and will not disable it");
|
|
982
|
+
}
|
|
983
|
+
let shutdownPromise = null;
|
|
984
|
+
const runtime = {
|
|
985
|
+
async forceFlush() {
|
|
986
|
+
await provider.forceFlush();
|
|
987
|
+
},
|
|
988
|
+
shutdown() {
|
|
989
|
+
if (!shutdownPromise) {
|
|
990
|
+
const shutdownWork = async () => {
|
|
991
|
+
activeSpans.endAll();
|
|
992
|
+
endAllActiveRootSpans();
|
|
993
|
+
try {
|
|
994
|
+
await provider.forceFlush();
|
|
995
|
+
} finally {
|
|
996
|
+
activeSpans.endAll();
|
|
997
|
+
await provider.shutdown().catch((error) => {
|
|
998
|
+
log.warn("OTLP export/shutdown failed", { error: String(error) });
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
};
|
|
1002
|
+
shutdownPromise = withTimeout(shutdownWork(), shutdownTimeoutMs).then((result) => {
|
|
1003
|
+
contextManager.disable();
|
|
1004
|
+
if (ownsContextGlobal) {
|
|
1005
|
+
import_api.context.disable();
|
|
1006
|
+
}
|
|
1007
|
+
import_api.trace.disable();
|
|
1008
|
+
return result;
|
|
1009
|
+
}).finally(() => {
|
|
1010
|
+
activeRuntime = null;
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
return shutdownPromise;
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
activeRuntime = runtime;
|
|
1017
|
+
return runtime;
|
|
1018
|
+
}
|
|
1019
|
+
function installObservabilityExitHandlers(runtime, opts) {
|
|
1020
|
+
let exitPromise = null;
|
|
1021
|
+
let exitCode = 0;
|
|
1022
|
+
let fatalSeen = false;
|
|
1023
|
+
const reportError = (error, source) => {
|
|
1024
|
+
try {
|
|
1025
|
+
opts?.onError?.(error, source);
|
|
1026
|
+
} catch {}
|
|
1027
|
+
};
|
|
1028
|
+
const exitWith = (code, error, source) => {
|
|
1029
|
+
let pendingReport = null;
|
|
1030
|
+
if (error !== undefined && !fatalSeen) {
|
|
1031
|
+
fatalSeen = true;
|
|
1032
|
+
exitCode = 1;
|
|
1033
|
+
const fatalSource = source ?? "uncaughtException";
|
|
1034
|
+
pendingReport = () => reportError(error, fatalSource);
|
|
1035
|
+
} else if (!fatalSeen && exitCode === 0) {
|
|
1036
|
+
exitCode = code;
|
|
1037
|
+
}
|
|
1038
|
+
if (exitPromise) {
|
|
1039
|
+
pendingReport?.();
|
|
1040
|
+
return exitPromise;
|
|
1041
|
+
}
|
|
1042
|
+
try {
|
|
1043
|
+
opts?.cleanup?.(code);
|
|
1044
|
+
} catch (cleanupError) {
|
|
1045
|
+
if (!fatalSeen) {
|
|
1046
|
+
fatalSeen = true;
|
|
1047
|
+
exitCode = 1;
|
|
1048
|
+
pendingReport = () => reportError(cleanupError, "uncaughtException");
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
pendingReport?.();
|
|
1052
|
+
exitPromise = runtime.shutdown().catch(() => {}).then(() => process.exit(exitCode));
|
|
1053
|
+
return exitPromise;
|
|
1054
|
+
};
|
|
1055
|
+
process.on("SIGINT", () => void exitWith(130));
|
|
1056
|
+
process.on("SIGTERM", () => void exitWith(143));
|
|
1057
|
+
process.on("uncaughtException", (error) => void exitWith(1, error, "uncaughtException"));
|
|
1058
|
+
process.on("unhandledRejection", (reason) => void exitWith(1, reason, "unhandledRejection"));
|
|
1059
|
+
return exitWith;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
511
1062
|
// src/tui/utils/command-flags.ts
|
|
512
1063
|
import { readFileSync } from "node:fs";
|
|
513
1064
|
import { isAbsolute, resolve } from "node:path";
|
|
514
|
-
init_toolset();
|
|
515
1065
|
function combinePromptParts(threatModel, prompt) {
|
|
516
1066
|
const parts = [];
|
|
517
1067
|
if (threatModel)
|
|
@@ -537,7 +1087,8 @@ function resolveThreatModelPrompt(value) {
|
|
|
537
1087
|
|
|
538
1088
|
// src/cli.ts
|
|
539
1089
|
var args = process.argv.slice(2);
|
|
540
|
-
var
|
|
1090
|
+
var version2 = package_default2.version;
|
|
1091
|
+
import_dotenv.config();
|
|
541
1092
|
var OBFUSCATE_FLAGS = new Set(["--obfuscate", "--redact", "-O"]);
|
|
542
1093
|
var obfuscateRequested = args.some((a) => OBFUSCATE_FLAGS.has(a));
|
|
543
1094
|
if (obfuscateRequested) {
|
|
@@ -592,7 +1143,7 @@ function attachCliAgentStreamListeners(bus) {
|
|
|
592
1143
|
async function createInstrumentedBus(session) {
|
|
593
1144
|
const bus = new AgentEventBus;
|
|
594
1145
|
attachCliAgentStreamListeners(bus);
|
|
595
|
-
const { attachWandbToEventBus } = await import("./upload-
|
|
1146
|
+
const { attachWandbToEventBus } = await import("./upload-twg8pvy7.js");
|
|
596
1147
|
const wandbCleanup = await attachWandbToEventBus(session, bus).catch((e) => {
|
|
597
1148
|
console.warn("[wandb] Tracing disabled:", e.message);
|
|
598
1149
|
return null;
|
|
@@ -606,10 +1157,10 @@ async function resolveCliHeaders() {
|
|
|
606
1157
|
if (headerArgs.length === 0 && !headersFromArg && !noGlobal) {
|
|
607
1158
|
return;
|
|
608
1159
|
}
|
|
609
|
-
const { parseHeaderLine
|
|
1160
|
+
const { parseHeaderLine, parseHeadersFromFile, formatParseError } = await import("./parse-cqecqrc5.js");
|
|
610
1161
|
const merged = {};
|
|
611
1162
|
if (!noGlobal) {
|
|
612
|
-
const { config: appConfig } = await import("./index-
|
|
1163
|
+
const { config: appConfig } = await import("./index-rjmmakbh.js");
|
|
613
1164
|
const cfg = await appConfig.get();
|
|
614
1165
|
if (cfg.defaultHeaders) {
|
|
615
1166
|
Object.assign(merged, cfg.defaultHeaders);
|
|
@@ -620,7 +1171,7 @@ async function resolveCliHeaders() {
|
|
|
620
1171
|
if (!parsed.ok) {
|
|
621
1172
|
for (const err of parsed.error) {
|
|
622
1173
|
console.error(`--headers-from error:
|
|
623
|
-
${
|
|
1174
|
+
${formatParseError(err)}`);
|
|
624
1175
|
}
|
|
625
1176
|
process.exit(1);
|
|
626
1177
|
}
|
|
@@ -629,10 +1180,10 @@ ${formatParseError2(err)}`);
|
|
|
629
1180
|
}
|
|
630
1181
|
}
|
|
631
1182
|
for (const arg of headerArgs) {
|
|
632
|
-
const parsed =
|
|
1183
|
+
const parsed = parseHeaderLine(arg);
|
|
633
1184
|
if (!parsed.ok) {
|
|
634
1185
|
console.error(`--header "${arg}" rejected:
|
|
635
|
-
${
|
|
1186
|
+
${formatParseError(parsed.error)}`);
|
|
636
1187
|
process.exit(1);
|
|
637
1188
|
}
|
|
638
1189
|
merged[parsed.value.name] = parsed.value.value;
|
|
@@ -643,8 +1194,8 @@ async function resolveCliModel() {
|
|
|
643
1194
|
const explicit = getArg("--model");
|
|
644
1195
|
if (explicit)
|
|
645
1196
|
return explicit;
|
|
646
|
-
const { config: appConfig } = await import("./index-
|
|
647
|
-
const { getDefaultModelForConfig } = await import("./utils-
|
|
1197
|
+
const { config: appConfig } = await import("./index-rjmmakbh.js");
|
|
1198
|
+
const { getDefaultModelForConfig } = await import("./utils-cnv9jj0h.js");
|
|
648
1199
|
const pensarConfig = await appConfig.get();
|
|
649
1200
|
const defaultModel = getDefaultModelForConfig(pensarConfig);
|
|
650
1201
|
if (!defaultModel) {
|
|
@@ -731,11 +1282,9 @@ Global options:
|
|
|
731
1282
|
`);
|
|
732
1283
|
}
|
|
733
1284
|
async function runPentest() {
|
|
734
|
-
const {
|
|
735
|
-
|
|
736
|
-
const {
|
|
737
|
-
const { sessions: sessions2 } = await import("./index-sf16jm0m.js");
|
|
738
|
-
const { config: appConfig } = await import("./index-y5w6n3tb.js");
|
|
1285
|
+
const { runPentestAgent } = await import("./blackboxPentest-bf7b9m36.js");
|
|
1286
|
+
const { sessions } = await import("./index-3dpcjj6e.js");
|
|
1287
|
+
const { config: appConfig } = await import("./index-rjmmakbh.js");
|
|
739
1288
|
const target = getArgRequired("--target");
|
|
740
1289
|
const cwd = getArg("--cwd");
|
|
741
1290
|
const mode = getArg("--mode");
|
|
@@ -770,7 +1319,7 @@ Task-driven: enabled` : ""}${fastStrike ? `
|
|
|
770
1319
|
Fast strike: enabled` : ""}${headers ? `
|
|
771
1320
|
Headers: ${Object.keys(headers).length} configured` : ""}
|
|
772
1321
|
`);
|
|
773
|
-
const session = await
|
|
1322
|
+
const session = await sessions.create({
|
|
774
1323
|
name: cwd ? "Whitebox Pentest" : "Blackbox Pentest",
|
|
775
1324
|
targets: [target],
|
|
776
1325
|
config: {
|
|
@@ -806,14 +1355,11 @@ Report: ${reportPath}` : ""}`);
|
|
|
806
1355
|
} finally {
|
|
807
1356
|
await wandbCleanup();
|
|
808
1357
|
}
|
|
809
|
-
process.exit(0);
|
|
810
1358
|
}
|
|
811
1359
|
async function runTargetedPentest() {
|
|
812
|
-
const {
|
|
813
|
-
|
|
814
|
-
const {
|
|
815
|
-
const { sessions: sessions2 } = await import("./index-sf16jm0m.js");
|
|
816
|
-
const { config: appConfig } = await import("./index-y5w6n3tb.js");
|
|
1360
|
+
const { runTargetedPentestAgent } = await import("./targetedPentest-34zhke7a.js");
|
|
1361
|
+
const { sessions } = await import("./index-3dpcjj6e.js");
|
|
1362
|
+
const { config: appConfig } = await import("./index-rjmmakbh.js");
|
|
817
1363
|
const target = getArgRequired("--target");
|
|
818
1364
|
const objectives = getAllArgs("--objective");
|
|
819
1365
|
const pensarConfig = await appConfig.get();
|
|
@@ -834,7 +1380,7 @@ Objectives:
|
|
|
834
1380
|
${objectivesList}
|
|
835
1381
|
`);
|
|
836
1382
|
const headers = await resolveCliHeaders();
|
|
837
|
-
const session = await
|
|
1383
|
+
const session = await sessions.create({
|
|
838
1384
|
name: "Targeted Pentest",
|
|
839
1385
|
targets: [target],
|
|
840
1386
|
...headers !== undefined ? { config: { headers } } : {}
|
|
@@ -860,18 +1406,15 @@ POCs: ${pocsPath}`);
|
|
|
860
1406
|
} finally {
|
|
861
1407
|
await wandbCleanup();
|
|
862
1408
|
}
|
|
863
|
-
process.exit(0);
|
|
864
1409
|
}
|
|
865
1410
|
async function runThreatModel() {
|
|
866
|
-
const {
|
|
867
|
-
config();
|
|
868
|
-
const
|
|
869
|
-
const { config: appConfig } = await import("./index-y5w6n3tb.js");
|
|
870
|
-
const path2 = await import("path");
|
|
1411
|
+
const { runThreatModelWorkflow } = await import("./threatModel-r96hed1d.js");
|
|
1412
|
+
const { config: appConfig } = await import("./index-rjmmakbh.js");
|
|
1413
|
+
const path = await import("path");
|
|
871
1414
|
const pensarConfig = await appConfig.get();
|
|
872
1415
|
const model = await resolveCliModel();
|
|
873
1416
|
const outputArg = getArg("--output") ?? getArg("-o") ?? "threat-model.md";
|
|
874
|
-
const resolvedPath =
|
|
1417
|
+
const resolvedPath = path.isAbsolute(outputArg) ? outputArg : path.resolve(process.cwd(), outputArg);
|
|
875
1418
|
const sep = "=".repeat(60);
|
|
876
1419
|
console.log(`${sep}
|
|
877
1420
|
THREAT MODEL GENERATION
|
|
@@ -900,16 +1443,14 @@ ${sep}
|
|
|
900
1443
|
Threat model written to: ${resolvedPath}`);
|
|
901
1444
|
}
|
|
902
1445
|
async function runOperator() {
|
|
903
|
-
const {
|
|
904
|
-
|
|
905
|
-
const {
|
|
906
|
-
const {
|
|
907
|
-
const { ALL_TOOL_NAMES, SKILL_TOOL_NAMES } = await import("./index-hqjdg6fg.js");
|
|
908
|
-
const { config: appConfig } = await import("./index-y5w6n3tb.js");
|
|
1446
|
+
const { runOffensiveSecurityAgent } = await import("./offesecAgent-jwnbnsqm.js");
|
|
1447
|
+
const { sessions, normalizeMessages, getResumeMessages } = await import("./index-3dpcjj6e.js");
|
|
1448
|
+
const { ALL_TOOL_NAMES, SKILL_TOOL_NAMES } = await import("./index-k1mb1edx.js");
|
|
1449
|
+
const { config: appConfig } = await import("./index-rjmmakbh.js");
|
|
909
1450
|
const { createInterface } = await import("readline");
|
|
910
|
-
const { readFileSync
|
|
911
|
-
const
|
|
912
|
-
const { stepCountIs } = await import("./index-
|
|
1451
|
+
const { readFileSync, existsSync } = await import("fs");
|
|
1452
|
+
const path = await import("path");
|
|
1453
|
+
const { stepCountIs } = await import("./index-a1bg29j1.js");
|
|
913
1454
|
const promptRaw = getArg("-p") ?? getArg("--prompt");
|
|
914
1455
|
if (!promptRaw) {
|
|
915
1456
|
console.error("Error: -p <prompt> is required");
|
|
@@ -930,7 +1471,7 @@ Target: ${target}` : ""}
|
|
|
930
1471
|
${sep}
|
|
931
1472
|
`);
|
|
932
1473
|
const headers = await resolveCliHeaders();
|
|
933
|
-
const session = await
|
|
1474
|
+
const session = await sessions.create({
|
|
934
1475
|
name: "Operator Session",
|
|
935
1476
|
targets: target ? [target] : [],
|
|
936
1477
|
config: {
|
|
@@ -951,13 +1492,13 @@ ${sep}
|
|
|
951
1492
|
input: process.stdin,
|
|
952
1493
|
output: process.stdout
|
|
953
1494
|
});
|
|
954
|
-
const askFollowUp = () => new Promise((
|
|
1495
|
+
const askFollowUp = () => new Promise((resolve) => {
|
|
955
1496
|
process.stdout.write(`
|
|
956
1497
|
${sep}
|
|
957
1498
|
`);
|
|
958
1499
|
rl.question("follow-up (empty to exit): ", (answer) => {
|
|
959
1500
|
const trimmed = answer.trim();
|
|
960
|
-
|
|
1501
|
+
resolve(trimmed || null);
|
|
961
1502
|
});
|
|
962
1503
|
});
|
|
963
1504
|
try {
|
|
@@ -974,9 +1515,9 @@ ${sep}
|
|
|
974
1515
|
session,
|
|
975
1516
|
messages
|
|
976
1517
|
});
|
|
977
|
-
const messagesPath =
|
|
1518
|
+
const messagesPath = path.join(session.rootPath, "messages.json");
|
|
978
1519
|
if (existsSync(messagesPath)) {
|
|
979
|
-
const raw = JSON.parse(
|
|
1520
|
+
const raw = JSON.parse(readFileSync(messagesPath, "utf-8"));
|
|
980
1521
|
const allMessages = Array.isArray(raw) ? raw : [];
|
|
981
1522
|
messages = normalizeMessages(getResumeMessages(allMessages));
|
|
982
1523
|
}
|
|
@@ -997,68 +1538,91 @@ ${sep}
|
|
|
997
1538
|
Session: ${session.rootPath}`);
|
|
998
1539
|
}
|
|
999
1540
|
async function runUpgrade2() {
|
|
1000
|
-
const currentVersion =
|
|
1541
|
+
const currentVersion = getCurrentVersion2();
|
|
1001
1542
|
console.log(`Current version: v${currentVersion}
|
|
1002
1543
|
Checking for updates...`);
|
|
1003
1544
|
const result = await upgrade({ interactive: true });
|
|
1004
1545
|
console.log(`
|
|
1005
1546
|
${result.message}`);
|
|
1006
|
-
process.
|
|
1547
|
+
process.exitCode = result.success ? 0 : 1;
|
|
1007
1548
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
} else if (command === "
|
|
1019
|
-
|
|
1020
|
-
} else if (command === "
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
} else if (command === "
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
} else if (command === "
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
} else if (
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1549
|
+
var observabilityRuntime = startObservabilityRuntime();
|
|
1550
|
+
var exitAfterObservabilityShutdown = args.length !== 0 ? installObservabilityExitHandlers(observabilityRuntime, {
|
|
1551
|
+
onError: (error) => {
|
|
1552
|
+
console.error("Uncaught exception:", error);
|
|
1553
|
+
}
|
|
1554
|
+
}) : null;
|
|
1555
|
+
setCurrentCommand(command);
|
|
1556
|
+
try {
|
|
1557
|
+
if (hasFlag("-p") || command === "--prompt") {
|
|
1558
|
+
await runOperator();
|
|
1559
|
+
} else if (command === "version" || command === "--version" || command === "-v") {
|
|
1560
|
+
console.log(`v${version2}`);
|
|
1561
|
+
} else if (command === "help" || command === "--help" || command === "-h") {
|
|
1562
|
+
showHelp();
|
|
1563
|
+
} else if (command === "upgrade" || command === "update") {
|
|
1564
|
+
await runUpgrade2();
|
|
1565
|
+
} else if (command === "pentest") {
|
|
1566
|
+
await runPentest();
|
|
1567
|
+
} else if (command === "targeted-pentest") {
|
|
1568
|
+
await runTargetedPentest();
|
|
1569
|
+
} else if (command === "login" || command === "auth") {
|
|
1570
|
+
process.argv = [process.argv[0], process.argv[1], ...args.slice(1)];
|
|
1571
|
+
await import("./auth-wf1r533f.js");
|
|
1572
|
+
} else if (command === "uninstall") {
|
|
1573
|
+
process.argv = [process.argv[0], process.argv[1], ...args.slice(1)];
|
|
1574
|
+
await import("./uninstall-qdzsynrt.js");
|
|
1575
|
+
} else if (command === "apps") {
|
|
1576
|
+
process.argv = [process.argv[0], process.argv[1], ...args.slice(1)];
|
|
1577
|
+
await import("./apps-qf8jww9t.js");
|
|
1578
|
+
} else if (command === "pentests") {
|
|
1579
|
+
process.argv = [process.argv[0], process.argv[1], ...args.slice(1)];
|
|
1580
|
+
await import("./pentests-6pp1j1w5.js");
|
|
1581
|
+
} else if (command === "targets") {
|
|
1582
|
+
process.argv = [process.argv[0], process.argv[1], ...args.slice(1)];
|
|
1583
|
+
await import("./targets-yvh0d0fr.js");
|
|
1584
|
+
} else if (command === "issues") {
|
|
1585
|
+
process.argv = [process.argv[0], process.argv[1], ...args.slice(1)];
|
|
1586
|
+
await import("./issues-vgfdw93j.js");
|
|
1587
|
+
} else if (command === "fixes") {
|
|
1588
|
+
process.argv = [process.argv[0], process.argv[1], ...args.slice(1)];
|
|
1589
|
+
await import("./fixes-6kxes4g7.js");
|
|
1590
|
+
} else if (command === "logs") {
|
|
1591
|
+
process.argv = [process.argv[0], process.argv[1], ...args.slice(1)];
|
|
1592
|
+
await import("./logs-czxxx0n0.js");
|
|
1593
|
+
} else if (command === "config") {
|
|
1594
|
+
process.argv = [process.argv[0], process.argv[1], ...args.slice(1)];
|
|
1595
|
+
await import("./config-g93k0986.js");
|
|
1596
|
+
} else if (command === "threat-model") {
|
|
1597
|
+
await runThreatModel();
|
|
1598
|
+
} else if (command === "doctor") {
|
|
1599
|
+
const { runDoctor } = await import("./doctor-4fcx7g0h.js");
|
|
1600
|
+
await runDoctor();
|
|
1601
|
+
} else if (args.length === 0) {
|
|
1602
|
+
if (process.env.PENSAR_NO_TUI === "1") {
|
|
1603
|
+
console.error("TUI mode requires Bun. Install Bun (https://bun.sh) or use a standalone binary release for interactive mode.");
|
|
1604
|
+
console.error("All other commands work with Node \u2014 run 'pensar --help'.");
|
|
1605
|
+
await observabilityRuntime.shutdown().catch(() => {});
|
|
1606
|
+
process.exitCode = 1;
|
|
1607
|
+
} else {
|
|
1608
|
+
await import("./index-r8554acn.js");
|
|
1609
|
+
}
|
|
1610
|
+
} else {
|
|
1611
|
+
console.error(`Error: Unknown command '${command}'`);
|
|
1612
|
+
console.error();
|
|
1613
|
+
console.error("Run 'pensar --help' for usage information");
|
|
1614
|
+
process.exitCode = 1;
|
|
1615
|
+
}
|
|
1616
|
+
} catch (error) {
|
|
1617
|
+
if (exitAfterObservabilityShutdown !== null) {
|
|
1618
|
+
await exitAfterObservabilityShutdown(1, error, "uncaughtException");
|
|
1619
|
+
}
|
|
1620
|
+
throw error;
|
|
1621
|
+
} finally {
|
|
1622
|
+
if (exitAfterObservabilityShutdown !== null) {
|
|
1623
|
+
const shutdownResult = await observabilityRuntime.shutdown().catch(() => "completed");
|
|
1624
|
+
if (shutdownResult === "timed-out" || command === "pentest" || command === "targeted-pentest") {
|
|
1625
|
+
await exitAfterObservabilityShutdown(typeof process.exitCode === "number" ? process.exitCode : 0);
|
|
1626
|
+
}
|
|
1057
1627
|
}
|
|
1058
|
-
await import("./index-6d22pyxt.js");
|
|
1059
|
-
} else {
|
|
1060
|
-
console.error(`Error: Unknown command '${command}'`);
|
|
1061
|
-
console.error();
|
|
1062
|
-
console.error("Run 'pensar --help' for usage information");
|
|
1063
|
-
process.exit(1);
|
|
1064
1628
|
}
|