hmcp-web 0.2.1 → 0.2.3

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 (63) hide show
  1. package/dist/api.d.ts +6 -0
  2. package/dist/api.js +36 -8
  3. package/dist/model/app-connect-note.d.ts +114 -0
  4. package/dist/model/app-connect-note.js +199 -0
  5. package/dist/model/app-servers.d.ts +24 -1
  6. package/dist/model/app-servers.js +54 -6
  7. package/dist/model/apps.d.ts +24 -0
  8. package/dist/model/apps.js +18 -0
  9. package/dist/model/bring-in.d.ts +185 -0
  10. package/dist/model/bring-in.js +755 -0
  11. package/dist/model/console-settings.d.ts +2 -2
  12. package/dist/model/import-record.d.ts +4 -0
  13. package/dist/model/import-record.js +22 -1
  14. package/dist/model/new-toolbox.d.ts +84 -0
  15. package/dist/model/new-toolbox.js +209 -0
  16. package/dist/model/protection.d.ts +21 -1
  17. package/dist/model/protection.js +68 -9
  18. package/dist/model/provisional-tools.d.ts +56 -0
  19. package/dist/model/provisional-tools.js +145 -0
  20. package/dist/model/server-names.d.ts +25 -0
  21. package/dist/model/server-names.js +158 -0
  22. package/dist/model/toolbox-label.d.ts +22 -0
  23. package/dist/model/toolbox-label.js +42 -0
  24. package/dist/model/tools.d.ts +20 -5
  25. package/dist/model/tools.js +22 -11
  26. package/dist/routes/connect-app.d.ts +54 -0
  27. package/dist/routes/connect-app.js +1018 -0
  28. package/dist/routes/connect-import.d.ts +21 -6
  29. package/dist/routes/connect-import.js +162 -546
  30. package/dist/routes/connect.d.ts +11 -0
  31. package/dist/routes/connect.js +28 -116
  32. package/dist/routes/github.js +2 -1
  33. package/dist/routes/guard.js +4 -0
  34. package/dist/routes/runtime.js +21 -22
  35. package/dist/routes/servers-add.d.ts +1 -0
  36. package/dist/routes/servers-add.js +6 -5
  37. package/dist-ui/assets/Activity-BSf4lBm-.js +1 -0
  38. package/dist-ui/assets/Approvals-CDz3zYpl.js +1 -0
  39. package/dist-ui/assets/AttachApp-COr1547c.js +5 -0
  40. package/dist-ui/assets/Connections-ClW5R6ea.js +2 -0
  41. package/dist-ui/assets/{Gallery-DB_OO7Vw.js → Gallery-0iiv1H9e.js} +3 -3
  42. package/dist-ui/assets/{PreApprovals-CXcU-_ug.js → PreApprovals-DYDKgSpr.js} +1 -1
  43. package/dist-ui/assets/Protection-DMtABpM7.js +1 -0
  44. package/dist-ui/assets/Safety-BLTF2fqV.js +1 -0
  45. package/dist-ui/assets/{Settings-XjNZ-wo-.js → Settings-DZ4P3Us6.js} +1 -1
  46. package/dist-ui/assets/StartPage-Bke6mrv5.js +1 -0
  47. package/dist-ui/assets/{Suggestions-HZyd0jDU.js → Suggestions-kAWUILyw.js} +1 -1
  48. package/dist-ui/assets/Tools-BdXSeKeL.js +4 -0
  49. package/dist-ui/assets/connect-app-words-CT8Fytzv.js +1 -0
  50. package/dist-ui/assets/index-Cm4wG2zz.js +16 -0
  51. package/dist-ui/assets/{kit-DRVm92_t.js → kit-BHB_ha4i.js} +1 -1
  52. package/dist-ui/assets/server-name-D9u6r07i.js +1 -0
  53. package/dist-ui/index.html +3 -2
  54. package/package.json +4 -4
  55. package/dist-ui/assets/Activity-Dgo5oK2r.js +0 -1
  56. package/dist-ui/assets/Approvals-C5_8rBkL.js +0 -1
  57. package/dist-ui/assets/AttachApp-BRW1mJ7X.js +0 -5
  58. package/dist-ui/assets/Connections-BHsXRdYI.js +0 -2
  59. package/dist-ui/assets/Protection-BF5OlzGC.js +0 -1
  60. package/dist-ui/assets/Safety-DVb8sdbt.js +0 -1
  61. package/dist-ui/assets/StartPage-D8WBBhDy.js +0 -1
  62. package/dist-ui/assets/Tools-GMaKxxIG.js +0 -4
  63. package/dist-ui/assets/index-DbHZ_SUd.js +0 -16
