@capybara-hq/kernel 0.1.0-rc.105 → 0.1.0-rc.106
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/dist/agents/agents.schemas.d.ts +9 -9
- package/dist/{schedules/schedules.controller.d.ts → automations/automations.controller.d.ts} +37 -32
- package/dist/{schedules/schedules.controller.js → automations/automations.controller.js} +68 -57
- package/dist/automations/automations.module.d.ts +16 -0
- package/dist/{schedules/schedules.module.js → automations/automations.module.js} +18 -15
- package/dist/{schedules/schedules.schemas.d.ts → automations/automations.schemas.d.ts} +151 -50
- package/dist/automations/automations.schemas.js +253 -0
- package/dist/{schedules/scheduled-tasks.service.d.ts → automations/automations.service.d.ts} +99 -52
- package/dist/{schedules/scheduled-tasks.service.js → automations/automations.service.js} +303 -134
- package/dist/{schedules → automations}/calendar.d.ts +8 -8
- package/dist/{schedules → automations}/calendar.js +2 -2
- package/dist/automations/effective-settings.d.ts +28 -0
- package/dist/automations/effective-settings.js +25 -0
- package/dist/automations/errors.d.ts +19 -0
- package/dist/automations/errors.js +19 -0
- package/dist/automations/events/coalesce.d.ts +28 -0
- package/dist/automations/events/coalesce.js +131 -0
- package/dist/automations/events/deadline.d.ts +10 -0
- package/dist/automations/events/deadline.js +24 -0
- package/dist/automations/events/dispatcher.d.ts +74 -0
- package/dist/automations/events/dispatcher.js +353 -0
- package/dist/automations/events/events.module.d.ts +7 -0
- package/dist/automations/events/events.module.js +26 -0
- package/dist/automations/events/guards.d.ts +32 -0
- package/dist/automations/events/guards.js +87 -0
- package/dist/automations/events/sweep.job.d.ts +49 -0
- package/dist/automations/events/sweep.job.js +202 -0
- package/dist/automations/events/token.d.ts +5 -0
- package/dist/automations/events/token.js +5 -0
- package/dist/automations/events/trigger-events.service.d.ts +47 -0
- package/dist/automations/events/trigger-events.service.js +254 -0
- package/dist/{schedules → automations}/fire.d.ts +57 -17
- package/dist/{schedules → automations}/fire.js +311 -79
- package/dist/{schedules → automations}/grant-rules.d.ts +1 -1
- package/dist/{schedules → automations}/grant-rules.js +5 -5
- package/dist/automations/job-ids.d.ts +113 -0
- package/dist/automations/job-ids.js +117 -0
- package/dist/{schedules → automations}/pause.d.ts +3 -3
- package/dist/{schedules → automations}/pause.js +3 -3
- package/dist/{schedules → automations}/run-tracker.d.ts +21 -10
- package/dist/{schedules → automations}/run-tracker.js +68 -56
- package/dist/{schedules → automations}/scan.job.d.ts +12 -8
- package/dist/{schedules → automations}/scan.job.js +39 -23
- package/dist/{schedules → automations}/schedule-math.d.ts +19 -12
- package/dist/{schedules → automations}/schedule-math.js +17 -7
- package/dist/{schedules → automations}/store.d.ts +57 -27
- package/dist/{schedules → automations}/store.js +102 -52
- package/dist/automations/store.module.d.ts +6 -0
- package/dist/{schedules → automations}/store.module.js +9 -9
- package/dist/automations/types.d.ts +178 -0
- package/dist/{schedules → automations}/unattended.d.ts +22 -11
- package/dist/{schedules → automations}/unattended.js +53 -30
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/channels.module.js +3 -3
- package/dist/channels/outbound.d.ts +5 -5
- package/dist/channels/outbound.js +17 -17
- package/dist/channels/threads.d.ts +1 -1
- package/dist/channels/threads.js +1 -1
- package/dist/config/schema.d.ts +5 -1
- package/dist/config/schema.js +44 -6
- package/dist/conversations/approval-profile.d.ts +2 -2
- package/dist/conversations/approval-profile.js +3 -3
- package/dist/conversations/conversations.controller.d.ts +7 -1
- package/dist/conversations/conversations.controller.js +26 -10
- package/dist/conversations/conversations.service.d.ts +101 -25
- package/dist/conversations/conversations.service.js +132 -32
- package/dist/conversations/events.d.ts +46 -0
- package/dist/conversations/events.js +54 -3
- package/dist/conversations/message-context.d.ts +2 -2
- package/dist/conversations/message-context.js +1 -1
- package/dist/conversations/permission-profile-store.d.ts +2 -1
- package/dist/conversations/permission-profiles.controller.d.ts +3 -0
- package/dist/conversations/permission-profiles.service.js +1 -1
- package/dist/conversations/prompt-suggestion-request.d.ts +1 -1
- package/dist/conversations/prompt-suggestion-request.js +2 -1
- package/dist/conversations/queue.d.ts +7 -4
- package/dist/conversations/queue.js +6 -2
- package/dist/conversations/queue.service.d.ts +5 -5
- package/dist/conversations/queue.service.js +20 -14
- package/dist/ctx/create-ctx.d.ts +20 -1
- package/dist/ctx/create-ctx.js +59 -2
- package/dist/db/kernel-schema.d.ts +104 -25
- package/dist/devices/device-project-files.service.d.ts +88 -0
- package/dist/devices/device-project-files.service.js +249 -0
- package/dist/devices/device-projects.service.d.ts +40 -0
- package/dist/devices/device-projects.service.js +16 -13
- package/dist/devices/devices.controller.d.ts +9 -3
- package/dist/devices/devices.controller.js +27 -5
- package/dist/devices/devices.module.js +9 -1
- package/dist/devices/devices.schemas.js +6 -1
- package/dist/devices/dto.d.ts +15 -0
- package/dist/devices/dto.js +11 -0
- package/dist/devices/project-paths.d.ts +29 -0
- package/dist/devices/project-paths.js +66 -0
- package/dist/devices/project-rules.d.ts +5 -1
- package/dist/devices/project-rules.js +5 -1
- package/dist/errors.d.ts +34 -13
- package/dist/errors.js +34 -13
- package/dist/evals/reconstruct.d.ts +10 -1
- package/dist/evals/reconstruct.js +7 -0
- package/dist/extensions/host.d.ts +6 -1
- package/dist/extensions/host.js +10 -0
- package/dist/extensions/permission-set.d.ts +17 -1
- package/dist/extensions/permission-set.js +13 -1
- package/dist/extensions/permission-view.d.ts +1 -1
- package/dist/extensions/permission-view.js +4 -1
- package/dist/git/gateway.js +2 -2
- package/dist/http/api.module.js +5 -5
- package/dist/http/request-signal.d.ts +8 -0
- package/dist/http/request-signal.js +14 -0
- package/dist/inbox/inbox.module.js +2 -2
- package/dist/inbox/inbox.service.d.ts +8 -8
- package/dist/inbox/inbox.service.js +7 -7
- package/dist/infra/config/kernel-config.service.js +10 -5
- package/dist/infra/outbox/registry.d.ts +29 -2
- package/dist/infra/outbox/registry.js +30 -7
- package/dist/kernel.module.js +3 -0
- package/dist/orgs/roles.d.ts +1 -1
- package/dist/orgs/roles.js +3 -3
- package/dist/orgs/settings.controller.d.ts +1 -1
- package/dist/orgs/settings.service.d.ts +27 -11
- package/dist/orgs/settings.service.js +42 -24
- package/dist/platform/operation.js +2 -2
- package/dist/platform/ops/{schedules.ops.d.ts → automations.ops.d.ts} +4 -4
- package/dist/platform/ops/automations.ops.js +560 -0
- package/dist/platform/ops/devices.ops.d.ts +3 -1
- package/dist/platform/ops/devices.ops.js +77 -3
- package/dist/platform/ops/inbox.ops.js +4 -4
- package/dist/platform/ops/orgs.ops.js +1 -1
- package/dist/platform/ops/platform.ops.js +4 -4
- package/dist/platform/platform-ops.module.d.ts +2 -2
- package/dist/platform/platform-ops.module.js +5 -5
- package/dist/platform/route-schemas.js +3 -3
- package/dist/push/jobs.d.ts +3 -3
- package/dist/push/jobs.js +2 -2
- package/dist/push/preferences.service.js +1 -1
- package/dist/push/push-owed.d.ts +3 -3
- package/dist/push/push-owed.js +6 -6
- package/dist/push/push.schemas.d.ts +4 -4
- package/dist/push/push.schemas.js +3 -3
- package/dist/push/recipients.d.ts +4 -4
- package/dist/push/recipients.js +23 -23
- package/dist/push/texts.d.ts +3 -3
- package/dist/push/texts.js +2 -2
- package/dist/push/triggers.d.ts +1 -1
- package/dist/roles/worker.module.js +3 -3
- package/dist/runtime/context/build.d.ts +6 -0
- package/dist/runtime/context/build.js +14 -3
- package/dist/runtime/context/compaction.js +15 -5
- package/dist/runtime/context/run-context.d.ts +38 -0
- package/dist/runtime/context/run-context.js +54 -0
- package/dist/runtime/maintenance.d.ts +8 -4
- package/dist/runtime/maintenance.js +37 -16
- package/dist/runtime/run-finish.d.ts +4 -4
- package/dist/runtime/run-finish.js +3 -3
- package/dist/runtime/run-queue.js +12 -7
- package/dist/runtime/run-worker.js +7 -1
- package/dist/runtime/runtime.module.js +3 -3
- package/dist/runtime/subagents/dispatch.js +11 -3
- package/dist/sandbox/browse-roots.d.ts +8 -0
- package/dist/sandbox/browse-roots.js +22 -0
- package/dist/sandbox/network-grants.d.ts +4 -4
- package/dist/sandbox/network-grants.js +7 -7
- package/dist/sandbox/operation-authority.d.ts +10 -3
- package/dist/sandbox/operation-authority.js +20 -10
- package/dist/sandbox/operation-intents.d.ts +3 -1
- package/dist/sandbox/operation-intents.js +11 -4
- package/dist/sandbox/permission-call-grants.js +2 -2
- package/dist/sandbox/permission-facts.js +1 -1
- package/dist/sandbox/review/classifier.d.ts +2 -2
- package/dist/sandbox/review/classifier.js +22 -11
- package/dist/sandbox/review/permission-candidate.d.ts +1 -1
- package/dist/sandbox/review/permission-candidate.js +1 -1
- package/dist/sandbox/sandbox.service.d.ts +15 -5
- package/dist/sandbox/sandbox.service.js +14 -8
- package/dist/storage/purge.d.ts +1 -1
- package/dist/storage/purge.js +2 -2
- package/dist/tools/approvals.service.d.ts +6 -6
- package/dist/tools/approvals.service.js +19 -19
- package/dist/tools/builtin-names.d.ts +12 -12
- package/dist/tools/builtin-names.js +29 -29
- package/dist/tools/builtins/{schedules.d.ts → automations.d.ts} +35 -33
- package/dist/tools/builtins/{schedules.js → automations.js} +236 -105
- package/dist/tools/builtins/builtin-tools.d.ts +8 -8
- package/dist/tools/builtins/builtin-tools.js +16 -16
- package/dist/tools/call-scope.d.ts +1 -1
- package/dist/tools/git-asks.js +1 -1
- package/dist/tools/git-push-policy.d.ts +3 -3
- package/dist/tools/git-push-policy.js +6 -6
- package/dist/tools/network-asks.d.ts +3 -3
- package/dist/tools/network-asks.js +3 -3
- package/dist/tools/pipeline.d.ts +4 -4
- package/dist/tools/pipeline.js +2 -2
- package/dist/tools/policy.d.ts +3 -3
- package/dist/tools/policy.js +3 -3
- package/dist/tools/tools.module.js +9 -9
- package/package.json +3 -3
- package/src/migrations/0188_automations_rename.sql +309 -0
- package/src/migrations/0189_event_automations.sql +136 -0
- package/dist/platform/ops/schedules.ops.js +0 -509
- package/dist/schedules/effective-settings.d.ts +0 -22
- package/dist/schedules/effective-settings.js +0 -18
- package/dist/schedules/errors.d.ts +0 -8
- package/dist/schedules/errors.js +0 -8
- package/dist/schedules/job-ids.d.ts +0 -81
- package/dist/schedules/job-ids.js +0 -95
- package/dist/schedules/schedules.module.d.ts +0 -16
- package/dist/schedules/schedules.schemas.js +0 -213
- package/dist/schedules/store.module.d.ts +0 -6
- package/dist/schedules/types.d.ts +0 -110
- /package/dist/{schedules → automations}/types.js +0 -0
|
@@ -282,7 +282,13 @@ export async function commitDispatchIn(d, a, plan, child) {
|
|
|
282
282
|
.executeTakeFirst();
|
|
283
283
|
const parent = await t
|
|
284
284
|
.selectFrom("runs")
|
|
285
|
-
.select([
|
|
285
|
+
.select([
|
|
286
|
+
"status",
|
|
287
|
+
"subagent_tokens_used",
|
|
288
|
+
"budget_run_id",
|
|
289
|
+
"automation_run_id",
|
|
290
|
+
"trigger_event_id",
|
|
291
|
+
])
|
|
286
292
|
.where("id", "=", ctx.runId)
|
|
287
293
|
.forUpdate()
|
|
288
294
|
.executeTakeFirst();
|
|
@@ -377,8 +383,10 @@ export async function commitDispatchIn(d, a, plan, child) {
|
|
|
377
383
|
trigger_account_id: ctx.accountId,
|
|
378
384
|
trigger_seq: task.seq,
|
|
379
385
|
budget_run_id: budgetRunId,
|
|
380
|
-
// an unattended parent's sub-agents are unattended too (scheduled tasks spec §4)
|
|
381
|
-
|
|
386
|
+
// an unattended parent's sub-agents are unattended too (scheduled tasks spec §4), and an
|
|
387
|
+
// event a sub-agent causes counts its chain from the parent's event (collaboration §4.7)
|
|
388
|
+
automation_run_id: parent.automation_run_id,
|
|
389
|
+
trigger_event_id: parent.trigger_event_id,
|
|
382
390
|
})
|
|
383
391
|
.execute();
|
|
384
392
|
await t
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The read roots of an owner browse narrowed to `narrow` (composer menus §5: a project's files are
|
|
3
|
+
* browsed in a scope rooted at the project path): each narrowing root that lies at or below one of
|
|
4
|
+
* the owner's ceiling roots, never wider than the ceiling. A narrowing root outside every ceiling
|
|
5
|
+
* root, or one that is not absolute and normalized, drops out. The result is deduplicated and may
|
|
6
|
+
* be empty (the caller refuses the browse then).
|
|
7
|
+
*/
|
|
8
|
+
export declare function narrowReadRoots(ceiling: readonly string[], narrow: readonly string[]): string[];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { posix } from "node:path";
|
|
2
|
+
/** `path` lies at or below `root` (both absolute and normalized). */
|
|
3
|
+
const within = (path, root) => path === root || root === "/" || path.startsWith(`${root}/`);
|
|
4
|
+
/** An absolute, normalized posix path without a trailing `/` (except `/` itself). */
|
|
5
|
+
const plainAbsolute = (p) => posix.isAbsolute(p) && posix.normalize(p) === p && (p === "/" || !p.endsWith("/"));
|
|
6
|
+
/**
|
|
7
|
+
* The read roots of an owner browse narrowed to `narrow` (composer menus §5: a project's files are
|
|
8
|
+
* browsed in a scope rooted at the project path): each narrowing root that lies at or below one of
|
|
9
|
+
* the owner's ceiling roots, never wider than the ceiling. A narrowing root outside every ceiling
|
|
10
|
+
* root, or one that is not absolute and normalized, drops out. The result is deduplicated and may
|
|
11
|
+
* be empty (the caller refuses the browse then).
|
|
12
|
+
*/
|
|
13
|
+
export function narrowReadRoots(ceiling, narrow) {
|
|
14
|
+
const out = new Set();
|
|
15
|
+
for (const n of narrow) {
|
|
16
|
+
if (!plainAbsolute(n))
|
|
17
|
+
continue;
|
|
18
|
+
if (ceiling.some((c) => within(n, c)))
|
|
19
|
+
out.add(n);
|
|
20
|
+
}
|
|
21
|
+
return [...out];
|
|
22
|
+
}
|
|
@@ -14,7 +14,7 @@ export interface NetworkRunState {
|
|
|
14
14
|
/** A network ask of the run tree is still pending (at most one at a time). */
|
|
15
15
|
pending: boolean;
|
|
16
16
|
/**
|
|
17
|
-
* Hosts the
|
|
17
|
+
* Hosts the automation the run serves approves on this device (spec §8.1; unattended runs
|
|
18
18
|
* only, read only with a `deviceId`): never asked about nor recorded as missing. Absent: none.
|
|
19
19
|
*/
|
|
20
20
|
taskGranted?: Set<string>;
|
|
@@ -26,7 +26,7 @@ export interface NetworkRunState {
|
|
|
26
26
|
* tree is the runs of one budget window (`runs.budget_run_id` lineage): a sub-agent's run sees the
|
|
27
27
|
* root's grants, another run tree never does. The hosts a decision allowed are its
|
|
28
28
|
* `detail.grantedHosts`; a decision without them grants nothing. In an unattended run of a
|
|
29
|
-
*
|
|
29
|
+
* automation, the task's `network:<host>` grants (spec §8.1) join them.
|
|
30
30
|
*/
|
|
31
31
|
export declare class NetworkGrants {
|
|
32
32
|
private readonly db;
|
|
@@ -35,7 +35,7 @@ export declare class NetworkGrants {
|
|
|
35
35
|
* Hosts allowed for this exec on `deviceId`: the run tree's once-approved network asks in
|
|
36
36
|
* `orgId` about that device, while the tree's root run has not ended (a grant ends with its run;
|
|
37
37
|
* a later run of the same budget window does not inherit it), with the root run as their source
|
|
38
|
-
* and the latest decider as its account; and in an unattended run of
|
|
38
|
+
* and the latest decider as its account; and in an unattended run of an automation, the
|
|
39
39
|
* task's network grants (spec §8.1) when the device is its creator's, with the task as their
|
|
40
40
|
* source and the creator as its account. Both together are one grant: the hosts of both, the
|
|
41
41
|
* task as the source. Undefined when none. The device applies them only when its owner allows
|
|
@@ -55,7 +55,7 @@ export declare class NetworkGrants {
|
|
|
55
55
|
/** The run tree's once-approved hosts as exec grants (source: the root run). */
|
|
56
56
|
private runGrants;
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
58
|
+
* An automation's network grants for an unattended run (spec §8.1): the task's
|
|
59
59
|
* `network:<host>` grants when the run serves a task run that is no trial run and no person
|
|
60
60
|
* joined (`taskGrantsRunOf`, inherited by its sub-agents), the task is of `orgId` (when given)
|
|
61
61
|
* and `deviceId` is a live device of the task's org owned by the task's creator (a creator
|
|
@@ -10,13 +10,13 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { validateAllowHost } from "@capybara-hq/plugin-sdk";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
|
+
import { taskGrantsRunOf } from "../automations/unattended.js";
|
|
13
14
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
14
15
|
import { budgetRunOf } from "../runtime/subagents/limits.js";
|
|
15
|
-
import { taskGrantsRunOf } from "../schedules/unattended.js";
|
|
16
16
|
import { coversHost } from "./modes.js";
|
|
17
17
|
/** The most hosts one exec's grants carry (the device protocol's limit). */
|
|
18
18
|
export const MAX_GRANT_HOSTS = 100;
|
|
19
|
-
/** The key prefix of
|
|
19
|
+
/** The key prefix of an automation's network grant (`automations/grant-rules.ts`). */
|
|
20
20
|
const NETWORK_KEY_PREFIX = "network:";
|
|
21
21
|
/** The statuses of a run that has not ended: its run grants still apply. */
|
|
22
22
|
const LIVE_RUN = ["queued", "running", "waiting"];
|
|
@@ -54,7 +54,7 @@ function askedOf(detail) {
|
|
|
54
54
|
* tree is the runs of one budget window (`runs.budget_run_id` lineage): a sub-agent's run sees the
|
|
55
55
|
* root's grants, another run tree never does. The hosts a decision allowed are its
|
|
56
56
|
* `detail.grantedHosts`; a decision without them grants nothing. In an unattended run of a
|
|
57
|
-
*
|
|
57
|
+
* automation, the task's `network:<host>` grants (spec §8.1) join them.
|
|
58
58
|
*/
|
|
59
59
|
let NetworkGrants = class NetworkGrants {
|
|
60
60
|
db;
|
|
@@ -65,7 +65,7 @@ let NetworkGrants = class NetworkGrants {
|
|
|
65
65
|
* Hosts allowed for this exec on `deviceId`: the run tree's once-approved network asks in
|
|
66
66
|
* `orgId` about that device, while the tree's root run has not ended (a grant ends with its run;
|
|
67
67
|
* a later run of the same budget window does not inherit it), with the root run as their source
|
|
68
|
-
* and the latest decider as its account; and in an unattended run of
|
|
68
|
+
* and the latest decider as its account; and in an unattended run of an automation, the
|
|
69
69
|
* task's network grants (spec §8.1) when the device is its creator's, with the task as their
|
|
70
70
|
* source and the creator as its account. Both together are one grant: the hosts of both, the
|
|
71
71
|
* task as the source. Undefined when none. The device applies them only when its owner allows
|
|
@@ -165,7 +165,7 @@ let NetworkGrants = class NetworkGrants {
|
|
|
165
165
|
return { hosts, source: { kind: "run", id: root, accountId: latest.decided_by } };
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
|
-
*
|
|
168
|
+
* An automation's network grants for an unattended run (spec §8.1): the task's
|
|
169
169
|
* `network:<host>` grants when the run serves a task run that is no trial run and no person
|
|
170
170
|
* joined (`taskGrantsRunOf`, inherited by its sub-agents), the task is of `orgId` (when given)
|
|
171
171
|
* and `deviceId` is a live device of the task's org owned by the task's creator (a creator
|
|
@@ -187,9 +187,9 @@ let NetworkGrants = class NetworkGrants {
|
|
|
187
187
|
if (device === undefined)
|
|
188
188
|
return undefined;
|
|
189
189
|
const rows = await this.db
|
|
190
|
-
.selectFrom("
|
|
190
|
+
.selectFrom("automation_grants")
|
|
191
191
|
.select("tool_key")
|
|
192
|
-
.where("
|
|
192
|
+
.where("automation_id", "=", task.taskId)
|
|
193
193
|
.where("tool_key", "like", `${NETWORK_KEY_PREFIX}%`)
|
|
194
194
|
.orderBy("tool_key")
|
|
195
195
|
.execute();
|
|
@@ -68,12 +68,19 @@ export declare class SandboxOperationAuthority {
|
|
|
68
68
|
private readonly locks;
|
|
69
69
|
private readonly epochs;
|
|
70
70
|
constructor(callGrants: PermissionCallGrants, publication: PermissionConfigPublication, db: KernelDb, txHost: TransactionHost, profiles: PermissionProfileStore, facts: PermissionFacts, grants: NetworkGrants, locks: PermissionAuthorityLock, epochs: PermissionAuthorityEpochStore);
|
|
71
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* Owner project browsing has no conversation, profile, or fabricated root identity. `narrow`
|
|
73
|
+
* (absolute paths, e.g. a project root) replaces the scope's read roots with those of its paths
|
|
74
|
+
* that lie inside the owner's ceiling ({@link narrowReadRoots}), never wider; when none does the
|
|
75
|
+
* browse is refused (`device.project_outside_mode`).
|
|
76
|
+
*/
|
|
72
77
|
resolveBrowse(ctx: {
|
|
73
78
|
orgId: string;
|
|
74
79
|
deviceId: string;
|
|
75
80
|
accountId: string;
|
|
76
|
-
}, signal: AbortSignal
|
|
81
|
+
}, signal: AbortSignal, narrow?: {
|
|
82
|
+
readRoots: readonly string[];
|
|
83
|
+
}): Promise<SandboxBrowseScope>;
|
|
77
84
|
/**
|
|
78
85
|
* The one actor liveness predicate of owner browsing, the recorded permission context and the
|
|
79
86
|
* managed device context writer: an active account that is still a member of a live org.
|
|
@@ -115,7 +122,7 @@ export declare class SandboxOperationAuthority {
|
|
|
115
122
|
private snapshot;
|
|
116
123
|
/**
|
|
117
124
|
* The actual run of an operation or context read: still this conversation's, triggered by this
|
|
118
|
-
* actor and not ended; true when it serves
|
|
125
|
+
* actor and not ended; true when it serves an automation run (an unattended child or wake
|
|
119
126
|
* included). Shared by admission and the recorded permission context.
|
|
120
127
|
*/
|
|
121
128
|
private runScheduledLocked;
|
|
@@ -18,6 +18,7 @@ import { ApiError } from "../errors.js";
|
|
|
18
18
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
19
19
|
import { TransactionHost, withTransactionFencePrelude, } from "../infra/database/transaction-host.js";
|
|
20
20
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
21
|
+
import { narrowReadRoots } from "./browse-roots.js";
|
|
21
22
|
import { hostGrantable } from "./device-sandbox.js";
|
|
22
23
|
import { KernelReadUnsupported, kernelReadCovering, kernelReadRoute, } from "./kernel-read.js";
|
|
23
24
|
import { coversHost } from "./modes.js";
|
|
@@ -144,8 +145,13 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
144
145
|
this.locks = locks;
|
|
145
146
|
this.epochs = epochs;
|
|
146
147
|
}
|
|
147
|
-
/**
|
|
148
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Owner project browsing has no conversation, profile, or fabricated root identity. `narrow`
|
|
150
|
+
* (absolute paths, e.g. a project root) replaces the scope's read roots with those of its paths
|
|
151
|
+
* that lie inside the owner's ceiling ({@link narrowReadRoots}), never wider; when none does the
|
|
152
|
+
* browse is refused (`device.project_outside_mode`).
|
|
153
|
+
*/
|
|
154
|
+
async resolveBrowse(ctx, signal, narrow) {
|
|
149
155
|
signal.throwIfAborted();
|
|
150
156
|
await this.locks.acquire({ orgId: ctx.orgId, deviceId: ctx.deviceId }, { kind: "admit" });
|
|
151
157
|
await this.publication.assertCurrent();
|
|
@@ -156,6 +162,12 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
156
162
|
const scope = await this.facts.projectScope(ctx.orgId, ctx.accountId, ctx.deviceId);
|
|
157
163
|
if (!scope.supported)
|
|
158
164
|
throw new ApiError("device.projects_unsupported", "Current owner and organization ceilings do not permit browsing");
|
|
165
|
+
// the base the picker starts from: the provider's reported home, else the workspace (what
|
|
166
|
+
// the device answers within it is the provider's rule)
|
|
167
|
+
const ceiling = [scope.home ?? scope.workspace];
|
|
168
|
+
const readRoots = narrow === undefined ? ceiling : narrowReadRoots(ceiling, narrow.readRoots);
|
|
169
|
+
if (readRoots.length === 0)
|
|
170
|
+
throw new ApiError("device.project_outside_mode", "The project lies outside what the device lets its owner browse; remove it and add it again from a directory under the device's base");
|
|
159
171
|
const operationId = randomUUID();
|
|
160
172
|
const vector = await this.epochs.readLocked({ orgId: ctx.orgId, deviceId: ctx.deviceId });
|
|
161
173
|
return parseSandboxBrowseScope({
|
|
@@ -164,9 +176,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
164
176
|
accountId: ctx.accountId,
|
|
165
177
|
admitBeforeMs: Date.now() + 30000,
|
|
166
178
|
ceilingRevision: permissionScopeHash(vector),
|
|
167
|
-
|
|
168
|
-
// the device answers within it is the provider's rule)
|
|
169
|
-
readRoots: [scope.home ?? scope.workspace],
|
|
179
|
+
readRoots,
|
|
170
180
|
tag: operationId,
|
|
171
181
|
});
|
|
172
182
|
}
|
|
@@ -461,7 +471,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
461
471
|
if (view.deviceId !== ctx.deviceId)
|
|
462
472
|
throw new ApiError("device.not_found", "The conversation is not bound to this device");
|
|
463
473
|
await this.facts.preview(ctx.orgId, ctx.actor.accountId, ctx.deviceId, root.project_name ?? undefined);
|
|
464
|
-
let unattended = root.
|
|
474
|
+
let unattended = root.automation_id !== null;
|
|
465
475
|
if (ctx.actor.runId)
|
|
466
476
|
unattended ||= await this.runScheduledLocked(ctx.holderConversationId, ctx.actor.accountId, ctx.actor.runId);
|
|
467
477
|
const base = await this.baseScopeLocked({
|
|
@@ -557,13 +567,13 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
557
567
|
}
|
|
558
568
|
/**
|
|
559
569
|
* The actual run of an operation or context read: still this conversation's, triggered by this
|
|
560
|
-
* actor and not ended; true when it serves
|
|
570
|
+
* actor and not ended; true when it serves an automation run (an unattended child or wake
|
|
561
571
|
* included). Shared by admission and the recorded permission context.
|
|
562
572
|
*/
|
|
563
573
|
async runScheduledLocked(conversationId, accountId, runId) {
|
|
564
574
|
const run = await this.db
|
|
565
575
|
.selectFrom("runs")
|
|
566
|
-
.select(["conversation_id", "trigger_account_id", "
|
|
576
|
+
.select(["conversation_id", "trigger_account_id", "automation_run_id", "status"])
|
|
567
577
|
.where("id", "=", runId)
|
|
568
578
|
.executeTakeFirst();
|
|
569
579
|
if (!run ||
|
|
@@ -571,7 +581,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
571
581
|
run.trigger_account_id !== accountId ||
|
|
572
582
|
!["running", "queued", "waiting"].includes(run.status))
|
|
573
583
|
throw new ApiError("forbidden", "The operation run is no longer authorized");
|
|
574
|
-
return run.
|
|
584
|
+
return run.automation_run_id !== null;
|
|
575
585
|
}
|
|
576
586
|
/**
|
|
577
587
|
* The call-independent base authority of a device for one root (B1): the device's policy and
|
|
@@ -711,7 +721,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
711
721
|
throw new ApiError("forbidden", "This run's actor is no longer authorized");
|
|
712
722
|
await this.publication.assertCurrent();
|
|
713
723
|
const scheduled = (await this.runScheduledLocked(input.conversationId, input.accountId, input.runId)) ||
|
|
714
|
-
root.
|
|
724
|
+
root.automation_id !== null;
|
|
715
725
|
const header = {
|
|
716
726
|
version: 2,
|
|
717
727
|
// only a supported context carries the device sandbox block (below)
|
|
@@ -102,7 +102,9 @@ export declare class SandboxOperationIntents {
|
|
|
102
102
|
orgId: string;
|
|
103
103
|
deviceId: string;
|
|
104
104
|
accountId: string;
|
|
105
|
-
}, instance: OperationInstance, method: "stat" | "list" | "scan", input: unknown, signal: AbortSignal
|
|
105
|
+
}, instance: OperationInstance, method: "stat" | "list" | "scan", input: unknown, signal: AbortSignal, narrow?: {
|
|
106
|
+
readRoots: readonly string[];
|
|
107
|
+
}): Promise<OperationIntent>;
|
|
106
108
|
/**
|
|
107
109
|
* The run of a kernel read (permission activation L2): the run must still be the claim's
|
|
108
110
|
* execution, triggered by the actor and in the state its purpose reads in, checked in PG under
|
|
@@ -8,7 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { createHash, randomUUID } from "node:crypto";
|
|
11
|
-
import { parseSandboxExecutionRef, parseSandboxOperationScope, SandboxOperationOutcomeUnknownError, SandboxPermissionUnsupportedError, SandboxScopeDeniedError, ToolError, } from "@capybara-hq/plugin-sdk";
|
|
11
|
+
import { parseSandboxBrowseScope, parseSandboxExecutionRef, parseSandboxOperationScope, SandboxOperationOutcomeUnknownError, SandboxPermissionUnsupportedError, SandboxScopeDeniedError, ToolError, } from "@capybara-hq/plugin-sdk";
|
|
12
12
|
import { Inject, Injectable } from "@nestjs/common";
|
|
13
13
|
import { sql } from "kysely";
|
|
14
14
|
import { STOP_CLAIM_TTL_MS } from "../background/store.js";
|
|
@@ -265,8 +265,8 @@ let SandboxOperationIntents = class SandboxOperationIntents {
|
|
|
265
265
|
return row;
|
|
266
266
|
}
|
|
267
267
|
/** Owner-native reads have their own admission, without a manufactured conversation or run. */
|
|
268
|
-
async admitBrowse(ctx, instance, method, input, signal) {
|
|
269
|
-
const scope = await this.authority.resolveBrowse(ctx, signal);
|
|
268
|
+
async admitBrowse(ctx, instance, method, input, signal, narrow) {
|
|
269
|
+
const scope = await this.authority.resolveBrowse(ctx, signal, narrow);
|
|
270
270
|
const described = describeOperationPayload(input);
|
|
271
271
|
const payload = payloadReference("input", described);
|
|
272
272
|
const vector = await this.epochs.readLocked({ orgId: ctx.orgId, deviceId: ctx.deviceId });
|
|
@@ -466,7 +466,14 @@ let SandboxOperationIntents = class SandboxOperationIntents {
|
|
|
466
466
|
denied("The browse admission does not match this owner");
|
|
467
467
|
if (row.state !== "admitted" || row.deadline.getTime() <= Date.now())
|
|
468
468
|
denied("Browse admission was revoked or expired");
|
|
469
|
-
|
|
469
|
+
// checked again with the read roots it was admitted with (a project's root narrows them), so
|
|
470
|
+
// a ceiling that moved since then refuses the browse instead of widening or keeping it
|
|
471
|
+
const admitted = parseSandboxBrowseScope(row.scope);
|
|
472
|
+
const fresh = await this.authority.resolveBrowse(ctx, new AbortController().signal, {
|
|
473
|
+
readRoots: admitted.readRoots,
|
|
474
|
+
});
|
|
475
|
+
if (JSON.stringify(fresh.readRoots) !== JSON.stringify(admitted.readRoots))
|
|
476
|
+
denied("Authority changed before the browse was dispatched");
|
|
470
477
|
await this.db
|
|
471
478
|
.updateTable("sandbox_operation_intents")
|
|
472
479
|
.set({ state: "dispatching", updated_at: new Date() })
|
|
@@ -83,11 +83,11 @@ let PermissionCallGrants = class PermissionCallGrants {
|
|
|
83
83
|
});
|
|
84
84
|
if (root.id !== binding.rootConversationId ||
|
|
85
85
|
root.device_id !== binding.deviceId ||
|
|
86
|
-
root.
|
|
86
|
+
root.automation_id ||
|
|
87
87
|
!run ||
|
|
88
88
|
run.conversation_id !== binding.conversationId ||
|
|
89
89
|
run.trigger_account_id !== binding.accountId ||
|
|
90
|
-
run.
|
|
90
|
+
run.automation_run_id ||
|
|
91
91
|
!["running", "waiting", "queued"].includes(run.status) ||
|
|
92
92
|
device?.owner_account_id !== binding.accountId ||
|
|
93
93
|
view.availability.state !== "supported" ||
|
|
@@ -398,7 +398,7 @@ let PermissionFacts = class PermissionFacts {
|
|
|
398
398
|
// a home reported after the project was added can put it above the home: the working root
|
|
399
399
|
// would fall back for it, so it is not bound (the add rule, project root §4.3)
|
|
400
400
|
if (aboveHome(row.path, scope.home))
|
|
401
|
-
throw tooBroad(row.
|
|
401
|
+
throw tooBroad(row.name);
|
|
402
402
|
return { name: row.name, path: row.path };
|
|
403
403
|
}
|
|
404
404
|
async projectMatches(deviceId, name, path) {
|
|
@@ -124,8 +124,8 @@ export declare function fitReviewText(build: (text: string, personMessages: stri
|
|
|
124
124
|
/** How many of the root conversation's latest person messages are read before bounding the text. */
|
|
125
125
|
export declare const PERSON_MESSAGES_READ = 20;
|
|
126
126
|
/**
|
|
127
|
-
* The bounded text of the root conversation's last person messages:
|
|
128
|
-
*
|
|
127
|
+
* The bounded text of the root conversation's last person messages: each `user_message`'s own
|
|
128
|
+
* words ({@link textOfUserMessage}), never an assistant message or a tool result, newest {@link PERSON_MESSAGES_READ} read and
|
|
129
129
|
* bounded to `budget` estimated tokens (`sandbox.review.messageTokens`). The command review and the
|
|
130
130
|
* tool review read the same messages.
|
|
131
131
|
*/
|
|
@@ -261,24 +261,35 @@ export function fitReviewText(build, parts, system, limits, marker) {
|
|
|
261
261
|
* ---------------------------------------------------------------------------------------------- */
|
|
262
262
|
/** How many of the root conversation's latest person messages are read before bounding the text. */
|
|
263
263
|
export const PERSON_MESSAGES_READ = 20;
|
|
264
|
-
/**
|
|
264
|
+
/**
|
|
265
|
+
* The person's own words of a `user_message` payload: `content[0]` when it is a text block (the
|
|
266
|
+
* typed text, or the rendered skill of an invocation) and the kernel-written lines naming the
|
|
267
|
+
* referenced project files (`payload.projectFiles`, blocks `1 + attachments.length + i`: the
|
|
268
|
+
* person's intent, worded by the kernel). The `@` resources' bodies (`payload.attachments`,
|
|
269
|
+
* blocks `1 .. attachments.length`) are content read from a connector, not the person's
|
|
270
|
+
* instructions, so they are skipped, like images, documents and uploaded files.
|
|
271
|
+
*/
|
|
265
272
|
function textOfUserMessage(payload) {
|
|
266
|
-
const
|
|
273
|
+
const p = payload;
|
|
274
|
+
const content = p?.content;
|
|
267
275
|
if (!Array.isArray(content))
|
|
268
276
|
return "";
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
277
|
+
const textAt = (i) => {
|
|
278
|
+
const b = content[i];
|
|
279
|
+
return b !== null && typeof b === "object" && b.type === "text" && typeof b.text === "string"
|
|
280
|
+
? [b.text]
|
|
281
|
+
: [];
|
|
282
|
+
};
|
|
283
|
+
const resources = Array.isArray(p?.attachments) ? p.attachments.length : 0;
|
|
284
|
+
const projectFiles = Array.isArray(p?.projectFiles) ? p.projectFiles.length : 0;
|
|
285
|
+
const first = 1 + resources;
|
|
286
|
+
return [...textAt(0), ...Array.from({ length: projectFiles }, (_, i) => textAt(first + i)).flat()]
|
|
276
287
|
.join("\n")
|
|
277
288
|
.trim();
|
|
278
289
|
}
|
|
279
290
|
/**
|
|
280
|
-
* The bounded text of the root conversation's last person messages:
|
|
281
|
-
*
|
|
291
|
+
* The bounded text of the root conversation's last person messages: each `user_message`'s own
|
|
292
|
+
* words ({@link textOfUserMessage}), never an assistant message or a tool result, newest {@link PERSON_MESSAGES_READ} read and
|
|
282
293
|
* bounded to `budget` estimated tokens (`sandbox.review.messageTokens`). The command review and the
|
|
283
294
|
* tool review read the same messages.
|
|
284
295
|
*/
|
|
@@ -34,7 +34,7 @@ export declare const isEscalatedCall: (toolKey: string, input: unknown) => boole
|
|
|
34
34
|
/** An escalated call without a usable justification: refused before any review. */
|
|
35
35
|
export declare const ESCALATION_JUSTIFICATION_MISSING_TEXT = "This Bash call asked to run outside the sandbox (sandbox: \"escalated\") without a justification, so it did not run. Retry with justification: one sentence saying why this command must run outside the sandbox, or call Bash without sandbox to run it in the sandbox.";
|
|
36
36
|
/** Why an escalation cannot be reviewed: an unattended run (no one can approve it). */
|
|
37
|
-
export declare const ESCALATION_UNATTENDED_WHY = "this is an unattended run (
|
|
37
|
+
export declare const ESCALATION_UNATTENDED_WHY = "this is an unattended run (an automation) where no one can approve running outside the sandbox";
|
|
38
38
|
/**
|
|
39
39
|
* Why an escalation cannot be reviewed because the device's provider does not allow running
|
|
40
40
|
* outside its sandbox now, with the provider's own description of the device and how to change it
|
|
@@ -78,7 +78,7 @@ export const isEscalatedCall = (toolKey, input) => toolKey === "Bash" &&
|
|
|
78
78
|
/** An escalated call without a usable justification: refused before any review. */
|
|
79
79
|
export const ESCALATION_JUSTIFICATION_MISSING_TEXT = 'This Bash call asked to run outside the sandbox (sandbox: "escalated") without a justification, so it did not run. Retry with justification: one sentence saying why this command must run outside the sandbox, or call Bash without sandbox to run it in the sandbox.';
|
|
80
80
|
/** Why an escalation cannot be reviewed: an unattended run (no one can approve it). */
|
|
81
|
-
export const ESCALATION_UNATTENDED_WHY = "this is an unattended run (
|
|
81
|
+
export const ESCALATION_UNATTENDED_WHY = "this is an unattended run (an automation) where no one can approve running outside the sandbox";
|
|
82
82
|
/**
|
|
83
83
|
* The device's own words appended to a refusal that cites its report: its description (what the
|
|
84
84
|
* device may do now) and its change hint (who changes that and how), each without a final period,
|
|
@@ -385,7 +385,7 @@ export declare class SandboxService {
|
|
|
385
385
|
policy?: EffectiveDevicePolicy;
|
|
386
386
|
}): Promise<DeviceLimits>;
|
|
387
387
|
/**
|
|
388
|
-
* The org's limits for a standing network grant (
|
|
388
|
+
* The org's limits for a standing network grant (an automation's grant, a network approval):
|
|
389
389
|
* {@link deviceLimits} with the org's per-call host ceiling as an allowlist (`hostGrantCeiling`
|
|
390
390
|
* with no device). Where that ceiling is bounded by the kernel only (`any`, which an allowlist
|
|
391
391
|
* cannot carry with its exclusions), the org's effective hosts: a standing grant never reaches
|
|
@@ -538,12 +538,18 @@ export declare class SandboxService {
|
|
|
538
538
|
/** Trusted staging only. The callback receives no exec, browsing or lifecycle methods. */
|
|
539
539
|
withPreparation<T>(ctx: SandboxUseContext, purpose: SandboxPreparationScope["purpose"], roots: readonly string[], fn: (p: SandboxPreparation, signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T>;
|
|
540
540
|
private prepareFor;
|
|
541
|
-
/**
|
|
541
|
+
/**
|
|
542
|
+
* Owner browse scopes never manufacture a conversation or Full consent. `narrow.readRoots`
|
|
543
|
+
* roots every call's scope at those paths (a project's files: its root), each inside the owner's
|
|
544
|
+
* ceiling and never wider; none inside it is `device.project_outside_mode`.
|
|
545
|
+
*/
|
|
542
546
|
withBrowse<T>(ctx: {
|
|
543
547
|
orgId: string;
|
|
544
548
|
deviceId: string;
|
|
545
549
|
accountId: string;
|
|
546
|
-
}, fn: (p: SandboxBrowse, signal: AbortSignal) => Promise<T>, signal: AbortSignal
|
|
550
|
+
}, fn: (p: SandboxBrowse, signal: AbortSignal) => Promise<T>, signal: AbortSignal, narrow?: {
|
|
551
|
+
readRoots: readonly string[];
|
|
552
|
+
}): Promise<T>;
|
|
547
553
|
/**
|
|
548
554
|
* Makes the device's instance run for its owner (permission activation L2, Hook 3), before an
|
|
549
555
|
* owner browse ({@link withBrowse}) of a device that may be stopped: the owner, membership and
|
|
@@ -551,13 +557,17 @@ export declare class SandboxService {
|
|
|
551
557
|
* use takes (the exclusive lease creates or resumes the instance through the retirement gate,
|
|
552
558
|
* the B-11 reconcile marker, `maxRunningSandboxes` and fencing), and the lease
|
|
553
559
|
* is left at once. No conversation holds it and nothing runs in it; what the start caused is
|
|
554
|
-
* not marked seen, so each conversation's next use still learns of it.
|
|
560
|
+
* not marked seen, so each conversation's next use still learns of it. `narrow` is the browse's
|
|
561
|
+
* own (see {@link withBrowse}), checked before the start, so a browse the narrowed scope refuses
|
|
562
|
+
* (`device.project_outside_mode`) never starts the device.
|
|
555
563
|
*/
|
|
556
564
|
ensureRunningForOwner(ctx: {
|
|
557
565
|
orgId: string;
|
|
558
566
|
deviceId: string;
|
|
559
567
|
accountId: string;
|
|
560
|
-
}, signal: AbortSignal
|
|
568
|
+
}, signal: AbortSignal, narrow?: {
|
|
569
|
+
readRoots: readonly string[];
|
|
570
|
+
}): Promise<void>;
|
|
561
571
|
/**
|
|
562
572
|
* Makes the device's instance run for a managed call before its permission review reads the
|
|
563
573
|
* device's facts: the lifecycle `enter` the call's own use takes (the exclusive lease creates
|
|
@@ -490,7 +490,7 @@ let SandboxService = class SandboxService {
|
|
|
490
490
|
}, override);
|
|
491
491
|
}
|
|
492
492
|
/**
|
|
493
|
-
* The org's limits for a standing network grant (
|
|
493
|
+
* The org's limits for a standing network grant (an automation's grant, a network approval):
|
|
494
494
|
* {@link deviceLimits} with the org's per-call host ceiling as an allowlist (`hostGrantCeiling`
|
|
495
495
|
* with no device). Where that ceiling is bounded by the kernel only (`any`, which an allowlist
|
|
496
496
|
* cannot carry with its exclusions), the org's effective hosts: a standing grant never reaches
|
|
@@ -927,9 +927,13 @@ let SandboxService = class SandboxService {
|
|
|
927
927
|
stat: async (path, signal) => (await operation()).stat(path, AbortSignal.any([sig, signal])),
|
|
928
928
|
}, sig);
|
|
929
929
|
}
|
|
930
|
-
/**
|
|
931
|
-
|
|
932
|
-
|
|
930
|
+
/**
|
|
931
|
+
* Owner browse scopes never manufacture a conversation or Full consent. `narrow.readRoots`
|
|
932
|
+
* roots every call's scope at those paths (a project's files: its root), each inside the owner's
|
|
933
|
+
* ceiling and never wider; none inside it is `device.project_outside_mode`.
|
|
934
|
+
*/
|
|
935
|
+
async withBrowse(ctx, fn, signal, narrow) {
|
|
936
|
+
await this.authority.resolveBrowse(ctx, signal, narrow);
|
|
933
937
|
const row = await this.readRow(ctx);
|
|
934
938
|
if (!row)
|
|
935
939
|
throw deviceNotRunning();
|
|
@@ -944,7 +948,7 @@ let SandboxService = class SandboxService {
|
|
|
944
948
|
provider: entry.plugin,
|
|
945
949
|
providerVersion: entry.version,
|
|
946
950
|
generation: String(row.created_at.getTime()),
|
|
947
|
-
}, method, input, combined);
|
|
951
|
+
}, method, input, combined, narrow);
|
|
948
952
|
const admitted = await this.operationIntents.claimBrowse(ctx, intent.operation_id);
|
|
949
953
|
combined.throwIfAborted();
|
|
950
954
|
try {
|
|
@@ -975,10 +979,12 @@ let SandboxService = class SandboxService {
|
|
|
975
979
|
* use takes (the exclusive lease creates or resumes the instance through the retirement gate,
|
|
976
980
|
* the B-11 reconcile marker, `maxRunningSandboxes` and fencing), and the lease
|
|
977
981
|
* is left at once. No conversation holds it and nothing runs in it; what the start caused is
|
|
978
|
-
* not marked seen, so each conversation's next use still learns of it.
|
|
982
|
+
* not marked seen, so each conversation's next use still learns of it. `narrow` is the browse's
|
|
983
|
+
* own (see {@link withBrowse}), checked before the start, so a browse the narrowed scope refuses
|
|
984
|
+
* (`device.project_outside_mode`) never starts the device.
|
|
979
985
|
*/
|
|
980
|
-
async ensureRunningForOwner(ctx, signal) {
|
|
981
|
-
await this.authority.resolveBrowse(ctx, signal);
|
|
986
|
+
async ensureRunningForOwner(ctx, signal, narrow) {
|
|
987
|
+
await this.authority.resolveBrowse(ctx, signal, narrow);
|
|
982
988
|
const p = await this.require(ctx.deviceId, ctx.orgId);
|
|
983
989
|
const use = {
|
|
984
990
|
orgId: ctx.orgId,
|
package/dist/storage/purge.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
5
5
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
6
6
|
import type { KernelLogger } from "../log.js";
|
|
7
7
|
import { type PrefixedStorage, StorageService } from "./storage.service.js";
|
|
8
|
-
/**
|
|
8
|
+
/** Scheduled job: purges the object storage of deleted organizations (the name has no `:`), hourly on the hour. */
|
|
9
9
|
export declare const STORAGE_PURGE_JOB = "storage-org-purge";
|
|
10
10
|
/**
|
|
11
11
|
* 删除「软删除超过 `afterDays` 天、尚未清理存储」的组织的全部对象(`StorageService.deleteOrg`),
|
package/dist/storage/purge.js
CHANGED
|
@@ -15,9 +15,9 @@ import { LockService } from "../infra/lock/lock.service.js";
|
|
|
15
15
|
import { LockedCron } from "../infra/schedule/locked-cron.decorator.js";
|
|
16
16
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
17
17
|
import { StorageService } from "./storage.service.js";
|
|
18
|
-
/**
|
|
18
|
+
/** Scheduled job: purges the object storage of deleted organizations (the name has no `:`), hourly on the hour. */
|
|
19
19
|
export const STORAGE_PURGE_JOB = "storage-org-purge";
|
|
20
|
-
/**
|
|
20
|
+
/** The most organizations one run handles (successes and failures together). */
|
|
21
21
|
const PURGE_BATCH = 100;
|
|
22
22
|
/** 认领超过这么久仍未完成(运行中途退出)就可被重新认领。 */
|
|
23
23
|
const CLAIM_STALE_MINUTES = 60;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type LocalizedName, type ToolDisplay } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { AutomationStore } from "../automations/store.js";
|
|
2
3
|
import { EventLog } from "../conversations/event-log.js";
|
|
3
4
|
import { type EventPayload, type ReviewRecord, type ToolView } from "../conversations/events.js";
|
|
4
5
|
import { ConversationLeakCheck } from "../conversations/leak-check.js";
|
|
@@ -18,7 +19,6 @@ import { PermissionAuthorityLock } from "../sandbox/permission-authority-lock.js
|
|
|
18
19
|
import { PermissionCallGrants } from "../sandbox/permission-call-grants.js";
|
|
19
20
|
import type { PermissionCandidate, PermissionEscalation, PermissionExpansion } from "../sandbox/permission-call-types.js";
|
|
20
21
|
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
21
|
-
import { ScheduledTaskStore } from "../schedules/store.js";
|
|
22
22
|
import type { ApprovalPolicySource } from "./pipeline.js";
|
|
23
23
|
import { ToolRegistry } from "./registry.js";
|
|
24
24
|
export { APPROVAL_DENY_REASON_MAX_CHARS } from "../conversations/events.js";
|
|
@@ -474,7 +474,7 @@ export declare class ApprovalsService {
|
|
|
474
474
|
private readonly eventLog;
|
|
475
475
|
private readonly events;
|
|
476
476
|
readonly txHost: TransactionHost;
|
|
477
|
-
private readonly
|
|
477
|
+
private readonly automations;
|
|
478
478
|
/** A trial approval is kept only for a tool the task may hold as a grant (its agent's tools). */
|
|
479
479
|
private readonly registry;
|
|
480
480
|
/** One decision of a network ask at a time, across replicas. */
|
|
@@ -491,7 +491,7 @@ export declare class ApprovalsService {
|
|
|
491
491
|
private readonly devices;
|
|
492
492
|
private readonly permissionLocks?;
|
|
493
493
|
private readonly permissionGrants?;
|
|
494
|
-
constructor(db: KernelDb, config: Pick<KernelConfigService, "get">, eventLog: Pick<EventLog, "appendIn" | "notify">, events: Pick<KernelEvents, "emit">, txHost: TransactionHost,
|
|
494
|
+
constructor(db: KernelDb, config: Pick<KernelConfigService, "get">, eventLog: Pick<EventLog, "appendIn" | "notify">, events: Pick<KernelEvents, "emit">, txHost: TransactionHost, automations: Pick<AutomationStore, "addGrant">,
|
|
495
495
|
/** A trial approval is kept only for a tool the task may hold as a grant (its agent's tools). */
|
|
496
496
|
registry: Pick<ToolRegistry, "forAgent">,
|
|
497
497
|
/** One decision of a network ask at a time, across replicas. */
|
|
@@ -614,7 +614,7 @@ export declare class ApprovalsService {
|
|
|
614
614
|
*/
|
|
615
615
|
private decideTx;
|
|
616
616
|
/**
|
|
617
|
-
* A trial run of
|
|
617
|
+
* A trial run of an automation (scheduled tasks spec §7): an approval its creator granted, in
|
|
618
618
|
* any scope, is also added to the task's grants with the approved definition's hash, so its
|
|
619
619
|
* unattended runs do not ask again. Kept only by the rule `addGrants` applies
|
|
620
620
|
* (`grantRefusalOf`, against the task agent's tools now): never a role-escalated approval
|
|
@@ -625,7 +625,7 @@ export declare class ApprovalsService {
|
|
|
625
625
|
*/
|
|
626
626
|
private keepTrialGrant;
|
|
627
627
|
/**
|
|
628
|
-
* A trial run of
|
|
628
|
+
* A trial run of an automation (network ask-to-allow spec §8.1): the hosts its creator allowed
|
|
629
629
|
* for this run (「这次允许」) on a network ask about one of their devices become the task's
|
|
630
630
|
* `network:<host>` grants, each only when `networkGrantRefusal` allows it (exact host, within the
|
|
631
631
|
* org's effective egress, the device takes remote grants). Never for an ask another account
|
|
@@ -639,7 +639,7 @@ export declare class ApprovalsService {
|
|
|
639
639
|
*/
|
|
640
640
|
private allowRepoIn;
|
|
641
641
|
/**
|
|
642
|
-
* A trial run of
|
|
642
|
+
* A trial run of an automation (sandbox git credentials spec §7): a push its creator allowed
|
|
643
643
|
* for this run (「这次允许」) becomes the task's `git:push:<owner>/<repo>` grant, when
|
|
644
644
|
* `gitGrantRefusal` allows it (the org does not forbid it). Never for an ask another account
|
|
645
645
|
* decided or one asked of someone else. In the decision's transaction.
|