Skip to content

Commit 702913e

Browse files
committed
feat: Improved folder naming and added README documentation
1 parent 7a64b1b commit 702913e

7 files changed

Lines changed: 130 additions & 21628 deletions

File tree

CLAUDE.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,36 @@ Deployment (`scripts/deploy.ts`) uploads the built plugin to Cloudflare R2:
283283
- Production: `plugins/{name}/{version}/index.js`
284284
- Beta: `plugins/{name}/beta/index.js`
285285

286+
## Completions System
287+
288+
The Codify Editor supports auto-complete for certain resource parameters (e.g. Homebrew formula names, Node.js versions). These completions are pre-fetched by a Cloudflare Workers cron job that lives in `completions-cron/`.
289+
290+
### Adding completions for a parameter
291+
292+
1. Create `src/resources/<category>/<resource>/completions/<type>.<param>.ts`
293+
2. Export a default async function returning `Promise<string[]>` — fetch the values, return them, nothing else
294+
3. The filename determines the Supabase metadata automatically:
295+
- `homebrew.formulae.ts``resource_type=homebrew`, `parameter_path=/formulae`
296+
4. Run `npm run build:completions` to regenerate the index
297+
298+
```bash
299+
npm run build:completions # regenerate completions-cron/src/__generated__/completions-index.ts
300+
npm run deploy:completions # build + deploy to Cloudflare Workers
301+
```
302+
303+
### How it fits together
304+
305+
```
306+
src/resources/**/completions/*.ts ← per-resource fetch scripts (return string[])
307+
↓ npm run build:completions
308+
completions-cron/src/__generated__/completions-index.ts ← AUTO-GENERATED, do not edit
309+
completions-cron/src/index.ts ← orchestrator: Supabase writes, scheduled handler
310+
↓ wrangler deploy
311+
Cloudflare Workers (runs daily at 05:00 UTC)
312+
```
313+
314+
See `completions-cron/README.md` for full details.
315+
286316
## Key Patterns
287317

288318
### allowMultiple Configuration
@@ -402,10 +432,17 @@ The framework automatically validates dependencies exist and orders execution.
402432
**Build:**
403433
- `/scripts/build.ts` - Build process with schema collection
404434
- `/scripts/deploy.ts` - Deployment to Cloudflare R2
435+
- `/scripts/generate-completions-index.ts` - Generates completions-cron entry index
405436
- `/rollup.config.js` - Bundling configuration
406437
- `/tsconfig.json` - TypeScript config (ES2024, strict mode)
407438
- `/vitest.config.ts` - Test runner config
408439

440+
**Completions cron:**
441+
- `/completions-cron/src/index.ts` - Cloudflare Workers scheduled handler
442+
- `/completions-cron/src/__generated__/completions-index.ts` - Auto-generated, do not edit
443+
- `/completions-cron/wrangler.toml` - Worker config (schedule, env vars)
444+
- `/completions-cron/README.md` - Full documentation
445+
409446
**Testing:**
410447
- `/test/setup.ts` - Global test setup/teardown
411448
- `/test/test-utils.ts` - Test helpers

completions-cron/.vscode/settings.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

completions-cron/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# resource-completions-cron
2+
3+
A Cloudflare Workers scheduled job that pre-fetches auto-complete values for resource parameters in the Codify Editor. It runs daily and writes results to the `resource_parameter_completions` Supabase table.
4+
5+
## How It Works
6+
7+
### 1. Per-resource completion scripts
8+
9+
Each resource that supports completions has one or more scripts co-located with it in the plugin:
10+
11+
```
12+
codify-homebrew-plugin/src/resources/
13+
homebrew/completions/
14+
homebrew.formulae.ts → resource_type=homebrew, parameter_path=/formulae
15+
homebrew.casks.ts → resource_type=homebrew, parameter_path=/casks
16+
javascript/nvm/completions/
17+
nvm.nodeVersions.ts → resource_type=nvm, parameter_path=/nodeVersions
18+
python/pyenv/completions/
19+
pyenv.pythonVersions.ts → resource_type=pyenv, parameter_path=/pythonVersions
20+
```
21+
22+
**Naming convention:** `<resource-type>.<parameter-name>.ts`
23+
- The filename determines the Supabase metadata — no configuration needed
24+
- Each file exports a single `default async function(): Promise<string[]>` that fetches and returns the completion values. It has no knowledge of Supabase.
25+
26+
### 2. Code generation
27+
28+
Running `npm run build:completions` (from the plugin root) executes `scripts/generate-completions-index.ts`, which:
29+
- Globs all `src/resources/**/completions/*.ts` files in the plugin
30+
- Parses each filename for `resourceType` and `parameterPath`
31+
- Writes `src/__generated__/completions-index.ts` — a static list of imports and metadata
32+
33+
`src/__generated__/completions-index.ts` is auto-generated. **Do not edit it by hand.**
34+
35+
### 3. Orchestrator
36+
37+
`src/index.ts` is the Cloudflare Workers entry point. It:
38+
- Imports `completionModules` from the generated index
39+
- For each module, calls the `fetch()` function to get `string[]` values
40+
- Looks up the `resource_id` from the `registry_resources` Supabase table
41+
- Deletes old completions and batch-inserts new ones (1000 rows per batch) into `resource_parameter_completions`
42+
- Runs all modules concurrently via `Promise.allSettled`
43+
44+
## Commands
45+
46+
All commands are run from the **plugin root** (`codify-homebrew-plugin/`):
47+
48+
```bash
49+
# Regenerate src/__generated__/completions-index.ts
50+
npm run build:completions
51+
52+
# Build + deploy to Cloudflare Workers
53+
npm run deploy:completions
54+
```
55+
56+
To run/test locally (from this directory):
57+
58+
```bash
59+
# Start local wrangler dev server with scheduled trigger support
60+
npm run dev
61+
62+
# Trigger the scheduled handler manually against the local server
63+
npm run start:cron
64+
```
65+
66+
## Adding a New Completion
67+
68+
1. Create `src/resources/<category>/<resource>/completions/<type>.<param>.ts` in the plugin
69+
2. Export a default async function returning `string[]`
70+
3. Run `npm run build:completions` from the plugin root to regenerate the index
71+
4. Run `npm run deploy:completions` to deploy
72+
73+
No changes are needed to any file in this directory.
74+
75+
## Environment Variables
76+
77+
| Variable | Where set |
78+
|---|---|
79+
| `SUPABASE_URL` | `wrangler.toml` `[vars]` (public URL, safe to commit) |
80+
| `SUPABASE_SERVICE_ROLE_KEY` | Cloudflare Workers secret (set via `wrangler secret put`) |
81+
82+
## Schedule
83+
84+
The cron runs daily at 05:00 UTC (`0 5 * * *`), configured in `wrangler.toml`.

completions-cron/src/completions-index.ts renamed to completions-cron/src/__generated__/completions-index.ts

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)