@cervio/create-plugin 0.0.0-stage → 1.0.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-present Cervio S.r.l.
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,69 @@
1
- # Temporary Holding Version
1
+ # @cervio/create-plugin
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
+ Scaffold a new [Cervio](https://cervio.app) plugin in one command:
4
+
5
+ - **Route plugin** (default): a full page in Cervio. Vite + React + TypeScript, wired to `@cervio/plugin-sdk`.
6
+ - **Write-gate plugin** (`--type policy`): allow or deny a record save (`before_create` / `before_update`), bundled for the server isolate.
7
+
8
+ ```bash
9
+ npm create @cervio/plugin@latest my-plugin
10
+ # or
11
+ npx @cervio/create-plugin my-plugin --host https://your-org.cervio.app
12
+
13
+ # write-gate plugin
14
+ npm create @cervio/plugin@latest my-guard -- --type policy
15
+ ```
16
+
17
+ `cervio init` (from `@cervio/cli`) runs the same scaffolder.
18
+
19
+ Options: `--host <url>`, `--route-slug <slug>` (route plugins; defaults to the
20
+ kebab-cased plugin name), `--type route|policy` (`server` is a legacy alias for
21
+ `policy`), `--yes` (skip the host prompt).
22
+
23
+ ## What you get (route)
24
+
25
+ ```text
26
+ my-plugin/
27
+ AGENTS.md # rules for coding agents: read this first
28
+ README.md
29
+ cervio.json # host, plugin_key, route_slug (CLI project config)
30
+ manifest.json # no "version" field: the host assigns releases
31
+ package.json # dev / build / validate / push scripts
32
+ vite.config.ts # multi-page build: dist/index.html + dist/surface.html
33
+ index.html
34
+ surface.html # CervioUI.dialog.surface body
35
+ src/
36
+ main.tsx, App.tsx
37
+ surface-main.tsx, SurfaceApp.tsx
38
+ i18n/ # bundled it/en catalogs
39
+ index.css # host CSS tokens only, no fixed palette
40
+ .cursor/rules/cervio-plugin.mdc
41
+ ```
42
+
43
+ ## What you get (write-gate plugin)
44
+
45
+ ```text
46
+ my-guard/
47
+ README.md
48
+ cervio.json
49
+ package.json # build / validate / pack / push (esbuild)
50
+ manifest.json # plugin_type: policy + hooks[]
51
+ src/index.js # edit here (imports @cervio/plugin-sdk/policy)
52
+ server/index.js # bundled isolate entry (npm run build)
53
+ ```
54
+
55
+ Always run `npm run build` before `pack` or `push`.
56
+
57
+ ## Programmatic use
58
+
59
+ ```ts
60
+ import { createPlugin } from '@cervio/create-plugin'
61
+
62
+ await createPlugin(['my-plugin', '--type', 'route', '--yes'])
63
+ ```
64
+
65
+ ## Documentation
66
+
67
+ [docs.cervio.app](https://docs.cervio.app): Authoring, Route plugins, Policy plugins.
68
+
69
+ `create-cervio-plugin` is the previous name of this package and is deprecated.
@@ -0,0 +1,185 @@
1
+ // src/index.ts
2
+ import { promises as fs } from "fs";
3
+ import path from "path";
4
+ import { fileURLToPath } from "url";
5
+ import prompts from "prompts";
6
+ var __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ var TEMPLATE_DIR = path.join(__dirname, "..", "template");
8
+ var TEMPLATE_POLICY_DIR = path.join(__dirname, "..", "template-policy");
9
+ var RESERVED_NAMES = /* @__PURE__ */ new Set([".", "..", "node_modules", ".git"]);
10
+ var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".ico", ".woff", ".woff2"]);
11
+ var DOTFILE_RENAMES = {
12
+ gitignore: ".gitignore"
13
+ };
14
+ function toKebabCase(input) {
15
+ return input.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
16
+ }
17
+ function parseArgs(argv) {
18
+ const positional = [];
19
+ const flags = /* @__PURE__ */ new Map();
20
+ for (let i = 0; i < argv.length; i += 1) {
21
+ const arg = argv[i];
22
+ if (!arg.startsWith("--")) {
23
+ positional.push(arg);
24
+ continue;
25
+ }
26
+ const eqIndex = arg.indexOf("=");
27
+ if (eqIndex !== -1) {
28
+ flags.set(arg.slice(2, eqIndex), arg.slice(eqIndex + 1));
29
+ continue;
30
+ }
31
+ const key = arg.slice(2);
32
+ const next = argv[i + 1];
33
+ if (next !== void 0 && !next.startsWith("--")) {
34
+ flags.set(key, next);
35
+ i += 1;
36
+ } else {
37
+ flags.set(key, "true");
38
+ }
39
+ }
40
+ return { positional, flags };
41
+ }
42
+ async function pathExists(target) {
43
+ try {
44
+ await fs.access(target);
45
+ return true;
46
+ } catch {
47
+ return false;
48
+ }
49
+ }
50
+ async function copyTemplate(srcDir, destDir, replacements) {
51
+ const entries = await fs.readdir(srcDir, { withFileTypes: true });
52
+ for (const entry of entries) {
53
+ const srcPath = path.join(srcDir, entry.name);
54
+ const destName = DOTFILE_RENAMES[entry.name] ?? entry.name;
55
+ const destPath = path.join(destDir, destName);
56
+ if (entry.isDirectory()) {
57
+ await fs.mkdir(destPath, { recursive: true });
58
+ await copyTemplate(srcPath, destPath, replacements);
59
+ continue;
60
+ }
61
+ const ext = path.extname(entry.name).toLowerCase();
62
+ if (BINARY_EXTENSIONS.has(ext)) {
63
+ await fs.copyFile(srcPath, destPath);
64
+ continue;
65
+ }
66
+ let content = await fs.readFile(srcPath, "utf8");
67
+ for (const [key, value] of Object.entries(replacements)) {
68
+ content = content.replaceAll(`{{${key}}}`, value);
69
+ }
70
+ await fs.writeFile(destPath, content);
71
+ }
72
+ }
73
+ async function createPlugin(argv) {
74
+ const { positional, flags } = parseArgs(argv);
75
+ let targetName = positional[0];
76
+ if (!targetName) {
77
+ const response = await prompts({
78
+ type: "text",
79
+ name: "name",
80
+ message: "Plugin name (used for the folder and plugin_key)",
81
+ initial: "my-cervio-plugin"
82
+ });
83
+ targetName = response.name;
84
+ }
85
+ if (!targetName || typeof targetName !== "string") {
86
+ console.error("A plugin name is required.");
87
+ process.exit(1);
88
+ return;
89
+ }
90
+ const pluginKey = toKebabCase(targetName);
91
+ if (!pluginKey) {
92
+ console.error(`"${targetName}" does not produce a valid plugin_key.`);
93
+ process.exit(1);
94
+ return;
95
+ }
96
+ const targetDir = path.resolve(process.cwd(), targetName);
97
+ const baseName = path.basename(targetDir);
98
+ if (RESERVED_NAMES.has(baseName)) {
99
+ console.error(`"${targetName}" is a reserved name - choose another.`);
100
+ process.exit(1);
101
+ return;
102
+ }
103
+ if (await pathExists(targetDir)) {
104
+ const existing = await fs.readdir(targetDir);
105
+ if (existing.length > 0) {
106
+ console.error(`Directory "${targetName}" already exists and is not empty.`);
107
+ process.exit(1);
108
+ return;
109
+ }
110
+ }
111
+ let host = flags.get("host") ?? "";
112
+ if (host === "true") host = "";
113
+ if (!host && !flags.has("yes")) {
114
+ const response = await prompts({
115
+ type: "text",
116
+ name: "host",
117
+ message: "Cervio host (e.g. https://your-org.cervio.app) - leave blank to fill in cervio.json later"
118
+ });
119
+ host = typeof response.host === "string" ? response.host : "";
120
+ }
121
+ const routeSlug = flags.get("route-slug") || pluginKey;
122
+ const rawType = (flags.get("type") || "route").toLowerCase();
123
+ const isPolicy = rawType === "policy" || rawType === "server";
124
+ const templateDir = isPolicy ? TEMPLATE_POLICY_DIR : TEMPLATE_DIR;
125
+ if (isPolicy && !await pathExists(templateDir)) {
126
+ console.error("The policy template is missing (template-policy/).");
127
+ process.exit(1);
128
+ return;
129
+ }
130
+ await fs.mkdir(targetDir, { recursive: true });
131
+ await copyTemplate(templateDir, targetDir, {
132
+ PLUGIN_NAME: targetName,
133
+ PLUGIN_KEY: pluginKey,
134
+ ROUTE_SLUG: routeSlug,
135
+ HOST: host.trim().replace(/\/+$/, "")
136
+ });
137
+ if (isPolicy) {
138
+ const manifestPath = path.join(targetDir, "manifest.json");
139
+ try {
140
+ const raw = await fs.readFile(manifestPath, "utf8");
141
+ const parsed = JSON.parse(raw);
142
+ parsed.plugin_key = pluginKey;
143
+ parsed.plugin_name = targetName;
144
+ parsed.plugin_type = "policy";
145
+ await fs.writeFile(manifestPath, `${JSON.stringify(parsed, null, 2)}
146
+ `);
147
+ } catch {
148
+ }
149
+ }
150
+ console.log("");
151
+ console.log(
152
+ `\u2714 Created ${targetName} at ${targetDir}${isPolicy ? " (write-gate plugin)" : ""}`
153
+ );
154
+ console.log("");
155
+ console.log("Next steps:");
156
+ console.log(` cd ${targetName}`);
157
+ if (isPolicy) {
158
+ console.log(" npm install # installs @cervio/plugin-sdk + esbuild");
159
+ console.log(" # edit src/index.js # plugin source (@cervio/plugin-sdk/policy)");
160
+ console.log(" npm run build # REQUIRED: bundles into server/index.js");
161
+ console.log(" npm run validate # build + cervio validate");
162
+ console.log(" npm run push # build + cervio push");
163
+ console.log(" # then bind the hook in Admin \u2192 Plugins (plugin_hook_bindings)");
164
+ } else {
165
+ console.log(" npm install # or pnpm install / yarn");
166
+ console.log(" npm run dev # local Vite preview (CervioUI stubs unavailable outside the sandbox)");
167
+ console.log(" npm run build # produces dist/index.html + dist/surface.html + dist/assets");
168
+ console.log(" npm run validate # cervio validate - matches host upload checks");
169
+ console.log(' npm run push # cervio push - prefer "cervio push --dev" while iterating');
170
+ }
171
+ console.log("");
172
+ if (!isPolicy) {
173
+ console.log("Read AGENTS.md before iterating with an LLM coding agent.");
174
+ }
175
+ if (!host) {
176
+ console.log("");
177
+ console.log(
178
+ 'Note: no host set - fill in "host" in cervio.json (or pass --host next time) before "cervio push".'
179
+ );
180
+ }
181
+ }
182
+
183
+ export {
184
+ createPlugin
185
+ };
package/dist/cli.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ createPlugin
4
+ } from "./chunk-NNLHAM7U.js";
5
+
6
+ // src/cli.ts
7
+ createPlugin(process.argv.slice(2)).catch((err) => {
8
+ console.error(err instanceof Error ? err.message : String(err));
9
+ process.exit(1);
10
+ });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Scaffold a new Cervio plugin project. `argv` are the command-line arguments
3
+ * without the node and script paths, e.g. `['my-plugin', '--type', 'policy']`.
4
+ * Used by the `create-plugin` bin and by `cervio init`.
5
+ */
6
+ declare function createPlugin(argv: string[]): Promise<void>;
7
+
8
+ export { createPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import {
2
+ createPlugin
3
+ } from "./chunk-NNLHAM7U.js";
4
+ export {
5
+ createPlugin
6
+ };
package/package.json CHANGED
@@ -1,6 +1,57 @@
1
1
  {
2
2
  "name": "@cervio/create-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "Scaffold a Cervio plugin (route, task or write-gate policy) wired to the Cervio toolchain. Run with: npm create @cervio/plugin",
5
+ "keywords": [
6
+ "cervio",
7
+ "plugin",
8
+ "scaffold",
9
+ "create-app"
10
+ ],
11
+ "license": "MIT",
12
+ "homepage": "https://github.com/cervio-app/cervio-devkit/tree/main/packages/create-plugin#readme",
13
+ "bugs": "https://github.com/cervio-app/cervio-devkit/issues",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/cervio-app/cervio-devkit.git",
17
+ "directory": "packages/create-plugin"
18
+ },
19
+ "type": "module",
20
+ "bin": {
21
+ "create-plugin": "./dist/cli.js"
22
+ },
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "template",
34
+ "template-policy",
35
+ "README.md",
36
+ "LICENSE"
37
+ ],
38
+ "engines": {
39
+ "node": ">=26"
40
+ },
41
+ "dependencies": {
42
+ "prompts": "^2.4.2"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^26.0.0",
46
+ "@types/prompts": "^2.4.9",
47
+ "tsup": "^9.0.0",
48
+ "typescript": "^5.8.3"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "scripts": {
54
+ "build": "tsup --config tsup.config.ts",
55
+ "typecheck": "tsc -p tsconfig.json --noEmit"
56
+ }
6
57
  }
