pentesting 0.1.9 → 0.1.10

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 (2) hide show
  1. package/dist/index.js +160 -119
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1840,6 +1840,93 @@ async function searchExploits(query) {
1840
1840
  return searchDuckDuckGo(`${query} site:exploit-db.com OR site:github.com exploit`);
1841
1841
  }
1842
1842
 
1843
+ // src/config/agent-constants.ts
1844
+ var AGENT_STATUS = {
1845
+ IDLE: "idle",
1846
+ RUNNING: "running",
1847
+ PAUSED: "paused",
1848
+ STUCK: "stuck",
1849
+ WAITING_INPUT: "waiting_input",
1850
+ COMPLETED: "completed"
1851
+ };
1852
+ var PHASE_ID = {
1853
+ RECON: "recon",
1854
+ SCAN: "scan",
1855
+ ENUM: "enum",
1856
+ VULN: "vuln",
1857
+ EXPLOIT: "exploit",
1858
+ PRIVESC: "privesc",
1859
+ PIVOT: "pivot",
1860
+ PERSIST: "persist",
1861
+ EXFIL: "exfil",
1862
+ REPORT: "report"
1863
+ };
1864
+ var PHASE_STATUS = {
1865
+ PENDING: "pending",
1866
+ IN_PROGRESS: "in_progress",
1867
+ COMPLETED: "completed",
1868
+ FAILED: "failed",
1869
+ SKIPPED: "skipped"
1870
+ };
1871
+ var THOUGHT_TYPE = {
1872
+ OBSERVATION: "observation",
1873
+ HYPOTHESIS: "hypothesis",
1874
+ PLAN: "plan",
1875
+ ACTION: "action",
1876
+ RESULT: "result",
1877
+ REFLECTION: "reflection",
1878
+ STUCK: "stuck",
1879
+ BREAKTHROUGH: "breakthrough"
1880
+ };
1881
+ var AGENT_EVENT = {
1882
+ // Lifecycle
1883
+ PLUGINS_LOADED: "plugins_loaded",
1884
+ HOOKS_LOADED: "hooks_loaded",
1885
+ COMMANDS_LOADED: "commands_loaded",
1886
+ MCP_SERVER_ADDED: "mcp_server_added",
1887
+ // Execution
1888
+ ITERATION: "iteration",
1889
+ THOUGHT: "thought",
1890
+ RESPONSE: "response",
1891
+ TOOL_CALL: "tool_call",
1892
+ TOOL_RESULT: "tool_result",
1893
+ COMMAND_EXECUTE: "command_execute",
1894
+ // State changes
1895
+ TARGET_SET: "target_set",
1896
+ PHASE_CHANGE: "phase_change",
1897
+ AGENT_SWITCH: "agent_switch",
1898
+ PAUSED: "paused",
1899
+ RESUMED: "resumed",
1900
+ RESET: "reset",
1901
+ // Discoveries
1902
+ FINDING: "finding",
1903
+ CREDENTIAL: "credential",
1904
+ COMPROMISED: "compromised",
1905
+ // Completion
1906
+ COMPLETE: "complete",
1907
+ REPORT: "report",
1908
+ ERROR: "error",
1909
+ HINT_RECEIVED: "hint_received"
1910
+ };
1911
+ var CLI_COMMAND = {
1912
+ HELP: "help",
1913
+ TARGET: "target",
1914
+ START: "start",
1915
+ STOP: "stop",
1916
+ FINDINGS: "findings",
1917
+ CLEAR: "clear",
1918
+ EXIT: "exit"
1919
+ };
1920
+ var MESSAGE_TYPE = {
1921
+ USER: "user",
1922
+ ASSISTANT: "assistant",
1923
+ TOOL: "tool",
1924
+ THINKING: "thinking",
1925
+ ERROR: "error",
1926
+ SYSTEM: "system",
1927
+ RESULT: "result"
1928
+ };
1929
+
1843
1930
  // src/core/agent/autonomous-agent.ts
