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 ¶
- type AdvancedHooks
- func (h *AdvancedHooks) ConsumeRollback() (string, string, bool)
- func (h *AdvancedHooks) Disable()
- func (h *AdvancedHooks) Enable()
- func (h *AdvancedHooks) LearningSummary() string
- func (h *AdvancedHooks) PostToolUse(ctx context.Context, name string, args json.RawMessage, result string)
- func (h *AdvancedHooks) PreToolUse(ctx context.Context, name string, args json.RawMessage) (bool, string)
- func (h *AdvancedHooks) SetCoverageMode(on bool)
- func (h *AdvancedHooks) SetCoverageThreshold(t float64)
- func (h *AdvancedHooks) SetImpactMode(on bool)
- func (h *AdvancedHooks) SetLearnMode(on bool)
- func (h *AdvancedHooks) SetLearningSaver(saver func(name, body string))
- func (h *AdvancedHooks) SetOkVerifyMode(on bool)
- func (h *AdvancedHooks) SetStyleCheckMode(on bool)
- func (h *AdvancedHooks) SetTargetedTestMode(on bool)
- type DSTHooks
- func (h *DSTHooks) ConsumeRollback() (reason, detail string, happened bool)
- func (h *DSTHooks) Disable()
- func (h *DSTHooks) Enable()
- func (h *DSTHooks) IsEnabled() bool
- func (h *DSTHooks) Next() agent.ToolHooks
- func (h *DSTHooks) PostToolUse(ctx context.Context, name string, args json.RawMessage, result string)
- func (h *DSTHooks) PreToolUse(ctx context.Context, name string, args json.RawMessage) (bool, string)
- func (h *DSTHooks) SetBuildCommands(compile, test string)
- func (h *DSTHooks) SetNext(next agent.ToolHooks)
- func (h *DSTHooks) SetNoticeSink(notify func(string))
- func (h *DSTHooks) SetProofChain(pc *core.ProofChain)
- func (h *DSTHooks) SetWorkDir(dir string)
- type Snapshot
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:
- Change impact analysis — PreToolUse warns which packages import the file being edited.
- Auto learning — PostToolUse captures successful edits into the proof chain.
- Targeted testing — runs tests only for packages that depend on the changed file.
- Coverage monitoring — warns when package coverage falls below the threshold.
- Style check — runs gofmt -d and go vet on the edited file's package after every write.
- 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 ¶
NewDSTHooks creates a DST hooks instance. DST checks start enabled.
func (*DSTHooks) ConsumeRollback ¶
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) 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 ¶
SetBuildCommands sets the compile and test commands.
func (*DSTHooks) SetNoticeSink ¶
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 ¶
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 (*Snapshot) Capture ¶
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 ¶
CaptureDir recursively captures all regular files under dir. Directories and symlinks are skipped; .git, node_modules, and .codegraph are excluded.
func (*Snapshot) Clear ¶
func (s *Snapshot) Clear()
Clear discards all snapshots, signaling that the current operation passed verification and no rollback is needed.