codebase-lens 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # codebase-lens
2
+
3
+ An evidence-backed Pi skill for understanding unfamiliar code projects.
4
+
5
+ It helps Pi build a practical project map instead of producing a speculative directory tour. The skill supports project orientation, feature-flow tracing, change-impact analysis, verification, project-specific investigation strategies, and a shared vocabulary bridge between the codebase, the user, and the model.
6
+
7
+ ## What it does
8
+
9
+ - Detects the project's language, framework, entry points, and run commands.
10
+ - Maps major components and recommends a dependency-ordered reading path.
11
+ - Traces a request, command, page, event, or job from entry to output.
12
+ - Analyzes the likely blast radius of a file, symbol, diff, or feature.
13
+ - Records evidence using `SOURCE`, `RUNTIME`, `INFERRED`, `UNKNOWN`, and `CONTRADICTED` labels.
14
+ - Captures canonical project terms, code names, aliases, boundaries, and confusing concepts.
15
+ - Creates or updates a root `ONBOARDING.md` with a Mermaid architecture diagram.
16
+ - Uses parallel read-only Pi subagents for broad investigations when available.
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ pi install npm:codebase-lens
22
+ ```
23
+
24
+ ## Use
25
+
26
+ Invoke it manually in Pi:
27
+
28
+ ```text
29
+ /codebase-lens
30
+ ```
31
+
32
+ Example requests:
33
+
34
+ ```text
35
+ Use codebase-lens in ORIENT mode. Explain this repository and give me a reading path.
36
+
37
+ Use codebase-lens in TRACE mode. Trace how an authenticated upload reaches storage.
38
+
39
+ Use codebase-lens in IMPACT mode. What could change if I modify this service?
40
+ ```
41
+
42
+ The skill is user-invoked by default so a full project investigation does not start unexpectedly during ordinary coding work.
43
+
44
+ ## Generated artifact
45
+
46
+ After an orientation or a materially useful focused investigation, the skill creates or updates:
47
+
48
+ ```text
49
+ ONBOARDING.md
50
+ ```
51
+
52
+ The document includes the detected stack, architecture map, Mermaid diagram, startup flow, component map, project vocabulary, tests, configuration, recommended reading order, and unresolved questions. Existing manual content is preserved.
53
+
54
+ ## Safety
55
+
56
+ Pi packages run with full system access. This package contains a skill that instructs the model how to inspect repositories and write `ONBOARDING.md`. Review the skill source before installing or using it in sensitive repositories.
57
+
58
+ ## License
59
+
60
+ MIT
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "codebase-lens",
3
+ "version": "0.1.0",
4
+ "description": "A Pi skill for evidence-backed codebase orientation, flow tracing, impact analysis, vocabulary mapping, and onboarding documentation.",
5
+ "keywords": [
6
+ "pi-package",
7
+ "pi",
8
+ "agent-skill",
9
+ "codebase",
10
+ "codebase-understanding",
11
+ "onboarding"
12
+ ],
13
+ "license": "MIT",
14
+ "files": [
15
+ "skills/"
16
+ ],
17
+ "pi": {
18
+ "skills": [
19
+ "./skills"
20
+ ]
21
+ }
22
+ }
@@ -0,0 +1,349 @@
1
+ ---
2
+ name: codebase-lens
3
+ description: Analyze an unfamiliar code project and produce an evidence-backed map of its architecture, entry points, flows, dependencies, and change impact.
4
+ disable-model-invocation: true
5
+ ---
6
+
7
+ # Codebase Lens
8
+
9
+ Build a verifiable mental model of a code project. Do not produce a confident directory tour. Read the smallest useful set of files, connect conclusions to evidence, and explain what remains unknown.
10
+
11
+ ## Operating contract
12
+
13
+ - Work read-first and preserve existing user changes.
14
+ - Do not install dependencies, switch branches, reset files, or edit source code.
15
+ - This skill is authorized to create or update the root `ONBOARDING.md` after investigation.
16
+ - Preserve manually written sections in an existing `ONBOARDING.md`; update generated sections rather than replacing the document.
17
+ - Read an existing `CONTEXT.md` or project vocabulary section before introducing terminology.
18
+ - Record confirmed project concepts, domain terms, abbreviations, and code-specific jargon in the onboarding document as a communication bridge.
19
+ - Read project configuration and entry points before reading broad areas of source.
20
+ - Treat names and directory conventions as search hints, not evidence.
21
+ - Do not claim runtime behavior from static code alone.
22
+ - Keep the investigation proportional to the user's question. For a large monorepo, establish the relevant package or service before exploring deeper.
23
+
24
+ ## Investigation modes
25
+
26
+ Select the smallest mode that answers the request. Modes may be combined.
27
+
28
+ | Mode | Use when the user asks | Main result |
29
+ |---|---|---|
30
+ | `ORIENT` | “Explain this project” or “Where should I start?” | Project map, stack, entry points, architecture, reading path |
31
+ | `TRACE` | “How does this feature/request work?” | Evidence-backed path from entry to output and side effects |
32
+ | `IMPACT` | “What will this change affect?” | Dependency, blast-radius, test, and deployment analysis |
33
+ | `VERIFY` | “Is this understanding or implementation correct?” | Independent checks, contradictions, and remaining unknowns |
34
+
35
+ If no mode is named, use `ORIENT` for a broad request, `TRACE` for a named feature or endpoint, and `IMPACT` for a file, diff, commit, or pull request. Record the selected mode in the report.
36
+
37
+ ## Evidence ledger
38
+
39
+ Attach an evidence label to every material conclusion:
40
+
41
+ - `SOURCE` — directly shown by source or configuration.
42
+ - `RUNTIME` — observed by executing a command; include the command, exit status, and relevant result.
43
+ - `INFERRED` — a conclusion supported by multiple signals; state the signals.
44
+ - `UNKNOWN` — the repository or environment does not establish the answer.
45
+ - `CONTRADICTED` — sources disagree; show both sides.
46
+
47
+ A static import or call graph is not `RUNTIME`. A passing test only supports the behavior asserted by that test. A skipped, flaky, timed-out, credential-blocked, or unavailable check remains an explicit limitation.
48
+
49
+ ## Project vocabulary and communication bridge
50
+
51
+ Treat terminology as part of the project model, not as incidental prose. Capture terms that a new contributor, user, or future agent needs in order to communicate efficiently:
52
+
53
+ - Domain concepts such as `Order`, `Workspace`, `Run`, `Tenant`, or `Policy`.
54
+ - Project-specific meanings of common words such as “account”, “job”, “session”, or “member”.
55
+ - Abbreviations, acronyms, code names, legacy names, and user-facing labels.
56
+ - Concepts represented by types, database tables, API resources, events, state values, or queue names.
57
+ - Pairs that are easy to confuse, such as `User` versus `Account`, or `Job` versus `Run`.
58
+
59
+ For each term, record:
60
+
61
+ | Field | Meaning |
62
+ |---|---|
63
+ | Canonical term | The term agents and users should prefer |
64
+ | Code names and aliases | Identifiers, abbreviations, legacy names, or UI labels |
65
+ | Meaning | What the concept represents in this project |
66
+ | Boundaries | What it includes and what it must not be confused with |
67
+ | Lifecycle or relationships | Important states, owners, parents, or related concepts |
68
+ | Evidence | Files, symbols, API fields, tests, or user confirmation |
69
+ | Status | `CONFIRMED`, `CANDIDATE`, `AMBIGUOUS`, or `CONTRADICTED` |
70
+
71
+ Use `CONFIRMED` only when the meaning is supported by source, documentation, or explicit user clarification. Keep `CANDIDATE` terms visible when they are useful but not yet settled. When the same word has multiple meanings, surface the collision instead of silently choosing one. Use the canonical term in the response after it is established, and mention aliases once so the user can connect their language to the code.
72
+
73
+ Keep domain definitions focused on meaning and boundaries. Put implementation locations in the evidence and code-name columns; do not turn the glossary into a file-by-file catalog.
74
+
75
+ ## Workflow
76
+
77
+ ### 1. Establish scope and baseline
78
+
79
+ Identify:
80
+
81
+ - Current working directory and repository root.
82
+ - User-specified package, service, feature, file, diff, branch, or revision.
83
+ - Whether the repository is a monorepo.
84
+ - Current revision and worktree status.
85
+ - Existing `AGENTS.md`, `CLAUDE.md`, `.pi` instructions, or other project guidance.
86
+
87
+ Do not modify the worktree while establishing the baseline.
88
+
89
+ **Completion criterion:** The report states the exact repository scope, revision when available, selected mode, and any pre-existing uncommitted changes.
90
+
91
+ ### 2. Reconnaissance
92
+
93
+ Inspect project landmarks before broad source exploration:
94
+
95
+ - README files and contributor documentation.
96
+ - Package manifests such as `package.json`, `pyproject.toml`, `go.mod`, `Cargo.toml`, `pom.xml`, `Gemfile`, or `pubspec.yaml`.
97
+ - Build, start, test, and lint scripts.
98
+ - Application bootstrap files.
99
+ - HTTP routes, CLI registration, event consumers, scheduled jobs, or queue workers.
100
+ - Database migrations, schemas, ORM configuration, and external-service clients.
101
+ - CI, Docker, deployment, and environment-variable examples.
102
+
103
+ Use directory listings and targeted text searches to narrow the next files. Avoid reading generated directories, dependency vendors, build output, and caches unless the question specifically concerns them.
104
+
105
+ **Completion criterion:** The report lists confirmed languages, frameworks, versions when present, run commands, entry candidates, system boundaries, and initial vocabulary candidates, each with evidence or an `UNKNOWN` label.
106
+
107
+ ### 3. Apply the project-type strategy
108
+
109
+ After detecting the stack, use the matching strategy below. Combine strategies for polyglot repositories. These are search priorities, not assumptions about the architecture.
110
+
111
+ | Project type | Inspect first | Trace especially |
112
+ |---|---|---|
113
+ | React / Next.js / Vue / Angular | app bootstrap, routes, pages, components, state stores, API clients | page → state/query → API → rendering |
114
+ | Node.js / Express / NestJS | bootstrap, module registration, routes/controllers, middleware, services, repositories | request → middleware → controller → service → persistence |
115
+ | Python / Django / Flask / FastAPI | app factory, settings, routers/views, dependencies, services, models, tasks | request → dependency/auth → handler → service → ORM/external call |
116
+ | Java / Spring | application class, configuration, controllers, filters, services, repositories, entities | request → filter → controller → service → repository → response |
117
+ | Go | `cmd/`, `internal/`, `main`, router setup, handlers, services, interfaces, migrations | server startup → middleware → handler → use case → store |
118
+ | Rust | workspace manifest, binaries, `main`/`lib`, modules, traits, handlers, adapters | binary → module/trait boundary → use case → adapter |
119
+ | Ruby / Rails | routes, controllers, models, jobs, concerns, initializers | route → controller → model/service → job or response |
120
+ | Mobile applications | app bootstrap, navigation, screens, state management, repositories, platform services | app start → navigation → screen → state → repository |
121
+ | CLI tools | executable entry, argument parser, command registry, handlers, config loading | process → parser → command → domain operation → output |
122
+ | Libraries / SDKs | public exports, package entry, interfaces, adapters, examples, contract tests | consumer API → core abstraction → implementation/transport |
123
+
124
+ For an unlisted stack, derive a strategy from its actual manifest, bootstrap mechanism, public boundary, and tests. Never force a listed pattern onto the project.
125
+
126
+ **Completion criterion:** The chosen strategy names the files and symbols it used; each inferred layer is backed by code, configuration, or is marked `INFERRED`.
127
+
128
+ ### 4. Capture the vocabulary bridge
129
+
130
+ During reconnaissance and flow tracing, extract terminology from documentation, type and class names, database schemas, API resources, events, state machines, tests, UI labels, and user language. Reconcile these terms with any existing `CONTEXT.md` or glossary.
131
+
132
+ Prefer one canonical term for each concept. Record aliases and code identifiers so users can ask in natural language while the agent can find the corresponding implementation. Explicitly record confusing near-synonyms and overloaded terms. If source and documentation disagree, preserve both observations and mark the term `CONTRADICTED` until clarified.
133
+
134
+ Do not promote a guess to canonical vocabulary. If a concept is only visible through a name or a single ambiguous use, record it as `CANDIDATE` with the evidence needed to confirm it.
135
+
136
+ **Completion criterion:** The project has a vocabulary table containing the important confirmed terms, useful candidates, aliases, confusing pairs, and unresolved terminology conflicts.
137
+
138
+ ### 5. Build the architecture map (`ORIENT`)
139
+
140
+ Compress the project into 5–7 meaningful components rather than summarizing every file. For each component record:
141
+
142
+ - Responsibility.
143
+ - Public or internal entry point.
144
+ - Important dependencies and dependents.
145
+ - Key files and symbols.
146
+ - Data or control boundary.
147
+ - Evidence label.
148
+
149
+ Prefer a dependency-ordered reading path of no more than 12 files. Include tests and configuration when they explain behavior better than implementation files.
150
+
151
+ **Completion criterion:** Every core component has at least one path and symbol as evidence, and the reading path explains why each file comes next.
152
+
153
+ ### 6. Trace a concrete flow (`TRACE`)
154
+
155
+ Name the object being traced: URL, CLI subcommand, page, event, job, type, class, or function. Follow the actual registration and call relationships:
156
+
157
+ ```text
158
+ entry → registration/router → parsing/validation → orchestration → persistence or external call → state change → output
159
+ ```
160
+
161
+ Record conditions, error paths, retries, transactions, authorization, caching, and other side effects. For dependency injection, reflection, dynamic registration, or configuration-driven behavior that cannot be statically confirmed, use `UNKNOWN` or `INFERRED`.
162
+
163
+ **Completion criterion:** The result is a causal, ordered path with a file, symbol, role, and evidence label for every important node.
164
+
165
+ ### 7. Analyze change impact (`IMPACT`)
166
+
167
+ For a target file, symbol, diff, commit, or feature, inspect:
168
+
169
+ - Direct importers, callers, subclasses, and implementations.
170
+ - Reverse callers and exposed APIs, routes, commands, events, or exports.
171
+ - Shared types, schemas, configuration, database tables, and serialized formats.
172
+ - Unit, integration, end-to-end, contract, and snapshot tests.
173
+ - Build, deployment, permission, performance, and compatibility boundaries.
174
+
175
+ Classify findings as direct impact, indirect impact, validation required, or no evidence.
176
+
177
+ **Completion criterion:** Every reported impact has a relationship and evidence; possible relevance is not presented as confirmed impact.
178
+
179
+ ### 8. Independently verify (`VERIFY`)
180
+
181
+ Use evidence that is different from the initial path:
182
+
183
+ - Search from callers back toward the target.
184
+ - Compare registration sites with configuration.
185
+ - Compare implementation behavior with test inputs and assertions.
186
+ - Run a focused existing check only when it is safe and appropriate; record its exact result.
187
+ - Re-check the worktree after commands that might create files.
188
+
189
+ If a command cannot run because of missing dependencies, services, credentials, or environment restrictions, report the blocker and leave the conclusion unverified.
190
+
191
+ **Completion criterion:** Each key conclusion is supported, contradicted, or explicitly unresolved, and the report lists the remaining unknowns.
192
+
193
+ ## Parallel subagent analysis in Pi
194
+
195
+ When the Pi subagent facility is available and the investigation is broad enough to benefit from independent evidence, use a single `workflowScript` with a small parallel fanout. Before launching, inspect available agent capabilities and launch only executable, non-disabled agents.
196
+
197
+ Use read-only children with distinct seams:
198
+
199
+ 1. **Structure scout** — manifests, directory boundaries, bootstrap files, entry points, and run commands.
200
+ 2. **Flow scout** — the named feature, endpoint, command, event, or data path.
201
+ 3. **Quality scout** — tests, conventions, configuration, deployment, and likely impact boundaries.
202
+
203
+ Each child receives a complete task contract: repository and scope, read-only authority, target question, evidence format, stop conditions, and concise output. Do not launch duplicate scouts. Children return reports; they do not edit `ONBOARDING.md` and do not spawn further agents.
204
+
205
+ Conceptual Pi orchestration shape:
206
+
207
+ ```js
208
+ subagent({
209
+ async: true,
210
+ context: "fresh",
211
+ workflowScript: `
212
+ const reports = await runs.all([
213
+ { key: "structure", agent: "scout", task: "Read-only structure analysis of the specified repository. Report manifests, stack, entry points, boundaries, commands, and evidence paths." },
214
+ { key: "flow", agent: "scout", task: "Read-only flow analysis of the specified feature or entry point. Trace callers, callees, side effects, and unknown dynamic edges with evidence." },
215
+ { key: "quality", agent: "scout", task: "Read-only analysis of tests, conventions, configuration, deployment, and likely impact boundaries. Report evidence and gaps." }
216
+ ]);
217
+ return reports.map(report => report.output);
218
+ `
219
+ })
220
+ ```
221
+
222
+ The parent agent remains responsible for scope, conflict resolution, synthesis, writing the onboarding document, and the final report. If subagents are unavailable or the task is small, perform the equivalent focused investigation directly.
223
+
224
+ **Completion criterion:** Parallel reports have distinct scopes, are reconciled against the actual files, and no child conclusion is accepted without evidence.
225
+
226
+ ## Automatic `ONBOARDING.md` generation
227
+
228
+ After completing `ORIENT`, or after a focused investigation materially improves the project map, create or update the root `ONBOARDING.md` automatically.
229
+
230
+ Preserve existing manually authored material. Maintain a clearly marked generated section with the revision and generation date. Do not write speculative content into the generated section. If the repository is not writable, provide the complete proposed content in the response and explain the write failure.
231
+
232
+ Use this structure:
233
+
234
+ ````md
235
+ # Project Onboarding
236
+
237
+ > Generated section: revision `<revision>`, date `<date>`.
238
+ > Regenerate with `/codebase-lens`.
239
+
240
+ ## One-line overview
241
+
242
+ ## Scope and confidence
243
+ - Scope:
244
+ - Revision:
245
+ - Modes:
246
+ - Evidence limitations:
247
+
248
+ ## Technology and commands
249
+
250
+ ## Architecture map
251
+
252
+ ```mermaid
253
+ flowchart TB
254
+ Entry[Entry point] --> Boundary[Boundary]
255
+ Boundary --> Core[Core component]
256
+ Core --> Data[Data or external system]
257
+ ```
258
+
259
+ The diagram must represent only evidence-backed relationships. Label uncertain edges or nodes as `INFERRED` or `UNKNOWN`, and add a short legend below the diagram. Keep it readable with 5–7 primary components; use a separate focused diagram for a detailed flow.
260
+
261
+ ## Directory and component map
262
+
263
+ | Component | Responsibility | Key paths and symbols | Evidence |
264
+ |---|---|---|---|
265
+
266
+ ## Startup and request / command lifecycle
267
+
268
+ ## Project vocabulary
269
+
270
+ | Canonical term | Code names and aliases | Meaning and boundaries | Lifecycle / relationships | Evidence | Status |
271
+ |---|---|---|---|---|---|
272
+
273
+ Use this section as the shared language between the project and future agents. Prefer canonical terms in conversation and mention aliases when they help users find the matching code.
274
+
275
+ ## Important configuration and external dependencies
276
+
277
+ ## Conventions and testing
278
+
279
+ ## Recommended reading order
280
+
281
+ 1. `path/to/file` — why it matters
282
+
283
+ ## Open questions and verification gaps
284
+ ````
285
+
286
+ For `TRACE`, add or update a focused flow section in `ONBOARDING.md`. For `IMPACT`, add the target, affected components, tests to inspect, and unresolved risks. Keep the document scannable; do not append repeated reports on every invocation.
287
+
288
+ **Completion criterion:** `ONBOARDING.md` exists or a documented write failure is reported; its generated section matches the current evidence, contains the vocabulary bridge, and contains an architecture Mermaid diagram or an explicit reason a diagram could not be established.
289
+
290
+ ## Response formats
291
+
292
+ Choose the smallest useful response format. Always include evidence for material claims.
293
+
294
+ ### Overview
295
+
296
+ ```md
297
+ # Project understanding
298
+
299
+ ## Scope
300
+ ## One-line overview
301
+ ## Technology and run commands
302
+ ## Architecture map
303
+ ## Project vocabulary
304
+ ## Startup flow
305
+ ## Recommended reading order
306
+ ## Unknowns
307
+ ```
308
+
309
+ ### Focused flow
310
+
311
+ ```md
312
+ # [Feature] flow
313
+
314
+ Entry → ... → output
315
+
316
+ | Order | File and symbol | Role | Side effects | Evidence |
317
+ |---|---|---|---|---|
318
+
319
+ ## Branches and error paths
320
+ ## Related tests
321
+ ## Unverified relationships
322
+ ```
323
+
324
+ ### Impact analysis
325
+
326
+ ```md
327
+ # Impact of [target]
328
+
329
+ ## Direct impact
330
+ ## Indirect impact
331
+ ## Tests and configuration to inspect
332
+ ## Risks
333
+ ## Evidence and unknowns
334
+ ```
335
+
336
+ ## Final checklist
337
+
338
+ Before finishing, confirm:
339
+
340
+ - The repository scope and revision are explicit.
341
+ - Important claims have paths, symbols, commands, or evidence labels.
342
+ - Static analysis is not presented as runtime verification.
343
+ - Directory names were not treated as proof.
344
+ - Direct impact, inferred impact, and unverified risk are separate.
345
+ - Existing user changes and manual onboarding content were preserved.
346
+ - `ONBOARDING.md` was created or updated after the investigation.
347
+ - Important project vocabulary, aliases, confusing pairs, and unresolved terminology conflicts were recorded.
348
+ - The Mermaid diagram contains only supported relationships and has an uncertainty legend.
349
+ - Subagent reports, when used, were parallel, read-only, distinct, and reconciled by the parent.