Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions .claude/failure-patterns.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{
"version": "1.0",
"description": "Common failure patterns and suggested fixes for autonomous iteration",
"patterns": [
{
"id": "missing-import",
"regex": "Unresolved reference: (\\w+)",
"type": "compilation",
"severity": "error",
"fix": "Add import for $1",
"strategy": "search-and-import"
},
{
"id": "type-mismatch",
"regex": "Type mismatch: inferred type is (\\w+) but (\\w+) was expected",
"type": "compilation",
"severity": "error",
"fix": "Cast or convert $1 to $2",
"strategy": "analyze-types"
},
{
"id": "assertion-failure",
"regex": "expected:<(.+)> but was:<(.+)>",
"type": "test",
"severity": "error",
"fix": "Check test expectation or fix implementation",
"strategy": "compare-expected-actual"
},
{
"id": "null-pointer",
"regex": "NullPointerException|null cannot be cast to non-null",
"type": "runtime",
"severity": "error",
"fix": "Add null check or use safe call operator",
"strategy": "null-safety"
},
{
"id": "missing-function",
"regex": "Unresolved reference: (\\w+)\\(\\)",
"type": "compilation",
"severity": "error",
"fix": "Implement missing function $1 or add import",
"strategy": "implement-or-import"
},
{
"id": "missing-parameter",
"regex": "No value passed for parameter '(\\w+)'",
"type": "compilation",
"severity": "error",
"fix": "Add missing parameter $1 to function call",
"strategy": "add-parameter"
},
{
"id": "visibility-error",
"regex": "Cannot access '(\\w+)': it is (\\w+) in",
"type": "compilation",
"severity": "error",
"fix": "Change visibility of $1 from $2 to internal/public",
"strategy": "adjust-visibility"
},
{
"id": "suspend-context",
"regex": "Suspend function '(\\w+)' should be called only from a coroutine",
"type": "compilation",
"severity": "error",
"fix": "Wrap call in coroutine scope or make calling function suspend",
"strategy": "coroutine-context"
},
{
"id": "http-status-mismatch",
"regex": "expected:<(\\d+)> but was:<(\\d+)>.*HttpStatusCode",
"type": "test",
"severity": "error",
"fix": "Check route handler returns correct status code",
"strategy": "analyze-http-response"
},
{
"id": "json-parse-error",
"regex": "JsonDecodingException|Unexpected JSON token",
"type": "runtime",
"severity": "error",
"fix": "Check JSON structure matches expected DTO",
"strategy": "validate-json-schema"
},
{
"id": "timeout",
"regex": "Timed out waiting for|SocketTimeoutException",
"type": "runtime",
"severity": "warning",
"fix": "Increase timeout or check for blocking operations",
"strategy": "async-analysis"
},
{
"id": "connection-refused",
"regex": "Connection refused|ConnectException",
"type": "runtime",
"severity": "error",
"fix": "Ensure service is running (Postgres/Redis in CI)",
"strategy": "check-services"
}
],
"strategies": {
"search-and-import": {
"description": "Search codebase for symbol definition and add import",
"steps": [
"Grep for 'class $1' or 'fun $1' or 'object $1'",
"Find package declaration in matching file",
"Add import statement to failing file"
]
},
"analyze-types": {
"description": "Analyze type hierarchy and apply correct conversion",
"steps": [
"Check if types are related (inheritance)",
"If convertible, add explicit cast or conversion",
"If not, fix the source of wrong type"
]
},
"compare-expected-actual": {
"description": "Compare expected vs actual values to identify root cause",
"steps": [
"Read the test to understand intent",
"Read the implementation under test",
"Determine if test expectation is wrong or implementation is wrong",
"Fix the appropriate side"
]
},
"null-safety": {
"description": "Apply Kotlin null safety patterns",
"steps": [
"Identify source of null value",
"Add null check with ?. or ?: operator",
"Or fix the source to not produce null"
]
}
}
}
59 changes: 59 additions & 0 deletions .claude/quality-gates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"version": "1.0",
"description": "Quality gates for DeepLine autonomous development",
"gates": {
"build": {
"command": "./gradlew assemble",
"description": "All modules must compile successfully",
"required": true
},
"server-tests": {
"command": "./gradlew :server:test --info",
"description": "Server unit and integration tests",
"required": true,
"minCoverage": 70
},
"shared-tests": {
"command": "./gradlew :shared:serverTest --info",
"description": "Shared module JVM/server tests",
"required": true,
"minCoverage": 80
},
"android-tests": {
"command": "./gradlew :clients:android:app:testDebugUnitTest --info",
"description": "Android unit tests",
"required": true
},
"security": {
"description": "Crypto boundary and security checks",
"checks": [
"no-plaintext-server",
"crypto-interfaces-only",
"secure-random",
"rate-limiting",
"no-hardcoded-secrets"
],
"required": true
},
"lint": {
"command": "./gradlew ktlintCheck",
"description": "Kotlin code style",
"required": false
}
},
"autoFix": {
"enabled": true,
"maxIterations": 5,
"failurePatterns": ".claude/failure-patterns.json",
"strategy": "fix-and-retest"
},
"coverage": {
"tool": "kover",
"reportCommand": "./gradlew koverHtmlReport",
"thresholds": {
"server": 70,
"shared": 80,
"android": 60
}
}
}
108 changes: 108 additions & 0 deletions .claude/skills/ai-iterate/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# AI Iterate Skill

