agent-customs 1.0.0 → 1.0.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
@@ -22,7 +22,7 @@
22
22
 
23
23
  <a href="https://github.com/montbaga/agent-customs/actions/workflows/pages.yml"><img alt="Tests and publish" src="https://github.com/montbaga/agent-customs/actions/workflows/pages.yml/badge.svg"></a>
24
24
  <a href="#how-well-it-works"><img alt="Bench: 87.8% blocked, 0% false blocks" src="https://img.shields.io/badge/bench-87.8%25_blocked_%C2%B7_0%25_FP-c8f03c?labelColor=0c1d18"></a>
25
- <a href="#try-it-yourself"><img alt="Tests: 198 passing" src="https://img.shields.io/badge/tests-198_passing-ece4d3?labelColor=0c1d18"></a>
25
+ <a href="#try-it-yourself"><img alt="Tests: 199 passing" src="https://img.shields.io/badge/tests-199_passing-ece4d3?labelColor=0c1d18"></a>
26
26
  <a href="LICENSE.md"><img alt="License: Apache 2.0" src="https://img.shields.io/badge/license-Apache%202.0-c8f03c?labelColor=0c1d18"></a>
27
27
  <img alt="Dependencies: none" src="https://img.shields.io/badge/dependencies-none-ece4d3?labelColor=0c1d18">
28
28
  <a href="#lets-talk"><img alt="Built by Monty Bagati" src="https://img.shields.io/badge/say_hello-Monty_Bagati-c8f03c?labelColor=132d25"></a>
@@ -116,19 +116,19 @@ A first-time visitor has no key, so the switch says so. Turning it on opens a sh
116
116
 
117
117
  Any site built with Cognizant's `agentify-website` kit can add it. There is no server and no build step, and the runtime stays unchanged. Pick one of four ways.
118
118
 
119
- **1. One line (easiest).** Paste this into your page, next to your other `<script>` tags. The guard switches itself on when your assistant starts.
119
+ **1. One line (easiest).** Paste this into your page, above your other `<script>` tags. The guard switches itself on when your assistant starts.
120
120
 
121
121
  ```html
122
- <script type="module" src="https://cdn.jsdelivr.net/gh/montbaga/agent-customs@v1.0.0/site/customs/auto.js"></script>
122
+ <script type="module" src="https://cdn.jsdelivr.net/gh/montbaga/agent-customs@v1.0.1/site/customs/auto.js"></script>
123
123
  ```
124
124
 
125
- `@v1.0.0` is a fixed version, so it never changes under you; change the number to update. If your page has a `Content-Security-Policy` with `script-src`, add `https://cdn.jsdelivr.net` to it.
125
+ `@v1.0.1` is a fixed version, so it never changes under you; change the number to update. Above the other tags, the browser runs it before your page starts the assistant. Until the guard's files have loaded, chats wait a moment, and if they cannot load, chats fail instead of running unchecked. If your page has a `Content-Security-Policy` with `script-src`, add `https://cdn.jsdelivr.net` to it.
126
126
 
127
127
  **2. Two lines, with your own settings.** Load the guard from the same address and pass any of the *Guard options* below:
128
128
 
129
129
  ```js
130
130
  // At the top of site.js
131
- import { installCustomsGuard } from "https://cdn.jsdelivr.net/gh/montbaga/agent-customs@v1.0.0/site/customs/guard.js";
131
+ import { installCustomsGuard } from "https://cdn.jsdelivr.net/gh/montbaga/agent-customs@v1.0.1/site/customs/guard.js";
132
132
 
133
133
  // Right after the boot(...) call
134
134
  installCustomsGuard(booted.engine, { strict: true });
@@ -185,7 +185,7 @@ Three ways in, fastest first:
185
185
  <strong>1 · The test suite</strong><br><br>
186
186
  No browser and no API key:<br><br>
187
187
  <code>npm test</code><br><br>
188
- 198 tests: the attack sentences, every frozen attack set, five batches of real MCP servers and A2A cards, the locks, the canary, the signed stamps, the benchmark, the command line tool, the extension, the practice site, the key vault and the one-line install.
188
+ 199 tests: the attack sentences, every frozen attack set, five batches of real MCP servers and A2A cards, the locks, the canary, the signed stamps, the benchmark, the command line tool, the extension, the practice site, the key vault and the one-line install.
189
189
  </td>
190
190
  <td width="33.3%" valign="top">
191
191
  <strong>2 · The inspection desk (no key)</strong><br><br>
@@ -430,7 +430,7 @@ Needs Node 22 or newer and no npm packages.
430
430
  ```sh
431
431
  git clone https://github.com/montbaga/agent-customs.git
432
432
  cd agent-customs
433
- npm test # 198 tests
433
+ npm test # 199 tests
434
434
  npm run bench -- --verbose # the benchmark, with every flagged case
435
435
  npm run check && npm run check:practice # both networks pass Cognizant's build check
436
436
  node bin/agent-customs.mjs check site/samples/mcp-poisoned --sarif
