@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
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Request-owned generations share the normal runner/tools, without creating channel state. */
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { DEFAULT_DESK } from "../desk/paths.js";
|
|
4
|
+
import { readDeskRecord } from "../desk/registry.js";
|
|
5
|
+
import * as log from "../log.js";
|
|
6
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
7
|
+
import { createEmptyUsageTotals } from "../usage/totals.js";
|
|
8
|
+
export function createRequestExecution(deps) {
|
|
9
|
+
const running = new Map();
|
|
10
|
+
let admitting = 0;
|
|
11
|
+
return {
|
|
12
|
+
async execute(message) {
|
|
13
|
+
if (deps.isShuttingDown())
|
|
14
|
+
return { kind: "rejected", reason: { code: "shutting_down" } };
|
|
15
|
+
if (running.size + admitting >= 32)
|
|
16
|
+
return { kind: "rejected", reason: { code: "request_capacity" } };
|
|
17
|
+
admitting++;
|
|
18
|
+
try {
|
|
19
|
+
const desk = message.desk ?? message.allowedDesks?.[0] ?? DEFAULT_DESK;
|
|
20
|
+
if (message.allowedDesks && !message.allowedDesks.includes(desk))
|
|
21
|
+
return { kind: "rejected", reason: { code: "desk_not_allowed", desk } };
|
|
22
|
+
const summary = await readDeskRecord(deps.workspaceDir, desk);
|
|
23
|
+
if (!summary.record)
|
|
24
|
+
throw new Error(`Desk ${desk} is unavailable; repair it before sending API requests.`);
|
|
25
|
+
if (deps.isShuttingDown())
|
|
26
|
+
return { kind: "rejected", reason: { code: "shutting_down" } };
|
|
27
|
+
const conversation = {
|
|
28
|
+
desk,
|
|
29
|
+
deskDir: summary.deskDir,
|
|
30
|
+
cwd: summary.record.cwd ?? summary.deskDir,
|
|
31
|
+
channelId: message.channelId,
|
|
32
|
+
conversation: "request",
|
|
33
|
+
conversationDir: join(summary.deskDir, ".requests"),
|
|
34
|
+
};
|
|
35
|
+
const runner = deps.createRunner(conversation);
|
|
36
|
+
running.set(message.channelId, runner);
|
|
37
|
+
deps.runners.set(message.channelId, runner);
|
|
38
|
+
runner.beginTurn(message.text);
|
|
39
|
+
const run = async () => {
|
|
40
|
+
let output;
|
|
41
|
+
try {
|
|
42
|
+
output = deps.transports.forChannel(message.channelId)?.openTurn(message, { quiet: false });
|
|
43
|
+
if (!output)
|
|
44
|
+
throw new Error("The request's transport is unavailable.");
|
|
45
|
+
await runner.run(message, output, deps.store);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
log.logWarn("runtime.request.failed", "Request execution failed", {
|
|
49
|
+
channelId: message.channelId,
|
|
50
|
+
reason: errorMessage(error),
|
|
51
|
+
});
|
|
52
|
+
await output?.finish({
|
|
53
|
+
kind: "failed",
|
|
54
|
+
usage: createEmptyUsageTotals(),
|
|
55
|
+
message: "请求执行失败,请稍后重试或让部署者检查服务日志。",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
runner.endTurn();
|
|
60
|
+
try {
|
|
61
|
+
await runner.dispose();
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
running.delete(message.channelId);
|
|
65
|
+
deps.runners.delete(message.channelId);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const task = run();
|
|
70
|
+
deps.activeTasks.add(task);
|
|
71
|
+
void task.finally(() => deps.activeTasks.delete(task)).catch(() => undefined);
|
|
72
|
+
return { kind: "started" };
|
|
73
|
+
}
|
|
74
|
+
finally {
|
|
75
|
+
admitting--;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
async cancel(channelId) {
|
|
79
|
+
const runner = running.get(channelId);
|
|
80
|
+
if (!runner)
|
|
81
|
+
return false;
|
|
82
|
+
runner.requestStop();
|
|
83
|
+
await runner.abort();
|
|
84
|
+
return true;
|
|
85
|
+
},
|
|
86
|
+
isIdle: () => admitting === 0 && running.size === 0,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Ordered daemon shutdown: stop the schedulers, stop admission
|
|
3
|
-
* them past a grace window), dispose idle runners,
|
|
2
|
+
* Ordered daemon shutdown: stop the schedulers, stop admission (the transports still deliver), wait
|
|
3
|
+
* for active turns (aborting them past a grace window), dispose idle runners, close the transports,
|
|
4
|
+
* then flush storage and logs. Idempotent: every
|
|
4
5
|
* call after the first returns the first call's promise.
|
|
5
6
|
*/
|
|
6
7
|
import type { AgentRunner } from "../agent/types.js";
|
|
@@ -16,7 +17,7 @@ export interface ShutdownDeps {
|
|
|
16
17
|
memoryMaintenanceScheduler: {
|
|
17
18
|
stop(): void;
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
+
deskRuntime: {
|
|
20
21
|
stop(): void;
|
|
21
22
|
flush?(): Promise<void>;
|
|
22
23
|
};
|
|
@@ -26,8 +27,13 @@ export interface ShutdownDeps {
|
|
|
26
27
|
jobs: {
|
|
27
28
|
stop(): void;
|
|
28
29
|
};
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
transports: {
|
|
31
|
+
stopAcceptingAll(): Promise<void>;
|
|
32
|
+
stopAll(): Promise<void>;
|
|
33
|
+
};
|
|
34
|
+
/** The inbound pipeline: stops taking work. */
|
|
35
|
+
ingress: {
|
|
36
|
+
stop(): void;
|
|
31
37
|
};
|
|
32
38
|
store: ChannelStore;
|
|
33
39
|
channelIndex: ChannelIndex;
|
|
@@ -35,5 +41,7 @@ export interface ShutdownDeps {
|
|
|
35
41
|
activeTasks: Set<Promise<void>>;
|
|
36
42
|
/** Flips the runtime's `isShuttingDown()` the moment shutdown begins. */
|
|
37
43
|
markShuttingDown: () => void;
|
|
44
|
+
/** Frees `state/daemon.lock`, last of all: until then no other runtime may open this app home. */
|
|
45
|
+
releaseDaemonLock: () => Promise<void>;
|
|
38
46
|
}
|
|
39
47
|
export declare function createShutdown(deps: ShutdownDeps): (reason?: NodeJS.Signals | "manual") => Promise<void>;
|
package/dist/runtime/shutdown.js
CHANGED
|
@@ -20,7 +20,7 @@ function waitForTasks(tasks, timeoutMs) {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
export function createShutdown(deps) {
|
|
23
|
-
const { taskDriver, memoryMaintenanceScheduler,
|
|
23
|
+
const { taskDriver, memoryMaintenanceScheduler, deskRuntime, runs, jobs, transports, ingress, store, channelIndex, channelRunners, activeTasks, } = deps;
|
|
24
24
|
let shutdownPromise = null;
|
|
25
25
|
return async (reason = "manual") => {
|
|
26
26
|
if (shutdownPromise) {
|
|
@@ -32,10 +32,13 @@ export function createShutdown(deps) {
|
|
|
32
32
|
taskDriver.stop();
|
|
33
33
|
deps.getDurableDispatch()?.stop();
|
|
34
34
|
memoryMaintenanceScheduler.stop();
|
|
35
|
-
|
|
35
|
+
deskRuntime.stop();
|
|
36
36
|
runs.stop();
|
|
37
37
|
jobs.stop();
|
|
38
|
-
|
|
38
|
+
// Admission closes first; the transports keep delivering, so a turn that finishes inside
|
|
39
|
+
// the grace window below still reaches its channel (its card, its Web API response).
|
|
40
|
+
await transports.stopAcceptingAll();
|
|
41
|
+
ingress.stop();
|
|
39
42
|
const runningTasks = Array.from(activeTasks);
|
|
40
43
|
if (runningTasks.length > 0) {
|
|
41
44
|
log.logInfoEvent("runtime.shutdown.waiting", "Waiting for active turns to finish", {
|
|
@@ -99,13 +102,15 @@ export function createShutdown(deps) {
|
|
|
99
102
|
}
|
|
100
103
|
}
|
|
101
104
|
channelRunners.clear();
|
|
105
|
+
// Only now do connections close: what is still unfinished ends as interrupted.
|
|
106
|
+
await transports.stopAll();
|
|
102
107
|
const storageFlushes = [
|
|
103
108
|
store.close(),
|
|
104
109
|
// Cancels the debounce timer and lands the last activity times.
|
|
105
110
|
channelIndex.close(),
|
|
106
111
|
getUsageLedger().flush?.() ?? Promise.resolve(),
|
|
107
112
|
flushSecurityLogs(),
|
|
108
|
-
...(
|
|
113
|
+
...(deskRuntime.flush ? [deskRuntime.flush()] : []),
|
|
109
114
|
];
|
|
110
115
|
const storageFlushed = await waitForTasks(storageFlushes, SHUTDOWN_LOG_FLUSH_WAIT_MS);
|
|
111
116
|
if (!storageFlushed) {
|
|
@@ -114,6 +119,7 @@ export function createShutdown(deps) {
|
|
|
114
119
|
});
|
|
115
120
|
}
|
|
116
121
|
await waitForTasks([log.flushLogging()], SHUTDOWN_LOG_FLUSH_WAIT_MS);
|
|
122
|
+
await deps.releaseDaemonLock();
|
|
117
123
|
})();
|
|
118
124
|
return shutdownPromise;
|
|
119
125
|
};
|
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { type DiscoverOptions } from "../channel/channel-index.js";
|
|
1
|
+
import type { WakeEvent } from "../channel/channel-event.js";
|
|
3
2
|
import { type PipiclawTaskDriverSettings } from "../config/settings.js";
|
|
4
3
|
import { type BudgetBreach } from "../tasks/budget.js";
|
|
5
4
|
import { type TaskLedgerEntry } from "../tasks/contract.js";
|
|
6
5
|
export interface TaskDriverOptions {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
/** The desks this driver scans — the active ones (spec 058, D6). A dormant desk's tasks are never touched. */
|
|
7
|
+
getActiveDesks: () => ReadonlyArray<{
|
|
8
|
+
desk: string;
|
|
9
|
+
deskDir: string;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Whether a delivery channel is bound to a desk right now. A task whose `channel` is missing or
|
|
13
|
+
* not bound to its own desk is suspended: frozen entirely, not merely undelivered (D8).
|
|
14
|
+
*/
|
|
15
|
+
isBoundTo: (channelId: string, desk: string) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the delivery channel's transport is switched on in this process. A task delivering to
|
|
18
|
+
* a transport that is off is suspended the same way (spec 061, INV-8): nothing could be said to
|
|
19
|
+
* its channel, so the task waits, untouched, until the transport is back.
|
|
20
|
+
*/
|
|
21
|
+
isReachable: (channelId: string) => boolean;
|
|
9
22
|
isChannelActive: (channelId: string) => boolean;
|
|
10
|
-
dispatch: (event:
|
|
23
|
+
dispatch: (event: WakeEvent) => boolean | Promise<boolean>;
|
|
11
24
|
/** Optional observability hook. It runs after every production dispatch attempt. */
|
|
12
|
-
onDispatch?: (event:
|
|
25
|
+
onDispatch?: (event: WakeEvent, accepted: boolean) => void;
|
|
13
26
|
/** Test-only override; production uses `TASK_DRIVER_SETTINGS`. */
|
|
14
27
|
settings?: PipiclawTaskDriverSettings;
|
|
15
28
|
/** Master autonomy switch (`tools.tasks.enabled`); re-read every tick. Defaults to on. */
|
|
@@ -17,27 +30,22 @@ export interface TaskDriverOptions {
|
|
|
17
30
|
/** Test-only override for the idle-sleep cap; production uses `settings.maxSleepMinutes`. */
|
|
18
31
|
intervalMs?: number;
|
|
19
32
|
/** Direct, non-LLM receipt for deterministic runtime stops. */
|
|
20
|
-
notify?: (event:
|
|
33
|
+
notify?: (event: WakeEvent) => boolean | Promise<boolean>;
|
|
21
34
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Channels this driver should scan. Live ids come first so a channel discovered on disk under
|
|
24
|
-
* its escaped directory name never displaces the real id the runner map already knows.
|
|
25
|
-
*/
|
|
26
|
-
export declare function discoverTaskChannels(workspaceDir: string, knownChannelIds?: Iterable<string>, options?: DiscoverOptions): Promise<string[]>;
|
|
27
35
|
/** The task a `[TASK_DRIVER:<id>]` dispatch text names, if it is one. */
|
|
28
36
|
export declare function parseDriverTaskId(text: string | undefined): string | undefined;
|
|
29
|
-
export declare function createTaskDriverEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number):
|
|
37
|
+
export declare function createTaskDriverEvent(desk: string, channelId: string, entry: TaskLedgerEntry, nowMs: number): WakeEvent;
|
|
30
38
|
/**
|
|
31
39
|
* The deterministic receipt a runtime stop produces (spec 051, D11). It is delivered directly,
|
|
32
40
|
* without opening a model turn: the user needs to know their task stopped, and spending an LLM
|
|
33
41
|
* call to phrase that is exactly the kind of cost this design removes. A budget stop also says
|
|
34
42
|
* how to resume with more of the dimension that ran out (spec 053, D6).
|
|
35
43
|
*/
|
|
36
|
-
export declare function taskStopReceipt(channelId: string, entry: TaskLedgerEntry, reason: string, nowMs: number, breach?: BudgetBreach):
|
|
44
|
+
export declare function taskStopReceipt(desk: string, channelId: string, entry: TaskLedgerEntry, reason: string, nowMs: number, breach?: BudgetBreach): WakeEvent;
|
|
37
45
|
/**
|
|
38
46
|
* Native, ticket-driven scheduler for the persistent task ledger (spec 051, D9; spec 052).
|
|
39
47
|
*
|
|
40
|
-
* Three jobs, in this order per
|
|
48
|
+
* Three jobs, in this order per desk: redeem due `time` tickets, apply the backstop to expired
|
|
41
49
|
* ones, and queue one step for a runnable task. `work` and `ask` tickets are never polled — their
|
|
42
50
|
* owners push them (a settling delegation or job, `/tasks reply`) — so the scan stays a cheap read
|
|
43
51
|
* of a handful of frontmatters. Recurring work is not the driver's business: an event spawns a
|
|
@@ -56,17 +64,18 @@ export declare class TaskDriver {
|
|
|
56
64
|
private nudgeTimer;
|
|
57
65
|
private loopActive;
|
|
58
66
|
private running;
|
|
59
|
-
private
|
|
67
|
+
private nextDeskIndex;
|
|
60
68
|
/** Absolute ms of the next moment worth waking for, recomputed each scan. */
|
|
61
69
|
private nextWakeMs;
|
|
62
70
|
/** Last dispatch time per task, so one in-flight step is not queued again on the next tick. */
|
|
63
71
|
private readonly lastDispatchMs;
|
|
64
72
|
/**
|
|
65
|
-
* Last task id dispatched per
|
|
66
|
-
*
|
|
67
|
-
* otherwise monopolise.
|
|
73
|
+
* Last task id dispatched per desk. Starting the search just after it gives every ready task in
|
|
74
|
+
* a desk the same round-robin fairness an actively-progressing task would otherwise monopolise.
|
|
68
75
|
*/
|
|
69
76
|
private readonly lastDispatchedTaskId;
|
|
77
|
+
/** Tasks currently suspended (D8), so the transition is logged once rather than every scan. */
|
|
78
|
+
private readonly suspended;
|
|
70
79
|
constructor(options: TaskDriverOptions);
|
|
71
80
|
private observeDispatch;
|
|
72
81
|
start(): void;
|
|
@@ -84,9 +93,9 @@ export declare class TaskDriver {
|
|
|
84
93
|
/** Stop one task and notify. Delivery failure is logged, never fatal: the durable stop already happened. */
|
|
85
94
|
private notifyStop;
|
|
86
95
|
/**
|
|
87
|
-
* Deterministic, zero-token maintenance for one
|
|
88
|
-
* backstops. Runs whether or not the channel is busy — only model
|
|
89
|
-
*
|
|
96
|
+
* Deterministic, zero-token maintenance for one desk's live tasks: redeem due tickets and apply
|
|
97
|
+
* expiry backstops. Runs whether or not the delivery channel is busy — only model dispatch is
|
|
98
|
+
* gated on an idle channel.
|
|
90
99
|
*/
|
|
91
100
|
private maintain;
|
|
92
101
|
/**
|
|
@@ -96,5 +105,12 @@ export declare class TaskDriver {
|
|
|
96
105
|
* comparison a `echo x` could defeat.
|
|
97
106
|
*/
|
|
98
107
|
private detectIdleLoop;
|
|
108
|
+
/**
|
|
109
|
+
* The tasks of one desk the driver may touch at all (spec 058, D8): those whose delivery channel
|
|
110
|
+
* is bound to this desk and reachable. Every other task — no `channel`, or a channel bound elsewhere or nowhere, or on a transport that is off
|
|
111
|
+
* — is frozen: no ticket redemption, no backstop, no budget or idle check, no step, no receipt.
|
|
112
|
+
* Freezing reads nothing back into the file, so a rebound task resumes from exactly where it was.
|
|
113
|
+
*/
|
|
114
|
+
private liveTasks;
|
|
99
115
|
runOnce(now?: Date): Promise<void>;
|
|
100
116
|
}
|