@zenera/cli 1.3.23 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenera/cli",
3
- "version": "1.3.23",
3
+ "version": "1.3.24",
4
4
  "description": "Command-line front end for @zenera/neo: agentic projects you can run, share and commit.",
5
5
  "keywords": [
6
6
  "agents",
@@ -56,11 +56,11 @@
56
56
  "@google/genai": "^2.30.0",
57
57
  "@inkjs/ui": "^2.0.0",
58
58
  "@openrouter/sdk": "^1.4.25",
59
- "@zenera/engine": "^1.3.23",
60
- "@zenera/neo": "^1.3.23",
61
- "@zenera/sandbox": "^1.3.23",
62
- "@zenera/server": "^1.3.23",
63
- "@zenera/view": "^1.3.23",
59
+ "@zenera/engine": "^1.3.24",
60
+ "@zenera/neo": "^1.3.24",
61
+ "@zenera/sandbox": "^1.3.24",
62
+ "@zenera/server": "^1.3.24",
63
+ "@zenera/view": "^1.3.24",
64
64
  "google-auth-library": "^10.0.0",
65
65
  "ink": "^7.1.1",
66
66
  "openai": "^6.0.0",
@@ -89,7 +89,8 @@ installed - no npm packages, no CSS frameworks. The kit's source is in
89
89
  | Load data, with loading and error state | `useCall(() => items.list_items({ show }), [show])`, `useData<Report>('data.json')` |
90
90
  | A change the user makes, then reload | `useAction((title: string) => items.add_item({ title }), list.reload)`: `.run`, `.busy`, `.error` |
91
91
  | View state that survives a reload (tab, open item) | `useHashState('tab', 'orders')` - kept in `#tab=...` |
92
- | Layout | `Page` (`width="narrow"` for an app), `Toolbar`, `Grid`, `Card` (`wide`), `Split` |
92
+ | Layout | `Page` (`width="narrow"` for an app), `Stack`, `Toolbar`, `Grid`, `Card` (`wide`) - see "Layout" |
93
+ | A list and what opens from it (item, edit, new) | `Split` - list or detail when narrow, side by side when wide; see "Layout" |
93
94
  | Controls | `Select`, `Field` around any input, plain `<input>`, `<button className="primary">` |
94
95
  | Headline numbers | `Kpis` with `Kpi` (`value` formatted, `delta` a fraction) |
95
96
  | Charts | `Chart` with an ECharts `option` (charts-and-tables.md) |
@@ -123,24 +124,76 @@ build reports most of these; know them so you do not write them:
123
124
  - Links to other sites need `target="_blank" rel="noopener"`.
124
125
  - The page cannot call the agent or any tool.
125
126
 
126
- ## Layout - always adaptive
127
-
128
- Every page must work at 360 px (narrow panel) and 1600 px (wide tab) without
129
- horizontal scrolling. The kit's components do this; keep to their rules:
130
-
131
- - No fixed widths. `Grid` reflows cards, `Toolbar` and `.row` wrap, `Split`
132
- shows a list and its open item side by side when wide and one at a time
133
- when narrow (give the item a Back button).
127
+ ## Layout - narrow first
128
+
129
+ The page is opened **most often in the chat's side panel, 360 - 600 px
130
+ wide**, and sometimes in a full tab up to 1600 px. Design it for the narrow
131
+ panel first, then let it spread out when there is room - never the other way
132
+ round. At every width:
133
+
134
+ 1. **Everything is reachable.** Every list, form, button and piece of
135
+ content the wide page shows can be reached on the narrow one - shown
136
+ stacked, or one tap away. Nothing is hidden because there is no room.
137
+ 2. **Nothing scrolls sideways.** The page scrolls down, never across; long
138
+ text wraps.
139
+ 3. **Controls stay usable**: inputs full width in forms, buttons that wrap to
140
+ the next line instead of shrinking or overflowing.
141
+
142
+ How, with the kit:
143
+
144
+ - One column by default: `Stack` for blocks one under another. `Grid` puts
145
+ cards side by side only when each gets at least `min` px, and stacks them
146
+ otherwise.
147
+ - **A list and what opens from it** (mail and a message, orders and an
148
+ order, items and an edit form) is always `Split`. Narrow, it shows the list,
149
+ or only what is open with a Back button; wide, both side by side. Whatever
150
+ the user can open - **including a "New …" or edit form** - goes in
151
+ `detail`, and `detail` is `null` when nothing is open:
152
+
153
+ ```tsx
154
+ const [openId, setOpenId] = useHashState('open');
155
+ const [composing, setComposing] = useState(false);
156
+ <Split
157
+ list={<Inbox onOpen={setOpenId} onNew={() => setComposing(true)} />}
158
+ detail={
159
+ composing ? (
160
+ <Compose onDone={() => setComposing(false)} />
161
+ ) : openId ? (
162
+ <Message id={openId} />
163
+ ) : null
164
+ }
165
+ onBack={() => {
166
+ setComposing(false);
167
+ setOpenId('');
168
+ }}
169
+ placeholder="Pick a message, or write a new one."
170
+ />;
171
+ ```
172
+
173
+ Never place a second panel beside a list any other way (two `Card`s in a
174
+ `Grid`, your own two-column css): on a narrow panel one of them ends up
175
+ below the other or out of reach.
176
+
177
+ - `Toolbar` and `.row` wrap their controls; keep each control at its natural
178
+ width. A form is a `Stack` of `Field`s inside a `Card`: its inputs take the
179
+ full width.
180
+ - A row of a list (sender, subject, date, actions) is a `.row` that wraps, or
181
+ two lines - not fixed columns.
182
+ - Your own css: no fixed widths over 360 px, no fixed grid columns
183
+ (`grid-template-columns: 160px 1fr`), no `display: none` in a media or
184
+ container query, no `100vh` or `overflow: hidden` on the page. The build
185
+ rejects them. Wider layouts go inside `@container page (min-width: …)` - the
186
+ page's width, not the window's, since the panel can be narrow on a wide
187
+ screen.
134
188
  - Anything you add inside a grid or flex row gets `min-width: 0` (the kit's
135
- `.card` has it), or a chart, table or long text pushes the page wider than
136
- the panel.
137
- - Let the page scroll; do not lock the body to `100vh`.
189
+ cards and stacks have it), or a chart, table or long text pushes the page
190
+ wider than the panel.
138
191
  - Light and dark: colours come from the kit's CSS variables, switched by
