Skip to content

Commit 25a1824

Browse files
hyperpolymathclaude
andcommitted
Add rescript-vite plugin with BoJ integration and tests
New Vite plugin for ReScript in rescript-ecosystem/rescript-vite/: - Compiler bridge, HMR, error overlay, diagnostic parsing - BoJ SSG-MCP server integration for build orchestration - 30+ tests, benchmarks, panic-attack integration tests - Also promoted to standalone repo: hyperpolymath/rescript-vite Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2fbeb2d commit 25a1824

22 files changed

Lines changed: 4747 additions & 105 deletions

.hypatia/activity.jsonl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"timestamp":"2026-03-08T02:03:03Z","bot":"hypatia-autofix","action":"scan","details":"fixes=0"}

.hypatia/last-visit.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"last_visit": "2026-03-08T02:03:03Z",
3+
"last_bot": "hypatia-autofix",
4+
"last_action": "scan",
5+
"visits_total": 1
6+
}

.hypatia/scan-cache/fix-http-to-https.hashes

Lines changed: 1616 additions & 0 deletions
Large diffs are not rendered by default.

.hypatia/scan-cache/fix-todo-markers.hashes

Lines changed: 446 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 198 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,154 +1,247 @@
1-
= RSR template repo - see RSR_OUTLINE.adoc in root for general background and specification
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
2+
// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
3+
4+
= rescript-vite
5+
:toc: macro
6+
:toclevels: 3
7+
8+
A Vite plugin for first-class ReScript support with HMR, compiler integration,
9+
error overlay, and optional BoJ (Bundle of Joy) build orchestration via the
10+
ssg-mcp cartridge.
11+
12+
toc::[]
13+
14+
== What is rescript-vite?
15+
16+
rescript-vite integrates the ReScript compiler into Vite's build pipeline.
17+
It automatically spawns the ReScript compiler in build or watch mode, tracks
18+
compiled `.res.js` output files for hot module replacement (HMR), and forwards
19+
compiler diagnostics to Vite's error overlay. When a BoJ server is available,
20+
it can delegate builds to the ssg-mcp cartridge for caching, telemetry, and
21+
orchestrated compilation.
22+
23+
=== Features
24+
25+
* *Automatic compiler management* -- spawns `rescript build` (one-shot) or
26+
`rescript build -w` (watch mode) depending on whether Vite is in `build`
27+
or `serve` mode.
28+
* *HMR for .res files* -- detects recompiled `.res.js` files and triggers
29+
hot module replacement in the browser.
30+
* *Error overlay integration* -- pushes ReScript compiler errors to Vite's
31+
built-in error overlay with file, line, and column info.
32+
* *Diagnostic parsing* -- parses ReScript compiler output including ANSI
33+
escape codes, extracting structured diagnostic objects.
34+
* *Deno compatible* -- auto-detects the Deno runtime and adjusts compiler
35+
invocation accordingly.
36+
* *BoJ build orchestration* -- optionally delegates builds to a running
37+
BoJ ssg-mcp cartridge for incremental builds, caching, and telemetry.
38+
* *panic-attacker compatible* -- diagnostic format maps cleanly to SARIF-style
39+
output used by panic-attacker weak-point scanning.
40+
41+
== Installation
42+
43+
=== Using Deno
244

3-
[TIP]
4-
====
5-
**AI-Assisted Install:** Just tell any AI assistant: +
6-
`Set up {{PROJECT_NAME}} from https://{{FORGE}}/{{OWNER}}/{{REPO}}` +
7-
The AI reads this repo, asks you a few questions, and handles everything. See <<ai-install,details below>>.
8-
====
45+
[source,bash]
46+
----
47+
deno add npm:rescript-vite
48+
----
49+
50+
=== Using npm (where Deno is not available)
51+
52+
[source,bash]
53+
----
54+
npm install rescript-vite
55+
----
956

10-
== This is your repo - don't forget to rename me!
57+
=== Peer dependencies
1158

12-
== ABI/FFI Standards (Hyperpolymath Universal Standard)
59+
rescript-vite expects these as peer dependencies:
1360

14-
**All repos with foreign function interfaces MUST follow this standard:**
61+
* `rescript` ^12.0.0
62+
* `@rescript/core` ^1.0.0
63+
* `vite` ^6.0.0
1564

16-
* **ABI (Application Binary Interface)** → **Idris2** (`src/abi/*.idr`)
17-
** Type definitions with dependent type proofs
18-
** Memory layout verification
19-
** Platform-specific ABIs with compile-time selection
20-
** Formal verification of interface correctness
65+
== Usage
2166

22-
* **FFI (Foreign Function Interface)** → **Zig** (`ffi/zig/src/*.zig`)
23-
** C-compatible function implementations
24-
** Zero-cost abstractions
25-
** Memory-safe by default
26-
** Cross-compilation support
67+
=== Basic setup
68+
69+
[source,javascript]
70+
----
71+
// vite.config.js
72+
import rescriptPlugin from "rescript-vite";
73+
74+
export default {
75+
plugins: [rescriptPlugin()],
76+
};
77+
----
78+
79+
=== With options
80+
81+
[source,javascript]
82+
----
83+
// vite.config.js
84+
import { make } from "rescript-vite";
85+
86+
export default {
87+
plugins: [
88+
make({
89+
useDeno: true,
90+
logLevel: "verbose",
91+
compilerFlags: ["-warn-error", "+a"],
92+
}),
93+
],
94+
};
95+
----
2796

28-
* **Generated C Headers** → Auto-generated from Idris2 ABI (`generated/abi/*.h`)
29-
** Bridge between Idris2 and Zig
30-
** Consumed by any language via C ABI
97+
=== With BoJ build orchestration
3198

32-
**Directory Structure:**
99+
[source,javascript]
33100
----
34-
project/
35-
├── src/abi/ # Idris2 ABI definitions (REQUIRED)
36-
├── ffi/zig/ # Zig FFI implementation (REQUIRED)
37-
├── generated/abi/ # Auto-generated C headers
38-
└── bindings/ # Language-specific wrappers (optional)
101+
// vite.config.js
102+
import { make } from "rescript-vite";
103+
104+
export default {
105+
plugins: [
106+
make({
107+
boj: true,
108+
bojEndpoint: "http://localhost:7077/mcp/ssg",
109+
logLevel: "info",
110+
}),
111+
],
112+
};
39113
----
40114

41-
**See:** `ABI-FFI-README.md` for complete documentation
115+
When `boj: true` is set, the plugin probes the BoJ ssg-mcp endpoint at
116+
build start. If the server is reachable, production builds are delegated to
117+
it. If unreachable, the plugin falls back to direct compiler invocation.
118+
119+
== API Reference
120+
121+
=== `make(options?)`
122+
123+
Creates a Vite plugin instance. Returns a standard Vite plugin object with
124+
`name: "rescript-vite"` and `enforce: "pre"`.
42125

43-
== AI Gatekeeper Protocol (MANDATORY)
126+
==== Options
44127

45-
**CRITICAL:** All repos MUST include an AI manifest.
128+
[cols="1,1,2,1"]
129+
|===
130+
|Option |Type |Description |Default
46131

47-
* **File:** `0-AI-MANIFEST.a2ml` (included in this template)
48-
* **Purpose:** Universal entry point for ALL AI agents (Claude, Gemini, OpenAI, etc.)
49-
* **Location:** Repository root (alphabetically first)
50-
* **Customize:** Update `[YOUR-REPO-NAME]` placeholders and repository structure section
132+
|`boj`
133+
|`boolean`
134+
|Enable BoJ ssg-mcp build orchestration. The plugin probes the endpoint
135+
at build start and falls back to direct compilation if unavailable.
136+
|`false`
51137

52-
**The manifest declares:**
138+
|`bojEndpoint`
139+
|`string`
140+
|URL of the BoJ ssg-mcp cartridge endpoint.
141+
|`http://localhost:7077/mcp/ssg`
53142

54-
* Canonical file locations (e.g., "machine-readable files ONLY in `.machine_readable/`")
55-
* Critical invariants (rules that must NEVER be violated)
56-
* Repository structure and organization
57-
* Lifecycle hooks (on-enter, on-exit) for session logging
143+
|`useDeno`
144+
|`boolean`
145+
|Use Deno to run the ReScript compiler (`deno run -A npm:rescript`).
146+
|Auto-detected
58147

