dstvalid

package
v1.0.3 Latest Latest
Warning

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

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

Documentation

Overview

Package dstvalid implements synchronous compile/test regression hooks. Every write_file / edit_file / multi_edit triggers a go build (and optionally go test) in PostToolUse. Passes are recorded into a ProofChain for per‑turn agent memory; failures roll back the file via snapshot and surface a "rolled back: ..." error through ConsumeRollback.

No async LLM verification — the proof chain alone gives the agent a compact, deduplicated summary of what has been verified across turns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdvancedHooks

type AdvancedHooks struct {
	// contains filtered or unexported fields
}

AdvancedHooks wraps DSTHooks with five opt-in capabilities:

  1. Change impact analysis — PreToolUse warns which packages import the file being edited.
  2. Auto learning — PostToolUse captures successful edits into the proof chain.
  3. Targeted testing — runs tests only for packages that depend on the changed file.
  4. Coverage monitoring — warns when package coverage falls below the threshold.
  5. Style check — runs gofmt -d and go vet on the edited file's package after every write.
  6. Static analysis — runs go vet on all affected packages after every write.

func NewAdvancedHooks

func NewAdvancedHooks(inner agent.ToolHooks, workDir, compileCmd, testCmd string, pc *core.ProofChain) *AdvancedHooks

NewAdvancedHooks creates an AdvancedHooks wrapping the given inner hooks. Starts disabled — call SetLearnMode/SetImpactMode/SetTargetedTestMode to enable.

func (*AdvancedHooks) ConsumeRollback

func (h *AdvancedHooks) ConsumeRollback() (string, string, bool)

func (*AdvancedHooks) Disable

func (h *AdvancedHooks) Disable()

Disable turns off all advanced features.

func (*AdvancedHooks) Enable

func (h *AdvancedHooks) Enable()

Enable turns on all advanced features.

func (*AdvancedHooks) LearningSummary

func (h *AdvancedHooks) LearningSummary() string

LearningSummary returns a formatted string of recent learnings, for system prompt injection.

func (*AdvancedHooks) PostToolUse

func (h *AdvancedHooks) PostToolUse(ctx context.Context, name string, args json.RawMessage, result string)

func (*AdvancedHooks) PreToolUse

func (h *AdvancedHooks) PreToolUse(ctx context.Context, name string, args json.RawMessage) (bool, string)

func (*AdvancedHooks) SetCoverageMode

func (h *AdvancedHooks) SetCoverageMode(on bool)

SetCoverageMode enables coverage threshold checking — after editing a file, run go test -cover on affected packages and warn if coverage drops below the threshold.

func (*AdvancedHooks) SetCoverageThreshold

func (h *AdvancedHooks) SetCoverageThreshold(t float64)

SetCoverageThreshold sets the minimum acceptable coverage ratio (0.0–1.0, default 0.5).

func (*AdvancedHooks) SetImpactMode

func (h *AdvancedHooks) SetImpactMode(on bool)

SetImpactMode enables change impact analysis — shows which packages import the edited file.

func (*AdvancedHooks) SetLearnMode

func (h *AdvancedHooks) SetLearnMode(on bool)

SetLearnMode enables auto learning — successful edits are captured as proof chain entries.

func (*AdvancedHooks) SetLearningSaver

func (h *AdvancedHooks) SetLearningSaver(saver func(name, body string))

SetLearningSaver installs a callback that persists learnings to durable storage (e.g. the memory store). The callback receives (name, body) and is called asynchronously after each successful edit capture — it must not block.

func (*AdvancedHooks) SetOkVerifyMode

func (h *AdvancedHooks) SetOkVerifyMode(on bool)

SetOkVerifyMode enables automatic static analysis (go vet ./... + ok-verify equivalent) after every write operation.

func (*AdvancedHooks) SetStyleCheckMode

func (h *AdvancedHooks) SetStyleCheckMode(on bool)

SetStyleCheckMode enables automatic gofmt + go vet after every write operation.

func (*AdvancedHooks) SetTargetedTestMode

func (h *AdvancedHooks) SetTargetedTestMode(on bool)

SetTargetedTestMode enables targeted testing — only tests packages affected by the change.

