@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,87 +0,0 @@
1
- /*
2
- * Calls the functions of this app's *.api.py files from the page. Keep this file as it is.
3
- *
4
- * const items = api('api/items'); // api/items.api.py, relative to the page
5
- * const list = await items.list_items(); // list_items()
6
- * await items.add_item({ title: 'Milk' }); // add_item(title="Milk")
7
- *
8
- * Each call is a POST of the arguments as JSON to `<file>/<function>`. It resolves with what the
9
- * function returned, or rejects with an ApiError: `.status` (0 when the server could not be
10
- * reached) and `.message` (the function's HttpError message, or what went wrong).
11
- * A server still starting (503) or busy (429) is waited for and asked again, up to 3 times.
12
- */
13
- (function () {
14
- class ApiError extends Error {
15
- constructor(message, status, body) {
16
- super(message);
17
- this.name = 'ApiError';
18
- this.status = status;
19
- this.body = body;
20
- }
21
- }
22
-
23
- const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
24
-
25
- async function call(file, name, args) {
26
- const url = `${String(file).replace(/\/+$/, '')}/${encodeURIComponent(name)}`;
27
- for (let attempt = 0; ; attempt++) {
28
- let res;
29
- try {
30
- // text/plain keeps this a "simple" request: the sandboxed page has no origin, and a
31
- // JSON content type would need a CORS preflight the app's host does not answer.
32
- res = await fetch(url, {
33
- method: 'POST',
34
- headers: {
35
- 'content-type': 'text/plain;charset=UTF-8',
36
- accept: 'application/json',
37
- },
38
- body: JSON.stringify(args ?? {}),
39
- });
40
- } catch (err) {
41
- throw new ApiError(`${name}: the app's server could not be reached`, 0, err);
42
- }
43
- if ((res.status === 503 || res.status === 429) && attempt < 3) {
44
- const seconds = Number(res.headers.get('retry-after')) || 2 * (attempt + 1);
45
- await sleep(Math.min(seconds, 10) * 1000);
46
- continue;
47
- }
48
- const text = await res.text();
49
- let body = null;
50
- if (text) {
51
- try {
52
- body = JSON.parse(text);
53
- } catch {
54
- body = text;
55
- }
56
- }
57
- if (!res.ok) {
58
- const message =
59
- body && typeof body === 'object' && body.error
60
- ? body.error
61
- : typeof body === 'string' && body
62
- ? body.slice(0, 300)
63
- : `${name} failed (${res.status})`;
64
- throw new ApiError(message, res.status, body);
65
- }
66
- return body;
67
- }
68
- }
69
-
70
- /** The functions of one .api.py file, by its path relative to the page without `.api.py`. */
71
- function api(file) {
72
- return new Proxy(
73
- {},
74
- {
75
- get(_, name) {
76
- // `then` too: an object returned from an async function must not look like a promise.
77
- if (typeof name !== 'string' || name === 'then') return undefined;
78
- return (args) => call(file, name, args);
79
- },
80
- },
81
- );
82
- }
83
-
84
- api.call = call;
85
- window.api = api;
86
- window.ApiError = ApiError;
87
- })();
@@ -1,278 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1" />
6
- <title>Items</title>
7
- <!-- Calls the functions of api/*.api.py: api('api/items').add_item({...}). Keep it. -->
8
- <script src="api.js"></script>
9
- <style>
10
- :root {
11
- color-scheme: light dark;
12
- --bg: #f7f7f8;
13
- --card: #ffffff;
14
- --fg: #1d1d1f;
15
- --muted: #6e6e73;
16
- --line: #e3e3e6;
17
- --accent: #2563eb;
18
- --danger: #b91c1c;
19
- --gap: 16px;
20
- --radius: 10px;
21
- font:
22
- 14px/1.45 system-ui,
23
- -apple-system,
24
- 'Segoe UI',
25
- Roboto,
26
- sans-serif;
27
- }
28
- @media (prefers-color-scheme: dark) {
29
- :root {
30
- --bg: #141416;
31
- --card: #1e1e21;
32
- --fg: #ececf0;
33
- --muted: #9a9aa2;
34
- --line: #2e2e33;
35
- --accent: #60a5fa;
36
- --danger: #f87171;
37
- }
38
- }
39
- * {
40
- box-sizing: border-box;
41
- }
42
- body {
43
- margin: 0;
44
- background: var(--bg);
45
- color: var(--fg);
46
- }
47
- main {
48
- max-width: 900px;
49
- margin: 0 auto;
50
- padding: var(--gap);
51
- display: grid;
52
- gap: var(--gap);
53
- }
54
- header h1 {
55
- margin: 0;
56
- font-size: 1.4rem;
57
- }
58
- header p {
59
- margin: 4px 0 0;
60
- color: var(--muted);
61
- }
62
- .card {
63
- background: var(--card);
64
- border: 1px solid var(--line);
65
- border-radius: var(--radius);
66
- padding: var(--gap);
67
- min-width: 0;
68
- }
69
- .row {
70
- display: flex;
71
- flex-wrap: wrap;
72
- gap: 8px;
73
- align-items: center;
74
- }
75
- .row > * {
76
- min-width: 0;
77
- }
78
- input[type='text'],
79
- select,
80
- button {
81
- font: inherit;
82
- color: var(--fg);
83
- background: var(--card);
84
- border: 1px solid var(--line);
85
- border-radius: 6px;
86
- padding: 6px 10px;
87
- }
88
- input[type='text'] {
89
- flex: 1 1 14rem;
90
- }
91
- button {
92
- cursor: pointer;
93
- }
94
- button.primary {
95
- background: var(--accent);
96
- border-color: var(--accent);
97
- color: #fff;
98
- }
99
- button.danger {
100
- color: var(--danger);
101
- }
102
- button:disabled {
103
- opacity: 0.6;
104
- cursor: default;
105
- }
106
- ul.list {
107
- list-style: none;
108
- margin: 0;
109
- padding: 0;
110
- }
111
- ul.list li {
112
- display: flex;
113
- gap: 10px;
114
- align-items: center;
115
- padding: 8px 0;
116
- border-bottom: 1px solid var(--line);
117
- }
118
- ul.list li:last-child {
119
- border-bottom: 0;
120
- }
121
- ul.list .title {
122
- flex: 1;
123
- min-width: 0;
124
- overflow-wrap: anywhere;
125
- }
126
- ul.list .done .title {
127
- color: var(--muted);
128
- text-decoration: line-through;
129
- }
130
- .muted {
131
- color: var(--muted);
132
- }
133
- .error {
134
- color: var(--danger);
135
- border-color: var(--danger);
136
- }
137
- [hidden] {
138
- display: none !important;
139
- }
140
- </style>
141
- </head>
142
- <body>
143
- <main>
144
- <header>
145
- <h1 id="title">Items</h1>
146
- <p id="subtitle">Add, check off and remove items. Changes are saved.</p>
147
- <p id="user" class="muted" hidden></p>
148
- </header>
149
-
150
- <!-- The page: replace from here -->
151
- <div id="error" class="card error" role="alert" hidden></div>
152
-
153
- <section class="card">
154
- <div class="row">
155
- <input id="new-title" type="text" placeholder="New item" maxlength="200" />
156
- <button id="add" class="primary">Add</button>
157
- <select id="show" aria-label="Show">
158
- <option value="all">All</option>
159
- <option value="open">Open</option>
160
- <option value="done">Done</option>
161
- </select>
162
- </div>
163
- </section>
164
-
165
- <section class="card">
166
- <p id="status" class="muted">Loading…</p>
167
- <ul id="items" class="list"></ul>
168
- </section>
169
- </main>
170
-
171
- <script>
172
- const items = api('api/items');
173
- const state = { show: 'all', list: [], loading: true };
174
- const $ = (id) => document.getElementById(id);
175
-
176
- function showError(err) {
177
- const box = $('error');
178
- box.textContent = err ? err.message || String(err) : '';
179
- box.hidden = !err;
180
- }
181
-
182
- // Every change goes through here: call, then reload and draw, or show what failed.
183
- async function run(work) {
184
- showError(null);
185
- try {
186
- await work();
187
- await reload();
188
- } catch (err) {
189
- showError(err);
190
- }
191
- }
192
-
193
- async function reload() {
194
- state.loading = true;
195
- render();
196
- try {
197
- state.list = await items.list_items({ show: state.show });
198
- } finally {
199
- state.loading = false;
200
- render();
201
- }
202
- }
203
-
204
- function render() {
205
- $('status').textContent = state.loading
206
- ? 'Loading…'
207
- : state.list.length
208
- ? `${state.list.length} item${state.list.length === 1 ? '' : 's'}`
209
- : 'Nothing here yet.';
210
- const ul = $('items');
211
- ul.replaceChildren(
212
- ...state.list.map((item) => {
213
- const li = document.createElement('li');
214
- li.className = item.done ? 'done' : '';
215
- const box = document.createElement('input');
216
- box.type = 'checkbox';
217
- box.checked = item.done;
218
- box.ariaLabel = 'Done';
219
- box.addEventListener('change', () =>
220
- run(() => items.set_done({ id: item.id, done: box.checked })),
221
- );
222
- const title = document.createElement('span');
223
- title.className = 'title';
224
- title.textContent = item.title;
225
- // No dialogs: the sandbox blocks them. A second click confirms.
226
- const del = document.createElement('button');
227
- del.className = 'danger';
228
- del.textContent = 'Delete';
229
- del.addEventListener('click', () => {
230
- if (del.dataset.armed)
231
- return run(() => items.remove_item({ id: item.id }));
232
- del.dataset.armed = '1';
233
- del.textContent = 'Sure?';
234
- setTimeout(() => {
235
- delete del.dataset.armed;
236
- del.textContent = 'Delete';
237
- }, 3000);
238
- });
239
- li.append(box, title, del);
240
- return li;
241
- }),
242
- );
243
- }
244
-
245
- async function add() {
246
- const input = $('new-title');
247
- const title = input.value.trim();
248
- if (!title) return;
249
- $('add').disabled = true;
250
- await run(async () => {
251
- await items.add_item({ title });
252
- input.value = '';
253
- });
254
- $('add').disabled = false;
255
- input.focus();
256
- }
257
-
258
- $('add').addEventListener('click', add);
259
- $('new-title').addEventListener('keydown', (e) => e.key === 'Enter' && add());
260
- $('show').addEventListener('change', (e) => {
261
- state.show = e.target.value;
262
- run(async () => {});
263
- });
264
-
265
- // Who is signed in comes from the server (me() in api/items.api.py), never the page.
266
- items
267
- .me()
268
- .then((me) => {
269
- if (!me) return;
270
- $('user').textContent = `Signed in as ${me.name}`;
271
- $('user').hidden = false;
272
- })
273
- .catch(showError);
274
-
275
- run(async () => {});
276
- </script>
277
- </body>
278
- </html>