From 93e51a4a9f295e04ed4dac726b5f58cfd0204d3c Mon Sep 17 00:00:00 2001 From: stateofshit Date: Wed, 29 Jul 2026 23:50:15 +0000 Subject: [PATCH] tools: full Cloudflare doc, ref in prompts+modes --- 000-configs/modes/workspace-mode.md | 5 +- .../prompts/workspace-system-prompt.md | 20 +- 000-configs/tools/CLOUDFLARE_INSTRUCTIONS.md | 391 ++++++++++++++++++ 000-configs/tools/Cloudflare instructions.md | 13 - 000-configs/tools/README.md | 3 +- 5 files changed, 412 insertions(+), 20 deletions(-) create mode 100644 000-configs/tools/CLOUDFLARE_INSTRUCTIONS.md delete mode 100644 000-configs/tools/Cloudflare instructions.md diff --git a/000-configs/modes/workspace-mode.md b/000-configs/modes/workspace-mode.md index 39add37..6015494 100644 --- a/000-configs/modes/workspace-mode.md +++ b/000-configs/modes/workspace-mode.md @@ -5,7 +5,7 @@ folder: "000-configs/modes" tags: [mode, workspace, primary] created: "2026-07-29" updated: "2026-07-29" -version: "1.0.0" +version: "1.1.0" --- # Workspace Mode @@ -24,7 +24,8 @@ The **default mode** for working in this openwebui workspace. Covers repo work, ## Stack - **Prompt:** `[[../prompts/workspace-system-prompt]]` — paste this as the system prompt -- **Tools:** `[[../tools/GH_CLI_INSTRUCTIONS]]`, `[[../tools/PLAYWRIGHT_BROWSER_INSTRUCTIONS]]`, `[[../tools/VITE_PREVIEW_INSTRUCTIONS]]` +- **Tools:** `[[../tools/GH_CLI_INSTRUCTIONS]]`, `[[../tools/PLAYWRIGHT_BROWSER_INSTRUCTIONS]]`, `[[../tools/VITE_PREVIEW_INSTRUCTIONS]]`, `[[../tools/CLOUDFLARE_INSTRUCTIONS]]` +- **Cloudflare creds:** `[[../../000-shit_admin/cloudflare]]` (admin-only, never paste publicly) - **Vault:** `[[../../04-models/Vault-Rules]]`, `[[../../04-models/model-boot]]` - **Skills:** `[[../skills/plugins-recommended]]` diff --git a/000-configs/prompts/workspace-system-prompt.md b/000-configs/prompts/workspace-system-prompt.md index 00870fc..50753fa 100644 --- a/000-configs/prompts/workspace-system-prompt.md +++ b/000-configs/prompts/workspace-system-prompt.md @@ -5,7 +5,7 @@ folder: "000-configs/prompts" tags: [prompt, system, workspace] created: "2026-07-29" updated: "2026-07-29" -version: "1.0.0" +version: "1.1.0" --- # Workspace System Prompt @@ -28,7 +28,8 @@ You are operating inside the user's openwebui workspace. You have direct access - **Vault:** `shit_in_a_vault/` is a private Obsidian vault synced via git. It has folder rules, YAML frontmatter conventions, and versioning rules. Read `shit_in_a_vault/04-models/Vault-Rules.md` before editing any vault file. - **Auth:** SSH key + gh CLI v2.96.0 authenticated as `stateofshit` - **Public preview:** `https://preview.boogerclub.com` (for vite/React previews) -- **Tools installed:** `git`, `gh`, `playwright`, `node`, `npm`, `pnpm`, `python3`, `vite` +- **Tools installed:** `git`, `gh`, `playwright`, `node`, `npm`, `pnpm`, `python3`, `vite`, `npx wrangler` +- **Cloudflare account:** see `shit_in_a_vault/000-shit_admin/cloudflare.md` (credentials, read at runtime) ## How You Behave @@ -70,8 +71,8 @@ status: "draft" | "active" | "archive" folder: "" tags: [tag1, tag2] created: "YYYY-MM-DD" -updated: "YYYY-MM-DD" -version: "1.0.0" +updated: "2026-07-29" +version: "1.1.0" --- ``` @@ -84,6 +85,17 @@ Add as needed: ## Common Workflows +### Cloudflare — deploy a worker + +```bash +cd /path/to/worker +npx wrangler deploy +# or to staging: +npx wrangler deploy --env staging +``` + +See `000-configs/tools/CLOUDFLARE_INSTRUCTIONS.md` for full reference. + ### Edit a vault file ```bash cd /home/user/02-repos/shit_in_a_vault diff --git a/000-configs/tools/CLOUDFLARE_INSTRUCTIONS.md b/000-configs/tools/CLOUDFLARE_INSTRUCTIONS.md new file mode 100644 index 0000000..e775fd3 --- /dev/null +++ b/000-configs/tools/CLOUDFLARE_INSTRUCTIONS.md @@ -0,0 +1,391 @@ +--- +title: "Cloudflare Platform" +status: "active" +folder: "000-configs/tools" +tags: [tool, cloudflare, workers, r2, d1, kv, ai, hosting] +created: "2026-07-29" +updated: "2026-07-29" +version: "1.1.0" +--- + +# Cloudflare Platform Instructions + +Cloudflare is the **hosting and edge platform** for this workspace. Use Workers (serverless functions), Pages (static sites), R2 (object storage), D1 (SQLite at the edge), KV (key-value), Workers AI, and the Agents SDK. + +Credentials are in `[[000-shit_admin/cloudflare]]` (admin-only file, read at runtime — never commit or paste publicly). + +## Quick Reference + +- **CLI:** `npx wrangler` (not installed globally — use npx) +- **Account ID:** see admin doc +- **API Token:** see admin doc +- **Auth check:** `npx wrangler whoami` +- **Docs:** https://developers.cloudflare.com/ + +--- + +## 1. First-Time Setup + +```bash +# Verify CLI is reachable +npx wrangler --version + +# Login (uses browser-based OAuth) +npx wrangler login + +# Verify auth +npx wrangler whoami +``` + +If `wrangler login` is not possible in the environment, set the API token directly: + +```bash +export CLOUDFLARE_API_TOKEN="" +export CLOUDFLARE_ACCOUNT_ID="" +``` + +**Verify token works:** + +```bash +curl -X GET "https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/tokens/verify" \ + -H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" +``` + +--- + +## 2. Workers (Serverless Functions) + +### Create a new Worker + +```bash +npx wrangler init my-worker +cd my-worker +``` + +### Deploy + +```bash +npx wrangler deploy +``` + +### Local dev + +```bash +npx wrangler dev +# runs at http://localhost:8787 +``` + +### Tail logs + +```bash +npx wrangler tail +# real-time logs from production +``` + +### Set secrets (env vars) + +```bash +echo "secret-value" | npx wrangler secret put SECRET_NAME +``` + +--- + +## 3. R2 (Object Storage) + +S3-compatible blob storage. Cheaper than AWS S3. + +### Create bucket + +```bash +npx wrangler r2 bucket create my-bucket +``` + +### List buckets + +```bash +npx wrangler r2 bucket list +``` + +### Upload file + +```bash +npx wrangler r2 object put my-bucket/path/to/file.txt --file ./local-file.txt +``` + +### Download file + +```bash +npx wrangler r2 object get my-bucket/path/to/file.txt --file ./downloaded.txt +``` + +### Direct API (S3-compatible) + +Endpoint format: `https://.r2.cloudflarestorage.com` + +```bash +# Credentials are in admin doc +ACCESS_KEY_ID="" +SECRET_ACCESS_KEY="" +ENDPOINT="https://.r2.cloudflarestorage.com" + +# Upload via AWS CLI (or any S3 client) +aws s3 cp ./file.txt s3://my-bucket/file.txt \ + --endpoint-url "$ENDPOINT" \ + --access-key-id "$ACCESS_KEY_ID" \ + --secret-access-key "$SECRET_ACCESS_KEY" +``` + +--- + +## 4. D1 (SQLite at the Edge) + +Distributed SQLite database. + +### Create database + +```bash +npx wrangler d1 create my-db +# outputs: database_id = "xxxx-xxxx-xxxx" +``` + +### Run migrations + +```bash +npx wrangler d1 migrations create my-db create_users_table +npx wrangler d1 migrations apply my-db --remote +``` + +### Execute SQL + +```bash +npx wrangler d1 execute my-db --command "SELECT * FROM users" +``` + +### Local dev DB + +```bash +npx wrangler d1 execute my-db --local --command "SELECT * FROM users" +``` + +--- + +## 5. KV (Key-Value Store) + +Low-latency global KV. + +### Create namespace + +```bash +npx wrangler kv namespace create MY_KV +# outputs: id = "xxxx" +``` + +### Write / read + +```bash +npx wrangler kv key put --namespace-id= "my-key" "my-value" +npx wrangler kv key get --namespace-id= "my-key" +``` + +--- + +## 6. Workers AI + +```bash +npx wrangler ai run "@cf/meta/llama-3.1-8b-instruct" \ + --prompt "Hello world" +``` + +Models list: https://developers.cloudflare.com/workers-ai/models/ + +--- + +## 7. Pages (Static Sites) + +### Deploy + +```bash +npx wrangler pages deploy ./dist --project-name=my-site +``` + +### Local dev + +```bash +npx wrangler pages dev ./dist +``` + +--- + +## 8. wrangler.jsonc Config + +Prefer JSON config over TOML. Newer features are JSON-only. + +```jsonc +{ + "name": "my-worker", + "main": "src/index.ts", + "compatibility_date": "2026-07-15", + "compatibility_flags": ["nodejs_compat"], + "vars": { + "ENV": "production" + }, + "kv_namespaces": [ + { + "binding": "MY_KV", + "id": "xxxx" + } + ], + "r2_buckets": [ + { + "binding": "MY_BUCKET", + "bucket_name": "my-bucket" + } + ], + "d1_databases": [ + { + "binding": "DB", + "database_name": "my-db", + "database_id": "xxxx" + } + ], + "ai": { + "binding": "AI" + } +} +``` + +After config changes, regenerate TypeScript bindings: + +```bash +npx wrangler types +``` + +--- + +## 9. Local Dev Defaults + +- Bindings use **local simulation** unless `remote: true` +- KV, R2, D1 all have local SQLite-backed emulators +- For real cloud data in dev: + +```bash +npx wrangler dev --remote +``` + +--- + +## 10. Profiles + +Use environments for staging/prod: + +```jsonc +{ + "env": { + "staging": { + "name": "my-worker-staging", + "vars": { "ENV": "staging" } + }, + "production": { + "name": "my-worker-prod", + "vars": { "ENV": "production" } + } + } +} +``` + +Deploy to env: + +```bash +npx wrangler deploy --env staging +npx wrangler deploy --env production +``` + +--- + +## 11. Common Patterns + +### Cron-triggered Worker + +```jsonc +{ + "triggers": { + "crons": ["*/5 * * * *"] // every 5 min + } +} +``` + +### Queue consumer + +```jsonc +{ + "queues": { + "consumers": [{ "queue": "my-queue", "max_batch_size": 10 }] + } +} +``` + +### Durable Object + +```jsonc +{ + "durable_objects": { + "bindings": [ + { "name": "COUNTER", "class_name": "Counter" } + ] + }, + "migrations": [ + { "tag": "v1", "new_sqlite_classes": ["Counter"] } + ] +} +``` + +--- + +## 12. Skills (Loaded on Demand) + +The following skills live in `/home/user/.agents/skills/`: + +| Skill | When to load | +|---|---| +| `cloudflare` | General Cloudflare platform questions | +| `wrangler` | CLI commands, flags, config reference | +| `workers-best-practices` | Worker architecture, performance | +| `durable-objects` | DO patterns, migrations | +| `cloudflare-email-service` | Email routing/workers | +| `cloudflare-one` | Zero Trust, Tunnel, Access | +| `cloudflare-one-migrations` | Migrate from other providers | +| `sandbox-sdk` | Sandboxed code execution | +| `turnstile-spin` | CAPTCHA integration | +| `web-perf` | Performance tuning | + +Load via `view_skill` tool or read `SKILL.md` directly. + +--- + +## 13. Failure Modes to Avoid + +- ❌ Don't hardcode credentials in source — use `wrangler secret` +- ❌ Don't commit `wrangler.jsonc` with secrets — only bindings/IDs +- ❌ Don't use TOML — prefer `wrangler.jsonc` +- ❌ Don't skip `compatibility_date` — always set a recent one +- ❌ Don't edit local DB and assume it's in prod — use `--remote` flag +- ❌ Don't run `wrangler deploy` without testing locally first +- ❌ Don't paste API tokens in chat — read from admin doc at runtime + +--- + +## 14. Auth Priority + +When loading the workspace prompt, prefer: +1. `wrangler login` (OAuth, persists) +2. `CLOUDFLARE_API_TOKEN` env var (read from admin doc) +3. Hardcoded token (worst, only for one-off scripts) + +--- + +## Related Docs + +- [[GH_CLI_INSTRUCTIONS]] — GitHub +- [[VITE_PREVIEW_INSTRUCTIONS]] — Vite preview +- [[PLAYWRIGHT_BROWSER_INSTRUCTIONS]] — Browser automation +- [[000-shit_admin/cloudflare]] — admin creds (read-only) diff --git a/000-configs/tools/Cloudflare instructions.md b/000-configs/tools/Cloudflare instructions.md deleted file mode 100644 index 4451940..0000000 --- a/000-configs/tools/Cloudflare instructions.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: cloudflare instructions -status: active -folder: 000-configs/tools -tags: - - ai-tools - - cli - - cloudflare -created: 2026-07-29 -updated: 2026-07-29 -version: 1.0.0 ---- -d \ No newline at end of file diff --git a/000-configs/tools/README.md b/000-configs/tools/README.md index 32cac7b..239f725 100644 --- a/000-configs/tools/README.md +++ b/000-configs/tools/README.md @@ -5,7 +5,7 @@ folder: "000-configs/tools" tags: [readme, tools] created: "2026-07-29" updated: "2026-07-29" -version: "1.0.0" +version: "1.1.0" --- # Tools @@ -21,6 +21,7 @@ Tool docs — CLI references, browser automation, frameworks, anything with a CL - `GH_CLI_INSTRUCTIONS.md` — GitHub CLI - `PLAYWRIGHT_BROWSER_INSTRUCTIONS.md` — browser automation - `VITE_PREVIEW_INSTRUCTIONS.md` — Vite preview server +- `CLOUDFLARE_INSTRUCTIONS.md` — Cloudflare Workers / R2 / D1 / KV / AI ## Adding a new tool doc