@vibes.diy/prompts 14.3.341 → 14.3.343

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/cli-footer.md CHANGED
@@ -10,6 +10,7 @@
10
10
  ### Other Commands
11
11
 
12
12
  - Name the app as `handle/app-slug` on every command (a bare slug falls back to your default handle — fine at a terminal, never in a script or agent)
13
+ - `npx vibes-diy push --vibe <handle>/<app-slug> --title "Potluck Sign-up"` — name a new app; the tab, share cards and emails show it (it never renames an app that already has a name)
13
14
  - `npx vibes-diy push --vibe <handle>/<app-slug> --access gated` — deploy so anyone can view but only members write (`open` is the default, `private` is members-only)
14
15
  - `npx vibes-diy push --vibe <handle>/<app-slug> --access private` — deploy for you and the members you invite, and nobody else
15
16
  - `npx vibes-diy push --handle <handle> --app-slug other-name` — deploy to a different app slug instead of the directory name
package/llms/backend.md CHANGED
@@ -1181,15 +1181,61 @@ if (url.pathname === "/feed-token" && request.method === "POST") {
1181
1181
  await ctx.db.put({ type: "feedToken", ownerHandle: me }, { db: "planner", id: "feedToken:" + token });
1182
1182
  return json({ ok: true, token });
1183
1183
  }
1184
+ if (url.pathname === "/feed-token/revoke" && request.method === "POST") {
1185
+ const me = ctx.userInfo?.userHandle;
1186
+ if (!me) return json({ ok: false, reason: "sign in to change a feed link" }, 401);
1187
+ const { token } = await request.json();
1188
+ const grant = await ctx.db.get("feedToken:" + token, { db: "planner" });
1189
+ if (grant?.type !== "feedToken" || grant.ownerHandle !== me) return json({ ok: false, reason: "your own feed links" }, 403);
1190
+ await ctx.db.delete("feedToken:" + token, { db: "planner" }); // the link drains on its next refresh
1191
+ return json({ ok: true });
1192
+ }
1184
1193
  if (url.pathname === "/feed.ics") {
1185
1194
  const token = url.searchParams.get("t") ?? "";
1186
1195
  const grant = token ? await ctx.db.get("feedToken:" + token, { db: "planner" }) : null;
1187
1196
  if (grant?.type !== "feedToken") return new Response("not found", { status: 404 });
1188
1197
  const rows = await ctx.db.query({ db: "planner", field: "ownerHandle", key: grant.ownerHandle, limit: 200 });
1189
- return new Response(toIcs(rows), { headers: { "content-type": "text/calendar" } });
1198
+ const work = rows.filter((row) => row.type === "assignment");
1199
+ return new Response(toIcs(work), { headers: { "content-type": "text/calendar" } });
1200
+ }
1201
+ ```
1202
+
1203
+ The token is drawn in the route, so the server chose it for the person it names.
1204
+ Every token record is one the route wrote, at an id made from fresh
1205
+ randomness, so a link one person shares with a friend stays theirs. In
1206
+ `access.js` the token type admits only the route, names its writer, is kept
1207
+ or revoked whole (the revoke route deletes it), and sits on its owner's private
1208
+ channel; each assignment names its writer the same way, and ids that start
1209
+ `feedToken:` hold feed links alone:
1210
+
1211
+ ### `access.js`
1212
+ ```js partial
1213
+ if (doc.type === "feedToken") {
1214
+ ctx.requireBackend("fetch"); // only the /feed-token route mints one
1215
+ if (!user?.userHandle || doc.ownerHandle !== user.userHandle) throw { forbidden: "a feed link is its owner's" };
1216
+ // Kept or revoked whole: the revoke route's delete passes, an edit is refused. A repair goes through admin mode.
1217
+ if (oldDoc && !doc._deleted) throw { forbidden: "a feed link is kept or revoked whole" };
1218
+ const mine = "user:" + user.userHandle;
1219
+ return { channels: [mine], grant: { users: { [user.userHandle]: [mine] } } };
1220
+ }
1221
+ if (String(doc._id ?? "").startsWith("feedToken:")) throw { forbidden: "feedToken: ids hold feed links" };
1222
+ if (doc.type === "assignment") {
1223
+ if (!user?.userHandle || doc.ownerHandle !== user.userHandle) throw { forbidden: "your own assignments" };
1224
+ if (oldDoc && oldDoc.ownerHandle !== user.userHandle) throw { forbidden: "your own assignments" };
1225
+ const mine = "user:" + user.userHandle;
1226
+ return { channels: [mine], grant: { users: { [user.userHandle]: [mine] } } };
1190
1227
  }
