@probelabs/probe 0.6.0-rc167 → 0.6.0-rc168
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/ProbeAgent.d.ts +7 -1
- package/build/agent/ProbeAgent.js +312 -15
- package/build/agent/engines/codex.js +347 -0
- package/build/agent/engines/enhanced-claude-code.js +3 -42
- package/build/agent/index.js +983 -59
- package/build/agent/mcp/built-in-server.js +334 -8
- package/build/agent/shared/Session.js +53 -0
- package/build/agent/shared/prompts.js +129 -0
- package/cjs/agent/ProbeAgent.cjs +986 -61
- package/cjs/index.cjs +995 -70
- package/index.d.ts +7 -1
- package/package.json +1 -1
- package/src/agent/ProbeAgent.d.ts +7 -1
- package/src/agent/ProbeAgent.js +312 -15
- package/src/agent/engines/codex.js +347 -0
- package/src/agent/engines/enhanced-claude-code.js +3 -42
- package/src/agent/mcp/built-in-server.js +334 -8
- package/src/agent/shared/Session.js +53 -0
- package/src/agent/shared/prompts.js +129 -0
package/cjs/index.cjs
CHANGED
|
@@ -6750,11 +6750,11 @@ var require_randomUUID = __commonJS({
|
|
|
6750
6750
|
var require_dist_cjs19 = __commonJS({
|
|
6751
6751
|
"node_modules/@smithy/uuid/dist-cjs/index.js"(exports2) {
|
|
6752
6752
|
"use strict";
|
|
6753
|
-
var
|
|
6753
|
+
var randomUUID6 = require_randomUUID();
|
|
6754
6754
|
var decimalToHex = Array.from({ length: 256 }, (_, i4) => i4.toString(16).padStart(2, "0"));
|
|
6755
6755
|
var v4 = () => {
|
|
6756
|
-
if (
|
|
6757
|
-
return
|
|
6756
|
+
if (randomUUID6.randomUUID) {
|
|
6757
|
+
return randomUUID6.randomUUID();
|
|
6758
6758
|
}
|
|
6759
6759
|
const rnds = new Uint8Array(16);
|
|
6760
6760
|
crypto.getRandomValues(rnds);
|
|
@@ -79400,6 +79400,126 @@ Provide only the corrected Mermaid diagram within a mermaid code block. Do not a
|
|
|
79400
79400
|
}
|
|
79401
79401
|
});
|
|
79402
79402
|
|
|
79403
|
+
// src/agent/shared/prompts.js
|
|
79404
|
+
var predefinedPrompts;
|
|
79405
|
+
var init_prompts = __esm({
|
|
79406
|
+
"src/agent/shared/prompts.js"() {
|
|
79407
|
+
"use strict";
|
|
79408
|
+
predefinedPrompts = {
|
|
79409
|
+
"code-explorer": `You are ProbeChat Code Explorer - an AI assistant focused on reading and explaining code using Probe's semantic search capabilities.
|
|
79410
|
+
|
|
79411
|
+
Your primary role is to explore codebases, understand code structure, and provide clear explanations. You should:
|
|
79412
|
+
|
|
79413
|
+
1. Use the 'search' tool to find relevant code snippets across the codebase
|
|
79414
|
+
2. Use the 'query' tool to locate specific symbols, functions, or classes
|
|
79415
|
+
3. Use the 'extract' tool to get full context for files or specific code blocks
|
|
79416
|
+
4. Explain code behavior, architecture patterns, and relationships between components
|
|
79417
|
+
5. Provide concise summaries with key insights highlighted
|
|
79418
|
+
|
|
79419
|
+
When exploring code:
|
|
79420
|
+
- Start with targeted searches to find relevant areas
|
|
79421
|
+
- Extract full context when you need to understand implementation details
|
|
79422
|
+
- Trace function calls and data flow to understand how components interact
|
|
79423
|
+
- Focus on "why" and "how" rather than just describing what the code does
|
|
79424
|
+
|
|
79425
|
+
You should NOT:
|
|
79426
|
+
- Make changes to the codebase (read-only access)
|
|
79427
|
+
- Execute or run code
|
|
79428
|
+
- Make assumptions without verifying through search/query/extract`,
|
|
79429
|
+
"architect": `You are ProbeChat Architect - a senior software architect specialized in analyzing and designing software systems.
|
|
79430
|
+
|
|
79431
|
+
Your role is to:
|
|
79432
|
+
|
|
79433
|
+
1. Analyze existing codebases to understand architecture patterns and design decisions
|
|
79434
|
+
2. Identify architectural issues, technical debt, and improvement opportunities
|
|
79435
|
+
3. Propose refactoring strategies and architectural changes
|
|
79436
|
+
4. Design new features that fit well with existing architecture
|
|
79437
|
+
5. Create high-level architecture diagrams and documentation
|
|
79438
|
+
|
|
79439
|
+
When analyzing architecture:
|
|
79440
|
+
- Use search/query/extract to understand component boundaries and dependencies
|
|
79441
|
+
- Identify layers, modules, and their responsibilities
|
|
79442
|
+
- Look for patterns like MVC, microservices, event-driven, etc.
|
|
79443
|
+
- Assess coupling, cohesion, and separation of concerns
|
|
79444
|
+
- Consider scalability, maintainability, and testability
|
|
79445
|
+
|
|
79446
|
+
When proposing changes:
|
|
79447
|
+
- Provide clear rationale backed by architectural principles
|
|
79448
|
+
- Consider migration paths and backwards compatibility
|
|
79449
|
+
- Identify risks and tradeoffs
|
|
79450
|
+
- Suggest incremental implementation steps`,
|
|
79451
|
+
"code-review": `You are ProbeChat Code Reviewer - a meticulous code reviewer focused on quality, best practices, and maintainability.
|
|
79452
|
+
|
|
79453
|
+
Your role is to:
|
|
79454
|
+
|
|
79455
|
+
1. Review code changes for correctness, clarity, and best practices
|
|
79456
|
+
2. Identify bugs, security issues, and performance problems
|
|
79457
|
+
3. Suggest improvements for readability and maintainability
|
|
79458
|
+
4. Ensure consistency with project conventions and patterns
|
|
79459
|
+
5. Verify test coverage and edge case handling
|
|
79460
|
+
|
|
79461
|
+
When reviewing code:
|
|
79462
|
+
- Use search to find similar patterns in the codebase for consistency
|
|
79463
|
+
- Look for common issues: null checks, error handling, resource leaks
|
|
79464
|
+
- Check for security vulnerabilities: injection, XSS, etc.
|
|
79465
|
+
- Assess complexity and suggest simplifications
|
|
79466
|
+
- Verify naming conventions and code organization
|
|
79467
|
+
|
|
79468
|
+
Provide constructive feedback:
|
|
79469
|
+
- Start with what's good about the code
|
|
79470
|
+
- Be specific about issues with examples
|
|
79471
|
+
- Suggest concrete improvements with code snippets
|
|
79472
|
+
- Prioritize critical issues over style preferences
|
|
79473
|
+
- Explain the "why" behind your suggestions`,
|
|
79474
|
+
"engineer": `You are a senior engineer who helps implement features and fix bugs.
|
|
79475
|
+
|
|
79476
|
+
Your role is to:
|
|
79477
|
+
|
|
79478
|
+
1. Implement new features following project conventions
|
|
79479
|
+
2. Fix bugs by understanding root causes
|
|
79480
|
+
3. Refactor code to improve quality
|
|
79481
|
+
4. Write clear, maintainable code
|
|
79482
|
+
5. Add appropriate tests and documentation
|
|
79483
|
+
|
|
79484
|
+
When implementing:
|
|
79485
|
+
- Use search/query to understand existing patterns
|
|
79486
|
+
- Follow the project's coding style and conventions
|
|
79487
|
+
- Consider edge cases and error handling
|
|
79488
|
+
- Write self-documenting code with clear names
|
|
79489
|
+
- Add comments for complex logic
|
|
79490
|
+
|
|
79491
|
+
You have access to:
|
|
79492
|
+
- search: Find relevant code patterns
|
|
79493
|
+
- query: Locate specific symbols/functions
|
|
79494
|
+
- extract: Get full file context
|
|
79495
|
+
- implement: Create or modify files (use carefully)
|
|
79496
|
+
- delegate: Break down complex tasks`,
|
|
79497
|
+
"support": `You are ProbeChat Support - a helpful assistant focused on answering questions about codebases.
|
|
79498
|
+
|
|
79499
|
+
Your role is to:
|
|
79500
|
+
|
|
79501
|
+
1. Answer questions about how code works
|
|
79502
|
+
2. Help users locate specific functionality
|
|
79503
|
+
3. Explain error messages and debugging approaches
|
|
79504
|
+
4. Guide users to relevant documentation
|
|
79505
|
+
5. Provide examples and usage patterns
|
|
79506
|
+
|
|
79507
|
+
When helping users:
|
|
79508
|
+
- Ask clarifying questions if the request is ambiguous
|
|
79509
|
+
- Use search/query to find relevant code quickly
|
|
79510
|
+
- Provide clear, step-by-step explanations
|
|
79511
|
+
- Include code examples when helpful
|
|
79512
|
+
- Point to relevant files and line numbers
|
|
79513
|
+
|
|
79514
|
+
You should be:
|
|
79515
|
+
- Patient and encouraging
|
|
79516
|
+
- Clear and concise
|
|
79517
|
+
- Thorough but not overwhelming
|
|
79518
|
+
- Honest about limitations (say "I don't know" when appropriate)`
|
|
79519
|
+
};
|
|
79520
|
+
}
|
|
79521
|
+
});
|
|
79522
|
+
|
|
79403
79523
|
// src/agent/mcp/config.js
|
|
79404
79524
|
function loadMCPConfigurationFromPath(configPath) {
|
|
79405
79525
|
if (!configPath) {
|
|
@@ -80937,14 +81057,58 @@ var init_contextCompactor = __esm({
|
|
|
80937
81057
|
});
|
|
80938
81058
|
|
|
80939
81059
|
// src/agent/mcp/built-in-server.js
|
|
80940
|
-
var import_http, import_events2, import_server, import_types3, BuiltInMCPServer;
|
|
81060
|
+
var import_http, import_events2, import_crypto4, import_server, import_sse2, import_streamableHttp, import_types3, InMemoryEventStore, BuiltInMCPServer;
|
|
80941
81061
|
var init_built_in_server = __esm({
|
|
80942
81062
|
"src/agent/mcp/built-in-server.js"() {
|
|
80943
81063
|
"use strict";
|
|
80944
81064
|
import_http = require("http");
|
|
80945
81065
|
import_events2 = require("events");
|
|
81066
|
+
import_crypto4 = require("crypto");
|
|
80946
81067
|
import_server = require("@modelcontextprotocol/sdk/server/index.js");
|
|
81068
|
+
import_sse2 = require("@modelcontextprotocol/sdk/server/sse.js");
|
|
81069
|
+
import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
80947
81070
|
import_types3 = require("@modelcontextprotocol/sdk/types.js");
|
|
81071
|
+
InMemoryEventStore = class {
|
|
81072
|
+
constructor() {
|
|
81073
|
+
this.events = /* @__PURE__ */ new Map();
|
|
81074
|
+
}
|
|
81075
|
+
generateEventId(streamId) {
|
|
81076
|
+
return `${streamId}_${Date.now()}_${Math.random().toString(36).substring(2, 10)}`;
|
|
81077
|
+
}
|
|
81078
|
+
getStreamIdFromEventId(eventId) {
|
|
81079
|
+
const parts = eventId.split("_");
|
|
81080
|
+
return parts.length > 0 ? parts[0] : "";
|
|
81081
|
+
}
|
|
81082
|
+
async storeEvent(streamId, message) {
|
|
81083
|
+
const eventId = this.generateEventId(streamId);
|
|
81084
|
+
this.events.set(eventId, { streamId, message });
|
|
81085
|
+
return eventId;
|
|
81086
|
+
}
|
|
81087
|
+
async replayEventsAfter(lastEventId, { send }) {
|
|
81088
|
+
if (!lastEventId || !this.events.has(lastEventId)) {
|
|
81089
|
+
return "";
|
|
81090
|
+
}
|
|
81091
|
+
const streamId = this.getStreamIdFromEventId(lastEventId);
|
|
81092
|
+
if (!streamId) {
|
|
81093
|
+
return "";
|
|
81094
|
+
}
|
|
81095
|
+
let foundLastEvent = false;
|
|
81096
|
+
const sortedEvents = [...this.events.entries()].sort((a4, b4) => a4[0].localeCompare(b4[0]));
|
|
81097
|
+
for (const [eventId, { streamId: eventStreamId, message }] of sortedEvents) {
|
|
81098
|
+
if (eventStreamId !== streamId) {
|
|
81099
|
+
continue;
|
|
81100
|
+
}
|
|
81101
|
+
if (eventId === lastEventId) {
|
|
81102
|
+
foundLastEvent = true;
|
|
81103
|
+
continue;
|
|
81104
|
+
}
|
|
81105
|
+
if (foundLastEvent) {
|
|
81106
|
+
await send(eventId, message);
|
|
81107
|
+
}
|
|
81108
|
+
}
|
|
81109
|
+
return streamId;
|
|
81110
|
+
}
|
|
81111
|
+
};
|
|
80948
81112
|
BuiltInMCPServer = class extends import_events2.EventEmitter {
|
|
80949
81113
|
constructor(agent, options = {}) {
|
|
80950
81114
|
super();
|
|
@@ -80953,6 +81117,8 @@ var init_built_in_server = __esm({
|
|
|
80953
81117
|
this.host = options.host || "127.0.0.1";
|
|
80954
81118
|
this.httpServer = null;
|
|
80955
81119
|
this.mcpServer = null;
|
|
81120
|
+
this.sseTransports = /* @__PURE__ */ new Map();
|
|
81121
|
+
this.streamableTransports = /* @__PURE__ */ new Map();
|
|
80956
81122
|
this.connections = /* @__PURE__ */ new Set();
|
|
80957
81123
|
this.debug = options.debug || false;
|
|
80958
81124
|
}
|
|
@@ -80974,11 +81140,13 @@ var init_built_in_server = __esm({
|
|
|
80974
81140
|
});
|
|
80975
81141
|
this.registerHandlers();
|
|
80976
81142
|
return new Promise((resolve5, reject2) => {
|
|
80977
|
-
this.httpServer.listen(this.port, this.host, () => {
|
|
81143
|
+
this.httpServer.listen(this.port, this.host, async () => {
|
|
80978
81144
|
const address = this.httpServer.address();
|
|
80979
81145
|
this.port = address.port;
|
|
80980
81146
|
if (this.debug) {
|
|
80981
81147
|
console.log(`[MCP] Built-in server started at http://${this.host}:${this.port}`);
|
|
81148
|
+
console.log(`[MCP] SSE endpoint: http://${this.host}:${this.port}/sse`);
|
|
81149
|
+
console.log(`[MCP] Messages endpoint: http://${this.host}:${this.port}/messages`);
|
|
80982
81150
|
}
|
|
80983
81151
|
this.emit("ready", { host: this.host, port: this.port });
|
|
80984
81152
|
resolve5({ host: this.host, port: this.port });
|
|
@@ -80991,6 +81159,9 @@ var init_built_in_server = __esm({
|
|
|
80991
81159
|
*/
|
|
80992
81160
|
handleRequest(req, res) {
|
|
80993
81161
|
const { method, url } = req;
|
|
81162
|
+
if (this.debug) {
|
|
81163
|
+
console.log(`[MCP] Request: ${method} ${url}`);
|
|
81164
|
+
}
|
|
80994
81165
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
80995
81166
|
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
80996
81167
|
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
@@ -81000,15 +81171,22 @@ var init_built_in_server = __esm({
|
|
|
81000
81171
|
return;
|
|
81001
81172
|
}
|
|
81002
81173
|
if (url === "/sse" && method === "GET") {
|
|
81003
|
-
this.
|
|
81174
|
+
if (this.debug) {
|
|
81175
|
+
console.log("[MCP] Routing to handleSSEConnection");
|
|
81176
|
+
}
|
|
81177
|
+
this.handleSSEConnection(req, res);
|
|
81178
|
+
return;
|
|
81179
|
+
}
|
|
81180
|
+
if (url.startsWith("/messages") && method === "POST") {
|
|
81181
|
+
this.handleSSEMessage(req, res);
|
|
81004
81182
|
return;
|
|
81005
81183
|
}
|
|
81006
81184
|
if (url === "/rpc" && method === "POST") {
|
|
81007
81185
|
this.handleJSONRPC(req, res);
|
|
81008
81186
|
return;
|
|
81009
81187
|
}
|
|
81010
|
-
if (url === "/mcp"
|
|
81011
|
-
this.
|
|
81188
|
+
if (url === "/mcp") {
|
|
81189
|
+
this.handleStreamableHTTP(req, res);
|
|
81012
81190
|
return;
|
|
81013
81191
|
}
|
|
81014
81192
|
if (url === "/health") {
|
|
@@ -81024,7 +81202,190 @@ var init_built_in_server = __esm({
|
|
|
81024
81202
|
res.end("Not Found");
|
|
81025
81203
|
}
|
|
81026
81204
|
/**
|
|
81027
|
-
* Handle
|
|
81205
|
+
* Handle SSE connection (GET /sse) - creates new transport
|
|
81206
|
+
*/
|
|
81207
|
+
async handleSSEConnection(req, res) {
|
|
81208
|
+
if (this.debug) {
|
|
81209
|
+
console.log("[MCP] New SSE connection request");
|
|
81210
|
+
}
|
|
81211
|
+
const transport = new import_sse2.SSEServerTransport("/messages", res);
|
|
81212
|
+
this.sseTransports.set(transport.sessionId, transport);
|
|
81213
|
+
res.on("close", () => {
|
|
81214
|
+
if (this.debug) {
|
|
81215
|
+
console.log("[MCP] SSE connection closed, sessionId:", transport.sessionId);
|
|
81216
|
+
}
|
|
81217
|
+
this.sseTransports.delete(transport.sessionId);
|
|
81218
|
+
});
|
|
81219
|
+
try {
|
|
81220
|
+
await this.mcpServer.connect(transport);
|
|
81221
|
+
if (this.debug) {
|
|
81222
|
+
console.log("[MCP] MCP server connected to SSE transport, sessionId:", transport.sessionId);
|
|
81223
|
+
}
|
|
81224
|
+
} catch (error2) {
|
|
81225
|
+
if (this.debug) {
|
|
81226
|
+
console.error("[MCP] Error connecting MCP server to transport:", error2);
|
|
81227
|
+
}
|
|
81228
|
+
this.sseTransports.delete(transport.sessionId);
|
|
81229
|
+
}
|
|
81230
|
+
}
|
|
81231
|
+
/**
|
|
81232
|
+
* Handle SSE message (POST /messages?sessionId=...) - routes to existing transport
|
|
81233
|
+
*/
|
|
81234
|
+
async handleSSEMessage(req, res) {
|
|
81235
|
+
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
81236
|
+
const sessionId = url.searchParams.get("sessionId");
|
|
81237
|
+
if (!sessionId) {
|
|
81238
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
81239
|
+
res.end(JSON.stringify({
|
|
81240
|
+
jsonrpc: "2.0",
|
|
81241
|
+
error: {
|
|
81242
|
+
code: -32e3,
|
|
81243
|
+
message: "Bad Request: sessionId query parameter is required"
|
|
81244
|
+
},
|
|
81245
|
+
id: null
|
|
81246
|
+
}));
|
|
81247
|
+
return;
|
|
81248
|
+
}
|
|
81249
|
+
const transport = this.sseTransports.get(sessionId);
|
|
81250
|
+
if (!transport) {
|
|
81251
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
81252
|
+
res.end(JSON.stringify({
|
|
81253
|
+
jsonrpc: "2.0",
|
|
81254
|
+
error: {
|
|
81255
|
+
code: -32e3,
|
|
81256
|
+
message: `Bad Request: No transport found for sessionId: ${sessionId}`
|
|
81257
|
+
},
|
|
81258
|
+
id: null
|
|
81259
|
+
}));
|
|
81260
|
+
return;
|
|
81261
|
+
}
|
|
81262
|
+
let body = "";
|
|
81263
|
+
req.on("data", (chunk) => {
|
|
81264
|
+
body += chunk.toString();
|
|
81265
|
+
});
|
|
81266
|
+
req.on("end", async () => {
|
|
81267
|
+
try {
|
|
81268
|
+
const message = JSON.parse(body);
|
|
81269
|
+
await transport.handlePostMessage(req, res, message);
|
|
81270
|
+
} catch (error2) {
|
|
81271
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
81272
|
+
res.end(JSON.stringify({
|
|
81273
|
+
jsonrpc: "2.0",
|
|
81274
|
+
error: {
|
|
81275
|
+
code: -32603,
|
|
81276
|
+
message: "Internal error",
|
|
81277
|
+
data: error2.message
|
|
81278
|
+
},
|
|
81279
|
+
id: null
|
|
81280
|
+
}));
|
|
81281
|
+
}
|
|
81282
|
+
});
|
|
81283
|
+
}
|
|
81284
|
+
/**
|
|
81285
|
+
* Handle Streamable HTTP protocol (GET/POST/DELETE on /mcp)
|
|
81286
|
+
*/
|
|
81287
|
+
async handleStreamableHTTP(req, res) {
|
|
81288
|
+
const { method } = req;
|
|
81289
|
+
if (this.debug) {
|
|
81290
|
+
console.log(`[MCP] Streamable HTTP ${method} request`);
|
|
81291
|
+
}
|
|
81292
|
+
try {
|
|
81293
|
+
let body = null;
|
|
81294
|
+
if (method === "POST") {
|
|
81295
|
+
body = await this.parseRequestBody(req);
|
|
81296
|
+
}
|
|
81297
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
81298
|
+
let transport;
|
|
81299
|
+
if (sessionId && this.streamableTransports.has(sessionId)) {
|
|
81300
|
+
transport = this.streamableTransports.get(sessionId);
|
|
81301
|
+
if (this.debug) {
|
|
81302
|
+
console.log(`[MCP] Reusing existing transport for session: ${sessionId}`);
|
|
81303
|
+
}
|
|
81304
|
+
} else if (!sessionId && method === "POST" && body && (0, import_types3.isInitializeRequest)(body)) {
|
|
81305
|
+
if (this.debug) {
|
|
81306
|
+
console.log("[MCP] Creating new Streamable HTTP transport for initialization");
|
|
81307
|
+
}
|
|
81308
|
+
const eventStore = new InMemoryEventStore();
|
|
81309
|
+
transport = new import_streamableHttp.StreamableHTTPServerTransport({
|
|
81310
|
+
sessionIdGenerator: () => (0, import_crypto4.randomUUID)(),
|
|
81311
|
+
eventStore,
|
|
81312
|
+
// Enable resumability
|
|
81313
|
+
onsessioninitialized: (newSessionId) => {
|
|
81314
|
+
if (this.debug) {
|
|
81315
|
+
console.log(`[MCP] Streamable HTTP session initialized: ${newSessionId}`);
|
|
81316
|
+
}
|
|
81317
|
+
this.streamableTransports.set(newSessionId, transport);
|
|
81318
|
+
},
|
|
81319
|
+
onsessionclosed: (closedSessionId) => {
|
|
81320
|
+
if (this.debug) {
|
|
81321
|
+
console.log(`[MCP] Streamable HTTP session closed: ${closedSessionId}`);
|
|
81322
|
+
}
|
|
81323
|
+
this.streamableTransports.delete(closedSessionId);
|
|
81324
|
+
}
|
|
81325
|
+
});
|
|
81326
|
+
transport.onclose = () => {
|
|
81327
|
+
const sid = transport.sessionId;
|
|
81328
|
+
if (sid && this.streamableTransports.has(sid)) {
|
|
81329
|
+
if (this.debug) {
|
|
81330
|
+
console.log(`[MCP] Transport closed for session ${sid}`);
|
|
81331
|
+
}
|
|
81332
|
+
this.streamableTransports.delete(sid);
|
|
81333
|
+
}
|
|
81334
|
+
};
|
|
81335
|
+
await this.mcpServer.connect(transport);
|
|
81336
|
+
} else {
|
|
81337
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
81338
|
+
res.end(JSON.stringify({
|
|
81339
|
+
jsonrpc: "2.0",
|
|
81340
|
+
error: {
|
|
81341
|
+
code: -32e3,
|
|
81342
|
+
message: "Bad Request: No valid session ID provided or not an initialization request"
|
|
81343
|
+
},
|
|
81344
|
+
id: null
|
|
81345
|
+
}));
|
|
81346
|
+
return;
|
|
81347
|
+
}
|
|
81348
|
+
await transport.handleRequest(req, res, body);
|
|
81349
|
+
} catch (error2) {
|
|
81350
|
+
if (this.debug) {
|
|
81351
|
+
console.error("[MCP] Error handling Streamable HTTP request:", error2);
|
|
81352
|
+
}
|
|
81353
|
+
if (!res.headersSent) {
|
|
81354
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
81355
|
+
res.end(JSON.stringify({
|
|
81356
|
+
jsonrpc: "2.0",
|
|
81357
|
+
error: {
|
|
81358
|
+
code: -32603,
|
|
81359
|
+
message: "Internal server error",
|
|
81360
|
+
data: error2.message
|
|
81361
|
+
},
|
|
81362
|
+
id: null
|
|
81363
|
+
}));
|
|
81364
|
+
}
|
|
81365
|
+
}
|
|
81366
|
+
}
|
|
81367
|
+
/**
|
|
81368
|
+
* Parse request body as JSON
|
|
81369
|
+
*/
|
|
81370
|
+
async parseRequestBody(req) {
|
|
81371
|
+
return new Promise((resolve5, reject2) => {
|
|
81372
|
+
let body = "";
|
|
81373
|
+
req.on("data", (chunk) => {
|
|
81374
|
+
body += chunk.toString();
|
|
81375
|
+
});
|
|
81376
|
+
req.on("end", () => {
|
|
81377
|
+
try {
|
|
81378
|
+
const parsed = body ? JSON.parse(body) : null;
|
|
81379
|
+
resolve5(parsed);
|
|
81380
|
+
} catch (error2) {
|
|
81381
|
+
reject2(error2);
|
|
81382
|
+
}
|
|
81383
|
+
});
|
|
81384
|
+
req.on("error", reject2);
|
|
81385
|
+
});
|
|
81386
|
+
}
|
|
81387
|
+
/**
|
|
81388
|
+
* Handle Server-Sent Events connection (DEPRECATED - use handleSSEConnection instead)
|
|
81028
81389
|
*/
|
|
81029
81390
|
handleSSE(req, res) {
|
|
81030
81391
|
res.writeHead(200, {
|
|
@@ -81291,6 +81652,32 @@ data: ${JSON.stringify(data2)}
|
|
|
81291
81652
|
* Stop the server
|
|
81292
81653
|
*/
|
|
81293
81654
|
async stop() {
|
|
81655
|
+
for (const [sessionId, transport] of this.streamableTransports.entries()) {
|
|
81656
|
+
try {
|
|
81657
|
+
await transport.close();
|
|
81658
|
+
if (this.debug) {
|
|
81659
|
+
console.log(`[MCP] Closed Streamable HTTP transport for session: ${sessionId}`);
|
|
81660
|
+
}
|
|
81661
|
+
} catch (error2) {
|
|
81662
|
+
if (this.debug) {
|
|
81663
|
+
console.error(`[MCP] Error closing Streamable HTTP transport ${sessionId}:`, error2);
|
|
81664
|
+
}
|
|
81665
|
+
}
|
|
81666
|
+
}
|
|
81667
|
+
this.streamableTransports.clear();
|
|
81668
|
+
for (const [sessionId, transport] of this.sseTransports.entries()) {
|
|
81669
|
+
try {
|
|
81670
|
+
await transport.close();
|
|
81671
|
+
if (this.debug) {
|
|
81672
|
+
console.log(`[MCP] Closed SSE transport for session: ${sessionId}`);
|
|
81673
|
+
}
|
|
81674
|
+
} catch (error2) {
|
|
81675
|
+
if (this.debug) {
|
|
81676
|
+
console.error(`[MCP] Error closing SSE transport ${sessionId}:`, error2);
|
|
81677
|
+
}
|
|
81678
|
+
}
|
|
81679
|
+
}
|
|
81680
|
+
this.sseTransports.clear();
|
|
81294
81681
|
for (const connection of this.connections) {
|
|
81295
81682
|
connection.end();
|
|
81296
81683
|
}
|
|
@@ -81322,6 +81709,59 @@ data: ${JSON.stringify(data2)}
|
|
|
81322
81709
|
}
|
|
81323
81710
|
});
|
|
81324
81711
|
|
|
81712
|
+
// src/agent/shared/Session.js
|
|
81713
|
+
var Session;
|
|
81714
|
+
var init_Session = __esm({
|
|
81715
|
+
"src/agent/shared/Session.js"() {
|
|
81716
|
+
"use strict";
|
|
81717
|
+
Session = class {
|
|
81718
|
+
constructor(id, debug = false) {
|
|
81719
|
+
this.id = id;
|
|
81720
|
+
this.conversationId = null;
|
|
81721
|
+
this.messageCount = 0;
|
|
81722
|
+
this.debug = debug;
|
|
81723
|
+
}
|
|
81724
|
+
/**
|
|
81725
|
+
* Set the conversation ID for session resumption
|
|
81726
|
+
* @param {string} conversationId - Provider's conversation/thread ID
|
|
81727
|
+
*/
|
|
81728
|
+
setConversationId(conversationId) {
|
|
81729
|
+
this.conversationId = conversationId;
|
|
81730
|
+
if (this.debug) {
|
|
81731
|
+
console.log(`[Session ${this.id}] Conversation ID: ${conversationId}`);
|
|
81732
|
+
}
|
|
81733
|
+
}
|
|
81734
|
+
/**
|
|
81735
|
+
* Increment the message count
|
|
81736
|
+
*/
|
|
81737
|
+
incrementMessageCount() {
|
|
81738
|
+
this.messageCount++;
|
|
81739
|
+
}
|
|
81740
|
+
/**
|
|
81741
|
+
* Get session info as plain object
|
|
81742
|
+
* @returns {Object} Session information
|
|
81743
|
+
*/
|
|
81744
|
+
getInfo() {
|
|
81745
|
+
return {
|
|
81746
|
+
id: this.id,
|
|
81747
|
+
conversationId: this.conversationId,
|
|
81748
|
+
messageCount: this.messageCount
|
|
81749
|
+
};
|
|
81750
|
+
}
|
|
81751
|
+
/**
|
|
81752
|
+
* Get resume arguments for CLI commands (used by Claude Code)
|
|
81753
|
+
* @returns {Array<string>} CLI arguments for resuming conversation
|
|
81754
|
+
*/
|
|
81755
|
+
getResumeArgs() {
|
|
81756
|
+
if (this.conversationId && this.messageCount > 0) {
|
|
81757
|
+
return ["--resume", this.conversationId];
|
|
81758
|
+
}
|
|
81759
|
+
return [];
|
|
81760
|
+
}
|
|
81761
|
+
};
|
|
81762
|
+
}
|
|
81763
|
+
});
|
|
81764
|
+
|
|
81325
81765
|
// src/agent/engines/enhanced-claude-code.js
|
|
81326
81766
|
var enhanced_claude_code_exports = {};
|
|
81327
81767
|
__export(enhanced_claude_code_exports, {
|
|
@@ -81329,8 +81769,8 @@ __export(enhanced_claude_code_exports, {
|
|
|
81329
81769
|
});
|
|
81330
81770
|
async function createEnhancedClaudeCLIEngine(options = {}) {
|
|
81331
81771
|
const { agent, systemPrompt, customPrompt, debug, sessionId, allowedTools } = options;
|
|
81332
|
-
const session = new
|
|
81333
|
-
sessionId || (0,
|
|
81772
|
+
const session = new Session(
|
|
81773
|
+
sessionId || (0, import_crypto5.randomBytes)(8).toString("hex"),
|
|
81334
81774
|
debug
|
|
81335
81775
|
);
|
|
81336
81776
|
let mcpServer = null;
|
|
@@ -81540,11 +81980,7 @@ ${opts.schema}`;
|
|
|
81540
81980
|
* Get session info
|
|
81541
81981
|
*/
|
|
81542
81982
|
getSession() {
|
|
81543
|
-
return
|
|
81544
|
-
id: session.id,
|
|
81545
|
-
conversationId: session.conversationId,
|
|
81546
|
-
messageCount: session.messageCount
|
|
81547
|
-
};
|
|
81983
|
+
return session.getInfo();
|
|
81548
81984
|
},
|
|
81549
81985
|
/**
|
|
81550
81986
|
* Clean up - MUST be called to stop MCP server and clean resources
|
|
@@ -81725,46 +82161,293 @@ function combinePrompts(systemPrompt, customPrompt, agent) {
|
|
|
81725
82161
|
}
|
|
81726
82162
|
return systemPrompt || "";
|
|
81727
82163
|
}
|
|
81728
|
-
var import_child_process7,
|
|
82164
|
+
var import_child_process7, import_crypto5, import_promises2, import_path6, import_os4, import_events3;
|
|
81729
82165
|
var init_enhanced_claude_code = __esm({
|
|
81730
82166
|
"src/agent/engines/enhanced-claude-code.js"() {
|
|
81731
82167
|
"use strict";
|
|
81732
82168
|
import_child_process7 = require("child_process");
|
|
81733
|
-
|
|
82169
|
+
import_crypto5 = require("crypto");
|
|
81734
82170
|
import_promises2 = __toESM(require("fs/promises"), 1);
|
|
81735
82171
|
import_path6 = __toESM(require("path"), 1);
|
|
81736
82172
|
import_os4 = __toESM(require("os"), 1);
|
|
81737
82173
|
import_events3 = require("events");
|
|
81738
82174
|
init_built_in_server();
|
|
81739
|
-
|
|
81740
|
-
|
|
81741
|
-
|
|
81742
|
-
|
|
81743
|
-
|
|
81744
|
-
|
|
82175
|
+
init_Session();
|
|
82176
|
+
}
|
|
82177
|
+
});
|
|
82178
|
+
|
|
82179
|
+
// src/agent/engines/codex.js
|
|
82180
|
+
var codex_exports = {};
|
|
82181
|
+
__export(codex_exports, {
|
|
82182
|
+
createCodexEngine: () => createCodexEngine
|
|
82183
|
+
});
|
|
82184
|
+
async function createCodexEngine(options = {}) {
|
|
82185
|
+
const { agent, systemPrompt, customPrompt, debug, sessionId, allowedTools, model } = options;
|
|
82186
|
+
const session = new Session(
|
|
82187
|
+
sessionId || (0, import_crypto6.randomBytes)(8).toString("hex"),
|
|
82188
|
+
debug
|
|
82189
|
+
);
|
|
82190
|
+
let mcpServer = null;
|
|
82191
|
+
let mcpServerUrl = null;
|
|
82192
|
+
let mcpServerName = null;
|
|
82193
|
+
if (agent) {
|
|
82194
|
+
mcpServer = new BuiltInMCPServer(agent, {
|
|
82195
|
+
port: 0,
|
|
82196
|
+
host: "127.0.0.1",
|
|
82197
|
+
debug
|
|
82198
|
+
});
|
|
82199
|
+
const { host, port } = await mcpServer.start();
|
|
82200
|
+
mcpServerUrl = `http://${host}:${port}/mcp`;
|
|
82201
|
+
mcpServerName = `probe_${session.id}`;
|
|
82202
|
+
if (debug) {
|
|
82203
|
+
console.log("[DEBUG] Built-in Probe MCP server started");
|
|
82204
|
+
console.log("[DEBUG] Probe MCP URL:", mcpServerUrl);
|
|
82205
|
+
}
|
|
82206
|
+
}
|
|
82207
|
+
if (debug) {
|
|
82208
|
+
console.log("[DEBUG] Starting Codex MCP server...");
|
|
82209
|
+
}
|
|
82210
|
+
const codexProcess = (0, import_child_process8.spawn)("codex", ["mcp-server"], {
|
|
82211
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
82212
|
+
});
|
|
82213
|
+
let requestId = 0;
|
|
82214
|
+
const pendingRequests = /* @__PURE__ */ new Map();
|
|
82215
|
+
const eventHandlers = /* @__PURE__ */ new Map();
|
|
82216
|
+
const stdoutReader = (0, import_readline.createInterface)({
|
|
82217
|
+
input: codexProcess.stdout,
|
|
82218
|
+
crlfDelay: Infinity
|
|
82219
|
+
});
|
|
82220
|
+
stdoutReader.on("line", (line) => {
|
|
82221
|
+
try {
|
|
82222
|
+
const message = JSON.parse(line);
|
|
82223
|
+
if (debug) {
|
|
82224
|
+
if (message.method === "codex/event") {
|
|
82225
|
+
console.log(`[DEBUG] Codex event: ${message.params?.msg?.type}`);
|
|
82226
|
+
}
|
|
81745
82227
|
}
|
|
81746
|
-
|
|
81747
|
-
|
|
81748
|
-
|
|
81749
|
-
|
|
81750
|
-
|
|
81751
|
-
|
|
81752
|
-
|
|
82228
|
+
if (message.id !== void 0 && pendingRequests.has(message.id)) {
|
|
82229
|
+
const { resolve: resolve5, reject: reject2 } = pendingRequests.get(message.id);
|
|
82230
|
+
pendingRequests.delete(message.id);
|
|
82231
|
+
if (message.error) {
|
|
82232
|
+
reject2(new Error(message.error.message || JSON.stringify(message.error)));
|
|
82233
|
+
} else {
|
|
82234
|
+
resolve5(message.result);
|
|
81753
82235
|
}
|
|
81754
82236
|
}
|
|
81755
|
-
|
|
81756
|
-
|
|
81757
|
-
|
|
81758
|
-
|
|
81759
|
-
if (this.conversationId && this.messageCount > 0) {
|
|
81760
|
-
return ["--resume", this.conversationId];
|
|
82237
|
+
if (message.method === "codex/event" && message.params) {
|
|
82238
|
+
const requestId2 = message.params._meta?.requestId;
|
|
82239
|
+
if (requestId2 !== void 0 && eventHandlers.has(requestId2)) {
|
|
82240
|
+
eventHandlers.get(requestId2)(message.params);
|
|
81761
82241
|
}
|
|
81762
|
-
return [];
|
|
81763
82242
|
}
|
|
81764
|
-
|
|
81765
|
-
|
|
82243
|
+
} catch (e4) {
|
|
82244
|
+
if (debug) {
|
|
82245
|
+
console.error("[DEBUG] Failed to parse message:", line);
|
|
81766
82246
|
}
|
|
81767
|
-
}
|
|
82247
|
+
}
|
|
82248
|
+
});
|
|
82249
|
+
if (debug) {
|
|
82250
|
+
codexProcess.stderr.on("data", (data2) => {
|
|
82251
|
+
console.error("[CODEX STDERR]", data2.toString());
|
|
82252
|
+
});
|
|
82253
|
+
}
|
|
82254
|
+
function sendRequest(method, params = {}) {
|
|
82255
|
+
return new Promise((resolve5, reject2) => {
|
|
82256
|
+
const id = ++requestId;
|
|
82257
|
+
const request = {
|
|
82258
|
+
jsonrpc: "2.0",
|
|
82259
|
+
id,
|
|
82260
|
+
method,
|
|
82261
|
+
params
|
|
82262
|
+
};
|
|
82263
|
+
pendingRequests.set(id, { resolve: resolve5, reject: reject2 });
|
|
82264
|
+
setTimeout(() => {
|
|
82265
|
+
if (pendingRequests.has(id)) {
|
|
82266
|
+
pendingRequests.delete(id);
|
|
82267
|
+
reject2(new Error(`Request ${method} timed out after 10 minutes`));
|
|
82268
|
+
}
|
|
82269
|
+
}, 6e5);
|
|
82270
|
+
codexProcess.stdin.write(JSON.stringify(request) + "\n");
|
|
82271
|
+
});
|
|
82272
|
+
}
|
|
82273
|
+
await sendRequest("initialize", {
|
|
82274
|
+
protocolVersion: "2024-11-05",
|
|
82275
|
+
capabilities: { tools: {} },
|
|
82276
|
+
clientInfo: {
|
|
82277
|
+
name: "probe-codex-client",
|
|
82278
|
+
version: "1.0.0"
|
|
82279
|
+
}
|
|
82280
|
+
});
|
|
82281
|
+
if (debug) {
|
|
82282
|
+
console.log("[DEBUG] Connected to Codex MCP server");
|
|
82283
|
+
console.log("[DEBUG] Session:", session.id);
|
|
82284
|
+
}
|
|
82285
|
+
const fullPrompt = combinePrompts2(systemPrompt, customPrompt, agent);
|
|
82286
|
+
return {
|
|
82287
|
+
sessionId: session.id,
|
|
82288
|
+
session,
|
|
82289
|
+
/**
|
|
82290
|
+
* Query Codex via MCP protocol with event streaming
|
|
82291
|
+
*/
|
|
82292
|
+
async *query(prompt, opts = {}) {
|
|
82293
|
+
let finalPrompt = prompt;
|
|
82294
|
+
if (!session.conversationId && fullPrompt) {
|
|
82295
|
+
finalPrompt = `${fullPrompt}
|
|
82296
|
+
|
|
82297
|
+
${prompt}`;
|
|
82298
|
+
}
|
|
82299
|
+
const isFollowUp = session.conversationId !== null;
|
|
82300
|
+
const toolName = isFollowUp ? "codex-reply" : "codex";
|
|
82301
|
+
const toolArgs = { prompt: finalPrompt };
|
|
82302
|
+
if (isFollowUp) {
|
|
82303
|
+
toolArgs.conversationId = session.conversationId;
|
|
82304
|
+
if (debug) {
|
|
82305
|
+
console.log(`[DEBUG] Follow-up with conversationId: ${session.conversationId}`);
|
|
82306
|
+
}
|
|
82307
|
+
} else {
|
|
82308
|
+
if (model) {
|
|
82309
|
+
toolArgs.model = model;
|
|
82310
|
+
}
|
|
82311
|
+
if (mcpServerUrl && mcpServerName) {
|
|
82312
|
+
toolArgs.config = {
|
|
82313
|
+
mcp_servers: {
|
|
82314
|
+
[mcpServerName]: { url: mcpServerUrl }
|
|
82315
|
+
}
|
|
82316
|
+
};
|
|
82317
|
+
}
|
|
82318
|
+
if (debug) {
|
|
82319
|
+
console.log(`[DEBUG] Initial query with tool: ${toolName}`);
|
|
82320
|
+
}
|
|
82321
|
+
}
|
|
82322
|
+
try {
|
|
82323
|
+
const reqId = requestId + 1;
|
|
82324
|
+
let fullResponse = "";
|
|
82325
|
+
let gotSessionId = false;
|
|
82326
|
+
const eventPromise = new Promise((resolve5) => {
|
|
82327
|
+
eventHandlers.set(reqId, (eventParams) => {
|
|
82328
|
+
const msg = eventParams.msg;
|
|
82329
|
+
if (msg.type === "session_configured" && msg.session_id && !gotSessionId) {
|
|
82330
|
+
session.setConversationId(msg.session_id);
|
|
82331
|
+
gotSessionId = true;
|
|
82332
|
+
}
|
|
82333
|
+
if (msg.type === "raw_response_item" && msg.item?.role === "assistant") {
|
|
82334
|
+
const content = msg.item.content;
|
|
82335
|
+
if (Array.isArray(content)) {
|
|
82336
|
+
for (const part of content) {
|
|
82337
|
+
if (part.type === "text" && part.text) {
|
|
82338
|
+
fullResponse += part.text;
|
|
82339
|
+
}
|
|
82340
|
+
}
|
|
82341
|
+
}
|
|
82342
|
+
}
|
|
82343
|
+
});
|
|
82344
|
+
setTimeout(() => {
|
|
82345
|
+
eventHandlers.delete(reqId);
|
|
82346
|
+
resolve5();
|
|
82347
|
+
}, 6e5);
|
|
82348
|
+
});
|
|
82349
|
+
const resultPromise = sendRequest("tools/call", {
|
|
82350
|
+
name: toolName,
|
|
82351
|
+
arguments: toolArgs
|
|
82352
|
+
});
|
|
82353
|
+
const result = await resultPromise;
|
|
82354
|
+
eventHandlers.delete(reqId);
|
|
82355
|
+
if (result && result.content && Array.isArray(result.content)) {
|
|
82356
|
+
for (const item of result.content) {
|
|
82357
|
+
if (item.type === "text" && item.text) {
|
|
82358
|
+
yield {
|
|
82359
|
+
type: "text",
|
|
82360
|
+
content: item.text
|
|
82361
|
+
};
|
|
82362
|
+
fullResponse = item.text;
|
|
82363
|
+
}
|
|
82364
|
+
}
|
|
82365
|
+
}
|
|
82366
|
+
if (fullResponse && (!result.content || result.content.length === 0)) {
|
|
82367
|
+
yield {
|
|
82368
|
+
type: "text",
|
|
82369
|
+
content: fullResponse
|
|
82370
|
+
};
|
|
82371
|
+
}
|
|
82372
|
+
session.incrementMessageCount();
|
|
82373
|
+
yield {
|
|
82374
|
+
type: "metadata",
|
|
82375
|
+
data: {
|
|
82376
|
+
sessionId: session.id,
|
|
82377
|
+
conversationId: session.conversationId,
|
|
82378
|
+
messageCount: session.messageCount
|
|
82379
|
+
}
|
|
82380
|
+
};
|
|
82381
|
+
} catch (error2) {
|
|
82382
|
+
if (debug) {
|
|
82383
|
+
console.error("[DEBUG] Codex query error:", error2);
|
|
82384
|
+
}
|
|
82385
|
+
yield {
|
|
82386
|
+
type: "error",
|
|
82387
|
+
error: error2
|
|
82388
|
+
};
|
|
82389
|
+
}
|
|
82390
|
+
},
|
|
82391
|
+
/**
|
|
82392
|
+
* Get session info
|
|
82393
|
+
*/
|
|
82394
|
+
getSession() {
|
|
82395
|
+
return session.getInfo();
|
|
82396
|
+
},
|
|
82397
|
+
/**
|
|
82398
|
+
* Clean up resources
|
|
82399
|
+
*/
|
|
82400
|
+
async close() {
|
|
82401
|
+
try {
|
|
82402
|
+
if (stdoutReader) {
|
|
82403
|
+
stdoutReader.close();
|
|
82404
|
+
if (debug) {
|
|
82405
|
+
console.log("[DEBUG] Closed stdout reader");
|
|
82406
|
+
}
|
|
82407
|
+
}
|
|
82408
|
+
pendingRequests.clear();
|
|
82409
|
+
eventHandlers.clear();
|
|
82410
|
+
if (codexProcess && !codexProcess.killed) {
|
|
82411
|
+
codexProcess.kill();
|
|
82412
|
+
if (debug) {
|
|
82413
|
+
console.log("[DEBUG] Killed Codex MCP server process");
|
|
82414
|
+
}
|
|
82415
|
+
}
|
|
82416
|
+
if (mcpServer) {
|
|
82417
|
+
await mcpServer.stop();
|
|
82418
|
+
if (debug) {
|
|
82419
|
+
console.log("[DEBUG] Stopped Probe MCP server");
|
|
82420
|
+
}
|
|
82421
|
+
}
|
|
82422
|
+
if (debug) {
|
|
82423
|
+
console.log("[DEBUG] Engine closed, session:", session.id);
|
|
82424
|
+
}
|
|
82425
|
+
} catch (error2) {
|
|
82426
|
+
if (debug) {
|
|
82427
|
+
console.error("[DEBUG] Error during cleanup:", error2.message);
|
|
82428
|
+
}
|
|
82429
|
+
}
|
|
82430
|
+
}
|
|
82431
|
+
};
|
|
82432
|
+
}
|
|
82433
|
+
function combinePrompts2(systemPrompt, customPrompt, agent) {
|
|
82434
|
+
if (!systemPrompt && customPrompt) {
|
|
82435
|
+
return customPrompt;
|
|
82436
|
+
}
|
|
82437
|
+
if (systemPrompt && customPrompt) {
|
|
82438
|
+
return systemPrompt + "\n\n## Additional Instructions\n" + customPrompt;
|
|
82439
|
+
}
|
|
82440
|
+
return systemPrompt || "";
|
|
82441
|
+
}
|
|
82442
|
+
var import_child_process8, import_crypto6, import_readline;
|
|
82443
|
+
var init_codex = __esm({
|
|
82444
|
+
"src/agent/engines/codex.js"() {
|
|
82445
|
+
"use strict";
|
|
82446
|
+
import_child_process8 = require("child_process");
|
|
82447
|
+
import_crypto6 = require("crypto");
|
|
82448
|
+
import_readline = require("readline");
|
|
82449
|
+
init_built_in_server();
|
|
82450
|
+
init_Session();
|
|
81768
82451
|
}
|
|
81769
82452
|
});
|
|
81770
82453
|
|
|
@@ -81842,7 +82525,7 @@ var ProbeAgent_exports = {};
|
|
|
81842
82525
|
__export(ProbeAgent_exports, {
|
|
81843
82526
|
ProbeAgent: () => ProbeAgent
|
|
81844
82527
|
});
|
|
81845
|
-
var import_dotenv, import_anthropic2, import_openai2, import_google2, import_ai2,
|
|
82528
|
+
var import_dotenv, import_anthropic2, import_openai2, import_google2, import_ai2, import_crypto7, import_events4, import_fs5, import_promises3, import_path7, MAX_TOOL_ITERATIONS, MAX_HISTORY_MESSAGES, MAX_IMAGE_FILE_SIZE, ProbeAgent;
|
|
81846
82529
|
var init_ProbeAgent = __esm({
|
|
81847
82530
|
"src/agent/ProbeAgent.js"() {
|
|
81848
82531
|
"use strict";
|
|
@@ -81852,7 +82535,7 @@ var init_ProbeAgent = __esm({
|
|
|
81852
82535
|
import_google2 = require("@ai-sdk/google");
|
|
81853
82536
|
init_dist3();
|
|
81854
82537
|
import_ai2 = require("ai");
|
|
81855
|
-
|
|
82538
|
+
import_crypto7 = require("crypto");
|
|
81856
82539
|
import_events4 = require("events");
|
|
81857
82540
|
import_fs5 = require("fs");
|
|
81858
82541
|
import_promises3 = require("fs/promises");
|
|
@@ -81868,6 +82551,7 @@ var init_ProbeAgent = __esm({
|
|
|
81868
82551
|
init_index();
|
|
81869
82552
|
init_schemaUtils();
|
|
81870
82553
|
init_xmlParsingUtils();
|
|
82554
|
+
init_prompts();
|
|
81871
82555
|
init_mcp();
|
|
81872
82556
|
init_RetryManager();
|
|
81873
82557
|
init_FallbackManager();
|
|
@@ -81889,6 +82573,7 @@ var init_ProbeAgent = __esm({
|
|
|
81889
82573
|
* @param {Object} options - Configuration options
|
|
81890
82574
|
* @param {string} [options.sessionId] - Optional session ID
|
|
81891
82575
|
* @param {string} [options.customPrompt] - Custom prompt to replace the default system message
|
|
82576
|
+
* @param {string} [options.systemPrompt] - Alias for customPrompt; takes precedence when both are provided
|
|
81892
82577
|
* @param {string} [options.promptType] - Predefined prompt type (architect, code-review, support)
|
|
81893
82578
|
* @param {boolean} [options.allowEdit=false] - Allow the use of the 'implement' tool
|
|
81894
82579
|
* @param {boolean} [options.enableDelegate=false] - Enable the delegate tool for task distribution to subagents
|
|
@@ -81923,8 +82608,8 @@ var init_ProbeAgent = __esm({
|
|
|
81923
82608
|
* @param {number} [options.fallback.maxTotalAttempts=10] - Maximum total attempts across all providers
|
|
81924
82609
|
*/
|
|
81925
82610
|
constructor(options = {}) {
|
|
81926
|
-
this.sessionId = options.sessionId || (0,
|
|
81927
|
-
this.customPrompt = options.customPrompt || null;
|
|
82611
|
+
this.sessionId = options.sessionId || (0, import_crypto7.randomUUID)();
|
|
82612
|
+
this.customPrompt = options.systemPrompt || options.customPrompt || null;
|
|
81928
82613
|
this.promptType = options.promptType || "code-explorer";
|
|
81929
82614
|
this.allowEdit = !!options.allowEdit;
|
|
81930
82615
|
this.enableDelegate = !!options.enableDelegate;
|
|
@@ -82048,9 +82733,10 @@ var init_ProbeAgent = __esm({
|
|
|
82048
82733
|
* This method initializes MCP and merges MCP tools into the tool list, and loads history from storage
|
|
82049
82734
|
*/
|
|
82050
82735
|
async initialize() {
|
|
82051
|
-
if (!this.provider && !this.clientApiProvider && this.apiType !== "claude-code") {
|
|
82736
|
+
if (!this.provider && !this.clientApiProvider && this.apiType !== "claude-code" && this.apiType !== "codex") {
|
|
82052
82737
|
if (this.apiType === "uninitialized") {
|
|
82053
82738
|
const claudeAvailable = await this.isClaudeCommandAvailable();
|
|
82739
|
+
const codexAvailable = await this.isCodexCommandAvailable();
|
|
82054
82740
|
if (claudeAvailable) {
|
|
82055
82741
|
if (this.debug) {
|
|
82056
82742
|
console.log("[DEBUG] No API keys found, but claude command detected");
|
|
@@ -82060,8 +82746,17 @@ var init_ProbeAgent = __esm({
|
|
|
82060
82746
|
this.provider = null;
|
|
82061
82747
|
this.model = this.clientApiModel || "claude-3-5-sonnet-20241022";
|
|
82062
82748
|
this.apiType = "claude-code";
|
|
82749
|
+
} else if (codexAvailable) {
|
|
82750
|
+
if (this.debug) {
|
|
82751
|
+
console.log("[DEBUG] No API keys found, but codex command detected");
|
|
82752
|
+
console.log("[DEBUG] Auto-switching to codex provider");
|
|
82753
|
+
}
|
|
82754
|
+
this.clientApiProvider = "codex";
|
|
82755
|
+
this.provider = null;
|
|
82756
|
+
this.model = this.clientApiModel || "gpt-4o";
|
|
82757
|
+
this.apiType = "codex";
|
|
82063
82758
|
} else {
|
|
82064
|
-
throw new Error("No API key provided and claude command
|
|
82759
|
+
throw new Error("No API key provided and neither claude nor codex command found. Please either:\n1. Set an API key: ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY, or AWS credentials\n2. Install claude command from https://docs.claude.com/en/docs/claude-code\n3. Install codex command from https://openai.com/codex");
|
|
82065
82760
|
}
|
|
82066
82761
|
}
|
|
82067
82762
|
}
|
|
@@ -82183,13 +82878,33 @@ var init_ProbeAgent = __esm({
|
|
|
82183
82878
|
}
|
|
82184
82879
|
/**
|
|
82185
82880
|
* Check if claude command is available on the system
|
|
82881
|
+
* Uses execFile instead of exec to avoid shell injection risks
|
|
82186
82882
|
* @returns {Promise<boolean>} True if claude command is available
|
|
82187
82883
|
* @private
|
|
82188
82884
|
*/
|
|
82189
82885
|
async isClaudeCommandAvailable() {
|
|
82190
82886
|
try {
|
|
82191
|
-
const {
|
|
82192
|
-
|
|
82887
|
+
const { execFile: execFile3 } = await import("child_process");
|
|
82888
|
+
const { promisify: promisify8 } = await import("util");
|
|
82889
|
+
const execFileAsync3 = promisify8(execFile3);
|
|
82890
|
+
await execFileAsync3("claude", ["--version"], { timeout: 5e3 });
|
|
82891
|
+
return true;
|
|
82892
|
+
} catch (error2) {
|
|
82893
|
+
return false;
|
|
82894
|
+
}
|
|
82895
|
+
}
|
|
82896
|
+
/**
|
|
82897
|
+
* Check if codex command is available on the system
|
|
82898
|
+
* Uses execFile instead of exec to avoid shell injection risks
|
|
82899
|
+
* @returns {Promise<boolean>} True if codex command is available
|
|
82900
|
+
* @private
|
|
82901
|
+
*/
|
|
82902
|
+
async isCodexCommandAvailable() {
|
|
82903
|
+
try {
|
|
82904
|
+
const { execFile: execFile3 } = await import("child_process");
|
|
82905
|
+
const { promisify: promisify8 } = await import("util");
|
|
82906
|
+
const execFileAsync3 = promisify8(execFile3);
|
|
82907
|
+
await execFileAsync3("codex", ["--version"], { timeout: 5e3 });
|
|
82193
82908
|
return true;
|
|
82194
82909
|
} catch (error2) {
|
|
82195
82910
|
return false;
|
|
@@ -82213,6 +82928,20 @@ var init_ProbeAgent = __esm({
|
|
|
82213
82928
|
}
|
|
82214
82929
|
return;
|
|
82215
82930
|
}
|
|
82931
|
+
if (this.clientApiProvider === "codex" || process.env.USE_CODEX === "true") {
|
|
82932
|
+
this.provider = null;
|
|
82933
|
+
this.model = modelName || null;
|
|
82934
|
+
this.apiType = "codex";
|
|
82935
|
+
if (this.debug) {
|
|
82936
|
+
console.log("[DEBUG] Codex CLI engine selected - will use built-in access if available");
|
|
82937
|
+
if (this.model) {
|
|
82938
|
+
console.log(`[DEBUG] Using model: ${this.model}`);
|
|
82939
|
+
} else {
|
|
82940
|
+
console.log("[DEBUG] Using Codex account default model");
|
|
82941
|
+
}
|
|
82942
|
+
}
|
|
82943
|
+
return;
|
|
82944
|
+
}
|
|
82216
82945
|
const anthropicApiKey = process.env.ANTHROPIC_API_KEY || process.env.ANTHROPIC_AUTH_TOKEN;
|
|
82217
82946
|
const openaiApiKey = process.env.OPENAI_API_KEY;
|
|
82218
82947
|
const googleApiKey = process.env.GOOGLE_GENERATIVE_AI_API_KEY || process.env.GOOGLE_API_KEY;
|
|
@@ -82374,6 +83103,44 @@ var init_ProbeAgent = __esm({
|
|
|
82374
83103
|
}
|
|
82375
83104
|
}
|
|
82376
83105
|
}
|
|
83106
|
+
if (this.clientApiProvider === "codex" || process.env.USE_CODEX === "true") {
|
|
83107
|
+
try {
|
|
83108
|
+
const engine = await this.getEngine();
|
|
83109
|
+
if (engine && engine.query) {
|
|
83110
|
+
const userMessages = options.messages.filter(
|
|
83111
|
+
(m4) => m4.role === "user" && !m4.content.includes("WARNING: You have reached the maximum tool iterations limit")
|
|
83112
|
+
);
|
|
83113
|
+
const lastUserMessage = userMessages[userMessages.length - 1];
|
|
83114
|
+
const prompt = lastUserMessage ? lastUserMessage.content : "";
|
|
83115
|
+
const engineOptions = {
|
|
83116
|
+
maxTokens: options.maxTokens,
|
|
83117
|
+
temperature: options.temperature,
|
|
83118
|
+
messages: options.messages,
|
|
83119
|
+
systemPrompt: options.messages.find((m4) => m4.role === "system")?.content
|
|
83120
|
+
};
|
|
83121
|
+
const engineStream = engine.query(prompt, engineOptions);
|
|
83122
|
+
async function* createTextStream() {
|
|
83123
|
+
for await (const message of engineStream) {
|
|
83124
|
+
if (message.type === "text" && message.content) {
|
|
83125
|
+
yield message.content;
|
|
83126
|
+
} else if (typeof message === "string") {
|
|
83127
|
+
yield message;
|
|
83128
|
+
}
|
|
83129
|
+
}
|
|
83130
|
+
}
|
|
83131
|
+
return {
|
|
83132
|
+
textStream: createTextStream(),
|
|
83133
|
+
usage: Promise.resolve({})
|
|
83134
|
+
// Engine should handle its own usage tracking
|
|
83135
|
+
// Add other streamText-compatible properties as needed
|
|
83136
|
+
};
|
|
83137
|
+
}
|
|
83138
|
+
} catch (error2) {
|
|
83139
|
+
if (this.debug) {
|
|
83140
|
+
console.log(`[DEBUG] Failed to use Codex engine, falling back to Vercel:`, error2.message);
|
|
83141
|
+
}
|
|
83142
|
+
}
|
|
83143
|
+
}
|
|
82377
83144
|
if (!this.retryManager) {
|
|
82378
83145
|
this.retryManager = new RetryManager({
|
|
82379
83146
|
maxRetries: this.retryConfig.maxRetries ?? 3,
|
|
@@ -82526,6 +83293,35 @@ var init_ProbeAgent = __esm({
|
|
|
82526
83293
|
this.clientApiProvider = null;
|
|
82527
83294
|
}
|
|
82528
83295
|
}
|
|
83296
|
+
if (this.clientApiProvider === "codex" || process.env.USE_CODEX === "true") {
|
|
83297
|
+
try {
|
|
83298
|
+
const { createCodexEngine: createCodexEngine2 } = await Promise.resolve().then(() => (init_codex(), codex_exports));
|
|
83299
|
+
const systemPrompt = this.customPrompt || this.getCodexNativeSystemPrompt();
|
|
83300
|
+
this.engine = await createCodexEngine2({
|
|
83301
|
+
agent: this,
|
|
83302
|
+
// Pass reference to ProbeAgent for tool access
|
|
83303
|
+
systemPrompt,
|
|
83304
|
+
customPrompt: this.customPrompt,
|
|
83305
|
+
sessionId: this.options?.sessionId,
|
|
83306
|
+
debug: this.debug,
|
|
83307
|
+
allowedTools: this.allowedTools,
|
|
83308
|
+
// Pass tool filtering configuration
|
|
83309
|
+
model: this.model
|
|
83310
|
+
// Pass model name (e.g., gpt-4o, o3, etc.)
|
|
83311
|
+
});
|
|
83312
|
+
if (this.debug) {
|
|
83313
|
+
console.log("[DEBUG] Using Codex CLI engine with Probe tools");
|
|
83314
|
+
if (this.customPrompt) {
|
|
83315
|
+
console.log("[DEBUG] Using custom prompt/persona");
|
|
83316
|
+
}
|
|
83317
|
+
}
|
|
83318
|
+
return this.engine;
|
|
83319
|
+
} catch (error2) {
|
|
83320
|
+
console.warn("[WARNING] Failed to load Codex CLI engine:", error2.message);
|
|
83321
|
+
console.warn("[WARNING] Falling back to Vercel AI SDK");
|
|
83322
|
+
this.clientApiProvider = null;
|
|
83323
|
+
}
|
|
83324
|
+
}
|
|
82529
83325
|
const { createEnhancedVercelEngine: createEnhancedVercelEngine2 } = await Promise.resolve().then(() => (init_enhanced_vercel(), enhanced_vercel_exports));
|
|
82530
83326
|
this.engine = createEnhancedVercelEngine2(this);
|
|
82531
83327
|
if (this.debug) {
|
|
@@ -82533,6 +83329,32 @@ var init_ProbeAgent = __esm({
|
|
|
82533
83329
|
}
|
|
82534
83330
|
return this.engine;
|
|
82535
83331
|
}
|
|
83332
|
+
/**
|
|
83333
|
+
* Get session information including thread ID for resumability
|
|
83334
|
+
* @returns {Object} Session info with sessionId, threadId, messageCount
|
|
83335
|
+
*/
|
|
83336
|
+
getSessionInfo() {
|
|
83337
|
+
if (this.engine && this.engine.getSession) {
|
|
83338
|
+
return this.engine.getSession();
|
|
83339
|
+
}
|
|
83340
|
+
return {
|
|
83341
|
+
id: this.sessionId,
|
|
83342
|
+
threadId: null,
|
|
83343
|
+
messageCount: 0
|
|
83344
|
+
};
|
|
83345
|
+
}
|
|
83346
|
+
/**
|
|
83347
|
+
* Close the agent and clean up resources (e.g., MCP servers)
|
|
83348
|
+
* @returns {Promise<void>}
|
|
83349
|
+
*/
|
|
83350
|
+
async close() {
|
|
83351
|
+
if (this.engine && this.engine.close) {
|
|
83352
|
+
await this.engine.close();
|
|
83353
|
+
}
|
|
83354
|
+
if (this.mcpBridge) {
|
|
83355
|
+
this.mcpBridge = null;
|
|
83356
|
+
}
|
|
83357
|
+
}
|
|
82536
83358
|
/**
|
|
82537
83359
|
* Process assistant response content and detect/load image references
|
|
82538
83360
|
* @param {string} content - The assistant's response content
|
|
@@ -82825,11 +83647,61 @@ var init_ProbeAgent = __esm({
|
|
|
82825
83647
|
*/
|
|
82826
83648
|
getClaudeNativeSystemPrompt() {
|
|
82827
83649
|
let systemPrompt = "";
|
|
82828
|
-
if (this.
|
|
82829
|
-
|
|
82830
|
-
|
|
82831
|
-
|
|
82832
|
-
|
|
83650
|
+
if (this.customPrompt) {
|
|
83651
|
+
systemPrompt += this.customPrompt + "\n\n";
|
|
83652
|
+
} else if (this.promptType && predefinedPrompts[this.promptType]) {
|
|
83653
|
+
systemPrompt += predefinedPrompts[this.promptType] + "\n\n";
|
|
83654
|
+
} else {
|
|
83655
|
+
systemPrompt += predefinedPrompts["code-explorer"] + "\n\n";
|
|
83656
|
+
}
|
|
83657
|
+
systemPrompt += `You have access to powerful code search and analysis tools through MCP:
|
|
83658
|
+
- search: Find code patterns using semantic search
|
|
83659
|
+
- extract: Extract specific code sections with context
|
|
83660
|
+
- query: Use AST patterns for structural code matching
|
|
83661
|
+
- listFiles: Browse directory contents
|
|
83662
|
+
- searchFiles: Find files by name patterns`;
|
|
83663
|
+
if (this.enableBash) {
|
|
83664
|
+
systemPrompt += `
|
|
83665
|
+
- bash: Execute bash commands for system operations`;
|
|
83666
|
+
}
|
|
83667
|
+
systemPrompt += `
|
|
83668
|
+
|
|
83669
|
+
When exploring code:
|
|
83670
|
+
1. Start with search to find relevant code patterns
|
|
83671
|
+
2. Use extract to get detailed context when needed
|
|
83672
|
+
3. Prefer focused, specific searches over broad queries
|
|
83673
|
+
4. Combine multiple tools to build complete understanding`;
|
|
83674
|
+
if (this.allowedFolders && this.allowedFolders.length > 0) {
|
|
83675
|
+
systemPrompt += `
|
|
83676
|
+
|
|
83677
|
+
Workspace: ${this.allowedFolders.join(", ")}`;
|
|
83678
|
+
}
|
|
83679
|
+
if (this.fileList) {
|
|
83680
|
+
systemPrompt += `
|
|
83681
|
+
|
|
83682
|
+
# Repository Structure
|
|
83683
|
+
`;
|
|
83684
|
+
systemPrompt += `You are working with a repository located at: ${this.allowedFolders[0]}
|
|
83685
|
+
|
|
83686
|
+
`;
|
|
83687
|
+
systemPrompt += `Here's an overview of the repository structure (showing up to 100 most relevant files):
|
|
83688
|
+
|
|
83689
|
+
`;
|
|
83690
|
+
systemPrompt += "```\n" + this.fileList + "\n```\n";
|
|
83691
|
+
}
|
|
83692
|
+
return systemPrompt;
|
|
83693
|
+
}
|
|
83694
|
+
/**
|
|
83695
|
+
* Get system prompt for Codex CLI (similar to Claude but optimized for Codex)
|
|
83696
|
+
*/
|
|
83697
|
+
getCodexNativeSystemPrompt() {
|
|
83698
|
+
let systemPrompt = "";
|
|
83699
|
+
if (this.customPrompt) {
|
|
83700
|
+
systemPrompt += this.customPrompt + "\n\n";
|
|
83701
|
+
} else if (this.promptType && predefinedPrompts[this.promptType]) {
|
|
83702
|
+
systemPrompt += predefinedPrompts[this.promptType] + "\n\n";
|
|
83703
|
+
} else {
|
|
83704
|
+
systemPrompt += predefinedPrompts["code-explorer"] + "\n\n";
|
|
82833
83705
|
}
|
|
82834
83706
|
systemPrompt += `You have access to powerful code search and analysis tools through MCP:
|
|
82835
83707
|
- search: Find code patterns using semantic search
|
|
@@ -83025,7 +83897,7 @@ Follow these instructions carefully:
|
|
|
83025
83897
|
- Use 'create' for new files or complete file rewrites` : ""}
|
|
83026
83898
|
</instructions>
|
|
83027
83899
|
`;
|
|
83028
|
-
const
|
|
83900
|
+
const predefinedPrompts2 = {
|
|
83029
83901
|
"code-explorer": `You are ProbeChat Code Explorer, a specialized AI assistant focused on helping developers, product managers, and QAs understand and navigate codebases. Your primary function is to answer questions based on code, explain how systems work, and provide insights into code functionality using the provided code analysis tools.
|
|
83030
83902
|
|
|
83031
83903
|
When exploring code:
|
|
@@ -83081,14 +83953,14 @@ When troubleshooting:
|
|
|
83081
83953
|
if (this.debug) {
|
|
83082
83954
|
console.log(`[DEBUG] Using custom prompt`);
|
|
83083
83955
|
}
|
|
83084
|
-
} else if (this.promptType &&
|
|
83085
|
-
systemMessage = "<role>" +
|
|
83956
|
+
} else if (this.promptType && predefinedPrompts2[this.promptType]) {
|
|
83957
|
+
systemMessage = "<role>" + predefinedPrompts2[this.promptType] + "</role>";
|
|
83086
83958
|
if (this.debug) {
|
|
83087
83959
|
console.log(`[DEBUG] Using predefined prompt: ${this.promptType}`);
|
|
83088
83960
|
}
|
|
83089
83961
|
systemMessage += commonInstructions;
|
|
83090
83962
|
} else {
|
|
83091
|
-
systemMessage = "<role>" +
|
|
83963
|
+
systemMessage = "<role>" + predefinedPrompts2["code-explorer"] + "</role>";
|
|
83092
83964
|
if (this.debug) {
|
|
83093
83965
|
console.log(`[DEBUG] Using default prompt: code explorer`);
|
|
83094
83966
|
}
|
|
@@ -83229,6 +84101,7 @@ You are working with a repository located at: ${searchDirectory}
|
|
|
83229
84101
|
const baseMaxIterations = this.maxIterations || MAX_TOOL_ITERATIONS;
|
|
83230
84102
|
const maxIterations = options.schema ? baseMaxIterations + 4 : baseMaxIterations;
|
|
83231
84103
|
const isClaudeCode = this.clientApiProvider === "claude-code" || process.env.USE_CLAUDE_CODE === "true";
|
|
84104
|
+
const isCodex = this.clientApiProvider === "codex" || process.env.USE_CODEX === "true";
|
|
83232
84105
|
if (isClaudeCode) {
|
|
83233
84106
|
if (this.debug) {
|
|
83234
84107
|
console.log(`[DEBUG] Using Claude Code engine - bypassing tool loop (black box mode)`);
|
|
@@ -83281,6 +84154,58 @@ You are working with a repository located at: ${searchDirectory}
|
|
|
83281
84154
|
throw error2;
|
|
83282
84155
|
}
|
|
83283
84156
|
}
|
|
84157
|
+
if (isCodex) {
|
|
84158
|
+
if (this.debug) {
|
|
84159
|
+
console.log(`[DEBUG] Using Codex engine - bypassing tool loop (black box mode)`);
|
|
84160
|
+
console.log(`[DEBUG] Sending question directly to Codex: ${message.substring(0, 100)}...`);
|
|
84161
|
+
}
|
|
84162
|
+
try {
|
|
84163
|
+
const engine = await this.getEngine();
|
|
84164
|
+
if (engine && engine.query) {
|
|
84165
|
+
let assistantResponseContent = "";
|
|
84166
|
+
let toolBatch = null;
|
|
84167
|
+
for await (const chunk of engine.query(message, options)) {
|
|
84168
|
+
if (chunk.type === "text" && chunk.content) {
|
|
84169
|
+
assistantResponseContent += chunk.content;
|
|
84170
|
+
if (options.onStream) {
|
|
84171
|
+
options.onStream(chunk.content);
|
|
84172
|
+
}
|
|
84173
|
+
} else if (chunk.type === "toolBatch" && chunk.tools) {
|
|
84174
|
+
toolBatch = chunk.tools;
|
|
84175
|
+
if (this.debug) {
|
|
84176
|
+
console.log(`[DEBUG] Received batch of ${chunk.tools.length} tool events from Codex`);
|
|
84177
|
+
}
|
|
84178
|
+
} else if (chunk.type === "error") {
|
|
84179
|
+
throw chunk.error;
|
|
84180
|
+
}
|
|
84181
|
+
}
|
|
84182
|
+
if (toolBatch && toolBatch.length > 0 && this.events) {
|
|
84183
|
+
if (this.debug) {
|
|
84184
|
+
console.log(`[DEBUG] Emitting ${toolBatch.length} tool events from Codex batch`);
|
|
84185
|
+
}
|
|
84186
|
+
for (const toolEvent of toolBatch) {
|
|
84187
|
+
this.events.emit("toolCall", toolEvent);
|
|
84188
|
+
}
|
|
84189
|
+
}
|
|
84190
|
+
this.history.push(userMessage);
|
|
84191
|
+
this.history.push({
|
|
84192
|
+
role: "assistant",
|
|
84193
|
+
content: assistantResponseContent
|
|
84194
|
+
});
|
|
84195
|
+
await this.hooks.emit(HOOK_TYPES.COMPLETION, {
|
|
84196
|
+
sessionId: this.sessionId,
|
|
84197
|
+
prompt: message,
|
|
84198
|
+
response: assistantResponseContent
|
|
84199
|
+
});
|
|
84200
|
+
return assistantResponseContent;
|
|
84201
|
+
}
|
|
84202
|
+
} catch (error2) {
|
|
84203
|
+
if (this.debug) {
|
|
84204
|
+
console.error("[DEBUG] Codex error:", error2);
|
|
84205
|
+
}
|
|
84206
|
+
throw error2;
|
|
84207
|
+
}
|
|
84208
|
+
}
|
|
83284
84209
|
if (this.debug) {
|
|
83285
84210
|
console.log(`[DEBUG] Starting agentic flow for question: ${message.substring(0, 100)}...`);
|
|
83286
84211
|
if (options.schema) {
|
|
@@ -84161,7 +85086,7 @@ Convert your previous response content into actual JSON data that follows this s
|
|
|
84161
85086
|
*/
|
|
84162
85087
|
clone(options = {}) {
|
|
84163
85088
|
const {
|
|
84164
|
-
sessionId = (0,
|
|
85089
|
+
sessionId = (0, import_crypto7.randomUUID)(),
|
|
84165
85090
|
stripInternalMessages = true,
|
|
84166
85091
|
keepSystemMessage = true,
|
|
84167
85092
|
deepCopy = true,
|
|
@@ -84378,7 +85303,7 @@ async function delegate({
|
|
|
84378
85303
|
if (!task || typeof task !== "string") {
|
|
84379
85304
|
throw new Error("Task parameter is required and must be a string");
|
|
84380
85305
|
}
|
|
84381
|
-
const sessionId = (0,
|
|
85306
|
+
const sessionId = (0, import_crypto8.randomUUID)();
|
|
84382
85307
|
const startTime = Date.now();
|
|
84383
85308
|
const remainingIterations = Math.max(1, maxIterations - currentIteration);
|
|
84384
85309
|
const delegationSpan = tracer ? tracer.createDelegationSpan(sessionId, task) : null;
|
|
@@ -84506,11 +85431,11 @@ async function delegate({
|
|
|
84506
85431
|
throw new Error(`Delegation failed: ${error2.message}`);
|
|
84507
85432
|
}
|
|
84508
85433
|
}
|
|
84509
|
-
var
|
|
85434
|
+
var import_crypto8, DelegationManager, delegationManager;
|
|
84510
85435
|
var init_delegate = __esm({
|
|
84511
85436
|
"src/delegate.js"() {
|
|
84512
85437
|
"use strict";
|
|
84513
|
-
|
|
85438
|
+
import_crypto8 = require("crypto");
|
|
84514
85439
|
init_ProbeAgent();
|
|
84515
85440
|
DelegationManager = class {
|
|
84516
85441
|
constructor() {
|
|
@@ -84733,8 +85658,8 @@ var init_vercel = __esm({
|
|
|
84733
85658
|
const { writeFileSync: writeFileSync2, unlinkSync } = await import("fs");
|
|
84734
85659
|
const { join: join3 } = await import("path");
|
|
84735
85660
|
const { tmpdir } = await import("os");
|
|
84736
|
-
const { randomUUID:
|
|
84737
|
-
tempFilePath = join3(tmpdir(), `probe-extract-${
|
|
85661
|
+
const { randomUUID: randomUUID6 } = await import("crypto");
|
|
85662
|
+
tempFilePath = join3(tmpdir(), `probe-extract-${randomUUID6()}.txt`);
|
|
84738
85663
|
writeFileSync2(tempFilePath, input_content);
|
|
84739
85664
|
if (debug) {
|
|
84740
85665
|
console.error(`Created temporary file for input content: ${tempFilePath}`);
|
|
@@ -85716,7 +86641,7 @@ async function executeBashCommand(command, options = {}) {
|
|
|
85716
86641
|
return;
|
|
85717
86642
|
}
|
|
85718
86643
|
const [cmd, ...cmdArgs] = args;
|
|
85719
|
-
const child = (0,
|
|
86644
|
+
const child = (0, import_child_process9.spawn)(cmd, cmdArgs, {
|
|
85720
86645
|
cwd,
|
|
85721
86646
|
env: processEnv,
|
|
85722
86647
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -85900,11 +86825,11 @@ function validateExecutionOptions(options = {}) {
|
|
|
85900
86825
|
warnings
|
|
85901
86826
|
};
|
|
85902
86827
|
}
|
|
85903
|
-
var
|
|
86828
|
+
var import_child_process9, import_path8, import_fs6;
|
|
85904
86829
|
var init_bashExecutor = __esm({
|
|
85905
86830
|
"src/agent/bashExecutor.js"() {
|
|
85906
86831
|
"use strict";
|
|
85907
|
-
|
|
86832
|
+
import_child_process9 = require("child_process");
|
|
85908
86833
|
import_path8 = require("path");
|
|
85909
86834
|
import_fs6 = require("fs");
|
|
85910
86835
|
init_bashCommandUtils();
|
|
@@ -86756,15 +87681,15 @@ function shouldIgnore(filePath, ignorePatterns) {
|
|
|
86756
87681
|
}
|
|
86757
87682
|
return false;
|
|
86758
87683
|
}
|
|
86759
|
-
var import_fs9, import_path11, import_util12,
|
|
87684
|
+
var import_fs9, import_path11, import_util12, import_child_process10, execAsync3;
|
|
86760
87685
|
var init_file_lister = __esm({
|
|
86761
87686
|
"src/utils/file-lister.js"() {
|
|
86762
87687
|
"use strict";
|
|
86763
87688
|
import_fs9 = __toESM(require("fs"), 1);
|
|
86764
87689
|
import_path11 = __toESM(require("path"), 1);
|
|
86765
87690
|
import_util12 = require("util");
|
|
86766
|
-
|
|
86767
|
-
execAsync3 = (0, import_util12.promisify)(
|
|
87691
|
+
import_child_process10 = require("child_process");
|
|
87692
|
+
execAsync3 = (0, import_util12.promisify)(import_child_process10.exec);
|
|
86768
87693
|
}
|
|
86769
87694
|
});
|
|
86770
87695
|
|