hmcp-web 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.
Files changed (94) hide show
  1. package/LICENSE +77 -0
  2. package/README.md +49 -2
  3. package/THIRD-PARTY-NOTICES.md +110 -0
  4. package/bin/hmcp-web.js +20 -0
  5. package/dist/api.d.ts +22 -0
  6. package/dist/api.js +1458 -0
  7. package/dist/cli.d.ts +2 -0
  8. package/dist/cli.js +40 -0
  9. package/dist/contracts/onboarding.d.ts +233 -0
  10. package/dist/contracts/onboarding.js +1 -0
  11. package/dist/http.d.ts +72 -0
  12. package/dist/http.js +319 -0
  13. package/dist/index.d.ts +7 -0
  14. package/dist/index.js +7 -0
  15. package/dist/model/app-servers.d.ts +85 -0
  16. package/dist/model/app-servers.js +109 -0
  17. package/dist/model/console-settings.d.ts +37 -0
  18. package/dist/model/console-settings.js +74 -0
  19. package/dist/model/doctor.d.ts +68 -0
  20. package/dist/model/doctor.js +254 -0
  21. package/dist/model/fs-browse.d.ts +9 -0
  22. package/dist/model/fs-browse.js +184 -0
  23. package/dist/model/gateway-config.d.ts +287 -0
  24. package/dist/model/gateway-config.js +760 -0
  25. package/dist/model/import-record.d.ts +80 -0
  26. package/dist/model/import-record.js +179 -0
  27. package/dist/model/metrics.d.ts +65 -0
  28. package/dist/model/metrics.js +213 -0
  29. package/dist/model/oauth-flows.d.ts +60 -0
  30. package/dist/model/oauth-flows.js +79 -0
  31. package/dist/model/pipeline.d.ts +58 -0
  32. package/dist/model/pipeline.js +84 -0
  33. package/dist/model/probe.d.ts +155 -0
  34. package/dist/model/probe.js +385 -0
  35. package/dist/model/process.d.ts +100 -0
  36. package/dist/model/process.js +278 -0
  37. package/dist/model/protection.d.ts +378 -0
  38. package/dist/model/protection.js +470 -0
  39. package/dist/model/registry-cache.d.ts +59 -0
  40. package/dist/model/registry-cache.js +238 -0
  41. package/dist/model/scan.d.ts +48 -0
  42. package/dist/model/scan.js +59 -0
  43. package/dist/model/server.d.ts +127 -0
  44. package/dist/model/server.js +243 -0
  45. package/dist/model/tools.d.ts +61 -0
  46. package/dist/model/tools.js +72 -0
  47. package/dist/routes/catalog.d.ts +8 -0
  48. package/dist/routes/catalog.js +47 -0
  49. package/dist/routes/connect-import.d.ts +9 -0
  50. package/dist/routes/connect-import.js +594 -0
  51. package/dist/routes/connect.d.ts +50 -0
  52. package/dist/routes/connect.js +691 -0
  53. package/dist/routes/github.d.ts +97 -0
  54. package/dist/routes/github.js +587 -0
  55. package/dist/routes/guard.d.ts +3 -0
  56. package/dist/routes/guard.js +166 -0
  57. package/dist/routes/oauth.d.ts +55 -0
  58. package/dist/routes/oauth.js +406 -0
  59. package/dist/routes/policy.d.ts +34 -0
  60. package/dist/routes/policy.js +513 -0
  61. package/dist/routes/runtime.d.ts +12 -0
  62. package/dist/routes/runtime.js +921 -0
  63. package/dist/routes/servers-add.d.ts +32 -0
  64. package/dist/routes/servers-add.js +1091 -0
  65. package/dist/routes/system.d.ts +4 -0
  66. package/dist/routes/system.js +13 -0
  67. package/dist/start.d.ts +56 -0
  68. package/dist/start.js +164 -0
  69. package/dist-ui/assets/Activity-CZ78RyRO.js +1 -0
  70. package/dist-ui/assets/Approvals-DPIlNZsv.js +1 -0
  71. package/dist-ui/assets/AttachApp-DjSeWCbS.js +5 -0
  72. package/dist-ui/assets/Connections-qcA96lXh.js +2 -0
  73. package/dist-ui/assets/Gallery-DB_OO7Vw.js +17 -0
  74. package/dist-ui/assets/PreApprovals-C4cKajcK.js +1 -0
  75. package/dist-ui/assets/Protection-B8h-5YAb.js +1 -0
  76. package/dist-ui/assets/Safety-BQqHyYdo.js +1 -0
  77. package/dist-ui/assets/Settings-Cx50zZSt.js +1 -0
  78. package/dist-ui/assets/StartPage-CdX-v7ej.js +1 -0
  79. package/dist-ui/assets/Suggestions-CRo5UOTT.js +1 -0
  80. package/dist-ui/assets/Tools-xo39lPKB.js +4 -0
  81. package/dist-ui/assets/index-DttDjRpu.js +16 -0
  82. package/dist-ui/assets/index-QeJyD5z2.css +2 -0
  83. package/dist-ui/assets/kit-DRVm92_t.js +4 -0
  84. package/dist-ui/brand/logo-256.png +0 -0
  85. package/dist-ui/brand/logo-512.png +0 -0
  86. package/dist-ui/brand/logo.svg +6 -0
  87. package/dist-ui/brand/mark.svg +5 -0
  88. package/dist-ui/fonts/OFL.txt +99 -0
  89. package/dist-ui/fonts/README.md +21 -0
  90. package/dist-ui/fonts/jetbrainsmono-latin.woff2 +0 -0
  91. package/dist-ui/fonts/manrope-latin.woff2 +0 -0
  92. package/dist-ui/index.html +51 -0
  93. package/package.json +69 -6
  94. package/bin/notice.js +0 -7
