@christianirack/brainllm 0.0.0-stage → 0.1.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Christian Irack Flores Maldonado
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 CHANGED
@@ -1,3 +1,378 @@
1
- # Temporary Holding Version
1
+ <p align="center"><img src="https://raw.githubusercontent.com/chrisifm/BRAINLLM/main/docs/site/assets/logo.png" width="88" alt="BRAINLLM brain mark"></p>
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # BRAINLLM
4
+
5
+ ### The web compiler for LLMs.
6
+
7
+ **Your LLM owns the frontend. Give it a language built for the job.**
8
+
9
+ ![BRAINLLM — The web compiler for LLMs](https://github.com/chrisifm/BRAINLLM/raw/main/docs/site/assets/cover.png)
10
+
11
+ BRAINLLM gives coding agents a compact language, a single specification and a compiler that tells them how to fix
12
+ mistakes. The model builds the frontend. You set the direction, inspect the result and decide what ships.
13
+
14
+ `.brain` components compile to direct-DOM JavaScript and scoped CSS. The Rust toolchain handles parsing, checking,
15
+ code generation, bundling and minification. The agent can operate it through the CLI or MCP.
16
+
17
+ **Build with it. Let your LLM make it better.** Every run is a chance to spot a compiler bug, an expensive step or
18
+ a confusing diagnostic. The agent can turn that finding into a tested proposal and, when configured, push it
19
+ automatically to a review branch. Maintainers decide what merges.
20
+
21
+ **[Visit the site](https://chrisifm.github.io/BRAINLLM/)** · **[Build your first app](#give-your-agent-its-first-task)** · **[Read the spec](https://github.com/chrisifm/BRAINLLM/blob/main/SPEC.md)** · **[See the benchmarks](#show-me-the-numbers)** · **[Contribute](#build-the-tool-your-agent-needs)**
22
+
23
+ ## A frontend language with the model in mind
24
+
25
+ An agent writing your app needs a contract it can follow and feedback it can act on. BRAINLLM makes that loop
26
+ explicit: read the spec, generate a component, check it, apply the fix, test the result.
27
+
28
+ ![An agent reads the BRAINLLM contract, writes a component and uses compiler feedback to validate the app](https://github.com/chrisifm/BRAINLLM/raw/main/docs/site/assets/agent-loop.png)
29
+
30
+ - **Less to guess.** `brain spec` defines the supported language. One component format, a prescribed project
31
+ structure and generators keep the model working inside a known contract.
32
+ - **Feedback it can use.** Diagnostics include the file, location, rule and proposed fix. Mechanical fixes carry
33
+ exact replacement edits; `brain fix` applies them. Decisions that need judgment remain visible to the agent.
34
+ - **Tools for the whole loop.** `brain map --json`, `brain check --json`, `brain doctor` and `brain build` let the
35
+ agent inspect, validate and compile its work. `brain mcp` exposes tools over stdio.
36
+ - **Output for the browser.** Signals update the affected DOM nodes. The toolchain includes its own compiler,
37
+ bundler and minifier, with no Vite, webpack, esbuild or Babel in the build pipeline.
38
+
39
+ BrainScript builds on HTML, CSS and a constrained subset of JavaScript. It is designed to reduce the choices an
40
+ agent has to reconstruct while preserving code that a developer can read and review.
41
+
42
+ ## What your agent gets to work with
43
+
44
+ | Capability | What it does for the app-building loop |
45
+ |---|---|
46
+ | A served language contract | `brain spec` gives the model the implemented syntax and conventions |
47
+ | Components and reactive state | `.brain` files combine markup, BrainScript and scoped styles; `sig`, `drv` and `fx` express updates |
48
+ | Forms and data | Form validation, HTTP resources and server contracts give common app behavior a documented path |
49
+ | Routes and layouts | Views, layouts, loaders and guards put navigation and access checks into the project structure |
50
+ | Diagnostics and repairs | JSON diagnostics identify failures; supported mechanical edits can be applied with `brain fix` |
51
+ | Context and automation | The project map, focused reads, CLI and MCP tools let an agent inspect and operate the app |
52
+ | Verification and delivery | Tests, `brain doctor` and the production build make validation part of the workflow |
53
+ | Tested compiler improvements | Isolated proposals, validation gates and optional review-branch pushes let the agent contribute fixes |
54
+
55
+ Use [SPEC.md](https://github.com/chrisifm/BRAINLLM/blob/main/SPEC.md), the served `brain spec` and [EVOLUTION.md](https://github.com/chrisifm/BRAINLLM/blob/main/docs/EVOLUTION.md) for exact contracts and limits.
56
+
57
+ ## Where it fits in the frontend stack
58
+
59
+ These tools occupy different layers. This is a comparison of their roles, not a universal speed ranking. Linked
60
+ project documentation describes each tool; the BRAINLLM column explains the choice this project makes.
61
+
62
+ | Project | Main role | How BRAINLLM approaches that part of the job |
63
+ |---|---|---|
64
+ | [React](https://react.dev/) | Library for building component-based user interfaces | A dedicated component language, compiler and agent workflow together |
65
+ | [Angular](https://angular.dev/overview) | Web application framework with integrated tooling | A constrained language and normative spec built around LLM authorship |
66
+ | [Vue](https://vuejs.org/guide/introduction.html) | Progressive framework for declarative, reactive interfaces | Prescribed component syntax and structure with compiler-guided repairs |
67
+ | [Astro](https://docs.astro.build/en/concepts/why-astro/) | Web framework focused on content-driven sites and islands | A language and toolchain for agent-authored frontends, with its own rendering contracts |
68
+ | [Vite](https://vite.dev/guide/) | Development server and production build tooling | An integrated Rust pipeline for `.brain` applications |
69
+ | [webpack](https://webpack.js.org/concepts/) | Module bundler with loaders and plugins | Its own bundler and minifier as part of the compiler pipeline |
70
+ | **BRAINLLM** | **Frontend language, compiler, runtime and agent contract** | **The model writes, checks and improves within one documented workflow** |
71
+
72
+ Other projects also offer AI guidance and tooling. BRAINLLM's emphasis is the authoring contract itself. It does
73
+ not run existing React, Angular or Vue components unchanged, and replacing a build tool alone is not a migration.
74
+ The numerical comparison below covers only the measured React/Vite and Svelte/Vite fixture builds.
75
+
76
+ ## A form shouldn't need an ecosystem.
77
+
78
+ Your agent came to build a button. Your stack handed it a committee.
79
+
80
+ If setup decisions are consuming the session, give the model a toolchain with a defined contract.
81
+
82
+ BRAINLLM brings component syntax, state, forms, routing and compiler feedback into one documented workflow. Its
83
+ Rust toolchain owns the build pipeline, and the browser runtime has no third-party dependencies. Start with the
84
+ web behavior you need; give the agent a smaller set of conventions to learn and check.
85
+
86
+ **Less tooling. More web.**
87
+
88
+ ## Show me the numbers
89
+
90
+ **Don't trust the headline. Run the benchmark.**
91
+
92
+ If you like reading raw timings more than launch posts, this part is for you. Inspect the fixture, reproduce the
93
+ run and keep the result even when it disagrees with ours.
94
+
95
+
96
+ **Seven stacks. The same dashboard workflow. 140 measured builds.**
97
+
98
+ | Warm production build | Median, 20 runs | Standard deviation |
99
+ |---|---:|---:|
100
+ | BRAINLLM | 34.32 ms | 13.23 ms |
101
+ | React + Vite | 155.49 ms | 16.71 ms |
102
+ | Vue + Vite | 211.76 ms | 53.56 ms |
103
+ | Svelte + Vite | 243.53 ms | 56.14 ms |
104
+ | Astro + React island | 504.78 ms | 77.45 ms |
105
+ | Angular CLI | 1,262.50 ms | 69.03 ms |
106
+ | React + webpack | 1,334.54 ms | 560.99 ms |
107
+
108
+ All seven implementations passed the same nine Chrome interaction checks, including create, search, edit and delete.
109
+ These measurements use frozen BRAINLLM source `7889787`, Apple M5 with 24 GiB RAM, Node 26.12.0 and two warmups per
110
+ stack. Builds run serially on a shared machine. Variance matters: inspect the raw samples, especially webpack's.
111
+ The output strategies differ (including SSR, client rendering and an Astro React island); this comparison measures
112
+ production build duration for this fixture, not universal app performance or feature equivalence.
113
+
114
+ Read the [expanded method, versions, payloads and results](https://github.com/chrisifm/BRAINLLM/blob/main/bench/build/expanded.md). The original three-stack
115
+ [historical results](https://github.com/chrisifm/BRAINLLM/blob/main/bench/build/results/summary.md) remain available unchanged. Use `bench/build/expanded.mjs`
116
+ with the documented frozen binary and scratch-directory setup to reproduce this seven-stack run.
117
+
118
+ **Ask your agent to challenge the result:**
119
+
120
+ ```text
121
+ Reproduce BRAINLLM's build benchmark and tell me what the evidence supports.
122
+ First inspect bench/build/README.md, bench/build/run.sh, the frozen fixture,
123
+ the React/Svelte reference implementations and their pinned dependencies.
124
+ Explain the output differences and required tools before running anything.
125
+
126
+ Run bench/build/run.sh in an isolated workspace using its documented settings.
127
+ Keep the compared fixture implementations unchanged. Record the compiler hash,
128
+ tool versions, hardware, machine load, warmups and sample count. Preserve the
129
+ raw timings and report cold and warm medians in ms, plus the measured HTML,
130
+ CSS and JavaScript payload in KiB gzip with every excluded asset identified.
131
+
132
+ Compare the local results with the checked-in results. Report failures,
133
+ limitations and regressions as observed. Do not claim a win unless the actual
134
+ numbers support it. Do not upload results or publish anything automatically.
135
+ Clean up only the temporary resources this run created.
136
+ ```
137
+
138
+ A separate [cache-key microbenchmark](https://github.com/chrisifm/BRAINLLM/blob/main/bench/build/results/compiler-cache-lookup.json) measured **43.3× faster key
139
+ lookup** after removing an unnecessary parse: 10,000 lookups of a 1,050-byte input. That number measures this
140
+ internal operation only. It is not a full-build speedup or a webpack comparison.
141
+
142
+ The [benchmark report](https://github.com/chrisifm/BRAINLLM/blob/main/bench/REPORT.md) also tracks agent-generated apps, browser behavior, payload size and
143
+ failure recovery. Historical LLM results describe their frozen model/spec/compiler runs; they do not guarantee
144
+ that a new prompt or compiler revision will pass. This project is open to developers and researchers who want to
145
+ investigate how language design and compiler feedback affect agent behavior. Bring a hypothesis and a reproducer.
146
+
147
+ The compiler pipeline is written in Rust. Browser automation drives real Chrome through CDP for interaction and
148
+ regression checks. Those checks establish the flows they exercise; they do not imply universal browser or app
149
+ compatibility. The repository's recorded LLM evaluations identify the models, tasks and frozen revisions so you can inspect
150
+ what each result actually establishes.
151
+
152
+ ## Tools for an agent that finishes the job
153
+
154
+ | The agent needs to… | The compiler provides… |
155
+ |---|---|
156
+ | Start with consistent files | Generators for views, components, channels, services, typed APIs, schemas, route guards and server modules |
157
+ | Refactor without guessing imports | Checked AST edits for props, component-file rename, move and extraction |
158
+ | Inspect what it built | Chrome screenshots, accessibility outlines and explicit visual baseline comparisons |
159
+ | Keep routes small | Enforced `viewKB` budgets for emitted JS + CSS + HTML |
160
+ | Defer optional UI | Visible, idle or keyboard-accessible interaction loading; async image decoding |
161
+ | Fix and verify | `brain doctor --fix` applies mechanical edits before the full quality check |
162
+ | Let you try production output | A temporary local `brain preview` server with owned-process cleanup |
163
+
164
+ Browser tooling and the preview supervisor currently require macOS or Linux. Screenshot baselines need stable browser,
165
+ font and app-data inputs. Runtime mount-time/heap budgets remain planned; the compiler rejects those settings rather
166
+ than pretending to measure them. See the [implemented contract](https://github.com/chrisifm/BRAINLLM/blob/main/SPEC.md) and [tool internals](https://github.com/chrisifm/BRAINLLM/blob/main/docs/INTERNALS.md).
167
+
168
+ ## Give your agent its first task
169
+
170
+ **Connect your coding agent. Tell it what to build. Try the app.**
171
+
172
+ Open a coding agent with access to your project files and terminal. Give it the prompt below and your product
173
+ brief. It can install the compiler, read the language contract and work through the checks. Once the app runs,
174
+ try the actual workflow and tell the agent what should change. You stay in charge of the product and what ships.
175
+
176
+ BRAINLLM's CLI is the starting point; `brain mcp` also connects through clients that support MCP over stdio.
177
+ Your agent needs Node 22+ and Chrome for browser-based checks on macOS or Linux. Git and Rust stable are needed
178
+ only when building the compiler from source or contributing. It should report missing prerequisites honestly.
179
+
180
+ **Paste this into your coding agent:**
181
+
182
+ ```text
183
+ Build a small task app with BRAINLLM: add, complete and delete tasks,
184
+ and save them locally. Follow https://github.com/chrisifm/BRAINLLM
185
+ for setup. Run the checks and open the app for me.
186
+ ```
187
+
188
+ <details>
189
+ <summary>Expanded agent workflow for a custom project</summary>
190
+
191
+ ```text
192
+ Build my frontend with BRAINLLM.
193
+
194
+ Product brief: [describe the app, its users and the first useful workflow].
195
+
196
+ 1. Inspect the workspace and available tools. Preserve existing files and secrets.
197
+ Verify Node 22+ and Chrome for browser checks. Create a separate app with
198
+ npm create @christianirack/brainll@latest my-app. If npm is unavailable,
199
+ follow the source-install instructions in the README. Report missing prerequisites.
200
+ 2. Enter the generated app. Read its AGENTS.md and run npx brain spec.
201
+ Only use implemented features in the served spec; do not invent APIs.
202
+ 3. Read npx brain map --json. Generate the needed views and components with brain add.
203
+ Implement the first complete user workflow, including loading, empty, error
204
+ and success states. Add meaningful behavior tests.
205
+ 4. Run npx brain fix, then npx brain check --json. Resolve remaining diagnostics.
206
+ Run npx brain doctor and npx brain build. Exercise the workflow in the browser.
207
+ 5. Report actual test results, remaining gaps and how to run the app. Stop
208
+ temporary processes and close only browser resources you created.
209
+ Do not publish or deploy without my instruction.
210
+
211
+ At each completed workflow, look for a concrete compiler defect or measurable
212
+ improvement. Read docs/EVOLUTION.md and docs/AGENT-IDEAS.md in the framework repo.
213
+ Reproduce it, add a regression test and propose the smallest compatible fix.
214
+ Only use automatic contribution when I have explicitly configured it for an
215
+ owned fork or authorized review branch. Never weaken checks or merge automatically.
216
+ ```
217
+
218
+ </details>
219
+
220
+ <details>
221
+ <summary>Prefer to install it yourself? Here are the commands.</summary>
222
+
223
+ Use the public initializer (no npm account required):
224
+
225
+ ```sh
226
+ npm create @christianirack/brainll@latest my-app
227
+ cd my-app
228
+ npm run dev
229
+ ```
230
+
231
+ `npm create @christianirack/brainllm@latest my-app` is the canonical spelling with identical behavior.
232
+ Inside the generated app, use `npx brain` for CLI commands and `npm run build` for production.
233
+ The compiler is prebuilt; Rust is needed only for the source installation below.
234
+
235
+ ```sh
236
+ git clone https://github.com/chrisifm/BRAINLLM.git
237
+ cd BRAINLLM
238
+ cargo install --locked --path crates/brain-cli
239
+ brain new my-app
240
+ cd my-app
241
+ brain run
242
+ ```
243
+
244
+ With a source installation, use the installed `brain` commands directly. That workflow does not require
245
+ `npm install` in the generated app.
246
+
247
+ Cargo installs `brain` into its bin directory; make sure that directory is on your `PATH`. Stop the dev server with
248
+ Ctrl+C. From the app directory, run `brain doctor` to validate it and `brain build` to create production output.
249
+ For an MCP client in an npm-created app, use command `npx` with arguments `["brain", "mcp"]` and the app as its
250
+ working directory. With a source installation, use the installed `brain` executable and argument `mcp`. Follow that client's configuration instructions; merely copying a prompt does not grant tool access.
251
+
252
+ </details>
253
+
254
+ For an existing frontend, start with the [migration workflow](https://github.com/chrisifm/BRAINLLM/blob/main/docs/MIGRATION.md). Its read-only planner recognizes
255
+ React, Angular, Vue, Svelte, Next and Nuxt projects. Port one tested route or component at a time, preserve its
256
+ behavior and keep a rollback path. It is an incremental workflow, not an automatic transpiler.
257
+
258
+ ## The code your agent handles
259
+
260
+ ```html
261
+ <meta props="start:num=0 label:str='Clicks'">
262
+
263
+ <script>
264
+ let n = sig(start)
265
+ let dbl = drv(() => n * 2)
266
+ </script>
267
+
268
+ <button on:click={n++}>{label}: {n} × 2 = {dbl}</button>
269
+ ```
270
+
271
+ The compiler handles signal reads and writes. Derived values update when their inputs change. Styles can live in
272
+ the same file and are scoped to the component. The [served spec](https://github.com/chrisifm/BRAINLLM/blob/main/SPEC.md) defines the supported syntax.
273
+
274
+ ## Readable intent. Lean browser output.
275
+
276
+ An internal function named `back_to_home` can become a short identifier in production. The exact letter depends
277
+ on scope and the other names in the module. Keep meaningful names where the agent reasons about the code; let the
278
+ compiler shorten eligible bindings in what the browser receives.
279
+
280
+ This example comes from the [minifier's scope regression tests](https://github.com/chrisifm/BRAINLLM/blob/main/crates/brain-min/src/mangle.rs):
281
+
282
+ ```js
283
+ // Before
284
+ function outer(longName, other) {
285
+ const total = longName + other.value;
286
+ return total + window.x;
287
+ }
288
+
289
+ // After
290
+ function a(a,b){const c=a+b.value;return c+window.x}
291
+ ```
292
+
293
+ Property names and external references retain their meaning. Exported bindings and other protected names follow
294
+ the minifier's preservation rules. The source stays readable; the production artifact gets smaller identifiers.
295
+ That saves output bytes, not automatically the tokens used by an LLM reading source. Reducing agent context cost
296
+ is a separate design goal served by the language contract, focused reads and project map; quantify it with a
297
+ measured agent workflow before claiming a token saving.
298
+
299
+ ## Errors should give the agent a next move.
300
+
301
+ BRAINLLM includes protections at several stages of the app loop:
302
+
303
+ - **Before it ships:** compiler checks cover supported language rules, accessibility and server/client boundaries.
304
+ Private environment values belong on the server; client access is restricted to `PUBLIC_` values.
305
+ - **At the form:** schemas define required fields and supported types; server field errors return to the form.
306
+ The application still owns its business rules, authorization and server-side validation.
307
+ - **When a component fails:** runtime boundaries capture render and reactive errors, report them and replace the
308
+ affected component with a fallback. A failing event handler reports the error while keeping the component.
309
+ Retry is bounded: three failures within ten seconds remove the retry button.
310
+ - **When work runs away:** runtime budgets stop affected components that exceed monitored limits. The production
311
+ build also probes views with simulated timers for unbounded growth. `brain doctor` runs the project's checks,
312
+ tests and diagnostics; failed stages remain visible to the agent.
313
+
314
+ These are implemented mechanisms, not a promise to catch every bug or repair every failure. The agent still needs
315
+ to test the user's workflow. See [runtime behavior in the spec](https://github.com/chrisifm/BRAINLLM/blob/main/SPEC.md#errors-at-runtime),
316
+ [component boundaries](https://github.com/chrisifm/BRAINLLM/blob/main/runtime/brain-guard.js) and [compiler diagnostics](https://github.com/chrisifm/BRAINLLM/blob/main/crates/brain-check/).
317
+
318
+ ## Build the tool your agent needs
319
+
320
+ **Build with it. Let your LLM make it better.**
321
+
322
+ ![An LLM turns an observed problem into an isolated fix, runs validation and submits a contribution for human review](https://github.com/chrisifm/BRAINLLM/raw/main/docs/site/assets/improvement-loop.png)
323
+
324
+ A failed compilation can become a regression test. A repeated slow step can become a benchmark. A fix made while
325
+ building your app can become a contribution that helps the next developer and their agent.
326
+
327
+ Found a compiler gap while building an app? Turn the smallest reproducible case into a regression test and a
328
+ contribution. BRAINLLM includes an [evolution workflow](https://github.com/chrisifm/BRAINLLM/blob/main/docs/EVOLUTION.md) for isolated proposals, validated compiler
329
+ binaries and reversible activation. Configured automatic pushes go to review branches; merges require the
330
+ principal author's review. This is an explicit development workflow, not a compiler that silently rewrites itself
331
+ on every build. Read the [agent improvement playbook](https://github.com/chrisifm/BRAINLLM/blob/main/docs/AGENT-IDEAS.md) for an opt-in prompt and concrete ideas
332
+ to investigate.
333
+
334
+ Human developers and LLM contributors are welcome. Useful first contributions include reproducible compiler bugs,
335
+ behavior-preserving migration examples, clearer diagnostics and performance improvements with before/after data.
336
+
337
+ 1. Read [CONTRIBUTING.md](https://github.com/chrisifm/BRAINLLM/blob/main/CONTRIBUTING.md) and the relevant [internals](https://github.com/chrisifm/BRAINLLM/blob/main/docs/INTERNALS.md).
338
+ 2. Make a focused change with a regression test and synthetic sample data.
339
+ 3. Run `bash scripts/verify.sh`. It builds the CLI and checks Rust, runtime, tooling, diagnostic fixtures, privacy
340
+ and repository language. Verification also requires ripgrep.
341
+ 4. Open a pull request with the problem, resulting behavior and actual validation evidence.
342
+
343
+ Changes to what app authors write also require the frozen LLM benchmark workflow described in CONTRIBUTING.
344
+ Never include app secrets, private source or customer data in a contribution.
345
+
346
+ ## Know what you are adopting
347
+
348
+ BRAINLLM is **0.1.0**. Start with a small app or an isolated route and test the behavior you need. Features marked
349
+ as planned in the source specification are not a supported promise; `brain spec` serves the implemented contract.
350
+ Third-party React, Angular and Vue components do not become BRAINLLM components automatically. Benchmark wins in
351
+ build time do not imply that every runtime workload is faster.
352
+
353
+ ## Keep building
354
+
355
+ | You want to… | Start here |
356
+ |---|---|
357
+ | Give an agent the project context | [llms.txt](https://github.com/chrisifm/BRAINLLM/blob/main/llms.txt) |
358
+ | Write an app | [SPEC.md](https://github.com/chrisifm/BRAINLLM/blob/main/SPEC.md) and `brain spec` |
359
+ | Migrate an existing frontend | [Migration guide](https://github.com/chrisifm/BRAINLLM/blob/main/docs/MIGRATION.md) |
360
+ | Improve the compiler while using it | [Evolution workflow](https://github.com/chrisifm/BRAINLLM/blob/main/docs/EVOLUTION.md) and [agent ideas](https://github.com/chrisifm/BRAINLLM/blob/main/docs/AGENT-IDEAS.md) |
361
+ | Understand the implementation | [Internals](https://github.com/chrisifm/BRAINLLM/blob/main/docs/INTERNALS.md) and [crates](https://github.com/chrisifm/BRAINLLM/blob/main/crates/) |
362
+ | Inspect examples and reproduce measurements | [Examples](https://github.com/chrisifm/BRAINLLM/blob/main/examples/) and [benchmarks](https://github.com/chrisifm/BRAINLLM/blob/main/bench/) |
363
+ | Contribute a change | [Contributor guide](https://github.com/chrisifm/BRAINLLM/blob/main/CONTRIBUTING.md) |
364
+
365
+ Released under the [MIT license](https://github.com/chrisifm/BRAINLLM/blob/main/LICENSE).
366
+
367
+ Created and maintained by **Christian Irack Flores Maldonado**, principal author.
368
+ [ingenieria.dev](https://ingenieria.dev) · [irack.mx](https://irack.mx) · [christian@irack.mx](mailto:christian@irack.mx)
369
+
370
+ <!-- contributors:start -->
371
+ ## Built by contributors
372
+
373
+ Every merged contribution helps the next developer and their agent. Thank you to the public GitHub accounts credited below.
374
+
375
+ [<img src="https://avatars.githubusercontent.com/u/1562002?v=4" width="48" height="48" alt="chrisifm">](https://github.com/chrisifm) [chrisifm](https://github.com/chrisifm)
376
+
377
+ Attribution is refreshed through a reviewed pull request. [How it works](https://github.com/chrisifm/BRAINLLM/blob/main/docs/CONTRIBUTORS.md).
378
+ <!-- contributors:end -->
package/bin/brain.js ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+ // `brain` launcher (INTERNALS §23): runs the native binary of this platform, shipped in one of the
3
+ // @christianirack/brainllm-<os>-<arch> optional dependencies. No postinstall, no download, no dependencies.
4
+ //
5
+ // 1. A global `brain` delegates to the version the project pins (node_modules/@christianirack/brainllm of the nearest
6
+ // package.json above the working directory), so two projects on different versions coexist.
7
+ // 2. BRAIN_BINARY=<path> runs that binary instead (local builds, unsupported platforms).
8
+ // 3. Otherwise the platform package's bin/brain(.exe); its exit code and signal pass through unchanged.
9
+ 'use strict'
10
+ const { spawnSync } = require('node:child_process')
11
+ const { existsSync, realpathSync } = require('node:fs')
12
+ const { dirname, join, resolve } = require('node:path')
13
+
14
+ const SCOPE = '@christianirack'
15
+ const here = realpathSync(__dirname)
16
+
17
+ function projectLauncher() {
18
+ if (process.env.BRAIN_NO_DELEGATE) return null
19
+ let dir = process.cwd()
20
+ for (;;) {
21
+ const cand = join(dir, 'node_modules', SCOPE, 'brainllm', 'bin', 'brain.js')
22
+ if (existsSync(cand)) {
23
+ const real = realpathSync(cand)
24
+ return dirname(real) === here ? null : real
25
+ }
26
+ const up = dirname(dir)
27
+ if (up === dir) return null
28
+ dir = up
29
+ }
30
+ }
31
+
32
+ function isMusl() {
33
+ if (process.platform !== 'linux') return false
34
+ try {
35
+ return !process.report.getReport().header.glibcVersionRuntime
36
+ } catch {
37
+ return existsSync('/etc/alpine-release')
38
+ }
39
+ }
40
+
41
+ function platformPackage() {
42
+ const { platform, arch } = process
43
+ const libc = isMusl() ? '-musl' : ''
44
+ const supported = ['darwin-arm64', 'darwin-x64', 'linux-x64', 'linux-arm64', 'linux-x64-musl', 'win32-x64', 'win32-arm64']
45
+ const key = `${platform}-${arch}${libc}`
46
+ return supported.includes(key) ? `${SCOPE}/brainllm-${key}` : null
47
+ }
48
+
49
+ function binary() {
50
+ if (process.env.BRAIN_BINARY) return resolve(process.env.BRAIN_BINARY)
51
+ const pkg = platformPackage()
52
+ if (!pkg) {
53
+ fail(`no prebuilt brain for ${process.platform}-${process.arch}; fix: build it with \`cargo build --release -p brain-cli\` and set BRAIN_BINARY to target/release/brain`)
54
+ }
55
+ const exe = process.platform === 'win32' ? 'brain.exe' : 'brain'
56
+ try {
57
+ return join(dirname(require.resolve(`${pkg}/package.json`, { paths: [here] })), 'bin', exe)
58
+ } catch {
59
+ fail(`${pkg} is not installed (it is an optional dependency of ${SCOPE}/brainllm); fix: reinstall without --no-optional / --omit=optional, e.g. \`npm install ${SCOPE}/brainllm\``)
60
+ }
61
+ }
62
+
63
+ function fail(msg) {
64
+ process.stderr.write(`error: ${msg}\n`)
65
+ process.exit(3)
66
+ }
67
+
68
+ const delegate = projectLauncher()
69
+ const [cmd, args] = delegate ? [process.execPath, [delegate, ...process.argv.slice(2)]] : [binary(), process.argv.slice(2)]
70
+ const r = spawnSync(cmd, args, { stdio: 'inherit', windowsHide: true })
71
+ if (r.error) fail(`could not run ${cmd}: ${r.error.message}`)
72
+ if (r.signal) process.kill(process.pid, r.signal)
73
+ process.exit(r.status ?? 1)
@@ -0,0 +1,153 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "brain.schema.json",
4
+ "title": "brain.json",
5
+ "description": "BRAINLLM app configuration. Precedence: flag > BRAIN_* variable > brain.json > defaults.",
6
+ "type": "object",
7
+ "properties": {
8
+ "$schema": {
9
+ "type": "string"
10
+ },
11
+ "name": {
12
+ "type": "string",
13
+ "description": "App name (SEO, web manifest)."
14
+ },
15
+ "description": {
16
+ "type": "string"
17
+ },
18
+ "lang": {
19
+ "type": "string",
20
+ "description": "Default document language, e.g. \"en\"."
21
+ },
22
+ "site": {
23
+ "type": "string",
24
+ "format": "uri",
25
+ "description": "Public origin, e.g. https://example.com. Prefer PUBLIC_SITE_URL in .brain_env."
26
+ },
27
+ "base": {
28
+ "type": "string",
29
+ "pattern": "^/([^/?#\\s]+/)*$",
30
+ "default": "/",
31
+ "description": "Path the app is hosted under: starts and ends with \"/\", e.g. \"/app/\". brain run, brain build and brain start serve every URL under it."
32
+ },
33
+ "cache": {
34
+ "type": "object",
35
+ "properties": {
36
+ "http": {
37
+ "type": "boolean",
38
+ "default": true
39
+ },
40
+ "sw": {
41
+ "type": "boolean",
42
+ "default": true
43
+ },
44
+ "offline": {
45
+ "type": "boolean",
46
+ "default": true
47
+ },
48
+ "data": {
49
+ "type": "boolean",
50
+ "default": true
51
+ },
52
+ "precacheKB": {
53
+ "type": "number",
54
+ "minimum": 0,
55
+ "default": 2048
56
+ }
57
+ }
58
+ },
59
+ "seo": {
60
+ "type": "object",
61
+ "properties": {
62
+ "minScore": {
63
+ "type": "number",
64
+ "minimum": 0,
65
+ "maximum": 100,
66
+ "default": 80
67
+ },
68
+ "sitemap": {
69
+ "type": "boolean",
70
+ "default": true
71
+ },
72
+ "llms": {
73
+ "type": "boolean",
74
+ "default": true
75
+ },
76
+ "llmsFull": {
77
+ "type": "boolean",
78
+ "default": true
79
+ },
80
+ "manifest": {
81
+ "type": "boolean",
82
+ "default": true
83
+ },
84
+ "indexnow": {
85
+ "type": "boolean",
86
+ "default": false
87
+ },
88
+ "markdown": {
89
+ "type": "boolean",
90
+ "default": true
91
+ }
92
+ }
93
+ },
94
+ "budget": {
95
+ "type": "object",
96
+ "additionalProperties": false,
97
+ "description": "Build byte budgets. mountMs and heapMB are planned browser measurements and are rejected until implemented.",
98
+ "properties": {
99
+ "viewKB": {
100
+ "type": "number",
101
+ "minimum": 0,
102
+ "description": "Maximum KiB (1024 bytes) of emitted JS, CSS and HTML per route. Uses gzip when smaller, otherwise raw bytes; includes the conservatively reachable JS graph, including lazy chunks. Excludes images/fonts. Exceeding this value fails build."
103
+ }
104
+ }
105
+ },
106
+ "i18n": {
107
+ "type": "object",
108
+ "properties": {
109
+ "default": {
110
+ "type": "string"
111
+ },
112
+ "locales": {
113
+ "type": "array",
114
+ "items": {
115
+ "type": "string"
116
+ }
117
+ }
118
+ }
119
+ },
120
+ "ext": {
121
+ "type": "string",
122
+ "enum": [
123
+ "web",
124
+ "brain"
125
+ ],
126
+ "default": "web",
127
+ "description": "Published file names: web (.html/.js/.css) or brain (.brain/.jsbrain/.cssbrain, with Content-Type set by _headers, nginx and Caddy). brain build --ext overrides it."
128
+ },
129
+ "lint": {
130
+ "type": "object",
131
+ "description": "Per-rule level, e.g. {\"B1307\": \"off\"}. Only the quality families (B09xx-B13xx) can be changed; other overrides are ignored.",
132
+ "propertyNames": {
133
+ "pattern": "^B(09|1[0-3])[0-9]{2}$"
134
+ },
135
+ "additionalProperties": {
136
+ "enum": [
137
+ "off",
138
+ "info",
139
+ "warning",
140
+ "error"
141
+ ]
142
+ }
143
+ },
144
+ "targets": {
145
+ "enum": [
146
+ "baseline-widely",
147
+ "baseline-newly"
148
+ ],
149
+ "default": "baseline-widely",
150
+ "description": "Browser support target of the B12xx compatibility rules: Baseline widely available (default) or newly available."
151
+ }
152
+ }
153
+ }
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@christianirack/brainllm",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "BRAINLLM: a web framework designed for LLMs to write. The `brain` CLI, dev server, build and MCP server.",
5
+ "bin": {
6
+ "brain": "bin/brain.js"
7
+ },
8
+ "files": [
9
+ "bin",
10
+ "brain.schema.json",
11
+ "README.md"
12
+ ],
13
+ "engines": {
14
+ "node": ">=22"
15
+ },
16
+ "optionalDependencies": {
17
+ "@christianirack/brainllm-darwin-arm64": "0.1.0",
18
+ "@christianirack/brainllm-darwin-x64": "0.1.0",
19
+ "@christianirack/brainllm-linux-x64": "0.1.0",
20
+ "@christianirack/brainllm-linux-arm64": "0.1.0",
21
+ "@christianirack/brainllm-linux-x64-musl": "0.1.0",
22
+ "@christianirack/brainllm-win32-x64": "0.1.0",
23
+ "@christianirack/brainllm-win32-arm64": "0.1.0"
24
+ },
25
+ "keywords": [
26
+ "framework",
27
+ "llm",
28
+ "ai",
29
+ "compiler",
30
+ "mcp",
31
+ "web"
32
+ ],
33
+ "license": "MIT",
34
+ "author": "Christian Irack Flores Maldonado <christian@irack.mx> (https://ingenieria.dev)",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/chrisifm/BRAINLLM.git"
38
+ },
39
+ "homepage": "https://chrisifm.github.io/BRAINLLM/",
40
+ "publishConfig": {
41
+ "access": "public",
42
+ "registry": "https://registry.npmjs.org/"
43
+ }
44
+ }