@pensar/apex 0.0.29 → 0.0.31-canary.0
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/bin/pensar.js +11 -14
- package/build/benchmark.js +293 -159
- package/build/index.js +311 -275
- package/build/pentest.js +293 -159
- package/build/quicktest.js +240 -4
- package/build/swarm.js +240 -4
- package/package.json +8 -1
package/build/quicktest.js
CHANGED
|
@@ -39942,7 +39942,8 @@ function streamResponse(opts) {
|
|
|
39942
39942
|
abortSignal,
|
|
39943
39943
|
activeTools,
|
|
39944
39944
|
silent,
|
|
39945
|
-
authConfig
|
|
39945
|
+
authConfig,
|
|
39946
|
+
onFinish
|
|
39946
39947
|
} = opts;
|
|
39947
39948
|
const messagesContainer = { current: messages || [] };
|
|
39948
39949
|
const providerModel = getProviderModel(model, authConfig);
|
|
@@ -39997,7 +39998,8 @@ function streamResponse(opts) {
|
|
|
39997
39998
|
}
|
|
39998
39999
|
throw repairError;
|
|
39999
40000
|
}
|
|
40000
|
-
}
|
|
40001
|
+
},
|
|
40002
|
+
onFinish
|
|
40001
40003
|
});
|
|
40002
40004
|
return wrapStreamWithErrorHandler(response, messagesContainer, opts, providerModel, silent);
|
|
40003
40005
|
} catch (error46) {
|
|
@@ -45041,6 +45043,236 @@ Begin your analysis now.
|
|
|
45041
45043
|
};
|
|
45042
45044
|
}
|
|
45043
45045
|
|
|
45046
|
+
// src/core/messages/index.ts
|
|
45047
|
+
import fs from "fs";
|
|
45048
|
+
|
|
45049
|
+
// src/core/messages/types.ts
|
|
45050
|
+
var ToolMessageObject = exports_external.object({
|
|
45051
|
+
role: exports_external.literal("tool"),
|
|
45052
|
+
status: exports_external.enum(["pending", "completed"]),
|
|
45053
|
+
toolCallId: exports_external.string(),
|
|
45054
|
+
content: exports_external.string(),
|
|
45055
|
+
args: exports_external.record(exports_external.string(), exports_external.any()),
|
|
45056
|
+
toolName: exports_external.string(),
|
|
45057
|
+
createdAt: exports_external.coerce.date()
|
|
45058
|
+
});
|
|
45059
|
+
var SystemModelMessageObject = exports_external.object({
|
|
45060
|
+
role: exports_external.literal("system"),
|
|
45061
|
+
content: exports_external.string(),
|
|
45062
|
+
createdAt: exports_external.coerce.date(),
|
|
45063
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45064
|
+
});
|
|
45065
|
+
var TextPartObject = exports_external.object({
|
|
45066
|
+
type: exports_external.literal("text"),
|
|
45067
|
+
text: exports_external.string(),
|
|
45068
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45069
|
+
});
|
|
45070
|
+
var FilePartObject = exports_external.object({
|
|
45071
|
+
type: exports_external.literal("file"),
|
|
45072
|
+
data: exports_external.union([
|
|
45073
|
+
exports_external.string(),
|
|
45074
|
+
exports_external.instanceof(Uint8Array),
|
|
45075
|
+
exports_external.instanceof(ArrayBuffer),
|
|
45076
|
+
exports_external.instanceof(Buffer),
|
|
45077
|
+
exports_external.url()
|
|
45078
|
+
]),
|
|
45079
|
+
filename: exports_external.string().optional(),
|
|
45080
|
+
mediaType: exports_external.string(),
|
|
45081
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45082
|
+
});
|
|
45083
|
+
var ReasoningPartObject = exports_external.object({
|
|
45084
|
+
type: exports_external.literal("reasoning"),
|
|
45085
|
+
text: exports_external.string(),
|
|
45086
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45087
|
+
});
|
|
45088
|
+
var ToolCallPartObject = exports_external.object({
|
|
45089
|
+
type: exports_external.literal("tool-call"),
|
|
45090
|
+
toolCallId: exports_external.string(),
|
|
45091
|
+
toolName: exports_external.string(),
|
|
45092
|
+
input: exports_external.unknown(),
|
|
45093
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional(),
|
|
45094
|
+
providerExecuted: exports_external.boolean().optional()
|
|
45095
|
+
});
|
|
45096
|
+
var ToolResultOutputObject = exports_external.discriminatedUnion("type", [
|
|
45097
|
+
exports_external.object({
|
|
45098
|
+
type: exports_external.literal("text"),
|
|
45099
|
+
value: exports_external.string()
|
|
45100
|
+
}),
|
|
45101
|
+
exports_external.object({
|
|
45102
|
+
type: exports_external.literal("json"),
|
|
45103
|
+
value: exports_external.any()
|
|
45104
|
+
}),
|
|
45105
|
+
exports_external.object({
|
|
45106
|
+
type: exports_external.literal("error-text"),
|
|
45107
|
+
value: exports_external.string()
|
|
45108
|
+
}),
|
|
45109
|
+
exports_external.object({
|
|
45110
|
+
type: exports_external.literal("error-json"),
|
|
45111
|
+
value: exports_external.any()
|
|
45112
|
+
}),
|
|
45113
|
+
exports_external.object({
|
|
45114
|
+
type: exports_external.literal("content"),
|
|
45115
|
+
value: exports_external.array(exports_external.discriminatedUnion("type", [
|
|
45116
|
+
exports_external.object({
|
|
45117
|
+
type: exports_external.literal("text"),
|
|
45118
|
+
text: exports_external.string()
|
|
45119
|
+
}),
|
|
45120
|
+
exports_external.object({
|
|
45121
|
+
type: exports_external.literal("media"),
|
|
45122
|
+
data: exports_external.string(),
|
|
45123
|
+
mediaType: exports_external.string()
|
|
45124
|
+
})
|
|
45125
|
+
]))
|
|
45126
|
+
})
|
|
45127
|
+
]);
|
|
45128
|
+
var ToolResultPartObject = exports_external.object({
|
|
45129
|
+
type: exports_external.literal("tool-result"),
|
|
45130
|
+
toolCallId: exports_external.string(),
|
|
45131
|
+
toolName: exports_external.string(),
|
|
45132
|
+
output: ToolResultOutputObject,
|
|
45133
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45134
|
+
});
|
|
45135
|
+
var AssistantModelMessageObject = exports_external.object({
|
|
45136
|
+
role: exports_external.literal("assistant"),
|
|
45137
|
+
content: exports_external.union([
|
|
45138
|
+
exports_external.string(),
|
|
45139
|
+
exports_external.array(exports_external.discriminatedUnion("type", [
|
|
45140
|
+
TextPartObject,
|
|
45141
|
+
FilePartObject,
|
|
45142
|
+
ReasoningPartObject,
|
|
45143
|
+
ToolCallPartObject,
|
|
45144
|
+
ToolResultPartObject
|
|
45145
|
+
]))
|
|
45146
|
+
]),
|
|
45147
|
+
createdAt: exports_external.coerce.date(),
|
|
45148
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45149
|
+
});
|
|
45150
|
+
var UserModelMessageObject = exports_external.object({
|
|
45151
|
+
role: exports_external.literal("user"),
|
|
45152
|
+
content: exports_external.union([
|
|
45153
|
+
exports_external.string(),
|
|
45154
|
+
exports_external.array(exports_external.discriminatedUnion("type", [TextPartObject, FilePartObject]))
|
|
45155
|
+
]),
|
|
45156
|
+
createdAt: exports_external.coerce.date(),
|
|
45157
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45158
|
+
});
|
|
45159
|
+
var ModelMessageObject = exports_external.discriminatedUnion("role", [
|
|
45160
|
+
SystemModelMessageObject,
|
|
45161
|
+
UserModelMessageObject,
|
|
45162
|
+
AssistantModelMessageObject,
|
|
45163
|
+
ToolMessageObject
|
|
45164
|
+
]);
|
|
45165
|
+
|
|
45166
|
+
// src/core/messages/index.ts
|
|
45167
|
+
function saveSubagentMessages(orchestratorSession, subagentId, messages) {
|
|
45168
|
+
const subagentDir = `${orchestratorSession.rootPath}/subagents/${subagentId}`;
|
|
45169
|
+
if (!fs.existsSync(`${orchestratorSession.rootPath}/subagents`)) {
|
|
45170
|
+
fs.mkdirSync(`${orchestratorSession.rootPath}/subagents`, {
|
|
45171
|
+
recursive: true
|
|
45172
|
+
});
|
|
45173
|
+
}
|
|
45174
|
+
if (!fs.existsSync(subagentDir)) {
|
|
45175
|
+
fs.mkdirSync(subagentDir, { recursive: true });
|
|
45176
|
+
}
|
|
45177
|
+
fs.writeFileSync(`${subagentDir}/messages.json`, JSON.stringify(messages, null, 2));
|
|
45178
|
+
}
|
|
45179
|
+
function mapMessages(messages) {
|
|
45180
|
+
const result = [];
|
|
45181
|
+
const toolResults = new Map;
|
|
45182
|
+
for (const message of messages) {
|
|
45183
|
+
if (message.role === "tool") {
|
|
45184
|
+
const content = message.content;
|
|
45185
|
+
if (Array.isArray(content)) {
|
|
45186
|
+
for (const part of content) {
|
|
45187
|
+
if (part.type === "tool-result") {
|
|
45188
|
+
toolResults.set(part.toolCallId, part.output);
|
|
45189
|
+
}
|
|
45190
|
+
}
|
|
45191
|
+
}
|
|
45192
|
+
}
|
|
45193
|
+
}
|
|
45194
|
+
for (const message of messages) {
|
|
45195
|
+
if (message.role === "system") {
|
|
45196
|
+
result.push({
|
|
45197
|
+
role: "system",
|
|
45198
|
+
content: message.content,
|
|
45199
|
+
createdAt: new Date,
|
|
45200
|
+
...message.providerOptions && {
|
|
45201
|
+
providerOptions: message.providerOptions
|
|
45202
|
+
}
|
|
45203
|
+
});
|
|
45204
|
+
continue;
|
|
45205
|
+
}
|
|
45206
|
+
if (message.role === "user") {
|
|
45207
|
+
const content = typeof message.content === "string" ? message.content : message.content.map((part) => part.type === "text" ? part.text : "").join("");
|
|
45208
|
+
result.push({
|
|
45209
|
+
role: "user",
|
|
45210
|
+
content,
|
|
45211
|
+
createdAt: new Date,
|
|
45212
|
+
...message.providerOptions && {
|
|
45213
|
+
providerOptions: message.providerOptions
|
|
45214
|
+
}
|
|
45215
|
+
});
|
|
45216
|
+
continue;
|
|
45217
|
+
}
|
|
45218
|
+
if (message.role === "tool") {
|
|
45219
|
+
continue;
|
|
45220
|
+
}
|
|
45221
|
+
if (message.role === "assistant") {
|
|
45222
|
+
const content = message.content;
|
|
45223
|
+
if (typeof content === "string") {
|
|
45224
|
+
result.push({
|
|
45225
|
+
role: "assistant",
|
|
45226
|
+
content,
|
|
45227
|
+
createdAt: new Date,
|
|
45228
|
+
...message.providerOptions && {
|
|
45229
|
+
providerOptions: message.providerOptions
|
|
45230
|
+
}
|
|
45231
|
+
});
|
|
45232
|
+
continue;
|
|
45233
|
+
}
|
|
45234
|
+
const textParts = [];
|
|
45235
|
+
const toolCalls = [];
|
|
45236
|
+
for (const part of content) {
|
|
45237
|
+
if (part.type === "text") {
|
|
45238
|
+
textParts.push(part.text);
|
|
45239
|
+
} else if (part.type === "tool-call") {
|
|
45240
|
+
toolCalls.push({
|
|
45241
|
+
toolCallId: part.toolCallId,
|
|
45242
|
+
toolName: part.toolName,
|
|
45243
|
+
input: part.input
|
|
45244
|
+
});
|
|
45245
|
+
}
|
|
45246
|
+
}
|
|
45247
|
+
if (textParts.length > 0) {
|
|
45248
|
+
result.push({
|
|
45249
|
+
role: "assistant",
|
|
45250
|
+
content: textParts.join(""),
|
|
45251
|
+
createdAt: new Date,
|
|
45252
|
+
...message.providerOptions && {
|
|
45253
|
+
providerOptions: message.providerOptions
|
|
45254
|
+
}
|
|
45255
|
+
});
|
|
45256
|
+
}
|
|
45257
|
+
for (const toolCall of toolCalls) {
|
|
45258
|
+
const input = toolCall.input;
|
|
45259
|
+
const toolCallDescription = input?.toolCallDescription || `Executing ${toolCall.toolName}`;
|
|
45260
|
+
const hasResult = toolResults.has(toolCall.toolCallId);
|
|
45261
|
+
result.push({
|
|
45262
|
+
role: "tool",
|
|
45263
|
+
status: hasResult ? "completed" : "pending",
|
|
45264
|
+
toolCallId: toolCall.toolCallId,
|
|
45265
|
+
content: hasResult ? `✓ ${toolCallDescription}` : toolCallDescription,
|
|
45266
|
+
args: input || {},
|
|
45267
|
+
toolName: toolCall.toolName,
|
|
45268
|
+
createdAt: new Date
|
|
45269
|
+
});
|
|
45270
|
+
}
|
|
45271
|
+
}
|
|
45272
|
+
}
|
|
45273
|
+
return result;
|
|
45274
|
+
}
|
|
45275
|
+
|
|
45044
45276
|
// src/core/agent/pentestAgent/agent.ts
|
|
45045
45277
|
var execAsync3 = promisify3(exec3);
|
|
45046
45278
|
function runAgent(opts) {
|
|
@@ -45057,6 +45289,7 @@ function runAgent(opts) {
|
|
|
45057
45289
|
sessionConfig
|
|
45058
45290
|
} = opts;
|
|
45059
45291
|
const session = opts.session || createSession(target, objective, undefined, sessionConfig);
|
|
45292
|
+
const subagentId = `pentest-${nanoid3(6)}`;
|
|
45060
45293
|
const pocsPath = join4(session.rootPath, "pocs");
|
|
45061
45294
|
if (!existsSync6(pocsPath)) {
|
|
45062
45295
|
mkdirSync4(pocsPath, { recursive: true });
|
|
@@ -45212,10 +45445,13 @@ You are only authorized to perform testing against the specific target endpoint
|
|
|
45212
45445
|
onStepFinish,
|
|
45213
45446
|
abortSignal,
|
|
45214
45447
|
silent,
|
|
45215
|
-
authConfig
|
|
45448
|
+
authConfig,
|
|
45449
|
+
onFinish: ({ response }) => {
|
|
45450
|
+
saveSubagentMessages(session, subagentId, mapMessages(response.messages));
|
|
45451
|
+
}
|
|
45216
45452
|
});
|
|
45217
45453
|
streamResult.session = session;
|
|
45218
|
-
return { streamResult, session };
|
|
45454
|
+
return { streamResult, session, subagentId };
|
|
45219
45455
|
}
|
|
45220
45456
|
|
|
45221
45457
|
// scripts/quicktest.ts
|
package/build/swarm.js
CHANGED
|
@@ -39942,7 +39942,8 @@ function streamResponse(opts) {
|
|
|
39942
39942
|
abortSignal,
|
|
39943
39943
|
activeTools,
|
|
39944
39944
|
silent,
|
|
39945
|
-
authConfig
|
|
39945
|
+
authConfig,
|
|
39946
|
+
onFinish
|
|
39946
39947
|
} = opts;
|
|
39947
39948
|
const messagesContainer = { current: messages || [] };
|
|
39948
39949
|
const providerModel = getProviderModel(model, authConfig);
|
|
@@ -39997,7 +39998,8 @@ function streamResponse(opts) {
|
|
|
39997
39998
|
}
|
|
39998
39999
|
throw repairError;
|
|
39999
40000
|
}
|
|
40000
|
-
}
|
|
40001
|
+
},
|
|
40002
|
+
onFinish
|
|
40001
40003
|
});
|
|
40002
40004
|
return wrapStreamWithErrorHandler(response, messagesContainer, opts, providerModel, silent);
|
|
40003
40005
|
} catch (error46) {
|
|
@@ -45042,6 +45044,236 @@ Begin your analysis now.
|
|
|
45042
45044
|
};
|
|
45043
45045
|
}
|
|
45044
45046
|
|
|
45047
|
+
// src/core/messages/index.ts
|
|
45048
|
+
import fs from "fs";
|
|
45049
|
+
|
|
45050
|
+
// src/core/messages/types.ts
|
|
45051
|
+
var ToolMessageObject = exports_external.object({
|
|
45052
|
+
role: exports_external.literal("tool"),
|
|
45053
|
+
status: exports_external.enum(["pending", "completed"]),
|
|
45054
|
+
toolCallId: exports_external.string(),
|
|
45055
|
+
content: exports_external.string(),
|
|
45056
|
+
args: exports_external.record(exports_external.string(), exports_external.any()),
|
|
45057
|
+
toolName: exports_external.string(),
|
|
45058
|
+
createdAt: exports_external.coerce.date()
|
|
45059
|
+
});
|
|
45060
|
+
var SystemModelMessageObject = exports_external.object({
|
|
45061
|
+
role: exports_external.literal("system"),
|
|
45062
|
+
content: exports_external.string(),
|
|
45063
|
+
createdAt: exports_external.coerce.date(),
|
|
45064
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45065
|
+
});
|
|
45066
|
+
var TextPartObject = exports_external.object({
|
|
45067
|
+
type: exports_external.literal("text"),
|
|
45068
|
+
text: exports_external.string(),
|
|
45069
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45070
|
+
});
|
|
45071
|
+
var FilePartObject = exports_external.object({
|
|
45072
|
+
type: exports_external.literal("file"),
|
|
45073
|
+
data: exports_external.union([
|
|
45074
|
+
exports_external.string(),
|
|
45075
|
+
exports_external.instanceof(Uint8Array),
|
|
45076
|
+
exports_external.instanceof(ArrayBuffer),
|
|
45077
|
+
exports_external.instanceof(Buffer),
|
|
45078
|
+
exports_external.url()
|
|
45079
|
+
]),
|
|
45080
|
+
filename: exports_external.string().optional(),
|
|
45081
|
+
mediaType: exports_external.string(),
|
|
45082
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45083
|
+
});
|
|
45084
|
+
var ReasoningPartObject = exports_external.object({
|
|
45085
|
+
type: exports_external.literal("reasoning"),
|
|
45086
|
+
text: exports_external.string(),
|
|
45087
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45088
|
+
});
|
|
45089
|
+
var ToolCallPartObject = exports_external.object({
|
|
45090
|
+
type: exports_external.literal("tool-call"),
|
|
45091
|
+
toolCallId: exports_external.string(),
|
|
45092
|
+
toolName: exports_external.string(),
|
|
45093
|
+
input: exports_external.unknown(),
|
|
45094
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional(),
|
|
45095
|
+
providerExecuted: exports_external.boolean().optional()
|
|
45096
|
+
});
|
|
45097
|
+
var ToolResultOutputObject = exports_external.discriminatedUnion("type", [
|
|
45098
|
+
exports_external.object({
|
|
45099
|
+
type: exports_external.literal("text"),
|
|
45100
|
+
value: exports_external.string()
|
|
45101
|
+
}),
|
|
45102
|
+
exports_external.object({
|
|
45103
|
+
type: exports_external.literal("json"),
|
|
45104
|
+
value: exports_external.any()
|
|
45105
|
+
}),
|
|
45106
|
+
exports_external.object({
|
|
45107
|
+
type: exports_external.literal("error-text"),
|
|
45108
|
+
value: exports_external.string()
|
|
45109
|
+
}),
|
|
45110
|
+
exports_external.object({
|
|
45111
|
+
type: exports_external.literal("error-json"),
|
|
45112
|
+
value: exports_external.any()
|
|
45113
|
+
}),
|
|
45114
|
+
exports_external.object({
|
|
45115
|
+
type: exports_external.literal("content"),
|
|
45116
|
+
value: exports_external.array(exports_external.discriminatedUnion("type", [
|
|
45117
|
+
exports_external.object({
|
|
45118
|
+
type: exports_external.literal("text"),
|
|
45119
|
+
text: exports_external.string()
|
|
45120
|
+
}),
|
|
45121
|
+
exports_external.object({
|
|
45122
|
+
type: exports_external.literal("media"),
|
|
45123
|
+
data: exports_external.string(),
|
|
45124
|
+
mediaType: exports_external.string()
|
|
45125
|
+
})
|
|
45126
|
+
]))
|
|
45127
|
+
})
|
|
45128
|
+
]);
|
|
45129
|
+
var ToolResultPartObject = exports_external.object({
|
|
45130
|
+
type: exports_external.literal("tool-result"),
|
|
45131
|
+
toolCallId: exports_external.string(),
|
|
45132
|
+
toolName: exports_external.string(),
|
|
45133
|
+
output: ToolResultOutputObject,
|
|
45134
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45135
|
+
});
|
|
45136
|
+
var AssistantModelMessageObject = exports_external.object({
|
|
45137
|
+
role: exports_external.literal("assistant"),
|
|
45138
|
+
content: exports_external.union([
|
|
45139
|
+
exports_external.string(),
|
|
45140
|
+
exports_external.array(exports_external.discriminatedUnion("type", [
|
|
45141
|
+
TextPartObject,
|
|
45142
|
+
FilePartObject,
|
|
45143
|
+
ReasoningPartObject,
|
|
45144
|
+
ToolCallPartObject,
|
|
45145
|
+
ToolResultPartObject
|
|
45146
|
+
]))
|
|
45147
|
+
]),
|
|
45148
|
+
createdAt: exports_external.coerce.date(),
|
|
45149
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45150
|
+
});
|
|
45151
|
+
var UserModelMessageObject = exports_external.object({
|
|
45152
|
+
role: exports_external.literal("user"),
|
|
45153
|
+
content: exports_external.union([
|
|
45154
|
+
exports_external.string(),
|
|
45155
|
+
exports_external.array(exports_external.discriminatedUnion("type", [TextPartObject, FilePartObject]))
|
|
45156
|
+
]),
|
|
45157
|
+
createdAt: exports_external.coerce.date(),
|
|
45158
|
+
providerOptions: exports_external.record(exports_external.string(), exports_external.any()).optional()
|
|
45159
|
+
});
|
|
45160
|
+
var ModelMessageObject = exports_external.discriminatedUnion("role", [
|
|
45161
|
+
SystemModelMessageObject,
|
|
45162
|
+
UserModelMessageObject,
|
|
45163
|
+
AssistantModelMessageObject,
|
|
45164
|
+
ToolMessageObject
|
|
45165
|
+
]);
|
|
45166
|
+
|
|
45167
|
+
// src/core/messages/index.ts
|
|
45168
|
+
function saveSubagentMessages(orchestratorSession, subagentId, messages) {
|
|
45169
|
+
const subagentDir = `${orchestratorSession.rootPath}/subagents/${subagentId}`;
|
|
45170
|
+
if (!fs.existsSync(`${orchestratorSession.rootPath}/subagents`)) {
|
|
45171
|
+
fs.mkdirSync(`${orchestratorSession.rootPath}/subagents`, {
|
|
45172
|
+
recursive: true
|
|
45173
|
+
});
|
|
45174
|
+
}
|
|
45175
|
+
if (!fs.existsSync(subagentDir)) {
|
|
45176
|
+
fs.mkdirSync(subagentDir, { recursive: true });
|
|
45177
|
+
}
|
|
45178
|
+
fs.writeFileSync(`${subagentDir}/messages.json`, JSON.stringify(messages, null, 2));
|
|
45179
|
+
}
|
|
45180
|
+
function mapMessages(messages) {
|
|
45181
|
+
const result = [];
|
|
45182
|
+
const toolResults = new Map;
|
|
45183
|
+
for (const message of messages) {
|
|
45184
|
+
if (message.role === "tool") {
|
|
45185
|
+
const content = message.content;
|
|
45186
|
+
if (Array.isArray(content)) {
|
|
45187
|
+
for (const part of content) {
|
|
45188
|
+
if (part.type === "tool-result") {
|
|
45189
|
+
toolResults.set(part.toolCallId, part.output);
|
|
45190
|
+
}
|
|
45191
|
+
}
|
|
45192
|
+
}
|
|
45193
|
+
}
|
|
45194
|
+
}
|
|
45195
|
+
for (const message of messages) {
|
|
45196
|
+
if (message.role === "system") {
|
|
45197
|
+
result.push({
|
|
45198
|
+
role: "system",
|
|
45199
|
+
content: message.content,
|
|
45200
|
+
createdAt: new Date,
|
|
45201
|
+
...message.providerOptions && {
|
|
45202
|
+
providerOptions: message.providerOptions
|
|
45203
|
+
}
|
|
45204
|
+
});
|
|
45205
|
+
continue;
|
|
45206
|
+
}
|
|
45207
|
+
if (message.role === "user") {
|
|
45208
|
+
const content = typeof message.content === "string" ? message.content : message.content.map((part) => part.type === "text" ? part.text : "").join("");
|
|
45209
|
+
result.push({
|
|
45210
|
+
role: "user",
|
|
45211
|
+
content,
|
|
45212
|
+
createdAt: new Date,
|
|
45213
|
+
...message.providerOptions && {
|
|
45214
|
+
providerOptions: message.providerOptions
|
|
45215
|
+
}
|
|
45216
|
+
});
|
|
45217
|
+
continue;
|
|
45218
|
+
}
|
|
45219
|
+
if (message.role === "tool") {
|
|
45220
|
+
continue;
|
|
45221
|
+
}
|
|
45222
|
+
if (message.role === "assistant") {
|
|
45223
|
+
const content = message.content;
|
|
45224
|
+
if (typeof content === "string") {
|
|
45225
|
+
result.push({
|
|
45226
|
+
role: "assistant",
|
|
45227
|
+
content,
|
|
45228
|
+
createdAt: new Date,
|
|
45229
|
+
...message.providerOptions && {
|
|
45230
|
+
providerOptions: message.providerOptions
|
|
45231
|
+
}
|
|
45232
|
+
});
|
|
45233
|
+
continue;
|
|
45234
|
+
}
|
|
45235
|
+
const textParts = [];
|
|
45236
|
+
const toolCalls = [];
|
|
45237
|
+
for (const part of content) {
|
|
45238
|
+
if (part.type === "text") {
|
|
45239
|
+
textParts.push(part.text);
|
|
45240
|
+
} else if (part.type === "tool-call") {
|
|
45241
|
+
toolCalls.push({
|
|
45242
|
+
toolCallId: part.toolCallId,
|
|
45243
|
+
toolName: part.toolName,
|
|
45244
|
+
input: part.input
|
|
45245
|
+
});
|
|
45246
|
+
}
|
|
45247
|
+
}
|
|
45248
|
+
if (textParts.length > 0) {
|
|
45249
|
+
result.push({
|
|
45250
|
+
role: "assistant",
|
|
45251
|
+
content: textParts.join(""),
|
|
45252
|
+
createdAt: new Date,
|
|
45253
|
+
...message.providerOptions && {
|
|
45254
|
+
providerOptions: message.providerOptions
|
|
45255
|
+
}
|
|
45256
|
+
});
|
|
45257
|
+
}
|
|
45258
|
+
for (const toolCall of toolCalls) {
|
|
45259
|
+
const input = toolCall.input;
|
|
45260
|
+
const toolCallDescription = input?.toolCallDescription || `Executing ${toolCall.toolName}`;
|
|
45261
|
+
const hasResult = toolResults.has(toolCall.toolCallId);
|
|
45262
|
+
result.push({
|
|
45263
|
+
role: "tool",
|
|
45264
|
+
status: hasResult ? "completed" : "pending",
|
|
45265
|
+
toolCallId: toolCall.toolCallId,
|
|
45266
|
+
content: hasResult ? `✓ ${toolCallDescription}` : toolCallDescription,
|
|
45267
|
+
args: input || {},
|
|
45268
|
+
toolName: toolCall.toolName,
|
|
45269
|
+
createdAt: new Date
|
|
45270
|
+
});
|
|
45271
|
+
}
|
|
45272
|
+
}
|
|
45273
|
+
}
|
|
45274
|
+
return result;
|
|
45275
|
+
}
|
|
45276
|
+
|
|
45045
45277
|
// src/core/agent/pentestAgent/agent.ts
|
|
45046
45278
|
var execAsync3 = promisify3(exec3);
|
|
45047
45279
|
function runAgent(opts) {
|
|
@@ -45058,6 +45290,7 @@ function runAgent(opts) {
|
|
|
45058
45290
|
sessionConfig
|
|
45059
45291
|
} = opts;
|
|
45060
45292
|
const session = opts.session || createSession(target, objective, undefined, sessionConfig);
|
|
45293
|
+
const subagentId = `pentest-${nanoid3(6)}`;
|
|
45061
45294
|
const pocsPath = join4(session.rootPath, "pocs");
|
|
45062
45295
|
if (!existsSync6(pocsPath)) {
|
|
45063
45296
|
mkdirSync4(pocsPath, { recursive: true });
|
|
@@ -45213,10 +45446,13 @@ You are only authorized to perform testing against the specific target endpoint
|
|
|
45213
45446
|
onStepFinish,
|
|
45214
45447
|
abortSignal,
|
|
45215
45448
|
silent,
|
|
45216
|
-
authConfig
|
|
45449
|
+
authConfig,
|
|
45450
|
+
onFinish: ({ response }) => {
|
|
45451
|
+
saveSubagentMessages(session, subagentId, mapMessages(response.messages));
|
|
45452
|
+
}
|
|
45217
45453
|
});
|
|
45218
45454
|
streamResult.session = session;
|
|
45219
|
-
return { streamResult, session };
|
|
45455
|
+
return { streamResult, session, subagentId };
|
|
45220
45456
|
}
|
|
45221
45457
|
// scripts/swarm.ts
|
|
45222
45458
|
import { readFileSync as readFileSync5 } from "fs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pensar/apex",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.31-canary.0",
|
|
4
4
|
"description": "AI-powered penetration testing CLI tool with terminal UI",
|
|
5
5
|
"module": "src/tui/index.tsx",
|
|
6
6
|
"main": "build/index.js",
|
|
@@ -20,6 +20,13 @@
|
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "bun build src/tui/index.tsx --outdir build --target node --format esm --external sharp && bun build scripts/benchmark.ts --outdir build --target node --format esm --external sharp && bun build scripts/quicktest.ts --outdir build --target node --format esm --external sharp && bun build scripts/pentest.ts --outdir build --target node --format esm --external sharp && bun build scripts/swarm.ts --outdir build --target node --format esm --external sharp",
|
|
23
|
+
"generate:ascii": "bun run scripts/generate-ascii-art.ts",
|
|
24
|
+
"build:binary": "bun run generate:ascii && bun build src/cli.ts --compile --outfile pensar",
|
|
25
|
+
"build:binary:macos-arm64": "bun build src/cli.ts --compile --target=bun-darwin-arm64 --outfile dist/pensar-darwin-arm64",
|
|
26
|
+
"build:binary:macos-x64": "bun build src/cli.ts --compile --target=bun-darwin-x64 --outfile dist/pensar-darwin-x64",
|
|
27
|
+
"build:binary:linux-x64": "bun build src/cli.ts --compile --target=bun-linux-x64 --outfile dist/pensar-linux-x64",
|
|
28
|
+
"build:binary:linux-arm64": "bun build src/cli.ts --compile --target=bun-linux-arm64 --outfile dist/pensar-linux-arm64",
|
|
29
|
+
"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",
|
|
23
30
|
"dev": "bun run scripts/watch.ts",
|
|
24
31
|
"dev:debug": "SHOW_CONSOLE=true bun run scripts/watch.ts",
|
|
25
32
|
"start": "bun run src/tui/index.tsx",
|