@capybara-hq/kernel 0.1.0-rc.33 → 0.1.0-rc.35
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/bootstrap.json +3 -3
- package/dist/admin/outbox-dead.service.d.ts +2 -0
- package/dist/admin/outbox-dead.service.js +34 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/requests.service.d.ts +8 -6
- package/dist/catalog/requests.service.js +52 -29
- package/dist/config/schema.d.ts +4 -0
- package/dist/config/schema.js +7 -1
- package/dist/conversations/conversations.service.d.ts +3 -3
- package/dist/conversations/conversations.service.js +58 -29
- package/dist/db/kernel-schema.d.ts +8 -0
- package/dist/devices/devices.service.js +8 -4
- package/dist/infra/database/transaction-host.d.ts +1 -0
- package/dist/infra/database/transaction-host.js +13 -2
- package/dist/infra/outbox/registry.d.ts +17 -0
- package/dist/infra/outbox/registry.js +11 -0
- package/dist/local-devices/local-device-gateway.d.ts +1 -1
- package/dist/local-devices/local-device-gateway.js +1 -1
- package/dist/local-devices/local-device-provider.d.ts +2 -2
- package/dist/local-devices/local-device-provider.js +7 -5
- package/dist/local-devices/network-grants.d.ts +1 -1
- package/dist/local-devices/network-grants.js +2 -3
- package/dist/orgs/offboarding.d.ts +2 -0
- package/dist/orgs/offboarding.js +4 -0
- package/dist/orgs/orgs.service.d.ts +3 -1
- package/dist/orgs/orgs.service.js +23 -10
- package/dist/orgs/settings.controller.d.ts +3 -1
- package/dist/orgs/settings.controller.js +7 -3
- package/dist/orgs/settings.service.d.ts +78 -31
- package/dist/orgs/settings.service.js +109 -52
- package/dist/platform/ops/org-settings.ops.js +20 -10
- package/dist/runtime/checkpointer.js +3 -0
- package/dist/runtime/context/compaction.js +5 -5
- package/dist/runtime/conversation-lock.d.ts +4 -11
- package/dist/runtime/conversation-lock.js +14 -18
- package/dist/runtime/maintenance.d.ts +3 -1
- package/dist/runtime/maintenance.js +17 -10
- package/dist/runtime/project/knowledge.service.js +2 -2
- package/dist/runtime/run-deletion.d.ts +23 -0
- package/dist/runtime/run-deletion.js +130 -0
- package/dist/runtime/run-execution.d.ts +23 -0
- package/dist/runtime/run-execution.js +105 -0
- package/dist/runtime/run-finish.js +17 -4
- package/dist/runtime/run-jobs.js +11 -0
- package/dist/runtime/run-orphan-check.job.d.ts +12 -12
- package/dist/runtime/run-orphan-check.job.js +94 -26
- package/dist/runtime/run-queue.js +14 -0
- package/dist/runtime/run-worker.d.ts +9 -5
- package/dist/runtime/run-worker.js +90 -44
- package/dist/runtime/runtime.module.js +6 -0
- package/dist/runtime/stream.js +8 -2
- package/dist/runtime/subagents/tree-jobs.d.ts +4 -3
- package/dist/runtime/subagents/tree-jobs.js +4 -4
- package/dist/sandbox/modes.d.ts +31 -19
- package/dist/sandbox/modes.js +43 -24
- package/dist/sandbox/sandbox.service.d.ts +4 -1
- package/dist/sandbox/sandbox.service.js +11 -0
- package/dist/schedules/grant-rules.d.ts +2 -0
- package/dist/schedules/grant-rules.js +3 -1
- package/dist/schedules/schedule-math.js +21 -2
- package/dist/schedules/scheduled-tasks.service.js +3 -1
- package/dist/tools/network-asks.d.ts +7 -0
- package/dist/tools/network-asks.js +11 -1
- package/dist/tools/pipeline.js +14 -2
- package/package.json +3 -3
- package/src/migrations/0134_org_cloud_network_delta.sql +38 -0
- package/src/migrations/0135_run_execution_claim.sql +2 -0
- package/src/migrations/0136_run_recovery_cursor.sql +6 -0
|
@@ -19,7 +19,7 @@ export declare const DEVICE_CLOSE: {
|
|
|
19
19
|
readonly replaced: 4002;
|
|
20
20
|
/** The machine's credential was revoked: the program exits. */
|
|
21
21
|
readonly revoked: 4003;
|
|
22
|
-
/** No valid `hello` first, or a frame that is not protocol
|
|
22
|
+
/** No valid `hello` first, or a frame that is not the current protocol from a device. */
|
|
23
23
|
readonly protocol: 4400;
|
|
24
24
|
/** The lease could not be claimed in time: reconnect. */
|
|
25
25
|
readonly claimTimeout: 4409;
|
|
@@ -30,7 +30,7 @@ export const DEVICE_CLOSE = {
|
|
|
30
30
|
replaced: 4002,
|
|
31
31
|
/** The machine's credential was revoked: the program exits. */
|
|
32
32
|
revoked: 4003,
|
|
33
|
-
/** No valid `hello` first, or a frame that is not protocol
|
|
33
|
+
/** No valid `hello` first, or a frame that is not the current protocol from a device. */
|
|
34
34
|
protocol: 4400,
|
|
35
35
|
/** The lease could not be claimed in time: reconnect. */
|
|
36
36
|
claimTimeout: 4409,
|
|
@@ -143,10 +143,10 @@ export declare class LocalDeviceProvider implements SandboxProvider {
|
|
|
143
143
|
/** The kernel never sends `list` or `scan` to a machine that did not announce `projects`. */
|
|
144
144
|
private requireProjects;
|
|
145
145
|
/**
|
|
146
|
-
* The device's org and
|
|
146
|
+
* The device's org and current limits for an exec or file read (ruling R27): the effective policy's
|
|
147
147
|
* `allowedMode` and the sandbox-mode allowlist. A deleted device is not found. A machine whose
|
|
148
148
|
* local policy is auto mode while the organization allows only sandbox mode is refused here, at
|
|
149
|
-
* every
|
|
149
|
+
* every such operation, so a machine switched locally is not used until it is switched back.
|
|
150
150
|
*/
|
|
151
151
|
private currentLimits;
|
|
152
152
|
}
|
|
@@ -162,9 +162,10 @@ let LocalDeviceProvider = class LocalDeviceProvider {
|
|
|
162
162
|
return { ...result, network: { blocked: relayer(result.network.blocked, limits) } };
|
|
163
163
|
}
|
|
164
164
|
async readFile(h, path, opts) {
|
|
165
|
+
const { limits } = await this.currentLimits(h.id);
|
|
165
166
|
// the answer must fit one frame: a larger file comes back truncated (Deliver: too large)
|
|
166
167
|
const maxBytes = Math.min(opts.maxBytes, maxReadBytes(this.config.get().devices.local.maxFrameBytes));
|
|
167
|
-
const r = await this.relay.call(h.id, "readFile", { path, maxBytes }, { deadlineMs: OP_DEADLINE_MS, signal: opts.signal });
|
|
168
|
+
const r = await this.relay.call(h.id, "readFile", { path, maxBytes, limits: { mode: limits.mode } }, { deadlineMs: OP_DEADLINE_MS, signal: opts.signal });
|
|
168
169
|
return r === null ? null : { data: bytesOf(r.dataB64), truncated: r.truncated };
|
|
169
170
|
}
|
|
170
171
|
async writeFile(h, path, data, signal) {
|
|
@@ -172,7 +173,8 @@ let LocalDeviceProvider = class LocalDeviceProvider {
|
|
|
172
173
|
await this.relay.call(h.id, "writeFile", { path, dataB64 }, { deadlineMs: OP_DEADLINE_MS, signal });
|
|
173
174
|
}
|
|
174
175
|
async stat(h, path, signal) {
|
|
175
|
-
|
|
176
|
+
const { limits } = await this.currentLimits(h.id);
|
|
177
|
+
return this.relay.call(h.id, "stat", { path, limits: { mode: limits.mode } }, { deadlineMs: OP_DEADLINE_MS, signal });
|
|
176
178
|
}
|
|
177
179
|
/**
|
|
178
180
|
* Lists one directory on the machine (the `list` op, project root §4.1), read in the mode the
|
|
@@ -201,10 +203,10 @@ let LocalDeviceProvider = class LocalDeviceProvider {
|
|
|
201
203
|
}
|
|
202
204
|
}
|
|
203
205
|
/**
|
|
204
|
-
* The device's org and
|
|
206
|
+
* The device's org and current limits for an exec or file read (ruling R27): the effective policy's
|
|
205
207
|
* `allowedMode` and the sandbox-mode allowlist. A deleted device is not found. A machine whose
|
|
206
208
|
* local policy is auto mode while the organization allows only sandbox mode is refused here, at
|
|
207
|
-
* every
|
|
209
|
+
* every such operation, so a machine switched locally is not used until it is switched back.
|
|
208
210
|
*/
|
|
209
211
|
async currentLimits(deviceId) {
|
|
210
212
|
const orgId = await this.targets.orgOf(deviceId);
|
|
@@ -215,7 +217,7 @@ let LocalDeviceProvider = class LocalDeviceProvider {
|
|
|
215
217
|
this.grants.reportedMode(deviceId),
|
|
216
218
|
]);
|
|
217
219
|
if (policy.allowedMode === "sandbox" && reported === "auto") {
|
|
218
|
-
this.log.warn("
|
|
220
|
+
this.log.warn("device operation refused on a machine that reports auto mode", { deviceId });
|
|
219
221
|
throw new ApiError("device.auto_mode_not_allowed", AUTO_MODE_NOT_ALLOWED_TEXT);
|
|
220
222
|
}
|
|
221
223
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type DeviceExecGrants, type NetworkBlockedHost, type SandboxLimits } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type SandboxMode } from "../sandbox/modes.js";
|
|
4
4
|
/** The most hosts one exec's grants carry (the device protocol's limit). */
|
|
5
5
|
export declare const MAX_GRANT_HOSTS = 100;
|
|
6
6
|
/** What a run tree's network asks add up to (network ask-to-allow spec §6.8). */
|
|
@@ -12,6 +12,7 @@ import { Inject, Injectable } from "@nestjs/common";
|
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
14
14
|
import { budgetRunOf } from "../runtime/subagents/limits.js";
|
|
15
|
+
import { coversHost } from "../sandbox/modes.js";
|
|
15
16
|
import { taskGrantsRunOf } from "../schedules/unattended.js";
|
|
16
17
|
import { localModeOf } from "./policy-summary.js";
|
|
17
18
|
/** The most hosts one exec's grants carry (the device protocol's limit). */
|
|
@@ -229,14 +230,12 @@ const normalize = (host) => {
|
|
|
229
230
|
const h = host.toLowerCase();
|
|
230
231
|
return h.endsWith(".") ? h.slice(0, -1) : h;
|
|
231
232
|
};
|
|
232
|
-
/** Whether the allowlist entry `pattern` admits `host` (`*.x.com`: subdomains, never the apex). */
|
|
233
|
-
const covers = (pattern, host) => pattern === host || (pattern.startsWith("*.") && host.endsWith(pattern.slice(1)));
|
|
234
233
|
/** Whether the org's sandbox-mode network lets a command reach `host`. */
|
|
235
234
|
export function orgAllows(host, limits) {
|
|
236
235
|
if (limits.network.kind === "open-public")
|
|
237
236
|
return true;
|
|
238
237
|
const h = normalize(host);
|
|
239
|
-
return limits.network.hosts.some((p) =>
|
|
238
|
+
return limits.network.hosts.some((p) => coversHost(p.toLowerCase(), h));
|
|
240
239
|
}
|
|
241
240
|
/**
|
|
242
241
|
* The kernel's own layer for a device's report (auto mode spec §4.2): it trusts the device's word
|
|
@@ -49,6 +49,8 @@ export interface OffboardingRunControl {
|
|
|
49
49
|
export declare const RUN_STOP_JOB = "run-stop";
|
|
50
50
|
/** The `run-stop` job's data. */
|
|
51
51
|
export interface RunStopJobData {
|
|
52
|
+
/** A deletion already settled PG; cancellation still needs delivery to its old worker. */
|
|
53
|
+
deleted?: true;
|
|
52
54
|
conversationId: string;
|
|
53
55
|
runId: string;
|
|
54
56
|
}
|
package/dist/orgs/offboarding.js
CHANGED
|
@@ -406,6 +406,10 @@ let Offboarding = class Offboarding {
|
|
|
406
406
|
* A failure throws (the job is retried).
|
|
407
407
|
*/
|
|
408
408
|
async stopRun(data) {
|
|
409
|
+
if (data.deleted) {
|
|
410
|
+
await this.runs.requestAbort(data.runId, null);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
409
413
|
const run = await this.db
|
|
410
414
|
.selectFrom("runs")
|
|
411
415
|
.select("status")
|
|
@@ -8,6 +8,7 @@ import { SettingsService } from "../identity/settings.js";
|
|
|
8
8
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
9
9
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
10
10
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
11
|
+
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
11
12
|
import { OrgLock } from "./org-lock.js";
|
|
12
13
|
import type { OrgRole } from "./roles.js";
|
|
13
14
|
export type Org = {
|
|
@@ -26,6 +27,7 @@ export declare function slugFromName(name: string): string;
|
|
|
26
27
|
*/
|
|
27
28
|
export declare class OrgsService {
|
|
28
29
|
private readonly db;
|
|
30
|
+
private readonly outbox;
|
|
29
31
|
readonly txHost: TransactionHost;
|
|
30
32
|
private readonly settings;
|
|
31
33
|
private readonly apiTokens;
|
|
@@ -39,7 +41,7 @@ export declare class OrgsService {
|
|
|
39
41
|
private readonly ownedItems;
|
|
40
42
|
/** Records `org.deleted` for the subscribing plugins in the delete's transaction. */
|
|
41
43
|
private readonly lifecycle;
|
|
42
|
-
constructor(db: KernelDb, txHost: TransactionHost, settings: SettingsService, apiTokens: ApiTokenService, orgLock: OrgLock, events: KernelEvents,
|
|
44
|
+
constructor(db: KernelDb, outbox: Pick<OutboxService, "add">, txHost: TransactionHost, settings: SettingsService, apiTokens: ApiTokenService, orgLock: OrgLock, events: KernelEvents,
|
|
43
45
|
/** Cancels the deleted org's running eval runs (in the delete's transaction). */
|
|
44
46
|
evalBudget: Pick<EvalBudget, "cancelRuns">,
|
|
45
47
|
/** A new org gets the plugins its scope offers it (the scope sync, owed with the org). */
|
|
@@ -24,6 +24,9 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
24
24
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
25
25
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
26
26
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
27
|
+
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
28
|
+
import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
|
|
29
|
+
import { STOP_DELETED_ORG_JOB } from "../runtime/run-deletion.js";
|
|
27
30
|
import { USAGE_REPORT_QUEUE } from "../runtime/usage-report-jobs.js";
|
|
28
31
|
import { OrgLock } from "./org-lock.js";
|
|
29
32
|
/** 组织 slug:小写字母数字与 `-`,首尾不能是 `-`,1–40 个字符。 */
|
|
@@ -79,6 +82,7 @@ async function slugGuard(p) {
|
|
|
79
82
|
*/
|
|
80
83
|
let OrgsService = class OrgsService {
|
|
81
84
|
db;
|
|
85
|
+
outbox;
|
|
82
86
|
txHost;
|
|
83
87
|
settings;
|
|
84
88
|
apiTokens;
|
|
@@ -88,7 +92,7 @@ let OrgsService = class OrgsService {
|
|
|
88
92
|
scopeSync;
|
|
89
93
|
ownedItems;
|
|
90
94
|
lifecycle;
|
|
91
|
-
constructor(db, txHost, settings, apiTokens, orgLock, events,
|
|
95
|
+
constructor(db, outbox, txHost, settings, apiTokens, orgLock, events,
|
|
92
96
|
/** Cancels the deleted org's running eval runs (in the delete's transaction). */
|
|
93
97
|
evalBudget,
|
|
94
98
|
/** A new org gets the plugins its scope offers it (the scope sync, owed with the org). */
|
|
@@ -98,6 +102,7 @@ let OrgsService = class OrgsService {
|
|
|
98
102
|
/** Records `org.deleted` for the subscribing plugins in the delete's transaction. */
|
|
99
103
|
lifecycle) {
|
|
100
104
|
this.db = db;
|
|
105
|
+
this.outbox = outbox;
|
|
101
106
|
this.txHost = txHost;
|
|
102
107
|
this.settings = settings;
|
|
103
108
|
this.apiTokens = apiTokens;
|
|
@@ -236,6 +241,7 @@ let OrgsService = class OrgsService {
|
|
|
236
241
|
await this.softDeleteIn(orgId, actor, actorTokenId);
|
|
237
242
|
}
|
|
238
243
|
async softDeleteIn(orgId, actor, actorTokenId) {
|
|
244
|
+
// The same org authorization lock admits fenced worker writes before conversation locks.
|
|
239
245
|
await this.orgLock.lockAndAuthorize(orgId, actor.id, "org.delete");
|
|
240
246
|
await this.db
|
|
241
247
|
.updateTable("orgs")
|
|
@@ -251,6 +257,12 @@ let OrgsService = class OrgsService {
|
|
|
251
257
|
.where("dead_at", "is", null)
|
|
252
258
|
.where("queue", "<>", USAGE_REPORT_QUEUE)
|
|
253
259
|
.execute();
|
|
260
|
+
await this.outbox.add({
|
|
261
|
+
queue: MAINTENANCE_QUEUE_NAME,
|
|
262
|
+
name: STOP_DELETED_ORG_JOB,
|
|
263
|
+
jobId: `stop-deleted-org-${orgId}`,
|
|
264
|
+
data: { orgId, byAccountId: actor.id },
|
|
265
|
+
});
|
|
254
266
|
// after the org is marked deleted, so it counts as no user of what it shared (P3-18)
|
|
255
267
|
await this.ownedItems.onOrgDeleted(orgId, actor.id, {
|
|
256
268
|
...(actorTokenId !== undefined && { actorTokenId }),
|
|
@@ -290,14 +302,15 @@ __decorate([
|
|
|
290
302
|
OrgsService = __decorate([
|
|
291
303
|
Injectable(),
|
|
292
304
|
__param(0, Inject(KernelDb)),
|
|
293
|
-
__param(1, Inject(
|
|
294
|
-
__param(2, Inject(
|
|
295
|
-
__param(3, Inject(
|
|
296
|
-
__param(4, Inject(
|
|
297
|
-
__param(5, Inject(
|
|
298
|
-
__param(6, Inject(
|
|
299
|
-
__param(7, Inject(
|
|
300
|
-
__param(8, Inject(
|
|
301
|
-
__param(9, Inject(
|
|
305
|
+
__param(1, Inject(OutboxService)),
|
|
306
|
+
__param(2, Inject(TransactionHost)),
|
|
307
|
+
__param(3, Inject(SettingsService)),
|
|
308
|
+
__param(4, Inject(ApiTokenService)),
|
|
309
|
+
__param(5, Inject(OrgLock)),
|
|
310
|
+
__param(6, Inject(KernelEvents)),
|
|
311
|
+
__param(7, Inject(EvalBudget)),
|
|
312
|
+
__param(8, Inject(PluginScopeSync)),
|
|
313
|
+
__param(9, Inject(OwnedItems)),
|
|
314
|
+
__param(10, Inject(LifecycleHooks))
|
|
302
315
|
], OrgsService);
|
|
303
316
|
export { OrgsService };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Principal } from "../identity/principal.js";
|
|
2
2
|
import { type OrgContext } from "./org.guard.js";
|
|
3
|
-
import { type OrgSandboxLimits, type OrgSettings, type OrgSettingsDeployment, type OrgSettingsPatch, OrgSettingsService } from "./settings.service.js";
|
|
3
|
+
import { type OrgEffectiveNetwork, type OrgSandboxLimits, type OrgSettings, type OrgSettingsDeployment, type OrgSettingsPatch, OrgSettingsService } from "./settings.service.js";
|
|
4
4
|
/**
|
|
5
5
|
* 组织设置(`/api/v1/orgs/:orgId/settings`):成员可读,修改需 `org.update`(admin)。
|
|
6
6
|
* 响应带 `deployment`(部署默认值,如沙箱出站),设置页据此展示「跟随部署」时的实际取值;
|
|
@@ -9,6 +9,8 @@ import { type OrgSandboxLimits, type OrgSettings, type OrgSettingsDeployment, ty
|
|
|
9
9
|
type SettingsResponse = {
|
|
10
10
|
settings: OrgSettings;
|
|
11
11
|
deployment: OrgSettingsDeployment;
|
|
12
|
+
/** The org's effective sandbox-mode network (org egress ceiling spec §D4). */
|
|
13
|
+
effectiveNetwork: OrgEffectiveNetwork;
|
|
12
14
|
sandboxLimits: OrgSandboxLimits;
|
|
13
15
|
};
|
|
14
16
|
export declare class OrgSettingsController {
|
|
@@ -21,18 +21,22 @@ let OrgSettingsController = class OrgSettingsController {
|
|
|
21
21
|
this.settings = settings;
|
|
22
22
|
}
|
|
23
23
|
async get(org) {
|
|
24
|
+
const settings = await this.settings.get(org.orgId);
|
|
24
25
|
return {
|
|
25
|
-
settings
|
|
26
|
+
settings,
|
|
26
27
|
deployment: await this.settings.deployment(),
|
|
28
|
+
effectiveNetwork: this.settings.effectiveNetwork(settings),
|
|
27
29
|
sandboxLimits: await this.settings.sandboxLimits(org.orgId),
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
32
|
async update(principal, org, body) {
|
|
31
33
|
const p = requireUser(principal);
|
|
34
|
+
// an API token may narrow auto mode and the cloud network, never widen them (auto mode spec §4.3)
|
|
35
|
+
const settings = await this.settings.update(org.orgId, body, p.account.id, patTokenId(p), undefined, { onlyNarrows: patTokenId(p) !== undefined });
|
|
32
36
|
return {
|
|
33
|
-
|
|
34
|
-
settings: await this.settings.update(org.orgId, body, p.account.id, patTokenId(p), undefined, { onlyNarrows: patTokenId(p) !== undefined }),
|
|
37
|
+
settings,
|
|
35
38
|
deployment: await this.settings.deployment(),
|
|
39
|
+
effectiveNetwork: this.settings.effectiveNetwork(settings),
|
|
36
40
|
sandboxLimits: await this.settings.sandboxLimits(org.orgId),
|
|
37
41
|
};
|
|
38
42
|
}
|
|
@@ -20,9 +20,9 @@ import { OrgLock } from "./org-lock.js";
|
|
|
20
20
|
* - `autoMode`: whether devices of the org may run in auto mode (auto mode spec §4.3); absent
|
|
21
21
|
* follows the platform's `devices.autoMode`, and an invalid stored value reads as `off`
|
|
22
22
|
* (narrower, never wider). Setting `allowed` while the platform is `off` is refused.
|
|
23
|
-
* - `cloudNetwork`: the org's network
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* - `cloudNetwork`: the org's sandbox-mode network as a delta over the platform's allowlist (org
|
|
24
|
+
* egress ceiling spec §D1, {@link CloudNetworkSettingSchema}). An invalid stored value reads as
|
|
25
|
+
* `{ mode: "allowlist", base: "none" }`, the empty allowlist (narrower, never wider).
|
|
26
26
|
* - `platformTool`: the `Platform` builtin for the whole org (Platform tool spec §3): `on`,
|
|
27
27
|
* `read-only` (writes listed as unavailable) or `off` (default `on`).
|
|
28
28
|
* - `timeZone`: the org's default time zone (IANA; absent = UTC) for senders without one of their
|
|
@@ -37,19 +37,31 @@ import { OrgLock } from "./org-lock.js";
|
|
|
37
37
|
/** The org cloud-network allowlist's host limit. */
|
|
38
38
|
export declare const ORG_SANDBOX_ALLOW_HOSTS_MAX = 200;
|
|
39
39
|
/**
|
|
40
|
-
* The org's network
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
40
|
+
* The org's sandbox-mode network (org egress ceiling spec §D1), stored as a delta over the
|
|
41
|
+
* platform's `sandbox.limits.allowHosts`, never a copy of it, so platform changes keep reaching the
|
|
42
|
+
* org:
|
|
43
|
+
* - `mode`: the cloud network of a cloud device in sandbox mode, `open` (any public host; loopback,
|
|
44
|
+
* private and cloud metadata addresses are blocked outside the container) or `allowlist`; absent
|
|
45
|
+
* follows the platform's default (open). `sandbox.limits.orgHosts: within` makes it the allowlist.
|
|
46
|
+
* - `base`: `platform` (the default: start from the platform's list) or `none` (only the org's own
|
|
47
|
+
* hosts).
|
|
48
|
+
* - `extraHosts`: hosts the org adds (ignored outside the platform list under `within`).
|
|
49
|
+
* - `excludedHosts`: platform entries the org drops (exact entries; any host is accepted, since the
|
|
50
|
+
* platform may drop an entry later).
|
|
51
|
+
* The effective hosts ({@link orgEffectiveHosts} in `sandbox/modes.ts`) are also the ceiling a local
|
|
52
|
+
* device in sandbox mode reaches (the device intersects them with its own list).
|
|
46
53
|
*/
|
|
47
54
|
export declare const CloudNetworkSettingSchema: z.ZodObject<{
|
|
48
|
-
mode: z.ZodEnum<{
|
|
55
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
49
56
|
allowlist: "allowlist";
|
|
50
57
|
open: "open";
|
|
51
|
-
}
|
|
52
|
-
|
|
58
|
+
}>>;
|
|
59
|
+
base: z.ZodOptional<z.ZodEnum<{
|
|
60
|
+
none: "none";
|
|
61
|
+
platform: "platform";
|
|
62
|
+
}>>;
|
|
63
|
+
extraHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
64
|
+
excludedHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
53
65
|
}, z.core.$strict>;
|
|
54
66
|
export type CloudNetworkSetting = z.infer<typeof CloudNetworkSettingSchema>;
|
|
55
67
|
/** What an invalid stored `cloudNetwork` reads as: the allowlist with no host (never wider). */
|
|
@@ -154,11 +166,16 @@ export declare const OrgSettingsSchema: z.ZodObject<{
|
|
|
154
166
|
off: "off";
|
|
155
167
|
}>>>;
|
|
156
168
|
cloudNetwork: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
157
|
-
mode: z.ZodEnum<{
|
|
169
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
158
170
|
allowlist: "allowlist";
|
|
159
171
|
open: "open";
|
|
160
|
-
}
|
|
161
|
-
|
|
172
|
+
}>>;
|
|
173
|
+
base: z.ZodOptional<z.ZodEnum<{
|
|
174
|
+
none: "none";
|
|
175
|
+
platform: "platform";
|
|
176
|
+
}>>;
|
|
177
|
+
extraHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
178
|
+
excludedHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
162
179
|
}, z.core.$strict>>>;
|
|
163
180
|
wakeOnBackgroundTask: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
|
|
164
181
|
timeZone: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
@@ -223,11 +240,16 @@ export declare const OrgSettingsPatchSchema: z.ZodObject<{
|
|
|
223
240
|
off: "off";
|
|
224
241
|
}>>>;
|
|
225
242
|
cloudNetwork: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
226
|
-
mode: z.ZodEnum<{
|
|
243
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
227
244
|
allowlist: "allowlist";
|
|
228
245
|
open: "open";
|
|
229
|
-
}
|
|
230
|
-
|
|
246
|
+
}>>;
|
|
247
|
+
base: z.ZodOptional<z.ZodEnum<{
|
|
248
|
+
none: "none";
|
|
249
|
+
platform: "platform";
|
|
250
|
+
}>>;
|
|
251
|
+
extraHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
252
|
+
excludedHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
231
253
|
}, z.core.$strict>>>;
|
|
232
254
|
timeZone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
233
255
|
theme: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
@@ -279,17 +301,24 @@ export interface OrgSandboxLimits {
|
|
|
279
301
|
memoryMb: number;
|
|
280
302
|
source: "deployment" | "override";
|
|
281
303
|
}
|
|
304
|
+
/** The org's effective sandbox-mode network (`effectiveNetwork` of the settings responses). */
|
|
305
|
+
export interface OrgEffectiveNetwork {
|
|
306
|
+
mode: "open" | "allowlist";
|
|
307
|
+
hosts: string[];
|
|
308
|
+
}
|
|
282
309
|
/** The deployment defaults the settings page shows for "follow the platform" (`GET` returns them). */
|
|
283
310
|
export interface OrgSettingsDeployment {
|
|
284
311
|
/** The platform's auto-mode switch and where it comes from. */
|
|
285
312
|
autoMode: DevicesAutoModeView;
|
|
286
313
|
/**
|
|
287
|
-
* The
|
|
288
|
-
* `sandbox.limits.
|
|
314
|
+
* The platform's network: its allowlist (what an org's delta applies to), whether orgs may go
|
|
315
|
+
* beyond it (`sandbox.limits.orgHosts`) and the kill switch (`off`: `sandbox.limits.egress` is
|
|
316
|
+
* `none`).
|
|
289
317
|
*/
|
|
290
318
|
cloudNetwork: {
|
|
291
|
-
mode: "open" | "allowlist";
|
|
292
319
|
allowHosts: string[];
|
|
320
|
+
orgHosts: "extend" | "within";
|
|
321
|
+
off: boolean;
|
|
293
322
|
};
|
|
294
323
|
/** The platform's effective attribution defaults for agent-created commits and pull requests. */
|
|
295
324
|
attribution: PlatformAttribution;
|
|
@@ -309,6 +338,14 @@ export declare function readOrgSettings(db: KernelSchemaDb, orgId: string): Prom
|
|
|
309
338
|
export declare function invalidStoredAutoMode(raw: unknown): boolean;
|
|
310
339
|
/** Whether a stored settings object holds a `cloudNetwork` this version reads as an empty allowlist. */
|
|
311
340
|
export declare function invalidStoredCloudNetwork(raw: unknown): boolean;
|
|
341
|
+
/**
|
|
342
|
+
* Whether `next` (absent: follow the platform) widens `prev` (spec §D3), both normalized (mode
|
|
343
|
+
* open, base platform, empty lists): the open mode where it was the allowlist; base none to
|
|
344
|
+
* platform; with base platform, dropping one of the stored exclusions; an extra host no stored
|
|
345
|
+
* extra covers. Over-strict on purpose: moving to base none with a platform entry as an extra is a
|
|
346
|
+
* narrowing these rules refuse (a token cannot pin a platform host the platform may drop later).
|
|
347
|
+
*/
|
|
348
|
+
export declare function cloudNetworkWidens(prev: CloudNetworkSetting | undefined, next: CloudNetworkSetting | undefined): boolean;
|
|
312
349
|
/** 组织设置服务:读取与修改(修改需 `org.update`,锁内实时复核角色,写审计)。 */
|
|
313
350
|
export declare class OrgSettingsService {
|
|
314
351
|
private readonly db;
|
|
@@ -331,11 +368,27 @@ export declare class OrgSettingsService {
|
|
|
331
368
|
private parseStored;
|
|
332
369
|
/** 部署默认值(设置页展示「跟随部署」时的实际取值)。 */
|
|
333
370
|
deployment(): Promise<OrgSettingsDeployment>;
|
|
371
|
+
/**
|
|
372
|
+
* The org's effective sandbox-mode network (spec §D3): the cloud network's mode and the hosts,
|
|
373
|
+
* from the platform's `sandbox.limits` and the org's stored delta.
|
|
374
|
+
*/
|
|
375
|
+
effectiveNetwork(settings: Pick<OrgSettings, "cloudNetwork">): OrgEffectiveNetwork;
|
|
334
376
|
/** 组织实际生效的沙箱 cpu / 内存(只读;由超级管理员在部署设置里覆盖)。 */
|
|
335
377
|
sandboxLimits(orgId: string): Promise<OrgSandboxLimits>;
|
|
336
378
|
get(orgId: string): Promise<OrgSettings>;
|
|
337
|
-
/**
|
|
379
|
+
/**
|
|
380
|
+
* The refusals of {@link update} that need no read of the org (the Platform tool's precheck):
|
|
381
|
+
* auto mode where the platform turned it off.
|
|
382
|
+
*/
|
|
338
383
|
check(patch: OrgSettingsPatch): Promise<void>;
|
|
384
|
+
/**
|
|
385
|
+
* Under `sandbox.limits.orgHosts: within` (spec §D2), refuses what would widen past the platform
|
|
386
|
+
* ceiling compared with the stored value `before`: the open cloud network where the org did not
|
|
387
|
+
* store it, or an extra host outside the platform's allowlist that the org did not store. Stored
|
|
388
|
+
* values are sent back as they are (the PATCH replaces `cloudNetwork` whole) and have no effect
|
|
389
|
+
* under the ceiling (they are filtered on read), so they never block a write.
|
|
390
|
+
*/
|
|
391
|
+
assertWithinCeiling(before: OrgSettings, patch: OrgSettingsPatch): void;
|
|
339
392
|
update(orgId: string, patch: OrgSettingsPatch, actorAccountId: string, actorTokenId?: string,
|
|
340
393
|
/** Merged into the audit detail (the Platform tool's `via: "agent"`). */
|
|
341
394
|
auditDetail?: Record<string, unknown>,
|
|
@@ -351,15 +404,9 @@ export declare class OrgSettingsService {
|
|
|
351
404
|
* never the Platform tool or an API token):
|
|
352
405
|
* - `autoMode`: `allowed` where the organization runs `off` (an absent value follows the
|
|
353
406
|
* platform); clearing it follows the platform too, never wider than the platform allows;
|
|
354
|
-
* - `cloudNetwork`:
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
* `sandbox/modes.ts` becomes `deviceLimits.localAllowedDomains`, which the device intersects
|
|
358
|
-
* with its own list): an org with no `cloudNetwork` still caps its local devices at the
|
|
359
|
-
* deployment's list, and an org whose network is `open` still caps them at its own `allowHosts`.
|
|
360
|
-
* The host comparison therefore applies to both shapes, whatever the target mode: a patch may
|
|
361
|
-
* only keep or lower the host set. Switching from `open` is a widening by itself, and the host
|
|
362
|
-
* set must not grow even when the target stays `open` (spec §4.2, §4.3).
|
|
407
|
+
* - `cloudNetwork`: compared as stored deltas ({@link cloudNetworkWidens}), never as effective
|
|
408
|
+
* values: under the kill switch or the platform ceiling the effective values hide a widening
|
|
409
|
+
* that takes effect when the platform relaxes (org egress ceiling spec §D3).
|
|
363
410
|
*/
|
|
364
411
|
assertOnlyNarrows(before: OrgSettings, patch: OrgSettingsPatch): Promise<void>;
|
|
365
412
|
private updateIn;
|