{"modulePath":"github.com/codefit-cli/codefit","version":"v0.2.9","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package baseline\n\nPackage baseline tracks codefit's view of a project's audited surface across scans. The baseline is a committed file (.codefit-baseline) — shared knowledge like .codefit.yaml — that records every item codefit knows about, identified by a content Fingerprint (see findings.Fingerprint), so a re-scan can tell what is new, unchanged (known), changed, or gone.\n\nSafeguard by certainty (PRD RF-08):\n\n  - SURFACE (a question) becomes known automatically once recorded; a re-scan silences it. accept marks it acknowledged (a false positive / accepted debt).\n  - DETERMINISTIC (an affirmation, confidence 1.0) is NEVER known automatically: it is shown on every scan until a human accepts it explicitly with a reason. Silencing an affirmation is graver than silencing a question, so it needs the stronger safeguard.\n\ncodefit never edits code — only this file.\n\nPackage baseline implements the adoption baseline (PRD RF-08): a committed snapshot of a project's findings so that, with baseline enabled, codefit reports only new findings while pre-existing debt is recorded (baselined: true) and does not block. This makes adopting codefit on an existing project painless (Scenario B).\n\nStatus: BUILT (Fase 1). The snapshot/diff logic and the on-disk format are implemented. The file is named by [Name](#Name) — \".codefit-baseline\" at the repo root, a committed plain file, NOT \".codefit/baseline.json\" as an earlier draft of this comment claimed.\n\n## Constants\n\n```go\nconst Name = \".codefit-baseline\"\n```\nName is the baseline file, committed at the repo root.\n\n## Types\n\n```go\ntype Ack struct {\n\tReason string `yaml:\"reason\"`\n\tAt     string `yaml:\"at\"`\n\tBy     string `yaml:\"by\"` // always \"human\": codefit never acknowledges on its own\n}\n```\nAck records that a human accepted an item (false positive or accepted debt).\n\n```go\ntype AuthzHelper struct {\n\tName     string `yaml:\"name\"`\n\tLanguage string `yaml:\"language\"`\n\tReason   string `yaml:\"reason\"`\n\tAt       string `yaml:\"at\"`\n\tBy       string `yaml:\"by\"` // always \"human\": codefit never registers on its own\n}\n```\nAuthzHelper is a project-specific authorization helper the AGENT identified by reasoning over the code and a HUMAN approved registering — so codefit recognizes it on later scans without the agent re-reasoning (it augments the built-in NextAuth-style set per project). It is project knowledge, like an acknowledged item: persisted, committed, recorded by:\"human\". Registering a helper changes a FACT (known\\_authz\\_detected for the authz concern), never a verdict — it clears the AUTHZ gap, never the IDOR/ownership gap (ADR 0013, ADR 0006 amended).\n\n```go\ntype Baseline struct {\n\tVersion      string        `yaml:\"version\"`\n\tItems        []Item        `yaml:\"items\"`\n\tAuthzHelpers []AuthzHelper `yaml:\"authz_helpers,omitempty\"`\n}\n```\nBaseline is the committed set of known items plus the project's registered authz helpers.\n\n```go\nfunc Load(path string) (*Baseline, error)\n```\nLoad reads the baseline at path. A missing file is NOT an error: it returns an empty baseline (the first scan creates it).\n\n```go\nfunc (b *Baseline) Accept(fps []string, reason, at string) (accepted []string, err error)\n```\nAccept marks the given fingerprints as acknowledged by a human. A reason is mandatory; an unknown fingerprint is an error (nothing is changed). codefit records by:\"human\" — it never acknowledges on its own.\n\n```go\nfunc (b *Baseline) List(filter string) ([]Entry, error)\n```\nList returns the baseline items as Entries, filtered by state: \"\" (all), \"known\" (not acknowledged), or \"acknowledged\". An unknown filter is an error.\n\n```go\nfunc (b *Baseline) Prune(fps []string) (pruned []string)\n```\nPrune removes the given fingerprints from the baseline (used for gone items the caller has confirmed no longer exist in the code). Returns the removed fps.\n\n```go\nfunc (b *Baseline) RecognizedAuthzHelpers(language string) []string\n```\nRecognizedAuthzHelpers returns the names of the helpers registered for a language — the set a scan adds to the built-in authz helpers for that project.\n\n```go\nfunc (b *Baseline) RegisterAuthzHelper(name, language, reason, at string) (added bool, err error)\n```\nRegisterAuthzHelper records a project-specific authz helper as recognized, by:\"human\". A name, language, and reason are mandatory (the reason is the human's justification, as for Accept). Idempotent: registering an already-known (language, name) is a no-op that returns added=false. codefit never registers on its own — the agent proposes, the human decides (the skill enforces it; codefit records the decision).\n\n```go\nfunc (b *Baseline) Save(path string) error\n```\nSave writes the baseline to path as commented, human-readable YAML.\n\n```go\nfunc (b *Baseline) UnregisterAuthzHelper(name, language string) bool\n```\nUnregisterAuthzHelper removes a registered helper (the reversal of RegisterAuthzHelper — the developer's decision is always reversible). Returns whether a helper was removed.\n\n```go\ntype Counts struct {\n\tNew, Changed, Known, Acknowledged, Gone, AffirmationsShown int\n}\n```\nCounts is the at-a-glance delta.\n\n```go\ntype DiffResult struct {\n\tState  map[string]State // fp → state, for observed items\n\tShown  map[string]bool  // fp → must be shown (not silenced)\n\tGone   []Item           // baseline items no longer observed (prune candidates)\n\tCounts Counts\n\tNext   *Baseline // the baseline to persist\n}\n```\nDiffResult is the full comparison of a scan against the previous baseline.\n\n```go\nfunc Diff(prev *Baseline, observed []Observed, scanned map[string]bool, files scope.Scope) DiffResult\n```\nDiff compares the observed scan against the previous baseline and returns the per-item delta, what must be shown, the gone candidates, and the next baseline to persist. It never silences a deterministic affirmation that has not been acknowledged.\n\nThe scope is TWO-DIMENSIONAL, and an item is eligible to be \"gone\" only when BOTH dimensions admit it:\n\n\tscanned[item.Category]  AND  files.Includes(item.File)\n\nscanned is the set of Item categories owned by the sensors that RAN this pass. A previous item whose category is NOT in scanned (its sensor did not run) is carried forward UNTOUCHED — absent from the delta, never a gone/prune candidate. This distinguishes \"not observed because the sensor did not run\" from \"not observed because it disappeared\", so a single-sensor run cannot corrupt another dimension's state (ADR 0019).\n\nfiles is the FILE scope of the pass. The category dimension alone does not cover a partial audit: a security finding in a file this pass never opened still belongs to the security category, which DID run, so a category-only guard would see it unobserved-and-in-scope and mark it gone — and codefit-baseline-prune would then delete the audit memory of every file the scan did not look at, silently, in the direction of going blind.\n\nBoth dimensions fail safe: an empty scanned and the zero-value scope.Scope each include nothing, so a caller that forgets one under-reports and never prunes. Under-report, never corrupt.\n\n```go\ntype Entry struct {\n\tFingerprint string `json:\"fingerprint\"`\n\tFile        string `json:\"file\"`\n\tCategory    string `json:\"category\"`\n\tState       State  `json:\"state\"` // known | acknowledged\n\tReason      string `json:\"reason,omitempty\"`\n\tAt          string `json:\"at,omitempty\"`\n}\n```\nEntry is a read-only projection of a baseline item for codefit-baseline-list: just what the agent needs to reference an item in accept/prune. It omits the snippet on purpose (the agent supplies the reasoning; this keeps the list small).\n\n```go\ntype Item struct {\n\tFP       string `yaml:\"fp\"`\n\tCategory string `yaml:\"category\"`\n\tFile     string `yaml:\"file\"`\n\tSnippet  string `yaml:\"snippet,omitempty\"`\n\tAck      *Ack   `yaml:\"acknowledged,omitempty\"`\n}\n```\nItem is one tracked surface item or deterministic finding. Snippet is a human-readable display only; it is never the matched secret (the identity is the content-hashed FP). Ack is non-nil only when the item was accepted.\n\n```go\ntype Observed struct {\n\tFP       string\n\tCategory string\n\tFile     string\n\tSnippet  string\n\tAffirms  bool\n}\n```\nObserved is one item seen in the current scan. Affirms is true for a deterministic finding (an affirmation) and false for a surface item (a question).\n\n```go\ntype State string\n```\nState is an item's delta against the previous baseline.\n\n```go\nconst (\n\tStateNew     State = \"new\"\n\tStateChanged State = \"changed\"\n\tStateKnown   State = \"known\"\n\tStateAcked   State = \"acknowledged\"\n)\n```\n\n","path":"github.com/codefit-cli/codefit/internal/core/baseline","name":"baseline","synopsis":"Package baseline tracks codefit's view of a project's audited surface across scans.","isRedistributable":true}
