@cervio/create-plugin 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +101 -2
- package/dist/chunk-AGG3S6VV.js +209 -0
- package/dist/cli.js +10 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +6 -0
- package/package.json +55 -3
- package/template/.cursor/rules/cervio-plugin.mdc +39 -0
- package/template/AGENTS.md +213 -0
- package/template/README.md +43 -0
- package/template/cervio.json +5 -0
- package/template/gitignore +4 -0
- package/template/index.html +12 -0
- package/template/manifest.json +13 -0
- package/template/package.json +28 -0
- package/template/src/App.tsx +92 -0
- package/template/src/SurfaceApp.tsx +40 -0
- package/template/src/i18n/en.ts +17 -0
- package/template/src/i18n/index.ts +15 -0
- package/template/src/i18n/it.ts +17 -0
- package/template/src/index.css +99 -0
- package/template/src/main.tsx +10 -0
- package/template/src/surface-main.tsx +10 -0
- package/template/src/vite-env.d.ts +5 -0
- package/template/surface.html +12 -0
- package/template/tsconfig.json +18 -0
- package/template/vite.config.ts +37 -0
- package/template/vite.surface.config.ts +25 -0
- package/template-policy/README.md +46 -0
- package/template-policy/cervio.json +4 -0
- package/template-policy/gitignore +4 -0
- package/template-policy/manifest.json +28 -0
- package/template-policy/package.json +19 -0
- package/template-policy/server/index.js +35 -0
- package/template-policy/src/index.js +50 -0
- package/template-task/.cursor/rules/cervio-plugin.mdc +17 -0
- package/template-task/AGENTS.md +34 -0
- package/template-task/README.md +46 -0
- package/template-task/cervio.json +4 -0
- package/template-task/gitignore +4 -0
- package/template-task/index.html +12 -0
- package/template-task/manifest.json +11 -0
- package/template-task/package.json +28 -0
- package/template-task/src/App.tsx +117 -0
- package/template-task/src/i18n/en.ts +14 -0
- package/template-task/src/i18n/index.ts +14 -0
- package/template-task/src/i18n/it.ts +14 -0
- package/template-task/src/index.css +117 -0
- package/template-task/src/main.tsx +10 -0
- package/template-task/src/vite-env.d.ts +5 -0
- package/template-task/tsconfig.json +18 -0
- package/template-task/vite.config.ts +31 -0
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,102 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cervio/create-plugin
|
|
2
2
|
|
|
3
|
-
|
|
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
|
+
- **Task plugin** (`--type task`): a widget inside a workflow task that can complete it (`task_form`).
|
|
7
|
+
- **Write-gate plugin** (`--type policy`): allow or deny a record save (`before_create` / `before_update`), bundled for the server isolate.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm create @cervio/plugin@latest my-plugin
|
|
11
|
+
# or
|
|
12
|
+
npx @cervio/create-plugin my-plugin --host https://your-org.cervio.app
|
|
13
|
+
|
|
14
|
+
# task plugin, write-gate plugin
|
|
15
|
+
npm create @cervio/plugin@latest my-task -- --type task
|
|
16
|
+
npm create @cervio/plugin@latest my-guard -- --type policy
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`cervio init` (from `@cervio/cli`) runs the same scaffolder. Requires Node.js 26 or later.
|
|
20
|
+
|
|
21
|
+
Options: `--host <url>`, `--route-slug <slug>` (route plugins; defaults to the
|
|
22
|
+
kebab-cased plugin name), `--type route|task|policy` (`server` is a legacy alias for
|
|
23
|
+
`policy`), `--yes` (skip the host prompt).
|
|
24
|
+
|
|
25
|
+
## What you get (route)
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
my-plugin/
|
|
29
|
+
AGENTS.md # rules for coding agents: read this first
|
|
30
|
+
README.md
|
|
31
|
+
cervio.json # host, plugin_key, route_slug (CLI project config)
|
|
32
|
+
manifest.json # no "version" field: the host assigns releases
|
|
33
|
+
package.json # dev / build / validate / push scripts
|
|
34
|
+
vite.config.ts # multi-page build: dist/index.html + dist/surface.html
|
|
35
|
+
index.html
|
|
36
|
+
surface.html # CervioUI.dialog.surface body
|
|
37
|
+
src/
|
|
38
|
+
main.tsx, App.tsx
|
|
39
|
+
surface-main.tsx, SurfaceApp.tsx
|
|
40
|
+
i18n/ # bundled it/en catalogs
|
|
41
|
+
index.css # host CSS tokens only, no fixed palette
|
|
42
|
+
.cursor/rules/cervio-plugin.mdc
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## What you get (task)
|
|
46
|
+
|
|
47
|
+
```text
|
|
48
|
+
my-task/
|
|
49
|
+
AGENTS.md # rules for coding agents
|
|
50
|
+
README.md # task vs task_form, drafts, box size
|
|
51
|
+
cervio.json # host, plugin_key
|
|
52
|
+
manifest.json # plugin_type: task_form, task_widget.preferred_size
|
|
53
|
+
package.json # build / validate / push scripts
|
|
54
|
+
vite.config.ts
|
|
55
|
+
index.html
|
|
56
|
+
src/
|
|
57
|
+
main.tsx, App.tsx # variables, draft, outcome buttons
|
|
58
|
+
i18n/ # it/en catalogs
|
|
59
|
+
index.css # fills the task box, host CSS tokens only
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## What you get (write-gate plugin)
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
my-guard/
|
|
66
|
+
README.md
|
|
67
|
+
cervio.json
|
|
68
|
+
package.json # build / validate / pack / push (esbuild)
|
|
69
|
+
manifest.json # plugin_type: policy + hooks[]
|
|
70
|
+
src/index.js # edit here (imports @cervio/plugin-sdk/policy)
|
|
71
|
+
server/index.js # bundled isolate entry (npm run build)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Always run `npm run build` before `pack` or `push`.
|
|
75
|
+
|
|
76
|
+
## Programmatic use
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { createPlugin } from '@cervio/create-plugin'
|
|
80
|
+
|
|
81
|
+
await createPlugin(['my-plugin', '--type', 'route', '--yes'])
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Documentation
|
|
85
|
+
|
|
86
|
+
[docs.cervio.app](https://docs.cervio.app): Authoring, Route plugins, Policy plugins.
|
|
87
|
+
|
|
88
|
+
`create-cervio-plugin` is the previous name of this package and is deprecated.
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT, see [LICENSE](LICENSE).
|
|
93
|
+
|
|
94
|
+
**Trademark.** "Cervio" and the Cervio logo are trademarks of Cervio S.r.l. This license
|
|
95
|
+
does not grant permission to use them. You may say that a plugin "works with Cervio"; you
|
|
96
|
+
may not imply endorsement or ship a product named Cervio.
|
|
97
|
+
|
|
98
|
+
**Platform.** Using a Cervio organization is governed by your partner or customer
|
|
99
|
+
agreement, not by this license.
|
|
100
|
+
|
|
101
|
+
**Your plugins.** Plugins you write are yours: using this package gives Cervio no rights
|
|
102
|
+
over your plugin, and does not require you to open-source it.
|
|
@@ -0,0 +1,209 @@
|
|
|
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 TEMPLATES = {
|
|
8
|
+
route: {
|
|
9
|
+
dir: path.join(__dirname, "..", "template"),
|
|
10
|
+
label: "route plugin",
|
|
11
|
+
next: [
|
|
12
|
+
"npm install",
|
|
13
|
+
"npm run dev # local Vite preview (CervioUI is unavailable outside Cervio)",
|
|
14
|
+
"npm run build # dist/index.html + dist/surface.html + dist/assets",
|
|
15
|
+
"npm run validate # same checks as the Cervio upload",
|
|
16
|
+
"npm run push:dev # dev channel while iterating; npm run push for a release"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
task: {
|
|
20
|
+
dir: path.join(__dirname, "..", "template-task"),
|
|
21
|
+
label: "task plugin",
|
|
22
|
+
next: [
|
|
23
|
+
"npm install",
|
|
24
|
+
"npm run build # dist/index.html + dist/assets",
|
|
25
|
+
"npm run validate # same checks as the Cervio upload",
|
|
26
|
+
"npm run push:dev # then add a plugin widget to a task layout in Admin"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
policy: {
|
|
30
|
+
dir: path.join(__dirname, "..", "template-policy"),
|
|
31
|
+
label: "write-gate plugin",
|
|
32
|
+
next: [
|
|
33
|
+
"npm install",
|
|
34
|
+
"# edit src/index.js (uses @cervio/plugin-sdk/policy)",
|
|
35
|
+
"npm run build # REQUIRED: bundles into server/index.js",
|
|
36
|
+
"npm run validate # build + cervio validate",
|
|
37
|
+
"npm run push # build + cervio push, then bind the hook in Admin \u2192 Plugins"
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var TYPE_ALIASES = {
|
|
42
|
+
route: "route",
|
|
43
|
+
task: "task",
|
|
44
|
+
policy: "policy",
|
|
45
|
+
server: "policy"
|
|
46
|
+
};
|
|
47
|
+
var RESERVED_NAMES = /* @__PURE__ */ new Set([".", "..", "node_modules", ".git"]);
|
|
48
|
+
var BINARY_EXTENSIONS = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".ico", ".woff", ".woff2"]);
|
|
49
|
+
var DOTFILE_RENAMES = {
|
|
50
|
+
gitignore: ".gitignore"
|
|
51
|
+
};
|
|
52
|
+
function toKebabCase(input) {
|
|
53
|
+
return input.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
54
|
+
}
|
|
55
|
+
function parseArgs(argv) {
|
|
56
|
+
const positional = [];
|
|
57
|
+
const flags = /* @__PURE__ */ new Map();
|
|
58
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
59
|
+
const arg = argv[i];
|
|
60
|
+
if (!arg.startsWith("--")) {
|
|
61
|
+
positional.push(arg);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const eqIndex = arg.indexOf("=");
|
|
65
|
+
if (eqIndex !== -1) {
|
|
66
|
+
flags.set(arg.slice(2, eqIndex), arg.slice(eqIndex + 1));
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const key = arg.slice(2);
|
|
70
|
+
const next = argv[i + 1];
|
|
71
|
+
if (next !== void 0 && !next.startsWith("--")) {
|
|
72
|
+
flags.set(key, next);
|
|
73
|
+
i += 1;
|
|
74
|
+
} else {
|
|
75
|
+
flags.set(key, "true");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { positional, flags };
|
|
79
|
+
}
|
|
80
|
+
async function pathExists(target) {
|
|
81
|
+
try {
|
|
82
|
+
await fs.access(target);
|
|
83
|
+
return true;
|
|
84
|
+
} catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function copyTemplate(srcDir, destDir, replacements) {
|
|
89
|
+
const entries = await fs.readdir(srcDir, { withFileTypes: true });
|
|
90
|
+
for (const entry of entries) {
|
|
91
|
+
const srcPath = path.join(srcDir, entry.name);
|
|
92
|
+
const destName = DOTFILE_RENAMES[entry.name] ?? entry.name;
|
|
93
|
+
const destPath = path.join(destDir, destName);
|
|
94
|
+
if (entry.isDirectory()) {
|
|
95
|
+
await fs.mkdir(destPath, { recursive: true });
|
|
96
|
+
await copyTemplate(srcPath, destPath, replacements);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const ext = path.extname(entry.name).toLowerCase();
|
|
100
|
+
if (BINARY_EXTENSIONS.has(ext)) {
|
|
101
|
+
await fs.copyFile(srcPath, destPath);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
let content = await fs.readFile(srcPath, "utf8");
|
|
105
|
+
for (const [key, value] of Object.entries(replacements)) {
|
|
106
|
+
content = content.replaceAll(`{{${key}}}`, value);
|
|
107
|
+
}
|
|
108
|
+
await fs.writeFile(destPath, content);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function createPlugin(argv) {
|
|
112
|
+
const { positional, flags } = parseArgs(argv);
|
|
113
|
+
let targetName = positional[0];
|
|
114
|
+
if (!targetName) {
|
|
115
|
+
const response = await prompts({
|
|
116
|
+
type: "text",
|
|
117
|
+
name: "name",
|
|
118
|
+
message: "Plugin name (used for the folder and plugin_key)",
|
|
119
|
+
initial: "my-cervio-plugin"
|
|
120
|
+
});
|
|
121
|
+
targetName = response.name;
|
|
122
|
+
}
|
|
123
|
+
if (!targetName || typeof targetName !== "string") {
|
|
124
|
+
console.error("A plugin name is required.");
|
|
125
|
+
process.exit(1);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const pluginKey = toKebabCase(targetName);
|
|
129
|
+
if (!pluginKey) {
|
|
130
|
+
console.error(`"${targetName}" does not produce a valid plugin_key.`);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const targetDir = path.resolve(process.cwd(), targetName);
|
|
135
|
+
const baseName = path.basename(targetDir);
|
|
136
|
+
if (RESERVED_NAMES.has(baseName)) {
|
|
137
|
+
console.error(`"${targetName}" is a reserved name - choose another.`);
|
|
138
|
+
process.exit(1);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (await pathExists(targetDir)) {
|
|
142
|
+
const existing = await fs.readdir(targetDir);
|
|
143
|
+
if (existing.length > 0) {
|
|
144
|
+
console.error(`Directory "${targetName}" already exists and is not empty.`);
|
|
145
|
+
process.exit(1);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
let host = flags.get("host") ?? "";
|
|
150
|
+
if (host === "true") host = "";
|
|
151
|
+
if (!host && !flags.has("yes")) {
|
|
152
|
+
const response = await prompts({
|
|
153
|
+
type: "text",
|
|
154
|
+
name: "host",
|
|
155
|
+
message: "Cervio host (e.g. https://your-org.cervio.app) - leave blank to fill in cervio.json later"
|
|
156
|
+
});
|
|
157
|
+
host = typeof response.host === "string" ? response.host : "";
|
|
158
|
+
}
|
|
159
|
+
const routeSlug = flags.get("route-slug") || pluginKey;
|
|
160
|
+
const rawType = (flags.get("type") || "route").toLowerCase();
|
|
161
|
+
const kind = TYPE_ALIASES[rawType];
|
|
162
|
+
if (!kind) {
|
|
163
|
+
console.error(`Unknown --type "${rawType}". Use one of: route, task, policy.`);
|
|
164
|
+
process.exit(1);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const template = TEMPLATES[kind];
|
|
168
|
+
const isPolicy = kind === "policy";
|
|
169
|
+
await fs.mkdir(targetDir, { recursive: true });
|
|
170
|
+
await copyTemplate(template.dir, targetDir, {
|
|
171
|
+
PLUGIN_NAME: targetName,
|
|
172
|
+
PLUGIN_KEY: pluginKey,
|
|
173
|
+
ROUTE_SLUG: routeSlug,
|
|
174
|
+
HOST: host.trim().replace(/\/+$/, "")
|
|
175
|
+
});
|
|
176
|
+
if (isPolicy) {
|
|
177
|
+
const manifestPath = path.join(targetDir, "manifest.json");
|
|
178
|
+
try {
|
|
179
|
+
const raw = await fs.readFile(manifestPath, "utf8");
|
|
180
|
+
const parsed = JSON.parse(raw);
|
|
181
|
+
parsed.plugin_key = pluginKey;
|
|
182
|
+
parsed.plugin_name = targetName;
|
|
183
|
+
parsed.plugin_type = "policy";
|
|
184
|
+
await fs.writeFile(manifestPath, `${JSON.stringify(parsed, null, 2)}
|
|
185
|
+
`);
|
|
186
|
+
} catch {
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
console.log("");
|
|
190
|
+
console.log(`\u2714 Created ${targetName} at ${targetDir} (${template.label})`);
|
|
191
|
+
console.log("");
|
|
192
|
+
console.log("Next steps:");
|
|
193
|
+
console.log(` cd ${targetName}`);
|
|
194
|
+
for (const line of template.next) console.log(` ${line}`);
|
|
195
|
+
console.log("");
|
|
196
|
+
if (!isPolicy) {
|
|
197
|
+
console.log("Read AGENTS.md before iterating with an LLM coding agent.");
|
|
198
|
+
}
|
|
199
|
+
if (!host) {
|
|
200
|
+
console.log("");
|
|
201
|
+
console.log(
|
|
202
|
+
'Note: no host set - fill in "host" in cervio.json (or pass --host next time) before "cervio push".'
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export {
|
|
208
|
+
createPlugin
|
|
209
|
+
};
|
package/dist/cli.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -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
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cervio/create-plugin",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Scaffold a Cervio plugin (route, task or write-gate) 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-task",
|
|
35
|
+
"template-policy",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=26"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"prompts": "^2.4.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/node": "^26.0.0",
|
|
47
|
+
"@types/prompts": "^2.4.9",
|
|
48
|
+
"tsup": "^9.0.0",
|
|
49
|
+
"typescript": "^5.8.3"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsup --config tsup.config.ts",
|
|
56
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
57
|
+
}
|
|
6
58
|
}
|
|
@@ -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).
|