@capybara-hq/kernel 0.1.0-rc.66 → 0.1.0-rc.67
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 +0 -8
- package/dist/admin/admin.schemas.d.ts +3 -0
- package/dist/agents/admin-agents.d.ts +2 -2
- package/dist/agents/admin-agents.js +2 -1
- package/dist/agents/agent-lookup.js +2 -1
- package/dist/agents/agent-profile.service.d.ts +5 -2
- package/dist/agents/agent-profile.service.js +13 -2
- package/dist/agents/agents.controller.d.ts +4 -3
- package/dist/agents/agents.controller.js +7 -3
- package/dist/agents/agents.module.js +3 -0
- package/dist/agents/agents.schemas.d.ts +6 -6
- package/dist/agents/agents.service.d.ts +23 -2
- package/dist/agents/agents.service.js +61 -6
- package/dist/agents/avatar-view.d.ts +8 -0
- package/dist/agents/avatar-view.js +12 -0
- package/dist/agents/profile.d.ts +38 -13
- package/dist/agents/profile.js +31 -20
- package/dist/background/poll.job.d.ts +1 -1
- package/dist/background/poll.job.js +8 -6
- package/dist/background/tasks.service.js +1 -1
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/inbound.d.ts +2 -3
- package/dist/channels/inbound.js +2 -3
- package/dist/channels/phrases.d.ts +3 -3
- package/dist/channels/phrases.js +3 -3
- package/dist/config/schema.d.ts +1 -0
- package/dist/config/schema.js +14 -1
- package/dist/conversations/conversations.service.d.ts +4 -3
- package/dist/conversations/conversations.service.js +4 -2
- package/dist/ctx/create-ctx.js +5 -2
- package/dist/ctx/device-provider-check.d.ts +7 -0
- package/dist/ctx/device-provider-check.js +21 -0
- package/dist/db/kernel-schema.d.ts +7 -0
- package/dist/devices/access.d.ts +16 -46
- package/dist/devices/access.js +26 -62
- package/dist/devices/access.module.js +2 -2
- package/dist/devices/conversation-devices.d.ts +38 -18
- package/dist/devices/conversation-devices.js +69 -51
- package/dist/devices/default-provider-setting.d.ts +45 -0
- package/dist/devices/default-provider-setting.js +59 -0
- package/dist/devices/device-projects.service.js +7 -2
- package/dist/devices/device-provider-selection.d.ts +37 -0
- package/dist/devices/device-provider-selection.js +86 -0
- package/dist/devices/device-provider-selection.module.d.ts +3 -0
- package/dist/devices/device-provider-selection.module.js +22 -0
- package/dist/devices/devices.controller.d.ts +8 -5
- package/dist/devices/devices.controller.js +7 -4
- package/dist/devices/devices.module.js +3 -1
- package/dist/devices/devices.schemas.js +2 -2
- package/dist/devices/devices.service.d.ts +72 -83
- package/dist/devices/devices.service.js +139 -248
- package/dist/devices/dto.d.ts +9 -0
- package/dist/devices/dto.js +15 -2
- package/dist/devices/label.d.ts +3 -5
- package/dist/devices/label.js +3 -14
- package/dist/devices/legacy-cleanup.job.d.ts +2 -2
- package/dist/devices/legacy-cleanup.job.js +6 -6
- package/dist/errors.d.ts +15 -1
- package/dist/errors.js +15 -1
- package/dist/extensions/guide-places.d.ts +2 -1
- package/dist/extensions/guide-places.js +8 -2
- package/dist/extensions/locks.d.ts +1 -1
- package/dist/extensions/locks.js +1 -1
- package/dist/extensions/org-config.d.ts +20 -4
- package/dist/extensions/org-config.js +23 -6
- package/dist/extensions/permission-view.d.ts +2 -2
- package/dist/extensions/permission-view.js +2 -2
- package/dist/extensions/plugin-guides.d.ts +1 -1
- package/dist/extensions/plugin-guides.js +11 -3
- package/dist/extensions/point-defaults.d.ts +14 -0
- package/dist/extensions/point-defaults.js +70 -47
- package/dist/extensions/resolve.js +7 -2
- package/dist/identity/settings.d.ts +8 -0
- package/dist/identity/settings.js +24 -1
- package/dist/infra/config/kernel-config.service.js +2 -0
- package/dist/lifecycle/kernel-lifecycle.js +7 -6
- package/dist/local-devices/device-routes.d.ts +1 -1
- package/dist/local-devices/device-routes.js +1 -1
- package/dist/local-devices/local-device-provider.d.ts +14 -11
- package/dist/local-devices/local-device-provider.js +14 -0
- package/dist/local-devices/local-devices.module.d.ts +4 -4
- package/dist/local-devices/local-devices.module.js +5 -3
- package/dist/local-devices/owner-report.js +2 -1
- package/dist/local-devices/targets.d.ts +2 -0
- package/dist/local-devices/targets.js +10 -0
- package/dist/orgs/settings.service.d.ts +26 -1
- package/dist/orgs/settings.service.js +44 -3
- package/dist/platform/ops/admin.ops.js +8 -3
- package/dist/platform/ops/agents.ops.d.ts +6 -1
- package/dist/platform/ops/agents.ops.js +38 -11
- package/dist/platform/ops/devices.ops.js +25 -20
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/platform/ops/themes.ops.js +1 -1
- package/dist/runtime/plugin-context.service.js +1 -12
- package/dist/sandbox/cloud-permission-snapshot.d.ts +2 -2
- package/dist/sandbox/cloud-permission-snapshot.js +3 -3
- package/dist/sandbox/device-reports.d.ts +50 -0
- package/dist/sandbox/device-reports.js +157 -0
- package/dist/sandbox/held-operations.d.ts +8 -8
- package/dist/sandbox/leases.d.ts +1 -1
- package/dist/sandbox/leases.js +1 -1
- package/dist/sandbox/operation-authority.d.ts +5 -2
- package/dist/sandbox/operation-authority.js +12 -11
- package/dist/sandbox/operation-reconcile.job.d.ts +2 -2
- package/dist/sandbox/operation-reconcile.job.js +5 -5
- package/dist/sandbox/permission-availability.d.ts +2 -2
- package/dist/sandbox/permission-call-types.d.ts +5 -0
- package/dist/sandbox/permission-facts.d.ts +2 -2
- package/dist/sandbox/permission-facts.js +5 -5
- package/dist/sandbox/providers.d.ts +23 -24
- package/dist/sandbox/providers.js +38 -46
- package/dist/sandbox/providers.module.js +3 -3
- package/dist/sandbox/sandbox.module.d.ts +1 -1
- package/dist/sandbox/sandbox.module.js +7 -2
- package/dist/sandbox/sandbox.service.d.ts +95 -68
- package/dist/sandbox/sandbox.service.js +212 -208
- package/dist/setup/setup-guides.service.d.ts +4 -1
- package/dist/setup/setup-guides.service.js +6 -1
- package/dist/themes/avatar-preset-key.d.ts +6 -0
- package/dist/themes/avatar-preset-key.js +9 -0
- package/dist/themes/theme-state.d.ts +29 -1
- package/dist/themes/theme-state.js +40 -1
- package/dist/themes/themes.service.d.ts +28 -1
- package/dist/themes/themes.service.js +36 -2
- package/dist/tools/builtins/image/generate.d.ts +3 -0
- package/dist/tools/builtins/image/generate.js +21 -11
- package/dist/tools/builtins/image/index.d.ts +1 -1
- package/dist/tools/builtins/image/index.js +1 -1
- package/dist/tools/builtins/sandbox/common.d.ts +36 -12
- package/dist/tools/builtins/sandbox/common.js +62 -18
- package/dist/tools/builtins/sandbox/read.d.ts +5 -2
- package/dist/tools/builtins/sandbox/read.js +9 -6
- package/dist/tools/builtins/sandbox/task-output.d.ts +2 -2
- package/dist/tools/builtins/sandbox/task-output.js +6 -5
- package/dist/tools/builtins/skill-load.js +13 -4
- package/dist/until-aborted.d.ts +5 -0
- package/dist/until-aborted.js +16 -0
- package/package.json +4 -4
- package/src/migrations/0176_device_report.sql +6 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
+
};
|
|
10
|
+
import { parseDeviceReport } from "@capybara-hq/plugin-sdk";
|
|
11
|
+
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
12
|
+
import { sql } from "kysely";
|
|
13
|
+
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
14
|
+
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
15
|
+
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
16
|
+
import { LockService } from "../infra/lock/lock.service.js";
|
|
17
|
+
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
18
|
+
import { untilAborted } from "../until-aborted.js";
|
|
19
|
+
/** How long a provider's `report` may take before the refresh gives up (keeps the stored one). */
|
|
20
|
+
export const DEVICE_REPORT_TIMEOUT_MS = 10_000;
|
|
21
|
+
/** Overrides {@link DEVICE_REPORT_TIMEOUT_MS} (ms; tests only). */
|
|
22
|
+
export const DEVICE_REPORT_TIMEOUT = Symbol("DEVICE_REPORT_TIMEOUT");
|
|
23
|
+
/** A device's report failures are logged at most once per this window. */
|
|
24
|
+
const FAILURE_LOG_WINDOW_MS = 60 * 60_000;
|
|
25
|
+
const failureLogKey = (deviceId) => `capk:device-report-failure:${deviceId}`;
|
|
26
|
+
/** The revision of a stored report, or null when none (or not a readable one) is stored. */
|
|
27
|
+
function storedRevision(stored) {
|
|
28
|
+
if (typeof stored !== "object" || stored === null)
|
|
29
|
+
return null;
|
|
30
|
+
const revision = stored.revision;
|
|
31
|
+
return typeof revision === "string" ? revision : null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The stored device report (`devices.report`, `report_at`; device-provider spec §6.1): what a
|
|
35
|
+
* device's provider last told about it (`device-provider@1` `report()`), shown to people and never
|
|
36
|
+
* used for enforcement. {@link refresh} asks the provider and stores the answer; request paths
|
|
37
|
+
* {@link read} the stored copy from PG and never call the provider.
|
|
38
|
+
*/
|
|
39
|
+
let DeviceReports = class DeviceReports {
|
|
40
|
+
db;
|
|
41
|
+
txHost;
|
|
42
|
+
locks;
|
|
43
|
+
log;
|
|
44
|
+
timeoutMs;
|
|
45
|
+
constructor(db, txHost, locks, log, timeoutMs = DEVICE_REPORT_TIMEOUT_MS) {
|
|
46
|
+
this.db = db;
|
|
47
|
+
this.txHost = txHost;
|
|
48
|
+
this.locks = locks;
|
|
49
|
+
this.log = log;
|
|
50
|
+
this.timeoutMs = timeoutMs;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Asks `entry` for the report of `ref`'s device (given up after {@link DEVICE_REPORT_TIMEOUT_MS}
|
|
54
|
+
* or on `signal`, even when the provider ignores its signal), checks it ({@link parseDeviceReport}) and stores it with `report_at`, only
|
|
55
|
+
* while the device is live and still bound to `entry` (`devices.provider = entry.plugin`).
|
|
56
|
+
* `changed`: the stored revision differs from the one before (true for a first report). Never
|
|
57
|
+
* throws: a failing or invalid answer leaves the stored report as it was and is logged at most
|
|
58
|
+
* once per device per hour; an abort of `signal` is not logged. Call it outside any transaction
|
|
59
|
+
* (the provider call must not hold one open).
|
|
60
|
+
*/
|
|
61
|
+
async refresh(entry, ref, signal) {
|
|
62
|
+
let report;
|
|
63
|
+
try {
|
|
64
|
+
const bounded = AbortSignal.any([signal, AbortSignal.timeout(this.timeoutMs)]);
|
|
65
|
+
// raced, not only signalled: a provider that ignores the signal never holds the lease past it
|
|
66
|
+
report = parseDeviceReport(await untilAborted(entry.impl.report(ref, bounded), bounded));
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
if (!signal.aborted)
|
|
70
|
+
await this.noteFailure(entry, ref.deviceId, err);
|
|
71
|
+
return { changed: false };
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
return { changed: await this.store(entry.plugin, ref, report) };
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
await this.noteFailure(entry, ref.deviceId, err);
|
|
78
|
+
return { changed: false };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The stored report of a live device of `orgId`, checked again ({@link parseDeviceReport});
|
|
83
|
+
* null when none is stored, the stored one no longer passes, or there is no such device.
|
|
84
|
+
* Reads PG only.
|
|
85
|
+
*/
|
|
86
|
+
async read(orgId, deviceId) {
|
|
87
|
+
const row = await this.db
|
|
88
|
+
.selectFrom("devices")
|
|
89
|
+
.select("report")
|
|
90
|
+
.where("id", "=", deviceId)
|
|
91
|
+
.where("org_id", "=", orgId)
|
|
92
|
+
.where("deleted_at", "is", null)
|
|
93
|
+
.executeTakeFirst();
|
|
94
|
+
if (row?.report == null)
|
|
95
|
+
return null;
|
|
96
|
+
try {
|
|
97
|
+
return parseDeviceReport(row.report);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Writes `report` on the device if it is live and bound to `plugin`; whether its revision
|
|
105
|
+
* differs from the stored one. The row is locked first, so two refreshes of one device compare
|
|
106
|
+
* against each other's writes, never against the same old value.
|
|
107
|
+
*/
|
|
108
|
+
async store(plugin, ref, report) {
|
|
109
|
+
const row = await this.db
|
|
110
|
+
.selectFrom("devices")
|
|
111
|
+
.select("report")
|
|
112
|
+
.where("id", "=", ref.deviceId)
|
|
113
|
+
.where("org_id", "=", ref.orgId)
|
|
114
|
+
.where("provider", "=", plugin)
|
|
115
|
+
.where("deleted_at", "is", null)
|
|
116
|
+
.forNoKeyUpdate()
|
|
117
|
+
.executeTakeFirst();
|
|
118
|
+
// deleted, or bound to another provider than the one that answered: nothing is written
|
|
119
|
+
if (!row)
|
|
120
|
+
return false;
|
|
121
|
+
await this.db
|
|
122
|
+
.updateTable("devices")
|
|
123
|
+
.set({ report: JSON.stringify(report), report_at: sql `now()` })
|
|
124
|
+
.where("id", "=", ref.deviceId)
|
|
125
|
+
.execute();
|
|
126
|
+
return storedRevision(row.report) !== report.revision;
|
|
127
|
+
}
|
|
128
|
+
/** Logs a refresh failure, at most once per device per hour (a Redis key with a TTL). */
|
|
129
|
+
async noteFailure(entry, deviceId, err) {
|
|
130
|
+
let first = true;
|
|
131
|
+
try {
|
|
132
|
+
first = await this.locks.lease(failureLogKey(deviceId), "1", FAILURE_LOG_WINDOW_MS);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// Redis unavailable: log anyway rather than hiding it
|
|
136
|
+
}
|
|
137
|
+
if (first)
|
|
138
|
+
this.log.warn("cannot refresh the device report; the stored one is kept", {
|
|
139
|
+
deviceId,
|
|
140
|
+
provider: entry.plugin,
|
|
141
|
+
err,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
__decorate([
|
|
146
|
+
Transactional()
|
|
147
|
+
], DeviceReports.prototype, "store", null);
|
|
148
|
+
DeviceReports = __decorate([
|
|
149
|
+
Injectable(),
|
|
150
|
+
__param(0, Inject(KernelDb)),
|
|
151
|
+
__param(1, Inject(TransactionHost)),
|
|
152
|
+
__param(2, Inject(LockService)),
|
|
153
|
+
__param(3, Inject(KERNEL_LOGGER)),
|
|
154
|
+
__param(4, Optional()),
|
|
155
|
+
__param(4, Inject(DEVICE_REPORT_TIMEOUT))
|
|
156
|
+
], DeviceReports);
|
|
157
|
+
export { DeviceReports };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type ExecResult, type SandboxExecOptions, type SandboxExecutionRef, type SandboxHandle, type SandboxOperationScope
|
|
1
|
+
import { type DeviceProvider, type ExecResult, type SandboxExecOptions, type SandboxExecutionRef, type SandboxHandle, type SandboxOperationScope } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
/** A callback can use native operations; it cannot obtain a new authority or change lifecycle. */
|
|
3
|
-
export type HeldProvider = Pick<
|
|
4
|
-
exec(h: SandboxHandle, args: Omit<Parameters<
|
|
3
|
+
export type HeldProvider = Pick<DeviceProvider, "readFile" | "writeFile" | "stat" | "list" | "scan"> & {
|
|
4
|
+
exec(h: SandboxHandle, args: Omit<Parameters<DeviceProvider["exec"]>[1], "tag" | "actor">): Promise<ExecResult>;
|
|
5
5
|
/**
|
|
6
6
|
* A managed background start (dormant until the paired activation): admitted, persisted and
|
|
7
7
|
* acknowledged by the service under the same stable operation identity. Present only on the
|
|
@@ -27,20 +27,20 @@ export type OperationDispatch = <T>(method: OperationMethod, input: unknown, inv
|
|
|
27
27
|
*/
|
|
28
28
|
preflight?: (scope: SandboxOperationScope, signal: AbortSignal) => Promise<void>) => Promise<T>;
|
|
29
29
|
/** The provider's runtime must enforce the scope's profile (and own background executions). */
|
|
30
|
-
export declare function assertPermissionSupport(provider:
|
|
30
|
+
export declare function assertPermissionSupport(provider: DeviceProvider, handle: SandboxHandle, scope: SandboxOperationScope, method: OperationMethod, signal: AbortSignal): Promise<void>;
|
|
31
31
|
/**
|
|
32
32
|
* Every check a managed start needs before it may reach the provider, for the first dispatch and
|
|
33
33
|
* for a same-identity recovery alike: the artifact is covered by the admitted starting authority,
|
|
34
34
|
* then the runtime supports the profile and owns background executions.
|
|
35
35
|
*/
|
|
36
|
-
export declare function checkManagedStart(provider:
|
|
36
|
+
export declare function checkManagedStart(provider: DeviceProvider, handle: SandboxHandle, scope: SandboxOperationScope, input: Omit<ManagedStartArgs, "signal">, signal: AbortSignal): Promise<void>;
|
|
37
37
|
/**
|
|
38
38
|
* `provider` whose background starts carry `instanceGeneration`, the kernel's generation of the
|
|
39
39
|
* held instance (its `created_at` milliseconds): a cloud provider cannot know it otherwise (it is
|
|
40
40
|
* allocated after `create` returns), and the acknowledgement requires the ref to name it. A bound
|
|
41
41
|
* (local) device knows its generation from its binding and is not given one.
|
|
42
42
|
*/
|
|
43
|
-
export declare function withKernelGeneration(provider:
|
|
44
|
-
export declare function createHeldOperations(provider:
|
|
43
|
+
export declare function withKernelGeneration(provider: DeviceProvider, generation: string): DeviceProvider;
|
|
44
|
+
export declare function createHeldOperations(provider: DeviceProvider, handle: SandboxHandle, heldSignal: AbortSignal, dispatch: OperationDispatch): HeldProvider;
|
|
45
45
|
/** Temporary v2 callback adapter. Removed with the coordinated Task 8 cutover. */
|
|
46
|
-
export declare function createLegacyHeldProvider(provider:
|
|
46
|
+
export declare function createLegacyHeldProvider(provider: DeviceProvider, tag: string, actor: Parameters<DeviceProvider["exec"]>[1]["actor"], before: () => Promise<void>): HeldProvider;
|
package/dist/sandbox/leases.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { KernelLogger } from "../log.js";
|
|
|
7
7
|
* protocol that lets several holders (every conversation bound to the device, and their
|
|
8
8
|
* sub-agents) use one device's running instance concurrently (shared leases: commands, file
|
|
9
9
|
* reads and writes) while lifecycle changes (create, resume, rebuild, suspend, destroy, reset) stay
|
|
10
|
-
* alone (exclusive leases). Every `
|
|
10
|
+
* alone (exclusive leases). Every `device-provider@1` provider runs commands concurrently and kills by tag,
|
|
11
11
|
* so there is no single-holder mode. Keys, env = the device id:
|
|
12
12
|
*
|
|
13
13
|
* - `capk:sandbox:<env>`: the lock key: an exclusive holder's token, or `shared` while shared
|
package/dist/sandbox/leases.js
CHANGED
|
@@ -18,7 +18,7 @@ import { KERNEL_LOGGER, REDIS } from "../infra/tokens.js";
|
|
|
18
18
|
* protocol that lets several holders (every conversation bound to the device, and their
|
|
19
19
|
* sub-agents) use one device's running instance concurrently (shared leases: commands, file
|
|
20
20
|
* reads and writes) while lifecycle changes (create, resume, rebuild, suspend, destroy, reset) stay
|
|
21
|
-
* alone (exclusive leases). Every `
|
|
21
|
+
* alone (exclusive leases). Every `device-provider@1` provider runs commands concurrently and kills by tag,
|
|
22
22
|
* so there is no single-holder mode. Keys, env = the device id:
|
|
23
23
|
*
|
|
24
24
|
* - `capk:sandbox:<env>`: the lock key: an exclusive holder's token, or `shared` while shared
|
|
@@ -27,7 +27,8 @@ export interface PermissionScopeFacts {
|
|
|
27
27
|
actor: SandboxActor;
|
|
28
28
|
tag: string;
|
|
29
29
|
workingRoot: string;
|
|
30
|
-
|
|
30
|
+
/** The bound project's path when it is the working root, else null (free mode). */
|
|
31
|
+
projectRoot: string | null;
|
|
31
32
|
writeRoots: readonly string[];
|
|
32
33
|
allowedHosts: readonly string[];
|
|
33
34
|
/** The sandbox network of the call ({@link sandboxNetworkOf}); `allowlist` uses `allowedHosts`. */
|
|
@@ -51,7 +52,9 @@ export declare function sandboxNetworkOf(box: Pick<DeviceSandbox, "networkMode">
|
|
|
51
52
|
/**
|
|
52
53
|
* Only server-resolved facts enter this constructor; callers never submit roots or profile. It
|
|
53
54
|
* never branches on the profile: every call is sandboxed (scoped filesystem, the sandbox network),
|
|
54
|
-
* and only an escalated call within the outside-sandbox ceiling gets the device pair.
|
|
55
|
+
* and only an escalated call within the outside-sandbox ceiling gets the device pair. A scoped
|
|
56
|
+
* filesystem names the project root and the write roots only: what a sandboxed operation may read
|
|
57
|
+
* is the provider's rule.
|
|
55
58
|
*/
|
|
56
59
|
export declare function intersectPermissionScope(f: PermissionScopeFacts): SandboxOperationScope;
|
|
57
60
|
/** Fresh authority shape only. Provider dispatch must add durable admission fencing before use. */
|
|
@@ -81,7 +81,9 @@ const instanceRoots = (workingRoot) => [...new Set(["/", workingRoot])].sort(per
|
|
|
81
81
|
/**
|
|
82
82
|
* Only server-resolved facts enter this constructor; callers never submit roots or profile. It
|
|
83
83
|
* never branches on the profile: every call is sandboxed (scoped filesystem, the sandbox network),
|
|
84
|
-
* and only an escalated call within the outside-sandbox ceiling gets the device pair.
|
|
84
|
+
* and only an escalated call within the outside-sandbox ceiling gets the device pair. A scoped
|
|
85
|
+
* filesystem names the project root and the write roots only: what a sandboxed operation may read
|
|
86
|
+
* is the provider's rule.
|
|
85
87
|
*/
|
|
86
88
|
export function intersectPermissionScope(f) {
|
|
87
89
|
if (f.escalated && (!f.outsideSandboxCeiling || f.boundary === "instance"))
|
|
@@ -103,12 +105,12 @@ export function intersectPermissionScope(f) {
|
|
|
103
105
|
: f.boundary === "instance"
|
|
104
106
|
? {
|
|
105
107
|
kind: "scoped",
|
|
106
|
-
|
|
108
|
+
projectRoot: f.projectRoot,
|
|
107
109
|
writeRoots: instanceRoots(f.workingRoot),
|
|
108
110
|
}
|
|
109
111
|
: {
|
|
110
112
|
kind: "scoped",
|
|
111
|
-
|
|
113
|
+
projectRoot: f.projectRoot,
|
|
112
114
|
writeRoots: [...new Set(f.writeRoots)].sort(),
|
|
113
115
|
},
|
|
114
116
|
network: escalated
|
|
@@ -308,10 +310,8 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
308
310
|
: [];
|
|
309
311
|
const scope = this.scopeOf(ctx, operation, {
|
|
310
312
|
...f,
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
...(grant?.expansion.readDirectories ?? []),
|
|
314
|
-
],
|
|
313
|
+
// an accepted read-directory expansion stays in the review facts and the grant row but
|
|
314
|
+
// reaches no provider: a scope carries no read roots (the provider's read rule decides)
|
|
315
315
|
baseWriteDirectories: [
|
|
316
316
|
...f.baseWriteDirectories,
|
|
317
317
|
...(grant?.expansion.writeDirectories ?? []),
|
|
@@ -382,7 +382,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
382
382
|
}
|
|
383
383
|
const profile = this.scopeOf(ctx, method, f);
|
|
384
384
|
if (profile.filesystem.kind === "scoped" &&
|
|
385
|
-
!
|
|
385
|
+
!f.baseReadDirectories.some((r) => covering === r || covering.startsWith(r === "/" ? "/" : `${r}/`)))
|
|
386
386
|
throw new ApiError("forbidden", "The kernel read is outside the conversation's profile");
|
|
387
387
|
// a restricted read-only scope whenever the runtime enforces it, whatever the conversation's
|
|
388
388
|
// profile: a runtime keyed on Full access may follow a symlinked AGENTS.md or SKILL.md out of
|
|
@@ -396,10 +396,10 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
396
396
|
filesystem: instance
|
|
397
397
|
? {
|
|
398
398
|
kind: "scoped",
|
|
399
|
-
|
|
399
|
+
projectRoot: covering,
|
|
400
400
|
writeRoots: instanceRoots(f.workingRoot),
|
|
401
401
|
}
|
|
402
|
-
: { kind: "scoped",
|
|
402
|
+
: { kind: "scoped", projectRoot: covering, writeRoots: [] },
|
|
403
403
|
network: { kind: "none" },
|
|
404
404
|
});
|
|
405
405
|
}
|
|
@@ -442,7 +442,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
442
442
|
actor: ctx.actor,
|
|
443
443
|
tag: operationId,
|
|
444
444
|
workingRoot: f.workingRoot,
|
|
445
|
-
|
|
445
|
+
projectRoot: f.projectRoot,
|
|
446
446
|
writeRoots: f.baseWriteDirectories,
|
|
447
447
|
allowedHosts: isExecutionMethod(operation) ? f.baseHosts : [],
|
|
448
448
|
// a native method reaches no network: only executions carry the sandbox network
|
|
@@ -548,6 +548,7 @@ let SandboxOperationAuthority = class SandboxOperationAuthority {
|
|
|
548
548
|
scopeRevision: view.scopeRevision,
|
|
549
549
|
authorityRevision: permissionScopeHash({ scopeRevision: view.scopeRevision, vector }),
|
|
550
550
|
workingRoot,
|
|
551
|
+
projectRoot,
|
|
551
552
|
baseReadDirectories: restrictedReadRoots(workingRoot, applied),
|
|
552
553
|
baseWriteDirectories: [workingRoot],
|
|
553
554
|
baseHosts: allowedHosts,
|
|
@@ -4,7 +4,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
|
4
4
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
5
5
|
import type { KernelLogger } from "../log.js";
|
|
6
6
|
import { SandboxOperationIntents } from "./operation-intents.js";
|
|
7
|
-
import {
|
|
7
|
+
import { DeviceProviders } from "./providers.js";
|
|
8
8
|
import { SandboxService } from "./sandbox.service.js";
|
|
9
9
|
/** Called only by the maintenance consumer. It has no native dispatch or lease token API. */
|
|
10
10
|
export declare class SandboxOperationReconcileJob {
|
|
@@ -17,7 +17,7 @@ export declare class SandboxOperationReconcileJob {
|
|
|
17
17
|
private readonly config;
|
|
18
18
|
/** Where a recovered start's refusal keeps the provider's own message (never the task's). */
|
|
19
19
|
private readonly log?;
|
|
20
|
-
constructor(intents: SandboxOperationIntents, db: KernelDb, providers:
|
|
20
|
+
constructor(intents: SandboxOperationIntents, db: KernelDb, providers: Pick<DeviceProviders, "forDevice">, sandbox: Pick<SandboxService, "ifRunning">, tasks: Pick<BackgroundTaskStore, "byOperation" | "settleOwedCancel">, stopper: Pick<BackgroundTaskStopper, "stop">, config: Pick<KernelConfigService, "get">,
|
|
21
21
|
/** Where a recovered start's refusal keeps the provider's own message (never the task's). */
|
|
22
22
|
log?: Pick<KernelLogger, "warn"> | undefined);
|
|
23
23
|
reconcile(operationId: string): Promise<void>;
|
|
@@ -18,7 +18,7 @@ import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
|
18
18
|
import { isDeviceRequestNotSent } from "../local-devices/relay.js";
|
|
19
19
|
import { checkManagedStart } from "./held-operations.js";
|
|
20
20
|
import { SandboxOperationIntents } from "./operation-intents.js";
|
|
21
|
-
import {
|
|
21
|
+
import { DeviceProviders } from "./providers.js";
|
|
22
22
|
import { SandboxService } from "./sandbox.service.js";
|
|
23
23
|
/**
|
|
24
24
|
* What an operation's in-sandbox time limit leaves beyond `sandbox.limits.maxCommandSeconds`
|
|
@@ -111,11 +111,11 @@ let SandboxOperationReconcileJob = class SandboxOperationReconcileJob {
|
|
|
111
111
|
.select("provider")
|
|
112
112
|
.where("device_id", "=", claimed.device_id)
|
|
113
113
|
.executeTakeFirst();
|
|
114
|
-
const entry = this.providers.
|
|
114
|
+
const entry = this.providers.forDevice(claimed.provider);
|
|
115
115
|
if (!Number.isSafeInteger(generation) ||
|
|
116
116
|
instance?.provider !== claimed.provider ||
|
|
117
117
|
!entry ||
|
|
118
|
-
|
|
118
|
+
entry.version !== claimed.provider_version)
|
|
119
119
|
throw new SandboxOperationOutcomeUnknownError("The recorded provider or instance is not current; the start outcome remains unknown");
|
|
120
120
|
const r = await this.sandbox.ifRunning(claimed.device_id, { createdAt: new Date(generation) }, async (p, h, signal) => {
|
|
121
121
|
await checkManagedStart(p, h, scope, input, signal);
|
|
@@ -201,7 +201,7 @@ let SandboxOperationReconcileJob = class SandboxOperationReconcileJob {
|
|
|
201
201
|
}
|
|
202
202
|
throw new SandboxOperationOutcomeUnknownError("The revoked operation's instance must be reconciled before cleanup is acknowledged");
|
|
203
203
|
}
|
|
204
|
-
const provider = this.providers.
|
|
204
|
+
const provider = this.providers.forDevice(row.provider)?.impl;
|
|
205
205
|
if (!provider?.revokeOperation)
|
|
206
206
|
throw new SandboxOperationOutcomeUnknownError("The operation's provider is unavailable; revocation remains owed");
|
|
207
207
|
await provider.revokeOperation(instance.handle, { operationId: row.operation_id, admitBeforeMs: row.deadline.getTime() }, AbortSignal.timeout(30_000));
|
|
@@ -283,7 +283,7 @@ SandboxOperationReconcileJob = __decorate([
|
|
|
283
283
|
Injectable(),
|
|
284
284
|
__param(0, Inject(SandboxOperationIntents)),
|
|
285
285
|
__param(1, Inject(KernelDb)),
|
|
286
|
-
__param(2, Inject(
|
|
286
|
+
__param(2, Inject(DeviceProviders)),
|
|
287
287
|
__param(3, Inject(SandboxService)),
|
|
288
288
|
__param(4, Inject(BackgroundTaskStore)),
|
|
289
289
|
__param(5, Inject(BackgroundTaskStopper)),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SandboxPermissionSupport, SandboxPermissionUnsupportedError
|
|
1
|
+
import { type DeviceProvider, type SandboxPermissionSupport, SandboxPermissionUnsupportedError } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
/**
|
|
3
3
|
* Why a device cannot run permission-scoped work, for people and for the kernel-rendered admission
|
|
4
4
|
* text (ruling R9): an outdated sandbox provider plugin, or a runtime that cannot enforce the
|
|
@@ -43,7 +43,7 @@ export declare const unprobedPermissionAvailability: () => PermissionAvailabilit
|
|
|
43
43
|
* (ruling R9).
|
|
44
44
|
*/
|
|
45
45
|
export declare function permissionAvailabilityFor(provider: {
|
|
46
|
-
impl:
|
|
46
|
+
impl: DeviceProvider;
|
|
47
47
|
plugin: string;
|
|
48
48
|
version?: string;
|
|
49
49
|
} | undefined): PermissionAvailability;
|
|
@@ -98,6 +98,11 @@ export type PermissionReviewSnapshot = Readonly<Omit<PermissionCallBinding, "too
|
|
|
98
98
|
baseWriteDirectories: readonly string[];
|
|
99
99
|
baseHosts: readonly string[];
|
|
100
100
|
workingRoot: string;
|
|
101
|
+
/**
|
|
102
|
+
* The bound project's path when it is the working root (`workingRootOf`), else null (free
|
|
103
|
+
* mode, or a project the review works around in the workspace). An operation scope names it.
|
|
104
|
+
*/
|
|
105
|
+
projectRoot: string | null;
|
|
101
106
|
/**
|
|
102
107
|
* The call's sandbox network (the device sandbox within the applied outer boundary): `open-public`,
|
|
103
108
|
* `allowlist` (the base hosts plus accepted host grants) or `none`. Absent reads as `none`.
|
|
@@ -9,7 +9,7 @@ import { type ConsentReach, type DeviceSandbox, type HostGrantCeiling } from "./
|
|
|
9
9
|
import { type DeviceNetwork, type EffectiveDevicePolicy } from "./modes.js";
|
|
10
10
|
import { type PermissionAvailability } from "./permission-availability.js";
|
|
11
11
|
import type { AppliedEnvironment, AppliedOuterNetwork } from "./permission-context-types.js";
|
|
12
|
-
import {
|
|
12
|
+
import { DeviceProviders } from "./providers.js";
|
|
13
13
|
type Scope = DeviceProjectScope;
|
|
14
14
|
/**
|
|
15
15
|
* What decides the working root of a call (project root spec §4.3), read the same way for a
|
|
@@ -33,7 +33,7 @@ export declare class PermissionFacts {
|
|
|
33
33
|
private readonly config;
|
|
34
34
|
private readonly providers;
|
|
35
35
|
private readonly devices;
|
|
36
|
-
constructor(db: KernelDb, config: Pick<KernelConfigService, "get" | "fieldSource">, providers: Pick<
|
|
36
|
+
constructor(db: KernelDb, config: Pick<KernelConfigService, "get" | "fieldSource">, providers: Pick<DeviceProviders, "forDevice">, devices: Pick<DeviceAccess, "usable">);
|
|
37
37
|
/**
|
|
38
38
|
* Current policy, the device sandbox and persisted owner roots; access is checked by the caller.
|
|
39
39
|
* `sandbox` is the device sandbox under the device's current runtime report (the provider layer
|
|
@@ -28,7 +28,7 @@ import { appliedOf, appliedWider, cloudChosenMode, coversHost, effectiveDevicePo
|
|
|
28
28
|
import { assertAuthorityHeld } from "./permission-authority-lock.js";
|
|
29
29
|
import { deviceWorkAvailability, permissionAvailabilityFor, } from "./permission-availability.js";
|
|
30
30
|
import { readCurrentReport, readRuntimeReport, sameRuntimeIdentity, } from "./permission-runtime-reports.js";
|
|
31
|
-
import {
|
|
31
|
+
import { DeviceProviders } from "./providers.js";
|
|
32
32
|
import { homeOf } from "./review/rules.js";
|
|
33
33
|
export const permissionScopeHash = (value) => createHash("sha256").update(canonical(value)).digest("hex");
|
|
34
34
|
function canonical(value) {
|
|
@@ -302,7 +302,7 @@ let PermissionFacts = class PermissionFacts {
|
|
|
302
302
|
.where("id", "=", deviceId)
|
|
303
303
|
.where("org_id", "=", orgId)
|
|
304
304
|
.executeTakeFirst();
|
|
305
|
-
const provider = device ?
|
|
305
|
+
const provider = device ? this.providers.forDevice(device.provider) : undefined;
|
|
306
306
|
let availability = permissionAvailabilityFor(provider);
|
|
307
307
|
if (availability.state === "unprobed" && provider) {
|
|
308
308
|
const machine = provider.plugin === "@local"
|
|
@@ -445,7 +445,7 @@ let PermissionFacts = class PermissionFacts {
|
|
|
445
445
|
supported: deviceFeaturesOf(row.features).includes("projects"),
|
|
446
446
|
};
|
|
447
447
|
}
|
|
448
|
-
const impl =
|
|
448
|
+
const impl = this.providers.forDevice(row.provider)?.impl;
|
|
449
449
|
const handle = row.handle;
|
|
450
450
|
return {
|
|
451
451
|
source: "cloud",
|
|
@@ -750,7 +750,7 @@ let PermissionFacts = class PermissionFacts {
|
|
|
750
750
|
.select("provider")
|
|
751
751
|
.where("id", "=", input.deviceId)
|
|
752
752
|
.executeTakeFirst();
|
|
753
|
-
const entry =
|
|
753
|
+
const entry = this.providers.forDevice(device?.provider ?? null);
|
|
754
754
|
if (!entry || entry.plugin !== instance.provider)
|
|
755
755
|
return null;
|
|
756
756
|
const evidence = await readCurrentReport(this.db.db, input.deviceId, entry.plugin, entry.version);
|
|
@@ -782,7 +782,7 @@ PermissionFacts = __decorate([
|
|
|
782
782
|
Injectable(),
|
|
783
783
|
__param(0, Inject(KernelDb)),
|
|
784
784
|
__param(1, Inject(KernelConfigService)),
|
|
785
|
-
__param(2, Inject(
|
|
785
|
+
__param(2, Inject(DeviceProviders)),
|
|
786
786
|
__param(3, Inject(DeviceAccess))
|
|
787
787
|
], PermissionFacts);
|
|
788
788
|
export { PermissionFacts };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type DeviceProvider } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
3
3
|
/** The kernel-internal provider of connected machines (local devices). */
|
|
4
4
|
export declare const LOCAL_PROVIDER = "@local";
|
|
5
5
|
/**
|
|
6
6
|
* A kernel-internal provider name: it starts with `@`, which no extension name can
|
|
7
|
-
* (`EXTENSION_NAME_RE`), so it never collides with a loaded `
|
|
7
|
+
* (`EXTENSION_NAME_RE`), so it never collides with a loaded `device-provider@1` plugin.
|
|
8
8
|
*/
|
|
9
9
|
export declare const isInternalProvider: (name: string) => boolean;
|
|
10
10
|
/**
|
|
@@ -23,11 +23,12 @@ export interface SandboxInstanceBinder {
|
|
|
23
23
|
*/
|
|
24
24
|
bind(deviceId: string, signal: AbortSignal): Promise<unknown>;
|
|
25
25
|
}
|
|
26
|
-
/** A
|
|
27
|
-
export interface
|
|
26
|
+
/** A device provider: its name (plugin name, or an internal `@…` name) and implementation. */
|
|
27
|
+
export interface DeviceProviderEntry {
|
|
28
28
|
plugin: string;
|
|
29
|
-
version
|
|
30
|
-
|
|
29
|
+
/** The loaded extension's version; a kernel-internal provider reports the kernel version. */
|
|
30
|
+
version: string;
|
|
31
|
+
impl: DeviceProvider;
|
|
31
32
|
/**
|
|
32
33
|
* The staged path's instance binder: the exclusive lifecycle holder binds the generation before
|
|
33
34
|
* it downgrades, and shared use waits for an installed binding. Absent on protocol 2.
|
|
@@ -35,34 +36,32 @@ export interface SandboxProviderEntry {
|
|
|
35
36
|
binder?: SandboxInstanceBinder;
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
|
-
* The
|
|
39
|
+
* The device providers of this process (a registry: which of them serve an org is
|
|
40
|
+
* `DeviceProviderSelection`). A cloud provider is a loaded `device-provider@1` extension,
|
|
39
41
|
* read from the {@link ExtensionRegistry} at every call (providers are ready only after the
|
|
40
|
-
* extension load, and change with installs). Kernel-internal providers (`@local`) are registered
|
|
41
|
-
*
|
|
42
|
+
* extension load, and change with installs). Kernel-internal providers (`@local`) are registered by their
|
|
43
|
+
* module on init, in every replica: they are code, not shared state.
|
|
42
44
|
*
|
|
43
|
-
* Every `
|
|
45
|
+
* Every `device-provider@1` extension is handed out guarded: a network-level failure to reach it is
|
|
44
46
|
* rethrown as `SandboxProviderUnreachableError` (`./unreachable.ts`), so the tools can tell it
|
|
45
47
|
* apart. Internal providers are not: their failures (the device relay's Redis, the machine's
|
|
46
48
|
* connection) are the kernel's own and have their own errors.
|
|
47
49
|
*/
|
|
48
|
-
export declare class
|
|
50
|
+
export declare class DeviceProviders {
|
|
49
51
|
private readonly registry;
|
|
50
52
|
private readonly internal;
|
|
51
53
|
constructor(registry: Pick<ExtensionRegistry, "list">);
|
|
52
54
|
/** Registers a kernel-internal provider (an `@…` name); a later registration replaces it. */
|
|
53
|
-
register(entry:
|
|
54
|
-
/** The cloud provider (the loaded `sandbox@2` extension); undefined without one. */
|
|
55
|
-
cloud(): SandboxProviderEntry | undefined;
|
|
55
|
+
register(entry: DeviceProviderEntry): void;
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
57
|
+
* The provider of a device, from its `devices.provider` (fixed at creation): a registered
|
|
58
|
+
* internal one (`@local`), else the loaded `device-provider@1` extension of that plugin name,
|
|
59
|
+
* on in no org in particular (whether it serves the device's org is
|
|
60
|
+
* `DeviceProviderSelection.isOnInOrg`). Undefined when neither exists, or for a device without
|
|
61
|
+
* a provider (`null`). Never another provider in its place.
|
|
59
62
|
*/
|
|
60
|
-
|
|
63
|
+
forDevice(provider: string | null): DeviceProviderEntry | undefined;
|
|
64
|
+
/** Every loaded `device-provider@1` extension (no internal ones), in registry order: the sweeps. */
|
|
65
|
+
loaded(): DeviceProviderEntry[];
|
|
66
|
+
private guarded;
|
|
61
67
|
}
|
|
62
|
-
/**
|
|
63
|
-
* The provider a device works with, from its `devices.provider`: an internal one
|
|
64
|
-
* (`@local`) by that name only, never falling back to the cloud provider; any other device
|
|
65
|
-
* is a cloud device and uses the current cloud provider (files kept by another provider are
|
|
66
|
-
* refused by the sandbox service, `device.unavailable`).
|
|
67
|
-
*/
|
|
68
|
-
export declare function providerForDevice(providers: Pick<SandboxProviders, "cloud" | "forName">, provider: string | null): SandboxProviderEntry | undefined;
|