hmcp-core 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -3
- package/dist/approvals.d.ts +508 -0
- package/dist/approvals.js +1445 -0
- package/dist/argpath.d.ts +75 -0
- package/dist/argpath.js +189 -0
- package/dist/audit.d.ts +297 -0
- package/dist/audit.js +524 -0
- package/dist/canonical.d.ts +78 -0
- package/dist/canonical.js +146 -0
- package/dist/classify-held.d.ts +47 -0
- package/dist/classify-held.js +60 -0
- package/dist/classify-name.d.ts +55 -0
- package/dist/classify-name.js +255 -0
- package/dist/decide.d.ts +168 -0
- package/dist/decide.js +518 -0
- package/dist/egress.d.ts +123 -0
- package/dist/egress.js +544 -0
- package/dist/enforce.d.ts +78 -0
- package/dist/enforce.js +231 -0
- package/dist/exposure-apply.d.ts +51 -0
- package/dist/exposure-apply.js +69 -0
- package/dist/exposure.d.ts +81 -0
- package/dist/exposure.js +65 -0
- package/dist/file-lock.d.ts +70 -0
- package/dist/file-lock.js +165 -0
- package/dist/glob.d.ts +11 -0
- package/dist/glob.js +55 -0
- package/dist/grants.d.ts +204 -0
- package/dist/grants.js +372 -0
- package/dist/http-util.d.ts +52 -0
- package/dist/http-util.js +81 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +36 -0
- package/dist/inventory.d.ts +100 -0
- package/dist/inventory.js +88 -0
- package/dist/ip.d.ts +15 -0
- package/dist/ip.js +186 -0
- package/dist/jwt.d.ts +57 -0
- package/dist/jwt.js +199 -0
- package/dist/live-state.d.ts +76 -0
- package/dist/live-state.js +57 -0
- package/dist/migrate.d.ts +22 -0
- package/dist/migrate.js +318 -0
- package/dist/pins.d.ts +119 -0
- package/dist/pins.js +125 -0
- package/dist/policy-batch.d.ts +89 -0
- package/dist/policy-batch.js +340 -0
- package/dist/policy-source.d.ts +161 -0
- package/dist/policy-source.js +299 -0
- package/dist/policy-write.d.ts +627 -0
- package/dist/policy-write.js +1697 -0
- package/dist/policy.d.ts +456 -0
- package/dist/policy.js +448 -0
- package/dist/redact.d.ts +65 -0
- package/dist/redact.js +191 -0
- package/dist/registry.d.ts +41 -0
- package/dist/registry.js +121 -0
- package/dist/remember-defaults.d.ts +9 -0
- package/dist/remember-defaults.js +9 -0
- package/dist/remember.d.ts +91 -0
- package/dist/remember.js +386 -0
- package/dist/resolve.d.ts +22 -0
- package/dist/resolve.js +34 -0
- package/dist/runtime-state.d.ts +65 -0
- package/dist/runtime-state.js +35 -0
- package/dist/secrets.d.ts +159 -0
- package/dist/secrets.js +361 -0
- package/dist/tenant.d.ts +83 -0
- package/dist/tenant.js +182 -0
- package/dist/unicode.d.ts +40 -0
- package/dist/unicode.js +103 -0
- package/dist/within-host.d.ts +33 -0
- package/dist/within-host.js +91 -0
- package/dist/within-real.d.ts +7 -0
- package/dist/within-real.js +28 -0
- package/package.json +33 -4
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { closeSync, openSync, statSync, unlinkSync, utimesSync } from "node:fs";
|
|
2
|
+
export class FileLockTimeout extends Error {
|
|
3
|
+
lockPath;
|
|
4
|
+
constructor(lockPath, what) {
|
|
5
|
+
super(`timed out waiting for ${what} to be free (lock file ${lockPath}). Another hardened-mcp process is ` +
|
|
6
|
+
`using it; if none is running, delete that lock file and try again.`);
|
|
7
|
+
this.lockPath = lockPath;
|
|
8
|
+
this.name = "FileLockTimeout";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const DEFAULT_TIMEOUT_MS = 5000;
|
|
12
|
+
const DEFAULT_STALE_MS = 10_000;
|
|
13
|
+
/** Blocks this thread without burning a core, as `approvals.ts` does when opening its store. */
|
|
14
|
+
function sleepSync(ms) {
|
|
15
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* One attempt to take the lock. A number is the open descriptor; `"busy"` means
|
|
19
|
+
* someone holds it; `"retry"` means a stale lock was just reclaimed (or vanished
|
|
20
|
+
* under us) and the caller should try again at once.
|
|
21
|
+
*/
|
|
22
|
+
function tryAcquire(lockPath, staleMs) {
|
|
23
|
+
try {
|
|
24
|
+
return openSync(lockPath, "wx", 0o600);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
if (err.code !== "EEXIST")
|
|
28
|
+
throw err;
|
|
29
|
+
// Reclaim a lock left behind by a process that died inside its critical section.
|
|
30
|
+
try {
|
|
31
|
+
if (Date.now() - statSync(lockPath).mtimeMs > staleMs) {
|
|
32
|
+
unlinkSync(lockPath);
|
|
33
|
+
return "retry";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// Released between our open and our stat: try again straight away.
|
|
38
|
+
return "retry";
|
|
39
|
+
}
|
|
40
|
+
return "busy";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function release(lockPath, fd) {
|
|
44
|
+
try {
|
|
45
|
+
closeSync(fd);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
/* best effort */
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
unlinkSync(lockPath);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
/* best effort: a reclaim may already have removed it */
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Runs `fn` holding `<path>.lock`. Synchronous: for a critical section that is
|
|
59
|
+
* a read and a rename, a few milliseconds long.
|
|
60
|
+
*/
|
|
61
|
+
export function withFileLock(path, fn, options = {}) {
|
|
62
|
+
const lockPath = `${path}.lock`;
|
|
63
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
64
|
+
const staleMs = options.staleMs ?? DEFAULT_STALE_MS;
|
|
65
|
+
const deadline = Date.now() + timeoutMs;
|
|
66
|
+
let fd;
|
|
67
|
+
for (;;) {
|
|
68
|
+
const got = tryAcquire(lockPath, staleMs);
|
|
69
|
+
if (typeof got === "number") {
|
|
70
|
+
fd = got;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
if (got === "retry")
|
|
74
|
+
continue;
|
|
75
|
+
if (Date.now() > deadline)
|
|
76
|
+
throw new FileLockTimeout(lockPath, options.what ?? path);
|
|
77
|
+
// Short, because the critical section is short; jittered so two waiters
|
|
78
|
+
// do not wake in lockstep and collide on every attempt.
|
|
79
|
+
sleepSync(2 + Math.floor(Math.random() * 4));
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
return fn();
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
release(lockPath, fd);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The same lock, held across `await`s -- for a critical section that waits on
|
|
90
|
+
* the network, such as refreshing a sign-in token whose refresh token is
|
|
91
|
+
* single-use.
|
|
92
|
+
*
|
|
93
|
+
* While held, the lock file's time is refreshed every second, so a holder that
|
|
94
|
+
* is merely slow (a token endpoint taking eight seconds) is never mistaken for
|
|
95
|
+
* a dead one and has its lock taken away mid-refresh. A holder that really did
|
|
96
|
+
* die stops refreshing and is reclaimed after `staleMs`.
|
|
97
|
+
*/
|
|
98
|
+
export async function withFileLockAsync(path, fn, options = {}) {
|
|
99
|
+
const lockPath = `${path}.lock`;
|
|
100
|
+
const timeoutMs = options.timeoutMs ?? 30_000;
|
|
101
|
+
const staleMs = options.staleMs ?? DEFAULT_STALE_MS;
|
|
102
|
+
const deadline = Date.now() + timeoutMs;
|
|
103
|
+
let fd;
|
|
104
|
+
for (;;) {
|
|
105
|
+
const got = tryAcquire(lockPath, staleMs);
|
|
106
|
+
if (typeof got === "number") {
|
|
107
|
+
fd = got;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
if (got === "retry")
|
|
111
|
+
continue;
|
|
112
|
+
if (Date.now() > deadline)
|
|
113
|
+
throw new FileLockTimeout(lockPath, options.what ?? path);
|
|
114
|
+
await new Promise((r) => setTimeout(r, 10 + Math.floor(Math.random() * 20)));
|
|
115
|
+
}
|
|
116
|
+
const keepAlive = setInterval(() => {
|
|
117
|
+
try {
|
|
118
|
+
const now = new Date();
|
|
119
|
+
utimesSync(lockPath, now, now);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
/* removed under us; nothing more to do */
|
|
123
|
+
}
|
|
124
|
+
}, Math.max(250, Math.min(1000, Math.floor(staleMs / 4))));
|
|
125
|
+
keepAlive.unref?.();
|
|
126
|
+
try {
|
|
127
|
+
return await fn();
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
clearInterval(keepAlive);
|
|
131
|
+
release(lockPath, fd);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** A file whose permissions let someone other than its owner read it. */
|
|
135
|
+
export class FileExposed extends Error {
|
|
136
|
+
path;
|
|
137
|
+
mode;
|
|
138
|
+
constructor(path, mode) {
|
|
139
|
+
super(`${path} can be read by other people on this computer (mode ${mode.toString(8).padStart(3, "0")}). ` +
|
|
140
|
+
`Make it private (chmod 600 "${path}") and try again.`);
|
|
141
|
+
this.path = path;
|
|
142
|
+
this.mode = mode;
|
|
143
|
+
this.name = "FileExposed";
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Throws when a file that holds a credential can be read by group or world.
|
|
148
|
+
*
|
|
149
|
+
* Skipped on Windows: there `stat` reports a synthesized mode (0o666 for any
|
|
150
|
+
* writable file) that says nothing about who can read it -- access is decided
|
|
151
|
+
* by ACLs, which Node does not expose. Checking the mode there refuses every
|
|
152
|
+
* file, which is how the console's token check failed on every Windows
|
|
153
|
+
* machine. A file in the user's profile is private to that user by default.
|
|
154
|
+
*
|
|
155
|
+
* A missing file is not this function's business: it throws the `stat` error
|
|
156
|
+
* (ENOENT) so the caller decides what absence means.
|
|
157
|
+
*/
|
|
158
|
+
export function assertPrivateFile(path, options = {}) {
|
|
159
|
+
const platform = options.platform ?? process.platform;
|
|
160
|
+
if (platform === "win32")
|
|
161
|
+
return;
|
|
162
|
+
const mode = statSync(path).mode & 0o777;
|
|
163
|
+
if ((mode & 0o077) !== 0)
|
|
164
|
+
throw options.error ? options.error(path, mode) : new FileExposed(path, mode);
|
|
165
|
+
}
|
package/dist/glob.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal glob matcher for tool-name patterns in policy rules.
|
|
3
|
+
*
|
|
4
|
+
* `*` matches any run of characters, `?` matches one, and `{a,b}` matches any
|
|
5
|
+
* one of the listed alternatives. Everything else is literal. Negation is not
|
|
6
|
+
* supported on purpose: a rule either matches or it does not, and precedence
|
|
7
|
+
* comes from rule order, which is visible in the audit log as a rule id.
|
|
8
|
+
*/
|
|
9
|
+
export declare function globToRegExp(pattern: string): RegExp;
|
|
10
|
+
export declare function globMatch(pattern: string, value: string): boolean;
|
|
11
|
+
export declare function anyGlobMatch(patterns: readonly string[], value: string): boolean;
|
package/dist/glob.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal glob matcher for tool-name patterns in policy rules.
|
|
3
|
+
*
|
|
4
|
+
* `*` matches any run of characters, `?` matches one, and `{a,b}` matches any
|
|
5
|
+
* one of the listed alternatives. Everything else is literal. Negation is not
|
|
6
|
+
* supported on purpose: a rule either matches or it does not, and precedence
|
|
7
|
+
* comes from rule order, which is visible in the audit log as a rule id.
|
|
8
|
+
*/
|
|
9
|
+
export function globToRegExp(pattern) {
|
|
10
|
+
let out = "^";
|
|
11
|
+
let depth = 0;
|
|
12
|
+
for (const ch of pattern) {
|
|
13
|
+
switch (ch) {
|
|
14
|
+
case "*":
|
|
15
|
+
out += ".*";
|
|
16
|
+
break;
|
|
17
|
+
case "?":
|
|
18
|
+
out += ".";
|
|
19
|
+
break;
|
|
20
|
+
case "{":
|
|
21
|
+
out += "(?:";
|
|
22
|
+
depth++;
|
|
23
|
+
break;
|
|
24
|
+
case "}":
|
|
25
|
+
if (depth > 0) {
|
|
26
|
+
out += ")";
|
|
27
|
+
depth--;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
out += "\\}";
|
|
31
|
+
}
|
|
32
|
+
break;
|
|
33
|
+
case ",":
|
|
34
|
+
out += depth > 0 ? "|" : "\\,";
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
out += ch.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// An unclosed brace is a typo. Closing it here would make the pattern match
|
|
41
|
+
// more than its author wrote, so it is treated as a literal instead.
|
|
42
|
+
if (depth > 0) {
|
|
43
|
+
return new RegExp(`^${escapeAll(pattern)}$`);
|
|
44
|
+
}
|
|
45
|
+
return new RegExp(out + "$");
|
|
46
|
+
}
|
|
47
|
+
function escapeAll(value) {
|
|
48
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
49
|
+
}
|
|
50
|
+
export function globMatch(pattern, value) {
|
|
51
|
+
return globToRegExp(pattern).test(value);
|
|
52
|
+
}
|
|
53
|
+
export function anyGlobMatch(patterns, value) {
|
|
54
|
+
return patterns.some((p) => globMatch(p, value));
|
|
55
|
+
}
|
package/dist/grants.d.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type ArgConstraint, type Effect } from "./policy.js";
|
|
3
|
+
/**
|
|
4
|
+
* Standing grants: a pre-approval for a *class* of call rather than one exact
|
|
5
|
+
* call.
|
|
6
|
+
*
|
|
7
|
+
* An ordinary approval is bound to `sha256(tool + canonical arguments)`, which
|
|
8
|
+
* is what stops a grant for a 10-unit transfer releasing a 10,000-unit one. A
|
|
9
|
+
* standing grant deliberately gives that up in exchange for not asking a human
|
|
10
|
+
* the same question repeatedly, so every other bound is kept tight:
|
|
11
|
+
*
|
|
12
|
+
* - it matches a glob over the tool name, not "anything";
|
|
13
|
+
* - its argument constraints are the same `ArgConstraint` vocabulary policy
|
|
14
|
+
* rules use, checked by the same `checkArgConstraints`;
|
|
15
|
+
* - it always expires, because a pre-approval with no end date is a posture
|
|
16
|
+
* change and those belong in `policy.yaml` where they get reviewed;
|
|
17
|
+
* - it can cap how many calls it releases;
|
|
18
|
+
* - it is revocable, and creation, use and revocation are all audited.
|
|
19
|
+
*
|
|
20
|
+
* A grant is strictly weaker than editing the policy: it cannot widen what
|
|
21
|
+
* `decide()` permits, only spare a human from re-approving what policy already
|
|
22
|
+
* routed to them.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* The longest a pre-approval may last. A grant is a concession made without a
|
|
26
|
+
* human in the loop at call time, so it has to come back for renewal; past a
|
|
27
|
+
* month it is a posture change wearing a grant's clothes.
|
|
28
|
+
*/
|
|
29
|
+
export declare const MAX_GRANT_TTL_SECONDS: number;
|
|
30
|
+
export type StandingGrantState = "active" | "revoked" | "expired" | "exhausted";
|
|
31
|
+
export interface StandingGrantRow {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
/** Which server this belongs to; "" on a row written before scoping. */
|
|
34
|
+
readonly component: string;
|
|
35
|
+
/** Whose data the grant covers; "" when no tenant is configured. */
|
|
36
|
+
readonly tenant: string;
|
|
37
|
+
readonly created_at: number;
|
|
38
|
+
/** Always set. There are no permanent grants on purpose. */
|
|
39
|
+
readonly expires_at: number;
|
|
40
|
+
/** Glob over the tool name, same dialect as `rules[].match`. */
|
|
41
|
+
readonly tool_match: string;
|
|
42
|
+
/** Optional extra restriction; null matches any effect. */
|
|
43
|
+
readonly effect: string | null;
|
|
44
|
+
/** JSON object of `Record<string, ArgConstraint>`. */
|
|
45
|
+
readonly constraints: string;
|
|
46
|
+
/** null means unlimited within the TTL. */
|
|
47
|
+
readonly max_uses: number | null;
|
|
48
|
+
readonly uses: number;
|
|
49
|
+
readonly reason: string;
|
|
50
|
+
readonly created_by: string;
|
|
51
|
+
readonly state: StandingGrantState;
|
|
52
|
+
readonly revoked_at: number | null;
|
|
53
|
+
readonly revoked_by: string | null;
|
|
54
|
+
/**
|
|
55
|
+
* 1 when the grant covers only calls whose every argument it names: a call
|
|
56
|
+
* that adds an argument the approved one did not send is not covered. Set on
|
|
57
|
+
* a grant remembered from one approved call ("Approve and don't ask again"),
|
|
58
|
+
* which promises exactly that call's inputs. 0 on a grant written by hand
|
|
59
|
+
* and on a row written before this existed.
|
|
60
|
+
*/
|
|
61
|
+
readonly closed: number;
|
|
62
|
+
}
|
|
63
|
+
export declare const GRANTS_SCHEMA = "\nCREATE TABLE IF NOT EXISTS standing_grants (\n id TEXT PRIMARY KEY,\n component TEXT NOT NULL DEFAULT '',\n tenant TEXT NOT NULL DEFAULT '',\n created_at INTEGER NOT NULL,\n expires_at INTEGER NOT NULL,\n tool_match TEXT NOT NULL,\n effect TEXT,\n constraints TEXT NOT NULL,\n max_uses INTEGER,\n uses INTEGER NOT NULL DEFAULT 0,\n reason TEXT NOT NULL,\n created_by TEXT NOT NULL,\n state TEXT NOT NULL,\n revoked_at INTEGER,\n revoked_by TEXT,\n closed INTEGER NOT NULL DEFAULT 0\n);\nCREATE INDEX IF NOT EXISTS grants_active ON standing_grants (component, tenant, state, expires_at);\n";
|
|
64
|
+
export declare function newGrantId(): string;
|
|
65
|
+
/** What a caller supplies; the store assigns the id, state and use count. */
|
|
66
|
+
export interface StandingGrantDraft {
|
|
67
|
+
readonly tool_match: string;
|
|
68
|
+
readonly effect?: Effect | null;
|
|
69
|
+
readonly constraints?: Record<string, ArgConstraint>;
|
|
70
|
+
readonly expires_at: number;
|
|
71
|
+
readonly max_uses?: number | null;
|
|
72
|
+
readonly reason: string;
|
|
73
|
+
readonly created_by: string;
|
|
74
|
+
/** See `StandingGrantRow.closed`. */
|
|
75
|
+
readonly closed?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Validates a grant as it arrives from an untrusted surface such as the web
|
|
79
|
+
* console. `expires_at` is required and must be in the future; a grant that is
|
|
80
|
+
* already expired would be silently useless rather than refused.
|
|
81
|
+
*/
|
|
82
|
+
export declare const StandingGrantDraftSchema: z.ZodObject<{
|
|
83
|
+
tool_match: z.ZodString;
|
|
84
|
+
effect: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
85
|
+
read: "read";
|
|
86
|
+
write: "write";
|
|
87
|
+
destructive: "destructive";
|
|
88
|
+
}>>>;
|
|
89
|
+
constraints: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
90
|
+
max: z.ZodOptional<z.ZodNumber>;
|
|
91
|
+
min: z.ZodOptional<z.ZodNumber>;
|
|
92
|
+
enum: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>>;
|
|
93
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
94
|
+
maxLength: z.ZodOptional<z.ZodNumber>;
|
|
95
|
+
maxItems: z.ZodOptional<z.ZodNumber>;
|
|
96
|
+
sum_max: z.ZodOptional<z.ZodNumber>;
|
|
97
|
+
count_max: z.ZodOptional<z.ZodNumber>;
|
|
98
|
+
within: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
99
|
+
host: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
100
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
101
|
+
optional: z.ZodOptional<z.ZodBoolean>;
|
|
102
|
+
coerce: z.ZodOptional<z.ZodBoolean>;
|
|
103
|
+
const: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>;
|
|
104
|
+
same_items: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
105
|
+
}, z.core.$strict>>>;
|
|
106
|
+
expires_at: z.ZodNumber;
|
|
107
|
+
max_uses: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
108
|
+
reason: z.ZodString;
|
|
109
|
+
created_by: z.ZodString;
|
|
110
|
+
closed: z.ZodOptional<z.ZodBoolean>;
|
|
111
|
+
}, z.core.$strict>;
|
|
112
|
+
export declare function parseGrantDraft(raw: unknown, now?: number): StandingGrantDraft;
|
|
113
|
+
/** Decodes the stored constraint JSON, treating corruption as "no match". */
|
|
114
|
+
export declare function grantConstraints(row: StandingGrantRow): Record<string, ArgConstraint> | null;
|
|
115
|
+
export interface GrantMatchResult {
|
|
116
|
+
readonly matches: boolean;
|
|
117
|
+
/** Why it did not match, for the console's dry-run preview. */
|
|
118
|
+
readonly reason: string;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Whether this grant covers this call.
|
|
122
|
+
*
|
|
123
|
+
* A grant whose constraints reject the arguments is *not a match*, which means
|
|
124
|
+
* the caller falls through to ordinary approval. It must never turn into a
|
|
125
|
+
* denial: a narrow pre-approval exists to save a human some clicks, and letting
|
|
126
|
+
* it block a call the human would have waved through would make adding one
|
|
127
|
+
* actively harmful.
|
|
128
|
+
*/
|
|
129
|
+
/**
|
|
130
|
+
* Whether a grant can apply to this tool at all, before any call's arguments
|
|
131
|
+
* are weighed.
|
|
132
|
+
*
|
|
133
|
+
* Split out for a reader with no call in front of them -- a preview of a grant
|
|
134
|
+
* that does not exist yet. Asking `grantMatches` instead means handing it an
|
|
135
|
+
* empty call, and an empty call breaks every value bound the grant has ("x is
|
|
136
|
+
* bounded by policy but absent"), so the more carefully a grant was written
|
|
137
|
+
* the less it would appear to cover. What its bounds then do to a real call is
|
|
138
|
+
* a separate question, and `grantBoundGaps` is the honest half of it.
|
|
139
|
+
*/
|
|
140
|
+
export declare function grantCoversTool(row: StandingGrantRow, tool: string, effect: Effect | null): GrantMatchResult;
|
|
141
|
+
/**
|
|
142
|
+
* The arguments a call sends that a closed grant names nowhere: `force: true`
|
|
143
|
+
* added to an approved push, a new key inside an approved object (R2 N4), or
|
|
144
|
+
* a new key inside one item of an approved list (`items[0].price`, R2 round
|
|
145
|
+
* 3). Every place a value sits must be named by a bound written for exactly
|
|
146
|
+
* that place: a bound on a list (`items: { maxItems: 1 }`) says how long it
|
|
147
|
+
* may be, not what its items may hold. A value that sends "nothing" -- null,
|
|
148
|
+
* an empty list or object -- is still sent: the server receives it.
|
|
149
|
+
*/
|
|
150
|
+
export declare function addedArgs(args: Record<string, unknown>, constraints: Record<string, ArgConstraint>): string[];
|
|
151
|
+
/**
|
|
152
|
+
* A grant "don't ask again" made before list items were pinned whole (R2
|
|
153
|
+
* round 4, R4-1). It bounded each field of a list's items on its own
|
|
154
|
+
* (`transfers[].to`, `transfers[].amount`), so approved items could be
|
|
155
|
+
* re-paired, repeated or swapped: approving 5 to alice and 1 to bob released
|
|
156
|
+
* 5 to bob. A remembered grant with a bound inside a list that is not pinned
|
|
157
|
+
* whole releases nothing now; the next call asks, and can be remembered again.
|
|
158
|
+
*/
|
|
159
|
+
export declare function hasLooseListItems(row: Pick<StandingGrantRow, "reason" | "constraints">): boolean;
|
|
160
|
+
/**
|
|
161
|
+
* A grant "don't ask again" made in an older build, which wrote it open. It is
|
|
162
|
+
* now read as covering only the arguments it names -- with none named, only a
|
|
163
|
+
* call with no arguments -- so it is shown as needing a fresh approval rather
|
|
164
|
+
* than as covering "any arguments" (R3 round 3).
|
|
165
|
+
*/
|
|
166
|
+
export declare function isOlderRemembered(row: Pick<StandingGrantRow, "closed" | "reason">): boolean;
|
|
167
|
+
/** True when a key named `__proto__` sits anywhere in the arguments (it can't be compared safely). */
|
|
168
|
+
export declare function hasProtoKey(value: unknown): boolean;
|
|
169
|
+
export declare function grantMatches(row: StandingGrantRow, tool: string, effect: Effect | null, args: Record<string, unknown>): GrantMatchResult;
|
|
170
|
+
/**
|
|
171
|
+
* Whether a grant's own constraints bound every one of the given arguments.
|
|
172
|
+
*
|
|
173
|
+
* `held` is the list of arguments that broke a rule's bound: concrete paths
|
|
174
|
+
* such as `transfer.amount` or `items[3].qty`, or the bound's own path
|
|
175
|
+
* (`amount`) when the argument was absent. An argument is bounded by the grant
|
|
176
|
+
* when one of its constraints says something about a value -- presence alone
|
|
177
|
+
* does not count -- and either is written against that exact path, or resolves
|
|
178
|
+
* in this call to that argument or to a container it sits inside.
|
|
179
|
+
*
|
|
180
|
+
* "Says something about a value" is `boundsValue`, so a constraint that only
|
|
181
|
+
* requires the argument to be sent does not make the grant its author's
|
|
182
|
+
* statement of how far past the rule a call may go.
|
|
183
|
+
*/
|
|
184
|
+
export declare function grantBoundsArgs(row: StandingGrantRow, args: Record<string, unknown>, held: readonly string[]): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Which of a rule's bounds a grant would not release a call for.
|
|
187
|
+
*
|
|
188
|
+
* `grantBoundsArgs` answers this for one call, from the arguments it actually
|
|
189
|
+
* sent. A reviewer about to create a grant has no call in front of them, so
|
|
190
|
+
* this answers the same question from the two sets of bounds alone: a rule
|
|
191
|
+
* bound that the grant says nothing about is one that will still stop a call
|
|
192
|
+
* and still ask a person, however well the grant matches the tool.
|
|
193
|
+
*
|
|
194
|
+
* Without it a preview reads "covers: yes" for a tool whose every interesting
|
|
195
|
+
* call the grant will not release -- a preview that promises what enforcement
|
|
196
|
+
* then refuses, which is worse than no preview.
|
|
197
|
+
*
|
|
198
|
+
* Both sides are patterns (`items[].qty`), compared as `grantBoundsArgs`
|
|
199
|
+
* compares a resolved path: the same spec, or a container the rule's bound
|
|
200
|
+
* sits inside.
|
|
201
|
+
*/
|
|
202
|
+
export declare function grantBoundGaps(grantConstraints: Record<string, ArgConstraint> | null, ruleArgs: Record<string, ArgConstraint> | undefined): string[];
|
|
203
|
+
/** True when the grant can still release a call, ignoring argument matching. */
|
|
204
|
+
export declare function grantIsLive(row: StandingGrantRow, now?: number): boolean;
|