@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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Where a task's own agent session lives (spec 051, D3; one per task since spec 052, D1) —
|
|
3
|
-
* left behind when the task is archived. Kept out of `<
|
|
3
|
+
* left behind when the task is archived. Kept out of `<deskDir>` root and under a desk-directory so
|
|
4
4
|
* `session_search`'s channel scan and `/new`'s session listing do not mistake a task transcript
|
|
5
5
|
* for the channel's conversation.
|
|
6
6
|
*/
|
|
7
7
|
export declare const TASK_SESSIONS_DIRNAME = ".sessions";
|
|
8
|
-
export declare function taskSessionsDir(
|
|
9
|
-
export declare function taskSessionPath(
|
|
8
|
+
export declare function taskSessionsDir(deskDir: string): string;
|
|
9
|
+
export declare function taskSessionPath(deskDir: string, taskId: string): string;
|
|
@@ -2,14 +2,14 @@ import { join } from "node:path";
|
|
|
2
2
|
import { normalizeTaskId } from "./contract.js";
|
|
3
3
|
/**
|
|
4
4
|
* Where a task's own agent session lives (spec 051, D3; one per task since spec 052, D1) —
|
|
5
|
-
* left behind when the task is archived. Kept out of `<
|
|
5
|
+
* left behind when the task is archived. Kept out of `<deskDir>` root and under a desk-directory so
|
|
6
6
|
* `session_search`'s channel scan and `/new`'s session listing do not mistake a task transcript
|
|
7
7
|
* for the channel's conversation.
|
|
8
8
|
*/
|
|
9
9
|
export const TASK_SESSIONS_DIRNAME = ".sessions";
|
|
10
|
-
export function taskSessionsDir(
|
|
11
|
-
return join(
|
|
10
|
+
export function taskSessionsDir(deskDir) {
|
|
11
|
+
return join(deskDir, "tasks", TASK_SESSIONS_DIRNAME);
|
|
12
12
|
}
|
|
13
|
-
export function taskSessionPath(
|
|
14
|
-
return join(taskSessionsDir(
|
|
13
|
+
export function taskSessionPath(deskDir, taskId) {
|
|
14
|
+
return join(taskSessionsDir(deskDir), `${normalizeTaskId(taskId)}.jsonl`);
|
|
15
15
|
}
|
package/dist/tasks/steer.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** Queue guidance for the task's next step. Repeated calls append, so nothing is silently lost. */
|
|
2
|
-
export declare function queueTaskSteer(
|
|
2
|
+
export declare function queueTaskSteer(deskDir: string, id: string, text: string, label?: string): Promise<void>;
|
|
3
3
|
/** Read and clear the pending guidance. Returns `undefined` when there is none. */
|
|
4
|
-
export declare function consumeTaskSteer(
|
|
4
|
+
export declare function consumeTaskSteer(deskDir: string, id: string): Promise<string | undefined>;
|
|
5
5
|
/** Whether guidance is waiting, without consuming it (for `/tasks show`). */
|
|
6
|
-
export declare function hasTaskSteer(
|
|
7
|
-
export declare function queueTaskNotice(
|
|
8
|
-
export declare function consumeTaskNotice(
|
|
6
|
+
export declare function hasTaskSteer(deskDir: string, id: string): boolean;
|
|
7
|
+
export declare function queueTaskNotice(deskDir: string, id: string, text: string): Promise<void>;
|
|
8
|
+
export declare function consumeTaskNotice(deskDir: string, id: string): Promise<string | undefined>;
|
package/dist/tasks/steer.js
CHANGED
|
@@ -4,6 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
5
5
|
import { formatLocalTime } from "../shared/local-time.js";
|
|
6
6
|
import { normalizeTaskId } from "./contract.js";
|
|
7
|
+
import { withTaskMutation } from "./mutation-lock.js";
|
|
7
8
|
/**
|
|
8
9
|
* Out-of-band guidance for a running task loop (spec 051, D11) — `/tasks steer` and `/tasks reply`.
|
|
9
10
|
*
|
|
@@ -12,68 +13,69 @@ import { normalizeTaskId } from "./contract.js";
|
|
|
12
13
|
* loop injects whole and which has a hard size budget) and must be consumed exactly once. The
|
|
13
14
|
* next step reads it, deletes it, and puts the text at the top of its own brief; nothing is left
|
|
14
15
|
* behind for a later step to act on twice.
|
|
16
|
+
*
|
|
17
|
+
* Each read-modify-write runs under the task's mutation lock: a TUI's `/tasks steer` appending
|
|
18
|
+
* while the daemon's step consumes would otherwise lose the appended line.
|
|
15
19
|
*/
|
|
16
|
-
function steerDir(
|
|
17
|
-
return join(
|
|
20
|
+
function steerDir(deskDir) {
|
|
21
|
+
return join(deskDir, "tasks", ".steer");
|
|
18
22
|
}
|
|
19
|
-
function steerPath(
|
|
20
|
-
return join(steerDir(
|
|
23
|
+
function steerPath(deskDir, id) {
|
|
24
|
+
return join(steerDir(deskDir), `${normalizeTaskId(id)}.md`);
|
|
21
25
|
}
|
|
22
26
|
/** Queue guidance for the task's next step. Repeated calls append, so nothing is silently lost. */
|
|
23
|
-
export async function queueTaskSteer(
|
|
27
|
+
export async function queueTaskSteer(deskDir, id, text, label = "用户指示") {
|
|
24
28
|
const trimmed = text.trim();
|
|
25
29
|
if (!trimmed)
|
|
26
30
|
return;
|
|
27
|
-
await
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
await withTaskMutation(deskDir, id, async () => {
|
|
32
|
+
await mkdir(steerDir(deskDir), { recursive: true });
|
|
33
|
+
const path = steerPath(deskDir, id);
|
|
34
|
+
const existing = existsSync(path) ? `${await readFile(path, "utf-8")}\n` : "";
|
|
35
|
+
await writeFileAtomically(path, `${existing}- [${formatLocalTime()}] ${label}:${trimmed}\n`);
|
|
36
|
+
});
|
|
31
37
|
}
|
|
32
38
|
/** Read and clear the pending guidance. Returns `undefined` when there is none. */
|
|
33
|
-
export async function consumeTaskSteer(
|
|
34
|
-
|
|
39
|
+
export async function consumeTaskSteer(deskDir, id) {
|
|
40
|
+
return consumeOnce(deskDir, id, steerPath(deskDir, id));
|
|
41
|
+
}
|
|
42
|
+
async function consumeOnce(deskDir, id, path) {
|
|
35
43
|
if (!existsSync(path))
|
|
36
44
|
return undefined;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
return withTaskMutation(deskDir, id, async () => {
|
|
46
|
+
try {
|
|
47
|
+
const text = (await readFile(path, "utf-8")).trim();
|
|
48
|
+
await rm(path, { force: true });
|
|
49
|
+
return text || undefined;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
45
55
|
}
|
|
46
56
|
/** Whether guidance is waiting, without consuming it (for `/tasks show`). */
|
|
47
|
-
export function hasTaskSteer(
|
|
48
|
-
return existsSync(steerPath(
|
|
57
|
+
export function hasTaskSteer(deskDir, id) {
|
|
58
|
+
return existsSync(steerPath(deskDir, id));
|
|
49
59
|
}
|
|
50
60
|
/**
|
|
51
61
|
* The other direction: what a step asked the runtime to tell the user (`task_step_end`'s
|
|
52
62
|
* `notify`). Held in a file rather than returned inline because the tool result never reaches the
|
|
53
63
|
* transport — the runtime reads and clears this after the step ends, and delivers it once.
|
|
54
64
|
*/
|
|
55
|
-
function noticePath(
|
|
56
|
-
return join(steerDir(
|
|
65
|
+
function noticePath(deskDir, id) {
|
|
66
|
+
return join(steerDir(deskDir), `${normalizeTaskId(id)}.out.md`);
|
|
57
67
|
}
|
|
58
|
-
export async function queueTaskNotice(
|
|
68
|
+
export async function queueTaskNotice(deskDir, id, text) {
|
|
59
69
|
const trimmed = text.trim();
|
|
60
70
|
if (!trimmed)
|
|
61
71
|
return;
|
|
62
|
-
await
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
await withTaskMutation(deskDir, id, async () => {
|
|
73
|
+
await mkdir(steerDir(deskDir), { recursive: true });
|
|
74
|
+
const path = noticePath(deskDir, id);
|
|
75
|
+
const existing = existsSync(path) ? `${await readFile(path, "utf-8")}\n\n` : "";
|
|
76
|
+
await writeFileAtomically(path, `${existing}${trimmed}`);
|
|
77
|
+
});
|
|
66
78
|
}
|
|
67
|
-
export async function consumeTaskNotice(
|
|
68
|
-
|
|
69
|
-
if (!existsSync(path))
|
|
70
|
-
return undefined;
|
|
71
|
-
try {
|
|
72
|
-
const text = (await readFile(path, "utf-8")).trim();
|
|
73
|
-
await rm(path, { force: true });
|
|
74
|
-
return text || undefined;
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
return undefined;
|
|
78
|
-
}
|
|
79
|
+
export async function consumeTaskNotice(deskDir, id) {
|
|
80
|
+
return consumeOnce(deskDir, id, noticePath(deskDir, id));
|
|
79
81
|
}
|
package/dist/tasks/store.d.ts
CHANGED
|
@@ -12,17 +12,17 @@ export interface StoredTaskDocument {
|
|
|
12
12
|
* clip: a contract over the target is written as-is and warned about once per write.
|
|
13
13
|
*/
|
|
14
14
|
export declare const MAX_CONTRACT_BYTES: number;
|
|
15
|
-
export declare function tasksDir(
|
|
16
|
-
export declare function taskPath(
|
|
17
|
-
export declare function archivedTaskPath(
|
|
18
|
-
export declare function readStoredTask(
|
|
15
|
+
export declare function tasksDir(deskDir: string): string;
|
|
16
|
+
export declare function taskPath(deskDir: string, id: string): string;
|
|
17
|
+
export declare function archivedTaskPath(deskDir: string, id: string): string;
|
|
18
|
+
export declare function readStoredTask(deskDir: string, idInput: string, includeArchive?: boolean): Promise<StoredTaskDocument | undefined>;
|
|
19
19
|
export declare function writeStoredTask(document: StoredTaskDocument): Promise<void>;
|
|
20
|
-
export declare function updateStoredTask(
|
|
20
|
+
export declare function updateStoredTask(deskDir: string, id: string, update: (document: StoredTaskDocument) => void, includeArchive?: boolean): Promise<StoredTaskDocument | undefined>;
|
|
21
21
|
/**
|
|
22
22
|
* Park a task on a ticket. The ticket must already have been through `resolveTicket` — this
|
|
23
23
|
* function persists a decision, it does not make one.
|
|
24
24
|
*/
|
|
25
|
-
export declare function parkTask(
|
|
25
|
+
export declare function parkTask(deskDir: string, id: string, ticket: Ticket): Promise<StoredTaskDocument | undefined>;
|
|
26
26
|
/**
|
|
27
27
|
* Redeem a ticket: the single, idempotent transition from `parked` back to `open`.
|
|
28
28
|
*
|
|
@@ -32,12 +32,12 @@ export declare function parkTask(channelDir: string, id: string, ticket: Ticket)
|
|
|
32
32
|
* needing its own claim bookkeeping: the outermost wake-claim in `wake-claim.ts` still guards
|
|
33
33
|
* duplicate delivery, and this guards duplicate application.
|
|
34
34
|
*/
|
|
35
|
-
export declare function redeemTicket(
|
|
35
|
+
export declare function redeemTicket(deskDir: string, id: string, matches: (ticket: Ticket) => boolean): Promise<{
|
|
36
36
|
document: StoredTaskDocument;
|
|
37
37
|
ticket: Ticket;
|
|
38
38
|
} | undefined>;
|
|
39
39
|
/** Disable a task without losing its stage. `paused` present *is* the disabled state (D1). */
|
|
40
|
-
export declare function pauseTask(
|
|
40
|
+
export declare function pauseTask(deskDir: string, id: string, paused: Omit<TaskPaused, "at"> & {
|
|
41
41
|
at?: string;
|
|
42
42
|
}): Promise<StoredTaskDocument | undefined>;
|
|
43
43
|
/**
|
|
@@ -45,7 +45,7 @@ export declare function pauseTask(channelDir: string, id: string, paused: Omit<T
|
|
|
45
45
|
* (the double-expiry stop) is reopened and its expiry count cleared: the user has looked at it,
|
|
46
46
|
* and resuming onto the same dead ticket would just expire — and pause — it a third time.
|
|
47
47
|
*/
|
|
48
|
-
export declare function resumeTask(
|
|
48
|
+
export declare function resumeTask(deskDir: string, id: string): Promise<StoredTaskDocument | undefined>;
|
|
49
49
|
/**
|
|
50
50
|
* The backstop transition (D2): a parked task whose `by` has passed goes back to `open` so its
|
|
51
51
|
* next step can re-check reality, and the second consecutive expiry stops the task and
|
|
@@ -54,7 +54,7 @@ export declare function resumeTask(channelDir: string, id: string): Promise<Stor
|
|
|
54
54
|
* Returns what the caller should do about it, or `undefined` when nothing applied.
|
|
55
55
|
*/
|
|
56
56
|
export type TicketExpiryOutcome = "reopened" | "paused";
|
|
57
|
-
export declare function expireTicket(
|
|
57
|
+
export declare function expireTicket(deskDir: string, id: string, limit?: number): Promise<{
|
|
58
58
|
document: StoredTaskDocument;
|
|
59
59
|
outcome: TicketExpiryOutcome;
|
|
60
60
|
ticket: string;
|
|
@@ -77,4 +77,4 @@ export declare class ArchiveUndoError extends Error {
|
|
|
77
77
|
* log shard are in the archive, and "rejected" to mean the pre-call state still stands (or, if the
|
|
78
78
|
* undo itself failed, the error says so).
|
|
79
79
|
*/
|
|
80
|
-
export declare function archiveTask(
|
|
80
|
+
export declare function archiveTask(deskDir: string, id: string, outcome: TaskArchiveOutcome): Promise<void>;
|
package/dist/tasks/store.js
CHANGED
|
@@ -17,19 +17,19 @@ import { describeTicket, ticketExpired } from "./ticket.js";
|
|
|
17
17
|
* clip: a contract over the target is written as-is and warned about once per write.
|
|
18
18
|
*/
|
|
19
19
|
export const MAX_CONTRACT_BYTES = 4 * 1024;
|
|
20
|
-
export function tasksDir(
|
|
21
|
-
return join(
|
|
20
|
+
export function tasksDir(deskDir) {
|
|
21
|
+
return join(deskDir, "tasks");
|
|
22
22
|
}
|
|
23
|
-
export function taskPath(
|
|
24
|
-
return join(tasksDir(
|
|
23
|
+
export function taskPath(deskDir, id) {
|
|
24
|
+
return join(tasksDir(deskDir), `${normalizeTaskId(id)}.md`);
|
|
25
25
|
}
|
|
26
|
-
export function archivedTaskPath(
|
|
27
|
-
return join(tasksDir(
|
|
26
|
+
export function archivedTaskPath(deskDir, id) {
|
|
27
|
+
return join(tasksDir(deskDir), "archive", `${normalizeTaskId(id)}.md`);
|
|
28
28
|
}
|
|
29
|
-
export async function readStoredTask(
|
|
29
|
+
export async function readStoredTask(deskDir, idInput, includeArchive = false) {
|
|
30
30
|
const id = normalizeTaskId(idInput);
|
|
31
|
-
const activePath = taskPath(
|
|
32
|
-
const archivePath = archivedTaskPath(
|
|
31
|
+
const activePath = taskPath(deskDir, id);
|
|
32
|
+
const archivePath = archivedTaskPath(deskDir, id);
|
|
33
33
|
const path = existsSync(activePath)
|
|
34
34
|
? activePath
|
|
35
35
|
: includeArchive && existsSync(archivePath)
|
|
@@ -52,9 +52,9 @@ export async function writeStoredTask(document) {
|
|
|
52
52
|
}
|
|
53
53
|
await writeFileAtomically(document.path, rendered);
|
|
54
54
|
}
|
|
55
|
-
export async function updateStoredTask(
|
|
56
|
-
return withTaskMutation(
|
|
57
|
-
const document = await readStoredTask(
|
|
55
|
+
export async function updateStoredTask(deskDir, id, update, includeArchive = false) {
|
|
56
|
+
return withTaskMutation(deskDir, id, async () => {
|
|
57
|
+
const document = await readStoredTask(deskDir, id, includeArchive);
|
|
58
58
|
if (!document)
|
|
59
59
|
return undefined;
|
|
60
60
|
update(document);
|
|
@@ -66,8 +66,8 @@ export async function updateStoredTask(channelDir, id, update, includeArchive =
|
|
|
66
66
|
* Park a task on a ticket. The ticket must already have been through `resolveTicket` — this
|
|
67
67
|
* function persists a decision, it does not make one.
|
|
68
68
|
*/
|
|
69
|
-
export async function parkTask(
|
|
70
|
-
return updateStoredTask(
|
|
69
|
+
export async function parkTask(deskDir, id, ticket) {
|
|
70
|
+
return updateStoredTask(deskDir, id, (task) => {
|
|
71
71
|
task.fields.state = "parked";
|
|
72
72
|
task.fields.ticket = ticket;
|
|
73
73
|
});
|
|
@@ -81,9 +81,9 @@ export async function parkTask(channelDir, id, ticket) {
|
|
|
81
81
|
* needing its own claim bookkeeping: the outermost wake-claim in `wake-claim.ts` still guards
|
|
82
82
|
* duplicate delivery, and this guards duplicate application.
|
|
83
83
|
*/
|
|
84
|
-
export async function redeemTicket(
|
|
84
|
+
export async function redeemTicket(deskDir, id, matches) {
|
|
85
85
|
let redeemed;
|
|
86
|
-
const document = await updateStoredTask(
|
|
86
|
+
const document = await updateStoredTask(deskDir, id, (task) => {
|
|
87
87
|
if (task.fields.state !== "parked" || !task.fields.ticket || task.fields.paused)
|
|
88
88
|
return;
|
|
89
89
|
if (!matches(task.fields.ticket))
|
|
@@ -98,8 +98,8 @@ export async function redeemTicket(channelDir, id, matches) {
|
|
|
98
98
|
return document && redeemed ? { document, ticket: redeemed } : undefined;
|
|
99
99
|
}
|
|
100
100
|
/** Disable a task without losing its stage. `paused` present *is* the disabled state (D1). */
|
|
101
|
-
export async function pauseTask(
|
|
102
|
-
return updateStoredTask(
|
|
101
|
+
export async function pauseTask(deskDir, id, paused) {
|
|
102
|
+
return updateStoredTask(deskDir, id, (task) => {
|
|
103
103
|
task.fields.paused = { ...paused, at: paused.at ?? formatLocalTime() };
|
|
104
104
|
});
|
|
105
105
|
}
|
|
@@ -108,8 +108,8 @@ export async function pauseTask(channelDir, id, paused) {
|
|
|
108
108
|
* (the double-expiry stop) is reopened and its expiry count cleared: the user has looked at it,
|
|
109
109
|
* and resuming onto the same dead ticket would just expire — and pause — it a third time.
|
|
110
110
|
*/
|
|
111
|
-
export async function resumeTask(
|
|
112
|
-
return updateStoredTask(
|
|
111
|
+
export async function resumeTask(deskDir, id) {
|
|
112
|
+
return updateStoredTask(deskDir, id, (task) => {
|
|
113
113
|
task.fields.paused = undefined;
|
|
114
114
|
if (task.fields.state === "parked" && task.fields.ticket && ticketExpired(task.fields.ticket)) {
|
|
115
115
|
task.fields.state = "open";
|
|
@@ -119,10 +119,10 @@ export async function resumeTask(channelDir, id) {
|
|
|
119
119
|
}
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
-
export async function expireTicket(
|
|
122
|
+
export async function expireTicket(deskDir, id, limit = 2) {
|
|
123
123
|
let outcome;
|
|
124
124
|
let summary = "";
|
|
125
|
-
const document = await updateStoredTask(
|
|
125
|
+
const document = await updateStoredTask(deskDir, id, (task) => {
|
|
126
126
|
const ticket = task.fields.ticket;
|
|
127
127
|
if (task.fields.state !== "parked" || !ticket || task.fields.paused)
|
|
128
128
|
return;
|
|
@@ -145,7 +145,7 @@ export async function expireTicket(channelDir, id, limit = 2) {
|
|
|
145
145
|
});
|
|
146
146
|
if (!document || !outcome)
|
|
147
147
|
return undefined;
|
|
148
|
-
await appendTaskLog(
|
|
148
|
+
await appendTaskLog(deskDir, id, {
|
|
149
149
|
kind: "expired",
|
|
150
150
|
ticket: summary,
|
|
151
151
|
action: outcome,
|
|
@@ -173,14 +173,17 @@ export class ArchiveUndoError extends Error {
|
|
|
173
173
|
* log shard are in the archive, and "rejected" to mean the pre-call state still stands (or, if the
|
|
174
174
|
* undo itself failed, the error says so).
|
|
175
175
|
*/
|
|
176
|
-
export
|
|
176
|
+
export function archiveTask(deskDir, id, outcome) {
|
|
177
|
+
return withTaskMutation(deskDir, id, () => moveToArchive(deskDir, id, outcome));
|
|
178
|
+
}
|
|
179
|
+
async function moveToArchive(deskDir, id, outcome) {
|
|
177
180
|
const normalized = normalizeTaskId(id);
|
|
178
|
-
const archiveDir = join(tasksDir(
|
|
181
|
+
const archiveDir = join(tasksDir(deskDir), "archive");
|
|
179
182
|
await mkdir(archiveDir, { recursive: true });
|
|
180
|
-
const document = await readStoredTask(
|
|
183
|
+
const document = await readStoredTask(deskDir, normalized);
|
|
181
184
|
if (!document)
|
|
182
185
|
return;
|
|
183
|
-
const archiveMd = archivedTaskPath(
|
|
186
|
+
const archiveMd = archivedTaskPath(deskDir, normalized);
|
|
184
187
|
const archiveLog = join(archiveDir, `${normalized}.jsonl`);
|
|
185
188
|
for (const target of [archiveMd, ...LOG_SUFFIXES.map((suffix) => `${archiveLog}${suffix}`)]) {
|
|
186
189
|
if (existsSync(target))
|
|
@@ -192,7 +195,7 @@ export async function archiveTask(channelDir, id, outcome) {
|
|
|
192
195
|
// whatever has already rotated into `.1`/`.2` (R9). Moving only the current file stranded
|
|
193
196
|
// those shards in the now-empty active `tasks/` dir, permanently split from the record they
|
|
194
197
|
// belong to and outside anywhere `readTaskLog` looks for an archived task.
|
|
195
|
-
const logFrom = taskLogPath(
|
|
198
|
+
const logFrom = taskLogPath(deskDir, normalized);
|
|
196
199
|
const movedLogs = [];
|
|
197
200
|
let wroteArchive = false;
|
|
198
201
|
try {
|
|
@@ -206,7 +209,7 @@ export async function archiveTask(channelDir, id, outcome) {
|
|
|
206
209
|
}
|
|
207
210
|
await writeStoredTask({ ...document, path: archiveMd });
|
|
208
211
|
wroteArchive = true;
|
|
209
|
-
await rm(taskPath(
|
|
212
|
+
await rm(taskPath(deskDir, normalized), { force: true });
|
|
210
213
|
}
|
|
211
214
|
catch (error) {
|
|
212
215
|
const undoFailures = [];
|
package/dist/tools/bash.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import { type Executor } from "../executor.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { DeskJobManager } from "../jobs/manager.js";
|
|
5
5
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
6
6
|
/**
|
|
7
7
|
* Default wall-clock timeout for bash commands when the caller supplies neither a
|
|
@@ -23,11 +23,11 @@ export interface BashToolOptions {
|
|
|
23
23
|
securityContext?: SecurityRuntimeContext;
|
|
24
24
|
channelId?: string;
|
|
25
25
|
/**
|
|
26
|
-
* The
|
|
27
|
-
* `<
|
|
26
|
+
* The desk directory. When set, the "full output" spill file lives under
|
|
27
|
+
* `<deskDir>/logs/` so the pointer the tool hands back is one the model's `read` can open
|
|
28
28
|
* under both path-guard boundaries. Absent on the sub-agent path (spill falls back to tmpdir).
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
deskDir?: string;
|
|
31
31
|
/**
|
|
32
32
|
* When true, route each command through the `rtk` command optimizer before executing
|
|
33
33
|
* (best-effort; falls back to the raw command when rtk is unavailable or declines).
|
|
@@ -38,7 +38,7 @@ export interface BashToolOptions {
|
|
|
38
38
|
* Present only on the main path when `tools.jobs.enabled` is on. Enables `async: true`
|
|
39
39
|
* background execution. Absent on the sub-agent path, so sub-agents cannot background jobs.
|
|
40
40
|
*/
|
|
41
|
-
jobManager?:
|
|
41
|
+
jobManager?: DeskJobManager;
|
|
42
42
|
/**
|
|
43
43
|
* Set inside a task's session. A background job started here belongs to this task, so the
|
|
44
44
|
* runtime binds the id rather than asking the model to repeat it (and rejects a conflicting one
|
package/dist/tools/bash.js
CHANGED
|
@@ -3,6 +3,7 @@ import { mkdir, open, readdir, stat, unlink } from "node:fs/promises";
|
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { Type } from "typebox";
|
|
6
|
+
import { getDeskLogsDir } from "../desk/paths.js";
|
|
6
7
|
import { CommandTerminatedError, EXECUTOR_SHELL_IS_BASH } from "../executor.js";
|
|
7
8
|
import { formatBlockMessage, GuardBlockedError } from "../security/block-message.js";
|
|
8
9
|
import { guardCommand } from "../security/command-guard.js";
|
|
@@ -19,26 +20,23 @@ import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateTail } from "
|
|
|
19
20
|
* Callers that legitimately need longer must pass an explicit `timeout`.
|
|
20
21
|
*/
|
|
21
22
|
export const DEFAULT_BASH_TIMEOUT_SECONDS = 300;
|
|
22
|
-
/**
|
|
23
|
-
const BASH_LOG_DIR_NAME = "logs";
|
|
24
|
-
/** Spill files kept per channel before the oldest are pruned on the next tool build. */
|
|
23
|
+
/** Spill files kept per desk before the oldest are pruned on the next tool build. */
|
|
25
24
|
const BASH_LOG_RETENTION = 40;
|
|
26
25
|
/** Bytes read back from the spill file when the in-memory capture was truncated (D2.3). */
|
|
27
26
|
const TAIL_FROM_SPILL_BYTES = DEFAULT_MAX_BYTES * 4;
|
|
28
27
|
/**
|
|
29
|
-
* Where the "full output" spill file for a command goes
|
|
30
|
-
* path,
|
|
31
|
-
*
|
|
32
|
-
* channel dir, so they fall back to the OS temp dir as before.
|
|
28
|
+
* Where the "full output" spill file for a command goes: under `<deskDir>/logs/` on the main
|
|
29
|
+
* path, next to the rest of the agent's files (fix plan §2.2). Sub-agents get no channel dir, so
|
|
30
|
+
* they fall back to the OS temp dir as before.
|
|
33
31
|
*/
|
|
34
|
-
function getSpillFilePath(
|
|
32
|
+
function getSpillFilePath(deskDir) {
|
|
35
33
|
const id = randomBytes(8).toString("hex");
|
|
36
|
-
const dir =
|
|
34
|
+
const dir = deskDir ? getDeskLogsDir(deskDir) : tmpdir();
|
|
37
35
|
return join(dir, `pipiclaw-bash-${id}.log`);
|
|
38
36
|
}
|
|
39
|
-
/** Best-effort: keep the
|
|
40
|
-
async function pruneBashLogs(
|
|
41
|
-
const dir =
|
|
37
|
+
/** Best-effort: keep the desk's `logs/` dir from growing without bound. */
|
|
38
|
+
async function pruneBashLogs(deskDir) {
|
|
39
|
+
const dir = getDeskLogsDir(deskDir);
|
|
42
40
|
let names;
|
|
43
41
|
try {
|
|
44
42
|
names = (await readdir(dir)).filter((n) => n.startsWith("pipiclaw-bash-") && n.endsWith(".log"));
|
|
@@ -154,10 +152,10 @@ export function createBashTool(executor, options = {}) {
|
|
|
154
152
|
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
155
153
|
const securityContext = options.securityContext ?? {
|
|
156
154
|
agentWorkspaceDir: process.cwd(),
|
|
157
|
-
|
|
155
|
+
cwd: process.cwd(),
|
|
158
156
|
};
|
|
159
|
-
if (options.
|
|
160
|
-
void pruneBashLogs(options.
|
|
157
|
+
if (options.deskDir) {
|
|
158
|
+
void pruneBashLogs(options.deskDir);
|
|
161
159
|
}
|
|
162
160
|
return {
|
|
163
161
|
name: "bash",
|
|
@@ -220,9 +218,12 @@ export function createBashTool(executor, options = {}) {
|
|
|
220
218
|
if (!options.jobManager) {
|
|
221
219
|
throw new RecoverableToolError("This context does not support background execution (sub-agents never get it). Run the command without async, or split it into shorter steps.");
|
|
222
220
|
}
|
|
221
|
+
if (!options.channelId)
|
|
222
|
+
throw new Error("Background execution has no delivery channel; run without async and have the deployer restore this context.");
|
|
223
223
|
const willNotify = notify ?? true;
|
|
224
224
|
const jobLabel = clipText(effectiveCommand, 60, { collapseWhitespace: true });
|
|
225
225
|
const job = await options.jobManager.start(effectiveCommand, jobLabel, effectiveTimeout, {
|
|
226
|
+
channelId: options.channelId,
|
|
226
227
|
signal,
|
|
227
228
|
notify: willNotify,
|
|
228
229
|
...(effectiveTaskId ? { taskId: effectiveTaskId } : {}),
|
|
@@ -308,9 +309,9 @@ export function createBashTool(executor, options = {}) {
|
|
|
308
309
|
}
|
|
309
310
|
return { text, details: { ...details, producedOutput: output.trim().length > 0 } };
|
|
310
311
|
};
|
|
311
|
-
const spillPath = getSpillFilePath(options.
|
|
312
|
-
if (options.
|
|
313
|
-
await mkdir(
|
|
312
|
+
const spillPath = getSpillFilePath(options.deskDir);
|
|
313
|
+
if (options.deskDir) {
|
|
314
|
+
await mkdir(getDeskLogsDir(options.deskDir), { recursive: true }).catch(() => undefined);
|
|
314
315
|
}
|
|
315
316
|
try {
|
|
316
317
|
const result = await executor.exec(effectiveCommand, {
|
|
@@ -9,3 +9,10 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const SUBAGENT_TOOL_NAMES: readonly ["read", "grep", "glob", "bash", "edit", "write", "web_search", "web_fetch"];
|
|
11
11
|
export type SubAgentToolName = (typeof SUBAGENT_TOOL_NAMES)[number];
|
|
12
|
+
/**
|
|
13
|
+
* The tools a request-scoped generation (a Web API request with no `conversation`) is given. It has
|
|
14
|
+
* no channel to deliver to once the request ends, so nothing that outlives it — a task, an event,
|
|
15
|
+
* a delegation, a background job, a change to a task's waiting condition — is offered. An
|
|
16
|
+
* allowlist, so a tool added later stays out until someone decides it belongs here.
|
|
17
|
+
*/
|
|
18
|
+
export declare const REQUEST_SCOPED_TOOL_NAMES: readonly ["read", "grep", "glob", "bash", "edit", "write", "web_search", "web_fetch", "skill", "memory_search", "memory_save", "memory_forget", "session_search", "task_list"];
|
|
@@ -17,3 +17,25 @@ export const SUBAGENT_TOOL_NAMES = [
|
|
|
17
17
|
"web_search",
|
|
18
18
|
"web_fetch",
|
|
19
19
|
];
|
|
20
|
+
/**
|
|
21
|
+
* The tools a request-scoped generation (a Web API request with no `conversation`) is given. It has
|
|
22
|
+
* no channel to deliver to once the request ends, so nothing that outlives it — a task, an event,
|
|
23
|
+
* a delegation, a background job, a change to a task's waiting condition — is offered. An
|
|
24
|
+
* allowlist, so a tool added later stays out until someone decides it belongs here.
|
|
25
|
+
*/
|
|
26
|
+
export const REQUEST_SCOPED_TOOL_NAMES = [
|
|
27
|
+
"read",
|
|
28
|
+
"grep",
|
|
29
|
+
"glob",
|
|
30
|
+
"bash",
|
|
31
|
+
"edit",
|
|
32
|
+
"write",
|
|
33
|
+
"web_search",
|
|
34
|
+
"web_fetch",
|
|
35
|
+
"skill",
|
|
36
|
+
"memory_search",
|
|
37
|
+
"memory_save",
|
|
38
|
+
"memory_forget",
|
|
39
|
+
"session_search",
|
|
40
|
+
"task_list",
|
|
41
|
+
];
|
package/dist/tools/edit.js
CHANGED
|
@@ -260,7 +260,7 @@ export function createEditTool(fileStore, options = {}) {
|
|
|
260
260
|
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
261
261
|
const securityContext = options.securityContext ?? {
|
|
262
262
|
agentWorkspaceDir: process.cwd(),
|
|
263
|
-
|
|
263
|
+
cwd: process.cwd(),
|
|
264
264
|
};
|
|
265
265
|
// Per-tool-instance counter of consecutive byte-identical no-op edits, keyed by the exact
|
|
266
266
|
// (path, oldText, newText) payload. A model stuck re-issuing the same no-op edit is chasing a
|
|
@@ -66,7 +66,9 @@ export interface EventManageRequest {
|
|
|
66
66
|
definition?: EventDefinitionInput;
|
|
67
67
|
}
|
|
68
68
|
export interface EventManageToolOptions {
|
|
69
|
-
|
|
69
|
+
/** Events belong to the desk: they live in `<deskDir>/events/` (spec 058, D14). */
|
|
70
|
+
deskDir: string;
|
|
71
|
+
/** The current channel: a created event delivers here; an update keeps the event's own delivery channel. */
|
|
70
72
|
channelId: string;
|
|
71
73
|
commandGuardConfig: SecurityConfig["commandGuard"];
|
|
72
74
|
}
|