@zenera/cli 1.3.22 → 1.3.24

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 (23) hide show
  1. package/package.json +6 -6
  2. package/templates/editor/.github/skills/zen-review/scripts/check-paths.sh +1 -1
  3. package/templates/project/agents/skills/html-page/SKILL.md +164 -57
  4. package/templates/project/agents/skills/html-page/assets/app/api/items.api.py +3 -2
  5. package/templates/project/agents/skills/html-page/assets/app/app.tsx +140 -0
  6. package/templates/project/agents/skills/html-page/assets/dashboard.tsx +162 -0
  7. package/templates/project/agents/skills/html-page/kit/Chart.tsx +79 -0
  8. package/templates/project/agents/skills/html-page/kit/Table.tsx +89 -0
  9. package/templates/project/agents/skills/html-page/kit/api.ts +93 -0
  10. package/templates/project/agents/skills/html-page/kit/components.tsx +302 -0
  11. package/templates/project/agents/skills/html-page/kit/format.ts +60 -0
  12. package/templates/project/agents/skills/html-page/kit/hooks.ts +159 -0
  13. package/templates/project/agents/skills/html-page/kit/index.ts +36 -0
  14. package/templates/project/agents/skills/html-page/kit/modules.d.ts +37 -0
  15. package/templates/project/agents/skills/html-page/kit/mount.tsx +62 -0
  16. package/templates/project/agents/skills/html-page/kit/shell.html +19 -0
  17. package/templates/project/agents/skills/html-page/kit/theme.css +356 -0
  18. package/templates/project/agents/skills/html-page/references/charts-and-tables.md +105 -53
  19. package/templates/project/agents/skills/html-page/references/python-functions.md +37 -29
  20. package/templates/project/agents/skills/html-page/scripts/build.ts +990 -0
  21. package/templates/project/agents/skills/html-page/assets/api.js +0 -87
  22. package/templates/project/agents/skills/html-page/assets/app/index.html +0 -278
  23. package/templates/project/agents/skills/html-page/assets/dashboard.html +0 -423
@@ -1,18 +1,20 @@
1
1
  # Charts, tables and headline numbers
2
2
 
3
- For a page built from `/skills/html-page/assets/dashboard.html`. The core
4
- rules (where it goes, the sandbox, adaptive layout, checks) are in `SKILL.md`.
3
+ For a page built from `/skills/html-page/assets/dashboard.tsx`. The core
4
+ rules (where it goes, the sandbox, adaptive layout, the build) are in
5
+ `SKILL.md`.
5
6
 
6
7
  ## Its data
7
8
 
8
- - Default: `data.json` beside the page, loaded with `fetch` (the template's
9
- `loadData()`).
10
- - Very small data (a few KB) may be inlined instead, in a JSON `<script>`
11
- block with `id="data"` - `loadData()` uses it when present.
12
- - Live data instead: copy `api.js` beside the page, add
13
- `<script src="api.js"></script>` before the page's script, and make
14
- `loadData()` return `api('api/report').get_data()` - a function of
15
- `api/report.api.py` that returns the same shape (`python-functions.md`).
9
+ - Default: `data.json` beside the page, loaded with
10
+ `const report = useData<Report>('data.json')` - `report.data`,
11
+ `report.error`, `report.loading`, `report.reload`. Give `Report` the
12
+ data's real shape: the build then checks every field the page reads.
13
+ - Live data instead: `useCall(() => api<ReportApi>('api/report').get_data(), [])`,
14
+ a function of `api/report.api.py` that returns the same shape
15
+ (`python-functions.md`). Filters over many rows go to the function as
16
+ arguments (`useCall(() => report.get_data({ region }), [region])`) and are
17
+ applied in SQL, instead of loading every row.
16
18
  - Ship the data the page needs, not the raw source: aggregate in Python, SQL
17
19
  or DuckDB first. Keep it under ~5 MB; past ~20 000 rows send aggregates plus
