@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
|
@@ -1,39 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The daemon's composition root: loads config and builds the
|
|
3
|
-
* runs, the events, memory and task services, then wires the
|
|
4
|
-
*
|
|
2
|
+
* The daemon's composition root: loads config and builds the transports, the ingress, durable
|
|
3
|
+
* dispatch, jobs, delegation runs, the events, memory and task services, then wires the ordered
|
|
4
|
+
* shutdown (`shutdown.ts`).
|
|
5
5
|
*/
|
|
6
6
|
import { join } from "path";
|
|
7
7
|
import { loadDetachedMaintenanceContext } from "../agent/maintenance-context.js";
|
|
8
8
|
import { createRunner } from "../agent/runner-factory.js";
|
|
9
|
-
import {
|
|
9
|
+
import { scanConversationsForInterruptedTurns } from "../agent/turn/turn-recovery.js";
|
|
10
10
|
import { BootstrapExitError, bootstrapAppHome, DEFAULT_BOOTSTRAP_PATHS, parseArgs, printBootstrapSummary, printFirstRunGuide, readCliVersion, } from "../app/home.js";
|
|
11
11
|
import { prepareAppServices } from "../app/services.js";
|
|
12
|
-
import { createChannelIndex } from "../channel/channel-index.js";
|
|
13
|
-
import { ensureChannelDir, getChannelDir } from "../channel/channel-paths.js";
|
|
12
|
+
import { CHANNELS_INDEX_FILENAME, createChannelIndex } from "../channel/channel-index.js";
|
|
14
13
|
import { ChannelStore } from "../channel/store.js";
|
|
15
14
|
import { PipiclawSettingsManager } from "../config/settings.js";
|
|
16
15
|
import { getToolsConfigPath, loadToolsConfig } from "../config/tools.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
16
|
+
import { buildDeskList } from "../desk/commands.js";
|
|
17
|
+
import { initializeDefaultDesk } from "../desk/default.js";
|
|
18
|
+
import { getDeskDir } from "../desk/paths.js";
|
|
19
|
+
import { listDesks } from "../desk/registry.js";
|
|
20
|
+
import { StartupRefusal } from "../desk/startup-error.js";
|
|
19
21
|
import { createEventsWatcher } from "../events/watcher.js";
|
|
20
22
|
import { createExecutor } from "../executor.js";
|
|
21
|
-
import {
|
|
23
|
+
import { createFileStore } from "../file-store.js";
|
|
24
|
+
import { createJobRuntime } from "../jobs/runtime.js";
|
|
22
25
|
import * as log from "../log.js";
|
|
23
26
|
import { MemoryMaintenanceScheduler } from "../memory/scheduler.js";
|
|
24
27
|
import { defaultModel } from "../models/runtime.js";
|
|
25
28
|
import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
|
|
29
|
+
import { logSecurityEvent } from "../security/logger.js";
|
|
26
30
|
import { fileStamp } from "../shared/format.js";
|
|
27
31
|
import { errorMessage } from "../shared/text-utils.js";
|
|
28
32
|
import { renderRunNotice } from "../subagents/commands.js";
|
|
29
33
|
import { createSubAgentRuntime } from "../subagents/run-registry.js";
|
|
34
|
+
import { taskSessionPath } from "../tasks/session-path.js";
|
|
30
35
|
import { getUsageLedger } from "../usage/ledger.js";
|
|
36
|
+
import { acquireDaemonLock, tryAcquireDaemonLock } from "./daemon-lock.js";
|
|
37
|
+
import { DeskRuntime } from "./desk-runtime.js";
|
|
31
38
|
import { DurableDispatchService, renderDispatchExhaustedNotice } from "./durable-dispatch.js";
|
|
39
|
+
import { createIngress } from "./ingress.js";
|
|
40
|
+
import { createRequestExecution } from "./request-execution.js";
|
|
32
41
|
import { createShutdown } from "./shutdown.js";
|
|
33
|
-
import {
|
|
34
|
-
import { migrateTasksToV5 } from "./task-migration.js";
|
|
42
|
+
import { TaskLane } from "./task-lane.js";
|
|
35
43
|
import { createTaskSpawner } from "./task-spawn.js";
|
|
36
|
-
import {
|
|
44
|
+
import { createTransportRegistry, loadTransports } from "./transports.js";
|
|
37
45
|
/**
|
|
38
46
|
* Ceiling on cached runners per daemon process. A long-lived daemon otherwise accumulates one
|
|
39
47
|
* `ChannelRunner` (session, subscriptions, memory state) per distinct channel it has ever heard
|
|
@@ -55,20 +63,52 @@ async function evictIdleRunnersOverCap(channelRunners) {
|
|
|
55
63
|
break;
|
|
56
64
|
if (runner.isBusy())
|
|
57
65
|
continue;
|
|
58
|
-
channelRunners
|
|
59
|
-
await runner.dispose().catch((err) => {
|
|
60
|
-
log.logWarn("runtime.runner.evict_dispose_failed", "Evicted runner dispose failed", {
|
|
61
|
-
channelId: channelId,
|
|
62
|
-
reason: errorMessage(err),
|
|
63
|
-
});
|
|
64
|
-
});
|
|
66
|
+
await releaseCachedRunner(channelRunners, channelId);
|
|
65
67
|
}
|
|
66
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Take a channel's runner out of the cache, then dispose it: the next message builds a fresh one
|
|
71
|
+
* from the channel's current binding. Used by LRU eviction and by `/desk bind` (spec 058, D5 step
|
|
72
|
+
* 5), whose final reflect writes into the desk the runner belonged to.
|
|
73
|
+
*/
|
|
74
|
+
async function releaseCachedRunner(channelRunners, channelId) {
|
|
75
|
+
const runner = channelRunners.get(channelId);
|
|
76
|
+
if (!runner)
|
|
77
|
+
return;
|
|
78
|
+
channelRunners.delete(channelId);
|
|
79
|
+
await runner.dispose().catch((err) => {
|
|
80
|
+
log.logWarn("runtime.runner.dispose_failed", "Released runner dispose failed", {
|
|
81
|
+
channelId: channelId,
|
|
82
|
+
reason: errorMessage(err),
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/** The security audit log as a transport's `audit` callback; the config is read when the first event arrives. */
|
|
87
|
+
function securityAudit(paths) {
|
|
88
|
+
let config;
|
|
89
|
+
return (event) => {
|
|
90
|
+
config ??= loadSecurityConfigWithDiagnostics(paths.appHomeDir).config;
|
|
91
|
+
void logSecurityEvent(paths.workspaceDir, config, event);
|
|
92
|
+
};
|
|
93
|
+
}
|
|
67
94
|
export async function createRuntimeContext(options) {
|
|
95
|
+
// One runtime per app home (INV-11): a second one would write the same desks, sessions and
|
|
96
|
+
// state files with no lock between them. Taken before anything is touched.
|
|
97
|
+
const daemonLock = options.daemonLock ?? (await acquireDaemonLock(options.paths.appHomeDir));
|
|
98
|
+
try {
|
|
99
|
+
initializeDefaultDesk(options.paths);
|
|
100
|
+
return await buildRuntimeContext(options, daemonLock);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
await daemonLock.release();
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function buildRuntimeContext(options, daemonLock) {
|
|
68
108
|
const startServices = options.startServices ?? true;
|
|
69
109
|
const registerSignalHandlers = options.registerSignalHandlers ?? true;
|
|
70
|
-
const
|
|
71
|
-
const runtimeSettingsManager = options.settingsManager ?? new PipiclawSettingsManager(
|
|
110
|
+
const { workspaceDir, appHomeDir } = options.paths;
|
|
111
|
+
const runtimeSettingsManager = options.settingsManager ?? new PipiclawSettingsManager(appHomeDir);
|
|
72
112
|
log.configureLogging(runtimeSettingsManager.getLoggingSettings());
|
|
73
113
|
const startedAt = Date.now();
|
|
74
114
|
const cliVersion = readCliVersion();
|
|
@@ -77,11 +117,94 @@ export async function createRuntimeContext(options) {
|
|
|
77
117
|
const activeTasks = new Set();
|
|
78
118
|
/** Channels with a `/stop` watchdog in flight, so a burst of `/stop` starts only one. */
|
|
79
119
|
const stopWatchdogs = new Set();
|
|
80
|
-
// `workspace/CHANNELS.md`: names every channel id so the workspace, the logs and the agent
|
|
81
|
-
// stop dealing in `group_cid...`. Writes are debounced internally (see channel-index.ts).
|
|
82
|
-
const channelIndex = createChannelIndex({ workspaceDir: options.paths.workspaceDir });
|
|
83
120
|
let durableDispatch;
|
|
84
121
|
let shuttingDown = false;
|
|
122
|
+
const executor = options.executor ?? createExecutor();
|
|
123
|
+
const fileStore = options.fileStore ?? createFileStore();
|
|
124
|
+
const dispatch = (event) => durableDispatch?.dispatch(event) ?? false;
|
|
125
|
+
// The transports this process hosts. A delivered answer is archived through `store`, which is
|
|
126
|
+
// built below: the closure only runs once a turn is under way.
|
|
127
|
+
const transports = createTransportRegistry(options.transports ??
|
|
128
|
+
(await loadTransports({
|
|
129
|
+
paths: options.paths,
|
|
130
|
+
stateDir: join(appHomeDir, "state"),
|
|
131
|
+
audit: securityAudit(options.paths),
|
|
132
|
+
archiveBotResponse: (channelId, text) => store.logBotResponse(channelId, text, Date.now().toString()),
|
|
133
|
+
})));
|
|
134
|
+
/** Say something to a channel outside any turn; whether it was delivered. */
|
|
135
|
+
const pushTo = (channelId, message) => transports.forChannel(channelId)?.push(channelId, message) ?? Promise.resolve(false);
|
|
136
|
+
// The one authority on bindings and active desks (spec 058, D6). `ingress`, `taskLane` and the
|
|
137
|
+
// spawner are resolved lazily by its callbacks: none of them runs before this function returns.
|
|
138
|
+
const deskRuntime = new DeskRuntime({
|
|
139
|
+
workspaceDir,
|
|
140
|
+
conversationKindOf: (channelId) => transports.conversationKindOf(channelId),
|
|
141
|
+
recover: async (conversations) => {
|
|
142
|
+
// Spec 043, D10 point 1: repair turns interrupted by the last shutdown/crash before any of
|
|
143
|
+
// these channels takes traffic — a dangling session would 400 against the provider on
|
|
144
|
+
// every attempt until a human ran /new.
|
|
145
|
+
const report = await scanConversationsForInterruptedTurns(conversations, {
|
|
146
|
+
api: defaultModel.api,
|
|
147
|
+
provider: defaultModel.provider,
|
|
148
|
+
model: defaultModel.id,
|
|
149
|
+
});
|
|
150
|
+
if (report.repaired.length > 0) {
|
|
151
|
+
log.logWarn("runtime.recovery.repaired", "Interrupted turns repaired on restart", {
|
|
152
|
+
fields: {
|
|
153
|
+
repaired: report.repaired.length,
|
|
154
|
+
scanned: report.scanned,
|
|
155
|
+
channels: report.repaired.map((r) => r.conversation.channelId),
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
if (report.blocked.length > 0) {
|
|
160
|
+
log.logWarn("runtime.recovery.blocked", "Channels with an unrecoverable session will refuse new turns", {
|
|
161
|
+
reason: report.blocked.map((b) => `${b.conversation.channelId}: ${b.reason}`).join("; "),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
createWatcher: (target) => options.createEventsWatcher
|
|
166
|
+
? options.createEventsWatcher(target)
|
|
167
|
+
: createEventsWatcher({
|
|
168
|
+
...target,
|
|
169
|
+
isBound: (channelId) => deskRuntime.isBoundTo(channelId, target.desk),
|
|
170
|
+
isReachable: (channelId) => transports.isReachable(channelId),
|
|
171
|
+
sink: ingress,
|
|
172
|
+
executor,
|
|
173
|
+
commandGuardConfig: loadSecurityConfigWithDiagnostics(appHomeDir).config.commandGuard,
|
|
174
|
+
historyPath: options.paths.eventHistoryPath,
|
|
175
|
+
dispatch,
|
|
176
|
+
spawnTask: createTaskSpawner({
|
|
177
|
+
getDeskDir: (desk) => getDeskDir(workspaceDir, desk),
|
|
178
|
+
wake: () => taskLane.notify(),
|
|
179
|
+
notify: (desk, channelId, text) => deskRuntime.sendFromDesk(desk, channelId, text),
|
|
180
|
+
}),
|
|
181
|
+
}),
|
|
182
|
+
send: (channelId, text) => pushTo(channelId, { text }),
|
|
183
|
+
isChannelBusy: (channelId) => channelRunners.get(channelId)?.isBusy() ?? false,
|
|
184
|
+
releaseRunner: (channelId) => releaseCachedRunner(channelRunners, channelId),
|
|
185
|
+
onBindingChanged: () => channelIndex.noteBindingChanged(),
|
|
186
|
+
});
|
|
187
|
+
await deskRuntime.load();
|
|
188
|
+
const isBoundTo = (channelId, desk) => deskRuntime.isBoundTo(channelId, desk);
|
|
189
|
+
const store = new ChannelStore({
|
|
190
|
+
resolveArchiveDir: (channelId) => {
|
|
191
|
+
const resolution = deskRuntime.resolve(channelId);
|
|
192
|
+
return resolution.kind === "bound" ? resolution.conversation.conversationDir : undefined;
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
// `workspace/CHANNELS.md`: names every channel id (and shows its desk) so the workspace, the logs
|
|
196
|
+
// and `/desk` stop dealing in `group_cid...`. Writes are debounced internally.
|
|
197
|
+
const channelIndex = createChannelIndex({
|
|
198
|
+
workspaceDir,
|
|
199
|
+
getBoundDesk: (channelId) => deskRuntime.boundDesk(channelId),
|
|
200
|
+
});
|
|
201
|
+
await channelIndex.load();
|
|
202
|
+
// How a channel is named to a user: its transport says.
|
|
203
|
+
const labelOf = (channelId) => transports.describeChannel(channelId, channelIndex.nameOf(channelId));
|
|
204
|
+
const describeChannel = (desk, channelId) => ({
|
|
205
|
+
label: labelOf(channelId),
|
|
206
|
+
boundHere: deskRuntime.isBoundTo(channelId, desk),
|
|
207
|
+
});
|
|
85
208
|
const archiveIncomingMessage = async (channelId, message, contextLabel) => {
|
|
86
209
|
try {
|
|
87
210
|
await store.logMessage(channelId, message);
|
|
@@ -94,44 +217,82 @@ export async function createRuntimeContext(options) {
|
|
|
94
217
|
});
|
|
95
218
|
}
|
|
96
219
|
};
|
|
220
|
+
/** What every runner of a channel shares: the desk's managers, settings and how the channel is named and answered. */
|
|
221
|
+
const runnerPaths = (conversation, channelId) => ({
|
|
222
|
+
fileStore,
|
|
223
|
+
jobManager: jobs.get(conversation.desk),
|
|
224
|
+
runManager: runs.get(conversation.desk),
|
|
225
|
+
appHomeDir,
|
|
226
|
+
workspaceDir,
|
|
227
|
+
authConfigPath: options.paths.authConfigPath,
|
|
228
|
+
modelsConfigPath: options.paths.modelsConfigPath,
|
|
229
|
+
settingsManager: runtimeSettingsManager,
|
|
230
|
+
onSessionEvent: options.observer,
|
|
231
|
+
describeChannel: (id) => (channelIndex.nameOf(id) ? labelOf(id) : undefined),
|
|
232
|
+
describeConversation: (dir) => {
|
|
233
|
+
const owner = deskRuntime.channelOfConversation(conversation.desk, dir);
|
|
234
|
+
return owner ? labelOf(owner) : undefined;
|
|
235
|
+
},
|
|
236
|
+
// Enables `send_media`: the file goes out through the transport that owns this channel.
|
|
237
|
+
...(transports.forChannel(channelId)?.sendsMedia === false
|
|
238
|
+
? {}
|
|
239
|
+
: {
|
|
240
|
+
sendMedia: async (id, media) => (await transports.forChannel(id)?.sendMedia(id, media)) ?? {
|
|
241
|
+
ok: false,
|
|
242
|
+
error: "This channel cannot receive attachments. Tell the user the file's path on the server instead.",
|
|
243
|
+
},
|
|
244
|
+
}),
|
|
245
|
+
});
|
|
246
|
+
/**
|
|
247
|
+
* The channel's runner, or `undefined` when it is not bound to an available desk — the runtime
|
|
248
|
+
* never builds a runner (or a directory) for an unbound channel (INV-2).
|
|
249
|
+
*/
|
|
97
250
|
const getRunner = (channelId) => {
|
|
251
|
+
const resolution = deskRuntime.resolve(channelId);
|
|
252
|
+
if (resolution.kind !== "bound")
|
|
253
|
+
return undefined;
|
|
254
|
+
const { conversation } = resolution;
|
|
98
255
|
const existing = channelRunners.get(channelId);
|
|
99
|
-
if (existing) {
|
|
256
|
+
if (existing && existing.conversation.desk === conversation.desk) {
|
|
100
257
|
// Re-insert to move this channel to the end (most-recently-used) of the Map's
|
|
101
258
|
// iteration order, which evictIdleRunnersOverCap relies on.
|
|
102
259
|
channelRunners.delete(channelId);
|
|
103
260
|
channelRunners.set(channelId, existing);
|
|
104
261
|
return existing;
|
|
105
262
|
}
|
|
106
|
-
const
|
|
107
|
-
const runner = createRunner(channelId, channelDir, {
|
|
108
|
-
jobManager: jobs.get(channelId),
|
|
109
|
-
runManager: runs.get(channelId),
|
|
110
|
-
appHomeDir: options.paths.appHomeDir,
|
|
111
|
-
authConfigPath: options.paths.authConfigPath,
|
|
112
|
-
modelsConfigPath: options.paths.modelsConfigPath,
|
|
113
|
-
settingsManager: runtimeSettingsManager,
|
|
114
|
-
onSessionEvent: options.observer,
|
|
115
|
-
// The DingTalk bot is the media sender for this transport; enables `send_media`.
|
|
116
|
-
// `bot` is defined below in this same scope and initialized before any message
|
|
117
|
-
// (and thus any getRunner call) can arrive.
|
|
118
|
-
mediaSender: bot,
|
|
119
|
-
});
|
|
263
|
+
const runner = createRunner(conversation, { ...runnerPaths(conversation, channelId), getTaskControl });
|
|
120
264
|
channelRunners.set(channelId, runner);
|
|
121
265
|
void evictIdleRunnersOverCap(channelRunners);
|
|
122
266
|
return runner;
|
|
123
267
|
};
|
|
124
268
|
const isShuttingDown = () => shuttingDown;
|
|
125
269
|
const getDurableDispatch = () => durableDispatch;
|
|
126
|
-
// `
|
|
127
|
-
// task driver's own `notify` needs) — these two closures resolve them lazily, the same way
|
|
128
|
-
// `getRunner` above already resolves `bot` before its own declaration: nothing here calls
|
|
129
|
-
// through them until long after the whole function has finished setting up.
|
|
270
|
+
// `jobs`/`runs`/`taskLane` are declared further down; these closures resolve them lazily.
|
|
130
271
|
const getJobs = () => jobs;
|
|
131
272
|
const getRuns = () => runs;
|
|
132
|
-
const
|
|
133
|
-
const
|
|
273
|
+
const getTaskControl = () => taskLane;
|
|
274
|
+
const ingress = createIngress({
|
|
275
|
+
requestExecution: createRequestExecution({
|
|
276
|
+
workspaceDir,
|
|
277
|
+
runners: channelRunners,
|
|
278
|
+
activeTasks,
|
|
279
|
+
transports,
|
|
280
|
+
store,
|
|
281
|
+
isShuttingDown,
|
|
282
|
+
createRunner: (conversation) => createRunner(conversation, {
|
|
283
|
+
profile: { kind: "request" },
|
|
284
|
+
jobManager: jobs.get(conversation.desk),
|
|
285
|
+
runManager: runs.get(conversation.desk),
|
|
286
|
+
appHomeDir,
|
|
287
|
+
workspaceDir,
|
|
288
|
+
authConfigPath: options.paths.authConfigPath,
|
|
289
|
+
modelsConfigPath: options.paths.modelsConfigPath,
|
|
290
|
+
settingsManager: runtimeSettingsManager,
|
|
291
|
+
onSessionEvent: options.observer,
|
|
292
|
+
}),
|
|
293
|
+
}),
|
|
134
294
|
options,
|
|
295
|
+
transports,
|
|
135
296
|
store,
|
|
136
297
|
channelRunners,
|
|
137
298
|
sessionResetChains,
|
|
@@ -140,52 +301,65 @@ export async function createRuntimeContext(options) {
|
|
|
140
301
|
channelIndex,
|
|
141
302
|
archiveIncomingMessage,
|
|
142
303
|
getRunner,
|
|
304
|
+
resolveChannel: (channelId) => deskRuntime.resolve(channelId),
|
|
305
|
+
ensureBinding: (channelId, desk) => deskRuntime.ensureDefaultBinding(channelId, desk),
|
|
306
|
+
unbind: (channelId) => deskRuntime.unbind(channelId),
|
|
307
|
+
deskPort: (channelId) => ({
|
|
308
|
+
list: async () => buildDeskList(await listDesks(workspaceDir), deskRuntime.bindingTable(), deskRuntime.boundDesk(channelId), labelOf),
|
|
309
|
+
channelIndexPath: join(workspaceDir, CHANNELS_INDEX_FILENAME),
|
|
310
|
+
create: (name) => deskRuntime.create(name),
|
|
311
|
+
bind: (name) => deskRuntime.bind(channelId, name),
|
|
312
|
+
}),
|
|
313
|
+
describeChannel,
|
|
143
314
|
cliVersion,
|
|
144
315
|
startedAt,
|
|
145
316
|
isShuttingDown,
|
|
146
317
|
getDurableDispatch,
|
|
147
318
|
getJobs,
|
|
148
319
|
getRuns,
|
|
149
|
-
|
|
320
|
+
getTaskControl,
|
|
321
|
+
pushTo,
|
|
150
322
|
});
|
|
151
|
-
const
|
|
152
|
-
? options.createBot(handler, options.dingtalkConfig)
|
|
153
|
-
: new DingTalkBot(handler, options.dingtalkConfig);
|
|
154
|
-
const dispatchStateDir = join(options.paths.appHomeDir, "state", "dispatch");
|
|
323
|
+
const dispatchStateDir = join(appHomeDir, "state", "dispatch");
|
|
155
324
|
durableDispatch = new DurableDispatchService({
|
|
325
|
+
intervalMs: options.dispatchIntervalMs,
|
|
156
326
|
stateDir: dispatchStateDir,
|
|
157
|
-
bot,
|
|
158
|
-
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
// inspection until a human clears it.
|
|
327
|
+
bot: ingress,
|
|
328
|
+
isReachable: (channelId) => transports.isReachable(channelId),
|
|
329
|
+
// A structured wake that keeps failing before it can mark itself complete would otherwise
|
|
330
|
+
// redeliver forever. Surface it once instead of looping silently; the record stays on disk
|
|
331
|
+
// for inspection until a human clears it. Like every background notice, only to a channel
|
|
332
|
+
// still bound to the wake's desk (D7).
|
|
162
333
|
onExhausted: async (record) => {
|
|
163
334
|
log.logEvent("warn", "dispatch.exhausted", "Dispatch exhausted", {
|
|
164
335
|
ctx: { channelId: record.event.channelId },
|
|
165
336
|
details: record.event.text.slice(0, 500),
|
|
166
|
-
fields: { dispatchId: record.id, deliveries: record.deliveries, producer: record.event.
|
|
337
|
+
fields: { dispatchId: record.id, deliveries: record.deliveries, producer: record.event.producer },
|
|
167
338
|
});
|
|
168
|
-
await
|
|
339
|
+
await deskRuntime.sendFromDesk(record.event.desk, record.event.channelId, renderDispatchExhaustedNotice(record, dispatchStateDir));
|
|
169
340
|
},
|
|
170
341
|
});
|
|
171
|
-
|
|
172
|
-
//
|
|
173
|
-
// can start one, then re-adopt whatever survived the last shutdown (spec 031, D6).
|
|
342
|
+
// Background jobs and delegation runs are owned per desk (spec 058, D15); their completion wakes
|
|
343
|
+
// pass the producer-side binding check before they are dispatched.
|
|
174
344
|
const jobs = createJobRuntime(executor, {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
345
|
+
fileStore,
|
|
346
|
+
jobsStateDir: join(appHomeDir, "state", "jobs"),
|
|
347
|
+
workspaceDir,
|
|
348
|
+
dispatch,
|
|
349
|
+
isBoundTo,
|
|
350
|
+
onTaskInput: (desk, taskId) => taskLane.inputAvailable(desk, taskId),
|
|
178
351
|
...(options.jobSweepIntervalMs ? { sweepIntervalMs: options.jobSweepIntervalMs } : {}),
|
|
179
352
|
});
|
|
180
|
-
// Delegation runs get the same treatment (spec 040, D1/D7): persistence root, wake delivery,
|
|
181
|
-
// and the usage/archive authority, wired before any turn can start a run.
|
|
182
353
|
const runs = createSubAgentRuntime({
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
354
|
+
adoptedCheckIntervalMs: options.adoptedRunCheckIntervalMs,
|
|
355
|
+
stateDir: join(appHomeDir, "state", "subagent-runs"),
|
|
356
|
+
workspaceDir,
|
|
357
|
+
dispatch,
|
|
358
|
+
isBoundTo,
|
|
359
|
+
onTaskInput: (desk, taskId) => taskLane.inputAvailable(desk, taskId),
|
|
360
|
+
// A best-effort out-of-band notice, independent of the completion wake. `notices: "off"`
|
|
361
|
+
// (settings.json) restores the silent behavior.
|
|
362
|
+
notify: (desk, channelId, notice) => {
|
|
189
363
|
const level = runtimeSettingsManager.getDelegationSettings().notices;
|
|
190
364
|
if (level === "off")
|
|
191
365
|
return;
|
|
@@ -193,68 +367,79 @@ export async function createRuntimeContext(options) {
|
|
|
193
367
|
return;
|
|
194
368
|
const text = renderRunNotice(notice);
|
|
195
369
|
if (text)
|
|
196
|
-
void
|
|
370
|
+
void deskRuntime.sendFromDesk(desk, channelId, text);
|
|
197
371
|
},
|
|
198
372
|
ledger: getUsageLedger(),
|
|
199
373
|
store,
|
|
200
374
|
});
|
|
375
|
+
// Producers can complete during restore; construct their scoped consumer before observing them.
|
|
376
|
+
// `tools.json` is re-read on every driver tick — and a tick follows every turn — so cache the
|
|
377
|
+
// parse behind the file's change token.
|
|
378
|
+
let cachedToolsStamp;
|
|
379
|
+
let cachedTasksEnabled = true;
|
|
380
|
+
const tasksToolEnabled = () => {
|
|
381
|
+
const stamp = fileStamp(getToolsConfigPath(appHomeDir));
|
|
382
|
+
if (stamp !== cachedToolsStamp) {
|
|
383
|
+
cachedToolsStamp = stamp;
|
|
384
|
+
cachedTasksEnabled = loadToolsConfig(appHomeDir).tools.tasks.enabled;
|
|
385
|
+
}
|
|
386
|
+
return cachedTasksEnabled;
|
|
387
|
+
};
|
|
388
|
+
const taskLane = new TaskLane({
|
|
389
|
+
getActiveDesks: () => deskRuntime.activeDesks(),
|
|
390
|
+
getDeskDir: (desk) => getDeskDir(workspaceDir, desk),
|
|
391
|
+
isBoundTo,
|
|
392
|
+
isReachable: (channelId) => transports.isReachable(channelId),
|
|
393
|
+
// One runner per executing task, built from the task's own report channel (spec 064, D13).
|
|
394
|
+
createTaskRunner: (target) => {
|
|
395
|
+
const resolution = deskRuntime.resolve(target.channelId);
|
|
396
|
+
if (resolution.kind !== "bound" || resolution.conversation.desk !== target.desk) {
|
|
397
|
+
throw new Error(`Task ${target.taskId}: report channel ${target.channelId} is not bound to desk ${target.desk}`);
|
|
398
|
+
}
|
|
399
|
+
return createRunner(resolution.conversation, {
|
|
400
|
+
...runnerPaths(resolution.conversation, target.channelId),
|
|
401
|
+
profile: {
|
|
402
|
+
kind: "task",
|
|
403
|
+
sessionPath: taskSessionPath(target.deskDir, target.taskId),
|
|
404
|
+
session: target.session,
|
|
405
|
+
},
|
|
406
|
+
});
|
|
407
|
+
},
|
|
408
|
+
getRuns: (desk) => runs.get(desk),
|
|
409
|
+
getJobs: (desk) => jobs.get(desk),
|
|
410
|
+
store,
|
|
411
|
+
deliver: async (desk, channelId, text) => {
|
|
412
|
+
const delivered = await deskRuntime.sendFromDesk(desk, channelId, text);
|
|
413
|
+
if (delivered)
|
|
414
|
+
await store.logBotResponse(channelId, text, Date.now().toString());
|
|
415
|
+
return delivered;
|
|
416
|
+
},
|
|
417
|
+
isEnabled: tasksToolEnabled,
|
|
418
|
+
activeTasks,
|
|
419
|
+
onStep: options.onTaskStep,
|
|
420
|
+
});
|
|
201
421
|
// Admission (bot.start() below) must not open until every persisted job and run is back in
|
|
202
|
-
// memory
|
|
203
|
-
// and durableDispatch's redelivery of a pending completion wake would find no record to claim.
|
|
204
|
-
// Spec 042 D11: `restoreChannelJobs` used to be a bare `void` while `restoreAllSubAgentRuns`
|
|
205
|
-
// was already awaited — the same admission race P0-1 closed for delegation runs was still open
|
|
206
|
-
// for background jobs.
|
|
422
|
+
// memory, and restore is independent of bindings (D6): a dormant desk's runs still settle.
|
|
207
423
|
await jobs.restore();
|
|
208
424
|
await runs.restore();
|
|
209
425
|
runs.start();
|
|
210
|
-
//
|
|
211
|
-
|
|
212
|
-
// every attempt (F3) until a human ran /new. Runs before bot.start() for the same reason as
|
|
213
|
-
// the job/run restores above: admission must see a structurally legal session, not a partial one.
|
|
214
|
-
const recoveryReport = await scanWorkspaceForInterruptedTurns(options.paths.workspaceDir, {
|
|
215
|
-
api: defaultModel.api,
|
|
216
|
-
provider: defaultModel.provider,
|
|
217
|
-
model: defaultModel.id,
|
|
218
|
-
});
|
|
219
|
-
if (recoveryReport.repaired.length > 0) {
|
|
220
|
-
log.logWarn("runtime.recovery.repaired", "Interrupted turns repaired on restart", {
|
|
221
|
-
fields: {
|
|
222
|
-
repaired: recoveryReport.repaired.length,
|
|
223
|
-
scanned: recoveryReport.scanned,
|
|
224
|
-
channels: recoveryReport.repaired.map((r) => r.channelDir),
|
|
225
|
-
},
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
if (recoveryReport.blocked.length > 0) {
|
|
229
|
-
log.logWarn("runtime.recovery.blocked", "Channels with an unrecoverable session will refuse new turns", {
|
|
230
|
-
reason: recoveryReport.blocked.map((b) => `${b.channelDir}: ${b.reason}`).join("; "),
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
const eventsWatcher = options.createEventsWatcher
|
|
234
|
-
? options.createEventsWatcher(options.paths.workspaceDir, bot, executor, options.paths.eventHistoryPath)
|
|
235
|
-
: createEventsWatcher(options.paths.workspaceDir, bot, executor, loadSecurityConfigWithDiagnostics(options.paths.appHomeDir).config.commandGuard, options.paths.eventHistoryPath, (event) => durableDispatch?.dispatch(event) ?? false, createTaskSpawner({
|
|
236
|
-
getChannelDir: (channelId) => getChannelDir(options.paths.workspaceDir, channelId),
|
|
237
|
-
nudge: () => getTaskDriver().nudge?.(),
|
|
238
|
-
notify: (channelId, text) => bot.sendPlain(channelId, text),
|
|
239
|
-
}));
|
|
426
|
+
// Activation repairs each bound desk's conversations before its channels can take traffic.
|
|
427
|
+
await deskRuntime.activateBound();
|
|
240
428
|
const memoryMaintenanceScheduler = options.createMemoryMaintenanceScheduler
|
|
241
429
|
? options.createMemoryMaintenanceScheduler()
|
|
242
430
|
: new MemoryMaintenanceScheduler({
|
|
243
|
-
appHomeDir
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
//
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
getRuntimeContext: async (channelId) => {
|
|
251
|
-
const runner = channelRunners.get(channelId);
|
|
252
|
-
if (runner) {
|
|
431
|
+
appHomeDir,
|
|
432
|
+
getConversations: () => deskRuntime.boundConversations(),
|
|
433
|
+
// Conversations active this boot reuse their runner's in-memory context; every other one
|
|
434
|
+
// gets a lightweight disk-backed context instead of resurrecting a full runner.
|
|
435
|
+
getRuntimeContext: async (conversation) => {
|
|
436
|
+
const runner = channelRunners.get(conversation.channelId);
|
|
437
|
+
if (runner && runner.conversation.desk === conversation.desk) {
|
|
253
438
|
return runner.getMemoryMaintenanceContext();
|
|
254
439
|
}
|
|
255
440
|
return loadDetachedMaintenanceContext({
|
|
256
|
-
|
|
257
|
-
|
|
441
|
+
conversation,
|
|
442
|
+
workspaceDir,
|
|
258
443
|
authConfigPath: options.paths.authConfigPath,
|
|
259
444
|
modelsConfigPath: options.paths.modelsConfigPath,
|
|
260
445
|
settingsManager: runtimeSettingsManager,
|
|
@@ -267,37 +452,15 @@ export async function createRuntimeContext(options) {
|
|
|
267
452
|
},
|
|
268
453
|
intervalMs: options.memoryMaintenanceSchedulerIntervalMs,
|
|
269
454
|
});
|
|
270
|
-
// `tools.json` is re-read on every driver tick — and a tick follows every turn — so cache the
|
|
271
|
-
// parse behind the file's change token.
|
|
272
|
-
let cachedToolsStamp;
|
|
273
|
-
let cachedTasksEnabled = true;
|
|
274
|
-
const tasksToolEnabled = () => {
|
|
275
|
-
const stamp = fileStamp(getToolsConfigPath(options.paths.appHomeDir));
|
|
276
|
-
if (stamp !== cachedToolsStamp) {
|
|
277
|
-
cachedToolsStamp = stamp;
|
|
278
|
-
cachedTasksEnabled = loadToolsConfig(options.paths.appHomeDir).tools.tasks.enabled;
|
|
279
|
-
}
|
|
280
|
-
return cachedTasksEnabled;
|
|
281
|
-
};
|
|
282
|
-
const taskDriver = options.createTaskDriver
|
|
283
|
-
? options.createTaskDriver()
|
|
284
|
-
: new TaskDriver({
|
|
285
|
-
workspaceDir: options.paths.workspaceDir,
|
|
286
|
-
getKnownChannelIds: () => channelRunners.keys(),
|
|
287
|
-
isChannelActive: (channelId) => channelRunners.get(channelId)?.isBusy() ?? false,
|
|
288
|
-
dispatch: (event) => durableDispatch?.dispatch(event) ?? false,
|
|
289
|
-
onDispatch: options.onTaskDriverDispatch,
|
|
290
|
-
notify: (receipt) => bot.sendPlain(receipt.channelId, receipt.text),
|
|
291
|
-
isEnabled: tasksToolEnabled,
|
|
292
|
-
});
|
|
293
455
|
const shutdownWithReason = createShutdown({
|
|
294
|
-
|
|
456
|
+
taskLane,
|
|
295
457
|
getDurableDispatch,
|
|
296
458
|
memoryMaintenanceScheduler,
|
|
297
|
-
|
|
459
|
+
deskRuntime,
|
|
298
460
|
runs,
|
|
299
461
|
jobs,
|
|
300
|
-
|
|
462
|
+
transports,
|
|
463
|
+
ingress,
|
|
301
464
|
store,
|
|
302
465
|
channelIndex,
|
|
303
466
|
channelRunners,
|
|
@@ -305,6 +468,7 @@ export async function createRuntimeContext(options) {
|
|
|
305
468
|
markShuttingDown: () => {
|
|
306
469
|
shuttingDown = true;
|
|
307
470
|
},
|
|
471
|
+
releaseDaemonLock: () => daemonLock.release(),
|
|
308
472
|
});
|
|
309
473
|
if (registerSignalHandlers) {
|
|
310
474
|
process.once("SIGINT", () => {
|
|
@@ -319,24 +483,20 @@ export async function createRuntimeContext(options) {
|
|
|
319
483
|
});
|
|
320
484
|
}
|
|
321
485
|
if (startServices) {
|
|
322
|
-
|
|
323
|
-
// on the v5 layout (spec 052, D12). Marker-gated and awaited: the pass writes event
|
|
324
|
-
// templates the watcher is about to load, so the services must not start underneath it.
|
|
325
|
-
// A failed or partial conversion throws and aborts startup: nothing may run on half-migrated state.
|
|
326
|
-
await migrateTasksToV5(options.paths.workspaceDir, join(options.paths.appHomeDir, "state"));
|
|
327
|
-
eventsWatcher.start();
|
|
486
|
+
deskRuntime.startServices();
|
|
328
487
|
memoryMaintenanceScheduler.start();
|
|
329
|
-
|
|
488
|
+
taskLane.start();
|
|
330
489
|
durableDispatch.start();
|
|
331
|
-
|
|
490
|
+
await transports.startAll(ingress);
|
|
332
491
|
}
|
|
333
492
|
return {
|
|
334
|
-
|
|
493
|
+
ingress,
|
|
494
|
+
transports,
|
|
335
495
|
jobs,
|
|
336
496
|
runs,
|
|
497
|
+
desks: deskRuntime,
|
|
337
498
|
store,
|
|
338
|
-
|
|
339
|
-
taskDriver,
|
|
499
|
+
taskLane,
|
|
340
500
|
memoryMaintenance: memoryMaintenanceScheduler,
|
|
341
501
|
shutdown: shutdownWithReason,
|
|
342
502
|
};
|
|
@@ -350,27 +510,72 @@ export async function bootstrap(argv, options = {}) {
|
|
|
350
510
|
const bootstrapResult = bootstrapAppHome(paths);
|
|
351
511
|
printBootstrapSummary(bootstrapResult, io, paths);
|
|
352
512
|
// A freshly written template is the expected first-run outcome, not a failure: guide and exit 0.
|
|
353
|
-
// A template that exists but is still unfilled is caught by `
|
|
513
|
+
// A template that exists but is still unfilled is caught by the transport loader (`loadTransports`) and exits 1.
|
|
354
514
|
if (bootstrapResult.channelTemplateCreated) {
|
|
355
515
|
printFirstRunGuide(io, paths);
|
|
356
516
|
throw new BootstrapExitError(0);
|
|
357
517
|
}
|
|
358
|
-
const dingtalkConfig = loadConfig(paths, io);
|
|
359
|
-
dingtalkConfig.stateDir = paths.workspaceDir;
|
|
360
518
|
const { settingsManager } = prepareAppServices(paths);
|
|
361
519
|
log.logStartup(paths.workspaceDir);
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
520
|
+
let runtime;
|
|
521
|
+
try {
|
|
522
|
+
runtime = await createRuntimeContext({
|
|
523
|
+
paths,
|
|
524
|
+
...(options.transports ? { transports: options.transports } : {}),
|
|
525
|
+
registerSignalHandlers,
|
|
526
|
+
startServices,
|
|
527
|
+
settingsManager,
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
catch (error) {
|
|
531
|
+
if (!(error instanceof StartupRefusal))
|
|
532
|
+
throw error;
|
|
533
|
+
io.error(error.message);
|
|
534
|
+
throw new BootstrapExitError(1);
|
|
535
|
+
}
|
|
369
536
|
return {
|
|
370
|
-
bot: runtime.bot,
|
|
371
537
|
store: runtime.store,
|
|
372
538
|
shutdown: async () => {
|
|
373
539
|
await runtime.shutdown("manual");
|
|
374
540
|
},
|
|
375
541
|
};
|
|
376
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* Start the runtime for `pipiclaw tui` when no daemon is running: only the Web API's local socket
|
|
545
|
+
* is switched on (the terminal is its client), whatever `channel.json` says. Returns `undefined`
|
|
546
|
+
* when another process already holds the app home — a daemon is running and the terminal should
|
|
547
|
+
* connect to it. The lock is taken exactly once and handed to the runtime.
|
|
548
|
+
*/
|
|
549
|
+
export async function bootstrapEmbedded(paths, io) {
|
|
550
|
+
printBootstrapSummary(bootstrapAppHome(paths), io, paths);
|
|
551
|
+
const lock = await tryAcquireDaemonLock(paths.appHomeDir);
|
|
552
|
+
if (lock.kind === "held")
|
|
553
|
+
return undefined;
|
|
554
|
+
// The full-screen terminal owns stdout: the runtime logs to its file sink only.
|
|
555
|
+
log.setConsoleLoggingEnabled(false);
|
|
556
|
+
const { settingsManager } = prepareAppServices(paths);
|
|
557
|
+
log.logStartup(paths.workspaceDir);
|
|
558
|
+
const { WebApiTransport } = await import("../webapi/transport.js");
|
|
559
|
+
let runtime;
|
|
560
|
+
try {
|
|
561
|
+
runtime = await createRuntimeContext({
|
|
562
|
+
paths,
|
|
563
|
+
daemonLock: lock.handle,
|
|
564
|
+
transports: [
|
|
565
|
+
new WebApiTransport({
|
|
566
|
+
config: { socket: true, keys: [] },
|
|
567
|
+
stateDir: join(paths.appHomeDir, "state", "webapi"),
|
|
568
|
+
audit: securityAudit(paths),
|
|
569
|
+
}),
|
|
570
|
+
],
|
|
571
|
+
registerSignalHandlers: false,
|
|
572
|
+
startServices: true,
|
|
573
|
+
settingsManager,
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
catch (error) {
|
|
577
|
+
await lock.handle.release();
|
|
578
|
+
throw error;
|
|
579
|
+
}
|
|
580
|
+
return { stop: () => runtime.shutdown("manual") };
|
|
581
|
+
}
|