agent-customs 1.0.0 → 1.1.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 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: 203 passing" src="https://img.shields.io/badge/tests-203_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>
@@ -104,7 +104,9 @@ This round fixed a weakness in how the rules handled their own exceptions, and i
104
104
 
105
105
  The desk also has a new switch under the address box: **AI double-check**. When it is on, your own AI reads every network the rules clear, and every partner the Officer is about to call. It can only make a verdict stricter. If your AI flags something, *Cleared* becomes *Held for review*; if it finds nothing, the verdict stays as it was. Networks the rules already stopped are never sent to it, so they cost no tokens. The switch is off until you turn it on and uses the key you set on the Officer tab. While it is on, the network's public text goes to your AI provider. When your AI has read a network, a round seal countersigns the verdict stamp, and a flag quotes the sentence that worried it (only words the network really wrote are shown).
106
106
 
107
- **Adding the guard now takes one line.** Paste one `<script>` tag into your page and the guard switches itself on, or install it with `npm install agent-customs`. See [Add the guard to your site](#add-the-guard-to-your-site).
107
+ **Adding the guard now takes one line.** Paste one `<script>` tag into your page and the guard switches itself on, or install it with `npm install agent-customs`. See [Add the guard to your site](#add-the-guard-to-your-site). The line carries a fingerprint (Subresource Integrity), so a browser refuses the file if it was ever changed; the whole guard is one file, so the fingerprint covers all of it.
108
+
109
+ **Checked against Google's guidance.** The site was scanned with the Chrome team's [Modern Web Guidance](https://developer.chrome.com/docs/modern-web-guidance) and checked against [Baseline](https://web.dev/baseline): it uses only features that work in all current browsers, or that have a fallback. Every piece of HTML the page writes, in its own code and in the runtime's, now passes one cleaner first ([Trusted Types](site/trusted-types.js)), which removes anything that could run code.
108
110
 
109
111
  **Your AI key now lives in a key vault.** The page no longer keeps your key anywhere. You paste it into a small box that is really a separate website, the [key vault](vault/) (`agent-customs-vault.github.io`). The browser keeps that site's storage apart from this page's. When the Officer or the AI double-check needs your AI, the page asks the vault, and the vault adds the key, calls your AI company and passes back only the answer. So even an agent file that broke this page could not take your key. By default the vault forgets the key when you close the tab. *Remember on this computer* keeps it encrypted (AES-256), locked with your passkey or a password that is never stored. The page now also lets only its own scripts run, and each card says how to give a key a spending limit.
110
112
 
@@ -116,19 +118,19 @@ A first-time visitor has no key, so the switch says so. Turning it on opens a sh
116
118
 
117
119
  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
120
 
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.
121
+ **1. One line (easiest).** Paste this into your page, above your other `<script>` tags. The guard switches itself on when your assistant starts.
120
122
 
121
123
  ```html
122
- <script type="module" src="https://cdn.jsdelivr.net/gh/montbaga/agent-customs@v1.0.0/site/customs/auto.js"></script>
124
+ <script type="module" src="https://cdn.jsdelivr.net/gh/montbaga/agent-customs@v1.1.0/dist/agent-customs.js" integrity="sha384-OGtRjuJ2hhEs8ntZHxM92x/7I93DVa4/22kF/6BrqrhhVNBBIcg/gULlR0TQtV7U" crossorigin="anonymous"></script>
123
125
  ```
124
126
 
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.
127
+ `integrity` is the file's fingerprint. If the file were ever changed, on the CDN or on the way, the browser would refuse to run it. The whole guard is in this one file ([`dist/agent-customs.js`](dist/agent-customs.js), built by `npm run bundle`), so the fingerprint covers all of it. `@v1.1.0` is a fixed version; to update, take the new line from the next release. Above the other tags, the browser runs it before your page starts the assistant, and chats wait until the guard is on. If your page has a `Content-Security-Policy` with `script-src`, add `https://cdn.jsdelivr.net` to it.
126
128
 
127
- **2. Two lines, with your own settings.** Load the guard from the same address and pass any of the *Guard options* below:
129
+ **2. Two lines, with your own settings.** Load the guard from the same release and pass any of the *Guard options* below. A browser cannot check a fingerprint on an `import`, so for that use option 3 or 4.
128
130
 
129
131
  ```js
130
132
  // 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";
133
+ import { installCustomsGuard } from "https://cdn.jsdelivr.net/gh/montbaga/agent-customs@v1.1.0/site/customs/guard.js";
132
134
 
133
135
  // Right after the boot(...) call
134
136
  installCustomsGuard(booted.engine, { strict: true });
@@ -185,7 +187,7 @@ Three ways in, fastest first:
185
187
  <strong>1 · The test suite</strong><br><br>
186
188
  No browser and no API key:<br><br>
187
189
  <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.
190
+ 203 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, the one-line install and its one-file build.
189
191
  </td>
190
192
  <td width="33.3%" valign="top">
191
193
  <strong>2 · The inspection desk (no key)</strong><br><br>
@@ -430,7 +432,7 @@ Needs Node 22 or newer and no npm packages.
430
432
  ```sh
431
433
  git clone https://github.com/montbaga/agent-customs.git
432
434
  cd agent-customs
433
- npm test # 198 tests
435
+ npm test # 203 tests
434
436
  npm run bench -- --verbose # the benchmark, with every flagged case
435
437
  npm run check && npm run check:practice # both networks pass Cognizant's build check
436
438
  node bin/agent-customs.mjs check site/samples/mcp-poisoned --sarif
@@ -537,7 +539,7 @@ The full picture, with diagrams, is in [**How it works**](ARCHITECTURE.md).
537
539
  | [`PAPER.md`](PAPER.md) | The research note: threat model, method, results and limits |
538
540
  | [`LICENSE.md`](LICENSE.md) | The license in plain words, with the full text |
539
541
  | [`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 |
542
+ | [`tests/`](tests/) | 203 tests, the frozen attack sets and the five batches of real-world snapshots |
541
543
  | [`vendor/agentify-website/`](vendor/agentify-website/) | Cognizant's kit scripts and templates, unmodified |
542
544
 
543
545
  </details>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-customs",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
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)",
@@ -62,6 +62,7 @@
62
62
  "range": "node tools/make-range.mjs",
63
63
  "practice": "node tools/make-practice.mjs",
64
64
  "extension": "node tools/make-extension.mjs",
65
+ "bundle": "node tools/make-bundle.mjs",
65
66
  "vault": "node tools/make-vault.mjs",
66
67
  "check:practice": "node vendor/agentify-website/scripts/build_network.mjs practice/main_street_guide.hocon --manifest practice/agent-manifest.json --check",
67
68
  "test": "node --test \"tests/*.test.mjs\"",
@@ -1,28 +1,66 @@
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:
1
+ // auto.js: Agent Customs in one line. Added to a page made with Cognizant's
2
+ // agentify-website kit, above the page's own script tags, it starts the guard with its default
3
+ // settings. The published one-line file is dist/agent-customs.js: this file and the guard,
4
+ // joined by tools/make-bundle.mjs so one integrity hash covers them (see the README).
3
5
  //
4
- // <script type="module" src="https://cdn.jsdelivr.net/gh/montbaga/agent-customs@v1.0.0/site/customs/auto.js"></script>
5
- //
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";
6
+ // Above the other tags, the browser runs it before the page's own code starts the assistant.
7
+ // The kit's runtime publishes its engine as window.__nsweb once boot() is done. This file
8
+ // imports nothing up front, so it runs as soon as it arrives, and the guard's own files load
9
+ // in the background. Until they have loaded and the guard is on, every chat turn and every
10
+ // partner waits. If the guard cannot load, they fail instead of running unchecked.
11
+ // For other settings, import guard.js instead.
9
12
 
10
13
  /**
11
- * Install the guard on the runtime's engine as soon as the runtime publishes it.
14
+ * Hold the runtime's engine until the guard is installed on it.
12
15
  *
13
16
  * :param target: The page's window.
14
- * :param install: The installer (installCustomsGuard; tests pass their own).
17
+ * :param load: Loads guard.js (tests pass their own).
15
18
  */
16
- export function guardWhenReady(target = globalThis, install = installCustomsGuard) {
19
+ export function guardWhenReady(target = globalThis, load = () => import("./guard.js")) {
20
+ let loading = null;
21
+ const guardModule = () => (loading ||= Promise.resolve().then(load));
22
+ // Start loading at once; a failure is reported when an engine waits on it.
23
+ guardModule().catch(() => {});
24
+
17
25
  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
- }
26
+ const engine = value?.engine;
27
+ if (!engine || engine.__agentCustoms || engine.__agentCustomsAuto) return;
28
+ engine.__agentCustomsAuto = true;
29
+ const turn = engine.runTurn;
30
+ const compile = engine._compile;
31
+ let held;
32
+ // A guard installed by hand meanwhile wraps the held step, so its calls already passed it.
33
+ let byHand = false;
34
+ const ready = guardModule().then(({ installCustomsGuard }) => {
35
+ byHand = Boolean(engine.__agentCustoms);
36
+ if (engine.runTurn === held.turn) engine.runTurn = turn;
37
+ if (!byHand) {
38
+ engine._compile = compile;
39
+ installCustomsGuard(engine);
40
+ }
41
+ });
42
+ ready.catch((error) => console.error("Agent Customs could not start, so the assistant is paused:", error));
43
+ const wait = async () => {
44
+ try {
45
+ await ready;
46
+ } catch {
47
+ throw new Error("Agent Customs could not load, so this was not run. Reload the page to try again.");
48
+ }
49
+ };
50
+ const heldTurn = async function (...args) {
51
+ await wait();
52
+ return turn.apply(this, args);
53
+ };
54
+ // A partner held here goes through the guard once it is on, never around it.
55
+ const heldCompile = async function (...args) {
56
+ await wait();
57
+ return (byHand ? compile : engine._compile).apply(this, args);
58
+ };
59
+ held = { turn: typeof turn === "function" ? heldTurn : turn, compile: heldCompile };
60
+ engine.runTurn = held.turn;
61
+ engine._compile = held.compile;
25
62
  };
63
+
26
64
  const existing = Object.getOwnPropertyDescriptor(target, "__nsweb");
27
65
  if (existing && "value" in existing) {
28
66
  attach(existing.value);
@@ -97,7 +97,7 @@ export function canaryEncodings(token) {
97
97
  const b64 = toBase64(raw);
98
98
  return {
99
99
  raw,
100
- reversed: [...raw].reverse().join(""),
100
+ reversed: [...raw].toReversed().join(""),
101
101
  base64: b64,
102
102
  base64url: b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""),
103
103
  hex: toHex(raw),
@@ -66,7 +66,7 @@ export function snapshotOf(config, manifest, fingerprint) {
66
66
  links: config?.links || {},
67
67
  manifest: {
68
68
  brand: manifest?.brand || "",
69
- allowedPeers: [...(manifest?.allowed_peers || [])].sort(),
69
+ allowedPeers: (manifest?.allowed_peers || []).toSorted(),
70
70
  peerPolicy: peerPolicyOf(manifest),
71
71
  codedTools: manifest?.coded_tools ? JSON.stringify(manifest.coded_tools) : "",
72
72
  },