@@ -6,19 +6,19 @@ export declare const SettingsPatchSchema: z.ZodObject<{
6
6
  onboarding: z.ZodOptional<z.ZodObject<{
7
7
  step: z.ZodOptional<z.ZodEnum<{
8
8
  server: "server";
9
+ app: "app";
9
10
  done: "done";
10
11
  welcome: "welcome";
11
12
  computer: "computer";
12
- app: "app";
13
13
  try: "try";
14
14
  protect: "protect";
15
15
  }>>;
16
16
  done: z.ZodOptional<z.ZodArray<z.ZodEnum<{
17
17
  server: "server";
18
+ app: "app";
18
19
  done: "done";
19
20
  welcome: "welcome";
20
21
  computer: "computer";
21
- app: "app";
22
22
  try: "try";
23
23
  protect: "protect";
24
24
  }>>>;
@@ -71,6 +71,10 @@ export declare function deleteImportRecord(registryPath: string, target: ScopeTa
71
71
  * - The connection itself gone (no undo record, or one for another toolbox):
72
72
  * the whole record goes. Undoing the connection said the servers brought
73
73
  * in stay in the toolbox.
74
+ * - Except that a record naming a toolbox id the console doesn't have, or
75
+ * beside an undo record that does, is kept as it is: a toolbox whose id
76
+ * changed is being pointed at its new one (`adoptToolboxId`), and a step
77
+ * of that left half-done must not lose what Undo needs.
74
78
  * - A server the app's record no longer holds is back in the app already.
75
79
  * If the toolbox still has it as the import added it, it is kept, marked
76
80
  * so: an Undo that put it back and then failed on the toolbox must still
@@ -125,6 +125,10 @@ export function deleteImportRecord(registryPath, target) {
125
125
  * - The connection itself gone (no undo record, or one for another toolbox):
126
126
  * the whole record goes. Undoing the connection said the servers brought
127
127
  * in stay in the toolbox.
128
+ * - Except that a record naming a toolbox id the console doesn't have, or
129
+ * beside an undo record that does, is kept as it is: a toolbox whose id
130
+ * changed is being pointed at its new one (`adoptToolboxId`), and a step
131
+ * of that left half-done must not lose what Undo needs.
128
132
  * - A server the app's record no longer holds is back in the app already.
129
133
  * If the toolbox still has it as the import added it, it is kept, marked
130
134
  * so: an Undo that put it back and then failed on the toolbox must still
@@ -143,12 +147,29 @@ export function readLiveImportRecord(registryPath, target) {
143
147
  // An unreadable record is not evidence that anything was given back.
144
148
  return rec;
145
149
  }
150
+ if (backup && backup.scope === target.scope && backup.registry_id !== rec.gateway_id) {
151
+ let ids;
152
+ try {
153
+ ids = new Set(readRegistry(registryPath).servers.map((s) => s.id));
154
+ }
155
+ catch {
156
+ // No list to check against is no evidence the toolbox is another one.
157
+ return rec;
158
+ }
159
+ if (!ids.has(rec.gateway_id) || (backup.registry_id !== undefined && !ids.has(backup.registry_id)))
160
+ return rec;
161
+ }
146
162
  const held = backup && backup.scope === target.scope && backup.registry_id === rec.gateway_id ? backup.replaced : undefined;
147
163
  const upstreams = held ? toolboxUpstreams(registryPath, rec.gateway_id) : undefined;
148
164
  const items = held
149
165
  ? rec.items.flatMap((i) => {
150
- if (i.source !== "config" || Object.hasOwn(held, i.key))
166
+ if (i.source !== "config")
151
167
  return [i];
168
+ if (Object.hasOwn(held, i.key)) {
169
+ // Out of the app again (brought in once more): no longer back in it, so Undo puts it back.
170
+ const { back_in_app: _back, ...rest } = i;
171
+ return [rest];
172
+ }
152
173
  // A toolbox that can't be read is no evidence the server left it: kept.
153
174
  const still = upstreams === undefined || upstreams.some((u) => u.name === i.upstream && (i.digest === undefined || upstreamDigest(u) === i.digest));
154
175
  return i.added && still ? [{ ...i, back_in_app: true }] : [];
@@ -0,0 +1,84 @@
1
+ import { type RegistryEntry } from "hmcp-core";
2
+ import { type Upstream } from "hmcp-gateway";
3
+ import { type PolicyChange } from "./gateway-config.js";
4
+ /**
5
+ * A toolbox from nothing: its gateway.yaml, its policy.yaml and its row in
6
+ * the console's list. What POST /api/v1/gateways writes, and what "Bring in
7
+ * servers" writes when the app has no toolbox yet.
8
+ *
9
+ * Worked out first (`planNewToolbox`, which writes nothing) and written
10
+ * after (`writeNewToolbox`), so a caller can test servers in between and
11
+ * still be told about a name already taken before anything starts.
12
+ */
13
+ export type Posture = "read-only" | "approve-writes" | "locked";
14
+ export interface NewToolboxInput {
15
+ /** Also the folder name under ~/.hmcp/gateways, checked by the caller. */
16
+ readonly name: string;
17
+ readonly upstreams: readonly Upstream[];
18
+ readonly posture?: Posture;
19
+ readonly mode?: "observe" | "enforce";
20
+ readonly onUnclassified?: "deny" | "approve";
21
+ /** The folder, already checked by the caller. Default ~/.hmcp/gateways/<name>. */
22
+ readonly dir?: string;
23
+ readonly id?: string;
24
+ readonly label?: string;
25
+ /**
26
+ * Changes made to the policy after it is written out, the way adding a
27
+ * server to an existing toolbox makes them. "Bring in servers" passes the
28
+ * network changes its servers were tested with, so the toolbox lets
29
+ * through what the test let through. POST /gateways passes none.
30
+ */
31
+ readonly policyChanges?: readonly PolicyChange[];
32
+ }
33
+ export interface NewToolboxPlan {
34
+ readonly name: string;
35
+ readonly id: string;
36
+ readonly label: string;
37
+ readonly dir: string;
38
+ readonly configPath: string;
39
+ readonly policyPath: string;
40
+ readonly gatewayYaml: string;
41
+ readonly policyYaml: string;
42
+ readonly upstreamNames: readonly string[];
43
+ readonly posture: Posture;
44
+ readonly mode: "observe" | "enforce";
45
+ /** A value in env or headers is written into gateway.yaml as it is. */
46
+ readonly literals: boolean;
47
+ /** Hosts on this computer or the local network, which need the private-address protection off. */
48
+ readonly local: readonly string[];
49
+ /** What `policyChanges` let through, in plain words. */
50
+ readonly loosens: readonly string[];
51
+ }
52
+ export interface NewToolbox {
53
+ readonly entry: RegistryEntry;
54
+ readonly id: string;
55
+ readonly configPath: string;
56
+ readonly policyPath: string;
57
+ readonly dir: string;
58
+ /** The folder was made for this toolbox, so taking the toolbox away again removes it (when nothing else is in it). */
59
+ readonly createdDir: boolean;
60
+ /** The files this toolbox wrote: the only ones taking it away deletes. */
61
+ readonly files: readonly string[];
62
+ }
63
+ export declare function uniqueId(base: string, taken: ReadonlySet<string>): string;
64
+ /** What switching the private-address protection off lets through, as POST /gateways words it. */
65
+ export declare function localLoosens(local: readonly string[]): string[];
66
+ /**
67
+ * The new toolbox's files as text, and where they go. Writes nothing.
68
+ *
69
+ * Refuses a folder that already holds a gateway.yaml or policy.yaml, and an
70
+ * id already in the console's list.
71
+ */
72
+ export declare function planNewToolbox(input: NewToolboxInput, registryPath: string): NewToolboxPlan;
73
+ /**
74
+ * Writes a planned toolbox: both files (never over one that appeared since
75
+ * the plan), then its row in the console's list. Either all of it is there
76
+ * afterwards, or none of it.
77
+ */
78
+ export declare function writeNewToolbox(plan: NewToolboxPlan, registryPath: string): NewToolbox;
79
+ /**
80
+ * Takes a toolbox `writeNewToolbox` made away again: its row (only while it
81
+ * still names these files), then its files and the folder made for it. The
82
+ * files go even when the row can't be taken out; that refusal is still thrown.
83
+ */
84
+ export declare function removeNewToolbox(made: NewToolbox, registryPath: string): void;
@@ -0,0 +1,209 @@
1
+ import { existsSync, mkdirSync, rmdirSync, unlinkSync, writeFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join, resolve } from "node:path";
4
+ import { stringify } from "yaml";
5
+ import { readRegistry, writeRegistry } from "hmcp-core";
6
+ import { emitPolicyYaml, isLocalTarget, loadGatewayConfig } from "hmcp-gateway";
7
+ import { conflict, unprocessable } from "../http.js";
8
+ import { applyPolicyChanges, unchangedBatch } from "./gateway-config.js";
9
+ /** An id is at most 64 characters, the registry's rule. */
10
+ const MAX_ID = 64;
11
+ /** How many numbered ids to try before saying so. */
12
+ const MAX_ID_TRIES = 1000;
13
+ export function uniqueId(base, taken) {
14
+ if (!taken.has(base))
15
+ return base;
16
+ for (let n = 2; n <= MAX_ID_TRIES; n++) {
17
+ // The name is shortened to make room, so a 64-character name still gets a different id.
18
+ const suffix = `-${n}`;
19
+ const candidate = `${base.slice(0, MAX_ID - suffix.length)}${suffix}`;
20
+ if (!taken.has(candidate))
21
+ return candidate;
22
+ }
23
+ throw conflict(`every id from "${base}" to "${base}-${MAX_ID_TRIES}" is taken; choose another name`);
24
+ }
25
+ /** Drops the keys `UpstreamSchema` filled with nothing, so the file says only what was chosen. */
26
+ function prune(upstream) {
27
+ const out = {};
28
+ for (const [key, value] of Object.entries(upstream)) {
29
+ if (Array.isArray(value) && value.length === 0)
30
+ continue;
31
+ if (value !== null && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0)
32
+ continue;
33
+ if (key === "credential_passthrough" && value.enabled === false)
34
+ continue;
35
+ out[key] = value;
36
+ }
37
+ return out;
38
+ }
39
+ /** Whether a value in env or headers is written as itself rather than as a locked-key reference. */
40
+ function hasLiteral(upstream) {
41
+ const values = Object.values(upstream.transport === "stdio" ? upstream.env : upstream.headers);
42
+ return values.some((v) => typeof v === "string");
43
+ }
44
+ /** What switching the private-address protection off lets through, as POST /gateways words it. */
45
+ export function localLoosens(local) {
46
+ if (local.length === 0)
47
+ return [];
48
+ return [`allow connections to this computer and the local network (${local.join(", ")})`, "allow plain http:// and bare IP addresses"];
49
+ }
50
+ /**
51
+ * The new toolbox's files as text, and where they go. Writes nothing.
52
+ *
53
+ * Refuses a folder that already holds a gateway.yaml or policy.yaml, and an
54
+ * id already in the console's list.
55
+ */
56
+ export function planNewToolbox(input, registryPath) {
57
+ const posture = input.posture ?? "approve-writes";
58
+ const mode = input.mode ?? "observe";
59
+ const onUnclassified = input.onUnclassified ?? "approve";
60
+ const upstreams = input.upstreams;
61
+ const names = upstreams.map((u) => u.name);
62
+ const dir = input.dir ?? join(homedir(), ".hmcp", "gateways", input.name);
63
+ const configPath = join(dir, "gateway.yaml");
64
+ const policyPath = join(dir, "policy.yaml");
65
+ for (const path of [configPath, policyPath]) {
66
+ if (existsSync(path))
67
+ throw conflict(`${path} already exists; choose another name or folder`);
68
+ }
69
+ const taken = new Set(readRegistry(registryPath).servers.map((s) => s.id));
70
+ if (input.id && taken.has(input.id))
71
+ throw conflict(`a server with id "${input.id}" is already registered`);
72
+ const id = input.id ?? uniqueId(input.name, taken);
73
+ // A `{ secret }` reference is a name, not a value, so only literals earn the warning.
74
+ const literals = upstreams.some(hasLiteral);
75
+ const hosts = upstreams.flatMap((u) => (u.transport === "http" ? [new URL(u.url).hostname] : []));
76
+ /*
77
+ * A server on this computer or the local network is reachable only with
78
+ * the private-address protections off, for every HTTP server of this
79
+ * gateway. That is a loosening, so the caller has it confirmed like any other.
80
+ */
81
+ const local = [...new Set(hosts.filter((h) => isLocalTarget(h)))];
82
+ const plan = {
83
+ upstreams: upstreams.map((upstream) => ({ upstream, originalName: upstream.name, warnings: [] })),
84
+ skipped: [],
85
+ gatewayEnv: {},
86
+ egressAllow: [...new Set(hosts)].sort(),
87
+ egressNeedsLocalHttp: local.length > 0,
88
+ secretsOnDisk: literals,
89
+ nameMap: new Map(),
90
+ malformed: []
91
+ };
92
+ const gatewayYaml = [
93
+ "# Created in the hardened-mcp console. policy.yaml beside this file decides",
94
+ "# what each tool may do.",
95
+ ...(literals
96
+ ? ["#", "# A value set in env or headers below is stored here as written. If it is a", "# credential, do not share or commit this file."]
97
+ : []),
98
+ "",
99
+ stringify({ version: 1, name: input.name, policy: "./policy.yaml", upstreams: upstreams.map(prune), on_injection: "strip", namespace: true }, { lineWidth: 0 })
100
+ ].join("\n");
101
+ const emitted = emitPolicyYaml(plan, {
102
+ name: input.name,
103
+ posture,
104
+ enforcement: mode,
105
+ onUnclassified
106
+ })
107
+ .replace("# Generated by `hmcp-gateway adopt`.", "# Created in the hardened-mcp console.")
108
+ .replace(`\nname: ${input.name}-adopted\n`, `\nname: ${input.name}\n`);
109
+ const batch = input.policyChanges && input.policyChanges.length > 0 ? applyPolicyChanges(emitted, input.policyChanges, policyPath) : unchangedBatch(emitted);
110
+ return {
111
+ name: input.name,
112
+ id,
113
+ label: input.label ?? input.name,
114
+ dir,
115
+ configPath,
116
+ policyPath,
117
+ gatewayYaml,
118
+ policyYaml: batch.text,
119
+ upstreamNames: names,
120
+ posture,
121
+ mode,
122
+ literals,
123
+ local,
124
+ loosens: batch.loosens
125
+ };
126
+ }
127
+ /**
128
+ * Writes a planned toolbox: both files (never over one that appeared since
129
+ * the plan), then its row in the console's list. Either all of it is there
130
+ * afterwards, or none of it.
131
+ */
132
+ export function writeNewToolbox(plan, registryPath) {
133
+ const { dir, configPath, policyPath } = plan;
134
+ // A toolbox can't be empty (gateway.yaml needs at least one server): refused before anything is written.
135
+ if (plan.upstreamNames.length === 0)
136
+ throw unprocessable("a toolbox needs at least one server, so nothing was written");
137
+ const createdDir = !existsSync(dir);
138
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
139
+ const files = [];
140
+ try {
141
+ // `wx`: a file that appeared since the check above is still not overwritten.
142
+ writeFileSync(configPath, plan.gatewayYaml, { encoding: "utf8", mode: 0o600, flag: "wx" });
143
+ files.push(configPath);
144
+ writeFileSync(policyPath, plan.policyYaml, { encoding: "utf8", mode: 0o600, flag: "wx" });
145
+ files.push(policyPath);
146
+ loadGatewayConfig(configPath);
147
+ }
148
+ catch (err) {
149
+ // Only what this wrote goes: a file that appeared meanwhile (EEXIST) is someone else's.
150
+ removeToolboxFiles({ dir, createdDir, files });
151
+ if (err.code === "EEXIST")
152
+ throw conflict(`${err.message}; nothing was written`);
153
+ throw unprocessable(`the gateway could not be written: ${err.message}`);
154
+ }
155
+ const written = { id: plan.id, configPath, policyPath, dir, createdDir, files };
156
+ const entry = {
157
+ id: plan.id,
158
+ kind: "gateway",
159
+ label: plan.label,
160
+ config_path: configPath,
161
+ added_at: new Date().toISOString()
162
+ };
163
+ try {
164
+ const reg = readRegistry(registryPath);
165
+ // Taken while servers were being tested: the files go again, and the row is not written twice.
166
+ if (reg.servers.some((s) => s.id === plan.id))
167
+ throw conflict(`a server with id "${plan.id}" is already registered`);
168
+ writeRegistry({ ...reg, servers: [...reg.servers, entry] }, registryPath);
169
+ }
170
+ catch (err) {
171
+ removeToolboxFiles(written);
172
+ throw err;
173
+ }
174
+ return { ...written, entry };
175
+ }
176
+ /**
177
+ * The files this toolbox wrote, and the folder when it was made for it and
178
+ * is empty now. Anything else in the folder, and the folder holding it, stays.
179
+ */
180
+ function removeToolboxFiles(made) {
181
+ for (const path of made.files)
182
+ if (existsSync(path))
183
+ unlinkSync(path);
184
+ if (!made.createdDir)
185
+ return;
186
+ try {
187
+ rmdirSync(made.dir);
188
+ }
189
+ catch (err) {
190
+ if (err.code !== "ENOTEMPTY" && err.code !== "EEXIST")
191
+ throw err;
192
+ }
193
+ }
194
+ /**
195
+ * Takes a toolbox `writeNewToolbox` made away again: its row (only while it
196
+ * still names these files), then its files and the folder made for it. The
197
+ * files go even when the row can't be taken out; that refusal is still thrown.
198
+ */
199
+ export function removeNewToolbox(made, registryPath) {
200
+ try {
201
+ const reg = readRegistry(registryPath);
202
+ const kept = reg.servers.filter((s) => !(s.id === made.id && resolve(s.config_path) === resolve(made.configPath)));
203
+ if (kept.length !== reg.servers.length)
204
+ writeRegistry({ ...reg, servers: kept }, registryPath);
205
+ }
206
+ finally {
207
+ removeToolboxFiles(made);
208
+ }
209
+ }
@@ -2,6 +2,7 @@ import { type Decision, type StandingGrantRow, type ArgConstraint, type ToolSurf
2
2
  import { type LoadedServer } from "./server.js";
3
3
  import { ENFORCEMENT_PIPELINE } from "./pipeline.js";
4
4
  import { type ToolSurfaceView } from "./tools.js";
5
+ import type { ProvisionalTool } from "./provisional-tools.js";
5
6
  /**
6
7
  * The protection view model.
7
8
  *
@@ -163,6 +164,23 @@ export interface ToolProtection {
163
164
  * `true` closed, `false` explicitly open, `null` the upstream did not say.
164
165
  */
165
166
  readonly schemaClosed: boolean | null;
167
+ /**
168
+ * The top-level inputs the governing rule's limits leave unlimited.
169
+ *
170
+ * Only for a rule that has limits and lets every other input through
171
+ * (`unknown_args: allow`): such a rule reads as protecting the whole tool,
172
+ * while an extra input like `force: true` is never checked. A bound on any
173
+ * path under an input (`meta.tag`, `items[].qty`) covers it. Names only,
174
+ * never values. Empty when the rule has no limits, or blocks or asks about
175
+ * the inputs they don't mention, since then nothing is let through unseen.
176
+ */
177
+ readonly unboundedInputs: readonly string[];
178
+ /**
179
+ * The tool accepts inputs its schema doesn't name, somewhere the limits
180
+ * don't fully reach, so `unboundedInputs` is not the whole list. Without
181
+ * this the console would read as complete when it is not.
182
+ */
183
+ readonly unboundedOpen: boolean;
166
184
  readonly standingGrants: readonly {
167
185
  readonly grantId: string;
168
186
  readonly reason: string;
@@ -221,6 +239,8 @@ export interface ServerProtection {
221
239
  readonly hiddenCount: number;
222
240
  /** Tools the gateway could not classify, which it refuses. */
223
241
  readonly unclassifiedCount: number;
242
+ /** What the servers offered when tested on the way in, read-only until the toolbox runs (see `ToolSurfaceView`). */
243
+ readonly provisional: readonly ProvisionalTool[];
224
244
  };
225
245
  readonly onUnclassified: string;
226
246
  /**
@@ -374,6 +394,6 @@ export type Reach = "read-only" | "approve-writes" | "locked";
374
394
  */
375
395
  export declare function effectiveReach(server: LoadedServer, tenant: string, surface?: ToolSurfaceView): Reach | null;
376
396
  export declare function toolProtection(server: LoadedServer, tool: ToolSurfaceEntry, grants: readonly StandingGrantRow[]): ToolProtection;
377
- export declare function buildProtection(server: LoadedServer, tenant: string, explicit?: boolean): ServerProtection;
397
+ export declare function buildProtection(server: LoadedServer, tenant: string, explicit?: boolean, registryPath?: string): ServerProtection;
378
398
  /** The last few decisions recorded for one tool. */
379
399
  export declare function recentActivity(server: LoadedServer, tool: string, limit?: number, otherComponents?: readonly string[]): import("hmcp-core").AuditRecord[];
@@ -1,7 +1,8 @@
1
1
  import { existsSync } from "node:fs";
2
- import { decide, globMatch, parseArgPath, grantBoundGaps, grantConstraints, grantCoversTool, policyDigest, queryAuditLog, resolveEffect, runtimeStateIsLive, verifyAuditLog } from "hmcp-core";
2
+ import { decide, globMatch, parseArgPath, grantBoundGaps, grantConstraints, grantCoversTool, policyDigest, queryAuditLog, resolveEffect, verifyAuditLog } from "hmcp-core";
3
3
  import { describeTenantSource, scopedFor, storeFor } from "./server.js";
4
4
  import { ENFORCEMENT_PIPELINE } from "./pipeline.js";
5
+ import { toolboxLabel } from "./toolbox-label.js";
5
6
  import { toolSurfaceFor } from "./tools.js";
6
7
  /** Which of `decide()`'s four stages produced a verdict, named from its rule id. */
7
8
  function verdictStage(ruleId) {
@@ -90,6 +91,61 @@ function boundsArg(rule, name) {
90
91
  }
91
92
  return false;
92
93
  }
94
+ const sameStep = (a, b) => a.kind === b.kind && (a.kind === "items" || a.name === b.name);
95
+ /** True when `inner` is `outer` or sits beneath it, compared as patterns. */
96
+ const atOrUnder = (inner, outer) => outer.length <= inner.length && outer.every((step, i) => sameStep(step, inner[i]));
97
+ const pathText = (at) => at.map((s, i) => (s.kind === "items" ? "[]" : i === 0 ? s.name : `.${s.name}`)).join("");
98
+ const asNode = (raw) => (typeof raw === "object" && raw !== null && !Array.isArray(raw) ? raw : {});
99
+ /**
100
+ * What the matched rule's limits leave unlimited, walked through the input
101
+ * schema the way `findUnknownArgs` walks a call.
102
+ *
103
+ * A bound claims its own path and everything under it, and nothing beside it:
104
+ * `meta.tag` leaves `meta.other` unclaimed, and `items[].qty` leaves
105
+ * `items[].sku`. So an input no bound touches is listed whole, one a bound
106
+ * reaches into is walked, and one a bound claims is skipped. Where the schema
107
+ * leaves room for inputs it doesn't name, the list cannot be complete, and
108
+ * `unboundedOpen` says so. Only for a rule with limits that lets everything
109
+ * else through, and not for one that blocks the tool anyway.
110
+ */
111
+ function unboundedOf(rule, inputSchema) {
112
+ const none = { unboundedInputs: [], unboundedOpen: false };
113
+ if (!rule || rule.decision === "deny" || rule.unknown_args !== "allow")
114
+ return none;
115
+ const specs = [];
116
+ for (const spec of Object.keys(rule.args ?? {})) {
117
+ const parsed = parseArgPath(spec);
118
+ if (parsed.ok)
119
+ specs.push(parsed.segments);
120
+ }
121
+ if (specs.length === 0)
122
+ return none;
123
+ const inputs = [];
124
+ let open = false;
125
+ const place = (at, node) => {
126
+ if (specs.some((spec) => atOrUnder(at, spec)))
127
+ return;
128
+ if (specs.some((spec) => spec.length > at.length && atOrUnder(spec, at)))
129
+ visit(at, node);
130
+ else
131
+ inputs.push(pathText(at));
132
+ };
133
+ // `at` is reached into by some bound but claimed by none.
134
+ const visit = (at, raw) => {
135
+ const node = asNode(raw);
136
+ if (node["type"] === "array" || node["items"] !== undefined) {
137
+ place([...at, { kind: "items" }], node["items"]);
138
+ return;
139
+ }
140
+ const props = node["properties"];
141
+ if (typeof props !== "object" || props === null || node["additionalProperties"] !== false)
142
+ open = true;
143
+ for (const [name, child] of Object.entries(asNode(props)))
144
+ place([...at, { kind: "key", name }], child);
145
+ };
146
+ visit([], inputSchema);
147
+ return { unboundedInputs: inputs, unboundedOpen: open };
148
+ }
93
149
  export function toolProtection(server, tool, grants) {
94
150
  const policy = server.policy;
95
151
  const effect = tool.effect ?? undefined;
@@ -147,6 +203,7 @@ export function toolProtection(server, tool, grants) {
147
203
  defaultIsUrl: isHttpUrl(node.defaultValue)
148
204
  })),
149
205
  schemaClosed: schema.additionalProperties === false ? true : schema.additionalProperties === true ? false : null,
206
+ ...unboundedOf(matchedRule, tool.inputSchema),
150
207
  standingGrants: grants.map((grant) => {
151
208
  const match = grantCoversTool(grant, tool.name, decision.effect);
152
209
  return {
@@ -334,9 +391,9 @@ function ruleRows(policy, toolNames) {
334
391
  };
335
392
  });
336
393
  }
337
- export function buildProtection(server, tenant, explicit = false) {
394
+ export function buildProtection(server, tenant, explicit = false, registryPath) {
338
395
  const policy = server.policy;
339
- const surface = toolSurfaceFor(server, tenant);
396
+ const surface = toolSurfaceFor(server, tenant, registryPath);
340
397
  const toolNames = surface.entries.map((t) => t.name);
341
398
  const store = storeFor(server);
342
399
  const scoped = scopedFor(server, tenant);
@@ -365,19 +422,20 @@ export function buildProtection(server, tenant, explicit = false) {
365
422
  * A row from a process that has stopped refreshing is ignored rather than
366
423
  * trusted: it describes a server that is no longer deciding anything, and
367
424
  * quoting it would be a second way of saying something untrue about what is
368
- * in force.
425
+ * in force. Whether anything is running is the shared judgement
426
+ * (`liveProcesses`): when only a twin process is, the page says running and
427
+ * leaves the start time and policy unknown, as `status` does.
369
428
  */
370
- const announced = store.runtimeState(server.component);
371
- const live = announced && runtimeStateIsLive(announced) ? announced : undefined;
429
+ const live = store.liveRuntimeState(server.component);
372
430
  const runtime = {
373
- running: live !== undefined,
431
+ running: store.liveProcesses(server.component).length > 0,
374
432
  startedAt: live?.started_at ?? null,
375
433
  policyApplied: live ? live.policy_digest === policyDigest(policy) : null,
376
434
  policyPath: live?.policy_path || server.policyPath
377
435
  };
378
436
  return {
379
437
  id: server.entry.id,
380
- label: server.entry.label,
438
+ label: toolboxLabel(server.entry, server.gateway.config.name),
381
439
  kind: server.entry.kind,
382
440
  tenant_scope: tenant,
383
441
  explicitTenant: explicit,
@@ -391,7 +449,8 @@ export function buildProtection(server, tenant, explicit = false) {
391
449
  toolCount: surface.entries.length,
392
450
  injectionCount: surface.entries.filter((t) => t.injection && t.injection.length > 0).length,
393
451
  hiddenCount: surface.entries.filter((t) => t.hiddenByPolicy).length,
394
- unclassifiedCount: surface.entries.filter((t) => t.effect === null).length
452
+ unclassifiedCount: surface.entries.filter((t) => t.effect === null).length,
453
+ provisional: surface.provisional
395
454
  },
396
455
  onUnclassified: policy.defaults.on_unclassified,
397
456
  enforcement: policy.enforcement,
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+ import type { ProbeTool } from "hmcp-gateway";
3
+ import type { LoadedServer } from "./server.js";
4
+ /**
5
+ * The tools a server offered when it was tested on the way into a toolbox,
6
+ * kept so the console can show them before the toolbox has ever run.
7
+ *
8
+ * A toolbox's real tool list is the one its running process publishes, and
9
+ * only that list is trusted for a switch or a rule. This list is not that: it
10
+ * is what a test saw, read-only, and shown only until the toolbox is live. It
11
+ * never joins `entries`, so nothing that writes protection can name a tool
12
+ * from it.
13
+ *
14
+ * Each server's list carries what the server ran as it was tested
15
+ * (`upstreamDigest`), and is dropped the moment gateway.yaml says something
16
+ * else: a list for a server changed since is a list for a server that isn't
17
+ * there. Names only: no settings, keys, command lines or addresses.
18
+ */
19
+ /** A server's own text, so a server offering huge names or thousands of tools can't make the note, or the page, unbounded. */
20
+ export declare const MAX_NAME = 200;
21
+ export declare const MAX_TOOLS_PER_SERVER = 500;
22
+ export declare const MAX_SERVERS = 100;
23
+ export declare const ProvisionalToolSchema: z.ZodObject<{
24
+ name: z.ZodString;
25
+ upstream: z.ZodString;
26
+ effect: z.ZodEnum<{
27
+ read: "read";
28
+ write: "write";
29
+ destructive: "destructive";
30
+ unknown: "unknown";
31
+ }>;
32
+ verdict: z.ZodEnum<{
33
+ run: "run";
34
+ ask: "ask";
35
+ blocked: "blocked";
36
+ }>;
37
+ withheld: z.ZodOptional<z.ZodString>;
38
+ }, z.core.$strict>;
39
+ export type ProvisionalTool = z.infer<typeof ProvisionalToolSchema>;
40
+ /** `<registry folder>/provisional/<toolbox id>.json`; an id that isn't plain is hashed, so no id becomes a path. */
41
+ export declare function provisionalPath(registryPath: string, gatewayId: string): string;
42
+ /** Keeps what these servers offered when tested; a server listed before is replaced. */
43
+ export declare function saveProvisional(registryPath: string, gatewayId: string, probed: readonly {
44
+ upstream: string;
45
+ digest: string;
46
+ tools: readonly ProbeTool[];
47
+ }[], now?: Date): void;
48
+ /** Drops these servers' lists, or the whole file when `upstreams` is left out. */
49
+ export declare function removeProvisional(registryPath: string, gatewayId: string, upstreams?: readonly string[]): void;
50
+ /**
51
+ * The tools to show for a toolbox that isn't live, each only while
52
+ * gateway.yaml still has its server exactly as it was tested, and only when
53
+ * the test is newer than the last list the toolbox published (`publishedAt`,
54
+ * null when it never published): an older test says less than that list.
55
+ */
56
+ export declare function provisionalFor(registryPath: string, server: LoadedServer, publishedAt?: number | null): ProvisionalTool[];