fastgrc-openclaw 1.0.5 → 1.0.7
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/bin.js +70 -1
- package/dist/bin.mjs +70 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -2
- package/dist/index.mjs +2 -1
- package/dist/plugin.d.mts +22 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/plugin.js +147 -0
- package/dist/plugin.mjs +114 -0
- package/openclaw.plugin.json +6 -0
- package/package.json +11 -2
package/dist/bin.js
CHANGED
|
@@ -120,13 +120,82 @@ if (cmd === "unset-key") {
|
|
|
120
120
|
process.stdout.write("FastGRC API key removed.\n");
|
|
121
121
|
process.exit(0);
|
|
122
122
|
}
|
|
123
|
+
if (cmd === "set-policy") {
|
|
124
|
+
if (!arg) {
|
|
125
|
+
process.stderr.write("Usage: fastgrc-hook set-policy <policy-id>\n");
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
writeConfig({ ...readConfig(), policyId: arg });
|
|
129
|
+
process.stdout.write(`\u2713 FastGRC policy ID saved to ${CONFIG_PATH}
|
|
130
|
+
`);
|
|
131
|
+
process.stdout.write(' Run "fastgrc-hook get-policy" to verify.\n');
|
|
132
|
+
process.exit(0);
|
|
133
|
+
}
|
|
134
|
+
if (cmd === "get-policy") {
|
|
135
|
+
const id = readConfig().policyId;
|
|
136
|
+
if (!id) {
|
|
137
|
+
process.stdout.write("No policy ID stored \u2014 org-wide default will be used.\n");
|
|
138
|
+
process.stdout.write("Run: fastgrc-hook set-policy <policy-id>\n");
|
|
139
|
+
} else {
|
|
140
|
+
process.stdout.write(`${id}
|
|
141
|
+
`);
|
|
142
|
+
}
|
|
143
|
+
process.exit(0);
|
|
144
|
+
}
|
|
145
|
+
if (cmd === "unset-policy") {
|
|
146
|
+
const cfg = readConfig();
|
|
147
|
+
delete cfg.policyId;
|
|
148
|
+
writeConfig(cfg);
|
|
149
|
+
process.stdout.write("FastGRC policy ID removed \u2014 org-wide default will be used.\n");
|
|
150
|
+
process.exit(0);
|
|
151
|
+
}
|
|
152
|
+
if (cmd === "install-hook") {
|
|
153
|
+
const targetDir = arg || process.cwd();
|
|
154
|
+
const hookMdPath = path.join(targetDir, "HOOK.md");
|
|
155
|
+
const HOOK_ENTRY = ' - matcher: PreToolUse\n handler: "fastgrc-hook"\n';
|
|
156
|
+
const HOOK_BLOCK = "---\nname: FastGRC Policy Check\ndescription: Evaluate every tool call against your FastGRC compliance policy\nhooks:\n" + HOOK_ENTRY + "---\n";
|
|
157
|
+
const hasKey = !!(readConfig().apiKey || process.env.FASTGRC_API_KEY);
|
|
158
|
+
if (!hasKey) {
|
|
159
|
+
process.stdout.write("\u26A0 No API key set yet. Run: fastgrc-hook set-key fgrc_k1_your_key\n\n");
|
|
160
|
+
}
|
|
161
|
+
if (!fs.existsSync(hookMdPath)) {
|
|
162
|
+
fs.writeFileSync(hookMdPath, HOOK_BLOCK, "utf8");
|
|
163
|
+
process.stdout.write(`\u2713 Created ${hookMdPath}
|
|
164
|
+
|
|
165
|
+
Restart OpenClaw \u2014 FastGRC will evaluate every tool call.
|
|
166
|
+
`);
|
|
167
|
+
process.exit(0);
|
|
168
|
+
}
|
|
169
|
+
const existing = fs.readFileSync(hookMdPath, "utf8");
|
|
170
|
+
if (existing.includes("fastgrc-hook")) {
|
|
171
|
+
process.stdout.write(`\u2713 FastGRC hook already present in ${hookMdPath}
|
|
172
|
+
`);
|
|
173
|
+
process.exit(0);
|
|
174
|
+
}
|
|
175
|
+
const fmEnd = existing.indexOf("\n---", 3);
|
|
176
|
+
let updated;
|
|
177
|
+
if (fmEnd !== -1) {
|
|
178
|
+
const hasHooksKey = existing.lastIndexOf("hooks:", fmEnd) !== -1;
|
|
179
|
+
const insertText = hasHooksKey ? HOOK_ENTRY : `hooks:
|
|
180
|
+
${HOOK_ENTRY}`;
|
|
181
|
+
updated = existing.slice(0, fmEnd) + "\n" + insertText + existing.slice(fmEnd);
|
|
182
|
+
} else {
|
|
183
|
+
updated = HOOK_BLOCK + "\n" + existing;
|
|
184
|
+
}
|
|
185
|
+
fs.writeFileSync(hookMdPath, updated, "utf8");
|
|
186
|
+
process.stdout.write(`\u2713 Updated ${hookMdPath} \u2014 FastGRC hook added.
|
|
187
|
+
|
|
188
|
+
Restart OpenClaw to activate.
|
|
189
|
+
`);
|
|
190
|
+
process.exit(0);
|
|
191
|
+
}
|
|
123
192
|
var apiKey = process.env.FASTGRC_API_KEY ?? readConfig().apiKey;
|
|
124
193
|
if (!apiKey) {
|
|
125
194
|
process.stderr.write("[fastgrc-hook] No API key configured \u2014 run: fastgrc-hook set-key fgrc_k1_...\n");
|
|
126
195
|
process.exit(0);
|
|
127
196
|
}
|
|
128
197
|
var baseUrl = process.env.FASTGRC_BASE_URL ?? "https://app.fastgrc.ai";
|
|
129
|
-
var policyId = process.env.FASTGRC_POLICY_ID;
|
|
198
|
+
var policyId = process.env.FASTGRC_POLICY_ID ?? readConfig().policyId;
|
|
130
199
|
async function main() {
|
|
131
200
|
const chunks = [];
|
|
132
201
|
for await (const chunk of process.stdin) chunks.push(chunk);
|
package/dist/bin.mjs
CHANGED
|
@@ -97,13 +97,82 @@ if (cmd === "unset-key") {
|
|
|
97
97
|
process.stdout.write("FastGRC API key removed.\n");
|
|
98
98
|
process.exit(0);
|
|
99
99
|
}
|
|
100
|
+
if (cmd === "set-policy") {
|
|
101
|
+
if (!arg) {
|
|
102
|
+
process.stderr.write("Usage: fastgrc-hook set-policy <policy-id>\n");
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
writeConfig({ ...readConfig(), policyId: arg });
|
|
106
|
+
process.stdout.write(`\u2713 FastGRC policy ID saved to ${CONFIG_PATH}
|
|
107
|
+
`);
|
|
108
|
+
process.stdout.write(' Run "fastgrc-hook get-policy" to verify.\n');
|
|
109
|
+
process.exit(0);
|
|
110
|
+
}
|
|
111
|
+
if (cmd === "get-policy") {
|
|
112
|
+
const id = readConfig().policyId;
|
|
113
|
+
if (!id) {
|
|
114
|
+
process.stdout.write("No policy ID stored \u2014 org-wide default will be used.\n");
|
|
115
|
+
process.stdout.write("Run: fastgrc-hook set-policy <policy-id>\n");
|
|
116
|
+
} else {
|
|
117
|
+
process.stdout.write(`${id}
|
|
118
|
+
`);
|
|
119
|
+
}
|
|
120
|
+
process.exit(0);
|
|
121
|
+
}
|
|
122
|
+
if (cmd === "unset-policy") {
|
|
123
|
+
const cfg = readConfig();
|
|
124
|
+
delete cfg.policyId;
|
|
125
|
+
writeConfig(cfg);
|
|
126
|
+
process.stdout.write("FastGRC policy ID removed \u2014 org-wide default will be used.\n");
|
|
127
|
+
process.exit(0);
|
|
128
|
+
}
|
|
129
|
+
if (cmd === "install-hook") {
|
|
130
|
+
const targetDir = arg || process.cwd();
|
|
131
|
+
const hookMdPath = path.join(targetDir, "HOOK.md");
|
|
132
|
+
const HOOK_ENTRY = ' - matcher: PreToolUse\n handler: "fastgrc-hook"\n';
|
|
133
|
+
const HOOK_BLOCK = "---\nname: FastGRC Policy Check\ndescription: Evaluate every tool call against your FastGRC compliance policy\nhooks:\n" + HOOK_ENTRY + "---\n";
|
|
134
|
+
const hasKey = !!(readConfig().apiKey || process.env.FASTGRC_API_KEY);
|
|
135
|
+
if (!hasKey) {
|
|
136
|
+
process.stdout.write("\u26A0 No API key set yet. Run: fastgrc-hook set-key fgrc_k1_your_key\n\n");
|
|
137
|
+
}
|
|
138
|
+
if (!fs.existsSync(hookMdPath)) {
|
|
139
|
+
fs.writeFileSync(hookMdPath, HOOK_BLOCK, "utf8");
|
|
140
|
+
process.stdout.write(`\u2713 Created ${hookMdPath}
|
|
141
|
+
|
|
142
|
+
Restart OpenClaw \u2014 FastGRC will evaluate every tool call.
|
|
143
|
+
`);
|
|
144
|
+
process.exit(0);
|
|
145
|
+
}
|
|
146
|
+
const existing = fs.readFileSync(hookMdPath, "utf8");
|
|
147
|
+
if (existing.includes("fastgrc-hook")) {
|
|
148
|
+
process.stdout.write(`\u2713 FastGRC hook already present in ${hookMdPath}
|
|
149
|
+
`);
|
|
150
|
+
process.exit(0);
|
|
151
|
+
}
|
|
152
|
+
const fmEnd = existing.indexOf("\n---", 3);
|
|
153
|
+
let updated;
|
|
154
|
+
if (fmEnd !== -1) {
|
|
155
|
+
const hasHooksKey = existing.lastIndexOf("hooks:", fmEnd) !== -1;
|
|
156
|
+
const insertText = hasHooksKey ? HOOK_ENTRY : `hooks:
|
|
157
|
+
${HOOK_ENTRY}`;
|
|
158
|
+
updated = existing.slice(0, fmEnd) + "\n" + insertText + existing.slice(fmEnd);
|
|
159
|
+
} else {
|
|
160
|
+
updated = HOOK_BLOCK + "\n" + existing;
|
|
161
|
+
}
|
|
162
|
+
fs.writeFileSync(hookMdPath, updated, "utf8");
|
|
163
|
+
process.stdout.write(`\u2713 Updated ${hookMdPath} \u2014 FastGRC hook added.
|
|
164
|
+
|
|
165
|
+
Restart OpenClaw to activate.
|
|
166
|
+
`);
|
|
167
|
+
process.exit(0);
|
|
168
|
+
}
|
|
100
169
|
var apiKey = process.env.FASTGRC_API_KEY ?? readConfig().apiKey;
|
|
101
170
|
if (!apiKey) {
|
|
102
171
|
process.stderr.write("[fastgrc-hook] No API key configured \u2014 run: fastgrc-hook set-key fgrc_k1_...\n");
|
|
103
172
|
process.exit(0);
|
|
104
173
|
}
|
|
105
174
|
var baseUrl = process.env.FASTGRC_BASE_URL ?? "https://app.fastgrc.ai";
|
|
106
|
-
var policyId = process.env.FASTGRC_POLICY_ID;
|
|
175
|
+
var policyId = process.env.FASTGRC_POLICY_ID ?? readConfig().policyId;
|
|
107
176
|
async function main() {
|
|
108
177
|
const chunks = [];
|
|
109
178
|
for await (const chunk of process.stdin) chunks.push(chunk);
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
declare function resolveApiKey(explicit?: string): string | undefined;
|
|
1
2
|
interface FastGRCPluginOptions {
|
|
2
3
|
/**
|
|
3
4
|
* Your FastGRC API key (fgrc_k1_...).
|
|
@@ -75,4 +76,4 @@ declare function evaluate(payload: {
|
|
|
75
76
|
}): Promise<EvaluateResponse | null>;
|
|
76
77
|
declare function FastGRCPlugin(options: FastGRCPluginOptions): OpenClawPlugin;
|
|
77
78
|
|
|
78
|
-
export { FastGRCApprovalRequiredError, FastGRCBlockedError, FastGRCPlugin, type FastGRCPluginOptions, evaluate };
|
|
79
|
+
export { FastGRCApprovalRequiredError, FastGRCBlockedError, FastGRCPlugin, type FastGRCPluginOptions, evaluate, resolveApiKey };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
declare function resolveApiKey(explicit?: string): string | undefined;
|
|
1
2
|
interface FastGRCPluginOptions {
|
|
2
3
|
/**
|
|
3
4
|
* Your FastGRC API key (fgrc_k1_...).
|
|
@@ -75,4 +76,4 @@ declare function evaluate(payload: {
|
|
|
75
76
|
}): Promise<EvaluateResponse | null>;
|
|
76
77
|
declare function FastGRCPlugin(options: FastGRCPluginOptions): OpenClawPlugin;
|
|
77
78
|
|
|
78
|
-
export { FastGRCApprovalRequiredError, FastGRCBlockedError, FastGRCPlugin, type FastGRCPluginOptions, evaluate };
|
|
79
|
+
export { FastGRCApprovalRequiredError, FastGRCBlockedError, FastGRCPlugin, type FastGRCPluginOptions, evaluate, resolveApiKey };
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,8 @@ __export(index_exports, {
|
|
|
33
33
|
FastGRCApprovalRequiredError: () => FastGRCApprovalRequiredError,
|
|
34
34
|
FastGRCBlockedError: () => FastGRCBlockedError,
|
|
35
35
|
FastGRCPlugin: () => FastGRCPlugin,
|
|
36
|
-
evaluate: () => evaluate
|
|
36
|
+
evaluate: () => evaluate,
|
|
37
|
+
resolveApiKey: () => resolveApiKey
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(index_exports);
|
|
39
40
|
var fs = __toESM(require("fs"));
|
|
@@ -177,5 +178,6 @@ function FastGRCPlugin(options) {
|
|
|
177
178
|
FastGRCApprovalRequiredError,
|
|
178
179
|
FastGRCBlockedError,
|
|
179
180
|
FastGRCPlugin,
|
|
180
|
-
evaluate
|
|
181
|
+
evaluate,
|
|
182
|
+
resolveApiKey
|
|
181
183
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
interface AgentContext {
|
|
2
|
+
id?: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
type?: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
type BeforeToolCallResult = {
|
|
8
|
+
block: true;
|
|
9
|
+
blockReason: string;
|
|
10
|
+
} | {
|
|
11
|
+
requireApproval: {
|
|
12
|
+
timeoutBehavior: 'allow' | 'deny';
|
|
13
|
+
};
|
|
14
|
+
} | undefined;
|
|
15
|
+
declare const plugin: {
|
|
16
|
+
name: string;
|
|
17
|
+
hooks: {
|
|
18
|
+
before_tool_call(toolName: string, args: unknown, context: AgentContext): Promise<BeforeToolCallResult>;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { plugin as default };
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
interface AgentContext {
|
|
2
|
+
id?: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
type?: string;
|
|
5
|
+
[key: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
type BeforeToolCallResult = {
|
|
8
|
+
block: true;
|
|
9
|
+
blockReason: string;
|
|
10
|
+
} | {
|
|
11
|
+
requireApproval: {
|
|
12
|
+
timeoutBehavior: 'allow' | 'deny';
|
|
13
|
+
};
|
|
14
|
+
} | undefined;
|
|
15
|
+
declare const plugin: {
|
|
16
|
+
name: string;
|
|
17
|
+
hooks: {
|
|
18
|
+
before_tool_call(toolName: string, args: unknown, context: AgentContext): Promise<BeforeToolCallResult>;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { plugin as default };
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/plugin.ts
|
|
31
|
+
var plugin_exports = {};
|
|
32
|
+
__export(plugin_exports, {
|
|
33
|
+
default: () => plugin_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
36
|
+
|
|
37
|
+
// src/index.ts
|
|
38
|
+
var fs = __toESM(require("fs"));
|
|
39
|
+
var os = __toESM(require("os"));
|
|
40
|
+
var path = __toESM(require("path"));
|
|
41
|
+
var DEFAULT_BASE_URL = "https://app.fastgrc.ai";
|
|
42
|
+
var DEFAULT_TIMEOUT_MS = 3e3;
|
|
43
|
+
function resolveApiKey(explicit) {
|
|
44
|
+
if (explicit) return explicit;
|
|
45
|
+
if (process.env.FASTGRC_API_KEY) return process.env.FASTGRC_API_KEY;
|
|
46
|
+
try {
|
|
47
|
+
const cfg = JSON.parse(fs.readFileSync(path.join(os.homedir(), ".fastgrc.json"), "utf8"));
|
|
48
|
+
if (cfg.apiKey) return cfg.apiKey;
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
async function evaluate(payload) {
|
|
54
|
+
const {
|
|
55
|
+
toolName,
|
|
56
|
+
args,
|
|
57
|
+
agentId,
|
|
58
|
+
agentType,
|
|
59
|
+
agentName,
|
|
60
|
+
apiKey: apiKey2,
|
|
61
|
+
policyId,
|
|
62
|
+
baseUrl = DEFAULT_BASE_URL,
|
|
63
|
+
timeoutMs = DEFAULT_TIMEOUT_MS
|
|
64
|
+
} = payload;
|
|
65
|
+
const evalUrl = `${baseUrl.replace(/\/$/, "")}/api/v1/policy-router/evaluate`;
|
|
66
|
+
const content = `tool_name: ${toolName}
|
|
67
|
+
args: ${JSON.stringify(args)}`;
|
|
68
|
+
try {
|
|
69
|
+
const controller = new AbortController();
|
|
70
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
71
|
+
const res = await fetch(evalUrl, {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: {
|
|
74
|
+
"Authorization": `Bearer ${apiKey2}`,
|
|
75
|
+
"Content-Type": "application/json"
|
|
76
|
+
},
|
|
77
|
+
body: JSON.stringify({
|
|
78
|
+
subjectContent: content,
|
|
79
|
+
subjectType: "tool_argument",
|
|
80
|
+
direction: "ingress",
|
|
81
|
+
agentId,
|
|
82
|
+
agentType,
|
|
83
|
+
agentName,
|
|
84
|
+
...policyId ? { policyId } : {}
|
|
85
|
+
}),
|
|
86
|
+
signal: controller.signal
|
|
87
|
+
});
|
|
88
|
+
clearTimeout(timer);
|
|
89
|
+
if (!res.ok) {
|
|
90
|
+
console.warn(`[fastgrc] Evaluate returned ${res.status} \u2014 failing open`);
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return await res.json();
|
|
94
|
+
} catch (err) {
|
|
95
|
+
const reason = err instanceof Error && err.name === "AbortError" ? "timeout" : String(err);
|
|
96
|
+
console.warn(`[fastgrc] Evaluate failed (${reason}) \u2014 failing open`);
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/plugin.ts
|
|
102
|
+
var DEFAULT_BASE_URL2 = "https://app.fastgrc.ai";
|
|
103
|
+
var DEFAULT_TIMEOUT_MS2 = 3e3;
|
|
104
|
+
var apiKey = resolveApiKey();
|
|
105
|
+
if (!apiKey) {
|
|
106
|
+
console.warn(
|
|
107
|
+
"[fastgrc] No API key found \u2014 all tool calls will proceed unchecked.\n\n Run once to connect:\n fastgrc-hook set-key fgrc_k1_your_key_here\n\n Get a key at: https://app.fastgrc.ai/connect\n Manage keys at: https://app.fastgrc.ai/dashboard/settings"
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
var plugin = {
|
|
111
|
+
name: "fastgrc",
|
|
112
|
+
hooks: {
|
|
113
|
+
async before_tool_call(toolName, args, context) {
|
|
114
|
+
if (!apiKey) return void 0;
|
|
115
|
+
const result = await evaluate({
|
|
116
|
+
toolName,
|
|
117
|
+
args,
|
|
118
|
+
agentId: context.id,
|
|
119
|
+
agentType: context.type,
|
|
120
|
+
agentName: context.name,
|
|
121
|
+
apiKey,
|
|
122
|
+
baseUrl: DEFAULT_BASE_URL2,
|
|
123
|
+
timeoutMs: DEFAULT_TIMEOUT_MS2
|
|
124
|
+
});
|
|
125
|
+
if (!result) return void 0;
|
|
126
|
+
const { decision, reasoning, policyContext, reasonTags } = result;
|
|
127
|
+
const matchedRule = policyContext?.matchedRule ?? "policy rule";
|
|
128
|
+
if (decision === "block") {
|
|
129
|
+
return {
|
|
130
|
+
block: true,
|
|
131
|
+
blockReason: `[${matchedRule}] ${reasoning}`
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
if (decision === "require_approval") {
|
|
135
|
+
return {
|
|
136
|
+
requireApproval: { timeoutBehavior: "deny" }
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (Array.isArray(reasonTags) && reasonTags.includes("override_block_active")) {
|
|
140
|
+
const msg = policyContext?.matchedRule ? `[FastGRC] Observability mode \u2014 would have blocked: [${policyContext.matchedRule}] ${reasoning}` : `[FastGRC] Observability mode \u2014 would have blocked: ${reasoning}`;
|
|
141
|
+
console.warn(msg);
|
|
142
|
+
}
|
|
143
|
+
return void 0;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var plugin_default = plugin;
|
package/dist/plugin.mjs
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as os from "os";
|
|
4
|
+
import * as path from "path";
|
|
5
|
+
var DEFAULT_BASE_URL = "https://app.fastgrc.ai";
|
|
6
|
+
var DEFAULT_TIMEOUT_MS = 3e3;
|
|
7
|
+
function resolveApiKey(explicit) {
|
|
8
|
+
if (explicit) return explicit;
|
|
9
|
+
if (process.env.FASTGRC_API_KEY) return process.env.FASTGRC_API_KEY;
|
|
10
|
+
try {
|
|
11
|
+
const cfg = JSON.parse(fs.readFileSync(path.join(os.homedir(), ".fastgrc.json"), "utf8"));
|
|
12
|
+
if (cfg.apiKey) return cfg.apiKey;
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
async function evaluate(payload) {
|
|
18
|
+
const {
|
|
19
|
+
toolName,
|
|
20
|
+
args,
|
|
21
|
+
agentId,
|
|
22
|
+
agentType,
|
|
23
|
+
agentName,
|
|
24
|
+
apiKey: apiKey2,
|
|
25
|
+
policyId,
|
|
26
|
+
baseUrl = DEFAULT_BASE_URL,
|
|
27
|
+
timeoutMs = DEFAULT_TIMEOUT_MS
|
|
28
|
+
} = payload;
|
|
29
|
+
const evalUrl = `${baseUrl.replace(/\/$/, "")}/api/v1/policy-router/evaluate`;
|
|
30
|
+
const content = `tool_name: ${toolName}
|
|
31
|
+
args: ${JSON.stringify(args)}`;
|
|
32
|
+
try {
|
|
33
|
+
const controller = new AbortController();
|
|
34
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
35
|
+
const res = await fetch(evalUrl, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: {
|
|
38
|
+
"Authorization": `Bearer ${apiKey2}`,
|
|
39
|
+
"Content-Type": "application/json"
|
|
40
|
+
},
|
|
41
|
+
body: JSON.stringify({
|
|
42
|
+
subjectContent: content,
|
|
43
|
+
subjectType: "tool_argument",
|
|
44
|
+
direction: "ingress",
|
|
45
|
+
agentId,
|
|
46
|
+
agentType,
|
|
47
|
+
agentName,
|
|
48
|
+
...policyId ? { policyId } : {}
|
|
49
|
+
}),
|
|
50
|
+
signal: controller.signal
|
|
51
|
+
});
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
if (!res.ok) {
|
|
54
|
+
console.warn(`[fastgrc] Evaluate returned ${res.status} \u2014 failing open`);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return await res.json();
|
|
58
|
+
} catch (err) {
|
|
59
|
+
const reason = err instanceof Error && err.name === "AbortError" ? "timeout" : String(err);
|
|
60
|
+
console.warn(`[fastgrc] Evaluate failed (${reason}) \u2014 failing open`);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/plugin.ts
|
|
66
|
+
var DEFAULT_BASE_URL2 = "https://app.fastgrc.ai";
|
|
67
|
+
var DEFAULT_TIMEOUT_MS2 = 3e3;
|
|
68
|
+
var apiKey = resolveApiKey();
|
|
69
|
+
if (!apiKey) {
|
|
70
|
+
console.warn(
|
|
71
|
+
"[fastgrc] No API key found \u2014 all tool calls will proceed unchecked.\n\n Run once to connect:\n fastgrc-hook set-key fgrc_k1_your_key_here\n\n Get a key at: https://app.fastgrc.ai/connect\n Manage keys at: https://app.fastgrc.ai/dashboard/settings"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
var plugin = {
|
|
75
|
+
name: "fastgrc",
|
|
76
|
+
hooks: {
|
|
77
|
+
async before_tool_call(toolName, args, context) {
|
|
78
|
+
if (!apiKey) return void 0;
|
|
79
|
+
const result = await evaluate({
|
|
80
|
+
toolName,
|
|
81
|
+
args,
|
|
82
|
+
agentId: context.id,
|
|
83
|
+
agentType: context.type,
|
|
84
|
+
agentName: context.name,
|
|
85
|
+
apiKey,
|
|
86
|
+
baseUrl: DEFAULT_BASE_URL2,
|
|
87
|
+
timeoutMs: DEFAULT_TIMEOUT_MS2
|
|
88
|
+
});
|
|
89
|
+
if (!result) return void 0;
|
|
90
|
+
const { decision, reasoning, policyContext, reasonTags } = result;
|
|
91
|
+
const matchedRule = policyContext?.matchedRule ?? "policy rule";
|
|
92
|
+
if (decision === "block") {
|
|
93
|
+
return {
|
|
94
|
+
block: true,
|
|
95
|
+
blockReason: `[${matchedRule}] ${reasoning}`
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (decision === "require_approval") {
|
|
99
|
+
return {
|
|
100
|
+
requireApproval: { timeoutBehavior: "deny" }
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (Array.isArray(reasonTags) && reasonTags.includes("override_block_active")) {
|
|
104
|
+
const msg = policyContext?.matchedRule ? `[FastGRC] Observability mode \u2014 would have blocked: [${policyContext.matchedRule}] ${reasoning}` : `[FastGRC] Observability mode \u2014 would have blocked: ${reasoning}`;
|
|
105
|
+
console.warn(msg);
|
|
106
|
+
}
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
var plugin_default = plugin;
|
|
112
|
+
export {
|
|
113
|
+
plugin_default as default
|
|
114
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastgrc-openclaw",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "FastGRC agent compliance plugin for OpenClaw — evaluates every tool call against your policy before it executes",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -10,14 +10,23 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.mjs",
|
|
12
12
|
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./plugin": {
|
|
15
|
+
"types": "./dist/plugin.d.ts",
|
|
16
|
+
"import": "./dist/plugin.mjs",
|
|
17
|
+
"require": "./dist/plugin.js"
|
|
13
18
|
}
|
|
14
19
|
},
|
|
20
|
+
"openclaw": {
|
|
21
|
+
"extensions": ["./dist/plugin.js"]
|
|
22
|
+
},
|
|
15
23
|
"bin": {
|
|
16
24
|
"fastgrc-hook": "./dist/bin.js"
|
|
17
25
|
},
|
|
18
26
|
"files": [
|
|
19
27
|
"dist",
|
|
20
|
-
"README.md"
|
|
28
|
+
"README.md",
|
|
29
|
+
"openclaw.plugin.json"
|
|
21
30
|
],
|
|
22
31
|
"scripts": {
|
|
23
32
|
"build": "tsup && node -e \"require('fs').chmodSync('dist/bin.js', '755')\"",
|