@zenera/cli 1.3.21 → 1.3.23

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 +96 -51
  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 +266 -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 +35 -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 +326 -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 +40 -29
  20. package/templates/project/agents/skills/html-page/scripts/build.ts +825 -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
@@ -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
 
@@ -77,6 +81,9 @@ The rules:
77
81
  fresh copy starts by itself.
78
82
  - `data_path("exports/report.csv")`: a path in the same folder, for other
79
83
  files it keeps.
84
+ - A page published with the project (under `/assets`, read-only) keeps each
85
+ user's data in their own workspace instead; `connect()` and `data_path()`
86
+ find it there by themselves.
80
87
  - A file the page should download or show (a CSV export, a chart image):
81
88
  write it next to the page instead, e.g. `../exports/orders.csv` from
82
89
  `api/`, and return the relative name; the page links to it.
@@ -144,8 +151,8 @@ def delete_note(id: int):
144
151
  - Store `.id` (an `owner` column), never the email or name: those can change.
145
152
  - Check permissions in the function (`HttpError(403, ...)`); hiding a button
146
153
  in the page is not a check.
147
- - In the page: `const me = await api('api/users').me();`, then show
148
- `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.
149
156
  - When it matters: a page in a chat's workspace already belongs to one user
150
157
  (each has their own copy and `.data`). Identity matters for data shared
151
158
  between users: an external database, or a page published in the project's
@@ -156,26 +163,30 @@ def delete_note(id: int):
156
163
 
157
164
  ## Calling them from the page
158
165
 
159
- - Copy `/skills/html-page/assets/api.js` beside the page and load it once,
160
- **by a relative path**: `<script src="api.js"></script>` (from a page in a
161
- subfolder: `../api.js`). Never edit it.
162
- - `api('<path to the file, relative to the page, without .api.py>')` gives an
163
- object whose methods are the file's functions:
164
- `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.
165
173
  - Always pass **one object** of named arguments (or nothing). Each call
166
174
  returns a promise of what the function returned.
167
175
  - A failure rejects with an `ApiError`: `.message` is the `HttpError`
168
- message, `.status` the HTTP status (0: not reachable). Show the message on
169
- the page.
170
- - After a change, load the data again from the function that lists it, so
171
- the page shows what is really saved. Disable a button while its call runs.
172
- The app template's `run(work)` does all three.
173
-
174
- | JavaScript | Request | Python |
175
- | --------------------------------------------- | ----------------------------- | ---------------------------- |
176
- | `api('api/orders').list_orders()` | `POST api/orders/list_orders` | `list_orders()` |
177
- | `api('api/orders').set_status({id: 7, ...})` | `POST api/orders/set_status` | `set_status(id=7, ...)` |
178
- | `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` |
179
190
 
180
191
  A plain link works for reads too: `api/orders/list_orders?status=open`
181
192
  (arguments as text, converted by their annotations).
@@ -193,8 +204,8 @@ python3 -m zenera.api api/items.api.py list_items
193
204
  python3 -m zenera.api api/items.api.py set_done '{"id": 1, "done": true}'
194
205
  python3 -m zenera.api api/items.api.py remove_item '{"id": 99}' # expect: 404: no item 99
195
206
  rm -rf /tmp/todo-test; unset ZEN_APP_DATA
196
- 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
197
208
  ```
198
209
 
199
210
  Every name the page calls must be a function the listing showed, with the
200
- argument names it shows.
211
+ argument names it shows - declare them so in the page's `ItemsApi`.