1191
1228
  ```
1192
1229
 
1230
+ A link for one record a person keeps, such as one student on a parent's or a
1231
+ teacher's list, comes from the same route with that record's id in the body
1232
+ (`{ recordId }`). The route reads the record, mints when its `ownerHandle`
1233
+ equals `me`, and saves `{ type: "feedToken", ownerHandle: me, recordId }`. The
1234
+ feed serves the assignments whose `recordId` and `ownerHandle` both match the
1235
+ token record,
1236
+ so each link shows one student's work as the person who keeps that student
1237
+ entered it.
1238
+
1193
1239
  OAuth state ties the user who starts the flow to the user who finishes it.
1194
1240
  A visitor's own account on another service is a connection first (the
1195
1241
  `connections` skill), and the platform holds that flow end to end. A flow the
package/llms/calendar.md CHANGED
@@ -145,9 +145,10 @@ after a deploy and the first one after a token is minted.
145
145
  ## The architecture (each piece is load-bearing)
146
146
 
147
147
  Calendar clients (iPhone, Google) refresh subscriptions with **anonymous
148
- GETs** — no login, no headers you control. An anonymous `fetch` handler cannot
149
- read the app's databases (anonymous `ctx.db.query` is denied, and the `fetch`
150
- lane can't query access-fn-bound databases at all). So:
148
+ GETs** — no login, no headers you control. A `fetch` handler reads a bound
149
+ database as its caller: the signed-in page's `apiFetch` call (the mint route
150
+ below) reads that person's own records, and an anonymous GET reads none of
151
+ them. So:
151
152
 
152
153
  1. **A `scheduled` tick aggregates; the `fetch` lane serves.** `scheduled`
153
154
  runs as the owner in admin mode and CAN read everything. Every minute it
@@ -158,21 +159,36 @@ lane can't query access-fn-bound databases at all). So:
158
159
  2. **The URL carries a per-user RANDOM TOKEN — a capability, not a handle.**
159
160
  Subscription URLs are unauthenticated and long-lived; a handle-keyed URL
160
161
  (`?u=<handle>`) is guessable, which silently makes every user's items
161
- world-readable. Instead, MINT the token LOCALLY: the first time the
162
- user opens the calendar surface with subscribable content, generate a
163
- `crypto.getRandomValues` token client-side and put a `caltoken` doc
164
- `{ type: "caltoken", userId, token }`, kept PRIVATE by the access function
165
- (owner-only channel, like notes — the token IS the secret; the scheduled
166
- lane reads it regardless). Local minting makes the URL available instantly
167
- (the optimistic write reaches the live query before the click finishes),
168
- and it stays **opt-in**: users who never open that surface get no token
169
- and no ics aggregate — the scheduled tick must skip aggregating any user
170
- without a token. The URL is `?t=<token>&n=<handle>` (`n` is a validated
162
+ world-readable. Instead, the backend mints the token for the person
163
+ asking.
164
+ The feed token is minted by a signed-in route in `backend.js`. The first
165
+ time the user opens the calendar surface with subscribable content, the
166
+ page calls `POST /caltoken` through `apiFetch`; the route reads the caller
167
+ from `ctx.userInfo`, reads `caltoken-<handle>` first and answers with the
168
+ token kept there, so phones already subscribed keep their link. Only when
169
+ there is none (or the person pressed "New link", `{ rotate: true }`) does
170
+ it draw a token from `crypto.getRandomValues` and save
171
+ `{ type: "caltoken", userId: me, token }` at `caltoken-<handle>`. Ids that
172
+ start `caltoken-` hold calendar links alone, so every other branch of
173
+ `access.js` keeps them for that.
174
+ `access.js` admits a `caltoken` only from that route
175
+ (`ctx.requireBackend("fetch")`) with `userId` equal to the writer, on the
176
+ owner's PRIVATE channel (like notes — the token IS the secret; the
177
+ scheduled lane reads it regardless). So every token is fresh randomness the
178
+ server drew for the person it names, and a link one person shares with a
179
+ friend stays theirs alone. The route answers with the token, so the URL
180
+ shows as soon as the press settles, and it stays **opt-in**: users who
181
+ never open that surface get no token and no ics aggregate — the scheduled
182
+ tick must skip aggregating any user without a token. Every item the tick
183
+ files under a person is one `access.js` checked they wrote
184
+ (`doc.userId === user.userHandle`), so each feed holds that person's own
185
+ items. The URL is `?t=<token>&n=<handle>` (`n` is a validated
171
186
  DISPLAY label only — iOS captures the calendar name at subscribe time,
172
187
  often before the tick has learned a fresh token; the token alone gates
173
188
  data): unguessable, shareable on purpose (handing out the link is the
174
- sharing feature), and revocable — delete the token doc and the feed drains
175
- on the next refresh. Because the token maps to the user (not to item ids),
189
+ sharing feature), and renewable — a "New link" press asks the route with
190
+ `{ rotate: true }`, it draws a fresh token in place, and the old link
191
+ drains on the next refresh. Because the token maps to the user (not to item ids),
176
192
  the feed is still LIVE: new items reach every subscriber automatically.
177
193
  Never let private types (notes, drafts) enter the aggregation.
178
194
  3. **Never answer a subscription GET with an error or emptiness you can
@@ -224,33 +240,38 @@ lane can't query access-fn-bound databases at all). So:
224
240
 
225
241
  ## The UI
226
242
 
227
- The token is auto-minted when the calendar surface opens, so the Subscribe
243
+ The token is minted when the calendar surface opens, so the Subscribe
228
244
  button is simply there once the user has subscribable content.
229
245
 
230
246
  ⚠️ Read the token from its OWN live query on `type: "caltoken"` (as below). A
231
247
  `caltoken` doc never appears in your items/favorites query — looking for it
232
- there means the Subscribe link never renders, even though the mint effect and
248
+ there means the Subscribe link never renders, even though the mint route and
233
249
  the feed itself work.
234
250
 
235
251
  ### `App.jsx`
236
252
  ```jsx app=calendar-feed
237
- // access.js needs a `caltoken` branch routing the doc to the owner's PRIVATE
238
- // channel (like notes) — the token is the secret.
253
+ // `apiFetch` comes from use-vibes: the route runs as the signed-in person.
239
254
  const { docs: calTokens } = useLiveQuery(byTypeUser, { key: ["caltoken", me.userHandle] });
