pentesting 0.1.6 → 0.1.8

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 +142 -87
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { render } from "ink";
5
5
  import { Command } from "commander";
6
6
 
7
7
  // src/cli/app.tsx
8
- import { useState, useEffect, useCallback } from "react";
8
+ import { useState, useEffect, useCallback, useRef } from "react";
9
9
  import { Box, Text, useInput, useApp, Static } from "ink";
10
10
  import TextInput from "ink-text-input";
11
11
  import Spinner from "ink-spinner";
@@ -2617,40 +2617,75 @@ var App = ({ autoApprove = false, target }) => {
2617
2617
  const [messages, setMessages] = useState([]);
2618
2618
  const [input, setInput] = useState("");
2619
2619
  const [isProcessing, setIsProcessing] = useState(false);
2620
+ const [currentStatus, setCurrentStatus] = useState("");
2621
+ const [elapsedTime, setElapsedTime] = useState(0);
2620
2622
  const [agent] = useState(() => new AutonomousHackingAgent(void 0, { autoApprove }));
2621
- const addMessage = useCallback((type, content) => {
2623
+ const startTimeRef = useRef(0);
2624
+ const timerRef = useRef(null);
2625
+ const addMessage = useCallback((type, content, duration) => {
2622
2626
  setMessages((prev) => [...prev, {
2623
2627
  id: `${Date.now()}-${Math.random().toString(36).slice(2)}`,
2624
2628
  type,
2625
2629
  content,
2626
- timestamp: /* @__PURE__ */ new Date()
2630
+ timestamp: /* @__PURE__ */ new Date(),
2631
+ duration
2627
2632
  }]);
2628
2633
  }, []);
2634
+ const startTimer = useCallback(() => {
2635
+ startTimeRef.current = Date.now();
2636
+ timerRef.current = setInterval(() => {
2637
+ setElapsedTime(Math.floor((Date.now() - startTimeRef.current) / 100) / 10);
2638
+ }, 100);
2639
+ }, []);
2640
+ const stopTimer = useCallback(() => {
2641
+ if (timerRef.current) {
2642
+ clearInterval(timerRef.current);
2643
+ timerRef.current = null;
2644
+ }
2645
+ const duration = Math.floor((Date.now() - startTimeRef.current) / 100) / 10;
2646
+ setElapsedTime(0);
2647
+ return duration;
2648
+ }, []);
2629
2649
  useEffect(() => {
2630
- addMessage("system", "Pentesting Agent ready. Type a message or use /help for commands.");
2650
+ addMessage("system", "Pentesting Agent initialized. Type /help for commands.");
2631
2651
  if (target) {
2632
2652
  agent.setTarget(target);
2633
- addMessage("system", `Target set: ${target}`);
2653
+ addMessage("system", `Target: ${target}`);
2634
2654
  }
2635
2655
  agent.on("thought", (type, content) => {
2636
- addMessage("assistant", `[${type}] ${content}`);
2656
+ setCurrentStatus(content.slice(0, 60));
2637
2657
  });
2638
2658
  agent.on("tool_call", (data) => {
2639
- const inputStr = Object.entries(data.input).map(([k, v]) => `${k}=${typeof v === "string" ? v : JSON.stringify(v)}`).join(" ");
2640
- addMessage("tool", `\u25B6 ${data.name} ${inputStr}`);
2659
+ const args = Object.entries(data.input).slice(0, 2).map(([k, v]) => `${k}=${typeof v === "string" ? v.slice(0, 30) : "..."}`).join(" ");
2660
+ setCurrentStatus(`Running ${data.name}...`);
2661
+ addMessage("tool", `\u25B6 ${data.name} ${args}`);
2641
2662
  });
2642
2663
  agent.on("tool_result", (data) => {
2643
- const status = data.result.success ? "\u2713" : "\u2717";
2644
- const output = data.result.output?.slice(0, 200) || "";
2645
- addMessage("tool", `${status} ${data.name}: ${output}`);
2664
+ const icon = data.result.success ? "\u2713" : "\u2717";
2665
+ const preview = data.result.output?.slice(0, 100).replace(/\n/g, " ") || "";
2666
+ addMessage("result", `${icon} ${preview}`);
2667
+ });
2668
+ agent.on("iteration", (data) => {
2669
+ setCurrentStatus(`Phase: ${data.phase} (iteration ${data.iteration})`);
2646
2670
  });
2647
2671
  agent.on("finding", (finding) => {
2648
- addMessage("system", `\u{1F3AF} Finding: [${finding.severity.toUpperCase()}] ${finding.title}`);
2672
+ addMessage("system", `\u{1F3AF} [${finding.severity.toUpperCase()}] ${finding.title}`);
2673
+ });
2674
+ agent.on("complete", () => {
2675
+ const duration = stopTimer();
2676
+ addMessage("system", `\u2713 Complete (${duration}s)`);
2677
+ setIsProcessing(false);
2678
+ setCurrentStatus("");
2649
2679
  });
2650
2680
  agent.on("error", (error) => {
2651
- addMessage("error", `Error: ${error.message}`);
2681
+ stopTimer();
2682
+ addMessage("error", error.message);
2683
+ setIsProcessing(false);
2652
2684
  });
2653
- }, [agent, target, addMessage]);
2685
+ return () => {
2686
+ if (timerRef.current) clearInterval(timerRef.current);
2687
+ };
2688
+ }, [agent, target, addMessage, stopTimer]);
2654
2689
  const handleSubmit = useCallback(async (value) => {
2655
2690
  const trimmed = value.trim();
2656
2691
  if (!trimmed || isProcessing) return;
@@ -2660,121 +2695,135 @@ var App = ({ autoApprove = false, target }) => {
2660
2695
  const [cmd, ...args] = trimmed.slice(1).split(" ");
2661
2696
  switch (cmd) {
2662
2697
  case "help":
2663
- addMessage("system", `Commands:
2664
- /target <ip> Set target
2665
- /start Start autonomous mode
2666
- /stop Stop current operation
2667
- /findings Show findings
2668
- /clear Clear messages
2669
- /exit Exit`);
2698
+ case "h":
2699
+ addMessage(
2700
+ "system",
2701
+ `/target <ip> Set target
2702
+ /start [goal] Start pentest
2703
+ /stop Stop operation
2704
+ /findings Show findings
2705
+ /clear Clear screen
2706
+ /exit Exit`
2707
+ );
2670
2708
  return;
2671
2709
  case "target":
2710
+ case "t":
2672
2711
  if (args[0]) {
2673
2712
  agent.setTarget(args[0]);
2674
- addMessage("system", `Target set: ${args[0]}`);
2713
+ addMessage("system", `Target \u2192 ${args[0]}`);
2675
2714
  } else {
2676
- addMessage("error", "Usage: /target <ip or domain>");
2715
+ addMessage("error", "Usage: /target <ip>");
2677
2716
  }
2678
2717
  return;
2679
2718
  case "start":
2680
- const objective = args.join(" ") || "Perform comprehensive penetration test";
2719
+ case "s":
2681
2720
  setIsProcessing(true);
2682
- addMessage("system", `Starting: ${objective}`);
2721
+ startTimer();
2722
+ const objective = args.join(" ") || "Perform comprehensive penetration testing";
2723
+ setCurrentStatus("Initializing...");
2683
2724
  try {
2684
- await agent.run(objective);
2725
+ await agent.runAutonomous(objective);
2685
2726
  } catch (e) {
2686
- addMessage("error", `Failed: ${e instanceof Error ? e.message : String(e)}`);
2727
+ addMessage("error", e instanceof Error ? e.message : String(e));
2687
2728
  }
2729
+ stopTimer();
2688
2730
  setIsProcessing(false);
2731
+ setCurrentStatus("");
2689
2732
  return;
2690
2733
  case "stop":
2691
- agent.stop();
2734
+ agent.pause();
2735
+ stopTimer();
2692
2736
  addMessage("system", "Stopped.");
2693
2737
  setIsProcessing(false);
2738
+ setCurrentStatus("");
2694
2739
  return;
2695
2740
  case "findings":
2741
+ case "f":
2696
2742
  const findings = agent.getState().findings;
2697
2743
  if (findings.length === 0) {
2698
- addMessage("system", "No findings yet.");
2744
+ addMessage("system", "No findings.");
2699
2745
  } else {
2700
- findings.forEach((f) => {
2701
- addMessage("system", `[${f.severity.toUpperCase()}] ${f.title}`);
2702
- });
2746
+ findings.forEach((f) => addMessage("system", `[${f.severity}] ${f.title}`));
2703
2747
  }
2704
2748
  return;
2705
2749
  case "clear":
2750
+ case "c":
2706
2751
  setMessages([]);
2707
- addMessage("system", "Cleared.");
2708
2752
  return;
2709
2753
  case "exit":
2710
2754
  case "quit":
2755
+ case "q":
2711
2756
  exit();
2712
2757
  return;
2713
2758
  default:
2714
- addMessage("error", `Unknown command: ${cmd}. Type /help`);
2759
+ addMessage("error", `Unknown: ${cmd}`);
2715
2760
  return;
2716
2761
  }
2717
2762
  }
2718
2763
  setIsProcessing(true);
2764
+ startTimer();
2765
+ setCurrentStatus("Thinking...");
2719
2766
  try {
2720
- await agent.chat(trimmed);
2767
+ await agent.processUserHint(trimmed);
2768
+ addMessage("system", "Hint received.");
2721
2769
  } catch (e) {
2722
- addMessage("error", `Error: ${e instanceof Error ? e.message : String(e)}`);
2770
+ addMessage("error", e instanceof Error ? e.message : String(e));
2723
2771
  }
2772
+ stopTimer();
2724
2773
  setIsProcessing(false);
2725
- }, [agent, isProcessing, addMessage, exit]);
2774
+ setCurrentStatus("");
2775
+ }, [agent, isProcessing, addMessage, exit, startTimer, stopTimer]);
2726
2776
  useInput((input2, key) => {
2727
2777
  if (key.ctrl && input2 === "c") {
2728
2778
  if (isProcessing) {
2729
- agent.stop();
2779
+ agent.pause();
2780
+ stopTimer();
2730
2781
  setIsProcessing(false);
2782
+ setCurrentStatus("");
2731
2783
  addMessage("system", "Interrupted.");
2732
2784
  } else {
2733
2785
  exit();
2734
2786
  }
2735
2787
  }
2736
2788
  });
