@oyasmi/pipiclaw 0.9.4 → 0.9.5-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +35 -31
- package/README.md +34 -30
- package/dist/agent/builtin-commands.d.ts +7 -2
- package/dist/agent/builtin-commands.js +19 -23
- package/dist/agent/channel-runner.d.ts +23 -35
- package/dist/agent/channel-runner.js +150 -89
- package/dist/agent/maintenance-context.d.ts +8 -5
- package/dist/agent/maintenance-context.js +30 -15
- package/dist/agent/prompt/manifest.js +1 -1
- package/dist/agent/prompt/resources.d.ts +1 -1
- package/dist/agent/prompt/resources.js +1 -1
- package/dist/agent/prompt/sections.js +11 -9
- package/dist/agent/prompt/types.d.ts +1 -1
- package/dist/agent/runner-factory.d.ts +6 -6
- package/dist/agent/runner-factory.js +7 -8
- package/dist/agent/session/command-extension.js +11 -0
- package/dist/agent/session/compaction-input.d.ts +6 -0
- package/dist/agent/session/compaction-input.js +75 -0
- package/dist/agent/session/compaction-snapshot.d.ts +30 -0
- package/dist/agent/session/compaction-snapshot.js +154 -0
- package/dist/agent/session/compaction-summary.d.ts +39 -0
- package/dist/agent/session/compaction-summary.js +162 -0
- package/dist/agent/session/compaction.d.ts +35 -0
- package/dist/agent/session/compaction.js +294 -0
- package/dist/agent/session/context-input.d.ts +15 -0
- package/dist/agent/session/context-input.js +82 -0
- package/dist/agent/session/context-snapshot.d.ts +11 -0
- package/dist/agent/session/context-snapshot.js +72 -0
- package/dist/agent/session/event-guards.d.ts +2 -0
- package/dist/agent/session/event-guards.js +4 -0
- package/dist/agent/session/execution-trace.d.ts +14 -0
- package/dist/agent/session/execution-trace.js +57 -0
- package/dist/agent/session/request-tools.d.ts +3 -0
- package/dist/agent/session/request-tools.js +20 -0
- package/dist/agent/session/session-adapter.d.ts +2 -1
- package/dist/agent/session/session-adapter.js +6 -3
- package/dist/agent/session/session-events.d.ts +4 -8
- package/dist/agent/session/session-events.js +80 -70
- package/dist/agent/session/session-host.d.ts +39 -61
- package/dist/agent/session/session-host.js +122 -124
- package/dist/agent/session/settings-diagnostics.d.ts +5 -0
- package/dist/agent/session/settings-diagnostics.js +21 -0
- package/dist/agent/status-render.js +5 -2
- package/dist/{runtime → agent}/stop-watchdog.d.ts +3 -1
- package/dist/{runtime → agent}/stop-watchdog.js +7 -3
- package/dist/agent/turn/progress-formatter.d.ts +1 -3
- package/dist/agent/turn/progress-formatter.js +3 -22
- package/dist/agent/turn/task-digest.d.ts +5 -4
- package/dist/agent/turn/task-digest.js +37 -34
- package/dist/agent/turn/turn-context.d.ts +12 -8
- package/dist/agent/turn/turn-context.js +27 -19
- package/dist/agent/turn/turn-finish.d.ts +18 -6
- package/dist/agent/turn/turn-finish.js +52 -77
- package/dist/agent/turn/turn-input.d.ts +2 -2
- package/dist/agent/turn/turn-input.js +4 -3
- package/dist/agent/turn/turn-output.d.ts +19 -0
- package/dist/agent/turn/turn-output.js +41 -0
- package/dist/agent/turn/turn-pipeline.d.ts +15 -10
- package/dist/agent/turn/turn-pipeline.js +86 -59
- package/dist/agent/turn/turn-prompt.d.ts +1 -1
- package/dist/agent/turn/turn-recovery.d.ts +11 -10
- package/dist/agent/turn/turn-recovery.js +14 -29
- package/dist/agent/types.d.ts +93 -24
- package/dist/agent/types.js +5 -1
- package/dist/app/auth-command.js +1 -1
- package/dist/app/home.js +34 -19
- package/dist/channel/active-session-store.d.ts +14 -12
- package/dist/channel/active-session-store.js +29 -25
- package/dist/channel/attachments.d.ts +25 -0
- package/dist/channel/attachments.js +56 -0
- package/dist/channel/channel-context.d.ts +87 -96
- package/dist/channel/channel-context.js +1 -66
- package/dist/channel/channel-event.d.ts +49 -47
- package/dist/channel/channel-event.js +6 -11
- package/dist/channel/channel-id.d.ts +22 -0
- package/dist/channel/channel-id.js +13 -0
- package/dist/channel/channel-index.d.ts +17 -34
- package/dist/channel/channel-index.js +41 -80
- package/dist/channel/config.d.ts +10 -0
- package/dist/channel/config.js +55 -0
- package/dist/channel/ingress.d.ts +93 -0
- package/dist/channel/ingress.js +5 -0
- package/dist/channel/store.d.ts +14 -16
- package/dist/channel/store.js +21 -25
- package/dist/channel/transport.d.ts +99 -0
- package/dist/channel/turn-context.d.ts +23 -0
- package/dist/channel/turn-context.js +1 -0
- package/dist/commands/catalog.d.ts +4 -7
- package/dist/commands/catalog.js +48 -49
- package/dist/commands/router.d.ts +28 -14
- package/dist/commands/router.js +30 -27
- package/dist/config/settings.d.ts +8 -14
- package/dist/config/settings.js +0 -7
- package/dist/config/tools.d.ts +2 -2
- package/dist/config/tools.js +2 -2
- package/dist/desk/bindings.d.ts +6 -0
- package/dist/desk/bindings.js +105 -0
- package/dist/desk/commands.d.ts +81 -0
- package/dist/desk/commands.js +145 -0
- package/dist/desk/default.d.ts +4 -0
- package/dist/desk/default.js +11 -0
- package/dist/desk/paths.d.ts +41 -0
- package/dist/desk/paths.js +81 -0
- package/dist/desk/registry.d.ts +17 -0
- package/dist/desk/registry.js +191 -0
- package/dist/desk/startup-error.d.ts +4 -0
- package/dist/desk/startup-error.js +7 -0
- package/dist/desk/types.d.ts +72 -0
- package/dist/desk/types.js +7 -0
- package/dist/dingtalk/bot.d.ts +20 -35
- package/dist/dingtalk/bot.js +25 -204
- package/dist/dingtalk/cards.d.ts +7 -0
- package/dist/dingtalk/cards.js +32 -2
- package/dist/dingtalk/channel-ids.d.ts +15 -0
- package/dist/dingtalk/channel-ids.js +39 -0
- package/dist/dingtalk/config.d.ts +6 -3
- package/dist/dingtalk/config.js +13 -25
- package/dist/dingtalk/connection.d.ts +1 -0
- package/dist/dingtalk/connection.js +5 -4
- package/dist/dingtalk/conversation-meta.d.ts +10 -5
- package/dist/dingtalk/conversation-meta.js +72 -50
- package/dist/dingtalk/delivery.d.ts +34 -14
- package/dist/dingtalk/delivery.js +332 -190
- package/dist/dingtalk/inbound-media.d.ts +2 -18
- package/dist/dingtalk/inbound-media.js +0 -53
- package/dist/dingtalk/inbound.d.ts +10 -11
- package/dist/dingtalk/inbound.js +12 -19
- package/dist/dingtalk/media.d.ts +9 -11
- package/dist/dingtalk/media.js +18 -31
- package/dist/dingtalk/progress.d.ts +57 -0
- package/dist/dingtalk/progress.js +199 -0
- package/dist/dingtalk/response-mode.d.ts +13 -0
- package/dist/dingtalk/response-mode.js +31 -0
- package/dist/dingtalk/transport.d.ts +47 -0
- package/dist/dingtalk/transport.js +71 -0
- package/dist/events/commands.d.ts +7 -2
- package/dist/events/commands.js +40 -22
- package/dist/events/pre-action-error.d.ts +10 -0
- package/dist/events/pre-action-error.js +10 -0
- package/dist/events/types.d.ts +20 -2
- package/dist/events/watcher.d.ts +14 -7
- package/dist/events/watcher.js +49 -26
- package/dist/file-store.d.ts +4 -0
- package/dist/file-store.js +6 -1
- package/dist/index.d.ts +4 -2
- package/dist/jobs/completion-observer.d.ts +20 -0
- package/dist/jobs/completion-observer.js +107 -0
- package/dist/jobs/completion-signal.d.ts +9 -0
- package/dist/jobs/completion-signal.js +32 -0
- package/dist/jobs/completion-wake.d.ts +14 -0
- package/dist/jobs/completion-wake.js +25 -0
- package/dist/jobs/manager.d.ts +29 -42
- package/dist/jobs/manager.js +130 -236
- package/dist/jobs/probe.d.ts +3 -0
- package/dist/jobs/probe.js +42 -0
- package/dist/jobs/record.d.ts +5 -6
- package/dist/jobs/record.js +2 -0
- package/dist/jobs/runtime.d.ts +28 -0
- package/dist/jobs/runtime.js +69 -0
- package/dist/log.d.ts +0 -1
- package/dist/log.js +1 -1
- package/dist/main.js +10 -3
- package/dist/memory/boundary-work.d.ts +19 -0
- package/dist/memory/boundary-work.js +204 -0
- package/dist/memory/commands.d.ts +4 -3
- package/dist/memory/commands.js +20 -17
- package/dist/memory/desk-memory-queue.d.ts +18 -0
- package/dist/memory/desk-memory-queue.js +33 -0
- package/dist/memory/index-budget.d.ts +3 -3
- package/dist/memory/index-budget.js +21 -18
- package/dist/memory/journal.d.ts +6 -6
- package/dist/memory/journal.js +16 -15
- package/dist/memory/lifecycle.d.ts +17 -28
- package/dist/memory/lifecycle.js +87 -147
- package/dist/memory/maintenance-state.d.ts +14 -15
- package/dist/memory/maintenance-state.js +43 -42
- package/dist/memory/reflect-job.d.ts +5 -10
- package/dist/memory/reflect-job.js +29 -44
- package/dist/memory/reflect.d.ts +6 -1
- package/dist/memory/reflect.js +44 -16
- package/dist/memory/render.d.ts +1 -1
- package/dist/memory/render.js +2 -2
- package/dist/memory/review-log.d.ts +17 -4
- package/dist/memory/review-log.js +54 -5
- package/dist/memory/scheduler.d.ts +12 -19
- package/dist/memory/scheduler.js +28 -64
- package/dist/memory/search.js +7 -4
- package/dist/memory/session-corpus.d.ts +4 -1
- package/dist/memory/session-corpus.js +70 -29
- package/dist/memory/session-search.d.ts +11 -3
- package/dist/memory/session-search.js +14 -11
- package/dist/memory/sidecar-worker.d.ts +1 -0
- package/dist/memory/sidecar-worker.js +57 -76
- package/dist/memory/source-window.d.ts +18 -7
- package/dist/memory/source-window.js +59 -29
- package/dist/memory/store.d.ts +14 -12
- package/dist/memory/store.js +89 -57
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +2 -0
- package/dist/playbooks/agent-delegation.md +23 -17
- package/dist/playbooks/background-jobs.md +7 -5
- package/dist/playbooks/event-scheduling.md +9 -7
- package/dist/playbooks/memory-and-learning.md +18 -14
- package/dist/playbooks/outbound-media.md +3 -3
- package/dist/playbooks/runtime-orientation.md +39 -23
- package/dist/playbooks/task-lead.md +57 -34
- package/dist/runtime/bootstrap.d.ts +45 -35
- package/dist/runtime/bootstrap.js +372 -167
- package/dist/runtime/channel-queue.d.ts +25 -0
- package/dist/{dingtalk → runtime}/channel-queue.js +25 -10
- package/dist/runtime/daemon-lock.d.ts +12 -0
- package/dist/runtime/daemon-lock.js +28 -0
- package/dist/runtime/desk-runtime.d.ts +131 -0
- package/dist/runtime/desk-runtime.js +402 -0
- package/dist/runtime/durable-dispatch.d.ts +18 -5
- package/dist/runtime/durable-dispatch.js +85 -14
- package/dist/runtime/inbound-images.d.ts +32 -10
- package/dist/runtime/inbound-images.js +95 -21
- package/dist/runtime/ingress-busy.d.ts +25 -0
- package/dist/runtime/ingress-busy.js +178 -0
- package/dist/runtime/ingress-commands.d.ts +7 -0
- package/dist/runtime/ingress-commands.js +170 -0
- package/dist/runtime/ingress-deps.d.ts +59 -0
- package/dist/runtime/ingress-deps.js +1 -0
- package/dist/runtime/ingress.d.ts +22 -0
- package/dist/runtime/ingress.js +386 -0
- package/dist/runtime/request-execution.d.ts +19 -0
- package/dist/runtime/request-execution.js +88 -0
- package/dist/runtime/shutdown.d.ts +14 -6
- package/dist/runtime/shutdown.js +11 -5
- package/dist/runtime/task-close.d.ts +4 -0
- package/dist/runtime/task-close.js +102 -0
- package/dist/runtime/task-control.d.ts +34 -0
- package/dist/runtime/task-control.js +225 -0
- package/dist/runtime/task-input.d.ts +13 -0
- package/dist/runtime/task-input.js +129 -0
- package/dist/runtime/task-lane-types.d.ts +123 -0
- package/dist/runtime/task-lane-types.js +14 -0
- package/dist/runtime/task-lane.d.ts +99 -0
- package/dist/runtime/task-lane.js +703 -0
- package/dist/runtime/task-pending.d.ts +8 -0
- package/dist/runtime/task-pending.js +40 -0
- package/dist/runtime/task-spawn.d.ts +8 -8
- package/dist/runtime/task-spawn.js +10 -9
- package/dist/runtime/task-step.d.ts +32 -0
- package/dist/runtime/task-step.js +276 -0
- package/dist/runtime/transports.d.ts +32 -0
- package/dist/runtime/transports.js +101 -0
- package/dist/runtime/turn-run.d.ts +20 -23
- package/dist/runtime/turn-run.js +252 -159
- package/dist/runtime/wake-coalescing.d.ts +12 -6
- package/dist/runtime/wake-coalescing.js +12 -4
- package/dist/security/config.js +5 -10
- package/dist/security/logger.js +1 -1
- package/dist/security/path-guard.js +7 -63
- package/dist/security/types.d.ts +27 -30
- package/dist/security/types.js +0 -1
- package/dist/shared/atomic-file.d.ts +2 -0
- package/dist/shared/atomic-file.js +14 -1
- package/dist/shared/file-lock.d.ts +35 -0
- package/dist/shared/file-lock.js +195 -0
- package/dist/shared/format.d.ts +0 -6
- package/dist/shared/format.js +0 -17
- package/dist/shared/host-process.d.ts +2 -0
- package/dist/shared/host-process.js +16 -1
- package/dist/shared/jsonl-appender.d.ts +5 -0
- package/dist/shared/jsonl-appender.js +25 -2
- package/dist/shared/with-timeout.d.ts +2 -0
- package/dist/shared/with-timeout.js +21 -0
- package/dist/skills/catalog.d.ts +9 -0
- package/dist/skills/catalog.js +34 -0
- package/dist/skills/commands.d.ts +3 -12
- package/dist/skills/commands.js +36 -22
- package/dist/skills/loader.d.ts +2 -31
- package/dist/skills/loader.js +101 -68
- package/dist/skills/roots.d.ts +12 -0
- package/dist/skills/roots.js +18 -0
- package/dist/skills/types.d.ts +24 -0
- package/dist/skills/types.js +1 -0
- package/dist/subagents/completion-wake.d.ts +11 -2
- package/dist/subagents/completion-wake.js +21 -18
- package/dist/subagents/discovery.d.ts +1 -1
- package/dist/subagents/discovery.js +10 -16
- package/dist/subagents/dispatch.d.ts +0 -10
- package/dist/subagents/dispatch.js +18 -44
- package/dist/subagents/external/cursor-cli.d.ts +2 -0
- package/dist/subagents/external/cursor-cli.js +256 -0
- package/dist/subagents/external/dispatch.js +1 -1
- package/dist/subagents/external/harness.d.ts +5 -5
- package/dist/subagents/external/reconciliation.d.ts +7 -0
- package/dist/subagents/external/reconciliation.js +105 -0
- package/dist/subagents/external/recovery.d.ts +20 -0
- package/dist/subagents/external/recovery.js +71 -0
- package/dist/subagents/external/registry.js +2 -0
- package/dist/subagents/external/role-warnings.d.ts +17 -0
- package/dist/subagents/external/role-warnings.js +42 -0
- package/dist/subagents/external/run.d.ts +1 -1
- package/dist/subagents/external/run.js +21 -25
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/grace.d.ts +2 -2
- package/dist/subagents/grace.js +3 -3
- package/dist/subagents/internal/run.js +8 -6
- package/dist/subagents/internal/worker.js +37 -16
- package/dist/subagents/result.js +2 -3
- package/dist/subagents/run-archive.d.ts +11 -0
- package/dist/subagents/run-archive.js +49 -0
- package/dist/subagents/run-record.d.ts +13 -15
- package/dist/subagents/run-record.js +5 -5
- package/dist/subagents/run-registry.d.ts +5 -3
- package/dist/subagents/run-registry.js +22 -45
- package/dist/subagents/runs.d.ts +51 -54
- package/dist/subagents/runs.js +178 -304
- package/dist/subagents/task-envelope.js +9 -11
- package/dist/subagents/task-settlement.d.ts +3 -0
- package/dist/subagents/task-settlement.js +20 -0
- package/dist/subagents/types.d.ts +7 -7
- package/dist/subagents/workspace-summary.js +5 -1
- package/dist/tasks/archive.d.ts +11 -0
- package/dist/tasks/archive.js +141 -0
- package/dist/tasks/board.d.ts +5 -12
- package/dist/tasks/board.js +4 -30
- package/dist/tasks/bound-work.d.ts +13 -7
- package/dist/tasks/bound-work.js +41 -28
- package/dist/tasks/brief.d.ts +39 -15
- package/dist/tasks/brief.js +131 -73
- package/dist/tasks/budget.d.ts +3 -3
- package/dist/tasks/budget.js +9 -4
- package/dist/tasks/commands.d.ts +24 -10
- package/dist/tasks/commands.js +225 -131
- package/dist/tasks/completion.d.ts +12 -0
- package/dist/tasks/completion.js +35 -0
- package/dist/tasks/contract.d.ts +8 -19
- package/dist/tasks/contract.js +41 -45
- package/dist/tasks/control.d.ts +138 -0
- package/dist/tasks/control.js +1 -0
- package/dist/tasks/create.d.ts +4 -2
- package/dist/tasks/create.js +13 -7
- package/dist/tasks/delivery.d.ts +24 -0
- package/dist/tasks/delivery.js +221 -0
- package/dist/tasks/file-mutation.d.ts +5 -0
- package/dist/tasks/file-mutation.js +38 -0
- package/dist/tasks/frontmatter.d.ts +46 -27
- package/dist/tasks/frontmatter.js +90 -47
- package/dist/tasks/input-receipts.d.ts +7 -0
- package/dist/tasks/input-receipts.js +60 -0
- package/dist/tasks/loop-log.d.ts +150 -37
- package/dist/tasks/loop-log.js +250 -42
- package/dist/tasks/mutation-lock.d.ts +7 -5
- package/dist/tasks/mutation-lock.js +32 -9
- package/dist/tasks/receipts.d.ts +19 -0
- package/dist/tasks/receipts.js +48 -0
- package/dist/tasks/session-path.d.ts +3 -3
- package/dist/tasks/session-path.js +5 -5
- package/dist/tasks/state.d.ts +93 -0
- package/dist/tasks/state.js +156 -0
- package/dist/tasks/store.d.ts +86 -54
- package/dist/tasks/store.js +256 -156
- package/dist/tools/bash.d.ts +8 -10
- package/dist/tools/bash.js +27 -40
- package/dist/tools/contract/details.d.ts +6 -6
- package/dist/tools/contract/details.js +6 -6
- package/dist/tools/contract/execution-trace.d.ts +4 -0
- package/dist/tools/contract/execution-trace.js +23 -0
- package/dist/tools/contract/names.d.ts +7 -0
- package/dist/tools/contract/names.js +22 -0
- package/dist/tools/contract/presentation.js +6 -2
- package/dist/tools/edit.d.ts +1 -0
- package/dist/tools/edit.js +46 -43
- package/dist/tools/event-manage.d.ts +3 -1
- package/dist/tools/event-manage.js +34 -33
- package/dist/tools/glob.js +5 -5
- package/dist/tools/grep.js +2 -2
- package/dist/tools/index.d.ts +17 -20
- package/dist/tools/index.js +28 -22
- package/dist/tools/job.d.ts +4 -2
- package/dist/tools/job.js +11 -8
- package/dist/tools/memory-manage.d.ts +5 -3
- package/dist/tools/memory-manage.js +32 -25
- package/dist/tools/read.js +1 -1
- package/dist/tools/registry.d.ts +19 -19
- package/dist/tools/registry.js +65 -34
- package/dist/tools/send-media.d.ts +2 -2
- package/dist/tools/send-media.js +3 -3
- package/dist/tools/session-search.d.ts +3 -1
- package/dist/tools/session-search.js +8 -6
- package/dist/tools/skill.d.ts +2 -2
- package/dist/tools/skill.js +24 -10
- package/dist/tools/subagent-manage.d.ts +2 -8
- package/dist/tools/subagent-manage.js +26 -19
- package/dist/tools/subagent.d.ts +0 -2
- package/dist/tools/subagent.js +3 -8
- package/dist/tools/task-manage/control-tools.d.ts +4 -0
- package/dist/tools/task-manage/control-tools.js +65 -0
- package/dist/tools/task-manage/create.js +3 -2
- package/dist/tools/task-manage/factory.d.ts +12 -6
- package/dist/tools/task-manage/factory.js +73 -58
- package/dist/tools/task-manage/lifecycle.d.ts +7 -12
- package/dist/tools/task-manage/lifecycle.js +119 -65
- package/dist/tools/task-manage/log-view.js +10 -7
- package/dist/tools/task-manage/schema.d.ts +21 -26
- package/dist/tools/task-manage/schema.js +29 -35
- package/dist/tools/task-manage/shared.d.ts +8 -39
- package/dist/tools/task-manage/shared.js +20 -69
- package/dist/tools/task-manage/step-tools.d.ts +5 -0
- package/dist/tools/task-manage/step-tools.js +103 -0
- package/dist/tools/task-manage/types.d.ts +33 -21
- package/dist/tools/web-cache.d.ts +3 -3
- package/dist/tools/web-cache.js +12 -12
- package/dist/tools/web-fetch.d.ts +2 -2
- package/dist/tools/web-fetch.js +7 -7
- package/dist/tools/write-content.d.ts +1 -0
- package/dist/tools/write-content.js +7 -2
- package/dist/tools/write.d.ts +1 -0
- package/dist/tools/write.js +1 -0
- package/dist/tui/cli.d.ts +17 -5
- package/dist/tui/cli.js +90 -27
- package/dist/tui/client.d.ts +26 -0
- package/dist/tui/client.js +157 -0
- package/dist/tui/colors.d.ts +0 -1
- package/dist/tui/colors.js +0 -1
- package/dist/tui/commands.d.ts +10 -51
- package/dist/tui/commands.js +16 -39
- package/dist/tui/frontend.d.ts +2 -2
- package/dist/tui/frontend.js +2 -2
- package/dist/tui/pitui-frontend.d.ts +0 -2
- package/dist/tui/pitui-frontend.js +1 -6
- package/dist/tui/render.d.ts +62 -0
- package/dist/tui/render.js +123 -0
- package/dist/tui/session.d.ts +92 -0
- package/dist/tui/session.js +317 -0
- package/dist/usage/ledger.d.ts +9 -4
- package/dist/usage/ledger.js +2 -0
- package/dist/usage/render.d.ts +6 -1
- package/dist/usage/render.js +20 -15
- package/dist/web/search-providers.js +0 -33
- package/dist/webapi/auth.d.ts +13 -0
- package/dist/webapi/auth.js +29 -0
- package/dist/webapi/config.d.ts +29 -0
- package/dist/webapi/config.js +100 -0
- package/dist/webapi/errors.d.ts +39 -0
- package/dist/webapi/errors.js +32 -0
- package/dist/webapi/http.d.ts +25 -0
- package/dist/webapi/http.js +4 -0
- package/dist/webapi/ids.d.ts +9 -0
- package/dist/webapi/ids.js +20 -0
- package/dist/webapi/input.d.ts +17 -0
- package/dist/webapi/input.js +229 -0
- package/dist/webapi/items.d.ts +37 -0
- package/dist/webapi/items.js +48 -0
- package/dist/webapi/key-command.d.ts +2 -0
- package/dist/webapi/key-command.js +110 -0
- package/dist/webapi/limits.d.ts +47 -0
- package/dist/webapi/limits.js +48 -0
- package/dist/webapi/request-policy.d.ts +17 -0
- package/dist/webapi/request-policy.js +160 -0
- package/dist/webapi/response-record.d.ts +68 -0
- package/dist/webapi/response-record.js +58 -0
- package/dist/webapi/response-state.d.ts +90 -0
- package/dist/webapi/response-state.js +347 -0
- package/dist/webapi/routes/conversations.d.ts +8 -0
- package/dist/webapi/routes/conversations.js +80 -0
- package/dist/webapi/routes/models.d.ts +3 -0
- package/dist/webapi/routes/models.js +12 -0
- package/dist/webapi/routes/responses.d.ts +8 -0
- package/dist/webapi/routes/responses.js +118 -0
- package/dist/webapi/routes/websocket.d.ts +9 -0
- package/dist/webapi/routes/websocket.js +328 -0
- package/dist/webapi/server.d.ts +24 -0
- package/dist/webapi/server.js +229 -0
- package/dist/webapi/service.d.ts +130 -0
- package/dist/webapi/service.js +588 -0
- package/dist/webapi/store.d.ts +46 -0
- package/dist/webapi/store.js +245 -0
- package/dist/webapi/stream.d.ts +13 -0
- package/dist/webapi/stream.js +76 -0
- package/dist/webapi/transport.d.ts +43 -0
- package/dist/webapi/transport.js +100 -0
- package/examples/sub-agents/README.md +23 -16
- package/examples/sub-agents/agents/claude-high.md +1 -1
- package/examples/sub-agents/agents/claude-main.md +1 -1
- package/examples/sub-agents/agents/codex-flash.md +1 -1
- package/examples/sub-agents/agents/codex-high.md +1 -1
- package/examples/sub-agents/agents/codex-main.md +4 -4
- package/examples/sub-agents/agents/cursor-high.md +22 -0
- package/examples/sub-agents/agents/cursor-main.md +22 -0
- package/examples/sub-agents/agents/glm-flash.md +1 -1
- package/examples/sub-agents/agents/glm-high.md +2 -2
- package/examples/sub-agents/agents/scout.md +30 -0
- package/package.json +13 -7
- package/dist/channel/channel-paths.d.ts +0 -16
- package/dist/channel/channel-paths.js +0 -53
- package/dist/channel/commands.d.ts +0 -32
- package/dist/channel/commands.js +0 -109
- package/dist/channel/project-scope-store.d.ts +0 -51
- package/dist/channel/project-scope-store.js +0 -112
- package/dist/dingtalk/channel-queue.d.ts +0 -19
- package/dist/dingtalk/handler.d.ts +0 -90
- package/dist/memory/channel-maintenance-queue.d.ts +0 -5
- package/dist/memory/channel-maintenance-queue.js +0 -8
- package/dist/runtime/task-driver.d.ts +0 -100
- package/dist/runtime/task-driver.js +0 -417
- package/dist/runtime/task-migration.d.ts +0 -30
- package/dist/runtime/task-migration.js +0 -465
- package/dist/runtime/task-wake.d.ts +0 -46
- package/dist/runtime/task-wake.js +0 -32
- package/dist/runtime/turn-handler.d.ts +0 -47
- package/dist/runtime/turn-handler.js +0 -318
- package/dist/security/project-scope.d.ts +0 -45
- package/dist/security/project-scope.js +0 -105
- package/dist/shared/wake-claim.d.ts +0 -23
- package/dist/shared/wake-claim.js +0 -26
- package/dist/skills/validation.d.ts +0 -8
- package/dist/skills/validation.js +0 -91
- package/dist/skills/workspace.d.ts +0 -33
- package/dist/skills/workspace.js +0 -116
- package/dist/tasks/steer.d.ts +0 -8
- package/dist/tasks/steer.js +0 -79
- package/dist/tasks/ticket.d.ts +0 -71
- package/dist/tasks/ticket.js +0 -138
- package/dist/tools/task-manage/step-end.d.ts +0 -11
- package/dist/tools/task-manage/step-end.js +0 -117
- package/dist/tui/app.d.ts +0 -16
- package/dist/tui/app.js +0 -166
- package/dist/tui/terminal-context.d.ts +0 -27
- package/dist/tui/terminal-context.js +0 -84
- package/dist/tui/terminal-media-sender.d.ts +0 -9
- package/dist/tui/terminal-media-sender.js +0 -15
- package/dist/tui/turn-controller.d.ts +0 -64
- package/dist/tui/turn-controller.js +0 -311
- /package/dist/{dingtalk/handler.js → channel/transport.js} +0 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the Web API keeps what it has told its callers (spec 061, D23). It lives under the
|
|
3
|
+
* channel's own `state/webapi/`, not in a desk, so a conversation's history survives `/desk bind`.
|
|
4
|
+
*
|
|
5
|
+
* state/webapi/ 0700
|
|
6
|
+
* ├── responses.jsonl response id → conversation id, append-only, for operators
|
|
7
|
+
* └── conversations/<conv_id>/
|
|
8
|
+
* ├── conversation.json { id, created_at, metadata, owner }, written atomically
|
|
9
|
+
* └── responses.jsonl a snapshot per response when created and when ended; the last wins
|
|
10
|
+
*
|
|
11
|
+
* Everything is read into memory once at start. A response that never reached an end (the process
|
|
12
|
+
* died mid-turn) is marked failed then, once — it is never re-run, because its tools may already
|
|
13
|
+
* have had effects.
|
|
14
|
+
*/
|
|
15
|
+
import { appendFile, chmod, mkdir, readdir, readFile, rm } from "node:fs/promises";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import * as log from "../log.js";
|
|
18
|
+
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
19
|
+
import { createJsonlAppender } from "../shared/jsonl-appender.js";
|
|
20
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
21
|
+
import { isPlainObject } from "../shared/type-guards.js";
|
|
22
|
+
import { isConversationId, newId } from "./ids.js";
|
|
23
|
+
import { isTerminal, nowSeconds } from "./response-record.js";
|
|
24
|
+
const RESTART_MESSAGE = "服务重启,回合被中断。";
|
|
25
|
+
const MAX_SNAPSHOT_PENDING_BYTES = 128 * 1024 * 1024;
|
|
26
|
+
export class WebApiStore {
|
|
27
|
+
constructor(dir) {
|
|
28
|
+
this.dir = dir;
|
|
29
|
+
this.conversations = new Map();
|
|
30
|
+
this.responses = new Map();
|
|
31
|
+
/** Response ids per conversation, in the order they were created. */
|
|
32
|
+
this.order = new Map();
|
|
33
|
+
/** The tail of the disk writes `saveResponse` has queued. */
|
|
34
|
+
this.writes = Promise.resolve();
|
|
35
|
+
this.appender = createJsonlAppender({
|
|
36
|
+
pathFor: (_now, record) => record.path,
|
|
37
|
+
recordForWrite: (record) => record.record,
|
|
38
|
+
// A snapshot carries its input and its continuation, each able to hold the full set of
|
|
39
|
+
// base64 images a request may attach; the default 8 MiB would refuse a legitimate one.
|
|
40
|
+
maxPendingBytes: MAX_SNAPSHOT_PENDING_BYTES,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** Open the store, reading everything and failing the responses a previous run left unfinished. */
|
|
44
|
+
static async open(stateDir) {
|
|
45
|
+
const store = new WebApiStore(stateDir);
|
|
46
|
+
await mkdir(join(stateDir, "conversations"), { recursive: true, mode: 0o700 });
|
|
47
|
+
// `mkdir -p` applies the mode to the leaf only; the whole tree must be private.
|
|
48
|
+
await chmod(stateDir, 0o700);
|
|
49
|
+
await chmod(join(stateDir, "conversations"), 0o700);
|
|
50
|
+
await store.load();
|
|
51
|
+
return store;
|
|
52
|
+
}
|
|
53
|
+
conversationDir(id) {
|
|
54
|
+
return join(this.dir, "conversations", id);
|
|
55
|
+
}
|
|
56
|
+
async load() {
|
|
57
|
+
let names = [];
|
|
58
|
+
try {
|
|
59
|
+
names = await readdir(join(this.dir, "conversations"));
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
for (const name of names.filter(isConversationId).sort()) {
|
|
65
|
+
const conversation = await this.readConversation(name);
|
|
66
|
+
if (!conversation)
|
|
67
|
+
continue;
|
|
68
|
+
this.conversations.set(conversation.id, conversation);
|
|
69
|
+
await this.readResponses(conversation.id);
|
|
70
|
+
}
|
|
71
|
+
await this.readResponses();
|
|
72
|
+
let interrupted = 0;
|
|
73
|
+
for (const record of this.responses.values()) {
|
|
74
|
+
if (isTerminal(record.status))
|
|
75
|
+
continue;
|
|
76
|
+
interrupted++;
|
|
77
|
+
record.status = "failed";
|
|
78
|
+
record.error = { code: "server_error", message: RESTART_MESSAGE };
|
|
79
|
+
record.completed_at = nowSeconds();
|
|
80
|
+
await this.appendSnapshot(record);
|
|
81
|
+
}
|
|
82
|
+
if (interrupted > 0) {
|
|
83
|
+
log.logWarn("webapi.store.interrupted", "Responses left unfinished by a restart were marked failed", {
|
|
84
|
+
fields: { count: interrupted },
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async readConversation(id) {
|
|
89
|
+
try {
|
|
90
|
+
const parsed = JSON.parse(await readFile(join(this.conversationDir(id), "conversation.json"), "utf-8"));
|
|
91
|
+
if (isPlainObject(parsed) &&
|
|
92
|
+
parsed.id === id &&
|
|
93
|
+
typeof parsed.created_at === "number" &&
|
|
94
|
+
typeof parsed.owner === "string") {
|
|
95
|
+
return {
|
|
96
|
+
id,
|
|
97
|
+
created_at: parsed.created_at,
|
|
98
|
+
owner: parsed.owner,
|
|
99
|
+
metadata: isPlainObject(parsed.metadata) ? parsed.metadata : null,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
log.logWarn("webapi.store.conversation_unreadable", "Conversation record skipped", {
|
|
105
|
+
reason: errorMessage(error),
|
|
106
|
+
fields: { conversationId: id },
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
async readResponses(conversationId) {
|
|
112
|
+
const path = conversationId
|
|
113
|
+
? join(this.conversationDir(conversationId), "responses.jsonl")
|
|
114
|
+
: join(this.dir, "standalone.jsonl");
|
|
115
|
+
let text;
|
|
116
|
+
try {
|
|
117
|
+
text = await readFile(path, "utf-8");
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const ids = [];
|
|
123
|
+
// A crash can leave a partial last line; end it, or the next snapshot would be glued onto it and lost.
|
|
124
|
+
if (text.length > 0 && !text.endsWith("\n")) {
|
|
125
|
+
await appendFile(path, "\n");
|
|
126
|
+
}
|
|
127
|
+
for (const line of text.split("\n")) {
|
|
128
|
+
if (!line.trim())
|
|
129
|
+
continue;
|
|
130
|
+
try {
|
|
131
|
+
const record = JSON.parse(line);
|
|
132
|
+
if (!isPlainObject(record) ||
|
|
133
|
+
typeof record.id !== "string" ||
|
|
134
|
+
(conversationId ? record.conversation_id !== conversationId : record.request_scoped !== true)) {
|
|
135
|
+
throw new Error("not a response snapshot");
|
|
136
|
+
}
|
|
137
|
+
if (!this.responses.has(record.id))
|
|
138
|
+
ids.push(record.id);
|
|
139
|
+
this.responses.set(record.id, record);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
log.logWarn("webapi.store.line_skipped", "Unreadable response snapshot skipped", {
|
|
143
|
+
reason: errorMessage(error),
|
|
144
|
+
fields: { conversationId },
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (conversationId)
|
|
149
|
+
this.order.set(conversationId, ids);
|
|
150
|
+
}
|
|
151
|
+
// ---- conversations ---------------------------------------------------------------------
|
|
152
|
+
async createConversation(owner, metadata, id = newId("conv")) {
|
|
153
|
+
const record = { id, created_at: nowSeconds(), metadata, owner };
|
|
154
|
+
this.conversations.set(record.id, record);
|
|
155
|
+
this.order.set(record.id, []);
|
|
156
|
+
await this.writeConversation(record);
|
|
157
|
+
return record;
|
|
158
|
+
}
|
|
159
|
+
getConversation(id) {
|
|
160
|
+
return this.conversations.get(id);
|
|
161
|
+
}
|
|
162
|
+
async updateConversationMetadata(id, metadata) {
|
|
163
|
+
const existing = this.conversations.get(id);
|
|
164
|
+
if (!existing)
|
|
165
|
+
throw new Error(`Unknown conversation ${id}`);
|
|
166
|
+
const updated = { ...existing, metadata };
|
|
167
|
+
await this.writeConversation(updated);
|
|
168
|
+
this.conversations.set(id, updated);
|
|
169
|
+
return updated;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Forget a conversation and its responses, and remove its directory. The index line in
|
|
173
|
+
* `responses.jsonl` stays: it is the operator's record, and it names an id that no longer resolves.
|
|
174
|
+
*/
|
|
175
|
+
async deleteConversation(id) {
|
|
176
|
+
for (const responseId of this.order.get(id) ?? [])
|
|
177
|
+
this.responses.delete(responseId);
|
|
178
|
+
this.order.delete(id);
|
|
179
|
+
this.conversations.delete(id);
|
|
180
|
+
// Snapshots queued before the delete must not recreate the directory afterwards.
|
|
181
|
+
await this.writes;
|
|
182
|
+
await rm(this.conversationDir(id), { recursive: true, force: true });
|
|
183
|
+
}
|
|
184
|
+
async writeConversation(record) {
|
|
185
|
+
await writeFileAtomically(join(this.conversationDir(record.id), "conversation.json"), `${JSON.stringify(record)}\n`);
|
|
186
|
+
}
|
|
187
|
+
// ---- responses -------------------------------------------------------------------------
|
|
188
|
+
getResponse(id) {
|
|
189
|
+
return this.responses.get(id);
|
|
190
|
+
}
|
|
191
|
+
/** A conversation's responses, oldest first. */
|
|
192
|
+
listResponses(conversationId) {
|
|
193
|
+
return (this.order.get(conversationId) ?? []).flatMap((id) => {
|
|
194
|
+
const record = this.responses.get(id);
|
|
195
|
+
return record ? [record] : [];
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
latestResponseId(conversationId) {
|
|
199
|
+
return this.order.get(conversationId)?.at(-1);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Record a response's current state: the first call for an id also registers it in the conversation.
|
|
203
|
+
* Registration is immediate; the disk writes happen in call order, so the last snapshot on disk is
|
|
204
|
+
* always the last one saved (the first save also writes the index line, which would otherwise let a
|
|
205
|
+
* later snapshot overtake it).
|
|
206
|
+
*/
|
|
207
|
+
saveResponse(record) {
|
|
208
|
+
if (record.request_scoped && record.store === false)
|
|
209
|
+
return Promise.resolve();
|
|
210
|
+
// A late snapshot of a deleted conversation's response (one that was settling) is dropped.
|
|
211
|
+
if (!record.request_scoped && !this.conversations.has(record.conversation_id))
|
|
212
|
+
return Promise.resolve();
|
|
213
|
+
const isNew = !this.responses.has(record.id);
|
|
214
|
+
this.responses.set(record.id, record);
|
|
215
|
+
if (isNew && !record.request_scoped) {
|
|
216
|
+
const ids = this.order.get(record.conversation_id) ?? [];
|
|
217
|
+
ids.push(record.id);
|
|
218
|
+
this.order.set(record.conversation_id, ids);
|
|
219
|
+
}
|
|
220
|
+
const snapshot = structuredClone(record);
|
|
221
|
+
const written = this.writes.then(async () => {
|
|
222
|
+
if (isNew) {
|
|
223
|
+
await this.appender.appendStrict({
|
|
224
|
+
path: join(this.dir, "responses.jsonl"),
|
|
225
|
+
record: { id: snapshot.id, conversation_id: snapshot.conversation_id },
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
await this.appendSnapshot(snapshot);
|
|
229
|
+
});
|
|
230
|
+
this.writes = written.catch(() => undefined);
|
|
231
|
+
return written;
|
|
232
|
+
}
|
|
233
|
+
appendSnapshot(record) {
|
|
234
|
+
return this.appender.appendStrict({
|
|
235
|
+
path: record.request_scoped
|
|
236
|
+
? join(this.dir, "standalone.jsonl")
|
|
237
|
+
: join(this.conversationDir(record.conversation_id), "responses.jsonl"),
|
|
238
|
+
record,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
async close() {
|
|
242
|
+
await this.writes;
|
|
243
|
+
await this.appender.close();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-sent events for a response (spec 061, D20): `event:` is the event's `type`, `data:` its
|
|
3
|
+
* JSON, no `id:` and no `[DONE]`. A stream is a cursor over the response's event log, so a late
|
|
4
|
+
* reader (a resumed background stream) sees the same events in the same order as the first.
|
|
5
|
+
*/
|
|
6
|
+
import type { ServerResponse } from "node:http";
|
|
7
|
+
import type { LiveResponse } from "./response-state.js";
|
|
8
|
+
export declare function openEventStream(raw: ServerResponse): void;
|
|
9
|
+
/**
|
|
10
|
+
* Pump `live`'s events from `fromSequence` to `raw` until the response ends or the client goes.
|
|
11
|
+
* Returns whether the response ended (as opposed to the client leaving first).
|
|
12
|
+
*/
|
|
13
|
+
export declare function pumpEvents(live: LiveResponse, fromSequence: number, raw: ServerResponse): Promise<boolean>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export function openEventStream(raw) {
|
|
2
|
+
raw.writeHead(200, {
|
|
3
|
+
"content-type": "text/event-stream; charset=utf-8",
|
|
4
|
+
"cache-control": "no-cache, no-transform",
|
|
5
|
+
connection: "keep-alive",
|
|
6
|
+
"x-accel-buffering": "no",
|
|
7
|
+
});
|
|
8
|
+
raw.flushHeaders();
|
|
9
|
+
}
|
|
10
|
+
function frame(event) {
|
|
11
|
+
return `event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`;
|
|
12
|
+
}
|
|
13
|
+
/** Write one chunk, waiting for the socket to drain if it is full; `false` once the client is gone. */
|
|
14
|
+
async function write(raw, chunk) {
|
|
15
|
+
if (raw.destroyed || raw.writableEnded)
|
|
16
|
+
return false;
|
|
17
|
+
if (raw.write(chunk))
|
|
18
|
+
return true;
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
const done = (ok) => {
|
|
21
|
+
raw.off("drain", onDrain);
|
|
22
|
+
raw.off("close", onClose);
|
|
23
|
+
resolve(ok);
|
|
24
|
+
};
|
|
25
|
+
const onDrain = () => done(true);
|
|
26
|
+
const onClose = () => done(false);
|
|
27
|
+
raw.once("drain", onDrain);
|
|
28
|
+
raw.once("close", onClose);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Pump `live`'s events from `fromSequence` to `raw` until the response ends or the client goes.
|
|
33
|
+
* Returns whether the response ended (as opposed to the client leaving first).
|
|
34
|
+
*/
|
|
35
|
+
export async function pumpEvents(live, fromSequence, raw) {
|
|
36
|
+
const queue = [];
|
|
37
|
+
let ended = false;
|
|
38
|
+
let gone = false;
|
|
39
|
+
let wake;
|
|
40
|
+
const nudge = () => wake?.();
|
|
41
|
+
const unsubscribe = live.subscribe(fromSequence, {
|
|
42
|
+
onEvent: (event) => {
|
|
43
|
+
queue.push(event);
|
|
44
|
+
nudge();
|
|
45
|
+
},
|
|
46
|
+
onEnd: () => {
|
|
47
|
+
ended = true;
|
|
48
|
+
nudge();
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
const onClose = () => {
|
|
52
|
+
gone = true;
|
|
53
|
+
nudge();
|
|
54
|
+
};
|
|
55
|
+
raw.once("close", onClose);
|
|
56
|
+
try {
|
|
57
|
+
for (;;) {
|
|
58
|
+
while (queue.length > 0) {
|
|
59
|
+
if (!(await write(raw, frame(queue.shift()))))
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (ended)
|
|
63
|
+
return true;
|
|
64
|
+
if (gone)
|
|
65
|
+
return false;
|
|
66
|
+
await new Promise((resolve) => {
|
|
67
|
+
wake = resolve;
|
|
68
|
+
});
|
|
69
|
+
wake = undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
unsubscribe();
|
|
74
|
+
raw.off("close", onClose);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ChannelContext } from "../channel/channel-context.js";
|
|
2
|
+
import type { Ingress } from "../channel/ingress.js";
|
|
3
|
+
import type { MediaSendResult, PushMessage, Transport, TransportPolicy, TurnInfo } from "../channel/transport.js";
|
|
4
|
+
import type { ConversationKind } from "../desk/types.js";
|
|
5
|
+
import type { SecurityLogEvent } from "../security/types.js";
|
|
6
|
+
import type { WebApiConfig } from "./config.js";
|
|
7
|
+
export interface WebApiTransportDeps {
|
|
8
|
+
config: WebApiConfig;
|
|
9
|
+
/** `<app home>/state/webapi` */
|
|
10
|
+
stateDir: string;
|
|
11
|
+
/** Where requests and refused requests are recorded (the security audit log). */
|
|
12
|
+
audit: (event: SecurityLogEvent) => void;
|
|
13
|
+
/** Test overrides. */
|
|
14
|
+
maxWebSocketMs?: number;
|
|
15
|
+
replayTtlMs?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare class WebApiTransport implements Transport {
|
|
18
|
+
private readonly deps;
|
|
19
|
+
readonly name: "webapi";
|
|
20
|
+
readonly policy: TransportPolicy;
|
|
21
|
+
private service;
|
|
22
|
+
private server;
|
|
23
|
+
constructor(deps: WebApiTransportDeps);
|
|
24
|
+
get socketPath(): string;
|
|
25
|
+
private requireService;
|
|
26
|
+
start(ingress: Ingress): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* New requests are refused from now on (503), while connections stay open: a running response
|
|
29
|
+
* keeps streaming to its caller until the runtime has let the turn finish.
|
|
30
|
+
*/
|
|
31
|
+
stopAccepting(): Promise<void>;
|
|
32
|
+
stop(): Promise<void>;
|
|
33
|
+
openTurn(turn: TurnInfo, opts: {
|
|
34
|
+
quiet: boolean;
|
|
35
|
+
}): ChannelContext;
|
|
36
|
+
push(channelId: string, message: PushMessage): Promise<boolean>;
|
|
37
|
+
dropped(_channelId: string, refs: string[]): void;
|
|
38
|
+
/** No download endpoint exists for a produced file, so `send_media` is not offered here. */
|
|
39
|
+
readonly sendsMedia = false;
|
|
40
|
+
sendMedia(): Promise<MediaSendResult>;
|
|
41
|
+
describe(channelId: string): string;
|
|
42
|
+
conversationKindOf(channelId: string): ConversationKind | undefined;
|
|
43
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Web API transport (spec 061, D4/D12): the `Transport` the runtime holds for the OpenAI
|
|
3
|
+
* Responses-shaped API. A conversation is a `webapi:conv_…` channel, a request is one message to
|
|
4
|
+
* the runtime's ingress, a Response is what that message turned into. The runtime never learns
|
|
5
|
+
* about HTTP; this file and its neighbours never learn what a command means.
|
|
6
|
+
*/
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { conversationIdOf } from "./ids.js";
|
|
9
|
+
import { WebApiServer } from "./server.js";
|
|
10
|
+
import { WebApiService } from "./service.js";
|
|
11
|
+
import { WebApiStore } from "./store.js";
|
|
12
|
+
/** The longest a unix socket path may be on Linux (108) with room to spare; macOS allows 104. */
|
|
13
|
+
const MAX_SOCKET_PATH_BYTES = 100;
|
|
14
|
+
export class WebApiTransport {
|
|
15
|
+
constructor(deps) {
|
|
16
|
+
this.deps = deps;
|
|
17
|
+
this.name = "webapi";
|
|
18
|
+
this.policy = { whenBusy: "queue", textControlCommands: false };
|
|
19
|
+
/** No download endpoint exists for a produced file, so `send_media` is not offered here. */
|
|
20
|
+
this.sendsMedia = false;
|
|
21
|
+
}
|
|
22
|
+
get socketPath() {
|
|
23
|
+
return join(this.deps.stateDir, "api.sock");
|
|
24
|
+
}
|
|
25
|
+
requireService() {
|
|
26
|
+
if (!this.service)
|
|
27
|
+
throw new Error("The Web API transport is not started");
|
|
28
|
+
return this.service;
|
|
29
|
+
}
|
|
30
|
+
async start(ingress) {
|
|
31
|
+
if (this.deps.config.socket && Buffer.byteLength(this.socketPath) > MAX_SOCKET_PATH_BYTES) {
|
|
32
|
+
throw new Error(`The Web API socket path ${this.socketPath} is too long for a unix socket; use a shorter PIPICLAW_HOME.`);
|
|
33
|
+
}
|
|
34
|
+
const store = await WebApiStore.open(this.deps.stateDir);
|
|
35
|
+
const service = new WebApiService({
|
|
36
|
+
store,
|
|
37
|
+
...(this.deps.replayTtlMs ? { replayTtlMs: this.deps.replayTtlMs } : {}),
|
|
38
|
+
});
|
|
39
|
+
service.setIngress(ingress);
|
|
40
|
+
const server = new WebApiServer({
|
|
41
|
+
config: this.deps.config,
|
|
42
|
+
service,
|
|
43
|
+
socketPath: this.socketPath,
|
|
44
|
+
audit: this.deps.audit,
|
|
45
|
+
...(this.deps.maxWebSocketMs ? { maxWebSocketMs: this.deps.maxWebSocketMs } : {}),
|
|
46
|
+
});
|
|
47
|
+
try {
|
|
48
|
+
await server.start();
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
// Nothing is kept on `this`, so `stop()` could not reach these: release them here.
|
|
52
|
+
await service.shutdown().catch(() => undefined);
|
|
53
|
+
await store.close().catch(() => undefined);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
this.service = service;
|
|
57
|
+
this.server = server;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* New requests are refused from now on (503), while connections stay open: a running response
|
|
61
|
+
* keeps streaming to its caller until the runtime has let the turn finish.
|
|
62
|
+
*/
|
|
63
|
+
async stopAccepting() {
|
|
64
|
+
this.service?.stopAccepting();
|
|
65
|
+
}
|
|
66
|
+
async stop() {
|
|
67
|
+
const server = this.server;
|
|
68
|
+
const service = this.service;
|
|
69
|
+
this.server = undefined;
|
|
70
|
+
this.service = undefined;
|
|
71
|
+
await server?.stop();
|
|
72
|
+
await service?.shutdown();
|
|
73
|
+
await service?.store.close();
|
|
74
|
+
}
|
|
75
|
+
openTurn(turn, opts) {
|
|
76
|
+
return this.requireService().openTurn(turn, opts);
|
|
77
|
+
}
|
|
78
|
+
async push(channelId, message) {
|
|
79
|
+
return this.service?.push(channelId, message) ?? false;
|
|
80
|
+
}
|
|
81
|
+
dropped(_channelId, refs) {
|
|
82
|
+
this.service?.dropped(refs);
|
|
83
|
+
}
|
|
84
|
+
async sendMedia() {
|
|
85
|
+
return {
|
|
86
|
+
ok: false,
|
|
87
|
+
error: "This channel cannot receive attachments. Tell the user the file's path on the server instead.",
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
describe(channelId) {
|
|
91
|
+
const conversationId = conversationIdOf(channelId);
|
|
92
|
+
const owner = conversationId ? this.service?.store.getConversation(conversationId)?.owner : undefined;
|
|
93
|
+
if (owner === "local")
|
|
94
|
+
return "终端";
|
|
95
|
+
return owner ? `API「${owner}」` : "API 会话";
|
|
96
|
+
}
|
|
97
|
+
conversationKindOf(channelId) {
|
|
98
|
+
return conversationIdOf(channelId) ? "webapi" : undefined;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
- [`agents/`](./agents/) — **推荐**。按能力与成本组织:把 agent、模型和推理档直接交给 Pipiclaw,由它按需选择。
|
|
6
6
|
- [`roles/`](./roles/) — 早期的岗位角色(planner / builder / reviewer / verifier …),保留作参考和迁移对照。
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
以能力条目为基础,只安装自己需要的一两个;岗位模板在提供真实执行边界或操作纪律时按需选用,也可以与个别能力条目一起使用。
|
|
9
9
|
|
|
10
10
|
## 为什么从「角色」改成「能力条目」
|
|
11
11
|
|
|
@@ -18,12 +18,13 @@
|
|
|
18
18
|
## 安装 `agents/`
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
# 源码 checkout
|
|
22
|
-
|
|
21
|
+
# 源码 checkout(先创建目标目录):
|
|
22
|
+
mkdir -p ~/.pipiclaw/workspace/sub-agents
|
|
23
|
+
cp examples/sub-agents/agents/codex-main.md ~/.pipiclaw/workspace/sub-agents/
|
|
23
24
|
|
|
24
25
|
# npm 全局安装:
|
|
25
26
|
PIPICLAW_PACKAGE_DIR="$(npm root -g)/@oyasmi/pipiclaw"
|
|
26
|
-
cp "$PIPICLAW_PACKAGE_DIR"/examples/sub-agents/agents
|
|
27
|
+
cp "$PIPICLAW_PACKAGE_DIR"/examples/sub-agents/agents/codex-main.md ~/.pipiclaw/workspace/sub-agents/
|
|
27
28
|
```
|
|
28
29
|
|
|
29
30
|
只装你真的有账号的那几个:条目里的 CLI 不在 PATH 上时不会被丢弃,而是标成 `unavailable` 并在调用时才报错。
|
|
@@ -32,16 +33,23 @@ cp "$PIPICLAW_PACKAGE_DIR"/examples/sub-agents/agents/*.md ~/.pipiclaw/workspace
|
|
|
32
33
|
|---|---|---|---|---|---|
|
|
33
34
|
| `claude-high` | claude-code | `opus` | high | 否 | 代码与推理最强,成本最高:设计、取舍分析、根因不明的疑难 |
|
|
34
35
|
| `claude-main` | claude-code | `sonnet` | medium | 否 | 代码能力最强的主力档:实现、修改、文档、排查 |
|
|
35
|
-
| `codex-high` | codex-cli | `gpt-6-
|
|
36
|
-
| `codex-main` | codex-cli | `gpt-6-
|
|
37
|
-
| `codex-flash` | codex-cli | `gpt-
|
|
36
|
+
| `codex-high` | codex-cli | `gpt-6.1-sol` | high | 是 | 高智能档,可读图片:设计、方案权衡、复杂分析 |
|
|
37
|
+
| `codex-main` | codex-cli | `gpt-6.1-terra` | high | 是 | 主力档,可读图片:常规实现、排查、文档 |
|
|
38
|
+
| `codex-flash` | codex-cli | `gpt-6-luna` | high | 是 | 最快最便宜,可读图片:明确、简单、重复的工作 |
|
|
39
|
+
| `cursor-high` | cursor-cli | `grok-4.7-high` | — | 随模型 | 高智能档,走 Cursor 额度:设计、取舍分析、根因不明的疑难 |
|
|
40
|
+
| `cursor-main` | cursor-cli | `auto` | — | 随模型 | 主力档,Cursor auto 路由:常规实现、排查、文档 |
|
|
38
41
|
| `glm-high` | claude-code | `glm-5.3` | high | 否 | 高智能档,额度宽松:高频使用不挤占 claude/codex 配额 |
|
|
39
42
|
| `glm-flash` | claude-code | `glm-5.3-flash` | medium | 是 | 最便宜,可读图片:大批量简单重复工作的首选 |
|
|
40
|
-
| `codex-review` | codex-cli | `gpt-6-
|
|
43
|
+
| `codex-review` | codex-cli | `gpt-6.1-sol` | high | 是 | 只读检查档:独立审查与 `purpose=verify`,在 CLI 的 read-only sandbox 中运行 |
|
|
44
|
+
| `scout` | 内置 | 默认 | low | 随模型 | 只读调查档:进程内运行,用 Pipiclaw 自己的模型与守卫,不占外部额度;轻量调查同步返回 |
|
|
45
|
+
|
|
46
|
+
`cursor-*` 不写 `thinkingLevel`:当前 Cursor CLI 把推理档做进 model id(如 `…-high`),而 runtime 在声明了 `thinkingLevel` 时会再给 model 加上 `[effort=…]`,该形式会被 CLI 拒绝。需要换档时改 `model`(以本机 `agent models` 为准),不要补 `thinkingLevel`。
|
|
41
47
|
|
|
42
48
|
三档的分工是这套配置的主要内容:**flash** 用于「做什么和怎么做都已清楚,只差有人去做」,可以大量派发;**main** 是主力,绝大多数实现、排查、文档都在这里,也包括 token 消耗很大的长任务;**high** 只留给这一轮真正需要新判断或取舍的工作。对已经定好的活派 high,只是更贵,不会更对。
|
|
43
49
|
|
|
44
|
-
`codex-review`
|
|
50
|
+
`scout` 和 `codex-review` 都不属于这三档。`scout` 是唯一的内置条目:它在 Pipiclaw 进程内运行,用 `settings.subagentModel`(未设时用主会话当前模型),不经过外部 CLI、不占它们的订阅额度,bash 与文件访问走 runtime 的命令与路径守卫。轻量调查通常在 120 秒同步宽限窗口内直接返回结果。它只做只读调查——定位实现、查配置、读日志——工具白名单里没有 `write`/`edit`,不占写锁,可以和其他工作并行;需要写入或跨文件实现时换外部条目。
|
|
51
|
+
|
|
52
|
+
`codex-review` 只做检查:read-only sandbox 是 codex 自己强制的边界,所以它改不了被检查的产物,也不占写锁,可以和其他工作并行。检查者尽量和实现者不是同一家模型——它检查 claude/glm 的产物最有价值;检查 codex 自己的产物时,可以另配一个 `claude --permission-mode plan` 的只读条目。它跑不了会写文件的测试或构建,这类检查要么先由实现者或主代理跑好、把输出交给它,要么换可写条目。
|
|
45
53
|
|
|
46
54
|
额度是真实约束:claude 和 codex 的订阅有周/月上限,GLM 只有 5 小时滚动限额、没有周月上限。所以简单重复的批量工作优先走 `glm-flash`,把受限额度留给难题。
|
|
47
55
|
|
|
@@ -64,11 +72,11 @@ exec claude --dangerously-skip-permissions "$@"
|
|
|
64
72
|
|
|
65
73
|
留着它是因为这几条跨每一个任务都成立,漏掉的代价又很高(尤其是伪造绿色检查结果和把未验证写成已验证),而让主代理每次委派重打一遍既费 token 又会漂移。
|
|
66
74
|
|
|
67
|
-
要改就
|
|
75
|
+
要改就 11 个文件一起改。也可以整段删掉:runtime 允许外部条目的正文为空,此时不会生成 `system-prompt.txt`,claude-code 不追加 `--append-system-prompt-file`,codex-cli / cursor-cli 的 stdin 就是 task 本身。内置条目的正文不能为空——没有正文的角色文件会被 discovery 丢弃。
|
|
68
76
|
|
|
69
77
|
## 这套配置的代价,别忽略
|
|
70
78
|
|
|
71
|
-
- **除 `codex-review` 外全部是放开权限的写条目。** 这
|
|
79
|
+
- **除 `codex-review` 和内置的 `scout` 外全部是放开权限的写条目。** 这 9 个条目都用 yolo 参数(`claude --dangerously-skip-permissions` / `codex exec --dangerously-bypass-approvals-and-sandbox` / `agent --force`)并声明 `mutates: write`,没有 sandbox 兜底。实际边界只剩宿主账号和 `task` 里写明的范围,**必须在可信 checkout 和最小权限账号下使用**。
|
|
72
80
|
- **同一工作目录同时只容得下一个写委派。** `mutates: write` 会取目标工作区的排他 lease(含父子目录冲突),并行写必须各自 `git worktree`;`codex-review` 不取 lease。
|
|
73
81
|
- **`VERDICT` 是供参考的结论,不是门禁。** runtime 只把检查者的 PASS/FAIL 记到 run 和任务看板上。只有 `codex-review` 在结构上改不了产物;用可写条目做检查时,它可能动过产物。无论哪种,都要自己对照真实产物、diff 和检查输出再采信。
|
|
74
82
|
- **独立性不再由角色提示词提供。** 要评审或验收时,必须在 `task` 里写明"你是检查者,不修实现,不把实现者的总结当作预期行为的来源",并给出同一份验收口径和待检版本。换一个条目不会自动带来独立性。
|
|
@@ -80,16 +88,15 @@ exec claude --dangerously-skip-permissions "$@"
|
|
|
80
88
|
- 需要**真正的只读执行边界**:`planner` 的 `--permission-mode plan`、`reviewer` 的 `--sandbox read-only` 是目标 CLI 提供的真实限制,不只是提示词声明;`reviewer` 承担 `purpose=verify` 时也不占工作区写锁。
|
|
81
89
|
- 需要**固定的、反复出现的作业纪律**:`git-committer` 的暂存区隔离规则就是一例——它约束的是一类操作的正确做法,不是一个岗位。
|
|
82
90
|
|
|
83
|
-
反过来,`builder` / `builder-hard` / `worker` 和 `agents/`
|
|
91
|
+
反过来,`explorer`、`builder` / `builder-hard` / `worker` 和 `agents/` 里的对应条目(`scout` 和各实现档位)重叠严重,正文里的岗位设定是净损失,不建议再装。
|
|
84
92
|
|
|
85
93
|
## 从早期模板迁移
|
|
86
94
|
|
|
87
|
-
|
|
95
|
+
已经复制到工作区的旧角色文件不会被自动删除,可以按需选择新条目;保留旧条目可继续使用其执行边界和续接能力:
|
|
88
96
|
|
|
89
97
|
```bash
|
|
90
98
|
cd ~/.pipiclaw/workspace/sub-agents
|
|
91
|
-
|
|
92
|
-
cp /path/to/pipiclaw/examples/sub-agents/agents/*.md .
|
|
99
|
+
cp /path/to/pipiclaw/examples/sub-agents/agents/codex-main.md .
|
|
93
100
|
```
|
|
94
101
|
|
|
95
102
|
迁移期间历史 task 的委派记录里仍会出现旧角色名;`subagent_run op=follow_up` 只能续接条目仍然存在且 `command`/`model`/`shell` 未变的 run,删掉旧文件后这些 run 需要重新委派。
|
|
@@ -99,5 +106,5 @@ cp /path/to/pipiclaw/examples/sub-agents/agents/*.md .
|
|
|
99
106
|
- **`description` 是唯一的路由依据。** 它进入主代理的系统提示词(子代理目录,预算 2400 字符),正文不在那里——改正文修不了选错条目。每条写清:能力特征、相对成本、适用场景,以及会改变选择的边界(能不能读图片、额度是否受限)。`runtime` / `workload` / `mutates` 已由目录分组展示,不要在文字里重复。
|
|
100
107
|
- **描述必须属实且可核查。** 写错一句"支持图片输入",代价是一次几十分钟后才失败的委派,比不写更糟。
|
|
101
108
|
- **不要扩到十几个条目。** agent × 档位 × 权限很容易组合爆炸。每加一个都先问:主代理会因为它做出不同的路由决定吗?答不上来就不该存在。
|
|
102
|
-
- **调 prompt 时看实际发出的内容。** 正文对 claude-code 经 `--append-system-prompt-file` 追加,对 codex-cli 与 task 一起写进 stdin;核对 run 目录里真实的 `system-prompt.txt` / `prompt.txt` 和 argv,不要只审模板 Markdown。
|
|
109
|
+
- **调 prompt 时看实际发出的内容。** 正文对 claude-code 经 `--append-system-prompt-file` 追加,对 codex-cli / cursor-cli 与 task 一起写进 stdin;核对 run 目录里真实的 `system-prompt.txt` / `prompt.txt` 和 argv,不要只审模板 Markdown。
|
|
103
110
|
- 委派的写法、并行隔离、等待与续接见 [../../docs/sub-agents.md](../../docs/sub-agents.md) 与运行时的 `agent-delegation.md` playbook。
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: codex-flash
|
|
3
3
|
description: >-
|
|
4
|
-
最快最便宜的一档,成本远低于 high/main
|
|
4
|
+
最快最便宜的一档,成本远低于 high/main,可接受图片输入。适合明确、简单、重复的工作,可大量派发;适合简单、明确的任务。
|
|
5
5
|
runtime: external
|
|
6
6
|
harness: codex-cli
|
|
7
7
|
command: codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: codex-main
|
|
3
3
|
description: >-
|
|
4
|
-
主力档,成本中等,可接受图片等多模态输入。常规实现、排查和文档产出;代码能力略逊 claude-main
|
|
4
|
+
主力档,成本中等,可接受图片等多模态输入。常规实现、排查和文档产出;代码能力略逊 claude-main。
|
|
5
5
|
runtime: external
|
|
6
6
|
harness: codex-cli
|
|
7
7
|
command: codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check
|
|
8
|
-
model: gpt-6.1-
|
|
9
|
-
thinkingLevel:
|
|
8
|
+
model: gpt-6.1-terra
|
|
9
|
+
thinkingLevel: high
|
|
10
10
|
workload: heavy
|
|
11
11
|
mutates: write
|
|
12
|
-
maxWallTimeSec:
|
|
12
|
+
maxWallTimeSec: 3600
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
- task 没有授权的动作不做:提交、推送、部署、发消息、写入外部系统或真实数据。
|