@pensar/apex 0.0.114 → 0.0.115-canary.3ff3bacc

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.
Files changed (46) hide show
  1. package/README.md +7 -55
  2. package/build/agent-axwrsbg1.js +16 -0
  3. package/build/{agent-jr0kf32x.js → agent-nh2wxyqw.js} +70 -57
  4. package/build/{auth-g7qfrmqn.js → auth-fddwgn5c.js} +4 -4
  5. package/build/{authentication-h92927qz.js → authentication-e8j8jz8e.js} +26 -20
  6. package/build/blackboxAgent-xfp6r8rj.js +17 -0
  7. package/build/{blackboxPentest-34sfsskq.js → blackboxPentest-z98fssj0.js} +15 -14
  8. package/build/cli-1b6mc26y.js +396 -0
  9. package/build/{cli-23qtjsce.js → cli-31djtdf4.js} +1 -1
  10. package/build/{cli-phajnhzs.js → cli-3ktgmce4.js} +1324 -529
  11. package/build/{cli-0tpx8khk.js → cli-5gh0m3xb.js} +57 -57
  12. package/build/cli-6q8a31h6.js +7632 -0
  13. package/build/cli-7tveyxgw.js +1215 -0
  14. package/build/{cli-zz9wwkqh.js → cli-8tasv0wm.js} +1 -1
  15. package/build/{cli-0r7qwt2h.js → cli-afjampe9.js} +93 -34
  16. package/build/{cli-tj25jvz6.js → cli-ezzp9f2r.js} +11 -1
  17. package/build/{cli-9hp2khjx.js → cli-j61f3t4k.js} +18 -8
  18. package/build/{cli-27bnjky6.js → cli-my5se8ds.js} +1 -1
  19. package/build/{cli-s1dd4n9x.js → cli-qeg5kcee.js} +6 -2
  20. package/build/{cli-vnydvy0r.js → cli-t02nbn54.js} +14 -14
  21. package/build/{cli-mx8pfb29.js → cli-vex0gtmg.js} +54 -28
  22. package/build/{cli-49cd9yfk.js → cli-wszshs5e.js} +1 -1
  23. package/build/{cli-xj88naps.js → cli-xksme06v.js} +1 -1
  24. package/build/{cli-z1s5njxn.js → cli-y0w4p2fn.js} +123 -15
  25. package/build/cli.js +164 -31
  26. package/build/{fixes-d3mb7zr3.js → fixes-wyffh2fp.js} +4 -4
  27. package/build/{index-gm4427rc.js → index-azhbn546.js} +2 -2
  28. package/build/{index-zyrn6ava.js → index-frw96hcs.js} +4674 -6081
  29. package/build/{index-rd11fk7h.js → index-h2hj2hj9.js} +14 -14
  30. package/build/{index-mefzr77w.js → index-vghwdr79.js} +14 -11
  31. package/build/{issues-gsfpfmwx.js → issues-5fmj09ta.js} +4 -4
  32. package/build/{logs-mgbbrr4b.js → logs-y7eng9gc.js} +4 -4
  33. package/build/{multipart-parser-r38qdp5v.js → multipart-parser-6zd16497.js} +2 -2
  34. package/build/pentest-r0j4aw5m.js +26 -0
  35. package/build/{pentests-ey20zzez.js → pentests-c4a4397g.js} +4 -4
  36. package/build/{projects-1z5x1bxj.js → projects-443xg0q3.js} +4 -4
  37. package/build/targetedPentest-q7v1twcc.js +33 -0
  38. package/build/threatModel-9hjpykge.js +59 -0
  39. package/build/{uninstall-b26ez5zf.js → uninstall-eamyc5aj.js} +1 -1
  40. package/build/{utils-9fhmzzzh.js → utils-7x4v0asf.js} +1 -1
  41. package/package.json +6 -2
  42. package/build/agent-q0mhy72n.js +0 -16
  43. package/build/blackboxAgent-bgqz7n74.js +0 -17
  44. package/build/cli-xtccf5qk.js +0 -1498
  45. package/build/pentest-1cntf5yv.js +0 -25
  46. package/build/targetedPentest-yatr7brn.js +0 -32
