caspian-utils 0.0.2 → 0.0.4
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/dist/docs/components.md +269 -0
- package/dist/docs/index.md +13 -7
- package/dist/docs/project-structure.md +38 -4
- package/dist/docs/pulsepoint.md +20 -9
- package/dist/docs/routing.md +67 -2
- package/package.json +1 -1
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Components
|
|
3
|
+
description: Create reusable Caspian components as `@component` Python functions, import them into templates as `<MyComponent />`, and split interactive UI into same-name HTML templates when PulsePoint logic is involved.
|
|
4
|
+
related:
|
|
5
|
+
title: Related docs
|
|
6
|
+
description: Use the structure guide for file placement, the routing guide for route templates, the PulsePoint guide for browser-side scripts, and the data guide for component-owned RPC flows.
|
|
7
|
+
links:
|
|
8
|
+
- /docs/project-structure
|
|
9
|
+
- /docs/routing
|
|
10
|
+
- /docs/pulsepoint
|
|
11
|
+
- /docs/fetch-data
|
|
12
|
+
- /docs/index
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
Components in Caspian are Python functions decorated with `@component`.
|
|
16
|
+
|
|
17
|
+
Import them into a template with an `@import` comment, then render them with JSX-style tags such as `<MyComponent />` or `<MyComponent>...</MyComponent>`.
|
|
18
|
+
|
|
19
|
+
For the current workspace, component tooling scans Python files under the paths listed in `caspian.config.json`. Right now that means `src/`, so `src/components/` is the clean default location for reusable UI, even though any scanned path under `src/` can work.
|
|
20
|
+
|
|
21
|
+
## Mental Model
|
|
22
|
+
|
|
23
|
+
- Use a Python component when you want a reusable server-rendered UI building block.
|
|
24
|
+
- Return an HTML string directly for small presentational components.
|
|
25
|
+
- Use `render_html(...)` with a same-name `.html` file when the component has more markup, PulsePoint behavior, or clearer separation between Python logic and UI.
|
|
26
|
+
- Keep page-level workflows in `src/app/`, and move reusable UI into components.
|
|
27
|
+
|
|
28
|
+
## Basic Component
|
|
29
|
+
|
|
30
|
+
This is the simplest pattern: accept props, merge classes or attributes, and return HTML.
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from casp.component_decorator import component
|
|
34
|
+
from casp.html_attrs import get_attributes, merge_classes
|
|
35
|
+
|
|
36
|
+
@component
|
|
37
|
+
def Container(children: str = "", **props) -> str:
|
|
38
|
+
incoming_class = props.pop("class", "")
|
|
39
|
+
final_class = merge_classes("mx-auto max-w-7xl px-4", incoming_class)
|
|
40
|
+
|
|
41
|
+
attributes = get_attributes({
|
|
42
|
+
"class": final_class,
|
|
43
|
+
}, props)
|
|
44
|
+
|
|
45
|
+
return f'<div {attributes}>{children}</div>'
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Notes:
|
|
49
|
+
|
|
50
|
+
- `children` receives the inner content passed between opening and closing tags.
|
|
51
|
+
- `**props` lets the component accept additional HTML attributes such as `id`, `data-*`, and `aria-*`.
|
|
52
|
+
- The runtime normalizes `class`, `className`, and `class_name` into a merged `class` value before the component is called.
|
|
53
|
+
|
|
54
|
+
## Import And Use Components
|
|
55
|
+
|
|
56
|
+
Import components inside the HTML template where they are used.
|
|
57
|
+
|
|
58
|
+
```html
|
|
59
|
+
<!-- @import Container from "../components" -->
|
|
60
|
+
|
|
61
|
+
<Container class="py-10">
|
|
62
|
+
<h1>Dashboard</h1>
|
|
63
|
+
</Container>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The import comment is the bridge between the Python component file and the JSX-style tag.
|
|
67
|
+
|
|
68
|
+
- `<!-- @import Container from "../components" -->` resolves `Container.py` from that folder.
|
|
69
|
+
- The component function name should match the tag name you render, such as `Container` for `<Container />`.
|
|
70
|
+
- Grouped imports and aliases are also supported, for example `<!-- @import { Button, Card as UserCard } from "../components/ui" -->`.
|
|
71
|
+
|
|
72
|
+
## Template-Backed Components
|
|
73
|
+
|
|
74
|
+
When a component includes richer UI or PulsePoint behavior, keep the Python file focused on props or server-side preparation and move the markup into a same-name HTML file.
|
|
75
|
+
|
|
76
|
+
`Counter.py`
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from casp.component_decorator import component, render_html
|
|
80
|
+
|
|
81
|
+
@component
|
|
82
|
+
def Counter(label: str = "Clicks") -> str:
|
|
83
|
+
return render_html(__file__, {
|
|
84
|
+
"label": label,
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`Counter.html`
|
|
89
|
+
|
|
90
|
+
```html
|
|
91
|
+
<div>
|
|
92
|
+
<h3>[[ label ]]</h3>
|
|
93
|
+
<button onclick="setCount(count + 1)">
|
|
94
|
+
{count}
|
|
95
|
+
</button>
|
|
96
|
+
|
|
97
|
+
<script>
|
|
98
|
+
const [count, setCount] = pp.state(0);
|
|
99
|
+
</script>
|
|
100
|
+
</div>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Use this split when:
|
|
104
|
+
|
|
105
|
+
- Python is shaping props, loading data, or exposing server-side helpers.
|
|
106
|
+
- The template has enough markup that returning a raw f-string becomes noisy.
|
|
107
|
+
- PulsePoint state, effects, refs, or event handlers belong next to the component markup.
|
|
108
|
+
|
|
109
|
+
This keeps the component easy to read: Python owns the server-side logic and template context, while the HTML file owns the rendered UI and browser behavior.
|
|
110
|
+
|
|
111
|
+
## Auto-Injected `pp-component` And PulsePoint Script Type
|
|
112
|
+
|
|
113
|
+
Treat `pp-component="componentName"` and `type="text/pp"` as framework output, not authored source.
|
|
114
|
+
|
|
115
|
+
- Do not manually add `pp-component="..."` to route templates, layout templates, or component HTML files.
|
|
116
|
+
- Do not manually add `type="text/pp"` to authored PulsePoint scripts.
|
|
117
|
+
- The Python render pipeline injects `pp-component` onto the single root element during render.
|
|
118
|
+
- `main.py` runs `transform_scripts(...)`, which rewrites authored body `<script>` tags to `<script type="text/pp">` before the browser runtime mounts.
|
|
119
|
+
- Add a plain `<script>` only when the route or component actually needs PulsePoint logic.
|
|
120
|
+
- When you do add a PulsePoint script, keep it inside that single root element.
|
|
121
|
+
|
|
122
|
+
Examples in runtime docs often show rendered HTML that already contains `pp-component` and `type="text/pp"`. That is the final output shape, not the normal authoring pattern.
|
|
123
|
+
|
|
124
|
+
### Authored Source vs Rendered Output
|
|
125
|
+
|
|
126
|
+
Author this:
|
|
127
|
+
|
|
128
|
+
`Counter.html`
|
|
129
|
+
|
|
130
|
+
```html
|
|
131
|
+
<div>
|
|
132
|
+
<h3>[[ label ]]</h3>
|
|
133
|
+
<button onclick="setCount(count + 1)">
|
|
134
|
+
{count}
|
|
135
|
+
</button>
|
|
136
|
+
|
|
137
|
+
<script>
|
|
138
|
+
const [count, setCount] = pp.state(0);
|
|
139
|
+
</script>
|
|
140
|
+
</div>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Do not author this by hand:
|
|
144
|
+
|
|
145
|
+
```html
|
|
146
|
+
<div pp-component="counter_ab12cd34">
|
|
147
|
+
<h3>Clicks</h3>
|
|
148
|
+
<button onclick="setCount(count + 1)">0</button>
|
|
149
|
+
|
|
150
|
+
<script type="text/pp">
|
|
151
|
+
const [count, setCount] = pp.state(0);
|
|
152
|
+
</script>
|
|
153
|
+
</div>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
The second example is the runtime shape after the Python side injects `pp-component` onto the component root.
|
|
157
|
+
|
|
158
|
+
## Single-Root Rule
|
|
159
|
+
|
|
160
|
+
Every component HTML template must render exactly one top-level lowercase HTML element.
|
|
161
|
+
|
|
162
|
+
The same rule applies to route templates such as `src/app/**/index.html`: one root element, no sibling roots, and no manual `pp-component` authoring.
|
|
163
|
+
|
|
164
|
+
This is not just style guidance. The installed compiler injects `pp-component` onto the root element, and it raises an error when the template has no root, multiple sibling roots, stray top-level text, or a component tag as the root.
|
|
165
|
+
|
|
166
|
+
For AI-generated templates, treat this as a hard authoring rule: write the HTML the same way a React component returns one parent element. If the template needs a PulsePoint script, keep that script inside the same parent root.
|
|
167
|
+
|
|
168
|
+
Good:
|
|
169
|
+
|
|
170
|
+
```html
|
|
171
|
+
<div class="card">
|
|
172
|
+
<h2>Title</h2>
|
|
173
|
+
|
|
174
|
+
<script>
|
|
175
|
+
const [open, setOpen] = pp.state(false);
|
|
176
|
+
</script>
|
|
177
|
+
</div>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Bad:
|
|
181
|
+
|
|
182
|
+
```html
|
|
183
|
+
<div class="card">
|
|
184
|
+
<h2>Title</h2>
|
|
185
|
+
</div>
|
|
186
|
+
|
|
187
|
+
<script>
|
|
188
|
+
const [open, setOpen] = pp.state(false);
|
|
189
|
+
</script>
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Also bad:
|
|
193
|
+
|
|
194
|
+
```html
|
|
195
|
+
<h2>Title</h2>
|
|
196
|
+
<p>Body</p>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Also avoid making another component tag the root of the HTML file. The root must be a normal lowercase HTML element such as `<div>`, `<section>`, or `<article>`.
|
|
200
|
+
|
|
201
|
+
Think about this rule the same way you would in a React component: one parent element per template root. In Caspian, that requirement exists so the Python renderer has exactly one place to attach `pp-component`.
|
|
202
|
+
|
|
203
|
+
## Props, Types, And Children
|
|
204
|
+
|
|
205
|
+
Props come from the attributes on the component tag.
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
from typing import Any, Literal
|
|
209
|
+
|
|
210
|
+
from casp.component_decorator import component
|
|
211
|
+
from casp.html_attrs import get_attributes, merge_classes
|
|
212
|
+
|
|
213
|
+
ButtonVariant = Literal["default", "outline", "destructive"]
|
|
214
|
+
|
|
215
|
+
@component
|
|
216
|
+
def Button(
|
|
217
|
+
children: Any = "",
|
|
218
|
+
variant: ButtonVariant = "default",
|
|
219
|
+
**props,
|
|
220
|
+
) -> str:
|
|
221
|
+
classes = {
|
|
222
|
+
"default": "btn btn-primary",
|
|
223
|
+
"outline": "btn btn-outline",
|
|
224
|
+
"destructive": "btn btn-danger",
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
incoming_class = props.pop("class", "")
|
|
228
|
+
attrs = get_attributes({
|
|
229
|
+
"class": merge_classes(classes[variant], incoming_class),
|
|
230
|
+
}, props)
|
|
231
|
+
|
|
232
|
+
return f'<button {attrs}>{children}</button>'
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Use typed parameters when you want better editor hints and stricter component APIs. `Literal[...]` is a good fit for variants, sizes, or other closed sets of values.
|
|
236
|
+
|
|
237
|
+
## Async Components
|
|
238
|
+
|
|
239
|
+
Components can also be async. Use this only when the component render contract really depends on awaited work such as a database query, service call, or file read.
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
from casp.component_decorator import component, render_html
|
|
243
|
+
|
|
244
|
+
@component
|
|
245
|
+
async def ProfileCard(user_id: str) -> str:
|
|
246
|
+
user = await get_user_by_id(user_id)
|
|
247
|
+
|
|
248
|
+
return render_html(__file__, {
|
|
249
|
+
"user": user,
|
|
250
|
+
})
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Keep synchronous components as the default. Switch to `async def` only when the component itself needs awaited I/O.
|
|
254
|
+
|
|
255
|
+
## Best Practices
|
|
256
|
+
|
|
257
|
+
- Put reusable components in `src/components/` and keep route files in `src/app/`.
|
|
258
|
+
- If the component includes PulsePoint behavior, prefer a thin Python wrapper plus a same-name `.html` template.
|
|
259
|
+
- Keep the component file name, exported function name, and tag name aligned, such as `Button.py`, `def Button(...)`, and `<Button />`.
|
|
260
|
+
- Accept `children` or `**props` when the component should support nested content.
|
|
261
|
+
- Keep page-level data loading in `page()` when the data is not intrinsic to the component itself.
|
|
262
|
+
- If you add `@rpc()` functions inside a component file, keep their names globally unique because component RPCs are not route-scoped.
|
|
263
|
+
|
|
264
|
+
## Related Reading
|
|
265
|
+
|
|
266
|
+
- Read [project-structure.md](./project-structure.md) for where reusable components should live.
|
|
267
|
+
- Read [routing.md](./routing.md) when importing components into route templates.
|
|
268
|
+
- Read [pulsepoint.md](./pulsepoint.md) for the runtime contract of `pp-component`, `script[type="text/pp"]`, props, and browser-side reactivity.
|
|
269
|
+
- Read [fetch-data.md](./fetch-data.md) when a component needs browser-triggered `pp.rpc()` calls or component-owned server actions.
|
package/dist/docs/index.md
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Caspian Docs
|
|
3
|
-
description: Caspian documentation with AI-aware routing to the right local docs before framework-specific code generation or project setup changes, with PulsePoint, RPC, and Validate as the default app stack.
|
|
3
|
+
description: Caspian documentation with AI-aware routing to the right local docs before framework-specific code generation or project setup changes, with components, PulsePoint, RPC, and Validate as the default app stack.
|
|
4
4
|
related:
|
|
5
5
|
title: Next Steps
|
|
6
|
-
description: Start with installation, review the CLI commands, then use the structure
|
|
6
|
+
description: Start with installation, review the CLI commands, then use the structure and component guides to place Caspian files correctly.
|
|
7
7
|
links:
|
|
8
8
|
- /docs/installation
|
|
9
9
|
- /docs/commands
|
|
10
10
|
- /docs/project-structure
|
|
11
|
+
- /docs/components
|
|
11
12
|
---
|
|
12
13
|
|
|
13
14
|
This directory contains the local Caspian documentation set for quick reference and AI-aware routing.
|
|
14
15
|
|
|
16
|
+
Before making feature, tooling, or file-placement decisions in a Caspian workspace, read `./caspian.config.json` almost immediately. That file is the project feature gate and tells you which capabilities are enabled, such as Prisma, MCP, TypeScript, Tailwind, backend-only mode, and component scan directories.
|
|
17
|
+
|
|
15
18
|
## Default Stack
|
|
16
19
|
|
|
17
20
|
When generating or editing a Caspian app, treat these as the default choices unless the task explicitly requires something else:
|
|
@@ -36,13 +39,14 @@ The packaged Caspian docs distributed by the current toolchain also live here:
|
|
|
36
39
|
- `commands.md` - Main Caspian CLI workflows for project creation, generation, updates, and config-aware maintenance
|
|
37
40
|
- `database.md` - Prisma schema, migration, seed, and client-generation workflow for the current workspace, plus Python-side helper caveats
|
|
38
41
|
- `auth.md` - Session-backed authentication with `casp.auth`, centralized `auth_config.py`, decorators, RBAC, and OAuth provider helpers
|
|
42
|
+
- `components.md` - Create reusable Python components, template-backed UI, JSX-style imports, and the single-parent root rule for component HTML files
|
|
39
43
|
- `pulsepoint.md` - Default reactive frontend runtime contract for component scripts, state, effects, directives, and client-side behaviors
|
|
40
44
|
- `fetch-data.md` - Initial server-side data loading and browser-triggered RPC flows with `pp.rpc()`, streaming, uploads, and auth-aware actions
|
|
41
45
|
- `state.md` - Request-scoped server state with `StateManager`, session-backed JSON persistence, and listener callbacks for transient flows
|
|
42
46
|
- `cache.md` - Route-level HTML caching with `Cache`, `CacheHandler`, TTL behavior, file-system storage, and invalidation patterns
|
|
43
47
|
- `validation.md` - Input validation and sanitization with `Validate`, `Rule`, direct field checks, and multi-rule workflows for routes and RPC actions
|
|
44
48
|
- `metadata.md` - Static and dynamic metadata, SEO inheritance, and Open Graph or Twitter card tags
|
|
45
|
-
- `routing.md` - Next.js App Router-style file-based routing with `src/app`, dynamic segments, route groups, and
|
|
49
|
+
- `routing.md` - Next.js App Router-style file-based routing with `src/app`, dynamic segments, route groups, nested layouts, and single-root route templates
|
|
46
50
|
- `project-structure.md` - Default Caspian layout and where routes, templates, shared code, and database files belong
|
|
47
51
|
|
|
48
52
|
## AI Awareness Notes
|
|
@@ -52,10 +56,12 @@ If an AI tool needs Caspian project documentation, start with this directory and
|
|
|
52
56
|
Preferred lookup order:
|
|
53
57
|
|
|
54
58
|
1. Read `node_modules/caspian-utils/dist/docs/index.md` to discover available local docs.
|
|
55
|
-
2. Read
|
|
56
|
-
3.
|
|
57
|
-
4.
|
|
58
|
-
5.
|
|
59
|
+
2. Read `./caspian.config.json` before making any feature assumption. Use it to confirm which project capabilities are enabled and which directories or tooling rules apply.
|
|
60
|
+
3. Read `database.md` for Prisma setup and ORM usage, `auth.md` for session auth and route protection, `components.md` for reusable UI authoring, `pulsepoint.md` for browser-side reactive runtime behavior, `fetch-data.md` for data flows, `state.md` for transient request-scoped state, `cache.md` for page caching, and `validation.md` for input boundaries.
|
|
61
|
+
4. For authored component, route, and layout HTML files, generate exactly one top-level lowercase HTML element. Think React-style single parent wrapper: keep any owned PulsePoint logic in a plain `<script>` inside that root, and do not handwrite `pp-component="..."` or `type="text/pp"` because Caspian injects those runtime attributes automatically.
|
|
62
|
+
5. Prefer local docs before generating code, commands, or migration guidance.
|
|
63
|
+
6. Check `node_modules/caspian-utils/dist/docs/` for packaged Caspian docs when local docs need more detail.
|
|
64
|
+
7. Only fall back to upstream documentation when local and packaged markdown do not cover the topic.
|
|
59
65
|
|
|
60
66
|
## Maintenance
|
|
61
67
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Project Structure
|
|
3
|
-
description: Understand the default Caspian project layout so AI agents place
|
|
3
|
+
description: Understand the default Caspian project layout so AI agents place routes, reusable components, PulsePoint templates, RPC actions, validation helpers, auth code, configuration, and database changes in the correct directories.
|
|
4
4
|
related:
|
|
5
5
|
title: Related docs
|
|
6
|
-
description: Start with installation for new apps, then use the auth guide for bootstrap and session wiring, the routing guide to map URLs correctly, and the cache guide when route HTML should be reused safely.
|
|
6
|
+
description: Start with installation for new apps, then use the component guide for reusable UI, the auth guide for bootstrap and session wiring, the routing guide to map URLs correctly, and the cache guide when route HTML should be reused safely.
|
|
7
7
|
links:
|
|
8
8
|
- /docs/installation
|
|
9
|
+
- /docs/components
|
|
9
10
|
- /docs/auth
|
|
10
11
|
- /docs/routing
|
|
11
12
|
- /docs/cache
|
|
@@ -19,13 +20,16 @@ This page explains the default layout of a Caspian application, where Caspian co
|
|
|
19
20
|
|
|
20
21
|
Caspian uses a lean project layout that keeps application code in `src`, database files in `prisma`, static assets in `public`, configuration in `caspian.config.json`, and framework internals in the installed package.
|
|
21
22
|
|
|
22
|
-
In that layout, the default stack is PulsePoint in
|
|
23
|
+
In that layout, the default stack is Python components for reusable UI, PulsePoint in templates for reactive browser behavior, RPC for browser-triggered server calls, and `casp.validate` for input validation at route and action boundaries.
|
|
23
24
|
|
|
24
25
|
For public pages that can safely reuse rendered HTML, Caspian also supports route-level page caching through `casp.cache_handler`.
|
|
25
26
|
|
|
27
|
+
Before an AI agent decides which Caspian features are available in a workspace, it should read `./caspian.config.json` almost immediately. That file is the feature gate for project capabilities such as `backendOnly`, `tailwindcss`, `mcp`, `prisma`, `typescript`, and `componentScanDirs`.
|
|
28
|
+
|
|
26
29
|
## Top-Level Areas
|
|
27
30
|
|
|
28
31
|
- `src/` contains routes, page templates, styles, and shared libraries.
|
|
32
|
+
- `src/components/` contains reusable Python components and optional same-name HTML templates.
|
|
29
33
|
- `src/lib/auth/auth_config.py` contains auth-specific configuration for the app.
|
|
30
34
|
- `prisma/` contains the Prisma schema and seed scripts.
|
|
31
35
|
- `public/` contains static assets served directly.
|
|
@@ -50,6 +54,11 @@ my-app/
|
|
|
50
54
|
index.py
|
|
51
55
|
index.html
|
|
52
56
|
globals.css
|
|
57
|
+
components/
|
|
58
|
+
Container.py
|
|
59
|
+
ui/
|
|
60
|
+
Button.py
|
|
61
|
+
Button.html
|
|
53
62
|
lib/
|
|
54
63
|
auth/
|
|
55
64
|
auth_config.py
|
|
@@ -77,8 +86,24 @@ This is the main application area. It contains route files, templates, styles, a
|
|
|
77
86
|
|
|
78
87
|
This directory handles file-based routing. Route templates and route-specific backend logic live here.
|
|
79
88
|
|
|
89
|
+
When authoring a route HTML file such as `src/app/**/index.html`, keep the whole template inside exactly one top-level lowercase HTML element. Treat it the same way you would a React component returning one parent element: wrap the route markup and any owned PulsePoint script in the same root.
|
|
90
|
+
|
|
91
|
+
Do not handwrite `pp-component="..."` or `type="text/pp"` in those source templates. Author a plain `<script>` inside the root when you need PulsePoint logic, and let Caspian add the runtime attributes during render.
|
|
92
|
+
|
|
80
93
|
See `routing.md` for the full App Router-style rules for dynamic segments, route groups, and nested layouts.
|
|
81
94
|
|
|
95
|
+
### `src/components/`
|
|
96
|
+
|
|
97
|
+
Use this folder for reusable UI components that should be imported into route templates or other component templates.
|
|
98
|
+
|
|
99
|
+
The common Caspian pattern is a Python file such as `Button.py` with `@component`, optionally paired with a same-name HTML file such as `Button.html` when the component has richer markup or PulsePoint behavior.
|
|
100
|
+
|
|
101
|
+
For component HTML files, follow the same one-parent rule as route HTML files: one top-level lowercase HTML element only, with no sibling roots and no top-level script sitting outside that root.
|
|
102
|
+
|
|
103
|
+
Do not handwrite `pp-component="..."` or `type="text/pp"` in component source templates either. Write plain `<script>` inside the single root and let the render pipeline inject the runtime shape.
|
|
104
|
+
|
|
105
|
+
This workspace's component tooling scans `src/` based on `caspian.config.json`, so `src/components/` is a conventionally clean location, not a hard-coded runtime requirement.
|
|
106
|
+
|
|
82
107
|
### `src/lib/`
|
|
83
108
|
|
|
84
109
|
Use this folder for shared helpers, reusable validators, RPC-facing service wrappers, reusable UI utilities, and app-level support code.
|
|
@@ -124,6 +149,10 @@ Use `main.py` for auth bootstrap and middleware-order changes. Use `src/lib/auth
|
|
|
124
149
|
|
|
125
150
|
The core feature configuration file for the application.
|
|
126
151
|
|
|
152
|
+
AI agents should read this file before making almost any feature-level decision. Use it to confirm which capabilities are enabled, which code generation paths make sense, and which directories should be scanned for components or other project assets.
|
|
153
|
+
|
|
154
|
+
In the current workspace, `caspian.config.json` shows `backendOnly: false`, `tailwindcss: true`, `mcp: false`, `prisma: true`, `typescript: false`, and `componentScanDirs: ["src"]`.
|
|
155
|
+
|
|
127
156
|
### `src/lib/auth/auth_config.py`
|
|
128
157
|
|
|
129
158
|
The project auth configuration file. Use this path when changing authentication behavior.
|
|
@@ -138,7 +167,9 @@ The backend logic for the route. This is where route behavior can load first-ren
|
|
|
138
167
|
|
|
139
168
|
### `src/app/index.html`
|
|
140
169
|
|
|
141
|
-
The route template. It supports standard HTML,
|
|
170
|
+
The route template. It supports standard HTML, `<!-- @import ... -->` component imports, and PulsePoint directives, and it should be the default place for reactive frontend behavior in Caspian.
|
|
171
|
+
|
|
172
|
+
Use `components.md` when the task involves authoring reusable `<MyComponent />` tags backed by Python files.
|
|
142
173
|
|
|
143
174
|
### `src/app/globals.css`
|
|
144
175
|
|
|
@@ -163,8 +194,11 @@ The packaged Caspian documentation location distributed with the current toolcha
|
|
|
163
194
|
|
|
164
195
|
If an AI agent is deciding where to make changes, use these rules first.
|
|
165
196
|
|
|
197
|
+
- Read `caspian.config.json` almost immediately before making feature, tooling, or file-placement decisions. It tells you which Caspian features are enabled in the current workspace.
|
|
166
198
|
- Put route templates and route-specific backend logic in `src/app/`.
|
|
167
199
|
- Check [routing.md](./routing.md) when you need URL segment rules, layout nesting behavior, or dynamic route conventions.
|
|
200
|
+
- Put reusable component files in `src/components/` and check [components.md](./components.md) for `@component`, `render_html(__file__)`, import comments, and single-root template rules.
|
|
201
|
+
- For route and component HTML files, always emit one top-level lowercase HTML element. Good: one wrapper containing the content and a plain `<script>` when needed. Bad: a wrapper element followed by a sibling top-level `<script>`, or handwritten `pp-component="..."` and `type="text/pp"` attributes in source.
|
|
168
202
|
- Put shared helpers and reusable libraries in `src/lib/`.
|
|
169
203
|
- Use PulsePoint conventions in route templates for reactive frontend behavior.
|
|
170
204
|
- Use `@rpc()` in route/backend code and `pp.rpc()` in client code for browser-triggered data flows.
|
package/dist/docs/pulsepoint.md
CHANGED
|
@@ -3,8 +3,9 @@ title: PulsePoint Runtime Guide
|
|
|
3
3
|
description: Learn how AI agents should use PulsePoint as the default reactive frontend contract in Caspian, including the bundled runtime loaded from `public/js/main.js` and implemented in `public/js/pp-reactive-v2.js`, component script rules, and supported directives.
|
|
4
4
|
related:
|
|
5
5
|
title: Related docs
|
|
6
|
-
description: Read the routing, data-fetching, and project-structure docs alongside the PulsePoint runtime contract.
|
|
6
|
+
description: Read the components, routing, data-fetching, and project-structure docs alongside the PulsePoint runtime contract.
|
|
7
7
|
links:
|
|
8
|
+
- /docs/components
|
|
8
9
|
- /docs/routing
|
|
9
10
|
- /docs/fetch-data
|
|
10
11
|
- /docs/project-structure
|
|
@@ -17,6 +18,8 @@ This file documents the PulsePoint runtime that is currently shipped in `public/
|
|
|
17
18
|
|
|
18
19
|
If a task involves `pp.state`, `pp.effect`, `pp.layoutEffect`, `pp-ref`, `pp-spread`, `pp-for`, context, portals, SPA navigation, or component boundary behavior, read this page first and keep generated code aligned with the runtime implemented in this repo.
|
|
19
20
|
|
|
21
|
+
Use `components.md` for authoring Python `@component` files and same-name HTML templates. Use this page for the browser-side `pp-component` contract and `script[type="text/pp"]` behavior after those templates are rendered.
|
|
22
|
+
|
|
20
23
|
PulsePoint is the default reactive frontend layer for Caspian.
|
|
21
24
|
|
|
22
25
|
Do not assume React, Vue, Svelte, JSX, Alpine, HTMX, or older PulsePoint docs unless the task explicitly asks for a different frontend contract.
|
|
@@ -34,7 +37,9 @@ When a Caspian page needs reactive browser behavior, use PulsePoint.
|
|
|
34
37
|
- Source authoring under `src/` may use convenience syntax that is transformed before it reaches the browser.
|
|
35
38
|
- This page describes the bundled browser runtime shipped in `public/js/pp-reactive-v2.js`.
|
|
36
39
|
- When source-layer examples conflict with the bundled runtime, follow the bundled runtime.
|
|
37
|
-
- In
|
|
40
|
+
- In authored route, layout, and component templates, do not add `pp-component` manually. The Python side injects it onto the template root during render.
|
|
41
|
+
- In authored templates, write PulsePoint logic in a plain `<script>` inside that root. `main.py` runs `transform_scripts(...)`, so the runtime receives `script[type="text/pp"]`.
|
|
42
|
+
- When reading or debugging runtime HTML, look for `pp-component` roots and `script[type="text/pp"]`.
|
|
38
43
|
|
|
39
44
|
## Runtime shape
|
|
40
45
|
|
|
@@ -45,16 +50,19 @@ A component root is any element with `pp-component`.
|
|
|
45
50
|
Important:
|
|
46
51
|
|
|
47
52
|
- `pp-component` is the instance id used for the component registry, saved state, cached template, parent tracking, and instance lookup.
|
|
53
|
+
- In normal Caspian authoring, `pp-component` arrives from the Python render pipeline on route, layout, and component roots rather than being handwritten in source templates.
|
|
48
54
|
- Reusing the same `pp-component` value for multiple live roots will destroy the previous registered instance and replace it with the new one.
|
|
49
55
|
- If a root is manually constructed with an empty `pp-component`, the runtime will assign an anonymous id. AI-generated markup should still use stable unique ids.
|
|
50
56
|
- `pp.mount()` bootstraps every `[pp-component]` in the document, so do not manually instantiate `Component` in authored app code.
|
|
51
57
|
|
|
52
58
|
## Component roots and scripts
|
|
53
59
|
|
|
54
|
-
- Each runtime component root should have at most one
|
|
55
|
-
- The runtime only treats `script` as component logic.
|
|
60
|
+
- Each runtime component root should have at most one `script[type="text/pp"]` block.
|
|
61
|
+
- The runtime only treats `script[type="text/pp"]` as component logic.
|
|
56
62
|
- The script lookup walks the current root and skips nested `pp-component` boundaries, so a parent does not consume a child component's script.
|
|
57
63
|
- If multiple matching scripts exist in the same root, the first matching owned script wins. Generate one script per root.
|
|
64
|
+
- Authored component and route HTML templates must have exactly one top-level lowercase HTML root because the compiler injects `pp-component` onto that root during render. Think React-style single parent wrapper, not sibling top-level tags.
|
|
65
|
+
- In authored Caspian templates, write plain `<script>` inside the single root and let the render pipeline rewrite it before mount.
|
|
58
66
|
- A scriptless component root still mounts and can receive props, refs, events, and nested children, but it has no local runtime scope beyond its props.
|
|
59
67
|
- Component scripts are plain JavaScript executed with `new Function(...)`. Do not use `import`, `export`, or top-level `await` inside them.
|
|
60
68
|
- The runtime auto-returns supported top-level bindings from the script. Do not rely on manual `return { ... }` objects.
|
|
@@ -82,7 +90,7 @@ Example:
|
|
|
82
90
|
<p>Count: {count}</p>
|
|
83
91
|
<button onclick="setCount(count + 1)">Increment</button>
|
|
84
92
|
|
|
85
|
-
<script>
|
|
93
|
+
<script type="text/pp">
|
|
86
94
|
const { title } = pp.props;
|
|
87
95
|
const [count, setCount] = pp.state(0);
|
|
88
96
|
|
|
@@ -93,6 +101,8 @@ Example:
|
|
|
93
101
|
</div>
|
|
94
102
|
```
|
|
95
103
|
|
|
104
|
+
That example shows runtime HTML after mountable roots already exist. In authored Caspian templates, you normally write the root without `pp-component` and keep the logic in a plain `<script>` so the Python render path can inject both runtime attributes before the browser runtime sees the HTML.
|
|
105
|
+
|
|
96
106
|
## Hooks and runtime API
|
|
97
107
|
|
|
98
108
|
Hooks exposed inside component scripts through `pp`:
|
|
@@ -324,8 +334,9 @@ Use these rules when generating or editing PulsePoint runtime code:
|
|
|
324
334
|
|
|
325
335
|
- Treat PulsePoint as the default reactive frontend for Caspian app code.
|
|
326
336
|
- Use the bundled runtime contract in `public/js/pp-reactive-v2.js`.
|
|
327
|
-
-
|
|
328
|
-
-
|
|
337
|
+
- In authored Caspian templates, do not handwrite `pp-component` or `type="text/pp"`; let the render pipeline inject them.
|
|
338
|
+
- If you are explicitly editing raw runtime HTML or internals, keep `pp-component` unique per live instance.
|
|
339
|
+
- In authored templates, use a plain `<script>` inside the root. In runtime HTML, the owned script appears as `script[type="text/pp"]`.
|
|
329
340
|
- Keep template-facing variables at top level.
|
|
330
341
|
- Use `pp.createContext`, `pp.context`, and `pp.provideContext` for context. Do not invent `pp-context`.
|
|
331
342
|
- Keep `pp-for` on `<template>` and use plain `key`.
|
|
@@ -348,7 +359,7 @@ Do not generate these unless the current source explicitly adds support:
|
|
|
348
359
|
- `pp-dynamic-script`
|
|
349
360
|
- `pp-dynamic-meta`
|
|
350
361
|
- `pp-dynamic-link`
|
|
351
|
-
-
|
|
362
|
+
- handwritten `pp-component="..."` or `type="text/pp"` in authored route, layout, or component templates
|
|
352
363
|
- `pp.fetchFunction()` as the current raw runtime helper name
|
|
353
364
|
- made-up hooks, directives, or globals not present in the current bundled runtime
|
|
354
365
|
|
|
@@ -357,7 +368,7 @@ Do not generate these unless the current source explicitly adds support:
|
|
|
357
368
|
These are current runtime caveats that matter for authors and AI tools:
|
|
358
369
|
|
|
359
370
|
- `pp-component` is the registry key for instances, state, parent tracking, and templates. Treat it as unique per mounted root.
|
|
360
|
-
- Nested roots without their own `script` block are not fully isolated during parent template compilation.
|
|
371
|
+
- Nested roots without their own `script[type="text/pp"]` block are not fully isolated during parent template compilation.
|
|
361
372
|
- The global `pp` singleton auto-mounts on DOM ready, and `pp.mount()` is idempotent.
|
|
362
373
|
- `pp.effect` and `pp.layoutEffect` are cleanup-style hooks. Their callbacks are not promise-aware.
|
|
363
374
|
- `pp.context()` resolves through ancestor components, not the current component's own pending providers.
|
package/dist/docs/routing.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Routing
|
|
3
|
-
description: Understand Caspian's Next.js App Router-style file-based routing, including src/app conventions, index files, dynamic segments, route groups, and
|
|
3
|
+
description: Understand Caspian's Next.js App Router-style file-based routing, including src/app conventions, index files, dynamic segments, route groups, nested layouts, and component-friendly route templates.
|
|
4
4
|
related:
|
|
5
5
|
title: Related docs
|
|
6
|
-
description: Read the structure guide first, then use the metadata guide for SEO fields, the cache guide for route-level HTML reuse, and the PulsePoint runtime guide for interactive route templates.
|
|
6
|
+
description: Read the structure guide first, then use the components guide for reusable UI, the metadata guide for SEO fields, the cache guide for route-level HTML reuse, and the PulsePoint runtime guide for interactive route templates.
|
|
7
7
|
links:
|
|
8
8
|
- /docs/project-structure
|
|
9
|
+
- /docs/components
|
|
9
10
|
- /docs/cache
|
|
10
11
|
- /docs/metadata
|
|
11
12
|
- /docs/pulsepoint
|
|
@@ -73,6 +74,70 @@ Examples:
|
|
|
73
74
|
|
|
74
75
|
Use `index.html` for the route template. This is the route's view layer.
|
|
75
76
|
|
|
77
|
+
Route templates can import reusable Python components with `<!-- @import ... -->` comments and render them with JSX-style tags such as `<Button />`. Use [components.md](./components.md) for the component authoring rules.
|
|
78
|
+
|
|
79
|
+
Do not manually add `pp-component="..."` to the route root. The Python render pipeline injects that attribute onto the route's single top-level lowercase HTML element.
|
|
80
|
+
|
|
81
|
+
Do not manually add `type="text/pp"` to a route-owned script either. In source templates, write a plain `<script>` inside the root and let `main.py` call `transform_scripts(...)` before the browser runtime sees the HTML.
|
|
82
|
+
|
|
83
|
+
That means route templates follow the same single-root discipline as component templates: one root element, no sibling roots, and PulsePoint scripts kept inside that root when needed.
|
|
84
|
+
|
|
85
|
+
For AI-generated route templates, treat `src/app/**/index.html` the same way you would a React component body: return one parent element that contains the entire route markup.
|
|
86
|
+
|
|
87
|
+
Good:
|
|
88
|
+
|
|
89
|
+
```html
|
|
90
|
+
<section class="dashboard-shell">
|
|
91
|
+
<h1>Dashboard</h1>
|
|
92
|
+
|
|
93
|
+
<script>
|
|
94
|
+
const [filter, setFilter] = pp.state("all");
|
|
95
|
+
</script>
|
|
96
|
+
</section>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Bad:
|
|
100
|
+
|
|
101
|
+
```html
|
|
102
|
+
<section class="dashboard-shell">
|
|
103
|
+
<h1>Dashboard</h1>
|
|
104
|
+
</section>
|
|
105
|
+
|
|
106
|
+
<script>
|
|
107
|
+
const [filter, setFilter] = pp.state("all");
|
|
108
|
+
</script>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Example authored route template:
|
|
112
|
+
|
|
113
|
+
```html
|
|
114
|
+
<!-- @import StatsCard from "../components" -->
|
|
115
|
+
|
|
116
|
+
<section class="dashboard-shell">
|
|
117
|
+
<StatsCard title="Users" value="42" />
|
|
118
|
+
|
|
119
|
+
<script>
|
|
120
|
+
const [filter, setFilter] = pp.state("all");
|
|
121
|
+
</script>
|
|
122
|
+
</section>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Rendered shape at runtime:
|
|
126
|
+
|
|
127
|
+
```html
|
|
128
|
+
<section pp-component="page_a1b2c3d4" class="dashboard-shell">
|
|
129
|
+
<div pp-component="statscard_e5f6g7h8" title="Users" value="42">
|
|
130
|
+
...
|
|
131
|
+
</div>
|
|
132
|
+
|
|
133
|
+
<script type="text/pp">
|
|
134
|
+
const [filter, setFilter] = pp.state("all");
|
|
135
|
+
</script>
|
|
136
|
+
</section>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Write the first form. Caspian produces the second form by injecting `pp-component` on the root and `type="text/pp"` on the owned script.
|
|
140
|
+
|
|
76
141
|
### `index.py`
|
|
77
142
|
|
|
78
143
|
Use `index.py` when the route needs metadata or async server-side logic. Because Caspian runs on FastAPI, the page entry should be async.
|