chore: delete code no binary or test reaches
This commit is contained in:
1 parent
7986ccb3f7
commit
01acb97f96
34 files changed
+1
-1483
No files matched your search
@@ -55,19 +55,6 @@ const (
|
||||
DecisionValid
|
||||
)
|
||||
|
||||
func (d Decision) String() string {
|
||||
switch d {
|
||||
case DecisionNone:
|
||||
return "none"
|
||||
case DecisionStale:
|
||||
return "stale"
|
||||
case DecisionValid:
|
||||
return "valid"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
// Decide returns the decision for marker. Nil means none; an empty current
|
||||
// epoch or a mismatched marker is stale.
|
||||
func Decide(current Epoch, marker *Marker) Decision {
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
// Package image defines the image generation provider contract.
|
||||
package image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Sentinel errors every provider wraps with fmt.Errorf("%w: %s", ...) so
|
||||
// callers can errors.Is regardless of backend.
|
||||
var (
|
||||
// ErrUnavailable means the provider cannot serve right now (missing
|
||||
// credential, backend down). Per the epic: this must degrade the
|
||||
// capability to a reported error, never prevent Archie from starting
|
||||
// or break text chat.
|
||||
ErrUnavailable = errors.New("image provider unavailable")
|
||||
// ErrUnsupported means the request needs a capability (e.g. Edit, or
|
||||
// Mask) the provider does not declare.
|
||||
ErrUnsupported = errors.New("image capability unsupported by provider")
|
||||
// ErrInputTooLarge means an input image exceeded a limit the provider
|
||||
// itself enforces. Caller-side limits are the routing layer's concern,
|
||||
// not this contract's — see the design doc.
|
||||
ErrInputTooLarge = errors.New("image input exceeds configured limit")
|
||||
// ErrTimeout means the provider's own deadline elapsed, distinct from
|
||||
// the caller's ctx being canceled.
|
||||
ErrTimeout = errors.New("image request timed out")
|
||||
// ErrCanceled means the caller's ctx was canceled.
|
||||
ErrCanceled = errors.New("image request canceled")
|
||||
)
|
||||
|
||||
// ProviderClass distinguishes hosted (spends money/quota per call) from
|
||||
// local (spends host GPU/time). Selection and config validation key off
|
||||
// this, never off Name, so a new provider cannot silently slip through the
|
||||
// hosted-cost gate under an unrecognized name.
|
||||
type ProviderClass string
|
||||
|
||||
const (
|
||||
ClassHosted ProviderClass = "hosted"
|
||||
ClassLocal ProviderClass = "local"
|
||||
)
|
||||
|
||||
// Capability declares what one provider supports, discoverable before a
|
||||
// request is built so a caller can reject an unsupported combination (e.g.
|
||||
// edit-with-mask on a generate-only provider) instead of sending it and
|
||||
// parsing a provider-specific error back out.
|
||||
type Capability struct {
|
||||
Generate bool
|
||||
// Edit requires at least one input image. MaxInputs bounds how many.
|
||||
Edit bool
|
||||
MaxInputs int
|
||||
// Mask reports whether Edit supports restricting the edited region to
|
||||
// a mask image.
|
||||
Mask bool
|
||||
// Sizes lists provider-declared output sizes (e.g. "1024x1024"). Empty
|
||||
// means the provider does not constrain size.
|
||||
Sizes []string
|
||||
}
|
||||
|
||||
// Validate checks that a declared Capability is internally consistent:
|
||||
// Edit implies at least one allowed input, and Mask cannot be declared
|
||||
// without Edit.
|
||||
func (c Capability) Validate() error {
|
||||
if c.Edit && c.MaxInputs < 1 {
|
||||
return errors.New("image capability: edit requires MaxInputs >= 1")
|
||||
}
|
||||
if c.Mask && !c.Edit {
|
||||
return errors.New("image capability: mask requires edit")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ImageData carries image bytes in-process, never a path or URL: the
|
||||
// domain layer must not assume a filesystem or a fetchable location.
|
||||
type ImageData struct {
|
||||
Bytes []byte
|
||||
MIMEType string
|
||||
}
|
||||
|
||||
// GenerateRequest asks a provider to create images from a prompt alone.
|
||||
type GenerateRequest struct {
|
||||
Prompt string
|
||||
// Size is a provider-declared value from Capability.Sizes, or "" for
|
||||
// the provider's default.
|
||||
Size string
|
||||
// N is the number of images requested. Zero means 1.
|
||||
N int
|
||||
// Options carries provider-specific overflow (e.g. "quality"),
|
||||
// deliberately untyped so the contract does not grow a field per
|
||||
// provider.
|
||||
Options map[string]string
|
||||
}
|
||||
|
||||
// Validate checks the fields every provider needs regardless of backend.
|
||||
func (r GenerateRequest) Validate() error {
|
||||
if r.Prompt == "" {
|
||||
return errors.New("image generate request: prompt must not be empty")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditRequest asks a provider to edit one or more input images per a
|
||||
// prompt, optionally restricted to a masked region.
|
||||
type EditRequest struct {
|
||||
Prompt string
|
||||
Inputs []ImageData
|
||||
// Mask restricts the edited region. Only valid when the provider's
|
||||
// Capability.Mask is true.
|
||||
Mask *ImageData
|
||||
Size string
|
||||
N int
|
||||
|
||||
Options map[string]string
|
||||
}
|
||||
|
||||
// Validate checks the fields every provider needs regardless of backend.
|
||||
// Capability-specific bounds (MaxInputs, Mask support) are the provider's
|
||||
// own responsibility to enforce against its declared Capability.
|
||||
func (r EditRequest) Validate() error {
|
||||
if r.Prompt == "" {
|
||||
return errors.New("image edit request: prompt must not be empty")
|
||||
}
|
||||
if len(r.Inputs) == 0 {
|
||||
return errors.New("image edit request: at least one input image is required")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Result is what a provider returns from Generate or Edit.
|
||||
type Result struct {
|
||||
Images []ImageData
|
||||
Provider string
|
||||
Model string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// Provider is the typed contract every image backend implements — hosted
|
||||
// (gpt-image-2-class) or local (GPU recipe).
|
||||
type Provider interface {
|
||||
Name() string
|
||||
Class() ProviderClass
|
||||
Capability() Capability
|
||||
Generate(ctx context.Context, req GenerateRequest) (Result, error)
|
||||
Edit(ctx context.Context, req EditRequest) (Result, error)
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package image
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"sync"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/lifecycle"
|
||||
)
|
||||
|
||||
// ErrDuplicate is returned when a provider name is already registered.
|
||||
var ErrDuplicate = errors.New("duplicate image provider")
|
||||
|
||||
// Registry is the image family owner: registration and discovery only. A
|
||||
// Provider is call-scoped (see package doc), so unlike curator's and
|
||||
// memory's registries there is no Start/Health/Stop to orchestrate here.
|
||||
type Registry struct {
|
||||
mu sync.RWMutex
|
||||
providers map[string]Provider
|
||||
}
|
||||
|
||||
// NewRegistry builds an empty provider registry.
|
||||
func NewRegistry() *Registry {
|
||||
return &Registry{providers: make(map[string]Provider)}
|
||||
}
|
||||
|
||||
// Register validates the provider's declared capability and adds it.
|
||||
// Registration fails on a nil provider, an invalid Capability, or a
|
||||
// duplicate name.
|
||||
func (r *Registry) Register(p Provider) error {
|
||||
if lifecycle.IsNil(p) {
|
||||
return errors.New("image: nil provider")
|
||||
}
|
||||
if err := p.Capability().Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
if _, dup := r.providers[p.Name()]; dup {
|
||||
return fmt.Errorf("%w: %s", ErrDuplicate, p.Name())
|
||||
}
|
||||
r.providers[p.Name()] = p
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get returns the registered provider by name.
|
||||
func (r *Registry) Get(name string) (Provider, bool) {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
p, ok := r.providers[name]
|
||||
return p, ok
|
||||
}
|
||||
|
||||
// Names returns every registered provider name, sorted.
|
||||
func (r *Registry) Names() []string {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
return slices.Sorted(maps.Keys(r.providers))
|
||||
}
|
||||
|
||||
// ByClass returns the sorted names of registered providers matching class.
|
||||
func (r *Registry) ByClass(class ProviderClass) []string {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
var names []string
|
||||
for name, p := range r.providers {
|
||||
if p.Class() == class {
|
||||
names = append(names, name)
|
||||
}
|
||||
}
|
||||
slices.Sort(names)
|
||||
return names
|
||||
}
|
||||
@@ -56,11 +56,6 @@ type Conversation struct {
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
// IsBranch reports whether this Conversation was forked from another.
|
||||
func (c Conversation) IsBranch() bool {
|
||||
return c.ParentConversationID != ConversationID{}
|
||||
}
|
||||
|
||||
// Message is one immutable, persisted turn in a Conversation.
|
||||
type Message struct {
|
||||
ID MessageID
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package sampling
|
||||
|
||||
import "context"
|
||||
|
||||
// allSampler is the "all" strategy: no filtering, returns every candidate
|
||||
// in input order, truncated to Request.Cap.
|
||||
type allSampler struct{}
|
||||
|
||||
// NewAll builds the "all" strategy.
|
||||
func NewAll() Sampler { return allSampler{} }
|
||||
|
||||
func (allSampler) Name() string { return "all" }
|
||||
|
||||
func (allSampler) Sample(_ context.Context, candidates []Candidate, req Request) ([]Candidate, error) {
|
||||
n := effectiveCap(req.Cap, len(candidates))
|
||||
out := make([]Candidate, n)
|
||||
copy(out, candidates[:n])
|
||||
return out, nil
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
// Package sampling is the curator sampler family: given a bounded set of
|
||||
// candidates, pick a subset to spend a curator pass's agentic budget on. The
|
||||
// embedding-backed surprisal strategy is a separate, deferred consumer of this
|
||||
// same interface -- it does not live here.
|
||||
package sampling
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Candidate is an item eligible for sampling.
|
||||
type Candidate struct {
|
||||
ID string
|
||||
At time.Time
|
||||
Metadata map[string]any
|
||||
}
|
||||
|
||||
// Request carries the knobs every strategy shares: a selection cap and a
|
||||
// deterministic seed. Both are optional -- Cap 0 (or negative) means
|
||||
// unlimited (the "all" strategy relies on this), Seed 0 is a valid seed,
|
||||
// not "unset".
|
||||
type Request struct {
|
||||
Cap int
|
||||
Seed int64
|
||||
}
|
||||
|
||||
// Sampler selects candidates for a curator pass. Implementations must be
|
||||
// deterministic.
|
||||
type Sampler interface {
|
||||
// Name identifies the strategy for logging/attribution (e.g.
|
||||
// "recency", "random", "all", "staleness", later "surprisal").
|
||||
Name() string
|
||||
// Sample selects from candidates per req. Implementations must not
|
||||
// mutate candidates or rely on anything but candidates and req --
|
||||
// determinism depends on that.
|
||||
Sample(ctx context.Context, candidates []Candidate, req Request) ([]Candidate, error)
|
||||
}
|
||||
|
||||
// effectiveCap resolves req.Cap against n candidates: zero, negative, or
|
||||
// larger than n means unlimited (every candidate); otherwise req.Cap.
|
||||
func effectiveCap(reqCap, n int) int {
|
||||
if reqCap <= 0 || reqCap > n {
|
||||
return n
|
||||
}
|
||||
return reqCap
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package sampling
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand/v2"
|
||||
)
|
||||
|
||||
// randomSampler is the "random" strategy: a uniform random subset, seeded
|
||||
// per call from Request.Seed so the same (candidates, req) pair always
|
||||
// produces the same selection -- a package-level or struct-level generator
|
||||
// would not give that guarantee under concurrent or repeated calls.
|
||||
type randomSampler struct{}
|
||||
|
||||
// NewRandom builds the "random" strategy.
|
||||
func NewRandom() Sampler { return randomSampler{} }
|
||||
|
||||
func (randomSampler) Name() string { return "random" }
|
||||
|
||||
func (randomSampler) Sample(_ context.Context, candidates []Candidate, req Request) ([]Candidate, error) {
|
||||
if len(candidates) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
n := effectiveCap(req.Cap, len(candidates))
|
||||
seed := uint64(req.Seed) // deterministic seeding, not a security boundary
|
||||
rng := rand.New(rand.NewPCG(seed, seed))
|
||||
order := rng.Perm(len(candidates))
|
||||
out := make([]Candidate, n)
|
||||
for i := range n {
|
||||
out[i] = candidates[order[i]]
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package sampling
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
)
|
||||
|
||||
// recencySampler is the "recency" strategy: prefers more recently
|
||||
// created/updated content, i.e. the largest Candidate.At first.
|
||||
type recencySampler struct{}
|
||||
|
||||
// NewRecency builds the "recency" strategy.
|
||||
func NewRecency() Sampler { return recencySampler{} }
|
||||
|
||||
func (recencySampler) Name() string { return "recency" }
|
||||
|
||||
func (recencySampler) Sample(_ context.Context, candidates []Candidate, req Request) ([]Candidate, error) {
|
||||
sorted := sortByTime(candidates, true)
|
||||
return sorted[:effectiveCap(req.Cap, len(sorted))], nil
|
||||
}
|
||||
|
||||
// sortByTime returns a stably sorted copy of candidates by At.
|
||||
func sortByTime(candidates []Candidate, newestFirst bool) []Candidate {
|
||||
sorted := append([]Candidate(nil), candidates...)
|
||||
slices.SortStableFunc(sorted, func(a, b Candidate) int {
|
||||
if newestFirst {
|
||||
return b.At.Compare(a.At)
|
||||
}
|
||||
return a.At.Compare(b.At)
|
||||
})
|
||||
return sorted
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package sampling
|
||||
|
||||
import "context"
|
||||
|
||||
// stalenessSampler prefers the oldest Candidate.At.
|
||||
type stalenessSampler struct{}
|
||||
|
||||
// NewStaleness builds the "staleness" strategy.
|
||||
func NewStaleness() Sampler { return stalenessSampler{} }
|
||||
|
||||
func (stalenessSampler) Name() string { return "staleness" }
|
||||
|
||||
func (stalenessSampler) Sample(_ context.Context, candidates []Candidate, req Request) ([]Candidate, error) {
|
||||
sorted := sortByTime(candidates, false)
|
||||
return sorted[:effectiveCap(req.Cap, len(sorted))], nil
|
||||
}
|
||||
@@ -548,24 +548,6 @@ func AddedLines(files []FileChange) []AddedLine {
|
||||
return added
|
||||
}
|
||||
|
||||
// MapLine maps a line of the file a change produces onto the diff: a line the
|
||||
// change added, a line a hunk quotes as context, or a line no hunk contains.
|
||||
func MapLine(files []FileChange, path string, line int) LineKind {
|
||||
for _, file := range files {
|
||||
if file.Path != path {
|
||||
continue
|
||||
}
|
||||
for _, hunk := range file.Hunks {
|
||||
for _, placed := range hunk.positions() {
|
||||
if placed.Line == line {
|
||||
return placed.Kind
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return LineOutside
|
||||
}
|
||||
|
||||
// SummarizeFiles computes the aggregate statistics of a parsed change.
|
||||
func SummarizeFiles(files []FileChange) DiffStats {
|
||||
stats := DiffStats{TotalFiles: len(files)}
|
||||
|
||||
@@ -125,46 +125,6 @@ func prepareWorktreeStage(name string, target func(*TaskContext) (PrepareTarget,
|
||||
}}
|
||||
}
|
||||
|
||||
// StageCommit commits everything in the worktree without pushing --
|
||||
// used mid-workflow so a PR tells its story in multiple commits (TDD:
|
||||
// failing tests first, fix second). An empty tree parks.
|
||||
func StageCommit(name string, message func(*TaskContext) string) Stage {
|
||||
return Stage{Name: name, Run: func(ctx context.Context, tc *TaskContext) error {
|
||||
changed, err := tc.Trees.CommitAll(ctx, tc.Dir, message(tc))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !changed {
|
||||
return fmt.Errorf("worktree has no changes to commit")
|
||||
}
|
||||
tc.captureChanges(ctx, capturedAfterCommit)
|
||||
return nil
|
||||
}}
|
||||
}
|
||||
|
||||
// StageCommitPush commits the worktree and pushes the branch. With no changes
|
||||
// it closes the issue with a comment, unless a baseline fix was committed, in
|
||||
// which case it still pushes.
|
||||
func StageCommitPush(message func(*TaskContext) string) Stage {
|
||||
return Stage{Name: "commit-push", Run: func(ctx context.Context, tc *TaskContext) error {
|
||||
if tc.BuildNoChanges {
|
||||
return closeNoChangesIssue(ctx, tc)
|
||||
}
|
||||
changed, err := tc.Trees.CommitAll(ctx, tc.Dir, message(tc))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !changed && !tc.BaselineFixed {
|
||||
return fmt.Errorf("worktree has no changes to commit")
|
||||
}
|
||||
if err := tc.Trees.Push(ctx, tc.Dir, tc.Branch); err != nil {
|
||||
return err
|
||||
}
|
||||
tc.captureChanges(ctx, capturedAfterCommitPush)
|
||||
return nil
|
||||
}}
|
||||
}
|
||||
|
||||
func closeNoChangesIssue(ctx context.Context, tc *TaskContext) error {
|
||||
if !tc.Task.IsForgeBacked() {
|
||||
tc.Outcome = Outcome{Status: StatusCompleted, Detail: "completed -- no changes required"}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"sync"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/lifecycle"
|
||||
@@ -119,16 +118,3 @@ func (m *Manager) Settings() map[string]any {
|
||||
defer m.mu.Unlock()
|
||||
return maps.Clone(m.settings)
|
||||
}
|
||||
|
||||
// StepTypes returns every registered step type name, sorted.
|
||||
func (m *Manager) StepTypes() []string {
|
||||
registry := m.Registry()
|
||||
return slices.Sorted(maps.Keys(registry))
|
||||
}
|
||||
|
||||
// Providers returns the registered provider names, sorted.
|
||||
func (m *Manager) Providers() []string {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
return slices.Sorted(slices.Values(m.providers))
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package workintake
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync/atomic"
|
||||
|
||||
workflowtask "github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
)
|
||||
@@ -11,24 +10,3 @@ import (
|
||||
type ReviewTaskLookup interface {
|
||||
OpenTaskByPR(ctx context.Context, owner, repo string, number int) (*workflowtask.Task, error)
|
||||
}
|
||||
|
||||
// ReviewTaskResolver admits only reactions for live Archie-owned pull requests.
|
||||
type ReviewTaskResolver struct {
|
||||
Tasks ReviewTaskLookup
|
||||
dropped atomic.Int64
|
||||
}
|
||||
|
||||
// Resolve returns the live task that owns reaction's pull request.
|
||||
func (r *ReviewTaskResolver) Resolve(ctx context.Context, reaction ReviewCommentEnvelope) (*workflowtask.Task, error) {
|
||||
task, err := r.Tasks.OpenTaskByPR(ctx, reaction.Owner, reaction.Repo, reaction.PRNumber)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if task == nil {
|
||||
r.dropped.Add(1)
|
||||
}
|
||||
return task, nil
|
||||
}
|
||||
|
||||
// Dropped reports how many reactions did not resolve to a live owned task.
|
||||
func (r *ReviewTaskResolver) Dropped() int64 { return r.dropped.Load() }
|
||||
Reference in new issue
Block a user