@capybara-hq/kernel 0.1.0-rc.73 → 0.1.0-rc.75
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 +5 -5
- package/dist/catalog/admin-catalog.schemas.d.ts +3 -1
- package/dist/catalog/admin-catalog.schemas.js +6 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.schemas.d.ts +3 -1
- package/dist/catalog/org-catalog.schemas.js +3 -1
- package/dist/catalog/plugin-package.js +7 -5
- package/dist/catalog/reserved-names.js +3 -9
- package/dist/channels/actions.js +4 -0
- package/dist/channels/cards.d.ts +10 -7
- package/dist/channels/cards.js +23 -12
- package/dist/channels/phrases.d.ts +24 -2
- package/dist/channels/phrases.js +12 -2
- package/dist/ctx/secrets.d.ts +4 -2
- package/dist/ctx/secrets.js +19 -5
- package/dist/db/kernel-schema.d.ts +14 -0
- package/dist/devices/conversation-devices.d.ts +3 -2
- package/dist/devices/conversation-devices.js +9 -4
- package/dist/devices/device-projects.service.d.ts +22 -27
- package/dist/devices/device-projects.service.js +39 -44
- package/dist/devices/devices.controller.d.ts +3 -5
- package/dist/devices/devices.controller.js +4 -17
- package/dist/devices/devices.schemas.d.ts +1 -1
- package/dist/devices/devices.schemas.js +1 -1
- package/dist/devices/devices.service.d.ts +75 -52
- package/dist/devices/devices.service.js +166 -95
- package/dist/devices/project-rules.d.ts +6 -8
- package/dist/devices/project-rules.js +5 -11
- package/dist/dial-in/auth.service.js +1 -1
- package/dist/dial-in/machines.d.ts +4 -15
- package/dist/dial-in/machines.js +4 -59
- package/dist/errors.d.ts +8 -3
- package/dist/errors.js +8 -3
- package/dist/extensions/admin-ops.js +2 -1
- package/dist/extensions/bootstrap-extra.d.ts +11 -1
- package/dist/extensions/bootstrap-extra.js +21 -1
- package/dist/extensions/bootstrap-manifest.d.ts +14 -0
- package/dist/extensions/bootstrap-manifest.js +23 -0
- package/dist/extensions/bootstrap-packages.d.ts +87 -0
- package/dist/extensions/bootstrap-packages.js +263 -0
- package/dist/extensions/bootstrap.d.ts +27 -71
- package/dist/extensions/bootstrap.js +85 -329
- package/dist/extensions/guide-places.d.ts +9 -0
- package/dist/extensions/guide-places.js +32 -22
- package/dist/extensions/plugin-guides.d.ts +20 -2
- package/dist/extensions/plugin-guides.js +39 -14
- package/dist/http/meta.controller.d.ts +0 -1
- package/dist/http/meta.controller.js +2 -6
- package/dist/identity/sso-paths.d.ts +7 -0
- package/dist/identity/sso-paths.js +13 -0
- package/dist/identity/sso.js +3 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +2 -2
- package/dist/platform/exclusions.js +2 -7
- package/dist/platform/ops/devices.ops.js +11 -7
- package/dist/platform/ops/setup.ops.js +1 -1
- package/dist/runtime/project/knowledge.service.js +6 -5
- package/dist/sandbox/device-sandbox.d.ts +27 -2
- package/dist/sandbox/device-sandbox.js +42 -5
- package/dist/sandbox/modes.d.ts +16 -4
- package/dist/sandbox/modes.js +12 -0
- package/dist/sandbox/operation-authority.js +3 -1
- package/dist/sandbox/permission-authority-lock.d.ts +6 -0
- package/dist/sandbox/permission-authority-lock.js +14 -0
- package/dist/sandbox/permission-facts.d.ts +16 -2
- package/dist/sandbox/permission-facts.js +20 -5
- package/dist/sandbox/review/permission-candidate.d.ts +12 -7
- package/dist/sandbox/review/permission-candidate.js +28 -7
- package/dist/sandbox/sandbox.service.d.ts +18 -11
- package/dist/sandbox/sandbox.service.js +51 -24
- package/dist/setup/setup-guides.service.d.ts +3 -4
- package/dist/setup/setup-guides.service.js +2 -5
- package/dist/shares/sweep.job.d.ts +2 -0
- package/dist/shares/sweep.job.js +3 -1
- package/dist/tools/approvals.service.d.ts +31 -11
- package/dist/tools/approvals.service.js +55 -19
- package/dist/tools/builtins/sandbox/common.d.ts +2 -2
- package/dist/tools/builtins/sandbox/common.js +2 -2
- package/dist/tools/network-asks.d.ts +103 -20
- package/dist/tools/network-asks.js +133 -18
- package/dist/tools/pipeline.d.ts +5 -0
- package/dist/tools/pipeline.js +15 -8
- package/package.json +3 -3
- package/src/migrations/0178_bootstrap_run_extra.sql +17 -0
|
@@ -46,8 +46,7 @@ function fenceFor(text) {
|
|
|
46
46
|
return "`".repeat(Math.max(3, longest + 1));
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
* The blocks of a rendered guide as one Markdown document (checks as `- [check <id>]` lines
|
|
50
|
-
* actions as `- [shell action <action>]` lines).
|
|
49
|
+
* The blocks of a rendered guide as one Markdown document (checks as `- [check <id>]` lines).
|
|
51
50
|
*/
|
|
52
51
|
export function guideMarkdown(title, blocks) {
|
|
53
52
|
const parts = [`# ${title}`];
|
|
@@ -56,8 +55,6 @@ export function guideMarkdown(title, blocks) {
|
|
|
56
55
|
parts.push(b.text.trimEnd());
|
|
57
56
|
else if (b.kind === "check")
|
|
58
57
|
parts.push(`- [check ${b.id}] ${b.label}`);
|
|
59
|
-
else if (b.kind === "shell-action")
|
|
60
|
-
parts.push(`- [shell action ${b.action}] ${b.label}`);
|
|
61
58
|
else {
|
|
62
59
|
const fence = fenceFor(b.text);
|
|
63
60
|
const code = `${fence}${b.language}\n${b.text.replace(/\n$/, "")}\n${fence}`;
|
|
@@ -135,7 +132,7 @@ let SetupGuidesService = class SetupGuidesService {
|
|
|
135
132
|
plugin: g.plugin,
|
|
136
133
|
guideId: g.id,
|
|
137
134
|
place: g.place,
|
|
138
|
-
|
|
135
|
+
templates: g.templates,
|
|
139
136
|
audience: p.audience,
|
|
140
137
|
title: g.title,
|
|
141
138
|
targets: [],
|
|
@@ -7,6 +7,8 @@ import { StorageService } from "../storage/storage.service.js";
|
|
|
7
7
|
import { ShareObjects } from "./share-objects.js";
|
|
8
8
|
/** The daily share sweep's name (scheduler key and lock; no `:`). */
|
|
9
9
|
export declare const SHARE_SWEEP_JOB = "share-sweep";
|
|
10
|
+
/** When the daily share sweep runs (the deployment's time zone). */
|
|
11
|
+
export declare const SHARE_SWEEP_CRON = "40 3 * * *";
|
|
10
12
|
/** What one sweep did (logged; returned for tests). */
|
|
11
13
|
export interface ShareSweepResult {
|
|
12
14
|
/** Shares revoked with `creator_lost_access` (their snapshots owed for deletion). */
|
package/dist/shares/sweep.job.js
CHANGED
|
@@ -22,6 +22,8 @@ import { revokeSharesIn } from "./revoke.js";
|
|
|
22
22
|
import { ShareObjects, shareObjectKey, shareRefreshLockKey, } from "./share-objects.js";
|
|
23
23
|
/** The daily share sweep's name (scheduler key and lock; no `:`). */
|
|
24
24
|
export const SHARE_SWEEP_JOB = "share-sweep";
|
|
25
|
+
/** When the daily share sweep runs (the deployment's time zone). */
|
|
26
|
+
export const SHARE_SWEEP_CRON = "40 3 * * *";
|
|
25
27
|
/** Rows per batch (one transaction per batch of revokes; one query per batch of reads). */
|
|
26
28
|
const BATCH = 200;
|
|
27
29
|
/** Snapshots of shares expired or revoked longer ago than this are deleted (rows kept). */
|
|
@@ -312,7 +314,7 @@ let ShareSweepJob = class ShareSweepJob {
|
|
|
312
314
|
}
|
|
313
315
|
};
|
|
314
316
|
__decorate([
|
|
315
|
-
LockedCron(
|
|
317
|
+
LockedCron(SHARE_SWEEP_CRON, { name: SHARE_SWEEP_JOB })
|
|
316
318
|
], ShareSweepJob.prototype, "sweep", null);
|
|
317
319
|
__decorate([
|
|
318
320
|
Transactional()
|
|
@@ -2,6 +2,7 @@ import { type LocalizedName, type ToolDisplay } from "@capybara-hq/plugin-sdk";
|
|
|
2
2
|
import { EventLog } from "../conversations/event-log.js";
|
|
3
3
|
import { type ReviewRecord, type ToolView } from "../conversations/events.js";
|
|
4
4
|
import { ConversationLeakCheck } from "../conversations/leak-check.js";
|
|
5
|
+
import { DevicesService } from "../devices/devices.service.js";
|
|
5
6
|
import { type PersonRef } from "../identity/account-avatar.js";
|
|
6
7
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
7
8
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -54,10 +55,17 @@ export interface KeptToolResult {
|
|
|
54
55
|
code: string;
|
|
55
56
|
};
|
|
56
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* When hosts added to a device's own network list take effect (device-provider spec §6.3): from
|
|
60
|
+
* the next command (per-operation hosts), the next time the device is used (an instance boundary),
|
|
61
|
+
* or after its files are rebuilt (a provider that fixes limits at its file system).
|
|
62
|
+
*/
|
|
63
|
+
export type NetworkAppliesAt = "next-command" | "next-use" | "files-reset";
|
|
57
64
|
/**
|
|
58
65
|
* A network ask's `detail` (network ask-to-allow spec §6.1, P-D2): the device, the refused hosts,
|
|
59
66
|
* the command and its kept `tool_result` (written with a note when the ask settles; the command is
|
|
60
|
-
* never run again), and once approved what took
|
|
67
|
+
* never run again), when "add to this device's list" would apply, and once approved what took
|
|
68
|
+
* effect.
|
|
61
69
|
*/
|
|
62
70
|
export interface NetworkAskDetail {
|
|
63
71
|
deviceId: string;
|
|
@@ -67,15 +75,17 @@ export interface NetworkAskDetail {
|
|
|
67
75
|
}[];
|
|
68
76
|
command: string;
|
|
69
77
|
description: string | null;
|
|
78
|
+
/** When hosts added to the device's own list apply ({@link NetworkAppliesAt}). */
|
|
79
|
+
appliesAt: NetworkAppliesAt;
|
|
70
80
|
/** The formatted `tool_result` of the command and its display-only fields. */
|
|
71
81
|
result: KeptToolResult;
|
|
72
82
|
/** The hosts the decision allowed (every approved decision writes them; none: nothing). */
|
|
73
83
|
grantedHosts?: string[];
|
|
74
84
|
/**
|
|
75
|
-
* What took effect: a run grant (`once
|
|
76
|
-
*
|
|
85
|
+
* What took effect: a run grant (`once`), or the hosts added to the device's own network list
|
|
86
|
+
* (`always`, applying at `appliesAt`; no run grant).
|
|
77
87
|
*/
|
|
78
|
-
outcome?: "once";
|
|
88
|
+
outcome?: "once" | "always";
|
|
79
89
|
}
|
|
80
90
|
/** A network ask's detail as the API shows it: without the kept command result. */
|
|
81
91
|
export type NetworkAskView = Omit<NetworkAskDetail, "result">;
|
|
@@ -379,10 +389,11 @@ export interface NetworkAskInput {
|
|
|
379
389
|
requestedFor: string;
|
|
380
390
|
detail: Omit<NetworkAskDetail, "grantedHosts" | "outcome">;
|
|
381
391
|
/**
|
|
382
|
-
*
|
|
383
|
-
*
|
|
392
|
+
* What the device's provider enforces (device-provider spec §6.3, `networkAskOffer`): `once` (a
|
|
393
|
+
* run grant) only with per-operation hosts, `always` (add to the device's own list) only when
|
|
394
|
+
* every asked host may join it.
|
|
384
395
|
*/
|
|
385
|
-
scopes: "once"[];
|
|
396
|
+
scopes: ("once" | "always")[];
|
|
386
397
|
}
|
|
387
398
|
/** The tool key a network ask is recorded under (the command ran in `Bash`). */
|
|
388
399
|
export declare const NETWORK_ASK_TOOL_KEY = "Bash";
|
|
@@ -449,6 +460,8 @@ export declare class ApprovalsService {
|
|
|
449
460
|
private readonly leakCheck;
|
|
450
461
|
/** A person's entered values are sealed in the decision's transaction (§4.3). */
|
|
451
462
|
private readonly sealed;
|
|
463
|
+
/** A network ask's "add to this device's list" writes the device's own network list. */
|
|
464
|
+
private readonly devices;
|
|
452
465
|
private readonly permissionLocks?;
|
|
453
466
|
private readonly permissionGrants?;
|
|
454
467
|
constructor(db: KernelDb, config: Pick<KernelConfigService, "get">, eventLog: Pick<EventLog, "appendIn" | "notify">, events: Pick<KernelEvents, "emit">, txHost: TransactionHost, schedules: Pick<ScheduledTaskStore, "addGrant">,
|
|
@@ -463,7 +476,9 @@ export declare class ApprovalsService {
|
|
|
463
476
|
/** An entered person value seen in the conversation is refused (§4.5). */
|
|
464
477
|
leakCheck: Pick<ConversationLeakCheck, "leaked">,
|
|
465
478
|
/** A person's entered values are sealed in the decision's transaction (§4.3). */
|
|
466
|
-
sealed: Pick<SealedInputs, "sealIn">,
|
|
479
|
+
sealed: Pick<SealedInputs, "sealIn">,
|
|
480
|
+
/** A network ask's "add to this device's list" writes the device's own network list. */
|
|
481
|
+
devices: Pick<DevicesService, "lockNetworkAddSubject" | "addNetworkHostsIn">, permissionLocks?: PermissionAuthorityLock | undefined, permissionGrants?: PermissionCallGrants | undefined);
|
|
467
482
|
/**
|
|
468
483
|
* 新建 pending 审批(`expires_at` = 现在 + `tools.approvalTimeoutHours`)并写 `approval_requested`,同一事务。
|
|
469
484
|
* 按 (run_id, call_id, attempt) 幂等:已存在则返回已有记录(不覆盖),事件按 `approval_requested:<approvalId>` 幂等。
|
|
@@ -524,9 +539,14 @@ export declare class ApprovalsService {
|
|
|
524
539
|
* A network ask's decision (network ask-to-allow spec §5.2), one at a time per ask across
|
|
525
540
|
* replicas: only the device owner (`requested_for`) decides, in a signed-in session (a personal
|
|
526
541
|
* access token is refused; the route already refuses service and embed tokens); the allowed
|
|
527
|
-
* hosts are a subset of those asked
|
|
528
|
-
*
|
|
529
|
-
*
|
|
542
|
+
* hosts are a subset of those asked, and the scope one the ask offers (device-provider spec
|
|
543
|
+
* §6.3). `once` is a run grant (the row itself); `always` adds the hosts to the device's own
|
|
544
|
+
* network list in the decision's transaction (`DevicesService.addNetworkHostsIn`, no run grant;
|
|
545
|
+
* the command that asked is not run again and the hosts apply at the ask's `appliesAt`). For
|
|
546
|
+
* `always` the transaction opens with the device's ordered prelude (`lockNetworkAddSubject`: the
|
|
547
|
+
* owner's membership, the device row, its permission write lock) before the conversation,
|
|
548
|
+
* approval and run rows; this method's distributed lock stays outside it. Every decision
|
|
549
|
+
* resumes the run in its transaction and is announced after the commit.
|
|
530
550
|
*/
|
|
531
551
|
private decideNetwork;
|
|
532
552
|
/**
|
|
@@ -16,6 +16,7 @@ import { EventLog } from "../conversations/event-log.js";
|
|
|
16
16
|
import { COMMAND_ASK_TEXT_MAX_CHARS, GIT_ASK_MAX_REFS, GIT_REF_MAX_CHARS, NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS, SECURE_INPUT_MAX_FIELDS, } from "../conversations/events.js";
|
|
17
17
|
import { ConversationLeakCheck } from "../conversations/leak-check.js";
|
|
18
18
|
import { conversationSourceOf } from "../conversations/source.js";
|
|
19
|
+
import { DevicesService } from "../devices/devices.service.js";
|
|
19
20
|
import { ApiError } from "../errors.js";
|
|
20
21
|
import { clipText } from "../extensions/hooks.js";
|
|
21
22
|
import { loadPeople } from "../identity/account-avatar.js";
|
|
@@ -23,7 +24,7 @@ import { audit } from "../identity/audit.js";
|
|
|
23
24
|
import { sha256Hex } from "../identity/hash.js";
|
|
24
25
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
25
26
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
26
|
-
import { TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
27
|
+
import { TransactionHost, withOrderedLocks, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
27
28
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
28
29
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
29
30
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
@@ -109,6 +110,11 @@ function personFieldsOf(detail) {
|
|
|
109
110
|
d.leakedFields.length > 0 && { leakedFields: d.leakedFields }),
|
|
110
111
|
};
|
|
111
112
|
}
|
|
113
|
+
const NETWORK_APPLIES_AT = new Set([
|
|
114
|
+
"next-command",
|
|
115
|
+
"next-use",
|
|
116
|
+
"files-reset",
|
|
117
|
+
]);
|
|
112
118
|
/** The tool key a network ask is recorded under (the command ran in `Bash`). */
|
|
113
119
|
export const NETWORK_ASK_TOOL_KEY = "Bash";
|
|
114
120
|
/** The spec hash of a network ask (no tool definition is approved). */
|
|
@@ -215,6 +221,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
215
221
|
resumes;
|
|
216
222
|
leakCheck;
|
|
217
223
|
sealed;
|
|
224
|
+
devices;
|
|
218
225
|
permissionLocks;
|
|
219
226
|
permissionGrants;
|
|
220
227
|
constructor(db, config, eventLog, events, txHost, schedules,
|
|
@@ -229,7 +236,9 @@ let ApprovalsService = class ApprovalsService {
|
|
|
229
236
|
/** An entered person value seen in the conversation is refused (§4.5). */
|
|
230
237
|
leakCheck,
|
|
231
238
|
/** A person's entered values are sealed in the decision's transaction (§4.3). */
|
|
232
|
-
sealed,
|
|
239
|
+
sealed,
|
|
240
|
+
/** A network ask's "add to this device's list" writes the device's own network list. */
|
|
241
|
+
devices, permissionLocks, permissionGrants) {
|
|
233
242
|
this.db = db;
|
|
234
243
|
this.config = config;
|
|
235
244
|
this.eventLog = eventLog;
|
|
@@ -242,6 +251,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
242
251
|
this.resumes = resumes;
|
|
243
252
|
this.leakCheck = leakCheck;
|
|
244
253
|
this.sealed = sealed;
|
|
254
|
+
this.devices = devices;
|
|
245
255
|
this.permissionLocks = permissionLocks;
|
|
246
256
|
this.permissionGrants = permissionGrants;
|
|
247
257
|
}
|
|
@@ -425,8 +435,14 @@ let ApprovalsService = class ApprovalsService {
|
|
|
425
435
|
if (hosts.some((h) => h.host.length === 0 || h.host.length > NETWORK_HOST_MAX_CHARS)) {
|
|
426
436
|
throw new Error("a network ask's host is 1 to 255 characters");
|
|
427
437
|
}
|
|
428
|
-
|
|
429
|
-
|
|
438
|
+
const scopes = new Set(input.scopes);
|
|
439
|
+
if (scopes.size === 0 ||
|
|
440
|
+
scopes.size !== input.scopes.length ||
|
|
441
|
+
[...scopes].some((k) => k !== "once" && k !== "always")) {
|
|
442
|
+
throw new Error('a network ask offers "once", "always" or both, each once');
|
|
443
|
+
}
|
|
444
|
+
if (!NETWORK_APPLIES_AT.has(input.detail.appliesAt)) {
|
|
445
|
+
throw new Error(`a network ask's appliesAt is one of ${[...NETWORK_APPLIES_AT].join(", ")}`);
|
|
430
446
|
}
|
|
431
447
|
const { record, toSeq } = await this.requestNetworkIn(input);
|
|
432
448
|
if (toSeq !== null)
|
|
@@ -850,9 +866,14 @@ let ApprovalsService = class ApprovalsService {
|
|
|
850
866
|
* A network ask's decision (network ask-to-allow spec §5.2), one at a time per ask across
|
|
851
867
|
* replicas: only the device owner (`requested_for`) decides, in a signed-in session (a personal
|
|
852
868
|
* access token is refused; the route already refuses service and embed tokens); the allowed
|
|
853
|
-
* hosts are a subset of those asked
|
|
854
|
-
*
|
|
855
|
-
*
|
|
869
|
+
* hosts are a subset of those asked, and the scope one the ask offers (device-provider spec
|
|
870
|
+
* §6.3). `once` is a run grant (the row itself); `always` adds the hosts to the device's own
|
|
871
|
+
* network list in the decision's transaction (`DevicesService.addNetworkHostsIn`, no run grant;
|
|
872
|
+
* the command that asked is not run again and the hosts apply at the ask's `appliesAt`). For
|
|
873
|
+
* `always` the transaction opens with the device's ordered prelude (`lockNetworkAddSubject`: the
|
|
874
|
+
* owner's membership, the device row, its permission write lock) before the conversation,
|
|
875
|
+
* approval and run rows; this method's distributed lock stays outside it. Every decision
|
|
876
|
+
* resumes the run in its transaction and is announced after the commit.
|
|
856
877
|
*/
|
|
857
878
|
async decideNetwork(orgId, id, accountId, body, actorTokenId, via) {
|
|
858
879
|
const row = await this.db
|
|
@@ -896,11 +917,9 @@ let ApprovalsService = class ApprovalsService {
|
|
|
896
917
|
let network;
|
|
897
918
|
if (body.decision === "approve") {
|
|
898
919
|
const scope = body.scope ?? "once";
|
|
899
|
-
//
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
if (scope !== "once" || !ask.scopes.includes(scope)) {
|
|
903
|
-
throw new ApiError("approval.scope_not_allowed", `Scope "${scope}" is not allowed for this approval; allowed: once`);
|
|
920
|
+
// only what the ask offers: what the device's provider enforces (device-provider spec §6.3)
|
|
921
|
+
if ((scope !== "once" && scope !== "always") || !ask.scopes.includes(scope)) {
|
|
922
|
+
throw new ApiError("approval.scope_not_allowed", `Scope "${scope}" is not allowed for this approval; allowed: ${ask.scopes.join(", ")}`);
|
|
904
923
|
}
|
|
905
924
|
const unknown = (body.hosts ?? []).filter((h) => !asked.includes(h));
|
|
906
925
|
if (unknown.length > 0) {
|
|
@@ -915,7 +934,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
915
934
|
{ path: "hosts", message: "Choose at least one host" },
|
|
916
935
|
]);
|
|
917
936
|
}
|
|
918
|
-
network = { wanted: granted, granted, outcome:
|
|
937
|
+
network = { wanted: granted, granted, outcome: scope, via };
|
|
919
938
|
}
|
|
920
939
|
else {
|
|
921
940
|
if (body.hosts !== undefined) {
|
|
@@ -925,7 +944,22 @@ let ApprovalsService = class ApprovalsService {
|
|
|
925
944
|
}
|
|
926
945
|
network = { wanted: [], granted: [], outcome: null, via };
|
|
927
946
|
}
|
|
928
|
-
const
|
|
947
|
+
const decide = () => this.decideIn(orgId, id, accountId, body, actorTokenId, network);
|
|
948
|
+
let decided;
|
|
949
|
+
if (network.outcome === "always") {
|
|
950
|
+
const granted = network.granted;
|
|
951
|
+
// the decider is the device's owner (checked above; the prelude checks it again under the
|
|
952
|
+
// device row's lock). The device write is the prelude's, before any conversation row: a
|
|
953
|
+
// widening locks the device's Full access root conversations (global order device →
|
|
954
|
+
// authority → root conversation → conversation), so it must precede the asking
|
|
955
|
+
// conversation's row. A refusal of the decision below rolls the addition back with it.
|
|
956
|
+
decided = await withOrderedLocks(async () => {
|
|
957
|
+
await this.devices.lockNetworkAddSubject(orgId, accountId, detail.deviceId);
|
|
958
|
+
await this.devices.addNetworkHostsIn(orgId, accountId, detail.deviceId, granted, via);
|
|
959
|
+
}, decide);
|
|
960
|
+
}
|
|
961
|
+
else
|
|
962
|
+
decided = await decide();
|
|
929
963
|
await this.announceDecided(decided.record, decided.toSeq);
|
|
930
964
|
return decided.record;
|
|
931
965
|
}
|
|
@@ -1203,7 +1237,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1203
1237
|
? (command.scope ?? "once")
|
|
1204
1238
|
: network === undefined
|
|
1205
1239
|
? (body.scope ?? "once")
|
|
1206
|
-
: "once";
|
|
1240
|
+
: (network.outcome ?? "once");
|
|
1207
1241
|
// 按角色升级的批准只对这一次有效:授权记在发起人名下会让其以后绕过角色要求
|
|
1208
1242
|
if (scope !== null && scope !== "once" && before.requestedFor === null) {
|
|
1209
1243
|
throw new ApiError("validation_failed", 'Only scope "once" is allowed for role-escalated approvals', [{ path: "scope", message: 'Only "once" is allowed for role-escalated approvals' }]);
|
|
@@ -1258,7 +1292,8 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1258
1292
|
const hash = before.specHash;
|
|
1259
1293
|
const connectorId = before.connectorId;
|
|
1260
1294
|
if (network !== undefined) {
|
|
1261
|
-
// a network ask grants nothing of the tool kind: its run grant is the row itself
|
|
1295
|
+
// a network ask grants nothing of the tool kind: its run grant is the row itself (`once`);
|
|
1296
|
+
// `always` added the hosts to the device's list in the decision's prelude
|
|
1262
1297
|
}
|
|
1263
1298
|
else if (git !== undefined) {
|
|
1264
1299
|
// a git ask's run grant is the row itself; `always` is the actor's standing allow for the
|
|
@@ -2111,9 +2146,10 @@ ApprovalsService = __decorate([
|
|
|
2111
2146
|
__param(9, Inject(RunResume)),
|
|
2112
2147
|
__param(10, Inject(ConversationLeakCheck)),
|
|
2113
2148
|
__param(11, Inject(SealedInputs)),
|
|
2114
|
-
__param(12,
|
|
2115
|
-
__param(12, Inject(PermissionAuthorityLock)),
|
|
2149
|
+
__param(12, Inject(DevicesService)),
|
|
2116
2150
|
__param(13, Optional()),
|
|
2117
|
-
__param(13, Inject(
|
|
2151
|
+
__param(13, Inject(PermissionAuthorityLock)),
|
|
2152
|
+
__param(14, Optional()),
|
|
2153
|
+
__param(14, Inject(PermissionCallGrants))
|
|
2118
2154
|
], ApprovalsService);
|
|
2119
2155
|
export { ApprovalsService };
|
|
@@ -283,8 +283,8 @@ export declare const SCOPE_DENIED_TOOL_TEXT = "This operation reaches outside th
|
|
|
283
283
|
export declare const ESCALATION_GRANT_MISSING_TEXT = "This Bash call was approved to run outside the sandbox, but the approval no longer matches: the device, its outside-sandbox setting or this conversation's permission scope changed since it was approved, so it did not run. Call Bash again with sandbox: \"escalated\" and a justification to ask again, or call it without sandbox to run it inside the sandbox.";
|
|
284
284
|
/** {@link ESCALATION_GRANT_MISSING_TEXT} as the reason of a refused background start. */
|
|
285
285
|
export declare const ESCALATION_GRANT_MISSING_LAUNCH_WHY = "its approval to run outside the sandbox no longer matches (the device, its outside-sandbox setting or the permission scope changed since it was approved); call Bash again with sandbox: \"escalated\" and a justification to ask again";
|
|
286
|
-
/** A
|
|
287
|
-
export declare const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected before this operation was sent, so nothing ran. Retry the tool call.";
|
|
286
|
+
/** A request the machine never got: it reconnected, or its instance was gone, before it was sent. */
|
|
287
|
+
export declare const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected or changed before this operation was sent, so nothing ran. Retry the tool call.";
|
|
288
288
|
/** The device itself refused: it cannot enforce its sandbox (`SandboxPermissionUnsupportedError`). */
|
|
289
289
|
export declare const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device refused to run the operation because it cannot enforce its sandbox limits, so nothing ran. Ask the device's owner to update its device program (or a super admin to update its device plugin), or continue without the device.";
|
|
290
290
|
/** Earlier work on the device blocks a new operation (`SandboxWorkUnsettledError`). */
|
|
@@ -314,8 +314,8 @@ export const SCOPE_DENIED_TOOL_TEXT = "This operation reaches outside the scope
|
|
|
314
314
|
export const ESCALATION_GRANT_MISSING_TEXT = 'This Bash call was approved to run outside the sandbox, but the approval no longer matches: the device, its outside-sandbox setting or this conversation\'s permission scope changed since it was approved, so it did not run. Call Bash again with sandbox: "escalated" and a justification to ask again, or call it without sandbox to run it inside the sandbox.';
|
|
315
315
|
/** {@link ESCALATION_GRANT_MISSING_TEXT} as the reason of a refused background start. */
|
|
316
316
|
export const ESCALATION_GRANT_MISSING_LAUNCH_WHY = 'its approval to run outside the sandbox no longer matches (the device, its outside-sandbox setting or the permission scope changed since it was approved); call Bash again with sandbox: "escalated" and a justification to ask again';
|
|
317
|
-
/** A
|
|
318
|
-
export const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected before this operation was sent, so nothing ran. Retry the tool call.";
|
|
317
|
+
/** A request the machine never got: it reconnected, or its instance was gone, before it was sent. */
|
|
318
|
+
export const DEVICE_REQUEST_NOT_SENT_TOOL_TEXT = "The device's machine reconnected or changed before this operation was sent, so nothing ran. Retry the tool call.";
|
|
319
319
|
/** The device itself refused: it cannot enforce its sandbox (`SandboxPermissionUnsupportedError`). */
|
|
320
320
|
export const PERMISSION_UNSUPPORTED_TOOL_TEXT = "This device refused to run the operation because it cannot enforce its sandbox limits, so nothing ran. Ask the device's owner to update its device program (or a super admin to update its device plugin), or continue without the device.";
|
|
321
321
|
/** Earlier work on the device blocks a new operation (`SandboxWorkUnsettledError`). */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type NetworkBlockedHost } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { NetworkRunState } from "../sandbox/network-grants.js";
|
|
3
3
|
import { type UnattendedRun } from "../schedules/unattended.js";
|
|
4
|
-
import { type ApprovalRecord } from "./approvals.service.js";
|
|
4
|
+
import { type ApprovalRecord, type NetworkAppliesAt } from "./approvals.service.js";
|
|
5
5
|
/**
|
|
6
6
|
* Network asks in the tool pipeline (network ask-to-allow spec §6.2, §6.6–§6.9, §8.3): what a
|
|
7
7
|
* command's reported refusals turn into (an ask to the device owner, or notes written at once) and
|
|
@@ -16,10 +16,74 @@ export declare const NETWORK_ASK_CLIPPED_NOTE = "[Output clipped to its first 16
|
|
|
16
16
|
/** The idempotency key of a call's `network_blocked` event. */
|
|
17
17
|
export declare const networkBlockedIdemKey: (runId: string, callId: string) => string;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* What a network ask offers (device-provider spec §6.3): only what the device's provider enforces.
|
|
20
|
+
* `once` (a run grant) needs per-operation hosts; `always` adds the hosts to the device's own
|
|
21
|
+
* network list, which takes effect at `appliesAt`.
|
|
21
22
|
*/
|
|
23
|
+
export interface NetworkAskOffer {
|
|
24
|
+
scopes: ("once" | "always")[];
|
|
25
|
+
appliesAt: NetworkAppliesAt;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The offer of a network ask on a device (device-provider spec §6.3): with per-operation hosts
|
|
29
|
+
* (`support.perOperationHosts`, an operation boundary) `once`, plus `always` when every asked host
|
|
30
|
+
* may join the device's own list (`listAddable`), applying from the next command; otherwise
|
|
31
|
+
* `always` only, applying the next time the device is used, or after the files are rebuilt when
|
|
32
|
+
* its provider fixes limits at its file system (`limitsApplyAt: "fileSystem"`). Null: nothing to
|
|
33
|
+
* offer (no per-operation hosts and not addable), so the host is never asked about.
|
|
34
|
+
*/
|
|
35
|
+
export declare function networkAskOffer(support: {
|
|
36
|
+
perOperationHosts: boolean;
|
|
37
|
+
}, limitsApplyAt: "instance" | "fileSystem" | undefined, listAddable: boolean): NetworkAskOffer | null;
|
|
38
|
+
/** What a device's sandbox says about what a network ask may offer (`SandboxService.hostRefusal`). */
|
|
39
|
+
export interface DeviceAskFacts {
|
|
40
|
+
/** Why a per-call grant for a host is unavailable (`hostGrantRefusal`), or null. */
|
|
41
|
+
refusal: (host: string) => string | null;
|
|
42
|
+
/** Why a host cannot join the device's own network list (`deviceListAddRefusal`), or null. */
|
|
43
|
+
listAddRefusal: (host: string) => string | null;
|
|
44
|
+
/**
|
|
45
|
+
* `perCallHosts`: the provider gives each operation its own hosts (an operation boundary);
|
|
46
|
+
* `hosts`: the device's effective allowlist (its own list within the org's hosts, else the org's
|
|
47
|
+
* hosts), what the device should allow.
|
|
48
|
+
*/
|
|
49
|
+
box: {
|
|
50
|
+
perCallHosts: boolean;
|
|
51
|
+
hosts: readonly string[];
|
|
52
|
+
};
|
|
53
|
+
/** The device's network is an allowlist with a host list of its own. */
|
|
54
|
+
ownList: boolean;
|
|
55
|
+
/** That list's hosts (entries may be `*.` patterns). */
|
|
56
|
+
ownHosts: readonly string[];
|
|
57
|
+
limitsApplyAt: "instance" | "fileSystem" | undefined;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The plan's `refusal` and `offer` on a device (device-provider spec §6.3). With per-operation
|
|
61
|
+
* hosts a host is offered unless a per-call grant is unavailable; without, unless it cannot join
|
|
62
|
+
* the device's own list (so a host outside the org's effective hosts is never offered). `always`
|
|
63
|
+
* is offered only when the device has a list of its own and every asked host may join it (what
|
|
64
|
+
* `addNetworkHostsIn` accepts), so an offered decision does not fail for that.
|
|
65
|
+
*/
|
|
66
|
+
export declare function deviceAskTerms(f: DeviceAskFacts): Required<Pick<NetworkPlanContext, "refusal" | "offer" | "onList" | "deviceBlocks">>;
|
|
67
|
+
/** Asked, allowed this time (a run grant: "once"). */
|
|
22
68
|
export declare const allowedOnceNote: (hosts: readonly string[]) => string;
|
|
69
|
+
/**
|
|
70
|
+
* Asked, added to the device's own network list ("always", device-provider spec §6.3): the hosts
|
|
71
|
+
* apply at `appliesAt`, never to the command that asked, which is not run again.
|
|
72
|
+
*/
|
|
73
|
+
export declare const addedToDeviceNote: (hosts: readonly string[], appliesAt: NetworkAppliesAt) => string;
|
|
74
|
+
/**
|
|
75
|
+
* Not asked: the device's network settings already allow the host (its own list, added by an
|
|
76
|
+
* earlier answer or on the device page, or the org's hosts it follows), but its sandbox has not
|
|
77
|
+
* applied them yet; they apply at `appliesAt`, not to this command (device-provider spec §6.3).
|
|
78
|
+
*/
|
|
79
|
+
export declare const onListNote: (hosts: readonly string[], appliesAt: NetworkAppliesAt) => string;
|
|
80
|
+
/**
|
|
81
|
+
* Not asked: on a device whose operations each carry its own host list, the list allows the host
|
|
82
|
+
* and it went out with the command, so the refusal comes from the device itself (such as
|
|
83
|
+
* its owner's local policy on the machine, device-provider spec §7.3); nothing in the
|
|
84
|
+
* conversation changes it.
|
|
85
|
+
*/
|
|
86
|
+
export declare const deviceOwnBlockNote: (hosts: readonly string[]) => string;
|
|
23
87
|
/** Asked and declined (also the unchecked hosts of a partial decision, and a host refused earlier in the run). */
|
|
24
88
|
export declare const deniedNote: (hosts: readonly string[], reason?: string | null) => string;
|
|
25
89
|
/** Asked, no answer within the approval timeout. */
|
|
@@ -72,10 +136,11 @@ export declare const unattendedNetworkNote: (hosts: readonly string[]) => string
|
|
|
72
136
|
/** What the pipeline knows when a command reported refused hosts. */
|
|
73
137
|
export interface NetworkPlanContext {
|
|
74
138
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
139
|
+
* What an ask about `hosts` would offer on the device ({@link networkAskOffer}); null: nothing,
|
|
140
|
+
* so those hosts get an unavailable note. Absent (no device sandbox known): a device-layer host
|
|
141
|
+
* is never asked about.
|
|
77
142
|
*/
|
|
78
|
-
|
|
143
|
+
offer?: (hosts: string[]) => NetworkAskOffer | null;
|
|
79
144
|
/** The scheduled task run the run serves (null / undefined: attended). */
|
|
80
145
|
unattended: UnattendedRun | null | undefined;
|
|
81
146
|
/**
|
|
@@ -84,10 +149,23 @@ export interface NetworkPlanContext {
|
|
|
84
149
|
*/
|
|
85
150
|
outsideCeiling?: (host: string) => boolean;
|
|
86
151
|
/**
|
|
87
|
-
* Why a
|
|
88
|
-
*
|
|
152
|
+
* Why a host cannot be offered on the device, or null when it may: with per-operation hosts why
|
|
153
|
+
* a per-call grant is unavailable (`hostGrantRefusal`), else why it cannot join the device's own
|
|
154
|
+
* list (`deviceListAddRefusal`). An unavailable host is never asked about; its note names who
|
|
155
|
+
* adds it.
|
|
89
156
|
*/
|
|
90
157
|
refusal?: (host: string) => string | null;
|
|
158
|
+
/**
|
|
159
|
+
* When a host the device's network settings already allow (its own list, or its org's hosts when
|
|
160
|
+
* it follows them) applies there, or null when they do not allow it: such a host is not asked
|
|
161
|
+
* again, its note says when it applies.
|
|
162
|
+
*/
|
|
163
|
+
onList?: (host: string) => NetworkAppliesAt | null;
|
|
164
|
+
/**
|
|
165
|
+
* Whether a device-layer refusal of a host comes from the device itself (its own list allows the
|
|
166
|
+
* host and every operation carries it): never asked, {@link deviceOwnBlockNote}.
|
|
167
|
+
*/
|
|
168
|
+
deviceBlocks?: (host: string) => boolean;
|
|
91
169
|
/**
|
|
92
170
|
* {@link addressEscalationHint}: a private-address block of an attended run answers with the
|
|
93
171
|
* escalation hint.
|
|
@@ -101,14 +179,13 @@ export interface NetworkPlanContext {
|
|
|
101
179
|
}
|
|
102
180
|
/** What to do with a command's refused hosts. */
|
|
103
181
|
export interface NetworkPlan {
|
|
104
|
-
/**
|
|
105
|
-
* The device-layer hosts to ask the device owner about (empty: no ask). The ask offers a run
|
|
106
|
-
* grant only; the owner adds a host to the device's own list on its page.
|
|
107
|
-
*/
|
|
182
|
+
/** The device-layer hosts to ask the device owner about (empty: no ask). */
|
|
108
183
|
ask: {
|
|
109
184
|
host: string;
|
|
110
185
|
port: number;
|
|
111
186
|
}[];
|
|
187
|
+
/** What the ask offers (present exactly when `ask` is not empty). */
|
|
188
|
+
offer?: NetworkAskOffer;
|
|
112
189
|
/** Notes written now, after the command output (one line per outcome). */
|
|
113
190
|
notes: string[];
|
|
114
191
|
/** `missing_grants` keys of an unattended run (`network:<host>`). */
|
|
@@ -124,22 +201,28 @@ export declare function blockedEventHosts(blocked: readonly NetworkBlockedHost[]
|
|
|
124
201
|
* an `address` host under the open network on a device that allows running outside the sandbox
|
|
125
202
|
* gets the escalation hint; an `org` host whose grant is unavailable names who adds it;
|
|
126
203
|
* `unknown`: nothing (the device's trailer explains);
|
|
127
|
-
* - a `device` host
|
|
128
|
-
*
|
|
129
|
-
* adds it, never an ask;
|
|
130
|
-
* - `device` layer
|
|
204
|
+
* - a `device` host that cannot be offered (`ctx.refusal`: beyond the org's or platform's
|
|
205
|
+
* allowlist ceiling, or on a device without per-operation hosts one its own list cannot take):
|
|
206
|
+
* a note naming who adds it, never an ask;
|
|
207
|
+
* - `device` layer with no device sandbox known (no `ctx.offer`): nothing (no ask);
|
|
208
|
+
* - a `device` host the device itself refused although its own list allows it and the operation
|
|
209
|
+
* carried that list (`ctx.deviceBlocks`): a note saying so, never asked;
|
|
210
|
+
* - a `device` host the device's settings already allow (`ctx.onList`: not yet applied to the
|
|
211
|
+
* instance): a note saying when it applies, never asked again;
|
|
131
212
|
* - approved by the scheduled task the run serves (`run.taskGranted`) yet refused: a note that
|
|
132
213
|
* the device ignores the task's grants (never asked, never a missing grant);
|
|
133
214
|
* - refused earlier in the run tree: the denied note; an unattended run in `fail` mode: its note
|
|
134
215
|
* and a missing grant;
|
|
135
|
-
* - the rest is asked
|
|
136
|
-
* {@link MAX_NETWORK_ASKS_PER_RUN} asks (a note
|
|
216
|
+
* - the rest is asked with `ctx.offer`'s offer (none: an unavailable note each), unless another
|
|
217
|
+
* ask of the run tree is pending or the run made {@link MAX_NETWORK_ASKS_PER_RUN} asks (a note
|
|
218
|
+
* each).
|
|
137
219
|
*/
|
|
138
220
|
export declare function planNetworkAsk(blocked: readonly NetworkBlockedHost[], run: NetworkRunState | null, ctx: NetworkPlanContext): NetworkPlan;
|
|
139
221
|
/**
|
|
140
222
|
* The note of a settled network ask (spec §6.6): one line per outcome. An approval allows
|
|
141
|
-
* `detail.grantedHosts` for the run
|
|
142
|
-
* left unchecked; `hours` is the ask's own
|
|
223
|
+
* `detail.grantedHosts` for the run (`once`) or added them to the device's own list (`always`,
|
|
224
|
+
* applying at `detail.appliesAt`) and declines the hosts left unchecked; `hours` is the ask's own
|
|
225
|
+
* wait (created to expiry). Null while it is pending.
|
|
143
226
|
*/
|
|
144
227
|
export declare function settledNetworkNotes(a: ApprovalRecord, hours: number): string[] | null;
|
|
145
228
|
/** `text` followed by `notes` after a blank line (unchanged without notes). */
|