@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
|
@@ -5,6 +5,7 @@ import type { ConversationEvent, EventPayload } from "../../conversations/events
|
|
|
5
5
|
import type { ConversationKind, KernelSchemaDb } from "../../db/kernel-schema.js";
|
|
6
6
|
import type { KernelConfigService } from "../../infra/config/kernel-config.service.js";
|
|
7
7
|
import type { ModelPurposesService } from "../../models/purposes.js";
|
|
8
|
+
import { type SkillInvoker } from "../../skills/invoke.js";
|
|
8
9
|
import { AGENT_REFUSALS, type AgentToolInputT } from "../../tools/builtins/agent.js";
|
|
9
10
|
import type { ToolStepContext } from "../../tools/pipeline.js";
|
|
10
11
|
import type { ProviderRegistry } from "../providers.js";
|
|
@@ -24,6 +25,8 @@ export interface DispatchDeps {
|
|
|
24
25
|
*/
|
|
25
26
|
owe: (data: RunJobData, jobId: string, kind: ConversationKind, orgId: string) => Promise<boolean>;
|
|
26
27
|
log: Pick<Logger, "error" | "warn">;
|
|
28
|
+
/** Renders a template's skills into the child's first messages ({@link templateSkillMessages}). */
|
|
29
|
+
invoker: Pick<SkillInvoker, "renderTask">;
|
|
27
30
|
/**
|
|
28
31
|
* Runs {@link commitDispatchIn} in a transaction of its own (`SubagentsService.commitDispatch`,
|
|
29
32
|
* a `@Transactional` method).
|
|
@@ -121,8 +124,8 @@ export interface DispatchPlan {
|
|
|
121
124
|
* Dispatches the sub-agent of one `Agent` call (spec §7.1, agent map spec §4.1), after the
|
|
122
125
|
* pipeline's validation, policy, approval and `tool.preExecute` stages: resolves its type and
|
|
123
126
|
* effective definition, then in one transaction (holding the parent run's row lock, so the
|
|
124
|
-
* dispatches of one run serialize) inserts the child conversation, appends `subagent_started
|
|
125
|
-
* the task message, inserts the child run (`queued`) and the `subagent_dispatches` row, appends
|
|
127
|
+
* dispatches of one run serialize) inserts the child conversation, appends `subagent_started`,
|
|
128
|
+
* the task message and the template's skill invocations ({@link templateSkillMessages}), inserts the child run (`queued`) and the `subagent_dispatches` row, appends
|
|
126
129
|
* `subagent_dispatched` and the call's `tool_result` ({@link agentStartedText}: the sub-agent runs
|
|
127
130
|
* in the background) to the parent and audits `subagent.dispatched` and `tool.called`. The child
|
|
128
131
|
* run's job is owed in the same transaction (transactional outbox spec §6), so the committed
|
|
@@ -173,6 +176,7 @@ export declare const taskMessage: (ctx: ToolStepContext, callId: string, prompt:
|
|
|
173
176
|
arguments: string;
|
|
174
177
|
mode: "fork" | "inline";
|
|
175
178
|
agentType?: string | undefined;
|
|
179
|
+
template?: true | undefined;
|
|
176
180
|
};
|
|
177
181
|
authorAccountId: string;
|
|
178
182
|
dispatch: {
|
|
@@ -9,7 +9,9 @@ import { childResult, finishedEvent } from "./child.js";
|
|
|
9
9
|
import { effectiveDefinition, SubagentTypeGoneError, } from "./definition.js";
|
|
10
10
|
import { subagentLimits } from "./limits.js";
|
|
11
11
|
import { auditRefusal, checkOrgAgent, currentAgentDefinition } from "./org-agents.js";
|
|
12
|
+
import { SUBAGENT_PREAMBLE } from "./preamble.js";
|
|
12
13
|
import { findType, GENERAL_PURPOSE_DESCRIPTION, resolveRoster, } from "./roster.js";
|
|
14
|
+
import { templateSkillMessages } from "./template-skills.js";
|
|
13
15
|
const refused = (content) => ({ kind: "refused", content });
|
|
14
16
|
/** The `general-purpose` roster entry (a fork invocation always has it). */
|
|
15
17
|
const GENERAL_ENTRY = {
|
|
@@ -28,8 +30,8 @@ export const dispatchedIdemKey = (runId, callId) => `subagent_dispatched:${runId
|
|
|
28
30
|
* Dispatches the sub-agent of one `Agent` call (spec §7.1, agent map spec §4.1), after the
|
|
29
31
|
* pipeline's validation, policy, approval and `tool.preExecute` stages: resolves its type and
|
|
30
32
|
* effective definition, then in one transaction (holding the parent run's row lock, so the
|
|
31
|
-
* dispatches of one run serialize) inserts the child conversation, appends `subagent_started
|
|
32
|
-
* the task message, inserts the child run (`queued`) and the `subagent_dispatches` row, appends
|
|
33
|
+
* dispatches of one run serialize) inserts the child conversation, appends `subagent_started`,
|
|
34
|
+
* the task message and the template's skill invocations ({@link templateSkillMessages}), inserts the child run (`queued`) and the `subagent_dispatches` row, appends
|
|
33
35
|
* `subagent_dispatched` and the call's `tool_result` ({@link agentStartedText}: the sub-agent runs
|
|
34
36
|
* in the background) to the parent and audits `subagent.dispatched` and `tool.called`. The child
|
|
35
37
|
* run's job is owed in the same transaction (transactional outbox spec §6), so the committed
|
|
@@ -92,6 +94,17 @@ export async function dispatchSubagent(d, a) {
|
|
|
92
94
|
}
|
|
93
95
|
throw e;
|
|
94
96
|
}
|
|
97
|
+
// read and rendered before the transaction (object storage): the template's skills as the
|
|
98
|
+
// child's invocation messages, after its task
|
|
99
|
+
const loaded = await templateSkillMessages(d, {
|
|
100
|
+
ctx,
|
|
101
|
+
child: eff.definition,
|
|
102
|
+
skills: eff.skills,
|
|
103
|
+
});
|
|
104
|
+
// the parent run was stopped: nothing is dispatched (as when the commit finds it not running)
|
|
105
|
+
if (loaded === null)
|
|
106
|
+
return refused(AGENT_REFUSALS.notAvailableHere);
|
|
107
|
+
warnings.push(...loaded.warnings);
|
|
95
108
|
const childId = randomUUID();
|
|
96
109
|
const plan = {
|
|
97
110
|
childConversationId: childId,
|
|
@@ -147,7 +160,7 @@ export async function dispatchSubagent(d, a) {
|
|
|
147
160
|
},
|
|
148
161
|
},
|
|
149
162
|
definition: eff.definition,
|
|
150
|
-
preamble:
|
|
163
|
+
preamble: SUBAGENT_PREAMBLE,
|
|
151
164
|
maxSteps: eff.maxSteps,
|
|
152
165
|
...([...eff.warnings, ...warnings].length > 0 && {
|
|
153
166
|
warnings: [...eff.warnings, ...warnings],
|
|
@@ -155,6 +168,7 @@ export async function dispatchSubagent(d, a) {
|
|
|
155
168
|
},
|
|
156
169
|
},
|
|
157
170
|
taskMessage(ctx, a.callId, fork === undefined ? input.prompt : fork.task(eff.definition), undefined, fork?.skill),
|
|
171
|
+
...loaded.messages,
|
|
158
172
|
]);
|
|
159
173
|
return task;
|
|
160
174
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isAgentVisibleTo } from "../../agents/agent-lookup.js";
|
|
2
2
|
import { normalizeStoredDefinition } from "../../agents/definition.js";
|
|
3
3
|
import { audit } from "../../identity/audit.js";
|
|
4
|
-
import { normalizeStoredDefinitionIn } from "../../tools/legacy-data.js";
|
|
5
4
|
/**
|
|
6
5
|
* Checks the gates for dispatching `agentId` from a parent whose current definition is
|
|
7
6
|
* `parentDefinition` (read live by the caller: R5, removing an allowlist entry stops new
|
|
@@ -24,7 +23,7 @@ export async function checkOrgAgent(db, a) {
|
|
|
24
23
|
if (!(a.parentDefinition.subagents?.agents ?? []).some((x) => x.agentId === a.agentId)) {
|
|
25
24
|
return { ok: false, gate: "allowlist" };
|
|
26
25
|
}
|
|
27
|
-
const definition =
|
|
26
|
+
const definition = normalizeStoredDefinition(row.definition);
|
|
28
27
|
if (definition.subagents?.dispatchable !== true)
|
|
29
28
|
return { ok: false, gate: "dispatchable" };
|
|
30
29
|
if (!(await isAgentVisibleTo(db, a.agentId, a.triggerAccountId))) {
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* The sub-agent preamble (spec §6.3, agent map spec §4.4, model-visible): rendered in a child's
|
|
3
3
|
* system text after `BEHAVIOR_RULES` and before its instructions. Frozen into each child's
|
|
4
4
|
* `subagent_started` at dispatch, and request building reads it from there, so changing this text
|
|
5
|
-
* never alters an old child's requests.
|
|
6
|
-
* template's skills to load first
|
|
5
|
+
* never alters an old child's requests. Older children's preambles may end with a line naming the
|
|
6
|
+
* template's skills to load first; a template's skills are now written as skill invocation
|
|
7
|
+
* messages after the task (`template-skills.ts`).
|
|
7
8
|
*/
|
|
8
9
|
export declare const SUBAGENT_PREAMBLE: string;
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
* The sub-agent preamble (spec §6.3, agent map spec §4.4, model-visible): rendered in a child's
|
|
3
3
|
* system text after `BEHAVIOR_RULES` and before its instructions. Frozen into each child's
|
|
4
4
|
* `subagent_started` at dispatch, and request building reads it from there, so changing this text
|
|
5
|
-
* never alters an old child's requests.
|
|
6
|
-
* template's skills to load first
|
|
5
|
+
* never alters an old child's requests. Older children's preambles may end with a line naming the
|
|
6
|
+
* template's skills to load first; a template's skills are now written as skill invocation
|
|
7
|
+
* messages after the task (`template-skills.ts`).
|
|
7
8
|
*/
|
|
8
9
|
export const SUBAGENT_PREAMBLE = "You are a sub-agent. Another agent dispatched you with the task in the first user message. " +
|
|
9
10
|
"Work on it on your own: the user does not watch this conversation and you cannot ask them " +
|
|
@@ -23,8 +23,7 @@ type Delivery = EventPayload<"subagent_delivery">;
|
|
|
23
23
|
*
|
|
24
24
|
* A run that handed back and then `completed` no longer gets a finished delivery (acceptance
|
|
25
25
|
* 2026-11-07, `SubagentDeliveries.finishIn`); the "already delivered" line stays for the other
|
|
26
|
-
* statuses after a handback
|
|
27
|
-
* byte. The switch is the delivery's absence in the log, so it needs no `DriftReason`.
|
|
26
|
+
* statuses after a handback.
|
|
28
27
|
*/
|
|
29
28
|
export declare function renderSubagentDelivery(p: Delivery): string;
|
|
30
29
|
export {};
|
|
@@ -22,8 +22,7 @@ import { subagentStatusText } from "./status.js";
|
|
|
22
22
|
*
|
|
23
23
|
* A run that handed back and then `completed` no longer gets a finished delivery (acceptance
|
|
24
24
|
* 2026-11-07, `SubagentDeliveries.finishIn`); the "already delivered" line stays for the other
|
|
25
|
-
* statuses after a handback
|
|
26
|
-
* byte. The switch is the delivery's absence in the log, so it needs no `DriftReason`.
|
|
25
|
+
* statuses after a handback.
|
|
27
26
|
*/
|
|
28
27
|
export function renderSubagentDelivery(p) {
|
|
29
28
|
const head = `Sub-agent ${p.subagentId} (${JSON.stringify(p.description)})`;
|
|
@@ -2,7 +2,6 @@ import type { EventLog } from "../../conversations/event-log.js";
|
|
|
2
2
|
import type { ConversationEvent, EventPayload } from "../../conversations/events.js";
|
|
3
3
|
import type { KernelSchemaDb } from "../../db/kernel-schema.js";
|
|
4
4
|
import { ApiError } from "../../errors.js";
|
|
5
|
-
import type { SkillInvoker } from "../../skills/invoke.js";
|
|
6
5
|
import { type LoopContext, type WaitingFor } from "../loop.js";
|
|
7
6
|
import { type DispatchDeps } from "./dispatch.js";
|
|
8
7
|
/**
|
|
@@ -82,9 +81,8 @@ export interface SkillForks {
|
|
|
82
81
|
fork: ForkInvocation;
|
|
83
82
|
}): Promise<SkillForkStep>;
|
|
84
83
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
84
|
+
/** The fork's dependencies: the dispatch's (its `invoker` renders the task). */
|
|
85
|
+
export type SkillForkDeps = DispatchDeps;
|
|
88
86
|
/**
|
|
89
87
|
* In `prepare`, for the run's fork invocation: dispatch it when it has no dispatch row (rendering
|
|
90
88
|
* the task from the recorded version, `SkillInvoker.renderTask`) and suspend; append the report once
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { AgentDefinition } from "../../agents/definition.js";
|
|
3
|
+
import type { EventPayload } from "../../conversations/events.js";
|
|
4
|
+
import type { SkillInvoker } from "../../skills/invoke.js";
|
|
5
|
+
import type { ToolStepContext } from "../../tools/pipeline.js";
|
|
6
|
+
import type { TemplateSkill } from "./definition.js";
|
|
7
|
+
/**
|
|
8
|
+
* A template's skills at child start (Claude Code's sub-agent `skills`, skills default-on spec
|
|
9
|
+
* §6.1): the dispatch writes one skill invocation message per skill the child has, after its task
|
|
10
|
+
* message and in the same transaction, so the child starts with the instructions instead of
|
|
11
|
+
* spending model steps on `Skill` calls. Each message is a `user_message` with the `skill` record
|
|
12
|
+
* (`mode: "inline"`, no arguments, `template: true`: nobody typed it) and the version's rendered
|
|
13
|
+
* `<skill_invocation>` text, as an inline invocation is logged: the text is fixed in the log
|
|
14
|
+
* (replay never renders it again), and the record lets the child's `Skill` copy the files of that
|
|
15
|
+
* version.
|
|
16
|
+
*/
|
|
17
|
+
/** The lead of a template skill's invocation message (model-visible, English). */
|
|
18
|
+
export declare const templateSkillLeadText: (name: string) => string;
|
|
19
|
+
/** The message of a template skill whose SKILL.md could not be read at dispatch. */
|
|
20
|
+
export declare const templateSkillUnreadableText: (name: string) => string;
|
|
21
|
+
/** The dispatch warning of a template skill that could not be read or rendered (not model-visible). */
|
|
22
|
+
export declare const templateSkillUnreadableWarning: (name: string) => string;
|
|
23
|
+
type UserMessage = {
|
|
24
|
+
type: "user_message";
|
|
25
|
+
payload: EventPayload<"user_message">;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The invocation messages of `skills` for the child's effective definition `child` (its tools
|
|
29
|
+
* decide the shell line), read from the versions its catalog lists. A version that cannot be read
|
|
30
|
+
* or rendered (storage down, integrity, over the size limit) gets {@link
|
|
31
|
+
* templateSkillUnreadableText} instead (marked `templateSkillNotice`, display only) and a dispatch
|
|
32
|
+
* warning ({@link templateSkillUnreadableWarning}, for `subagent_started.warnings`), and the
|
|
33
|
+
* dispatch goes on.
|
|
34
|
+
* Null when the run's signal aborted before a read: the dispatch writes nothing.
|
|
35
|
+
*/
|
|
36
|
+
export declare function templateSkillMessages(d: {
|
|
37
|
+
invoker: Pick<SkillInvoker, "renderTask">;
|
|
38
|
+
log: Pick<Logger, "warn">;
|
|
39
|
+
}, a: {
|
|
40
|
+
ctx: ToolStepContext;
|
|
41
|
+
child: AgentDefinition;
|
|
42
|
+
skills: readonly TemplateSkill[];
|
|
43
|
+
}): Promise<{
|
|
44
|
+
messages: UserMessage[];
|
|
45
|
+
warnings: string[];
|
|
46
|
+
} | null>;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ApiError } from "../../errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* A template's skills at child start (Claude Code's sub-agent `skills`, skills default-on spec
|
|
4
|
+
* §6.1): the dispatch writes one skill invocation message per skill the child has, after its task
|
|
5
|
+
* message and in the same transaction, so the child starts with the instructions instead of
|
|
6
|
+
* spending model steps on `Skill` calls. Each message is a `user_message` with the `skill` record
|
|
7
|
+
* (`mode: "inline"`, no arguments, `template: true`: nobody typed it) and the version's rendered
|
|
8
|
+
* `<skill_invocation>` text, as an inline invocation is logged: the text is fixed in the log
|
|
9
|
+
* (replay never renders it again), and the record lets the child's `Skill` copy the files of that
|
|
10
|
+
* version.
|
|
11
|
+
*/
|
|
12
|
+
/** The lead of a template skill's invocation message (model-visible, English). */
|
|
13
|
+
export const templateSkillLeadText = (name) => `Your sub-agent type comes with the skill "${name}"; its instructions follow. Use them for this task.`;
|
|
14
|
+
/** The message of a template skill whose SKILL.md could not be read at dispatch. */
|
|
15
|
+
export const templateSkillUnreadableText = (name) => `Your sub-agent type comes with the skill "${name}", but it could not be read when you started; load it with Skill before you use it.`;
|
|
16
|
+
/** The dispatch warning of a template skill that could not be read or rendered (not model-visible). */
|
|
17
|
+
export const templateSkillUnreadableWarning = (name) => `The skill "${name}" could not be read at dispatch; the sub-agent was told to load it with Skill.`;
|
|
18
|
+
/**
|
|
19
|
+
* The invocation messages of `skills` for the child's effective definition `child` (its tools
|
|
20
|
+
* decide the shell line), read from the versions its catalog lists. A version that cannot be read
|
|
21
|
+
* or rendered (storage down, integrity, over the size limit) gets {@link
|
|
22
|
+
* templateSkillUnreadableText} instead (marked `templateSkillNotice`, display only) and a dispatch
|
|
23
|
+
* warning ({@link templateSkillUnreadableWarning}, for `subagent_started.warnings`), and the
|
|
24
|
+
* dispatch goes on.
|
|
25
|
+
* Null when the run's signal aborted before a read: the dispatch writes nothing.
|
|
26
|
+
*/
|
|
27
|
+
export async function templateSkillMessages(d, a) {
|
|
28
|
+
const messages = [];
|
|
29
|
+
const warnings = [];
|
|
30
|
+
for (const s of a.skills) {
|
|
31
|
+
// a stopped run reads no more skill files (as the fork path checks before its read)
|
|
32
|
+
if (a.ctx.signal.aborted)
|
|
33
|
+
return null;
|
|
34
|
+
const record = {
|
|
35
|
+
id: s.id,
|
|
36
|
+
version: s.version,
|
|
37
|
+
source: s.source,
|
|
38
|
+
name: s.name,
|
|
39
|
+
...(s.plugin !== undefined && { plugin: s.plugin }),
|
|
40
|
+
arguments: "",
|
|
41
|
+
mode: "inline",
|
|
42
|
+
template: true,
|
|
43
|
+
};
|
|
44
|
+
let text;
|
|
45
|
+
try {
|
|
46
|
+
const { task } = await d.invoker.renderTask({
|
|
47
|
+
orgId: a.ctx.orgId,
|
|
48
|
+
conversationId: a.ctx.conversationId,
|
|
49
|
+
skill: record,
|
|
50
|
+
});
|
|
51
|
+
text = `${templateSkillLeadText(s.name)}\n\n${task(a.child)}`;
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
if (!(e instanceof ApiError) && !(e instanceof RangeError))
|
|
55
|
+
throw e;
|
|
56
|
+
d.log.warn("template skill not loaded at dispatch", {
|
|
57
|
+
orgId: a.ctx.orgId,
|
|
58
|
+
conversationId: a.ctx.conversationId,
|
|
59
|
+
skillId: s.id,
|
|
60
|
+
version: s.version,
|
|
61
|
+
err: e,
|
|
62
|
+
});
|
|
63
|
+
messages.push(message(a.ctx, templateSkillUnreadableText(s.name), {
|
|
64
|
+
templateSkillNotice: { name: s.name },
|
|
65
|
+
}));
|
|
66
|
+
warnings.push(templateSkillUnreadableWarning(s.name));
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
messages.push(message(a.ctx, text, { skill: record }));
|
|
70
|
+
}
|
|
71
|
+
return { messages, warnings };
|
|
72
|
+
}
|
|
73
|
+
const message = (ctx, text, marker) => ({
|
|
74
|
+
type: "user_message",
|
|
75
|
+
payload: { content: [{ type: "text", text }], ...marker, authorAccountId: ctx.accountId },
|
|
76
|
+
});
|
package/dist/runtime/waits.js
CHANGED
|
@@ -153,6 +153,8 @@ let Waits = class Waits {
|
|
|
153
153
|
* {@link suspend}'s transaction: the conditional `running → waiting` and the wait's timeout job
|
|
154
154
|
* owed with it ({@link oweTimeout}). False when the run was no longer running (nothing written).
|
|
155
155
|
*/
|
|
156
|
+
// a run loop hot-path write: shared admission under the run fence (`RunExecution`); it updates
|
|
157
|
+
// only the run row and owes its timeout
|
|
156
158
|
async suspendIn(runId, waitingFor) {
|
|
157
159
|
const row = await this.db
|
|
158
160
|
.updateTable("runs")
|
|
@@ -722,7 +724,7 @@ let Waits = class Waits {
|
|
|
722
724
|
}
|
|
723
725
|
};
|
|
724
726
|
__decorate([
|
|
725
|
-
Transactional({ propagation: "requires_new" })
|
|
727
|
+
Transactional({ propagation: "requires_new", admission: "shared" })
|
|
726
728
|
], Waits.prototype, "suspendIn", null);
|
|
727
729
|
__decorate([
|
|
728
730
|
Transactional()
|
|
@@ -8,9 +8,15 @@ export interface ScheduleBounds {
|
|
|
8
8
|
maxTasksPerOrgCap: number;
|
|
9
9
|
maxRunsPerHourCap: number;
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The org's scheduled-task settings after clamping to the platform bounds. `forbiddenToolsUnreadable`:
|
|
13
|
+
* the stored list cannot be read (`invalidStoredForbiddenTools`); `forbiddenTools` is then `[]`
|
|
14
|
+
* and unattended runs of the org must fail instead of running with nothing forbidden.
|
|
15
|
+
*/
|
|
16
|
+
export type EffectiveScheduleSettings = ScheduledTasksSettings & {
|
|
17
|
+
forbiddenToolsUnreadable: boolean;
|
|
18
|
+
};
|
|
13
19
|
/** An org value outside the platform bounds is clamped: the interval up, the counts down. */
|
|
14
|
-
export declare function effectiveScheduleSettings(org: ScheduledTasksSettings, bounds: ScheduleBounds): EffectiveScheduleSettings;
|
|
20
|
+
export declare function effectiveScheduleSettings(org: ScheduledTasksSettings, bounds: ScheduleBounds, forbiddenToolsUnreadable?: boolean): EffectiveScheduleSettings;
|
|
15
21
|
/** Read the org's effective settings live (PG and the current kernel config). */
|
|
16
22
|
export declare function readScheduleSettings(db: KernelSchemaDb, config: Pick<KernelConfigService, "get">, orgId: string): Promise<EffectiveScheduleSettings>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { invalidStoredForbiddenTools, parseOrgSettings, readStoredOrgSettings, } from "../orgs/settings.service.js";
|
|
2
2
|
/** An org value outside the platform bounds is clamped: the interval up, the counts down. */
|
|
3
|
-
export function effectiveScheduleSettings(org, bounds) {
|
|
3
|
+
export function effectiveScheduleSettings(org, bounds, forbiddenToolsUnreadable = false) {
|
|
4
4
|
return {
|
|
5
5
|
...org,
|
|
6
6
|
forbiddenTools: [...org.forbiddenTools],
|
|
7
|
+
forbiddenToolsUnreadable,
|
|
7
8
|
minIntervalMinutes: Math.max(org.minIntervalMinutes, bounds.minIntervalFloorMinutes),
|
|
8
9
|
maxTasksPerMember: Math.min(org.maxTasksPerMember, bounds.maxTasksPerMemberCap),
|
|
9
10
|
maxTasksPerOrg: Math.min(org.maxTasksPerOrg, bounds.maxTasksPerOrgCap),
|
|
@@ -12,6 +13,6 @@ export function effectiveScheduleSettings(org, bounds) {
|
|
|
12
13
|
}
|
|
13
14
|
/** Read the org's effective settings live (PG and the current kernel config). */
|
|
14
15
|
export async function readScheduleSettings(db, config, orgId) {
|
|
15
|
-
const
|
|
16
|
-
return effectiveScheduleSettings(
|
|
16
|
+
const raw = await readStoredOrgSettings(db, orgId);
|
|
17
|
+
return effectiveScheduleSettings(parseOrgSettings(raw).scheduledTasks, config.get().schedules, invalidStoredForbiddenTools(raw));
|
|
17
18
|
}
|
package/dist/schedules/fire.js
CHANGED
|
@@ -27,6 +27,7 @@ import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
|
27
27
|
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
28
28
|
import { deviceLeaseKey } from "../local-devices/keys.js";
|
|
29
29
|
import { OrgLock, OrgLockModule } from "../orgs/org-lock.js";
|
|
30
|
+
import { FORBIDDEN_TOOLS_UNREADABLE_ERROR } from "../orgs/settings.service.js";
|
|
30
31
|
import { RuntimeModule } from "../runtime/runtime.module.js";
|
|
31
32
|
import { readScheduleSettings } from "./effective-settings.js";
|
|
32
33
|
import { oweSchedSettle, SCHED_LATE_FIRE_SLACK_MS, SCHED_SETTLE_AFTER_MS, SCHED_SETTLE_LONG_CHECKS, SCHED_SETTLE_RECHECK_MS, } from "./job-ids.js";
|
|
@@ -249,6 +250,16 @@ let ScheduledTaskFirer = class ScheduledTaskFirer {
|
|
|
249
250
|
}
|
|
250
251
|
if (!resumed && !settings.enabled)
|
|
251
252
|
return skip("org_disabled");
|
|
253
|
+
// an unattended run must not run with nothing forbidden (a trial run is attended)
|
|
254
|
+
if (!resumed && !run.trial && settings.forbiddenToolsUnreadable) {
|
|
255
|
+
this.log.warn("scheduled task run failed: the org's forbidden tool list is unreadable", {
|
|
256
|
+
orgId,
|
|
257
|
+
taskId: task.id,
|
|
258
|
+
taskRunId: run.id,
|
|
259
|
+
});
|
|
260
|
+
await this.tracker.failStartIn(run.id, FORBIDDEN_TOOLS_UNREADABLE_ERROR);
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
252
263
|
if (!resumed && !(await this.creatorActive(orgId, task.accountId))) {
|
|
253
264
|
return skip("creator_inactive");
|
|
254
265
|
}
|
|
@@ -26,6 +26,7 @@ import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
|
26
26
|
import { orgAllows } from "../local-devices/network-grants.js";
|
|
27
27
|
import { OrgLock } from "../orgs/org-lock.js";
|
|
28
28
|
import { can, roleAtLeast } from "../orgs/roles.js";
|
|
29
|
+
import { FORBIDDEN_TOOLS_UNREADABLE_GRANT_ERROR } from "../orgs/settings.service.js";
|
|
29
30
|
import { ProviderRegistry } from "../runtime/providers.js";
|
|
30
31
|
import { orgHostOutsideCeiling } from "../sandbox/modes.js";
|
|
31
32
|
import { SandboxService } from "../sandbox/sandbox.service.js";
|
|
@@ -1035,6 +1036,10 @@ let ScheduledTasksService = class ScheduledTasksService {
|
|
|
1035
1036
|
async resolveGrants(orgId, role, agent, settings, grants, _deviceId, source = {}) {
|
|
1036
1037
|
if (grants.length === 0)
|
|
1037
1038
|
return [];
|
|
1039
|
+
// fail closed: no grant can be checked against a list that cannot be read
|
|
1040
|
+
if (settings.forbiddenToolsUnreadable) {
|
|
1041
|
+
throw grantNotAllowed(FORBIDDEN_TOOLS_UNREADABLE_GRANT_ERROR);
|
|
1042
|
+
}
|
|
1038
1043
|
const out = new Map();
|
|
1039
1044
|
const network = grants.filter((g) => isNetworkGrantKey(g.toolKey));
|
|
1040
1045
|
if (network.length > 0) {
|
|
@@ -58,6 +58,8 @@ export interface UnattendedRun {
|
|
|
58
58
|
trial: boolean;
|
|
59
59
|
unattendedAsk: "fail" | "wait";
|
|
60
60
|
forbiddenTools: string[];
|
|
61
|
+
/** The org's stored `forbiddenTools` cannot be read: every tool call of the run is refused. */
|
|
62
|
+
forbiddenToolsUnreadable?: boolean;
|
|
61
63
|
}
|
|
62
64
|
/** An unattended run that is not a trial run: the §7 rules apply. */
|
|
63
65
|
export declare const unattendedRules: (u: UnattendedRun | null | undefined) => u is UnattendedRun;
|
|
@@ -146,7 +146,12 @@ export async function unattendedRunOf(db, config, orgId, runId) {
|
|
|
146
146
|
if (!run.trial && (await personJoined(db, runId)))
|
|
147
147
|
return null;
|
|
148
148
|
const s = await readScheduleSettings(db, config, orgId);
|
|
149
|
-
return {
|
|
149
|
+
return {
|
|
150
|
+
...run,
|
|
151
|
+
unattendedAsk: s.unattendedAsk,
|
|
152
|
+
forbiddenTools: s.forbiddenTools,
|
|
153
|
+
forbiddenToolsUnreadable: s.forbiddenToolsUnreadable,
|
|
154
|
+
};
|
|
150
155
|
}
|
|
151
156
|
/**
|
|
152
157
|
* The scheduled task whose grants a run's actions use (spec §7; network ask-to-allow spec §8.1),
|
|
@@ -91,8 +91,7 @@ export async function shareSkillIn(db, v) {
|
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
93
|
* The catalog snapshot `base` with skill `name` replaced by the version just written or proposed
|
|
94
|
-
* (`source` = its prefix), or removed when that version is manual-only.
|
|
95
|
-
* snapshot are not carried (skills default-on spec §8).
|
|
94
|
+
* (`source` = its prefix), or removed when that version is manual-only.
|
|
96
95
|
*/
|
|
97
96
|
function withVersion(base, v) {
|
|
98
97
|
return {
|
package/dist/skills/catalog.d.ts
CHANGED
|
@@ -142,9 +142,7 @@ export declare function lockLatestCatalog(db: KernelSchemaDb, conversationId: st
|
|
|
142
142
|
* 解析只读 skills / agents / 申请(不加锁),不会与别的路径形成死锁。
|
|
143
143
|
*
|
|
144
144
|
* The snapshot also carries each skill's `plugin` and the Claude Code tool-name map (`toolMap`,
|
|
145
|
-
* iff an effective skill has source format `claude-code`).
|
|
146
|
-
* (skills default-on spec §8): a conversation whose latest snapshot has pins gets one without them,
|
|
147
|
-
* and the request tells the model they were removed. Run start reads no object storage.
|
|
145
|
+
* iff an effective skill has source format `claude-code`). Run start reads no object storage.
|
|
148
146
|
*
|
|
149
147
|
* The catalog budget (`skills.catalogBudgetChars`, spec §7) is applied here and recorded in the
|
|
150
148
|
* snapshot: entries past it carry `nameOnly: true` ({@link applyCatalogBudget}); the cut is logged
|
package/dist/skills/catalog.js
CHANGED
|
@@ -254,9 +254,7 @@ export async function lockLatestCatalog(db, conversationId) {
|
|
|
254
254
|
* 解析只读 skills / agents / 申请(不加锁),不会与别的路径形成死锁。
|
|
255
255
|
*
|
|
256
256
|
* The snapshot also carries each skill's `plugin` and the Claude Code tool-name map (`toolMap`,
|
|
257
|
-
* iff an effective skill has source format `claude-code`).
|
|
258
|
-
* (skills default-on spec §8): a conversation whose latest snapshot has pins gets one without them,
|
|
259
|
-
* and the request tells the model they were removed. Run start reads no object storage.
|
|
257
|
+
* iff an effective skill has source format `claude-code`). Run start reads no object storage.
|
|
260
258
|
*
|
|
261
259
|
* The catalog budget (`skills.catalogBudgetChars`, spec §7) is applied here and recorded in the
|
|
262
260
|
* snapshot: entries past it carry `nameOnly: true` ({@link applyCatalogBudget}); the cut is logged
|
|
@@ -22,8 +22,7 @@ export interface CancelledDrafts {
|
|
|
22
22
|
* between "read latest" and "append". Returns the seq written, or null when nothing was written;
|
|
23
23
|
* the caller calls `eventLog.notify` after the commit.
|
|
24
24
|
* `derive` gets the whole latest payload, so `toolMap` is carried forward (it is only recomputed at
|
|
25
|
-
* run start).
|
|
26
|
-
* default-on spec §8).
|
|
25
|
+
* run start).
|
|
27
26
|
*/
|
|
28
27
|
export declare function appendConversationCatalog(deps: ConversationCatalogDeps, conversationId: string, derive: (base: SkillsSnapshot) => SkillsSnapshot | null, idemKey: string, runId?: string | null): Promise<number | null>;
|
|
29
28
|
/**
|
|
@@ -10,8 +10,7 @@ const byName = (a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
|
|
10
10
|
* between "read latest" and "append". Returns the seq written, or null when nothing was written;
|
|
11
11
|
* the caller calls `eventLog.notify` after the commit.
|
|
12
12
|
* `derive` gets the whole latest payload, so `toolMap` is carried forward (it is only recomputed at
|
|
13
|
-
* run start).
|
|
14
|
-
* default-on spec §8).
|
|
13
|
+
* run start).
|
|
15
14
|
*/
|
|
16
15
|
export async function appendConversationCatalog(deps, conversationId, derive, idemKey, runId) {
|
|
17
16
|
const base = (await lockLatestCatalog(deps.db.db, conversationId)) ?? { skills: [] };
|
package/dist/skills/usable.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { skillDisabled } from "../agents/definition.js";
|
|
2
2
|
import { componentOn, platformBuiltin } from "../catalog/component-state.js";
|
|
3
|
+
import { LIVE_INSTALL_STATUSES } from "../catalog/install-status.js";
|
|
3
4
|
/** The `source` prefix of a platform skill version in a snapshot or an invocation record. */
|
|
4
5
|
export const PLATFORM_SOURCE = "platform:";
|
|
5
6
|
/** The snapshot `source` of a platform skill version stored at `prefix` (in `deployment/`). */
|
|
@@ -14,8 +15,6 @@ export function skillFileStore(storage, orgId, source) {
|
|
|
14
15
|
? { store: storage.deployment(), prefix: source.slice(PLATFORM_SOURCE.length) }
|
|
15
16
|
: { store: storage.kernel(orgId), prefix: source };
|
|
16
17
|
}
|
|
17
|
-
/** Plugin install statuses that make a plugin on in the org (phase 1, org catalog state). */
|
|
18
|
-
const LIVE_INSTALL = ["installing", "installed", "upgrading"];
|
|
19
18
|
const byNameThenId = (a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
20
19
|
/** The live platform skill rows on in the org (`ids`: only those), before any name clash. */
|
|
21
20
|
async function platformRowsOn(db, orgId, ids) {
|
|
@@ -48,7 +47,7 @@ async function platformRowsOn(db, orgId, ids) {
|
|
|
48
47
|
.select("a.id")
|
|
49
48
|
.whereRef("a.item_id", "=", "p.catalog_item_id")
|
|
50
49
|
.where("a.org_id", "=", orgId)
|
|
51
|
-
.where("a.status", "in", [...
|
|
50
|
+
.where("a.status", "in", [...LIVE_INSTALL_STATUSES]))
|
|
52
51
|
.as("installed"),
|
|
53
52
|
eb
|
|
54
53
|
.exists(eb
|
|
@@ -84,7 +84,7 @@ export class PrefixedStorage {
|
|
|
84
84
|
}
|
|
85
85
|
scopedStore(ks) {
|
|
86
86
|
const scoped = () => new ScopedStore(this.require(), ks);
|
|
87
|
-
|
|
87
|
+
const store = {
|
|
88
88
|
put: async (key, body, opts) => scoped().put(key, body, opts),
|
|
89
89
|
get: async (key, opts) => scoped().get(key, opts),
|
|
90
90
|
head: async (key) => scoped().head(key),
|
|
@@ -94,6 +94,14 @@ export class PrefixedStorage {
|
|
|
94
94
|
presignGet: async (key, opts) => scoped().presignGet(key, opts),
|
|
95
95
|
presignPut: async (key, opts) => scoped().presignPut(key, opts),
|
|
96
96
|
};
|
|
97
|
+
// the unsigned URI of a key (`s3://bucket/key`, no credentials) comes from the provider when it
|
|
98
|
+
// has one and carries the prefix; without it `uri` stays absent (the caller falls back)
|
|
99
|
+
const provider = this.d.provider();
|
|
100
|
+
const uri = provider?.uri;
|
|
101
|
+
if (provider !== undefined && uri !== undefined) {
|
|
102
|
+
store.uri = (key) => uri.call(provider, ks.key(key));
|
|
103
|
+
}
|
|
104
|
+
return store;
|
|
97
105
|
}
|
|
98
106
|
/** 删除该组织的全部对象:`kernel/<orgId>/` 与每个插件的 `plugins/<插件>/<orgId>/`。返回删除数。 */
|
|
99
107
|
async deleteOrg(orgId) {
|
|
@@ -12,6 +12,7 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
12
12
|
import { connectorToolKey, parseToolKey, validateAllowHost, } from "@capybara-hq/plugin-sdk";
|
|
13
13
|
import { Inject, Injectable } from "@nestjs/common";
|
|
14
14
|
import { sql } from "kysely";
|
|
15
|
+
import { normalizeStoredDefinition } from "../agents/definition.js";
|
|
15
16
|
import { EventLog } from "../conversations/event-log.js";
|
|
16
17
|
import { COMMAND_ASK_TEXT_MAX_CHARS, GIT_ASK_MAX_REFS, GIT_REF_MAX_CHARS, NETWORK_ASK_MAX_HOSTS, NETWORK_HOST_MAX_CHARS, } from "../conversations/events.js";
|
|
17
18
|
import { conversationSourceOf } from "../conversations/source.js";
|
|
@@ -40,7 +41,6 @@ import { ScheduledTaskStore } from "../schedules/store.js";
|
|
|
40
41
|
import { unattendedTaskRunOf } from "../schedules/unattended.js";
|
|
41
42
|
import { gitPushPolicyName, personalAuth } from "./connector-account-policies.js";
|
|
42
43
|
import { pluginDisplayNames } from "./display-names.js";
|
|
43
|
-
import { normalizeStoredDefinitionIn } from "./legacy-data.js";
|
|
44
44
|
import { ToolRegistry } from "./registry.js";
|
|
45
45
|
export { APPROVAL_DENY_REASON_MAX_CHARS } from "../conversations/events.js";
|
|
46
46
|
/** `list` 一次最多返回的审批数(收件箱据此判断这个来源是否取满)。 */
|
|
@@ -1437,9 +1437,7 @@ let ApprovalsService = class ApprovalsService {
|
|
|
1437
1437
|
.executeTakeFirst();
|
|
1438
1438
|
if (!member)
|
|
1439
1439
|
return;
|
|
1440
|
-
const def = task.definition === null
|
|
1441
|
-
? undefined
|
|
1442
|
-
: await normalizeStoredDefinitionIn(t, a.orgId, task.definition);
|
|
1440
|
+
const def = task.definition === null ? undefined : normalizeStoredDefinition(task.definition);
|
|
1443
1441
|
const { tools } = await this.registry.forAgent(a.orgId, {
|
|
1444
1442
|
disabledTools: def?.disabledTools ?? [],
|
|
1445
1443
|
subagentTools: def?.subagentTools,
|
|
@@ -3,8 +3,7 @@ import type { ToolKind } from "./info.js";
|
|
|
3
3
|
* The names (model-visible keys) of the kernel's builtin tools, following Claude Code (tool naming
|
|
4
4
|
* spec §4.1). Plain constants: `BuiltinTools`, the tool factories, the registry, policy and the
|
|
5
5
|
* runtime import them from here. The web keeps its own copy (`apps/web/src/lib/agents.ts`,
|
|
6
|
-
* `lib/timeline.ts`), checked equal by `test/tools/builtin-names.test.ts`.
|
|
7
|
-
* names are in `legacy-keys.ts`, never here.
|
|
6
|
+
* `lib/timeline.ts`), checked equal by `test/tools/builtin-names.test.ts`.
|
|
8
7
|
*/
|
|
9
8
|
export declare const BUILTIN: {
|
|
10
9
|
readonly Bash: "Bash";
|
|
@@ -14,6 +13,7 @@ export declare const BUILTIN: {
|
|
|
14
13
|
readonly Glob: "Glob";
|
|
15
14
|
readonly Grep: "Grep";
|
|
16
15
|
readonly Deliver: "Deliver";
|
|
16
|
+
readonly FetchAttachment: "FetchAttachment";
|
|
17
17
|
readonly Skill: "Skill";
|
|
18
18
|
readonly AskUserQuestion: "AskUserQuestion";
|
|
19
19
|
readonly ReadToolOutput: "ReadToolOutput";
|
|
@@ -71,13 +71,6 @@ export declare const SCHEDULE_TOOL_NAMES: readonly BuiltinName[];
|
|
|
71
71
|
* manage the person's scheduled tasks ({@link SCHEDULE_TOOL_NAMES}).
|
|
72
72
|
*/
|
|
73
73
|
export declare const BUILTIN_TOOL_NAMES: readonly BuiltinName[];
|
|
74
|
-
/**
|
|
75
|
-
* Is `key` a builtin-shaped key (a bare name, no `mcp__` / `plugin__` prefix) that names no
|
|
76
|
-
* builtin the kernel has now, e.g. the removed `SkillWrite`? Saving an agent or an org template
|
|
77
|
-
* drops such a `toolPolicies` key instead of refusing the save: a stored definition may still
|
|
78
|
-
* carry it, and the web sends the whole definition back.
|
|
79
|
-
*/
|
|
80
|
-
export declare function isRemovedBuiltinKey(key: string): boolean;
|
|
81
74
|
/** The builtin that loads a skill (added by the registry when the log has a skills catalog). */
|
|
82
75
|
export declare const SKILL_LOAD: "Skill";
|
|
83
76
|
/** The builtin that searches the tool catalog (added by the registry by org setting and threshold). */
|