opencodekit 0.15.0 → 0.15.2

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.
Files changed (52) hide show
  1. package/dist/index.js +367 -31
  2. package/dist/template/.opencode/README.md +1 -1
  3. package/dist/template/.opencode/agent/vision.md +4 -4
  4. package/dist/template/.opencode/command/agent-browser.md +21 -0
  5. package/dist/template/.opencode/command/complete-next-task.md +77 -0
  6. package/dist/template/.opencode/command/create.md +38 -3
  7. package/dist/template/.opencode/command/design-audit.md +1 -1
  8. package/dist/template/.opencode/command/design.md +1 -1
  9. package/dist/template/.opencode/command/finish.md +8 -0
  10. package/dist/template/.opencode/command/frontend-design.md +21 -0
  11. package/dist/template/.opencode/command/index-knowledge.md +25 -0
  12. package/dist/template/.opencode/command/init.md +6 -0
  13. package/dist/template/.opencode/command/opensrc.md +58 -0
  14. package/dist/template/.opencode/command/skill-create.md +3 -3
  15. package/dist/template/.opencode/command/skill-optimize.md +2 -2
  16. package/dist/template/.opencode/command/start.md +15 -6
  17. package/dist/template/.opencode/command/ui-review.md +1 -1
  18. package/dist/template/.opencode/memory/_templates/prd.md +50 -14
  19. package/dist/template/.opencode/opencode.json +143 -159
  20. package/dist/template/.opencode/package.json +1 -1
  21. package/dist/template/.opencode/skill/accessibility-audit/SKILL.md +1 -1
  22. package/dist/template/.opencode/skill/agent-browser/SKILL.md +376 -0
  23. package/dist/template/.opencode/skill/design-system-audit/SKILL.md +1 -1
  24. package/dist/template/.opencode/skill/frontend-design/SKILL.md +155 -0
  25. package/dist/template/.opencode/skill/frontend-design/references/animation/motion-advanced.md +224 -0
  26. package/dist/template/.opencode/skill/frontend-design/references/animation/motion-core.md +171 -0
  27. package/dist/template/.opencode/skill/frontend-design/references/canvas/execution.md +90 -0
  28. package/dist/template/.opencode/skill/frontend-design/references/canvas/philosophy.md +94 -0
  29. package/dist/template/.opencode/skill/frontend-design/references/shadcn/accessibility.md +132 -0
  30. package/dist/template/.opencode/skill/frontend-design/references/shadcn/core-components.md +153 -0
  31. package/dist/template/.opencode/skill/frontend-design/references/shadcn/form-components.md +158 -0
  32. package/dist/template/.opencode/skill/frontend-design/references/shadcn/setup.md +69 -0
  33. package/dist/template/.opencode/skill/frontend-design/references/shadcn/theming.md +152 -0
  34. package/dist/template/.opencode/skill/frontend-design/references/tailwind/responsive.md +112 -0
  35. package/dist/template/.opencode/skill/frontend-design/references/tailwind/utilities-layout.md +134 -0
  36. package/dist/template/.opencode/skill/frontend-design/references/tailwind/utilities-styling.md +165 -0
  37. package/dist/template/.opencode/skill/frontend-design/references/tailwind/v4-config.md +147 -0
  38. package/dist/template/.opencode/skill/frontend-design/references/tailwind/v4-features.md +128 -0
  39. package/dist/template/.opencode/skill/index-knowledge/SKILL.md +358 -0
  40. package/dist/template/.opencode/skill/mockup-to-code/SKILL.md +1 -1
  41. package/dist/template/.opencode/skill/opensrc/SKILL.md +115 -0
  42. package/dist/template/.opencode/skill/opensrc/references/architecture.md +176 -0
  43. package/dist/template/.opencode/skill/opensrc/references/cli-usage.md +176 -0
  44. package/dist/template/.opencode/skill/opensrc/references/registry-support.md +137 -0
  45. package/dist/template/.opencode/skill/prd/SKILL.md +212 -0
  46. package/dist/template/.opencode/skill/prd-task/SKILL.md +128 -0
  47. package/dist/template/.opencode/skill/prd-task/references/prd-schema.json +28 -0
  48. package/dist/template/.opencode/skill/skill-creator/SKILL.md +155 -0
  49. package/dist/template/.opencode/skill/ui-ux-research/SKILL.md +1 -1
  50. package/dist/template/.opencode/skill/visual-analysis/SKILL.md +1 -1
  51. package/package.json +1 -1
  52. package/dist/template/.opencode/skill/frontend-aesthetics/SKILL.md +0 -117
