botmux 2.46.1 → 2.47.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/README.en.md +5 -10
- package/README.md +5 -10
- package/dist/adapters/backend/tmux-backend.d.ts.map +1 -1
- package/dist/adapters/backend/tmux-backend.js +0 -11
- package/dist/adapters/backend/tmux-backend.js.map +1 -1
- package/dist/adapters/cli/claude-code.d.ts.map +1 -1
- package/dist/adapters/cli/claude-code.js +9 -36
- package/dist/adapters/cli/claude-code.js.map +1 -1
- package/dist/adapters/cli/coco.d.ts.map +1 -1
- package/dist/adapters/cli/coco.js +1 -26
- package/dist/adapters/cli/coco.js.map +1 -1
- package/dist/adapters/cli/codex.d.ts.map +1 -1
- package/dist/adapters/cli/codex.js +1 -6
- package/dist/adapters/cli/codex.js.map +1 -1
- package/dist/adapters/cli/cursor.d.ts.map +1 -1
- package/dist/adapters/cli/cursor.js +12 -58
- package/dist/adapters/cli/cursor.js.map +1 -1
- package/dist/adapters/cli/gemini.d.ts.map +1 -1
- package/dist/adapters/cli/gemini.js +1 -5
- package/dist/adapters/cli/gemini.js.map +1 -1
- package/dist/adapters/cli/opencode.d.ts.map +1 -1
- package/dist/adapters/cli/opencode.js +1 -19
- package/dist/adapters/cli/opencode.js.map +1 -1
- package/dist/adapters/cli/registry.d.ts +1 -5
- package/dist/adapters/cli/registry.d.ts.map +1 -1
- package/dist/adapters/cli/registry.js +2 -22
- package/dist/adapters/cli/registry.js.map +1 -1
- package/dist/adapters/cli/shared-hints.d.ts +1 -1
- package/dist/adapters/cli/shared-hints.d.ts.map +1 -1
- package/dist/adapters/cli/shared-hints.js +1 -2
- package/dist/adapters/cli/shared-hints.js.map +1 -1
- package/dist/adapters/cli/types.d.ts +2 -35
- package/dist/adapters/cli/types.d.ts.map +1 -1
- package/dist/bot-registry.d.ts +0 -59
- package/dist/bot-registry.d.ts.map +1 -1
- package/dist/bot-registry.js +0 -67
- package/dist/bot-registry.js.map +1 -1
- package/dist/cli/bots-list-output.d.ts +0 -8
- package/dist/cli/bots-list-output.d.ts.map +1 -1
- package/dist/cli/bots-list-output.js +0 -9
- package/dist/cli/bots-list-output.js.map +1 -1
- package/dist/cli.d.ts +1 -15
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +106 -603
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +2 -11
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -17
- package/dist/config.js.map +1 -1
- package/dist/core/command-handler.d.ts +0 -20
- package/dist/core/command-handler.d.ts.map +1 -1
- package/dist/core/command-handler.js +313 -762
- package/dist/core/command-handler.js.map +1 -1
- package/dist/core/dashboard-ipc-server.d.ts +0 -2
- package/dist/core/dashboard-ipc-server.d.ts.map +1 -1
- package/dist/core/dashboard-ipc-server.js +2 -222
- package/dist/core/dashboard-ipc-server.js.map +1 -1
- package/dist/core/role-resolver.d.ts +1 -17
- package/dist/core/role-resolver.d.ts.map +1 -1
- package/dist/core/role-resolver.js +10 -64
- package/dist/core/role-resolver.js.map +1 -1
- package/dist/core/session-discovery.d.ts.map +1 -1
- package/dist/core/session-discovery.js +5 -19
- package/dist/core/session-discovery.js.map +1 -1
- package/dist/core/session-manager.d.ts +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +20 -37
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/types.d.ts +0 -5
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/core/worker-pool.d.ts +0 -141
- package/dist/core/worker-pool.d.ts.map +1 -1
- package/dist/core/worker-pool.js +24 -543
- package/dist/core/worker-pool.js.map +1 -1
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +58 -213
- package/dist/daemon.js.map +1 -1
- package/dist/dashboard/auth.d.ts +1 -6
- package/dist/dashboard/auth.d.ts.map +1 -1
- package/dist/dashboard/auth.js +1 -9
- package/dist/dashboard/auth.js.map +1 -1
- package/dist/dashboard/web/app.js +0 -8
- package/dist/dashboard/web/app.js.map +1 -1
- package/dist/dashboard/web/bot-defaults.d.ts.map +1 -1
- package/dist/dashboard/web/bot-defaults.js +21 -205
- package/dist/dashboard/web/bot-defaults.js.map +1 -1
- package/dist/dashboard/web/i18n.d.ts.map +1 -1
- package/dist/dashboard/web/i18n.js +5 -43
- package/dist/dashboard/web/i18n.js.map +1 -1
- package/dist/dashboard/web/sessions.d.ts.map +1 -1
- package/dist/dashboard/web/sessions.js +0 -4
- package/dist/dashboard/web/sessions.js.map +1 -1
- package/dist/dashboard/web/workflows.js +3 -3
- package/dist/dashboard/web/workflows.js.map +1 -1
- package/dist/dashboard/workflow-api.d.ts +1 -8
- package/dist/dashboard/workflow-api.d.ts.map +1 -1
- package/dist/dashboard/workflow-api.js +4 -19
- package/dist/dashboard/workflow-api.js.map +1 -1
- package/dist/dashboard-web/app.js +375 -539
- package/dist/dashboard-web/index.html +1 -3
- package/dist/dashboard-web/style.css +0 -22
- package/dist/dashboard.js +2 -199
- package/dist/dashboard.js.map +1 -1
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +11 -104
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/zh.d.ts.map +1 -1
- package/dist/i18n/zh.js +11 -104
- package/dist/i18n/zh.js.map +1 -1
- package/dist/im/lark/card-builder.d.ts +3 -108
- package/dist/im/lark/card-builder.d.ts.map +1 -1
- package/dist/im/lark/card-builder.js +50 -480
- package/dist/im/lark/card-builder.js.map +1 -1
- package/dist/im/lark/card-handler.d.ts.map +1 -1
- package/dist/im/lark/card-handler.js +18 -241
- package/dist/im/lark/card-handler.js.map +1 -1
- package/dist/im/lark/client.d.ts +0 -83
- package/dist/im/lark/client.d.ts.map +1 -1
- package/dist/im/lark/client.js +70 -286
- package/dist/im/lark/client.js.map +1 -1
- package/dist/im/lark/event-dispatcher.d.ts.map +1 -1
- package/dist/im/lark/event-dispatcher.js +4 -29
- package/dist/im/lark/event-dispatcher.js.map +1 -1
- package/dist/im/lark/grant-command.d.ts +1 -2
- package/dist/im/lark/grant-command.d.ts.map +1 -1
- package/dist/im/lark/grant-command.js +2 -3
- package/dist/im/lark/grant-command.js.map +1 -1
- package/dist/im/lark/identity-cache.d.ts.map +1 -1
- package/dist/im/lark/identity-cache.js +3 -3
- package/dist/im/lark/identity-cache.js.map +1 -1
- package/dist/im/lark/md-card.d.ts +2 -20
- package/dist/im/lark/md-card.d.ts.map +1 -1
- package/dist/im/lark/md-card.js +17 -49
- package/dist/im/lark/md-card.js.map +1 -1
- package/dist/im/lark/message-parser.d.ts.map +1 -1
- package/dist/im/lark/message-parser.js +31 -87
- package/dist/im/lark/message-parser.js.map +1 -1
- package/dist/im/lark/workflow-card-handler.d.ts +2 -2
- package/dist/im/lark/workflow-card-handler.d.ts.map +1 -1
- package/dist/im/lark/workflow-card-handler.js +1 -12
- package/dist/im/lark/workflow-card-handler.js.map +1 -1
- package/dist/im/lark/workflow-progress-card.d.ts.map +1 -1
- package/dist/im/lark/workflow-progress-card.js +0 -53
- package/dist/im/lark/workflow-progress-card.js.map +1 -1
- package/dist/services/codex-bridge-queue.d.ts +0 -1
- package/dist/services/codex-bridge-queue.d.ts.map +1 -1
- package/dist/services/codex-bridge-queue.js +0 -23
- package/dist/services/codex-bridge-queue.js.map +1 -1
- package/dist/services/codex-transcript.d.ts +0 -1
- package/dist/services/codex-transcript.d.ts.map +1 -1
- package/dist/services/codex-transcript.js.map +1 -1
- package/dist/services/feishu-task-client.d.ts +28 -0
- package/dist/services/feishu-task-client.d.ts.map +1 -0
- package/dist/services/feishu-task-client.js +123 -0
- package/dist/services/feishu-task-client.js.map +1 -0
- package/dist/services/grant-store.d.ts +2 -12
- package/dist/services/grant-store.d.ts.map +1 -1
- package/dist/services/grant-store.js +4 -51
- package/dist/services/grant-store.js.map +1 -1
- package/dist/services/group-creator.d.ts +0 -10
- package/dist/services/group-creator.d.ts.map +1 -1
- package/dist/services/group-creator.js +1 -26
- package/dist/services/group-creator.js.map +1 -1
- package/dist/services/groups-store.d.ts +0 -30
- package/dist/services/groups-store.d.ts.map +1 -1
- package/dist/services/groups-store.js +12 -85
- package/dist/services/groups-store.js.map +1 -1
- package/dist/services/project-scanner.d.ts +0 -10
- package/dist/services/project-scanner.d.ts.map +1 -1
- package/dist/services/project-scanner.js +0 -11
- package/dist/services/project-scanner.js.map +1 -1
- package/dist/services/session-store.js +1 -1
- package/dist/services/session-store.js.map +1 -1
- package/dist/services/task-store.d.ts +37 -0
- package/dist/services/task-store.d.ts.map +1 -0
- package/dist/services/task-store.js +115 -0
- package/dist/services/task-store.js.map +1 -0
- package/dist/setup/bot-config-editor.d.ts +1 -8
- package/dist/setup/bot-config-editor.d.ts.map +1 -1
- package/dist/setup/bot-config-editor.js +2 -20
- package/dist/setup/bot-config-editor.js.map +1 -1
- package/dist/setup/ensure-tmux.d.ts +22 -0
- package/dist/setup/ensure-tmux.d.ts.map +1 -1
- package/dist/setup/ensure-tmux.js +1 -25
- package/dist/setup/ensure-tmux.js.map +1 -1
- package/dist/setup/verify-permissions.d.ts.map +1 -1
- package/dist/setup/verify-permissions.js +1 -15
- package/dist/setup/verify-permissions.js.map +1 -1
- package/dist/skills/definitions.d.ts +0 -2
- package/dist/skills/definitions.d.ts.map +1 -1
- package/dist/skills/definitions.js +12 -178
- package/dist/skills/definitions.js.map +1 -1
- package/dist/skills/installer.d.ts +0 -34
- package/dist/skills/installer.d.ts.map +1 -1
- package/dist/skills/installer.js +2 -119
- package/dist/skills/installer.js.map +1 -1
- package/dist/types.d.ts +0 -25
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/bot-routing.d.ts +0 -50
- package/dist/utils/bot-routing.d.ts.map +1 -1
- package/dist/utils/bot-routing.js +0 -83
- package/dist/utils/bot-routing.js.map +1 -1
- package/dist/utils/user-token.d.ts.map +1 -1
- package/dist/utils/user-token.js +2 -0
- package/dist/utils/user-token.js.map +1 -1
- package/dist/worker.js +27 -198
- package/dist/worker.js.map +1 -1
- package/dist/workflows/attempt-resume.d.ts.map +1 -1
- package/dist/workflows/attempt-resume.js +2 -2
- package/dist/workflows/attempt-resume.js.map +1 -1
- package/dist/workflows/definition.d.ts +9 -412
- package/dist/workflows/definition.d.ts.map +1 -1
- package/dist/workflows/definition.js +3 -238
- package/dist/workflows/definition.js.map +1 -1
- package/dist/workflows/events/payloads.d.ts +11 -114
- package/dist/workflows/events/payloads.d.ts.map +1 -1
- package/dist/workflows/events/payloads.js +0 -46
- package/dist/workflows/events/payloads.js.map +1 -1
- package/dist/workflows/events/replay.d.ts +0 -21
- package/dist/workflows/events/replay.d.ts.map +1 -1
- package/dist/workflows/events/replay.js +0 -103
- package/dist/workflows/events/replay.js.map +1 -1
- package/dist/workflows/events/schema.d.ts +1017 -1712
- package/dist/workflows/events/schema.d.ts.map +1 -1
- package/dist/workflows/events/schema.js +1 -37
- package/dist/workflows/events/schema.js.map +1 -1
- package/dist/workflows/events/types.d.ts +1 -5
- package/dist/workflows/events/types.d.ts.map +1 -1
- package/dist/workflows/loader.d.ts +0 -14
- package/dist/workflows/loader.d.ts.map +1 -1
- package/dist/workflows/loader.js +0 -27
- package/dist/workflows/loader.js.map +1 -1
- package/dist/workflows/loop.js +0 -58
- package/dist/workflows/loop.js.map +1 -1
- package/dist/workflows/ops-projection.d.ts +0 -58
- package/dist/workflows/ops-projection.d.ts.map +1 -1
- package/dist/workflows/ops-projection.js +0 -74
- package/dist/workflows/ops-projection.js.map +1 -1
- package/dist/workflows/orchestrator.d.ts +1 -65
- package/dist/workflows/orchestrator.d.ts.map +1 -1
- package/dist/workflows/orchestrator.js +74 -486
- package/dist/workflows/orchestrator.js.map +1 -1
- package/dist/workflows/output-binding.d.ts +1 -8
- package/dist/workflows/output-binding.d.ts.map +1 -1
- package/dist/workflows/output-binding.js +11 -75
- package/dist/workflows/output-binding.js.map +1 -1
- package/dist/workflows/runtime.d.ts +1 -1
- package/dist/workflows/runtime.d.ts.map +1 -1
- package/dist/workflows/runtime.js +4 -39
- package/dist/workflows/runtime.js.map +1 -1
- package/dist/workflows/wait.d.ts +2 -23
- package/dist/workflows/wait.d.ts.map +1 -1
- package/dist/workflows/wait.js +17 -39
- package/dist/workflows/wait.js.map +1 -1
- package/package.json +1 -1
- package/dist/adapters/adopt-route.d.ts +0 -63
- package/dist/adapters/adopt-route.d.ts.map +0 -1
- package/dist/adapters/adopt-route.js +0 -195
- package/dist/adapters/adopt-route.js.map +0 -1
- package/dist/adapters/cli/codex-app.d.ts +0 -4
- package/dist/adapters/cli/codex-app.d.ts.map +0 -1
- package/dist/adapters/cli/codex-app.js +0 -72
- package/dist/adapters/cli/codex-app.js.map +0 -1
- package/dist/adapters/cli/hermes.d.ts +0 -4
- package/dist/adapters/cli/hermes.d.ts.map +0 -1
- package/dist/adapters/cli/hermes.js +0 -40
- package/dist/adapters/cli/hermes.js.map +0 -1
- package/dist/adapters/cli/mira.d.ts +0 -4
- package/dist/adapters/cli/mira.d.ts.map +0 -1
- package/dist/adapters/cli/mira.js +0 -67
- package/dist/adapters/cli/mira.js.map +0 -1
- package/dist/adapters/cli/mtr.d.ts +0 -5
- package/dist/adapters/cli/mtr.d.ts.map +0 -1
- package/dist/adapters/cli/mtr.js +0 -62
- package/dist/adapters/cli/mtr.js.map +0 -1
- package/dist/adapters/hook-command.d.ts +0 -18
- package/dist/adapters/hook-command.d.ts.map +0 -1
- package/dist/adapters/hook-command.js +0 -38
- package/dist/adapters/hook-command.js.map +0 -1
- package/dist/adapters/hook-installer.d.ts +0 -14
- package/dist/adapters/hook-installer.d.ts.map +0 -1
- package/dist/adapters/hook-installer.js +0 -192
- package/dist/adapters/hook-installer.js.map +0 -1
- package/dist/codex-app-runner.d.ts +0 -3
- package/dist/codex-app-runner.d.ts.map +0 -1
- package/dist/codex-app-runner.js +0 -512
- package/dist/codex-app-runner.js.map +0 -1
- package/dist/core/ask-api.d.ts +0 -47
- package/dist/core/ask-api.d.ts.map +0 -1
- package/dist/core/ask-api.js +0 -139
- package/dist/core/ask-api.js.map +0 -1
- package/dist/core/ask-args.d.ts +0 -53
- package/dist/core/ask-args.d.ts.map +0 -1
- package/dist/core/ask-args.js +0 -122
- package/dist/core/ask-args.js.map +0 -1
- package/dist/core/ask-broker.d.ts +0 -98
- package/dist/core/ask-broker.d.ts.map +0 -1
- package/dist/core/ask-broker.js +0 -329
- package/dist/core/ask-broker.js.map +0 -1
- package/dist/core/ask-hook/claude-code.d.ts +0 -50
- package/dist/core/ask-hook/claude-code.d.ts.map +0 -1
- package/dist/core/ask-hook/claude-code.js +0 -145
- package/dist/core/ask-hook/claude-code.js.map +0 -1
- package/dist/core/ask-hook/codex.d.ts +0 -43
- package/dist/core/ask-hook/codex.d.ts.map +0 -1
- package/dist/core/ask-hook/codex.js +0 -69
- package/dist/core/ask-hook/codex.js.map +0 -1
- package/dist/core/ask-hook/opencode.d.ts +0 -41
- package/dist/core/ask-hook/opencode.d.ts.map +0 -1
- package/dist/core/ask-hook/opencode.js +0 -108
- package/dist/core/ask-hook/opencode.js.map +0 -1
- package/dist/core/ask-hook/registry.d.ts +0 -3
- package/dist/core/ask-hook/registry.d.ts.map +0 -1
- package/dist/core/ask-hook/registry.js +0 -12
- package/dist/core/ask-hook/registry.js.map +0 -1
- package/dist/core/ask-hook/types.d.ts +0 -26
- package/dist/core/ask-hook/types.d.ts.map +0 -1
- package/dist/core/ask-hook/types.js +0 -2
- package/dist/core/ask-hook/types.js.map +0 -1
- package/dist/core/ask-types.d.ts +0 -146
- package/dist/core/ask-types.d.ts.map +0 -1
- package/dist/core/ask-types.js +0 -18
- package/dist/core/ask-types.js.map +0 -1
- package/dist/core/trigger-session.d.ts +0 -9
- package/dist/core/trigger-session.d.ts.map +0 -1
- package/dist/core/trigger-session.js +0 -158
- package/dist/core/trigger-session.js.map +0 -1
- package/dist/dashboard/connector-api.d.ts +0 -3
- package/dist/dashboard/connector-api.d.ts.map +0 -1
- package/dist/dashboard/connector-api.js +0 -351
- package/dist/dashboard/connector-api.js.map +0 -1
- package/dist/dashboard/federated-group-core.d.ts +0 -54
- package/dist/dashboard/federated-group-core.d.ts.map +0 -1
- package/dist/dashboard/federated-group-core.js +0 -165
- package/dist/dashboard/federated-group-core.js.map +0 -1
- package/dist/dashboard/federation-api.d.ts +0 -42
- package/dist/dashboard/federation-api.d.ts.map +0 -1
- package/dist/dashboard/federation-api.js +0 -408
- package/dist/dashboard/federation-api.js.map +0 -1
- package/dist/dashboard/federation-spoke-api.d.ts +0 -76
- package/dist/dashboard/federation-spoke-api.d.ts.map +0 -1
- package/dist/dashboard/federation-spoke-api.js +0 -618
- package/dist/dashboard/federation-spoke-api.js.map +0 -1
- package/dist/dashboard/team-group.d.ts +0 -18
- package/dist/dashboard/team-group.d.ts.map +0 -1
- package/dist/dashboard/team-group.js +0 -7
- package/dist/dashboard/team-group.js.map +0 -1
- package/dist/dashboard/trigger-api.d.ts +0 -13
- package/dist/dashboard/trigger-api.d.ts.map +0 -1
- package/dist/dashboard/trigger-api.js +0 -77
- package/dist/dashboard/trigger-api.js.map +0 -1
- package/dist/dashboard/web/connectors.d.ts +0 -2
- package/dist/dashboard/web/connectors.d.ts.map +0 -1
- package/dist/dashboard/web/connectors.js +0 -187
- package/dist/dashboard/web/connectors.js.map +0 -1
- package/dist/dashboard/web/team-federation.d.ts +0 -3
- package/dist/dashboard/web/team-federation.d.ts.map +0 -1
- package/dist/dashboard/web/team-federation.js +0 -487
- package/dist/dashboard/web/team-federation.js.map +0 -1
- package/dist/dashboard/webhook-routes.d.ts +0 -19
- package/dist/dashboard/webhook-routes.d.ts.map +0 -1
- package/dist/dashboard/webhook-routes.js +0 -321
- package/dist/dashboard/webhook-routes.js.map +0 -1
- package/dist/im/lark/ask-card.d.ts +0 -55
- package/dist/im/lark/ask-card.d.ts.map +0 -1
- package/dist/im/lark/ask-card.js +0 -328
- package/dist/im/lark/ask-card.js.map +0 -1
- package/dist/mira-output.d.ts +0 -3
- package/dist/mira-output.d.ts.map +0 -1
- package/dist/mira-output.js +0 -136
- package/dist/mira-output.js.map +0 -1
- package/dist/mira-runner.d.ts +0 -3
- package/dist/mira-runner.d.ts.map +0 -1
- package/dist/mira-runner.js +0 -534
- package/dist/mira-runner.js.map +0 -1
- package/dist/services/bot-owner-store.d.ts +0 -28
- package/dist/services/bot-owner-store.d.ts.map +0 -1
- package/dist/services/bot-owner-store.js +0 -82
- package/dist/services/bot-owner-store.js.map +0 -1
- package/dist/services/bot-profile-store.d.ts +0 -16
- package/dist/services/bot-profile-store.d.ts.map +0 -1
- package/dist/services/bot-profile-store.js +0 -98
- package/dist/services/bot-profile-store.js.map +0 -1
- package/dist/services/brand-store.d.ts +0 -15
- package/dist/services/brand-store.d.ts.map +0 -1
- package/dist/services/brand-store.js +0 -47
- package/dist/services/brand-store.js.map +0 -1
- package/dist/services/card-prefs-store.d.ts +0 -20
- package/dist/services/card-prefs-store.d.ts.map +0 -1
- package/dist/services/card-prefs-store.js +0 -82
- package/dist/services/card-prefs-store.js.map +0 -1
- package/dist/services/connector-store.d.ts +0 -58
- package/dist/services/connector-store.d.ts.map +0 -1
- package/dist/services/connector-store.js +0 -79
- package/dist/services/connector-store.js.map +0 -1
- package/dist/services/deployment-identity.d.ts +0 -22
- package/dist/services/deployment-identity.d.ts.map +0 -1
- package/dist/services/deployment-identity.js +0 -67
- package/dist/services/deployment-identity.js.map +0 -1
- package/dist/services/federation-membership-store.d.ts +0 -23
- package/dist/services/federation-membership-store.d.ts.map +0 -1
- package/dist/services/federation-membership-store.js +0 -66
- package/dist/services/federation-membership-store.js.map +0 -1
- package/dist/services/federation-roster.d.ts +0 -54
- package/dist/services/federation-roster.d.ts.map +0 -1
- package/dist/services/federation-roster.js +0 -51
- package/dist/services/federation-roster.js.map +0 -1
- package/dist/services/federation-store.d.ts +0 -76
- package/dist/services/federation-store.d.ts.map +0 -1
- package/dist/services/federation-store.js +0 -133
- package/dist/services/federation-store.js.map +0 -1
- package/dist/services/hermes-transcript.d.ts +0 -7
- package/dist/services/hermes-transcript.d.ts.map +0 -1
- package/dist/services/hermes-transcript.js +0 -117
- package/dist/services/hermes-transcript.js.map +0 -1
- package/dist/services/invite-store.d.ts +0 -28
- package/dist/services/invite-store.d.ts.map +0 -1
- package/dist/services/invite-store.js +0 -85
- package/dist/services/invite-store.js.map +0 -1
- package/dist/services/pairing-store.d.ts +0 -47
- package/dist/services/pairing-store.d.ts.map +0 -1
- package/dist/services/pairing-store.js +0 -132
- package/dist/services/pairing-store.js.map +0 -1
- package/dist/services/relay-picker.d.ts +0 -22
- package/dist/services/relay-picker.d.ts.map +0 -1
- package/dist/services/relay-picker.js +0 -62
- package/dist/services/relay-picker.js.map +0 -1
- package/dist/services/send-policy.d.ts +0 -55
- package/dist/services/send-policy.d.ts.map +0 -1
- package/dist/services/send-policy.js +0 -47
- package/dist/services/send-policy.js.map +0 -1
- package/dist/services/team-roster.d.ts +0 -38
- package/dist/services/team-roster.d.ts.map +0 -1
- package/dist/services/team-roster.js +0 -82
- package/dist/services/team-roster.js.map +0 -1
- package/dist/services/team-store.d.ts +0 -54
- package/dist/services/team-store.d.ts.map +0 -1
- package/dist/services/team-store.js +0 -156
- package/dist/services/team-store.js.map +0 -1
- package/dist/services/trigger-log-store.d.ts +0 -46
- package/dist/services/trigger-log-store.d.ts.map +0 -1
- package/dist/services/trigger-log-store.js +0 -132
- package/dist/services/trigger-log-store.js.map +0 -1
- package/dist/services/trigger-types.d.ts +0 -57
- package/dist/services/trigger-types.d.ts.map +0 -1
- package/dist/services/trigger-types.js +0 -28
- package/dist/services/trigger-types.js.map +0 -1
- package/dist/services/webhook-key.d.ts +0 -16
- package/dist/services/webhook-key.d.ts.map +0 -1
- package/dist/services/webhook-key.js +0 -123
- package/dist/services/webhook-key.js.map +0 -1
- package/dist/services/webhook-lifecycle-extractors.d.ts +0 -15
- package/dist/services/webhook-lifecycle-extractors.d.ts.map +0 -1
- package/dist/services/webhook-lifecycle-extractors.js +0 -59
- package/dist/services/webhook-lifecycle-extractors.js.map +0 -1
- package/dist/services/webhook-lifecycle-store.d.ts +0 -45
- package/dist/services/webhook-lifecycle-store.d.ts.map +0 -1
- package/dist/services/webhook-lifecycle-store.js +0 -159
- package/dist/services/webhook-lifecycle-store.js.map +0 -1
- package/dist/utils/daemon-discovery.d.ts +0 -11
- package/dist/utils/daemon-discovery.d.ts.map +0 -1
- package/dist/utils/daemon-discovery.js +0 -59
- package/dist/utils/daemon-discovery.js.map +0 -1
- package/dist/workflows/trigger-from-envelope.d.ts +0 -13
- package/dist/workflows/trigger-from-envelope.d.ts.map +0 -1
- package/dist/workflows/trigger-from-envelope.js +0 -67
- package/dist/workflows/trigger-from-envelope.js.map +0 -1
|
@@ -2,32 +2,32 @@
|
|
|
2
2
|
* Command handler — processes /slash commands from users.
|
|
3
3
|
* Extracted from daemon.ts for modularity.
|
|
4
4
|
*/
|
|
5
|
-
import { existsSync, readFileSync
|
|
6
|
-
import { join
|
|
5
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
7
|
import { config } from '../config.js';
|
|
8
8
|
import { getBot, getAllBots, getBotOpenId } from '../bot-registry.js';
|
|
9
9
|
import * as sessionStore from '../services/session-store.js';
|
|
10
10
|
import * as scheduleStore from '../services/schedule-store.js';
|
|
11
|
+
import * as taskStore from '../services/task-store.js';
|
|
11
12
|
import * as scheduler from './scheduler.js';
|
|
12
|
-
import { scanMultipleProjects
|
|
13
|
+
import { scanMultipleProjects } from '../services/project-scanner.js';
|
|
13
14
|
import { buildRepoSelectCard, buildAdoptSelectCard, buildSessionClosedCard, getCliDisplayName } from '../im/lark/card-builder.js';
|
|
14
15
|
import { createCliAdapterSync } from '../adapters/cli/registry.js';
|
|
15
|
-
import { deleteMessage, sendMessage,
|
|
16
|
-
import { claimPairing } from '../services/pairing-store.js';
|
|
16
|
+
import { deleteMessage, sendMessage, replyMessage, listChatBotMembers } from '../im/lark/client.js';
|
|
17
17
|
import { logger } from '../utils/logger.js';
|
|
18
|
-
import { killWorker, forkWorker, forkAdoptWorker, getCurrentCliVersion
|
|
18
|
+
import { killWorker, forkWorker, forkAdoptWorker, getCurrentCliVersion } from './worker-pool.js';
|
|
19
19
|
import { expandHome, getSessionWorkingDir, getProjectScanDirs, rememberLastCliInput } from './session-manager.js';
|
|
20
20
|
import { validateWorkingDir } from './working-dir.js';
|
|
21
21
|
import { discoverAdoptableSessions, validateAdoptTarget } from './session-discovery.js';
|
|
22
22
|
import { generateAuthUrl, getTokenStatus } from '../utils/user-token.js';
|
|
23
23
|
import { bindOncall, unbindOncall, getOncallStatus } from '../services/oncall-store.js';
|
|
24
24
|
import { invalidWorkingDirs } from '../utils/working-dir.js';
|
|
25
|
-
import { writeRoleFile, deleteRoleFile
|
|
26
|
-
import {
|
|
25
|
+
import { resolveRoleFile, writeRoleFile, deleteRoleFile } from './role-resolver.js';
|
|
26
|
+
import { addFeishuTaskAssignee, completeFeishuTask, createFeishuTask, FeishuTaskUnavailableError } from '../services/feishu-task-client.js';
|
|
27
27
|
import { sessionKey, sessionAnchorId } from './types.js';
|
|
28
28
|
import { t, localeForBot } from '../i18n/index.js';
|
|
29
29
|
// ─── Exported constants ──────────────────────────────────────────────────────
|
|
30
|
-
export const DAEMON_COMMANDS = new Set(['/close', '/restart', '/status', '/help', '/cd', '/repo', '/schedule', '/
|
|
30
|
+
export const DAEMON_COMMANDS = new Set(['/close', '/restart', '/status', '/help', '/cd', '/repo', '/skip', '/schedule', '/task', '/role', '/login', '/adopt', '/oncall', '/group', '/g']);
|
|
31
31
|
/**
|
|
32
32
|
* Slash commands that are forwarded verbatim to the underlying CLI (e.g.
|
|
33
33
|
* Claude Code's `/compact`, `/model`, `/usage`). The daemon does NOT handle
|
|
@@ -47,67 +47,6 @@ const MULTILINE_COMMANDS = new Set(['/schedule', '/role']);
|
|
|
47
47
|
// `validateWorkingDir` now lives in ./working-dir.js (leaf module the CLI can
|
|
48
48
|
// import without the daemon graph); re-exported here for existing callers.
|
|
49
49
|
export { validateWorkingDir };
|
|
50
|
-
/**
|
|
51
|
-
* Resolve a non-numeric `/repo <arg>` into a concrete repo path + display name.
|
|
52
|
-
* `arg` is either a path (absolute or relative) or a first-level project name
|
|
53
|
-
* under one of the bot's scan dirs — letting the user skip the selection card.
|
|
54
|
-
*
|
|
55
|
-
* Resolution:
|
|
56
|
-
* 1. Build candidate absolute paths — absolute / `~` taken as-is; relative or
|
|
57
|
-
* bare names resolved against each scan dir, then the daemon cwd (mirrors
|
|
58
|
-
* how the card's project list is rooted).
|
|
59
|
-
* 2. Prefer a candidate matching a scanned git project (carries a branch label).
|
|
60
|
-
* 3. For a bare name, also match a scanned project by basename (covers projects
|
|
61
|
-
* nested deeper than the scan-dir top level).
|
|
62
|
-
* 4. Fall back to any existing directory — lenient like `/cd`, whose trust model
|
|
63
|
-
* is "owner explicitly chose a dir"; the CLI already runs with full FS access.
|
|
64
|
-
* Returns null when nothing resolves to an existing directory.
|
|
65
|
-
*/
|
|
66
|
-
export function resolveRepoSelection(repoArg, scanDirs) {
|
|
67
|
-
const existingScanDirs = scanDirs.filter((d) => existsSync(d));
|
|
68
|
-
const projects = existingScanDirs.length > 0 ? scanMultipleProjects(existingScanDirs) : [];
|
|
69
|
-
const isExplicitPath = repoArg.startsWith('/') ||
|
|
70
|
-
repoArg.startsWith('~') ||
|
|
71
|
-
repoArg.startsWith('.') ||
|
|
72
|
-
repoArg.includes('/');
|
|
73
|
-
const candidates = [];
|
|
74
|
-
if (repoArg.startsWith('/') || repoArg.startsWith('~')) {
|
|
75
|
-
candidates.push(resolve(expandHome(repoArg)));
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
for (const d of scanDirs)
|
|
79
|
-
candidates.push(resolve(d, repoArg));
|
|
80
|
-
candidates.push(resolve(expandHome(repoArg))); // daemon-cwd fallback (matches /cd)
|
|
81
|
-
}
|
|
82
|
-
// 1) Exact scanned-project match — preferred, gives the "name (branch)" label.
|
|
83
|
-
for (const cand of candidates) {
|
|
84
|
-
const proj = projects.find((p) => resolve(p.path) === cand);
|
|
85
|
-
if (proj)
|
|
86
|
-
return { path: proj.path, displayName: `${proj.name} (${proj.branch})` };
|
|
87
|
-
}
|
|
88
|
-
// 2) Bare name → match a scanned project by basename.
|
|
89
|
-
if (!isExplicitPath) {
|
|
90
|
-
const byName = projects.find((p) => p.name === repoArg);
|
|
91
|
-
if (byName)
|
|
92
|
-
return { path: byName.path, displayName: `${byName.name} (${byName.branch})` };
|
|
93
|
-
}
|
|
94
|
-
// 3) Lenient fallback: any existing directory. Label it with a git ref when
|
|
95
|
-
// it's a repo (covers explicit paths outside the scan roots), else basename.
|
|
96
|
-
for (const cand of candidates) {
|
|
97
|
-
try {
|
|
98
|
-
if (!statSync(cand).isDirectory())
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
continue; // missing / not a dir — try next candidate
|
|
103
|
-
}
|
|
104
|
-
const desc = describeProjectDir(cand);
|
|
105
|
-
return desc
|
|
106
|
-
? { path: cand, displayName: `${desc.name} (${desc.branch})` }
|
|
107
|
-
: { path: cand, displayName: basename(cand) };
|
|
108
|
-
}
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
50
|
/**
|
|
112
51
|
* Parse a force-topic invocation: `/t [prompt]` or `/topic [prompt]`.
|
|
113
52
|
*
|
|
@@ -220,69 +159,16 @@ function invalidConfiguredWorkingDirs(ds, larkAppId) {
|
|
|
220
159
|
});
|
|
221
160
|
}
|
|
222
161
|
// ─── Schedule command ────────────────────────────────────────────────────────
|
|
223
|
-
async function handleRoleCommand(args, rootId, chatId, larkAppId,
|
|
162
|
+
async function handleRoleCommand(args, rootId, chatId, larkAppId, deps) {
|
|
224
163
|
const sessionReply = (rid, content, msgType) => deps.sessionReply(rid, content, msgType, larkAppId);
|
|
225
164
|
const trimmed = args.trim();
|
|
226
165
|
const loc = localeForBot(larkAppId);
|
|
227
|
-
|
|
228
|
-
// /role team [...] — manage the team-level (per-bot, cross-chat) role
|
|
229
|
-
const teamMatch = trimmed.match(/^team\b([\s\S]*)$/);
|
|
230
|
-
if (teamMatch) {
|
|
231
|
-
const teamArgs = teamMatch[1].trim();
|
|
232
|
-
const teamSet = teamArgs.match(/^set\s+([\s\S]+)/);
|
|
233
|
-
if (teamSet) {
|
|
234
|
-
const content = teamSet[1].trim();
|
|
235
|
-
if (!content) {
|
|
236
|
-
await sessionReply(rootId, t('role.set_empty', undefined, loc));
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
writeTeamRoleFile(larkAppId, content);
|
|
240
|
-
await sessionReply(rootId, t('role.team_saved', { bytes: Buffer.byteLength(content, 'utf-8'), max: 4096 }, loc));
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
if (teamArgs === 'delete' || teamArgs === '删除') {
|
|
244
|
-
await sessionReply(rootId, deleteTeamRoleFile(larkAppId) ? t('role.team_deleted', undefined, loc) : t('role.team_nothing', undefined, loc));
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
const content = resolveTeamRoleFile(larkAppId);
|
|
248
|
-
if (content) {
|
|
249
|
-
await sessionReply(rootId, `${t('role.team_current', undefined, loc)}\n\`\`\`markdown\n${content}\n\`\`\`\n${t('role.byte_count', { bytes: Buffer.byteLength(content, 'utf-8'), max: 4096 }, loc)}`);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
await sessionReply(rootId, t('role.team_empty', undefined, loc));
|
|
253
|
-
}
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
// /role cap [...] — manage the short capability label shown in the roster
|
|
257
|
-
const capMatch = trimmed.match(/^cap\b([\s\S]*)$/);
|
|
258
|
-
if (capMatch) {
|
|
259
|
-
const capArgs = capMatch[1].trim();
|
|
260
|
-
const capSet = capArgs.match(/^set\s+([\s\S]+)/);
|
|
261
|
-
if (capSet) {
|
|
262
|
-
const label = capSet[1].trim();
|
|
263
|
-
if (!label) {
|
|
264
|
-
await sessionReply(rootId, t('role.cap_set_empty', undefined, loc));
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
setBotCapability(dataDir, larkAppId, label, senderId);
|
|
268
|
-
await sessionReply(rootId, t('role.cap_saved', { cap: getBotCapability(dataDir, larkAppId) ?? label }, loc));
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
if (capArgs === 'clear' || capArgs === '清除') {
|
|
272
|
-
await sessionReply(rootId, clearBotCapability(dataDir, larkAppId) ? t('role.cap_cleared', undefined, loc) : t('role.cap_empty', undefined, loc));
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
const cap = getBotCapability(dataDir, larkAppId);
|
|
276
|
-
await sessionReply(rootId, cap ? t('role.cap_current', { cap }, loc) : t('role.cap_empty', undefined, loc));
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
// /role → show the EFFECTIVE role + where it comes from (chat override > team > none)
|
|
166
|
+
// /role → show current role
|
|
280
167
|
if (!trimmed) {
|
|
281
|
-
const
|
|
168
|
+
const content = resolveRoleFile(larkAppId, chatId);
|
|
282
169
|
if (content) {
|
|
283
170
|
const len = Buffer.byteLength(content, 'utf-8');
|
|
284
|
-
|
|
285
|
-
await sessionReply(rootId, `${t('role.current', undefined, loc)} ${srcLabel}\n\`\`\`markdown\n${content}\n\`\`\`\n${t('role.byte_count', { bytes: len, max: 4096 }, loc)}`);
|
|
171
|
+
await sessionReply(rootId, `${t('role.current', undefined, loc)}\n\`\`\`markdown\n${content}\n\`\`\`\n${t('role.byte_count', { bytes: len, max: 4096 }, loc)}`);
|
|
286
172
|
}
|
|
287
173
|
else {
|
|
288
174
|
await sessionReply(rootId, t('role.empty', undefined, loc));
|
|
@@ -425,6 +311,237 @@ async function handleScheduleCommand(args, rootId, chatId, deps, larkAppId) {
|
|
|
425
311
|
// Unrecognized format
|
|
426
312
|
await sessionReply(rootId, t('schedule.parse_failed', undefined, loc));
|
|
427
313
|
}
|
|
314
|
+
function taskUsage() {
|
|
315
|
+
return [
|
|
316
|
+
'用法:',
|
|
317
|
+
'/task new <name> - 登记当前 thread/chat 的任务(需要已有 session)',
|
|
318
|
+
'/task list - 列出当前群的任务',
|
|
319
|
+
'/task status <task-id> - 查看任务状态',
|
|
320
|
+
'/task close <task-id> - 关闭任务登记(不关闭 session)',
|
|
321
|
+
'/task assign <task-id> @Bot - 指派任务并显式 @目标 bot',
|
|
322
|
+
].join('\n');
|
|
323
|
+
}
|
|
324
|
+
function formatTaskStatus(task) {
|
|
325
|
+
return [
|
|
326
|
+
`Task: ${task.taskId}`,
|
|
327
|
+
`Feishu Task: ${task.externalTaskId ?? '-'}`,
|
|
328
|
+
`Name: ${task.name}`,
|
|
329
|
+
`Status: ${task.status}`,
|
|
330
|
+
`Session: ${task.sessionId}`,
|
|
331
|
+
`Chat: ${task.chatId}`,
|
|
332
|
+
`Anchor: ${task.anchor}`,
|
|
333
|
+
`Bot app: ${task.larkAppId}`,
|
|
334
|
+
`Owner: ${task.ownerOpenId ? `<at id=${task.ownerOpenId}></at>` : '-'}`,
|
|
335
|
+
`Assignee: ${task.assigneeOpenId ? `<at id=${task.assigneeOpenId}></at>` : '-'}`,
|
|
336
|
+
task.externalSyncError ? `Feishu sync: ${task.externalSyncError}` : undefined,
|
|
337
|
+
`Created: ${task.createdAt}`,
|
|
338
|
+
`Updated: ${task.updatedAt}`,
|
|
339
|
+
].filter(Boolean).join('\n');
|
|
340
|
+
}
|
|
341
|
+
function buildTaskHandoffPost(task, assigneeOpenId) {
|
|
342
|
+
const content = [
|
|
343
|
+
[
|
|
344
|
+
{ tag: 'at', user_id: assigneeOpenId },
|
|
345
|
+
{ tag: 'text', text: ` 请接手任务 ${task.taskId}:${task.name}` },
|
|
346
|
+
],
|
|
347
|
+
[{ tag: 'text', text: `Task: ${task.taskId}` }],
|
|
348
|
+
[{ tag: 'text', text: `Feishu Task: ${task.externalTaskId ?? '-'}` }],
|
|
349
|
+
[{ tag: 'text', text: `Session: ${task.sessionId}` }],
|
|
350
|
+
[{ tag: 'text', text: `Chat: ${task.chatId}` }],
|
|
351
|
+
[{ tag: 'text', text: `Thread/anchor: ${task.anchor}` }],
|
|
352
|
+
task.ownerOpenId
|
|
353
|
+
? [{ tag: 'text', text: 'Owner: ' }, { tag: 'at', user_id: task.ownerOpenId }]
|
|
354
|
+
: [{ tag: 'text', text: 'Owner: -' }],
|
|
355
|
+
[{ tag: 'text', text: '请基于这个 task id 和对应 thread/session 上下文继续处理;这是显式 @ 指派,不依赖 lastCaller footer。' }],
|
|
356
|
+
];
|
|
357
|
+
return JSON.stringify({ zh_cn: { title: '', content } });
|
|
358
|
+
}
|
|
359
|
+
function taskSyncError(err) {
|
|
360
|
+
if (err instanceof FeishuTaskUnavailableError)
|
|
361
|
+
return err.message;
|
|
362
|
+
return err instanceof Error ? err.message : String(err);
|
|
363
|
+
}
|
|
364
|
+
async function tryCreateExternalTask(task) {
|
|
365
|
+
try {
|
|
366
|
+
const external = await createFeishuTask({
|
|
367
|
+
larkAppId: task.larkAppId,
|
|
368
|
+
summary: task.name,
|
|
369
|
+
localTaskId: task.taskId,
|
|
370
|
+
sessionId: task.sessionId,
|
|
371
|
+
chatId: task.chatId,
|
|
372
|
+
anchor: task.anchor,
|
|
373
|
+
ownerOpenId: task.ownerOpenId,
|
|
374
|
+
});
|
|
375
|
+
return taskStore.updateTaskFields(task.taskId, {
|
|
376
|
+
externalTaskId: external.guid,
|
|
377
|
+
externalTaskUrl: external.url,
|
|
378
|
+
externalSyncError: undefined,
|
|
379
|
+
}) ?? task;
|
|
380
|
+
}
|
|
381
|
+
catch (err) {
|
|
382
|
+
const message = taskSyncError(err);
|
|
383
|
+
logger.warn(`[task] Feishu task create failed for ${task.taskId}: ${message}`);
|
|
384
|
+
return taskStore.updateTaskFields(task.taskId, { externalSyncError: message }) ?? task;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
async function tryCompleteExternalTask(task) {
|
|
388
|
+
if (!task.externalTaskId)
|
|
389
|
+
return task;
|
|
390
|
+
try {
|
|
391
|
+
await completeFeishuTask(task.larkAppId, task.externalTaskId);
|
|
392
|
+
return taskStore.updateTaskFields(task.taskId, { externalSyncError: undefined }) ?? task;
|
|
393
|
+
}
|
|
394
|
+
catch (err) {
|
|
395
|
+
const message = taskSyncError(err);
|
|
396
|
+
logger.warn(`[task] Feishu task complete failed for ${task.taskId}: ${message}`);
|
|
397
|
+
return taskStore.updateTaskFields(task.taskId, { externalSyncError: message }) ?? task;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
async function tryAssignExternalTask(task, assigneeOpenId) {
|
|
401
|
+
if (!task.externalTaskId)
|
|
402
|
+
return task;
|
|
403
|
+
try {
|
|
404
|
+
await addFeishuTaskAssignee(task.larkAppId, task.externalTaskId, assigneeOpenId);
|
|
405
|
+
return taskStore.updateTaskFields(task.taskId, { externalSyncError: undefined }) ?? task;
|
|
406
|
+
}
|
|
407
|
+
catch (err) {
|
|
408
|
+
const message = taskSyncError(err);
|
|
409
|
+
logger.warn(`[task] Feishu task assign failed for ${task.taskId}: ${message}`);
|
|
410
|
+
return taskStore.updateTaskFields(task.taskId, { externalSyncError: message }) ?? task;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function mentionedOpenIds(message) {
|
|
414
|
+
return (message.mentions ?? [])
|
|
415
|
+
.map(m => m.openId)
|
|
416
|
+
.filter((id) => !!id);
|
|
417
|
+
}
|
|
418
|
+
function isCurrentBotMention(openId, larkAppId) {
|
|
419
|
+
if (!larkAppId)
|
|
420
|
+
return false;
|
|
421
|
+
const self = getBotOpenId(larkAppId);
|
|
422
|
+
return !!self && self === openId;
|
|
423
|
+
}
|
|
424
|
+
async function handleTaskCommand(args, rootId, message, deps, larkAppId) {
|
|
425
|
+
const { activeSessions } = deps;
|
|
426
|
+
const sessionReply = (rid, content, msgType) => deps.sessionReply(rid, content, msgType, larkAppId);
|
|
427
|
+
const rawDs = larkAppId ? activeSessions.get(sessionKey(rootId, larkAppId)) : undefined;
|
|
428
|
+
const isEphemeralTaskCommandSession = !!rawDs && !rawDs.hasHistory && !rawDs.worker && rawDs.session.title.trim().startsWith('/task');
|
|
429
|
+
const commandChatId = rawDs?.chatId;
|
|
430
|
+
if (isEphemeralTaskCommandSession && larkAppId) {
|
|
431
|
+
activeSessions.delete(sessionKey(rootId, larkAppId));
|
|
432
|
+
sessionStore.closeSession(rawDs.session.sessionId);
|
|
433
|
+
}
|
|
434
|
+
const ds = isEphemeralTaskCommandSession ? undefined : rawDs;
|
|
435
|
+
const [subRaw, ...rest] = args.trim().split(/\s+/).filter(Boolean);
|
|
436
|
+
const sub = subRaw?.toLowerCase();
|
|
437
|
+
if (!sub || sub === 'help' || sub === '帮助') {
|
|
438
|
+
await sessionReply(rootId, taskUsage());
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (sub === 'new' || sub === '新建') {
|
|
442
|
+
const name = rest.join(' ').trim();
|
|
443
|
+
if (!name) {
|
|
444
|
+
await sessionReply(rootId, '请提供任务名称:/task new <name>');
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (!ds) {
|
|
448
|
+
await sessionReply(rootId, '当前没有可绑定的 session。请先在独立话题里 @Bot 发起任务,或用 /t <任务内容> 开一个独立任务。');
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
let task = taskStore.createTask({
|
|
452
|
+
name,
|
|
453
|
+
chatId: ds.chatId,
|
|
454
|
+
anchor: sessionAnchorId(ds),
|
|
455
|
+
sessionId: ds.session.sessionId,
|
|
456
|
+
larkAppId: ds.larkAppId,
|
|
457
|
+
ownerOpenId: message.senderId || ds.ownerOpenId || ds.session.ownerOpenId,
|
|
458
|
+
});
|
|
459
|
+
task = await tryCreateExternalTask(task);
|
|
460
|
+
const externalLine = task.externalTaskId
|
|
461
|
+
? `Feishu Task: ${task.externalTaskId}`
|
|
462
|
+
: `Feishu Task: 未创建(${task.externalSyncError ?? 'unknown'}),已降级为本地 task`;
|
|
463
|
+
await sessionReply(rootId, `✅ 已登记任务 ${task.taskId}\n${externalLine}\nName: ${task.name}\nSession: ${task.sessionId}\nAnchor: ${task.anchor}`);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
if (sub === 'list' || sub === '列表') {
|
|
467
|
+
const chatId = ds?.chatId ?? commandChatId ?? (() => {
|
|
468
|
+
const all = taskStore.listTasks();
|
|
469
|
+
return all.find(t => t.anchor === rootId && t.larkAppId === larkAppId)?.chatId ?? all.find(t => t.anchor === rootId)?.chatId ?? rootId;
|
|
470
|
+
})();
|
|
471
|
+
const tasks = taskStore.listTasks({ chatId });
|
|
472
|
+
if (tasks.length === 0) {
|
|
473
|
+
await sessionReply(rootId, '当前群还没有登记 task。');
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const lines = tasks.map(t => `${t.taskId} [${t.status}] ${t.name}\n feishu=${t.externalTaskId ?? '-'} session=${t.sessionId} anchor=${t.anchor} assignee=${t.assigneeOpenId ? `<at id=${t.assigneeOpenId}></at>` : '-'}`);
|
|
477
|
+
await sessionReply(rootId, `当前群任务:\n${lines.join('\n')}`);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
if (sub === 'status' || sub === '状态') {
|
|
481
|
+
const id = rest[0];
|
|
482
|
+
if (!id) {
|
|
483
|
+
await sessionReply(rootId, '请提供 task id:/task status <task-id>');
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
const task = taskStore.getTask(id);
|
|
487
|
+
if (!task) {
|
|
488
|
+
await sessionReply(rootId, `未找到 task:${id}`);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
await sessionReply(rootId, formatTaskStatus(task));
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
if (sub === 'close' || sub === '关闭') {
|
|
495
|
+
const id = rest[0];
|
|
496
|
+
if (!id) {
|
|
497
|
+
await sessionReply(rootId, '请提供 task id:/task close <task-id>');
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
let task = taskStore.closeTask(id);
|
|
501
|
+
if (!task) {
|
|
502
|
+
await sessionReply(rootId, `未找到 task:${id}`);
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
task = await tryCompleteExternalTask(task);
|
|
506
|
+
const syncLine = task.externalTaskId
|
|
507
|
+
? (task.externalSyncError ? `\nFeishu Task 同步失败:${task.externalSyncError}` : '\nFeishu Task 已标记完成。')
|
|
508
|
+
: '';
|
|
509
|
+
await sessionReply(rootId, `✅ 已关闭任务 ${task.taskId}${syncLine}\n注意:关联 session 未关闭,如需关闭请在对应话题里使用 /close。`);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
if (sub === 'assign' || sub === '指派') {
|
|
513
|
+
const id = rest[0];
|
|
514
|
+
if (!id) {
|
|
515
|
+
await sessionReply(rootId, '请提供 task id:/task assign <task-id> @Bot');
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
const candidates = mentionedOpenIds(message).filter(openId => !isCurrentBotMention(openId, larkAppId));
|
|
519
|
+
const assigneeOpenId = candidates[0];
|
|
520
|
+
if (!assigneeOpenId) {
|
|
521
|
+
await sessionReply(rootId, '请在 /task assign 命令里显式 @目标 Bot。');
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
let task = taskStore.assignTask(id, assigneeOpenId);
|
|
525
|
+
if (!task) {
|
|
526
|
+
await sessionReply(rootId, `未找到 task:${id}`);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
task = await tryAssignExternalTask(task, assigneeOpenId);
|
|
530
|
+
const handoff = buildTaskHandoffPost(task, assigneeOpenId);
|
|
531
|
+
if (!larkAppId) {
|
|
532
|
+
await sessionReply(rootId, formatTaskStatus(task));
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
if (ds?.scope === 'chat' || task.anchor.startsWith('oc_')) {
|
|
536
|
+
await sendMessage(larkAppId, task.chatId, handoff, 'post');
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
await replyMessage(larkAppId, task.anchor, handoff, 'post', true);
|
|
540
|
+
}
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
await sessionReply(rootId, taskUsage());
|
|
544
|
+
}
|
|
428
545
|
// ─── Main command handler ────────────────────────────────────────────────────
|
|
429
546
|
export async function handleCommand(cmd, rootId, message, deps, larkAppId) {
|
|
430
547
|
const { activeSessions, getActiveCount, lastRepoScan } = deps;
|
|
@@ -513,36 +630,38 @@ export async function handleCommand(cmd, rootId, message, deps, larkAppId) {
|
|
|
513
630
|
}
|
|
514
631
|
case '/repo': {
|
|
515
632
|
const repoArg = message.content.replace(/^\/repo\s*/, '').trim();
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
ds.pendingMentions = undefined;
|
|
531
|
-
ds.pendingSender = undefined;
|
|
532
|
-
ds.pendingFollowUps = undefined;
|
|
533
|
-
forkWorker(ds, prompt);
|
|
534
|
-
await sessionReply(rootId, replyText);
|
|
535
|
-
};
|
|
536
|
-
// Shared commit path for an already-resolved repo: update the session's
|
|
537
|
-
// working dir, then either fork into the pending CLI (first spawn) or
|
|
538
|
-
// close + recreate the session (mid-session switch). Used by both the
|
|
539
|
-
// numeric `/repo <N>` form and the `/repo <path|name>` form.
|
|
540
|
-
const commitRepoSelection = async (selectedPath, displayName, how) => {
|
|
633
|
+
const repoIndex = repoArg ? parseInt(repoArg, 10) : NaN;
|
|
634
|
+
if (!isNaN(repoIndex) && ds) {
|
|
635
|
+
const cached = lastRepoScan.get(ds.chatId);
|
|
636
|
+
if (!cached || cached.length === 0) {
|
|
637
|
+
await sessionReply(rootId, t('cmd.repo.no_prior_scan', undefined, loc));
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
if (repoIndex < 1 || repoIndex > cached.length) {
|
|
641
|
+
await sessionReply(rootId, t('cmd.repo.index_out_of_range', { max: cached.length }, loc));
|
|
642
|
+
break;
|
|
643
|
+
}
|
|
644
|
+
const project = cached[repoIndex - 1];
|
|
645
|
+
const selectedPath = project.path;
|
|
646
|
+
const displayName = `${project.name} (${project.branch})`;
|
|
541
647
|
ds.workingDir = selectedPath;
|
|
542
648
|
ds.session.workingDir = selectedPath;
|
|
543
649
|
sessionStore.updateSession(ds.session);
|
|
544
650
|
if (ds.pendingRepo) {
|
|
545
|
-
|
|
651
|
+
const selfBot = getBot(ds.larkAppId);
|
|
652
|
+
const botCfg = selfBot.config;
|
|
653
|
+
ds.pendingRepo = false;
|
|
654
|
+
const { buildNewTopicPrompt, getAvailableBots } = await import('./session-manager.js');
|
|
655
|
+
const pendingPrompt = ds.pendingPrompt ?? '';
|
|
656
|
+
const prompt = buildNewTopicPrompt(pendingPrompt, ds.session.sessionId, botCfg.cliId, botCfg.cliPathOverride, ds.pendingAttachments, ds.pendingMentions, await getAvailableBots(ds.larkAppId, ds.chatId), ds.pendingFollowUps, { name: selfBot.botName, openId: selfBot.botOpenId }, loc, ds.pendingSender, { larkAppId, chatId: ds.chatId });
|
|
657
|
+
rememberLastCliInput(ds, pendingPrompt, prompt);
|
|
658
|
+
ds.pendingPrompt = undefined;
|
|
659
|
+
ds.pendingAttachments = undefined;
|
|
660
|
+
ds.pendingMentions = undefined;
|
|
661
|
+
ds.pendingSender = undefined;
|
|
662
|
+
ds.pendingFollowUps = undefined;
|
|
663
|
+
forkWorker(ds, prompt);
|
|
664
|
+
await sessionReply(rootId, t('cmd.repo.selected_in_pending', { name: displayName }, loc));
|
|
546
665
|
}
|
|
547
666
|
else {
|
|
548
667
|
killWorker(ds);
|
|
@@ -562,56 +681,7 @@ export async function handleCommand(cmd, rootId, message, deps, larkAppId) {
|
|
|
562
681
|
deleteMessage(ds.larkAppId, ds.repoCardMessageId);
|
|
563
682
|
ds.repoCardMessageId = undefined;
|
|
564
683
|
}
|
|
565
|
-
logger.info(`[${logTag}] Repo selected via ${
|
|
566
|
-
};
|
|
567
|
-
// Numeric arg → pick by 1-based index from the last scan.
|
|
568
|
-
if (repoArg && ds && /^\d+$/.test(repoArg)) {
|
|
569
|
-
const repoIndex = parseInt(repoArg, 10);
|
|
570
|
-
const cached = lastRepoScan.get(ds.chatId);
|
|
571
|
-
if (!cached || cached.length === 0) {
|
|
572
|
-
await sessionReply(rootId, t('cmd.repo.no_prior_scan', undefined, loc));
|
|
573
|
-
break;
|
|
574
|
-
}
|
|
575
|
-
if (repoIndex < 1 || repoIndex > cached.length) {
|
|
576
|
-
await sessionReply(rootId, t('cmd.repo.index_out_of_range', { max: cached.length }, loc));
|
|
577
|
-
break;
|
|
578
|
-
}
|
|
579
|
-
const project = cached[repoIndex - 1];
|
|
580
|
-
await commitRepoSelection(project.path, `${project.name} (${project.branch})`, `/repo ${repoIndex}`);
|
|
581
|
-
break;
|
|
582
|
-
}
|
|
583
|
-
// Non-numeric arg → a path (relative/absolute) or first-level project
|
|
584
|
-
// name under workingDir; resolve it directly and skip the card.
|
|
585
|
-
if (repoArg && ds) {
|
|
586
|
-
const resolved = resolveRepoSelection(repoArg, getProjectScanDirs(ds));
|
|
587
|
-
if (!resolved) {
|
|
588
|
-
await sessionReply(rootId, t('cmd.repo.path_not_found', { arg: repoArg }, loc));
|
|
589
|
-
break;
|
|
590
|
-
}
|
|
591
|
-
await commitRepoSelection(resolved.path, resolved.displayName, `/repo ${repoArg}`);
|
|
592
|
-
break;
|
|
593
|
-
}
|
|
594
|
-
// Bare `/repo` while a repo card is pending → launch right away in the
|
|
595
|
-
// default workingDir. This is the text-command twin of the card's
|
|
596
|
-
// "start directly" button (and replaces the old `/skip` command).
|
|
597
|
-
// Mid-session bare `/repo` (no pending) still falls through to the card.
|
|
598
|
-
if (!repoArg && ds?.pendingRepo) {
|
|
599
|
-
// Validate the configured workingDir before spawning — `forkWorker`
|
|
600
|
-
// doesn't, so a dead cwd would otherwise spawn-and-fail silently. Same
|
|
601
|
-
// guard the card path runs below. On failure we keep the pending state
|
|
602
|
-
// so the user can recover with `/repo <valid-path>` (no card here).
|
|
603
|
-
const invalidDirs = invalidConfiguredWorkingDirs(ds, ds.larkAppId ?? larkAppId);
|
|
604
|
-
if (invalidDirs.length > 0) {
|
|
605
|
-
await sessionReply(rootId, t('cmd.repo.working_dir_not_exist', { dirs: invalidDirs.map(d => `\`${d}\``).join(', ') }, loc));
|
|
606
|
-
break;
|
|
607
|
-
}
|
|
608
|
-
const cwd = getSessionWorkingDir(ds);
|
|
609
|
-
await forkPendingCli(t('cmd.skip.opened', { cwd }, loc));
|
|
610
|
-
if (ds.repoCardMessageId) {
|
|
611
|
-
deleteMessage(ds.larkAppId, ds.repoCardMessageId);
|
|
612
|
-
ds.repoCardMessageId = undefined;
|
|
613
|
-
}
|
|
614
|
-
logger.info(`[${logTag}] Bare /repo while pending → launch in workingDir ${cwd}`);
|
|
684
|
+
logger.info(`[${logTag}] Repo selected via /repo ${repoIndex}: ${selectedPath}`);
|
|
615
685
|
break;
|
|
616
686
|
}
|
|
617
687
|
if (ds?.worker && !ds.worker.killed) {
|
|
@@ -643,6 +713,34 @@ export async function handleCommand(cmd, rootId, message, deps, larkAppId) {
|
|
|
643
713
|
logger.info(`[${logTag}] Sent repo card with ${projects.length} project(s)`);
|
|
644
714
|
break;
|
|
645
715
|
}
|
|
716
|
+
case '/skip': {
|
|
717
|
+
if (ds?.pendingRepo) {
|
|
718
|
+
const selfBot = getBot(ds.larkAppId);
|
|
719
|
+
const botCfg = selfBot.config;
|
|
720
|
+
ds.pendingRepo = false;
|
|
721
|
+
const { buildNewTopicPrompt, getAvailableBots } = await import('./session-manager.js');
|
|
722
|
+
const pendingPrompt = ds.pendingPrompt ?? '';
|
|
723
|
+
const prompt = buildNewTopicPrompt(pendingPrompt, ds.session.sessionId, botCfg.cliId, botCfg.cliPathOverride, ds.pendingAttachments, ds.pendingMentions, await getAvailableBots(ds.larkAppId, ds.chatId), ds.pendingFollowUps, { name: selfBot.botName, openId: selfBot.botOpenId }, loc, ds.pendingSender, { larkAppId, chatId: ds.chatId });
|
|
724
|
+
rememberLastCliInput(ds, pendingPrompt, prompt);
|
|
725
|
+
ds.pendingPrompt = undefined;
|
|
726
|
+
ds.pendingAttachments = undefined;
|
|
727
|
+
ds.pendingMentions = undefined;
|
|
728
|
+
ds.pendingSender = undefined;
|
|
729
|
+
ds.pendingFollowUps = undefined;
|
|
730
|
+
forkWorker(ds, prompt);
|
|
731
|
+
const cwd = getSessionWorkingDir(ds);
|
|
732
|
+
await sessionReply(rootId, t('cmd.skip.opened', { cwd }, loc));
|
|
733
|
+
if (ds.repoCardMessageId) {
|
|
734
|
+
deleteMessage(ds.larkAppId, ds.repoCardMessageId);
|
|
735
|
+
ds.repoCardMessageId = undefined;
|
|
736
|
+
}
|
|
737
|
+
logger.info(`[${logTag}] Skip repo via /skip, spawning CLI in ${cwd}`);
|
|
738
|
+
}
|
|
739
|
+
else {
|
|
740
|
+
await sessionReply(rootId, t('cmd.skip.no_pending', undefined, loc));
|
|
741
|
+
}
|
|
742
|
+
break;
|
|
743
|
+
}
|
|
646
744
|
case '/status': {
|
|
647
745
|
if (ds) {
|
|
648
746
|
const alive = ds.worker && !ds.worker.killed;
|
|
@@ -677,6 +775,12 @@ export async function handleCommand(cmd, rootId, message, deps, larkAppId) {
|
|
|
677
775
|
logger.info(`[${logTag}] Schedule command handled`);
|
|
678
776
|
break;
|
|
679
777
|
}
|
|
778
|
+
case '/task': {
|
|
779
|
+
const taskArgs = message.content.replace(/^\/task\s*/i, '');
|
|
780
|
+
await handleTaskCommand(taskArgs, rootId, message, deps, larkAppId);
|
|
781
|
+
logger.info(`[${logTag}] Task command handled`);
|
|
782
|
+
break;
|
|
783
|
+
}
|
|
680
784
|
case '/role': {
|
|
681
785
|
const chatId = ds?.chatId;
|
|
682
786
|
if (!chatId || !larkAppId) {
|
|
@@ -684,35 +788,10 @@ export async function handleCommand(cmd, rootId, message, deps, larkAppId) {
|
|
|
684
788
|
break;
|
|
685
789
|
}
|
|
686
790
|
const roleArgs = message.content.replace(/^\/role\s*/, '');
|
|
687
|
-
await handleRoleCommand(roleArgs, rootId, chatId, larkAppId,
|
|
791
|
+
await handleRoleCommand(roleArgs, rootId, chatId, larkAppId, deps);
|
|
688
792
|
logger.info(`[${logTag}] Role command handled`);
|
|
689
793
|
break;
|
|
690
794
|
}
|
|
691
|
-
case '/pair': {
|
|
692
|
-
const code = message.content.replace(/^\/pair\s*/, '').trim();
|
|
693
|
-
if (!larkAppId) {
|
|
694
|
-
await sessionReply(rootId, t('role.no_chat', undefined, loc));
|
|
695
|
-
break;
|
|
696
|
-
}
|
|
697
|
-
if (!code) {
|
|
698
|
-
await sessionReply(rootId, t('pair.usage', undefined, loc));
|
|
699
|
-
break;
|
|
700
|
-
}
|
|
701
|
-
// Resolve the sender's canonical union_id (best-effort) so the web
|
|
702
|
-
// session is keyed stably across apps; degrade to open_id-only.
|
|
703
|
-
const who = await resolveUserUnionId(larkAppId, message.senderId);
|
|
704
|
-
const result = claimPairing(config.session.dataDir, code, { openId: message.senderId, unionId: who.unionId, name: who.name, larkAppId });
|
|
705
|
-
if (result.ok)
|
|
706
|
-
await sessionReply(rootId, t('pair.ok', undefined, loc));
|
|
707
|
-
else if (result.reason === 'expired')
|
|
708
|
-
await sessionReply(rootId, t('pair.expired', undefined, loc));
|
|
709
|
-
else if (result.reason === 'already_claimed')
|
|
710
|
-
await sessionReply(rootId, t('pair.already', undefined, loc));
|
|
711
|
-
else
|
|
712
|
-
await sessionReply(rootId, t('pair.not_found', undefined, loc));
|
|
713
|
-
logger.info(`[${logTag}] Pair command handled: ${result.ok ? 'ok' : result.reason}`);
|
|
714
|
-
break;
|
|
715
|
-
}
|
|
716
795
|
case '/login': {
|
|
717
796
|
const subCmd = message.content.replace(/^\/login\s*/, '').trim();
|
|
718
797
|
if (subCmd === 'status' || subCmd === '状态') {
|
|
@@ -977,10 +1056,7 @@ export async function handleCommand(cmd, rootId, message, deps, larkAppId) {
|
|
|
977
1056
|
transferOwnerTo: senderOpenId,
|
|
978
1057
|
notifyOwnerOpenId: senderOpenId,
|
|
979
1058
|
});
|
|
980
|
-
|
|
981
|
-
// back to the member-only applink URL when Lark's link API failed.
|
|
982
|
-
const applink = `https://applink.feishu.cn/client/chat/open?openChatId=${encodeURIComponent(result.chatId)}`;
|
|
983
|
-
const link = result.shareLink ?? applink;
|
|
1059
|
+
const link = `https://applink.feishu.cn/client/chat/open?openChatId=${encodeURIComponent(result.chatId)}`;
|
|
984
1060
|
// Partial failures are non-fatal — the chat exists; surface them as
|
|
985
1061
|
// hints so the user knows whether to expect to be auto-invited.
|
|
986
1062
|
const hints = [];
|
|
@@ -990,12 +1066,6 @@ export async function handleCommand(cmd, rootId, message, deps, larkAppId) {
|
|
|
990
1066
|
else if (result.transferError) {
|
|
991
1067
|
hints.push(t('cmd.group.warn_transfer_failed', { reason: result.transferError }, loc));
|
|
992
1068
|
}
|
|
993
|
-
// Share-link fetch failed → the displayed link is the member-only
|
|
994
|
-
// applink; warn the user so they don't expect non-members to join via it.
|
|
995
|
-
if (!result.shareLink && result.shareLinkError) {
|
|
996
|
-
logger.warn(`[${logTag}] /group share-link unavailable, using applink: ${result.shareLinkError}`);
|
|
997
|
-
hints.push(t('cmd.group.warn_share_link_failed', undefined, loc));
|
|
998
|
-
}
|
|
999
1069
|
// List every bot in the new group (creator included), and warn about
|
|
1000
1070
|
// any Feishu rejected. Names come from the chat roster (members) since
|
|
1001
1071
|
// getBot() only knows this process's own bot in the one-daemon-per-bot
|
|
@@ -1022,527 +1092,6 @@ export async function handleCommand(cmd, rootId, message, deps, larkAppId) {
|
|
|
1022
1092
|
}
|
|
1023
1093
|
break;
|
|
1024
1094
|
}
|
|
1025
|
-
/**
|
|
1026
|
-
* `/relay --create <群名> @bot [@bot...]` — create a new chat, invite
|
|
1027
|
-
* the @-mentioned bots, then migrate every bot's session in this
|
|
1028
|
-
* thread (including the leader's) into the new chat.
|
|
1029
|
-
*
|
|
1030
|
-
* Two-path command:
|
|
1031
|
-
* • `--create` (PR2) — implemented below; creates a new chat.
|
|
1032
|
-
* • no flag (PR3) — picker card listing user's relayable sessions
|
|
1033
|
-
* in OTHER chats so the user can pull one into
|
|
1034
|
-
* the current chat. Stubbed for now.
|
|
1035
|
-
*
|
|
1036
|
-
* Leader election is `mentions[0]` (identical to /group). The leader
|
|
1037
|
-
* is the only daemon that:
|
|
1038
|
-
* 1. Creates the new chat (createGroupWithBots)
|
|
1039
|
-
* 2. Sends the M1 announcement message (its message_id becomes the
|
|
1040
|
-
* shared rootMessageId for all relayed sessions — multi-bot
|
|
1041
|
-
* sessions co-anchor on the same root via different larkAppIds)
|
|
1042
|
-
* 3. Transfers its own session (if any) via local transferSession()
|
|
1043
|
-
* 4. POSTs /api/sessions/migrate-to-chat to every peer daemon to
|
|
1044
|
-
* ask them to transfer their own session at the same anchor
|
|
1045
|
-
* 5. Aggregates results into a single reply in the source thread
|
|
1046
|
-
*
|
|
1047
|
-
* Owner-only: only the source session's `ownerOpenId` may invoke. Peers
|
|
1048
|
-
* enforce the same check independently inside the migrate endpoint.
|
|
1049
|
-
*
|
|
1050
|
-
* Failure mode: best-effort, no rollback. Peers that timeout / fail /
|
|
1051
|
-
* are offline simply appear in the report as "skipped". The new chat
|
|
1052
|
-
* and any successful transfers stand.
|
|
1053
|
-
*/
|
|
1054
|
-
case '/relay': {
|
|
1055
|
-
const argsLine = message.content.replace(/^\/relay\s*/i, '').trim();
|
|
1056
|
-
if (!/^--create\b/i.test(argsLine)) {
|
|
1057
|
-
// ── Pull picker ───────────────────────────────────────────────────
|
|
1058
|
-
// /relay (no flag) lives in the *target* chat — list the operator's
|
|
1059
|
-
// own active sessions in OTHER chats so they can pull one in.
|
|
1060
|
-
//
|
|
1061
|
-
// Filter:
|
|
1062
|
-
// • same bot (this larkAppId)
|
|
1063
|
-
// • session is active (has a worker / appears in activeSessions)
|
|
1064
|
-
// • session NOT in the current chat (can't relay to yourself)
|
|
1065
|
-
// • operator IS the session owner (owner-only access)
|
|
1066
|
-
//
|
|
1067
|
-
// The button's `target_chat_id` / `target_root_id` are the chat we're
|
|
1068
|
-
// pulling INTO (the chat hosting this command). card-handler uses
|
|
1069
|
-
// them to invoke transferSession after sending the M1 announcement.
|
|
1070
|
-
const operatorOpenId = message.senderId;
|
|
1071
|
-
if (!operatorOpenId) {
|
|
1072
|
-
await sessionReply(rootId, t('cmd.relay.no_sender', undefined, loc));
|
|
1073
|
-
break;
|
|
1074
|
-
}
|
|
1075
|
-
const myAppId = larkAppId ?? ds?.larkAppId;
|
|
1076
|
-
if (!myAppId) {
|
|
1077
|
-
await sessionReply(rootId, t('cmd.group.no_bot', undefined, loc));
|
|
1078
|
-
break;
|
|
1079
|
-
}
|
|
1080
|
-
const targetChatId = ds?.chatId;
|
|
1081
|
-
if (!targetChatId) {
|
|
1082
|
-
await sessionReply(rootId, t('cmd.relay.no_session', undefined, loc));
|
|
1083
|
-
break;
|
|
1084
|
-
}
|
|
1085
|
-
// ── Chat-type guard ───────────────────────────────────────────────
|
|
1086
|
-
// Picker mode only makes sense in regular group chats. p2p (1:1 with
|
|
1087
|
-
// bot) has no relay concept — there's no other participant to
|
|
1088
|
-
// collaborate with — and topic chats route per-thread, so a chat-
|
|
1089
|
-
// scope session pulled in would have no thread anchor.
|
|
1090
|
-
//
|
|
1091
|
-
// p2p is detectable from `ds.chatType` locally (cheap). Topic vs
|
|
1092
|
-
// regular group is NOT captured in chatType — both record 'group'
|
|
1093
|
-
// — so we hit the Lark API (getChatNameAndMode) to resolve the
|
|
1094
|
-
// mode. One API call per /relay invocation; picker is user-
|
|
1095
|
-
// triggered so latency is acceptable.
|
|
1096
|
-
if (ds?.chatType === 'p2p') {
|
|
1097
|
-
await sessionReply(rootId, t('cmd.relay.picker_p2p_unsupported', undefined, loc));
|
|
1098
|
-
break;
|
|
1099
|
-
}
|
|
1100
|
-
{
|
|
1101
|
-
const { getChatNameAndMode } = await import('../im/lark/client.js');
|
|
1102
|
-
const info = await getChatNameAndMode(myAppId, targetChatId).catch(() => null);
|
|
1103
|
-
if (info?.mode === 'p2p') {
|
|
1104
|
-
await sessionReply(rootId, t('cmd.relay.picker_p2p_unsupported', undefined, loc));
|
|
1105
|
-
break;
|
|
1106
|
-
}
|
|
1107
|
-
if (info?.mode === 'topic') {
|
|
1108
|
-
await sessionReply(rootId, t('cmd.relay.picker_topic_unsupported', undefined, loc));
|
|
1109
|
-
break;
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
// ── Existing-session guard ────────────────────────────────────────
|
|
1113
|
-
// If this bot already runs a real session in the target chat, pulling
|
|
1114
|
-
// another session in would collide on sessionKey(targetChatId, larkAppId)
|
|
1115
|
-
// — Map.set would silently overwrite, orphaning the existing worker.
|
|
1116
|
-
// Refuse upfront with an actionable message.
|
|
1117
|
-
//
|
|
1118
|
-
// Scratch sessions (the placeholder a `/relay` typed in a fresh chat
|
|
1119
|
-
// gets routed through) are filtered by `!!c.worker` — they have no
|
|
1120
|
-
// worker process. We do NOT exclude `ds` by sessionId: when `/relay`
|
|
1121
|
-
// rides an EXISTING real session (daemon.ts:2034's "existing-session
|
|
1122
|
-
// DAEMON_COMMANDS" path skips the scratch and binds `ds` to the
|
|
1123
|
-
// chat's real session), `ds` itself IS the conflict — excluding it
|
|
1124
|
-
// would let the picker render and the user pick a remote session
|
|
1125
|
-
// that the eventual transferSession would have to refuse anyway.
|
|
1126
|
-
const conflict = [...activeSessions.values()].find(c => c.larkAppId === myAppId
|
|
1127
|
-
&& c.chatId === targetChatId
|
|
1128
|
-
// chat-scope only: thread-scope sessions (e.g. a `/t` force-topic
|
|
1129
|
-
// session in a regular group) live at a different sessionKey
|
|
1130
|
-
// anchor (rootMessageId), so they don't collide on transfer.
|
|
1131
|
-
// transferSession's own pre-flight (worker-pool.ts) and card-
|
|
1132
|
-
// handler's confirm both filter the same way; align here so the
|
|
1133
|
-
// picker doesn't false-positive a thread-scope live session.
|
|
1134
|
-
&& c.scope === 'chat'
|
|
1135
|
-
&& !!c.worker // real running session, not a placeholder
|
|
1136
|
-
);
|
|
1137
|
-
if (conflict) {
|
|
1138
|
-
await sessionReply(rootId, t('cmd.relay.target_has_session', { title: conflict.session.title || conflict.session.sessionId.substring(0, 8) }, loc));
|
|
1139
|
-
break;
|
|
1140
|
-
}
|
|
1141
|
-
// Shared candidate-collection logic — used here at initial render
|
|
1142
|
-
// and again in card-handler when the user clicks a card to switch
|
|
1143
|
-
// selection (the card re-render needs the same filtered list).
|
|
1144
|
-
// Filters out: other bots / current chat / non-owned / adopt
|
|
1145
|
-
// sessions. Resolves friendly chat names + modes in parallel.
|
|
1146
|
-
const { collectRelayPickerEntries } = await import('../services/relay-picker.js');
|
|
1147
|
-
const entries = await collectRelayPickerEntries(activeSessions, myAppId, targetChatId, operatorOpenId);
|
|
1148
|
-
const { buildRelayPickerCard } = await import('../im/lark/card-builder.js');
|
|
1149
|
-
const card = buildRelayPickerCard(entries, targetChatId, rootId, operatorOpenId, loc);
|
|
1150
|
-
await sessionReply(rootId, card, 'interactive');
|
|
1151
|
-
break;
|
|
1152
|
-
}
|
|
1153
|
-
const afterFlag = argsLine.replace(/^--create\s*/i, '').trim();
|
|
1154
|
-
const creatorAppId = larkAppId ?? ds?.larkAppId;
|
|
1155
|
-
if (!creatorAppId) {
|
|
1156
|
-
await sessionReply(rootId, t('cmd.group.no_bot', undefined, loc));
|
|
1157
|
-
break;
|
|
1158
|
-
}
|
|
1159
|
-
const senderOpenId = message.senderId;
|
|
1160
|
-
// Cross-app stable identity — peer daemons can't compare against
|
|
1161
|
-
// leader's open_id directly because the same user has a different
|
|
1162
|
-
// open_id in each bot's namespace. union_id is shared per tenant.
|
|
1163
|
-
// We pass it through the migrate-to-chat HTTP body; peers compare
|
|
1164
|
-
// against their session's `ownerUnionId` (with fallback to
|
|
1165
|
-
// open_id for sessions persisted before this field existed).
|
|
1166
|
-
const senderUnionId = message.senderUnionId;
|
|
1167
|
-
if (!senderOpenId) {
|
|
1168
|
-
await sessionReply(rootId, t('cmd.relay.no_sender', undefined, loc));
|
|
1169
|
-
break;
|
|
1170
|
-
}
|
|
1171
|
-
// `--create` must be invoked inside an existing thread — the source
|
|
1172
|
-
// anchor for peer transfers comes from `ds`. (Picker mode in PR3 is
|
|
1173
|
-
// allowed without a session.)
|
|
1174
|
-
if (!ds) {
|
|
1175
|
-
await sessionReply(rootId, t('cmd.relay.no_session', undefined, loc));
|
|
1176
|
-
break;
|
|
1177
|
-
}
|
|
1178
|
-
// Front-loaded guards — transferSession refuses adoptedFrom /
|
|
1179
|
-
// pendingRepo too, but only after createGroupWithBots has already
|
|
1180
|
-
// built a new chat. Failing here keeps relay clean and avoids
|
|
1181
|
-
// orphan-chat garbage when the operation can't possibly succeed.
|
|
1182
|
-
if (ds.session.adoptedFrom) {
|
|
1183
|
-
await sessionReply(rootId, t('cmd.relay.adopt_not_relayable', undefined, loc));
|
|
1184
|
-
break;
|
|
1185
|
-
}
|
|
1186
|
-
if (ds.pendingRepo) {
|
|
1187
|
-
await sessionReply(rootId, t('cmd.relay.not_started_yet', undefined, loc));
|
|
1188
|
-
break;
|
|
1189
|
-
}
|
|
1190
|
-
// ── Mention parsing & leader election (mirror of /group) ───────────
|
|
1191
|
-
const mentions = message.mentions ?? [];
|
|
1192
|
-
const knownBotNames = globalKnownBotNames();
|
|
1193
|
-
if (knownBotNames.size === 0 && mentions.some(m => !!m.name)) {
|
|
1194
|
-
logger.warn(`[${logTag}] /relay --create: global bot registry empty; cannot elect a creator`);
|
|
1195
|
-
await sessionReply(rootId, t('cmd.relay.resolve_failed', undefined, loc));
|
|
1196
|
-
break;
|
|
1197
|
-
}
|
|
1198
|
-
const botMentions = mentions.filter(m => m.name && knownBotNames.has(m.name.toLowerCase()));
|
|
1199
|
-
if (botMentions.length === 0) {
|
|
1200
|
-
await sessionReply(rootId, t('cmd.relay.no_mentions', undefined, loc));
|
|
1201
|
-
break;
|
|
1202
|
-
}
|
|
1203
|
-
// Am I `mentions[0]`?
|
|
1204
|
-
const firstBot = botMentions[0];
|
|
1205
|
-
const myOpenId = getBotOpenId(creatorAppId);
|
|
1206
|
-
const myName = getBot(creatorAppId).botName?.toLowerCase();
|
|
1207
|
-
const myNameAmbiguous = !!myName
|
|
1208
|
-
&& botMentions.filter(m => m.name?.toLowerCase() === myName).length > 1;
|
|
1209
|
-
const iAmFirstBot = (!!myOpenId && firstBot.openId === myOpenId) ||
|
|
1210
|
-
(!myOpenId && !!myName && !myNameAmbiguous && firstBot.name?.toLowerCase() === myName);
|
|
1211
|
-
if (!iAmFirstBot) {
|
|
1212
|
-
logger.info(`[${logTag}] /relay --create: not the first @-mentioned bot, staying silent`);
|
|
1213
|
-
break;
|
|
1214
|
-
}
|
|
1215
|
-
// Owner-only — only the source session owner may relay this session.
|
|
1216
|
-
if (ds.session.ownerOpenId && ds.session.ownerOpenId !== senderOpenId) {
|
|
1217
|
-
await sessionReply(rootId, t('cmd.relay.not_owner', undefined, loc));
|
|
1218
|
-
break;
|
|
1219
|
-
}
|
|
1220
|
-
// ── Resolve @-bots to larkAppIds via the source chat's bot roster ──
|
|
1221
|
-
const sourceChatId = ds.chatId;
|
|
1222
|
-
let members = [];
|
|
1223
|
-
try {
|
|
1224
|
-
members = await listChatBotMembers(creatorAppId, sourceChatId);
|
|
1225
|
-
}
|
|
1226
|
-
catch (e) {
|
|
1227
|
-
logger.warn(`[${logTag}] /relay --create: failed to list source chat members: ${e?.message ?? e}`);
|
|
1228
|
-
}
|
|
1229
|
-
const memberByOpenId = new Map(members.map(m => [m.openId, m]));
|
|
1230
|
-
const appIdToName = new Map();
|
|
1231
|
-
for (const m of members) {
|
|
1232
|
-
if (m.larkAppId && m.displayName)
|
|
1233
|
-
appIdToName.set(m.larkAppId, m.displayName);
|
|
1234
|
-
}
|
|
1235
|
-
const mentionedBotAppIds = [];
|
|
1236
|
-
const seenApp = new Set();
|
|
1237
|
-
let unresolved;
|
|
1238
|
-
for (const bm of botMentions) {
|
|
1239
|
-
const mem = bm.openId ? memberByOpenId.get(bm.openId) : undefined;
|
|
1240
|
-
if (!mem || !mem.larkAppId) {
|
|
1241
|
-
unresolved = bm.name;
|
|
1242
|
-
break;
|
|
1243
|
-
}
|
|
1244
|
-
if (!seenApp.has(mem.larkAppId)) {
|
|
1245
|
-
seenApp.add(mem.larkAppId);
|
|
1246
|
-
mentionedBotAppIds.push(mem.larkAppId);
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
if (unresolved) {
|
|
1250
|
-
logger.warn(`[${logTag}] /relay --create: unresolved bot "${unresolved}"`);
|
|
1251
|
-
await sessionReply(rootId, t('cmd.relay.resolve_failed', undefined, loc));
|
|
1252
|
-
break;
|
|
1253
|
-
}
|
|
1254
|
-
// ── Group name extraction (mirror of /group) ───────────────────────
|
|
1255
|
-
let rawArgs = afterFlag;
|
|
1256
|
-
for (const m of mentions) {
|
|
1257
|
-
if (m.name)
|
|
1258
|
-
rawArgs = rawArgs.split(`@${m.name}`).join(' ');
|
|
1259
|
-
}
|
|
1260
|
-
const firstLine = rawArgs.split(/\r?\n/).map(s => s.trim()).find(Boolean) ?? '';
|
|
1261
|
-
const MAX_NAME = 50;
|
|
1262
|
-
let groupName;
|
|
1263
|
-
if (firstLine) {
|
|
1264
|
-
groupName = firstLine.length > MAX_NAME ? firstLine.slice(0, MAX_NAME) + '…' : firstLine;
|
|
1265
|
-
}
|
|
1266
|
-
else {
|
|
1267
|
-
const now = new Date();
|
|
1268
|
-
const ts = `${String(now.getMonth() + 1).padStart(2, '0')}/${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
|
|
1269
|
-
groupName = t('cmd.relay.empty_group_name', { ts }, loc);
|
|
1270
|
-
}
|
|
1271
|
-
// ── Create the new chat ────────────────────────────────────────────
|
|
1272
|
-
const nameOf = (id) => appIdToName.get(id) ?? botDisplayName(id);
|
|
1273
|
-
let newChatId;
|
|
1274
|
-
let inviteLink;
|
|
1275
|
-
try {
|
|
1276
|
-
const { createGroupWithBots } = await import('../services/group-creator.js');
|
|
1277
|
-
const result = await createGroupWithBots({
|
|
1278
|
-
creatorLarkAppId: creatorAppId,
|
|
1279
|
-
larkAppIds: mentionedBotAppIds,
|
|
1280
|
-
name: groupName,
|
|
1281
|
-
userOpenIds: [senderOpenId],
|
|
1282
|
-
transferOwnerTo: senderOpenId,
|
|
1283
|
-
});
|
|
1284
|
-
newChatId = result.chatId;
|
|
1285
|
-
const applink = `https://applink.feishu.cn/client/chat/open?openChatId=${encodeURIComponent(result.chatId)}`;
|
|
1286
|
-
inviteLink = result.shareLink ?? applink;
|
|
1287
|
-
}
|
|
1288
|
-
catch (err) {
|
|
1289
|
-
logger.error(`[${logTag}] /relay --create: createGroup failed: ${err?.message ?? err}`);
|
|
1290
|
-
await sessionReply(rootId, t('cmd.relay.failed', { error: err?.message ?? String(err) }, loc));
|
|
1291
|
-
break;
|
|
1292
|
-
}
|
|
1293
|
-
// Snapshot the pre-transfer source anchor — peers locate their own
|
|
1294
|
-
// session by this value, and `transferSession()` will overwrite
|
|
1295
|
-
// `ds.session.rootMessageId` once it runs. Must capture BEFORE the
|
|
1296
|
-
// leader transfer call (caught in review).
|
|
1297
|
-
const sourceAnchor = ds.session.rootMessageId;
|
|
1298
|
-
// ── M1 deferred: post the announcement AFTER all transfers settle ──
|
|
1299
|
-
// Previous flow sent an optimistic "已接力" M1 before running any
|
|
1300
|
-
// transfer. When leader/peers later failed, that M1 was a lie — and
|
|
1301
|
-
// the --create path had no orphan-cleanup (picker path did).
|
|
1302
|
-
//
|
|
1303
|
-
// New flow: pass `newChatId` as a placeholder for targetRootMessageId
|
|
1304
|
-
// into transferSession. Chat-scope routing ignores rootMessageId
|
|
1305
|
-
// (worker-pool transferSession only stores it for audit/UX), so the
|
|
1306
|
-
// placeholder doesn't break routing. Once all outcomes are in, we
|
|
1307
|
-
// post the real M1 with success/failure breakdown, then patch the
|
|
1308
|
-
// leader's session.rootMessageId to that final M1 id. Peer sessions
|
|
1309
|
-
// keep newChatId as a cosmetic placeholder — fixing them would
|
|
1310
|
-
// require another round-trip; chat-scope doesn't actually care.
|
|
1311
|
-
const placeholderRootMessageId = newChatId;
|
|
1312
|
-
// Resolve friendly source-chat label for the M1 body — falls back to
|
|
1313
|
-
// raw chatId if Lark can't return a name. Mirrors picker-path
|
|
1314
|
-
// (card-handler.ts:341) so the message reads the same in both UX
|
|
1315
|
-
// entry points.
|
|
1316
|
-
const { getChatName } = await import('../im/lark/client.js');
|
|
1317
|
-
const sourceLabel = (await getChatName(creatorAppId, sourceChatId).catch(() => null)) ?? sourceChatId;
|
|
1318
|
-
// ── Step 1: leader transfers its own session (if any) ───────────────
|
|
1319
|
-
// Empty-leader handling: daemon auto-creates a placeholder ds for any
|
|
1320
|
-
// DAEMON_COMMAND (worker:null + hasHistory:false). If the user typed
|
|
1321
|
-
// `/relay --create` in a chat where they never actually chatted with
|
|
1322
|
-
// the bot, ds IS that placeholder — there's no real session to
|
|
1323
|
-
// migrate. Pre-Codex-review we'd happily transferSession the empty
|
|
1324
|
-
// shell and report "已就绪:leader" as a lie. Now we detect this,
|
|
1325
|
-
// skip transferSession, mark leader as `no_session`, and close the
|
|
1326
|
-
// scratch so it doesn't linger as a ghost.
|
|
1327
|
-
//
|
|
1328
|
-
// The new chat is still created (createGroupWithBots already ran
|
|
1329
|
-
// above) — that itself is a valuable product outcome since the
|
|
1330
|
-
// mentioned bots were invited. Peers continue through their normal
|
|
1331
|
-
// path; the final M1 template adapts to "all_fresh" when no bot
|
|
1332
|
-
// actually had a session to bring along.
|
|
1333
|
-
const reportLines = [];
|
|
1334
|
-
const leaderName = nameOf(creatorAppId);
|
|
1335
|
-
const successBotNames = [];
|
|
1336
|
-
const failedBotNames = [];
|
|
1337
|
-
// Use the persisted-marker predicate, not runtime ds.hasHistory:
|
|
1338
|
-
// restoreActiveSessions sets hasHistory:true UNCONDITIONALLY on
|
|
1339
|
-
// restart (session-manager.ts:618), so a scratch that survives a
|
|
1340
|
-
// restart comes back with hasHistory:true and would defeat a
|
|
1341
|
-
// naive `!!ds.worker || ds.hasHistory` check. cliId / lastCliInput
|
|
1342
|
-
// are only written after a real worker started the CLI, so they
|
|
1343
|
-
// survive restart correctly.
|
|
1344
|
-
const { isRelayableRealSession } = await import('./worker-pool.js');
|
|
1345
|
-
const leaderHasRealSession = isRelayableRealSession(ds);
|
|
1346
|
-
if (leaderHasRealSession) {
|
|
1347
|
-
const { transferSession } = await import('./worker-pool.js');
|
|
1348
|
-
// Target chat was just built by createGroupWithBots — by
|
|
1349
|
-
// construction a regular group.
|
|
1350
|
-
const leaderResult = await transferSession(ds.session.sessionId, newChatId, placeholderRootMessageId, 'group');
|
|
1351
|
-
if (!leaderResult.ok) {
|
|
1352
|
-
// Real session, real failure (worker busy / unsupported target
|
|
1353
|
-
// / tmux issue). Abort the entire --create flow — the new chat
|
|
1354
|
-
// exists but is empty of any migrated session; we don't post
|
|
1355
|
-
// an M1 because there's nothing to announce.
|
|
1356
|
-
reportLines.push(t('cmd.relay.report_leader_failed', { bot: leaderName, error: leaderResult.error }, loc));
|
|
1357
|
-
await sessionReply(rootId, t('cmd.relay.created', { name: groupName, link: inviteLink, report: reportLines.join('\n') }, loc));
|
|
1358
|
-
break;
|
|
1359
|
-
}
|
|
1360
|
-
reportLines.push(t('cmd.relay.report_leader_ok', { bot: leaderName }, loc));
|
|
1361
|
-
successBotNames.push(leaderName);
|
|
1362
|
-
}
|
|
1363
|
-
else {
|
|
1364
|
-
// Empty leader: no real session to migrate.
|
|
1365
|
-
reportLines.push(t('cmd.relay.report_leader_no_session', { bot: leaderName }, loc));
|
|
1366
|
-
failedBotNames.push(leaderName);
|
|
1367
|
-
// Close the daemon-command scratch so it doesn't linger as a
|
|
1368
|
-
// ghost active row at the source anchor (same hygiene that
|
|
1369
|
-
// transferSession's pre-flight applies to target-chat scratches).
|
|
1370
|
-
const { closeSession } = await import('./worker-pool.js');
|
|
1371
|
-
await closeSession(ds.session.sessionId).catch(err => {
|
|
1372
|
-
logger.warn(`[${logTag}] /relay --create: failed to close empty-leader scratch: ${err instanceof Error ? err.message : err}`);
|
|
1373
|
-
});
|
|
1374
|
-
}
|
|
1375
|
-
// ── Step 2: coordinate peer daemons (parallel) ─────────────────────
|
|
1376
|
-
const { findOnlineDaemon } = await import('../utils/daemon-discovery.js');
|
|
1377
|
-
const peerAppIds = mentionedBotAppIds.filter(id => id !== creatorAppId);
|
|
1378
|
-
const peerOutcomes = await Promise.all(peerAppIds.map(async (peerAppId) => {
|
|
1379
|
-
const botName = nameOf(peerAppId);
|
|
1380
|
-
const daemon = findOnlineDaemon(peerAppId);
|
|
1381
|
-
if (!daemon)
|
|
1382
|
-
return { peerAppId, botName, status: 'offline' };
|
|
1383
|
-
try {
|
|
1384
|
-
const ctrl = new AbortController();
|
|
1385
|
-
const tt = setTimeout(() => ctrl.abort(), 5000);
|
|
1386
|
-
const res = await fetch(`http://127.0.0.1:${daemon.ipcPort}/api/sessions/migrate-to-chat`, {
|
|
1387
|
-
method: 'POST',
|
|
1388
|
-
headers: { 'content-type': 'application/json' },
|
|
1389
|
-
body: JSON.stringify({
|
|
1390
|
-
sourceAnchor,
|
|
1391
|
-
targetChatId: newChatId,
|
|
1392
|
-
targetRootMessageId: placeholderRootMessageId,
|
|
1393
|
-
requesterLarkAppId: creatorAppId,
|
|
1394
|
-
requestingUserOpenId: senderOpenId,
|
|
1395
|
-
// union_id is cross-app stable within a tenant — peer
|
|
1396
|
-
// compares against its own session.ownerUnionId rather
|
|
1397
|
-
// than translating open_ids per bot. Optional for
|
|
1398
|
-
// backward compat with daemons older than this commit.
|
|
1399
|
-
requestingUserUnionId: senderUnionId,
|
|
1400
|
-
}),
|
|
1401
|
-
signal: ctrl.signal,
|
|
1402
|
-
}).finally(() => clearTimeout(tt));
|
|
1403
|
-
const body = await res.json().catch(() => ({}));
|
|
1404
|
-
if (res.ok && body.ok)
|
|
1405
|
-
return { peerAppId, botName, status: 'ok' };
|
|
1406
|
-
if (body.error === 'no_session_at_anchor')
|
|
1407
|
-
return { peerAppId, botName, status: 'no_session' };
|
|
1408
|
-
if (body.error === 'not_session_owner')
|
|
1409
|
-
return { peerAppId, botName, status: 'not_owner' };
|
|
1410
|
-
if (body.error === 'worker_busy')
|
|
1411
|
-
return { peerAppId, botName, status: 'busy' };
|
|
1412
|
-
return { peerAppId, botName, status: 'failed', error: body.error ?? `http_${res.status}` };
|
|
1413
|
-
}
|
|
1414
|
-
catch (err) {
|
|
1415
|
-
const reason = err?.name === 'AbortError' ? 'busy' : 'failed';
|
|
1416
|
-
return { peerAppId, botName, status: reason, error: err?.message ?? String(err) };
|
|
1417
|
-
}
|
|
1418
|
-
}));
|
|
1419
|
-
// Bucket peer outcomes for the final M1 (success / failure) AND extend the
|
|
1420
|
-
// source-chat report with per-peer detail. Leader was already bucketed
|
|
1421
|
-
// above (real-success → successBotNames; real-fail or empty-leader →
|
|
1422
|
-
// failedBotNames), so we only iterate peers here.
|
|
1423
|
-
for (const r of peerOutcomes) {
|
|
1424
|
-
if (r.status === 'ok') {
|
|
1425
|
-
successBotNames.push(r.botName);
|
|
1426
|
-
reportLines.push(t('cmd.relay.report_peer_ok', { bot: r.botName }, loc));
|
|
1427
|
-
}
|
|
1428
|
-
else {
|
|
1429
|
-
failedBotNames.push(r.botName);
|
|
1430
|
-
switch (r.status) {
|
|
1431
|
-
case 'no_session':
|
|
1432
|
-
reportLines.push(t('cmd.relay.report_peer_no_session', { bot: r.botName }, loc));
|
|
1433
|
-
break;
|
|
1434
|
-
case 'not_owner':
|
|
1435
|
-
reportLines.push(t('cmd.relay.report_peer_not_owner', { bot: r.botName }, loc));
|
|
1436
|
-
break;
|
|
1437
|
-
case 'offline':
|
|
1438
|
-
reportLines.push(t('cmd.relay.report_peer_offline', { bot: r.botName }, loc));
|
|
1439
|
-
break;
|
|
1440
|
-
case 'busy':
|
|
1441
|
-
reportLines.push(t('cmd.relay.report_peer_busy', { bot: r.botName }, loc));
|
|
1442
|
-
break;
|
|
1443
|
-
case 'failed':
|
|
1444
|
-
reportLines.push(t('cmd.relay.report_peer_failed', { bot: r.botName, error: r.error ?? 'unknown' }, loc));
|
|
1445
|
-
break;
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
// ── Step 3: post the real M1 with status breakdown ─────────────────
|
|
1450
|
-
// Three templates:
|
|
1451
|
-
// - all_ok : every bot migrated cleanly
|
|
1452
|
-
// - partial : some migrated, some didn't (failed list explains)
|
|
1453
|
-
// - all_fresh : nobody had a session to migrate (group's still
|
|
1454
|
-
// useful — bots were invited; user just @s to start)
|
|
1455
|
-
// Pass the raw text — sendMessage wraps `'text'` msgType bodies into
|
|
1456
|
-
// { text: content } itself.
|
|
1457
|
-
let finalM1Text;
|
|
1458
|
-
if (successBotNames.length === 0) {
|
|
1459
|
-
finalM1Text = t('cmd.relay.m1_final_all_fresh', { sourceChat: sourceLabel }, loc);
|
|
1460
|
-
}
|
|
1461
|
-
else if (failedBotNames.length === 0) {
|
|
1462
|
-
finalM1Text = t('cmd.relay.m1_final_all_ok', {
|
|
1463
|
-
sourceChat: sourceLabel,
|
|
1464
|
-
successBots: successBotNames.join('、'),
|
|
1465
|
-
}, loc);
|
|
1466
|
-
}
|
|
1467
|
-
else {
|
|
1468
|
-
finalM1Text = t('cmd.relay.m1_final_partial', {
|
|
1469
|
-
sourceChat: sourceLabel,
|
|
1470
|
-
successBots: successBotNames.join('、'),
|
|
1471
|
-
failedBots: failedBotNames.join('、'),
|
|
1472
|
-
}, loc);
|
|
1473
|
-
}
|
|
1474
|
-
try {
|
|
1475
|
-
const finalM1Id = await sendMessage(creatorAppId, newChatId, finalM1Text, 'text');
|
|
1476
|
-
// Patch the leader's session.rootMessageId to the real M1 id, but
|
|
1477
|
-
// only if the leader was actually transferred — for the empty-
|
|
1478
|
-
// leader / all_fresh path, ds was either closed or never moved,
|
|
1479
|
-
// so we don't touch it (would write to a closed/stale record).
|
|
1480
|
-
if (leaderHasRealSession && successBotNames.includes(leaderName)) {
|
|
1481
|
-
ds.session.rootMessageId = finalM1Id;
|
|
1482
|
-
sessionStore.updateSession(ds.session);
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
catch (err) {
|
|
1486
|
-
// Non-fatal: transfers already succeeded. The source-chat report
|
|
1487
|
-
// (sessionReply below) is the user's authoritative status.
|
|
1488
|
-
logger.warn(`[${logTag}] /relay --create: final M1 send failed: ${err?.message ?? err}`);
|
|
1489
|
-
}
|
|
1490
|
-
await sessionReply(rootId, t('cmd.relay.created', { name: groupName, link: inviteLink, report: reportLines.join('\n') }, loc));
|
|
1491
|
-
logger.info(`[${logTag}] /relay --create completed: chat=${newChatId} leader=${creatorAppId} peers=[${peerAppIds.join(',')}]`);
|
|
1492
|
-
break;
|
|
1493
|
-
}
|
|
1494
|
-
case '/card': {
|
|
1495
|
-
if (!ds) {
|
|
1496
|
-
await sessionReply(rootId, t('cmd.no_active_session', undefined, loc));
|
|
1497
|
-
break;
|
|
1498
|
-
}
|
|
1499
|
-
// Private mode (`privateCard`): send a one-shot snapshot only to the
|
|
1500
|
-
// explicit talk-grant audience via the ephemeral API, instead of the
|
|
1501
|
-
// group-visible live card. Ephemeral cards only work in plain `group`
|
|
1502
|
-
// chats and can't be patched — so no live updates, and we fail closed
|
|
1503
|
-
// (never fall back to a group-visible card) since not leaking is the
|
|
1504
|
-
// entire point of this mode.
|
|
1505
|
-
if (getBot(ds.larkAppId).config.privateCard) {
|
|
1506
|
-
// Strict gate: only a *confirmed* plain group is safe — getChatModeStrict
|
|
1507
|
-
// returns 'unknown' on API error instead of guessing 'group', so we fail
|
|
1508
|
-
// closed (no leak) when we can't verify the chat type.
|
|
1509
|
-
const mode = await getChatModeStrict(ds.larkAppId, ds.chatId);
|
|
1510
|
-
if (mode !== 'group') {
|
|
1511
|
-
await sessionReply(rootId, t('cmd.card.private_not_group', undefined, loc));
|
|
1512
|
-
break;
|
|
1513
|
-
}
|
|
1514
|
-
const audience = resolvePrivateCardAudience(ds);
|
|
1515
|
-
if (audience.length === 0) {
|
|
1516
|
-
await sessionReply(rootId, t('cmd.card.private_no_audience', undefined, loc));
|
|
1517
|
-
break;
|
|
1518
|
-
}
|
|
1519
|
-
const r = await postPrivateSnapshotCard(ds, audience);
|
|
1520
|
-
if (r.notReady) {
|
|
1521
|
-
await sessionReply(rootId, t('cmd.card.private_not_ready', undefined, loc));
|
|
1522
|
-
}
|
|
1523
|
-
else if (r.sent === 0) {
|
|
1524
|
-
// Total failure — surface a non-sensitive error (no terminal content,
|
|
1525
|
-
// no open_id list). Most likely cause: missing send permission / bot
|
|
1526
|
-
// not in chat / topic-thread chat.
|
|
1527
|
-
await sessionReply(rootId, t('cmd.card.private_failed', undefined, loc));
|
|
1528
|
-
}
|
|
1529
|
-
else if (r.sent < r.total) {
|
|
1530
|
-
// Partial — report counts only, never the audience identities.
|
|
1531
|
-
await sessionReply(rootId, t('cmd.card.private_partial', { sent: r.sent, total: r.total }, loc));
|
|
1532
|
-
}
|
|
1533
|
-
break;
|
|
1534
|
-
}
|
|
1535
|
-
// Manual summon. Force the live card on for the rest of this session —
|
|
1536
|
-
// even when the bot has `disableStreamingCard` set — then post a fresh
|
|
1537
|
-
// card. If the worker terminal isn't up yet, the force flag still sticks
|
|
1538
|
-
// so the card appears (and live-updates) as soon as the worker is ready.
|
|
1539
|
-
ds.streamingCardForced = true;
|
|
1540
|
-
const posted = await postFreshStreamingCard(ds, deps.sessionReply);
|
|
1541
|
-
if (!posted) {
|
|
1542
|
-
await sessionReply(rootId, t('cmd.card.not_ready', undefined, loc));
|
|
1543
|
-
}
|
|
1544
|
-
break;
|
|
1545
|
-
}
|
|
1546
1095
|
case '/help': {
|
|
1547
1096
|
const botCfg = ds ? getBot(ds.larkAppId).config : getAllBots()[0]?.config;
|
|
1548
1097
|
const cliName = getCliDisplayName(botCfg?.cliId ?? 'claude-code');
|
|
@@ -1553,9 +1102,7 @@ export async function handleCommand(cmd, rootId, message, deps, larkAppId) {
|
|
|
1553
1102
|
t('help.cd', { cliName }, loc),
|
|
1554
1103
|
t('help.repo_list', undefined, loc),
|
|
1555
1104
|
t('help.repo_n', undefined, loc),
|
|
1556
|
-
t('help.repo_path', undefined, loc),
|
|
1557
1105
|
t('help.status', undefined, loc),
|
|
1558
|
-
t('help.card', undefined, loc),
|
|
1559
1106
|
'',
|
|
1560
1107
|
t('help.heading_passthrough', { cliName }, loc),
|
|
1561
1108
|
// 直接从集合渲染,保证文案与 PASSTHROUGH_COMMANDS 不漂移
|
|
@@ -1568,6 +1115,10 @@ export async function handleCommand(cmd, rootId, message, deps, larkAppId) {
|
|
|
1568
1115
|
t('help.schedule_toggle', undefined, loc),
|
|
1569
1116
|
t('help.schedule_run', undefined, loc),
|
|
1570
1117
|
'',
|
|
1118
|
+
'任务管理:',
|
|
1119
|
+
'/task new <name> — 登记当前任务',
|
|
1120
|
+
'/task list | /task status <id> | /task assign <id> @Bot | /task close <id>',
|
|
1121
|
+
'',
|
|
1571
1122
|
t('help.schedule_formats', undefined, loc),
|
|
1572
1123
|
'',
|
|
1573
1124
|
t('help.heading_adopt', undefined, loc),
|