gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2f2725ac2f2725actests/browser.mjs: commit-row check (one row, centred date)MG2f2725ac/plugins/proc/server.hl

11.0 KB

  1. \* hl:proc — child processes as INSTANCE EVENTS.
  2. let server = spawn('llama-server -m ' + model + ' --port 8480')
  3. on server.line({ line, stream }) { … } \\ stream: 'stdout' | 'stderr'
  4. on server.exit({ exit, pid }) { … } \\ always arrives, kill or not
  5. server.kill() \\ SIGTERM; exit still fires
  6. server.write(text) \\ to its stdin ({ stdin = 'pipe' }): String or Bytes, raw
  7. server.end() \\ close its stdin: it reads EOF
  8. A child spawned with `{ binary = true }` delivers its output as raw Bytes
  9. instead of text lines — `on server.data({ data, stream })`, one event per
  10. chunk as it arrives, nothing split and nothing replaced. The default stays
  11. text lines.
  12. `stream` names the PIPE, not a verdict — most servers (llama.cpp included)
  13. write their whole LOG to stderr, keeping stdout for data.
  14. A CHILD DIES WITH ITS PARENT: every child is started with the kernel's
  15. parent-death signal set to SIGTERM (Linux PR_SET_PDEATHSIG), so when this
  16. program exits — any exit, a crash or Ctrl-C included — its children get
  17. SIGTERM and no orphan keeps a port. There is no option to turn it off. The
  18. setting is the child's own and is not inherited by what IT starts, so a
  19. process meant to outlive you is started one level down, by the child:
  20. spawnArgs([ 'sh', '-c', 'long-job &' ]).
  21. A command that CANNOT START has no exit — it is an ERROR: caught by
  22. `on server.Error(e)` (this instance) or the global `on Error(e)`; uncaught
  23. it is a located crash naming the binary and the errno. A finished child
  24. retires its event source, so a program whose children are done simply ends.
  25. THE PROGRAM PATH follows the Hybriel path rule: `spawn('bin/llama-server …')`
  26. resolves bin/ against THIS SCRIPT's directory (like imports and hl:fs) — a
  27. copied build folder next to your .hl file just works. A bare name searches
  28. PATH; absolute stays absolute.
  29. OPTIONS, the last argument of spawn and spawnArgs, all optional: `cwd`
  30. is the directory the child starts in — a relative one resolves against
  31. THIS SCRIPT's directory, like the program path; `env` is added to the
  32. environment the child inherits (`{ LANG = 'C' DEBUG = null }` sets LANG
  33. and removes DEBUG); `binary = true` delivers the output as Bytes (above);
  34. `stdin = 'pipe'` makes the child's stdin writable with write() and end()
  35. — without it the child inherits this program's stdin, as before.
  36. let st = spawn('git', [ 'status', '--short' ], { cwd = 'repo' })
  37. There is NO SHELL — no quoting, no expansion (the safety property, not a
  38. gap). `spawnArgs([ 'sh', '-c', pipeline ])` is how you ASK for one,
  39. explicitly. *\
  40. /* Gate file (docs campaign): __native lives only here; the Process class
  41. (process.hl) carries the instance events and their declarations. */
  42. \* Start a child from ONE command string: split on WHITESPACE RUNS (spaces,
  43. tabs AND newlines — a command written across lines is one command); a
  44. quoted argument is GROUPED and its quotes stripped ('{"a": 1}' arrives as
  45. one argv entry). A command that cannot start is an Error — caught by
  46. `on server.Error(e)` or the global `on Error(e)`. *\
  47. spawn(
  48. String cmd \\ the program and its arguments, whitespace-separated — or, with `args`, the program alone
  49. Hybrid args = null \\ the arguments as a list, each passed as is (cmd is then not split)
  50. Hybrid options = null \\ { cwd, env, stdin, binary } — see the head of this file
  51. ) {
  52. if (args == null) {
  53. return new Process().start(cmd, options)
  54. }
  55. return new Process().startArgs([cmd] + args, options)
  56. }
  57. \* The LIST form — argv exactly as given: for arguments that contain spaces,
  58. or to ask for a shell explicitly: spawnArgs([ 'sh', '-c', pipeline ]). *\
  59. spawnArgs(
  60. Hybrid args \\ argv entries, one string each — args[0] is the program
  61. Hybrid options = null \\ { cwd, env, stdin, binary }, as for spawn
  62. ) {
  63. return new Process().startArgs(args, options)
  64. }
  65. \* RUN A PROGRAM AND WAIT FOR IT (ticket #80): the blocking twin of spawn,
  66. for code that needs the output NOW — a page's root that is being
  67. constructed on the server, a build step, a script. It answers once the
  68. program has exited:
  69. let log = run([ 'git', 'log', '--oneline', '-5' ], { cwd = 'repo' })
  70. log.exit \\ the exit status (128 + n when signal n ended it)
  71. log.lines \\ stdout, one String per line, no newlines
  72. log.stderr \\ stderr, the same
  73. `command` is a String (split like spawn's) or an argv list, passed as is.
  74. `options` are spawn's `cwd`, `env` and `binary` — with `binary = true`
  75. stdout comes back whole as `data`, a Bytes, instead of `lines` — and
  76. `timeout`, in seconds: past it the program is killed and the call is an
  77. Error. `stdin`, a String or a Bytes (ticket #91), is what the program
  78. reads: written to it whole, then closed, so it reads EOF —
  79. let r = run([ 'git', 'upload-pack', '--stateless-rpc', dir ], { stdin = req.bytes binary = true })
  80. Without `stdin` the program's stdin is empty (/dev/null); a program that
  81. waited for input would otherwise hold the caller forever.
  82. The wait holds the fiber that called, as fetch() does, so a server keeps
  83. a run short or bounds it with `timeout`. A command that cannot start is an
  84. Error, as for spawn; a program that ran and failed is not — read `exit`. *\
  85. run(
  86. command \\ the program and its arguments: a String, whitespace-separated, or a list
  87. Hybrid options = null \\ { cwd, env, binary, stdin, timeout } — see above
  88. ) {
  89. // stdin crosses the plugin boundary as hex (the ABI has no Bytes), beside the options
  90. let o = options
  91. let feed = null
  92. if (o != null && o.stdin != null) {
  93. let t = hlTypeName(o.stdin)
  94. if (t == 'Bytes') {
  95. feed = o.stdin.hex()
  96. o.stdin = null
  97. } else if (t == 'String') {
  98. feed = toBytes(o.stdin).hex()
  99. o.stdin = null
  100. }
  101. }
  102. let r = __native("proc.run", command, o, feed)
  103. // a failure an `on Error` handler absorbed leaves the call yielding null
  104. if (r == null) {
  105. return null
  106. }
  107. if (options != null && options.binary == true) {
  108. return { exit = r.exit data = toBytes(r.out) stderr = linesOf(r.err) }
  109. }
  110. return { exit = r.exit lines = linesOf(r.out) stderr = linesOf(r.err) }
  111. }
  112. // A stream's text as its lines: split at each newline, and a final newline ends
  113. // the last line rather than starting an empty one — spawn's `line` events say the same.
  114. linesOf(String text) {
  115. let nl = "
  116. "
  117. let out = []
  118. if (text == '') {
  119. return out
  120. }
  121. for (l of text.split(nl)) {
  122. out.push(l)
  123. }
  124. if (text.endsWith(nl)) {
  125. out.pop()
  126. }
  127. return out
  128. }
  129. \* The terminal's own input as instance events — `input = stdin()`, then
  130. `on input.line(text)` per typed line and `on input.eof()` at Ctrl-D. A joined
  131. terminal realm (SPEC "Joining a realm") reads its keyboard here. *\
  132. stdin() {
  133. return new Stdin().start()
  134. }
  135. \* One environment variable, null when unset. The runtime loads a `.env`
  136. beside the project's entry BEFORE anything runs (KEY=VALUE lines, #
  137. comments; the real environment always wins), so env('OPENROUTER_KEY')
  138. reads either source through one call. *\
  139. env(
  140. String name \\ the variable's name
  141. ) {
  142. return __native("proc.env", name)
  143. }
  144. \* Set one variable of this process's environment; null removes it. The
  145. programs it starts from then on inherit it; a runtime setting read while
  146. the program runs (HL_GC_PACING) takes it at once. *\
  147. setEnv(
  148. String name \\ the variable's name
  149. value \\ its new value, a String, or null
  150. ) {
  151. return __native("proc.set_env", name, value)
  152. }
  153. \* THE PROGRAM'S OWN ARGUMENTS (mission 317) — the strings that follow the
  154. entry on the command line, in order, as a list; an empty list when there
  155. were none.
  156. hybriel lex.hl a b // args() is ['a', 'b']
  157. ./lex a b // the compiled binary answers the same
  158. EVERYTHING AFTER THE ENTRY IS THE PROGRAM'S, unchanged: `hybriel
  159. [runtime flags] <file> [app args]` (creator ruling 2026-09-27). Flags
  160. included — `hybriel t.hl x --post --strict --` gives
  161. ['x', '--post', '--strict', '--']; hybriel's own flags (--strict,
  162. --offline) are written BEFORE the entry.
  163. A project DIRECTORY entry is the same: every argument after it is the
  164. program's. Joining a realm is a runtime flag, written before the entry:
  165. `hybriel --realm=<name> <projectDir>` (SPEC "Joining a realm").
  166. Built here rather than handed over whole because a `__native` call answers
  167. with ONE value and a list is what the caller wants: the count and the i-th
  168. argument are the two questions the runtime can answer, and the list is the
  169. language's own. *\
  170. args() {
  171. let out = []
  172. let n = __native("proc.argc")
  173. let i = 0
  174. while (i < n) {
  175. out.push(__native("proc.arg", i))
  176. i = i + 1
  177. }
  178. return out
  179. }
  180. \* WRITE TO THIS PROGRAM'S OWN STDOUT, RAW (ruling on ticket #42): a String's
  181. bytes or a Bytes, exactly as they are — no newline, no text form, unlike
  182. console.log. For a binary protocol on stdout. Answers how many bytes went. *\
  183. writeStdout(
  184. data \\ a String or a Bytes
  185. ) {
  186. if (hlTypeName(data) == 'Bytes') {
  187. return __native("proc.write_stdout_hex", data.hex())
  188. }
  189. return __native("proc.write_stdout", data)
  190. }
  191. \* WRITE TO THIS PROGRAM'S OWN STDERR, RAW: writeStdout's twin on the error
  192. stream — a String's bytes or a Bytes, exactly as they are, no newline.
  193. Answers how many bytes went. *\
  194. writeStderr(
  195. data \\ a String or a Bytes
  196. ) {
  197. if (hlTypeName(data) == 'Bytes') {
  198. return __native("proc.write_stderr_hex", data.hex())
  199. }
  200. return __native("proc.write_stderr", data)
  201. }
  202. \* END THIS PROGRAM NOW with an exit status (ruling on ticket #36): 0 is
  203. success, anything up to 255 tells the shell it failed. Nothing after the
  204. call runs. An uncaught error still exits 1 by itself. *\
  205. exit(
  206. Number code = 0 \\ the exit status, 0-255
  207. ) {
  208. __native("proc.exit", code)
  209. }
  210. \* BECOME ANOTHER PROGRAM (mission 326 rung 12): this process is replaced by
  211. `argv` — its stdin, stdout and stderr are the program's, its exit status
  212. is the run's, and nothing after the call runs. `options.cwd` is where it
  213. starts; `options.unlink = true` removes argv[0]'s file once it is open
  214. (a scratch binary leaves nothing behind), and with it `options.argv0` is
  215. the name the program then sees in place of that path. Answers only when
  216. the program cannot start: an Error saying why. *\
  217. exec(
  218. Hybrid argv \\ argv[0] is the program (a path, or a name on PATH), the rest its arguments
  219. Hybrid options = null \\ { cwd, unlink, argv0 }
  220. ) {
  221. return __native("proc.exec", argv, options)
  222. }
  223. \* THE PROGRAM'S OWN DIRECTORY, absolute (ticket #37): the directory of the
  224. entry script on the interpreter, the directory the executable sits in for
  225. a compiled binary (a binary knows no build directory). cwd() is where the
  226. user launched from; file() is the calling file's path. *\
  227. dir() {
  228. return __native("proc.dir")
  229. }
  230. \* The process's current working directory, absolute — where the USER
  231. launched from. Your own files resolve script-relatively everywhere
  232. (imports, hl:fs, spawn); cwd() is for tools whose subject is the caller's
  233. directory: a formatter, a scaffolder. *\
  234. cwd() {
  235. return __native("proc.cwd")
  236. }

Branches

Latest commits

  • 2f2725actests/browser.mjs: commit-row check (one row, centred date)MG
  • 4df1ea01tests/browser.mjs: MG phone checks (list first, no dead strip, one branch heading, tab grid, commit rows, PR title row, ticket columns, wrapping commands)MG
  • c52424e9gitoria mobile: repo list before the forms, 3x2 tab grid, no duplicate branch heading, ordered commit rows, aligned ticket rows, pull title on its own row, wrapping clone commands, no dead strip under formsMG
  • 3a95252dG3: cache parsed README blocks by sha256 of the text (bounded LRU), reportmre
  • 570138cddeploy: security gate (tests/security.mjs)mre
  • da6b20fcgitoria SG: security audit fixes (uploadMax 0, Secure cookie on https, session rotation at login, nosniff on function routes, no identity in page data) + tests/security.mjs gate + reportmre
  • f98c981fgitoria B1: report wordingmre
  • c6364cedgitoria B1: compact Markdown blocks (one kind flag per block/span, empty and false fields omitted); same rendered HTML, page values -67%mre
  • cd99d2feWIP gitoria#22: always render the repo level's slot (missing-repo boot hang), pages render nothing without a repo; hydration diagnosis in reports/G2-hydrate.mdmre
  • e5404b9breport: commit idsmre
  • 63cfa21ereports/G2-repotabs.mdmre
  • 9b0516fdgitoria#22: mark the tab underline functional (check-theme), chain E2E: serve/measure split, bring the lisbeth tab to frontmre
  • 19bc1df8gitoria#22: all repo pages under ONE layout level (components/repo.hl, hl:web D-CHAIN): a tab click replaces only the page in the slot; head and tab nav stay the same DOM nodesmre
  • 40658417tests/browser.mjs: wait for the page to be live (hydrated) before clicking Merge — a click on the server-rendered button before the client mounted was lost (flaky 'Clashing change' under load)mre
  • 48a6154bre-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • e972e8d7tests: short-id-switch (GITORIA_SWITCH_IDENT_PORT/_PORT) and ssh tunnel (GITORIA_GATE_TUNNEL_PORT) ports from env, defaults unchangedmre
  • f06f5349re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • c7d3cc87docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • f0e7ff8cdeploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • fe5f707cgitoria 010: report, mission, comment on why current = true staysmre