fullcourtdefense 2.1.2 → 2.3.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 +35 -4
- package/dist/anthropic.js +2 -0
- package/dist/client.d.ts +80 -1
- package/dist/client.js +425 -12
- package/dist/localDecision.d.ts +100 -0
- package/dist/localDecision.js +246 -0
- package/dist/localGate.d.ts +8 -0
- package/dist/localGate.js +41 -4
- package/dist/localSafety.d.ts +48 -0
- package/dist/localSafety.js +220 -0
- package/dist/policy/acorn.js +6365 -0
- package/dist/policy/actionPolicyEngine.d.ts +448 -0
- package/dist/policy/actionPolicyEngine.js +6560 -0
- package/dist/policy/detectionData.d.ts +21 -0
- package/dist/policy/detectionData.js +71 -0
- package/dist/policy/detectorRuntime.d.ts +27 -0
- package/dist/policy/detectorRuntime.js +58 -0
- package/dist/policy/deterministicGuard.d.ts +406 -0
- package/dist/policy/deterministicGuard.js +6829 -0
- package/dist/protect.d.ts +6 -0
- package/dist/protect.js +18 -0
- package/dist/recordQueue.d.ts +108 -0
- package/dist/recordQueue.js +296 -0
- package/dist/types.d.ts +57 -1
- package/package.json +16 -10
package/README.md
CHANGED
|
@@ -61,13 +61,15 @@ await run(agent, 'Who is customer c-1?');
|
|
|
61
61
|
What happens on each call:
|
|
62
62
|
|
|
63
63
|
```
|
|
64
|
-
agent asks for tool -> protect() ->
|
|
65
|
-
(
|
|
66
|
-
|
|
64
|
+
agent asks for tool -> protect() -> decided in your process -> allow: run tool, record in the background
|
|
65
|
+
(your organisation's policy, -> block: throw, tool never runs
|
|
66
|
+
refreshed every 60 s) -> approval: throw (or wait, see below)
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
- **No request per tool call.** The SDK holds a copy of your policy and decides in well under a millisecond; FullCourtDefense being slow or unreachable does not delay a call. Only a call that needs a manager's approval contacts FullCourtDefense while it runs. Details: [Local decisions](#local-decisions-default-no-request-per-tool-call).
|
|
70
|
+
|
|
69
71
|
- **Identity:** every call carries the agent's name. Without `FCD_AGENT_ID` it is the service the process runs as (`OTEL_SERVICE_NAME`, Cloud Run `K_SERVICE`, `AWS_LAMBDA_FUNCTION_NAME`, Azure Container Apps / App Service), then the npm package (`npm start`), then the main script — and the call says it was derived (`agentIdSource: 'default'`).
|
|
70
|
-
- **A wrong key, an unknown shield
|
|
72
|
+
- **A wrong, expired or rotated key, or an unknown shield (HTTP 401 / 403 / 404), never stops your agent.** The SDK says so loudly once (`console.error`, and `onDegrade`), keeps deciding from the policies it already holds, and with none yet answers by `FCD_FAIL_MODE` (default `tiered`: the tool runs and is reported as "ran without a check" once a key works; `closed` stops it). On a Monitor shield the tool runs and the call is still reported, so FullCourtDefense raises a "wrong or missing shield key" alert. **A refused request (HTTP 400, and any other 4xx except 408 / 429) is not an outage:** the tool does not run and `FullCourtDefenseApiError` says what to fix. Only a real outage and a refused key are answered by `FCD_FAIL_MODE` (below).
|
|
71
73
|
- **Arguments too deep or too large to check** (nested deeper than 32 levels, more than 20,000 values, or not encodable as JSON) are never sent: on Block the call is stopped ("too large to check safely"), in Monitor it runs and the record says what was not sent. Never an outage, and they cannot trip the circuit breaker.
|
|
72
74
|
|
|
73
75
|
No text leaves your process by default. Text scanning (prompt injection in user input, poisoned tool output, RAG chunks) is a separate, opt-in capability — see [Text scanning (opt-in)](#text-scanning-opt-in).
|
|
@@ -133,6 +135,14 @@ FCD_MODE_AT_PROTECT monitor # the shield's mode, rewritten whe
|
|
|
133
135
|
|
|
134
136
|
---
|
|
135
137
|
|
|
138
|
+
## Upgrading to 2.3
|
|
139
|
+
|
|
140
|
+
| 2.2 | 2.3 |
|
|
141
|
+
|---|---|
|
|
142
|
+
| A wrong, expired or rotated shield key, or an unknown shield (HTTP 401 / 403 / 404), stopped every tool of a Block-mode agent with `FullCourtDefenseApiError` | **It never stops your agent.** The SDK says so once on `console.error` (and `onDegrade`), keeps deciding from the policies it holds, and with none answers by `FCD_FAIL_MODE` (default `tiered`: the tool runs and is reported once a key works). Set `FCD_FAIL_MODE=closed` to keep stopping. **Breaking** if your code catches `FullCourtDefenseApiError` with `status` 401 / 403 / 404 on a tool call: it is no longer thrown there (a 400 still is). |
|
|
143
|
+
| The first Block-mode call of a process waited up to 3 s for the first policies | Up to **1 s** (`FCD_COLD_START_WAIT_MS` / `coldStartWaitMs` to change it; `await fcd.ready()` at start-up waits once, outside any tool call). |
|
|
144
|
+
| A record sent again after a slow answer could be stored twice; records refused during a bad-key window were dropped in silence | Every record carries an id (one record per action); refused records are reported as a gap ("N actions were not recorded"). |
|
|
145
|
+
|
|
136
146
|
## Upgrading to 2.1
|
|
137
147
|
|
|
138
148
|
| 2.0 | 2.1 |
|
|
@@ -748,6 +758,27 @@ the console:
|
|
|
748
758
|
The mode is cached for 60s, so flipping monitor → block in the console takes
|
|
749
759
|
effect within a minute without redeploying your agent.
|
|
750
760
|
|
|
761
|
+
### Local decisions (default): no request per tool call
|
|
762
|
+
|
|
763
|
+
With `decisionMode: 'local'` (the default; env `FCD_DECISION_MODE`) a Block-mode tool call is decided **in your process**
|
|
764
|
+
from the shield's policies, with the same policy engine and the same answer the API gives. The SDK fetches the policies
|
|
765
|
+
when the client is built and refreshes them every 60 s in the background; a tool call never waits for that.
|
|
766
|
+
|
|
767
|
+
- The call's record (what was decided, which rule, how the tool ended, the provider's tool-call id) is sent afterwards,
|
|
768
|
+
in background batches. If FullCourtDefense is down the records wait in memory (bounded) and are sent once it is back;
|
|
769
|
+
at exit they are flushed briefly or kept in the local spool for the next run.
|
|
770
|
+
- The built-in safety rules (command, file and web tools) are decided locally too, with the rules FullCourtDefense
|
|
771
|
+
serves in the same bundle. Only a call that needs a **manager's approval** goes to FullCourtDefense while it runs, plus
|
|
772
|
+
the rare call the bundle cannot decide: a policy that reads the agent's recorded history, a suspended shield.
|
|
773
|
+
- Cold start: a Block-mode call made in the first 1 s after the client was built waits for the first policies
|
|
774
|
+
(`coldStartWaitMs`, env `FCD_COLD_START_WAIT_MS`; `0` = never wait), so a short-lived agent's first call is checked.
|
|
775
|
+
After that, or if FullCourtDefense cannot be reached, a call with no policies runs, is recorded, and one warning says
|
|
776
|
+
so: the agent is never stalled. `await fcd.ready()` waits for the policies once at start-up instead.
|
|
777
|
+
- `decisionMode: 'server'` (or `FCD_DECISION_MODE=server`) restores a check request per call. FullCourtDefense can also
|
|
778
|
+
switch local decisions off for every agent from the server.
|
|
779
|
+
- Pass the model's tool-call id as `toolCallId` (`protect()` and `anthropicToolResults()` do it for Vercel AI, LangChain
|
|
780
|
+
and Anthropic): when a local AI gateway also sees the same call, one action stays one record.
|
|
781
|
+
|
|
751
782
|
### Tiered by default in Enforce, never blocking in Monitor
|
|
752
783
|
|
|
753
784
|
A tool call is answered quickly in every case: allow, or a typed refusal. Nothing waits for a manager inside the call
|
package/dist/anthropic.js
CHANGED
|
@@ -42,6 +42,8 @@ async function anthropicToolResults(fcd, content, handlers, options = {}) {
|
|
|
42
42
|
toolName: block.name,
|
|
43
43
|
toolArgs: input,
|
|
44
44
|
framework: 'anthropic',
|
|
45
|
+
// The tool_use id: one action = one record when a local AI gateway also saw this call.
|
|
46
|
+
...(typeof block.id === 'string' && block.id ? { toolCallId: block.id } : {}),
|
|
45
47
|
agentName: options.agentName,
|
|
46
48
|
sessionId: options.sessionId,
|
|
47
49
|
operation: options.operation,
|
package/dist/client.d.ts
CHANGED
|
@@ -52,17 +52,68 @@ export declare class FullCourtDefense {
|
|
|
52
52
|
/** O4: a Monitor call ran with a refused key or shield and stderr said so (once, without onDegrade). */
|
|
53
53
|
private warnedMonitorConfigError;
|
|
54
54
|
private onDegrade?;
|
|
55
|
+
/** Where Block-mode calls are decided (`local` = from the bundle, in this process). */
|
|
56
|
+
private readonly decisionMode;
|
|
57
|
+
/** Local decisions: until this time (ms epoch) a Block-mode call may wait for the first bundle; never after. */
|
|
58
|
+
private readonly coldStartDeadline;
|
|
59
|
+
/** Records of locally decided calls (and Monitor records in local mode), sent in background batches. */
|
|
60
|
+
private readonly records;
|
|
61
|
+
/** One warning when a Block-mode call ran before any policy bundle was available. */
|
|
62
|
+
private warnedNoBundle;
|
|
63
|
+
/** guardToolCall's calls: the local decision's record is handed back here and written after the tool ran. */
|
|
64
|
+
private readonly deferredLocalRecords;
|
|
55
65
|
private breaker;
|
|
56
66
|
private readonly _identity;
|
|
57
67
|
private readonly _features;
|
|
58
68
|
chat: ChatNamespace;
|
|
59
69
|
constructor(config?: FullCourtDefenseConfig);
|
|
70
|
+
/**
|
|
71
|
+
* Local decisions: refresh the bundle every BUNDLE_REFRESH_MS in the background (stale-while-revalidate), one
|
|
72
|
+
* timer per shield, never keeping the process alive. A call never waits for it; a failed refresh keeps the
|
|
73
|
+
* last bundle (the policies a live answer gave) and the next tick tries again.
|
|
74
|
+
*/
|
|
75
|
+
private _startBundleRefresh;
|
|
76
|
+
/**
|
|
77
|
+
* Wait (at most `timeoutMs`, default 3 s) for the shield's mode and policies, at START-UP, outside any tool call.
|
|
78
|
+
* Local decisions never wait inside a call: a call made before the first bundle arrives runs and is reported. An
|
|
79
|
+
* agent that must have its first call checked awaits this once after building the client (a Lambda handler during
|
|
80
|
+
* its init). Resolves true when the policies are here, false when FullCourtDefense did not answer in time. Never throws.
|
|
81
|
+
*/
|
|
82
|
+
ready(timeoutMs?: number): Promise<boolean>;
|
|
83
|
+
/** The bundle for a local decision, or undefined (none yet, or the backend serves no policies to decide from). */
|
|
84
|
+
private _localBundle;
|
|
85
|
+
/**
|
|
86
|
+
* One batch of queued records (RecordQueue's sender): `POST /runtime/tool-calls` with the records and, when the queue dropped
|
|
87
|
+
* some, the gap. An older backend (404 / 405 with no runtime error code) has no such route: the records go one by one to
|
|
88
|
+
* `/runtime/tool-call` from then on, for the rest of the process. A record or two the backend could not write come back as
|
|
89
|
+
* `outage` (resent); a record it refused is dropped.
|
|
90
|
+
*/
|
|
91
|
+
private _sendRecordBatch;
|
|
92
|
+
/** The older route: one record per request, a few at a time; after the first outage the rest of the batch waits (resent later). */
|
|
93
|
+
private _sendRecordsOneByOne;
|
|
94
|
+
/** Queue a record for the background batches; kept across the end of the process (exit flush, local spool). */
|
|
95
|
+
private _enqueueRecord;
|
|
60
96
|
/** Send the records an earlier process left in the local spool (once per shield per process, off the first tick). */
|
|
61
97
|
private _replaySpooledRecords;
|
|
62
98
|
/** @internal Calls held in memory, as request bodies for the local spool (called at exit). */
|
|
63
99
|
_takeUnsentForSpool(): SpooledRecord[];
|
|
64
|
-
/** @internal Send the calls spooled while the API was down (called at `beforeExit`; the caller bounds the wait). */
|
|
100
|
+
/** @internal Send the calls spooled while the API was down and the queued records (called at `beforeExit`; the caller bounds the wait). */
|
|
65
101
|
_flushForExit(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* How the background record upload is doing (observability for the app and the load tests): records waiting, sent,
|
|
104
|
+
* refused, dropped because the upload could not keep up (`dropped`; `unreported` is the part no accepted upload has told
|
|
105
|
+
* FullCourtDefense about yet), gaps the backend took, requests made, and whether records go in batches or one by one (an older backend).
|
|
106
|
+
*/
|
|
107
|
+
recordStats(): {
|
|
108
|
+
queued: number;
|
|
109
|
+
sent: number;
|
|
110
|
+
refused: number;
|
|
111
|
+
dropped: number;
|
|
112
|
+
unreported: number;
|
|
113
|
+
gapsReported: number;
|
|
114
|
+
requests: number;
|
|
115
|
+
mode: 'batch' | 'single';
|
|
116
|
+
};
|
|
66
117
|
/** Identity recorded on every runtime action (agentId / agentInstanceId / environment). */
|
|
67
118
|
get identity(): Readonly<RuntimeIdentity>;
|
|
68
119
|
/** Effective feature flags. */
|
|
@@ -199,6 +250,21 @@ export declare class FullCourtDefense {
|
|
|
199
250
|
registerAgent(input: AgentRegistrationInput): Promise<AgentSecurityApiResult>;
|
|
200
251
|
recordToolCall(rawInput: AgentToolCallInput): Promise<AgentSecurityApiResult>;
|
|
201
252
|
checkToolCall(rawInput: AgentToolCallInput): Promise<AgentSecurityApiResult<AgentToolCallCheckResult>>;
|
|
253
|
+
/**
|
|
254
|
+
* A Block-mode call decided in this process from the bundle, or undefined when the server decides it (server
|
|
255
|
+
* decision mode, a manager approval, a call the bundle cannot decide, a backend that serves no policies, a
|
|
256
|
+
* refused key). With no bundle at all (FullCourtDefense never reached since this agent started), the call is
|
|
257
|
+
* answered by the fail mode at once: it runs (only a never-allowed rule stops one), it is recorded, and one
|
|
258
|
+
* warning says so. Never a request, never a wait.
|
|
259
|
+
*/
|
|
260
|
+
private _decideLocal;
|
|
261
|
+
/**
|
|
262
|
+
* The record of a locally decided call, for the existing record endpoint (`POST /runtime/tool-call`): what was
|
|
263
|
+
* decided and by which rule, the arguments as their summary (the server minimizes them as for every SDK record),
|
|
264
|
+
* the provider's tool-call id (one action = one record when a local AI gateway also saw it), and how the tool
|
|
265
|
+
* ended when it ran.
|
|
266
|
+
*/
|
|
267
|
+
private _localRecordBody;
|
|
202
268
|
/**
|
|
203
269
|
* The record of a call that runs in Monitor (it never waits for it):
|
|
204
270
|
* - the API refused the key or shield (O4): the call runs; its report goes to the API anyway, where
|
|
@@ -232,7 +298,20 @@ export declare class FullCourtDefense {
|
|
|
232
298
|
*/
|
|
233
299
|
private _degradeByFailMode;
|
|
234
300
|
checkContext(input: AgentContextSecurityInput): Promise<AgentSecurityApiResult<AgentContextSecurityResult>>;
|
|
301
|
+
/**
|
|
302
|
+
* The container's local gate (`gate-host`, started by the wrap): asked first when `FCD_LOCAL_GATE=on` (only the wrap writes
|
|
303
|
+
* it, once the gate listens). Created on first use; `NO_GATE` everywhere else, so no other path pays a connect.
|
|
304
|
+
*/
|
|
305
|
+
private localGateClient?;
|
|
306
|
+
private localGate;
|
|
307
|
+
/** What the gate said about a call it did not allow: the error the agent code receives (the gate wrote the record). */
|
|
308
|
+
private _localGateStop;
|
|
235
309
|
guardToolCall<T>(rawInput: AgentToolCallInput, action: () => Promise<T>, options?: GuardToolCallOptions): Promise<T>;
|
|
310
|
+
/**
|
|
311
|
+
* Run (or stop) a call decided locally, and write its ONE record afterwards in the background: a stopped call
|
|
312
|
+
* at once, an allowed call with how it ended (`executed`, or `failed` with the error's type name only).
|
|
313
|
+
*/
|
|
314
|
+
private _runLocallyDecided;
|
|
236
315
|
/**
|
|
237
316
|
* How an allowed call ended. When the check returned the gate record's `actionId` (backends with
|
|
238
317
|
* the G-11 outcome report), the outcome goes ON that record: no second record, and a failure
|