@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.38
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 -2
- package/dist/admin/admin.module.js +9 -5
- 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/org-network.controller.d.ts +30 -0
- package/dist/admin/org-network.controller.js +77 -0
- package/dist/admin/org-network.schemas.d.ts +16 -0
- package/dist/admin/org-network.schemas.js +27 -0
- package/dist/admin/org-network.service.d.ts +41 -0
- package/dist/admin/org-network.service.js +101 -0
- 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.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 +4 -12
- package/dist/agents/readiness.controller.js +4 -12
- package/dist/agents/readiness.service.d.ts +23 -11
- package/dist/agents/readiness.service.js +31 -14
- 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 +54 -47
- package/dist/config/schema.js +198 -42
- 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/event-log.js +4 -1
- 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.d.ts +8 -1
- package/dist/ctx/create-ctx.js +13 -3
- package/dist/ctx/net.d.ts +50 -0
- package/dist/ctx/net.js +67 -0
- package/dist/ctx/secrets.d.ts +24 -7
- package/dist/ctx/secrets.js +97 -30
- package/dist/db/kernel-schema.d.ts +27 -6
- package/dist/devices/devices.service.js +2 -1
- package/dist/errors.d.ts +10 -2
- package/dist/errors.js +10 -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/extensions.module.js +3 -0
- package/dist/extensions/host.d.ts +9 -4
- package/dist/extensions/host.js +14 -8
- 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 +4 -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/database/transaction-host.d.ts +32 -1
- package/dist/infra/database/transaction-host.js +30 -4
- package/dist/infra/database/xact-lock.d.ts +16 -0
- package/dist/infra/database/xact-lock.js +28 -1
- 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/net/public-address.d.ts +21 -1
- package/dist/net/public-address.js +56 -10
- package/dist/net/safe-fetch.d.ts +4 -1
- package/dist/net/safe-fetch.js +15 -4
- package/dist/orgs/directory-sync.js +2 -0
- package/dist/orgs/members.service.js +5 -0
- package/dist/orgs/network-allowances.service.d.ts +79 -0
- package/dist/orgs/network-allowances.service.js +371 -0
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +9 -2
- package/dist/orgs/org-lock.d.ts +28 -2
- package/dist/orgs/org-lock.js +59 -4
- package/dist/orgs/orgs.controller.d.ts +11 -2
- package/dist/orgs/orgs.controller.js +19 -3
- package/dist/orgs/orgs.module.d.ts +3 -2
- package/dist/orgs/orgs.module.js +6 -2
- package/dist/orgs/orgs.schemas.d.ts +12 -0
- package/dist/orgs/orgs.schemas.js +5 -0
- package/dist/orgs/orgs.service.js +6 -1
- 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 +7 -7
- package/dist/overrides.js +4 -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.js +1 -1
- 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 +11 -3
- package/dist/platform/ops/orgs.ops.js +139 -5
- package/dist/platform/ops/outbox.ops.js +5 -5
- package/dist/platform/route-schemas.js +3 -0
- package/dist/roles/worker-role.d.ts +2 -3
- package/dist/roles/worker-role.js +3 -13
- package/dist/runtime/checkpointer.d.ts +3 -0
- package/dist/runtime/checkpointer.js +7 -4
- 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 +9 -3
- 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.d.ts +56 -3
- package/dist/runtime/run-execution.js +81 -11
- 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/step-log.d.ts +5 -0
- package/dist/runtime/step-log.js +9 -4
- 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/runtime/waits.js +3 -1
- 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/connector-content.js +1 -0
- 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 +65 -6
- package/dist/tools/drift.d.ts +6 -2
- package/dist/tools/drift.js +10 -5
- 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 +17 -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/src/migrations/0145_org_network_allowances.sql +12 -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
|
@@ -7,23 +7,79 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
12
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
12
13
|
import { TransactionHost, withTransactionFence } from "../infra/database/transaction-host.js";
|
|
13
14
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
15
|
+
import { XactLock } from "../infra/database/xact-lock.js";
|
|
16
|
+
import { isLive } from "./run-liveness.js";
|
|
14
17
|
import { rootConversationOf } from "./subagents/child.js";
|
|
18
|
+
/** Set inside a tool step: every fenced transaction there is admitted exclusively. */
|
|
19
|
+
const exclusiveScope = new AsyncLocalStorage();
|
|
20
|
+
/**
|
|
21
|
+
* Runs `fn` (a tool step, a sub-agent dispatch) with every fenced transaction it opens admitted
|
|
22
|
+
* exclusively, even one that asks for shared admission (an event append made by a tool). Tool code
|
|
23
|
+
* takes org-level locks (`OrgLock`, agents, memberships, devices) after the conversation rows,
|
|
24
|
+
* which only the exclusive admission (the org row first) keeps in the global lock order; a
|
|
25
|
+
* transaction asking for shared admission takes none (an org-level lock in one throws,
|
|
26
|
+
* `assertNotSharedAdmission`), so this scope is not what keeps the order: it keeps tool steps
|
|
27
|
+
* serialized per org as the design states, and is defence in depth for a write a tool makes
|
|
28
|
+
* through a path marked shared.
|
|
29
|
+
*/
|
|
30
|
+
export function withExclusiveAdmission(fn) {
|
|
31
|
+
return exclusiveScope.run(true, fn);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Whether the caller runs inside {@link withExclusiveAdmission} (a tool step, a dispatch). A test
|
|
35
|
+
* seam: the kernel never reads it (the fence reads the scope directly); tests use it to prove which
|
|
36
|
+
* loop steps run under exclusive admission (`langgraph-loop.test.ts`).
|
|
37
|
+
*/
|
|
38
|
+
export function inExclusiveAdmission() {
|
|
39
|
+
return exclusiveScope.getStore() === true;
|
|
40
|
+
}
|
|
15
41
|
/** Internal interruption: a revoked execution must never write its own terminal failure. */
|
|
16
42
|
export class ExecutionRevoked extends Error {
|
|
17
43
|
constructor() {
|
|
18
44
|
super("execution revoked");
|
|
19
45
|
}
|
|
20
46
|
}
|
|
21
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Claims serialize on the same conversation lock as the event log and all fenced writes.
|
|
49
|
+
*
|
|
50
|
+
* The fence admits every writable transaction of a claimed run in one of two modes, then locks the
|
|
51
|
+
* root and the current conversation rows `FOR NO KEY UPDATE` and compares `runs.execution_id`:
|
|
52
|
+
* - **exclusive** (the default, and every transaction inside a tool step,
|
|
53
|
+
* {@link withExclusiveAdmission}: conformance with the design and defence in depth): the org row
|
|
54
|
+
* `FOR NO KEY UPDATE`, `OrgLock`'s mode. These
|
|
55
|
+
* transactions serialize per org with each other and with org admin writes, so whatever they
|
|
56
|
+
* lock after the conversation rows (`OrgLock`, agents, memberships, the default device) stays in
|
|
57
|
+
* the order org row → conversations that offboarding and the decisions take.
|
|
58
|
+
* - **shared** (a transaction opened with `admission: "shared"`: the run loop's event appends,
|
|
59
|
+
* checkpoint writes and suspend): the org admission lock shared
|
|
60
|
+
* (`XactLock.admitOrgShared`), and the org row read without a lock. These transactions lock
|
|
61
|
+
* nothing org-level after the conversation rows (enforced: `OrgLock`, the membership locks and
|
|
62
|
+
* `XactLock.lock` throw in one, `assertNotSharedAdmission`; only READ COMMITTED), so the runs of
|
|
63
|
+
* one org append in parallel.
|
|
64
|
+
* Org deletion and offboarding take the admission lock exclusively first
|
|
65
|
+
* (`OrgLock.lockForRemoval`): they wait for the admitted writes, keep new ones out (a later one
|
|
66
|
+
* then sees the org deleted), and are not starved by a stream of them (the lock queues fairly).
|
|
67
|
+
*
|
|
68
|
+
* Global order: org admission lock → org row → root conversation → conversation; a writer that
|
|
69
|
+
* locks several conversation or run rows of one tree locks the tree's root first (the fence
|
|
70
|
+
* does, so every fenced write of a tree serializes on its root). A claim never
|
|
71
|
+
* opens a nested fenced `requires_new` transaction (shared or not) and waits for it while its
|
|
72
|
+
* outer fenced transaction is open: the inner one waits for the outer's root row (and, behind a
|
|
73
|
+
* queued deletion, for the admission lock) on another connection, which PostgreSQL cannot see as
|
|
74
|
+
* a deadlock.
|
|
75
|
+
*/
|
|
22
76
|
let RunExecution = class RunExecution {
|
|
23
77
|
db;
|
|
78
|
+
xactLock;
|
|
24
79
|
txHost;
|
|
25
|
-
constructor(db, txHost) {
|
|
80
|
+
constructor(db, xactLock, txHost) {
|
|
26
81
|
this.db = db;
|
|
82
|
+
this.xactLock = xactLock;
|
|
27
83
|
this.txHost = txHost;
|
|
28
84
|
}
|
|
29
85
|
async claim(conversationId, runId, executionId, live = () => true) {
|
|
@@ -51,9 +107,11 @@ let RunExecution = class RunExecution {
|
|
|
51
107
|
return run ? claim : null;
|
|
52
108
|
}
|
|
53
109
|
withClaim(claim, live, fn) {
|
|
54
|
-
return withTransactionFence(async () => {
|
|
55
|
-
|
|
110
|
+
return withTransactionFence(async ({ shared }) => {
|
|
111
|
+
const admitShared = shared && !exclusiveScope.getStore();
|
|
112
|
+
if (!live() || !(await this.lockLiveConversation(claim, admitShared))) {
|
|
56
113
|
throw new ExecutionRevoked();
|
|
114
|
+
}
|
|
57
115
|
const run = await this.db
|
|
58
116
|
.selectFrom("runs")
|
|
59
117
|
.select("execution_id")
|
|
@@ -62,17 +120,28 @@ let RunExecution = class RunExecution {
|
|
|
62
120
|
.executeTakeFirst();
|
|
63
121
|
if (run?.execution_id !== claim.executionId || !live())
|
|
64
122
|
throw new ExecutionRevoked();
|
|
123
|
+
return admitShared ? "shared" : "exclusive";
|
|
65
124
|
}, fn);
|
|
66
125
|
}
|
|
67
|
-
/**
|
|
68
|
-
|
|
126
|
+
/**
|
|
127
|
+
* The admission (see the class), then the root and the current conversation; NO KEY UPDATE
|
|
128
|
+
* allows foreign key references while excluding deletion and other writers. The root stays
|
|
129
|
+
* `FOR NO KEY UPDATE` in both modes: a sub-agent's handback appends to its parent (the root at
|
|
130
|
+
* depth 1) under `FOR UPDATE`, so two siblings holding the root only shared would deadlock
|
|
131
|
+
* upgrading it.
|
|
132
|
+
*/
|
|
133
|
+
async lockLiveConversation(claim, shared = false) {
|
|
134
|
+
// shared: after the admission lock, a plain read sees a committed deletion (a new statement
|
|
135
|
+
// under READ COMMITTED), and the deletion cannot commit before this transaction ends
|
|
136
|
+
if (shared)
|
|
137
|
+
await this.xactLock.admitOrgShared(claim.orgId);
|
|
69
138
|
const org = await this.db
|
|
70
139
|
.selectFrom("orgs")
|
|
71
140
|
.select("deleted_at")
|
|
72
141
|
.where("id", "=", claim.orgId)
|
|
73
|
-
.forNoKeyUpdate()
|
|
142
|
+
.$call((q) => (shared ? q : q.forNoKeyUpdate()))
|
|
74
143
|
.executeTakeFirst();
|
|
75
|
-
if (!org || org.deleted_at
|
|
144
|
+
if (!org || !isLive(org.deleted_at))
|
|
76
145
|
return false;
|
|
77
146
|
const root = await this.db
|
|
78
147
|
.selectFrom("conversations")
|
|
@@ -80,7 +149,7 @@ let RunExecution = class RunExecution {
|
|
|
80
149
|
.where("id", "=", claim.rootId)
|
|
81
150
|
.forNoKeyUpdate()
|
|
82
151
|
.executeTakeFirst();
|
|
83
|
-
if (!root || root.deleted_at
|
|
152
|
+
if (!root || !isLive(root.deleted_at))
|
|
84
153
|
return false;
|
|
85
154
|
if (claim.rootId === claim.conversationId)
|
|
86
155
|
return true;
|
|
@@ -91,7 +160,7 @@ let RunExecution = class RunExecution {
|
|
|
91
160
|
.where("org_id", "=", claim.orgId)
|
|
92
161
|
.forNoKeyUpdate()
|
|
93
162
|
.executeTakeFirst();
|
|
94
|
-
return conv !== undefined && conv.deleted_at
|
|
163
|
+
return conv !== undefined && isLive(conv.deleted_at);
|
|
95
164
|
}
|
|
96
165
|
};
|
|
97
166
|
__decorate([
|
|
@@ -100,6 +169,7 @@ __decorate([
|
|
|
100
169
|
RunExecution = __decorate([
|
|
101
170
|
Injectable(),
|
|
102
171
|
__param(0, Inject(KernelDb)),
|
|
103
|
-
__param(1, Inject(
|
|
172
|
+
__param(1, Inject(XactLock)),
|
|
173
|
+
__param(2, Inject(TransactionHost))
|
|
104
174
|
], RunExecution);
|
|
105
175
|
export { RunExecution };
|
|
@@ -21,6 +21,7 @@ import { ScheduledTaskRunTracker } from "../schedules/run-tracker.js";
|
|
|
21
21
|
import { ApprovalsService } from "../tools/approvals.service.js";
|
|
22
22
|
import { QuestionsService } from "../tools/questions.service.js";
|
|
23
23
|
import { ACTIVE_RUN_STATUSES, lockWaitRowsIn, oweEnsureRun, TERMINAL_STATUSES, } from "./run-jobs.js";
|
|
24
|
+
import { isLive } from "./run-liveness.js";
|
|
24
25
|
import { pairStoppedForks } from "./subagents/skill-fork.js";
|
|
25
26
|
import { oweDeliverToParent, oweStopChildren } from "./subagents/tree-jobs.js";
|
|
26
27
|
/**
|
|
@@ -149,7 +150,7 @@ let RunFinish = class RunFinish {
|
|
|
149
150
|
// ensureRun); owed here too, for when that never happens (an eval's hidden conversation never
|
|
150
151
|
// starts runs)
|
|
151
152
|
if (conv?.org_live &&
|
|
152
|
-
conv.deleted_at
|
|
153
|
+
isLive(conv.deleted_at) &&
|
|
153
154
|
(conv.kind === "chat" || conv.kind === "subagent")) {
|
|
154
155
|
await oweEnsureRun(this.outbox, a.conversationId, seq, conv.org_id);
|
|
155
156
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { KernelDb } from "../infra/database/kernel-db.js";
|
|
2
|
+
/**
|
|
3
|
+
* The one definition of "live" for runs: an org or conversation is live while it is not
|
|
4
|
+
* soft-deleted. Every path that decides from an org's or a conversation's deletion whether a run
|
|
5
|
+
* may start, keep executing or be stopped (queueing, wakes, the post-run ensure, the execution
|
|
6
|
+
* fence, the orphan check, deletion) goes through here; other rows' deletion (agents, accounts,
|
|
7
|
+
* devices) is not run liveness.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isLive(...deletedAt: ReadonlyArray<unknown>): boolean;
|
|
10
|
+
/** Whether the org exists and is live (a plain read; the fence takes its own lock variant). */
|
|
11
|
+
export declare function orgIsLive(t: Pick<KernelDb, "selectFrom">, orgId: string): Promise<boolean>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one definition of "live" for runs: an org or conversation is live while it is not
|
|
3
|
+
* soft-deleted. Every path that decides from an org's or a conversation's deletion whether a run
|
|
4
|
+
* may start, keep executing or be stopped (queueing, wakes, the post-run ensure, the execution
|
|
5
|
+
* fence, the orphan check, deletion) goes through here; other rows' deletion (agents, accounts,
|
|
6
|
+
* devices) is not run liveness.
|
|
7
|
+
*/
|
|
8
|
+
export function isLive(...deletedAt) {
|
|
9
|
+
return deletedAt.every((d) => d === null);
|
|
10
|
+
}
|
|
11
|
+
/** Whether the org exists and is live (a plain read; the fence takes its own lock variant). */
|
|
12
|
+
export async function orgIsLive(t, orgId) {
|
|
13
|
+
const org = await t
|
|
14
|
+
.selectFrom("orgs")
|
|
15
|
+
.select("deleted_at")
|
|
16
|
+
.where("id", "=", orgId)
|
|
17
|
+
.executeTakeFirst();
|
|
18
|
+
return org !== undefined && isLive(org.deleted_at);
|
|
19
|
+
}
|
|
@@ -24,6 +24,7 @@ import { QueueLostJobs } from "./queue-lost-jobs.js";
|
|
|
24
24
|
import { RunDeletion } from "./run-deletion.js";
|
|
25
25
|
import { notifyFinished, RunFinish } from "./run-finish.js";
|
|
26
26
|
import { RunJobs, runJobId, runQueueNameFor } from "./run-jobs.js";
|
|
27
|
+
import { isLive } from "./run-liveness.js";
|
|
27
28
|
import { RunQueue } from "./run-queue.js";
|
|
28
29
|
import { Waits } from "./waits.js";
|
|
29
30
|
/** The check's `@LockedInterval` job name (its run lock key: `cron:run-orphan-check`). */
|
|
@@ -83,7 +84,7 @@ export async function orphanCandidates(db, statuses, minAgeMs, limit, after) {
|
|
|
83
84
|
orgId: r.org_id,
|
|
84
85
|
kind: r.kind,
|
|
85
86
|
status: r.status,
|
|
86
|
-
deleted: r.conversation_deleted
|
|
87
|
+
deleted: !isLive(r.conversation_deleted, r.org_deleted),
|
|
87
88
|
jobId: r.job_id ?? runJobId(r.conversation_id, Number(r.trigger_seq)),
|
|
88
89
|
queue: runQueueNameFor(r.kind),
|
|
89
90
|
since: r.since,
|
|
@@ -27,6 +27,7 @@ import { KyselyCheckpointSaver } from "./checkpointer.js";
|
|
|
27
27
|
import { ConversationLock } from "./conversation-lock.js";
|
|
28
28
|
import { notifyFinished, RunFinish } from "./run-finish.js";
|
|
29
29
|
import { ACTIVE_RUN_STATUSES, RunJobs, runJobId, runQueueNameFor } from "./run-jobs.js";
|
|
30
|
+
import { isLive, orgIsLive } from "./run-liveness.js";
|
|
30
31
|
import { rootConversationOf } from "./subagents/child.js";
|
|
31
32
|
import { budgetWindowOf } from "./subagents/limits.js";
|
|
32
33
|
export { ACTIVE_RUN_STATUSES, ENSURE_RUN_BACKSTOP_MS, ENSURE_RUN_JOB, ensureRunJobId, RUN_QUEUE_NAME, runJobId, runQueueNameFor, SUBAGENT_RUN_QUEUE_NAME, } from "./run-jobs.js";
|
|
@@ -141,16 +142,12 @@ let RunQueue = class RunQueue {
|
|
|
141
142
|
.forUpdate()
|
|
142
143
|
.executeTakeFirst();
|
|
143
144
|
// a deleted conversation, or a sub-agent's / eval one, has no manual compaction
|
|
144
|
-
if (!conv || conv.deleted_at
|
|
145
|
+
if (!conv || !isLive(conv.deleted_at) || conv.kind !== "chat") {
|
|
145
146
|
throw new ApiError("conversation.not_found", "Conversation not found");
|
|
146
147
|
}
|
|
147
|
-
|
|
148
|
-
.selectFrom("orgs")
|
|
149
|
-
.select("deleted_at")
|
|
150
|
-
.where("id", "=", conv.org_id)
|
|
151
|
-
.executeTakeFirst();
|
|
152
|
-
if (!org || org.deleted_at !== null)
|
|
148
|
+
if (!(await orgIsLive(t, conv.org_id))) {
|
|
153
149
|
throw new ApiError("conversation.not_found", "Conversation not found");
|
|
150
|
+
}
|
|
154
151
|
const active = await t
|
|
155
152
|
.selectFrom("runs")
|
|
156
153
|
.select(["id", "compact"])
|
|
@@ -217,14 +214,9 @@ let RunQueue = class RunQueue {
|
|
|
217
214
|
if (conv?.kind !== "chat" && conv?.kind !== "subagent")
|
|
218
215
|
return null;
|
|
219
216
|
// A deleted conversation starts no run, whatever is still unconsumed or queued
|
|
220
|
-
if (conv.deleted_at
|
|
217
|
+
if (!isLive(conv.deleted_at))
|
|
221
218
|
return null;
|
|
222
|
-
|
|
223
|
-
.selectFrom("orgs")
|
|
224
|
-
.select("deleted_at")
|
|
225
|
-
.where("id", "=", conv.org_id)
|
|
226
|
-
.executeTakeFirst();
|
|
227
|
-
if (!org || org.deleted_at !== null)
|
|
219
|
+
if (!(await orgIsLive(t, conv.org_id)))
|
|
228
220
|
return null;
|
|
229
221
|
if (conv.kind === "subagent")
|
|
230
222
|
return this.childWakeIn(conversationId, conv, st);
|
|
@@ -515,7 +507,7 @@ let RunQueue = class RunQueue {
|
|
|
515
507
|
.select(["queue_paused", "deleted_at"])
|
|
516
508
|
.where("id", "=", rootId)
|
|
517
509
|
.executeTakeFirst();
|
|
518
|
-
if (!root || root.queue_paused || root.deleted_at
|
|
510
|
+
if (!root || root.queue_paused || !isLive(root.deleted_at))
|
|
519
511
|
return null;
|
|
520
512
|
const accountId = message.payload.authorAccountId;
|
|
521
513
|
if (!(await authorCanSend(t, rootId, accountId)))
|
|
@@ -552,7 +544,7 @@ let RunQueue = class RunQueue {
|
|
|
552
544
|
.select(["queue_paused", "deleted_at"])
|
|
553
545
|
.where("id", "=", rootId)
|
|
554
546
|
.executeTakeFirst();
|
|
555
|
-
if (!root || root.queue_paused || root.deleted_at
|
|
547
|
+
if (!root || root.queue_paused || !isLive(root.deleted_at))
|
|
556
548
|
return;
|
|
557
549
|
for (const c of await this.heldTree(rootId)) {
|
|
558
550
|
await this.jobs.oweEnsureRun(c.id, c.seq, c.org_id);
|
|
@@ -73,7 +73,7 @@ export declare class RunWorker {
|
|
|
73
73
|
private readonly titles;
|
|
74
74
|
/** Resolves a switched-to model at run start (fallback when it is gone; UI refresh B). */
|
|
75
75
|
private readonly models;
|
|
76
|
-
/** Run start's skills catalog snapshot
|
|
76
|
+
/** Run start's skills catalog snapshot. */
|
|
77
77
|
private readonly skillsCatalog;
|
|
78
78
|
/** Run start's run context (run context spec §5): who the agent is, the day, the person. */
|
|
79
79
|
private readonly runContext;
|
|
@@ -109,7 +109,7 @@ export declare class RunWorker {
|
|
|
109
109
|
titles: Pick<TitleQueue, "maybeEnqueue">,
|
|
110
110
|
/** Resolves a switched-to model at run start (fallback when it is gone; UI refresh B). */
|
|
111
111
|
models: Pick<ProviderRegistry, "resolve">,
|
|
112
|
-
/** Run start's skills catalog snapshot
|
|
112
|
+
/** Run start's skills catalog snapshot. */
|
|
113
113
|
skillsCatalog: Pick<SkillsCatalogService, "record">,
|
|
114
114
|
/** Run start's run context (run context spec §5): who the agent is, the day, the person. */
|
|
115
115
|
runContext: Pick<RunContextService, "record">,
|
|
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
11
11
|
import { DelayedError } from "bullmq";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
|
+
import { normalizeStoredDefinition } from "../agents/definition.js";
|
|
13
14
|
import { EventLog } from "../conversations/event-log.js";
|
|
14
15
|
import { isAbsorbable, } from "../conversations/events.js";
|
|
15
16
|
import { effectiveDefinition, NO_SELECTION, readSelection, sameModel, sameSelection, } from "../conversations/selection.js";
|
|
@@ -24,7 +25,6 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
|
24
25
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
25
26
|
import { KERNEL_BUS, KERNEL_LOGGER } from "../infra/tokens.js";
|
|
26
27
|
import { SkillsCatalogService } from "../skills/catalog.js";
|
|
27
|
-
import { normalizeStoredDefinitionIn } from "../tools/legacy-data.js";
|
|
28
28
|
import { ToolRegistry } from "../tools/registry.js";
|
|
29
29
|
import { RunAbort } from "./abort.js";
|
|
30
30
|
import { KyselyCheckpointSaver } from "./checkpointer.js";
|
|
@@ -58,8 +58,10 @@ const FOLLOW_UP_MIN_WAIT_MS = 250;
|
|
|
58
58
|
/** 读插话的分页大小。 */
|
|
59
59
|
const READ_PAGE = 500;
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
61
|
+
* Retry delays when the post-run ensureRun fails (3 retries after the first try). In-process timers:
|
|
62
|
+
* this is follow-up work for a job this process just finished, tracked and time-bounded by close().
|
|
63
|
+
* If every try fails the conversation is not stuck: the `run-orphan-check` repairs it (SSE and reads
|
|
64
|
+
* no longer call ensureRun). The ladder only shortens recovery from common transient failures.
|
|
63
65
|
*/
|
|
64
66
|
const ENSURE_RETRY_DELAYS_MS = [200, 1000, 3000];
|
|
65
67
|
/** Optional provider: the run worker's {@link RunHooks} (tests). */
|
|
@@ -130,7 +132,7 @@ let RunWorker = class RunWorker {
|
|
|
130
132
|
titles,
|
|
131
133
|
/** Resolves a switched-to model at run start (fallback when it is gone; UI refresh B). */
|
|
132
134
|
models,
|
|
133
|
-
/** Run start's skills catalog snapshot
|
|
135
|
+
/** Run start's skills catalog snapshot. */
|
|
134
136
|
skillsCatalog,
|
|
135
137
|
/** Run start's run context (run context spec §5): who the agent is, the day, the person. */
|
|
136
138
|
runContext,
|
|
@@ -596,7 +598,7 @@ let RunWorker = class RunWorker {
|
|
|
596
598
|
// a follow-up runs with its task message's narrowing (final review I1): the frozen tools
|
|
597
599
|
// and org skills the current version still allows, recorded at its dispatch
|
|
598
600
|
const trigger = (await this.eventLog.readAfter(conversationId, Number(run.trigger_seq) - 1, 1))[0];
|
|
599
|
-
agent = childRunDefinition(
|
|
601
|
+
agent = childRunDefinition(normalizeStoredDefinition(started.payload.definition), trigger?.type === "user_message" && trigger.seq === Number(run.trigger_seq)
|
|
600
602
|
? trigger.payload.dispatch?.narrowed
|
|
601
603
|
: undefined);
|
|
602
604
|
// the tighter of the logged limit and the deployment's (0 in either = no limit there)
|
|
@@ -643,7 +645,7 @@ let RunWorker = class RunWorker {
|
|
|
643
645
|
.where("agent_id", "=", conv.agent_id)
|
|
644
646
|
.where("version", "=", run.agent_version)
|
|
645
647
|
.executeTakeFirstOrThrow();
|
|
646
|
-
saved =
|
|
648
|
+
saved = normalizeStoredDefinition(version.definition);
|
|
647
649
|
agent = saved;
|
|
648
650
|
}
|
|
649
651
|
// the trigger account's role, read once per run for the plugin context and plugin tool
|
|
@@ -13,6 +13,11 @@ export type StepAuditEntry = Parameters<typeof audit>[1];
|
|
|
13
13
|
* definitions it sent, a denial with its audit row, usage events with their owed `usage.report`
|
|
14
14
|
* deliveries (transactional outbox spec §8.1), and a sub-agent's usage counted on its parent run.
|
|
15
15
|
* The step functions (`model-call.ts`, `hook-calls.ts`) reach it through their deps.
|
|
16
|
+
*
|
|
17
|
+
* Run loop hot-path writes: each transaction asks the run fence for shared admission
|
|
18
|
+
* (`RunExecution`), so the runs of one org write in parallel. They lock only the conversation rows,
|
|
19
|
+
* the run rows of the same tree and rows of their own; never anything org-level (`OrgLock`,
|
|
20
|
+
* agents, memberships).
|
|
16
21
|
*/
|
|
17
22
|
export declare class StepLog {
|
|
18
23
|
private readonly kdb;
|
package/dist/runtime/step-log.js
CHANGED
|
@@ -24,6 +24,11 @@ import { UsageReportJobs, UsageReportJobsModule } from "./usage-report-jobs.js";
|
|
|
24
24
|
* definitions it sent, a denial with its audit row, usage events with their owed `usage.report`
|
|
25
25
|
* deliveries (transactional outbox spec §8.1), and a sub-agent's usage counted on its parent run.
|
|
26
26
|
* The step functions (`model-call.ts`, `hook-calls.ts`) reach it through their deps.
|
|
27
|
+
*
|
|
28
|
+
* Run loop hot-path writes: each transaction asks the run fence for shared admission
|
|
29
|
+
* (`RunExecution`), so the runs of one org write in parallel. They lock only the conversation rows,
|
|
30
|
+
* the run rows of the same tree and rows of their own; never anything org-level (`OrgLock`,
|
|
31
|
+
* agents, memberships).
|
|
27
32
|
*/
|
|
28
33
|
let StepLog = class StepLog {
|
|
29
34
|
kdb;
|
|
@@ -97,16 +102,16 @@ let StepLog = class StepLog {
|
|
|
97
102
|
}
|
|
98
103
|
};
|
|
99
104
|
__decorate([
|
|
100
|
-
Transactional({ propagation: "requires_new" })
|
|
105
|
+
Transactional({ propagation: "requires_new", admission: "shared" })
|
|
101
106
|
], StepLog.prototype, "appendReported", null);
|
|
102
107
|
__decorate([
|
|
103
|
-
Transactional({ propagation: "requires_new" })
|
|
108
|
+
Transactional({ propagation: "requires_new", admission: "shared" })
|
|
104
109
|
], StepLog.prototype, "appendCounted", null);
|
|
105
110
|
__decorate([
|
|
106
|
-
Transactional({ propagation: "requires_new" })
|
|
111
|
+
Transactional({ propagation: "requires_new", admission: "shared" })
|
|
107
112
|
], StepLog.prototype, "appendAudited", null);
|
|
108
113
|
__decorate([
|
|
109
|
-
Transactional({ propagation: "requires_new" })
|
|
114
|
+
Transactional({ propagation: "requires_new", admission: "shared" })
|
|
110
115
|
], StepLog.prototype, "appendWithSpecs", null);
|
|
111
116
|
StepLog = __decorate([
|
|
112
117
|
Injectable(),
|
|
@@ -23,16 +23,24 @@ export interface EffectiveDefinition {
|
|
|
23
23
|
/** The child's step limit; 0 = no limit. */
|
|
24
24
|
maxSteps: number;
|
|
25
25
|
/**
|
|
26
|
-
* The
|
|
27
|
-
*
|
|
26
|
+
* The template's `skills` the child has, in the template's order: the dispatch writes each as a
|
|
27
|
+
* skill invocation message after the task (no model step spent loading them).
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
skills: TemplateSkill[];
|
|
30
30
|
/**
|
|
31
31
|
* Dispatch warnings (a template skill the child does not have), recorded in
|
|
32
32
|
* `subagent_started.warnings`.
|
|
33
33
|
*/
|
|
34
34
|
warnings: string[];
|
|
35
35
|
}
|
|
36
|
+
/** A template skill the child starts with: its catalog entry (the version its catalog lists). */
|
|
37
|
+
export interface TemplateSkill {
|
|
38
|
+
id: string;
|
|
39
|
+
version: number;
|
|
40
|
+
source: string;
|
|
41
|
+
name: string;
|
|
42
|
+
plugin?: string;
|
|
43
|
+
}
|
|
36
44
|
export interface EffectiveDefinitionDeps {
|
|
37
45
|
db: KernelSchemaDb;
|
|
38
46
|
purposes: Pick<ModelPurposesService, "resolve">;
|
|
@@ -54,8 +62,6 @@ export declare function stricterPolicies(base: Record<string, string>, over: Rec
|
|
|
54
62
|
* and an entry that is no valid reference (stored template data is not re-validated) are dropped.
|
|
55
63
|
*/
|
|
56
64
|
export declare function disallowedSkillRefs(db: KernelSchemaDb, orgId: string, refs: readonly unknown[] | undefined): Promise<DisabledSkillRef[]>;
|
|
57
|
-
/** The preamble line naming the skills a template child loads first (skills default-on §6.1). */
|
|
58
|
-
export declare const loadSkillsFirstText: (names: readonly string[]) => string;
|
|
59
65
|
/** An org agent's version and definition as checked by its gates. */
|
|
60
66
|
export interface CheckedOrgAgent {
|
|
61
67
|
version: number;
|
|
@@ -72,8 +78,8 @@ export interface ChildDepth {
|
|
|
72
78
|
* The effective definition of a sub-agent at its first dispatch (spec §5.3–§5.5):
|
|
73
79
|
* - `general` / `inline` / `plugin`: the parent's definition narrowed by the template (tools by
|
|
74
80
|
* resolved key, `disallowedTools`, {@link CHILD_REMOVED_TOOLS}; policies stricter-wins; skills
|
|
75
|
-
* by its `disallowedSkills`), the template's instructions, its `skills` the child has
|
|
76
|
-
*
|
|
81
|
+
* by its `disallowedSkills`), the template's instructions, its `skills` the child has (written
|
|
82
|
+
* as skill invocations at dispatch; general has none), `maxSteps` = the tighter of the template's and `runtime.maxSteps` (0 = no limit), and the model tier
|
|
77
83
|
* `tier` (the call's) → the template's → `inherit`; an unmapped tier runs on the parent's model
|
|
78
84
|
* (`tierFallback`); a template `effort` is set when the resolved model declares it;
|
|
79
85
|
* - `agent`: the org agent's version that passed the gates (`orgAgent`, from {@link checkOrgAgent}),
|
|
@@ -102,15 +108,8 @@ export declare function effectiveDefinition(d: EffectiveDefinitionDeps, a: Child
|
|
|
102
108
|
* the run and its replay read it from the log.
|
|
103
109
|
*/
|
|
104
110
|
export interface FollowUpNarrowing {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
/** Absent in logs from before skills were on by default (skills default-on spec §6.1). */
|
|
108
|
-
disabledSkills?: DisabledSkillRef[] | undefined;
|
|
109
|
-
/** Older logs only: the frozen org skills intersected with the current ones. */
|
|
110
|
-
skills?: {
|
|
111
|
-
orgSkills: string[];
|
|
112
|
-
pinned?: string[] | undefined;
|
|
113
|
-
} | undefined;
|
|
111
|
+
disabledTools: DisabledToolRef[];
|
|
112
|
+
disabledSkills: DisabledSkillRef[];
|
|
114
113
|
}
|
|
115
114
|
/**
|
|
116
115
|
* The narrowing of a follow-up (final review I1): `frozen` (the child's `subagent_started`
|
|
@@ -120,8 +119,5 @@ export interface FollowUpNarrowing {
|
|
|
120
119
|
* `disabledTools` and `disabledSkills` are both lists together.
|
|
121
120
|
*/
|
|
122
121
|
export declare function narrowFollowUp(frozen: Pick<AgentDefinition, "disabledTools" | "disabledSkills">, current: Pick<AgentDefinition, "disabledTools" | "disabledSkills">): FollowUpNarrowing;
|
|
123
|
-
/**
|
|
124
|
-
* The definition a child run uses: the frozen one with its trigger's follow-up narrowing. A
|
|
125
|
-
* narrowing logged before tools (or skills) were on by default narrows nothing of that kind.
|
|
126
|
-
*/
|
|
122
|
+
/** The definition a child run uses: the frozen one with its trigger's follow-up narrowing. */
|
|
127
123
|
export declare function childRunDefinition(frozen: AgentDefinition, narrowed: FollowUpNarrowing | undefined): AgentDefinition;
|
|
@@ -7,7 +7,6 @@ import { invocationOf, resolveSkills } from "../../skills/catalog.js";
|
|
|
7
7
|
import { agentSkills, usableSkills } from "../../skills/usable.js";
|
|
8
8
|
import { AGENT_TOOL, CHILD_REMOVED_TOOLS } from "../../tools/builtin-names.js";
|
|
9
9
|
import { tightestLimit } from "../limits.js";
|
|
10
|
-
import { SUBAGENT_PREAMBLE } from "./preamble.js";
|
|
11
10
|
export { CHILD_REMOVED_TOOLS } from "../../tools/builtin-names.js";
|
|
12
11
|
/**
|
|
13
12
|
* The roster entry's template is gone (an inline template edited away, a plugin template
|
|
@@ -101,27 +100,25 @@ export async function disallowedSkillRefs(db, orgId, refs) {
|
|
|
101
100
|
return out;
|
|
102
101
|
}
|
|
103
102
|
/** The warning of a template skill the child does not have. */
|
|
104
|
-
const skillNotLoadedText = (ref) => `The skill "${ref}" is not among the sub-agent's skills, so it is not
|
|
105
|
-
/** The preamble line naming the skills a template child loads first (skills default-on §6.1). */
|
|
106
|
-
export const loadSkillsFirstText = (names) => `Before you start, load these skills with Skill: ${names.join(", ")}.`;
|
|
103
|
+
const skillNotLoadedText = (ref) => `The skill "${ref}" is not among the sub-agent's skills, so it is not loaded.`;
|
|
107
104
|
/**
|
|
108
|
-
* The template's `skills` the child has (skills default-on spec §6.1: they are
|
|
109
|
-
*
|
|
110
|
-
*
|
|
105
|
+
* The template's `skills` the child has (skills default-on spec §6.1: they are never pinned), as
|
|
106
|
+
* the entries its catalog lists, in the template's order: the catalog its first run records (the
|
|
107
|
+
* agent `agentId` with the child's `disabledSkills`, model-invocable skills only).
|
|
111
108
|
* Inline templates name skill ids (`byId`; a platform skill's id names its linked copy too), plugin
|
|
112
109
|
* templates names (`<name>`, or `<plugin>:<name>` when the catalog's skill of that name is from
|
|
113
110
|
* that plugin). The others become warnings.
|
|
114
111
|
*/
|
|
115
112
|
async function skillsToLoad(db, a, refs, byId) {
|
|
116
113
|
if (refs.length === 0)
|
|
117
|
-
return {
|
|
114
|
+
return { skills: [], warnings: [] };
|
|
118
115
|
const input = { orgId: a.orgId, agentId: a.agentId, disabledSkills: [...a.disabledSkills] };
|
|
119
116
|
const catalog = (await resolveSkills(db, { ...input, agent: input }))
|
|
120
117
|
.filter((r) => invocationOf(r.manifest).model)
|
|
121
118
|
.slice(0, SKILLS_CATALOG_MAX)
|
|
122
119
|
.map((r) => r.skill);
|
|
123
120
|
const rows = byId ? await agentSkills(db, input) : [];
|
|
124
|
-
const
|
|
121
|
+
const skills = [];
|
|
125
122
|
const warnings = [];
|
|
126
123
|
for (const ref of refs) {
|
|
127
124
|
let found;
|
|
@@ -136,12 +133,20 @@ async function skillsToLoad(db, a, refs, byId) {
|
|
|
136
133
|
? catalog.find((c) => c.name === ref)
|
|
137
134
|
: catalog.find((c) => c.name === ref.slice(i + 1) && c.plugin === ref.slice(0, i));
|
|
138
135
|
}
|
|
139
|
-
|
|
136
|
+
const f = found;
|
|
137
|
+
if (f === undefined)
|
|
140
138
|
warnings.push(skillNotLoadedText(ref));
|
|
141
|
-
else if (!
|
|
142
|
-
|
|
139
|
+
else if (!skills.some((s) => s.id === f.id)) {
|
|
140
|
+
skills.push({
|
|
141
|
+
id: f.id,
|
|
142
|
+
version: f.version,
|
|
143
|
+
source: f.source,
|
|
144
|
+
name: f.name,
|
|
145
|
+
...(f.plugin !== undefined && { plugin: f.plugin }),
|
|
146
|
+
});
|
|
147
|
+
}
|
|
143
148
|
}
|
|
144
|
-
return {
|
|
149
|
+
return { skills, warnings };
|
|
145
150
|
}
|
|
146
151
|
/** The `effort` declaration of `model`, or null (or when the model cannot be resolved). */
|
|
147
152
|
async function effortDecl(registry, orgId, model) {
|
|
@@ -212,7 +217,7 @@ function orgAgentDefinition(d, a) {
|
|
|
212
217
|
definition,
|
|
213
218
|
template: { source: "agent", id: agentId, version: a.orgAgent.version },
|
|
214
219
|
maxSteps: d.config.get().runtime.maxSteps,
|
|
215
|
-
|
|
220
|
+
skills: [],
|
|
216
221
|
warnings: [],
|
|
217
222
|
model: own.model,
|
|
218
223
|
tierFallback: false,
|
|
@@ -222,8 +227,8 @@ function orgAgentDefinition(d, a) {
|
|
|
222
227
|
* The effective definition of a sub-agent at its first dispatch (spec §5.3–§5.5):
|
|
223
228
|
* - `general` / `inline` / `plugin`: the parent's definition narrowed by the template (tools by
|
|
224
229
|
* resolved key, `disallowedTools`, {@link CHILD_REMOVED_TOOLS}; policies stricter-wins; skills
|
|
225
|
-
* by its `disallowedSkills`), the template's instructions, its `skills` the child has
|
|
226
|
-
*
|
|
230
|
+
* by its `disallowedSkills`), the template's instructions, its `skills` the child has (written
|
|
231
|
+
* as skill invocations at dispatch; general has none), `maxSteps` = the tighter of the template's and `runtime.maxSteps` (0 = no limit), and the model tier
|
|
227
232
|
* `tier` (the call's) → the template's → `inherit`; an unmapped tier runs on the parent's model
|
|
228
233
|
* (`tierFallback`); a template `effort` is set when the resolved model declares it;
|
|
229
234
|
* - `agent`: the org agent's version that passed the gates (`orgAgent`, from {@link checkOrgAgent}),
|
|
@@ -260,12 +265,12 @@ export async function effectiveDefinition(d, a) {
|
|
|
260
265
|
}
|
|
261
266
|
const toolPolicies = stricterPolicies(parent.toolPolicies ?? {}, template?.toolPolicies ?? {});
|
|
262
267
|
// skills default-on (spec §6.1): the parent's catalog, narrowed by the template's
|
|
263
|
-
// `disallowedSkills`; the template's `skills` are
|
|
268
|
+
// `disallowedSkills`; the template's `skills` are written as invocations, never pinned
|
|
264
269
|
const narrowing = await disallowedSkillRefs(d.db, a.orgId, template?.disallowedSkills);
|
|
265
270
|
const disabledSkills = narrowing.length === 0
|
|
266
271
|
? (parent.disabledSkills ?? [])
|
|
267
272
|
: canonicalDisabledSkills([...(parent.disabledSkills ?? []), ...narrowing]);
|
|
268
|
-
const {
|
|
273
|
+
const { skills, warnings } = await skillsToLoad(d.db, { orgId: a.orgId, agentId: a.parentAgentId, disabledSkills }, template?.skills ?? [], entry.source === "inline");
|
|
269
274
|
const tier = a.tier ?? template?.model ?? "inherit";
|
|
270
275
|
const m = await resolveTier(d, a.orgId, parent, tier);
|
|
271
276
|
let modelParams = m.modelParams;
|
|
@@ -301,9 +306,7 @@ export async function effectiveDefinition(d, a) {
|
|
|
301
306
|
template: ref,
|
|
302
307
|
// the tighter of the template's and the deployment's, 0 = no limit (`runtime.maxSteps` 0)
|
|
303
308
|
maxSteps: tightestLimit(template?.maxSteps, runtimeMax) ?? 0,
|
|
304
|
-
|
|
305
|
-
? SUBAGENT_PREAMBLE
|
|
306
|
-
: `${SUBAGENT_PREAMBLE}\n\n${loadSkillsFirstText(names)}`,
|
|
309
|
+
skills,
|
|
307
310
|
warnings,
|
|
308
311
|
model: m.model,
|
|
309
312
|
tierFallback: m.tierFallback,
|
|
@@ -328,16 +331,13 @@ export function narrowFollowUp(frozen, current) {
|
|
|
328
331
|
]),
|
|
329
332
|
};
|
|
330
333
|
}
|
|
331
|
-
/**
|
|
332
|
-
* The definition a child run uses: the frozen one with its trigger's follow-up narrowing. A
|
|
333
|
-
* narrowing logged before tools (or skills) were on by default narrows nothing of that kind.
|
|
334
|
-
*/
|
|
334
|
+
/** The definition a child run uses: the frozen one with its trigger's follow-up narrowing. */
|
|
335
335
|
export function childRunDefinition(frozen, narrowed) {
|
|
336
336
|
if (narrowed === undefined)
|
|
337
337
|
return frozen;
|
|
338
338
|
return {
|
|
339
339
|
...frozen,
|
|
340
|
-
|
|
341
|
-
|
|
340
|
+
disabledTools: narrowed.disabledTools,
|
|
341
|
+
disabledSkills: narrowed.disabledSkills,
|
|
342
342
|
};
|
|
343
343
|
}
|