@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.
- package/package.json +6 -6
- package/templates/editor/.github/skills/zen-review/scripts/check-paths.sh +1 -1
- package/templates/project/agents/skills/html-page/SKILL.md +164 -57
- package/templates/project/agents/skills/html-page/assets/app/api/items.api.py +3 -2
- package/templates/project/agents/skills/html-page/assets/app/app.tsx +140 -0
- package/templates/project/agents/skills/html-page/assets/dashboard.tsx +162 -0
- package/templates/project/agents/skills/html-page/kit/Chart.tsx +79 -0
- package/templates/project/agents/skills/html-page/kit/Table.tsx +89 -0
- package/templates/project/agents/skills/html-page/kit/api.ts +93 -0
- package/templates/project/agents/skills/html-page/kit/components.tsx +302 -0
- package/templates/project/agents/skills/html-page/kit/format.ts +60 -0
- package/templates/project/agents/skills/html-page/kit/hooks.ts +159 -0
- package/templates/project/agents/skills/html-page/kit/index.ts +36 -0
- package/templates/project/agents/skills/html-page/kit/modules.d.ts +37 -0
- package/templates/project/agents/skills/html-page/kit/mount.tsx +62 -0
- package/templates/project/agents/skills/html-page/kit/shell.html +19 -0
- package/templates/project/agents/skills/html-page/kit/theme.css +356 -0
- package/templates/project/agents/skills/html-page/references/charts-and-tables.md +105 -53
- package/templates/project/agents/skills/html-page/references/python-functions.md +37 -29
- package/templates/project/agents/skills/html-page/scripts/build.ts +990 -0
- package/templates/project/agents/skills/html-page/assets/api.js +0 -87
- package/templates/project/agents/skills/html-page/assets/app/index.html +0 -278
- 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.
|
|
4
|
-
rules (where it goes, the sandbox, adaptive layout,
|
|
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
|
|
9
|
-
`
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- Live data instead:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
`
|
|
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
|
-
##
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
```
|
|
11
|
-
|
|
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
|
|
19
|
-
(`orders.api.py`, `customers.api.py`),
|
|
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 =
|
|
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
|
-
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
- `
|
|
166
|
-
object
|
|
167
|
-
|
|
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).
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
|
181
|
-
|
|
|
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
|
-
|
|
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`.
|