@oyasmi/pipiclaw 0.9.4-beta.2 → 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 +9 -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
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The daemon's per-channel turn handler: what happens when the DingTalk transport hands the runtime
|
|
3
|
-
* a message, `/stop`, `/new`, a busy-turn message, or a synthetic wake. Wired together (and handed
|
|
4
|
-
* its collaborators) by `bootstrap.ts`.
|
|
5
|
-
*/
|
|
6
|
-
import { join } from "path";
|
|
7
|
-
import { createFreshActiveSession } from "../channel/active-session-store.js";
|
|
8
|
-
import { ensureChannelDir, getChannelDir } from "../channel/channel-paths.js";
|
|
9
|
-
import { resolveProjectScope } from "../channel/project-scope-store.js";
|
|
10
|
-
import { formatMissingQueueMessage, formatNewSessionReply, formatSteerQueued, } from "../commands/catalog.js";
|
|
11
|
-
import { runReportCommand } from "../commands/router.js";
|
|
12
|
-
import * as log from "../log.js";
|
|
13
|
-
import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
|
|
14
|
-
import { resolveProjectAccessPolicy } from "../security/project-scope.js";
|
|
15
|
-
import { errorMessage } from "../shared/text-utils.js";
|
|
16
|
-
import { readActiveTasks } from "../tasks/contract.js";
|
|
17
|
-
import { pauseTask as pauseStoredTask } from "../tasks/store.js";
|
|
18
|
-
import { persistInboundImage, relativeImagePaths } from "./inbound-images.js";
|
|
19
|
-
import { forceEndStuckTurnAfterStop } from "./stop-watchdog.js";
|
|
20
|
-
import { createTaskDriverEvent, parseDriverTaskId } from "./task-driver.js";
|
|
21
|
-
import { createEventTurnRunner } from "./turn-run.js";
|
|
22
|
-
function isNoRunningTaskQueueError(err) {
|
|
23
|
-
return err instanceof Error && err.message === "No task is currently running.";
|
|
24
|
-
}
|
|
25
|
-
export function createTurnHandler(deps) {
|
|
26
|
-
const { options, store, channelRunners, sessionResetChains, activeTasks, stopWatchdogs, channelIndex, archiveIncomingMessage, getRunner, cliVersion, startedAt, isShuttingDown, getDurableDispatch, getJobs, getRuns, getTaskDriver, } = deps;
|
|
27
|
-
const runEventTurn = createEventTurnRunner({
|
|
28
|
-
options,
|
|
29
|
-
store,
|
|
30
|
-
activeTasks,
|
|
31
|
-
archiveIncomingMessage,
|
|
32
|
-
getRunner,
|
|
33
|
-
isShuttingDown,
|
|
34
|
-
getDurableDispatch,
|
|
35
|
-
getJobs,
|
|
36
|
-
getRuns,
|
|
37
|
-
getTaskDriver,
|
|
38
|
-
runRuntimeCommand: (event, name, args) => handler.runRuntimeCommand(event, name, args),
|
|
39
|
-
});
|
|
40
|
-
const handler = {
|
|
41
|
-
isRunning(channelId) {
|
|
42
|
-
return channelRunners.get(channelId)?.isBusy() ?? false;
|
|
43
|
-
},
|
|
44
|
-
noteChannelActivity(observation) {
|
|
45
|
-
if (isShuttingDown())
|
|
46
|
-
return;
|
|
47
|
-
channelIndex.note(observation);
|
|
48
|
-
},
|
|
49
|
-
async handleStop(channelId, _bot) {
|
|
50
|
-
const runner = channelRunners.get(channelId);
|
|
51
|
-
let pausedTaskId;
|
|
52
|
-
if (runner?.isBusy()) {
|
|
53
|
-
runner.requestStop();
|
|
54
|
-
// Stopping a task step stops the task: otherwise the driver would queue the next step
|
|
55
|
-
// straight away. The step may not be bound to its session yet, so fall back to the text.
|
|
56
|
-
const taskId = runner.getTaskLoop()?.taskId ?? parseDriverTaskId(runner.getTurnStatus().taskText);
|
|
57
|
-
if (taskId) {
|
|
58
|
-
await pauseStoredTask(getChannelDir(options.paths.workspaceDir, channelId), taskId, {
|
|
59
|
-
by: "user",
|
|
60
|
-
reason: "用户 /stop 中止了该任务的当前步骤。",
|
|
61
|
-
});
|
|
62
|
-
pausedTaskId = taskId;
|
|
63
|
-
log.logInfoEvent("tasks.task.paused_on_stop", "Task paused on /stop", {
|
|
64
|
-
channelId: channelId,
|
|
65
|
-
fields: { taskId },
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
_bot.discardCard(channelId);
|
|
69
|
-
// Drop queued-but-not-started messages so a burst does not keep
|
|
70
|
-
// running after the user asked to halt; abort the in-flight one.
|
|
71
|
-
const dropped = _bot.clearPendingMessages(channelId);
|
|
72
|
-
// Same tick as the clear: record that absorbed wakes' queued closures are gone.
|
|
73
|
-
getDurableDispatch()?.discardQueuedClaims(channelId);
|
|
74
|
-
if (dropped > 0) {
|
|
75
|
-
log.logInfoEvent("agent.turn.queue_dropped", "Queued messages dropped on /stop", {
|
|
76
|
-
channelId: channelId,
|
|
77
|
-
fields: { count: dropped },
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
void runner.abort().catch((err) => {
|
|
81
|
-
log.logWarn("agent.turn.abort_failed", "Turn abort failed", {
|
|
82
|
-
channelId: channelId,
|
|
83
|
-
reason: errorMessage(err),
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
void getDurableDispatch()
|
|
87
|
-
?.cancelChannel(channelId)
|
|
88
|
-
.then((canceled) => {
|
|
89
|
-
if (canceled)
|
|
90
|
-
log.logInfoEvent("dispatch.cancel.reset", "Durable dispatch leases reset on /stop", {
|
|
91
|
-
channelId: channelId,
|
|
92
|
-
fields: { count: canceled },
|
|
93
|
-
});
|
|
94
|
-
})
|
|
95
|
-
.catch((err) => {
|
|
96
|
-
log.logWarn("dispatch.cancel.failed", "Durable dispatch lease reset on stop failed", {
|
|
97
|
-
channelId: channelId,
|
|
98
|
-
reason: errorMessage(err),
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
log.logInfoEvent("agent.turn.stop_requested", "Stop requested", { channelId: channelId });
|
|
102
|
-
if (!stopWatchdogs.has(channelId)) {
|
|
103
|
-
stopWatchdogs.add(channelId);
|
|
104
|
-
void forceEndStuckTurnAfterStop({
|
|
105
|
-
channelId,
|
|
106
|
-
runner,
|
|
107
|
-
graceMs: options.stopForceEndGraceMs,
|
|
108
|
-
notify: (text) => _bot.sendPlain(channelId, text),
|
|
109
|
-
})
|
|
110
|
-
.catch((err) => {
|
|
111
|
-
log.logWarn("agent.turn.stop_watchdog_failed", "Stop watchdog failed", {
|
|
112
|
-
channelId: channelId,
|
|
113
|
-
reason: errorMessage(err),
|
|
114
|
-
});
|
|
115
|
-
})
|
|
116
|
-
.finally(() => {
|
|
117
|
-
stopWatchdogs.delete(channelId);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return { pausedTaskId };
|
|
122
|
-
},
|
|
123
|
-
async handleNewSession(event, _bot) {
|
|
124
|
-
if (isShuttingDown())
|
|
125
|
-
return;
|
|
126
|
-
const previous = sessionResetChains.get(event.channelId) ?? Promise.resolve();
|
|
127
|
-
const reset = previous
|
|
128
|
-
.catch(() => undefined)
|
|
129
|
-
.then(async () => {
|
|
130
|
-
try {
|
|
131
|
-
const channelDir = ensureChannelDir(options.paths.workspaceDir, event.channelId);
|
|
132
|
-
const access = resolveProjectAccessPolicy(loadSecurityConfigWithDiagnostics(options.paths.appHomeDir).config, process.cwd());
|
|
133
|
-
const scope = resolveProjectScope(channelDir, access);
|
|
134
|
-
if (scope.kind === "blocked") {
|
|
135
|
-
throw new Error(scope.reason);
|
|
136
|
-
}
|
|
137
|
-
// The empty session file and active pointer are committed before the old
|
|
138
|
-
// generation is touched. A filesystem failure therefore leaves the live
|
|
139
|
-
// session authoritative and retryable.
|
|
140
|
-
const result = await createFreshActiveSession(channelDir, scope.scope.projectRoot);
|
|
141
|
-
const oldRunner = channelRunners.get(event.channelId);
|
|
142
|
-
if (oldRunner) {
|
|
143
|
-
channelRunners.delete(event.channelId);
|
|
144
|
-
try {
|
|
145
|
-
oldRunner.retireForNewSession();
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
// The active pointer already names the new session. Retirement is
|
|
149
|
-
// best-effort cleanup and must not misreport the committed reset as failed.
|
|
150
|
-
log.logWarn("agent.session.retire_failed", "Old runner retirement after /new failed", {
|
|
151
|
-
channelId: event.channelId,
|
|
152
|
-
reason: errorMessage(error),
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
const dropped = _bot.resetChannelQueue(event.channelId);
|
|
157
|
-
if (dropped > 0) {
|
|
158
|
-
log.logInfoEvent("agent.session.queue_dropped", "Old-session queued messages discarded by /new", {
|
|
159
|
-
channelId: event.channelId,
|
|
160
|
-
fields: { count: dropped },
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
await _bot.sendPlain(event.channelId, formatNewSessionReply(result.sessionId));
|
|
164
|
-
void archiveIncomingMessage(event.channelId, {
|
|
165
|
-
date: new Date().toISOString(),
|
|
166
|
-
ts: event.ts,
|
|
167
|
-
user: event.user,
|
|
168
|
-
userName: event.userName,
|
|
169
|
-
text: event.text,
|
|
170
|
-
isBot: false,
|
|
171
|
-
images: relativeImagePaths(options.paths.workspaceDir, event.channelId, event.images),
|
|
172
|
-
}, "/new command");
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
const message = errorMessage(error);
|
|
176
|
-
log.logWarn("agent.session.create_failed", "Fresh session creation failed", {
|
|
177
|
-
channelId: event.channelId,
|
|
178
|
-
reason: message,
|
|
179
|
-
});
|
|
180
|
-
await _bot.sendPlain(event.channelId, `新会话创建失败:${message}\n旧会话保持不变,可以重试 \`/new\`。`);
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
sessionResetChains.set(event.channelId, reset);
|
|
184
|
-
activeTasks.add(reset);
|
|
185
|
-
try {
|
|
186
|
-
await reset;
|
|
187
|
-
}
|
|
188
|
-
finally {
|
|
189
|
-
activeTasks.delete(reset);
|
|
190
|
-
if (sessionResetChains.get(event.channelId) === reset) {
|
|
191
|
-
sessionResetChains.delete(event.channelId);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
async runRuntimeCommand(event, name, args) {
|
|
196
|
-
const { channelId } = event;
|
|
197
|
-
return runReportCommand({
|
|
198
|
-
channelId,
|
|
199
|
-
paths: options.paths,
|
|
200
|
-
actor: "dingtalk-command",
|
|
201
|
-
version: cliVersion,
|
|
202
|
-
startedAt,
|
|
203
|
-
peekRunner: () => channelRunners.get(channelId),
|
|
204
|
-
getRunner: () => getRunner(channelId),
|
|
205
|
-
runManager: getRuns().get(channelId),
|
|
206
|
-
runningJobLines: () => getJobs().runningLines(channelId),
|
|
207
|
-
// D4.2: dispose the cached runner so the next access rebuilds it under the new scope.
|
|
208
|
-
// The active-session ref is untouched — same session, new project root.
|
|
209
|
-
onScopeChanged: async () => {
|
|
210
|
-
const runner = channelRunners.get(channelId);
|
|
211
|
-
channelRunners.delete(channelId);
|
|
212
|
-
await runner?.dispose().catch((err) => {
|
|
213
|
-
log.logWarn("runtime.runner.dispose_failed", "Runner dispose after /project failed", {
|
|
214
|
-
channelId: channelId,
|
|
215
|
-
reason: errorMessage(err),
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
},
|
|
219
|
-
dispatchTask: async (id) => {
|
|
220
|
-
const channelDir = getChannelDir(options.paths.workspaceDir, channelId);
|
|
221
|
-
const entry = (await readActiveTasks(join(channelDir, "tasks"))).find((candidate) => candidate.id === id);
|
|
222
|
-
if (!entry)
|
|
223
|
-
return false;
|
|
224
|
-
// A human asking to run a task twice means twice, so this key is deliberately
|
|
225
|
-
// unique per invocation rather than sharing the driver's occurrence key (D1).
|
|
226
|
-
const now = Date.now();
|
|
227
|
-
return ((await getDurableDispatch()?.dispatch({
|
|
228
|
-
...createTaskDriverEvent(channelId, entry, now),
|
|
229
|
-
dispatchId: `task:${channelId}:${entry.id}:manual:${new Date(now).toISOString()}`,
|
|
230
|
-
})) ?? false);
|
|
231
|
-
},
|
|
232
|
-
}, name, args);
|
|
233
|
-
},
|
|
234
|
-
async handleBusyMessage(event, bot, mode, queueText) {
|
|
235
|
-
if (isShuttingDown()) {
|
|
236
|
-
return { kind: "handled" };
|
|
237
|
-
}
|
|
238
|
-
const runner = getRunner(event.channelId);
|
|
239
|
-
const trimmedQueueText = queueText.trim();
|
|
240
|
-
if (!trimmedQueueText) {
|
|
241
|
-
await bot.sendPlain(event.channelId, formatMissingQueueMessage(mode === "followUp" ? "followup" : "steer"));
|
|
242
|
-
return { kind: "handled" };
|
|
243
|
-
}
|
|
244
|
-
// Compaction is maintenance, not user work. A new message cancels it and is
|
|
245
|
-
// kept as a normal queued turn instead of trying to steer an agent loop that
|
|
246
|
-
// is currently disconnected for summarization.
|
|
247
|
-
if (runner.interruptCompaction()) {
|
|
248
|
-
log.logInfoEvent("agent.compaction.interrupted", "Compaction interrupted for a new user message", {
|
|
249
|
-
channelId: event.channelId,
|
|
250
|
-
});
|
|
251
|
-
return { kind: "requeue", text: trimmedQueueText };
|
|
252
|
-
}
|
|
253
|
-
// A task step runs in the task's own session and is muted: a steer here would land in
|
|
254
|
-
// the background task's context and its answer would never reach the user, while the
|
|
255
|
-
// message itself is kept out of the chat session. Run it as the next chat turn instead.
|
|
256
|
-
const taskLoop = runner.getTaskLoop();
|
|
257
|
-
if (taskLoop) {
|
|
258
|
-
await bot.sendPlain(event.channelId, `后台任务 \`${taskLoop.taskId}\` 正在执行一步,你的消息会在这一步结束后处理;要给该任务补充指示,用 \`/tasks steer ${taskLoop.taskId} <内容>\`。`);
|
|
259
|
-
log.logEvent("info", "agent.turn.followup_queued", "Message deferred past a task step", {
|
|
260
|
-
ctx: { channelId: event.channelId, userName: event.userName },
|
|
261
|
-
fields: { messageLength: trimmedQueueText.length, taskId: taskLoop.taskId },
|
|
262
|
-
});
|
|
263
|
-
return { kind: "requeue", text: trimmedQueueText };
|
|
264
|
-
}
|
|
265
|
-
if (mode === "followUp") {
|
|
266
|
-
log.logEvent("info", "agent.turn.followup_queued", "Follow-up queued", {
|
|
267
|
-
ctx: { channelId: event.channelId, userName: event.userName },
|
|
268
|
-
fields: { messageLength: trimmedQueueText.length },
|
|
269
|
-
});
|
|
270
|
-
return { kind: "requeue", text: trimmedQueueText };
|
|
271
|
-
}
|
|
272
|
-
try {
|
|
273
|
-
await runner.queueSteer(trimmedQueueText, event.userName, event.images);
|
|
274
|
-
await archiveIncomingMessage(event.channelId, {
|
|
275
|
-
date: new Date().toISOString(),
|
|
276
|
-
ts: event.ts,
|
|
277
|
-
user: event.user,
|
|
278
|
-
userName: event.userName,
|
|
279
|
-
text: event.text,
|
|
280
|
-
isBot: false,
|
|
281
|
-
deliveryMode: mode,
|
|
282
|
-
skipContextSync: true,
|
|
283
|
-
images: relativeImagePaths(options.paths.workspaceDir, event.channelId, event.images),
|
|
284
|
-
}, `${mode} message`);
|
|
285
|
-
await bot.sendPlain(event.channelId, formatSteerQueued(!event.text.trim().startsWith("/")));
|
|
286
|
-
log.logEvent("info", "agent.turn.steer_queued", "Steer queued", {
|
|
287
|
-
ctx: { channelId: event.channelId, userName: event.userName },
|
|
288
|
-
fields: { messageLength: trimmedQueueText.length },
|
|
289
|
-
});
|
|
290
|
-
return { kind: "handled" };
|
|
291
|
-
}
|
|
292
|
-
catch (err) {
|
|
293
|
-
const errMsg = errorMessage(err);
|
|
294
|
-
if (isNoRunningTaskQueueError(err)) {
|
|
295
|
-
log.logInfoEvent("agent.turn.requeued", "Busy window closed; message requeued as a normal turn", {
|
|
296
|
-
channelId: event.channelId,
|
|
297
|
-
fields: { mode },
|
|
298
|
-
});
|
|
299
|
-
return { kind: "requeue", text: trimmedQueueText };
|
|
300
|
-
}
|
|
301
|
-
log.logWarn("agent.turn.queue_failed", "Busy message queueing failed", {
|
|
302
|
-
channelId: event.channelId,
|
|
303
|
-
reason: errMsg,
|
|
304
|
-
fields: { mode },
|
|
305
|
-
});
|
|
306
|
-
await bot.sendPlain(event.channelId, `这条消息没能排进当前回合:${errMsg}\n等当前回合结束后重发,或用 \`/followup <消息>\` 排到它之后。`);
|
|
307
|
-
return { kind: "handled" };
|
|
308
|
-
}
|
|
309
|
-
},
|
|
310
|
-
persistInboundImage: (channelId, image) => persistInboundImage(options.paths.workspaceDir, channelId, image),
|
|
311
|
-
handleEvent: runEventTurn,
|
|
312
|
-
reserveEvent(event) {
|
|
313
|
-
// Must stay synchronous: runs before the queued handler is awaited, so busy state shows up at once.
|
|
314
|
-
getRunner(event.channelId).beginTurn(event.text);
|
|
315
|
-
},
|
|
316
|
-
};
|
|
317
|
-
return handler;
|
|
318
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { ConfigDiagnostic } from "../shared/config-diagnostic.js";
|
|
2
|
-
import type { SecurityConfig } from "./types.js";
|
|
3
|
-
/** Spec 043, D6.3: the runtime must never claim `system` without an explicit bootstrap-injected
|
|
4
|
-
* host sandbox. Nothing wires that injection point yet, so this is the only reachable value today. */
|
|
5
|
-
export interface ProjectSandboxStatus {
|
|
6
|
-
level: "application" | "system";
|
|
7
|
-
provider: string;
|
|
8
|
-
summary: string;
|
|
9
|
-
}
|
|
10
|
-
/** The effective result a runner generation uses; see D2.1. Not the raw request. */
|
|
11
|
-
export interface ProjectScope {
|
|
12
|
-
/** Realpath of an existing directory. */
|
|
13
|
-
projectRoot: string;
|
|
14
|
-
/** `project`: generic file tools are bounded to `projectRoot`. `unbounded`: today's global pathGuard defaults. */
|
|
15
|
-
boundary: "project" | "unbounded";
|
|
16
|
-
sandbox: ProjectSandboxStatus;
|
|
17
|
-
}
|
|
18
|
-
/** The app-level policy resolved from `security.json`'s `projectAccess` section (D3.1). */
|
|
19
|
-
export interface ProjectAccessPolicy {
|
|
20
|
-
/** Realpath. Always a member of `allowedRoots`. */
|
|
21
|
-
defaultRoot: string;
|
|
22
|
-
/** Realpaths. */
|
|
23
|
-
allowedRoots: readonly string[];
|
|
24
|
-
}
|
|
25
|
-
export interface ProjectAccessResolution {
|
|
26
|
-
policy: ProjectAccessPolicy;
|
|
27
|
-
/** False in the unconfigured-compat state, or when `defaultRoot` itself fails to canonicalize. */
|
|
28
|
-
mutable: boolean;
|
|
29
|
-
/** Whether `security.json` had a `projectAccess` key at all (distinct from mutable — see D3.2). */
|
|
30
|
-
configured: boolean;
|
|
31
|
-
diagnostics: ConfigDiagnostic[];
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Resolves the app's project-access policy for a fresh runner generation. `startupCwd` is only
|
|
35
|
-
* used as the implicit default when `projectAccess` is configured but omits `defaultRoot` (D3.2
|
|
36
|
-
* row 3) — the unconfigured-compat row (row 1) also uses it, but never persists it as a "chosen"
|
|
37
|
-
* default the way a configured policy's `defaultRoot` is.
|
|
38
|
-
*/
|
|
39
|
-
export declare function resolveProjectAccessPolicy(config: SecurityConfig, startupCwd: string): ProjectAccessResolution;
|
|
40
|
-
/** Prefix match with a path-separator boundary, so `/repo-ab` is not treated as within `/repo-a`. */
|
|
41
|
-
export declare function isWithinAllowedRoots(root: string, policy: ProjectAccessPolicy): boolean;
|
|
42
|
-
/** True until a host sandbox injection point exists (D6.3, D9 risk #2) — see `ProjectSandboxStatus`. */
|
|
43
|
-
export declare function currentProjectSandboxStatus(): ProjectSandboxStatus;
|
|
44
|
-
/** True if `raw` resolves (after `~`-expansion) to an existing directory — used by `/project set` validation. */
|
|
45
|
-
export declare function resolveExistingDirectory(raw: string): string | undefined;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { realpathSync, statSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { isAbsolute, resolve } from "node:path";
|
|
4
|
-
import { withTrailingSlash } from "../shared/text-utils.js";
|
|
5
|
-
const DIAGNOSTIC_SOURCE = "security";
|
|
6
|
-
function expandHome(path) {
|
|
7
|
-
if (path === "~")
|
|
8
|
-
return homedir();
|
|
9
|
-
if (path.startsWith("~/"))
|
|
10
|
-
return resolve(homedir(), path.slice(2));
|
|
11
|
-
return path;
|
|
12
|
-
}
|
|
13
|
-
/** Absolute, existing, real directory — or `undefined` if any of that doesn't hold. */
|
|
14
|
-
function canonicalizeRoot(raw) {
|
|
15
|
-
const expanded = expandHome(raw);
|
|
16
|
-
if (!isAbsolute(expanded))
|
|
17
|
-
return undefined;
|
|
18
|
-
try {
|
|
19
|
-
const real = realpathSync(expanded);
|
|
20
|
-
return statSync(real).isDirectory() ? real : undefined;
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function realpathOrResolve(path) {
|
|
27
|
-
try {
|
|
28
|
-
return realpathSync(path);
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return resolve(path);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Resolves the app's project-access policy for a fresh runner generation. `startupCwd` is only
|
|
36
|
-
* used as the implicit default when `projectAccess` is configured but omits `defaultRoot` (D3.2
|
|
37
|
-
* row 3) — the unconfigured-compat row (row 1) also uses it, but never persists it as a "chosen"
|
|
38
|
-
* default the way a configured policy's `defaultRoot` is.
|
|
39
|
-
*/
|
|
40
|
-
export function resolveProjectAccessPolicy(config, startupCwd) {
|
|
41
|
-
const diagnostics = [];
|
|
42
|
-
const raw = config.projectAccess;
|
|
43
|
-
const fallbackRoot = realpathOrResolve(startupCwd);
|
|
44
|
-
if (!raw) {
|
|
45
|
-
return {
|
|
46
|
-
policy: { defaultRoot: fallbackRoot, allowedRoots: [fallbackRoot] },
|
|
47
|
-
mutable: false,
|
|
48
|
-
configured: false,
|
|
49
|
-
diagnostics,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
const defaultRootRaw = raw.defaultRoot ?? startupCwd;
|
|
53
|
-
const defaultRoot = canonicalizeRoot(defaultRootRaw);
|
|
54
|
-
if (!defaultRoot) {
|
|
55
|
-
diagnostics.push({
|
|
56
|
-
source: DIAGNOSTIC_SOURCE,
|
|
57
|
-
path: "projectAccess.defaultRoot",
|
|
58
|
-
severity: "error",
|
|
59
|
-
message: `${JSON.stringify(defaultRootRaw)} is not an absolute, existing directory; project scope changes are disabled until this is fixed`,
|
|
60
|
-
});
|
|
61
|
-
return {
|
|
62
|
-
policy: { defaultRoot: fallbackRoot, allowedRoots: [fallbackRoot] },
|
|
63
|
-
mutable: false,
|
|
64
|
-
configured: true,
|
|
65
|
-
diagnostics,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
const rawAllowed = raw.allowedRoots && raw.allowedRoots.length > 0 ? raw.allowedRoots : [defaultRootRaw];
|
|
69
|
-
const allowedRoots = new Set([defaultRoot]);
|
|
70
|
-
for (const entry of rawAllowed) {
|
|
71
|
-
const canonical = canonicalizeRoot(entry);
|
|
72
|
-
if (!canonical) {
|
|
73
|
-
diagnostics.push({
|
|
74
|
-
source: DIAGNOSTIC_SOURCE,
|
|
75
|
-
path: "projectAccess.allowedRoots",
|
|
76
|
-
severity: "warning",
|
|
77
|
-
message: `entry ${JSON.stringify(entry)} is not an absolute, existing directory; ignored`,
|
|
78
|
-
});
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
allowedRoots.add(canonical);
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
policy: { defaultRoot, allowedRoots: [...allowedRoots] },
|
|
85
|
-
mutable: true,
|
|
86
|
-
configured: true,
|
|
87
|
-
diagnostics,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
/** Prefix match with a path-separator boundary, so `/repo-ab` is not treated as within `/repo-a`. */
|
|
91
|
-
export function isWithinAllowedRoots(root, policy) {
|
|
92
|
-
return policy.allowedRoots.some((allowed) => root === allowed || root.startsWith(withTrailingSlash(allowed)));
|
|
93
|
-
}
|
|
94
|
-
/** True until a host sandbox injection point exists (D6.3, D9 risk #2) — see `ProjectSandboxStatus`. */
|
|
95
|
-
export function currentProjectSandboxStatus() {
|
|
96
|
-
return {
|
|
97
|
-
level: "application",
|
|
98
|
-
provider: "pipiclaw-path-guard",
|
|
99
|
-
summary: "文件工具被约束在项目目录内;shell 仅设置了 cwd,未受系统沙箱隔离,可通过 cd/绝对路径/子进程逃逸。",
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/** True if `raw` resolves (after `~`-expansion) to an existing directory — used by `/project set` validation. */
|
|
103
|
-
export function resolveExistingDirectory(raw) {
|
|
104
|
-
return canonicalizeRoot(raw);
|
|
105
|
-
}
|
package/dist/tui/app.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type BootstrapIO, type BootstrapPaths } from "../app/home.js";
|
|
2
|
-
export interface TuiAppOptions {
|
|
3
|
-
channel?: string;
|
|
4
|
-
/** One-shot, non-interactive run: process a single prompt then exit. */
|
|
5
|
-
print?: boolean;
|
|
6
|
-
/** Suppress progress/notice output (plain frontend). */
|
|
7
|
-
quiet?: boolean;
|
|
8
|
-
/** Force the plain frontend even on a TTY. */
|
|
9
|
-
plain?: boolean;
|
|
10
|
-
/** Initial prompt to run before handing control to the input loop. */
|
|
11
|
-
initialPrompt?: string;
|
|
12
|
-
io?: BootstrapIO;
|
|
13
|
-
paths?: BootstrapPaths;
|
|
14
|
-
}
|
|
15
|
-
export declare function resolveChannelId(raw: string | undefined, io?: BootstrapIO): string;
|
|
16
|
-
export declare function runTuiApp(options: TuiAppOptions): Promise<void>;
|
package/dist/tui/app.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Terminal TUI runtime: transport-neutral app init (no DingTalk gate), channel
|
|
3
|
-
* resolution, and wiring of the collaborators the `TurnController` drives.
|
|
4
|
-
*
|
|
5
|
-
* The heavy lifting is reused as-is: `ChannelRunner` drives each turn, the
|
|
6
|
-
* `ChannelContext` is a terminal one (`terminal-context.ts`), and app
|
|
7
|
-
* preparation shares `prepareAppServices` with the DingTalk path.
|
|
8
|
-
*/
|
|
9
|
-
import { userInfo } from "node:os";
|
|
10
|
-
import { createRunner } from "../agent/runner-factory.js";
|
|
11
|
-
import { BootstrapExitError, bootstrapAppHome, DEFAULT_BOOTSTRAP_PATHS, printBootstrapSummary, readCliVersion, } from "../app/home.js";
|
|
12
|
-
import { prepareAppServices } from "../app/services.js";
|
|
13
|
-
import { finalDeliveryOf, progressStyleOf } from "../channel/channel-context.js";
|
|
14
|
-
import { ensureChannelDir } from "../channel/channel-paths.js";
|
|
15
|
-
import { ChannelStore } from "../channel/store.js";
|
|
16
|
-
import { renderBuiltInHelp } from "../commands/catalog.js";
|
|
17
|
-
import { runReportCommand } from "../commands/router.js";
|
|
18
|
-
import { createExecutor } from "../executor.js";
|
|
19
|
-
import { createJobRuntime } from "../jobs/manager.js";
|
|
20
|
-
import * as log from "../log.js";
|
|
21
|
-
import { flushSecurityLogs } from "../security/logger.js";
|
|
22
|
-
import { createSubAgentRuntime } from "../subagents/run-registry.js";
|
|
23
|
-
import { getUsageLedger } from "../usage/ledger.js";
|
|
24
|
-
import { TUI_SLASH_COMMANDS } from "./commands.js";
|
|
25
|
-
import { createFrontend } from "./renderer.js";
|
|
26
|
-
import { createTerminalMediaSender } from "./terminal-media-sender.js";
|
|
27
|
-
import { TurnController } from "./turn-controller.js";
|
|
28
|
-
const DEFAULT_CHANNEL_ID = "tui_local";
|
|
29
|
-
const CHANNEL_ID_PATTERN = /^[A-Za-z0-9._-]+$/;
|
|
30
|
-
const STORAGE_FLUSH_TIMEOUT_MS = 10_000;
|
|
31
|
-
async function waitForStorageFlush(task) {
|
|
32
|
-
await new Promise((resolve) => {
|
|
33
|
-
const timer = setTimeout(resolve, STORAGE_FLUSH_TIMEOUT_MS);
|
|
34
|
-
timer.unref?.();
|
|
35
|
-
void task.then(() => {
|
|
36
|
-
clearTimeout(timer);
|
|
37
|
-
resolve();
|
|
38
|
-
}, () => {
|
|
39
|
-
clearTimeout(timer);
|
|
40
|
-
resolve();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* A replaceable `AgentRunner` reference (spec 043, D4.2): `TurnController` holds a single
|
|
46
|
-
* `AgentRunner` for the process's lifetime, but `/project set|reset` needs to dispose the runner
|
|
47
|
-
* built under the old scope and hand the next turn a fresh one built under the new scope. The
|
|
48
|
-
* proxy forwards every call to whichever runner is current, so `TurnController` never needs to
|
|
49
|
-
* know the reference changed.
|
|
50
|
-
*/
|
|
51
|
-
function createRunnerSlot(initial) {
|
|
52
|
-
let current = initial;
|
|
53
|
-
const runner = new Proxy({}, {
|
|
54
|
-
get(_target, prop, _receiver) {
|
|
55
|
-
const value = Reflect.get(current, prop);
|
|
56
|
-
return typeof value === "function" ? value.bind(current) : value;
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
return {
|
|
60
|
-
runner,
|
|
61
|
-
replace(next) {
|
|
62
|
-
current = next;
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
export function resolveChannelId(raw, io = console) {
|
|
67
|
-
const channel = raw?.trim() || DEFAULT_CHANNEL_ID;
|
|
68
|
-
if (!CHANNEL_ID_PATTERN.test(channel)) {
|
|
69
|
-
io.error(`Invalid --channel "${channel}": use letters, digits, dot, dash or underscore.`);
|
|
70
|
-
throw new BootstrapExitError(1);
|
|
71
|
-
}
|
|
72
|
-
return channel;
|
|
73
|
-
}
|
|
74
|
-
function safeUserName() {
|
|
75
|
-
try {
|
|
76
|
-
return userInfo().username || "you";
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
return "you";
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
export async function runTuiApp(options) {
|
|
83
|
-
const io = options.io ?? console;
|
|
84
|
-
const paths = options.paths ?? DEFAULT_BOOTSTRAP_PATHS;
|
|
85
|
-
const channelId = resolveChannelId(options.channel, io);
|
|
86
|
-
// The pi-tui frontend owns stdout; the plain frontend prints only the final
|
|
87
|
-
// answer. Either way the human-readable console log sink would corrupt output,
|
|
88
|
-
// so route logging to the file sink only. Turn progress and errors are still
|
|
89
|
-
// surfaced through the transcript.
|
|
90
|
-
log.setConsoleLoggingEnabled(false);
|
|
91
|
-
// Transport-neutral init. Unlike the DingTalk path, the TUI ignores
|
|
92
|
-
// channelTemplateCreated (it needs no channel.json) and shares app services
|
|
93
|
-
// (settings, diagnostics) with bootstrap via prepareAppServices.
|
|
94
|
-
printBootstrapSummary(bootstrapAppHome(paths), io, paths);
|
|
95
|
-
const { settingsManager } = prepareAppServices(paths);
|
|
96
|
-
log.configureLogging(settingsManager.getLoggingSettings());
|
|
97
|
-
log.logStartup(paths.workspaceDir);
|
|
98
|
-
const channelDir = ensureChannelDir(paths.workspaceDir, channelId);
|
|
99
|
-
const store = new ChannelStore({ workingDir: paths.workspaceDir });
|
|
100
|
-
const jobs = createJobRuntime(createExecutor());
|
|
101
|
-
const runs = createSubAgentRuntime();
|
|
102
|
-
const buildRunner = () => createRunner(channelId, channelDir, {
|
|
103
|
-
jobManager: jobs.get(channelId),
|
|
104
|
-
runManager: runs.get(channelId),
|
|
105
|
-
appHomeDir: paths.appHomeDir,
|
|
106
|
-
authConfigPath: paths.authConfigPath,
|
|
107
|
-
modelsConfigPath: paths.modelsConfigPath,
|
|
108
|
-
settingsManager,
|
|
109
|
-
mediaSender: createTerminalMediaSender(io),
|
|
110
|
-
});
|
|
111
|
-
const runnerSlot = createRunnerSlot(buildRunner());
|
|
112
|
-
const runner = runnerSlot.runner;
|
|
113
|
-
const tuiSettings = settingsManager.getTuiSettings();
|
|
114
|
-
const traits = {
|
|
115
|
-
progressStyle: progressStyleOf(tuiSettings.responseMode),
|
|
116
|
-
finalDelivery: finalDeliveryOf(tuiSettings.responseMode),
|
|
117
|
-
};
|
|
118
|
-
const interactive = !options.print;
|
|
119
|
-
const frontend = createFrontend({
|
|
120
|
-
plain: options.plain,
|
|
121
|
-
quiet: options.quiet,
|
|
122
|
-
interactive,
|
|
123
|
-
commands: TUI_SLASH_COMMANDS,
|
|
124
|
-
basePath: paths.workspaceDir,
|
|
125
|
-
});
|
|
126
|
-
const startedAt = Date.now();
|
|
127
|
-
const controller = new TurnController({
|
|
128
|
-
runner,
|
|
129
|
-
frontend,
|
|
130
|
-
store,
|
|
131
|
-
traits,
|
|
132
|
-
channelId,
|
|
133
|
-
userName: safeUserName(),
|
|
134
|
-
renderHelp: (args) => renderBuiltInHelp(args),
|
|
135
|
-
runReport: (name, args) => runReportCommand({
|
|
136
|
-
channelId,
|
|
137
|
-
paths,
|
|
138
|
-
actor: "tui-command",
|
|
139
|
-
version: readCliVersion(),
|
|
140
|
-
startedAt,
|
|
141
|
-
peekRunner: () => runner,
|
|
142
|
-
getRunner: () => runner,
|
|
143
|
-
runManager: runs.get(channelId),
|
|
144
|
-
runningJobLines: () => jobs.runningLines(channelId),
|
|
145
|
-
onScopeChanged: async () => {
|
|
146
|
-
await runner.dispose();
|
|
147
|
-
runnerSlot.replace(buildRunner());
|
|
148
|
-
},
|
|
149
|
-
}, name, args),
|
|
150
|
-
});
|
|
151
|
-
try {
|
|
152
|
-
if (options.print) {
|
|
153
|
-
await controller.runOnce(options.initialPrompt);
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
await controller.startInteractive(options.initialPrompt);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
finally {
|
|
160
|
-
await runner.dispose();
|
|
161
|
-
runs.stop();
|
|
162
|
-
jobs.stop();
|
|
163
|
-
await waitForStorageFlush(Promise.allSettled([store.close(), getUsageLedger().flush?.() ?? Promise.resolve(), flushSecurityLogs()]));
|
|
164
|
-
await waitForStorageFlush(log.flushLogging());
|
|
165
|
-
}
|
|
166
|
-
}
|