opencodekit 0.19.6 → 0.20.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/dist/index.js +1 -1
- package/dist/template/.opencode/dcp-prompts/defaults/compress-message.md +1 -0
- package/dist/template/.opencode/memory.db +0 -0
- package/dist/template/.opencode/memory.db-shm +0 -0
- package/dist/template/.opencode/memory.db-wal +0 -0
- package/dist/template/.opencode/opencode.json +2 -2
- package/dist/template/.opencode/skill/chrome-devtools/SKILL.md +1 -1
- package/dist/template/.opencode/skill/cloudflare/SKILL.md +1 -1
- package/dist/template/.opencode/skill/context-management/SKILL.md +306 -79
- package/dist/template/.opencode/skill/core-data-expert/SKILL.md +1 -1
- package/dist/template/.opencode/skill/design-system-audit/SKILL.md +1 -1
- package/dist/template/.opencode/skill/design-taste-frontend/SKILL.md +1 -1
- package/dist/template/.opencode/skill/figma/SKILL.md +1 -1
- package/dist/template/.opencode/skill/figma-go/SKILL.md +1 -1
- package/dist/template/.opencode/skill/frontend-design/SKILL.md +1 -1
- package/dist/template/.opencode/skill/full-output-enforcement/SKILL.md +1 -1
- package/dist/template/.opencode/skill/high-end-visual-design/SKILL.md +1 -1
- package/dist/template/.opencode/skill/index-knowledge/SKILL.md +1 -1
- package/dist/template/.opencode/skill/industrial-brutalist-ui/SKILL.md +1 -1
- package/dist/template/.opencode/skill/jira/SKILL.md +1 -1
- package/dist/template/.opencode/skill/minimalist-ui/SKILL.md +1 -1
- package/dist/template/.opencode/skill/mqdh/SKILL.md +1 -1
- package/dist/template/.opencode/skill/opensrc/SKILL.md +184 -27
- package/dist/template/.opencode/skill/pdf-extract/SKILL.md +1 -1
- package/dist/template/.opencode/skill/pencil/SKILL.md +1 -1
- package/dist/template/.opencode/skill/playwright/SKILL.md +18 -6
- package/dist/template/.opencode/skill/{agent-browser/SKILL.md → playwright/references/agent-browser-cli.md} +0 -8
- package/dist/template/.opencode/skill/playwriter/SKILL.md +1 -1
- package/dist/template/.opencode/skill/polar/SKILL.md +1 -1
- package/dist/template/.opencode/skill/prd/SKILL.md +1 -1
- package/dist/template/.opencode/skill/react-best-practices/SKILL.md +1 -1
- package/dist/template/.opencode/skill/redesign-existing-projects/SKILL.md +1 -1
- package/dist/template/.opencode/skill/resend/SKILL.md +1 -1
- package/dist/template/.opencode/skill/stitch/SKILL.md +1 -1
- package/dist/template/.opencode/skill/stitch-design-taste/SKILL.md +1 -1
- package/dist/template/.opencode/skill/supabase/SKILL.md +1 -1
- package/dist/template/.opencode/skill/supabase-postgres-best-practices/SKILL.md +1 -1
- package/dist/template/.opencode/skill/v0/SKILL.md +1 -1
- package/dist/template/.opencode/skill/v1-run/SKILL.md +1 -1
- package/dist/template/.opencode/skill/webclaw/SKILL.md +1 -1
- package/dist/template/.opencode/skill/writing-skills/SKILL.md +43 -6
- package/dist/template/.opencode/skill/{testing-skills-with-subagents/SKILL.md → writing-skills/references/testing-methodology.md} +0 -8
- package/package.json +1 -1
- package/dist/template/.opencode/skill/compaction/SKILL.md +0 -384
- package/dist/template/.opencode/skill/session-management/SKILL.md +0 -9
- package/dist/template/.opencode/skill/source-code-research/SKILL.md +0 -293
- package/dist/template/.opencode/skill/ui-ux-research/SKILL.md +0 -9
- package/dist/template/.opencode/skill/using-skills/SKILL.md +0 -117
- /package/dist/template/.opencode/skill/{source-code-research → opensrc}/references/analysis-tips.md +0 -0
- /package/dist/template/.opencode/skill/{source-code-research → opensrc}/references/anti-patterns.md +0 -0
- /package/dist/template/.opencode/skill/{source-code-research → opensrc}/references/common-patterns.md +0 -0
- /package/dist/template/.opencode/skill/{source-code-research → opensrc}/references/example-workflow.md +0 -0
- /package/dist/template/.opencode/skill/{source-code-research → opensrc}/references/further-reading.md +0 -0
- /package/dist/template/.opencode/skill/{source-code-research → opensrc}/references/source-structure.md +0 -0
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: compaction
|
|
3
|
-
description: >
|
|
4
|
-
Use when context is growing large during long-running tasks and needs server-side or client-side
|
|
5
|
-
summarization to continue effectively. Covers compaction triggers, custom summarization patterns,
|
|
6
|
-
session handoff, and context preservation strategies.
|
|
7
|
-
version: 1.0.0
|
|
8
|
-
tags: [context, workflow]
|
|
9
|
-
dependencies: []
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# Context Compaction - Managing Long-Running Sessions
|
|
13
|
-
|
|
14
|
-
## When to Use
|
|
15
|
-
|
|
16
|
-
- Context is growing large and needs compression/cleanup to continue.
|
|
17
|
-
|
|
18
|
-
## When NOT to Use
|
|
19
|
-
|
|
20
|
-
- Short sessions with low context usage where no compaction is needed.
|
|
21
|
-
|
|
22
|
-
## Overview
|
|
23
|
-
|
|
24
|
-
**Compaction = Summarization + Preservation + Continuity**
|
|
25
|
-
|
|
26
|
-
Long-running sessions accumulate context (tool outputs, code reads, exploration results). When context approaches limits, compaction reduces it to essential information while preserving decision history and work state.
|
|
27
|
-
|
|
28
|
-
## Context Budget Awareness
|
|
29
|
-
|
|
30
|
-
### Token Thresholds
|
|
31
|
-
|
|
32
|
-
| Context Usage | Status | Action |
|
|
33
|
-
| ------------- | ----------- | --------------------------------------------- |
|
|
34
|
-
| 0-50% | 🟢 Normal | Work freely |
|
|
35
|
-
| 50-70% | 🟡 Watch | Start compressing completed explorations |
|
|
36
|
-
| 70-85% | 🟠 Compact | Actively compress and sweep stale noise |
|
|
37
|
-
| 85-95% | 🔴 Critical | Emergency compaction, prepare session handoff |
|
|
38
|
-
| 95%+ | ⛔ Limit | Session handoff required |
|
|
39
|
-
|
|
40
|
-
### Monitoring
|
|
41
|
-
|
|
42
|
-
Pay attention to these signals:
|
|
43
|
-
|
|
44
|
-
- Completed phases accumulating without being compressed
|
|
45
|
-
- Repeated file reads of the same content
|
|
46
|
-
- Large bash outputs from builds/tests
|
|
47
|
-
- Multiple exploration rounds without synthesis
|
|
48
|
-
|
|
49
|
-
## Compaction Strategies
|
|
50
|
-
|
|
51
|
-
### Strategy 1: Phase Compression (Preferred)
|
|
52
|
-
|
|
53
|
-
Compress completed conversation phases into dense summaries. This is the primary DCP instrument in the installed beta.
|
|
54
|
-
|
|
55
|
-
Compress completed conversation phases into dense summaries.
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
WHEN: A research phase is complete and findings are clear
|
|
59
|
-
DO: compress({
|
|
60
|
-
topic: "Auth Research Complete",
|
|
61
|
-
content: {
|
|
62
|
-
startString: "unique text at phase start",
|
|
63
|
-
endString: "unique text at phase end",
|
|
64
|
-
summary: "Complete technical summary of findings..."
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
**Key principle**: Only compress CLOSED chapters. Never compress active work.
|
|
70
|
-
|
|
71
|
-
### Strategy 2: Sweep Stale Noise
|
|
72
|
-
|
|
73
|
-
Use `/dcp sweep` after a phase is complete to remove stale/noisy content automatically.
|
|
74
|
-
|
|
75
|
-
```
|
|
76
|
-
WHEN: Wrong-target searches or superseded outputs are no longer needed
|
|
77
|
-
DO: /dcp sweep
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
**Key principle**: Sweep only after the relevant phase is closed. If in doubt, keep it.
|
|
81
|
-
|
|
82
|
-
### Strategy 3: Session Handoff
|
|
83
|
-
|
|
84
|
-
When context is too large to compact further, hand off to a new session.
|
|
85
|
-
|
|
86
|
-
```
|
|
87
|
-
WHEN: Context > 85% and significant work remains
|
|
88
|
-
DO:
|
|
89
|
-
1. Create handoff document with memory-update
|
|
90
|
-
2. Save all decisions with observation tool
|
|
91
|
-
3. Document current state and remaining work
|
|
92
|
-
4. Start new session with handoff reference
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
## Compaction Decision Tree
|
|
96
|
-
|
|
97
|
-
```
|
|
98
|
-
Is context growing large?
|
|
99
|
-
├── NO → Continue working normally
|
|
100
|
-
└── YES → What type of content is consuming space?
|
|
101
|
-
├── Completed conversation phases → COMPRESS
|
|
102
|
-
├── Stale/noisy closed-phase outputs → SWEEP
|
|
103
|
-
└── Everything is still relevant → SESSION HANDOFF
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## Custom Summarization Patterns
|
|
107
|
-
|
|
108
|
-
### For Code Exploration
|
|
109
|
-
|
|
110
|
-
```markdown
|
|
111
|
-
## Exploration Summary: [Component/Module]
|
|
112
|
-
|
|
113
|
-
### Architecture
|
|
114
|
-
|
|
115
|
-
- Entry point: `src/auth/index.ts`
|
|
116
|
-
- Key classes: AuthService, TokenManager, SessionStore
|
|
117
|
-
- Dependencies: jwt, bcrypt, redis
|
|
118
|
-
|
|
119
|
-
### Key Findings
|
|
120
|
-
|
|
121
|
-
- Auth flow: login → validate → issue JWT → store session
|
|
122
|
-
- Token rotation: every 15 minutes via refresh endpoint
|
|
123
|
-
- Session storage: Redis with 24h TTL
|
|
124
|
-
|
|
125
|
-
### Decisions Made
|
|
126
|
-
|
|
127
|
-
- Use existing TokenManager (don't replace)
|
|
128
|
-
- Add rate limiting to login endpoint
|
|
129
|
-
- Migrate session store from memory to Redis
|
|
130
|
-
|
|
131
|
-
### Files to Modify
|
|
132
|
-
|
|
133
|
-
- src/auth/service.ts (add rate limiting)
|
|
134
|
-
- src/auth/session.ts (Redis integration)
|
|
135
|
-
- src/config/redis.ts (new file)
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### For Implementation Phase
|
|
139
|
-
|
|
140
|
-
```markdown
|
|
141
|
-
## Implementation Summary: [Feature]
|
|
142
|
-
|
|
143
|
-
### Completed
|
|
144
|
-
|
|
145
|
-
- [x] Database schema migration (src/db/migrations/004_auth.ts)
|
|
146
|
-
- [x] API endpoints (src/routes/auth.ts) - 3 new routes
|
|
147
|
-
- [x] Frontend forms (src/components/auth/) - Login, Register, Reset
|
|
148
|
-
|
|
149
|
-
### Verification
|
|
150
|
-
|
|
151
|
-
- TypeScript: ✅ passing
|
|
152
|
-
- Tests: ✅ 12/12 passing
|
|
153
|
-
- Lint: ✅ no issues
|
|
154
|
-
|
|
155
|
-
### Remaining
|
|
156
|
-
|
|
157
|
-
- [ ] Email verification flow
|
|
158
|
-
- [ ] Rate limiting middleware
|
|
159
|
-
|
|
160
|
-
### Key Decisions
|
|
161
|
-
|
|
162
|
-
- JWT expiry: 15 minutes (refresh: 7 days)
|
|
163
|
-
- Password hashing: bcrypt with 12 rounds
|
|
164
|
-
- Session storage: Redis (not in-memory)
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
### For Debugging
|
|
168
|
-
|
|
169
|
-
```markdown
|
|
170
|
-
## Debug Summary: [Issue]
|
|
171
|
-
|
|
172
|
-
### Symptoms
|
|
173
|
-
|
|
174
|
-
- Error: "TypeError: Cannot read property 'id' of undefined"
|
|
175
|
-
- Location: src/auth/middleware.ts:42
|
|
176
|
-
- Trigger: POST /api/protected when token is expired
|
|
177
|
-
|
|
178
|
-
### Root Cause
|
|
179
|
-
|
|
180
|
-
- Token validation returns null on expired tokens
|
|
181
|
-
- Middleware assumes valid token object, no null check
|
|
182
|
-
- Race condition: token expires between validation and use
|
|
183
|
-
|
|
184
|
-
### Fix Applied
|
|
185
|
-
|
|
186
|
-
- Added null check in middleware (src/auth/middleware.ts:42)
|
|
187
|
-
- Added token refresh attempt before rejecting (src/auth/refresh.ts)
|
|
188
|
-
- Added test for expired token scenario (src/auth/**tests**/middleware.test.ts)
|
|
189
|
-
|
|
190
|
-
### Verification
|
|
191
|
-
|
|
192
|
-
- Tests: ✅ all passing including new test
|
|
193
|
-
- Manual: ✅ expired token now triggers refresh
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
## Session Handoff Protocol
|
|
197
|
-
|
|
198
|
-
When you must hand off to a new session:
|
|
199
|
-
|
|
200
|
-
### 1. Create Handoff Document
|
|
201
|
-
|
|
202
|
-
```typescript
|
|
203
|
-
memory -
|
|
204
|
-
update({
|
|
205
|
-
file: "handoffs/YYYY-MM-DD-feature-name",
|
|
206
|
-
content: `# Session Handoff: [Feature Name]
|
|
207
|
-
|
|
208
|
-
## Context
|
|
209
|
-
[Why this session started, what was the goal]
|
|
210
|
-
|
|
211
|
-
## Completed Work
|
|
212
|
-
[What was done, files changed, decisions made]
|
|
213
|
-
|
|
214
|
-
## Current State
|
|
215
|
-
[Where things stand right now]
|
|
216
|
-
|
|
217
|
-
## Remaining Work
|
|
218
|
-
[What still needs to be done]
|
|
219
|
-
|
|
220
|
-
## Key Decisions
|
|
221
|
-
[Important choices made and why]
|
|
222
|
-
|
|
223
|
-
## Files Modified
|
|
224
|
-
[List of all files changed with brief description]
|
|
225
|
-
|
|
226
|
-
## Gotchas
|
|
227
|
-
[Things the next session should know]
|
|
228
|
-
`,
|
|
229
|
-
mode: "replace",
|
|
230
|
-
});
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
### 2. Save Key Observations
|
|
234
|
-
|
|
235
|
-
```typescript
|
|
236
|
-
observation({
|
|
237
|
-
type: "decision",
|
|
238
|
-
title: "Auth implementation approach",
|
|
239
|
-
narrative: "Chose JWT with Redis sessions because...",
|
|
240
|
-
facts: "JWT 15min expiry, Redis 24h TTL, bcrypt 12 rounds",
|
|
241
|
-
concepts: "authentication, sessions, tokens",
|
|
242
|
-
confidence: "high",
|
|
243
|
-
});
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
### 3. Resume in New Session
|
|
247
|
-
|
|
248
|
-
```typescript
|
|
249
|
-
// In new session:
|
|
250
|
-
memory - read({ file: "handoffs/YYYY-MM-DD-feature-name" });
|
|
251
|
-
memory - search({ query: "auth implementation" });
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
## Integration with DCP Plugin
|
|
255
|
-
|
|
256
|
-
This project uses `@tarquinen/opencode-dcp` for always-on context management (injected via `experimental.chat.system.transform`):
|
|
257
|
-
|
|
258
|
-
- **compress**: Phase-level conversation compression (primary DCP tool in the installed beta)
|
|
259
|
-
- **/dcp sweep**: Cleanup command for stale/noisy content after a phase is complete
|
|
260
|
-
- **Prunable-tools list**: Auto-injected into messages with token estimates
|
|
261
|
-
- **Nudge system**: Reminders every N tool calls + critical limit warnings
|
|
262
|
-
|
|
263
|
-
**Division of responsibility:**
|
|
264
|
-
|
|
265
|
-
- **DCP plugin**: Context budget rules, tool guidance, prunable-tools list, nudges (always present via system prompt)
|
|
266
|
-
- **Compaction plugin** (`.opencode/plugin/compaction.ts`): Session continuity, beads state, handoff recovery, post-compaction protocol (fires during compaction events only)
|
|
267
|
-
|
|
268
|
-
**Custom prompts (enabled):**
|
|
269
|
-
|
|
270
|
-
DCP custom prompts are enabled (`experimental.customPrompts: true`). Override files live at `.opencode/dcp-prompts/overrides/`:
|
|
271
|
-
|
|
272
|
-
- `compress-message.md` — 9-section structured summary format (Primary Request, Key Technical Concepts, Files/Code, Errors/Fixes, Problem Solving, User Messages, Pending Tasks, Current Work, Next Step)
|
|
273
|
-
|
|
274
|
-
Override precedence: project (`.opencode/dcp-prompts/overrides/`) > config dir > global (`~/.config/opencode/dcp-prompts/overrides/`).
|
|
275
|
-
|
|
276
|
-
## Post-Compaction Restoration Protocol
|
|
277
|
-
|
|
278
|
-
**Critical:** After any compaction (server-side or DCP compress), you lose raw file content and active context. Immediately restore:
|
|
279
|
-
|
|
280
|
-
### Step 1: Re-read Active Files (max 5)
|
|
281
|
-
|
|
282
|
-
Re-read the files you were actively editing before compaction. Prioritize by recency — most recently modified first. Cap at 5 files, use offset/limit to read only the sections you need (~200 lines each).
|
|
283
|
-
|
|
284
|
-
```
|
|
285
|
-
After compaction, if you were editing src/auth.ts:
|
|
286
|
-
read({ filePath: "src/auth.ts", offset: 30, limit: 50 })
|
|
287
|
-
```
|
|
288
|
-
|
|
289
|
-
**Why:** The Write/Edit tool requires a prior Read in the same session (`FileTime.assert()`). Without re-reading, your next edit attempt will fail.
|
|
290
|
-
|
|
291
|
-
### Step 2: Restore Active Skill Context
|
|
292
|
-
|
|
293
|
-
If you were using a skill before compaction, re-load it:
|
|
294
|
-
|
|
295
|
-
```typescript
|
|
296
|
-
skill({ name: "<active-skill>" });
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
Skills are prompt-injected — compaction drops them. Re-load to restore the workflow.
|
|
300
|
-
|
|
301
|
-
### Step 3: Check Todo State
|
|
302
|
-
|
|
303
|
-
Review your TodoWrite list to re-establish task tracking:
|
|
304
|
-
|
|
305
|
-
```
|
|
306
|
-
- What was in_progress?
|
|
307
|
-
- What was pending?
|
|
308
|
-
- What was completed?
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
### Step 4: Verify Git Position
|
|
312
|
-
|
|
313
|
-
```bash
|
|
314
|
-
git branch --show-current
|
|
315
|
-
git status --short
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
Confirms you're on the right branch and shows any uncommitted changes.
|
|
319
|
-
|
|
320
|
-
### Step 5: Scan Memory for Context
|
|
321
|
-
|
|
322
|
-
If the compaction was heavy (>50% reduction), check memory for recent observations:
|
|
323
|
-
|
|
324
|
-
```typescript
|
|
325
|
-
memory - search({ query: "<current task keywords>", limit: 3 });
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
### Why This Protocol Exists
|
|
329
|
-
|
|
330
|
-
Compaction strips raw file content, tool outputs, and skill prompts. Without restoration:
|
|
331
|
-
|
|
332
|
-
- File edits fail (`FileTime.assert` — no prior read)
|
|
333
|
-
- Line-number precision is lost (you're guessing, not citing)
|
|
334
|
-
- Skill workflows are inactive (no prompt injection)
|
|
335
|
-
- Task tracking is disconnected (todos lost in compressed summary)
|
|
336
|
-
|
|
337
|
-
## Anti-Patterns
|
|
338
|
-
|
|
339
|
-
### ❌ Premature Compaction
|
|
340
|
-
|
|
341
|
-
```
|
|
342
|
-
// DON'T compress a file you're about to edit
|
|
343
|
-
compress({ ... }) // Loses exact line numbers you need
|
|
344
|
-
edit({ ... }) // Now you can't find the right location
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
**Fix**: Keep raw content while actively editing. Compress AFTER the edit phase.
|
|
348
|
-
|
|
349
|
-
### ❌ Compressing Active Work
|
|
350
|
-
|
|
351
|
-
```
|
|
352
|
-
// DON'T compress a conversation phase you might return to
|
|
353
|
-
compress({ summary: "Explored auth options" })
|
|
354
|
-
// Later: "Wait, which options did we consider?"
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
**Fix**: Only compress CLOSED chapters where findings are crystallized.
|
|
358
|
-
|
|
359
|
-
### ❌ Ignoring Context Growth
|
|
360
|
-
|
|
361
|
-
```
|
|
362
|
-
// DON'T let context grow unchecked until hitting limits
|
|
363
|
-
// By the time you notice, emergency compaction loses information
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
**Fix**: Monitor regularly. Compress at natural breakpoints and use `/dcp sweep` after closed phases.
|
|
367
|
-
|
|
368
|
-
## Checklist
|
|
369
|
-
|
|
370
|
-
Before compacting:
|
|
371
|
-
|
|
372
|
-
- [ ] Identified what type of content is consuming context
|
|
373
|
-
- [ ] Chosen appropriate strategy (compress/sweep/handoff)
|
|
374
|
-
- [ ] Verified raw content is no longer needed for active work
|
|
375
|
-
- [ ] Captured all key details in the compression summary or handoff
|
|
376
|
-
- [ ] Saved important decisions as observations
|
|
377
|
-
- [ ] Created handoff document if switching sessions
|
|
378
|
-
|
|
379
|
-
During long sessions:
|
|
380
|
-
|
|
381
|
-
- [ ] Compressing completed phases at natural breakpoints
|
|
382
|
-
- [ ] Sweeping stale/noisy outputs after phase completion
|
|
383
|
-
- [ ] Monitoring context usage trends
|
|
384
|
-
- [ ] Planning session handoff if approaching limits
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: "Merged into context-management. Load that skill instead."
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Session Management
|
|
6
|
-
|
|
7
|
-
> This skill has been merged into `context-management` which now covers both context and session lifecycle management.
|
|
8
|
-
>
|
|
9
|
-
> Load `context-management` instead.
|
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: source-code-research
|
|
3
|
-
description: "Use when researching library implementation details beyond API docs. Fetches package source code using opensrc to understand internals, edge cases, and implementation patterns. Complements documentation-based research with actual code inspection."
|
|
4
|
-
version: 1.0.0
|
|
5
|
-
tags: [research, code-quality]
|
|
6
|
-
dependencies: [opensrc]
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# Source Code Research - Deep Library Investigation
|
|
10
|
-
|
|
11
|
-
Fetch and analyze package source code when documentation is insufficient.
|
|
12
|
-
|
|
13
|
-
## When to Use
|
|
14
|
-
|
|
15
|
-
- Documentation gaps — API docs don't explain behavior clearly
|
|
16
|
-
- Edge cases — need to understand how library handles corner cases
|
|
17
|
-
- Implementation details — need to see actual code, not just interfaces
|
|
18
|
-
- Debugging — library behaving unexpectedly, need to trace internals
|
|
19
|
-
- Evaluation — deciding if library fits requirements, need to assess quality
|
|
20
|
-
- Type definitions — TypeScript types exist but implementation unclear
|
|
21
|
-
|
|
22
|
-
## When NOT to Use
|
|
23
|
-
|
|
24
|
-
- Official docs answer your question (check Context7 first)
|
|
25
|
-
- You only need API syntax (codesearch is faster)
|
|
26
|
-
- Library is too large to analyze in session (>50k LOC)
|
|
27
|
-
|
|
28
|
-
## Prerequisites
|
|
29
|
-
|
|
30
|
-
OpenSrc must be available:
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
npx opensrc --help
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
If not installed, it will be fetched via npx automatically.
|
|
37
|
-
|
|
38
|
-
## Workflow
|
|
39
|
-
|
|
40
|
-
### Step 1: Identify What to Fetch
|
|
41
|
-
|
|
42
|
-
Determine the minimal package/repo needed:
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
// If researching a specific npm package
|
|
46
|
-
const target = "zod"; // Just the package name
|
|
47
|
-
|
|
48
|
-
// If researching Python library
|
|
49
|
-
const target = "pypi:requests";
|
|
50
|
-
|
|
51
|
-
// If researching Rust crate
|
|
52
|
-
const target = "crates:serde";
|
|
53
|
-
|
|
54
|
-
// If researching GitHub repo directly
|
|
55
|
-
const target = "vercel/ai"; // or "github:vercel/ai@v3.0.0"
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Step 2: Fetch Source Code
|
|
59
|
-
|
|
60
|
-
Run opensrc to clone the repository:
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
npx opensrc <package>
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
**Examples:**
|
|
67
|
-
|
|
68
|
-
```bash
|
|
69
|
-
npx opensrc zod # Fetch latest zod from npm
|
|
70
|
-
npx opensrc zod@3.22.0 # Fetch specific version
|
|
71
|
-
npx opensrc pypi:requests # Fetch Python package
|
|
72
|
-
npx opensrc vercel/ai # Fetch GitHub repo
|
|
73
|
-
npx opensrc vercel/ai@v3.0.0 # Fetch specific tag
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
**What happens:**
|
|
77
|
-
|
|
78
|
-
- Clones source to `opensrc/repos/<host>/<owner>/<repo>/`
|
|
79
|
-
- Auto-detects version from lockfiles if no version specified
|
|
80
|
-
- Updates `opensrc/sources.json` with metadata
|
|
81
|
-
- Adds `opensrc/` to `.gitignore` automatically (asks once)
|
|
82
|
-
|
|
83
|
-
### Step 3: Locate Relevant Code
|
|
84
|
-
|
|
85
|
-
Use search tools to find code you need:
|
|
86
|
-
|
|
87
|
-
```typescript
|
|
88
|
-
// Find all TypeScript source files
|
|
89
|
-
glob({ pattern: "opensrc/**/src/**/*.ts" });
|
|
90
|
-
|
|
91
|
-
// Search for specific function/class
|
|
92
|
-
grep({
|
|
93
|
-
pattern: "class ValidationError",
|
|
94
|
-
path: "opensrc/",
|
|
95
|
-
include: "*.ts",
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// Search for function pattern
|
|
99
|
-
grep({
|
|
100
|
-
pattern: "export function parse",
|
|
101
|
-
path: "opensrc/",
|
|
102
|
-
include: "*.ts",
|
|
103
|
-
});
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### Step 4: Read and Analyze
|
|
107
|
-
|
|
108
|
-
Read the implementation:
|
|
109
|
-
|
|
110
|
-
```typescript
|
|
111
|
-
// Read the file
|
|
112
|
-
read({ filePath: "opensrc/repos/github.com/colinhacks/zod/src/types.ts" });
|
|
113
|
-
|
|
114
|
-
// Use LSP for navigation (if available)
|
|
115
|
-
lsp_lsp_goto_definition({
|
|
116
|
-
filePath: "opensrc/.../file.ts",
|
|
117
|
-
line: 42,
|
|
118
|
-
character: 10,
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// Find all references
|
|
122
|
-
lsp_lsp_find_references({
|
|
123
|
-
filePath: "opensrc/.../file.ts",
|
|
124
|
-
line: 42,
|
|
125
|
-
character: 10,
|
|
126
|
-
});
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
### Step 5: Document Findings
|
|
130
|
-
|
|
131
|
-
Write research findings to bead artifact:
|
|
132
|
-
|
|
133
|
-
````markdown
|
|
134
|
-
# Research: [Library Name] Implementation
|
|
135
|
-
|
|
136
|
-
**Package:** [name@version]
|
|
137
|
-
**Source:** opensrc/repos/[path]
|
|
138
|
-
**Focus:** [What you were investigating]
|
|
139
|
-
|
|
140
|
-
## Key Findings
|
|
141
|
-
|
|
142
|
-
### [Topic 1]: [Function/Pattern Name]
|
|
143
|
-
|
|
144
|
-
**Location:** `opensrc/repos/.../file.ts:42`
|
|
145
|
-
|
|
146
|
-
**Implementation:**
|
|
147
|
-
|
|
148
|
-
```typescript
|
|
149
|
-
// Paste relevant code snippet
|
|
150
|
-
```
|
|
151
|
-
````
|
|
152
|
-
|
|
153
|
-
**Insights:**
|
|
154
|
-
|
|
155
|
-
- [What you learned]
|
|
156
|
-
- [Edge cases discovered]
|
|
157
|
-
- [Performance implications]
|
|
158
|
-
|
|
159
|
-
**Confidence:** High (direct source code)
|
|
160
|
-
|
|
161
|
-
---
|
|
162
|
-
|
|
163
|
-
### [Topic 2]: [Another Discovery]
|
|
164
|
-
|
|
165
|
-
[Same structure]
|
|
166
|
-
|
|
167
|
-
## Answers to Original Questions
|
|
168
|
-
|
|
169
|
-
1. **Q:** [Original question]
|
|
170
|
-
**A:** [Answer based on source code]
|
|
171
|
-
**Evidence:** `file.ts:123-145`
|
|
172
|
-
|
|
173
|
-
2. **Q:** [Another question]
|
|
174
|
-
**A:** [Answer]
|
|
175
|
-
|
|
176
|
-
## Recommendations
|
|
177
|
-
|
|
178
|
-
Based on source analysis:
|
|
179
|
-
|
|
180
|
-
- [Recommendation 1]
|
|
181
|
-
- [Recommendation 2]
|
|
182
|
-
|
|
183
|
-
## Caveats
|
|
184
|
-
|
|
185
|
-
- Version analyzed: [version]
|
|
186
|
-
- Code may have changed in newer versions
|
|
187
|
-
- Private APIs discovered may change without notice
|
|
188
|
-
|
|
189
|
-
````
|
|
190
|
-
|
|
191
|
-
## Limitations
|
|
192
|
-
|
|
193
|
-
### When Source Code Won't Help
|
|
194
|
-
|
|
195
|
-
- **Build-time transforms**: Source may differ from runtime (Babel, webpack)
|
|
196
|
-
- **Native modules**: C/C++ code requires different analysis
|
|
197
|
-
- **Minified code**: Some packages don't publish source
|
|
198
|
-
- **Monorepos**: May need to navigate complex structure
|
|
199
|
-
|
|
200
|
-
### Alternatives
|
|
201
|
-
|
|
202
|
-
If opensrc doesn't work:
|
|
203
|
-
|
|
204
|
-
1. **GitHub web interface**: Browse online at github.com/owner/repo
|
|
205
|
-
2. **npm unpacked**: `npm pack <package>` then extract
|
|
206
|
-
3. **node_modules**: If already installed, check `node_modules/<package>/`
|
|
207
|
-
4. **Source maps**: If debugging, browser DevTools may show original source
|
|
208
|
-
|
|
209
|
-
## Integration with Other Research Methods
|
|
210
|
-
|
|
211
|
-
Source code research complements other tools:
|
|
212
|
-
|
|
213
|
-
| Method | Best For | Source Code Adds |
|
|
214
|
-
| -------------- | -------------------------- | ------------------------------ |
|
|
215
|
-
| **Context7** | API docs, official guides | Implementation details |
|
|
216
|
-
| **codesearch** | Usage patterns in the wild | Canonical implementation |
|
|
217
|
-
| **grepsearch** | Real-world examples | How library itself works |
|
|
218
|
-
| **Web search** | Tutorials, blog posts | Ground truth from source |
|
|
219
|
-
| **Codebase** | Project-specific patterns | How dependencies actually work |
|
|
220
|
-
|
|
221
|
-
**Recommended flow:**
|
|
222
|
-
|
|
223
|
-
1. Context7 - Check official docs
|
|
224
|
-
2. Codebase - Check existing usage
|
|
225
|
-
3. **Source code** - If still unclear, fetch source
|
|
226
|
-
4. codesearch/grepsearch - See how others use it
|
|
227
|
-
5. Web search - Last resort for context
|
|
228
|
-
|
|
229
|
-
## Cleanup
|
|
230
|
-
|
|
231
|
-
After research is complete:
|
|
232
|
-
|
|
233
|
-
```bash
|
|
234
|
-
# Remove specific package
|
|
235
|
-
npx opensrc remove <package>
|
|
236
|
-
|
|
237
|
-
# Remove all sources
|
|
238
|
-
npx opensrc clean
|
|
239
|
-
|
|
240
|
-
# Remove just npm packages
|
|
241
|
-
npx opensrc clean --npm
|
|
242
|
-
|
|
243
|
-
# Keep sources for documentation
|
|
244
|
-
# (opensrc/ is gitignored, won't be committed)
|
|
245
|
-
```
|
|
246
|
-
|
|
247
|
-
## Success Criteria
|
|
248
|
-
|
|
249
|
-
You've successfully used this skill when:
|
|
250
|
-
|
|
251
|
-
- [ ] Fetched correct package/version source
|
|
252
|
-
- [ ] Located relevant implementation code
|
|
253
|
-
- [ ] Understood behavior from reading source
|
|
254
|
-
- [ ] Documented findings with file:line references
|
|
255
|
-
- [ ] Answered original research question with high confidence
|
|
256
|
-
- [ ] Provided code evidence for claims
|
|
257
|
-
|
|
258
|
-
## Quick Reference
|
|
259
|
-
|
|
260
|
-
```bash
|
|
261
|
-
# Fetch package source
|
|
262
|
-
npx opensrc <package> # npm (auto-detect version)
|
|
263
|
-
npx opensrc <package>@<version> # npm (specific version)
|
|
264
|
-
npx opensrc pypi:<package> # Python
|
|
265
|
-
npx opensrc crates:<package> # Rust
|
|
266
|
-
npx opensrc <owner>/<repo> # GitHub
|
|
267
|
-
npx opensrc <owner>/<repo>@<tag> # GitHub (specific tag)
|
|
268
|
-
|
|
269
|
-
# List fetched sources
|
|
270
|
-
npx opensrc list
|
|
271
|
-
npx opensrc list --json
|
|
272
|
-
|
|
273
|
-
# Remove sources
|
|
274
|
-
npx opensrc remove <package>
|
|
275
|
-
npx opensrc clean
|
|
276
|
-
npx opensrc clean --npm --pypi --crates
|
|
277
|
-
|
|
278
|
-
# Source location
|
|
279
|
-
opensrc/repos/<host>/<owner>/<repo>/
|
|
280
|
-
|
|
281
|
-
# Metadata
|
|
282
|
-
opensrc/sources.json
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
## References
|
|
286
|
-
|
|
287
|
-
- `references/common-patterns.md` - Error handling, tracing behavior, quality evaluation patterns
|
|
288
|
-
- `references/source-structure.md` - npm/PyPI/Rust source layouts
|
|
289
|
-
- `references/analysis-tips.md` - Tests, examples, changelog, types, blame
|
|
290
|
-
- `references/example-workflow.md` - Full zod async refinement workflow
|
|
291
|
-
- `references/anti-patterns.md` - What not to do when researching
|
|
292
|
-
- `references/further-reading.md` - External links
|
|
293
|
-
````
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
description: "Merged into design-system-audit. Load that skill instead."
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# UI/UX Research
|
|
6
|
-
|
|
7
|
-
> This skill has been merged into `design-system-audit` which now covers UI pattern analysis, design token auditing, and visual comparison.
|
|
8
|
-
>
|
|
9
|
-
> Load `design-system-audit` instead.
|