@datafog/fogclaw 0.1.4 → 0.1.6
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 +44 -4
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +100 -1
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +127 -30
- package/dist/index.js.map +1 -1
- package/dist/scanner.d.ts +13 -2
- package/dist/scanner.d.ts.map +1 -1
- package/dist/scanner.js +76 -2
- package/dist/scanner.js.map +1 -1
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/docs/plans/active/2026-02-17-feat-release-fogclaw-via-datafog-package-plan.md +24 -21
- package/docs/plugins/fogclaw.md +2 -0
- package/fogclaw.config.example.json +19 -1
- package/openclaw.plugin.json +103 -4
- package/package.json +1 -1
- package/src/config.ts +139 -2
- package/src/index.ts +185 -36
- package/src/scanner.ts +114 -8
- package/src/types.ts +19 -0
- package/tests/config.test.ts +55 -81
- package/tests/plugin-smoke.test.ts +30 -1
- package/tests/scanner.test.ts +61 -1
package/README.md
CHANGED
|
@@ -7,11 +7,15 @@ FogClaw uses a dual-engine approach: battle-tested regex patterns for structured
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
9
|
- **Automatic guardrail** — intercepts messages before they reach the LLM via OpenClaw's `before_agent_start` hook
|
|
10
|
-
- **On-demand tools** — `fogclaw_scan` and `fogclaw_redact`
|
|
10
|
+
- **On-demand tools** — `fogclaw_scan`, `fogclaw_preview`, and `fogclaw_redact`
|
|
11
11
|
- **Dual detection engine** — regex for structured PII (<1ms), GLiNER for zero-shot NER (~50-200ms)
|
|
12
12
|
- **Custom entity types** — define any entity label (e.g., "project codename", "competitor name") and GLiNER detects them with zero training
|
|
13
13
|
- **Configurable actions** — per-entity-type behavior: `redact`, `block`, or `warn`
|
|
14
|
+
- **Per-entity confidence tuning** — tighten or relax detection confidence by label
|
|
15
|
+
- **Policy allowlist** — whitelist exact strings or regex patterns to skip enforcement on known-safe values
|
|
16
|
+
- **Policy preview** — run a dry-run simulation before changing runtime policy
|
|
14
17
|
- **Multiple redaction strategies** — `token`, `mask`, or `hash`
|
|
18
|
+
- **Audit trail summary logging** — optional structured action summaries without logging raw entity content
|
|
15
19
|
- **Graceful degradation** — falls back to regex-only mode if GLiNER fails to load
|
|
16
20
|
|
|
17
21
|
## Installation
|
|
@@ -60,6 +64,10 @@ cp fogclaw.config.example.json fogclaw.config.json
|
|
|
60
64
|
"redactStrategy": "token",
|
|
61
65
|
"model": "onnx-community/gliner_large-v2.1",
|
|
62
66
|
"confidence_threshold": 0.5,
|
|
67
|
+
"entityConfidenceThresholds": {
|
|
68
|
+
"PERSON": 0.6,
|
|
69
|
+
"ORGANIZATION": 0.7
|
|
70
|
+
},
|
|
63
71
|
"custom_entities": ["project codename", "competitor name"],
|
|
64
72
|
"entityActions": {
|
|
65
73
|
"SSN": "block",
|
|
@@ -67,7 +75,15 @@ cp fogclaw.config.example.json fogclaw.config.json
|
|
|
67
75
|
"EMAIL": "redact",
|
|
68
76
|
"PHONE": "redact",
|
|
69
77
|
"PERSON": "warn"
|
|
70
|
-
}
|
|
78
|
+
},
|
|
79
|
+
"allowlist": {
|
|
80
|
+
"values": ["noreply@example.com"],
|
|
81
|
+
"patterns": ["^internal-"],
|
|
82
|
+
"entities": {
|
|
83
|
+
"PERSON": ["john doe"]
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"auditEnabled": true
|
|
71
87
|
}
|
|
72
88
|
```
|
|
73
89
|
|
|
@@ -113,13 +129,13 @@ Incoming message
|
|
|
113
129
|
+-----------+
|
|
114
130
|
| GLiNER | persons, orgs, locations + your custom entities
|
|
115
131
|
| (ONNX) | confidence: 0.0-1.0
|
|
116
|
-
|
|
132
|
+
+-----------+
|
|
117
133
|
|
|
|
118
134
|
v
|
|
119
135
|
+-----------+
|
|
120
136
|
| Merge & | deduplicate overlapping spans, prefer higher confidence
|
|
121
137
|
| Normalize |
|
|
122
|
-
|
|
138
|
+
+-----------+
|
|
123
139
|
|
|
|
124
140
|
v
|
|
125
141
|
Apply action per entity type (redact / block / warn)
|
|
@@ -162,8 +178,11 @@ Plus any labels you add via `custom_entities` in the config.
|
|
|
162
178
|
| `redactStrategy` | `string` | `"token"` | How to redact: `"token"`, `"mask"`, or `"hash"` |
|
|
163
179
|
| `model` | `string` | `"onnx-community/gliner_large-v2.1"` | HuggingFace model path for GLiNER (or a local `.onnx` path for advanced setups). |
|
|
164
180
|
| `confidence_threshold` | `number` | `0.5` | Minimum confidence for GLiNER detections (0-1) |
|
|
181
|
+
| `entityConfidenceThresholds` | `object` | `{}` | Per-label confidence overrides, e.g. `{ "PERSON": 0.7, "ORGANIZATION": 0.85 }` |
|
|
165
182
|
| `custom_entities` | `string[]` | `[]` | Custom entity labels for zero-shot detection |
|
|
166
183
|
| `entityActions` | `object` | `{}` | Per-entity-type action overrides |
|
|
184
|
+
| `allowlist` | `object` | `{}` | Exception rules to skip enforcement via exact values or regex patterns |
|
|
185
|
+
| `auditEnabled` | `boolean` | `true` | Emit structured audit logs for guardrail decisions |
|
|
167
186
|
|
|
168
187
|
## OpenClaw Tools
|
|
169
188
|
|
|
@@ -175,6 +194,21 @@ Scan text for PII and custom entities. Returns detected entities with types, pos
|
|
|
175
194
|
- `text` (required) — text to scan
|
|
176
195
|
- `custom_labels` (optional) — additional entity labels for zero-shot detection
|
|
177
196
|
|
|
197
|
+
### `fogclaw_preview`
|
|
198
|
+
|
|
199
|
+
Preview what the guardrail would do for a message.
|
|
200
|
+
|
|
201
|
+
**Parameters:**
|
|
202
|
+
- `text` (required) — text to simulate
|
|
203
|
+
- `strategy` (optional) — `"token"`, `"mask"`, or `"hash"` (defaults to config)
|
|
204
|
+
- `custom_labels` (optional) — additional entity labels for zero-shot detection
|
|
205
|
+
|
|
206
|
+
**Response:**
|
|
207
|
+
- `entities`: detected entities and metadata
|
|
208
|
+
- `totalEntities`: total entities found
|
|
209
|
+
- `actionPlan`: counts and labels grouped by `blocked`, `warned`, `redacted`
|
|
210
|
+
- `redactedText`: message with only redacted entities applied
|
|
211
|
+
|
|
178
212
|
### `fogclaw_redact`
|
|
179
213
|
|
|
180
214
|
Scan and redact PII/custom entities from text. Returns sanitized text with entities replaced.
|
|
@@ -219,6 +253,12 @@ npm run build # compile TypeScript
|
|
|
219
253
|
npm run lint # type-check without emitting
|
|
220
254
|
```
|
|
221
255
|
|
|
256
|
+
## Security Notes
|
|
257
|
+
|
|
258
|
+
- Keep `api.logger` output free of raw sensitive values.
|
|
259
|
+
- Use allowlists and `auditEnabled` according to your governance requirements.
|
|
260
|
+
- Consider `block` actions for high-risk entity types in regulated environments.
|
|
261
|
+
|
|
222
262
|
## License
|
|
223
263
|
|
|
224
264
|
MIT
|
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type FogClawConfig } from "./types.js";
|
|
2
2
|
export declare const DEFAULT_CONFIG: FogClawConfig;
|
|
3
3
|
export declare function loadConfig(overrides: Partial<FogClawConfig>): FogClawConfig;
|
|
4
4
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,YAAY,CAAC;AAoGpB,eAAO,MAAM,cAAc,EAAE,aAe5B,CAAC;AAEF,wBAAgB,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,CA2D3E"}
|
package/dist/config.js
CHANGED
|
@@ -1,5 +1,74 @@
|
|
|
1
|
+
import { canonicalType, } from "./types.js";
|
|
1
2
|
const VALID_GUARDRAIL_MODES = ["redact", "block", "warn"];
|
|
2
3
|
const VALID_REDACT_STRATEGIES = ["token", "mask", "hash"];
|
|
4
|
+
function ensureStringList(value, path) {
|
|
5
|
+
if (!Array.isArray(value)) {
|
|
6
|
+
throw new Error(`${path} must be an array of strings`);
|
|
7
|
+
}
|
|
8
|
+
const entries = value.filter((entry) => {
|
|
9
|
+
if (typeof entry !== "string") {
|
|
10
|
+
throw new Error(`${path} must contain only strings`);
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
});
|
|
14
|
+
return entries.map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
15
|
+
}
|
|
16
|
+
function ensureEntityAllowlist(value) {
|
|
17
|
+
if (value == null) {
|
|
18
|
+
return { values: [], patterns: [], entities: {} };
|
|
19
|
+
}
|
|
20
|
+
if (typeof value !== "object" || Array.isArray(value)) {
|
|
21
|
+
throw new Error("allowlist must be an object");
|
|
22
|
+
}
|
|
23
|
+
const raw = value;
|
|
24
|
+
const values = ensureStringList(raw.values ?? [], "allowlist.values");
|
|
25
|
+
const patterns = ensureStringList(raw.patterns ?? [], "allowlist.patterns");
|
|
26
|
+
for (const pattern of patterns) {
|
|
27
|
+
try {
|
|
28
|
+
new RegExp(pattern);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
throw new Error(`allowlist.patterns contains invalid regex pattern: "${pattern}"`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const entitiesValue = raw.entities ?? {};
|
|
35
|
+
if (typeof entitiesValue !== "object" ||
|
|
36
|
+
Array.isArray(entitiesValue) ||
|
|
37
|
+
entitiesValue === null) {
|
|
38
|
+
throw new Error("allowlist.entities must be an object mapping entity labels to string arrays");
|
|
39
|
+
}
|
|
40
|
+
const entities = {};
|
|
41
|
+
for (const [entityType, entryValue] of Object.entries(entitiesValue)) {
|
|
42
|
+
const normalizedType = canonicalType(entityType);
|
|
43
|
+
entities[normalizedType] = ensureStringList(entryValue, `allowlist.entities.${entityType}`);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
values: [...new Set(values)],
|
|
47
|
+
patterns: [...new Set(patterns)],
|
|
48
|
+
entities,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function ensureEntityConfidenceThresholds(value) {
|
|
52
|
+
if (!value) {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
if (typeof value !== "object" || Array.isArray(value) || value === null) {
|
|
56
|
+
throw new Error("entityConfidenceThresholds must be an object");
|
|
57
|
+
}
|
|
58
|
+
const raw = value;
|
|
59
|
+
const normalized = {};
|
|
60
|
+
for (const [entityType, rawThreshold] of Object.entries(raw)) {
|
|
61
|
+
if (typeof rawThreshold !== "number" || Number.isNaN(rawThreshold)) {
|
|
62
|
+
throw new Error(`entityConfidenceThresholds["${entityType}"] must be a number between 0 and 1, got ${String(rawThreshold)}`);
|
|
63
|
+
}
|
|
64
|
+
if (rawThreshold < 0 || rawThreshold > 1) {
|
|
65
|
+
throw new Error(`entityConfidenceThresholds["${entityType}"] must be between 0 and 1, got ${rawThreshold}`);
|
|
66
|
+
}
|
|
67
|
+
const canonicalTypeKey = canonicalType(entityType);
|
|
68
|
+
normalized[canonicalTypeKey] = rawThreshold;
|
|
69
|
+
}
|
|
70
|
+
return normalized;
|
|
71
|
+
}
|
|
3
72
|
export const DEFAULT_CONFIG = {
|
|
4
73
|
enabled: true,
|
|
5
74
|
guardrail_mode: "redact",
|
|
@@ -8,9 +77,32 @@ export const DEFAULT_CONFIG = {
|
|
|
8
77
|
confidence_threshold: 0.5,
|
|
9
78
|
custom_entities: [],
|
|
10
79
|
entityActions: {},
|
|
80
|
+
entityConfidenceThresholds: {},
|
|
81
|
+
allowlist: {
|
|
82
|
+
values: [],
|
|
83
|
+
patterns: [],
|
|
84
|
+
entities: {},
|
|
85
|
+
},
|
|
86
|
+
auditEnabled: true,
|
|
11
87
|
};
|
|
12
88
|
export function loadConfig(overrides) {
|
|
13
|
-
const config = {
|
|
89
|
+
const config = {
|
|
90
|
+
...DEFAULT_CONFIG,
|
|
91
|
+
...overrides,
|
|
92
|
+
entityActions: {
|
|
93
|
+
...DEFAULT_CONFIG.entityActions,
|
|
94
|
+
...(overrides.entityActions ?? {}),
|
|
95
|
+
},
|
|
96
|
+
entityConfidenceThresholds: {
|
|
97
|
+
...DEFAULT_CONFIG.entityConfidenceThresholds,
|
|
98
|
+
...(overrides.entityConfidenceThresholds ?? {}),
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
config.allowlist = ensureEntityAllowlist(overrides.allowlist ?? DEFAULT_CONFIG.allowlist);
|
|
102
|
+
config.entityConfidenceThresholds = ensureEntityConfidenceThresholds(config.entityConfidenceThresholds);
|
|
103
|
+
if (typeof config.enabled !== "boolean") {
|
|
104
|
+
throw new Error(`enabled must be true or false`);
|
|
105
|
+
}
|
|
14
106
|
if (!VALID_GUARDRAIL_MODES.includes(config.guardrail_mode)) {
|
|
15
107
|
throw new Error(`Invalid guardrail_mode "${config.guardrail_mode}". Must be one of: ${VALID_GUARDRAIL_MODES.join(", ")}`);
|
|
16
108
|
}
|
|
@@ -20,11 +112,18 @@ export function loadConfig(overrides) {
|
|
|
20
112
|
if (config.confidence_threshold < 0 || config.confidence_threshold > 1) {
|
|
21
113
|
throw new Error(`confidence_threshold must be between 0 and 1, got ${config.confidence_threshold}`);
|
|
22
114
|
}
|
|
115
|
+
if (typeof config.auditEnabled !== "boolean") {
|
|
116
|
+
throw new Error(`auditEnabled must be true or false`);
|
|
117
|
+
}
|
|
118
|
+
const normalizedActions = {};
|
|
23
119
|
for (const [entityType, action] of Object.entries(config.entityActions)) {
|
|
24
120
|
if (!VALID_GUARDRAIL_MODES.includes(action)) {
|
|
25
121
|
throw new Error(`Invalid action "${action}" for entity type "${entityType}". Must be one of: ${VALID_GUARDRAIL_MODES.join(", ")}`);
|
|
26
122
|
}
|
|
123
|
+
const normalizedType = canonicalType(entityType);
|
|
124
|
+
normalizedActions[normalizedType] = action;
|
|
27
125
|
}
|
|
126
|
+
config.entityActions = normalizedActions;
|
|
28
127
|
return config;
|
|
29
128
|
}
|
|
30
129
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAKd,MAAM,YAAY,CAAC;AAEpB,MAAM,qBAAqB,GAAsB,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAC7E,MAAM,uBAAuB,GAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5E,SAAS,gBAAgB,CAAC,KAAc,EAAE,IAAY;IACpD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,8BAA8B,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE;QACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,4BAA4B,CAAC,CAAC;QACvD,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAClF,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc;IAC3C,IAAI,KAAK,IAAI,IAAI,EA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,CAAC,EAAE,CAAC;QAC7D,MAAM,IAAI,KAAK,CACb,2BAA2B,MAAM,CAAC,cAAc,sBAAsB,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC3G,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,oBAAoB,GAAG,CAAC,IAAI,MAAM,CAAC,oBAAoB,GAAG,CAAC,EAAE,CAAC;QACvE,MAAM,IAAI,KAAK,CACb,qDAAqD,MAAM,CAAC,oBAAoB,EAAE,CACnF,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,MAAM,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,iBAAiB,GAAoC,EAAE,CAAC;IAC9D,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QACxE,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CACb,mBAAmB,MAAM,sBAAsB,UAAU,sBAAsB,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAClH,CAAC;QACJ,CAAC;QAED,MAAM,cAAc,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;QACjD,iBAAiB,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC;IAC7C,CAAC;IACD,MAAM,CAAC,aAAa,GAAG,iBAAiB,CAAC;IAEzC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type { Entity, FogClawConfig, ScanResult, RedactResult, RedactStrategy, G
|
|
|
8
8
|
* Registers:
|
|
9
9
|
* - `before_agent_start` hook for automatic PII guardrail
|
|
10
10
|
* - `fogclaw_scan` tool for on-demand entity detection
|
|
11
|
+
* - `fogclaw_preview` tool for dry-run policy simulation
|
|
11
12
|
* - `fogclaw_redact` tool for on-demand redaction
|
|
12
13
|
*/
|
|
13
14
|
declare const fogclaw: {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzD,YAAY,EACV,MAAM,EACN,aAAa,EACb,UAAU,EACV,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,YAAY,CAAC;AAyEpB;;;;;;;;GAQG;AACH,QAAA,MAAM,OAAO;;;kBAIG,GAAG;CAqQlB,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,12 +4,61 @@ import { loadConfig } from "./config.js";
|
|
|
4
4
|
export { Scanner } from "./scanner.js";
|
|
5
5
|
export { redact } from "./redactor.js";
|
|
6
6
|
export { loadConfig, DEFAULT_CONFIG } from "./config.js";
|
|
7
|
+
function resolveAction(entity, config) {
|
|
8
|
+
return config.entityActions[entity.label] ?? config.guardrail_mode;
|
|
9
|
+
}
|
|
10
|
+
function buildGuardrailPlan(entities, config) {
|
|
11
|
+
const blocked = [];
|
|
12
|
+
const warned = [];
|
|
13
|
+
const redacted = [];
|
|
14
|
+
for (const entity of entities) {
|
|
15
|
+
const action = resolveAction(entity, config);
|
|
16
|
+
if (action === "block")
|
|
17
|
+
blocked.push(entity);
|
|
18
|
+
else if (action === "warn")
|
|
19
|
+
warned.push(entity);
|
|
20
|
+
else
|
|
21
|
+
redacted.push(entity);
|
|
22
|
+
}
|
|
23
|
+
return { blocked, warned, redacted };
|
|
24
|
+
}
|
|
25
|
+
function planToSummary(plan) {
|
|
26
|
+
return {
|
|
27
|
+
total: plan.blocked.length + plan.warned.length + plan.redacted.length,
|
|
28
|
+
blocked: plan.blocked.length,
|
|
29
|
+
warned: plan.warned.length,
|
|
30
|
+
redacted: plan.redacted.length,
|
|
31
|
+
labels: {
|
|
32
|
+
blocked: [...new Set(plan.blocked.map((entity) => entity.label))],
|
|
33
|
+
warned: [...new Set(plan.warned.map((entity) => entity.label))],
|
|
34
|
+
redacted: [...new Set(plan.redacted.map((entity) => entity.label))],
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function buildGuardrailContext(plan, config) {
|
|
39
|
+
const contextParts = [];
|
|
40
|
+
if (plan.blocked.length > 0) {
|
|
41
|
+
const types = [...new Set(plan.blocked.map((entity) => entity.label))].join(", ");
|
|
42
|
+
contextParts.push(`[FOGCLAW GUARDRAIL — BLOCKED] The user's message contains sensitive information (${types}). ` +
|
|
43
|
+
`Do NOT process or repeat this information. Ask the user to rephrase without sensitive data.`);
|
|
44
|
+
}
|
|
45
|
+
if (plan.warned.length > 0) {
|
|
46
|
+
const types = [...new Set(plan.warned.map((entity) => entity.label))].join(", ");
|
|
47
|
+
contextParts.push(`[FOGCLAW NOTICE] PII detected in user message: ${types}. Handle with care.`);
|
|
48
|
+
}
|
|
49
|
+
if (plan.redacted.length > 0) {
|
|
50
|
+
const labels = [...new Set(plan.redacted.map((entity) => entity.label))].join(", ");
|
|
51
|
+
contextParts.push(`[FOGCLAW REDACTED] ${plan.redacted.length} entity(ies) prepared for ${config.redactStrategy} redaction (${labels}).`);
|
|
52
|
+
}
|
|
53
|
+
return contextParts;
|
|
54
|
+
}
|
|
7
55
|
/**
|
|
8
56
|
* OpenClaw plugin definition.
|
|
9
57
|
*
|
|
10
58
|
* Registers:
|
|
11
59
|
* - `before_agent_start` hook for automatic PII guardrail
|
|
12
60
|
* - `fogclaw_scan` tool for on-demand entity detection
|
|
61
|
+
* - `fogclaw_preview` tool for dry-run policy simulation
|
|
13
62
|
* - `fogclaw_redact` tool for on-demand redaction
|
|
14
63
|
*/
|
|
15
64
|
const fogclaw = {
|
|
@@ -36,35 +85,23 @@ const fogclaw = {
|
|
|
36
85
|
const result = await scanner.scan(message);
|
|
37
86
|
if (result.entities.length === 0)
|
|
38
87
|
return;
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
88
|
+
const plan = buildGuardrailPlan(result.entities, config);
|
|
89
|
+
const contextParts = buildGuardrailContext(plan, config);
|
|
90
|
+
if (config.auditEnabled) {
|
|
91
|
+
const summary = planToSummary(plan);
|
|
92
|
+
api.logger?.info(`[FOGCLAW AUDIT] guardrail_scan ${JSON.stringify({
|
|
93
|
+
totalEntities: summary.total,
|
|
94
|
+
blocked: summary.blocked,
|
|
95
|
+
warned: summary.warned,
|
|
96
|
+
redacted: summary.redacted,
|
|
97
|
+
blockedLabels: summary.labels.blocked,
|
|
98
|
+
warnedLabels: summary.labels.warned,
|
|
99
|
+
redactedLabels: summary.labels.redacted,
|
|
100
|
+
})}`);
|
|
51
101
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const types = [...new Set(blocked.map((e) => e.label))].join(", ");
|
|
56
|
-
contextParts.push(`[FOGCLAW GUARDRAIL — BLOCKED] The user's message contains sensitive information (${types}). ` +
|
|
57
|
-
`Do NOT process or repeat this information. Ask the user to rephrase without sensitive data.`);
|
|
58
|
-
}
|
|
59
|
-
// "warn" — inject a warning notice
|
|
60
|
-
if (warned.length > 0) {
|
|
61
|
-
const types = [...new Set(warned.map((e) => e.label))].join(", ");
|
|
62
|
-
contextParts.push(`[FOGCLAW NOTICE] PII detected in user message: ${types}. Handle with care.`);
|
|
63
|
-
}
|
|
64
|
-
// "redact" — replace PII with tokens
|
|
65
|
-
if (toRedact.length > 0) {
|
|
66
|
-
const redacted = redact(message, toRedact, config.redactStrategy);
|
|
67
|
-
contextParts.push(`[FOGCLAW REDACTED] The following is the user's message with PII redacted:\n${redacted.redacted_text}`);
|
|
102
|
+
if (plan.redacted.length > 0) {
|
|
103
|
+
const redactedResult = redact(message, plan.redacted, config.redactStrategy);
|
|
104
|
+
contextParts.push(`[FOGCLAW REDACTED] The following is the user's message with PII redacted:\n${redactedResult.redacted_text}`);
|
|
68
105
|
}
|
|
69
106
|
if (contextParts.length > 0) {
|
|
70
107
|
return { prependContext: contextParts.join("\n\n") };
|
|
@@ -100,7 +137,7 @@ const fogclaw = {
|
|
|
100
137
|
entities: result.entities,
|
|
101
138
|
count: result.entities.length,
|
|
102
139
|
summary: result.entities.length > 0
|
|
103
|
-
? `Found ${result.entities.length} entities: ${[...new Set(result.entities.map((
|
|
140
|
+
? `Found ${result.entities.length} entities: ${[...new Set(result.entities.map((entity) => entity.label))].join(", ")}`
|
|
104
141
|
: "No entities detected",
|
|
105
142
|
}, null, 2),
|
|
106
143
|
},
|
|
@@ -108,6 +145,66 @@ const fogclaw = {
|
|
|
108
145
|
};
|
|
109
146
|
},
|
|
110
147
|
});
|
|
148
|
+
// --- TOOL: Policy preview ---
|
|
149
|
+
api.registerTool({
|
|
150
|
+
name: "fogclaw_preview",
|
|
151
|
+
id: "fogclaw_preview",
|
|
152
|
+
description: "Preview which entities will be blocked, warned, or redacted and the redacted message, without changing runtime behavior.",
|
|
153
|
+
schema: {
|
|
154
|
+
type: "object",
|
|
155
|
+
properties: {
|
|
156
|
+
text: {
|
|
157
|
+
type: "string",
|
|
158
|
+
description: "Text to run through FogClaw policy preview",
|
|
159
|
+
},
|
|
160
|
+
strategy: {
|
|
161
|
+
type: "string",
|
|
162
|
+
description: 'Override redaction strategy for the preview: "token" ([EMAIL_1]), "mask" (****), or "hash" ([EMAIL_a1b2c3...]).',
|
|
163
|
+
enum: ["token", "mask", "hash"],
|
|
164
|
+
},
|
|
165
|
+
custom_labels: {
|
|
166
|
+
type: "array",
|
|
167
|
+
items: { type: "string" },
|
|
168
|
+
description: "Additional entity labels for zero-shot detection",
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
required: ["text"],
|
|
172
|
+
},
|
|
173
|
+
handler: async ({ text, strategy, custom_labels, }) => {
|
|
174
|
+
const result = await scanner.scan(text, custom_labels);
|
|
175
|
+
const plan = buildGuardrailPlan(result.entities, config);
|
|
176
|
+
const summary = planToSummary(plan);
|
|
177
|
+
const redacted = redact(text, plan.redacted, strategy ?? config.redactStrategy);
|
|
178
|
+
return {
|
|
179
|
+
content: [
|
|
180
|
+
{
|
|
181
|
+
type: "text",
|
|
182
|
+
text: JSON.stringify({
|
|
183
|
+
entities: result.entities,
|
|
184
|
+
totalEntities: summary.total,
|
|
185
|
+
actionPlan: {
|
|
186
|
+
blocked: {
|
|
187
|
+
count: summary.blocked,
|
|
188
|
+
labels: summary.labels.blocked,
|
|
189
|
+
},
|
|
190
|
+
warned: {
|
|
191
|
+
count: summary.warned,
|
|
192
|
+
labels: summary.labels.warned,
|
|
193
|
+
},
|
|
194
|
+
redacted: {
|
|
195
|
+
count: summary.redacted,
|
|
196
|
+
labels: summary.labels.redacted,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
redactedText: redacted.redacted_text,
|
|
200
|
+
redactionStrategy: strategy ?? config.redactStrategy,
|
|
201
|
+
mapping: redacted.mapping,
|
|
202
|
+
}, null, 2),
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
};
|
|
206
|
+
},
|
|
207
|
+
});
|
|
111
208
|
// --- TOOL: On-demand redact ---
|
|
112
209
|
api.registerTool({
|
|
113
210
|
name: "fogclaw_redact",
|
|
@@ -150,7 +247,7 @@ const fogclaw = {
|
|
|
150
247
|
};
|
|
151
248
|
},
|
|
152
249
|
});
|
|
153
|
-
api.logger?.info(`[fogclaw] Plugin registered — guardrail: ${config.guardrail_mode}, model: ${config.model}, custom entities: ${config.custom_entities.length}`);
|
|
250
|
+
api.logger?.info(`[fogclaw] Plugin registered — guardrail: ${config.guardrail_mode}, model: ${config.model}, custom entities: ${config.custom_entities.length}, audit: ${config.auditEnabled}`);
|
|
154
251
|
},
|
|
155
252
|
};
|
|
156
253
|
export default fogclaw;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAUzC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAUzD,SAAS,aAAa,CAAC,MAAc,EAAE,MAAqB;IAC1D,OAAO,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,cAAc,CAAC;AACrE,CAAC;AAED,SAAS,kBAAkB,CAAC,QAAkB,EAAE,MAAqB;IACnE,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,KAAK,MAAM,MAAM,IAAI,QAAQ,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,M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AY,MAAM,CAAC,KAAK,sBAAsB,MAAM,CAAC,eAAe,CAAC,MAAM,YAAY,MAAM,CAAC,YAAY,EAAE,CAC9K,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
package/dist/scanner.d.ts
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Entity, FogClawConfig } from "./types.js";
|
|
2
2
|
export declare class Scanner {
|
|
3
3
|
private regexEngine;
|
|
4
4
|
private glinerEngine;
|
|
5
5
|
private glinerAvailable;
|
|
6
6
|
private config;
|
|
7
|
+
private allowlist;
|
|
7
8
|
constructor(config: FogClawConfig);
|
|
8
9
|
initialize(): Promise<void>;
|
|
9
|
-
scan(text: string, extraLabels?: string[]): Promise<
|
|
10
|
+
scan(text: string, extraLabels?: string[]): Promise<{
|
|
11
|
+
entities: Entity[];
|
|
12
|
+
text: string;
|
|
13
|
+
}>;
|
|
14
|
+
private filterByConfidence;
|
|
15
|
+
private filterByPolicy;
|
|
16
|
+
private shouldAllowlistEntity;
|
|
17
|
+
private getThresholdForLabel;
|
|
18
|
+
private computeGlinerThreshold;
|
|
19
|
+
private buildAllowlistCache;
|
|
20
|
+
get isGlinerAvailable(): boolean;
|
|
10
21
|
}
|
|
11
22
|
//# sourceMappingURL=scanner.d.ts.map
|
package/dist/scanner.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAuBxD,qBAAa,OAAO;IAClB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,SAAS,CAAwB;gBAE7B,MAAM,EAAE,aAAa;IAa3B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IA4B/F,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,qBAAqB;IAmB7B,OAAO,CAAC,oBAAoB;IAK5B,OAAO,CAAC,sBAAsB;IAS9B,OAAO,CAAC,mBAAmB;IAuB3B,IAAI,iBAAiB,IAAI,OAAO,CAE/B;CACF"}
|