Documentation
¶
Overview ¶
Package history is abcd's native session-transcript store: the write/read/ redact engine that populates ~/.abcd/history/<root-sha>/transcripts/ and retires the specstory shim (adr-29). It is transport-agnostic — no stdout, no os.Exit, no CLI knowledge — so any surface can drive it and marshal its structured results.
The index.json registry and per-repo meta.json (the store's substrate) are owned by internal/core/ahoy and created at install time; this package only writes transcript records into an already-bootstrapped transcripts/ dir.
Redaction is NOT reimplemented here. Every transcript is sanitised through internal/adapter/scanner — the same detector and masking discipline the launch path uses — in a two-stage, fail-closed capture: sanitise on write, then re-scan and refuse to write if any hard_fail secret or self home path survived. A stored record can never contain a live secret or an absolute home path.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CaptureResult ¶
type CaptureResult struct {
Record Record `json:"record"`
Wrote bool `json:"wrote"` // false on an idempotent no-op (source unchanged)
Residual []scanner.Finding `json:"residual"` // populated only alongside RedactionResidualError
}
CaptureResult reports the outcome of one capture.
func Capture ¶
func Capture(repoRoot, rootSHA, sessionID string, raw []byte, kind string) (CaptureResult, error)
Capture reads a raw session transcript, redacts it through the scanner (two-stage, fail-closed), and writes a record into ~/.abcd/history/<rootSHA>/transcripts/.
It is idempotent on the source's sha256: an identical source already stored is a no-op (Wrote=false, existing record returned, mtime preserved). It is fail-closed: if a blocking span survives redaction it returns a *RedactionResidualError and writes nothing.
Precondition: the transcripts/ dir must already exist (abcd ahoy install created it). Capture re-validates that the store's owned dirs are real directories; it never creates the index or meta.
type DrainFailure ¶
type DrainFailure struct {
SessionID string `json:"session_id"`
Path string `json:"path"`
Err string `json:"error"`
}
DrainFailure is one staged transcript that could not be captured. The staged file is deliberately LEFT in place: a failure here is recoverable by hand, and deleting the only copy abcd holds would convert a reported problem into the silent permanent loss this whole mechanism exists to end.
type DrainResult ¶
type DrainResult struct {
Captured []Record `json:"captured"`
Failed []DrainFailure `json:"failed"`
Remaining int `json:"remaining"` // staged entries not attempted, budget exhausted
}
DrainResult reports one drain pass.
func Drain ¶
func Drain(repoRoot, rootSHA string, budget int) (DrainResult, error)
Drain captures every staged transcript into the store and removes the ones it stored. It is the SessionStart half of capture.
budget bounds how many entries one pass attempts; <= 0 means all of them. The bound exists because a backlog drains at redaction speed and SessionStart is interactive: a repo with a dozen missed sessions would otherwise stall the user's first prompt. Whatever the budget leaves is reported in Remaining rather than dropped, so a partial pass is loud and the caller can say so.
A staged file is deleted ONLY when its transcript is in the store — either captured now or already present — and only while it still holds the bytes that were captured. The staging lock is deliberately NOT held across Capture: redaction is the cost staging exists to keep out of SessionEnd, and holding the lock through it would stall every concurrent hook for its duration. So a Stage that replaces the copy mid-drain wins the race by design: the removal re-checks the bytes under the lock, a replaced copy is left for the next pass, and the fresher transcript is never lost. Any failure leaves the file where it is.
type Record ¶
type Record struct {
SessionID string `json:"session_id"`
RootCommit string `json:"root_commit"`
CapturedAt time.Time `json:"captured_at"`
SourceKind string `json:"source_kind"`
SourceSHA256 string `json:"source_sha256"`
Path string `json:"path"`
Secrets int `json:"redacted_secrets"`
HomePaths int `json:"redacted_home_paths"`
}
Record is one stored transcript's metadata (its frontmatter). It never carries raw content — the redacted body is fetched separately via Read.
type RedactionResidualError ¶
RedactionResidualError is returned by Capture when the stage-two re-scan finds a BLOCKING span that survived redaction — any identity or network span whatever its severity, plus every hard_fail one (scanner.BlockingResidual). NO file is written. It carries the surviving findings' kinds/locations only — the scanner has already masked their Matched fields, so no raw secret material is exposed.
func (*RedactionResidualError) Error ¶
func (e *RedactionResidualError) Error() string
type StageResult ¶
type StageResult struct {
Staged Staged `json:"staged"`
Wrote bool `json:"wrote"` // false when this session is already staged with identical bytes
// Replaced is true when the session was already staged with DIFFERENT bytes
// and that copy was replaced by this one; ReplacedBytes is the size of the
// copy that was replaced. Both are zero on a first stage and on a no-op.
Replaced bool `json:"replaced"`
ReplacedBytes int64 `json:"replaced_bytes"`
}
StageResult reports the outcome of one stage.
func Stage ¶
func Stage(rootSHA, sessionID string, raw []byte) (StageResult, error)
Stage writes raw transcript bytes into the staging area without redacting them. It is the SessionEnd half of capture and must stay cheap: no scanner and no read of the store. Cost is one listing of the staging dir, at most one read of this session's own staged copy, and one write, so the hook's runtime is independent of the store's size — which is the entire point.
It is idempotent per session on CONTENT, and the whole list-compare-write runs under the staging lock so the guarantee holds across concurrent hooks (GHSA-xq36-hcgf-9wrj): a session already staged with identical bytes is a no-op (Wrote=false); a session staged with different bytes has that copy replaced at its existing path (Wrote=true, Replaced=true) — last-writer-wins, because a re-fired SessionEnd carrying different bytes is the later snapshot of the same session, and the fresher end-of-session bytes are the ones worth keeping. Either way one session has one staged file, whatever fires.
type Staged ¶
type Staged struct {
SessionID string `json:"session_id"`
StagedAt time.Time `json:"staged_at"`
Path string `json:"path"`
Bytes int64 `json:"bytes"`
}
Staged is one raw transcript awaiting redaction.
func ListStaged ¶
ListStaged returns the transcripts awaiting redaction for this repo, oldest first. An absent staging dir is not an error: it means nothing is pending.
type StorePathError ¶
StorePathError is a preflight fault: an owned store path is absent, a symlink, or otherwise unsafe. It is returned (never panicked) so the caller can surface a clean diagnostic and refuse the operation.
func (*StorePathError) Error ¶
func (e *StorePathError) Error() string