Autonomous iteration loop for fixing failures without human intervention.

## Trigger

Use this skill when:
- CI has failed and needs fixing
- Multiple test failures need resolution
- Asked to "fix all the tests" or "make it work"

## Core Algorithm

```
FAILURE_QUEUE = parse_failures(test_output)
ITERATION = 0
MAX_ITERATIONS = 5

while FAILURE_QUEUE not empty AND ITERATION < MAX_ITERATIONS:
ITERATION++

failure = FAILURE_QUEUE.pop()

# Analyze
pattern = match_failure_pattern(failure, ".claude/failure-patterns.json")
source_file = identify_source_file(failure)
test_file = identify_test_file(failure)

# Read context
read(source_file)
read(test_file)

# Generate fix
fix = generate_fix(failure, pattern, context)

# Apply fix
apply_edit(source_file, fix)

# Verify
result = run_test(test_file, failure.test_method)

if result.passed:
log("Fixed: " + failure.description)
else if result.new_failure:
FAILURE_QUEUE.push(result.new_failure)
log("New failure discovered, adding to queue")
else:
# Same failure - try alternative approach
alternative_fix = generate_alternative_fix(failure, pattern)
apply_edit(source_file, alternative_fix)
# Re-test...

# Final verification
run_full_suite()
```

## Failure Pattern Matching

Reference `.claude/failure-patterns.json` for common patterns:

| Pattern | Strategy |
|---------|----------|
| `Unresolved reference: X` | Search codebase for X, add import |
| `Type mismatch` | Analyze types, add cast/conversion |
| `expected:<A> but was:<B>` | Compare test vs implementation |
| `NullPointerException` | Add null safety |
| `Suspend function` | Add coroutine context |

## Iteration Limits

- **Per failure**: Max 3 fix attempts before escalating
- **Total iterations**: Max 5 rounds through the queue
- **Time limit**: None (complete the task)

## When to Escalate

If after MAX_ITERATIONS failures remain:
1. Document what was tried
2. Identify the root cause pattern
3. Suggest architectural changes if needed
4. Create a detailed issue for human review

## Example Session

```
[Iteration 1]
Failure: UserRoutesTest.testCreateUser - expected 201 but was 400
Pattern: http-status-mismatch
Action: Read UserRoutes.kt, found missing validation
Fix: Added email format validation
Result: PASS

[Iteration 2]
Failure: MessageRoutesTest.testSendMessage - NullPointerException
Pattern: null-pointer
Action: Read MessageRoutes.kt, conversation lookup returns null
Fix: Added null check with proper error response
Result: PASS

[Final] All tests passing ✓
```

## Integration

This skill works with:
- `ci-loop` - Provides the test execution
- `test-gaps` - Identifies missing coverage
- `security-scan` - Validates crypto boundary
Loading
Loading