240
- const calToken = calTokens[0]?.token || null;
255
+ const [mintedToken, setMintedToken] = useState(null);
256
+ const [asked, setAsked] = useState(false);
257
+ const calToken = mintedToken || calTokens[0]?.token || null;
258
+ // The route answers with the person's kept token, or a fresh one when they have none.
259
+ const askForLink = (rotate) =>
260
+ apiFetch("/caltoken", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ rotate }) })
261
+ .then((res) => (res.ok ? res.json() : null))
262
+ .then((body) => body?.token && setMintedToken(body.token))
263
+ .catch(() => {}); // asked stays true: the next visit to this view asks again
241
264
  useEffect(() => {
242
- // Local minting on first visit to this view with content: the URL is ready
243
- // instantly (optimistic write), and users who never come here never get a
244
- // token. Until the backend tick learns the token (≤1m), the endpoint serves
245
- // a valid placeholder calendar, so even an immediate subscribe can't fail.
246
- if (!signedIn || myItems.length === 0 || calToken) return;
247
- const b = new Uint8Array(16);
248
- crypto.getRandomValues(b);
249
- let bin = "";
250
- for (const x of b) bin += String.fromCharCode(x);
251
- const token = btoa(bin).replace(/[+]/g, "-").replace(/[/]/g, "_").replace(/=+$/, "");
252
- database.put({ _id: `caltoken-${me.userHandle}`, type: "caltoken", userId: me.userHandle, token, createdAt: Date.now() }).catch(() => {});
253
- }, [signedIn, myItems.length, calToken]);
265
+ // The route mints on the first visit to this view with content, and users
266
+ // who never come here never get a token. Until the backend tick learns the
267
+ // token (≤1m), the endpoint serves a valid placeholder calendar, so even an
268
+ // immediate subscribe can't fail.
269
+ if (!signedIn || myItems.length === 0 || calToken || asked) return;
270
+ setAsked(true);
271
+ askForLink(false);
272
+ }, [signedIn, myItems.length, calToken, asked]);
273
+ // "New link" draws a fresh token in place; the old link drains on the next refresh.
274
+ {calToken && <Button onClick={() => askForLink(true)}>New link</Button>}
254
275
  // The feed lives at the app's public address, which also serves backend.js:
255
276
  // https://vibes.diy/vibe/<handle>/<app>/_api/faves.ics. The app's own host,
256
277
  // `<app>--<handle>.…`, names both in its first label.