@@ -0,0 +1,184 @@
1
+ import { existsSync, readdirSync, realpathSync, statSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { dirname, isAbsolute, join, parse, resolve, sep } from "node:path";
4
+ import { HttpError, notFound, unprocessable } from "../http.js";
5
+ /**
6
+ * The folder picker's view of the disk: folder names, and nothing else.
7
+ *
8
+ * A server like Filesystem is given folders, and typing a path is where a
9
+ * non-technical person gets stuck. This lets the browser walk folders without
10
+ * the console ever sending a file name or a byte of content -- the picker
11
+ * does not need them, and the console is not a file browser.
12
+ *
13
+ * Hidden folders (".git", ".ssh") are left out: nobody choosing "my
14
+ * documents" means them, and `.ssh` is the last thing to hand a server.
15
+ */
16
+ const MAX_ENTRIES = 500;
17
+ /** Windows folders that are not really anyone's. */
18
+ const WINDOWS_SYSTEM = new Set(["$recycle.bin", "system volume information", "$windows.~bt", "$windows.~ws", "config.msi"]);
19
+ function samePath(a, b, platform) {
20
+ return platform === "win32" ? a.toLowerCase() === b.toLowerCase() : a === b;
21
+ }
22
+ function within(child, parent, platform) {
23
+ const c = platform === "win32" ? child.toLowerCase() : child;
24
+ const p = platform === "win32" ? parent.toLowerCase() : parent;
25
+ return c === p || c.startsWith(p.endsWith(sep) ? p : p + sep);
26
+ }
27
+ /** Hidden folders in a home folder that hold sign-in keys, by name. */
28
+ const KEY_FOLDERS = {
29
+ ".ssh": "the keys this computer uses to sign in to other computers (SSH)",
30
+ ".aws": "your Amazon Web Services keys",
31
+ ".gnupg": "your encryption keys",
32
+ ".kube": "the keys to your Kubernetes clusters",
33
+ ".docker": "your Docker sign-ins",
34
+ ".azure": "your Microsoft Azure sign-ins",
35
+ ".config": "many programs' settings, often with their sign-ins",
36
+ ".gcloud": "your Google Cloud keys",
37
+ ".npmrc": "your npm sign-in"
38
+ };
39
+ /** Folders that belong to the computer itself, not to any one person. */
40
+ const SYSTEM_POSIX = ["/etc", "/private/etc", "/System", "/usr", "/bin", "/sbin", "/var", "/private/var", "/Library", "/opt", "/boot", "/proc", "/sys", "/root"];
41
+ /** Plain words when choosing this folder gives a server more than anyone means to. */
42
+ export function folderWarning(path, home, platform = process.platform) {
43
+ const candidates = [path];
44
+ try {
45
+ // A link ("Documents/ssh-link" -> ~/.ssh) is judged by where it really goes, too.
46
+ const real = realpathSync(path);
47
+ if (!samePath(real, path, platform))
48
+ candidates.push(real);
49
+ }
50
+ catch {
51
+ /* a folder that cannot be resolved is judged by its name */
52
+ }
53
+ const homes = [home];
54
+ try {
55
+ homes.push(realpathSync(home));
56
+ }
57
+ catch {
58
+ /* judged by its name */
59
+ }
60
+ for (const p of candidates) {
61
+ if (parse(p).root === p) {
62
+ return "This is the top of your computer's disk: a server given it can reach every file on this computer.";
63
+ }
64
+ for (const h of homes) {
65
+ if (samePath(p, h, platform)) {
66
+ return "This is your whole home folder: every file you have, including private ones. Choose a folder inside it instead.";
67
+ }
68
+ if (within(p, join(h, ".hmcp"), platform)) {
69
+ return "This is hardened-mcp's own folder, where your locked keys and settings live. A server given it could read or change them.";
70
+ }
71
+ if (within(p, h, platform)) {
72
+ const first = p.slice(h.length).split(/[\\/]+/).filter(Boolean)[0] ?? "";
73
+ const keys = KEY_FOLDERS[platform === "win32" ? first.toLowerCase() : first];
74
+ if (keys)
75
+ return `This folder holds ${keys}. A server given it could use them to act as you. Choose another folder.`;
76
+ if (first.startsWith(".")) {
77
+ return "This is a hidden folder, where programs keep their own settings and sometimes their keys. Choose one of your own folders instead.";
78
+ }
79
+ if (platform === "darwin" && first === "Library") {
80
+ return "This is where your apps keep their own data, including saved sign-ins and browser data. Choose one of your own folders instead.";
81
+ }
82
+ if (platform === "win32" && first.toLowerCase() === "appdata") {
83
+ return "This is where your apps keep their own data, including saved sign-ins and browser data. Choose one of your own folders instead.";
84
+ }
85
+ }
86
+ }
87
+ // Inside your own home folder, the checks above are the ones that matter.
88
+ if (homes.some((h) => within(p, h, platform)))
89
+ continue;
90
+ const homesRoot = dirname(home);
91
+ const isHomesRoot = /^(\/Users|\/home|[A-Za-z]:\\Users)$/i.test(homesRoot);
92
+ if (isHomesRoot && samePath(p, homesRoot, platform)) {
93
+ return "This folder holds the home folder of everyone who uses this computer. Choose one of your own folders instead.";
94
+ }
95
+ if (isHomesRoot && within(p, homesRoot, platform) && !within(p, join(homesRoot, "Shared"), platform)) {
96
+ return "This is another person's home folder on this computer. Choose one of your own folders instead.";
97
+ }
98
+ if (platform === "win32") {
99
+ if (/^[A-Za-z]:\\(windows|program files( \(x86\))?|programdata)(\\|$)/i.test(p)) {
100
+ return "This is one of the computer's own system folders. A server given it could change how this computer works. Choose one of your own folders instead.";
101
+ }
102
+ }
103
+ else if (SYSTEM_POSIX.some((s) => within(p, s, platform))) {
104
+ return "This is one of the computer's own system folders. A server given it could read its settings or change how it works. Choose one of your own folders instead.";
105
+ }
106
+ }
107
+ return undefined;
108
+ }
109
+ export function shortcuts(home, platform = process.platform) {
110
+ const out = [{ label: "Home", path: home }];
111
+ for (const name of ["Desktop", "Documents", "Downloads"]) {
112
+ const path = join(home, name);
113
+ if (existsSync(path))
114
+ out.push({ label: name, path });
115
+ }
116
+ if (platform === "win32") {
117
+ for (const letter of "CDEFGHIJKLMNOPQRSTUVWXYZ") {
118
+ const drive = `${letter}:\\`;
119
+ if (existsSync(drive))
120
+ out.push({ label: `${letter}: drive`, path: drive });
121
+ }
122
+ }
123
+ return out;
124
+ }
125
+ /** One folder's sub-folders. `raw` empty means the home folder. */
126
+ export function listDirs(raw, options = {}) {
127
+ const home = options.home ?? homedir();
128
+ const platform = options.platform ?? process.platform;
129
+ const requested = raw && raw.trim() ? raw.trim() : home;
130
+ if (requested.includes("\0") || !isAbsolute(requested)) {
131
+ throw unprocessable("A folder has to be given as a full path, starting from the top of the disk.");
132
+ }
133
+ const path = resolve(requested);
134
+ let entries;
135
+ try {
136
+ if (!statSync(path).isDirectory())
137
+ throw unprocessable(`${path} is a file, not a folder.`);
138
+ entries = readdirSync(path, { withFileTypes: true });
139
+ }
140
+ catch (err) {
141
+ if (err instanceof HttpError)
142
+ throw err;
143
+ const code = err.code;
144
+ if (code === "ENOENT")
145
+ throw notFound(`There is no folder at ${path}.`);
146
+ if (code === "EACCES" || code === "EPERM") {
147
+ throw new HttpError(403, "forbidden", `This computer does not let the console look inside ${path}. Choose another folder.`);
148
+ }
149
+ throw unprocessable(`${path} could not be opened: ${err.message}`);
150
+ }
151
+ const dirs = [];
152
+ for (const entry of entries) {
153
+ if (entry.name.startsWith("."))
154
+ continue;
155
+ if (platform === "win32" && WINDOWS_SYSTEM.has(entry.name.toLowerCase()))
156
+ continue;
157
+ const full = join(path, entry.name);
158
+ if (entry.isDirectory()) {
159
+ dirs.push({ name: entry.name, path: full });
160
+ }
161
+ else if (entry.isSymbolicLink()) {
162
+ // Shown with where it really goes, so "Documents" pointing at a cloud drive is not a surprise.
163
+ try {
164
+ if (!statSync(full).isDirectory())
165
+ continue;
166
+ dirs.push({ name: entry.name, path: full, symlinkTo: realpathSync(full) });
167
+ }
168
+ catch {
169
+ /* a broken link is not a folder anyone can pick */
170
+ }
171
+ }
172
+ }
173
+ dirs.sort((a, b) => a.name.localeCompare(b.name, undefined, { sensitivity: "base" }));
174
+ const parent = dirname(path);
175
+ const warning = folderWarning(path, home, platform);
176
+ return {
177
+ path,
178
+ parent: parent === path ? null : parent,
179
+ dirs: dirs.slice(0, MAX_ENTRIES),
180
+ truncated: dirs.length > MAX_ENTRIES,
181
+ shortcuts: shortcuts(home, platform),
182
+ ...(warning ? { warning } : {})
183
+ };
184
+ }
@@ -0,0 +1,287 @@
1
+ import { type ApprovalStore, type LiveConfigStateRow } from "hmcp-core";
2
+ import { type GatewayConfig, type Upstream } from "hmcp-gateway";
3
+ /**
4
+ * Editing `gateway.yaml` from the console.
5
+ *
6
+ * Every write here goes through `commitGatewayText`, which is the whole of the
7
+ * boundary: a digest lock, YAML that parses, a config the gateway's own schema
8
+ * accepts, the two settings that decide whether the console may write policy
9
+ * at all left exactly as they were, the policy itself left alone, and an
10
+ * acknowledgement for any change that widens what reaches the model. Edits are
11
+ * made through the `yaml` Document API, so comments and layout around the
12
+ * edited node survive.
13
+ *
14
+ * A running gateway with `upstream_reload` (the default) applies a change to
15
+ * `upstreams` live; any other change still waits for its next start. Which of
16
+ * the two happened is read from what the running processes report -- see
17
+ * `applyState` in routes/runtime.ts.
18
+ */
19
+ /**
20
+ * What the console shows in place of an upstream header or env value.
21
+ *
22
+ * Those two maps are where credentials live in this file, and the console does
23
+ * not echo a credential back over its API. A value left as this marker on a
24
+ * save keeps whatever is on disk for the same upstream and key.
25
+ */
26
+ export declare const KEPT_SECRET = "[kept secret]";
27
+ /** The two settings no console write may change. See `assertGuardsUnchanged`. */
28
+ export declare const GUARDED_SETTINGS: readonly ["policy_writes", "policy_overrides"];
29
+ export interface GatewayFile {
30
+ readonly path: string;
31
+ readonly text: string;
32
+ readonly digest: string;
33
+ readonly config: GatewayConfig;
34
+ }
35
+ export declare function digestText(text: string): string;
36
+ export declare function readGatewayFile(path: string): GatewayFile;
37
+ /**
38
+ * A gateway.yaml the schema rejects, read so it can be repaired.
39
+ *
40
+ * `text` is null when the file is not even YAML: the credential markers are
41
+ * found by walking the YAML document, so text that does not parse cannot be
42
+ * redacted, and is never sent to the browser.
43
+ */
44
+ export interface BrokenGatewayFile {
45
+ readonly path: string;
46
+ readonly text: string | null;
47
+ readonly digest: string;
48
+ readonly error: string;
49
+ }
50
+ /** The file when it is valid, or what is wrong with it when it is not. */
51
+ export declare function readGatewayFileOrBroken(path: string): GatewayFile | BrokenGatewayFile;
52
+ export declare function isBroken(file: GatewayFile | BrokenGatewayFile): file is BrokenGatewayFile;
53
+ /**
54
+ * Repairs a gateway.yaml the schema rejects.
55
+ *
56
+ * The usual checks compare against the parsed config before the edit, and a
57
+ * broken file has none, so this path holds the line differently:
58
+ * - the broken text must still be YAML, so the guards' values on disk can be
59
+ * read from it (a file that is not even YAML is refused: there is nothing
60
+ * to compare the guards against);
61
+ * - `policy_writes`, `policy_overrides` and `policy:` must come out exactly as
62
+ * the broken file has them, reading an absent guard as its schema default;
63
+ * - the save always counts as loosening, because what it widens cannot be
64
+ * computed against a file the gateway could not load.
65
+ */
66
+ export declare function repairGatewayText(args: {
67
+ file: BrokenGatewayFile;
68
+ text: string;
69
+ expectedDigest: string;
70
+ acknowledgedLoosens: boolean;
71
+ }): {
72
+ after: GatewayConfig;
73
+ previousDigest: string;
74
+ digest: string;
75
+ };
76
+ /**
77
+ * The file as the console shows it: byte for byte, except that each credential
78
+ * value is replaced in place by the marker. Done on source ranges rather than
79
+ * by re-serialising, so what the editor shows is the file's own layout.
80
+ */
81
+ export declare function redactText(text: string): string;
82
+ /**
83
+ * The redaction for a file the schema rejects: everything `conservativeSites`
84
+ * finds, as well as everything `redactText` would.
85
+ */
86
+ export declare function redactBrokenText(text: string): string;
87
+ export declare function redactUpstream(upstream: Upstream): Upstream;
88
+ export declare function redactConfig(config: GatewayConfig): GatewayConfig;
89
+ /**
90
+ * Puts the real values back wherever the marker was left in a submitted text.
91
+ *
92
+ * Copied from the current file's own source, so a credential never passes
93
+ * through the browser in either direction. A marker with nothing to keep -- an
94
+ * upstream or key that does not exist on disk -- is refused, rather than
95
+ * written as the literal word.
96
+ */
97
+ export declare function restoreSecretsInText(submitted: string, current: string): string;
98
+ /** The same, for an upstream submitted as an object. */
99
+ export declare function restoreSecretsInUpstream(submitted: Upstream, current: Upstream | undefined): Upstream;
100
+ /**
101
+ * Every way a change widens what this gateway lets through, in plain words.
102
+ *
103
+ * Each one needs `acknowledged.loosens`. They are the changes where a person
104
+ * clicking through a form could make the gateway quietly protect less: a
105
+ * weaker answer to a poisoned description, a renamed gateway or tool set that
106
+ * strands every switch and pin stored under the old names, and credentials or
107
+ * environment handed to a server that did not have them.
108
+ */
109
+ export declare function gatewayLoosens(before: GatewayConfig, after: GatewayConfig): string[];
110
+ export interface CommitResult {
111
+ readonly before: GatewayConfig;
112
+ readonly after: GatewayConfig;
113
+ readonly previousDigest: string;
114
+ readonly digest: string;
115
+ readonly loosens: string[];
116
+ }
117
+ /** Parses and validates text as a gateway config, or says why it is not one. */
118
+ export declare function parseGatewayText(text: string): GatewayConfig;
119
+ /**
120
+ * The guard on the guard.
121
+ *
122
+ * `policy_writes` and `policy_overrides` decide whether this console may write
123
+ * policy at all. A console that could change them would be granting itself
124
+ * permission, so no write from here may, in either direction -- tightening
125
+ * them is a reviewed edit to the file too.
126
+ */
127
+ export declare function assertGuardsUnchanged(before: GatewayConfig, after: GatewayConfig): void;
128
+ /**
129
+ * The one place a gateway.yaml is written from the console.
130
+ *
131
+ * `intended` is the caller's own assertion that nothing outside the part it
132
+ * meant to change has changed: a check on the parsed result rather than on the
133
+ * edit, so a Document API surprise cannot widen a write.
134
+ */
135
+ export declare function commitGatewayText(args: {
136
+ file: GatewayFile;
137
+ text: string;
138
+ expectedDigest: string;
139
+ acknowledgedLoosens: boolean;
140
+ intended?: (before: GatewayConfig, after: GatewayConfig) => string | null;
141
+ }): CommitResult;
142
+ /** Every top-level key but these, canonicalised, for an "only this changed" check. */
143
+ export declare function sameExcept(before: GatewayConfig, after: GatewayConfig, keys: readonly string[]): boolean;
144
+ export interface DiffLine {
145
+ readonly op: " " | "+" | "-";
146
+ readonly line: string;
147
+ }
148
+ /**
149
+ * A line diff, for a preview, as a flat op/line list: the gateway editor's
150
+ * shape. The policy editor's diff is hunked instead -- see `lineDiff` in
151
+ * routes/policy.ts. Longest common subsequence, which is quadratic,
152
+ * so a pair of files too large for it falls back to "all removed, all added" --
153
+ * still correct, just less helpful.
154
+ */
155
+ export declare function lineDiff(a: string, b: string): DiffLine[];
156
+ /**
157
+ * What adding a server needs from the policy beside it: its address allowed,
158
+ * POST allowed (opening a Streamable HTTP session is a POST), private
159
+ * addresses allowed for a server on this computer, and the ready-made rules
160
+ * for it.
161
+ */
162
+ export type PolicyChange = {
163
+ readonly kind: "egress-allow";
164
+ readonly host: string;
165
+ } | {
166
+ readonly kind: "egress-method";
167
+ readonly method: string;
168
+ } | {
169
+ readonly kind: "egress-local-network";
170
+ }
171
+ /** Plain http:// to a public host: only `allow_http`, private addresses stay refused. */
172
+ | {
173
+ readonly kind: "egress-plain-http";
174
+ } | {
175
+ readonly kind: "rule";
176
+ readonly rule: {
177
+ readonly id: string;
178
+ readonly match: string;
179
+ readonly effect?: string;
180
+ readonly decision: string;
181
+ } & Record<string, unknown>;
182
+ };
183
+ export interface PolicyBatchResult {
184
+ readonly text: string;
185
+ /** Plain words, one per change that lets more through. */
186
+ readonly loosens: string[];
187
+ /** False when every change was already in the file. */
188
+ readonly changed: boolean;
189
+ /** Rule ids written new, written over an older copy, and left out (with why). */
190
+ readonly rulesAdded: readonly string[];
191
+ readonly rulesReplaced: readonly string[];
192
+ readonly rulesSkipped: readonly {
193
+ readonly id: string;
194
+ readonly why: string;
195
+ }[];
196
+ }
197
+ /** A batch that changed nothing, for a policy that was not edited at all. */
198
+ export declare function unchangedBatch(text: string): PolicyBatchResult;
199
+ /**
200
+ * ADAPTER for core's `applyPolicyBatch(policyText, changes)` (workstream A,
201
+ * core/src/policy-batch.ts). Until that lands this applies the changes itself
202
+ * through the yaml Document API, so comments and layout around them survive;
203
+ * at merge this body becomes a one-line call (translating `PolicyChange` if
204
+ * A's shape differs).
205
+ */
206
+ export declare function applyPolicyChanges(policyText: string, changes: readonly PolicyChange[], source?: string): PolicyBatchResult;
207
+ /**
208
+ * The refusal for a toolbox with `policy_overrides: false`, which lets the
209
+ * console tighten its policy but never loosen it -- the same line core's
210
+ * `writePolicyBatch` holds. Acknowledging would not change the answer, so
211
+ * this carries no `needs: "loosens"`: the page must not offer a confirm
212
+ * button that can only fail. Throws when `loosens` is not empty.
213
+ */
214
+ export declare function refuseIfOverridesOff(config: GatewayConfig, loosens: readonly string[]): void;
215
+ /**
216
+ * policy.yaml without the rules the console or a pack wrote for one server:
217
+ * ids starting `pack-` or `console-` whose `match` names a tool of that
218
+ * server (`<upstream>__...`). Removing a server otherwise leaves them behind,
219
+ * deciding tools that no longer exist -- and deciding them again, unseen, for
220
+ * a different server later added under the same name.
221
+ *
222
+ * A rule a person wrote is never touched, and neither is `egress`: another
223
+ * server may share an address. Edited through the Document API so comments
224
+ * survive, and checked to have removed exactly those rules.
225
+ */
226
+ export declare function removeRulesWrittenFor(policyText: string, upstream: string): {
227
+ text: string;
228
+ removed: string[];
229
+ };
230
+ /**
231
+ * Whether the egress guard refuses this host unless private addresses are
232
+ * allowed: `localhost`, and any literal in loopback, link-local or private
233
+ * space. The same test adopt-plan.ts makes.
234
+ */
235
+ export declare function isLocalHost(hostname: string): boolean;
236
+ /**
237
+ * The changes an upstream needs for its own address, before any rule pack.
238
+ *
239
+ * The one place this is worked out: Test it's scratch policy and install both
240
+ * call it, so what is saved is what was tested. A server on this computer or
241
+ * the local network needs the guard's private-address, bare-IP and plain-http
242
+ * protections off; one on a public host reached over plain http needs only
243
+ * plain http. `localNetwork` is what the draft found (a private address);
244
+ * it can only add to what the address itself says, never take it away.
245
+ */
246
+ export declare function egressChangesFor(upstream: Upstream, options?: {
247
+ localNetwork?: boolean;
248
+ }): PolicyChange[];
249
+ /** The rows of gateway processes still beating, newest heartbeat first. */
250
+ export declare function liveRows(store: ApprovalStore, component: string, now?: number): LiveConfigStateRow[];
251
+ /** Asks running gateways to retry one server now. False when the store cannot take requests. */
252
+ export declare function requestRetry(store: ApprovalStore, component: string, upstream: string): boolean;
253
+ export type ApplyState = "live" | "pending" | "not-running" | "needs-restart";
254
+ /**
255
+ * A gateway's refusal in words a person can act on. The gateway writes for a
256
+ * log ("gateway.yaml changed connect_timeout_ms, which a running gateway cannot
257
+ * pick up..."); the console shows this instead, with the setting's own name
258
+ * kept in brackets for whoever wants to look it up.
259
+ */
260
+ export declare function plainRefusal(refusal: string): string;
261
+ /**
262
+ * Whether a gateway's published refusal can only be cleared by a restart.
263
+ * A file that did not parse ("could not be used") is cleared by the next good
264
+ * write, so it does not count; a change outside `upstreams` does.
265
+ */
266
+ export declare function refusalNeedsRestart(refusal: string | null | undefined): boolean;
267
+ /**
268
+ * Whether that refusal also holds back changes to the servers. A gateway that
269
+ * carries server changes past a standing refusal says so ("The servers were
270
+ * updated"); one that does not refuses the whole file.
271
+ */
272
+ export declare function refusalBlocksServers(refusal: string | null | undefined): boolean;
273
+ /**
274
+ * What a write to gateway.yaml means for what is running.
275
+ *
276
+ * Only `upstreams` changes are applied live, and only by a gateway with
277
+ * `upstream_reload` on; anything else waits for its next start. `running`
278
+ * covers a gateway from before live state existed, which announces itself but
279
+ * writes no live rows: it can only pick the change up by restarting.
280
+ */
281
+ export declare function applyStateFor(args: {
282
+ rows: readonly LiveConfigStateRow[];
283
+ running: boolean;
284
+ upstreamsOnly: boolean;
285
+ upstreamReload: boolean;
286
+ digest: string;
287
+ }): ApplyState;