@zenera/cli 1.3.22 → 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 +37 -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
 
@@ -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`.