1844
1931
  function toContentBlockParam(block) {
1845
1932
  switch (block.type) {
@@ -1923,36 +2010,36 @@ var AutonomousHackingAgent = class extends EventEmitter3 {
1923
2010
  try {
1924
2011
  const agentsDir = new URL("../../../../plugins/pentesting-core/agents", import.meta.url).pathname;
1925
2012
  this.pluginAgents = await loadAllAgents(agentsDir);
1926
- this.emit("plugins_loaded", { agents: this.pluginAgents.length });
2013
+ this.emit(AGENT_EVENT.PLUGINS_LOADED, { agents: this.pluginAgents.length });
1927
2014
  await this.hookExecutor.initialize();
1928
- this.emit("hooks_loaded");
2015
+ this.emit(AGENT_EVENT.HOOKS_LOADED);
1929
2016
  await this.commandRegistry.initialize();
1930
- this.emit("commands_loaded");
2017
+ this.emit(AGENT_EVENT.COMMANDS_LOADED);
1931
2018
  } catch {
1932
2019
  }
1933
2020
  }
1934
2021
  // Add MCP server at runtime
1935
2022
  async addMCPServer(name, command, args) {
1936
2023
  await this.mcpManager.addServer(name, { command, args });
1937
- this.emit("mcp_server_added", { name });
2024
+ this.emit(AGENT_EVENT.MCP_SERVER_ADDED, { name });
1938
2025
  }
1939
2026
  // Web search capabilities
1940
2027
  async webSearch(query) {
1941
- this.think("observation", `Web search: ${query}`);
2028
+ this.think(THOUGHT_TYPE.OBSERVATION, `Web search: ${query}`);
1942
2029
  const results = await searchDuckDuckGo(query);
1943
- this.think("result", `Found ${results.length} results`);
2030
+ this.think(THOUGHT_TYPE.RESULT, `Found ${results.length} results`);
1944
2031
  return results;
1945
2032
  }
1946
2033
  async searchForCVE(query) {
1947
- this.think("observation", `CVE search: ${query}`);
2034
+ this.think(THOUGHT_TYPE.OBSERVATION, `CVE search: ${query}`);
1948
2035
  const results = await searchCVE(query);
1949
- this.think("result", `Found ${results.length} CVE results`);
2036
+ this.think(THOUGHT_TYPE.RESULT, `Found ${results.length} CVE results`);
1950
2037
  return results;
1951
2038
  }
1952
2039
  async searchForExploits(query) {
1953
- this.think("observation", `Exploit search: ${query}`);
2040
+ this.think(THOUGHT_TYPE.OBSERVATION, `Exploit search: ${query}`);
1954
2041
  const results = await searchExploits(query);
1955
- this.think("result", `Found ${results.length} exploit results`);
2042
+ this.think(THOUGHT_TYPE.RESULT, `Found ${results.length} exploit results`);
1956
2043
  return results;
1957
2044
  }
1958
2045
  // Process slash command
@@ -1964,8 +2051,8 @@ var AutonomousHackingAgent = class extends EventEmitter3 {
1964
2051
  return `Unknown command: /${parsed.command}
1965
2052
  ${await this.commandRegistry.getHelp()}`;
1966
2053
  }
1967
- this.think("plan", `Executing command: /${cmd.name}`);
1968
- this.emit("command_execute", { command: cmd.name, args: parsed.rawArgs });
2054
+ this.think(THOUGHT_TYPE.PLAN, `Executing command: /${cmd.name}`);
2055
+ this.emit(AGENT_EVENT.COMMAND_EXECUTE, { command: cmd.name, args: parsed.rawArgs });
1969
2056
  return cmd.content;
1970
2057
  }
1971
2058
  // Switch to specialized agent
@@ -1975,8 +2062,8 @@ ${await this.commandRegistry.getHelp()}`;
1975
2062
  );
1976
2063
  if (agent) {
1977
2064
  this.currentAgent = agent;
1978
- this.think("plan", `Switching to specialized agent: ${agent.name}`);
1979
- this.emit("agent_switch", agent);
2065
+ this.think(THOUGHT_TYPE.PLAN, `Switching to specialized agent: ${agent.name}`);
2066
+ this.emit(AGENT_EVENT.AGENT_SWITCH, agent);
1980
2067
  return true;
1981
2068
  }
1982
2069
  return false;
@@ -1988,7 +2075,7 @@ ${await this.commandRegistry.getHelp()}`;
1988
2075
  // ===== State Management =====
1989
2076
  createInitialState() {
1990
2077
  return {
1991
- status: "idle",
2078
+ status: AGENT_STATUS.IDLE,
1992
2079
  target: {
1993
2080
  primary: "",
1994
2081
  discovered: [],
@@ -2015,7 +2102,7 @@ ${await this.commandRegistry.getHelp()}`;
2015
2102
  return { ...this.state };
2016
2103
  }
2017
2104
  getPhaseProgress() {
2018
- const completed = this.state.phases.filter((p) => p.status === "completed").length;
2105
+ const completed = this.state.phases.filter((p) => p.status === PHASE_STATUS.COMPLETED).length;
2019
2106
  return {
2020
2107
  completed,
2021
2108
  full: this.state.phases.length,
@@ -2032,13 +2119,13 @@ ${await this.commandRegistry.getHelp()}`;
2032
2119
  phase: this.state.currentPhase
2033
2120
  };
2034
2121
  this.state.thoughts.push(thought);
2035
- this.emit("thought", thought);
2122
+ this.emit(AGENT_EVENT.THOUGHT, thought);
2036
2123
  }
2037
2124
  // ===== Target Setting =====
2038
2125
  setTarget(target) {
2039
2126
  this.state.target.primary = target;
2040
- this.think("observation", `Target Setting: ${target}`);
2041
- this.emit("target_set", target);
2127
+ this.think(THOUGHT_TYPE.OBSERVATION, `Target Setting: ${target}`);
2128
+ this.emit(AGENT_EVENT.TARGET_SET, target);
2042
2129
  }
2043
2130
  // ===== Phase Management =====
2044
2131
  getCurrentPhase() {
@@ -2051,21 +2138,21 @@ ${await this.commandRegistry.getHelp()}`;
2051
2138
  phase.status = status;
2052
2139
  if (status === "in_progress" && !phase.startTime) {
2053
2140
  phase.startTime = /* @__PURE__ */ new Date();
2054
- } else if ((status === "completed" || status === "failed") && !phase.endTime) {
2141
+ } else if ((status === PHASE_STATUS.COMPLETED || status === PHASE_STATUS.FAILED) && !phase.endTime) {
2055
2142
  phase.endTime = /* @__PURE__ */ new Date();
2056
2143
  }
2057
- this.emit("phase_change", { phaseId, oldStatus, newStatus: status });
2058
- this.think("observation", `Phase status changed: ${phase.shortName} (${oldStatus} \u2192 ${status})`);
2144
+ this.emit(AGENT_EVENT.PHASE_CHANGE, { phaseId, oldStatus, newStatus: status });
2145
+ this.think(THOUGHT_TYPE.OBSERVATION, `Phase status changed: ${phase.shortName} (${oldStatus} \u2192 ${status})`);
2059
2146
  }
2060
2147
  }
2061
2148
  advanceToNextPhase() {
2062
2149
  const currentIndex = this.state.phases.findIndex((p) => p.id === this.state.currentPhase);
2063
2150
  if (currentIndex < this.state.phases.length - 1) {
2064
2151
  const nextPhase = this.state.phases[currentIndex + 1];
2065
- this.setPhaseStatus(this.state.currentPhase, "completed");
2152
+ this.setPhaseStatus(this.state.currentPhase, PHASE_STATUS.COMPLETED);
2066
2153
  this.state.currentPhase = nextPhase.id;
2067
2154
  this.setPhaseStatus(nextPhase.id, "in_progress");
2068
- this.think("plan", `Advancing to next phase: ${nextPhase.shortName}`);
2155
+ this.think(THOUGHT_TYPE.PLAN, `Advancing to next phase: ${nextPhase.shortName}`);
2069
2156
  this.resetStuckCounter();
2070
2157
  return true;
2071
2158
  }
@@ -2075,16 +2162,16 @@ ${await this.commandRegistry.getHelp()}`;
2075
2162
  checkIfStuck() {
2076
2163
  const currentPhase = this.getCurrentPhase();
2077
2164
  if (currentPhase.attempts > this.MAX_PHASE_ATTEMPTS) {
2078
- this.think("stuck", `[!] Rabbit hole detected: ${currentPhase.attempts} attempts in ${currentPhase.shortName} phase`);
2165
+ this.think(THOUGHT_TYPE.STUCK, `[!] Rabbit hole detected: ${currentPhase.attempts} attempts in ${currentPhase.shortName} phase`);
2079
2166
  return true;
2080
2167
  }
2081
2168
  const timeSinceProgress = Date.now() - this.state.lastProgressTime.getTime();
2082
2169
  if (timeSinceProgress > this.STUCK_TIME_THRESHOLD) {
2083
- this.think("stuck", `[!] Rabbit hole detected: No progress for ${Math.round(timeSinceProgress / 6e4)} minutes`);
2170
+ this.think(THOUGHT_TYPE.STUCK, `[!] Rabbit hole detected: No progress for ${Math.round(timeSinceProgress / 6e4)} minutes`);
2084
2171
  return true;
2085
2172
  }
2086
2173
  if (this.state.stuckCounter > this.STUCK_THRESHOLD) {
2087
- this.think("stuck", `[!] Rabbit hole detected: Same pattern ${this.state.stuckCounter} times repeated`);
2174
+ this.think(THOUGHT_TYPE.STUCK, `[!] Rabbit hole detected: Same pattern ${this.state.stuckCounter} times repeated`);
2088
2175
  return true;
2089
2176
  }
2090
2177
  return false;
@@ -2103,7 +2190,7 @@ ${await this.commandRegistry.getHelp()}`;
2103
2190
  }
2104
2191
  // ===== Self Reflection =====
2105
2192
  async performSelfReflection() {
2106
- this.think("reflection", "[reflect] Starting self-reflection...");
2193
+ this.think(THOUGHT_TYPE.REFLECTION, "[reflect] Starting self-reflection...");
2107
2194
  const reflectionPrompt = `
2108
2195
  ${SELF_REFLECTION_PROMPT}
2109
2196
 
@@ -2124,7 +2211,7 @@ What went wrong and what different approach should be tried?
2124
2211
  messages: [{ role: "user", content: reflectionPrompt }]
2125
2212
  });
2126
2213
  const reflection = response.content.filter((b) => b.type === "text").map((b) => b.text).join("\n");
2127
- this.think("reflection", reflection);
2214
+ this.think(THOUGHT_TYPE.REFLECTION, reflection);
2128
2215
  return reflection;
2129
2216
  }
2130
2217
  // ===== Progress Detection =====
@@ -2133,16 +2220,16 @@ What went wrong and what different approach should be tried?
2133
2220
  this.state.lastProgressTime = /* @__PURE__ */ new Date();
2134
2221
  switch (type) {
2135
2222
  case "discovery":
2136
- this.think("breakthrough", "[target] New target discovered!");
2223
+ this.think(THOUGHT_TYPE.BREAKTHROUGH, "[target] New target discovered!");
2137
2224
  break;
2138
2225
  case "credential":
2139
- this.think("breakthrough", "[cred] Credential obtained!");
2226
+ this.think(THOUGHT_TYPE.BREAKTHROUGH, "[cred] Credential obtained!");
2140
2227
  break;
2141
2228
  case "access":
2142
- this.think("breakthrough", "[access] Access obtained!");
2229
+ this.think(THOUGHT_TYPE.BREAKTHROUGH, "[access] Access obtained!");
2143
2230
  break;
2144
2231
  case "exploit":
2145
- this.think("breakthrough", "[exploit] Exploit successful!");
2232
+ this.think(THOUGHT_TYPE.BREAKTHROUGH, "[exploit] Exploit successful!");
2146
2233
  this.state.successfulExploits++;
2147
2234
  break;
2148
2235
  }
@@ -2156,7 +2243,7 @@ What went wrong and what different approach should be tried?
2156
2243
  };
