@chalky/chalky 0.1.4 → 0.1.5

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.
Files changed (104) hide show
  1. package/README.md +10 -5
  2. package/{app → agent}/SYSTEM.md +15 -11
  3. package/agent/extensions/app/README.md +68 -0
  4. package/{app/extensions/ui → agent/extensions/app}/agents.js +22 -16
  5. package/agent/extensions/app/guide.md +5 -0
  6. package/agent/extensions/app/index.ts +66 -0
  7. package/{app/extensions/ui/skills/agent-apps → agent/extensions/app/skills/app-agents}/SKILL.md +17 -18
  8. package/{app/extensions/boards → agent/extensions/board}/browser.js +25 -23
  9. package/{app/extensions/boards → agent/extensions/board}/guide.md +1 -1
  10. package/{app/extensions/boards → agent/extensions/board}/index.ts +32 -30
  11. package/agent/extensions/card/README.md +88 -0
  12. package/agent/extensions/card/blocks/Button.js +34 -0
  13. package/{app/extensions/ui/components → agent/extensions/card/blocks}/Column.js +2 -2
  14. package/agent/extensions/card/blocks/Markdown.js +37 -0
  15. package/{app/extensions/ui/components/Card.js → agent/extensions/card/blocks/Panel.js} +3 -3
  16. package/{app/extensions/ui/components → agent/extensions/card/blocks}/Row.js +2 -2
  17. package/{app/extensions/ui/components → agent/extensions/card/blocks}/TextField.js +3 -3
  18. package/{app/extensions/ui → agent/extensions/card}/browser.js +155 -129
  19. package/agent/extensions/card/guide.md +13 -0
  20. package/agent/extensions/card/index.ts +370 -0
  21. package/{app/extensions/commands → agent/extensions/command}/browser.js +3 -3
  22. package/agent/extensions/command/guide.md +2 -0
  23. package/{app/extensions/commands → agent/extensions/command}/index.ts +14 -16
  24. package/agent/extensions/doodle/README.md +57 -0
  25. package/agent/extensions/doodle/browser.js +1013 -0
  26. package/agent/extensions/doodle/guide.md +22 -0
  27. package/agent/extensions/doodle/index.ts +274 -0
  28. package/agent/extensions/file/browser.js +143 -0
  29. package/agent/extensions/file/guide.md +5 -0
  30. package/{app/extensions/files → agent/extensions/file}/index.ts +34 -16
  31. package/{app/extensions/frames → agent/extensions/frame}/README.md +13 -13
  32. package/{app/extensions/frames → agent/extensions/frame}/browser.js +20 -18
  33. package/agent/extensions/frame/guide.md +3 -0
  34. package/{app/extensions/frames → agent/extensions/frame}/index.ts +27 -31
  35. package/{app/extensions/ui_history → agent/extensions/history}/browser.js +18 -18
  36. package/{app/extensions/ui_history → agent/extensions/history}/index.ts +32 -33
  37. package/{app → agent}/extensions/mcp/browser.js +1 -1
  38. package/agent/extensions/mcp/guide.md +3 -0
  39. package/{app → agent}/extensions/mcp/index.ts +2 -4
  40. package/{app/extensions/login → agent/extensions/model}/browser.js +67 -67
  41. package/{app → agent}/extensions/model/index.ts +8 -4
  42. package/{app/extensions/login/index.ts → agent/extensions/model/login.ts} +47 -46
  43. package/agent/extensions/note/README.md +35 -0
  44. package/agent/extensions/note/browser.js +356 -0
  45. package/agent/extensions/note/guide.md +8 -0
  46. package/agent/extensions/note/index.ts +192 -0
  47. package/{app → agent}/extensions/page/index.ts +2 -2
  48. package/{app → agent}/extensions/page/page.html +55 -49
  49. package/agent/extensions/prompt/index.ts +38 -0
  50. package/{app → agent}/extensions/reload/index.ts +3 -3
  51. package/{app → agent}/extensions/screen/browser.js +4 -4
  52. package/{app → agent}/extensions/screen/index.ts +11 -11
  53. package/{app/extensions/steps → agent/extensions/step}/index.ts +1 -1
  54. package/{app/extensions/swarm → agent/extensions/team}/README.md +19 -19
  55. package/{app/extensions/swarm → agent/extensions/team}/guide.md +4 -4
  56. package/{app/extensions/swarm → agent/extensions/team}/index.ts +41 -66
  57. package/{app/extensions/versions → agent/extensions/version}/browser.js +10 -10
  58. package/{app/extensions/versions → agent/extensions/version}/index.ts +39 -54
  59. package/{app → agent}/extensions/viewer/README.md +4 -4
  60. package/{app → agent}/extensions/viewer/browser.js +8 -8
  61. package/agent/extensions/viewer/guide.md +3 -0
  62. package/{app → agent}/extensions/viewer/index.ts +22 -17
  63. package/{app → agent}/extensions/voice/browser.js +4 -3
  64. package/{app → agent}/extensions/voice/index.ts +8 -6
  65. package/{app/extensions/ui → agent/extensions/voice}/voice.js +5 -5
  66. package/agent/settings.json +8 -0
  67. package/{app/extensions/ui/skills/ui-check → agent/skills/browser-check}/SKILL.md +4 -4
  68. package/{app/extensions/ui/skills/ui-check → agent/skills/browser-check}/scripts/check.mjs +1 -1
  69. package/{app/extensions/ui/skills/ui-design → agent/skills/design}/SKILL.md +14 -14
  70. package/agent/skills/extension-map/SKILL.md +56 -0
  71. package/{app → agent}/skills/write-skill/SKILL.md +1 -1
  72. package/bin/chalky.mjs +2 -2
  73. package/package.json +8 -8
  74. package/server.ts +151 -58
  75. package/app/extensions/appdata/README.md +0 -10
  76. package/app/extensions/appdata/guide.md +0 -4
  77. package/app/extensions/appdata/index.ts +0 -47
  78. package/app/extensions/commands/guide.md +0 -3
  79. package/app/extensions/doodle/README.md +0 -15
  80. package/app/extensions/doodle/browser.js +0 -398
  81. package/app/extensions/doodle/guide.md +0 -6
  82. package/app/extensions/doodle/index.ts +0 -54
  83. package/app/extensions/files/browser.js +0 -96
  84. package/app/extensions/files/guide.md +0 -7
  85. package/app/extensions/frames/guide.md +0 -7
  86. package/app/extensions/mcp/guide.md +0 -5
  87. package/app/extensions/point/README.md +0 -22
  88. package/app/extensions/point/browser.js +0 -247
  89. package/app/extensions/point/guide.md +0 -6
  90. package/app/extensions/point/index.ts +0 -112
  91. package/app/extensions/prompt/index.ts +0 -19
  92. package/app/extensions/ui/README.md +0 -69
  93. package/app/extensions/ui/components/App.js +0 -28
  94. package/app/extensions/ui/components/Button.js +0 -28
  95. package/app/extensions/ui/components/Markdown.js +0 -37
  96. package/app/extensions/ui/guide.md +0 -7
  97. package/app/extensions/ui/index.ts +0 -291
  98. package/app/extensions/viewer/guide.md +0 -5
  99. package/app/mcp.json +0 -3
  100. package/app/settings.json +0 -3
  101. package/app/skills/plugin-map/SKILL.md +0 -49
  102. package/app/ui/apps/.keep +0 -0
  103. /package/{app/extensions/ui/components → agent/extensions/card/blocks}/Table.js +0 -0
  104. /package/{app/extensions/ui/components → agent/extensions/card/blocks}/Text.js +0 -0