139
192
  `prefers-color-scheme`. Use `var(--fg)`, `var(--muted)`, `var(--line)`,
140
193
  `var(--accent)`, `var(--danger)` - no hard-coded colours. For styles of
141
194
  your own, `import './app.css'`.
142
- - Controls in one wrapping row at the top; then headline numbers; then
143
- charts or the list; the detailed table last.
195
+ - Order, top to bottom: controls in one wrapping row; then headline numbers;
196
+ then charts or the list; the detailed table last.
144
197
 
145
198
  ## Page code
146
199
 
@@ -149,6 +202,15 @@ horizontal scrolling. The kit's components do this; keep to their rules:
149
202
  - State lives in hooks; everything on the page is drawn from it, so the
150
203
  numbers, charts and lists always agree. Derive filtered rows and chart
151
204
  options with `useMemo` from the data and the filters.
205
+ - **The page speaks the user's language, never the builder's.** Nothing the
206
+ user sees - titles, subtitles, labels, footers, empty states, error
207
+ messages, tooltips - names how it is made: no "stored in SQLite", "saved
208
+ to the database", "via the API", "calls a Python function", "loaded from
209
+ data.json", "built with React", no table, file, function or endpoint
210
+ names. Say what it means for the user instead: "Saved", "Your items",
211
+ "Updated just now", "Couldn't load orders - try again". A source line
212
+ names where the numbers come from in business terms ("Q1 orders export"),
213
+ not the file or service.
152
214
  - Show "Loading…", an empty state ("No orders yet", "No data for these
153
215
  filters") and errors on the page with `Loading`, `Empty` and `ErrorBox` -
154
216
  never fail silently. `useCall` and `useAction` catch errors for you.
@@ -152,24 +152,60 @@ export function Card({
152
152
  );
153
153
  }
154
154
 
155
+ /** Cards and blocks one under another, with the page's gap. */
156
+ export function Stack({ children }: { children?: ReactNode }) {
157
+ return <div className="stack">{children}</div>;
158
+ }
159
+
155
160
  /**
156
- * A list and the item opened from it. Wide: side by side. Narrow (the chat's side panel):
157
- * the list, or the item when one is open - give the item a Back button that closes it.
161
+ * A list and what is open from it: a message, a record, a form to write a new one.
162
+ *
163
+ * Wide: side by side, `placeholder` on the right while nothing is open.
164
+ * Narrow (the chat's side panel): the list, or - while `detail` is given - only the detail,
165
+ * with a Back button (calling `onBack`) above it.
166
+ *
167
+ * `detail` is null when nothing is open, and whatever is open otherwise: anything the user
168
+ * can open, including a compose or edit form, goes in it, so it is reachable at every width.
169
+ *
170
+ * <Split
171
+ * list={<Inbox onOpen={setOpenId} onNew={() => setComposing(true)} />}
172
+ * detail={composing ? <Compose … /> : openId != null ? <Message id={openId} /> : null}
173
+ * onBack={() => { setComposing(false); setOpenId(null); }}
174
+ * />
158
175
  */
159
176
  export function Split({
160
177
  list,
161
178
  detail,
162
- open,
179
+ onBack,
180
+ placeholder = 'Pick an item to open it.',
181
+ backLabel = 'Back',
163
182
  }: {
164
183
  list: ReactNode;
184
+ /** what is open, or null (or false) when nothing is */
165
185
  detail: ReactNode;
166
- /** whether an item is open (detail shown instead of the list when narrow) */
167
- open: boolean;
186
+ /** closes what is open: the narrow layout's Back button */
187
+ onBack: () => void;
188
+ placeholder?: ReactNode;
189
+ backLabel?: ReactNode;
168
190
  }) {
191
+ const open = detail != null && detail !== false;
169
192
  return (
170
193
  <div className={`split${open ? ' split-open' : ''}`}>
171
194
  <div className="split-list">{list}</div>
172
- <div className="split-detail">{detail}</div>
195
+ <div className="split-detail">
196
+ {open ? (
197
+ <>
198
+ <button className="split-back" onClick={onBack}>
199
+ ← {backLabel}
200
+ </button>
201
+ {detail}
202
+ </>
203
+ ) : (
204
+ <Card>
205
+ <Empty>{placeholder}</Empty>
206
+ </Card>
207
+ )}
208
+ </div>
173
209
  </div>
174
210
  );
175
211
  }
@@ -28,6 +28,7 @@ export {
28
28
  SafeHtml,
29
29
  Select,
30
30
  Split,
31
+ Stack,
31
32
  Toolbar,
32
33
  type Option,
33
34
  } from './components.tsx';
@@ -123,6 +123,15 @@ body {
123
123
  .row > * {
124
124
  min-width: 0;
125
125
  }
126
+ .stack {
127
+ display: grid;
128
+ gap: var(--gap);
129
+ align-content: start;
130
+ }
131
+ .stack > * {
132
+ min-width: 0;
133
+ }
134
+ /* Narrow: the list, or what is open with a Back button. Wide: both side by side. */
126
135
  .split {
127
136
  display: grid;
128
137
  gap: var(--gap);
@@ -130,6 +139,19 @@ body {
130
139
  .split > * {
131
140
  min-width: 0;
132
141
  }
142
+ .split-list,
143
+ .split-detail {
144
+ display: grid;
145
+ gap: var(--gap);
146
+ align-content: start;
147
+ }
148
+ .split-list > *,
149
+ .split-detail > * {
150
+ min-width: 0;
151
+ }
152
+ .split-back {
153
+ justify-self: start;
154
+ }
133
155
  .split.split-open > .split-list,
134
156
  .split:not(.split-open) > .split-detail {
135
157
  display: none;
@@ -141,7 +163,10 @@ body {
141
163
  }
142
164
  .split.split-open > .split-list,
143
165
  .split:not(.split-open) > .split-detail {
144
- display: block;
166
+ display: grid;
167
+ }
168
+ .split-back {
169
+ display: none;
145
170
  }
146
171
  }
147
172
 
@@ -157,6 +182,11 @@ body {
157
182
  gap: 2px;
158
183
  font-size: 0.85rem;
159
184
  color: var(--muted);
185
+ min-width: 0;
186
+ }
187
+ .stack > .field > :is(input, textarea, select),
188
+ .card > .field > :is(input, textarea, select) {
189
+ width: 100%;
160
190
  }
161
191
  input,
162
192
  select,
@@ -214,7 +214,8 @@ function typecheck(tools: Tools, dir: string, entries: Entry[]): Problem[] {
214
214
  types: [],
215
215
  paths: {
216
216
  '@page/kit': [KIT_INDEX],
217
- '*': [`${tools.modules}/*`, `${tools.types}/*`],
217
+ // Types first: react itself is untyped JavaScript, which would quietly make it `any`.
218
+ '*': [`${tools.types}/*`, `${tools.modules}/*`],
218
219
  },
219
220
  };
220
221
  const program = ts.createProgram(
@@ -244,6 +245,137 @@ function hostOf(url: string): string {
244
245
  }
245
246
  }
246
247
 
248
+ // ---- Layout: the chat's side panel is 360 - 600 px wide, and a page must work there ----
249
+
250
+ /** What the narrowest panel leaves for a page's content, in px. */
251
+ const NARROW = 360;
252
+ /** Fixed columns adding up to more than this leave too little for the rest at NARROW. */
253
+ const FIXED_COLUMNS = 140;
254
+
255
+ /** A length in px, for px, rem and em; null for anything relative (%, fr, vw, auto, calc). */
256
+ function pxOf(value: string): number | null {
257
+ const m = /^\s*(\d+(?:\.\d+)?)(px|rem|em)\s*$/.exec(value);
258
+ if (!m) return null;
259
+ return Number(m[1]) * (m[2] === 'px' ? 1 : 16);
260
+ }
261
+
262
+ /** Where a declaration is: inside which at-rules, under which selector. */
263
+ interface CssWhere {
264
+ /** inside @media / @container */
265
+ query: boolean;
266
+ /** inside a query that only applies from some width up: fixed widths are fine there */
267
+ wideOnly: boolean;
268
+ selector: string;
269
+ }
270
+
271
+ /** What is wrong with one declaration for a narrow panel, or null. */
272
+ function layoutProblem(prop: string, value: string, where: CssWhere): string | null {
273
+ const v = value.replace(/!important/i, '').trim();
274
+ if (prop === 'display' && /^none$/i.test(v) && where.query) {
275
+ return (
276
+ 'display: none in a media or container query hides this at some widths: everything ' +
277
+ 'shown on a wide page must be reachable on a narrow one - stack it, or put it in ' +
278
+ "Split's detail (narrow: the list or the detail, with a Back button)"
279
+ );
280
+ }
281
+ if (where.wideOnly) return null;
282
+ if (['width', 'min-width', 'flex-basis'].includes(prop)) {
283
+ const px = pxOf(v);
284
+ if (px !== null && px > NARROW) {
285
+ return (
286
+ `${prop}: ${v} is wider than the chat's side panel (${NARROW} px): use max-width, ` +
287
+ 'a percentage, or flex/grid that wraps'
288
+ );
289
+ }
290
+ }
291
+ if (prop === 'grid-template-columns') {
292
+ const floor = /minmax\(\s*(\d+(?:\.\d+)?(?:px|rem|em))\s*,/.exec(v);
293
+ const floorPx = floor ? pxOf(floor[1]!) : null;
294
+ if (floorPx !== null && floorPx > NARROW / 2 && /repeat\(\s*auto-(fit|fill)/.test(v)) {
295
+ return (
296
+ `minmax(${floor![1]}, …) overflows a narrow panel: write ` +
297
+ `minmax(min(100%, ${floor![1]}), 1fr), or use the kit's Grid`
298
+ );
299
+ }
300
+ // Fixed tracks outside min()/max()/minmax()/clamp(), repeat(n, …) counted n times.
301
+ let tracks = v;
302
+ for (;;) {
303
+ const next = tracks.replace(
304
+ /repeat\(\s*(\d+)\s*,\s*([^()]*)\)/g,
305
+ (_, n: string, inner: string) => ` ${inner} `.repeat(Number(n)),
306
+ );
307
+ const stripped = next.replace(/[a-z-]+\([^()]*\)/gi, ' ');
308
+ if (stripped === tracks) break;
309
+ tracks = stripped;
310
+ }
311
+ const fixed = tracks
312
+ .split(/\s+/)
313
+ .map((t) => pxOf(t) ?? 0)
314
+ .reduce((a, b) => a + b, 0);
315
+ if (fixed > FIXED_COLUMNS) {
316
+ return (
317
+ `fixed columns of ${fixed} px leave little of a ${NARROW} px panel for the rest: ` +
318
+ 'use minmax(0, 1fr) columns and stack the row when narrow, or give the fixed ' +
319
+ 'columns only inside an @container (min-width: …) query'
320
+ );
321
+ }
322
+ }
323
+ if (/(^|,|\s)(html|body|:root|#root)\b/.test(where.selector)) {
324
+ if ((prop === 'height' || prop === 'max-height') && /vh\b/.test(v)) {
325
+ return `${prop}: ${v} on the page itself locks it to the window: let the page scroll`;
326
+ }
327
+ if (/^overflow(-y)?$/.test(prop) && /hidden/.test(v)) {
328
+ return `${prop}: ${v} on the page itself cuts it off: let the page scroll`;
329
+ }
330
+ }
331
+ return null;
332
+ }
333
+
334
+ /** Layout problems of a stylesheet, at their lines. */
335
+ function cssProblems(dir: string, file: string): Problem[] {
336
+ const text = readFileSync(file, 'utf8').replace(/\/\*[\s\S]*?\*\//g, (c) =>
337
+ c.replace(/[^\n]/g, ' '),
338
+ );
339
+ const problems: Problem[] = [];
340
+ const stack: string[] = [];
341
+ let start = 0;
342
+ const lineAt = (i: number) => text.slice(0, i).split('\n').length;
343
+ const declaration = (end: number) => {
344
+ const raw = text.slice(start, end);
345
+ const m = /^(\s*)([-\w]+)\s*:([\s\S]*)$/.exec(raw);
346
+ if (!m || !stack.length) return;
347
+ const at = start + m[1]!.length;
348
+ const queries = stack.filter((h) => /^@(media|container)\b/i.test(h));
349
+ const where: CssWhere = {
350
+ query: queries.length > 0,
351
+ wideOnly: queries.some((q) => /min-width|width\s*>=?/i.test(q)),
352
+ selector: [...stack].reverse().find((h) => !h.startsWith('@')) ?? '',
353
+ };
354
+ const message = layoutProblem(m[2]!.toLowerCase(), m[3]!.trim(), where);
355
+ if (message) {
356
+ const col = at - text.lastIndexOf('\n', at - 1);
357
+ problems.push({ file: rel(dir, file), line: lineAt(at), col, message });
358
+ }
359
+ };
360
+ for (let i = 0; i < text.length; i++) {
361
+ const c = text[i];
362
+ if (c === '{') {
363
+ stack.push(text.slice(start, i).trim());
364
+ start = i + 1;
365
+ } else if (c === ';') {
366
+ declaration(i);
367
+ start = i + 1;
368
+ } else if (c === '}') {
369
+ declaration(i);
370
+ stack.pop();
371
+ start = i + 1;
372
+ }
373
+ }
374
+ return problems;
375
+ }
376
+
377
+ const kebab = (name: string) => name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
378
+
247
379
  function rules(tools: Tools, dir: string, sources: string[]): Problem[] {
248
380
  const { ts } = tools;
249
381
  const problems: Problem[] = [];
@@ -274,6 +406,10 @@ function rules(tools: Tools, dir: string, sources: string[]): Problem[] {
274
406
  };
275
407
 
276
408
  for (const file of sources) {
409
+ if (file.endsWith('.css')) {
410
+ problems.push(...cssProblems(dir, file));
411
+ continue;
412
+ }
277
413
  if (!/\.tsx?$/.test(file) || file.endsWith('.d.ts')) continue;
278
414
  const text = readFileSync(file, 'utf8');
279
415
  const sf = ts.createSourceFile(
@@ -365,6 +501,35 @@ function rules(tools: Tools, dir: string, sources: string[]): Problem[] {
365
501
  node,
366
502
  'no raw html: use JSX (it escapes), or SafeHtml for html from outside',
367
503
  );
504
+ } else if (
505
+ ts.isJsxAttribute(node) &&
506
+ node.name.getText(sf) === 'style' &&
507
+ node.initializer &&
508
+ ts.isJsxExpression(node.initializer) &&
509
+ node.initializer.expression &&
510
+ ts.isObjectLiteralExpression(node.initializer.expression)
511
+ ) {
512
+ // style={{ width: 600, gridTemplateColumns: '200px 1fr' }}: the same rules as css.
513
+ for (const prop of node.initializer.expression.properties) {
514
+ if (!ts.isPropertyAssignment(prop)) continue;
515
+ const name =
516
+ ts.isIdentifier(prop.name) || ts.isStringLiteral(prop.name)
517
+ ? prop.name.text
518
+ : '';
519
+ const init = prop.initializer;
520
+ const value = ts.isNumericLiteral(init)
521
+ ? `${init.text}px`
522
+ : ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)
523
+ ? init.text
524
+ : null;
525
+ if (!name || value === null) continue;
526
+ const message = layoutProblem(kebab(name), value, {
527
+ query: false,
528
+ wideOnly: false,
529
+ selector: '',
530
+ });
531
+ if (message) report(prop, message);
532
+ }
368
533
  } else if (
369
534
  ts.isJsxAttribute(node) &&
370
535
  node.name.getText(sf) === 'dangerouslySetInnerHTML'