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
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
* plain text rather than sending sanitized-text + original-signature
|
|
23
23
|
* mismatch. Skips `redacted: true` blocks (no readable text to taint).
|
|
24
24
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
25
|
+
* cacheFenceIndex is intentionally NOT consulted to gate guarding. The
|
|
26
|
+
* guard is pure/deterministic — input messages → same guarded output every
|
|
27
|
+
* time — so iter 1 strips, Anthropic caches the guarded prefix, iter 2
|
|
28
|
+
* strips identically, and the cache hits. The prior fence-skip caused
|
|
29
|
+
* per-execution divergence symmetric to the bug found in
|
|
30
|
+
* `signature-replay-scrubber.ts` and `thinking-block-cleaner.ts`: iter 1
|
|
31
|
+
* stripped (fence=-1) and built a surrogate-safe cached prefix, iter 2
|
|
32
|
+
* preserved fence-protected messages (fence>0) and re-introduced
|
|
33
|
+
* surrogate-tainted-with-original-signature blocks at positions Anthropic
|
|
34
|
+
* had cached without them.
|
|
35
35
|
*
|
|
36
36
|
* Immutability: never mutates input; shallow-copies the block and the
|
|
37
37
|
* containing message only when scrubbing is needed. When no scrub fires,
|
|
@@ -69,10 +69,10 @@ export function createSignatureSurrogateGuard(deps) {
|
|
|
69
69
|
for (let i = 0; i < messages.length; i++) {
|
|
70
70
|
// eslint-disable-next-line security/detect-object-injection -- numeric index
|
|
71
71
|
const original = messages[i];
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
72
|
+
// cacheFenceIndex is intentionally NOT consulted here. Stripping
|
|
73
|
+
// uniformly across the array keeps the guarded prefix identical
|
|
74
|
+
// across iterations of the same execution, which is what
|
|
75
|
+
// Anthropic's prompt-cache validator requires.
|
|
76
76
|
const msg = original;
|
|
77
77
|
if (msg.role !== "assistant" || !Array.isArray(msg.content)) {
|
|
78
78
|
// eslint-disable-next-line security/detect-object-injection -- numeric index
|
|
@@ -5,17 +5,16 @@
|
|
|
5
5
|
* keep-window, measured in assistant turns (not turn pairs). Redacted thinking
|
|
6
6
|
* blocks (containing encrypted signatures for API continuity) are always preserved.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* stats only and never gates the strip decision.
|
|
8
|
+
* cacheFenceIndex is intentionally NOT consulted to gate stripping. The
|
|
9
|
+
* cleaner is pure/deterministic — input messages → same cleaned output
|
|
10
|
+
* every time — so iteration 1 strips, Anthropic caches the cleaned prefix,
|
|
11
|
+
* iteration 2 strips identically, and the cache hits. The prior fence-skip
|
|
12
|
+
* caused per-execution divergence: iter 1 stripped (fence=-1) and built a
|
|
13
|
+
* thinking-free cached prefix, iter 2 preserved fence-protected messages
|
|
14
|
+
* (fence>0) and re-introduced thinking blocks at positions Anthropic had
|
|
15
|
+
* cached without them, which the prompt-cache validator rejected with
|
|
16
|
+
* `400 ... blocks cannot be modified`. The cacheFenceIndex on the budget
|
|
17
|
+
* is read for diagnostic stats only and never gates the strip decision.
|
|
19
18
|
*
|
|
20
19
|
* Immutability: never mutates input messages or arrays. Returns new arrays and
|
|
21
20
|
* shallow-copied messages only when changes are needed. When no changes are
|
|
@@ -39,8 +38,7 @@ import type { ContextLayer } from "./types.js";
|
|
|
39
38
|
export declare function createThinkingBlockCleaner(keepTurns: number, onCleaned?: (stats: {
|
|
40
39
|
blocksRemoved: number;
|
|
41
40
|
/** Cache fence index when present on the budget; reported for diagnostics
|
|
42
|
-
* only. Stripping is no longer gated on the fence
|
|
43
|
-
* thinking-block). */
|
|
41
|
+
* only. Stripping is no longer gated on the fence. */
|
|
44
42
|
cacheFenceIndex?: number;
|
|
45
43
|
/** Number of messages protected by the cache fence. Always undefined now
|
|
46
44
|
* because the fence does not protect any messages from stripping. */
|
|
@@ -6,17 +6,16 @@
|
|
|
6
6
|
* keep-window, measured in assistant turns (not turn pairs). Redacted thinking
|
|
7
7
|
* blocks (containing encrypted signatures for API continuity) are always preserved.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* stats only and never gates the strip decision.
|
|
9
|
+
* cacheFenceIndex is intentionally NOT consulted to gate stripping. The
|
|
10
|
+
* cleaner is pure/deterministic — input messages → same cleaned output
|
|
11
|
+
* every time — so iteration 1 strips, Anthropic caches the cleaned prefix,
|
|
12
|
+
* iteration 2 strips identically, and the cache hits. The prior fence-skip
|
|
13
|
+
* caused per-execution divergence: iter 1 stripped (fence=-1) and built a
|
|
14
|
+
* thinking-free cached prefix, iter 2 preserved fence-protected messages
|
|
15
|
+
* (fence>0) and re-introduced thinking blocks at positions Anthropic had
|
|
16
|
+
* cached without them, which the prompt-cache validator rejected with
|
|
17
|
+
* `400 ... blocks cannot be modified`. The cacheFenceIndex on the budget
|
|
18
|
+
* is read for diagnostic stats only and never gates the strip decision.
|
|
20
19
|
*
|
|
21
20
|
* Immutability: never mutates input messages or arrays. Returns new arrays and
|
|
22
21
|
* shallow-copied messages only when changes are needed. When no changes are
|
|
@@ -77,10 +76,10 @@ export function createThinkingBlockCleaner(keepTurns, onCleaned, getKeepTurnsOve
|
|
|
77
76
|
let blocksRemoved = 0;
|
|
78
77
|
const result = new Array(messages.length);
|
|
79
78
|
for (let i = 0; i < messages.length; i++) {
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
//
|
|
79
|
+
// cacheFenceIndex is intentionally NOT consulted here. Stripping
|
|
80
|
+
// uniformly across the array keeps the cleaned prefix identical
|
|
81
|
+
// across iterations of the same execution, which is what
|
|
82
|
+
// Anthropic's prompt-cache validator requires.
|
|
84
83
|
const msg = messages[i];
|
|
85
84
|
if (!oldAssistantIndices.has(i)) {
|
|
86
85
|
// Within keep-window or not an assistant message -- pass through unchanged
|
|
@@ -131,6 +131,21 @@ export interface ContextEngineDeps {
|
|
|
131
131
|
/** Called when observation masking modifies content (maskedCount > 0).
|
|
132
132
|
* Used by cache break detector to suppress false-positive CacheBreakEvents. */
|
|
133
133
|
onContentModified?: () => void;
|
|
134
|
+
/** Optional sink for the signature-replay scrubber's per-apply stats.
|
|
135
|
+
* Receives the SAME shape the scrubber emits to its `onScrubbed` callback,
|
|
136
|
+
* so callers can accumulate per-execute totals without the scrubber owning
|
|
137
|
+
* the accumulator. Invoked alongside the existing snapshot wiring in
|
|
138
|
+
* context-engine.ts (the snapshot consumer at lines ~720-727 still works
|
|
139
|
+
* because field names and shapes are unchanged). */
|
|
140
|
+
onSignatureReplayScrubbed?: (stats: {
|
|
141
|
+
scrubbedAssistantMessages: number;
|
|
142
|
+
blocksAffected: number;
|
|
143
|
+
toolCallsAffected: number;
|
|
144
|
+
latestAssistantIdx: number;
|
|
145
|
+
dropped: number;
|
|
146
|
+
signaturesStripped: number;
|
|
147
|
+
reason?: string;
|
|
148
|
+
}) => void;
|
|
134
149
|
/** Optional getter for the API-grounded token anchor.
|
|
135
150
|
* Returns the last API response's input_tokens and message count.
|
|
136
151
|
* When absent or returning null, estimation falls back to char-based heuristics. */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cache break detection module: two-phase detection with Anthropic adapter.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Pre-call: Records prompt state via provider-specific adapter
|
|
5
5
|
* (system hash, per-tool schema hashes, cache_control metadata hash).
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* Post-call: Compares cacheRead tokens against baseline using
|
|
8
8
|
* AND-based dual threshold (both >5% relative AND >2000 absolute must exceed).
|
|
9
9
|
* Provider-agnostic.
|
|
10
10
|
*
|
|
@@ -202,15 +202,15 @@ export interface CacheBreakDetectorOptions {
|
|
|
202
202
|
*/
|
|
203
203
|
export declare function createCacheBreakDetector(logger: DetectorLogger, options?: CacheBreakDetectorOptions): CacheBreakDetector;
|
|
204
204
|
/**
|
|
205
|
-
* Extract prompt state from Anthropic API payload for
|
|
205
|
+
* Extract prompt state from Anthropic API payload for pre-call recording.
|
|
206
206
|
*
|
|
207
207
|
* CRITICAL: Does NOT mutate the original params object. Creates shallow copies
|
|
208
|
-
* for hashing with cache_control stripped
|
|
209
|
-
* input_schema
|
|
208
|
+
* for hashing with cache_control stripped. Per-tool hashing uses
|
|
209
|
+
* input_schema.
|
|
210
210
|
*/
|
|
211
211
|
export declare function extractAnthropicPromptState(params: Record<string, unknown>, modelId: string, retention: string | undefined, sessionKey: string, agentId: string, headers?: Record<string, string>): RecordPromptStateInput;
|
|
212
212
|
/**
|
|
213
|
-
* Extract Gemini-native prompt state for
|
|
213
|
+
* Extract Gemini-native prompt state for pre-call cache break detection.
|
|
214
214
|
*
|
|
215
215
|
* Gemini payload structure differs from Anthropic:
|
|
216
216
|
* - System prompt: config.systemInstruction (string, not array of blocks)
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Cache break detection module: two-phase detection with Anthropic adapter.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* Pre-call: Records prompt state via provider-specific adapter
|
|
6
6
|
* (system hash, per-tool schema hashes, cache_control metadata hash).
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* Post-call: Compares cacheRead tokens against baseline using
|
|
9
9
|
* AND-based dual threshold (both >5% relative AND >2000 absolute must exceed).
|
|
10
10
|
* Provider-agnostic.
|
|
11
11
|
*
|
|
@@ -467,18 +467,18 @@ const STANDARD_ANTHROPIC_FIELDS = new Set([
|
|
|
467
467
|
"betas",
|
|
468
468
|
]);
|
|
469
469
|
/**
|
|
470
|
-
* Extract prompt state from Anthropic API payload for
|
|
470
|
+
* Extract prompt state from Anthropic API payload for pre-call recording.
|
|
471
471
|
*
|
|
472
472
|
* CRITICAL: Does NOT mutate the original params object. Creates shallow copies
|
|
473
|
-
* for hashing with cache_control stripped
|
|
474
|
-
* input_schema
|
|
473
|
+
* for hashing with cache_control stripped. Per-tool hashing uses
|
|
474
|
+
* input_schema.
|
|
475
475
|
*/
|
|
476
476
|
export function extractAnthropicPromptState(params, modelId, retention, sessionKey, agentId, headers) {
|
|
477
477
|
// Extract tools (do NOT mutate params)
|
|
478
478
|
const tools = Array.isArray(params.tools)
|
|
479
479
|
? params.tools
|
|
480
480
|
: [];
|
|
481
|
-
// Per-tool hashing using input_schema
|
|
481
|
+
// Per-tool hashing using input_schema.
|
|
482
482
|
// Skip server-side tools (tool_search_tool_regex etc.) which lack input_schema.
|
|
483
483
|
const perToolHashes = {};
|
|
484
484
|
const toolNames = [];
|
|
@@ -510,7 +510,7 @@ export function extractAnthropicPromptState(params, modelId, retention, sessionK
|
|
|
510
510
|
return rest;
|
|
511
511
|
});
|
|
512
512
|
const systemHash = computeHash(systemForHash);
|
|
513
|
-
// Hash cache_control metadata separately
|
|
513
|
+
// Hash cache_control metadata separately
|
|
514
514
|
const cacheMetadata = [
|
|
515
515
|
...tools.map((t) => t.cache_control).filter(Boolean),
|
|
516
516
|
...system.map((b) => b.cache_control).filter(Boolean),
|
|
@@ -600,7 +600,7 @@ export function extractAnthropicPromptState(params, modelId, retention, sessionK
|
|
|
600
600
|
// Gemini adapter
|
|
601
601
|
// ---------------------------------------------------------------------------
|
|
602
602
|
/**
|
|
603
|
-
* Extract Gemini-native prompt state for
|
|
603
|
+
* Extract Gemini-native prompt state for pre-call cache break detection.
|
|
604
604
|
*
|
|
605
605
|
* Gemini payload structure differs from Anthropic:
|
|
606
606
|
* - System prompt: config.systemInstruction (string, not array of blocks)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-turn capability-index renderer.
|
|
3
|
+
*
|
|
4
|
+
* Renders the `## Capabilities` block for the dynamic preamble. Lives
|
|
5
|
+
* post-deferral in the executor lifecycle; consumes a `ToolCapabilityPort`
|
|
6
|
+
* for cluster/skill resolution and an `ExcludeDeferralResult` for active
|
|
7
|
+
* vs deferred tool partitioning.
|
|
8
|
+
*
|
|
9
|
+
* Pure-function builder: no logger, no IO, no `Result` envelope, no mutable
|
|
10
|
+
* module state beyond frozen module-level constants. Mirrors the shape of
|
|
11
|
+
* `buildDeferredToolsContext` in `tool-deferral.ts`.
|
|
12
|
+
*
|
|
13
|
+
* IMPORTANT -- cache fence:
|
|
14
|
+
* This module is consumed ONLY by `executor-tool-assembly.ts`. It MUST NOT
|
|
15
|
+
* be imported by `prompt-assembly.ts` -- the static prompt cache prefix MUST
|
|
16
|
+
* stay byte-identical when the skill registry reloads between turns.
|
|
17
|
+
* An architecture-grep enforces this invariant.
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
import type { ToolCapabilityPort } from "@comis/core";
|
|
22
|
+
import type { ExcludeDeferralResult } from "./tool-deferral.js";
|
|
23
|
+
/**
|
|
24
|
+
* Output struct from {@link buildCapabilityIndexContext}. All counts are
|
|
25
|
+
* post-elision -- they reflect what the renderer surfaces, not the upstream
|
|
26
|
+
* input cardinality.
|
|
27
|
+
*/
|
|
28
|
+
export interface CapabilityIndexRenderResult {
|
|
29
|
+
/** Rendered text block. Empty string when the index is gated off or all-zero counts. */
|
|
30
|
+
readonly text: string;
|
|
31
|
+
/** Estimated tokens for the rendered text (`Math.ceil(text.length / CHARS_PER_TOKEN_RATIO)`). */
|
|
32
|
+
readonly capabilityIndexTokens: number;
|
|
33
|
+
/** Number of distinct clusters surfaced. */
|
|
34
|
+
readonly clusterCount: number;
|
|
35
|
+
/** Number of active tools (builtins + active MCP tools). */
|
|
36
|
+
readonly activeToolCount: number;
|
|
37
|
+
/** Number of deferred MCP tools after the orphan-drop (server connected). */
|
|
38
|
+
readonly deferredToolCount: number;
|
|
39
|
+
/** Number of visible eligible prompt skills (port-reported, not rendered count). */
|
|
40
|
+
readonly promptSkillCount: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Build the per-turn capability-index render result.
|
|
44
|
+
*
|
|
45
|
+
* Behavior:
|
|
46
|
+
* - Gate respect: returns {@link EMPTY} when `port.isCapabilityIndexEnabled()` is false.
|
|
47
|
+
* - Empty-input fast path: returns {@link EMPTY} when all three surface counts are zero.
|
|
48
|
+
* - Cluster bucketing: builtins -> `getBuiltinCluster()` (or `"other-tools"`),
|
|
49
|
+
* MCP -> `getMcpServerHint().cluster` (or `"external-integrations"`),
|
|
50
|
+
* skills -> `skill.cluster` (or `"prompt-skills"`).
|
|
51
|
+
* - Orphan-drop: deferred MCP tools whose server is not in the live
|
|
52
|
+
* `getConnectedMcpServers()` snapshot are dropped silently.
|
|
53
|
+
* - Sort: `(priority asc, clusterId asc)` for clusters; `TOOL_ORDER` for
|
|
54
|
+
* builtins (alphabetical fallback for unknowns); alphabetical for MCP
|
|
55
|
+
* servers and skills.
|
|
56
|
+
* - Per-group cap: 8 names + `+N more`.
|
|
57
|
+
* - >32 elision: drop ALL per-cluster name lists; keep headers + counts only.
|
|
58
|
+
* - Forbidden-literal discipline: the rendered text names neither the
|
|
59
|
+
* client-side discovery tool nor the server-side tool search regex tool.
|
|
60
|
+
* The deferred-tools preamble bullet uses the mechanism-neutral
|
|
61
|
+
* `"discovery mechanism available in your active toolspace"` wording.
|
|
62
|
+
* An architecture-grep enforces the file-level invariant.
|
|
63
|
+
*
|
|
64
|
+
* Restart-required note: `tooling.capabilityIndex.enabled` requires a daemon
|
|
65
|
+
* restart to take effect. The renderer respects the port's reported value at
|
|
66
|
+
* render time but does not enforce the restart constraint.
|
|
67
|
+
*
|
|
68
|
+
* @param deferralResult - Output of `applyToolDeferral` (active + deferred tool partition).
|
|
69
|
+
* @param port - The capability port (gate flag, cluster/skill resolution, live runtime view).
|
|
70
|
+
* @returns Frozen {@link CapabilityIndexRenderResult}; identity-stable {@link EMPTY} for the no-op path.
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildCapabilityIndexContext(deferralResult: ExcludeDeferralResult, port: ToolCapabilityPort): CapabilityIndexRenderResult;
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Per-turn capability-index renderer.
|
|
4
|
+
*
|
|
5
|
+
* Renders the `## Capabilities` block for the dynamic preamble. Lives
|
|
6
|
+
* post-deferral in the executor lifecycle; consumes a `ToolCapabilityPort`
|
|
7
|
+
* for cluster/skill resolution and an `ExcludeDeferralResult` for active
|
|
8
|
+
* vs deferred tool partitioning.
|
|
9
|
+
*
|
|
10
|
+
* Pure-function builder: no logger, no IO, no `Result` envelope, no mutable
|
|
11
|
+
* module state beyond frozen module-level constants. Mirrors the shape of
|
|
12
|
+
* `buildDeferredToolsContext` in `tool-deferral.ts`.
|
|
13
|
+
*
|
|
14
|
+
* IMPORTANT -- cache fence:
|
|
15
|
+
* This module is consumed ONLY by `executor-tool-assembly.ts`. It MUST NOT
|
|
16
|
+
* be imported by `prompt-assembly.ts` -- the static prompt cache prefix MUST
|
|
17
|
+
* stay byte-identical when the skill registry reloads between turns.
|
|
18
|
+
* An architecture-grep enforces this invariant.
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
21
|
+
*/
|
|
22
|
+
import { extractMcpServerName } from "@comis/shared";
|
|
23
|
+
import { TOOL_ORDER } from "../bootstrap/sections/tool-descriptions.js";
|
|
24
|
+
import { CHARS_PER_TOKEN_RATIO } from "../context-engine/constants.js";
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Module-level frozen sentinel + constants
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
/**
|
|
29
|
+
* Frozen empty result. Returned when the gate is off or when all three
|
|
30
|
+
* surface counts are zero. Identity-stable so callers can do cheap reference
|
|
31
|
+
* equality checks if useful.
|
|
32
|
+
*/
|
|
33
|
+
const EMPTY = Object.freeze({
|
|
34
|
+
text: "",
|
|
35
|
+
capabilityIndexTokens: 0,
|
|
36
|
+
clusterCount: 0,
|
|
37
|
+
activeToolCount: 0,
|
|
38
|
+
deferredToolCount: 0,
|
|
39
|
+
promptSkillCount: 0,
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* Active-tool count threshold above which all per-cluster name lists are
|
|
43
|
+
* dropped (cluster headers + `(N tools)` counts remain).
|
|
44
|
+
* Constant in v1.1; revisit only if telemetry shows fleets clustering near it.
|
|
45
|
+
*/
|
|
46
|
+
const ELISION_THRESHOLD = 32;
|
|
47
|
+
/**
|
|
48
|
+
* Maximum names rendered per server (active MCP) or per skill cluster
|
|
49
|
+
* before `+N more` truncation.
|
|
50
|
+
*/
|
|
51
|
+
const PER_GROUP_NAME_CAP = 8;
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// Reserved cluster IDs
|
|
54
|
+
//
|
|
55
|
+
// Inlined as string literals at the three fallback sites instead of named
|
|
56
|
+
// constants -- the IDs are part of the user-visible config schema in
|
|
57
|
+
// `packages/core/src/config/schema-tooling.ts`. Renaming them is intentionally
|
|
58
|
+
// not supported -- the cluster ID itself is fixed.
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
// Public renderer
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
/**
|
|
64
|
+
* Build the per-turn capability-index render result.
|
|
65
|
+
*
|
|
66
|
+
* Behavior:
|
|
67
|
+
* - Gate respect: returns {@link EMPTY} when `port.isCapabilityIndexEnabled()` is false.
|
|
68
|
+
* - Empty-input fast path: returns {@link EMPTY} when all three surface counts are zero.
|
|
69
|
+
* - Cluster bucketing: builtins -> `getBuiltinCluster()` (or `"other-tools"`),
|
|
70
|
+
* MCP -> `getMcpServerHint().cluster` (or `"external-integrations"`),
|
|
71
|
+
* skills -> `skill.cluster` (or `"prompt-skills"`).
|
|
72
|
+
* - Orphan-drop: deferred MCP tools whose server is not in the live
|
|
73
|
+
* `getConnectedMcpServers()` snapshot are dropped silently.
|
|
74
|
+
* - Sort: `(priority asc, clusterId asc)` for clusters; `TOOL_ORDER` for
|
|
75
|
+
* builtins (alphabetical fallback for unknowns); alphabetical for MCP
|
|
76
|
+
* servers and skills.
|
|
77
|
+
* - Per-group cap: 8 names + `+N more`.
|
|
78
|
+
* - >32 elision: drop ALL per-cluster name lists; keep headers + counts only.
|
|
79
|
+
* - Forbidden-literal discipline: the rendered text names neither the
|
|
80
|
+
* client-side discovery tool nor the server-side tool search regex tool.
|
|
81
|
+
* The deferred-tools preamble bullet uses the mechanism-neutral
|
|
82
|
+
* `"discovery mechanism available in your active toolspace"` wording.
|
|
83
|
+
* An architecture-grep enforces the file-level invariant.
|
|
84
|
+
*
|
|
85
|
+
* Restart-required note: `tooling.capabilityIndex.enabled` requires a daemon
|
|
86
|
+
* restart to take effect. The renderer respects the port's reported value at
|
|
87
|
+
* render time but does not enforce the restart constraint.
|
|
88
|
+
*
|
|
89
|
+
* @param deferralResult - Output of `applyToolDeferral` (active + deferred tool partition).
|
|
90
|
+
* @param port - The capability port (gate flag, cluster/skill resolution, live runtime view).
|
|
91
|
+
* @returns Frozen {@link CapabilityIndexRenderResult}; identity-stable {@link EMPTY} for the no-op path.
|
|
92
|
+
*/
|
|
93
|
+
export function buildCapabilityIndexContext(deferralResult, port) {
|
|
94
|
+
// Gate (restart-required).
|
|
95
|
+
if (!port.isCapabilityIndexEnabled())
|
|
96
|
+
return EMPTY;
|
|
97
|
+
// Snapshot the live runtime view ONCE per render. Re-querying the port
|
|
98
|
+
// mid-render would risk inconsistent state if a server connect/disconnect
|
|
99
|
+
// happens between two reads.
|
|
100
|
+
const connectedServers = new Set(port.getConnectedMcpServers());
|
|
101
|
+
const visibleSkills = port.getPromptSkillCapabilities();
|
|
102
|
+
// Bucket every input source into a clusterId -> ClusterRender map.
|
|
103
|
+
const clusterMap = new Map();
|
|
104
|
+
// Active builtin / non-MCP tools.
|
|
105
|
+
for (const tool of deferralResult.activeTools) {
|
|
106
|
+
if (extractMcpServerName(tool.name) !== undefined)
|
|
107
|
+
continue;
|
|
108
|
+
const clusterId = port.getBuiltinCluster(tool.name) ?? "other-tools";
|
|
109
|
+
const cluster = ensureCluster(clusterMap, clusterId, port);
|
|
110
|
+
cluster.builtins.push(tool.name);
|
|
111
|
+
}
|
|
112
|
+
// Active MCP tools. Group by server within their cluster.
|
|
113
|
+
for (const tool of deferralResult.activeTools) {
|
|
114
|
+
const server = extractMcpServerName(tool.name);
|
|
115
|
+
if (server === undefined)
|
|
116
|
+
continue;
|
|
117
|
+
const clusterId = port.getMcpServerHint(server)?.cluster ?? "external-integrations";
|
|
118
|
+
const cluster = ensureCluster(clusterMap, clusterId, port);
|
|
119
|
+
const bucket = ensureServerBucket(cluster, server);
|
|
120
|
+
bucket.activeTools.push(tool.name);
|
|
121
|
+
}
|
|
122
|
+
// Deferred MCP tools (with orphan-drop). Non-MCP deferred entries are
|
|
123
|
+
// dropped entirely -- a header-only shell would be misleading because the
|
|
124
|
+
// renderer cannot teach what to do with a non-MCP deferred name.
|
|
125
|
+
let deferredToolCount = 0;
|
|
126
|
+
for (const entry of deferralResult.deferredEntries) {
|
|
127
|
+
const server = extractMcpServerName(entry.name);
|
|
128
|
+
if (server === undefined)
|
|
129
|
+
continue;
|
|
130
|
+
if (!connectedServers.has(server))
|
|
131
|
+
continue; // orphan-drop
|
|
132
|
+
const clusterId = port.getMcpServerHint(server)?.cluster ?? "external-integrations";
|
|
133
|
+
const cluster = ensureCluster(clusterMap, clusterId, port);
|
|
134
|
+
const bucket = ensureServerBucket(cluster, server);
|
|
135
|
+
bucket.deferredCount += 1;
|
|
136
|
+
deferredToolCount += 1;
|
|
137
|
+
}
|
|
138
|
+
// Visible prompt skills. The port has already merged
|
|
139
|
+
// operator > comis.capability > fallback; we only resolve cluster.
|
|
140
|
+
for (const skill of visibleSkills) {
|
|
141
|
+
const clusterId = skill.cluster ?? "prompt-skills";
|
|
142
|
+
const cluster = ensureCluster(clusterMap, clusterId, port);
|
|
143
|
+
cluster.skills.push(skill);
|
|
144
|
+
}
|
|
145
|
+
// Compute totals.
|
|
146
|
+
let activeToolCount = 0;
|
|
147
|
+
for (const cluster of clusterMap.values()) {
|
|
148
|
+
activeToolCount += cluster.builtins.length;
|
|
149
|
+
for (const bucket of cluster.mcpServers.values()) {
|
|
150
|
+
activeToolCount += bucket.activeTools.length;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Empty-input fast path.
|
|
154
|
+
if (activeToolCount + deferredToolCount + visibleSkills.length === 0) {
|
|
155
|
+
return EMPTY;
|
|
156
|
+
}
|
|
157
|
+
// Sort clusters: (priority asc, clusterId asc).
|
|
158
|
+
const orderedClusters = [...clusterMap.values()].sort((a, b) => a.config.priority - b.config.priority || a.id.localeCompare(b.id));
|
|
159
|
+
// Determine elision: when total active exceeds 32, drop all per-cluster
|
|
160
|
+
// name lists (cluster headers + `(N tools)` counts remain).
|
|
161
|
+
const eliminateNameLists = activeToolCount > ELISION_THRESHOLD;
|
|
162
|
+
// Render the text envelope.
|
|
163
|
+
const lines = [];
|
|
164
|
+
lines.push("## Capabilities");
|
|
165
|
+
lines.push("");
|
|
166
|
+
lines.push("Map the task to one of these connected capabilities before using exec to install libraries.");
|
|
167
|
+
lines.push("");
|
|
168
|
+
lines.push("- Active tools: callable now.");
|
|
169
|
+
lines.push("- Deferred tools: connected, but load them through the discovery mechanism available in your active toolspace before invoking them.");
|
|
170
|
+
lines.push("- Prompt skills: available instructions/workflows; use the existing skill-loading mechanism when the task matches.");
|
|
171
|
+
for (const cluster of orderedClusters) {
|
|
172
|
+
lines.push("");
|
|
173
|
+
lines.push(`### ${cluster.config.label}`);
|
|
174
|
+
if (cluster.config.preferOverInstalls) {
|
|
175
|
+
lines.push("Prefer connected tools and available skills over installing equivalent libraries.");
|
|
176
|
+
}
|
|
177
|
+
if (eliminateNameLists) {
|
|
178
|
+
// Headers + count-only.
|
|
179
|
+
const tools = cluster.builtins.length + sumActiveServerTools(cluster);
|
|
180
|
+
lines.push(`(${tools} tools)`);
|
|
181
|
+
const deferredHere = sumDeferredServerTools(cluster);
|
|
182
|
+
if (deferredHere > 0) {
|
|
183
|
+
lines.push(`(${deferredHere} deferred tools)`);
|
|
184
|
+
}
|
|
185
|
+
if (cluster.skills.length > 0) {
|
|
186
|
+
lines.push(`(${cluster.skills.length} skills)`);
|
|
187
|
+
}
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
appendClusterBody(lines, cluster);
|
|
191
|
+
}
|
|
192
|
+
const text = lines.join("\n");
|
|
193
|
+
const clusterCount = orderedClusters.length;
|
|
194
|
+
return Object.freeze({
|
|
195
|
+
text,
|
|
196
|
+
capabilityIndexTokens: Math.ceil(text.length / CHARS_PER_TOKEN_RATIO),
|
|
197
|
+
clusterCount,
|
|
198
|
+
activeToolCount,
|
|
199
|
+
deferredToolCount,
|
|
200
|
+
promptSkillCount: visibleSkills.length,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
// Internal helpers (file-scoped; not exported)
|
|
205
|
+
// ---------------------------------------------------------------------------
|
|
206
|
+
/**
|
|
207
|
+
* Lookup-or-create a {@link ClusterRender} bucket for a cluster ID. The
|
|
208
|
+
* cluster's {@link ClusterConfig} resolves through the port; missing config
|
|
209
|
+
* for a non-reserved ID falls back to a synthesized default labelled by the
|
|
210
|
+
* cluster ID itself. The wiring layer emits a WARN for missing configs; the
|
|
211
|
+
* renderer only renders.
|
|
212
|
+
*/
|
|
213
|
+
function ensureCluster(map, clusterId, port) {
|
|
214
|
+
const existing = map.get(clusterId);
|
|
215
|
+
if (existing)
|
|
216
|
+
return existing;
|
|
217
|
+
const config = port.getClusterConfig(clusterId) ?? synthesizeClusterConfig(clusterId);
|
|
218
|
+
const cluster = {
|
|
219
|
+
id: clusterId,
|
|
220
|
+
config,
|
|
221
|
+
builtins: [],
|
|
222
|
+
mcpServers: new Map(),
|
|
223
|
+
skills: [],
|
|
224
|
+
};
|
|
225
|
+
map.set(clusterId, cluster);
|
|
226
|
+
return cluster;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Synthesize a {@link ClusterConfig} for a cluster ID the port does not
|
|
230
|
+
* recognize. This keeps the renderer total pure -- it never throws on
|
|
231
|
+
* misconfiguration. The wiring layer owns the WARN path; here we render
|
|
232
|
+
* with the cluster ID as both label and a sentinel `9999` priority (sorts
|
|
233
|
+
* last) and `preferOverInstalls: false`.
|
|
234
|
+
*/
|
|
235
|
+
function synthesizeClusterConfig(clusterId) {
|
|
236
|
+
return Object.freeze({
|
|
237
|
+
label: clusterId,
|
|
238
|
+
priority: 9999,
|
|
239
|
+
preferOverInstalls: false,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
function ensureServerBucket(cluster, server) {
|
|
243
|
+
const existing = cluster.mcpServers.get(server);
|
|
244
|
+
if (existing)
|
|
245
|
+
return existing;
|
|
246
|
+
const bucket = { activeTools: [], deferredCount: 0 };
|
|
247
|
+
cluster.mcpServers.set(server, bucket);
|
|
248
|
+
return bucket;
|
|
249
|
+
}
|
|
250
|
+
function sumActiveServerTools(cluster) {
|
|
251
|
+
let total = 0;
|
|
252
|
+
for (const bucket of cluster.mcpServers.values())
|
|
253
|
+
total += bucket.activeTools.length;
|
|
254
|
+
return total;
|
|
255
|
+
}
|
|
256
|
+
function sumDeferredServerTools(cluster) {
|
|
257
|
+
let total = 0;
|
|
258
|
+
for (const bucket of cluster.mcpServers.values())
|
|
259
|
+
total += bucket.deferredCount;
|
|
260
|
+
return total;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Sort builtin/non-MCP tool names within a cluster: known names follow
|
|
264
|
+
* {@link TOOL_ORDER}; unknown names fall through to alphabetical via
|
|
265
|
+
* `localeCompare`.
|
|
266
|
+
*/
|
|
267
|
+
function sortBuiltinsInCluster(builtins) {
|
|
268
|
+
const orderIndex = (name) => {
|
|
269
|
+
const idx = TOOL_ORDER.indexOf(name);
|
|
270
|
+
return idx === -1 ? Number.MAX_SAFE_INTEGER : idx;
|
|
271
|
+
};
|
|
272
|
+
return builtins.slice().sort((a, b) => {
|
|
273
|
+
const diff = orderIndex(a) - orderIndex(b);
|
|
274
|
+
if (diff !== 0)
|
|
275
|
+
return diff;
|
|
276
|
+
return a.localeCompare(b);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Append the body of a single cluster (after its `### Label` heading and
|
|
281
|
+
* optional callout have already been pushed) to the line buffer. Renders:
|
|
282
|
+
* 1. Builtin/non-MCP tool names (TOOL_ORDER sort, alphabetical fallback).
|
|
283
|
+
* 2. MCP servers alphabetical, each with capped `+N more` tool list and
|
|
284
|
+
* optional `(N deferred)` suffix when deferred entries exist.
|
|
285
|
+
* 3. Prompt skills alphabetical, capped at 8 + `+N more`.
|
|
286
|
+
*
|
|
287
|
+
* Elision is handled by the caller (skip this body, emit count-only lines
|
|
288
|
+
* instead).
|
|
289
|
+
*/
|
|
290
|
+
function appendClusterBody(lines, cluster) {
|
|
291
|
+
if (cluster.builtins.length > 0) {
|
|
292
|
+
const sorted = sortBuiltinsInCluster(cluster.builtins);
|
|
293
|
+
lines.push(`- ${sorted.join(", ")}`);
|
|
294
|
+
}
|
|
295
|
+
const sortedServers = [...cluster.mcpServers.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
296
|
+
for (const [server, bucket] of sortedServers) {
|
|
297
|
+
const sortedTools = bucket.activeTools.slice().sort((a, b) => a.localeCompare(b));
|
|
298
|
+
const shortNames = sortedTools.map((full) => stripServerPrefix(full, server));
|
|
299
|
+
const head = shortNames.slice(0, PER_GROUP_NAME_CAP);
|
|
300
|
+
const overflow = shortNames.length - head.length;
|
|
301
|
+
const namesPart = head.length === 0
|
|
302
|
+
? ""
|
|
303
|
+
: `: ${head.join(", ")}${overflow > 0 ? `, +${overflow} more` : ""}`;
|
|
304
|
+
const deferredPart = bucket.deferredCount > 0
|
|
305
|
+
? ` (${bucket.deferredCount} deferred)`
|
|
306
|
+
: "";
|
|
307
|
+
lines.push(`- [${server}] (${bucket.activeTools.length} tools${deferredPart})${namesPart}`);
|
|
308
|
+
}
|
|
309
|
+
if (cluster.skills.length > 0) {
|
|
310
|
+
const sortedSkills = cluster.skills
|
|
311
|
+
.slice()
|
|
312
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
313
|
+
const head = sortedSkills.slice(0, PER_GROUP_NAME_CAP);
|
|
314
|
+
const overflow = sortedSkills.length - head.length;
|
|
315
|
+
const names = head.map((s) => s.name).join(", ");
|
|
316
|
+
const overflowText = overflow > 0 ? `, +${overflow} more` : "";
|
|
317
|
+
lines.push(`- skills: ${names}${overflowText}`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Strip the `mcp__<server>--` prefix from a sanitized MCP tool name so the
|
|
322
|
+
* cluster body shows compact short names. Falls back to the full name if
|
|
323
|
+
* the prefix does not match (defensive -- the upstream parser already
|
|
324
|
+
* validated the shape).
|
|
325
|
+
*/
|
|
326
|
+
function stripServerPrefix(toolName, server) {
|
|
327
|
+
const prefix = `mcp__${server}--`;
|
|
328
|
+
return toolName.startsWith(prefix) ? toolName.slice(prefix.length) : toolName;
|
|
329
|
+
}
|