How vishal2612200/agentpack works
1. What this repository is
AgentPack is a local-first context engine for coding agents. Its core job is to scan a repository, score what matters for a task, and emit a compact “pack” of files, tests, rules, warnings, and provenance that another agent can consume before editing code.
2. Primary runtime and delivery shape
The main implementation is a Python CLI package under src/agentpack. That engine is the source of truth for scanning, ranking, packaging, routing, review prep, and diagnostics. Around it are thin distribution layers: an npm wrapper in npm/, native integration stubs in native-integrations/, and CLI/IDE plugin assets stored under src/agentpack/data/ and the repo root.
3. Core orchestration layer
src/agentpack/application/pack_service.py is the central orchestration boundary for “pack” creation. It sits above analysis, caching, rendering, and provenance, and is the main application-service layer that turns raw repo signals into a usable context artifact.
4. Repository analysis subsystem
src/agentpack/analysis/ contains the signal extraction and scoring inputs: import parsing for Python/JS/TS/Go/Java/Rust, symbol extraction, dependency graphs, monorepo detection, naming signals, task classification, role inference, repo maps, and broad-context detection. This layer is responsible for understanding the repository structure before any context is selected.
5. Task routing subsystem
src/agentpack/router/ decides which skill, rule, prompt, or workflow best fits the task. It includes discovery, parsing, scoring, prompt building, and skills indexing. In architecture terms, this is the “task-to-workflow matcher” that converts a user intent like “fix auth expiry” into an actionable local route.
6. Context packing and representation
src/agentpack/core/context_pack.py, snapshot.py, structured_format.py, citations.py, token_estimator.py, redactor.py, and related files implement the pack assembly pipeline. This layer handles budgeted selection, token accounting, file receipts, freshness checks, citation-backed provenance, and redaction/safety before rendering output.
7. State, cache, and repository lifecycle
src/agentpack/core/cache.py, execution_state.py, task_freshness.py, changed_paths.py, git.py, ignore.py, scanner.py, and pack_registry.py provide persistence and repo-awareness. They track what changed, what was already summarized, what should be ignored, and whether a prior pack is stale relative to task or git state.
8. Rendering and output formats
src/agentpack/renderers/ converts the internal pack model into consumable artifacts such as compact text, markdown, receipts, and TOON format. src/agentpack/output_compression/ is a separate output-shaping layer for shrinking or normalizing command output. This is the boundary between internal selection logic and what humans or agents actually read.
9. CLI command surface
src/agentpack/commands/ is the user-facing shell API. Commands cover packing, routing, review, learning, benchmarking, diagnostics, installation, init/doctor/scan/status/watch, memory/state, CI helpers, and integrations. The CLI is the main entrypoint that stitches together application services, analysis, and renderers.
10. Agent and editor integrations
src/agentpack/adapters/ and src/agentpack/installers/ encode platform-specific behavior for Claude, Codex, Cursor, Windsurf, Antigravity, and generic flows. src/agentpack/integrations/ and native-integrations/ hold the glue for Git hooks, VS Code tasks, global install handling, platform detection, and editor-extension shells. These are intentionally thin boundaries over the core engine.
11. Learning, evaluation, and routing intelligence
src/agentpack/learning/ and src/agentpack/summaries/ support reusable memory, lesson extraction, feedback loops, quality ranking, and offline summaries. src/agentpack/core/evals.py, e2e_benchmark.py, and src/agentpack/analysis/ranking.py connect this intelligence to measured pack quality. The architecture treats learning as local metadata that improves future routing and ranking, not as a cloud model service.
12. Session and review workflows
src/agentpack/session/ and src/agentpack/core/pack_handoff.py manage thread context, references, and event/state continuity across agent interactions. Review-oriented artifacts in src/agentpack/data/review/ and the review commands build staged PR-review bundles rather than a single prompt, separating “understand” from “judge” to make review outputs more reproducible.
13. MCP and plugin distribution
src/agentpack/mcp_server.py exposes the local engine as MCP tools, so external agents can call the same repository-analysis and packing workflow through a standard tool interface. The repo also ships plugin metadata and generated assets under src/agentpack/data/codex_plugin/ and the root .codex-plugin, .cursor, .windsurf, etc., which are distribution surfaces rather than core logic.
14. Test and fixture architecture
tests/ is broad and integration-heavy, with fixtures for Python/FastAPI, Django REST, Go services, Rails, Next.js, mixed-language repos, and secret-repo cases. Those fixtures reflect the engine’s real architecture concern: selecting and ranking repo context across heterogeneous codebases, not just one framework.
15. End-to-end data flow
The main flow is: CLI/agent request → scan and repo signals → task classification/routing → ranking and freshness checks → pack assembly with citations and receipts → renderer/output artifact → optional MCP/plugin consumption. Most boundaries are local and file-system based, with Git and editor hooks as the main external interfaces; there is no cloud index in the core architecture.
Main entry points: pack_service.py Pack service · commands Commands · context_pack.py Context pack · analysis Analysis
Components 23
Core Engine
Main Python implementation for scanning, routing, packing, rendering, and repo state.
- CLI · User-facing command surface that dispatches into application services and subsystem commands.
src/agentpack/cli.py - Pack service · Central application boundary that coordinates pack creation end to end.
src/agentpack/application/pack_service.py - Analysis · Repository understanding layer: imports, symbols, dependency graphs, repo maps, task intent, and ranking signals.
src/agentpack/analysis - Router · Selects the best skill, rule, prompt, or workflow for a task.
src/agentpack/router - Context pack · Builds the budgeted pack with selection, freshness, citations, redaction, and token accounting.
src/agentpack/core/context_pack.py - Repo state · Tracks cache, git changes, ignore rules, execution state, and pack registry freshness.
src/agentpack/core - Renderers · Formats the internal pack into compact text, markdown, receipts, and TOON.
src/agentpack/renderers - Compression · Normalizes or shrinks command output before it reaches the user or agent.
src/agentpack/output_compression - Commands · Pack, route, review, diagnose, install, scan, status, watch, learn, benchmark, and maintenance commands.
src/agentpack/commands - Learning · Collects lessons, feedback, quality signals, and reusable skill memory for future routing and ranking.
src/agentpack/learning - Session · Maintains thread context, references, and event continuity across interactions.
src/agentpack/session - Dashboard · Collects and renders operational metrics and pack-related views.
src/agentpack/dashboard
Integrations
Thin boundaries for agents, editors, hooks, and MCP exposure.
- MCP server · Exposes the local engine as MCP tools for external agents.
src/agentpack/mcp_server.py - Adapters · Agent-specific behavior for Claude, Codex, Cursor, Windsurf, Antigravity, and generic flows.
src/agentpack/adapters - Installers · Platform-specific installation and setup logic for editor and agent environments.
src/agentpack/installers - Hooks & platform · Git hooks, global install handling, platform detection, and VS Code task helpers.
src/agentpack/integrations
Distribution
Non-Python delivery surfaces and plugin packaging.
- Native plugins · Cursor and Windsurf extension shells that wrap the Python core.
native-integrations - npm wrapper · JavaScript launcher and package metadata for CLI distribution.
npm - Plugin assets · Published plugin metadata, skills, and agent-specific assets shipped with the repo.
src/agentpack/data/codex_plugin
Docs & Ops
Repository documentation, benchmarks, and release/workflow assets.
- Docs · Architecture, usage, integrations, threat model, and benchmark documentation.
docs - Benchmarks · Public-repo benchmark definitions and result history for pack quality and routing.
benchmarks
Connections 28
- CLI → Commands: dispatches · CLI entrypoint routes subcommands into command handlers.
- Commands → Pack service: packs · Pack-related commands invoke the orchestration boundary.
- Commands → Router: routes · Route-oriented commands use the task matcher.
- Commands → Learning: learns · Learning, review, and refresh commands update local memory.
- Commands → Dashboard: reports · Dashboard and stats commands assemble operational views.
- Pack service → Analysis: analyzes · Pack creation depends on repository signals and scoring.
- Pack service → Router: selects · Task intent is resolved into a workflow or skill path.
- Pack service → Context pack: assembles · Selected signals become a bounded context artifact.
- Context pack → Repo state: checks freshness · Uses cache, git, ignored paths, and prior packs to decide what is stale.
- Context pack → Renderers: renders · Internal pack representation is converted into consumable formats.
- Context pack → Compression: shrinks · Output shaping can reduce or normalize command output.
- Analysis → Router: feeds signals · Task classification and repo understanding inform routing decisions.
- Analysis → Learning: ranks · Scoring and quality signals help prioritize lessons and context.
- Repo state → Session: persists · Execution state and thread context support continuity across runs.
- Session → Pack service: handoffs · Session references and thread continuity can influence pack construction.
- Learning → Router: improves · Lessons and skill maps refine future route selection.
- Learning → Benchmarks: evaluates · Offline benchmarking and quality measures validate learning effects.
- Renderers → Adapters: consumes · Rendered artifacts are tailored for specific agent environments.
- MCP server → Pack service: exposes · MCP tools call the same pack orchestration pipeline.
- Adapters → Installers: configures · Agent-specific adapters pair with install/setup flows.
- Installers → Hooks & platform: hooks · Installers rely on platform and hook integration helpers.
- Native plugins → Adapters: wraps · Editor extension shells provide thin runtime integration around adapters.
- npm wrapper → CLI: launches · Node wrapper launches the Python CLI package.
- Plugin assets → Native plugins: ships · Packaged plugin metadata and skills are distributed with editor integrations.
- Tests → Fixtures: uses · Integration tests exercise the engine against representative repositories.
- Tests → Pack service: verifies · End-to-end tests validate the main pack pipeline.
- Docs → Commands: documents · Docs explain CLI commands, runtime flow, and integrations.
- Benchmarks → Analysis: measures · Benchmark results track ranking and selection quality.