@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
|
@@ -7,10 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { Agent } from "@earendil-works/pi-agent-core";
|
|
9
9
|
import { streamSimple } from "@earendil-works/pi-ai/compat";
|
|
10
|
-
import { AgentSession, AgentSessionRuntime,
|
|
11
|
-
import {
|
|
12
|
-
import { dirname, join } from "path";
|
|
13
|
-
import { commitActiveSessionRef, resolveActiveSessionFile } from "../../channel/active-session-store.js";
|
|
10
|
+
import { AgentSession, AgentSessionRuntime, DefaultResourceLoader, } from "@earendil-works/pi-coding-agent";
|
|
11
|
+
import { commitActiveSessionRef } from "../../channel/active-session-store.js";
|
|
14
12
|
import { loadToolsConfigWithDiagnostics } from "../../config/tools.js";
|
|
15
13
|
import * as log from "../../log.js";
|
|
16
14
|
import { handleMemoryCommand } from "../../memory/commands.js";
|
|
@@ -18,23 +16,28 @@ import { hasMemoryBootstrapBlock } from "../../memory/render.js";
|
|
|
18
16
|
import { getApiKeyForModel } from "../../models/api-keys.js";
|
|
19
17
|
import { findExactModelReferenceMatch, hasKnownModelPricing } from "../../models/reference.js";
|
|
20
18
|
import { createModelRuntime, resolveInitialModel, wrapModelRegistry } from "../../models/runtime.js";
|
|
21
|
-
import { formatConfigDiagnostic } from "../../shared/config-diagnostic.js";
|
|
22
19
|
import { errorMessage } from "../../shared/text-utils.js";
|
|
23
20
|
import { isRecord } from "../../shared/type-guards.js";
|
|
24
21
|
import { withTimeout } from "../../shared/with-timeout.js";
|
|
25
|
-
import { loadPipiclawSkills
|
|
22
|
+
import { loadPipiclawSkills } from "../../skills/loader.js";
|
|
23
|
+
import { getSkillRoots } from "../../skills/roots.js";
|
|
26
24
|
import { discoverSubAgents } from "../../subagents/discovery.js";
|
|
27
|
-
import {
|
|
25
|
+
import { withExecutionTrace } from "../../tools/contract/execution-trace.js";
|
|
28
26
|
import { createPipiclawTools } from "../../tools/index.js";
|
|
29
27
|
import { buildPipiclawSystemPrompt } from "../prompt/builder.js";
|
|
30
28
|
import { createPromptBoundaryExtension } from "../prompt/extension.js";
|
|
31
29
|
import { measureToolSchemas, TOOL_SCHEMA_TARGET_UNITS, toolSchemaBudgetWarning } from "../prompt/manifest.js";
|
|
32
30
|
import { loadPlaybooks, loadWorkspacePromptResources } from "../prompt/resources.js";
|
|
33
31
|
import { createCommandExtension } from "./command-extension.js";
|
|
32
|
+
import { SessionCompaction } from "./compaction.js";
|
|
33
|
+
import { RequestContextInput } from "./context-input.js";
|
|
34
34
|
import { getLastAssistantUsage, isAutoCompactionEndEvent } from "./event-guards.js";
|
|
35
|
+
import { SessionExecutionTrace } from "./execution-trace.js";
|
|
36
|
+
import { requestTools } from "./request-tools.js";
|
|
35
37
|
import { asSdkSettingsManager, DEFAULT_MAIN_THINKING_LEVEL, initializeThinkingLevelCompat, setSessionBaseToolsOverride, } from "./session-adapter.js";
|
|
36
38
|
import { handleSessionEvent } from "./session-events.js";
|
|
37
39
|
import { SessionResourceGate } from "./session-resource-gate.js";
|
|
40
|
+
import { reportConfigDiagnostics, reportSettingsDiagnostics } from "./settings-diagnostics.js";
|
|
38
41
|
const MODEL_REGISTRY_REFRESH_TIMEOUT_MS = 15_000;
|
|
39
42
|
const SESSION_RELOAD_TIMEOUT_MS = 30_000;
|
|
40
43
|
const CONTEXT_FAULT_MESSAGE = "会话上下文保存失败。请让部署者检查服务器存储后发送 /new 重新开启会话。";
|
|
@@ -48,23 +51,10 @@ function plainTextOf(content) {
|
|
|
48
51
|
.map((part) => (isRecord(part) && part.type === "text" && typeof part.text === "string" ? part.text : ""))
|
|
49
52
|
.join("\n");
|
|
50
53
|
}
|
|
51
|
-
/** Task sessions live under `<channelDir>/tasks/.sessions/`; nothing else may be mistaken for one. */
|
|
52
|
-
function isTaskSessionPath(sessionFile) {
|
|
53
|
-
return sessionFile?.replace(/\\/g, "/").includes(`/${TASK_SESSIONS_DIRNAME}/`) === true;
|
|
54
|
-
}
|
|
55
|
-
/** Surface settings.json load errors (once drained) as warnings; shared by construction and reload. */
|
|
56
|
-
export function reportSettingsDiagnostics(settingsManager, channelId, appHomeDir) {
|
|
57
|
-
for (const { scope, error } of settingsManager.drainErrors()) {
|
|
58
|
-
log.logWarn("config.settings.load_failed", "Settings load failed", {
|
|
59
|
-
channelId,
|
|
60
|
-
reason: error.message,
|
|
61
|
-
fields: { scope, path: join(appHomeDir, "settings.json") },
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
54
|
export class SessionHost {
|
|
66
55
|
constructor(deps) {
|
|
67
56
|
this.deps = deps;
|
|
57
|
+
this.contextInput = new RequestContextInput();
|
|
68
58
|
/**
|
|
69
59
|
* Flips true only once `initializeSession` has fully assigned `this.session`
|
|
70
60
|
* and loaded its resources. Synchronous dispatch-path callers (`isKnownSlashCommand`)
|
|
@@ -73,19 +63,29 @@ export class SessionHost {
|
|
|
73
63
|
*/
|
|
74
64
|
this.sessionInitialized = false;
|
|
75
65
|
this.currentTools = [];
|
|
66
|
+
this.retired = false;
|
|
76
67
|
this.firstTurnMemoryBootstrapPending = true;
|
|
77
68
|
/** Mirror of `tools.tasks.enabled` from the last tools-config load (see buildRuntimeTools). */
|
|
78
69
|
this.tasksEnabled = true;
|
|
79
70
|
this.contextFaults = new WeakSet();
|
|
80
|
-
this.
|
|
81
|
-
this.
|
|
71
|
+
this.conversation = deps.conversation;
|
|
72
|
+
this.channelId = deps.conversation.channelId;
|
|
73
|
+
this.deskDir = deps.conversation.deskDir;
|
|
74
|
+
this.conversationDir = deps.conversation.conversationDir;
|
|
75
|
+
this.trace = new SessionExecutionTrace(deps.profile, () => ({
|
|
76
|
+
desk: this.conversation.desk,
|
|
77
|
+
channelId: this.channelId,
|
|
78
|
+
conversation: this.conversationDir,
|
|
79
|
+
session: this.session?.sessionManager.getSessionId(),
|
|
80
|
+
}));
|
|
82
81
|
this.workspaceDir = deps.workspaceDir;
|
|
82
|
+
this.describeConversation = deps.describeConversation;
|
|
83
83
|
this.appHomeDir = deps.appHomeDir;
|
|
84
84
|
this.authConfigPath = deps.authConfigPath;
|
|
85
85
|
this.modelsConfigPath = deps.modelsConfigPath;
|
|
86
86
|
this.onSessionEvent = deps.onSessionEvent;
|
|
87
|
-
this.
|
|
88
|
-
this.
|
|
87
|
+
this.sendMedia = deps.sendMedia;
|
|
88
|
+
this.cwd = deps.cwd;
|
|
89
89
|
this.settingsManager = deps.settingsManager;
|
|
90
90
|
this.loadSecurityConfig = deps.loadSecurityConfig;
|
|
91
91
|
this.executor = deps.executor;
|
|
@@ -96,6 +96,20 @@ export class SessionHost {
|
|
|
96
96
|
this.models = deps.models;
|
|
97
97
|
this.ledger = deps.ledger;
|
|
98
98
|
this.currentSkills = deps.initialSkills;
|
|
99
|
+
this.compaction = new SessionCompaction({
|
|
100
|
+
conversation: this.conversation,
|
|
101
|
+
getSession: () => this.session,
|
|
102
|
+
getRuntime: () => this.modelRuntime,
|
|
103
|
+
preserveMemory: (event) => this.memoryLifecycle.prepareCompaction(event),
|
|
104
|
+
ledger: this.ledger,
|
|
105
|
+
getRunState: () => this.runState,
|
|
106
|
+
isEnabled: () => this.settingsManager.getCompactionEnabled(),
|
|
107
|
+
onPersistenceFault: (session, error) => this.markContextFault(session, error, "background-compaction"),
|
|
108
|
+
onAdopt: () => {
|
|
109
|
+
this.firstTurnMemoryBootstrapPending = true;
|
|
110
|
+
void this.memoryLifecycle.resumeBoundaryReflect();
|
|
111
|
+
},
|
|
112
|
+
});
|
|
99
113
|
this.sessionResourceGate = new SessionResourceGate(async () => {
|
|
100
114
|
await this.reloadSessionResources();
|
|
101
115
|
});
|
|
@@ -106,6 +120,12 @@ export class SessionHost {
|
|
|
106
120
|
get agent() {
|
|
107
121
|
return this.session.agent;
|
|
108
122
|
}
|
|
123
|
+
importContext(context) {
|
|
124
|
+
this.contextInput.import(this.session, context);
|
|
125
|
+
}
|
|
126
|
+
async promptContext(context, submit) {
|
|
127
|
+
await this.contextInput.prompt(this.session, context, submit ? "" : (this.lastPromptBuild?.footer ?? ""), submit);
|
|
128
|
+
}
|
|
109
129
|
get sessionManager() {
|
|
110
130
|
return this.session.sessionManager;
|
|
111
131
|
}
|
|
@@ -113,12 +133,12 @@ export class SessionHost {
|
|
|
113
133
|
start(sessionManager) {
|
|
114
134
|
this.sessionReady = this.initializeSession(sessionManager);
|
|
115
135
|
}
|
|
116
|
-
markContextFault(session, error) {
|
|
136
|
+
markContextFault(session, error, stage = "fallback-context-edit") {
|
|
117
137
|
this.contextFaults.add(session);
|
|
118
138
|
log.logWarn("agent.session.context_failed", "Session context persistence failed", {
|
|
119
139
|
channelId: this.channelId,
|
|
120
140
|
reason: errorMessage(error),
|
|
121
|
-
fields: { sessionId: session.sessionManager.getSessionId(), stage
|
|
141
|
+
fields: { sessionId: session.sessionManager.getSessionId(), stage },
|
|
122
142
|
});
|
|
123
143
|
return new Error(CONTEXT_FAULT_MESSAGE, { cause: error });
|
|
124
144
|
}
|
|
@@ -135,9 +155,11 @@ export class SessionHost {
|
|
|
135
155
|
}
|
|
136
156
|
/** Stop listening to the live session and dispose it (no-op error handling is the caller's). */
|
|
137
157
|
retireLiveSession() {
|
|
158
|
+
this.retired = true;
|
|
159
|
+
this.compaction.retire();
|
|
138
160
|
this.sessionUnsubscribe?.();
|
|
139
161
|
this.sessionUnsubscribe = undefined;
|
|
140
|
-
this.session
|
|
162
|
+
this.session?.dispose();
|
|
141
163
|
}
|
|
142
164
|
/**
|
|
143
165
|
* Release the session once idle. Guards a dispose() racing construction: initializeSession
|
|
@@ -145,6 +167,7 @@ export class SessionHost {
|
|
|
145
167
|
* not have one yet.
|
|
146
168
|
*/
|
|
147
169
|
async disposeSession() {
|
|
170
|
+
this.compaction.retire();
|
|
148
171
|
await this.sessionReady;
|
|
149
172
|
this.sessionUnsubscribe?.();
|
|
150
173
|
this.sessionUnsubscribe = undefined;
|
|
@@ -175,17 +198,23 @@ export class SessionHost {
|
|
|
175
198
|
this.subAgentDiscovery = await this.refreshSubAgentDiscovery();
|
|
176
199
|
const initial = await this.createSessionRuntime(sessionManager);
|
|
177
200
|
this.session = initial.session;
|
|
201
|
+
if (this.retired) {
|
|
202
|
+
this.session.dispose();
|
|
203
|
+
throw new Error("Session generation retired");
|
|
204
|
+
}
|
|
178
205
|
this.sessionRuntime = new AgentSessionRuntime(this.session, this.createAgentSessionServices(initial.resourceLoader), async ({ sessionManager, sessionStartEvent }) => {
|
|
206
|
+
if (this.retired)
|
|
207
|
+
throw new Error("Session generation retired");
|
|
179
208
|
// `/new`, fork, and switch already wrote the target session's durable header by
|
|
180
209
|
// this point (the SDK does it synchronously before invoking this callback); commit
|
|
181
210
|
// the pointer before we rebuild and rebind to it, so a crash between "SDK created
|
|
182
211
|
// session" and "we finished rebinding" leaves the old ref (and old session)
|
|
183
212
|
// authoritative rather than an orphaned new file (spec 043, D1.3).
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
// conversation (spec 051, D3).
|
|
187
|
-
if (
|
|
188
|
-
await commitActiveSessionRef(this.
|
|
213
|
+
// Only a chat owns an active-session ref: a task session or a request must never
|
|
214
|
+
// repoint it, or `/new` and restart recovery would adopt their transcript as the
|
|
215
|
+
// conversation (spec 051, D3; spec 064, D13).
|
|
216
|
+
if (this.deps.profile.kind === "chat") {
|
|
217
|
+
await commitActiveSessionRef(this.conversationDir, sessionManager);
|
|
189
218
|
}
|
|
190
219
|
const next = await this.createSessionRuntime(sessionManager, sessionStartEvent);
|
|
191
220
|
return {
|
|
@@ -196,6 +225,11 @@ export class SessionHost {
|
|
|
196
225
|
};
|
|
197
226
|
});
|
|
198
227
|
this.sessionRuntime.setRebindSession(async (session) => {
|
|
228
|
+
this.compaction.cancel("session-rebind");
|
|
229
|
+
if (this.retired) {
|
|
230
|
+
session.dispose();
|
|
231
|
+
throw new Error("Session generation retired");
|
|
232
|
+
}
|
|
199
233
|
this.session = session;
|
|
200
234
|
await this.bindSessionExtensions();
|
|
201
235
|
this.subscribeToSessionEvents();
|
|
@@ -210,11 +244,18 @@ export class SessionHost {
|
|
|
210
244
|
this.sessionInitialized = true;
|
|
211
245
|
}
|
|
212
246
|
async reloadSessionResources() {
|
|
247
|
+
if (this.retired)
|
|
248
|
+
return;
|
|
213
249
|
this.settingsManager.reload();
|
|
214
|
-
this.
|
|
215
|
-
|
|
216
|
-
|
|
250
|
+
reportSettingsDiagnostics(this.settingsManager, this.channelId, this.appHomeDir);
|
|
251
|
+
this.currentSkills = loadPipiclawSkills({
|
|
252
|
+
workspaceDir: this.workspaceDir,
|
|
253
|
+
securityConfig: this.loadSecurityConfig().config,
|
|
254
|
+
securityContext: { agentWorkspaceDir: this.workspaceDir, cwd: this.cwd },
|
|
255
|
+
});
|
|
217
256
|
this.subAgentDiscovery = await this.refreshSubAgentDiscovery();
|
|
257
|
+
if (this.retired)
|
|
258
|
+
return;
|
|
218
259
|
this.rebuildSessionTools();
|
|
219
260
|
try {
|
|
220
261
|
await withTimeout(`[${this.channelId}] session reload`, SESSION_RELOAD_TIMEOUT_MS, () => this.session.reload());
|
|
@@ -277,27 +318,7 @@ export class SessionHost {
|
|
|
277
318
|
}
|
|
278
319
|
return discovery;
|
|
279
320
|
}
|
|
280
|
-
|
|
281
|
-
reportSettingsDiagnostics(this.settingsManager, this.channelId, this.appHomeDir);
|
|
282
|
-
}
|
|
283
|
-
reportConfigDiagnostics(diagnostics) {
|
|
284
|
-
for (const diagnostic of diagnostics) {
|
|
285
|
-
log.logWarn("config.diagnostic", formatConfigDiagnostic(diagnostic), {
|
|
286
|
-
channelId: this.channelId,
|
|
287
|
-
fields: { path: diagnostic.path },
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Build the Pipiclaw-owned system prompt (spec 025). This replaces pi's default
|
|
293
|
-
* base prompt entirely: identity, execution contract, hard invariants, the tool
|
|
294
|
-
* catalog and the workspace files are ours. pi still appends its tail (skills,
|
|
295
|
-
* date, cwd), and the boundary footer is appended after that by the prompt
|
|
296
|
-
* extension.
|
|
297
|
-
*
|
|
298
|
-
* Nothing channel-specific enters this text — that is what lets two channels in
|
|
299
|
-
* one workspace share a cached prompt prefix. Channel facts ride the turn.
|
|
300
|
-
*/
|
|
321
|
+
/** Build the shared Pipiclaw prompt; channel facts stay in turn context and pi appends its tail. */
|
|
301
322
|
buildSystemPrompt() {
|
|
302
323
|
const toolNames = this.currentTools.map((tool) => tool.name);
|
|
303
324
|
const resources = loadWorkspacePromptResources(this.workspaceDir);
|
|
@@ -338,10 +359,11 @@ export class SessionHost {
|
|
|
338
359
|
}
|
|
339
360
|
createResourceLoader() {
|
|
340
361
|
return new DefaultResourceLoader({
|
|
341
|
-
cwd: this.
|
|
362
|
+
cwd: this.cwd,
|
|
342
363
|
agentDir: this.appHomeDir,
|
|
343
364
|
settingsManager: asSdkSettingsManager(this.settingsManager),
|
|
344
365
|
extensionFactories: [
|
|
366
|
+
this.compaction.createExtensionFactory(),
|
|
345
367
|
this.memoryLifecycle.createExtensionFactory(),
|
|
346
368
|
createPromptBoundaryExtension({
|
|
347
369
|
getFooter: () => this.lastPromptBuild?.footer ?? "",
|
|
@@ -367,12 +389,9 @@ export class SessionHost {
|
|
|
367
389
|
// Manual /model switch redefines the preferred model and clears fallback state.
|
|
368
390
|
this.models.clearFallbackState();
|
|
369
391
|
},
|
|
370
|
-
refreshSessionResources:
|
|
371
|
-
await this.refreshSessionResources();
|
|
372
|
-
},
|
|
392
|
+
refreshSessionResources: () => this.refreshSessionResources(),
|
|
373
393
|
runMemoryCommand: async (args) => handleMemoryCommand({
|
|
374
|
-
|
|
375
|
-
channelDir: this.channelDir,
|
|
394
|
+
conversation: this.conversation,
|
|
376
395
|
appHomeDir: this.appHomeDir,
|
|
377
396
|
args,
|
|
378
397
|
}),
|
|
@@ -385,24 +404,23 @@ export class SessionHost {
|
|
|
385
404
|
// APPEND_SYSTEM.md, not a base append. SOUL/AGENTS are rendered as sections.
|
|
386
405
|
appendSystemPromptOverride: () => [],
|
|
387
406
|
agentsFilesOverride: () => ({ agentsFiles: [] }),
|
|
388
|
-
//
|
|
389
|
-
|
|
390
|
-
skillsOverride: (
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
log.logWarn("agent.skills.diagnostic", "Skill diagnostic", {
|
|
407
|
+
// SDK renders/expands skills; only our two-source catalog may enter the session.
|
|
408
|
+
noSkills: true,
|
|
409
|
+
skillsOverride: () => {
|
|
410
|
+
for (const diagnostic of this.currentSkills.diagnostics) {
|
|
411
|
+
log.logWarn("agent.skills.load", "Skill loading failed", {
|
|
394
412
|
channelId: this.channelId,
|
|
395
413
|
reason: diagnostic.message,
|
|
396
414
|
fields: { type: diagnostic.type, path: diagnostic.path },
|
|
397
415
|
});
|
|
398
416
|
}
|
|
399
|
-
return
|
|
417
|
+
return this.currentSkills;
|
|
400
418
|
},
|
|
401
419
|
});
|
|
402
420
|
}
|
|
403
421
|
createAgentSessionServices(resourceLoader) {
|
|
404
422
|
return {
|
|
405
|
-
cwd: this.
|
|
423
|
+
cwd: this.cwd,
|
|
406
424
|
agentDir: this.appHomeDir,
|
|
407
425
|
settingsManager: asSdkSettingsManager(this.settingsManager),
|
|
408
426
|
modelRuntime: this.modelRuntime,
|
|
@@ -440,6 +458,8 @@ export class SessionHost {
|
|
|
440
458
|
initializeThinkingLevelCompat(agent, model, sessionManager, this.settingsManager.getDefaultThinkingLevel());
|
|
441
459
|
}
|
|
442
460
|
async createSessionRuntime(sessionManager, sessionStartEvent) {
|
|
461
|
+
if (this.retired)
|
|
462
|
+
throw new Error("Session generation retired");
|
|
443
463
|
const tools = this.buildRuntimeTools();
|
|
444
464
|
const agent = new Agent({
|
|
445
465
|
initialState: {
|
|
@@ -449,21 +469,26 @@ export class SessionHost {
|
|
|
449
469
|
tools: [],
|
|
450
470
|
messages: sessionManager.buildSessionContext().messages,
|
|
451
471
|
},
|
|
452
|
-
convertToLlm,
|
|
472
|
+
convertToLlm: (messages) => this.contextInput.convert(messages),
|
|
453
473
|
getApiKey: async () => getApiKeyForModel(this.modelRegistry, this.models.activeModel),
|
|
454
|
-
streamFn:
|
|
474
|
+
streamFn: (model, context, options) => {
|
|
475
|
+
this.trace.startRequest();
|
|
476
|
+
return streamSimple(model, context, options);
|
|
477
|
+
},
|
|
455
478
|
});
|
|
456
479
|
this.initializeThinkingLevel(agent, this.models.activeModel, sessionManager);
|
|
457
480
|
const resourceLoader = this.createResourceLoader();
|
|
458
481
|
// Must precede `new AgentSession`: the session snapshots the loader's extensions in its
|
|
459
482
|
// constructor (see `loadSessionResources`).
|
|
460
483
|
await this.loadSessionResources(resourceLoader);
|
|
484
|
+
if (this.retired)
|
|
485
|
+
throw new Error("Session generation retired");
|
|
461
486
|
const sessionSettingsManager = asSdkSettingsManager(this.settingsManager);
|
|
462
487
|
const session = new AgentSession({
|
|
463
488
|
agent,
|
|
464
489
|
sessionManager,
|
|
465
490
|
settingsManager: sessionSettingsManager,
|
|
466
|
-
cwd: this.
|
|
491
|
+
cwd: this.cwd,
|
|
467
492
|
modelRuntime: this.modelRuntime,
|
|
468
493
|
resourceLoader,
|
|
469
494
|
baseToolsOverride: Object.fromEntries(tools.map((tool) => [tool.name, tool])),
|
|
@@ -473,52 +498,26 @@ export class SessionHost {
|
|
|
473
498
|
this.sessionSettingsManager = sessionSettingsManager;
|
|
474
499
|
return { session, resourceLoader };
|
|
475
500
|
}
|
|
476
|
-
/**
|
|
477
|
-
* Bind this runner to a task cycle's own session (spec 051, D3/INV-5).
|
|
478
|
-
*
|
|
479
|
-
* Task work must not accumulate in the channel's chat transcript: the one real channel on the
|
|
480
|
-
* author's machine had grown to 7.4 MB and been compacted six times because chat and two daily
|
|
481
|
-
* tasks shared it, so every compaction damaged all three at once. Swapping the bound session
|
|
482
|
-
* per turn gives each task its own bounded context while leaving turn state, `/stop`, and
|
|
483
|
-
* delivery exactly where they already are.
|
|
484
|
-
*/
|
|
485
|
-
async bindTaskSession(taskId) {
|
|
486
|
-
await this.sessionReady;
|
|
487
|
-
const path = taskSessionPath(this.channelDir, taskId);
|
|
488
|
-
await mkdir(dirname(path), { recursive: true });
|
|
489
|
-
this.taskLoop = { taskId };
|
|
490
|
-
await this.sessionRuntime.switchSession(path);
|
|
491
|
-
this.syncMemoryBootstrapPendingFromSession();
|
|
492
|
-
}
|
|
493
|
-
/** Return to the channel's chat session after a task step. Safe to call when already bound. */
|
|
494
|
-
async bindChatSession() {
|
|
495
|
-
if (!this.taskLoop)
|
|
496
|
-
return;
|
|
497
|
-
this.taskLoop = undefined;
|
|
498
|
-
await this.sessionRuntime.switchSession(join(this.channelDir, resolveActiveSessionFile(this.channelDir)));
|
|
499
|
-
this.syncMemoryBootstrapPendingFromSession();
|
|
500
|
-
}
|
|
501
501
|
/** Bootstrap presence follows canonical context, including omissions and compaction.
|
|
502
|
-
*
|
|
503
|
-
*
|
|
502
|
+
* Restarting must neither duplicate a visible bootstrap nor mistake an omitted failed input for
|
|
503
|
+
* one. Raw messages remain available to memory/recovery.
|
|
504
504
|
*/
|
|
505
505
|
syncMemoryBootstrapPendingFromSession() {
|
|
506
|
-
|
|
506
|
+
this.firstTurnMemoryBootstrapPending = !this.contextIncludes((text) => hasMemoryBootstrapBlock(text));
|
|
507
|
+
}
|
|
508
|
+
/** Whether any user message of the session's canonical context satisfies `matches` (spec 064, D15). */
|
|
509
|
+
contextIncludes(matches) {
|
|
510
|
+
return this.sessionManager.buildSessionContext().messages.some((value) => {
|
|
507
511
|
const message = value;
|
|
508
512
|
if (!isRecord(message))
|
|
509
513
|
return false;
|
|
510
|
-
return message.role === "user" &&
|
|
514
|
+
return message.role === "user" && matches(plainTextOf(message.content));
|
|
511
515
|
});
|
|
512
|
-
this.firstTurnMemoryBootstrapPending = !injected;
|
|
513
|
-
}
|
|
514
|
-
/** Which task loop this runner is currently bound to, if any. */
|
|
515
|
-
getTaskLoop() {
|
|
516
|
-
return this.taskLoop;
|
|
517
516
|
}
|
|
518
517
|
buildRuntimeTools() {
|
|
519
518
|
const securityLoad = this.loadSecurityConfig();
|
|
520
519
|
const toolsLoad = loadToolsConfigWithDiagnostics(this.appHomeDir);
|
|
521
|
-
|
|
520
|
+
reportConfigDiagnostics([...securityLoad.diagnostics, ...toolsLoad.diagnostics], this.channelId);
|
|
522
521
|
this.tasksEnabled = toolsLoad.config.tools.tasks.enabled;
|
|
523
522
|
const tools = createPipiclawTools({
|
|
524
523
|
jobManager: this.jobManager,
|
|
@@ -529,33 +528,33 @@ export class SessionHost {
|
|
|
529
528
|
getAvailableModels: () => this.modelRegistry.getAvailable(),
|
|
530
529
|
resolveApiKey: async (model) => getApiKeyForModel(this.modelRegistry, model),
|
|
531
530
|
workspaceDir: this.workspaceDir,
|
|
532
|
-
|
|
533
|
-
|
|
531
|
+
cwd: this.cwd,
|
|
532
|
+
desk: this.conversation.desk,
|
|
533
|
+
deskDir: this.deskDir,
|
|
534
534
|
channelId: this.channelId,
|
|
535
|
+
describeConversation: this.describeConversation,
|
|
535
536
|
getSubAgentDiscovery: () => this.subAgentDiscovery,
|
|
536
537
|
getSubAgentModelReference: () => this.settingsManager.getSubAgentModelReference(),
|
|
537
538
|
resolveFallbackModel: () => this.models.resolveFallbackModel(),
|
|
538
539
|
getSessionSearchSettings: () => this.settingsManager.getSessionSearchSettings(),
|
|
539
540
|
securityConfig: securityLoad.config,
|
|
540
541
|
toolsConfig: toolsLoad.config,
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
// Assistant usage only: an internal sub-agent's cost is also in `totalUsage`, and a bound
|
|
545
|
-
// one is already credited to the task when it settles.
|
|
546
|
-
getStepCost: () => ({ usd: this.runState.assistantUsage.cost.total, estimated: !this.runState.costKnown }),
|
|
542
|
+
sendMedia: this.sendMedia,
|
|
543
|
+
...(this.deps.profile.kind === "task" ? { taskSession: this.deps.profile.session } : {}),
|
|
544
|
+
...(this.deps.profile.kind === "chat" ? { taskControl: this.deps.getTaskControl?.() } : {}),
|
|
547
545
|
});
|
|
548
|
-
this.
|
|
546
|
+
const active = this.deps.profile.kind === "request" ? requestTools(tools) : tools;
|
|
547
|
+
this.currentTools = active;
|
|
549
548
|
// Tool schemas are billed with the system prompt and, unlike it, nothing trims them.
|
|
550
549
|
// Warn where the prompt's own budget diagnostics are reported, once per tool rebuild.
|
|
551
|
-
const schemas = measureToolSchemas(
|
|
550
|
+
const schemas = measureToolSchemas(active);
|
|
552
551
|
if (schemas.units > TOOL_SCHEMA_TARGET_UNITS) {
|
|
553
552
|
log.logWarn("agent.tools.schema_over_budget", "Tool schemas over budget", {
|
|
554
553
|
channelId: this.channelId,
|
|
555
554
|
reason: toolSchemaBudgetWarning(schemas),
|
|
556
555
|
});
|
|
557
556
|
}
|
|
558
|
-
return
|
|
557
|
+
return active.map((tool) => withExecutionTrace(tool, () => this.trace.fields()));
|
|
559
558
|
}
|
|
560
559
|
rebuildSessionTools() {
|
|
561
560
|
const tools = this.buildRuntimeTools();
|
|
@@ -577,6 +576,7 @@ export class SessionHost {
|
|
|
577
576
|
reason: errorMessage(err),
|
|
578
577
|
});
|
|
579
578
|
}
|
|
579
|
+
this.trace.observe(event);
|
|
580
580
|
if (isRecord(event) && event.type === "message_start") {
|
|
581
581
|
this.deps.markStreaming();
|
|
582
582
|
}
|
|
@@ -606,10 +606,8 @@ export class SessionHost {
|
|
|
606
606
|
const model = findExactModelReferenceMatch(reference, this.modelRegistry.getAvailable()).match;
|
|
607
607
|
return model ? hasKnownModelPricing(model) : false;
|
|
608
608
|
},
|
|
609
|
-
refreshSessionResources:
|
|
610
|
-
|
|
611
|
-
},
|
|
612
|
-
skillsDir: join(this.workspaceDir, "skills"),
|
|
609
|
+
refreshSessionResources: () => this.refreshSessionResources(),
|
|
610
|
+
skillsDirs: getSkillRoots(this.workspaceDir).map(({ dir }) => dir),
|
|
613
611
|
}).catch((err) => {
|
|
614
612
|
log.logWarn("agent.session.handler_failed", "Session event handler failed", {
|
|
615
613
|
channelId: this.channelId,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PipiclawSettingsManager } from "../../config/settings.js";
|
|
2
|
+
import { type ConfigDiagnostic } from "../../shared/config-diagnostic.js";
|
|
3
|
+
/** Surface settings.json load errors (once drained) as warnings; shared by construction and reload. */
|
|
4
|
+
export declare function reportSettingsDiagnostics(settingsManager: PipiclawSettingsManager, channelId: string, appHomeDir: string): void;
|
|
5
|
+
export declare function reportConfigDiagnostics(diagnostics: ConfigDiagnostic[], channelId: string): void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import * as log from "../../log.js";
|
|
3
|
+
import { formatConfigDiagnostic } from "../../shared/config-diagnostic.js";
|
|
4
|
+
/** Surface settings.json load errors (once drained) as warnings; shared by construction and reload. */
|
|
5
|
+
export function reportSettingsDiagnostics(settingsManager, channelId, appHomeDir) {
|
|
6
|
+
for (const { scope, error } of settingsManager.drainErrors()) {
|
|
7
|
+
log.logWarn("config.settings.load_failed", "Settings load failed", {
|
|
8
|
+
channelId,
|
|
9
|
+
reason: error.message,
|
|
10
|
+
fields: { scope, path: join(appHomeDir, "settings.json") },
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function reportConfigDiagnostics(diagnostics, channelId) {
|
|
15
|
+
for (const diagnostic of diagnostics) {
|
|
16
|
+
log.logWarn("config.diagnostic", formatConfigDiagnostic(diagnostic), {
|
|
17
|
+
channelId: channelId,
|
|
18
|
+
fields: { path: diagnostic.path },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -24,9 +24,12 @@ export function renderStatus(options) {
|
|
|
24
24
|
runState = "空闲";
|
|
25
25
|
}
|
|
26
26
|
const lines = [`**状态** · ${runState}`];
|
|
27
|
-
|
|
27
|
+
const snapshot = runner?.getStatusSnapshot();
|
|
28
|
+
if (runner && !snapshot) {
|
|
29
|
+
lines.push("- 模型:会话正在启动,稍后再试");
|
|
30
|
+
}
|
|
31
|
+
else if (runner && snapshot) {
|
|
28
32
|
try {
|
|
29
|
-
const snapshot = runner.getStatusSnapshot();
|
|
30
33
|
let modelLine = `- 模型:\`${snapshot.model}\`(思考档位 \`${snapshot.thinkingLevel}\`)`;
|
|
31
34
|
if (snapshot.fallback) {
|
|
32
35
|
const until = new Date(snapshot.fallback.cooldownUntilMs);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The `/stop` watchdog: a stopped turn that never ends is force-released after a grace window, so
|
|
3
3
|
* the channel does not keep reporting "a turn is already running".
|
|
4
4
|
*/
|
|
5
|
-
import type { AgentRunner } from "
|
|
5
|
+
import type { AgentRunner } from "./types.js";
|
|
6
6
|
/**
|
|
7
7
|
* Watchdog for `/stop`: release the channel if the stopped turn has not ended
|
|
8
8
|
* once the grace window elapses. Returns true when it had to force the release.
|
|
@@ -13,4 +13,6 @@ export declare function forceEndStuckTurnAfterStop(input: {
|
|
|
13
13
|
graceMs?: number;
|
|
14
14
|
pollMs?: number;
|
|
15
15
|
notify?: (text: string) => Promise<unknown>;
|
|
16
|
+
isCurrent?: () => boolean;
|
|
17
|
+
recover?: () => void;
|
|
16
18
|
}): Promise<boolean>;
|
|
@@ -9,7 +9,7 @@ import { sleepUnref } from "../shared/with-timeout.js";
|
|
|
9
9
|
* epilogue (delivery drain, session-resource reload, memory flush) ignores both
|
|
10
10
|
* and would otherwise keep the channel reporting "已有回合在运行" indefinitely.
|
|
11
11
|
*/
|
|
12
|
-
const STOP_FORCE_END_GRACE_MS =
|
|
12
|
+
const STOP_FORCE_END_GRACE_MS = 3_000;
|
|
13
13
|
const STOP_FORCE_END_POLL_MS = 250;
|
|
14
14
|
/**
|
|
15
15
|
* Watchdog for `/stop`: release the channel if the stopped turn has not ended
|
|
@@ -19,14 +19,18 @@ export async function forceEndStuckTurnAfterStop(input) {
|
|
|
19
19
|
const graceMs = input.graceMs ?? STOP_FORCE_END_GRACE_MS;
|
|
20
20
|
const pollMs = input.pollMs ?? STOP_FORCE_END_POLL_MS;
|
|
21
21
|
const deadline = Date.now() + graceMs;
|
|
22
|
-
|
|
22
|
+
const stopped = () => input.runner.isBusy() && input.runner.getTurnStatus().stopRequested && (input.isCurrent?.() ?? true);
|
|
23
|
+
while (stopped() && Date.now() < deadline) {
|
|
23
24
|
await sleepUnref(Math.min(pollMs, Math.max(1, deadline - Date.now())));
|
|
24
25
|
}
|
|
26
|
+
if (!stopped())
|
|
27
|
+
return false;
|
|
25
28
|
if (!input.runner.forceEndTurn(`/stop did not take effect within ${graceMs}ms`)) {
|
|
26
29
|
return false;
|
|
27
30
|
}
|
|
31
|
+
input.recover?.();
|
|
28
32
|
await input
|
|
29
|
-
.notify?.(`⚠️
|
|
33
|
+
.notify?.(`⚠️ 上一个回合未能及时停止,已隔离并恢复原会话。现在可以继续发消息,或使用 \`/new\`、\`/model\`。`)
|
|
30
34
|
.catch(() => undefined);
|
|
31
35
|
return true;
|
|
32
36
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Helpers for clipping over-length user input and for reading a tool result as text.
|
|
3
3
|
*/
|
|
4
|
-
import type { ProgressEntryKind } from "../types.js";
|
|
5
4
|
/**
|
|
6
5
|
* Head + tail of an over-length message, with the middle replaced by a marker.
|
|
7
6
|
*
|
|
@@ -12,5 +11,4 @@ import type { ProgressEntryKind } from "../types.js";
|
|
|
12
11
|
* in this runtime follows).
|
|
13
12
|
*/
|
|
14
13
|
export declare function clipUserInput(text: string, maxChars: number, fullTextPath?: string): string;
|
|
15
|
-
export declare function formatProgressEntry(kind: ProgressEntryKind, text: string): string;
|
|
16
14
|
export declare function extractToolResultText(result: unknown): string;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
.replace(/\r/g, "")
|
|
5
|
-
.trim();
|
|
6
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for clipping over-length user input and for reading a tool result as text.
|
|
3
|
+
*/
|
|
7
4
|
/**
|
|
8
5
|
* Head + tail of an over-length message, with the middle replaced by a marker.
|
|
9
6
|
*
|
|
@@ -25,22 +22,6 @@ export function clipUserInput(text, maxChars, fullTextPath) {
|
|
|
25
22
|
: "";
|
|
26
23
|
return `${normalized.slice(0, headChars)}\n\n[... omitted ${normalized.length - maxChars} chars${recovery} ...]\n\n${normalized.slice(-tailChars)}`;
|
|
27
24
|
}
|
|
28
|
-
export function formatProgressEntry(kind, text) {
|
|
29
|
-
const cleaned = sanitizeProgressText(text);
|
|
30
|
-
if (!cleaned)
|
|
31
|
-
return "";
|
|
32
|
-
const normalized = cleaned.replace(/\n+/g, " ").trim();
|
|
33
|
-
switch (kind) {
|
|
34
|
-
case "tool":
|
|
35
|
-
return `➜ ${normalized}`;
|
|
36
|
-
case "thinking":
|
|
37
|
-
return `✦ ${normalized}`;
|
|
38
|
-
case "error":
|
|
39
|
-
return `✕ ${normalized}`;
|
|
40
|
-
case "assistant":
|
|
41
|
-
return normalized;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
25
|
export function extractToolResultText(result) {
|
|
45
26
|
if (typeof result === "string") {
|
|
46
27
|
return result;
|
|
@@ -10,17 +10,18 @@ export declare const TASK_AGENDA_MAX_UNITS = 600;
|
|
|
10
10
|
* reference, not instruction, so it can never turn an unrelated user turn into task work.
|
|
11
11
|
*/
|
|
12
12
|
export interface TaskDigestOptions {
|
|
13
|
-
/** The
|
|
14
|
-
|
|
13
|
+
/** The desk directory; tasks live in `<deskDir>/tasks/`. */
|
|
14
|
+
deskDir: string;
|
|
15
|
+
/** The asking channel: a task delivering to another channel is marked, as it reports there. */
|
|
16
|
+
channelId?: string;
|
|
15
17
|
maxTasks: number;
|
|
16
18
|
maxChars: number;
|
|
17
19
|
/** Runtime hard cap in prompt units (spec 026 §5.3); whichever of chars/units is hit first clips. */
|
|
18
20
|
maxUnits?: number;
|
|
19
|
-
now?: number;
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* Render the in-flight task agenda, or `""` when there are no live tasks to show.
|
|
23
|
-
*
|
|
24
|
+
* Waiting and paused tasks stay visible so the model can distinguish dormant work from lost work
|
|
24
25
|
* and tell the user what each one is waiting for.
|
|
25
26
|
*/
|
|
26
27
|
export declare function buildTaskDigest(options: TaskDigestOptions): Promise<string>;
|