loop

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package loop is quarry's supervisor: one complete cycle of the expanded scientific method, end-to-end, on a real target. It seeds the hypothesis frontier, drives the exploit-dev agent through the tool belt, and — the moment the oracle confirms — extracts a pattern, splits it into a private self-reproducing specimen and a public abstract sibling, and pushes both through the emit gate into the outbox. A run that never confirms terminates with a structured "ruled out" report, never a proof of absence.

M1 is a single hypothesis line; the parallel frontier and multi-agent peer review arrive in M2/M3 behind the same store + seams.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Critic

type Critic interface {
	Review(ctx context.Context, req ReviewRequest) (ReviewVerdict, error)
}

Critic reviews a non-confirmed conclusion.

type Federated

type Federated []channels.PatternSource

Federated consults several sources and unions their hits, deduped by artifact id (the first source to name an id keeps its metadata). A source that errors is skipped: consultation is best-effort and must never block a harvest — a retrieval failure degrades to "assume novel", never a drop.

func (Federated) Lookup

func (f Federated) Lookup(ctx context.Context, keys []string) ([]channels.PriorArt, error)

type Finding

type Finding struct {
	HypothesisID string
	Statement    string
	Private      *artifact.Envelope
	Public       *artifact.Envelope

	// PriorArt lists local/federation matches for this finding's crash keys —
	// retrieval, re-grounded by the local oracle. Novel ⇒ nobody we can see
	// already holds this crash.
	PriorArt []channels.PriorArt
	Novel    bool
}

Finding is one oracle-confirmed result: a private self-reproducing specimen plus its public abstract sibling, tied to the hypothesis that produced it.

type Hypothesis

type Hypothesis struct {
	Statement string `json:"statement"`
}

Hypothesis is a proposed line of investigation the supervisor seeds onto the frontier. In M2 the frontier is flat; sub-hypothesis spawning and backtracking-into-children come later.

type LocalSource

type LocalSource struct {
	Store candidateIndex
}

LocalSource resolves prior art from the local crash-state key index — free near-dup detection across everything this machine has already found, on the union of the multi-resolution keys (broader than the exact-key dedup).

func (LocalSource) Lookup

func (s LocalSource) Lookup(ctx context.Context, keys []string) ([]channels.PriorArt, error)

type Loop

type Loop struct {
	Store  *store.Store
	Model  model.Model
	Router router.Router
	Runner runner.Runner

	Gate *channels.Gate        // emit gate (anonymize → tier → re-id → self-verify)
	Sink channels.ArtifactSink // where vetted patterns go (M1: local outbox)

	// Signer, if set, client-signs emitted patterns.
	Signer ed25519.PrivateKey

	// Source, if set, is consulted at harvest for prior art matching a
	// confirmed crash's keys — the "down" query channel. It
	// classifies a finding (novel vs. rediscovery) and never gates the harvest.
	Source channels.PatternSource

	// Critic, if set, reviews a top-level dead-end (a scientist that gave up
	// without confirming or spawning) with fresh context; a "premature" verdict
	// yields one more child line (M3 governance).
	Critic Critic

	// Planner decomposes the objective into a hypothesis frontier. Defaults are
	// chosen by mode (copilot → SingleHypothesis; discover → ModelPlanner).
	Planner Planner
	// MaxParallel bounds concurrent scientists in discovery mode (default 4).
	MaxParallel int

	// WorkspaceRoot is where per-run agent workspaces are created.
	WorkspaceRoot string

	// AgentImage, if set (and digest-pinned), runs each scientist's exec in an
	// isolated container instead of on the host. DockerBin overrides
	// the docker binary. Unset → host exec (not a security boundary).
	AgentImage string
	DockerBin  string
	// SandboxNetwork is the sandbox docker network (default "none"); a named
	// network is the scoped tool-broker hole.
	SandboxNetwork string

	// Catalog, if non-empty, surfaces role-scoped pinned tools to the agent via
	// the broker. Its pinned set is recorded in every emitted
	// artifact's provenance so a replay re-provisions identically.
	Catalog   toolcat.Catalog
	AgentRole string // role scope for catalog tools (default "exploit-dev")

	// Now supplies timestamps for artifacts (defaults to time.Now).
	Now func() time.Time
	// Log receives short progress lines (optional).
	Log func(string)
}

Loop wires the whole client together for one investigation.

func (*Loop) Run

func (l *Loop) Run(ctx context.Context, req Request) (Report, error)

Run is the supervisor: it decomposes the objective into a hypothesis frontier, dispatches scientists over it (parallel on independent branches for discovery, a single coupled line for copilot), and aggregates the oracle-confirmed findings. Termination = every hypothesis in a definite state or the global budget hit — a bounded search, never a proof of absence.

type Metrics

