Skip to content

Commit 16992bf

Browse files
authored
Merge pull request #15 from kaakaww/feature/refinements
feat: agentic workflow support — app CRUD, scan detail, repo linking, git-aware init
2 parents bddd8a2 + 3045801 commit 16992bf

Some content is hidden

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

45 files changed

+10992
-5893
lines changed

.claude/commands/add-api.md

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,91 @@
11
---
2-
description: Add a new StackHawk API integration
2+
description: Add a new StackHawk API integration (with pattern matching + quirks check)
33
---
44

5-
Help me add a new StackHawk API endpoint integration. Ask me:
5+
Help me add a new StackHawk API endpoint integration.
6+
7+
## Step 1: Research the Endpoint
8+
9+
Before writing code, gather information:
10+
11+
1. **Read the API reference**`.claude/skills/stackhawk-api-sherpa/stackhawk-api.md`
12+
2. **Check the OpenAPI spec**`stackhawk-openapi.json` for exact request/response schemas
13+
3. **Check API quirks**`.claude/skills/stackhawk-api-sherpa/api-quirks.md` for known issues
14+
4. **Check the roadmap**`docs/ROADMAP.md` for planned status
15+
16+
Ask the user:
617
1. What API endpoint should be integrated?
7-
2. What HTTP method (GET, POST, etc.)?
8-
3. What request/response structures are needed?
9-
4. Should this support pagination?
18+
2. What HTTP method (GET, POST, PUT, DELETE)?
19+
3. Should this support pagination?
20+
4. Is this a read-only query or a state mutation?
21+
22+
## Step 2: Study Existing Patterns
23+
24+
Read the most similar existing integration to match patterns:
25+
26+
**For GET/list endpoints** — study:
27+
- `src/client/api/listing.rs` for pagination and query params
28+
- `src/client/pagination.rs` for `PaginationParams` and `PagedResponse`
29+
30+
**For POST/PUT mutations** — study:
31+
- `src/client/stackhawk.rs` for `request_json_with_query()` and `request_with_body()`
32+
- The team update pattern (fetch-modify-put) if it's a PUT endpoint
33+
34+
**For detail/drill-down** — study:
35+
- `src/client/api/scan_detail.rs` for nested resource fetching
36+
37+
## Step 3: Implementation
38+
39+
Follow this exact pattern:
40+
41+
### 3.1 API Model (`src/client/models/<resource>.rs`)
42+
```rust
43+
#[derive(Debug, Clone, Serialize, Deserialize)]
44+
#[serde(rename_all = "camelCase")]
45+
pub struct NewResource {
46+
// Use #[serde(default)] for fields that may be missing
47+
// Use #[serde(alias = "...")] for API field name differences
48+
// Use Option<T> for truly optional fields
49+
}
50+
```
51+
52+
### 3.2 Response Wrapper (in implementation file)
53+
```rust
54+
#[derive(Deserialize)]
55+
struct ListResponse {
56+
items: Vec<NewResource>,
57+
#[serde(default, deserialize_with = "deserialize_string_to_usize")]
58+
total_count: usize, // Some endpoints return this as a string!
59+
}
60+
```
61+
62+
### 3.3 Trait Method (`src/client/mod.rs`)
63+
```rust
64+
async fn list_resource(&self, org_id: &str, pagination: Option<&PaginationParams>) -> Result<Vec<Resource>>;
65+
```
66+
67+
### 3.4 Implementation
68+
- Use `self.request_with_query()` for GET with query params
69+
- Use `self.request_json_with_query()` for POST with body
70+
- Apply rate limiting category (check `src/client/rate_limit.rs`)
71+
- Add to `CachedStackHawkClient` in `src/cache/client.rs` with appropriate TTL
72+
73+
### 3.5 Mock Implementation (`src/client/mock.rs`)
74+
Add the method to `MockStackHawkClient` returning fixture data.
75+
76+
## Step 4: Verify
77+
78+
```bash
79+
cargo check # Compiles?
80+
cargo test # Tests pass?
81+
cargo clippy -- -D warnings # Lint clean?
82+
```
83+
84+
## Common Pitfalls
1085

