typeclaw 0.48.13 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/agent/attention-escalation.d.ts +18 -0
- package/dist/types/agent/auth.d.ts +7 -0
- package/dist/types/agent/compaction.d.ts +8 -0
- package/dist/types/agent/git-nudge.d.ts +6 -0
- package/dist/types/agent/guard-types.d.ts +25 -0
- package/dist/types/agent/guards.d.ts +7 -0
- package/dist/types/agent/idle-compaction.d.ts +7 -0
- package/dist/types/agent/index.d.ts +163 -0
- package/dist/types/agent/live-subagents.d.ts +113 -0
- package/dist/types/agent/llm-replay-sanitizer.d.ts +11 -0
- package/dist/types/agent/loop-guard.d.ts +67 -0
- package/dist/types/agent/model-fallback.d.ts +29 -0
- package/dist/types/agent/model-overrides.d.ts +8 -0
- package/dist/types/agent/multimodal/index.d.ts +2 -0
- package/dist/types/agent/multimodal/look-at.d.ts +60 -0
- package/dist/types/agent/multimodal/looker.d.ts +61 -0
- package/dist/types/agent/multimodal/read-redirect.d.ts +6 -0
- package/dist/types/agent/network/response-body.d.ts +1 -0
- package/dist/types/agent/network/safe-http.d.ts +46 -0
- package/dist/types/agent/plugin-tools.d.ts +129 -0
- package/dist/types/agent/proactive-next-step-nudge.d.ts +2 -0
- package/dist/types/agent/prompt-cache-key.d.ts +3 -0
- package/dist/types/agent/provider-error.d.ts +23 -0
- package/dist/types/agent/reload-tool.d.ts +10 -0
- package/dist/types/agent/restart/index.d.ts +31 -0
- package/dist/types/agent/restart-handoff/index.d.ts +32 -0
- package/dist/types/agent/restart-handoff/paths.d.ts +1 -0
- package/dist/types/agent/retry-same-ref.d.ts +41 -0
- package/dist/types/agent/reviewer-activity.d.ts +3 -0
- package/dist/types/agent/reviewer-bash-policy.d.ts +8 -0
- package/dist/types/agent/self.d.ts +1 -0
- package/dist/types/agent/session-meta.d.ts +28 -0
- package/dist/types/agent/session-origin.d.ts +65 -0
- package/dist/types/agent/subagent-cache-keepalive.d.ts +38 -0
- package/dist/types/agent/subagent-completion-reminder.d.ts +29 -0
- package/dist/types/agent/subagent-drain.d.ts +25 -0
- package/dist/types/agent/subagent-session.d.ts +3 -0
- package/dist/types/agent/subagents.d.ts +153 -0
- package/dist/types/agent/system-prompt.d.ts +7 -0
- package/dist/types/agent/throttle-circuit.d.ts +25 -0
- package/dist/types/agent/todo/continuation-policy.d.ts +54 -0
- package/dist/types/agent/todo/continuation-state.d.ts +11 -0
- package/dist/types/agent/todo/continuation-wiring.d.ts +32 -0
- package/dist/types/agent/todo/continuation.d.ts +21 -0
- package/dist/types/agent/todo/scope.d.ts +6 -0
- package/dist/types/agent/todo/store.d.ts +16 -0
- package/dist/types/agent/tool-error-remediation.d.ts +1 -0
- package/dist/types/agent/tool-file-safety.d.ts +78 -0
- package/dist/types/agent/tool-not-found-nudge.d.ts +9 -0
- package/dist/types/agent/tool-result-budget.d.ts +15 -0
- package/dist/types/agent/tools/channel-disengage.d.ts +18 -0
- package/dist/types/agent/tools/channel-edit.d.ts +19 -0
- package/dist/types/agent/tools/channel-fetch-attachment.d.ts +36 -0
- package/dist/types/agent/tools/channel-handoff.d.ts +13 -0
- package/dist/types/agent/tools/channel-history-render.d.ts +3 -0
- package/dist/types/agent/tools/channel-history.d.ts +25 -0
- package/dist/types/agent/tools/channel-log.d.ts +5 -0
- package/dist/types/agent/tools/channel-react.d.ts +23 -0
- package/dist/types/agent/tools/channel-read.d.ts +27 -0
- package/dist/types/agent/tools/channel-reply.d.ts +47 -0
- package/dist/types/agent/tools/channel-send.d.ts +42 -0
- package/dist/types/agent/tools/channel-session-search.d.ts +10 -0
- package/dist/types/agent/tools/curl-impersonate.d.ts +37 -0
- package/dist/types/agent/tools/ddg.d.ts +18 -0
- package/dist/types/agent/tools/grant-role.d.ts +25 -0
- package/dist/types/agent/tools/keyed-semaphore.d.ts +10 -0
- package/dist/types/agent/tools/post-github-review.d.ts +38 -0
- package/dist/types/agent/tools/restart.d.ts +25 -0
- package/dist/types/agent/tools/runtime-notice.d.ts +3 -0
- package/dist/types/agent/tools/search-retry.d.ts +16 -0
- package/dist/types/agent/tools/skip-response.d.ts +17 -0
- package/dist/types/agent/tools/spawn-subagent.d.ts +77 -0
- package/dist/types/agent/tools/stream-snapshot.d.ts +23 -0
- package/dist/types/agent/tools/subagent-access.d.ts +20 -0
- package/dist/types/agent/tools/subagent-cancel.d.ts +23 -0
- package/dist/types/agent/tools/subagent-output.d.ts +50 -0
- package/dist/types/agent/tools/todo/index.d.ts +14 -0
- package/dist/types/agent/tools/webfetch/adaptive-html.d.ts +29 -0
- package/dist/types/agent/tools/webfetch/fetch.d.ts +26 -0
- package/dist/types/agent/tools/webfetch/html-lexical.d.ts +27 -0
- package/dist/types/agent/tools/webfetch/index.d.ts +1 -0
- package/dist/types/agent/tools/webfetch/inline-style-visibility.d.ts +3 -0
- package/dist/types/agent/tools/webfetch/strategies/grep.d.ts +11 -0
- package/dist/types/agent/tools/webfetch/strategies/jq.d.ts +4 -0
- package/dist/types/agent/tools/webfetch/strategies/raw.d.ts +1 -0
- package/dist/types/agent/tools/webfetch/strategies/readability.d.ts +16 -0
- package/dist/types/agent/tools/webfetch/strategies/selector.d.ts +4 -0
- package/dist/types/agent/tools/webfetch/strategies/snapshot.d.ts +1 -0
- package/dist/types/agent/tools/webfetch/tool.d.ts +15 -0
- package/dist/types/agent/tools/webfetch/types.d.ts +32 -0
- package/dist/types/agent/tools/websearch.d.ts +17 -0
- package/dist/types/agent/tools/wikipedia.d.ts +7 -0
- package/dist/types/agent/tools-without-local-file-operands.d.ts +1 -0
- package/dist/types/agent/turn-runner.d.ts +36 -0
- package/dist/types/agent-messenger/config-dir.d.ts +19 -0
- package/dist/types/browser/dockerfile.d.ts +2 -0
- package/dist/types/browser/registry.d.ts +49 -0
- package/dist/types/bundled-plugins/bun-hygiene/policy.d.ts +18 -0
- package/dist/types/bundled-plugins/github-cli-auth/git-askpass.d.ts +5 -0
- package/dist/types/bundled-plugins/guard/keys.d.ts +6 -0
- package/dist/types/bundled-plugins/guard/policies/managed-config.d.ts +7 -0
- package/dist/types/bundled-plugins/guard/policies/memory-topics-delete.d.ts +11 -0
- package/dist/types/bundled-plugins/guard/policies/memory-topics-write.d.ts +7 -0
- package/dist/types/bundled-plugins/guard/policies/non-workspace-write.d.ts +9 -0
- package/dist/types/bundled-plugins/guard/policies/skill-authoring.d.ts +20 -0
- package/dist/types/bundled-plugins/guard/policies/uncommitted-changes.d.ts +12 -0
- package/dist/types/bundled-plugins/guard/policy.d.ts +11 -0
- package/dist/types/bundled-plugins/memory/secret-detector.d.ts +11 -0
- package/dist/types/bundled-plugins/memory/slug.d.ts +4 -0
- package/dist/types/bundled-plugins/security/permissions.d.ts +20 -0
- package/dist/types/bundled-plugins/security/policies/private-surface-read.d.ts +34 -0
- package/dist/types/bundled-plugins/security/policies/ssrf.d.ts +18 -0
- package/dist/types/bundled-plugins/security/policy.d.ts +4 -0
- package/dist/types/channels/adapter-namespace.d.ts +2 -0
- package/dist/types/channels/adapters/mention-hints.d.ts +12 -0
- package/dist/types/channels/adapters/webex-id-ref.d.ts +5 -0
- package/dist/types/channels/background-handoff.d.ts +56 -0
- package/dist/types/channels/background-obligations.d.ts +135 -0
- package/dist/types/channels/catch-up.d.ts +26 -0
- package/dist/types/channels/commands.d.ts +2 -0
- package/dist/types/channels/completion-claim.d.ts +20 -0
- package/dist/types/channels/continuation-willingness.d.ts +1 -0
- package/dist/types/channels/continuity-types.d.ts +75 -0
- package/dist/types/channels/describe-error.d.ts +1 -0
- package/dist/types/channels/engagement.d.ts +34 -0
- package/dist/types/channels/github-false-receipt.d.ts +20 -0
- package/dist/types/channels/github-repo.d.ts +2 -0
- package/dist/types/channels/github-rereview-guard.d.ts +24 -0
- package/dist/types/channels/github-review-check.d.ts +135 -0
- package/dist/types/channels/github-review-claim.d.ts +3 -0
- package/dist/types/channels/github-review-turn-ledger.d.ts +71 -0
- package/dist/types/channels/github-review-verdict-coordinator.d.ts +117 -0
- package/dist/types/channels/github-token-bridge.d.ts +20 -0
- package/dist/types/channels/github-verdict-activity.d.ts +12 -0
- package/dist/types/channels/inbound-journal.d.ts +272 -0
- package/dist/types/channels/last-alive.d.ts +3 -0
- package/dist/types/channels/membership-cache.d.ts +27 -0
- package/dist/types/channels/membership.d.ts +21 -0
- package/dist/types/channels/outbound-flood-filter.d.ts +7 -0
- package/dist/types/channels/participants.d.ts +4 -0
- package/dist/types/channels/persistence.d.ts +32 -0
- package/dist/types/channels/recovery-notice.d.ts +26 -0
- package/dist/types/channels/recovery-outbox.d.ts +58 -0
- package/dist/types/channels/router.d.ts +798 -0
- package/dist/types/channels/schema.d.ts +501 -0
- package/dist/types/channels/session-handoff.d.ts +58 -0
- package/dist/types/channels/session-search.d.ts +29 -0
- package/dist/types/channels/types.d.ts +414 -0
- package/dist/types/channels/waiting-reactions.d.ts +25 -0
- package/dist/types/cli/builtins.d.ts +2 -0
- package/dist/types/cli/command-meta.d.ts +9 -0
- package/dist/types/coding-agent/broker-body.d.ts +7 -0
- package/dist/types/coding-agent/broker.d.ts +22 -0
- package/dist/types/coding-agent/claude.d.ts +22 -0
- package/dist/types/coding-agent/codex.d.ts +19 -0
- package/dist/types/coding-agent/index.d.ts +71 -0
- package/dist/types/coding-agent/omo-state.d.ts +2 -0
- package/dist/types/coding-agent/omo-stream.d.ts +22 -0
- package/dist/types/coding-agent/omo.d.ts +133 -0
- package/dist/types/coding-agent/runner.d.ts +35 -0
- package/dist/types/coding-agent/tool.d.ts +27 -0
- package/dist/types/coding-agent/worktree.d.ts +22 -0
- package/dist/types/commands/index.d.ts +45 -0
- package/dist/types/config/config.d.ts +814 -0
- package/dist/types/config/index.d.ts +3 -0
- package/dist/types/config/model-overrides.d.ts +3 -0
- package/dist/types/config/providers.d.ts +1456 -0
- package/dist/types/config/reloadable.d.ts +9 -0
- package/dist/types/container/agent-operation-lock.d.ts +31 -0
- package/dist/types/container/build-cache.d.ts +39 -0
- package/dist/types/container/compose-project.d.ts +1 -0
- package/dist/types/container/controller.d.ts +25 -0
- package/dist/types/container/docker-app.d.ts +23 -0
- package/dist/types/container/exit-reason.d.ts +10 -0
- package/dist/types/container/index.d.ts +14 -0
- package/dist/types/container/log-archive.d.ts +68 -0
- package/dist/types/container/log-colors.d.ts +3 -0
- package/dist/types/container/log-timestamps.d.ts +9 -0
- package/dist/types/container/logs.d.ts +37 -0
- package/dist/types/container/memory-limit.d.ts +13 -0
- package/dist/types/container/memory-oversubscription.d.ts +20 -0
- package/dist/types/container/oom-events.d.ts +18 -0
- package/dist/types/container/port.d.ts +18 -0
- package/dist/types/container/require-running.d.ts +16 -0
- package/dist/types/container/restart.d.ts +32 -0
- package/dist/types/container/shared.d.ts +93 -0
- package/dist/types/container/shell.d.ts +35 -0
- package/dist/types/container/start.d.ts +144 -0
- package/dist/types/container/stats.d.ts +31 -0
- package/dist/types/container/status.d.ts +25 -0
- package/dist/types/container/stop.d.ts +24 -0
- package/dist/types/container/tool-oom-priority.d.ts +4 -0
- package/dist/types/container/verify-running.d.ts +49 -0
- package/dist/types/cron/consumer.d.ts +42 -0
- package/dist/types/cron/count-state.d.ts +24 -0
- package/dist/types/cron/index.d.ts +21 -0
- package/dist/types/cron/list.d.ts +33 -0
- package/dist/types/cron/reloadable.d.ts +11 -0
- package/dist/types/cron/scheduler.d.ts +51 -0
- package/dist/types/cron/schema.d.ts +108 -0
- package/dist/types/dependencies/bin-resolver.d.ts +28 -0
- package/dist/types/dependencies/bins.d.ts +22 -0
- package/dist/types/dependencies/index.d.ts +2 -0
- package/dist/types/git/bound-gc-config.d.ts +4 -0
- package/dist/types/git/hookless.d.ts +1 -0
- package/dist/types/git/reconcile-ignored.d.ts +13 -0
- package/dist/types/git/resolve-agent-git.d.ts +8 -0
- package/dist/types/git/resolve-identity.d.ts +10 -0
- package/dist/types/git/run.d.ts +24 -0
- package/dist/types/git/system-commit.d.ts +2 -0
- package/dist/types/hostd/client.d.ts +13 -0
- package/dist/types/hostd/models.d.ts +1 -0
- package/dist/types/hostd/paths.d.ts +17 -0
- package/dist/types/hostd/protocol.d.ts +93 -0
- package/dist/types/hostd/spawn.d.ts +17 -0
- package/dist/types/hostd/version.d.ts +18 -0
- package/dist/types/init/auto-upgrade.d.ts +41 -0
- package/dist/types/init/cli-version.d.ts +7 -0
- package/dist/types/init/dockerfile.d.ts +34 -0
- package/dist/types/init/ensure-deps.d.ts +17 -0
- package/dist/types/init/env-file.d.ts +3 -0
- package/dist/types/init/gitignore.d.ts +5 -0
- package/dist/types/init/local-source-stamp.d.ts +3 -0
- package/dist/types/init/packagejson.d.ts +7 -0
- package/dist/types/init/paths.d.ts +3 -0
- package/dist/types/init/reconcile-plugin-deps.d.ts +13 -0
- package/dist/types/init/run-bun-install.d.ts +16 -0
- package/dist/types/init/windows-dev-link.d.ts +8 -0
- package/dist/types/mcp/catalog.d.ts +7 -0
- package/dist/types/mcp/client.d.ts +58 -0
- package/dist/types/mcp/manager.d.ts +56 -0
- package/dist/types/mcp/tools.d.ts +23 -0
- package/dist/types/models/embedding-model.d.ts +20 -0
- package/dist/types/models/transformers-version.d.ts +1 -0
- package/dist/types/network/internal-destinations.d.ts +29 -0
- package/dist/types/operations/classify-tool-outcome.d.ts +35 -0
- package/dist/types/operations/incidents.d.ts +47 -0
- package/dist/types/operations/index.d.ts +3 -0
- package/dist/types/operations/remediations.d.ts +25 -0
- package/dist/types/path-safety/real-intended-path.d.ts +9 -0
- package/dist/types/permissions/builtins.d.ts +25 -0
- package/dist/types/permissions/grant.d.ts +19 -0
- package/dist/types/permissions/index.d.ts +6 -0
- package/dist/types/permissions/match-rule.d.ts +28 -0
- package/dist/types/permissions/permissions.d.ts +42 -0
- package/dist/types/permissions/resolve.d.ts +25 -0
- package/dist/types/permissions/schema.d.ts +14 -0
- package/dist/types/plugin/context.d.ts +20 -0
- package/dist/types/plugin/core-tool-names.d.ts +4 -0
- package/dist/types/plugin/define.d.ts +46 -0
- package/dist/types/plugin/hooks.d.ts +52 -0
- package/dist/types/plugin/index.d.ts +11 -0
- package/dist/types/plugin/load-skill.d.ts +14 -0
- package/dist/types/plugin/loader.d.ts +25 -0
- package/dist/types/plugin/manager.d.ts +42 -0
- package/dist/types/plugin/registry.d.ts +73 -0
- package/dist/types/plugin/skills.d.ts +11 -0
- package/dist/types/plugin/types.d.ts +336 -0
- package/dist/types/plugin/zod-introspect.d.ts +11 -0
- package/dist/types/reload/client.d.ts +11 -0
- package/dist/types/reload/docker-exec-client.d.ts +11 -0
- package/dist/types/reload/format.d.ts +2 -0
- package/dist/types/reload/index.d.ts +6 -0
- package/dist/types/reload/recover.d.ts +22 -0
- package/dist/types/reload/registry.d.ts +10 -0
- package/dist/types/reload/types.d.ts +25 -0
- package/dist/types/role-claim/client.d.ts +20 -0
- package/dist/types/role-claim/code.d.ts +4 -0
- package/dist/types/role-claim/controller.d.ts +59 -0
- package/dist/types/role-claim/index.d.ts +6 -0
- package/dist/types/role-claim/match-rule.d.ts +9 -0
- package/dist/types/role-claim/pending.d.ts +35 -0
- package/dist/types/role-claim/reload-after-claim.d.ts +16 -0
- package/dist/types/run/llm-fetch-observer.d.ts +50 -0
- package/dist/types/sandbox/availability.d.ts +21 -0
- package/dist/types/sandbox/build.d.ts +7 -0
- package/dist/types/sandbox/canonical-secrets.d.ts +8 -0
- package/dist/types/sandbox/coding-agent.d.ts +20 -0
- package/dist/types/sandbox/dependency-bins.d.ts +19 -0
- package/dist/types/sandbox/dev-source.d.ts +4 -0
- package/dist/types/sandbox/env-exposure.d.ts +1 -0
- package/dist/types/sandbox/errors.d.ts +20 -0
- package/dist/types/sandbox/hidden-paths.d.ts +11 -0
- package/dist/types/sandbox/index.d.ts +14 -0
- package/dist/types/sandbox/package-install.d.ts +1 -0
- package/dist/types/sandbox/policy.d.ts +71 -0
- package/dist/types/sandbox/privileged-runtime.d.ts +13 -0
- package/dist/types/sandbox/quote.d.ts +2 -0
- package/dist/types/sandbox/runtime-private.d.ts +1 -0
- package/dist/types/sandbox/session-tmp.d.ts +6 -0
- package/dist/types/sandbox/symlinks.d.ts +6 -0
- package/dist/types/sandbox/writable-zones.d.ts +15 -0
- package/dist/types/secrets/coding-agent-auth.d.ts +25 -0
- package/dist/types/secrets/defaults.d.ts +21 -0
- package/dist/types/secrets/export-github-cli-store.d.ts +22 -0
- package/dist/types/secrets/hydrate.d.ts +7 -0
- package/dist/types/secrets/index.d.ts +7 -0
- package/dist/types/secrets/provision-github-cli-store.d.ts +45 -0
- package/dist/types/secrets/refresh-provider-oauth.d.ts +22 -0
- package/dist/types/secrets/resolve.d.ts +14 -0
- package/dist/types/secrets/schema.d.ts +840 -0
- package/dist/types/secrets/storage.d.ts +56 -0
- package/dist/types/shared/host-locale.d.ts +1 -0
- package/dist/types/shared/index.d.ts +5 -0
- package/dist/types/shared/local-time.d.ts +4 -0
- package/dist/types/shared/platform.d.ts +2 -0
- package/dist/types/shared/protocol.d.ts +424 -0
- package/dist/types/shared/style-text.d.ts +3 -0
- package/dist/types/shared/wsl.d.ts +17 -0
- package/dist/types/stream/broker.d.ts +2 -0
- package/dist/types/stream/index.d.ts +2 -0
- package/dist/types/stream/types.d.ts +71 -0
- package/package.json +13 -6
- package/scripts/build-plugin-types.ts +105 -0
- package/scripts/check-plugin-sdk.ts +111 -0
- package/scripts/dump-system-prompt.ts +52 -110
- package/scripts/require-parallel.ts +5 -32
- package/src/agent/guard-types.ts +3 -0
- package/src/agent/guards.ts +4 -0
- package/src/agent/idle-compaction.ts +174 -0
- package/src/agent/index.ts +210 -80
- package/src/agent/live-sessions.ts +2 -2
- package/src/agent/live-subagents.ts +20 -0
- package/src/agent/multimodal/look-at.ts +22 -9
- package/src/agent/plugin-tools.ts +66 -12
- package/src/agent/prompt-cache-key.ts +42 -0
- package/src/agent/provider-error.ts +179 -10
- package/src/agent/restart-handoff/index.ts +7 -14
- package/src/agent/reviewer-activity.ts +68 -0
- package/src/agent/reviewer-bash-policy.ts +41 -1
- package/src/agent/session-origin.ts +58 -9
- package/src/agent/subagent-cache-keepalive.ts +198 -0
- package/src/agent/subagent-session.ts +6 -0
- package/src/agent/subagents.ts +59 -9
- package/src/agent/system-prompt.ts +68 -202
- package/src/agent/todo/continuation-policy.ts +12 -4
- package/src/agent/tool-file-safety.ts +119 -15
- package/src/agent/tool-not-found-nudge.ts +1 -1
- package/src/agent/tools/channel-edit.ts +20 -10
- package/src/agent/tools/channel-fetch-attachment.ts +12 -5
- package/src/agent/tools/channel-handoff.ts +72 -0
- package/src/agent/tools/channel-history-render.ts +2 -1
- package/src/agent/tools/channel-read.ts +57 -10
- package/src/agent/tools/channel-reply.ts +55 -30
- package/src/agent/tools/channel-send.ts +69 -19
- package/src/agent/tools/channel-session-search.ts +35 -0
- package/src/agent/tools/curl-impersonate.ts +22 -6
- package/src/agent/tools/ddg.ts +13 -5
- package/src/agent/tools/post-github-review.ts +77 -15
- package/src/agent/tools/skip-response.ts +2 -2
- package/src/agent/tools/spawn-subagent.ts +190 -23
- package/src/agent/tools/stream-snapshot.ts +15 -2
- package/src/agent/tools/subagent-access.ts +11 -4
- package/src/agent/tools/subagent-output.ts +8 -0
- package/src/browser/bsk-shim.mjs +74 -0
- package/src/browser/dockerfile.ts +84 -0
- package/src/browser/egress.ts +104 -0
- package/src/browser/managed-browser.ts +205 -0
- package/src/browser/registry.ts +110 -0
- package/src/browser/relay.ts +231 -0
- package/src/browser/sandbox-entry.ts +167 -0
- package/src/bundled-plugins/agent-browser/index.ts +2 -0
- package/src/bundled-plugins/backup/README.md +10 -9
- package/src/bundled-plugins/backup/runner.ts +140 -58
- package/src/bundled-plugins/backup/subagents.ts +58 -26
- package/src/bundled-plugins/browser-agent/browser-agent.ts +89 -0
- package/src/bundled-plugins/browser-agent/index.ts +12 -0
- package/src/bundled-plugins/doc-render/index.ts +0 -10
- package/src/bundled-plugins/doc-render/render.ts +83 -111
- package/src/bundled-plugins/doc-render/skills/typeclaw-render-pdf/SKILL.md +152 -257
- package/src/bundled-plugins/github-cli-auth/gh-command.ts +38 -2
- package/src/bundled-plugins/github-cli-auth/git-auth-diagnostic.ts +95 -0
- package/src/bundled-plugins/github-cli-auth/granted-push.ts +135 -0
- package/src/bundled-plugins/github-cli-auth/index.ts +158 -70
- package/src/bundled-plugins/github-cli-auth/review-account.ts +23 -0
- package/src/bundled-plugins/github-cli-auth/review-checkout.ts +9 -2
- package/src/bundled-plugins/github-cli-auth/review-recorder.ts +45 -7
- package/src/bundled-plugins/managed-browser/index.ts +74 -0
- package/src/bundled-plugins/managed-browser/skills/browser-use/browser-use/SKILL.md +27 -0
- package/src/bundled-plugins/managed-browser/skills/browserskill/browserskill/SKILL.md +28 -0
- package/src/bundled-plugins/managed-browser/skills/omowright/omowright/SKILL.md +40 -0
- package/src/bundled-plugins/operator/operator.ts +15 -4
- package/src/bundled-plugins/qa/index.ts +11 -0
- package/src/bundled-plugins/qa/qa.ts +160 -0
- package/src/bundled-plugins/qa/skills/qa-cli.ts +50 -0
- package/src/bundled-plugins/qa/skills/qa-general.ts +30 -0
- package/src/bundled-plugins/qa/skills/qa-http.ts +39 -0
- package/src/bundled-plugins/qa/skills/qa-pr.ts +51 -0
- package/src/bundled-plugins/qa/skills/qa-web.ts +49 -0
- package/src/bundled-plugins/reviewer/skills/code-review.ts +1 -1
- package/src/bundled-plugins/security/index.ts +103 -36
- package/src/bundled-plugins/security/policies/git-exfil.ts +24 -12
- package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +1 -0
- package/src/channels/adapter-namespace.ts +13 -0
- package/src/channels/adapters/discord-bot-reactions.ts +18 -0
- package/src/channels/adapters/discord-bot.ts +219 -72
- package/src/channels/adapters/discord-reactions.ts +18 -0
- package/src/channels/adapters/discord.ts +114 -8
- package/src/channels/adapters/github/inbound.ts +103 -8
- package/src/channels/adapters/github/index.ts +267 -19
- package/src/channels/adapters/github/last-alive.ts +15 -0
- package/src/channels/adapters/github/outbound.ts +54 -18
- package/src/channels/adapters/github/pending-review-store.ts +141 -0
- package/src/channels/adapters/github/permission-guidance.ts +1 -0
- package/src/channels/adapters/github/reactions.ts +100 -0
- package/src/channels/adapters/github/reconcile-cooldown-store.ts +197 -67
- package/src/channels/adapters/github/reconcile-open-prs.ts +418 -33
- package/src/channels/adapters/github/recovery.ts +106 -0
- package/src/channels/adapters/github/review-check.ts +510 -0
- package/src/channels/adapters/github/review-submitter.ts +34 -2
- package/src/channels/adapters/instagram.ts +32 -14
- package/src/channels/adapters/kakaotalk.ts +22 -7
- package/src/channels/adapters/line.ts +18 -3
- package/src/channels/adapters/outbound-account.ts +20 -0
- package/src/channels/adapters/own-reactions.ts +66 -0
- package/src/channels/adapters/recovery-correlation.ts +214 -0
- package/src/channels/adapters/slack-attachment-download.ts +14 -3
- package/src/channels/adapters/slack-bot-author-resolver.ts +4 -3
- package/src/channels/adapters/slack-bot-channel-resolver.ts +9 -6
- package/src/channels/adapters/slack-bot-classify.ts +19 -11
- package/src/channels/adapters/slack-bot-dedupe.ts +111 -28
- package/src/channels/adapters/slack-bot-reactions.ts +18 -0
- package/src/channels/adapters/slack-bot-slash-commands.ts +3 -1
- package/src/channels/adapters/slack-bot.ts +424 -124
- package/src/channels/adapters/slack-classify.ts +26 -4
- package/src/channels/adapters/slack-inbound-revision.ts +96 -0
- package/src/channels/adapters/slack-reactions.ts +18 -0
- package/src/channels/adapters/slack-thread-ts.ts +6 -0
- package/src/channels/adapters/slack.ts +48 -3
- package/src/channels/adapters/teams.ts +14 -4
- package/src/channels/adapters/telegram-bot.ts +56 -10
- package/src/channels/adapters/webex-bot.ts +12 -2
- package/src/channels/adapters/webex.ts +12 -2
- package/src/channels/background-handoff.ts +434 -0
- package/src/channels/background-obligations.ts +893 -0
- package/src/channels/catch-up.ts +137 -0
- package/src/channels/continuation-willingness.ts +2 -2
- package/src/channels/continuity-types.ts +272 -0
- package/src/channels/engagement.ts +17 -1
- package/src/channels/github-false-receipt.ts +3 -3
- package/src/channels/github-rereview-guard.ts +9 -5
- package/src/channels/github-review-check.ts +598 -0
- package/src/channels/github-review-turn-ledger.ts +102 -28
- package/src/channels/github-review-verdict-coordinator.ts +72 -12
- package/src/channels/github-token-bridge.ts +35 -5
- package/src/channels/inbound-journal.ts +1738 -0
- package/src/channels/index.ts +6 -1
- package/src/channels/last-alive.ts +34 -0
- package/src/channels/manager.ts +25 -8
- package/src/channels/recovery-dispatcher.ts +264 -0
- package/src/channels/recovery-notice.ts +94 -0
- package/src/channels/recovery-outbox.ts +459 -0
- package/src/channels/router.ts +2951 -736
- package/src/channels/schema.ts +8 -1
- package/src/channels/session-handoff.fixture.ts +144 -0
- package/src/channels/session-handoff.ts +175 -0
- package/src/channels/session-search.ts +71 -0
- package/src/channels/subagent-completion-bridge.ts +17 -14
- package/src/channels/types.ts +133 -18
- package/src/channels/waiting-reactions.ts +664 -0
- package/src/cli/channel.ts +2 -3
- package/src/cli/compose.ts +7 -4
- package/src/cli/hostd.ts +49 -3
- package/src/cli/init.ts +2 -3
- package/src/cli/inspect.ts +11 -14
- package/src/cli/model.ts +132 -3
- package/src/coding-agent/broker-body.ts +38 -0
- package/src/coding-agent/broker.ts +290 -0
- package/src/coding-agent/claude.ts +95 -0
- package/src/coding-agent/codex.ts +104 -0
- package/src/coding-agent/index.ts +512 -0
- package/src/coding-agent/omo-state.ts +69 -0
- package/src/coding-agent/omo-stream.ts +138 -0
- package/src/coding-agent/omo.ts +192 -0
- package/src/coding-agent/runner.ts +285 -0
- package/src/coding-agent/tool.ts +62 -0
- package/src/coding-agent/worktree.ts +355 -0
- package/src/compose/restart.ts +10 -3
- package/src/compose/start.ts +20 -3
- package/src/config/config.ts +121 -25
- package/src/config/model-overrides.ts +59 -0
- package/src/config/models-mutation.ts +185 -2
- package/src/config/providers-mutation.ts +12 -4
- package/src/config/providers.ts +71 -9
- package/src/container/exit-reason.ts +44 -0
- package/src/container/index.ts +5 -0
- package/src/container/log-archive.ts +51 -13
- package/src/container/memory-limit.ts +1 -1
- package/src/container/memory-oversubscription.ts +36 -6
- package/src/container/oom-events.ts +86 -0
- package/src/container/restart.ts +2 -0
- package/src/container/shared.ts +8 -1
- package/src/container/start.ts +120 -17
- package/src/container/stop.ts +6 -2
- package/src/container/tool-oom-priority.ts +32 -0
- package/src/cron/consumer.ts +10 -4
- package/src/cron/reloadable.ts +23 -2
- package/src/doctor/checks.ts +22 -8
- package/src/hostd/daemon.ts +33 -11
- package/src/hostd/spawn.ts +106 -5
- package/src/hostd/version.ts +20 -0
- package/src/hostd/watchdog.ts +241 -0
- package/src/init/auto-upgrade.ts +7 -1
- package/src/init/dockerfile.ts +112 -602
- package/src/init/index.ts +6 -6
- package/src/init/local-source-stamp.ts +68 -0
- package/src/init/models-dev.ts +4 -0
- package/src/init/validate-api-key.ts +3 -0
- package/src/mcp/client.ts +3 -1
- package/src/operations/classify-tool-outcome.ts +45 -1
- package/src/operations/incidents.ts +10 -5
- package/src/permissions/builtins.ts +7 -0
- package/src/permissions/permissions.ts +18 -9
- package/src/permissions/resolve.ts +7 -1
- package/src/plugin/context.ts +2 -0
- package/src/plugin/core-tool-names.ts +1 -1
- package/src/plugin/define.ts +1 -0
- package/src/plugin/hooks.ts +137 -0
- package/src/plugin/index.ts +7 -0
- package/src/plugin/manager.ts +4 -0
- package/src/plugin/types.ts +66 -1
- package/src/run/background-handoff-boot.ts +86 -0
- package/src/run/bundled-plugins.ts +6 -0
- package/src/run/index.ts +107 -97
- package/src/run/llm-fetch-observer.ts +12 -15
- package/src/run/resource-sample.ts +19 -0
- package/src/sandbox/build.ts +4 -0
- package/src/sandbox/canonical-secrets.ts +4 -0
- package/src/sandbox/coding-agent.ts +214 -0
- package/src/sandbox/dev-source.ts +26 -0
- package/src/sandbox/hidden-paths.ts +16 -2
- package/src/sandbox/policy.ts +1 -0
- package/src/sandbox/runtime-private.ts +4 -1
- package/src/secrets/coding-agent-auth.ts +97 -0
- package/src/secrets/index.ts +0 -16
- package/src/secrets/storage.ts +13 -0
- package/src/server/command-runner.ts +6 -2
- package/src/server/index.ts +101 -40
- package/src/skills/typeclaw-channel-github/SKILL.md +15 -13
- package/src/skills/typeclaw-claude-code/SKILL.md +25 -260
- package/src/skills/typeclaw-claude-code/references/auth-flow.md +7 -23
- package/src/skills/typeclaw-claude-code/references/headless-sessions.md +11 -0
- package/src/skills/typeclaw-claude-code/references/results-and-worktrees.md +13 -0
- package/src/skills/typeclaw-codex-cli/SKILL.md +35 -270
- package/src/skills/typeclaw-codex-cli/references/auth-flow.md +13 -20
- package/src/skills/typeclaw-codex-cli/references/headless-sessions.md +26 -0
- package/src/skills/typeclaw-codex-cli/references/results-and-worktrees.md +28 -0
- package/src/skills/typeclaw-config/SKILL.md +60 -26
- package/src/skills/typeclaw-config/references/dockerfile.md +14 -13
- package/src/skills/typeclaw-cron/SKILL.md +1 -1
- package/src/skills/typeclaw-github-contributing/SKILL.md +3 -3
- package/src/skills/typeclaw-memory/SKILL.md +3 -3
- package/src/skills/typeclaw-monorepo/SKILL.md +1 -1
- package/src/skills/typeclaw-omo-cli/SKILL.md +52 -0
- package/src/skills/typeclaw-omo-cli/references/auth-flow.md +11 -0
- package/src/skills/typeclaw-omo-cli/references/headless-sessions.md +11 -0
- package/src/skills/typeclaw-omo-cli/references/results-and-worktrees.md +23 -0
- package/src/skills/typeclaw-permissions/SKILL.md +7 -7
- package/src/skills/typeclaw-plugins/SKILL.md +15 -15
- package/src/skills/typeclaw-skills/SKILL.md +19 -2
- package/src/skills/typeclaw-troubleshooting/SKILL.md +26 -2
- package/typeclaw.schema.json +448 -6
- package/src/bundled-plugins/doc-render/templates/lib.typ +0 -339
- package/src/bundled-plugins/github-cli-auth/gh-store.ts +0 -733
- package/src/secrets/claude-credentials-json.ts +0 -129
- package/src/secrets/codex-auth-json.ts +0 -102
- package/src/secrets/export-claude-credentials-file.ts +0 -270
- package/src/secrets/export-codex-auth-file.ts +0 -250
- package/src/skills/typeclaw-claude-code/references/stop-hook.md +0 -101
- package/src/skills/typeclaw-claude-code/references/tmux-driving.md +0 -243
- package/src/skills/typeclaw-codex-cli/references/stop-hook.md +0 -92
- package/src/skills/typeclaw-codex-cli/references/tmux-driving.md +0 -239
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type SlackSocketModeSlashCommandArgs,
|
|
6
6
|
} from 'agent-messenger/slackbot'
|
|
7
7
|
|
|
8
|
+
import { CATCH_UP_CONVERSATION_LIMIT, type ListMissedInbound, type MissedInbound } from '@/channels/catch-up'
|
|
8
9
|
import { DEFAULT_ATTACHMENT_MAX_BYTES, enforceAttachmentMetadataSize } from '@/channels/fetch-attachment'
|
|
9
10
|
import {
|
|
10
11
|
MEMBERSHIP_CACHE_TRANSIENT_TTL_MS,
|
|
@@ -15,10 +16,11 @@ import {
|
|
|
15
16
|
type MembershipResolverResult,
|
|
16
17
|
} from '@/channels/membership'
|
|
17
18
|
import { deriveMembershipFromHistory } from '@/channels/membership-from-history'
|
|
18
|
-
import type { ChannelRouter } from '@/channels/router'
|
|
19
|
+
import type { ChannelRouter, ExecuteCommandResult } from '@/channels/router'
|
|
19
20
|
import type { ChannelAdapterConfig } from '@/channels/schema'
|
|
20
21
|
import type {
|
|
21
22
|
ChannelHistoryMessage,
|
|
23
|
+
ChannelKey,
|
|
22
24
|
ChannelListEntry,
|
|
23
25
|
ChannelSelfIdentityResolver,
|
|
24
26
|
FetchAttachmentCallback,
|
|
@@ -39,9 +41,12 @@ import type {
|
|
|
39
41
|
TypingTarget,
|
|
40
42
|
} from '@/channels/types'
|
|
41
43
|
import { chunkMarkdown } from '@/markdown'
|
|
44
|
+
import type { ChannelMessageObservedEvent, ChannelOutboundBeforeEvent, SlackObservedMessage } from '@/plugin'
|
|
42
45
|
|
|
43
46
|
import { describeError } from '../describe-error'
|
|
44
47
|
import { addSlackMentionHints } from './mention-hints'
|
|
48
|
+
import { withOutboundAccount } from './outbound-account'
|
|
49
|
+
import { createBotRecoveryCallbacks, sendBotRecovery } from './recovery-correlation'
|
|
45
50
|
import { downloadSlackAttachment, type SlackAttachmentFetch } from './slack-attachment-download'
|
|
46
51
|
import { createSlackAuthorResolver, type SlackAuthorResolver } from './slack-bot-author-resolver'
|
|
47
52
|
import { createSlackChannelResolver } from './slack-bot-channel-resolver'
|
|
@@ -54,13 +59,14 @@ import {
|
|
|
54
59
|
type SlackInboundAppMentionEvent,
|
|
55
60
|
type SlackInboundMessageEvent,
|
|
56
61
|
} from './slack-bot-classify'
|
|
57
|
-
import { createSlackDedupe } from './slack-bot-dedupe'
|
|
62
|
+
import { createSlackDedupe, type SlackDedupeReservation } from './slack-bot-dedupe'
|
|
58
63
|
import { createSlackEditMessageCallback } from './slack-bot-edit'
|
|
59
64
|
import {
|
|
60
65
|
createSlackReactionCallback,
|
|
61
66
|
createSlackRemoveReactionCallback,
|
|
62
67
|
encodeSlackReactionRef,
|
|
63
68
|
} from './slack-bot-reactions'
|
|
69
|
+
import { createSlackOwnReactionCallbacks } from './slack-bot-reactions'
|
|
64
70
|
import { enrichSlackReferenceContext } from './slack-bot-reference'
|
|
65
71
|
import {
|
|
66
72
|
buildSlashAckPayload,
|
|
@@ -69,9 +75,12 @@ import {
|
|
|
69
75
|
parseThreadCommand,
|
|
70
76
|
SLACK_SLASH_REPLY_FAILED,
|
|
71
77
|
type ThreadCommandInput,
|
|
78
|
+
type SlashAckPayload,
|
|
72
79
|
} from './slack-bot-slash-commands'
|
|
73
80
|
import { slackTsToMillis } from './slack-bot-time'
|
|
74
81
|
import { toSlackMrkdwn } from './slack-format'
|
|
82
|
+
import { admitSlackInbound, type SlackInboundSource } from './slack-inbound-revision'
|
|
83
|
+
import { invalidSlackThreadTs } from './slack-thread-ts'
|
|
75
84
|
|
|
76
85
|
// One slash command per logical agent gesture. Mirrors the discord-bot
|
|
77
86
|
// SLASH_COMMANDS constant so the cross-platform set stays consistent — when
|
|
@@ -99,74 +108,80 @@ export type SlackBotAdapterLoggerLike = {
|
|
|
99
108
|
}
|
|
100
109
|
|
|
101
110
|
export type SlashCommandHandlerDeps = {
|
|
102
|
-
router: Pick<ChannelRouter, 'executeCommand'>
|
|
111
|
+
router: Pick<ChannelRouter, 'executeCommand'> & Partial<Pick<ChannelRouter, 'reviewOutbound' | 'hasOutboundReviewer'>>
|
|
103
112
|
knownCommandNames: ReadonlySet<string>
|
|
104
113
|
logger: SlackBotAdapterLoggerLike
|
|
105
114
|
formatChannelTag: (workspace: string, chat: string) => Promise<string>
|
|
115
|
+
postSlashResponse?: (url: string, payload: SlashAckPayload) => Promise<number>
|
|
106
116
|
}
|
|
107
117
|
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
// "/stop didn't respond in time". The synchronous executeCommand happy
|
|
113
|
-
// path is fast (in-memory map lookup + abort), so ack-after-execute is
|
|
114
|
-
// safe; everything else (formatChannelTag, post-ack logging) runs after.
|
|
115
|
-
//
|
|
116
|
-
// Ack failure handling: a thrown ack on the happy path is logged but does
|
|
117
|
-
// NOT trigger the catch-all error-ack below, which would attempt a second
|
|
118
|
-
// ack call and break the exactly-once contract.
|
|
118
|
+
// With a reviewer, acknowledge immediately and publish exactly one ephemeral
|
|
119
|
+
// response through Slack's response_url. Slow review must not consume Slack's
|
|
120
|
+
// three-second transport-ack budget. Without a safe response URL, fail open to
|
|
121
|
+
// the original immediate ack rather than losing an authorized command response.
|
|
119
122
|
export function createSlashCommandHandler(
|
|
120
123
|
deps: SlashCommandHandlerDeps,
|
|
121
124
|
): (args: SlackSocketModeSlashCommandArgs) => Promise<void> {
|
|
122
125
|
return async ({ ack, body }) => {
|
|
126
|
+
const responseUrl = safeSlashResponseUrl(body.response_url)
|
|
127
|
+
const deferred =
|
|
128
|
+
deps.router.hasOutboundReviewer?.() === true &&
|
|
129
|
+
deps.router.reviewOutbound !== undefined &&
|
|
130
|
+
deps.postSlashResponse !== undefined &&
|
|
131
|
+
responseUrl !== undefined
|
|
132
|
+
const acknowledge = (text?: string) => {
|
|
133
|
+
try {
|
|
134
|
+
if (text === undefined) ack()
|
|
135
|
+
else ack(buildSlashAckPayload(text))
|
|
136
|
+
} catch {
|
|
137
|
+
// Ack is attempted once, even if the transport throws.
|
|
138
|
+
deps.logger.warn('[slack-bot] slash command ack failed')
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (deferred) acknowledge()
|
|
142
|
+
const reply = async (text: string, workspace: string, chat: string) => {
|
|
143
|
+
if (!deferred) {
|
|
144
|
+
acknowledge(text)
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
const reviewed = await reviewControlReply(deps, {
|
|
148
|
+
adapter: 'slack-bot',
|
|
149
|
+
workspace,
|
|
150
|
+
chat,
|
|
151
|
+
text,
|
|
152
|
+
op: 'send',
|
|
153
|
+
source: 'system',
|
|
154
|
+
outputKind: 'meta',
|
|
155
|
+
})
|
|
156
|
+
try {
|
|
157
|
+
const status = await deps.postSlashResponse!(responseUrl!, buildSlashAckPayload(reviewed))
|
|
158
|
+
if (status < 200 || status >= 300) {
|
|
159
|
+
deps.logger.warn(`[slack-bot] slash response failed status=${status}`)
|
|
160
|
+
}
|
|
161
|
+
} catch {
|
|
162
|
+
// response_url is a credential; neither it nor the HTTP error is logged.
|
|
163
|
+
deps.logger.warn('[slack-bot] slash response transport failed')
|
|
164
|
+
}
|
|
165
|
+
}
|
|
123
166
|
const parsed = parseSlashCommand(body, deps.knownCommandNames)
|
|
124
167
|
if (parsed.kind === 'ignore') {
|
|
125
168
|
deps.logger.warn(`[slack-bot] slash command dropped reason=${parsed.reason} command=${body.command}`)
|
|
126
|
-
|
|
127
|
-
ack(buildSlashAckPayload(SLACK_SLASH_REPLY_FAILED))
|
|
128
|
-
} catch (err) {
|
|
129
|
-
deps.logger.warn(`[slack-bot] slash command ack (drop path) failed: ${describeError(err)}`)
|
|
130
|
-
}
|
|
169
|
+
await reply(SLACK_SLASH_REPLY_FAILED, body.team_id ?? '', body.channel_id ?? '')
|
|
131
170
|
return
|
|
132
171
|
}
|
|
133
172
|
const { command } = parsed
|
|
134
|
-
|
|
135
|
-
// Pre-ACK log: bare ids only (no formatChannelTag — would burn ack budget
|
|
136
|
-
// on a slow Slack API minute via the channel-name resolver).
|
|
137
173
|
deps.logger.info(
|
|
138
174
|
`[slack-bot] slash /${command.name} invoker=${command.invokerId} team=${command.key.workspace} channel=${command.key.chat}`,
|
|
139
175
|
)
|
|
140
|
-
|
|
141
|
-
let result: Awaited<ReturnType<typeof deps.router.executeCommand>>
|
|
176
|
+
let result: ExecuteCommandResult
|
|
142
177
|
try {
|
|
143
|
-
result = await deps.router.executeCommand(command.key, command.name, {
|
|
144
|
-
invokerId: command.invokerId,
|
|
145
|
-
})
|
|
178
|
+
result = await deps.router.executeCommand(command.key, command.name, { invokerId: command.invokerId })
|
|
146
179
|
} catch (err) {
|
|
147
180
|
deps.logger.error(`[slack-bot] slash command handler failed: ${describeError(err)}`)
|
|
148
|
-
|
|
149
|
-
ack(buildSlashAckPayload(SLACK_SLASH_REPLY_FAILED))
|
|
150
|
-
} catch (ackErr) {
|
|
151
|
-
deps.logger.warn(`[slack-bot] slash command error-ack failed: ${describeError(ackErr)}`)
|
|
152
|
-
}
|
|
181
|
+
await reply(SLACK_SLASH_REPLY_FAILED, command.key.workspace, command.key.chat)
|
|
153
182
|
return
|
|
154
183
|
}
|
|
155
|
-
|
|
156
|
-
const replyContent = commandResultReply(result)
|
|
157
|
-
|
|
158
|
-
// Final ack on the happy path: own try/catch so a thrown ack here does
|
|
159
|
-
// NOT cascade into the error-path ack above (which would violate the
|
|
160
|
-
// exactly-once contract). The abort already happened server-side; only
|
|
161
|
-
// the user-visible confirmation is lost.
|
|
162
|
-
try {
|
|
163
|
-
ack(buildSlashAckPayload(replyContent))
|
|
164
|
-
} catch (err) {
|
|
165
|
-
deps.logger.warn(`[slack-bot] slash command ack failed: ${describeError(err)}`)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Decorative post-ack logging: resolve channel names now that the 3s
|
|
169
|
-
// budget is no longer a concern. Best-effort.
|
|
184
|
+
await reply(commandResultReply(result), command.key.workspace, command.key.chat)
|
|
170
185
|
try {
|
|
171
186
|
const inboundTag = await deps.formatChannelTag(command.key.workspace, command.key.chat)
|
|
172
187
|
deps.logger.info(`[slack-bot] slash /${command.name} result=${result.kind} ${inboundTag}`)
|
|
@@ -178,6 +193,60 @@ export function createSlashCommandHandler(
|
|
|
178
193
|
}
|
|
179
194
|
}
|
|
180
195
|
|
|
196
|
+
// Restart starts SIGTERM before its reply is posted; run's shutdown deadline is
|
|
197
|
+
// eight seconds. A slow copy editor must not consume that entire delivery window.
|
|
198
|
+
export const SLACK_CONTROL_REVIEW_TIMEOUT_MS = 1_000
|
|
199
|
+
|
|
200
|
+
function reviewControlReply(
|
|
201
|
+
deps: Pick<SlashCommandHandlerDeps, 'router' | 'logger'>,
|
|
202
|
+
event: ChannelOutboundBeforeEvent,
|
|
203
|
+
): Promise<string> {
|
|
204
|
+
return new Promise((resolve) => {
|
|
205
|
+
let settled = false
|
|
206
|
+
const finish = (text: string, failure?: string) => {
|
|
207
|
+
if (settled) return
|
|
208
|
+
settled = true
|
|
209
|
+
clearTimeout(timer)
|
|
210
|
+
if (failure) {
|
|
211
|
+
try {
|
|
212
|
+
deps.logger.warn(`[slack-bot] control response review ${failure}; retaining original`)
|
|
213
|
+
} catch {
|
|
214
|
+
// Logging cannot turn review into a delivery gate.
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
resolve(text)
|
|
218
|
+
}
|
|
219
|
+
const timer = setTimeout(() => finish(event.text, 'timed out'), SLACK_CONTROL_REVIEW_TIMEOUT_MS)
|
|
220
|
+
Promise.resolve()
|
|
221
|
+
.then(() => deps.router.reviewOutbound!(event))
|
|
222
|
+
.then(
|
|
223
|
+
(text) => finish(text),
|
|
224
|
+
() => finish(event.text, 'failed'),
|
|
225
|
+
)
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function safeSlashResponseUrl(value: unknown): string | undefined {
|
|
230
|
+
if (typeof value !== 'string') return undefined
|
|
231
|
+
try {
|
|
232
|
+
const url = new URL(value)
|
|
233
|
+
if (
|
|
234
|
+
url.protocol === 'https:' &&
|
|
235
|
+
(url.hostname === 'hooks.slack.com' || url.hostname === 'hooks.slack-gov.com') &&
|
|
236
|
+
url.port === '' &&
|
|
237
|
+
url.username === '' &&
|
|
238
|
+
url.password === '' &&
|
|
239
|
+
url.pathname.startsWith('/commands/') &&
|
|
240
|
+
url.search === '' &&
|
|
241
|
+
url.hash === ''
|
|
242
|
+
)
|
|
243
|
+
return url.href
|
|
244
|
+
} catch {
|
|
245
|
+
// Malformed transport metadata is not permission to contact another host.
|
|
246
|
+
}
|
|
247
|
+
return undefined
|
|
248
|
+
}
|
|
249
|
+
|
|
181
250
|
export type ThreadCommandReplyPoster = (args: { chat: string; thread: string | null; text: string }) => Promise<void>
|
|
182
251
|
|
|
183
252
|
export type ThreadCommandHandlerDeps = {
|
|
@@ -250,7 +319,8 @@ export function createThreadCommandHandler(
|
|
|
250
319
|
// promote them to a message-shaped event for the shared classifier. The
|
|
251
320
|
// promoted event is classified as a regular channel message; the
|
|
252
321
|
// `<@BOT_USER_ID>` substring inside `text` is what makes the classifier
|
|
253
|
-
// mark it as a mention.
|
|
322
|
+
// mark it as a mention. `edited` is carried over because an app_mention for an
|
|
323
|
+
// edit lacks the previous body and must stay subject to the edit gate.
|
|
254
324
|
export function promoteAppMentionToMessage(event: SlackInboundAppMentionEvent): SlackInboundMessageEvent {
|
|
255
325
|
return {
|
|
256
326
|
type: 'message',
|
|
@@ -262,6 +332,7 @@ export function promoteAppMentionToMessage(event: SlackInboundAppMentionEvent):
|
|
|
262
332
|
...(event.thread_ts !== undefined ? { thread_ts: event.thread_ts } : {}),
|
|
263
333
|
...(event.event_ts !== undefined ? { event_ts: event.event_ts } : {}),
|
|
264
334
|
...(event.client_msg_id !== undefined ? { client_msg_id: event.client_msg_id } : {}),
|
|
335
|
+
...(event.edited !== undefined ? { edited: event.edited as SlackInboundMessageEvent['edited'] } : {}),
|
|
265
336
|
}
|
|
266
337
|
}
|
|
267
338
|
|
|
@@ -277,6 +348,11 @@ const consoleLogger: SlackBotAdapterLogger = {
|
|
|
277
348
|
error: (m) => console.error(m),
|
|
278
349
|
}
|
|
279
350
|
|
|
351
|
+
export type SlackMessageObserver = {
|
|
352
|
+
readonly active: () => boolean
|
|
353
|
+
readonly observe: (event: ChannelMessageObservedEvent) => void
|
|
354
|
+
}
|
|
355
|
+
|
|
280
356
|
export type SlackBotAdapterOptions = {
|
|
281
357
|
router: ChannelRouter
|
|
282
358
|
configRef: () => ChannelAdapterConfig
|
|
@@ -288,6 +364,7 @@ export type SlackBotAdapterOptions = {
|
|
|
288
364
|
// classifier behaves as before (no alias-driven thread anchoring), so
|
|
289
365
|
// tests and ad-hoc adapter constructions stay backwards-compatible.
|
|
290
366
|
selfAliasesRef?: () => readonly string[]
|
|
367
|
+
messageObserver?: SlackMessageObserver
|
|
291
368
|
fetchImpl?: typeof fetch
|
|
292
369
|
createClient?: () => SlackBotClient
|
|
293
370
|
createListener?: (client: SlackBotClient, appToken: string) => SlackBotListener
|
|
@@ -423,6 +500,9 @@ type SlackRawHistoryMessage = {
|
|
|
423
500
|
thread_ts?: string
|
|
424
501
|
parent_user_id?: string
|
|
425
502
|
files?: SlackFile[]
|
|
503
|
+
edited?: { user: string; ts: string }
|
|
504
|
+
reply_count?: number
|
|
505
|
+
latest_reply?: string
|
|
426
506
|
}
|
|
427
507
|
|
|
428
508
|
type SlackHistoryResponse = {
|
|
@@ -707,24 +787,9 @@ export function createSlackHistoryCallback(deps: {
|
|
|
707
787
|
const fetchFn = deps.fetchImpl ?? fetch
|
|
708
788
|
return async (args: FetchHistoryArgs): Promise<FetchHistoryResult> => {
|
|
709
789
|
const limit = clampLimit(args.limit, SLACK_HISTORY_LIMIT_MAX)
|
|
710
|
-
const endpoint = args.thread === null ? 'conversations.history' : 'conversations.replies'
|
|
711
|
-
const body = new URLSearchParams()
|
|
712
|
-
body.set('channel', args.chat)
|
|
713
|
-
body.set('limit', String(limit))
|
|
714
|
-
if (args.thread !== null) body.set('ts', args.thread)
|
|
715
|
-
if (args.cursor !== undefined && args.cursor !== '') body.set('cursor', args.cursor)
|
|
716
|
-
|
|
717
790
|
let raw: SlackHistoryResponse
|
|
718
791
|
try {
|
|
719
|
-
|
|
720
|
-
method: 'POST',
|
|
721
|
-
headers: {
|
|
722
|
-
Authorization: `Bearer ${token}`,
|
|
723
|
-
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
|
|
724
|
-
},
|
|
725
|
-
body: body.toString(),
|
|
726
|
-
})
|
|
727
|
-
raw = (await response.json()) as SlackHistoryResponse
|
|
792
|
+
raw = await fetchSlackHistoryPage(token, fetchFn, { ...args, limit })
|
|
728
793
|
} catch (err) {
|
|
729
794
|
const message = describeError(err)
|
|
730
795
|
logger.warn(`[slack-bot] history fetch failed: ${message}`)
|
|
@@ -768,6 +833,121 @@ export function createSlackHistoryCallback(deps: {
|
|
|
768
833
|
}
|
|
769
834
|
}
|
|
770
835
|
|
|
836
|
+
async function fetchSlackHistoryPage(
|
|
837
|
+
token: string,
|
|
838
|
+
fetchFn: typeof fetch,
|
|
839
|
+
args: FetchHistoryArgs & { since?: number },
|
|
840
|
+
): Promise<SlackHistoryResponse> {
|
|
841
|
+
const body = new URLSearchParams({ channel: args.chat, limit: String(args.limit) })
|
|
842
|
+
if (args.thread !== null) body.set('ts', args.thread)
|
|
843
|
+
if (args.cursor) body.set('cursor', args.cursor)
|
|
844
|
+
if (args.since !== undefined) body.set('oldest', String(args.since / 1000))
|
|
845
|
+
const endpoint = args.thread === null ? 'conversations.history' : 'conversations.replies'
|
|
846
|
+
const response = await fetchFn(`${SLACK_API_BASE}/${endpoint}`, {
|
|
847
|
+
method: 'POST',
|
|
848
|
+
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' },
|
|
849
|
+
body: body.toString(),
|
|
850
|
+
})
|
|
851
|
+
return (await response.json()) as SlackHistoryResponse
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
export function createSlackMissedInboundCallback(deps: {
|
|
855
|
+
token: string
|
|
856
|
+
logger: SlackBotAdapterLogger
|
|
857
|
+
configRef: () => ChannelAdapterConfig
|
|
858
|
+
identity: () => { teamId: string; botUserId: string } | null
|
|
859
|
+
targets: () => Promise<readonly ChannelKey[]>
|
|
860
|
+
selfAliases: () => readonly string[]
|
|
861
|
+
fetchImpl?: typeof fetch
|
|
862
|
+
}): ListMissedInbound {
|
|
863
|
+
const fetchFn = deps.fetchImpl ?? fetch
|
|
864
|
+
const list = createSlackListCallback(deps)
|
|
865
|
+
const getRoot = createSlackMessageGetCallback({
|
|
866
|
+
token: deps.token,
|
|
867
|
+
logger: deps.logger,
|
|
868
|
+
fetchImpl: fetchFn,
|
|
869
|
+
botUserIdRef: () => deps.identity()?.botUserId ?? null,
|
|
870
|
+
})
|
|
871
|
+
return async (since) => {
|
|
872
|
+
const identity = deps.identity()
|
|
873
|
+
if (!identity) return []
|
|
874
|
+
const scopes = new Map<string, ChannelKey>()
|
|
875
|
+
const add = (key: ChannelKey) => scopes.set(`${key.chat}:${key.thread ?? ''}`, key)
|
|
876
|
+
// Persisted sessions include watched thread roots older than the history
|
|
877
|
+
// window. Query them directly; channel history does not include replies.
|
|
878
|
+
for (const key of await deps.targets()) add(key)
|
|
879
|
+
const channels = await list({ workspace: identity.teamId, limit: 200 })
|
|
880
|
+
if (!channels.ok) throw new Error(channels.error)
|
|
881
|
+
for (const channel of channels.entries) {
|
|
882
|
+
if (channel.isMember !== true && channel.kind !== 'dm' && channel.kind !== 'group') continue
|
|
883
|
+
add({
|
|
884
|
+
adapter: 'slack-bot',
|
|
885
|
+
workspace: channel.kind === 'dm' ? '@dm' : identity.teamId,
|
|
886
|
+
chat: channel.chat,
|
|
887
|
+
thread: null,
|
|
888
|
+
})
|
|
889
|
+
}
|
|
890
|
+
const result: MissedInbound[] = []
|
|
891
|
+
let calls = 0
|
|
892
|
+
// New roots discovered in history can append thread scopes to this map.
|
|
893
|
+
for (const key of scopes.values()) {
|
|
894
|
+
if (calls++ >= CATCH_UP_CONVERSATION_LIMIT) break
|
|
895
|
+
const page = await fetchSlackHistoryPage(deps.token, fetchFn, {
|
|
896
|
+
chat: key.chat,
|
|
897
|
+
thread: key.thread,
|
|
898
|
+
limit: 100,
|
|
899
|
+
since,
|
|
900
|
+
})
|
|
901
|
+
if (!page.ok) {
|
|
902
|
+
deps.logger.warn(`[slack-bot] catch-up history ${key.chat} failed: ${page.error ?? 'unknown slack error'}`)
|
|
903
|
+
if (page.error === 'not_in_channel' || page.error === 'channel_not_found') continue
|
|
904
|
+
throw new Error(page.error ?? 'Slack catch-up history unavailable')
|
|
905
|
+
}
|
|
906
|
+
const rows = page.messages ?? []
|
|
907
|
+
const latestTs = Math.max(0, ...rows.map((row) => slackTsToMillis(row.ts)))
|
|
908
|
+
let rootAuthor = key.thread === null ? undefined : rows.find((row) => row.ts === key.thread)?.user
|
|
909
|
+
// Replies are oldest-first: an incomplete page cannot prove the thread
|
|
910
|
+
// has not moved on, so skip rather than answer an obsolete message.
|
|
911
|
+
if (key.thread !== null && page.response_metadata?.next_cursor) {
|
|
912
|
+
deps.logger.info(`[slack-bot] catch-up skipped incomplete thread ${key.chat}/${key.thread}`)
|
|
913
|
+
continue
|
|
914
|
+
}
|
|
915
|
+
if (key.thread !== null && rows.length > 0 && rootAuthor === undefined) {
|
|
916
|
+
if (calls++ >= CATCH_UP_CONVERSATION_LIMIT) break
|
|
917
|
+
const root = await getRoot({ chat: key.chat, thread: null, messageId: key.thread })
|
|
918
|
+
if (!root.ok) continue
|
|
919
|
+
rootAuthor = root.message.authorId
|
|
920
|
+
}
|
|
921
|
+
for (const row of rows) {
|
|
922
|
+
if (key.thread === null && (row.reply_count ?? 0) > 0) {
|
|
923
|
+
add({ ...key, thread: row.ts })
|
|
924
|
+
}
|
|
925
|
+
if (slackTsToMillis(row.ts) < since) continue
|
|
926
|
+
const verdict = classifyInbound(
|
|
927
|
+
{
|
|
928
|
+
...row,
|
|
929
|
+
type: 'message',
|
|
930
|
+
channel: key.chat,
|
|
931
|
+
channel_type: key.workspace === '@dm' ? 'im' : 'channel',
|
|
932
|
+
...(key.thread !== null ? { thread_ts: key.thread, parent_user_id: row.parent_user_id ?? rootAuthor } : {}),
|
|
933
|
+
},
|
|
934
|
+
deps.configRef(),
|
|
935
|
+
{ ...identity, selfAliases: deps.selfAliases() },
|
|
936
|
+
)
|
|
937
|
+
if (verdict.kind !== 'route') continue
|
|
938
|
+
result.push({
|
|
939
|
+
message: verdict.payload,
|
|
940
|
+
latestTs:
|
|
941
|
+
key.thread === null
|
|
942
|
+
? Math.max(latestTs, row.latest_reply === undefined ? 0 : slackTsToMillis(row.latest_reply))
|
|
943
|
+
: latestTs,
|
|
944
|
+
})
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
return result.sort((a, b) => a.message.ts - b.message.ts)
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
|
|
771
951
|
// Fetch one message by ts. Slack has no by-id endpoint, so we window
|
|
772
952
|
// conversations.history (channel root) or conversations.replies (thread) to a
|
|
773
953
|
// single ts via oldest=latest=messageId, inclusive=true, limit=1 — without the
|
|
@@ -974,6 +1154,8 @@ export function createOutboundCallback(deps: {
|
|
|
974
1154
|
formatChannelTag: (workspace: string, chat: string) => Promise<string>
|
|
975
1155
|
readFile?: (path: string) => Promise<Buffer>
|
|
976
1156
|
typingTracker?: Pick<SlackTypingTracker, 'clearAfterSend'>
|
|
1157
|
+
token?: string
|
|
1158
|
+
fetchImpl?: typeof fetch
|
|
977
1159
|
}): OutboundCallback {
|
|
978
1160
|
const { client, logger, formatChannelTag, typingTracker } = deps
|
|
979
1161
|
const readFile = deps.readFile ?? readAttachmentBuffer
|
|
@@ -981,11 +1163,17 @@ export function createOutboundCallback(deps: {
|
|
|
981
1163
|
if (msg.adapter !== 'slack-bot') {
|
|
982
1164
|
return { ok: false, error: `unknown adapter: ${msg.adapter}` }
|
|
983
1165
|
}
|
|
1166
|
+
if (msg.sendOptions?.accounting === 'recovery') {
|
|
1167
|
+
if (!deps.token) return { ok: false, error: 'recovery-token-unavailable' }
|
|
1168
|
+
return sendBotRecovery('slack-bot', deps.token, msg, deps.fetchImpl)
|
|
1169
|
+
}
|
|
984
1170
|
const text = msg.text ?? ''
|
|
985
1171
|
const attachments = msg.attachments ?? []
|
|
986
1172
|
if (text === '' && attachments.length === 0) {
|
|
987
1173
|
return { ok: false, error: 'message has neither text nor attachments' }
|
|
988
1174
|
}
|
|
1175
|
+
const invalidThread = invalidSlackThreadTs(msg.thread)
|
|
1176
|
+
if (invalidThread !== null) return { ok: false, error: invalidThread }
|
|
989
1177
|
const tag = await formatChannelTag(msg.workspace, msg.chat)
|
|
990
1178
|
logger.info(
|
|
991
1179
|
`[slack-bot] outbound ${tag} text_len=${text.length} attachments=${attachments.length}${msg.thread ? ` thread=${msg.thread}` : ''}`,
|
|
@@ -999,8 +1187,14 @@ export function createOutboundCallback(deps: {
|
|
|
999
1187
|
try {
|
|
1000
1188
|
for (let i = 0; i < chunks.length; i++) {
|
|
1001
1189
|
const chunk = chunks[i]!
|
|
1002
|
-
const options: { thread_ts?: string; blocks?: unknown[] } = {
|
|
1190
|
+
const options: { thread_ts?: string; blocks?: unknown[]; unfurl_links?: boolean; unfurl_media?: boolean } = {
|
|
1191
|
+
blocks: [buildMarkdownBlock(chunk)],
|
|
1192
|
+
}
|
|
1003
1193
|
if (threadTs !== null) options.thread_ts = threadTs
|
|
1194
|
+
if (msg.link_previews === false) {
|
|
1195
|
+
options.unfurl_links = false
|
|
1196
|
+
options.unfurl_media = false
|
|
1197
|
+
}
|
|
1004
1198
|
const sent = await client.postMessage(msg.chat, chunk, options)
|
|
1005
1199
|
sentTs.push(sent.ts)
|
|
1006
1200
|
logger.info(
|
|
@@ -1150,6 +1344,11 @@ export function createSlackBotAdapter(options: SlackBotAdapterOptions): SlackBot
|
|
|
1150
1344
|
const logger = options.logger ?? consoleLogger
|
|
1151
1345
|
const client = options.createClient?.() ?? new SlackBotClient()
|
|
1152
1346
|
const fetchImpl = options.fetchImpl ?? fetch
|
|
1347
|
+
const recoveryCallbacks = createBotRecoveryCallbacks('slack-bot', options.token, fetchImpl, (workspace) =>
|
|
1348
|
+
botUserId !== null && teamId !== null && (workspace === undefined || workspace === '@dm' || workspace === teamId)
|
|
1349
|
+
? `slack-bot:${teamId}:${botUserId}`
|
|
1350
|
+
: undefined,
|
|
1351
|
+
)
|
|
1153
1352
|
let listener: SlackBotListener | null = null
|
|
1154
1353
|
let botUserId: string | null = null
|
|
1155
1354
|
let teamId: string | null = null
|
|
@@ -1158,8 +1357,8 @@ export function createSlackBotAdapter(options: SlackBotAdapterOptions): SlackBot
|
|
|
1158
1357
|
let inflightInbounds = 0
|
|
1159
1358
|
let stopWaiters: Array<() => void> = []
|
|
1160
1359
|
|
|
1161
|
-
const authorResolver = createSlackAuthorResolver({ token: options.token })
|
|
1162
|
-
const channelResolver = createSlackChannelResolver({ token: options.token })
|
|
1360
|
+
const authorResolver = createSlackAuthorResolver({ token: options.token, fetchImpl })
|
|
1361
|
+
const channelResolver = createSlackChannelResolver({ token: options.token, fetchImpl })
|
|
1163
1362
|
|
|
1164
1363
|
// Slack mentions by id (`<@U…>`), so no username form. Read live off the
|
|
1165
1364
|
// closure so a reconnect re-running auth.test stays reflected; one team
|
|
@@ -1198,6 +1397,15 @@ export function createSlackBotAdapter(options: SlackBotAdapterOptions): SlackBot
|
|
|
1198
1397
|
})
|
|
1199
1398
|
|
|
1200
1399
|
const listCallback = createSlackListCallback({ token: options.token, logger })
|
|
1400
|
+
const missedInbound = createSlackMissedInboundCallback({
|
|
1401
|
+
token: options.token,
|
|
1402
|
+
logger,
|
|
1403
|
+
configRef: options.configRef,
|
|
1404
|
+
fetchImpl,
|
|
1405
|
+
identity: () => (botUserId !== null && teamId !== null ? { botUserId, teamId } : null),
|
|
1406
|
+
targets: () => options.router.catchUpTargets('slack-bot'),
|
|
1407
|
+
selfAliases: () => options.selfAliasesRef?.() ?? [],
|
|
1408
|
+
})
|
|
1201
1409
|
|
|
1202
1410
|
const membershipResolver = createSlackMembershipResolver({
|
|
1203
1411
|
token: options.token,
|
|
@@ -1205,17 +1413,29 @@ export function createSlackBotAdapter(options: SlackBotAdapterOptions): SlackBot
|
|
|
1205
1413
|
historyCallback,
|
|
1206
1414
|
})
|
|
1207
1415
|
|
|
1208
|
-
const outboundCallback =
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1416
|
+
const outboundCallback = withOutboundAccount(
|
|
1417
|
+
createOutboundCallback({
|
|
1418
|
+
client,
|
|
1419
|
+
token: options.token,
|
|
1420
|
+
fetchImpl,
|
|
1421
|
+
logger,
|
|
1422
|
+
formatChannelTag,
|
|
1423
|
+
typingTracker,
|
|
1424
|
+
}),
|
|
1425
|
+
(workspace) => recoveryCallbacks.cachedAccountIdentity?.(workspace),
|
|
1426
|
+
)
|
|
1214
1427
|
|
|
1215
1428
|
const fetchAttachmentCallback = createFetchAttachmentCallback({ client, logger, token: options.token })
|
|
1216
1429
|
|
|
1217
1430
|
const reactionCallback = createSlackReactionCallback({ client })
|
|
1218
1431
|
const removeReactionCallback = createSlackRemoveReactionCallback({ client })
|
|
1432
|
+
const ownReaction = createSlackOwnReactionCallbacks({
|
|
1433
|
+
client,
|
|
1434
|
+
identity: async () => {
|
|
1435
|
+
const self = await client.testAuth()
|
|
1436
|
+
return self.team_id && self.user_id ? `${self.team_id}:${self.user_id}` : null
|
|
1437
|
+
},
|
|
1438
|
+
})
|
|
1219
1439
|
const editMessageCallback = createSlackEditMessageCallback({ token: options.token, fetchImpl })
|
|
1220
1440
|
|
|
1221
1441
|
const dedupe = createSlackDedupe()
|
|
@@ -1225,6 +1445,18 @@ export function createSlackBotAdapter(options: SlackBotAdapterOptions): SlackBot
|
|
|
1225
1445
|
knownCommandNames: SLACK_SLASH_COMMAND_NAMES,
|
|
1226
1446
|
logger,
|
|
1227
1447
|
formatChannelTag,
|
|
1448
|
+
postSlashResponse: async (url, payload) => {
|
|
1449
|
+
const response = await fetchImpl(url, {
|
|
1450
|
+
method: 'POST',
|
|
1451
|
+
redirect: 'error',
|
|
1452
|
+
signal: AbortSignal.timeout(5_000),
|
|
1453
|
+
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
|
1454
|
+
body: JSON.stringify(payload),
|
|
1455
|
+
})
|
|
1456
|
+
// Consume no response text: it can contain private content.
|
|
1457
|
+
await response.body?.cancel()
|
|
1458
|
+
return response.status
|
|
1459
|
+
},
|
|
1228
1460
|
})
|
|
1229
1461
|
|
|
1230
1462
|
const handleThreadCommand = createThreadCommandHandler({
|
|
@@ -1232,12 +1464,28 @@ export function createSlackBotAdapter(options: SlackBotAdapterOptions): SlackBot
|
|
|
1232
1464
|
knownCommandNames: SLACK_SLASH_COMMAND_NAMES,
|
|
1233
1465
|
logger,
|
|
1234
1466
|
postReply: async ({ chat, thread, text }) => {
|
|
1467
|
+
const workspace = teamId ?? 'unknown'
|
|
1468
|
+
const reviewed = options.router.hasOutboundReviewer?.()
|
|
1469
|
+
? await reviewControlReply(
|
|
1470
|
+
{ router: options.router, logger },
|
|
1471
|
+
{
|
|
1472
|
+
adapter: 'slack-bot',
|
|
1473
|
+
workspace,
|
|
1474
|
+
chat,
|
|
1475
|
+
...(thread !== null ? { thread } : {}),
|
|
1476
|
+
text,
|
|
1477
|
+
op: 'send',
|
|
1478
|
+
source: 'system',
|
|
1479
|
+
outputKind: 'meta',
|
|
1480
|
+
},
|
|
1481
|
+
)
|
|
1482
|
+
: text
|
|
1235
1483
|
const result = await outboundCallback({
|
|
1236
1484
|
adapter: 'slack-bot',
|
|
1237
|
-
workspace
|
|
1485
|
+
workspace,
|
|
1238
1486
|
chat,
|
|
1239
1487
|
...(thread !== null ? { thread } : {}),
|
|
1240
|
-
text,
|
|
1488
|
+
text: reviewed,
|
|
1241
1489
|
})
|
|
1242
1490
|
if (!result.ok) {
|
|
1243
1491
|
throw new Error(result.error)
|
|
@@ -1245,29 +1493,52 @@ export function createSlackBotAdapter(options: SlackBotAdapterOptions): SlackBot
|
|
|
1245
1493
|
},
|
|
1246
1494
|
})
|
|
1247
1495
|
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
): Promise<void> => {
|
|
1496
|
+
// Gate raw edits before dedupe, commands and reference enrichment. `source`
|
|
1497
|
+
// is the listener that delivered the event: app_mention promotion rewrites
|
|
1498
|
+
// its type to 'message', so it cannot be recovered from the event itself.
|
|
1499
|
+
const handleMessageEvent = async (rawEvent: SlackInboundMessageEvent, source: SlackInboundSource): Promise<void> => {
|
|
1500
|
+
const inboundTeamId = teamId
|
|
1501
|
+
const inboundBotId = botUserId
|
|
1502
|
+
let admissionReservation: SlackDedupeReservation | undefined
|
|
1252
1503
|
inflightInbounds++
|
|
1253
1504
|
try {
|
|
1505
|
+
if (inboundTeamId === null) {
|
|
1506
|
+
logger.warn(`[slack-bot] dropped ts=${rawEvent.ts} reason=pre_connected (team_id unknown)`)
|
|
1507
|
+
return
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
// A rejected edit must not reach `!cmd` interception: edited control
|
|
1511
|
+
// text would otherwise execute without a fresh, original gesture.
|
|
1512
|
+
const admission = admitSlackInbound(rawEvent, inboundBotId, source)
|
|
1513
|
+
if (admission.kind === 'drop') {
|
|
1514
|
+
logger.info(`[slack-bot] dropped ts=${rawEvent.ts} reason=${admission.reason} (source=${source})`)
|
|
1515
|
+
return
|
|
1516
|
+
}
|
|
1517
|
+
const event = admission.event
|
|
1254
1518
|
const text = event.text ?? ''
|
|
1255
1519
|
const userId = event.user ?? 'unknown'
|
|
1256
|
-
const inboundWorkspace = event.channel_type === 'im' ? '@dm' :
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
if (
|
|
1266
|
-
logger.
|
|
1520
|
+
const inboundWorkspace = event.channel_type === 'im' ? '@dm' : inboundTeamId
|
|
1521
|
+
const commandInput = {
|
|
1522
|
+
text,
|
|
1523
|
+
channel: event.channel,
|
|
1524
|
+
threadTs: event.thread_ts ?? null,
|
|
1525
|
+
isDm: event.channel_type === 'im',
|
|
1526
|
+
teamId: inboundTeamId,
|
|
1527
|
+
invokerId: userId,
|
|
1528
|
+
}
|
|
1529
|
+
if (admission.isEdit && parseThreadCommand(commandInput, SLACK_SLASH_COMMAND_NAMES).kind === 'parsed') {
|
|
1530
|
+
logger.info(`[slack-bot] dropped ts=${event.ts} reason=edited_control (source=${source})`)
|
|
1267
1531
|
return
|
|
1268
1532
|
}
|
|
1269
1533
|
|
|
1270
|
-
const
|
|
1534
|
+
const verdict = classifyInbound(rawEvent, options.configRef(), {
|
|
1535
|
+
teamId: inboundTeamId,
|
|
1536
|
+
botUserId: inboundBotId,
|
|
1537
|
+
source,
|
|
1538
|
+
...(options.selfAliasesRef ? { selfAliases: options.selfAliasesRef() } : {}),
|
|
1539
|
+
})
|
|
1540
|
+
const isBotMention = verdict.kind === 'route' && verdict.payload.isBotMention
|
|
1541
|
+
const dedupeMatch = dedupe.check(event, isBotMention)
|
|
1271
1542
|
if (dedupeMatch !== null) {
|
|
1272
1543
|
logger.info(
|
|
1273
1544
|
`[slack-bot] dropped ts=${event.ts} reason=duplicate_delivery (source=${source}, matched=${dedupeMatch})`,
|
|
@@ -1275,50 +1546,43 @@ export function createSlackBotAdapter(options: SlackBotAdapterOptions): SlackBot
|
|
|
1275
1546
|
return
|
|
1276
1547
|
}
|
|
1277
1548
|
|
|
1278
|
-
// Intercept `!cmd`
|
|
1279
|
-
//
|
|
1280
|
-
//
|
|
1281
|
-
//
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
// instant the command is recognised (before the router await), closing
|
|
1285
|
-
// the check→execute race for duplicate deliveries.
|
|
1286
|
-
if (event.user !== undefined && event.user !== '' && (botUserId === null || event.user !== botUserId)) {
|
|
1549
|
+
// Intercept `!cmd` before acting on the classifier verdict: commands are
|
|
1550
|
+
// control traffic, not agent messages. Retain self-author/userless floors.
|
|
1551
|
+
// The handler reserves synchronously before executing, and a consumed
|
|
1552
|
+
// command cannot later promote into a mention.
|
|
1553
|
+
if (event.user !== undefined && event.user !== '' && (inboundBotId === null || event.user !== inboundBotId)) {
|
|
1554
|
+
let commandReserved = false
|
|
1287
1555
|
const reserve = (): boolean => {
|
|
1288
|
-
if (dedupe.check(event) !== null) return false
|
|
1289
|
-
dedupe.mark(event)
|
|
1556
|
+
if (dedupe.check(event, isBotMention) !== null) return false
|
|
1557
|
+
dedupe.mark(event, true)
|
|
1558
|
+
commandReserved = true
|
|
1290
1559
|
return true
|
|
1291
1560
|
}
|
|
1292
|
-
const
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
isDm: event.channel_type === 'im',
|
|
1298
|
-
teamId,
|
|
1299
|
-
invokerId: event.user,
|
|
1300
|
-
},
|
|
1301
|
-
reserve,
|
|
1302
|
-
)
|
|
1303
|
-
if (outcome.kind === 'executed') return
|
|
1304
|
-
if (outcome.kind === 'duplicate') {
|
|
1305
|
-
logger.info(`[slack-bot] dropped ts=${event.ts} reason=duplicate_delivery (thread-command race)`)
|
|
1561
|
+
const outcomePromise = handleThreadCommand(commandInput, reserve)
|
|
1562
|
+
// The handler reserves synchronously before its first await. Do not
|
|
1563
|
+
// await a non-command: regular delivery must reserve in this same tick.
|
|
1564
|
+
if (commandReserved) {
|
|
1565
|
+
await outcomePromise
|
|
1306
1566
|
return
|
|
1307
1567
|
}
|
|
1308
1568
|
}
|
|
1309
1569
|
|
|
1310
|
-
const verdict = classifyInbound(event, options.configRef(), {
|
|
1311
|
-
teamId,
|
|
1312
|
-
botUserId,
|
|
1313
|
-
...(options.selfAliasesRef ? { selfAliases: options.selfAliasesRef() } : {}),
|
|
1314
|
-
})
|
|
1315
1570
|
if (verdict.kind === 'drop') {
|
|
1316
1571
|
logger.info(`[slack-bot] dropped ts=${event.ts} reason=${verdict.reason}${dropHint(verdict.reason)}`)
|
|
1317
1572
|
return
|
|
1318
1573
|
}
|
|
1319
1574
|
|
|
1320
|
-
dedupe.
|
|
1321
|
-
const
|
|
1575
|
+
admissionReservation = dedupe.reserve(event, isBotMention)
|
|
1576
|
+
const [resolvedUserName, inboundTag] = await Promise.all([
|
|
1577
|
+
event.user !== undefined && event.user !== '' ? authorResolver.resolve(event.user) : Promise.resolve(userId),
|
|
1578
|
+
formatChannelTag(inboundWorkspace, event.channel),
|
|
1579
|
+
])
|
|
1580
|
+
logger.info(
|
|
1581
|
+
`[slack-bot] inbound source=${source} ts=${event.ts} user=${formatLabel(resolvedUserName, userId)} ${inboundTag} text_len=${text.length}`,
|
|
1582
|
+
)
|
|
1583
|
+
const hintedText = await addSlackMentionHints(verdict.payload.text, authorResolver.resolve, {
|
|
1584
|
+
botUserId: inboundBotId,
|
|
1585
|
+
})
|
|
1322
1586
|
const slackAttachments = Array.isArray(event.attachments) ? event.attachments : undefined
|
|
1323
1587
|
const referenceResult = await enrichSlackReferenceContext({
|
|
1324
1588
|
text: hintedText,
|
|
@@ -1340,7 +1604,9 @@ export function createSlackBotAdapter(options: SlackBotAdapterOptions): SlackBot
|
|
|
1340
1604
|
`[slack-bot] routed ts=${event.ts} ${routedTag} mention=${enriched.isBotMention} reply=${enriched.replyToBotMessageId !== null}`,
|
|
1341
1605
|
)
|
|
1342
1606
|
await options.router.route(enriched)
|
|
1607
|
+
admissionReservation.commit()
|
|
1343
1608
|
} catch (err) {
|
|
1609
|
+
admissionReservation?.rollback()
|
|
1344
1610
|
logger.error(`[slack-bot] handleInbound failed: ${describeError(err)}`)
|
|
1345
1611
|
} finally {
|
|
1346
1612
|
inflightInbounds--
|
|
@@ -1384,20 +1650,39 @@ export function createSlackBotAdapter(options: SlackBotAdapterOptions): SlackBot
|
|
|
1384
1650
|
new SlackBotListener(client, { appToken: options.appToken })
|
|
1385
1651
|
listener.on('connected', (info) => {
|
|
1386
1652
|
socketConnected = started
|
|
1653
|
+
if (started) void options.router.catchUp('slack-bot')
|
|
1387
1654
|
logger.info(`[slack-bot] connected (app_id=${info.app_id ?? 'unknown'})`)
|
|
1388
1655
|
})
|
|
1389
1656
|
listener.on('disconnected', () => {
|
|
1390
1657
|
socketConnected = false
|
|
1658
|
+
options.router.disconnectCatchUp('slack-bot')
|
|
1391
1659
|
logger.warn('[slack-bot] disconnected; SDK will reconnect with backoff')
|
|
1392
1660
|
})
|
|
1393
1661
|
listener.on('error', (err) => {
|
|
1394
|
-
if (recordValue(err)?.code === 'disconnect_terminal')
|
|
1662
|
+
if (recordValue(err)?.code === 'disconnect_terminal') {
|
|
1663
|
+
socketConnected = false
|
|
1664
|
+
options.router.disconnectCatchUp('slack-bot')
|
|
1665
|
+
}
|
|
1395
1666
|
logger.error(`[slack-bot] socket-mode error: ${describeError(err)}`)
|
|
1396
1667
|
})
|
|
1397
1668
|
listener.on('message', ({ ack, event }) => {
|
|
1398
1669
|
// Ack first so Slack stops retrying; failure to ack causes duplicate
|
|
1399
1670
|
// deliveries within seconds. Then process asynchronously.
|
|
1400
1671
|
ack()
|
|
1672
|
+
const observer = options.messageObserver
|
|
1673
|
+
try {
|
|
1674
|
+
if (observer?.active()) {
|
|
1675
|
+
observer.observe({
|
|
1676
|
+
adapter: 'slack-bot',
|
|
1677
|
+
workspace: teamId,
|
|
1678
|
+
selfUserId: botUserId,
|
|
1679
|
+
receivedAt: Date.now(),
|
|
1680
|
+
event: event as SlackObservedMessage,
|
|
1681
|
+
})
|
|
1682
|
+
}
|
|
1683
|
+
} catch {
|
|
1684
|
+
logger.warn('[slack-bot] raw message observer dispatch failed')
|
|
1685
|
+
}
|
|
1401
1686
|
// Cast at the SDK boundary: upstream types this event with a
|
|
1402
1687
|
// `[key: string]: unknown` catchall for fields it does not
|
|
1403
1688
|
// declare (parent_user_id, client_msg_id, files). The Slack
|
|
@@ -1433,13 +1718,17 @@ export function createSlackBotAdapter(options: SlackBotAdapterOptions): SlackBot
|
|
|
1433
1718
|
})
|
|
1434
1719
|
|
|
1435
1720
|
options.router.registerOutbound('slack-bot', outboundCallback)
|
|
1721
|
+
options.router.registerRecoveryAdapter('slack-bot', recoveryCallbacks)
|
|
1436
1722
|
options.router.registerReaction('slack-bot', reactionCallback)
|
|
1437
1723
|
options.router.registerRemoveReaction('slack-bot', removeReactionCallback)
|
|
1724
|
+
options.router.registerPrepareOwnReaction('slack-bot', ownReaction.prepare)
|
|
1725
|
+
options.router.registerRemoveOwnReaction('slack-bot', ownReaction.remove)
|
|
1438
1726
|
options.router.registerTyping('slack-bot', typingCallback)
|
|
1439
1727
|
options.router.setTypingCapability('slack-bot', true)
|
|
1440
1728
|
options.router.registerChannelNameResolver('slack-bot', channelResolver)
|
|
1441
1729
|
options.router.registerSelfIdentity('slack-bot', selfIdentityResolver)
|
|
1442
1730
|
options.router.registerHistory('slack-bot', historyCallback)
|
|
1731
|
+
options.router.registerMissedInbound('slack-bot', missedInbound)
|
|
1443
1732
|
options.router.registerMessageGet('slack-bot', messageGetCallback)
|
|
1444
1733
|
options.router.registerList('slack-bot', listCallback)
|
|
1445
1734
|
options.router.registerEditMessage('slack-bot', editMessageCallback)
|
|
@@ -1454,13 +1743,17 @@ export function createSlackBotAdapter(options: SlackBotAdapterOptions): SlackBot
|
|
|
1454
1743
|
// !started and would otherwise skip cleanup), mirroring the github
|
|
1455
1744
|
// adapter's rollback path.
|
|
1456
1745
|
options.router.unregisterOutbound('slack-bot', outboundCallback)
|
|
1746
|
+
options.router.unregisterRecoveryAdapter('slack-bot', recoveryCallbacks)
|
|
1457
1747
|
options.router.unregisterReaction('slack-bot', reactionCallback)
|
|
1458
1748
|
options.router.unregisterRemoveReaction('slack-bot', removeReactionCallback)
|
|
1749
|
+
options.router.unregisterPrepareOwnReaction('slack-bot', ownReaction.prepare)
|
|
1750
|
+
options.router.unregisterRemoveOwnReaction('slack-bot', ownReaction.remove)
|
|
1459
1751
|
options.router.unregisterTyping('slack-bot', typingCallback)
|
|
1460
1752
|
options.router.setTypingCapability('slack-bot', false)
|
|
1461
1753
|
options.router.unregisterChannelNameResolver('slack-bot', channelResolver)
|
|
1462
1754
|
options.router.unregisterSelfIdentity('slack-bot', selfIdentityResolver)
|
|
1463
1755
|
options.router.unregisterHistory('slack-bot', historyCallback)
|
|
1756
|
+
options.router.unregisterMissedInbound('slack-bot', missedInbound)
|
|
1464
1757
|
options.router.unregisterMessageGet('slack-bot', messageGetCallback)
|
|
1465
1758
|
options.router.unregisterList('slack-bot', listCallback)
|
|
1466
1759
|
options.router.unregisterEditMessage('slack-bot', editMessageCallback)
|
|
@@ -1480,14 +1773,18 @@ export function createSlackBotAdapter(options: SlackBotAdapterOptions): SlackBot
|
|
|
1480
1773
|
if (!started) return
|
|
1481
1774
|
started = false
|
|
1482
1775
|
socketConnected = false
|
|
1776
|
+
options.router.unregisterMissedInbound('slack-bot', missedInbound)
|
|
1483
1777
|
options.router.unregisterOutbound('slack-bot', outboundCallback)
|
|
1484
1778
|
options.router.unregisterReaction('slack-bot', reactionCallback)
|
|
1485
1779
|
options.router.unregisterRemoveReaction('slack-bot', removeReactionCallback)
|
|
1780
|
+
options.router.unregisterPrepareOwnReaction('slack-bot', ownReaction.prepare)
|
|
1781
|
+
options.router.unregisterRemoveOwnReaction('slack-bot', ownReaction.remove)
|
|
1486
1782
|
options.router.unregisterTyping('slack-bot', typingCallback)
|
|
1487
1783
|
options.router.setTypingCapability('slack-bot', false)
|
|
1488
1784
|
options.router.unregisterChannelNameResolver('slack-bot', channelResolver)
|
|
1489
1785
|
options.router.unregisterSelfIdentity('slack-bot', selfIdentityResolver)
|
|
1490
1786
|
options.router.unregisterHistory('slack-bot', historyCallback)
|
|
1787
|
+
options.router.unregisterRecoveryAdapter('slack-bot', recoveryCallbacks)
|
|
1491
1788
|
options.router.unregisterMessageGet('slack-bot', messageGetCallback)
|
|
1492
1789
|
options.router.unregisterList('slack-bot', listCallback)
|
|
1493
1790
|
options.router.unregisterEditMessage('slack-bot', editMessageCallback)
|
|
@@ -1517,6 +1814,9 @@ function dropHint(reason: InboundDropReason): string {
|
|
|
1517
1814
|
case 'pre_connect':
|
|
1518
1815
|
case 'self_author':
|
|
1519
1816
|
case 'slack_system_message':
|
|
1817
|
+
case 'unverified_edit':
|
|
1818
|
+
case 'edit_without_new_mention':
|
|
1819
|
+
case 'edited_control':
|
|
1520
1820
|
return ''
|
|
1521
1821
|
}
|
|
1522
1822
|
}
|