This commit adds the read path (Cortex) to complement the write path (Spine): ## Crates - stemedb-api: HTTP API with axum + utoipa OpenAPI - /v1/assert, /v1/query, /v1/epoch, /v1/skeptic, /v1/trace, /v1/audit - Metered endpoints with quota enforcement - Ed25519 signature verification - stemedb-lens: Truth resolution lenses - RecencyLens, ConsensusLens, ConfidenceLens - VoteAwareConsensusLens (Ballot Box pattern) - TrustAwareAuthorityLens (The Hive pattern) - SkepticLens (conflict analysis) - EpochAwareLens (paradigm-safe queries) - stemedb-query: Query engine with materialized views ## Storage Extensions - VoteStore: Vote aggregation with cached counts - TrustRankStore: Agent reputation with decay - AuditStore: Query audit trail - IndexStore: SP/P/S index structures - SupersessionStore: Epoch supersession chains ## SDKs - sdk/go/steme: Go HTTP client with Ed25519 signing - sdk/go/adk: ADK-Go tools for AI agents ## Documentation - Updated CLAUDE.md, architecture.md, roadmap.md - New ai-lookup entries for all services - Use case docs for consumer health intelligence - Arena roadmap for simulation advancement Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
105 lines
3.1 KiB
Go
105 lines
3.1 KiB
Go
// Package main demonstrates basic StemeDB SDK usage.
|
|
//
|
|
// This example shows:
|
|
// - Creating a signer (keypair)
|
|
// - Building an assertion with the fluent API
|
|
// - Submitting to StemeDB (auto-signed)
|
|
// - Querying with a lens
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/orchard9/stemedb-go/steme"
|
|
)
|
|
|
|
func main() {
|
|
// 1. Generate a new keypair
|
|
//
|
|
// In production, you'd load this from environment or key management.
|
|
// For this example, we generate a new one each run.
|
|
signer, err := steme.GenerateSigner()
|
|
if err != nil {
|
|
log.Fatalf("Failed to generate signer: %v", err)
|
|
}
|
|
|
|
fmt.Printf("Agent ID (public key): %s\n", signer.PublicKey())
|
|
fmt.Printf("Seed (save this!): %s\n\n", signer.Seed())
|
|
|
|
// 2. Create a StemeDB client
|
|
//
|
|
// The client automatically signs all assertions using the signer.
|
|
client := steme.NewClient("http://localhost:3000", signer)
|
|
|
|
// 3. Build an assertion with the fluent API
|
|
//
|
|
// This asserts: "Tesla_Inc has_revenue 96.7 (billion USD)"
|
|
// with 95% confidence, marked as Approved, sourced from Clinical evidence.
|
|
assertion := steme.NewAssertion("Tesla_Inc", "has_revenue").
|
|
WithNumber(96.7).
|
|
WithConfidence(0.95).
|
|
WithLifecycle(steme.LifecycleApproved).
|
|
WithSourceClass(steme.SourceClassClinical).
|
|
WithSourceHash("0000000000000000000000000000000000000000000000000000000000000000").
|
|
Build()
|
|
|
|
// 4. Submit to StemeDB
|
|
//
|
|
// The client automatically:
|
|
// - Signs the assertion with your private key
|
|
// - Adds a timestamp
|
|
// - POSTs to /v1/assert
|
|
// - Returns the content-addressed hash
|
|
hash, err := client.Assert(context.Background(), assertion)
|
|
if err != nil {
|
|
log.Fatalf("Failed to assert: %v", err)
|
|
}
|
|
|
|
fmt.Printf("✓ Created assertion: %s\n\n", hash)
|
|
|
|
// 5. Query with lens-based conflict resolution
|
|
//
|
|
// This queries for "Tesla_Inc has_revenue" and uses the Consensus lens
|
|
// to resolve any conflicts (picks the most common value).
|
|
params := steme.NewQuery().
|
|
WithSubject("Tesla_Inc").
|
|
WithPredicate("has_revenue").
|
|
WithLens(steme.LensConsensus).
|
|
Build()
|
|
|
|
result, err := client.Query(context.Background(), params)
|
|
if err != nil {
|
|
log.Fatalf("Failed to query: %v", err)
|
|
}
|
|
|
|
fmt.Printf("Query Results:\n")
|
|
fmt.Printf(" Total: %d assertions\n", result.TotalCount)
|
|
fmt.Printf(" Has more: %v\n\n", result.HasMore)
|
|
|
|
for i, a := range result.Assertions {
|
|
fmt.Printf("Assertion #%d:\n", i+1)
|
|
fmt.Printf(" Hash: %s\n", a.Hash)
|
|
fmt.Printf(" Subject: %s\n", a.Subject)
|
|
fmt.Printf(" Predicate: %s\n", a.Predicate)
|
|
fmt.Printf(" Object: %v (%s)\n", a.Object.Value, a.Object.Type)
|
|
fmt.Printf(" Confidence: %.2f\n", a.Confidence)
|
|
fmt.Printf(" Lifecycle: %s\n", a.Lifecycle)
|
|
fmt.Printf(" Source Class: %s\n", a.SourceClass)
|
|
fmt.Printf(" Signatures: %d agents\n", len(a.Signatures))
|
|
fmt.Printf("\n")
|
|
}
|
|
|
|
// 6. Health check
|
|
health, err := client.Health(context.Background())
|
|
if err != nil {
|
|
log.Fatalf("Failed health check: %v", err)
|
|
}
|
|
|
|
fmt.Printf("StemeDB Health:\n")
|
|
fmt.Printf(" Status: %s\n", health.Status)
|
|
fmt.Printf(" Version: %s\n", health.Version)
|
|
fmt.Printf(" Assertions: %d\n", health.AssertionsCount)
|
|
}
|