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. 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
}
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, no lock, no read of the existing store. Cost is one write, so the hook's runtime is independent of transcript size — which is the entire point.
It is idempotent per session: a session already staged is a no-op, so a double-fired SessionEnd cannot stage two copies of the same transcript.
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