create-usebecky 0.0.0-stage → 0.2.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/README.md +80 -2
- package/dist/create.js +842 -0
- package/dist/extension-skill/usebecky-extension/SKILL.md +181 -0
- package/dist/extension-skill/usebecky-extension/references/accounts.md +125 -0
- package/dist/extension-skill/usebecky-extension/references/dev-server.md +102 -0
- package/dist/extension-skill/usebecky-extension/references/manifest.md +104 -0
- package/dist/extension-skill/usebecky-extension/references/oauth-and-tokens.md +179 -0
- package/dist/extension-skill/usebecky-extension/references/partner-api.md +87 -0
- package/dist/extension-skill/usebecky-extension/references/submit-and-pricing.md +31 -0
- package/dist/extension-skill/usebecky-extension/references/ui.md +172 -0
- package/dist/extension-skill/usebecky-extension/references/webhooks.md +97 -0
- package/dist/index.js +10 -0
- package/dist/keys.js +72 -0
- package/dist/platform.js +104 -0
- package/dist/pm.js +69 -0
- package/dist/prompts.js +242 -0
- package/dist/scaffold.js +108 -0
- package/dist/setup.js +130 -0
- package/dist/shared/ai.js +203 -0
- package/dist/shared/extension-skill.js +107 -0
- package/dist/shared/framework.js +460 -0
- package/dist/shared/hosted.js +8 -0
- package/dist/shared/ui.js +141 -0
- package/dist/skill/usebecky/SKILL.md +339 -0
- package/dist/skill/usebecky/references/access-rules.md +307 -0
- package/dist/skill/usebecky/references/addons.md +68 -0
- package/dist/skill/usebecky/references/analytics.md +166 -0
- package/dist/skill/usebecky/references/android.md +434 -0
- package/dist/skill/usebecky/references/auth.md +379 -0
- package/dist/skill/usebecky/references/cache.md +51 -0
- package/dist/skill/usebecky/references/components.md +127 -0
- package/dist/skill/usebecky/references/emails.md +105 -0
- package/dist/skill/usebecky/references/expo.md +147 -0
- package/dist/skill/usebecky/references/functions.md +99 -0
- package/dist/skill/usebecky/references/hosting.md +119 -0
- package/dist/skill/usebecky/references/http-api.md +233 -0
- package/dist/skill/usebecky/references/ios.md +355 -0
- package/dist/skill/usebecky/references/payments.md +493 -0
- package/dist/skill/usebecky/references/realtime.md +143 -0
- package/dist/skill/usebecky/references/scheduled-jobs.md +82 -0
- package/dist/skill/usebecky/references/sdk.md +838 -0
- package/dist/skill/usebecky/references/storage.md +210 -0
- package/dist/skill/usebecky/references/templates.md +191 -0
- package/dist/skill/usebecky/references/wordpress.md +87 -0
- package/dist/templates.js +74 -0
- package/package.json +37 -4
- package/templates/expo/App.tsx +48 -0
- package/templates/expo/README.md +59 -0
- package/templates/expo/_env.example +4 -0
- package/templates/expo/_gitignore +12 -0
- package/templates/expo/app.json +25 -0
- package/templates/expo/assets/icon.png +0 -0
- package/templates/expo/brand.ts +7 -0
- package/templates/expo/components/Avatar.tsx +75 -0
- package/templates/expo/components/ui.tsx +57 -0
- package/templates/expo/index.ts +4 -0
- package/templates/expo/lib/theme.ts +43 -0
- package/templates/expo/lib/usebecky.ts +15 -0
- package/templates/expo/package.json +29 -0
- package/templates/expo/screens/Home.tsx +187 -0
- package/templates/expo/screens/SignIn.tsx +112 -0
- package/templates/expo/tsconfig.json +6 -0
- package/templates/expo/usebecky.template.json +36 -0
- package/templates/extension/README.md +128 -0
- package/templates/extension/_env.example +21 -0
- package/templates/extension/_gitignore +11 -0
- package/templates/extension/logo.svg +1 -0
- package/templates/extension/package.json +25 -0
- package/templates/extension/src/accounts.ts +90 -0
- package/templates/extension/src/app.ts +178 -0
- package/templates/extension/src/pages.ts +108 -0
- package/templates/extension/src/replay-guard.ts +17 -0
- package/templates/extension/src/server.ts +57 -0
- package/templates/extension/src/settings.ts +69 -0
- package/templates/extension/src/ui.ts +70 -0
- package/templates/extension/test/app.test.ts +222 -0
- package/templates/extension/tsconfig.json +16 -0
- package/templates/extension/usebecky-extension.json +36 -0
- package/templates/extension/usebecky.template.json +22 -0
- package/templates/landing/README.md +43 -0
- package/templates/landing/_env.example +4 -0
- package/templates/landing/_gitignore +9 -0
- package/templates/landing/index.html +16 -0
- package/templates/landing/package.json +28 -0
- package/templates/landing/public/icon.svg +1 -0
- package/templates/landing/src/App.tsx +97 -0
- package/templates/landing/src/components/Contact.tsx +43 -0
- package/templates/landing/src/components/Counter.tsx +34 -0
- package/templates/landing/src/components/Feedback.tsx +36 -0
- package/templates/landing/src/components/Logo.tsx +11 -0
- package/templates/landing/src/components/Receipt.tsx +128 -0
- package/templates/landing/src/components/Setup.tsx +20 -0
- package/templates/landing/src/components/fields.tsx +63 -0
- package/templates/landing/src/content.ts +22 -0
- package/templates/landing/src/index.css +119 -0
- package/templates/landing/src/lib/usebecky.ts +11 -0
- package/templates/landing/src/lib/waitlist.ts +46 -0
- package/templates/landing/src/main.tsx +12 -0
- package/templates/landing/src/vite-env.d.ts +6 -0
- package/templates/landing/tsconfig.json +19 -0
- package/templates/landing/usebecky.template.json +20 -0
- package/templates/landing/vite.config.ts +10 -0
- package/templates/notes/README.md +68 -0
- package/templates/notes/_env.example +4 -0
- package/templates/notes/_gitignore +9 -0
- package/templates/notes/index.html +15 -0
- package/templates/notes/package.json +28 -0
- package/templates/notes/public/icon.svg +1 -0
- package/templates/notes/src/App.tsx +35 -0
- package/templates/notes/src/brand.ts +7 -0
- package/templates/notes/src/components/Composer.tsx +113 -0
- package/templates/notes/src/components/NoteEntry.tsx +151 -0
- package/templates/notes/src/components/Notes.tsx +163 -0
- package/templates/notes/src/components/Setup.tsx +44 -0
- package/templates/notes/src/components/SignIn.tsx +112 -0
- package/templates/notes/src/components/icons.tsx +54 -0
- package/templates/notes/src/index.css +105 -0
- package/templates/notes/src/lib/notes.ts +68 -0
- package/templates/notes/src/lib/usebecky.ts +9 -0
- package/templates/notes/src/main.tsx +22 -0
- package/templates/notes/src/vite-env.d.ts +6 -0
- package/templates/notes/tsconfig.json +19 -0
- package/templates/notes/usebecky.template.json +34 -0
- package/templates/notes/vite.config.ts +10 -0
- package/templates/saas/README.md +69 -0
- package/templates/saas/_env.example +10 -0
- package/templates/saas/_gitignore +11 -0
- package/templates/saas/app/(app)/account/ManageBilling.tsx +26 -0
- package/templates/saas/app/(app)/account/page.tsx +71 -0
- package/templates/saas/app/(app)/dashboard/Projects.tsx +227 -0
- package/templates/saas/app/(app)/dashboard/page.tsx +21 -0
- package/templates/saas/app/(app)/layout.tsx +29 -0
- package/templates/saas/app/(app)/premium/page.tsx +62 -0
- package/templates/saas/app/auth/callback/page.tsx +33 -0
- package/templates/saas/app/globals.css +143 -0
- package/templates/saas/app/icon.svg +1 -0
- package/templates/saas/app/layout.tsx +20 -0
- package/templates/saas/app/page.tsx +87 -0
- package/templates/saas/app/pricing/Plans.tsx +133 -0
- package/templates/saas/app/pricing/TestCardHint.tsx +18 -0
- package/templates/saas/app/pricing/page.tsx +21 -0
- package/templates/saas/app/setup/page.tsx +34 -0
- package/templates/saas/app/sign-in/SignInForm.tsx +195 -0
- package/templates/saas/app/sign-in/page.tsx +21 -0
- package/templates/saas/brand.ts +10 -0
- package/templates/saas/components/AppNav.tsx +45 -0
- package/templates/saas/components/Logo.tsx +22 -0
- package/templates/saas/components/SiteHeader.tsx +50 -0
- package/templates/saas/components/Status.tsx +15 -0
- package/templates/saas/lib/session.ts +26 -0
- package/templates/saas/lib/usebecky.ts +11 -0
- package/templates/saas/next-env.d.ts +5 -0
- package/templates/saas/next.config.ts +5 -0
- package/templates/saas/package.json +26 -0
- package/templates/saas/postcss.config.mjs +3 -0
- package/templates/saas/tsconfig.json +21 -0
- package/templates/saas/usebecky.template.json +31 -0
package/dist/setup.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export async function applySetup(platform, ref, setup = {}) {
|
|
2
|
+
const steps = [];
|
|
3
|
+
const env = {};
|
|
4
|
+
const base = `/projects/${encodeURIComponent(ref)}`;
|
|
5
|
+
const api = platform.request;
|
|
6
|
+
const wantsTables = (setup.tables?.length ?? 0) > 0 || (setup.realtime?.length ?? 0) > 0;
|
|
7
|
+
let tables = new Map();
|
|
8
|
+
if (wantsTables) {
|
|
9
|
+
const r = await api('GET', `${base}/database/tables`);
|
|
10
|
+
if (r.error)
|
|
11
|
+
return { steps: [{ kind: 'table', name: 'tables', status: 'failed', error: r.error }], env, ok: false };
|
|
12
|
+
tables = new Map(r.data.map((t) => [t.name, t]));
|
|
13
|
+
}
|
|
14
|
+
for (const spec of setup.tables ?? [])
|
|
15
|
+
steps.push(...(await ensureTable(spec)));
|
|
16
|
+
const realtimeTables = [...(setup.tables ?? []).filter((t) => t.realtime).map((t) => t.name), ...(setup.realtime ?? [])];
|
|
17
|
+
for (const name of [...new Set(realtimeTables)])
|
|
18
|
+
steps.push(await ensureRealtime(name));
|
|
19
|
+
for (const spec of setup.buckets ?? [])
|
|
20
|
+
steps.push(...(await ensureBucket(spec)));
|
|
21
|
+
for (const spec of setup.forms ?? [])
|
|
22
|
+
steps.push(await ensureForm(spec));
|
|
23
|
+
return { steps, env, ok: !steps.some((s) => s.status === 'failed') };
|
|
24
|
+
async function ensureTable(spec) {
|
|
25
|
+
const existing = tables.get(spec.name);
|
|
26
|
+
if (!existing) {
|
|
27
|
+
const r = await api('POST', `${base}/database/tables`, { name: spec.name, preset: spec.preset ?? 'owner', columns: spec.columns, comment: spec.comment });
|
|
28
|
+
if (r.error)
|
|
29
|
+
return [{ kind: 'table', name: spec.name, status: 'failed', error: r.error }];
|
|
30
|
+
tables.set(spec.name, r.data);
|
|
31
|
+
return [{ kind: 'table', name: spec.name, status: 'created', detail: describeColumns(spec) }];
|
|
32
|
+
}
|
|
33
|
+
// The table is there (an earlier run, or the user made it): add only the columns it lacks.
|
|
34
|
+
const have = new Set(existing.columns.map((c) => c.name));
|
|
35
|
+
const out = [];
|
|
36
|
+
for (const col of spec.columns) {
|
|
37
|
+
if (have.has(col.name))
|
|
38
|
+
continue;
|
|
39
|
+
const r = await api('POST', `${base}/database/tables/${encodeURIComponent(spec.name)}/columns`, col);
|
|
40
|
+
out.push(r.error ? { kind: 'column', name: `${spec.name}.${col.name}`, status: 'failed', error: r.error } : { kind: 'column', name: `${spec.name}.${col.name}`, status: 'created' });
|
|
41
|
+
if (!r.error)
|
|
42
|
+
tables.set(spec.name, r.data);
|
|
43
|
+
}
|
|
44
|
+
return out.length ? out : [{ kind: 'table', name: spec.name, status: 'exists' }];
|
|
45
|
+
}
|
|
46
|
+
async function ensureRealtime(table) {
|
|
47
|
+
const list = await api('GET', `${base}/realtime/tables`);
|
|
48
|
+
if (list.error)
|
|
49
|
+
return { kind: 'realtime', name: table, status: 'failed', error: list.error };
|
|
50
|
+
const row = list.data.find((t) => t.table === table);
|
|
51
|
+
if (!row)
|
|
52
|
+
return { kind: 'realtime', name: table, status: 'failed', error: { code: 'table_not_found', message: `There is no "${table}" table to turn realtime on for.`, status: 404 } };
|
|
53
|
+
if (row.enabled)
|
|
54
|
+
return { kind: 'realtime', name: table, status: 'exists' };
|
|
55
|
+
const r = await api('POST', `${base}/realtime/tables`, { table });
|
|
56
|
+
return r.error ? { kind: 'realtime', name: table, status: 'failed', error: r.error } : { kind: 'realtime', name: table, status: 'created' };
|
|
57
|
+
}
|
|
58
|
+
async function ensureBucket(spec) {
|
|
59
|
+
const out = [];
|
|
60
|
+
const list = await api('GET', `${base}/storage/buckets`);
|
|
61
|
+
if (list.error)
|
|
62
|
+
return [{ kind: 'bucket', name: spec.id, status: 'failed', error: list.error }];
|
|
63
|
+
if (list.data.some((b) => b.id === spec.id))
|
|
64
|
+
out.push({ kind: 'bucket', name: spec.id, status: 'exists' });
|
|
65
|
+
else {
|
|
66
|
+
const r = await api('POST', `${base}/storage/buckets`, { id: spec.id, public: spec.public ?? false, file_size_limit: spec.file_size_limit, allowed_mime_types: spec.allowed_mime_types });
|
|
67
|
+
if (r.error && r.error.code !== 'bucket_exists')
|
|
68
|
+
return [{ kind: 'bucket', name: spec.id, status: 'failed', error: r.error }];
|
|
69
|
+
out.push({ kind: 'bucket', name: spec.id, status: r.error ? 'exists' : 'created', detail: describeBucket(spec) });
|
|
70
|
+
}
|
|
71
|
+
if (spec.policies?.length) {
|
|
72
|
+
// Only add the rules to a bucket that has none: never replace rules someone already set.
|
|
73
|
+
const current = await api('GET', `${base}/storage/buckets/${encodeURIComponent(spec.id)}/policies`);
|
|
74
|
+
if (current.error)
|
|
75
|
+
out.push({ kind: 'policy', name: spec.id, status: 'failed', error: current.error });
|
|
76
|
+
else if (current.data.length)
|
|
77
|
+
out.push({ kind: 'policy', name: spec.id, status: 'exists' });
|
|
78
|
+
else {
|
|
79
|
+
for (const preset of spec.policies) {
|
|
80
|
+
const r = await api('POST', `${base}/storage/buckets/${encodeURIComponent(spec.id)}/policies`, { preset });
|
|
81
|
+
out.push(r.error ? { kind: 'policy', name: `${spec.id}: ${preset}`, status: 'failed', error: r.error } : { kind: 'policy', name: `${spec.id}: ${preset}`, status: 'created' });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
async function ensureForm(spec) {
|
|
88
|
+
const list = await api('GET', `${base}/forms`);
|
|
89
|
+
if (list.error) {
|
|
90
|
+
// No Forms API at that address: the starter falls back to its own table.
|
|
91
|
+
if (list.error.status === 404)
|
|
92
|
+
return { kind: 'form', name: spec.key, status: 'skipped', detail: 'forms are not available yet; the starter keeps messages in its own table' };
|
|
93
|
+
return { kind: 'form', name: spec.key, status: 'failed', error: list.error };
|
|
94
|
+
}
|
|
95
|
+
const found = list.data.forms.find((f) => f.key === spec.key);
|
|
96
|
+
if (found) {
|
|
97
|
+
if (spec.env)
|
|
98
|
+
env[spec.env] = found.id;
|
|
99
|
+
return { kind: 'form', name: spec.key, status: 'exists' };
|
|
100
|
+
}
|
|
101
|
+
const r = await api('POST', `${base}/forms`, { preset: spec.preset, name: spec.name, key: spec.key });
|
|
102
|
+
if (r.error)
|
|
103
|
+
return { kind: 'form', name: spec.key, status: 'failed', error: r.error };
|
|
104
|
+
if (spec.env)
|
|
105
|
+
env[spec.env] = r.data.id;
|
|
106
|
+
return { kind: 'form', name: spec.key, status: 'created' };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function describeColumns(spec) {
|
|
110
|
+
const auto = spec.preset === 'owner' || spec.preset === 'public_read' ? ['id', 'user_id', 'created_at'] : ['id', 'created_at'];
|
|
111
|
+
return [...auto, ...spec.columns.map((c) => c.name)].join(', ');
|
|
112
|
+
}
|
|
113
|
+
function describeBucket(spec) {
|
|
114
|
+
const parts = [spec.public ? 'public' : 'private'];
|
|
115
|
+
if (spec.file_size_limit)
|
|
116
|
+
parts.push(`${Math.round(spec.file_size_limit / 1024 / 1024)} MB max`);
|
|
117
|
+
if (spec.allowed_mime_types?.length)
|
|
118
|
+
parts.push(spec.allowed_mime_types.join(', '));
|
|
119
|
+
return parts.join(', ');
|
|
120
|
+
}
|
|
121
|
+
/** Tables the starter expects that the project lacks (e.g. an existing blank project for the SaaS starter). */
|
|
122
|
+
export async function missingTables(platform, ref, required) {
|
|
123
|
+
if (!required.length)
|
|
124
|
+
return [];
|
|
125
|
+
const r = await platform.request('GET', `/projects/${encodeURIComponent(ref)}/database/tables`);
|
|
126
|
+
if (r.error)
|
|
127
|
+
return null;
|
|
128
|
+
const have = new Set(r.data.map((t) => t.name));
|
|
129
|
+
return required.filter((t) => !have.has(t));
|
|
130
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// GENERATED: copied from packages/sdk/src/cli/ai.ts by scripts/sync-shared.mjs. Edit it there, then run `npm run sync`.
|
|
2
|
+
// `npx usebecky ai` (alias `skill`): teach AI coding assistants how to use usebecky.
|
|
3
|
+
// Copies the bundled skill (packages/sdk/skill/usebecky) into .claude/skills/usebecky/ and keeps a
|
|
4
|
+
// delimited usebecky section in AGENTS.md for Cursor, Codex, Copilot, Windsurf and others. The
|
|
5
|
+
// AGENTS.md rules fit the app: JavaScript, Swift (iOS), Kotlin (Android), or all of them.
|
|
6
|
+
// Pure functions over directories so they are easy to test.
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { detectProject } from "./framework.js";
|
|
11
|
+
export const SKILL_NAME = 'usebecky';
|
|
12
|
+
/** Where the skill is installed, relative to the project (forward slashes, for display). */
|
|
13
|
+
export const SKILL_TARGET = `.claude/skills/${SKILL_NAME}`;
|
|
14
|
+
export const AGENTS_FILE = 'AGENTS.md';
|
|
15
|
+
export const BLOCK_START = '<!-- usebecky:start -->';
|
|
16
|
+
export const BLOCK_END = '<!-- usebecky:end -->';
|
|
17
|
+
/**
|
|
18
|
+
* The skill ships at `<package>/skill/usebecky`. This file is `<package>/src/cli/ai.ts` in the repo
|
|
19
|
+
* and `<package>/dist/cli/ai.js` when installed, so look two levels up (and the levels between).
|
|
20
|
+
*/
|
|
21
|
+
export function findSkillSource(fromDir = path.dirname(fileURLToPath(import.meta.url))) {
|
|
22
|
+
let dir = path.resolve(fromDir);
|
|
23
|
+
for (let i = 0; i < 3; i++) {
|
|
24
|
+
const candidate = path.join(dir, 'skill', SKILL_NAME);
|
|
25
|
+
if (fs.existsSync(path.join(candidate, 'SKILL.md')))
|
|
26
|
+
return candidate;
|
|
27
|
+
const parent = path.dirname(dir);
|
|
28
|
+
if (parent === dir)
|
|
29
|
+
break;
|
|
30
|
+
dir = parent;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
/** Files under `dir`, as sorted relative paths with forward slashes. */
|
|
35
|
+
export function listFiles(dir) {
|
|
36
|
+
const out = [];
|
|
37
|
+
const walk = (rel) => {
|
|
38
|
+
for (const entry of fs.readdirSync(path.join(dir, rel), { withFileTypes: true })) {
|
|
39
|
+
if (entry.name.startsWith('.'))
|
|
40
|
+
continue;
|
|
41
|
+
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
42
|
+
if (entry.isDirectory())
|
|
43
|
+
walk(child);
|
|
44
|
+
else if (entry.isFile())
|
|
45
|
+
out.push(child);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
walk('');
|
|
49
|
+
return out.sort();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Copy every skill file into `<cwd>/.claude/skills/usebecky/`. Missing files are created and identical
|
|
53
|
+
* files left alone. A file that differs (edited by the user, or from another version) is only
|
|
54
|
+
* replaced with `force`; otherwise it is kept and reported.
|
|
55
|
+
*/
|
|
56
|
+
export function installSkill(source, cwd, force = false) {
|
|
57
|
+
const target = path.join(cwd, ...SKILL_TARGET.split('/'));
|
|
58
|
+
return listFiles(source).map((rel) => {
|
|
59
|
+
const display = `${SKILL_TARGET}/${rel}`;
|
|
60
|
+
const content = fs.readFileSync(path.join(source, ...rel.split('/')));
|
|
61
|
+
const dest = path.join(target, ...rel.split('/'));
|
|
62
|
+
if (!fs.existsSync(dest)) {
|
|
63
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
64
|
+
fs.writeFileSync(dest, content);
|
|
65
|
+
return { path: display, status: 'created' };
|
|
66
|
+
}
|
|
67
|
+
if (fs.readFileSync(dest).equals(content))
|
|
68
|
+
return { path: display, status: 'unchanged' };
|
|
69
|
+
if (!force)
|
|
70
|
+
return { path: display, status: 'kept' };
|
|
71
|
+
fs.writeFileSync(dest, content);
|
|
72
|
+
return { path: display, status: 'updated' };
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export const AGENTS_PLATFORMS = ['js', 'ios', 'android', 'any'];
|
|
76
|
+
export function agentsPlatformFor(project) {
|
|
77
|
+
if (project.kind === 'js')
|
|
78
|
+
return 'js';
|
|
79
|
+
if (project.kind === 'native' && project.native.platforms.length === 1)
|
|
80
|
+
return project.native.platforms[0];
|
|
81
|
+
return 'any';
|
|
82
|
+
}
|
|
83
|
+
const RULE_ACCESS = `Access rules first. Row Level Security is on for every table; without a policy, reads return no rows, inserts fail with \`permission_denied\` and updates/deletes silently change nothing. Write the table, its policies (usually \`user_id = auth.uid()\`) and the queries in the same change, and give the user the SQL to run.`;
|
|
84
|
+
function rulesFor(platform) {
|
|
85
|
+
const skill = `\`${SKILL_TARGET}/SKILL.md\``;
|
|
86
|
+
if (platform === 'ios') {
|
|
87
|
+
return {
|
|
88
|
+
intro: `This app uses usebecky (sign-in, Postgres database, access rules, file storage, realtime, Stripe payments, push notifications, forms, newsletter) through the native Swift package \`UseBecky\`. Before you write or change anything that touches sign-in, data, access rules, files, realtime or payments, read ${skill}, then \`${SKILL_TARGET}/references/ios.md\` (the Swift API). Use only the APIs documented there. Never add npm packages or JavaScript to this app.`,
|
|
89
|
+
rules: [
|
|
90
|
+
'Never put the secret key (`ub_sk_...`) in the app: anyone can read every value inside an app. The app uses only the Project URL and the publishable key (`ub_pk_...`): `let baas = UseBecky(url: "...", publishableKey: "ub_pk_...")`. Work that needs the secret key (sending push notifications or emails, admin tasks) runs on a server or in the dashboard.',
|
|
91
|
+
RULE_ACCESS,
|
|
92
|
+
'Every call is `try await` and throws `UseBeckyError` (`code`, `message`, `hint`). Always wrap calls in `do { ... } catch { ... }` and show `error.localizedDescription`; Swift calls do not return a `data`/`error` pair.',
|
|
93
|
+
'usebecky is not Supabase or Firebase. Use `baas.auth.signInWithApple()`, `baas.auth.signIn(email:password:)`, `baas.auth.signIn(with: .google, redirectTo:)`, `baas.from("notes").select().execute()` and `baas.realtime.subscribe(table:)`; never supabase-swift or Firebase APIs.',
|
|
94
|
+
'Social sign-in returns through a URL scheme equal to the bundle ID (`com.example.mynotes://auth`): register it under the target\'s URL Types and allow `com.example.mynotes://**` in Dashboard → Settings → General → Your app’s addresses. Offer Sign in with Apple first.',
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (platform === 'android') {
|
|
99
|
+
return {
|
|
100
|
+
intro: `This app uses usebecky (sign-in, Postgres database, access rules, file storage, realtime, Stripe payments, push notifications, forms, newsletter) through the native Kotlin SDK \`com.usebecky:usebecky-kotlin\`. Before you write or change anything that touches sign-in, data, access rules, files, realtime or payments, read ${skill}, then \`${SKILL_TARGET}/references/android.md\` (the Kotlin API). Use only the APIs documented there. Never add npm packages or JavaScript to this app.`,
|
|
101
|
+
rules: [
|
|
102
|
+
'Never put the secret key (`ub_sk_...`) in the app: anyone can read every value inside an app (the SDK refuses it with `secret_key_in_app`). The app uses only the Project URL and the publishable key (`ub_pk_...`). Work that needs the secret key (sending push notifications or emails, admin tasks) runs on a server or in the dashboard.',
|
|
103
|
+
RULE_ACCESS,
|
|
104
|
+
'Every call is a `suspend` function that throws `UseBeckyException` (`code`, `message`, `hint`). Always wrap calls in `try { ... } catch (e: UseBeckyException) { ... }`: an uncaught throw in a coroutine crashes the app. Kotlin calls do not return a `data`/`error` pair.',
|
|
105
|
+
'usebecky is not Supabase or Firebase. Use `baas.auth.signIn(email, password)`, `baas.auth.signInWithIdToken("google", idToken, rawNonce)` (Credential Manager), `baas.from("notes").select().list<Note>()` and `baas.realtime.subscribe("notes")`; never supabase-kt, Firebase Auth or Firestore APIs.',
|
|
106
|
+
'Social sign-in returns through a URL scheme equal to the application ID (`com.example.mynotes://auth`): add it to the intent filter and allow `com.example.mynotes://**` in Dashboard → Settings → General → Your app’s addresses. Offer Google sign-in with Credential Manager first.',
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const secret = 'Never expose the secret key. `ub_sk_...` / `USEBECKY_SECRET_KEY` stays in server code (`usebecky/server`); never put it in browser or mobile code or in a `NEXT_PUBLIC_`, `VITE_`, `PUBLIC_` or `EXPO_PUBLIC_` variable.';
|
|
111
|
+
const notSupabase = "usebecky is not Supabase. Use `auth.signIn`, `auth.signInWith('google')`, `auth.sendMagicLink` and `realtime.subscribe(table, options, callback)`; never supabase-js names such as `signInWithPassword`, `signInWithOAuth` or `channel().on('postgres_changes')`.";
|
|
112
|
+
const server = 'On the server, act as the user with `baas.as(req)` (RLS applies). Use `baas.admin` (bypasses RLS) only in trusted code, never to work around a missing policy.';
|
|
113
|
+
if (platform === 'js') {
|
|
114
|
+
return {
|
|
115
|
+
intro: `This app uses usebecky (auth, Postgres database, access rules, storage, realtime, Stripe payments, webhooks, push, forms, newsletter, emails) through the \`usebecky\` npm package. Before you write or change anything that touches sign-in, data, access rules, files, realtime, payments or webhooks, read ${skill} and the reference files it points to. Use only the APIs documented there.`,
|
|
116
|
+
rules: [
|
|
117
|
+
`${secret} Browser and app code uses \`createClient\` from \`usebecky\` with the publishable key.`,
|
|
118
|
+
RULE_ACCESS,
|
|
119
|
+
'JavaScript calls return `{ data, error }` and never throw. Check `error` before using `data`. (The Swift and Kotlin SDKs throw instead; see the skill.)',
|
|
120
|
+
notSupabase,
|
|
121
|
+
server,
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
intro: `This project uses usebecky (auth, Postgres database, access rules, storage, realtime, Stripe payments, webhooks, push, forms, newsletter, emails). Web, Node and Expo code use the \`usebecky\` npm package; iOS apps use the Swift package \`UseBecky\` (read \`${SKILL_TARGET}/references/ios.md\`); Android apps use the Kotlin SDK \`com.usebecky:usebecky-kotlin\` (read \`${SKILL_TARGET}/references/android.md\`). Before you write or change anything that touches sign-in, data, access rules, files, realtime, payments or webhooks, read ${skill} and the reference files it points to. Use only the APIs documented there. Never add npm packages to a Swift or Kotlin app.`,
|
|
127
|
+
rules: [
|
|
128
|
+
`${secret} Browsers and apps (Swift, Kotlin, Expo) use only the publishable key \`ub_pk_...\`.`,
|
|
129
|
+
RULE_ACCESS,
|
|
130
|
+
'Handle errors the way each SDK reports them. JavaScript: every call returns `{ data, error }` and never throws; check `error` before using `data`. Swift: calls throw `UseBeckyError`; always `do { try await ... } catch { ... }`. Kotlin: calls throw `UseBeckyException`; always `try { ... } catch (e: UseBeckyException) { ... }`.',
|
|
131
|
+
`${notSupabase} In Swift and Kotlin use the names in the iOS and Android references.`,
|
|
132
|
+
server,
|
|
133
|
+
],
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** The AGENTS.md section: where the skill is, plus the rules agents get wrong most often on this platform. */
|
|
137
|
+
export function agentsBlock(platform = 'any') {
|
|
138
|
+
const { intro, rules } = rulesFor(platform);
|
|
139
|
+
return `${BLOCK_START}
|
|
140
|
+
## Backend: usebecky
|
|
141
|
+
|
|
142
|
+
${intro}
|
|
143
|
+
|
|
144
|
+
Rules:
|
|
145
|
+
|
|
146
|
+
${rules.map((r, i) => `${i + 1}. ${r}`).join('\n')}
|
|
147
|
+
${BLOCK_END}`;
|
|
148
|
+
}
|
|
149
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
150
|
+
const BLOCK_RE = new RegExp(`${escapeRe(BLOCK_START)}[\\s\\S]*?${escapeRe(BLOCK_END)}`, 'g');
|
|
151
|
+
const DUPLICATE = '\u0000usebecky-duplicate\u0000';
|
|
152
|
+
/**
|
|
153
|
+
* Put `block` into AGENTS.md content: create it, append it, or replace the existing block in place
|
|
154
|
+
* (extra copies are removed, so it is never duplicated). A start marker without an end marker is
|
|
155
|
+
* `broken` and left alone, unless `force`, which replaces everything from the start marker on.
|
|
156
|
+
*/
|
|
157
|
+
export function mergeAgentsBlock(existing, block, force = false) {
|
|
158
|
+
if (existing === null)
|
|
159
|
+
return { content: `${block}\n`, status: 'created' };
|
|
160
|
+
const eol = existing.includes('\r\n') ? '\r\n' : '\n';
|
|
161
|
+
const ours = block.replace(/\r?\n/g, eol);
|
|
162
|
+
const matches = existing.match(BLOCK_RE);
|
|
163
|
+
if (!matches) {
|
|
164
|
+
const start = existing.indexOf(BLOCK_START);
|
|
165
|
+
if (start >= 0) {
|
|
166
|
+
if (!force)
|
|
167
|
+
return { content: existing, status: 'broken' };
|
|
168
|
+
return { content: `${existing.slice(0, start)}${ours}${eol}`, status: 'updated' };
|
|
169
|
+
}
|
|
170
|
+
const trimmed = existing.replace(/\s+$/, '');
|
|
171
|
+
return { content: trimmed ? `${trimmed}${eol}${eol}${ours}${eol}` : `${ours}${eol}`, status: 'appended' };
|
|
172
|
+
}
|
|
173
|
+
let seen = 0;
|
|
174
|
+
const content = existing
|
|
175
|
+
.replace(BLOCK_RE, () => (seen++ === 0 ? ours : DUPLICATE))
|
|
176
|
+
.replace(new RegExp(`(?:\\r?\\n)*${DUPLICATE}`, 'g'), '');
|
|
177
|
+
return { content, status: content === existing ? 'unchanged' : 'updated' };
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Create or update `<cwd>/AGENTS.md`. Writes only when something changed. The rules fit the app found
|
|
181
|
+
* in `cwd` (JavaScript, Swift, Kotlin, or all of them) unless `platform` is given.
|
|
182
|
+
*/
|
|
183
|
+
export function writeAgentsFile(cwd, force = false, platform = agentsPlatformFor(detectProject(cwd))) {
|
|
184
|
+
const file = path.join(cwd, AGENTS_FILE);
|
|
185
|
+
const existing = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : null;
|
|
186
|
+
const result = mergeAgentsBlock(existing, agentsBlock(platform), force);
|
|
187
|
+
if (result.status !== 'unchanged' && result.status !== 'broken')
|
|
188
|
+
fs.writeFileSync(file, result.content);
|
|
189
|
+
return { path: AGENTS_FILE, status: result.status, platform };
|
|
190
|
+
}
|
|
191
|
+
/** What to try first, printed after installing (web and Node apps). */
|
|
192
|
+
export const EXAMPLE_PROMPTS = [
|
|
193
|
+
'Add sign-in with Google and a private notes table',
|
|
194
|
+
'Let users upload a profile picture',
|
|
195
|
+
'Add a Pro plan with Stripe and hide premium pages from free users',
|
|
196
|
+
];
|
|
197
|
+
export function examplePromptsFor(platform) {
|
|
198
|
+
if (platform === 'ios')
|
|
199
|
+
return ['Add Sign in with Apple and a private notes list', 'Let users pick a profile photo and upload it', 'Add a newsletter sign-up to the settings screen'];
|
|
200
|
+
if (platform === 'android')
|
|
201
|
+
return ['Add Google sign-in with Credential Manager and a private notes list', 'Let users pick a profile photo and upload it', 'Add a newsletter sign-up to the settings screen'];
|
|
202
|
+
return EXAMPLE_PROMPTS;
|
|
203
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// GENERATED: copied from packages/extension/src/cli/skill.ts by scripts/sync-shared.mjs. Edit it there, then run `npm run sync`.
|
|
2
|
+
// The usebecky-extension AI skill: copied into .claude/skills/usebecky-extension/ (Claude Code loads it
|
|
3
|
+
// by itself) plus a short delimited section in AGENTS.md (Cursor, Codex, Copilot, Windsurf...).
|
|
4
|
+
// Used by `npx @usebecky/extension ai` and, as a generated copy, by create-usebecky's extension starter
|
|
5
|
+
// (packages/create-usebecky/scripts/sync-shared.mjs). Keep it self-contained: node:* imports only.
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
export const EXTENSION_SKILL_NAME = 'usebecky-extension';
|
|
10
|
+
export const EXTENSION_SKILL_TARGET = `.claude/skills/${EXTENSION_SKILL_NAME}`;
|
|
11
|
+
const AGENTS_FILE = 'AGENTS.md';
|
|
12
|
+
const START = '<!-- usebecky-extension:start -->';
|
|
13
|
+
const END = '<!-- usebecky-extension:end -->';
|
|
14
|
+
/** `<package>/skill/usebecky-extension`, looked up from this file (src/cli or dist/cli) upwards. */
|
|
15
|
+
export function findExtensionSkill(fromDir = path.dirname(fileURLToPath(import.meta.url))) {
|
|
16
|
+
let dir = path.resolve(fromDir);
|
|
17
|
+
for (let i = 0; i < 4; i++) {
|
|
18
|
+
const candidate = path.join(dir, 'skill', EXTENSION_SKILL_NAME);
|
|
19
|
+
if (fs.existsSync(path.join(candidate, 'SKILL.md')))
|
|
20
|
+
return candidate;
|
|
21
|
+
const parent = path.dirname(dir);
|
|
22
|
+
if (parent === dir)
|
|
23
|
+
break;
|
|
24
|
+
dir = parent;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
function listFiles(dir) {
|
|
29
|
+
const out = [];
|
|
30
|
+
const walk = (rel) => {
|
|
31
|
+
for (const entry of fs.readdirSync(path.join(dir, rel), { withFileTypes: true })) {
|
|
32
|
+
if (entry.name.startsWith('.'))
|
|
33
|
+
continue;
|
|
34
|
+
const child = rel ? `${rel}/${entry.name}` : entry.name;
|
|
35
|
+
if (entry.isDirectory())
|
|
36
|
+
walk(child);
|
|
37
|
+
else if (entry.isFile())
|
|
38
|
+
out.push(child);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
walk('');
|
|
42
|
+
return out.sort();
|
|
43
|
+
}
|
|
44
|
+
/** Copy the skill. Files you changed are kept unless `force`. */
|
|
45
|
+
export function installExtensionSkill(source, cwd, force = false) {
|
|
46
|
+
const target = path.join(cwd, ...EXTENSION_SKILL_TARGET.split('/'));
|
|
47
|
+
return listFiles(source).map((rel) => {
|
|
48
|
+
const shown = `${EXTENSION_SKILL_TARGET}/${rel}`;
|
|
49
|
+
const content = fs.readFileSync(path.join(source, ...rel.split('/')));
|
|
50
|
+
const dest = path.join(target, ...rel.split('/'));
|
|
51
|
+
if (!fs.existsSync(dest)) {
|
|
52
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
53
|
+
fs.writeFileSync(dest, content);
|
|
54
|
+
return { path: shown, status: 'created' };
|
|
55
|
+
}
|
|
56
|
+
if (fs.readFileSync(dest).equals(content))
|
|
57
|
+
return { path: shown, status: 'unchanged' };
|
|
58
|
+
if (!force)
|
|
59
|
+
return { path: shown, status: 'kept' };
|
|
60
|
+
fs.writeFileSync(dest, content);
|
|
61
|
+
return { path: shown, status: 'updated' };
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export function extensionAgentsBlock() {
|
|
65
|
+
return `${START}
|
|
66
|
+
## usebecky extension
|
|
67
|
+
|
|
68
|
+
This folder is an extension for the usebecky store, built with \`@usebecky/extension\`. Before you change anything about installing, OAuth, tokens, webhooks, the partner API, pages inside usebecky or \`usebecky-extension.json\`, read \`${EXTENSION_SKILL_TARGET}/SKILL.md\` and the references it points to.
|
|
69
|
+
|
|
70
|
+
Rules:
|
|
71
|
+
|
|
72
|
+
1. Use the kit for OAuth, tokens and webhooks (\`createExtension\`, \`oauthHandlers\`, \`webhookHandler\`). Never write your own signature checks, PKCE or token refresh.
|
|
73
|
+
2. Secrets (client secret, webhook secret, tokens) live in environment variables and the token store, never in code, logs, URLs or the browser.
|
|
74
|
+
3. Verify every webhook with the kit before you trust it, and delete what you stored for a project on \`extension.uninstalled\`.
|
|
75
|
+
4. Ask for the fewest scopes that work; describe every one of them in \`data_shared\` in plain words.
|
|
76
|
+
5. Pages, menu rows, dashboards and settings inside usebecky are blocks answered from \`ext.uiHandler\` (listing \`ui\`): usebecky draws them in its own design. Never HTML, CSS, scripts or an iframe for usebecky. Your own web pages use usebecky's look with your own name and logo.
|
|
77
|
+
6. Test with \`npm run dev\` (a pretend usebecky) and run \`npx @usebecky/extension validate\` before you submit.
|
|
78
|
+
${END}`;
|
|
79
|
+
}
|
|
80
|
+
/** Create or update the usebecky-extension section of AGENTS.md (other sections are left alone). */
|
|
81
|
+
export function writeExtensionAgents(cwd) {
|
|
82
|
+
const file = path.join(cwd, AGENTS_FILE);
|
|
83
|
+
const block = extensionAgentsBlock();
|
|
84
|
+
if (!fs.existsSync(file)) {
|
|
85
|
+
fs.writeFileSync(file, `${block}\n`);
|
|
86
|
+
return { path: AGENTS_FILE, status: 'created' };
|
|
87
|
+
}
|
|
88
|
+
const existing = fs.readFileSync(file, 'utf8');
|
|
89
|
+
const start = existing.indexOf(START);
|
|
90
|
+
const end = existing.indexOf(END);
|
|
91
|
+
let content;
|
|
92
|
+
let status;
|
|
93
|
+
if (start >= 0) {
|
|
94
|
+
// A start marker without its end (edited by hand): our section runs to the end of the file.
|
|
95
|
+
const stop = end > start ? end + END.length : existing.length;
|
|
96
|
+
content = existing.slice(0, start) + block + (end > start ? existing.slice(stop) : '\n');
|
|
97
|
+
status = content === existing ? 'unchanged' : 'updated';
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const trimmed = existing.replace(/\s+$/, '');
|
|
101
|
+
content = `${trimmed ? `${trimmed}\n\n` : ''}${block}\n`;
|
|
102
|
+
status = 'appended';
|
|
103
|
+
}
|
|
104
|
+
if (status !== 'unchanged')
|
|
105
|
+
fs.writeFileSync(file, content);
|
|
106
|
+
return { path: AGENTS_FILE, status };
|
|
107
|
+
}
|