@@ -364,6 +385,19 @@ export async function scheduled(event, ctx) {
364
385
 
365
386
  export async function fetch(request, ctx) {
366
387
  const url = new URL(request.url);
388
+ if (url.pathname === "/caltoken" && request.method === "POST") {
389
+ // The signed-in person's own token: the kept one, or one drawn here and saved under their handle.
390
+ const me = ctx.userInfo?.userHandle;
391
+ if (!me) return Response.json({ ok: false, reason: "sign in to make a calendar link" }, { status: 401 });
392
+ const { rotate } = await request.json().catch(() => ({}));
393
+ const kept = await ctx.db.get(`caltoken-${me}`, { db: "items" });
394
+ // Phones already subscribed keep their link until the person presses New link.
395
+ if (!rotate && kept?.type === "caltoken" && kept.userId === me) return Response.json({ ok: true, token: kept.token });
396
+ const b = crypto.getRandomValues(new Uint8Array(16));
397
+ const token = btoa(String.fromCharCode(...b)).replace(/[+]/g, "-").replace(/[/]/g, "_").replace(/=+$/, "");
398
+ await ctx.db.put({ type: "caltoken", userId: me, token, createdAt: Date.now() }, { db: "items", id: `caltoken-${me}` });
399
+ return Response.json({ ok: true, token });
400
+ }
367
401
  if (url.pathname !== "/faves.ics") return new Response("not found", { status: 404 });
368
402
  if (request.method !== "GET" && request.method !== "HEAD")
369
403
  return new Response("method not allowed", { status: 405, headers: { allow: "GET" } });
@@ -388,6 +422,38 @@ export async function fetch(request, ctx) {
388
422
  }
389
423
  ```
390
424
 
425
+ `access.js` holds both halves of the feed: a `caltoken` comes only from the
426
+ mint route, sits at its owner's own `caltoken-<handle>` id and names its
427
+ writer, and a `favorite` names its writer too and lives at an id of its own,
428
+ so the tick files each person's own picks under each person's own token:
429
+
430
+ ### `access.js`
431
+ ```js app=calendar-feed
432
+ export function items(doc, oldDoc, user, ctx) {
433
+ if (oldDoc && oldDoc.type !== doc.type) throw { forbidden: "a record keeps its type" };
434
+ // Ids that start `caltoken-` hold calendar links alone.
435
+ const linkId = String(doc._id ?? "").startsWith("caltoken-");
436
+ if (doc.type === "caltoken") {
437
+ ctx.requireBackend("fetch"); // only the /caltoken route mints one
438
+ if (!user?.userHandle || doc.userId !== user.userHandle) throw { forbidden: "a calendar link is its owner's" };
439
+ if (doc._id !== "caltoken-" + user.userHandle) throw { forbidden: "a calendar link sits at its owner's id" };
440
+ const mine = "user:" + user.userHandle;
441
+ return { channels: [mine], grant: { users: { [user.userHandle]: [mine] } } };
442
+ }
443
+ if (linkId) throw { forbidden: "caltoken- ids hold calendar links" };
444
+ if (doc.type === "favorite") {
445
+ if (!user?.userHandle) throw { forbidden: "sign in" };
446
+ if (doc.userId !== user.userHandle) throw { forbidden: "a pick is its picker's" };
447
+ if (oldDoc && oldDoc.userId !== user.userHandle) throw { forbidden: "a pick is its picker's" };
448
+ const mine = "user:" + user.userHandle;
449
+ return { channels: [mine], grant: { users: { [user.userHandle]: [mine] } } };
450
+ }
451
+ throw { forbidden: "unknown document type" };
452
+ }
453
+
454
+ // Summary: each person's picks and calendar link are theirs alone. A favorite carries its picker's handle in userId, and a caltoken, minted by the backend's /caltoken route, carries its owner's handle in userId.
455
+ ```
456
+
391
457
  If items should track a live external events API, add the join inside `fetch`:
392
458
  fetch the API window with `globalThis.fetch`, key rows by the same item id,
393
459
  prefer the live row over the stored snapshot, skip items the API marks
package/llms/index.d.ts CHANGED
@@ -46,6 +46,7 @@ export { spotifyConfig } from "./spotify.js";
46
46
  export { squareConfig } from "./square.js";
47
47
  export { stripeConfig } from "./stripe.js";
48
48
  export { stripeSubscriptionsConfig } from "./stripe-subscriptions.js";
49
+ export { memberAreaConfig } from "./member-area.js";
49
50
  export { blocklyConfig } from "./blockly.js";
50
51
  export { strudelConfig } from "./strudel.js";
51
52
  export { hydraConfig } from "./hydra.js";
@@ -86,7 +87,7 @@ export { uiTestimonialsConfig } from "./ui-testimonials.js";
86
87
  export type { LlmConfig, SkillCredential, SkillEgress } from "./types.js";
87
88
  export { cueMatches, cueMatchedSkills, type CueCatalogEntry } from "./cues.js";
88
89
  export { dropCoveredSkills, expandSkills, onSkillMenu, skillGraphProblems, universalSkillNames, type NeedsCatalogEntry } from "./needs.js";
89
- export declare const allConfigs: readonly [LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig];
90
+ export declare const allConfigs: readonly [LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig, LlmConfig];
90
91
  export { mapsConfig } from "./maps.js";
91
92
  export declare const SKILL_ALIASES: ReadonlyMap<string, string>;
92
93
  export declare function canonicalSkillName(name: string): string;
package/llms/index.js CHANGED
@@ -46,6 +46,7 @@ import { spotifyConfig } from "./spotify.js";
46
46
  import { squareConfig } from "./square.js";
47
47
  import { stripeConfig } from "./stripe.js";
48
48
  import { stripeSubscriptionsConfig } from "./stripe-subscriptions.js";
49
+ import { memberAreaConfig } from "./member-area.js";
49
50
  import { blocklyConfig } from "./blockly.js";
50
51
  import { strudelConfig } from "./strudel.js";
51
52
  import { hydraConfig } from "./hydra.js";
@@ -130,6 +131,7 @@ export { spotifyConfig } from "./spotify.js";
130
131
  export { squareConfig } from "./square.js";
131
132
  export { stripeConfig } from "./stripe.js";
132
133
  export { stripeSubscriptionsConfig } from "./stripe-subscriptions.js";
134
+ export { memberAreaConfig } from "./member-area.js";
133
135
  export { blocklyConfig } from "./blockly.js";
134
136
  export { strudelConfig } from "./strudel.js";
135
137
  export { hydraConfig } from "./hydra.js";
@@ -214,6 +216,7 @@ export const allConfigs = [
214
216
  stripeConfig,
215
217
  stripeSubscriptionsConfig,
216
218
  squareConfig,
219
+ memberAreaConfig,
217
220
  groupPlanConfig,
218
221
  vibeToolsConfig,
219
222
  blocklyConfig,
@@ -56,7 +56,8 @@ already wears a look (an earlier reskin's CSS string and the wrapper element
56
56
  it scopes, or an earlier `THEME_CSS`) trades it for the new block in the same
57
57
  pass: the new `THEME_CSS` takes that string's place, its `<style>` element and
58
58
  wrapper go with it, and the ornament it drew (a texture, a glow, a heading prefix,
59
- letter-spaced capitals) gives way to what the new style asks for. The app
59
+ letter-spaced capitals, stripes, borders, a hard shadow) and the plain elements it
60
+ added (a title bar, a menu strip) give way to what the new style asks for. The app
60
61
  then carries one stylesheet of its own, the block above.
61
62
 
62
63
  ### The variables
@@ -0,0 +1,2 @@
1
+ import type { LlmConfig } from "./types.js";
2
+ export declare const memberAreaConfig: LlmConfig;
@@ -0,0 +1,19 @@
1
+ export const memberAreaConfig = {
2
+ name: "member-area",
3
+ label: "Member area with tiers",
4
+ description: "A member area with TIERS on top of a payment recipe — gold and platinum, supporter levels, a top tier that gets the owner's own tools — for a creator's audience from YouTube, a newsletter or a community: load it beside stripe-subscriptions (renewing, the default), square (when the person names Square) or stripe (dues or a season pass), never on its own, and only when the person asks for tiers, a members' discussion or members-only tools. Each tier is an owner-written plan record with a rank, copied onto the membership by backend.js; a member of rank N holds channels tier-1 through tier-N while entitled; every post, room and message names its lowest tier in minRank; members post in rooms their tier reads, checked with ctx.requireAccess in access.js; members-only tools run in backend.js and answer 403 below the tool's rank before ctx.callAI; on Square or a one-time Stripe charge a tier is a pass whose paidThrough each paid order moves forward. One database for memberships, plans, posts, rooms and messages. A single members-only feed with one price and no tiers, discussion or tools is stripe-subscriptions alone",
5
+ cues: [
6
+ "member area",
7
+ "members area",
8
+ "members' area",
9
+ "membership tiers",
10
+ "tiers",
11
+ "gold and platinum",
12
+ "supporter tiers",
13
+ "patron tiers",
14
+ "members-only discussion",
15
+ "members only discussion",
16
+ "members-only tools",
17
+ "community for my subscribers",
18
+ ],
19
+ };
@@ -0,0 +1,212 @@
1
+ # Member area — tiers, a members' discussion, and members-only tools
2
+
3
+ When someone asks for a **member area with tiers** — gold and platinum for a
4
+ YouTube audience, supporter levels for a newsletter, a community where the top
5
+ tier gets the owner's own tools — build the layer this page teaches on top of
6
+ a payment recipe. The payment recipe decides *who paid and until when*; this
7
+ page decides *what each tier opens*: a ladder of tiers, a discussion members
8
+ post in, and tools that only a tier's members can run.
9
+
10
+ **This page sits on a payment recipe, and it works the same on each one.**
11
+
12
+ - **Stripe, renewing** (the default, and what "a month", "subscribe" or "a
13
+ membership" means): the `stripe-subscriptions` recipe. Stripe renews and
14
+ retries, and its status plus the grace period is the entitlement.
15
+ - **Square** ("I sell on Square", "with my Square account"): the `square`
16
+ recipe, which takes one payment at a time. A tier is a **pass**: the member
17
+ buys a month (or a year) and buys the next one when it runs out (§ 6).
18
+ - **Stripe, once** (annual dues, a season pass with no renewal): the `stripe`
19
+ recipe, with the same pass shape as Square.
20
+
21
+ Whichever it is, the payment recipe keeps its own rules word for word — its
22
+ setup items, its read-back, its sweep, its mode. This page adds a field to its
23
+ plan record, a field to its membership record, and the records the member
24
+ area holds. Nothing here talks to a payment provider.
25
+
26
+ **One database.** Grants are reduced per database, so the membership records,
27
+ the plans, the posts, the rooms and the messages all live in the payment
28
+ recipe's one database (`club` in `stripe-subscriptions`), and one access
29
+ function handles every type. A discussion kept in a second database would
30
+ grant a paying member a channel no message is on.
31
+
32
+ **The owner names the tiers.** The app's code writes no tier names and no
33
+ prices: "Gold" and "Platinum" are plan records the owner creates on the
34
+ **Plans** screen, and the page shows each plan's own title. Asking the builder
35
+ for "a gold tier at $5 and a platinum tier at $15" writes those two records,
36
+ the same ones the screen does.
37
+
38
+ ## 1. A tier is a plan with a rank
39
+
40
+ Each tier is a plan with a rank the owner sets — 1 for the first tier, 2 for the one above it — and the membership carries the rank of the plan it was settled for, copied by backend.js from the plan record, never sent by the browser.
41
+
42
+ - The plan record gains `rank`, a whole number from 1 to `MAX_RANK` (5). The
43
+ **Plans** screen shows it as "Tier 1, 2, 3" beside the title, and `access.js`
44
+ checks it with the plan's price and interval. Two plans may share a rank —
45
+ a monthly and a yearly Gold are both rank 1.
46
+ - The route that opens checkout (`/subscribe` in `stripe-subscriptions`, the
47
+ pass checkout in § 6) copies `rank` from the plan record onto the pending
48
+ membership beside the price, exactly as it copies the amount. The browser
49
+ names a plan; the rank, like the price, is the server's reading of it.
50
+ - `access.js` checks a new membership's `rank` is a whole number from 1 to
51
+ `MAX_RANK`, and every later change of it goes through `ctx.requireBackend()`
52
+ with the rest of the membership.
53
+
54
+ ## 2. A higher tier opens everything below it
55
+
56
+ A member of rank N holds every tier channel from tier-1 to tier-N, so a higher tier opens everything below it: the access function grants them from the membership record's rank while it is entitled.
57
+
58
+ ```js
59
+ const MAX_RANK = 5;
60
+ // tier-1 … tier-<rank>: Platinum (rank 2) reads Gold's posts and its own.
61
+ const tiersUpTo = (rank) => Array.from({ length: Math.min(rank, MAX_RANK) }, (_, i) => `tier-${i + 1}`);
62
+ ```
63
+
64
+ The membership case of the access function grants `tiersUpTo(doc.rank)` in
65
+ place of the single `members` channel the payment recipe grants, and only
66
+ while `doc.entitled === true`; the rewrite that says otherwise takes every
67
+ tier away on the next sync. The owner holds every tier through the role grant
68
+ (`roles: { owner: tiersUpTo(MAX_RANK) }`), so the owner reads every room.
69
+
70
+ The page reads the same facts for display: `access.hasChannel("tier-2")`
71
+ shows the Platinum room's door open, and a Gold member sees it with
72
+ "Platinum members" and the Join button for that plan. Display never decides
73
+ access; the grant does.
74
+
75
+ ## 3. Every members-only thing names its lowest tier
76
+
77
+ Every members-only document — a post, a room, a message, a file — names the lowest tier that reads it in minRank, and the access function routes it to that tier's channel.
78
+
79
+ - A **post** the owner writes carries `minRank` (0 for public): the access
80
+ function checks `ctx.requireRole("owner")` and routes it to
81
+ `minRank > 0 ? \`tier-${minRank}\` : "public"`. The owner's post form picks
82
+ the tier from the plans that exist, by title.
83
+ - A **room** is the owner's: `_id` is `room-<minRank>-<slug>`, written only by
84
+ the owner, with a title and a line about what it is for. A Gold room and a
85
+ Platinum room are two rooms.
86
+ - A file a member downloads (a pattern, a recording) is a post with the file
87
+ on it, so it follows the same rule.
88
+
89
+ ## 4. The discussion: members post where their tier reads
90
+
91
+ A member posts to the discussion only into a room their tier reads: the access function checks the author is the signed-in member and calls ctx.requireAccess on the room's tier channel.
92
+
93
+ A `message` carries `roomId`, `minRank`, `authorHandle`, `text` and
94
+ `createdAt`. The access function can read only the document in front of it,
95
+ so the room's tier is written into the room's id and the message proves it
96
+ carries the same one:
97
+
98
+ ```js
99
+ if (doc.type === "message") {
100
+ if (!Number.isInteger(doc.minRank) || doc.minRank < 1 || !doc.roomId?.startsWith(`room-${doc.minRank}-`)) {
101
+ throw { forbidden: "a message carries its room's tier" };
102
+ }
103
+ if (oldDoc && (oldDoc.authorHandle !== doc.authorHandle || oldDoc.roomId !== doc.roomId)) throw { forbidden: "a message keeps its author and its room" };
104
+ if (oldDoc && doc.authorHandle !== user.userHandle) {
105
+ // The owner's moderation: hiding someone else's message, never rewriting it.
106
+ ctx.requireRole("owner");
107
+ if (doc.text !== oldDoc.text) throw { forbidden: "the owner hides a message, never rewrites it" };
108
+ } else {
109
+ if (doc.authorHandle !== user.userHandle) throw { forbidden: "a message is its author's" };
110
+ // The writer holds the room's tier right now: a lapsed member reads nothing and posts nothing.
111
+ ctx.requireAccess(`tier-${doc.minRank}`);
112
+ }
113
+ return { channels: [`tier-${doc.minRank}`] };
114
+ }
115
+ ```
116
+
117
+ The owner hides any message with a `hidden: true` rewrite the page filters
118
+ out; a member edits only their own. The page lists a room's
119
+ messages with a live query on `roomId`, newest last, with the composer gated
120
+ on `can.create(...)` for that room — so a lapsed member sees the room's door,
121
+ "Rejoin to post", and no composer.
122
+
123
+ ## 5. Members-only tools run in backend.js
124
+
125
+ A members-only tool runs in backend.js: the route reads the caller's own membership record and answers 403 unless it is entitled at the tool's rank, before it calls ctx.callAI or anything else that costs the owner.
126
+
127
+ The tool is often the reason the top tier exists — a sewing-pattern advisor
128
+ that knows the owner's own fitting rules, a critique of a member's draft in
129
+ the owner's voice, a calculator built on the owner's method. Its prompt and
130
+ its know-how are the owner's work, so they live in `backend.js`, where no
131
+ browser reads them, and the page sends only the member's question.
132
+
133
+ ```js
134
+ // The owner's tools, each with the lowest tier that runs it.
135
+ const TOOLS = { "pattern-advisor": { minRank: 2 } };
136
+
137
+ async function memberRank(ctx, mode) {
138
+ const me = ctx.userInfo?.userHandle;
139
+ if (!me) return 0;
140
+ if (me === ctx.appInfo.ownerHandle) return MAX_RANK; // the owner runs every tool, as the page shows them
141
+ const m = await ctx.db.get(`membership-${mode}-${me}`, { db: DB });
142
+ return m?.entitled === true && Number.isInteger(m.rank) ? m.rank : 0;
143
+ }
144
+
145
+ // inside fetch(request, ctx):
146
+ if (url.pathname === "/tool/pattern-advisor" && request.method === "POST") {
147
+ const { mode } = await checkoutMode(ctx);
148
+ if ((await memberRank(ctx, mode)) < TOOLS["pattern-advisor"].minRank) {
149
+ return json({ ok: false, reason: "tier", minRank: TOOLS["pattern-advisor"].minRank }, 403);
150
+ }
151
+ const { question } = await request.json();
152
+ const answer = await ctx.callAI(`${ADVISOR_PROMPT}\n\nThe member asks: ${String(question).slice(0, 4000)}`, { max_tokens: 900 });
153
+ return json({ ok: true, answer });
154
+ }
155
+ ```
156
+
157
+ - The route reads **one** record, the caller's own membership in the app's
158
+ current mode, so it sits under the `unfilteredReads` declaration the payment
159
+ recipe already makes; add the tool routes to its `why`.
160
+ - The page calls it with `apiFetch`, shows the tool to a member whose tier
161
+ runs it, and shows a member below it the tool's name, what it does and the
162
+ plan that opens it. A 403 with `reason: "tier"` reads the same way.
163
+ - `ctx.callAI` in a `fetch` route runs on the signed-in caller's credits; a
164
+ tool that saves its answers writes them to the member's own channel
165
+ (`user:<handle>`), so each member's history is theirs.
166
+
167
+ ## 6. Passes: a tier on Square, or on Stripe once
168
+
169
+ On Square, which takes one payment at a time, a tier is a pass: each paid order moves the membership's paidThrough forward by the plan's period, and backend.js writes entitled from paidThrough and the clock.
170
+
171
+ - The plan is the payment recipe's product record with `rank` and an
172
+ `interval` of `month` or `year`; a pass order is one line, that plan, priced
173
+ from the record like every other line.
174
+ - A pass membership is named for the payment's mode as well as the member,
175
+ `membership-<mode>-<handle>` (Stripe's `test` or `live`, Square's `sandbox`
176
+ or `production`), exactly as the payment recipe keeps its orders apart: a
177
+ test pass grants nothing once the app takes real money, and the tool check
178
+ and the page read the record for the app's current mode only.
179
+ - When the recipe's settle marks a pass order paid, the same settle rewrites
180
+ the buyer's membership record in the order's own mode: `paidThrough` becomes
181
+ `max(now, paidThrough) + one interval`, `rank` becomes the plan's, and
182
+ `entitled` is `paidThrough > now`. A member who buys early keeps every day
183
+ they already paid for.
184
+ - The recipe's scheduled sweep also reads every entitled membership and
185
+ rewrites `entitled: false` once `paidThrough` has passed, so a lapsed pass
186
+ closes the tiers on its own. Three days before, the sweep tells the member
187
+ with `ctx.notify` (dedupeKey `renew-<handle>-<paidThrough>`) that their pass
188
+ runs to that date, with the app's link to buy the next one.
189
+ - A pass order needs the buyer signed in, because the membership is theirs:
190
+ the Join button asks for sign-in first, and the order records
191
+ `buyerHandle`.
192
+ - Moving up a tier on a pass is buying the higher pass: the new rank applies
193
+ at once, and the days left carry over.
194
+
195
+ ## 7. The front door is a link the owner shares
196
+
197
+ The owner finds their people somewhere else — a video's description, a
198
+ newsletter, a pinned post — so the public page is the one they link. It reads
199
+ well to someone arriving cold: the owner's name and what the community is
200
+ for, each tier's title, price and what it opens (the rooms and tools at that
201
+ rank, read from the records), a Join per tier, and one public post or a
202
+ sample of the tool's output that shows what members get. The owner's **Share**
203
+ button copies that link with `?from=` set to where they will post it
204
+ (`youtube`, `newsletter`), and the membership records that `from` once, so the
205
+ **Members** page can say where each member came from.
206
+
207
+ **Changing tier on a renewing plan.** On `stripe-subscriptions` the app does
208
+ not change a live subscription's price, so a member holds one tier per
209
+ subscription. The page says which tier they hold and when it renews, and a
210
+ member who wants another tier cancels in the Customer Portal — which keeps
211
+ their tier to the end of the period they paid for — and joins the other tier
212
+ from the app once that period ends.
package/llms/reskin.md CHANGED
@@ -16,7 +16,10 @@ technique.
16
16
  - A style the person BRINGS — a brand guide, pasted CSS or tokens, Material 3,
17
17
  a screenshot to copy — is the `match-style` skill, which replaces the
18
18
  components with the app's own and makes its `THEME_CSS` the app's one look,
19
- in this skin's place.
19
+ in this skin's place. A build that stays on this skill for it (a palette and
20
+ fonts pasted onto a reskinned app) writes a new skin from that design in this
21
+ string's place, as step 3 says; either way the app wears the brought design
22
+ alone.
20
23
  - Everything between — a mood, a named style, a site named with nothing