11-
Then implement the API client method following the existing patterns in src/client/stackhawk.rs with proper error handling, rate limiting, and JWT authentication.
86+
From `api-quirks.md`:
87+
- **PUT = REPLACE-ALL** — Always fetch current state before PUT operations
88+
- **readOnly fields required** — Don't trust OpenAPI `readOnly` annotations
89+
- **String numbers** — Use `deserialize_string_to_usize` for `totalCount` fields
90+
- **Removed endpoints** — Check if the endpoint was removed from recent spec updates
91+
- **Rate limits** — Categorize correctly: Scan (80/sec), User (80/sec), AppList (80/sec), Default (6/sec)

.claude/commands/add-command.md

Lines changed: 110 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,118 @@
11
---
2-
description: Add a new CLI command to HawkOp
2+
description: Add a new CLI command to HawkOp (with design review + test-first workflow)
33
---
44

55
Help me add a new command to the HawkOp CLI.
66

7-
**Before designing, invoke the `cli-designer` skill** to ensure the command follows clig.dev and 12-Factor CLI principles.
7+
## Phase 1: Design (before writing any implementation code)
88

9-
## Questions to Answer
9+
### 1.1 Gather Requirements
1010

11+
Answer these questions with the user:
1112
1. What should the command do?
12-
2. What command name should be added?
13-
3. What subcommands (if any) should it have?
14-
4. What flags does it need? (prefer flags over multiple positional args)
15-
5. What arguments does it need? (max 1 type of positional arg)
16-
17-
## Implementation Checklist
18-
19-
- [ ] Add help text with examples in `after_help`
20-
- [ ] Support `--format json` for machine-readable output
21-
- [ ] Use stdout for data, stderr for messages
22-
- [ ] Return non-zero exit code on failure
23-
- [ ] Add navigation hints (`→ hawkop next-command`)
24-
- [ ] Test with pipes: `hawkop cmd | jq`
25-
26-
## Implementation Steps
27-
28-
1. Add API models in `src/client/mod.rs`
29-
2. Add trait method to `StackHawkApi` trait
30-
3. Implement in `src/client/stackhawk.rs`
31-
4. Add display model in `src/models/display.rs`
32-
5. Add CLI command enum in `src/cli/mod.rs`
33-
6. Create handler in `src/cli/<command>.rs`
34-
7. Wire up in `src/main.rs`
35-
36-
Follow patterns in `src/cli/` and the cli-designer skill's `patterns.md`.
13+
2. What command name and subcommands?
14+
3. What flags and arguments? (prefer flags over multiple positional args)
15+
4. What API endpoint(s) does it call? (check `stackhawk-api.md` and `api-quirks.md`)
16+
17+
### 1.2 Invoke CLI Designer
18+
19+
**Invoke the `cli-designer` skill** to design the interface. Verify:
20+
- Command follows clig.dev and 12-Factor CLI principles
21+
- Args vs flags decision is correct
22+
- Help text includes examples in `after_help`
23+
- Matches existing HawkOp patterns (`--org`, `--format`, `--limit`, etc.)
24+
25+
### 1.3 Check Existing Patterns
26+
27+
Before implementing, study the closest existing command:
28+
- Read `src/cli/` files for a similar command (e.g., `scan.rs` for list+detail, `team.rs` for CRUD)
29+
- Read `src/client/api/` for the API integration pattern
30+
- Read `src/models/display/` for the display model pattern
31+
- Check `src/client/mod.rs` for trait method conventions
32+
33+
### 1.4 Check API Quirks
34+
35+
Read `.claude/skills/stackhawk-api-sherpa/api-quirks.md` to check if the endpoint has known quirks (field naming, replace-all PUT behavior, removed endpoints, etc.).
36+
37+
## Phase 2: Test-First Contract
38+
39+
### 2.1 Write Test Stubs First
40+
41+
Before implementing the command, create test stubs that define the expected behavior:
42+
43+
**Unit test** in the relevant source file:
44+
```rust
45+
#[cfg(test)]
46+
mod tests {
47+
// Test that the command handler produces expected output
48+
// Test error cases (not found, invalid args)
49+
// Test JSON format output
50+
}
51+
```
52+
53+
**Functional test** in `tests/functional/`:
54+
- Add to the appropriate test file (read_tests.rs, mutation_tests.rs, etc.)
55+
- At minimum, write stubs for:
56+
- Happy-path test (command runs successfully)
57+
- Error-path test (invalid input, not-found)
58+
- JSON output test (`--format json` produces valid JSON)
59+
60+
### 2.2 Update Coverage Script
61+
62+
Add the new command to `scripts/check-test-coverage.sh` so it's tracked:
63+
```bash
64+
check_coverage "hawkop <cmd> <subcmd>" "test_<cmd>_<subcmd>|\"<cmd>\".*\"<subcmd>\""
65+
```
66+
67+
## Phase 3: Implementation
68+
69+
Follow this order (matches CLAUDE.md "Adding New Commands"):
70+
71+
1. **API models**`src/client/models/<resource>.rs`
72+
- `#[serde(rename_all = "camelCase")]`
73+
- Use `#[serde(default)]` for optional fields
74+
- Check `stackhawk-openapi.json` for exact field names
75+
2. **Trait method**`src/client/mod.rs`
76+
3. **API implementation**`src/client/api/` (or `src/client/stackhawk.rs`)
77+
4. **Mock implementation**`src/client/mock.rs`
78+
5. **Display model**`src/models/display/<resource>.rs`
79+
6. **CLI command enum**`src/cli/mod.rs`
80+
7. **Handler**`src/cli/<command>.rs`
81+
8. **Main routing**`src/main.rs`
82+
83+
## Phase 4: Verification
84+
85+
### 4.1 Run Tests
86+
```bash
87+
cargo test # All unit/integration tests
88+
cargo clippy -- -D warnings # Lint check
89+
```
90+
91+
### 4.2 Run CLI Design Checklist
92+
93+
Verify against `docs/CLI_DESIGN_PRINCIPLES.md`:
94+
- [ ] `-h`/`--help` display useful help with examples
95+
- [ ] `--format json` produces valid JSON parseable by `jq`
96+
- [ ] Data on stdout, messages on stderr
97+
- [ ] Non-zero exit on failure
98+
- [ ] Navigation hints (`-> hawkop next-command`)
99+
- [ ] Works when piped (`hawkop cmd | jq`)
100+
- [ ] No ANSI codes when not TTY
101+
102+
### 4.3 Run Functional Tests
103+
```bash
104+
HAWKOP_PROFILE=test HAWKOP_FUNCTIONAL_TESTS_CONFIRM=yes \
105+
cargo test --features functional-tests --test functional -- --test-threads=1 --nocapture "<test_name>"
106+
```
107+
108+
### 4.4 Check Test Coverage
109+
```bash
110+
./scripts/check-test-coverage.sh
111+
```
112+
113+
## Phase 5: Documentation
114+
115+
- [ ] Update `docs/CLI_REFERENCE.md` with the new command
116+
- [ ] Update `docs/ROADMAP.md` if this completes a planned endpoint
117+
- [ ] Add entry to `CHANGELOG.md` under `[Unreleased]`
118+
- [ ] Update `CLAUDE.md` command list if a new top-level command