2157
2244
  this.state.findings.push(newFinding);
2158
2245
  this.getCurrentPhase().findings.push(newFinding);
2159
- this.emit("finding", newFinding);
2246
+ this.emit(AGENT_EVENT.FINDING, newFinding);
2160
2247
  if (finding.severity === "critical" || finding.severity === "high") {
2161
2248
  this.recordProgress("discovery");
2162
2249
  }
@@ -2164,55 +2251,55 @@ What went wrong and what different approach should be tried?
2164
2251
  addCredential(cred) {
2165
2252
  this.state.target.credentials.push(cred);
2166
2253
  this.recordProgress("credential");
2167
- this.emit("credential", cred);
2168
- this.think("observation", `Credential obtained: ${cred.type} - ${cred.username || "unknown"}@${cred.source}`);
2254
+ this.emit(AGENT_EVENT.CREDENTIAL, cred);
2255
+ this.think(THOUGHT_TYPE.OBSERVATION, `Credential obtained: ${cred.type} - ${cred.username || "unknown"}@${cred.source}`);
2169
2256
  }
2170
2257
  addCompromisedHost(host) {
2171
2258
  if (!this.state.target.compromised.includes(host)) {
2172
2259
  this.state.target.compromised.push(host);
2173
2260
  this.recordProgress("access");
2174
- this.emit("compromised", host);
2175
- this.think("breakthrough", `Host compromised: ${host}`);
2261
+ this.emit(AGENT_EVENT.COMPROMISED, host);
2262
+ this.think(THOUGHT_TYPE.BREAKTHROUGH, `Host compromised: ${host}`);
2176
2263
  }
2177
2264
  }
