Intelligence Layer
Shipwright’s intelligence layer replaces hardcoded heuristics with AI-powered analysis at every decision point in the delivery pipeline. From issue triage to model selection to architecture validation, intelligence modules make context-aware decisions that improve over time.
All intelligence features are behind feature flags and degrade gracefully to static fallbacks when disabled. Intelligence uses auto mode by default: enabled when Claude CLI is available; set intelligence.enabled=false to explicitly disable.
Overview
Section titled “Overview”The intelligence layer consists of seven specialized modules that work together:
- Intelligence Core — Analyzes issues semantically, manages cached analysis, and provides unified API
- Pipeline Composer — Dynamically composes pipeline configurations from analysis
- Self-Optimize — Learns from historical metrics and tunes configuration
- Predictive Analytics — Pre-pipeline risk assessment and anomaly detection
- Adversarial Review — Red-team code for edge cases and security issues
- Developer Simulation — Simulates reviewer personas before PR submission
- Architecture Enforcer — Validates changes against established architectural patterns
Enabling Intelligence
Section titled “Enabling Intelligence”The intelligence flags default to "auto". Each one turns on when the Claude CLI is detected, and daemon init writes these values. The modules that are off by default are adversarial, simulation, and architecture. Override in .claude/daemon-config.json:
{ "intelligence": { "enabled": "auto", "cache_ttl_seconds": 3600, "composer_enabled": "auto", "optimization_enabled": "auto", "prediction_enabled": "auto", "adversarial_enabled": false, "simulation_enabled": false, "architecture_enabled": false, "ab_test_ratio": 0.2, "anomaly_threshold": 3.0 }}Default configuration (written by daemon init to .claude/daemon-config.json):
enabled: "auto"— Master switch. On when the Claude CLI is detected.optimization_enabled: "auto"— Learn from every pipeline runprediction_enabled: "auto"— Risk assessment before pipeline starts
Enable additional modules as your workflows mature:
composer_enabled— Custom pipelines based on issue analysis, set to"auto"by default (advanced)adversarial_enabled: true— Extra code review pass (slower pipelines)simulation_enabled: true— Simulate PR review before submittingarchitecture_enabled: true— Enforce architectural patterns (requires initial model build)
Intelligence Core
Section titled “Intelligence Core”The sw-intelligence.sh module provides semantic analysis and unified APIs for all other intelligence modules.
Issue Analysis
Section titled “Issue Analysis”Analyzes GitHub issues semantically instead of just counting words and matching regex patterns:
shipwright intelligence analyze '{"title":"Add OAuth2 support","body":"Users can't...","labels":"feature,auth"}'Returns structured analysis:
{ "complexity": 7, "risk_level": "high", "success_probability": 65, "recommended_template": "standard", "key_risks": ["scope creep", "security validation", "backward compatibility"], "implementation_hints": [ "start with design phase", "security review required" ]}Pipeline Composition
Section titled “Pipeline Composition”Generates initial pipeline configuration from issue analysis:
shipwright intelligence compose <analysis_json> [repo_context] [budget_usd]Cost Prediction
Section titled “Cost Prediction”Estimates cost and iterations before pipeline runs:
shipwright intelligence predict <analysis_json> [historical_data]Returns:
{ "estimated_cost_usd": 12.5, "estimated_iterations": 8, "estimated_tokens": 750000, "likely_failure_stage": "test", "confidence": 75}Memory Search
Section titled “Memory Search”Ranks memory entries by relevance to current context:
shipwright intelligence search-memory "auth refactor" [memory_dir] [top_n]Model Recommendation
Section titled “Model Recommendation”Recommends the right model (opus/sonnet/haiku) for each stage based on complexity and budget:
shipwright intelligence recommend-model design 8 50Pipeline Composer
Section titled “Pipeline Composer”The sw-pipeline-composer.sh module creates custom pipelines tailored to each issue.
Dynamic Composition
Section titled “Dynamic Composition”Instead of selecting a static template, the composer generates a pipeline that matches the issue:
- Low complexity issues → Skip plan/design stages, focus on build/test
- High-risk issues → Add extra review and validation stages
- Budget-constrained runs → Downgrade Opus to Sonnet in later stages
- Security issues → Insert dedicated security audit stage
Conditional Stage Insertion
Section titled “Conditional Stage Insertion”Insert specialized stages dynamically:
composer_insert_conditional_stage <pipeline> after_review '{"id":"security_audit","enabled":true,"model":"opus"}'Model Downgrading
Section titled “Model Downgrading”When budget runs low, downgrade remaining stages to cheaper models:
composer_downgrade_models <pipeline> from_test_stageSelf-Optimization
Section titled “Self-Optimization”The sw-self-optimize.sh module learns from every pipeline run and automatically tunes configuration.
Outcome Analysis
Section titled “Outcome Analysis”Records metrics from each completed pipeline:
shipwright optimize analyze-outcome .claude/pipeline-state.mdTracks: complexity, template used, result, iterations, cost, and per-stage outcomes.
Template Tuning
Section titled “Template Tuning”Analyzes success/failure rates per template and label combination:
shipwright optimize tuneAdjusts template weights over time:
{ "standard|feature": 1.1, "standard|bugfix": 0.9, "fast|hotfix": 1.0}Iteration Learning
Section titled “Iteration Learning”Builds a prediction model for build iterations by complexity:
{ "low": { "mean": 3.2, "stddev": 1.1, "samples": 24 }, "medium": { "mean": 8.5, "stddev": 2.3, "samples": 18 }, "high": { "mean": 15.2, "stddev": 4.1, "samples": 12 }}Model Routing
Section titled “Model Routing”Tracks per-stage model success rates and recommends cheaper models when viable:
{ "build": { "recommended": "sonnet", "sonnet_rate": 92.5, "opus_rate": 95.0, "sonnet_samples": 20, "opus_samples": 5 }}Switches from Opus to Sonnet when Sonnet achieves 90%+ success rate with sufficient samples.
Memory Evolution
Section titled “Memory Evolution”Prunes stale failure patterns, strengthens confirmed ones, and promotes cross-repo patterns:
shipwright optimize evolve-memoryContext Efficiency Closed Loop
Section titled “Context Efficiency Closed Loop”The self-optimization module includes a context efficiency feedback loop that analyzes how well pipeline agents use their context budgets:
- Budget utilization tracking — Measures what percentage of the context budget each iteration uses
- Trim ratio monitoring — Tracks how much content gets trimmed by the context engineering layer
- Automatic recommendations — When utilization is consistently high (>90%), recommends increasing budget; when low (under 50%), recommends decreasing to save tokens; when trim ratio is high (>30%), recommends reducing verbose context sections
shipwright optimize tune # Includes context efficiency analysisContext efficiency events are also visible in the dashboard via the /api/context-efficiency endpoint.
Predictive Analytics
Section titled “Predictive Analytics”The sw-predictive.sh module assesses pipeline risk and detects anomalies.
Pre-Pipeline Risk Assessment
Section titled “Pre-Pipeline Risk Assessment”Analyzes issues before pipeline starts to identify high-risk work:
shipwright predict risk <issue_json>Returns:
{ "overall_risk": 72, "failure_stages": [ { "stage": "build", "risk": 85, "reason": "Complex refactor with many dependencies" }, { "stage": "test", "risk": 65, "reason": "Difficult to test concurrent changes" } ], "preventative_actions": [ "Add integration tests first", "Validate dependency impact" ]}AI Patrol
Section titled “AI Patrol”Replaces grep-based checks with AI analysis of sampled source files:
patrol_ai_analyze <sample_files> [git_log]Analyzes code for high/critical security, performance, architecture, and testing issues.
Anomaly Detection
Section titled “Anomaly Detection”Compares current pipeline metrics against baselines:
predict_detect_anomaly build test_duration 45.2Returns: normal, warning, or critical based on deviation from historical baseline.
Preventative Injection
Section titled “Preventative Injection”Injects prevention context into stages based on memory patterns for similar work.
Adversarial Review
Section titled “Adversarial Review”The sw-adversarial.sh module adds a red-team code review pass.
After the primary agent writes code, an adversarial agent tries to break it:
shipwright adversarial review <code_diff> [context]Returns findings with severity (critical/high/medium/low) and exploit scenarios:
[ { "severity": "critical", "category": "security", "description": "SQL injection in query builder", "location": "db.ts:145", "exploit_scenario": "Pass malicious WHERE clause in user input" }]Iterative Hardening
Section titled “Iterative Hardening”Up to 3 rounds of find-and-fix. After adversarial review finds issues, the primary agent addresses them and the adversarial agent re-reviews:
shipwright adversarial iterate <primary_code> <findings_json> [round]Use ADVERSARIAL_MAX_ROUNDS environment variable to control iteration count (default: 3).
Developer Simulation
Section titled “Developer Simulation”The sw-developer-simulation.sh module simulates reviewer personas before PR submission.
Instead of waiting for human review, simulate three reviewer personas:
shipwright simulation review <pr_diff> [pr_description]Reviewer Personas
Section titled “Reviewer Personas”- Security — Focuses on authentication, injection risks, data exposure, privilege escalation
- Performance — Focuses on N+1 queries, allocations, caching, algorithmic complexity
- Maintainability — Focuses on code smells, test coverage, naming, coupling
Each persona returns concerns with severity and specific suggestions.
Address Objections
Section titled “Address Objections”After simulated review, the agent addresses each concern:
shipwright simulation address <objections_json> [implementation_context]Returns for each concern: will_fix, wont_fix, or already_addressed, with explanations.
Use SIMULATION_MAX_ROUNDS environment variable (default: 3).
Architecture Enforcer
Section titled “Architecture Enforcer”The sw-architecture-enforcer.sh module validates changes against established architectural patterns.
Build Architecture Model
Section titled “Build Architecture Model”Analyzes codebase structure and establishes the architectural model:
shipwright architecture build [repo_root]Extracts:
- Layers — Presentation, business, data, etc.
- Patterns — MVC, provider, pipeline, middleware, etc.
- Conventions — Naming, file organization, dependency direction
- Dependencies — External libraries and their roles
Model is stored per repo at ~/.shipwright/memory/<repo-hash>/architecture.json.
Validate Changes
Section titled “Validate Changes”Check if code changes respect the architectural model:
shipwright architecture validate <diff> [model_file]Returns violations with severity, the pattern broken, and suggestions.
Evolve Model
Section titled “Evolve Model”When legitimate architectural changes are made, update the model:
shipwright architecture evolve [model_file] <changes_summary>The system decides if changes represent intentional evolution and updates the model accordingly.
CLI Commands
Section titled “CLI Commands”Intelligence
Section titled “Intelligence”shipwright intelligence analyze <issue_json> # Semantic issue analysisshipwright intelligence compose <analysis> [ctx] [$$] # Dynamic pipeline compositionshipwright intelligence predict <analysis> [history] # Cost and effort predictionshipwright intelligence synthesize <findings_json> # Unify findings into strategyshipwright intelligence search-memory <context> [dir] # Ranked memory searchshipwright intelligence recommend-model <stage> [cplx]# Model recommendationshipwright intelligence cache-stats # Show cache statisticsshipwright intelligence cache-clear # Clear intelligence cacheSelf-Optimize
Section titled “Self-Optimize”shipwright optimize analyze-outcome <state-file> # Record pipeline outcomeshipwright optimize tune # Run full optimizationshipwright optimize report # Show 7-day reportshipwright optimize evolve-memory # Evolve memory patternsPredict
Section titled “Predict”shipwright predict risk <issue_json> # Pre-pipeline risk assessmentshipwright predict anomaly <stage> <metric> <value> # Detect metric anomalyAdversarial
Section titled “Adversarial”shipwright adversarial review <diff> [context] # Red-team code reviewshipwright adversarial iterate <code> <findings> [r] # Iterative hardeningSimulation
Section titled “Simulation”shipwright simulation review <diff> [description] # Multi-persona PR reviewshipwright simulation address <objections> [ctx] # Address reviewer concernsArchitecture
Section titled “Architecture”shipwright architecture build [repo_root] # Build architecture modelshipwright architecture validate <diff> [model] # Validate against modelshipwright architecture evolve <model> <changes> # Evolve modelConfiguration Reference
Section titled “Configuration Reference”All intelligence settings go in .claude/daemon-config.json under intelligence:
| Setting | Default | Purpose |
|---|---|---|
enabled |
"auto" |
Master switch (on when the Claude CLI is detected) |
cache_ttl_seconds |
3600 |
How long analysis results are cached |
composer_enabled |
"auto" |
Enable dynamic pipeline composition |
optimization_enabled |
"auto" |
Enable self-tuning based on DORA metrics |
prediction_enabled |
"auto" |
Enable risk assessment and anomaly detection |
adversarial_enabled |
false |
Enable adversarial code review pass |
simulation_enabled |
false |
Enable developer workflow simulation |
architecture_enabled |
false |
Enable architecture rule enforcement |
ab_test_ratio |
0.2 |
Fraction of runs using composed pipelines (A/B test) |
anomaly_threshold |
3.0 |
Standard deviations from baseline for anomaly alert |
Performance Considerations
Section titled “Performance Considerations”Caching
Section titled “Caching”Intelligence analysis results are cached to avoid repeated Claude calls. Cache TTL defaults to 1 hour but can be customized:
- Issue analysis — Cached by title+body hash
- Pipeline composition — Cached by analysis+budget hash
- Memory search — Cached by context+directory hash
- Risk assessment — Cached per-issue
Clear cache with shipwright intelligence cache-clear.
Feature Flag Interactions
Section titled “Feature Flag Interactions”Optimization and prediction default to "auto", which turns them on when the Claude CLI is detected. Enable additional features in order of impact:
- Default:
optimization_enabled+prediction_enabledset to"auto"— Active when the Claude CLI is detected - Phase 2:
simulation_enabled: true— Simulated PR review (adds time) - Phase 3:
adversarial_enabled: true— Red-team review (slower) - Advanced:
architecture_enabled: true,composer_enabled: true
The default configuration gives immediate feedback without slowing pipelines significantly.
A/B Testing
Section titled “A/B Testing”With composer_enabled: true, ab_test_ratio controls how often composed pipelines are used. Set to 0.1 (10%) initially to compare against standard templates before full rollout.
Monitoring Intelligence
Section titled “Monitoring Intelligence”View Cache Statistics
Section titled “View Cache Statistics”shipwright intelligence cache-statsShows cache hit rate and age of entries.
Review Optimization Report
Section titled “Review Optimization Report”shipwright optimize reportShows last 7 days of metrics, template weights, model routing recommendations, and iteration model statistics.
Check Predictive Alerts
Section titled “Check Predictive Alerts”Prediction findings are logged to ~/.shipwright/events.jsonl with type prediction.*:
grep 'prediction' ~/.shipwright/events.jsonl | tail -20Architecture Model Status
Section titled “Architecture Model Status”cat ~/.shipwright/memory/<repo-hash>/architecture.json | jq .Troubleshooting
Section titled “Troubleshooting”Intelligence Disabled or Unavailable
Section titled “Intelligence Disabled or Unavailable”Ensure intelligence.enabled is "auto" or true in daemon config and the Claude CLI is available:
which claudeclaude --versionCache Stale or Growing
Section titled “Cache Stale or Growing”Clear cache if analysis is outdated:
shipwright intelligence cache-clearMonitor cache size — it grows as more unique issues are analyzed. Clear periodically if size exceeds 10MB.
Anomalies Not Detected
Section titled “Anomalies Not Detected”Set baseline by running several pipelines, then enable anomaly detection. Threshold is configurable via anomaly_threshold (default: 3.0 standard deviations).
Architecture Violations Not Found
Section titled “Architecture Violations Not Found”First build the architecture model:
shipwright architecture buildThen validate changes. Model must exist for validation to work.
Next Steps
Section titled “Next Steps”See related guides for complementary features:
- Persistent Memory — How the system learns from failures
- Cost Intelligence — Token tracking and budget management
- Self-Optimization — DORA-driven tuning
- Continuous Loop — The autonomous development loop