Skip to content

Commit 6342757

Browse files
feat: integrate Sandwich runtime and Hermes profile
1 parent f14bcc2 commit 6342757

25 files changed

Lines changed: 5860 additions & 8 deletions

‎.gitattributes‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ docker/entrypoint.sh text eol=lf
2525
*.ico binary
2626
*.woff binary
2727
*.woff2 binary
28+
29+
# Embedded patch payloads preserve the reviewed source diff verbatim.
30+
*.patch -whitespace

‎components/sandwich/README.md‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Sandwich
2+
3+
A fail-loud Bun compatibility layer for systems that intentionally do not
4+
install Node.js, npm, pnpm, or Yarn.
5+
6+
Sandwich makes Bun the canonical JavaScript runtime and package manager while
7+
translating only the compatibility behavior it can represent honestly.
8+
Ambiguous state-changing commands fail with an explanation instead of
9+
pretending that Bun and another package manager have identical semantics.
10+
11+
## Guarantees
12+
13+
- `node` executes JavaScript with Bun and reports Bun's Node-compatible
14+
`process.version`.
15+
- `npx` executes packages through `bun x --bun`.
16+
- common npm, pnpm, and Yarn operations translate to tested Bun commands.
17+
- `npm ci` requires `bun.lock` and uses `bun install --frozen-lockfile`.
18+
- unsupported dependency semantics fail loudly.
19+
- Bun telemetry and crash uploads are disabled.
20+
- installation is user-scoped, previewable, idempotent, and does not restart
21+
services.
22+
23+
Sandwich does not install Bun and does not remove an existing Node runtime.
24+
Install or update Bun through Bun's supported installer first, then let
25+
Sandwich control command resolution at the user level.
26+
27+
## Layout
28+
29+
- `bin/`: the canonical `sandwich` command and compatibility façades
30+
- `manifest.json`: versioned operations consumed by Ulysses
31+
- `lib/`: shared Bun discovery and translation helpers
32+
- `config/`: managed Bun and shell configuration
33+
- `scripts/install-user.sh`: previewable user-level installer
34+
- `scripts/apply-hermes-maintenance.sh`: guarded Hermes integration profile
35+
- `scripts/refresh-hermes-artifacts.sh`: maintainer-only Hermes profile refresh
36+
- `patches/` and `config/hermes.*`: version-pinned Hermes updater artifacts
37+
- `tests/compat.sh`: offline compatibility contract
38+
39+
`bun-sovereign` remains as a backward-compatible alias for installations made
40+
before the project was renamed.
41+
42+
## Install
43+
44+
Preview all destinations without changing the system:
45+
46+
```bash
47+
./scripts/install-user.sh --check
48+
```
49+
50+
Apply the user-level configuration:
51+
52+
```bash
53+
./scripts/install-user.sh --apply
54+
source ~/.bashrc
55+
sandwich doctor
56+
```
57+
58+
The installer creates timestamped backups under
59+
`~/.local/state/sandwich/backups`, installs user-owned links in
60+
`~/.local/bin`, and replaces only the marked Sandwich or legacy Bun Sovereign
61+
block in `~/.bashrc`. It preserves all unrelated PATH entries and shell
62+
configuration.
63+
64+
## Environment
65+
66+
Sandwich recognizes:
67+
68+
- `SANDWICH_BUN`: explicit Bun executable
69+
- `SANDWICH_NPM_VERSION`: npm compatibility version reported to tooling
70+
- `SANDWICH_PNPM_VERSION`: pnpm compatibility version
71+
- `SANDWICH_YARN_VERSION`: Yarn compatibility version
72+
- `BUN_INSTALL`: Bun installation root, normally `~/.bun`
73+
74+
The former `BUN_SOVEREIGN_*` names remain accepted as compatibility fallbacks.
75+
76+
## Hermes integration profile
77+
78+
Sandwich includes the tested Hermes updater repair that originally shipped
79+
with Bun Sovereign. The profile keeps the Hermes root, state directory,
80+
protected production roots, and upstream reference configurable:
81+
82+
- `HERMES_LIVE_DIR`, default `~/.hermes/hermes-agent`
83+
- `HERMES_UPSTREAM_REF`, default `origin/main`
84+
- `SANDWICH_STATE_ROOT`, default `~/.local/state/sandwich`
85+
- `SANDWICH_PROTECTED_ROOTS`, a colon-separated list defaulting to
86+
`~/Hermes:~/Odysseus`
87+
88+
Previewing the profile is read-only and refuses while the Hermes worktree or a
89+
protected Compose project is active:
90+
91+
```bash
92+
./scripts/apply-hermes-maintenance.sh --check
93+
```
94+
95+
`--apply` is intentionally maintenance-window-only. It requires an exact
96+
Hermes commit match, rejects unrelated tracked changes, backs up the files it
97+
will replace, applies the pinned patch and Bun artifacts, performs frozen
98+
workspace installs, and rebuilds the TUI and Web workspaces. It never restarts
99+
Hermes or another service. `--allow-active` is an explicit human override, not
100+
an automatic Ulysses action.
101+
102+
After a reviewed upstream Hermes update, maintainers can refresh the profile
103+
against an explicitly selected upstream reference:
104+
105+
```bash
106+
HERMES_UPSTREAM_REF=origin/main \
107+
./scripts/refresh-hermes-artifacts.sh
108+
```
109+
110+
## Contract
111+
112+
Run the offline compatibility suite at any time:
113+
114+
```bash
115+
./tests/compat.sh
116+
```
117+
118+
Use `bun` and `bun x` directly when Bun-native behavior is desired. Add a
119+
tested translation before relying on a package-manager command that Sandwich
120+
currently rejects.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
# Backward-compatible entrypoint retained for existing installations.
4+
exec "$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")/sandwich" "$@"

