agent-recall-mcp 3.5.2 → 3.5.4
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 +254 -143
- package/dist/build-server.d.ts +28 -0
- package/dist/build-server.d.ts.map +1 -0
- package/dist/build-server.js +55 -0
- package/dist/build-server.js.map +1 -0
- package/dist/http/activity.d.ts +60 -0
- package/dist/http/activity.d.ts.map +1 -0
- package/dist/http/activity.js +254 -0
- package/dist/http/activity.js.map +1 -0
- package/dist/http/alerts.d.ts +84 -0
- package/dist/http/alerts.d.ts.map +1 -0
- package/dist/http/alerts.js +213 -0
- package/dist/http/alerts.js.map +1 -0
- package/dist/http/cli.d.ts +3 -0
- package/dist/http/cli.d.ts.map +1 -0
- package/dist/http/cli.js +515 -0
- package/dist/http/cli.js.map +1 -0
- package/dist/http/export-tar.d.ts +23 -0
- package/dist/http/export-tar.d.ts.map +1 -0
- package/dist/http/export-tar.js +264 -0
- package/dist/http/export-tar.js.map +1 -0
- package/dist/http/federation.d.ts +45 -0
- package/dist/http/federation.d.ts.map +1 -0
- package/dist/http/federation.js +185 -0
- package/dist/http/federation.js.map +1 -0
- package/dist/http/film/film.css +80 -0
- package/dist/http/film/film.js +446 -0
- package/dist/http/film/human.jpg +0 -0
- package/dist/http/film/m0.jpg +0 -0
- package/dist/http/film/m2.jpg +0 -0
- package/dist/http/film/m3.jpg +0 -0
- package/dist/http/film/wrong.jpg +0 -0
- package/dist/http/film.d.ts +16 -0
- package/dist/http/film.d.ts.map +1 -0
- package/dist/http/film.js +119 -0
- package/dist/http/film.js.map +1 -0
- package/dist/http/home/cabinet.svg +1 -0
- package/dist/http/home/drawer-project.svg +1 -0
- package/dist/http/home/drawer-rules.svg +1 -0
- package/dist/http/home/drawer-you.svg +1 -0
- package/dist/http/home/fig1.svg +242 -0
- package/dist/http/home/fig2-1.svg +61 -0
- package/dist/http/home/fig2-2.svg +92 -0
- package/dist/http/home/fig3.svg +1 -0
- package/dist/http/home/home.css +509 -0
- package/dist/http/home/home.html +517 -0
- package/dist/http/home/icons.svg +15 -0
- package/dist/http/home.d.ts +23 -0
- package/dist/http/home.d.ts.map +1 -0
- package/dist/http/home.js +295 -0
- package/dist/http/home.js.map +1 -0
- package/dist/http/identities.d.ts +29 -0
- package/dist/http/identities.d.ts.map +1 -0
- package/dist/http/identities.js +91 -0
- package/dist/http/identities.js.map +1 -0
- package/dist/http/import-memory.d.ts +161 -0
- package/dist/http/import-memory.d.ts.map +1 -0
- package/dist/http/import-memory.js +718 -0
- package/dist/http/import-memory.js.map +1 -0
- package/dist/http/jsonfile.d.ts +6 -0
- package/dist/http/jsonfile.d.ts.map +1 -0
- package/dist/http/jsonfile.js +60 -0
- package/dist/http/jsonfile.js.map +1 -0
- package/dist/http/legal/PRIVACY.md +70 -0
- package/dist/http/legal.d.ts +10 -0
- package/dist/http/legal.d.ts.map +1 -0
- package/dist/http/legal.js +35 -0
- package/dist/http/legal.js.map +1 -0
- package/dist/http/limits.d.ts +59 -0
- package/dist/http/limits.d.ts.map +1 -0
- package/dist/http/limits.js +163 -0
- package/dist/http/limits.js.map +1 -0
- package/dist/http/markdown-lite.d.ts +2 -0
- package/dist/http/markdown-lite.d.ts.map +1 -0
- package/dist/http/markdown-lite.js +86 -0
- package/dist/http/markdown-lite.js.map +1 -0
- package/dist/http/multipart.d.ts +43 -0
- package/dist/http/multipart.d.ts.map +1 -0
- package/dist/http/multipart.js +152 -0
- package/dist/http/multipart.js.map +1 -0
- package/dist/http/oauth-app.d.ts +75 -0
- package/dist/http/oauth-app.d.ts.map +1 -0
- package/dist/http/oauth-app.js +259 -0
- package/dist/http/oauth-app.js.map +1 -0
- package/dist/http/oauth-config.d.ts +46 -0
- package/dist/http/oauth-config.d.ts.map +1 -0
- package/dist/http/oauth-config.js +122 -0
- package/dist/http/oauth-config.js.map +1 -0
- package/dist/http/oauth-pages.d.ts +40 -0
- package/dist/http/oauth-pages.d.ts.map +1 -0
- package/dist/http/oauth-pages.js +97 -0
- package/dist/http/oauth-pages.js.map +1 -0
- package/dist/http/oauth-provider.d.ts +124 -0
- package/dist/http/oauth-provider.d.ts.map +1 -0
- package/dist/http/oauth-provider.js +486 -0
- package/dist/http/oauth-provider.js.map +1 -0
- package/dist/http/oauth-store.d.ts +128 -0
- package/dist/http/oauth-store.d.ts.map +1 -0
- package/dist/http/oauth-store.js +317 -0
- package/dist/http/oauth-store.js.map +1 -0
- package/dist/http/redirect-policy.d.ts +16 -0
- package/dist/http/redirect-policy.d.ts.map +1 -0
- package/dist/http/redirect-policy.js +83 -0
- package/dist/http/redirect-policy.js.map +1 -0
- package/dist/http/review-pages.d.ts +39 -0
- package/dist/http/review-pages.d.ts.map +1 -0
- package/dist/http/review-pages.js +78 -0
- package/dist/http/review-pages.js.map +1 -0
- package/dist/http/review.d.ts +36 -0
- package/dist/http/review.d.ts.map +1 -0
- package/dist/http/review.js +220 -0
- package/dist/http/review.js.map +1 -0
- package/dist/http/serve.d.ts +58 -0
- package/dist/http/serve.d.ts.map +1 -0
- package/dist/http/serve.js +324 -0
- package/dist/http/serve.js.map +1 -0
- package/dist/http/site-pages.d.ts +110 -0
- package/dist/http/site-pages.d.ts.map +1 -0
- package/dist/http/site-pages.js +630 -0
- package/dist/http/site-pages.js.map +1 -0
- package/dist/http/site-theme.d.ts +13 -0
- package/dist/http/site-theme.d.ts.map +1 -0
- package/dist/http/site-theme.js +22 -0
- package/dist/http/site-theme.js.map +1 -0
- package/dist/http/site.d.ts +52 -0
- package/dist/http/site.d.ts.map +1 -0
- package/dist/http/site.js +353 -0
- package/dist/http/site.js.map +1 -0
- package/dist/http/stats.d.ts +139 -0
- package/dist/http/stats.d.ts.map +1 -0
- package/dist/http/stats.js +599 -0
- package/dist/http/stats.js.map +1 -0
- package/dist/http/tar-import.d.ts +69 -0
- package/dist/http/tar-import.d.ts.map +1 -0
- package/dist/http/tar-import.js +234 -0
- package/dist/http/tar-import.js.map +1 -0
- package/dist/http/tenant-paths.d.ts +14 -0
- package/dist/http/tenant-paths.d.ts.map +1 -0
- package/dist/http/tenant-paths.js +42 -0
- package/dist/http/tenant-paths.js.map +1 -0
- package/dist/http/tokens.d.ts +32 -0
- package/dist/http/tokens.d.ts.map +1 -0
- package/dist/http/tokens.js +137 -0
- package/dist/http/tokens.js.map +1 -0
- package/dist/http/trial.d.ts +55 -0
- package/dist/http/trial.d.ts.map +1 -0
- package/dist/http/trial.js +218 -0
- package/dist/http/trial.js.map +1 -0
- package/dist/http/web-session.d.ts +108 -0
- package/dist/http/web-session.d.ts.map +1 -0
- package/dist/http/web-session.js +267 -0
- package/dist/http/web-session.js.map +1 -0
- package/dist/index.js +12 -65
- package/dist/index.js.map +1 -1
- package/dist/lib/ambient-capture.d.ts.map +1 -1
- package/dist/lib/ambient-capture.js +4 -1
- package/dist/lib/ambient-capture.js.map +1 -1
- package/dist/lib/bookkeeping.d.ts +26 -0
- package/dist/lib/bookkeeping.d.ts.map +1 -0
- package/dist/lib/bookkeeping.js +31 -0
- package/dist/lib/bookkeeping.js.map +1 -0
- package/dist/lib/hosted-redact.d.ts +17 -0
- package/dist/lib/hosted-redact.d.ts.map +1 -0
- package/dist/lib/hosted-redact.js +57 -0
- package/dist/lib/hosted-redact.js.map +1 -0
- package/dist/lib/lifecycle-exit.d.ts +5 -13
- package/dist/lib/lifecycle-exit.d.ts.map +1 -1
- package/dist/lib/lifecycle-exit.js +38 -16
- package/dist/lib/lifecycle-exit.js.map +1 -1
- package/dist/server.d.ts +3 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -3
- package/dist/server.js.map +1 -1
- package/dist/tools/annotations.d.ts +65 -0
- package/dist/tools/annotations.d.ts.map +1 -0
- package/dist/tools/annotations.js +4 -0
- package/dist/tools/annotations.js.map +1 -0
- package/dist/tools/check-action.d.ts.map +1 -1
- package/dist/tools/check-action.js +2 -0
- package/dist/tools/check-action.js.map +1 -1
- package/dist/tools/check.d.ts.map +1 -1
- package/dist/tools/check.js +6 -2
- package/dist/tools/check.js.map +1 -1
- package/dist/tools/digest.d.ts.map +1 -1
- package/dist/tools/digest.js +2 -0
- package/dist/tools/digest.js.map +1 -1
- package/dist/tools/pipeline-close.d.ts.map +1 -1
- package/dist/tools/pipeline-close.js +2 -0
- package/dist/tools/pipeline-close.js.map +1 -1
- package/dist/tools/pipeline-current.d.ts.map +1 -1
- package/dist/tools/pipeline-current.js +2 -0
- package/dist/tools/pipeline-current.js.map +1 -1
- package/dist/tools/pipeline-list.d.ts.map +1 -1
- package/dist/tools/pipeline-list.js +2 -0
- package/dist/tools/pipeline-list.js.map +1 -1
- package/dist/tools/pipeline-open.d.ts.map +1 -1
- package/dist/tools/pipeline-open.js +2 -0
- package/dist/tools/pipeline-open.js.map +1 -1
- package/dist/tools/pipeline-show.d.ts.map +1 -1
- package/dist/tools/pipeline-show.js +2 -0
- package/dist/tools/pipeline-show.js.map +1 -1
- package/dist/tools/recall.d.ts.map +1 -1
- package/dist/tools/recall.js +4 -1
- package/dist/tools/recall.js.map +1 -1
- package/dist/tools/register-rule.d.ts.map +1 -1
- package/dist/tools/register-rule.js +2 -0
- package/dist/tools/register-rule.js.map +1 -1
- package/dist/tools/remember.d.ts.map +1 -1
- package/dist/tools/remember.js +10 -1
- package/dist/tools/remember.js.map +1 -1
- package/dist/tools/session-end.d.ts +15 -0
- package/dist/tools/session-end.d.ts.map +1 -1
- package/dist/tools/session-end.js +13 -1
- package/dist/tools/session-end.js.map +1 -1
- package/dist/tools/session-start.d.ts +6 -1
- package/dist/tools/session-start.d.ts.map +1 -1
- package/dist/tools/session-start.js +24 -212
- package/dist/tools/session-start.js.map +1 -1
- package/package.json +11 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-store.d.ts","sourceRoot":"","sources":["../../src/http/oauth-store.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AAI3F,eAAO,MAAM,aAAa,QAAiB,CAAC;AA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EAAE,MAAM,GAAG,OAAO;IAOpD,6GAA6G;IAC7G,OAAO,CAAC,MAAM;IAgBd,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa;IAiBpE,qHAAqH;IACrH,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;CAYnD"}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oauth-store.ts — persistent OAuth state for the hosted server.
|
|
3
|
+
*
|
|
4
|
+
* oauth-clients.json registered clients (server writes; cap 5 000, oldest unused pruned first)
|
|
5
|
+
* oauth-grants.json grants + token hashes (server writes; SHA-256 hashes only, never plaintext)
|
|
6
|
+
* oauth-revoked.json operator revocations (CLI writes; read per request, mtime-cached)
|
|
7
|
+
*
|
|
8
|
+
* Token formats: access `aro_` + 32 random bytes (1 h), refresh `arr_` + 32 random
|
|
9
|
+
* bytes (30 d, rotated on every use). Presenting an already-rotated refresh token
|
|
10
|
+
* revokes the whole grant (theft signal), except the most recently rotated one by the
|
|
11
|
+
* same client inside a short grace window (a lost /token response is not theft).
|
|
12
|
+
* All expiries are compared against Date.now() at check time (or the injected clock).
|
|
13
|
+
*
|
|
14
|
+
* Every change is written to disk FIRST and only then applied in memory: a failed
|
|
15
|
+
* write (EPERM from an antivirus lock, ENOSPC) leaves memory exactly as on disk, so
|
|
16
|
+
* a client's retry with the same token still works.
|
|
17
|
+
*/
|
|
18
|
+
import * as path from "node:path";
|
|
19
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
20
|
+
import { readJsonCached, readJsonFresh, writeJsonAtomic } from "./jsonfile.js";
|
|
21
|
+
import { UID_RE } from "./tokens.js";
|
|
22
|
+
export const ACCESS_TTL_MS = 60 * 60 * 1000;
|
|
23
|
+
export const REFRESH_TTL_MS = 30 * 24 * 60 * 60 * 1000;
|
|
24
|
+
export const MAX_CLIENTS = 5000;
|
|
25
|
+
const CLIENT_TOUCH_MS = 60 * 60 * 1000;
|
|
26
|
+
/** A grant dies this long after sign-in no matter how often it is refreshed. */
|
|
27
|
+
export const ABSOLUTE_GRANT_TTL_MS = 90 * 24 * 60 * 60 * 1000;
|
|
28
|
+
const MAX_ACCESS_PER_GRANT = 8;
|
|
29
|
+
const MAX_ROTATED_PER_GRANT = 50;
|
|
30
|
+
const REVOKED_GRANT_KEEP_MS = 30 * 24 * 60 * 60 * 1000;
|
|
31
|
+
/** Live grants per uid (one per signed-in client/device); a new sign-in evicts the oldest beyond this. */
|
|
32
|
+
export const MAX_GRANTS_PER_UID = 20;
|
|
33
|
+
/** The just-rotated refresh token still works this long, for the same client only. */
|
|
34
|
+
export const REFRESH_GRACE_MS = 10 * 1000;
|
|
35
|
+
const ACCESS_RE = /^aro_[A-Za-z0-9_-]{43}$/;
|
|
36
|
+
const REFRESH_RE = /^arr_[A-Za-z0-9_-]{43}$/;
|
|
37
|
+
export function sha256Hex(s) {
|
|
38
|
+
return createHash("sha256").update(s, "utf-8").digest("hex");
|
|
39
|
+
}
|
|
40
|
+
const parseClients = (raw) => {
|
|
41
|
+
const f = raw;
|
|
42
|
+
return f?.version === 1 && Array.isArray(f.clients) ? f : null;
|
|
43
|
+
};
|
|
44
|
+
const parseGrants = (raw) => {
|
|
45
|
+
const f = raw;
|
|
46
|
+
return f?.version === 1 && Array.isArray(f.grants) ? f : null;
|
|
47
|
+
};
|
|
48
|
+
export const parseRevoked = (raw) => {
|
|
49
|
+
const f = raw;
|
|
50
|
+
const isMap = (m) => typeof m === "object" && m !== null && !Array.isArray(m);
|
|
51
|
+
return f?.version === 1 && isMap(f.grants) && isMap(f.uids) ? f : null;
|
|
52
|
+
};
|
|
53
|
+
export const emptyRevoked = () => ({ version: 1, grants: {}, uids: {} });
|
|
54
|
+
const serverDir = (dataDir) => path.join(dataDir, "_server");
|
|
55
|
+
export const revokedPath = (dataDir) => path.join(serverDir(dataDir), "oauth-revoked.json");
|
|
56
|
+
// ---- operator revocations (CLI is the only writer) -------------------------
|
|
57
|
+
export function readGrantsFresh(dataDir) {
|
|
58
|
+
return readJsonFresh(path.join(serverDir(dataDir), "oauth-grants.json"), parseGrants, () => ({ version: 1, grants: [] })).grants;
|
|
59
|
+
}
|
|
60
|
+
export function operatorRevokeGrant(dataDir, grantId) {
|
|
61
|
+
if (!readGrantsFresh(dataDir).some((g) => g.id === grantId))
|
|
62
|
+
return false;
|
|
63
|
+
const f = readJsonFresh(revokedPath(dataDir), parseRevoked, emptyRevoked);
|
|
64
|
+
f.grants[grantId] = new Date().toISOString();
|
|
65
|
+
writeJsonAtomic(revokedPath(dataDir), f);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
export function readJsonFreshRevoked(dataDir) {
|
|
69
|
+
return readJsonFresh(revokedPath(dataDir), parseRevoked, emptyRevoked);
|
|
70
|
+
}
|
|
71
|
+
/** Revokes every grant of `uid` created up to now; sign-ins afterwards work normally. */
|
|
72
|
+
export function operatorRevokeUid(dataDir, uid) {
|
|
73
|
+
if (!UID_RE.test(uid))
|
|
74
|
+
throw new Error(`invalid uid "${uid}"`);
|
|
75
|
+
const f = readJsonFresh(revokedPath(dataDir), parseRevoked, emptyRevoked);
|
|
76
|
+
f.uids[uid] = new Date().toISOString();
|
|
77
|
+
writeJsonAtomic(revokedPath(dataDir), f);
|
|
78
|
+
}
|
|
79
|
+
export class OAuthStore {
|
|
80
|
+
dataDir;
|
|
81
|
+
now;
|
|
82
|
+
write;
|
|
83
|
+
clients = new Map();
|
|
84
|
+
grants = [];
|
|
85
|
+
byAccess = new Map();
|
|
86
|
+
byRefresh = new Map();
|
|
87
|
+
byRotated = new Map();
|
|
88
|
+
clientsPath;
|
|
89
|
+
grantsPath;
|
|
90
|
+
constructor(dataDir, now = Date.now,
|
|
91
|
+
/** Test seam: the file writer (default atomic tmp + rename). */
|
|
92
|
+
write = writeJsonAtomic) {
|
|
93
|
+
this.dataDir = dataDir;
|
|
94
|
+
this.now = now;
|
|
95
|
+
this.write = write;
|
|
96
|
+
this.clientsPath = path.join(serverDir(dataDir), "oauth-clients.json");
|
|
97
|
+
this.grantsPath = path.join(serverDir(dataDir), "oauth-grants.json");
|
|
98
|
+
// Fail closed on a corrupt file: starting empty would let the next write destroy every grant.
|
|
99
|
+
for (const c of readJsonFresh(this.clientsPath, parseClients, () => ({ version: 1, clients: [] })).clients) {
|
|
100
|
+
if (typeof c?.client_id === "string")
|
|
101
|
+
this.clients.set(c.client_id, c);
|
|
102
|
+
}
|
|
103
|
+
this.grants = readJsonFresh(this.grantsPath, parseGrants, () => ({ version: 1, grants: [] })).grants;
|
|
104
|
+
this.reindex();
|
|
105
|
+
}
|
|
106
|
+
// ---- clients ----
|
|
107
|
+
getClient(id) {
|
|
108
|
+
return this.clients.get(id);
|
|
109
|
+
}
|
|
110
|
+
addClient(client) {
|
|
111
|
+
const next = new Map(this.clients);
|
|
112
|
+
if (next.size >= MAX_CLIENTS)
|
|
113
|
+
pruneOneClient(next);
|
|
114
|
+
next.set(client.client_id, client);
|
|
115
|
+
this.commitClients(next);
|
|
116
|
+
}
|
|
117
|
+
touchClient(id) {
|
|
118
|
+
const c = this.clients.get(id);
|
|
119
|
+
if (!c)
|
|
120
|
+
return;
|
|
121
|
+
const t = this.now();
|
|
122
|
+
if (c.last_used_at !== undefined && t - c.last_used_at < CLIENT_TOUCH_MS)
|
|
123
|
+
return; // persist at most once per client per hour
|
|
124
|
+
const next = new Map(this.clients);
|
|
125
|
+
next.set(id, { ...c, last_used_at: t });
|
|
126
|
+
this.commitClients(next);
|
|
127
|
+
}
|
|
128
|
+
clientCount() {
|
|
129
|
+
return this.clients.size;
|
|
130
|
+
}
|
|
131
|
+
/** Write, then swap: a failed write leaves the in-memory clients as on disk. */
|
|
132
|
+
commitClients(next) {
|
|
133
|
+
this.write(this.clientsPath, { version: 1, clients: [...next.values()] });
|
|
134
|
+
this.clients = next;
|
|
135
|
+
}
|
|
136
|
+
// ---- grants & tokens ----
|
|
137
|
+
reindex() {
|
|
138
|
+
this.byAccess.clear();
|
|
139
|
+
this.byRefresh.clear();
|
|
140
|
+
this.byRotated.clear();
|
|
141
|
+
for (const g of this.grants) {
|
|
142
|
+
for (const a of g.access)
|
|
143
|
+
this.byAccess.set(a.hash, g);
|
|
144
|
+
this.byRefresh.set(g.refresh.hash, g);
|
|
145
|
+
for (const r of g.rotated)
|
|
146
|
+
this.byRotated.set(r, g);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Prune `next` (expired grants, old revoked ones, expired access tokens) WITHOUT touching
|
|
151
|
+
* any grant object that is live in memory, write it, and only then make it current.
|
|
152
|
+
*/
|
|
153
|
+
commitGrants(next) {
|
|
154
|
+
const t = this.now();
|
|
155
|
+
const kept = next
|
|
156
|
+
.filter((g) => (g.revoked_at ? t - Date.parse(g.revoked_at) < REVOKED_GRANT_KEEP_MS : g.refresh.exp > t))
|
|
157
|
+
.map((g) => {
|
|
158
|
+
const access = g.access.filter((a) => a.exp > t).slice(-MAX_ACCESS_PER_GRANT);
|
|
159
|
+
return access.length === g.access.length ? g : { ...g, access };
|
|
160
|
+
});
|
|
161
|
+
this.write(this.grantsPath, { version: 1, grants: kept });
|
|
162
|
+
this.grants = kept;
|
|
163
|
+
this.reindex();
|
|
164
|
+
}
|
|
165
|
+
replaceGrant(old, updated) {
|
|
166
|
+
this.commitGrants(this.grants.map((g) => (g === old ? updated : g)));
|
|
167
|
+
}
|
|
168
|
+
newAccess() {
|
|
169
|
+
const token = "aro_" + randomBytes(32).toString("base64url");
|
|
170
|
+
return { token, entry: { hash: sha256Hex(token), exp: this.now() + ACCESS_TTL_MS } };
|
|
171
|
+
}
|
|
172
|
+
hasGrantForUid(uid) {
|
|
173
|
+
return this.grants.some((g) => g.uid === uid);
|
|
174
|
+
}
|
|
175
|
+
createGrant(p) {
|
|
176
|
+
const t = this.now();
|
|
177
|
+
let id;
|
|
178
|
+
do {
|
|
179
|
+
id = randomBytes(6).toString("hex");
|
|
180
|
+
} while (this.grants.some((g) => g.id === id));
|
|
181
|
+
const refreshToken = "arr_" + randomBytes(32).toString("base64url");
|
|
182
|
+
const access = this.newAccess();
|
|
183
|
+
const grant = {
|
|
184
|
+
id,
|
|
185
|
+
uid: p.uid,
|
|
186
|
+
client_id: p.clientId,
|
|
187
|
+
resource: p.resource,
|
|
188
|
+
created_at: new Date(t).toISOString(),
|
|
189
|
+
access: [access.entry],
|
|
190
|
+
refresh: { hash: sha256Hex(refreshToken), exp: t + REFRESH_TTL_MS },
|
|
191
|
+
rotated: [],
|
|
192
|
+
};
|
|
193
|
+
// Bound grants per uid (live AND revoked, so sign-in + revoke loops are bounded too): one account
|
|
194
|
+
// signing in again and again evicts its own oldest grants, so the grants file (rewritten on every
|
|
195
|
+
// change) cannot grow without limit. An evicted revoked grant only loses its reuse-detection record.
|
|
196
|
+
const at = (g) => Date.parse(g.created_at) || 0; // a corrupt date sorts first instead of breaking the order
|
|
197
|
+
const own = this.grants.filter((g) => g.uid === p.uid).sort((a, b) => at(a) - at(b));
|
|
198
|
+
const evict = new Set(own.slice(0, Math.max(0, own.length - (MAX_GRANTS_PER_UID - 1))));
|
|
199
|
+
this.commitGrants([...this.grants.filter((g) => !evict.has(g)), grant]);
|
|
200
|
+
return { access_token: access.token, refresh_token: refreshToken, expires_in: ACCESS_TTL_MS / 1000 };
|
|
201
|
+
}
|
|
202
|
+
/** Operator revocations, re-read (mtime-cached) on every check so the CLI takes effect at once. */
|
|
203
|
+
operatorRevoked(g) {
|
|
204
|
+
const r = readJsonCached(revokedPath(this.dataDir), parseRevoked, emptyRevoked);
|
|
205
|
+
if (r.grants[g.id] !== undefined)
|
|
206
|
+
return true;
|
|
207
|
+
const uidAt = r.uids[g.uid];
|
|
208
|
+
return uidAt !== undefined && Date.parse(g.created_at) <= Date.parse(uidAt);
|
|
209
|
+
}
|
|
210
|
+
live(g) {
|
|
211
|
+
// Absolute lifetime: refreshing never extends a grant past 90 days (the user signs in again).
|
|
212
|
+
if (Date.parse(g.created_at) + ABSOLUTE_GRANT_TTL_MS <= this.now())
|
|
213
|
+
return false;
|
|
214
|
+
return !g.revoked_at && !this.operatorRevoked(g);
|
|
215
|
+
}
|
|
216
|
+
/** Access token → uid/client/resource, or null (unknown, expired, revoked, wrong audience). */
|
|
217
|
+
resolveAccess(token) {
|
|
218
|
+
if (!ACCESS_RE.test(token))
|
|
219
|
+
return null;
|
|
220
|
+
const h = sha256Hex(token);
|
|
221
|
+
const g = this.byAccess.get(h);
|
|
222
|
+
if (!g || !this.live(g))
|
|
223
|
+
return null;
|
|
224
|
+
const entry = g.access.find((a) => a.hash === h);
|
|
225
|
+
if (!entry || entry.exp <= this.now())
|
|
226
|
+
return null;
|
|
227
|
+
if (!UID_RE.test(g.uid))
|
|
228
|
+
return null;
|
|
229
|
+
return { uid: g.uid, grantId: g.id, clientId: g.client_id, resource: g.resource, expiresAt: entry.exp };
|
|
230
|
+
}
|
|
231
|
+
/** The live (not revoked, not expired) grants of `uid`, newest first, for the owner's connections list. Never includes token material. */
|
|
232
|
+
liveGrantsOf(uid) {
|
|
233
|
+
const t = this.now();
|
|
234
|
+
return this.grants
|
|
235
|
+
.filter((g) => g.uid === uid && this.live(g) && g.refresh.exp > t)
|
|
236
|
+
.sort((a, b) => (Date.parse(b.created_at) || 0) - (Date.parse(a.created_at) || 0))
|
|
237
|
+
.map((g) => {
|
|
238
|
+
const c = this.clients.get(g.client_id);
|
|
239
|
+
return {
|
|
240
|
+
id: g.id,
|
|
241
|
+
clientName: c?.client_name ?? "unnamed app",
|
|
242
|
+
createdAt: g.created_at,
|
|
243
|
+
lastUsedAt: c?.last_used_at === undefined ? undefined : new Date(c.last_used_at).toISOString(),
|
|
244
|
+
};
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/** The owner disconnects one of THEIR grants. A grant id that does not exist or belongs to another uid changes nothing. */
|
|
248
|
+
revokeGrantOf(uid, grantId) {
|
|
249
|
+
const g = this.grants.find((x) => x.id === grantId && x.uid === uid);
|
|
250
|
+
if (!g || g.revoked_at)
|
|
251
|
+
return false;
|
|
252
|
+
this.replaceGrant(g, { ...g, revoked_at: new Date(this.now()).toISOString() });
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
/** Issue a new refresh + access token for `g`. `grace` = whether this rotation starts a new grace window. */
|
|
256
|
+
rotate(g, startGrace) {
|
|
257
|
+
const t = this.now();
|
|
258
|
+
const next = "arr_" + randomBytes(32).toString("base64url");
|
|
259
|
+
const access = this.newAccess();
|
|
260
|
+
const updated = {
|
|
261
|
+
...g,
|
|
262
|
+
rotated: [...g.rotated, g.refresh.hash].slice(-MAX_ROTATED_PER_GRANT),
|
|
263
|
+
refresh: { hash: sha256Hex(next), exp: Math.min(t + REFRESH_TTL_MS, Date.parse(g.created_at) + ABSOLUTE_GRANT_TTL_MS) },
|
|
264
|
+
access: [...g.access, access.entry],
|
|
265
|
+
// One retry per rotation: a grace use clears the window, so a stolen old token cannot keep minting tokens.
|
|
266
|
+
grace: startGrace ? { hash: g.refresh.hash, until: t + REFRESH_GRACE_MS } : undefined,
|
|
267
|
+
};
|
|
268
|
+
this.replaceGrant(g, updated);
|
|
269
|
+
return { type: "ok", grant: updated, tokens: { access_token: access.token, refresh_token: next, expires_in: ACCESS_TTL_MS / 1000 } };
|
|
270
|
+
}
|
|
271
|
+
rotateRefresh(clientId, refreshToken) {
|
|
272
|
+
if (!REFRESH_RE.test(refreshToken))
|
|
273
|
+
return { type: "invalid" };
|
|
274
|
+
const h = sha256Hex(refreshToken);
|
|
275
|
+
const stale = this.byRotated.get(h);
|
|
276
|
+
if (stale) {
|
|
277
|
+
if (stale.client_id !== clientId)
|
|
278
|
+
return { type: "invalid" };
|
|
279
|
+
const t = this.now();
|
|
280
|
+
// The client never got the response to its last refresh: same token again, inside the window.
|
|
281
|
+
if (stale.grace?.hash === h && t < stale.grace.until && this.live(stale) && stale.refresh.exp > t)
|
|
282
|
+
return this.rotate(stale, false);
|
|
283
|
+
if (!stale.revoked_at)
|
|
284
|
+
this.replaceGrant(stale, { ...stale, revoked_at: new Date(t).toISOString() });
|
|
285
|
+
return { type: "reuse", grantId: stale.id };
|
|
286
|
+
}
|
|
287
|
+
const g = this.byRefresh.get(h);
|
|
288
|
+
if (!g || g.client_id !== clientId || !this.live(g) || g.refresh.exp <= this.now())
|
|
289
|
+
return { type: "invalid" };
|
|
290
|
+
return this.rotate(g, true);
|
|
291
|
+
}
|
|
292
|
+
/** RFC 7009: unknown/foreign tokens are ignored silently. Refresh token → whole grant; access token → that token. */
|
|
293
|
+
revokeToken(clientId, token) {
|
|
294
|
+
const h = sha256Hex(token);
|
|
295
|
+
const byRefresh = this.byRefresh.get(h);
|
|
296
|
+
if (byRefresh && byRefresh.client_id === clientId) {
|
|
297
|
+
if (!byRefresh.revoked_at)
|
|
298
|
+
this.replaceGrant(byRefresh, { ...byRefresh, revoked_at: new Date(this.now()).toISOString() });
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const byAccess = this.byAccess.get(h);
|
|
302
|
+
if (byAccess && byAccess.client_id === clientId) {
|
|
303
|
+
this.replaceGrant(byAccess, { ...byAccess, access: byAccess.access.filter((a) => a.hash !== h) });
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/** Oldest never-used client first; if every client has been used, the least recently used. */
|
|
308
|
+
function pruneOneClient(clients) {
|
|
309
|
+
let victim;
|
|
310
|
+
const rank = (c) => (c.last_used_at === undefined ? 0 : 1) * 1e15 + (c.last_used_at ?? (c.client_id_issued_at ?? 0) * 1000);
|
|
311
|
+
for (const c of clients.values())
|
|
312
|
+
if (!victim || rank(c) < rank(victim))
|
|
313
|
+
victim = c;
|
|
314
|
+
if (victim)
|
|
315
|
+
clients.delete(victim.client_id);
|
|
316
|
+
}
|
|
317
|
+
//# sourceMappingURL=oauth-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-store.js","sourceRoot":"","sources":["../../src/http/oauth-store.ts"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AAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,CAAC,mBAAmB,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1I,KAAK,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,EAAE;QAAE,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;YAAE,MAAM,GAAG,CAAC,CAAC;IACpF,IAAI,MAAM;QAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* redirect-policy.ts — which redirect_uri values a client may register/use.
|
|
3
|
+
*
|
|
4
|
+
* Open dynamic registration + arbitrary redirects would let anyone phish a
|
|
5
|
+
* user's memory token, so only these are allowed:
|
|
6
|
+
* - loopback (RFC 8252): http://127.0.0.1:*, http://localhost:*, http://[::1]:*
|
|
7
|
+
* - https://claude.ai/api/mcp/auth_callback and https://claude.com/api/mcp/auth_callback
|
|
8
|
+
* - ChatGPT's two MCP OAuth callbacks (see CHATGPT below)
|
|
9
|
+
* - operator-listed prefixes (AR_OAUTH_REDIRECT_ALLOW)
|
|
10
|
+
* Never allowed, whatever the allow-list says: fragments, userinfo, whitespace/
|
|
11
|
+
* control chars/backslashes, javascript:/data:/file:/blob:/vbscript: schemes.
|
|
12
|
+
*/
|
|
13
|
+
/** Custom-scheme native apps that are allowed out of the box (PKCE protects the code). */
|
|
14
|
+
export declare const DEFAULT_REDIRECT_PREFIXES: readonly string[];
|
|
15
|
+
export declare function isAllowedRedirect(uri: unknown, extraPrefixes?: readonly string[]): boolean;
|
|
16
|
+
//# sourceMappingURL=redirect-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirect-policy.d.ts","sourceRoot":"","sources":["../../src/http/redirect-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAkBH,0FAA0F;AAC1F,eAAO,MAAM,yBAAyB,EAAE,SAAS,MAAM,EAA6C,CAAC;AAyBrG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,aAAa,GAAE,SAAS,MAAM,EAAO,GAAG,OAAO,CAqB9F"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* redirect-policy.ts — which redirect_uri values a client may register/use.
|
|
3
|
+
*
|
|
4
|
+
* Open dynamic registration + arbitrary redirects would let anyone phish a
|
|
5
|
+
* user's memory token, so only these are allowed:
|
|
6
|
+
* - loopback (RFC 8252): http://127.0.0.1:*, http://localhost:*, http://[::1]:*
|
|
7
|
+
* - https://claude.ai/api/mcp/auth_callback and https://claude.com/api/mcp/auth_callback
|
|
8
|
+
* - ChatGPT's two MCP OAuth callbacks (see CHATGPT below)
|
|
9
|
+
* - operator-listed prefixes (AR_OAUTH_REDIRECT_ALLOW)
|
|
10
|
+
* Never allowed, whatever the allow-list says: fragments, userinfo, whitespace/
|
|
11
|
+
* control chars/backslashes, javascript:/data:/file:/blob:/vbscript: schemes.
|
|
12
|
+
*/
|
|
13
|
+
const LOOPBACK = new Set(["127.0.0.1", "localhost", "[::1]"]);
|
|
14
|
+
const FIXED = new Set([
|
|
15
|
+
"https://claude.ai/api/mcp/auth_callback",
|
|
16
|
+
"https://claude.com/api/mcp/auth_callback",
|
|
17
|
+
// CHATGPT: the stable callback. OpenAI, Apps SDK "Authentication" (https://developers.openai.com/apps-sdk/build/auth):
|
|
18
|
+
// "https://chatgpt.com/connector_platform_oauth_redirect" is used by servers that return `iss` on every authorization response
|
|
19
|
+
// (and by servers published before callback-ID redirects).
|
|
20
|
+
"https://chatgpt.com/connector_platform_oauth_redirect",
|
|
21
|
+
]);
|
|
22
|
+
// CHATGPT: the per-connector callback, same doc: "https://chatgpt.com/connector/oauth/{callback_id}". The id is only shown
|
|
23
|
+
// on the connector's management page, so it is matched as one path segment (no query, no further path).
|
|
24
|
+
const CHATGPT_CALLBACK_ID = /^\/connector\/oauth\/[A-Za-z0-9_-]{1,128}$/;
|
|
25
|
+
const FORBIDDEN_SCHEMES = new Set(["javascript:", "data:", "file:", "blob:", "vbscript:", "about:"]);
|
|
26
|
+
// eslint-disable-next-line no-control-regex
|
|
27
|
+
const BAD_CHARS = /[\s\u0000-\u001f\u007f\\]/;
|
|
28
|
+
/** Custom-scheme native apps that are allowed out of the box (PKCE protects the code). */
|
|
29
|
+
export const DEFAULT_REDIRECT_PREFIXES = ["cursor://anysphere.cursor-retrieval/"];
|
|
30
|
+
/** Encoded dots/slashes/backslashes or dot segments could slip past a prefix check (…/cb/%2e%2e/admin). */
|
|
31
|
+
function hasPathTricks(raw) {
|
|
32
|
+
if (/%2e|%2f|%5c/i.test(raw))
|
|
33
|
+
return true;
|
|
34
|
+
const afterAuthority = raw.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/?]*/i, "");
|
|
35
|
+
const pathOnly = afterAuthority.split("?")[0];
|
|
36
|
+
return pathOnly.split("/").some((seg) => seg === "." || seg === "..");
|
|
37
|
+
}
|
|
38
|
+
/** A prefix matches only at a URL boundary, so https://a.com never matches https://a.com.evil.net. */
|
|
39
|
+
function prefixMatches(raw, prefix) {
|
|
40
|
+
if (!raw.startsWith(prefix))
|
|
41
|
+
return false;
|
|
42
|
+
const rest = raw.slice(prefix.length);
|
|
43
|
+
return rest === "" || prefix.endsWith("/") || /^[/?]/.test(rest);
|
|
44
|
+
}
|
|
45
|
+
function normalizedHref(s) {
|
|
46
|
+
try {
|
|
47
|
+
return new URL(s).href;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function isAllowedRedirect(uri, extraPrefixes = []) {
|
|
54
|
+
if (typeof uri !== "string" || uri.length === 0 || uri.length > 2048)
|
|
55
|
+
return false;
|
|
56
|
+
if (BAD_CHARS.test(uri) || uri.includes("#"))
|
|
57
|
+
return false;
|
|
58
|
+
let u;
|
|
59
|
+
try {
|
|
60
|
+
u = new URL(uri);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
if (u.username || u.password || u.hash)
|
|
66
|
+
return false;
|
|
67
|
+
if (FORBIDDEN_SCHEMES.has(u.protocol))
|
|
68
|
+
return false;
|
|
69
|
+
if (u.protocol === "http:" && LOOPBACK.has(u.hostname))
|
|
70
|
+
return true;
|
|
71
|
+
if (u.protocol === "https:" && u.search === "" && FIXED.has(`${u.origin}${u.pathname}`))
|
|
72
|
+
return true;
|
|
73
|
+
if (u.protocol === "https:" && u.origin === "https://chatgpt.com" && u.search === "" && CHATGPT_CALLBACK_ID.test(u.pathname))
|
|
74
|
+
return true;
|
|
75
|
+
// Prefixes are matched against the NORMALIZED URL, and encoded/dot-segment paths are refused outright.
|
|
76
|
+
if (hasPathTricks(uri))
|
|
77
|
+
return false;
|
|
78
|
+
return [...DEFAULT_REDIRECT_PREFIXES, ...extraPrefixes].some((p) => {
|
|
79
|
+
const np = p.length > 0 ? normalizedHref(p) : null;
|
|
80
|
+
return np !== null && prefixMatches(u.href, np);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=redirect-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirect-policy.js","sourceRoot":"","sources":["../../src/http/redirect-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AAC9D,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC;IACpB,yCAAyC;IACzC,0CAA0C;IAC1C,uHAAuH;IACvH,+HAA+H;IAC/H,2DAA2D;IAC3D,uDAAuD;CACxD,CAAC,C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AC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IAC1I,uGAAuG;IACvG,IAAI,aAAa,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACrC,OAAO,CAAC,GAAG,yBAAyB,EAAE,GAAG,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;QACjE,MAAM,EAAE,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACnD,OAAO,EAAE,KAAK,IAAI,IAAI,aAAa,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface ReviewItem {
|
|
2
|
+
id: string;
|
|
3
|
+
project: string;
|
|
4
|
+
severity: string;
|
|
5
|
+
seenCount: number;
|
|
6
|
+
firstSeen: string;
|
|
7
|
+
lastSeen: string;
|
|
8
|
+
rule: string;
|
|
9
|
+
why: string;
|
|
10
|
+
appliesWhen: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface ReviewListView {
|
|
13
|
+
/** Who signed in, e.g. "GitHub account 101". */
|
|
14
|
+
account: string;
|
|
15
|
+
/** The memory (tenant) the account maps to. */
|
|
16
|
+
uid: string;
|
|
17
|
+
csrf: string;
|
|
18
|
+
/** A key of NOTICES (the session's one-shot outcome of the last post); anything else is ignored, never echoed. */
|
|
19
|
+
notice?: string;
|
|
20
|
+
items: ReviewItem[];
|
|
21
|
+
/** Captures that cannot be approved as they stand (not the structured form). */
|
|
22
|
+
incomplete: number;
|
|
23
|
+
/** Ready proposals not shown because of the display cap. */
|
|
24
|
+
hidden: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ReviewSignInView {
|
|
27
|
+
providers: Array<{
|
|
28
|
+
name: string;
|
|
29
|
+
label: string;
|
|
30
|
+
}>;
|
|
31
|
+
error?: string;
|
|
32
|
+
privacyUrl?: string;
|
|
33
|
+
}
|
|
34
|
+
export declare function noticeKey(v: unknown): string | undefined;
|
|
35
|
+
export declare function reviewSignInPage(v: ReviewSignInView): string;
|
|
36
|
+
export declare function reviewListPage(v: ReviewListView): string;
|
|
37
|
+
/** A standalone message (errors, expired sessions) with a way back to the start. */
|
|
38
|
+
export declare function reviewMessagePage(title: string, message: string): string;
|
|
39
|
+
//# sourceMappingURL=review-pages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"review-pages.d.ts","sourceRoot":"","sources":["../../src/http/review-pages.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,kHAAkH;IAClH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,gFAAgF;IAChF,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAWD,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAExD;AAkBD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAW5D;AAgBD,wBAAgB,cAAc,CAAC,CAAC,EAAE,cAAc,GAAG,MAAM,CAmBxD;AAED,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAIxE"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* review-pages.ts — HTML for the owner's review page (/review). Plain strings, no
|
|
3
|
+
* template engine, no scripts. EVERY interpolated value goes through esc(): proposal
|
|
4
|
+
* text is agent-written, so it is untrusted however it was cleaned on the way in.
|
|
5
|
+
* Headers come from oauth-pages.pageHeaders (strict CSP, no framing, no-store).
|
|
6
|
+
*/
|
|
7
|
+
import { esc, shell } from "./oauth-pages.js";
|
|
8
|
+
const NOTICES = {
|
|
9
|
+
approved: "Approved. It is active from the next session_start.",
|
|
10
|
+
merged: "Approved. An active correction with the same rule already existed, so this one was merged into it and the existing wording is kept.",
|
|
11
|
+
rejected: "Rejected. It will not become active.",
|
|
12
|
+
gone: "That proposal is no longer waiting, or its text changed after it was shown. Nothing was activated.",
|
|
13
|
+
failed: "That proposal could not be approved. Nothing was activated; if it is still waiting it is listed below.",
|
|
14
|
+
unavailable: "Your proposals could not be read just now. Nothing was changed; please try again.",
|
|
15
|
+
};
|
|
16
|
+
export function noticeKey(v) {
|
|
17
|
+
return typeof v === "string" && Object.prototype.hasOwnProperty.call(NOTICES, v) ? v : undefined;
|
|
18
|
+
}
|
|
19
|
+
const REVIEW_STYLE = `
|
|
20
|
+
main{max-width:760px}
|
|
21
|
+
.p{background:var(--sunk);border:1px solid var(--line);border-radius:12px;padding:16px 18px;margin:16px 0}
|
|
22
|
+
.meta{font-size:13px;color:var(--dim);margin:0 0 6px}
|
|
23
|
+
.rule{font-size:17px;font-weight:600;color:var(--ink);white-space:pre-wrap;overflow-wrap:anywhere;margin:4px 0}
|
|
24
|
+
.why{white-space:pre-wrap;overflow-wrap:anywhere}
|
|
25
|
+
.when{font-size:14px}.when code{background:var(--bg);border:1px solid var(--line);color:var(--cyan);font:13px var(--mono);border-radius:6px;padding:1px 6px;margin-right:4px;white-space:pre-wrap;overflow-wrap:anywhere}
|
|
26
|
+
.id{font:12px var(--mono);color:var(--dim);overflow-wrap:anywhere}
|
|
27
|
+
.acts{display:flex;gap:10px}.acts form{flex:1}
|
|
28
|
+
.ok{background:var(--ok-bg);border:1px solid var(--ok-line);border-left-width:4px;color:var(--ok-ink);border-radius:10px;padding:10px 14px;font-size:14.5px;margin:14px 0}
|
|
29
|
+
.bar{display:flex;justify-content:space-between;align-items:center;gap:12px}.bar form{width:auto}.bar button{margin:0;width:auto;padding:9px 16px;font-size:14px;white-space:nowrap}
|
|
30
|
+
@media (max-width:520px){.acts{flex-direction:column;gap:0}}
|
|
31
|
+
`;
|
|
32
|
+
const hidden = (name, value) => `<input type="hidden" name="${esc(name)}" value="${esc(value)}">`;
|
|
33
|
+
export function reviewSignInPage(v) {
|
|
34
|
+
return shell("Review your AgentRecall corrections", `<h1>Review your corrections</h1>` +
|
|
35
|
+
`<p>Your agents can only <strong>propose</strong> an always-follow rule. Nothing becomes active until you approve it here.</p>` +
|
|
36
|
+
`<p class="note">Sign in with the account your hosted memory belongs to. Agent tokens are not accepted on this page, so an agent cannot approve its own proposals.</p>` +
|
|
37
|
+
(v.error ? `<div class="err" role="alert">${esc(v.error)}</div>` : "") +
|
|
38
|
+
`<form method="post" action="/review/start">` +
|
|
39
|
+
v.providers.map((p) => `<button type="submit" name="provider" value="${esc(p.name)}">Continue with ${esc(p.label)}</button>`).join("") +
|
|
40
|
+
`</form>` +
|
|
41
|
+
(v.privacyUrl ? `<p class="note"><a href="${esc(v.privacyUrl)}" rel="noopener noreferrer" target="_blank">Privacy policy</a></p>` : ""), REVIEW_STYLE);
|
|
42
|
+
}
|
|
43
|
+
function item(it, csrf) {
|
|
44
|
+
const fields = hidden("id", it.id) + hidden("project", it.project) + hidden("csrf", csrf);
|
|
45
|
+
return `<section class="p">` +
|
|
46
|
+
`<p class="meta">project <strong>${esc(it.project)}</strong> · ${esc(it.severity)} · proposed ${esc(it.seenCount)}× · first ${esc(it.firstSeen)} · last ${esc(it.lastSeen)}</p>` +
|
|
47
|
+
`<p class="rule">${esc(it.rule)}</p>` +
|
|
48
|
+
`<p class="why"><strong>Why:</strong> ${esc(it.why)}</p>` +
|
|
49
|
+
`<p class="when"><strong>Applies when:</strong> ${it.appliesWhen.map((w) => `<code>${esc(w)}</code>`).join("")}</p>` +
|
|
50
|
+
`<p class="id">${esc(it.id)}</p>` +
|
|
51
|
+
`<div class="acts">` +
|
|
52
|
+
`<form method="post" action="/review/approve">${fields}<button type="submit">Approve</button></form>` +
|
|
53
|
+
`<form method="post" action="/review/reject">${fields}<button type="submit" class="reject">Reject</button></form>` +
|
|
54
|
+
`</div></section>`;
|
|
55
|
+
}
|
|
56
|
+
export function reviewListPage(v) {
|
|
57
|
+
const key = noticeKey(v.notice);
|
|
58
|
+
const n = v.items.length;
|
|
59
|
+
return shell("Review your AgentRecall corrections", `<div class="bar"><h1>Review your corrections</h1>` +
|
|
60
|
+
`<form method="post" action="/review/logout">${hidden("csrf", v.csrf)}<button type="submit" class="secondary">Sign out</button></form></div>` +
|
|
61
|
+
`<p class="note">Signed in with ${esc(v.account)} · memory <strong>${esc(v.uid)}</strong></p>` +
|
|
62
|
+
(key ? `<div class="${key === "gone" || key === "failed" || key === "unavailable" ? "err" : "ok"}" role="status" data-notice="${esc(key)}">${esc(NOTICES[key])}</div>` : "") +
|
|
63
|
+
(n === 0
|
|
64
|
+
? `<p>Nothing is waiting for your review.</p>`
|
|
65
|
+
: `<p>${n} proposed correction${n === 1 ? " is" : "s are"} waiting, oldest first. An approved correction is loaded by every one of your agents at session_start; ` +
|
|
66
|
+
`a p0 shows up under HARD RULES. Read it in full: what you see is exactly what approving activates.</p>` +
|
|
67
|
+
v.items.map((it) => item(it, v.csrf)).join("")) +
|
|
68
|
+
(v.hidden > 0 ? `<p class="note">${esc(v.hidden)} more waiting. Approve or reject these to see them.</p>` : "") +
|
|
69
|
+
(v.incomplete > 0
|
|
70
|
+
? `<p class="note">${esc(v.incomplete)} other capture${v.incomplete === 1 ? "" : "s"} cannot be approved as ${v.incomplete === 1 ? "it stands" : "they stand"}: ` +
|
|
71
|
+
`ask your agent to re-submit ${v.incomplete === 1 ? "it" : "them"} with a rule (at most 200 characters), a why (at most 600) and applies_when (at most 8 entries of at most 60 characters). They expire after 14 days.</p>`
|
|
72
|
+
: ""), REVIEW_STYLE);
|
|
73
|
+
}
|
|
74
|
+
/** A standalone message (errors, expired sessions) with a way back to the start. */
|
|
75
|
+
export function reviewMessagePage(title, message) {
|
|
76
|
+
return shell("AgentRecall review", `<h1>${esc(title)}</h1><div class="err" role="alert">${esc(message)}</div><p><a href="/review">Back to the review page</a></p>`, REVIEW_STYLE);
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=review-pages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"review-pages.js","sourceRoot":"","sources":["../../src/http/review-pages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAmC9C,MAAM,OAAO,GAA2B;IACtC,QAAQ,EAAE,qDAAqD;IAC/D,MAAM,EAAE,qIAAqI;IAC7I,QAAQ,EAAE,sCAAsC;IAChD,IAAI,EAAE,oGAAoG;IAC1G,MAAM,EAAE,wGAAwG;IAChH,WAAW,EAAE,mFAAmF;CACjG,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,CAAU;IAClC,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC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
|
2
|
+
import type { OAuthConfig } from "./oauth-config.js";
|
|
3
|
+
import { type ReviewItem } from "./review-pages.js";
|
|
4
|
+
import { WebSession, REVIEW_SESSION_COOKIE, REVIEW_SESSION_TTL_MS, REVIEW_LOGIN_TTL_MS, type WebResult } from "./web-session.js";
|
|
5
|
+
export { REVIEW_SESSION_COOKIE, REVIEW_SESSION_TTL_MS, REVIEW_LOGIN_TTL_MS };
|
|
6
|
+
/** Kept for callers of the old name: the review page now shares the site's sign-in and session (web-session.ts). */
|
|
7
|
+
export type ReviewResult = WebResult;
|
|
8
|
+
export declare const REVIEW_PATHS: ReadonlySet<string>;
|
|
9
|
+
export interface TenantProposals {
|
|
10
|
+
items: ReviewItem[];
|
|
11
|
+
incomplete: number;
|
|
12
|
+
hidden: number;
|
|
13
|
+
}
|
|
14
|
+
/** Every staged correction of `uid`, as the owner. Ready proposals are what approving activates, verbatim. */
|
|
15
|
+
export declare function listTenantProposals(dataDir: string, uid: string): Promise<TenantProposals>;
|
|
16
|
+
export type ReviewOutcome = "approved" | "merged" | "rejected" | "gone" | "failed" | "unavailable";
|
|
17
|
+
/**
|
|
18
|
+
* Approve or reject one staged proposal of `uid`, as the owner. Only a row that
|
|
19
|
+
* readStagedProposal accepts is acted on: its id ends in the digest of exactly the
|
|
20
|
+
* text the page showed, so a tampered id or an altered row is simply "gone".
|
|
21
|
+
*/
|
|
22
|
+
export declare function decideProposal(dataDir: string, uid: string, project: string, id: string, action: "approve" | "reject"): Promise<ReviewOutcome>;
|
|
23
|
+
export interface ReviewRouteDeps {
|
|
24
|
+
flow: WebSession;
|
|
25
|
+
config: OAuthConfig;
|
|
26
|
+
dataDir: string;
|
|
27
|
+
log: (line: string) => void;
|
|
28
|
+
/** Provider origins the sign-in form may be redirected to. */
|
|
29
|
+
formOrigins: string[];
|
|
30
|
+
/** Rate limit for POST /review/start: seconds to wait, or 0. */
|
|
31
|
+
limitStart: (req: express.Request) => number;
|
|
32
|
+
}
|
|
33
|
+
export declare function sendReview(res: express.Response, r: ReviewResult, formOrigins: string[]): void;
|
|
34
|
+
/** Mounts /review* on the OAuth app. Only called when OAuth is configured. */
|
|
35
|
+
export declare function mountReview(app: express.Express, d: ReviewRouteDeps): void;
|
|
36
|
+
//# sourceMappingURL=review.d.ts.map
|