@guardiojs/guardio 0.0.2 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +50 -54
- package/dist/cli.js.map +1 -1
- package/dist/config/PluginManager.d.ts +4 -0
- package/dist/config/PluginManager.d.ts.map +1 -1
- package/dist/config/PluginManager.js +69 -60
- package/dist/config/PluginManager.js.map +1 -1
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/types.d.ts +29 -25
- package/dist/config/types.d.ts.map +1 -1
- package/dist/core/GuardioActions.d.ts +12 -0
- package/dist/core/GuardioActions.d.ts.map +1 -0
- package/dist/core/GuardioActions.js +12 -0
- package/dist/core/GuardioActions.js.map +1 -0
- package/dist/core/GuardioCore.d.ts +22 -9
- package/dist/core/GuardioCore.d.ts.map +1 -1
- package/dist/core/GuardioCore.js +175 -74
- package/dist/core/GuardioCore.js.map +1 -1
- package/dist/core/GuardioErrorCodes.d.ts +42 -0
- package/dist/core/GuardioErrorCodes.d.ts.map +1 -0
- package/dist/core/GuardioErrorCodes.js +71 -0
- package/dist/core/GuardioErrorCodes.js.map +1 -0
- package/dist/core/transports/create-client-transport.d.ts +14 -0
- package/dist/core/transports/create-client-transport.d.ts.map +1 -0
- package/dist/core/transports/create-client-transport.js +19 -0
- package/dist/core/transports/create-client-transport.js.map +1 -0
- package/dist/core/transports/http-client.d.ts +27 -0
- package/dist/core/transports/http-client.d.ts.map +1 -0
- package/dist/core/transports/http-client.js +86 -0
- package/dist/core/transports/http-client.js.map +1 -0
- package/dist/core/transports/index.d.ts +13 -0
- package/dist/core/transports/index.d.ts.map +1 -0
- package/dist/core/transports/index.js +11 -0
- package/dist/core/transports/index.js.map +1 -0
- package/dist/core/transports/sse-url-transport.d.ts +26 -0
- package/dist/core/transports/sse-url-transport.d.ts.map +1 -0
- package/dist/core/transports/sse-url-transport.js +111 -0
- package/dist/core/transports/sse-url-transport.js.map +1 -0
- package/dist/core/transports/stdio-client.d.ts +12 -0
- package/dist/core/transports/stdio-client.d.ts.map +1 -0
- package/dist/core/transports/stdio-client.js +25 -0
- package/dist/core/transports/stdio-client.js.map +1 -0
- package/dist/core/transports/types.d.ts +21 -0
- package/dist/core/transports/types.d.ts.map +1 -0
- package/dist/core/transports/types.js +2 -0
- package/dist/core/transports/types.js.map +1 -0
- package/dist/core/types.d.ts +40 -4
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +11 -1
- package/dist/core/types.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +4 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +16 -0
- package/dist/logger.js.map +1 -0
- package/dist/plugins/intervention/HttpInterventionPlugin.d.ts.map +1 -1
- package/dist/plugins/intervention/HttpInterventionPlugin.js +4 -7
- package/dist/plugins/intervention/HttpInterventionPlugin.js.map +1 -1
- package/dist/plugins/notification/DefaultNotificationPlugin.d.ts +1 -1
- package/dist/plugins/notification/DefaultNotificationPlugin.d.ts.map +1 -1
- package/dist/plugins/notification/DefaultNotificationPlugin.js +3 -2
- package/dist/plugins/notification/DefaultNotificationPlugin.js.map +1 -1
- package/dist/plugins/policy/DefaultPolicyPlugin.d.ts.map +1 -1
- package/dist/plugins/policy/DefaultPolicyPlugin.js +4 -1
- package/dist/plugins/policy/DefaultPolicyPlugin.js.map +1 -1
- package/dist/plugins/policy/RegexPolicyPlugin.d.ts.map +1 -1
- package/dist/plugins/policy/RegexPolicyPlugin.js +2 -1
- package/dist/plugins/policy/RegexPolicyPlugin.js.map +1 -1
- package/dist/server/index.d.ts +20 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +27 -0
- package/dist/server/index.js.map +1 -0
- package/package.json +4 -6
- package/README.md +0 -225
- package/bin/guardio.mjs +0 -2
package/dist/cli.js
CHANGED
|
@@ -1,75 +1,71 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CLI –
|
|
2
|
+
* CLI – load config, require server type "url" (HTTP/SSE only). Client can be stdio or http.
|
|
3
3
|
*/
|
|
4
4
|
import { resolve, dirname } from "node:path";
|
|
5
5
|
import { GuardioCore } from "./core/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { GuardioHttpServer } from "./server/index.js";
|
|
7
|
+
import { loadConfigFromPath, getConfigPath } from "./config/index.js";
|
|
8
|
+
import { logger } from "./logger.js";
|
|
7
9
|
const configIdx = process.argv.indexOf("--config");
|
|
8
10
|
const configPathArg = configIdx >= 0 && process.argv[configIdx + 1]
|
|
9
11
|
? process.argv[configIdx + 1]
|
|
10
12
|
: null;
|
|
11
13
|
async function main() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
configPath = resolved;
|
|
20
|
-
cwd = dirname(resolved);
|
|
21
|
-
if (config.server?.type === "command") {
|
|
22
|
-
command = config.server.command;
|
|
23
|
-
const configDir = dirname(resolved);
|
|
24
|
-
args = (config.server.args ?? []).map((arg) => resolve(configDir, arg));
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
command =
|
|
28
|
-
process.env.GUARDIO_COMMAND ??
|
|
29
|
-
process.env.MCP_REAL_TOOL_COMMAND ??
|
|
30
|
-
"node";
|
|
31
|
-
args = process.env.GUARDIO_ARGS
|
|
32
|
-
? process.env.GUARDIO_ARGS.split(",").map((s) => s.trim())
|
|
33
|
-
: process.env.MCP_REAL_TOOL_ARGS
|
|
34
|
-
? process.env.MCP_REAL_TOOL_ARGS.split(",").map((s) => s.trim())
|
|
35
|
-
: ["/path/to/your/actual-mcp-server/index.js"];
|
|
36
|
-
}
|
|
14
|
+
logger.debug({ argv: process.argv }, "CLI starting");
|
|
15
|
+
const resolved = configPathArg
|
|
16
|
+
? resolve(configPathArg)
|
|
17
|
+
: getConfigPath(process.cwd());
|
|
18
|
+
if (!resolved) {
|
|
19
|
+
logger.error("No guardio config found. Use --config guardio.config.json or add guardio.config.js/ts/json in cwd.");
|
|
20
|
+
process.exit(1);
|
|
37
21
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
22
|
+
logger.info({ configPath: resolved }, "Loading config");
|
|
23
|
+
const config = await loadConfigFromPath(resolved);
|
|
24
|
+
const configPath = resolved;
|
|
25
|
+
const cwd = dirname(resolved);
|
|
26
|
+
if (!config.server || config.server.type !== "url") {
|
|
27
|
+
logger.error('Guardio requires server: { type: "url", url: "<MCP_SSE_BASE_URL>" } in config.');
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
const server = {
|
|
31
|
+
type: "url",
|
|
32
|
+
url: config.server.url,
|
|
33
|
+
headers: config.server.headers,
|
|
34
|
+
timeoutMs: config.server.timeoutMs,
|
|
35
|
+
};
|
|
36
|
+
const clientConfig = config.client ?? { mode: "stdio" };
|
|
37
|
+
if (clientConfig.mode === "http") {
|
|
38
|
+
const portEnv = process.env.GUARDIO_HTTP_PORT ?? process.env.GUARDIO_CLIENT_PORT;
|
|
39
|
+
const port = portEnv != null && portEnv !== ""
|
|
40
|
+
? parseInt(portEnv, 10)
|
|
41
|
+
: (clientConfig.port ?? 3939);
|
|
42
|
+
const host = process.env.GUARDIO_HTTP_HOST ?? clientConfig.host;
|
|
43
|
+
if (port == null || Number.isNaN(port)) {
|
|
44
|
+
logger.error("When client mode is 'http', set client.port or GUARDIO_HTTP_PORT.");
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
logger.info({ port, host }, "Starting HTTP server mode");
|
|
48
|
+
const httpServer = new GuardioHttpServer({
|
|
49
|
+
server,
|
|
50
|
+
listen: { port, host },
|
|
51
|
+
cwd,
|
|
52
|
+
configPath,
|
|
53
|
+
});
|
|
54
|
+
await httpServer.run();
|
|
55
|
+
return;
|
|
62
56
|
}
|
|
57
|
+
const client = clientConfig;
|
|
58
|
+
logger.info("Starting stdio mode");
|
|
63
59
|
const core = new GuardioCore({
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
server,
|
|
61
|
+
client,
|
|
66
62
|
cwd,
|
|
67
63
|
configPath,
|
|
68
64
|
});
|
|
69
65
|
await core.run();
|
|
70
66
|
}
|
|
71
67
|
main().catch((err) => {
|
|
72
|
-
|
|
68
|
+
logger.error({ err }, "Guardio failed to start");
|
|
73
69
|
process.exit(1);
|
|
74
70
|
});
|
|
75
71
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +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;
|
|
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,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,mBAAmB,C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,CAAC;IACnC,MAAM,IAAI,GAAG,IAAI,WAAW,CAAC;QAC3B,MAAM;QACN,MAAM;QACN,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,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,EAAE,yBAAyB,CAAC,CAAC;IACjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -3,6 +3,10 @@ import type { PolicyPluginInterface } from "../interfaces/PolicyPluginInterface.
|
|
|
3
3
|
import type { InterventionPluginInterface } from "../interfaces/InterventionPluginInterface.js";
|
|
4
4
|
export type PolicyPluginFactory = (config?: Record<string, unknown>) => PolicyPluginInterface;
|
|
5
5
|
export type InterventionPluginFactory = (config?: Record<string, unknown>) => InterventionPluginInterface;
|
|
6
|
+
/**
|
|
7
|
+
* Resolves path to config file: first .js, then .ts, then .json (from cwd).
|
|
8
|
+
*/
|
|
9
|
+
export declare function getConfigPath(cwd: string): string | null;
|
|
6
10
|
/**
|
|
7
11
|
* Loads GuardioConfig from a path. Supports .json (readFile + parse) and .js/.ts (dynamic import).
|
|
8
12
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/config/PluginManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/config/PluginManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EAGd,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AACpF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,8CAA8C,CAAC;AAWhG,MAAM,MAAM,mBAAmB,GAAG,CAChC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import { readFileSync, existsSync
|
|
2
|
-
import { join, dirname } from "node:path";
|
|
1
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { join, dirname, resolve } from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
4
|
import { DefaultPolicyPlugin, RegexPolicyPlugin, } from "../plugins/policy/index.js";
|
|
6
5
|
import { DefaultInterventionPlugin, HttpInterventionPlugin, } from "../plugins/intervention/index.js";
|
|
6
|
+
import { logger } from "../logger.js";
|
|
7
7
|
const policyRegistry = {
|
|
8
8
|
default: (config) => new DefaultPolicyPlugin(config ?? {}),
|
|
9
9
|
regex: (config) => new RegexPolicyPlugin(config ?? {}),
|
|
@@ -12,65 +12,36 @@ const interventionRegistry = {
|
|
|
12
12
|
default: (config) => new DefaultInterventionPlugin(config),
|
|
13
13
|
http: (config) => new HttpInterventionPlugin(config),
|
|
14
14
|
};
|
|
15
|
-
/** Entry
|
|
16
|
-
const
|
|
15
|
+
/** Entry filenames to load from a plugin directory (first found wins). */
|
|
16
|
+
const PLUGIN_ENTRY_NAMES = ["index.js", "index.mjs"];
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
* Each plugin is a subdirectory with index.ts (or index.js/mjs/cjs); default export must be a descriptor.
|
|
18
|
+
* Resolve plugin directory to an entry file (index.js or index.mjs). Path is relative to configDir or absolute.
|
|
20
19
|
*/
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return;
|
|
28
|
-
const entries = readdirSync(pluginsDir, { withFileTypes: true });
|
|
29
|
-
for (const dirent of entries) {
|
|
30
|
-
if (!dirent.isDirectory())
|
|
31
|
-
continue;
|
|
32
|
-
const entryPath = join(pluginsDir, dirent.name, PLUGIN_ENTRY_NAME);
|
|
33
|
-
if (!existsSync(entryPath))
|
|
34
|
-
continue;
|
|
35
|
-
const mod = await loadPluginModule(entryPath);
|
|
36
|
-
const raw = mod?.default ?? mod;
|
|
37
|
-
if (!raw || typeof raw !== "object")
|
|
38
|
-
continue;
|
|
39
|
-
const descriptor = raw;
|
|
40
|
-
if (descriptor.type !== "policy" && descriptor.type !== "intervention")
|
|
41
|
-
continue;
|
|
42
|
-
if (typeof descriptor.name !== "string" ||
|
|
43
|
-
typeof descriptor.create !== "function") {
|
|
44
|
-
throw new Error(`Local plugin at ${entryPath}: default export must be { type, name, create } (name string, create function).`);
|
|
45
|
-
}
|
|
46
|
-
const desc = descriptor;
|
|
47
|
-
if (desc.type === "policy") {
|
|
48
|
-
pluginManager.registerPolicyPlugin(desc.name, (config) => desc.create(config ?? {}));
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
pluginManager.registerInterventionPlugin(desc.name, (config) => desc.create(config ?? {}));
|
|
52
|
-
}
|
|
20
|
+
function resolvePluginEntryPath(pluginPath, configDir) {
|
|
21
|
+
const dir = resolve(configDir, pluginPath);
|
|
22
|
+
for (const name of PLUGIN_ENTRY_NAMES) {
|
|
23
|
+
const p = join(dir, name);
|
|
24
|
+
if (existsSync(p))
|
|
25
|
+
return p;
|
|
53
26
|
}
|
|
27
|
+
throw new Error(`Plugin at ${pluginPath} must contain index.js or index.mjs (run build to compile index.ts).`);
|
|
54
28
|
}
|
|
55
29
|
/**
|
|
56
|
-
* Load
|
|
30
|
+
* Load plugin instance from a directory: import index.js/index.mjs, return default export (the instance).
|
|
57
31
|
*/
|
|
58
|
-
async function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
67
|
-
throw new Error(`Failed to load TypeScript plugin ${entryPath}. Install ts-node (e.g. npm install ts-node). ${msg}`);
|
|
32
|
+
async function loadPluginInstance(entryPath) {
|
|
33
|
+
const url = pathToFileURL(entryPath).href;
|
|
34
|
+
const mod = await import(url);
|
|
35
|
+
const instance = mod?.default ?? mod;
|
|
36
|
+
if (!instance || typeof instance !== "object") {
|
|
37
|
+
throw new Error(`Plugin at ${entryPath}: default export must be the plugin instance.`);
|
|
68
38
|
}
|
|
39
|
+
return instance;
|
|
69
40
|
}
|
|
70
41
|
/**
|
|
71
42
|
* Resolves path to config file: first .js, then .ts, then .json (from cwd).
|
|
72
43
|
*/
|
|
73
|
-
function getConfigPath(cwd) {
|
|
44
|
+
export function getConfigPath(cwd) {
|
|
74
45
|
const names = [
|
|
75
46
|
"guardio.config.js",
|
|
76
47
|
"guardio.config.ts",
|
|
@@ -87,6 +58,7 @@ function getConfigPath(cwd) {
|
|
|
87
58
|
* Loads GuardioConfig from a path. Supports .json (readFile + parse) and .js/.ts (dynamic import).
|
|
88
59
|
*/
|
|
89
60
|
export async function loadConfigFromPath(configPath) {
|
|
61
|
+
logger.debug({ configPath }, "Loading config from path");
|
|
90
62
|
if (configPath.endsWith(".json")) {
|
|
91
63
|
const raw = readFileSync(configPath, "utf-8");
|
|
92
64
|
return JSON.parse(raw);
|
|
@@ -95,8 +67,10 @@ export async function loadConfigFromPath(configPath) {
|
|
|
95
67
|
const mod = await import(url);
|
|
96
68
|
const config = mod.default ?? mod;
|
|
97
69
|
if (!config || typeof config !== "object" || !Array.isArray(config.plugins)) {
|
|
70
|
+
logger.error({ configPath }, "Invalid guardio config: expected default export with plugins array");
|
|
98
71
|
throw new Error(`Invalid guardio config: expected default export with plugins array (at ${configPath})`);
|
|
99
72
|
}
|
|
73
|
+
logger.debug({ configPath, pluginCount: config.plugins.length }, "Config loaded");
|
|
100
74
|
return config;
|
|
101
75
|
}
|
|
102
76
|
export class PluginManager {
|
|
@@ -123,16 +97,17 @@ export class PluginManager {
|
|
|
123
97
|
async loadConfig(cwd = process.cwd(), configPath) {
|
|
124
98
|
const path = configPath ?? getConfigPath(cwd);
|
|
125
99
|
if (!path) {
|
|
100
|
+
logger.error({ cwd }, "No guardio config found");
|
|
126
101
|
throw new Error(`No guardio config found in ${cwd}. Add guardio.config.js, guardio.config.ts, or guardio.config.json`);
|
|
127
102
|
}
|
|
128
103
|
if (this.configPath === path && this.config !== null) {
|
|
104
|
+
logger.debug("Using cached config");
|
|
129
105
|
return this.config;
|
|
130
106
|
}
|
|
131
107
|
this.configPath = path;
|
|
132
108
|
this.config = await loadConfigFromPath(path);
|
|
133
109
|
this.policyPlugins = null;
|
|
134
110
|
this.interventionPlugins = null;
|
|
135
|
-
await loadLocalPlugins(this, path);
|
|
136
111
|
return this.config;
|
|
137
112
|
}
|
|
138
113
|
/**
|
|
@@ -144,14 +119,31 @@ export class PluginManager {
|
|
|
144
119
|
return this.policyPlugins;
|
|
145
120
|
const plugins = (this.config.plugins ?? []).filter((p) => p.type === "policy");
|
|
146
121
|
const instances = [];
|
|
122
|
+
const configDir = dirname(this.configPath);
|
|
147
123
|
for (const entry of plugins) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
124
|
+
if (entry.path) {
|
|
125
|
+
const entryPath = resolvePluginEntryPath(entry.path, configDir);
|
|
126
|
+
logger.debug({ path: entry.path, entryPath }, "Loading policy plugin from path");
|
|
127
|
+
const instance = await loadPluginInstance(entryPath);
|
|
128
|
+
if (typeof instance.name !== "string" ||
|
|
129
|
+
typeof instance.evaluate !== "function") {
|
|
130
|
+
logger.error({ path: entry.path }, "Plugin default export must be a policy instance (name, evaluate)");
|
|
131
|
+
throw new Error(`Plugin at ${entry.path}: default export must be a policy instance (name, evaluate).`);
|
|
132
|
+
}
|
|
133
|
+
instances.push(instance);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const factory = policyRegistry[entry.name];
|
|
137
|
+
if (!factory) {
|
|
138
|
+
logger.error({ name: entry.name, registered: Object.keys(policyRegistry) }, "Unknown policy plugin name");
|
|
139
|
+
throw new Error(`Unknown policy plugin name: "${entry.name}". Registered: ${Object.keys(policyRegistry).join(", ")}`);
|
|
140
|
+
}
|
|
141
|
+
logger.debug({ name: entry.name }, "Instantiating built-in policy plugin");
|
|
142
|
+
instances.push(factory(entry.config ?? {}));
|
|
151
143
|
}
|
|
152
|
-
instances.push(factory(entry.config ?? {}));
|
|
153
144
|
}
|
|
154
145
|
this.policyPlugins = instances;
|
|
146
|
+
logger.debug({ count: instances.length, names: instances.map((p) => p.name) }, "Policy plugins resolved");
|
|
155
147
|
return instances;
|
|
156
148
|
}
|
|
157
149
|
/**
|
|
@@ -173,14 +165,31 @@ export class PluginManager {
|
|
|
173
165
|
return this.interventionPlugins;
|
|
174
166
|
const plugins = (this.config.plugins ?? []).filter((p) => p.type === "intervention");
|
|
175
167
|
const instances = [];
|
|
168
|
+
const configDir = dirname(this.configPath);
|
|
176
169
|
for (const entry of plugins) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
170
|
+
if (entry.path) {
|
|
171
|
+
const entryPath = resolvePluginEntryPath(entry.path, configDir);
|
|
172
|
+
logger.debug({ path: entry.path, entryPath }, "Loading intervention plugin from path");
|
|
173
|
+
const instance = await loadPluginInstance(entryPath);
|
|
174
|
+
if (typeof instance.name !== "string" ||
|
|
175
|
+
typeof instance.act !== "function") {
|
|
176
|
+
logger.error({ path: entry.path }, "Plugin default export must be an intervention instance (name, act)");
|
|
177
|
+
throw new Error(`Plugin at ${entry.path}: default export must be an intervention instance (name, act).`);
|
|
178
|
+
}
|
|
179
|
+
instances.push(instance);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
const factory = interventionRegistry[entry.name];
|
|
183
|
+
if (!factory) {
|
|
184
|
+
logger.error({ name: entry.name, registered: Object.keys(interventionRegistry) }, "Unknown intervention plugin name");
|
|
185
|
+
throw new Error(`Unknown intervention plugin name: "${entry.name}". Registered: ${Object.keys(interventionRegistry).join(", ")}`);
|
|
186
|
+
}
|
|
187
|
+
logger.debug({ name: entry.name }, "Instantiating built-in intervention plugin");
|
|
188
|
+
instances.push(factory(entry.config ?? {}));
|
|
180
189
|
}
|
|
181
|
-
instances.push(factory(entry.config ?? {}));
|
|
182
190
|
}
|
|
183
191
|
this.interventionPlugins = instances;
|
|
192
|
+
logger.debug({ count: instances.length, names: instances.map((p) => p.name) }, "Intervention plugins resolved");
|
|
184
193
|
return instances;
|
|
185
194
|
}
|
|
186
195
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginManager.js","sourceRoot":"","sources":["../../src/config/PluginManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"PluginManager.js","sourceRoot":"","sources":["../../src/config/PluginManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAQzC,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,yBAAyB,EACzB,sBAAsB,GACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAUtC,MAAM,cAAc,GAAwC;IAC1D,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,mBAAmB,CAAC,MAAM,IAAI,EAAE,CAAC;IAC1D,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,iBAAiB,CAAC,MAAM,IAAI,EAAE,CAAC;CACvD,CAAC;AAEF,MAAM,oBAAoB,GAA8C;IACtE,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,yBAAyB,CAAC,MAAM,CAAC;IAC1D,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,sBAAsB,CAAC,MAAM,CAAC;CACrD,CAAC;AAEF,0EAA0E;AAC1E,MAAM,kBAAkB,GAAG,CAAC,UAAU,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AAM,CAAC,KAAK,CACV,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,EACpB,4CAA4C,CAC7C,CAAC;gBACF,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;QAED,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;QACrC,MAAM,CAAC,KAAK,CACV,EAAE,KAAK,EAAE,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAChE,+BAA+B,CAChC,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { PluginManager, loadConfigFromPath } from "./PluginManager.js";
|
|
1
|
+
export { PluginManager, loadConfigFromPath, getConfigPath, } from "./PluginManager.js";
|
|
2
2
|
export type { PolicyPluginFactory } from "./PluginManager.js";
|
|
3
|
-
export type { GuardioConfig, GuardioServerConfig,
|
|
3
|
+
export type { GuardioConfig, GuardioServerConfig, GuardioServerConfigUrl, GuardioClientConfig, PolicyPluginConfigEntry, InterventionPluginConfigEntry, PluginConfigEntry, } from "./types.js";
|
|
4
4
|
export type { InterventionPluginFactory } from "./PluginManager.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,aAAa,GACd,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/config/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { PluginManager, loadConfigFromPath } from "./PluginManager.js";
|
|
1
|
+
export { PluginManager, loadConfigFromPath, getConfigPath, } from "./PluginManager.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,aAAa,GACd,MAAM,oBAAoB,CAAC"}
|
package/dist/config/types.d.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Policy plugin entry in guardio config.
|
|
3
|
+
* Use "path" for a custom plugin (directory with index.js/index.mjs; default export = instance).
|
|
3
4
|
*/
|
|
4
5
|
export interface PolicyPluginConfigEntry {
|
|
5
6
|
type: "policy";
|
|
6
7
|
name: string;
|
|
8
|
+
/** Directory to custom plugin (relative to config file or absolute). Must contain index.js or index.mjs with default export = policy instance. */
|
|
9
|
+
path?: string;
|
|
7
10
|
config?: Record<string, unknown>;
|
|
8
11
|
}
|
|
9
12
|
/**
|
|
10
13
|
* Intervention plugin entry in guardio config.
|
|
14
|
+
* Use "path" for a custom plugin (directory with index.js/index.mjs; default export = instance).
|
|
11
15
|
*/
|
|
12
16
|
export interface InterventionPluginConfigEntry {
|
|
13
17
|
type: "intervention";
|
|
14
18
|
name: string;
|
|
19
|
+
/** Directory to custom plugin (relative to config file or absolute). Must contain index.js or index.mjs with default export = intervention instance. */
|
|
20
|
+
path?: string;
|
|
15
21
|
config?: Record<string, unknown>;
|
|
16
22
|
}
|
|
17
23
|
/**
|
|
@@ -19,40 +25,38 @@ export interface InterventionPluginConfigEntry {
|
|
|
19
25
|
*/
|
|
20
26
|
export type PluginConfigEntry = PolicyPluginConfigEntry | InterventionPluginConfigEntry;
|
|
21
27
|
/**
|
|
22
|
-
*
|
|
23
|
-
* create() must return an instance implementing PolicyPluginInterface or InterventionPluginInterface.
|
|
28
|
+
* MCP server to proxy to (HTTP/SSE URL only).
|
|
24
29
|
*/
|
|
25
|
-
export interface
|
|
26
|
-
type: "
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
export interface InterventionPluginDescriptor {
|
|
34
|
-
type: "intervention";
|
|
35
|
-
name: string;
|
|
36
|
-
create: (config: Record<string, unknown>) => {
|
|
37
|
-
name: string;
|
|
38
|
-
act: (context: unknown) => void | boolean | Promise<void> | Promise<boolean>;
|
|
39
|
-
};
|
|
30
|
+
export interface GuardioServerConfigUrl {
|
|
31
|
+
type: "url";
|
|
32
|
+
url: string;
|
|
33
|
+
/** Optional headers (e.g. Authorization). */
|
|
34
|
+
headers?: Record<string, string>;
|
|
35
|
+
/** Request timeout in ms. Defaults to 30000. */
|
|
36
|
+
timeoutMs?: number;
|
|
40
37
|
}
|
|
41
|
-
|
|
38
|
+
/** Server config: only HTTP/SSE URL is supported. */
|
|
39
|
+
export type GuardioServerConfig = GuardioServerConfigUrl;
|
|
42
40
|
/**
|
|
43
|
-
*
|
|
41
|
+
* How the AI Agent (client) connects to Guardio: stdio (local pipe) or http (standalone server).
|
|
42
|
+
* When mode is "http", port and host are the address the proxy listens on.
|
|
44
43
|
*/
|
|
45
|
-
export interface
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
export interface GuardioClientConfig {
|
|
45
|
+
/** "stdio" = read from stdin, write to stdout (default). "http" = run HTTP server for requests. */
|
|
46
|
+
mode: "stdio" | "http";
|
|
47
|
+
/** When mode is "http". Port the proxy listens on. Default 3939. */
|
|
48
|
+
port?: number;
|
|
49
|
+
/** When mode is "http". Host to bind (default "127.0.0.1"). Use "0.0.0.0" for external. */
|
|
50
|
+
host?: string;
|
|
49
51
|
}
|
|
50
52
|
/**
|
|
51
53
|
* Guardio config file shape (default export of guardio.config.ts / .json).
|
|
52
54
|
*/
|
|
53
55
|
export interface GuardioConfig {
|
|
54
|
-
/** MCP server to proxy to
|
|
55
|
-
server
|
|
56
|
+
/** MCP server to proxy to (HTTP/SSE URL). Required. */
|
|
57
|
+
server: GuardioServerConfig;
|
|
58
|
+
/** How the AI client connects to Guardio. Default: { mode: "stdio" }. */
|
|
59
|
+
client?: GuardioClientConfig;
|
|
56
60
|
plugins: PluginConfigEntry[];
|
|
57
61
|
}
|
|
58
62
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,kJAAkJ;IAClJ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,wJAAwJ;IACxJ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,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,sBAAsB;IACrC,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qDAAqD;AACrD,MAAM,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AAEzD;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,mGAAmG;IACnG,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC;IACvB,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2FAA2F;IAC3F,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,uDAAuD;IACvD,MAAM,EAAE,mBAAmB,CAAC;IAC5B,yEAAyE;IACzE,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,OAAO,EAAE,iBAAiB,EAAE,CAAC;CAC9B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action names for result._guardio.action when Guardio blocks or rejects a tool call.
|
|
3
|
+
* We return a successful JSON-RPC result (not an error), so numeric error codes are not used.
|
|
4
|
+
* These strings identify the kind of denial for the AI Agent / client.
|
|
5
|
+
*/
|
|
6
|
+
export declare const GuardioAction: {
|
|
7
|
+
/** Tool was blocked by a policy plugin. */
|
|
8
|
+
readonly TOOL_BLOCKED: "TOOL_BLOCKED";
|
|
9
|
+
/** Tool call was rejected by an intervention plugin. */
|
|
10
|
+
readonly POLICY_VIOLATION: "POLICY_VIOLATION";
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=GuardioActions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GuardioActions.d.ts","sourceRoot":"","sources":["../../src/core/GuardioActions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,aAAa;IACxB,2CAA2C;;IAE3C,wDAAwD;;CAEhD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action names for result._guardio.action when Guardio blocks or rejects a tool call.
|
|
3
|
+
* We return a successful JSON-RPC result (not an error), so numeric error codes are not used.
|
|
4
|
+
* These strings identify the kind of denial for the AI Agent / client.
|
|
5
|
+
*/
|
|
6
|
+
export const GuardioAction = {
|
|
7
|
+
/** Tool was blocked by a policy plugin. */
|
|
8
|
+
TOOL_BLOCKED: "TOOL_BLOCKED",
|
|
9
|
+
/** Tool call was rejected by an intervention plugin. */
|
|
10
|
+
POLICY_VIOLATION: "POLICY_VIOLATION",
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=GuardioActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GuardioActions.js","sourceRoot":"","sources":["../../src/core/GuardioActions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,2CAA2C;IAC3C,YAAY,EAAE,cAAc;IAC5B,wDAAwD;IACxD,gBAAgB,EAAE,kBAAkB;CAC5B,CAAC"}
|
|
@@ -3,17 +3,30 @@ export declare class GuardioCore {
|
|
|
3
3
|
private readonly config;
|
|
4
4
|
private policyPlugins;
|
|
5
5
|
private interventionPlugins;
|
|
6
|
-
private
|
|
7
|
-
private
|
|
8
|
-
private toolInterface;
|
|
9
|
-
private pendingResponseId;
|
|
10
|
-
private readonly appQueue;
|
|
6
|
+
private transport;
|
|
7
|
+
private clientTransport;
|
|
11
8
|
constructor(config: GuardioCoreConfig);
|
|
12
9
|
run(): Promise<void>;
|
|
13
|
-
private
|
|
10
|
+
private sendToClient;
|
|
11
|
+
/** Resolve Guardio package version from package.json when available. */
|
|
12
|
+
private getGuardioVersion;
|
|
13
|
+
/**
|
|
14
|
+
* Build a successful JSON-RPC response for blocked/rejected tool calls.
|
|
15
|
+
* Returns a result (not error) so AI Agent frameworks don't treat it as a fatal error;
|
|
16
|
+
* the agent can read the content and _guardio metadata.
|
|
17
|
+
*/
|
|
18
|
+
private buildGuardioBlockedResponse;
|
|
19
|
+
/**
|
|
20
|
+
* Handle POST /messages (HTTP client): run policy/intervention, then forward to remote.
|
|
21
|
+
*/
|
|
22
|
+
handlePostMessage(body: string): Promise<{
|
|
23
|
+
status: number;
|
|
24
|
+
body: string;
|
|
25
|
+
}>;
|
|
26
|
+
private sendBlockedResponse;
|
|
27
|
+
/**
|
|
28
|
+
* Process one line from client (stdio or from queue): run plugins, then forward to MCP.
|
|
29
|
+
*/
|
|
14
30
|
private processAppLine;
|
|
15
|
-
private drainAppQueue;
|
|
16
|
-
private attachAppHandler;
|
|
17
|
-
private attachToolHandler;
|
|
18
31
|
}
|
|
19
32
|
//# sourceMappingURL=GuardioCore.d.ts.map
|