@@ -0,0 +1,358 @@
1
+ ---
2
+ name: index-knowledge
3
+ description: Generate hierarchical AGENTS.md knowledge base for a codebase. Creates root + complexity-scored subdirectory documentation.
4
+ ---
5
+
6
+ # index-knowledge
7
+
8
+ Generate hierarchical AGENTS.md files. Root + complexity-scored subdirectories.
9
+
10
+ ## Usage
11
+
12
+ ```
13
+ --create-new # Read existing → remove all → regenerate from scratch
14
+ --max-depth=2 # Limit directory depth (default: 5)
15
+ ```
16
+
17
+ Default: Update mode (modify existing + create new where warranted)
18
+
19
+ ---
20
+
21
+ ## Workflow (High-Level)
22
+
23
+ 1. **Discovery + Analysis** (concurrent)
24
+ - Launch parallel explore agents (multiple Task calls in one message)
25
+ - Main session: bash structure + LSP codemap + read existing AGENTS.md
26
+ 2. **Score & Decide** - Determine AGENTS.md locations from merged findings
27
+ 3. **Generate** - Root first, then subdirs in parallel
28
+ 4. **Review** - Deduplicate, trim, validate
29
+
30
+ <critical>
31
+ **TodoWrite ALL phases. Mark in_progress → completed in real-time.**
32
+
33
+ ```
34
+ TodoWrite([
35
+ { id: "discovery", content: "Fire explore agents + LSP codemap + read existing", status: "pending", priority: "high" },
36
+ { id: "scoring", content: "Score directories, determine locations", status: "pending", priority: "high" },
37
+ { id: "generate", content: "Generate AGENTS.md files (root + subdirs)", status: "pending", priority: "high" },
38
+ { id: "review", content: "Deduplicate, validate, trim", status: "pending", priority: "medium" }
39
+ ])
40
+ ```
41
+ </critical>
42
+
43
+ ---
44
+
45
+ ## Phase 1: Discovery + Analysis (Concurrent)
46
+
47
+ **Mark "discovery" as in_progress.**
48
+
49
+ ### Launch Parallel Explore Agents
50
+
51
+ Multiple Task calls in a single message execute in parallel. Results return directly.
52
+
53
+ ```
54
+ // All Task calls in ONE message = parallel execution
55
+
56
+ Task(
57
+ description="project structure",
58
+ subagent_type="explore",
59
+ prompt="Project structure: PREDICT standard patterns for detected language → REPORT deviations only"
60
+ )
61
+
62
+ Task(
63
+ description="entry points",
64
+ subagent_type="explore",
65
+ prompt="Entry points: FIND main files → REPORT non-standard organization"
66
+ )
67
+
68
+ Task(
69
+ description="conventions",
70
+ subagent_type="explore",
71
+ prompt="Conventions: FIND config files (.eslintrc, pyproject.toml, .editorconfig) → REPORT project-specific rules"
72
+ )
73
+
74
+ Task(
75
+ description="anti-patterns",
76
+ subagent_type="explore",
77
+ prompt="Anti-patterns: FIND 'DO NOT', 'NEVER', 'ALWAYS', 'DEPRECATED' comments → LIST forbidden patterns"
78
+ )
79
+
80
+ Task(
81
+ description="build/ci",
82
+ subagent_type="explore",
83
+ prompt="Build/CI: FIND .github/workflows, Makefile → REPORT non-standard patterns"
84
+ )
85
+
86
+ Task(
87
+ description="test patterns",
88
+ subagent_type="explore",
89
+ prompt="Test patterns: FIND test configs, test structure → REPORT unique conventions"
90
+ )
91
+ ```
92
+
93
+ <dynamic-agents>
94
+ **DYNAMIC AGENT SPAWNING**: After bash analysis, spawn ADDITIONAL explore agents based on project scale:
95
+
96
+ | Factor | Threshold | Additional Agents |
97
+ |--------|-----------|-------------------|
98
+ | **Total files** | >100 | +1 per 100 files |
99
+ | **Total lines** | >10k | +1 per 10k lines |
100
+ | **Directory depth** | ≥4 | +2 for deep exploration |
101
+ | **Large files (>500 lines)** | >10 files | +1 for complexity hotspots |
102
+ | **Monorepo** | detected | +1 per package/workspace |
103
+ | **Multiple languages** | >1 | +1 per language |
104
+
105
+ ```bash
106
+ # Measure project scale first
107
+ total_files=$(find . -type f -not -path '*/node_modules/*' -not -path '*/.git/*' | wc -l)
108
+ total_lines=$(find . -type f \( -name "*.ts" -o -name "*.py" -o -name "*.go" \) -not -path '*/node_modules/*' -exec wc -l {} + 2>/dev/null | tail -1 | awk '{print $1}')
109
+ large_files=$(find . -type f \( -name "*.ts" -o -name "*.py" \) -not -path '*/node_modules/*' -exec wc -l {} + 2>/dev/null | awk '$1 > 500 {count++} END {print count+0}')
110
+ max_depth=$(find . -type d -not -path '*/node_modules/*' -not -path '*/.git/*' | awk -F/ '{print NF}' | sort -rn | head -1)
111
+ ```
112
+
113
+ Example spawning (all in ONE message for parallel execution):
114
+ ```
115
+ // 500 files, 50k lines, depth 6, 15 large files → spawn additional agents
116
+ Task(
117
+ description="large files",
118
+ subagent_type="explore",
119
+ prompt="Large file analysis: FIND files >500 lines, REPORT complexity hotspots"
120
+ )
121
+
122
+ Task(
123
+ description="deep modules",
124
+ subagent_type="explore",
125
+ prompt="Deep modules at depth 4+: FIND hidden patterns, internal conventions"
126
+ )
127
+
128
+ Task(
129
+ description="cross-cutting",
130
+ subagent_type="explore",
131
+ prompt="Cross-cutting concerns: FIND shared utilities across directories"
132
+ )
133
+ // ... more based on calculation
134
+ ```
135
+ </dynamic-agents>
136
+
137
+ ### Main Session: Concurrent Analysis
138
+
139
+ **While Task agents execute**, main session does:
140
+
141
+ #### 1. Bash Structural Analysis
142
+ ```bash
143
+ # Directory depth + file counts
144
+ find . -type d -not -path '*/\.*' -not -path '*/node_modules/*' -not -path '*/venv/*' -not -path '*/dist/*' -not -path '*/build/*' | awk -F/ '{print NF-1}' | sort -n | uniq -c
145
+
146
+ # Files per directory (top 30)
147
+ find . -type f -not -path '*/\.*' -not -path '*/node_modules/*' | sed 's|/[^/]*$||' | sort | uniq -c | sort -rn | head -30
148
+
149
+ # Code concentration by extension
150
+ find . -type f \( -name "*.py" -o -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.go" -o -name "*.rs" \) -not -path '*/node_modules/*' | sed 's|/[^/]*$||' | sort | uniq -c | sort -rn | head -20
151
+
152
+ # Existing AGENTS.md / CLAUDE.md
153
+ find . -type f \( -name "AGENTS.md" -o -name "CLAUDE.md" \) -not -path '*/node_modules/*' 2>/dev/null
154
+ ```
155
+
156
+ #### 2. Read Existing AGENTS.md
157
+ ```
158
+ For each existing file found:
159
+ Read(filePath=file)
160
+ Extract: key insights, conventions, anti-patterns
161
+ Store in EXISTING_AGENTS map
162
+ ```
163
+
164
+ If `--create-new`: Read all existing first (preserve context) → then delete all → regenerate.
165
+
166
+ #### 3. LSP Codemap (if available)
167
+ ```
168
+ lsp_servers() # Check availability
169
+
170
+ # Entry points (parallel)
171
+ lsp_document_symbols(filePath="src/index.ts")
172
+ lsp_document_symbols(filePath="main.py")
173
+
174
+ # Key symbols (parallel)
175
+ lsp_workspace_symbols(filePath=".", query="class")
176
+ lsp_workspace_symbols(filePath=".", query="interface")
177
+ lsp_workspace_symbols(filePath=".", query="function")
178
+
179
+ # Centrality for top exports
180
+ lsp_find_references(filePath="...", line=X, character=Y)
181
+ ```
182
+
183
+ **LSP Fallback**: If unavailable, rely on explore agents + AST-grep.
184
+
185
+ **Merge: bash + LSP + existing + Task agent results. Mark "discovery" as completed.**
186
+
187
+ ---
188
+
189
+ ## Phase 2: Scoring & Location Decision
190
+
191
+ **Mark "scoring" as in_progress.**
192
+
193
+ ### Scoring Matrix
194
+
195
+ | Factor | Weight | High Threshold | Source |
196
+ |--------|--------|----------------|--------|
197
+ | File count | 3x | >20 | bash |
198
+ | Subdir count | 2x | >5 | bash |
199
+ | Code ratio | 2x | >70% | bash |
200
+ | Unique patterns | 1x | Has own config | explore |
201
+ | Module boundary | 2x | Has index.ts/__init__.py | bash |
202
+ | Symbol density | 2x | >30 symbols | LSP |
203
+ | Export count | 2x | >10 exports | LSP |
204
+ | Reference centrality | 3x | >20 refs | LSP |
205
+
206
+ ### Decision Rules
207
+
208
+ | Score | Action |
209
+ |-------|--------|
210
+ | **Root (.)** | ALWAYS create |
211
+ | **>15** | Create AGENTS.md |
212
+ | **8-15** | Create if distinct domain |
213
+ | **<8** | Skip (parent covers) |
214
+
215
+ ### Output
216
+ ```
217
+ AGENTS_LOCATIONS = [
218
+ { path: ".", type: "root" },
219
+ { path: "src/hooks", score: 18, reason: "high complexity" },
220
+ { path: "src/api", score: 12, reason: "distinct domain" }
221
+ ]
222
+ ```
223
+
224
+ **Mark "scoring" as completed.**
225
+
226
+ ---
227
+
228
+ ## Phase 3: Generate AGENTS.md
229
+
230
+ **Mark "generate" as in_progress.**
231
+
232
+ ### Root AGENTS.md (Full Treatment)
233
+
234
+ ```markdown
235
+ # PROJECT KNOWLEDGE BASE
236
+
237
+ **Generated:** {TIMESTAMP}
238
+ **Commit:** {SHORT_SHA}
239
+ **Branch:** {BRANCH}
240
+
241
+ ## OVERVIEW
242
+ {1-2 sentences: what + core stack}
243
+
244
+ ## STRUCTURE
245
+ \`\`\`
246
+ {root}/
247
+ ├── {dir}/ # {non-obvious purpose only}
248
+ └── {entry}
249
+ \`\`\`
250
+
251
+ ## WHERE TO LOOK
252
+ | Task | Location | Notes |
253
+ |------|----------|-------|
254
+
255
+ ## CODE MAP
256
+ {From LSP - skip if unavailable or project <10 files}
257
+
258
+ | Symbol | Type | Location | Refs | Role |
259
+
260
+ ## CONVENTIONS
261
+ {ONLY deviations from standard}
262
+
263
+ ## ANTI-PATTERNS (THIS PROJECT)
264
+ {Explicitly forbidden here}
265
+
266
+ ## UNIQUE STYLES
267
+ {Project-specific}
268
+
269
+ ## COMMANDS
270
+ \`\`\`bash
271
+ {dev/test/build}
272
+ \`\`\`
273
+
274
+ ## NOTES
275
+ {Gotchas}
276
+ ```
277
+
278
+ **Quality gates**: 50-150 lines, no generic advice, no obvious info.
279
+
280
+ ### Subdirectory AGENTS.md (Parallel)
281
+
282
+ Launch general agents for each location in ONE message (parallel execution):
283
+
284
+ ```
285
+ // All in single message = parallel
286
+ Task(
287
+ description="AGENTS.md for src/hooks",
288
+ subagent_type="general",
289
+ prompt="Generate AGENTS.md for: src/hooks
290
+ - Reason: high complexity
291
+ - 30-80 lines max
292
+ - NEVER repeat parent content
293
+ - Sections: OVERVIEW (1 line), STRUCTURE (if >5 subdirs), WHERE TO LOOK, CONVENTIONS (if different), ANTI-PATTERNS
294
+ - Write directly to src/hooks/AGENTS.md"
295
+ )
296
+
297
+ Task(
298
+ description="AGENTS.md for src/api",
299
+ subagent_type="general",
300
+ prompt="Generate AGENTS.md for: src/api
301
+ - Reason: distinct domain
302
+ - 30-80 lines max
303
+ - NEVER repeat parent content
304
+ - Sections: OVERVIEW (1 line), STRUCTURE (if >5 subdirs), WHERE TO LOOK, CONVENTIONS (if different), ANTI-PATTERNS
305
+ - Write directly to src/api/AGENTS.md"
306
+ )
307
+ // ... one Task per AGENTS_LOCATIONS entry
308
+ ```
309
+
310
+ **Results return directly. Mark "generate" as completed.**
311
+
312
+ ---
313
+
314
+ ## Phase 4: Review & Deduplicate
315
+
316
+ **Mark "review" as in_progress.**
317
+
318
+ For each generated file:
319
+ - Remove generic advice
320
+ - Remove parent duplicates
321
+ - Trim to size limits
322
+ - Verify telegraphic style
323
+
324
+ **Mark "review" as completed.**
325
+
326
+ ---
327
+
328
+ ## Final Report
329
+
330
+ ```
331
+ === index-knowledge Complete ===
332
+
333
+ Mode: {update | create-new}
334
+
335
+ Files:
336
+ ✓ ./AGENTS.md (root, {N} lines)
337
+ ✓ ./src/hooks/AGENTS.md ({N} lines)
338
+
339
+ Dirs Analyzed: {N}
340
+ AGENTS.md Created: {N}
341
+ AGENTS.md Updated: {N}
342
+
343
+ Hierarchy:
344
+ ./AGENTS.md
345
+ └── src/hooks/AGENTS.md
346
+ ```
347
+
348
+ ---
349
+
350
+ ## Anti-Patterns
351
+
352
+ - **Static agent count**: MUST vary agents based on project size/depth
353
+ - **Sequential execution**: MUST parallel (multiple Task calls in one message)
354
+ - **Ignoring existing**: ALWAYS read existing first, even with --create-new
355
+ - **Over-documenting**: Not every dir needs AGENTS.md
356
+ - **Redundancy**: Child never repeats parent
357
+ - **Generic content**: Remove anything that applies to ALL projects
358
+ - **Verbose style**: Telegraphic or die
@@ -158,6 +158,6 @@ Save implementations to `.opencode/memory/design/implementations/`
158
158
 
