gitoria

kunibert

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmainbd3591c7conductor: gates run on the live day44 binarymremain/rules/HL-STANDARD.md

12.0 KB

  1. # Hybriel + hl:web usage standard
  2. 2026-11-09 · Checked against hybriel `ea3966e8f6996e62f16b63a05def0c89579b4096`.
  3. Replaces CODE-ORDER; merges its rules below; the primer remains the explanation.
  4. References: [SPEC.md](../SPEC.md) (truth), [HL-PRIMER.md](HL-PRIMER.md), [COMPONENTS.md](../COMPONENTS.md).
  5. ## Part A — Language (owner Anton)
  6. Wrong → right pairs show intent; style violations can compile. Spot commands find review candidates, not proofs; run from the app root.
  7. **L1.** Do not end a statement with `;` (classic `for` clauses and braced hybrid entries may use it).
  8. `x = 1;` → `x = 1`
  9. Spot: `rg -n ';\s*$' -g '*.hl'`
  10. **L2.** Use `let` only for a name reassigned later; otherwise use a plain declaration.
  11. `let n = items.length` → `n = items.length`
  12. Spot: `rg -n '\blet\b' -g '*.hl'` (check subsequent writes).
  13. **L3.** Call functions directly: calls await automatically; do not add `async`, `await` or Promise `.then` chains.
  14. `await save()` → `save()`
  15. Spot: `rg -n '\b(async|await)\b|\.then\(' -g '*.hl'`
  16. **L4.** Function values require parenthesized parameters and a block body.
  17. `n => n + 1` → `(n) => { return n + 1 }`
  18. Spot: `rg -n '=>' -g '*.hl'`
  19. **L5.** Handle expected failures with value forms (`JSON.tryParse`, `tryFetch`, `tryReadFile`) or `on Error(e)`, never `try`/`catch`/`throw`.
  20. `try { JSON.parse(t) }` → `JSON.tryParse(t)`
  21. Spot: `rg -n '\b(try|catch|throw)\b' -g '*.hl'`
  22. **L6.** Build strings with `+` or `join`; interpolation is literal text and `\n` is two characters (write a real newline).
  23. `"a ${b}"` → `'a ' + b`
  24. Spot: `rg -n '\$\{|\\n' -g '*.hl'`
  25. **L7.** Name literal fields with `=` or `=name`; bare names are ordered entries, not named-field shorthand.
  26. `{ id, name }` → `{ =id =name }`
  27. Spot: `rg -n '\{\s*\w+\s*,' -g '*.hl'` (destructuring differs).
  28. **L8.** Read needed outer values before a same-named literal entry shadows them for later entries.
  29. `card(app) { return { app = app.id n = app.name } }` → `card(app) { name = app.name return { app = app.id n = name } }`
  30. Spot: review literals in entry order (#292).
  31. **L9.** Test an ordered hybrid's length for emptiness; even an empty hybrid is true.
  32. `if (rows) { echo('nonempty') }` → `if (rows.length > 0) { echo('nonempty') }`
  33. Spot: `rg -n 'if\s*\(\w+\)' -g '*.hl'`
  34. **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.
  35. `save(id, title) { … }`, `"42" - 0` → `save(String id, String title) { … }`, `n = toNumber("42")`
  36. Spot: `rg -n ' - 0' -g '*.hl'`; review parameter lists. An untyped member with a literal or `null` initializer is not a finding.
  37. 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`.
  38. **L11.** Hybrids and Bytes copy on assignment/call; to change the caller's variable, use a mutable binding and `&` at both ends.
  39. `fill(&list) { list.push(1) } let list = [] fill(list)` → `fill(&list) { list.push(1) } let list = [] fill(&list)`
  40. Spot: `rg -n '&' -g '*.hl'` (compare caller and parameter).
  41. **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.
  42. `class Home { name = "Home" }` → `String name = "Home"`
  43. Spot: `rg -n '\bclass\b|\b(__construct|constructor)\b|on start\(' -g '*.hl'`
  44. **L13.** Pass cross-realm values as emit arguments; a server face's last `session` parameter belongs to the server, never the peer.
  45. `emit server save()` / `on server save(session) { echo(id) }` → `emit server save(id)` / `on server save(String id, session) { echo(id) }`
  46. Spot: `rg -n 'emit |on .*session' -g '*.hl'` (review reads of members written by the other realm).
  47. 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."
  48. **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.
  49. `helper(String s) { return s.toUpperCase() }` in `project.hl` → `import { helper } from './lib/util.hl'`
  50. Spot: `rg -n '^\s*(static\s+)?([A-Z]\w*\s+)?\w+\(' project.hl` (also review function literals).
  51. **L15.** Keep only `project.hl` as root `.hl`; use `components/` for UI, `lib/` for logic, `tools/` for CLI tools and `tests/` for gates.
  52. `// root: tool.hl` → `// tools/tool.hl`
  53. Spot: `find . -maxdepth 1 -name '*.hl' -print`
  54. **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.
  55. `// components/posts.hl: save logic` → `// lib/posts.hl: save logic`
  56. Spot: review `lib/shows.hl`, `lib/watches.hl`, `lib/sync.hl` by topic; shared env/date/path helpers belong in `lib/util.hl` once.
  57. **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.
  58. `on server save(String title) { return title.trim() }` → `on server save(String title) { return saveTitle(title) }`
  59. Spot: review handlers; line count alone does not establish thinness.
  60. **L18.** Group plainly by topic without models/repository/services layers, factories or service classes; cleanups preserve behavior, page output and green gates before/after.
  61. `// services/posts.hl: makeService()` → `// lib/posts.hl: save()`
  62. Spot: `find . -type d \( -name models -o -name repository -o -name services \)`; compare gates and page output for cleanups.
  63. 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.”
  64. **L19.** Use `echo` for browser output; bare `print`/`log` are native-only builtins and the JS target refuses them.
  65. `print(x)` → `echo(x)`
  66. Spot: `rg -n '\b(print|log)\(' -g '*.hl'` (exclude `console.log` and user bindings).
  67. ## Part B — Framework (owner Arachne)
  68. 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.
  69. **F1.** Going somewhere is a link with a real address.
  70. `span { "Post" on click() { navigate(url) } }` → `a { href = url "Post" }`
  71. **F2.** Doing something is a `button` with `type = "button"`.
  72. `b { "✕" on click() { del(id) } }` → `button { type = "button" "✕" on click() { del(id) } }`
  73. **F3.** No `on click` on `b`, `span`, `div`, `li`, `ol`, a custom element, or an `a` without `href`.
  74. 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).
  75. **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.
  76. `tab = 'songs'` in a handler → route `/artists/:id/:tab`, link `a { href = songsUrl }`; read `route.query.q` (`route = null` member).
  77. **F5.** Reload, Back, Forward and "open in new tab" on any URL show the same state. Checked in the e2e test (F21).
  78. **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)`.
  79. `window.location.assign('/')` → `navigate('/')` (`import { navigate } from 'hl:web'`)
  80. Spot: `rg -n 'location\.(assign|replace|href\s*=)' -g '*.hl'`
  81. **F7.** Input is a `form` with named, labelled controls and a submit button; Enter submits; the handler is `on submit(e)`.
  82. `input` + `button { on click() { add() } }` → `form { on submit(e) { add() } label { "Search" input { name = "q" } } button { "Add" } }`
  83. **F8.** State changes are member writes; the framework patches the page.
  84. `document.createElement('li')`, `innerHTML` → `rows.push({ id = 1 title = t })` with `for (r of rows) { li { r.title } }` in the View.
  85. **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.
  86. Spot: `rg -n 'document\.|innerHTML' -g '*.hl'`
  87. **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.
  88. `script { src = '/assets/pwa.js' }` → `.hl` handlers and members
  89. Spot: `rg -n 'script \{|window\.' -g '*.hl'`; `ls assets/*.js`
  90. **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`.
  91. own `main.js` calling the library → `import js Chart from 'chart.js' // 4.4.1` in the `.hl` component
  92. **F12.** Offline, install and push come from the manifest: `offline = [ Page ]`, `offlineFallback`, `offlineFiles`, `appIcons`, `pushKey`. No own service worker.
  93. `{ pattern = "/sw.js" … }` → `offline = [ Home ]` `offlineFallback = Home`
  94. Spot: `rg -n 'sw\.js|serviceWorker' -g '*.hl'`
  95. **F13.** Connection state is `__hlOnline = true`, `__hlReach = 'connecting'` and `on client reachability(r)` / `on client reconnected(r)`; never `window.__hl*`.
  96. `window.__hlAttempt(fetch('/api/online'))` → `__hlReach = 'connecting'` and `if (__hlReach == 'down') { … }`
  97. Spot: `rg -n 'window\.__hl' -g '*.hl'`
  98. **F14.** A component's look lives in its own `Style { }`; no inline `style =`; mobile first (390 px).
  99. `p { style = 'color:red' }` → `Style { warn { color = 'red' } }` and `p { Style.warn }`
  100. Spot: `rg -n "(^|[\s{])style\s*=\s*['\"]" -g '*.hl'`
  101. **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.
  102. `setInterval(() => { reload() }, 5000)` → `all = db.list()` and `on client changed(rows) { all = rows }`
  103. Spot: `rg -n 'setInterval|setTimeout' -g '*.hl'`
  104. **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.
  105. `emit rowPicked()` handled in the host's file → `$parent.pick(rid)`
  106. **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.
  107. parsing the cookie → `session = null`, then `session.user`
  108. **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)`.
  109. `list = list.map((q) => { return q })` in a handler → `rows.upsert(row)`; `rows.remove(rid)`
  110. Spot: `rg -n '\w+ = \w+\.(map|filter)\(' -g '*.hl'`
  111. **F19.** A View attribute is a literal, a member or a field path. Refused at build.
  112. `href = '/posts/' + id` → root `postUrl = '/posts/' + id`, then `href = postUrl`
  113. **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).
  114. comment "framework gap" above a bypass → the ticket number in the report, no bypass
  115. **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