@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,8 @@
|
|
|
1
|
+
import type { TaskPendingWork } from "../tasks/control.js";
|
|
2
|
+
import type { TaskLaneOptions } from "./task-lane-types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Delegations and background jobs bound to a task and not yet settled — the facts a task's wait
|
|
5
|
+
* is derived from (spec 064, D8/INV-4). Read from the run and job managers, which also own each
|
|
6
|
+
* one's hard deadline.
|
|
7
|
+
*/
|
|
8
|
+
export declare function listPendingWork(options: Pick<TaskLaneOptions, "getRuns" | "getJobs">, desk: string, now: number, withActivity?: boolean): Promise<Map<string, TaskPendingWork[]>>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { readLastOutputAt, STALL_THRESHOLD_MS } from "../subagents/external/progress-tail.js";
|
|
2
|
+
/**
|
|
3
|
+
* Delegations and background jobs bound to a task and not yet settled — the facts a task's wait
|
|
4
|
+
* is derived from (spec 064, D8/INV-4). Read from the run and job managers, which also own each
|
|
5
|
+
* one's hard deadline.
|
|
6
|
+
*/
|
|
7
|
+
export async function listPendingWork(options, desk, now, withActivity = false) {
|
|
8
|
+
const byTask = new Map();
|
|
9
|
+
await options.getRuns(desk).retryTaskSettlements?.();
|
|
10
|
+
const add = (taskId, work) => {
|
|
11
|
+
const list = byTask.get(taskId);
|
|
12
|
+
if (list)
|
|
13
|
+
list.push(work);
|
|
14
|
+
else
|
|
15
|
+
byTask.set(taskId, [work]);
|
|
16
|
+
};
|
|
17
|
+
for (const run of options.getRuns(desk).list()) {
|
|
18
|
+
if (!run.taskId || run.settledAt !== undefined)
|
|
19
|
+
continue;
|
|
20
|
+
let lastOutputAt;
|
|
21
|
+
if (withActivity && run.runtime === "external")
|
|
22
|
+
lastOutputAt = await readLastOutputAt(run.artifactDir);
|
|
23
|
+
const quietSince = lastOutputAt ?? run.processStartedAt ?? run.startedAt;
|
|
24
|
+
add(run.taskId, {
|
|
25
|
+
ref: run.runId,
|
|
26
|
+
kind: "delegation",
|
|
27
|
+
label: run.agent,
|
|
28
|
+
startedAt: run.startedAt,
|
|
29
|
+
...(lastOutputAt !== undefined ? { lastOutputAt } : {}),
|
|
30
|
+
stalled: run.runtime === "external" && withActivity && now - quietSince >= STALL_THRESHOLD_MS,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const jobs = await options.getJobs(desk).list();
|
|
34
|
+
for (const job of jobs) {
|
|
35
|
+
if (!job.taskId || job.status !== "running")
|
|
36
|
+
continue;
|
|
37
|
+
add(job.taskId, { ref: job.id, kind: "job", label: job.label, startedAt: job.startedAt, stalled: false });
|
|
38
|
+
}
|
|
39
|
+
return byTask;
|
|
40
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { SpawnTaskRequest, SpawnTaskResult } from "../events/types.js";
|
|
2
2
|
export interface TaskSpawnerOptions {
|
|
3
|
-
/** The
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
/** Direct, non-LLM
|
|
8
|
-
notify: (channelId: string, text: string) => Promise<unknown>;
|
|
3
|
+
/** The event's desk directory: the instance is created in its `tasks/`. */
|
|
4
|
+
getDeskDir: (desk: string) => string;
|
|
5
|
+
/** Tell the task lane so the new instance is admitted promptly. */
|
|
6
|
+
wake: () => void;
|
|
7
|
+
/** Direct, non-LLM receipt to the event's channel, through the desk's binding guard (D7). */
|
|
8
|
+
notify: (desk: string, channelId: string, text: string) => Promise<unknown>;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Create the task instance a template event asks for (spec 052, D2).
|
|
@@ -18,7 +18,7 @@ export interface TaskSpawnerOptions {
|
|
|
18
18
|
* A second instance of the same event never runs alongside the first: two copies of the same
|
|
19
19
|
* recurring job mostly duplicate work or collide. The occurrence is skipped and the user is told
|
|
20
20
|
* every time (INV-7) — a stuck instance is something they need to know about, not something to
|
|
21
|
-
* hide behind a quiet skip. The stuck instance itself is bounded by its budget
|
|
22
|
-
*
|
|
21
|
+
* hide behind a quiet skip. The stuck instance itself is bounded by its budget and the lane's
|
|
22
|
+
* guards, so the skipping cannot go on forever.
|
|
23
23
|
*/
|
|
24
24
|
export declare function createTaskSpawner(options: TaskSpawnerOptions): (request: SpawnTaskRequest) => Promise<SpawnTaskResult>;
|
|
@@ -15,21 +15,21 @@ import { archivedTaskPath, taskPath, tasksDir } from "../tasks/store.js";
|
|
|
15
15
|
* A second instance of the same event never runs alongside the first: two copies of the same
|
|
16
16
|
* recurring job mostly duplicate work or collide. The occurrence is skipped and the user is told
|
|
17
17
|
* every time (INV-7) — a stuck instance is something they need to know about, not something to
|
|
18
|
-
* hide behind a quiet skip. The stuck instance itself is bounded by its budget
|
|
19
|
-
*
|
|
18
|
+
* hide behind a quiet skip. The stuck instance itself is bounded by its budget and the lane's
|
|
19
|
+
* guards, so the skipping cannot go on forever.
|
|
20
20
|
*/
|
|
21
21
|
export function createTaskSpawner(options) {
|
|
22
22
|
return async (request) => {
|
|
23
|
-
const
|
|
23
|
+
const deskDir = options.getDeskDir(request.desk);
|
|
24
24
|
const id = `${request.eventName}-${instanceStamp(request.occurrence)}`;
|
|
25
|
-
if (existsSync(taskPath(
|
|
25
|
+
if (existsSync(taskPath(deskDir, id)) || existsSync(archivedTaskPath(deskDir, id))) {
|
|
26
26
|
return { outcome: "exists", id };
|
|
27
27
|
}
|
|
28
|
-
const active = (await readActiveTasks(tasksDir(
|
|
28
|
+
const active = (await readActiveTasks(tasksDir(deskDir))).find((entry) => entry.fields.origin === request.eventName && !entry.fields.outcome);
|
|
29
29
|
if (active) {
|
|
30
|
-
const state =
|
|
30
|
+
const state = taskStateLabel(active.fields);
|
|
31
31
|
await options
|
|
32
|
-
.notify(request.channelId, `⚠️ 周期任务 \`${request.eventName}\` 本次(${instanceStamp(request.occurrence)})未启动:上一个实例 \`${active.id}\` 仍未结束(${state})。\n查看:\`/tasks show ${active.id}\``)
|
|
32
|
+
.notify(request.desk, request.channelId, `⚠️ 周期任务 \`${request.eventName}\` 本次(${instanceStamp(request.occurrence)})未启动:上一个实例 \`${active.id}\` 仍未结束(${state})。\n查看:\`/tasks show ${active.id}\``)
|
|
33
33
|
.catch((error) => {
|
|
34
34
|
log.logWarn("tasks.spawn.receipt_failed", "Skip receipt delivery failed", {
|
|
35
35
|
channelId: request.channelId,
|
|
@@ -40,9 +40,10 @@ export function createTaskSpawner(options) {
|
|
|
40
40
|
return { outcome: "skipped", id: active.id };
|
|
41
41
|
}
|
|
42
42
|
await createTaskDocument({
|
|
43
|
-
|
|
43
|
+
deskDir,
|
|
44
44
|
id,
|
|
45
45
|
input: request.template,
|
|
46
|
+
channel: request.channelId,
|
|
46
47
|
origin: request.eventName,
|
|
47
48
|
now: request.occurrence,
|
|
48
49
|
});
|
|
@@ -50,7 +51,7 @@ export function createTaskSpawner(options) {
|
|
|
50
51
|
channelId: request.channelId,
|
|
51
52
|
fields: { event: request.eventName, taskId: id },
|
|
52
53
|
});
|
|
53
|
-
options.
|
|
54
|
+
options.wake();
|
|
54
55
|
return { outcome: "spawned", id };
|
|
55
56
|
};
|
|
56
57
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type AgentRunner } from "../agent/types.js";
|
|
2
|
+
import type { TaskStepIntent } from "../tasks/control.js";
|
|
3
|
+
import { type TaskStepResult } from "../tasks/loop-log.js";
|
|
4
|
+
import type { StepDerivation } from "../tasks/state.js";
|
|
5
|
+
import { type EndedStep } from "../tasks/store.js";
|
|
6
|
+
import type { LaneContext, LiveTask, StepAbort } from "./task-lane-types.js";
|
|
7
|
+
/** The task's runner, built on first use and kept until the task leaves execution (D13). */
|
|
8
|
+
export declare function ensureRunner(ctx: LaneContext, live: LiveTask): AgentRunner;
|
|
9
|
+
/** Stop the running step: the turn is asked to end, and the abort cuts a tool that would not. */
|
|
10
|
+
export declare function abortStep(ctx: LaneContext, live: LiveTask, reason: StepAbort): void;
|
|
11
|
+
/** What a finished step tells the drive loop. */
|
|
12
|
+
export type StepReport =
|
|
13
|
+
/** The task is gone, or was paused or moved to a wait since the lane decided to run it: nothing ran. */
|
|
14
|
+
{
|
|
15
|
+
kind: "skipped";
|
|
16
|
+
}
|
|
17
|
+
/** The process is stopping: the step's `step_end` is written by the next start's reconciliation (D10). */
|
|
18
|
+
| {
|
|
19
|
+
kind: "interrupted";
|
|
20
|
+
} | {
|
|
21
|
+
kind: "ended";
|
|
22
|
+
result: TaskStepResult;
|
|
23
|
+
ended: EndedStep | undefined;
|
|
24
|
+
derivation: StepDerivation;
|
|
25
|
+
intent: TaskStepIntent;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* One step (spec 064, D14): write the `step` record, build the brief, run the turn in the task's
|
|
29
|
+
* own session with a time limit, and write what happened. The state that follows is derived from the
|
|
30
|
+
* step's facts inside `endStep`, not declared by the model (INV-2).
|
|
31
|
+
*/
|
|
32
|
+
export declare function executeStep(ctx: LaneContext, live: LiveTask): Promise<StepReport>;
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { clipUserInput } from "../agent/turn/progress-formatter.js";
|
|
2
|
+
import { MAX_USER_MESSAGE_CHARS } from "../agent/types.js";
|
|
3
|
+
import * as log from "../log.js";
|
|
4
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
5
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
6
|
+
import { BRIEF_INPUT_LIMIT, buildTaskStepBrief, contractOpenTag, contractSha, } from "../tasks/brief.js";
|
|
7
|
+
import { taskReportDelivered } from "../tasks/completion.js";
|
|
8
|
+
import { drainTaskDeliveries, queueTaskReport } from "../tasks/delivery.js";
|
|
9
|
+
import { acknowledgeTaskInputs, taskInputTag } from "../tasks/input-receipts.js";
|
|
10
|
+
import { readTaskLog } from "../tasks/loop-log.js";
|
|
11
|
+
import { beginStep, endStep, pauseTask, readStoredTask } from "../tasks/store.js";
|
|
12
|
+
import { listPendingWork } from "./task-pending.js";
|
|
13
|
+
/** A task step speaks to nobody: only `task_report`, `task_ask` and the lane's receipts reach a channel (INV-1). */
|
|
14
|
+
const SILENT_CONTEXT = { emit: () => undefined, finish: async () => undefined };
|
|
15
|
+
/** The task session's view of its lane: which step is running and where it reports. */
|
|
16
|
+
function sessionContextOf(ctx, live) {
|
|
17
|
+
const assertActive = () => {
|
|
18
|
+
if (!live.step || live.step.abort || live.quarantined || ctx.isStopped())
|
|
19
|
+
throw new RecoverableToolError("This task step has stopped. End the turn; the runtime will preserve its pending inputs.");
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
assertActive,
|
|
23
|
+
taskId: live.taskId,
|
|
24
|
+
seq: () => {
|
|
25
|
+
assertActive();
|
|
26
|
+
return live.seq;
|
|
27
|
+
},
|
|
28
|
+
intent: () => {
|
|
29
|
+
assertActive();
|
|
30
|
+
return live.intent;
|
|
31
|
+
},
|
|
32
|
+
report: async (text) => {
|
|
33
|
+
assertActive();
|
|
34
|
+
const message = await queueTaskReport(live.deskDir, live.taskId, live.seq, live.channelId, text);
|
|
35
|
+
await drainTaskDeliveries(live.deskDir, (channel, text) => ctx.options.deliver(live.desk, channel, text), (channel) => ctx.options.isBoundTo(channel, live.desk) && ctx.options.isReachable(channel), ctx.now());
|
|
36
|
+
ctx.notify();
|
|
37
|
+
return {
|
|
38
|
+
id: message.id,
|
|
39
|
+
delivered: taskReportDelivered(await readTaskLog(live.deskDir, live.taskId), message.id),
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** The task's runner, built on first use and kept until the task leaves execution (D13). */
|
|
45
|
+
export function ensureRunner(ctx, live) {
|
|
46
|
+
if (live.runner)
|
|
47
|
+
return live.runner;
|
|
48
|
+
live.runner = ctx.options.createTaskRunner({
|
|
49
|
+
desk: live.desk,
|
|
50
|
+
deskDir: live.deskDir,
|
|
51
|
+
taskId: live.taskId,
|
|
52
|
+
channelId: live.channelId,
|
|
53
|
+
session: sessionContextOf(ctx, live),
|
|
54
|
+
});
|
|
55
|
+
return live.runner;
|
|
56
|
+
}
|
|
57
|
+
/** Stop the running step: the turn is asked to end, and the abort cuts a tool that would not. */
|
|
58
|
+
export function abortStep(ctx, live, reason) {
|
|
59
|
+
const step = live.step;
|
|
60
|
+
if (!step || step.abort)
|
|
61
|
+
return;
|
|
62
|
+
step.abort = reason;
|
|
63
|
+
const runner = live.runner;
|
|
64
|
+
if (!runner)
|
|
65
|
+
return;
|
|
66
|
+
runner.requestStop();
|
|
67
|
+
if (reason !== "shutdown") {
|
|
68
|
+
step.stopTimer = setTimeout(() => {
|
|
69
|
+
if (live.step !== step)
|
|
70
|
+
return;
|
|
71
|
+
live.quarantined = true;
|
|
72
|
+
runner.retireForRecovery();
|
|
73
|
+
void pauseTask(live.deskDir, live.taskId, {
|
|
74
|
+
by: "runtime",
|
|
75
|
+
reason: "当前步骤未能停止,请联系部署者重启服务后再恢复任务",
|
|
76
|
+
})
|
|
77
|
+
.then(async () => {
|
|
78
|
+
await ctx.options.deliver(live.desk, live.channelId, `⚠️ 任务 \`${live.taskId}\` 的当前步骤未能停止,已暂停后续执行。请联系部署者重启服务,再用 \`/tasks resume ${live.taskId}\` 恢复。`);
|
|
79
|
+
})
|
|
80
|
+
.catch((error) => log.logWarn("tasks.step.quarantine_failed", "Task step quarantine failed", {
|
|
81
|
+
reason: errorMessage(error),
|
|
82
|
+
fields: { taskId: live.taskId, desk: live.desk },
|
|
83
|
+
}));
|
|
84
|
+
}, ctx.timing.stopGraceMs);
|
|
85
|
+
step.stopTimer.unref?.();
|
|
86
|
+
}
|
|
87
|
+
void runner.abort().catch((error) => {
|
|
88
|
+
log.logWarn("tasks.step.abort_failed", "Task step abort failed", {
|
|
89
|
+
channelId: live.channelId,
|
|
90
|
+
reason: errorMessage(error),
|
|
91
|
+
fields: { taskId: live.taskId, desk: live.desk },
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function notifyStep(ctx, event) {
|
|
96
|
+
try {
|
|
97
|
+
ctx.options.onStep?.(event);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
log.logWarn("tasks.step.observer_failed", "Task step observer failed", { reason: errorMessage(error) });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* One step (spec 064, D14): write the `step` record, build the brief, run the turn in the task's
|
|
105
|
+
* own session with a time limit, and write what happened. The state that follows is derived from the
|
|
106
|
+
* step's facts inside `endStep`, not declared by the model (INV-2).
|
|
107
|
+
*/
|
|
108
|
+
export async function executeStep(ctx, live) {
|
|
109
|
+
const { options } = ctx;
|
|
110
|
+
const document = await readStoredTask(live.deskDir, live.taskId);
|
|
111
|
+
if (!document || document.fields.outcome)
|
|
112
|
+
return { kind: "skipped" };
|
|
113
|
+
await acknowledgeTaskInputs(live.deskDir, live.taskId);
|
|
114
|
+
const runner = ensureRunner(ctx, live);
|
|
115
|
+
// Whether the session still holds the current contract is read from the session itself, so a
|
|
116
|
+
// compaction that dropped it, or an edit that changed it, brings the full brief back (D15).
|
|
117
|
+
const full = !(await runner.contextIncludes(contractOpenTag(live.taskId, contractSha(document.body))));
|
|
118
|
+
const begun = await beginStep(live.deskDir, live.taskId, {
|
|
119
|
+
brief: full ? "full" : "delta",
|
|
120
|
+
allowed: (fields) => !ctx.isStopped() &&
|
|
121
|
+
options.isEnabled?.() !== false &&
|
|
122
|
+
!!fields.channel &&
|
|
123
|
+
options.isBoundTo(fields.channel, live.desk) &&
|
|
124
|
+
options.isReachable(fields.channel),
|
|
125
|
+
});
|
|
126
|
+
if (!begun)
|
|
127
|
+
return { kind: "skipped" };
|
|
128
|
+
live.seq = begun.seq;
|
|
129
|
+
live.intent = { reports: 0 };
|
|
130
|
+
const now = ctx.now();
|
|
131
|
+
const pendingMap = await listPendingWork(options, live.desk, now);
|
|
132
|
+
const pending = (pendingMap.get(live.taskId) ?? []).map((work) => ({
|
|
133
|
+
ref: work.ref,
|
|
134
|
+
label: work.label,
|
|
135
|
+
runningMs: now - work.startedAt,
|
|
136
|
+
}));
|
|
137
|
+
const brief = await buildTaskStepBrief({
|
|
138
|
+
deskDir: live.deskDir,
|
|
139
|
+
document: begun.document,
|
|
140
|
+
seq: begun.seq,
|
|
141
|
+
records: begun.records,
|
|
142
|
+
inputs: begun.inputs,
|
|
143
|
+
full,
|
|
144
|
+
pending,
|
|
145
|
+
now,
|
|
146
|
+
});
|
|
147
|
+
const visibleBrief = clipUserInput(brief.text, MAX_USER_MESSAGE_CHARS);
|
|
148
|
+
const step = {
|
|
149
|
+
seq: begun.seq,
|
|
150
|
+
startedAt: now,
|
|
151
|
+
submittedInputIds: new Set(begun.inputs
|
|
152
|
+
.slice(-BRIEF_INPUT_LIMIT)
|
|
153
|
+
.flatMap((input) => (input.id && visibleBrief.includes(taskInputTag(input.id)) ? [input.id] : []))),
|
|
154
|
+
};
|
|
155
|
+
live.step = step;
|
|
156
|
+
step.timer = setTimeout(() => abortStep(ctx, live, "timeout"), ctx.timing.stepTimeLimitMs);
|
|
157
|
+
step.timer.unref?.();
|
|
158
|
+
const info = {
|
|
159
|
+
channelId: live.channelId,
|
|
160
|
+
user: "TASK",
|
|
161
|
+
userName: "TASK",
|
|
162
|
+
text: brief.text,
|
|
163
|
+
ts: String(now),
|
|
164
|
+
};
|
|
165
|
+
notifyStep(ctx, { phase: "started", desk: live.desk, taskId: live.taskId, seq: begun.seq });
|
|
166
|
+
log.logInfoEvent("tasks.step.started", "Task step started", {
|
|
167
|
+
channelId: live.channelId,
|
|
168
|
+
fields: {
|
|
169
|
+
taskId: live.taskId,
|
|
170
|
+
desk: live.desk,
|
|
171
|
+
seq: begun.seq,
|
|
172
|
+
reason: begun.reason,
|
|
173
|
+
brief: full ? "full" : "delta",
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
let result = "ok";
|
|
177
|
+
let error;
|
|
178
|
+
let finalText = "";
|
|
179
|
+
let toolsUsed = [];
|
|
180
|
+
let usd = 0;
|
|
181
|
+
let usdEstimated = false;
|
|
182
|
+
let usdKnown = false;
|
|
183
|
+
try {
|
|
184
|
+
const running = runner.run(info, SILENT_CONTEXT, options.store);
|
|
185
|
+
ctx.inputAvailable(live.desk, live.taskId);
|
|
186
|
+
const run = await running;
|
|
187
|
+
finalText = run.finalText ?? "";
|
|
188
|
+
toolsUsed = run.toolsUsed ?? [];
|
|
189
|
+
usd = run.assistantCost?.usd ?? 0;
|
|
190
|
+
usdEstimated = run.assistantCost?.estimated === true;
|
|
191
|
+
usdKnown = run.assistantCost?.known ?? run.costKnown ?? run.assistantCost !== undefined;
|
|
192
|
+
if (run.stopReason === "error") {
|
|
193
|
+
result = "error";
|
|
194
|
+
error = run.errorMessage;
|
|
195
|
+
}
|
|
196
|
+
else if (run.stopReason === "aborted") {
|
|
197
|
+
result = "aborted";
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (cause) {
|
|
201
|
+
result = "error";
|
|
202
|
+
error = errorMessage(cause);
|
|
203
|
+
}
|
|
204
|
+
finally {
|
|
205
|
+
if (step.timer)
|
|
206
|
+
clearTimeout(step.timer);
|
|
207
|
+
if (step.stopTimer)
|
|
208
|
+
clearTimeout(step.stopTimer);
|
|
209
|
+
}
|
|
210
|
+
step.ending = true;
|
|
211
|
+
await step.submitting;
|
|
212
|
+
// Only this task step can own the SDK queue here; the next step has not started.
|
|
213
|
+
runner.clearTaskStepQueue?.(step.seq);
|
|
214
|
+
await acknowledgeTaskInputs(live.deskDir, live.taskId, {
|
|
215
|
+
desk: live.desk,
|
|
216
|
+
seq: step.seq,
|
|
217
|
+
generation: runner.generation,
|
|
218
|
+
});
|
|
219
|
+
live.step = undefined;
|
|
220
|
+
// A stop from the lane decides the result whatever the turn reported on its way out.
|
|
221
|
+
switch (step.abort) {
|
|
222
|
+
case "shutdown":
|
|
223
|
+
return { kind: "interrupted" };
|
|
224
|
+
case "timeout":
|
|
225
|
+
result = "timeout";
|
|
226
|
+
break;
|
|
227
|
+
case "pause":
|
|
228
|
+
case "cancel":
|
|
229
|
+
result = "aborted";
|
|
230
|
+
break;
|
|
231
|
+
case undefined:
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
// The leader's intent counts only if the step went well: a step that failed or was cut off
|
|
235
|
+
// did not finish what it started, so it is re-run rather than half-believed.
|
|
236
|
+
const intent = live.intent;
|
|
237
|
+
const honoured = result === "ok";
|
|
238
|
+
const ended = await endStep(live.deskDir, live.taskId, {
|
|
239
|
+
seq: begun.seq,
|
|
240
|
+
result,
|
|
241
|
+
note: finalText.trim() || "(无)",
|
|
242
|
+
tools: toolsUsed,
|
|
243
|
+
usd,
|
|
244
|
+
usdEstimated,
|
|
245
|
+
usdKnown,
|
|
246
|
+
...(error ? { error } : {}),
|
|
247
|
+
...(honoured && intent.close ? { close: intent.close } : {}),
|
|
248
|
+
facts: {
|
|
249
|
+
result,
|
|
250
|
+
closed: honoured && intent.close !== undefined,
|
|
251
|
+
pausedByUser: step.abort === "pause" || step.abort === "cancel" || live.quarantined === true,
|
|
252
|
+
...(honoured && intent.ask ? { asked: intent.ask } : {}),
|
|
253
|
+
...(honoured && intent.waitUntil ? { waitUntil: intent.waitUntil } : {}),
|
|
254
|
+
pendingWork: (await listPendingWork(options, live.desk, ctx.now())).get(live.taskId)?.length ?? 0,
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
notifyStep(ctx, {
|
|
258
|
+
phase: "ended",
|
|
259
|
+
desk: live.desk,
|
|
260
|
+
taskId: live.taskId,
|
|
261
|
+
seq: begun.seq,
|
|
262
|
+
result,
|
|
263
|
+
...(ended ? { next: ended.derivation.next } : {}),
|
|
264
|
+
});
|
|
265
|
+
log.logInfoEvent("tasks.step.ended", "Task step ended", {
|
|
266
|
+
channelId: live.channelId,
|
|
267
|
+
fields: { taskId: live.taskId, desk: live.desk, seq: begun.seq, result, next: ended?.derivation.next },
|
|
268
|
+
});
|
|
269
|
+
return {
|
|
270
|
+
kind: "ended",
|
|
271
|
+
result,
|
|
272
|
+
ended,
|
|
273
|
+
derivation: ended?.derivation ?? { next: "continue", state: "queued", keepSlot: false },
|
|
274
|
+
intent,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BootstrapPaths } from "../app/home.js";
|
|
2
|
+
import type { Ingress } from "../channel/ingress.js";
|
|
3
|
+
import type { Transport } from "../channel/transport.js";
|
|
4
|
+
import type { ConversationKind } from "../desk/types.js";
|
|
5
|
+
import type { SecurityLogEvent } from "../security/types.js";
|
|
6
|
+
export interface TransportRegistry {
|
|
7
|
+
/** The transport that owns `channelId`; `undefined` when its transport is not hosted by this process. */
|
|
8
|
+
forChannel(channelId: string): Transport | undefined;
|
|
9
|
+
/** Whether a message can be delivered to `channelId` right now. */
|
|
10
|
+
isReachable(channelId: string): boolean;
|
|
11
|
+
all(): readonly Transport[];
|
|
12
|
+
conversationKindOf(channelId: string): ConversationKind | undefined;
|
|
13
|
+
/** How a channel is named to a user; an unreachable channel falls back to its id. */
|
|
14
|
+
describeChannel(channelId: string, knownName?: string): string;
|
|
15
|
+
startAll(ingress: Ingress): Promise<void>;
|
|
16
|
+
/** Every transport stops taking messages and keeps delivering (see `Transport.stopAccepting`). */
|
|
17
|
+
stopAcceptingAll(): Promise<void>;
|
|
18
|
+
stopAll(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare function createTransportRegistry(transports: readonly Transport[]): TransportRegistry;
|
|
21
|
+
/**
|
|
22
|
+
* Build the transports `channel.json` turns on. A transport's code is imported only when its turn
|
|
23
|
+
* comes, so a disabled transport costs nothing — not its module, not its dependencies, not a
|
|
24
|
+
* listener (INV-7). A configuration that cannot be used, or that turns nothing on, refuses to start.
|
|
25
|
+
*/
|
|
26
|
+
export declare function loadTransports(deps: {
|
|
27
|
+
paths: BootstrapPaths;
|
|
28
|
+
stateDir: string;
|
|
29
|
+
archiveBotResponse: (channelId: string, text: string) => Promise<void>;
|
|
30
|
+
/** The security audit log, for the transports that take requests from the network. */
|
|
31
|
+
audit: (event: SecurityLogEvent) => void;
|
|
32
|
+
}): Promise<Transport[]>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The channel registry (spec 061, D9): which transports this process hosts and how a channel id
|
|
3
|
+
* finds its transport. The runtime never names a concrete transport anywhere else — it asks here.
|
|
4
|
+
*/
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { transportOf } from "../channel/channel-id.js";
|
|
8
|
+
import { ChannelConfigError, parseChannelConfig } from "../channel/config.js";
|
|
9
|
+
import { StartupRefusal } from "../desk/startup-error.js";
|
|
10
|
+
import * as log from "../log.js";
|
|
11
|
+
import { docsUrl } from "../paths.js";
|
|
12
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
13
|
+
export function createTransportRegistry(transports) {
|
|
14
|
+
const byName = new Map(transports.map((transport) => [transport.name, transport]));
|
|
15
|
+
const forChannel = (channelId) => {
|
|
16
|
+
const name = transportOf(channelId);
|
|
17
|
+
return name === undefined ? undefined : byName.get(name);
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
forChannel,
|
|
21
|
+
isReachable: (channelId) => forChannel(channelId) !== undefined,
|
|
22
|
+
all: () => transports,
|
|
23
|
+
conversationKindOf: (channelId) => forChannel(channelId)?.conversationKindOf(channelId),
|
|
24
|
+
describeChannel: (channelId, knownName) => forChannel(channelId)?.describe(channelId, knownName) ?? `\`${channelId}\``,
|
|
25
|
+
async startAll(ingress) {
|
|
26
|
+
for (const transport of transports) {
|
|
27
|
+
await transport.start(ingress);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
stopAcceptingAll: () => eachTransport(transports, (transport) => transport.stopAccepting()),
|
|
31
|
+
stopAll: () => eachTransport(transports, (transport) => transport.stop()),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Every transport gets the call even when an earlier one fails: shutdown must not strand a listener. */
|
|
35
|
+
async function eachTransport(transports, call) {
|
|
36
|
+
await Promise.all(transports.map((transport) => call(transport).catch((error) => {
|
|
37
|
+
log.logWarn("runtime.transport.stop_failed", "Transport stop failed", {
|
|
38
|
+
reason: errorMessage(error),
|
|
39
|
+
fields: { transport: transport.name },
|
|
40
|
+
});
|
|
41
|
+
})));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Build the transports `channel.json` turns on. A transport's code is imported only when its turn
|
|
45
|
+
* comes, so a disabled transport costs nothing — not its module, not its dependencies, not a
|
|
46
|
+
* listener (INV-7). A configuration that cannot be used, or that turns nothing on, refuses to start.
|
|
47
|
+
*/
|
|
48
|
+
export async function loadTransports(deps) {
|
|
49
|
+
const { channelConfigPath, appName } = deps.paths;
|
|
50
|
+
let sections;
|
|
51
|
+
try {
|
|
52
|
+
sections = parseChannelConfig(readFileSync(channelConfigPath, "utf-8"));
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (!(error instanceof ChannelConfigError)) {
|
|
56
|
+
throw new StartupRefusal(`Cannot read ${channelConfigPath}: ${errorMessage(error)}`);
|
|
57
|
+
}
|
|
58
|
+
throw new StartupRefusal(configurationRefusal(channelConfigPath, appName, error.issues));
|
|
59
|
+
}
|
|
60
|
+
const transports = [];
|
|
61
|
+
try {
|
|
62
|
+
if (sections.dingtalk !== undefined) {
|
|
63
|
+
const [{ DingTalkTransport }, { parseDingTalkConfig }] = await Promise.all([
|
|
64
|
+
import("../dingtalk/transport.js"),
|
|
65
|
+
import("../dingtalk/config.js"),
|
|
66
|
+
]);
|
|
67
|
+
const config = parseDingTalkConfig(sections.dingtalk);
|
|
68
|
+
config.stateDir = deps.stateDir;
|
|
69
|
+
transports.push(new DingTalkTransport({ config, archiveBotResponse: deps.archiveBotResponse }));
|
|
70
|
+
}
|
|
71
|
+
if (sections.webapi !== undefined) {
|
|
72
|
+
const [{ WebApiTransport }, { parseWebApiConfig }] = await Promise.all([
|
|
73
|
+
import("../webapi/transport.js"),
|
|
74
|
+
import("../webapi/config.js"),
|
|
75
|
+
]);
|
|
76
|
+
transports.push(new WebApiTransport({
|
|
77
|
+
config: parseWebApiConfig(sections.webapi),
|
|
78
|
+
stateDir: join(deps.stateDir, "webapi"),
|
|
79
|
+
audit: deps.audit,
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (!(error instanceof ChannelConfigError))
|
|
85
|
+
throw error;
|
|
86
|
+
throw new StartupRefusal(configurationRefusal(channelConfigPath, appName, error.issues));
|
|
87
|
+
}
|
|
88
|
+
if (transports.length === 0) {
|
|
89
|
+
throw new StartupRefusal(`No channel is switched on in ${channelConfigPath}. Set \`dingtalk.enabled\` or \`webapi.enabled\` to true, then run \`${appName}\` again.\nDocs: ${docsUrl("configuration.md")}`);
|
|
90
|
+
}
|
|
91
|
+
return transports;
|
|
92
|
+
}
|
|
93
|
+
function configurationRefusal(path, appName, issues) {
|
|
94
|
+
return [
|
|
95
|
+
`Configuration is not ready: ${path}`,
|
|
96
|
+
...issues.map((issue) => ` - ${issue}`),
|
|
97
|
+
"",
|
|
98
|
+
`Fix ${path} and run \`${appName}\` again.`,
|
|
99
|
+
`Docs: ${docsUrl("configuration.md")}`,
|
|
100
|
+
].join("\n");
|
|
101
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* One turn of the daemon's per-channel pipeline (
|
|
3
|
-
* built-in commands,
|
|
4
|
-
*
|
|
2
|
+
* One turn of the daemon's per-channel pipeline (what a channel queue runs for each item): dispatch
|
|
3
|
+
* admission, built-in commands, the agent run, and the settle-and-release epilogue that runs
|
|
4
|
+
* whatever happens. Task steps never come through here — they run in the task lane (spec 064).
|
|
5
5
|
*/
|
|
6
6
|
import type { AgentRunner } from "../agent/types.js";
|
|
7
|
-
import type
|
|
8
|
-
import type { ChannelEvent } from "../channel/channel-event.js";
|
|
7
|
+
import { type ChannelEvent, type WakeEvent } from "../channel/channel-event.js";
|
|
9
8
|
import type { ChannelStore } from "../channel/store.js";
|
|
10
9
|
import { type RuntimeCommandName } from "../commands/catalog.js";
|
|
11
|
-
import type {
|
|
12
|
-
import type
|
|
13
|
-
import type { SubAgentRuntime } from "../subagents/run-registry.js";
|
|
10
|
+
import type { TaskControl } from "../tasks/control.js";
|
|
11
|
+
import { type ChannelResolution } from "./desk-runtime.js";
|
|
14
12
|
import type { DurableDispatchService } from "./durable-dispatch.js";
|
|
15
|
-
import type {
|
|
13
|
+
import type { TransportRegistry } from "./transports.js";
|
|
14
|
+
/** A wake from an in-process producer rather than a person (spec 061, D8: the event's `source`). */
|
|
15
|
+
export declare function isSyntheticEvent(event: ChannelEvent): event is WakeEvent;
|
|
16
16
|
/** One message or wake, written to the message archive (see `ChannelStore.logMessage`). */
|
|
17
17
|
export interface ArchivedMessage {
|
|
18
18
|
date: string;
|
|
@@ -26,27 +26,24 @@ export interface ArchivedMessage {
|
|
|
26
26
|
images?: string[];
|
|
27
27
|
}
|
|
28
28
|
export interface EventTurnDeps {
|
|
29
|
-
|
|
30
|
-
paths: BootstrapPaths;
|
|
31
|
-
/** Test-only fault seams for the atomic structured-wake task transition. */
|
|
32
|
-
wakeTransitionHooks?: Partial<Record<"job" | "subagent", WakeTaskTransitionHooks>>;
|
|
33
|
-
};
|
|
29
|
+
transports: TransportRegistry;
|
|
34
30
|
store: ChannelStore;
|
|
35
31
|
activeTasks: Set<Promise<void>>;
|
|
36
32
|
archiveIncomingMessage: (channelId: string, message: ArchivedMessage, contextLabel: string) => Promise<void>;
|
|
37
|
-
|
|
33
|
+
/** The channel's runner; `undefined` when the channel is not bound to an available desk (no runner is built). */
|
|
34
|
+
getRunner: (channelId: string) => AgentRunner | undefined;
|
|
35
|
+
isCurrentRunner: (runner: AgentRunner) => boolean;
|
|
36
|
+
resolveChannel: (channelId: string) => ChannelResolution;
|
|
37
|
+
/** Events whose `reserveEvent` began a turn: a turn rejected at admission releases exactly these. */
|
|
38
|
+
reservedTurns: WeakSet<ChannelEvent>;
|
|
38
39
|
isShuttingDown: () => boolean;
|
|
39
40
|
getDurableDispatch: () => DurableDispatchService | undefined;
|
|
40
|
-
|
|
41
|
-
getRuns: () => SubAgentRuntime;
|
|
42
|
-
getTaskDriver: () => {
|
|
43
|
-
nudge?(): void;
|
|
44
|
-
};
|
|
41
|
+
getTaskControl: () => TaskControl | undefined;
|
|
45
42
|
/** The handler's `runRuntimeCommand`, for stateless reports typed on an idle channel. */
|
|
46
43
|
runRuntimeCommand: (event: ChannelEvent, name: RuntimeCommandName, args: string) => Promise<string>;
|
|
47
44
|
}
|
|
48
45
|
/**
|
|
49
|
-
* The turn pipeline behind
|
|
50
|
-
*
|
|
46
|
+
* The turn pipeline behind a queued item: admit the dispatch, run commands or the agent (as a task
|
|
47
|
+
* step when the wake is one), and always settle the dispatch and release the turn.
|
|
51
48
|
*/
|
|
52
|
-
export declare function createEventTurnRunner(deps: EventTurnDeps): (inboundEvent: ChannelEvent
|
|
49
|
+
export declare function createEventTurnRunner(deps: EventTurnDeps): (inboundEvent: ChannelEvent) => Promise<void>;
|