@vibes.diy/prompts 14.3.286 → 14.3.288
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/llms/chess-variants.d.ts +2 -0
- package/llms/chess-variants.js +12 -0
- package/llms/chess-variants.js.map +1 -0
- package/llms/chess-variants.md +472 -0
- package/llms/chess.js +3 -2
- package/llms/chess.js.map +1 -1
- package/llms/chess.md +3 -3
- package/llms/fireproof.md +2 -0
- package/llms/index.d.ts +2 -1
- package/llms/index.js +3 -0
- package/llms/index.js.map +1 -1
- package/llms/stripe.md +32 -13
- package/llms/ui-quiz.md +87 -70
- package/llms/ui-storefront.md +57 -24
- package/package.json +5 -5
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const chessVariantsConfig = {
|
|
2
|
+
name: "chess-variants",
|
|
3
|
+
label: "Chess variants",
|
|
4
|
+
description: "Load it for chess on anything but the standard 8×8 rules — minichess on 5×5 or 6×6 boards, pawns-only games, " +
|
|
5
|
+
"atomic, crazyhouse, antichess, horde, three-check, King of the Hill, Chess960, shogi, xiangqi, new pieces, and a " +
|
|
6
|
+
"chess club's own invented variant. Rules from Fairy-Stockfish's ffish library, a variant written in a few lines " +
|
|
7
|
+
"of config, and a Fairy-Stockfish engine opponent in a Web Worker at any strength, on a board of any size.",
|
|
8
|
+
needs: ["board-games"],
|
|
9
|
+
cues: ["chess variant", "chess variants", "minichess", "fairy chess", "fairy-stockfish", "crazyhouse", "atomic chess", "antichess", "pawn wars"],
|
|
10
|
+
teaches: ["ffish", "fairy-stockfish-single"],
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=chess-variants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chess-variants.js","sourceRoot":"","sources":["../../jsr/llms/chess-variants.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,mBAAmB,GAAc;IAC5C,IAAI,EAAE,gBAAgB;IACtB,KAAK,EAAE,gBAAgB;IACvB,WAAW,EACT,+GAA+G;QAC/G,mHAAmH;QACnH,kHAAkH;QAClH,2GAA2G;IAE7G,KAAK,EAAE,CAAC,aAAa,CAAC;IACtB,IAAI,EAAE,CAAC,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW,CAAC;IAChJ,OAAO,EAAE,CAAC,OAAO,EAAE,wBAAwB,CAAC;CAC7C,CAAC"}
|
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
# Chess variants — small boards, odd pieces, a club's own rules, and an engine that plays them
|
|
2
|
+
|
|
3
|
+
Load this for chess on anything but the standard rules: 5×5 Gardner and 6×6 Los Alamos
|
|
4
|
+
minichess, Pawn Wars and other pawns-only games, atomic, crazyhouse, antichess, horde,
|
|
5
|
+
three-check, King of the Hill, Chess960, shogi and xiangqi, and a variant a club invents. It
|
|
6
|
+
stands on the board-games skill, which owns the board's look, turns, seats and who sees what.
|
|
7
|
+
Standard chess on 8×8 is the chess skill's (`chess.js` and Stockfish); this doc replaces both for
|
|
8
|
+
every other game:
|
|
9
|
+
|
|
10
|
+
1. **The rules come from ffish**, Fairy-Stockfish's rules library, in a Web Worker, whether the
|
|
11
|
+
opponent is the computer or a friend on another phone. It knows about 120 variants by name and
|
|
12
|
+
reads a new one from a few lines of text, so an app never writes a move generator, even for a
|
|
13
|
+
piece nobody has played before.
|
|
14
|
+
2. **The computer opponent is fairy-stockfish-single**, the Fairy-Stockfish engine built to run on
|
|
15
|
+
one thread, in a second Web Worker. It plays every variant the rules worker knows, at any
|
|
16
|
+
strength, and keeps the page responsive while it thinks.
|
|
17
|
+
3. **A club's own variant is a variants.ini section**, loaded into both workers from the same
|
|
18
|
+
string, so the board and the engine always agree on the rules.
|
|
19
|
+
|
|
20
|
+
## The rules — ffish in a Worker
|
|
21
|
+
|
|
22
|
+
`ffish-es6` loads from unpkg as an ES module. Run it in a module Worker built from a blob, as the
|
|
23
|
+
worked example's `lib/variants.js` does, and ask it for positions by message.
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
const ff = await (await import("https://unpkg.com/ffish-es6@0.7.10/ffish.js")).default({
|
|
27
|
+
locateFile: (f) => "https://unpkg.com/ffish-es6@0.7.10/" + f,
|
|
28
|
+
});
|
|
29
|
+
ff.loadVariantConfig(iniText); // adds the variants in a variants.ini string
|
|
30
|
+
const board = new ff.Board("gardner"); // or new ff.Board("gardner", fen) — never pass undefined
|
|
31
|
+
board.legalMoves(); // "a2a3 b2b3 …": UCI moves, space-separated
|
|
32
|
+
board.sanMove("b1c3"); // "Nc3", for the move list (ask before pushing it)
|
|
33
|
+
board.push("b1c3"); // false when illegal
|
|
34
|
+
board.fen(); board.turn(); // true when White is to move
|
|
35
|
+
board.isCheck(); board.isGameOver(); board.result(); // "1-0", "0-1", "1/2-1/2" or "*"
|
|
36
|
+
board.delete(); // boards live in WebAssembly memory until deleted
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- **The game is its UCI move list.** Store `moves: ["c2c3", "b4c3", …]` and the variant's id;
|
|
40
|
+
replay them on a fresh `Board(variant)` for every position. Ranks can have two digits on big
|
|
41
|
+
boards (`a10a9`), a promotion adds the piece letter (`b4b5q`), and a drop reads `P@e4`.
|
|
42
|
+
- **A move is legal when it is in `legalMoves()`.** The board's highlights come from the moves that
|
|
43
|
+
start on the tapped square, and the engine's reply and a friend's move go through the same list.
|
|
44
|
+
- **Promotion asks when the rules offer a choice.** Several legal moves with the same from and to
|
|
45
|
+
squares are a promotion: show one button per piece. Gardner promotes to queen, rook, bishop or
|
|
46
|
+
knight; a variant that allows one piece gives one move and needs no picker.
|
|
47
|
+
- **`new ff.Board(variant, undefined)` throws** inside the worker, and a throw in an async
|
|
48
|
+
`onmessage` reaches neither `onerror` nor the page. Pass a FEN only when there is one, and post
|
|
49
|
+
errors back as a message, as the example does.
|
|
50
|
+
|
|
51
|
+
## A club's own variant
|
|
52
|
+
|
|
53
|
+
A variant is an ini section that names a built-in parent and changes what differs. Fairy-Stockfish's
|
|
54
|
+
[variants.ini](https://github.com/fairy-stockfish/Fairy-Stockfish/blob/master/src/variants.ini)
|
|
55
|
+
documents every option; these cover most club inventions:
|
|
56
|
+
|
|
57
|
+
| Option | What it sets |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `startFen` | the starting position, which also sets the board size with `maxRank`/`maxFile` |
|
|
60
|
+
| `maxRank`, `maxFile` | a board up to 12 files by 10 ranks |
|
|
61
|
+
| `king = -` | no king, so no check or mate: the game is won another way |
|
|
62
|
+
| `castling`, `doubleStep` | turn castling or the pawn's two-step off |
|
|
63
|
+
| `promotionPieceTypes` | what a pawn may become, such as `q` or `nbrq` |
|
|
64
|
+
| `flagPiece`, `flagRegionWhite`, `flagRegionBlack` | a race: getting that piece to that region wins (a pawn that promotes on arrival is already the promoted piece, so name that) |
|
|
65
|
+
| `extinctionValue`, `extinctionPieceTypes` | losing all of those pieces decides the game |
|
|
66
|
+
| `checkCounting` | win by giving a number of checks (the FEN carries the count) |
|
|
67
|
+
| `mustCapture` | captures are compulsory, as in antichess |
|
|
68
|
+
| `stalemateValue` | stalemate wins or loses instead of drawing |
|
|
69
|
+
| `customPiece1 = a:NB` | a new piece, letter `a`, moving in Betza notation (here knight plus bishop) |
|
|
70
|
+
|
|
71
|
+
```ini
|
|
72
|
+
[pawnwars:chess]
|
|
73
|
+
startFen = 8/pppppppp/8/8/8/8/PPPPPPPP/8 w - - 0 1
|
|
74
|
+
king = -
|
|
75
|
+
castling = false
|
|
76
|
+
extinctionValue = loss
|
|
77
|
+
extinctionPieceTypes = *
|
|
78
|
+
flagPiece = q
|
|
79
|
+
flagRegionWhite = *8
|
|
80
|
+
flagRegionBlack = *1
|
|
81
|
+
promotionPieceTypes = q
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**A piece that moves differently swaps its letter onto another piece type.** Bishops that also
|
|
85
|
+
jump like knights are the built-in archbishop (bishop plus knight) wearing the bishop's letter:
|
|
86
|
+
|
|
87
|
+
```ini
|
|
88
|
+
[leapingbishops:chess]
|
|
89
|
+
bishop = -
|
|
90
|
+
archbishop = b
|
|
91
|
+
promotionPieceTypes = qrbn
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Name the promotion pieces again after a swap: removing `bishop` also drops it from promotion, and
|
|
95
|
+
`b` in `promotionPieceTypes` now means the archbishop.
|
|
96
|
+
|
|
97
|
+
The built-in types cover most club ideas: `archbishop` (B+N), `chancellor` (R+N), `amazon` (Q+N),
|
|
98
|
+
`centaur` (K+N), `commoner` (moves like a king but is not one), `wazir`, `fers`, `alfil`. Anything else
|
|
99
|
+
is a `customPiece` in Betza notation. Variants.ini lists every type and its letter.
|
|
100
|
+
|
|
101
|
+
The section name is the variant's id for `new ff.Board("pawnwars")` and for the engine's
|
|
102
|
+
`UCI_Variant`. Load the same string into both workers.
|
|
103
|
+
|
|
104
|
+
## The opponent — fairy-stockfish-single in a Web Worker
|
|
105
|
+
|
|
106
|
+
The published Fairy-Stockfish engines are multi-threaded and need `SharedArrayBuffer`, which a
|
|
107
|
+
vibe's page does not have. `VibesDIY/fairy-stockfish-single` is the same engine built for one thread
|
|
108
|
+
(1.1 MB of WebAssembly, from jsDelivr), and it loads the way the chess skill's Stockfish does:
|
|
109
|
+
|
|
110
|
+
- **A blob worker `importScripts` the engine, and the `.wasm` address rides in the worker URL's
|
|
111
|
+
`#hash`**: `new Worker(`${blobUrl}#${encodeURIComponent(wasmUrl)}`)`.
|
|
112
|
+
- **Custom variants go in as an object**: `worker.postMessage({ variants: iniText })`. Every other
|
|
113
|
+
message is a UCI line: `setoption name UCI_Variant value pawnwars`,
|
|
114
|
+
`position startpos moves c2c3 b4c3`, then `go movetime 400`.
|
|
115
|
+
- **Every `go` carries a limit** (`movetime`, `depth` or `nodes`). The engine thinks on the worker's
|
|
116
|
+
only thread, so a `stop` waits until it is done; an unlimited `go` searches for two seconds.
|
|
117
|
+
- Strength is `Skill Level` (0 to 20) and the thinking time, as in the chess skill. The reply is a
|
|
118
|
+
UCI move from `legalMoves()`; append it to the move list.
|
|
119
|
+
- **When the engine cannot load**, the promise rejects: keep playing with a random legal move and
|
|
120
|
+
say "Engine offline".
|
|
121
|
+
- **Credit it.** ffish and the engine are GPL-3 and run unmodified in their own workers; a muted
|
|
122
|
+
line under the board says "Rules and engine: Fairy-Stockfish (GPL-3)".
|
|
123
|
+
|
|
124
|
+
## Two players on two phones
|
|
125
|
+
|
|
126
|
+
A friend on their own phone is the board-games turn rule: one game doc holds the `variant`, the
|
|
127
|
+
`moves` list and the two seats, and only the seat whose turn it is writes. Each phone asks its
|
|
128
|
+
rules worker for the position after `moves` and accepts a move only when it is in `legal`, the same
|
|
129
|
+
as against the computer; there is just no engine worker. `access.js` cannot run ffish, so it checks
|
|
130
|
+
the seat, the turn, that `variant` is unchanged, and that the new `moves` is the old list with
|
|
131
|
+
exactly one move appended (every earlier move identical), so a turn can only add to the game.
|
|
132
|
+
|
|
133
|
+
## Drawing the board — any size
|
|
134
|
+
|
|
135
|
+
Draw the board-games SVG board from the FEN, whatever its size: `parseBoard(fen)` in the example
|
|
136
|
+
reads the rows (top rank first) and counts the files, so the same component draws 5×5, 6×6, 8×8
|
|
137
|
+
and 10×10. Chess letters (`kqrbnp`) take the solid glyphs ♚♛♜♝♞♟; any other letter is a fairy
|
|
138
|
+
piece, drawn as its capital letter until the app's look gives it art. Square names run `a`…`l` by
|
|
139
|
+
file and `1`…`10` by rank from White's side.
|
|
140
|
+
|
|
141
|
+
## Variants clubs reach for
|
|
142
|
+
|
|
143
|
+
- **Small boards:** `gardner` (5×5, every piece), `losalamos` (6×6, no bishops), `minishogi`,
|
|
144
|
+
`micro` and `kinglet`.
|
|
145
|
+
- **Odd goals:** `kingofthehill` (a king on a centre square wins), `3check`, `racingkings`
|
|
146
|
+
(race the kings to rank 8), `antichess` (lose everything to win), `horde` (36 pawns against an
|
|
147
|
+
army), `atomic` (captures explode).
|
|
148
|
+
- **Pieces in hand:** `crazyhouse` (captured pieces come back on your side), `placement`.
|
|
149
|
+
- **Starting positions:** `fischerandom` for Chess960.
|
|
150
|
+
|
|
151
|
+
Name a built-in by its id; build anything else as an ini section on top of one of these.
|
|
152
|
+
|
|
153
|
+
## Worked example — minichess against the computer
|
|
154
|
+
|
|
155
|
+
Three games behind one board: Gardner and Los Alamos are built in, and Pawn Wars is the club's
|
|
156
|
+
own section. You play White at three strengths.
|
|
157
|
+
|
|
158
|
+
### `lib/variants.js`
|
|
159
|
+
```js
|
|
160
|
+
// Chess variants: the rules from ffish (Fairy-Stockfish's rules library) and the opponent from
|
|
161
|
+
// fairy-stockfish-single (the same engine, built to run on one thread). Both are GPL-3 and run
|
|
162
|
+
// unmodified in their own Workers; the page only exchanges messages with them.
|
|
163
|
+
const FFISH = "https://unpkg.com/ffish-es6@0.7.10/";
|
|
164
|
+
const FSF = "https://cdn.jsdelivr.net/gh/VibesDIY/fairy-stockfish-single@v0.1.0/dist/fairy-stockfish";
|
|
165
|
+
|
|
166
|
+
export const LEVELS = [
|
|
167
|
+
{ id: "easy", label: "Easy", skill: 0, ms: 150 },
|
|
168
|
+
{ id: "club", label: "Club", skill: 8, ms: 400 },
|
|
169
|
+
{ id: "strong", label: "Strong", skill: 20, ms: 1200 },
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
// The rules worker: a module worker that imports ffish, loads the custom variants once, and
|
|
173
|
+
// answers each { variant, moves } with the position after those moves.
|
|
174
|
+
const RULES_WORKER = (ini) => `
|
|
175
|
+
const ready = import(${JSON.stringify(FFISH + "ffish.js")})
|
|
176
|
+
.then((m) => m.default({ locateFile: (f) => ${JSON.stringify(FFISH)} + f }))
|
|
177
|
+
.then((ff) => { if (${JSON.stringify(ini)}) ff.loadVariantConfig(${JSON.stringify(ini)}); return ff; });
|
|
178
|
+
onmessage = async (e) => {
|
|
179
|
+
const { id, variant, moves } = e.data;
|
|
180
|
+
try {
|
|
181
|
+
const ff = await ready;
|
|
182
|
+
const board = new ff.Board(variant); // a second argument must be a FEN string, never undefined
|
|
183
|
+
const san = [];
|
|
184
|
+
for (const uci of moves) { san.push(board.sanMove(uci)); board.push(uci); }
|
|
185
|
+
const out = { id, fen: board.fen(), legal: board.legalMoves().split(" ").filter(Boolean),
|
|
186
|
+
white: board.turn(), check: board.isCheck(), over: board.isGameOver(), result: board.result(), san };
|
|
187
|
+
board.delete(); // ffish boards live in WebAssembly memory until deleted
|
|
188
|
+
postMessage(out);
|
|
189
|
+
} catch (err) { postMessage({ id, error: String(err) }); }
|
|
190
|
+
};`;
|
|
191
|
+
|
|
192
|
+
export function startRules(ini = "") {
|
|
193
|
+
const url = URL.createObjectURL(new Blob([RULES_WORKER(ini)], { type: "text/javascript" }));
|
|
194
|
+
const worker = new Worker(url, { type: "module" });
|
|
195
|
+
let n = 0;
|
|
196
|
+
const pending = new Map();
|
|
197
|
+
worker.onmessage = (e) => {
|
|
198
|
+
const p = pending.get(e.data.id);
|
|
199
|
+
pending.delete(e.data.id);
|
|
200
|
+
if (p) e.data.error ? p.reject(new Error(e.data.error)) : p.resolve(e.data);
|
|
201
|
+
};
|
|
202
|
+
worker.onerror = (e) => {
|
|
203
|
+
for (const p of pending.values()) p.reject(new Error(e.message || "rules unavailable"));
|
|
204
|
+
pending.clear();
|
|
205
|
+
};
|
|
206
|
+
return {
|
|
207
|
+
// The position after `moves` (UCI strings) from the variant's start.
|
|
208
|
+
position: (variant, moves) =>
|
|
209
|
+
new Promise((resolve, reject) => {
|
|
210
|
+
const id = ++n;
|
|
211
|
+
pending.set(id, { resolve, reject });
|
|
212
|
+
worker.postMessage({ id, variant, moves });
|
|
213
|
+
}),
|
|
214
|
+
stop: () => worker.terminate(),
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function startEngine(ini = "") {
|
|
219
|
+
const boot = URL.createObjectURL(new Blob([`importScripts("${FSF}.js");`], { type: "application/javascript" }));
|
|
220
|
+
const worker = new Worker(`${boot}#${encodeURIComponent(`${FSF}.wasm`)}`);
|
|
221
|
+
let current = null;
|
|
222
|
+
let queue = Promise.resolve();
|
|
223
|
+
let broken = null;
|
|
224
|
+
worker.onmessage = (e) => {
|
|
225
|
+
const line = String(e.data);
|
|
226
|
+
if (line.startsWith("bestmove") && current) {
|
|
227
|
+
const uci = line.split(" ")[1];
|
|
228
|
+
const done = current;
|
|
229
|
+
current = null;
|
|
230
|
+
done.resolve(uci && uci !== "(none)" ? uci : null);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
worker.onerror = () => {
|
|
234
|
+
broken = new Error("engine unavailable");
|
|
235
|
+
if (current) current.reject(broken);
|
|
236
|
+
current = null;
|
|
237
|
+
};
|
|
238
|
+
worker.postMessage("uci");
|
|
239
|
+
if (ini) worker.postMessage({ variants: ini }); // the same rules text the rules worker loaded
|
|
240
|
+
|
|
241
|
+
return {
|
|
242
|
+
bestMove: (variant, moves, level) => {
|
|
243
|
+
const run = () =>
|
|
244
|
+
new Promise((resolve, reject) => {
|
|
245
|
+
if (broken) return reject(broken);
|
|
246
|
+
current = { resolve, reject };
|
|
247
|
+
worker.postMessage(`setoption name UCI_Variant value ${variant}`);
|
|
248
|
+
worker.postMessage(`setoption name Skill Level value ${level.skill}`);
|
|
249
|
+
worker.postMessage(`position startpos moves ${moves.join(" ")}`);
|
|
250
|
+
worker.postMessage(`go movetime ${level.ms}`); // every search needs a limit on one thread
|
|
251
|
+
});
|
|
252
|
+
const next = queue.then(run, run);
|
|
253
|
+
queue = next.catch(() => {});
|
|
254
|
+
return next;
|
|
255
|
+
},
|
|
256
|
+
stop: () => worker.terminate(),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// The FEN's board as rows of cells, top rank first, for any width: "10" is ten empty squares,
|
|
261
|
+
// "+P" a promoted piece, and a crazyhouse "[...]" pocket is not part of the board.
|
|
262
|
+
export function parseBoard(fen) {
|
|
263
|
+
const rows = fen.split(" ")[0].replace(/\[.*\]$/, "").split("/");
|
|
264
|
+
return rows.map((row) => {
|
|
265
|
+
const cells = [];
|
|
266
|
+
for (const m of row.matchAll(/(\d+)|(\+?[A-Za-z]~?)/g)) {
|
|
267
|
+
if (m[1]) for (let i = 0; i < Number(m[1]); i++) cells.push(null);
|
|
268
|
+
else {
|
|
269
|
+
const letter = m[2].replace(/[+~]/g, "");
|
|
270
|
+
cells.push({ type: letter.toLowerCase(), white: letter === letter.toUpperCase() });
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return cells;
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// "a7a8q" → { from: "a7", to: "a8", promo: "q" }; ranks can be two digits on big boards, and a
|
|
278
|
+
// drop reads "P@e4".
|
|
279
|
+
export function splitMove(uci) {
|
|
280
|
+
const m = uci.match(/^([a-z]\d+|[A-Za-z]@)([a-z]\d+)(.*)$/);
|
|
281
|
+
return m ? { from: m[1], to: m[2], promo: m[3] } : null;
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### `App.jsx`
|
|
286
|
+
```jsx
|
|
287
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
288
|
+
import { Badge, Button, Card, Heading, Row, Stack, Text } from "@vibes.diy/ui";
|
|
289
|
+
import { LEVELS, parseBoard, splitMove, startEngine, startRules } from "./lib/variants.js";
|
|
290
|
+
|
|
291
|
+
// A club's own rules, written in Fairy-Stockfish's variant format. Both workers load the same text.
|
|
292
|
+
const CLUB_RULES = `
|
|
293
|
+
[pawnwars:chess]
|
|
294
|
+
startFen = 8/pppppppp/8/8/8/8/PPPPPPPP/8 w - - 0 1
|
|
295
|
+
king = -
|
|
296
|
+
castling = false
|
|
297
|
+
extinctionValue = loss
|
|
298
|
+
extinctionPieceTypes = *
|
|
299
|
+
flagPiece = q
|
|
300
|
+
flagRegionWhite = *8
|
|
301
|
+
flagRegionBlack = *1
|
|
302
|
+
promotionPieceTypes = q
|
|
303
|
+
`;
|
|
304
|
+
|
|
305
|
+
const GAMES = [
|
|
306
|
+
{ id: "gardner", label: "5×5 Gardner", about: "Every chess piece on a 5×5 board. Mate comes fast." },
|
|
307
|
+
{ id: "losalamos", label: "6×6 Los Alamos", about: "The 1956 computer chess board: no bishops, no castling." },
|
|
308
|
+
{ id: "pawnwars", label: "Pawn Wars", about: "Only pawns. Reach the far side or take every enemy pawn to win." },
|
|
309
|
+
];
|
|
310
|
+
|
|
311
|
+
const S = 100;
|
|
312
|
+
const FILES = "abcdefghijkl";
|
|
313
|
+
const GLYPH = { k: "♚", q: "♛", r: "♜", b: "♝", n: "♞", p: "♟" };
|
|
314
|
+
const PIECE_NAME = { q: "Queen", r: "Rook", b: "Bishop", n: "Knight", k: "King" };
|
|
315
|
+
|
|
316
|
+
function outcome(pos) {
|
|
317
|
+
if (!pos?.over) return null;
|
|
318
|
+
if (pos.result === "1-0") return "You win";
|
|
319
|
+
if (pos.result === "0-1") return "The computer wins";
|
|
320
|
+
return "Draw";
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function VariantBoard({ pos, selected, lastMove, onSquare }) {
|
|
324
|
+
const rows = parseBoard(pos.fen);
|
|
325
|
+
const width = rows[0].length;
|
|
326
|
+
const targets = selected ? pos.legal.map(splitMove).filter((m) => m && m.from === selected).map((m) => m.to) : [];
|
|
327
|
+
return (
|
|
328
|
+
<svg viewBox={`0 0 ${width * S} ${rows.length * S}`} className="w-full max-w-md touch-manipulation select-none" role="group" aria-label="Game board">
|
|
329
|
+
{rows.map((row, r) =>
|
|
330
|
+
row.map((piece, f) => {
|
|
331
|
+
const square = FILES[f] + (rows.length - r);
|
|
332
|
+
const x = f * S;
|
|
333
|
+
const y = r * S;
|
|
334
|
+
return (
|
|
335
|
+
<g key={square} role="button" tabIndex={0} aria-label={piece ? `${square}, ${piece.white ? "white" : "black"} ${PIECE_NAME[piece.type] ?? piece.type}` : square} onClick={() => onSquare(square)} onKeyDown={(e) => (e.key === "Enter" || e.key === " ") && (e.preventDefault(), onSquare(square))} className="cursor-pointer">
|
|
336
|
+
<rect x={x} y={y} width={S} height={S} className={(r + f) % 2 ? "fill-muted" : "fill-card"} />
|
|
337
|
+
{lastMove?.includes(square) && <rect x={x} y={y} width={S} height={S} className="fill-accent opacity-40" />}
|
|
338
|
+
{selected === square && <rect x={x + 4} y={y + 4} width={S - 8} height={S - 8} strokeWidth="8" className="fill-none stroke-primary" />}
|
|
339
|
+
{piece && (
|
|
340
|
+
<text x={x + S / 2} y={y + S / 2 + 4} textAnchor="middle" dominantBaseline="central" fontSize={GLYPH[piece.type] ? 78 : 52} strokeWidth="3" className={piece.white ? "fill-card stroke-foreground" : "fill-foreground stroke-foreground"}>
|
|
341
|
+
{GLYPH[piece.type] ? GLYPH[piece.type] + "︎" : piece.type.toUpperCase()}
|
|
342
|
+
</text>
|
|
343
|
+
)}
|
|
344
|
+
{targets.includes(square) && <circle cx={x + S / 2} cy={y + S / 2} r={piece ? 44 : 14} strokeWidth={piece ? 6 : 0} className={piece ? "fill-none stroke-primary" : "fill-primary opacity-70"} />}
|
|
345
|
+
</g>
|
|
346
|
+
);
|
|
347
|
+
})
|
|
348
|
+
)}
|
|
349
|
+
</svg>
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export default function App() {
|
|
354
|
+
const [variant, setVariant] = useState(GAMES[0].id);
|
|
355
|
+
const [moves, setMoves] = useState([]); // the game is its UCI move list from the variant's start
|
|
356
|
+
const [pos, setPos] = useState(null);
|
|
357
|
+
const [level, setLevel] = useState(LEVELS[1]);
|
|
358
|
+
const [selected, setSelected] = useState(null);
|
|
359
|
+
const [choices, setChoices] = useState(null); // promotion moves waiting for a pick
|
|
360
|
+
const [thinking, setThinking] = useState(false);
|
|
361
|
+
const [engineDown, setEngineDown] = useState(false);
|
|
362
|
+
const rules = useRef(null);
|
|
363
|
+
const engine = useRef(null);
|
|
364
|
+
|
|
365
|
+
useEffect(() => {
|
|
366
|
+
rules.current = startRules(CLUB_RULES);
|
|
367
|
+
engine.current = startEngine(CLUB_RULES);
|
|
368
|
+
return () => (rules.current.stop(), engine.current.stop());
|
|
369
|
+
}, []);
|
|
370
|
+
|
|
371
|
+
// Every position comes from the rules worker: legal moves, check, the end of the game.
|
|
372
|
+
useEffect(() => {
|
|
373
|
+
let live = true;
|
|
374
|
+
rules.current.position(variant, moves).then((p) => live && setPos(p));
|
|
375
|
+
return () => {
|
|
376
|
+
live = false;
|
|
377
|
+
};
|
|
378
|
+
}, [variant, moves]);
|
|
379
|
+
|
|
380
|
+
const result = outcome(pos);
|
|
381
|
+
const myTurn = pos && pos.white && !pos.over;
|
|
382
|
+
|
|
383
|
+
// The computer plays Black.
|
|
384
|
+
useEffect(() => {
|
|
385
|
+
if (!pos || pos.white || pos.over || pos.legal.length === 0) return;
|
|
386
|
+
let live = true;
|
|
387
|
+
setThinking(true);
|
|
388
|
+
engine.current
|
|
389
|
+
.bestMove(variant, moves, level)
|
|
390
|
+
.then((uci) => live && uci && setMoves([...moves, uci]))
|
|
391
|
+
.catch(() => {
|
|
392
|
+
setEngineDown(true);
|
|
393
|
+
if (live) setMoves([...moves, pos.legal[Math.floor(Math.random() * pos.legal.length)]]);
|
|
394
|
+
})
|
|
395
|
+
.finally(() => live && setThinking(false));
|
|
396
|
+
return () => {
|
|
397
|
+
live = false;
|
|
398
|
+
};
|
|
399
|
+
}, [pos]);
|
|
400
|
+
|
|
401
|
+
function onSquare(square) {
|
|
402
|
+
if (!myTurn || thinking || choices) return; // a promotion picker waits for its pick
|
|
403
|
+
const options = selected ? pos.legal.filter((uci) => { const m = splitMove(uci); return m && m.from === selected && m.to === square; }) : [];
|
|
404
|
+
if (options.length > 1) return setChoices(options); // a promotion: let the player pick the piece
|
|
405
|
+
if (options.length === 1) return (setMoves([...moves, options[0]]), setSelected(null));
|
|
406
|
+
const owns = pos.legal.some((uci) => splitMove(uci)?.from === square);
|
|
407
|
+
setSelected(owns ? square : null);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function newGame(id) {
|
|
411
|
+
setVariant(id);
|
|
412
|
+
setMoves([]);
|
|
413
|
+
setPos(null);
|
|
414
|
+
setSelected(null);
|
|
415
|
+
setChoices(null);
|
|
416
|
+
setThinking(false); // a search still running for the old game is ignored when it returns
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const game = GAMES.find((g) => g.id === variant);
|
|
420
|
+
const last = moves.length ? splitMove(moves[moves.length - 1]) : null;
|
|
421
|
+
const status = result ?? (thinking ? "The computer is thinking…" : pos?.check ? "Check! Your move" : "Your move, you play White");
|
|
422
|
+
|
|
423
|
+
return (
|
|
424
|
+
<main className="min-h-screen bg-background text-foreground font-sans p-4 flex flex-col items-center gap-4">
|
|
425
|
+
<Heading level={1}>Mini chess</Heading>
|
|
426
|
+
<Row gap={2} wrap>
|
|
427
|
+
{GAMES.map((g) => (
|
|
428
|
+
<Button key={g.id} type="button" size="sm" variant={g.id === variant ? "solid" : "quiet"} onClick={() => newGame(g.id)}>
|
|
429
|
+
{g.label}
|
|
430
|
+
</Button>
|
|
431
|
+
))}
|
|
432
|
+
</Row>
|
|
433
|
+
<Text size="sm" muted>{game.about}</Text>
|
|
434
|
+
<Row gap={2} align="center">
|
|
435
|
+
<Badge tone={result ? "up" : "info"}>{pos ? status : "Setting up the board…"}</Badge>
|
|
436
|
+
{engineDown && <Text size="sm" muted>Engine offline, playing random moves</Text>}
|
|
437
|
+
</Row>
|
|
438
|
+
|
|
439
|
+
{pos && <VariantBoard pos={pos} selected={selected} lastMove={last ? [last.from, last.to] : null} onSquare={onSquare} />}
|
|
440
|
+
|
|
441
|
+
{choices && (
|
|
442
|
+
<Row gap={2} wrap>
|
|
443
|
+
{choices.map((uci) => (
|
|
444
|
+
<Button key={uci} type="button" size="sm" onClick={() => (setMoves([...moves, uci]), setChoices(null), setSelected(null))}>
|
|
445
|
+
{PIECE_NAME[splitMove(uci).promo] ?? splitMove(uci).promo.toUpperCase()}
|
|
446
|
+
</Button>
|
|
447
|
+
))}
|
|
448
|
+
</Row>
|
|
449
|
+
)}
|
|
450
|
+
|
|
451
|
+
<Row gap={2} wrap>
|
|
452
|
+
{LEVELS.map((l) => (
|
|
453
|
+
<Button key={l.id} type="button" size="sm" variant={l.id === level.id ? "solid" : "quiet"} onClick={() => setLevel(l)}>
|
|
454
|
+
{l.label}
|
|
455
|
+
</Button>
|
|
456
|
+
))}
|
|
457
|
+
<Button type="button" size="sm" variant="quiet" onClick={() => newGame(variant)}>New game</Button>
|
|
458
|
+
</Row>
|
|
459
|
+
|
|
460
|
+
<div className="w-full max-w-md">
|
|
461
|
+
<Card>
|
|
462
|
+
<Stack gap={2}>
|
|
463
|
+
<Heading level={2}>Moves</Heading>
|
|
464
|
+
<Text size="sm">{pos?.san.map((s, i) => (i % 2 ? s : `${i / 2 + 1}. ${s}`)).join(" ") || "No moves yet."}</Text>
|
|
465
|
+
</Stack>
|
|
466
|
+
</Card>
|
|
467
|
+
</div>
|
|
468
|
+
<Text size="sm" muted>Rules and engine: Fairy-Stockfish (GPL-3).</Text>
|
|
469
|
+
</main>
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
```
|
package/llms/chess.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export const chessConfig = {
|
|
2
2
|
name: "chess",
|
|
3
3
|
label: "Chess",
|
|
4
|
-
description: "Load it for every chess app — play the computer at a chosen strength, play a friend from
|
|
5
|
-
"opening trainers, blunder coaches, game reviews, club ladders
|
|
4
|
+
description: "Load it for every standard chess app on the 8×8 board — play the computer at a chosen strength, play a friend from " +
|
|
5
|
+
"a shared link, puzzles, opening trainers, blunder coaches, game reviews, club ladders (other boards and rule sets " +
|
|
6
|
+
"are chess-variants'). Real rules from chess.js (castling, " +
|
|
6
7
|
"en passant, promotion, check, mate, every draw), a Stockfish engine opponent and analysis in a Web Worker, move " +
|
|
7
8
|
"lists, PGN and FEN, clocks, and the board drawn in SVG, with react-chessboard drag-and-drop, or in 3D.",
|
|
8
9
|
needs: ["board-games"],
|
package/llms/chess.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chess.js","sourceRoot":"","sources":["../../jsr/llms/chess.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,WAAW,GAAc;IACpC,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,OAAO;IACd,WAAW,EACT,
|
|
1
|
+
{"version":3,"file":"chess.js","sourceRoot":"","sources":["../../jsr/llms/chess.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,WAAW,GAAc;IACpC,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,OAAO;IACd,WAAW,EACT,qHAAqH;QACrH,oHAAoH;QACpH,4DAA4D;QAC5D,kHAAkH;QAClH,wGAAwG;IAE1G,KAAK,EAAE,CAAC,aAAa,CAAC;IACtB,IAAI,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,KAAK,CAAC;IAC/F,OAAO,EAAE,CAAC,YAAY,EAAE,WAAW,CAAC;CACrC,CAAC"}
|
package/llms/chess.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Chess — the rules from chess.js, the opponent from Stockfish, the board drawn your way
|
|
2
2
|
|
|
3
3
|
Load this for any chess app: play against the computer, play a friend from a shared link, a
|
|
4
|
-
puzzle or opening trainer, a blunder coach, a game review, a club ladder
|
|
5
|
-
|
|
6
|
-
geometry, its look, turns, seats and who sees what. This doc owns the three things chess gets
|
|
4
|
+
puzzle or opening trainer, a blunder coach, a game review, a club ladder. A smaller board, new
|
|
5
|
+
pieces or new rules are the chess-variants skill's instead. It stands on the board-games skill,
|
|
6
|
+
which loads with it and owns the board's geometry, its look, turns, seats and who sees what. This doc owns the three things chess gets
|
|
7
7
|
wrong when an app writes them itself:
|
|
8
8
|
|
|
9
9
|
1. **The rules come from `chess.js`.** Castling (and losing the right to castle), en passant,
|
package/llms/fireproof.md
CHANGED
|
@@ -21,6 +21,8 @@ Each document has an `_id`, which can be auto-generated or set explicitly. Auto-
|
|
|
21
21
|
|
|
22
22
|
Use granular documents, e.g. one document per user action, so saving a form or clicking a button should typically create or update a single document, or just a few documents. Avoid patterns that require a single document to grow without bound.
|
|
23
23
|
|
|
24
|
+
A flow someone moves through in steps (a quiz, a wizard, a game run, a bag or cart, a booking) is data from its first step. Write its parent record with the first step, then save each answer, pick, move or line as its own document carrying the parent's id (`attemptId`, `orderId`, `bagId`) the moment it is made, with a deterministic `_id` such as `` `${attemptId}:${step}` `` so a repeat rewrites one row. The parent's open record and a `useLiveQuery` on that id rebuild the screen, so a reload, another device or the person's own agent lands where they were. Scores, types and totals are computed from those rows; a snapshot stored on the parent when the flow finishes sits beside them and never replaces them. React state holds only what means nothing outside this screen: the open tab, the choice not yet confirmed, a hover.
|
|
25
|
+
|
|
24
26
|
`useLiveQuery` populates and refreshes the UI reactively as data arrives, so render an inviting empty state while a list has nothing in it. Writes are optimistic and local: `put()`/`save()`/`del()` land in the local replica instantly, and transport or offline failures queue and retry on their own. The server's access rules have the final word: a refused write converges **server-wins** to the server's version, and the **platform** tells the visitor — in the app's own `forbidden("…")` words when it gave some, its own line otherwise, and "saved on this device" when a signed-out visitor's save waits for sign-in. So write plainly and let the store be the feedback: render from `useLiveQuery`/`useDocument`, gate write surfaces up front with `useVibe(dbName).can.create/edit/delete` so only allowed actions render, and keep `try/catch` for a save carrying `_files` (covered with the image uploader below). A toggle shows the whole shape — flip it at once, follow its receipt beside the control, and the list re-reads itself:
|
|
25
27
|
|
|
26
28
|
```jsx
|
package/llms/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { backendConfig } from "./backend.js";
|
|
|
3
3
|
export { calendarConfig } from "./calendar.js";
|
|
4
4
|
export { boardGamesConfig } from "./board-games.js";
|
|
5
5
|
export { chessConfig } from "./chess.js";
|
|
6
|
+
export { chessVariantsConfig } from "./chess-variants.js";
|
|
6
7
|
export { surfaceBoardConfig } from "./surface-board.js";
|
|
7
8
|
export { ownerSecretConfig } from "./owner-secret.js";
|
|
8
9
|
export { thirdPartyEmbedConfig } from "./third-party-embed.js";
|
|
@@ -80,7 +81,7 @@ export { uiTestimonialsConfig } from "./ui-testimonials.js";
|
|
|
80
81
|
export type { LlmConfig, SkillCredential, SkillEgress } from "./types.js";
|
|
81
82
|
export { cueMatches, cueMatchedSkills, type CueCatalogEntry } from "./cues.js";
|
|
82
83
|
export { expandSkills, onSkillMenu, skillGraphProblems, universalSkillNames, type NeedsCatalogEntry } from "./needs.js";
|
|
83
|
-
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];
|
|
84
|
+
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];
|
|
84
85
|
export { mapsConfig } from "./maps.js";
|
|
85
86
|
export declare const SKILL_ALIASES: ReadonlyMap<string, string>;
|
|
86
87
|
export declare function canonicalSkillName(name: string): string;
|
package/llms/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { mapsConfig } from "./maps.js";
|
|
|
3
3
|
import { calendarConfig } from "./calendar.js";
|
|
4
4
|
import { boardGamesConfig } from "./board-games.js";
|
|
5
5
|
import { chessConfig } from "./chess.js";
|
|
6
|
+
import { chessVariantsConfig } from "./chess-variants.js";
|
|
6
7
|
import { surfaceBoardConfig } from "./surface-board.js";
|
|
7
8
|
import { ownerSecretConfig } from "./owner-secret.js";
|
|
8
9
|
import { thirdPartyEmbedConfig } from "./third-party-embed.js";
|
|
@@ -81,6 +82,7 @@ export { backendConfig } from "./backend.js";
|
|
|
81
82
|
export { calendarConfig } from "./calendar.js";
|
|
82
83
|
export { boardGamesConfig } from "./board-games.js";
|
|
83
84
|
export { chessConfig } from "./chess.js";
|
|
85
|
+
export { chessVariantsConfig } from "./chess-variants.js";
|
|
84
86
|
export { surfaceBoardConfig } from "./surface-board.js";
|
|
85
87
|
export { ownerSecretConfig } from "./owner-secret.js";
|
|
86
88
|
export { thirdPartyEmbedConfig } from "./third-party-embed.js";
|
|
@@ -188,6 +190,7 @@ export const allConfigs = [
|
|
|
188
190
|
surfaceBoardConfig,
|
|
189
191
|
boardGamesConfig,
|
|
190
192
|
chessConfig,
|
|
193
|
+
chessVariantsConfig,
|
|
191
194
|
accessConfig,
|
|
192
195
|
connectionsConfig,
|
|
193
196
|
socialPostConfig,
|
package/llms/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../jsr/llms/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO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GAAG,CAAC;IACrH,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAC7D,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,CAAC,aAAa,EAAE,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IACtE,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;CACvD,CAAC,CAAC;AAWH,MAAM,UAAU,gBAAgB,CAAC,KAAwB,EAAE,OAAgB;IACzE,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,SAAS,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC3C,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC1C,MAAM,IAAI,GAAG,KAAK,KAAK,SAAS,IAAI,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAChH,KAAK,MAAM,CAAC,IAAI,IAAI;YAAE,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,KAAK;gBAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/llms/stripe.md
CHANGED
|
@@ -1078,15 +1078,17 @@ and `rev`, a fresh random string on every write, which is the version the
|
|
|
1078
1078
|
Pay link names. Its lines take one of two shapes, and a shop picks the one
|
|
1079
1079
|
that fits:
|
|
1080
1080
|
|
|
1081
|
-
- **Lines on the bag.** `lines: [{ productId, qty }]` on the bag itself, and
|
|
1082
|
-
every change is one put of the whole bag with a new `rev`. Right for most
|
|
1083
|
-
shops: one record, one write, nothing to keep in step.
|
|
1084
1081
|
- **A record per line.** Each line is its own `type: "line"` record with
|
|
1085
1082
|
`bagId`, `productId`, `qty` and whatever options it carries (size, milk,
|
|
1086
1083
|
engraving), and every line write also puts the bag with a new `rev` and
|
|
1087
|
-
`touchedAt`. Right
|
|
1088
|
-
|
|
1089
|
-
|
|
1084
|
+
`touchedAt`. Right for most shops: each line can be read, counted and
|
|
1085
|
+
changed on its own, the shop can tally a product across bags, and anyone
|
|
1086
|
+
helping the buyer adds a line without rewriting the rest. The line carries
|
|
1087
|
+
the `touchedAt` of the bag write that went with it, so a line newer than
|
|
1088
|
+
the bag was written after the link and is not in it.
|
|
1089
|
+
- **Lines on the bag.** `lines: [{ productId, qty }]` on the bag itself, and
|
|
1090
|
+
every change is one put of the whole bag with a new `rev`. Right only for a
|
|
1091
|
+
bag of one or two fixed things that nobody reads line by line.
|
|
1090
1092
|
|
|
1091
1093
|
A line's options are the shop's to price: `priceBag` reads them off the line
|
|
1092
1094
|
and adds what the owner's product record says they cost, so a modifier is
|
|
@@ -1187,9 +1189,17 @@ answer, and the page puts the bag on it.
|
|
|
1187
1189
|
### `App.jsx`
|
|
1188
1190
|
```jsx partial
|
|
1189
1191
|
// The buyer's open bag: theirs alone (access.js routes it to their own channel), and the newest one
|
|
1190
|
-
// no paid order names.
|
|
1192
|
+
// no paid order names. Its lines are records naming it by bagId; every Add puts one line and the
|
|
1193
|
+
// bag with a fresh rev.
|
|
1191
1194
|
const { docs: bags } = useLiveQuery("type", { key: "bag" });
|
|
1192
1195
|
const bag = me && bags.filter((b) => b.buyerHandle === me.userHandle && !orders.some((o) => o.bagId === b._id && o.status === "paid")).sort((a, b) => b.touchedAt - a.touchedAt)[0];
|
|
1196
|
+
const { docs: bagLines } = useLiveQuery("bagId", { key: bag?._id ?? "" });
|
|
1197
|
+
const savedLines = bagLines.filter((l) => l.type === "line" && l.buyerHandle === me?.userHandle);
|
|
1198
|
+
// A bag this page started that the live query has not returned yet: two quick Adds share it.
|
|
1199
|
+
const startedBag = useRef(null);
|
|
1200
|
+
useEffect(() => {
|
|
1201
|
+
if (bag) startedBag.current = null; // the query has it now, and a paid bag must not be reused
|
|
1202
|
+
}, [bag?._id]);
|
|
1193
1203
|
// A guest's bag: page state kept in localStorage, emptied when their payment comes back paid.
|
|
1194
1204
|
const [guestLines, setGuestLines] = useState(() => {
|
|
1195
1205
|
try {
|
|
@@ -1207,12 +1217,21 @@ useEffect(() => {
|
|
|
1207
1217
|
useEffect(() => {
|
|
1208
1218
|
if (!me && back?.status === "paid") setGuestLines([]);
|
|
1209
1219
|
}, [me, back?.status]);
|
|
1210
|
-
const lines = (
|
|
1211
|
-
const add = (productId) => {
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1220
|
+
const lines = (me ? savedLines : guestLines).filter((l) => forSale.some((p) => p._id === l.productId));
|
|
1221
|
+
const add = async (productId) => {
|
|
1222
|
+
if (!me) {
|
|
1223
|
+
const next = guestLines.some((l) => l.productId === productId) ? guestLines.map((l) => (l.productId === productId ? { ...l, qty: l.qty + 1 } : l)) : [...guestLines, { productId, qty: 1 }];
|
|
1224
|
+
return setGuestLines(next);
|
|
1225
|
+
}
|
|
1226
|
+
// One line per product, its id derived from the bag and the product, so a second Add is a new
|
|
1227
|
+
// quantity on the same line, options and all. The bag takes its new rev FIRST, so a Pay link to
|
|
1228
|
+
// the old version is refused before its line changes; the line shares the bag's touchedAt, so
|
|
1229
|
+
// /pay counts it in this version.
|
|
1230
|
+
const bagId = bag?._id ?? (startedBag.current ??= "bag-" + crypto.randomUUID());
|
|
1231
|
+
const touchedAt = Date.now();
|
|
1232
|
+
const line = savedLines.find((l) => l.productId === productId);
|
|
1233
|
+
await database.put({ ...(bag ?? { _id: bagId, type: "bag", buyerHandle: me.userHandle }), rev: crypto.randomUUID(), touchedAt });
|
|
1234
|
+
await database.put({ ...(line ?? { _id: `${bagId}:${productId}`, type: "line", bagId, buyerHandle: me.userHandle, productId }), qty: (line?.qty ?? 0) + 1, touchedAt });
|
|
1216
1235
|
};
|
|
1217
1236
|
// The same address anyone helping the buyer would hand them. The subtotal is a preview; /pay prices it.
|
|
1218
1237
|
const payUrl = bag && setup?.pay && `${setup.pay}?bag=${encodeURIComponent(bag._id)}&rev=${encodeURIComponent(bag.rev)}&mode=${setup.mode}`;
|
package/llms/ui-quiz.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Quiz
|
|
2
2
|
|
|
3
|
-
A short multiple-choice quiz that keeps score: an astronomy club's star-chart check, a refresher round before a test, a pub quiz warm-up, a training check for new staff. Reach for it when the app asks a handful of questions one at a time, says right or wrong after each answer, ends on a score and lets people come back to beat it.
|
|
3
|
+
A short multiple-choice quiz that keeps score: an astronomy club's star-chart check, a refresher round before a test, a pub quiz warm-up, a training check for new staff. Reach for it when the app asks a handful of questions one at a time, says right or wrong after each answer, ends on a score and lets people come back to beat it. Every answer is its own document the moment it is checked, keyed to its attempt, so a reload or another device opens the quiz at the question the person reached, their past attempts are there on the next visit, and the score is computed from the answers.
|
|
4
4
|
|
|
5
5
|
Built from @vibes.diy/ui components; persisted state lives in Fireproof. Every write surface is gated on `useVibe(dbName).can`.
|
|
6
6
|
|
|
7
7
|
## The block
|
|
8
8
|
|
|
9
|
-
One view with one job: answer the questions, then keep the score. A `Heading` and a muted line open the page. The quiz sits on a `Card`: an `Eyebrow` with the question number beside an `info` `Badge` counting correct answers so far (it steps aside on the result, which states the score once), and a `Progress` (`info`) across the top. Each question is a `Heading level={2}` over a `RadioGroup`; `Check answer` is the view's one lead, then the answer shows as a `Badge` (`up` right, `down` wrong) with the right option in muted `Text`, and the lead becomes `Next question`. The result swaps in an `IconTile` (`up` for a pass, `warn` otherwise), the score and a recap of every question with its own `up` or `down` `Badge`. `
|
|
9
|
+
One view with one job: answer the questions, then keep the score. A `Heading` and a muted line open the page. The quiz sits on a `Card`: an `Eyebrow` with the question number beside an `info` `Badge` counting correct answers so far (it steps aside on the result, which states the score once), and a `Progress` (`info`) across the top. Each question is a `Heading level={2}` over a `RadioGroup`; `Check answer` is the view's one lead, then the answer shows as a `Badge` (`up` right, `down` wrong) with the right option in muted `Text`, and the lead becomes `Next question`. The result swaps in an `IconTile` (`up` for a pass, `warn` otherwise), the score and a recap of every question with its own `up` or `down` `Badge`. A quiet `Play again` sits beside a line saying the attempt is kept. A signed-in person's finished attempts sit below as `RowCard`s, newest first, each with a `Badge` toned by how it went. Keeping answers waits on its `can` verdict from `useVibe("quiz")`, the database the attempts live in: a `Skeleton` inside an `aria-busy` wrapper while it resolves, a `Sign in to keep your answers` lead wired to `useViewer().requestLogin()` for a visitor who has not signed in, and a sentence in the app's own words when keeping is closed. Anyone can take the quiz without signing in; a visitor's answers stay on the page, and the copy invites them to sign in so every answer is kept as they go.
|
|
10
10
|
|
|
11
11
|
### `App.jsx`
|
|
12
12
|
```jsx
|
|
@@ -71,67 +71,87 @@ const when = (ms) => new Date(ms).toLocaleDateString(undefined, { month: "short"
|
|
|
71
71
|
|
|
72
72
|
export default function App() {
|
|
73
73
|
const { database, useLiveQuery } = useFireproof("quiz");
|
|
74
|
-
const { docs } = useLiveQuery("type", { key: "attempt" });
|
|
74
|
+
const { docs: attempts } = useLiveQuery("type", { key: "attempt" });
|
|
75
75
|
const { can, me } = useVibe("quiz");
|
|
76
76
|
const { requestLogin } = useViewer();
|
|
77
77
|
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
const [choice, setChoice] = useState("");
|
|
81
|
-
const [revealed, setRevealed] = useState(false);
|
|
82
|
-
const [results, setResults] = useState([]);
|
|
83
|
-
const [saving, setSaving] = useState(false);
|
|
84
|
-
const [savedResults, setSavedResults] = useState(undefined);
|
|
85
|
-
|
|
86
|
-
const question = QUESTIONS[step];
|
|
87
|
-
const score = results.filter(Boolean).length;
|
|
88
|
-
const done = results.length === TOTAL;
|
|
89
|
-
const lastRight = results[results.length - 1];
|
|
90
|
-
|
|
91
|
-
// One document per saved attempt; this person's, newest first.
|
|
78
|
+
// This person's attempts, newest first. One without `finishedAt` is the quiz they are partway
|
|
79
|
+
// through: a reload, another device or another tab opens it at the question they reached.
|
|
92
80
|
const mine = me
|
|
93
|
-
?
|
|
94
|
-
.filter((d) => d.quiz === QUIZ_ID && d.authorHandle === me.userHandle)
|
|
95
|
-
.sort((a, b) => b.createdAt - a.createdAt)
|
|
96
|
-
.slice(0, 5)
|
|
81
|
+
? attempts.filter((d) => d.quiz === QUIZ_ID && d.authorHandle === me.userHandle).sort((a, b) => b.createdAt - a.createdAt)
|
|
97
82
|
: [];
|
|
83
|
+
const open = mine.find((a) => !a.finishedAt);
|
|
84
|
+
const finished = mine.filter((a) => a.finishedAt).slice(0, 5);
|
|
98
85
|
|
|
99
|
-
|
|
100
|
-
|
|
86
|
+
const [choice, setChoice] = useState("");
|
|
87
|
+
// The answer just checked, kept on screen until Next; the saved row is the record.
|
|
88
|
+
const [shown, setShown] = useState(null);
|
|
89
|
+
// The attempt whose result is on screen once its last answer lands.
|
|
90
|
+
const [doneId, setDoneId] = useState(null);
|
|
91
|
+
// A new attempt's id is made once, so the gate and both puts check one complete record.
|
|
92
|
+
const [newAttemptId, setNewAttemptId] = useState(() => "attempt-" + crypto.randomUUID());
|
|
93
|
+
const [pageAnswers, setPageAnswers] = useState([]);
|
|
101
94
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
95
|
+
// One `answer` document per question, keyed by its attempt: the attempt's answers are a query, and
|
|
96
|
+
// every score, recap and later view (which question trips people up) is computed from them.
|
|
97
|
+
const attemptId = open?._id ?? doneId ?? newAttemptId;
|
|
98
|
+
const { docs: rows } = useLiveQuery("attemptId", { key: attemptId });
|
|
99
|
+
const saved = rows.filter((d) => d.type === "answer").sort((a, b) => a.step - b.step);
|
|
100
|
+
|
|
101
|
+
// The answer this Check would save, complete, so the verdict is on the exact record the put writes.
|
|
102
|
+
const nextStep = shown ? shown.step : saved.length;
|
|
103
|
+
const candidate = {
|
|
104
|
+
_id: `${attemptId}:${nextStep}`,
|
|
105
|
+
type: "answer",
|
|
106
|
+
attemptId,
|
|
107
|
+
quiz: QUIZ_ID,
|
|
108
|
+
step: nextStep,
|
|
109
|
+
choice,
|
|
110
|
+
right: choice === QUESTIONS[nextStep]?.answer,
|
|
111
|
+
authorHandle: me?.userHandle,
|
|
112
|
+
};
|
|
113
|
+
// A signed-in person keeps each answer as it is made, when `can` says so. A visitor plays in the page.
|
|
114
|
+
const canKeep = can.create(candidate);
|
|
115
|
+
const keeping = Boolean(me) && !canKeep.pending && canKeep.ok;
|
|
116
|
+
const answers = keeping ? saved : pageAnswers;
|
|
117
|
+
|
|
118
|
+
const step = shown ? shown.step : answers.length;
|
|
119
|
+
const done = !shown && answers.length === TOTAL;
|
|
120
|
+
const question = QUESTIONS[step];
|
|
121
|
+
const score = answers.filter((a) => a.right).length;
|
|
122
|
+
// Next waits until the checked answer is a row (and, on the last question, until the attempt is
|
|
123
|
+
// finished), so the next question is read from the saved answers rather than racing them.
|
|
124
|
+
const landed = !shown || !keeping || (shown.step === TOTAL - 1 ? doneId !== null : saved.length > shown.step);
|
|
106
125
|
|
|
107
|
-
function
|
|
108
|
-
|
|
126
|
+
async function check() {
|
|
127
|
+
const entry = { step, choice, right: choice === question.answer };
|
|
128
|
+
setShown(entry);
|
|
109
129
|
setChoice("");
|
|
110
|
-
|
|
130
|
+
if (!keeping) return setPageAnswers((a) => [...a, entry]);
|
|
131
|
+
// The attempt is written with its first answer, so the person's place exists from step one.
|
|
132
|
+
const attempt = open ?? { _id: attemptId, type: "attempt", quiz: QUIZ_ID, authorHandle: me.userHandle, createdAt: Date.now() };
|
|
133
|
+
if (!open) await database.put(attempt);
|
|
134
|
+
// A deterministic id per question: checking the same question twice rewrites one row, never two.
|
|
135
|
+
await database.put({ ...candidate, ...entry, answeredAt: Date.now() });
|
|
136
|
+
if (step === TOTAL - 1) {
|
|
137
|
+
// The score stored on the attempt is a snapshot beside the answers, for lists that read attempts alone.
|
|
138
|
+
const correct = score + (entry.right ? 1 : 0);
|
|
139
|
+
await database.put({ ...attempt, correct, total: TOTAL, finishedAt: Date.now() });
|
|
140
|
+
setDoneId(attempt._id);
|
|
141
|
+
}
|
|
111
142
|
}
|
|
112
143
|
|
|
113
144
|
function playAgain() {
|
|
114
|
-
setStep(0);
|
|
115
145
|
setChoice("");
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
async function saveScore() {
|
|
122
|
-
setSaving(true);
|
|
123
|
-
try {
|
|
124
|
-
await database.put({ type: "attempt", quiz: QUIZ_ID, correct: score, total: TOTAL, authorHandle: me?.userHandle, createdAt: Date.now() });
|
|
125
|
-
// Marks this exact attempt as saved, so the button can't post it twice.
|
|
126
|
-
setSavedResults(results);
|
|
127
|
-
} finally {
|
|
128
|
-
setSaving(false);
|
|
129
|
-
}
|
|
146
|
+
setShown(null);
|
|
147
|
+
setDoneId(null);
|
|
148
|
+
setNewAttemptId("attempt-" + crypto.randomUUID());
|
|
149
|
+
setPageAnswers([]);
|
|
130
150
|
}
|
|
131
151
|
|
|
132
152
|
let ending;
|
|
133
|
-
if (
|
|
134
|
-
else if (
|
|
153
|
+
if (keeping) ending = <Text muted>Kept. It is in your attempts below.</Text>;
|
|
154
|
+
else if (canKeep.pending)
|
|
135
155
|
ending = (
|
|
136
156
|
<div aria-busy="true">
|
|
137
157
|
<Skeleton variant="row" />
|
|
@@ -141,18 +161,12 @@ export default function App() {
|
|
|
141
161
|
ending = (
|
|
142
162
|
<Stack gap={2}>
|
|
143
163
|
<Text size="sm" muted>
|
|
144
|
-
Sign in
|
|
164
|
+
Sign in and every answer is kept as you go, so you can pick up where you left off.
|
|
145
165
|
</Text>
|
|
146
|
-
<Button onClick={requestLogin}>Sign in to
|
|
166
|
+
<Button onClick={requestLogin}>Sign in to keep your answers</Button>
|
|
147
167
|
</Stack>
|
|
148
168
|
);
|
|
149
|
-
else
|
|
150
|
-
else
|
|
151
|
-
ending = (
|
|
152
|
-
<Button loading={saving} onClick={saveScore}>
|
|
153
|
-
Save score
|
|
154
|
-
</Button>
|
|
155
|
-
);
|
|
169
|
+
else ending = <Text muted>Scores aren't being kept right now. Play on for practice.</Text>;
|
|
156
170
|
|
|
157
171
|
const passed = score >= PASS;
|
|
158
172
|
|
|
@@ -171,7 +185,7 @@ export default function App() {
|
|
|
171
185
|
<Eyebrow>{done ? "Finished" : `Question ${step + 1} of ${TOTAL}`}</Eyebrow>
|
|
172
186
|
{!done && <Badge tone="info">{score} correct</Badge>}
|
|
173
187
|
</Row>
|
|
174
|
-
<Progress value={
|
|
188
|
+
<Progress value={answers.length} max={TOTAL} tone="info" label="Quiz progress" />
|
|
175
189
|
</Stack>
|
|
176
190
|
|
|
177
191
|
{done ? (
|
|
@@ -188,7 +202,7 @@ export default function App() {
|
|
|
188
202
|
<Stack gap={2}>
|
|
189
203
|
{QUESTIONS.map((item, i) => (
|
|
190
204
|
<Row key={item.q} gap={2} wrap={false}>
|
|
191
|
-
<Badge tone={
|
|
205
|
+
<Badge tone={answers[i]?.right ? "up" : "down"}>{answers[i]?.right ? "Right" : "Missed"}</Badge>
|
|
192
206
|
<Text size="sm" muted truncate>
|
|
193
207
|
{item.q}
|
|
194
208
|
</Text>
|
|
@@ -205,18 +219,20 @@ export default function App() {
|
|
|
205
219
|
) : (
|
|
206
220
|
<Stack gap={4}>
|
|
207
221
|
<Heading level={2}>{question.q}</Heading>
|
|
208
|
-
<RadioGroup label="Your answer" value={choice} onChange={setChoice} options={question.options} disabled={
|
|
209
|
-
{
|
|
222
|
+
<RadioGroup label="Your answer" value={shown ? shown.choice : choice} onChange={setChoice} options={question.options} disabled={Boolean(shown)} />
|
|
223
|
+
{shown && (
|
|
210
224
|
<Row gap={2} wrap={false}>
|
|
211
|
-
<Badge tone={
|
|
212
|
-
{!
|
|
225
|
+
<Badge tone={shown.right ? "up" : "down"}>{shown.right ? "Correct" : "Not quite"}</Badge>
|
|
226
|
+
{!shown.right && <Text muted>The answer is “{answerLabel(question)}”.</Text>}
|
|
213
227
|
</Row>
|
|
214
228
|
)}
|
|
215
229
|
<Row justify="end">
|
|
216
|
-
{
|
|
217
|
-
<Button onClick={
|
|
230
|
+
{shown ? (
|
|
231
|
+
<Button disabled={!landed} onClick={() => setShown(null)}>
|
|
232
|
+
Next question
|
|
233
|
+
</Button>
|
|
218
234
|
) : (
|
|
219
|
-
<Button disabled={!choice} onClick={check}>
|
|
235
|
+
<Button disabled={!choice || (Boolean(me) && canKeep.pending)} onClick={check}>
|
|
220
236
|
Check answer
|
|
221
237
|
</Button>
|
|
222
238
|
)}
|
|
@@ -226,11 +242,11 @@ export default function App() {
|
|
|
226
242
|
</Stack>
|
|
227
243
|
</Card>
|
|
228
244
|
|
|
229
|
-
{
|
|
245
|
+
{finished.length > 0 && (
|
|
230
246
|
<Stack gap={3}>
|
|
231
247
|
<Heading level={2}>Your attempts</Heading>
|
|
232
248
|
<Stack gap={2}>
|
|
233
|
-
{
|
|
249
|
+
{finished.map((a) => (
|
|
234
250
|
<RowCard key={a._id}>
|
|
235
251
|
<Row justify="between" wrap={false}>
|
|
236
252
|
<Text>
|
|
@@ -238,7 +254,7 @@ export default function App() {
|
|
|
238
254
|
</Text>
|
|
239
255
|
<Row gap={2} wrap={false}>
|
|
240
256
|
<Text size="sm" muted>
|
|
241
|
-
{when(a.
|
|
257
|
+
{when(a.finishedAt)}
|
|
242
258
|
</Text>
|
|
243
259
|
<Badge tone={a.correct === a.total ? "up" : a.correct >= PASS ? "info" : "warn"}>
|
|
244
260
|
{a.correct === a.total ? "Perfect" : a.correct >= PASS ? "Passed" : "Practise"}
|
|
@@ -258,8 +274,9 @@ export default function App() {
|
|
|
258
274
|
|
|
259
275
|
## Adapting
|
|
260
276
|
|
|
261
|
-
- Change the questions, not the flow: each one is `{ q, options: [{ value, label }], answer }
|
|
262
|
-
- Keep
|
|
277
|
+
- Change the questions, not the flow: each one is `{ q, options: [{ value, label }], answer }`; the attempt document is written with the first answer, each answer is its own `answer` document with `attemptId`, `step`, the `choice` and whether it was `right`, and the attempt gains `finishedAt` and a score snapshot with the last one.
|
|
278
|
+
- Keep the person's own picks, not only the result: a personality quiz saves each answer's `choice` (and the trait it scores) and computes the type from the answers, so a reload resumes, a retake can be compared answer by answer, and a later view can show which questions moved the result.
|
|
279
|
+
- Keep one attempt document per run and compute everything else (best score, average, a class board) from them at read time; a single "best score" document that each attempt rewrites loses scores when two people finish at once.
|
|
263
280
|
- Store what a later view might group or sort by on the attempt (`quiz` for which quiz, `correct`, `total`, a `level`), and give each quiz its own `QUIZ_ID` so several quizzes can share one database.
|
|
264
281
|
- A board of everyone's scores names each player with `useViewer()`'s `ViewerTag` from the stored `authorHandle`. Scores people would rather keep to themselves (a staff assessment, a medical exam drill) need an access function that limits who can read them before they are shown to anyone else.
|
|
265
282
|
- A new write surface gets its own verdict: `can.create(draft)` with the fields the write stamps, `can.edit(doc)` or `can.delete(doc)` on the document it changes, always on `useVibe` of the database it writes.
|
package/llms/ui-storefront.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Storefront
|
|
2
2
|
|
|
3
|
-
A small shop: product cards to browse, a category filter and a search, a bag that adds things up, and a checkout that places the order. It fits a potter's ceramics, a bakery's preorders, a club's merch table or a school fair's stall. Reach for it whenever the app's core is a short catalogue that people pick from and then order. The catalogue is the owner's: each thing for sale is a `product` record the owner adds on the app's own Products screen, with its name, price, a short line, a category and a photo, so changing what the shop sells is an edit in the app, never a rebuild.
|
|
3
|
+
A small shop: product cards to browse, a category filter and a search, a bag that adds things up, and a checkout that places the order. It fits a potter's ceramics, a bakery's preorders, a club's merch table or a school fair's stall. Reach for it whenever the app's core is a short catalogue that people pick from and then order. The catalogue is the owner's: each thing for sale is a `product` record the owner adds on the app's own Products screen, with its name, price, a short line, a category and a photo, so changing what the shop sells is an edit in the app, never a rebuild. A signed-in buyer's bag is saved as they shop: an open order and one line document per product, keyed by the order's id, so the bag is there after a reload or on another device, and placing it moves that same order to received. The shop can see what to make, line by line, and the buyer can see what they ordered. It records orders; taking card payment is the `stripe` skill, which reads these same product records.
|
|
4
4
|
|
|
5
5
|
Built from @vibes.diy/ui components; persisted state lives in Fireproof. Every write surface is gated on `useVibe(dbName).can`.
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ Two screens, one job each. The **Shop** fills the bag and places the order: a `N
|
|
|
10
10
|
|
|
11
11
|
The **Products** screen is the owner's, behind `can.create` on a product draft: a form for the name, price, short line, category and photo, then one row per product whose price edits in place and whose `On sale` checkbox puts it in front of buyers or takes it away. The catalogue starts empty, and an owner who opens an empty shop lands on this screen with "Add the first thing you sell"; a visitor sees a warm `Empty` until the first product goes on sale. Every price is a whole number in the currency's smallest unit (cents for usd, whole yen for jpy) beside its `currency`, the unit card payments charge in, and the page shows, edits and adds prices through that unit.
|
|
12
12
|
|
|
13
|
-
An order is
|
|
13
|
+
An order is a document with its lines beside it: each `line` carries the `orderId`, the product, the quantity and, once placed, the title and unit price it was bought at, and the order holds the totals, the currency and the buyer's handle, so a later price change never rewrites an order already placed and every line can be read, counted and fixed on its own; the person's own orders list under the bag, each with a `Badge` for its status (`info` received, `warn` ready to collect, `up` collected). Checkout waits on its `can` verdict from `useVibe("orders")`: a `Skeleton` inside an `aria-busy` wrapper while it resolves, a sentence in the app's own words when ordering is closed, and for a visitor who has not signed in a `Sign in to place your order` lead wired to `useViewer().requestLogin()`, with the bag they filled kept in place. Sign-in is required here, unlike a local-first note, because a signed-out write stays on the device until sign-in: an order placed that way would never reach the shop. That sign-in lead belongs to the pay-when-you-collect order alone: a shop that takes card payment with the `stripe` skill shows Pay to every visitor, signed in or not, because Stripe's own page takes the buyer's email and sends the receipt, and it asks for sign-in only when the owner asked for it.
|
|
14
14
|
|
|
15
15
|
### `App.jsx`
|
|
16
16
|
```jsx
|
|
@@ -213,9 +213,29 @@ export default function App() {
|
|
|
213
213
|
|
|
214
214
|
const [category, setCategory] = useState("all");
|
|
215
215
|
const [query, setQuery] = useState("");
|
|
216
|
-
//
|
|
217
|
-
|
|
216
|
+
// A signed-in buyer's bag is their order in the making: an `order` with status "open" and one
|
|
217
|
+
// `line` document per product, keyed by its orderId. Every Add writes its line at once, so the bag
|
|
218
|
+
// is there after a reload and on their phone, and placing the order moves the same id along.
|
|
219
|
+
const mine = me ? orders.filter((o) => o.authorHandle === me.userHandle).sort((a, b) => b.createdAt - a.createdAt) : [];
|
|
220
|
+
const open = mine.find((o) => o.status === "open");
|
|
221
|
+
const placed = mine.filter((o) => o.status !== "open");
|
|
222
|
+
const { docs: lineDocs } = useLiveQuery("orderId", { key: open?._id ?? "" });
|
|
223
|
+
// The verdict for the order this bag becomes, carrying the fields change() stamps on it.
|
|
224
|
+
const orderDraft = { type: "order", status: "open", authorHandle: me?.userHandle };
|
|
225
|
+
const canOrder = can.create(orderDraft);
|
|
226
|
+
// A line write and the move to received are their own decisions, each checked on the record it writes.
|
|
227
|
+
// The line verdict reads one representative line; access.js holds every line to its buyer the same way.
|
|
228
|
+
const canLine = can.create({ type: "line", orderId: open?._id ?? "order-new", productId: "", qty: 1, authorHandle: me?.userHandle });
|
|
229
|
+
const canPlace = open ? can.edit({ ...open, status: "received" }) : canOrder;
|
|
230
|
+
const keeping = Boolean(me) && !canOrder.pending && canOrder.ok && canLine.ok;
|
|
231
|
+
// A visitor's bag stays in the page until they sign in; then their saved lines join it.
|
|
232
|
+
const [pageBag, setPageBag] = useState({});
|
|
233
|
+
const savedBag = Object.fromEntries(lineDocs.filter((l) => l.type === "line").map((l) => [l.productId, l.qty]));
|
|
234
|
+
const bag = keeping ? { ...pageBag, ...savedBag } : pageBag;
|
|
218
235
|
const [placing, setPlacing] = useState(false);
|
|
236
|
+
// The id of an order this page has started but the live query has not returned yet, so two
|
|
237
|
+
// quick Adds land on one order instead of opening two.
|
|
238
|
+
const startedOrder = useRef(null);
|
|
219
239
|
|
|
220
240
|
// One currency per bag: the shop sells in CURRENCY, so a record priced in another stays off the shelf.
|
|
221
241
|
const forSale = products.filter((p) => p.onSale && p.currency === CURRENCY).sort((a, b) => a.createdAt - b.createdAt);
|
|
@@ -230,26 +250,39 @@ export default function App() {
|
|
|
230
250
|
const count = lines.reduce((n, l) => n + l.qty, 0);
|
|
231
251
|
const subtotal = lines.reduce((n, l) => n + l.unitAmount * l.qty, 0);
|
|
232
252
|
const shipping = subtotal === 0 || subtotal >= FREE_SHIPPING ? 0 : SHIPPING;
|
|
233
|
-
const mine = me ? orders.filter((o) => o.authorHandle === me.userHandle).sort((a, b) => b.createdAt - a.createdAt) : [];
|
|
234
253
|
|
|
235
|
-
//
|
|
236
|
-
|
|
237
|
-
const
|
|
254
|
+
// One line per product, its id derived from the order and the product, so the same product
|
|
255
|
+
// twice is one line with a new quantity; a line at zero stays as a row and drops out of the bag.
|
|
256
|
+
const lineFor = (orderId, productId, qty) => ({ _id: `${orderId}:${productId}`, type: "line", orderId, productId, qty, authorHandle: me.userHandle, updatedAt: Date.now() });
|
|
238
257
|
|
|
239
|
-
function change(id, delta) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const { [id]: _gone, ...rest } =
|
|
243
|
-
return qty === 0 ? rest : { ...rest, [id]: qty };
|
|
244
|
-
}
|
|
258
|
+
async function change(id, delta) {
|
|
259
|
+
const qty = Math.min(MAX_QTY, Math.max(0, (bag[id] ?? 0) + delta));
|
|
260
|
+
if (!keeping) {
|
|
261
|
+
const { [id]: _gone, ...rest } = pageBag;
|
|
262
|
+
return setPageBag(qty === 0 ? rest : { ...rest, [id]: qty });
|
|
263
|
+
}
|
|
264
|
+
// The order is written with its first line, so the bag exists from the first Add.
|
|
265
|
+
const orderId = open?._id ?? startedOrder.current;
|
|
266
|
+
if (orderId) return database.put(lineFor(orderId, id, qty));
|
|
267
|
+
const fresh = "order-" + crypto.randomUUID();
|
|
268
|
+
startedOrder.current = fresh;
|
|
269
|
+
await database.put({ _id: fresh, ...orderDraft, currency: CURRENCY, createdAt: Date.now() });
|
|
270
|
+
await database.put(lineFor(fresh, id, qty));
|
|
245
271
|
}
|
|
246
272
|
|
|
247
273
|
async function placeOrder() {
|
|
248
274
|
setPlacing(true);
|
|
249
275
|
try {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
276
|
+
const orderId = open?._id ?? startedOrder.current ?? "order-" + crypto.randomUUID();
|
|
277
|
+
const order = open ?? { _id: orderId, ...orderDraft, currency: CURRENCY, createdAt: Date.now() };
|
|
278
|
+
// Each line keeps the title and unit price it was bought at, so a later price change never
|
|
279
|
+
// rewrites a placed order; the order keeps a snapshot of the totals beside its lines.
|
|
280
|
+
for (const l of lines) await database.put({ ...lineFor(orderId, l.productId, l.qty), title: l.title, unitAmount: l.unitAmount });
|
|
281
|
+
// A saved line whose product went off sale is not in this order: it goes to zero with it.
|
|
282
|
+
for (const l of lineDocs) if (l.type === "line" && l.qty > 0 && !lines.some((x) => x.productId === l.productId)) await database.put({ ...l, qty: 0, updatedAt: Date.now() });
|
|
283
|
+
await database.put({ ...order, status: "received", subtotal, shipping, total: subtotal + shipping, itemCount: count, placedAt: Date.now() });
|
|
284
|
+
setPageBag({});
|
|
285
|
+
startedOrder.current = null;
|
|
253
286
|
toast.success("Order placed. We'll be in touch about collection.");
|
|
254
287
|
} finally {
|
|
255
288
|
setPlacing(false);
|
|
@@ -257,7 +290,7 @@ export default function App() {
|
|
|
257
290
|
}
|
|
258
291
|
|
|
259
292
|
let checkout;
|
|
260
|
-
if (
|
|
293
|
+
if (canPlace.pending)
|
|
261
294
|
checkout = (
|
|
262
295
|
<div aria-busy="true">
|
|
263
296
|
<Skeleton variant="row" />
|
|
@@ -269,7 +302,7 @@ export default function App() {
|
|
|
269
302
|
Sign in to place your order
|
|
270
303
|
</Button>
|
|
271
304
|
);
|
|
272
|
-
else if (!
|
|
305
|
+
else if (!canPlace.ok) checkout = <Text muted>The shop isn't taking orders right now. Check back soon.</Text>;
|
|
273
306
|
else
|
|
274
307
|
checkout = (
|
|
275
308
|
<Button block disabled={count === 0} loading={placing} onClick={placeOrder}>
|
|
@@ -429,16 +462,16 @@ export default function App() {
|
|
|
429
462
|
</Stack>
|
|
430
463
|
</Card>
|
|
431
464
|
|
|
432
|
-
{
|
|
465
|
+
{placed.length > 0 && (
|
|
433
466
|
<Card variant="tight">
|
|
434
467
|
<Stack gap={3}>
|
|
435
468
|
<Heading level={3}>Your orders</Heading>
|
|
436
|
-
{
|
|
469
|
+
{placed.map((o) => (
|
|
437
470
|
<Row key={o._id} justify="between" wrap={false}>
|
|
438
471
|
<Stack gap={1}>
|
|
439
472
|
<Text num>{money(o.total, o.currency ?? CURRENCY)}</Text>
|
|
440
473
|
<Text size="sm" muted>
|
|
441
|
-
{new Date(o.createdAt).toLocaleDateString()} · {plural(o.
|
|
474
|
+
{new Date(o.placedAt ?? o.createdAt).toLocaleDateString()} · {plural(o.itemCount ?? 0, "item", "items")}
|
|
442
475
|
</Text>
|
|
443
476
|
</Stack>
|
|
444
477
|
<Badge tone={ORDER_STATUS[o.status]?.tone ?? "info"}>{ORDER_STATUS[o.status]?.label ?? "Received"}</Badge>
|
|
@@ -465,8 +498,8 @@ export default function App() {
|
|
|
465
498
|
|
|
466
499
|
- The catalogue is records, so a shop with three things and a shop with forty are the same code. It ships empty: example products for a first look go in the app's seed data, which the owner clears, and the owner adds the real ones on **Products**. Swap `CATEGORIES`, `BADGES`, the shipping rule and `CURRENCY` for the shop's own.
|
|
467
500
|
- Product records belong to the owner: `access.js` takes a `product` only from the owner (`ctx.requireRole("owner")`), with an `amount` that is a positive whole number, a three-letter lowercase `currency` and an `onSale` true or false, and puts it on a channel every visitor reads. Keep the `orders` database and the field names `title`, `amount`, `currency` and `onSale`: they are the `stripe` skill's, so its checkout reads these records and prices this bag unchanged.
|
|
468
|
-
- Keep
|
|
469
|
-
- Orders hold who bought what, so `access.js` and the app's sharing should keep each order between its buyer and the shop: a buyer creates and reads their own, the shop reads them all and moves each through `ORDER_STATUS` behind `can.edit(order)`.
|
|
501
|
+
- Keep each line a snapshot of its title, unit price and quantity once placed, and the order a snapshot of its totals: an order is a record of what was agreed, so a later price change must not touch it. Lines are their own documents keyed by `orderId`, never an array on the order, so the shop can count a product across orders, a buyer's agent can fill the same bag, and one line can change without rewriting the rest.
|
|
502
|
+
- Orders hold who bought what, so `access.js` and the app's sharing should keep each order between its buyer and the shop: a buyer creates and reads their own orders and lines (a `line` routes with the order its `orderId` names), the shop reads them all and moves each through `ORDER_STATUS` behind `can.edit(order)`.
|
|
470
503
|
- Card payment is the `stripe` skill, and it comes in when the person asks to take money: its checkout replaces `Place order` with one `pay(...)` that sends each product and its quantity, `backend.js` prices every line from these records, and the order becomes the one `/checkout` writes. Anyone pays: the `Sign in to place your order` lead goes away with `Place order`, and a guest's bag stays on the page until they pay. Until then, keep the pay-when-you-collect line truthful, and offer `▸ [pay] Take card payments with Stripe` as the capability option.
|
|
471
504
|
- A new write surface gets its own verdict: `can.create(draft)` with the fields the write stamps, `can.edit(doc)` or `can.delete(doc)` on the document it changes, always on `useVibe` of the database it writes.
|
|
472
505
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibes.diy/prompts",
|
|
3
|
-
"version": "14.3.
|
|
3
|
+
"version": "14.3.288",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"exports": {
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"license": "Apache-2.0",
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@adviser/cement": "~0.5.34",
|
|
42
|
-
"@vibes.diy/api-types": "14.3.
|
|
43
|
-
"@vibes.diy/call-ai-v2": "14.3.
|
|
44
|
-
"@vibes.diy/identity": "14.3.
|
|
45
|
-
"@vibes.diy/use-vibes-types": "14.3.
|
|
42
|
+
"@vibes.diy/api-types": "14.3.288",
|
|
43
|
+
"@vibes.diy/call-ai-v2": "14.3.288",
|
|
44
|
+
"@vibes.diy/identity": "14.3.288",
|
|
45
|
+
"@vibes.diy/use-vibes-types": "14.3.288",
|
|
46
46
|
"arktype": "~2.2.9",
|
|
47
47
|
"json-schema-faker": "~0.6.3"
|
|
48
48
|
},
|