@guardiojs/guardio 0.0.1
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/README.md +213 -0
- package/bin/guardio.mjs +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +74 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/PluginManager.d.ts +40 -0
- package/dist/config/PluginManager.d.ts.map +1 -0
- package/dist/config/PluginManager.js +130 -0
- package/dist/config/PluginManager.js.map +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/types.d.ts +37 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/core/GuardioCore.d.ts +19 -0
- package/dist/core/GuardioCore.d.ts.map +1 -0
- package/dist/core/GuardioCore.js +115 -0
- package/dist/core/GuardioCore.js.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/types.d.ts +29 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/InterventionPluginInterface.d.ts +20 -0
- package/dist/interfaces/InterventionPluginInterface.d.ts.map +1 -0
- package/dist/interfaces/InterventionPluginInterface.js +2 -0
- package/dist/interfaces/InterventionPluginInterface.js.map +1 -0
- package/dist/interfaces/InterventionTypes.d.ts +8 -0
- package/dist/interfaces/InterventionTypes.d.ts.map +1 -0
- package/dist/interfaces/InterventionTypes.js +2 -0
- package/dist/interfaces/InterventionTypes.js.map +1 -0
- package/dist/interfaces/NotificationPluginInterface.d.ts +13 -0
- package/dist/interfaces/NotificationPluginInterface.d.ts.map +1 -0
- package/dist/interfaces/NotificationPluginInterface.js +2 -0
- package/dist/interfaces/NotificationPluginInterface.js.map +1 -0
- package/dist/interfaces/PolicyPluginInterface.d.ts +16 -0
- package/dist/interfaces/PolicyPluginInterface.d.ts.map +1 -0
- package/dist/interfaces/PolicyPluginInterface.js +2 -0
- package/dist/interfaces/PolicyPluginInterface.js.map +1 -0
- package/dist/interfaces/PolicyTypes.d.ts +12 -0
- package/dist/interfaces/PolicyTypes.d.ts.map +1 -0
- package/dist/interfaces/PolicyTypes.js +2 -0
- package/dist/interfaces/PolicyTypes.js.map +1 -0
- package/dist/interfaces/index.d.ts +6 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +2 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/plugins/intervention/DefaultInterventionPlugin.d.ts +12 -0
- package/dist/plugins/intervention/DefaultInterventionPlugin.d.ts.map +1 -0
- package/dist/plugins/intervention/DefaultInterventionPlugin.js +14 -0
- package/dist/plugins/intervention/DefaultInterventionPlugin.js.map +1 -0
- package/dist/plugins/intervention/HttpInterventionPlugin.d.ts +22 -0
- package/dist/plugins/intervention/HttpInterventionPlugin.d.ts.map +1 -0
- package/dist/plugins/intervention/HttpInterventionPlugin.js +99 -0
- package/dist/plugins/intervention/HttpInterventionPlugin.js.map +1 -0
- package/dist/plugins/intervention/index.d.ts +3 -0
- package/dist/plugins/intervention/index.d.ts.map +1 -0
- package/dist/plugins/intervention/index.js +3 -0
- package/dist/plugins/intervention/index.js.map +1 -0
- package/dist/plugins/notification/DefaultNotificationPlugin.d.ts +8 -0
- package/dist/plugins/notification/DefaultNotificationPlugin.d.ts.map +1 -0
- package/dist/plugins/notification/DefaultNotificationPlugin.js +9 -0
- package/dist/plugins/notification/DefaultNotificationPlugin.js.map +1 -0
- package/dist/plugins/notification/index.d.ts +2 -0
- package/dist/plugins/notification/index.d.ts.map +1 -0
- package/dist/plugins/notification/index.js +2 -0
- package/dist/plugins/notification/index.js.map +1 -0
- package/dist/plugins/policy/DefaultPolicyPlugin.d.ts +16 -0
- package/dist/plugins/policy/DefaultPolicyPlugin.d.ts.map +1 -0
- package/dist/plugins/policy/DefaultPolicyPlugin.js +21 -0
- package/dist/plugins/policy/DefaultPolicyPlugin.js.map +1 -0
- package/dist/plugins/policy/RegexPolicyPlugin.d.ts +38 -0
- package/dist/plugins/policy/RegexPolicyPlugin.d.ts.map +1 -0
- package/dist/plugins/policy/RegexPolicyPlugin.js +65 -0
- package/dist/plugins/policy/RegexPolicyPlugin.js.map +1 -0
- package/dist/plugins/policy/index.d.ts +3 -0
- package/dist/plugins/policy/index.d.ts.map +1 -0
- package/dist/plugins/policy/index.js +3 -0
- package/dist/plugins/policy/index.js.map +1 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Guardio
|
|
2
|
+
|
|
3
|
+
A security layer that sits between an MCP client (e.g. Cursor) and an MCP server. It proxies JSON-RPC and lets you **policy-check** and **intervene** on `tools/call` requests before they reach the real server.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
- **Proxies** stdin/stdout between the client and the real MCP server.
|
|
8
|
+
- **Intercepts** `tools/call` requests and runs them through:
|
|
9
|
+
1. **Policy plugins** – each can allow, block, or require approval. If any policy returns _blocked_, the call is rejected.
|
|
10
|
+
2. **Intervention plugins** – each can run side effects (e.g. log, show approval UI). If any returns _reject_, the call is rejected.
|
|
11
|
+
- **Forwards** the call to the real MCP server only when all policies and interventions allow it.
|
|
12
|
+
|
|
13
|
+
## Install and build
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm install
|
|
17
|
+
pnpm run build
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The CLI is available as `guardio` (or via `pnpm run guardio`).
|
|
21
|
+
|
|
22
|
+
## Quick start: create Guardio (per MCP server)
|
|
23
|
+
|
|
24
|
+
Scaffold a directory with a config and a bin you can point your MCP client at:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx create-guardio
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
You will be prompted for:
|
|
31
|
+
|
|
32
|
+
- **Guardio directory** – e.g. `./my-security` (created for you).
|
|
33
|
+
- **MCP Server command** – e.g. `node`, `python`.
|
|
34
|
+
- **MCP Server args** – e.g. path to your server script (comma-separated if multiple).
|
|
35
|
+
|
|
36
|
+
This writes **guardio.config.json** (with `server` and default plugins) and **bin/guardio** in that directory. At the end you’ll see:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
Add to MCP client
|
|
40
|
+
|
|
41
|
+
# Copy/paste the shown command
|
|
42
|
+
|
|
43
|
+
./my-security/bin/guardio
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Add that path to your MCP client config (e.g. Cursor’s `mcp.json`) as the command to run for this MCP server.
|
|
47
|
+
|
|
48
|
+
## Configuration
|
|
49
|
+
|
|
50
|
+
Guardio loads a config file either from **current working directory** (when run without `--config`) or from the path given by **`--config`**. It looks for (in order):
|
|
51
|
+
|
|
52
|
+
- `guardio.config.js`
|
|
53
|
+
- `guardio.config.ts`
|
|
54
|
+
- `guardio.config.json`
|
|
55
|
+
|
|
56
|
+
The config must have a **plugins** array. It can optionally have **server** (used when you run with `--config`):
|
|
57
|
+
|
|
58
|
+
- **`server`** – optional. When present and you use `--config`, Guardio uses this instead of argv/env to run the MCP server: **`{ "type": "command", "command": "node", "args": ["path/to/server.js"] }`**.
|
|
59
|
+
|
|
60
|
+
Each **plugins** entry has:
|
|
61
|
+
|
|
62
|
+
- **`type`** – `"policy"` or `"intervention"`
|
|
63
|
+
- **`name`** – which plugin to use (e.g. `"default"`, `"regex"`, `"http"`)
|
|
64
|
+
- **`config`** – optional object passed to the plugin
|
|
65
|
+
|
|
66
|
+
### Example: `guardio.config.json`
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"server": {
|
|
71
|
+
"type": "command",
|
|
72
|
+
"command": "node",
|
|
73
|
+
"args": ["/path/to/your-mcp-server/index.js"]
|
|
74
|
+
},
|
|
75
|
+
"plugins": [
|
|
76
|
+
{
|
|
77
|
+
"type": "policy",
|
|
78
|
+
"name": "regex",
|
|
79
|
+
"config": {
|
|
80
|
+
"rules": [
|
|
81
|
+
{
|
|
82
|
+
"name": "get_weather",
|
|
83
|
+
"parameter_name": "location",
|
|
84
|
+
"regex": "secret|internal|localhost",
|
|
85
|
+
"flags": "i"
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"type": "intervention",
|
|
92
|
+
"name": "http",
|
|
93
|
+
"config": { "port": 3939, "timeoutMs": 120000 }
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
When using **`--config /path/to/guardio.config.json`**, the **server** block above is used automatically; you don’t pass the MCP server command on the command line.
|
|
100
|
+
|
|
101
|
+
## Running Guardio (CLI)
|
|
102
|
+
|
|
103
|
+
You must tell Guardio **which command to run** for the real MCP server (unless you use `--config` with a config that has **server**). Options:
|
|
104
|
+
|
|
105
|
+
### 1. Direct arguments
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
guardio node /path/to/your-mcp-server/index.js
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 2. After `--`
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
guardio -- node /path/to/your-mcp-server/index.js
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 3. Environment variables
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
export GUARDIO_COMMAND=node
|
|
121
|
+
export GUARDIO_ARGS=/path/to/your-mcp-server/index.js
|
|
122
|
+
guardio
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Or use `MCP_REAL_TOOL_COMMAND` and `MCP_REAL_TOOL_ARGS` (comma-separated) for the same purpose.
|
|
126
|
+
|
|
127
|
+
### 4. Config file with `--config`
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
guardio --config /path/to/guardio.config.json
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
If the config contains **server** with **type `"command"`**, that command and args are used; no need to pass them on the command line. The config path is also used to load **plugins**.
|
|
134
|
+
|
|
135
|
+
Guardio will **spawn** that command and proxy stdin/stdout to it. Make sure a **guardio config** exists (in the current working directory or via `--config`).
|
|
136
|
+
|
|
137
|
+
## Using with Cursor MCP
|
|
138
|
+
|
|
139
|
+
Point Cursor’s MCP config to Guardio instead of the real server. Example `.cursor/mcp.json`:
|
|
140
|
+
|
|
141
|
+
```json
|
|
142
|
+
{
|
|
143
|
+
"mcpServers": {
|
|
144
|
+
"my-tool-gated": {
|
|
145
|
+
"command": "node",
|
|
146
|
+
"args": [
|
|
147
|
+
"/path/to/guardio-draft/bin/guardio.mjs",
|
|
148
|
+
"--",
|
|
149
|
+
"node",
|
|
150
|
+
"/path/to/actual-mcp-server/index.js"
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Or use the built-in bin if the package is linked/installed:
|
|
158
|
+
|
|
159
|
+
```json
|
|
160
|
+
{
|
|
161
|
+
"mcpServers": {
|
|
162
|
+
"my-tool-gated": {
|
|
163
|
+
"command": "guardio",
|
|
164
|
+
"args": ["--", "node", "/path/to/actual-mcp-server/index.js"]
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Cursor talks to Guardio; Guardio applies policies and interventions, then talks to your real MCP server.
|
|
171
|
+
|
|
172
|
+
## Built-in plugins
|
|
173
|
+
|
|
174
|
+
### Policy plugins
|
|
175
|
+
|
|
176
|
+
- **`default`** – Block calls by tool name. Config required: `{ blockedTools: ["tool_a", "tool_b"] }`. No default block list.
|
|
177
|
+
- **`regex`** – Blocks based on rules aligned to the tools/call schema. Config:
|
|
178
|
+
- **`rules`** – array of:
|
|
179
|
+
- **`name`** – tool name (exact match).
|
|
180
|
+
- **`parameter_name`** – optional; if set, the regex is applied to this argument’s value; otherwise to the tool name.
|
|
181
|
+
- **`regex`** – pattern string (if it matches, the call is blocked).
|
|
182
|
+
- **`flags`** – optional RegExp flags (e.g. `"i"`).
|
|
183
|
+
- **`debug`** – optional boolean; if `true`, logs evaluation details to stderr.
|
|
184
|
+
|
|
185
|
+
### Intervention plugins
|
|
186
|
+
|
|
187
|
+
- **`default`** – No-op. Config: `{}`.
|
|
188
|
+
- **`http`** – Starts an HTTP server and waits for user approve/reject before forwarding. Config:
|
|
189
|
+
- **`port`** – default `3939`.
|
|
190
|
+
- **`timeoutMs`** – approval timeout in ms; default `120000`.
|
|
191
|
+
|
|
192
|
+
## Programmatic API
|
|
193
|
+
|
|
194
|
+
You can use the core and plugins in code:
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import { GuardioCore } from "@guardiojs/guardio";
|
|
198
|
+
|
|
199
|
+
const core = new GuardioCore({
|
|
200
|
+
command: "node",
|
|
201
|
+
args: ["/path/to/mcp-server/index.js"],
|
|
202
|
+
cwd: "/path/to/dir/with/guardio.config.json", // optional
|
|
203
|
+
configPath: "/path/to/guardio.config.json", // optional
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
await core.run();
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Policy and intervention plugins are loaded from the config file; you can also implement custom plugins and register them with `PluginManager` before running the core.
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
Apache-2.0
|
package/bin/guardio.mjs
ADDED
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI – parse argv (including --config), build config, run GuardioCore.
|
|
3
|
+
*/
|
|
4
|
+
import { resolve, dirname } from "node:path";
|
|
5
|
+
import { GuardioCore } from "./core/index.js";
|
|
6
|
+
import { loadConfigFromPath } from "./config/index.js";
|
|
7
|
+
const configIdx = process.argv.indexOf("--config");
|
|
8
|
+
const configPathArg = configIdx >= 0 && process.argv[configIdx + 1]
|
|
9
|
+
? process.argv[configIdx + 1]
|
|
10
|
+
: null;
|
|
11
|
+
async function main() {
|
|
12
|
+
let command;
|
|
13
|
+
let args;
|
|
14
|
+
let cwd;
|
|
15
|
+
let configPath;
|
|
16
|
+
if (configPathArg) {
|
|
17
|
+
const resolved = resolve(configPathArg);
|
|
18
|
+
const config = await loadConfigFromPath(resolved);
|
|
19
|
+
configPath = resolved;
|
|
20
|
+
cwd = dirname(resolved);
|
|
21
|
+
if (config.server?.type === "command") {
|
|
22
|
+
command = config.server.command;
|
|
23
|
+
args = config.server.args ?? [];
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
command =
|
|
27
|
+
process.env.GUARDIO_COMMAND ??
|
|
28
|
+
process.env.MCP_REAL_TOOL_COMMAND ??
|
|
29
|
+
"node";
|
|
30
|
+
args = process.env.GUARDIO_ARGS
|
|
31
|
+
? process.env.GUARDIO_ARGS.split(",").map((s) => s.trim())
|
|
32
|
+
: process.env.MCP_REAL_TOOL_ARGS
|
|
33
|
+
? process.env.MCP_REAL_TOOL_ARGS.split(",").map((s) => s.trim())
|
|
34
|
+
: ["/path/to/your/actual-mcp-server/index.js"];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const dashDashIdx = process.argv.indexOf("--");
|
|
39
|
+
const argvAfterDash = dashDashIdx >= 0 ? process.argv.slice(dashDashIdx + 1) : [];
|
|
40
|
+
const directArgs = dashDashIdx === -1 && process.argv.length >= 3
|
|
41
|
+
? process.argv.slice(2)
|
|
42
|
+
: [];
|
|
43
|
+
command =
|
|
44
|
+
argvAfterDash.length > 0
|
|
45
|
+
? argvAfterDash[0]
|
|
46
|
+
: directArgs.length > 0
|
|
47
|
+
? directArgs[0]
|
|
48
|
+
: process.env.GUARDIO_COMMAND ??
|
|
49
|
+
process.env.MCP_REAL_TOOL_COMMAND ??
|
|
50
|
+
"node";
|
|
51
|
+
args =
|
|
52
|
+
argvAfterDash.length > 1
|
|
53
|
+
? argvAfterDash.slice(1)
|
|
54
|
+
: directArgs.length > 1
|
|
55
|
+
? directArgs.slice(1)
|
|
56
|
+
: process.env.GUARDIO_ARGS
|
|
57
|
+
? process.env.GUARDIO_ARGS.split(",").map((s) => s.trim())
|
|
58
|
+
: process.env.MCP_REAL_TOOL_ARGS
|
|
59
|
+
? process.env.MCP_REAL_TOOL_ARGS.split(",").map((s) => s.trim())
|
|
60
|
+
: ["/path/to/your/actual-mcp-server/index.js"];
|
|
61
|
+
}
|
|
62
|
+
const core = new GuardioCore({
|
|
63
|
+
command,
|
|
64
|
+
args,
|
|
65
|
+
cwd,
|
|
66
|
+
configPath,
|
|
67
|
+
});
|
|
68
|
+
await core.run();
|
|
69
|
+
}
|
|
70
|
+
main().catch((err) => {
|
|
71
|
+
console.error("Guardio failed to start:", err);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
});
|
|
74
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AACnD,MAAM,a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AAI,EAAE,CAAC;wBAC1D,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB;4BAChC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;4BAChE,CAAC,CAAC,CAAC,0CAA0C,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC;QAC3B,OAAO;QACP,IAAI;QACJ,GAAG;QACH,UAAU;KACX,CAAC,CAAC;IAEH,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;AACnB,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,GAAG,CAAC,CAAC;IAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { GuardioConfig } from "./types.js";
|
|
2
|
+
import type { PolicyPluginInterface } from "../interfaces/PolicyPluginInterface.js";
|
|
3
|
+
import type { InterventionPluginInterface } from "../interfaces/InterventionPluginInterface.js";
|
|
4
|
+
export type PolicyPluginFactory = (config?: Record<string, unknown>) => PolicyPluginInterface;
|
|
5
|
+
export type InterventionPluginFactory = (config?: Record<string, unknown>) => InterventionPluginInterface;
|
|
6
|
+
/**
|
|
7
|
+
* Loads GuardioConfig from a path. Supports .json (readFile + parse) and .js/.ts (dynamic import).
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadConfigFromPath(configPath: string): Promise<GuardioConfig>;
|
|
10
|
+
export declare class PluginManager {
|
|
11
|
+
private config;
|
|
12
|
+
private configPath;
|
|
13
|
+
private policyPlugins;
|
|
14
|
+
private interventionPlugins;
|
|
15
|
+
/**
|
|
16
|
+
* Register a policy plugin factory by name (e.g. for custom plugins).
|
|
17
|
+
*/
|
|
18
|
+
registerPolicyPlugin(name: string, factory: PolicyPluginFactory): void;
|
|
19
|
+
/**
|
|
20
|
+
* Register an intervention plugin factory by name (e.g. for custom plugins).
|
|
21
|
+
*/
|
|
22
|
+
registerInterventionPlugin(name: string, factory: InterventionPluginFactory): void;
|
|
23
|
+
/**
|
|
24
|
+
* Load config from cwd (or optional path). Idempotent; subsequent calls use cached config if path unchanged.
|
|
25
|
+
*/
|
|
26
|
+
loadConfig(cwd?: string, configPath?: string): Promise<GuardioConfig>;
|
|
27
|
+
/**
|
|
28
|
+
* Get the list of policy plugin instances from the loaded config. Calls loadConfig() if not loaded.
|
|
29
|
+
*/
|
|
30
|
+
getPolicyPlugins(cwd?: string, configPath?: string): Promise<PolicyPluginInterface[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Get a single policy plugin for the core: first from config, or throws if none.
|
|
33
|
+
*/
|
|
34
|
+
getPolicyPlugin(cwd?: string, configPath?: string): Promise<PolicyPluginInterface>;
|
|
35
|
+
/**
|
|
36
|
+
* Get the list of intervention plugin instances from the loaded config. Calls loadConfig() if not loaded.
|
|
37
|
+
*/
|
|
38
|
+
getInterventionPlugins(cwd?: string, configPath?: string): Promise<InterventionPluginInterface[]>;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=PluginManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/config/PluginManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAiC,MAAM,YAAY,CAAC;AAC/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AACpF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAUhG,MAAM,MAAM,mBAAmB,GAAG,CAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,qBAAqB,CAAC;AAE3B,MAAM,MAAM,yBAAyB,GAAG,CACtC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,2BAA2B,CAAC;AA4BjC;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,CAAC,CAcxB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,aAAa,CAAwC;IAC7D,OAAO,CAAC,mBAAmB,CAA8C;IAEzE;;OAEG;IACH,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAItE;;OAEG;IACH,0BAA0B,CACxB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,yBAAyB,GACjC,IAAI;IAKP;;OAEG;IACG,UAAU,CACd,GAAG,GAAE,MAAsB,EAC3B,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,aAAa,CAAC;IAiBzB;;OAEG;IACG,gBAAgB,CACpB,GAAG,GAAE,MAAsB,EAC3B,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAyBnC;;OAEG;IACG,eAAe,CACnB,GAAG,CAAC,EAAE,MAAM,EACZ,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,CAAC;IAUjC;;OAEG;IACG,sBAAsB,CAC1B,GAAG,GAAE,MAAsB,EAC3B,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,2BAA2B,EAAE,CAAC;CAwB1C"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { DefaultPolicyPlugin, RegexPolicyPlugin, } from "../plugins/policy/index.js";
|
|
5
|
+
import { DefaultInterventionPlugin, HttpInterventionPlugin, } from "../plugins/intervention/index.js";
|
|
6
|
+
const policyRegistry = {
|
|
7
|
+
default: (config) => new DefaultPolicyPlugin(config ?? {}),
|
|
8
|
+
regex: (config) => new RegexPolicyPlugin(config ?? {}),
|
|
9
|
+
};
|
|
10
|
+
const interventionRegistry = {
|
|
11
|
+
default: (config) => new DefaultInterventionPlugin(config),
|
|
12
|
+
http: (config) => new HttpInterventionPlugin(config),
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Resolves path to config file: first .js, then .ts, then .json (from cwd).
|
|
16
|
+
*/
|
|
17
|
+
function getConfigPath(cwd) {
|
|
18
|
+
const names = [
|
|
19
|
+
"guardio.config.js",
|
|
20
|
+
"guardio.config.ts",
|
|
21
|
+
"guardio.config.json",
|
|
22
|
+
];
|
|
23
|
+
for (const name of names) {
|
|
24
|
+
const p = join(cwd, name);
|
|
25
|
+
if (existsSync(p))
|
|
26
|
+
return p;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Loads GuardioConfig from a path. Supports .json (readFile + parse) and .js/.ts (dynamic import).
|
|
32
|
+
*/
|
|
33
|
+
export async function loadConfigFromPath(configPath) {
|
|
34
|
+
if (configPath.endsWith(".json")) {
|
|
35
|
+
const raw = readFileSync(configPath, "utf-8");
|
|
36
|
+
return JSON.parse(raw);
|
|
37
|
+
}
|
|
38
|
+
const url = pathToFileURL(configPath).href;
|
|
39
|
+
const mod = await import(url);
|
|
40
|
+
const config = mod.default ?? mod;
|
|
41
|
+
if (!config || typeof config !== "object" || !Array.isArray(config.plugins)) {
|
|
42
|
+
throw new Error(`Invalid guardio config: expected default export with plugins array (at ${configPath})`);
|
|
43
|
+
}
|
|
44
|
+
return config;
|
|
45
|
+
}
|
|
46
|
+
export class PluginManager {
|
|
47
|
+
config = null;
|
|
48
|
+
configPath = null;
|
|
49
|
+
policyPlugins = null;
|
|
50
|
+
interventionPlugins = null;
|
|
51
|
+
/**
|
|
52
|
+
* Register a policy plugin factory by name (e.g. for custom plugins).
|
|
53
|
+
*/
|
|
54
|
+
registerPolicyPlugin(name, factory) {
|
|
55
|
+
policyRegistry[name] = factory;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Register an intervention plugin factory by name (e.g. for custom plugins).
|
|
59
|
+
*/
|
|
60
|
+
registerInterventionPlugin(name, factory) {
|
|
61
|
+
interventionRegistry[name] =
|
|
62
|
+
factory;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Load config from cwd (or optional path). Idempotent; subsequent calls use cached config if path unchanged.
|
|
66
|
+
*/
|
|
67
|
+
async loadConfig(cwd = process.cwd(), configPath) {
|
|
68
|
+
const path = configPath ?? getConfigPath(cwd);
|
|
69
|
+
if (!path) {
|
|
70
|
+
throw new Error(`No guardio config found in ${cwd}. Add guardio.config.js, guardio.config.ts, or guardio.config.json`);
|
|
71
|
+
}
|
|
72
|
+
if (this.configPath === path && this.config !== null) {
|
|
73
|
+
return this.config;
|
|
74
|
+
}
|
|
75
|
+
this.configPath = path;
|
|
76
|
+
this.config = await loadConfigFromPath(path);
|
|
77
|
+
this.policyPlugins = null;
|
|
78
|
+
this.interventionPlugins = null;
|
|
79
|
+
return this.config;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the list of policy plugin instances from the loaded config. Calls loadConfig() if not loaded.
|
|
83
|
+
*/
|
|
84
|
+
async getPolicyPlugins(cwd = process.cwd(), configPath) {
|
|
85
|
+
await this.loadConfig(cwd, configPath);
|
|
86
|
+
if (this.policyPlugins !== null)
|
|
87
|
+
return this.policyPlugins;
|
|
88
|
+
const plugins = (this.config.plugins ?? []).filter((p) => p.type === "policy");
|
|
89
|
+
const instances = [];
|
|
90
|
+
for (const entry of plugins) {
|
|
91
|
+
const factory = policyRegistry[entry.name];
|
|
92
|
+
if (!factory) {
|
|
93
|
+
throw new Error(`Unknown policy plugin name: "${entry.name}". Registered: ${Object.keys(policyRegistry).join(", ")}`);
|
|
94
|
+
}
|
|
95
|
+
instances.push(factory(entry.config ?? {}));
|
|
96
|
+
}
|
|
97
|
+
this.policyPlugins = instances;
|
|
98
|
+
return instances;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get a single policy plugin for the core: first from config, or throws if none.
|
|
102
|
+
*/
|
|
103
|
+
async getPolicyPlugin(cwd, configPath) {
|
|
104
|
+
const list = await this.getPolicyPlugins(cwd, configPath);
|
|
105
|
+
if (list.length === 0) {
|
|
106
|
+
throw new Error("No policy plugins in config. Add at least one plugin with type 'policy'.");
|
|
107
|
+
}
|
|
108
|
+
return list[0];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get the list of intervention plugin instances from the loaded config. Calls loadConfig() if not loaded.
|
|
112
|
+
*/
|
|
113
|
+
async getInterventionPlugins(cwd = process.cwd(), configPath) {
|
|
114
|
+
await this.loadConfig(cwd, configPath);
|
|
115
|
+
if (this.interventionPlugins !== null)
|
|
116
|
+
return this.interventionPlugins;
|
|
117
|
+
const plugins = (this.config.plugins ?? []).filter((p) => p.type === "intervention");
|
|
118
|
+
const instances = [];
|
|
119
|
+
for (const entry of plugins) {
|
|
120
|
+
const factory = interventionRegistry[entry.name];
|
|
121
|
+
if (!factory) {
|
|
122
|
+
throw new Error(`Unknown intervention plugin name: "${entry.name}". Registered: ${Object.keys(interventionRegistry).join(", ")}`);
|
|
123
|
+
}
|
|
124
|
+
instances.push(factory(entry.config ?? {}));
|
|
125
|
+
}
|
|
126
|
+
this.interventionPlugins = instances;
|
|
127
|
+
return instances;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=PluginManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginManager.js","sourceRoot":"","sources":["../../src/config/PluginManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM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}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { PluginManager, loadConfigFromPath } from "./PluginManager.js";
|
|
2
|
+
export type { PolicyPluginFactory } from "./PluginManager.js";
|
|
3
|
+
export type { GuardioConfig, GuardioServerConfig, PolicyPluginConfigEntry, InterventionPluginConfigEntry, PluginConfigEntry, } from "./types.js";
|
|
4
|
+
export type { InterventionPluginFactory } from "./PluginManager.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACvE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Policy plugin entry in guardio config.
|
|
3
|
+
*/
|
|
4
|
+
export interface PolicyPluginConfigEntry {
|
|
5
|
+
type: "policy";
|
|
6
|
+
name: string;
|
|
7
|
+
config?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Intervention plugin entry in guardio config.
|
|
11
|
+
*/
|
|
12
|
+
export interface InterventionPluginConfigEntry {
|
|
13
|
+
type: "intervention";
|
|
14
|
+
name: string;
|
|
15
|
+
config?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Any plugin entry in guardio config.
|
|
19
|
+
*/
|
|
20
|
+
export type PluginConfigEntry = PolicyPluginConfigEntry | InterventionPluginConfigEntry;
|
|
21
|
+
/**
|
|
22
|
+
* MCP server to proxy to (spawn command).
|
|
23
|
+
*/
|
|
24
|
+
export interface GuardioServerConfig {
|
|
25
|
+
type: "command";
|
|
26
|
+
command: string;
|
|
27
|
+
args: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Guardio config file shape (default export of guardio.config.ts / .json).
|
|
31
|
+
*/
|
|
32
|
+
export interface GuardioConfig {
|
|
33
|
+
/** MCP server to proxy to. When present, CLI uses this instead of argv. */
|
|
34
|
+
server?: GuardioServerConfig;
|
|
35
|
+
plugins: PluginConfigEntry[];
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,uBAAuB,GACvB,6BAA6B,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,2EAA2E;IAC3E,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,OAAO,EAAE,iBAAiB,EAAE,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { GuardioCoreConfig } from "./types.js";
|
|
2
|
+
export declare class GuardioCore {
|
|
3
|
+
private readonly config;
|
|
4
|
+
private policyPlugins;
|
|
5
|
+
private interventionPlugins;
|
|
6
|
+
private child;
|
|
7
|
+
private appInterface;
|
|
8
|
+
private toolInterface;
|
|
9
|
+
private pendingResponseId;
|
|
10
|
+
private readonly appQueue;
|
|
11
|
+
constructor(config: GuardioCoreConfig);
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
private sendErrorResponse;
|
|
14
|
+
private processAppLine;
|
|
15
|
+
private drainAppQueue;
|
|
16
|
+
private attachAppHandler;
|
|
17
|
+
private attachToolHandler;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=GuardioCore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GuardioCore.d.ts","sourceRoot":"","sources":["../../src/core/GuardioCore.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAIpD,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;IAC3C,OAAO,CAAC,aAAa,CAA+B;IACpD,OAAO,CAAC,mBAAmB,CAAqC;IAEhE,OAAO,CAAC,KAAK,CAAyC;IACtD,OAAO,CAAC,YAAY,CAAmC;IACvD,OAAO,CAAC,aAAa,CAAmC;IAExD,OAAO,CAAC,iBAAiB,CAAgC;IACzD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;gBAE7B,MAAM,EAAE,iBAAiB;IAI/B,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAmC1B,OAAO,CAAC,iBAAiB;YAaX,cAAc;IAgD5B,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,iBAAiB;CAc1B"}
|