pi-guard 1.0.0
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 +193 -0
- package/package.json +50 -0
- package/src/config.ts +310 -0
- package/src/extract.ts +424 -0
- package/src/format.ts +206 -0
- package/src/index.ts +426 -0
- package/src/matchers.ts +72 -0
- package/src/matching.ts +133 -0
- package/src/prompt.ts +47 -0
- package/src/resolve.ts +9 -0
- package/src/types.ts +52 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Command } from "unbash";
|
|
2
|
+
|
|
3
|
+
/** A concrete command node together with the source string its positions refer to. */
|
|
4
|
+
export interface CommandRef {
|
|
5
|
+
node: Command;
|
|
6
|
+
source: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Matcher types define how to extract and match input from a tool call. */
|
|
10
|
+
export type MatcherType = "bash" | "glob" | "exact";
|
|
11
|
+
|
|
12
|
+
/** Defines how to extract and match input from a tool call. */
|
|
13
|
+
export interface Matcher {
|
|
14
|
+
/** Tool parameter to extract (e.g., "command", "path", "url") */
|
|
15
|
+
param: string;
|
|
16
|
+
/** How to match the extracted value */
|
|
17
|
+
type: MatcherType;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Permission actions. */
|
|
21
|
+
export type Action = "allow" | "ask" | "deny";
|
|
22
|
+
|
|
23
|
+
/** Rules for a single tool - can be a single action or pattern-based rules. */
|
|
24
|
+
export type ToolRules = Action | Record<string, Action>;
|
|
25
|
+
|
|
26
|
+
/** All rules organized by tool name. */
|
|
27
|
+
export type Rules = Action | Record<string, ToolRules>;
|
|
28
|
+
|
|
29
|
+
/** Custom matchers for additional tools. */
|
|
30
|
+
export type Matchers = Record<string, Matcher>;
|
|
31
|
+
|
|
32
|
+
/** Full configuration for pi-guard. */
|
|
33
|
+
export interface GuardConfig {
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
matchers?: Matchers;
|
|
36
|
+
rules: Rules;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Result of a permission check. */
|
|
40
|
+
export interface PermissionResult {
|
|
41
|
+
/** Whether to block the tool call */
|
|
42
|
+
block: boolean;
|
|
43
|
+
/** Human-readable reason for the decision */
|
|
44
|
+
reason?: string;
|
|
45
|
+
/** Context to inject into the tool result */
|
|
46
|
+
context?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Tool call event shape for type-safe matching. */
|
|
50
|
+
export interface ToolCallInput {
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}
|