@capybara-hq/kernel 0.0.0-stage → 0.1.0-rc.0
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 +22 -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 +1125 -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 +223 -0
- package/dist/config/schema.js +1151 -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 +422 -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 +150 -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 +210 -0
- package/dist/errors.js +212 -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 +789 -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 +149 -0
- package/dist/extensions/bootstrap.js +441 -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 +170 -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 +67 -0
- package/dist/index.js +65 -0
- package/dist/kernel.d.ts +256 -0
- package/dist/kernel.js +1326 -0
- package/dist/log.d.ts +48 -0
- package/dist/log.js +229 -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 +271 -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 +147 -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 +805 -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 +550 -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 +114 -0
- package/dist/tools/builtins/sandbox/common.js +304 -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 +67 -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,446 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { parseSkillMd, SKILL_ENTRY_FILE, SKILLS_SANDBOX_ROOT, skillSandboxPath, ToolError, } from "@capybara-hq/plugin-sdk";
|
|
3
|
+
import { sql } from "kysely";
|
|
4
|
+
import { normalizeStoredDefinition } from "../../agents/definition.js";
|
|
5
|
+
import { ApiError } from "../../errors.js";
|
|
6
|
+
import { latestInvocation } from "../../runtime/context/skills.js";
|
|
7
|
+
import { dispatchOfChildRun } from "../../runtime/subagents/child.js";
|
|
8
|
+
import { resolveSkillForkType } from "../../runtime/subagents/roster.js";
|
|
9
|
+
import { invocationOf, resolveSkills } from "../../skills/catalog.js";
|
|
10
|
+
import { clip, display, inSandbox, sandboxBaseTimeoutMs, withNotices, withPathLease, } from "./sandbox/common.js";
|
|
11
|
+
import { SANDBOX_TOOL_NAMES } from "./sandbox/names.js";
|
|
12
|
+
/**
|
|
13
|
+
* 内置工具 `skill_load`(M5 T14,Ruling M17):按日志里最新一份技能目录快照把名字解析为 id 与版本,返回该版本
|
|
14
|
+
* SKILL.md 的正文与文件清单(结果里写明版本)。技能带其他文件时把整个技能复制进本对话沙箱的 `/skills/<name>/`
|
|
15
|
+
* (提供方以 root 写,命令用户只读);没有沙箱提供方时只给正文,并说明脚本不可用。
|
|
16
|
+
*
|
|
17
|
+
* - 存储里读出的每个文件都按清单的 sha256 核对,不符即拒绝(不把被替换的内容给模型或放进沙箱)。
|
|
18
|
+
* - 复制记录在内核控制的标记文件(每个技能一个,{@link skillMarkerPath}:`/skills/.capybara/<name>.json`,
|
|
19
|
+
* 命令用户改不了):`{ id, version, prefix, files, stale }`。新建 / 重建的沙箱、版本或来源前缀变化、同名换了技能时
|
|
20
|
+
* 重新复制,否则跳过。
|
|
21
|
+
* - agent 没有任何沙箱工具时不创建沙箱、不复制(模型也跑不了脚本),只给正文并说明。
|
|
22
|
+
* - 可执行位:提供方写的文件一律不可执行(0644)。不扩展 `sandbox@1` 的 `writeFile`,而是在结果里告诉模型用解释器
|
|
23
|
+
* 运行(`sh` / `python3` / `node`):契约与两个提供方不变,技能包里的 shebang 脚本照样能跑,代价只是不能 `./x`。
|
|
24
|
+
* - 旧版本多出的文件:`sandbox@1` 没有删除原语,命令用户也删不了 `/skills` 下的文件,所以新版本原地覆盖,
|
|
25
|
+
* 旧版本独有的文件留在原处、记进标记的 `stale`,每次加载都在结果里列出「不属于当前版本、忽略它们」。
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* 已复制进沙箱的技能的标记目录(内核控制:`/skills` 只有提供方以 root 能写;技能名不以 `.` 开头,不会撞名)。
|
|
29
|
+
*/
|
|
30
|
+
export const SKILLS_MARKER_DIR = `${SKILLS_SANDBOX_ROOT}/.capybara`;
|
|
31
|
+
/** 一个技能的标记文件。 */
|
|
32
|
+
export const skillMarkerPath = (name) => `${SKILLS_MARKER_DIR}/${name}.json`;
|
|
33
|
+
const MARKER_MAX_BYTES = 256 * 1024;
|
|
34
|
+
/** 结果里最多列出的文件数(其余只给数量)。 */
|
|
35
|
+
const MAX_LISTED_FILES = 200;
|
|
36
|
+
/** 「不在目录里」的错误里最多列出的技能名。 */
|
|
37
|
+
const MAX_LISTED_NAMES = 50;
|
|
38
|
+
const SPEC = {
|
|
39
|
+
name: "skill_load",
|
|
40
|
+
// Display only (the tool row; not in the fingerprint, never sent to the model).
|
|
41
|
+
keyArgs: ["name"],
|
|
42
|
+
description: "Load a skill from the skills list: returns the skill's instructions " +
|
|
43
|
+
"(its SKILL.md) and the list of its files. Call it before starting a task that matches a " +
|
|
44
|
+
"skill's description, then follow the returned instructions. If the skill has scripts or other " +
|
|
45
|
+
"files, they are copied read-only to /skills/<name>/ in this conversation's sandbox; run scripts " +
|
|
46
|
+
"there with an interpreter (sh, python3, node). Call it again when the skills list changes or " +
|
|
47
|
+
"the sandbox was recreated. Do not use it for skills that are not in the list.",
|
|
48
|
+
inputSchema: {
|
|
49
|
+
type: "object",
|
|
50
|
+
properties: {
|
|
51
|
+
name: {
|
|
52
|
+
type: "string",
|
|
53
|
+
minLength: 1,
|
|
54
|
+
maxLength: 64,
|
|
55
|
+
description: 'The skill name exactly as listed, e.g. "pdf-report".',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
required: ["name"],
|
|
59
|
+
additionalProperties: false,
|
|
60
|
+
},
|
|
61
|
+
annotations: { readOnlyHint: true },
|
|
62
|
+
};
|
|
63
|
+
// ---- 模型可见文案(英文) ----
|
|
64
|
+
const NO_SKILLS_TEXT = "No skills are available in this conversation; do the task without a skill, or ask the user to add one to this agent.";
|
|
65
|
+
const STORAGE_UNAVAILABLE_TEXT = "File storage is temporarily unavailable, so the skill's files cannot be read; retry later.";
|
|
66
|
+
const notInCatalog = (name, skills) => {
|
|
67
|
+
const names = skills.slice(0, MAX_LISTED_NAMES).map((s) => s.name);
|
|
68
|
+
const more = skills.length > names.length ? ", …" : "";
|
|
69
|
+
return `Skill "${clip(name, 80)}" is not in the skills catalog for this conversation; call skill_load with one of the listed names: ${names.join(", ")}${more}.`;
|
|
70
|
+
};
|
|
71
|
+
const removedText = (name) => `Skill "${name}" was removed after the skills list was shown and can no longer be loaded; do the task without it, or ask the user to restore it.`;
|
|
72
|
+
/** Phase D spec §4.4: the line before a forked skill's instructions (model-visible, English). */
|
|
73
|
+
const forkAvailableText = (type) => `This skill is written to run in a sub-agent: call agent with subagent_type "${type}" and a prompt containing these instructions and the details of the task, then use its report; do not follow the instructions yourself.`;
|
|
74
|
+
const FORK_UNAVAILABLE_TEXT = "This skill is written to run in a sub-agent, which is not available here; follow the instructions yourself.";
|
|
75
|
+
const integrityText = (name) => `Skill "${name}" failed an integrity check (its stored files do not match the uploaded package); ask an administrator to upload the skill again.`;
|
|
76
|
+
const strings = (v) => Array.isArray(v) ? v.filter((x) => typeof x === "string") : [];
|
|
77
|
+
/** 解析一个技能的标记文件;坏的按没有处理(重新复制)。 */
|
|
78
|
+
function parseMarker(data) {
|
|
79
|
+
try {
|
|
80
|
+
const r = JSON.parse(new TextDecoder().decode(data));
|
|
81
|
+
if (r === null || typeof r !== "object" || Array.isArray(r))
|
|
82
|
+
return undefined;
|
|
83
|
+
const e = r;
|
|
84
|
+
if (typeof e.id !== "string" || typeof e.version !== "number")
|
|
85
|
+
return undefined;
|
|
86
|
+
return {
|
|
87
|
+
id: e.id,
|
|
88
|
+
version: e.version,
|
|
89
|
+
...(typeof e.prefix === "string" && { prefix: e.prefix }),
|
|
90
|
+
files: strings(e.files),
|
|
91
|
+
stale: strings(e.stale),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** 存储错误 → 给模型的说明(存储不可用可重试);其余原样抛出。 */
|
|
99
|
+
function storageError(e) {
|
|
100
|
+
if (e instanceof ApiError && e.code === "storage.unavailable") {
|
|
101
|
+
return new ToolError(STORAGE_UNAVAILABLE_TEXT);
|
|
102
|
+
}
|
|
103
|
+
return e;
|
|
104
|
+
}
|
|
105
|
+
/** A stored skill file is missing or does not match its manifest entry (size, sha256). */
|
|
106
|
+
export class SkillIntegrityError extends Error {
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Reads one skill file and checks it against its manifest entry (size and sha256). A missing or
|
|
110
|
+
* mismatching object throws {@link SkillIntegrityError}; a storage error is rethrown as is
|
|
111
|
+
* (`storage.unavailable` from the store). Shared with a person's skill invocation (phase D).
|
|
112
|
+
*/
|
|
113
|
+
export async function readSkillFile(store, key, file, signal) {
|
|
114
|
+
const got = await store.get(key, signal && { signal });
|
|
115
|
+
if (!got)
|
|
116
|
+
throw new SkillIntegrityError(`${key} is missing`);
|
|
117
|
+
const hash = createHash("sha256");
|
|
118
|
+
const chunks = [];
|
|
119
|
+
let n = 0;
|
|
120
|
+
const reader = got.body.getReader();
|
|
121
|
+
try {
|
|
122
|
+
for (;;) {
|
|
123
|
+
const { done, value } = await reader.read();
|
|
124
|
+
if (done)
|
|
125
|
+
break;
|
|
126
|
+
n += value.byteLength;
|
|
127
|
+
if (n > file.size)
|
|
128
|
+
throw new SkillIntegrityError(`${key} is larger than its manifest says`);
|
|
129
|
+
hash.update(value);
|
|
130
|
+
chunks.push(value);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
await reader.cancel().catch(() => { });
|
|
135
|
+
}
|
|
136
|
+
if (n !== file.size || hash.digest("hex") !== file.sha256) {
|
|
137
|
+
throw new SkillIntegrityError(`${key} does not match its manifest`);
|
|
138
|
+
}
|
|
139
|
+
return new Uint8Array(Buffer.concat(chunks));
|
|
140
|
+
}
|
|
141
|
+
/** {@link readSkillFile} for the model: integrity and storage failures become tool errors. */
|
|
142
|
+
async function readVerified(store, key, file, skill, signal) {
|
|
143
|
+
try {
|
|
144
|
+
return await readSkillFile(store, key, file, signal);
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
if (e instanceof SkillIntegrityError)
|
|
148
|
+
throw new ToolError(integrityText(skill));
|
|
149
|
+
throw storageError(e);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 把技能整个复制到 `/skills/<name>/`(标记命中则跳过)。每个文件按清单核对后写入,全部写完才更新标记:
|
|
154
|
+
* 中途失败下次整体重来。返回旧版本留下的文件。
|
|
155
|
+
*/
|
|
156
|
+
async function copySkill(s, v) {
|
|
157
|
+
const { name, id, version } = v.entry;
|
|
158
|
+
const markerPath = skillMarkerPath(name);
|
|
159
|
+
let cur;
|
|
160
|
+
if (!s.reset) {
|
|
161
|
+
const m = await s.p.readFile(s.h, markerPath, { maxBytes: MARKER_MAX_BYTES, signal: s.signal });
|
|
162
|
+
if (m && !m.truncated)
|
|
163
|
+
cur = parseMarker(m.data);
|
|
164
|
+
}
|
|
165
|
+
if (cur && cur.id === id && cur.version === version && cur.prefix === v.prefix) {
|
|
166
|
+
return { stale: cur.stale };
|
|
167
|
+
}
|
|
168
|
+
for (const f of v.manifest.files) {
|
|
169
|
+
const data = f.path === SKILL_ENTRY_FILE
|
|
170
|
+
? v.entryBytes
|
|
171
|
+
: await readVerified(v.store, `${v.prefix}${f.path}`, f, name, s.signal);
|
|
172
|
+
await s.p.writeFile(s.h, skillSandboxPath(name, f.path), data, s.signal);
|
|
173
|
+
}
|
|
174
|
+
const files = v.manifest.files.map((f) => f.path);
|
|
175
|
+
const now = new Set(files);
|
|
176
|
+
const stale = cur ? [...new Set([...cur.stale, ...cur.files])].filter((p) => !now.has(p)) : [];
|
|
177
|
+
stale.sort();
|
|
178
|
+
const entry = { id, version, prefix: v.prefix, files, stale };
|
|
179
|
+
await s.p.writeFile(s.h, markerPath, new TextEncoder().encode(JSON.stringify(entry)), s.signal);
|
|
180
|
+
return { stale };
|
|
181
|
+
}
|
|
182
|
+
/** 本步可用的工具里是否有沙箱工具(没有时模型用不了复制进去的文件)。 */
|
|
183
|
+
const hasSandboxTools = (ctx) => (ctx.tools ?? []).some((t) => t.source.kind === "builtin" &&
|
|
184
|
+
SANDBOX_TOOL_NAMES.includes(t.source.name));
|
|
185
|
+
/** 文件清单(最多 {@link MAX_LISTED_FILES} 行)。 */
|
|
186
|
+
function fileList(files) {
|
|
187
|
+
const shown = files.slice(0, MAX_LISTED_FILES).map((f) => `- ${f.path} (${f.size} bytes)`);
|
|
188
|
+
if (files.length > shown.length)
|
|
189
|
+
shown.push(`- … and ${files.length - shown.length} more files`);
|
|
190
|
+
return shown.join("\n");
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* 目录条目对应的内容,按条目的 `source`(对象前缀,T15)精确解析:先找该技能前缀相同的已生成版本(技能未删除;
|
|
194
|
+
* 批准时草稿前缀原样成为版本前缀,版本号变了也能找到),再找本对话发起、仍待批准、前缀相同的技能改动(试用草稿:
|
|
195
|
+
* 没有 `skill_versions` 行,新技能连 `skills` 行都没有)。绝不按版本号解析——被拒绝的草稿与之后别人批准的同号版本
|
|
196
|
+
* 内容不同。都没有 → undefined(已移除)。
|
|
197
|
+
*/
|
|
198
|
+
export async function findSkillVersion(db, ctx, entry) {
|
|
199
|
+
const row = await db
|
|
200
|
+
.selectFrom("skills")
|
|
201
|
+
.innerJoin("skill_versions", "skill_versions.skill_id", "skills.id")
|
|
202
|
+
.select(["skills.deleted_at", "skill_versions.manifest", "skill_versions.object_prefix"])
|
|
203
|
+
.where("skills.id", "=", entry.id)
|
|
204
|
+
.where("skills.org_id", "=", ctx.orgId)
|
|
205
|
+
.where("skill_versions.object_prefix", "=", entry.source)
|
|
206
|
+
.executeTakeFirst();
|
|
207
|
+
if (row)
|
|
208
|
+
return row.deleted_at === null ? row : undefined;
|
|
209
|
+
const draft = await db
|
|
210
|
+
.selectFrom("skill_change_requests")
|
|
211
|
+
.select(["proposed_version", "object_prefix"])
|
|
212
|
+
.where("org_id", "=", ctx.orgId)
|
|
213
|
+
.where("requested_in_conversation", "=", ctx.conversationId)
|
|
214
|
+
.where("status", "=", "pending")
|
|
215
|
+
.where("object_prefix", "=", entry.source)
|
|
216
|
+
.where(sql `proposed_version ->> 'skillId'`, "=", entry.id)
|
|
217
|
+
.executeTakeFirst();
|
|
218
|
+
if (!draft)
|
|
219
|
+
return undefined;
|
|
220
|
+
return { manifest: draft.proposed_version.manifest, object_prefix: draft.object_prefix };
|
|
221
|
+
}
|
|
222
|
+
/** A Claude Code style qualified name `<plugin>:<skill>` (phase B, spec §9.3). */
|
|
223
|
+
const QUALIFIED_NAME_RE = /^([a-z0-9][a-z0-9-]{0,63}):(.+)$/;
|
|
224
|
+
/**
|
|
225
|
+
* The catalog entry for `name`: the skill with exactly that name; else, for `<plugin>:<skill>`,
|
|
226
|
+
* the skill named `<skill>` whose `plugin` (recorded in the snapshot) is `<plugin>`.
|
|
227
|
+
*/
|
|
228
|
+
function findEntry(skills, name) {
|
|
229
|
+
const exact = skills.find((s) => s.name === name);
|
|
230
|
+
if (exact)
|
|
231
|
+
return exact;
|
|
232
|
+
const m = QUALIFIED_NAME_RE.exec(name);
|
|
233
|
+
if (!m)
|
|
234
|
+
return undefined;
|
|
235
|
+
return skills.find((s) => s.name === m[2] && s.plugin !== undefined && s.plugin === m[1]);
|
|
236
|
+
}
|
|
237
|
+
/** The definition of the agent version this run uses; undefined without a run. */
|
|
238
|
+
async function runAgent(db, ctx) {
|
|
239
|
+
if (ctx.runId === undefined)
|
|
240
|
+
return undefined;
|
|
241
|
+
const row = await db
|
|
242
|
+
.selectFrom("runs")
|
|
243
|
+
.innerJoin("conversations", "conversations.id", "runs.conversation_id")
|
|
244
|
+
.innerJoin("agent_versions", (j) => j
|
|
245
|
+
.onRef("agent_versions.agent_id", "=", "conversations.agent_id")
|
|
246
|
+
.onRef("agent_versions.version", "=", "runs.agent_version"))
|
|
247
|
+
.select(["conversations.agent_id", "agent_versions.definition"])
|
|
248
|
+
.where("runs.id", "=", ctx.runId)
|
|
249
|
+
.where("conversations.org_id", "=", ctx.orgId)
|
|
250
|
+
.executeTakeFirst();
|
|
251
|
+
return row
|
|
252
|
+
? { agentId: row.agent_id, definition: normalizeStoredDefinition(row.definition) }
|
|
253
|
+
: undefined;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Where an invoked skill's effectiveness is checked: the conversation, agent and agent version of
|
|
257
|
+
* the person's invocation. In a sub-agent's run (a fork's child: its task message carries the
|
|
258
|
+
* record the kernel wrote at dispatch) that is the PARENT: its conversation, its agent and the
|
|
259
|
+
* parent run's agent version, so an org-agent child or a trial draft of the parent conversation
|
|
260
|
+
* resolves as the parent did (final review I1). Undefined without a run.
|
|
261
|
+
*/
|
|
262
|
+
async function invocationScope(db, ctx) {
|
|
263
|
+
if (ctx.runId === undefined)
|
|
264
|
+
return undefined;
|
|
265
|
+
const dispatch = await dispatchOfChildRun(db, ctx.runId);
|
|
266
|
+
if (!dispatch) {
|
|
267
|
+
const agent = await runAgent(db, ctx);
|
|
268
|
+
return agent && { ...agent, conversationId: ctx.conversationId };
|
|
269
|
+
}
|
|
270
|
+
const row = await db
|
|
271
|
+
.selectFrom("runs")
|
|
272
|
+
.innerJoin("conversations", "conversations.id", "runs.conversation_id")
|
|
273
|
+
.innerJoin("agent_versions", (j) => j
|
|
274
|
+
.onRef("agent_versions.agent_id", "=", "conversations.agent_id")
|
|
275
|
+
.onRef("agent_versions.version", "=", "runs.agent_version"))
|
|
276
|
+
.select(["conversations.agent_id", "agent_versions.definition"])
|
|
277
|
+
.where("runs.id", "=", dispatch.parentRunId)
|
|
278
|
+
.where("conversations.id", "=", dispatch.parentConversationId)
|
|
279
|
+
.where("conversations.org_id", "=", ctx.orgId)
|
|
280
|
+
.executeTakeFirst();
|
|
281
|
+
return row
|
|
282
|
+
? {
|
|
283
|
+
agentId: row.agent_id,
|
|
284
|
+
definition: normalizeStoredDefinition(row.definition),
|
|
285
|
+
conversationId: dispatch.parentConversationId,
|
|
286
|
+
}
|
|
287
|
+
: undefined;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Phase D spec §4.4: a name that is not in the snapshot may be a skill a person invoked in this
|
|
291
|
+
* conversation (a manual-only one never is in the catalog). Resolved from the latest
|
|
292
|
+
* `user_message.skill` with that name, then checked against the effective skills of the
|
|
293
|
+
* invocation's scope now ({@link invocationScope}: the parent's for a fork's sub-agent): the same
|
|
294
|
+
* id and name must still be one (deleted, deselected or replaced by another skill of the same
|
|
295
|
+
* name → `removed`). `conversationId` is the scope's (a trial draft is found there). Undefined
|
|
296
|
+
* when nobody invoked it here (A4: the caller says "not in the catalog").
|
|
297
|
+
*/
|
|
298
|
+
async function invokedEntry(db, ctx, name) {
|
|
299
|
+
// only the `skill` field: a message's content holds the rendered skill (up to 200k characters)
|
|
300
|
+
const rows = await db
|
|
301
|
+
.selectFrom("conversation_events")
|
|
302
|
+
.select(["seq", sql `payload -> 'skill'`.as("skill")])
|
|
303
|
+
.where("conversation_id", "=", ctx.conversationId)
|
|
304
|
+
.where("type", "=", "user_message")
|
|
305
|
+
.where(sql `payload -> 'skill' IS NOT NULL`)
|
|
306
|
+
.orderBy("seq")
|
|
307
|
+
.execute();
|
|
308
|
+
const invoked = latestInvocation(rows.map((r) => ({ type: "user_message", seq: Number(r.seq), payload: { skill: r.skill } })), name);
|
|
309
|
+
if (!invoked)
|
|
310
|
+
return undefined;
|
|
311
|
+
const scope = await invocationScope(db, ctx);
|
|
312
|
+
if (!scope)
|
|
313
|
+
return "removed";
|
|
314
|
+
const effective = await resolveSkills(db, {
|
|
315
|
+
orgId: ctx.orgId,
|
|
316
|
+
agentId: scope.agentId,
|
|
317
|
+
agent: scope.definition,
|
|
318
|
+
conversationId: scope.conversationId,
|
|
319
|
+
});
|
|
320
|
+
if (!effective.some((r) => r.skill.id === invoked.id && r.skill.name === invoked.name)) {
|
|
321
|
+
return "removed";
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
entry: {
|
|
325
|
+
id: invoked.id,
|
|
326
|
+
name: invoked.name,
|
|
327
|
+
description: "",
|
|
328
|
+
version: invoked.version,
|
|
329
|
+
source: invoked.source,
|
|
330
|
+
...(invoked.plugin !== undefined && { plugin: invoked.plugin }),
|
|
331
|
+
},
|
|
332
|
+
conversationId: scope.conversationId,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* The line before a forked skill's instructions (spec §4.4): run it through `agent` when this step
|
|
337
|
+
* offers the tool and the skill's type is in the agent's roster, else follow it yourself.
|
|
338
|
+
*/
|
|
339
|
+
async function forkLine(db, ctx, fork, plugin) {
|
|
340
|
+
const hasAgent = (ctx.tools ?? []).some((t) => t.source.kind === "builtin" && t.source.name === "agent");
|
|
341
|
+
if (!hasAgent)
|
|
342
|
+
return FORK_UNAVAILABLE_TEXT;
|
|
343
|
+
const agent = await runAgent(db, ctx);
|
|
344
|
+
if (!agent)
|
|
345
|
+
return FORK_UNAVAILABLE_TEXT;
|
|
346
|
+
const type = await resolveSkillForkType(db, ctx.orgId, agent.definition, fork.agent, plugin);
|
|
347
|
+
return type.inRoster ? forkAvailableText(type.agentType) : FORK_UNAVAILABLE_TEXT;
|
|
348
|
+
}
|
|
349
|
+
/** 内置工具 `skill_load`(见文件头)。 */
|
|
350
|
+
export function skillLoadTool(deps) {
|
|
351
|
+
return {
|
|
352
|
+
spec: SPEC,
|
|
353
|
+
defaultPolicy: "allow",
|
|
354
|
+
// 可能要创建 / 恢复沙箱并复制文件:与沙箱工具同一时限
|
|
355
|
+
timeoutMs: () => sandboxBaseTimeoutMs(deps.config()),
|
|
356
|
+
async run(input, ctx) {
|
|
357
|
+
const asked = input.name;
|
|
358
|
+
const snap = await deps.eventLog.latestOfType(ctx.conversationId, "skills_catalog");
|
|
359
|
+
const skills = snap?.payload.skills ?? [];
|
|
360
|
+
let entry = findEntry(skills, asked);
|
|
361
|
+
// a trial draft is looked up in the conversation where the skill resolved
|
|
362
|
+
let draftConversation = ctx.conversationId;
|
|
363
|
+
if (!entry) {
|
|
364
|
+
// phase D: a skill a person invoked here (manual-only skills are never in the catalog)
|
|
365
|
+
const invoked = await invokedEntry(deps.db, ctx, asked);
|
|
366
|
+
if (invoked === "removed")
|
|
367
|
+
throw new ToolError(removedText(asked));
|
|
368
|
+
if (invoked) {
|
|
369
|
+
entry = invoked.entry;
|
|
370
|
+
draftConversation = invoked.conversationId;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (!entry && skills.length === 0)
|
|
374
|
+
throw new ToolError(NO_SKILLS_TEXT);
|
|
375
|
+
if (!entry)
|
|
376
|
+
throw new ToolError(notInCatalog(asked, skills));
|
|
377
|
+
const name = entry.name;
|
|
378
|
+
const row = await findSkillVersion(deps.db, { orgId: ctx.orgId, conversationId: draftConversation }, entry);
|
|
379
|
+
if (!row)
|
|
380
|
+
throw new ToolError(removedText(name));
|
|
381
|
+
const manifest = row.manifest;
|
|
382
|
+
const store = deps.storage.kernel(ctx.orgId);
|
|
383
|
+
const prefix = row.object_prefix;
|
|
384
|
+
const md = manifest.files.find((f) => f.path === SKILL_ENTRY_FILE);
|
|
385
|
+
if (!md)
|
|
386
|
+
throw new ToolError(integrityText(name));
|
|
387
|
+
const mdBytes = await readVerified(store, `${prefix}${md.path}`, md, name, ctx.signal);
|
|
388
|
+
const v = { entry, manifest, prefix, store, entryBytes: mdBytes };
|
|
389
|
+
let parsed;
|
|
390
|
+
try {
|
|
391
|
+
parsed = parseSkillMd(new TextDecoder("utf-8", { fatal: true }).decode(mdBytes), {
|
|
392
|
+
invocationKeys: false,
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
catch {
|
|
396
|
+
throw new ToolError(integrityText(name));
|
|
397
|
+
}
|
|
398
|
+
if ("errors" in parsed)
|
|
399
|
+
throw new ToolError(integrityText(name));
|
|
400
|
+
const dir = `${SKILLS_SANDBOX_ROOT}/${name}/`;
|
|
401
|
+
const others = manifest.files.filter((f) => f.path !== SKILL_ENTRY_FILE);
|
|
402
|
+
let notices = [];
|
|
403
|
+
let filesText;
|
|
404
|
+
if (others.length === 0) {
|
|
405
|
+
filesText = "This skill has no files besides its instructions.";
|
|
406
|
+
}
|
|
407
|
+
else if (!deps.sandbox.available) {
|
|
408
|
+
filesText =
|
|
409
|
+
`Skill files (for reference):\n${fileList(manifest.files)}\n` +
|
|
410
|
+
"This deployment has no sandbox, so the skill's scripts and other files are not available; " +
|
|
411
|
+
"follow the instructions without running them.";
|
|
412
|
+
}
|
|
413
|
+
else if (!hasSandboxTools(ctx)) {
|
|
414
|
+
// 模型跑不了脚本:不为它创建沙箱、不复制
|
|
415
|
+
filesText =
|
|
416
|
+
`Skill files (for reference):\n${fileList(manifest.files)}\n` +
|
|
417
|
+
"This agent has no sandbox tools, so the skill's scripts and other files cannot be run; " +
|
|
418
|
+
"follow the instructions in the body without them.";
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
// the skill's marker is read, compared and written: one holder at a time per skill
|
|
422
|
+
const r = await inSandbox(deps, ctx, (s) => withPathLease(deps, ctx, skillMarkerPath(v.entry.name), s.signal, (signal) => copySkill({ ...s, signal }, v)));
|
|
423
|
+
notices = r.notices;
|
|
424
|
+
const stale = r.value.stale.length > 0
|
|
425
|
+
? `\nFiles left over from an earlier version (not part of this version; ignore them): ${r.value.stale.join(", ")}`
|
|
426
|
+
: "";
|
|
427
|
+
filesText =
|
|
428
|
+
`Skill files (copied to ${dir} in the sandbox, read-only):\n${fileList(manifest.files)}\n` +
|
|
429
|
+
`Run scripts with an interpreter, e.g. \`sh ${dir}<script>.sh\`, \`python3 ${dir}<script>.py\` ` +
|
|
430
|
+
"or `node`; the files are not executable, so `./script` does not work. Write outputs under " +
|
|
431
|
+
`/workspace, not ${SKILLS_SANDBOX_ROOT}.${stale}`;
|
|
432
|
+
}
|
|
433
|
+
const fork = invocationOf(manifest).fork;
|
|
434
|
+
const text = [
|
|
435
|
+
...(fork ? [await forkLine(deps.db, ctx, fork, entry.plugin)] : []),
|
|
436
|
+
`Loaded skill "${name}" (version ${entry.version}).`,
|
|
437
|
+
filesText,
|
|
438
|
+
`<skill name="${name}" version="${entry.version}">\n${parsed.body.trim()}\n</skill>`,
|
|
439
|
+
].join("\n\n");
|
|
440
|
+
return {
|
|
441
|
+
content: [{ type: "text", text: withNotices(notices, text) }],
|
|
442
|
+
display: display(`加载技能 ${name}(版本 ${entry.version})`, `Loaded skill ${name} (version ${entry.version})`),
|
|
443
|
+
};
|
|
444
|
+
},
|
|
445
|
+
};
|
|
446
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { SkillManifest } from "../../db/kernel-schema.js";
|
|
2
|
+
import type { SkillChangesService } from "../../skills/changes.service.js";
|
|
3
|
+
import type { BuiltinTool } from "../registry.js";
|
|
4
|
+
/**
|
|
5
|
+
* 内置工具 `skill_write`(M5 T15,R4):agent 新建或更新它自己的技能(`scope = agent`)。
|
|
6
|
+
* - 输入 `{ name, description, files: [{ path, content }] }`,只收文本文件,整个技能 ≤ {@link SKILL_WRITE_MAX_BYTES};
|
|
7
|
+
* - the kernel generates SKILL.md ({@link buildSkillWrite}): its frontmatter is `name` / `description`
|
|
8
|
+
* plus the invocation keys (`disable-model-invocation`, `context`, ... phase D) of the frontmatter
|
|
9
|
+
* of the `SKILL.md` entry in `files`, whose other keys are dropped; its body is that entry's body
|
|
10
|
+
* (empty without the entry);
|
|
11
|
+
* - 每次调用写一个完整的新版本(上一版有、这次没给的文件不再属于新版本);
|
|
12
|
+
* - 私有 agent 直接生成新版本并立即生效;共享 agent 由触发对话的人先确认这次调用(R3 固定 ask,见 tools/policy.ts),
|
|
13
|
+
* 再生成变更申请等负责人批准,期间只有本对话试用新版本(见 skills/changes.service.ts);
|
|
14
|
+
* - 成功后立即在日志追加技能目录快照(`skills_catalog`,Ruling M17),同一运行的下一步就能 `skill_load`。
|
|
15
|
+
*/
|
|
16
|
+
/** 一个技能(含合成的 SKILL.md)的总大小上限(UTF-8 字节)。 */
|
|
17
|
+
export declare const SKILL_WRITE_MAX_BYTES: number;
|
|
18
|
+
/** 一次最多的文件数(含 SKILL.md)。 */
|
|
19
|
+
export declare const SKILL_WRITE_MAX_FILES = 200;
|
|
20
|
+
/** `skill_write` 的输入(已按 inputSchema 校验)。 */
|
|
21
|
+
export interface SkillWriteInput {
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
files: {
|
|
25
|
+
path: string;
|
|
26
|
+
content: string;
|
|
27
|
+
}[];
|
|
28
|
+
}
|
|
29
|
+
/** 一个待写入的文件。 */
|
|
30
|
+
export interface BuiltSkillFile {
|
|
31
|
+
path: string;
|
|
32
|
+
data: Uint8Array;
|
|
33
|
+
size: number;
|
|
34
|
+
sha256: string;
|
|
35
|
+
}
|
|
36
|
+
/** {@link buildSkillWrite} 成功的结果。 */
|
|
37
|
+
export interface BuiltSkill {
|
|
38
|
+
name: string;
|
|
39
|
+
description: string;
|
|
40
|
+
files: BuiltSkillFile[];
|
|
41
|
+
manifest: SkillManifest;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 由工具输入合成技能文件(纯函数):
|
|
45
|
+
* - SKILL.md = `---\n<yaml name/description>---\n\n<正文>\n`,正文为 `files` 里 `SKILL.md` 的内容去掉 frontmatter、
|
|
46
|
+
* 去掉首尾空行;合成结果再用 `parseSkillMd` 校验(名字规则、描述长度、不含 XML 标签);
|
|
47
|
+
* - 其余文件按 `validateSkillPackage` 校验路径(不能越出 `/skills/<name>/`、不能重复、大小写冲突等);
|
|
48
|
+
* - 只收文本:内容含 NUL 视为二进制,拒绝;全部文件(含 SKILL.md)的 UTF-8 字节数之和 ≤ {@link SKILL_WRITE_MAX_BYTES}。
|
|
49
|
+
* 返回合成结果或全部问题(英文,直接给模型)。
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildSkillWrite(input: SkillWriteInput): BuiltSkill | {
|
|
52
|
+
errors: string[];
|
|
53
|
+
};
|
|
54
|
+
/** 依赖:技能变更服务。 */
|
|
55
|
+
export interface SkillWriteDeps {
|
|
56
|
+
changes: Pick<SkillChangesService, "write">;
|
|
57
|
+
}
|
|
58
|
+
/** 内置工具 `skill_write`(见文件头)。 */
|
|
59
|
+
export declare function skillWriteTool(deps: SkillWriteDeps): BuiltinTool;
|