agent-customs 0.0.0-stage → 1.0.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.
Files changed (48) hide show
  1. package/LICENSE.md +341 -0
  2. package/README.md +592 -2
  3. package/bin/agent-customs.mjs +194 -0
  4. package/package.json +77 -4
  5. package/site/.well-known/agent-customs-key.json +13 -0
  6. package/site/certificate.js +944 -0
  7. package/site/customs/analyze.js +1224 -0
  8. package/site/customs/auto.js +44 -0
  9. package/site/customs/canary.js +270 -0
  10. package/site/customs/canonical.js +123 -0
  11. package/site/customs/capabilities.js +387 -0
  12. package/site/customs/diff.js +236 -0
  13. package/site/customs/english-words.js +153 -0
  14. package/site/customs/guard-notice.js +226 -0
  15. package/site/customs/guard-ui.js +105 -0
  16. package/site/customs/guard.js +259 -0
  17. package/site/customs/inspect.js +446 -0
  18. package/site/customs/judge.js +208 -0
  19. package/site/customs/languages.js +826 -0
  20. package/site/customs/locks.js +967 -0
  21. package/site/customs/pins.js +119 -0
  22. package/site/customs/protocols.js +621 -0
  23. package/site/customs/receipts.js +154 -0
  24. package/site/customs/rules.js +1470 -0
  25. package/site/customs/unicode.js +361 -0
  26. package/site/runtime/LICENSE.txt +176 -0
  27. package/site/runtime/generated/graph.gen.mjs +83 -0
  28. package/site/runtime/generated/validation.gen.mjs +70 -0
  29. package/site/runtime/hocon.js +262 -0
  30. package/site/runtime/kernel.js +237 -0
  31. package/site/runtime/model.js +44 -0
  32. package/tests/fixtures/official/NOTICE +3 -0
  33. package/tests/fixtures/official/guesthouse_agentified/agent-manifest.json +86 -0
  34. package/tests/fixtures/official/guesthouse_agentified/links.json +6 -0
  35. package/tests/fixtures/official/guesthouse_agentified/tidewhistle_guesthouse.network.json +56 -0
  36. package/tests/fixtures/official/harbor_tours_agentified/agent-manifest.json +86 -0
  37. package/tests/fixtures/official/harbor_tours_agentified/links.json +6 -0
  38. package/tests/fixtures/official/harbor_tours_agentified/marrow_point_harbor_tours.network.json +56 -0
  39. package/tests/fixtures/official/pizza_restaurant_agentified/agent-manifest.json +78 -0
  40. package/tests/fixtures/official/pizza_restaurant_agentified/links.json +6 -0
  41. package/tests/fixtures/official/pizza_restaurant_agentified/pizza_restaurant_website_assistant.network.json +156 -0
  42. package/tools/bench.mjs +731 -0
  43. package/tools/external-heldout.mjs +337 -0
  44. package/tools/fs-fetch.mjs +19 -0
  45. package/tools/heldout-corpus.mjs +135 -0
  46. package/tools/inspect-local.mjs +88 -0
  47. package/tools/round2-corpus.mjs +395 -0
  48. package/tools/round3-corpus.mjs +192 -0
@@ -0,0 +1,119 @@
1
+ // pins.js: remember which version of a network the visitor approved.
2
+ //
3
+ // A pin is the fingerprint and snapshot of a network at the moment it was approved,
4
+ // stored in this browser only (origin-scoped localStorage). Nothing is sent anywhere.
5
+ // When the published network no longer matches its pin, the guard holds it for review.
6
+
7
+ const KEY = "agent-customs-pins-v1";
8
+
9
+ /**
10
+ * A Storage-like object kept in memory, for tests and for browsers that block storage.
11
+ */
12
+ export class MemoryStorage {
13
+ constructor() { this.map = new Map(); }
14
+ getItem(k) { return this.map.has(k) ? this.map.get(k) : null; }
15
+ setItem(k, v) { this.map.set(k, String(v)); }
16
+ removeItem(k) { this.map.delete(k); }
17
+ }
18
+
19
+ function defaultStorage() {
20
+ try {
21
+ const s = globalThis.localStorage;
22
+ const probe = "__agent_customs_probe__";
23
+ s.setItem(probe, "1");
24
+ s.removeItem(probe);
25
+ return s;
26
+ } catch {
27
+ return new MemoryStorage();
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Pins by network URL.
33
+ */
34
+ export class PinStore {
35
+ /**
36
+ * :param storage: A Storage-like object; defaults to localStorage, or memory when blocked.
37
+ * :param key: The storage key.
38
+ */
39
+ constructor(storage = defaultStorage(), key = KEY) {
40
+ this.storage = storage;
41
+ this.key = key;
42
+ this.listeners = new Set();
43
+ }
44
+
45
+ all() {
46
+ try {
47
+ const raw = this.storage.getItem(this.key);
48
+ const parsed = raw ? JSON.parse(raw) : {};
49
+ return parsed && typeof parsed === "object" ? parsed : {};
50
+ } catch {
51
+ return {};
52
+ }
53
+ }
54
+
55
+ save(all) {
56
+ try { this.storage.setItem(this.key, JSON.stringify(all)); } catch { /* storage full or blocked */ }
57
+ for (const fn of this.listeners) { try { fn(); } catch { /* listener errors stay local */ } }
58
+ }
59
+
60
+ get(url) {
61
+ return this.all()[normalize(url)] || null;
62
+ }
63
+
64
+ set(url, pin) {
65
+ const all = this.all();
66
+ all[normalize(url)] = pin;
67
+ this.save(all);
68
+ }
69
+
70
+ delete(url) {
71
+ const all = this.all();
72
+ const existed = normalize(url) in all;
73
+ delete all[normalize(url)];
74
+ this.save(all);
75
+ return existed;
76
+ }
77
+
78
+ list() {
79
+ return Object.values(this.all()).sort((a, b) => String(b.pinnedAt).localeCompare(String(a.pinnedAt)));
80
+ }
81
+
82
+ onChange(fn) {
83
+ this.listeners.add(fn);
84
+ return () => this.listeners.delete(fn);
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Make a pin from an inspection report.
90
+ *
91
+ * :param report: A report from analyzeNetwork.
92
+ * :param how: "manual" when the visitor pinned it, "first-use" when the guard did.
93
+ * :return: The pin.
94
+ */
95
+ export function pinFromReport(report, how = "manual") {
96
+ return {
97
+ url: report.target.url,
98
+ host: report.target.host,
99
+ network: report.target.network,
100
+ brand: report.identity.brand,
101
+ hash: report.identity.hash,
102
+ short: report.identity.short,
103
+ verdict: report.verdict.code,
104
+ pinnedAt: new Date().toISOString(),
105
+ how,
106
+ snapshot: report.snapshot,
107
+ };
108
+ }
109
+
110
+ function normalize(url) {
111
+ const raw = String(url || "").trim();
112
+ if (raw.startsWith("mcp:")) return `mcp:${normalize(raw.slice(4))}`;
113
+ try {
114
+ const u = new URL(raw);
115
+ return `${u.origin}${u.pathname.replace(/\/+$/, "")}`;
116
+ } catch {
117
+ return raw;
118
+ }
119
+ }