@vellumai/assistant 0.10.1 → 0.10.2-dev.202606241743.799fce7
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/docs/workspace-tools.md +42 -33
- package/eslint-rules/cli-no-daemon-internals.js +6 -0
- package/node_modules/@vellumai/gateway-client/src/__tests__/guardian-delivery-contract.test.ts +91 -0
- package/node_modules/@vellumai/gateway-client/src/__tests__/trust-verdict-contract.test.ts +31 -0
- package/node_modules/@vellumai/gateway-client/src/guardian-delivery-contract.ts +48 -0
- package/node_modules/@vellumai/gateway-client/src/index.ts +14 -0
- package/node_modules/@vellumai/gateway-client/src/trust-verdict-contract.ts +17 -0
- package/openapi.yaml +74 -1
- package/package.json +1 -1
- package/scripts/test.sh +36 -15
- package/src/__tests__/actor-token-service.test.ts +36 -14
- package/src/__tests__/agent-loop-override-profile.test.ts +1 -0
- package/src/__tests__/agent-wake-disk-pressure-callsite.test.ts +2 -0
- package/src/__tests__/agent-wake-override-profile.test.ts +2 -0
- package/src/__tests__/annotate-activity-metadata.test.ts +2 -0
- package/src/__tests__/annotate-risk-options.test.ts +2 -0
- package/src/__tests__/approval-cascade.test.ts +2 -0
- package/src/__tests__/background-workers-disk-pressure.test.ts +2 -0
- package/src/__tests__/btw-routes.test.ts +2 -0
- package/src/__tests__/build-persisted-content.test.ts +2 -0
- package/src/__tests__/call-controller.test.ts +19 -0
- package/src/__tests__/channel-guardian.test.ts +94 -58
- package/src/__tests__/channel-reply-delivery.test.ts +2 -0
- package/src/__tests__/compaction-events.test.ts +2 -0
- package/src/__tests__/compaction.benchmark.test.ts +2 -0
- package/src/__tests__/compactor-call-site-logging.test.ts +2 -0
- package/src/__tests__/compactor-low-watermark-cut.test.ts +2 -0
- package/src/__tests__/compactor-preserved-tail-count.test.ts +2 -0
- package/src/__tests__/compactor-summary-call-truncation.test.ts +2 -0
- package/src/__tests__/compactor-web-search-strip.test.ts +2 -0
- package/src/__tests__/computer-use-tools.test.ts +13 -0
- package/src/__tests__/config-loader-backfill.test.ts +5 -1
- package/src/__tests__/config-schema.test.ts +1 -0
- package/src/__tests__/confirmation-request-guardian-bridge.test.ts +31 -29
- package/src/__tests__/contacts-relay-reads.test.ts +13 -15
- package/src/__tests__/conversation-abort-tool-results.test.ts +2 -0
- package/src/__tests__/conversation-agent-loop-disk-pressure.test.ts +2 -0
- package/src/__tests__/conversation-agent-loop-inference-profile.test.ts +2 -0
- package/src/__tests__/conversation-agent-loop-overflow.test.ts +2 -0
- package/src/__tests__/conversation-agent-loop.test.ts +7 -0
- package/src/__tests__/conversation-analysis-routes.test.ts +2 -0
- package/src/__tests__/conversation-app-control-lifecycle.test.ts +2 -0
- package/src/__tests__/conversation-confirmation-signals.test.ts +2 -0
- package/src/__tests__/conversation-history-web-search.test.ts +2 -0
- package/src/__tests__/conversation-load-history-repair.test.ts +2 -0
- package/src/__tests__/conversation-load-history-stripped.test.ts +2 -0
- package/src/__tests__/conversation-pairing.test.ts +2 -0
- package/src/__tests__/conversation-process-app-control-preactivation.test.ts +2 -0
- package/src/__tests__/conversation-process-callsite.test.ts +2 -0
- package/src/__tests__/conversation-provider-retry-repair.test.ts +2 -0
- package/src/__tests__/conversation-queue.test.ts +91 -0
- package/src/__tests__/conversation-routes-guardian-reply.test.ts +14 -0
- package/src/__tests__/conversation-routes-slash-commands.test.ts +14 -0
- package/src/__tests__/conversation-slash-queue.test.ts +2 -0
- package/src/__tests__/conversation-slash-unknown.test.ts +2 -0
- package/src/__tests__/conversation-speed-override.test.ts +2 -0
- package/src/__tests__/conversation-surfaces-action-delivery.test.ts +65 -0
- package/src/__tests__/conversation-title-service.test.ts +2 -0
- package/src/__tests__/conversation-tool-setup-attribution.test.ts +47 -0
- package/src/__tests__/conversation-usage.test.ts +2 -0
- package/src/__tests__/conversation-workspace-cache-state.test.ts +2 -0
- package/src/__tests__/conversation-workspace-injection.test.ts +2 -0
- package/src/__tests__/conversation-workspace-tool-tracking.test.ts +2 -0
- package/src/__tests__/credential-security-invariants.test.ts +0 -1
- package/src/__tests__/db-migration-rollback.test.ts +205 -171
- package/src/__tests__/db-test-helpers.ts +5 -4
- package/src/__tests__/deterministic-verification-control-plane.test.ts +4 -2
- package/src/__tests__/disk-pressure-guard.test.ts +41 -0
- package/src/__tests__/dm-persistence.test.ts +2 -0
- package/src/__tests__/emit-signal-routing-intent.test.ts +10 -5
- package/src/__tests__/events-dev-bypass-actor.test.ts +7 -1
- package/src/__tests__/filing-service.test.ts +2 -0
- package/src/__tests__/guardian-binding-drift-heal.test.ts +75 -10
- package/src/__tests__/guardian-dispatch.test.ts +95 -1
- package/src/__tests__/guardian-outbound-http.test.ts +13 -0
- package/src/__tests__/heartbeat-disk-pressure.test.ts +2 -0
- package/src/__tests__/heartbeat-service.test.ts +2 -0
- package/src/__tests__/helpers/channel-test-adapter.ts +1 -7
- package/src/__tests__/host-app-control-routes.test.ts +24 -30
- package/src/__tests__/host-bash-routes.test.ts +31 -41
- package/src/__tests__/host-browser-routes.test.ts +26 -32
- package/src/__tests__/host-cu-proxy.test.ts +299 -0
- package/src/__tests__/host-cu-routes-targeted.test.ts +25 -33
- package/src/__tests__/host-file-routes-targeted.test.ts +40 -52
- package/src/__tests__/host-transfer-routes-targeted.test.ts +31 -43
- package/src/__tests__/http-user-message-parity.test.ts +167 -8
- package/src/__tests__/inbound-slack-persistence.test.ts +2 -0
- package/src/__tests__/invite-redemption-service.test.ts +43 -0
- package/src/__tests__/llm-context-normalization.test.ts +105 -0
- package/src/__tests__/llm-usage-store.test.ts +25 -0
- package/src/__tests__/media-stream-server-integration.test.ts +127 -0
- package/src/__tests__/memory-retrieval-hook.test.ts +2 -0
- package/src/__tests__/messaging-send-tool.test.ts +2 -0
- package/src/__tests__/migration-import-from-url.test.ts +2 -2
- package/src/__tests__/mtime-cache.test.ts +146 -5
- package/src/__tests__/native-web-search.test.ts +2 -0
- package/src/__tests__/non-member-access-request.test.ts +189 -17
- package/src/__tests__/notification-broadcaster.test.ts +4 -0
- package/src/__tests__/notification-decision-recipient-context.test.ts +33 -32
- package/src/__tests__/notification-deep-link.test.ts +6 -0
- package/src/__tests__/notification-guardian-path.test.ts +19 -0
- package/src/__tests__/outbound-slack-persistence.test.ts +2 -0
- package/src/__tests__/pending-interactions-resolved-event.test.ts +7 -4
- package/src/__tests__/persistence-secret-redaction.test.ts +2 -0
- package/src/__tests__/plugin-bootstrap.test.ts +3 -73
- package/src/__tests__/plugin-route-contribution.test.ts +4 -17
- package/src/__tests__/plugin-tool-contribution.test.ts +3 -18
- package/src/__tests__/plugin-types.test.ts +0 -2
- package/src/__tests__/process-message-background-slack.test.ts +2 -0
- package/src/__tests__/process-message-display-content.test.ts +2 -0
- package/src/__tests__/provider-usage-tracking.test.ts +39 -0
- package/src/__tests__/regenerate-fire-and-forget-trace.test.ts +2 -0
- package/src/__tests__/registry.test.ts +3 -0
- package/src/__tests__/relay-server.test.ts +694 -25
- package/src/__tests__/runtime-attachment-metadata.test.ts +0 -1
- package/src/__tests__/secret-ingress-http.test.ts +14 -0
- package/src/__tests__/send-endpoint-busy.test.ts +30 -8
- package/src/__tests__/skills.test.ts +44 -0
- package/src/__tests__/slack-inbound-verification.test.ts +47 -2
- package/src/__tests__/sse-actor-principal-guardian-source.test.ts +102 -0
- package/src/__tests__/steer-on-enqueue-question.test.ts +181 -0
- package/src/__tests__/stt-hints.test.ts +44 -13
- package/src/__tests__/subagent-detail.test.ts +27 -0
- package/src/__tests__/subagent-disposal.test.ts +65 -0
- package/src/__tests__/subagent-notify-parent.test.ts +2 -0
- package/src/__tests__/subagent-spawn-tool-fork.test.ts +2 -0
- package/src/__tests__/subagent-tools.test.ts +2 -0
- package/src/__tests__/suggestion-routes.test.ts +2 -0
- package/src/__tests__/title-generate-hook.test.ts +2 -0
- package/src/__tests__/tool-executor-lifecycle-events.test.ts +2 -0
- package/src/__tests__/tool-executor.test.ts +16 -11
- package/src/__tests__/tool-preview-lifecycle.test.ts +2 -0
- package/src/__tests__/tool-result-metadata-plumbing.test.ts +2 -0
- package/src/__tests__/tool-start-timestamp.test.ts +2 -0
- package/src/__tests__/trusted-contact-inline-approval-integration.test.ts +10 -10
- package/src/__tests__/twilio-routes.test.ts +96 -0
- package/src/__tests__/verification-control-plane-policy.test.ts +2 -0
- package/src/__tests__/web-search-backend-failure.test.ts +2 -0
- package/src/__tests__/workspace-migration-remove-hooks.test.ts +14 -35
- package/src/__tests__/workspace-tool-loader.test.ts +195 -2
- package/src/agent/loop-exclusive-tool.test.ts +150 -0
- package/src/agent/loop.ts +56 -0
- package/src/api/constants/sse-replay.ts +41 -0
- package/src/api/index.ts +6 -0
- package/src/api/responses/llm-request-log-entry.ts +25 -0
- package/src/api/responses/subagent-detail.ts +17 -0
- package/src/calls/__tests__/relay-setup-router.test.ts +262 -4
- package/src/calls/call-domain.ts +3 -3
- package/src/calls/guardian-dispatch.ts +10 -8
- package/src/calls/inbound-trust-reader.ts +17 -1
- package/src/calls/media-stream-server.ts +21 -0
- package/src/calls/relay-server.ts +167 -50
- package/src/calls/relay-setup-router.ts +37 -7
- package/src/calls/relay-verification.ts +4 -4
- package/src/calls/stt-hints.ts +9 -12
- package/src/calls/twilio-routes.ts +14 -4
- package/src/cli/commands/__tests__/cache.test.ts +8 -1
- package/src/cli/commands/cache.ts +194 -181
- package/src/cli/commands/db/__tests__/repair.test.ts +6 -5
- package/src/cli/commands/db/status.ts +37 -1
- package/src/cli/commands/mcp.ts +252 -218
- package/src/cli/commands/memory/__tests__/worker.test.ts +302 -0
- package/src/cli/commands/memory/index.ts +2 -0
- package/src/cli/commands/memory/worker.ts +175 -0
- package/src/cli/commands/plugins.ts +75 -3
- package/src/cli/lib/__tests__/install-from-github.test.ts +102 -0
- package/src/cli/lib/__tests__/list-installed-plugins.test.ts +160 -1
- package/src/cli/lib/list-installed-plugins.ts +179 -1
- package/src/config/__tests__/loader-callsite-strip-fallback.test.ts +143 -0
- package/src/config/bundled-skills/computer-use/TOOLS.json +6 -1
- package/src/config/bundled-skills/contacts/tools/contact-merge.ts +27 -17
- package/src/config/bundled-skills/contacts/tools/contact-search.ts +13 -3
- package/src/config/feature-flag-registry.json +0 -8
- package/src/config/loader.ts +36 -5
- package/src/config/schemas/__tests__/memory-v3.test.ts +1 -0
- package/src/config/schemas/memory-lifecycle.ts +12 -0
- package/src/config/schemas/memory-v3.ts +7 -0
- package/src/config/schemas/memory.ts +4 -0
- package/src/config/schemas/timeouts.ts +8 -0
- package/src/config/seed-inference-profiles.ts +14 -5
- package/src/config/skills.ts +27 -5
- package/src/contacts/__tests__/guardian-delivery-reader.test.ts +312 -0
- package/src/contacts/contacts-write.ts +3 -0
- package/src/contacts/guardian-delivery-reader.ts +223 -0
- package/src/daemon/conversation-agent-loop.ts +9 -0
- package/src/daemon/conversation-process.ts +39 -17
- package/src/daemon/conversation-surfaces.ts +93 -36
- package/src/daemon/conversation-tool-setup.ts +49 -16
- package/src/daemon/conversation.ts +21 -2
- package/src/daemon/disk-pressure-guard.ts +12 -2
- package/src/daemon/event-loop-watchdog.ts +28 -1
- package/src/daemon/external-plugins-bootstrap.ts +4 -34
- package/src/daemon/handlers/__tests__/config-a2a-redeem.test.ts +25 -0
- package/src/daemon/handlers/__tests__/config-channels.test.ts +225 -0
- package/src/daemon/handlers/config-a2a.ts +6 -14
- package/src/daemon/handlers/config-channels.ts +78 -22
- package/src/daemon/handlers/conversations.ts +77 -0
- package/src/daemon/host-cu-proxy.ts +102 -11
- package/src/daemon/lifecycle.ts +4 -0
- package/src/daemon/memory-v2-startup.test.ts +72 -0
- package/src/daemon/memory-v2-startup.ts +87 -19
- package/src/daemon/server.ts +0 -4
- package/src/daemon/shutdown-handlers.ts +20 -0
- package/src/daemon/tool-setup-types.ts +9 -0
- package/src/hooks/hook-loader.ts +341 -0
- package/src/ipc/__tests__/clients-list-ipc.test.ts +1 -1
- package/src/ipc/assistant-server.ts +2 -2
- package/src/memory/__tests__/301-create-watchdog-events.test.ts +110 -0
- package/src/memory/__tests__/memory-retrospective-job.test.ts +8 -0
- package/src/memory/__tests__/prompt-override.test.ts +192 -0
- package/src/memory/__tests__/watchdog-events-store.test.ts +161 -0
- package/src/memory/conversation-crud.ts +38 -0
- package/src/memory/db-connection.ts +22 -3
- package/src/memory/db-init.ts +36 -502
- package/src/memory/db-singleton.ts +6 -4
- package/src/memory/jobs-worker.ts +58 -0
- package/src/memory/llm-usage-store.ts +48 -20
- package/src/memory/memory-retrospective-job.ts +9 -8
- package/src/memory/migrations/014-backfill-inbox-thread-state.ts +13 -3
- package/src/memory/migrations/136-drop-assistant-id-columns.ts +52 -27
- package/src/memory/migrations/209-strip-thinking-from-consolidated.ts +130 -56
- package/src/memory/migrations/300-add-processing-started-at.ts +30 -0
- package/src/memory/migrations/301-create-watchdog-events.ts +45 -0
- package/src/memory/migrations/__tests__/014-backfill-inbox-thread-state.test.ts +108 -0
- package/src/memory/migrations/__tests__/136-drop-assistant-id-columns.test.ts +82 -0
- package/src/memory/migrations/__tests__/209-strip-thinking-from-consolidated.test.ts +224 -0
- package/src/memory/migrations/__tests__/run-migrations.test.ts +2 -2
- package/src/memory/migrations/run-migrations.ts +90 -6
- package/src/memory/migrations/schema-introspection.ts +14 -0
- package/src/memory/migrations/validate-migration-state.ts +101 -66
- package/src/memory/prompt-override.ts +129 -0
- package/src/memory/schema/conversations.ts +9 -0
- package/src/memory/schema/infrastructure.ts +20 -0
- package/src/memory/steps.ts +573 -0
- package/src/memory/v2/__tests__/cli-command-store.test.ts +25 -0
- package/src/memory/v2/__tests__/skill-store.test.ts +80 -0
- package/src/memory/v2/cli-command-store.ts +75 -38
- package/src/memory/v2/prompts/consolidation.ts +13 -82
- package/src/memory/v2/prompts/router.ts +21 -93
- package/src/memory/v2/skill-store.ts +68 -31
- package/src/memory/watchdog-events-store.ts +87 -0
- package/src/memory/worker-control.ts +118 -0
- package/src/memory/worker-process.ts +72 -0
- package/src/notifications/__tests__/broadcaster.test.ts +16 -8
- package/src/notifications/__tests__/connected-channels.test.ts +114 -0
- package/src/notifications/__tests__/decision-engine.test.ts +78 -9
- package/src/notifications/__tests__/destination-resolver.test.ts +256 -0
- package/src/notifications/broadcaster.ts +8 -1
- package/src/notifications/decision-engine.ts +15 -7
- package/src/notifications/destination-resolver.ts +68 -24
- package/src/notifications/emit-signal.ts +39 -14
- package/src/onboarding/checkin-event.test.ts +220 -0
- package/src/onboarding/checkin-event.ts +321 -0
- package/src/onboarding/schedule-checkin.ts +190 -0
- package/src/permissions/question-prompter.test.ts +1 -1
- package/src/permissions/question-prompter.ts +7 -4
- package/src/plugin-api/index.ts +6 -6
- package/src/plugin-api/types.ts +3 -5
- package/src/plugin-api/vision-support.test.ts +28 -4
- package/src/plugin-api/vision-support.ts +66 -31
- package/src/plugins/defaults/advisor/__tests__/consult.test.ts +161 -0
- package/src/plugins/defaults/advisor/__tests__/context-pack-gating.test.ts +106 -0
- package/src/plugins/defaults/advisor/__tests__/context-pack.test.ts +60 -0
- package/src/plugins/defaults/advisor/consult.ts +110 -6
- package/src/plugins/defaults/advisor/context-pack.ts +288 -0
- package/src/plugins/defaults/advisor/steering.ts +14 -2
- package/src/plugins/defaults/advisor/tools/advisor.ts +32 -5
- package/src/plugins/defaults/image-fallback/__tests__/image-fallback.test.ts +47 -7
- package/src/plugins/defaults/image-fallback/hooks/post-tool-use.ts +10 -11
- package/src/plugins/defaults/image-fallback/hooks/user-prompt-submit.ts +12 -20
- package/src/plugins/defaults/image-fallback/src/caption-blocks.ts +42 -11
- package/src/plugins/defaults/memory-v3-shadow/orchestrate.ts +11 -2
- package/src/plugins/defaults/memory-v3-shadow/pool-select.test.ts +146 -0
- package/src/plugins/defaults/memory-v3-shadow/pool-select.ts +29 -1
- package/src/plugins/defaults/memory-v3-shadow/shadow-plugin.ts +8 -1
- package/src/plugins/mtime-cache.ts +76 -291
- package/src/plugins/surface-import.ts +121 -0
- package/src/plugins/types.ts +0 -2
- package/src/providers/anthropic/client.ts +5 -0
- package/src/providers/call-site-routing.ts +4 -0
- package/src/providers/model-catalog.ts +16 -0
- package/src/providers/openai/responses-provider.ts +5 -0
- package/src/providers/openrouter/client.ts +5 -0
- package/src/providers/provider-send-message.ts +4 -0
- package/src/providers/ratelimit.ts +4 -0
- package/src/providers/retry.ts +4 -0
- package/src/providers/types.ts +9 -0
- package/src/providers/usage-tracking.ts +4 -0
- package/src/runtime/__tests__/channel-verification-service.test.ts +133 -0
- package/src/runtime/__tests__/guardian-vellum-migration.test.ts +181 -0
- package/src/runtime/__tests__/is-guardian-bound-for-channel.test.ts +66 -0
- package/src/runtime/__tests__/local-principal-trust.test.ts +164 -0
- package/src/runtime/__tests__/trust-verdict-consumer.test.ts +335 -3
- package/src/runtime/access-request-helper.ts +19 -39
- package/src/runtime/actor-trust-resolver.ts +2 -2
- package/src/runtime/anchored-guardian.test.ts +156 -0
- package/src/runtime/anchored-guardian.ts +135 -0
- package/src/runtime/assistant-event-hub.ts +1 -1
- package/src/runtime/assistant-stream-state.ts +9 -2
- package/src/runtime/auth/__tests__/require-bound-guardian.test.ts +99 -0
- package/src/runtime/auth/require-bound-guardian.ts +21 -11
- package/src/runtime/channel-verification-service.ts +56 -31
- package/src/runtime/confirmation-request-guardian-bridge.ts +3 -3
- package/src/runtime/guardian-vellum-migration.ts +66 -7
- package/src/runtime/invite-redemption-service.ts +50 -18
- package/src/runtime/local-actor-identity.ts +76 -11
- package/src/runtime/local-principal-trust.ts +52 -0
- package/src/runtime/pending-interactions.ts +11 -1
- package/src/runtime/routes/__tests__/channel-verification-revoke.test.ts +56 -5
- package/src/runtime/routes/__tests__/channel-verification-routes.test.ts +1 -1
- package/src/runtime/routes/__tests__/contact-routes.test.ts +212 -0
- package/src/runtime/routes/__tests__/global-search-routes.test.ts +93 -0
- package/src/runtime/routes/__tests__/surface-action-routes.test.ts +215 -1
- package/src/runtime/routes/browser-routes.ts +1 -1
- package/src/runtime/routes/channel-verification-routes.ts +3 -3
- package/src/runtime/routes/contact-routes.ts +8 -32
- package/src/runtime/routes/conversation-cli-routes.ts +4 -5
- package/src/runtime/routes/conversation-list-routes.ts +4 -7
- package/src/runtime/routes/conversation-routes.ts +74 -81
- package/src/runtime/routes/events-routes.ts +2 -2
- package/src/runtime/routes/global-search-routes.ts +3 -1
- package/src/runtime/routes/guardian-action-routes.ts +4 -5
- package/src/runtime/routes/host-app-control-routes.ts +5 -4
- package/src/runtime/routes/host-bash-routes.ts +5 -4
- package/src/runtime/routes/host-browser-routes.ts +9 -11
- package/src/runtime/routes/host-cu-routes.ts +5 -4
- package/src/runtime/routes/host-file-routes.ts +5 -4
- package/src/runtime/routes/host-transfer-routes.ts +6 -6
- package/src/runtime/routes/http-adapter.ts +1 -1
- package/src/runtime/routes/identity-routes.ts +3 -2
- package/src/runtime/routes/inbound-message-handler.ts +5 -5
- package/src/runtime/routes/inbound-stages/acl-enforcement.test.ts +97 -5
- package/src/runtime/routes/inbound-stages/acl-enforcement.ts +61 -49
- package/src/runtime/routes/inbound-stages/background-dispatch.ts +16 -4
- package/src/runtime/routes/inbound-stages/escalation-intercept.ts +7 -7
- package/src/runtime/routes/inbound-stages/guardian-activation-intercept.test.ts +21 -8
- package/src/runtime/routes/inbound-stages/guardian-activation-intercept.ts +14 -3
- package/src/runtime/routes/index.ts +2 -0
- package/src/runtime/routes/llm-context-normalization.ts +71 -0
- package/src/runtime/routes/mcp-auth-routes.ts +38 -15
- package/src/runtime/routes/migration-rollback-routes.ts +4 -3
- package/src/runtime/routes/migration-routes.ts +4 -1
- package/src/runtime/routes/onboarding-checkin-routes.ts +86 -0
- package/src/runtime/routes/subagents-routes.ts +5 -0
- package/src/runtime/routes/surface-action-routes.ts +51 -55
- package/src/runtime/services/__tests__/conversation-serializer.test.ts +1 -0
- package/src/runtime/services/conversation-serializer.ts +7 -9
- package/src/runtime/tool-grant-request-helper.ts +3 -3
- package/src/runtime/trust-verdict-consumer.ts +85 -9
- package/src/runtime/verification-outbound-actions.ts +18 -18
- package/src/signals/user-message.ts +16 -0
- package/src/subagent/manager.ts +9 -0
- package/src/telemetry/types.ts +34 -1
- package/src/telemetry/usage-telemetry-reporter.test.ts +3 -2
- package/src/telemetry/usage-telemetry-reporter.ts +87 -3
- package/src/tools/ask-question/ask-question-tool.test.ts +29 -0
- package/src/tools/ask-question/ask-question-tool.ts +13 -0
- package/src/tools/computer-use/definitions.ts +8 -2
- package/src/tools/executor.ts +4 -4
- package/src/tools/registry.ts +18 -0
- package/src/tools/tool-approval-handler.ts +1 -1
- package/src/tools/tool-defaults.ts +9 -2
- package/src/tools/types.ts +17 -2
- package/src/tools/workspace-tools/loader.ts +348 -244
- package/src/util/platform.ts +5 -0
- package/src/util/telemetry-db-path.ts +24 -0
- package/src/workspace/migrations/017-seed-persona-dirs.ts +3 -34
- package/src/workspace/migrations/019-scope-journal-to-guardian.ts +3 -24
- package/src/workspace/migrations/048-remove-workspace-hooks.ts +14 -66
- package/src/__tests__/workspace-tools-watcher-flag.test.ts +0 -70
- package/src/daemon/workspace-tools-watcher.ts +0 -328
- package/src/memory/migrations/registry.ts +0 -573
|
@@ -1,32 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Per-surface mtime cache for user plugins.
|
|
2
|
+
* Per-surface mtime cache for user plugins (discovery + tools).
|
|
3
3
|
*
|
|
4
|
-
* Instead of caching whole `Plugin` objects,
|
|
5
|
-
*
|
|
4
|
+
* Instead of caching whole `Plugin` objects, the user-plugin system caches
|
|
5
|
+
* individual surfaces keyed by their source file's mtime. This module owns
|
|
6
|
+
* plugin **discovery** (which plugin directories exist, in what order) and the
|
|
7
|
+
* **tool** cache; the **hook** cache and every hook operation live in
|
|
8
|
+
* `../hooks/hook-loader.ts`. This module is the boot orchestrator: it scans the
|
|
9
|
+
* plugins directory, registers tools, and drives hook pre-import / init /
|
|
10
|
+
* shutdown by handing the discovered directories to the hook loader.
|
|
6
11
|
*
|
|
7
|
-
* - A changed
|
|
8
|
-
* plugin rebuild.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* and hooks into the global registries, then cache-bust them using mtime
|
|
13
|
-
* on reads.
|
|
12
|
+
* - A changed tool file triggers a re-import of just that tool, not a full
|
|
13
|
+
* plugin rebuild. Added and removed surface files are picked up live, since
|
|
14
|
+
* discovery is by directory listing.
|
|
15
|
+
* - Plugins are never "registered" as a unit — we register their tools into
|
|
16
|
+
* the global tool registry and cache-bust them using mtime on reads.
|
|
14
17
|
*
|
|
15
18
|
* The cache is populated at boot by `loadUserPlugins()` and read on every
|
|
16
|
-
* `getHooksFor` / `getAllTools` call.
|
|
17
|
-
* the next read detects the mismatch, re-imports the file, and swaps the
|
|
18
|
-
* cached entry.
|
|
19
|
+
* `getHooksFor` / `getAllTools` call.
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
|
-
import { existsSync,
|
|
22
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
22
23
|
import { join } from "node:path";
|
|
23
24
|
|
|
24
|
-
import { getConfig } from "../config/loader.js";
|
|
25
25
|
import { registerShutdownHook } from "../daemon/shutdown-registry.js";
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
clearPluginHooks,
|
|
28
|
+
collectUserHooks,
|
|
29
|
+
evictHooksForOwner,
|
|
30
|
+
hasWorkspaceHooks,
|
|
31
|
+
preImportHooksDir,
|
|
32
|
+
preImportWorkspaceHooks,
|
|
33
|
+
resetHookCacheForTests,
|
|
34
|
+
runInitHook,
|
|
35
|
+
runShutdownHook,
|
|
36
|
+
WORKSPACE_HOOKS_OWNER,
|
|
37
|
+
} from "../hooks/hook-loader.js";
|
|
27
38
|
import type {
|
|
28
39
|
PluginHookFn,
|
|
29
|
-
PluginInitContext,
|
|
30
40
|
PluginShutdownContext,
|
|
31
41
|
} from "../plugin-api/types.js";
|
|
32
42
|
import {
|
|
@@ -36,14 +46,19 @@ import {
|
|
|
36
46
|
import { finalizeTool } from "../tools/tool-defaults.js";
|
|
37
47
|
import type { Tool, ToolDefinition } from "../tools/types.js";
|
|
38
48
|
import { getLogger } from "../util/logger.js";
|
|
39
|
-
import {
|
|
49
|
+
import { getWorkspacePluginsDir } from "../util/platform.js";
|
|
40
50
|
import { APP_VERSION } from "../version.js";
|
|
41
51
|
import {
|
|
42
52
|
deriveToolName,
|
|
43
|
-
importDefault,
|
|
44
53
|
listSurfaceDir,
|
|
45
54
|
parsePluginManifest,
|
|
46
55
|
} from "./external-plugin-loader.js";
|
|
56
|
+
import {
|
|
57
|
+
clearSurfaceImportInflight,
|
|
58
|
+
getMtime,
|
|
59
|
+
importWithTimeout,
|
|
60
|
+
setSurfaceImportTimeout,
|
|
61
|
+
} from "./surface-import.js";
|
|
47
62
|
|
|
48
63
|
// Re-export for type compat — consumers that import PluginHookFn from
|
|
49
64
|
// the mtime cache module still resolve.
|
|
@@ -51,13 +66,6 @@ export type { PluginHookFn } from "./types.js";
|
|
|
51
66
|
|
|
52
67
|
const log = getLogger("plugin-mtime-cache");
|
|
53
68
|
|
|
54
|
-
/**
|
|
55
|
-
* Import timeout for surface file imports. Set by `populateCacheAtBoot` from
|
|
56
|
-
* the value passed by `loadUserPlugins`, and used by `getUserHooksFor` and
|
|
57
|
-
* `reconcilePluginTools` for runtime re-imports. Defaults to 10s.
|
|
58
|
-
*/
|
|
59
|
-
let importTimeoutMs = 10_000;
|
|
60
|
-
|
|
61
69
|
/**
|
|
62
70
|
* Cached install-date timestamps per plugin directory, so `scanPlugins`
|
|
63
71
|
* doesn't re-read `install-meta.json` on every turn. Populated on first
|
|
@@ -130,16 +138,6 @@ function getInstallDate(pluginDir: string): number {
|
|
|
130
138
|
|
|
131
139
|
// ─── Cache entries ───────────────────────────────────────────────────────────
|
|
132
140
|
|
|
133
|
-
/**
|
|
134
|
-
* A cached hook function plus the mtime of its source file. When the on-disk
|
|
135
|
-
* mtime changes, the hook is re-imported and the entry is replaced.
|
|
136
|
-
*/
|
|
137
|
-
interface CachedHook {
|
|
138
|
-
readonly hook: PluginHookFn;
|
|
139
|
-
/** mtimeMs of the source file this hook was imported from. */
|
|
140
|
-
readonly sourceMtime: number;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
141
|
/**
|
|
144
142
|
* A cached tool plus the mtime of its source file. When the on-disk mtime
|
|
145
143
|
* changes, the tool is re-imported, the old tool is unregistered from the
|
|
@@ -155,25 +153,12 @@ interface CachedTool {
|
|
|
155
153
|
|
|
156
154
|
// ─── Internal state ──────────────────────────────────────────────────────────
|
|
157
155
|
|
|
158
|
-
/**
|
|
159
|
-
* Cached hooks keyed by `${pluginName}/${hookName}`. The key includes the
|
|
160
|
-
* plugin name so hooks from different plugins don't collide.
|
|
161
|
-
*/
|
|
162
|
-
const hookCache = new Map<string, CachedHook>();
|
|
163
|
-
|
|
164
156
|
/**
|
|
165
157
|
* Cached tools keyed by `${pluginName}/${toolName}`. The key includes the
|
|
166
158
|
* plugin name so tools from different plugins don't collide.
|
|
167
159
|
*/
|
|
168
160
|
const toolCache = new Map<string, CachedTool>();
|
|
169
161
|
|
|
170
|
-
/**
|
|
171
|
-
* In-flight import promises, keyed by file path. Prevents duplicate
|
|
172
|
-
* `import()` calls when multiple readers request the same surface
|
|
173
|
-
* concurrently.
|
|
174
|
-
*/
|
|
175
|
-
const inflight = new Map<string, Promise<unknown>>();
|
|
176
|
-
|
|
177
162
|
/**
|
|
178
163
|
* Plugin directories discovered at boot, in discovery order. Maps directory
|
|
179
164
|
* path to the plugin's scope-stripped manifest name so eviction can find
|
|
@@ -189,94 +174,19 @@ const discoveredPluginDirs = new Map<string, string>();
|
|
|
189
174
|
*/
|
|
190
175
|
const disabledPluginDirs = new Set<string>();
|
|
191
176
|
|
|
192
|
-
// ───
|
|
177
|
+
// ─── Hook reads ──────────────────────────────────────────────────────────────
|
|
193
178
|
|
|
194
179
|
/**
|
|
195
|
-
* Get
|
|
196
|
-
*
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
return statSync(filePath).mtimeMs;
|
|
201
|
-
} catch {
|
|
202
|
-
return 0;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// ─── Hook cache ──────────────────────────────────────────────────────────────
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Cache key for a hook: `${pluginName}/${hookName}`.
|
|
210
|
-
*/
|
|
211
|
-
function hookKey(pluginName: string, hookName: string): string {
|
|
212
|
-
return `${pluginName}/${hookName}`;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Get all hooks for a given event name from user plugins, re-importing
|
|
217
|
-
* any whose source files have changed since the cache was populated.
|
|
218
|
-
*
|
|
219
|
-
* Also scans for newly added plugins and hooks (via directory listing).
|
|
220
|
-
* Deleted plugins/hooks are skipped naturally (their directories/files
|
|
221
|
-
* no longer appear in the listing).
|
|
180
|
+
* Get all hooks for a given event name from user plugins and standalone
|
|
181
|
+
* workspace hooks. Refreshes plugin discovery first, then delegates the actual
|
|
182
|
+
* hook resolution to the hook loader. Plugin hooks run in install-date order,
|
|
183
|
+
* the workspace hook runs last.
|
|
222
184
|
*/
|
|
223
185
|
export async function getUserHooksFor<TCtx = unknown>(
|
|
224
186
|
hookName: string,
|
|
225
187
|
): Promise<PluginHookFn<TCtx>[]> {
|
|
226
188
|
await scanPlugins();
|
|
227
|
-
|
|
228
|
-
const out: PluginHookFn<TCtx>[] = [];
|
|
229
|
-
|
|
230
|
-
for (const [pluginDir, pluginName] of discoveredPluginDirs) {
|
|
231
|
-
const hooksDir = join(pluginDir, "hooks");
|
|
232
|
-
const surfaceFiles = listSurfaceDir(hooksDir);
|
|
233
|
-
const hookFile = surfaceFiles.find((f) => f.name === hookName);
|
|
234
|
-
if (hookFile === undefined) continue;
|
|
235
|
-
|
|
236
|
-
const key = hookKey(pluginName, hookName);
|
|
237
|
-
const currentMtime = getMtime(hookFile.path);
|
|
238
|
-
|
|
239
|
-
// Cache hit — same mtime.
|
|
240
|
-
const cached = hookCache.get(key);
|
|
241
|
-
if (
|
|
242
|
-
cached !== undefined &&
|
|
243
|
-
cached.sourceMtime === currentMtime &&
|
|
244
|
-
currentMtime > 0
|
|
245
|
-
) {
|
|
246
|
-
out.push(cached.hook as PluginHookFn<TCtx>);
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Cache miss — re-import.
|
|
251
|
-
if (currentMtime === 0) {
|
|
252
|
-
// File was deleted — evict cache entry.
|
|
253
|
-
hookCache.delete(key);
|
|
254
|
-
continue;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
try {
|
|
258
|
-
const hook = await importWithTimeout<PluginHookFn>(
|
|
259
|
-
hookFile.path,
|
|
260
|
-
importTimeoutMs,
|
|
261
|
-
);
|
|
262
|
-
if (hook === undefined || typeof hook !== "function") {
|
|
263
|
-
log.error(
|
|
264
|
-
{ plugin: pluginName, hook: hookName, path: hookFile.path },
|
|
265
|
-
`hook ${hookName} default export must be a function (got ${typeof hook}) — skipping`,
|
|
266
|
-
);
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
hookCache.set(key, { hook, sourceMtime: currentMtime });
|
|
270
|
-
out.push(hook as PluginHookFn<TCtx>);
|
|
271
|
-
} catch (err) {
|
|
272
|
-
log.error(
|
|
273
|
-
{ err, plugin: pluginName, hook: hookName, path: hookFile.path },
|
|
274
|
-
`Failed to import hook ${hookName} from ${hookFile.path}`,
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return out;
|
|
189
|
+
return collectUserHooks<TCtx>(hookName, discoveredPluginDirs);
|
|
280
190
|
}
|
|
281
191
|
|
|
282
192
|
// ─── Tool cache ──────────────────────────────────────────────────────────────
|
|
@@ -326,10 +236,7 @@ async function reconcilePluginTools(
|
|
|
326
236
|
}
|
|
327
237
|
|
|
328
238
|
try {
|
|
329
|
-
const toolSpec = await importWithTimeout<ToolDefinition>(
|
|
330
|
-
file.path,
|
|
331
|
-
importTimeoutMs,
|
|
332
|
-
);
|
|
239
|
+
const toolSpec = await importWithTimeout<ToolDefinition>(file.path);
|
|
333
240
|
if (
|
|
334
241
|
toolSpec === undefined ||
|
|
335
242
|
toolSpec === null ||
|
|
@@ -470,17 +377,13 @@ async function evictPlugin(
|
|
|
470
377
|
pluginDir: string,
|
|
471
378
|
pluginName: string,
|
|
472
379
|
): Promise<void> {
|
|
473
|
-
// Evict hooks.
|
|
474
|
-
|
|
475
|
-
for (const key of hookCache.keys()) {
|
|
476
|
-
if (key.startsWith(hookPrefix)) {
|
|
477
|
-
hookCache.delete(key);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
380
|
+
// Evict hooks (owned by the hook loader).
|
|
381
|
+
evictHooksForOwner(pluginName);
|
|
480
382
|
|
|
481
383
|
// Evict tools.
|
|
384
|
+
const toolPrefix = `${pluginName}/`;
|
|
482
385
|
for (const key of toolCache.keys()) {
|
|
483
|
-
if (key.startsWith(
|
|
386
|
+
if (key.startsWith(toolPrefix)) {
|
|
484
387
|
toolCache.delete(key);
|
|
485
388
|
}
|
|
486
389
|
}
|
|
@@ -494,83 +397,30 @@ async function evictPlugin(
|
|
|
494
397
|
}
|
|
495
398
|
|
|
496
399
|
/**
|
|
497
|
-
* Evict all cache entries (when the plugins directory is gone
|
|
400
|
+
* Evict all plugin-owned cache entries (when the plugins directory is gone
|
|
401
|
+
* entirely). Standalone workspace hooks are preserved by the hook loader:
|
|
402
|
+
* they live outside the plugins directory, so the absence of any plugin must
|
|
403
|
+
* not evict them.
|
|
498
404
|
*/
|
|
499
405
|
async function evictAll(): Promise<void> {
|
|
500
|
-
|
|
406
|
+
clearPluginHooks();
|
|
501
407
|
toolCache.clear();
|
|
502
408
|
discoveredPluginDirs.clear();
|
|
503
409
|
installDateCache.clear();
|
|
504
410
|
disabledPluginDirs.clear();
|
|
505
411
|
}
|
|
506
412
|
|
|
507
|
-
// ─── Import dedup ────────────────────────────────────────────────────────────
|
|
508
|
-
|
|
509
|
-
/**
|
|
510
|
-
* Import a module's default export with a timeout. If the import doesn't
|
|
511
|
-
* resolve within `timeoutMs`, logs a warning and returns `undefined` so
|
|
512
|
-
* a hanging plugin module doesn't block daemon startup indefinitely.
|
|
513
|
-
*/
|
|
514
|
-
async function importWithTimeout<T>(
|
|
515
|
-
filePath: string,
|
|
516
|
-
timeoutMs: number,
|
|
517
|
-
): Promise<T | undefined> {
|
|
518
|
-
let timeoutHandle: ReturnType<typeof setTimeout> | undefined;
|
|
519
|
-
try {
|
|
520
|
-
const timeoutSentinel = Symbol("import-timeout");
|
|
521
|
-
const importPromise = importWithDedup<T>(filePath);
|
|
522
|
-
const timeoutPromise = new Promise<typeof timeoutSentinel>((resolve) => {
|
|
523
|
-
timeoutHandle = setTimeout(() => resolve(timeoutSentinel), timeoutMs);
|
|
524
|
-
});
|
|
525
|
-
const result = await Promise.race([importPromise, timeoutPromise]);
|
|
526
|
-
if (result === timeoutSentinel) {
|
|
527
|
-
importPromise.catch(() => {
|
|
528
|
-
/* swallow — late rejection from abandoned import */
|
|
529
|
-
});
|
|
530
|
-
log.warn(
|
|
531
|
-
{ filePath, timeoutMs },
|
|
532
|
-
`Import timed out after ${timeoutMs}ms — skipping surface`,
|
|
533
|
-
);
|
|
534
|
-
return undefined;
|
|
535
|
-
}
|
|
536
|
-
return result as T;
|
|
537
|
-
} finally {
|
|
538
|
-
if (timeoutHandle !== undefined) clearTimeout(timeoutHandle);
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* Import a module's default export, deduplicating concurrent imports for
|
|
544
|
-
* the same file path. This prevents two readers from triggering duplicate
|
|
545
|
-
* `import()` calls when they request the same surface simultaneously.
|
|
546
|
-
*
|
|
547
|
-
* Note: Bun caches `import()` by URL within a process, so the dedup is
|
|
548
|
-
* primarily about avoiding redundant async work, not about cache-busting.
|
|
549
|
-
*/
|
|
550
|
-
async function importWithDedup<T>(filePath: string): Promise<T> {
|
|
551
|
-
let promise = inflight.get(filePath);
|
|
552
|
-
if (promise === undefined) {
|
|
553
|
-
promise = importDefault<T>(filePath);
|
|
554
|
-
inflight.set(filePath, promise);
|
|
555
|
-
}
|
|
556
|
-
try {
|
|
557
|
-
return (await promise) as T;
|
|
558
|
-
} finally {
|
|
559
|
-
inflight.delete(filePath);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
|
|
563
413
|
// ─── Boot population ─────────────────────────────────────────────────────────
|
|
564
414
|
|
|
565
415
|
/**
|
|
566
|
-
* Plugins that were fully activated at
|
|
567
|
-
* run). Used by the shutdown hook to tear
|
|
568
|
-
* brought up.
|
|
416
|
+
* Plugins (and the workspace-hooks pseudo-owner) that were fully activated at
|
|
417
|
+
* boot (tools registered + init hook run). Used by the shutdown hook to tear
|
|
418
|
+
* down only what was actually brought up.
|
|
569
419
|
*/
|
|
570
420
|
const activatedPlugins: Array<{ name: string }> = [];
|
|
571
421
|
|
|
572
422
|
/**
|
|
573
|
-
* Populate the
|
|
423
|
+
* Populate the caches at boot by scanning the plugins directory once,
|
|
574
424
|
* importing all surfaces, registering tools into the tool registry,
|
|
575
425
|
* running `init` hooks, and installing a shutdown hook.
|
|
576
426
|
*
|
|
@@ -587,7 +437,7 @@ export async function populateCacheAtBoot(
|
|
|
587
437
|
opts: { importTimeoutMs?: number } = {},
|
|
588
438
|
): Promise<void> {
|
|
589
439
|
if (opts.importTimeoutMs !== undefined) {
|
|
590
|
-
|
|
440
|
+
setSurfaceImportTimeout(opts.importTimeoutMs);
|
|
591
441
|
}
|
|
592
442
|
|
|
593
443
|
await scanPlugins();
|
|
@@ -598,28 +448,7 @@ export async function populateCacheAtBoot(
|
|
|
598
448
|
|
|
599
449
|
for (const [pluginDir, pluginName] of discoveredPluginDirs) {
|
|
600
450
|
// Pre-import all hooks so the first turn doesn't pay the import cost.
|
|
601
|
-
|
|
602
|
-
const hookFiles = listSurfaceDir(hooksDir);
|
|
603
|
-
for (const file of hookFiles) {
|
|
604
|
-
const key = hookKey(pluginName, file.name);
|
|
605
|
-
const currentMtime = getMtime(file.path);
|
|
606
|
-
if (currentMtime === 0) continue;
|
|
607
|
-
|
|
608
|
-
try {
|
|
609
|
-
const hook = await importWithTimeout<PluginHookFn>(
|
|
610
|
-
file.path,
|
|
611
|
-
importTimeoutMs,
|
|
612
|
-
);
|
|
613
|
-
if (hook !== undefined && typeof hook === "function") {
|
|
614
|
-
hookCache.set(key, { hook, sourceMtime: currentMtime });
|
|
615
|
-
}
|
|
616
|
-
} catch (err) {
|
|
617
|
-
log.error(
|
|
618
|
-
{ err, plugin: pluginName, hook: file.name, path: file.path },
|
|
619
|
-
`Failed to pre-import hook ${file.name}`,
|
|
620
|
-
);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
451
|
+
await preImportHooksDir(join(pluginDir, "hooks"), pluginName);
|
|
623
452
|
|
|
624
453
|
// Register user plugin tools into the global tool registry so
|
|
625
454
|
// `getAllTools()` and `getTool()` can find them. Tools were already
|
|
@@ -643,38 +472,33 @@ export async function populateCacheAtBoot(
|
|
|
643
472
|
}
|
|
644
473
|
|
|
645
474
|
// Run the `init` hook if present.
|
|
646
|
-
|
|
647
|
-
if (initHookEntry !== undefined) {
|
|
648
|
-
try {
|
|
649
|
-
const initContext: PluginInitContext = {
|
|
650
|
-
config: getConfig().plugins?.[pluginName],
|
|
651
|
-
credentials: {},
|
|
652
|
-
logger: log.child({ plugin: pluginName }),
|
|
653
|
-
pluginStorageDir: ensurePluginStorageDir(pluginName),
|
|
654
|
-
assistantVersion: APP_VERSION,
|
|
655
|
-
};
|
|
656
|
-
await initHookEntry.hook(initContext);
|
|
657
|
-
log.info({ plugin: pluginName }, "user plugin initialized");
|
|
658
|
-
} catch (err) {
|
|
659
|
-
log.error(
|
|
660
|
-
{ err, plugin: pluginName },
|
|
661
|
-
`User plugin ${pluginName} init() failed — continuing`,
|
|
662
|
-
);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
475
|
+
await runInitHook(pluginName);
|
|
665
476
|
|
|
666
477
|
activatedPlugins.push({ name: pluginName });
|
|
667
478
|
}
|
|
668
479
|
|
|
669
|
-
//
|
|
670
|
-
//
|
|
480
|
+
// Activate standalone workspace hooks under `<workspace>/hooks/`. These
|
|
481
|
+
// carry no package.json, no tools, and no install-date ordering — just hook
|
|
482
|
+
// files. Pre-import them and run their `init` hook so a workspace-wide
|
|
483
|
+
// `init`/`shutdown` lifecycle works the same way a plugin's does. Only
|
|
484
|
+
// register for teardown when at least one hook file is actually present, so
|
|
485
|
+
// an empty/absent directory adds no shutdown work.
|
|
486
|
+
if (hasWorkspaceHooks()) {
|
|
487
|
+
await preImportWorkspaceHooks();
|
|
488
|
+
await runInitHook(WORKSPACE_HOOKS_OWNER);
|
|
489
|
+
activatedPlugins.push({ name: WORKSPACE_HOOKS_OWNER });
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// Register a single shutdown hook that walks all activated owners in reverse
|
|
493
|
+
// order, unregistering tools and running shutdown hooks.
|
|
671
494
|
const shutdownSnapshot = [...activatedPlugins];
|
|
672
495
|
registerShutdownHook("user-plugins", async (reason) => {
|
|
673
496
|
for (let i = shutdownSnapshot.length - 1; i >= 0; i--) {
|
|
674
497
|
const { name } = shutdownSnapshot[i]!;
|
|
675
498
|
|
|
676
499
|
// Unregister tools before running shutdown so onShutdown sees a
|
|
677
|
-
// clean model-visible surface.
|
|
500
|
+
// clean model-visible surface. (No-op for the workspace-hooks owner,
|
|
501
|
+
// which registers no tools.)
|
|
678
502
|
try {
|
|
679
503
|
unregisterPluginTools(name);
|
|
680
504
|
} catch (err) {
|
|
@@ -685,30 +509,11 @@ export async function populateCacheAtBoot(
|
|
|
685
509
|
}
|
|
686
510
|
|
|
687
511
|
// Run the `shutdown` hook if present.
|
|
688
|
-
|
|
689
|
-
if (shutdownHookEntry !== undefined) {
|
|
690
|
-
try {
|
|
691
|
-
await shutdownHookEntry.hook(shutdownContext);
|
|
692
|
-
} catch (err) {
|
|
693
|
-
log.warn(
|
|
694
|
-
{ err, plugin: name, reason },
|
|
695
|
-
"user plugin shutdown hook failed (continuing)",
|
|
696
|
-
);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
512
|
+
await runShutdownHook(name, shutdownContext, reason);
|
|
699
513
|
}
|
|
700
514
|
});
|
|
701
515
|
}
|
|
702
516
|
|
|
703
|
-
/**
|
|
704
|
-
* Ensure `<workspaceDir>/plugins-data/<name>/` exists and return its path.
|
|
705
|
-
*/
|
|
706
|
-
function ensurePluginStorageDir(pluginName: string): string {
|
|
707
|
-
const dir = join(getWorkspaceDir(), "plugins-data", pluginName);
|
|
708
|
-
mkdirSync(dir, { recursive: true });
|
|
709
|
-
return dir;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
517
|
// ─── Test hooks ──────────────────────────────────────────────────────────────
|
|
713
518
|
|
|
714
519
|
/**
|
|
@@ -722,35 +527,15 @@ export function resetPluginCacheForTests(): void {
|
|
|
722
527
|
"resetPluginCacheForTests may only be called in test environments",
|
|
723
528
|
);
|
|
724
529
|
}
|
|
725
|
-
|
|
530
|
+
resetHookCacheForTests();
|
|
531
|
+
clearSurfaceImportInflight();
|
|
726
532
|
toolCache.clear();
|
|
727
|
-
inflight.clear();
|
|
728
533
|
discoveredPluginDirs.clear();
|
|
729
534
|
installDateCache.clear();
|
|
730
535
|
activatedPlugins.length = 0;
|
|
731
536
|
disabledPluginDirs.clear();
|
|
732
537
|
}
|
|
733
538
|
|
|
734
|
-
/**
|
|
735
|
-
* Test-only: inspect the hook cache.
|
|
736
|
-
*/
|
|
737
|
-
export function _inspectHookCacheForTests(): Array<{
|
|
738
|
-
key: string;
|
|
739
|
-
sourceMtime: number;
|
|
740
|
-
}> {
|
|
741
|
-
const isTest =
|
|
742
|
-
process.env.BUN_TEST === "1" || process.env.NODE_ENV === "test";
|
|
743
|
-
if (!isTest) {
|
|
744
|
-
throw new Error(
|
|
745
|
-
"_inspectHookCacheForTests may only be called in test environments",
|
|
746
|
-
);
|
|
747
|
-
}
|
|
748
|
-
return Array.from(hookCache.entries()).map(([key, c]) => ({
|
|
749
|
-
key,
|
|
750
|
-
sourceMtime: c.sourceMtime,
|
|
751
|
-
}));
|
|
752
|
-
}
|
|
753
|
-
|
|
754
539
|
/**
|
|
755
540
|
* Test-only: inspect the tool cache.
|
|
756
541
|
*/
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared low-level import machinery for user-surface files (plugin tools,
|
|
3
|
+
* plugin hooks, and standalone workspace hooks).
|
|
4
|
+
*
|
|
5
|
+
* Both the plugin/tool cache (`mtime-cache.ts`) and the hook cache
|
|
6
|
+
* (`../hooks/hook-loader.ts`) re-import surface files keyed by mtime. This
|
|
7
|
+
* module owns the pieces they share — mtime stat, the per-process import
|
|
8
|
+
* timeout, and a timeout-guarded, concurrency-deduplicated dynamic import —
|
|
9
|
+
* so neither surface duplicates the logic and the import-timeout knob is
|
|
10
|
+
* configured in exactly one place.
|
|
11
|
+
*
|
|
12
|
+
* Kept dependency-light (only the logger and `importDefault`) so it can sit
|
|
13
|
+
* below both caches without introducing an import cycle.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { statSync } from "node:fs";
|
|
17
|
+
|
|
18
|
+
import { getLogger } from "../util/logger.js";
|
|
19
|
+
import { importDefault } from "./external-plugin-loader.js";
|
|
20
|
+
|
|
21
|
+
const log = getLogger("surface-import");
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Per-process upper bound on how long a single surface import may take.
|
|
25
|
+
* Set once at boot by `populateCacheAtBoot`; read by every re-import. A
|
|
26
|
+
* plugin/hook with a hanging top-level `await` is skipped rather than
|
|
27
|
+
* blocking the daemon.
|
|
28
|
+
*/
|
|
29
|
+
let importTimeoutMs = 10_000;
|
|
30
|
+
|
|
31
|
+
/** Override the surface import timeout (called once at boot). */
|
|
32
|
+
export function setSurfaceImportTimeout(ms: number): void {
|
|
33
|
+
importTimeoutMs = ms;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Current surface import timeout in milliseconds. */
|
|
37
|
+
export function getSurfaceImportTimeout(): number {
|
|
38
|
+
return importTimeoutMs;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get the mtimeMs of a file, or 0 if the file doesn't exist or can't be
|
|
43
|
+
* stat'd. Callers treat 0 as "absent" (cache-evict / skip).
|
|
44
|
+
*/
|
|
45
|
+
export function getMtime(filePath: string): number {
|
|
46
|
+
try {
|
|
47
|
+
return statSync(filePath).mtimeMs;
|
|
48
|
+
} catch {
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* In-flight import promises, keyed by file path. Prevents duplicate
|
|
55
|
+
* `import()` calls when multiple readers request the same surface
|
|
56
|
+
* concurrently.
|
|
57
|
+
*/
|
|
58
|
+
const inflight = new Map<string, Promise<unknown>>();
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Import a module's default export with a timeout. If the import doesn't
|
|
62
|
+
* resolve within `timeoutMs`, logs a warning and returns `undefined` so a
|
|
63
|
+
* hanging module doesn't block daemon startup indefinitely. Defaults to the
|
|
64
|
+
* module-level {@link getSurfaceImportTimeout}.
|
|
65
|
+
*/
|
|
66
|
+
export async function importWithTimeout<T>(
|
|
67
|
+
filePath: string,
|
|
68
|
+
timeoutMs: number = importTimeoutMs,
|
|
69
|
+
): Promise<T | undefined> {
|
|
70
|
+
let timeoutHandle: ReturnType<typeof setTimeout> | undefined;
|
|
71
|
+
try {
|
|
72
|
+
const timeoutSentinel = Symbol("import-timeout");
|
|
73
|
+
const importPromise = importWithDedup<T>(filePath);
|
|
74
|
+
const timeoutPromise = new Promise<typeof timeoutSentinel>((resolve) => {
|
|
75
|
+
timeoutHandle = setTimeout(() => resolve(timeoutSentinel), timeoutMs);
|
|
76
|
+
});
|
|
77
|
+
const result = await Promise.race([importPromise, timeoutPromise]);
|
|
78
|
+
if (result === timeoutSentinel) {
|
|
79
|
+
importPromise.catch(() => {
|
|
80
|
+
/* swallow — late rejection from abandoned import */
|
|
81
|
+
});
|
|
82
|
+
log.warn(
|
|
83
|
+
{ filePath, timeoutMs },
|
|
84
|
+
`Import timed out after ${timeoutMs}ms — skipping surface`,
|
|
85
|
+
);
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
return result as T;
|
|
89
|
+
} finally {
|
|
90
|
+
if (timeoutHandle !== undefined) clearTimeout(timeoutHandle);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Import a module's default export, deduplicating concurrent imports for
|
|
96
|
+
* the same file path. This prevents two readers from triggering duplicate
|
|
97
|
+
* `import()` calls when they request the same surface simultaneously.
|
|
98
|
+
*
|
|
99
|
+
* Note: Bun caches `import()` by resolved path within a process and does not
|
|
100
|
+
* bust on query-string or hash changes, so the dedup is about avoiding
|
|
101
|
+
* redundant async work, not cache-busting. A content edit to an existing
|
|
102
|
+
* file is only picked up after a process restart (added and removed files
|
|
103
|
+
* are picked up live, since discovery is by directory listing).
|
|
104
|
+
*/
|
|
105
|
+
async function importWithDedup<T>(filePath: string): Promise<T> {
|
|
106
|
+
let promise = inflight.get(filePath);
|
|
107
|
+
if (promise === undefined) {
|
|
108
|
+
promise = importDefault<T>(filePath);
|
|
109
|
+
inflight.set(filePath, promise);
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
return (await promise) as T;
|
|
113
|
+
} finally {
|
|
114
|
+
inflight.delete(filePath);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Clear in-flight import state. Test-only. */
|
|
119
|
+
export function clearSurfaceImportInflight(): void {
|
|
120
|
+
inflight.clear();
|
|
121
|
+
}
|
package/src/plugins/types.ts
CHANGED
|
@@ -47,8 +47,6 @@ export interface PluginManifest {
|
|
|
47
47
|
* own version at load time.
|
|
48
48
|
*/
|
|
49
49
|
version: string;
|
|
50
|
-
/** Credential keys the plugin needs resolved before `init()` runs. */
|
|
51
|
-
requiresCredential?: string[];
|
|
52
50
|
/**
|
|
53
51
|
* Assistant feature-flag keys that must all be enabled for this plugin to
|
|
54
52
|
* activate. Checked by `bootstrapPlugins` via `isAssistantFeatureFlagEnabled`
|
|
@@ -786,6 +786,11 @@ export class AnthropicProvider implements Provider {
|
|
|
786
786
|
this.useNativeWebSearch = options.useNativeWebSearch ?? false;
|
|
787
787
|
}
|
|
788
788
|
|
|
789
|
+
/** See {@link Provider.supportsNativeWebSearch}. */
|
|
790
|
+
get supportsNativeWebSearch(): boolean {
|
|
791
|
+
return this.useNativeWebSearch;
|
|
792
|
+
}
|
|
793
|
+
|
|
789
794
|
async sendMessage(
|
|
790
795
|
messages: Message[],
|
|
791
796
|
options?: SendMessageOptions,
|
|
@@ -43,6 +43,9 @@ import type {
|
|
|
43
43
|
|
|
44
44
|
export class CallSiteRoutingProvider implements Provider {
|
|
45
45
|
public readonly tokenEstimationProvider?: string;
|
|
46
|
+
// Forward native web-search capability so it survives the wrapper chain
|
|
47
|
+
// (callers like the advisor consult gate on it). Fixed at construction.
|
|
48
|
+
public readonly supportsNativeWebSearch?: boolean;
|
|
46
49
|
|
|
47
50
|
// Per-call async context that tracks which provider is currently executing.
|
|
48
51
|
// Using AsyncLocalStorage instead of a plain instance field means concurrent
|
|
@@ -94,6 +97,7 @@ export class CallSiteRoutingProvider implements Provider {
|
|
|
94
97
|
) => Promise<Provider | null>,
|
|
95
98
|
) {
|
|
96
99
|
this.tokenEstimationProvider = defaultProvider.tokenEstimationProvider;
|
|
100
|
+
this.supportsNativeWebSearch = defaultProvider.supportsNativeWebSearch;
|
|
97
101
|
if (defaultProvider.countInputTokens) {
|
|
98
102
|
this.countInputTokens =
|
|
99
103
|
defaultProvider.countInputTokens.bind(defaultProvider);
|