appsec-agent 0.0.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 ADDED
@@ -0,0 +1,233 @@
1
+ # AppSec Agent (TypeScript)
2
+
3
+ A TypeScript package that provides AI-powered agents for Application Security (AppSec) tasks, built on top of the Claude Agent SDK. This is a TypeScript reimplementation of the Python AppSec AI Agent toolkit that helps automate mundane security operations and streamline AppSec workflows.
4
+
5
+ ## 🚀 Features
6
+
7
+ - **AI-Powered AppSec Automation**: Leverage Claude's capabilities for security operations
8
+ - **Multiple Agent Types**: Simple query agent, code review agent, and threat modeler for different use cases
9
+ - **Tool Permission Management**: Advanced tool permission callbacks with bypass mode for trusted operations
10
+ - **Code Review Capabilities**: Automated security and privacy issue detection in code
11
+ - **Modular Agent Architecture**: Easy to extend and customize agents for specific use cases
12
+ - **Simple Integration**: Built on the Claude Agent SDK for seamless AI integration
13
+ - **Production Ready**: Stable package with proper error handling and configuration
14
+
15
+ ## 📋 Table of Contents
16
+
17
+ - [Installation](#installation)
18
+ - [Quick Start](#quick-start)
19
+ - [Configuration](#configuration)
20
+ - [Available Agents](#available-agents)
21
+ - [Architecture](#architecture)
22
+ - [Usage Examples](#usage-examples)
23
+ - [Development](#development)
24
+
25
+ ## 🛠 Installation
26
+
27
+ ### Prerequisites
28
+
29
+ - Node.js 18.0 or higher
30
+ - npm or yarn
31
+ - Anthropic API key
32
+
33
+ ### Step 1: Install Claude Code
34
+ Our agent toolkit is built on top of Claude Agent SDK. And the Claude Agent SDK is built on top of Claude Code. So in order to install our toolkit, you would need to start with Claude Code. You may want to install it in the global user space:
35
+
36
+ ```bash
37
+ $ npm install -g @anthropic-ai/claude-code
38
+ ```
39
+
40
+ ### Step 2: Install Dependencies
41
+ ```bash
42
+ $ cd appsec-agent
43
+ $ npm install
44
+ ```
45
+
46
+ ### Step 3: Build the Project
47
+ ```bash
48
+ $ npm run build
49
+ ```
50
+
51
+ This will compile the TypeScript source files to JavaScript in the `dist/` directory.
52
+
53
+ ## ⚡ Quick Start
54
+
55
+ ### 1. Set Up Environment Variables
56
+
57
+ Add these to your shell profile (`.bashrc`, `.zshrc`, etc.):
58
+
59
+ ```bash
60
+ # Anthropic API Configuration
61
+ export ANTHROPIC_API_KEY="your-anthropic-api-key"
62
+ export ANTHROPIC_BASE_URL="https://api.anthropic.com"
63
+ ```
64
+
65
+ ### 2. Run Your First Agent
66
+
67
+ **Important**: Make sure to build the project first:
68
+ ```bash
69
+ $ npm run build
70
+ ```
71
+
72
+ Then you can run the agent:
73
+ ```bash
74
+ # Run the basic agent using npm script
75
+ $ npm start
76
+
77
+ # Or use the CLI directly (after building)
78
+ $ node bin/agent-run
79
+
80
+ # Or use ts-node for development (no build needed)
81
+ $ npx ts-node bin/agent-run.ts
82
+ ```
83
+
84
+ ## 🔧 Configuration
85
+
86
+ The agents can be configured through environment variables and configuration files. Key configuration options include:
87
+
88
+ - `ANTHROPIC_API_KEY`: Your Anthropic API key (required)
89
+ - `ANTHROPIC_BASE_URL`: API endpoint URL (default: https://api.anthropic.com)
90
+ - `MAX_TURNS`: Maximum conversation turns (default: 1)
91
+
92
+ Configuration file: `conf/appsec_agent.yaml`
93
+
94
+ ## 🤖 Available Agents
95
+
96
+ ### Simple Query Agent (`simple_query_agent`)
97
+ A general-purpose AppSec assistant that can:
98
+ - Answer security-related questions
99
+ - Help with security analysis tasks
100
+ - Provide guidance on security best practices
101
+ - Interactive query processing
102
+
103
+ ### Code Review Agent (`code_reviewer`)
104
+ A specialized agent for automated code analysis that can:
105
+ - Review code for security vulnerabilities
106
+ - Detect privacy issues in codebases
107
+ - Generate comprehensive security reports
108
+ - Support multiple output formats (Markdown, etc.)
109
+ - Analyze entire project directories
110
+ - Use advanced tools: Read, Grep, and Write capabilities
111
+
112
+ ### Threat Modeler (`threat_modeler`)
113
+ A specialized agent for comprehensive threat modeling that can:
114
+ - Generate ASCII text-based Data Flow Diagrams (DFD)
115
+ - Perform STRIDE methodology threat modeling on DFDs
116
+ - Create detailed risk registry reports with remediation plans
117
+ - Analyze codebases for security threats and vulnerabilities
118
+ - Generate multiple deliverable reports
119
+
120
+ ## 📖 Usage Examples
121
+
122
+ ### Basic Query
123
+ ```bash
124
+ $ node bin/agent-run
125
+ ```
126
+
127
+ ### Code Review Example
128
+ ```bash
129
+ # Review code in current directory
130
+ $ node bin/agent-run -r code_reviewer
131
+
132
+ # Review specific source directory
133
+ $ node bin/agent-run -r code_reviewer -s /path/to/source
134
+
135
+ # Custom output file and format
136
+ $ node bin/agent-run -r code_reviewer -o security_report.html -f html
137
+ ```
138
+
139
+ ### Threat Modeler Example
140
+ ```bash
141
+ # Run threat modeler on current directory
142
+ $ node bin/agent-run -r threat_modeler
143
+
144
+ # Run threat modeler on specific source directory
145
+ $ node bin/agent-run -r threat_modeler -s /path/to/source
146
+ ```
147
+
148
+ ### List Available Roles
149
+ ```bash
150
+ $ node bin/agent-run -l
151
+ ```
152
+
153
+ ### Version Information
154
+ ```bash
155
+ $ node bin/agent-run -v
156
+ ```
157
+
158
+ ## 🏗 Architecture
159
+
160
+ The AppSec AI Agent is built with a modular architecture consisting of several key components:
161
+
162
+ ### Core Components
163
+
164
+ - **`AgentActions`**: Handles async interactions with Claude agents, including simple queries, code reviews, and threat modeling
165
+ - **`AgentOptions`**: Manages configuration, tool permissions, and permission modes for different agent types
166
+ - **`utils`**: Utility functions for file operations, YAML loading, and project management
167
+ - **`agent-run`**: Command-line interface script for running agents
168
+
169
+ ### File Structure
170
+
171
+ ```
172
+ appsec-agent/
173
+ ├── src/
174
+ │ ├── agent_actions.ts # Agent interaction logic
175
+ │ ├── agent_options.ts # Agent configuration management
176
+ │ ├── main.ts # Main application logic
177
+ │ └── utils.ts # Utility functions
178
+ ├── bin/
179
+ │ └── agent-run # Main CLI script
180
+ ├── conf/
181
+ │ └── appsec_agent.yaml # General configuration file
182
+ ├── package.json
183
+ ├── tsconfig.json
184
+ └── README.md
185
+ ```
186
+
187
+ ## 🛠 Development
188
+
189
+ ### Setting Up Development Environment
190
+
191
+ 1. Clone the repository and navigate to the TypeScript directory:
192
+ ```bash
193
+ $ cd appsec-agent
194
+ ```
195
+
196
+ 2. Install dependencies:
197
+ ```bash
198
+ $ npm install
199
+ ```
200
+
201
+ 3. Build the project:
202
+ ```bash
203
+ $ npm run build
204
+ ```
205
+
206
+ ### Building the Package
207
+
208
+ ```bash
209
+ # Build the package
210
+ $ npm run build
211
+
212
+ # Clean build artifacts
213
+ $ npm run clean
214
+ ```
215
+
216
+ ## 📚 References
217
+
218
+ - [Claude Agent SDK Documentation](https://docs.claude.com/en/api/agent-sdk)
219
+ - [Anthropic API Documentation](https://docs.anthropic.com/)
220
+ - [Claude Code Documentation](https://docs.anthropic.com/claude-code)
221
+
222
+ ## 📄 License
223
+
224
+ This project is licensed under the MIT License.
225
+
226
+ ## 👥 Author
227
+
228
+ **Sam Li** - *Initial work* - [yang.li@owasp.org](mailto:yang.li@owasp.org)
229
+
230
+ ---
231
+
232
+ *Built with ❤️ for the AppSec*
233
+
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CLI script for AppSec AI Agent
4
+ *
5
+ * Author: Sam Li
6
+ */
7
+
8
+ const path = require('path');
9
+ const fs = require('fs');
10
+
11
+ // Check if we're running from source or compiled
12
+ const isCompiled = fs.existsSync(path.join(__dirname, '..', 'dist'));
13
+ const basePath = isCompiled ? '../dist' : '../src';
14
+
15
+ // Use require for CommonJS compatibility
16
+ const { loadYaml, listRoles, printVersionInfo, getProjectRoot } = require(path.join(__dirname, basePath, 'utils'));
17
+ const { main } = require(path.join(__dirname, basePath, 'main'));
18
+
19
+ // Dynamic import of commander for ESM compatibility
20
+ const { Command } = require('commander');
21
+
22
+ const program = new Command();
23
+
24
+ program
25
+ .name('agent-run')
26
+ .description('Automate the AppSec AI Agent dispatch')
27
+ .option('-y, --yaml <file>', 'Yaml configuration file - default to "appsec_agent.yaml" in the conf directory')
28
+ .option('-e, --environment <env>', 'Program running environment - default to "development"', 'development')
29
+ .option('-r, --role <role>', 'AppSec AI Agent role, refer to "appsec_agent.yaml" for available roles - default to "simple_query_agent"', 'simple_query_agent')
30
+ .option('-s, --src_dir <dir>', 'Project source code directory for code review agent - default to "src"')
31
+ .option('-o, --output_file <file>', 'Output file - default to "code_review_report.md"', 'code_review_report.md')
32
+ .option('-f, --output_format <format>', 'Output format - default to "markdown"', 'markdown')
33
+ .option('-l, --list_roles', 'List all available roles')
34
+ .option('-v, --version', 'Program version')
35
+ .option('-V, --verbose', 'Verbose mode');
36
+
37
+ program.parse();
38
+
39
+ const options = program.opts();
40
+
41
+ // Handle version flag
42
+ if (options.version) {
43
+ printVersionInfo();
44
+ process.exit(0);
45
+ }
46
+
47
+ // Set default yaml configuration file
48
+ const yamlFile = options.yaml || path.join(getProjectRoot(), 'conf', 'appsec_agent.yaml');
49
+
50
+ console.log('Reading AppSec AI agent configuration file:', yamlFile);
51
+ const confDict = loadYaml(yamlFile, options.verbose);
52
+
53
+ if (!confDict) {
54
+ console.error('Failed to load configuration file');
55
+ process.exit(1);
56
+ }
57
+
58
+ console.log('AppSec AI agent configuration file read successfully');
59
+
60
+ // Handle list roles flag
61
+ if (options.list_roles) {
62
+ console.log('Listing all available AppSec AI agent roles');
63
+ listRoles(confDict, options.environment);
64
+ process.exit(0);
65
+ }
66
+
67
+ // Prepare args
68
+ const args = {
69
+ role: options.role,
70
+ environment: options.environment,
71
+ src_dir: options.src_dir,
72
+ output_file: options.output_file,
73
+ output_format: options.output_format,
74
+ verbose: options.verbose
75
+ };
76
+
77
+ // Run main function
78
+ main(confDict, args).catch((error) => {
79
+ console.error('Error running agent:', error);
80
+ process.exit(1);
81
+ });
82
+
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,31 @@
1
+ # appsec_agent configuration file
2
+ # This file is used to configure the appsec_agent behaviors.
3
+ # The yaml file structure is as follows: environment -> role -> options -> system_prompt, max_turns, output_format, verbose
4
+
5
+ ---
6
+ default: &default
7
+ simple_query_agent:
8
+ options:
9
+ system_prompt: "You are an AppSec expert assistant. You are responsible for providing security advice and guidance to the user."
10
+ max_turns: 1
11
+ output_format: "stdout"
12
+ verbose: True
13
+ code_reviewer:
14
+ options:
15
+ system_prompt: "You are an AppSec expert assistant. You are responsible for performing a thorough code review. List out all the potential security and privacy issues found in the code. Then provide security and privacy advice and guidance in the code review report."
16
+ output_format: "markdown"
17
+ verbose: True
18
+ threat_modeler:
19
+ options:
20
+ system_prompt: "You are an AppSec expert assistant. You are responsible for performing risk assessment on the source code repository for SOC2 type 2 compliance audit: Start with drawing the ASCII text based Data Flow Diagrm (DFD), with output format as <codebase_data_flow_diagram_text_timestamp>; then proceeding to use STRIDE methodology to perform threat modeling on the DFD, without output report in the format <codebase_threat_model_timestamp>; finally, provide a seperate risk registry report including proposed remediation plan in the format <codebase_risk_registry_text_timestamp>. We're looking for 3 reports in the current working directory as the deliverable."
21
+ output_format: "markdown"
22
+ verbose: True
23
+
24
+
25
+ development:
26
+ <<: *default
27
+
28
+
29
+ production:
30
+ <<: *default
31
+
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Agent Actions for AppSec AI Agent
3
+ *
4
+ * Author: Sam Li
5
+ */
6
+ import { ConfigDict } from './utils';
7
+ export interface AgentArgs {
8
+ role: string;
9
+ environment: string;
10
+ src_dir?: string;
11
+ output_file?: string;
12
+ output_format?: string;
13
+ verbose?: boolean;
14
+ }
15
+ export declare class AgentActions {
16
+ private confDict;
17
+ private environment;
18
+ private args;
19
+ constructor(confDict: ConfigDict, environment: string, args: AgentArgs);
20
+ /**
21
+ * Simple query agent with options
22
+ */
23
+ simpleQueryClaudeWithOptions(yourPrompt: string): Promise<string>;
24
+ /**
25
+ * Secure code reviewer with options
26
+ */
27
+ codeReviewerWithOptions(userPrompt: string): Promise<string>;
28
+ /**
29
+ * Threat modeler agent with options
30
+ */
31
+ threatModelerAgentWithOptions(userPrompt: string): Promise<string>;
32
+ }
33
+ //# sourceMappingURL=agent_actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent_actions.d.ts","sourceRoot":"","sources":["../src/agent_actions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,IAAI,CAAY;gBAEZ,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS;IAMtE;;OAEG;IACG,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAwIvE;;OAEG;IACG,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA8BlE;;OAEG;IACG,6BAA6B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CA6BzE"}
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ /**
3
+ * Agent Actions for AppSec AI Agent
4
+ *
5
+ * Author: Sam Li
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.AgentActions = void 0;
9
+ const claude_agent_sdk_1 = require("@anthropic-ai/claude-agent-sdk");
10
+ const agent_options_1 = require("./agent_options");
11
+ class AgentActions {
12
+ confDict;
13
+ environment;
14
+ args;
15
+ constructor(confDict, environment, args) {
16
+ this.confDict = confDict;
17
+ this.environment = environment;
18
+ this.args = args;
19
+ }
20
+ /**
21
+ * Simple query agent with options
22
+ */
23
+ async simpleQueryClaudeWithOptions(yourPrompt) {
24
+ const agentOptions = new agent_options_1.AgentOptions(this.confDict, this.environment);
25
+ const options = agentOptions.getSimpleQueryAgentOptions(this.args.role);
26
+ try {
27
+ let accumulatedText = '';
28
+ let hasPrintedHeader = false;
29
+ let hasSeenStreamEvents = false;
30
+ let messageCount = 0;
31
+ for await (const msg of (0, claude_agent_sdk_1.query)({ prompt: yourPrompt, options })) {
32
+ messageCount++;
33
+ // Debug logging (remove in production)
34
+ if (this.args.verbose) {
35
+ console.error(`[DEBUG] Message #${messageCount}: type=${msg.type}`);
36
+ }
37
+ // Handle stream events (streaming deltas) - these come first
38
+ if (msg.type === 'stream_event') {
39
+ hasSeenStreamEvents = true;
40
+ const streamMsg = msg;
41
+ // Handle content block deltas (streaming text)
42
+ if (streamMsg.event?.type === 'content_block_delta' && streamMsg.event.delta?.type === 'text_delta') {
43
+ const deltaText = streamMsg.event.delta.text || '';
44
+ if (deltaText) {
45
+ if (!hasPrintedHeader) {
46
+ console.log(`\nClaude:\n`);
47
+ hasPrintedHeader = true;
48
+ }
49
+ // Accumulate and write streaming deltas directly
50
+ accumulatedText += deltaText;
51
+ process.stdout.write(deltaText);
52
+ }
53
+ }
54
+ // Handle content block start (beginning of new content block)
55
+ else if (streamMsg.event?.type === 'content_block_start') {
56
+ // Content block is starting - ensure header is printed
57
+ if (!hasPrintedHeader) {
58
+ console.log(`\nClaude:\n`);
59
+ hasPrintedHeader = true;
60
+ }
61
+ // Reset accumulated text for new content block
62
+ accumulatedText = '';
63
+ }
64
+ // Handle message stop (streaming is complete)
65
+ else if (streamMsg.event?.type === 'message_stop') {
66
+ // Message is complete - ensure we have a newline
67
+ if (hasPrintedHeader && accumulatedText) {
68
+ // Stream is done, newline will be added by result handler
69
+ }
70
+ }
71
+ }
72
+ // Handle assistant messages (complete messages) - only use if no stream events
73
+ // Note: If we've seen stream events, the content was already printed incrementally
74
+ else if (msg.type === 'assistant' && !hasSeenStreamEvents) {
75
+ const assistantMsg = msg;
76
+ if (assistantMsg.message.content) {
77
+ for (const block of assistantMsg.message.content) {
78
+ if (block.type === 'text') {
79
+ const currentText = block.text || '';
80
+ if (currentText.length > 0 && currentText !== accumulatedText) {
81
+ if (!hasPrintedHeader) {
82
+ console.log(`\nClaude:\n`);
83
+ hasPrintedHeader = true;
84
+ }
85
+ // Print the complete text only if it's different from what we've accumulated
86
+ console.log(currentText);
87
+ accumulatedText = currentText;
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
93
+ // If we see assistant message after stream events, ignore it (already printed)
94
+ else if (msg.type === 'assistant' && hasSeenStreamEvents) {
95
+ // Already printed via stream events, skip
96
+ if (this.args.verbose) {
97
+ console.error(`[DEBUG] Skipping assistant message (already printed via stream events)`);
98
+ }
99
+ }
100
+ // Handle result messages
101
+ else if (msg.type === 'result') {
102
+ const resultMsg = msg;
103
+ // Ensure we flush any partial output and add newline
104
+ if (hasPrintedHeader) {
105
+ console.log(); // New line after final output
106
+ }
107
+ // Check for errors in result messages
108
+ if (resultMsg.is_error) {
109
+ const errorMsg = resultMsg.errors?.[0] || resultMsg.error_message || 'Unknown error occurred';
110
+ console.error(`\nError: ${errorMsg}`);
111
+ if (resultMsg.subtype) {
112
+ console.error(`Error subtype: ${resultMsg.subtype}`);
113
+ }
114
+ // Log max_turns error specifically
115
+ if (resultMsg.subtype === 'error_max_turns') {
116
+ console.error(`\nNote: The conversation stopped because max_turns (${options.maxTurns || 1}) was reached.`);
117
+ console.error(`To allow the agent to use tools and continue, increase max_turns in the configuration or use the code_reviewer role.`);
118
+ }
119
+ }
120
+ else if (resultMsg.total_cost_usd && resultMsg.total_cost_usd > 0) {
121
+ console.log(`\nCost: $${resultMsg.total_cost_usd.toFixed(4)}`);
122
+ }
123
+ // Debug: log turn count
124
+ if (this.args.verbose) {
125
+ console.error(`[DEBUG] Result: num_turns=${resultMsg.num_turns}, is_error=${resultMsg.is_error}`);
126
+ }
127
+ }
128
+ // Handle tool progress messages (agent might be using tools)
129
+ else if (msg.type === 'tool_progress') {
130
+ // Tool is being executed - this is normal, just continue
131
+ if (this.args.verbose) {
132
+ const toolMsg = msg;
133
+ console.log(`[Tool Progress] ${toolMsg.tool_name}: ${toolMsg.elapsed_time_seconds}s`);
134
+ }
135
+ }
136
+ // Log other message types for debugging
137
+ else if (this.args.verbose) {
138
+ console.log(`[DEBUG] Received message type: ${msg.type}`);
139
+ }
140
+ }
141
+ // Debug: log total messages processed
142
+ if (this.args.verbose) {
143
+ console.error(`[DEBUG] Total messages processed: ${messageCount}`);
144
+ }
145
+ }
146
+ catch (error) {
147
+ console.error('Error during query:', error);
148
+ throw error;
149
+ }
150
+ console.log();
151
+ return '';
152
+ }
153
+ /**
154
+ * Secure code reviewer with options
155
+ */
156
+ async codeReviewerWithOptions(userPrompt) {
157
+ const agentOptions = new agent_options_1.AgentOptions(this.confDict, this.environment);
158
+ const options = agentOptions.getCodeReviewerOptions(this.args.role);
159
+ try {
160
+ for await (const message of (0, claude_agent_sdk_1.query)({ prompt: userPrompt, options })) {
161
+ if (message.type === 'assistant') {
162
+ const assistantMsg = message;
163
+ if (assistantMsg.message.content) {
164
+ for (const block of assistantMsg.message.content) {
165
+ if (block.type === 'text') {
166
+ console.log(`Claude: ${block.text}`);
167
+ }
168
+ }
169
+ }
170
+ }
171
+ else if (message.type === 'result') {
172
+ const resultMsg = message;
173
+ if (resultMsg.total_cost_usd && resultMsg.total_cost_usd > 0) {
174
+ console.log(`\nCost: $${resultMsg.total_cost_usd.toFixed(4)}`);
175
+ }
176
+ }
177
+ }
178
+ }
179
+ catch (error) {
180
+ console.error('Error during code review:', error);
181
+ throw error;
182
+ }
183
+ console.log();
184
+ return '';
185
+ }
186
+ /**
187
+ * Threat modeler agent with options
188
+ */
189
+ async threatModelerAgentWithOptions(userPrompt) {
190
+ const agentOptions = new agent_options_1.AgentOptions(this.confDict, this.environment);
191
+ const options = agentOptions.getThreatModelerOptions(this.args.role);
192
+ try {
193
+ for await (const message of (0, claude_agent_sdk_1.query)({ prompt: userPrompt, options })) {
194
+ if (message.type === 'assistant') {
195
+ const assistantMsg = message;
196
+ if (assistantMsg.message.content) {
197
+ for (const block of assistantMsg.message.content) {
198
+ if (block.type === 'text') {
199
+ console.log(`Claude: ${block.text}`);
200
+ }
201
+ }
202
+ }
203
+ }
204
+ else if (message.type === 'result') {
205
+ const resultMsg = message;
206
+ if (resultMsg.total_cost_usd && resultMsg.total_cost_usd > 0) {
207
+ console.log(`\nCost: $${resultMsg.total_cost_usd.toFixed(4)}`);
208
+ }
209
+ }
210
+ }
211
+ }
212
+ catch (error) {
213
+ console.error('Error during threat modeling:', error);
214
+ throw error;
215
+ }
216
+ console.log();
217
+ return '';
218
+ }
219
+ }
220
+ exports.AgentActions = AgentActions;
221
+ //# sourceMappingURL=agent_actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent_actions.js","sourceRoot":"","sources":["../src/agent_actions.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,qEAA8F;AAC9F,mDAA+C;AAY/C,MAAa,YAAY;IACf,QAAQ,CAAa;IACrB,WAAW,CAAS;IACpB,IAAI,CAAY;IAExB,YAAY,QAAoB,EAAE,WAAmB,EAAE,IAAe;QACpE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,4BAA4B,CAAC,UAAkB;QACnD,MAAM,YAAY,GAAG,IAAI,4BAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACvE,MAAM,OAAO,GAAG,YAAY,CAAC,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAExE,IAAI,CAAC;YACH,IAAI,eAAe,GAAG,EAAE,CAAC;YACzB,IAAI,gBAAgB,GAAG,KAAK,CAAC;YAC7B,IAAI,mBAA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 import { ConfigDict } from './utils';
8
+ export interface ToolUsageLog {
9
+ tool: string;
10
+ input: any;
11
+ suggestions: string;
12
+ }
13
+ export declare class AgentOptions {
14
+ private confDict;
15
+ private environment;
16
+ toolUsageLog: ToolUsageLog[];
17
+ constructor(confDict: ConfigDict, environment: string);
18
+ /**
19
+ * Tool permission callback to control tool access
20
+ */
21
+ toolPermissionCallback: CanUseTool;
22
+ /**
23
+ * Get options for simple query agent
24
+ */
25
+ getSimpleQueryAgentOptions(role?: string): Options;
26
+ /**
27
+ * Get options for code reviewer
28
+ */
29
+ getCodeReviewerOptions(role?: string): Options;
30
+ /**
31
+ * Get options for threat modeler
32
+ */
33
+ getThreatModelerOptions(role?: string): Options;
34
+ }
35
+ //# sourceMappingURL=agent_options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent_options.d.ts","sourceRoot":"","sources":["../src/agent_options.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAqC,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACxG,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,GAAG,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,WAAW,CAAS;IACrB,YAAY,EAAE,YAAY,EAAE,CAAM;gBAE7B,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM;IAKrD;;OAEG;IACH,sBAAsB,EAAE,UAAU,CAqBjC;IAED;;OAEG;IACH,0BAA0B,CAAC,IAAI,GAAE,MAA6B,GAAG,OAAO;IAQxE;;OAEG;IACH,sBAAsB,CAAC,IAAI,GAAE,MAAwB,GAAG,OAAO;IAkB/D;;OAEG;IACH,uBAAuB,CAAC,IAAI,GAAE,MAAyB,GAAG,OAAO;CAiBlE"}