@@ -0,0 +1,39 @@
1
+ ---
2
+ description: Cervio route plugin rules - ZIP contract, CervioUI, parentOrigin, build/validate/push loop
3
+ globs:
4
+ - "**/*"
5
+ alwaysApply: true
6
+ ---
7
+
8
+ # Cervio route plugin - agent rules
9
+
10
+ This project is a Cervio route plugin scaffolded with `@cervio/create-plugin`.
11
+ **Read `AGENTS.md` in full before editing anything** - this rule is a
12
+ condensed pointer to it, not a replacement.
13
+
14
+ 1. **No `version` in `manifest.json`.** It's optional and ignored on upload -
15
+ the Cervio host assigns release versions.
16
+ 2. **ZIP contract:** `manifest.json` + `dist/index.html` + `dist/assets/*`
17
+ (+ `dist/surface.html` if using `CervioUI.dialog.surface`). Never hand-edit
18
+ files under `dist/` - always rebuild with `npm run build`.
19
+ 3. **CervioUI only.** Never `window.alert` / `window.confirm`. Never emit
20
+ `__cervioPluginToast` / `__cervioPluginModal` (removed from the host). Use
21
+ `getCervioUI()` / `isCervioUIAvailable()` from `@cervio/plugin-sdk`.
22
+ 4. **`parentOrigin`, not `location.origin`.** Resolve API base URLs via
23
+ `__CERVIO_PLUGIN_CONTEXT__.parentOrigin` (already handled by
24
+ `createCervioClient` / `createCervioSessionClient` in `@cervio/plugin-sdk`
25
+ - do not reimplement URL resolution or add a `location.origin` fallback).
26
+ 5. **CSS uses host tokens only** (`var(--background)`, `var(--primary)`, …).
27
+ Never ship a fixed `:root` color palette.
28
+ 6. **Loop:** `npm run build` → `npm run validate` (`cervio validate`) →
29
+ `npm run push` (`cervio push`). Prefer `cervio push --dev` while iterating
30
+ on a shared/dev org; only push to the stable channel once verified.
31
+ 7. **Multi-instance safety.** `cervio.json`'s `host` is local project config
32
+ (not a secret). Before pushing to an unfamiliar host, run
33
+ `cervio whoami --host <host>` and/or `cervio push --expect-host <host>`.
34
+ 8. **i18n:** route plugins can't use the host's `next-intl`. Ship catalogs in
35
+ `src/i18n/` with identical keys per locale; resolve via `createI18n()`.
36
+ 9. Resolve Cervio entities by **technical name** at runtime
37
+ (`GET /api/v1/entities`) - never hard-code org-specific UUIDs. No chatty
38
+ fetch loops; page/batch list calls.
39
+ 10. Before a non-`--dev` push, run through the checklist in `AGENTS.md` §9.
@@ -0,0 +1,213 @@
1
+ # Agent guide - {{PLUGIN_NAME}}
2
+
3
+ This file is the canonical source of truth for AI coding agents (and humans)
4
+ working on this Cervio route plugin. Read it before making changes. If you are
5
+ an agent, treat every rule below as mandatory unless the user explicitly says
6
+ otherwise.
7
+
8
+ This plugin was scaffolded with `@cervio/create-plugin` and depends on
9
+ `@cervio/plugin-sdk`. Host-side authoring docs (deeper detail, External
10
+ Connections, performance rules) live in [Authoring](https://docs.cervio.app/docs/authoring)
11
+ ([connections](https://docs.cervio.app/docs/authoring/connections),
12
+ [performance](https://docs.cervio.app/docs/authoring/performance-safety)) and
13
+ [CervioUI docs](https://docs.cervio.app/docs/plugins/ui) in the **Cervio host repo** - this file is the condensed,
14
+ plugin-repo-local version.
15
+
16
+ ## 1. What this is
17
+
18
+ A prebuilt static bundle (`dist/`) that the Cervio host loads into a
19
+ sandboxed iframe (`sandbox="allow-scripts"`, **no**
20
+ `allow-same-origin`). There is no server-side build step on the host - you
21
+ build locally, then `push` (or upload) the ZIP.
22
+
23
+ ## 2. ZIP contract (non-negotiable)
24
+
25
+ The upload artifact root must contain:
26
+
27
+ ```text
28
+ manifest.json
29
+ dist/index.html
30
+ dist/assets/... (js, css, …)
31
+ dist/surface.html (only if you use CervioUI.dialog.surface)
32
+ ```
33
+
34
+ Rules:
35
+
36
+ - **Never hand-set `version` in `manifest.json`.** It is optional and
37
+ **ignored on upload** - the Cervio host assigns the release semver
38
+ (`0.1.0`, then patch bumps) and dedupes identical `manifest` (minus
39
+ `version`) + `dist/**` content. Do not "bump" it yourself; there is nothing
40
+ to bump from the plugin's point of view.
41
+ - `plugin_type` must be `route` for this template.
42
+ - Upload is rejected if `dist/index.html` is missing.
43
+ - Keep `plugin_key` stable forever - it is the plugin's identity on the host.
44
+ - `cervio validate` / `cervio pack` (via `@cervio/plugin-core`) run the same
45
+ checks the host runs on upload - always green before `cervio push`.
46
+
47
+ ## 3. CervioUI only - never raw browser dialogs
48
+
49
+ - Use `window.CervioUI.*` (via `@cervio/plugin-sdk`'s `getCervioUI()` /
50
+ `isCervioUIAvailable()`) for toast, confirm/alert, and custom modals.
51
+ **Never** inject HTML into the parent document.
52
+ - **Never** call `window.alert` / `window.confirm` / `window.prompt` - they
53
+ are blocked inside the sandbox and will hang or throw.
54
+ - **Never** emit `__cervioPluginToast` or `__cervioPluginModal` - these
55
+ bridges are removed from the host. `CervioUI` is the only supported surface.
56
+ - Prefer `CervioUI.dialog.surface` (+ `dist/surface.html`) for custom modals
57
+ (forms, readers, dense editors) over the legacy `dialog.frame`.
58
+ - Theme: use host CSS variables only (`var(--background)`, `var(--card)`,
59
+ `var(--primary)`, `var(--border)`, `var(--radius-lg)`, …). **Never** ship a
60
+ fixed `:root { ... }` palette - the host injects its tokens at the end of
61
+ `<head>`, so a bundled `:root` can win the cascade and break dark mode /
62
+ org themes. See `src/index.css` for the pattern already in this template.
63
+
64
+ ## 4. `parentOrigin`, not `location.origin`
65
+
66
+ Inside the sandboxed iframe, `window.location.origin` frequently
67
+ serializes as the literal string `"null"`. **Always** resolve the API base
68
+ URL from `window.__CERVIO_PLUGIN_CONTEXT__.parentOrigin`.
69
+
70
+ `@cervio/plugin-sdk`'s `createCervioClient()` / `createCervioSessionClient()`
71
+ already do this for you - do not reimplement URL resolution, and never add a
72
+ `location.origin` fallback.
73
+
74
+ ```ts
75
+ import { createCervioSessionClient } from '@cervio/plugin-sdk'
76
+
77
+ // baseUrl defaults to __CERVIO_PLUGIN_CONTEXT__.parentOrigin - do not pass
78
+ // window.location.origin.
79
+ const client = createCervioSessionClient()
80
+ ```
81
+
82
+ Same rule for deep links: use `parentPath` / `parentSearch` / `parentHref`
83
+ from `getPluginContext()` - the iframe's own `location` is opaque. Top-level
84
+ navigation (OAuth consent, cross-plugin links) goes through
85
+ `openExternalAuth(url)` from `@cervio/plugin-sdk`, never `window.top.location`
86
+ directly from arbitrary code paths.
87
+
88
+ ## 5. The loop: build → validate → push
89
+
90
+ ```bash
91
+ npm run build # vite build -> dist/index.html, dist/surface.html, dist/assets/*
92
+ npm run validate # cervio validate - same checks the host runs on upload
93
+ npm run push # cervio push - uploads + creates/updates the plugin version
94
+ ```
95
+
96
+ While iterating on a shared/dev org, **prefer**:
97
+
98
+ ```bash
99
+ npm run build && npm run validate && npm run push:dev
100
+ ```
101
+
102
+ (`push:dev` is a `cervio push --dev` shortcut already in `package.json`.)
103
+
104
+ `--dev` publishes to the host's dev channel instead of the stable release
105
+ channel, so you can iterate without disturbing users on the current stable
106
+ version. Only push to the stable channel (`cervio push`, no `--dev`) once
107
+ you've verified the change.
108
+
109
+ Never edit files under `dist/` by hand - always rebuild.
110
+
111
+ **Code-splitting: dynamic `import()` only.** Cervio caches the plugin
112
+ document per version and inlines the entry JS/CSS into it. Keep everything on
113
+ the first screen in the entry bundle; put rarely used heavy features (an
114
+ export, a chart library) behind `import()`. The template allows exactly that
115
+ (one input per Vite pass, `chunkFileNames` under `assets/`). A sandboxed
116
+ iframe does not cache its own requests, so a chunk is downloaded every time it
117
+ is first used in an open: never split the start-up path.
118
+
119
+ ## 6. Multi-instance / multi-host safety
120
+
121
+ The same plugin source can be pushed to more than one Cervio host (e.g. a
122
+ staging org and a customer org). `cervio.json`'s `"host"` field is **local
123
+ project config**, not a secret - it is the default target for `cervio push`.
124
+
125
+ Before pushing to a host you don't push to every day:
126
+
127
+ ```bash
128
+ cervio whoami --host <host> # confirm which org/user you are about to push as
129
+ cervio push --expect-host <host> # fails loudly if the resolved host doesn't match
130
+ ```
131
+
132
+ `--expect-host` is a safety net against a stale `CERVIO_URL` env var or a
133
+ copy-pasted `cervio.json` pointing at the wrong org. Treat a host mismatch as
134
+ a hard stop, not a warning to ignore.
135
+
136
+ ## 7. i18n
137
+
138
+ Route plugins cannot use the host's `next-intl` / `public/locales`. Ship your
139
+ own catalogs (`src/i18n/it.ts`, `src/i18n/en.ts`) with **identical key sets**,
140
+ and resolve the active locale with `createI18n()` from `@cervio/plugin-sdk`
141
+ (order: host locale, if enabled for this plugin → `runtimeSettings.fallbackLocale`
142
+ → plugin default). Never hardcode UI prose directly in components - always
143
+ go through `t(key)`.
144
+
145
+ ## 8. Performance & safety
146
+
147
+ - Declare the GET calls the plugin makes at start in `boot_requests`
148
+ (`[{ "path": "/api/v1/views/<view id>/records?limit=50" }]`, max 8, each
149
+ covered by a GET `cervio_apis` prefix): Cervio starts them while the plugin
150
+ loads and your own `fetch` of the same path + query gets that response
151
+ without waiting. `GET /api/v1/me` and `GET /api/v1/entities` are answered at
152
+ boot already when declared in `cervio_apis`.
153
+ - Call `markReady()` from `@cervio/plugin-sdk` once the first useful content
154
+ is on screen (data shown, not the skeleton). Cervio uses it to time how long
155
+ the plugin takes to open; it is a no-op outside Cervio.
156
+ - No chatty loops: don't `fetch` the same endpoint every render/paint or from
157
+ an unbounded `setInterval`.
158
+ - Batch and page: prefer one list/count call over N per-row calls; always cap
159
+ page size.
160
+ - No Realtime (`wss://…/realtime/…`) from the plugin - use `/api/v1` +
161
+ explicit refresh.
162
+ - Read records through a **view** (`listViewRecords`, `countViewRecords`):
163
+ `GET /api/v1/entities/<name>/records` without a view answers `view_required`
164
+ to anyone who is not an organization administrator. Take view ids from the
165
+ plugin settings, never hard-code them; count with `countViewRecords` (one
166
+ call), never by paging through every record.
167
+ - Address Cervio entities by **technical name**, never by org-specific UUIDs:
168
+ `GET /api/v1/entities/<name>` and `/capabilities` accept the name directly
169
+ (one round trip, no `GET /api/v1/entities` first). List every
170
+ `fetch` `/api/v1` method+prefix in `cervio_apis` (empty → relay denies all
171
+ API fetch; CervioUI still works). Undeclared call → error
172
+ **`Path not declared for this plugin`**: fix the manifest and re-push; do
173
+ not treat it as a per-user permission issue.
174
+ - Never put OAuth client secrets, refresh tokens, or LLM API keys in the ZIP,
175
+ `localStorage`, or a `postMessage` payload.
176
+
177
+ ## 9. Checklist before `cervio push` (no `--dev`)
178
+
179
+ - [ ] `npm run build` succeeded; `dist/index.html` (+ `dist/surface.html` if
180
+ used) and `dist/assets/*` are present
181
+ - [ ] `cervio validate` passes
182
+ - [ ] No `version` hand-edited in `manifest.json`
183
+ - [ ] `plugin_key` unchanged from the previous push
184
+ - [ ] Only `window.CervioUI.*` used for UI chrome - no `window.alert` /
185
+ `confirm`, no `__cervioPluginToast` / `__cervioPluginModal`
186
+ - [ ] CSS uses host tokens only - no fixed `:root` palette
187
+ - [ ] API base URL resolved via `__CERVIO_PLUGIN_CONTEXT__.parentOrigin` (or
188
+ `@cervio/plugin-sdk` defaults) - never `window.location.origin`
189
+ - [ ] i18n catalogs have identical keys across every shipped locale
190
+ - [ ] `cervio whoami` / `--expect-host` checked if pushing to an
191
+ unfamiliar host
192
+ - [ ] Idle Network tab quiet for ~30s (no repeating identical requests);
193
+ no `wss://` connection attempts
194
+ - [ ] `cervio_apis` lists every `/api/v1` method+path_prefix the plugin `fetch`es
195
+ - [ ] Ran `cervio push --dev` first and smoke-tested before a stable push
196
+
197
+ ## 10. Where to look next
198
+
199
+ - **Start here (MCP / agents):** [AI & MCP best practices](https://docs.cervio.app/docs/authoring/ai-mcp-best-practices)
200
+ and [Plugin types](https://docs.cervio.app/docs/authoring/plugin-types). Pull the same
201
+ pages with MCP `get_plugin_docs` (`authoring-ai-mcp-best-practices`,
202
+ `authoring-plugin-types`) before inventing APIs.
203
+ - `README.md` in this repo - project layout quick reference.
204
+ - `@cervio/plugin-sdk` README - full API surface (`getCervioUI`,
205
+ `getPluginContext`, `createCervioClient`/`createCervioSessionClient`,
206
+ `onThemeChange`, `createI18n`).
207
+ - Cervio host repo: [Authoring](https://docs.cervio.app/docs/authoring)
208
+ ([manifest](https://docs.cervio.app/docs/authoring/manifest-and-zip),
209
+ [policy](https://docs.cervio.app/docs/authoring/policy-plugins),
210
+ [task](https://docs.cervio.app/docs/authoring/task-plugins),
211
+ [connections](https://docs.cervio.app/docs/authoring/connections),
212
+ [performance](https://docs.cervio.app/docs/authoring/performance-safety)) and
213
+ [CervioUI docs](https://docs.cervio.app/docs/plugins/ui) (every `CervioUI` capability in depth).
@@ -0,0 +1,43 @@
1
+ # {{PLUGIN_NAME}}
2
+
3
+ A Cervio route plugin scaffolded with `@cervio/create-plugin` (Vite + React + TypeScript).
4
+
5
+ **Read [`AGENTS.md`](./AGENTS.md) first** - it is the canonical rulebook for
6
+ building, validating, and publishing this plugin (also picked up automatically
7
+ by AI coding agents).
8
+
9
+ ## Quick start
10
+
11
+ ```bash
12
+ npm install
13
+ npm run dev # local Vite dev server (CervioUI / __CERVIO_PLUGIN_CONTEXT__ are not injected here)
14
+ npm run build # dist/index.html + dist/surface.html + dist/assets/*
15
+ npm run validate # cervio validate - matches host upload checks
16
+ npm run push # cervio push - prefer "cervio push --dev" while iterating
17
+ ```
18
+
19
+ `npm run validate` / `npm run push` require the [`cervio` CLI](https://github.com/cervio-app) -
20
+ already a devDependency here. Log in once per host: `npx cervio login --host <host>`.
21
+
22
+ ## Project layout
23
+
24
+ | Path | Purpose |
25
+ |------|---------|
26
+ | `manifest.json` | Plugin metadata. **No `version` field** - the Cervio host assigns release versions on upload. |
27
+ | `cervio.json` | CLI project config: `host`, `plugin_key`, `route_slug`. Per-project, not secret. |
28
+ | `src/main.tsx` / `src/App.tsx` | Route page entry (`dist/index.html`). |
29
+ | `src/surface-main.tsx` / `src/SurfaceApp.tsx` | `CervioUI.dialog.surface` body (`dist/surface.html`) - the recommended pattern for custom modals. |
30
+ | `src/i18n/` | Bundled `it` / `en` catalogs - route plugins cannot use the host's `next-intl`. |
31
+ | `src/index.css` | Uses host CSS tokens (`var(--background)`, …) only - never a fixed `:root` palette. |
32
+
33
+ ## What this plugin can talk to
34
+
35
+ - `@cervio/plugin-sdk` - `getPluginContext()`, `createCervioSessionClient()`,
36
+ `getCervioUI()` / `isCervioUIAvailable()`, `onThemeChange()`, `createI18n()`.
37
+ - Cervio's public `/api/v1/*` REST API (same schema/RLS as the rest of the app).
38
+ - `window.CervioUI` for toast / dialog / select - never `window.alert` /
39
+ `window.confirm`, and never the deprecated `__cervioPluginToast` /
40
+ `__cervioPluginModal` bridges.
41
+
42
+ Full host-side docs (ZIP contract, External Connections, performance rules):
43
+ [Authoring](https://docs.cervio.app/docs/authoring) (chapters: manifest, runtime, connections, performance, checklist) and [CervioUI docs](https://docs.cervio.app/docs/plugins/ui) in the Cervio host repo.
@@ -0,0 +1,5 @@
1
+ {
2
+ "host": "{{HOST}}",
3
+ "plugin_key": "{{PLUGIN_KEY}}",
4
+ "route_slug": "{{ROUTE_SLUG}}"
5
+ }