@capybara-hq/kernel 0.1.0-rc.49 → 0.1.0-rc.50
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/admin/admin.schemas.d.ts +0 -6
- package/dist/background/launch.d.ts +7 -61
- package/dist/background/launch.js +8 -133
- package/dist/background/poll.job.d.ts +19 -23
- package/dist/background/poll.job.js +30 -66
- package/dist/background/render.d.ts +9 -0
- package/dist/background/render.js +19 -0
- package/dist/background/session.d.ts +3 -66
- package/dist/background/session.js +3 -114
- package/dist/background/stop.d.ts +26 -33
- package/dist/background/stop.js +59 -90
- package/dist/background/store.d.ts +26 -60
- package/dist/background/store.js +23 -108
- package/dist/background/tasks.service.d.ts +9 -29
- package/dist/background/tasks.service.js +18 -115
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/channels/cards.d.ts +3 -0
- package/dist/channels/cards.js +29 -2
- package/dist/channels/phrases.d.ts +35 -0
- package/dist/channels/phrases.js +32 -0
- package/dist/config/load.d.ts +3 -10
- package/dist/config/load.js +26 -21
- package/dist/config/schema.js +3 -3
- package/dist/conversations/events.d.ts +45 -2
- package/dist/conversations/events.js +44 -4
- package/dist/db/kernel-schema.d.ts +9 -4
- package/dist/devices/devices.service.js +1 -1
- package/dist/devices/errors.d.ts +5 -0
- package/dist/devices/errors.js +5 -0
- package/dist/devices/project-rules.d.ts +2 -2
- package/dist/errors.d.ts +9 -11
- package/dist/errors.js +9 -11
- package/dist/identity/settings.d.ts +4 -17
- package/dist/identity/settings.js +9 -32
- package/dist/infra/config/kernel-config.service.js +2 -9
- package/dist/infra/outbox/registry.d.ts +13 -0
- package/dist/infra/outbox/registry.js +8 -0
- package/dist/local-devices/device-auth.controller.d.ts +1 -1
- package/dist/local-devices/device-auth.controller.js +1 -1
- package/dist/local-devices/device-auth.d.ts +4 -3
- package/dist/local-devices/device-auth.js +1 -1
- package/dist/local-devices/device-policy.service.d.ts +6 -6
- package/dist/local-devices/device-routes.d.ts +4 -2
- package/dist/local-devices/device-routes.js +7 -6
- package/dist/local-devices/instance-bindings.d.ts +4 -4
- package/dist/local-devices/instance-bindings.js +2 -2
- package/dist/local-devices/local-device-gateway.d.ts +12 -12
- package/dist/local-devices/local-device-gateway.js +94 -129
- package/dist/local-devices/local-device-provider.d.ts +19 -87
- package/dist/local-devices/local-device-provider.js +43 -158
- package/dist/local-devices/local-devices.module.d.ts +4 -5
- package/dist/local-devices/local-devices.module.js +6 -9
- package/dist/local-devices/machines.d.ts +6 -6
- package/dist/local-devices/machines.js +4 -4
- package/dist/local-devices/owner-report.d.ts +3 -3
- package/dist/local-devices/owner-report.js +4 -4
- package/dist/local-devices/owner-reports.js +2 -2
- package/dist/local-devices/policy-summary.js +2 -2
- package/dist/local-devices/relay.d.ts +12 -25
- package/dist/local-devices/relay.js +17 -31
- package/dist/orgs/settings.controller.d.ts +1 -4
- package/dist/orgs/settings.controller.js +3 -3
- package/dist/orgs/settings.service.d.ts +7 -21
- package/dist/orgs/settings.service.js +16 -40
- package/dist/overrides.d.ts +3 -3
- package/dist/platform/ops/admin.ops.js +6 -8
- package/dist/platform/ops/org-settings.ops.js +4 -4
- package/dist/platform/ops/orgs.ops.js +0 -1
- package/dist/runtime/maintenance.d.ts +1 -1
- package/dist/runtime/maintenance.js +7 -1
- package/dist/runtime/run-steps.js +2 -2
- package/dist/sandbox/held-operations.d.ts +7 -0
- package/dist/sandbox/held-operations.js +25 -1
- package/dist/sandbox/leases.d.ts +6 -3
- package/dist/sandbox/leases.js +16 -10
- package/dist/sandbox/legacy-retirement.d.ts +0 -19
- package/dist/sandbox/legacy-retirement.js +6 -37
- package/dist/sandbox/managed-device-context.d.ts +12 -0
- package/dist/sandbox/managed-device-context.js +49 -1
- package/dist/sandbox/modes.d.ts +9 -8
- package/dist/sandbox/modes.js +4 -15
- package/dist/sandbox/operation-authority-types.d.ts +18 -1
- package/dist/sandbox/operation-authority-types.js +20 -1
- package/dist/sandbox/operation-authority.d.ts +14 -0
- package/dist/sandbox/operation-authority.js +120 -18
- package/dist/sandbox/operation-intents.d.ts +43 -0
- package/dist/sandbox/operation-intents.js +107 -4
- package/dist/sandbox/operation-reconcile.job.d.ts +12 -1
- package/dist/sandbox/operation-reconcile.job.js +53 -6
- package/dist/sandbox/permission-call-grants.d.ts +4 -0
- package/dist/sandbox/permission-call-grants.js +32 -3
- package/dist/sandbox/permission-call-types.d.ts +27 -2
- package/dist/sandbox/permission-ceiling-writes.js +2 -1
- package/dist/sandbox/permission-context-types.d.ts +2 -2
- package/dist/sandbox/permission-context-types.js +2 -2
- package/dist/sandbox/permission-facts.js +10 -2
- package/dist/sandbox/platform-full-access.d.ts +8 -26
- package/dist/sandbox/platform-full-access.js +8 -20
- package/dist/sandbox/review/classifier.d.ts +2 -2
- package/dist/sandbox/review/classifier.js +18 -5
- package/dist/sandbox/review/permission-candidate.d.ts +59 -3
- package/dist/sandbox/review/permission-candidate.js +192 -25
- package/dist/sandbox/review/review.service.d.ts +18 -0
- package/dist/sandbox/review/review.service.js +158 -12
- package/dist/sandbox/sandbox.service.d.ts +71 -47
- package/dist/sandbox/sandbox.service.js +234 -133
- package/dist/tools/approvals.service.d.ts +6 -1
- package/dist/tools/approvals.service.js +10 -0
- package/dist/tools/builtins/builtin-tools.d.ts +1 -4
- package/dist/tools/builtins/builtin-tools.js +13 -18
- package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
- package/dist/tools/builtins/sandbox/bash.js +92 -270
- package/dist/tools/builtins/sandbox/common.d.ts +15 -9
- package/dist/tools/builtins/sandbox/common.js +55 -19
- package/dist/tools/builtins/sandbox/device-owner.d.ts +13 -0
- package/dist/tools/builtins/sandbox/device-owner.js +14 -0
- package/dist/tools/builtins/sandbox/task-list.js +2 -2
- package/dist/tools/builtins/sandbox/task-output.d.ts +14 -57
- package/dist/tools/builtins/sandbox/task-output.js +88 -210
- package/dist/tools/builtins/sandbox/task-stop.d.ts +2 -2
- package/dist/tools/builtins/sandbox/task-stop.js +15 -26
- package/dist/tools/pipeline.d.ts +31 -2
- package/dist/tools/pipeline.js +273 -43
- package/dist/tools/registry.d.ts +7 -0
- package/package.json +4 -4
- package/src/migrations/0162_permission_call_escalation.sql +9 -0
- package/dist/background/status.d.ts +0 -35
- package/dist/background/status.js +0 -57
|
@@ -7,7 +7,6 @@ export type { HeldProvider } from "./held-operations.js";
|
|
|
7
7
|
import { type ExecResult, type SandboxHandle, type SandboxLimits, type SandboxProvider, type SandboxRoots } from "@capybara-hq/plugin-sdk";
|
|
8
8
|
import type { Redis } from "ioredis";
|
|
9
9
|
import { type Selectable } from "kysely";
|
|
10
|
-
import { BackgroundTaskStore } from "../background/store.js";
|
|
11
10
|
import type { KernelConfig } from "../config/schema.js";
|
|
12
11
|
import type { DeviceInstancesTable } from "../db/kernel-schema.js";
|
|
13
12
|
import { ApiError } from "../errors.js";
|
|
@@ -216,15 +215,17 @@ export declare const replaceRequired: () => ApiError;
|
|
|
216
215
|
* `gone`, the instance was destroyed, or `fn` throws `SandboxGoneError` (retried once), a new
|
|
217
216
|
* instance is created on the kept files and `restarted` is true. Several holders hitting `gone`
|
|
218
217
|
* together rebuild once: the others find the new instance.
|
|
219
|
-
* - **Takeover** (spec §10.5;
|
|
220
|
-
* `capk:sandbox-holders:<env>` (again before each `exec`) and
|
|
221
|
-
* as
|
|
222
|
-
* that holder's
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
218
|
+
* - **Takeover** (spec §10.5; permission runtime cutover B-1): every holder records itself in
|
|
219
|
+
* `capk:sandbox-holders:<env>` (again before each `exec`), and the operations it admits carry
|
|
220
|
+
* its lease token as their holder. An acquirer that finds a record without a live lease (a
|
|
221
|
+
* crashed holder) revokes exactly that holder's operations, never by a broad kill: the
|
|
222
|
+
* revocation is owed durably (an outbox row per token) before the record is forgotten, runs
|
|
223
|
+
* inline, and the owed operation revokes of the instance are delivered by operation id. Under
|
|
224
|
+
* the exclusive lease, on an instance just resumed from `suspended` (nobody else holds it; a
|
|
225
|
+
* provider that keeps memory across a pause brings old work back), every started-or-unknown
|
|
226
|
+
* operation of that generation is revoked too, before the row says running. Nothing is ever
|
|
227
|
+
* `killAll`ed or `killTagged`. Inline delivery failures are only warned: the revoke jobs keep
|
|
228
|
+
* them owed.
|
|
228
229
|
* - **Instance identity**: a holder that hits `gone` names the instance by its handle and the
|
|
229
230
|
* row's `created_at` (set by the fenced write after each `create`); the handle alone is the same
|
|
230
231
|
* after a rebuild on providers whose handle is the instance name (sandbox-docker).
|
|
@@ -260,8 +261,6 @@ export declare class SandboxService {
|
|
|
260
261
|
private readonly providers;
|
|
261
262
|
private readonly config;
|
|
262
263
|
private readonly log;
|
|
263
|
-
/** Background tasks lost while their process may live on (killed after a resume). */
|
|
264
|
-
private readonly background;
|
|
265
264
|
private readonly facts;
|
|
266
265
|
private readonly operationIntents;
|
|
267
266
|
private readonly authority;
|
|
@@ -274,9 +273,7 @@ export declare class SandboxService {
|
|
|
274
273
|
/** The record of the instance each holder last used (`capk:sandbox-seen:…`). */
|
|
275
274
|
redis: Pick<Redis, "get" | "set" | "getdel">, leases: SandboxLeases,
|
|
276
275
|
/** The providers (read at every call: providers are ready after the extension load). */
|
|
277
|
-
providers: Pick<SandboxProviders, "cloud" | "forName">, config: Pick<KernelConfigService, "get" | "fieldSource">, log: Pick<KernelLogger, "info" | "warn">,
|
|
278
|
-
/** Background tasks lost while their process may live on (killed after a resume). */
|
|
279
|
-
background: Pick<BackgroundTaskStore, "pendingKills" | "clearKill">, facts: Pick<PermissionFacts, "devicePolicy" | "assertCloudReconciled" | "readHeldEnvironment">, operationIntents: SandboxOperationIntents, authority: SandboxOperationAuthority, instanceWrites: PermissionInstanceWrites,
|
|
276
|
+
providers: Pick<SandboxProviders, "cloud" | "forName">, config: Pick<KernelConfigService, "get" | "fieldSource">, log: Pick<KernelLogger, "info" | "warn">, facts: Pick<PermissionFacts, "devicePolicy" | "assertCloudReconciled" | "readHeldEnvironment">, operationIntents: SandboxOperationIntents, authority: SandboxOperationAuthority, instanceWrites: PermissionInstanceWrites,
|
|
280
277
|
/** The retirement obligations every lifecycle acquisition is gated on (8.5). */
|
|
281
278
|
retirement: Pick<LegacyRetirementStore, "unresolved" | "hasUnresolved" | "settleRebooted" | "scanUntilStable" | "frozen" | "frozenAt" | "quarantine" | "noteFailure" | "resolveDestroyed" | "resolveCancelled" | "membersOf" | "recordDestruction" | "destructionRecorded">,
|
|
282
279
|
/** The cloud snapshot writer's reconcile, for the lifecycle reconcile of marked devices (B-12). */
|
|
@@ -390,8 +387,8 @@ export declare class SandboxService {
|
|
|
390
387
|
* creates, resumes or rebuilds one: an instance that is missing, suspended, being created or
|
|
391
388
|
* destroyed (or recorded with another provider) is `not_running`, one that records another
|
|
392
389
|
* instance is `other_instance`. Otherwise `fn` runs under a shared lease, as a `withSandbox`
|
|
393
|
-
* holder does (its tag on every exec, crashed holders'
|
|
394
|
-
* moves forward when it ends. Waits for the lease up to `sandbox.lockWaitSeconds`
|
|
390
|
+
* holder does (its tag on every exec, crashed holders' operations revoked exactly), and
|
|
391
|
+
* `last_used_at` moves forward when it ends. Waits for the lease up to `sandbox.lockWaitSeconds`
|
|
395
392
|
* (`sandbox.busy`); `signal` (optional) ends the wait with its abort reason. The signal passed
|
|
396
393
|
* to `fn` aborts with `signal` or when the lease is lost. Errors of `fn` (`SandboxGoneError`
|
|
397
394
|
* too) are thrown as they are.
|
|
@@ -457,6 +454,14 @@ export declare class SandboxService {
|
|
|
457
454
|
deviceId: string;
|
|
458
455
|
accountId: string;
|
|
459
456
|
}, signal: AbortSignal): Promise<void>;
|
|
457
|
+
/**
|
|
458
|
+
* Makes the device's instance run for a managed call before its permission review reads the
|
|
459
|
+
* device's facts: the lifecycle `enter` the call's own use takes (the exclusive lease creates
|
|
460
|
+
* or resumes the instance through the retirement gate, the binding, the limits and fencing, and
|
|
461
|
+
* records a cloud instance's permission evidence), then the lease is left at once. Nothing runs
|
|
462
|
+
* in it; what the start caused is kept for the holder's next use to tell (as a silent use).
|
|
463
|
+
*/
|
|
464
|
+
ensureRunning(use: SandboxUseContext, signal: AbortSignal): Promise<void>;
|
|
460
465
|
/**
|
|
461
466
|
* A run start's kernel read of the bound project (permission activation L2, Hook 1): the use
|
|
462
467
|
* a tool call's would be (the instance made or resumed, the read silent for the holder), whose
|
|
@@ -566,27 +571,62 @@ export declare class SandboxService {
|
|
|
566
571
|
private usable;
|
|
567
572
|
/**
|
|
568
573
|
* Under a just-taken shared lease: confirms the row is still `accept`ed (else releases and
|
|
569
|
-
* returns null), records the holder and
|
|
574
|
+
* returns null), records the holder and revokes crashed holders' operations exactly.
|
|
570
575
|
*/
|
|
571
576
|
private asShared;
|
|
572
577
|
/**
|
|
573
578
|
* Under a just-taken exclusive lease: makes the instance run (file system, create / resume /
|
|
574
|
-
* rebuild when the recorded instance is the one found gone),
|
|
575
|
-
* a shared lease.
|
|
576
|
-
*
|
|
577
|
-
*
|
|
579
|
+
* rebuild when the recorded instance is the one found gone), revokes what crashed holders left,
|
|
580
|
+
* then downgrades to a shared lease. A resumed instance's started-or-unknown operations were
|
|
581
|
+
* revoked by `ensure` before its row said running; here the crashed holders' records are owed and
|
|
582
|
+
* forgotten and every owed revoke of the instance is delivered (nothing is `killAll`ed).
|
|
578
583
|
*/
|
|
579
584
|
private asExclusive;
|
|
580
585
|
/** Ends a holder: unregisters it before releasing its lease, then moves `last_used_at` forward. */
|
|
581
586
|
private leave;
|
|
582
587
|
private register;
|
|
583
588
|
private unregister;
|
|
584
|
-
/**
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
589
|
+
/**
|
|
590
|
+
* The crashed holders' cleanup (permission runtime cutover B-1): their tokens are read without
|
|
591
|
+
* removing them, their revocation is owed durably ({@link oweDeadHolders}), it runs inline
|
|
592
|
+
* (`revokeHolders`), and the owed operation revokes of the instance are delivered by operation id
|
|
593
|
+
* ({@link deliverRevocations}). `delivered`: a resume under the exclusive lease, which delivers
|
|
594
|
+
* the revokes `ensure` owed on the incarnation even with no crashed holder. A failure after the
|
|
595
|
+
* revocation is owed is only warned (the outbox retries it); gone and abort are thrown.
|
|
596
|
+
*/
|
|
597
|
+
private takeOver;
|
|
598
|
+
/**
|
|
599
|
+
* Crashed holders' tokens whose revocation is now owed durably: read without removing them, an
|
|
600
|
+
* outbox row per token committed ({@link SandboxOperationIntents.oweHolderRevocations}), then
|
|
601
|
+
* their records forgotten. A Redis or database error leaves the records for the next acquirer
|
|
602
|
+
* and counts as none.
|
|
603
|
+
*/
|
|
604
|
+
private oweDeadHolders;
|
|
605
|
+
/**
|
|
606
|
+
* The exact cleanup of an incarnation nobody else holds (exclusive lease), in place of a broad
|
|
607
|
+
* `killAll`: revokes its started-or-unknown operations
|
|
608
|
+
* ({@link SandboxOperationIntents.revokeIncarnation}) and delivers the owed revokes. Thrown when
|
|
609
|
+
* the revocation cannot be recorded (`strict`), else only warned: the caller's row still says
|
|
610
|
+
* suspended, so the next resume revokes again.
|
|
611
|
+
*/
|
|
612
|
+
private revokeIncarnation;
|
|
613
|
+
/**
|
|
614
|
+
* Delivers the owed operation revokes of one instance generation inline, by operation id
|
|
615
|
+
* (`revokeOperation`), acknowledging each: what the revoke jobs would deliver, sent before this
|
|
616
|
+
* holder runs anything. Best effort, as the broad `killAll` it replaces was: at most
|
|
617
|
+
* {@link INLINE_REVOKE_LIMIT} per call, nothing for a provider without `revokeOperation`, and any
|
|
618
|
+
* failure only warned. Durability does not depend on it: every revocation wrote its
|
|
619
|
+
* `sandbox-operation-revoke-<operationId>` outbox job in the same transaction, and those jobs
|
|
620
|
+
* deliver until acknowledged. Gone and abort are thrown (the use rebuilds / ends).
|
|
621
|
+
*/
|
|
622
|
+
private deliverRevocations;
|
|
623
|
+
/** The {@link RevokedIncarnation} of an instance row. */
|
|
624
|
+
private incarnationOf;
|
|
625
|
+
/**
|
|
626
|
+
* The owed revocation job of one crashed holder (`sandbox-holder-revoke`): revokes its intents
|
|
627
|
+
* still admitted, dispatching or started-or-unknown and owes each its exact revoke job.
|
|
628
|
+
*/
|
|
629
|
+
revokeDeadHolder(deviceId: string, token: string): Promise<void>;
|
|
590
630
|
/**
|
|
591
631
|
* Suspends running instances idle longer than `suspendAfterIdleMinutes` or running continuously
|
|
592
632
|
* longer than `maxRunningMinutes`. Skips a device with any holder; one past
|
|
@@ -639,8 +679,8 @@ export declare class SandboxService {
|
|
|
639
679
|
* gate's alone (never resumed here). When the
|
|
640
680
|
* marker stays on a live instance whose provider can `update`, the provider applies the
|
|
641
681
|
* reconcile target, which is never wider than the instance in any dimension, so this only
|
|
642
|
-
* narrows; a suspended instance is resumed for it (its leftover
|
|
643
|
-
* holds it) and suspended again, as its row still says. `updated` records the target as
|
|
682
|
+
* narrows; a suspended instance is resumed for it (its leftover operations revoked exactly,
|
|
683
|
+
* nobody else holds it) and suspended again, as its row still says. `updated` records the target as
|
|
644
684
|
* applied (fenced) and the reconcile runs again, which clears the marker. No `update`, a
|
|
645
685
|
* `recreate` answer, a gone instance or a failure leave the marker and its file reset action.
|
|
646
686
|
*/
|
|
@@ -676,22 +716,6 @@ export declare class SandboxService {
|
|
|
676
716
|
* Returns the row as it is afterwards.
|
|
677
717
|
*/
|
|
678
718
|
private retireIncarnations;
|
|
679
|
-
/**
|
|
680
|
-
* Under the exclusive lease (before the downgrade), on an instance just resumed from
|
|
681
|
-
* `suspended`: kills every command left in it (`killAll`), crashed holders' (`dead`, already
|
|
682
|
-
* claimed) included. Never on the shared path: other holders may be running commands. A gone
|
|
683
|
-
* instance (`SandboxGoneError`) and an abort are thrown (`withSandbox` rebuilds / ends); other
|
|
684
|
-
* failures are only warned.
|
|
685
|
-
*/
|
|
686
|
-
private killLeftovers;
|
|
687
|
-
/**
|
|
688
|
-
* Under the exclusive lease, right after a resume or a (re)build: kills the sessions of the
|
|
689
|
-
* background tasks marked lost while their process may live on (`kill_pending`), in one exec of
|
|
690
|
-
* `pkill -KILL -s <sid>` (`-g` on macOS), then clears their flags. Tasks of another instance have no process
|
|
691
|
-
* here and are only cleared. A gone instance and an abort are thrown; another failure is warned
|
|
692
|
-
* and leaves the flags of this instance's tasks for the next resume.
|
|
693
|
-
*/
|
|
694
|
-
private killPendingTasks;
|
|
695
719
|
/**
|
|
696
720
|
* A fenced write: only while the lease holds and the row's generation is still the one read
|
|
697
721
|
* under it (and incremented); otherwise {@link SandboxLockLostError}.
|
|
@@ -737,7 +761,7 @@ export declare class SandboxService {
|
|
|
737
761
|
private applyLimits;
|
|
738
762
|
/**
|
|
739
763
|
* After a failed `update` that cannot be repaired by a recreate: best effort, with fresh short
|
|
740
|
-
* signals (the use's own may be aborted), suspends the instance (or
|
|
764
|
+
* signals (the use's own may be aborted), suspends the instance (or revokes its operations) and
|
|
741
765
|
* records it suspended (fenced: a lost lease leaves the record to the new holder).
|
|
742
766
|
*/
|
|
743
767
|
private quarantine;
|