‎components/sandwich/bin/node‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
source "$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")/../lib/common.sh"
4+
5+
case "${1:-}" in
6+
--version|-v)
7+
exec "$SANDWICH_BIN" -e 'process.stdout.write(process.version + "\n")'
8+
;;
9+
--help|-h)
10+
exec "$SANDWICH_BIN" --help
11+
;;
12+
esac
13+
14+
declare -a translated_args=()
15+
input_type=""
16+
17+
while (($#)); do
18+
case "$1" in
19+
--input-type=module|--input-type=commonjs)
20+
input_type="${1#*=}"
21+
shift
22+
;;
23+
--input-type)
24+
if (($# < 2)) || [[ "$2" != "module" && "$2" != "commonjs" ]]; then
25+
printf 'node: --input-type must be "module" or "commonjs"\n' >&2
26+
exit 9
27+
fi
28+
input_type="$2"
29+
shift 2
30+
;;
31+
--input-type=*)
32+
printf 'node: invalid --input-type value: %s\n' "${1#*=}" >&2
33+
exit 9
34+
;;
35+
*)
36+
translated_args+=("$1")
37+
shift
38+
;;
39+
esac
40+
done
41+
42+
if ((${#translated_args[@]} == 0)); then
43+
if [[ -t 0 ]]; then
44+
if [[ -n "$input_type" ]]; then
45+
printf 'node: --input-type can only be used with string input via --eval, --print, or STDIN\n' >&2
46+
exit 9
47+
fi
48+
exec "$SANDWICH_BIN" repl
49+
fi
50+
exec "$SANDWICH_BIN" -
51+
fi
52+
53+
if [[ "${translated_args[0]}" == "--test" ]]; then
54+
translated_args[0]="test"
55+
fi
56+
57+
# Bun already evaluates stdin, --eval, and --print as JavaScript/TypeScript
58+
# modules with both ESM and CommonJS compatibility. Node's --input-type flag
59+
# is therefore a semantic no-op after validation and must not be forwarded:
60+
# Bun treats the unknown flag as a request for top-level CLI help.
61+
exec "$SANDWICH_BIN" "${translated_args[@]}"

0 commit comments

Comments
 (0)