21
24
  supplied — is a reskin.
22
25
 
@@ -57,7 +60,15 @@ open modal and dropdown included.
57
60
  **3. The skin is one module-level CSS string.** Declare `const SKIN = \`…\``
58
61
  above the component and render `<style>{SKIN}</style>` as the wrapper's first
59
62
  child. A later reskin rewrites this same string, so the app wears one skin
60
- at a time. Web fonts load from Google Fonts with an `@import` at the top of that
63
+ at a time. A design the person brings replaces this string whole — a pasted
64
+ palette, fonts or tokens, "use this design for the whole app": the new string
65
+ is drawn from their design alone, and the earlier skin's stripes, borders, hard
66
+ shadows, glow and the plain elements it added (a title bar, a menu strip) leave
67
+ with its colours, back only where their design asks for them, while every
68
+ component, control and record stays. A change to one colour or one face of the
69
+ skin is an edit to that value in this string, and the skin keeps its shapes and
70
+ chrome: "make the accent green" moves the accent token, and the title bar stays.
71
+ Web fonts load from Google Fonts with an `@import` at the top of that
61
72
  string. A heading face reads the Font card's pick first,
62
73
  `font-family: var(--font-pick, 'Silkscreen', monospace)`, so the skin's face is
63
74
  the default and a font the person picks in the Look tab reaches every heading