@@ -1,39 +1,39 @@
1
- // Boards: the main space is several numbered boards, and everything on it (surfaces, frames, notes; a doodle's
1
+ // Boards: the main space is several numbered boards, and everything on it (cards, frames, notes; a doodle's
2
2
  // steps when sent) has a board number. Numbers are never reused: remove board 2 and the rest stay 1, 3, 4, so "board 3" keeps
3
3
  // meaning the same board to the user and to every agent. A thing with no number is on board 1.
4
- // app/ui/boards.json {last: <last number>, boards: [numbers]}: next to surfaces.json, so a rollback of the code
4
+ // built/board.json {last: <last number>, boards: [numbers]}: next to card.json, so a rollback
5
5
  // brings back both together (read each time: never stale after one)
6
6
  // The board the user is looking at is the page's to say (in memory; board 1 until it does). browser.js: the shelf.
7
- // Tool boards(board?): the boards and what is on each, and the board the user is on. Others use host.api.boards:
7
+ // Tool boards(board?): the boards and what is on each, and the board the user is on. Others use host.api.board:
8
8
  // list() -> [numbers] has(n) add(by?) -> the new number current() -> the user's board
9
9
  // onRemove(name, fn) remove(n): see below
10
- // GET /boards {boards, current} page messages board_view {board}, board_add, board_remove {board}
11
- // event "boards" {boards, added, by}: a board was added (by "user": that page goes there); {boards, removed}
10
+ // GET /board {boards, current} page messages board_view {board}, board_add, board_remove {board}
11
+ // event "board" {boards, added, by}: a board was added (by "user": that page goes there); {boards, removed}
12
12
  import fs from "node:fs";