159
159
  | Need | Skill |
160
160
  | ----------------- | --------------------- |
161
- | Aesthetic quality | `frontend-aesthetics` |
161
+ | Aesthetic quality | `frontend-design` |
162
162
  | Accessibility | `accessibility-audit` |
163
163
  | Design tokens | `design-system-audit` |
@@ -0,0 +1,115 @@
1
+ ---
2
+ name: opensrc
3
+ description: Fetch source code for npm, PyPI, or crates.io packages and GitHub/GitLab repos to provide AI agents with implementation context beyond types and docs. Use when needing to understand how a library works internally, debug dependency issues, or explore package implementations.
4
+ ---
5
+
6
+ # opensrc
7
+
8
+ CLI tool to fetch source code for packages/repos, giving AI coding agents deeper implementation context.
9
+
10
+ ## When to Use
11
+
12
+ - Need to understand how a library/package works internally (not just its interface)
13
+ - Debugging issues where types alone are insufficient
14
+ - Exploring implementation patterns in dependencies
15
+ - Agent needs to reference actual source code of a package
16
+
17
+ ## Quick Start
18
+
19
+ ```bash
20
+ # Install globally or use npx
21
+ npm install -g opensrc
22
+
23
+ # Fetch npm package (auto-detects installed version from lockfile)
24
+ npx opensrc zod
25
+
26
+ # Fetch from other registries
27
+ npx opensrc pypi:requests # Python/PyPI
28
+ npx opensrc crates:serde # Rust/crates.io
29
+
30
+ # Fetch GitHub repo directly
31
+ npx opensrc vercel/ai # owner/repo shorthand
32
+ npx opensrc github:owner/repo # explicit prefix
33
+ npx opensrc https://github.com/colinhacks/zod # full URL
34
+
35
+ # Fetch specific version/ref
36
+ npx opensrc zod@3.22.0
37
+ npx opensrc owner/repo@v1.0.0
38
+ ```
39
+
40
+ ## Commands
41
+
42
+ | Command | Description |
43
+ |---------|-------------|
44
+ | `opensrc <packages...>` | Fetch source for packages/repos |
45
+ | `opensrc list` | List all fetched sources |
46
+ | `opensrc remove <name>` | Remove specific source |
47
+ | `opensrc clean` | Remove all sources |
48
+
49
+ ## Output Structure
50
+
51
+ After fetching, sources stored in `opensrc/` directory:
52
+
53
+ ```
54
+ opensrc/
55
+ ├── settings.json # User preferences
56
+ ├── sources.json # Index of fetched packages/repos
57
+ └── repos/
58
+ └── github.com/
59
+ └── owner/
60
+ └── repo/ # Cloned source code
61
+ ```
62
+
63
+ ## File Modifications
64
+
65
+ On first run, opensrc prompts to modify:
66
+ - `.gitignore` - adds `opensrc/` to ignore list
67
+ - `tsconfig.json` - excludes `opensrc/` from compilation
68
+ - `AGENTS.md` - adds section pointing agents to source code
69
+
70
+ Use `--modify` or `--modify=false` to skip prompt.
71
+
72
+ ## Key Behaviors
73
+
74
+ 1. **Version Detection** - For npm, auto-detects installed version from `node_modules`, `package-lock.json`, `pnpm-lock.yaml`, or `yarn.lock`
75
+ 2. **Repository Resolution** - Resolves package to its git repo via registry API, clones at matching tag
76
+ 3. **Monorepo Support** - Handles packages in monorepos via `repository.directory` field
77
+ 4. **Shallow Clone** - Uses `--depth 1` for efficient cloning, removes `.git` after clone
78
+ 5. **Tag Fallback** - Tries `v{version}`, `{version}`, then default branch if tag not found
79
+
80
+ ## Common Workflows
81
+
82
+ ### Fetching a Package
83
+
84
+ ```bash
85
+ # Agent needs to understand zod's implementation
86
+ npx opensrc zod
87
+ # → Detects version from lockfile
88
+ # → Finds repo URL from npm registry
89
+ # → Clones at matching git tag
90
+ # → Source available at opensrc/repos/github.com/colinhacks/zod/
91
+ ```
92
+
93
+ ### Updating Sources
94
+
95
+ ```bash
96
+ # Re-run same command to update to currently installed version
97
+ npx opensrc zod
98
+ # → Checks if version changed
99
+ # → Re-clones if needed
100
+ ```
101
+
102
+ ### Multiple Sources
103
+
104
+ ```bash
105
+ # Fetch multiple at once
106
+ npx opensrc react react-dom next
107
+ npx opensrc zod pypi:pydantic vercel/ai
108
+ ```
109
+
110
+ ## References
111
+
112
+ For detailed information:
113
+ - [CLI Usage & Options](references/cli-usage.md) - Full command reference
114
+ - [Architecture](references/architecture.md) - Code structure and extension
115
+ - [Registry Support](references/registry-support.md) - npm, PyPI, crates.io details
@@ -0,0 +1,176 @@
1
+ # opensrc Architecture
2
+
3
+ ## Contents
4
+ - Directory structure
5
+ - Core flow
6
+ - Key modules
7
+ - Type definitions
8
+ - Extension points
9
+
10
+ ## Directory Structure
11
+
12
+ ```
13
+ src/
14
+ ├── index.ts # CLI entry, Commander setup
15
+ ├── types.ts # Shared type definitions
16
+ ├── commands/
17
+ │ ├── fetch.ts # Main fetch logic
18
+ │ ├── list.ts # List sources
19
+ │ ├── remove.ts # Remove sources
20
+ │ └── clean.ts # Clean all sources
21
+ └── lib/
22
+ ├── git.ts # Clone, path management
23
+ ├── repo.ts # Parse/resolve repo specs
24
+ ├── version.ts # Detect installed versions
25
+ ├── agents.ts # AGENTS.md/sources.json updates
26
+ ├── gitignore.ts # .gitignore management
27
+ ├── tsconfig.ts # tsconfig.json exclude
28
+ ├── settings.ts # User preferences
29
+ ├── prompt.ts # Interactive prompts
30
+ └── registries/
31
+ ├── index.ts # Registry detection/routing
32
+ ├── npm.ts # npm registry API
33
+ ├── pypi.ts # PyPI API
34
+ └── crates.ts # crates.io API
35
+ ```
36
+
37
+ ## Core Flow
38
+
39
+ ### Fetch Package
40
+
41
+ 1. **Parse input** - Detect registry prefix or repo format
42
+ 2. **Version detection** (npm only) - Check lockfiles/node_modules
43
+ 3. **Registry lookup** - Query API for repo URL
44
+ 4. **Clone** - Shallow clone at matching git tag
45
+ 5. **Update index** - Write to sources.json, optionally AGENTS.md
46
+
47
+ ### Input Type Detection
48
+
49
+ ```
50
+ detectInputType(spec) → "package" | "repo"
51
+ ```
52
+
53
+ - Registry prefix (`npm:`, `pypi:`, `crates:`) → package
54
+ - Repo pattern (`owner/repo`, URL, `github:`) → repo
55
+ - Default → package (npm)
56
+
57
+ ## Key Modules
58
+
59
+ ### registries/index.ts
60
+
61
+ Routes to correct registry handler:
62
+
63
+ ```typescript
64
+ parsePackageSpec(spec): PackageSpec
65
+ resolvePackage(spec): ResolvedPackage
66
+ detectRegistry(spec): { registry, cleanSpec }
67
+ detectInputType(spec): "package" | "repo"
68
+ ```
69
+
70
+ ### git.ts
71
+
72
+ Manages cloning and source storage:
73
+
74
+ ```typescript
75
+ fetchSource(resolved, cwd): FetchResult
76
+ fetchRepoSource(resolved, cwd): FetchResult
77
+ listSources(cwd): { packages, repos }
78
+ removePackageSource(name, cwd, registry): { removed, repoRemoved }
79
+ ```
80
+
81
+ Storage structure: `opensrc/repos/{host}/{owner}/{repo}/`
82
+
83
+ ### version.ts
84
+
85
+ Detects installed npm versions (priority order):
86
+ 1. `node_modules/{pkg}/package.json`
87
+ 2. `package-lock.json`
88
+ 3. `pnpm-lock.yaml`
89
+ 4. `yarn.lock`
90
+ 5. `package.json` (strips range prefixes)
91
+
92
+ ### repo.ts
93
+
94
+ Parses repo specs, resolves via GitHub/GitLab API:
95
+
96
+ ```typescript
97
+ parseRepoSpec(spec): RepoSpec | null
98
+ resolveRepo(spec): ResolvedRepo
99
+ isRepoSpec(spec): boolean
100
+ ```
101
+
102
+ Supports: GitHub, GitLab, Bitbucket (GitHub/GitLab via API).
103
+
104
+ ## Type Definitions
105
+
106
+ ```typescript
107
+ type Registry = "npm" | "pypi" | "crates"
108
+
109
+ interface PackageSpec {
110
+ registry: Registry
111
+ name: string
112
+ version?: string
113
+ }
114
+
115
+ interface ResolvedPackage {
116
+ registry: Registry
117
+ name: string
118
+ version: string
119
+ repoUrl: string
120
+ repoDirectory?: string // For monorepos
121
+ gitTag: string
122
+ }
123
+
124
+ interface RepoSpec {
125
+ host: string // github.com, gitlab.com
126
+ owner: string
127
+ repo: string
128
+ ref?: string // Branch, tag, commit
129
+ }
130
+
131
+ interface FetchResult {
132
+ package: string
133
+ version: string
134
+ path: string
135
+ success: boolean
136
+ error?: string
137
+ registry?: Registry
138
+ }
139
+ ```
140
+
141
+ ## Extension Points
142
+
143
+ ### Adding a Registry
144
+
145
+ 1. Create `registries/{name}.ts`:
146
+ - `parse{Name}Spec(spec)` - Parse name@version
147
+ - `resolve{Name}Package(name, version)` - Query API, return ResolvedPackage
148
+
149
+ 2. Update `registries/index.ts`:
150
+ - Add prefix to `REGISTRY_PREFIXES`
151
+ - Add case to `parsePackageSpec` and `resolvePackage`
152
+
153
+ 3. Add to `Registry` type in `types.ts`
154
+
155
+ ### Registry Implementation Pattern
156
+
157
+ ```typescript
158
+ // Parse spec into name/version
159
+ export function parseSpec(spec: string): { name: string; version?: string }
160
+
161
+ // Query registry API, extract repo URL
162
+ async function fetchInfo(name: string): Promise<RegistryResponse>
163
+
164
+ // Normalize git URLs (remove git+, .git suffix)
165
+ function extractRepoUrl(info): string | null
166
+
167
+ // Main resolver
168
+ export async function resolve(name: string, version?: string): Promise<ResolvedPackage>
169
+ ```
170
+
171
+ ### Git Tag Resolution
172
+
173
+ Clone tries tags in order:
174
+ 1. `v{version}` (most common)
175
+ 2. `{version}` (no prefix)
176
+ 3. Default branch (fallback with warning)