fullcourtdefense 2.2.0 → 2.3.1

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 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() -> POST /runtime/check-tool-call -> allow: run tool, record
65
- (deterministic policy) -> block: throw, tool never runs
66
- -> approval: throw (or wait, see below)
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, a refused request (HTTP 401 / 403 / 404 / 400, and any other 4xx except 408 / 429) is not an outage:** on a Block shield the tool does not run and `FullCourtDefenseApiError` says what to fix. On a Monitor shield (the mode a live answer gave earlier, else `FCD_MODE_AT_PROTECT`) the tool runs and the call is still reported, so FullCourtDefense raises a "wrong or missing shield key" alert. With no known mode the shield is treated as Block. Only a real outage is answered by `FCD_FAIL_MODE` (below).
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 |
@@ -760,7 +770,7 @@ when the client is built and refreshes them every 60 s in the background; a tool
760
770
  - The built-in safety rules (command, file and web tools) are decided locally too, with the rules FullCourtDefense
761
771
  serves in the same bundle. Only a call that needs a **manager's approval** goes to FullCourtDefense while it runs, plus
762
772
  the rare call the bundle cannot decide: a policy that reads the agent's recorded history, a suspended shield.
763
- - Cold start: a Block-mode call made in the first 1.5 s after the client was built waits for the first policies
773
+ - Cold start: a Block-mode call made in the first 1 s after the client was built waits for the first policies
764
774
  (`coldStartWaitMs`, env `FCD_COLD_START_WAIT_MS`; `0` = never wait), so a short-lived agent's first call is checked.
765
775
  After that, or if FullCourtDefense cannot be reached, a call with no policies runs, is recorded, and one warning says
766
776
  so: the agent is never stalled. `await fcd.ready()` waits for the policies once at start-up instead.
@@ -796,7 +806,8 @@ Every call that ran during the outage is reported with `ranDuringOutage: true` (
796
806
  `failsafeRuleId` / `failsafeRuleName` when a rule applied). When the API is up and answers "pending" (a manager has to
797
807
  decide), the call does not run and returns at once: a manager who does not answer is not our failure.
798
808
 
799
- Records survive a short-lived process: sends are tracked, the end of the process waits at most 1.5 s for them, and what is
809
+ Records survive a short-lived process: when it ends the SDK **sends** what is unsent (at most 4 s), reports straight to
810
+ FullCourtDefense how many it could not deliver (shown in the console even if the disk is gone), and what is
800
811
  still unsent (or failed) is kept in a small file in the user cache directory (`~/.cache/fullcourtdefense/sdk-spool`, or
801
812
  `%LOCALAPPDATA%` / `~/Library/Caches`) that the next start with the same shield sends. `FCD_SDK_SPOOL=off` disables it,
802
813
  `FCD_SDK_SPOOL_DIR` moves it.
package/dist/client.d.ts CHANGED
@@ -82,16 +82,44 @@ export declare class FullCourtDefense {
82
82
  ready(timeoutMs?: number): Promise<boolean>;
83
83
  /** The bundle for a local decision, or undefined (none yet, or the backend serves no policies to decide from). */
84
84
  private _localBundle;
85
- /** One queued record to the record endpoint (RecordQueue's sender). */
86
- private _sendQueuedRecord;
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;
87
94
  /** Queue a record for the background batches; kept across the end of the process (exit flush, local spool). */
88
95
  private _enqueueRecord;
89
96
  /** Send the records an earlier process left in the local spool (once per shield per process, off the first tick). */
90
97
  private _replaySpooledRecords;
98
+ /** Once the replayed records left the queue, clear the pending gaps an earlier process reported for them. */
99
+ private _resolveReplayedGaps;
91
100
  /** @internal Calls held in memory, as request bodies for the local spool (called at exit). */
92
101
  _takeUnsentForSpool(): SpooledRecord[];
93
102
  /** @internal Send the calls spooled while the API was down and the queued records (called at `beforeExit`; the caller bounds the wait). */
94
103
  _flushForExit(): Promise<void>;
104
+ /** @internal This client's shield (the end of the process groups leftovers by shield). */
105
+ _shieldIdForExit(): string;
106
+ /** @internal The one direct gap report at the end of the process; true when the server took it. */
107
+ _postExitReport(body: Record<string, unknown>, timeoutMs: number): Promise<boolean>;
108
+ /**
109
+ * How the background record upload is doing (observability for the app and the load tests): records waiting, sent,
110
+ * refused, dropped because the upload could not keep up (`dropped`; `unreported` is the part no accepted upload has told
111
+ * FullCourtDefense about yet), gaps the backend took, requests made, and whether records go in batches or one by one (an older backend).
112
+ */
113
+ recordStats(): {
114
+ queued: number;
115
+ sent: number;
116
+ refused: number;
117
+ dropped: number;
118
+ unreported: number;
119
+ gapsReported: number;
120
+ requests: number;
121
+ mode: 'batch' | 'single';
122
+ };
95
123
  /** Identity recorded on every runtime action (agentId / agentInstanceId / environment). */
96
124
  get identity(): Readonly<RuntimeIdentity>;
97
125
  /** Effective feature flags. */
@@ -276,6 +304,14 @@ export declare class FullCourtDefense {
276
304
  */
277
305
  private _degradeByFailMode;
278
306
  checkContext(input: AgentContextSecurityInput): Promise<AgentSecurityApiResult<AgentContextSecurityResult>>;
307
+ /**
308
+ * The container's local gate (`gate-host`, started by the wrap): asked first when `FCD_LOCAL_GATE=on` (only the wrap writes
309
+ * it, once the gate listens). Created on first use; `NO_GATE` everywhere else, so no other path pays a connect.
310
+ */
311
+ private localGateClient?;
312
+ private localGate;
313
+ /** What the gate said about a call it did not allow: the error the agent code receives (the gate wrote the record). */
314
+ private _localGateStop;
279
315
  guardToolCall<T>(rawInput: AgentToolCallInput, action: () => Promise<T>, options?: GuardToolCallOptions): Promise<T>;
280
316
  /**
281
317
  * Run (or stop) a call decided locally, and write its ONE record afterwards in the background: a stopped call