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