@agent-custody/receipts 0.16.5 → 0.16.7
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 +29 -13
- package/dist/capture.d.ts +2 -0
- package/dist/capture.js +13 -2
- package/dist/check.d.ts +1 -1
- package/dist/check.js +34 -10
- package/dist/cli.js +54 -9
- package/dist/config.d.ts +27 -2
- package/dist/config.js +66 -2
- package/dist/console-page.js +144 -50
- package/dist/deny-report.d.ts +7 -0
- package/dist/deny-report.js +8 -3
- package/dist/design.d.ts +11 -0
- package/dist/design.js +91 -0
- package/dist/door-app.d.ts +28 -0
- package/dist/door-app.js +244 -0
- package/dist/door-partner.d.ts +66 -0
- package/dist/door-partner.js +94 -0
- package/dist/door.d.ts +139 -10
- package/dist/door.js +297 -137
- package/dist/gateway-http.d.ts +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +5 -1
- package/dist/log-admin.js +100 -59
- package/dist/log-store.d.ts +8 -2
- package/dist/log-store.js +22 -12
- package/dist/perathos.d.ts +50 -0
- package/dist/perathos.js +188 -0
- package/dist/portal.d.ts +66 -5
- package/dist/portal.js +895 -242
- package/dist/receipt.d.ts +4 -1
- package/dist/session-audit.d.ts +46 -0
- package/dist/session-audit.js +150 -0
- package/dist/site-links.d.ts +23 -0
- package/dist/site-links.js +29 -0
- package/dist/verify.js +44 -4
- package/dist/web-bot-auth.d.ts +105 -0
- package/dist/web-bot-auth.js +508 -0
- package/docs/acs.md +2 -0
- package/docs/approvals.md +1 -1
- package/docs/completeness.md +1 -1
- package/docs/configuration.md +2 -0
- package/docs/console.md +11 -2
- package/docs/door-languages.md +168 -0
- package/docs/door-middleware.md +216 -0
- package/docs/door-quickstart.md +1 -1
- package/docs/door-signals.md +43 -6
- package/docs/door.md +129 -32
- package/docs/egress.md +3 -1
- package/docs/github-action.md +2 -2
- package/docs/mandates.md +1 -1
- package/docs/perathos.md +100 -0
- package/docs/sdk.md +32 -1
- package/docs/threat-model.md +2 -1
- package/docs/tutorials.md +6 -0
- package/docs/usage.md +3 -1
- package/docs/verification.md +3 -1
- package/package.json +7 -1
- package/vectors/audit.json +27 -27
- package/vectors/canonical.json +5 -5
- package/vectors/interop/perathos/LICENSE +21 -0
- package/vectors/interop/perathos/README.md +17 -0
- package/vectors/interop/perathos/pocketos-replay/session.head.json +11 -0
- package/vectors/interop/perathos/pocketos-replay/session.jsonl +8 -0
- package/vectors/interop/perathos/pocketos-replay/verification.json +65 -0
- package/vectors/receipts.json +1701 -1210
package/dist/config.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { dirname, resolve } from "node:path";
|
|
4
|
+
import { agentOrigin, normalizeAuthority } from "./web-bot-auth.js";
|
|
4
5
|
/** Where receipts are logged: a local file, or a log reached over HTTP whose bearer token comes from an environment variable. */
|
|
5
6
|
const LogSchema = z.object({ url: z.string().url(), tokenEnv: z.string().min(1).optional(), /** send leaf hashes only; the log never holds the receipt. Use it for any log run by someone else */ hashOnly: z.boolean().optional(), /** milliseconds one append may take before the log counts as unreachable; default 10000 */ timeoutMs: z.number().int().positive().optional(), /** the log's public key files; every append's answer is checked against them before a call is forwarded. Without them the log's key document is fetched from the log itself on first use and pinned, which catches a log that turns dishonest later but not one dishonest from the start; required with precommit. */ keys: z.array(z.string().min(1)).optional(), /** the id the log must write into every tree head; an answer for another log is refused */ logId: z.string().min(1).optional() });
|
|
6
7
|
export const ONE_LOG = "exactly one of logFile or log is required";
|
|
@@ -240,13 +241,15 @@ const DoorRouteSchema = z.object({
|
|
|
240
241
|
*/
|
|
241
242
|
export const DoorConfigSchema = z.object({
|
|
242
243
|
identity: z.object({ keyFile: z.string() }),
|
|
243
|
-
/** where allowed requests go: the site or API the door stands in front of */
|
|
244
|
+
/** where allowed requests go: the site or API the door stands in front of. The proxy needs it unless `authz` is set; the in-process door (`door-app.ts`) passes the request to the app instead and refuses a config that names one */
|
|
244
245
|
origin: z.object({
|
|
245
246
|
url: z.string().url(),
|
|
246
247
|
headers: z.record(z.string(), z.string()).optional(),
|
|
247
248
|
headerEnv: z.record(z.string(), z.string().min(1)).optional(),
|
|
248
249
|
timeoutMs: z.number().int().positive().default(30_000),
|
|
249
|
-
}),
|
|
250
|
+
}).optional(),
|
|
251
|
+
/** answer nginx `auth_request` and Envoy `ext_authz` checks instead of relaying: 200 with the receipt headers or 403, from `X-Original-Method` and `X-Original-URI`. The door never sees the body or the origin's answer */
|
|
252
|
+
authz: z.boolean().optional(),
|
|
250
253
|
routes: z.array(DoorRouteSchema).default([]),
|
|
251
254
|
/** the action name for an arrival no route matches; default "other" */
|
|
252
255
|
unmatchedRoute: z.string().min(1).default("other"),
|
|
@@ -281,6 +284,64 @@ export const DoorConfigSchema = z.object({
|
|
|
281
284
|
/** checks with the provider at once; an arrival past this is `unavailable`, never relayed on a pass it did not get. Default 64 */
|
|
282
285
|
maxInFlight: z.number().int().positive().default(64),
|
|
283
286
|
}).refine((c) => !c.action || c.provider === "turnstile", { message: "challenge.action is a Turnstile field; hCaptcha does not report an action" }).optional(),
|
|
287
|
+
/**
|
|
288
|
+
* Web Bot Auth: an RFC 9421 signature tagged `web-bot-auth`, Ed25519, checked against the key the `Signature-Agent`
|
|
289
|
+
* origin publishes at /.well-known/http-message-signatures-directory. The door fetches only the directories of `agents`,
|
|
290
|
+
* so an arrival cannot point it at a URL of its choosing.
|
|
291
|
+
*/
|
|
292
|
+
webBotAuth: z.object({
|
|
293
|
+
/** the signature agents whose directories the door fetches, as https origins (`https://crawler.example`) */
|
|
294
|
+
agents: z.array(z.string().refine((u) => { try {
|
|
295
|
+
return agentOrigin(u) === new URL(u).origin;
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
return false;
|
|
299
|
+
} }, { message: "a signature agent is an https origin, with no path, query, or credentials" }).transform((u) => new URL(u).origin)).min(1),
|
|
300
|
+
/** the authorities (host, or host:port) this door serves; a signature must cover `@authority` and name one of them */
|
|
301
|
+
authorities: z.array(z.string().min(1).transform(normalizeAuthority)).min(1),
|
|
302
|
+
/** refuse a signature without a nonce; with one, a signature serves one request. Default true */
|
|
303
|
+
requireNonce: z.boolean().default(true),
|
|
304
|
+
/** the longest after `created` a signature is accepted, whatever its `expires`. Default 300 */
|
|
305
|
+
maxAgeSeconds: z.number().int().positive().default(300),
|
|
306
|
+
/** how far the signer's clock may be from the door's. Default 60 */
|
|
307
|
+
clockSkewSeconds: z.number().int().nonnegative().default(60),
|
|
308
|
+
/** one directory fetch's budget. Default 3000 */
|
|
309
|
+
timeoutMs: z.number().int().positive().default(3_000),
|
|
310
|
+
/** the largest directory the door reads. Default 64 KiB */
|
|
311
|
+
maxDirectoryBytes: z.number().int().positive().default(64 * 1024),
|
|
312
|
+
/** how long a fetched directory is kept; a failed fetch is retried after 30 s. Default 300 */
|
|
313
|
+
cacheSeconds: z.number().int().positive().default(300),
|
|
314
|
+
/** nonces remembered at once; past this a signature is `unavailable`. Default 100000 */
|
|
315
|
+
maxNonces: z.number().int().positive().default(100_000),
|
|
316
|
+
}).optional(),
|
|
317
|
+
/**
|
|
318
|
+
* A partner detection engine (Cloudflare Bot Management, HUMAN, DataDome, behind an adapter that holds a signing key):
|
|
319
|
+
* the door asks it about each arrival on `routes`, naming the receipt it is writing, and the engine signs its verdict
|
|
320
|
+
* for that receipt. Only a verdict whose signature verifies under `keyFile` reaches the policy, as
|
|
321
|
+
* `context.facts.partner`, and the receipt records it as attested.
|
|
322
|
+
*/
|
|
323
|
+
partner: z.object({
|
|
324
|
+
/** the engine's name; the signed verdict must name the same engine */
|
|
325
|
+
engine: z.string().min(1).max(64),
|
|
326
|
+
/** where the door POSTs its question about an arrival */
|
|
327
|
+
url: z.string().url(),
|
|
328
|
+
/** the engine's Ed25519 public key file; the verdict's signature must verify under it */
|
|
329
|
+
keyFile: z.string(),
|
|
330
|
+
/** the route names whose arrivals the engine is asked about, or ["*"] */
|
|
331
|
+
routes: z.array(z.string().min(1)).min(1),
|
|
332
|
+
/** one question's budget, the answer's body included. Default 1500 */
|
|
333
|
+
timeoutMs: z.number().int().positive().default(1_500),
|
|
334
|
+
/**
|
|
335
|
+
* When no verified verdict is had (the engine is unreachable, slow, busy, or answers with a bad signature or a
|
|
336
|
+
* verdict for another arrival): "deny" (default) refuses the arrival with 503, whatever the policy says; "absent"
|
|
337
|
+
* leaves the `partner` fact out, so the policy decides without it and a rule that requires it denies. Never allow.
|
|
338
|
+
*/
|
|
339
|
+
onFailure: z.enum(["deny", "absent"]).default("deny"),
|
|
340
|
+
/** questions waiting on the engine at once; an arrival past this has no verdict (`unavailable`). Default 64 */
|
|
341
|
+
maxInFlight: z.number().int().positive().default(64),
|
|
342
|
+
/** the largest answer the door reads. Default 16 KiB */
|
|
343
|
+
maxResponseBytes: z.number().int().positive().default(16 * 1024),
|
|
344
|
+
}).optional(),
|
|
284
345
|
receiptsDir: z.string(),
|
|
285
346
|
logFile: z.string().optional(),
|
|
286
347
|
log: LogSchema.optional(),
|
|
@@ -289,6 +350,8 @@ export const DoorConfigSchema = z.object({
|
|
|
289
350
|
capture: CaptureSchema.optional(),
|
|
290
351
|
captureKeyEnv: z.string().min(1).optional(),
|
|
291
352
|
}).refine(hasOneLog, oneLog).refine((c) => new Set(c.routes.map((r) => r.name)).size === c.routes.length, { message: "route names must be unique" })
|
|
353
|
+
.refine((c) => !c.partner || c.partner.routes.every((r) => r === "*" || r === c.unmatchedRoute || c.routes.some((x) => x.name === r)), { message: "partner.routes names a route the door does not have" })
|
|
354
|
+
.refine((c) => !c.authz || c.trustProxy, { message: "authz needs trustProxy: true, since every check comes from the proxy and the arrival's address is the last in its X-Forwarded-For" })
|
|
292
355
|
.refine((c) => !c.log || !!c.log.keys?.length, { message: "a remote log needs log.keys: the log's public key files, pinned, to check its answer before a request is relayed" });
|
|
293
356
|
/**
|
|
294
357
|
* The egress witness: a forward proxy in the agent's network path for every connection that does not go to the gateway.
|
|
@@ -340,6 +403,7 @@ export function loadDoorConfig(path) {
|
|
|
340
403
|
receiptsDir: r(cfg.receiptsDir),
|
|
341
404
|
...(cfg.logFile ? { logFile: r(cfg.logFile) } : {}),
|
|
342
405
|
...(cfg.log?.keys ? { log: { ...cfg.log, keys: cfg.log.keys.map(r) } } : {}),
|
|
406
|
+
...(cfg.partner ? { partner: { ...cfg.partner, keyFile: r(cfg.partner.keyFile) } } : {}),
|
|
343
407
|
};
|
|
344
408
|
}
|
|
345
409
|
/**
|
package/dist/console-page.js
CHANGED
|
@@ -1,47 +1,50 @@
|
|
|
1
1
|
// The console's one page. The data it shows is written into the document with textContent only, never as markup, and the
|
|
2
2
|
// content-security-policy allows exactly this script and this style by hash, so a value that reaches the page cannot run.
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
:root[data-theme="dark"] { --bg: #1c1917; --panel: #292524; --ink: #fafaf9; --muted: #a8a29e; --line: #44403c; --accent: #f59e0b; --accent-ink: #1c1917; --ok: #4ade80; --warn: #fbbf24; --bad: #f87171; --code: #1c1917; }
|
|
8
|
-
* { box-sizing: border-box; }
|
|
9
|
-
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
|
|
4
|
+
import { DESIGN_CSS } from "./design.js";
|
|
5
|
+
const STYLE = DESIGN_CSS + String.raw `
|
|
6
|
+
:root { --muted: var(--ink2); --code: var(--soft); }
|
|
10
7
|
header { display: flex; align-items: center; gap: 16px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
|
|
11
|
-
header h1 { font-size:
|
|
8
|
+
header h1 { font-size: var(--text-md); margin: 0; }
|
|
12
9
|
nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
|
|
13
|
-
nav button { background: none; border: 0; padding: 6px 12px; border-radius:
|
|
10
|
+
nav button { background: none; border: 0; padding: 6px 12px; border-radius: var(--radius-sm); color: var(--muted); cursor: pointer; font: inherit; }
|
|
14
11
|
nav button[aria-current="page"] { background: var(--code); color: var(--ink); font-weight: 600; }
|
|
15
12
|
main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
|
|
16
|
-
h2 {
|
|
17
|
-
h3 {
|
|
18
|
-
.card {
|
|
13
|
+
h2 { margin: 0 0 12px; }
|
|
14
|
+
h3 { margin: 0 0 8px; }
|
|
15
|
+
.card { padding: 16px; margin-bottom: 16px; }
|
|
19
16
|
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
|
|
20
17
|
.grid .card { margin: 0; }
|
|
21
18
|
table { width: 100%; border-collapse: collapse; }
|
|
22
19
|
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
|
|
23
|
-
th { color: var(--muted); font-weight: 600; font-size:
|
|
20
|
+
th { color: var(--muted); font-weight: 600; font-size: var(--text-xs); white-space: nowrap; overflow-wrap: normal; }
|
|
24
21
|
table.kv th { width: 9em; white-space: nowrap; overflow-wrap: normal; }
|
|
25
22
|
tr.click { cursor: pointer; } tr.click:hover { background: var(--code); }
|
|
26
|
-
code, pre, textarea { font-family:
|
|
27
|
-
pre { background: var(--code); padding: 10px; border-radius:
|
|
28
|
-
textarea { width: 100%; min-height: 280px; background: var(--code); color: var(--ink); border: 1px solid var(--line); border-radius:
|
|
29
|
-
input[type=password], input[type=text], select { background: var(--code); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; font: inherit; }
|
|
30
|
-
button.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 6px; padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer; }
|
|
31
|
-
button.secondary { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 7px 14px; font: inherit; cursor: pointer; }
|
|
32
|
-
button.danger { background: var(--bad); color: #fff; border: 0; border-radius: 6px; padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer; }
|
|
33
|
-
button:disabled { opacity: .5; cursor: default; }
|
|
23
|
+
code, pre, textarea { font-family: var(--mono); font-size: var(--text-xs); }
|
|
24
|
+
pre { background: var(--code); padding: 10px; border-radius: var(--radius-sm); overflow: auto; max-height: 420px; margin: 8px 0 0; }
|
|
25
|
+
textarea { width: 100%; min-height: 280px; background: var(--code); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; resize: vertical; }
|
|
34
26
|
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
|
|
35
27
|
.muted { color: var(--muted); }
|
|
36
28
|
.ok { color: var(--ok); } .warn { color: var(--warn); } .error, .bad { color: var(--bad); }
|
|
37
|
-
.pill { display: inline-block; padding: 0 8px; border-radius:
|
|
38
|
-
.banner { border: 1px solid var(--line); border-left: 4px solid var(--accent); background: var(--panel); border-radius:
|
|
29
|
+
.pill { display: inline-block; padding: 0 8px; border-radius: var(--radius-full); border: 1px solid var(--line); font-size: var(--text-xs); }
|
|
30
|
+
.banner { border: 1px solid var(--line); border-left: 4px solid var(--accent); background: var(--panel); border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 16px; }
|
|
39
31
|
.banner.bad { border-left-color: var(--bad); }
|
|
40
32
|
.finding { display: grid; grid-template-columns: 56px 130px 1fr; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); }
|
|
41
33
|
#login { max-width: 420px; margin: 96px auto; }
|
|
42
34
|
[hidden] { display: none !important; }
|
|
43
35
|
.mt { margin-top: 16px; }
|
|
44
36
|
textarea.short { min-height: 140px; }
|
|
37
|
+
dialog { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 16px; max-width: min(480px, calc(100vw - 32px)); }
|
|
38
|
+
dialog::backdrop { background: rgba(0, 0, 0, .5); }
|
|
39
|
+
dialog h3 { margin: 0 0 8px; }
|
|
40
|
+
dialog p { margin: 8px 0; overflow-wrap: anywhere; }
|
|
41
|
+
.inline { margin-left: 4px; }
|
|
42
|
+
button.link { background: none; border: 0; padding: 0; font: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--accent); text-decoration: underline; cursor: pointer; }
|
|
43
|
+
details { margin-top: 8px; }
|
|
44
|
+
summary { cursor: pointer; color: var(--muted); }
|
|
45
|
+
.scroll { overflow-x: auto; } .scroll table { min-width: 640px; }
|
|
46
|
+
.detail h3:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
47
|
+
.pair { padding: 1px 0; }
|
|
45
48
|
@media (max-width: 600px) { .finding { grid-template-columns: 56px 1fr; } .finding .check { display: none; } }
|
|
46
49
|
`;
|
|
47
50
|
const SCRIPT = String.raw `
|
|
@@ -56,6 +59,7 @@ const SCRIPT = String.raw `
|
|
|
56
59
|
var tabs = ['Overview', 'Check', 'Policy', 'Grants', 'Receipts', 'Audit'];
|
|
57
60
|
var current = 'Overview';
|
|
58
61
|
var policyDigest = '';
|
|
62
|
+
var dirty = false;
|
|
59
63
|
|
|
60
64
|
function h(tag, attrs) {
|
|
61
65
|
var e = document.createElement(tag);
|
|
@@ -109,6 +113,57 @@ const SCRIPT = String.raw `
|
|
|
109
113
|
return box;
|
|
110
114
|
}
|
|
111
115
|
function short(s) { return s ? String(s).slice(0, 12) + '…' : '-'; }
|
|
116
|
+
// the one place a time is formatted: local time to read, the UTC ISO value in the title and in datetime
|
|
117
|
+
function when(v) {
|
|
118
|
+
var d = v == null || v === '' ? null : new Date(v);
|
|
119
|
+
if (!d || isNaN(d.getTime())) return v == null || v === '' ? '-' : String(v);
|
|
120
|
+
var iso = d.toISOString();
|
|
121
|
+
return h('time', { datetime: iso, title: iso + ' (UTC)', text: d.toLocaleString() });
|
|
122
|
+
}
|
|
123
|
+
function digest(v) { return h('code', { title: String(v), text: short(v) }); }
|
|
124
|
+
function isDigest(v) { return typeof v === 'string' && /^(sha256:)?[0-9a-f]{32,}$/i.test(v); }
|
|
125
|
+
function isIso(v) { return typeof v === 'string' && /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?Z$/.test(v); }
|
|
126
|
+
function value(v) {
|
|
127
|
+
if (isDigest(v)) return digest(v);
|
|
128
|
+
if (isIso(v)) return when(v);
|
|
129
|
+
if (typeof v === 'boolean') return v ? 'yes' : 'no';
|
|
130
|
+
if (Array.isArray(v)) return v.length ? v.join(', ') : 'none';
|
|
131
|
+
if (v !== null && typeof v === 'object') return JSON.stringify(v);
|
|
132
|
+
return v == null ? '-' : String(v);
|
|
133
|
+
}
|
|
134
|
+
function pairs(o) {
|
|
135
|
+
var box = h('div');
|
|
136
|
+
Object.keys(o).forEach(function (k) { box.appendChild(h('div', { class: 'pair' }, h('span', { class: 'muted', text: k + ' ' }), value(o[k]))); });
|
|
137
|
+
return box;
|
|
138
|
+
}
|
|
139
|
+
function inline(el, text, bad) { el.className = 'inline ' + (bad ? 'bad' : 'ok'); el.textContent = text; }
|
|
140
|
+
function inlineFail(el) { return function (e) { inline(el, e.message || String(e), true); }; }
|
|
141
|
+
|
|
142
|
+
// An in-page question built on the native dialog. It resolves true on the confirm button and false on Cancel or Escape.
|
|
143
|
+
function ask(title, body, label, danger) {
|
|
144
|
+
return new Promise(function (resolve) {
|
|
145
|
+
var dlg = h('dialog', { 'aria-labelledby': 'dlg-title' });
|
|
146
|
+
var cancel = h('button', { type: 'button', class: 'secondary', autofocus: !!danger, onclick: function () { dlg.close('cancel'); } }, 'Cancel');
|
|
147
|
+
var go = h('button', { type: 'button', class: danger ? 'danger' : 'primary', autofocus: !danger, onclick: function () { dlg.close('ok'); } }, label);
|
|
148
|
+
dlg.appendChild(h('h3', { id: 'dlg-title', text: title }));
|
|
149
|
+
body.forEach(function (t) { dlg.appendChild(h('p', { text: t })); });
|
|
150
|
+
dlg.appendChild(h('div', { class: 'row' }, go, cancel));
|
|
151
|
+
dlg.addEventListener('close', function () { document.body.removeChild(dlg); resolve(dlg.returnValue === 'ok'); });
|
|
152
|
+
document.body.appendChild(dlg);
|
|
153
|
+
dlg.showModal();
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
var ACTIONS = { 'policy.save': 'Policy saved', 'grant.revoke': 'Grant revoked' };
|
|
158
|
+
function historyTable(files) {
|
|
159
|
+
var t = h('table', null, h('tr', null, h('th', { text: 'saved' }), h('th', { text: 'digest' })));
|
|
160
|
+
files.forEach(function (f) {
|
|
161
|
+
var m = /^(\d{4}-\d\d-\d\d)T(\d\d)-(\d\d)-(\d\d)-(\d+)Z-([0-9a-f]+)\.cedar$/.exec(f);
|
|
162
|
+
t.appendChild(m ? h('tr', null, h('td', null, when(m[1] + 'T' + m[2] + ':' + m[3] + ':' + m[4] + '.' + m[5] + 'Z')), h('td', null, h('code', { text: m[6] })))
|
|
163
|
+
: h('tr', null, h('td', { colspan: 2, text: f })));
|
|
164
|
+
});
|
|
165
|
+
return t;
|
|
166
|
+
}
|
|
112
167
|
|
|
113
168
|
var renderers = {
|
|
114
169
|
Overview: function () {
|
|
@@ -126,7 +181,7 @@ const SCRIPT = String.raw `
|
|
|
126
181
|
h('div', { class: 'card' }, h('h3', { text: 'Gateway' }), kv([['status', gw], ['key id', o.gatewayKeyid ? short(o.gatewayKeyid) : 'not created yet'], ['mode', o.mode], ['config', o.configFile]])),
|
|
127
182
|
h('div', { class: 'card' }, h('h3', { text: 'Evidence' }), kv([['receipts', String(o.receiptCount)], ['last receipt', o.lastReceiptAt], ['log', o.log.kind === 'remote' ? 'remote ' + o.log.url + (o.log.hashOnly ? ' (hashes only)' : '') : 'local ' + o.log.file], ['precommit', o.precommit.length ? o.precommit.join(', ') : 'none']])),
|
|
128
183
|
h('div', { class: 'card' }, h('h3', { text: 'Who is trusted' }), kv([['principal keys', String(o.principals.length)], ['key ids', o.principals.map(short).join(', ') || 'none'], ['revoked grants', String(o.revokedCount)]])),
|
|
129
|
-
h('div', { class: 'card' }, h('h3', { text: 'Config check' }), h('p', null, h('span', { class: errs ? 'bad' : 'ok', text: errs + ' error' + (errs === 1 ? '' : 's') }), ', ', h('span', { class: warns ? 'warn' : 'muted', text: warns + ' warning' + (warns === 1 ? '' : 's') })), h('button', { class: 'secondary', onclick: function () {
|
|
184
|
+
h('div', { class: 'card' }, h('h3', { text: 'Config check' }), h('p', null, h('span', { class: errs ? 'bad' : 'ok', text: errs + ' error' + (errs === 1 ? '' : 's') }), ', ', h('span', { class: warns ? 'warn' : 'muted', text: warns + ' warning' + (warns === 1 ? '' : 's') })), h('button', { class: 'secondary', onclick: function () { location.hash = hashOf('Check'); } }, 'See the findings'))),
|
|
130
185
|
o.keyProblems.length ? h('div', { class: 'banner bad' }, o.keyProblems.join('. ')) : null,
|
|
131
186
|
h('div', { class: 'card mt' }, h('h3', { text: 'Upstreams' }), up),
|
|
132
187
|
o.facts.length ? h('div', { class: 'card' }, h('h3', { text: 'Fact lookups the gateway makes itself' }), kv(o.facts.map(function (f) { return [f.name, f.tool + ' for ' + f.forTools.join(', ')]; }))) : null);
|
|
@@ -152,7 +207,10 @@ const SCRIPT = String.raw `
|
|
|
152
207
|
policyDigest = p.digest;
|
|
153
208
|
var area = h('textarea', { 'aria-label': 'Cedar policy', spellcheck: 'false' });
|
|
154
209
|
area.value = p.text;
|
|
210
|
+
dirty = false;
|
|
155
211
|
var out = h('div');
|
|
212
|
+
var result = h('span', { role: 'status' });
|
|
213
|
+
area.addEventListener('input', function () { dirty = true; inline(result, ''); });
|
|
156
214
|
function validate() {
|
|
157
215
|
return api('POST', '/api/policy/validate', { text: area.value }).then(function (r) {
|
|
158
216
|
clear(out);
|
|
@@ -184,12 +242,14 @@ const SCRIPT = String.raw `
|
|
|
184
242
|
function save() {
|
|
185
243
|
return validate().then(function (v) {
|
|
186
244
|
if (!v.ok) return;
|
|
187
|
-
var
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
245
|
+
var body = ['A running gateway applies it from its next call.'].concat(v.issues);
|
|
246
|
+
return ask('Save the policy ' + p.path + '?', body, v.issues.length ? 'Save anyway' : 'Save').then(function (yes) {
|
|
247
|
+
if (!yes) return;
|
|
248
|
+
return api('PUT', '/api/policy', { text: area.value, expectDigest: policyDigest, confirm: v.issues.length > 0 }).then(function (r) {
|
|
249
|
+
policyDigest = r.digest;
|
|
250
|
+
dirty = false;
|
|
251
|
+
inline(result, 'Saved (' + short(r.digest) + '). A running gateway applies it from its next call.');
|
|
252
|
+
});
|
|
193
253
|
});
|
|
194
254
|
});
|
|
195
255
|
}
|
|
@@ -199,9 +259,9 @@ const SCRIPT = String.raw `
|
|
|
199
259
|
area, h('div', { class: 'row' },
|
|
200
260
|
h('button', { class: 'secondary', onclick: function () { validate().catch(fail); } }, 'Validate'),
|
|
201
261
|
h('button', { class: 'secondary', onclick: function () { simulate().catch(fail); } }, 'Replay recorded calls'),
|
|
202
|
-
h('button', { class: 'primary', onclick: function () { save().catch(
|
|
262
|
+
h('button', { class: 'primary', onclick: function () { inline(result, ''); save().catch(inlineFail(result)); } }, 'Save'), result),
|
|
203
263
|
out,
|
|
204
|
-
p.history.length ? h('div', { class: 'card' }, h('h3', { text: 'Earlier versions kept' }),
|
|
264
|
+
p.history.length ? h('div', { class: 'card' }, h('h3', { text: 'Earlier versions kept' }), historyTable(p.history)) : null);
|
|
205
265
|
});
|
|
206
266
|
},
|
|
207
267
|
|
|
@@ -209,26 +269,31 @@ const SCRIPT = String.raw `
|
|
|
209
269
|
var area = h('textarea', { 'aria-label': 'Grant', placeholder: 'Paste a grant (the JSON of a grant file)', spellcheck: 'false', class: 'short' });
|
|
210
270
|
var out = h('div');
|
|
211
271
|
var last = null;
|
|
272
|
+
var note = h('span', { role: 'status' });
|
|
212
273
|
function inspect() {
|
|
213
274
|
return api('POST', '/api/grants/inspect', { grant: area.value }).then(function (g) {
|
|
214
275
|
last = g;
|
|
215
276
|
clear(out);
|
|
216
277
|
out.appendChild(h('div', { class: 'card' }, h('h3', { text: 'Grant' }), kv([
|
|
217
278
|
['status', h('span', { class: g.status === 'valid' ? 'ok' : 'bad', text: g.status })],
|
|
218
|
-
['agent', g.agent], ['principal', g.principal], ['scopes', g.scopes.join(', ')], ['issued', g.issuedAt], ['expires', g.expiresAt],
|
|
219
|
-
['delegated from another grant', g.delegated ? 'yes' : 'no'], ['can delegate', g.canDelegate ? 'yes' : 'no'], ['digest', g.digest], ['why not valid', g.error]]),
|
|
220
|
-
h('div', { class: 'row' }, g.revoked ? h('span', { class: 'pill', text: 'already revoked' }) : h('button', { class: 'danger', onclick: function () { revoke().catch(
|
|
279
|
+
['agent', g.agent], ['principal', g.principal], ['scopes', g.scopes.join(', ')], ['issued', when(g.issuedAt)], ['expires', when(g.expiresAt)],
|
|
280
|
+
['delegated from another grant', g.delegated ? 'yes' : 'no'], ['can delegate', g.canDelegate ? 'yes' : 'no'], ['digest', g.digest ? digest(g.digest) : null], ['why not valid', g.error]]),
|
|
281
|
+
h('div', { class: 'row' }, g.revoked ? h('span', { class: 'pill', text: 'already revoked' }) : h('button', { class: 'danger', onclick: function () { inline(note, ''); revoke().catch(inlineFail(note)); } }, 'Revoke this grant'), note)));
|
|
221
282
|
});
|
|
222
283
|
}
|
|
223
284
|
function revoke() {
|
|
224
|
-
if (!last
|
|
225
|
-
|
|
285
|
+
if (!last) return Promise.resolve();
|
|
286
|
+
var who = last.agent + ' (digest ' + short(last.digest) + ')';
|
|
287
|
+
return ask('Revoke the grant for ' + who + '?', ['The grant, and every grant delegated from it, is refused on its next call. This cannot be undone here.'], 'Revoke', true).then(function (yes) {
|
|
288
|
+
if (!yes) return;
|
|
289
|
+
return api('POST', '/api/grants/revoke', { grant: area.value }).then(function (r) { return inspect().then(list).then(function () { inline(note, 'Revoked the grant for ' + r.agent + '. The gateway refuses it, and every grant delegated from it, on its next call.'); }); });
|
|
290
|
+
});
|
|
226
291
|
}
|
|
227
292
|
var revoked = h('div');
|
|
228
293
|
function list() {
|
|
229
294
|
return api('GET', '/api/revocations').then(function (r) {
|
|
230
295
|
clear(revoked);
|
|
231
|
-
revoked.appendChild(h('div', { class: 'card' }, h('h3', { text: 'Revoked grants (' + r.digests.length + ')' }), r.digests.length ?
|
|
296
|
+
revoked.appendChild(h('div', { class: 'card' }, h('h3', { text: 'Revoked grants (' + r.digests.length + ')' }), r.digests.length ? r.digests.reduce(function (t, d) { t.appendChild(h('tr', null, h('td', null, h('code', { text: d })))); return t; }, h('table', null, h('tr', null, h('th', { text: 'digest' })))) : h('p', { class: 'muted', text: 'None.' })));
|
|
232
297
|
});
|
|
233
298
|
}
|
|
234
299
|
list().catch(fail);
|
|
@@ -244,20 +309,36 @@ const SCRIPT = String.raw `
|
|
|
244
309
|
var body = h('table');
|
|
245
310
|
function draw() {
|
|
246
311
|
clear(body);
|
|
247
|
-
body.appendChild(h('tr', null, h('th', { text: 'time' }), h('th', { text: 'agent' }), h('th', { text: 'tool' }), h('th', { text: 'decision' }), h('th', { text: 'outcome' }), h('th', { text: 'verifies' })));
|
|
312
|
+
body.appendChild(h('tr', null, h('th', { text: 'receipt' }), h('th', { text: 'time' }), h('th', { text: 'agent' }), h('th', { text: 'tool' }), h('th', { text: 'decision' }), h('th', { text: 'outcome' }), h('th', { text: 'verifies' })));
|
|
248
313
|
r.receipts.filter(function (x) { return !filter.value || x.status === filter.value; }).forEach(function (x) {
|
|
249
|
-
body.appendChild(h('tr', { class: 'click', onclick: function () { open(x.id); } },
|
|
250
|
-
h('td',
|
|
314
|
+
body.appendChild(h('tr', { class: 'click', onclick: function (ev) { open(x.id, ev.currentTarget.querySelector('button')); } },
|
|
315
|
+
h('td', null, h('button', { type: 'button', class: 'link', 'data-id': x.id, title: x.id, text: short(x.id) })),
|
|
316
|
+
h('td', null, when(x.timestamp)), h('td', { text: x.agent || '-' }), h('td', { text: x.tool || '-' }),
|
|
251
317
|
h('td', { class: x.decision === 'deny' ? 'bad' : '', text: x.decision ? x.decision + (x.enforced ? '' : ' (not enforced)') : '-' }),
|
|
252
318
|
h('td', { text: x.status ? x.status + (x.reason ? ': ' + x.reason : '') : '-' }),
|
|
253
319
|
h('td', { class: x.verified ? 'ok' : 'bad', text: x.verified ? 'yes' : 'NO: ' + (x.failing || []).join(', ') })));
|
|
254
320
|
});
|
|
255
321
|
}
|
|
256
|
-
function
|
|
322
|
+
function close(id) {
|
|
323
|
+
clear(detail);
|
|
324
|
+
var row = body.querySelector('button[data-id="' + id + '"]');
|
|
325
|
+
(row || filter).focus();
|
|
326
|
+
}
|
|
327
|
+
function open(id, opener) {
|
|
257
328
|
api('GET', '/api/receipts/' + encodeURIComponent(id)).then(function (d) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
329
|
+
var s = d.summary || {};
|
|
330
|
+
var st = d.statement || {};
|
|
331
|
+
var title = h('h3', { tabindex: '-1', text: 'Receipt ' + id });
|
|
332
|
+
var args = st.request && st.request.argsDigest;
|
|
333
|
+
var res = st.execution && st.execution.resultDigest;
|
|
334
|
+
var rows = [['tool', s.tool], ['decision', s.decision ? s.decision + (s.enforced ? '' : ' (not enforced)') : null],
|
|
335
|
+
['status', s.status ? s.status + (s.reason ? ': ' + s.reason : '') : null], ['time', when(s.timestamp)], ['agent', s.agent], ['principal', s.principal],
|
|
336
|
+
['grant', st.delegation ? 'a signed grant was presented' : 'none'], ['arguments digest', args ? digest(args) : null], ['result digest', res ? digest(res) : null],
|
|
337
|
+
['verifies', h('span', { class: s.verified ? 'ok' : 'bad', text: s.verified ? 'yes' : 'NO: ' + (s.failing || []).join(', ') })]];
|
|
338
|
+
clear(detail).appendChild(h('div', { class: 'card detail' }, title, kv(rows),
|
|
339
|
+
h('details', null, h('summary', { text: 'Raw JSON' }), h('pre', { text: JSON.stringify(d.statement, null, 2) })),
|
|
340
|
+
h('div', { class: 'row' }, h('button', { type: 'button', class: 'secondary', onclick: function () { close(id); } }, 'Close'))));
|
|
341
|
+
title.focus();
|
|
261
342
|
}).catch(fail);
|
|
262
343
|
}
|
|
263
344
|
filter.addEventListener('change', draw);
|
|
@@ -265,7 +346,7 @@ const SCRIPT = String.raw `
|
|
|
265
346
|
return h('div', null, h('h2', { text: 'Receipts' }),
|
|
266
347
|
h('p', { class: 'muted', text: r.total + ' receipts on disk, the newest ' + r.receipts.length + ' shown. Each is verified against the gateway key, the trusted principals, and the local log.' }),
|
|
267
348
|
r.problems.length ? h('div', { class: 'banner bad' }, r.problems.join('. ')) : null,
|
|
268
|
-
h('div', { class: 'row' }, h('label', null, 'Outcome ', filter)), h('div', { class: 'card' }, body), detail);
|
|
349
|
+
h('div', { class: 'row' }, h('label', null, 'Outcome ', filter)), h('div', { class: 'card scroll' }, body), detail);
|
|
269
350
|
});
|
|
270
351
|
},
|
|
271
352
|
|
|
@@ -274,15 +355,19 @@ const SCRIPT = String.raw `
|
|
|
274
355
|
var t = h('table', null, h('tr', null, h('th', { text: 'when' }), h('th', { text: 'by' }), h('th', { text: 'action' }), h('th', { text: 'detail' })));
|
|
275
356
|
a.entries.forEach(function (e) {
|
|
276
357
|
var rest = {}; Object.keys(e).forEach(function (k) { if (k !== 'at' && k !== 'by' && k !== 'action') rest[k] = e[k]; });
|
|
277
|
-
t.appendChild(h('tr', null, h('td',
|
|
358
|
+
t.appendChild(h('tr', null, h('td', null, when(e.at)), h('td', { text: e.by }), h('td', { text: ACTIONS[e.action] || e.action }), h('td', null, pairs(rest))));
|
|
278
359
|
});
|
|
279
|
-
return h('div', null, h('h2', { text: 'Audit trail' }), h('p', { class: 'muted', text: 'Every change made here: who, when, and what.' }), h('div', { class: 'card' }, a.entries.length ? t : h('p', { class: 'muted', text: 'No changes yet.' })));
|
|
360
|
+
return h('div', null, h('h2', { text: 'Audit trail' }), h('p', { class: 'muted', text: 'Every change made here: who, when, and what.' }), h('div', { class: 'card scroll' }, a.entries.length ? t : h('p', { class: 'muted', text: 'No changes yet.' })));
|
|
280
361
|
});
|
|
281
362
|
}
|
|
282
363
|
};
|
|
283
364
|
|
|
365
|
+
// "tab=" keeps the hash from ever matching an element id, so the browser does not scroll to one
|
|
366
|
+
function hashOf(name) { return '#tab=' + name.toLowerCase(); }
|
|
367
|
+
function tabOf(hash) { return tabs.filter(function (n) { return hashOf(n) === hash; })[0]; }
|
|
284
368
|
function show(name) {
|
|
285
369
|
current = name;
|
|
370
|
+
dirty = false;
|
|
286
371
|
say('');
|
|
287
372
|
Array.prototype.forEach.call(document.querySelectorAll('nav button'), function (b) { if (b.textContent === name) b.setAttribute('aria-current', 'page'); else b.removeAttribute('aria-current'); });
|
|
288
373
|
clear(view).appendChild(h('p', { class: 'muted', text: 'Loading…' }));
|
|
@@ -290,7 +375,16 @@ const SCRIPT = String.raw `
|
|
|
290
375
|
}
|
|
291
376
|
|
|
292
377
|
var nav = document.getElementById('nav');
|
|
293
|
-
tabs.forEach(function (n) { nav.appendChild(h('button', { type: 'button', onclick: function () {
|
|
378
|
+
tabs.forEach(function (n) { nav.appendChild(h('button', { type: 'button', onclick: function () { location.hash = hashOf(n); } }, n)); });
|
|
379
|
+
window.addEventListener('hashchange', function () {
|
|
380
|
+
var name = tabOf(location.hash);
|
|
381
|
+
if (document.getElementById('app').hidden || !name || name === current) return;
|
|
382
|
+
if (!dirty) return show(name);
|
|
383
|
+
ask('Leave the policy editor?', ['The policy has changes that are not saved. If you leave, they are lost.'], 'Discard the changes', true).then(function (yes) {
|
|
384
|
+
if (yes) show(name); else history.replaceState(null, '', hashOf(current));
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
window.addEventListener('beforeunload', function (ev) { if (dirty) { ev.preventDefault(); ev.returnValue = ''; } });
|
|
294
388
|
document.getElementById('signout').addEventListener('click', signOut);
|
|
295
389
|
document.getElementById('theme').addEventListener('click', function () {
|
|
296
390
|
var dark = document.documentElement.getAttribute('data-theme') === 'dark' || (!document.documentElement.getAttribute('data-theme') && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
@@ -306,11 +400,11 @@ const SCRIPT = String.raw `
|
|
|
306
400
|
try { sessionStorage.setItem(KEY, token); } catch (e) {}
|
|
307
401
|
document.getElementById('login').hidden = true;
|
|
308
402
|
document.getElementById('app').hidden = false;
|
|
309
|
-
show(current);
|
|
403
|
+
show(tabOf(location.hash) || current);
|
|
310
404
|
}).catch(function (e) { clear(document.getElementById('login-msg')).appendChild(h('p', { class: 'bad', role: 'alert', text: e.message })); });
|
|
311
405
|
});
|
|
312
406
|
if (token) {
|
|
313
|
-
api('GET', '/api/audit').then(function () { document.getElementById('login').hidden = true; document.getElementById('app').hidden = false; show(current); }).catch(function () { signOut(); });
|
|
407
|
+
api('GET', '/api/audit').then(function () { document.getElementById('login').hidden = true; document.getElementById('app').hidden = false; show(tabOf(location.hash) || current); }).catch(function () { signOut(); });
|
|
314
408
|
}
|
|
315
409
|
})();
|
|
316
410
|
`;
|
package/dist/deny-report.d.ts
CHANGED
|
@@ -26,5 +26,12 @@ export interface DenyReport {
|
|
|
26
26
|
reason: string;
|
|
27
27
|
}[];
|
|
28
28
|
}
|
|
29
|
+
/** The command, file path, or URL of a call, for a one-line listing. */
|
|
30
|
+
export declare function targetOf(args: unknown): string;
|
|
31
|
+
/** The `@reason` and the text of each rule a decision names, from the policy's rules and reasons by their ids. */
|
|
32
|
+
export declare function ruleTexts(policyIds: string[], rules: (string | null)[], reasons: (string | null)[]): {
|
|
33
|
+
reasons: string[];
|
|
34
|
+
rules: string[];
|
|
35
|
+
};
|
|
29
36
|
export declare function denyReport(configFile: string): DenyReport;
|
|
30
37
|
export declare function formatDenyReport(r: DenyReport): string;
|
package/dist/deny-report.js
CHANGED
|
@@ -8,7 +8,8 @@ import { policyDigest, policyReasons, policyRules } from "./policy.js";
|
|
|
8
8
|
import { verifyBundle } from "./verify.js";
|
|
9
9
|
const ANNOTATIONS = /^(?:\s*@\w+\s*\("(?:[^"\\]|\\.)*"\))+\s*/;
|
|
10
10
|
const TARGET_ARGS = ["command", "file_path", "notebook_path", "path", "url"];
|
|
11
|
-
|
|
11
|
+
/** The command, file path, or URL of a call, for a one-line listing. */
|
|
12
|
+
export function targetOf(args) {
|
|
12
13
|
if (!args || typeof args !== "object")
|
|
13
14
|
return "(withheld)";
|
|
14
15
|
const a = args;
|
|
@@ -16,6 +17,11 @@ function targetOf(args) {
|
|
|
16
17
|
const text = name ? a[name] : JSON.stringify(a);
|
|
17
18
|
return text.replace(/\s+/g, " ").trim();
|
|
18
19
|
}
|
|
20
|
+
/** The `@reason` and the text of each rule a decision names, from the policy's rules and reasons by their ids. */
|
|
21
|
+
export function ruleTexts(policyIds, rules, reasons) {
|
|
22
|
+
const at = (list) => policyIds.map((id) => list[Number(id.replace(/^policy/, ""))]).filter((r) => typeof r === "string");
|
|
23
|
+
return { reasons: at(reasons), rules: at(rules).map((r) => r.replace(/\s+/g, " ").replace(/;$/, "").replace(ANNOTATIONS, "").trim()) };
|
|
24
|
+
}
|
|
19
25
|
export function denyReport(configFile) {
|
|
20
26
|
const cfg = loadSdkConfig(configFile);
|
|
21
27
|
const issuer = loadPrivateKey(cfg.identity.keyFile);
|
|
@@ -57,8 +63,7 @@ export function denyReport(configFile) {
|
|
|
57
63
|
tool: p.tool.name,
|
|
58
64
|
target: targetOf(p.request.args),
|
|
59
65
|
policyIds,
|
|
60
|
-
|
|
61
|
-
rules: known ? policyIds.map((id) => rules[Number(id.replace(/^policy/, ""))]).filter((r) => typeof r === "string").map((r) => r.replace(/\s+/g, " ").replace(/;$/, "").replace(ANNOTATIONS, "").trim()) : [],
|
|
66
|
+
...(known ? ruleTexts(policyIds, rules, reasons) : { reasons: [], rules: [] }),
|
|
62
67
|
};
|
|
63
68
|
leafOf.set(call, bundle.inclusion.leafIndex);
|
|
64
69
|
(p.policy.enforced === false ? report.wouldDeny : report.denied).push(call);
|
package/dist/design.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The app pages: the tokens, light and dark (system or data-theme), the base, and the shared components. */
|
|
2
|
+
export declare const DESIGN_CSS: string;
|
|
3
|
+
/** The site: the same tokens and components; VitePress sets the dark class itself. */
|
|
4
|
+
export declare const SITE_CSS: string;
|
|
5
|
+
/** The logo: a receipt with a check mark. The tile takes the accent colour, so the mark follows the theme. */
|
|
6
|
+
export declare const LOGO_MARK = "<svg class=\"mark\" viewBox=\"0 0 64 64\" aria-hidden=\"true\"><rect class=\"tile\" width=\"64\" height=\"64\" rx=\"14\"/><path d=\"M19 11H45V45L41.75 48 38.5 45 35.25 48 32 45 28.75 48 25.5 45 22.25 48 19 45Z\" fill=\"#fff\"/><path class=\"ink\" d=\"M25 20h14M25 27h14\" stroke-width=\"2.6\" stroke-linecap=\"round\"/><path class=\"ink\" d=\"M25 37.5l5 4.5 9.5-10\" fill=\"none\" stroke-width=\"3.4\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>";
|
|
7
|
+
/** The header of the review page and the case file: the logo, the name of the page, and the theme toggle. */
|
|
8
|
+
export declare const appHeader: (name: string) => string;
|
|
9
|
+
export declare const APP_HEADER_CSS = "\n.apphead { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); background: var(--panel); }\n.apphead .brand { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--ink); font-weight: 700; text-decoration: none; }\n.apphead .pill { padding: 0 var(--space-2); border-radius: var(--radius-full); background: var(--accent-bg); color: var(--accent); font: 600 var(--text-xs)/1.6 var(--font); }\n.apphead #themeToggle { margin-left: auto; }\n.mark { width: 28px; height: 28px; display: block; } .mark .tile { fill: var(--accent); } .mark .ink { stroke: var(--accent); }\n#themeToggle[aria-pressed=\"true\"] .moon, #themeToggle[aria-pressed=\"false\"] .sun { display: none; }\n";
|
|
10
|
+
/** Applies the saved theme and wires the toggle. It uses the storage key of the portal. Put it after the button. */
|
|
11
|
+
export declare const THEME_SCRIPT = "(() => {\n const root = document.documentElement, button = document.getElementById(\"themeToggle\");\n try { const saved = localStorage.getItem(\"agent-custody-theme\"); if (saved === \"dark\" || saved === \"light\") root.dataset.theme = saved; } catch {}\n const now = () => root.dataset.theme || (matchMedia(\"(prefers-color-scheme: dark)\").matches ? \"dark\" : \"light\");\n const label = () => button.setAttribute(\"aria-pressed\", String(now() === \"dark\"));\n button.onclick = () => { const next = now() === \"dark\" ? \"light\" : \"dark\"; root.dataset.theme = next; try { localStorage.setItem(\"agent-custody-theme\", next); } catch {} label(); };\n label();\n})();\n";
|
package/dist/design.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// The design tokens and the shared components of every surface: the site, the portal, the log admin, the gateway
|
|
2
|
+
// console, the review page, and the offline case file. The app pages inline DESIGN_CSS, so they make no outside request.
|
|
3
|
+
// The site imports site/.vitepress/theme/tokens.css, which a test keeps identical to SITE_CSS.
|
|
4
|
+
// "Inter" comes from VitePress on the site; the app pages use it only when the machine has it installed.
|
|
5
|
+
const LIGHT = `--bg: #fafaf9; --panel: #ffffff; --soft: #f5f5f4; --line: #e7e5e4; --line-strong: #d6d3d1;
|
|
6
|
+
--ink: #1c1917; --ink2: #57534e; --ink3: #78716c;
|
|
7
|
+
--accent: #b45309; --accent-hover: #92400e; --accent-active: #78350f; --accent-ink: #ffffff; --accent-bg: #fef3c7;
|
|
8
|
+
--ok: #15803d; --ok-bg: #dcfce7; --warn: #a16207; --warn-bg: #fef9c3; --bad: #b91c1c; --bad-bg: #fee2e2;
|
|
9
|
+
--shadow: 0 1px 2px rgb(28 25 23 / .05), 0 18px 40px -18px rgb(28 25 23 / .25);`;
|
|
10
|
+
const DARK = `--bg: #0c0a09; --panel: #1c1917; --soft: #292524; --line: #292524; --line-strong: #44403c;
|
|
11
|
+
--ink: #fafaf9; --ink2: #a8a29e; --ink3: #8a847f;
|
|
12
|
+
--accent: #f59e0b; --accent-hover: #fbbf24; --accent-active: #d97706; --accent-ink: #1c1917; --accent-bg: #451a03;
|
|
13
|
+
--ok: #4ade80; --ok-bg: #052e16; --warn: #facc15; --warn-bg: #422006; --bad: #f87171; --bad-bg: #450a0a;
|
|
14
|
+
--shadow: none;`;
|
|
15
|
+
const SCALE = `--font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
16
|
+
--mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
|
|
17
|
+
--text-xs: .75rem; --text-sm: .875rem; --text-md: 1rem; --text-lg: 1.125rem; --text-xl: 1.5rem; --text-2xl: 2rem; --text-3xl: 2.75rem;
|
|
18
|
+
--space-1: .25rem; --space-2: .5rem; --space-3: .75rem; --space-4: 1rem; --space-5: 1.5rem; --space-6: 2rem; --space-7: 3rem; --space-8: 4rem;
|
|
19
|
+
--radius-sm: 8px; --radius-md: 12px; --radius-full: 999px;`;
|
|
20
|
+
// The select arrow is two gradients, because the case file allows no image, not even a data URL.
|
|
21
|
+
const components = (button) => `
|
|
22
|
+
:where(h1, h2, h3) { font-family: var(--font); color: var(--ink); letter-spacing: -.015em; line-height: 1.25; }
|
|
23
|
+
:where(h1) { font-size: var(--text-xl); font-weight: 700; }
|
|
24
|
+
:where(h2) { font-size: var(--text-lg); font-weight: 600; }
|
|
25
|
+
:where(h3) { font-size: var(--text-md); font-weight: 600; }
|
|
26
|
+
${button} { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: 2.5rem; padding: 0 var(--space-4); border: 1px solid var(--accent); border-radius: var(--radius-sm); background: var(--accent); color: var(--accent-ink); font: 600 var(--text-sm)/1.2 var(--font); text-decoration: none; white-space: nowrap; cursor: pointer; transition: background-color .15s, border-color .15s, color .15s; }
|
|
27
|
+
${button}:not(:disabled):hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
|
|
28
|
+
${button}:not(:disabled):active { background: var(--accent-active); border-color: var(--accent-active); }
|
|
29
|
+
${button}:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
30
|
+
${button}:disabled { opacity: .5; cursor: not-allowed; }
|
|
31
|
+
${button}:is(.quiet, .secondary) { background: transparent; border-color: var(--line-strong); color: var(--ink); }
|
|
32
|
+
${button}:is(.quiet, .secondary):not(:disabled):hover { background: var(--soft); border-color: var(--ink3); color: var(--ink); }
|
|
33
|
+
${button}:is(.quiet, .secondary):not(:disabled):active { background: var(--line); }
|
|
34
|
+
${button}.danger { background: var(--bad); border-color: var(--bad); color: var(--panel); }
|
|
35
|
+
${button}.danger:not(:disabled):hover { background: var(--bad); border-color: var(--bad); color: var(--panel); filter: brightness(1.1); }
|
|
36
|
+
${button}.icon { width: 2.25rem; min-height: 2.25rem; padding: 0; background: transparent; border-color: var(--line); color: var(--ink2); }
|
|
37
|
+
${button}.icon:not(:disabled):hover { background: var(--soft); border-color: var(--line-strong); color: var(--ink); }
|
|
38
|
+
${button}.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
|
|
39
|
+
select { appearance: none; min-height: 2.5rem; padding: 0 2.25rem 0 var(--space-3); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background-color: var(--panel); color: var(--ink); font: var(--text-sm) var(--font); cursor: pointer;
|
|
40
|
+
background-image: linear-gradient(45deg, transparent 50%, var(--ink2) 50%), linear-gradient(135deg, var(--ink2) 50%, transparent 50%);
|
|
41
|
+
background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
|
|
42
|
+
select:hover { border-color: var(--ink3); }
|
|
43
|
+
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
|
|
44
|
+
select:disabled { opacity: .5; cursor: not-allowed; }
|
|
45
|
+
:where(.card, .panel, dialog) { background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-md); }
|
|
46
|
+
:where(dialog) { padding: var(--space-5); box-shadow: var(--shadow); max-width: min(32rem, calc(100vw - 2rem)); }
|
|
47
|
+
:where(dialog)::backdrop { background: rgb(12 10 9 / .5); }
|
|
48
|
+
`;
|
|
49
|
+
const DARK_ON_SYSTEM = `@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { ${DARK} } }
|
|
50
|
+
:root[data-theme="dark"] { ${DARK} }`;
|
|
51
|
+
/** The app pages: the tokens, light and dark (system or data-theme), the base, and the shared components. */
|
|
52
|
+
export const DESIGN_CSS = `
|
|
53
|
+
:root { color-scheme: light dark; ${SCALE} ${LIGHT} }
|
|
54
|
+
${DARK_ON_SYSTEM}
|
|
55
|
+
:root[data-theme="light"] { color-scheme: light; } :root[data-theme="dark"] { color-scheme: dark; }
|
|
56
|
+
* { box-sizing: border-box; }
|
|
57
|
+
body { margin: 0; background: var(--bg); color: var(--ink); font: var(--text-sm)/1.5 var(--font); -webkit-font-smoothing: antialiased; }
|
|
58
|
+
a { color: var(--accent); text-underline-offset: 3px; }
|
|
59
|
+
:where(a, button, input, textarea):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
|
60
|
+
:where(code, pre, kbd, .mono) { font-family: var(--mono); }
|
|
61
|
+
:where(input:not([type="checkbox"], [type="radio"]), textarea) { min-height: 2.5rem; padding: var(--space-2) var(--space-3); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--panel); color: var(--ink); font: var(--text-sm) var(--font); }
|
|
62
|
+
:where(textarea) { font-family: var(--mono); }
|
|
63
|
+
${components(":where(.btn, button:not(.link, nav button))")}`;
|
|
64
|
+
/** The site: the same tokens and components; VitePress sets the dark class itself. */
|
|
65
|
+
export const SITE_CSS = `/* Generated from packages/receipts/src/design.ts. Do not edit; a test compares the two. */
|
|
66
|
+
:root { ${SCALE} ${LIGHT} }
|
|
67
|
+
.dark { ${DARK} }
|
|
68
|
+
${components(".btn")}`;
|
|
69
|
+
/** The logo: a receipt with a check mark. The tile takes the accent colour, so the mark follows the theme. */
|
|
70
|
+
export const LOGO_MARK = '<svg class="mark" viewBox="0 0 64 64" aria-hidden="true"><rect class="tile" width="64" height="64" rx="14"/><path d="M19 11H45V45L41.75 48 38.5 45 35.25 48 32 45 28.75 48 25.5 45 22.25 48 19 45Z" fill="#fff"/><path class="ink" d="M25 20h14M25 27h14" stroke-width="2.6" stroke-linecap="round"/><path class="ink" d="M25 37.5l5 4.5 9.5-10" fill="none" stroke-width="3.4" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
|
71
|
+
const THEME_BUTTON = '<button class="icon" id="themeToggle" type="button" aria-label="Dark mode" aria-pressed="false" title="Dark mode"><svg class="moon" viewBox="0 0 24 24" aria-hidden="true"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z"/></svg><svg class="sun" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg></button>';
|
|
72
|
+
/** The header of the review page and the case file: the logo, the name of the page, and the theme toggle. */
|
|
73
|
+
export const appHeader = (name) => `<header class="apphead"><a class="brand" href="https://agent-custody.dev/">${LOGO_MARK}agent-custody</a><span class="pill">${name}</span>${THEME_BUTTON}</header>`;
|
|
74
|
+
export const APP_HEADER_CSS = `
|
|
75
|
+
.apphead { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); background: var(--panel); }
|
|
76
|
+
.apphead .brand { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--ink); font-weight: 700; text-decoration: none; }
|
|
77
|
+
.apphead .pill { padding: 0 var(--space-2); border-radius: var(--radius-full); background: var(--accent-bg); color: var(--accent); font: 600 var(--text-xs)/1.6 var(--font); }
|
|
78
|
+
.apphead #themeToggle { margin-left: auto; }
|
|
79
|
+
.mark { width: 28px; height: 28px; display: block; } .mark .tile { fill: var(--accent); } .mark .ink { stroke: var(--accent); }
|
|
80
|
+
#themeToggle[aria-pressed="true"] .moon, #themeToggle[aria-pressed="false"] .sun { display: none; }
|
|
81
|
+
`;
|
|
82
|
+
/** Applies the saved theme and wires the toggle. It uses the storage key of the portal. Put it after the button. */
|
|
83
|
+
export const THEME_SCRIPT = `(() => {
|
|
84
|
+
const root = document.documentElement, button = document.getElementById("themeToggle");
|
|
85
|
+
try { const saved = localStorage.getItem("agent-custody-theme"); if (saved === "dark" || saved === "light") root.dataset.theme = saved; } catch {}
|
|
86
|
+
const now = () => root.dataset.theme || (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
|
|
87
|
+
const label = () => button.setAttribute("aria-pressed", String(now() === "dark"));
|
|
88
|
+
button.onclick = () => { const next = now() === "dark" ? "light" : "dark"; root.dataset.theme = next; try { localStorage.setItem("agent-custody-theme", next); } catch {} label(); };
|
|
89
|
+
label();
|
|
90
|
+
})();
|
|
91
|
+
`;
|