@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/subagents/runs.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { readdir, readFile, rename, rmdir, stat, unlink } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { getChannelDir } from "../channel/channel-paths.js";
|
|
4
3
|
import * as log from "../log.js";
|
|
5
4
|
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
6
5
|
import { isProcessAlive, killProcessGroup, readProcessStartTime } from "../shared/host-process.js";
|
|
@@ -9,11 +8,13 @@ import { createSerialQueue } from "../shared/serial-queue.js";
|
|
|
9
8
|
import { errorMessage } from "../shared/text-utils.js";
|
|
10
9
|
import { beginWakeClaim, finishWakeClaim } from "../shared/wake-claim.js";
|
|
11
10
|
import { logTaskDispatch, logTaskSettlement } from "../tasks/bound-work.js";
|
|
11
|
+
import { redeemTicket } from "../tasks/store.js";
|
|
12
12
|
import { createEmptyUsageTotals } from "../usage/totals.js";
|
|
13
|
-
import { buildRunCompletionWake, WAKE_OUTPUT_TAIL_CHARS } from "./completion-wake.js";
|
|
13
|
+
import { buildRunCompletionWake, countWakeSiblings, WAKE_OUTPUT_TAIL_CHARS } from "./completion-wake.js";
|
|
14
14
|
import { createProgressPacer, startExternalProgressTail } from "./external/progress-tail.js";
|
|
15
15
|
import { finalizeExternalRun } from "./external/settlement.js";
|
|
16
|
-
import {
|
|
16
|
+
import { runArchiveEntry, runLedgerEntry } from "./run-archive.js";
|
|
17
|
+
import { applyPendingSettlement, createPendingSettlement, isTerminal, MAX_RUNNING_SUBAGENT_RUNS_PER_DESK, MAX_RUNNING_SUBAGENT_RUNS_PER_HOST, normalizeRunIdQuery, parseRunRecord, RUN_ARTIFACT_FILENAMES, RUN_ID_PREFIX, RUN_RETENTION_MS, randomRunIdSuffix, } from "./run-record.js";
|
|
17
18
|
import { acquireWorkspaceLease, formatWorkspaceLeaseConflict, releaseWorkspaceLease } from "./workspace-lease.js";
|
|
18
19
|
/** Registration is serialized across channel managers so the host-wide count and insertion are
|
|
19
20
|
* one admission transaction. The per-run manager queue alone cannot protect the 19 -> 20 edge
|
|
@@ -29,14 +30,15 @@ async function unlinkIfPresent(path) {
|
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
|
-
* Per-
|
|
33
|
+
* Per-desk manager for delegation runs — the single settlement/usage/wake authority for both
|
|
33
34
|
* internal sub-agents and (once wired) external harnesses (D7). Modeled directly on
|
|
34
|
-
* `
|
|
35
|
+
* `DeskJobManager`; the two are not unified because a run's terminal status depends on a
|
|
35
36
|
* protocol verdict, not just process exit (D4), so the state machines genuinely differ.
|
|
36
37
|
*/
|
|
37
38
|
export class SubAgentRunManager {
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
/** `target` owns these runs; each run's own `channelId` is where it reports back. */
|
|
40
|
+
constructor(target, options) {
|
|
41
|
+
this.target = target;
|
|
40
42
|
this.options = options;
|
|
41
43
|
this.runs = new Map();
|
|
42
44
|
/** In-memory cancel handles for runs alive in *this* process (internal worker abort or live
|
|
@@ -59,6 +61,10 @@ export class SubAgentRunManager {
|
|
|
59
61
|
this.internalProgressPacers = new Map();
|
|
60
62
|
this.queue = createSerialQueue();
|
|
61
63
|
}
|
|
64
|
+
/** The completion wake's dispatch id — the only id `beginWakeConsumption` accepts for it. */
|
|
65
|
+
wakeDispatchId(runId) {
|
|
66
|
+
return `subagent:${this.target.desk}:${runId}:done`;
|
|
67
|
+
}
|
|
62
68
|
/** Release observation timers without cancelling dispatched work or its settlement. */
|
|
63
69
|
stop() {
|
|
64
70
|
this.stopped = true;
|
|
@@ -68,10 +74,8 @@ export class SubAgentRunManager {
|
|
|
68
74
|
this.stopExternalProgressTail(runId);
|
|
69
75
|
}
|
|
70
76
|
recordDir() {
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
// restart silently abandoned every delegation run of every such channel.
|
|
74
|
-
return this.options.stateDir ? getChannelDir(this.options.stateDir, this.channelId) : undefined;
|
|
77
|
+
// The desk name is a validated path segment; a channel id never is (spec 058, INV-3).
|
|
78
|
+
return this.options.stateDir ? join(this.options.stateDir, this.target.desk) : undefined;
|
|
75
79
|
}
|
|
76
80
|
recordPath(runId) {
|
|
77
81
|
const dir = this.recordDir();
|
|
@@ -116,12 +120,12 @@ export class SubAgentRunManager {
|
|
|
116
120
|
}
|
|
117
121
|
}
|
|
118
122
|
/** Fire-and-forget: a notifier failure must never affect settlement or the progress tail. */
|
|
119
|
-
emitNotice(notice) {
|
|
123
|
+
emitNotice(record, notice) {
|
|
120
124
|
const notify = this.options.notify;
|
|
121
125
|
if (!notify)
|
|
122
126
|
return;
|
|
123
127
|
void Promise.resolve()
|
|
124
|
-
.then(() => notify(this.channelId, notice))
|
|
128
|
+
.then(() => notify(this.target.desk, record.channelId, notice))
|
|
125
129
|
.catch((error) => log.logWarn("subagent.notice.failed", "Run notice failed", {
|
|
126
130
|
reason: errorMessage(error),
|
|
127
131
|
fields: { runId: notice.runId },
|
|
@@ -140,7 +144,7 @@ export class SubAgentRunManager {
|
|
|
140
144
|
harnessId: record.harness,
|
|
141
145
|
startedAt: record.processStartedAt ?? record.startedAt,
|
|
142
146
|
onProgress: (step) => {
|
|
143
|
-
this.emitNotice({
|
|
147
|
+
this.emitNotice(record, {
|
|
144
148
|
kind: "progress",
|
|
145
149
|
runId: record.runId,
|
|
146
150
|
agent: record.agent,
|
|
@@ -149,7 +153,7 @@ export class SubAgentRunManager {
|
|
|
149
153
|
});
|
|
150
154
|
},
|
|
151
155
|
onStall: (silentMs) => {
|
|
152
|
-
this.emitNotice({
|
|
156
|
+
this.emitNotice(record, {
|
|
153
157
|
kind: "stalled",
|
|
154
158
|
runId: record.runId,
|
|
155
159
|
agent: record.agent,
|
|
@@ -173,7 +177,7 @@ export class SubAgentRunManager {
|
|
|
173
177
|
return;
|
|
174
178
|
let pacer = this.internalProgressPacers.get(runId);
|
|
175
179
|
if (!pacer) {
|
|
176
|
-
pacer = createProgressPacer(record.startedAt, (label) => this.emitNotice({
|
|
180
|
+
pacer = createProgressPacer(record.startedAt, (label) => this.emitNotice(record, {
|
|
177
181
|
kind: "progress",
|
|
178
182
|
runId,
|
|
179
183
|
agent: record.agent,
|
|
@@ -215,16 +219,6 @@ export class SubAgentRunManager {
|
|
|
215
219
|
list() {
|
|
216
220
|
return Array.from(this.runs.values());
|
|
217
221
|
}
|
|
218
|
-
/** Task ids a still-running delegation on this channel will eventually wake. Feeds `/tasks doctor`. */
|
|
219
|
-
runningTaskIds() {
|
|
220
|
-
const ids = new Set();
|
|
221
|
-
for (const record of this.runs.values()) {
|
|
222
|
-
if (record.status === "running" && record.taskId) {
|
|
223
|
-
ids.add(record.taskId);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return ids;
|
|
227
|
-
}
|
|
228
222
|
runningCount() {
|
|
229
223
|
return Array.from(this.runs.values()).filter((record) => record.status === "running").length;
|
|
230
224
|
}
|
|
@@ -259,11 +253,11 @@ export class SubAgentRunManager {
|
|
|
259
253
|
/** Register the run's lifecycle before any work starts, and persist it immediately (D1). */
|
|
260
254
|
async register(input) {
|
|
261
255
|
return hostAdmissionQueue.run("host", () => this.queue.run(input.runId, async () => {
|
|
262
|
-
// D10.2: a per-
|
|
256
|
+
// D10.2: a per-desk and a host-wide cap, both code constants (a local response to a
|
|
263
257
|
// runaway model, not a global cross-subsystem admission scheme — see the design doc's
|
|
264
258
|
// non-goals). Checked before anything is persisted, so a rejected run costs nothing.
|
|
265
|
-
if (this.runningCount() >=
|
|
266
|
-
throw new RecoverableToolError(`Too many delegation runs already running
|
|
259
|
+
if (this.runningCount() >= MAX_RUNNING_SUBAGENT_RUNS_PER_DESK) {
|
|
260
|
+
throw new RecoverableToolError(`Too many delegation runs already running in this desk (>= ${MAX_RUNNING_SUBAGENT_RUNS_PER_DESK}). ` +
|
|
267
261
|
"Wait for one to finish, or cancel one with subagent_run op=cancel first.");
|
|
268
262
|
}
|
|
269
263
|
if ((this.options.runningCount?.() ?? this.runningCount()) >= MAX_RUNNING_SUBAGENT_RUNS_PER_HOST) {
|
|
@@ -271,7 +265,7 @@ export class SubAgentRunManager {
|
|
|
271
265
|
"Wait for one to finish before dispatching another.");
|
|
272
266
|
}
|
|
273
267
|
if (this.runs.has(input.runId)) {
|
|
274
|
-
throw new RecoverableToolError(`Run id "${input.runId}" is already registered
|
|
268
|
+
throw new RecoverableToolError(`Run id "${input.runId}" is already registered in this desk.`);
|
|
275
269
|
}
|
|
276
270
|
const record = {
|
|
277
271
|
...input,
|
|
@@ -292,8 +286,8 @@ export class SubAgentRunManager {
|
|
|
292
286
|
this.externalLaunches.delete(record.runId);
|
|
293
287
|
throw error;
|
|
294
288
|
}
|
|
295
|
-
if (record.taskId
|
|
296
|
-
await logTaskDispatch(
|
|
289
|
+
if (record.taskId) {
|
|
290
|
+
await logTaskDispatch(this.target.deskDir, record.taskId, {
|
|
297
291
|
ref: record.runId,
|
|
298
292
|
item: record.item,
|
|
299
293
|
agent: record.agent,
|
|
@@ -346,7 +340,7 @@ export class SubAgentRunManager {
|
|
|
346
340
|
record.sessionId = info.sessionId;
|
|
347
341
|
record.maxWallTimeSec = info.maxWallTimeSec;
|
|
348
342
|
record.processStartedAt = info.processStartedAt;
|
|
349
|
-
record.
|
|
343
|
+
record.deskDir = info.deskDir;
|
|
350
344
|
record.invocationWarnings = info.invocationWarnings;
|
|
351
345
|
record.roleFingerprint = info.roleFingerprint;
|
|
352
346
|
record.parserVersion = info.parserVersion;
|
|
@@ -378,7 +372,7 @@ export class SubAgentRunManager {
|
|
|
378
372
|
const record = this.runs.get(runId);
|
|
379
373
|
if (!record)
|
|
380
374
|
return false;
|
|
381
|
-
const expected =
|
|
375
|
+
const expected = this.wakeDispatchId(runId);
|
|
382
376
|
const eligible = record.settledAt !== undefined && record.taskId === taskId && dispatchId === expected;
|
|
383
377
|
const previousClaim = record.wakeClaimDispatchId;
|
|
384
378
|
if (!beginWakeClaim(record, eligible, dispatchId))
|
|
@@ -475,50 +469,11 @@ export class SubAgentRunManager {
|
|
|
475
469
|
this.internalProgressPacers.delete(runId);
|
|
476
470
|
if (!record.usageRecorded) {
|
|
477
471
|
record.usageRecorded = true;
|
|
478
|
-
this.options.ledger?.record(
|
|
479
|
-
channelId: record.channelId,
|
|
480
|
-
kind: "subagent",
|
|
481
|
-
model: record.model ?? "unknown",
|
|
482
|
-
label: record.label,
|
|
483
|
-
runId: record.runId,
|
|
484
|
-
taskId: record.taskId,
|
|
485
|
-
usage: {
|
|
486
|
-
input: input.usage.input,
|
|
487
|
-
output: input.usage.output,
|
|
488
|
-
cacheRead: input.usage.cacheRead,
|
|
489
|
-
cacheWrite: input.usage.cacheWrite,
|
|
490
|
-
total: input.usage.total,
|
|
491
|
-
},
|
|
492
|
-
cost: { ...input.usage.cost },
|
|
493
|
-
usageKnown: input.usageKnown,
|
|
494
|
-
costKnown: input.costKnown,
|
|
495
|
-
});
|
|
472
|
+
this.options.ledger?.record(runLedgerEntry(this.target.desk, record, input));
|
|
496
473
|
// Archive is an observability write, not a settlement fact — a full queue must not
|
|
497
474
|
// swallow the completion wake below (P0-2).
|
|
498
475
|
await this.options.store
|
|
499
|
-
?.logSubAgentRun(
|
|
500
|
-
date: new Date().toISOString(),
|
|
501
|
-
toolCallId: record.runId,
|
|
502
|
-
label: record.label,
|
|
503
|
-
agent: record.agent,
|
|
504
|
-
source: record.source,
|
|
505
|
-
model: record.model ?? "unknown",
|
|
506
|
-
tools: record.tools,
|
|
507
|
-
turns: input.turns,
|
|
508
|
-
toolCalls: input.toolCalls,
|
|
509
|
-
durationMs: input.durationMs,
|
|
510
|
-
failed: input.status !== "completed",
|
|
511
|
-
failureReason: input.failureReason,
|
|
512
|
-
output: input.outputText.length > 16_000 ? input.outputText.slice(0, 16_000) : input.outputText,
|
|
513
|
-
outputTruncated: input.outputText.length > 16_000,
|
|
514
|
-
usage: { ...input.usage, cost: { ...input.usage.cost } },
|
|
515
|
-
runId: record.runId,
|
|
516
|
-
runtime: record.runtime,
|
|
517
|
-
harness: record.harness,
|
|
518
|
-
status: pending.status,
|
|
519
|
-
taskId: record.taskId,
|
|
520
|
-
artifactDir: record.artifactDir,
|
|
521
|
-
})
|
|
476
|
+
?.logSubAgentRun(this.target.deskDir, runArchiveEntry(record, input, pending.status))
|
|
522
477
|
.catch((error) => {
|
|
523
478
|
log.logWarn("subagent.archive.failed", "Run archive failed", {
|
|
524
479
|
reason: errorMessage(error),
|
|
@@ -531,7 +486,7 @@ export class SubAgentRunManager {
|
|
|
531
486
|
// budget and the outcome onto its log (the board's source), whether or not the run record
|
|
532
487
|
// is still around by the time the leader looks. Guarded by its own idempotency marker
|
|
533
488
|
// inside the same settlement lock, so a replay writes nothing twice.
|
|
534
|
-
if (!record.taskAccounted && record.taskId
|
|
489
|
+
if (!record.taskAccounted && record.taskId) {
|
|
535
490
|
record.taskAccounted = true;
|
|
536
491
|
await this.creditOwningTask(record, input, outputSaved).catch((error) => {
|
|
537
492
|
log.logWarn("subagent.task_settle.log_failed", "Task credit for run failed", {
|
|
@@ -557,11 +512,10 @@ export class SubAgentRunManager {
|
|
|
557
512
|
* block the completion wake.
|
|
558
513
|
*/
|
|
559
514
|
async creditOwningTask(record, input, outputSaved) {
|
|
560
|
-
const channelDir = record.channelDir;
|
|
561
515
|
const taskId = record.taskId;
|
|
562
|
-
if (!
|
|
516
|
+
if (!taskId)
|
|
563
517
|
return;
|
|
564
|
-
await logTaskSettlement(
|
|
518
|
+
await logTaskSettlement(this.target.deskDir, taskId, {
|
|
565
519
|
ref: record.runId,
|
|
566
520
|
item: record.item,
|
|
567
521
|
status: record.status,
|
|
@@ -583,7 +537,7 @@ export class SubAgentRunManager {
|
|
|
583
537
|
// caller was not already holding the result in the same tool call (`announce: true`, the same
|
|
584
538
|
// condition that gates the wake below). It reaches the channel in roughly the time the run
|
|
585
539
|
// itself took to settle, independent of the wake turn's own LLM latency on top of that.
|
|
586
|
-
this.emitNotice({
|
|
540
|
+
this.emitNotice(record, {
|
|
587
541
|
kind: "settled",
|
|
588
542
|
runId: record.runId,
|
|
589
543
|
agent: record.agent,
|
|
@@ -592,8 +546,19 @@ export class SubAgentRunManager {
|
|
|
592
546
|
});
|
|
593
547
|
if (!this.options.dispatch)
|
|
594
548
|
return;
|
|
595
|
-
|
|
596
|
-
|
|
549
|
+
if (this.options.isBoundTo && !this.options.isBoundTo(record.channelId, this.target.desk)) {
|
|
550
|
+
await this.suppressWake(record);
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
const siblingCount = countWakeSiblings(record, this.runs.values());
|
|
554
|
+
const event = buildRunCompletionWake({
|
|
555
|
+
desk: this.target.desk,
|
|
556
|
+
dispatchId: this.wakeDispatchId(record.runId),
|
|
557
|
+
record,
|
|
558
|
+
outputText,
|
|
559
|
+
outputSaved,
|
|
560
|
+
siblingCount,
|
|
561
|
+
});
|
|
597
562
|
// The `boolean` return value (queue-full/backpressure -> `false`) is deliberately not
|
|
598
563
|
// checked here, unlike the thrown-error case above: `DurableDispatchService.enqueueEvent`
|
|
599
564
|
// puts a rejected record back into `pending` rather than dropping it, and the 30s periodic
|
|
@@ -613,6 +578,28 @@ export class SubAgentRunManager {
|
|
|
613
578
|
record.wakeEnqueued = true;
|
|
614
579
|
await this.persist(record);
|
|
615
580
|
}
|
|
581
|
+
/**
|
|
582
|
+
* Spec 058, D8: the run's channel left this desk, so the wake has no recipient. Settlement and the
|
|
583
|
+
* task's settle record already happened; the wake is dropped (marker set, never replayed), and the
|
|
584
|
+
* `work` ticket it would have redeemed is redeemed here via `redeemTicket`, so the suspended task
|
|
585
|
+
* resumes as soon as its delivery channel is bound again.
|
|
586
|
+
*/
|
|
587
|
+
async suppressWake(record) {
|
|
588
|
+
log.logInfoEvent("subagent.wake.suppressed", "Completion wake dropped: channel not bound to the run's desk", {
|
|
589
|
+
channelId: record.channelId,
|
|
590
|
+
fields: { runId: record.runId, desk: this.target.desk, taskId: record.taskId },
|
|
591
|
+
});
|
|
592
|
+
if (record.taskId) {
|
|
593
|
+
await redeemTicket(this.target.deskDir, record.taskId, (ticket) => ticket.kind === "work").catch((error) => {
|
|
594
|
+
log.logWarn("subagent.wake.redeem_failed", "Work ticket redeem for a dropped wake failed", {
|
|
595
|
+
reason: errorMessage(error),
|
|
596
|
+
fields: { runId: record.runId, taskId: record.taskId },
|
|
597
|
+
});
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
record.wakeEnqueued = true;
|
|
601
|
+
await this.persist(record);
|
|
602
|
+
}
|
|
616
603
|
/** Explicit cancel (`subagent_run op=cancel`, spec 040 D6). Does not wake — it is the model's own decision. */
|
|
617
604
|
async cancel(runId) {
|
|
618
605
|
let adoptedRecord;
|
|
@@ -1017,6 +1004,12 @@ export class SubAgentRunManager {
|
|
|
1017
1004
|
const current = this.runs.get(record.runId);
|
|
1018
1005
|
if (!current || current.status !== "running")
|
|
1019
1006
|
return;
|
|
1007
|
+
// Timers can fire just before their wall-clock deadline. Re-arm rather than losing
|
|
1008
|
+
// the only recovery check and leaving an adopted process running indefinitely.
|
|
1009
|
+
if (current.deadlineAt && Date.now() < current.deadlineAt) {
|
|
1010
|
+
this.scheduleExternalRecovery(current);
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1020
1013
|
void this.reconcileExternalRunAtDeadline(current).catch((error) => {
|
|
1021
1014
|
log.logWarn("subagent.reconcile.failed", "Adopted external run reconcile failed", {
|
|
1022
1015
|
reason: errorMessage(error),
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { readFile } from "node:fs/promises";
|
|
7
7
|
import { join } from "node:path";
|
|
8
|
-
import { getChannelDir } from "../channel/channel-paths.js";
|
|
9
8
|
import * as log from "../log.js";
|
|
10
|
-
import {
|
|
9
|
+
import { buildMemoryIndexForBootstrap, clipJournalTailForBootstrap, clipWorkspaceMemoryForBootstrap, JOURNAL_TAIL_MAX_UNITS, MEMORY_INDEX_MAX_UNITS, WORKSPACE_MEMORY_MAX_UNITS, } from "../memory/index-budget.js";
|
|
11
10
|
import { readJournalDay } from "../memory/journal.js";
|
|
12
11
|
import { renderMemoryBootstrap } from "../memory/render.js";
|
|
13
12
|
import { listMemoryEntries } from "../memory/store.js";
|
|
@@ -77,8 +76,9 @@ export function buildSubAgentTask(task, config, runtimeContext, contextBlocks, r
|
|
|
77
76
|
const lines = [
|
|
78
77
|
`Runtime context:`,
|
|
79
78
|
`- Workspace root: ${runtimeContext.workspaceDir}`,
|
|
79
|
+
`- Desk: ${runtimeContext.desk}`,
|
|
80
|
+
`- Desk directory: ${runtimeContext.deskDir}`,
|
|
80
81
|
`- Channel id: ${runtimeContext.channelId}`,
|
|
81
|
-
`- Channel directory: ${getChannelDir(runtimeContext.workspaceDir, runtimeContext.channelId)}`,
|
|
82
82
|
`- Working directory: ${runContext.workingDirectory}`,
|
|
83
83
|
`- Artifact directory: ${runContext.artifactDir}`,
|
|
84
84
|
`- Your configured role: ${config.name}`,
|
|
@@ -96,9 +96,7 @@ export function buildSubAgentTask(task, config, runtimeContext, contextBlocks, r
|
|
|
96
96
|
return lines.join("\n");
|
|
97
97
|
}
|
|
98
98
|
function verificationTaskPath(runtimeContext, runContext) {
|
|
99
|
-
return runContext.taskId
|
|
100
|
-
? join(getChannelDir(runtimeContext.workspaceDir, runtimeContext.channelId), "tasks", `${runContext.taskId}.md`)
|
|
101
|
-
: undefined;
|
|
99
|
+
return runContext.taskId ? join(runtimeContext.deskDir, "tasks", `${runContext.taskId}.md`) : undefined;
|
|
102
100
|
}
|
|
103
101
|
/**
|
|
104
102
|
* The envelope for `subagent_run op=follow_up`. A resumed session already holds the first
|
|
@@ -123,7 +121,7 @@ export function buildFollowUpTask(task, runtimeContext, runContext) {
|
|
|
123
121
|
}
|
|
124
122
|
/**
|
|
125
123
|
* Spec 050, D12: `memory: index` injects the same three sections the main agent's first-turn
|
|
126
|
-
* bootstrap does — workspace MEMORY.md, the
|
|
124
|
+
* bootstrap does — workspace MEMORY.md, the desk memory index, today's journal tail — at half the
|
|
127
125
|
* main agent's budget. No per-call LLM recall: a sub-agent task is short-lived, so there is no
|
|
128
126
|
* "first turn" to bootstrap once and reuse; it gets the same snapshot every dispatch.
|
|
129
127
|
*/
|
|
@@ -148,14 +146,14 @@ async function buildContextualBlocks(config, options) {
|
|
|
148
146
|
}
|
|
149
147
|
};
|
|
150
148
|
const [entries, workspaceMemory, journalToday] = await Promise.all([
|
|
151
|
-
listMemoryEntries(options.
|
|
149
|
+
listMemoryEntries(options.deskDir).catch(() => []),
|
|
152
150
|
readOptionalFile(join(options.workspaceDir, "MEMORY.md")),
|
|
153
|
-
readJournalDay(options.
|
|
151
|
+
readJournalDay(options.deskDir, today).catch(() => ""),
|
|
154
152
|
]);
|
|
155
|
-
const index =
|
|
153
|
+
const index = buildMemoryIndexForBootstrap(entries, MEMORY_INDEX_MAX_UNITS / 2);
|
|
156
154
|
const bootstrap = renderMemoryBootstrap({
|
|
157
155
|
workspaceMemory: clipWorkspaceMemoryForBootstrap(workspaceMemory, WORKSPACE_MEMORY_MAX_UNITS / 2),
|
|
158
|
-
|
|
156
|
+
memoryIndex: entries.length > 0 ? index.text : "",
|
|
159
157
|
journal: (() => {
|
|
160
158
|
const text = clipJournalTailForBootstrap(journalToday, JOURNAL_TAIL_MAX_UNITS / 2);
|
|
161
159
|
return text ? { date: today, text } : undefined;
|
|
@@ -86,7 +86,7 @@ export interface WorkerToolRequest {
|
|
|
86
86
|
securityConfig: SecurityConfig;
|
|
87
87
|
securityContext: SecurityRuntimeContext;
|
|
88
88
|
channelId: string;
|
|
89
|
-
|
|
89
|
+
deskDir: string;
|
|
90
90
|
workspaceDir: string;
|
|
91
91
|
webConfig?: PipiclawWebToolsConfig;
|
|
92
92
|
rtkEnabled?: boolean;
|
|
@@ -99,15 +99,13 @@ export interface SubAgentToolOptions {
|
|
|
99
99
|
buildWorkerTools: BuildWorkerTools;
|
|
100
100
|
executor: Executor;
|
|
101
101
|
fileStore: FileStore;
|
|
102
|
-
/**
|
|
102
|
+
/** Default working directory for a run: the parent's cwd. Defaults to process.cwd(). */
|
|
103
103
|
workingDirectory?: string;
|
|
104
|
-
/** Mirrors the parent channel's ProjectScope.boundary onto the sub-agent's own tool set (spec 043, D6.2). */
|
|
105
|
-
projectBoundary?: "project" | "unbounded";
|
|
106
104
|
getCurrentModel: () => Model<Api>;
|
|
107
105
|
getAvailableModels: () => Model<Api>[];
|
|
108
106
|
resolveApiKey: (model: Model<Api>) => Promise<string>;
|
|
109
107
|
workspaceDir: string;
|
|
110
|
-
|
|
108
|
+
deskDir: string;
|
|
111
109
|
getSubAgentDiscovery?: () => SubAgentDiscoveryResult;
|
|
112
110
|
/** `settings.subagentModel` (spec 032 D5); null/undefined means unset. */
|
|
113
111
|
getSubAgentModelReference?: () => string | null;
|
|
@@ -116,6 +114,9 @@ export interface SubAgentToolOptions {
|
|
|
116
114
|
rtkEnabled?: boolean;
|
|
117
115
|
runtimeContext: {
|
|
118
116
|
workspaceDir: string;
|
|
117
|
+
/** The desk the delegating turn belongs to, and its directory (tasks, memory). */
|
|
118
|
+
desk: string;
|
|
119
|
+
deskDir: string;
|
|
119
120
|
channelId: string;
|
|
120
121
|
};
|
|
121
122
|
createWorker?: (config: {
|
package/dist/tasks/board.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface TaskBoard {
|
|
|
31
31
|
}
|
|
32
32
|
/** Ref lines the board renders before folding old, already-seen results away. */
|
|
33
33
|
export declare const BOARD_REF_LINE_BUDGET = 12;
|
|
34
|
-
export declare function buildTaskBoard(
|
|
34
|
+
export declare function buildTaskBoard(deskDir: string, taskId: string, body: string): Promise<TaskBoard | undefined>;
|
|
35
35
|
/** Render the `<task_board>` block body (model-facing; `/tasks show` uses `renderTaskBoardForUser`). */
|
|
36
36
|
export declare function renderTaskBoard(board: TaskBoard, nowMs?: number): string;
|
|
37
37
|
/**
|
package/dist/tasks/board.js
CHANGED
|
@@ -5,8 +5,8 @@ import { parseTaskItems } from "./contract.js";
|
|
|
5
5
|
import { describeSettlement, describeWorkRef, readTaskLog, } from "./loop-log.js";
|
|
6
6
|
/** Ref lines the board renders before folding old, already-seen results away. */
|
|
7
7
|
export const BOARD_REF_LINE_BUDGET = 12;
|
|
8
|
-
export async function buildTaskBoard(
|
|
9
|
-
const records = await readTaskLog(
|
|
8
|
+
export async function buildTaskBoard(deskDir, taskId, body) {
|
|
9
|
+
const records = await readTaskLog(deskDir, taskId, { kinds: ["dispatch", "settle", "step"] });
|
|
10
10
|
const dispatches = new Map();
|
|
11
11
|
const settles = new Map();
|
|
12
12
|
let lastStepIndex = -1;
|
|
@@ -8,7 +8,7 @@ import { type TaskDispatchRecord, type TaskSettleRecord } from "./loop-log.js";
|
|
|
8
8
|
* replayed settlement writes nothing twice.
|
|
9
9
|
*/
|
|
10
10
|
/** Record that a delegation or job was bound to the task. A task that no longer exists is skipped. */
|
|
11
|
-
export declare function logTaskDispatch(
|
|
11
|
+
export declare function logTaskDispatch(deskDir: string, taskId: string, record: Omit<TaskDispatchRecord, "ts" | "kind">): Promise<void>;
|
|
12
12
|
export interface TaskSettlementCost {
|
|
13
13
|
usd: number;
|
|
14
14
|
estimated: boolean;
|
|
@@ -17,4 +17,4 @@ export interface TaskSettlementCost {
|
|
|
17
17
|
* Record that bound work settled and add its cost to the task's usage. The cost lands in the
|
|
18
18
|
* same budget the leader's own steps spend from, so a runaway fan-out stops the task.
|
|
19
19
|
*/
|
|
20
|
-
export declare function logTaskSettlement(
|
|
20
|
+
export declare function logTaskSettlement(deskDir: string, taskId: string, record: Omit<TaskSettleRecord, "ts" | "kind" | "usd" | "usdEstimated">, cost?: TaskSettlementCost): Promise<void>;
|
package/dist/tasks/bound-work.js
CHANGED
|
@@ -9,18 +9,18 @@ import { readStoredTask, updateStoredTask } from "./store.js";
|
|
|
9
9
|
* replayed settlement writes nothing twice.
|
|
10
10
|
*/
|
|
11
11
|
/** Record that a delegation or job was bound to the task. A task that no longer exists is skipped. */
|
|
12
|
-
export async function logTaskDispatch(
|
|
13
|
-
if (!(await readStoredTask(
|
|
12
|
+
export async function logTaskDispatch(deskDir, taskId, record) {
|
|
13
|
+
if (!(await readStoredTask(deskDir, taskId)))
|
|
14
14
|
return;
|
|
15
|
-
await appendTaskLog(
|
|
15
|
+
await appendTaskLog(deskDir, taskId, { kind: "dispatch", ...record });
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Record that bound work settled and add its cost to the task's usage. The cost lands in the
|
|
19
19
|
* same budget the leader's own steps spend from, so a runaway fan-out stops the task.
|
|
20
20
|
*/
|
|
21
|
-
export async function logTaskSettlement(
|
|
21
|
+
export async function logTaskSettlement(deskDir, taskId, record, cost = { usd: 0, estimated: false }) {
|
|
22
22
|
if (cost.usd > 0 || cost.estimated) {
|
|
23
|
-
await updateStoredTask(
|
|
23
|
+
await updateStoredTask(deskDir, taskId, (task) => {
|
|
24
24
|
const usage = task.fields.usage;
|
|
25
25
|
if (!usage)
|
|
26
26
|
return;
|
|
@@ -31,9 +31,9 @@ export async function logTaskSettlement(channelDir, taskId, record, cost = { usd
|
|
|
31
31
|
};
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
-
if (!(await readStoredTask(
|
|
34
|
+
if (!(await readStoredTask(deskDir, taskId)))
|
|
35
35
|
return;
|
|
36
|
-
await appendTaskLog(
|
|
36
|
+
await appendTaskLog(deskDir, taskId, {
|
|
37
37
|
kind: "settle",
|
|
38
38
|
...record,
|
|
39
39
|
...(cost.usd > 0 ? { usd: cost.usd } : {}),
|
package/dist/tasks/brief.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare const BRIEF_LOG_LINES = 8;
|
|
|
3
3
|
/** Cap on each part (close note, last report) of the previous occurrence carried into a spawned instance's first step. */
|
|
4
4
|
export declare const PREVIOUS_OCCURRENCE_MAX_CHARS = 1200;
|
|
5
5
|
export interface TaskBriefInput {
|
|
6
|
-
|
|
6
|
+
deskDir: string;
|
|
7
7
|
taskId: string;
|
|
8
8
|
/** Why this step is running, when the caller knows. */
|
|
9
9
|
reason?: string;
|
package/dist/tasks/brief.js
CHANGED
|
@@ -19,8 +19,8 @@ export const PREVIOUS_OCCURRENCE_MAX_CHARS = 1_200;
|
|
|
19
19
|
* no scan of every archived contract. A candidate is accepted only if its own `origin` says so,
|
|
20
20
|
* since one event name can be a prefix of another's.
|
|
21
21
|
*/
|
|
22
|
-
async function findPreviousOccurrence(
|
|
23
|
-
const archiveDir = join(tasksDir(
|
|
22
|
+
async function findPreviousOccurrence(deskDir, origin, currentId) {
|
|
23
|
+
const archiveDir = join(tasksDir(deskDir), "archive");
|
|
24
24
|
if (!existsSync(archiveDir))
|
|
25
25
|
return undefined;
|
|
26
26
|
const candidates = (await readdir(archiveDir))
|
|
@@ -30,10 +30,10 @@ async function findPreviousOccurrence(channelDir, origin, currentId) {
|
|
|
30
30
|
.sort()
|
|
31
31
|
.reverse();
|
|
32
32
|
for (const id of candidates) {
|
|
33
|
-
const document = await readStoredTask(
|
|
33
|
+
const document = await readStoredTask(deskDir, id, true).catch(() => undefined);
|
|
34
34
|
if (!document || document.fields.origin !== origin)
|
|
35
35
|
continue;
|
|
36
|
-
const latestFirst = (await readTaskLog(
|
|
36
|
+
const latestFirst = (await readTaskLog(deskDir, id, { kinds: ["close", "step"] })).reverse();
|
|
37
37
|
const close = latestFirst.find((record) => record.kind === "close");
|
|
38
38
|
const reported = latestFirst.find((record) => record.kind === "step" && record.report);
|
|
39
39
|
return {
|
|
@@ -58,13 +58,13 @@ async function findPreviousOccurrence(channelDir, origin, currentId) {
|
|
|
58
58
|
* the brief that is genuinely new since the previous step.
|
|
59
59
|
*/
|
|
60
60
|
export async function buildTaskStepBrief(input) {
|
|
61
|
-
const document = await readStoredTask(input.
|
|
61
|
+
const document = await readStoredTask(input.deskDir, input.taskId);
|
|
62
62
|
if (!document)
|
|
63
63
|
return undefined;
|
|
64
|
-
const steer = await consumeTaskSteer(input.
|
|
65
|
-
const log = await readTaskLog(input.
|
|
64
|
+
const steer = await consumeTaskSteer(input.deskDir, input.taskId);
|
|
65
|
+
const log = await readTaskLog(input.deskDir, input.taskId, { kinds: ["step", "expired", "close"] });
|
|
66
66
|
const recent = log.slice(-BRIEF_LOG_LINES);
|
|
67
|
-
const board = await buildTaskBoard(input.
|
|
67
|
+
const board = await buildTaskBoard(input.deskDir, input.taskId, document.body);
|
|
68
68
|
const blocks = [`[TASK_STEP:${input.taskId}]`];
|
|
69
69
|
if (input.reason)
|
|
70
70
|
blocks.push(input.reason);
|
|
@@ -78,7 +78,7 @@ export async function buildTaskStepBrief(input) {
|
|
|
78
78
|
blocks.push(`<user_guidance>\n${steer}\n</user_guidance>`);
|
|
79
79
|
const isFirstStep = !log.some((record) => record.kind === "step");
|
|
80
80
|
if (isFirstStep && document.fields.origin) {
|
|
81
|
-
const previous = await findPreviousOccurrence(input.
|
|
81
|
+
const previous = await findPreviousOccurrence(input.deskDir, document.fields.origin, input.taskId);
|
|
82
82
|
if (previous) {
|
|
83
83
|
const parts = [`收尾记录:${clipText(previous.note, PREVIOUS_OCCURRENCE_MAX_CHARS)}`];
|
|
84
84
|
if (previous.report)
|
package/dist/tasks/commands.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { type TaskBudget } from "./frontmatter.js";
|
|
2
|
+
/** What `/tasks` needs to say about a delivery channel (structurally `channel/channel-id.ts`'s `ChannelDescription`). */
|
|
3
|
+
interface TaskChannelDescription {
|
|
4
|
+
label: string;
|
|
5
|
+
/** Still bound to this desk; false means the task is suspended (spec 058, D8). */
|
|
6
|
+
boundHere: boolean;
|
|
7
|
+
}
|
|
2
8
|
export interface HandleTasksCommandOptions {
|
|
3
9
|
args: string;
|
|
4
|
-
/** The
|
|
5
|
-
|
|
10
|
+
/** The desk directory; tasks live in `<deskDir>/tasks/`. */
|
|
11
|
+
deskDir: string;
|
|
12
|
+
/** The channel the command was typed in: a task delivering elsewhere names its channel. */
|
|
13
|
+
currentChannelId: string;
|
|
14
|
+
describeChannel: (channelId: string) => TaskChannelDescription;
|
|
6
15
|
/** Optional immediate task wake, available in the long-lived DingTalk runtime. */
|
|
7
16
|
dispatchTask?: (id: string) => Promise<boolean>;
|
|
8
17
|
}
|