agent-customs 0.0.0-stage → 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/LICENSE.md +341 -0
- package/README.md +592 -2
- package/bin/agent-customs.mjs +194 -0
- package/package.json +77 -4
- package/site/.well-known/agent-customs-key.json +13 -0
- package/site/certificate.js +944 -0
- package/site/customs/analyze.js +1224 -0
- package/site/customs/auto.js +83 -0
- package/site/customs/canary.js +270 -0
- package/site/customs/canonical.js +123 -0
- package/site/customs/capabilities.js +387 -0
- package/site/customs/diff.js +236 -0
- package/site/customs/english-words.js +153 -0
- package/site/customs/guard-notice.js +226 -0
- package/site/customs/guard-ui.js +105 -0
- package/site/customs/guard.js +259 -0
- package/site/customs/inspect.js +446 -0
- package/site/customs/judge.js +208 -0
- package/site/customs/languages.js +826 -0
- package/site/customs/locks.js +967 -0
- package/site/customs/pins.js +119 -0
- package/site/customs/protocols.js +621 -0
- package/site/customs/receipts.js +154 -0
- package/site/customs/rules.js +1470 -0
- package/site/customs/unicode.js +361 -0
- package/site/runtime/LICENSE.txt +176 -0
- package/site/runtime/generated/graph.gen.mjs +83 -0
- package/site/runtime/generated/validation.gen.mjs +70 -0
- package/site/runtime/hocon.js +262 -0
- package/site/runtime/kernel.js +237 -0
- package/site/runtime/model.js +44 -0
- package/tests/fixtures/official/NOTICE +3 -0
- package/tests/fixtures/official/guesthouse_agentified/agent-manifest.json +86 -0
- package/tests/fixtures/official/guesthouse_agentified/links.json +6 -0
- package/tests/fixtures/official/guesthouse_agentified/tidewhistle_guesthouse.network.json +56 -0
- package/tests/fixtures/official/harbor_tours_agentified/agent-manifest.json +86 -0
- package/tests/fixtures/official/harbor_tours_agentified/links.json +6 -0
- package/tests/fixtures/official/harbor_tours_agentified/marrow_point_harbor_tours.network.json +56 -0
- package/tests/fixtures/official/pizza_restaurant_agentified/agent-manifest.json +78 -0
- package/tests/fixtures/official/pizza_restaurant_agentified/links.json +6 -0
- package/tests/fixtures/official/pizza_restaurant_agentified/pizza_restaurant_website_assistant.network.json +156 -0
- package/tools/bench.mjs +731 -0
- package/tools/external-heldout.mjs +337 -0
- package/tools/fs-fetch.mjs +19 -0
- package/tools/heldout-corpus.mjs +135 -0
- package/tools/inspect-local.mjs +88 -0
- package/tools/round2-corpus.mjs +395 -0
- package/tools/round3-corpus.mjs +192 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
// capabilities.js: name- and schema-based "Lethal Trifecta" capability & data-flow analyzer.
|
|
2
|
+
//
|
|
3
|
+
// Text rules inspect what an agent *says*. Capability analysis inspects what declared tools,
|
|
4
|
+
// parameter schemas, and external endpoints allow an agent to *do*: combining Untrusted Input
|
|
5
|
+
// + Sensitive Access + External Egress creates an exfiltration path even in polite prose.
|
|
6
|
+
// MCP self-declared annotations can raise risk when present, but never suppress name,
|
|
7
|
+
// schema, REST toolbox, or off-origin URL signals.
|
|
8
|
+
|
|
9
|
+
function splitWords(value) {
|
|
10
|
+
return String(value || "")
|
|
11
|
+
.replace(/([a-z\d])([A-Z])/g, "$1 $2")
|
|
12
|
+
.replace(/[_\-./:]+/g, " ")
|
|
13
|
+
.replace(/\s+/g, " ")
|
|
14
|
+
.trim()
|
|
15
|
+
.toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const UNTRUSTED_TOOL = /\b(?:fetch|scrape|browse|crawl|search web|web search|read emails?|read mails?|get emails?|read pages?|read web ?pages?|get web ?pages?|read urls?|fetch url|web fetch|webhook listen|receive webhook)\b/i;
|
|
19
|
+
const SENSITIVE_TOOL = /\b(?:read files?|list files?|(?:user|private|personal)\s+(?:files?|documents?|docs|notes|photos)|read env|get env|get config|read config|dump config|env(?:ironment)? settings?|env(?:ironment)? variables?|secrets?|credentials?|(?<!\b(?:phone|sms)\s)wallet|bank accounts?|payment methods?|credit cards?|order history|inbox|(?:read|get|search|list)\s+(?:an?\s+)?emails?|(?:read|get|list|fetch|search|dump)\s+(?:private\s+|direct\s+|user\s+)?messages?|db query|sql query|private data)\b/i;
|
|
20
|
+
// Reading a wallet's balance or status is not reading its keys. A wallet tool is sensitive
|
|
21
|
+
// when its name or description says it can move money or show keys.
|
|
22
|
+
const WALLET_CONTROL = /\b(?:transfer|transfers|send|sends|withdraw|withdrawal|export|keys?|seed|private|mnemonic|secret|sign|signs|pay|pays|payout|import|recover|drain)\b/i;
|
|
23
|
+
const NON_VISITOR_TOOL_SECRET = /\b(?:(?:rotate|roll|revoke|renew|verify|create|generate|regenerate|reset|set|update|delete)\s+(?:the\s+|your\s+|a\s+|an\s+)?(?:webhook|signing|forward|client|app|room)?\s*secrets?|(?:webhook|signing|forward)\s+secrets?)\b/i;
|
|
24
|
+
const CREDENTIAL_LIFECYCLE_ONLY = /\b(?:rotate|roll|revoke|renew|regenerate|reset)\b/i;
|
|
25
|
+
// A lifecycle tool that hands the current values back is a reader of secrets after all.
|
|
26
|
+
const RETURNS_SECRET_VALUES = /\breturn(?:s|ing)?\b[^.!?\n]{0,40}\b(?:values?|secrets?|keys?|tokens?|credentials?|passwords?)\b/i;
|
|
27
|
+
const NO_SECRET_VALUES_RETURNED = /\bvalues?\s+(?:are|is)\s+write[- ]?only\b[^.!?\n]{0,35}\bnever\s+(?:returned|exposed|readable)\b/i;
|
|
28
|
+
const STORED_SECRET_AUDIT_RISK = /\b(?:users?|visitors?|customers?|members?|employees?|vault|all\s+credentials|\.env|passwords?)\b/i;
|
|
29
|
+
const SENSITIVE_PARAM = /\b(?:tokens?|secrets?|passwords?|passwd|passcodes?|passphrases?|cookies?|session (?:cookie|secret|key|data|state)|auth(?:orization)?|auth header|credentials?|api key|private key|ssh key|ssn|iban)\b/i;
|
|
30
|
+
const UNIVERSAL_SECRET_PARAM = /\b(?:passwords?|passwd|passcodes?|passphrases?|cookies?|session (?:cookie|secret|key)|auth code|private key|ssh key|ssn|iban)\b/i;
|
|
31
|
+
const SECRET_COMPOUND_MODIFIER = /\b(?:access|auth(?:entication)?|bearer|refresh|oauth|id|api|secret|private|signing|user|visitor|account|client|personal|l402|third[- ]party)\s+(?:token|credential|secret)s?\b/i;
|
|
32
|
+
const SAFE_OPAQUE_HANDLE_NAME = /^(?:delete|status|cancel|retry|page|pagination|cursor|next|prev|previous|idempotency|upload|download|lease|claim|approval|confirm|confirmation|csrf|xsrf|webhook|signing)\s+(?:token|key|secret)$/i;
|
|
33
|
+
const NON_SECRET_TOKEN_METRIC = /\btokens?\s+(?:budget|limit|cap|count|max|min|size|price|amount|decimals|saved)\b/i;
|
|
34
|
+
const CRYPTO_OR_TEMPLATE_TOKEN_DESC = /\b(?:coingecko|erc-?20|spl|solana|base:0x|0x\s*address|contract address|token address|symbol|ticker|mint|liquidity|swap|swapping|dex aggregator|token swap|token substitutions?|design tokens?|template tokens?|brand colou?rs?|html references?|css tokens?)\b/i;
|
|
35
|
+
const BARE_TOKEN_NONSECRET_CONTEXT = /\b(?:concurrency|e-?tag|precondition|css\s+custom|brand\s+kits?)\b/i;
|
|
36
|
+
// Provenance that names this server itself.
|
|
37
|
+
const EXPLICIT_OWN_PROVENANCE_RE = /\b(?:returned|issued|generated|created|obtained|received|assigned|provided)\s+(?:by|from)\s+this\s+(?:server|service|mcp|api)\b/i;
|
|
38
|
+
// Provenance that only says "an earlier step": enough for this server's handles, not for
|
|
39
|
+
// real credential types (access, OAuth, bearer, API tokens), which another service may issue.
|
|
40
|
+
const GENERIC_PROVENANCE_RE = /\b(?:returned|issued|generated|created|obtained|received|assigned|provided)\s+(?:by|from)\s+a\s+(?:previous|prior)\s+(?:call|step)\b|\b(?:returned|received|obtained|copied)\s+(?:with|from|in)\s+(?:a|an|the)?\s*(?:previous|prior|earlier)?\s*(?:result|response|payload|call|retry\w*|creation)\b|\bfrom\s+(?:a|an|the)\s+(?:previous|prior|earlier|ready)\s+(?:result|response|payload|report)\b|\b(?:returned|issued|given|sent)\s+when\s+(?:the|this|a|your)\s+\w+\s+(?:was|is)\s+(?:created|opened|started|submitted|placed|registered)\b|\(\s*[a-z]{2,5}_[a-z0-9_….*-]{1,20}\s*[),]|\b(?:your|an?)\s+[a-z]{2,6}_\s+(?:api\s+)?(?:key|token)\b|\bauthorization\s*:\s*bearer\s+header\b|\boptional\s+(?:partner\s+)?api\s+key\b/i;
|
|
41
|
+
// Tools that link the visitor's account at another service. A token "from connect_dropbox"
|
|
42
|
+
// belongs to Dropbox and the visitor, not to this server.
|
|
43
|
+
const LINKING_TOOL = /\b(?:connect|link|oauth|login|log in|sign in|signin|authori[sz]e|auth)\b/i;
|
|
44
|
+
const PASSWORD_GATE_DESC = /\boptional\s+password\s+to\b|\b(?:set|add|remove|clear|protect|lock|gate)\s+(?:a|an|this|the|optional)?\s*password\b[^.]{0,30}\b(?:page|site|link|url|file|room|document|pdf)\b|\bpassword[- ]?(?:gate|protect(?:ed)?)\s+(?:a|an|this|the)?\s*(?:page|site|link|url|file|room|document|pdf)\b/i;
|
|
45
|
+
const PASSWORD_REUSE_RISK = /\b(?:same\s+password|reuse|online\s+bank|banking|e-?mail|account\s+password|existing\s+password)\b/i;
|
|
46
|
+
const USER_OWNED_PARAM_DESC = /\b(?:user's|users'|visitor's|visitors'|customer's|customers'|guest's|guests'|(?:the|your)\s+(?:user|visitor|customer|guest)\b|(?:user|visitor|customer|guest)\s+account|their|dashboard)\b/i;
|
|
47
|
+
const HANDLE_CREDENTIAL_RISK_DESC = /\b(?:password|passcode|login|bank|banking|wallet|exchange|e-?mail\s+account|third[- ]party)\b/i;
|
|
48
|
+
|
|
49
|
+
// True when the description names one of this server's own tools as the source, and that
|
|
50
|
+
// tool is not one that links an account at another service.
|
|
51
|
+
function mentionsOwnToolProvenance(desc, ownToolNames, linkingToolNames = new Set()) {
|
|
52
|
+
if (!desc || !ownToolNames.size) return false;
|
|
53
|
+
if (!/\b(?:from|by|via|call(?:ing)?|returned|issued|generated|created)\b/i.test(desc)) return false;
|
|
54
|
+
const lower = desc.toLowerCase();
|
|
55
|
+
const normalized = splitWords(desc);
|
|
56
|
+
let named = false;
|
|
57
|
+
for (const name of ownToolNames) {
|
|
58
|
+
if (name.length < 4 || !(lower.includes(name) || normalized.includes(splitWords(name)))) continue;
|
|
59
|
+
if (linkingToolNames.has(name)) return false;
|
|
60
|
+
named = true;
|
|
61
|
+
}
|
|
62
|
+
return named;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function provenanceIsOwn(kw, desc, ownToolNames, linkingToolNames) {
|
|
66
|
+
if (mentionsOwnToolProvenance(desc, ownToolNames, linkingToolNames)) return true;
|
|
67
|
+
if (EXPLICIT_OWN_PROVENANCE_RE.test(desc)) return true;
|
|
68
|
+
// Real credential types need the server itself (or one of its tools) named as the source.
|
|
69
|
+
if (SECRET_COMPOUND_MODIFIER.test(kw)) return false;
|
|
70
|
+
return GENERIC_PROVENANCE_RE.test(desc) && !USER_OWNED_PARAM_DESC.test(desc);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function hasOwnServerProvenance(param, ownToolNames, linkingToolNames) {
|
|
74
|
+
const kw = splitWords(param.key);
|
|
75
|
+
if (!kw || !SENSITIVE_PARAM.test(kw) || UNIVERSAL_SECRET_PARAM.test(kw)) return false;
|
|
76
|
+
return provenanceIsOwn(kw, String(param.description || ""), ownToolNames, linkingToolNames);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* How a schema field counts as visitor-sensitive.
|
|
81
|
+
*
|
|
82
|
+
* :return: "yes" (sensitive), "no" (not a secret at all: a flag, a count, an id) or
|
|
83
|
+
* "exempt" (looks like this server's own handle). Exempt fields do not make a Lethal
|
|
84
|
+
* Trifecta on their own, but they still make a "possible data path" note, so wording
|
|
85
|
+
* that imitates an own handle never clears a path silently.
|
|
86
|
+
*/
|
|
87
|
+
function schemaParamSensitivity({ key, type, description }, ctx) {
|
|
88
|
+
const { toolWords, toolDescWords, ownToolNames, linkingToolNames, provenancedKeys, siblingKeys } = ctx;
|
|
89
|
+
const kw = splitWords(key);
|
|
90
|
+
if (!kw || !SENSITIVE_PARAM.test(kw)) return "no";
|
|
91
|
+
if (type === "boolean") return "no";
|
|
92
|
+
if ((type === "integer" || type === "number") && /\btokens?\b/i.test(kw)) return "no";
|
|
93
|
+
if (NON_SECRET_TOKEN_METRIC.test(kw)) return "no";
|
|
94
|
+
if (/\bid$/i.test(kw) || /\b(?:auth )?state$/i.test(kw)) return "no";
|
|
95
|
+
if (/\bpasswords? (?:setup|reset|change|recovery|policy)(?: (?:link|url|page|token))?\b/i.test(kw)) return "no";
|
|
96
|
+
const desc = String(description || "");
|
|
97
|
+
if (PASSWORD_GATE_DESC.test(desc) && !/^(?:login|sign in|auth)/i.test(toolWords) && !PASSWORD_REUSE_RISK.test(desc)) {
|
|
98
|
+
return "exempt";
|
|
99
|
+
}
|
|
100
|
+
if (UNIVERSAL_SECRET_PARAM.test(kw)) return "yes";
|
|
101
|
+
|
|
102
|
+
if (!SECRET_COMPOUND_MODIFIER.test(kw) && (CRYPTO_OR_TEMPLATE_TOKEN_DESC.test(desc) || CRYPTO_OR_TEMPLATE_TOKEN_DESC.test(toolDescWords))) {
|
|
103
|
+
return "exempt";
|
|
104
|
+
}
|
|
105
|
+
if ((kw === "token" || kw === "tokens") && (BARE_TOKEN_NONSECRET_CONTEXT.test(desc) || BARE_TOKEN_NONSECRET_CONTEXT.test(toolDescWords))) {
|
|
106
|
+
return "exempt";
|
|
107
|
+
}
|
|
108
|
+
// A token "returned by a previous call" of a tool that links a bank or a login is that
|
|
109
|
+
// account's token, whatever the wording says.
|
|
110
|
+
const linksAccount = LINKING_TOOL.test(toolWords) || HANDLE_CREDENTIAL_RISK_DESC.test(`${toolWords} ${toolDescWords}`);
|
|
111
|
+
if (!linksAccount && provenanceIsOwn(kw, desc, ownToolNames, linkingToolNames)) return "exempt";
|
|
112
|
+
if (!desc.trim() && provenancedKeys.has(kw)) return "exempt";
|
|
113
|
+
|
|
114
|
+
// Plural "tokens" (CSS/template/UI/LLM token counts) is not a secret unless explicitly a secret modifier.
|
|
115
|
+
if (/\btokens$/i.test(kw) && !SECRET_COMPOUND_MODIFIER.test(kw)) return "exempt";
|
|
116
|
+
|
|
117
|
+
// Known lifecycle/pagination handles.
|
|
118
|
+
if (SAFE_OPAQUE_HANDLE_NAME.test(kw) && !HANDLE_CREDENTIAL_RISK_DESC.test(desc)) return "exempt";
|
|
119
|
+
|
|
120
|
+
// A plain token next to the id of the object it opens (application_id + token): an access
|
|
121
|
+
// handle for that one object, unless the tool links an account or talks about logins.
|
|
122
|
+
const plainToken = kw === "token" || (/^\w+ (?:token|secret|key)$/i.test(kw) && !SECRET_COMPOUND_MODIFIER.test(kw));
|
|
123
|
+
if (plainToken && siblingKeys.some((k) => /(?:^|_|\b)id$|Id$|^slug$|^reference$/i.test(k))
|
|
124
|
+
&& !HANDLE_CREDENTIAL_RISK_DESC.test(`${desc} ${toolDescWords}`) && !LINKING_TOOL.test(toolWords)) {
|
|
125
|
+
return "exempt";
|
|
126
|
+
}
|
|
127
|
+
return "yes";
|
|
128
|
+
}
|
|
129
|
+
const SENSITIVE_DESC = /\b(?:private\s+(?:documents?|notes|photos|messages)|(?:user|visitor|customer)'?s?\s+(?:private\s+)?(?:files|documents|notes|photos)|environment settings?|environment variables?|api credentials?|database credentials?|private files?|secret keys?|ssh keys?|(?:read|reads|load|loads|fetch|fetches|dump|dumps|extract|extracts|get|gets|access|accesses|collect|collects|steal|steals)\s+(?:the\s+|host\s+|local\s+|user\s+)?(?:env(?:ironment)?(?:\s+vars?)?|\.env|credentials?|cookies?|access\s+tokens?|config(?:uration)?\s+files?|private\s+data))\b/i;
|
|
130
|
+
const EGRESS_TOOL = /\b(?:http post|post to url|post url|send to url|http request|post data|send email|send message|post message|send reply|send to|send webhook|webhook|notify(?: team)?|dispatch|exfil|upload|export data|publish|write file|push data|transfer funds|transfer domain|domain transfer|send telemetry)\b/i;
|
|
131
|
+
const EGRESS_PARAM_URL = /\b(?:webhook(?:\s*url)?|callback(?:\s*url)?|exfil(?:\s*url)?|(?:destination|endpoint|upload|forward|recipient|target|post)\s*(?:url|uri|webhook|hook|email))\b/i;
|
|
132
|
+
const EGRESS_PARAM_WEAK = /\b(?:destination|recipient|endpoint|callback|forward\s*to)\b/i;
|
|
133
|
+
const EGRESS_PARAM_DESC_URL = /\b(?:url|uri|webhook|endpoint|https?|e-?mail)\b/i;
|
|
134
|
+
const EGRESS_DESC = /\b(?:send|sends|post|posts|upload|uploads|transmit|transmits|forward|forwards|push|pushes|stream|streams|relay|relays|export|exports|ship|ships|submit|submits|deliver|delivers|exfiltrate|exfiltrates)\b[^.!?\n]{0,45}\b(?:webhook|callback|external\s+(?:url|endpoint|server|host|api)|remote\s+(?:url|endpoint|server|host)|https?:\/\/|url\s+you\s+(?:give|provide|pass|specify)|destination\s+url|configured\s+address|team|channel)\b|\b(?:send|sends)\s+(?:a\s+)?(?:real\s+)?(?:e-?mail|reply|message|link)\s+to\b|\b(?:post|posts|send|sends|upload|uploads)\b[^.!?\n]{0,30}\bto\s+any\s+(?:url|address|endpoint|server|host|webhook)\b|\b(?:telemetry\s+payload|notify\s+team|send\s+telemetry|webhook\s+url)\b/i;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Analyze declared input, sensitivity, and egress capabilities across agents/tools.
|
|
138
|
+
*
|
|
139
|
+
* :param input.agents: Normalized agents/tools array from config.tools.
|
|
140
|
+
* :param input.itinerary: Evaluated itinerary stops array (or Map values).
|
|
141
|
+
* :param input.privacy: Extracted privacy forwarding rules ({agent, direction, fields}).
|
|
142
|
+
* :param input.manifest: Published manifest object.
|
|
143
|
+
* :param input.frontMan: Entry agent name.
|
|
144
|
+
* :param input.protocol: "open-agentic-web" | "a2a" | "mcp".
|
|
145
|
+
* :param input.targetOrigin: Origin of the inspected site so same-site endpoints aren't treated as external.
|
|
146
|
+
* :return: {untrustedInput, sensitiveAccess, externalEgress, trifecta, riskLevel, paths}.
|
|
147
|
+
*/
|
|
148
|
+
export function analyzeCapabilities({ agents = [], itinerary = [], privacy = [], manifest = {}, frontMan = "", protocol = "open-agentic-web", targetOrigin = "" }) {
|
|
149
|
+
const untrustedInput = [];
|
|
150
|
+
const sensitiveAccess = [];
|
|
151
|
+
// Access that only looks harmless because of wording ("own handle", "returned by …").
|
|
152
|
+
const exemptAccess = [];
|
|
153
|
+
const externalEgress = [];
|
|
154
|
+
|
|
155
|
+
const externalStops = [...itinerary].filter((s) => !s.sameSite && s.contacted);
|
|
156
|
+
const openPolicy = (manifest?.peer_policy || manifest?.web_policy)?.mode === "open";
|
|
157
|
+
const agentTools = new Set(manifest?.actions?.agentTools || []);
|
|
158
|
+
const ownToolNames = new Set(agents.map((a) => String(a?.name || "").toLowerCase()).filter(Boolean));
|
|
159
|
+
const linkingToolNames = new Set(agents
|
|
160
|
+
.filter((a) => LINKING_TOOL.test(splitWords(a?.name || "")))
|
|
161
|
+
.map((a) => String(a.name).toLowerCase()));
|
|
162
|
+
const EGRESS_HINT_TOOL = /\b(?:post|send|share|publish|submit|upload|export|transfer|forward|relay|notify|broadcast|webhook|e-?mail|exfil|transmit|dispatch|push)\b/i;
|
|
163
|
+
const EGRESS_HINT_DESC = /\b(?:send|sends|post|posts|share|shares|publish|publishes|upload|uploads|export|exports|transfer|transfers|forward|forwards|relay|relays|notify|notifies|broadcast|broadcasts|transmit|transmits|e-?mail|e-?mails)\s+(?:a|an|the|this|given|your|user|external|it|data|text|message|report|file|content|to)\b/i;
|
|
164
|
+
|
|
165
|
+
const toolSchemas = agents.map((agent) => collectSchemaInfo(agent.function?.parameters));
|
|
166
|
+
const provenancedKeys = new Set();
|
|
167
|
+
for (const schemaInfo of toolSchemas) {
|
|
168
|
+
for (const param of schemaInfo.paramSpecs) {
|
|
169
|
+
if (hasOwnServerProvenance(param, ownToolNames, linkingToolNames)) provenancedKeys.add(splitWords(param.key));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Front agent receives arbitrary caller/user text or partner outputs.
|
|
174
|
+
if (frontMan) {
|
|
175
|
+
untrustedInput.push({ source: frontMan, kind: "caller_prompt", detail: `Entry "${frontMan}" receives untrusted prompt/query text` });
|
|
176
|
+
} else if (agents.length) {
|
|
177
|
+
untrustedInput.push({ source: agents[0].name || "entry", kind: "tool_input", detail: "Exposes tool inputs reachable by a model" });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
for (let i = 0; i < agents.length; i++) {
|
|
181
|
+
const agent = agents[i];
|
|
182
|
+
const name = agent.name || "agent";
|
|
183
|
+
const ann = agent.annotations || {};
|
|
184
|
+
const toolWords = splitWords(name);
|
|
185
|
+
const descWords = splitWords([agent.function?.description, agent.instructions].filter(Boolean).join(" "));
|
|
186
|
+
const schemaInfo = toolSchemas[i];
|
|
187
|
+
const agentToolHit = [...agentTools].some((t) => SENSITIVE_TOOL.test(splitWords(t)));
|
|
188
|
+
|
|
189
|
+
if (UNTRUSTED_TOOL.test(toolWords) || (ann.openWorldHint === true && ann.readOnlyHint === true)) {
|
|
190
|
+
untrustedInput.push({ source: name, kind: "external_read", detail: `"${name}" ingests external/open-world content` });
|
|
191
|
+
}
|
|
192
|
+
const sensitiveMatch = toolWords.match(SENSITIVE_TOOL);
|
|
193
|
+
const toolText = `${toolWords} ${descWords}`;
|
|
194
|
+
const onlyOwnCredentialLifecycle = sensitiveMatch
|
|
195
|
+
&& /^(?:secrets?|credentials?)$/i.test(sensitiveMatch[0])
|
|
196
|
+
&& ((CREDENTIAL_LIFECYCLE_ONLY.test(toolText) && !STORED_SECRET_AUDIT_RISK.test(toolText) && !RETURNS_SECRET_VALUES.test(descWords))
|
|
197
|
+
|| (ann.readOnlyHint === true && NO_SECRET_VALUES_RETURNED.test(descWords)));
|
|
198
|
+
// The description decides: a "wallet_balance" tool that "transfers it" moves money.
|
|
199
|
+
const walletReadOnly = sensitiveMatch && /wallet/i.test(sensitiveMatch[0]) && !WALLET_CONTROL.test(toolText);
|
|
200
|
+
const sensitiveToolName = Boolean(sensitiveMatch) && !NON_VISITOR_TOOL_SECRET.test(toolWords) && !onlyOwnCredentialLifecycle && !walletReadOnly;
|
|
201
|
+
if (sensitiveToolName || SENSITIVE_DESC.test(descWords) || SENSITIVE_DESC.test(schemaInfo.descWords) || agentToolHit) {
|
|
202
|
+
sensitiveAccess.push({ source: name, kind: "sensitive_tool", detail: `"${name}" accesses potentially sensitive data, config, or files` });
|
|
203
|
+
} else if (sensitiveMatch) {
|
|
204
|
+
exemptAccess.push({ source: name, kind: "sensitive_tool", detail: `"${name}" handles its own credentials or balances` });
|
|
205
|
+
}
|
|
206
|
+
if (sensitiveToolName && /^(?:secrets?|credentials?)$/i.test(sensitiveMatch[0]) && NO_SECRET_VALUES_RETURNED.test(descWords)) {
|
|
207
|
+
// "Values are write-only and never returned": it lists names only. Only the tool's own
|
|
208
|
+
// word says so, so the path stays visible as a note instead of a hold.
|
|
209
|
+
const i = sensitiveAccess.findIndex((s) => s.source === name && s.kind === "sensitive_tool");
|
|
210
|
+
if (i >= 0) exemptAccess.push({ ...sensitiveAccess.splice(i, 1)[0], detail: `"${name}" lists secret names; it says values are never returned` });
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const ctx = { toolWords, toolDescWords: descWords, ownToolNames, linkingToolNames, provenancedKeys, siblingKeys: schemaInfo.keys };
|
|
214
|
+
const graded = schemaInfo.paramSpecs.map((param) => ({ param, level: schemaParamSensitivity(param, ctx) }));
|
|
215
|
+
const sensitiveParams = graded.filter((g) => g.level === "yes").map((g) => g.param.key);
|
|
216
|
+
const exemptParams = graded.filter((g) => g.level === "exempt").map((g) => g.param.key);
|
|
217
|
+
if (sensitiveParams.length) {
|
|
218
|
+
sensitiveAccess.push({
|
|
219
|
+
source: name,
|
|
220
|
+
kind: "sensitive_param",
|
|
221
|
+
detail: `"${name}" declares sensitive schema fields (${sensitiveParams.slice(0, 4).join(", ")})`,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
if (exemptParams.length) {
|
|
225
|
+
exemptAccess.push({
|
|
226
|
+
source: name,
|
|
227
|
+
kind: "sensitive_param",
|
|
228
|
+
detail: `"${name}" declares fields that look like the server's own handles (${exemptParams.slice(0, 4).join(", ")})`,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Hints may raise risk (openWorld mutating tools with sharing/outbound semantics), never lower concrete findings.
|
|
233
|
+
const hintRaisesEgress = ann.openWorldHint === true && ann.readOnlyHint === false
|
|
234
|
+
&& (EGRESS_HINT_TOOL.test(toolWords) || EGRESS_HINT_DESC.test(descWords));
|
|
235
|
+
const toolExternalUrl = toolOffOriginUrl(agent, targetOrigin);
|
|
236
|
+
const egressParams = schemaInfo.paramSpecs.filter(({ key, format, description }) => {
|
|
237
|
+
const kw = splitWords(key);
|
|
238
|
+
if (EGRESS_PARAM_URL.test(kw)) return true;
|
|
239
|
+
if (EGRESS_PARAM_WEAK.test(kw)) {
|
|
240
|
+
const fmt = String(format || "").toLowerCase();
|
|
241
|
+
return fmt === "uri" || fmt === "url" || fmt === "email" || EGRESS_PARAM_DESC_URL.test(splitWords(description));
|
|
242
|
+
}
|
|
243
|
+
return false;
|
|
244
|
+
}).map((p) => p.key);
|
|
245
|
+
if (EGRESS_TOOL.test(toolWords) || EGRESS_DESC.test(descWords) || hintRaisesEgress || toolExternalUrl || egressParams.length) {
|
|
246
|
+
externalEgress.push({
|
|
247
|
+
sink: toolExternalUrl || (egressParams.length ? `${name}(${egressParams[0]})` : name),
|
|
248
|
+
kind: toolExternalUrl ? "external_endpoint" : egressParams.length ? "egress_param" : "outbound_tool",
|
|
249
|
+
detail: toolExternalUrl
|
|
250
|
+
? `"${name}" sends tool requests off-origin (${toolExternalUrl})`
|
|
251
|
+
: egressParams.length
|
|
252
|
+
? `"${name}" accepts external destination parameter(s) (${egressParams.slice(0, 3).join(", ")})`
|
|
253
|
+
: `"${name}" performs external or state-changing egress`,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (agent.toolbox && typeof agent.args?.url === "string") {
|
|
258
|
+
let restOrigin = "";
|
|
259
|
+
try { restOrigin = new URL(agent.args.url, targetOrigin || undefined).origin; } catch { restOrigin = ""; }
|
|
260
|
+
if (!targetOrigin || !restOrigin || restOrigin !== targetOrigin) {
|
|
261
|
+
externalEgress.push({ sink: agent.args.url, kind: "rest_toolbox", detail: `REST toolbox "${name}" sends requests to ${agent.args.url}` });
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
for (const p of privacy) {
|
|
267
|
+
sensitiveAccess.push({
|
|
268
|
+
source: p.agent,
|
|
269
|
+
kind: "private_context",
|
|
270
|
+
detail: `Agent "${p.agent}" shares private context (${p.direction.replace("_", " ")}: ${p.fields.join(", ")})`,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
for (const stop of externalStops) {
|
|
275
|
+
const kindList = [...(stop.kinds || [])].join(", ");
|
|
276
|
+
externalEgress.push({
|
|
277
|
+
sink: stop.host,
|
|
278
|
+
kind: kindList,
|
|
279
|
+
detail: `Contacts external host ${stop.host} (${kindList})`,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (manifest.coded_tools?.bundle) {
|
|
284
|
+
externalEgress.push({ sink: manifest.coded_tools.bundle, kind: "code_bundle", detail: "Executes publisher code bundle in browser worker" });
|
|
285
|
+
}
|
|
286
|
+
if (openPolicy && externalStops.length) {
|
|
287
|
+
externalEgress.push({ sink: "any origin (open policy)", kind: "open_policy", detail: "peer_policy.mode is open with active external refs" });
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const uniq = (arr) => {
|
|
291
|
+
const seen = new Set();
|
|
292
|
+
return arr.filter((item) => {
|
|
293
|
+
if (seen.has(item.detail)) return false;
|
|
294
|
+
seen.add(item.detail);
|
|
295
|
+
return true;
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
const inputs = uniq(untrustedInput);
|
|
300
|
+
const secrets = uniq(sensitiveAccess);
|
|
301
|
+
const egress = uniq(externalEgress);
|
|
302
|
+
|
|
303
|
+
// Only treat external egress as a Trifecta when there is concrete sensitive access.
|
|
304
|
+
const concreteSensitive = secrets.filter((s) => s.kind === "private_context" || s.kind === "sensitive_tool" || s.kind === "sensitive_param");
|
|
305
|
+
const concreteEgress = egress.filter((e) => e.kind !== "code_bundle");
|
|
306
|
+
|
|
307
|
+
const crossOriginEgress = concreteEgress.some((e) => externalStops.some((s) => e.sink === s.host) || e.kind === "rest_toolbox" || e.kind === "outbound_tool" || e.kind === "external_endpoint" || e.kind === "egress_param");
|
|
308
|
+
const trifecta = inputs.length > 0 && concreteSensitive.length > 0 && concreteEgress.length > 0 && (crossOriginEgress || protocol === "mcp");
|
|
309
|
+
|
|
310
|
+
const paths = [];
|
|
311
|
+
if (trifecta) {
|
|
312
|
+
for (const s of concreteSensitive.slice(0, 3)) {
|
|
313
|
+
for (const e of concreteEgress.slice(0, 3)) {
|
|
314
|
+
paths.push({
|
|
315
|
+
from: inputs[0].source,
|
|
316
|
+
through: s.source,
|
|
317
|
+
to: e.sink,
|
|
318
|
+
reason: `${inputs[0].detail} -> ${s.detail} -> ${e.detail}`,
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const riskLevel = trifecta ? (crossOriginEgress ? "high" : "medium") : (concreteSensitive.length && concreteEgress.length ? "medium" : "none");
|
|
325
|
+
|
|
326
|
+
// The same path through fields or tools that were let off as the server's own: a note.
|
|
327
|
+
const exempt = uniq(exemptAccess);
|
|
328
|
+
const softTrifecta = !trifecta && inputs.length > 0 && exempt.length > 0 && concreteEgress.length > 0 && (crossOriginEgress || protocol === "mcp");
|
|
329
|
+
const softPaths = softTrifecta
|
|
330
|
+
? exempt.slice(0, 2).map((s) => ({
|
|
331
|
+
from: inputs[0].source, through: s.source, to: concreteEgress[0].sink,
|
|
332
|
+
reason: `${inputs[0].detail} -> ${s.detail} -> ${concreteEgress[0].detail}`,
|
|
333
|
+
}))
|
|
334
|
+
: [];
|
|
335
|
+
|
|
336
|
+
return {
|
|
337
|
+
untrustedInput: inputs,
|
|
338
|
+
sensitiveAccess: secrets,
|
|
339
|
+
externalEgress: egress,
|
|
340
|
+
trifecta,
|
|
341
|
+
riskLevel,
|
|
342
|
+
paths,
|
|
343
|
+
softTrifecta,
|
|
344
|
+
softPaths,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function toolOffOriginUrl(agent, targetOrigin) {
|
|
349
|
+
const candidates = [];
|
|
350
|
+
if (typeof agent?.url === "string") candidates.push(agent.url);
|
|
351
|
+
for (const ref of agent?.tools || []) {
|
|
352
|
+
if (typeof ref === "string" && /^https?:\/\//i.test(ref)) candidates.push(ref);
|
|
353
|
+
else if (ref && typeof ref === "object" && typeof ref.url === "string") candidates.push(ref.url);
|
|
354
|
+
}
|
|
355
|
+
for (const raw of candidates) {
|
|
356
|
+
try {
|
|
357
|
+
const u = new URL(raw, targetOrigin || undefined);
|
|
358
|
+
if (/^https?:$/.test(u.protocol) && (!targetOrigin || u.origin !== targetOrigin)) return u.href;
|
|
359
|
+
} catch { /* ignore invalid */ }
|
|
360
|
+
}
|
|
361
|
+
return "";
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function collectSchemaInfo(node, keys = [], descs = [], paramSpecs = []) {
|
|
365
|
+
if (!node || typeof node !== "object") return { keys, descWords: splitWords(descs.join(" ")), paramSpecs };
|
|
366
|
+
if (Array.isArray(node)) {
|
|
367
|
+
for (const item of node) collectSchemaInfo(item, keys, descs, paramSpecs);
|
|
368
|
+
return { keys, descWords: splitWords(descs.join(" ")), paramSpecs };
|
|
369
|
+
}
|
|
370
|
+
if (node.properties && typeof node.properties === "object" && !Array.isArray(node.properties)) {
|
|
371
|
+
for (const [k, v] of Object.entries(node.properties)) {
|
|
372
|
+
keys.push(k);
|
|
373
|
+
if (v && typeof v === "object") {
|
|
374
|
+
if (typeof v.title === "string") descs.push(v.title);
|
|
375
|
+
if (typeof v.description === "string") descs.push(v.description);
|
|
376
|
+
paramSpecs.push({ key: k, type: String(v.type || "").toLowerCase(), format: v.format || "", description: v.description || "" });
|
|
377
|
+
} else {
|
|
378
|
+
paramSpecs.push({ key: k, type: "", format: "", description: "" });
|
|
379
|
+
}
|
|
380
|
+
collectSchemaInfo(v, keys, descs, paramSpecs);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
for (const [k, v] of Object.entries(node)) {
|
|
384
|
+
if (k !== "properties" && v && typeof v === "object") collectSchemaInfo(v, keys, descs, paramSpecs);
|
|
385
|
+
}
|
|
386
|
+
return { keys, descWords: splitWords(descs.join(" ")), paramSpecs };
|
|
387
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// diff.js: what changed in a network since it was approved.
|
|
2
|
+
//
|
|
3
|
+
// A visitor's approval is given to what a network says at that moment. If the
|
|
4
|
+
// publisher later changes its instructions (a "rug pull"), the old approval should
|
|
5
|
+
// not carry over silently. A snapshot keeps what matters for that decision; diff()
|
|
6
|
+
// lists the changes in plain terms and line by line.
|
|
7
|
+
|
|
8
|
+
import { canonicalJson } from "./canonical.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The text the runtime sends as an agent's system prompt: its instructions, then its
|
|
12
|
+
* "command" (runner.js and langchain-runner.mjs). Every check that reads an agent's words
|
|
13
|
+
* reads both, so nothing the model reads goes unchecked.
|
|
14
|
+
*
|
|
15
|
+
* :param agent: An agent from the network file, or one from a snapshot.
|
|
16
|
+
* :return: The two texts, trimmed and joined the way the runtime joins them.
|
|
17
|
+
*/
|
|
18
|
+
export function promptOf(agent) {
|
|
19
|
+
return [agent?.instructions, agent?.command]
|
|
20
|
+
.filter((text) => typeof text === "string" && text.trim())
|
|
21
|
+
.map((text) => text.trim())
|
|
22
|
+
.join("\n\n");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The peer policy mode the runtime applies: peer_policy, or web_policy when there is no
|
|
27
|
+
* peer_policy (engine.js manifestAllowsPeer).
|
|
28
|
+
*
|
|
29
|
+
* :param manifest: A site's agent-manifest.json.
|
|
30
|
+
* :return: "open", "closed", "allowlist" or "".
|
|
31
|
+
*/
|
|
32
|
+
export function peerPolicyOf(manifest) {
|
|
33
|
+
return (manifest?.peer_policy || manifest?.web_policy)?.mode || "";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Take a snapshot of a compiled network and its manifest.
|
|
38
|
+
*
|
|
39
|
+
* :param config: AgentNetwork.config.
|
|
40
|
+
* :param manifest: The site's agent-manifest.json.
|
|
41
|
+
* :param fingerprint: {hash, linksHash} from canonical.js.
|
|
42
|
+
* :return: A small JSON object that diff() can compare.
|
|
43
|
+
*/
|
|
44
|
+
export function snapshotOf(config, manifest, fingerprint) {
|
|
45
|
+
const agents = {};
|
|
46
|
+
for (const agent of config?.tools || []) {
|
|
47
|
+
if (!agent || typeof agent.name !== "string") continue;
|
|
48
|
+
const record = {
|
|
49
|
+
description: String(agent.function?.description || ""),
|
|
50
|
+
instructions: String(agent.instructions || ""),
|
|
51
|
+
// The runtime adds "command" to the system prompt after the instructions.
|
|
52
|
+
command: String(agent.command || ""),
|
|
53
|
+
tools: (agent.tools || []).map((t) => (typeof t === "string" ? t : JSON.stringify(t))).sort(),
|
|
54
|
+
parameters: JSON.stringify(agent.function?.parameters || null),
|
|
55
|
+
allow: JSON.stringify(agent.allow || null),
|
|
56
|
+
limits: JSON.stringify({ max_steps: agent.max_steps, max_execution_seconds: agent.max_execution_seconds }),
|
|
57
|
+
};
|
|
58
|
+
if (agent.annotations) record.annotations = JSON.stringify(agent.annotations);
|
|
59
|
+
agents[agent.name] = record;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
hash: fingerprint?.hash || "",
|
|
63
|
+
linksHash: fingerprint?.linksHash || "",
|
|
64
|
+
description: String(config?.metadata?.description || ""),
|
|
65
|
+
linkLabels: config?.link_labels || {},
|
|
66
|
+
links: config?.links || {},
|
|
67
|
+
manifest: {
|
|
68
|
+
brand: manifest?.brand || "",
|
|
69
|
+
allowedPeers: [...(manifest?.allowed_peers || [])].sort(),
|
|
70
|
+
peerPolicy: peerPolicyOf(manifest),
|
|
71
|
+
codedTools: manifest?.coded_tools ? JSON.stringify(manifest.coded_tools) : "",
|
|
72
|
+
},
|
|
73
|
+
agents,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Whether two snapshots describe the same version: the same network fingerprint, the
|
|
79
|
+
* same partner links, and the same manifest fields that matter for trust (brand,
|
|
80
|
+
* allowed peers, peer policy and code bundle). The fingerprint covers only the network
|
|
81
|
+
* file, so a publisher could otherwise change its manifest without anyone noticing.
|
|
82
|
+
*
|
|
83
|
+
* :param before: A snapshot, such as the one stored with an approval.
|
|
84
|
+
* :param after: A snapshot of what is published now.
|
|
85
|
+
* :return: True when nothing the snapshots cover has changed.
|
|
86
|
+
*/
|
|
87
|
+
export function sameSnapshot(before, after) {
|
|
88
|
+
if (!before || !after) return false;
|
|
89
|
+
// The whole recorded manifest block, so a field added to snapshotOf counts here too.
|
|
90
|
+
return before.hash === after.hash && before.linksHash === after.linksHash
|
|
91
|
+
&& canonicalJson(before.manifest || {}) === canonicalJson(after.manifest || {});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Whether an approval covers exactly the version in a snapshot.
|
|
96
|
+
*
|
|
97
|
+
* :param pin: A stored approval (pins.js).
|
|
98
|
+
* :param snapshot: The snapshot of what is published now.
|
|
99
|
+
* :return: True when the approval still applies.
|
|
100
|
+
*/
|
|
101
|
+
export function matchesPin(pin, snapshot) {
|
|
102
|
+
if (!pin?.hash || !snapshot) return false;
|
|
103
|
+
// An approval without a snapshot holds only the fingerprint.
|
|
104
|
+
return pin.hash === snapshot.hash && (!pin.snapshot || sameSnapshot(pin.snapshot, snapshot));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Compare two snapshots.
|
|
109
|
+
*
|
|
110
|
+
* :param before: The approved snapshot.
|
|
111
|
+
* :param after: The snapshot of what is published now.
|
|
112
|
+
* :return: [{kind, severity, agent?, title, added?, removed?}], empty when nothing changed.
|
|
113
|
+
*/
|
|
114
|
+
export function diffSnapshots(before, after) {
|
|
115
|
+
const changes = [];
|
|
116
|
+
if (!before || !after) return changes;
|
|
117
|
+
if (sameSnapshot(before, after)) return changes;
|
|
118
|
+
const add = (change) => changes.push(change);
|
|
119
|
+
// Text the model reads, compared line by line.
|
|
120
|
+
const textChanged = (kind, name, label, old, now) => {
|
|
121
|
+
if ((old || "") === (now || "")) return;
|
|
122
|
+
const d = lineDiff(lines(old), lines(now));
|
|
123
|
+
add({ kind, severity: "high", agent: name, title: `${label} changed (${d.added.length} line(s) added, ${d.removed.length} removed)`,
|
|
124
|
+
added: d.added, removed: d.removed });
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const beforeAgents = before.agents || {};
|
|
128
|
+
const afterAgents = after.agents || {};
|
|
129
|
+
for (const name of Object.keys(afterAgents)) {
|
|
130
|
+
if (!(name in beforeAgents)) {
|
|
131
|
+
add({ kind: "agent_added", severity: "high", agent: name, title: `New agent "${name}"`,
|
|
132
|
+
added: lines(promptOf(afterAgents[name])) });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
for (const name of Object.keys(beforeAgents)) {
|
|
136
|
+
if (!(name in afterAgents)) add({ kind: "agent_removed", severity: "low", agent: name, title: `Agent "${name}" removed` });
|
|
137
|
+
}
|
|
138
|
+
for (const name of Object.keys(afterAgents)) {
|
|
139
|
+
const a = beforeAgents[name];
|
|
140
|
+
const b = afterAgents[name];
|
|
141
|
+
if (!a) continue;
|
|
142
|
+
textChanged("instructions_changed", name, `Instructions of "${name}"`, a.instructions, b.instructions);
|
|
143
|
+
// Approvals saved before "command" was recorded have none; they match an agent without one.
|
|
144
|
+
textChanged("command_changed", name, `The "command" text of "${name}", which the model reads after its instructions,`, a.command, b.command);
|
|
145
|
+
if (a.description !== b.description) {
|
|
146
|
+
add({ kind: "description_changed", severity: "medium", agent: name, title: `Description of "${name}" changed`,
|
|
147
|
+
added: [b.description], removed: [a.description] });
|
|
148
|
+
}
|
|
149
|
+
const toolsAdded = b.tools.filter((t) => !a.tools.includes(t));
|
|
150
|
+
const toolsRemoved = a.tools.filter((t) => !b.tools.includes(t));
|
|
151
|
+
if (toolsAdded.length) {
|
|
152
|
+
const external = toolsAdded.some((t) => /^https?:|^\{/.test(t));
|
|
153
|
+
add({ kind: "tools_added", severity: external ? "high" : "medium", agent: name,
|
|
154
|
+
title: external ? `"${name}" can now reach other sites or services` : `"${name}" can now call more agents`,
|
|
155
|
+
added: toolsAdded });
|
|
156
|
+
}
|
|
157
|
+
if (toolsRemoved.length) add({ kind: "tools_removed", severity: "low", agent: name, title: `"${name}" calls fewer tools`, removed: toolsRemoved });
|
|
158
|
+
if (a.allow !== b.allow) {
|
|
159
|
+
add({ kind: "privacy_changed", severity: "high", agent: name, title: `Private-context rules of "${name}" changed`,
|
|
160
|
+
added: [b.allow], removed: [a.allow] });
|
|
161
|
+
}
|
|
162
|
+
// A calling model reads the whole input schema, so its text is shown like the rest.
|
|
163
|
+
if (a.parameters !== b.parameters) {
|
|
164
|
+
add({ kind: "schema_changed", severity: "medium", agent: name, title: `Input schema of "${name}" changed`,
|
|
165
|
+
added: [b.parameters], removed: [a.parameters] });
|
|
166
|
+
}
|
|
167
|
+
if (a.limits !== b.limits) {
|
|
168
|
+
add({ kind: "limits_changed", severity: "medium", agent: name, title: `Execution limits of "${name}" changed`,
|
|
169
|
+
added: [b.limits], removed: [a.limits] });
|
|
170
|
+
}
|
|
171
|
+
if ((a.annotations || "") !== (b.annotations || "")) {
|
|
172
|
+
add({ kind: "annotations_changed", severity: "medium", agent: name, title: `Safety annotations of "${name}" changed`,
|
|
173
|
+
added: [b.annotations || ""], removed: [a.annotations || ""] });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (before.description !== after.description) {
|
|
177
|
+
add({ kind: "metadata_changed", severity: "low", title: "Network description changed", added: [after.description], removed: [before.description] });
|
|
178
|
+
}
|
|
179
|
+
const m0 = before.manifest || {};
|
|
180
|
+
const m1 = after.manifest || {};
|
|
181
|
+
if (m0.brand !== m1.brand) add({ kind: "brand_changed", severity: "medium", title: `Brand changed from "${m0.brand}" to "${m1.brand}"` });
|
|
182
|
+
const peersAdded = (m1.allowedPeers || []).filter((p) => !(m0.allowedPeers || []).includes(p));
|
|
183
|
+
if (peersAdded.length) add({ kind: "peers_added", severity: "high", title: "It may now contact more origins", added: peersAdded });
|
|
184
|
+
if (m0.peerPolicy !== m1.peerPolicy) {
|
|
185
|
+
add({ kind: "policy_changed", severity: m1.peerPolicy === "open" ? "high" : "low",
|
|
186
|
+
title: `Peer policy changed from "${m0.peerPolicy || "none"}" to "${m1.peerPolicy || "none"}"` });
|
|
187
|
+
}
|
|
188
|
+
if (m0.codedTools !== m1.codedTools) add({ kind: "code_changed", severity: "high", title: "Its executable code bundle changed" });
|
|
189
|
+
if (JSON.stringify(before.links) !== JSON.stringify(after.links) || JSON.stringify(before.linkLabels) !== JSON.stringify(after.linkLabels)) {
|
|
190
|
+
add({ kind: "links_changed", severity: "medium", title: "Its partner links or their labels changed" });
|
|
191
|
+
}
|
|
192
|
+
// The fingerprint ignores formatting, so a change here is real content this list does
|
|
193
|
+
// not cover. Say so, rather than suggest that nothing important changed.
|
|
194
|
+
if (!changes.length) add({ kind: "other", severity: "medium", title: "Other parts of the network file changed. This list does not show them, so read the file before approving." });
|
|
195
|
+
return changes;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function lines(text) {
|
|
199
|
+
return String(text || "").split(/\r?\n/).map((l) => l.trimEnd()).filter((l) => l.trim());
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Line diff by longest common subsequence. Instructions are short (well under a
|
|
204
|
+
* thousand lines), so the quadratic table is fine.
|
|
205
|
+
*
|
|
206
|
+
* :param a: Old lines.
|
|
207
|
+
* :param b: New lines.
|
|
208
|
+
* :return: {added, removed}
|
|
209
|
+
*/
|
|
210
|
+
export function lineDiff(a, b) {
|
|
211
|
+
const n = a.length;
|
|
212
|
+
const m = b.length;
|
|
213
|
+
if (n * m > 2_000_000) {
|
|
214
|
+
const setA = new Set(a);
|
|
215
|
+
const setB = new Set(b);
|
|
216
|
+
return { added: b.filter((l) => !setA.has(l)), removed: a.filter((l) => !setB.has(l)) };
|
|
217
|
+
}
|
|
218
|
+
const dp = Array.from({ length: n + 1 }, () => new Uint32Array(m + 1));
|
|
219
|
+
for (let i = n - 1; i >= 0; i -= 1) {
|
|
220
|
+
for (let j = m - 1; j >= 0; j -= 1) {
|
|
221
|
+
dp[i][j] = a[i] === b[j] ? dp[i + 1][j + 1] + 1 : Math.max(dp[i + 1][j], dp[i][j + 1]);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const added = [];
|
|
225
|
+
const removed = [];
|
|
226
|
+
let i = 0;
|
|
227
|
+
let j = 0;
|
|
228
|
+
while (i < n && j < m) {
|
|
229
|
+
if (a[i] === b[j]) { i += 1; j += 1; }
|
|
230
|
+
else if (dp[i + 1][j] >= dp[i][j + 1]) { removed.push(a[i]); i += 1; }
|
|
231
|
+
else { added.push(b[j]); j += 1; }
|
|
232
|
+
}
|
|
233
|
+
while (i < n) removed.push(a[i++]);
|
|
234
|
+
while (j < m) added.push(b[j++]);
|
|
235
|
+
return { added, removed };
|
|
236
|
+
}
|