Skip to content

Commit 111fbc3

Browse files
phasenullclaude
andauthored
TypeTorch.feedback(): player feedback as a built-in (plans/32), 0.7.0 (#16)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 15db526 commit 111fbc3

16 files changed

Lines changed: 1091 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,49 @@ TypeTorch.runDetached(() => store.StartSessionAsync(`Player_${userId}`)).then((p
384384
players who joined before the callback connected. Rows (`kind = notify`): `want`, `drop`, `optin_check`,
385385
`optin_shown`, `optin_closed`, `open`, `open_bad`, `played` (src/analytics/SCHEMA.md); the join row gets
386386
`from = "notification"`. Without backend settings (Studio) nothing is posted; rows are still written.
387+
- **`feedback()`** (plans/32, server only): player feedback as a built-in. Collect the answer in your own UI, send it
388+
to the server through your own network, and submit it there; the framework checks it and writes one analytics row
389+
(`kind = feedback`, `name = submit`) on the player's session, which the explorer's Feedback page reads:
390+
391+
```ts
392+
const feedback = TypeTorch.feedback();
393+
// Optional, once at start: the scale in code (used while the settings record has no game.feedback).
394+
feedback.configure({ scale: { id: "faces5", type: "scale", steps: 5, labels: ["BAD", "MEH", "OK", "GOOD", "GREAT"] } });
395+
// In your remote's handler (the arguments come from a client: everything is checked here).
396+
const result = feedback.submit(player, { rating, text, topic: "bug", ctx: { level: 12, map: "forest" } });
397+
if (!result.ok) warn(result.reason); // "rate_limited" | "empty" | "bad_rating" | "no_session" | "disabled"
398+
// rate_limited also has retryIn: whole seconds until the player may submit again (for "try again in 40 s").
399+
feedback.scale(); // the scale in effect, to send to clients for the UI (undefined while disabled)
400+
```
401+
402+
The config (the settings record's `game.feedback`, live: `typetorch settings set game.feedback '<json>'`; without
403+
it the game's `configure(...)`; without that the defaults):
404+
405+
```jsonc
406+
"feedback": {
407+
"scale": { "id": "faces5", "type": "scale", "steps": 5, "labels": ["BAD", "MEH", "OK", "GOOD", "GREAT"] },
408+
"maxText": 1000,
409+
"rate": { "perMinute": 2, "perDay": 20 }
410+
}
411+
```
412+
413+
| Field | Default | Meaning |
414+
|---|---|---|
415+
| `enabled` | `true` | `false` (or the whole value `false`): every submit answers `disabled` |
416+
| `scale.id` | `"stars5"` | 1-32 of `[a-z0-9_]`, on every row; give a changed scale a new id (old rows keep theirs) |
417+
| `scale.type` | `"stars"` | `thumbs` (rating 0 down / 1 up), `stars` or `scale` (rating 1..steps) |
418+
| `scale.steps` | `5` | 2..10; thumbs is always 2 |
419+
| `scale.labels` | none | one per step, lowest first (thumbs: 2, e.g. `["Down", "Up"]`); the rated step's label goes on the row |
420+
| `maxText` | `1000` | most characters of text kept (1..2000); the row also keeps at most 2000 UTF-8 bytes |
421+
| `rate.perMinute`, `rate.perDay` | `2`, `20` | accepted submits per player (in memory, kept across swaps, cleared when the player leaves) |
422+
423+
An invalid record value disables feedback (warned once per value); an invalid `configure` throws. Text is sanitised
424+
(control and invisible characters stripped, whitespace collapsed, trimmed) and capped without splitting a code point;
425+
`len` keeps the original length. `rating` must be an integer in the scale (`bad_rating`); a submit needs a rating or
426+
some text (`empty`); `no_session` when no `AnalyticsEngine` runs or the player isn't in this server. Refused submits
427+
don't count against the limits. The row's props (`scale`, `type`, `steps`, `r?`, `norm?`, `label?`, `text?`, `len`,
428+
`topic?`, `play_s`, `ctx?`) are in src/analytics/SCHEMA.md. On a client `feedback()` throws; in edit mode every
429+
submit is `disabled`.
387430
- **Edit mode** (UI Labs stories, no kernel): `running` is false, identity has defaults, `persist` keeps a local table,
388431
events never fire, and the server-only reads throw.
389432

@@ -622,7 +665,9 @@ bun run build # rbxtsc --type package -> out/
622665
`test-explorer-core` (Dex), `test-toolbox-sanitize` (the Creator Store sanitizer), `test-sha256` (SHA-256 / HMAC in util and the
623666
pairing-code fingerprint), `test-notifications` (the launch token with the contract's shared vector, intent checks,
624667
the queue: batches of 200, rev order, a swap's handover), `test-notify-server` (the notifications server against
625-
mocked services) and `test-analytics-join` (the join row's metadata; no other player's UserId). `node scripts/check-self-calls.mjs out` flags compiled functions that call themselves on their first
668+
mocked services), `test-analytics-join` (the join row's metadata; no other player's UserId) and `test-feedback`
669+
(`feedback()`: the scale config, rating normalisation, text sanitising and caps with multi-byte text, rate limits, the
670+
row's shape; run from framework/: `lune run scripts/test-feedback.luau out/`). `node scripts/check-self-calls.mjs out` flags compiled functions that call themselves on their first
626671
lines (after `bun run build`).
627672
- **Package contents:** only `out/` (no `.tsbuildinfo`), `README.md` and `LICENSE`; check with `bun pm pack --dry-run`.
628673
- **Explorer class icons:** `assets/class-icons.png` (kept locally, not in the repo: it is Roblox's own texture) is

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typetorch/framework",
3-
"version": "0.6.3",
3+
"version": "0.7.0",
44
"description": "TypeTorch framework for roblox-ts: hot-swappable modules (dependency injection, lifecycle, troves), guarded networking, hot assets and the in-game dev menu. Ships inside every TypeTorch artifact.",
55
"license": "MIT",
66
"author": "TypeTorch",

‎scripts/test-analytics-server.luau‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,9 @@ task.wait(0.6) -- joins wait for the device
514514

515515
local joins = rowsNamed(store().events.rows, "session", "join")
516516
check("two joins", #joins == 2, #joins)
517+
-- Built-ins' session lookup (feedback's play_s, plans/32).
518+
local played = loadAnalytics("rows").builtinSession(regular)
519+
check("builtinSession: the session's play seconds", played ~= nil and played.playSeconds >= 0 and played.playSeconds < 5, played and played.playSeconds)
517520
local joinNew, joinReg
518521
for _, row in joins do
519522
if row.pid == newbiePid then
@@ -846,6 +849,7 @@ local leaveProps = leave and serde.decode("json", leave.props)
846849
check("leave row", leave and leave.pid == "existingpid00000000000000000002" and leaveProps.why == "left" and leaveProps.swap60 == true)
847850
check("leave writes last", records["p/2"].last >= before and records["p/2"].pid == "existingpid00000000000000000002")
848851
check("session removed", store().players["2"] == nil)
852+
check("builtinSession: none after the leave", loadAnalytics("rows").builtinSession(regular) == nil)
849853

850854
local requestsBefore = #requests
851855
for hook in closeHooks do

0 commit comments

Comments
 (0)