@capybara-hq/kernel 0.0.0-stage → 0.1.0-rc.1
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/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +20 -2
- package/bootstrap.json +26 -0
- package/dist/admin/admin.controller.d.ts +139 -0
- package/dist/admin/admin.controller.js +238 -0
- package/dist/admin/extensions.controller.d.ts +100 -0
- package/dist/admin/extensions.controller.js +226 -0
- package/dist/admin/setup.controller.d.ts +36 -0
- package/dist/admin/setup.controller.js +106 -0
- package/dist/admin/setup.service.d.ts +47 -0
- package/dist/admin/setup.service.js +90 -0
- package/dist/agents/agents.controller.d.ts +205 -0
- package/dist/agents/agents.controller.js +144 -0
- package/dist/agents/agents.service.d.ts +177 -0
- package/dist/agents/agents.service.js +677 -0
- package/dist/agents/definition.d.ts +198 -0
- package/dist/agents/definition.js +152 -0
- package/dist/agents/models.controller.d.ts +13 -0
- package/dist/agents/models.controller.js +31 -0
- package/dist/agents/templates.controller.d.ts +15 -0
- package/dist/agents/templates.controller.js +37 -0
- package/dist/agents/templates.d.ts +83 -0
- package/dist/agents/templates.js +173 -0
- package/dist/catalog/admin-catalog.controller.d.ts +143 -0
- package/dist/catalog/admin-catalog.controller.js +245 -0
- package/dist/catalog/catalog.service.d.ts +430 -0
- package/dist/catalog/catalog.service.js +882 -0
- package/dist/catalog/claude/agents.d.ts +27 -0
- package/dist/catalog/claude/agents.js +270 -0
- package/dist/catalog/claude/commands.d.ts +50 -0
- package/dist/catalog/claude/commands.js +179 -0
- package/dist/catalog/claude/manifest.d.ts +69 -0
- package/dist/catalog/claude/manifest.js +134 -0
- package/dist/catalog/claude/marketplace.d.ts +35 -0
- package/dist/catalog/claude/marketplace.js +194 -0
- package/dist/catalog/claude/mcp.d.ts +33 -0
- package/dist/catalog/claude/mcp.js +226 -0
- package/dist/catalog/claude/report.d.ts +86 -0
- package/dist/catalog/claude/report.js +121 -0
- package/dist/catalog/claude/translate.d.ts +56 -0
- package/dist/catalog/claude/translate.js +857 -0
- package/dist/catalog/cli.d.ts +46 -0
- package/dist/catalog/cli.js +211 -0
- package/dist/catalog/git-source.d.ts +127 -0
- package/dist/catalog/git-source.js +520 -0
- package/dist/catalog/marketplace-fetch.d.ts +99 -0
- package/dist/catalog/marketplace-fetch.js +203 -0
- package/dist/catalog/marketplaces.controller.d.ts +97 -0
- package/dist/catalog/marketplaces.controller.js +197 -0
- package/dist/catalog/marketplaces.service.d.ts +340 -0
- package/dist/catalog/marketplaces.service.js +1217 -0
- package/dist/catalog/org-catalog.controller.d.ts +128 -0
- package/dist/catalog/org-catalog.controller.js +277 -0
- package/dist/catalog/org-catalog.service.d.ts +246 -0
- package/dist/catalog/org-catalog.service.js +625 -0
- package/dist/catalog/plugin-import.d.ts +436 -0
- package/dist/catalog/plugin-import.js +1069 -0
- package/dist/catalog/plugin-install.d.ts +447 -0
- package/dist/catalog/plugin-install.js +1333 -0
- package/dist/catalog/plugin-package.d.ts +143 -0
- package/dist/catalog/plugin-package.js +382 -0
- package/dist/catalog/plugin-upgrade.d.ts +222 -0
- package/dist/catalog/plugin-upgrade.js +1219 -0
- package/dist/catalog/requests.service.d.ts +162 -0
- package/dist/catalog/requests.service.js +504 -0
- package/dist/catalog/schema-path.d.ts +7 -0
- package/dist/catalog/schema-path.js +63 -0
- package/dist/catalog/upgrade-targets.d.ts +59 -0
- package/dist/catalog/upgrade-targets.js +90 -0
- package/dist/catalog/versions.d.ts +31 -0
- package/dist/catalog/versions.js +44 -0
- package/dist/channels/actions.d.ts +37 -0
- package/dist/channels/actions.js +121 -0
- package/dist/channels/cards.d.ts +44 -0
- package/dist/channels/cards.js +156 -0
- package/dist/channels/connections.controller.d.ts +59 -0
- package/dist/channels/connections.controller.js +115 -0
- package/dist/channels/connections.service.d.ts +187 -0
- package/dist/channels/connections.service.js +534 -0
- package/dist/channels/features.d.ts +12 -0
- package/dist/channels/features.js +22 -0
- package/dist/channels/inbound.d.ts +120 -0
- package/dist/channels/inbound.js +332 -0
- package/dist/channels/outbound.d.ts +140 -0
- package/dist/channels/outbound.js +1126 -0
- package/dist/channels/phrases.d.ts +100 -0
- package/dist/channels/phrases.js +81 -0
- package/dist/channels/supervisor.d.ts +182 -0
- package/dist/channels/supervisor.js +625 -0
- package/dist/channels/threads.d.ts +29 -0
- package/dist/channels/threads.js +104 -0
- package/dist/channels/webhook-url.d.ts +16 -0
- package/dist/channels/webhook-url.js +34 -0
- package/dist/channels/webhook.controller.d.ts +19 -0
- package/dist/channels/webhook.controller.js +72 -0
- package/dist/channels/webhook.d.ts +73 -0
- package/dist/channels/webhook.js +274 -0
- package/dist/config/docs.d.ts +9 -0
- package/dist/config/docs.js +85 -0
- package/dist/config/env.d.ts +6 -0
- package/dist/config/env.js +73 -0
- package/dist/config/fields.d.ts +42 -0
- package/dist/config/fields.js +214 -0
- package/dist/config/file-source.d.ts +3 -0
- package/dist/config/file-source.js +31 -0
- package/dist/config/load.d.ts +20 -0
- package/dist/config/load.js +98 -0
- package/dist/config/nacos-source.d.ts +31 -0
- package/dist/config/nacos-source.js +229 -0
- package/dist/config/schema.d.ts +237 -0
- package/dist/config/schema.js +1192 -0
- package/dist/config/sources.d.ts +18 -0
- package/dist/config/sources.js +59 -0
- package/dist/config/types.d.ts +9 -0
- package/dist/config/types.js +7 -0
- package/dist/conversations/artifacts.d.ts +52 -0
- package/dist/conversations/artifacts.js +137 -0
- package/dist/conversations/attachments.controller.d.ts +28 -0
- package/dist/conversations/attachments.controller.js +96 -0
- package/dist/conversations/attachments.service.d.ts +180 -0
- package/dist/conversations/attachments.service.js +578 -0
- package/dist/conversations/conversations.controller.d.ts +288 -0
- package/dist/conversations/conversations.controller.js +607 -0
- package/dist/conversations/conversations.service.d.ts +321 -0
- package/dist/conversations/conversations.service.js +754 -0
- package/dist/conversations/event-log.d.ts +122 -0
- package/dist/conversations/event-log.js +259 -0
- package/dist/conversations/events.d.ts +856 -0
- package/dist/conversations/events.js +639 -0
- package/dist/conversations/files.d.ts +92 -0
- package/dist/conversations/files.js +213 -0
- package/dist/conversations/outputs-read.d.ts +34 -0
- package/dist/conversations/outputs-read.js +37 -0
- package/dist/conversations/queue.d.ts +169 -0
- package/dist/conversations/queue.js +527 -0
- package/dist/conversations/sandbox-status.d.ts +21 -0
- package/dist/conversations/sandbox-status.js +24 -0
- package/dist/conversations/selection.d.ts +46 -0
- package/dist/conversations/selection.js +75 -0
- package/dist/conversations/titles.d.ts +93 -0
- package/dist/conversations/titles.js +423 -0
- package/dist/ctx/bus.d.ts +16 -0
- package/dist/ctx/bus.js +101 -0
- package/dist/ctx/create-ctx.d.ts +109 -0
- package/dist/ctx/create-ctx.js +592 -0
- package/dist/ctx/kv.d.ts +4 -0
- package/dist/ctx/kv.js +31 -0
- package/dist/ctx/lock.d.ts +4 -0
- package/dist/ctx/lock.js +39 -0
- package/dist/ctx/namespace.d.ts +6 -0
- package/dist/ctx/namespace.js +12 -0
- package/dist/ctx/queue.d.ts +25 -0
- package/dist/ctx/queue.js +151 -0
- package/dist/ctx/secrets.d.ts +45 -0
- package/dist/ctx/secrets.js +175 -0
- package/dist/db/kernel-schema.d.ts +1122 -0
- package/dist/db/kernel-schema.js +5 -0
- package/dist/db/migrator.d.ts +28 -0
- package/dist/db/migrator.js +140 -0
- package/dist/db/pool.d.ts +21 -0
- package/dist/db/pool.js +28 -0
- package/dist/db/sql-statements.d.ts +34 -0
- package/dist/db/sql-statements.js +168 -0
- package/dist/errors.d.ts +211 -0
- package/dist/errors.js +213 -0
- package/dist/evals/budget.d.ts +61 -0
- package/dist/evals/budget.js +181 -0
- package/dist/evals/diff.d.ts +55 -0
- package/dist/evals/diff.js +133 -0
- package/dist/evals/judge.d.ts +53 -0
- package/dist/evals/judge.js +149 -0
- package/dist/evals/plan.d.ts +47 -0
- package/dist/evals/plan.js +77 -0
- package/dist/evals/reconstruct.d.ts +137 -0
- package/dist/evals/reconstruct.js +322 -0
- package/dist/evals/recorded-tools.d.ts +54 -0
- package/dist/evals/recorded-tools.js +167 -0
- package/dist/evals/run-replay.d.ts +86 -0
- package/dist/evals/run-replay.js +502 -0
- package/dist/evals/runs.controller.d.ts +100 -0
- package/dist/evals/runs.controller.js +199 -0
- package/dist/evals/runs.service.d.ts +275 -0
- package/dist/evals/runs.service.js +836 -0
- package/dist/evals/sets.controller.d.ts +61 -0
- package/dist/evals/sets.controller.js +183 -0
- package/dist/evals/sets.service.d.ts +128 -0
- package/dist/evals/sets.service.js +558 -0
- package/dist/evals/snapshot.d.ts +76 -0
- package/dist/evals/snapshot.js +207 -0
- package/dist/evals/step-replay.d.ts +113 -0
- package/dist/evals/step-replay.js +181 -0
- package/dist/evals/trajectory.controller.d.ts +41 -0
- package/dist/evals/trajectory.controller.js +88 -0
- package/dist/evals/trajectory.d.ts +144 -0
- package/dist/evals/trajectory.js +338 -0
- package/dist/evals/trajectory.service.d.ts +108 -0
- package/dist/evals/trajectory.service.js +323 -0
- package/dist/evals/worker.d.ts +101 -0
- package/dist/evals/worker.js +790 -0
- package/dist/extensions/admin-ops.d.ts +105 -0
- package/dist/extensions/admin-ops.js +353 -0
- package/dist/extensions/admin-view.d.ts +79 -0
- package/dist/extensions/admin-view.js +327 -0
- package/dist/extensions/approvals.d.ts +119 -0
- package/dist/extensions/approvals.js +205 -0
- package/dist/extensions/blobs.d.ts +45 -0
- package/dist/extensions/blobs.js +160 -0
- package/dist/extensions/bootstrap.d.ts +176 -0
- package/dist/extensions/bootstrap.js +535 -0
- package/dist/extensions/cli.d.ts +61 -0
- package/dist/extensions/cli.js +165 -0
- package/dist/extensions/config-json-schema.d.ts +9 -0
- package/dist/extensions/config-json-schema.js +73 -0
- package/dist/extensions/deployment-config.d.ts +138 -0
- package/dist/extensions/deployment-config.js +394 -0
- package/dist/extensions/enabled.d.ts +31 -0
- package/dist/extensions/enabled.js +55 -0
- package/dist/extensions/hooks.d.ts +161 -0
- package/dist/extensions/hooks.js +425 -0
- package/dist/extensions/host.d.ts +577 -0
- package/dist/extensions/host.js +2071 -0
- package/dist/extensions/inflight.d.ts +69 -0
- package/dist/extensions/inflight.js +277 -0
- package/dist/extensions/installs.d.ts +166 -0
- package/dist/extensions/installs.js +253 -0
- package/dist/extensions/instance.d.ts +167 -0
- package/dist/extensions/instance.js +329 -0
- package/dist/extensions/ledger.d.ts +30 -0
- package/dist/extensions/ledger.js +50 -0
- package/dist/extensions/lifecycle.d.ts +80 -0
- package/dist/extensions/lifecycle.js +152 -0
- package/dist/extensions/migrate-lock.d.ts +51 -0
- package/dist/extensions/migrate-lock.js +100 -0
- package/dist/extensions/org-config.controller.d.ts +24 -0
- package/dist/extensions/org-config.controller.js +59 -0
- package/dist/extensions/org-config.d.ts +169 -0
- package/dist/extensions/org-config.js +520 -0
- package/dist/extensions/package.d.ts +115 -0
- package/dist/extensions/package.js +246 -0
- package/dist/extensions/permission-set.d.ts +117 -0
- package/dist/extensions/permission-set.js +184 -0
- package/dist/extensions/permission-view.d.ts +194 -0
- package/dist/extensions/permission-view.js +284 -0
- package/dist/extensions/registry.d.ts +24 -0
- package/dist/extensions/registry.js +56 -0
- package/dist/extensions/resolve.d.ts +12 -0
- package/dist/extensions/resolve.js +71 -0
- package/dist/extensions/sources.d.ts +69 -0
- package/dist/extensions/sources.js +120 -0
- package/dist/extensions/sync.d.ts +40 -0
- package/dist/extensions/sync.js +242 -0
- package/dist/files/previewers.controller.d.ts +46 -0
- package/dist/files/previewers.controller.js +105 -0
- package/dist/files/previewers.d.ts +100 -0
- package/dist/files/previewers.js +250 -0
- package/dist/http/api.module.d.ts +114 -0
- package/dist/http/api.module.js +448 -0
- package/dist/http/app.d.ts +77 -0
- package/dist/http/app.js +220 -0
- package/dist/http/error.filter.d.ts +21 -0
- package/dist/http/error.filter.js +85 -0
- package/dist/http/gateway.module.d.ts +15 -0
- package/dist/http/gateway.module.js +13 -0
- package/dist/http/health.controller.d.ts +26 -0
- package/dist/http/health.controller.js +79 -0
- package/dist/http/nest-logger.d.ts +20 -0
- package/dist/http/nest-logger.js +28 -0
- package/dist/http/plugin-dispatch.d.ts +68 -0
- package/dist/http/plugin-dispatch.js +200 -0
- package/dist/http/tokens.d.ts +131 -0
- package/dist/http/tokens.js +131 -0
- package/dist/http/zod.pipe.d.ts +8 -0
- package/dist/http/zod.pipe.js +14 -0
- package/dist/identity/accounts.d.ts +93 -0
- package/dist/identity/accounts.js +367 -0
- package/dist/identity/api-tokens.d.ts +73 -0
- package/dist/identity/api-tokens.js +197 -0
- package/dist/identity/audit.d.ts +23 -0
- package/dist/identity/audit.js +41 -0
- package/dist/identity/auth.controller.d.ts +40 -0
- package/dist/identity/auth.controller.js +130 -0
- package/dist/identity/auth.guard.d.ts +41 -0
- package/dist/identity/auth.guard.js +162 -0
- package/dist/identity/binding.d.ts +47 -0
- package/dist/identity/binding.js +84 -0
- package/dist/identity/cookies.d.ts +16 -0
- package/dist/identity/cookies.js +32 -0
- package/dist/identity/credential-check.d.ts +17 -0
- package/dist/identity/credential-check.js +24 -0
- package/dist/identity/enterprise-admin.d.ts +14 -0
- package/dist/identity/enterprise-admin.js +27 -0
- package/dist/identity/external.d.ts +106 -0
- package/dist/identity/external.js +337 -0
- package/dist/identity/hash.d.ts +2 -0
- package/dist/identity/hash.js +3 -0
- package/dist/identity/login.d.ts +6 -0
- package/dist/identity/login.js +20 -0
- package/dist/identity/me.controller.d.ts +61 -0
- package/dist/identity/me.controller.js +159 -0
- package/dist/identity/passwords.d.ts +6 -0
- package/dist/identity/passwords.js +37 -0
- package/dist/identity/principal.d.ts +56 -0
- package/dist/identity/principal.js +38 -0
- package/dist/identity/rate-limit.d.ts +55 -0
- package/dist/identity/rate-limit.js +121 -0
- package/dist/identity/sessions.d.ts +84 -0
- package/dist/identity/sessions.js +306 -0
- package/dist/identity/settings.d.ts +121 -0
- package/dist/identity/settings.js +248 -0
- package/dist/identity/sso.controller.d.ts +59 -0
- package/dist/identity/sso.controller.js +192 -0
- package/dist/identity/sso.d.ts +83 -0
- package/dist/identity/sso.js +202 -0
- package/dist/inbox/inbox.service.d.ts +43 -0
- package/dist/inbox/inbox.service.js +57 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.js +67 -0
- package/dist/kernel.d.ts +259 -0
- package/dist/kernel.js +1326 -0
- package/dist/log-config.d.ts +9 -0
- package/dist/log-config.js +27 -0
- package/dist/log-context.d.ts +32 -0
- package/dist/log-context.js +40 -0
- package/dist/log-loki.d.ts +34 -0
- package/dist/log-loki.js +145 -0
- package/dist/log.d.ts +79 -0
- package/dist/log.js +303 -0
- package/dist/models/prices.d.ts +53 -0
- package/dist/models/prices.js +121 -0
- package/dist/models/purposes.controller.d.ts +19 -0
- package/dist/models/purposes.controller.js +56 -0
- package/dist/models/purposes.d.ts +140 -0
- package/dist/models/purposes.js +267 -0
- package/dist/net/proxy.d.ts +44 -0
- package/dist/net/proxy.js +162 -0
- package/dist/net/public-address.d.ts +60 -0
- package/dist/net/public-address.js +272 -0
- package/dist/net/safe-fetch.d.ts +38 -0
- package/dist/net/safe-fetch.js +140 -0
- package/dist/orgs/directory-sync.controller.d.ts +14 -0
- package/dist/orgs/directory-sync.controller.js +40 -0
- package/dist/orgs/directory-sync.d.ts +166 -0
- package/dist/orgs/directory-sync.js +558 -0
- package/dist/orgs/invitations.controller.d.ts +58 -0
- package/dist/orgs/invitations.controller.js +137 -0
- package/dist/orgs/invitations.service.d.ts +80 -0
- package/dist/orgs/invitations.service.js +217 -0
- package/dist/orgs/members.service.d.ts +63 -0
- package/dist/orgs/members.service.js +234 -0
- package/dist/orgs/offboarding.d.ts +141 -0
- package/dist/orgs/offboarding.js +398 -0
- package/dist/orgs/org-lock.d.ts +32 -0
- package/dist/orgs/org-lock.js +46 -0
- package/dist/orgs/org.guard.d.ts +35 -0
- package/dist/orgs/org.guard.js +95 -0
- package/dist/orgs/orgs.controller.d.ts +78 -0
- package/dist/orgs/orgs.controller.js +192 -0
- package/dist/orgs/orgs.service.d.ts +61 -0
- package/dist/orgs/orgs.service.js +209 -0
- package/dist/orgs/roles.d.ts +13 -0
- package/dist/orgs/roles.js +58 -0
- package/dist/orgs/settings.controller.d.ts +20 -0
- package/dist/orgs/settings.controller.js +53 -0
- package/dist/orgs/settings.service.d.ts +120 -0
- package/dist/orgs/settings.service.js +178 -0
- package/dist/packages/npm.d.ts +50 -0
- package/dist/packages/npm.js +218 -0
- package/dist/packages/provenance.d.ts +47 -0
- package/dist/packages/provenance.js +147 -0
- package/dist/packages/tgz.d.ts +76 -0
- package/dist/packages/tgz.js +225 -0
- package/dist/runtime/abort.d.ts +32 -0
- package/dist/runtime/abort.js +71 -0
- package/dist/runtime/checkpointer.d.ts +32 -0
- package/dist/runtime/checkpointer.js +243 -0
- package/dist/runtime/context/build.d.ts +254 -0
- package/dist/runtime/context/build.js +693 -0
- package/dist/runtime/context/claude-tools.d.ts +11 -0
- package/dist/runtime/context/claude-tools.js +24 -0
- package/dist/runtime/context/compaction.d.ts +26 -0
- package/dist/runtime/context/compaction.js +195 -0
- package/dist/runtime/context/pairing.d.ts +11 -0
- package/dist/runtime/context/pairing.js +82 -0
- package/dist/runtime/context/reminders.d.ts +5 -0
- package/dist/runtime/context/reminders.js +11 -0
- package/dist/runtime/context/skills.d.ts +105 -0
- package/dist/runtime/context/skills.js +283 -0
- package/dist/runtime/context/tokens.d.ts +19 -0
- package/dist/runtime/context/tokens.js +104 -0
- package/dist/runtime/conversation-lock.d.ts +40 -0
- package/dist/runtime/conversation-lock.js +97 -0
- package/dist/runtime/hook-calls.d.ts +84 -0
- package/dist/runtime/hook-calls.js +136 -0
- package/dist/runtime/langgraph-loop.d.ts +52 -0
- package/dist/runtime/langgraph-loop.js +247 -0
- package/dist/runtime/loop.d.ts +93 -0
- package/dist/runtime/loop.js +7 -0
- package/dist/runtime/maintenance.d.ts +80 -0
- package/dist/runtime/maintenance.js +148 -0
- package/dist/runtime/media-cache.d.ts +21 -0
- package/dist/runtime/media-cache.js +51 -0
- package/dist/runtime/model-call.d.ts +176 -0
- package/dist/runtime/model-call.js +1049 -0
- package/dist/runtime/providers.d.ts +86 -0
- package/dist/runtime/providers.js +224 -0
- package/dist/runtime/quota.d.ts +29 -0
- package/dist/runtime/quota.js +70 -0
- package/dist/runtime/run-finish.d.ts +45 -0
- package/dist/runtime/run-finish.js +69 -0
- package/dist/runtime/run-queue.d.ts +121 -0
- package/dist/runtime/run-queue.js +493 -0
- package/dist/runtime/run-worker.d.ts +138 -0
- package/dist/runtime/run-worker.js +806 -0
- package/dist/runtime/stream.controller.d.ts +34 -0
- package/dist/runtime/stream.controller.js +122 -0
- package/dist/runtime/stream.d.ts +63 -0
- package/dist/runtime/stream.js +262 -0
- package/dist/runtime/subagents/child.d.ts +80 -0
- package/dist/runtime/subagents/child.js +225 -0
- package/dist/runtime/subagents/definition.d.ts +103 -0
- package/dist/runtime/subagents/definition.js +392 -0
- package/dist/runtime/subagents/dispatch.d.ts +69 -0
- package/dist/runtime/subagents/dispatch.js +502 -0
- package/dist/runtime/subagents/limits.d.ts +23 -0
- package/dist/runtime/subagents/limits.js +34 -0
- package/dist/runtime/subagents/org-agents.d.ts +50 -0
- package/dist/runtime/subagents/org-agents.js +70 -0
- package/dist/runtime/subagents/preamble.d.ts +7 -0
- package/dist/runtime/subagents/preamble.js +11 -0
- package/dist/runtime/subagents/progress.d.ts +26 -0
- package/dist/runtime/subagents/progress.js +36 -0
- package/dist/runtime/subagents/roster.d.ts +55 -0
- package/dist/runtime/subagents/roster.js +111 -0
- package/dist/runtime/subagents/skill-fork.d.ts +123 -0
- package/dist/runtime/subagents/skill-fork.js +259 -0
- package/dist/runtime/usage-report.d.ts +163 -0
- package/dist/runtime/usage-report.js +551 -0
- package/dist/runtime/waits.d.ts +233 -0
- package/dist/runtime/waits.js +883 -0
- package/dist/sandbox/leases.d.ts +169 -0
- package/dist/sandbox/leases.js +515 -0
- package/dist/sandbox/lifecycle.d.ts +21 -0
- package/dist/sandbox/lifecycle.js +68 -0
- package/dist/sandbox/sandbox.service.d.ts +249 -0
- package/dist/sandbox/sandbox.service.js +908 -0
- package/dist/skills/catalog.d.ts +149 -0
- package/dist/skills/catalog.js +405 -0
- package/dist/skills/changes.controller.d.ts +56 -0
- package/dist/skills/changes.controller.js +136 -0
- package/dist/skills/changes.service.d.ts +175 -0
- package/dist/skills/changes.service.js +805 -0
- package/dist/skills/invocable.controller.d.ts +23 -0
- package/dist/skills/invocable.controller.js +50 -0
- package/dist/skills/invocation-keys.d.ts +23 -0
- package/dist/skills/invocation-keys.js +44 -0
- package/dist/skills/invoke.d.ts +135 -0
- package/dist/skills/invoke.js +286 -0
- package/dist/skills/package.d.ts +87 -0
- package/dist/skills/package.js +227 -0
- package/dist/skills/skills.controller.d.ts +40 -0
- package/dist/skills/skills.controller.js +110 -0
- package/dist/skills/skills.service.d.ts +192 -0
- package/dist/skills/skills.service.js +567 -0
- package/dist/storage/prefix.d.ts +36 -0
- package/dist/storage/prefix.js +104 -0
- package/dist/storage/purge.d.ts +27 -0
- package/dist/storage/purge.js +75 -0
- package/dist/storage/storage.service.d.ts +44 -0
- package/dist/storage/storage.service.js +145 -0
- package/dist/text.d.ts +13 -0
- package/dist/text.js +13 -0
- package/dist/tools/approvals.controller.d.ts +53 -0
- package/dist/tools/approvals.controller.js +128 -0
- package/dist/tools/approvals.service.d.ts +172 -0
- package/dist/tools/approvals.service.js +568 -0
- package/dist/tools/breaker.d.ts +28 -0
- package/dist/tools/breaker.js +72 -0
- package/dist/tools/builtins/agent.d.ts +81 -0
- package/dist/tools/builtins/agent.js +223 -0
- package/dist/tools/builtins/ask-user.d.ts +28 -0
- package/dist/tools/builtins/ask-user.js +139 -0
- package/dist/tools/builtins/read-tool-output.d.ts +18 -0
- package/dist/tools/builtins/read-tool-output.js +108 -0
- package/dist/tools/builtins/sandbox/bash.d.ts +16 -0
- package/dist/tools/builtins/sandbox/bash.js +137 -0
- package/dist/tools/builtins/sandbox/common.d.ts +116 -0
- package/dist/tools/builtins/sandbox/common.js +306 -0
- package/dist/tools/builtins/sandbox/deliver.d.ts +5 -0
- package/dist/tools/builtins/sandbox/deliver.js +180 -0
- package/dist/tools/builtins/sandbox/edit.d.ts +4 -0
- package/dist/tools/builtins/sandbox/edit.js +98 -0
- package/dist/tools/builtins/sandbox/glob-match.d.ts +25 -0
- package/dist/tools/builtins/sandbox/glob-match.js +240 -0
- package/dist/tools/builtins/sandbox/glob.d.ts +4 -0
- package/dist/tools/builtins/sandbox/glob.js +104 -0
- package/dist/tools/builtins/sandbox/grep.d.ts +9 -0
- package/dist/tools/builtins/sandbox/grep.js +133 -0
- package/dist/tools/builtins/sandbox/index.d.ts +12 -0
- package/dist/tools/builtins/sandbox/index.js +27 -0
- package/dist/tools/builtins/sandbox/names.d.ts +7 -0
- package/dist/tools/builtins/sandbox/names.js +20 -0
- package/dist/tools/builtins/sandbox/read.d.ts +8 -0
- package/dist/tools/builtins/sandbox/read.js +121 -0
- package/dist/tools/builtins/sandbox/write.d.ts +4 -0
- package/dist/tools/builtins/sandbox/write.js +88 -0
- package/dist/tools/builtins/skill-load.d.ts +53 -0
- package/dist/tools/builtins/skill-load.js +446 -0
- package/dist/tools/builtins/skill-write.d.ts +59 -0
- package/dist/tools/builtins/skill-write.js +244 -0
- package/dist/tools/builtins/tool-search.d.ts +31 -0
- package/dist/tools/builtins/tool-search.js +171 -0
- package/dist/tools/connector-content.controller.d.ts +34 -0
- package/dist/tools/connector-content.controller.js +78 -0
- package/dist/tools/connector-content.d.ts +104 -0
- package/dist/tools/connector-content.js +267 -0
- package/dist/tools/connectors.controller.d.ts +210 -0
- package/dist/tools/connectors.controller.js +234 -0
- package/dist/tools/connectors.service.d.ts +303 -0
- package/dist/tools/connectors.service.js +1102 -0
- package/dist/tools/credentials.d.ts +139 -0
- package/dist/tools/credentials.js +351 -0
- package/dist/tools/drift.d.ts +141 -0
- package/dist/tools/drift.js +539 -0
- package/dist/tools/elicitation.d.ts +81 -0
- package/dist/tools/elicitation.js +266 -0
- package/dist/tools/endpoint.d.ts +18 -0
- package/dist/tools/endpoint.js +115 -0
- package/dist/tools/info.d.ts +67 -0
- package/dist/tools/info.js +113 -0
- package/dist/tools/naming.d.ts +27 -0
- package/dist/tools/naming.js +47 -0
- package/dist/tools/oauth/discovery.d.ts +65 -0
- package/dist/tools/oauth/discovery.js +307 -0
- package/dist/tools/oauth/flow.d.ts +63 -0
- package/dist/tools/oauth/flow.js +237 -0
- package/dist/tools/oauth/oauth.controller.d.ts +31 -0
- package/dist/tools/oauth/oauth.controller.js +95 -0
- package/dist/tools/oauth/tokens.d.ts +111 -0
- package/dist/tools/oauth/tokens.js +258 -0
- package/dist/tools/outputs.d.ts +61 -0
- package/dist/tools/outputs.js +156 -0
- package/dist/tools/pipeline.d.ts +322 -0
- package/dist/tools/pipeline.js +1236 -0
- package/dist/tools/policy.d.ts +60 -0
- package/dist/tools/policy.js +236 -0
- package/dist/tools/questions.controller.d.ts +24 -0
- package/dist/tools/questions.controller.js +58 -0
- package/dist/tools/questions.service.d.ts +103 -0
- package/dist/tools/questions.service.js +295 -0
- package/dist/tools/redact.d.ts +20 -0
- package/dist/tools/redact.js +60 -0
- package/dist/tools/registry.d.ts +246 -0
- package/dist/tools/registry.js +481 -0
- package/dist/tools/resources.d.ts +16 -0
- package/dist/tools/resources.js +76 -0
- package/dist/tools/specs.d.ts +14 -0
- package/dist/tools/specs.js +31 -0
- package/dist/tools/validate.d.ts +20 -0
- package/dist/tools/validate.js +183 -0
- package/dist/tools/view.d.ts +43 -0
- package/dist/tools/view.js +225 -0
- package/dist/ui/embed-token.d.ts +31 -0
- package/dist/ui/embed-token.js +132 -0
- package/dist/ui/registry.d.ts +58 -0
- package/dist/ui/registry.js +90 -0
- package/dist/ui/ui-stream.d.ts +37 -0
- package/dist/ui/ui-stream.js +162 -0
- package/dist/ui/views.controller.d.ts +81 -0
- package/dist/ui/views.controller.js +261 -0
- package/dist/ui/views.d.ts +155 -0
- package/dist/ui/views.js +306 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.js +6 -0
- package/package.json +69 -3
- package/src/migrations/0001_init.sql +8 -0
- package/src/migrations/0002_secrets.sql +8 -0
- package/src/migrations/0003_identity.sql +117 -0
- package/src/migrations/0004_plugin_org_config_nullable.sql +3 -0
- package/src/migrations/0005_agents.sql +27 -0
- package/src/migrations/0006_conversations.sql +37 -0
- package/src/migrations/0007_checkpoints.sql +26 -0
- package/src/migrations/0008_runs_trigger_seq.sql +3 -0
- package/src/migrations/0009_runs_active_unique.sql +4 -0
- package/src/migrations/0010_tools.sql +125 -0
- package/src/migrations/0011_approvals_spec.sql +10 -0
- package/src/migrations/0012_run_waits.sql +24 -0
- package/src/migrations/0013_app_tools_source.sql +4 -0
- package/src/migrations/0014_tool_specs.sql +8 -0
- package/src/migrations/0015_tool_drift.sql +20 -0
- package/src/migrations/0016_plugin_permissions.sql +11 -0
- package/src/migrations/0017_identity_sources.sql +6 -0
- package/src/migrations/0018_channels.sql +74 -0
- package/src/migrations/0019_identity_trust.sql +17 -0
- package/src/migrations/0020_channel_card_lookup.sql +10 -0
- package/src/migrations/0021_org_storage_purge.sql +9 -0
- package/src/migrations/0022_attachments.sql +29 -0
- package/src/migrations/0023_sandboxes.sql +37 -0
- package/src/migrations/0024_skills.sql +46 -0
- package/src/migrations/0025_skills_catalog_idx.sql +6 -0
- package/src/migrations/0026_skill_changes.sql +34 -0
- package/src/migrations/0027_model_prices.sql +18 -0
- package/src/migrations/0028_evals.sql +105 -0
- package/src/migrations/0029_model_purposes.sql +18 -0
- package/src/migrations/0030_plugin_installs.sql +73 -0
- package/src/migrations/0031_plugin_snapshot_source.sql +6 -0
- package/src/migrations/0032_plugin_deployment_configs.sql +10 -0
- package/src/migrations/0033_rename_apps_to_connectors.sql +25 -0
- package/src/migrations/0034_directory.sql +49 -0
- package/src/migrations/0035_catalogs.sql +40 -0
- package/src/migrations/0036_app_import_staging.sql +17 -0
- package/src/migrations/0037_directory_installs.sql +92 -0
- package/src/migrations/0038_channel_inbound_mode.sql +6 -0
- package/src/migrations/0039_channel_card_pending.sql +8 -0
- package/src/migrations/0040_usage_report_sweep.sql +10 -0
- package/src/migrations/0041_rename_plugins_to_extensions.sql +38 -0
- package/src/migrations/0042_rename_directory_to_catalog.sql +80 -0
- package/src/migrations/0043_rename_app_installs_to_plugin_installs.sql +20 -0
- package/src/migrations/0044_catalog_one_kind.sql +90 -0
- package/src/migrations/0045_plugin_dependencies.sql +9 -0
- package/src/migrations/0046_git_sources.sql +25 -0
- package/src/migrations/0047_marketplace_entry_heads.sql +7 -0
- package/src/migrations/0048_marketplace_entry_trees.sql +8 -0
- package/src/migrations/0049_plugin_upgrades.sql +37 -0
- package/src/migrations/0050_bootstrap.sql +53 -0
- package/src/migrations/0051_claude_compat.sql +26 -0
- package/src/migrations/0052_conversations_account_agent_idx.sql +5 -0
- package/src/migrations/0053_subagents.sql +73 -0
- package/src/migrations/0054_subagent_wait_expiry.sql +7 -0
- package/src/migrations/0055_subagent_parent_indexes.sql +10 -0
- package/src/migrations/0056_approval_reason.sql +3 -0
- package/src/migrations/0057_conversation_titles.sql +11 -0
- package/src/migrations/0058_conversation_selection.sql +4 -0
- package/src/migrations/0059_conversation_queue.sql +22 -0
- package/src/migrations/0060_file_previewers.sql +10 -0
- package/src/migrations/0061_queue_selection.sql +5 -0
- package/src/migrations/0062_queued_skill.sql +8 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sub-agent preamble (spec §6.3, model-visible): rendered in a child's system text after
|
|
3
|
+
* `BEHAVIOR_RULES` and before its instructions. Frozen into each child's `subagent_started` at
|
|
4
|
+
* dispatch, and request building reads it from there, so changing this text never alters an old
|
|
5
|
+
* child's requests.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SUBAGENT_PREAMBLE: string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sub-agent preamble (spec §6.3, model-visible): rendered in a child's system text after
|
|
3
|
+
* `BEHAVIOR_RULES` and before its instructions. Frozen into each child's `subagent_started` at
|
|
4
|
+
* dispatch, and request building reads it from there, so changing this text never alters an old
|
|
5
|
+
* child's requests.
|
|
6
|
+
*/
|
|
7
|
+
export const SUBAGENT_PREAMBLE = "You are a sub-agent. Another agent dispatched you with the task in the first user message. " +
|
|
8
|
+
"Work on it on your own: the user does not watch this conversation and you cannot ask them " +
|
|
9
|
+
"questions. When you are done, reply with your final report. That reply is the only thing " +
|
|
10
|
+
"returned to the agent that dispatched you, so include everything it needs. If you cannot " +
|
|
11
|
+
"finish, say what is missing and why.";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Logger } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { KernelDb } from "../../db/kernel-schema.js";
|
|
3
|
+
/** A finished step of a sub-agent run, as the loop reports it. */
|
|
4
|
+
export interface SubagentStep {
|
|
5
|
+
/** The parent conversation, whose topic gets the message. */
|
|
6
|
+
parentConversationId: string;
|
|
7
|
+
/** The child conversation (the sub-agent's id). */
|
|
8
|
+
conversationId: string;
|
|
9
|
+
runId: string;
|
|
10
|
+
step: number;
|
|
11
|
+
}
|
|
12
|
+
export interface SubagentProgressDeps {
|
|
13
|
+
db: KernelDb;
|
|
14
|
+
bus: {
|
|
15
|
+
publish(topic: string, payload: unknown): Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
log: Pick<Logger, "warn">;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Publishes `{ kind: "subagent_progress", subagentId, step, toolCalls, lastToolKey? }` on the
|
|
21
|
+
* parent conversation's topic after a child step (sub-agents spec §14.2). Ephemeral: not in any
|
|
22
|
+
* log, lost on reconnect (the summary API has the current numbers). The counts come from the
|
|
23
|
+
* child run's log (its `tool_result` events), never from process memory, so any replica running
|
|
24
|
+
* the step reports the same. Never throws: a lost progress message costs nothing.
|
|
25
|
+
*/
|
|
26
|
+
export declare function publishSubagentProgress(d: SubagentProgressDeps, s: SubagentStep): Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
import { conversationTopic } from "../../conversations/event-log.js";
|
|
3
|
+
/**
|
|
4
|
+
* Publishes `{ kind: "subagent_progress", subagentId, step, toolCalls, lastToolKey? }` on the
|
|
5
|
+
* parent conversation's topic after a child step (sub-agents spec §14.2). Ephemeral: not in any
|
|
6
|
+
* log, lost on reconnect (the summary API has the current numbers). The counts come from the
|
|
7
|
+
* child run's log (its `tool_result` events), never from process memory, so any replica running
|
|
8
|
+
* the step reports the same. Never throws: a lost progress message costs nothing.
|
|
9
|
+
*/
|
|
10
|
+
export async function publishSubagentProgress(d, s) {
|
|
11
|
+
try {
|
|
12
|
+
const { rows } = await sql `
|
|
13
|
+
SELECT count(*) AS n,
|
|
14
|
+
(array_agg(e.payload->>'toolKey' ORDER BY e.seq DESC))[1] AS last
|
|
15
|
+
FROM capybara.conversation_events e
|
|
16
|
+
WHERE e.conversation_id = ${s.conversationId} AND e.run_id = ${s.runId}
|
|
17
|
+
AND e.type = 'tool_result'
|
|
18
|
+
`.execute(d.db);
|
|
19
|
+
const row = rows[0];
|
|
20
|
+
const msg = {
|
|
21
|
+
kind: "subagent_progress",
|
|
22
|
+
subagentId: s.conversationId,
|
|
23
|
+
step: s.step,
|
|
24
|
+
toolCalls: Number(row?.n ?? 0),
|
|
25
|
+
...(row?.last != null && { lastToolKey: row.last }),
|
|
26
|
+
};
|
|
27
|
+
await d.bus.publish(conversationTopic(s.parentConversationId), msg);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
d.log.warn("sub-agent progress publish failed", {
|
|
31
|
+
conversationId: s.conversationId,
|
|
32
|
+
runId: s.runId,
|
|
33
|
+
err,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { AgentDefinition } from "../../agents/definition.js";
|
|
2
|
+
import type { KernelDb } from "../../db/kernel-schema.js";
|
|
3
|
+
/**
|
|
4
|
+
* The sub-agent roster of an agent version (phase C, spec §4.3, §5.1): the agent types its `agent`
|
|
5
|
+
* tool offers, in the order the description lists them.
|
|
6
|
+
*/
|
|
7
|
+
export interface RosterEntry {
|
|
8
|
+
/** `general-purpose` | inline name | `<plugin>:<name>` | an org agent's roster name (`as`). */
|
|
9
|
+
type: string;
|
|
10
|
+
source: "general" | "inline" | "plugin" | "agent";
|
|
11
|
+
/** When to use it (shown in the tool description), cut to {@link ROSTER_DESCRIPTION_MAX}. */
|
|
12
|
+
description: string;
|
|
13
|
+
/** Plugin templates: the `agent_templates` id. */
|
|
14
|
+
templateId?: string;
|
|
15
|
+
/** Org agents: the allowlisted agent id. */
|
|
16
|
+
agentId?: string;
|
|
17
|
+
/** Org agents: the agent's current name, when it is still a live agent of the org. */
|
|
18
|
+
agentName?: string;
|
|
19
|
+
/** Plugin templates: the plugin name. */
|
|
20
|
+
plugin?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const ROSTER_DESCRIPTION_MAX = 1024;
|
|
23
|
+
/** The description of `general-purpose` in the roster (spec §4.3, model-visible). */
|
|
24
|
+
export declare const GENERAL_PURPOSE_DESCRIPTION = "a copy of you with your tools and skills, for multi-step work.";
|
|
25
|
+
/** Plugin template type: `<plugin>:<name>`. */
|
|
26
|
+
export declare const templateType: (plugin: string, name: string) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Resolves the roster of `parent` (spec §4.3): `general-purpose` first unless
|
|
29
|
+
* `subagents.general === false`, then the plugin templates, inline templates and allowlisted org
|
|
30
|
+
* agents, each in the owner's order, at most {@link SUBAGENT_ROSTER_MAX} entries. Templates deleted
|
|
31
|
+
* since the save are skipped; allowlisted org agents stay listed (the dispatch checks their gates
|
|
32
|
+
* and refuses with the §4.5 text), with `agentName` only while the agent is live.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveRoster(db: KernelDb, orgId: string, parent: Pick<AgentDefinition, "subagents">): Promise<RosterEntry[]>;
|
|
35
|
+
/**
|
|
36
|
+
* The roster entry for a requested `subagent_type`: an exact type first; else a bare `<name>`
|
|
37
|
+
* matches the plugin template `<plugin>:<name>` when exactly one has it (as Claude Code accepts
|
|
38
|
+
* `reviewer` for `my-plugin:reviewer`). Null when nothing matches.
|
|
39
|
+
*/
|
|
40
|
+
export declare function findType(roster: RosterEntry[], requested: string): RosterEntry | null;
|
|
41
|
+
/** A forked skill's `agent` that runs as `general-purpose` by definition (absent ones aside). */
|
|
42
|
+
export declare const isGeneralAlias: (agent: string) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The sub-agent type a forked skill (`context: fork`, phase D spec §6.2) runs as for `parent`:
|
|
45
|
+
* `general-purpose` for no `agent` and Claude's built-in types; else a roster type (a bare name
|
|
46
|
+
* prefers the skill's own plugin's template `<plugin>:<name>`, then {@link findType}). An `agent`
|
|
47
|
+
* that does not resolve falls back to `general-purpose` and is returned as `unknown`. `inRoster`:
|
|
48
|
+
* the type is one the parent's `agent` tool offers (`general-purpose` is not when
|
|
49
|
+
* `subagents.general === false`, which does not block a person's fork invocation).
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveSkillForkType(db: KernelDb, orgId: string, parent: Pick<AgentDefinition, "subagents">, agent: string | undefined, plugin: string | undefined): Promise<{
|
|
52
|
+
agentType: string;
|
|
53
|
+
unknown?: string;
|
|
54
|
+
inRoster: boolean;
|
|
55
|
+
}>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { SUBAGENT_ROSTER_MAX } from "../../agents/agents.service.js";
|
|
2
|
+
import { loadTemplates } from "../../agents/templates.js";
|
|
3
|
+
export const ROSTER_DESCRIPTION_MAX = 1024;
|
|
4
|
+
/** The description of `general-purpose` in the roster (spec §4.3, model-visible). */
|
|
5
|
+
export const GENERAL_PURPOSE_DESCRIPTION = "a copy of you with your tools and skills, for multi-step work.";
|
|
6
|
+
const cut = (s) => s.slice(0, ROSTER_DESCRIPTION_MAX);
|
|
7
|
+
/** Plugin template type: `<plugin>:<name>`. */
|
|
8
|
+
export const templateType = (plugin, name) => `${plugin}:${name}`;
|
|
9
|
+
/**
|
|
10
|
+
* Resolves the roster of `parent` (spec §4.3): `general-purpose` first unless
|
|
11
|
+
* `subagents.general === false`, then the plugin templates, inline templates and allowlisted org
|
|
12
|
+
* agents, each in the owner's order, at most {@link SUBAGENT_ROSTER_MAX} entries. Templates deleted
|
|
13
|
+
* since the save are skipped; allowlisted org agents stay listed (the dispatch checks their gates
|
|
14
|
+
* and refuses with the §4.5 text), with `agentName` only while the agent is live.
|
|
15
|
+
*/
|
|
16
|
+
export async function resolveRoster(db, orgId, parent) {
|
|
17
|
+
const sub = parent.subagents;
|
|
18
|
+
const out = [];
|
|
19
|
+
if (sub?.general !== false) {
|
|
20
|
+
out.push({
|
|
21
|
+
type: "general-purpose",
|
|
22
|
+
source: "general",
|
|
23
|
+
description: GENERAL_PURPOSE_DESCRIPTION,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const templateIds = sub?.templates ?? [];
|
|
27
|
+
const templates = await loadTemplates(db, orgId, templateIds);
|
|
28
|
+
for (const id of templateIds) {
|
|
29
|
+
const r = templates.get(id);
|
|
30
|
+
if (!r)
|
|
31
|
+
continue;
|
|
32
|
+
const description = r.template.description;
|
|
33
|
+
out.push({
|
|
34
|
+
type: templateType(r.plugin, r.name),
|
|
35
|
+
source: "plugin",
|
|
36
|
+
description: cut(typeof description === "string" ? description : ""),
|
|
37
|
+
templateId: r.id,
|
|
38
|
+
plugin: r.plugin,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
for (const t of sub?.inline ?? []) {
|
|
42
|
+
out.push({ type: t.name, source: "inline", description: cut(t.description) });
|
|
43
|
+
}
|
|
44
|
+
const agents = sub?.agents ?? [];
|
|
45
|
+
if (agents.length > 0) {
|
|
46
|
+
const rows = await db
|
|
47
|
+
.selectFrom("agents")
|
|
48
|
+
.innerJoin("agent_versions", (j) => j
|
|
49
|
+
.onRef("agent_versions.agent_id", "=", "agents.id")
|
|
50
|
+
.onRef("agent_versions.version", "=", "agents.current_version"))
|
|
51
|
+
.select(["agents.id", "agent_versions.definition"])
|
|
52
|
+
.where("agents.org_id", "=", orgId)
|
|
53
|
+
.where("agents.deleted_at", "is", null)
|
|
54
|
+
.where("agents.id", "in", agents.map((a) => a.agentId))
|
|
55
|
+
.execute();
|
|
56
|
+
const names = new Map(rows.map((r) => [r.id, r.definition.name]));
|
|
57
|
+
for (const a of agents) {
|
|
58
|
+
const agentName = names.get(a.agentId);
|
|
59
|
+
out.push({
|
|
60
|
+
type: a.as,
|
|
61
|
+
source: "agent",
|
|
62
|
+
description: cut(a.description),
|
|
63
|
+
agentId: a.agentId,
|
|
64
|
+
...(agentName !== undefined && { agentName }),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return out.slice(0, SUBAGENT_ROSTER_MAX);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The roster entry for a requested `subagent_type`: an exact type first; else a bare `<name>`
|
|
72
|
+
* matches the plugin template `<plugin>:<name>` when exactly one has it (as Claude Code accepts
|
|
73
|
+
* `reviewer` for `my-plugin:reviewer`). Null when nothing matches.
|
|
74
|
+
*/
|
|
75
|
+
export function findType(roster, requested) {
|
|
76
|
+
const exact = roster.find((e) => e.type === requested);
|
|
77
|
+
if (exact)
|
|
78
|
+
return exact;
|
|
79
|
+
if (requested.includes(":"))
|
|
80
|
+
return null;
|
|
81
|
+
const bare = roster.filter((e) => e.source === "plugin" && e.type.endsWith(`:${requested}`));
|
|
82
|
+
return bare.length === 1 ? bare[0] : null;
|
|
83
|
+
}
|
|
84
|
+
/** Claude Code's built-in agent types a forked skill may name; they run as `general-purpose`. */
|
|
85
|
+
const GENERAL_ALIASES = new Set(["general-purpose", "Explore", "Plan"]);
|
|
86
|
+
/** A forked skill's `agent` that runs as `general-purpose` by definition (absent ones aside). */
|
|
87
|
+
export const isGeneralAlias = (agent) => GENERAL_ALIASES.has(agent);
|
|
88
|
+
/**
|
|
89
|
+
* The sub-agent type a forked skill (`context: fork`, phase D spec §6.2) runs as for `parent`:
|
|
90
|
+
* `general-purpose` for no `agent` and Claude's built-in types; else a roster type (a bare name
|
|
91
|
+
* prefers the skill's own plugin's template `<plugin>:<name>`, then {@link findType}). An `agent`
|
|
92
|
+
* that does not resolve falls back to `general-purpose` and is returned as `unknown`. `inRoster`:
|
|
93
|
+
* the type is one the parent's `agent` tool offers (`general-purpose` is not when
|
|
94
|
+
* `subagents.general === false`, which does not block a person's fork invocation).
|
|
95
|
+
*/
|
|
96
|
+
export async function resolveSkillForkType(db, orgId, parent, agent, plugin) {
|
|
97
|
+
const roster = await resolveRoster(db, orgId, parent);
|
|
98
|
+
const general = () => ({
|
|
99
|
+
agentType: "general-purpose",
|
|
100
|
+
inRoster: roster.some((e) => e.type === "general-purpose"),
|
|
101
|
+
});
|
|
102
|
+
if (agent === undefined || GENERAL_ALIASES.has(agent))
|
|
103
|
+
return general();
|
|
104
|
+
if (plugin !== undefined && !agent.includes(":")) {
|
|
105
|
+
const own = roster.find((e) => e.type === templateType(plugin, agent));
|
|
106
|
+
if (own)
|
|
107
|
+
return { agentType: own.type, inRoster: true };
|
|
108
|
+
}
|
|
109
|
+
const e = findType(roster, agent);
|
|
110
|
+
return e ? { agentType: e.type, inRoster: true } : { ...general(), unknown: agent };
|
|
111
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { Transaction } from "kysely";
|
|
2
|
+
import type { EventLog } from "../../conversations/event-log.js";
|
|
3
|
+
import type { ConversationEvent, EventPayload } from "../../conversations/events.js";
|
|
4
|
+
import type { KernelDatabase } from "../../db/kernel-schema.js";
|
|
5
|
+
import { ApiError } from "../../errors.js";
|
|
6
|
+
import type { SkillInvoker } from "../../skills/invoke.js";
|
|
7
|
+
import type { LoopContext, WaitingFor } from "../loop.js";
|
|
8
|
+
import { type DispatchDeps } from "./dispatch.js";
|
|
9
|
+
/**
|
|
10
|
+
* Forked skills (phase D spec §6): a person's invocation of a `context: fork` skill starts its own
|
|
11
|
+
* run (the run boundary, {@link forkBoundary}), whose `prepare` node dispatches the sub-agent
|
|
12
|
+
* through phase C's `dispatchSubagent` before any model call and waits on it like an `agent` call
|
|
13
|
+
* (`subagents` wait `sa-<runId>-0`). When the child has ended, `prepare` appends the model-visible
|
|
14
|
+
* `skill_fork_result` and the parent's model answers. Every terminal path of the run (and the wait
|
|
15
|
+
* sweep) pairs a fork invocation without a report ({@link pairStoppedForks}), so the log never holds
|
|
16
|
+
* a fork lead whose report is missing before the next model call.
|
|
17
|
+
*/
|
|
18
|
+
type KernelTrx = Transaction<KernelDatabase>;
|
|
19
|
+
/** The dispatch's parent call id (no `:`; there is no tool call). */
|
|
20
|
+
export declare const skillCallId: (seq: number) => string;
|
|
21
|
+
/** Idempotency key of a fork invocation's report (one per invocation, whatever the run). */
|
|
22
|
+
export declare const forkResultIdemKey: (seq: number) => string;
|
|
23
|
+
/** A fork dispatch's step: before the run's first model step (steps start at 1). */
|
|
24
|
+
export declare const FORK_STEP = 0;
|
|
25
|
+
/** The invocation seq of a fork dispatch row (`skill-<seq>` at step 0), else null. */
|
|
26
|
+
export declare const forkSeqOfCall: (callId: string, step: number) => number | null;
|
|
27
|
+
export type ForkInvocation = ConversationEvent & {
|
|
28
|
+
type: "user_message";
|
|
29
|
+
payload: EventPayload<"user_message"> & {
|
|
30
|
+
skill: NonNullable<EventPayload<"user_message">["skill"]>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/** A person's fork invocation (`user_message.skill.mode === "fork"`). */
|
|
34
|
+
export declare const isForkInvocation: (e: ConversationEvent) => e is ForkInvocation;
|
|
35
|
+
/**
|
|
36
|
+
* The run boundary (spec §6.3): the messages a run absorbs, in order, stopping before any fork
|
|
37
|
+
* invocation other than the run's own trigger message, and right after its own. A fork invocation
|
|
38
|
+
* is therefore only ever absorbed by the run it triggers (`RunQueue.ensureRun` makes the first
|
|
39
|
+
* unconsumed fork invocation a run's trigger), at that run's first step, and is its last message
|
|
40
|
+
* there; messages posted after it (also during the sub-agent wait) come at a later step or in the
|
|
41
|
+
* next run, after the report (batch 3 review C1).
|
|
42
|
+
*/
|
|
43
|
+
export declare function forkBoundary<E extends ConversationEvent>(messages: readonly E[], triggerSeq: number): E[];
|
|
44
|
+
/** The model-visible report text (spec §6.3). */
|
|
45
|
+
export declare const forkReportText: (name: string, body: string) => string;
|
|
46
|
+
/** The report when the run ended before the sub-agent was dispatched. */
|
|
47
|
+
export declare const FORK_NOT_STARTED_TEXT = "The run ended before the sub-agent started; the skill did not run.";
|
|
48
|
+
/** The report when the skill's instructions could not be read at dispatch. */
|
|
49
|
+
export declare const FORK_UNREADABLE_TEXT = "The sub-agent did not start: the skill's instructions could not be read. The user can run the skill again.";
|
|
50
|
+
/** The report when storage was down at dispatch (batch 3 review m5). */
|
|
51
|
+
export declare const FORK_STORAGE_DOWN_TEXT = "The sub-agent did not start: the skill's instructions could not be read right now. The user can try again.";
|
|
52
|
+
/**
|
|
53
|
+
* The report for a task that could not be rendered at dispatch: the version is gone or its
|
|
54
|
+
* SKILL.md unreadable (`skill_unreadable`), or storage was down.
|
|
55
|
+
*/
|
|
56
|
+
export declare const forkRenderFailureText: (e: ApiError) => string;
|
|
57
|
+
/** What `prepare` does with the run's fork invocation. */
|
|
58
|
+
export type SkillForkStep =
|
|
59
|
+
/** The report is in the log: go on to the model step. */
|
|
60
|
+
{
|
|
61
|
+
kind: "ready";
|
|
62
|
+
}
|
|
63
|
+
/** The sub-agent runs: suspend on it. */
|
|
64
|
+
| {
|
|
65
|
+
kind: "suspend";
|
|
66
|
+
waitingFor: WaitingFor;
|
|
67
|
+
}
|
|
68
|
+
/** The run is being stopped: end it; its terminal path writes the report. */
|
|
69
|
+
| {
|
|
70
|
+
kind: "aborted";
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* End the run without a model call (full-run replay of a run whose recording has no report:
|
|
74
|
+
* the original ended before it, so the replay ends there too, as a finished run with no reply).
|
|
75
|
+
*/
|
|
76
|
+
| {
|
|
77
|
+
kind: "end";
|
|
78
|
+
};
|
|
79
|
+
/** The loop's fork handler (`LoopDeps.skillForks`): live dispatch, or the recorded report. */
|
|
80
|
+
export interface SkillForks {
|
|
81
|
+
advance(a: {
|
|
82
|
+
ctx: LoopContext;
|
|
83
|
+
fork: ForkInvocation;
|
|
84
|
+
}): Promise<SkillForkStep>;
|
|
85
|
+
}
|
|
86
|
+
export interface SkillForkDeps extends DispatchDeps {
|
|
87
|
+
invoker: Pick<SkillInvoker, "renderTask">;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* In `prepare`, for the run's fork invocation: dispatch it when it has no dispatch row (rendering
|
|
91
|
+
* the task from the recorded version, `SkillInvoker.renderTask`) and suspend; append the report once
|
|
92
|
+
* the child has ended. Phase C's dispatch transaction applies unchanged: limits, the parent run
|
|
93
|
+
* lock, the starter's credentials, the org agent gates, the stop cascade. A refusal, or a SKILL.md
|
|
94
|
+
* that cannot be read, is reported as the sub-agent's result.
|
|
95
|
+
*/
|
|
96
|
+
export declare function advanceSkillForks(d: SkillForkDeps, a: {
|
|
97
|
+
ctx: LoopContext;
|
|
98
|
+
fork: ForkInvocation;
|
|
99
|
+
}): Promise<SkillForkStep>;
|
|
100
|
+
/** The live handler for the loop (`LoopDeps.skillForks`). */
|
|
101
|
+
export declare const liveSkillForks: (d: SkillForkDeps) => SkillForks;
|
|
102
|
+
/**
|
|
103
|
+
* The full-run replay's handler (spec §7, A5): never dispatches. The recorded report of the
|
|
104
|
+
* original run (`skill_fork_result` with this `invokedSeq`) is appended as it was; without one (the
|
|
105
|
+
* original run ended before its report) the replayed run ends there, before any model call.
|
|
106
|
+
*/
|
|
107
|
+
export declare const recordedSkillForks: (eventLog: Pick<EventLog, "append" | "findByIdem">, recorded: readonly {
|
|
108
|
+
type: string;
|
|
109
|
+
payload: unknown;
|
|
110
|
+
}[]) => SkillForks;
|
|
111
|
+
/**
|
|
112
|
+
* In the transaction `t` of a run's terminal path (or the wait sweep): the run's fork invocation
|
|
113
|
+
* (its trigger message, by the run boundary) without a report gets one now: the ended child's
|
|
114
|
+
* result (and the parent's missing `subagent_finished`), {@link AGENT_STOPPED_WITH_RUN_TEXT} for a
|
|
115
|
+
* child still active (the caller stops it after its commit, as for `agent` calls), or
|
|
116
|
+
* {@link FORK_NOT_STARTED_TEXT} when nothing was dispatched. Returns the call ids written
|
|
117
|
+
* (`skill-<seq>`) and the highest seq; the caller notifies after its commit.
|
|
118
|
+
*/
|
|
119
|
+
export declare function pairStoppedForks(t: KernelTrx, eventLog: EventLog, runId: string): Promise<{
|
|
120
|
+
callIds: string[];
|
|
121
|
+
toSeq: number | null;
|
|
122
|
+
}>;
|
|
123
|
+
export {};
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { ApiError } from "../../errors.js";
|
|
2
|
+
import { AGENT_STOPPED_WITH_RUN_TEXT } from "../../tools/builtins/agent.js";
|
|
3
|
+
import { subagentsWait } from "../../tools/pipeline.js";
|
|
4
|
+
import { TERMINAL_STATUSES } from "../run-finish.js";
|
|
5
|
+
import { childResult, dispatchOfCall, finishedEvent } from "./child.js";
|
|
6
|
+
import { dispatchSubagent } from "./dispatch.js";
|
|
7
|
+
/** The dispatch's parent call id (no `:`; there is no tool call). */
|
|
8
|
+
export const skillCallId = (seq) => `skill-${seq}`;
|
|
9
|
+
/** Idempotency key of a fork invocation's report (one per invocation, whatever the run). */
|
|
10
|
+
export const forkResultIdemKey = (seq) => `skill_fork_result:${seq}`;
|
|
11
|
+
/** A fork dispatch's step: before the run's first model step (steps start at 1). */
|
|
12
|
+
export const FORK_STEP = 0;
|
|
13
|
+
const SKILL_CALL_RE = /^skill-(\d+)$/;
|
|
14
|
+
/** The invocation seq of a fork dispatch row (`skill-<seq>` at step 0), else null. */
|
|
15
|
+
export const forkSeqOfCall = (callId, step) => {
|
|
16
|
+
const m = step === FORK_STEP ? SKILL_CALL_RE.exec(callId) : null;
|
|
17
|
+
return m ? Number(m[1]) : null;
|
|
18
|
+
};
|
|
19
|
+
/** A person's fork invocation (`user_message.skill.mode === "fork"`). */
|
|
20
|
+
export const isForkInvocation = (e) => e.type === "user_message" && e.payload.skill?.mode === "fork";
|
|
21
|
+
/**
|
|
22
|
+
* The run boundary (spec §6.3): the messages a run absorbs, in order, stopping before any fork
|
|
23
|
+
* invocation other than the run's own trigger message, and right after its own. A fork invocation
|
|
24
|
+
* is therefore only ever absorbed by the run it triggers (`RunQueue.ensureRun` makes the first
|
|
25
|
+
* unconsumed fork invocation a run's trigger), at that run's first step, and is its last message
|
|
26
|
+
* there; messages posted after it (also during the sub-agent wait) come at a later step or in the
|
|
27
|
+
* next run, after the report (batch 3 review C1).
|
|
28
|
+
*/
|
|
29
|
+
export function forkBoundary(messages, triggerSeq) {
|
|
30
|
+
const out = [];
|
|
31
|
+
for (const m of messages) {
|
|
32
|
+
if (isForkInvocation(m) && m.seq !== triggerSeq)
|
|
33
|
+
break;
|
|
34
|
+
out.push(m);
|
|
35
|
+
if (isForkInvocation(m))
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
/** The model-visible report text (spec §6.3). */
|
|
41
|
+
export const forkReportText = (name, body) => `Report from the sub-agent that ran the skill "${name}":\n\n${body}`;
|
|
42
|
+
/** The report when the run ended before the sub-agent was dispatched. */
|
|
43
|
+
export const FORK_NOT_STARTED_TEXT = "The run ended before the sub-agent started; the skill did not run.";
|
|
44
|
+
/** The report when the skill's instructions could not be read at dispatch. */
|
|
45
|
+
export const FORK_UNREADABLE_TEXT = "The sub-agent did not start: the skill's instructions could not be read. The user can run the skill again.";
|
|
46
|
+
/** The report when storage was down at dispatch (batch 3 review m5). */
|
|
47
|
+
export const FORK_STORAGE_DOWN_TEXT = "The sub-agent did not start: the skill's instructions could not be read right now. The user can try again.";
|
|
48
|
+
/**
|
|
49
|
+
* The report for a task that could not be rendered at dispatch: the version is gone or its
|
|
50
|
+
* SKILL.md unreadable (`skill_unreadable`), or storage was down.
|
|
51
|
+
*/
|
|
52
|
+
export const forkRenderFailureText = (e) => e.details?.some((d) => d?.reason === "skill_unreadable")
|
|
53
|
+
? FORK_UNREADABLE_TEXT
|
|
54
|
+
: FORK_STORAGE_DOWN_TEXT;
|
|
55
|
+
const reportEvent = (runId, seq, text, row) => ({
|
|
56
|
+
type: "skill_fork_result",
|
|
57
|
+
runId,
|
|
58
|
+
idemKey: forkResultIdemKey(seq),
|
|
59
|
+
payload: {
|
|
60
|
+
invokedSeq: seq,
|
|
61
|
+
...(row !== undefined && { subagentId: row.childConversationId, childRunId: row.childRunId }),
|
|
62
|
+
text,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* In `prepare`, for the run's fork invocation: dispatch it when it has no dispatch row (rendering
|
|
67
|
+
* the task from the recorded version, `SkillInvoker.renderTask`) and suspend; append the report once
|
|
68
|
+
* the child has ended. Phase C's dispatch transaction applies unchanged: limits, the parent run
|
|
69
|
+
* lock, the starter's credentials, the org agent gates, the stop cascade. A refusal, or a SKILL.md
|
|
70
|
+
* that cannot be read, is reported as the sub-agent's result.
|
|
71
|
+
*/
|
|
72
|
+
export async function advanceSkillForks(d, a) {
|
|
73
|
+
const { ctx, fork } = a;
|
|
74
|
+
const seq = fork.seq;
|
|
75
|
+
const skill = fork.payload.skill;
|
|
76
|
+
const ready = { kind: "ready" };
|
|
77
|
+
if (await d.eventLog.findByIdem(ctx.conversationId, forkResultIdemKey(seq)))
|
|
78
|
+
return ready;
|
|
79
|
+
const report = (text, row, extra = []) => d.eventLog.append(ctx.conversationId, [
|
|
80
|
+
...extra,
|
|
81
|
+
reportEvent(ctx.runId, seq, forkReportText(skill.name, text), row),
|
|
82
|
+
]);
|
|
83
|
+
const callId = skillCallId(seq);
|
|
84
|
+
const row = await dispatchOfCall(d.db, ctx.runId, callId);
|
|
85
|
+
if (row) {
|
|
86
|
+
const r = await childResult(d.eventLog, row, { forSkill: true });
|
|
87
|
+
if (!r)
|
|
88
|
+
return ctx.signal.aborted ? { kind: "aborted" } : suspend(d, ctx);
|
|
89
|
+
await report(r.content, row, [finishedEvent(row, r.finished)]);
|
|
90
|
+
return ready;
|
|
91
|
+
}
|
|
92
|
+
if (ctx.signal.aborted)
|
|
93
|
+
return { kind: "aborted" };
|
|
94
|
+
let rendered;
|
|
95
|
+
try {
|
|
96
|
+
rendered = await d.invoker.renderTask({
|
|
97
|
+
orgId: ctx.orgId,
|
|
98
|
+
conversationId: ctx.conversationId,
|
|
99
|
+
skill,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
if (!(e instanceof ApiError))
|
|
104
|
+
throw e;
|
|
105
|
+
await report(forkRenderFailureText(e));
|
|
106
|
+
return ready;
|
|
107
|
+
}
|
|
108
|
+
const out = await dispatchSubagent(d, {
|
|
109
|
+
ctx: {
|
|
110
|
+
orgId: ctx.orgId,
|
|
111
|
+
conversationId: ctx.conversationId,
|
|
112
|
+
runId: ctx.runId,
|
|
113
|
+
step: FORK_STEP,
|
|
114
|
+
agentId: ctx.agentId,
|
|
115
|
+
agentVersion: ctx.agentVersion,
|
|
116
|
+
agent: ctx.agent,
|
|
117
|
+
accountId: ctx.triggerAccountId,
|
|
118
|
+
signal: ctx.signal,
|
|
119
|
+
deadline: ctx.limits.deadline,
|
|
120
|
+
...(ctx.conversationKind !== undefined &&
|
|
121
|
+
ctx.conversationKind !== "eval" && { conversationKind: ctx.conversationKind }),
|
|
122
|
+
},
|
|
123
|
+
callId,
|
|
124
|
+
input: {
|
|
125
|
+
description: skill.name.slice(0, 80),
|
|
126
|
+
// the task message renders `forSkill.task` for the sub-agent's definition
|
|
127
|
+
prompt: rendered.task(ctx.agent),
|
|
128
|
+
subagent_type: skill.agentType ?? "general-purpose",
|
|
129
|
+
},
|
|
130
|
+
forSkill: {
|
|
131
|
+
seq,
|
|
132
|
+
skill,
|
|
133
|
+
warnings: rendered.warning === undefined ? [] : [rendered.warning],
|
|
134
|
+
task: rendered.task,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
if (out.kind === "refused") {
|
|
138
|
+
// a refusal because the run is being stopped: its terminal path reports
|
|
139
|
+
if (ctx.signal.aborted)
|
|
140
|
+
return { kind: "aborted" };
|
|
141
|
+
await report(out.content);
|
|
142
|
+
return ready;
|
|
143
|
+
}
|
|
144
|
+
// a stop that arrived meanwhile never suspends on the sub-agent (phase C's rule for agent calls)
|
|
145
|
+
return ctx.signal.aborted ? { kind: "aborted" } : suspend(d, ctx);
|
|
146
|
+
}
|
|
147
|
+
const suspend = (d, ctx) => ({
|
|
148
|
+
kind: "suspend",
|
|
149
|
+
waitingFor: subagentsWait(ctx.runId, FORK_STEP, d.config()),
|
|
150
|
+
});
|
|
151
|
+
/** The live handler for the loop (`LoopDeps.skillForks`). */
|
|
152
|
+
export const liveSkillForks = (d) => ({
|
|
153
|
+
advance: (a) => advanceSkillForks(d, a),
|
|
154
|
+
});
|
|
155
|
+
/**
|
|
156
|
+
* The full-run replay's handler (spec §7, A5): never dispatches. The recorded report of the
|
|
157
|
+
* original run (`skill_fork_result` with this `invokedSeq`) is appended as it was; without one (the
|
|
158
|
+
* original run ended before its report) the replayed run ends there, before any model call.
|
|
159
|
+
*/
|
|
160
|
+
export const recordedSkillForks = (eventLog, recorded) => ({
|
|
161
|
+
async advance({ ctx, fork }) {
|
|
162
|
+
if (await eventLog.findByIdem(ctx.conversationId, forkResultIdemKey(fork.seq))) {
|
|
163
|
+
return { kind: "ready" };
|
|
164
|
+
}
|
|
165
|
+
const r = recorded.find((e) => e.type === "skill_fork_result" &&
|
|
166
|
+
e.payload.invokedSeq === fork.seq);
|
|
167
|
+
if (!r)
|
|
168
|
+
return { kind: "end" };
|
|
169
|
+
await eventLog.append(ctx.conversationId, [
|
|
170
|
+
{
|
|
171
|
+
type: "skill_fork_result",
|
|
172
|
+
runId: ctx.runId,
|
|
173
|
+
idemKey: forkResultIdemKey(fork.seq),
|
|
174
|
+
payload: r.payload,
|
|
175
|
+
},
|
|
176
|
+
]);
|
|
177
|
+
return { kind: "ready" };
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
/**
|
|
181
|
+
* In the transaction `t` of a run's terminal path (or the wait sweep): the run's fork invocation
|
|
182
|
+
* (its trigger message, by the run boundary) without a report gets one now: the ended child's
|
|
183
|
+
* result (and the parent's missing `subagent_finished`), {@link AGENT_STOPPED_WITH_RUN_TEXT} for a
|
|
184
|
+
* child still active (the caller stops it after its commit, as for `agent` calls), or
|
|
185
|
+
* {@link FORK_NOT_STARTED_TEXT} when nothing was dispatched. Returns the call ids written
|
|
186
|
+
* (`skill-<seq>`) and the highest seq; the caller notifies after its commit.
|
|
187
|
+
*/
|
|
188
|
+
export async function pairStoppedForks(t, eventLog, runId) {
|
|
189
|
+
const none = { callIds: [], toSeq: null };
|
|
190
|
+
const run = await t
|
|
191
|
+
.selectFrom("runs as r")
|
|
192
|
+
.innerJoin("conversations as c", "c.id", "r.conversation_id")
|
|
193
|
+
.select(["r.conversation_id", "r.trigger_seq", "c.kind"])
|
|
194
|
+
.where("r.id", "=", runId)
|
|
195
|
+
.executeTakeFirst();
|
|
196
|
+
if (run?.kind !== "chat")
|
|
197
|
+
return none;
|
|
198
|
+
const conversationId = run.conversation_id;
|
|
199
|
+
const seq = Number(run.trigger_seq);
|
|
200
|
+
const trigger = await t
|
|
201
|
+
.selectFrom("conversation_events")
|
|
202
|
+
.select(["type", "payload"])
|
|
203
|
+
.where("conversation_id", "=", conversationId)
|
|
204
|
+
.where("seq", "=", run.trigger_seq)
|
|
205
|
+
.executeTakeFirst();
|
|
206
|
+
const skill = trigger?.type === "user_message"
|
|
207
|
+
? trigger.payload.skill
|
|
208
|
+
: undefined;
|
|
209
|
+
if (skill?.mode !== "fork")
|
|
210
|
+
return none;
|
|
211
|
+
const written = await t
|
|
212
|
+
.selectFrom("conversation_events")
|
|
213
|
+
.select("seq")
|
|
214
|
+
.where("conversation_id", "=", conversationId)
|
|
215
|
+
.where("idem_key", "=", forkResultIdemKey(seq))
|
|
216
|
+
.executeTakeFirst();
|
|
217
|
+
if (written)
|
|
218
|
+
return none;
|
|
219
|
+
const callId = skillCallId(seq);
|
|
220
|
+
const d = await t
|
|
221
|
+
.selectFrom("subagent_dispatches")
|
|
222
|
+
.select([
|
|
223
|
+
"parent_run_id",
|
|
224
|
+
"parent_call_id",
|
|
225
|
+
"parent_conversation_id",
|
|
226
|
+
"child_conversation_id",
|
|
227
|
+
"child_run_id",
|
|
228
|
+
])
|
|
229
|
+
.where("parent_run_id", "=", runId)
|
|
230
|
+
.where("parent_call_id", "=", callId)
|
|
231
|
+
.executeTakeFirst();
|
|
232
|
+
const events = [];
|
|
233
|
+
if (!d) {
|
|
234
|
+
events.push(reportEvent(runId, seq, forkReportText(skill.name, FORK_NOT_STARTED_TEXT)));
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
const row = {
|
|
238
|
+
parentRunId: d.parent_run_id,
|
|
239
|
+
parentCallId: d.parent_call_id,
|
|
240
|
+
parentConversationId: d.parent_conversation_id,
|
|
241
|
+
childConversationId: d.child_conversation_id,
|
|
242
|
+
childRunId: d.child_run_id,
|
|
243
|
+
};
|
|
244
|
+
const child = await t
|
|
245
|
+
.selectFrom("runs")
|
|
246
|
+
.select("status")
|
|
247
|
+
.where("id", "=", row.childRunId)
|
|
248
|
+
.executeTakeFirst();
|
|
249
|
+
// a child that already ended keeps its own result (its log is committed)
|
|
250
|
+
const ended = child !== undefined && TERMINAL_STATUSES.has(child.status)
|
|
251
|
+
? await childResult(eventLog, row, { forSkill: true })
|
|
252
|
+
: null;
|
|
253
|
+
if (ended)
|
|
254
|
+
events.push(finishedEvent(row, ended.finished));
|
|
255
|
+
events.push(reportEvent(runId, seq, forkReportText(skill.name, ended ? ended.content : AGENT_STOPPED_WITH_RUN_TEXT), row));
|
|
256
|
+
}
|
|
257
|
+
const out = await eventLog.append(conversationId, events, t);
|
|
258
|
+
return { callIds: [callId], toSeq: Math.max(...out.map((e) => e.seq)) };
|
|
259
|
+
}
|