.claude/commands/new-feature.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
---
2+
description: "End-to-end feature workflow: API research -> CLI design -> test-first implementation -> docs"
3+
arguments:
4+
- name: feature
5+
description: "Brief description of the feature to implement"
6+
required: true
7+
---
8+
9+
Orchestrate a complete feature implementation for HawkOp. This command sequences
10+
all the right skills and checks so nothing falls through the cracks.
11+
12+
**Feature requested**: $ARGUMENTS
13+
14+
---
15+
16+
## Stage 1: Research & Design
17+
18+
### 1.1 API Research
19+
20+
Invoke the **stackhawk-api-sherpa** skill to research the API endpoints needed:
21+
1. Read `.claude/skills/stackhawk-api-sherpa/stackhawk-api.md` for endpoint details
22+
2. Check `stackhawk-openapi.json` for request/response schemas
23+
3. Read `.claude/skills/stackhawk-api-sherpa/api-quirks.md` for known API gotchas
24+
4. Check `docs/ROADMAP.md` to see if this feature is planned and what phase it's in
25+
26+
Present findings to the user:
27+
- Which endpoint(s) are needed
28+
- Any API quirks or limitations
29+
- Whether the endpoint is stable or under active development
30+
- Recommended approach
31+
32+
**Wait for user approval before proceeding.**
33+
34+
### 1.2 CLI Design
35+
36+
Invoke the **cli-designer** skill to design the command interface:
37+
1. Command name, subcommands, flags, arguments
38+
2. Apply clig.dev and 12-Factor CLI principles
39+
3. Match existing HawkOp conventions
40+
4. Write help text with examples
41+
42+
Present the proposed CLI interface to the user.
43+
44+
**Wait for user approval before proceeding.**
45+
46+
## Stage 2: Test-First Contract
47+
48+
### 2.1 Study Existing Patterns
49+
50+
Before writing any code, study the closest existing implementation:
51+
- Read the most similar command in `src/cli/` for handler patterns
52+
- Read the corresponding API method in `src/client/api/`
53+
- Read the display model in `src/models/display/`
54+
- Note any reusable utilities or shared patterns
55+
56+
### 2.2 Write Test Stubs
57+
58+
Create test stubs BEFORE implementation:
59+
60+
1. **Unit tests** — Define expected behavior:
61+
- Mock client returns expected data
62+
- Error cases produce correct error types
63+
- Display model converts correctly
64+
65+
2. **Functional tests** — In `tests/functional/`:
66+
- Happy-path test (command succeeds with real API)
67+
- Error-path test (invalid input, not-found)
68+
- JSON output test (`--format json` produces valid, parseable JSON)
69+
70+
3. **Update coverage script** — Add to `scripts/check-test-coverage.sh`
71+
72+
### 2.3 Verify Stubs Compile
73+
74+
```bash
75+
cargo test --no-run
76+
```
77+
78+
Tests should compile but may not pass yet (that's expected at this stage).
79+
80+
## Stage 3: Implementation
81+
82+
Follow the implementation order from `/add-command`:
83+
84+
1. API models (`src/client/models/`)
85+
2. Trait method (`src/client/mod.rs`)
86+
3. API implementation (`src/client/api/` or `src/client/stackhawk.rs`)
87+
4. Mock implementation (`src/client/mock.rs`)
88+
5. Display model (`src/models/display/`)
89+
6. CLI command enum (`src/cli/mod.rs`)
90+
7. Handler (`src/cli/<command>.rs`)
91+
8. Main routing (`src/main.rs`)
92+
93+
After each file, run `cargo check` to catch errors early.
94+
95+
## Stage 4: Verify
96+
97+
### 4.1 Quality Gate
98+
99+
Run the full quality suite:
100+
```bash
101+
cargo fmt -- --check
102+
cargo clippy -- -D warnings
103+
cargo test
104+
```
105+
106+
### 4.2 CLI Design Compliance
107+
108+
Run through the CLI design checklist (`.claude/skills/cli-designer/checklist.md`):
109+
- Help text with examples
110+
- JSON output valid
111+
- stdout/stderr separation
112+
- Exit codes correct
113+
- Navigation hints present
114+
- Non-TTY compatible
115+
116+
### 4.3 Functional Tests
117+
118+
```bash
119+
HAWKOP_PROFILE=test HAWKOP_FUNCTIONAL_TESTS_CONFIRM=yes \
120+
cargo test --features functional-tests --test functional -- --test-threads=1 --nocapture "<test_pattern>"
121+
```
122+
123+
### 4.4 Test Coverage
124+
125+
```bash
126+
./scripts/check-test-coverage.sh
127+
```
128+
129+
## Stage 5: Documentation
130+
131+
Update all relevant docs:
132+
- [ ] `docs/CLI_REFERENCE.md` — New command, flags, examples
133+
- [ ] `docs/ROADMAP.md` — Mark endpoint as complete, update coverage count
134+
- [ ] `CHANGELOG.md` — Entry under `[Unreleased]`
135+
- [ ] `CLAUDE.md` — Add to command list if new top-level command
136+
137+
## Stage 6: Pre-Commit
138+
139+
Run `/pre-commit` for the final check before the user commits.
140+
141+
Present a summary:
142+
```
143+
Feature Implementation Summary
144+
==============================
145+
Command: hawkop <cmd> <subcmd>
146+
API endpoint(s): <method> <path>
147+
Files created: N new files
148+
Files modified: N existing files
149+
Tests: N unit, N functional
150+
Docs updated: CLI_REFERENCE, ROADMAP, CHANGELOG
151+
Quality: fmt OK, clippy OK, tests OK
152+
Coverage: N/N commands tested
153+
```

0 commit comments

Comments
 (0)