13
13
  import path from "node:path";
14
14
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
15
15
  import { Type } from "typebox";
16
16
 
17
17
  const host = (globalThis as any).chalky;
18
- const FILE = path.join(host.app, "ui/boards.json");
18
+ const FILE = path.join(host.built, "board.json");
19
19
  const read = () => (fs.existsSync(FILE) ? JSON.parse(fs.readFileSync(FILE, "utf8")) : { last: 1, boards: [1] });
20
20
  if (!host.shared.has("board-view")) host.shared.set("board-view", { current: 1 });
21
21
  const view = host.shared.get("board-view");
22
22
 
23
- host.api.boards = {
23
+ host.api.board = {
24
24
  list: () => read().boards as number[],
25
25
  has: (n: number) => read().boards.includes(n),
26
26
  add(by = "agent") { // by "user": the page that asked goes there
27
27
  const saved = read();
28
28
  saved.boards.push(++saved.last);
29
29
  fs.writeFileSync(FILE, JSON.stringify(saved));
30
- host.broadcast("boards", { boards: saved.boards, added: saved.last, by });
30
+ host.broadcast("board", { boards: saved.boards, added: saved.last, by });
31
31
  return saved.last;
32
32
  },
33
33
  current: () => (read().boards.includes(view.current) ? view.current : read().boards[0]),
34
34
  // Removing a board (the user's ✕, after its few seconds of Undo on the page): each extension takes its own things
35
35
  // off it (onRemove(name, fn): fn(n) deletes them and returns [{owner, what}], e.g. {owner: "agent2", what:
36
- // "surface prices"}; name: the extension's, so its reload replaces its own). Each agent that owned something gets
36
+ // "card prices"}; name: the extension's, so its reload replaces its own). Each agent that owned something gets
37
37
  // one fyi (no turn of its own: it reads it on its next one). The last board stays.
38
38
  onRemove: (name: string, fn: (n: number) => { owner?: string; what: string }[]) => removers.set(name, fn),
39
39
  remove(n: number) {
@@ -46,11 +46,11 @@ host.api.boards = {
46
46
  }
47
47
  saved.boards = saved.boards.filter((b: number) => b !== n);
48
48
  fs.writeFileSync(FILE, JSON.stringify(saved));
49
- host.broadcast("boards", { boards: saved.boards, removed: n });
49
+ host.broadcast("board", { boards: saved.boards, removed: n });
50
50
  const byOwner = new Map<string, string[]>();
51
51
  for (const g of gone) if (g.owner && host.agents.has(g.owner)) byOwner.set(g.owner, [...(byOwner.get(g.owner) ?? []), g.what]);
52
52
  for (const [owner, things] of byOwner)
53
- host.api.swarm?.fyi("user", owner, `[board removed] The user removed board ${n}; your ${things.join(", ")} went with it.`);
53
+ host.api.team?.fyi("user", owner, `[board removed] The user removed board ${n}; your ${things.join(", ")} went with it.`);
54
54
  },
55
55
  };
56
56
  // on the host, so they outlive this file's reloads (as ui's watchers)
@@ -60,39 +60,41 @@ host.shared.set("board-removers", removers);
60
60
  const result = (text: string) => ({ content: [{ type: "text" as const, text }], details: undefined });
61
61
 
62
62
  export default function (pi: ExtensionAPI) {
63
- const guide = fs.readFileSync(path.join(import.meta.dirname, "guide.md"), "utf8");
64
- pi.on("before_agent_start", (event) => { event.systemPromptOptions.sections.boards = guide; });
65
63
 
66
64
  pi.registerTool({
67
- name: "boards", label: "Boards",
65
+ name: "board_list", label: "Board list",
68
66
  description: "List the boards, what is on each, and the board the user is on. With a board: that one in detail.",
69
67
  parameters: Type.Object({ board: Type.Optional(Type.Number()) }),
70
68
  async execute(_id, a) {
71
- // what has a board: surfaces (ui/), frames not filled yet (frames/), open notes (point/); doodles aren't kept
69
+ // what has a board: cards (card/), frames not filled yet (frame/), open notes (note/), marks not cleared (doodle/)
72
70
  const of = (m: any) => Object.entries(m ?? {}) as [string, any][];
73
- const kinds = (n: number) => [of(host.shared.get("ui")?.surfaces), of(host.shared.get("frames")?.frames), of(host.shared.get("point")?.open)]
71
+ const kinds = (n: number) => [of(host.shared.get("card")?.cards), of(host.shared.get("frame")?.frames),
72
+ of(host.shared.get("note")?.notes).filter(([, r]) => r.state === "open"),
73
+ of(host.shared.get("doodle")?.groups).filter(([, r]) => r.state !== "cleared")]
74
74
  .map((list) => list.filter(([, r]) => (r.board ?? 1) === n));
75
- const head = `the user is on board ${host.api.boards.current()}`;
75
+ const head = `the user is on board ${host.api.board.current()}`;
76
76
  if (a.board === undefined)
77
- return result([head, ...host.api.boards.list().map((n: number) => {
78
- const [s, f, notes] = kinds(n);
79
- return `${n} ${[s.map(([id]) => id).join(", "), f.map(([id]) => id).join(", "), notes.map(([id]) => `note ${id}`).join(", ")]
77
+ return result([head, ...host.api.board.list().map((n: number) => {
78
+ const [s, f, notes, marks] = kinds(n);
79
+ return `${n} ${[s.map(([id]) => id).join(", "), f.map(([id]) => id).join(", "), notes.map(([id]) => `note ${id}`).join(", "),
80
+ marks.map(([id]) => `marks ${id}`).join(", ")]
80
81
  .filter(Boolean).join(" · ") || "(empty)"}`;
81
82
  })].join("\n"));
82
- if (!host.api.boards.has(a.board)) return result(`error: no board ${a.board}. Boards: ${host.api.boards.list().join(", ")}`);
83
- const [s, f, notes] = kinds(a.board);
83
+ if (!host.api.board.has(a.board)) return result(`error: no board ${a.board}. Boards: ${host.api.board.list().join(", ")}`);
84
+ const [s, f, notes, marks] = kinds(a.board);
84
85
  return result([head, `board ${a.board}:`,
85
- ...s.map(([id, r]) => ` surface ${id} · by ${r.owner} · place ${JSON.stringify(r.place)}${r.pinned ? " · pinned" : ""}`),
86
+ ...s.map(([id, r]) => ` card ${id} · by ${r.owner} · place ${JSON.stringify(r.place)}${r.pinned ? " · pinned" : ""}`),
86
87
  ...f.map(([id, r]) => ` frame ${id} "${r.text}" · ${r.sent ? `sent to ${r.to}` : "not sent"} · place ${JSON.stringify({ x: r.x, y: r.y, width: r.width, height: r.height })}`),
87
- ...notes.map(([id, r]) => ` note ${id} "${r.text}" · to ${r.to}`)].join("\n") + (s.length + f.length + notes.length ? "" : "\n (empty)"));
88
+ ...notes.map(([id, r]) => ` note ${id} "${r.thread[0]?.text}" · to ${r.to}`),
89
+ ...marks.map(([id, r]) => ` marks ${id} (${r.state}) · ${r.label}`)].join("\n") + (s.length + f.length + notes.length + marks.length ? "" : "\n (empty)"));
88
90
  },
89
91
  });
90
92
 
91
- host.routes.set("/boards", (_req: any, res: any) => res.writeHead(200, { "content-type": "application/json" })
92
- .end(JSON.stringify({ boards: host.api.boards.list(), current: host.api.boards.current() })));
93
- host.pageHandlers.set("boards", (msg: any) => {
94
- if (msg.type === "board_view" && host.api.boards.has(Number(msg.board))) view.current = Number(msg.board);
95
- else if (msg.type === "board_add") host.api.boards.add("user");
96
- else if (msg.type === "board_remove") host.api.boards.remove(Number(msg.board));
93
+ host.routes.set("/board", (_req: any, res: any) => res.writeHead(200, { "content-type": "application/json" })
94
+ .end(JSON.stringify({ boards: host.api.board.list(), current: host.api.board.current() })));
95
+ host.pageHandlers.set("board", (msg: any) => {
96
+ if (msg.type === "board_view" && host.api.board.has(Number(msg.board))) view.current = Number(msg.board);
97
+ else if (msg.type === "board_add") host.api.board.add("user");
98
+ else if (msg.type === "board_remove") host.api.board.remove(Number(msg.board));
97
99
  });
98
100
  }
@@ -0,0 +1,88 @@
1
+ # Cards (the card extension)
2
+ A card is one thing you show the user on a board in the page's main space: a form, a table, a dashboard, a game.
3
+ It shows either blocks (pieces described as JSON) or an app (a page you write). Prefer a card over editing the page
4
+ ({agent}/extensions/page/page.html). Aim for one screen; make it scroll only if the user asks.
5
+ A card shows only what you build, with no frame: when asked for a thing (a smiley, a chart), show just that thing.
6
+ Add a background, border or Panel only if the thing itself needs one. An app's page should keep a transparent
7
+ background, so it sits on the board.
8
+ Name what you build (a clear card id, block ids, ids or data-name on elements): the user points at things by name.
9
+ Blocks or an app? What the user clicks never wakes you, so the page must do everything a click should do:
10
+ - Blocks (card_show with blocks), when clicks and typing only store a value: the layout is fixed, the user types,
11
+ picks, ticks or switches tabs (Button set, when, bindings), and you read the data when they next write. Status,
12
+ tables, summaries, forms, settings, a fixed checklist, a dashboard you fill in.
13
+ - An app, when the page must work something out or change its own shape while the user uses it: compute a value
14
+ (a total, a streak, a score), add or remove items, follow rules or time (a game, a timer), draw (a chart).
15
+ Trackers, calculators, games, editors, charts.
16
+ The test: if a click or keystroke should change anything other than the value it sets, it is an app. Blocks
17
+ can't append to a list or calculate; a Button only writes the fixed value it was given.
18
+ A new block is for one part blocks can't do yet that many cards will reuse; then use it from JSON.
19
+ Before building or restyling what the user sees, load the design skill (how it should look and read).
20
+ - card_blocks (load it with tool_search): lists the blocks and their props. Read it first.
21
+ - card_show(card, blocks, data): show a card, or replace it. blocks is a flat list; each has "id", "block" (its
22
+ kind, a name from card_blocks), its props, and "children": [ids] or "child": id. One has id "root".
23
+ A prop can be {"path": "/x"} to bind it to this card's data (inputs write to it), or
24
+ {"ref": "other-card", "path": "/x"} to read another card's data live (no copy: it follows changes).
25
+ Any block can have "when": {"path": "/x", "is": value}: hidden while the data there is something else.
26
+ Tabs: Buttons with "set": {"/tab": "today"} etc., and one block per tab with "when": {"path": "/tab", "is": ...};
27
+ start the data with the first tab ({"tab": "today"}). Errors come back to you; fix and retry.
28
+ - card_show(card, app=<name>): the card shows that app, then says what it found on the board (errors, and whether
29
+ it fits its card): fix what it reports. Write the page first, in
30
+ {built}/apps/<name>/index.html (its other files next to it); the app extension's README says how an app keeps
31
+ its data and talks to the agents. height: its height in px when nothing else sizes it (default 400).
32
+ - about="...": one or two sentences on what the card is for and why it is built this way. The user reads it on
33
+ the card's back side; you read it in {built}/card.json. Keep it true when you change things.
34
+ - options=[{"label", "blocks" or "app", "data"}, ...] instead of blocks or app: when you are not sure what the user
35
+ meant, offer 2-3 versions; they flip through them and keep one.
36
+ - Pinned cards (the user held their label): your card_show, card_update and card_remove on them fail. Don't work
37
+ around it: make a new card (made_from=[the pinned one]) or ask the user.
38
+ - Cards stack in the main space and are as wide as their content. place={"x", "y", "width"?, "height"?}
39
+ (px from the main space's top-left) pins one at a spot instead: use it when the user points at a spot ("here")
40
+ or draws an area (then fill that area: its x, y, width and height).
41
+ - Everything you show is draggable by default: the user moves a card by its label (shown on hover), and it stays
42
+ where they put it (card_show without place keeps it there; where things are now: the "place" of each card in
43
+ {built}/card.json). Pass draggable=false only when the user wants something fixed. In an app you build, make
44
+ separate pieces draggable too, unless told otherwise.
45
+ - Everything you show is resizable by default too: the user drags its bottom-right corner (shown on hover), and
46
+ the card's root block (or its app) fills the new size. So build things that fill their space (sizes in %, flex,
47
+ or scaled to their box, e.g. an SVG with a viewBox), not fixed px. Pass resizable=false only when the user wants
48
+ a fixed size.
49
+ - card_update(card, path, value): change data only (fast; blocks keep their state). With block=<its id>, path is a
50
+ prop of that block (e.g. a label's text): a small fix without card_show. card_show without data keeps the card's
51
+ data. card_remove(card) takes it off its board.
52
+ - Data (what users typed, rows, scores) is kept in {data}/card.json (not versioned); the rest of each card in
53
+ {built}/card.json. The user can undo any change (theirs or yours), so don't keep backups.
54
+ - A Button's click writes its set ({path: value}) into the card's data on the page; you are not woken, and you
55
+ see the data in {data}/card.json. A row of Buttons setting the same path works as tabs.
56
+ - Voice input (dictation, meeting notes): import /voice/voice.js in the app (read its header), never the browser's
57
+ speech API or a provider directly: it uses the sandbox's speech-to-text API, or the browser's.
58
+ - A new block: {agent}/extensions/card/blocks/<Name>.js. Start with a comment line "// Name: what it does" (more
59
+ comment lines if needed), then its about block, then
60
+ `export default class extends HTMLElement { update(props, card) {...} }`.
61
+ The about block of a block (strict JSON after `export const about = `):
62
+ "version": 1 the shape of its props; raise it when they change, and export
63
+ upgrade(props, fromVersion) -> props, so cards saved earlier still draw
64
+ "props": {"name": {"type": "text" | "number" | "boolean" | "choice" | "list" | "rows" | "object" | "action",
65
+ "options": [...] (for choice), "default": ..., "doc": "what it is"}}
66
+ "children": "none" | "one" | "many"
67
+ "levers": ["Shown as {variant}."] the back side: plain sentences; each {prop} becomes a control the user
68
+ can change there (choice and boolean cycle, text and number are typed)
69
+ "accepts": "rows with a number column" optional: what it can take when something is dropped on it
70
+ "example": {...props} one sample, for the catalog and for checks
71
+ update() runs on every change, on the same element: keep internal state there (e.g. a game loop).
72
+ card.children: child elements, placed with card.mount(container); card.set(prop, value) writes a bound prop;
73
+ card.data is the card's data and card.write({path: value}) changes it (saved, you are not woken).
74
+ card.action(name, context) sends an action to you and wakes you: only for what truly needs you (e.g. "ask the
75
+ agents"), never for clicks the page can handle. Make it general so it can be reused. New blocks work
76
+ immediately; edited blocks and app files show when your turn ends (the page refreshes itself).
77
+ Pointing inside a canvas: give the element (or an app page's window) a partAt(x, y) function returning
78
+ {"name", ...} for what is at that spot, so the user can point at parts (an enemy, a cell).
79
+ - Agents inside what you build (a simulation's members, a debate, characters): load the app-agents skill first.
80
+ They are real agents that belong to the app, not workers helping you build it.
81
+ - Libraries: blocks import marked and dompurify by name (import { marked } from "marked"), as mapped in the import
82
+ map at the top of {agent}/extensions/page/page.html. To add one, put its ES-module build in
83
+ {agent}/extensions/card/lib/<pkg>/ and import it by path (/card/lib/<pkg>/<file>.js).
84
+ - Block pitfalls (you can't see the browser, so avoid them up front):
85
+ keep your own state in one object, this.state = {...}: fields like this.dir, this.title, this.hidden,
86
+ this.id, this.style, this.lang are built-in HTMLElement properties and silently break;
87
+ set a canvas's width/height BEFORE drawing (resizing clears it); don't create things twice in update();
88
+ remove document-level listeners/timers when the element is no longer connected.
@@ -0,0 +1,34 @@
1
+ // Button: a click writes {set} into the card's data, on the page (no agent is woken). It looks primary
2
+ // while the data already holds those values, so a row of them works as tabs.
3
+ export const about = {
4
+ "version": 2,
5
+ "props": {
6
+ "label": {"type": "text", "default": "OK"},
7
+ "set": {"type": "object", "doc": "{path: value, ...} written into this card's data on click, e.g. {\"/tab\": \"training\"}"},
8
+ "variant": {"type": "choice", "options": ["primary", "secondary"], "default": "primary", "doc": "its look when not selected"}
9
+ },
10
+ "children": "none",
11
+ "levers": ["Says {label}.", "Sets {set}.", "Looks {variant}."],
12
+ "example": {"label": "Training", "set": {"/tab": "training"}, "variant": "secondary"}
13
+ };
14
+ export function upgrade(props, from) { // version 1 sent an action to the agent instead
15
+ const { action, context, ...rest } = props;
16
+ return rest;
17
+ }
18
+ const get = (data, path) => path.split("/").filter(Boolean).reduce((o, k) => o?.[k], data);
19
+ export default class extends HTMLElement {
20
+ update(props, card) {
21
+ if (!this.button) {
22
+ this.button = document.createElement("button");
23
+ this.button.onclick = () => this.props.set && this.card.write(this.props.set);
24
+ this.append(this.button);
25
+ }
26
+ this.props = props;
27
+ this.card = card;
28
+ const selected = props.set && Object.entries(props.set).every(([p, v]) => get(card.data, p) === v);
29
+ this.button.textContent = props.label || "OK";
30
+ this.button.style.cssText = "border-radius:980px;padding:7px 16px;font-weight:500;" + (!selected && props.variant === "secondary"
31
+ ? "background:var(--glass-strong);color:var(--accent);border:1px solid var(--line)"
32
+ : "background:var(--accent);color:#fff;border:0");
33
+ }
34
+ }
@@ -10,8 +10,8 @@ export const about = {
10
10
  "example": {"gap": 8}
11
11
  };
12
12
  export default class extends HTMLElement {
13
- update({ gap = 8, align = "stretch" }, ui) {
13
+ update({ gap = 8, align = "stretch" }, card) {
14
14
  this.style.cssText = `display:flex;flex-direction:column;gap:${gap}px;align-items:${align}`;
15
- ui.mount(this);
15
+ card.mount(this);
16
16
  }
17
17
  }
@@ -0,0 +1,37 @@
1
+ // Markdown: formatted text from a markdown string (headings, lists, tables, code, links, quotes).
2
+ // HTML in the text is sanitised; links open in a new tab. The chat draws message bodies with it too.
3
+ export const about = {
4
+ "version": 1,
5
+ "props": {
6
+ "text": {"type": "text", "doc": "markdown"}
7
+ },
8
+ "children": "none",
9
+ "levers": [],
10
+ "example": {"text": "**Lunch** closes *Friday 11:00*"}
11
+ };
12
+ import { marked } from "marked"; // bare names: resolved by the import map in page.html
13
+ import DOMPurify from "dompurify";
14
+
15
+ const CSS = `
16
+ block-markdown { display: block; white-space: normal; }
17
+ block-markdown p, block-markdown ul, block-markdown ol, block-markdown pre, block-markdown table, block-markdown blockquote { margin: 6px 0; }
18
+ block-markdown ul, block-markdown ol { padding-left: 22px; }
19
+ block-markdown h1, block-markdown h2, block-markdown h3, block-markdown h4 { font-size: 1.05em; margin: 8px 0 4px; }
20
+ block-markdown code { font: 12.5px monospace; background: rgba(0, 0, 0, .06); padding: 1px 4px; border-radius: 3px; }
21
+ block-markdown pre { background: var(--hover); padding: 8px; border-radius: 4px; overflow-x: auto; }
22
+ block-markdown pre code { background: none; padding: 0; }
23
+ block-markdown table { border-collapse: collapse; }
24
+ block-markdown th, block-markdown td { border: 1px solid var(--line); padding: 3px 8px; }
25
+ block-markdown blockquote { border-left: 3px solid var(--line); padding-left: 8px; color: var(--soft); }`;
26
+
27
+ export default class extends HTMLElement {
28
+ update({ text = "" }) {
29
+ if (!document.getElementById("block-markdown-css")) {
30
+ document.head.insertAdjacentHTML("beforeend", `<style id="block-markdown-css">${CSS}</style>`);
31
+ }
32
+ if (this.state?.text === text) return; // unchanged: keep the DOM (and any selection)
33
+ this.state = { text };
34
+ this.innerHTML = DOMPurify.sanitize(marked.parse(text, { gfm: true, breaks: true }));
35
+ for (const a of this.querySelectorAll("a")) { a.target = "_blank"; a.rel = "noopener"; }
36
+ }
37
+ }
@@ -1,4 +1,4 @@
1
- // Card: a glass panel with an optional title; its children are stacked inside.
1
+ // Panel: a glass panel with an optional title; its children are stacked inside.
2
2
  export const about = {
3
3
  "version": 1,
4
4
  "props": {
@@ -9,7 +9,7 @@ export const about = {
9
9
  "example": {"title": "Lunch orders"}
10
10
  };
11
11
  export default class extends HTMLElement {
12
- update({ title = "" }, ui) {
12
+ update({ title = "" }, card) {
13
13
  if (!this.body) {
14
14
  this.style.cssText = "display:block;padding:14px 16px;border-radius:var(--radius);background:var(--glass-strong);" +
15
15
  "border:1px solid var(--edge);box-shadow:var(--shadow);backdrop-filter:var(--blur)";
@@ -18,6 +18,6 @@ export default class extends HTMLElement {
18
18
  }
19
19
  this.firstChild.textContent = title;
20
20
  this.firstChild.hidden = !title;
21
- ui.mount(this.body);
21
+ card.mount(this.body);
22
22
  }
23
23
  }
@@ -10,8 +10,8 @@ export const about = {
10
10
  "example": {"gap": 8}
11
11
  };
12
12
  export default class extends HTMLElement {
13
- update({ gap = 8, align = "center" }, ui) {
13
+ update({ gap = 8, align = "center" }, card) {
14
14
  this.style.cssText = `display:flex;flex-wrap:wrap;gap:${gap}px;align-items:${align}`;
15
- ui.mount(this);
15
+ card.mount(this);
16
16
  }
17
17
  }
@@ -12,17 +12,17 @@ export const about = {
12
12
  "example": {"label": "Your name", "value": "", "placeholder": "e.g. S. Tan"}
13
13
  };
14
14
  export default class extends HTMLElement {
15
- update({ label = "", value = "", placeholder = "", multiline = false }, ui) {
15
+ update({ label = "", value = "", placeholder = "", multiline = false }, card) {
16
16
  if (!this.input) {
17
17
  this.style.cssText = "display:flex;flex-direction:column;gap:4px";
18
18
  this.innerHTML = `<label style="font-size:12px;color:var(--muted)"></label>`;
19
19
  this.input = document.createElement(multiline ? "textarea" : "input");
20
20
  this.input.style.cssText = "padding:8px 10px;font:inherit;color:inherit;border-radius:10px;" +
21
21
  "background:var(--glass-strong);border:1px solid var(--line)";
22
- this.input.oninput = () => this.ui.set("value", this.input.value);
22
+ this.input.oninput = () => this.card.set("value", this.input.value);
23
23
  this.append(this.input);
24
24
  }
25
- this.ui = ui;
25
+ this.card = card;
26
26
  this.firstChild.textContent = label;
27
27
  this.input.placeholder = placeholder;
28
28
  if (document.activeElement !== this.input) this.input.value = value ?? ""; // don't fight the user's typing