type DSTHooks

type DSTHooks struct {

	// notice callback for user-facing DST status.
	Noticef func(format string, args ...interface{})
	// contains filtered or unexported fields
}

DSTHooks implements agent.ToolHooks with synchronous compile/test checks. Access to lastCompilePass / lastTestPass is guarded by passMu — a belt-and- suspenders measure against a future where writer tools may run in parallel.

func NewDSTHooks

func NewDSTHooks(workDir string) *DSTHooks

NewDSTHooks creates a DST hooks instance. DST checks start enabled.

func (*DSTHooks) ConsumeRollback

func (h *DSTHooks) ConsumeRollback() (reason, detail string, happened bool)

ConsumeRollback checks and drains the rollback event. Called by Agent.executeOne after PostToolUse to inject the rollback message into the tool result.

func (*DSTHooks) Disable

func (h *DSTHooks) Disable()

Disable turns off compile/test checks and clears the current snapshot so a later re-enable starts fresh rather than replaying stale state.

func (*DSTHooks) Enable

func (h *DSTHooks) Enable()

Enable turns on compile/test checks.

func (*DSTHooks) IsEnabled

func (h *DSTHooks) IsEnabled() bool

IsEnabled reports whether compile/test checks are active.

func (*DSTHooks) Next

func (h *DSTHooks) Next() agent.ToolHooks

Next returns the chained hooks, or nil.

func (*DSTHooks) PostToolUse

func (h *DSTHooks) PostToolUse(ctx context.Context, name string, args json.RawMessage, result string)

PostToolUse runs compile/test checks after a write, records passes in the proof chain, and rolls back on regression (pass→fail).

func (*DSTHooks) PreToolUse

func (h *DSTHooks) PreToolUse(ctx context.Context, name string, args json.RawMessage) (bool, string)

PreToolUse snapshots files before they are written.

func (*DSTHooks) SetBuildCommands

func (h *DSTHooks) SetBuildCommands(compile, test string)

SetBuildCommands sets the compile and test commands.

func (*DSTHooks) SetNext

func (h *DSTHooks) SetNext(next agent.ToolHooks)

SetNext sets the chained hooks.

func (*DSTHooks) SetNoticeSink

func (h *DSTHooks) SetNoticeSink(notify func(string))

SetNoticeSink sets a callback for DST status messages.

func (*DSTHooks) SetProofChain

func (h *DSTHooks) SetProofChain(pc *core.ProofChain)

SetProofChain wires a proof chain for recording compile/test passes.

func (*DSTHooks) SetWorkDir

func (h *DSTHooks) SetWorkDir(dir string)

SetWorkDir sets the working directory for compile/test checks.

type Snapshot

type Snapshot struct {
	// contains filtered or unexported fields
}

Snapshot captures file content before a write so it can be restored on compile/test failure.

func NewSnapshot

func NewSnapshot() *Snapshot

NewSnapshot creates a snapshot manager.

func (*Snapshot) Capture

func (s *Snapshot) Capture(paths ...string) error

Capture saves the current content of the specified files. Calling Capture repeatedly on the same file keeps the first-captured content — only the original state matters for rollback.

func (*Snapshot) CaptureDir

func (s *Snapshot) CaptureDir(dir string) error

CaptureDir recursively captures all regular files under dir. Directories and symlinks are skipped; .git, node_modules, and .codegraph are excluded.

func (*Snapshot) Captured

func (s *Snapshot) Captured() []string

Captured returns the absolute paths of all snapshotted files.

func (*Snapshot) Clear

func (s *Snapshot) Clear()

Clear discards all snapshots, signaling that the current operation passed verification and no rollback is needed.

func (*Snapshot) Commit

func (s *Snapshot) Commit(paths ...string)

Commit removes the given paths from the snapshot so they are NOT rolled back. Used after a per-tool compile check passes — the tool's changes are good and should survive even if a later tool in the same turn triggers a rollback.

func (*Snapshot) Rollback

func (s *Snapshot) Rollback() error

Rollback restores all captured files to their pre-write state. files that didn't exist at capture are removed; modified files are restored to their original content.

Jump to

Keyboard shortcuts

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