kramscan 0.1.0 โ 0.1.1
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/README.md +197 -48
- package/dist/agent/confirmation.d.ts +34 -0
- package/dist/agent/confirmation.js +190 -0
- package/dist/agent/context.d.ts +81 -0
- package/dist/agent/context.js +228 -0
- package/dist/agent/index.d.ts +10 -0
- package/dist/agent/index.js +32 -0
- package/dist/agent/orchestrator.d.ts +61 -0
- package/dist/agent/orchestrator.js +328 -0
- package/dist/agent/prompts/system.d.ts +6 -0
- package/dist/agent/prompts/system.js +118 -0
- package/dist/agent/skill-registry.d.ts +78 -0
- package/dist/agent/skill-registry.js +202 -0
- package/dist/agent/skills/analyze-findings.d.ts +22 -0
- package/dist/agent/skills/analyze-findings.js +191 -0
- package/dist/agent/skills/generate-report.d.ts +26 -0
- package/dist/agent/skills/generate-report.js +436 -0
- package/dist/agent/skills/health-check.d.ts +28 -0
- package/dist/agent/skills/health-check.js +324 -0
- package/dist/agent/skills/index.d.ts +8 -0
- package/dist/agent/skills/index.js +15 -0
- package/dist/agent/skills/web-scan.d.ts +22 -0
- package/dist/agent/skills/web-scan.js +157 -0
- package/dist/agent/types.d.ts +141 -0
- package/dist/agent/types.js +16 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +39 -3
- package/dist/commands/agent.d.ts +6 -0
- package/dist/commands/agent.js +250 -0
- package/dist/commands/analyze.js +1 -1
- package/dist/commands/config.js +8 -8
- package/dist/commands/doctor.js +2 -2
- package/dist/commands/onboard.js +24 -6
- package/dist/commands/report.js +1 -1
- package/dist/core/ai-client.d.ts +1 -1
- package/dist/core/ai-client.js +159 -16
- package/dist/core/config.d.ts +10 -6
- package/dist/core/config.js +198 -14
- package/dist/core/scanner.d.ts +15 -0
- package/dist/core/scanner.js +333 -52
- package/dist/core/vulnerability-detector.d.ts +15 -2
- package/dist/core/vulnerability-detector.js +334 -33
- package/package.json +27 -6
- package/dist/core/executor.d.ts +0 -2
- package/dist/core/executor.js +0 -74
- package/dist/core/logger.d.ts +0 -12
- package/dist/core/logger.js +0 -51
- package/dist/core/registry.d.ts +0 -3
- package/dist/core/registry.js +0 -35
- package/dist/core/storage.d.ts +0 -4
- package/dist/core/storage.js +0 -39
- package/dist/core/types.d.ts +0 -24
- package/dist/core/types.js +0 -2
- package/dist/skills/base.d.ts +0 -8
- package/dist/skills/base.js +0 -6
- package/dist/skills/builtin.d.ts +0 -4
- package/dist/skills/builtin.js +0 -71
- package/dist/skills/loader.d.ts +0 -2
- package/dist/skills/loader.js +0 -27
- package/dist/skills/types.d.ts +0 -46
- package/dist/skills/types.js +0 -2
package/README.md
CHANGED
|
@@ -1,87 +1,236 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://github.com/user-attachments/assets/6439c670-8d73-4bdd-b8fa-c74de949a31e" width="500" alt="KramScan Logo" />
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
<h3 align="center">AI-Powered Web Application Security Testing CLI</h3>
|
|
5
|
+
|
|
6
|
+
<br />
|
|
7
|
+
|
|
8
|
+
[](https://www.npmjs.com/package/kramscan)
|
|
9
|
+
[](https://www.npmjs.com/package/kramscan)
|
|
10
|
+
[](https://github.com/shaikhakramshakil/kramscan/blob/main/LICENSE)
|
|
11
|
+
[](https://github.com/shaikhakramshakil/kramscan)
|
|
12
|
+
[](https://www.typescriptlang.org)
|
|
13
|
+
[](https://nodejs.org)
|
|
14
|
+
|
|
15
|
+
<br />
|
|
16
|
+
|
|
17
|
+
๐ฌ **A next-generation security auditing tool that combines automated vulnerability scanning with multi-provider AI analysis.**
|
|
18
|
+
|
|
19
|
+
*Empowering developers and security researchers with institutional-grade insights and an interactive AI agent.*
|
|
20
|
+
|
|
21
|
+
<br />
|
|
22
|
+
|
|
23
|
+
[๐ NPM Package](https://www.npmjs.com/package/kramscan) ยท [๐ Documentation](#-usage) ยท [๐ Report Bug](https://github.com/shaikhakramshakil/kramscan/issues)
|
|
24
|
+
|
|
25
|
+
</div>
|
|
4
26
|
|
|
5
27
|
---
|
|
6
28
|
|
|
7
|
-
|
|
29
|
+
<br />
|
|
8
30
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
31
|
+
## ๐ The Problem We Solve
|
|
32
|
+
Web security is complex and often fragmented. Developers rely on multiple disjointed tools for scanning, manual testing, and reporting. Traditional automated scanners generate noise without context, and manual pentesting is time-consuming and expensive.
|
|
33
|
+
|
|
34
|
+
**KramScan bridges this gap.** We provide a unified command-line interface that orchestrates headless browser scanning, scrapes critical security headers, and leverages **Generative AI** (OpenAI, Gemini, Anthropic) to analyze findings. It delivers actionable, human-readable insights alongside raw vulnerability dataโall in seconds.
|
|
35
|
+
|
|
36
|
+
<br />
|
|
37
|
+
|
|
38
|
+
---
|
|
12
39
|
|
|
13
|
-
|
|
14
|
-
npm run build
|
|
40
|
+
<br />
|
|
15
41
|
|
|
16
|
-
|
|
17
|
-
|
|
42
|
+
## โจ Key Features
|
|
43
|
+
| Feature | Description |
|
|
44
|
+
| :--- | :--- |
|
|
45
|
+
| ๐ **Automated Vulnerability Engine** | Detects XSS, SQL Injection, CSRF, and insecure headers using Puppeteer-powered crawling. |
|
|
46
|
+
| ๐ค **Interactive AI Agent** | A conversational security assistant that understands natural language commands like "scan example.com". |
|
|
47
|
+
| ๐ง **Multi-Provider AI Analysis** | Supports OpenAI, Anthropic, Google Gemini, Mistral, OpenRouter, and Kimi (Moonshot). |
|
|
48
|
+
| ๐ **Professional Reporting** | Generates detailed DOCX, TXT, and JSON reports with executive summaries and remediation steps. |
|
|
49
|
+
| ๐ **Headless Browser Testing** | Renders modern SPAs (Single Page Applications) to find vulnerabilities in dynamic content. |
|
|
50
|
+
| โก **CLI-First Architecture** | Optimized for speed, scriptability, and seamless integration into CI/CD pipelines. |
|
|
18
51
|
|
|
19
|
-
|
|
20
|
-
|
|
52
|
+
<br />
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
<br />
|
|
57
|
+
|
|
58
|
+
## ๐๏ธ Architecture & Workflow
|
|
59
|
+
|
|
60
|
+
```mermaid
|
|
61
|
+
graph LR
|
|
62
|
+
A[User Command] --> B{CLI Controller};
|
|
63
|
+
B --> C[Scanner Module<br/>Puppeteer / Cheerio];
|
|
64
|
+
B --> D[AI Agent<br/>NLP Processing];
|
|
65
|
+
|
|
66
|
+
C --> E[Vulnerability Detection<br/>XSS / SQLi / Headers];
|
|
67
|
+
C --> F[Data Aggregation];
|
|
68
|
+
|
|
69
|
+
E & F --> G[AI Analysis Engine<br/>LLM Provider];
|
|
70
|
+
|
|
71
|
+
G --> H[Risk Assessment<br/>Confidence Scoring];
|
|
72
|
+
H --> I[Report Generator<br/>DOCX / JSON / TXT];
|
|
73
|
+
I --> J((Final Output));
|
|
21
74
|
```
|
|
22
75
|
|
|
76
|
+
<br />
|
|
77
|
+
|
|
23
78
|
---
|
|
24
79
|
|
|
25
|
-
|
|
80
|
+
<br />
|
|
81
|
+
|
|
82
|
+
## ๐งช Tech Stack
|
|
83
|
+
<div align="center">
|
|
84
|
+
|
|
85
|
+
| Component | Technology |
|
|
86
|
+
| :--- | :--- |
|
|
87
|
+
| **Runtime** | Node.js โฅ 18 |
|
|
88
|
+
| **Language** | TypeScript 5.4 |
|
|
89
|
+
| **CLI Framework** | Commander.js, Inquirer.js |
|
|
90
|
+
| **Browser Automation** | Puppeteer (Headless Chrome) |
|
|
91
|
+
| **AI Integration** | OpenAI SDK, Google Generative AI, Anthropic SDK |
|
|
92
|
+
| **Reporting** | Docx, Chalk|
|
|
93
|
+
| **Package Manager** | NPM / Yarn / PNPM |
|
|
94
|
+
|
|
95
|
+
</div>
|
|
26
96
|
|
|
27
|
-
|
|
28
|
-
|:-------------------|:-------------------------------------|:-------------|
|
|
29
|
-
| `kramscan` | Launch interactive dashboard | โ
Active |
|
|
30
|
-
| `kramscan onboard` | First-time setup wizard | โ
Active |
|
|
31
|
-
| `kramscan scan` | Scan a target URL | ๐ Coming |
|
|
32
|
-
| `kramscan analyze` | AI-powered analysis of scan results | ๐ Coming |
|
|
33
|
-
| `kramscan report` | Generate a professional report | ๐ Coming |
|
|
34
|
-
| `kramscan doctor` | Check environment health | ๐ Coming |
|
|
35
|
-
| `kramscan --help` | Show all available commands | โ
Active |
|
|
97
|
+
<br />
|
|
36
98
|
|
|
37
99
|
---
|
|
38
100
|
|
|
39
|
-
|
|
101
|
+
<br />
|
|
40
102
|
|
|
41
|
-
|
|
103
|
+
## ๐ง Supported AI Providers
|
|
42
104
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
105
|
+
| Provider | SDK / Integration | Default Model |
|
|
106
|
+
| :--- | :--- | :--- |
|
|
107
|
+
| **OpenAI** | `openai` | `gpt-4` |
|
|
108
|
+
| **Anthropic** | `@anthropic-ai/sdk` | `claude-3-5-sonnet-20241022` |
|
|
109
|
+
| **Google Gemini** | `@google/generative-ai` | `gemini-2.0-flash-exp` |
|
|
110
|
+
| **Mistral** | `@mistralai/mistralai` | `mistral-large-latest` |
|
|
111
|
+
| **OpenRouter** | OpenAI-compatible | `anthropic/claude-3.5-sonnet` |
|
|
112
|
+
| **Kimi** | OpenAI-compatible | `moonshot-v1-8k` |
|
|
49
113
|
|
|
50
|
-
|
|
114
|
+
> Switch providers instantly with `kramscan onboard` or by editing `~/.kramscan/config.json`.
|
|
115
|
+
|
|
116
|
+
<br />
|
|
51
117
|
|
|
52
118
|
---
|
|
53
119
|
|
|
54
|
-
|
|
120
|
+
<br />
|
|
121
|
+
|
|
122
|
+
## ๐ Quick Start
|
|
123
|
+
|
|
124
|
+
### 1. Installation
|
|
125
|
+
Install KramScan globally using npm:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npm install -g kramscan
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 2. First-Time Setup
|
|
132
|
+
Initialize the configuration wizard to set up your AI provider and API keys:
|
|
55
133
|
|
|
56
134
|
```bash
|
|
57
|
-
|
|
58
|
-
|
|
135
|
+
kramscan onboard
|
|
136
|
+
```
|
|
59
137
|
|
|
60
|
-
|
|
61
|
-
|
|
138
|
+
### 3. Run a Scan
|
|
139
|
+
Execute a full security scan on a target URL:
|
|
62
140
|
|
|
63
|
-
|
|
64
|
-
|
|
141
|
+
```bash
|
|
142
|
+
kramscan scan https://example.com
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
<br />
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
<br />
|
|
150
|
+
|
|
151
|
+
## ๐ Usage & Commands
|
|
152
|
+
|
|
153
|
+
| Command | Description | Status |
|
|
154
|
+
| :--- | :--- | :---: |
|
|
155
|
+
| `kramscan` | Launch the interactive dashboard menu. | โ
Stable |
|
|
156
|
+
| `kramscan scan <url>` | Run a comprehensive vulnerability scan. | โ
Stable |
|
|
157
|
+
| `kramscan agent` | Start the conversational AI security assistant. | โ
Stable |
|
|
158
|
+
| `kramscan analyze` | Analyze previous scan results using the configured AI. | โ
Stable |
|
|
159
|
+
| `kramscan report` | Generate a professional report from scan data. | โ
Stable |
|
|
160
|
+
| `kramscan onboard` | Run the configuration and setup wizard. | โ
Stable |
|
|
161
|
+
| `kramscan doctor` | Verify environment health and dependencies. | โ
Stable |
|
|
162
|
+
| `kramscan config` | View and edit current configuration settings. | โ
Stable |
|
|
163
|
+
|
|
164
|
+
<br />
|
|
165
|
+
|
|
166
|
+
### Example Agent Session
|
|
167
|
+
```bash
|
|
168
|
+
$ kramscan agent
|
|
169
|
+
> scan https://example.com
|
|
170
|
+
|
|
171
|
+
Agent: I'll perform a comprehensive security scan of https://example.com.
|
|
172
|
+
Checking for XSS, SQLi, and missing headers...
|
|
173
|
+
[Scanning...]
|
|
174
|
+
|
|
175
|
+
Agent: Scan complete! Found 2 High severity issues.
|
|
176
|
+
Would you like me to generate a report?
|
|
65
177
|
```
|
|
66
178
|
|
|
179
|
+
<br />
|
|
180
|
+
|
|
67
181
|
---
|
|
68
182
|
|
|
69
|
-
|
|
183
|
+
<br />
|
|
184
|
+
|
|
185
|
+
## ๐บ๏ธ Roadmap
|
|
70
186
|
|
|
71
|
-
-
|
|
72
|
-
-
|
|
73
|
-
-
|
|
74
|
-
-
|
|
75
|
-
-
|
|
187
|
+
- [x] Core vulnerability scanner (XSS, SQLi, CSRF, headers)
|
|
188
|
+
- [x] Multi-provider AI analysis engine
|
|
189
|
+
- [x] Interactive AI agent mode
|
|
190
|
+
- [x] Professional report generation (DOCX, TXT, JSON)
|
|
191
|
+
- [x] Configuration wizard & management
|
|
192
|
+
- [ ] Plugin system for custom scan modules
|
|
193
|
+
- [ ] CI/CD integration (GitHub Actions, GitLab CI)
|
|
194
|
+
- [ ] PDF report generation
|
|
195
|
+
- [ ] Web-based dashboard UI
|
|
196
|
+
|
|
197
|
+
<br />
|
|
76
198
|
|
|
77
199
|
---
|
|
78
200
|
|
|
79
|
-
|
|
201
|
+
<br />
|
|
202
|
+
|
|
203
|
+
## ๐ Security & Privacy
|
|
204
|
+
- **Local Execution:** All scanning logic runs locally on your machine.
|
|
205
|
+
- **API Key Safety:** AI provider API keys are stored securely in your local home directory and are never sent to our servers.
|
|
206
|
+
- **Data Privacy:** Scan data is sent only to your chosen AI provider for analysis and is not stored by KramScan.
|
|
80
207
|
|
|
81
|
-
|
|
208
|
+
<br />
|
|
82
209
|
|
|
83
210
|
---
|
|
84
211
|
|
|
85
|
-
|
|
212
|
+
<br />
|
|
213
|
+
|
|
214
|
+
## ๐ค Author
|
|
215
|
+
<div align="center">
|
|
216
|
+
|
|
217
|
+
**Akram Shaikh**
|
|
218
|
+
|
|
219
|
+
[](https://akramshaikh.me)
|
|
220
|
+
[](https://github.com/shaikhakramshakil)
|
|
221
|
+
[](https://www.linkedin.com/in/shaikhakramshakil/)
|
|
222
|
+
|
|
223
|
+
</div>
|
|
224
|
+
|
|
225
|
+
<br />
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
<br />
|
|
230
|
+
|
|
231
|
+
## ๐ License
|
|
232
|
+
This project is licensed under the **MIT License** โ see the [LICENSE](LICENSE) file for details.
|
|
86
233
|
|
|
87
|
-
|
|
234
|
+
<div align="center">
|
|
235
|
+
<sub>Made with โค๏ธ by Akram Shaikh</sub>
|
|
236
|
+
</div>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confirmation Prompt System
|
|
3
|
+
* Handles user confirmation for skill execution with detailed risk assessment
|
|
4
|
+
*/
|
|
5
|
+
import { ConfirmationPrompt } from "./types";
|
|
6
|
+
export interface ConfirmationResult {
|
|
7
|
+
confirmed: boolean;
|
|
8
|
+
showDetails: boolean;
|
|
9
|
+
cancelled: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class ConfirmationHandler {
|
|
12
|
+
private rl;
|
|
13
|
+
constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Display confirmation prompt and get user response
|
|
16
|
+
*/
|
|
17
|
+
prompt(confirmation: ConfirmationPrompt): Promise<ConfirmationResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Quick confirmation for low-risk actions
|
|
20
|
+
*/
|
|
21
|
+
quickConfirm(action: string): Promise<boolean>;
|
|
22
|
+
/**
|
|
23
|
+
* Display detailed information about the action
|
|
24
|
+
*/
|
|
25
|
+
showDetails(confirmation: ConfirmationPrompt): void;
|
|
26
|
+
/**
|
|
27
|
+
* Close the readline interface
|
|
28
|
+
*/
|
|
29
|
+
close(): void;
|
|
30
|
+
private getUserInput;
|
|
31
|
+
private getRiskColor;
|
|
32
|
+
private getDetailedDescription;
|
|
33
|
+
private getSafetyInfo;
|
|
34
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Confirmation Prompt System
|
|
4
|
+
* Handles user confirmation for skill execution with detailed risk assessment
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
40
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
41
|
+
};
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.ConfirmationHandler = void 0;
|
|
44
|
+
const readline = __importStar(require("readline"));
|
|
45
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
46
|
+
class ConfirmationHandler {
|
|
47
|
+
rl;
|
|
48
|
+
constructor() {
|
|
49
|
+
this.rl = readline.createInterface({
|
|
50
|
+
input: process.stdin,
|
|
51
|
+
output: process.stdout,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Display confirmation prompt and get user response
|
|
56
|
+
*/
|
|
57
|
+
async prompt(confirmation) {
|
|
58
|
+
console.log("");
|
|
59
|
+
console.log(chalk_1.default.bold.yellow("โ ๏ธ Action Requires Confirmation"));
|
|
60
|
+
console.log(chalk_1.default.gray("โ".repeat(50)));
|
|
61
|
+
console.log("");
|
|
62
|
+
// Display action details
|
|
63
|
+
console.log(chalk_1.default.white("Action:"), chalk_1.default.cyan(confirmation.action));
|
|
64
|
+
console.log(chalk_1.default.white("Description:"), confirmation.description);
|
|
65
|
+
console.log("");
|
|
66
|
+
// Display risk level with color coding
|
|
67
|
+
const riskColor = this.getRiskColor(confirmation.risk);
|
|
68
|
+
console.log(chalk_1.default.white("Risk Level:"), riskColor(confirmation.risk.toUpperCase()));
|
|
69
|
+
console.log(chalk_1.default.white("Estimated Time:"), confirmation.estimatedTime);
|
|
70
|
+
console.log("");
|
|
71
|
+
// Display parameters
|
|
72
|
+
console.log(chalk_1.default.white("Parameters:"));
|
|
73
|
+
Object.entries(confirmation.parameters).forEach(([key, value]) => {
|
|
74
|
+
const displayValue = typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
75
|
+
console.log(` ${chalk_1.default.gray(key)}: ${chalk_1.default.white(displayValue)}`);
|
|
76
|
+
});
|
|
77
|
+
console.log("");
|
|
78
|
+
// Risk warnings
|
|
79
|
+
if (confirmation.risk === "high") {
|
|
80
|
+
console.log(chalk_1.default.red.bold("โ ๏ธ WARNING: This action may have significant impact."));
|
|
81
|
+
}
|
|
82
|
+
else if (confirmation.risk === "medium") {
|
|
83
|
+
console.log(chalk_1.default.yellow("โ ๏ธ This action will interact with external systems."));
|
|
84
|
+
}
|
|
85
|
+
console.log("");
|
|
86
|
+
// Get user input
|
|
87
|
+
return this.getUserInput();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Quick confirmation for low-risk actions
|
|
91
|
+
*/
|
|
92
|
+
async quickConfirm(action) {
|
|
93
|
+
return new Promise((resolve) => {
|
|
94
|
+
this.rl.question(chalk_1.default.gray(`${action} [Y/n]: `), (answer) => {
|
|
95
|
+
const normalized = answer.trim().toLowerCase();
|
|
96
|
+
resolve(normalized === "" || normalized === "y" || normalized === "yes");
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Display detailed information about the action
|
|
102
|
+
*/
|
|
103
|
+
showDetails(confirmation) {
|
|
104
|
+
console.log("");
|
|
105
|
+
console.log(chalk_1.default.bold.cyan("๐ Action Details"));
|
|
106
|
+
console.log(chalk_1.default.gray("โ".repeat(50)));
|
|
107
|
+
console.log("");
|
|
108
|
+
console.log(chalk_1.default.white("What will happen:"));
|
|
109
|
+
console.log(chalk_1.default.gray(this.getDetailedDescription(confirmation.action)));
|
|
110
|
+
console.log("");
|
|
111
|
+
console.log(chalk_1.default.white("Safety considerations:"));
|
|
112
|
+
console.log(chalk_1.default.gray(this.getSafetyInfo(confirmation.risk)));
|
|
113
|
+
console.log("");
|
|
114
|
+
if (confirmation.risk === "high") {
|
|
115
|
+
console.log(chalk_1.default.yellow("Recommendations:"));
|
|
116
|
+
console.log(chalk_1.default.gray("โข Ensure you have proper authorization"));
|
|
117
|
+
console.log(chalk_1.default.gray("โข Verify the target is correct"));
|
|
118
|
+
console.log(chalk_1.default.gray("โข Consider testing in a safe environment first"));
|
|
119
|
+
console.log("");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Close the readline interface
|
|
124
|
+
*/
|
|
125
|
+
close() {
|
|
126
|
+
this.rl.close();
|
|
127
|
+
}
|
|
128
|
+
async getUserInput() {
|
|
129
|
+
return new Promise((resolve) => {
|
|
130
|
+
const askQuestion = () => {
|
|
131
|
+
this.rl.question(chalk_1.default.gray("Proceed? [Y/n/details/cancel]: "), (answer) => {
|
|
132
|
+
const normalized = answer.trim().toLowerCase();
|
|
133
|
+
if (normalized === "" || normalized === "y" || normalized === "yes") {
|
|
134
|
+
resolve({ confirmed: true, showDetails: false, cancelled: false });
|
|
135
|
+
}
|
|
136
|
+
else if (normalized === "n" || normalized === "no") {
|
|
137
|
+
resolve({ confirmed: false, showDetails: false, cancelled: false });
|
|
138
|
+
}
|
|
139
|
+
else if (normalized === "details" || normalized === "d") {
|
|
140
|
+
resolve({ confirmed: false, showDetails: true, cancelled: false });
|
|
141
|
+
}
|
|
142
|
+
else if (normalized === "cancel" || normalized === "c") {
|
|
143
|
+
resolve({ confirmed: false, showDetails: false, cancelled: true });
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
console.log(chalk_1.default.gray("Please enter: Y, n, details, or cancel"));
|
|
147
|
+
askQuestion();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
askQuestion();
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
getRiskColor(risk) {
|
|
155
|
+
switch (risk) {
|
|
156
|
+
case "high":
|
|
157
|
+
return chalk_1.default.red.bold;
|
|
158
|
+
case "medium":
|
|
159
|
+
return chalk_1.default.yellow;
|
|
160
|
+
case "low":
|
|
161
|
+
return chalk_1.default.green;
|
|
162
|
+
default:
|
|
163
|
+
return chalk_1.default.gray;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
getDetailedDescription(action) {
|
|
167
|
+
const descriptions = {
|
|
168
|
+
"Web Scan": "This will crawl the target website and test for common vulnerabilities including XSS, SQL injection, CSRF, and security header misconfigurations. The scan sends HTTP requests to the target.",
|
|
169
|
+
"Analyze Findings": "This will use AI to analyze previously discovered vulnerabilities and provide detailed remediation recommendations.",
|
|
170
|
+
"Generate Report": "This will create a professional security report document based on scan results.",
|
|
171
|
+
"Check Environment": "This will verify your system configuration, API keys, and dependencies.",
|
|
172
|
+
"View Configuration": "This will display your current KramScan configuration settings.",
|
|
173
|
+
};
|
|
174
|
+
return (descriptions[action] ||
|
|
175
|
+
"This action will execute the requested security operation.");
|
|
176
|
+
}
|
|
177
|
+
getSafetyInfo(risk) {
|
|
178
|
+
switch (risk) {
|
|
179
|
+
case "high":
|
|
180
|
+
return "This action may trigger security systems, generate significant network traffic, or have other notable effects. Use with caution.";
|
|
181
|
+
case "medium":
|
|
182
|
+
return "This action will make network requests to external systems. Ensure you have permission to test the target.";
|
|
183
|
+
case "low":
|
|
184
|
+
return "This is a safe, read-only operation that won't modify any external systems.";
|
|
185
|
+
default:
|
|
186
|
+
return "Please review the action details carefully before proceeding.";
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.ConfirmationHandler = ConfirmationHandler;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversation Context Manager
|
|
3
|
+
* Manages conversation history, user context, and session state
|
|
4
|
+
*/
|
|
5
|
+
import { ConversationMessage, AgentContext, AgentConfig } from "./types";
|
|
6
|
+
export declare class ConversationContext {
|
|
7
|
+
private messages;
|
|
8
|
+
private context;
|
|
9
|
+
private config;
|
|
10
|
+
private historyFile;
|
|
11
|
+
constructor(config?: Partial<AgentConfig>);
|
|
12
|
+
private initializeContext;
|
|
13
|
+
/**
|
|
14
|
+
* Get the current agent context
|
|
15
|
+
*/
|
|
16
|
+
getContext(): AgentContext;
|
|
17
|
+
/**
|
|
18
|
+
* Update the current target URL
|
|
19
|
+
*/
|
|
20
|
+
setCurrentTarget(target: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Get the current target URL
|
|
23
|
+
*/
|
|
24
|
+
getCurrentTarget(): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Store last scan results
|
|
27
|
+
*/
|
|
28
|
+
setLastScanResults(results: unknown): void;
|
|
29
|
+
/**
|
|
30
|
+
* Get last scan results
|
|
31
|
+
*/
|
|
32
|
+
getLastScanResults(): unknown | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Add a message to the conversation
|
|
35
|
+
*/
|
|
36
|
+
addMessage(role: ConversationMessage["role"], content: string, toolCalls?: any[], toolCallResults?: any[]): ConversationMessage;
|
|
37
|
+
/**
|
|
38
|
+
* Get all conversation messages
|
|
39
|
+
*/
|
|
40
|
+
getMessages(): ConversationMessage[];
|
|
41
|
+
/**
|
|
42
|
+
* Get recent messages (for AI context)
|
|
43
|
+
*/
|
|
44
|
+
getRecentMessages(count?: number): ConversationMessage[];
|
|
45
|
+
/**
|
|
46
|
+
* Get the last message
|
|
47
|
+
*/
|
|
48
|
+
getLastMessage(): ConversationMessage | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Get conversation summary for display
|
|
51
|
+
*/
|
|
52
|
+
getSummary(): {
|
|
53
|
+
totalMessages: number;
|
|
54
|
+
sessionDuration: string;
|
|
55
|
+
currentTarget?: string;
|
|
56
|
+
hasScanResults: boolean;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Clear conversation history
|
|
60
|
+
*/
|
|
61
|
+
clear(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Trim history to max length
|
|
64
|
+
*/
|
|
65
|
+
private trimHistory;
|
|
66
|
+
/**
|
|
67
|
+
* Persist conversation to disk
|
|
68
|
+
*/
|
|
69
|
+
save(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Load conversation from disk
|
|
72
|
+
*/
|
|
73
|
+
load(): Promise<boolean>;
|
|
74
|
+
/**
|
|
75
|
+
* Format messages for AI provider (OpenAI/Anthropic format)
|
|
76
|
+
*/
|
|
77
|
+
formatForAI(): Array<{
|
|
78
|
+
role: string;
|
|
79
|
+
content: string;
|
|
80
|
+
}>;
|
|
81
|
+
}
|