How panndabea/gosherpa works
Purpose and Runtime
GoSherpa is a Go 1.24 CLI for local, deterministic structural intelligence over Go modules/workspaces. It answers repository, symbol, call-graph, interface, impact, test, and pre-edit agent-context questions; it is not a hosted service. Primary executable entry point: cmd/gosherpa/main.go.
CLI Orchestration and Output Contract
Command registration, flag handling, dispatch, and terminal/JSON rendering are centralized in cmd/gosherpa/command_registry.go, cmd/gosherpa/command_handlers.go, and cmd/gosherpa/cli_json.go. The CLI exposes human-readable tables plus stable JSON envelopes for automation. Command-specific orchestration covers analysis, agent workflows, PR summaries, snapshots, and initialization in cmd/gosherpa/analyze.go, cmd/gosherpa/agent.go, and cmd/gosherpa/pr.go.
Repository Discovery and Semantic Analysis
The core analysis layer discovers repository roots, module/workspace layout, Go source, packages, symbols, references, calls, dependencies, tests, entrypoints, architecture, and risk. Its central repository model and scan/parse pipeline live in internal/sherpa/repository.go, internal/sherpa/scan.go, and internal/sherpa/parse.go. Semantic repository loading and caching form a boundary around Go-aware analysis in internal/semantics/repository.go and internal/semantics/repository_cache.go.
Symbol and Relationship Graph
Symbol indexing provides reusable symbol and relationship records, while Sherpa queries derive callers, callees, references, paths, dependencies, interfaces, and implementations. Key graph-facing components are internal/symbolindex/index.go, internal/symbolindex/relationship.go, and internal/sherpa/relationship_records.go; query implementations include internal/sherpa/call.go, internal/sherpa/reference.go, and internal/sherpa/dependency.go. This is the main boundary supplying structured facts to higher-level context and impact stages.
Snapshot and Configuration Layer
init persists repository settings and a reusable bounded inventory under .gosherpa; later commands may reuse it but must fall back to live analysis when missing, stale, invalid, or insufficient. Configuration and snapshot persistence are implemented in internal/config/config.go, internal/snapshot/snapshot.go, and wired by cmd/gosherpa/init.go and cmd/gosherpa/snapshot_reuse.go. Snapshot reuse is an optimization, not the source of truth.
Context, Impact, and Test Planning
Higher-level workflows convert analysis and Git diffs into bounded, ordered guidance for agents and developers. Agent-context reporting, byte limits, semantic reading order, and diff/file/package reports live in internal/agentcontext/report.go, internal/agentcontext/semantic.go, and internal/agentcontext/diff_report.go. Impact traversal and relationship evidence are in internal/impact/report.go, internal/impact/diff.go, and internal/impact/snapshot_relationships.go. Test inventory/planning is built in internal/sherpa/test_inventory.go and internal/sherpa/test_plan.go.
Git and GitHub Action Boundary
Local Git integration resolves base refs and changed files for diff-based context, impact, affected tests, and PR summaries via internal/git/base.go and internal/git/diff.go. GitHub is optional infrastructure: the composite action in action.yml runs the CLI against PR bases, produces step summaries, and uploads JSON artifacts. CI and GitHub Pages workflows reside in .github/workflows/ci.yml and .github/workflows/pages.yml.
Main entry points: relationship_records.go Relationship queries · repository.go Repository scan and parse · agent.go Agent, analysis, and PR commands · command_handlers.go Command handlers
Components 19
CLI Runtime
- gosherpa executable
cmd/gosherpa/main.go - Command dispatch · Registers commands, flags, handlers, and renderers.
cmd/gosherpa/command_registry.go - Command handlers
cmd/gosherpa/command_handlers.go - Terminal and JSON output · Provides tables and stable JSON envelopes.
cmd/gosherpa/cli_json.go - Agent, analysis, and PR commands
cmd/gosherpa/agent.go - Init and snapshot reuse · Persists settings and reuses valid bounded inventories.
cmd/gosherpa/init.go
Analysis Core
- Repository scan and parse · Discovers layout, source, packages, symbols, tests, and structural facts.
internal/sherpa/repository.go - Go semantic loader · Loads and caches Go-aware repository semantics.
internal/semantics/repository.go - Symbol relationship index · Reusable symbols and relationship records for structural queries.
internal/symbolindex/index.go - Relationship queries · Derives calls, references, paths, dependencies, and implementations.
internal/sherpa/relationship_records.go - Test inventory and plan
internal/sherpa/test_inventory.go
Guidance Workflows
- Agent context reports · Produces bounded semantic reading order and diff guidance.
internal/agentcontext/report.go - Impact analysis · Traverses relationship evidence for changed code.
internal/impact/report.go - Local Git diff · Resolves base refs and changed files.
internal/git/diff.go
Local Persistence
- Repository settings
internal/config/config.go - Reusable inventory snapshot · Optimization only; live analysis remains authoritative.
internal/snapshot/snapshot.go
GitHub Integration
- GitHub composite action · Runs CLI for PRs, summaries, and JSON artifacts.
action.yml - CI workflow
.github/workflows/ci.yml - Pages workflow
.github/workflows/pages.yml
Connections 22
- gosherpa executable → Command dispatch: starts
- Command dispatch → Command handlers: dispatches
- Command handlers → Terminal and JSON output: renders through
- Command handlers → Repository scan and parse: requests analysis
- Repository scan and parse → Go semantic loader: loads Go semantics
- Go semantic loader → Symbol relationship index: supplies semantic facts
- Repository scan and parse → Symbol relationship index: indexes discovered code
- Symbol relationship index → Relationship queries: backs
- Relationship queries → Test inventory and plan: informs
- Agent, analysis, and PR commands → Agent context reports: runs
- Agent, analysis, and PR commands → Impact analysis: runs
- Agent, analysis, and PR commands → Test inventory and plan: requests
- Local Git diff → Agent context reports: changed files
- Local Git diff → Impact analysis: diff input
- Relationship queries → Agent context reports: structural context
- Relationship queries → Impact analysis: relationship evidence
- Init and snapshot reuse → Repository settings: writes settings
- Init and snapshot reuse → Reusable inventory snapshot: persists inventory
- Reusable inventory snapshot → Repository scan and parse: reused when valid
- GitHub composite action → gosherpa executable: invokes CLI
- CI workflow → GitHub composite action: automation context
- Pages workflow → GitHub composite action: publishing context