Further Updates to MD

This commit is contained in:
Raven Scott
2026-04-25 23:15:49 -04:00
parent acd4867bad
commit 0e3e5be329
115 changed files with 824 additions and 702 deletions
@@ -14,18 +14,18 @@ Use this skill when you (or the user) need to **author or debug** Bare OS **Java
## Core model
1. **Entrypoints** — Kernel: **`async function start(ctx)`** in `/boot/init.js` (or your image). Commands: **`async function run(ctx, argv)**` where `**argv[0]`** is the invoked name (e.g. `agent`). You **must** set **`ctx.exitCode`** (number) before returning on failure paths.
2. **`ctx` is not Node** — There is no full **`process`**, no `**require('node:fs')**`. The booter assembles **`ctx`** as the narrow **syscall surface**: **`vfs`**, **`env`**, **`execLine`**, **`runBinCommand`**, optional **`httpFetch`**, **`bare`**, identity helpers, diagnostics, etc. See the mermaid overview in Chapter 2 of the developer guide.
1. **Entrypoints** — Kernel: **`async function start(ctx)`** in `/boot/init.js` (or your image). Commands: **`async function run(ctx, argv)`** where **`argv[0]`** is the invoked name (e.g. `agent`). You **must** set **`ctx.exitCode`** (number) before returning on failure paths.
2. **`ctx` is not Node** — There is no full **`process`**, no **`require('node:fs')`**. The booter assembles **`ctx`** as the narrow **syscall surface**: **`vfs`**, **`env`**, **`execLine`**, **`runBinCommand`**, optional **`httpFetch`**, **`bare`**, identity helpers, diagnostics, etc. See the mermaid overview in Chapter 2 of the developer guide.
3. **`/bin/agent` is special** — The agent bundle uses **`run_js_script`** for guest JS and a frozen tool surface; do not assume **`node`** exists. For **general** in-guest scripting, prefer **`ctx.vfs`** + **`ctx.execLine`** / **`ctx.runBinCommand`** and optional **`ctx.bare.*`** modules when enabled.
## Writing scripts (`run(ctx, argv)`)
- **Argv** — `argv` is a string array; **`argv[0]`** is how you were invoked (symlink name matters for multi-call binaries).
- **Stdout** — Prefer **`ctx.console.log`** / **`ctx.console.error`** (session-aware). For binary or captured stdout, **`ctx.bareOsBinWrite`** may exist when the shell captures pipeline output.
- **Shell a subprocess** — **`await ctx.execLine('some shell line', { signal, timeoutMs })**` returns a string (see booter **`raceWithAbortAndTimeout`**). Heavy work: `**await ctx.runBinCommand(['/bin/grep', …], opts)`** for same resolution as the interactive shell.
- **Filesystem** — **`await ctx.vfs.readFile(path)**`**`Uint8Array`**; `**await ctx.vfs.writeFile(path, buf, opts?)**`. Decode with `**ctx.b4a.toString(buf)**` or **`TextDecoder`**. Always use **absolute** paths under **`/home`**, **`/tmp`**, **`/mnt`**, **`/bin`**, etc., per policy.
- **Shell a subprocess** — **`await ctx.execLine('some shell line', { signal, timeoutMs })`** returns a string (see booter **`raceWithAbortAndTimeout`**). Heavy work: **`await ctx.runBinCommand(['/bin/grep', …], opts)`** for same resolution as the interactive shell.
- **Filesystem** — **`await ctx.vfs.readFile(path)`****`Uint8Array`**; **`await ctx.vfs.writeFile(path, buf, opts?)`**. Decode with **`ctx.b4a.toString(buf)`** or **`TextDecoder`**. Always use **absolute** paths under **`/home`**, **`/tmp`**, **`/mnt`**, **`/bin`**, etc., per policy.
- **Environment** — **`ctx.env`** is mutable shell state (also **`ctx.vfs.env`**). After **`execLine`**, **`ctx.env.BARE_OS_EXIT_STATUS`** reflects last exit code when the booter sets it.
- **Exit** — Set **`ctx.exitCode = 1**` (or other code) on error; **`0`** on success. `**ctx.requestBooterExit(code)**` ends the whole session from builtins like **`exit`**.
- **Exit** — Set **`ctx.exitCode = 1`** (or other code) on error; **`0`** on success. **`ctx.requestBooterExit(code)`** ends the whole session from builtins like **`exit`**.
## Building “apps” (long-lived behaviour)
@@ -34,13 +34,13 @@ Think in layers the stock OS already uses:
| Layer | Mechanism | Notes |
| --- | --- | --- |
| **Init** | **`bareOsRegisterBootStepHook`**, initd units | Boot-order DAG (stock: **`bare-os-www`** before **`bare-holesail`** so **`bare-www-*`** reaches loopback HTTP; **`bare-openssh`** + login stack ensure **`bare-ssh-*`** in **`~/.holesail/state.json`**); pair **`registerKernelShutdownHook`** / initd disposers for teardown. |
| **Virtual files** | **`bareOsRegisterVirtualFile(name, reader, opts?)**` | Serves **`/run/bare-os/virtual/<name>`**; gated by runtime caps. |
| **Virtual files** | **`bareOsRegisterVirtualFile(name, reader, opts?)`** | Serves **`/run/bare-os/virtual/<name>`**; gated by runtime caps. |
| **IPC** | **`ctx.bareOsIpc`** when present | `**push`/`take**`, JSON helpers, fanout, duplex bridge — bounded; audit when **`BARE_OS_IPC_AUDIT=1`**. |
| **Kernel extensions** | **`bareOsRegisterKernelExtensionRecord`**, **`bareOsRunImageScript`** under **`/lib/bare-os/extensions/`** | Trusted image paths only. |
| **Sandboxed user JS** | **`bareOsSandboxRunScript(source, argv?, opts?)**` | Restricted **`ctx`**; disable with **`BARE_OS_SANDBOX_SCRIPT=0`**. |
| **Pear / host** | **`bareOsPearIpcEmit`**, **`bareOsPearIpcRequest`**, mirror/export hints | Host must cooperate; return `**{ ok, hint }`** patterns. |
| **Sandboxed user JS** | **`bareOsSandboxRunScript(source, argv?, opts?)`** | Restricted **`ctx`**; disable with **`BARE_OS_SANDBOX_SCRIPT=0`**. |
| **Pear / host** | **`bareOsPearIpcEmit`**, **`bareOsPearIpcRequest`**, mirror/export hints | Host must cooperate; return **`{ ok, hint }`** patterns. |
Before touching sensitive **`ctx`** methods in hardened images, call `**ctx.bareOsIsCtxMethodAllowed?.(name)**` when boot policy **`BARE_OS_BOOT_POLICY_ALLOWED_CTX_METHODS`** is set.
Before touching sensitive **`ctx`** methods in hardened images, call **`ctx.bareOsIsCtxMethodAllowed?.(name)`** when boot policy **`BARE_OS_BOOT_POLICY_ALLOWED_CTX_METHODS`** is set.
## `ctx` field map (cheat sheet)
@@ -61,7 +61,7 @@ Before touching sensitive **`ctx`** methods in hardened images, call `**ctx.bare
### Bare OS introspection & policy
- **`ctx.bareOsCtxApiVersion`**, **`ctx.bareOsRuntimeCaps`** (frozen)
- **`ctx.bareOsAdvertisedKernelCapabilityWords`**, **`ctx.bareOsSeedKernelCapabilityWords`** — `**>>> 0`** when testing bits.
- **`ctx.bareOsAdvertisedKernelCapabilityWords`**, **`ctx.bareOsSeedKernelCapabilityWords`** — **`>>> 0`** when testing bits.
- **`ctx.bareOsGetResourceStatus`**, **`ctx.bareOsReadProcMetricsLive`**, **`ctx.bareOsReadBareTopSnapshot`**
- **`ctx.bareOsRegisterVirtualFile`**, **`ctx.bareOsInvalidateVirtualFile`**, **`ctx.bareOsUpdateVirtualFileMeta`**
- **`ctx.bareOsEmitIpcAudit`**, **`ctx.bareOsEvaluatePeerAdmission`**, **`ctx.bareOsEmitMirrorDriveHint`**