package/llms/square.md CHANGED
@@ -36,7 +36,9 @@ page).
36
36
  **One-time payments.** A payment link takes one payment for one order. Sell a
37
37
  period as a one-time item (a season pass, this month's class) and say so; a
38
38
  renewing Square subscription needs plans in the owner's Square catalog, which
39
- is beyond this recipe.
39
+ is beyond this recipe. A members' area on Square sells **passes** — a month of
40
+ Gold, a year of Platinum — and the `member-area` skill, beside this one,
41
+ turns each paid pass into a membership with a paid-through date.
40
42
 
41
43
  **The first sale is real money.** The owner's production token charges real
42
44
  cards, so the Setup screen says so plainly and suggests the owner buy their
@@ -22,7 +22,9 @@ a ticket, a deposit — is the `stripe` skill, not this one.
22
22
  **One merchant, many members.** Every member pays the Stripe account the owner
23
23
  connected. A member is a signed-in person whose membership is a record between
24
24
  them and the owner, and the members-only content is a channel that record
25
- grants. An app where each visitor sells their own subscriptions is a
25
+ grants. Tiers (gold and platinum), a members' discussion and members-only
26
+ tools are the `member-area` skill, which loads beside this one and swaps the
27
+ single `members` channel for a ladder of tier channels. An app where each visitor sells their own subscriptions is a
26
28
  marketplace, a bigger thing than this recipe — say so and build the
27
29
  one-merchant half.
28
30
 
package/llms/web-audio.md CHANGED
@@ -63,6 +63,23 @@ Practical: clean up disconnected nodes; check browser support; use headphones to
63
63
  - Latency budget: device `baseLatency` + your lookahead + any Worklet buffering.
64
64
  - Headphones recommended for monitoring to avoid acoustic feedback.
65
65
 
66
+ ## 2b) Sound that plays with the iPhone's silent switch on
67
+
68
+ When sound is the point of the app — a drum machine, a synth, a soundboard, a metronome, a timer whose chime is the thing it does — set the playback audio session when the person first presses to start sound, before the context is created, so the app keeps playing with the silent switch on the way a music app does. iOS otherwise plays Web Audio in the ambient session, which the switch mutes after the first sound. Feature-detect it: `navigator.audioSession` exists in Safari 17 and later, and every other browser skips the line and plays as before.
69
+
70
+ ```js
71
+ // Sound is the point of this app: it plays with the silent switch on, like a music app.
72
+ function playThroughSilentSwitch() {
73
+ if ("audioSession" in navigator) navigator.audioSession.type = "playback";
74
+ }
75
+
76
+ // The first line of the sound core's unlockAudio(), ahead of new AudioContext():
77
+ // playThroughSilentSwitch();
78
+ ```
79
+
80
+ An app whose sound is feedback on its actions (a game's blips, a tap
81
+ confirmation) leaves the session alone, so the phone's switch quiets it.
82
+
66
83
  ## 3) Restraint
67
84
 
68
85
  The sound core's restraint rule holds here too: an audio toy plays what the person plays, and an app whose sound is feedback keeps it to the core actions.
package/llms/web-music.md CHANGED
@@ -343,6 +343,8 @@ let drums;
343
343
 
344
344
  // The sound core's gate: synchronous, inside the tap, with one real (silent) sound.
345
345
  function unlockAudio() {
346
+ // A drum machine's point is sound: play with the iPhone's silent switch on (web-audio § 2b).
347
+ if ("audioSession" in navigator) navigator.audioSession.type = "playback";
346
348
  audioCtx ||= new (window.AudioContext || window.webkitAudioContext)();
347
349
  if (audioCtx.state !== "running") {
348
350
  audioCtx.resume();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibes.diy/prompts",
3
- "version": "14.3.341",
3
+ "version": "14.3.343",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "exports": {
@@ -39,10 +39,10 @@
39
39
  "license": "SEE LICENSE IN LICENSE.md",
40
40
  "dependencies": {
41
41
  "@adviser/cement": "~0.5.37",
42
- "@vibes.diy/api-types": "14.3.341",
43
- "@vibes.diy/call-ai-v2": "14.3.341",
44
- "@vibes.diy/identity": "14.3.341",
45
- "@vibes.diy/use-vibes-types": "14.3.341",
42
+ "@vibes.diy/api-types": "14.3.343",
43
+ "@vibes.diy/call-ai-v2": "14.3.343",
44
+ "@vibes.diy/identity": "14.3.343",
45
+ "@vibes.diy/use-vibes-types": "14.3.343",
46
46
  "arktype": "~2.2.9",
47
47
  "json-schema-faker": "~0.6.4"
48
48
  },
@@ -1,5 +1,6 @@
1
1
  import type { PaletteSeed } from "./palette-gen.js";
2
2
  import type { Ornament } from "./ornament-pad.js";
3
+ import { type PoufSeed } from "./pouf-rooms.js";
3
4
  export interface StylePreset {
4
5
  readonly slug: string;
5
6
  readonly label: string;
@@ -17,3 +18,6 @@ export declare const POUF_ROOM_ACCENT_PINS: Readonly<Record<string, number>>;
17
18
  export declare const POUF_STYLE_PRESETS: readonly StylePreset[];
18
19
  export declare const POUF_BOLD_TONE = 1;
19
20
  export declare const POUF_BOLD_PRESETS: readonly StylePreset[];
21
+ export declare function poufSeedEqualsPreset(seed: PoufSeed | undefined, preset: PoufSeed | undefined): boolean;
22
+ export declare function poufPresetOfSeed(seed: PoufSeed | undefined): string | undefined;
23
+ export declare function poufRoomOfSeed(seed: PoufSeed | undefined): string | undefined;
@@ -174,3 +174,18 @@ export const POUF_BOLD_PRESETS = POUF_STYLE_PRESETS.filter((p) => p.slug !== "po
174
174
  },
175
175
  };
176
176
  });
177
+ export function poufSeedEqualsPreset(seed, preset) {
178
+ if (seed === undefined || preset === undefined)
179
+ return false;
180
+ if (seed.up !== undefined || seed.down !== undefined)
181
+ return false;
182
+ return preset.lead === seed.lead && preset.locked === seed.locked && preset.tone === seed.tone && preset.gap === seed.gap;
183
+ }
184
+ export function poufPresetOfSeed(seed) {
185
+ const slugs = [...POUF_ROOM_SLUGS, ...POUF_BOLD_PRESETS.map((p) => p.slug)];
186
+ return slugs.find((slug) => poufSeedEqualsPreset(seed, getStylePreset(slug)?.palette.pouf));
187
+ }
188
+ export function poufRoomOfSeed(seed) {
189
+ const slug = poufPresetOfSeed(seed);
190
+ return slug?.endsWith("-bold") === true ? slug.slice(0, -"-bold".length) : slug;
191
+ }