This commit is contained in:
Raven Scott
2026-04-03 21:39:36 -04:00
parent 2655fe6a7d
commit 57b1296981
355 changed files with 781062 additions and 7351 deletions
+25 -6
View File
@@ -19,7 +19,7 @@ bare-operating-system/
│ ├── 01-introduction.md … 10-manpages-and-online-help.md
├── developer-guide/ # How-to: in-image JS, ctx, coreutils, testing
│ ├── README.md # Index + reading order
│ ├── 01-two-runtimes-host-vs-image.md … 10-glossary-and-faq.md
│ ├── 01-two-runtimes-host-vs-image.md … 12-bare-modules-and-pear-ecosystem.md
├── LICENSE # Apache-2.0 notice (root repo)
├── .gitignore # Ignore rules
├── .prettierrc # Prettier formatting defaults
@@ -29,6 +29,7 @@ bare-operating-system/
├── kernel/ # Files staged into the system Hyperdrive
│ ├── init.js
│ ├── bin/ # Tier-1 utilities (built from bare-os-coreutils)
│ ├── lib/bare/ # Optional ctx.bare drive bundles + manifest (bare-os-bare-libs)
│ └── etc/
│ └── os-release
└── packages/
@@ -41,6 +42,9 @@ bare-operating-system/
│ ├── messages.js
│ ├── channel.js
│ └── kernel-feature-bits.js
├── bare-os-bare-libs/ # esbuild → kernel/lib/bare/bundles + manifest.json (seeder mirror)
│ ├── package.json
│ └── build.mjs
├── bare-os-coreutils/ # Sources + build → kernel/bin/* and seeder copy
│ ├── package.json
│ ├── build.mjs
@@ -65,6 +69,8 @@ bare-operating-system/
├── bare-os-abort.js
├── bare-os-http-policy.js
├── bare-os-ctx-api.js
├── bare-os-ctx-bare.js # ctx.bare host import + drive bundle merge
├── bare-module-manifest.json
├── bare-os-ctx.d.ts
├── git-cli.js # isomorphic-git; booter delegates `git`
├── curl-cli.js # Fetch HTTP client; booter delegates `curl`
@@ -88,7 +94,9 @@ bare-operating-system/
| `private` | `true` — not published as a single npm package |
| `type` | `module` — ESM |
| `workspaces` | `["packages/*"]` — npm workspaces (protocol, coreutils, seeder, booter, …) |
| `scripts.pretest` | Runs `npm run build -w bare-os-coreutils` before tests |
| `scripts.pretest` | Runs `bare-os-coreutils` + `bare-os-bare-libs` builds, kernel/seeder parity, [`smoke:bare-manifest`](scripts/smoke-bare-manifest-imports.mjs) |
| `scripts.gen:bare-catalog` | Refresh [`docs/bare-holepunch-catalog.json`](docs/bare-holepunch-catalog.json) from GitHub + npm (see [Chapter 12](developer-guide/12-bare-modules-and-pear-ecosystem.md)) |
| `scripts.sync:bare-manifest` | Apply catalog → [`bare-module-manifest.json`](packages/bare-os-booter/lib/bare-module-manifest.json) + booter `optionalDependencies` |
| `scripts.test` | Runs `npm run test --workspaces --if-present` |
| `scripts.format` | `prettier --write .` |
| `scripts.lint` | `prettier --check .` |
@@ -441,7 +449,7 @@ Pear-safe path resolution (same idea as Holepunch [pear-rti](https://github.com/
- **`defaultShellAliases`** — includes `ll`, `la`, `l`, `..`, `...` as the baseline merged from **`~/.barerc`**.
- **`tokenize` / `expandWord` / `parsePipeline`** — POSIX-ish words, `'...'`, `"..."`, `\`, `|`, `||`, `&&`, `;`, `>`, `>>`, `<`; `$VAR` and `${VAR}`; pipelines split on `|`; **`;`** splits lists; **`&&`** / **`||`** short-circuit using **`ctx.exitCode`** (left-associative).
- **`execShellLine(ctx, line)`** — semicolon-separated lists, then per segment AND-OR chains of pipelines; leading `NAME=value` assignments (blocked for `ctx.shellReadonlyVars`), redirections, builtins `alias`, `unalias`, `cd`, `export`, `unset`, `readonly`, `umask`, `:`, `command`, `type`, `login`, `logout`, `exit`, else `runBinCommand`. `command -v`/`-V` and `type` use **`resolveBinInPath`**. `login`/`logout` call the same `ctx.applyRegister` / `ctx.applyUnlock` / `ctx.applyLogout` hooks as `/bin/login` and `/bin/logout`. Captures `console.log` for pipes and file redirection; `>` / `>>` target paths via `ctx.vfs.writeFile` (personal tree). Returns `'exit'` when the `exit` builtin runs. Lone **`&`** (job control) is rejected with a clear error. After each completed line (except empty input), **`syncBareOsExitStatusEnv`** writes **`ctx.exitCode`** to **`vfs.env.BARE_OS_EXIT_STATUS`**; **`expandWord`** maps **`$?`** / **`${?}`** to that value.
- **`execShellLine(ctx, line)`** — semicolon-separated lists, then per segment AND-OR chains of pipelines; leading `NAME=value` assignments (blocked for `ctx.shellReadonlyVars`), redirections, builtins `alias`, **`barerc`** (`barerc reload` re-parses `~/.barerc` and reapplies theme), `unalias`, `cd`, `export`, `unset`, `readonly`, `umask`, `:`, `command`, `type`, `login`, `logout`, `exit`, else `runBinCommand`. `command -v`/`-V` and `type` use **`resolveBinInPath`**. `login`/`logout` call the same `ctx.applyRegister` / `ctx.applyUnlock` / `ctx.applyLogout` hooks as `/bin/login` and `/bin/logout`. Captures `console.log` for pipes and file redirection; `>` / `>>` target paths via `ctx.vfs.writeFile` (personal tree). Returns `'exit'` when the `exit` builtin runs. Lone **`&`** (job control) is rejected with a clear error. After each completed line (except empty input), **`syncBareOsExitStatusEnv`** writes **`ctx.exitCode`** to **`vfs.env.BARE_OS_EXIT_STATUS`**; **`expandWord`** maps **`$?`** / **`${?}`** to that value.
### 12.8 [packages/bare-os-booter/lib/identity-account.js](packages/bare-os-booter/lib/identity-account.js)
@@ -458,7 +466,7 @@ Pear-safe path resolution (same idea as Holepunch [pear-rti](https://github.com/
- **[packages/bare-os-coreutils/lib/commands.mjs](packages/bare-os-coreutils/lib/commands.mjs)** — **`COREUTILS_COMMANDS`**: authoritative sorted `/bin` names for **`build.mjs`** and the manual database builder (keeps the image and **`man`** coverage in sync).
- **[packages/bare-os-coreutils/build.mjs](packages/bare-os-coreutils/build.mjs)** — `export async function build()`: runs **`scripts/build-man-db.mjs`** (validates **`man/pages/*.json`**, writes **`kernel/share/man/man.json`** and the same path under **`packages/bare-os-seeder/kernel/share/man/`**); then for each command concatenates `lib/runtime.js`, optional **`preamble`** libs (`sed``lib/sed-engine.js`, `awk``lib/awk-engine.js`, **`man`** → `lib/man-render.js`), then `src/<name>.js`; writes to `kernel/bin/<name>` and `packages/bare-os-seeder/kernel/bin/<name>`. CLI: `node build.mjs` when executed as main.
- **Manual pages** — Authoring: **`packages/bare-os-coreutils/man/pages/<name>.json`**; schema: **`man/schema.json`**. Optional **`examples`** (cheat.sh-style) and **`descriptionMode`**: **`preserve`** for preformatted text. **`scripts/ingest-handbook-for-man.mjs`** merges every **`handbook/*.md`** as **`man(7)`** at build time (**`man handbook`**, **`man handbook-01-introduction`**, …). Regenerate JSON stubs with **`node packages/bare-os-coreutils/scripts/seed-man-pages.mjs`**. Runtime: **`/bin/man`** reads **`/share/man/man.json`**. **Handbook:** [handbook/10-manpages-and-online-help.md](handbook/10-manpages-and-online-help.md).
- **Commands** (sources under `src/`, same order as **`COREUTILS_COMMANDS`** in [`commands.mjs`](packages/bare-os-coreutils/lib/commands.mjs)): `awk`, `basename`, `cat`, `chgrp`, `chmod`, `chown`, `cksum`, `clear`, `cp`, `crontab`, `cut`, `date`, `dirname`, `du`, `echo`, `env`, `exit`, `false`, `find`, `getconf`, `git-pear`, `grep`, `head`, `hdms`, `help`, `hostname`, `id`, `jq`, `ln`, `login`, `logout`, `logname`, `ls`, `man`, `mkdir`, `mkfifo`, `mktemp`, `mv`, `nl`, `od`, `pathchk`, `printenv`, `printf`, `pwd`, `readlink`, `rm`, `rmdir`, `savevault`, `sed`, `seq`, `sleep`, `sort`, `stat`, `tail`, `tee`, `test`, `time`, `touch`, `tr`, `true`, `tty`, `uname`, `wc`, `which`, `whoami`, `xargs`. Each built script begins with **`BARE_OS_BIN_API`** in the concatenated prelude; root **`pretest`** runs **[`scripts/verify-kernel-seeder-parity.mjs`](scripts/verify-kernel-seeder-parity.mjs)** to keep **`kernel/bin/*`** and **`packages/bare-os-seeder/kernel/bin/*`** in sync and to require that pragma on every staged binary. Scripts are plain `async function run(ctx, argv)` using `ctx.vfs`, `ctx.drive`, `ctx.b4a`, `ctx.console`, optional `bareStdin(ctx)`, optional `ctx.runBinCommand` — no ESM `import` in `src/` (Bare-safe `AsyncFunction` load). **Booter-delegated** (stubs under `kernel/bin/`, logic in `packages/bare-os-booter/lib/`): `systemctl`, `journalctl` (bare-initd control; `bare-initctl` alias; see [handbook/04-the-booter-runtime.md](handbook/04-the-booter-runtime.md)). **Narrative reference:** [handbook/09-posix-utilities-shell-and-vfs.md](handbook/09-posix-utilities-shell-and-vfs.md).
- **Commands** (sources under `src/`, same order as **`COREUTILS_COMMANDS`** in [`commands.mjs`](packages/bare-os-coreutils/lib/commands.mjs)): `awk`, `basename`, `cat`, `chgrp`, `chmod`, `chown`, `cksum`, `clear`, `cp`, `crontab`, `cut`, `date`, `dirname`, `dircolors`, `du`, `echo`, `env`, `exit`, `false`, `find`, `getconf`, `git-pear`, `grep`, `head`, `hdms`, `help`, `hostname`, `id`, `jq`, `ln`, `login`, `logout`, `logname`, `ls`, `man`, `mkdir`, `mkfifo`, `mktemp`, `mv`, `nl`, `od`, `pathchk`, `printenv`, `printf`, `pwd`, `readlink`, `rm`, `rmdir`, `savevault`, `sed`, `seq`, `sleep`, `sort`, `stat`, `tail`, `tee`, `test`, `theme`, `time`, `touch`, `tr`, `true`, `tty`, `uname`, `wc`, `which`, `whoami`, `xargs`. Each built script begins with **`BARE_OS_BIN_API`** in the concatenated prelude; root **`pretest`** runs **[`scripts/verify-kernel-seeder-parity.mjs`](scripts/verify-kernel-seeder-parity.mjs)** to keep **`kernel/bin/*`** and **`packages/bare-os-seeder/kernel/bin/*`** in sync and to require that pragma on every staged binary. Scripts are plain `async function run(ctx, argv)` using `ctx.vfs`, `ctx.drive`, `ctx.b4a`, `ctx.console`, optional `bareStdin(ctx)`, optional `ctx.runBinCommand` — no ESM `import` in `src/` (Bare-safe `AsyncFunction` load). **Booter-delegated** (stubs under `kernel/bin/`, logic in `packages/bare-os-booter/lib/`): `systemctl`, `journalctl` (bare-initd control; `bare-initctl` alias; see [handbook/04-the-booter-runtime.md](handbook/04-the-booter-runtime.md)). **Narrative reference:** [handbook/09-posix-utilities-shell-and-vfs.md](handbook/09-posix-utilities-shell-and-vfs.md).
### 12.11 [packages/bare-os-booter/test.js](packages/bare-os-booter/test.js) and [test.identity.js](packages/bare-os-booter/test.identity.js)
@@ -514,10 +522,21 @@ sequenceDiagram
| `MANWIDTH` | `/bin/man` | Wrap width for manual text (default `72`; minimum `40`) |
| `NO_COLOR` | `/bin/man` | If set, disable ANSI bold for section headings on a TTY |
**Host → session passthrough** (booter copies into `shellEnv` when the host sets a non-empty value): `BARE_OS_PIPELINE_MAX_STAGES`, `BARE_OS_PIPELINE_MAX_BYTES`, `BARE_OS_PIPELINE_MAX_LINES`, `BARE_OS_BOOT_PROFILE`, `BARE_OS_ONBOOT`, `BARE_OS_BOOT_STRICT`, `BARE_OS_RC_D_SKIP`, `BARE_OS_BOOT_MINIMAL`, `BARE_OS_BOOT_SKIP`, `BARE_OS_BOOT_TRACE`, `BARE_OS_KERNEL_SELFTEST`, `BARE_OS_SELFTEST_FORMAT`, `BARE_OS_AUDIT`, `BARE_OS_AUDIT_JSON`, `BARE_OS_AUDIT_REDACT`, `BARE_OS_IMAGE_DIGEST`, `BARE_OS_EXEC_MAX_DEPTH`, `BARE_OS_IPC_MAX_BYTES`, `BARE_OS_VFS_WATCH`, `BARE_OS_BOOT_ALLOWLIST`, `BARE_OS_PEAR_CHANNEL`, `BARE_OS_PEAR_RELEASE`, `PEAR_CHANNEL`.
**Host → session passthrough** (booter copies into `shellEnv` when the host sets a non-empty value): `BARE_OS_PIPELINE_MAX_STAGES`, `BARE_OS_PIPELINE_MAX_BYTES`, `BARE_OS_PIPELINE_MAX_LINES`, `BARE_OS_BOOT_PROFILE`, `BARE_OS_ONBOOT`, `BARE_OS_BOOT_STRICT`, `BARE_OS_RC_D_SKIP`, `BARE_OS_BOOT_MINIMAL`, `BARE_OS_BOOT_SKIP`, `BARE_OS_BOOT_TRACE`, `BARE_OS_KERNEL_SELFTEST`, `BARE_OS_SELFTEST_FORMAT`, `BARE_OS_AUDIT`, `BARE_OS_AUDIT_JSON`, `BARE_OS_AUDIT_REDACT`, `BARE_OS_IMAGE_DIGEST`, `BARE_OS_EXEC_MAX_DEPTH`, `BARE_OS_IPC_MAX_BYTES`, `BARE_OS_VFS_WATCH`, `BARE_OS_BOOT_ALLOWLIST`, `BARE_OS_PEAR_CHANNEL`, `BARE_OS_PEAR_RELEASE`, `PEAR_CHANNEL`, **`TERM`**, **`COLORTERM`** (terminal capability hints for colorized tools).
**Session env (set by booter, not user configuration):** `USER`, `LOGNAME`, `HOME`, `PWD`, `UID`, `GID`, `GROUP`, `BARE_OS_IDENTITY` (`guest` or `unlocked`), `BARE_OS_CTX_API_VERSION`, `BARE_OS_SESSION_ID`, `BARE_OS_BOOT_PROFILE_RESOLVED`, and when unlocked `BARE_OS_PUBLIC_KEY` (hex Ed25519 public key).
**Theme and color (from `~/.barerc`, `/bin/theme`, and `applyBareOsThemeFromEnv`):**
| Variable | Meaning |
| -------- | ------- |
| `BARE_OS_THEME` | Preset name (`default`, `nord`, `dracula`, …). Set by `theme <name>` in `~/.barerc` or `/bin/theme set`. |
| `BARE_OS_COLOR_DEPTH` | `truecolor` (default), `256` / `8bit`, or `16` / `8` / `ansi`. Downgrades truecolor **`BARE_OS_COLOR_*`** REPL sequences only; `LS_COLORS` strings stay as in the preset or `dircolors` output. |
| `BARE_OS_COLOR_PROMPT`, `COMMAND`, `PATH`, `ENVSET`, `ENVUNSET`, `GHOST`, `SEARCH` | ANSI open sequences for fish readline (set by the active theme). |
| `LS_COLORS` | GNU-style `ls` coloring; filled from the preset unless already set or **`BARE_OS_LS_COLORS_LOCKED=1`**. |
| `BARE_OS_DIRCOLORS` | Path to a dircolors-format file; when set, theme apply parses it (for the current `TERM`) into `LS_COLORS`. |
| `NO_COLOR` | When set, disables color in `ls` and other tools that honor it. |
---
## 14a. POSIX userland appendix (implemented vs gaps)
@@ -527,7 +546,7 @@ sequenceDiagram
| **VFS** | Two-drive unified paths; **`$HOME`** maps to the personal Hyperdrive; writable mounts under **`/mnt`** when HDMS allows. **`mkdir`/`rmdir`**, **`chmod`** (octal + symbolic subset), **`symlink`/`readlink`**, **`stat`/`lstat`**, **`rm`** recursive, **`watch()`** on Hyperdrive paths (optional host **`BARE_OS_VFS_WATCH=0`** to disable). Synthetic **`/proc`**, **`/sys`**, **`/run`**, **`/dev`** for introspection (quotas JSON, boot JSON, initd snapshot, etc.). Empty dirs use **`.bareos_empty`** (same idea as `git-fs-adapter`). |
| **Shell** | Pipelines (pipe between commands), list separator **`;`**, short-circuit logical-**AND** / logical-**OR** between commands, redirects **`>`** / **`>>`** / **`<`**, quoting, **`$VAR`** / **`${VAR}`**, **`$?`** / **`${?}`** (from **`BARE_OS_EXIT_STATUS`**), builtins: **`alias`**, **`unalias`**, **`cd`**, **`export`**, **`unset`**, **`readonly`**, **`umask`**, **`:`**, **`command`**, **`type`**, **`login`**, **`logout`**, **`exit`**. Branching uses **`ctx.exitCode`**. Bounded pipeline capture; optional boot-snippet allowlist (**`BARE_OS_BOOT_ALLOWLIST`** + **`/etc/bare-os/boot.allow`**). No full POSIX **`sh`** grammar. |
| **Ownership** | Display and permission checks use **`UID`/`GID`** and mode bits; **`chown`/`chgrp`** update **`metadata.bareOs`** on the **personal** writable tree (not a multi-user host kernel). |
| **Utilities** | Tier-1 JS **`/bin`** (see §12.10): includes **`man`**, **`sed`**, **`awk`**, **`cp`**, **`mv`**, **`find`** (**`-maxdepth`**, **`-mindepth`**, **`-depth`**, **`-name`**, **`-type`**), **`mktemp`**, **`git-pear`**, **`cksum`**, **`getconf`** (fixed variable table + **`-a`**), **`xargs`** (bounded; **`ctx.runBinCommand`**; **`-0`**, **`-n`**), etc. Large **`sed`/`awk`** are not byte-identical to GNU on all inputs. **`mkfifo`** creates in-memory FIFOs under **`/run/bare-os/ipc/`**. Online help: **`/share/man/man.json`** and **`man`**. |
| **Utilities** | Tier-1 JS **`/bin`** (see §12.10): includes **`man`**, **`sed`**, **`awk`**, **`cp`**, **`mv`**, **`find`** (**`-maxdepth`**, **`-mindepth`**, **`-depth`**, **`-name`**, **`-type`**), **`mktemp`**, **`git-pear`**, **`cksum`**, **`getconf`** (fixed variable table + **`-a`**), **`xargs`** (bounded; **`ctx.runBinCommand`**; **`-0`**, **`-n`**), **`dircolors`**, **`theme`**, **`ls`** with GNU-style **`LS_COLORS`** (including **`mh`** when **`stat.nlink` > 1** and **`ca`** when **`stat.capabilities`** is set). Large **`sed`/`awk`** are not byte-identical to GNU on all inputs. **`mkfifo`** creates in-memory FIFOs under **`/run/bare-os/ipc/`**. Online help: **`/share/man/man.json`** and **`man`**. |
**Handbook:** [handbook/09-posix-utilities-shell-and-vfs.md](handbook/09-posix-utilities-shell-and-vfs.md) — narrative catalog, engine notes, and Issue 7 alignment. **Manual pages:** [handbook/10-manpages-and-online-help.md](handbook/10-manpages-and-online-help.md).