antcolony
All repositories: gitoria
3.8 KB
\* hl:proc — child processes as INSTANCE EVENTS.let server = spawn('llama-server -m ' + model + ' --port 8480')on server.line({ line, stream }) { … } \\ stream: 'stdout' | 'stderr'on server.exit({ exit, pid }) { … } \\ always arrives, kill or notserver.kill() \\ SIGTERM; exit still fires`stream` names the PIPE, not a verdict — most servers (llama.cpp included)write their whole LOG to stderr, keeping stdout for data.A command that CANNOT START has no exit — it is an ERROR: caught by`on server.Error(e)` (this instance) or the global `on Error(e)`; uncaughtit is a located crash naming the binary and the errno. A finished childretires its event source, so a program whose children are done simply ends.THE PROGRAM PATH follows the Hybriel path rule: `spawn('bin/llama-server …')`resolves bin/ against THIS SCRIPT's directory (like imports and hl:fs) — acopied build folder next to your .hl file just works. A bare name searchesPATH; absolute stays absolute.There is NO SHELL — no quoting, no expansion (the safety property, not agap). `spawnArgs([ 'sh', '-c', pipeline ])` is how you ASK for one,explicitly. *\/* Gate file (docs campaign): __native lives only here; the Process class(process.hl) carries the instance events and their declarations. */\* Start a child from ONE command string: split on WHITESPACE RUNS (spaces,tabs AND newlines — a command written across lines is one command); aquoted argument is GROUPED and its quotes stripped ('{"a": 1}' arrives asone argv entry). A command that cannot start is an Error — caught by`on server.Error(e)` or the global `on Error(e)`. *\spawn(String cmd \\ the program and its arguments, whitespace-separated) {return new Process().start(cmd)}\* The LIST form — argv exactly as given: for arguments that contain spaces,or to ask for a shell explicitly: spawnArgs([ 'sh', '-c', pipeline ]). *\spawnArgs(Hybrid args \\ argv entries, one string each — args[0] is the program) {return new Process().startArgs(args)}\* The terminal's own input as instance events — `input = stdin()`, then`on input.line(text)` per typed line and `on input.eof()` at Ctrl-D. A joinedterminal realm (SPEC "Joining a realm") reads its keyboard here. *\stdin() {return new Stdin().start()}\* One environment variable, null when unset. The runtime loads a `.env`beside the project's entry BEFORE anything runs (KEY=VALUE lines, #comments; the real environment always wins), so env('OPENROUTER_KEY')reads either source through one call. *\env(String name \\ the variable's name) {return __native("proc.env", name)}\* THE PROGRAM'S OWN ARGUMENTS (mission 317) — the strings that follow theentry on the command line, in order, as a list; an empty list when therewere none.hybriel lex.hl a b // args() is ['a', 'b']./lex a b // the compiled binary answers the sameA project DIRECTORY entry is unchanged: `hybriel <projectDir> <realm>` stillJOINS that realm, so the positional there is the realm's name and never anargument (SPEC "Joining a realm").Built here rather than handed over whole because a `__native` call answerswith ONE value and a list is what the caller wants: the count and the i-thargument are the two questions the runtime can answer, and the list is thelanguage's own. *\args() {let out = []let n = __native("proc.argc")let i = 0while (i < n) {out.push(__native("proc.arg", i))i = i + 1}return out}\* The process's current working directory, absolute — where the USERlaunched from. Your own files resolve script-relatively everywhere(imports, hl:fs, spawn); cwd() is for tools whose subject is the caller'sdirectory: a formatter, a scaffolder. *\cwd() {return __native("proc.cwd")}
Branches
- mainmain branch