impact

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package impact is the shared "impact_of_change" implementation used by both internal/mcp.impact_of_change and internal/server's HTTP /api/impact handler. Before this package existed the algorithm lived inside internal/mcp; the HTTP viewer surface had to either re-implement reverse-dependency closure (drift risk) or reach across packages into private mcp helpers (layering inversion). Mirrors the pkg/smartctx pattern: callers serialise the returned map however they prefer (mcp wraps it in mcp.NewToolResult, server json-encodes it directly).

Citation Enforcement (warn mode): every node in any bucket includes file_path + start_line. Nodes that lack either are kept in the response (preserve recall) but recorded under metadata.warnings with code "missing-citation" — same contract as smartctx.

Index

Constants

View Source
const DepthCap = 5

DepthCap caps user-supplied depth so a misconfigured client (or LLM that asks for depth=99) cannot blow up the BFS. Five hops is already more than enough for human review; deeper transitive closures dilute signal more than they help.

Variables

This section is empty.

Functions

func Compute

func Compute(store persist.StoreReader, seedQname, seedFile string, opt Options) (map[string]any, error)

Compute is the shared algorithm body. seed_qname wins when both seedQname and seedFile are set (less ambiguous, and the qname path returns a single seed node for the response envelope).

The output is fully deterministic for a fixed (store, seed, depth) tuple: per-group node slices are sorted by qname (tiebreak id), edge triples by (type, src, dst, line), warnings by node_id, and the multi-seed echo by id. Go map iteration randomness is therefore boundary-only — it never leaks into the marshalled response, which keeps the LLM context cache stable.

Response shape (always present):

depth        int                — actual depth used (post-clamp)
seed         object?            — single-seed envelope (qname mode)
seeds        []object?          — multi-seed envelope (file mode)
seed_file    string?            — echoed file path (file mode)
seed_qname   string?            — echoed seed qname when not_found
not_found    bool?              — true when the seed did not resolve
impact       map[string][]node  — keys: callers, interface_impact,
                                  type_users, distributed, concurrent,
                                  other_refs (always all six, possibly
                                  empty so consumers don't nil-check)
edges        [][]any            — [src, dst, type, line] triples
totals       object             — { nodes, edges, by_group }
metadata     object             — { warnings: [...] }

Types

type Options

type Options struct {
	Depth        int  // default 2; clamped to [1, DepthCap]
	IncludeBlobs bool // default false; opt-in source bodies for LLMs
}

Options bundles the tunable knobs of Compute. Zero values are resolved to documented defaults inside Compute so callers can pass an empty struct for the typical case.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL