Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d94fc3e
test(docs): reverse export-coverage — every public runtime export doc…
Jul 24, 2026
f297b28
test(docs): docExample() runs documented examples for real; first CI …
Jul 24, 2026
dfd23d1
feat(docs): copy button on every code block + hero installs via bun c…
Jul 24, 2026
fc70ff9
docs(examples): shop & i18n READMEs; snippet check now covers example…
Jul 24, 2026
5cb2899
feat(docs): Examples page + nav links and per-guide example cross-links
Jul 24, 2026
99ce22f
feat(create-janux): --example <name> scaffolds any examples/ app from…
Jul 24, 2026
aa76296
refactor(create-janux): list examples via withFileTypes directory check
Jul 24, 2026
346f9bb
test(agent): pg probe recognizes Bun's refused-connection error so CI…
Jul 24, 2026
75dca34
feat(docs): Next.js-style landing + mission statement + mobile fixes
Jul 24, 2026
3a0b9e1
feat(docs): mission pillars (write/review/operate) + code-block actio…
Jul 24, 2026
821ae52
docs(interop): example uses the identifier it imports (ReactFlow) and…
Jul 24, 2026
c75efc4
fix(docs): TOC entries decode HTML entities — no more &amp;amp; in On…
Jul 24, 2026
fd98ad7
docs(navigation): show the base case — a plain <a href> is the router
Jul 24, 2026
fe64462
fix(client): SPA navigation never corrupts pages with imperative-DOM …
Jul 24, 2026
1501d56
chore(deps): diff-dom-streaming 0.6.7 (stream-walker robustness fixes)
Jul 24, 2026
08963df
docs(wave-a): getting-started section + one reference page per reacti…
Jul 24, 2026
90b7ea7
docs(wave-a): the complete JSX prop surface + keys, both executable
Jul 24, 2026
83a52d8
docs(wave-b): data-cache and foreign() reference pages; backlog down …
Jul 24, 2026
93f468d
docs(wave-b): client-state and client-runtime reference; janux/client…
Jul 24, 2026
049a789
docs(wave-c): the agent harness, six reference pages; backlog 41 → 22
Jul 24, 2026
7080fc1
docs(wave-c): i18n, build internals and client tools — export backlog…
Jul 24, 2026
8e83448
docs(tutorial): stop claiming create-janux ships the task board
Jul 24, 2026
f86f31d
fix(docs): CSS glyphs survive any charset guess (mojibake in the side…
Jul 24, 2026
bee0f5d
docs(wave-d): forms recipe — and the executable test caught it lying
Jul 24, 2026
fb344ec
fix(vite): dev shell links the stylesheet as CSS, not as a JS module
Jul 24, 2026
0cf12b8
test(docs): guard the second axis — pages whose examples must be EXEC…
Jul 24, 2026
182d11b
docs(readme): Documentation section on the new IA; mark the old plan'…
Jul 24, 2026
aefc40a
docs(wave-d): optimistic-ui recipe, executed end to end
Jul 24, 2026
2ed3dc8
docs(wave-d): error-handling recipe — three surfaces, all executed
Jul 24, 2026
decf10a
docs(wave-d): custom-server recipe, and the export that makes it honest
Jul 24, 2026
350b4b9
docs(guide): data-cache lied about setQueryData — the test says so now
Jul 24, 2026
7c47d57
fix(core): every().orOn().orOn() — the docs promised chaining that threw
Jul 24, 2026
ea13ba5
docs(more): comparison — Brisa/SvelteKit/Nuxt/SolidStart, and React i…
Jul 24, 2026
00ce7a6
test(docs): third axis — every link resolves, and the audit it caught
Jul 24, 2026
2ec1ae0
refactor(docs-tests): order-independent page tests, and one file unde…
Jul 24, 2026
cb3acdc
docs(readme): the test badge said 300+ when it's 630+, and there are …
Jul 24, 2026
e3ded1b
fix(vite): janux build no longer needs React to be installed
Jul 24, 2026
97449d9
docs(wave-d): docker and monorepo recipes, both built and run for real
Jul 24, 2026
f9935c8
fix(server): the copilot loop ran confirm-guarded api() tools without…
Jul 24, 2026
ca79464
docs(wave-d): agent-evals-in-ci — three layers, all three executed
Jul 24, 2026
7be559b
feat(config): src/ctx.ts — the auth convention the docs already promised
Jul 24, 2026
a6ec554
docs(wave-d): refresh the 8 existing recipes, the tutorial, faq and g…
Jul 24, 2026
3755464
fix(static): a static export stops advertising endpoints it does not …
Jul 24, 2026
4e42512
fix(client): urlState no longer crashes SSR, and data-cache finally u…
Jul 24, 2026
591bd67
fix(signals): watch() treated any return value as a cleanup
Jul 24, 2026
2937d62
fix(persist): a payload from another version is dropped, as documented
Jul 24, 2026
aa0a2a3
test(signals): express the implicit-return footgun as a JS caller wri…
Jul 24, 2026
0cef914
test(docs): execute schema, components, api-rpc and http-handlers pages
Jul 24, 2026
2575ebb
test(docs): execute the i18n and interop pages
Jul 24, 2026
d9c37c6
test(docs): execute the five agent-harness pages, and fix a wrong sig…
Jul 24, 2026
858654e
test(docs): the untested-pages backlog is empty — every page now runs
Jul 24, 2026
5eef229
refactor(docs-tests): one serveIntoDom fixture instead of three copies
Jul 24, 2026
1eedee3
docs(readme): the test counts, measured
Jul 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install --frozen-lockfile
- run: bun run test
- run: bun run typecheck
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<p align="center">
<a href="https://www.npmjs.com/package/janux"><img src="https://img.shields.io/npm/v/janux" alt="npm version" /></a>
<a href="https://www.npmjs.com/package/janux"><img src="https://img.shields.io/npm/dm/janux" alt="npm downloads" /></a>
<img src="https://img.shields.io/badge/tests-300%2B%20passing-brightgreen" alt="300+ tests passing" />
<img src="https://img.shields.io/badge/tests-850%2B%20passing-brightgreen" alt="850+ tests passing" />
<img src="https://img.shields.io/badge/runtime-Bun-14151a?logo=bun&logoColor=white" alt="Bun" />
<img src="https://img.shields.io/badge/compiler-Vite%20%2B%20SWC-646cff?logo=vite&logoColor=white" alt="Vite + SWC" />
<img src="https://img.shields.io/badge/TypeScript-first-3178c6?logo=typescript&logoColor=white" alt="TypeScript" />
Expand Down Expand Up @@ -145,20 +145,20 @@ Zero config — first match wins:

## Documentation

The docs site is **built with Janux itself** — polished light/dark theme, ⌘K full-text search, an interactive playground, `llms.txt` for agents, and an "Ask AI" copilot running on the same agent bridge every Janux app gets:
**[janux.dev docs](https://github.com/aralroca/Janux/tree/main/apps/docs)** — 74 pages, ⌘K search, dark mode, and a copilot that answers from the docs themselves.

<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="docs/docs-dark.png" />
<img src="docs/docs-light.png" width="720" alt="The Janux docs site: topbar with search, grouped sidebar, Janus engraving hero" />
</picture>
</p>
| Section | Start here |
|---|---|
| **Getting started** | [What is Janux?](apps/docs/content/getting-started/what-is-janux.md) · [Quick start](apps/docs/content/getting-started/quick-start.md) · [Mental model](apps/docs/content/getting-started/mental-model.md) |
| **Guide** | [Components](apps/docs/content/guide/components.md) · [Views and JSX](apps/docs/content/guide/views-and-jsx.md) · [Intents and guards](apps/docs/content/guide/intents-and-guards.md) · [Navigation](apps/docs/content/guide/navigation.md) · [The agent and your copilot](apps/docs/content/guide/agent-and-copilot.md) |
| **Tutorial** | [A task board with two faces](apps/docs/content/tutorial/tasks-app-part-1.md) (3 parts) |
| **Reference** | one page per export: [reactivity](apps/docs/content/reference/signal.md), [client](apps/docs/content/reference/client-state.md), [data cache](apps/docs/content/reference/data-cache-api.md), [agent harness](apps/docs/content/reference/agent-memory.md), [CLI](apps/docs/content/reference/cli.md) |
| **Recipes** | [Testing components](apps/docs/content/recipes/testing-components.md) · [Forms](apps/docs/content/recipes/forms.md) · [Optimistic UI](apps/docs/content/recipes/optimistic-ui.md) · [Error handling](apps/docs/content/recipes/error-handling.md) · [Custom server](apps/docs/content/recipes/custom-server.md) · [Docker](apps/docs/content/recipes/docker.md) · [Monorepo](apps/docs/content/recipes/monorepo-setup.md) · [Tailwind](apps/docs/content/recipes/tailwind.md) · [Local model copilot](apps/docs/content/recipes/local-model-copilot.md) |
| **More** | [Examples](apps/docs/content/more/examples.md) · [Comparison](apps/docs/content/more/comparison.md) · [FAQ](apps/docs/content/more/faq.md) · [Glossary](apps/docs/content/more/glossary.md) |

```bash
bun run --cwd apps/docs dev
```
Agents read the same docs at `/llms.txt` and any page as Markdown by appending `.md`.

Sources in [`apps/docs/content`](apps/docs/content), organized as **Guide** (components & state, rendering & navigation, server & agents, shipping), **Tutorial** (a task board in 3 parts), **Reference** (per-package APIs & CLI), **Recipes** and **More**.
**Every example is verified.** `packages/docs-tests` compiles every snippet, checks it imports only symbols the packages really export, runs the main example of a page and asserts what the prose claims. Three guards fail the build when an export has no reference page, when a page's executable claims aren't executed, or when any documented link stops resolving. **Both backlogs are empty**: every public export is documented, and every page that imports the framework has a test that runs it.

## Examples

Expand All @@ -177,7 +177,7 @@ bun run --cwd examples/i18n dev

```bash
bun install
bun test packages # 300+ tests: schema, signals, runtime, SSR, resume, morph, interop, router, cache, guards, agent loop, harness, SWC stubs
bun test packages # 820+ tests: schema, signals, runtime, SSR, resume, morph, interop, router, cache, guards, agent loop, harness, SWC stubs
bun run typecheck
```

Expand Down
72 changes: 72 additions & 0 deletions apps/docs/content/getting-started/editor-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Editor setup

`bun create janux` writes all of this for you. This page is what to do when you're adding Janux to an existing project — or when JSX suddenly types as `any`.

## tsconfig.json

```json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "bundler",
"strict": true,
"skipLibCheck": true,
"types": ["bun"],
"noEmit": true,
"jsx": "react-jsx",
"jsxImportSource": "janux"
},
"include": ["src/**/*"]
}
```

The two lines that matter:

- **`"jsx": "react-jsx"`** — the automatic runtime. No `import { jsx }` in your files.
- **`"jsxImportSource": "janux"`** — JSX resolves to Janux's runtime, not React's. Get this wrong and every element types as `any` while still *running* fine, which is the confusing failure mode.

`"moduleResolution": "bundler"` lets TypeScript follow the package's `exports` map (`janux/client`, `janux/interop`, `janux/query`…).

## Per-file React override

A file that must render with React (a component you mount via [`foreign()`](/docs/guide/interop)) opts out with a pragma — everything else in the project keeps the Janux runtime:

```tsx
/** @jsxImportSource react */
export function Mixer({ band, onBand }: Props) {
return <input type="range" value={band} onChange={(event) => onBand(Number(event.target.value))} />;
}
```

## VS Code

No extension is required. Two settings help:

```json
{
"typescript.tsdk": "node_modules/typescript/lib",
"editor.formatOnSave": true
}
```

Using the workspace TypeScript matters when your global version is older than the project's — Janux's types rely on recent inference.

## Typechecking in CI

```bash
bunx tsc --noEmit
```

Pair it with [`janux verify`](/docs/reference/cli), which fails the build when an agent-reachable `intent()` or `api()` has no `description` — an incomplete agent contract is a bug types can't catch.

## Troubleshooting

| Symptom | Cause |
|---|---|
| JSX elements are `any`, no autocomplete | `jsxImportSource` missing or set to `react` |
| `Cannot find module 'janux/client'` | `moduleResolution` isn't `bundler` (or `node16`+) |
| `Property 'on' does not exist` on an element | the file is compiling with React's JSX types — check the pragma |
| Intent bag fields type as `any` | `strict` is off, or `state` was written without `schema()` |

Next: [Components](/docs/guide/components) · [Schema types](/docs/guide/schema)
68 changes: 68 additions & 0 deletions apps/docs/content/getting-started/mental-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Mental model

Four ideas carry the whole framework. Learn these and the rest of the docs is detail.

## 1. One definition, three projections

A `component({...})` is not a function that returns markup. It's a **declaration** the runtime projects three ways:

| Projection | Who consumes it | Where it shows up |
|---|---|---|
| **View** | Humans | Server-rendered HTML, resumed on interaction |
| **Resource** | Agents (read) | `ui://counter` — plain JSON state + derived |
| **Tools** | Agents *and* humans | `counter.inc` with JSON Schema input + guard |

The view is a *projection*, not the source of truth — which is why adding an intent instantly gives agents a new capability, and why the two audiences can never diverge.

## 2. State is typed, and only intents mutate it

State is declared with [`schema`](/docs/reference/schema-api), not inferred from initial values. Every mutation goes through a named [`intent`](/docs/guide/intents-and-guards) whose input is validated — there is no `setState` you can call from anywhere.

```tsx
state: schema({ count: int() }),
intents: {
inc: intent({ input: schema({ by: int().default(1) }), run: ({ state, input }) => (state.count += input.by) }),
},
```

That restriction is what buys the agent surface: every state transition is named, validated, guarded and auditable — identical whether a human clicked or a model called. Direct writes outside a `run()` throw.

**Corollary:** `run()` receives everything it needs in its bag (`state`, `input`, `ctx`, `emit`, `use`). It must not close over outer variables to mutate state — the definition has to be fully describable, or the projection would lie.

## 3. Islands resume; they don't hydrate

A page is server-rendered HTML. Components with state become **islands**: their state is serialized as a JSON snapshot, and the component's code loads *on first interaction*, restoring from that snapshot. Nothing re-renders on load, no closure is serialized, no effect is replayed. A page with no islands ships **0 KB** of JavaScript.

Mark an island `eager` when it must be live on arrival (an editor, an event listener), and `persist` when its live instance must survive navigation.

## 4. Guards are the contract with agents

Each intent (and each `api()`) declares who may run it and whether a human must approve:

| Guard | Human | Agent |
|---|---|---|
| `auto` (default) | runs | runs |
| `confirm` | runs | returns a **proposal** a human approves |
| `forbidden` | runs | rejected |

Guards resolve per request origin, server-side. This is how you let a copilot fill a cart but never check out unattended.

## Where things live

**Islands are ephemeral, stores and the server are durable.** State that must outlive a navigation belongs in a [store](/docs/guide/stores) (or on the server), not in a route island. Put it there and it survives; leave it in a route island and it re-resumes fresh from the incoming page — by design, not by accident.

## Coming from React?

| React | Janux |
|---|---|
| `useState` + setters | `state: schema({...})` + `intents` |
| `useMemo` / derived render | `derived: { total: (s) => ... }` |
| `useEffect` + deps array | `effect({ when: (s) => s.items, debounce: '300ms', run })` |
| Context / a store library | `store({ name, scope: 'app' })` + `use: { theme }` |
| Data fetching hooks | `source({ query, refresh: every('5m') })` or [`useQuery`](/docs/guide/data-cache) |
| `<Link>` | a plain `<a href>` — [navigation](/docs/guide/navigation) is automatic |
| An MCP integration you write | generated |

Real React components still work — mount them unchanged with [`foreign()`](/docs/guide/interop) when you need the ecosystem.

Next: [Editor setup](/docs/getting-started/editor-setup) · [Components](/docs/guide/components)
72 changes: 72 additions & 0 deletions apps/docs/content/getting-started/project-structure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Project structure

Janux is convention over configuration: every path below is **optional** and discovered by existence. Create the file and the feature turns on — there is nothing to register.

```
my-app/
src/
routes/ # file-system routes: index.tsx → /, orders/[id].tsx → /orders/:id
components/ # your components (static, islands, stores)
server/ # *.api.ts — server functions that double as agent tools
api/ # arbitrary HTTP handlers: src/api/upload.ts → POST /api/upload
client.ts # boot({ defs: [...] }) — the client entry
agent.ts # defineAgent({...}) — the copilot
stores.ts # exported store defs, so SSR can render store-dependent views
ctx.ts # (req) => ctx — per-request context: session, tenant, role
middleware.ts # runs before routing on every request
matchers.ts # custom typed route params: [post=slug]
i18n.ts # or src/i18n/index.ts — locales, messages, routing
styles.css # the app stylesheet, injected into the HTML shell
public/
favicon.svg # served and linked automatically
janux.config.ts # optional: title, output, llms.txt, path overrides
tsconfig.json
```

## What each convention does

| Path | Turns on | Details |
|---|---|---|
| `src/routes/**` | Routing, layouts (`_layout.tsx`), groups (`(name)/`), dynamic and typed segments | [Navigation](/docs/guide/navigation) |
| `src/server/*.api.ts` | `api()` RPC endpoints, auto-published as agent tools | [api() as agent tools](/docs/guide/api-rpc) |
| `src/api/**` | Raw HTTP handlers by exported method (`export function POST`) and uploads | [HTTP handlers](/docs/guide/http-handlers) |
| `src/client.ts` | The client runtime (`boot`). Omit it for a zero-JS site | [SSR and resumability](/docs/guide/ssr-and-resumability) |
| `src/agent.ts` | The copilot at `/_janux/agent` + the embedded harness | [The agent and your copilot](/docs/guide/agent-and-copilot) |
| `src/stores.ts` | Server-side store instances per request, so SSR can render views that read them | [Stores](/docs/guide/stores) |
| `src/ctx.ts` | The per-request `ctx` every route, intent, source and `api()` receives | [Auth and request context](/docs/recipes/auth-and-context) |
| `src/middleware.ts` | A request hook before routing — redirects, auth gates, locale hardening | [Navigation § Middleware](/docs/guide/navigation) |
| `src/matchers.ts` | Custom param matchers (each export is `(value: string) => boolean`) | [Navigation § The route tree](/docs/guide/navigation) |
| `src/i18n.ts` | Locale-prefixed routing, typed `t()`, page-scoped client messages | [i18n](/docs/guide/i18n) |
| `src/styles.css` | Stylesheet link in the HTML shell (Tailwind works here) | [Tailwind recipe](/docs/recipes/tailwind) |
| `public/favicon.svg` | Favicon link in the shell | — |

## What the starter ships

`bun create janux my-app` gives you the smallest app that shows both faces:

- `src/components/Counter.tsx` — a bifacial island: schema state, an intent with a description, a view. This is the piece agents can read *and* drive.
- `src/components/AgentPanel.tsx` — the copilot UI, talking to `/_janux/agent`.
- `src/routes/index.tsx` — the page, with `meta` for title and description.
- `src/client.ts` — `boot({ defs: [Counter] })`.
- `src/components/Counter.test.ts` — a unit test driving intents through the real pipeline.

## Overriding the layout

`janux.config.ts` takes the same options as the Vite plugin:

```ts
import { defineConfig } from 'janux';

export default defineConfig({
title: 'My app',
output: 'static', // 'bun' (default) | 'static'
routesDir: 'src/pages', // if you dislike the defaults
serverDir: 'src/rpc',
clientEntry: 'src/entry.ts',
llmsTxt: { title: 'My app', description: 'What it does' },
});
```

Edits are picked up live in dev. A `"janux"` field in `package.json` still works as a fallback, but `janux.config.ts` wins.

Next: [Mental model](/docs/getting-started/mental-model) · [Editor setup](/docs/getting-started/editor-setup)
80 changes: 80 additions & 0 deletions apps/docs/content/getting-started/quick-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Quick start

## Create an app

```bash
bun create janux my-app
cd my-app
bun install
bun run dev
```

`bunx create-janux my-app` is the same command. Prefer starting from a complete app? Any [example](/docs/more/examples) works as a template:

```bash
bun create janux my-shop --example shop
```

**Requirements:** [Bun](https://bun.sh) ≥ 1.3. No other global tooling.

## What the dev server gives you

```
janux dev ready
→ app: http://localhost:3000/
→ manifest: http://localhost:3000/_janux/manifest
→ agent: http://localhost:3000/_janux/agent
```

Open the app: a counter island and an agent panel. Then open the **manifest** — that JSON is your app as an agent sees it, generated from the same components. The two views are never out of sync because there is only one definition.

```bash
curl localhost:3000/_janux/manifest
```

## Make your first change

Edit `src/components/Counter.tsx` and add an intent:

```tsx
intents: {
inc: intent({
description: 'Increment the counter',
input: schema({ by: int().default(1) }),
run: ({ state, input }) => (state.count += input.by),
}),
double: intent({
description: 'Double the counter',
run: ({ state }) => (state.count *= 2),
}),
},
```

Save. Three things happen at once: the view hot-reloads, `counter.double` appears in the manifest, and the copilot can call it — no registration, no schema written twice.

## Turn on the copilot

The agent panel needs a model. Set **one** environment variable:

```bash
# option 1: pick the model explicitly
JANUX_MODEL="anthropic/claude-fable-5" bun run dev

# option 2: just give it a provider key and let it choose
ANTHROPIC_API_KEY=sk-... bun run dev
```

Also supported: `OPENAI_API_KEY`, `GOOGLE_GENERATIVE_AI_API_KEY`, `OPENROUTER_API_KEY`. Resolution order is `defineAgent({ model })` → `JANUX_MODEL` → provider-key sniffing → a setup card. Without any of them the app still boots and tells you exactly which variable to set.

Now ask the copilot *"double the counter twice"* and watch the view update — the agent called the same intent your button calls.

## Ship it

```bash
bun run build # bundles client assets
bun run start # production server on Bun
```

Apps with no islands (or `"output": "static"`) build to a folder of HTML you can host anywhere — see [CLI and deployment](/docs/guide/cli-and-deployment).

Next: [Project structure](/docs/getting-started/project-structure) · [Mental model](/docs/getting-started/mental-model)
Loading
Loading