2737
- const getColor = (type) => {
2738
- switch (type) {
2739
- case "user":
2740
- return THEME.text.accent;
2741
- case "assistant":
2742
- return THEME.text.primary;
2743
- case "tool":
2744
- return THEME.status.info;
2745
- case "error":
2746
- return THEME.status.error;
2747
- case "system":
2748
- return THEME.text.muted;
2749
- default:
2750
- return THEME.text.primary;
2751
- }
2752
- };
2753
- const getPrefix = (type) => {
2754
- switch (type) {
2755
- case "user":
2756
- return "\u276F";
2757
- case "assistant":
2758
- return "\u25C8";
2759
- case "tool":
2760
- return "\u2699";
2761
- case "error":
2762
- return "\u2717";
2763
- case "system":
2764
- return "\u2022";
2765
- default:
2766
- return " ";
2767
- }
2789
+ const getStyle = (type) => {
2790
+ const styles = {
2791
+ user: { color: THEME.text.accent, prefix: "\u276F" },
2792
+ assistant: { color: THEME.text.primary, prefix: "\u25C8" },
2793
+ tool: { color: THEME.text.muted, prefix: " ", dim: true },
2794
+ result: { color: THEME.text.muted, prefix: " ", dim: true },
2795
+ thinking: { color: THEME.status.running, prefix: "\u25CB" },
2796
+ error: { color: THEME.status.error, prefix: "\u2717" },
2797
+ system: { color: THEME.text.muted, prefix: "\u2022" }
2798
+ };
2799
+ return styles[type] || styles.system;
2768
2800
  };
2769
- return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", padding: 1, children: [
2770
- /* @__PURE__ */ jsx(Box, { flexDirection: "column", marginBottom: 1, children: /* @__PURE__ */ jsx(Static, { items: messages.slice(-30), children: (msg) => /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Text, { color: getColor(msg.type), children: [
2771
- getPrefix(msg.type),
2772
- " ",
2773
- msg.content
2774
- ] }) }, msg.id) }) }),
2775
- /* @__PURE__ */ jsx(Box, { children: isProcessing ? /* @__PURE__ */ jsxs(Text, { color: THEME.status.running, children: [
2776
- /* @__PURE__ */ jsx(Spinner, { type: "dots" }),
2777
- " Processing..."
2801
+ const state = agent.getState();
2802
+ return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", paddingX: 1, children: [
2803
+ /* @__PURE__ */ jsx(Box, { flexDirection: "column", marginBottom: 1, children: /* @__PURE__ */ jsx(Static, { items: messages.slice(-40), children: (msg) => {
2804
+ const style = getStyle(msg.type);
2805
+ return /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsxs(Text, { color: style.color, dimColor: style.dim, children: [
2806
+ style.prefix,
2807
+ " ",
2808
+ msg.content,
2809
+ msg.duration && /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
2810
+ " (",
2811
+ msg.duration,
2812
+ "s)"
2813
+ ] })
2814
+ ] }) }, msg.id);
2815
+ } }) }),
2816
+ isProcessing ? /* @__PURE__ */ jsxs(Box, { children: [
2817
+ /* @__PURE__ */ jsx(Text, { color: THEME.status.running, children: /* @__PURE__ */ jsx(Spinner, { type: "dots" }) }),
2818
+ /* @__PURE__ */ jsxs(Text, { color: THEME.text.muted, children: [
2819
+ " ",
2820
+ currentStatus,
2821
+ elapsedTime > 0 && /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
2822
+ " (",
2823
+ elapsedTime,
2824
+ "s)"
2825
+ ] })
2826
+ ] })
2778
2827
  ] }) : /* @__PURE__ */ jsxs(Box, { children: [
2779
2828
  /* @__PURE__ */ jsx(Text, { color: THEME.status.success, children: "\u276F " }),
2780
2829
  /* @__PURE__ */ jsx(
@@ -2783,17 +2832,23 @@ var App = ({ autoApprove = false, target }) => {
2783
2832
  value: input,
2784
2833
  onChange: setInput,
2785
2834
  onSubmit: handleSubmit,
2786
- placeholder: "Type a message or /help..."
2835
+ placeholder: "Message or /help..."
2787
2836
  }
2788
2837
  )
2789
- ] }) }),
2790
- /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsxs(Text, { color: THEME.text.muted, dimColor: true, children: [
2791
- agent.getState().target ? `Target: ${agent.getState().target}` : "No target",
2792
- " | Findings: ",
2793
- agent.getState().findings.length,
2794
- " | Ctrl+C to ",
2795
- isProcessing ? "stop" : "exit"
2796
- ] }) })
2838
+ ] }),
2839
+ /* @__PURE__ */ jsxs(Box, { marginTop: 1, justifyContent: "space-between", children: [
2840
+ /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
2841
+ state.target.primary || "No target",
2842
+ " \u2502",
2843
+ state.findings.length,
2844
+ " findings \u2502",
2845
+ state.currentPhase !== "idle" && ` ${state.currentPhase} \u2502`
2846
+ ] }),
2847
+ /* @__PURE__ */ jsxs(Text, { dimColor: true, children: [
2848
+ "/help \u2502 Ctrl+C ",
2849
+ isProcessing ? "stop" : "exit"
2850
+ ] })
2851
+ ] })
2797
2852
  ] });
2798
2853
  };
2799
2854
  var app_default = App;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pentesting",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Autonomous Penetration Testing AI Agent",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",