@capybara-hq/kernel 0.1.0-rc.35 → 0.1.0-rc.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.json +5 -5
- package/dist/admin/admin.module.d.ts +3 -3
- package/dist/admin/admin.module.js +6 -6
- package/dist/admin/audit-log.service.d.ts +51 -0
- package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
- package/dist/admin/audit.controller.d.ts +18 -6
- package/dist/admin/audit.controller.js +36 -6
- package/dist/admin/audit.schemas.d.ts +9 -1
- package/dist/admin/audit.schemas.js +22 -2
- package/dist/admin/outbox-dead.controller.d.ts +4 -6
- package/dist/admin/outbox-dead.controller.js +9 -6
- package/dist/admin/outbox-dead.schemas.d.ts +16 -0
- package/dist/admin/outbox-dead.schemas.js +25 -1
- package/dist/admin/outbox-dead.service.d.ts +16 -7
- package/dist/admin/outbox-dead.service.js +34 -10
- package/dist/admin/overview.service.d.ts +3 -3
- package/dist/admin/overview.service.js +0 -1
- package/dist/agents/agent-lookup.js +2 -10
- package/dist/agents/agents.module.js +3 -0
- package/dist/agents/agents.service.js +9 -20
- package/dist/agents/definition.d.ts +3 -51
- package/dist/agents/definition.js +4 -254
- package/dist/agents/org-templates.js +2 -6
- package/dist/agents/readiness.controller.d.ts +8 -19
- package/dist/agents/readiness.controller.js +11 -25
- package/dist/agents/readiness.service.d.ts +42 -0
- package/dist/agents/readiness.service.js +78 -0
- package/dist/agents/templates.d.ts +0 -6
- package/dist/agents/templates.js +8 -34
- package/dist/background/store.d.ts +2 -0
- package/dist/background/store.js +3 -1
- package/dist/background/wake-rules.js +2 -1
- package/dist/catalog/admin-catalog.controller.d.ts +1 -2
- package/dist/catalog/admin-catalog.controller.js +1 -2
- package/dist/catalog/appearance.service.js +1 -3
- package/dist/catalog/catalog-content.d.ts +1 -1
- package/dist/catalog/catalog-content.js +1 -4
- package/dist/catalog/catalog-items.js +3 -3
- package/dist/catalog/catalog-scope.service.d.ts +10 -28
- package/dist/catalog/catalog-scope.service.js +22 -73
- package/dist/catalog/cli.d.ts +0 -11
- package/dist/catalog/cli.js +0 -20
- package/dist/catalog/component-scope.service.js +0 -2
- package/dist/catalog/component-state.js +2 -2
- package/dist/catalog/install-status.d.ts +6 -0
- package/dist/catalog/install-status.js +6 -0
- package/dist/catalog/job-ids.d.ts +0 -4
- package/dist/catalog/job-ids.js +0 -4
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +2 -0
- package/dist/catalog/org-catalog.service.js +8 -3
- package/dist/catalog/org-extension-switch.d.ts +7 -2
- package/dist/catalog/org-extension-switch.js +56 -9
- package/dist/catalog/org-plugin-uploads.d.ts +6 -15
- package/dist/catalog/org-plugin-uploads.js +9 -27
- package/dist/catalog/owned-items.js +1 -3
- package/dist/catalog/platform-import-update.js +1 -1
- package/dist/catalog/plugin-import.d.ts +15 -13
- package/dist/catalog/plugin-import.js +21 -30
- package/dist/catalog/plugin-install.d.ts +3 -43
- package/dist/catalog/plugin-install.js +8 -150
- package/dist/catalog/plugin-package.d.ts +5 -10
- package/dist/catalog/plugin-package.js +12 -33
- package/dist/catalog/plugin-upgrade.js +5 -4
- package/dist/catalog/scope-jobs.d.ts +34 -34
- package/dist/catalog/scope-jobs.js +50 -37
- package/dist/catalog/scope-orgs.d.ts +1 -1
- package/dist/catalog/scope-orgs.js +1 -2
- package/dist/catalog/scope-sync-workers.d.ts +4 -3
- package/dist/catalog/scope-sync-workers.js +18 -6
- package/dist/catalog/scope-sync.d.ts +56 -59
- package/dist/catalog/scope-sync.js +96 -166
- package/dist/catalog/unshare.d.ts +3 -4
- package/dist/catalog/unshare.js +5 -8
- package/dist/channels/job-ids.d.ts +2 -6
- package/dist/channels/job-ids.js +2 -6
- package/dist/channels/outbound.d.ts +1 -1
- package/dist/channels/outbound.js +1 -1
- package/dist/channels/supervisor.d.ts +2 -3
- package/dist/channels/supervisor.js +2 -3
- package/dist/client/client-access.service.js +1 -1
- package/dist/config/env.js +19 -1
- package/dist/config/load.d.ts +0 -6
- package/dist/config/load.js +8 -27
- package/dist/config/schema.d.ts +53 -47
- package/dist/config/schema.js +190 -40
- package/dist/conversations/attachments.service.d.ts +10 -3
- package/dist/conversations/attachments.service.js +49 -16
- package/dist/conversations/conversations.controller.d.ts +0 -39
- package/dist/conversations/conversations.controller.js +0 -39
- package/dist/conversations/events.d.ts +71 -46
- package/dist/conversations/events.js +124 -112
- package/dist/conversations/media-types.d.ts +25 -0
- package/dist/conversations/media-types.js +38 -0
- package/dist/conversations/queue.d.ts +3 -1
- package/dist/conversations/queue.service.js +9 -2
- package/dist/conversations/titles.js +6 -0
- package/dist/ctx/create-ctx.js +1 -2
- package/dist/ctx/secrets.d.ts +24 -7
- package/dist/ctx/secrets.js +97 -30
- package/dist/db/kernel-schema.d.ts +17 -6
- package/dist/errors.d.ts +5 -2
- package/dist/errors.js +5 -2
- package/dist/evals/reconstruct.d.ts +4 -17
- package/dist/evals/reconstruct.js +13 -53
- package/dist/evals/recorded-tools.d.ts +0 -27
- package/dist/evals/recorded-tools.js +2 -92
- package/dist/evals/run-replay.d.ts +1 -6
- package/dist/evals/run-replay.js +10 -17
- package/dist/evals/sets.service.d.ts +17 -5
- package/dist/evals/sets.service.js +33 -12
- package/dist/evals/snapshot.d.ts +1 -2
- package/dist/evals/snapshot.js +4 -17
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +17 -4
- package/dist/extensions/admin-view.d.ts +7 -4
- package/dist/extensions/admin-view.js +27 -21
- package/dist/extensions/bootstrap.js +0 -1
- package/dist/extensions/cli.js +0 -1
- package/dist/extensions/host.d.ts +2 -3
- package/dist/extensions/host.js +1 -5
- package/dist/extensions/installs.d.ts +1 -3
- package/dist/extensions/instance.d.ts +0 -2
- package/dist/extensions/instance.js +0 -3
- package/dist/extensions/org-config.d.ts +4 -4
- package/dist/extensions/org-config.js +13 -22
- package/dist/extensions/package.d.ts +6 -6
- package/dist/extensions/package.js +3 -7
- package/dist/extensions/permission-view.d.ts +2 -4
- package/dist/extensions/plugin-items.d.ts +21 -1
- package/dist/extensions/plugin-items.js +28 -0
- package/dist/extensions/sync.js +5 -10
- package/dist/extensions/unavailable.js +0 -1
- package/dist/http/api.module.js +2 -1
- package/dist/identity/audit.d.ts +0 -12
- package/dist/identity/audit.js +0 -27
- package/dist/identity/auth.controller.js +5 -9
- package/dist/identity/cookies.d.ts +4 -9
- package/dist/identity/cookies.js +8 -32
- package/dist/identity/initial-passwords.d.ts +1 -1
- package/dist/identity/initial-passwords.js +1 -2
- package/dist/identity/sessions.d.ts +0 -6
- package/dist/identity/sessions.js +0 -18
- package/dist/inbox/platform-inbox.service.d.ts +33 -1
- package/dist/inbox/platform-inbox.service.js +56 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
- package/dist/infra/cli/master-key-rewrap.js +24 -0
- package/dist/infra/config/kernel-config.service.js +0 -17
- package/dist/infra/health/health.controller.js +8 -0
- package/dist/infra/health/process-fault.d.ts +16 -0
- package/dist/infra/health/process-fault.js +49 -0
- package/dist/infra/lifecycle/process-guards.d.ts +8 -2
- package/dist/infra/lifecycle/process-guards.js +12 -3
- package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
- package/dist/infra/lifecycle/shutdown-signals.js +28 -13
- package/dist/infra/outbox/outbox.service.d.ts +12 -9
- package/dist/infra/outbox/outbox.service.js +22 -26
- package/dist/infra/outbox/registry.d.ts +15 -7
- package/dist/infra/outbox/registry.js +39 -23
- package/dist/lifecycle/kernel-lifecycle.js +1 -7
- package/dist/models/enablement.d.ts +5 -6
- package/dist/models/enablement.js +7 -14
- package/dist/orgs/orgs.module.d.ts +2 -2
- package/dist/orgs/orgs.module.js +2 -2
- package/dist/orgs/settings.controller.d.ts +3 -2
- package/dist/orgs/settings.service.d.ts +59 -14
- package/dist/orgs/settings.service.js +102 -20
- package/dist/overrides.d.ts +3 -7
- package/dist/overrides.js +2 -4
- package/dist/packages/tgz.d.ts +0 -2
- package/dist/packages/tgz.js +0 -2
- package/dist/platform/exclusions.js +0 -5
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.d.ts +2 -2
- package/dist/platform/ops/admin.ops.js +9 -6
- package/dist/platform/ops/agents.ops.d.ts +3 -3
- package/dist/platform/ops/agents.ops.js +7 -10
- package/dist/platform/ops/connectors.ops.js +46 -1
- package/dist/platform/ops/evals.ops.js +1 -64
- package/dist/platform/ops/extensions-admin.ops.js +1 -1
- package/dist/platform/ops/inbox.ops.js +16 -3
- package/dist/platform/ops/org-plugins.ops.js +1 -1
- package/dist/platform/ops/orgs.ops.d.ts +5 -3
- package/dist/platform/ops/orgs.ops.js +19 -4
- package/dist/platform/ops/outbox.ops.js +5 -5
- package/dist/roles/worker-role.d.ts +2 -3
- package/dist/roles/worker-role.js +3 -13
- package/dist/runtime/context/build.d.ts +56 -18
- package/dist/runtime/context/build.js +143 -50
- package/dist/runtime/context/compaction.d.ts +1 -3
- package/dist/runtime/context/compaction.js +42 -8
- package/dist/runtime/context/run-context.js +1 -2
- package/dist/runtime/context/skills.d.ts +27 -56
- package/dist/runtime/context/skills.js +42 -114
- package/dist/runtime/context/tool-changes.d.ts +3 -3
- package/dist/runtime/context/tool-changes.js +6 -16
- package/dist/runtime/hook-calls.d.ts +6 -6
- package/dist/runtime/hook-calls.js +7 -7
- package/dist/runtime/langgraph-loop.js +1 -0
- package/dist/runtime/maintenance.d.ts +3 -11
- package/dist/runtime/maintenance.js +5 -20
- package/dist/runtime/model-call.d.ts +5 -0
- package/dist/runtime/model-call.js +48 -36
- package/dist/runtime/providers.d.ts +33 -35
- package/dist/runtime/providers.js +64 -109
- package/dist/runtime/run-context.service.js +7 -22
- package/dist/runtime/run-deletion.d.ts +6 -0
- package/dist/runtime/run-deletion.js +39 -16
- package/dist/runtime/run-execution.js +4 -3
- package/dist/runtime/run-finish.js +2 -1
- package/dist/runtime/run-liveness.d.ts +11 -0
- package/dist/runtime/run-liveness.js +19 -0
- package/dist/runtime/run-orphan-check.job.js +2 -1
- package/dist/runtime/run-queue.js +8 -16
- package/dist/runtime/run-worker.d.ts +2 -2
- package/dist/runtime/run-worker.js +8 -6
- package/dist/runtime/subagents/definition.d.ts +16 -20
- package/dist/runtime/subagents/definition.js +27 -27
- package/dist/runtime/subagents/dispatch.d.ts +6 -2
- package/dist/runtime/subagents/dispatch.js +17 -3
- package/dist/runtime/subagents/org-agents.js +1 -2
- package/dist/runtime/subagents/preamble.d.ts +3 -2
- package/dist/runtime/subagents/preamble.js +3 -2
- package/dist/runtime/subagents/render.d.ts +1 -2
- package/dist/runtime/subagents/render.js +1 -2
- package/dist/runtime/subagents/skill-fork.d.ts +2 -4
- package/dist/runtime/subagents/template-skills.d.ts +47 -0
- package/dist/runtime/subagents/template-skills.js +76 -0
- package/dist/schedules/effective-settings.d.ts +9 -3
- package/dist/schedules/effective-settings.js +5 -4
- package/dist/schedules/fire.js +11 -0
- package/dist/schedules/scheduled-tasks.service.js +5 -0
- package/dist/schedules/unattended.d.ts +2 -0
- package/dist/schedules/unattended.js +6 -1
- package/dist/skills/agent-skills.service.js +1 -2
- package/dist/skills/catalog.d.ts +1 -3
- package/dist/skills/catalog.js +1 -3
- package/dist/skills/conversation-catalog.d.ts +1 -2
- package/dist/skills/conversation-catalog.js +1 -2
- package/dist/skills/usable.js +2 -3
- package/dist/storage/storage.service.js +9 -1
- package/dist/tools/approvals.service.js +2 -4
- package/dist/tools/builtin-names.d.ts +2 -9
- package/dist/tools/builtin-names.js +4 -13
- package/dist/tools/builtins/sandbox/bash.js +3 -3
- package/dist/tools/builtins/sandbox/common.d.ts +7 -13
- package/dist/tools/builtins/sandbox/common.js +8 -115
- package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
- package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
- package/dist/tools/builtins/sandbox/glob.js +1 -3
- package/dist/tools/builtins/sandbox/grep.js +3 -5
- package/dist/tools/builtins/sandbox/index.d.ts +8 -5
- package/dist/tools/builtins/sandbox/index.js +10 -5
- package/dist/tools/builtins/sandbox/read.js +3 -2
- package/dist/tools/builtins/tool-search.d.ts +4 -7
- package/dist/tools/builtins/tool-search.js +6 -10
- package/dist/tools/connector-account-policies.d.ts +30 -3
- package/dist/tools/connector-account-policies.js +54 -7
- package/dist/tools/connectors.controller.d.ts +24 -11
- package/dist/tools/connectors.controller.js +35 -6
- package/dist/tools/connectors.schemas.d.ts +14 -1
- package/dist/tools/connectors.schemas.js +14 -2
- package/dist/tools/connectors.service.d.ts +22 -0
- package/dist/tools/connectors.service.js +56 -0
- package/dist/tools/drift.d.ts +1 -1
- package/dist/tools/drift.js +1 -1
- package/dist/tools/git-push-policy.d.ts +4 -1
- package/dist/tools/git-push-policy.js +3 -1
- package/dist/tools/info.d.ts +1 -7
- package/dist/tools/info.js +5 -18
- package/dist/tools/job-ids.d.ts +0 -4
- package/dist/tools/job-ids.js +1 -6
- package/dist/tools/pipeline.d.ts +4 -10
- package/dist/tools/pipeline.js +16 -62
- package/dist/tools/policy.d.ts +6 -2
- package/dist/tools/policy.js +14 -12
- package/dist/tools/registry.js +1 -5
- package/dist/ui/views.d.ts +5 -5
- package/dist/ui/views.js +10 -16
- package/package.json +3 -3
- package/src/migrations/0137_audit_org_idx.sql +5 -0
- package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
- package/src/migrations/0139_retire_legacy_forms.sql +183 -0
- package/src/migrations/0140_retire_history_forms.sql +148 -0
- package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
- package/src/migrations/0142_backfill_event_fields.sql +74 -0
- package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
- package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
- package/dist/admin/platform-audit.service.d.ts +0 -41
- package/dist/conversations/job-ids.d.ts +0 -6
- package/dist/conversations/job-ids.js +0 -6
- package/dist/extensions/job-ids.d.ts +0 -6
- package/dist/extensions/job-ids.js +0 -6
- package/dist/infra/queue/retired-schedulers.d.ts +0 -7
- package/dist/infra/queue/retired-schedulers.js +0 -9
- package/dist/orgs/job-ids.d.ts +0 -8
- package/dist/orgs/job-ids.js +0 -8
- package/dist/runtime/context/legacy-text.d.ts +0 -22
- package/dist/runtime/context/legacy-text.js +0 -37
- package/dist/runtime/job-ids.d.ts +0 -10
- package/dist/runtime/job-ids.js +0 -10
- package/dist/runtime/retired-schedulers.d.ts +0 -7
- package/dist/runtime/retired-schedulers.js +0 -31
- package/dist/storage/job-ids.d.ts +0 -6
- package/dist/storage/job-ids.js +0 -6
- package/dist/tools/legacy-data.d.ts +0 -34
- package/dist/tools/legacy-data.js +0 -76
- package/dist/tools/legacy-keys.d.ts +0 -51
- package/dist/tools/legacy-keys.js +0 -114
|
@@ -15,20 +15,15 @@ export declare const REFRESH_COOKIE = "cap_rt";
|
|
|
15
15
|
* session while rendering on the server.
|
|
16
16
|
*/
|
|
17
17
|
export declare const REFRESH_COOKIE_PATH = "/";
|
|
18
|
-
/** The Path earlier releases set `cap_rt` on; browsers may still hold it, so it is cleared too. */
|
|
19
|
-
export declare const LEGACY_REFRESH_COOKIE_PATH = "/api/v1/auth";
|
|
20
18
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* The Path earlier builds set `cap_rt` on. Cleared (never read) with every session write, so a
|
|
20
|
+
* browser that still holds it stops sending a stale token. Remove after 2026-12-01.
|
|
23
21
|
*/
|
|
22
|
+
export declare const OLD_REFRESH_COOKIE_PATH = "/api/v1/auth";
|
|
23
|
+
/** Writes the session cookies. Both are HttpOnly, host-only (no Domain), SameSite=Lax and Path=/. */
|
|
24
24
|
export declare function setSessionCookies(reply: FastifyReply, s: IssuedSession, cfg: KernelConfig): void;
|
|
25
25
|
/** 清除会话 Cookie(Path 必须与设置时一致才能覆盖)。 */
|
|
26
26
|
export declare function clearSessionCookies(reply: FastifyReply): void;
|
|
27
|
-
/**
|
|
28
|
-
* Every `cap_rt` value of a raw `cookie` header, in header order. A browser holding the legacy
|
|
29
|
-
* Path cookie and the new one sends both, the more specific Path first.
|
|
30
|
-
*/
|
|
31
|
-
export declare function refreshCookieValues(header: string | undefined): string[];
|
|
32
27
|
/**
|
|
33
28
|
* The startup warning for an http trial that cannot sign in: session cookies are Secure but the
|
|
34
29
|
* configured public URL is plain http, so browsers drop them. Null when cookies are not Secure,
|
package/dist/identity/cookies.js
CHANGED
|
@@ -12,12 +12,12 @@ export const REFRESH_COOKIE = "cap_rt";
|
|
|
12
12
|
* session while rendering on the server.
|
|
13
13
|
*/
|
|
14
14
|
export const REFRESH_COOKIE_PATH = "/";
|
|
15
|
-
/** The Path earlier releases set `cap_rt` on; browsers may still hold it, so it is cleared too. */
|
|
16
|
-
export const LEGACY_REFRESH_COOKIE_PATH = "/api/v1/auth";
|
|
17
15
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* The Path earlier builds set `cap_rt` on. Cleared (never read) with every session write, so a
|
|
17
|
+
* browser that still holds it stops sending a stale token. Remove after 2026-12-01.
|
|
20
18
|
*/
|
|
19
|
+
export const OLD_REFRESH_COOKIE_PATH = "/api/v1/auth";
|
|
20
|
+
/** Writes the session cookies. Both are HttpOnly, host-only (no Domain), SameSite=Lax and Path=/. */
|
|
21
21
|
export function setSessionCookies(reply, s, cfg) {
|
|
22
22
|
const secure = cfg.auth.cookieSecure;
|
|
23
23
|
reply.setCookie(ACCESS_COOKIE, s.accessToken, {
|
|
@@ -34,39 +34,15 @@ export function setSessionCookies(reply, s, cfg) {
|
|
|
34
34
|
secure,
|
|
35
35
|
maxAge: cfg.auth.refreshTokenTtlDays * 86400,
|
|
36
36
|
});
|
|
37
|
-
|
|
37
|
+
// clears stale client state from earlier builds; remove after 2026-12-01
|
|
38
|
+
reply.clearCookie(REFRESH_COOKIE, { path: OLD_REFRESH_COOKIE_PATH });
|
|
38
39
|
}
|
|
39
40
|
/** 清除会话 Cookie(Path 必须与设置时一致才能覆盖)。 */
|
|
40
41
|
export function clearSessionCookies(reply) {
|
|
41
42
|
reply.clearCookie(ACCESS_COOKIE, { path: "/" });
|
|
42
43
|
reply.clearCookie(REFRESH_COOKIE, { path: REFRESH_COOKIE_PATH });
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Every `cap_rt` value of a raw `cookie` header, in header order. A browser holding the legacy
|
|
47
|
-
* Path cookie and the new one sends both, the more specific Path first.
|
|
48
|
-
*/
|
|
49
|
-
export function refreshCookieValues(header) {
|
|
50
|
-
if (!header)
|
|
51
|
-
return [];
|
|
52
|
-
const out = [];
|
|
53
|
-
for (const part of header.split(";")) {
|
|
54
|
-
const eq = part.indexOf("=");
|
|
55
|
-
if (eq < 0 || part.slice(0, eq).trim() !== REFRESH_COOKIE)
|
|
56
|
-
continue;
|
|
57
|
-
let v = part.slice(eq + 1).trim();
|
|
58
|
-
if (v.startsWith('"') && v.endsWith('"') && v.length >= 2)
|
|
59
|
-
v = v.slice(1, -1);
|
|
60
|
-
try {
|
|
61
|
-
v = decodeURIComponent(v);
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
// keep the raw value
|
|
65
|
-
}
|
|
66
|
-
if (v)
|
|
67
|
-
out.push(v);
|
|
68
|
-
}
|
|
69
|
-
return out;
|
|
44
|
+
// clears stale client state from earlier builds; remove after 2026-12-01
|
|
45
|
+
reply.clearCookie(REFRESH_COOKIE, { path: OLD_REFRESH_COOKIE_PATH });
|
|
70
46
|
}
|
|
71
47
|
/**
|
|
72
48
|
* The startup warning for an http trial that cannot sign in: session cookies are Secure but the
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Keyring } from "../ctx/secrets.js";
|
|
2
2
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
3
3
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
4
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { randomInt } from "node:crypto";
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
|
+
import { initialPasswordAad as aadOf } from "../ctx/secrets.js";
|
|
13
14
|
import { ApiError } from "../errors.js";
|
|
14
15
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
15
16
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
@@ -35,8 +36,6 @@ export function generateInitialPassword() {
|
|
|
35
36
|
out += ALPHABET[randomInt(ALPHABET.length)];
|
|
36
37
|
return out;
|
|
37
38
|
}
|
|
38
|
-
/** The AAD binding a sealed password to its account (a row moved to another account fails). */
|
|
39
|
-
const aadOf = (accountId) => `capybara:initial-password:${accountId}`;
|
|
40
39
|
/**
|
|
41
40
|
* Accounts created with a kernel-generated one-time password (Platform tool spec §14.5 item 2).
|
|
42
41
|
* The password never leaves the kernel except through {@link reveal}: it is not returned to the
|
|
@@ -42,12 +42,6 @@ export declare class SessionService {
|
|
|
42
42
|
* app then asks to choose or create one).
|
|
43
43
|
*/
|
|
44
44
|
private startingOrg;
|
|
45
|
-
/**
|
|
46
|
-
* Read-only: of several refresh tokens (a cookie header carrying the legacy and the `Path=/`
|
|
47
|
-
* cookie), the first that is the current token of a live session, if any. Choosing before
|
|
48
|
-
* rotating keeps a stale token from tripping replay detection on a still valid session.
|
|
49
|
-
*/
|
|
50
|
-
pickCurrentRefresh(candidates: readonly string[]): Promise<string | undefined>;
|
|
51
45
|
refresh(refreshToken: string, meta: {
|
|
52
46
|
userAgent?: string;
|
|
53
47
|
ip?: string;
|
|
@@ -97,24 +97,6 @@ let SessionService = class SessionService {
|
|
|
97
97
|
return last.orgId;
|
|
98
98
|
return orgs.length === 1 ? (orgs[0]?.orgId ?? null) : null;
|
|
99
99
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Read-only: of several refresh tokens (a cookie header carrying the legacy and the `Path=/`
|
|
102
|
-
* cookie), the first that is the current token of a live session, if any. Choosing before
|
|
103
|
-
* rotating keeps a stale token from tripping replay detection on a still valid session.
|
|
104
|
-
*/
|
|
105
|
-
async pickCurrentRefresh(candidates) {
|
|
106
|
-
if (candidates.length === 0)
|
|
107
|
-
return undefined;
|
|
108
|
-
const rows = await this.db
|
|
109
|
-
.selectFrom("sessions")
|
|
110
|
-
.select("refresh_hash")
|
|
111
|
-
.where("refresh_hash", "in", candidates.map((c) => sha256Hex(c)))
|
|
112
|
-
.where("revoked_at", "is", null)
|
|
113
|
-
.where("expires_at", ">", sql `now()`)
|
|
114
|
-
.execute();
|
|
115
|
-
const live = new Set(rows.map((r) => r.refresh_hash));
|
|
116
|
-
return candidates.find((c) => live.has(sha256Hex(c)));
|
|
117
|
-
}
|
|
118
100
|
async refresh(refreshToken, meta) {
|
|
119
101
|
const oldHash = sha256Hex(refreshToken);
|
|
120
102
|
const next = newRefreshToken();
|
|
@@ -29,6 +29,27 @@ export interface ScopeSyncFailureView {
|
|
|
29
29
|
message: string;
|
|
30
30
|
failedAt: string;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* A live platform plugin (or an org's own) whose scope turns it on (`all` or `named`) while its
|
|
34
|
+
* extension is installed and approved but disabled on the deployment (a super admin disabled it, or
|
|
35
|
+
* its enable was refused because another enabled extension holds one of its single-provider
|
|
36
|
+
* extension points): the scope sync installs it nowhere until the extension is enabled, whose
|
|
37
|
+
* enable owes the sync. Derived from the current state at every read.
|
|
38
|
+
*/
|
|
39
|
+
export interface ExtensionDisabledView {
|
|
40
|
+
item: {
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
displayName: LocalizedName | null;
|
|
44
|
+
};
|
|
45
|
+
/** The extension's name (the plugin's) and its installed version. */
|
|
46
|
+
extension: {
|
|
47
|
+
name: string;
|
|
48
|
+
version: string;
|
|
49
|
+
};
|
|
50
|
+
/** When the extension's install record last changed (its disable, or its install). */
|
|
51
|
+
since: string;
|
|
52
|
+
}
|
|
32
53
|
/**
|
|
33
54
|
* One item of the super admin's inbox (by `type`). Nothing is decided in the inbox: each item is
|
|
34
55
|
* acted on where it lives (the web links to it).
|
|
@@ -39,6 +60,9 @@ export interface ScopeSyncFailureView {
|
|
|
39
60
|
* - `org_upload_pending`: an org-owned plugin whose uploaded version (with an extension) waits for
|
|
40
61
|
* the super admin in 待确认 (ruling P3-22; confirmed or rejected there), `id` = the item's;
|
|
41
62
|
* - `scope_sync_failed`: an open scope sync failure, `id` = `<itemId>/<orgId>`;
|
|
63
|
+
* - `extension_disabled`: a plugin its scope turns on whose extension is disabled on the deployment
|
|
64
|
+
* ({@link ExtensionDisabledView}), `id` = the item's; gone once the extension is enabled (or the
|
|
65
|
+
* scope no longer turns it on);
|
|
42
66
|
* - `ownership_transferred`: a deleted org's shared item now belongs to the platform, until a
|
|
43
67
|
* super admin dismisses it (`POST admin/inbox/notices/:id/dismiss`).
|
|
44
68
|
*/
|
|
@@ -62,6 +86,11 @@ export type PlatformInboxItem = {
|
|
|
62
86
|
id: string;
|
|
63
87
|
createdAt: string;
|
|
64
88
|
failure: ScopeSyncFailureView;
|
|
89
|
+
} | {
|
|
90
|
+
type: "extension_disabled";
|
|
91
|
+
id: string;
|
|
92
|
+
createdAt: string;
|
|
93
|
+
disabled: ExtensionDisabledView;
|
|
65
94
|
} | {
|
|
66
95
|
type: "ownership_transferred";
|
|
67
96
|
id: string;
|
|
@@ -69,7 +98,7 @@ export type PlatformInboxItem = {
|
|
|
69
98
|
notice: PlatformNoticeView;
|
|
70
99
|
};
|
|
71
100
|
/** Every {@link PlatformInboxItem} type, in the order the admin overview lists them. */
|
|
72
|
-
export declare const PLATFORM_INBOX_TYPES: readonly ["catalog_request", "permission_confirmation", "org_upload_pending", "scope_sync_failed", "ownership_transferred"];
|
|
101
|
+
export declare const PLATFORM_INBOX_TYPES: readonly ["catalog_request", "permission_confirmation", "org_upload_pending", "scope_sync_failed", "extension_disabled", "ownership_transferred"];
|
|
73
102
|
/** How many items of each type wait: every type, zeros included. */
|
|
74
103
|
export type PlatformInboxCounts = Record<PlatformInboxItem["type"], number>;
|
|
75
104
|
/** An open platform notice (`platform_notices`, kind `ownership_transferred`). */
|
|
@@ -115,6 +144,9 @@ export declare class PlatformInboxService {
|
|
|
115
144
|
* dismissed is fine; no notice with that id -> `inbox.notice_not_found`.
|
|
116
145
|
*/
|
|
117
146
|
dismissNotice(accountId: string, id: string): Promise<void>;
|
|
147
|
+
private countDisabledExtensions;
|
|
148
|
+
/** The plugins on by scope whose extension is disabled, newest change first. */
|
|
149
|
+
private disabledExtensions;
|
|
118
150
|
/**
|
|
119
151
|
* The open failures still worth a look, joined to their item and org: of a live item and org,
|
|
120
152
|
* and the pair still differs in the failed direction (a person may have converged it meanwhile):
|
|
@@ -10,6 +10,7 @@ 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 { CatalogService } from "../catalog/catalog.service.js";
|
|
13
|
+
import { LIVE_INSTALL_STATUSES } from "../catalog/install-status.js";
|
|
13
14
|
import { CatalogRequestsService } from "../catalog/requests.service.js";
|
|
14
15
|
import { ApiError } from "../errors.js";
|
|
15
16
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
@@ -17,14 +18,13 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
17
18
|
export const PLATFORM_INBOX_MAX_ITEMS = 100;
|
|
18
19
|
/** The most open scope sync failures one read takes. */
|
|
19
20
|
export const SCOPE_SYNC_FAILURES_LIST_MAX = 200;
|
|
20
|
-
/** Plugin install statuses of a plugin that is on in the org. */
|
|
21
|
-
const LIVE_INSTALL = ["installing", "installed", "upgrading"];
|
|
22
21
|
/** Every {@link PlatformInboxItem} type, in the order the admin overview lists them. */
|
|
23
22
|
export const PLATFORM_INBOX_TYPES = [
|
|
24
23
|
"catalog_request",
|
|
25
24
|
"permission_confirmation",
|
|
26
25
|
"org_upload_pending",
|
|
27
26
|
"scope_sync_failed",
|
|
27
|
+
"extension_disabled",
|
|
28
28
|
"ownership_transferred",
|
|
29
29
|
];
|
|
30
30
|
/**
|
|
@@ -43,12 +43,14 @@ let PlatformInboxService = class PlatformInboxService {
|
|
|
43
43
|
this.kdb = kdb;
|
|
44
44
|
}
|
|
45
45
|
async list() {
|
|
46
|
-
const [requests, requestCount, pending, failures, failureCount, notices, noticeCount] = await Promise.all([
|
|
46
|
+
const [requests, requestCount, pending, failures, failureCount, disabled, disabledCount, notices, noticeCount,] = await Promise.all([
|
|
47
47
|
this.requests.listDeployment(),
|
|
48
48
|
this.requests.countPendingDeployment(),
|
|
49
49
|
this.catalog.list({ pending: true }),
|
|
50
50
|
this.scopeSyncFailures(),
|
|
51
51
|
this.countScopeSyncFailures(),
|
|
52
|
+
this.disabledExtensions(),
|
|
53
|
+
this.countDisabledExtensions(),
|
|
52
54
|
this.notices(),
|
|
53
55
|
this.countNotices(),
|
|
54
56
|
]);
|
|
@@ -71,6 +73,12 @@ let PlatformInboxService = class PlatformInboxService {
|
|
|
71
73
|
createdAt: f.failedAt,
|
|
72
74
|
failure: f,
|
|
73
75
|
})),
|
|
76
|
+
...disabled.map((d) => ({
|
|
77
|
+
type: "extension_disabled",
|
|
78
|
+
id: d.item.id,
|
|
79
|
+
createdAt: d.since,
|
|
80
|
+
disabled: d,
|
|
81
|
+
})),
|
|
74
82
|
...notices.map((n) => ({
|
|
75
83
|
type: "ownership_transferred",
|
|
76
84
|
id: n.id,
|
|
@@ -94,6 +102,7 @@ let PlatformInboxService = class PlatformInboxService {
|
|
|
94
102
|
permission_confirmation: pending.length - orgUploads,
|
|
95
103
|
org_upload_pending: orgUploads,
|
|
96
104
|
scope_sync_failed: failureCount,
|
|
105
|
+
extension_disabled: disabledCount,
|
|
97
106
|
ownership_transferred: noticeCount,
|
|
98
107
|
};
|
|
99
108
|
const total = Object.values(byType).reduce((a, b) => a + b, 0);
|
|
@@ -105,13 +114,14 @@ let PlatformInboxService = class PlatformInboxService {
|
|
|
105
114
|
* requests and the failures; the permission confirmations are the catalog's pending list).
|
|
106
115
|
*/
|
|
107
116
|
async count() {
|
|
108
|
-
const [requests, pending, failures, notices] = await Promise.all([
|
|
117
|
+
const [requests, pending, failures, disabled, notices] = await Promise.all([
|
|
109
118
|
this.requests.countPendingDeployment(),
|
|
110
119
|
this.catalog.list({ pending: true }),
|
|
111
120
|
this.countScopeSyncFailures(),
|
|
121
|
+
this.countDisabledExtensions(),
|
|
112
122
|
this.countNotices(),
|
|
113
123
|
]);
|
|
114
|
-
return requests + pending.length + failures + notices;
|
|
124
|
+
return requests + pending.length + failures + disabled + notices;
|
|
115
125
|
}
|
|
116
126
|
async countNotices() {
|
|
117
127
|
const r = await this.kdb.db
|
|
@@ -161,6 +171,26 @@ let PlatformInboxService = class PlatformInboxService {
|
|
|
161
171
|
if (!exists)
|
|
162
172
|
throw new ApiError("inbox.notice_not_found", "Notice not found");
|
|
163
173
|
}
|
|
174
|
+
async countDisabledExtensions() {
|
|
175
|
+
const r = await disabledExtensionRows(this.kdb)
|
|
176
|
+
.select(sql `count(*)`.as("n"))
|
|
177
|
+
.executeTakeFirstOrThrow();
|
|
178
|
+
return Number(r.n);
|
|
179
|
+
}
|
|
180
|
+
/** The plugins on by scope whose extension is disabled, newest change first. */
|
|
181
|
+
async disabledExtensions() {
|
|
182
|
+
const rows = await disabledExtensionRows(this.kdb)
|
|
183
|
+
.select(["i.id", "i.name", "i.display_name", "e.version", "e.updated_at"])
|
|
184
|
+
.orderBy("e.updated_at", "desc")
|
|
185
|
+
.orderBy("i.id")
|
|
186
|
+
.limit(PLATFORM_INBOX_MAX_ITEMS)
|
|
187
|
+
.execute();
|
|
188
|
+
return rows.map((r) => ({
|
|
189
|
+
item: { id: r.id, name: r.name, displayName: r.display_name },
|
|
190
|
+
extension: { name: r.name, version: r.version },
|
|
191
|
+
since: r.updated_at.toISOString(),
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
164
194
|
/**
|
|
165
195
|
* The open failures still worth a look, joined to their item and org: of a live item and org,
|
|
166
196
|
* and the pair still differs in the failed direction (a person may have converged it meanwhile):
|
|
@@ -180,7 +210,7 @@ let PlatformInboxService = class PlatformInboxService {
|
|
|
180
210
|
.select("p.id")
|
|
181
211
|
.whereRef("p.org_id", "=", "f.org_id")
|
|
182
212
|
.whereRef("p.item_id", "=", "f.item_id")
|
|
183
|
-
.where("p.status", "in", [...
|
|
213
|
+
.where("p.status", "in", [...LIVE_INSTALL_STATUSES]));
|
|
184
214
|
return eb.or([
|
|
185
215
|
eb.and([eb("f.op", "=", "install"), eb.not(live)]),
|
|
186
216
|
eb.and([eb("f.op", "in", ["uninstall", "dependencies"]), live]),
|
|
@@ -229,4 +259,24 @@ PlatformInboxService = __decorate([
|
|
|
229
259
|
__param(2, Inject(KernelDb))
|
|
230
260
|
], PlatformInboxService);
|
|
231
261
|
export { PlatformInboxService };
|
|
262
|
+
/**
|
|
263
|
+
* The rows of {@link ExtensionDisabledView}: a live, usable, not builtin, not disabled item whose
|
|
264
|
+
* scope is not `optional`, joined to its extension's install record (same name) that is disabled
|
|
265
|
+
* and approved (a permission snapshot exists; an unapproved one is a permission confirmation).
|
|
266
|
+
*/
|
|
267
|
+
function disabledExtensionRows(kdb) {
|
|
268
|
+
return kdb.db
|
|
269
|
+
.selectFrom("catalog_items as i")
|
|
270
|
+
.innerJoin("extension_installs as e", "e.name", "i.name")
|
|
271
|
+
.where("i.deleted_at", "is", null)
|
|
272
|
+
.where("i.builtin", "=", false)
|
|
273
|
+
.where("i.disabled", "=", false)
|
|
274
|
+
.where("i.awaiting_confirmation", "=", false)
|
|
275
|
+
.where("i.scope", "<>", "optional")
|
|
276
|
+
.where("e.desired_state", "=", "disabled")
|
|
277
|
+
.where((eb) => eb.exists(eb
|
|
278
|
+
.selectFrom("extension_permission_snapshots as s")
|
|
279
|
+
.select("s.plugin")
|
|
280
|
+
.whereRef("s.plugin", "=", "e.name")));
|
|
281
|
+
}
|
|
232
282
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { closeKernelApp, createKernelApp, type KernelAppOptions, kernelAppHttp,
|
|
|
3
3
|
export { type CatalogCli, openCatalogCli } from "./catalog/cli.js";
|
|
4
4
|
export { GitSourceError, type ReadGitTreeOptions, readGitTree, } from "./catalog/git-source.js";
|
|
5
5
|
export type { PluginConfirmResult, PluginReview } from "./catalog/plugin-import.js";
|
|
6
|
-
export {
|
|
6
|
+
export { type PluginPackage, PluginPackageError, type ReadPluginPackageOptions, readPluginPackage, } from "./catalog/plugin-package.js";
|
|
7
7
|
export { gatewayReplicasKey } from "./channels/supervisor.js";
|
|
8
8
|
export { envName, renderConfigDocs } from "./config/docs.js";
|
|
9
9
|
export { envOverrides } from "./config/env.js";
|
|
@@ -19,7 +19,7 @@ export { createExtensionContext, type KernelDeps, pluginSchemaName, type Route,
|
|
|
19
19
|
export { createKv } from "./ctx/kv.js";
|
|
20
20
|
export { createLock } from "./ctx/lock.js";
|
|
21
21
|
export { createQueue } from "./ctx/queue.js";
|
|
22
|
-
export { createKeyring, createSecrets, type DerivedKeys, type Keyring,
|
|
22
|
+
export { createKeyring, createSecrets, type DerivedKeys, type Keyring, REWRAP_BATCH_SIZE, type RewrapResult, rewrapToCurrentMasterKey, } from "./ctx/secrets.js";
|
|
23
23
|
export { type KernelDatabase, type KernelSchemaDb, kernelDb } from "./db/kernel-schema.js";
|
|
24
24
|
export { type MigrationOwner, migrate } from "./db/migrator.js";
|
|
25
25
|
export { createDb } from "./db/pool.js";
|
|
@@ -54,6 +54,8 @@ export { DUMMY_PASSWORD_HASH, hashPassword, verifyPassword } from "./identity/pa
|
|
|
54
54
|
export { type IssuedSession, REFRESH_RACE_GRACE_MS, SessionService, } from "./identity/sessions.js";
|
|
55
55
|
export { DEPLOYMENT_SETTINGS, type DeploymentSettings, SettingsService, } from "./identity/settings.js";
|
|
56
56
|
export { type KernelCliOptions, openKernelCli, openKernelCliOverPool, } from "./infra/cli/kernel-cli.module.js";
|
|
57
|
+
export { rewrapMasterKeys } from "./infra/cli/master-key-rewrap.js";
|
|
58
|
+
export { onProcessFault } from "./infra/health/process-fault.js";
|
|
57
59
|
export { GUARD_CIRCUIT_LIMIT, GUARD_CIRCUIT_WINDOW_MS, installProcessGuards, type ProcessGuardDeps, } from "./infra/lifecycle/process-guards.js";
|
|
58
60
|
export { handleShutdownSignals, type ShutdownSignalHandle, type ShutdownSignalOptions, } from "./infra/lifecycle/shutdown-signals.js";
|
|
59
61
|
export { KERNEL_MIGRATIONS_DIR, KERNEL_SCHEMA, migrateAll } from "./kernel.js";
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { closeKernelApp, createKernelApp, kernelAppHttp, kernelAppPort, startKer
|
|
|
3
3
|
export { openCatalogCli } from "./catalog/cli.js";
|
|
4
4
|
// The git reader marketplaces use; core's check:bootstrap reads the official marketplace with it.
|
|
5
5
|
export { GitSourceError, readGitTree, } from "./catalog/git-source.js";
|
|
6
|
-
export {
|
|
6
|
+
export { PluginPackageError, readPluginPackage, } from "./catalog/plugin-package.js";
|
|
7
7
|
export { gatewayReplicasKey } from "./channels/supervisor.js";
|
|
8
8
|
export { envName, renderConfigDocs } from "./config/docs.js";
|
|
9
9
|
export { envOverrides } from "./config/env.js";
|
|
@@ -18,7 +18,7 @@ export { createExtensionContext, pluginSchemaName, } from "./ctx/create-ctx.js";
|
|
|
18
18
|
export { createKv } from "./ctx/kv.js";
|
|
19
19
|
export { createLock } from "./ctx/lock.js";
|
|
20
20
|
export { createQueue } from "./ctx/queue.js";
|
|
21
|
-
export { createKeyring, createSecrets,
|
|
21
|
+
export { createKeyring, createSecrets, REWRAP_BATCH_SIZE, rewrapToCurrentMasterKey, } from "./ctx/secrets.js";
|
|
22
22
|
export { kernelDb } from "./db/kernel-schema.js";
|
|
23
23
|
export { migrate } from "./db/migrator.js";
|
|
24
24
|
export { createDb } from "./db/pool.js";
|
|
@@ -52,6 +52,8 @@ export { DUMMY_PASSWORD_HASH, hashPassword, verifyPassword } from "./identity/pa
|
|
|
52
52
|
export { REFRESH_RACE_GRACE_MS, SessionService, } from "./identity/sessions.js";
|
|
53
53
|
export { DEPLOYMENT_SETTINGS, SettingsService, } from "./identity/settings.js";
|
|
54
54
|
export { openKernelCli, openKernelCliOverPool, } from "./infra/cli/kernel-cli.module.js";
|
|
55
|
+
export { rewrapMasterKeys } from "./infra/cli/master-key-rewrap.js";
|
|
56
|
+
export { onProcessFault } from "./infra/health/process-fault.js";
|
|
55
57
|
export { GUARD_CIRCUIT_LIMIT, GUARD_CIRCUIT_WINDOW_MS, installProcessGuards, } from "./infra/lifecycle/process-guards.js";
|
|
56
58
|
export { handleShutdownSignals, } from "./infra/lifecycle/shutdown-signals.js";
|
|
57
59
|
export { KERNEL_MIGRATIONS_DIR, KERNEL_SCHEMA, migrateAll } from "./kernel.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { KernelConfig } from "../../config/schema.js";
|
|
2
|
+
import { type RewrapResult } from "../../ctx/secrets.js";
|
|
3
|
+
import type { KernelLogger } from "../../log.js";
|
|
4
|
+
/**
|
|
5
|
+
* `capybara secrets rewrap`: opens a PostgreSQL-only CLI context over `config` (its keyring is
|
|
6
|
+
* `masterKey` plus `masterKeyPrevious`) and rewraps everything sealed with a previous master key
|
|
7
|
+
* with the current one ({@link rewrapToCurrentMasterKey}). Returns the counts and the current
|
|
8
|
+
* master key id (a hash prefix, never key material).
|
|
9
|
+
*/
|
|
10
|
+
export declare function rewrapMasterKeys(config: KernelConfig, opts: {
|
|
11
|
+
logger: KernelLogger;
|
|
12
|
+
batchSize?: number;
|
|
13
|
+
}): Promise<RewrapResult & {
|
|
14
|
+
currentMasterKeyId: string;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { rewrapToCurrentMasterKey } from "../../ctx/secrets.js";
|
|
2
|
+
import { KernelDb } from "../database/kernel-db.js";
|
|
3
|
+
import { TransactionHost } from "../database/transaction-host.js";
|
|
4
|
+
import { KEYRING } from "../tokens.js";
|
|
5
|
+
import { openKernelCli } from "./kernel-cli.module.js";
|
|
6
|
+
/**
|
|
7
|
+
* `capybara secrets rewrap`: opens a PostgreSQL-only CLI context over `config` (its keyring is
|
|
8
|
+
* `masterKey` plus `masterKeyPrevious`) and rewraps everything sealed with a previous master key
|
|
9
|
+
* with the current one ({@link rewrapToCurrentMasterKey}). Returns the counts and the current
|
|
10
|
+
* master key id (a hash prefix, never key material).
|
|
11
|
+
*/
|
|
12
|
+
export async function rewrapMasterKeys(config, opts) {
|
|
13
|
+
const app = await openKernelCli(config, { logger: opts.logger, modules: [], redis: false });
|
|
14
|
+
try {
|
|
15
|
+
const keyring = app.get(KEYRING);
|
|
16
|
+
const result = await rewrapToCurrentMasterKey({ db: app.get(KernelDb), txHost: app.get(TransactionHost) }, keyring, opts.batchSize !== undefined ? { batchSize: opts.batchSize } : {});
|
|
17
|
+
return { ...result, currentMasterKeyId: keyring.currentId };
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
await app.close().catch((err) => {
|
|
21
|
+
opts.logger.debug("secrets rewrap: closing the CLI context failed", { err });
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -69,18 +69,6 @@ const HOT_APPLIERS = {
|
|
|
69
69
|
"attribution.pr": () => { },
|
|
70
70
|
"attribution.sessionUrl": () => { },
|
|
71
71
|
};
|
|
72
|
-
/**
|
|
73
|
-
* Environment variables of renamed config keys, with their replacements: warned about once when
|
|
74
|
-
* the service starts (agent map spec §6: `subagents.maxConcurrentPerRun` became
|
|
75
|
-
* `subagents.maxConcurrentPerConversation`). A retired file or Nacos key cannot be told here: the
|
|
76
|
-
* schema strips unknown keys before the kernel receives its config.
|
|
77
|
-
*/
|
|
78
|
-
const RETIRED_ENV = [
|
|
79
|
-
[
|
|
80
|
-
"CAPYBARA_SUBAGENTS__MAX_CONCURRENT_PER_RUN",
|
|
81
|
-
"CAPYBARA_SUBAGENTS__MAX_CONCURRENT_PER_CONVERSATION",
|
|
82
|
-
],
|
|
83
|
-
];
|
|
84
72
|
const HOT_PATHS = configFields(KernelConfigSchema)
|
|
85
73
|
.filter((f) => f.meta?.hot)
|
|
86
74
|
.map((f) => f.path);
|
|
@@ -101,11 +89,6 @@ let KernelConfigService = class KernelConfigService {
|
|
|
101
89
|
this.env = input.env ?? process.env;
|
|
102
90
|
log.setLevel(input.config.log.level);
|
|
103
91
|
log.addSecrets(secretValues(KernelConfigSchema, input.config));
|
|
104
|
-
for (const [old, now] of RETIRED_ENV) {
|
|
105
|
-
if (this.env[old] !== undefined) {
|
|
106
|
-
log.warn(`${old} is no longer read and is ignored; set ${now} instead`, { env: old });
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
92
|
}
|
|
110
93
|
get() {
|
|
111
94
|
return this.current;
|
|
@@ -12,6 +12,7 @@ import { HealthCheckService, HealthIndicatorService, } from "@nestjs/terminus";
|
|
|
12
12
|
import { Public } from "../../identity/principal.js";
|
|
13
13
|
import { KERNEL_LOGGER } from "../tokens.js";
|
|
14
14
|
import { HEALTH_CHECKS } from "./health.options.js";
|
|
15
|
+
import { processFault } from "./process-fault.js";
|
|
15
16
|
import { SHUTDOWN_STATE } from "./shutdown-state.js";
|
|
16
17
|
/** A dependency that hangs (Redis reconnecting, commands in the offline queue) must still give 503 fast. */
|
|
17
18
|
export const CHECK_TIMEOUT_MS = 2_000;
|
|
@@ -45,6 +46,13 @@ let HealthController = class HealthController {
|
|
|
45
46
|
};
|
|
46
47
|
if (this.shutdown.isShuttingDown())
|
|
47
48
|
return stopping();
|
|
49
|
+
// A swallowed fatal event: not ready while `capybara start` stops gracefully and exits 1
|
|
50
|
+
// (liveness stays)
|
|
51
|
+
const faulted = processFault();
|
|
52
|
+
if (faulted !== undefined) {
|
|
53
|
+
reply.code(503);
|
|
54
|
+
return { ok: false, faulted: faulted.kind };
|
|
55
|
+
}
|
|
48
56
|
const names = Object.keys(this.checks);
|
|
49
57
|
const logged = new Set();
|
|
50
58
|
const fns = names.map((name) => () => this.indicators
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks this process faulted (idempotent: the first kind stays, and only the first mark notifies
|
|
3
|
+
* the listeners; a listener that throws does not keep the others from running).
|
|
4
|
+
*/
|
|
5
|
+
export declare function markProcessFaulted(kind: string): void;
|
|
6
|
+
/** The kind of the first swallowed fatal event, or `undefined` while the process is clean. */
|
|
7
|
+
export declare function processFault(): {
|
|
8
|
+
kind: string;
|
|
9
|
+
} | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Calls `listener` when this process is marked faulted (at once when it already is); returns a
|
|
12
|
+
* function that removes it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function onProcessFault(listener: (kind: string) => void): () => void;
|
|
15
|
+
/** Test seam: clears the state (the listeners stay). */
|
|
16
|
+
export declare function resetProcessFault(): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this process swallowed a fatal event (an unhandled rejection or uncaught exception the
|
|
3
|
+
* process guards kept running through). Readiness answers 503 from then on, and `capybara start`
|
|
4
|
+
* stops gracefully and exits with 1 (`onProcessFault`, wired by `handleShutdownSignals`) so any
|
|
5
|
+
* restart policy replaces the process; liveness is unchanged. Per-process state about this process
|
|
6
|
+
* itself, never shared across replicas, and never cleared (a faulted process is meant to be
|
|
7
|
+
* replaced).
|
|
8
|
+
*/
|
|
9
|
+
let fault;
|
|
10
|
+
const listeners = new Set();
|
|
11
|
+
/**
|
|
12
|
+
* Marks this process faulted (idempotent: the first kind stays, and only the first mark notifies
|
|
13
|
+
* the listeners; a listener that throws does not keep the others from running).
|
|
14
|
+
*/
|
|
15
|
+
export function markProcessFaulted(kind) {
|
|
16
|
+
if (fault !== undefined)
|
|
17
|
+
return;
|
|
18
|
+
fault = { kind };
|
|
19
|
+
for (const l of [...listeners]) {
|
|
20
|
+
try {
|
|
21
|
+
l(kind);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// a listener failing must not stop the others (nor reach the guard that marked the fault)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** The kind of the first swallowed fatal event, or `undefined` while the process is clean. */
|
|
29
|
+
export function processFault() {
|
|
30
|
+
return fault;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Calls `listener` when this process is marked faulted (at once when it already is); returns a
|
|
34
|
+
* function that removes it.
|
|
35
|
+
*/
|
|
36
|
+
export function onProcessFault(listener) {
|
|
37
|
+
if (fault !== undefined) {
|
|
38
|
+
listener(fault.kind);
|
|
39
|
+
return () => { };
|
|
40
|
+
}
|
|
41
|
+
listeners.add(listener);
|
|
42
|
+
return () => {
|
|
43
|
+
listeners.delete(listener);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Test seam: clears the state (the listeners stay). */
|
|
47
|
+
export function resetProcessFault() {
|
|
48
|
+
fault = undefined;
|
|
49
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { KernelLogger } from "../../log.js";
|
|
2
2
|
/**
|
|
3
3
|
* Process-level guards for `capybara start`: an unhandled rejection or an uncaught exception is
|
|
4
|
-
* logged and the process
|
|
4
|
+
* logged and does not kill the process at once: it stops gracefully instead (see below), unless
|
|
5
|
+
* the events come in bursts.
|
|
5
6
|
*
|
|
6
7
|
* Node's default for an async failure nobody handles is to kill the process. That default assumes
|
|
7
8
|
* the program state is corrupt, which holds for errors thrown by business logic, but the ones seen
|
|
@@ -16,7 +17,12 @@ import type { KernelLogger } from "../../log.js";
|
|
|
16
17
|
*
|
|
17
18
|
* What this cannot save: a V8 heap exhaustion is a hard abort no listener sees; and a resource that
|
|
18
19
|
* first fails through an uncaught event and afterwards only through caught errors (500s) keeps the
|
|
19
|
-
* process alive but broken, which used to self-heal through a crash and a restart.
|
|
20
|
+
* process alive but broken, which used to self-heal through a crash and a restart. To keep that
|
|
21
|
+
* self-healing, every swallowed fatal event marks the process faulted (`markProcessFaulted`):
|
|
22
|
+
* `/readyz` answers 503 from then on, and `capybara start` runs its graceful stop (the bounded
|
|
23
|
+
* drain of a SIGTERM) and exits with 1, so any restart policy starts a clean process (readiness
|
|
24
|
+
* alone restarts nothing). `/healthz` (liveness) is unchanged. The record carries
|
|
25
|
+
* `severity: "fatal"` (the logger has no fatal level).
|
|
20
26
|
*
|
|
21
27
|
* Every line of the recorder is wrapped: a handler that throws while the process handles a fatal
|
|
22
28
|
* event would defeat the guard. Records go through the kernel logger (pino, redacted) with
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { markProcessFaulted } from "../health/process-fault.js";
|
|
1
2
|
/**
|
|
2
3
|
* Process-level guards for `capybara start`: an unhandled rejection or an uncaught exception is
|
|
3
|
-
* logged and the process
|
|
4
|
+
* logged and does not kill the process at once: it stops gracefully instead (see below), unless
|
|
5
|
+
* the events come in bursts.
|
|
4
6
|
*
|
|
5
7
|
* Node's default for an async failure nobody handles is to kill the process. That default assumes
|
|
6
8
|
* the program state is corrupt, which holds for errors thrown by business logic, but the ones seen
|
|
@@ -15,7 +17,12 @@
|
|
|
15
17
|
*
|
|
16
18
|
* What this cannot save: a V8 heap exhaustion is a hard abort no listener sees; and a resource that
|
|
17
19
|
* first fails through an uncaught event and afterwards only through caught errors (500s) keeps the
|
|
18
|
-
* process alive but broken, which used to self-heal through a crash and a restart.
|
|
20
|
+
* process alive but broken, which used to self-heal through a crash and a restart. To keep that
|
|
21
|
+
* self-healing, every swallowed fatal event marks the process faulted (`markProcessFaulted`):
|
|
22
|
+
* `/readyz` answers 503 from then on, and `capybara start` runs its graceful stop (the bounded
|
|
23
|
+
* drain of a SIGTERM) and exits with 1, so any restart policy starts a clean process (readiness
|
|
24
|
+
* alone restarts nothing). `/healthz` (liveness) is unchanged. The record carries
|
|
25
|
+
* `severity: "fatal"` (the logger has no fatal level).
|
|
19
26
|
*
|
|
20
27
|
* Every line of the recorder is wrapped: a handler that throws while the process handles a fatal
|
|
21
28
|
* event would defeat the guard. Records go through the kernel logger (pino, redacted) with
|
|
@@ -47,13 +54,15 @@ export function createFatalRecorder(deps) {
|
|
|
47
54
|
const t = now();
|
|
48
55
|
recent = recent.filter((x) => t - x < GUARD_CIRCUIT_WINDOW_MS);
|
|
49
56
|
recent.push(t);
|
|
57
|
+
safely(() => markProcessFaulted(kind));
|
|
50
58
|
safely(() => deps
|
|
51
59
|
.log()
|
|
52
|
-
.error(kind === "unhandledRejection" ? "unhandled promise rejection" : "uncaught exception", { marker: GUARD_LOG_MARKER, kind, err }));
|
|
60
|
+
.error(kind === "unhandledRejection" ? "unhandled promise rejection" : "uncaught exception", { marker: GUARD_LOG_MARKER, severity: "fatal", kind, err }));
|
|
53
61
|
if (recent.length > GUARD_CIRCUIT_LIMIT && !open) {
|
|
54
62
|
open = true;
|
|
55
63
|
safely(() => deps.log().error("too many fatal events; exiting so the process is restarted clean", {
|
|
56
64
|
marker: GUARD_LOG_MARKER,
|
|
65
|
+
severity: "fatal",
|
|
57
66
|
kind: "circuit-open",
|
|
58
67
|
events: recent.length,
|
|
59
68
|
windowMs: GUARD_CIRCUIT_WINDOW_MS,
|