agent-relay-server 0.60.1 → 0.61.1
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/docs/openapi.json +361 -1
- package/package.json +3 -2
- package/public/assets/{MessageBubble-vzupFQD8.js → MessageBubble-CX63ZV4X.js} +2 -2
- package/public/assets/{MessageBubble-vzupFQD8.js.map → MessageBubble-CX63ZV4X.js.map} +1 -1
- package/public/assets/{PlanGraphPanel-DQvycBMW.js → PlanGraphPanel-Dby7wq9c.js} +2 -2
- package/public/assets/{PlanGraphPanel-DQvycBMW.js.map → PlanGraphPanel-Dby7wq9c.js.map} +1 -1
- package/public/assets/{activity-gmfkOBhQ.js → activity-2xPOScu_.js} +2 -2
- package/public/assets/{activity-gmfkOBhQ.js.map → activity-2xPOScu_.js.map} +1 -1
- package/public/assets/{agent-profiles-7X8gFuwj.js → agent-profiles-BfGTTbeY.js} +2 -2
- package/public/assets/{agent-profiles-7X8gFuwj.js.map → agent-profiles-BfGTTbeY.js.map} +1 -1
- package/public/assets/agents-Bg3WOBRV.js +2 -0
- package/public/assets/{agents-D201CuTR.js.map → agents-Bg3WOBRV.js.map} +1 -1
- package/public/assets/{analytics-CkOTrr5t.js → analytics-De0cEZGx.js} +3 -3
- package/public/assets/{analytics-CkOTrr5t.js.map → analytics-De0cEZGx.js.map} +1 -1
- package/public/assets/{automation-_5u-nVs8.js → automation-CHxhzq2t.js} +2 -2
- package/public/assets/{automation-_5u-nVs8.js.map → automation-CHxhzq2t.js.map} +1 -1
- package/public/assets/{badge-Cy6qO_Jz.js → badge-DhLyCPag.js} +2 -2
- package/public/assets/{badge-Cy6qO_Jz.js.map → badge-DhLyCPag.js.map} +1 -1
- package/public/assets/branch-state-badge-DSyWKluD.js +2 -0
- package/public/assets/{branch-state-badge-BPXXLpQG.js.map → branch-state-badge-DSyWKluD.js.map} +1 -1
- package/public/assets/{button-73wpRw65.js → button-K20wAZG1.js} +2 -2
- package/public/assets/{button-73wpRw65.js.map → button-K20wAZG1.js.map} +1 -1
- package/public/assets/card-CcZ9hLI7.js +2 -0
- package/public/assets/{card-BU6PvVHv.js.map → card-CcZ9hLI7.js.map} +1 -1
- package/public/assets/{channels-BsJu5TXR.js → channels-BG0Nib7y.js} +2 -2
- package/public/assets/{channels-BsJu5TXR.js.map → channels-BG0Nib7y.js.map} +1 -1
- package/public/assets/chat-CjP_crSl.js +2 -0
- package/public/assets/{chat-CHgPGHQD.js.map → chat-CjP_crSl.js.map} +1 -1
- package/public/assets/{connectors-arjfBQvc.js → connectors-DWh7MwV_.js} +2 -2
- package/public/assets/{connectors-arjfBQvc.js.map → connectors-DWh7MwV_.js.map} +1 -1
- package/public/assets/{copy-button-HRopUwui.js → copy-button-eF3cKp4Q.js} +2 -2
- package/public/assets/{copy-button-HRopUwui.js.map → copy-button-eF3cKp4Q.js.map} +1 -1
- package/public/assets/display-DzNvOu1j.js +3 -0
- package/public/assets/{display-CketawEF.js.map → display-DzNvOu1j.js.map} +1 -1
- package/public/assets/{dist-Kkpnjx_M.js → dist-1dhfdhm9.js} +2 -2
- package/public/assets/{dist-Kkpnjx_M.js.map → dist-1dhfdhm9.js.map} +1 -1
- package/public/assets/dist-BLBF7qqr.js +2 -0
- package/public/assets/{dist-De2oguBm.js.map → dist-BLBF7qqr.js.map} +1 -1
- package/public/assets/{dist-T7u7IZGJ.js → dist-BrQsqBbc.js} +2 -2
- package/public/assets/{dist-T7u7IZGJ.js.map → dist-BrQsqBbc.js.map} +1 -1
- package/public/assets/{dist-Cko2KPW8.js → dist-COQuunEv.js} +2 -2
- package/public/assets/{dist-Cko2KPW8.js.map → dist-COQuunEv.js.map} +1 -1
- package/public/assets/{dist-CLHMeXYi.js → dist-Ci5Y37nj.js} +2 -2
- package/public/assets/{dist-CLHMeXYi.js.map → dist-Ci5Y37nj.js.map} +1 -1
- package/public/assets/{dist-Ci1MM51P.js → dist-CoROafNg.js} +2 -2
- package/public/assets/{dist-Ci1MM51P.js.map → dist-CoROafNg.js.map} +1 -1
- package/public/assets/{dist-CC5f7oYw.js → dist-I-MFUv51.js} +2 -2
- package/public/assets/{dist-CC5f7oYw.js.map → dist-I-MFUv51.js.map} +1 -1
- package/public/assets/{dist-DFLciw0h.js → dist-UQGKwqZH.js} +2 -2
- package/public/assets/{dist-DFLciw0h.js.map → dist-UQGKwqZH.js.map} +1 -1
- package/public/assets/dist-YpHfnnIA.js +2 -0
- package/public/assets/{dist-DUoZnlB2.js.map → dist-YpHfnnIA.js.map} +1 -1
- package/public/assets/dist-qd198ib9.js +2 -0
- package/public/assets/{dist-D41tzJYg.js.map → dist-qd198ib9.js.map} +1 -1
- package/public/assets/{dist-DmN94rc8.js → dist-yGOq6sB3.js} +2 -2
- package/public/assets/{dist-DmN94rc8.js.map → dist-yGOq6sB3.js.map} +1 -1
- package/public/assets/{es2015-Df08Opjx.js → es2015-CRxz9lOj.js} +2 -2
- package/public/assets/{es2015-Df08Opjx.js.map → es2015-CRxz9lOj.js.map} +1 -1
- package/public/assets/{formatted-body-impl-DBt5tnS0.js → formatted-body-impl-u0W_hWYA.js} +2 -2
- package/public/assets/{formatted-body-impl-DBt5tnS0.js.map → formatted-body-impl-u0W_hWYA.js.map} +1 -1
- package/public/assets/index-BwfVOzUG.js +21 -0
- package/public/assets/{index-D7js3XlH.js.map → index-BwfVOzUG.js.map} +1 -1
- package/public/assets/index-Dn_GDXbi.css +2 -0
- package/public/assets/{input-B2EDz-BE.js → input-BHYNpXAG.js} +2 -2
- package/public/assets/{input-B2EDz-BE.js.map → input-BHYNpXAG.js.map} +1 -1
- package/public/assets/{insights-BvjkOXk9.js → insights-CAF9Hi5D.js} +2 -2
- package/public/assets/{insights-BvjkOXk9.js.map → insights-CAF9Hi5D.js.map} +1 -1
- package/public/assets/{integrations-7L1f3eIE.js → integrations-CG9qyHUf.js} +2 -2
- package/public/assets/{integrations-7L1f3eIE.js.map → integrations-CG9qyHUf.js.map} +1 -1
- package/public/assets/{lib-BZrjIp-o.js → lib-Df4aph5u.js} +2 -2
- package/public/assets/{lib-BZrjIp-o.js.map → lib-Df4aph5u.js.map} +1 -1
- package/public/assets/lucide-react-L2UxFDic.js +9 -0
- package/public/assets/lucide-react-L2UxFDic.js.map +1 -0
- package/public/assets/{maintenance-BBoL--vs.js → maintenance-DgHA35ve.js} +2 -2
- package/public/assets/{maintenance-BBoL--vs.js.map → maintenance-DgHA35ve.js.map} +1 -1
- package/public/assets/{managed-agents-BjYBzVZt.js → managed-agents-Rk6ghKR9.js} +2 -2
- package/public/assets/{managed-agents-BjYBzVZt.js.map → managed-agents-Rk6ghKR9.js.map} +1 -1
- package/public/assets/{markdown-preview-impl-BnwjZsmO.js → markdown-preview-impl-NWMtJdYz.js} +2 -2
- package/public/assets/{markdown-preview-impl-BnwjZsmO.js.map → markdown-preview-impl-NWMtJdYz.js.map} +1 -1
- package/public/assets/memory-DamwWa9A.js +2 -0
- package/public/assets/{memory-SLycz2gC.js.map → memory-DamwWa9A.js.map} +1 -1
- package/public/assets/{messages-DfSCTe6N.js → messages--NU-YIL6.js} +2 -2
- package/public/assets/{messages-DfSCTe6N.js.map → messages--NU-YIL6.js.map} +1 -1
- package/public/assets/{orchestrators-BwxdTQm_.js → orchestrators-DQnIn6qx.js} +2 -2
- package/public/assets/{orchestrators-BwxdTQm_.js.map → orchestrators-DQnIn6qx.js.map} +1 -1
- package/public/assets/{overview-Djy3qkY5.js → overview-DCmNgXDf.js} +2 -2
- package/public/assets/{overview-Djy3qkY5.js.map → overview-DCmNgXDf.js.map} +1 -1
- package/public/assets/{pairs-9KNduLnC.js → pairs-DNELeC9P.js} +2 -2
- package/public/assets/{pairs-9KNduLnC.js.map → pairs-DNELeC9P.js.map} +1 -1
- package/public/assets/{react-dom-WI6TjVe7.js → react-dom-CrP_AtcL.js} +2 -2
- package/public/assets/{react-dom-WI6TjVe7.js.map → react-dom-CrP_AtcL.js.map} +1 -1
- package/public/assets/{security-tG3q7fFW.js → security-Dd3Kh0oC.js} +2 -2
- package/public/assets/{security-tG3q7fFW.js.map → security-Dd3Kh0oC.js.map} +1 -1
- package/public/assets/{select-CGUdMNOG.js → select-DQbeJZX0.js} +2 -2
- package/public/assets/{select-CGUdMNOG.js.map → select-DQbeJZX0.js.map} +1 -1
- package/public/assets/settings-BMAJrBIH.js +4 -0
- package/public/assets/settings-BMAJrBIH.js.map +1 -0
- package/public/assets/store-B8xP6z6T.js +9 -0
- package/public/assets/store-B8xP6z6T.js.map +1 -0
- package/public/assets/tasks-BYR4L9GP.js +2 -0
- package/public/assets/{tasks-DWlKg218.js.map → tasks-BYR4L9GP.js.map} +1 -1
- package/public/assets/teams-CoTifrq_.js +2 -0
- package/public/assets/{teams-DRchUP_p.js.map → teams-CoTifrq_.js.map} +1 -1
- package/public/assets/{terminal-viewer-impl-D_Sqe-vo.js → terminal-viewer-impl-B1YzfpE6.js} +3 -3
- package/public/assets/{terminal-viewer-impl-D_Sqe-vo.js.map → terminal-viewer-impl-B1YzfpE6.js.map} +1 -1
- package/public/assets/{use-keyboard-viewport-fOL_3RHB.js → use-keyboard-viewport-DrRH_QzG.js} +2 -2
- package/public/assets/{use-keyboard-viewport-fOL_3RHB.js.map → use-keyboard-viewport-DrRH_QzG.js.map} +1 -1
- package/public/assets/{work-queue-HNcyjON9.js → work-queue-x57vlgyZ.js} +2 -2
- package/public/assets/{work-queue-HNcyjON9.js.map → work-queue-x57vlgyZ.js.map} +1 -1
- package/public/assets/{workspaces-CicYE2Ax.js → workspaces-CYm5bLg9.js} +3 -3
- package/public/assets/{workspaces-CicYE2Ax.js.map → workspaces-CYm5bLg9.js.map} +1 -1
- package/public/index.html +22 -22
- package/runner/src/config.ts +66 -2
- package/src/automations.ts +3 -4
- package/src/config-store.ts +5 -6
- package/src/connectors.ts +5 -0
- package/src/db/migrations.ts +6 -0
- package/src/db/schema.ts +1 -1
- package/src/index.ts +5 -2
- package/src/mcp-provider-catalog.ts +9 -0
- package/src/mcp.ts +4 -4
- package/src/provider-catalog-store.ts +33 -4
- package/src/provider-config-store.ts +216 -0
- package/src/recipe-runner.ts +2 -1
- package/src/recipe-validator.ts +4 -3
- package/src/routes/agents-spawn.ts +2 -2
- package/src/routes/index.ts +12 -2
- package/src/routes/insights.ts +4 -3
- package/src/routes/orchestrator.ts +21 -1
- package/src/routes/provider-config.ts +89 -41
- package/src/routes/settings.ts +127 -0
- package/src/routes/steward.ts +5 -5
- package/src/routes/tokens.ts +32 -1
- package/src/security.ts +34 -37
- package/src/settings/modules.ts +149 -0
- package/src/settings/registry.ts +397 -0
- package/src/spawn-command.ts +5 -1
- package/src/team-template-config.ts +2 -2
- package/src/token-db.ts +20 -0
- package/public/assets/agents-D201CuTR.js +0 -2
- package/public/assets/branch-state-badge-BPXXLpQG.js +0 -2
- package/public/assets/card-BU6PvVHv.js +0 -2
- package/public/assets/chat-CHgPGHQD.js +0 -2
- package/public/assets/display-CketawEF.js +0 -3
- package/public/assets/dist-D41tzJYg.js +0 -2
- package/public/assets/dist-DUoZnlB2.js +0 -2
- package/public/assets/dist-De2oguBm.js +0 -2
- package/public/assets/index-D7js3XlH.js +0 -21
- package/public/assets/index-DaNOQJci.css +0 -2
- package/public/assets/lucide-react-H_-8G79A.js +0 -9
- package/public/assets/lucide-react-H_-8G79A.js.map +0 -1
- package/public/assets/memory-SLycz2gC.js +0 -2
- package/public/assets/settings-CGcqyJ5L.js +0 -10
- package/public/assets/settings-CGcqyJ5L.js.map +0 -1
- package/public/assets/store-DXdfhiVf.js +0 -9
- package/public/assets/store-DXdfhiVf.js.map +0 -1
- package/public/assets/tasks-DWlKg218.js +0 -2
- package/public/assets/teams-DRchUP_p.js +0 -2
package/src/security.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { dirname, join, resolve } from "node:path";
|
|
|
5
5
|
import { getDb } from "./db";
|
|
6
6
|
import { isPathWithinBase } from "./utils";
|
|
7
7
|
import type { ComponentToken, TokenConstraints } from "./types";
|
|
8
|
+
import { hasScope, normalizeScope } from "agent-relay-sdk/types";
|
|
8
9
|
|
|
9
10
|
const LOOPBACK_HOSTS = new Set(["127.0.0.1", "::1", "localhost"]);
|
|
10
11
|
|
|
@@ -99,30 +100,7 @@ type AuthorizationCheck = {
|
|
|
99
100
|
resource?: AuthorizationResource;
|
|
100
101
|
};
|
|
101
102
|
|
|
102
|
-
|
|
103
|
-
"admin:*": "system:admin",
|
|
104
|
-
"system:write": "system:admin",
|
|
105
|
-
"agents:read": "agent:read",
|
|
106
|
-
"agents:write": "agent:write",
|
|
107
|
-
"messages:read": "message:read",
|
|
108
|
-
"messages:write": "message:send",
|
|
109
|
-
"tasks:read": "task:read",
|
|
110
|
-
"tasks:write": "task:write",
|
|
111
|
-
"commands:read": "command:read",
|
|
112
|
-
"commands:write": "command:write",
|
|
113
|
-
"channels:read": "channel:read",
|
|
114
|
-
"channels:write": "channel:write",
|
|
115
|
-
"integrations:read": "integration:read",
|
|
116
|
-
"integrations:write": "integration:write",
|
|
117
|
-
"connectors:read": "integration:read",
|
|
118
|
-
"connectors:write": "integration:write",
|
|
119
|
-
"events:create": "integration:write",
|
|
120
|
-
"tasks:create": "task:write",
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
export function normalizeScope(scope: string): string {
|
|
124
|
-
return SCOPE_ALIASES[scope] ?? scope;
|
|
125
|
-
}
|
|
103
|
+
export { normalizeScope };
|
|
126
104
|
|
|
127
105
|
export function getIntegrationAuth(req: Request): IntegrationAuth | null {
|
|
128
106
|
const token = extractToken(req);
|
|
@@ -170,6 +148,8 @@ export function requiredScopeFor(method: string, pathname: string): string | nul
|
|
|
170
148
|
if (pathname === "/api/orchestrators/bootstrap") return "token:write";
|
|
171
149
|
if (pathname.match(/^\/api\/orchestrators\/[^/]+\/logs\//)) return "logs:read";
|
|
172
150
|
if (pathname.match(/^\/api\/orchestrators\/[^/]+\/terminal\//)) return "terminal:attach";
|
|
151
|
+
const settingScope = requiredSettingsScopeFor(method, pathname);
|
|
152
|
+
if (settingScope !== undefined) return settingScope;
|
|
173
153
|
if (pathname.startsWith("/api/artifacts")) {
|
|
174
154
|
if (method === "GET" || method === "HEAD") return "artifact:read";
|
|
175
155
|
if (method === "DELETE") return "artifact:admin";
|
|
@@ -201,6 +181,7 @@ export function requiredScopeFor(method: string, pathname: string): string | nul
|
|
|
201
181
|
if (pathname.startsWith("/api/recipes")) return method === "GET" ? "recipes:read" : "recipes:write";
|
|
202
182
|
if (pathname === "/api/runtime-tokens/renew") return "agent:write";
|
|
203
183
|
if (pathname.startsWith("/api/runtime-tokens")) return "token:write";
|
|
184
|
+
if (pathname === "/api/tokens/me") return null;
|
|
204
185
|
if (pathname.startsWith("/api/tokens") || pathname.startsWith("/api/token-profiles")) return method === "GET" ? "token:read" : "token:write";
|
|
205
186
|
if (pathname.startsWith("/api/maintenance")) return "system:admin";
|
|
206
187
|
if (pathname.startsWith("/api/tasks")) return method === "GET" ? "task:read" : "task:write";
|
|
@@ -251,12 +232,15 @@ export function requiredComponentScopeFor(method: string, pathname: string): str
|
|
|
251
232
|
if (pathname === "/api/mcp") return "mcp:use";
|
|
252
233
|
if (pathname.match(/^\/api\/orchestrators\/[^/]+\/logs\//)) return "logs:read";
|
|
253
234
|
if (pathname.match(/^\/api\/orchestrators\/[^/]+\/terminal\//)) return "terminal:attach";
|
|
235
|
+
const settingScope = requiredSettingsScopeFor(method, pathname);
|
|
236
|
+
if (settingScope !== undefined) return settingScope ?? "system:admin";
|
|
254
237
|
if (pathname.startsWith("/api/commands")) {
|
|
255
238
|
if (method === "GET") return "command:read";
|
|
256
239
|
return "command:write";
|
|
257
240
|
}
|
|
258
241
|
if (pathname.startsWith("/api/merges")) return method === "GET" ? "command:read" : "command:write";
|
|
259
242
|
if (pathname.startsWith("/api/workspaces")) return method === "GET" ? "agent:read" : "agent:write";
|
|
243
|
+
if (pathname === "/api/tokens/me") return null;
|
|
260
244
|
if (pathname.startsWith("/api/tokens") || pathname.startsWith("/api/token-profiles")) return method === "GET" ? "token:read" : "token:write";
|
|
261
245
|
if (pathname.startsWith("/api/maintenance")) return "system:admin";
|
|
262
246
|
if (pathname === "/api/recipes/start") return "recipe:start";
|
|
@@ -298,6 +282,32 @@ export function requiredComponentScopeFor(method: string, pathname: string): str
|
|
|
298
282
|
return "system:admin";
|
|
299
283
|
}
|
|
300
284
|
|
|
285
|
+
const CONFIG_SETTINGS_NAMESPACES = new Set(["steward", "insights", "notifications", "workspace", "landing", "provider"]);
|
|
286
|
+
|
|
287
|
+
function requiredSettingsScopeFor(method: string, pathname: string): string | null | undefined {
|
|
288
|
+
if (pathname === "/api/settings") return method === "GET" ? "settings:read" : null;
|
|
289
|
+
const settingsMatch = pathname.match(/^\/api\/settings\/([^/]+)(?:\/[^/]+)?$/);
|
|
290
|
+
if (settingsMatch) return settingsScope(method, decodeURIComponent(settingsMatch[1]!));
|
|
291
|
+
if (pathname === "/api/steward-config") return settingsScope(method, "steward");
|
|
292
|
+
if (pathname === "/api/workspace-config") return settingsScope(method, "workspace");
|
|
293
|
+
if (pathname === "/api/insights/config") return settingsScope(method, "insights");
|
|
294
|
+
const configMatch = pathname.match(/^\/api\/config\/([^/]+)(?:\/[^/]+)?(?:\/history)?$/);
|
|
295
|
+
if (configMatch) {
|
|
296
|
+
const namespace = decodeURIComponent(configMatch[1]!);
|
|
297
|
+
if (CONFIG_SETTINGS_NAMESPACES.has(namespace)) return settingsScope(method, namespace);
|
|
298
|
+
}
|
|
299
|
+
if (pathname.match(/^\/api\/providers\/[^/]+\/models\/[^/]+$/) && ["PUT", "PATCH", "DELETE"].includes(method)) {
|
|
300
|
+
return "settings:write:provider";
|
|
301
|
+
}
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function settingsScope(method: string, namespace: string): string | null {
|
|
306
|
+
if (method === "GET" || method === "HEAD") return `settings:read:${namespace}`;
|
|
307
|
+
if (["PUT", "PATCH", "POST", "DELETE"].includes(method)) return `settings:write:${namespace}`;
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
|
|
301
311
|
export function signComponentToken(payload: Omit<ComponentToken, "iat"> & { iat?: number }): string {
|
|
302
312
|
const header = { alg: "HS256", typ: "JWT" };
|
|
303
313
|
const body: ComponentToken = {
|
|
@@ -404,19 +414,6 @@ function isComponentToken(value: unknown): value is ComponentToken {
|
|
|
404
414
|
(record.jti === undefined || typeof record.jti === "string");
|
|
405
415
|
}
|
|
406
416
|
|
|
407
|
-
function hasScope(scopes: string[], requiredScope: string): boolean {
|
|
408
|
-
const required = normalizeScope(requiredScope);
|
|
409
|
-
if (scopes.includes("*")) return true;
|
|
410
|
-
for (const rawScope of scopes) {
|
|
411
|
-
const scope = normalizeScope(rawScope);
|
|
412
|
-
if (scope === "system:admin") return true;
|
|
413
|
-
if (scope === required) return true;
|
|
414
|
-
const [category] = required.split(":");
|
|
415
|
-
if (category && scope === `${category}:*`) return true;
|
|
416
|
-
}
|
|
417
|
-
return false;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
417
|
/** Authoritative parent lineage from a registering token's signed constraints — agent-initiated
|
|
421
418
|
* spawn (`spawnedBy`) or the delegating-component path (`parentAgents`). One home, used by both the
|
|
422
419
|
* HTTP `postAgent` route and the bus register path so `spawned_by` is set however a child registers
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SPAWN_PROVIDERS,
|
|
3
|
+
errMessage,
|
|
4
|
+
isRecord,
|
|
5
|
+
type ConnectorManifest,
|
|
6
|
+
type JSONSchema,
|
|
7
|
+
type SettingDescriptor,
|
|
8
|
+
type SettingDisplay,
|
|
9
|
+
type SettingScope,
|
|
10
|
+
type SettingTier,
|
|
11
|
+
} from "agent-relay-sdk";
|
|
12
|
+
import { ValidationError } from "../db";
|
|
13
|
+
import { cleanString } from "../validation";
|
|
14
|
+
import type { ProviderConfig } from "../../runner/src/adapter";
|
|
15
|
+
import { defaultProviderConfig } from "../../runner/src/config";
|
|
16
|
+
import { SETTING_ADMIN_SCOPE, getSettingDescriptor, registerProviderConfigSetting, registerSetting, validateSettingValue } from "./registry";
|
|
17
|
+
|
|
18
|
+
export const CONNECTOR_CONFIG_NAMESPACE = "connector-config";
|
|
19
|
+
export const CHANNEL_TYPE_CONFIG_NAMESPACE = "channel-type";
|
|
20
|
+
|
|
21
|
+
export function registerConnectorConfigSetting(
|
|
22
|
+
manifest: Pick<ConnectorManifest, "id" | "displayName" | "description" | "configSchema">,
|
|
23
|
+
opts: { defaults?: unknown } = {},
|
|
24
|
+
): SettingDescriptor | undefined {
|
|
25
|
+
if (!manifest.configSchema) return undefined;
|
|
26
|
+
const schema = schemaFromRecord(manifest.configSchema, `connector ${manifest.id} configSchema`);
|
|
27
|
+
return registerModuleSetting({
|
|
28
|
+
namespace: CONNECTOR_CONFIG_NAMESPACE,
|
|
29
|
+
key: manifest.id,
|
|
30
|
+
schema,
|
|
31
|
+
defaults: opts.defaults ?? schemaDefault(schema) ?? {},
|
|
32
|
+
scope: { read: "integration:read", write: SETTING_ADMIN_SCOPE },
|
|
33
|
+
tier: "server-runtime",
|
|
34
|
+
display: {
|
|
35
|
+
group: "Connectors",
|
|
36
|
+
label: manifest.displayName || manifest.id,
|
|
37
|
+
description: manifest.description ?? `Configuration for connector ${manifest.id}.`,
|
|
38
|
+
order: 100,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function validateConnectorConfig(manifest: ConnectorManifest, config: unknown): void {
|
|
44
|
+
const descriptor = getSettingDescriptor(CONNECTOR_CONFIG_NAMESPACE, manifest.id) ?? registerConnectorConfigSetting(manifest);
|
|
45
|
+
if (!descriptor) return;
|
|
46
|
+
const validation = validateSettingValue(descriptor.namespace, descriptor.key, config);
|
|
47
|
+
if (!validation.valid) throw new ValidationError(validation.errors.join("; "));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function registerChannelTypeSetting(input: {
|
|
51
|
+
type: string;
|
|
52
|
+
schema: JSONSchema;
|
|
53
|
+
defaults: unknown;
|
|
54
|
+
scope?: Partial<SettingScope>;
|
|
55
|
+
tier?: SettingTier;
|
|
56
|
+
display?: Partial<SettingDisplay>;
|
|
57
|
+
}): SettingDescriptor {
|
|
58
|
+
const type = cleanString(input.type, "channel type", { required: true, max: 80 })!;
|
|
59
|
+
return registerModuleSetting({
|
|
60
|
+
namespace: CHANNEL_TYPE_CONFIG_NAMESPACE,
|
|
61
|
+
key: type,
|
|
62
|
+
schema: input.schema,
|
|
63
|
+
defaults: input.defaults,
|
|
64
|
+
scope: { read: "integration:read", write: SETTING_ADMIN_SCOPE, ...input.scope },
|
|
65
|
+
tier: input.tier ?? "server-runtime",
|
|
66
|
+
display: {
|
|
67
|
+
group: "Channels",
|
|
68
|
+
label: `${type} channel`,
|
|
69
|
+
description: `Configuration for ${type} channel integrations.`,
|
|
70
|
+
order: 120,
|
|
71
|
+
...input.display,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface ProviderSettingsDeclaration {
|
|
77
|
+
provider: string;
|
|
78
|
+
defaults: ProviderConfig;
|
|
79
|
+
display?: Partial<SettingDisplay>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const providerSettingsDeclarations = new Map<string, ProviderSettingsDeclaration>();
|
|
83
|
+
let builtInProvidersSeeded = false;
|
|
84
|
+
|
|
85
|
+
export function registerProviderSettingsDeclaration(input: {
|
|
86
|
+
provider: string;
|
|
87
|
+
defaults?: ProviderConfig;
|
|
88
|
+
display?: Partial<SettingDisplay>;
|
|
89
|
+
}): ProviderSettingsDeclaration {
|
|
90
|
+
const provider = cleanString(input.provider, "provider", { required: true, max: 80 })!;
|
|
91
|
+
const declaration: ProviderSettingsDeclaration = {
|
|
92
|
+
provider,
|
|
93
|
+
defaults: input.defaults ?? defaultProviderConfig(provider),
|
|
94
|
+
display: input.display,
|
|
95
|
+
};
|
|
96
|
+
providerSettingsDeclarations.set(provider, declaration);
|
|
97
|
+
return declaration;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function listProviderSettingsDeclarations(): ProviderSettingsDeclaration[] {
|
|
101
|
+
ensureBuiltInProviderSettingsDeclarations();
|
|
102
|
+
return [...providerSettingsDeclarations.values()];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function getProviderSettingsDeclaration(provider: string): ProviderSettingsDeclaration | undefined {
|
|
106
|
+
ensureBuiltInProviderSettingsDeclarations();
|
|
107
|
+
return providerSettingsDeclarations.get(provider);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function providerConfigDefaults(provider: string): ProviderConfig {
|
|
111
|
+
return getProviderSettingsDeclaration(provider)?.defaults ?? defaultProviderConfig(provider);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function registerDeclaredProviderConfigSetting(input: { host: string; provider: string }): SettingDescriptor {
|
|
115
|
+
const declaration = getProviderSettingsDeclaration(input.provider);
|
|
116
|
+
if (!declaration) throw new ValidationError(`provider must be one of: ${listProviderSettingsDeclarations().map((d) => d.provider).join(", ")}`);
|
|
117
|
+
return registerProviderConfigSetting({
|
|
118
|
+
host: input.host,
|
|
119
|
+
provider: declaration.provider,
|
|
120
|
+
defaults: declaration.defaults,
|
|
121
|
+
display: declaration.display,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function ensureBuiltInProviderSettingsDeclarations(): void {
|
|
126
|
+
if (builtInProvidersSeeded) return;
|
|
127
|
+
builtInProvidersSeeded = true;
|
|
128
|
+
for (const provider of SPAWN_PROVIDERS) {
|
|
129
|
+
registerProviderSettingsDeclaration({ provider, defaults: defaultProviderConfig(provider) });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function registerModuleSetting(input: Parameters<typeof registerSetting>[0]): SettingDescriptor {
|
|
134
|
+
try {
|
|
135
|
+
return registerSetting(input);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
if (error instanceof ValidationError) throw error;
|
|
138
|
+
throw new ValidationError(errMessage(error));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function schemaFromRecord(value: Record<string, unknown>, field: string): JSONSchema {
|
|
143
|
+
if (!isRecord(value)) throw new ValidationError(`${field} must be an object`);
|
|
144
|
+
return value as JSONSchema;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function schemaDefault(schema: JSONSchema): unknown {
|
|
148
|
+
return Object.prototype.hasOwnProperty.call(schema, "default") ? schema.default : undefined;
|
|
149
|
+
}
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
// Settings descriptor registry (epic #380, #382) — the single server-side source
|
|
2
|
+
// of truth for which settings exist, their JSON Schema, defaults, required scope,
|
|
3
|
+
// tier, and display. This is the *declaration* layer over the existing `config`
|
|
4
|
+
// table (src/config-store.ts owns storage + history + the `config.changed` SSE) —
|
|
5
|
+
// it does NOT touch storage. The API (#383), scope enforcement (#385), module
|
|
6
|
+
// wiring (#386), and the Settings UI (#384) all build on this contract.
|
|
7
|
+
//
|
|
8
|
+
// DECISION LOCKED (#380 thread): validation is via `ajv`, descriptors carry full
|
|
9
|
+
// JSON Schema. Each descriptor's schema is ajv-compiled at registration, which
|
|
10
|
+
// validates it against the JSON Schema meta-schema and throws on a malformed
|
|
11
|
+
// schema — fail fast, never seed a broken descriptor.
|
|
12
|
+
//
|
|
13
|
+
// The `SettingDescriptor`/`JSONSchema` types live in `sdk/src/types.ts` (imported
|
|
14
|
+
// here, never re-declared — DRY rule). Keep this module under the ratchet ceiling;
|
|
15
|
+
// add per-surface seed helpers, don't inline a god-object.
|
|
16
|
+
|
|
17
|
+
import Ajv from "ajv";
|
|
18
|
+
import type { ValidateFunction } from "ajv";
|
|
19
|
+
import {
|
|
20
|
+
APPROVAL_MODES,
|
|
21
|
+
errMessage,
|
|
22
|
+
SPAWN_PROVIDERS,
|
|
23
|
+
VALID_EFFORTS,
|
|
24
|
+
type JSONSchema,
|
|
25
|
+
type SettingDescriptor,
|
|
26
|
+
type SettingScope,
|
|
27
|
+
} from "agent-relay-sdk";
|
|
28
|
+
|
|
29
|
+
/** Fail-closed default scope — a descriptor that omits scope requires admin to
|
|
30
|
+
* read and write (#385 owns the scope grammar; this layer only declares it). */
|
|
31
|
+
export const SETTING_ADMIN_SCOPE = "system:admin";
|
|
32
|
+
|
|
33
|
+
// One shared compiler. `strict: false` relaxes ajv's opinionated strict-mode
|
|
34
|
+
// warnings (unknown keywords/formats) so any reasonable JSON Schema compiles,
|
|
35
|
+
// while meta-schema validation (default on) still rejects a structurally broken
|
|
36
|
+
// schema. `allErrors` so value-validation reports every failure, not just the first.
|
|
37
|
+
const ajv = new Ajv({ allErrors: true, strict: false });
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Registration input: a descriptor with an optional, possibly-partial `scope`.
|
|
41
|
+
* The registry resolves any omitted read/write scope to the fail-closed admin
|
|
42
|
+
* default and returns a fully-populated `SettingDescriptor`.
|
|
43
|
+
*/
|
|
44
|
+
export type SettingRegistration<T = unknown> = Omit<SettingDescriptor<T>, "scope"> & {
|
|
45
|
+
scope?: Partial<SettingScope>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
interface RegisteredSetting {
|
|
49
|
+
descriptor: SettingDescriptor;
|
|
50
|
+
validate: ValidateFunction;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const registry = new Map<string, RegisteredSetting>();
|
|
54
|
+
|
|
55
|
+
function descriptorId(namespace: string, key: string): string {
|
|
56
|
+
return `${namespace}:${key}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function resolveScope(scope: Partial<SettingScope> | undefined): SettingScope {
|
|
60
|
+
return {
|
|
61
|
+
read: scope?.read ?? SETTING_ADMIN_SCOPE,
|
|
62
|
+
write: scope?.write ?? SETTING_ADMIN_SCOPE,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Register (or replace) a setting descriptor. Compiles `schema` with ajv — a
|
|
68
|
+
* malformed JSON Schema throws here, at registration/seed time. The mechanism
|
|
69
|
+
* #386 modules call to contribute their own settings.
|
|
70
|
+
*/
|
|
71
|
+
export function registerSetting<T>(reg: SettingRegistration<T>): SettingDescriptor<T> {
|
|
72
|
+
if (!reg.namespace) throw new Error("setting descriptor requires a non-empty namespace");
|
|
73
|
+
if (!reg.key) throw new Error("setting descriptor requires a non-empty key");
|
|
74
|
+
const id = descriptorId(reg.namespace, reg.key);
|
|
75
|
+
|
|
76
|
+
let validate: ValidateFunction;
|
|
77
|
+
try {
|
|
78
|
+
validate = ajv.compile(reg.schema as object);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
throw new Error(`invalid JSON Schema for setting "${id}": ${errMessage(error)}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const descriptor: SettingDescriptor<T> = {
|
|
84
|
+
namespace: reg.namespace,
|
|
85
|
+
key: reg.key,
|
|
86
|
+
schema: reg.schema,
|
|
87
|
+
defaults: reg.defaults,
|
|
88
|
+
scope: resolveScope(reg.scope),
|
|
89
|
+
tier: reg.tier,
|
|
90
|
+
display: reg.display,
|
|
91
|
+
};
|
|
92
|
+
registry.set(id, { descriptor: descriptor as SettingDescriptor, validate });
|
|
93
|
+
return descriptor;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Look up a single descriptor by its (namespace, key) address. */
|
|
97
|
+
export function getSettingDescriptor(namespace: string, key: string): SettingDescriptor | undefined {
|
|
98
|
+
return registry.get(descriptorId(namespace, key))?.descriptor;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** All registered descriptors (built-ins + module contributions), seeded on first access. */
|
|
102
|
+
export function listSettingDescriptors(): SettingDescriptor[] {
|
|
103
|
+
ensureSeeded();
|
|
104
|
+
return [...registry.values()].map((entry) => entry.descriptor);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Distinct namespaces that have at least one registered descriptor. */
|
|
108
|
+
export function listSettingNamespaces(): string[] {
|
|
109
|
+
return [...new Set(listSettingDescriptors().map((d) => d.namespace))];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Validate a candidate value against a registered descriptor's compiled schema.
|
|
114
|
+
* The single validation seam — #383 calls this on writes so the schema is the one
|
|
115
|
+
* source of truth. Returns `valid:false` with a reason when no descriptor exists.
|
|
116
|
+
*/
|
|
117
|
+
export function validateSettingValue(
|
|
118
|
+
namespace: string,
|
|
119
|
+
key: string,
|
|
120
|
+
value: unknown,
|
|
121
|
+
): { valid: boolean; errors: string[] } {
|
|
122
|
+
ensureSeeded();
|
|
123
|
+
const entry = registry.get(descriptorId(namespace, key));
|
|
124
|
+
if (!entry) return { valid: false, errors: [`no descriptor registered for "${descriptorId(namespace, key)}"`] };
|
|
125
|
+
const valid = entry.validate(value) === true;
|
|
126
|
+
if (valid) return { valid: true, errors: [] };
|
|
127
|
+
const errors = (entry.validate.errors ?? []).map((e) => `${e.instancePath || "/"} ${e.message ?? "invalid"}`.trim());
|
|
128
|
+
return { valid: false, errors };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ──────────────────────────────────────────────────────────────────────────
|
|
132
|
+
// Built-in seeds — descriptors for today's `config`-table namespaces. Schemas
|
|
133
|
+
// mirror the validators in src/config-store.ts; defaults mirror its *_DEFAULTS.
|
|
134
|
+
// All current built-ins are `server-runtime` (config-table backed, runtime
|
|
135
|
+
// mutable). Scope is left default (admin) here; #385 refines read/write tokens.
|
|
136
|
+
// ──────────────────────────────────────────────────────────────────────────
|
|
137
|
+
|
|
138
|
+
const STEWARD_SCHEMA: JSONSchema = {
|
|
139
|
+
type: "object",
|
|
140
|
+
additionalProperties: false,
|
|
141
|
+
required: ["enabled", "provider", "permissionMode", "keepaliveSeconds"],
|
|
142
|
+
properties: {
|
|
143
|
+
enabled: { type: "boolean" },
|
|
144
|
+
provider: { type: "string", enum: [...SPAWN_PROVIDERS] },
|
|
145
|
+
model: { type: "string", maxLength: 120 },
|
|
146
|
+
effort: { type: "string", enum: [...VALID_EFFORTS] },
|
|
147
|
+
permissionMode: { type: "string", enum: [...APPROVAL_MODES] },
|
|
148
|
+
keepaliveSeconds: { type: "integer", minimum: 0, maximum: 2_592_000 },
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const INSIGHTS_SCHEMA: JSONSchema = {
|
|
153
|
+
type: "object",
|
|
154
|
+
additionalProperties: false,
|
|
155
|
+
required: ["enabled", "contextRatio", "introspection"],
|
|
156
|
+
properties: {
|
|
157
|
+
enabled: { type: "boolean" },
|
|
158
|
+
contextRatio: {
|
|
159
|
+
type: "object",
|
|
160
|
+
additionalProperties: false,
|
|
161
|
+
required: ["enabled"],
|
|
162
|
+
properties: { enabled: { type: "boolean" } },
|
|
163
|
+
},
|
|
164
|
+
introspection: {
|
|
165
|
+
type: "object",
|
|
166
|
+
additionalProperties: false,
|
|
167
|
+
required: ["enabled", "minTurns", "minContextRemaining"],
|
|
168
|
+
properties: {
|
|
169
|
+
enabled: { type: "boolean" },
|
|
170
|
+
minTurns: { type: "integer", minimum: 0, maximum: 1000 },
|
|
171
|
+
minContextRemaining: { type: "number", minimum: 0, maximum: 1 },
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const CONTEXT_THRESHOLD_SCHEMA: JSONSchema = {
|
|
178
|
+
type: "object",
|
|
179
|
+
additionalProperties: false,
|
|
180
|
+
required: ["enabled", "advisoryUtilization", "hardBackstopUtilization", "bandSize"],
|
|
181
|
+
properties: {
|
|
182
|
+
enabled: { type: "boolean" },
|
|
183
|
+
advisoryUtilization: { type: "number", minimum: 0, maximum: 1 },
|
|
184
|
+
hardBackstopUtilization: { type: "number", minimum: 0, maximum: 1 },
|
|
185
|
+
bandSize: { type: "number", minimum: 0, maximum: 1 },
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const NOTIFICATIONS_SCHEMA: JSONSchema = {
|
|
190
|
+
type: "object",
|
|
191
|
+
additionalProperties: false,
|
|
192
|
+
required: ["enabled", "branchLanded", "agentReady", "agentExited", "agentSpawnFailed", "contextThreshold"],
|
|
193
|
+
properties: {
|
|
194
|
+
enabled: { type: "boolean" },
|
|
195
|
+
branchLanded: { type: "boolean" },
|
|
196
|
+
agentReady: { type: "boolean" },
|
|
197
|
+
agentExited: { type: "boolean" },
|
|
198
|
+
agentSpawnFailed: { type: "boolean" },
|
|
199
|
+
contextThreshold: CONTEXT_THRESHOLD_SCHEMA,
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const WORKSPACE_SCHEMA: JSONSchema = {
|
|
204
|
+
type: "object",
|
|
205
|
+
additionalProperties: false,
|
|
206
|
+
required: ["symlinkPaths"],
|
|
207
|
+
properties: {
|
|
208
|
+
symlinkPaths: {
|
|
209
|
+
type: "array",
|
|
210
|
+
maxItems: 100,
|
|
211
|
+
items: { type: "string", maxLength: 120 },
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const LANDING_SCHEMA: JSONSchema = {
|
|
217
|
+
type: "object",
|
|
218
|
+
additionalProperties: false,
|
|
219
|
+
required: ["strategy"],
|
|
220
|
+
properties: {
|
|
221
|
+
strategy: { type: "string", enum: ["direct", "pr"] },
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// Provider chat/reasoning capture toggles (source: runner/src/adapter.ts ProviderConfig).
|
|
226
|
+
// NOTE (#383 coordination): provider config storage is being centralized in #383;
|
|
227
|
+
// these are seeded instance-global under namespace "provider". Per-provider
|
|
228
|
+
// (claude vs codex) host-addressing is #383's call — keep these minimal until then.
|
|
229
|
+
const PROVIDER_CHAT_CAPTURE_SCHEMA: JSONSchema = {
|
|
230
|
+
type: "string",
|
|
231
|
+
enum: ["final", "full"],
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const PROVIDER_REASONING_CAPTURE_SCHEMA: JSONSchema = {
|
|
235
|
+
type: "boolean",
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export const PROVIDER_CONFIG_NAMESPACE = "provider-config";
|
|
239
|
+
export const PROVIDER_CONFIG_SCHEMA: JSONSchema = {
|
|
240
|
+
type: "object",
|
|
241
|
+
additionalProperties: false,
|
|
242
|
+
required: [
|
|
243
|
+
"command",
|
|
244
|
+
"defaultArgs",
|
|
245
|
+
"env",
|
|
246
|
+
"pluginDirs",
|
|
247
|
+
"defaultCapabilities",
|
|
248
|
+
"defaultApprovalMode",
|
|
249
|
+
"defaultTags",
|
|
250
|
+
"chatCaptureMode",
|
|
251
|
+
"reasoningCapture",
|
|
252
|
+
"headless",
|
|
253
|
+
],
|
|
254
|
+
properties: {
|
|
255
|
+
command: { type: "string", minLength: 1, maxLength: 500 },
|
|
256
|
+
defaultArgs: { type: "array", maxItems: 50, items: { type: "string", maxLength: 80 } },
|
|
257
|
+
env: { type: "object", additionalProperties: { type: "string" } },
|
|
258
|
+
pluginDirs: { type: "array", maxItems: 50, items: { type: "string", maxLength: 80 } },
|
|
259
|
+
defaultCapabilities: { type: "array", maxItems: 50, items: { type: "string", maxLength: 80 } },
|
|
260
|
+
defaultApprovalMode: { type: "string", maxLength: 80 },
|
|
261
|
+
defaultTags: { type: "array", maxItems: 50, items: { type: "string", maxLength: 80 } },
|
|
262
|
+
chatCaptureMode: { type: "string", enum: ["final", "full"] },
|
|
263
|
+
reasoningCapture: { type: "boolean" },
|
|
264
|
+
headless: {
|
|
265
|
+
type: "object",
|
|
266
|
+
additionalProperties: false,
|
|
267
|
+
required: ["tmuxPrefix", "shutdownTimeoutMs"],
|
|
268
|
+
properties: {
|
|
269
|
+
tmuxPrefix: { type: "string", minLength: 1, maxLength: 120 },
|
|
270
|
+
shutdownTimeoutMs: { type: "integer", minimum: 1 },
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
let seeded = false;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Register the built-in descriptors. Idempotent: safe to call repeatedly (and is
|
|
280
|
+
* called lazily by the read accessors). #386 adds module-contributed descriptors
|
|
281
|
+
* on top via `registerSetting`.
|
|
282
|
+
*/
|
|
283
|
+
export function seedBuiltInSettings(): void {
|
|
284
|
+
if (seeded) return;
|
|
285
|
+
seeded = true;
|
|
286
|
+
|
|
287
|
+
registerSetting({
|
|
288
|
+
namespace: "steward",
|
|
289
|
+
key: "default",
|
|
290
|
+
schema: STEWARD_SCHEMA,
|
|
291
|
+
defaults: { enabled: false, provider: "claude", permissionMode: "open", keepaliveSeconds: 300 },
|
|
292
|
+
scope: { read: "settings:read:steward", write: "settings:write:steward" },
|
|
293
|
+
tier: "server-runtime",
|
|
294
|
+
display: { group: "Agents", label: "Steward", description: "Auto-provisioned steward that reconciles merges and commands.", order: 10 },
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
registerSetting({
|
|
298
|
+
namespace: "insights",
|
|
299
|
+
key: "default",
|
|
300
|
+
schema: INSIGHTS_SCHEMA,
|
|
301
|
+
defaults: {
|
|
302
|
+
enabled: true,
|
|
303
|
+
contextRatio: { enabled: true },
|
|
304
|
+
introspection: { enabled: true, minTurns: 4, minContextRemaining: 0.15 },
|
|
305
|
+
},
|
|
306
|
+
scope: { read: "settings:read:insights", write: "settings:write:insights" },
|
|
307
|
+
tier: "server-runtime",
|
|
308
|
+
display: { group: "Insights", label: "Insights", description: "Continuous self-improvement instrumentation toggles.", order: 20 },
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
registerSetting({
|
|
312
|
+
namespace: "notifications",
|
|
313
|
+
key: "default",
|
|
314
|
+
schema: NOTIFICATIONS_SCHEMA,
|
|
315
|
+
defaults: {
|
|
316
|
+
enabled: true,
|
|
317
|
+
branchLanded: true,
|
|
318
|
+
agentReady: true,
|
|
319
|
+
agentExited: true,
|
|
320
|
+
agentSpawnFailed: true,
|
|
321
|
+
contextThreshold: { enabled: true, advisoryUtilization: 0.7, hardBackstopUtilization: 0.9, bandSize: 0.1 },
|
|
322
|
+
},
|
|
323
|
+
scope: { read: "settings:read:notifications", write: "settings:write:notifications" },
|
|
324
|
+
tier: "server-runtime",
|
|
325
|
+
display: { group: "Notifications", label: "Lifecycle notifications", description: "Relay-driven lifecycle push notifications (#239).", order: 30 },
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
registerSetting({
|
|
329
|
+
namespace: "workspace",
|
|
330
|
+
key: "default",
|
|
331
|
+
schema: WORKSPACE_SCHEMA,
|
|
332
|
+
defaults: { symlinkPaths: ["AGENTS.md", ".claude-rig"] },
|
|
333
|
+
scope: { read: "settings:read:workspace", write: "settings:write:workspace" },
|
|
334
|
+
tier: "server-runtime",
|
|
335
|
+
display: { group: "Workspace", label: "Workspace provisioning", description: "Untracked paths symlinked into isolated worktrees.", order: 40 },
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
registerSetting({
|
|
339
|
+
namespace: "landing",
|
|
340
|
+
key: "default",
|
|
341
|
+
schema: LANDING_SCHEMA,
|
|
342
|
+
defaults: { strategy: "direct" },
|
|
343
|
+
scope: { read: "settings:read:landing", write: "settings:write:landing" },
|
|
344
|
+
tier: "server-runtime",
|
|
345
|
+
display: { group: "Workspace", label: "Landing strategy", description: "Default land strategy for workspace branches.", order: 41 },
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
registerSetting({
|
|
349
|
+
namespace: "provider",
|
|
350
|
+
key: "chatCaptureMode",
|
|
351
|
+
schema: PROVIDER_CHAT_CAPTURE_SCHEMA,
|
|
352
|
+
defaults: "full",
|
|
353
|
+
scope: { read: "settings:read:provider", write: "settings:write:provider" },
|
|
354
|
+
tier: "server-runtime",
|
|
355
|
+
display: { group: "Providers", label: "Chat capture mode", description: "How much provider output is captured into chat.", order: 50 },
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
registerSetting({
|
|
359
|
+
namespace: "provider",
|
|
360
|
+
key: "reasoningCapture",
|
|
361
|
+
schema: PROVIDER_REASONING_CAPTURE_SCHEMA,
|
|
362
|
+
defaults: true,
|
|
363
|
+
scope: { read: "settings:read:provider", write: "settings:write:provider" },
|
|
364
|
+
tier: "server-runtime",
|
|
365
|
+
display: { group: "Providers", label: "Reasoning capture", description: "Stream reasoning/tool steps into chat.", order: 51 },
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export function registerProviderConfigSetting(input: {
|
|
370
|
+
host: string;
|
|
371
|
+
provider: string;
|
|
372
|
+
defaults: unknown;
|
|
373
|
+
display?: Partial<SettingDescriptor["display"]>;
|
|
374
|
+
}): SettingDescriptor {
|
|
375
|
+
return registerSetting({
|
|
376
|
+
namespace: PROVIDER_CONFIG_NAMESPACE,
|
|
377
|
+
key: `${input.host}/${input.provider}`,
|
|
378
|
+
schema: PROVIDER_CONFIG_SCHEMA,
|
|
379
|
+
defaults: input.defaults,
|
|
380
|
+
scope: { read: "agent:read", write: SETTING_ADMIN_SCOPE },
|
|
381
|
+
tier: "server-runtime",
|
|
382
|
+
display: {
|
|
383
|
+
group: "Providers",
|
|
384
|
+
label: `${input.host} ${input.provider}`,
|
|
385
|
+
description: `Provider runtime configuration for ${input.provider} on ${input.host}.`,
|
|
386
|
+
order: 60,
|
|
387
|
+
...input.display,
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function ensureSeeded(): void {
|
|
393
|
+
if (!seeded) seedBuiltInSettings();
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Seed on import so any consumer of the registry sees the built-ins.
|
|
397
|
+
seedBuiltInSettings();
|