@@ -0,0 +1,396 @@
1
+ import {
2
+ CweEntrySchema
3
+ } from "./cli-3ktgmce4.js";
4
+ import {
5
+ exports_external,
6
+ init_zod
7
+ } from "./cli-y0w4p2fn.js";
8
+
9
+ // src/core/report/schemas.ts
10
+ init_zod();
11
+ var PentestReportFindingSchema = exports_external.object({
12
+ title: exports_external.string(),
13
+ severity: exports_external.enum(["CRITICAL", "HIGH", "MEDIUM", "LOW"]),
14
+ description: exports_external.string(),
15
+ impact: exports_external.string(),
16
+ evidence: exports_external.string(),
17
+ endpoint: exports_external.string(),
18
+ pocPath: exports_external.string(),
19
+ remediation: exports_external.string(),
20
+ references: exports_external.string().optional(),
21
+ cwes: exports_external.array(CweEntrySchema).optional()
22
+ });
23
+ var PentestReportSchema = exports_external.object({
24
+ version: exports_external.string().regex(/^1\.\d+$/),
25
+ metadata: exports_external.object({
26
+ target: exports_external.string(),
27
+ model: exports_external.string(),
28
+ timestamp: exports_external.string(),
29
+ sessionId: exports_external.string(),
30
+ mode: exports_external.enum(["blackbox", "whitebox", "targeted"])
31
+ }),
32
+ summary: exports_external.object({
33
+ totalFindings: exports_external.number(),
34
+ bySeverity: exports_external.object({
35
+ CRITICAL: exports_external.number(),
36
+ HIGH: exports_external.number(),
37
+ MEDIUM: exports_external.number(),
38
+ LOW: exports_external.number()
39
+ })
40
+ }),
41
+ findings: exports_external.array(PentestReportFindingSchema)
42
+ });
43
+ var REPORT_VERSION = "1.0";
44
+
45
+ // src/core/report/builder.ts
46
+ var SEVERITY_ORDER = ["CRITICAL", "HIGH", "MEDIUM", "LOW"];
47
+ function buildPentestReport(findings, context) {
48
+ const sorted = [...findings].sort((a, b) => SEVERITY_ORDER.indexOf(a.severity) - SEVERITY_ORDER.indexOf(b.severity));
49
+ const bySeverity = { CRITICAL: 0, HIGH: 0, MEDIUM: 0, LOW: 0 };
50
+ for (const f of findings) {
51
+ bySeverity[f.severity]++;
52
+ }
53
+ return {
54
+ version: REPORT_VERSION,
55
+ metadata: {
56
+ target: context.target,
57
+ model: context.model,
58
+ timestamp: new Date().toISOString(),
59
+ sessionId: context.sessionId,
60
+ mode: context.mode
61
+ },
62
+ summary: {
63
+ totalFindings: findings.length,
64
+ bySeverity
65
+ },
66
+ findings: sorted.map((f) => ({
67
+ title: f.title,
68
+ severity: f.severity,
69
+ description: f.description,
70
+ impact: f.impact,
71
+ evidence: f.evidence,
72
+ endpoint: f.endpoint,
73
+ pocPath: f.pocPath,
74
+ remediation: f.remediation,
75
+ references: f.references
76
+ }))
77
+ };
78
+ }
79
+
80
+ // src/core/report/renderers/markdown.ts
81
+ function renderMarkdown(report) {
82
+ const { metadata, findings, summary } = report;
83
+ const header = [
84
+ `# Pentest Report — ${metadata.target}`,
85
+ "",
86
+ `**Date:** ${metadata.timestamp} `,
87
+ `**Session:** ${metadata.sessionId} `,
88
+ `**Model:** ${metadata.model} `,
89
+ `**Mode:** ${metadata.mode}`,
90
+ "",
91
+ `**Findings:** ${summary.totalFindings}`,
92
+ ""
93
+ ];
94
+ if (findings.length === 0) {
95
+ return [
96
+ ...header,
97
+ "No findings were identified during this assessment.",
98
+ ""
99
+ ].join(`
100
+ `);
101
+ }
102
+ const body = findings.map((finding) => renderFinding(finding, metadata)).join(`
103
+ `);
104
+ return [...header, body].join(`
105
+ `);
106
+ }
107
+ function renderFinding(finding, metadata) {
108
+ const lines = [
109
+ `# ${finding.title}`,
110
+ "",
111
+ `**Severity:** ${finding.severity} `,
112
+ `**Target:** ${metadata.target} `,
113
+ `**Endpoint:** ${finding.endpoint} `,
114
+ `**Date:** ${metadata.timestamp} `,
115
+ `**Session:** ${metadata.sessionId}`,
116
+ "",
117
+ "## Description",
118
+ "",
119
+ finding.description,
120
+ "",
121
+ "## Impact",
122
+ "",
123
+ finding.impact,
124
+ "",
125
+ "## Evidence",
126
+ "",
127
+ "```",
128
+ finding.evidence,
129
+ "```",
130
+ "",
131
+ ...finding.cwes?.length ? [
132
+ "## CWE Classification",
133
+ "",
134
+ ...finding.cwes.map((cwe) => `- **${cwe.id}** — ${cwe.reasoning}`),
135
+ ""
136
+ ] : [],
137
+ "## POC",
138
+ "",
139
+ `Path: \`${finding.pocPath}\``,
140
+ "",
141
+ "## Remediation",
142
+ "",
143
+ finding.remediation,
144
+ ...finding.references ? ["", `## References`, "", finding.references] : [],
145
+ "",
146
+ "---",
147
+ "",
148
+ "*This finding was automatically documented by the Pensar penetration testing agent.*",
149
+ ""
150
+ ];
151
+ return lines.join(`
152
+ `);
153
+ }
154
+
155
+ // src/core/report/renderers/json.ts
156
+ function renderJson(report) {
157
+ return JSON.stringify(report, null, 2);
158
+ }
159
+
160
+ // src/core/report/index.ts
161
+ var REPORT_FILENAME_MD = "pentest-report.md";
162
+ var REPORT_FILENAME_JSON = "pentest-report.json";
163
+
164
+ // src/core/session/persistence.ts
165
+ import {
166
+ existsSync,
167
+ mkdirSync,
168
+ writeFileSync,
169
+ readFileSync,
170
+ readdirSync
171
+ } from "fs";
172
+ import { join } from "path";
173
+ var SUBAGENTS_DIR = "subagents";
174
+ var MANIFEST_FILE = "agent-manifest.json";
175
+ function loadSubagentMessages(session, agentName) {
176
+ const filePath = join(session.rootPath, SUBAGENTS_DIR, `${agentName}.json`);
177
+ if (!existsSync(filePath))
178
+ return [];
179
+ try {
180
+ const data = JSON.parse(readFileSync(filePath, "utf-8"));
181
+ return data.messages;
182
+ } catch {
183
+ return [];
184
+ }
185
+ }
186
+ function saveSubagentData(session, data) {
187
+ const subagentsDir = join(session.rootPath, SUBAGENTS_DIR);
188
+ mkdirSync(subagentsDir, { recursive: true });
189
+ let toolCallCount = 0;
190
+ let stepCount = 0;
191
+ for (const msg of data.messages) {
192
+ if (msg.role === "assistant") {
193
+ stepCount++;
194
+ if (Array.isArray(msg.content)) {
195
+ for (const part of msg.content) {
196
+ if (part.type === "tool-call")
197
+ toolCallCount++;
198
+ }
199
+ }
200
+ }
201
+ }
202
+ const savedData = {
203
+ agentName: data.agentName,
204
+ timestamp: new Date().toISOString(),
205
+ target: data.target,
206
+ objective: data.objective,
207
+ vulnerabilityClass: data.vulnerabilityClass,
208
+ toolCallCount,
209
+ stepCount,
210
+ findingsCount: data.findingsCount ?? 0,
211
+ status: data.status,
212
+ error: data.error,
213
+ messages: data.messages
214
+ };
215
+ writeFileSync(join(subagentsDir, `${data.agentName}.json`), JSON.stringify(savedData, null, 2));
216
+ }
217
+ function writeAgentManifest(session, entries) {
218
+ const manifestPath = join(session.rootPath, MANIFEST_FILE);
219
+ writeFileSync(manifestPath, JSON.stringify(entries, null, 2));
220
+ }
221
+ function readAgentManifest(session) {
222
+ const manifestPath = join(session.rootPath, MANIFEST_FILE);
223
+ if (!existsSync(manifestPath))
224
+ return [];
225
+ try {
226
+ return JSON.parse(readFileSync(manifestPath, "utf-8"));
227
+ } catch {
228
+ return [];
229
+ }
230
+ }
231
+ function buildManifestEntries(targets) {
232
+ return targets.map((t, i) => ({
233
+ id: `pentest-agent-${i + 1}`,
234
+ name: `Pentest Agent ${i + 1}`,
235
+ target: t.target,
236
+ vulnerabilityClass: t.objectives[0] || "general",
237
+ objective: t.objectives.join("; "),
238
+ status: "running",
239
+ spawnedAt: new Date().toISOString()
240
+ }));
241
+ }
242
+ function finalizeManifest(session, entries, results) {
243
+ const finalManifest = entries.map((entry, i) => {
244
+ if (entry.status === "completed")
245
+ return entry;
246
+ return {
247
+ ...entry,
248
+ status: results[i] != null ? "completed" : "failed",
249
+ completedAt: new Date().toISOString()
250
+ };
251
+ });
252
+ writeAgentManifest(session, finalManifest);
253
+ }
254
+ function updateManifestEntryStatus(session, agentId, status) {
255
+ const manifest = readAgentManifest(session);
256
+ const updated = manifest.map((e) => e.id === agentId ? { ...e, status, completedAt: new Date().toISOString() } : e);
257
+ writeAgentManifest(session, updated);
258
+ }
259
+ function getCompletedAgentIds(session) {
260
+ const manifest = readAgentManifest(session);
261
+ return new Set(manifest.filter((e) => e.id.startsWith("pentest-agent-") && e.status === "completed").map((e) => e.id));
262
+ }
263
+ function convertMessagesToUI(messages, baseTime) {
264
+ const uiMessages = [];
265
+ let messageIndex = 0;
266
+ const toolResults = new Map;
267
+ for (const msg of messages) {
268
+ if (Array.isArray(msg.content)) {
269
+ for (const part of msg.content) {
270
+ if (part.type === "tool-result" && part.toolCallId) {
271
+ toolResults.set(part.toolCallId, part.output);
272
+ }
273
+ }
274
+ }
275
+ }
276
+ for (const msg of messages) {
277
+ const createdAt = new Date(baseTime.getTime() + messageIndex * 1000);
278
+ messageIndex++;
279
+ if (typeof msg.content === "string") {
280
+ uiMessages.push({
281
+ role: msg.role,
282
+ content: msg.content,
283
+ createdAt
284
+ });
285
+ } else if (Array.isArray(msg.content)) {
286
+ for (const part of msg.content) {
287
+ if (part.type === "text" && part.text) {
288
+ uiMessages.push({
289
+ role: "assistant",
290
+ content: part.text,
291
+ createdAt
292
+ });
293
+ } else if (part.type === "tool-call") {
294
+ const input = part.input;
295
+ const toolDescription = typeof input?.toolCallDescription === "string" ? input.toolCallDescription : part.toolName || "tool";
296
+ const result = part.toolCallId ? toolResults.get(part.toolCallId) : undefined;
297
+ const resultText = typeof result === "string" ? result : result != null && typeof result === "object" && ("value" in result) && typeof result.value === "string" ? result.value : undefined;
298
+ const cancelled = typeof resultText === "string" && resultText.toLowerCase().includes("cancelled");
299
+ uiMessages.push({
300
+ role: "tool",
301
+ content: toolDescription,
302
+ createdAt,
303
+ toolCallId: part.toolCallId,
304
+ toolName: part.toolName,
305
+ args: input,
306
+ result,
307
+ status: cancelled ? "error" : "completed"
308
+ });
309
+ }
310
+ }
311
+ }
312
+ }
313
+ return uiMessages;
314
+ }
315
+ function convertModelMessagesToUI(messages) {
316
+ return convertMessagesToUI(messages, new Date);
317
+ }
318
+
319
+ // src/core/session/execution-metrics.ts
320
+ import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
321
+ import { join as join2 } from "path";
322
+ var EXECUTION_METRICS_FILENAME = "execution-metrics.json";
323
+ function toNonNegativeInteger(value) {
324
+ const n = Number(value);
325
+ return Number.isFinite(n) && n > 0 ? Math.floor(n) : 0;
326
+ }
327
+ function normalizeTokenUsage(value) {
328
+ const inputTokens = toNonNegativeInteger(value?.inputTokens);
329
+ const outputTokens = toNonNegativeInteger(value?.outputTokens);
330
+ const derivedTotal = inputTokens + outputTokens;
331
+ const explicitTotal = toNonNegativeInteger(value?.totalTokens);
332
+ return {
333
+ inputTokens,
334
+ outputTokens,
335
+ totalTokens: explicitTotal > 0 ? explicitTotal : derivedTotal
336
+ };
337
+ }
338
+ function metricsPath(sessionRootPath) {
339
+ return join2(sessionRootPath, EXECUTION_METRICS_FILENAME);
340
+ }
341
+ function sessionJsonPath(sessionRootPath) {
342
+ return join2(sessionRootPath, "session.json");
343
+ }
344
+ function readExecutionMetrics(sessionRootPath) {
345
+ const path = metricsPath(sessionRootPath);
346
+ if (!existsSync2(path))
347
+ return null;
348
+ try {
349
+ const parsed = JSON.parse(readFileSync2(path, "utf-8"));
350
+ return {
351
+ tokenUsage: normalizeTokenUsage(parsed.tokenUsage),
352
+ runtime: typeof parsed.runtime === "string" ? parsed.runtime : undefined,
353
+ elapsedSeconds: toNonNegativeInteger(parsed.elapsedSeconds) || undefined,
354
+ updatedAt: typeof parsed.updatedAt === "string" ? parsed.updatedAt : new Date().toISOString()
355
+ };
356
+ } catch {
357
+ return null;
358
+ }
359
+ }
360
+ function writeSessionJsonTokenTotals(sessionRootPath, tokenUsage) {
361
+ const path = sessionJsonPath(sessionRootPath);
362
+ if (!existsSync2(path))
363
+ return;
364
+ try {
365
+ const parsed = JSON.parse(readFileSync2(path, "utf-8"));
366
+ parsed.tokensIn = tokenUsage.inputTokens;
367
+ parsed.tokensOut = tokenUsage.outputTokens;
368
+ writeFileSync2(path, JSON.stringify(parsed, null, 2));
369
+ } catch {}
370
+ }
371
+ function writeExecutionMetrics(input) {
372
+ const existing = readExecutionMetrics(input.sessionRootPath);
373
+ const nextTokenUsage = input.tokenUsage ? normalizeTokenUsage(input.tokenUsage) : existing?.tokenUsage ?? {
374
+ inputTokens: 0,
375
+ outputTokens: 0,
376
+ totalTokens: 0
377
+ };
378
+ const next = {
379
+ tokenUsage: nextTokenUsage,
380
+ runtime: input.runtime ?? existing?.runtime,
381
+ elapsedSeconds: input.elapsedSeconds ?? existing?.elapsedSeconds,
382
+ updatedAt: new Date().toISOString()
383
+ };
384
+ writeFileSync2(metricsPath(input.sessionRootPath), JSON.stringify(next, null, 2), "utf-8");
385
+ writeSessionJsonTokenTotals(input.sessionRootPath, next.tokenUsage);
386
+ return next;
387
+ }
388
+ function formatDurationHmsFromMs(durationMs) {
389
+ const totalSeconds = Math.max(0, Math.floor(durationMs / 1000));
390
+ const hours = Math.floor(totalSeconds / 3600);
391
+ const minutes = Math.floor(totalSeconds % 3600 / 60);
392
+ const seconds = totalSeconds % 60;
393
+ return `${hours}h${minutes}m${seconds}s`;
394
+ }
395
+
396
+ export { buildPentestReport, renderMarkdown, renderJson, REPORT_FILENAME_MD, REPORT_FILENAME_JSON, loadSubagentMessages, saveSubagentData, writeAgentManifest, readAgentManifest, buildManifestEntries, finalizeManifest, updateManifestEntryStatus, getCompletedAgentIds, convertModelMessagesToUI, readExecutionMetrics, writeExecutionMetrics, formatDurationHmsFromMs };
@@ -2,7 +2,7 @@ import {
2
2
  config,
3
3
  ensureValidToken,
4
4
  getPensarApiUrl
5
- } from "./cli-27bnjky6.js";
5
+ } from "./cli-my5se8ds.js";
6
6
 
7
7
  // src/core/api/issues.ts
8
8
  async function getAuthHeaders() {