create-guardio 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.
Files changed (2) hide show
  1. package/index.mjs +42 -22
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -42,7 +42,12 @@ async function main() {
42
42
  server: serverConfig,
43
43
  plugins: [
44
44
  { type: "policy", name: "default", config: { blockedTools: [] } },
45
- { type: "policy", name: "example", config: {} },
45
+ {
46
+ type: "policy",
47
+ name: "example",
48
+ path: "./plugins/example",
49
+ config: {},
50
+ },
46
51
  ],
47
52
  };
48
53
 
@@ -55,7 +60,15 @@ async function main() {
55
60
  private: true,
56
61
  type: "module",
57
62
  description: "Guardio-gated MCP server with optional local plugins",
63
+ scripts: {
64
+ build: "tsc",
65
+ guardio: "node bin/guardio.mjs",
66
+ },
58
67
  dependencies: { "@guardiojs/guardio": "*" },
68
+ devDependencies: {
69
+ typescript: "^5.6.0",
70
+ "@types/node": "^22.0.0",
71
+ },
59
72
  };
60
73
  await writeFile(
61
74
  resolve(guardioPath, "package.json"),
@@ -63,6 +76,23 @@ async function main() {
63
76
  "utf-8"
64
77
  );
65
78
 
79
+ const tsconfig = {
80
+ compilerOptions: {
81
+ target: "ES2022",
82
+ module: "NodeNext",
83
+ moduleResolution: "NodeNext",
84
+ strict: true,
85
+ skipLibCheck: true,
86
+ esModuleInterop: true,
87
+ },
88
+ include: ["plugins/**/*.ts"],
89
+ };
90
+ await writeFile(
91
+ resolve(guardioPath, "tsconfig.json"),
92
+ JSON.stringify(tsconfig, null, 2),
93
+ "utf-8"
94
+ );
95
+
66
96
  await writeFile(
67
97
  resolve(guardioPath, "guardio.config.json"),
68
98
  JSON.stringify(config, null, 2),
@@ -91,33 +121,23 @@ process.exit(result.status ?? 1);
91
121
  PolicyPluginInterface,
92
122
  PolicyRequestContext,
93
123
  PolicyResult,
94
- PolicyPluginDescriptor,
95
124
  } from "@guardiojs/guardio";
96
125
 
97
126
  /**
98
- * Example policy plugin: implements Guardio's PolicyPluginInterface.
99
- * Register in guardio.config.json with: { "type": "policy", "name": "example", "config": {} }
127
+ * Example policy plugin: implements PolicyPluginInterface.
128
+ * Reference in guardio.config.json with: { "type": "policy", "name": "example", "path": "./plugins/example" }
129
+ * Default export must be the plugin instance.
100
130
  */
101
131
  class ExamplePolicyPlugin implements PolicyPluginInterface {
102
132
  readonly name = "example";
103
133
 
104
- constructor(_config: Record<string, unknown>) {
105
- // config from guardio.config.json is passed here
106
- }
107
-
108
134
  evaluate(context: PolicyRequestContext): PolicyResult {
109
135
  // Example: allow all calls. Replace with your policy logic.
110
136
  return "allowed";
111
137
  }
112
138
  }
113
139
 
114
- const descriptor: PolicyPluginDescriptor = {
115
- type: "policy",
116
- name: "example",
117
- create: (config) => new ExamplePolicyPlugin(config),
118
- };
119
-
120
- export default descriptor;
140
+ export default new ExamplePolicyPlugin();
121
141
  `;
122
142
 
123
143
  await writeFile(
@@ -126,16 +146,15 @@ export default descriptor;
126
146
  "utf-8"
127
147
  );
128
148
 
129
- const pluginsReadme = `# Local plugins
130
-
131
- Each subdirectory (e.g. example/) is a plugin. Guardio loads \`index.ts\` from each subdirectory.
149
+ const pluginsReadme = `# Custom plugins (path-based)
132
150
 
133
- Your plugin must implement Guardio's interface and export a descriptor:
151
+ Add a plugin by setting \`path\` in \`guardio.config.json\` to a directory that contains \`index.js\` or \`index.mjs\` (compile from \`index.ts\` with \`npm run build\`).
134
152
 
135
- - Policy: \`PolicyPluginInterface\` and \`PolicyPluginDescriptor\` (type "policy", create() returns instance with evaluate()).
136
- - Intervention: \`InterventionPluginInterface\` and \`InterventionPluginDescriptor\` (type "intervention", create() returns instance with act()).
153
+ - The directory must have \`index.js\` or \`index.mjs\` whose **default export is the plugin instance** (no descriptor).
154
+ - Policy: implement \`PolicyPluginInterface\` (name, evaluate). Config: \`{ "type": "policy", "name": "my-policy", "path": "./plugins/my-policy" }\`.
155
+ - Intervention: implement \`InterventionPluginInterface\` (name, act). Config: \`{ "type": "intervention", "name": "my-intervention", "path": "./plugins/my-intervention" }\`.
137
156
 
138
- Import types from "@guardiojs/guardio". Add the plugin name to \`guardio.config.json\` in the \`plugins\` array to enable it.
157
+ Import types from "@guardiojs/guardio". See example/ for a policy plugin.
139
158
  `;
140
159
 
141
160
  await writeFile(
@@ -150,6 +169,7 @@ Import types from "@guardiojs/guardio". Add the plugin name to \`guardio.config.
150
169
  console.log("\n---\n");
151
170
  console.log("Next steps");
152
171
  console.log(" cd " + guardioDir + " && npm install");
172
+ console.log(" npm run build # compile plugins (index.ts → index.js)");
153
173
  console.log("");
154
174
  console.log("Add to MCP client");
155
175
  console.log("# Copy/paste the shown command\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-guardio",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Scaffold a Guardio project",
5
5
  "type": "module",
6
6
  "bin": {