18
20
  the top rows, and say so on the page.
@@ -21,51 +23,101 @@ rules (where it goes, the sandbox, adaptive layout, checks) are in `SKILL.md`.
21
23
  chart. Numbers as numbers, dates as ISO strings (`2026-03-31`), no `NaN`
22
24
  (write `null`).
23
25
  - Several pages can share one data file by a relative path that starts with
24
- `..`.
25
-
26
- ## Sizing
27
-
28
- - Chart cards: `grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr))`;
29
- KPI cards `minmax(150px, 1fr)`. `.wide` spans the full row.
30
- - Charts: width 100% of their card, a fixed height (`320px`, `260px` under
31
- 520 px). Never size charts in `vh` or by the window. The template's
32
- `chart()` resizes them with a `ResizeObserver`, so they follow the panel
33
- being dragged, not only the window, and re-theme on light/dark.
34
- - Tables: the template's `table()` collapses columns that do not fit and
35
- paginates. Put the most important columns first.
36
-
37
- ## Components
38
-
39
- Use these, from the CDN URLs in the template, pinned to the version shown
40
- there:
41
-
42
- | Need | Use |
43
- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
44
- | Charts of any kind - bar, line, area, pie, scatter, heatmap, treemap, sankey, funnel, gauge | ECharts (`chart()` helper). Same library as the chat's charts, so `a2ui-charts` advice on choosing a chart type applies. |
45
- | Tables - sort, filter per column, pagination, many rows | Tabulator (`table()` helper) |
46
- | Headline numbers with change vs. a previous period | KPI cards (`kpis()` helper) |
47
- | Filters across the whole page | `<select>` per field (`filters()` helper); `<input type="date">` or `type="range"` for ranges |
48
- | Number, money, percent and date formatting | `Intl.NumberFormat` and `Intl.DateTimeFormat` (`fmt` helper) - never format by hand |
49
- | Long time series | ECharts `dataZoom` (`inside`, plus `slider` on wide pages) |
50
- | Text sections, notes, method | Plain HTML in a `.card`; `<details>` for anything secondary |
51
- | Tabs between views | Buttons that show and hide sections; keep the active tab in `location.hash` |
52
-
53
- Avoid: CSS frameworks and Tailwind's browser build (heavy, and the template
54
- styles are enough), React or Vue (no build step here), Leaflet or any map
55
- with tiles (blocked - use an ECharts `map` with GeoJSON you write to the
56
- folder), Plotly unless a chart type ECharts lacks is needed (it is ~3 MB).
26
+ `..` (`useData('../shared/data.json')`).
27
+
28
+ ## Charts: `Chart`
29
+
30
+ ```tsx
31
+ const byCategory = useMemo(() => {
32
+ const totals = groupSum(rows, 'category', 'amount').sort((a, b) => b[1] - a[1]);
33
+ return {
34
+ xAxis: { type: 'category', data: totals.map((d) => d[0]) },
35
+ yAxis: { type: 'value' },
36
+ series: [{ type: 'bar', data: totals.map((d) => d[1]) }],
37
+ };
38
+ }, [rows]);
39
+
40
+ <Card title="Amount by category, USD">
41
+ <Chart option={byCategory} onClick={(e) => setCategory(e.name)} />
42
+ </Card>;
43
+ ```
44
+
45
+ - `option` is a plain ECharts option object - every chart type ECharts has:
46
+ bar, line, area, pie, scatter, heatmap, treemap, sankey, funnel, gauge,
47
+ `map` with GeoJSON you write to the folder. Same library as the chat's
48
+ charts, so `a2ui-charts` advice on choosing a chart type applies.
49
+ - Build `option` in `useMemo` from the filtered rows: the chart redraws when
50
+ it changes, not on every render.
51
+ - Defaults: an axis tooltip (`confine: true`, stays inside a narrow panel)
52
+ and a tight grid. A top-level key of `option` replaces its default: a pie
53
+ wants `tooltip: { trigger: 'item' }`.
54
+ - `height` (default 320) is the chart's; its width is the card's. It follows
55
+ the panel being resized and switches light/dark by itself. Never size a
56
+ chart in `vh` or by the window.
57
+ - `onClick` gets the clicked bar, point or slice: `e.name` is its category -
58
+ set a filter from it.
59
+ - Long time series: `dataZoom: [{ type: 'inside' }]`, plus
60
+ `{ type: 'slider' }` on wide pages.
61
+ - Show `Empty` ("No data for these filters") instead of an empty chart.
62
+
63
+ ## Tables: `Table`
64
+
65
+ ```tsx
66
+ const columns: Column[] = [
67
+ { title: 'Date', field: 'date', headerFilter: 'input', minWidth: 100 },
68
+ { title: 'Customer', field: 'customer', headerFilter: 'input' },
69
+ {
70
+ title: 'Amount',
71
+ field: 'amount',
72
+ hozAlign: 'right',
73
+ sorter: 'number',
74
+ formatter: (cell: { getValue(): number }) => fmt.money(cell.getValue()),
75
+ },
76
+ ];
77
+
78
+ <Card title="Orders" wide>
79
+ <Table data={rows} columns={columns} onRowClick={(row) => setOpen(row.id)} />
80
+ </Card>;
81
+ ```
82
+
83
+ - Tabulator underneath: `columns` take its column options
84
+ (`sorter`, `hozAlign`, `headerFilter`, `formatter`, `minWidth`, `width`).
85
+ Define `columns` outside `App` or in `useMemo`.
86
+ - It sorts, filters per column, pages (25 rows) and collapses the columns
87
+ that do not fit a narrow panel - put the most important columns first.
88
+ - New `data` replaces the rows in place (page and sort are kept). `options`
89
+ passes more Tabulator options (`{ paginationSize: 50 }`,
90
+ `{ pagination: false }` for a short table).
91
+ - A short, fixed table (under ~15 rows, no sorting needed) can be a plain
92
+ `<table>` in a `Card` instead.
93
+
94
+ ## Headline numbers and filters
95
+
96
+ | Need | Use |
97
+ | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
98
+ | Headline numbers with change vs. a previous period | `<Kpis><Kpi label="Revenue" value={fmt.money(total)} delta={0.12} hint="vs. Q4" /></Kpis>` |
99
+ | A filter over the whole page | `<Select label="Region" all="All" value={region} options={uniq(rows, 'region')} onChange={setRegion} />` |
100
+ | A date or number range | `<Field label="From"><input type="date" value={from} onChange={(e) => setFrom(e.target.value)} /></Field>` |
101
+ | Number, money, percent and date formatting | `fmt.num(v, 2)`, `fmt.money(v, 'EUR')`, `fmt.pct(0.12)`, `fmt.date('2026-03-31')` - never by hand |
102
+ | Totals and groups of rows | `sum(rows, 'amount')`, `groupSum(rows, 'region', 'amount')`, `uniq(rows, 'region')` |
103
+ | Text sections, notes, method | JSX in a `Card`; `<details>` for anything secondary |
104
+ | Tabs between views | Buttons that set `useHashState('tab', 'summary')`, and render the active view |
105
+
106
+ Avoid: CSS frameworks and other npm packages, and other chart or table
107
+ libraries - the page has React, the kit, and ECharts and Tabulator from the
108
+ CDN, added by the build when `Chart` or `Table` is used. No Leaflet or any map
109
+ with tiles (blocked): use an ECharts `map` with GeoJSON you write to the
110
+ folder.
57
111
 
