gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit03d2989303d29893boot scans read primary-key slices (lib/slices.hl from mission 044): iterate is eager too; people view log line back; allShows/allEpisodes stay for toolsmre03d29893/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

  • 03d29893boot scans read primary-key slices (lib/slices.hl from mission 044): iterate is eager too; people view log line back; allShows/allEpisodes stay for toolsmre
  • 0d6293ebmission 043: mission filemre
  • 55bbd619boot: one streamed pass per table (lib/bootscan.hl) instead of find(null,null) per module; follows/watches/franchises scans streammre
  • 1d465d3ere-vendor plugins to Hybriel master f9614007 (mpackdb #202 copy fix, libmpackdb sha 6fb3b9d6)mre
  • 6648ba44mission 042: real-browser E2E on ce6f2e0a re-vendor 69/0 at 390 + 1280mre
  • 3ed3a0efmission 042: gates old/new equal (browser #41 route-table regex accepts unescaped hl:web output), real-data TTFB, E2E blocked by lisbeth lockmre
  • d5b61e90LOG 042mre
  • 4acdbaccmission 042: memory comparison old vs ce6f2e0a (stopped: warm VmHWM higher), reportmre
  • d0f620d6mission 042: re-vendor Hybriel ce6f2e0a (plugins incl. mpackdb; bin runtime built from the same archive, git-ignored), compact=false keptmre
  • 5bd14e12mission 040: theme 76f99f6 gates + E2E green; 44 px fixes (skeleton row, type-word, genre-link/pill); README, reportmre
  • 77cfa45cmission 040: partial report (theme/modal/pagination re-copied, tilelist onPage, 44 px taps; gates new + E2E pending)mre
  • 4b14822fe2e-theme: menu marker by colourmre
  • 09780f4emission 040 WIP: theme, modal, pagination, tokens re-copied from layouts 76f99f6; tilelist uses onPage; tap sizes 44 px for tracker's own small buttons; tests/e2e-theme.mjsmre
  • fb80bb8chotfix: open the 5 show stores without compaction (compact = false) — compact-on-open left another handle on stale offsets, every read gave a bare Number (hybriel mpackdb refresh after a shrink); live down 2026-10-20 05:11mre
  • e00d3bf7paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • a8c7f234tracker#36 (mission 039): tools/tmdb-check.hl survives a dropped connection (on Error, asked again, failed lines) and resumes with --from N; tests/tmdbcheck.mjs 6/6 against a fake TMDBmre
  • 9c230516mission brief w39mre
  • 3609121dmission 038 docs + report (quota stop): README/kinds.md for #43 #42 #36, STATUS, LOG; HEAD browser gate 374/8 in the in-app daily run block (hour-boundary suspected, rerun pending), other gates green; #36 real run needs TMDB_READ_TOKENmre
  • a5d06e79tracker#36 (mission 038): tools/tmdb-check.hl + lib/tmdbcheck.hl — every live migrated title's migrated title + year against its TMDB entry (one GET /movie|tv/<id>?append_to_response=alternative_titles, 260 ms apart, passing failures asked once more): ok / ambiguous (one of title, year disagrees) / clear (both, or 404); read-only; token only from TMDB_READ_TOKEN; --stored = a title-only preview from the TMDB names already stored (no request). Tested against a fake TMDB (.scratch/w38/t36): 7 titles, 3 ok, 2 ambiguous, 2 clear, data unchangedmre
  • 982554f3tracker#42 (mission 038): series pages — an unknown slug no longer scans every title (lib/shows.hl showBySlug: the slug map only; new titles are noted by refreshTitleCaches, which both title puts already reach): 10.7–15.7 s → 0.013 s on the real copy (the one-request-at-a-time server was blocked meanwhile); cast/crew rows take name + slug from a person-link cache (personLinkOf) instead of whole person records (SNL: 303 cast with 4,761 credits, ~49k allocations per render) — allocations per series page −5…−40 %; HTML of 20 pages identical to beforemre