kunibert
All repositories: gitoria
12.0 KB
# Hybriel + hl:web usage standard2026-11-09 · Checked against hybriel `ea3966e8f6996e62f16b63a05def0c89579b4096`.Replaces CODE-ORDER; merges its rules below; the primer remains the explanation.References: [SPEC.md](../SPEC.md) (truth), [HL-PRIMER.md](HL-PRIMER.md), [COMPONENTS.md](../COMPONENTS.md).## Part A — Language (owner Anton)Wrong → right pairs show intent; style violations can compile. Spot commands find review candidates, not proofs; run from the app root.**L1.** Do not end a statement with `;` (classic `for` clauses and braced hybrid entries may use it).`x = 1;` → `x = 1`Spot: `rg -n ';\s*$' -g '*.hl'`**L2.** Use `let` only for a name reassigned later; otherwise use a plain declaration.`let n = items.length` → `n = items.length`Spot: `rg -n '\blet\b' -g '*.hl'` (check subsequent writes).**L3.** Call functions directly: calls await automatically; do not add `async`, `await` or Promise `.then` chains.`await save()` → `save()`Spot: `rg -n '\b(async|await)\b|\.then\(' -g '*.hl'`**L4.** Function values require parenthesized parameters and a block body.`n => n + 1` → `(n) => { return n + 1 }`Spot: `rg -n '=>' -g '*.hl'`**L5.** Handle expected failures with value forms (`JSON.tryParse`, `tryFetch`, `tryReadFile`) or `on Error(e)`, never `try`/`catch`/`throw`.`try { JSON.parse(t) }` → `JSON.tryParse(t)`Spot: `rg -n '\b(try|catch|throw)\b' -g '*.hl'`**L6.** Build strings with `+` or `join`; interpolation is literal text and `\n` is two characters (write a real newline).`"a ${b}"` → `'a ' + b`Spot: `rg -n '\$\{|\\n' -g '*.hl'`**L7.** Name literal fields with `=` or `=name`; bare names are ordered entries, not named-field shorthand.`{ id, name }` → `{ =id =name }`Spot: `rg -n '\{\s*\w+\s*,' -g '*.hl'` (destructuring differs).**L8.** Read needed outer values before a same-named literal entry shadows them for later entries.`card(app) { return { app = app.id n = app.name } }` → `card(app) { name = app.name return { app = app.id n = name } }`Spot: review literals in entry order (#292).**L9.** Test an ordered hybrid's length for emptiness; even an empty hybrid is true.`if (rows) { echo('nonempty') }` → `if (rows.length > 0) { echo('nonempty') }`Spot: `rg -n 'if\s*\(\w+\)' -g '*.hl'`**L10.** Type every function parameter; a member or local whose initializer shows its type (`count = 0`, `n = items.length`) needs none. Convert numeric text with `toNumber` (Number or null), never arithmetic coercion.`save(id, title) { … }`, `"42" - 0` → `save(String id, String title) { … }`, `n = toNumber("42")`Spot: `rg -n ' - 0' -g '*.hl'`; review parameter lists. An untyped member with a literal or `null` initializer is not a finding.A record or list parameter is `Hybrid r`, and so are hl:web's `route`, `req` and DOM event parameters (`on submit(Hybrid e)`; `Object` is refused). A `&` parameter stays untyped (`fill(&list)`), because the parser refuses `Hybrid &x`.**L11.** Hybrids and Bytes copy on assignment/call; to change the caller's variable, use a mutable binding and `&` at both ends.`fill(&list) { list.push(1) } let list = [] fill(list)` → `fill(&list) { list.push(1) } let list = [] fill(&list)`Spot: `rg -n '&' -g '*.hl'` (compare caller and parameter).**L12.** Put members at file root: one file is one class, root statements run at construction; no class wrapper, `constructor`, `__construct` or `on start()` entry hook.`class Home { name = "Home" }` → `String name = "Home"`Spot: `rg -n '\bclass\b|\b(__construct|constructor)\b|on start\(' -g '*.hl'`**L13.** Pass cross-realm values as emit arguments; a server face's last `session` parameter belongs to the server, never the peer.`emit server save()` / `on server save(session) { echo(id) }` → `emit server save(id)` / `on server save(String id, session) { echo(id) }`Spot: `rg -n 'emit |on .*session' -g '*.hl'` (review reads of members written by the other realm).The following merge CODE-ORDER's creator rules (2026-10-03), including L2 above. Creator: "why is `let` in all projects constantly misused? let is needed to make a variable overwritable … why is the project.hl cluttered with deeper process functions? why are .hl files scattered in the project roots?" — and on patterns: "i dont really want to rewrite code or add complexity with higher concepts, its enough if things that belong together land in the same file … one file that holds the central logic, so it gets that at one look and stuff it can look up additionally goes in helper files."**L14.** Keep `project.hl` a map: config, routes/wiring and a short index with one line per feature naming its file; put process/helper functions elsewhere.`helper(String s) { return s.toUpperCase() }` in `project.hl` → `import { helper } from './lib/util.hl'`Spot: `rg -n '^\s*(static\s+)?([A-Z]\w*\s+)?\w+\(' project.hl` (also review function literals).**L15.** Keep only `project.hl` as root `.hl`; use `components/` for UI, `lib/` for logic, `tools/` for CLI tools and `tests/` for gates.`// root: tool.hl` → `// tools/tool.hl`Spot: `find . -maxdepth 1 -name '*.hl' -print`**L16.** Keep one topic's central logic and all writes to its tables in `lib/<topic>.hl`, readable at one look; move formatting/parsing/noise and shared helpers to `lib/util.hl` or `lib/<topic>-helpers.hl`, never copy them.`// components/posts.hl: save logic` → `// lib/posts.hl: save logic`Spot: review `lib/shows.hl`, `lib/watches.hl`, `lib/sync.hl` by topic; shared env/date/path helpers belong in `lib/util.hl` once.**L17.** Keep API endpoints, faces and page handlers thin: check input/session, call the topic function, return; no business logic in `api.hl`, `project.hl` or components.`on server save(String title) { return title.trim() }` → `on server save(String title) { return saveTitle(title) }`Spot: review handlers; line count alone does not establish thinness.**L18.** Group plainly by topic without models/repository/services layers, factories or service classes; cleanups preserve behavior, page output and green gates before/after.`// services/posts.hl: makeService()` → `// lib/posts.hl: save()`Spot: `find . -type d \( -name models -o -name repository -o -name services \)`; compare gates and page output for cleanups.Creator: “i ment one central logic per topic … i would also move out noise from it or functions shared between topics … the api is probably just a wrapper that then calls a function from the topic.”**L19.** Use `echo` for browser output; bare `print`/`log` are native-only builtins and the JS target refuses them.`print(x)` → `echo(x)`Spot: `rg -n '\b(print|log)\(' -g '*.hl'` (exclude `console.log` and user bindings).## Part B — Framework (owner Arachne)F1-F21 are checked against the current build. A wrong form marked "refused at build" does not boot; the others compile and need review. Run Spots from the app root.**F1.** Going somewhere is a link with a real address.`span { "Post" on click() { navigate(url) } }` → `a { href = url "Post" }`**F2.** Doing something is a `button` with `type = "button"`.`b { "✕" on click() { del(id) } }` → `button { type = "button" "✕" on click() { del(id) } }`**F3.** No `on click` on `b`, `span`, `div`, `li`, `ol`, a custom element, or an `a` without `href`.Spot: `rg -n '(^|\s)(b|span|div|li|ol|p|[a-z]+-[a-z-]+) \{[^}]*on click' -g '*.hl'`; `rg -n '\ba \{[^}]*on click' -g '*.hl' | rg -v href`; `rg -n -B3 'on click' -g '*.hl'` (element on the line above).**F4.** Every state a user can return to (page, tab, filter, search, selected row, page number) is in the URL: a route parameter or `route.query`; `navigate(path)` adds a history entry, `navigate(path, replace = true)` replaces it.`tab = 'songs'` in a handler → route `/artists/:id/:tab`, link `a { href = songsUrl }`; read `route.query.q` (`route = null` member).**F5.** Reload, Back, Forward and "open in new tab" on any URL show the same state. Checked in the e2e test (F21).**F6.** The app's own pages are left with `navigate`, never `location.assign`, `location.href =` or `location.replace`; `location.reload()` only on `r.stale` in `on client reconnected(r)`.`window.location.assign('/')` → `navigate('/')` (`import { navigate } from 'hl:web'`)Spot: `rg -n 'location\.(assign|replace|href\s*=)' -g '*.hl'`**F7.** Input is a `form` with named, labelled controls and a submit button; Enter submits; the handler is `on submit(e)`.`input` + `button { on click() { add() } }` → `form { on submit(e) { add() } label { "Search" input { name = "q" } } button { "Add" } }`**F8.** State changes are member writes; the framework patches the page.`document.createElement('li')`, `innerHTML` → `rows.push({ id = 1 title = t })` with `for (r of rows) { li { r.title } }` in the View.**F9.** No `document.*` or `innerHTML` to find or write app state; a direct DOM write is only a transient gesture effect on the event's own element.Spot: `rg -n 'document\.|innerHTML' -g '*.hl'`**F10.** No hand-written JavaScript: no `assets/*.js` logic, no `script { … }` with code, no JS in string members, no `window.*` as state or mailbox. The only exception is F11.`script { src = '/assets/pwa.js' }` → `.hl` handlers and membersSpot: `rg -n 'script \{|window\.' -g '*.hl'`; `ls assets/*.js`**F11.** JavaScript is allowed only as an unmodified third-party module, imported at the root of a component by `import js Name from 'module'` (or `import js { a, b } from 'module'`; SPEC.md "import js"); its version is recorded next to the import. App logic, state, DOM building and event wiring stay in `.hl`.own `main.js` calling the library → `import js Chart from 'chart.js' // 4.4.1` in the `.hl` component**F12.** Offline, install and push come from the manifest: `offline = [ Page ]`, `offlineFallback`, `offlineFiles`, `appIcons`, `pushKey`. No own service worker.`{ pattern = "/sw.js" … }` → `offline = [ Home ]` `offlineFallback = Home`Spot: `rg -n 'sw\.js|serviceWorker' -g '*.hl'`**F13.** Connection state is `__hlOnline = true`, `__hlReach = 'connecting'` and `on client reachability(r)` / `on client reconnected(r)`; never `window.__hl*`.`window.__hlAttempt(fetch('/api/online'))` → `__hlReach = 'connecting'` and `if (__hlReach == 'down') { … }`Spot: `rg -n 'window\.__hl' -g '*.hl'`**F14.** A component's look lives in its own `Style { }`; no inline `style =`; mobile first (390 px).`p { style = 'color:red' }` → `Style { warn { color = 'red' } }` and `p { Style.warn }`Spot: `rg -n "(^|[\s{])style\s*=\s*['\"]" -g '*.hl'`**F15.** Server data comes from member initializers that read a server import; later changes are `emit client …` (with an `audience` entry for other tabs). No load-on-mount emit, no polling.`setInterval(() => { reload() }, 5000)` → `all = db.list()` and `on client changed(rows) { all = rows }`Spot: `rg -n 'setInterval|setTimeout' -g '*.hl'`**F16.** A component reaches its host with `$parent.fn(x)` in a handler (never in the View or an initializer, never a write); values go in as component arguments (`Row { title = r.title }`); no cross-file emit.`emit rowPicked()` handled in the host's file → `$parent.pick(rid)`**F17.** One file is one component; layout through `parent './main.hl'` (the parent declares `slot = null`); routes are in the manifest with `component =`; who is logged in is the `session = null` member.parsing the cookie → `session = null`, then `session.user`**F18.** Lists are `for (r of rows)` in the View over records with an `id`, changed by `push`, `upsert(record)` and one-argument `remove(id)`.`list = list.map((q) => { return q })` in a handler → `rows.upsert(row)`; `rows.remove(rid)`Spot: `rg -n '\w+ = \w+\.(map|filter)\(' -g '*.hl'`**F19.** A View attribute is a literal, a member or a field path. Refused at build.`href = '/posts/' + id` → root `postUrl = '/posts/' + id`, then `href = postUrl`**F20.** If the framework cannot do it: stop, file a hybriel ticket, wait; a workaround is a finding. Open gaps: mount event (#236), modal dialog (#329).comment "framework gap" above a bypass → the ticket number in the report, no bypass**F21.** Each app has a real-browser e2e test that covers F5, keyboard use (Tab, Enter) and, for an `offline` app, an offline reload that still shows the shell.
Branches
Latest commits
- bd3591c7conductor: gates run on the live day44 binarymre
- 47f747a7records: jukebox #9 fix livemre
- 0a3169fdMerge branch 'vendored-size' into mainKunibert
- e447bb09Vendored size fix: keep renames with an app side whole; type the filter parameter (L10)mre
- 99ccc742Vendored size fix: no renames in the app diff, filter the resumed delta toomre
- 1a52e100|||PR Diff size limit counts only app files when vendored paths are setmre
- 50a1867estatus: jukebox #9mre
- c57484e6log: jukebox #9 diff sizemre
- 795a20carecords: guard fix live (PR 8)mre
- 6981d96fMerge branch 'fresh-on-nocmd' into mainKunibert
- 37c47840runner: one shared prompt for both fresh-session fallbacks (L16)mre
- f945d2e1|||PR runner: a resumed run with no command on a new head gets one fresh session instead of a tool errormre
- 10b2a49estatus: PR 314, guard fix proposedmre
- e73995a3log: hycon PR 314 approved after fresh reviewmre
- f60427falog: hycon PR 314 false tool errormre
- 481974f7log: Hermes accepts PR 259 findingmre
- bb0976acrecords: hycon PR 259 design findingmre
- 5c637c24records: hycon PR 259 false tool errormre
- a344c406log: routger 132 reviewedmre
- 56e70dcbrecords: review time limit 1800 s (routger 132)mre