codeforge-dev 1.4.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/.devcontainer/.env +22 -0
- package/.devcontainer/CHANGELOG.md +197 -0
- package/.devcontainer/CLAUDE.md +117 -0
- package/.devcontainer/README.md +222 -0
- package/.devcontainer/config/main-system-prompt.md +502 -0
- package/.devcontainer/config/settings.json +47 -0
- package/.devcontainer/devcontainer.json +94 -0
- package/.devcontainer/features/README.md +113 -0
- package/.devcontainer/features/agent-browser/README.md +65 -0
- package/.devcontainer/features/agent-browser/devcontainer-feature.json +23 -0
- package/.devcontainer/features/agent-browser/install.sh +79 -0
- package/.devcontainer/features/ast-grep/README.md +24 -0
- package/.devcontainer/features/ast-grep/devcontainer-feature.json +24 -0
- package/.devcontainer/features/ast-grep/install.sh +51 -0
- package/.devcontainer/features/ccstatusline/README.md +296 -0
- package/.devcontainer/features/ccstatusline/devcontainer-feature.json +19 -0
- package/.devcontainer/features/ccstatusline/install.sh +290 -0
- package/.devcontainer/features/ccusage/README.md +205 -0
- package/.devcontainer/features/ccusage/devcontainer-feature.json +38 -0
- package/.devcontainer/features/ccusage/install.sh +132 -0
- package/.devcontainer/features/claude-code/README.md +498 -0
- package/.devcontainer/features/claude-code/config/settings.json +36 -0
- package/.devcontainer/features/claude-code/config/system-prompt.md +118 -0
- package/.devcontainer/features/claude-code/config/world-building-sp.md +1432 -0
- package/.devcontainer/features/claude-code/devcontainer-feature.json +42 -0
- package/.devcontainer/features/claude-code/install.sh +466 -0
- package/.devcontainer/features/claude-monitor/README.md +74 -0
- package/.devcontainer/features/claude-monitor/devcontainer-feature.json +38 -0
- package/.devcontainer/features/claude-monitor/install.sh +99 -0
- package/.devcontainer/features/lsp-servers/README.md +85 -0
- package/.devcontainer/features/lsp-servers/devcontainer-feature.json +40 -0
- package/.devcontainer/features/lsp-servers/install.sh +116 -0
- package/.devcontainer/features/mcp-qdrant/CHANGES.md +399 -0
- package/.devcontainer/features/mcp-qdrant/README.md +474 -0
- package/.devcontainer/features/mcp-qdrant/devcontainer-feature.json +57 -0
- package/.devcontainer/features/mcp-qdrant/install.sh +295 -0
- package/.devcontainer/features/mcp-qdrant/poststart-hook.sh +129 -0
- package/.devcontainer/features/mcp-reasoner/README.md +177 -0
- package/.devcontainer/features/mcp-reasoner/devcontainer-feature.json +20 -0
- package/.devcontainer/features/mcp-reasoner/install.sh +177 -0
- package/.devcontainer/features/mcp-reasoner/poststart-hook.sh +67 -0
- package/.devcontainer/features/notify-hook/README.md +86 -0
- package/.devcontainer/features/notify-hook/devcontainer-feature.json +23 -0
- package/.devcontainer/features/notify-hook/install.sh +38 -0
- package/.devcontainer/features/splitrail/README.md +140 -0
- package/.devcontainer/features/splitrail/devcontainer-feature.json +34 -0
- package/.devcontainer/features/splitrail/install.sh +129 -0
- package/.devcontainer/features/tree-sitter/README.md +138 -0
- package/.devcontainer/features/tree-sitter/devcontainer-feature.json +52 -0
- package/.devcontainer/features/tree-sitter/install.sh +173 -0
- package/.devcontainer/plugins/devs-marketplace/.claude-plugin/marketplace.json +106 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/auto-formatter/.claude-plugin/plugin.json +7 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/auto-formatter/hooks/hooks.json +17 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/auto-formatter/scripts/format-file.py +101 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/auto-linter/.claude-plugin/plugin.json +7 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/auto-linter/hooks/hooks.json +17 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/auto-linter/scripts/lint-file.py +137 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/.claude-plugin/plugin.json +8 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/claude-code-headless/SKILL.md +387 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/claude-code-headless/references/cli-flags-and-output.md +312 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/claude-code-headless/references/sdk-and-mcp.md +569 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/docker/SKILL.md +309 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/docker/references/compose-services.md +438 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/docker/references/dockerfile-patterns.md +340 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/docker-py/SKILL.md +412 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/docker-py/references/container-lifecycle.md +388 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/docker-py/references/resources-and-security.md +444 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/fastapi/SKILL.md +344 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/fastapi/references/middleware-and-lifespan.md +254 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/fastapi/references/pydantic-models.md +245 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/fastapi/references/routing-and-dependencies.md +255 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/fastapi/references/sse-and-streaming.md +318 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/pydantic-ai/SKILL.md +345 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/pydantic-ai/references/agents-and-tools.md +271 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/pydantic-ai/references/models-and-streaming.md +422 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/skill-building/SKILL.md +220 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/skill-building/references/cross-vendor-principles.md +139 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/skill-building/references/patterns-and-antipatterns.md +376 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/skill-building/references/skill-authoring-patterns.md +356 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/sqlite/SKILL.md +329 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/sqlite/references/advanced-queries.md +314 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/sqlite/references/javascript-patterns.md +323 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/sqlite/references/python-patterns.md +354 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/sqlite/references/schema-and-pragmas.md +326 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/SKILL.md +356 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/ai-sdk-svelte.md +128 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/component-patterns.md +332 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/layercake.md +203 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/migration-guide.md +350 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/runes-and-reactivity.md +328 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/spa-and-routing.md +262 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/svelte5/references/svelte-dnd-action.md +181 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/testing/SKILL.md +414 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/testing/references/fastapi-testing.md +411 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/testing/references/svelte-testing.md +538 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/codeforge-lsp/.claude-plugin/plugin.json +7 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/dangerous-command-blocker/.claude-plugin/plugin.json +7 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/dangerous-command-blocker/hooks/hooks.json +17 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/dangerous-command-blocker/scripts/block-dangerous.py +110 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/notify-hook/.claude-plugin/plugin.json +7 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/notify-hook/hooks/hooks.json +17 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/planning-reminder/.claude-plugin/plugin.json +7 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/planning-reminder/hooks/hooks.json +17 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/protected-files-guard/.claude-plugin/plugin.json +7 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/protected-files-guard/hooks/hooks.json +17 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/protected-files-guard/scripts/guard-protected.py +108 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/ticket-workflow/.claude-plugin/commands/ticket/357/200/272create-pr.md +337 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/ticket-workflow/.claude-plugin/commands/ticket/357/200/272new.md +166 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/ticket-workflow/.claude-plugin/commands/ticket/357/200/272review-commit.md +290 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/ticket-workflow/.claude-plugin/commands/ticket/357/200/272work.md +257 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/ticket-workflow/.claude-plugin/plugin.json +8 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/ticket-workflow/.claude-plugin/system-prompt.md +184 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/.claude-plugin/plugin.json +6 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/config/planning-instructions.md +14 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/functional-conjuring-map.md +989 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/hooks/hooks.json +33 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/__pycache__/post-enhance-task.cpython-314.pyc +0 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/enhance-planning.py +71 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/enhancers/enhance-plan.sh +68 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/enhancers/enhance-task.sh +120 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/post-enhance-plan.py +133 -0
- package/.devcontainer/plugins/devs-marketplace/plugins/workflow-enhancer/scripts/post-enhance-task.py +253 -0
- package/.devcontainer/scripts/setup-aliases.sh +80 -0
- package/.devcontainer/scripts/setup-config.sh +28 -0
- package/.devcontainer/scripts/setup-irie-claude.sh +32 -0
- package/.devcontainer/scripts/setup-plugins.sh +80 -0
- package/.devcontainer/scripts/setup.sh +58 -0
- package/LICENSE.txt +674 -0
- package/README.md +267 -0
- package/package.json +44 -0
- package/setup.js +83 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
# Skill Authoring Patterns
|
|
2
|
+
|
|
3
|
+
This reference describes five skill authoring patterns, ordered by complexity. Select the pattern that matches the skill's requirements. Simpler patterns are preferred when they suffice -- complexity should be justified by the task.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Pattern 1: Instruction-Only
|
|
8
|
+
|
|
9
|
+
### When to Use
|
|
10
|
+
The skill provides knowledge and guidelines without requiring external files, scripts, or templates. Pure procedural knowledge that changes model behavior through instructions alone.
|
|
11
|
+
|
|
12
|
+
### Characteristics
|
|
13
|
+
- SKILL.md only -- no references/, scripts/, or assets/
|
|
14
|
+
- Typically 800-1,500 words
|
|
15
|
+
- Knowledge the model does not possess by default
|
|
16
|
+
- No deterministic operations required
|
|
17
|
+
|
|
18
|
+
### Structure
|
|
19
|
+
```
|
|
20
|
+
skill-name/
|
|
21
|
+
└── SKILL.md
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Example: Code Review Standards
|
|
25
|
+
|
|
26
|
+
```yaml
|
|
27
|
+
---
|
|
28
|
+
name: Code Review Standards
|
|
29
|
+
description: >-
|
|
30
|
+
This skill should be used when the user asks to "review code",
|
|
31
|
+
"check this PR", "audit code quality", or discusses code review
|
|
32
|
+
criteria, review comments, or approval standards.
|
|
33
|
+
version: 0.1.0
|
|
34
|
+
---
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```markdown
|
|
38
|
+
# Code Review Standards
|
|
39
|
+
|
|
40
|
+
This skill establishes code review criteria for consistent, actionable feedback.
|
|
41
|
+
|
|
42
|
+
## Review Priorities (ordered)
|
|
43
|
+
|
|
44
|
+
1. **Correctness** -- Does the code do what it claims?
|
|
45
|
+
2. **Security** -- Are there injection, auth, or data exposure risks?
|
|
46
|
+
3. **Maintainability** -- Can another developer understand and modify this?
|
|
47
|
+
4. **Performance** -- Are there obvious inefficiencies? (Do not micro-optimize.)
|
|
48
|
+
|
|
49
|
+
## Comment Format
|
|
50
|
+
|
|
51
|
+
Structure every review comment as:
|
|
52
|
+
|
|
53
|
+
**[Category] File:Line -- Observation**
|
|
54
|
+
> Suggestion with rationale.
|
|
55
|
+
|
|
56
|
+
Example:
|
|
57
|
+
**[Security] auth.py:42 -- User input passed directly to SQL query**
|
|
58
|
+
> Use parameterized queries to prevent SQL injection. The `execute()`
|
|
59
|
+
> method accepts parameters as a second argument.
|
|
60
|
+
|
|
61
|
+
## Approval Criteria
|
|
62
|
+
|
|
63
|
+
Approve when:
|
|
64
|
+
- No correctness or security issues remain
|
|
65
|
+
- All maintainability concerns are either addressed or acknowledged with justification
|
|
66
|
+
- Performance concerns are documented for follow-up if not blocking
|
|
67
|
+
|
|
68
|
+
Request changes when:
|
|
69
|
+
- Any correctness bug exists
|
|
70
|
+
- Any security vulnerability exists
|
|
71
|
+
- Code is not understandable without the author explaining it verbally
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Guidance
|
|
75
|
+
- Keep it lean. If the body exceeds 1,500 words, consider whether a reference file is warranted, which would promote the skill to Pattern 2.
|
|
76
|
+
- Focus on knowledge the model lacks, not general best practices it already follows.
|
|
77
|
+
- Instruction-Only skills are the easiest to maintain. Prefer this pattern unless the skill genuinely needs external resources.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Pattern 2: Asset Utilization
|
|
82
|
+
|
|
83
|
+
### When to Use
|
|
84
|
+
The skill requires reference material, documentation, or templates that are too large for the SKILL.md body, or that change independently from the core instructions.
|
|
85
|
+
|
|
86
|
+
### Characteristics
|
|
87
|
+
- SKILL.md + references/ and/or assets/
|
|
88
|
+
- SKILL.md stays lean (1,500-2,000 words), detail lives in references/
|
|
89
|
+
- Reference material loaded on demand, not on every activation
|
|
90
|
+
- Assets used in output but not loaded into context
|
|
91
|
+
|
|
92
|
+
### Structure
|
|
93
|
+
```
|
|
94
|
+
skill-name/
|
|
95
|
+
├── SKILL.md
|
|
96
|
+
├── references/
|
|
97
|
+
│ ├── api-schema.md
|
|
98
|
+
│ └── domain-glossary.md
|
|
99
|
+
└── assets/
|
|
100
|
+
└── template/
|
|
101
|
+
├── index.html
|
|
102
|
+
└── styles.css
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Example: API Integration Skill
|
|
106
|
+
|
|
107
|
+
**SKILL.md** contains core workflow (authenticate, construct request, handle response) and a table pointing to reference files:
|
|
108
|
+
|
|
109
|
+
```markdown
|
|
110
|
+
## API Reference
|
|
111
|
+
|
|
112
|
+
| Endpoint Group | Reference File | Search Pattern |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| User management | `references/api-users.md` | "POST /users" |
|
|
115
|
+
| Billing | `references/api-billing.md` | "GET /invoices" |
|
|
116
|
+
| Webhooks | `references/api-webhooks.md` | "Event: payment." |
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Guidance
|
|
120
|
+
- Include search patterns for large reference files (>5,000 words) so the model can grep for specific sections.
|
|
121
|
+
- Avoid duplicating reference content in SKILL.md. Summarize and point.
|
|
122
|
+
- Assets are not loaded into context -- they are copied or modified during output generation. Include a manifest or description of assets in SKILL.md so the model knows what is available.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Pattern 3: Few-Shot
|
|
127
|
+
|
|
128
|
+
### When to Use
|
|
129
|
+
The output format, style, or structure is critical and cannot be reliably specified through rules alone. The model needs to see concrete input-output examples to calibrate.
|
|
130
|
+
|
|
131
|
+
### Characteristics
|
|
132
|
+
- SKILL.md contains 2-5 high-quality input-output examples
|
|
133
|
+
- Examples demonstrate the full range of expected behaviors
|
|
134
|
+
- Each example illustrates a distinct aspect (not redundant variations)
|
|
135
|
+
- May combine with other patterns (e.g., Few-Shot + Asset Utilization)
|
|
136
|
+
|
|
137
|
+
### Structure
|
|
138
|
+
```
|
|
139
|
+
skill-name/
|
|
140
|
+
├── SKILL.md # Contains inline examples
|
|
141
|
+
└── references/
|
|
142
|
+
└── examples.md # Additional examples if needed
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Example: Changelog Generator
|
|
146
|
+
|
|
147
|
+
````markdown
|
|
148
|
+
## Examples
|
|
149
|
+
|
|
150
|
+
### Example 1: Feature Addition
|
|
151
|
+
|
|
152
|
+
**Input (commit log):**
|
|
153
|
+
```
|
|
154
|
+
feat(auth): add OAuth2 PKCE flow for mobile clients
|
|
155
|
+
feat(auth): add refresh token rotation
|
|
156
|
+
fix(auth): handle expired tokens during active session
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Output (changelog entry):**
|
|
160
|
+
```markdown
|
|
161
|
+
### Authentication
|
|
162
|
+
- **Added** OAuth2 PKCE flow for mobile clients, enabling secure
|
|
163
|
+
authentication without client secrets
|
|
164
|
+
- **Added** Refresh token rotation to prevent token replay attacks
|
|
165
|
+
- **Fixed** Expired token handling during active sessions -- users
|
|
166
|
+
are now seamlessly re-authenticated instead of logged out
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Example 2: Breaking Change
|
|
170
|
+
|
|
171
|
+
**Input (commit log):**
|
|
172
|
+
```
|
|
173
|
+
feat(api)!: change response envelope from {data} to {result, meta}
|
|
174
|
+
migration(api): add v1-to-v2 response adapter
|
|
175
|
+
docs(api): update API migration guide
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Output (changelog entry):**
|
|
179
|
+
```markdown
|
|
180
|
+
### API (Breaking)
|
|
181
|
+
- **Changed** Response envelope from `{data}` to `{result, meta}`.
|
|
182
|
+
See migration guide for adapter utilities.
|
|
183
|
+
**Migration:** Use `v1-to-v2` adapter for backward compatibility.
|
|
184
|
+
```
|
|
185
|
+
````
|
|
186
|
+
|
|
187
|
+
### Guidance
|
|
188
|
+
- Each example should teach something the others do not. Example 1 shows standard features; Example 2 shows breaking changes. Redundant examples waste tokens.
|
|
189
|
+
- Place the 2-3 most important examples in SKILL.md. Move additional examples to `references/examples.md` if more are needed.
|
|
190
|
+
- Include edge cases in examples: empty inputs, ambiguous inputs, error cases.
|
|
191
|
+
- Few-shot is the most reliable way to enforce output format. Rules like "use bold for action verbs" are less reliably followed than examples that demonstrate the format.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Pattern 4: Procedural Logic
|
|
196
|
+
|
|
197
|
+
### When to Use
|
|
198
|
+
The skill involves a multi-step deterministic workflow where steps must execute in order and some steps benefit from being implemented as scripts rather than generated each time.
|
|
199
|
+
|
|
200
|
+
### Characteristics
|
|
201
|
+
- SKILL.md defines the workflow and step ordering
|
|
202
|
+
- scripts/ contains deterministic steps
|
|
203
|
+
- The model orchestrates: deciding when to invoke scripts and handling branching logic
|
|
204
|
+
- References may supplement with documentation
|
|
205
|
+
|
|
206
|
+
### Structure
|
|
207
|
+
```
|
|
208
|
+
skill-name/
|
|
209
|
+
├── SKILL.md
|
|
210
|
+
├── scripts/
|
|
211
|
+
│ ├── validate-input.sh
|
|
212
|
+
│ ├── transform-data.py
|
|
213
|
+
│ └── generate-report.py
|
|
214
|
+
├── references/
|
|
215
|
+
│ └── format-specification.md
|
|
216
|
+
└── assets/
|
|
217
|
+
└── report-template.html
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Example: Data Pipeline Skill
|
|
221
|
+
|
|
222
|
+
**SKILL.md** defines the workflow:
|
|
223
|
+
|
|
224
|
+
```markdown
|
|
225
|
+
## Workflow
|
|
226
|
+
|
|
227
|
+
Execute these steps in order:
|
|
228
|
+
|
|
229
|
+
1. **Validate Input**
|
|
230
|
+
Run `scripts/validate-input.sh <file>` to verify format and schema.
|
|
231
|
+
If validation fails, report errors to the user and stop.
|
|
232
|
+
|
|
233
|
+
2. **Transform Data**
|
|
234
|
+
Run `scripts/transform-data.py --input <file> --output <temp>`.
|
|
235
|
+
The script normalizes date formats, deduplicates records, and
|
|
236
|
+
applies business rules defined in `references/format-specification.md`.
|
|
237
|
+
|
|
238
|
+
3. **Review Transformation**
|
|
239
|
+
Read the transformation summary from stdout. Present key statistics
|
|
240
|
+
to the user: records processed, duplicates removed, format corrections.
|
|
241
|
+
Await confirmation before proceeding.
|
|
242
|
+
|
|
243
|
+
4. **Generate Report**
|
|
244
|
+
Run `scripts/generate-report.py --data <temp> --template assets/report-template.html`.
|
|
245
|
+
Output the report path to the user.
|
|
246
|
+
|
|
247
|
+
## Error Recovery
|
|
248
|
+
|
|
249
|
+
- **Validation failure:** Present the specific validation errors. Suggest corrections. Offer to auto-fix common issues (date formats, encoding).
|
|
250
|
+
- **Transformation failure:** Read the error log. Diagnose whether the issue is data quality or script bug. For data quality issues, present options to the user.
|
|
251
|
+
- **Report failure:** Fall back to plain-text summary if template rendering fails.
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Guidance
|
|
255
|
+
- Scripts should be self-contained and testable independently. Each script handles one step.
|
|
256
|
+
- The model's role is orchestration: deciding branching, handling errors, presenting results. Keep deterministic logic in scripts.
|
|
257
|
+
- Document each script's inputs, outputs, and exit codes in SKILL.md so the model can invoke them correctly.
|
|
258
|
+
- Include error recovery for each step. Multi-step workflows fail at steps, and the model needs to know how to recover.
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Pattern 5: Complex Orchestration
|
|
263
|
+
|
|
264
|
+
### When to Use
|
|
265
|
+
The skill coordinates multiple tools, external services, or sub-workflows with conditional branching, parallel execution, or state management across steps.
|
|
266
|
+
|
|
267
|
+
### Characteristics
|
|
268
|
+
- Multiple scripts and reference files working together
|
|
269
|
+
- Conditional branching based on intermediate results
|
|
270
|
+
- May involve external tool calls (APIs, databases, file systems)
|
|
271
|
+
- State management across steps
|
|
272
|
+
- Comprehensive error handling and rollback
|
|
273
|
+
|
|
274
|
+
### Structure
|
|
275
|
+
```
|
|
276
|
+
skill-name/
|
|
277
|
+
├── SKILL.md
|
|
278
|
+
├── scripts/
|
|
279
|
+
│ ├── discover-environment.sh
|
|
280
|
+
│ ├── run-analysis.py
|
|
281
|
+
│ ├── apply-changes.py
|
|
282
|
+
│ └── verify-results.sh
|
|
283
|
+
├── references/
|
|
284
|
+
│ ├── architecture.md
|
|
285
|
+
│ ├── rollback-procedures.md
|
|
286
|
+
│ └── environment-matrix.md
|
|
287
|
+
└── assets/
|
|
288
|
+
└── config-templates/
|
|
289
|
+
├── production.yaml
|
|
290
|
+
└── staging.yaml
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Example: Deployment Skill
|
|
294
|
+
|
|
295
|
+
**SKILL.md** defines the orchestration:
|
|
296
|
+
|
|
297
|
+
```markdown
|
|
298
|
+
## Deployment Workflow
|
|
299
|
+
|
|
300
|
+
### Phase 1: Environment Discovery
|
|
301
|
+
Run `scripts/discover-environment.sh` to detect:
|
|
302
|
+
- Current branch and latest commit
|
|
303
|
+
- Target environment (from user input or branch convention)
|
|
304
|
+
- Required configuration (from `references/environment-matrix.md`)
|
|
305
|
+
|
|
306
|
+
### Phase 2: Pre-flight Checks
|
|
307
|
+
Execute in sequence:
|
|
308
|
+
1. Verify all tests pass in CI (check GitHub Actions status)
|
|
309
|
+
2. Run `scripts/run-analysis.py --type security` for vulnerability scan
|
|
310
|
+
3. Run `scripts/run-analysis.py --type compatibility` for breaking change detection
|
|
311
|
+
|
|
312
|
+
**Branch on results:**
|
|
313
|
+
- All checks pass: proceed to Phase 3
|
|
314
|
+
- Security issues found: present findings, await user decision (fix/accept/abort)
|
|
315
|
+
- Breaking changes detected: present migration requirements, await approval
|
|
316
|
+
|
|
317
|
+
### Phase 3: Deployment
|
|
318
|
+
1. Select configuration template from `assets/config-templates/`
|
|
319
|
+
2. Run `scripts/apply-changes.py --env <target> --config <template>`
|
|
320
|
+
3. Monitor deployment output for errors
|
|
321
|
+
|
|
322
|
+
### Phase 4: Verification
|
|
323
|
+
1. Run `scripts/verify-results.sh --env <target>`
|
|
324
|
+
2. Present health check results
|
|
325
|
+
3. If verification fails, consult `references/rollback-procedures.md` and present rollback options
|
|
326
|
+
|
|
327
|
+
## State Management
|
|
328
|
+
Track deployment state across phases. If interrupted:
|
|
329
|
+
- Phase 1-2: Safe to restart from beginning
|
|
330
|
+
- Phase 3: Check partial deployment state before retrying
|
|
331
|
+
- Phase 4: Do not re-deploy; verify current state first
|
|
332
|
+
|
|
333
|
+
## Rollback Policy
|
|
334
|
+
Consult `references/rollback-procedures.md` for environment-specific rollback procedures. Present the rollback plan to the user before executing.
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Guidance
|
|
338
|
+
- Complex Orchestration skills are the hardest to maintain. Use this pattern only when the workflow genuinely requires it. Many workflows that seem complex can be decomposed into multiple simpler skills.
|
|
339
|
+
- Define state management explicitly. The model needs to know what happens when the workflow is interrupted at each phase.
|
|
340
|
+
- Include rollback procedures for destructive operations.
|
|
341
|
+
- Test the full workflow end-to-end, not just individual scripts.
|
|
342
|
+
- Consider whether the skill should be split into multiple skills (one per phase) that compose together. Composition often produces better results than monolithic orchestration.
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## Pattern Selection Guide
|
|
347
|
+
|
|
348
|
+
| Question | If Yes | If No |
|
|
349
|
+
|---|---|---|
|
|
350
|
+
| Does the skill need external files? | Pattern 2+ | Pattern 1 |
|
|
351
|
+
| Is output format critical? | Pattern 3 | Continue |
|
|
352
|
+
| Are there multi-step deterministic operations? | Pattern 4 | Continue |
|
|
353
|
+
| Are there conditional branches or state management? | Pattern 5 | Continue |
|
|
354
|
+
| Is the scope well-defined and narrow? | Selected pattern is appropriate | Split into multiple skills |
|
|
355
|
+
|
|
356
|
+
**Default to the simplest pattern that covers the requirements.** Escalate only when a simpler pattern demonstrably fails to capture the skill's needs.
|
package/.devcontainer/plugins/devs-marketplace/plugins/codedirective-skills/skills/sqlite/SKILL.md
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sqlite
|
|
3
|
+
description: >-
|
|
4
|
+
This skill should be used when the user asks to "set up a SQLite database",
|
|
5
|
+
"use WAL mode in SQLite", "query SQLite with Python", "use better-sqlite3",
|
|
6
|
+
"add full-text search with FTS5", "store JSON in SQLite",
|
|
7
|
+
"use SQLite with Cloudflare D1", "write CTEs or window functions in SQLite",
|
|
8
|
+
or discusses SQLite pragmas, schema design, JSON1 extension, FTS5,
|
|
9
|
+
aiosqlite, or embedded database patterns.
|
|
10
|
+
version: 0.1.0
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# SQLite Development
|
|
14
|
+
|
|
15
|
+
## Mental Model
|
|
16
|
+
|
|
17
|
+
SQLite is an **embedded database engine**, not a client-server system. The entire database lives in a single file (or `:memory:`), linked directly into the application process. There is no network protocol, no connection pooling daemon, and no separate service to manage.
|
|
18
|
+
|
|
19
|
+
This architecture gives SQLite properties that eliminate external infrastructure: ACID transactions without a database server, full-text search without Elasticsearch, JSON querying without a document store, and concurrent reads without connection pool tuning. The tradeoff is a single-writer model -- only one connection can write at a time, though WAL mode allows concurrent reads during writes.
|
|
20
|
+
|
|
21
|
+
SQLite supports these built-in extensions that replace external services:
|
|
22
|
+
- **JSON1** -- query and index JSON columns without a document database
|
|
23
|
+
- **FTS5** -- full-text search with ranking without a search engine
|
|
24
|
+
- **R-Tree** -- spatial indexing without PostGIS
|
|
25
|
+
|
|
26
|
+
Assume SQLite 3.35+ (2021) for all new code, which includes `RETURNING`, `INSERT ... ON CONFLICT`, and `STRICT` tables.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Core Configuration
|
|
31
|
+
|
|
32
|
+
Apply these PRAGMAs at connection startup. They control durability, concurrency, and correctness:
|
|
33
|
+
|
|
34
|
+
```sql
|
|
35
|
+
PRAGMA journal_mode = WAL; -- concurrent readers, non-blocking writes
|
|
36
|
+
PRAGMA foreign_keys = ON; -- enforce foreign key constraints
|
|
37
|
+
PRAGMA busy_timeout = 5000; -- wait 5s on lock instead of failing immediately
|
|
38
|
+
PRAGMA synchronous = NORMAL; -- safe with WAL, faster than FULL
|
|
39
|
+
PRAGMA cache_size = -64000; -- 64MB page cache (negative = KB)
|
|
40
|
+
PRAGMA temp_store = MEMORY; -- temp tables in RAM
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**WAL (Write-Ahead Log)** replaces the default rollback journal with an append-only log. Readers see a consistent snapshot while a writer appends to the log. This eliminates read-write contention for most workloads. WAL persists across connections -- set it once per database, not per connection.
|
|
44
|
+
|
|
45
|
+
`foreign_keys` must be enabled per connection; it does not persist in the database file.
|
|
46
|
+
|
|
47
|
+
> **Deep dive:** See `references/schema-and-pragmas.md` for all recommended PRAGMAs with rationale, WAL internals, checkpointing, and FTS5 tokenizer configuration.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Schema Design
|
|
52
|
+
|
|
53
|
+
### Tables and Types
|
|
54
|
+
|
|
55
|
+
Use `STRICT` tables for new schemas to enforce type checking at the engine level. Without `STRICT`, SQLite uses type affinity -- a column declared `INTEGER` happily stores text:
|
|
56
|
+
|
|
57
|
+
```sql
|
|
58
|
+
CREATE TABLE users (
|
|
59
|
+
id INTEGER PRIMARY KEY, -- alias for rowid, auto-increment
|
|
60
|
+
email TEXT NOT NULL UNIQUE,
|
|
61
|
+
display_name TEXT,
|
|
62
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
63
|
+
metadata TEXT -- JSON stored as text
|
|
64
|
+
) STRICT;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`INTEGER PRIMARY KEY` is an alias for SQLite's internal `rowid`, giving maximum performance for lookups by primary key.
|
|
68
|
+
|
|
69
|
+
### WITHOUT ROWID
|
|
70
|
+
|
|
71
|
+
For tables where the primary key is not a single integer (composite keys, text keys), `WITHOUT ROWID` stores rows in primary-key order, eliminating the separate rowid lookup:
|
|
72
|
+
|
|
73
|
+
```sql
|
|
74
|
+
CREATE TABLE user_roles (
|
|
75
|
+
user_id INTEGER NOT NULL REFERENCES users(id),
|
|
76
|
+
role TEXT NOT NULL,
|
|
77
|
+
PRIMARY KEY (user_id, role)
|
|
78
|
+
) WITHOUT ROWID, STRICT;
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### CHECK Constraints
|
|
82
|
+
|
|
83
|
+
```sql
|
|
84
|
+
CREATE TABLE products (
|
|
85
|
+
id INTEGER PRIMARY KEY,
|
|
86
|
+
price REAL NOT NULL CHECK (price > 0),
|
|
87
|
+
status TEXT NOT NULL CHECK (status IN ('active', 'archived', 'draft'))
|
|
88
|
+
) STRICT;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Parameterized Queries
|
|
94
|
+
|
|
95
|
+
Always use parameter binding. Never interpolate values into SQL strings -- this prevents SQL injection and allows SQLite to cache prepared statements.
|
|
96
|
+
|
|
97
|
+
**Python:**
|
|
98
|
+
```python
|
|
99
|
+
cursor.execute("SELECT * FROM users WHERE email = ?", (email,))
|
|
100
|
+
cursor.execute("INSERT INTO users (email, name) VALUES (:email, :name)",
|
|
101
|
+
{"email": email, "name": name})
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**JavaScript (better-sqlite3):**
|
|
105
|
+
```javascript
|
|
106
|
+
const user = db.prepare("SELECT * FROM users WHERE email = ?").get(email);
|
|
107
|
+
const insert = db.prepare("INSERT INTO users (email, name) VALUES (@email, @name)");
|
|
108
|
+
insert.run({ email, name });
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`?` placeholders bind by position. Named placeholders (`:name` in Python, `@name` or `$name` in better-sqlite3) bind by key from a dict/object. Named placeholders are clearer for queries with many parameters.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## JSON Support (JSON1)
|
|
116
|
+
|
|
117
|
+
SQLite stores JSON as text but provides functions to query, extract, and index JSON values without parsing in application code.
|
|
118
|
+
|
|
119
|
+
### Extraction and Querying
|
|
120
|
+
|
|
121
|
+
```sql
|
|
122
|
+
-- Extract a scalar value
|
|
123
|
+
SELECT json_extract(metadata, '$.theme') FROM users;
|
|
124
|
+
|
|
125
|
+
-- Arrow operators (SQLite 3.38+)
|
|
126
|
+
SELECT metadata->>'$.theme' FROM users;
|
|
127
|
+
|
|
128
|
+
-- Iterate over a JSON array
|
|
129
|
+
SELECT u.email, tag.value
|
|
130
|
+
FROM users u, json_each(u.metadata, '$.tags') AS tag;
|
|
131
|
+
|
|
132
|
+
-- Aggregate into a JSON array
|
|
133
|
+
SELECT json_group_array(json_object('id', id, 'email', email))
|
|
134
|
+
FROM users;
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Indexing JSON Fields
|
|
138
|
+
|
|
139
|
+
Create a generated column to index a JSON path, enabling indexed lookups on JSON values:
|
|
140
|
+
|
|
141
|
+
```sql
|
|
142
|
+
ALTER TABLE users ADD COLUMN theme TEXT
|
|
143
|
+
GENERATED ALWAYS AS (json_extract(metadata, '$.theme')) STORED;
|
|
144
|
+
|
|
145
|
+
CREATE INDEX idx_users_theme ON users(theme);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Expression indexes provide the same result without a physical column:
|
|
149
|
+
|
|
150
|
+
```sql
|
|
151
|
+
CREATE INDEX idx_users_theme ON users(json_extract(metadata, '$.theme'));
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Full-Text Search (FTS5)
|
|
157
|
+
|
|
158
|
+
FTS5 provides full-text indexing with BM25 ranking. Create a virtual table backed by the source data:
|
|
159
|
+
|
|
160
|
+
```sql
|
|
161
|
+
CREATE VIRTUAL TABLE posts_fts USING fts5(
|
|
162
|
+
title, body,
|
|
163
|
+
content='posts',
|
|
164
|
+
content_rowid='id',
|
|
165
|
+
tokenize='porter unicode61'
|
|
166
|
+
);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Querying
|
|
170
|
+
|
|
171
|
+
```sql
|
|
172
|
+
-- Basic search with ranking
|
|
173
|
+
SELECT p.*, rank
|
|
174
|
+
FROM posts_fts
|
|
175
|
+
JOIN posts p ON posts_fts.rowid = p.id
|
|
176
|
+
WHERE posts_fts MATCH 'sqlite AND full-text'
|
|
177
|
+
ORDER BY rank;
|
|
178
|
+
|
|
179
|
+
-- Highlighted results
|
|
180
|
+
SELECT highlight(posts_fts, 0, '<b>', '</b>') AS title,
|
|
181
|
+
snippet(posts_fts, 1, '<b>', '</b>', '...', 32) AS body_snippet
|
|
182
|
+
FROM posts_fts WHERE posts_fts MATCH 'search query';
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Keeping FTS in Sync
|
|
186
|
+
|
|
187
|
+
Maintain the FTS index with triggers on the source table:
|
|
188
|
+
|
|
189
|
+
```sql
|
|
190
|
+
CREATE TRIGGER posts_ai AFTER INSERT ON posts BEGIN
|
|
191
|
+
INSERT INTO posts_fts(rowid, title, body) VALUES (new.id, new.title, new.body);
|
|
192
|
+
END;
|
|
193
|
+
CREATE TRIGGER posts_ad AFTER DELETE ON posts BEGIN
|
|
194
|
+
INSERT INTO posts_fts(posts_fts, rowid, title, body) VALUES ('delete', old.id, old.title, old.body);
|
|
195
|
+
END;
|
|
196
|
+
CREATE TRIGGER posts_au AFTER UPDATE ON posts BEGIN
|
|
197
|
+
INSERT INTO posts_fts(posts_fts, rowid, title, body) VALUES ('delete', old.id, old.title, old.body);
|
|
198
|
+
INSERT INTO posts_fts(rowid, title, body) VALUES (new.id, new.title, new.body);
|
|
199
|
+
END;
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
> **Deep dive:** See `references/schema-and-pragmas.md` for FTS5 tokenizer options, external content tables, prefix indexes, and FTS5 configuration.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Python: sqlite3 and aiosqlite
|
|
207
|
+
|
|
208
|
+
### Synchronous with sqlite3
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
import sqlite3
|
|
212
|
+
|
|
213
|
+
def get_connection(db_path: str) -> sqlite3.Connection:
|
|
214
|
+
conn = sqlite3.connect(db_path)
|
|
215
|
+
conn.row_factory = sqlite3.Row # dict-like access
|
|
216
|
+
conn.execute("PRAGMA journal_mode=WAL")
|
|
217
|
+
conn.execute("PRAGMA foreign_keys=ON")
|
|
218
|
+
return conn
|
|
219
|
+
|
|
220
|
+
with get_connection("app.db") as conn:
|
|
221
|
+
conn.execute("INSERT INTO users (email) VALUES (?)", ("alice@example.com",))
|
|
222
|
+
users = conn.execute("SELECT * FROM users").fetchall()
|
|
223
|
+
for user in users:
|
|
224
|
+
print(user["email"])
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
`sqlite3.Row` enables column-name access (`row["email"]`) while remaining subscriptable by index. The `with` statement auto-commits on success or rolls back on exception.
|
|
228
|
+
|
|
229
|
+
### Async with aiosqlite
|
|
230
|
+
|
|
231
|
+
```python
|
|
232
|
+
import aiosqlite
|
|
233
|
+
|
|
234
|
+
async def init_db(db_path: str) -> aiosqlite.Connection:
|
|
235
|
+
db = await aiosqlite.connect(db_path)
|
|
236
|
+
db.row_factory = aiosqlite.Row
|
|
237
|
+
await db.execute("PRAGMA journal_mode=WAL")
|
|
238
|
+
await db.execute("PRAGMA foreign_keys=ON")
|
|
239
|
+
return db
|
|
240
|
+
|
|
241
|
+
async def list_users(db: aiosqlite.Connection):
|
|
242
|
+
async with db.execute("SELECT * FROM users") as cursor:
|
|
243
|
+
return await cursor.fetchall()
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
aiosqlite wraps `sqlite3` in a background thread, providing an async interface without blocking the event loop. Each `aiosqlite.Connection` maps to one `sqlite3.Connection` in a dedicated thread.
|
|
247
|
+
|
|
248
|
+
> **Deep dive:** See `references/python-patterns.md` for connection pooling, custom aggregates, datetime adapters, blob I/O, aiosqlite + FastAPI integration, and migration patterns.
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## JavaScript: better-sqlite3 and D1
|
|
253
|
+
|
|
254
|
+
### Node.js with better-sqlite3
|
|
255
|
+
|
|
256
|
+
```javascript
|
|
257
|
+
const Database = require("better-sqlite3");
|
|
258
|
+
|
|
259
|
+
const db = new Database("app.db");
|
|
260
|
+
db.pragma("journal_mode = WAL");
|
|
261
|
+
db.pragma("foreign_keys = ON");
|
|
262
|
+
|
|
263
|
+
// Prepared statement (cached, reusable)
|
|
264
|
+
const getUser = db.prepare("SELECT * FROM users WHERE id = ?");
|
|
265
|
+
const user = getUser.get(42);
|
|
266
|
+
|
|
267
|
+
// Transaction
|
|
268
|
+
const insertMany = db.transaction((users) => {
|
|
269
|
+
const insert = db.prepare("INSERT INTO users (email, name) VALUES (@email, @name)");
|
|
270
|
+
for (const u of users) insert.run(u);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
insertMany([
|
|
274
|
+
{ email: "alice@example.com", name: "Alice" },
|
|
275
|
+
{ email: "bob@example.com", name: "Bob" },
|
|
276
|
+
]);
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
better-sqlite3 is synchronous by design -- it runs in the main thread with no async overhead. This makes it the fastest SQLite binding for Node.js. For CPU-bound queries on large datasets, offload to a worker thread.
|
|
280
|
+
|
|
281
|
+
### Cloudflare D1
|
|
282
|
+
|
|
283
|
+
D1 provides SQLite at the edge in Cloudflare Workers. The API is async and batch-oriented:
|
|
284
|
+
|
|
285
|
+
```javascript
|
|
286
|
+
export default {
|
|
287
|
+
async fetch(request, env) {
|
|
288
|
+
const { results } = await env.DB.prepare(
|
|
289
|
+
"SELECT * FROM users WHERE email = ?"
|
|
290
|
+
).bind(email).all();
|
|
291
|
+
|
|
292
|
+
// Batch multiple statements in one round-trip
|
|
293
|
+
const batch = await env.DB.batch([
|
|
294
|
+
env.DB.prepare("INSERT INTO logs (action) VALUES (?)").bind("login"),
|
|
295
|
+
env.DB.prepare("UPDATE users SET last_login = ? WHERE id = ?").bind(now, userId),
|
|
296
|
+
]);
|
|
297
|
+
|
|
298
|
+
return Response.json(results);
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
D1 batches execute as a single transaction. Use batching to reduce round-trip latency between the Worker and the database.
|
|
304
|
+
|
|
305
|
+
> **Deep dive:** See `references/javascript-patterns.md` for better-sqlite3 UDFs, WAL checkpoints, prepared statement caching, D1 migrations, and testing with Miniflare.
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## Ambiguity Policy
|
|
310
|
+
|
|
311
|
+
These defaults apply when the user does not specify a preference. State the assumption when making a choice so the user can override:
|
|
312
|
+
|
|
313
|
+
- **Journal mode:** Default to WAL. Use rollback journal only when WAL is explicitly problematic (network filesystems, single-write-then-close patterns).
|
|
314
|
+
- **Python sync vs async:** Default to `sqlite3` for synchronous code, `aiosqlite` for async/FastAPI/ASGI applications.
|
|
315
|
+
- **JavaScript runtime:** Default to `better-sqlite3` for Node.js, D1 for Cloudflare Workers. Do not use `better-sqlite3` in Workers or D1 outside Workers.
|
|
316
|
+
- **FTS version:** Default to FTS5. Do not use FTS3/FTS4 for new code.
|
|
317
|
+
- **Table strictness:** Default to `STRICT` for new tables. Omit `STRICT` only when interfacing with legacy schemas that rely on type affinity.
|
|
318
|
+
- **Parameter style:** Default to named placeholders (`:name` / `@name`) for queries with 3+ parameters. Use positional (`?`) for simple single-parameter queries.
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
## Reference Files
|
|
323
|
+
|
|
324
|
+
| File | Contents |
|
|
325
|
+
|------|----------|
|
|
326
|
+
| `references/python-patterns.md` | Connection pooling, custom aggregates and collations, backup API, datetime adapters, blob I/O, aiosqlite + FastAPI integration, migration patterns |
|
|
327
|
+
| `references/javascript-patterns.md` | better-sqlite3 UDFs, WAL checkpoints, prepared statement caching, D1 batch operations, D1 migrations, testing with Miniflare |
|
|
328
|
+
| `references/advanced-queries.md` | CTEs (recursive), window functions (ROW_NUMBER, RANK, LAG/LEAD, running totals), upsert, RETURNING, EXPLAIN QUERY PLAN, covering indexes |
|
|
329
|
+
| `references/schema-and-pragmas.md` | All recommended PRAGMAs with rationale, WAL internals, FTS5 tokenizers, external content tables, FTS5 sync triggers, partial/expression indexes, ANALYZE |
|