Skip to content

Commit 22b69a8

Browse files
ChrisEdwardsclaude
andauthored
AIML-230: Harden coding standards and practices [STACKED] (#29)
* Fix mcp-6bs: Change list_vulns_by_app tools to use appID parameter Changes two tools to accept appID instead of app_name for consistency with AIML-189 standardization: - list_vulns_by_app_and_metadata: Renamed method to listVulnsByAppIdAndSessionMetadata, removed SDKHelper lookup - list_vulns_by_app_latest_session: Renamed method to listVulnsByAppIdForLatestSession, removed SDKHelper lookup Both tools now: - Accept appID parameter directly - Have updated @tool descriptions mentioning list_applications_with_name - Skip application name lookup for better performance - Are consistent with all other application-level tools Tests updated to use appID. All tests passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Update test plan files to use appID parameter Fixed test plan documentation for list_vulns_by_app tools to use appID parameter instead of app_name, matching the code changes in mcp-6bs. This was causing Copilot to cache the old parameter name and fail when calling these tools. Changes: - test-plan-list_vulns_by_app_and_metadata.md: Updated all references from app_name to appID - test-plan-list_vulns_by_app_latest_session.md: Updated all references from app_name to appID 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove test plan files from git tracking These test plan files are development/testing documentation that should not be committed to the repository. They are now ignored via .gitignore. The files are preserved locally for development use but won't be tracked in version control. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Add coding standards section to CLAUDE.md Documents Java coding conventions for the project: - Prefer var for local variables when type is obvious - Use isEmpty() instead of size() comparisons for collections 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Add Spotless Maven plugin with Google Java Format (AIML-230) - Added spotless-maven-plugin 2.43.0 to pom.xml - Configured with Google Java Format 1.26.0 matching aiml-services standards - Enabled automatic enforcement via validate phase - Formatted entire codebase (96 Java files) - Updated CLAUDE.md with Spotless commands and usage notes Configuration: - Google Java Format style with import reordering - Long string reflowing enabled - Javadoc formatting enabled - Runs automatically on every build (mvn compile/test/install) All tests pass: 250 tests, 0 failures, 0 errors 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Refactor codebase to use var keyword for local variables (AIML-230) Applied var keyword throughout the codebase where type is obvious from right-hand side, following CLAUDE.md coding standards. Changes: - Service classes: 70 var replacements - ADRService (9), AssessService (42), RouteCoverageService (7), SCAService (6), SastService (6) - Data/mapper/utils: 13 var replacements - AttackSummary, VulnerabilityMapper, PaginationHandler, hint classes - SDK extension classes: 29 var replacements - SDKExtension (13), SDKHelper (16) - Test classes: 437 var replacements - Unit tests (386): All *Test.java files - Integration tests (51): All *IntegrationTest.java files Total: 549 var replacements across 34 files Rules applied: ✅ Use var when type is obvious from constructor/method call ✅ Use var for mock objects and ArgumentCaptors ✅ Use var for collections with explicit type parameters ❌ Do NOT use var for numeric literals ❌ Do NOT use var for null assignments ❌ Do NOT use var when type would be ambiguous All 224 unit tests pass (0 failures, 0 errors) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Document no wildcard imports coding standard (AIML-230) Add coding standard to CLAUDE.md requiring explicit imports only. Wildcard imports (import package.*) are not allowed to improve code clarity and maintainability. * Convert wildcard imports to explicit imports (AIML-230) Replace all wildcard imports with explicit imports in main source files per CLAUDE.md coding standards. Static wildcard imports in test files remain unchanged as they follow standard test code conventions. Changes: - SDKExtension.java: 1 wildcard → 5 explicit imports - AssessService.java: 3 wildcards → 19 explicit imports - VulnerabilityFilterParams.java: 1 wildcard → 6 explicit imports Verified: mvn test passes (218 tests, 0 failures) * Fix spelling: rename sdkexstension to sdkextension (AIML-230) Correct package name spelling from 'sdkexstension' to 'sdkextension' throughout the codebase. Used git mv to preserve file history. Changes: - Renamed 49 Java files (package directories) - Updated package declarations in all moved files - Updated imports in 23 files that reference the package - Updated documentation (CLAUDE.md, plans) Verified: All 250 tests pass, compilation successful * Fix formatting after rebase --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4d33882 commit 22b69a8

File tree

152 files changed

+22404
-16188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+22404
-16188
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ build/
4141
### Beads ###
4242
.beads/
4343
test-plan-*.md
44+
plans/

CLAUDE.md

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44

5-
**Note**: This project uses [bd (beads)](https://github.com/steveyegge/beads) for issue tracking. Use `bd` commands instead of markdown TODOs. See AGENTS.md for workflow details.
6-
75
## Project Overview
86

97
This is an MCP (Model Context Protocol) server for Contrast Security that enables AI agents to access and analyze vulnerability data from Contrast's security platform. It serves as a bridge between Contrast Security's API and AI tools like Claude, enabling automated vulnerability remediation and security analysis.
@@ -12,10 +10,12 @@ This is an MCP (Model Context Protocol) server for Contrast Security that enable
1210

1311
### Building the Project
1412
- **Build**: `mvn clean install` or `./mvnw clean install`
15-
- **Package without tests**: `mvn clean package -DskipTests`
1613
- **Test**: `mvn test` or `./mvnw test`
17-
- **Run single test**: `mvn test -Dtest=HintGeneratorTest` or `mvn test -Dtest=HintGeneratorTest#specificTestMethod`
18-
- **Run locally**: `java -jar target/mcp-contrast-0.0.12-SNAPSHOT.jar --CONTRAST_HOST_NAME=<host> --CONTRAST_API_KEY=<key> --CONTRAST_SERVICE_KEY=<key> --CONTRAST_USERNAME=<user> --CONTRAST_ORG_ID=<org>`
14+
- **Format code**: `mvn spotless:apply` - Auto-format all Java files (run before committing)
15+
- **Check formatting**: `mvn spotless:check` - Verify code formatting (runs automatically during build)
16+
- **Run locally**: `java -jar target/mcp-contrast-0.0.11.jar --CONTRAST_HOST_NAME=<host> --CONTRAST_API_KEY=<key> --CONTRAST_SERVICE_KEY=<key> --CONTRAST_USERNAME=<user> --CONTRAST_ORG_ID=<org>`
17+
18+
**Note:** Spotless enforces Google Java Format style automatically. The `spotless:check` goal runs during the `validate` phase, so any `mvn compile`, `mvn test`, or `mvn install` will fail if code is not properly formatted. Run `mvn spotless:apply` before committing to ensure formatting is correct.
1919

2020
### Docker Commands
2121
- **Build Docker image**: `docker build -t mcp-contrast .`
@@ -32,19 +32,17 @@ This is an MCP (Model Context Protocol) server for Contrast Security that enable
3232

3333
**Main Application**: `McpContrastApplication.java` - Spring Boot application that registers MCP tools from all service classes.
3434

35-
**Service Layer**: Each service handles a specific aspect of Contrast Security data and exposes `@Tool` annotated methods:
35+
**Service Layer**: Each service handles a specific aspect of Contrast Security data:
3636
- `AssessService` - Vulnerability analysis and trace data
3737
- `SastService` - Static application security testing data
3838
- `SCAService` - Software composition analysis (library vulnerabilities)
3939
- `ADRService` - Attack detection and response events
4040
- `RouteCoverageService` - Route coverage analysis
41+
- `PromptService` - AI prompt management
4142

42-
**SDK Extensions**: Located in `sdkexstension/` package:
43-
- `SDKExtension.java` - Extends Contrast SDK API with additional endpoints not in standard SDK (library observations, route details, session metadata, etc.)
44-
- `SDKHelper.java` - Utility methods for hostname protocol handling and common operations
45-
- `data/` subpackages - Enhanced data models with AI-friendly representations organized by domain (application, adr, routecoverage, sca, traces, sessionmetadata)
43+
**SDK Extensions**: Located in `sdkextension/` package, these extend the Contrast SDK with enhanced data models and helper methods for better AI integration.
4644

47-
**Data Models**: Comprehensive POJOs in `data/` package representing vulnerability information, library data, applications, and attack events used by service layer.
45+
**Data Models**: Comprehensive POJOs in `data/` package representing vulnerability information, library data, applications, and attack events.
4846

4947
**Hint System**: `hints/` package provides context-aware security guidance for vulnerability remediation.
5048

@@ -64,29 +62,25 @@ Required environment variables/arguments:
6462

6563
### Technology Stack
6664

67-
- **Framework**: Spring Boot 3.4.5 with Spring AI 1.0.1
65+
- **Framework**: Spring Boot 3.4.5 with Spring AI 1.0.0-RC1
6866
- **MCP Integration**: Spring AI MCP Server starter
6967
- **Contrast Integration**: Contrast SDK Java 3.4.2
70-
- **JSON Processing**: Gson (via Contrast SDK)
71-
- **Testing**: JUnit 5 with Spring Boot Test
72-
- **Build Tool**: Maven 3.6+ with wrapper
68+
- **Testing**: JUnit 5
69+
- **Build Tool**: Maven with wrapper
7370
- **Packaging**: Executable JAR and Docker container
7471

7572
### Development Patterns
7673

77-
1. **MCP Tools**: Services expose methods via `@Tool` annotation for AI agent consumption. Register new services in `McpContrastApplication.tools()` bean.
78-
2. **SDK Extension Pattern**:
79-
- Use `SDKExtension` to add new Contrast API endpoints not in the standard SDK
80-
- Use `SDKHelper` for common utility operations (hostname handling, etc.)
81-
- Enhanced data models in `sdkexstension/data/` provide AI-friendly JSON representations
82-
3. **Hint Generation**: Rule-based system in `hints/` package provides contextual security guidance for vulnerability remediation
83-
4. **Defensive Design**: All external API calls include proper resource management (try-with-resources), error handling, and logging
84-
5. **Pagination Handling**: SDK extension methods handle pagination automatically (see `getLibraryObservations` for pattern)
74+
1. **MCP Tools**: Services expose methods via `@Tool` annotation for AI agent consumption
75+
2. **SDK Extension Pattern**: Enhanced data models extend base SDK classes with AI-friendly representations
76+
3. **Hint Generation**: Rule-based system provides contextual security guidance
77+
4. **Defensive Design**: All external API calls include error handling and logging
8578

8679
### Coding Standards
8780

8881
- **Prefer `var`** for local variables when the type is obvious from the right-hand side
8982
- **Use `isEmpty()`** instead of `size() > 0` or `size() == 0` for collection checks
83+
- **No wildcard imports** - All imports must be explicit. Do not use `import package.*` syntax
9084

9185
### Security Considerations
9286

@@ -97,7 +91,6 @@ This codebase handles sensitive vulnerability data. The README contains critical
9791
- Default log location: `/tmp/mcp-contrast.log`
9892
- Debug logging: Add `--logging.level.root=DEBUG` to startup arguments
9993
- Console logging is minimal by design for MCP protocol compatibility
100-
- Debug mode buffers API responses for logging (memory impact with large datasets)
10194

10295
## Beads Workflow Requirements
10396

@@ -136,22 +129,6 @@ Example: If B must be done after A completes, use `bd dep add B A` (not `bd dep
136129

137130
Verify with `bd show <task-id>` - dependent tasks show "Depends on", prerequisites show "Blocks".
138131

139-
### Testing Requirements Before Closing Beads
140-
### Troubleshooting
141-
142-
For common issues (SSL certificates, proxy configuration, debug logging), see the "Common Issues" and "Proxy Configuration" sections in [README.md](README.md).
143-
144-
### Adding New MCP Tools
145-
146-
To add a new tool/service:
147-
1. Create a new `@Service` class with methods annotated with `@Tool(description="...")`
148-
2. Inject dependencies (ContrastSDK, SDKExtension) via constructor
149-
3. Register the service in `McpContrastApplication.tools()` bean method
150-
4. Use `SDKExtension` to add new API endpoints if needed
151-
5. Create enhanced data models in appropriate `sdkexstension/data/` subpackage
152-
153-
See INTEGRATION_TESTS.md for integration test setup and credentials.
154-
155132
## Project Management
156133

157134
### Jira Issue Tracking
@@ -225,7 +202,9 @@ Promoting Stacked PR (after base PR merges):
225202
- Record the branch name in the bead (so it's easily found later)
226203
- **If this is a stacked branch** (based on another PR branch):
227204
- Label the bead with `stacked-branch`
228-
- Create parent-child dependency: the stacked bead depends on the bead of the branch it's based on
205+
- Create blocks dependency: `bd dep add <new-bead-id> <base-bead-id> --type blocks`
206+
- This represents that the base bead "blocks" the new bead from being merged
207+
- Example: If AIML-230 is stacked on AIML-228, use `bd dep add mcp-uuv mcp-9kr --type blocks`
229208

230209
**3. Update Jira (if applicable):**
231210
- If bead has a linked Jira ticket:
@@ -580,4 +559,4 @@ This workflow is for ending the current session while preserving all state so wo
580559

581560
**Cannot close parent beads** if they still have open children. Ensure all child beads are closed first.
582561

583-
Beads typically remain `in_progress` (with `in-review` label) until the PR review is complete and merged. Only close beads when explicitly instructed by the user.
562+
Beads typically remain `in_progress` (with `in-review` label) until the PR review is complete and merged. Only close beads when explicitly instructed by the user.

WORKFLOW.md

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
# Developer Workflow Quick Reference
2+
3+
Personal workflow guide for Chris Edwards - how to use beads + Jira + Claude Code effectively.
4+
5+
## Starting New Work
6+
7+
### 1. Check for Ready Work
8+
```bash
9+
bd ready
10+
```
11+
12+
### 2. Create or Pick a Bead
13+
14+
**For Jira-tracked work:**
15+
- Create Jira ticket first in AIML project
16+
- Create bead with Jira ID in title and external_ref:
17+
```bash
18+
bd create "AIML-XXX: Description" -t task -p 1 --external-ref AIML-XXX
19+
```
20+
21+
**For discovered work during implementation:**
22+
- Create child bead linked to parent:
23+
```bash
24+
bd create "Fix bug found in feature X" -t bug -p 1 --deps discovered-from:mcp-parent-id
25+
```
26+
27+
### 3. Start Work with Claude Code
28+
29+
Tell Claude to start work on the bead:
30+
```
31+
Start work on bead mcp-XXX
32+
```
33+
34+
Claude will:
35+
- Ask which branch to base off (for stacked PRs)
36+
- Create feature branch (if Jira-linked): `AIML-XXX-description`
37+
- Update bead status to `in_progress`
38+
- Update Jira status to "In Progress" and assign to you
39+
- Present a textual plan and ask you to discuss
40+
- Wait for you to say "generate a plan" before proceeding
41+
42+
**Important**: Discuss the approach BEFORE telling Claude to generate a full plan.
43+
44+
## During Development
45+
46+
### Working with Claude Code
47+
48+
**Tell Claude what to do:**
49+
- "Implement the changes we discussed"
50+
- "Write tests for the new feature"
51+
- "Run the full test suite"
52+
53+
**Claude follows your workflow automatically:**
54+
- Writes tests for all code changes
55+
- Runs `mvn test` and `mvn verify`
56+
- Builds artifacts when needed (`mvn clean package`)
57+
- Records branch name in bead
58+
59+
### Managing Related Work
60+
61+
**Creating child beads:**
62+
- When Claude suggests new work, it will ask if it should be a child bead
63+
- Child beads share the same branch as parent
64+
- Use for: bug fixes found during implementation, follow-up tasks, subtasks
65+
66+
**Check dependencies:**
67+
```bash
68+
bd show mcp-XXX
69+
```
70+
71+
## Moving to Review
72+
73+
When ready for review, tell Claude:
74+
```
75+
Move to review
76+
```
77+
78+
Claude will:
79+
1. Apply `in-review` label to all beads on the branch
80+
2. Push branch to remote
81+
3. Create or update PR with comprehensive description by researching:
82+
- All beads worked on in this branch
83+
- All commits and diffs
84+
- Related voice notes for context
85+
- Jira ticket details
86+
4. Write PR description with why/what/how and step-by-step walkthrough
87+
88+
**Review the PR description** before marking ready - Claude makes it easy for reviewers.
89+
90+
## Long Sessions: Landing the Plane
91+
92+
When context is running low or you need to pause, tell Claude:
93+
```
94+
Let's land the plane
95+
```
96+
97+
Claude will:
98+
1. Create child beads for any remaining work
99+
2. Update current bead with complete status and context
100+
3. Commit all WIP with descriptive message
101+
4. Generate continuation prompt for next session
102+
103+
Copy the continuation prompt to resume work in a fresh session.
104+
105+
## Closing Work
106+
107+
**Never close beads yourself during development.** Tell Claude when you're ready:
108+
```
109+
Close bead mcp-XXX
110+
```
111+
112+
Claude will:
113+
- Ask for confirmation
114+
- Check for open child beads (can't close parent with open children)
115+
- Only close after you explicitly confirm
116+
117+
**Typical lifecycle:**
118+
1. `open` → Start work → `in_progress`
119+
2. `in_progress` → Move to review → `in_progress` + `in-review` label
120+
3. `in_progress` + `in-review` → PR merged → Ask Claude to close → `closed`
121+
122+
## Stacked PRs Workflow
123+
124+
When working on multiple related changes:
125+
126+
1. **First PR**: Branch from `main`, implement, create PR
127+
2. **Second PR**: Tell Claude to base new branch off first PR branch
128+
3. **Continue stacking**: Each new branch comes off the previous one
129+
130+
Claude will ask which branch to base off and show recent branches.
131+
132+
## Quick Commands Reference
133+
134+
### Beads
135+
```bash
136+
bd ready # Show unblocked work
137+
bd list --status in_progress # Your current work
138+
bd show mcp-XXX # Show bead details
139+
bd update mcp-XXX --priority 0 # Bump priority
140+
bd dep add mcp-child mcp-parent # Add dependency
141+
```
142+
143+
### Git
144+
```bash
145+
git log --oneline -10 # Recent commits
146+
git diff main...HEAD # All changes in branch
147+
gh pr view # View current PR
148+
gh pr checks # Check CI status
149+
```
150+
151+
### Maven
152+
```bash
153+
mvn test -q # Run unit tests (quiet)
154+
mvn verify -q # Run integration tests
155+
mvn clean package # Build JAR
156+
```
157+
158+
### Log Work
159+
```bash
160+
/log-work # Log work to voice notes
161+
```
162+
163+
## Tips
164+
165+
- **Always discuss the plan** with Claude before implementation
166+
- **Let Claude manage workflow state** (bead status, Jira status, branches)
167+
- **Use stacked PRs** for dependent changes to keep PRs small
168+
- **Land the plane** when context runs low - don't fight it
169+
- **Voice notes are your friend** - Claude uses them for PR descriptions
170+
- **Test everything** - Claude won't move to review without passing tests
171+
172+
## Common Scenarios
173+
174+
### "I found a bug while implementing"
175+
Tell Claude: "Create a child bead for this bug"
176+
Claude will ask if it should be a child and create it.
177+
178+
### "This is taking too long"
179+
Tell Claude: "Let's land the plane"
180+
Resume in next session with the continuation prompt.
181+
182+
### "I need to work on something urgent"
183+
Commit current work, switch branches. Return to original work by:
184+
```
185+
Continue work on bead mcp-XXX
186+
```
187+
188+
### "PR got approved and merged"
189+
Tell Claude: "Close bead mcp-XXX" (for all beads in that branch)
190+
191+
### "I need to update the PR description"
192+
Tell Claude: "Update the PR description with latest changes"
193+
Claude will research and regenerate.
194+
195+
## Files to Know
196+
197+
- `CLAUDE.md` - Instructions for Claude Code (AI workflow)
198+
- `AGENTS.md` - General beads usage patterns
199+
- `WORKFLOW.md` - This file (your reference)
200+
- `.beads/issues.jsonl` - Bead database (auto-synced with git)
201+
- `voice-notes/YYYY-MM-DD.md` - Daily work log
202+
203+
## Remember
204+
205+
**You focus on the work. Claude manages the workflow.**

0 commit comments

Comments
 (0)