stemedb/sdk/go/adk/tools_constraint.go
jordan b3e8a9a058 feat: Multi-application expansion with chaos testing and community UI
Major additions:
- Community Next.js app (port 18187) for browsing claims with API docs
- stemedb-chaos crate: Fault injection, chaos testing, CRDT properties
- Latent ingestion system: Reddit/FDA ingesters with ADK-Go agents
- Disputed claims handling: Manual review workflows and validation
- Aphoria security scanner: New extractors (SQL injection, command
  injection, weak crypto, TLS version), policy-based ignores, UAT reports
- Docker infrastructure: Dockerfile, docker-compose.yml for full stack
- VulnBank demo: Intentionally vulnerable multi-language test corpus

SDK & API enhancements:
- Source registry handlers for tracking data provenance
- Metrics endpoint
- Skeptic filtering improvements

Code quality:
- Split 14 large files (>500 lines) into focused modules
- All files now under 500-line limit per project guidelines

Documentation:
- Chaos testing guide, circuit breakers, observability docs
- Phase 7 UAT documentation updates
- Martin Kleppmann technical writer agent

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 01:24:14 -07:00

65 lines
1.9 KiB
Go

package adk
import (
"context"
"encoding/json"
"fmt"
"github.com/orchard9/stemedb-go/steme"
)
// ConstraintCheckTool provides pre-flight validation for Implementation Agent.
//
// Returns must-use and forbidden patterns for a given context.
type ConstraintCheckTool struct {
client EpistemeClient
}
// NewConstraintCheckTool creates a new ConstraintCheck tool.
func NewConstraintCheckTool(client EpistemeClient) *ConstraintCheckTool {
return &ConstraintCheckTool{client: client}
}
// Name returns the tool name.
func (t *ConstraintCheckTool) Name() string {
return "episteme_constraint_check"
}
// Description returns the tool description.
func (t *ConstraintCheckTool) Description() string {
return "Check for must-use and forbidden patterns before code generation. " +
"Returns constraints with explanations for contrastive learning. " +
"Implementation Agent MUST call this before writing code."
}
// Execute performs the constraint check.
func (t *ConstraintCheckTool) Execute(ctx context.Context, input []byte) ([]byte, error) {
var params ConstraintCheckInput
if err := json.Unmarshal(input, &params); err != nil {
return nil, fmt.Errorf("invalid constraint check input: %w", err)
}
// Query for constraints in the given context
// This queries for assertions with predicate "must_use" or "forbidden"
builder := steme.NewQuery().
WithSubject(params.Context).
WithLifecycle(steme.LifecycleApproved). // Only approved constraints
WithLens(steme.LensAuthority)
result, err := t.client.Query(ctx, builder.Build())
if err != nil {
return nil, fmt.Errorf("constraint query failed: %w", err)
}
// Convert assertions to constraints
constraints := convertToConstraints(result)
outputBytes, err := json.Marshal(ConstraintCheckOutput{
Constraints: constraints,
})
if err != nil {
return nil, fmt.Errorf("failed to marshal constraint output: %w", err)
}
return outputBytes, nil
}