type Metrics struct {
	Confirmed         int           // oracle-verified findings
	Novel             int           // findings nobody (local or commons) already held
	Rediscoveries     int           // findings that matched prior art (retrieval hit)
	TotalTokens       int           // prompt + completion across every scientist
	CostUSD           float64       // proxy-reported spend
	Elapsed           time.Duration // supervisor wall-clock
	Iterations        int           // total ReAct iterations across the frontier
	TokensPerFinding  int           // TotalTokens / Confirmed (0 when nothing confirmed)
	SecondsPerFinding float64       // Elapsed / Confirmed
	PriorArtHitRate   float64       // Rediscoveries / Confirmed — commons/local retrieval effectiveness
}

Metrics derives the empirical numbers a run produces (docs KF1): the cost of a verified finding and how much of the frontier was already known. Zero-safe.

type ModelCritic

type ModelCritic struct {
	Model  model.Model
	Router router.Router
}

ModelCritic is a model-backed critic. It runs a single fresh-context call (RoleCritic → the strong tier + a decorrelated model under a TieredRouter) and never sees the agent's trajectory, only the conclusion.

func (ModelCritic) Review

type ModelPlanner

type ModelPlanner struct {
	Model  model.Model
	Router router.Router
}

ModelPlanner asks a model to decompose the objective into independent, separately-testable hypotheses (the attack-surface map). It always returns at least the objective itself, so a weak/empty plan degrades to the single-line behavior rather than doing nothing.

func (ModelPlanner) Plan

func (p ModelPlanner) Plan(ctx context.Context, req PlanRequest) ([]Hypothesis, error)

type PlanRequest

type PlanRequest struct {
	Objective  string
	TargetDesc string
	Mode       string // discover | copilot
	Max        int
}

PlanRequest parameterizes decomposition.

type Planner

type Planner interface {
	Plan(ctx context.Context, req PlanRequest) ([]Hypothesis, error)
}

Planner decomposes an objective into hypotheses. Discovery fans out into independent branches; exploit-dev stays a single coupled line.

type Report

type Report struct {
	RunID          string
	Confirmed      bool
	StopReason     string
	Iterations     int
	Usage          model.Usage
	Findings       []Finding
	Hypotheses     int // how many were on the frontier
	RuledOut       string
	PoVSubmissions int

	// Private/Public mirror the first finding for single-finding (copilot) use.
	Private *artifact.Envelope
	Public  *artifact.Envelope

	// Elapsed is the supervisor wall-clock for the whole run (instrumentation:
	// the speed half of the token/speed claims).
	Elapsed time.Duration
}

Report is the terminal conclusion of a run over the hypothesis frontier.

func (Report) Metrics

func (r Report) Metrics() Metrics

Metrics computes the run's empirical instrumentation from the report.

type Request

type Request struct {
	Objective  string
	Mode       string // "discover" | "copilot"
	TargetRef  string
	TargetDesc string

	Oracle oracle.Spec
	Base   runner.RunSpec  // authoritative target run template
	Fixed  *runner.RunSpec // optional differential fixed-image template

	MaxIters         int
	HypothesisBudget int

	// M2 frontier controls.
	MaxHypotheses int // planner cap (discovery); default 6, copilot forces 1
	GlobalBudget  int // total scientist iterations across the frontier; 0 → derived

	// M3 governance: per-scientist token budget and stall limit.
	TokenBudget int // halt a scientist once it spends this many tokens (0 → unlimited)
	StallLimit  int // halt after this many no-progress iterations (0 → default)

	// Context compaction (context compaction): reproject the working
	// context onto a bounded digest over the durable trajectory when the estimated
	// prompt exceeds ContextBudget tokens, so a scientist runs long instead of
	// halting when history fills. 0 → disabled. KeepRecent turns kept verbatim (0 → 6).
	// Compactor selects the strategy: "" / "template" (deterministic, 0 tokens,
	// default) or "model" (adds a cheap-tier narrative of the compacted turns).
	ContextBudget int
	KeepRecent    int
	Compactor     string

	// MaxDepth bounds sub-hypothesis backtracking: a scientist may spawn child
	// lines the supervisor dispatches in the next wave, down to this depth (M2).
	// 0 → default 2 (top-level + two levels of children).
	MaxDepth int

	// SeedFiles are host file paths copied into each scientist's workspace before
	// it runs — e.g. the target's source for a WHITE-BOX audit (the agent can
	// read_file it), the realistic "audit arbitrary code" scenario.
	SeedFiles []string
}

Request describes one investigation.

type ReviewRequest

type ReviewRequest struct {
	Objective  string
	StopReason string
	Summary    string // the scientist's final message / conclusion
}

ReviewRequest is what the critic sees — deliberately just the objective and how/why the scientist stopped, NOT the agent's message history.

type ReviewVerdict

type ReviewVerdict struct {
	Adequate   bool   `json:"adequate"`
	Reason     string `json:"reason"`
	Suggestion string `json:"suggestion"`
}

ReviewVerdict is the critic's judgment. Suggestion is a sub-hypothesis to try next when the search was inadequate (empty ⇒ nothing to add).

type SingleHypothesis

type SingleHypothesis struct{}

SingleHypothesis is the trivial planner: the objective is the one hypothesis. It is correct for copilot/exploit-dev (a tightly coupled single line).

func (SingleHypothesis) Plan

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL