@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
|
@@ -7,7 +7,7 @@
|
|
|
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,
|
|
10
|
+
import { AgentSession, AgentSessionRuntime, DefaultResourceLoader, } from "@earendil-works/pi-coding-agent";
|
|
11
11
|
import { mkdir } from "fs/promises";
|
|
12
12
|
import { dirname, join } from "path";
|
|
13
13
|
import { commitActiveSessionRef, resolveActiveSessionFile } from "../../channel/active-session-store.js";
|
|
@@ -18,7 +18,6 @@ import { hasMemoryBootstrapBlock } from "../../memory/render.js";
|
|
|
18
18
|
import { getApiKeyForModel } from "../../models/api-keys.js";
|
|
19
19
|
import { findExactModelReferenceMatch, hasKnownModelPricing } from "../../models/reference.js";
|
|
20
20
|
import { createModelRuntime, resolveInitialModel, wrapModelRegistry } from "../../models/runtime.js";
|
|
21
|
-
import { formatConfigDiagnostic } from "../../shared/config-diagnostic.js";
|
|
22
21
|
import { errorMessage } from "../../shared/text-utils.js";
|
|
23
22
|
import { isRecord } from "../../shared/type-guards.js";
|
|
24
23
|
import { withTimeout } from "../../shared/with-timeout.js";
|
|
@@ -31,10 +30,14 @@ import { createPromptBoundaryExtension } from "../prompt/extension.js";
|
|
|
31
30
|
import { measureToolSchemas, TOOL_SCHEMA_TARGET_UNITS, toolSchemaBudgetWarning } from "../prompt/manifest.js";
|
|
32
31
|
import { loadPlaybooks, loadWorkspacePromptResources } from "../prompt/resources.js";
|
|
33
32
|
import { createCommandExtension } from "./command-extension.js";
|
|
33
|
+
import { SessionCompaction } from "./compaction.js";
|
|
34
|
+
import { RequestContextInput } from "./context-input.js";
|
|
34
35
|
import { getLastAssistantUsage, isAutoCompactionEndEvent } from "./event-guards.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,14 @@ 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 `<
|
|
54
|
+
/** Task sessions live under `<deskDir>/tasks/.sessions/`; nothing else may be mistaken for one. */
|
|
52
55
|
function isTaskSessionPath(sessionFile) {
|
|
53
56
|
return sessionFile?.replace(/\\/g, "/").includes(`/${TASK_SESSIONS_DIRNAME}/`) === true;
|
|
54
57
|
}
|
|
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
58
|
export class SessionHost {
|
|
66
59
|
constructor(deps) {
|
|
67
60
|
this.deps = deps;
|
|
61
|
+
this.contextInput = new RequestContextInput();
|
|
68
62
|
/**
|
|
69
63
|
* Flips true only once `initializeSession` has fully assigned `this.session`
|
|
70
64
|
* and loaded its resources. Synchronous dispatch-path callers (`isKnownSlashCommand`)
|
|
@@ -73,19 +67,23 @@ export class SessionHost {
|
|
|
73
67
|
*/
|
|
74
68
|
this.sessionInitialized = false;
|
|
75
69
|
this.currentTools = [];
|
|
70
|
+
this.retired = false;
|
|
76
71
|
this.firstTurnMemoryBootstrapPending = true;
|
|
77
72
|
/** Mirror of `tools.tasks.enabled` from the last tools-config load (see buildRuntimeTools). */
|
|
78
73
|
this.tasksEnabled = true;
|
|
79
74
|
this.contextFaults = new WeakSet();
|
|
80
|
-
this.
|
|
81
|
-
this.
|
|
75
|
+
this.conversation = deps.conversation;
|
|
76
|
+
this.channelId = deps.conversation.channelId;
|
|
77
|
+
this.deskDir = deps.conversation.deskDir;
|
|
78
|
+
this.conversationDir = deps.conversation.conversationDir;
|
|
82
79
|
this.workspaceDir = deps.workspaceDir;
|
|
80
|
+
this.describeConversation = deps.describeConversation;
|
|
83
81
|
this.appHomeDir = deps.appHomeDir;
|
|
84
82
|
this.authConfigPath = deps.authConfigPath;
|
|
85
83
|
this.modelsConfigPath = deps.modelsConfigPath;
|
|
86
84
|
this.onSessionEvent = deps.onSessionEvent;
|
|
87
|
-
this.
|
|
88
|
-
this.
|
|
85
|
+
this.sendMedia = deps.sendMedia;
|
|
86
|
+
this.cwd = deps.cwd;
|
|
89
87
|
this.settingsManager = deps.settingsManager;
|
|
90
88
|
this.loadSecurityConfig = deps.loadSecurityConfig;
|
|
91
89
|
this.executor = deps.executor;
|
|
@@ -96,6 +94,20 @@ export class SessionHost {
|
|
|
96
94
|
this.models = deps.models;
|
|
97
95
|
this.ledger = deps.ledger;
|
|
98
96
|
this.currentSkills = deps.initialSkills;
|
|
97
|
+
this.compaction = new SessionCompaction({
|
|
98
|
+
conversation: this.conversation,
|
|
99
|
+
getSession: () => this.session,
|
|
100
|
+
getRuntime: () => this.modelRuntime,
|
|
101
|
+
preserveMemory: (event) => this.memoryLifecycle.prepareCompaction(event),
|
|
102
|
+
ledger: this.ledger,
|
|
103
|
+
getRunState: () => this.runState,
|
|
104
|
+
isEnabled: () => this.settingsManager.getCompactionEnabled(),
|
|
105
|
+
onPersistenceFault: (session, error) => this.markContextFault(session, error, "background-compaction"),
|
|
106
|
+
onAdopt: () => {
|
|
107
|
+
this.firstTurnMemoryBootstrapPending = true;
|
|
108
|
+
void this.memoryLifecycle.resumeBoundaryReflect();
|
|
109
|
+
},
|
|
110
|
+
});
|
|
99
111
|
this.sessionResourceGate = new SessionResourceGate(async () => {
|
|
100
112
|
await this.reloadSessionResources();
|
|
101
113
|
});
|
|
@@ -106,6 +118,12 @@ export class SessionHost {
|
|
|
106
118
|
get agent() {
|
|
107
119
|
return this.session.agent;
|
|
108
120
|
}
|
|
121
|
+
importContext(context) {
|
|
122
|
+
this.contextInput.import(this.session, context);
|
|
123
|
+
}
|
|
124
|
+
async promptContext(context, submit) {
|
|
125
|
+
await this.contextInput.prompt(this.session, context, submit ? "" : (this.lastPromptBuild?.footer ?? ""), submit);
|
|
126
|
+
}
|
|
109
127
|
get sessionManager() {
|
|
110
128
|
return this.session.sessionManager;
|
|
111
129
|
}
|
|
@@ -113,12 +131,12 @@ export class SessionHost {
|
|
|
113
131
|
start(sessionManager) {
|
|
114
132
|
this.sessionReady = this.initializeSession(sessionManager);
|
|
115
133
|
}
|
|
116
|
-
markContextFault(session, error) {
|
|
134
|
+
markContextFault(session, error, stage = "fallback-context-edit") {
|
|
117
135
|
this.contextFaults.add(session);
|
|
118
136
|
log.logWarn("agent.session.context_failed", "Session context persistence failed", {
|
|
119
137
|
channelId: this.channelId,
|
|
120
138
|
reason: errorMessage(error),
|
|
121
|
-
fields: { sessionId: session.sessionManager.getSessionId(), stage
|
|
139
|
+
fields: { sessionId: session.sessionManager.getSessionId(), stage },
|
|
122
140
|
});
|
|
123
141
|
return new Error(CONTEXT_FAULT_MESSAGE, { cause: error });
|
|
124
142
|
}
|
|
@@ -135,9 +153,11 @@ export class SessionHost {
|
|
|
135
153
|
}
|
|
136
154
|
/** Stop listening to the live session and dispose it (no-op error handling is the caller's). */
|
|
137
155
|
retireLiveSession() {
|
|
156
|
+
this.retired = true;
|
|
157
|
+
this.compaction.retire();
|
|
138
158
|
this.sessionUnsubscribe?.();
|
|
139
159
|
this.sessionUnsubscribe = undefined;
|
|
140
|
-
this.session
|
|
160
|
+
this.session?.dispose();
|
|
141
161
|
}
|
|
142
162
|
/**
|
|
143
163
|
* Release the session once idle. Guards a dispose() racing construction: initializeSession
|
|
@@ -145,6 +165,7 @@ export class SessionHost {
|
|
|
145
165
|
* not have one yet.
|
|
146
166
|
*/
|
|
147
167
|
async disposeSession() {
|
|
168
|
+
this.compaction.retire();
|
|
148
169
|
await this.sessionReady;
|
|
149
170
|
this.sessionUnsubscribe?.();
|
|
150
171
|
this.sessionUnsubscribe = undefined;
|
|
@@ -175,7 +196,13 @@ export class SessionHost {
|
|
|
175
196
|
this.subAgentDiscovery = await this.refreshSubAgentDiscovery();
|
|
176
197
|
const initial = await this.createSessionRuntime(sessionManager);
|
|
177
198
|
this.session = initial.session;
|
|
199
|
+
if (this.retired) {
|
|
200
|
+
this.session.dispose();
|
|
201
|
+
throw new Error("Session generation retired");
|
|
202
|
+
}
|
|
178
203
|
this.sessionRuntime = new AgentSessionRuntime(this.session, this.createAgentSessionServices(initial.resourceLoader), async ({ sessionManager, sessionStartEvent }) => {
|
|
204
|
+
if (this.retired)
|
|
205
|
+
throw new Error("Session generation retired");
|
|
179
206
|
// `/new`, fork, and switch already wrote the target session's durable header by
|
|
180
207
|
// this point (the SDK does it synchronously before invoking this callback); commit
|
|
181
208
|
// the pointer before we rebuild and rebind to it, so a crash between "SDK created
|
|
@@ -185,7 +212,7 @@ export class SessionHost {
|
|
|
185
212
|
// ref at it, or `/new` and restart recovery would adopt a task's transcript as the
|
|
186
213
|
// conversation (spec 051, D3).
|
|
187
214
|
if (!isTaskSessionPath(sessionManager.getSessionFile())) {
|
|
188
|
-
await commitActiveSessionRef(this.
|
|
215
|
+
await commitActiveSessionRef(this.conversationDir, sessionManager);
|
|
189
216
|
}
|
|
190
217
|
const next = await this.createSessionRuntime(sessionManager, sessionStartEvent);
|
|
191
218
|
return {
|
|
@@ -196,6 +223,11 @@ export class SessionHost {
|
|
|
196
223
|
};
|
|
197
224
|
});
|
|
198
225
|
this.sessionRuntime.setRebindSession(async (session) => {
|
|
226
|
+
this.compaction.cancel("session-rebind");
|
|
227
|
+
if (this.retired) {
|
|
228
|
+
session.dispose();
|
|
229
|
+
throw new Error("Session generation retired");
|
|
230
|
+
}
|
|
199
231
|
this.session = session;
|
|
200
232
|
await this.bindSessionExtensions();
|
|
201
233
|
this.subscribeToSessionEvents();
|
|
@@ -210,11 +242,15 @@ export class SessionHost {
|
|
|
210
242
|
this.sessionInitialized = true;
|
|
211
243
|
}
|
|
212
244
|
async reloadSessionResources() {
|
|
245
|
+
if (this.retired)
|
|
246
|
+
return;
|
|
213
247
|
this.settingsManager.reload();
|
|
214
|
-
this.
|
|
215
|
-
const skills = loadPipiclawSkills(this.
|
|
248
|
+
reportSettingsDiagnostics(this.settingsManager, this.channelId, this.appHomeDir);
|
|
249
|
+
const skills = loadPipiclawSkills(this.workspaceDir);
|
|
216
250
|
this.currentSkills = skills;
|
|
217
251
|
this.subAgentDiscovery = await this.refreshSubAgentDiscovery();
|
|
252
|
+
if (this.retired)
|
|
253
|
+
return;
|
|
218
254
|
this.rebuildSessionTools();
|
|
219
255
|
try {
|
|
220
256
|
await withTimeout(`[${this.channelId}] session reload`, SESSION_RELOAD_TIMEOUT_MS, () => this.session.reload());
|
|
@@ -277,27 +313,7 @@ export class SessionHost {
|
|
|
277
313
|
}
|
|
278
314
|
return discovery;
|
|
279
315
|
}
|
|
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
|
-
*/
|
|
316
|
+
/** Build the shared Pipiclaw prompt; channel facts stay in turn context and pi appends its tail. */
|
|
301
317
|
buildSystemPrompt() {
|
|
302
318
|
const toolNames = this.currentTools.map((tool) => tool.name);
|
|
303
319
|
const resources = loadWorkspacePromptResources(this.workspaceDir);
|
|
@@ -338,10 +354,11 @@ export class SessionHost {
|
|
|
338
354
|
}
|
|
339
355
|
createResourceLoader() {
|
|
340
356
|
return new DefaultResourceLoader({
|
|
341
|
-
cwd: this.
|
|
357
|
+
cwd: this.cwd,
|
|
342
358
|
agentDir: this.appHomeDir,
|
|
343
359
|
settingsManager: asSdkSettingsManager(this.settingsManager),
|
|
344
360
|
extensionFactories: [
|
|
361
|
+
this.compaction.createExtensionFactory(),
|
|
345
362
|
this.memoryLifecycle.createExtensionFactory(),
|
|
346
363
|
createPromptBoundaryExtension({
|
|
347
364
|
getFooter: () => this.lastPromptBuild?.footer ?? "",
|
|
@@ -371,8 +388,7 @@ export class SessionHost {
|
|
|
371
388
|
await this.refreshSessionResources();
|
|
372
389
|
},
|
|
373
390
|
runMemoryCommand: async (args) => handleMemoryCommand({
|
|
374
|
-
|
|
375
|
-
channelDir: this.channelDir,
|
|
391
|
+
conversation: this.conversation,
|
|
376
392
|
appHomeDir: this.appHomeDir,
|
|
377
393
|
args,
|
|
378
394
|
}),
|
|
@@ -402,7 +418,7 @@ export class SessionHost {
|
|
|
402
418
|
}
|
|
403
419
|
createAgentSessionServices(resourceLoader) {
|
|
404
420
|
return {
|
|
405
|
-
cwd: this.
|
|
421
|
+
cwd: this.cwd,
|
|
406
422
|
agentDir: this.appHomeDir,
|
|
407
423
|
settingsManager: asSdkSettingsManager(this.settingsManager),
|
|
408
424
|
modelRuntime: this.modelRuntime,
|
|
@@ -440,6 +456,8 @@ export class SessionHost {
|
|
|
440
456
|
initializeThinkingLevelCompat(agent, model, sessionManager, this.settingsManager.getDefaultThinkingLevel());
|
|
441
457
|
}
|
|
442
458
|
async createSessionRuntime(sessionManager, sessionStartEvent) {
|
|
459
|
+
if (this.retired)
|
|
460
|
+
throw new Error("Session generation retired");
|
|
443
461
|
const tools = this.buildRuntimeTools();
|
|
444
462
|
const agent = new Agent({
|
|
445
463
|
initialState: {
|
|
@@ -449,7 +467,7 @@ export class SessionHost {
|
|
|
449
467
|
tools: [],
|
|
450
468
|
messages: sessionManager.buildSessionContext().messages,
|
|
451
469
|
},
|
|
452
|
-
convertToLlm,
|
|
470
|
+
convertToLlm: (messages) => this.contextInput.convert(messages),
|
|
453
471
|
getApiKey: async () => getApiKeyForModel(this.modelRegistry, this.models.activeModel),
|
|
454
472
|
streamFn: streamSimple,
|
|
455
473
|
});
|
|
@@ -458,12 +476,14 @@ export class SessionHost {
|
|
|
458
476
|
// Must precede `new AgentSession`: the session snapshots the loader's extensions in its
|
|
459
477
|
// constructor (see `loadSessionResources`).
|
|
460
478
|
await this.loadSessionResources(resourceLoader);
|
|
479
|
+
if (this.retired)
|
|
480
|
+
throw new Error("Session generation retired");
|
|
461
481
|
const sessionSettingsManager = asSdkSettingsManager(this.settingsManager);
|
|
462
482
|
const session = new AgentSession({
|
|
463
483
|
agent,
|
|
464
484
|
sessionManager,
|
|
465
485
|
settingsManager: sessionSettingsManager,
|
|
466
|
-
cwd: this.
|
|
486
|
+
cwd: this.cwd,
|
|
467
487
|
modelRuntime: this.modelRuntime,
|
|
468
488
|
resourceLoader,
|
|
469
489
|
baseToolsOverride: Object.fromEntries(tools.map((tool) => [tool.name, tool])),
|
|
@@ -473,18 +493,12 @@ export class SessionHost {
|
|
|
473
493
|
this.sessionSettingsManager = sessionSettingsManager;
|
|
474
494
|
return { session, resourceLoader };
|
|
475
495
|
}
|
|
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
|
-
*/
|
|
496
|
+
/** Bind a task to its own transcript, keeping scheduled work out of the chat history. */
|
|
485
497
|
async bindTaskSession(taskId) {
|
|
486
498
|
await this.sessionReady;
|
|
487
|
-
|
|
499
|
+
if (this.retired)
|
|
500
|
+
return;
|
|
501
|
+
const path = taskSessionPath(this.deskDir, taskId);
|
|
488
502
|
await mkdir(dirname(path), { recursive: true });
|
|
489
503
|
this.taskLoop = { taskId };
|
|
490
504
|
await this.sessionRuntime.switchSession(path);
|
|
@@ -492,10 +506,10 @@ export class SessionHost {
|
|
|
492
506
|
}
|
|
493
507
|
/** Return to the channel's chat session after a task step. Safe to call when already bound. */
|
|
494
508
|
async bindChatSession() {
|
|
495
|
-
if (!this.taskLoop)
|
|
509
|
+
if (this.retired || !this.taskLoop)
|
|
496
510
|
return;
|
|
497
511
|
this.taskLoop = undefined;
|
|
498
|
-
await this.sessionRuntime.switchSession(join(this.
|
|
512
|
+
await this.sessionRuntime.switchSession(join(this.conversationDir, resolveActiveSessionFile(this.conversationDir)));
|
|
499
513
|
this.syncMemoryBootstrapPendingFromSession();
|
|
500
514
|
}
|
|
501
515
|
/** Bootstrap presence follows canonical context, including omissions and compaction.
|
|
@@ -518,7 +532,7 @@ export class SessionHost {
|
|
|
518
532
|
buildRuntimeTools() {
|
|
519
533
|
const securityLoad = this.loadSecurityConfig();
|
|
520
534
|
const toolsLoad = loadToolsConfigWithDiagnostics(this.appHomeDir);
|
|
521
|
-
|
|
535
|
+
reportConfigDiagnostics([...securityLoad.diagnostics, ...toolsLoad.diagnostics], this.channelId);
|
|
522
536
|
this.tasksEnabled = toolsLoad.config.tools.tasks.enabled;
|
|
523
537
|
const tools = createPipiclawTools({
|
|
524
538
|
jobManager: this.jobManager,
|
|
@@ -529,33 +543,36 @@ export class SessionHost {
|
|
|
529
543
|
getAvailableModels: () => this.modelRegistry.getAvailable(),
|
|
530
544
|
resolveApiKey: async (model) => getApiKeyForModel(this.modelRegistry, model),
|
|
531
545
|
workspaceDir: this.workspaceDir,
|
|
532
|
-
|
|
533
|
-
|
|
546
|
+
cwd: this.cwd,
|
|
547
|
+
desk: this.conversation.desk,
|
|
548
|
+
deskDir: this.deskDir,
|
|
534
549
|
channelId: this.channelId,
|
|
550
|
+
describeConversation: this.describeConversation,
|
|
535
551
|
getSubAgentDiscovery: () => this.subAgentDiscovery,
|
|
536
552
|
getSubAgentModelReference: () => this.settingsManager.getSubAgentModelReference(),
|
|
537
553
|
resolveFallbackModel: () => this.models.resolveFallbackModel(),
|
|
538
554
|
getSessionSearchSettings: () => this.settingsManager.getSessionSearchSettings(),
|
|
539
555
|
securityConfig: securityLoad.config,
|
|
540
556
|
toolsConfig: toolsLoad.config,
|
|
541
|
-
|
|
557
|
+
sendMedia: this.sendMedia,
|
|
542
558
|
taskLoop: this.taskLoop,
|
|
543
559
|
getToolsUsed: () => this.runState.toolsUsed,
|
|
544
560
|
// Assistant usage only: an internal sub-agent's cost is also in `totalUsage`, and a bound
|
|
545
561
|
// one is already credited to the task when it settles.
|
|
546
562
|
getStepCost: () => ({ usd: this.runState.assistantUsage.cost.total, estimated: !this.runState.costKnown }),
|
|
547
563
|
});
|
|
548
|
-
this.
|
|
564
|
+
const active = this.deps.requestScoped ? requestTools(tools) : tools;
|
|
565
|
+
this.currentTools = active;
|
|
549
566
|
// Tool schemas are billed with the system prompt and, unlike it, nothing trims them.
|
|
550
567
|
// Warn where the prompt's own budget diagnostics are reported, once per tool rebuild.
|
|
551
|
-
const schemas = measureToolSchemas(
|
|
568
|
+
const schemas = measureToolSchemas(active);
|
|
552
569
|
if (schemas.units > TOOL_SCHEMA_TARGET_UNITS) {
|
|
553
570
|
log.logWarn("agent.tools.schema_over_budget", "Tool schemas over budget", {
|
|
554
571
|
channelId: this.channelId,
|
|
555
572
|
reason: toolSchemaBudgetWarning(schemas),
|
|
556
573
|
});
|
|
557
574
|
}
|
|
558
|
-
return
|
|
575
|
+
return active;
|
|
559
576
|
}
|
|
560
577
|
rebuildSessionTools() {
|
|
561
578
|
const tools = this.buildRuntimeTools();
|
|
@@ -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,8 +10,10 @@ 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. */
|
|
@@ -20,10 +20,13 @@ function relativeTime(atMs, now) {
|
|
|
20
20
|
return `${hours}h`;
|
|
21
21
|
return `${Math.round(hours / 24)}d`;
|
|
22
22
|
}
|
|
23
|
-
function renderLine(entry, now) {
|
|
23
|
+
function renderLine(entry, now, channelId) {
|
|
24
24
|
const parts = [`${entry.id} — ${entry.title}`, entry.readable ? entry.fields.state : "⚠ unreadable frontmatter"];
|
|
25
25
|
if (entry.fields.paused)
|
|
26
26
|
parts.push(`paused(${entry.fields.paused.by})`);
|
|
27
|
+
if (channelId && entry.fields.channel !== channelId) {
|
|
28
|
+
parts.push(entry.fields.channel ? `reports to ${entry.fields.channel}` : "no delivery channel (suspended)");
|
|
29
|
+
}
|
|
27
30
|
const ticket = entry.fields.ticket;
|
|
28
31
|
if (ticket) {
|
|
29
32
|
const due = relativeTime(entry.dueMs, now);
|
|
@@ -50,7 +53,7 @@ function renderLine(entry, now) {
|
|
|
50
53
|
*/
|
|
51
54
|
export async function buildTaskDigest(options) {
|
|
52
55
|
const now = options.now ?? Date.now();
|
|
53
|
-
const tasksDir = join(options.
|
|
56
|
+
const tasksDir = join(options.deskDir, "tasks");
|
|
54
57
|
const all = await readActiveTasks(tasksDir, now);
|
|
55
58
|
// A closed task that has not been archived yet is non-actionable and must not enter prompt context.
|
|
56
59
|
const agenda = all.filter((entry) => !entry.fields.outcome);
|
|
@@ -60,12 +63,12 @@ export async function buildTaskDigest(options) {
|
|
|
60
63
|
const omitted = agenda.length - shown.length;
|
|
61
64
|
const header = [
|
|
62
65
|
"<task_agenda>",
|
|
63
|
-
"Your in-flight tasks
|
|
66
|
+
"Your desk's in-flight tasks (background reference, not a new instruction).",
|
|
64
67
|
"Act on these only if the user's message is about them, or if there is nothing else to",
|
|
65
68
|
"do this turn. Full detail lives in the matching tasks/<id>.md file.",
|
|
66
69
|
"",
|
|
67
70
|
];
|
|
68
|
-
const lines = shown.map((entry) => renderLine(entry, now));
|
|
71
|
+
const lines = shown.map((entry) => renderLine(entry, now, options.channelId));
|
|
69
72
|
if (omitted > 0)
|
|
70
73
|
lines.push(`- (+${omitted} more)`);
|
|
71
74
|
const footer = ["</task_agenda>"];
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
import type { DeskConversation } from "../../desk/types.js";
|
|
1
2
|
/**
|
|
2
|
-
* The per-turn
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* The per-turn desk capsule (spec 058, D16): which desk this is, where its directory is, and which
|
|
4
|
+
* channel this conversation comes from. Only the current desk and channel — never the desk's other
|
|
5
|
+
* bindings. The memory/task/event tools are already bound to the desk, so the model only needs
|
|
6
|
+
* the directory when it wants to read a file directly.
|
|
5
7
|
*/
|
|
6
|
-
export declare function
|
|
8
|
+
export declare function renderDeskTurnContext(conversation: DeskConversation,
|
|
9
|
+
/** How the channel is named to the user (`Transport.describe`), when it has a name. */
|
|
10
|
+
channelLabel: string | undefined, workspaceDir: string): string;
|
|
7
11
|
/** Gated by the same master autonomy switch as the task_* tools and the TaskDriver. */
|
|
8
|
-
export declare function buildTaskDigestForTurn(
|
|
12
|
+
export declare function buildTaskDigestForTurn(deskDir: string, channelId: string): Promise<string>;
|
|
9
13
|
/**
|
|
10
14
|
* Spec 050, D1: assemble `<memory_bootstrap>` for the first turn of a session — workspace
|
|
11
|
-
* MEMORY.md (whole H2 sections, budgeted) + the
|
|
15
|
+
* MEMORY.md (whole H2 sections, budgeted) + the desk memory index (full, or budget-tiered) +
|
|
12
16
|
* today's journal tail.
|
|
13
17
|
*/
|
|
14
|
-
export declare function buildFirstTurnMemoryBootstrap(
|
|
18
|
+
export declare function buildFirstTurnMemoryBootstrap(deskDir: string, workspaceDir: string): Promise<string>;
|