comisai 1.0.34 → 1.0.37
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/node_modules/@comis/agent/dist/background/auto-background-middleware.d.ts +11 -1
- package/node_modules/@comis/agent/dist/background/auto-background-middleware.js +30 -4
- package/node_modules/@comis/agent/dist/background/background-task-manager.d.ts +22 -2
- package/node_modules/@comis/agent/dist/background/background-task-manager.js +88 -40
- package/node_modules/@comis/agent/dist/background/background-task-persistence.js +34 -4
- package/node_modules/@comis/agent/dist/background/background-task-types.d.ts +59 -3
- package/node_modules/@comis/agent/dist/background/background-task-types.js +1 -1
- package/node_modules/@comis/agent/dist/background/completion-dispatcher.d.ts +130 -0
- package/node_modules/@comis/agent/dist/background/completion-dispatcher.js +215 -0
- package/node_modules/@comis/agent/dist/background/completion-formatter.d.ts +39 -0
- package/node_modules/@comis/agent/dist/background/completion-formatter.js +77 -0
- package/node_modules/@comis/agent/dist/background/completion-runner.d.ts +62 -0
- package/node_modules/@comis/agent/dist/background/completion-runner.js +234 -0
- package/node_modules/@comis/agent/dist/background/index.d.ts +10 -1
- package/node_modules/@comis/agent/dist/background/index.js +4 -0
- package/node_modules/@comis/agent/dist/background/session-resolver.d.ts +85 -0
- package/node_modules/@comis/agent/dist/background/session-resolver.js +78 -0
- package/node_modules/@comis/agent/dist/bootstrap/sections/messaging-sections.js +1 -0
- package/node_modules/@comis/agent/dist/bootstrap/sections/tool-descriptions.js +3 -3
- package/node_modules/@comis/agent/dist/bootstrap/sections/tooling-sections.d.ts +30 -2
- package/node_modules/@comis/agent/dist/bootstrap/sections/tooling-sections.js +51 -2
- package/node_modules/@comis/agent/dist/bootstrap/system-prompt-assembler.d.ts +22 -0
- package/node_modules/@comis/agent/dist/bootstrap/system-prompt-assembler.js +2 -2
- package/node_modules/@comis/agent/dist/bridge/bridge-event-handlers.d.ts +1 -5
- package/node_modules/@comis/agent/dist/bridge/bridge-event-handlers.js +2 -14
- package/node_modules/@comis/agent/dist/bridge/bridge-metrics.d.ts +43 -2
- package/node_modules/@comis/agent/dist/bridge/bridge-metrics.js +17 -2
- package/node_modules/@comis/agent/dist/bridge/pi-event-bridge.d.ts +32 -23
- package/node_modules/@comis/agent/dist/bridge/pi-event-bridge.js +145 -62
- package/node_modules/@comis/agent/dist/bridge/thinking-block-hash-invariant.d.ts +6 -7
- package/node_modules/@comis/agent/dist/bridge/thinking-block-hash-invariant.js +24 -25
- package/node_modules/@comis/agent/dist/budget/cost-tracker.d.ts +1 -1
- package/node_modules/@comis/agent/dist/context-engine/constants.d.ts +5 -5
- package/node_modules/@comis/agent/dist/context-engine/constants.js +12 -12
- package/node_modules/@comis/agent/dist/context-engine/context-engine.js +13 -4
- package/node_modules/@comis/agent/dist/context-engine/dag-annotator.d.ts +1 -2
- package/node_modules/@comis/agent/dist/context-engine/dag-annotator.js +1 -2
- package/node_modules/@comis/agent/dist/context-engine/llm-compaction.js +20 -16
- package/node_modules/@comis/agent/dist/context-engine/rehydration.js +6 -6
- package/node_modules/@comis/agent/dist/context-engine/signature-replay-scrubber.d.ts +12 -12
- package/node_modules/@comis/agent/dist/context-engine/signature-replay-scrubber.js +36 -22
- package/node_modules/@comis/agent/dist/context-engine/signature-surrogate-guard.d.ts +10 -10
- package/node_modules/@comis/agent/dist/context-engine/signature-surrogate-guard.js +14 -14
- package/node_modules/@comis/agent/dist/context-engine/thinking-block-cleaner.d.ts +11 -13
- package/node_modules/@comis/agent/dist/context-engine/thinking-block-cleaner.js +14 -15
- package/node_modules/@comis/agent/dist/context-engine/types-core.d.ts +15 -0
- package/node_modules/@comis/agent/dist/executor/cache-break-detection.d.ts +6 -6
- package/node_modules/@comis/agent/dist/executor/cache-break-detection.js +8 -8
- package/node_modules/@comis/agent/dist/executor/capability-index-context.d.ts +72 -0
- package/node_modules/@comis/agent/dist/executor/capability-index-context.js +329 -0
- package/node_modules/@comis/agent/dist/executor/drain-helper.d.ts +122 -0
- package/node_modules/@comis/agent/dist/executor/drain-helper.js +173 -0
- package/node_modules/@comis/agent/dist/executor/error-classifier.js +2 -2
- package/node_modules/@comis/agent/dist/executor/executor-context-engine-setup.d.ts +16 -0
- package/node_modules/@comis/agent/dist/executor/executor-context-engine-setup.js +46 -5
- package/node_modules/@comis/agent/dist/executor/executor-post-execution.d.ts +78 -4
- package/node_modules/@comis/agent/dist/executor/executor-post-execution.js +150 -31
- package/node_modules/@comis/agent/dist/executor/executor-prompt-runner.d.ts +7 -0
- package/node_modules/@comis/agent/dist/executor/executor-prompt-runner.js +26 -5
- package/node_modules/@comis/agent/dist/executor/executor-response-filter.d.ts +7 -6
- package/node_modules/@comis/agent/dist/executor/executor-response-filter.js +9 -42
- package/node_modules/@comis/agent/dist/executor/executor-tool-assembly.d.ts +18 -1
- package/node_modules/@comis/agent/dist/executor/executor-tool-assembly.js +20 -18
- package/node_modules/@comis/agent/dist/executor/gemini-cache-injector.d.ts +2 -2
- package/node_modules/@comis/agent/dist/executor/gemini-cache-injector.js +4 -4
- package/node_modules/@comis/agent/dist/executor/jit-guide-injector.d.ts +11 -2
- package/node_modules/@comis/agent/dist/executor/jit-guide-injector.js +16 -2
- package/node_modules/@comis/agent/dist/executor/phase-filter.d.ts +2 -2
- package/node_modules/@comis/agent/dist/executor/phase-filter.js +5 -7
- package/node_modules/@comis/agent/dist/executor/pi-executor.d.ts +21 -2
- package/node_modules/@comis/agent/dist/executor/pi-executor.js +96 -18
- package/node_modules/@comis/agent/dist/executor/post-batch-continuation.js +7 -7
- package/node_modules/@comis/agent/dist/executor/prompt-assembly.d.ts +9 -1
- package/node_modules/@comis/agent/dist/executor/prompt-assembly.js +15 -1
- package/node_modules/@comis/agent/dist/executor/stream-wrappers/request-body-injector.d.ts +1 -1
- package/node_modules/@comis/agent/dist/executor/stream-wrappers/request-body-injector.js +1 -1
- package/node_modules/@comis/agent/dist/executor/tool-deferral.d.ts +18 -27
- package/node_modules/@comis/agent/dist/executor/tool-deferral.js +34 -43
- package/node_modules/@comis/agent/dist/index.d.ts +17 -0
- package/node_modules/@comis/agent/dist/index.js +32 -11
- package/node_modules/@comis/agent/dist/model/auth-provider.d.ts +25 -2
- package/node_modules/@comis/agent/dist/model/auth-provider.js +6 -0
- package/node_modules/@comis/agent/dist/model/compaction-model-resolver.d.ts +3 -3
- package/node_modules/@comis/agent/dist/model/compaction-model-resolver.js +3 -3
- package/node_modules/@comis/agent/dist/model/model-registry-adapter.js +1 -1
- package/node_modules/@comis/agent/dist/model/model-scanner.js +1 -1
- package/node_modules/@comis/agent/dist/model/oauth-credential-store-file.d.ts +37 -0
- package/node_modules/@comis/agent/dist/model/oauth-credential-store-file.js +279 -0
- package/node_modules/@comis/agent/dist/model/oauth-credential-store-selector.d.ts +49 -0
- package/node_modules/@comis/agent/dist/model/oauth-credential-store-selector.js +50 -0
- package/node_modules/@comis/agent/dist/model/oauth-device-code.d.ts +57 -0
- package/node_modules/@comis/agent/dist/model/oauth-device-code.js +302 -0
- package/node_modules/@comis/agent/dist/model/oauth-env.d.ts +33 -0
- package/node_modules/@comis/agent/dist/model/oauth-env.js +38 -0
- package/node_modules/@comis/agent/dist/model/oauth-errors.d.ts +41 -0
- package/node_modules/@comis/agent/dist/model/oauth-errors.js +88 -0
- package/node_modules/@comis/agent/dist/model/oauth-identity.d.ts +53 -0
- package/node_modules/@comis/agent/dist/model/oauth-identity.js +141 -0
- package/node_modules/@comis/agent/dist/model/oauth-login-runner.d.ts +99 -0
- package/node_modules/@comis/agent/dist/model/oauth-login-runner.js +374 -0
- package/node_modules/@comis/agent/dist/model/oauth-tls-preflight.d.ts +58 -0
- package/node_modules/@comis/agent/dist/model/oauth-tls-preflight.js +82 -0
- package/node_modules/@comis/agent/dist/model/oauth-token-manager.d.ts +86 -16
- package/node_modules/@comis/agent/dist/model/oauth-token-manager.js +961 -66
- package/node_modules/@comis/agent/dist/model/operation-model-defaults.d.ts +9 -4
- package/node_modules/@comis/agent/dist/model/operation-model-defaults.js +36 -9
- package/node_modules/@comis/agent/dist/model/resolve-provider-api-key.d.ts +48 -0
- package/node_modules/@comis/agent/dist/model/resolve-provider-api-key.js +66 -0
- package/node_modules/@comis/agent/dist/provider/capabilities.d.ts +5 -5
- package/node_modules/@comis/agent/dist/provider/capabilities.js +10 -23
- package/node_modules/@comis/agent/dist/safety/tool-output-safety.js +3 -3
- package/node_modules/@comis/agent/dist/safety/tool-retry-breaker.d.ts +11 -1
- package/node_modules/@comis/agent/dist/safety/tool-retry-breaker.js +19 -22
- package/node_modules/@comis/agent/dist/session/comis-session-manager.d.ts +17 -3
- package/node_modules/@comis/agent/dist/session/comis-session-manager.js +1 -1
- package/node_modules/@comis/agent/dist/spawn/narrative-caster.d.ts +10 -0
- package/node_modules/@comis/agent/dist/spawn/narrative-caster.js +5 -1
- package/node_modules/@comis/agent/dist/spawn/pi-mono-adapters.d.ts +1 -1
- package/node_modules/@comis/agent/dist/spawn/pi-mono-adapters.js +5 -5
- package/node_modules/@comis/agent/dist/workspace/data-env.d.ts +38 -0
- package/node_modules/@comis/agent/dist/workspace/data-env.js +56 -0
- package/node_modules/@comis/agent/dist/workspace/index.d.ts +1 -0
- package/node_modules/@comis/agent/dist/workspace/index.js +1 -0
- package/node_modules/@comis/agent/dist/workspace/templates.js +5 -1
- package/node_modules/@comis/agent/package.json +1 -1
- package/node_modules/@comis/channels/dist/email/email-adapter.js +6 -6
- package/node_modules/@comis/channels/dist/email/imap-lifecycle.js +7 -7
- package/node_modules/@comis/channels/dist/index.d.ts +1 -1
- package/node_modules/@comis/channels/dist/index.js +1 -1
- package/node_modules/@comis/channels/dist/shared/channel-manager.d.ts +9 -3
- package/node_modules/@comis/channels/dist/shared/deliver-to-channel.js +12 -10
- package/node_modules/@comis/channels/dist/shared/inbound-gate.d.ts +1 -1
- package/node_modules/@comis/channels/dist/shared/inbound-gate.js +22 -7
- package/node_modules/@comis/channels/dist/shared/inbound-pipeline.d.ts +10 -3
- package/node_modules/@comis/channels/dist/shared/inbound-route.d.ts +1 -1
- package/node_modules/@comis/channels/dist/shared/inbound-route.js +13 -2
- package/node_modules/@comis/channels/dist/shared/response-filter.d.ts +11 -24
- package/node_modules/@comis/channels/dist/shared/response-filter.js +25 -53
- package/node_modules/@comis/channels/dist/telegram/telegram-adapter.js +1 -1
- package/node_modules/@comis/channels/package.json +1 -1
- package/node_modules/@comis/cli/dist/cli.js +2 -0
- package/node_modules/@comis/cli/dist/commands/agent.d.ts +3 -3
- package/node_modules/@comis/cli/dist/commands/agent.js +46 -3
- package/node_modules/@comis/cli/dist/commands/auth.d.ts +37 -0
- package/node_modules/@comis/cli/dist/commands/auth.js +433 -0
- package/node_modules/@comis/cli/dist/commands/doctor.d.ts +4 -1
- package/node_modules/@comis/cli/dist/commands/doctor.js +20 -5
- package/node_modules/@comis/cli/dist/commands/providers.d.ts +1 -2
- package/node_modules/@comis/cli/dist/commands/providers.js +5 -6
- package/node_modules/@comis/cli/dist/doctor/checks/oauth-health.d.ts +39 -0
- package/node_modules/@comis/cli/dist/doctor/checks/oauth-health.js +399 -0
- package/node_modules/@comis/cli/dist/doctor/types.d.ts +19 -0
- package/node_modules/@comis/cli/dist/index.d.ts +1 -0
- package/node_modules/@comis/cli/dist/index.js +10 -4
- package/node_modules/@comis/cli/dist/output/relative-time.d.ts +23 -0
- package/node_modules/@comis/cli/dist/output/relative-time.js +36 -0
- package/node_modules/@comis/cli/dist/wizard/non-interactive.js +17 -8
- package/node_modules/@comis/cli/dist/wizard/steps/03-provider.js +2 -1
- package/node_modules/@comis/cli/dist/wizard/steps/04-credentials.js +223 -34
- package/node_modules/@comis/cli/dist/wizard/steps/10-write-config.js +14 -0
- package/node_modules/@comis/cli/dist/wizard/steps/11-daemon-start.js +3 -3
- package/node_modules/@comis/cli/dist/wizard/types.d.ts +7 -0
- package/node_modules/@comis/cli/package.json +1 -1
- package/node_modules/@comis/core/dist/bootstrap.d.ts +1 -1
- package/node_modules/@comis/core/dist/config/env-substitution.d.ts +66 -0
- package/node_modules/@comis/core/dist/config/env-substitution.js +115 -0
- package/node_modules/@comis/core/dist/config/field-metadata.js +2 -0
- package/node_modules/@comis/core/dist/config/immutable-keys.js +4 -1
- package/node_modules/@comis/core/dist/config/index.d.ts +7 -1
- package/node_modules/@comis/core/dist/config/index.js +4 -1
- package/node_modules/@comis/core/dist/config/loader.js +61 -0
- package/node_modules/@comis/core/dist/config/managed-sections.d.ts +3 -3
- package/node_modules/@comis/core/dist/config/managed-sections.js +10 -5
- package/node_modules/@comis/core/dist/config/schema-agent.d.ts +4 -792
- package/node_modules/@comis/core/dist/config/schema-agent.js +16 -1
- package/node_modules/@comis/core/dist/config/schema-approvals.d.ts +0 -14
- package/node_modules/@comis/core/dist/config/schema-auto-reply-engine.d.ts +0 -6
- package/node_modules/@comis/core/dist/config/schema-background-tasks.d.ts +1 -6
- package/node_modules/@comis/core/dist/config/schema-background-tasks.js +7 -0
- package/node_modules/@comis/core/dist/config/schema-browser.d.ts +0 -18
- package/node_modules/@comis/core/dist/config/schema-channel.d.ts +0 -158
- package/node_modules/@comis/core/dist/config/schema-coalescer.d.ts +0 -5
- package/node_modules/@comis/core/dist/config/schema-daemon.d.ts +0 -32
- package/node_modules/@comis/core/dist/config/schema-delivery.d.ts +1 -17
- package/node_modules/@comis/core/dist/config/schema-delivery.js +2 -0
- package/node_modules/@comis/core/dist/config/schema-documentation.d.ts +0 -12
- package/node_modules/@comis/core/dist/config/schema-embedding.d.ts +0 -20
- package/node_modules/@comis/core/dist/config/schema-envelope.d.ts +0 -15
- package/node_modules/@comis/core/dist/config/schema-gateway.d.ts +0 -37
- package/node_modules/@comis/core/dist/config/schema-gemini-cache.d.ts +0 -4
- package/node_modules/@comis/core/dist/config/schema-gemini-cache.js +0 -2
- package/node_modules/@comis/core/dist/config/schema-integrations.d.ts +0 -318
- package/node_modules/@comis/core/dist/config/schema-lifecycle-reactions.d.ts +0 -18
- package/node_modules/@comis/core/dist/config/schema-memory-review.d.ts +0 -7
- package/node_modules/@comis/core/dist/config/schema-memory.d.ts +0 -16
- package/node_modules/@comis/core/dist/config/schema-messages.d.ts +0 -8
- package/node_modules/@comis/core/dist/config/schema-models.d.ts +0 -15
- package/node_modules/@comis/core/dist/config/schema-notification.d.ts +0 -5
- package/node_modules/@comis/core/dist/config/schema-oauth.d.ts +18 -0
- package/node_modules/@comis/core/dist/config/schema-oauth.js +19 -0
- package/node_modules/@comis/core/dist/config/schema-observability.d.ts +0 -38
- package/node_modules/@comis/core/dist/config/schema-output-retention.d.ts +34 -0
- package/node_modules/@comis/core/dist/config/schema-output-retention.js +48 -0
- package/node_modules/@comis/core/dist/config/schema-plugins.d.ts +0 -8
- package/node_modules/@comis/core/dist/config/schema-providers.d.ts +0 -64
- package/node_modules/@comis/core/dist/config/schema-queue.d.ts +0 -58
- package/node_modules/@comis/core/dist/config/schema-response-prefix.d.ts +0 -2
- package/node_modules/@comis/core/dist/config/schema-retry.d.ts +0 -6
- package/node_modules/@comis/core/dist/config/schema-scheduler.d.ts +0 -39
- package/node_modules/@comis/core/dist/config/schema-secrets.d.ts +0 -3
- package/node_modules/@comis/core/dist/config/schema-security.d.ts +0 -18
- package/node_modules/@comis/core/dist/config/schema-send-policy.d.ts +0 -13
- package/node_modules/@comis/core/dist/config/schema-sender-trust-display.d.ts +0 -5
- package/node_modules/@comis/core/dist/config/schema-serializer.js +2 -0
- package/node_modules/@comis/core/dist/config/schema-skills.d.ts +0 -63
- package/node_modules/@comis/core/dist/config/schema-skills.js +3 -4
- package/node_modules/@comis/core/dist/config/schema-streaming.d.ts +0 -38
- package/node_modules/@comis/core/dist/config/schema-telegram-file-guard.d.ts +0 -3
- package/node_modules/@comis/core/dist/config/schema-tooling.d.ts +87 -0
- package/node_modules/@comis/core/dist/config/schema-tooling.js +152 -0
- package/node_modules/@comis/core/dist/config/schema-verbosity.d.ts +0 -12
- package/node_modules/@comis/core/dist/config/schema-webhooks.d.ts +0 -40
- package/node_modules/@comis/core/dist/config/schema.d.ts +50 -37
- package/node_modules/@comis/core/dist/config/schema.js +9 -0
- package/node_modules/@comis/core/dist/context/context.d.ts +0 -4
- package/node_modules/@comis/core/dist/domain/approval-request.d.ts +0 -17
- package/node_modules/@comis/core/dist/domain/background-task-origin.d.ts +29 -0
- package/node_modules/@comis/core/dist/domain/background-task-origin.js +39 -0
- package/node_modules/@comis/core/dist/domain/delivery-origin.d.ts +0 -5
- package/node_modules/@comis/core/dist/domain/execution-graph.d.ts +0 -48
- package/node_modules/@comis/core/dist/domain/memory-entry.d.ts +0 -3
- package/node_modules/@comis/core/dist/domain/model-compat.d.ts +0 -4
- package/node_modules/@comis/core/dist/domain/normalized-message.d.ts +0 -15
- package/node_modules/@comis/core/dist/domain/provider-capabilities.d.ts +0 -6
- package/node_modules/@comis/core/dist/domain/rich-message.d.ts +0 -14
- package/node_modules/@comis/core/dist/domain/subagent-context-config.d.ts +0 -22
- package/node_modules/@comis/core/dist/domain/subagent-context-types.d.ts +0 -8
- package/node_modules/@comis/core/dist/event-bus/events-agent.d.ts +31 -0
- package/node_modules/@comis/core/dist/event-bus/events-infra.d.ts +76 -2
- package/node_modules/@comis/core/dist/exports/config.d.ts +2 -2
- package/node_modules/@comis/core/dist/exports/config.js +3 -1
- package/node_modules/@comis/core/dist/exports/domain.d.ts +2 -0
- package/node_modules/@comis/core/dist/exports/domain.js +1 -0
- package/node_modules/@comis/core/dist/exports/hooks.d.ts +1 -1
- package/node_modules/@comis/core/dist/exports/ports.d.ts +2 -2
- package/node_modules/@comis/core/dist/exports/ports.js +1 -1
- package/node_modules/@comis/core/dist/ports/channel-plugin.d.ts +0 -13
- package/node_modules/@comis/core/dist/ports/delivery-queue.d.ts +23 -0
- package/node_modules/@comis/core/dist/ports/delivery-queue.js +2 -0
- package/node_modules/@comis/core/dist/ports/index.d.ts +4 -0
- package/node_modules/@comis/core/dist/ports/index.js +5 -0
- package/node_modules/@comis/core/dist/ports/no-op-tool-capability.d.ts +30 -0
- package/node_modules/@comis/core/dist/ports/no-op-tool-capability.js +47 -0
- package/node_modules/@comis/core/dist/ports/oauth-credential-store.d.ts +64 -0
- package/node_modules/@comis/core/dist/ports/oauth-credential-store.js +37 -0
- package/node_modules/@comis/core/dist/ports/tool-capability.d.ts +165 -0
- package/node_modules/@comis/core/dist/ports/tool-capability.js +15 -0
- package/node_modules/@comis/core/dist/security/audit.d.ts +0 -11
- package/node_modules/@comis/core/dist/tool-metadata.d.ts +41 -1
- package/node_modules/@comis/core/dist/tool-metadata.js +1 -1
- package/node_modules/@comis/core/package.json +1 -1
- package/node_modules/@comis/daemon/bundled-skills/skill-creator/scripts/validate-skill.py +1 -1
- package/node_modules/@comis/daemon/dist/daemon-types.d.ts +23 -3
- package/node_modules/@comis/daemon/dist/daemon.js +168 -30
- package/node_modules/@comis/daemon/dist/index.d.ts +2 -0
- package/node_modules/@comis/daemon/dist/index.js +5 -0
- package/node_modules/@comis/daemon/dist/observability/channel-health-logger.js +3 -3
- package/node_modules/@comis/daemon/dist/observability/delivery-queue-logger.js +1 -1
- package/node_modules/@comis/daemon/dist/rpc/agent-handlers.d.ts +22 -1
- package/node_modules/@comis/daemon/dist/rpc/agent-handlers.js +84 -21
- package/node_modules/@comis/daemon/dist/rpc/agent-inline-workspace.d.ts +1 -1
- package/node_modules/@comis/daemon/dist/rpc/agent-inline-workspace.js +3 -3
- package/node_modules/@comis/daemon/dist/rpc/builtin-provider-guard.js +2 -2
- package/node_modules/@comis/daemon/dist/rpc/config-handlers.d.ts +9 -1
- package/node_modules/@comis/daemon/dist/rpc/config-handlers.js +104 -23
- package/node_modules/@comis/daemon/dist/rpc/credential-resolver.d.ts +30 -1
- package/node_modules/@comis/daemon/dist/rpc/credential-resolver.js +74 -11
- package/node_modules/@comis/daemon/dist/rpc/mcp-handlers.d.ts +8 -0
- package/node_modules/@comis/daemon/dist/rpc/mcp-handlers.js +22 -8
- package/node_modules/@comis/daemon/dist/rpc/model-handlers.d.ts +1 -1
- package/node_modules/@comis/daemon/dist/rpc/model-handlers.js +2 -2
- package/node_modules/@comis/daemon/dist/rpc/provider-handlers.js +9 -12
- package/node_modules/@comis/daemon/dist/rpc/rpc-dispatch.d.ts +1 -0
- package/node_modules/@comis/daemon/dist/rpc/rpc-dispatch.js +27 -2
- package/node_modules/@comis/daemon/dist/setup-docker-restart-warn.js +0 -1
- package/node_modules/@comis/daemon/dist/sub-agent-runner.d.ts +18 -0
- package/node_modules/@comis/daemon/dist/sub-agent-runner.js +41 -9
- package/node_modules/@comis/daemon/dist/wiring/index.d.ts +4 -0
- package/node_modules/@comis/daemon/dist/wiring/index.js +2 -0
- package/node_modules/@comis/daemon/dist/wiring/oauth-preflight.d.ts +21 -0
- package/node_modules/@comis/daemon/dist/wiring/oauth-preflight.js +134 -0
- package/node_modules/@comis/daemon/dist/wiring/setup-agents.d.ts +81 -2
- package/node_modules/@comis/daemon/dist/wiring/setup-agents.js +164 -3
- package/node_modules/@comis/daemon/dist/wiring/setup-background-completion-runner.d.ts +58 -0
- package/node_modules/@comis/daemon/dist/wiring/setup-background-completion-runner.js +59 -0
- package/node_modules/@comis/daemon/dist/wiring/setup-background-tasks.d.ts +10 -3
- package/node_modules/@comis/daemon/dist/wiring/setup-background-tasks.js +13 -7
- package/node_modules/@comis/daemon/dist/wiring/setup-channels.d.ts +9 -2
- package/node_modules/@comis/daemon/dist/wiring/setup-channels.js +35 -10
- package/node_modules/@comis/daemon/dist/wiring/setup-cross-session.d.ts +20 -5
- package/node_modules/@comis/daemon/dist/wiring/setup-cross-session.js +21 -16
- package/node_modules/@comis/daemon/dist/wiring/setup-delivery.d.ts +14 -5
- package/node_modules/@comis/daemon/dist/wiring/setup-delivery.js +65 -20
- package/node_modules/@comis/daemon/dist/wiring/setup-gateway.d.ts +4 -6
- package/node_modules/@comis/daemon/dist/wiring/setup-gateway.js +3 -5
- package/node_modules/@comis/daemon/dist/wiring/setup-heartbeat.d.ts +20 -5
- package/node_modules/@comis/daemon/dist/wiring/setup-heartbeat.js +11 -2
- package/node_modules/@comis/daemon/dist/wiring/setup-output-retention.d.ts +89 -0
- package/node_modules/@comis/daemon/dist/wiring/setup-output-retention.js +212 -0
- package/node_modules/@comis/daemon/dist/wiring/setup-schedulers.js +4 -0
- package/node_modules/@comis/daemon/dist/wiring/setup-tools.d.ts +18 -4
- package/node_modules/@comis/daemon/dist/wiring/setup-tools.js +29 -10
- package/node_modules/@comis/daemon/dist/wiring/tool-capability-adapter.d.ts +75 -0
- package/node_modules/@comis/daemon/dist/wiring/tool-capability-adapter.js +253 -0
- package/node_modules/@comis/daemon/package.json +1 -1
- package/node_modules/@comis/gateway/dist/index.d.ts +2 -0
- package/node_modules/@comis/gateway/dist/index.js +2 -0
- package/node_modules/@comis/gateway/dist/oauth/oauth-callback-route.d.ts +66 -0
- package/node_modules/@comis/gateway/dist/oauth/oauth-callback-route.js +212 -0
- package/node_modules/@comis/gateway/dist/server/hono-server.d.ts +14 -0
- package/node_modules/@comis/gateway/dist/server/hono-server.js +10 -0
- package/node_modules/@comis/gateway/dist/webhook/webhook-endpoint.d.ts +0 -4
- package/node_modules/@comis/gateway/package.json +1 -1
- package/node_modules/@comis/infra/dist/logging/log-fields.d.ts +23 -0
- package/node_modules/@comis/infra/package.json +1 -1
- package/node_modules/@comis/memory/dist/compaction.d.ts +3 -5
- package/node_modules/@comis/memory/dist/compaction.js +2 -3
- package/node_modules/@comis/memory/dist/delivery-queue-adapter.d.ts +2 -2
- package/node_modules/@comis/memory/dist/delivery-queue-adapter.js +49 -1
- package/node_modules/@comis/memory/dist/index.d.ts +2 -0
- package/node_modules/@comis/memory/dist/index.js +3 -0
- package/node_modules/@comis/memory/dist/memory-api.d.ts +1 -1
- package/node_modules/@comis/memory/dist/memory-api.js +1 -1
- package/node_modules/@comis/memory/dist/oauth-profile-schema.d.ts +17 -0
- package/node_modules/@comis/memory/dist/oauth-profile-schema.js +33 -0
- package/node_modules/@comis/memory/dist/oauth-profile-store-encrypted.d.ts +27 -0
- package/node_modules/@comis/memory/dist/oauth-profile-store-encrypted.js +144 -0
- package/node_modules/@comis/memory/dist/session-store.d.ts +1 -1
- package/node_modules/@comis/memory/dist/session-store.js +1 -1
- package/node_modules/@comis/memory/dist/sqlite-secret-store.d.ts +29 -3
- package/node_modules/@comis/memory/dist/sqlite-secret-store.js +11 -3
- package/node_modules/@comis/memory/package.json +1 -1
- package/node_modules/@comis/scheduler/dist/cron/cron-types.d.ts +0 -42
- package/node_modules/@comis/scheduler/dist/execution/execution-lock.d.ts +13 -0
- package/node_modules/@comis/scheduler/dist/execution/execution-lock.js +1 -1
- package/node_modules/@comis/scheduler/dist/execution/index.d.ts +2 -0
- package/node_modules/@comis/scheduler/dist/execution/index.js +2 -0
- package/node_modules/@comis/scheduler/dist/heartbeat/agent-heartbeat-source.d.ts +29 -8
- package/node_modules/@comis/scheduler/dist/heartbeat/agent-heartbeat-source.js +20 -8
- package/node_modules/@comis/scheduler/dist/index.d.ts +2 -0
- package/node_modules/@comis/scheduler/dist/index.js +2 -0
- package/node_modules/@comis/scheduler/dist/system-events/system-event-types.d.ts +0 -3
- package/node_modules/@comis/scheduler/dist/tasks/task-types.d.ts +0 -17
- package/node_modules/@comis/scheduler/package.json +1 -1
- package/node_modules/@comis/shared/dist/index.d.ts +3 -0
- package/node_modules/@comis/shared/dist/index.js +4 -0
- package/node_modules/@comis/shared/dist/mcp-tool-name.d.ts +78 -0
- package/node_modules/@comis/shared/dist/mcp-tool-name.js +92 -0
- package/node_modules/@comis/shared/dist/silent-tokens.d.ts +38 -0
- package/node_modules/@comis/shared/dist/silent-tokens.js +51 -0
- package/node_modules/@comis/shared/dist/visible-delivery.d.ts +28 -0
- package/node_modules/@comis/shared/dist/visible-delivery.js +16 -0
- package/node_modules/@comis/shared/package.json +1 -1
- package/node_modules/@comis/skills/dist/bridge/mcp-tool-bridge.d.ts +2 -13
- package/node_modules/@comis/skills/dist/bridge/mcp-tool-bridge.js +3 -21
- package/node_modules/@comis/skills/dist/bridge/schema-validator.d.ts +38 -0
- package/node_modules/@comis/skills/dist/bridge/schema-validator.js +169 -0
- package/node_modules/@comis/skills/dist/bridge/tool-metadata-enforcement.js +12 -0
- package/node_modules/@comis/skills/dist/bridge/tool-metadata-registry.js +133 -3
- package/node_modules/@comis/skills/dist/builtin/exec-diagnostics.d.ts +32 -0
- package/node_modules/@comis/skills/dist/builtin/exec-diagnostics.js +127 -0
- package/node_modules/@comis/skills/dist/builtin/exec-security.js +38 -0
- package/node_modules/@comis/skills/dist/builtin/exec-tool.d.ts +55 -9
- package/node_modules/@comis/skills/dist/builtin/exec-tool.js +392 -19
- package/node_modules/@comis/skills/dist/builtin/file-tools/grep-tool.js +6 -6
- package/node_modules/@comis/skills/dist/builtin/install-detour.d.ts +67 -0
- package/node_modules/@comis/skills/dist/builtin/install-detour.js +342 -0
- package/node_modules/@comis/skills/dist/builtin/platform/admin-manage-factory.js +5 -5
- package/node_modules/@comis/skills/dist/builtin/platform/agents-manage-tool.d.ts +7 -6
- package/node_modules/@comis/skills/dist/builtin/platform/agents-manage-tool.js +40 -29
- package/node_modules/@comis/skills/dist/builtin/platform/background-tasks-tool.d.ts +4 -1
- package/node_modules/@comis/skills/dist/builtin/platform/background-tasks-tool.js +3 -3
- package/node_modules/@comis/skills/dist/builtin/platform/cron-tool.js +1 -1
- package/node_modules/@comis/skills/dist/builtin/platform/gateway-tool.js +6 -6
- package/node_modules/@comis/skills/dist/builtin/platform/mcp-manage-tool.d.ts +1 -1
- package/node_modules/@comis/skills/dist/builtin/platform/mcp-manage-tool.js +9 -9
- package/node_modules/@comis/skills/dist/builtin/platform/message-tool.js +18 -0
- package/node_modules/@comis/skills/dist/builtin/platform/messaging-factory.d.ts +18 -1
- package/node_modules/@comis/skills/dist/builtin/platform/messaging-factory.js +18 -2
- package/node_modules/@comis/skills/dist/builtin/platform/models-manage-tool.js +3 -3
- package/node_modules/@comis/skills/dist/builtin/process-registry.d.ts +14 -0
- package/node_modules/@comis/skills/dist/builtin/process-tool.d.ts +24 -4
- package/node_modules/@comis/skills/dist/builtin/process-tool.js +25 -7
- package/node_modules/@comis/skills/dist/builtin/sandbox/bwrap-provider.d.ts +11 -0
- package/node_modules/@comis/skills/dist/builtin/sandbox/bwrap-provider.js +123 -1
- package/node_modules/@comis/skills/dist/builtin/sandbox/detect-provider.js +40 -15
- package/node_modules/@comis/skills/dist/index.d.ts +4 -1
- package/node_modules/@comis/skills/dist/index.js +3 -1
- package/node_modules/@comis/skills/dist/manifest/capability-parser.d.ts +44 -0
- package/node_modules/@comis/skills/dist/manifest/capability-parser.js +68 -0
- package/node_modules/@comis/skills/dist/manifest/schema.d.ts +44 -37
- package/node_modules/@comis/skills/dist/manifest/schema.js +35 -0
- package/node_modules/@comis/skills/dist/media/ssrf-fetcher.d.ts +7 -0
- package/node_modules/@comis/skills/dist/media/ssrf-fetcher.js +9 -2
- package/node_modules/@comis/skills/dist/registry/discovery.d.ts +8 -0
- package/node_modules/@comis/skills/dist/registry/discovery.js +10 -3
- package/node_modules/@comis/skills/dist/registry/skill-registry.d.ts +45 -1
- package/node_modules/@comis/skills/dist/registry/skill-registry.js +70 -7
- package/node_modules/@comis/skills/package.json +1 -1
- package/node_modules/@comis/web/dist/assets/{agent-detail-71BSbSfD.js → agent-detail-q8t1NB7w.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{agent-editor-CTSDZhwT.js → agent-editor-B46io5gv.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{agent-list-BEhni2ea.js → agent-list-DQ6g2Rcx.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{billing-view-DVP1IvVs.js → billing-view-IWPR8LgF.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{channel-detail-N_YK74xC.js → channel-detail-DlNNZuuC.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{channel-list-DRk6ZJaF.js → channel-list-DhGwxiMc.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{chat-console-Dm-GtSf9.js → chat-console-Nv6fM3Rc.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{config-editor-CIferYX6.js → config-editor-BYKuJF76.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{context-dag-browser-CL84rXXM.js → context-dag-browser-ClNEtzYE.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{context-engine-B1HOTEZv.js → context-engine-BZJ6HChd.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{delivery-view-Y6JKYVFw.js → delivery-view-Cb7I3vGu.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{diagnostics-view-DWV1UQjz.js → diagnostics-view-9u9Lyu5a.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{ic-chat-message-DfSERzzg.js → ic-chat-message-BFt3cVpx.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{ic-connection-dot-CXyhlJup.js → ic-connection-dot-y77LZ3Gu.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{ic-tool-call-DNmwTjek.js → ic-tool-call-qt6w1NQl.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{index-CBr0Tm9_.js → index-8Tg9oc-C.js} +2 -2
- package/node_modules/@comis/web/dist/assets/{mcp-management-BaH2-vox.js → mcp-management-69dtH_kY.js} +2 -2
- package/node_modules/@comis/web/dist/assets/{media-config-CZLshJoN.js → media-config-BdjLj5c1.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{media-test-C9NUWgo_.js → media-test-DuPqrixi.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{memory-inspector-D_fmTcRN.js → memory-inspector-B-Pepbq-.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{message-center-BBFlNCZn.js → message-center-B7l0yNYY.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{models-BytGLm99.js → models-JHFHuv5S.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{observe-view-VXtHqaqq.js → observe-view-r8mqhy4O.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{pipeline-builder-CfXczlfJ.js → pipeline-builder-XjkiZRcR.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{pipeline-history-CPmXFnbe.js → pipeline-history-CZqJv_Hj.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{pipeline-history-detail-DcueTMs9.js → pipeline-history-detail-BEFGMoDy.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{pipeline-list-B-xG5WZh.js → pipeline-list-B6q5LvO1.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{pipeline-monitor-pnIOYaSY.js → pipeline-monitor-BNomXjVL.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{scheduler-BtUIFHhA.js → scheduler-BJEjcGKA.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{security-C8mWRq2y.js → security-2G1jhBfV.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{session-detail-DgdkO5ka.js → session-detail-DmVPzFBR.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{session-list-DcylcfTn.js → session-list-CsqMQoHs.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{setup-wizard-BP5yjsuL.js → setup-wizard-CAdM-gSP.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{skills-DXt1bX8Z.js → skills-2ODqKaWr.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{subagents-C7YbUHXY.js → subagents-BFlwfTbD.js} +1 -1
- package/node_modules/@comis/web/dist/assets/{workspace-manager-DP6pW4wa.js → workspace-manager--CbOx_dI.js} +1 -1
- package/node_modules/@comis/web/dist/index.html +1 -1
- package/node_modules/@comis/web/package.json +1 -1
- package/package.json +25 -24
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Output retention housekeeper: scans the agent's output/ directory,
|
|
4
|
+
* deletes files whose age exceeds the per-class retentionMs.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors setup-delivery.ts drain+prune timer pattern (single-tick gate +
|
|
7
|
+
* unref() + structured DEBUG log per pass).
|
|
8
|
+
*
|
|
9
|
+
* Consumes JSONL details.visibleDelivery for offline analysis (the
|
|
10
|
+
* housekeeper does NOT delete JSONL itself; it only manages output/
|
|
11
|
+
* files referenced by it).
|
|
12
|
+
*
|
|
13
|
+
* Per AGENTS §2.2: NO `path.join`, NO `process.env`. All paths via
|
|
14
|
+
* `safePath(workspaceDir, ...)`. Per AGENTS §2.4: factory + Deps with
|
|
15
|
+
* ComisLogger injected. Per AGENTS §2.1: error paths log WARN/DEBUG with
|
|
16
|
+
* hint+errorKind; never throws. Per AGENTS §2.3 KISS: in-place file
|
|
17
|
+
* deletion. No "trash dir", no "soft delete". Per AGENTS §6.6
|
|
18
|
+
* (security/daemon): file deletion is destructive — operator can
|
|
19
|
+
* disable via `enabled: false` config.
|
|
20
|
+
*
|
|
21
|
+
* Test contract: `validateOutputRetentionConfig({ classes:
|
|
22
|
+
* [{classId, retentionMs}] })` returns `{ ok, value | error }`.
|
|
23
|
+
*
|
|
24
|
+
* @module setup-output-retention
|
|
25
|
+
*/
|
|
26
|
+
import { readdirSync, statSync, unlinkSync } from "node:fs";
|
|
27
|
+
import { safePath } from "@comis/core";
|
|
28
|
+
import { ok, err, suppressError } from "@comis/shared";
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Validator (test contract gate)
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
/**
|
|
33
|
+
* Validate an output-retention config supplied as the legacy
|
|
34
|
+
* `{ classes: [{classId, retentionMs}] }` shape. Returns a Result-shaped
|
|
35
|
+
* `{ ok: true, value }` on success, `{ ok: false, error }` on failure.
|
|
36
|
+
*
|
|
37
|
+
* Validator contract:
|
|
38
|
+
* - retentionMs = -1 → rejected
|
|
39
|
+
* - retentionMs = 0 → rejected
|
|
40
|
+
* - retentionMs = 1 → accepted
|
|
41
|
+
*
|
|
42
|
+
* Production wiring uses the Zod schema in
|
|
43
|
+
* @comis/core/config/schema-output-retention.ts directly; this
|
|
44
|
+
* validator is a thin compatibility surface for the test contract.
|
|
45
|
+
*/
|
|
46
|
+
export function validateOutputRetentionConfig(config) {
|
|
47
|
+
if (typeof config !== "object" || config === null) {
|
|
48
|
+
return err(new Error("output retention config must be an object"));
|
|
49
|
+
}
|
|
50
|
+
const obj = config;
|
|
51
|
+
if (!Array.isArray(obj.classes)) {
|
|
52
|
+
return err(new Error("output retention config: 'classes' must be an array"));
|
|
53
|
+
}
|
|
54
|
+
const out = [];
|
|
55
|
+
for (let i = 0; i < obj.classes.length; i++) {
|
|
56
|
+
const entry = obj.classes[i];
|
|
57
|
+
if (typeof entry !== "object" || entry === null) {
|
|
58
|
+
return err(new Error(`output retention config: classes[${i}] must be an object`));
|
|
59
|
+
}
|
|
60
|
+
const e = entry;
|
|
61
|
+
if (typeof e.classId !== "string" || e.classId.length === 0) {
|
|
62
|
+
return err(new Error(`output retention config: classes[${i}].classId must be a non-empty string`));
|
|
63
|
+
}
|
|
64
|
+
if (typeof e.retentionMs !== "number" ||
|
|
65
|
+
!Number.isInteger(e.retentionMs) ||
|
|
66
|
+
e.retentionMs <= 0) {
|
|
67
|
+
return err(new Error(`output retention config: classes[${i}].retentionMs must be a positive integer (got ${String(e.retentionMs)})`));
|
|
68
|
+
}
|
|
69
|
+
out.push({ classId: e.classId, retentionMs: e.retentionMs });
|
|
70
|
+
}
|
|
71
|
+
return ok({ classes: out });
|
|
72
|
+
}
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
// Housekeeper factory
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
/**
|
|
77
|
+
* Wire the per-class output-retention housekeeper.
|
|
78
|
+
*
|
|
79
|
+
* Mirrors setup-delivery.ts (drain + prune timer): single-tick gate, .unref(),
|
|
80
|
+
* structured per-pass log. The factory starts the recurring interval
|
|
81
|
+
* immediately on construction; call shutdown() on system:shutdown.
|
|
82
|
+
*
|
|
83
|
+
* Returns a handle exposing `shutdown()` (idempotent) and `runOnePass()`
|
|
84
|
+
* (manual trigger for tests).
|
|
85
|
+
*/
|
|
86
|
+
export function setupOutputRetention(deps) {
|
|
87
|
+
const log = deps.logger.child({ submodule: "output-retention-housekeeper" });
|
|
88
|
+
// Defensive degradation: when config is undefined (legacy test mocks
|
|
89
|
+
// bypassing the AppConfig schema via `as unknown as`), behave as if
|
|
90
|
+
// disabled. Mirrors setupDeliveryMirror's optional-chain pattern.
|
|
91
|
+
// Production paths get a fully-defaulted config from
|
|
92
|
+
// AppConfigSchema.outputRetention, so this branch only triggers in
|
|
93
|
+
// tests with hand-constructed config objects.
|
|
94
|
+
if (!deps.config) {
|
|
95
|
+
log.debug({
|
|
96
|
+
hint: "Output retention config not present; housekeeper inactive (likely a hand-constructed test mock)",
|
|
97
|
+
}, "Output retention: no config");
|
|
98
|
+
return {
|
|
99
|
+
shutdown: () => { },
|
|
100
|
+
runOnePass: async () => ({ deleted: 0, bytesFreed: 0 }),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const config = deps.config;
|
|
104
|
+
let interval;
|
|
105
|
+
let running = null;
|
|
106
|
+
async function runOnePass() {
|
|
107
|
+
const outputDir = safePath(deps.workspaceDir, "output");
|
|
108
|
+
const now = Date.now();
|
|
109
|
+
let deleted = 0;
|
|
110
|
+
let bytesFreed = 0;
|
|
111
|
+
// Read class subdirectories under output/. Missing dir = nothing to do.
|
|
112
|
+
let classDirs;
|
|
113
|
+
try {
|
|
114
|
+
classDirs = readdirSync(outputDir);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
log.debug({ outputDir, hint: "Output dir missing — nothing to retain yet" }, "Output retention: output dir not present");
|
|
118
|
+
return { deleted, bytesFreed };
|
|
119
|
+
}
|
|
120
|
+
for (const className of classDirs) {
|
|
121
|
+
// Resolve class config: explicit class, else fall back to "default".
|
|
122
|
+
const classConfig = config.classes[className] ?? config.classes.default;
|
|
123
|
+
if (!classConfig)
|
|
124
|
+
continue;
|
|
125
|
+
const classDir = safePath(outputDir, className);
|
|
126
|
+
let entries;
|
|
127
|
+
try {
|
|
128
|
+
entries = readdirSync(classDir);
|
|
129
|
+
}
|
|
130
|
+
catch (entryErr) {
|
|
131
|
+
log.debug({
|
|
132
|
+
err: entryErr,
|
|
133
|
+
classDir,
|
|
134
|
+
hint: "Could not read class dir; will retry next pass",
|
|
135
|
+
errorKind: "internal",
|
|
136
|
+
}, "Output retention: class dir read failed");
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
for (const entry of entries) {
|
|
140
|
+
const filePath = safePath(classDir, entry);
|
|
141
|
+
try {
|
|
142
|
+
const stats = statSync(filePath);
|
|
143
|
+
// Skip subdirectories — only retain leaf files. Per KISS, no
|
|
144
|
+
// recursion: each retention class is a single flat directory.
|
|
145
|
+
if (!stats.isFile())
|
|
146
|
+
continue;
|
|
147
|
+
const ageMs = now - stats.mtimeMs;
|
|
148
|
+
if (ageMs > classConfig.retentionMs) {
|
|
149
|
+
bytesFreed += stats.size;
|
|
150
|
+
unlinkSync(filePath);
|
|
151
|
+
deleted++;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (fileErr) {
|
|
155
|
+
log.debug({
|
|
156
|
+
err: fileErr,
|
|
157
|
+
filePath,
|
|
158
|
+
hint: "Failed to inspect/delete file in housekeeper pass; will retry next pass",
|
|
159
|
+
errorKind: "internal",
|
|
160
|
+
}, "Output retention: file inspect/delete failed");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (deleted > 0) {
|
|
165
|
+
log.info({
|
|
166
|
+
deleted,
|
|
167
|
+
bytesFreed,
|
|
168
|
+
class: "output_retention",
|
|
169
|
+
hint: "Per-class output retention completed; files older than configured retentionMs removed",
|
|
170
|
+
}, "Output retention: housekeeper pass completed");
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
log.debug({ class: "output_retention", hint: "No files exceeded retentionMs this pass" }, "Output retention: nothing to delete");
|
|
174
|
+
}
|
|
175
|
+
return { deleted, bytesFreed };
|
|
176
|
+
}
|
|
177
|
+
function startInterval() {
|
|
178
|
+
if (!config.enabled) {
|
|
179
|
+
log.info({ hint: "Output retention disabled by config; not starting housekeeper" }, "Output retention: disabled");
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
interval = setInterval(() => {
|
|
183
|
+
// Single-tick gate: in-flight Promise prevents overlapping ticks.
|
|
184
|
+
if (running)
|
|
185
|
+
return;
|
|
186
|
+
running = runOnePass()
|
|
187
|
+
.then(() => undefined)
|
|
188
|
+
.finally(() => {
|
|
189
|
+
running = null;
|
|
190
|
+
});
|
|
191
|
+
// Fire-and-forget: failures inside runOnePass are already logged
|
|
192
|
+
// and do not propagate (it never throws). suppressError satisfies
|
|
193
|
+
// the no-floating-promise lint without altering semantics.
|
|
194
|
+
suppressError(running, "output retention recurring tick");
|
|
195
|
+
}, config.intervalMs);
|
|
196
|
+
interval.unref();
|
|
197
|
+
log.info({
|
|
198
|
+
intervalMs: config.intervalMs,
|
|
199
|
+
classes: Object.keys(config.classes),
|
|
200
|
+
hint: "Output retention housekeeper started",
|
|
201
|
+
}, "Output retention: started");
|
|
202
|
+
}
|
|
203
|
+
function shutdown() {
|
|
204
|
+
if (interval) {
|
|
205
|
+
clearInterval(interval);
|
|
206
|
+
interval = undefined;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// Start immediately on construction (mirrors setup-delivery's startup pattern).
|
|
210
|
+
startInterval();
|
|
211
|
+
return { shutdown, runOnePass };
|
|
212
|
+
}
|
|
@@ -108,6 +108,10 @@ export async function setupSchedulers(deps) {
|
|
|
108
108
|
payloadKind: job.payload.kind,
|
|
109
109
|
sessionStrategy: job.sessionStrategy,
|
|
110
110
|
maxHistoryTurns: job.maxHistoryTurns,
|
|
111
|
+
// Cadence is a literal number only for kind === "every"; cron-expression
|
|
112
|
+
// schedules would require parsing the expression to estimate a cadence,
|
|
113
|
+
// which is out of scope. Consumers must treat undefined as "unknown".
|
|
114
|
+
cadenceMs: job.schedule.kind === "every" ? job.schedule.everyMs : undefined,
|
|
111
115
|
cronJobModel: job.payload.kind === "agent_turn" ? job.payload.model : undefined,
|
|
112
116
|
cacheRetention: job.cacheRetention,
|
|
113
117
|
toolPolicy: job.toolPolicy,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tool assembly setup: assembleToolsForAgent and preprocessMessageText.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* sequence.
|
|
3
|
+
* Isolates per-agent tool creation and message preprocessing from the
|
|
4
|
+
* main wiring sequence.
|
|
6
5
|
* @module
|
|
7
6
|
*/
|
|
8
|
-
import type { AppContainer, ApprovalGate, CredentialMappingPort, WrapExternalContentOptions, SessionKey } from "@comis/core";
|
|
7
|
+
import type { AppContainer, ApprovalGate, CredentialMappingPort, WrapExternalContentOptions, SessionKey, ToolCapabilityPort } from "@comis/core";
|
|
9
8
|
import type { ComisLogger } from "@comis/infra";
|
|
10
9
|
import type { SessionTrackerRegistry } from "@comis/agent";
|
|
11
10
|
import type { PerAgentConfig } from "@comis/core";
|
|
@@ -54,6 +53,21 @@ export interface ToolsDeps {
|
|
|
54
53
|
* without requiring a daemon restart.
|
|
55
54
|
*/
|
|
56
55
|
mcpClientManager: McpClientManager;
|
|
56
|
+
/**
|
|
57
|
+
* Per-agent ToolCapabilityPort resolver. Populated by daemon.ts from the
|
|
58
|
+
* AgentsResult.toolCapabilityPorts map (one adapter per agent constructed
|
|
59
|
+
* inside setupSingleAgent). Used by exec / process tools to consult the
|
|
60
|
+
* live install-detour mode + connected MCP servers + visible skills, and
|
|
61
|
+
* to read operator-supplied cluster hints. The closure may throw or fall
|
|
62
|
+
* back to the default agent's port for unknown agentIds -- daemon.ts
|
|
63
|
+
* decides the contract.
|
|
64
|
+
*
|
|
65
|
+
* Consumed via the single mandated form `deps.getCapabilityPortForAgent(agentId)`
|
|
66
|
+
* inside assembleToolsForAgent (mirrors the deps.<field> direct-access
|
|
67
|
+
* convention used for nearby fields like deps.eventBus, deps.skillsLogger,
|
|
68
|
+
* deps.linkRunner, deps.subprocessEnv).
|
|
69
|
+
*/
|
|
70
|
+
getCapabilityPortForAgent: (agentId: string) => ToolCapabilityPort;
|
|
57
71
|
/** Image generation provider (undefined when API key missing -- tool not registered). */
|
|
58
72
|
imageGenProvider?: ImageGenerationPort;
|
|
59
73
|
/** OS-level sandbox provider detected once at daemon startup. */
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
/**
|
|
3
3
|
* Tool assembly setup: assembleToolsForAgent and preprocessMessageText.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* sequence.
|
|
4
|
+
* Isolates per-agent tool creation and message preprocessing from the
|
|
5
|
+
* main wiring sequence.
|
|
7
6
|
* @module
|
|
8
7
|
*/
|
|
9
8
|
import { isAbsolute, resolve } from "node:path";
|
|
10
9
|
import { enterConfigMutationFence, leaveConfigMutationFence } from "../rpc/persist-to-config.js";
|
|
11
|
-
import { SkillsConfigSchema, sanitizeLogString, tryGetContext, parseFormattedSessionKey, safePath, formatSessionKey } from "@comis/core";
|
|
10
|
+
import { SkillsConfigSchema, sanitizeLogString, tryGetContext, parseFormattedSessionKey, safePath, formatSessionKey, } from "@comis/core";
|
|
12
11
|
import { sessionKeyToPath, WORKSPACE_FILE_NAMES, DEFAULT_TEMPLATES, registerWorkspaceFilesInTracker, } from "@comis/agent";
|
|
13
12
|
import { stat as fsStat } from "node:fs/promises";
|
|
14
13
|
import { assembleToolPipeline, createFileStateTracker, createCronTool, createUnifiedMemoryTool, createUnifiedSessionTool, createUnifiedContextTool, createMessageTool, createDiscordActionTool, createTelegramActionTool, createSlackActionTool, createWhatsAppActionTool, createSessionsSendTool, createSessionsSpawnTool, createSubagentsTool, createPipelineTool, createImageTool, createTTSTool, createTranscribeAudioTool, createDescribeVideoTool, createExtractDocumentTool, createGatewayTool, createBrowserTool, createAgentsManageTool, createObsQueryTool, createSessionsManageTool, createModelsManageTool, createTokensManageTool, createChannelsManageTool, createSkillsManageTool, createMcpManageTool, createHeartbeatManageTool, createProvidersManageTool, createNotifyTool, createImageGenerateTool, createBackgroundTasksTool, createExecTool, createProcessTool, createProcessRegistry, createApplyPatchTool, sanitizeImageForApi, createMediaPersistenceService, createCredentialInjector, mcpToolsToAgentTools, TOOL_PROFILES, TOOL_GROUPS, } from "@comis/skills";
|
|
@@ -117,7 +116,7 @@ export function setupTools(deps) {
|
|
|
117
116
|
// admin agents are covered by agents_manage's onAgentCreated callback.
|
|
118
117
|
const ownWorkspaceDir = workspaceDirs.get(agentId) ?? defaultWorkspaceDir;
|
|
119
118
|
await registerWorkspaceFilesInTracker(ownWorkspaceDir, fileStateTracker, skillsLogger);
|
|
120
|
-
// Enrich sharedPaths for admin-trust agents: grant cross-workspace file access
|
|
119
|
+
// Enrich sharedPaths for admin-trust agents: grant cross-workspace file access.
|
|
121
120
|
// Default agent (orchestrator) and supervisor-profile agents can access other agent workspaces.
|
|
122
121
|
// Lazy callback for admin agents so hot-added workspaces are visible without re-assembling tools.
|
|
123
122
|
const isDefaultAgent = agentId === defaultAgentId;
|
|
@@ -273,15 +272,35 @@ export function setupTools(deps) {
|
|
|
273
272
|
const sessionDir = sessionKeyToPath(parsed, sessionBaseDir);
|
|
274
273
|
return safePath(sessionDir, "tool-results");
|
|
275
274
|
};
|
|
276
|
-
tools.push(createExecTool(
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
275
|
+
tools.push(createExecTool({
|
|
276
|
+
workspacePath: agentWorkspaceDir,
|
|
277
|
+
registry,
|
|
278
|
+
secretManager,
|
|
279
|
+
platformSecretNames,
|
|
280
|
+
logger: skillsLogger,
|
|
281
|
+
subprocessEnv, // Filtered subprocess environment
|
|
282
|
+
sandboxConfig: sandboxCfg, // Per-agent sandbox config
|
|
283
|
+
eventBus, // command:blocked + secret:accessed audit events
|
|
284
|
+
getToolResultsDir, // Session tool-results dir for output persistence
|
|
285
|
+
// Live per-agent ToolCapabilityPort resolver populated by daemon.ts
|
|
286
|
+
// from AgentsResult.toolCapabilityPorts map. Single mandated form
|
|
287
|
+
// `deps.<field>(agentId)` mirrors the surrounding direct-deps-access
|
|
288
|
+
// convention.
|
|
289
|
+
toolCapabilityPort: deps.getCapabilityPortForAgent(agentId),
|
|
290
|
+
approvalGate, // Soft-stop override path
|
|
291
|
+
}));
|
|
280
292
|
}
|
|
281
293
|
// Process tool -- always instantiated; builtinTools ceiling applied after profile filtering
|
|
282
294
|
{
|
|
283
295
|
const registry = getOrCreateRegistry(agentId);
|
|
284
|
-
tools.push(createProcessTool(
|
|
296
|
+
tools.push(createProcessTool({
|
|
297
|
+
registry,
|
|
298
|
+
logger: skillsLogger,
|
|
299
|
+
// Live per-agent ToolCapabilityPort resolver populated by daemon.ts
|
|
300
|
+
// from AgentsResult.toolCapabilityPorts. Single mandated form
|
|
301
|
+
// `deps.<field>(agentId)`.
|
|
302
|
+
toolCapabilityPort: deps.getCapabilityPortForAgent(agentId),
|
|
303
|
+
}));
|
|
285
304
|
}
|
|
286
305
|
// Apply patch tool -- always included, gated by tool policy
|
|
287
306
|
tools.push(createApplyPatchTool(workspaceDirs.get(agentId) ?? defaultWorkspaceDir, effectiveSharedPaths, skillsLogger));
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live ToolCapabilityPort adapter -- daemon-side wiring.
|
|
3
|
+
*
|
|
4
|
+
* Factory whose 9 frozen methods read live state from:
|
|
5
|
+
* - `deps.toolingConfig` (operator config; the `tooling.*` subtree)
|
|
6
|
+
* - `deps.skillRegistry` (already applies allow/deny + eligibility +
|
|
7
|
+
* disableModelInvocation filters)
|
|
8
|
+
* - `deps.mcpClientManager` (live MCP connection state per server)
|
|
9
|
+
*
|
|
10
|
+
* Cross-field cluster-ID validation runs at construction time across three
|
|
11
|
+
* surfaces (`builtinAssignments`, `mcp.capabilityHints[*].cluster`,
|
|
12
|
+
* `skills.capabilityHints[*].cluster`). Operator typos emit a Pino WARN with
|
|
13
|
+
* { errorKind: "config", configPath, unresolvedClusterId, hint }
|
|
14
|
+
* and DO NOT throw -- lookup-time fallback applies (`external-integrations`
|
|
15
|
+
* for unresolved MCP clusters; `prompt-skills` for unresolved skill clusters).
|
|
16
|
+
* WARN (not DEBUG) is intentional: operator visibility for misconfiguration.
|
|
17
|
+
*
|
|
18
|
+
* Default merge contract: `mergedClusters = { ...DEFAULT_CLUSTER_CONFIG,
|
|
19
|
+
* ...operator.clusters }` because `z.record(...).default({})` would replace
|
|
20
|
+
* the entire record. Empty operator config preserves the 3 reserved IDs;
|
|
21
|
+
* partial-add preserves defaults plus addition; per-key override wins for the
|
|
22
|
+
* overridden key only. The same shape applies to `mergedBuiltinAssignments`.
|
|
23
|
+
*
|
|
24
|
+
* Liveness:
|
|
25
|
+
* - `getConnectedMcpServers()` filters `getAllConnections()` by
|
|
26
|
+
* `c.status === "connected"` on EVERY call -- never cached at construction
|
|
27
|
+
* (TOCTOU mitigation).
|
|
28
|
+
* - `getPackageAliasMap()` rebuilds fresh per call from operator MCP hints +
|
|
29
|
+
* visible skills + universal MCP fallback. No memoization.
|
|
30
|
+
* - `getPromptSkillCapabilities()` re-invokes `skillRegistry`'s sweep on
|
|
31
|
+
* every call; the operator-hint callback resolves through `port.getSkillHint`
|
|
32
|
+
* at call time (the arrow lambda holds the `port` reference, not a
|
|
33
|
+
* snapshot of `getSkillHint`).
|
|
34
|
+
*
|
|
35
|
+
* Returned port is `Object.freeze`d -- post-construction tampering is
|
|
36
|
+
* structurally impossible in strict mode (silently no-ops in sloppy mode).
|
|
37
|
+
*
|
|
38
|
+
* Boundary discipline: production source MUST NOT import test stubs from
|
|
39
|
+
* `@comis/core/__test-helpers/`.
|
|
40
|
+
*
|
|
41
|
+
* @module
|
|
42
|
+
*/
|
|
43
|
+
import type { ToolCapabilityPort, ToolingConfig } from "@comis/core";
|
|
44
|
+
import type { SkillRegistry, McpClientManager } from "@comis/skills";
|
|
45
|
+
import type { ComisLogger } from "@comis/infra";
|
|
46
|
+
/**
|
|
47
|
+
* Dependencies for the live ToolCapabilityPort adapter.
|
|
48
|
+
*
|
|
49
|
+
* Receivers MUST hold the daemon's container.config.tooling slice (NOT the
|
|
50
|
+
* top-level AppConfig) and the live skill registry / MCP client manager
|
|
51
|
+
* instances -- the adapter closes over them and re-reads on every method call.
|
|
52
|
+
*/
|
|
53
|
+
export interface ToolCapabilityAdapterDeps {
|
|
54
|
+
readonly toolingConfig: ToolingConfig;
|
|
55
|
+
readonly skillRegistry: SkillRegistry;
|
|
56
|
+
readonly mcpClientManager: McpClientManager;
|
|
57
|
+
readonly logger: ComisLogger;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build the live ToolCapabilityPort adapter.
|
|
61
|
+
*
|
|
62
|
+
* Pure synchronous function. Construction-time work:
|
|
63
|
+
* - Key-by-key merge of `DEFAULT_CLUSTER_CONFIG` with operator clusters.
|
|
64
|
+
* - Key-by-key merge of `DEFAULT_BUILTIN_ASSIGNMENTS` with operator assignments.
|
|
65
|
+
* - Cross-field cluster-ID validation across 3 surfaces (one Pino WARN per
|
|
66
|
+
* unresolved reference; never throws).
|
|
67
|
+
*
|
|
68
|
+
* Lookup-time work:
|
|
69
|
+
* - All 9 port methods are closures over the merged maps + the live
|
|
70
|
+
* `skillRegistry` / `mcpClientManager` references.
|
|
71
|
+
*
|
|
72
|
+
* @param deps - The adapter's dependencies.
|
|
73
|
+
* @returns A frozen `ToolCapabilityPort`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function createToolCapabilityAdapter(deps: ToolCapabilityAdapterDeps): ToolCapabilityPort;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Live ToolCapabilityPort adapter -- daemon-side wiring.
|
|
4
|
+
*
|
|
5
|
+
* Factory whose 9 frozen methods read live state from:
|
|
6
|
+
* - `deps.toolingConfig` (operator config; the `tooling.*` subtree)
|
|
7
|
+
* - `deps.skillRegistry` (already applies allow/deny + eligibility +
|
|
8
|
+
* disableModelInvocation filters)
|
|
9
|
+
* - `deps.mcpClientManager` (live MCP connection state per server)
|
|
10
|
+
*
|
|
11
|
+
* Cross-field cluster-ID validation runs at construction time across three
|
|
12
|
+
* surfaces (`builtinAssignments`, `mcp.capabilityHints[*].cluster`,
|
|
13
|
+
* `skills.capabilityHints[*].cluster`). Operator typos emit a Pino WARN with
|
|
14
|
+
* { errorKind: "config", configPath, unresolvedClusterId, hint }
|
|
15
|
+
* and DO NOT throw -- lookup-time fallback applies (`external-integrations`
|
|
16
|
+
* for unresolved MCP clusters; `prompt-skills` for unresolved skill clusters).
|
|
17
|
+
* WARN (not DEBUG) is intentional: operator visibility for misconfiguration.
|
|
18
|
+
*
|
|
19
|
+
* Default merge contract: `mergedClusters = { ...DEFAULT_CLUSTER_CONFIG,
|
|
20
|
+
* ...operator.clusters }` because `z.record(...).default({})` would replace
|
|
21
|
+
* the entire record. Empty operator config preserves the 3 reserved IDs;
|
|
22
|
+
* partial-add preserves defaults plus addition; per-key override wins for the
|
|
23
|
+
* overridden key only. The same shape applies to `mergedBuiltinAssignments`.
|
|
24
|
+
*
|
|
25
|
+
* Liveness:
|
|
26
|
+
* - `getConnectedMcpServers()` filters `getAllConnections()` by
|
|
27
|
+
* `c.status === "connected"` on EVERY call -- never cached at construction
|
|
28
|
+
* (TOCTOU mitigation).
|
|
29
|
+
* - `getPackageAliasMap()` rebuilds fresh per call from operator MCP hints +
|
|
30
|
+
* visible skills + universal MCP fallback. No memoization.
|
|
31
|
+
* - `getPromptSkillCapabilities()` re-invokes `skillRegistry`'s sweep on
|
|
32
|
+
* every call; the operator-hint callback resolves through `port.getSkillHint`
|
|
33
|
+
* at call time (the arrow lambda holds the `port` reference, not a
|
|
34
|
+
* snapshot of `getSkillHint`).
|
|
35
|
+
*
|
|
36
|
+
* Returned port is `Object.freeze`d -- post-construction tampering is
|
|
37
|
+
* structurally impossible in strict mode (silently no-ops in sloppy mode).
|
|
38
|
+
*
|
|
39
|
+
* Boundary discipline: production source MUST NOT import test stubs from
|
|
40
|
+
* `@comis/core/__test-helpers/`.
|
|
41
|
+
*
|
|
42
|
+
* @module
|
|
43
|
+
*/
|
|
44
|
+
import { DEFAULT_CLUSTER_CONFIG, DEFAULT_BUILTIN_ASSIGNMENTS, getToolMetadata, } from "@comis/core";
|
|
45
|
+
// Module-level reference-stable empty alias map. Returned only when no
|
|
46
|
+
// operator hints / visible skills / connected servers exist; downstream
|
|
47
|
+
// callers can rely on stable identity for cheap equality checks.
|
|
48
|
+
const EMPTY_ALIAS_MAP = new Map();
|
|
49
|
+
/**
|
|
50
|
+
* PEP-503-like normalization for package alias keys.
|
|
51
|
+
*
|
|
52
|
+
* - npm scoped packages (`@scope/name`) are preserved as-is, lowercased.
|
|
53
|
+
* - Everything else: lowercased, with runs of `_`, `.`, `-` collapsed to a
|
|
54
|
+
* single `-`.
|
|
55
|
+
*
|
|
56
|
+
* @param pkg - The raw package identifier from operator config or skill metadata.
|
|
57
|
+
* @returns The normalized key for `getPackageAliasMap`.
|
|
58
|
+
*/
|
|
59
|
+
function normalizeAliasKey(pkg) {
|
|
60
|
+
if (pkg.startsWith("@"))
|
|
61
|
+
return pkg.toLowerCase();
|
|
62
|
+
return pkg.toLowerCase().replace(/[_.\-]+/g, "-");
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Build the live ToolCapabilityPort adapter.
|
|
66
|
+
*
|
|
67
|
+
* Pure synchronous function. Construction-time work:
|
|
68
|
+
* - Key-by-key merge of `DEFAULT_CLUSTER_CONFIG` with operator clusters.
|
|
69
|
+
* - Key-by-key merge of `DEFAULT_BUILTIN_ASSIGNMENTS` with operator assignments.
|
|
70
|
+
* - Cross-field cluster-ID validation across 3 surfaces (one Pino WARN per
|
|
71
|
+
* unresolved reference; never throws).
|
|
72
|
+
*
|
|
73
|
+
* Lookup-time work:
|
|
74
|
+
* - All 9 port methods are closures over the merged maps + the live
|
|
75
|
+
* `skillRegistry` / `mcpClientManager` references.
|
|
76
|
+
*
|
|
77
|
+
* @param deps - The adapter's dependencies.
|
|
78
|
+
* @returns A frozen `ToolCapabilityPort`.
|
|
79
|
+
*/
|
|
80
|
+
export function createToolCapabilityAdapter(deps) {
|
|
81
|
+
const log = deps.logger.child({ submodule: "tool-capability-adapter" });
|
|
82
|
+
// Key-by-key default merge at adapter construction. Schema cannot supply
|
|
83
|
+
// DEFAULT_CLUSTER_CONFIG via `.default(...)` because z.record(...).default({})
|
|
84
|
+
// replaces the entire record.
|
|
85
|
+
const mergedClusters = {
|
|
86
|
+
...DEFAULT_CLUSTER_CONFIG,
|
|
87
|
+
...deps.toolingConfig.capabilityClusters.clusters,
|
|
88
|
+
};
|
|
89
|
+
const mergedBuiltinAssignments = {
|
|
90
|
+
...DEFAULT_BUILTIN_ASSIGNMENTS,
|
|
91
|
+
...deps.toolingConfig.capabilityClusters.builtinAssignments,
|
|
92
|
+
};
|
|
93
|
+
// Build the validation set once; used by all three loops AND by the lookup
|
|
94
|
+
// closures below (so a runtime typo also falls through to the documented
|
|
95
|
+
// fallback rather than silently substituting at lookup time).
|
|
96
|
+
const validClusterIds = new Set(Object.keys(mergedClusters));
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
// Cross-field cluster-ID validation (3 surfaces). Each loop emits one Pino
|
|
99
|
+
// WARN per unresolved reference. Construction is total -- no throws.
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
// Surface 1: builtinAssignments[toolName] -> clusterId
|
|
102
|
+
for (const [toolName, clusterId] of Object.entries(mergedBuiltinAssignments)) {
|
|
103
|
+
if (!validClusterIds.has(clusterId)) {
|
|
104
|
+
log.warn({
|
|
105
|
+
hint: `Add cluster '${clusterId}' to tooling.capabilityClusters.clusters or fix the reference at tooling.capabilityClusters.builtinAssignments.${toolName}`,
|
|
106
|
+
errorKind: "config",
|
|
107
|
+
configPath: `tooling.capabilityClusters.builtinAssignments.${toolName}`,
|
|
108
|
+
unresolvedClusterId: clusterId,
|
|
109
|
+
}, "Unresolved cluster ID in tooling config (builtinAssignments)");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Surface 2: mcp.capabilityHints[serverName].cluster
|
|
113
|
+
for (const [serverName, hint] of Object.entries(deps.toolingConfig.mcp.capabilityHints)) {
|
|
114
|
+
if (!validClusterIds.has(hint.cluster)) {
|
|
115
|
+
log.warn({
|
|
116
|
+
hint: `Add cluster '${hint.cluster}' to tooling.capabilityClusters.clusters or fix the reference at tooling.mcp.capabilityHints.${serverName}.cluster`,
|
|
117
|
+
errorKind: "config",
|
|
118
|
+
configPath: `tooling.mcp.capabilityHints.${serverName}.cluster`,
|
|
119
|
+
unresolvedClusterId: hint.cluster,
|
|
120
|
+
}, "Unresolved cluster ID in tooling config (mcp.capabilityHints)");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Surface 3: skills.capabilityHints[skillName].cluster
|
|
124
|
+
for (const [skillName, hint] of Object.entries(deps.toolingConfig.skills.capabilityHints)) {
|
|
125
|
+
if (!validClusterIds.has(hint.cluster)) {
|
|
126
|
+
log.warn({
|
|
127
|
+
hint: `Add cluster '${hint.cluster}' to tooling.capabilityClusters.clusters or fix the reference at tooling.skills.capabilityHints.${skillName}.cluster`,
|
|
128
|
+
errorKind: "config",
|
|
129
|
+
configPath: `tooling.skills.capabilityHints.${skillName}.cluster`,
|
|
130
|
+
unresolvedClusterId: hint.cluster,
|
|
131
|
+
}, "Unresolved cluster ID in tooling config (skills.capabilityHints)");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
// Build the frozen port. All closures capture `deps`, `mergedClusters`,
|
|
136
|
+
// `mergedBuiltinAssignments`, and `validClusterIds` lexically; runtime state
|
|
137
|
+
// (MCP connections, visible skills) is re-read on every method call.
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
const port = Object.freeze({
|
|
140
|
+
isCapabilityIndexEnabled: () => deps.toolingConfig.capabilityIndex.enabled,
|
|
141
|
+
getInstallDetourMode: () => deps.toolingConfig.installDetours.mode,
|
|
142
|
+
getBuiltinCluster: (toolName) => {
|
|
143
|
+
// Operator override wins when it resolves; an unresolved override
|
|
144
|
+
// already triggered a construction-time WARN -- fall through to
|
|
145
|
+
// metadata so the caller never sees a phantom cluster ID.
|
|
146
|
+
const opOverride = mergedBuiltinAssignments[toolName];
|
|
147
|
+
if (opOverride !== undefined && validClusterIds.has(opOverride)) {
|
|
148
|
+
return opOverride;
|
|
149
|
+
}
|
|
150
|
+
const meta = getToolMetadata(toolName);
|
|
151
|
+
return meta?.capability?.cluster;
|
|
152
|
+
},
|
|
153
|
+
getClusterConfig: (clusterId) => mergedClusters[clusterId],
|
|
154
|
+
getMcpServerHint: (serverName) => {
|
|
155
|
+
const hint = deps.toolingConfig.mcp.capabilityHints[serverName];
|
|
156
|
+
if (!hint)
|
|
157
|
+
return undefined;
|
|
158
|
+
// Fallback: unresolved cluster -> "external-integrations".
|
|
159
|
+
const cluster = validClusterIds.has(hint.cluster)
|
|
160
|
+
? hint.cluster
|
|
161
|
+
: "external-integrations";
|
|
162
|
+
return {
|
|
163
|
+
cluster,
|
|
164
|
+
description: hint.description,
|
|
165
|
+
replacesPackages: hint.replacesPackages,
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
getSkillHint: (skillName, skillKey) => {
|
|
169
|
+
// Precedence: operator(skillKey) > operator(skillName).
|
|
170
|
+
const hintByKey = skillKey
|
|
171
|
+
? deps.toolingConfig.skills.capabilityHints[skillKey]
|
|
172
|
+
: undefined;
|
|
173
|
+
const hintByName = !hintByKey
|
|
174
|
+
? deps.toolingConfig.skills.capabilityHints[skillName]
|
|
175
|
+
: undefined;
|
|
176
|
+
const hint = hintByKey ?? hintByName;
|
|
177
|
+
if (!hint)
|
|
178
|
+
return undefined;
|
|
179
|
+
// Fallback: unresolved cluster -> "prompt-skills".
|
|
180
|
+
const cluster = validClusterIds.has(hint.cluster)
|
|
181
|
+
? hint.cluster
|
|
182
|
+
: "prompt-skills";
|
|
183
|
+
return {
|
|
184
|
+
cluster,
|
|
185
|
+
...(hint.description !== undefined ? { description: hint.description } : {}),
|
|
186
|
+
replacesPackages: hint.replacesPackages,
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
getPackageAliasMap: () => {
|
|
190
|
+
// Fresh per call -- no memoization. Visible skills can change
|
|
191
|
+
// mid-session (file-watcher reloads, allow/deny edits); MCP servers
|
|
192
|
+
// connect/disconnect; capturing at construction would freeze stale
|
|
193
|
+
// state.
|
|
194
|
+
const skills = port.getPromptSkillCapabilities();
|
|
195
|
+
const connectedServers = port.getConnectedMcpServers();
|
|
196
|
+
const mcpHints = Object.entries(deps.toolingConfig.mcp.capabilityHints);
|
|
197
|
+
// Reference-stable empty result for cheap equality checks downstream.
|
|
198
|
+
if (mcpHints.length === 0 &&
|
|
199
|
+
skills.length === 0 &&
|
|
200
|
+
connectedServers.length === 0) {
|
|
201
|
+
return EMPTY_ALIAS_MAP;
|
|
202
|
+
}
|
|
203
|
+
const map = new Map();
|
|
204
|
+
// 1. Operator MCP hints -- replacesPackages entries point at the server.
|
|
205
|
+
for (const [serverName, hint] of mcpHints) {
|
|
206
|
+
for (const pkg of hint.replacesPackages) {
|
|
207
|
+
const key = normalizeAliasKey(pkg);
|
|
208
|
+
if (!map.has(key)) {
|
|
209
|
+
map.set(key, { type: "mcp", name: serverName });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// 2. Visible skills -- replacesPackages entries point at the skill.
|
|
214
|
+
// `port.getPromptSkillCapabilities()` reference resolves at call time;
|
|
215
|
+
// the lexical `port` const is in scope by the time
|
|
216
|
+
// `getPackageAliasMap` fires.
|
|
217
|
+
for (const skill of skills) {
|
|
218
|
+
for (const pkg of skill.replacesPackages) {
|
|
219
|
+
const key = normalizeAliasKey(pkg);
|
|
220
|
+
if (!map.has(key)) {
|
|
221
|
+
map.set(key, { type: "skill", name: skill.name });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// 3. Universal MCP fallback -- each connected server alias-keyed by its
|
|
226
|
+
// own name (so `pip install <serverName>` resolves to the server itself
|
|
227
|
+
// even without an operator-supplied replacesPackages entry).
|
|
228
|
+
for (const serverName of connectedServers) {
|
|
229
|
+
const key = normalizeAliasKey(serverName);
|
|
230
|
+
if (!map.has(key)) {
|
|
231
|
+
map.set(key, { type: "mcp", name: serverName });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// Reference-stability guarantee (line 80-82 module docstring):
|
|
235
|
+
// the early-return shortcut above only fires when ALL three input
|
|
236
|
+
// sources are length-zero. Operator hints / skills / connected servers
|
|
237
|
+
// that produce zero map entries (e.g. every hint has
|
|
238
|
+
// `replacesPackages: []`) bypass that shortcut and would otherwise
|
|
239
|
+
// return a fresh empty map -- silently breaking the documented
|
|
240
|
+
// identity-stable empty-result contract. Re-check the size after the
|
|
241
|
+
// loops complete and collapse to the shared sentinel when empty.
|
|
242
|
+
if (map.size === 0)
|
|
243
|
+
return EMPTY_ALIAS_MAP;
|
|
244
|
+
return map;
|
|
245
|
+
},
|
|
246
|
+
getConnectedMcpServers: () => deps.mcpClientManager
|
|
247
|
+
.getAllConnections()
|
|
248
|
+
.filter((c) => c.status === "connected")
|
|
249
|
+
.map((c) => c.name),
|
|
250
|
+
getPromptSkillCapabilities: () => deps.skillRegistry.getPromptSkillCapabilities((skillName, skillKey) => port.getSkillHint(skillName, skillKey)),
|
|
251
|
+
});
|
|
252
|
+
return port;
|
|
253
|
+
}
|