@@ -537,7 +537,7 @@ The full picture, with diagrams, is in [**How it works**](ARCHITECTURE.md).
537
537
  | [`PAPER.md`](PAPER.md) | The research note: threat model, method, results and limits |
538
538
  | [`LICENSE.md`](LICENSE.md) | The license in plain words, with the full text |
539
539
  | [`tools/`](tools/) | The benchmark and its frozen sets, the stamp signer, the local server, the builders and the smoke test |
540
- | [`tests/`](tests/) | 198 tests, the frozen attack sets and the five batches of real-world snapshots |
540
+ | [`tests/`](tests/) | 199 tests, the frozen attack sets and the five batches of real-world snapshots |
541
541
  | [`vendor/agentify-website/`](vendor/agentify-website/) | Cognizant's kit scripts and templates, unmodified |
542
542
 
543
543
  </details>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-customs",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Border control for the Open Agentic Web: inspect any agent network before it runs in your browser.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Monty Bagati (https://github.com/montbaga)",
@@ -1,28 +1,67 @@
1
1
  // auto.js: Agent Customs in one line. Add this to a page made with Cognizant's
2
- // agentify-website kit, and the guard starts with its default settings:
2
+ // agentify-website kit, above the page's own script tags, and the guard starts with its
3
+ // default settings:
3
4
  //
4
- // <script type="module" src="https://cdn.jsdelivr.net/gh/montbaga/agent-customs@v1.0.0/site/customs/auto.js"></script>
5
+ // <script type="module" src="https://cdn.jsdelivr.net/gh/montbaga/agent-customs@v1.0.1/site/customs/auto.js"></script>
5
6
  //
6
- // The kit's runtime publishes its engine as window.__nsweb once boot() is done. This file waits
7
- // for that moment and installs the guard. For other settings, import guard.js instead.
8
- import { installCustomsGuard } from "./guard.js";
7
+ // Above the other tags, the browser runs it before the page's own code starts the assistant.
8
+ // The kit's runtime publishes its engine as window.__nsweb once boot() is done. This file
9
+ // imports nothing up front, so it runs as soon as it arrives, and the guard's own files load
10
+ // in the background. Until they have loaded and the guard is on, every chat turn and every
11
+ // partner waits. If the guard cannot load, they fail instead of running unchecked.
12
+ // For other settings, import guard.js instead.
9
13
 
10
14
  /**
11
- * Install the guard on the runtime's engine as soon as the runtime publishes it.
15
+ * Hold the runtime's engine until the guard is installed on it.
12
16
  *
13
17
  * :param target: The page's window.
14
- * :param install: The installer (installCustomsGuard; tests pass their own).
18
+ * :param load: Loads guard.js (tests pass their own).
15
19
  */
16
- export function guardWhenReady(target = globalThis, install = installCustomsGuard) {
20
+ export function guardWhenReady(target = globalThis, load = () => import("./guard.js")) {
21
+ let loading = null;
22
+ const guardModule = () => (loading ||= Promise.resolve().then(load));
23
+ // Start loading at once; a failure is reported when an engine waits on it.
24
+ guardModule().catch(() => {});
25
+
17
26
  const attach = (value) => {
18
- if (!value?.engine) return;
19
- try {
20
- install(value.engine);
21
- } catch (error) {
22
- // Never break the page's own start-up.
23
- console.error("Agent Customs could not start:", error);
24
- }
27
+ const engine = value?.engine;
28
+ if (!engine || engine.__agentCustoms || engine.__agentCustomsAuto) return;
29
+ engine.__agentCustomsAuto = true;
30
+ const turn = engine.runTurn;
31
+ const compile = engine._compile;
32
+ let held;
33
+ // A guard installed by hand meanwhile wraps the held step, so its calls already passed it.
34
+ let byHand = false;
35
+ const ready = guardModule().then(({ installCustomsGuard }) => {
36
+ byHand = Boolean(engine.__agentCustoms);
37
+ if (engine.runTurn === held.turn) engine.runTurn = turn;
38
+ if (!byHand) {
39
+ engine._compile = compile;
40
+ installCustomsGuard(engine);
41
+ }
42
+ });
43
+ ready.catch((error) => console.error("Agent Customs could not start, so the assistant is paused:", error));
44
+ const wait = async () => {
45
+ try {
46
+ await ready;
47
+ } catch {
48
+ throw new Error("Agent Customs could not load, so this was not run. Reload the page to try again.");
49
+ }
50
+ };
51
+ const heldTurn = async function (...args) {
52
+ await wait();
53
+ return turn.apply(this, args);
54
+ };
55
+ // A partner held here goes through the guard once it is on, never around it.
56
+ const heldCompile = async function (...args) {
57
+ await wait();
58
+ return (byHand ? compile : engine._compile).apply(this, args);
59
+ };
60
+ held = { turn: typeof turn === "function" ? heldTurn : turn, compile: heldCompile };
61
+ engine.runTurn = held.turn;
62
+ engine._compile = held.compile;
25
63
  };
64
+
26
65
  const existing = Object.getOwnPropertyDescriptor(target, "__nsweb");
27
66
  if (existing && "value" in existing) {
28
67
  attach(existing.value);