@tjakoen/grain 0.1.29 → 0.1.30

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.
@@ -50,3 +50,26 @@ buttons render clean, because clicking them is the **human's** move, not AI-auth
50
50
 
51
51
  Every verb here must exist in `ai/contract.ts` and walk the usual alignment row — an action button
52
52
  in the chat is a door client like any other, so a new verb needs its reasoner branch + tests.
53
+
54
+ ## Consent notice (the desk asks before it stores anything)
55
+
56
+ A consent question is not an AI offer, so it carries no `data-action`: the app owns the policy and
57
+ the endpoint. It is still an AI message (`data-role="ai"`, grain), because the desk asks it, and its
58
+ buttons stay clean because choosing is the human's move. Use the actions row with
59
+ `data-consent="allow|deny"`, name what is stored and for how long, and make the decline real.
60
+
61
+ ```html
62
+ <div class="chat-message" data-role="ai" data-grade="grain" data-consent-notice>
63
+ <span class="chat-message__who">GRAIN</span>
64
+ <span class="chat-message__body">May the desk remember this conversation on this device with a cookie? It stores a session id for 30 days. Not now loses only the remembering.</span>
65
+ <div class="chat-message__actions">
66
+ <button class="btn" data-variant="soft" data-consent="allow" type="button">Remember this chat</button>
67
+ <button class="btn" data-variant="outline" data-consent="deny" type="button">Not now</button>
68
+ </div>
69
+ </div>
70
+ ```
71
+
72
+ The app sets the server-issued id on `data-desk-session` (see `scripts/ai-dispatch.js`) or as
73
+ `window.__DESK_SESSION__` before the dispatcher runs, handles the two buttons, sets the cookie only
74
+ on allow, and dismisses the notice after either choice. A static site with no consent endpoint
75
+ simply never renders the notice.
@@ -20,6 +20,19 @@ function cssFiles(dir: string, out: string[] = []): string[] {
20
20
  const HEX = /#[0-9a-fA-F]{3,8}\b/g;
21
21
  const FUNC = /\b(rgb|rgba|hsl|hsla)\(/;
22
22
 
23
+ test("the dense type steps sit below the caption step, in order", () => {
24
+ const css = readFileSync(join(import.meta.dir, "../styles/variables.css"), "utf8");
25
+ const rem = (name: string) => {
26
+ const m = css.match(new RegExp(`--${name}:\\s*([\\d.]+)rem`));
27
+ return m ? Number(m[1]) : Number.NaN;
28
+ };
29
+ expect(rem("text-3xs")).toBe(0.625);
30
+ expect(rem("text-2xs")).toBe(0.6875);
31
+ expect(rem("text-xs")).toBe(0.8125);
32
+ expect(rem("text-3xs")).toBeLessThan(rem("text-2xs"));
33
+ expect(rem("text-2xs")).toBeLessThan(rem("text-xs"));
34
+ });
35
+
23
36
  test("no component stylesheet hardcodes a color (tokens only, ever)", () => {
24
37
  const offenders: string[] = [];
25
38
  for (const f of cssFiles(import.meta.dir)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tjakoen/grain",
3
- "version": "0.1.29",
3
+ "version": "0.1.30",
4
4
  "description": "GRAIN — an AI-interaction design system where every surface is operable by both a human and an AI through one shared vocabulary.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -17,8 +17,17 @@ import { createSpotlight } from "/scripts/ai-spotlight.js";
17
17
  (() => {
18
18
  "use strict";
19
19
 
20
- // A stable session id for this tab; the server pushes results back on it.
20
+ // A stable session id for this tab; the server pushes results back on it. A server that issues
21
+ // and validates ids can hand one in (a data attribute or a global, set before this script runs);
22
+ // the per-tab UUID stays the fallback for a fully static site, so a page with no server still
23
+ // works. The id is validated here too, because it ends up in a query string: 128 safe characters
24
+ // or it is ignored and the UUID is used.
25
+ const provided =
26
+ (document.documentElement.dataset.deskSession || "") ||
27
+ (document.body.dataset.deskSession || "") ||
28
+ (typeof window.__DESK_SESSION__ === "string" ? window.__DESK_SESSION__ : "");
21
29
  const session =
30
+ (provided.length > 0 && provided.length <= 128 && /^[A-Za-z0-9_-]+$/.test(provided) && provided) ||
22
31
  (crypto && crypto.randomUUID && crypto.randomUUID()) ||
23
32
  "s-" + Math.random().toString(36).slice(2) + performance.now();
24
33
 
@@ -20,6 +20,14 @@ test("ai-dispatch.js registers a case for every RenderOpKind contract.ts declare
20
20
  for (const kind of kinds) expect(dispatch).toContain(`case "${kind}":`);
21
21
  });
22
22
 
23
+ test("the client takes a server-issued session id before falling back to the per-tab UUID", async () => {
24
+ const dispatch = await read("./ai-dispatch.js");
25
+ expect(dispatch).toContain("dataset.deskSession");
26
+ expect(dispatch).toContain("__DESK_SESSION__");
27
+ expect(dispatch.indexOf("dataset.deskSession")).toBeLessThan(dispatch.indexOf("crypto.randomUUID"));
28
+ expect(dispatch).toContain("provided.length <= 128");
29
+ });
30
+
23
31
  test("SAFE_NAV_HREF in ai-dispatch.js matches contract.ts's isSafeNavigateHref regex verbatim", async () => {
24
32
  const [dispatch, contract] = await Promise.all([read("./ai-dispatch.js"), read("../ai/contract.ts")]);
25
33
  const dispatchRe = dispatch.match(/const SAFE_NAV_HREF = (\/.*\/);/)?.[1];
@@ -82,6 +82,11 @@
82
82
  --font-weight-bold: 700; /* reserved for rare extra punch */
83
83
 
84
84
  /* type scale (mobile-first, rem @ 16px) — fluid display via clamp */
85
+ /* Dense instrument steps, below the caption. Only for packed panels and meters, never body copy,
86
+ and only where the foreground clears 4.5:1 at that size; a hint that cannot be read is not a
87
+ hint. The Nest panel is the surface these were added for (2026-11-08). */
88
+ --text-3xs: 0.625rem; /* 10px dense instrument: meter hints, micro-labels */
89
+ --text-2xs: 0.6875rem; /* 11px dense instrument: panel labels, captions */
85
90
  --text-xs: 0.8125rem; /* 13px caption */
86
91
  --text-sm: 0.875rem; /* 14px label / eyebrow */
87
92
  --text-base: 0.9375rem; /* 15px body */