59-
**Benefits:**
148+
|`rescriptBin`
149+
|`string`
150+
|Path to the rescript binary. When set, the plugin invokes this binary
151+
directly instead of using `npx`.
152+
|`undefined` (uses `npx`)
60153

61-
* ✅ Prevents duplicate file errors (e.g., machine-readable files in wrong locations)
62-
* ✅ Context preserved across sessions and AI platforms
63-
* ✅ No repeated explanations - mechanical enforcement
64-
* ✅ Works universally (not just Claude)
154+
|`compilerFlags`
155+
|`string[]`
156+
|Extra flags passed to the ReScript compiler.
157+
|`[]`
65158

66-
**See:** link:https://github.com/{{OWNER}}/0-ai-gatekeeper-protocol[AI Gatekeeper Protocol] for details
159+
|`logLevel`
160+
|`"silent" \| "info" \| "verbose"`
161+
|Controls console output verbosity.
162+
|`"info"`
163+
|===
67164

68-
**Enforcement:**
165+
=== Default export
69166

70-
* MCP server (mcp-repo-guardian) - Hard enforcement for Claude
71-
* FUSE wrapper (repo-guardian-fs) - Universal enforcement (coming soon)
72-
* CI/CD validation - Continuous compliance checking
167+
The module's default export is a plugin instance created with default options:
73168

74-
== TOPOLOGY.md (Architecture Map)
169+
[source,javascript]
170+
----
171+
import rescriptPlugin from "rescript-vite";
172+
// Equivalent to: make()
173+
----
75174

76-
Every repo should include a `TOPOLOGY.md` in its root — an ASCII architecture diagram combined with a completion dashboard. This gives any contributor (human or AI) an instant picture of the whole project.
175+
=== `rescript-vite/boj` (BojBridge)
77176

78-
* **Template:** `TOPOLOGY.md` (included in this template)
79-
* **Guide:** `docs/TOPOLOGY-GUIDE.adoc` (includes AI prompt for generation, conventions, batch rollout)
80-
* **Sections:** System Architecture (ASCII diagram), Completion Dashboard (progress bars), Key Dependencies (critical path)
177+
The BoJ bridge is available as a separate export for direct use:
81178

82-
See `docs/TOPOLOGY-GUIDE.adoc` for how to generate bespoke TOPOLOGY.md files for existing repos using an AI agent.
179+
[source,javascript]
180+
----
181+
import { make, probe, requestBuild, recentEvents, disconnect } from "rescript-vite/boj";
83182
84-
== AI CLI standards
183+
const bridge = make("http://localhost:7077/mcp/ssg");
184+
const connected = await probe(bridge);
185+
----
85186

86-
- **FIRST:** Customize `0-AI-MANIFEST.a2ml` for your repo before any other work
87-
- All machine-readable content lives in `.machine_readable/` — state files (`*.a2ml`), `anchors/`, `bot_directives/`, `contractiles/`, and `ai/`.
88-
- Include `.machine_readable/` structure from this template in new repos.
187+
==== BojBridge API
89188

90-
== Directory Structure Policy (Owner Override)
189+
* `make(endpoint?)` -- Create a bridge instance (disconnected by default).
190+
* `probe(bridge)` -- Attempt to connect; returns `true` on success.
191+
* `isConnected(bridge)` -- Check connection state.
192+
* `requestBuild(bridge, request)` -- Send a build request via JSON-RPC.
193+
* `recentEvents(bridge, limit?)` -- Get recent telemetry events (default limit: 20).
194+
* `disconnect(bridge)` -- Disconnect the bridge.
91195

92-
The owner policy for this template family is:
196+
== BoJ Integration
93197

94-
* Keep only essential entry-point files in root.
95-
* Put licensing materials in `licensing/` (retain root `LICENSE` for forge/license detection).
96-
* Put documentation under `docs/` with explicit tracks:
97-
** `docs/theory/`
98-
** `docs/practice/`
99-
** `docs/whitepapers/academic/`
100-
** `docs/whitepapers/industry/`
101-
* Keep test fixtures/outputs under `tests/`.
102-
* Keep AI-agent guidance in `.machine_readable/ai/`.
103-
* Prefer `Containerfile` (not `Dockerfile`) for container builds.
198+
The plugin integrates with the *BoJ (Bundle of Joy)* server's `ssg-mcp`
199+
cartridge. BoJ is a multi-cartridge build orchestration system; the ssg-mcp
200+
cartridge handles static site generation and ReScript compilation with:
104201

