@oyasmi/pipiclaw 0.9.4 → 0.9.5-beta.2
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 +28 -22
- package/README.md +27 -21
- package/dist/agent/builtin-commands.d.ts +7 -2
- package/dist/agent/builtin-commands.js +19 -23
- package/dist/agent/channel-runner.d.ts +13 -13
- package/dist/agent/channel-runner.js +93 -76
- package/dist/agent/maintenance-context.d.ts +6 -5
- package/dist/agent/maintenance-context.js +15 -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 +4 -4
- package/dist/agent/runner-factory.d.ts +6 -6
- package/dist/agent/runner-factory.js +6 -7
- 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 +158 -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/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 +5 -4
- package/dist/agent/session/session-events.js +46 -59
- package/dist/agent/session/session-host.d.ts +29 -41
- package/dist/agent/session/session-host.js +86 -69
- 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 +4 -2
- package/dist/agent/turn/task-digest.js +7 -4
- package/dist/agent/turn/turn-context.d.ts +11 -7
- package/dist/agent/turn/turn-context.js +26 -18
- package/dist/agent/turn/turn-finish.d.ts +17 -5
- package/dist/agent/turn/turn-finish.js +51 -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 +11 -8
- package/dist/agent/turn/turn-pipeline.js +54 -55
- 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 +31 -12
- package/dist/agent/types.js +2 -1
- package/dist/app/auth-command.js +1 -1
- package/dist/app/home.js +31 -15
- 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 +51 -41
- 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 +101 -0
- package/dist/channel/ingress.js +5 -0
- package/dist/channel/store.d.ts +13 -15
- 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 +24 -31
- package/dist/commands/router.d.ts +23 -12
- package/dist/commands/router.js +22 -24
- package/dist/config/settings.d.ts +5 -4
- 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 +18 -35
- package/dist/dingtalk/bot.js +21 -204
- 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 +30 -14
- package/dist/dingtalk/delivery.js +189 -62
- 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 +8 -0
- package/dist/dingtalk/progress.js +20 -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/index.d.ts +4 -2
- package/dist/jobs/completion-wake.d.ts +14 -0
- package/dist/jobs/completion-wake.js +36 -0
- package/dist/jobs/manager.d.ts +27 -22
- package/dist/jobs/manager.js +58 -91
- package/dist/jobs/record.d.ts +2 -0
- package/dist/jobs/record.js +2 -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 +17 -0
- package/dist/memory/boundary-work.js +162 -0
- package/dist/memory/commands.d.ts +4 -3
- package/dist/memory/commands.js +16 -16
- 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 +3 -3
- package/dist/memory/journal.d.ts +6 -6
- package/dist/memory/journal.js +14 -14
- package/dist/memory/lifecycle.d.ts +14 -21
- package/dist/memory/lifecycle.js +73 -103
- 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 -4
- package/dist/memory/reflect-job.js +21 -15
- package/dist/memory/reflect.d.ts +2 -1
- package/dist/memory/reflect.js +13 -12
- package/dist/memory/render.d.ts +1 -1
- package/dist/memory/render.js +2 -2
- package/dist/memory/review-log.d.ts +4 -4
- package/dist/memory/review-log.js +5 -5
- package/dist/memory/scheduler.d.ts +12 -19
- package/dist/memory/scheduler.js +28 -64
- 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 +0 -6
- package/dist/memory/source-window.js +0 -20
- package/dist/memory/store.d.ts +12 -12
- package/dist/memory/store.js +44 -44
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +2 -0
- package/dist/playbooks/agent-delegation.md +16 -16
- package/dist/playbooks/background-jobs.md +5 -3
- package/dist/playbooks/event-scheduling.md +7 -5
- package/dist/playbooks/memory-and-learning.md +16 -12
- package/dist/playbooks/outbound-media.md +1 -1
- package/dist/playbooks/runtime-orientation.md +35 -23
- package/dist/playbooks/task-lead.md +13 -11
- package/dist/runtime/bootstrap.d.ts +36 -13
- package/dist/runtime/bootstrap.js +310 -138
- package/dist/runtime/channel-queue.d.ts +23 -0
- package/dist/{dingtalk → runtime}/channel-queue.js +20 -9
- 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 +11 -5
- package/dist/runtime/durable-dispatch.js +20 -8
- package/dist/runtime/inbound-images.d.ts +32 -10
- package/dist/runtime/inbound-images.js +95 -21
- package/dist/runtime/ingress-busy.d.ts +26 -0
- package/dist/runtime/ingress-busy.js +211 -0
- package/dist/runtime/ingress-commands.d.ts +7 -0
- package/dist/runtime/ingress-commands.js +162 -0
- package/dist/runtime/ingress-deps.d.ts +62 -0
- package/dist/runtime/ingress-deps.js +1 -0
- package/dist/runtime/ingress.d.ts +22 -0
- package/dist/runtime/ingress.js +376 -0
- package/dist/runtime/request-execution.d.ts +19 -0
- package/dist/runtime/request-execution.js +88 -0
- package/dist/runtime/shutdown.d.ts +13 -5
- package/dist/runtime/shutdown.js +10 -4
- package/dist/runtime/task-driver.d.ts +38 -22
- package/dist/runtime/task-driver.js +142 -116
- package/dist/runtime/task-spawn.d.ts +4 -4
- package/dist/runtime/task-spawn.js +6 -5
- package/dist/runtime/task-wake.d.ts +6 -4
- package/dist/runtime/task-wake.js +7 -7
- package/dist/runtime/transports.d.ts +32 -0
- package/dist/runtime/transports.js +101 -0
- package/dist/runtime/turn-run.d.ts +18 -9
- package/dist/runtime/turn-run.js +302 -71
- package/dist/runtime/wake-coalescing.d.ts +11 -3
- package/dist/runtime/wake-coalescing.js +10 -0
- 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/with-timeout.d.ts +2 -0
- package/dist/shared/with-timeout.js +21 -0
- package/dist/skills/loader.d.ts +1 -1
- package/dist/skills/loader.js +2 -2
- package/dist/skills/workspace.js +2 -2
- package/dist/subagents/completion-wake.d.ts +11 -2
- package/dist/subagents/completion-wake.js +22 -9
- package/dist/subagents/discovery.js +1 -1
- package/dist/subagents/dispatch.d.ts +0 -10
- package/dist/subagents/dispatch.js +10 -28
- package/dist/subagents/external/dispatch.js +1 -1
- package/dist/subagents/external/run.d.ts +1 -1
- package/dist/subagents/external/run.js +3 -3
- package/dist/subagents/internal/run.js +1 -1
- package/dist/subagents/internal/worker.js +6 -14
- package/dist/subagents/run-archive.d.ts +11 -0
- package/dist/subagents/run-archive.js +49 -0
- package/dist/subagents/run-record.d.ts +9 -8
- package/dist/subagents/run-record.js +3 -3
- package/dist/subagents/run-registry.d.ts +5 -3
- package/dist/subagents/run-registry.js +22 -45
- package/dist/subagents/runs.d.ts +23 -13
- package/dist/subagents/runs.js +75 -82
- package/dist/subagents/task-envelope.js +9 -11
- package/dist/subagents/types.d.ts +6 -5
- package/dist/tasks/board.d.ts +1 -1
- package/dist/tasks/board.js +2 -2
- package/dist/tasks/bound-work.d.ts +2 -2
- package/dist/tasks/bound-work.js +7 -7
- package/dist/tasks/brief.d.ts +1 -1
- package/dist/tasks/brief.js +9 -9
- package/dist/tasks/commands.d.ts +11 -2
- package/dist/tasks/commands.js +66 -41
- package/dist/tasks/contract.d.ts +0 -2
- package/dist/tasks/contract.js +1 -3
- package/dist/tasks/create.d.ts +3 -1
- package/dist/tasks/create.js +10 -4
- package/dist/tasks/frontmatter.d.ts +6 -2
- package/dist/tasks/frontmatter.js +10 -10
- package/dist/tasks/loop-log.d.ts +7 -13
- package/dist/tasks/loop-log.js +14 -17
- package/dist/tasks/mutation-lock.d.ts +7 -5
- package/dist/tasks/mutation-lock.js +32 -9
- package/dist/tasks/session-path.d.ts +3 -3
- package/dist/tasks/session-path.js +5 -5
- package/dist/tasks/steer.d.ts +5 -5
- package/dist/tasks/steer.js +42 -40
- package/dist/tasks/store.d.ts +11 -11
- package/dist/tasks/store.js +32 -29
- package/dist/tools/bash.d.ts +5 -5
- package/dist/tools/bash.js +19 -18
- package/dist/tools/contract/names.d.ts +7 -0
- package/dist/tools/contract/names.js +22 -0
- package/dist/tools/edit.js +1 -1
- 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 +9 -8
- package/dist/tools/index.js +12 -16
- 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 +24 -24
- package/dist/tools/read.js +1 -1
- package/dist/tools/registry.d.ts +12 -8
- package/dist/tools/registry.js +13 -9
- 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/subagent-manage.d.ts +2 -8
- package/dist/tools/subagent-manage.js +19 -15
- package/dist/tools/subagent.js +1 -1
- package/dist/tools/task-manage/create.js +1 -1
- package/dist/tools/task-manage/factory.js +2 -2
- package/dist/tools/task-manage/lifecycle.js +3 -1
- package/dist/tools/task-manage/log-view.js +2 -2
- package/dist/tools/task-manage/shared.js +3 -3
- package/dist/tools/task-manage/step-end.js +3 -3
- package/dist/tools/task-manage/types.d.ts +8 -3
- 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.js +1 -1
- 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 +5 -0
- package/dist/usage/ledger.js +2 -0
- package/dist/usage/render.d.ts +6 -1
- package/dist/usage/render.js +18 -13
- 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/package.json +8 -2
- 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-migration.d.ts +0 -30
- package/dist/runtime/task-migration.js +0 -465
- 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/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
|
@@ -5,9 +5,9 @@ import { isRecord } from "../../shared/type-guards.js";
|
|
|
5
5
|
import { isArgumentValidationFailure, isRecoverableRejection, takeGuardBlock, toolResultDetails, } from "../../tools/contract/details.js";
|
|
6
6
|
import { describeToolCall } from "../../tools/contract/presentation.js";
|
|
7
7
|
import { addUsage } from "../../usage/totals.js";
|
|
8
|
-
import { extractToolResultText
|
|
8
|
+
import { extractToolResultText } from "../turn/progress-formatter.js";
|
|
9
9
|
import { renderCompactionFailure } from "../turn/turn-error.js";
|
|
10
|
-
import { extractCustomCommandResultText, isAssistantEventMessage, isAutoCompactionEndEvent, isAutoCompactionStartEvent, isAutoRetryStartEvent, isMessageEndEvent, isMessageStartEvent, isSubAgentToolDetails, isTextPart, isThinkingPart, isToolExecutionEndEvent, isToolExecutionStartEvent, isToolExecutionUpdateEvent, isTurnEndEvent, } from "./event-guards.js";
|
|
10
|
+
import { extractCustomCommandResultText, isAssistantEventMessage, isAutoCompactionEndEvent, isAutoCompactionStartEvent, isAutoRetryStartEvent, isMessageEndEvent, isMessageStartEvent, isSubAgentToolDetails, isTextPart, isThinkingPart, isToolExecutionEndEvent, isToolExecutionStartEvent, isToolExecutionUpdateEvent, isTurnEndEvent, isUserEventMessage, } from "./event-guards.js";
|
|
11
11
|
/**
|
|
12
12
|
* A `write`/`edit` result whose resolved target landed inside the workspace `skills/` tree. The
|
|
13
13
|
* `skill` tool is read-only (spec 045); authoring a workspace skill goes through the generic file
|
|
@@ -23,6 +23,8 @@ function isWorkspaceSkillWrite(toolName, details, skillsDir) {
|
|
|
23
23
|
}
|
|
24
24
|
return details.path === skillsDir || details.path.startsWith(`${skillsDir}/`);
|
|
25
25
|
}
|
|
26
|
+
/** How much of a tool's result a `tool.end` event carries; the full text stays in the log and the session. */
|
|
27
|
+
const TOOL_EVENT_OUTPUT_CHARS = 4000;
|
|
26
28
|
function firstLine(text) {
|
|
27
29
|
return text.trim().split("\n", 1)[0] ?? "";
|
|
28
30
|
}
|
|
@@ -37,8 +39,6 @@ function mergeAssistantUsage(runState, usage) {
|
|
|
37
39
|
}
|
|
38
40
|
export async function handleSessionEvent(event, context) {
|
|
39
41
|
const { ctx, logCtx, queue, pendingTools, runState, memoryLifecycle } = context;
|
|
40
|
-
const showProgress = ctx.progressStyle !== "none";
|
|
41
|
-
const finalToCard = ctx.finalDelivery === "card";
|
|
42
42
|
if (isToolExecutionStartEvent(event)) {
|
|
43
43
|
const label = describeToolCall(event.toolName, event.args);
|
|
44
44
|
pendingTools.set(event.toolCallId, {
|
|
@@ -48,9 +48,7 @@ export async function handleSessionEvent(event, context) {
|
|
|
48
48
|
});
|
|
49
49
|
memoryLifecycle.noteToolCall();
|
|
50
50
|
log.logToolStart(logCtx, event.toolName, label, isRecord(event.args) ? event.args : {});
|
|
51
|
-
|
|
52
|
-
queue.enqueue(() => ctx.respond(formatProgressEntry("tool", label), false), "tool label");
|
|
53
|
-
}
|
|
51
|
+
ctx.emit({ type: "tool.start", callId: event.toolCallId, tool: event.toolName, args: event.args });
|
|
54
52
|
return;
|
|
55
53
|
}
|
|
56
54
|
if (isToolExecutionUpdateEvent(event)) {
|
|
@@ -61,9 +59,7 @@ export async function handleSessionEvent(event, context) {
|
|
|
61
59
|
if (!partialText.trim()) {
|
|
62
60
|
return;
|
|
63
61
|
}
|
|
64
|
-
|
|
65
|
-
queue.enqueue(() => ctx.respond(formatProgressEntry("tool", partialText), false), "tool update");
|
|
66
|
-
}
|
|
62
|
+
ctx.emit({ type: "tool.update", callId: event.toolCallId, text: partialText });
|
|
67
63
|
return;
|
|
68
64
|
}
|
|
69
65
|
if (isToolExecutionEndEvent(event)) {
|
|
@@ -94,7 +90,9 @@ export async function handleSessionEvent(event, context) {
|
|
|
94
90
|
context.refreshSessionResources &&
|
|
95
91
|
isWorkspaceSkillWrite(event.toolName, details, context.skillsDir)) {
|
|
96
92
|
queue.enqueue(() => context.refreshSessionResources?.() ?? Promise.resolve(), "refresh skills");
|
|
97
|
-
queue.enqueue(() =>
|
|
93
|
+
queue.enqueue(async () => {
|
|
94
|
+
ctx.emit({ type: "commentary", text: "已更新 workspace skill,下一条消息起生效。", level: "notice" });
|
|
95
|
+
}, "skill notice");
|
|
98
96
|
}
|
|
99
97
|
// A recoverable rejection (bad arguments, unmet precondition the model can fix) is not a
|
|
100
98
|
// fault: the model normally corrects it on the next call. It is logged so the retry is
|
|
@@ -123,19 +121,34 @@ export async function handleSessionEvent(event, context) {
|
|
|
123
121
|
}
|
|
124
122
|
// Claimed on every error, shown or not, so the parked refusal never outlives its call.
|
|
125
123
|
const blocked = event.isError ? takeGuardBlock(event.toolCallId, resultStr) : undefined;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
// The tool's error text is written for the model (spec 053, D2): a guard refusal is shown
|
|
125
|
+
// from its structured form; anything else as its first line only — the full text is in
|
|
126
|
+
// the log (`agent.tool.failed`).
|
|
127
|
+
const failure = treatAsError
|
|
128
|
+
? blocked
|
|
129
|
+
? renderGuardBlockForUser(blocked)
|
|
130
|
+
: truncate(firstLine(resultStr), 120)
|
|
131
|
+
: undefined;
|
|
132
|
+
ctx.emit({
|
|
133
|
+
type: "tool.end",
|
|
134
|
+
callId: event.toolCallId,
|
|
135
|
+
ok: !event.isError && !subAgentDetails?.failed,
|
|
136
|
+
output: truncate(resultStr, TOOL_EVENT_OUTPUT_CHARS),
|
|
137
|
+
...(failure ? { failure } : {}),
|
|
138
|
+
});
|
|
133
139
|
return;
|
|
134
140
|
}
|
|
135
141
|
if (isMessageStartEvent(event)) {
|
|
136
142
|
if (isAssistantEventMessage(event.message)) {
|
|
137
143
|
log.logResponseStart(logCtx);
|
|
138
144
|
}
|
|
145
|
+
else if (isUserEventMessage(event.message)) {
|
|
146
|
+
// The turn's own prompt is the first user message; any later one is a steering or
|
|
147
|
+
// follow-up message the SDK injected into the running loop.
|
|
148
|
+
runState.userMessagesStarted++;
|
|
149
|
+
if (runState.userMessagesStarted > 1)
|
|
150
|
+
ctx.emit({ type: "steer.applied" });
|
|
151
|
+
}
|
|
139
152
|
return;
|
|
140
153
|
}
|
|
141
154
|
if (isMessageEndEvent(event)) {
|
|
@@ -143,18 +156,8 @@ export async function handleSessionEvent(event, context) {
|
|
|
143
156
|
if (commandResultText) {
|
|
144
157
|
runState.finalOutcome = { kind: "final", text: commandResultText };
|
|
145
158
|
log.logResponse(logCtx, commandResultText);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
await ctx.replaceMessage(commandResultText);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
const delivered = await ctx.respondPlain(commandResultText);
|
|
152
|
-
if (!delivered) {
|
|
153
|
-
await ctx.replaceMessage(commandResultText);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
runState.finalResponseDelivered = true;
|
|
157
|
-
}, "command result");
|
|
159
|
+
runState.answerEmitted = true;
|
|
160
|
+
ctx.emit({ type: "answer", text: commandResultText });
|
|
158
161
|
return;
|
|
159
162
|
}
|
|
160
163
|
if (isAssistantEventMessage(event.message)) {
|
|
@@ -190,14 +193,12 @@ export async function handleSessionEvent(event, context) {
|
|
|
190
193
|
}
|
|
191
194
|
}
|
|
192
195
|
const text = textParts.join("\n");
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
queue.enqueue(() => ctx.respond(formatProgressEntry("thinking", thinking), false), "thinking");
|
|
197
|
-
}
|
|
196
|
+
for (const thinking of thinkingParts) {
|
|
197
|
+
log.logThinking(logCtx, thinking);
|
|
198
|
+
ctx.emit({ type: "reasoning", text: thinking });
|
|
198
199
|
}
|
|
199
|
-
if (text.trim() && hasToolCalls
|
|
200
|
-
|
|
200
|
+
if (text.trim() && hasToolCalls) {
|
|
201
|
+
ctx.emit({ type: "commentary", text });
|
|
201
202
|
}
|
|
202
203
|
}
|
|
203
204
|
return;
|
|
@@ -231,30 +232,17 @@ export async function handleSessionEvent(event, context) {
|
|
|
231
232
|
runState.finalOutcome = { kind: "final", text: finalText };
|
|
232
233
|
memoryLifecycle.noteCompletedAssistantTurn();
|
|
233
234
|
log.logResponse(logCtx, finalText);
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
await ctx.replaceMessage(finalText);
|
|
237
|
-
runState.finalResponseDelivered = true;
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
const delivered = await ctx.respondPlain(finalText);
|
|
241
|
-
if (delivered) {
|
|
242
|
-
runState.finalResponseDelivered = true;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}, "final response");
|
|
235
|
+
runState.answerEmitted = true;
|
|
236
|
+
ctx.emit({ type: "answer", text: finalText });
|
|
246
237
|
}
|
|
247
238
|
return;
|
|
248
239
|
}
|
|
249
240
|
if (isAutoCompactionStartEvent(event)) {
|
|
250
|
-
const label = "正在压缩上下文…";
|
|
251
241
|
log.logEvent("info", "agent.compaction.started", "Compaction started", {
|
|
252
242
|
ctx: logCtx,
|
|
253
243
|
fields: { reason: event.reason },
|
|
254
244
|
});
|
|
255
|
-
|
|
256
|
-
queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", label), false), "compaction start");
|
|
257
|
-
}
|
|
245
|
+
ctx.emit({ type: "compaction", phase: "start" });
|
|
258
246
|
return;
|
|
259
247
|
}
|
|
260
248
|
if (isAutoCompactionEndEvent(event)) {
|
|
@@ -264,9 +252,11 @@ export async function handleSessionEvent(event, context) {
|
|
|
264
252
|
ctx: logCtx,
|
|
265
253
|
fields: { tokensBefore: event.result.tokensBefore },
|
|
266
254
|
});
|
|
255
|
+
ctx.emit({ type: "compaction", phase: "end", ok: true });
|
|
267
256
|
}
|
|
268
257
|
else if (event.aborted) {
|
|
269
258
|
log.logEvent("info", "agent.compaction.aborted", "Compaction aborted", { ctx: logCtx });
|
|
259
|
+
ctx.emit({ type: "compaction", phase: "end", ok: false });
|
|
270
260
|
}
|
|
271
261
|
else if (event.errorMessage) {
|
|
272
262
|
runState.lastCompactionError = event.errorMessage;
|
|
@@ -274,9 +264,8 @@ export async function handleSessionEvent(event, context) {
|
|
|
274
264
|
ctx: logCtx,
|
|
275
265
|
fields: { error: event.errorMessage },
|
|
276
266
|
});
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
267
|
+
ctx.emit({ type: "compaction", phase: "end", ok: false });
|
|
268
|
+
ctx.emit({ type: "commentary", text: renderCompactionFailure(event.errorMessage ?? ""), level: "error" });
|
|
280
269
|
}
|
|
281
270
|
return;
|
|
282
271
|
}
|
|
@@ -285,8 +274,6 @@ export async function handleSessionEvent(event, context) {
|
|
|
285
274
|
ctx: logCtx,
|
|
286
275
|
fields: { attempt: event.attempt, maxAttempts: event.maxAttempts, error: event.errorMessage },
|
|
287
276
|
});
|
|
288
|
-
|
|
289
|
-
queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", `模型请求失败,正在重试(${event.attempt}/${event.maxAttempts})…`), false), "retry");
|
|
290
|
-
}
|
|
277
|
+
ctx.emit({ type: "commentary", text: `模型请求失败,正在重试(${event.attempt}/${event.maxAttempts})…` });
|
|
291
278
|
}
|
|
292
279
|
}
|
|
@@ -7,14 +7,15 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { Agent, type AgentTool } from "@earendil-works/pi-agent-core";
|
|
9
9
|
import { AgentSession, type ModelRegistry, type SettingsManager as SDKSettingsManager, type SessionManager } from "@earendil-works/pi-coding-agent";
|
|
10
|
-
import type {
|
|
10
|
+
import type { SendMedia } from "../../channel/transport.js";
|
|
11
|
+
import type { TurnContext } from "../../channel/turn-context.js";
|
|
11
12
|
import type { PipiclawSettingsManager } from "../../config/settings.js";
|
|
13
|
+
import type { DeskConversation } from "../../desk/types.js";
|
|
12
14
|
import type { Executor } from "../../executor.js";
|
|
13
15
|
import type { FileStore } from "../../file-store.js";
|
|
14
|
-
import type {
|
|
16
|
+
import type { DeskJobManager } from "../../jobs/manager.js";
|
|
15
17
|
import type { MemoryLifecycle } from "../../memory/lifecycle.js";
|
|
16
18
|
import type { LoadedSecurityConfig } from "../../security/config.js";
|
|
17
|
-
import type { ProjectScope } from "../../security/project-scope.js";
|
|
18
19
|
import { type PipiclawSkillsResult } from "../../skills/loader.js";
|
|
19
20
|
import { type SubAgentDiscoveryResult } from "../../subagents/discovery.js";
|
|
20
21
|
import type { SubAgentRunManager } from "../../subagents/runs.js";
|
|
@@ -22,30 +23,27 @@ import type { UsageLedger } from "../../usage/ledger.js";
|
|
|
22
23
|
import { type WorkspacePromptResources } from "../prompt/resources.js";
|
|
23
24
|
import type { PromptBuildResult } from "../prompt/types.js";
|
|
24
25
|
import type { RunState } from "../types.js";
|
|
26
|
+
import { SessionCompaction } from "./compaction.js";
|
|
25
27
|
import type { ModelSelection } from "./model-selection.js";
|
|
26
|
-
/** Surface settings.json load errors (once drained) as warnings; shared by construction and reload. */
|
|
27
|
-
export declare function reportSettingsDiagnostics(settingsManager: PipiclawSettingsManager, channelId: string, appHomeDir: string): void;
|
|
28
28
|
export interface SessionHostDeps {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
requestScoped?: boolean;
|
|
30
|
+
conversation: DeskConversation;
|
|
31
31
|
workspaceDir: string;
|
|
32
32
|
appHomeDir: string;
|
|
33
33
|
authConfigPath: string;
|
|
34
34
|
modelsConfigPath: string;
|
|
35
35
|
onSessionEvent?: (event: unknown, channelId: string) => void;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*/
|
|
42
|
-
projectScope: ProjectScope;
|
|
36
|
+
sendMedia?: SendMedia;
|
|
37
|
+
/** The agent's working directory: SDK session and resource-loader cwd, and the tools' relative-path base. */
|
|
38
|
+
cwd: string;
|
|
39
|
+
/** A conversation directory's channel name, for labelling `session_search` hits. */
|
|
40
|
+
describeConversation?: (conversation: string) => string | undefined;
|
|
43
41
|
settingsManager: PipiclawSettingsManager;
|
|
44
42
|
/** Re-read per use, not captured once: an edited security.json takes effect without a restart. */
|
|
45
43
|
loadSecurityConfig: () => LoadedSecurityConfig;
|
|
46
44
|
executor: Executor;
|
|
47
45
|
fileStore: FileStore;
|
|
48
|
-
jobManager:
|
|
46
|
+
jobManager: DeskJobManager;
|
|
49
47
|
runManager: SubAgentRunManager;
|
|
50
48
|
memoryLifecycle: MemoryLifecycle;
|
|
51
49
|
models: ModelSelection;
|
|
@@ -59,16 +57,21 @@ export interface SessionHostDeps {
|
|
|
59
57
|
}
|
|
60
58
|
export declare class SessionHost {
|
|
61
59
|
private readonly deps;
|
|
60
|
+
private readonly contextInput;
|
|
61
|
+
private readonly conversation;
|
|
62
62
|
private readonly channelId;
|
|
63
|
-
private readonly
|
|
63
|
+
private readonly deskDir;
|
|
64
|
+
/** Sessions and the active-session pointer live here; tasks, memory and tools use `deskDir`. */
|
|
65
|
+
private readonly conversationDir;
|
|
64
66
|
private readonly workspaceDir;
|
|
67
|
+
private readonly describeConversation?;
|
|
65
68
|
private readonly appHomeDir;
|
|
66
69
|
private readonly authConfigPath;
|
|
67
70
|
private readonly modelsConfigPath;
|
|
68
71
|
private readonly onSessionEvent?;
|
|
69
|
-
private readonly
|
|
70
|
-
private readonly
|
|
71
|
-
|
|
72
|
+
private readonly sendMedia?;
|
|
73
|
+
private readonly cwd;
|
|
74
|
+
readonly settingsManager: PipiclawSettingsManager;
|
|
72
75
|
private readonly loadSecurityConfig;
|
|
73
76
|
private readonly executor;
|
|
74
77
|
private readonly fileStore;
|
|
@@ -103,7 +106,9 @@ export declare class SessionHost {
|
|
|
103
106
|
/** The exact system prompt the provider last received (our prompt + pi's tail + footer). */
|
|
104
107
|
lastFinalPrompt?: string;
|
|
105
108
|
currentTools: AgentTool<any>[];
|
|
109
|
+
private retired;
|
|
106
110
|
firstTurnMemoryBootstrapPending: boolean;
|
|
111
|
+
readonly compaction: SessionCompaction;
|
|
107
112
|
/** Mirror of `tools.tasks.enabled` from the last tools-config load (see buildRuntimeTools). */
|
|
108
113
|
tasksEnabled: boolean;
|
|
109
114
|
/**
|
|
@@ -118,11 +123,13 @@ export declare class SessionHost {
|
|
|
118
123
|
constructor(deps: SessionHostDeps);
|
|
119
124
|
private get runState();
|
|
120
125
|
get agent(): Agent;
|
|
126
|
+
importContext(context: TurnContext): void;
|
|
127
|
+
promptContext(context: TurnContext, submit?: () => Promise<void>): Promise<void>;
|
|
121
128
|
get sessionManager(): SessionManager;
|
|
122
129
|
/** Kick off asynchronous session construction. The first message can arrive before it settles. */
|
|
123
130
|
start(sessionManager: SessionManager): void;
|
|
124
131
|
private readonly contextFaults;
|
|
125
|
-
markContextFault(session: AgentSession, error: unknown): Error;
|
|
132
|
+
markContextFault(session: AgentSession, error: unknown, stage?: string): Error;
|
|
126
133
|
assertContextHealthy(): void;
|
|
127
134
|
/** Run a prompt (or steer) with the resource gate and the context-fault guard. */
|
|
128
135
|
runPrompt<T>(fn: () => Promise<T>): Promise<T>;
|
|
@@ -140,18 +147,7 @@ export declare class SessionHost {
|
|
|
140
147
|
private bindSessionExtensions;
|
|
141
148
|
ensureSessionReady(): Promise<void>;
|
|
142
149
|
private refreshSubAgentDiscovery;
|
|
143
|
-
|
|
144
|
-
private reportConfigDiagnostics;
|
|
145
|
-
/**
|
|
146
|
-
* Build the Pipiclaw-owned system prompt (spec 025). This replaces pi's default
|
|
147
|
-
* base prompt entirely: identity, execution contract, hard invariants, the tool
|
|
148
|
-
* catalog and the workspace files are ours. pi still appends its tail (skills,
|
|
149
|
-
* date, cwd), and the boundary footer is appended after that by the prompt
|
|
150
|
-
* extension.
|
|
151
|
-
*
|
|
152
|
-
* Nothing channel-specific enters this text — that is what lets two channels in
|
|
153
|
-
* one workspace share a cached prompt prefix. Channel facts ride the turn.
|
|
154
|
-
*/
|
|
150
|
+
/** Build the shared Pipiclaw prompt; channel facts stay in turn context and pi appends its tail. */
|
|
155
151
|
buildSystemPrompt(): PromptBuildResult;
|
|
156
152
|
private createResourceLoader;
|
|
157
153
|
private createAgentSessionServices;
|
|
@@ -173,15 +169,7 @@ export declare class SessionHost {
|
|
|
173
169
|
*/
|
|
174
170
|
private initializeThinkingLevel;
|
|
175
171
|
private createSessionRuntime;
|
|
176
|
-
/**
|
|
177
|
-
* Bind this runner to a task cycle's own session (spec 051, D3/INV-5).
|
|
178
|
-
*
|
|
179
|
-
* Task work must not accumulate in the channel's chat transcript: the one real channel on the
|
|
180
|
-
* author's machine had grown to 7.4 MB and been compacted six times because chat and two daily
|
|
181
|
-
* tasks shared it, so every compaction damaged all three at once. Swapping the bound session
|
|
182
|
-
* per turn gives each task its own bounded context while leaving turn state, `/stop`, and
|
|
183
|
-
* delivery exactly where they already are.
|
|
184
|
-
*/
|
|
172
|
+
/** Bind a task to its own transcript, keeping scheduled work out of the chat history. */
|
|
185
173
|
bindTaskSession(taskId: string): Promise<void>;
|
|
186
174
|
/** Return to the channel's chat session after a task step. Safe to call when already bound. */
|
|
187
175
|
bindChatSession(): Promise<void>;
|