@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
package/dist/tools/registry.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
|
-
import type {
|
|
3
|
+
import type { SendMedia } from "../channel/transport.js";
|
|
4
4
|
import type { PipiclawSessionSearchSettings } from "../config/settings.js";
|
|
5
5
|
import type { PipiclawToolsConfig, PipiclawWebToolsConfig } from "../config/tools.js";
|
|
6
6
|
import type { Executor } from "../executor.js";
|
|
7
7
|
import type { FileStore } from "../file-store.js";
|
|
8
|
-
import type {
|
|
8
|
+
import type { DeskJobManager } from "../jobs/manager.js";
|
|
9
9
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
10
10
|
import type { SubAgentRunManager } from "../subagents/runs.js";
|
|
11
11
|
import { type ToolDetailsKind } from "./contract/details.js";
|
|
@@ -26,7 +26,9 @@ export interface ToolBuildContext {
|
|
|
26
26
|
securityConfig: SecurityConfig;
|
|
27
27
|
securityContext: SecurityRuntimeContext;
|
|
28
28
|
channelId: string;
|
|
29
|
-
|
|
29
|
+
/** Main path only: the desk this tool set acts for; its name keys the memory queue (spec 058, INV-8). */
|
|
30
|
+
desk?: string;
|
|
31
|
+
deskDir: string;
|
|
30
32
|
workspaceDir: string;
|
|
31
33
|
/** Main set: `toolsConfig.tools.web`; sub-agent set: the sub-agent's own webConfig. */
|
|
32
34
|
webConfig?: PipiclawWebToolsConfig;
|
|
@@ -37,26 +39,28 @@ export interface ToolBuildContext {
|
|
|
37
39
|
/** Gates the bash tool's rtk command optimizer (`tools.rtk.enabled`). Threaded to both sets. */
|
|
38
40
|
rtkEnabled?: boolean;
|
|
39
41
|
/**
|
|
40
|
-
* Set by `buildToolSet` from `BuildToolSetOptions.forSubagent`. A sub-agent
|
|
41
|
-
*
|
|
42
|
-
*
|
|
42
|
+
* Set by `buildToolSet` from `BuildToolSetOptions.forSubagent`. A sub-agent works in its own
|
|
43
|
+
* working directory, so tools that would otherwise write into the desk directory (bash/job
|
|
44
|
+
* output spill) fall back to a neutral location for it.
|
|
43
45
|
*/
|
|
44
46
|
forSubagent?: boolean;
|
|
45
47
|
/**
|
|
46
48
|
* Present only on the main path. Enables bash `async` and the `job` tool.
|
|
47
49
|
* The sub-agent set never supplies it, so sub-agents get neither.
|
|
48
50
|
*/
|
|
49
|
-
jobManager?:
|
|
51
|
+
jobManager?: DeskJobManager;
|
|
50
52
|
runManager?: SubAgentRunManager;
|
|
51
53
|
getCurrentModel?: () => Model<Api>;
|
|
52
54
|
getAvailableModels?: () => Model<Api>[];
|
|
53
55
|
resolveApiKey?: (model: Model<Api>) => Promise<string>;
|
|
54
56
|
getSessionSearchSettings?: () => PipiclawSessionSearchSettings;
|
|
57
|
+
/** Names a conversation directory of this desk after its channel, for `session_search` results. */
|
|
58
|
+
describeConversation?: (conversation: string) => string | undefined;
|
|
55
59
|
/**
|
|
56
60
|
* Present only on the main path, and only when the driving transport can deliver
|
|
57
61
|
* files. Gates the `send_media` tool; sub-agents never receive it.
|
|
58
62
|
*/
|
|
59
|
-
|
|
63
|
+
sendMedia?: SendMedia;
|
|
60
64
|
/**
|
|
61
65
|
* Present only inside a task loop step (spec 051, D3): which task this tool set belongs to.
|
|
62
66
|
* `task_step_end` is registered only when this is set, so the chat surface can never end a
|
package/dist/tools/registry.js
CHANGED
|
@@ -31,7 +31,8 @@ function fileToolOptions(ctx) {
|
|
|
31
31
|
function memoryToolOptions(ctx) {
|
|
32
32
|
return {
|
|
33
33
|
channelId: ctx.channelId,
|
|
34
|
-
|
|
34
|
+
desk: req(ctx.desk, "desk"),
|
|
35
|
+
deskDir: ctx.deskDir,
|
|
35
36
|
workspaceDir: ctx.workspaceDir,
|
|
36
37
|
};
|
|
37
38
|
}
|
|
@@ -39,7 +40,8 @@ function taskToolOptions(ctx) {
|
|
|
39
40
|
return {
|
|
40
41
|
jobManager: req(ctx.jobManager, "jobManager"),
|
|
41
42
|
runManager: req(ctx.runManager, "runManager"),
|
|
42
|
-
|
|
43
|
+
deskDir: ctx.deskDir,
|
|
44
|
+
channelId: ctx.channelId,
|
|
43
45
|
};
|
|
44
46
|
}
|
|
45
47
|
function webEnabled(ctx) {
|
|
@@ -63,7 +65,7 @@ export const TOOL_REGISTRY = [
|
|
|
63
65
|
rtkEnabled: ctx.rtkEnabled === true,
|
|
64
66
|
interceptorEnabled: ctx.toolsConfig?.tools.bashInterceptor.enabled === true,
|
|
65
67
|
// Sub-agents get no channel dir (their guard context has none); their spill stays in tmpdir.
|
|
66
|
-
...(ctx.forSubagent ? {} : {
|
|
68
|
+
...(ctx.forSubagent ? {} : { deskDir: ctx.deskDir }),
|
|
67
69
|
...(ctx.taskLoop ? { boundTaskId: ctx.taskLoop.taskId } : {}),
|
|
68
70
|
...(ctx.jobManager ? { jobManager: ctx.jobManager } : {}),
|
|
69
71
|
...(ctx.bashDefaultTimeoutSeconds !== undefined
|
|
@@ -105,16 +107,16 @@ export const TOOL_REGISTRY = [
|
|
|
105
107
|
securityConfig: ctx.securityConfig,
|
|
106
108
|
workspaceDir: ctx.workspaceDir,
|
|
107
109
|
channelId: ctx.channelId,
|
|
108
|
-
|
|
110
|
+
deskDir: ctx.deskDir,
|
|
109
111
|
}),
|
|
110
112
|
},
|
|
111
113
|
{
|
|
112
114
|
name: "send_media",
|
|
113
115
|
// Enabled only when the driving transport supplied a media sender (the DingTalk
|
|
114
116
|
// bot, or the terminal). Absent it, the tool is not built or advertised.
|
|
115
|
-
enabledBy: (ctx) => ctx.
|
|
117
|
+
enabledBy: (ctx) => ctx.sendMedia != null,
|
|
116
118
|
create: (ctx) => createSendMediaTool(ctx.fileStore, {
|
|
117
|
-
|
|
119
|
+
sendMedia: req(ctx.sendMedia, "sendMedia"),
|
|
118
120
|
channelId: ctx.channelId,
|
|
119
121
|
securityConfig: ctx.securityConfig,
|
|
120
122
|
securityContext: ctx.securityContext,
|
|
@@ -124,7 +126,9 @@ export const TOOL_REGISTRY = [
|
|
|
124
126
|
name: "session_search",
|
|
125
127
|
create: (ctx) => createSessionSearchTool({
|
|
126
128
|
channelId: ctx.channelId,
|
|
127
|
-
|
|
129
|
+
desk: ctx.desk,
|
|
130
|
+
deskDir: ctx.deskDir,
|
|
131
|
+
describeConversation: ctx.describeConversation,
|
|
128
132
|
getCurrentModel: req(ctx.getCurrentModel, "getCurrentModel"),
|
|
129
133
|
resolveApiKey: req(ctx.resolveApiKey, "resolveApiKey"),
|
|
130
134
|
getSessionSearchSettings: req(ctx.getSessionSearchSettings, "getSessionSearchSettings"),
|
|
@@ -150,7 +154,7 @@ export const TOOL_REGISTRY = [
|
|
|
150
154
|
{
|
|
151
155
|
name: "event_manage",
|
|
152
156
|
create: (ctx) => createEventManageTool({
|
|
153
|
-
|
|
157
|
+
deskDir: ctx.deskDir,
|
|
154
158
|
channelId: ctx.channelId,
|
|
155
159
|
commandGuardConfig: ctx.securityConfig.commandGuard,
|
|
156
160
|
}),
|
|
@@ -199,7 +203,7 @@ export const TOOL_REGISTRY = [
|
|
|
199
203
|
// Present only when a job manager was supplied (always on the main path,
|
|
200
204
|
// never for sub-agents).
|
|
201
205
|
enabledBy: (ctx) => ctx.jobManager !== undefined,
|
|
202
|
-
create: (ctx) => createJobTool({ jobManager: req(ctx.jobManager, "jobManager") }),
|
|
206
|
+
create: (ctx) => createJobTool({ jobManager: req(ctx.jobManager, "jobManager"), channelId: ctx.channelId }),
|
|
203
207
|
},
|
|
204
208
|
];
|
|
205
209
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
-
import type {
|
|
3
|
+
import type { SendMedia } from "../channel/transport.js";
|
|
4
4
|
import type { FileStore } from "../file-store.js";
|
|
5
5
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
6
6
|
declare const sendMediaSchema: Type.TObject<{
|
|
@@ -9,7 +9,7 @@ declare const sendMediaSchema: Type.TObject<{
|
|
|
9
9
|
}>;
|
|
10
10
|
export interface SendMediaToolOptions {
|
|
11
11
|
/** Transport that actually delivers the attachment. Bound to `channelId`. */
|
|
12
|
-
|
|
12
|
+
sendMedia: SendMedia;
|
|
13
13
|
/** The channel this tool instance is bound to — supplied by the runtime, not the model. */
|
|
14
14
|
channelId: string;
|
|
15
15
|
securityConfig?: SecurityConfig;
|
package/dist/tools/send-media.js
CHANGED
|
@@ -7,7 +7,7 @@ import { formatSize, MAX_INLINE_BINARY_BYTES } from "./truncate.js";
|
|
|
7
7
|
/** Extensions delivered as inline images; everything else goes as a file attachment. */
|
|
8
8
|
const IMAGE_EXTENSIONS = new Set([".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp"]);
|
|
9
9
|
const sendMediaSchema = Type.Object({
|
|
10
|
-
path: Type.String({ description: "Local file path (relative to the current
|
|
10
|
+
path: Type.String({ description: "Local file path (relative to the current working directory, or absolute)" }),
|
|
11
11
|
fileName: Type.Optional(Type.String({ description: "Display name for the recipient; defaults to the file's own name" })),
|
|
12
12
|
});
|
|
13
13
|
/**
|
|
@@ -21,7 +21,7 @@ const sendMediaSchema = Type.Object({
|
|
|
21
21
|
*/
|
|
22
22
|
export function createSendMediaTool(fileStore, options) {
|
|
23
23
|
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
24
|
-
const securityContext = options.securityContext ?? { agentWorkspaceDir: process.cwd(),
|
|
24
|
+
const securityContext = options.securityContext ?? { agentWorkspaceDir: process.cwd(), cwd: process.cwd() };
|
|
25
25
|
return {
|
|
26
26
|
name: "send_media",
|
|
27
27
|
label: "send_media",
|
|
@@ -50,7 +50,7 @@ export function createSendMediaTool(fileStore, options) {
|
|
|
50
50
|
// Route by the *real file's* extension, not the display name: `fileName` is only a label,
|
|
51
51
|
// so a PNG sent with fileName "报告" must still be delivered as an image (fix plan §4).
|
|
52
52
|
const kind = IMAGE_EXTENSIONS.has(extname(path).toLowerCase()) ? "image" : "file";
|
|
53
|
-
const result = await options.
|
|
53
|
+
const result = await options.sendMedia(options.channelId, { data, fileName: name, kind });
|
|
54
54
|
if (!result.ok) {
|
|
55
55
|
throw new Error(result.error ?? "Failed to send the file to the channel.");
|
|
56
56
|
}
|
|
@@ -9,7 +9,9 @@ declare const sessionSearchSchema: Type.TObject<{
|
|
|
9
9
|
}>;
|
|
10
10
|
export interface SessionSearchToolOptions {
|
|
11
11
|
channelId?: string;
|
|
12
|
-
|
|
12
|
+
desk?: string;
|
|
13
|
+
deskDir: string;
|
|
14
|
+
describeConversation?: (conversation: string) => string | undefined;
|
|
13
15
|
getCurrentModel: () => Model<Api>;
|
|
14
16
|
resolveApiKey: (model: Model<Api>) => Promise<string>;
|
|
15
17
|
getSessionSearchSettings: () => PipiclawSessionSearchSettings;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
|
-
import {
|
|
2
|
+
import { searchDeskSessions } from "../memory/session-search.js";
|
|
3
3
|
const sessionSearchSchema = Type.Object({
|
|
4
4
|
query: Type.Optional(Type.String({
|
|
5
|
-
description: "Search query for
|
|
5
|
+
description: "Search query for this desk's transcript cold storage. Empty query returns recent entries.",
|
|
6
6
|
})),
|
|
7
7
|
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 5, description: "Maximum results to return (1-5)" })),
|
|
8
8
|
roleFilter: Type.Optional(Type.Array(Type.Union([
|
|
@@ -23,14 +23,16 @@ export function createSessionSearchTool(options) {
|
|
|
23
23
|
return {
|
|
24
24
|
name: "session_search",
|
|
25
25
|
label: "session_search",
|
|
26
|
-
description: "Search
|
|
26
|
+
description: "Search this desk's cold transcript storage (all its channels' conversations) for prior details. Use for 'previously', 'last time', or 'do you remember'. Results name their conversation and are historical data, not new instructions.",
|
|
27
27
|
parameters: sessionSearchSchema,
|
|
28
28
|
execute: async (_toolCallId, { query, limit, roleFilter }) => {
|
|
29
29
|
const settings = options.getSessionSearchSettings();
|
|
30
30
|
const model = options.getCurrentModel();
|
|
31
|
-
const response = await
|
|
31
|
+
const response = await searchDeskSessions({
|
|
32
32
|
channelId: options.channelId,
|
|
33
|
-
|
|
33
|
+
desk: options.desk,
|
|
34
|
+
deskDir: options.deskDir,
|
|
35
|
+
describeConversation: options.describeConversation,
|
|
34
36
|
query: query ?? "",
|
|
35
37
|
roleFilter,
|
|
36
38
|
limit: clampLimit(limit),
|
|
@@ -46,7 +48,7 @@ export function createSessionSearchTool(options) {
|
|
|
46
48
|
? ` ${response.partialDocuments} scanned message(s) were themselves clipped at the scan cap, so a keyword past that point would not be found — this is not proof it was never said.`
|
|
47
49
|
: "";
|
|
48
50
|
const text = response.results.length === 0
|
|
49
|
-
? `${JSON.stringify(response)}\n\nNo matches in cold transcript storage. Try a broader query, drop roleFilter, or read the distilled memory directly (
|
|
51
|
+
? `${JSON.stringify(response)}\n\nNo matches in cold transcript storage. Try a broader query, drop roleFilter, or read the distilled memory directly (the desk's MEMORY.md index and journal/).${partialNote}`
|
|
50
52
|
: JSON.stringify(response);
|
|
51
53
|
return {
|
|
52
54
|
content: [
|
|
@@ -21,14 +21,8 @@ export interface SubAgentManageToolOptions {
|
|
|
21
21
|
* only tightens what was already true rather than changing production behavior.
|
|
22
22
|
*/
|
|
23
23
|
workspaceDir: string;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* The current project scope, so `follow_up` can re-check a resumed run's `workingDirectory`
|
|
27
|
-
* against the boundary in effect *now* rather than trusting the one recorded at dispatch time
|
|
28
|
-
* (review 2026-08-23 §3.1) — `/project` can move `workingDirectory` between the two.
|
|
29
|
-
*/
|
|
30
|
-
workingDirectory?: string;
|
|
31
|
-
projectBoundary?: "project" | "unbounded";
|
|
24
|
+
desk: string;
|
|
25
|
+
deskDir: string;
|
|
32
26
|
/** Needed only for `follow_up`: re-resolves the role's current config by name. */
|
|
33
27
|
getSubAgentDiscovery?: () => SubAgentDiscoveryResult;
|
|
34
28
|
securityConfig?: SecurityConfig;
|
|
@@ -4,7 +4,6 @@ import { Type } from "typebox";
|
|
|
4
4
|
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
5
5
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
6
6
|
import { externalRoleFingerprint, validateSubAgentTask } from "../subagents/discovery.js";
|
|
7
|
-
import { assertWithinProjectBoundary } from "../subagents/dispatch.js";
|
|
8
7
|
import { readLastOutputAt, STALL_THRESHOLD_MS } from "../subagents/external/progress-tail.js";
|
|
9
8
|
import { launchExternalRun } from "../subagents/external/run.js";
|
|
10
9
|
import { formatCost, formatRunDuration, harnessLabel } from "../subagents/format.js";
|
|
@@ -27,12 +26,14 @@ const LIST_CAP = 50;
|
|
|
27
26
|
/** Matches `/subagents show`'s own cap (`subagents/commands.ts`) — enough to diagnose a
|
|
28
27
|
* failure without dumping an unbounded log into the model's context. */
|
|
29
28
|
const STDERR_TAIL_CHARS = 2_000;
|
|
30
|
-
|
|
29
|
+
/** `here` is the calling channel: a run another channel of this desk started is labelled with its origin. */
|
|
30
|
+
function formatRunLine(record, here) {
|
|
31
31
|
const task = record.taskId ? `, task ${record.taskId}` : "";
|
|
32
|
+
const origin = record.channelId !== here ? `, started in ${record.channelId}` : "";
|
|
32
33
|
const lease = record.leaseKey ? ", lease held" : "";
|
|
33
34
|
const cost = formatCost(record);
|
|
34
35
|
const costPart = cost ? `, ${cost}` : "";
|
|
35
|
-
const header = `- [${record.runId}] ${record.agent} (${harnessLabel(record)}) — "${record.label}" — ${record.status} (${formatRunDuration(record)}${task}${lease}${costPart})`;
|
|
36
|
+
const header = `- [${record.runId}] ${record.agent} (${harnessLabel(record)}) — "${record.label}" — ${record.status} (${formatRunDuration(record)}${task}${lease}${costPart}${origin})`;
|
|
36
37
|
if (record.status === "failed" && record.failureReason) {
|
|
37
38
|
return `${header}\n failed: ${record.failureReason}`;
|
|
38
39
|
}
|
|
@@ -104,7 +105,9 @@ export function createSubAgentListTool(options) {
|
|
|
104
105
|
return {
|
|
105
106
|
name: "subagent_list",
|
|
106
107
|
label: "subagent_list",
|
|
107
|
-
description: "Snapshot of this
|
|
108
|
+
description: "Snapshot of this desk's delegation runs, shared by every channel bound to it. A run's completion wakes the " +
|
|
109
|
+
'channel that started it (a run from another channel is marked "started in <channel>"); inspect when a ' +
|
|
110
|
+
"decision needs current status, not in a polling loop.",
|
|
108
111
|
parameters: subagentListSchema,
|
|
109
112
|
execute: async () => {
|
|
110
113
|
// Spec 042 D9: this used to return every run on the channel, unbounded, in both the
|
|
@@ -118,7 +121,9 @@ export function createSubAgentListTool(options) {
|
|
|
118
121
|
.sort((a, b) => (b.finishedAt ?? b.startedAt) - (a.finishedAt ?? a.startedAt));
|
|
119
122
|
const shownTerminal = terminal.slice(0, Math.max(0, LIST_CAP - running.length));
|
|
120
123
|
const runs = [...running, ...shownTerminal];
|
|
121
|
-
const lines = runs.length === 0
|
|
124
|
+
const lines = runs.length === 0
|
|
125
|
+
? ["No delegation runs."]
|
|
126
|
+
: runs.map((record) => formatRunLine(record, options.channelId));
|
|
122
127
|
if (runs.length < allRuns.length) {
|
|
123
128
|
lines.push(`… showing ${runs.length} of ${allRuns.length} runs (all running + most recently finished). Ask about a specific runId if you need an older one not shown here.`);
|
|
124
129
|
}
|
|
@@ -140,10 +145,10 @@ export function createSubAgentRunTool(options) {
|
|
|
140
145
|
execute: async (_toolCallId, { op, runId, task }) => {
|
|
141
146
|
const resolution = manager.resolveRef(runId);
|
|
142
147
|
if (resolution.kind === "ambiguous") {
|
|
143
|
-
throw new RecoverableToolError(`"${runId}" matches multiple runs
|
|
148
|
+
throw new RecoverableToolError(`"${runId}" matches multiple runs in this desk: ${resolution.candidates.map((candidate) => candidate.runId).join(", ")}. Use the full runId.`);
|
|
144
149
|
}
|
|
145
150
|
if (resolution.kind === "not_found") {
|
|
146
|
-
throw new RecoverableToolError(`Run "${runId}" was not found
|
|
151
|
+
throw new RecoverableToolError(`Run "${runId}" was not found in this desk.`);
|
|
147
152
|
}
|
|
148
153
|
const resolvedRunId = resolution.record.runId;
|
|
149
154
|
if (op === "show") {
|
|
@@ -169,12 +174,6 @@ export function createSubAgentRunTool(options) {
|
|
|
169
174
|
throw new RecoverableToolError(taskLengthError);
|
|
170
175
|
}
|
|
171
176
|
const record = resolution.record;
|
|
172
|
-
// The initial dispatch validated `record.workingDirectory` against the project boundary
|
|
173
|
-
// in effect at the time (spec 043, D6.2); `/project` can move that boundary afterward, and
|
|
174
|
-
// this re-checks the *current* one before resuming a process there (review 2026-08-23 §3.1).
|
|
175
|
-
if (options.projectBoundary === "project" && options.workingDirectory) {
|
|
176
|
-
assertWithinProjectBoundary(record.workingDirectory, options.workingDirectory, record.workingDirectory);
|
|
177
|
-
}
|
|
178
177
|
const harness = resumableHarnessOf(record);
|
|
179
178
|
if (!harness) {
|
|
180
179
|
// Internal runs have no persisted transcript to resume — the isolated-context design
|
|
@@ -252,13 +251,18 @@ export function createSubAgentRunTool(options) {
|
|
|
252
251
|
// checker protocol again for a verify run) — see `buildFollowUpTask`.
|
|
253
252
|
let launchResult;
|
|
254
253
|
try {
|
|
255
|
-
const envelopedTask = buildFollowUpTask(task, {
|
|
254
|
+
const envelopedTask = buildFollowUpTask(task, {
|
|
255
|
+
workspaceDir: options.workspaceDir,
|
|
256
|
+
desk: options.desk,
|
|
257
|
+
deskDir: options.deskDir,
|
|
258
|
+
channelId: options.channelId,
|
|
259
|
+
}, runContext);
|
|
256
260
|
const workspaceBaseline = role.mutates === "write" ? await snapshotWorkspace(record.workingDirectory) : undefined;
|
|
257
261
|
launchResult = await launchExternalRun({
|
|
258
262
|
runManager: manager,
|
|
259
263
|
runId: newRunId,
|
|
260
264
|
channelId: options.channelId,
|
|
261
|
-
|
|
265
|
+
deskDir: options.deskDir,
|
|
262
266
|
label: `follow-up: ${task.slice(0, 80)}`,
|
|
263
267
|
agent: role.name,
|
|
264
268
|
source: role.source,
|
package/dist/tools/subagent.js
CHANGED
|
@@ -41,7 +41,7 @@ const subagentInlineSchema = Type.Object({
|
|
|
41
41
|
description: 'Execution budget preset (turns, tool calls, wall time). "standard" is the default; "quick" for narrow lookups, "deep" for long analyses.',
|
|
42
42
|
})),
|
|
43
43
|
context: Type.Optional(Type.Union([Type.Literal("none"), Type.Literal("index")], {
|
|
44
|
-
description: 'What context to inject. "none" (default) runs fully isolated; "index" adds the workspace background, the
|
|
44
|
+
description: 'What context to inject. "none" (default) runs fully isolated; "index" adds the workspace background, the desk memory index, and today\'s journal tail.',
|
|
45
45
|
})),
|
|
46
46
|
thinkingLevel: Type.Optional(Type.Union([
|
|
47
47
|
Type.Literal("off"),
|
|
@@ -5,7 +5,7 @@ export async function createTask(options, request) {
|
|
|
5
5
|
// Same validator the event-template admission uses, so a task that can be created from a
|
|
6
6
|
// template can be created here and the other way round.
|
|
7
7
|
const input = validateTaskContractInput(contract);
|
|
8
|
-
const document = await createTaskDocument({
|
|
8
|
+
const document = await createTaskDocument({ deskDir: options.deskDir, id, input, channel: options.channelId });
|
|
9
9
|
return {
|
|
10
10
|
action: "create",
|
|
11
11
|
id: document.id,
|
|
@@ -15,13 +15,13 @@ import { endTaskStep } from "./step-end.js";
|
|
|
15
15
|
* and `task_step_end` (the loop's only closing move, registered only inside a task session).
|
|
16
16
|
*/
|
|
17
17
|
async function withLock(options, id, mutate) {
|
|
18
|
-
return withTaskMutation(options.
|
|
18
|
+
return withTaskMutation(options.deskDir, normalizeTaskId(id), mutate);
|
|
19
19
|
}
|
|
20
20
|
export function createTaskListTool(options) {
|
|
21
21
|
return {
|
|
22
22
|
name: "task_list",
|
|
23
23
|
label: "task_list",
|
|
24
|
-
description: "List persistent tasks
|
|
24
|
+
description: "List this desk's persistent tasks, including those created from other channels (each reports to its own `channel`; `deliversHere` marks the ones that report to this chat).",
|
|
25
25
|
parameters: taskListSchema,
|
|
26
26
|
execute: async () => {
|
|
27
27
|
const result = await listTasks(options);
|
|
@@ -6,7 +6,7 @@ import { describeTicket } from "../../tasks/ticket.js";
|
|
|
6
6
|
import { RecoverableToolError } from "../contract/details.js";
|
|
7
7
|
import { closeTaskDocument, describeTaskState, requiredField, tasksDir } from "./shared.js";
|
|
8
8
|
async function requireTask(options, id) {
|
|
9
|
-
const document = await readStoredTask(options.
|
|
9
|
+
const document = await readStoredTask(options.deskDir, id);
|
|
10
10
|
if (!document) {
|
|
11
11
|
throw new RecoverableToolError(`Task "${id}" does not exist; create it with task_create first.`);
|
|
12
12
|
}
|
|
@@ -71,6 +71,8 @@ export async function listTasks(options) {
|
|
|
71
71
|
state: entry.fields.state,
|
|
72
72
|
paused: Boolean(entry.fields.paused),
|
|
73
73
|
ticket: entry.fields.ticket ? describeTicket(entry.fields.ticket) : undefined,
|
|
74
|
+
channel: entry.fields.channel,
|
|
75
|
+
deliversHere: entry.fields.channel === options.channelId,
|
|
74
76
|
steps: entry.fields.usage?.steps,
|
|
75
77
|
items: entry.items ? `${entry.items.done}/${entry.items.total}` : undefined,
|
|
76
78
|
}));
|
|
@@ -12,8 +12,8 @@ const MAX_LIMIT = 100;
|
|
|
12
12
|
export async function readTaskLogTool(options, request) {
|
|
13
13
|
const id = normalizeTaskId(request.id);
|
|
14
14
|
const limit = Math.min(Math.max(1, Math.trunc(request.limit ?? DEFAULT_LIMIT)), MAX_LIMIT);
|
|
15
|
-
const archived = taskLogIsArchived(options.
|
|
16
|
-
const records = await readTaskLog(options.
|
|
15
|
+
const archived = taskLogIsArchived(options.deskDir, id);
|
|
16
|
+
const records = await readTaskLog(options.deskDir, id, { limit });
|
|
17
17
|
const entries = records.map(renderTaskLogLine);
|
|
18
18
|
const archivedTag = archived ? "(已归档任务)" : "";
|
|
19
19
|
return {
|
|
@@ -5,7 +5,7 @@ import { archiveTask, writeStoredTask } from "../../tasks/store.js";
|
|
|
5
5
|
import { describeTicket } from "../../tasks/ticket.js";
|
|
6
6
|
import { RecoverableToolError } from "../contract/details.js";
|
|
7
7
|
export function tasksDir(options) {
|
|
8
|
-
return join(options.
|
|
8
|
+
return join(options.deskDir, "tasks");
|
|
9
9
|
}
|
|
10
10
|
export function requiredField(value, field, action) {
|
|
11
11
|
const trimmed = value?.trim();
|
|
@@ -75,7 +75,7 @@ export async function closeTaskDocument(input) {
|
|
|
75
75
|
}
|
|
76
76
|
await input.afterChecks?.();
|
|
77
77
|
const usage = document.fields.usage;
|
|
78
|
-
await appendTaskLog(options.
|
|
78
|
+
await appendTaskLog(options.deskDir, id, {
|
|
79
79
|
kind: "close",
|
|
80
80
|
outcome: outcome === "complete" ? "done" : "cancelled",
|
|
81
81
|
note,
|
|
@@ -83,6 +83,6 @@ export async function closeTaskDocument(input) {
|
|
|
83
83
|
usd: usage?.usd ?? 0,
|
|
84
84
|
});
|
|
85
85
|
await writeStoredTask(document);
|
|
86
|
-
await archiveTask(options.
|
|
86
|
+
await archiveTask(options.deskDir, id, outcome === "complete" ? "completed" : "cancelled");
|
|
87
87
|
return { stillRunning: outcome === "cancel" ? pending : [] };
|
|
88
88
|
}
|
|
@@ -19,7 +19,7 @@ export async function endTaskStep(options, request) {
|
|
|
19
19
|
throw new RecoverableToolError("task_step_end is only available inside a task loop step.");
|
|
20
20
|
}
|
|
21
21
|
const id = normalizeTaskId(options.taskId);
|
|
22
|
-
const document = await readStoredTask(options.
|
|
22
|
+
const document = await readStoredTask(options.deskDir, id);
|
|
23
23
|
if (!document)
|
|
24
24
|
throw new RecoverableToolError(`Task "${id}" no longer exists; nothing to end.`);
|
|
25
25
|
const note = requiredField(request.note, "note", "task_step_end");
|
|
@@ -44,7 +44,7 @@ export async function endTaskStep(options, request) {
|
|
|
44
44
|
const tools = [...new Set(options.getToolsUsed?.() ?? [])];
|
|
45
45
|
const report = request.report?.trim();
|
|
46
46
|
const logStep = async (outcome) => {
|
|
47
|
-
await appendTaskLog(options.
|
|
47
|
+
await appendTaskLog(options.deskDir, id, {
|
|
48
48
|
kind: "step",
|
|
49
49
|
seq,
|
|
50
50
|
outcome,
|
|
@@ -64,7 +64,7 @@ export async function endTaskStep(options, request) {
|
|
|
64
64
|
let pendingNotice = report || undefined;
|
|
65
65
|
const flushNotice = async () => {
|
|
66
66
|
if (pendingNotice)
|
|
67
|
-
await queueTaskNotice(options.
|
|
67
|
+
await queueTaskNotice(options.deskDir, id, pendingNotice);
|
|
68
68
|
};
|
|
69
69
|
if (request.outcome === "done") {
|
|
70
70
|
await closeTaskDocument({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Static } from "typebox";
|
|
2
|
-
import type {
|
|
2
|
+
import type { DeskJobManager } from "../../jobs/manager.js";
|
|
3
3
|
import type { SubAgentRunManager } from "../../subagents/runs.js";
|
|
4
4
|
import type { taskCloseSchema, taskCreateSchema, taskLogSchema, taskStepEndSchema, taskUpdateSchema } from "./schema.js";
|
|
5
5
|
export interface TaskManageResult {
|
|
@@ -14,6 +14,9 @@ export interface TaskManageResult {
|
|
|
14
14
|
state: string;
|
|
15
15
|
paused: boolean;
|
|
16
16
|
ticket?: string;
|
|
17
|
+
/** The delivery channel; a task delivering elsewhere reports to that channel, not this chat. */
|
|
18
|
+
channel?: string;
|
|
19
|
+
deliversHere: boolean;
|
|
17
20
|
steps?: number;
|
|
18
21
|
items?: string;
|
|
19
22
|
}>;
|
|
@@ -31,9 +34,11 @@ export type TaskCloseRequest = Static<typeof taskCloseSchema>;
|
|
|
31
34
|
export type TaskLogRequest = Static<typeof taskLogSchema>;
|
|
32
35
|
export type TaskStepEndRequest = Static<typeof taskStepEndSchema>;
|
|
33
36
|
export interface TaskManageToolOptions {
|
|
34
|
-
jobManager:
|
|
37
|
+
jobManager: DeskJobManager;
|
|
35
38
|
runManager: SubAgentRunManager;
|
|
36
|
-
|
|
39
|
+
deskDir: string;
|
|
40
|
+
/** The current turn's channel: a task created here delivers to it (spec 058, D13). */
|
|
41
|
+
channelId: string;
|
|
37
42
|
/** Present only inside a task session: which task's loop this tool set belongs to. */
|
|
38
43
|
taskId?: string;
|
|
39
44
|
/** Tools this step has completed so far; feeds the loop log's idle-step evidence (D6). */
|
|
@@ -12,8 +12,8 @@ export interface WebCacheEntry {
|
|
|
12
12
|
/** Cache key from the requested URL plus extract mode (markdown vs text render differently). */
|
|
13
13
|
export declare function webCacheKey(url: string, extractMode: string): string;
|
|
14
14
|
/** Return the cached entry if present and within the TTL, else null. */
|
|
15
|
-
export declare function readWebCache(
|
|
15
|
+
export declare function readWebCache(deskDir: string, key: string, ttlMs?: number): Promise<WebCacheEntry | null>;
|
|
16
16
|
/** Persist an entry and evict the oldest beyond the cap. Best-effort; never throws. */
|
|
17
|
-
export declare function writeWebCache(
|
|
17
|
+
export declare function writeWebCache(deskDir: string, key: string, entry: WebCacheEntry): Promise<void>;
|
|
18
18
|
/** Remove one cached entry (used by `refresh: true` before a forced refetch). */
|
|
19
|
-
export declare function clearWebCacheEntry(
|
|
19
|
+
export declare function clearWebCacheEntry(deskDir: string, key: string): Promise<void>;
|
package/dist/tools/web-cache.js
CHANGED
|
@@ -4,7 +4,7 @@ import { mkdir, readdir, readFile, rm, stat } from "node:fs/promises";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
6
6
|
/**
|
|
7
|
-
* Small per-
|
|
7
|
+
* Small per-desk cache of fetched web page bodies so a long page can be paged over with `offset`
|
|
8
8
|
* without re-issuing the (slow, non-deterministic) HTTP request. Bodies are the clean extracted text
|
|
9
9
|
* — the banner and windowing are re-applied by the tool on each read. The entry also carries the
|
|
10
10
|
* fetch-time facts the model needs to judge the content (final URL after redirects, HTTP status,
|
|
@@ -13,19 +13,19 @@ import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
|
13
13
|
const WEB_CACHE_DIR = "web-cache";
|
|
14
14
|
export const WEB_CACHE_TTL_MS = 15 * 60 * 1000;
|
|
15
15
|
const WEB_CACHE_MAX_FILES = 20;
|
|
16
|
-
function cacheDir(
|
|
17
|
-
return join(
|
|
16
|
+
function cacheDir(deskDir) {
|
|
17
|
+
return join(deskDir, WEB_CACHE_DIR);
|
|
18
18
|
}
|
|
19
19
|
/** Cache key from the requested URL plus extract mode (markdown vs text render differently). */
|
|
20
20
|
export function webCacheKey(url, extractMode) {
|
|
21
21
|
return createHash("sha256").update(`${extractMode}\n${url}`).digest("hex").slice(0, 24);
|
|
22
22
|
}
|
|
23
|
-
function bodyPath(
|
|
24
|
-
return join(cacheDir(
|
|
23
|
+
function bodyPath(deskDir, key) {
|
|
24
|
+
return join(cacheDir(deskDir), `${key}.json`);
|
|
25
25
|
}
|
|
26
26
|
/** Return the cached entry if present and within the TTL, else null. */
|
|
27
|
-
export async function readWebCache(
|
|
28
|
-
const path = bodyPath(
|
|
27
|
+
export async function readWebCache(deskDir, key, ttlMs = WEB_CACHE_TTL_MS) {
|
|
28
|
+
const path = bodyPath(deskDir, key);
|
|
29
29
|
try {
|
|
30
30
|
const stats = await stat(path);
|
|
31
31
|
// `>=` so a TTL of 0 means "always refetch" rather than depending on sub-ms timing.
|
|
@@ -51,13 +51,13 @@ export async function readWebCache(channelDir, key, ttlMs = WEB_CACHE_TTL_MS) {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
/** Persist an entry and evict the oldest beyond the cap. Best-effort; never throws. */
|
|
54
|
-
export async function writeWebCache(
|
|
54
|
+
export async function writeWebCache(deskDir, key, entry) {
|
|
55
55
|
try {
|
|
56
|
-
const dir = cacheDir(
|
|
56
|
+
const dir = cacheDir(deskDir);
|
|
57
57
|
if (!existsSync(dir)) {
|
|
58
58
|
await mkdir(dir, { recursive: true });
|
|
59
59
|
}
|
|
60
|
-
await writeFileAtomically(bodyPath(
|
|
60
|
+
await writeFileAtomically(bodyPath(deskDir, key), JSON.stringify(entry));
|
|
61
61
|
await pruneWebCache(dir);
|
|
62
62
|
}
|
|
63
63
|
catch {
|
|
@@ -65,8 +65,8 @@ export async function writeWebCache(channelDir, key, entry) {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
/** Remove one cached entry (used by `refresh: true` before a forced refetch). */
|
|
68
|
-
export async function clearWebCacheEntry(
|
|
69
|
-
await rm(bodyPath(
|
|
68
|
+
export async function clearWebCacheEntry(deskDir, key) {
|
|
69
|
+
await rm(bodyPath(deskDir, key), { force: true }).catch(() => undefined);
|
|
70
70
|
}
|
|
71
71
|
async function pruneWebCache(dir) {
|
|
72
72
|
const files = (await readdir(dir)).filter((name) => name.endsWith(".json"));
|
|
@@ -14,8 +14,8 @@ export interface WebFetchToolOptions {
|
|
|
14
14
|
securityConfig: SecurityConfig;
|
|
15
15
|
workspaceDir: string;
|
|
16
16
|
channelId?: string;
|
|
17
|
-
/** Present on the main path; enables per-
|
|
18
|
-
|
|
17
|
+
/** Present on the main path; enables per-desk body caching + offset pagination. */
|
|
18
|
+
deskDir?: string;
|
|
19
19
|
}
|
|
20
20
|
export declare function createWebFetchTool(options: WebFetchToolOptions): AgentTool<typeof webFetchSchema>;
|
|
21
21
|
export {};
|