58
112
  Every chart and table has a short heading saying what it shows, with units.
59
- The page footer names the source and the date of the data.
113
+ The page footer (`Page footer=...`) names the source and the date of the data.
60
114
 
61
115
  ## Interactivity
62
116
 
63
- - One `render(state)` draws everything from the filtered rows; every control
64
- just updates `state` and calls it. KPIs, charts and table then always agree.
65
- - Tooltips on every chart (on by default in `chart()`), `confine: true` so
66
- they stay inside a narrow panel.
67
- - Clicking a bar or slice may set a filter: `bar.on('click', (p) => ...)`
68
- with `p.name` the category clicked; the handler survives a theme switch.
69
- - Show "No data for these filters" rather than an empty chart.
70
- - Filters over live data with many rows: pass them to the function
71
- (`get_data({ region })`) and filter in SQL, instead of loading every row.
117
+ - Filters are `useState` in `App`; the filtered rows are a `useMemo` of the
118
+ data and the filters; KPIs, chart options and the table all come from
119
+ those rows. They then always agree.
120
+ - Clicking a bar or slice may set a filter (`onClick` above); show the
121
+ active filters in the `Toolbar` so they can be cleared.
122
+ - Keep the view a user would share (the tab, the open record) in
123
+ `useHashState`, so a reload or a link opens it again.
@@ -4,20 +4,24 @@ For a page that shows live data or saves changes. The core rules (where it
4
4
  goes, the sandbox, adaptive layout, checks) are in `SKILL.md`.