105-
== Maintenance Gate (Release)
202+
* *Build caching* -- avoids redundant recompilation when source files
203+
have not changed.
204+
* *Telemetry* -- records build events (duration, file count, cache hit rate,
205+
diagnostic count) for monitoring and analysis.
206+
* *MCP protocol* -- communicates via JSON-RPC 2.0 over HTTP, calling the
207+
`tools/call` method with the `ssg_build` tool name.
106208

107-
This template includes a maintenance workflow that is intended to be a release gate.
209+
When `boj: true` is set:
108210

109-
- Scripted audit: `scripts/maintenance/run-maintenance.sh`
110-
- Permission lock/restore helper: `scripts/maintenance/perms-state.sh`
111-
- Checklist: `docs/maintenance/MAINTENANCE-CHECKLIST.md`
211+
1. On `buildStart`, the plugin probes `{bojEndpoint}/health`.
212+
2. If healthy, production builds are sent as `ssg_build` requests.
213+
3. If the BoJ request fails, the plugin falls back to direct `rescript build`.
214+
4. Telemetry events are recorded in the bridge for later inspection.
112215

113-
Recommended release flow:
216+
== Development
217+
218+
=== Build
114219

115220
[source,bash]
116221
----
117-
just maint-audit
118-
just maint-hard-pass
222+
deno task res:build
119223
----
120224

121-
Permission policy is audit-first by default. Use `just perms-lock` only when intentionally hardening local modes, and `just perms-restore` to restore your previous local permission state.
122-
123-
[[ai-install]]
124-
== AI-Assisted Installation
225+
=== Test
125226

126-
**You don't need to read this README to get started.** Just say this to any AI:
127-
128-
[source,text]
227+
[source,bash]
129228
----
130-
Set up {{PROJECT_NAME}} from https://{{FORGE}}/{{OWNER}}/{{REPO}}
229+
deno task test
131230
----
132231

133-
The URL is the spec. The AI fetches this repo, reads `docs/AI_INSTALLATION_GUIDE.adoc`, and handles everything -- prerequisites, build, config, verification. You answer a few questions and confirm the privacy notice. No commands, no installers, no forms.
232+
=== Benchmarks
134233

135-
If the AI already knows this project, shorter prompts work too. If it doesn't, the URL gives it everything.
234+
[source,bash]
235+
----
236+
deno bench --no-check --allow-all tests/bench_test.js
237+
----
136238

137-
**For developers:** Fill in `docs/AI_INSTALLATION_GUIDE.adoc` with your project-specific install recipe. Paste the highlight box from `docs/AI-INSTALL-README-SECTION.adoc` into your README. Run `just validate-ai-install` to check completeness. finishbot verifies this pre-release.
239+
== License
138240

139-
The normal installation instructions remain below for anyone who prefers to do things manually.
241+
PMPL-1.0-or-later (Palimpsest License).
140242

141-
== Standard Dependencies (Optional)
243+
See link:LICENSE[LICENSE] for the full text.
142244

143-
Add your project's standard dependencies here. Remove or customize this section
144-
for your ecosystem.
245+
== Author
145246

146-
// Example:
147-
// [cols="1,2,1"]
148-
// |===
149-
// |Library |Purpose |Status
150-
//
151-
// |your-library
152-
// |Description
153-
// |Required / Recommended / Optional
154-
// |===
247+
Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"tasks": {
3+
"res:build": "deno run -A npm:rescript build",
4+
"res:clean": "deno run -A npm:rescript clean",
5+
"res:watch": "deno run -A npm:rescript build -w",
6+
"test": "deno test --no-check --allow-all tests/"
7+
},
8+
"nodeModulesDir": "auto",
9+
"imports": {
10+
"rescript": "npm:rescript@^12.0.0",
11+
"@rescript/core": "npm:@rescript/core@^1.6.0",
12+
"@rescript/runtime": "npm:@rescript/runtime@^12.0.0"
13+
}
14+
}

0 commit comments

Comments
 (0)