2178
2265
  // ===== Main Autonomous Execution Loop =====
2179
2266
  async runAutonomous(objective) {
2180
2267
  if (!this.state.target.primary) {
2181
- this.emit("error", new Error("Target not set"));
2268
+ this.emit(AGENT_EVENT.ERROR, new Error("Target not set"));
2182
2269
  return;
2183
2270
  }
2184
- this.state.status = "running";
2271
+ this.state.status = AGENT_STATUS.RUNNING;
2185
2272
  this.setPhaseStatus("recon", "in_progress");
2186
2273
  const mainObjective = objective || `
2187
2274
  Target ${this.state.target.primary} - performing full penetration test.
2188
2275
  Goal: Deep penetration to obtain root/system privileges, extract internal data, map entire network.
2189
2276
  `;
2190
- this.think("plan", `Autonomous hacking started: ${mainObjective}`);
2277
+ this.think(THOUGHT_TYPE.PLAN, `Autonomous hacking started: ${mainObjective}`);
2191
2278
  this.state.history.push({
2192
2279
  role: "user",
2193
2280
  content: mainObjective
2194
2281
  });
2195
2282
  let iteration = 0;
2196
2283
  const maxIterations = this.config.maxIterations;
2197
- while (iteration < maxIterations && this.state.status === "running") {
2284
+ while (iteration < maxIterations && this.state.status === AGENT_STATUS.RUNNING) {
2198
2285
  iteration++;
2199
2286
  this.state.iteration = iteration;
2200
2287
  this.getCurrentPhase().attempts++;
2201
2288
  this.state.fullAttempts++;
2202
- this.emit("iteration", { current: iteration, max: maxIterations, phase: this.state.currentPhase });
2289
+ this.emit(AGENT_EVENT.ITERATION, { current: iteration, max: maxIterations, phase: this.state.currentPhase });
2203
2290
  try {
2204
2291
  if (this.checkIfStuck()) {
2205
- this.state.status = "stuck";
2292
+ this.state.status = AGENT_STATUS.STUCK;
2206
2293
  const reflection = await this.performSelfReflection();
2207
2294
  const shouldSkip = await this.decideNextAction(reflection);
2208
2295
  if (shouldSkip) {
2209
2296
  this.setPhaseStatus(this.state.currentPhase, "skipped");
2210
2297
  if (!this.advanceToNextPhase()) {
2211
- this.think("observation", "All phases completed or skipped");
2298
+ this.think(THOUGHT_TYPE.OBSERVATION, "All phases completed or skipped");
2212
2299
  break;
2213
2300
  }
2214
2301
  }
2215
- this.state.status = "running";
2302
+ this.state.status = AGENT_STATUS.RUNNING;
2216
2303
  this.resetStuckCounter();
2217
2304
  continue;
2218
2305
  }
@@ -2220,25 +2307,25 @@ Goal: Deep penetration to obtain root/system privileges, extract internal data,
2220
2307
  await this.analyzeResponse(response);
2221
2308
  if (this.shouldAdvancePhase()) {
2222
2309
  if (!this.advanceToNextPhase()) {
2223
- this.think("observation", "[done] All phases completed!");
2310
+ this.think(THOUGHT_TYPE.OBSERVATION, "[done] All phases completed!");
2224
2311
  break;
2225
2312
  }
2226
2313
  }
2227
2314
  } catch (error) {
2228
2315
  this.state.failedAttempts++;
2229
- this.think("result", `[-] Error: ${error.message}`);
2230
- this.emit("error", error);
2316
+ this.think(THOUGHT_TYPE.RESULT, `[-] Error: ${error.message}`);
2317
+ this.emit(AGENT_EVENT.ERROR, error);
2231
2318
  await this.attemptRecovery(error);
2232
2319
  }
2233
2320
  }
2234
- this.state.status = "completed";
2321
+ this.state.status = AGENT_STATUS.COMPLETED;
2235
2322
  await this.generateFinalReport();
2236
- this.emit("complete", this.getSummary());
2323
+ this.emit(AGENT_EVENT.COMPLETE, this.getSummary());
2237
2324
  }
2238
2325
  // ===== Step Execution =====
2239
2326
  async executeStep() {
2240
2327
  const contextPrompt = this.buildContextPrompt();
2241
- this.think("plan", "Deciding next action...");
2328
+ this.think(THOUGHT_TYPE.PLAN, "Deciding next action...");
2242
2329
  const historyMessages = this.state.history.map(toMessageParam);
2243
2330
  const messages = [
2244
2331
  ...historyMessages,
@@ -2266,7 +2353,7 @@ Goal: Deep penetration to obtain root/system privileges, extract internal data,
2266
2353
  === Current Status ===
2267
2354
  Target: ${this.state.target.primary}
2268
2355
  Current phase: ${phase.shortName} (${phase.name})
2269
- Phase progress: ${this.state.phases.filter((p) => p.status === "completed").length}/${this.state.phases.length}
2356
+ Phase progress: ${this.state.phases.filter((p) => p.status === PHASE_STATUS.COMPLETED).length}/${this.state.phases.length}
2270
2357
  Compromised hosts: ${this.state.target.compromised.join(", ") || "none"}
2271
2358
 
2272
2359
  === Discovered Services ===
@@ -2293,8 +2380,8 @@ Use report_finding tool for important discoveries.
2293
2380
  if (block.type === "text") {
2294
2381
  textResponse += block.text;
2295
2382
  contentBlocks.push({ type: "text", text: block.text });
2296
- this.think("observation", block.text.slice(0, 500));
2297
- this.emit("response", block.text);
2383
+ this.think(THOUGHT_TYPE.OBSERVATION, block.text.slice(0, 500));
2384
+ this.emit(AGENT_EVENT.RESPONSE, block.text);
2298
2385
  } else if (block.type === "tool_use") {
2299
2386
  const toolName = block.name;
2300
2387
  const toolInput = block.input;
@@ -2306,15 +2393,15 @@ Use report_finding tool for important discoveries.
2306
2393
  });
2307
2394
  const actionKey = `${toolName}:${JSON.stringify(toolInput).slice(0, 100)}`;
2308
2395
  this.trackAction(actionKey);
2309
- this.think("action", `[tool] Tool execution: ${toolName}`);
2310
- this.emit("tool_call", { id: block.id, name: toolName, input: toolInput });
2396
+ this.think(THOUGHT_TYPE.ACTION, `[tool] Tool execution: ${toolName}`);
2397
+ this.emit(AGENT_EVENT.TOOL_CALL, { id: block.id, name: toolName, input: toolInput });
2311
2398
  const result = await executeToolCall(toolName, toolInput);
2312
2399
  const resultType = result.success ? "result" : "result";
2313
2400
  this.think(
2314
2401
  resultType,
2315
2402
  result.success ? `[+] ${toolName} Success: ${result.output.slice(0, 200)}...` : `[-] ${toolName} Failed: ${result.error}`
2316
2403
  );
2317
- this.emit("tool_result", { id: block.id, name: toolName, result });
2404
+ this.emit(AGENT_EVENT.TOOL_RESULT, { id: block.id, name: toolName, result });
2318
2405
  this.extractIntelligence(toolName, result);
2319
2406
  this.state.history.push({
2320
2407
  role: "assistant",
@@ -2378,14 +2465,14 @@ Use report_finding tool for important discoveries.
2378
2465
  passwordPatterns.forEach((pattern) => {
2379
2466
  const matches = result.output.match(pattern);
2380
2467
  if (matches) {
2381
- this.think("observation", `Potential credentials found: ${matches.slice(0, 3).join(", ")}`);
2468
+ this.think(THOUGHT_TYPE.OBSERVATION, `Potential credentials found: ${matches.slice(0, 3).join(", ")}`);
2382
2469
  }
2383
2470
  });
2384
2471
  }
2385
2472
  const cveMatches = result.output.match(/CVE-\d{4}-\d+/gi);
2386
2473
  if (cveMatches) {
2387
2474
  cveMatches.forEach((cve) => {
2388
- this.think("observation", `CVE found: ${cve}`);
2475
+ this.think(THOUGHT_TYPE.OBSERVATION, `CVE found: ${cve}`);
2389
2476
  });
2390
2477
  }
2391
2478
  if (output.includes("meterpreter") || output.includes("shell session") || output.includes("www-data") || output.includes("uid=")) {
@@ -2431,11 +2518,11 @@ Use report_finding tool for important discoveries.
2431
2518
  }
2432
2519
  // ===== Recovery Attempt =====
2433
2520
  async attemptRecovery(error) {
2434
- this.think("reflection", `Attempting recovery: ${error.message}`);
2521
+ this.think(THOUGHT_TYPE.REFLECTION, `Attempting recovery: ${error.message}`);
2435
2522
  if (error.message.includes("timeout")) {
2436
- this.think("plan", "Timeout - retrying with shorter command");
2523
+ this.think(THOUGHT_TYPE.PLAN, "Timeout - retrying with shorter command");
2437
2524
  } else if (error.message.includes("permission")) {
2438
- this.think("plan", "Permission error - trying different approach");
2525
+ this.think(THOUGHT_TYPE.PLAN, "Permission error - trying different approach");
2439
2526
  }
2440
2527
  }
2441
2528
  // ===== Final Report Generation =====
@@ -2480,8 +2567,8 @@ ${this.state.phases.map((p) => `- **${p.shortName}**: ${p.status} (${p.attempts}
2480
2567
  Based on the findings, the following remediation steps are recommended:
2481
2568
  ${this.state.findings.filter((f) => f.severity !== "info").map((f) => `- Address: ${f.title}`).join("\n")}
2482
2569
  `;
2483
- this.setPhaseStatus("report", "completed");
2484
- this.emit("report", report);
2570
+ this.setPhaseStatus(PHASE_ID.REPORT, PHASE_STATUS.COMPLETED);
2571
+ this.emit(AGENT_EVENT.REPORT, report);
2485
2572
  return report;
2486
2573
  }
2487
2574
  // ===== Summary =====
@@ -2499,29 +2586,29 @@ ${this.state.findings.filter((f) => f.severity !== "info").map((f) => `- Address
2499
2586
  }
2500
2587
  // ===== User Hint Processing =====
2501
2588
  async processUserHint(hint) {
2502
- this.think("observation", `User hint: ${hint}`);
2589
+ this.think(THOUGHT_TYPE.OBSERVATION, `User hint: ${hint}`);
2503
2590
  this.state.history.push({
2504
2591
  role: "user",
2505
2592
  content: `[User hint] ${hint}`
2506
2593
  });
2507
2594
  this.resetStuckCounter();
2508
- this.emit("hint_received", hint);
2595
+ this.emit(AGENT_EVENT.HINT_RECEIVED, hint);
2509
2596
  }
2510
2597
  // ===== Pause/Resume =====
2511
2598
  pause() {
2512
- this.state.status = "paused";
2513
- this.emit("paused");
2599
+ this.state.status = AGENT_STATUS.PAUSED;
2600
+ this.emit(AGENT_EVENT.PAUSED);
2514
2601
  }
2515
2602
  resume() {
2516
- if (this.state.status === "paused") {
2517
- this.state.status = "running";
2518
- this.emit("resumed");
2603
+ if (this.state.status === AGENT_STATUS.PAUSED) {
2604
+ this.state.status = AGENT_STATUS.RUNNING;
2605
+ this.emit(AGENT_EVENT.RESUMED);
2519
2606
  }
2520
2607
  }
2521
2608
  // ===== Reset =====
2522
2609
  reset() {
2523
2610
  this.state = this.createInitialState();
2524
- this.emit("reset");
2611
+ this.emit(AGENT_EVENT.RESET);
2525
2612
  }
2526
2613
  };
2527
2614
 
@@ -2610,52 +2697,6 @@ var ASCII_BANNER = `
2610
2697
  \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D
2611
2698
  `;
2612
2699
 
2613
- // src/config/agent-constants.ts
2614
- var AGENT_EVENT = {
2615
- // Lifecycle
2616
- PLUGINS_LOADED: "plugins_loaded",
2617
- HOOKS_LOADED: "hooks_loaded",
2618
- COMMANDS_LOADED: "commands_loaded",
2619
- MCP_SERVER_ADDED: "mcp_server_added",
2620
- // Execution
2621
- ITERATION: "iteration",
2622
- THOUGHT: "thought",
2623
- RESPONSE: "response",
2624
- TOOL_CALL: "tool_call",
2625
- TOOL_RESULT: "tool_result",
2626
- COMMAND_EXECUTE: "command_execute",
2627
- // State changes
2628
- TARGET_SET: "target_set",
2629
- PHASE_CHANGE: "phase_change",
2630
- AGENT_SWITCH: "agent_switch",
2631
- // Discoveries
2632
- FINDING: "finding",
2633
- CREDENTIAL: "credential",
2634
- COMPROMISED: "compromised",
2635
- // Completion
2636
- COMPLETE: "complete",
2637
- REPORT: "report",
2638
- ERROR: "error"
2639
- };
2640
- var CLI_COMMAND = {
2641
- HELP: "help",
2642
- TARGET: "target",
2643
- START: "start",
2644
- STOP: "stop",
2645
- FINDINGS: "findings",
2646
- CLEAR: "clear",
2647
- EXIT: "exit"
2648
- };
2649
- var MESSAGE_TYPE = {
2650
- USER: "user",
2651
- ASSISTANT: "assistant",
2652
- TOOL: "tool",
2653
- THINKING: "thinking",
2654
- ERROR: "error",
2655
- SYSTEM: "system",
2656
- RESULT: "result"
2657
- };
2658
-
2659
2700
  // src/cli/app.tsx
2660
2701
  import { jsx, jsxs } from "react/jsx-runtime";
2661
2702
  var App = ({ autoApprove = false, target }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pentesting",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Autonomous Penetration Testing AI Agent",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",