5
5
 
6
6
  Every **public function** in an `*.api.py` beside the page can be called from
7
- the page's JavaScript by name, with its arguments as an object, and returns
8
- JSON. No server code, routes or framework: write plain Python functions.
9
-
10
- ```js
11
- const items = api('api/items'); // api/items.api.py
7
+ the page by name, with its arguments as an object, and returns JSON. No
8
+ server code, routes or framework: write plain Python functions.
9
+
10
+ ```tsx
11
+ interface ItemsApi {
12
+ list_items(args: { show: string }): Promise<Item[]>; // list_items(show: str)
13
+ add_item(args: { title: string }): Promise<Item>; // add_item(title: str)
14
+ }
15
+ const items = api<ItemsApi>('api/items'); // api/items.api.py
12
16
  const list = await items.list_items({ show: 'open' }); // list_items(show="open")
13
17
  await items.add_item({ title: 'Milk' }); // add_item(title="Milk")
14
18
  ```
15
19
 
16
20
  The app template (`/skills/html-page/assets/app`) is a working example: a
17
21
  list in SQLite with add, check off, filter and delete. Rename
18
- `api/items.api.py` to what it holds; one `*.api.py` per area of the app
19
- (`orders.api.py`, `customers.api.py`), shared helpers in plain `.py` files
20
- beside them.
22
+ `api/items.api.py` to what it holds, and its interface in `app.tsx` with it;
23
+ one `*.api.py` per area of the app (`orders.api.py`, `customers.api.py`),
24
+ shared helpers in plain `.py` files beside them.
21
25
 
22
26
  ## Writing the functions
23
27
 
@@ -147,8 +151,8 @@ def delete_note(id: int):
147
151
  - Store `.id` (an `owner` column), never the email or name: those can change.
148
152
  - Check permissions in the function (`HttpError(403, ...)`); hiding a button
149
153
  in the page is not a check.
150
- - In the page: `const me = await api('api/users').me();`, then show
151
- `me.name` in the header, and hide what `me.role` may not do.
154
+ - In the page: `const me = useCall(() => users.me(), [])`, then show
155
+ `me.data?.name` in the header, and hide what `me.data?.role` may not do.
152
156
  - When it matters: a page in a chat's workspace already belongs to one user
153
157
  (each has their own copy and `.data`). Identity matters for data shared
154
158
  between users: an external database, or a page published in the project's
@@ -159,26 +163,30 @@ def delete_note(id: int):
159
163
 
160
164
  ## Calling them from the page
161
165
 
162
- - Copy `/skills/html-page/assets/api.js` beside the page and load it once,
163
- **by a relative path**: `<script src="api.js"></script>` (from a page in a
164
- subfolder: `../api.js`). Never edit it.
165
- - `api('<path to the file, relative to the page, without .api.py>')` gives an
166
- object whose methods are the file's functions:
167
- `api('api/orders').set_status({ id: 7, status: 'paid' })`.
166
+ - `api<FileApi>('<path to the file, relative to the page, without .api.py>')`
167
+ from `@page/kit` gives an object whose methods are the file's functions:
168
+ `api<OrdersApi>('api/orders').set_status({ id: 7, status: 'paid' })`.
169
+ - Declare `FileApi` beside it: one method per function the page calls, its
170
+ arguments as one object named like the Python parameters, and what it
171
+ returns. Keep it in step with the Python - the build checks the page
172
+ against it, and that the `.api.py` exists.
168
173
  - Always pass **one object** of named arguments (or nothing). Each call
169
174
  returns a promise of what the function returned.
170
175
  - A failure rejects with an `ApiError`: `.message` is the `HttpError`
171
- message, `.status` the HTTP status (0: not reachable). Show the message on
172
- the page.
173
- - After a change, load the data again from the function that lists it, so
174
- the page shows what is really saved. Disable a button while its call runs.
175
- The app template's `run(work)` does all three.
176
-
177
- | JavaScript | Request | Python |
178
- | --------------------------------------------- | ----------------------------- | ---------------------------- |
179
- | `api('api/orders').list_orders()` | `POST api/orders/list_orders` | `list_orders()` |
180
- | `api('api/orders').set_status({id: 7, ...})` | `POST api/orders/set_status` | `set_status(id=7, ...)` |
181
- | `api('../api/users').me()` (page in a folder) | `POST ../api/users/me` | `me()` in `api/users.api.py` |
176
+ message, `.status` the HTTP status (0: not reachable).
177
+ - Reading: `useCall(() => orders.list_orders({ status }), [status])` calls
178
+ it when the page opens and when `status` changes, with `.data`, `.error`,
179
+ `.loading` and `.reload()`.
180
+ - Changing: `useAction((id: number) => orders.set_status({ id, status: 'paid' }), list.reload)`
181
+ runs the call, then loads the list again so the page shows what is really
182
+ saved; disable the button while `.busy`, and show `.error` in an
183
+ `ErrorBox`. The app template does all of this.
184
+
185
+ | TypeScript | Request | Python |
186
+ | ------------------------------------------------ | ----------------------------- | ---------------------------- |
187
+ | `api<OrdersApi>('api/orders').list_orders()` | `POST api/orders/list_orders` | `list_orders()` |
188
+ | `api<OrdersApi>('api/orders').set_status({...})` | `POST api/orders/set_status` | `set_status(id=7, ...)` |
189
+ | `api<UsersApi>('../api/users').me()` (`report/`) | `POST ../api/users/me` | `me()` in `api/users.api.py` |
182
190
 
183
191
  A plain link works for reads too: `api/orders/list_orders?status=open`
184
192
  (arguments as text, converted by their annotations).
@@ -196,8 +204,8 @@ python3 -m zenera.api api/items.api.py list_items
196
204
  python3 -m zenera.api api/items.api.py set_done '{"id": 1, "done": true}'
197
205
  python3 -m zenera.api api/items.api.py remove_item '{"id": 99}' # expect: 404: no item 99
198
206
  rm -rf /tmp/todo-test; unset ZEN_APP_DATA
199
- grep -noE "api\('[^']+'\)" *.html # each path, + .api.py, must exist relative to the page
207
+ node /skills/html-page/scripts/build.ts . # checks each api('...') path and the page's calls
200
208
  ```
201
209
 
202
210
  Every name the page calls must be a function the listing showed, with the
203
- argument names it shows.
211
+ argument names it shows - declare them so in the page's `ItemsApi`.