unplannedread

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 18 Imported by: 0

Documentation

Overview

Package unplannedread measures reads that Corvint failed to prevent: tool calls that opened a project file the delivered context packet did not already carry. It is an explicitly opt-in, bounded, local, private ledger. It is never an input to ranking, evidence, or authority, is read as labels only by the operator-invoked slot-weight learning step (decision 0368), and stores no file contents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(root string, event Event) error

Append writes one row, and only when the opt-in marker exists. Without the marker it is a no-op returning nil, so no default install ever gains a file.

func Disable

func Disable(root string) error

func Enable

func Enable(root string) error

Enable and Disable are the only mutations in this package that a read command never performs; they are explicit operator verbs.

func Enabled

func Enabled(root string) bool

Enabled reports whether the operator created the opt-in marker.

func HookPostTool

func HookPostTool(root string, packetPaths []string, payload map[string]any) error

HookPostTool is the orchestrator entry point. It is log-and-drop: it never returns an error that could fail a host hook, and the dropped error is persisted as an error row the digest reports as LastError.

func HookPostToolSession

func HookPostToolSession(root, session string, payload map[string]any) error

HookPostToolSession is the host adapter's post-tool entry point. It judges a read against the newest packet recorded for the same session; when no such packet is retained it abstains and writes nothing, because a read with no known packet cannot be called unplanned (URE-V0-009). It never returns an error.

func PacketDigest

func PacketDigest(packetPaths []string) string

PacketDigest names the packet a read was judged against without retaining its paths.

func RecordPacket

func RecordPacket(root, session string, packetPaths []string) error

RecordPacket stores the planned set of the packet just delivered to a session, so a later post-tool call in that session has a denominator. It is marker-gated and log-and-drop like HookPostTool: it never returns an error.

func RefusePacket

func RefusePacket(root, session string) error

RefusePacket records that a session's newest prompt delivered no packet, so later reads in that session abstain rather than score against its older packet (URE-V0-008). It is marker-gated and log-and-drop like RecordPacket.

func Render

func Render(root string, limit int, output io.Writer) error

Render writes the digest, mirroring the self-observation digest's shape.

Types

type Digest

type Digest struct {
	Unplanned   int
	Planned     int
	TotalBytes  int64
	Tools       map[string]int
	TopPaths    []PathBytes
	SkippedRows int
	// LastError is the reason code of the newest retained error row and
	// DroppedErrors counts every retained error row.
	LastError     string
	DroppedErrors int
}

Digest is the read-only summary of the ledger.

func Read

func Read(root string) (Digest, error)

Read folds the ledger into a digest. It writes nothing.

func (Digest) Ratio

func (d Digest) Ratio() string

Ratio is the unplanned share of all recorded reads, rendered to three decimals, or "n/a" when nothing was recorded.

type Event

type Event struct {
	Timestamp    string `json:"ts"`
	Tool         string `json:"tool"`
	Path         string `json:"path,omitempty"`
	Bytes        int64  `json:"bytes"`
	SizeKnown    bool   `json:"size_known"`
	PacketDigest string `json:"packet"`
	Planned      bool   `json:"planned"`
}

Event is one classified read. Planned rows carry no path: only the counts needed to compute the unplanned share.

func Classify

func Classify(packetPaths []string, toolName string, toolInput map[string]any, root string) (Event, bool)

Classify decides whether one post-tool payload is a project-relative read and whether the packet already planned it. It reads filesystem metadata to resolve containment and the worktree path's byte size. The second result is false when the call is not a recognized read or its target is not inside the worktree.

type PathBytes

type PathBytes struct {
	Path  string
	Bytes int64
}

PathBytes is one retained path and the bytes read through it.

Jump to

Keyboard shortcuts

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