@bneb/b4mal 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +89 -0
  3. package/dist/index.js +18922 -0
  4. package/package.json +64 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kevin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # B4mal
2
+
3
+ B4mal is a fast, deterministic build system and orchestrator for monorepos. It is designed around a strict model of task dependencies to guarantee reproducibility, parallel execution safety, and cache correctness.
4
+
5
+ ## Design Philosophy
6
+
7
+ The core invariant of B4mal is determinism. If a task is executed with the exact same inputs, it must yield the exact same outputs. To achieve this, B4mal completely rejects implicit dependencies. Every file read, file write, and environment variable must be explicitly declared in the task configuration.
8
+
9
+ If two tasks declare intersecting resource modifications without an explicit dependency edge, B4mal prevents them from executing in parallel using a strict path-based prefix tree lock.
10
+
11
+ ## Key Features
12
+
13
+ - **Resource-isolated scheduling**: Declared filesystem and environment access is checked before execution. Two tasks whose claims overlap are serialized rather than raced, and the prefix tree understands directory/file containment (`dist/` overlaps `dist/main.js`, but `src/db` does not overlap `src/db_backup`).
14
+ - **DAG audit — `b4mal check`**: Verifies a lockfile without executing anything. It reports resource collisions, deterministic overwrites ("shadowing"), and undeclared producer/consumer pairs. Shadowing is audited across *every* pair of tasks, not only pairs already linked by a dependency chain — two independent tasks declaring the same output are reported even though the planner silently orders them with a synthesized edge.
15
+ - **Verified caching**: L1 (local SQLite ledger + artifact vault) and L2 (remote object storage). A cache key is a pure function of a task's declared inputs — its command, its declared `reads`, and the values of its declared `needsEnv` variables. A task's own declared outputs never contribute to its key, so leftover or externally modified build products cannot change whether the cache hits. The `ArtifactVault` enforces OS-level file descriptor constraints to eliminate TOCTOU vulnerabilities and symlink breakouts.
16
+ - **Fail-fast scheduling**: When a task fails, its transitive dependents are skipped and the build exits non-zero, instead of running downstream work against inputs that were never produced.
17
+ - **Strict environment isolation**: Subprocesses receive only a minimal POSIX whitelist plus the variables the task explicitly declares. Undeclared variables never reach the child process.
18
+ - **Continuous-Flow DAG**: Tasks are compiled into a Directed Acyclic Graph (DAG) and executed in parallel where dependencies allow. Overlapping filesystem constraints automatically inject synthetic dependencies.
19
+ - **Language Server Protocol (LSP)**: B4mal ships with a built-in LSP (`b4mal lsp`) to provide real-time editor feedback for resource collisions while editing configuration files.
20
+
21
+ ## Installation
22
+
23
+ The CLI runs on the [Bun](https://bun.sh) runtime, and the published entry point is a Bun script — **install Bun first**, whichever installer you use.
24
+
25
+ ```bash
26
+ bun install -g @bneb/b4mal
27
+ ```
28
+
29
+ `npm install -g @bneb/b4mal` also works for placing the binary on your `PATH`, but Bun must still be available at runtime.
30
+
31
+ ## Quick Start
32
+
33
+ Define your tasks in `b4mal.config.json`:
34
+
35
+ ```json
36
+ {
37
+ "tasks": {
38
+ "typecheck": { "cmd": ["bunx", "tsc", "--noEmit"], "inputs": ["src"] },
39
+ "test": { "cmd": ["bun", "test"], "inputs": ["src", "tests"], "dependencies": ["typecheck"] },
40
+ "build": { "cmd": ["bun", "build"], "inputs": ["src"], "outputs": ["dist"], "dependencies": ["test"] }
41
+ }
42
+ }
43
+ ```
44
+
45
+ Then audit and run it:
46
+
47
+ ```bash
48
+ b4mal check # verify the DAG without executing anything
49
+ b4mal build # prove + execute, cache-aware
50
+ b4mal build --sync # force-regenerate b4mal.lock from b4mal.config.json
51
+ b4mal analyze # static HTML observability dashboard
52
+ ```
53
+
54
+ `b4mal.lock` is a **generated** artifact whenever `b4mal.config.json` is present — edit the config, not the lock. Running `b4mal init` auto-discovers an existing project, and the migration wizard can translate legacy Turborepo, Nx, and Lerna configurations.
55
+
56
+ ### Autonomous Trace Synthesis
57
+
58
+ B4mal can automatically synthesize a mathematically sound DAG by passively tracing a legacy build script's file descriptor usage:
59
+
60
+ ```bash
61
+ b4mal trace "npm run build"
62
+ ```
63
+
64
+ **Platform Requirements for Tracing**:
65
+ The `trace` command intercepts `execve`, `openat`, and `clone` system calls via Linux tracing primitives (`strace`/eBPF).
66
+ - **Linux / CI**: Runs natively (e.g., GitHub Actions Ubuntu runners).
67
+ - **Docker**: Requires the `--cap-add=SYS_PTRACE` flag to allow system call interception.
68
+ - **macOS / Windows**: Native tracing is unsupported due to OS-level restrictions (SIP). Run the trace step inside a Linux container.
69
+
70
+ *Note: Once `b4mal.ts` is synthesized, the resulting DAG can be executed (`b4mal build`) natively on any OS.*
71
+
72
+ ## Not Yet Implemented
73
+
74
+ Documented in some design notes in this repository, but **not implemented in the code**. Do not rely on these:
75
+
76
+ - **Failure sandboxing.** There is no `.b4mal/shadow/<taskId>` clone-on-failure workspace. A failing task leaves whatever it wrote in place; its dependents are skipped, but nothing is snapshotted for offline diagnosis. (`src/guard/sandbox.ts` exists as an unused standalone helper that nothing calls.)
77
+ - **`BuildDoctor`.** Referenced in `ARCHITECTURE.md`; no such component exists.
78
+ - **Native `trace` on macOS / Windows.** Linux-only, as noted above.
79
+
80
+ ## Documentation
81
+
82
+ - [Core Engine](./src/core/README.md) - Deep dive into caching, validation, and formal verification.
83
+ - [Orchestrator](./src/orchestrator/README.md) - Dynamic scheduling, DAG planning, and subprocess isolation.
84
+ - [Architecture](./ARCHITECTURE.md) - Details on the internal engine mechanics and the DAG collision engine.
85
+ - [Benchmarks](./BENCHMARKS.md) - Apple M4 and Linux NVMe bare-metal performance metrics.
86
+
87
+ ## Contributing
88
+
89
+ Pull requests are welcome. Ensure that you have read the architecture documents to understand the invariants governing the task executor. Run `bun test` to execute the full test suite, and `bunx tsc --noEmit` to type-check, before submitting.