fullcourtdefense-cli 1.21.35 → 1.21.37

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.
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Action-policy evaluation ENGINE — pure, self-contained, no I/O, no imports.
3
+ *
4
+ * This file is the single source of truth for HOW a tool call is matched
5
+ * against org Action Policies. It runs in TWO places:
6
+ *
7
+ * - backend/src/modules/policies/action-policy-engine.ts (server: check-tool-call)
8
+ * - sdks/cli/src/actionPolicyEngine.ts (CLI: OFFLINE enforcement)
9
+ *
10
+ * The CLI copy lets fleet machines keep enforcing the org's real policies when
11
+ * the control plane is unreachable: the runtime bundle ships the policy rules
12
+ * (hash-versioned, so edits bust the cache within one poll) and hooks / the
13
+ * MCP gateway evaluate locally with EXACTLY these semantics.
14
+ *
15
+ * THE TWO COPIES MUST STAY BYTE-IDENTICAL. A CI drift-guard test
16
+ * (backend/src/__tests__/action-policy-engine-sync.test.ts) fails the build if
17
+ * they diverge. Change this file? Copy it to the other location verbatim.
18
+ */
19
+ export type ActionPolicyVerdict = 'allow' | 'block' | 'require_approval' | 'log';
20
+ export interface ActionPolicyConstraint {
21
+ field: string;
22
+ operator: 'contains' | 'not_contains' | 'equals' | 'not_equals' | 'gt' | 'lt' | 'matches';
23
+ value: string;
24
+ }
25
+ export interface ActionPolicyRule {
26
+ operations: string[];
27
+ verdict: ActionPolicyVerdict;
28
+ constraints?: ActionPolicyConstraint[];
29
+ }
30
+ export interface ActionPolicyTargeting {
31
+ developerNames?: string[];
32
+ machineNames?: string[];
33
+ }
34
+ /** The minimal policy shape the engine needs — structurally satisfied by the backend's ActionPolicy. */
35
+ export interface EngineActionPolicy {
36
+ id: string;
37
+ name: string;
38
+ scope?: string;
39
+ /** Rollout stage — `monitor` policies log would-be verdicts without enforcing. Default: enforce. */
40
+ stage?: string;
41
+ /** First-class developer/machine targeting (empty = applies to everyone). */
42
+ appliesTo?: ActionPolicyTargeting;
43
+ resourceType?: string;
44
+ rules: ActionPolicyRule[];
45
+ enabled?: boolean;
46
+ }
47
+ /** A monitor-stage policy match: what WOULD have happened, recorded but not enforced. */
48
+ export interface ActionPolicyMonitorMatch {
49
+ policyId?: string;
50
+ policyName?: string;
51
+ verdict: ActionPolicyVerdict;
52
+ matchedRule?: string;
53
+ }
54
+ export interface EngineCheckResult {
55
+ allowed: boolean;
56
+ verdict: ActionPolicyVerdict;
57
+ policyId?: string;
58
+ policyName?: string;
59
+ resourceType?: string;
60
+ matchedRule?: string;
61
+ reason?: string;
62
+ /** Monitor-stage policies that matched (would-block / would-approve) without enforcing. */
63
+ monitorMatches?: ActionPolicyMonitorMatch[];
64
+ /** Org-scoped policies skipped because the call carried no developerName (for caller-side logging). */
65
+ skippedOrgPolicies?: string[];
66
+ }
67
+ /**
68
+ * Derive the set of canonical operations a tool represents from its NAME and declared inventory
69
+ * actions. This is the "declared operations" model: the tool's identity/declaration defines what
70
+ * operation a bare call performs, NOT a substring match against the raw tool name. Used only for
71
+ * bare invocations (see evaluateActionPolicies).
72
+ */
73
+ export declare function deriveToolOperations(toolName: string, declaredActions?: string[]): string[];
74
+ export declare function toolCapabilities(value: string): Set<string>;
75
+ /**
76
+ * Check a tool call against action policies.
77
+ * Returns the most restrictive matching verdict (pure — callers do their own logging).
78
+ */
79
+ export declare function evaluateActionPolicies(policies: EngineActionPolicy[], toolName: string, operation: string, context?: Record<string, string>, declaredOperations?: string[]): EngineCheckResult;
80
+ /**
81
+ * Infer operation and context from a tool call.
82
+ * Handles common patterns: SQL operations, file paths, HTTP methods, etc.
83
+ */
84
+ export declare function inferToolContext(toolName: string, args: Record<string, any>): {
85
+ operation: string;
86
+ context: Record<string, string>;
87
+ };
88
+ /** Static inventory match — same operation rules as runtime, without constraint context. */
89
+ export declare function inventoryToolMatchesActionPolicy(toolName: string, toolActions: string[] | undefined, policies: EngineActionPolicy[]): boolean;