@oyasmi/pipiclaw 0.9.4 → 0.9.5-beta.3
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 +35 -31
- package/README.md +34 -30
- package/dist/agent/builtin-commands.d.ts +7 -2
- package/dist/agent/builtin-commands.js +19 -23
- package/dist/agent/channel-runner.d.ts +23 -35
- package/dist/agent/channel-runner.js +150 -89
- package/dist/agent/maintenance-context.d.ts +8 -5
- package/dist/agent/maintenance-context.js +30 -15
- package/dist/agent/prompt/manifest.js +1 -1
- package/dist/agent/prompt/resources.d.ts +1 -1
- package/dist/agent/prompt/resources.js +1 -1
- package/dist/agent/prompt/sections.js +11 -9
- package/dist/agent/prompt/types.d.ts +1 -1
- package/dist/agent/runner-factory.d.ts +6 -6
- package/dist/agent/runner-factory.js +7 -8
- package/dist/agent/session/command-extension.js +11 -0
- package/dist/agent/session/compaction-input.d.ts +6 -0
- package/dist/agent/session/compaction-input.js +75 -0
- package/dist/agent/session/compaction-snapshot.d.ts +30 -0
- package/dist/agent/session/compaction-snapshot.js +154 -0
- package/dist/agent/session/compaction-summary.d.ts +39 -0
- package/dist/agent/session/compaction-summary.js +162 -0
- package/dist/agent/session/compaction.d.ts +35 -0
- package/dist/agent/session/compaction.js +294 -0
- package/dist/agent/session/context-input.d.ts +15 -0
- package/dist/agent/session/context-input.js +82 -0
- package/dist/agent/session/context-snapshot.d.ts +11 -0
- package/dist/agent/session/context-snapshot.js +72 -0
- package/dist/agent/session/event-guards.d.ts +2 -0
- package/dist/agent/session/event-guards.js +4 -0
- package/dist/agent/session/execution-trace.d.ts +14 -0
- package/dist/agent/session/execution-trace.js +57 -0
- package/dist/agent/session/request-tools.d.ts +3 -0
- package/dist/agent/session/request-tools.js +20 -0
- package/dist/agent/session/session-adapter.d.ts +2 -1
- package/dist/agent/session/session-adapter.js +6 -3
- package/dist/agent/session/session-events.d.ts +4 -8
- package/dist/agent/session/session-events.js +80 -70
- package/dist/agent/session/session-host.d.ts +39 -61
- package/dist/agent/session/session-host.js +122 -124
- package/dist/agent/session/settings-diagnostics.d.ts +5 -0
- package/dist/agent/session/settings-diagnostics.js +21 -0
- package/dist/agent/status-render.js +5 -2
- package/dist/{runtime → agent}/stop-watchdog.d.ts +3 -1
- package/dist/{runtime → agent}/stop-watchdog.js +7 -3
- package/dist/agent/turn/progress-formatter.d.ts +1 -3
- package/dist/agent/turn/progress-formatter.js +3 -22
- package/dist/agent/turn/task-digest.d.ts +5 -4
- package/dist/agent/turn/task-digest.js +37 -34
- package/dist/agent/turn/turn-context.d.ts +12 -8
- package/dist/agent/turn/turn-context.js +27 -19
- package/dist/agent/turn/turn-finish.d.ts +18 -6
- package/dist/agent/turn/turn-finish.js +52 -77
- package/dist/agent/turn/turn-input.d.ts +2 -2
- package/dist/agent/turn/turn-input.js +4 -3
- package/dist/agent/turn/turn-output.d.ts +19 -0
- package/dist/agent/turn/turn-output.js +41 -0
- package/dist/agent/turn/turn-pipeline.d.ts +15 -10
- package/dist/agent/turn/turn-pipeline.js +86 -59
- package/dist/agent/turn/turn-prompt.d.ts +1 -1
- package/dist/agent/turn/turn-recovery.d.ts +11 -10
- package/dist/agent/turn/turn-recovery.js +14 -29
- package/dist/agent/types.d.ts +93 -24
- package/dist/agent/types.js +5 -1
- package/dist/app/auth-command.js +1 -1
- package/dist/app/home.js +34 -19
- package/dist/channel/active-session-store.d.ts +14 -12
- package/dist/channel/active-session-store.js +29 -25
- package/dist/channel/attachments.d.ts +25 -0
- package/dist/channel/attachments.js +56 -0
- package/dist/channel/channel-context.d.ts +87 -96
- package/dist/channel/channel-context.js +1 -66
- package/dist/channel/channel-event.d.ts +49 -47
- package/dist/channel/channel-event.js +6 -11
- package/dist/channel/channel-id.d.ts +22 -0
- package/dist/channel/channel-id.js +13 -0
- package/dist/channel/channel-index.d.ts +17 -34
- package/dist/channel/channel-index.js +41 -80
- package/dist/channel/config.d.ts +10 -0
- package/dist/channel/config.js +55 -0
- package/dist/channel/ingress.d.ts +93 -0
- package/dist/channel/ingress.js +5 -0
- package/dist/channel/store.d.ts +14 -16
- package/dist/channel/store.js +21 -25
- package/dist/channel/transport.d.ts +99 -0
- package/dist/channel/turn-context.d.ts +23 -0
- package/dist/channel/turn-context.js +1 -0
- package/dist/commands/catalog.d.ts +4 -7
- package/dist/commands/catalog.js +48 -49
- package/dist/commands/router.d.ts +28 -14
- package/dist/commands/router.js +30 -27
- package/dist/config/settings.d.ts +8 -14
- package/dist/config/settings.js +0 -7
- package/dist/config/tools.d.ts +2 -2
- package/dist/config/tools.js +2 -2
- package/dist/desk/bindings.d.ts +6 -0
- package/dist/desk/bindings.js +105 -0
- package/dist/desk/commands.d.ts +81 -0
- package/dist/desk/commands.js +145 -0
- package/dist/desk/default.d.ts +4 -0
- package/dist/desk/default.js +11 -0
- package/dist/desk/paths.d.ts +41 -0
- package/dist/desk/paths.js +81 -0
- package/dist/desk/registry.d.ts +17 -0
- package/dist/desk/registry.js +191 -0
- package/dist/desk/startup-error.d.ts +4 -0
- package/dist/desk/startup-error.js +7 -0
- package/dist/desk/types.d.ts +72 -0
- package/dist/desk/types.js +7 -0
- package/dist/dingtalk/bot.d.ts +20 -35
- package/dist/dingtalk/bot.js +25 -204
- package/dist/dingtalk/cards.d.ts +7 -0
- package/dist/dingtalk/cards.js +32 -2
- package/dist/dingtalk/channel-ids.d.ts +15 -0
- package/dist/dingtalk/channel-ids.js +39 -0
- package/dist/dingtalk/config.d.ts +6 -3
- package/dist/dingtalk/config.js +13 -25
- package/dist/dingtalk/connection.d.ts +1 -0
- package/dist/dingtalk/connection.js +5 -4
- package/dist/dingtalk/conversation-meta.d.ts +10 -5
- package/dist/dingtalk/conversation-meta.js +72 -50
- package/dist/dingtalk/delivery.d.ts +34 -14
- package/dist/dingtalk/delivery.js +332 -190
- package/dist/dingtalk/inbound-media.d.ts +2 -18
- package/dist/dingtalk/inbound-media.js +0 -53
- package/dist/dingtalk/inbound.d.ts +10 -11
- package/dist/dingtalk/inbound.js +12 -19
- package/dist/dingtalk/media.d.ts +9 -11
- package/dist/dingtalk/media.js +18 -31
- package/dist/dingtalk/progress.d.ts +57 -0
- package/dist/dingtalk/progress.js +199 -0
- package/dist/dingtalk/response-mode.d.ts +13 -0
- package/dist/dingtalk/response-mode.js +31 -0
- package/dist/dingtalk/transport.d.ts +47 -0
- package/dist/dingtalk/transport.js +71 -0
- package/dist/events/commands.d.ts +7 -2
- package/dist/events/commands.js +40 -22
- package/dist/events/pre-action-error.d.ts +10 -0
- package/dist/events/pre-action-error.js +10 -0
- package/dist/events/types.d.ts +20 -2
- package/dist/events/watcher.d.ts +14 -7
- package/dist/events/watcher.js +49 -26
- package/dist/file-store.d.ts +4 -0
- package/dist/file-store.js +6 -1
- package/dist/index.d.ts +4 -2
- package/dist/jobs/completion-observer.d.ts +20 -0
- package/dist/jobs/completion-observer.js +107 -0
- package/dist/jobs/completion-signal.d.ts +9 -0
- package/dist/jobs/completion-signal.js +32 -0
- package/dist/jobs/completion-wake.d.ts +14 -0
- package/dist/jobs/completion-wake.js +25 -0
- package/dist/jobs/manager.d.ts +29 -42
- package/dist/jobs/manager.js +130 -236
- package/dist/jobs/probe.d.ts +3 -0
- package/dist/jobs/probe.js +42 -0
- package/dist/jobs/record.d.ts +5 -6
- package/dist/jobs/record.js +2 -0
- package/dist/jobs/runtime.d.ts +28 -0
- package/dist/jobs/runtime.js +69 -0
- package/dist/log.d.ts +0 -1
- package/dist/log.js +1 -1
- package/dist/main.js +10 -3
- package/dist/memory/boundary-work.d.ts +19 -0
- package/dist/memory/boundary-work.js +204 -0
- package/dist/memory/commands.d.ts +4 -3
- package/dist/memory/commands.js +20 -17
- package/dist/memory/desk-memory-queue.d.ts +18 -0
- package/dist/memory/desk-memory-queue.js +33 -0
- package/dist/memory/index-budget.d.ts +3 -3
- package/dist/memory/index-budget.js +21 -18
- package/dist/memory/journal.d.ts +6 -6
- package/dist/memory/journal.js +16 -15
- package/dist/memory/lifecycle.d.ts +17 -28
- package/dist/memory/lifecycle.js +87 -147
- package/dist/memory/maintenance-state.d.ts +14 -15
- package/dist/memory/maintenance-state.js +43 -42
- package/dist/memory/reflect-job.d.ts +5 -10
- package/dist/memory/reflect-job.js +29 -44
- package/dist/memory/reflect.d.ts +6 -1
- package/dist/memory/reflect.js +44 -16
- package/dist/memory/render.d.ts +1 -1
- package/dist/memory/render.js +2 -2
- package/dist/memory/review-log.d.ts +17 -4
- package/dist/memory/review-log.js +54 -5
- package/dist/memory/scheduler.d.ts +12 -19
- package/dist/memory/scheduler.js +28 -64
- package/dist/memory/search.js +7 -4
- package/dist/memory/session-corpus.d.ts +4 -1
- package/dist/memory/session-corpus.js +70 -29
- package/dist/memory/session-search.d.ts +11 -3
- package/dist/memory/session-search.js +14 -11
- package/dist/memory/sidecar-worker.d.ts +1 -0
- package/dist/memory/sidecar-worker.js +57 -76
- package/dist/memory/source-window.d.ts +18 -7
- package/dist/memory/source-window.js +59 -29
- package/dist/memory/store.d.ts +14 -12
- package/dist/memory/store.js +89 -57
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +2 -0
- package/dist/playbooks/agent-delegation.md +23 -17
- package/dist/playbooks/background-jobs.md +7 -5
- package/dist/playbooks/event-scheduling.md +9 -7
- package/dist/playbooks/memory-and-learning.md +18 -14
- package/dist/playbooks/outbound-media.md +3 -3
- package/dist/playbooks/runtime-orientation.md +39 -23
- package/dist/playbooks/task-lead.md +57 -34
- package/dist/runtime/bootstrap.d.ts +45 -35
- package/dist/runtime/bootstrap.js +372 -167
- package/dist/runtime/channel-queue.d.ts +25 -0
- package/dist/{dingtalk → runtime}/channel-queue.js +25 -10
- package/dist/runtime/daemon-lock.d.ts +12 -0
- package/dist/runtime/daemon-lock.js +28 -0
- package/dist/runtime/desk-runtime.d.ts +131 -0
- package/dist/runtime/desk-runtime.js +402 -0
- package/dist/runtime/durable-dispatch.d.ts +18 -5
- package/dist/runtime/durable-dispatch.js +85 -14
- package/dist/runtime/inbound-images.d.ts +32 -10
- package/dist/runtime/inbound-images.js +95 -21
- package/dist/runtime/ingress-busy.d.ts +25 -0
- package/dist/runtime/ingress-busy.js +178 -0
- package/dist/runtime/ingress-commands.d.ts +7 -0
- package/dist/runtime/ingress-commands.js +170 -0
- package/dist/runtime/ingress-deps.d.ts +59 -0
- package/dist/runtime/ingress-deps.js +1 -0
- package/dist/runtime/ingress.d.ts +22 -0
- package/dist/runtime/ingress.js +386 -0
- package/dist/runtime/request-execution.d.ts +19 -0
- package/dist/runtime/request-execution.js +88 -0
- package/dist/runtime/shutdown.d.ts +14 -6
- package/dist/runtime/shutdown.js +11 -5
- package/dist/runtime/task-close.d.ts +4 -0
- package/dist/runtime/task-close.js +102 -0
- package/dist/runtime/task-control.d.ts +34 -0
- package/dist/runtime/task-control.js +225 -0
- package/dist/runtime/task-input.d.ts +13 -0
- package/dist/runtime/task-input.js +129 -0
- package/dist/runtime/task-lane-types.d.ts +123 -0
- package/dist/runtime/task-lane-types.js +14 -0
- package/dist/runtime/task-lane.d.ts +99 -0
- package/dist/runtime/task-lane.js +703 -0
- package/dist/runtime/task-pending.d.ts +8 -0
- package/dist/runtime/task-pending.js +40 -0
- package/dist/runtime/task-spawn.d.ts +8 -8
- package/dist/runtime/task-spawn.js +10 -9
- package/dist/runtime/task-step.d.ts +32 -0
- package/dist/runtime/task-step.js +276 -0
- package/dist/runtime/transports.d.ts +32 -0
- package/dist/runtime/transports.js +101 -0
- package/dist/runtime/turn-run.d.ts +20 -23
- package/dist/runtime/turn-run.js +252 -159
- package/dist/runtime/wake-coalescing.d.ts +12 -6
- package/dist/runtime/wake-coalescing.js +12 -4
- package/dist/security/config.js +5 -10
- package/dist/security/logger.js +1 -1
- package/dist/security/path-guard.js +7 -63
- package/dist/security/types.d.ts +27 -30
- package/dist/security/types.js +0 -1
- package/dist/shared/atomic-file.d.ts +2 -0
- package/dist/shared/atomic-file.js +14 -1
- package/dist/shared/file-lock.d.ts +35 -0
- package/dist/shared/file-lock.js +195 -0
- package/dist/shared/format.d.ts +0 -6
- package/dist/shared/format.js +0 -17
- package/dist/shared/host-process.d.ts +2 -0
- package/dist/shared/host-process.js +16 -1
- package/dist/shared/jsonl-appender.d.ts +5 -0
- package/dist/shared/jsonl-appender.js +25 -2
- package/dist/shared/with-timeout.d.ts +2 -0
- package/dist/shared/with-timeout.js +21 -0
- package/dist/skills/catalog.d.ts +9 -0
- package/dist/skills/catalog.js +34 -0
- package/dist/skills/commands.d.ts +3 -12
- package/dist/skills/commands.js +36 -22
- package/dist/skills/loader.d.ts +2 -31
- package/dist/skills/loader.js +101 -68
- package/dist/skills/roots.d.ts +12 -0
- package/dist/skills/roots.js +18 -0
- package/dist/skills/types.d.ts +24 -0
- package/dist/skills/types.js +1 -0
- package/dist/subagents/completion-wake.d.ts +11 -2
- package/dist/subagents/completion-wake.js +21 -18
- package/dist/subagents/discovery.d.ts +1 -1
- package/dist/subagents/discovery.js +10 -16
- package/dist/subagents/dispatch.d.ts +0 -10
- package/dist/subagents/dispatch.js +18 -44
- package/dist/subagents/external/cursor-cli.d.ts +2 -0
- package/dist/subagents/external/cursor-cli.js +256 -0
- package/dist/subagents/external/dispatch.js +1 -1
- package/dist/subagents/external/harness.d.ts +5 -5
- package/dist/subagents/external/reconciliation.d.ts +7 -0
- package/dist/subagents/external/reconciliation.js +105 -0
- package/dist/subagents/external/recovery.d.ts +20 -0
- package/dist/subagents/external/recovery.js +71 -0
- package/dist/subagents/external/registry.js +2 -0
- package/dist/subagents/external/role-warnings.d.ts +17 -0
- package/dist/subagents/external/role-warnings.js +42 -0
- package/dist/subagents/external/run.d.ts +1 -1
- package/dist/subagents/external/run.js +21 -25
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/grace.d.ts +2 -2
- package/dist/subagents/grace.js +3 -3
- package/dist/subagents/internal/run.js +8 -6
- package/dist/subagents/internal/worker.js +37 -16
- package/dist/subagents/result.js +2 -3
- package/dist/subagents/run-archive.d.ts +11 -0
- package/dist/subagents/run-archive.js +49 -0
- package/dist/subagents/run-record.d.ts +13 -15
- package/dist/subagents/run-record.js +5 -5
- package/dist/subagents/run-registry.d.ts +5 -3
- package/dist/subagents/run-registry.js +22 -45
- package/dist/subagents/runs.d.ts +51 -54
- package/dist/subagents/runs.js +178 -304
- package/dist/subagents/task-envelope.js +9 -11
- package/dist/subagents/task-settlement.d.ts +3 -0
- package/dist/subagents/task-settlement.js +20 -0
- package/dist/subagents/types.d.ts +7 -7
- package/dist/subagents/workspace-summary.js +5 -1
- package/dist/tasks/archive.d.ts +11 -0
- package/dist/tasks/archive.js +141 -0
- package/dist/tasks/board.d.ts +5 -12
- package/dist/tasks/board.js +4 -30
- package/dist/tasks/bound-work.d.ts +13 -7
- package/dist/tasks/bound-work.js +41 -28
- package/dist/tasks/brief.d.ts +39 -15
- package/dist/tasks/brief.js +131 -73
- package/dist/tasks/budget.d.ts +3 -3
- package/dist/tasks/budget.js +9 -4
- package/dist/tasks/commands.d.ts +24 -10
- package/dist/tasks/commands.js +225 -131
- package/dist/tasks/completion.d.ts +12 -0
- package/dist/tasks/completion.js +35 -0
- package/dist/tasks/contract.d.ts +8 -19
- package/dist/tasks/contract.js +41 -45
- package/dist/tasks/control.d.ts +138 -0
- package/dist/tasks/control.js +1 -0
- package/dist/tasks/create.d.ts +4 -2
- package/dist/tasks/create.js +13 -7
- package/dist/tasks/delivery.d.ts +24 -0
- package/dist/tasks/delivery.js +221 -0
- package/dist/tasks/file-mutation.d.ts +5 -0
- package/dist/tasks/file-mutation.js +38 -0
- package/dist/tasks/frontmatter.d.ts +46 -27
- package/dist/tasks/frontmatter.js +90 -47
- package/dist/tasks/input-receipts.d.ts +7 -0
- package/dist/tasks/input-receipts.js +60 -0
- package/dist/tasks/loop-log.d.ts +150 -37
- package/dist/tasks/loop-log.js +250 -42
- package/dist/tasks/mutation-lock.d.ts +7 -5
- package/dist/tasks/mutation-lock.js +32 -9
- package/dist/tasks/receipts.d.ts +19 -0
- package/dist/tasks/receipts.js +48 -0
- package/dist/tasks/session-path.d.ts +3 -3
- package/dist/tasks/session-path.js +5 -5
- package/dist/tasks/state.d.ts +93 -0
- package/dist/tasks/state.js +156 -0
- package/dist/tasks/store.d.ts +86 -54
- package/dist/tasks/store.js +256 -156
- package/dist/tools/bash.d.ts +8 -10
- package/dist/tools/bash.js +27 -40
- package/dist/tools/contract/details.d.ts +6 -6
- package/dist/tools/contract/details.js +6 -6
- package/dist/tools/contract/execution-trace.d.ts +4 -0
- package/dist/tools/contract/execution-trace.js +23 -0
- package/dist/tools/contract/names.d.ts +7 -0
- package/dist/tools/contract/names.js +22 -0
- package/dist/tools/contract/presentation.js +6 -2
- package/dist/tools/edit.d.ts +1 -0
- package/dist/tools/edit.js +46 -43
- package/dist/tools/event-manage.d.ts +3 -1
- package/dist/tools/event-manage.js +34 -33
- package/dist/tools/glob.js +5 -5
- package/dist/tools/grep.js +2 -2
- package/dist/tools/index.d.ts +17 -20
- package/dist/tools/index.js +28 -22
- package/dist/tools/job.d.ts +4 -2
- package/dist/tools/job.js +11 -8
- package/dist/tools/memory-manage.d.ts +5 -3
- package/dist/tools/memory-manage.js +32 -25
- package/dist/tools/read.js +1 -1
- package/dist/tools/registry.d.ts +19 -19
- package/dist/tools/registry.js +65 -34
- package/dist/tools/send-media.d.ts +2 -2
- package/dist/tools/send-media.js +3 -3
- package/dist/tools/session-search.d.ts +3 -1
- package/dist/tools/session-search.js +8 -6
- package/dist/tools/skill.d.ts +2 -2
- package/dist/tools/skill.js +24 -10
- package/dist/tools/subagent-manage.d.ts +2 -8
- package/dist/tools/subagent-manage.js +26 -19
- package/dist/tools/subagent.d.ts +0 -2
- package/dist/tools/subagent.js +3 -8
- package/dist/tools/task-manage/control-tools.d.ts +4 -0
- package/dist/tools/task-manage/control-tools.js +65 -0
- package/dist/tools/task-manage/create.js +3 -2
- package/dist/tools/task-manage/factory.d.ts +12 -6
- package/dist/tools/task-manage/factory.js +73 -58
- package/dist/tools/task-manage/lifecycle.d.ts +7 -12
- package/dist/tools/task-manage/lifecycle.js +119 -65
- package/dist/tools/task-manage/log-view.js +10 -7
- package/dist/tools/task-manage/schema.d.ts +21 -26
- package/dist/tools/task-manage/schema.js +29 -35
- package/dist/tools/task-manage/shared.d.ts +8 -39
- package/dist/tools/task-manage/shared.js +20 -69
- package/dist/tools/task-manage/step-tools.d.ts +5 -0
- package/dist/tools/task-manage/step-tools.js +103 -0
- package/dist/tools/task-manage/types.d.ts +33 -21
- package/dist/tools/web-cache.d.ts +3 -3
- package/dist/tools/web-cache.js +12 -12
- package/dist/tools/web-fetch.d.ts +2 -2
- package/dist/tools/web-fetch.js +7 -7
- package/dist/tools/write-content.d.ts +1 -0
- package/dist/tools/write-content.js +7 -2
- package/dist/tools/write.d.ts +1 -0
- package/dist/tools/write.js +1 -0
- package/dist/tui/cli.d.ts +17 -5
- package/dist/tui/cli.js +90 -27
- package/dist/tui/client.d.ts +26 -0
- package/dist/tui/client.js +157 -0
- package/dist/tui/colors.d.ts +0 -1
- package/dist/tui/colors.js +0 -1
- package/dist/tui/commands.d.ts +10 -51
- package/dist/tui/commands.js +16 -39
- package/dist/tui/frontend.d.ts +2 -2
- package/dist/tui/frontend.js +2 -2
- package/dist/tui/pitui-frontend.d.ts +0 -2
- package/dist/tui/pitui-frontend.js +1 -6
- package/dist/tui/render.d.ts +62 -0
- package/dist/tui/render.js +123 -0
- package/dist/tui/session.d.ts +92 -0
- package/dist/tui/session.js +317 -0
- package/dist/usage/ledger.d.ts +9 -4
- package/dist/usage/ledger.js +2 -0
- package/dist/usage/render.d.ts +6 -1
- package/dist/usage/render.js +20 -15
- package/dist/web/search-providers.js +0 -33
- package/dist/webapi/auth.d.ts +13 -0
- package/dist/webapi/auth.js +29 -0
- package/dist/webapi/config.d.ts +29 -0
- package/dist/webapi/config.js +100 -0
- package/dist/webapi/errors.d.ts +39 -0
- package/dist/webapi/errors.js +32 -0
- package/dist/webapi/http.d.ts +25 -0
- package/dist/webapi/http.js +4 -0
- package/dist/webapi/ids.d.ts +9 -0
- package/dist/webapi/ids.js +20 -0
- package/dist/webapi/input.d.ts +17 -0
- package/dist/webapi/input.js +229 -0
- package/dist/webapi/items.d.ts +37 -0
- package/dist/webapi/items.js +48 -0
- package/dist/webapi/key-command.d.ts +2 -0
- package/dist/webapi/key-command.js +110 -0
- package/dist/webapi/limits.d.ts +47 -0
- package/dist/webapi/limits.js +48 -0
- package/dist/webapi/request-policy.d.ts +17 -0
- package/dist/webapi/request-policy.js +160 -0
- package/dist/webapi/response-record.d.ts +68 -0
- package/dist/webapi/response-record.js +58 -0
- package/dist/webapi/response-state.d.ts +90 -0
- package/dist/webapi/response-state.js +347 -0
- package/dist/webapi/routes/conversations.d.ts +8 -0
- package/dist/webapi/routes/conversations.js +80 -0
- package/dist/webapi/routes/models.d.ts +3 -0
- package/dist/webapi/routes/models.js +12 -0
- package/dist/webapi/routes/responses.d.ts +8 -0
- package/dist/webapi/routes/responses.js +118 -0
- package/dist/webapi/routes/websocket.d.ts +9 -0
- package/dist/webapi/routes/websocket.js +328 -0
- package/dist/webapi/server.d.ts +24 -0
- package/dist/webapi/server.js +229 -0
- package/dist/webapi/service.d.ts +130 -0
- package/dist/webapi/service.js +588 -0
- package/dist/webapi/store.d.ts +46 -0
- package/dist/webapi/store.js +245 -0
- package/dist/webapi/stream.d.ts +13 -0
- package/dist/webapi/stream.js +76 -0
- package/dist/webapi/transport.d.ts +43 -0
- package/dist/webapi/transport.js +100 -0
- package/examples/sub-agents/README.md +23 -16
- package/examples/sub-agents/agents/claude-high.md +1 -1
- package/examples/sub-agents/agents/claude-main.md +1 -1
- package/examples/sub-agents/agents/codex-flash.md +1 -1
- package/examples/sub-agents/agents/codex-high.md +1 -1
- package/examples/sub-agents/agents/codex-main.md +4 -4
- package/examples/sub-agents/agents/cursor-high.md +22 -0
- package/examples/sub-agents/agents/cursor-main.md +22 -0
- package/examples/sub-agents/agents/glm-flash.md +1 -1
- package/examples/sub-agents/agents/glm-high.md +2 -2
- package/examples/sub-agents/agents/scout.md +30 -0
- package/package.json +13 -7
- package/dist/channel/channel-paths.d.ts +0 -16
- package/dist/channel/channel-paths.js +0 -53
- package/dist/channel/commands.d.ts +0 -32
- package/dist/channel/commands.js +0 -109
- package/dist/channel/project-scope-store.d.ts +0 -51
- package/dist/channel/project-scope-store.js +0 -112
- package/dist/dingtalk/channel-queue.d.ts +0 -19
- package/dist/dingtalk/handler.d.ts +0 -90
- package/dist/memory/channel-maintenance-queue.d.ts +0 -5
- package/dist/memory/channel-maintenance-queue.js +0 -8
- package/dist/runtime/task-driver.d.ts +0 -100
- package/dist/runtime/task-driver.js +0 -417
- package/dist/runtime/task-migration.d.ts +0 -30
- package/dist/runtime/task-migration.js +0 -465
- package/dist/runtime/task-wake.d.ts +0 -46
- package/dist/runtime/task-wake.js +0 -32
- package/dist/runtime/turn-handler.d.ts +0 -47
- package/dist/runtime/turn-handler.js +0 -318
- package/dist/security/project-scope.d.ts +0 -45
- package/dist/security/project-scope.js +0 -105
- package/dist/shared/wake-claim.d.ts +0 -23
- package/dist/shared/wake-claim.js +0 -26
- package/dist/skills/validation.d.ts +0 -8
- package/dist/skills/validation.js +0 -91
- package/dist/skills/workspace.d.ts +0 -33
- package/dist/skills/workspace.js +0 -116
- package/dist/tasks/steer.d.ts +0 -8
- package/dist/tasks/steer.js +0 -79
- package/dist/tasks/ticket.d.ts +0 -71
- package/dist/tasks/ticket.js +0 -138
- package/dist/tools/task-manage/step-end.d.ts +0 -11
- package/dist/tools/task-manage/step-end.js +0 -117
- package/dist/tui/app.d.ts +0 -16
- package/dist/tui/app.js +0 -166
- package/dist/tui/terminal-context.d.ts +0 -27
- package/dist/tui/terminal-context.js +0 -84
- package/dist/tui/terminal-media-sender.d.ts +0 -9
- package/dist/tui/terminal-media-sender.js +0 -15
- package/dist/tui/turn-controller.d.ts +0 -64
- package/dist/tui/turn-controller.js +0 -311
- /package/dist/{dingtalk/handler.js → channel/transport.js} +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ChannelEvent, type HumanEvent } from "../channel/channel-event.js";
|
|
2
|
+
import { type RuntimeCommandName } from "../commands/catalog.js";
|
|
3
|
+
import type { IngressDeps } from "./ingress-deps.js";
|
|
4
|
+
export declare function createCommandHandlers(deps: IngressDeps, resetChannelQueue: (channelId: string) => number): {
|
|
5
|
+
handleNewSession: (event: HumanEvent) => Promise<void>;
|
|
6
|
+
runRuntimeCommand: (event: ChannelEvent, name: RuntimeCommandName, args: string) => Promise<string>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The commands the runtime itself answers: `/new` (a fresh session for one channel) and the
|
|
3
|
+
* stateless report commands (`/status`, `/tasks`, …), shared by the busy and the idle path of
|
|
4
|
+
* `ingress.ts`.
|
|
5
|
+
*/
|
|
6
|
+
import { preserveMemoryBeforeNewSession } from "../agent/maintenance-context.js";
|
|
7
|
+
import { createFreshActiveSession } from "../channel/active-session-store.js";
|
|
8
|
+
import { senderOf } from "../channel/channel-event.js";
|
|
9
|
+
import { formatNewSessionReply } from "../commands/catalog.js";
|
|
10
|
+
import { runReportCommand } from "../commands/router.js";
|
|
11
|
+
import { formatNoDeskReply } from "../desk/commands.js";
|
|
12
|
+
import * as log from "../log.js";
|
|
13
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
14
|
+
import { relativeImagePaths } from "./inbound-images.js";
|
|
15
|
+
/**
|
|
16
|
+
* The lane is built after the ingress, so a command resolves it when it runs. A command that lands
|
|
17
|
+
* before the lane exists is refused with a retry hint rather than guessed at.
|
|
18
|
+
*/
|
|
19
|
+
function lazyTaskControl(get) {
|
|
20
|
+
const control = () => {
|
|
21
|
+
const current = get();
|
|
22
|
+
if (!current)
|
|
23
|
+
throw new Error("任务服务尚未就绪,请稍后重试。");
|
|
24
|
+
return current;
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
isRunning: (desk, id) => control().isRunning(desk, id),
|
|
28
|
+
created: (...args) => control().created(...args),
|
|
29
|
+
snapshot: (...args) => control().snapshot(...args),
|
|
30
|
+
message: (...args) => control().message(...args),
|
|
31
|
+
pause: (...args) => control().pause(...args),
|
|
32
|
+
resume: (...args) => control().resume(...args),
|
|
33
|
+
cancel: (...args) => control().cancel(...args),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function createCommandHandlers(deps, resetChannelQueue) {
|
|
37
|
+
const { options, channelRunners, sessionResetChains, activeTasks, archiveIncomingMessage, getRunner, resolveChannel, deskPort, describeChannel, cliVersion, startedAt, isShuttingDown, getRuns, } = deps;
|
|
38
|
+
const say = (event, text) => deps.pushTo(event.channelId, {
|
|
39
|
+
text,
|
|
40
|
+
...(event.source === "human" && event.ref !== undefined ? { ref: event.ref } : {}),
|
|
41
|
+
});
|
|
42
|
+
/** The desk port a command runs with: a sender limited to some desks may bind only to those. */
|
|
43
|
+
const deskPortFor = (event) => {
|
|
44
|
+
const port = deskPort(event.channelId);
|
|
45
|
+
const allowed = event.source === "human" ? event.allowedDesks : undefined;
|
|
46
|
+
const bind = port.bind;
|
|
47
|
+
if (!allowed || !bind)
|
|
48
|
+
return port;
|
|
49
|
+
return {
|
|
50
|
+
...port,
|
|
51
|
+
bind: async (name) => allowed.includes(name) ? bind(name) : { kind: "forbidden", desk: name },
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/** `/new` bypasses the old per-channel queue and live SDK session. */
|
|
55
|
+
async function handleNewSession(event) {
|
|
56
|
+
if (isShuttingDown())
|
|
57
|
+
return;
|
|
58
|
+
const previous = sessionResetChains.get(event.channelId) ?? Promise.resolve();
|
|
59
|
+
const reset = previous
|
|
60
|
+
.catch(() => undefined)
|
|
61
|
+
.then(async () => {
|
|
62
|
+
try {
|
|
63
|
+
const resolution = resolveChannel(event.channelId);
|
|
64
|
+
if (resolution.kind !== "bound") {
|
|
65
|
+
await say(event, formatNoDeskReply(resolution));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const { conversation } = resolution;
|
|
69
|
+
if (event.allowedDesks && !event.allowedDesks.includes(conversation.desk)) {
|
|
70
|
+
await say(event, `当前身份无权使用工位 \`${conversation.desk}\`。`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// The empty session file and active pointer are committed before the old
|
|
74
|
+
// generation is touched. A filesystem failure therefore leaves the live
|
|
75
|
+
// session authoritative and retryable. `/new` resets only this channel's
|
|
76
|
+
// conversation in the desk.
|
|
77
|
+
await preserveMemoryBeforeNewSession(conversation);
|
|
78
|
+
const result = await createFreshActiveSession(conversation.conversationDir, conversation.cwd);
|
|
79
|
+
const oldRunner = channelRunners.get(event.channelId);
|
|
80
|
+
if (oldRunner) {
|
|
81
|
+
channelRunners.delete(event.channelId);
|
|
82
|
+
try {
|
|
83
|
+
oldRunner.retireForNewSession();
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
// The active pointer already names the new session. Retirement is
|
|
87
|
+
// best-effort cleanup and must not misreport the committed reset as failed.
|
|
88
|
+
log.logWarn("agent.session.retire_failed", "Old runner retirement after /new failed", {
|
|
89
|
+
channelId: event.channelId,
|
|
90
|
+
reason: errorMessage(error),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const dropped = resetChannelQueue(event.channelId);
|
|
95
|
+
if (dropped > 0) {
|
|
96
|
+
log.logInfoEvent("agent.session.queue_dropped", "Old-session queued messages discarded by /new", {
|
|
97
|
+
channelId: event.channelId,
|
|
98
|
+
fields: { count: dropped },
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
await say(event, formatNewSessionReply(result.sessionId));
|
|
102
|
+
void archiveIncomingMessage(event.channelId, {
|
|
103
|
+
date: new Date().toISOString(),
|
|
104
|
+
ts: event.ts,
|
|
105
|
+
user: event.user,
|
|
106
|
+
userName: event.userName,
|
|
107
|
+
text: event.text,
|
|
108
|
+
isBot: false,
|
|
109
|
+
images: relativeImagePaths(conversation.deskDir, event.images),
|
|
110
|
+
}, "/new command");
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
const message = errorMessage(error);
|
|
114
|
+
log.logWarn("agent.session.create_failed", "Fresh session creation failed", {
|
|
115
|
+
channelId: event.channelId,
|
|
116
|
+
reason: message,
|
|
117
|
+
});
|
|
118
|
+
await say(event, `新会话创建失败:${message}\n旧会话保持不变,可以重试 \`/new\`。`);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
sessionResetChains.set(event.channelId, reset);
|
|
122
|
+
activeTasks.add(reset);
|
|
123
|
+
try {
|
|
124
|
+
await reset;
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
activeTasks.delete(reset);
|
|
128
|
+
if (sessionResetChains.get(event.channelId) === reset) {
|
|
129
|
+
sessionResetChains.delete(event.channelId);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Render one of the stateless report commands (events/tasks/status/usage/subagents/skills/desk)
|
|
135
|
+
* to text. The single dispatch point behind both the busy-turn path and the idle-turn path.
|
|
136
|
+
*/
|
|
137
|
+
async function runRuntimeCommand(event, name, args) {
|
|
138
|
+
const { channelId } = event;
|
|
139
|
+
const resolution = resolveChannel(channelId);
|
|
140
|
+
if (resolution.kind !== "bound") {
|
|
141
|
+
return runReportCommand({
|
|
142
|
+
kind: "no-desk",
|
|
143
|
+
deskPort: deskPortFor(event),
|
|
144
|
+
refusal: formatNoDeskReply(resolution),
|
|
145
|
+
}, name, args);
|
|
146
|
+
}
|
|
147
|
+
const { conversation } = resolution;
|
|
148
|
+
const { desk } = conversation;
|
|
149
|
+
return runReportCommand({
|
|
150
|
+
kind: "bound",
|
|
151
|
+
conversation,
|
|
152
|
+
deskPort: deskPortFor(event),
|
|
153
|
+
paths: options.paths,
|
|
154
|
+
describeChannel: (target) => describeChannel(desk, target),
|
|
155
|
+
version: cliVersion,
|
|
156
|
+
startedAt,
|
|
157
|
+
peekRunner: () => channelRunners.get(channelId),
|
|
158
|
+
getRunner: () => {
|
|
159
|
+
const runner = getRunner(channelId);
|
|
160
|
+
if (!runner)
|
|
161
|
+
throw new Error(`Channel ${channelId} lost its desk binding`);
|
|
162
|
+
return runner;
|
|
163
|
+
},
|
|
164
|
+
runManager: getRuns().get(desk),
|
|
165
|
+
taskControl: lazyTaskControl(deps.getTaskControl),
|
|
166
|
+
senderName: senderOf(event).userName,
|
|
167
|
+
}, name, args);
|
|
168
|
+
}
|
|
169
|
+
return { handleNewSession, runRuntimeCommand };
|
|
170
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything the ingress needs from `createRuntimeContext`'s scope, as a reviewable typed list
|
|
3
|
+
* instead of "however many closures happen to be in scope". The `get*`/`is*` accessors exist only
|
|
4
|
+
* for state the composition root assigns *after* the ingress is built (`durableDispatch`, the
|
|
5
|
+
* task driver) or mutates later (`shuttingDown`): a method only ever runs long after all of them
|
|
6
|
+
* are set, but a value captured at construction would freeze a stale snapshot.
|
|
7
|
+
*/
|
|
8
|
+
import type { AgentRunner } from "../agent/types.js";
|
|
9
|
+
import type { BootstrapPaths } from "../app/home.js";
|
|
10
|
+
import type { ChannelDescription } from "../channel/channel-id.js";
|
|
11
|
+
import type { ChannelIndex } from "../channel/channel-index.js";
|
|
12
|
+
import type { ChannelStore } from "../channel/store.js";
|
|
13
|
+
import type { PushMessage } from "../channel/transport.js";
|
|
14
|
+
import type { DeskCommandPort } from "../desk/commands.js";
|
|
15
|
+
import type { JobRuntime } from "../jobs/runtime.js";
|
|
16
|
+
import type { SubAgentRuntime } from "../subagents/run-registry.js";
|
|
17
|
+
import type { TaskControl } from "../tasks/control.js";
|
|
18
|
+
import type { ChannelResolution } from "./desk-runtime.js";
|
|
19
|
+
import type { DurableDispatchService } from "./durable-dispatch.js";
|
|
20
|
+
import type { TransportRegistry } from "./transports.js";
|
|
21
|
+
import type { ArchivedMessage } from "./turn-run.js";
|
|
22
|
+
export interface IngressOptions {
|
|
23
|
+
paths: BootstrapPaths;
|
|
24
|
+
/** Override the `/stop` watchdog's grace window (tests use a short one). */
|
|
25
|
+
stopForceEndGraceMs?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface IngressDeps {
|
|
28
|
+
requestExecution?: import("./request-execution.js").RequestExecution;
|
|
29
|
+
options: IngressOptions;
|
|
30
|
+
transports: TransportRegistry;
|
|
31
|
+
store: ChannelStore;
|
|
32
|
+
channelRunners: Map<string, AgentRunner>;
|
|
33
|
+
sessionResetChains: Map<string, Promise<void>>;
|
|
34
|
+
activeTasks: Set<Promise<void>>;
|
|
35
|
+
stopWatchdogs: Set<string>;
|
|
36
|
+
channelIndex: ChannelIndex;
|
|
37
|
+
archiveIncomingMessage: (channelId: string, message: ArchivedMessage, contextLabel: string) => Promise<void>;
|
|
38
|
+
/** The channel's runner; `undefined` when it is not bound to an available desk — none is ever built then. */
|
|
39
|
+
getRunner: (channelId: string) => AgentRunner | undefined;
|
|
40
|
+
resolveChannel: (channelId: string) => ChannelResolution;
|
|
41
|
+
/** Bind a channel that has no binding yet to `desk`; a no-op when it already has one. */
|
|
42
|
+
ensureBinding: (channelId: string, desk: string) => Promise<void>;
|
|
43
|
+
/** Drop a channel's binding and runner for good (`Ingress.closeChannel`). */
|
|
44
|
+
unbind: (channelId: string) => Promise<boolean>;
|
|
45
|
+
/** `/desk` as asked from `channelId` (spec 058, D5). */
|
|
46
|
+
deskPort: (channelId: string) => DeskCommandPort;
|
|
47
|
+
/** Names a channel and says whether it is bound to `desk` — the asking channel's desk. */
|
|
48
|
+
describeChannel: (desk: string, channelId: string) => ChannelDescription;
|
|
49
|
+
cliVersion: string;
|
|
50
|
+
startedAt: number;
|
|
51
|
+
isShuttingDown: () => boolean;
|
|
52
|
+
getDurableDispatch: () => DurableDispatchService | undefined;
|
|
53
|
+
getJobs: () => JobRuntime;
|
|
54
|
+
getRuns: () => SubAgentRuntime;
|
|
55
|
+
/** The task lane's control port; `undefined` until the runtime has built it. */
|
|
56
|
+
getTaskControl: () => TaskControl | undefined;
|
|
57
|
+
/** Say something to a channel outside any turn; whether it was delivered. */
|
|
58
|
+
pushTo: (channelId: string, message: PushMessage) => Promise<boolean>;
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ChannelEvent, ChannelEventSink, HumanEvent } from "../channel/channel-event.js";
|
|
2
|
+
import type { Ingress, IngressResult } from "../channel/ingress.js";
|
|
3
|
+
import { type RuntimeCommandName } from "../commands/catalog.js";
|
|
4
|
+
import type { IngressDeps } from "./ingress-deps.js";
|
|
5
|
+
/** Pending turns a channel may hold when its transport sends plain messages one turn each (`whenBusy: "queue"`). */
|
|
6
|
+
export declare const MAX_QUEUED_TURNS_PER_CHANNEL = 8;
|
|
7
|
+
export interface IngressService extends Ingress, ChannelEventSink {
|
|
8
|
+
/** Stop taking work: every channel queue drops what it has not started. */
|
|
9
|
+
stop(): void;
|
|
10
|
+
/** Test seam (spec 048): no message is being handed over and no channel queue has work. */
|
|
11
|
+
isIdle(): boolean;
|
|
12
|
+
isRunning(channelId: string): boolean;
|
|
13
|
+
/** The stateless report commands, for the e2e harness and the TUI. */
|
|
14
|
+
runRuntimeCommand(event: ChannelEvent, name: RuntimeCommandName, args: string): Promise<string>;
|
|
15
|
+
/** Run one turn for `event` now, bypassing the queue (test seam). */
|
|
16
|
+
handleEvent(event: ChannelEvent): Promise<void>;
|
|
17
|
+
/** Route a human message whose attachments are already settled, as `receive` would (test seam). */
|
|
18
|
+
routeEvent(event: HumanEvent): Promise<IngressResult>;
|
|
19
|
+
/** Reserve the turn for `event` the way the queue does just before it runs (test seam). */
|
|
20
|
+
reserveEvent(event: ChannelEvent): void;
|
|
21
|
+
}
|
|
22
|
+
export declare function createIngress(deps: IngressDeps): IngressService;
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { formatBusyHint, parseBuiltInCommand, renderBuiltInHelp, slashCommandName, } from "../commands/catalog.js";
|
|
2
|
+
import { DEFAULT_DESK } from "../desk/paths.js";
|
|
3
|
+
import * as log from "../log.js";
|
|
4
|
+
import { ChannelQueue } from "./channel-queue.js";
|
|
5
|
+
import { admitsSyntheticEvent, resolvedDesk } from "./desk-runtime.js";
|
|
6
|
+
import { resolveInboundAttachments } from "./inbound-images.js";
|
|
7
|
+
import { createBusyHandlers } from "./ingress-busy.js";
|
|
8
|
+
import { createCommandHandlers } from "./ingress-commands.js";
|
|
9
|
+
import { createEventTurnRunner, isSyntheticEvent } from "./turn-run.js";
|
|
10
|
+
/** Pending turns a channel may hold when its transport sends plain messages one turn each (`whenBusy: "queue"`). */
|
|
11
|
+
export const MAX_QUEUED_TURNS_PER_CHANNEL = 8;
|
|
12
|
+
// Bounds the turns queued for a channel whose busy messages steer or follow up (user messages and
|
|
13
|
+
// follow-up requeues). Without a limit, a flooded busy channel grows this queue without bound —
|
|
14
|
+
// each item still runs a full serialized turn, so an unbounded queue means unbounded backlog time
|
|
15
|
+
// and unbounded memory, not just a slow channel.
|
|
16
|
+
const USER_MESSAGE_QUEUE_LIMIT = 20;
|
|
17
|
+
const EVENT_QUEUE_LIMIT = 5;
|
|
18
|
+
export function createIngress(deps) {
|
|
19
|
+
const { transports, channelRunners, activeTasks, getRunner, resolveChannel, isShuttingDown, channelIndex } = deps;
|
|
20
|
+
const queues = new Map();
|
|
21
|
+
/** The `ref` of the message each channel's queue is running now, so a cancel can name its turn. */
|
|
22
|
+
const runningRefs = new Map();
|
|
23
|
+
let stopped = false;
|
|
24
|
+
let pendingReceives = 0;
|
|
25
|
+
const reservedTurns = new WeakSet();
|
|
26
|
+
const getQueue = (channelId) => {
|
|
27
|
+
let queue = queues.get(channelId);
|
|
28
|
+
if (!queue) {
|
|
29
|
+
queue = new ChannelQueue((current) => {
|
|
30
|
+
if (stopped || isShuttingDown() || deps.stopWatchdogs.has(channelId) || queues.get(channelId) !== current)
|
|
31
|
+
return;
|
|
32
|
+
deps.getDurableDispatch()?.notifyCapacity(channelId);
|
|
33
|
+
});
|
|
34
|
+
queues.set(channelId, queue);
|
|
35
|
+
}
|
|
36
|
+
return queue;
|
|
37
|
+
};
|
|
38
|
+
/** Drop what has not started on `channelId`, telling its transport which named messages went. */
|
|
39
|
+
const clearPending = (channelId) => {
|
|
40
|
+
const dropped = queues.get(channelId)?.clearPending();
|
|
41
|
+
if (dropped && dropped.refs.length > 0)
|
|
42
|
+
transports.forChannel(channelId)?.dropped?.(channelId, dropped.refs);
|
|
43
|
+
return dropped?.count ?? 0;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Detach all queued work from the previous session generation. The in-flight callback may
|
|
47
|
+
* still unwind on its old queue object, while subsequent messages get a fresh queue.
|
|
48
|
+
*/
|
|
49
|
+
const resetChannelQueue = (channelId) => {
|
|
50
|
+
const dropped = clearPending(channelId);
|
|
51
|
+
queues.get(channelId)?.stop();
|
|
52
|
+
queues.delete(channelId);
|
|
53
|
+
return dropped;
|
|
54
|
+
};
|
|
55
|
+
const isRunning = (channelId) => channelRunners.get(channelId)?.isBusy() ?? false;
|
|
56
|
+
const busy = createBusyHandlers(deps, { clearPending, reset: resetChannelQueue });
|
|
57
|
+
const commands = createCommandHandlers(deps, resetChannelQueue);
|
|
58
|
+
const runEventTurn = createEventTurnRunner({
|
|
59
|
+
transports,
|
|
60
|
+
store: deps.store,
|
|
61
|
+
activeTasks,
|
|
62
|
+
archiveIncomingMessage: deps.archiveIncomingMessage,
|
|
63
|
+
getRunner,
|
|
64
|
+
resolveChannel,
|
|
65
|
+
isCurrentRunner: (runner) => channelRunners.get(runner.conversation.channelId) === runner,
|
|
66
|
+
reservedTurns,
|
|
67
|
+
isShuttingDown,
|
|
68
|
+
getDurableDispatch: deps.getDurableDispatch,
|
|
69
|
+
getTaskControl: deps.getTaskControl,
|
|
70
|
+
runRuntimeCommand: commands.runRuntimeCommand,
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* Synchronously reserve an inbound turn before the queued async body yields: busy state shows
|
|
74
|
+
* up at once. Only a turn admission will accept gets reserved; `runEventTurn` releases it if
|
|
75
|
+
* it refuses.
|
|
76
|
+
*/
|
|
77
|
+
function reserveEvent(event) {
|
|
78
|
+
const resolution = resolveChannel(event.channelId);
|
|
79
|
+
if (resolution.kind !== "bound")
|
|
80
|
+
return;
|
|
81
|
+
if (isSyntheticEvent(event) && !admitsSyntheticEvent(resolution, event))
|
|
82
|
+
return;
|
|
83
|
+
// `/desk` runs outside any turn: `/desk bind` must see this channel idle (D5 step 1).
|
|
84
|
+
if (!isSyntheticEvent(event) && parseBuiltInCommand(event.text)?.name === "desk")
|
|
85
|
+
return;
|
|
86
|
+
const runner = getRunner(event.channelId);
|
|
87
|
+
if (!runner)
|
|
88
|
+
return;
|
|
89
|
+
runner.beginTurn(event.text);
|
|
90
|
+
reservedTurns.add(event);
|
|
91
|
+
}
|
|
92
|
+
/** Queue `event` as a turn of its own. */
|
|
93
|
+
function enqueueTurn(event, limit, onFull) {
|
|
94
|
+
const queue = getQueue(event.channelId);
|
|
95
|
+
const waiting = !queue.isIdle() || isRunning(event.channelId);
|
|
96
|
+
if (queue.size() >= limit) {
|
|
97
|
+
onFull();
|
|
98
|
+
return { kind: "rejected", reason: { code: "queue_full" } };
|
|
99
|
+
}
|
|
100
|
+
const ref = event.source === "human" ? event.ref : undefined;
|
|
101
|
+
queue.enqueue(async () => {
|
|
102
|
+
if (ref !== undefined)
|
|
103
|
+
runningRefs.set(event.channelId, ref);
|
|
104
|
+
try {
|
|
105
|
+
service.reserveEvent(event);
|
|
106
|
+
await service.handleEvent(event);
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
if (runningRefs.get(event.channelId) === ref)
|
|
110
|
+
runningRefs.delete(event.channelId);
|
|
111
|
+
}
|
|
112
|
+
}, ref);
|
|
113
|
+
return { kind: waiting ? "queued" : "started" };
|
|
114
|
+
}
|
|
115
|
+
function enqueueMessage(event, transport, textOverride) {
|
|
116
|
+
const queued = textOverride === undefined ? event : { ...event, text: textOverride };
|
|
117
|
+
if (transport.policy.whenBusy === "queue") {
|
|
118
|
+
return enqueueTurn(queued, MAX_QUEUED_TURNS_PER_CHANNEL, () => {
|
|
119
|
+
log.logWarn("ingress.queue.full", "Message rejected: channel queue full", {
|
|
120
|
+
channelId: event.channelId,
|
|
121
|
+
fields: { limit: MAX_QUEUED_TURNS_PER_CHANNEL },
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return enqueueTurn(queued, USER_MESSAGE_QUEUE_LIMIT, () => {
|
|
126
|
+
log.logWarn("ingress.queue.full", "Message discarded: channel queue full", {
|
|
127
|
+
channelId: event.channelId,
|
|
128
|
+
fields: { limit: USER_MESSAGE_QUEUE_LIMIT, preview: queued.text.substring(0, 50) },
|
|
129
|
+
});
|
|
130
|
+
void deps
|
|
131
|
+
.pushTo(event.channelId, {
|
|
132
|
+
text: `⚠️ 消息积压过多(超过 ${USER_MESSAGE_QUEUE_LIMIT} 条待处理),本条消息已丢弃,请稍后重试。`,
|
|
133
|
+
})
|
|
134
|
+
.catch(() => undefined);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const reply = (event, text, opts) => deps.pushTo(event.channelId, { text, ...opts, ...(event.ref !== undefined ? { ref: event.ref } : {}) });
|
|
138
|
+
async function replyToCommand(event, name, args) {
|
|
139
|
+
const response = await commands.runRuntimeCommand(event, name, args);
|
|
140
|
+
const delivered = await reply(event, response, { title: `/${name}`, markdown: true });
|
|
141
|
+
if (!delivered) {
|
|
142
|
+
log.logWarn("delivery.command_reply.failed", "Command reply delivery failed", {
|
|
143
|
+
channelId: event.channelId,
|
|
144
|
+
fields: { command: name, chars: response.length },
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** A message arrived while the channel is running a turn. */
|
|
149
|
+
async function routeBusy(event, transport) {
|
|
150
|
+
const { channelId } = event;
|
|
151
|
+
const content = event.text;
|
|
152
|
+
const builtIn = parseBuiltInCommand(content);
|
|
153
|
+
// All built-in commands are usable while a turn streams.
|
|
154
|
+
if (builtIn) {
|
|
155
|
+
switch (builtIn.name) {
|
|
156
|
+
case "help":
|
|
157
|
+
await reply(event, renderBuiltInHelp(builtIn.args), { title: "/help", markdown: true });
|
|
158
|
+
return { kind: "replied" };
|
|
159
|
+
case "stop": {
|
|
160
|
+
await busy.handleStop(channelId);
|
|
161
|
+
await reply(event, "已停止当前回合。", { title: "/stop", markdown: true });
|
|
162
|
+
return { kind: "replied" };
|
|
163
|
+
}
|
|
164
|
+
case "steer":
|
|
165
|
+
case "followup": {
|
|
166
|
+
const outcome = await busy.handleBusyMessage(event, builtIn.name === "steer" ? "steer" : "followUp", builtIn.args);
|
|
167
|
+
return outcome.kind === "requeue" ? enqueueMessage(event, transport, outcome.text) : { kind: "replied" };
|
|
168
|
+
}
|
|
169
|
+
default:
|
|
170
|
+
// Every remaining name is a stateless report (events/tasks/status/usage/context/
|
|
171
|
+
// subagents/skills), narrowed to RuntimeCommandName by the four cases above. Busy has
|
|
172
|
+
// no retry semantics, so `/context` is answered here like the rest instead of the
|
|
173
|
+
// runner-handled path idle uses for it (see IDLE_RUNTIME_COMMAND_NAMES in turn-run).
|
|
174
|
+
await replyToCommand(event, builtIn.name, builtIn.args);
|
|
175
|
+
return { kind: "replied" };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// Other session commands (/model, /compact, …) and unknown slash commands cannot run
|
|
179
|
+
// mid-turn: they would need the idle session layer.
|
|
180
|
+
if (content.trim().startsWith("/")) {
|
|
181
|
+
await reply(event, formatBusyHint());
|
|
182
|
+
return { kind: "replied" };
|
|
183
|
+
}
|
|
184
|
+
const { whenBusy } = transport.policy;
|
|
185
|
+
if (whenBusy === "queue") {
|
|
186
|
+
return enqueueMessage(event, transport);
|
|
187
|
+
}
|
|
188
|
+
const outcome = await busy.handleBusyMessage(event, whenBusy, content);
|
|
189
|
+
return outcome.kind === "requeue" ? enqueueMessage(event, transport, outcome.text) : { kind: "replied" };
|
|
190
|
+
}
|
|
191
|
+
/** Route one authorized, bound, attachment-settled human message (D6 steps 3–6). */
|
|
192
|
+
async function route(event, transport) {
|
|
193
|
+
if (event.context?.messages.length)
|
|
194
|
+
return enqueueMessage(event, transport);
|
|
195
|
+
const builtIn = parseBuiltInCommand(event.text);
|
|
196
|
+
// `/new` is an emergency boundary as well as a session command. Route it before busy
|
|
197
|
+
// checking and before the old channel queue, so a wedged compaction/provider request
|
|
198
|
+
// cannot prevent recovery.
|
|
199
|
+
if (slashCommandName(event.text) === "new") {
|
|
200
|
+
await commands.handleNewSession(event);
|
|
201
|
+
return { kind: "replied" };
|
|
202
|
+
}
|
|
203
|
+
if (!transport.policy.textControlCommands &&
|
|
204
|
+
builtIn &&
|
|
205
|
+
(builtIn.name === "stop" || builtIn.name === "steer" || builtIn.name === "followup")) {
|
|
206
|
+
return { kind: "rejected", reason: { code: "control_command", command: builtIn.name } };
|
|
207
|
+
}
|
|
208
|
+
if (isRunning(event.channelId)) {
|
|
209
|
+
return routeBusy(event, transport);
|
|
210
|
+
}
|
|
211
|
+
return enqueueMessage(event, transport);
|
|
212
|
+
}
|
|
213
|
+
/** D6 steps 1–2 plus attachment settling: everything before a message can be routed. */
|
|
214
|
+
async function admit(message) {
|
|
215
|
+
if (isShuttingDown() || stopped)
|
|
216
|
+
return { kind: "rejected", reason: { code: "shutting_down" } };
|
|
217
|
+
const transport = transports.forChannel(message.channelId);
|
|
218
|
+
if (!transport) {
|
|
219
|
+
throw new Error(`No transport hosts channel ${message.channelId}`);
|
|
220
|
+
}
|
|
221
|
+
// The one place a real person's message is seen before command/busy routing splits the path,
|
|
222
|
+
// so the channel index counts every human message and no synthetic wake.
|
|
223
|
+
channelIndex.note({ channelId: message.channelId, name: message.channelName, at: Date.now() });
|
|
224
|
+
await deps.ensureBinding(message.channelId, message.allowedDesks?.[0] ?? DEFAULT_DESK);
|
|
225
|
+
const resolution = resolveChannel(message.channelId);
|
|
226
|
+
const desk = resolvedDesk(resolution);
|
|
227
|
+
if (message.allowedDesks && desk !== undefined && !message.allowedDesks.includes(desk)) {
|
|
228
|
+
return { kind: "rejected", reason: { code: "desk_not_allowed", desk } };
|
|
229
|
+
}
|
|
230
|
+
let text = message.text;
|
|
231
|
+
let images;
|
|
232
|
+
if (message.attachments && message.attachments.length > 0) {
|
|
233
|
+
const settled = await resolveInboundAttachments({
|
|
234
|
+
deskDir: resolution.kind === "bound" ? resolution.conversation.deskDir : undefined,
|
|
235
|
+
channelId: message.channelId,
|
|
236
|
+
text,
|
|
237
|
+
attachments: message.attachments,
|
|
238
|
+
});
|
|
239
|
+
text = settled.text;
|
|
240
|
+
if (settled.images.length > 0)
|
|
241
|
+
images = settled.images;
|
|
242
|
+
}
|
|
243
|
+
const event = {
|
|
244
|
+
source: "human",
|
|
245
|
+
channelId: message.channelId,
|
|
246
|
+
ts: message.ts,
|
|
247
|
+
user: message.user,
|
|
248
|
+
userName: message.userName ?? message.user,
|
|
249
|
+
text,
|
|
250
|
+
...(message.context ? { context: message.context } : {}),
|
|
251
|
+
...(message.channelName ? { channelName: message.channelName } : {}),
|
|
252
|
+
...(images ? { images } : {}),
|
|
253
|
+
...(message.ref !== undefined ? { ref: message.ref } : {}),
|
|
254
|
+
...(message.allowedDesks ? { allowedDesks: message.allowedDesks } : {}),
|
|
255
|
+
};
|
|
256
|
+
return { event, transport };
|
|
257
|
+
}
|
|
258
|
+
const service = {
|
|
259
|
+
execute: (message) => {
|
|
260
|
+
if (stopped || !deps.requestExecution)
|
|
261
|
+
return Promise.resolve({ kind: "rejected", reason: { code: "shutting_down" } });
|
|
262
|
+
return deps.requestExecution.execute(message);
|
|
263
|
+
},
|
|
264
|
+
async receive(message) {
|
|
265
|
+
pendingReceives++;
|
|
266
|
+
try {
|
|
267
|
+
const admitted = await admit(message);
|
|
268
|
+
if ("kind" in admitted)
|
|
269
|
+
return admitted;
|
|
270
|
+
return await route(admitted.event, admitted.transport);
|
|
271
|
+
}
|
|
272
|
+
finally {
|
|
273
|
+
pendingReceives--;
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
async steer(channelId, message) {
|
|
277
|
+
pendingReceives++;
|
|
278
|
+
try {
|
|
279
|
+
const admitted = await admit({ ...message, channelId });
|
|
280
|
+
if ("kind" in admitted)
|
|
281
|
+
return { kind: "rejected", code: "response_not_active" };
|
|
282
|
+
const { event, transport } = admitted;
|
|
283
|
+
if (!event.text.trim() && !event.images)
|
|
284
|
+
return { kind: "rejected", code: "invalid_input" };
|
|
285
|
+
const outcome = await busy.handleBusyMessage(event, "steer", event.text, true);
|
|
286
|
+
if (outcome.kind === "steered")
|
|
287
|
+
return { kind: "accepted" };
|
|
288
|
+
if (outcome.kind === "requeue") {
|
|
289
|
+
// The turn ended before the message could join it: it runs next, as a turn of its own.
|
|
290
|
+
const queued = enqueueMessage(event, transport, outcome.text);
|
|
291
|
+
return queued.kind === "rejected"
|
|
292
|
+
? { kind: "rejected", code: "too_many_pending_steers" }
|
|
293
|
+
: { kind: "accepted" };
|
|
294
|
+
}
|
|
295
|
+
return { kind: "rejected", code: "response_not_active" };
|
|
296
|
+
}
|
|
297
|
+
finally {
|
|
298
|
+
pendingReceives--;
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
async cancel(channelId) {
|
|
302
|
+
if (await deps.requestExecution?.cancel(channelId))
|
|
303
|
+
return;
|
|
304
|
+
await busy.handleStop(channelId);
|
|
305
|
+
},
|
|
306
|
+
async cancelTurn(channelId, ref) {
|
|
307
|
+
if (await deps.requestExecution?.cancel(channelId))
|
|
308
|
+
return true;
|
|
309
|
+
if (runningRefs.get(channelId) !== ref)
|
|
310
|
+
return false;
|
|
311
|
+
return busy.cancelRunningTurn(channelId);
|
|
312
|
+
},
|
|
313
|
+
dropQueued(channelId, ref) {
|
|
314
|
+
return queues.get(channelId)?.removeByRef(ref) ?? false;
|
|
315
|
+
},
|
|
316
|
+
async closeChannel(channelId) {
|
|
317
|
+
const queue = queues.get(channelId);
|
|
318
|
+
if (isRunning(channelId) || (queue && !queue.isIdle()))
|
|
319
|
+
return "busy";
|
|
320
|
+
resetChannelQueue(channelId);
|
|
321
|
+
await deps.unbind(channelId);
|
|
322
|
+
return "closed";
|
|
323
|
+
},
|
|
324
|
+
enqueueEvent(event) {
|
|
325
|
+
if (stopped)
|
|
326
|
+
return false;
|
|
327
|
+
const queue = getQueue(event.channelId);
|
|
328
|
+
if (queue.size() >= EVENT_QUEUE_LIMIT) {
|
|
329
|
+
log.logEvent("warn", "runtime.channel_queue.full", "Discarding incoming event", {
|
|
330
|
+
ctx: { channelId: event.channelId, userName: event.producer },
|
|
331
|
+
fields: {
|
|
332
|
+
messageLength: event.text.length,
|
|
333
|
+
dispatchId: event.dispatchId,
|
|
334
|
+
desk: event.desk,
|
|
335
|
+
queueLength: queue.size(),
|
|
336
|
+
reason: "capacity",
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
log.logEvent("debug", "runtime.channel_queue.enqueued", "Incoming event queued", {
|
|
342
|
+
ctx: { channelId: event.channelId, userName: event.producer },
|
|
343
|
+
fields: {
|
|
344
|
+
messageLength: event.text.length,
|
|
345
|
+
dispatchId: event.dispatchId,
|
|
346
|
+
desk: event.desk,
|
|
347
|
+
queueLength: queue.size(),
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
queue.enqueue(async () => {
|
|
351
|
+
service.reserveEvent(event);
|
|
352
|
+
await service.handleEvent(event);
|
|
353
|
+
});
|
|
354
|
+
return true;
|
|
355
|
+
},
|
|
356
|
+
stop() {
|
|
357
|
+
stopped = true;
|
|
358
|
+
for (const queue of queues.values()) {
|
|
359
|
+
queue.stop();
|
|
360
|
+
}
|
|
361
|
+
},
|
|
362
|
+
isIdle() {
|
|
363
|
+
if (deps.requestExecution && !deps.requestExecution.isIdle())
|
|
364
|
+
return false;
|
|
365
|
+
if (pendingReceives > 0)
|
|
366
|
+
return false;
|
|
367
|
+
for (const queue of queues.values()) {
|
|
368
|
+
if (!queue.isIdle())
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
return true;
|
|
372
|
+
},
|
|
373
|
+
async routeEvent(event) {
|
|
374
|
+
const transport = transports.forChannel(event.channelId);
|
|
375
|
+
if (!transport)
|
|
376
|
+
throw new Error(`No transport hosts channel ${event.channelId}`);
|
|
377
|
+
await deps.ensureBinding(event.channelId, DEFAULT_DESK);
|
|
378
|
+
return route(event, transport);
|
|
379
|
+
},
|
|
380
|
+
isRunning,
|
|
381
|
+
runRuntimeCommand: commands.runRuntimeCommand,
|
|
382
|
+
handleEvent: runEventTurn,
|
|
383
|
+
reserveEvent,
|
|
384
|
+
};
|
|
385
|
+
return service;
|
|
386
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AgentRunner } from "../agent/types.js";
|
|
2
|
+
import type { InboundMessage, IngressResult } from "../channel/ingress.js";
|
|
3
|
+
import type { ChannelStore } from "../channel/store.js";
|
|
4
|
+
import type { DeskConversation } from "../desk/types.js";
|
|
5
|
+
import type { TransportRegistry } from "./transports.js";
|
|
6
|
+
export interface RequestExecution {
|
|
7
|
+
execute(message: InboundMessage): Promise<IngressResult>;
|
|
8
|
+
cancel(channelId: string): Promise<boolean>;
|
|
9
|
+
isIdle(): boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function createRequestExecution(deps: {
|
|
12
|
+
workspaceDir: string;
|
|
13
|
+
runners: Map<string, AgentRunner>;
|
|
14
|
+
activeTasks: Set<Promise<void>>;
|
|
15
|
+
transports: TransportRegistry;
|
|
16
|
+
store: ChannelStore;
|
|
17
|
+
isShuttingDown: () => boolean;
|
|
18
|
+
createRunner: (conversation: DeskConversation) => AgentRunner;
|
|
19
|
+
}): RequestExecution;
|