@capybara-hq/kernel 0.1.0-rc.105 → 0.1.0-rc.107
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 +3 -0
- 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 +7 -6
- package/dist/channels/file-delivery.d.ts +26 -11
- package/dist/channels/file-delivery.js +32 -11
- package/dist/channels/outbound.d.ts +8 -8
- package/dist/channels/outbound.js +32 -30
- package/dist/channels/threads.d.ts +1 -1
- package/dist/channels/threads.js +1 -1
- package/dist/config/schema.d.ts +8 -1
- package/dist/config/schema.js +56 -6
- package/dist/conversations/approval-profile.d.ts +2 -2
- package/dist/conversations/approval-profile.js +3 -3
- package/dist/conversations/artifacts.d.ts +20 -17
- package/dist/conversations/artifacts.js +30 -37
- package/dist/conversations/attachments.controller.d.ts +6 -19
- package/dist/conversations/attachments.controller.js +8 -59
- package/dist/conversations/attachments.service.d.ts +30 -74
- package/dist/conversations/attachments.service.js +51 -193
- package/dist/conversations/conversations.controller.d.ts +7 -1
- package/dist/conversations/conversations.controller.js +26 -10
- package/dist/conversations/conversations.module.js +4 -0
- package/dist/conversations/conversations.service.d.ts +112 -35
- package/dist/conversations/conversations.service.js +160 -43
- package/dist/conversations/event-log.d.ts +1 -0
- package/dist/conversations/events.d.ts +95 -27
- package/dist/conversations/events.js +108 -10
- package/dist/conversations/files.d.ts +66 -64
- package/dist/conversations/files.js +127 -147
- 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 +4 -2
- package/dist/conversations/prompt-suggestions.d.ts +3 -3
- package/dist/conversations/prompt-suggestions.js +11 -10
- 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 +27 -16
- package/dist/ctx/create-ctx.d.ts +23 -2
- package/dist/ctx/create-ctx.js +78 -3
- package/dist/db/kernel-schema.d.ts +184 -27
- 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 +53 -13
- package/dist/errors.js +53 -13
- package/dist/evals/canonical-json.d.ts +7 -0
- package/dist/evals/canonical-json.js +21 -0
- package/dist/evals/reconstruct.d.ts +10 -1
- package/dist/evals/reconstruct.js +20 -1
- package/dist/evals/recorded-tools.d.ts +0 -2
- package/dist/evals/recorded-tools.js +1 -16
- package/dist/evals/snapshot.d.ts +26 -3
- package/dist/evals/snapshot.js +110 -57
- package/dist/evals/worker.d.ts +4 -3
- package/dist/evals/worker.js +8 -4
- package/dist/extensions/host.d.ts +9 -2
- package/dist/extensions/host.js +12 -0
- package/dist/extensions/instance.d.ts +3 -1
- package/dist/extensions/instance.js +4 -0
- package/dist/extensions/ledger.d.ts +1 -1
- 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/files/blob-objects.d.ts +124 -0
- package/dist/files/blob-objects.js +341 -0
- package/dist/files/blob-sweep.job.d.ts +122 -0
- package/dist/files/blob-sweep.job.js +389 -0
- package/dist/files/blobs.service.d.ts +135 -0
- package/dist/files/blobs.service.js +300 -0
- package/dist/files/conversation-media.d.ts +41 -0
- package/dist/files/conversation-media.js +124 -0
- package/dist/files/deliveries.d.ts +64 -0
- package/dist/files/deliveries.js +156 -0
- package/dist/files/deliveries.module.d.ts +6 -0
- package/dist/files/deliveries.module.js +24 -0
- package/dist/files/draft-cleanup.job.d.ts +26 -0
- package/dist/files/draft-cleanup.job.js +93 -0
- package/dist/files/files.module.d.ts +1 -1
- package/dist/files/files.module.js +3 -2
- package/dist/files/hash-job.d.ts +127 -0
- package/dist/files/hash-job.js +447 -0
- package/dist/files/library-backfill.d.ts +63 -0
- package/dist/files/library-backfill.js +143 -0
- package/dist/files/library-files.service.d.ts +255 -0
- package/dist/files/library-files.service.js +883 -0
- package/dist/files/library-jobs.module.d.ts +8 -0
- package/dist/files/library-jobs.module.js +27 -0
- package/dist/files/library-query.d.ts +127 -0
- package/dist/files/library-query.js +322 -0
- package/dist/files/library-read.module.d.ts +9 -0
- package/dist/files/library-read.module.js +30 -0
- package/dist/files/library.controller.d.ts +77 -0
- package/dist/files/library.controller.js +235 -0
- package/dist/files/library.module.d.ts +9 -0
- package/dist/files/library.module.js +29 -0
- package/dist/files/library.schemas.d.ts +46 -0
- package/dist/files/library.schemas.js +49 -0
- package/dist/files/previewers.controller.d.ts +20 -0
- package/dist/files/previewers.controller.js +47 -0
- package/dist/files/previewers.d.ts +25 -11
- package/dist/files/previewers.js +43 -27
- package/dist/files/referenced-files.d.ts +150 -0
- package/dist/files/referenced-files.js +234 -0
- package/dist/git/gateway.js +2 -2
- package/dist/html/html-document.controller.d.ts +8 -1
- package/dist/html/html-document.controller.js +19 -1
- package/dist/html/html-document.service.d.ts +19 -4
- package/dist/html/html-document.service.js +43 -22
- package/dist/html/html-token.d.ts +10 -1
- package/dist/html/html-token.js +14 -0
- package/dist/html/html.module.js +8 -1
- package/dist/http/api.module.js +10 -5
- package/dist/http/request-signal.d.ts +8 -0
- package/dist/http/request-signal.js +14 -0
- package/dist/identity/settings.d.ts +26 -0
- package/dist/identity/settings.js +33 -2
- 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 +111 -2
- package/dist/infra/outbox/registry.js +104 -9
- package/dist/infra/throttler/named-throttlers.d.ts +2 -0
- package/dist/infra/throttler/named-throttlers.js +14 -0
- package/dist/kernel.module.js +3 -0
- package/dist/lifecycle/kernel-lifecycle.js +6 -0
- package/dist/models/purposes.js +1 -1
- package/dist/orgs/offboarding.js +1 -1
- 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 +75 -13
- package/dist/orgs/settings.service.js +104 -26
- package/dist/platform/exclusions.js +45 -8
- package/dist/platform/file-ref.d.ts +18 -3
- package/dist/platform/file-ref.js +22 -11
- package/dist/platform/operation.js +6 -2
- package/dist/platform/ops/admin.ops.js +5 -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/files.ops.d.ts +18 -0
- package/dist/platform/ops/files.ops.js +267 -0
- package/dist/platform/ops/inbox.ops.js +4 -4
- package/dist/platform/ops/org-settings.ops.js +6 -2
- package/dist/platform/ops/orgs.ops.js +2 -1
- package/dist/platform/ops/platform.ops.js +4 -4
- package/dist/platform/ops/shares.ops.js +2 -2
- package/dist/platform/platform-ops.module.d.ts +3 -2
- package/dist/platform/platform-ops.module.js +10 -5
- package/dist/platform/route-schemas.js +6 -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 +18 -4
- package/dist/runtime/compaction-settings.service.d.ts +13 -1
- package/dist/runtime/compaction-settings.service.js +16 -1
- package/dist/runtime/compaction.service.d.ts +3 -1
- package/dist/runtime/compaction.service.js +3 -1
- package/dist/runtime/context/build.d.ts +24 -1
- package/dist/runtime/context/build.js +33 -11
- package/dist/runtime/context/cache-expiry.d.ts +31 -0
- package/dist/runtime/context/cache-expiry.js +60 -0
- package/dist/runtime/context/cache-ttl.d.ts +18 -0
- package/dist/runtime/context/cache-ttl.js +30 -0
- package/dist/runtime/context/compaction.d.ts +9 -2
- package/dist/runtime/context/compaction.js +64 -21
- package/dist/runtime/context/in-context-compaction.d.ts +156 -0
- package/dist/runtime/context/in-context-compaction.js +310 -0
- package/dist/runtime/context/run-context.d.ts +38 -0
- package/dist/runtime/context/run-context.js +54 -0
- package/dist/runtime/hook-calls.d.ts +2 -1
- package/dist/runtime/hook-calls.js +5 -2
- package/dist/runtime/maintenance.d.ts +16 -4
- package/dist/runtime/maintenance.js +79 -18
- package/dist/runtime/model-call.d.ts +34 -5
- package/dist/runtime/model-call.js +207 -22
- package/dist/runtime/providers.js +11 -1
- 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-steps.d.ts +4 -2
- package/dist/runtime/run-steps.js +10 -5
- package/dist/runtime/run-worker.js +7 -1
- package/dist/runtime/runtime.module.js +6 -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/shares/liveness.d.ts +26 -12
- package/dist/shares/liveness.js +79 -20
- package/dist/shares/revoke.d.ts +16 -11
- package/dist/shares/revoke.js +18 -14
- package/dist/shares/share-objects.d.ts +16 -21
- package/dist/shares/share-objects.js +25 -55
- package/dist/shares/share-open.service.d.ts +8 -4
- package/dist/shares/share-open.service.js +14 -11
- package/dist/shares/shares.controller.d.ts +16 -5
- package/dist/shares/shares.controller.js +39 -5
- package/dist/shares/shares.module.d.ts +4 -4
- package/dist/shares/shares.module.js +7 -6
- package/dist/shares/shares.schemas.d.ts +4 -0
- package/dist/shares/shares.schemas.js +2 -0
- package/dist/shares/shares.service.d.ts +93 -54
- package/dist/shares/shares.service.js +292 -131
- package/dist/shares/sweep.job.d.ts +18 -39
- package/dist/shares/sweep.job.js +47 -206
- 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/artifacts.d.ts +21 -13
- package/dist/tools/builtins/artifacts.js +81 -51
- 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 +15 -9
- package/dist/tools/builtins/builtin-tools.js +33 -22
- package/dist/tools/builtins/conversation-files.d.ts +23 -13
- package/dist/tools/builtins/conversation-files.js +62 -83
- package/dist/tools/builtins/image/generate.d.ts +7 -1
- package/dist/tools/builtins/image/generate.js +1 -1
- package/dist/tools/builtins/platform.js +1 -0
- package/dist/tools/builtins/sandbox/common.d.ts +6 -2
- package/dist/tools/builtins/sandbox/deliver.js +6 -7
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +6 -5
- package/dist/tools/builtins/sandbox/fetch-attachment.js +19 -12
- 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 +15 -9
- package/dist/ui/call-extension.d.ts +6 -4
- package/dist/ui/call-extension.js +5 -4
- package/dist/ui/embed-token.js +6 -3
- package/dist/ui/registry.d.ts +21 -5
- package/dist/ui/registry.js +24 -6
- package/dist/ui/ui.schemas.d.ts +22 -0
- package/dist/ui/ui.schemas.js +22 -4
- package/dist/ui/views.controller.d.ts +13 -3
- package/dist/ui/views.controller.js +33 -2
- package/dist/ui/views.d.ts +29 -1
- package/dist/ui/views.js +131 -7
- package/package.json +3 -3
- package/src/migrations/0188_automations_rename.sql +309 -0
- package/src/migrations/0189_event_automations.sql +136 -0
- package/src/migrations/0190_file_library.sql +285 -0
- package/src/migrations/0191_file_library_copy.sql +4 -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
|
@@ -1,56 +1,41 @@
|
|
|
1
1
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
2
2
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
3
3
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
4
|
-
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
5
4
|
import type { KernelLogger } from "../log.js";
|
|
6
|
-
import { StorageService } from "../storage/storage.service.js";
|
|
7
|
-
import { ShareObjects } from "./share-objects.js";
|
|
8
5
|
/** The daily share sweep's name (scheduler key and lock; no `:`). */
|
|
9
6
|
export declare const SHARE_SWEEP_JOB = "share-sweep";
|
|
10
7
|
/** When the daily share sweep runs (the deployment's time zone). */
|
|
11
8
|
export declare const SHARE_SWEEP_CRON = "40 3 * * *";
|
|
9
|
+
/** Shares expired or revoked longer ago than this stop pointing at their blob (rows kept). */
|
|
10
|
+
export declare const RETAIN_DAYS = 7;
|
|
12
11
|
/** What one sweep did (logged; returned for tests). */
|
|
13
12
|
export interface ShareSweepResult {
|
|
14
|
-
/** Shares revoked with `creator_lost_access
|
|
13
|
+
/** Shares revoked with `creator_lost_access`. */
|
|
15
14
|
revoked: number;
|
|
16
|
-
/**
|
|
15
|
+
/** Shares expired or revoked more than {@link RETAIN_DAYS} days ago that let go of their blob. */
|
|
17
16
|
freed: number;
|
|
18
|
-
/** Orphan objects under `shares/` deleted. */
|
|
19
|
-
orphans: number;
|
|
20
17
|
}
|
|
21
18
|
/**
|
|
22
|
-
* The daily share sweep (file sharing spec §9), a `@LockedCron` (once per
|
|
23
|
-
* provided only under `WorkerModule`). In order
|
|
19
|
+
* The daily share sweep (file sharing spec §9, file library spec §7), a `@LockedCron` (once per
|
|
20
|
+
* tick across replicas, provided only under `WorkerModule`). In order:
|
|
24
21
|
*
|
|
25
22
|
* 1. revokes with `creator_lost_access` the unrevoked, unexpired shares whose creator fails the
|
|
26
23
|
* live check's creator predicates (account disabled, no longer a member, agent deleted or hidden,
|
|
27
|
-
* the conversation or its root deleted), one transaction per batch
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* still
|
|
32
|
-
* backstop) and clears `object_key`; the rows stay for the audit trail;
|
|
33
|
-
* 3. per organization not deleted, lists `shares/` and deletes every object older than one hour
|
|
34
|
-
* that is not the `object_key` of its row (no row: an insert that failed after its copy; another
|
|
35
|
-
* generation: a refresh that died between its copy and its commit). An object whose age the
|
|
36
|
-
* store does not report is kept. Its age is read again (`head`) just before the delete, and a
|
|
37
|
-
* non-current generation of an existing share is deleted only under that share's refresh lock
|
|
38
|
-
* (tried once), so a retried refresh writing the same key again is never undone.
|
|
24
|
+
* the conversation or its root deleted), one transaction per batch (the open routes already
|
|
25
|
+
* refuse them; this shows a reason in the lists);
|
|
26
|
+
* 2. frees the shares expired or revoked more than {@link RETAIN_DAYS} days ago: `blob_id` becomes
|
|
27
|
+
* null (the rows stay for the audit trail), so the blob sweep may delete a blob no file or other
|
|
28
|
+
* share still needs. No storage call: the bytes are the blob's.
|
|
39
29
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* organizations are skipped: their objects go with `storage-org-purge`. Nothing is kept in process
|
|
43
|
-
* memory between runs; a run that stops midway (abort, error) is finished by the next one.
|
|
30
|
+
* Deleted organizations are skipped: their objects go with `storage-org-purge`. Nothing is kept in
|
|
31
|
+
* process memory between runs; a run that stops midway (abort, error) is finished by the next one.
|
|
44
32
|
*/
|
|
45
33
|
export declare class ShareSweepJob {
|
|
46
34
|
private readonly db;
|
|
47
35
|
readonly txHost: TransactionHost;
|
|
48
|
-
private readonly outbox;
|
|
49
|
-
private readonly objects;
|
|
50
|
-
private readonly storage;
|
|
51
36
|
readonly lockService: LockService;
|
|
52
37
|
readonly log: KernelLogger;
|
|
53
|
-
constructor(db: KernelDb, txHost: TransactionHost,
|
|
38
|
+
constructor(db: KernelDb, txHost: TransactionHost, lockService: LockService, log: KernelLogger);
|
|
54
39
|
sweep(signal?: AbortSignal): Promise<void>;
|
|
55
40
|
/** One sweep without the tick lock (the cron body; tests call it directly). */
|
|
56
41
|
runOnce(signal?: AbortSignal): Promise<ShareSweepResult>;
|
|
@@ -58,17 +43,11 @@ export declare class ShareSweepJob {
|
|
|
58
43
|
private revokeLostAccess;
|
|
59
44
|
/** One batch of step 1 (the creator's access is checked again in the `UPDATE`). */
|
|
60
45
|
revokeBatch(shareIds: readonly string[]): Promise<number>;
|
|
61
|
-
/** Step 2:
|
|
46
|
+
/** Step 2: lets go of the blobs of shares expired or revoked more than a week ago. */
|
|
62
47
|
private freeOld;
|
|
63
|
-
/** Step 3: deletes the orphan objects under `shares/` of every organization not deleted. */
|
|
64
|
-
private deleteOrphans;
|
|
65
|
-
/** The orphan objects of one organization, page by page. */
|
|
66
|
-
private orphansOf;
|
|
67
48
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
49
|
+
* One batch of step 2 (one org, in its scope): the condition is checked again in the `UPDATE` (expiry is final and a
|
|
50
|
+
* revoke is never undone, so a row read as old is still old).
|
|
70
51
|
*/
|
|
71
|
-
|
|
72
|
-
/** {@link ShareObjects.deleteObject}, logging instead of throwing (one bad object stops nothing). */
|
|
73
|
-
private deleteGuarded;
|
|
52
|
+
freeBatch(orgId: string, shareIds: readonly string[]): Promise<number>;
|
|
74
53
|
}
|
package/dist/shares/sweep.job.js
CHANGED
|
@@ -10,89 +10,58 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { sql } from "kysely";
|
|
12
12
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
13
|
+
import { withOrgScope } from "../infra/database/org-scope.js";
|
|
13
14
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
14
15
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
15
16
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
16
|
-
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
17
17
|
import { LockedCron } from "../infra/schedule/locked-cron.decorator.js";
|
|
18
18
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
19
|
-
import { StorageService } from "../storage/storage.service.js";
|
|
20
19
|
import { creatorStillHasAccess } from "./liveness.js";
|
|
21
20
|
import { revokeSharesIn } from "./revoke.js";
|
|
22
|
-
import { ShareObjects, shareObjectKey, shareRefreshLockKey, } from "./share-objects.js";
|
|
23
21
|
/** The daily share sweep's name (scheduler key and lock; no `:`). */
|
|
24
22
|
export const SHARE_SWEEP_JOB = "share-sweep";
|
|
25
23
|
/** When the daily share sweep runs (the deployment's time zone). */
|
|
26
24
|
export const SHARE_SWEEP_CRON = "40 3 * * *";
|
|
27
|
-
/** Rows per batch (one transaction per batch
|
|
25
|
+
/** Rows per batch (one transaction per batch). */
|
|
28
26
|
const BATCH = 200;
|
|
29
|
-
/**
|
|
30
|
-
const RETAIN_DAYS = 7;
|
|
31
|
-
/** An object under `shares/` no row names is deleted only once it is older than this. */
|
|
32
|
-
const ORPHAN_AGE_MS = 60 * 60 * 1000;
|
|
33
|
-
/** The objects listed per page when looking for orphans. */
|
|
34
|
-
const LIST_PAGE = 1000;
|
|
35
|
-
/** The sweep's hold on a share's refresh lock (tried once; a refresh holding it skips the key). */
|
|
36
|
-
const REFRESH_LOCK_TTL_MS = 30_000;
|
|
27
|
+
/** Shares expired or revoked longer ago than this stop pointing at their blob (rows kept). */
|
|
28
|
+
export const RETAIN_DAYS = 7;
|
|
37
29
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*/
|
|
41
|
-
const SHARE_KEY_RE = /^shares\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/(\d+)$/;
|
|
42
|
-
/**
|
|
43
|
-
* The daily share sweep (file sharing spec §9), a `@LockedCron` (once per tick across replicas,
|
|
44
|
-
* provided only under `WorkerModule`). In order, with every storage call outside a transaction:
|
|
30
|
+
* The daily share sweep (file sharing spec §9, file library spec §7), a `@LockedCron` (once per
|
|
31
|
+
* tick across replicas, provided only under `WorkerModule`). In order:
|
|
45
32
|
*
|
|
46
33
|
* 1. revokes with `creator_lost_access` the unrevoked, unexpired shares whose creator fails the
|
|
47
34
|
* live check's creator predicates (account disabled, no longer a member, agent deleted or hidden,
|
|
48
|
-
* the conversation or its root deleted), one transaction per batch
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* still
|
|
53
|
-
* backstop) and clears `object_key`; the rows stay for the audit trail;
|
|
54
|
-
* 3. per organization not deleted, lists `shares/` and deletes every object older than one hour
|
|
55
|
-
* that is not the `object_key` of its row (no row: an insert that failed after its copy; another
|
|
56
|
-
* generation: a refresh that died between its copy and its commit). An object whose age the
|
|
57
|
-
* store does not report is kept. Its age is read again (`head`) just before the delete, and a
|
|
58
|
-
* non-current generation of an existing share is deleted only under that share's refresh lock
|
|
59
|
-
* (tried once), so a retried refresh writing the same key again is never undone.
|
|
35
|
+
* the conversation or its root deleted), one transaction per batch (the open routes already
|
|
36
|
+
* refuse them; this shows a reason in the lists);
|
|
37
|
+
* 2. frees the shares expired or revoked more than {@link RETAIN_DAYS} days ago: `blob_id` becomes
|
|
38
|
+
* null (the rows stay for the audit trail), so the blob sweep may delete a blob no file or other
|
|
39
|
+
* share still needs. No storage call: the bytes are the blob's.
|
|
60
40
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* organizations are skipped: their objects go with `storage-org-purge`. Nothing is kept in process
|
|
64
|
-
* memory between runs; a run that stops midway (abort, error) is finished by the next one.
|
|
41
|
+
* Deleted organizations are skipped: their objects go with `storage-org-purge`. Nothing is kept in
|
|
42
|
+
* process memory between runs; a run that stops midway (abort, error) is finished by the next one.
|
|
65
43
|
*/
|
|
66
44
|
let ShareSweepJob = class ShareSweepJob {
|
|
67
45
|
db;
|
|
68
46
|
txHost;
|
|
69
|
-
outbox;
|
|
70
|
-
objects;
|
|
71
|
-
storage;
|
|
72
47
|
lockService;
|
|
73
48
|
log;
|
|
74
|
-
constructor(db, txHost,
|
|
49
|
+
constructor(db, txHost, lockService, log) {
|
|
75
50
|
this.db = db;
|
|
76
51
|
this.txHost = txHost;
|
|
77
|
-
this.outbox = outbox;
|
|
78
|
-
this.objects = objects;
|
|
79
|
-
this.storage = storage;
|
|
80
52
|
this.lockService = lockService;
|
|
81
53
|
this.log = log;
|
|
82
54
|
}
|
|
83
55
|
async sweep(signal) {
|
|
84
56
|
const r = await this.runOnce(signal);
|
|
85
|
-
if (r.revoked + r.freed
|
|
57
|
+
if (r.revoked + r.freed > 0)
|
|
86
58
|
this.log.info("share sweep done", { ...r });
|
|
87
59
|
}
|
|
88
60
|
/** One sweep without the tick lock (the cron body; tests call it directly). */
|
|
89
61
|
async runOnce(signal) {
|
|
90
62
|
const revoked = await this.revokeLostAccess(signal);
|
|
91
|
-
if (!this.storage.available)
|
|
92
|
-
return { revoked, freed: 0, orphans: 0 };
|
|
93
63
|
const freed = await this.freeOld(signal);
|
|
94
|
-
|
|
95
|
-
return { revoked, freed, orphans };
|
|
64
|
+
return { revoked, freed };
|
|
96
65
|
}
|
|
97
66
|
/** Step 1: revokes, batch by batch, the shares whose creator lost access. */
|
|
98
67
|
async revokeLostAccess(signal) {
|
|
@@ -105,7 +74,6 @@ let ShareSweepJob = class ShareSweepJob {
|
|
|
105
74
|
.select("file_shares.id")
|
|
106
75
|
.where("orgs.deleted_at", "is", null)
|
|
107
76
|
.where("file_shares.revoked_at", "is", null)
|
|
108
|
-
.where("file_shares.object_key", "is not", null)
|
|
109
77
|
.where((eb) => eb.or([
|
|
110
78
|
eb("file_shares.expires_at", "is", null),
|
|
111
79
|
eb("file_shares.expires_at", ">", sql `now()`),
|
|
@@ -126,9 +94,9 @@ let ShareSweepJob = class ShareSweepJob {
|
|
|
126
94
|
}
|
|
127
95
|
/** One batch of step 1 (the creator's access is checked again in the `UPDATE`). */
|
|
128
96
|
async revokeBatch(shareIds) {
|
|
129
|
-
return revokeSharesIn(this.db.db,
|
|
97
|
+
return revokeSharesIn(this.db.db, { shareIds }, "creator_lost_access");
|
|
130
98
|
}
|
|
131
|
-
/** Step 2:
|
|
99
|
+
/** Step 2: lets go of the blobs of shares expired or revoked more than a week ago. */
|
|
132
100
|
async freeOld(signal) {
|
|
133
101
|
let freed = 0;
|
|
134
102
|
let after = null;
|
|
@@ -137,14 +105,9 @@ let ShareSweepJob = class ShareSweepJob {
|
|
|
137
105
|
const rows = await this.db
|
|
138
106
|
.selectFrom("file_shares")
|
|
139
107
|
.innerJoin("orgs", "orgs.id", "file_shares.org_id")
|
|
140
|
-
.select([
|
|
141
|
-
"file_shares.id",
|
|
142
|
-
"file_shares.org_id",
|
|
143
|
-
"file_shares.generation",
|
|
144
|
-
"file_shares.object_key",
|
|
145
|
-
])
|
|
108
|
+
.select(["file_shares.id", "file_shares.org_id"])
|
|
146
109
|
.where("orgs.deleted_at", "is", null)
|
|
147
|
-
.where("file_shares.
|
|
110
|
+
.where("file_shares.blob_id", "is not", null)
|
|
148
111
|
.where((eb) => eb.or([
|
|
149
112
|
eb("file_shares.revoked_at", "<", old),
|
|
150
113
|
eb.and([
|
|
@@ -158,17 +121,11 @@ let ShareSweepJob = class ShareSweepJob {
|
|
|
158
121
|
.execute();
|
|
159
122
|
if (rows.length === 0)
|
|
160
123
|
break;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
shareId: r.id,
|
|
167
|
-
generation: r.generation,
|
|
168
|
-
objectKey: r.object_key,
|
|
169
|
-
};
|
|
170
|
-
if (await this.deleteGuarded(data))
|
|
171
|
-
freed++;
|
|
124
|
+
const byOrg = new Map();
|
|
125
|
+
for (const r of rows)
|
|
126
|
+
byOrg.set(r.org_id, [...(byOrg.get(r.org_id) ?? []), r.id]);
|
|
127
|
+
for (const [orgId, ids] of byOrg) {
|
|
128
|
+
freed += await withOrgScope(orgId, () => this.freeBatch(orgId, ids));
|
|
172
129
|
}
|
|
173
130
|
after = rows.at(-1).id;
|
|
174
131
|
if (rows.length < BATCH)
|
|
@@ -176,141 +133,25 @@ let ShareSweepJob = class ShareSweepJob {
|
|
|
176
133
|
}
|
|
177
134
|
return freed;
|
|
178
135
|
}
|
|
179
|
-
/** Step 3: deletes the orphan objects under `shares/` of every organization not deleted. */
|
|
180
|
-
async deleteOrphans(signal) {
|
|
181
|
-
let deleted = 0;
|
|
182
|
-
let after = null;
|
|
183
|
-
while (!signal?.aborted) {
|
|
184
|
-
const orgs = await this.db
|
|
185
|
-
.selectFrom("orgs")
|
|
186
|
-
.select("id")
|
|
187
|
-
.where("deleted_at", "is", null)
|
|
188
|
-
.$if(after !== null, (q) => q.where("id", ">", after))
|
|
189
|
-
.orderBy("id")
|
|
190
|
-
.limit(BATCH)
|
|
191
|
-
.execute();
|
|
192
|
-
for (const o of orgs) {
|
|
193
|
-
if (signal?.aborted)
|
|
194
|
-
break;
|
|
195
|
-
try {
|
|
196
|
-
deleted += await this.orphansOf(o.id, signal);
|
|
197
|
-
}
|
|
198
|
-
catch (err) {
|
|
199
|
-
this.log.warn("share sweep: cannot clean orphan snapshots; the next run retries", {
|
|
200
|
-
orgId: o.id,
|
|
201
|
-
err,
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if (orgs.length < BATCH)
|
|
206
|
-
break;
|
|
207
|
-
after = orgs.at(-1).id;
|
|
208
|
-
}
|
|
209
|
-
return deleted;
|
|
210
|
-
}
|
|
211
|
-
/** The orphan objects of one organization, page by page. */
|
|
212
|
-
async orphansOf(orgId, signal) {
|
|
213
|
-
const store = this.storage.kernel(orgId);
|
|
214
|
-
let deleted = 0;
|
|
215
|
-
let cursor;
|
|
216
|
-
do {
|
|
217
|
-
const page = await store.list("shares/", {
|
|
218
|
-
limit: LIST_PAGE,
|
|
219
|
-
...(cursor !== undefined && { cursor }),
|
|
220
|
-
});
|
|
221
|
-
cursor = page.cursor;
|
|
222
|
-
// the rows are read once per page; `deleteObject` reads its row again before deleting
|
|
223
|
-
const cutoff = Date.now() - ORPHAN_AGE_MS;
|
|
224
|
-
const old = page.items.filter((i) => {
|
|
225
|
-
const at = i.lastModified === undefined ? Number.NaN : Date.parse(i.lastModified);
|
|
226
|
-
return Number.isFinite(at) && at < cutoff;
|
|
227
|
-
});
|
|
228
|
-
const parsed = old.map((i) => ({ key: i.key, m: SHARE_KEY_RE.exec(i.key) }));
|
|
229
|
-
const ids = [...new Set(parsed.flatMap((p) => (p.m ? [p.m[1]] : [])))];
|
|
230
|
-
const named = new Map();
|
|
231
|
-
if (ids.length > 0) {
|
|
232
|
-
const rows = await this.db
|
|
233
|
-
.selectFrom("file_shares")
|
|
234
|
-
.select(["id", "object_key"])
|
|
235
|
-
.where("org_id", "=", orgId)
|
|
236
|
-
.where("id", "in", ids)
|
|
237
|
-
.execute();
|
|
238
|
-
for (const r of rows)
|
|
239
|
-
named.set(r.id, r.object_key);
|
|
240
|
-
}
|
|
241
|
-
for (const p of parsed) {
|
|
242
|
-
if (signal?.aborted)
|
|
243
|
-
return deleted;
|
|
244
|
-
const shareId = p.m?.[1];
|
|
245
|
-
const generation = Number(p.m?.[2]);
|
|
246
|
-
const snapshot = shareId !== undefined &&
|
|
247
|
-
Number.isSafeInteger(generation) &&
|
|
248
|
-
shareObjectKey(shareId, generation) === p.key;
|
|
249
|
-
if (!snapshot || shareId === undefined) {
|
|
250
|
-
if (await this.stillOld(store, p.key, cutoff)) {
|
|
251
|
-
await store.delete(p.key);
|
|
252
|
-
deleted++;
|
|
253
|
-
}
|
|
254
|
-
continue;
|
|
255
|
-
}
|
|
256
|
-
if (named.get(shareId) === p.key)
|
|
257
|
-
continue; // its row's snapshot: step 2's, not an orphan
|
|
258
|
-
const data = { orgId, shareId, generation, objectKey: p.key };
|
|
259
|
-
if (!named.has(shareId)) {
|
|
260
|
-
// no row (an insert that failed after its copy): a new create uses a new id
|
|
261
|
-
if ((await this.stillOld(store, p.key, cutoff)) && (await this.deleteGuarded(data))) {
|
|
262
|
-
deleted++;
|
|
263
|
-
}
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
// another generation of an existing share: a retried refresh may be writing this very key
|
|
267
|
-
// again, its commit about to name it. Held, the refresh lock means no refresh is between its
|
|
268
|
-
// copy and its commit, so the row `deleteObject` reads is the last word; a refresh holding
|
|
269
|
-
// it now skips the key (the next run sees it again)
|
|
270
|
-
const lock = await this.lockService.acquire(shareRefreshLockKey(shareId), {
|
|
271
|
-
ttlMs: REFRESH_LOCK_TTL_MS,
|
|
272
|
-
waitMs: 0,
|
|
273
|
-
});
|
|
274
|
-
if (!lock)
|
|
275
|
-
continue;
|
|
276
|
-
try {
|
|
277
|
-
if ((await this.stillOld(store, p.key, cutoff)) && (await this.deleteGuarded(data))) {
|
|
278
|
-
deleted++;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
finally {
|
|
282
|
-
await lock.release();
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
} while (cursor !== undefined && !signal?.aborted);
|
|
286
|
-
return deleted;
|
|
287
|
-
}
|
|
288
136
|
/**
|
|
289
|
-
*
|
|
290
|
-
*
|
|
137
|
+
* One batch of step 2 (one org, in its scope): the condition is checked again in the `UPDATE` (expiry is final and a
|
|
138
|
+
* revoke is never undone, so a row read as old is still old).
|
|
291
139
|
*/
|
|
292
|
-
async
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
orgId: data.orgId,
|
|
308
|
-
shareId: data.shareId,
|
|
309
|
-
generation: data.generation,
|
|
310
|
-
err,
|
|
311
|
-
});
|
|
312
|
-
return false;
|
|
313
|
-
}
|
|
140
|
+
async freeBatch(orgId, shareIds) {
|
|
141
|
+
const old = sql `now() - make_interval(days => ${RETAIN_DAYS})`;
|
|
142
|
+
const rows = await this.db
|
|
143
|
+
.updateTable("file_shares")
|
|
144
|
+
.set({ blob_id: null })
|
|
145
|
+
.where("org_id", "=", orgId)
|
|
146
|
+
.where("id", "in", [...shareIds])
|
|
147
|
+
.where("blob_id", "is not", null)
|
|
148
|
+
.where((eb) => eb.or([
|
|
149
|
+
eb("revoked_at", "<", old),
|
|
150
|
+
eb.and([eb("revoked_at", "is", null), eb("expires_at", "<", old)]),
|
|
151
|
+
]))
|
|
152
|
+
.returning("id")
|
|
153
|
+
.execute();
|
|
154
|
+
return rows.length;
|
|
314
155
|
}
|
|
315
156
|
};
|
|
316
157
|
__decorate([
|
|
@@ -319,14 +160,14 @@ __decorate([
|
|
|
319
160
|
__decorate([
|
|
320
161
|
Transactional()
|
|
321
162
|
], ShareSweepJob.prototype, "revokeBatch", null);
|
|
163
|
+
__decorate([
|
|
164
|
+
Transactional()
|
|
165
|
+
], ShareSweepJob.prototype, "freeBatch", null);
|
|
322
166
|
ShareSweepJob = __decorate([
|
|
323
167
|
Injectable(),
|
|
324
168
|
__param(0, Inject(KernelDb)),
|
|
325
169
|
__param(1, Inject(TransactionHost)),
|
|
326
|
-
__param(2, Inject(
|
|
327
|
-
__param(3, Inject(
|
|
328
|
-
__param(4, Inject(StorageService)),
|
|
329
|
-
__param(5, Inject(LockService)),
|
|
330
|
-
__param(6, Inject(KERNEL_LOGGER))
|
|
170
|
+
__param(2, Inject(LockService)),
|
|
171
|
+
__param(3, Inject(KERNEL_LOGGER))
|
|
331
172
|
], ShareSweepJob);
|
|
332
173
|
export { ShareSweepJob };
|
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.
|