Documentation
¶
Overview ¶
Package history is abcd's native session-transcript store: the write/read/ redact engine that populates ~/.abcd/transcripts/<root-sha>/records/ 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 store's location, its root-SHA keying, the home-scoped opt-in that pulls one repo's transcripts into that repo, and the migration off the legacy location all live in location.go, behind the single Resolve seam this file's verbs go through. The store creates itself; no install step is a precondition of capture (iss-95).
The index.json registry and per-repo meta.json are owned by internal/core/ahoy and stay under ~/.abcd/history/; this package owns the corpus and nothing else.
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 ¶
const ( // LocalStoreRelPath is the opt-in per-repo pull-in, relative to the repo // root. It is under .abcd/.work.local/ deliberately: that tier is gitignored // and per-worktree, so a pulled-in transcript is never a commit candidate and // never merge-conflicts between concurrent sessions. LocalStoreRelPath = ".abcd/.work.local/transcripts" // LocalRootsRelPath is the home-scoped declaration that pulls a repo's // transcripts into that repo, relative to the caller's home. LocalRootsRelPath = ".abcd/local-transcript-roots" // LocalRootsDisplay names that file in a diagnostic in tilde form, so a // message a user pastes into a shell works and no diagnostic carries the // caller's home path (iss-81, fsutil.RedactHome). LocalRootsDisplay = "~/" + LocalRootsRelPath )
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 this repo's lane of the store — ~/.abcd/transcripts/<rootSHA>/records/ by default.
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.
There is no install precondition: Resolve creates the store when it is absent and refuses anything on the path that is not a real directory. It never touches ahoy's 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.
func List ¶
List returns this repo's records, newest first. It reads frontmatter only, never bodies. An empty store returns no records and no error (this repo has simply not been captured yet); a store path that is not a real directory is refused with an error.
It goes through Resolve like every other verb, so a read is also the moment a corpus left at the legacy location is migrated: a reader that skipped that would report the store as empty while the transcripts sat one directory away.
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 Resolution ¶ added in v0.8.0
type Resolution struct {
Base string `json:"base"`
Records string `json:"records"`
Staging string `json:"staging"`
Local bool `json:"local"`
Notes []string `json:"notes"`
}
Resolution is where this repo's transcripts live, and what resolving it had to say out loud.
Notes is the out-of-band diagnostic channel, mirroring rules.Resolve: core never writes to stdout, so a migration it performed or a declaration it declined to honour is returned for the front door to print on stderr. A store that quietly moved a corpus, or quietly ignored an opt-in the caller wrote, would be indistinguishable from one that did neither.
func Resolve ¶ added in v0.8.0
func Resolve(repoRoot, rootSHA string) (Resolution, error)
Resolve returns this repo's store, creating it when absent, and migrating a corpus left at the legacy location into it.
It is the ONE seam every read and write path goes through, so the store can never be reached by a path that skipped the creation, the symlink discipline or the migration. It is idempotent and cheap: a resolved store is a handful of stat calls and, after the first call, a no-op migration.
Front doors call it explicitly as well, in order to PRINT Notes — the verbs below discard them, because a verb that printed would be a core package speaking to a terminal.
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(repoRoot, 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