{"modulePath":"github.com/codefit-cli/codefit","version":"v0.2.9","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package report\n\nPackage report defines the canonical audit report and the renderers that present it. The JSON report is the single source of truth (it carries its own schema\\_version, independent of the codefit version); plain-text, TUI and HTML are interchangeable renderers over it, chosen by TTY detection (PRD section 18).\n\nIt defines [AuditReport](#AuditReport) and three [Renderer](#Renderer) implementations — JSON (canonical), plain text, and an HTML placeholder — plus TTY detection so the plain renderer is used in pipes/CI/MCP.\n\n## Constants\n\n```go\nconst SchemaVersion = \"1.0\"\n```\nSchemaVersion is the version of the canonical JSON report format, independent of the codefit binary version so report consumers can migrate in a controlled way (PRD §18).\n\n## Functions\n\n```go\nfunc ClassifyEndpoints(eps []EndpointReport) (actionable []EndpointReport, resolvedClean []ResolvedCleanEndpoint, frontier []FrontierEndpoint)\n```\nClassifyEndpoints splits aggregated endpoints into three buckets, one per resolution level — all by facts codefit already computes, no new judgment:\n\n  - actionable     — resolved locally AND has a gap (CertainConcerns\u003e0, Actionable\u003e0): full detail, the agent acts on these.\n  - resolved\\_clean — resolved locally, NO gap (CertainConcerns\u003e0, Actionable==0): named + a verification fact; codefit checked and it is clean.\n  - frontier       — not resolved locally (CertainConcerns==0): named; the data left the body, the agent follows it in the code.\n\nThe order matters: CertainConcerns==0 → frontier first, so a frontier-only endpoint that happens to carry an access-gap signal is still named as frontier (codefit did not resolve it locally), never promoted to actionable. Actionable endpoints are returned WHOLE (all their concerns, including any frontier concern of the same endpoint, because the agent reasons the endpoint). Input order (hardest gap first) is preserved within each bucket.\n\n## Types\n\n```go\ntype ActionableEndpoint struct {\n\tFile   string `json:\"file\"`\n\tLine   int    `json:\"line,omitempty\"`\n\tMethod string `json:\"method,omitempty\"`\n\t// Concerns is how many concerns the endpoint has in total; Actionable how many\n\t// of them are a missing/broken control; CertainConcerns how many codefit\n\t// resolved locally (deterministic + surface_confirmed).\n\tConcerns        int      `json:\"concerns\"`\n\tActionable      int      `json:\"actionable\"`\n\tCertainConcerns int      `json:\"certain_concerns\"`\n\tCategories      []string `json:\"categories\"`\n\t// Gaps names the KINDS of missing control present, hardest first — the same\n\t// order the endpoint list is ranked by, so an agent can see WHY an endpoint is\n\t// where it is without fetching it.\n\tGaps []string `json:\"gaps,omitempty\"`\n\t// HighestCertainty is the best certainty codefit reached on this endpoint.\n\tHighestCertainty CertaintyLevel `json:\"highest_certainty\"`\n\t// HasAffirmation is true when at least one concern is something codefit\n\t// AFFIRMS rather than asks. An agent must not have to fetch a file to learn a\n\t// fact exists.\n\tHasAffirmation bool `json:\"has_affirmation\"`\n\t// Deterministic carries the endpoint's deterministic concerns in full (see the\n\t// type comment). Empty on the ordinary endpoint, whose concerns are all surface.\n\tDeterministic []Concern `json:\"deterministic_concerns,omitempty\"`\n}\n```\nActionableEndpoint NAMES an endpoint that codefit resolved locally and found a gap in. It is the same discipline FrontierEndpoint has always followed, finally applied to the bucket that carries 99% of the payload: the endpoint is named with enough for the agent to RANK and CHOOSE, and the ~800-byte-per-concern question/signals text is fetched on demand with codefit-scan-endpoint, which is stateless and recomputes the identical analysis (ADR 0008, ADR 0054).\n\n\"Enough to rank\" is the whole contract of this type, and every field earns its place against it: how many concerns and of which categories, how many are actionable gaps and of which KIND (hardest first), the best certainty codefit reached, and whether a deterministic affirmation is in there.\n\nDeterministic is the ONE exception to naming, and it is not a compromise: a deterministic finding is a fact codefit already concluded, not a question it is handing over. Hiding it behind a second call would make a scan's headline result depend on the agent choosing to look. Those concerns stay here IN FULL — they are rare by construction and are not what makes the payload big.\n\n```go\nfunc NameActionable(eps []EndpointReport) []ActionableEndpoint\n```\nNameActionable turns the complete per-endpoint reports into their named summaries, in the same order. It is a pure RENDERING narrowing: it reads the endpoints, it computes nothing new and it drops no endpoint — the set it returns is exactly the set it was given. Anything derived from the audit (the score, the baseline delta, the counts) is computed before this and never from its output.\n\n```go\ntype AuditReport struct {\n\tSchemaVersion  string               `json:\"schema_version\"`\n\tCodefitVersion string               `json:\"codefit_version\"`\n\tTimestamp      time.Time            `json:\"timestamp\"`\n\tProject        string               `json:\"project\"`\n\tLanguage       string               `json:\"language\"`\n\tCommit         string               `json:\"commit,omitempty\"`\n\tScore          scoring.ScoreSummary `json:\"score\"`\n\tBlocked        bool                 `json:\"blocked\"`\n\tBlockReason    string               `json:\"block_reason,omitempty\"`\n\tBaseline       *BaselineSummary     `json:\"baseline,omitempty\"`\n\tFindings       []findings.Finding   `json:\"findings\"`\n\t// Surface is the auditable structural surface the agent must reason about\n\t// (PRD section 10), aggregated across sensors.\n\tSurface []findings.SurfaceItem `json:\"surface,omitempty\"`\n\t// Endpoints is the synthesis view (codefit-scan-all): the deterministic\n\t// findings and the surface grouped by the handler they belong to, each\n\t// endpoint's concerns ordered by certainty (deterministic → confirmed →\n\t// frontier). It is the complete picture per endpoint for the agent to reason;\n\t// the flat Findings/Surface remain for traceability.\n\tEndpoints []EndpointReport `json:\"endpoints,omitempty\"`\n\t// CoverageNote states which classes of problems were not audited (derived\n\t// from the coverage manifest), so the report always informs its own limits\n\t// (PRD section 21). Populated once the coverage manifest exists (Fase C).\n\tCoverageNote   string                  `json:\"coverage_note,omitempty\"`\n\tRegressionRisk *RegressionRisk         `json:\"regression_risk,omitempty\"`\n\tSensorResults  []findings.SensorResult `json:\"sensor_results\"`\n}\n```\nAuditReport is the canonical, language-agnostic audit result. JSON is the single source of truth; every renderer derives from this struct.\n\n```go\ntype BaselineSummary struct {\n\tActive            bool `json:\"active\"`\n\tNewFindings       int  `json:\"new_findings\"`\n\tBaselinedFindings int  `json:\"baselined_findings\"`\n}\n```\nBaselineSummary reports how many findings were new vs. recorded as historical debt when a baseline is active (RF-08).\n\n```go\ntype CertaintyLevel string\n```\nCertaintyLevel ranks how certain codefit is about a concern — the report's epistemological honesty. A deterministic finding is an ASSERTION (codefit saw a conclusive pattern, confidence 1.0). A surface concern is a QUESTION codefit hands to the agent: structurally confirmed (it saw the shape locally) or at the frontier (the data left the handler body, codefit could not see). The agent must distinguish what codefit affirms from what it asks; it never flattens them.\n\n```go\nconst (\n\tDeterministic    CertaintyLevel = \"deterministic\"     // codefit affirms (rule, 1.0)\n\tSurfaceConfirmed CertaintyLevel = \"surface_confirmed\" // codefit asks; saw the shape locally\n\tSurfaceFrontier  CertaintyLevel = \"surface_frontier\"  // codefit asks; the data left the body\n)\n```\n\n```go\ntype Concern struct {\n\tCertainty     CertaintyLevel `json:\"certainty\"`\n\tAffirms       bool           `json:\"affirms\"` // true: codefit asserts a fact; false: codefit asks the agent\n\tSource        string         `json:\"source\"`  // \"rule\" | \"surface\"\n\tID            string         `json:\"id\"`\n\tCategory      string         `json:\"category\"` // security | idor | authz | overfetch\n\tTitle         string         `json:\"title\"`\n\tDescription   string         `json:\"description,omitempty\"` // deterministic finding description\n\tSignals       []string       `json:\"signals,omitempty\"`     // surface structural_signals (facts)\n\tQuestion      string         `json:\"question,omitempty\"`    // surface reason_to_review\n\tLine          int            `json:\"line\"`\n\tConfidence    float64        `json:\"confidence\"`\n\tProbabilistic bool           `json:\"probabilistic\"`\n\t// RefinesAuthz marks an IDOR concern whose endpoint also has an authz concern:\n\t// IDOR is the structural refinement of authz (the sensitive handler also\n\t// receives a client id). A fact about structure, not a judgment.\n\tRefinesAuthz bool `json:\"refines_authz,omitempty\"`\n\t// Actionable is true when the concern is a missing/broken control codefit\n\t// detected (an affirmed finding, no authz/ownership check, or no field limit).\n\tActionable bool `json:\"actionable\"`\n\t// Gap names the KIND of missing control, hardest first: \"affirmed\" (a\n\t// deterministic finding), \"access\" (no authz/ownership on a sensitive\n\t// handler), \"exposure\" (a serialization with no select/omit). Empty when the\n\t// concern is not an actionable gap (e.g. a checked handler, or the frontier).\n\tGap string `json:\"gap,omitempty\"`\n\t// Fingerprint is the concern's baseline content identity (findings.Fingerprint).\n\t// The agent passes it to codefit-baseline-accept / -prune.\n\tFingerprint string `json:\"fingerprint,omitempty\"`\n\t// Baseline is the concern's delta vs the previous baseline, set by the scan-all\n\t// handler: \"new\" | \"changed\" | \"known\" | \"acknowledged\" (empty when no baseline).\n\tBaseline string `json:\"baseline,omitempty\"`\n}\n```\nConcern is one thing to review about an endpoint, from either source — a deterministic rule finding or a mapped surface item. Affirms records whether codefit asserts it (deterministic) or asks it (surface), so the distinction is never ambiguous.\n\n```go\ntype EndpointReport struct {\n\tFile            string    `json:\"file\"`\n\tLine            int       `json:\"line\"`             // handler anchor line (0 = module scope)\n\tMethod          string    `json:\"method,omitempty\"` // GET/POST/... when known\n\tActionable      int       `json:\"actionable\"`       // count of missing/broken-control concerns\n\tCertainConcerns int       `json:\"certain_concerns\"` // deterministic + surface_confirmed\n\tConcerns        []Concern `json:\"concerns\"`\n}\n```\nEndpointReport is the complete picture of one handler: all its concerns from both sources, ordered by certainty (deterministic → confirmed → frontier).\n\n```go\nfunc AggregateEndpoints(fs []findings.Finding, surface []findings.SurfaceItem) []EndpointReport\n```\nAggregateEndpoints groups deterministic findings and surface items by the handler they belong to and assembles the per-endpoint picture: concerns ordered by certainty within an endpoint (deterministic → confirmed → frontier), and endpoints ordered by their ACTIONABLE structural gaps, hardest kind first (affirmed deterministic → missing access control → over-exposure), then by certain-concern count. This surfaces the real findings, not the most instrumented endpoints. Ordering is by FACT (which control is missing), never by severity — the agent judges danger. It invents nothing: every concern comes from a real finding or surface item with its id.\n\n```go\ntype FrontierEndpoint struct {\n\tFile       string   `json:\"file\"`\n\tLine       int      `json:\"line,omitempty\"`\n\tMethod     string   `json:\"method,omitempty\"`\n\tCategories []string `json:\"categories\"`\n}\n```\nFrontierEndpoint names a frontier-only endpoint — every one of its concerns is surface\\_frontier (the data left the handler body, local\\_access\\_detected=false), so codefit concluded nothing locally about it. It is NAMED, not detailed: the agent goes to the code to follow the data regardless, so the concern detail would not save it the trip (ADR 0008). It carries the file and the categories at stake, one line, for the agent to know what is pending and request the full detail on demand via codefit-scan-endpoint.\n\n```go\ntype JSONRenderer struct{}\n```\nJSONRenderer writes the canonical JSON, indented. In the MCP-first model the report is delivered as JSON to the agent; this is the only renderer in v1 (an HTML renderer is a future addition over the same canonical report).\n\n```go\nfunc (JSONRenderer) Render(w io.Writer, r AuditReport) error\n```\n\n```go\ntype RegressionItem struct {\n\tSymbol    string   `json:\"symbol\"`\n\tFile      string   `json:\"file\"`\n\tCallsites []string `json:\"callsites,omitempty\"`\n\tReason    string   `json:\"reason,omitempty\"`\n}\n```\nRegressionItem is a single function/symbol at risk from recent changes.\n\n```go\ntype RegressionRisk struct {\n\tHigh   []RegressionItem `json:\"high,omitempty\"`\n\tMedium []RegressionItem `json:\"medium,omitempty\"`\n}\n```\nRegressionRisk groups regression-risk items by level (RF-06, --since mode).\n\n```go\ntype Renderer interface {\n\tRender(w io.Writer, r AuditReport) error\n}\n```\nRenderer writes an AuditReport to w. Renderers never reach into the core; they only consume the canonical report.\n\n```go\ntype ResolvedCleanEndpoint struct {\n\tFile         string `json:\"file\"`\n\tLine         int    `json:\"line,omitempty\"`\n\tMethod       string `json:\"method,omitempty\"`\n\tVerification string `json:\"verification\"`\n}\n```\nResolvedCleanEndpoint names an endpoint codefit resolved LOCALLY and found clean: it accessed data locally (CertainConcerns\u003e0) and codefit verified the controls are present — no gap. It is NAMED (file, method) plus one VERIFICATION FACT that affirms what codefit checked (\"an authorization check is present; field selection is present — no gap found\"). This is the crux of the three- bucket split: resolved\\_clean is an AFFIRMATION (codefit looked and it is clean), epistemologically OPPOSITE to a frontier endpoint (codefit could NOT conclude). Flattening the two into a single \"not detailed\" bucket would be the same error as the old frontier wording — so they are kept distinct on purpose.\n\n","path":"github.com/codefit-cli/codefit/internal/core/report","name":"report","synopsis":"Package report defines the canonical audit report and the renderers that present it.","isRedistributable":true}
