@oyasmi/pipiclaw 0.9.3 → 0.9.4-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/dist/agent/builtin-commands.d.ts +19 -0
- package/dist/agent/builtin-commands.js +80 -0
- package/dist/agent/channel-runner.d.ts +20 -208
- package/dist/agent/channel-runner.js +167 -1188
- package/dist/agent/maintenance-context.d.ts +1 -1
- package/dist/agent/maintenance-context.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +45 -64
- package/dist/agent/prompt/resources.d.ts +3 -0
- package/dist/agent/prompt/resources.js +11 -2
- package/dist/agent/runner-factory.d.ts +1 -43
- package/dist/agent/{command-extension.d.ts → session/command-extension.d.ts} +4 -0
- package/dist/agent/{command-extension.js → session/command-extension.js} +48 -35
- package/dist/agent/{type-guards.d.ts → session/event-guards.d.ts} +2 -2
- package/dist/agent/{type-guards.js → session/event-guards.js} +5 -1
- package/dist/agent/session/model-selection.d.ts +47 -0
- package/dist/agent/session/model-selection.js +99 -0
- package/dist/agent/{session-adapter.d.ts → session/session-adapter.d.ts} +21 -1
- package/dist/agent/session/session-adapter.js +159 -0
- package/dist/agent/{session-events.d.ts → session/session-events.d.ts} +9 -5
- package/dist/agent/{session-events.js → session/session-events.js} +24 -13
- package/dist/agent/session/session-host.d.ts +200 -0
- package/dist/agent/session/session-host.js +621 -0
- package/dist/agent/{session-resource-gate.js → session/session-resource-gate.js} +5 -3
- package/dist/agent/status-render.d.ts +0 -1
- package/dist/agent/status-render.js +4 -16
- package/dist/agent/{context-budget.js → turn/context-budget.js} +5 -1
- package/dist/agent/{progress-formatter.d.ts → turn/progress-formatter.d.ts} +4 -1
- package/dist/agent/{run-queue.d.ts → turn/run-queue.d.ts} +1 -1
- package/dist/agent/{run-queue.js → turn/run-queue.js} +10 -5
- package/dist/{memory → agent/turn}/task-digest.js +4 -4
- package/dist/agent/turn/turn-context.d.ts +14 -0
- package/dist/agent/turn/turn-context.js +64 -0
- package/dist/agent/turn/turn-error.d.ts +31 -0
- package/dist/agent/turn/turn-error.js +68 -0
- package/dist/agent/turn/turn-finish.d.ts +50 -0
- package/dist/agent/turn/turn-finish.js +188 -0
- package/dist/agent/turn/turn-input.d.ts +43 -0
- package/dist/agent/turn/turn-input.js +79 -0
- package/dist/agent/turn/turn-pipeline.d.ts +68 -0
- package/dist/agent/turn/turn-pipeline.js +257 -0
- package/dist/agent/{turn-prompt.d.ts → turn/turn-prompt.d.ts} +2 -2
- package/dist/agent/{turn-prompt.js → turn/turn-prompt.js} +6 -2
- package/dist/agent/{turn-recovery.js → turn/turn-recovery.js} +1 -1
- package/dist/agent/{turn-state.d.ts → turn/turn-state.d.ts} +1 -1
- package/dist/agent/types.d.ts +43 -2
- package/dist/agent/types.js +1 -1
- package/dist/{models/auth-cli.d.ts → app/auth-command.d.ts} +1 -1
- package/dist/{models/auth-cli.js → app/auth-command.js} +14 -10
- package/dist/{runtime/app-home.d.ts → app/home.d.ts} +6 -2
- package/dist/{runtime/app-home.js → app/home.js} +22 -75
- package/dist/{runtime → app}/proxy.js +4 -2
- package/dist/{app-services.d.ts → app/services.d.ts} +5 -5
- package/dist/{app-services.js → app/services.js} +17 -14
- package/dist/channel/channel-context.d.ts +12 -2
- package/dist/channel/channel-context.js +29 -2
- package/dist/channel/channel-event.d.ts +10 -2
- package/dist/channel/channel-event.js +1 -1
- package/dist/channel/channel-index.js +4 -1
- package/dist/{runtime/project-commands.d.ts → channel/commands.d.ts} +1 -1
- package/dist/{runtime/project-commands.js → channel/commands.js} +17 -16
- package/dist/channel/project-scope-store.js +1 -1
- package/dist/channel/store.js +4 -0
- package/dist/commands/catalog.d.ts +24 -7
- package/dist/commands/catalog.js +91 -44
- package/dist/commands/reply-limits.d.ts +6 -0
- package/dist/commands/reply-limits.js +24 -0
- package/dist/{runtime/report-commands.d.ts → commands/router.d.ts} +10 -3
- package/dist/{runtime/report-commands.js → commands/router.js} +6 -6
- package/dist/{settings.d.ts → config/settings.d.ts} +10 -10
- package/dist/{settings.js → config/settings.js} +11 -11
- package/dist/{tools/config.d.ts → config/tools.d.ts} +1 -2
- package/dist/{tools/config.js → config/tools.js} +5 -2
- package/dist/dingtalk/access-token.d.ts +12 -0
- package/dist/dingtalk/access-token.js +51 -0
- package/dist/dingtalk/api.d.ts +19 -0
- package/dist/dingtalk/api.js +67 -0
- package/dist/dingtalk/bot.d.ts +97 -0
- package/dist/dingtalk/bot.js +389 -0
- package/dist/dingtalk/cards.d.ts +56 -0
- package/dist/dingtalk/cards.js +318 -0
- package/dist/{runtime → dingtalk}/channel-queue.js +4 -1
- package/dist/dingtalk/config.d.ts +19 -0
- package/dist/dingtalk/config.js +95 -0
- package/dist/dingtalk/connection.d.ts +57 -0
- package/dist/dingtalk/connection.js +356 -0
- package/dist/dingtalk/conversation-meta.d.ts +16 -0
- package/dist/dingtalk/conversation-meta.js +77 -0
- package/dist/{runtime → dingtalk}/delivery.d.ts +6 -2
- package/dist/{runtime → dingtalk}/delivery.js +29 -15
- package/dist/dingtalk/handler.d.ts +90 -0
- package/dist/dingtalk/handler.js +1 -0
- package/dist/dingtalk/inbound.d.ts +66 -0
- package/dist/dingtalk/inbound.js +137 -0
- package/dist/dingtalk/media.d.ts +66 -0
- package/dist/dingtalk/media.js +214 -0
- package/dist/events/{event-commands.js → commands.js} +99 -45
- package/dist/events/parse.d.ts +14 -0
- package/dist/events/parse.js +114 -0
- package/dist/events/types.d.ts +93 -0
- package/dist/events/types.js +1 -0
- package/dist/events/{event-validation.d.ts → validation.d.ts} +14 -3
- package/dist/events/{event-validation.js → validation.js} +17 -9
- package/dist/events/watcher.d.ts +67 -0
- package/dist/events/{events.js → watcher.js} +63 -121
- package/dist/executor.js +2 -2
- package/dist/index.d.ts +6 -4
- package/dist/index.js +2 -2
- package/dist/jobs/launch.d.ts +42 -0
- package/dist/jobs/launch.js +118 -0
- package/dist/{agent/job-manager.d.ts → jobs/manager.d.ts} +1 -67
- package/dist/{agent/job-manager.js → jobs/manager.js} +34 -157
- package/dist/jobs/record.d.ts +55 -0
- package/dist/jobs/record.js +36 -0
- package/dist/log.d.ts +12 -2
- package/dist/log.js +26 -34
- package/dist/main.js +3 -3
- package/dist/memory/commands.js +29 -23
- package/dist/memory/lifecycle.js +26 -5
- package/dist/memory/maintenance-gates.d.ts +2 -2
- package/dist/memory/maintenance-state.js +4 -1
- package/dist/memory/maintenance-tuning.d.ts +15 -0
- package/dist/memory/maintenance-tuning.js +3 -0
- package/dist/memory/reflect-job.d.ts +2 -2
- package/dist/memory/reflect-job.js +4 -2
- package/dist/memory/scheduler.d.ts +3 -3
- package/dist/memory/scheduler.js +5 -2
- package/dist/memory/sidecar-worker.js +1 -1
- package/dist/memory/transcript.js +1 -1
- package/dist/{agent/model-fallback.d.ts → models/fallback.d.ts} +6 -6
- package/dist/{agent/model-fallback.js → models/fallback.js} +15 -28
- package/dist/models/login-identity.d.ts +2 -0
- package/dist/models/login-identity.js +83 -0
- package/dist/models/provider-login.d.ts +3 -1
- package/dist/models/provider-login.js +8 -2
- package/dist/models/reference.d.ts +20 -0
- package/dist/models/{utils.js → reference.js} +0 -48
- package/dist/models/{utils.d.ts → runtime.d.ts} +1 -16
- package/dist/models/runtime.js +52 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +9 -0
- package/dist/playbooks/agent-delegation.md +2 -2
- package/dist/playbooks/catalog.d.ts +6 -2
- package/dist/playbooks/catalog.js +9 -6
- package/dist/runtime/bootstrap.d.ts +7 -17
- package/dist/runtime/bootstrap.js +70 -659
- package/dist/runtime/durable-dispatch.d.ts +43 -4
- package/dist/runtime/durable-dispatch.js +153 -3
- package/dist/runtime/inbound-images.d.ts +18 -0
- package/dist/runtime/inbound-images.js +51 -0
- package/dist/runtime/shutdown.d.ts +39 -0
- package/dist/runtime/shutdown.js +120 -0
- package/dist/runtime/stop-watchdog.d.ts +16 -0
- package/dist/runtime/stop-watchdog.js +32 -0
- package/dist/runtime/task-driver.d.ts +6 -4
- package/dist/runtime/task-driver.js +58 -23
- package/dist/runtime/task-migration.js +25 -8
- package/dist/runtime/task-spawn.d.ts +1 -1
- package/dist/runtime/task-spawn.js +13 -6
- package/dist/runtime/turn-handler.d.ts +47 -0
- package/dist/runtime/turn-handler.js +318 -0
- package/dist/runtime/turn-run.d.ts +52 -0
- package/dist/runtime/turn-run.js +318 -0
- package/dist/runtime/wake-coalescing.d.ts +18 -0
- package/dist/runtime/wake-coalescing.js +29 -0
- package/dist/security/block-message.d.ts +22 -1
- package/dist/security/block-message.js +66 -1
- package/dist/security/command-guard.js +4 -0
- package/dist/security/network.d.ts +2 -1
- package/dist/security/network.js +7 -2
- package/dist/security/path-guard-check.js +2 -2
- package/dist/security/path-guard.js +4 -0
- package/dist/security/types.d.ts +1 -2
- package/dist/security/types.js +1 -2
- package/dist/shared/exact-keys.d.ts +1 -1
- package/dist/shared/format.d.ts +12 -0
- package/dist/shared/format.js +37 -0
- package/dist/shared/host-process.js +16 -4
- package/dist/shared/wake-claim.d.ts +1 -1
- package/dist/shared/with-timeout.d.ts +3 -2
- package/dist/shared/with-timeout.js +14 -3
- package/dist/{runtime/skill-commands.d.ts → skills/commands.d.ts} +2 -2
- package/dist/{runtime/skill-commands.js → skills/commands.js} +18 -11
- package/dist/{agent/workspace-resources.js → skills/loader.js} +1 -1
- package/dist/{tools/skill-security.js → skills/validation.js} +4 -0
- package/dist/skills/workspace.d.ts +33 -0
- package/dist/skills/workspace.js +116 -0
- package/dist/{runtime/subagent-commands.d.ts → subagents/commands.d.ts} +9 -7
- package/dist/{runtime/subagent-commands.js → subagents/commands.js} +116 -77
- package/dist/subagents/completion-wake.d.ts +17 -0
- package/dist/subagents/completion-wake.js +76 -0
- package/dist/subagents/detached-discovery.js +1 -1
- package/dist/subagents/discovery.d.ts +1 -1
- package/dist/subagents/discovery.js +2 -2
- package/dist/subagents/dispatch.d.ts +33 -0
- package/dist/subagents/dispatch.js +190 -0
- package/dist/subagents/external/claude-code.js +23 -1
- package/dist/subagents/external/dispatch.d.ts +25 -0
- package/dist/subagents/external/dispatch.js +90 -0
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/progress-tail.d.ts +18 -1
- package/dist/subagents/external/progress-tail.js +64 -17
- package/dist/subagents/external/run.d.ts +5 -1
- package/dist/subagents/external/run.js +23 -9
- package/dist/subagents/external/settlement.d.ts +4 -1
- package/dist/subagents/external/settlement.js +1 -1
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/grace.d.ts +24 -0
- package/dist/subagents/grace.js +57 -0
- package/dist/subagents/internal/outcome.d.ts +24 -0
- package/dist/subagents/internal/outcome.js +149 -0
- package/dist/subagents/internal/provider-retry.d.ts +19 -0
- package/dist/subagents/internal/provider-retry.js +83 -0
- package/dist/subagents/internal/run.d.ts +31 -0
- package/dist/subagents/internal/run.js +240 -0
- package/dist/subagents/internal/state.d.ts +43 -0
- package/dist/subagents/internal/state.js +48 -0
- package/dist/subagents/internal/worker.d.ts +51 -0
- package/dist/subagents/internal/worker.js +167 -0
- package/dist/subagents/result.d.ts +62 -0
- package/dist/subagents/result.js +103 -0
- package/dist/subagents/run-record.d.ts +222 -0
- package/dist/subagents/run-record.js +101 -0
- package/dist/subagents/run-registry.d.ts +9 -0
- package/dist/subagents/run-registry.js +125 -0
- package/dist/subagents/runs.d.ts +16 -232
- package/dist/subagents/runs.js +132 -310
- package/dist/subagents/task-envelope.d.ts +36 -0
- package/dist/subagents/task-envelope.js +168 -0
- package/dist/subagents/types.d.ts +154 -0
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/verification-outcome.d.ts +1 -1
- package/dist/subagents/workspace-summary.d.ts +16 -4
- package/dist/subagents/workspace-summary.js +74 -18
- package/dist/tasks/board.d.ts +10 -3
- package/dist/tasks/board.js +38 -3
- package/dist/tasks/{work-log.d.ts → bound-work.d.ts} +1 -1
- package/dist/tasks/{work-log.js → bound-work.js} +1 -1
- package/dist/tasks/brief.js +1 -1
- package/dist/{runtime/task-commands.d.ts → tasks/commands.d.ts} +1 -1
- package/dist/{runtime/task-commands.js → tasks/commands.js} +117 -67
- package/dist/tasks/contract-input.d.ts +1 -1
- package/dist/tasks/contract-input.js +1 -1
- package/dist/tasks/create.js +1 -1
- package/dist/tasks/frontmatter.d.ts +5 -0
- package/dist/tasks/frontmatter.js +8 -0
- package/dist/tasks/{log.d.ts → loop-log.d.ts} +11 -1
- package/dist/tasks/{log.js → loop-log.js} +59 -3
- package/dist/tasks/mutation-lock.js +1 -1
- package/dist/tasks/session-path.js +1 -1
- package/dist/tasks/steer.js +1 -1
- package/dist/tasks/store.js +6 -4
- package/dist/tasks/ticket.d.ts +3 -1
- package/dist/tasks/ticket.js +19 -1
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.js +2 -2
- package/dist/tools/{tool-details.d.ts → contract/details.d.ts} +11 -3
- package/dist/tools/{tool-details.js → contract/details.js} +42 -5
- package/dist/tools/{presentation.js → contract/presentation.js} +3 -3
- package/dist/tools/event-manage.d.ts +1 -1
- package/dist/tools/event-manage.js +4 -4
- package/dist/tools/index.d.ts +5 -3
- package/dist/tools/index.js +8 -6
- package/dist/tools/job.d.ts +1 -1
- package/dist/tools/memory-manage.js +4 -1
- package/dist/tools/registry.d.ts +7 -7
- package/dist/tools/registry.js +6 -6
- package/dist/tools/session-search.d.ts +1 -1
- package/dist/tools/skill.d.ts +2 -34
- package/dist/tools/skill.js +8 -116
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +19 -13
- package/dist/tools/subagent.d.ts +46 -0
- package/dist/tools/subagent.js +127 -0
- package/dist/tools/{task-manage.d.ts → task-manage/factory.d.ts} +7 -3
- package/dist/tools/{task-manage.js → task-manage/factory.js} +7 -7
- package/dist/tools/task-manage/lifecycle.js +2 -2
- 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 +7 -4
- package/dist/tools/task-manage/types.d.ts +1 -1
- package/dist/tools/web-fetch.d.ts +1 -1
- package/dist/tools/web-search.d.ts +1 -1
- package/dist/tui/app.d.ts +1 -1
- package/dist/tui/app.js +6 -6
- package/dist/tui/cli.d.ts +1 -1
- package/dist/tui/cli.js +3 -3
- package/dist/tui/commands.js +4 -4
- package/dist/tui/frontend.d.ts +44 -0
- package/dist/tui/frontend.js +13 -0
- package/dist/tui/pitui-frontend.d.ts +1 -1
- package/dist/tui/pitui-frontend.js +1 -1
- package/dist/tui/plain-frontend.d.ts +1 -1
- package/dist/tui/renderer.d.ts +3 -42
- package/dist/tui/renderer.js +3 -2
- package/dist/tui/terminal-context.d.ts +2 -2
- package/dist/tui/terminal-media-sender.d.ts +1 -1
- package/dist/tui/turn-controller.d.ts +3 -1
- package/dist/tui/turn-controller.js +36 -21
- package/dist/usage/ledger.js +7 -1
- package/dist/usage/render.js +3 -1
- package/dist/{shared/types.d.ts → usage/totals.d.ts} +3 -0
- package/dist/web/client.d.ts +5 -1
- package/dist/web/client.js +4 -0
- package/dist/web/config.d.ts +1 -1
- package/dist/web/fetch.d.ts +1 -1
- package/dist/web/search-providers.d.ts +1 -1
- package/dist/web/search.d.ts +1 -1
- package/package.json +9 -7
- package/dist/agent/session-adapter.js +0 -77
- package/dist/events/events.d.ts +0 -159
- package/dist/runtime/dingtalk.d.ts +0 -272
- package/dist/runtime/dingtalk.js +0 -1416
- package/dist/subagents/tool.d.ts +0 -206
- package/dist/subagents/tool.js +0 -1088
- /package/dist/{runtime → agent/prompt}/workspace-templates.d.ts +0 -0
- /package/dist/{runtime → agent/prompt}/workspace-templates.js +0 -0
- /package/dist/agent/{session-resource-gate.d.ts → session/session-resource-gate.d.ts} +0 -0
- /package/dist/agent/{context-budget.d.ts → turn/context-budget.d.ts} +0 -0
- /package/dist/agent/{progress-formatter.js → turn/progress-formatter.js} +0 -0
- /package/dist/{memory → agent/turn}/task-digest.d.ts +0 -0
- /package/dist/agent/{turn-recovery.d.ts → turn/turn-recovery.d.ts} +0 -0
- /package/dist/agent/{turn-state.js → turn/turn-state.js} +0 -0
- /package/dist/{runtime → app}/proxy.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/channel-queue.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.js +0 -0
- /package/dist/events/{event-commands.d.ts → commands.d.ts} +0 -0
- /package/dist/{agent/workspace-resources.d.ts → skills/loader.d.ts} +0 -0
- /package/dist/{tools/skill-security.d.ts → skills/validation.d.ts} +0 -0
- /package/dist/tasks/{ledger.d.ts → contract.d.ts} +0 -0
- /package/dist/tasks/{ledger.js → contract.js} +0 -0
- /package/dist/tools/{subagent-tool-names.d.ts → contract/names.d.ts} +0 -0
- /package/dist/tools/{subagent-tool-names.js → contract/names.js} +0 -0
- /package/dist/tools/{presentation.d.ts → contract/presentation.d.ts} +0 -0
- /package/dist/{shared/types.js → usage/totals.js} +0 -0
|
@@ -2,13 +2,14 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { discoverWorkspaceChannelIds } from "../channel/channel-index.js";
|
|
4
4
|
import { dedupeChannelIdsByDirectory, getChannelDir, isChannelId } from "../channel/channel-paths.js";
|
|
5
|
+
import { TASK_DRIVER_SETTINGS } from "../config/settings.js";
|
|
5
6
|
import * as log from "../log.js";
|
|
6
7
|
import { PLAYBOOKS_DIR } from "../paths.js";
|
|
7
|
-
import { TASK_DRIVER_SETTINGS } from "../settings.js";
|
|
8
8
|
import { errorMessage } from "../shared/text-utils.js";
|
|
9
9
|
import { checkBudget, IDLE_STEP_LIMIT } from "../tasks/budget.js";
|
|
10
|
-
import { readActiveTasks } from "../tasks/
|
|
11
|
-
import {
|
|
10
|
+
import { readActiveTasks } from "../tasks/contract.js";
|
|
11
|
+
import { taskStateLabel } from "../tasks/frontmatter.js";
|
|
12
|
+
import { readTaskLog } from "../tasks/loop-log.js";
|
|
12
13
|
import { expireTicket, pauseTask, redeemTicket } from "../tasks/store.js";
|
|
13
14
|
/** Short debounce so a burst of nudges collapses into a single rescan. */
|
|
14
15
|
const NUDGE_DEBOUNCE_MS = 50;
|
|
@@ -79,17 +80,22 @@ export function createTaskDriverEvent(channelId, entry, nowMs) {
|
|
|
79
80
|
/**
|
|
80
81
|
* The deterministic receipt a runtime stop produces (spec 051, D11). It is delivered directly,
|
|
81
82
|
* without opening a model turn: the user needs to know their task stopped, and spending an LLM
|
|
82
|
-
* call to phrase that is exactly the kind of cost this design removes.
|
|
83
|
+
* call to phrase that is exactly the kind of cost this design removes. A budget stop also says
|
|
84
|
+
* how to resume with more of the dimension that ran out (spec 053, D6).
|
|
83
85
|
*/
|
|
84
|
-
export function taskStopReceipt(channelId, entry, reason, nowMs) {
|
|
86
|
+
export function taskStopReceipt(channelId, entry, reason, nowMs, breach) {
|
|
87
|
+
const usage = entry.fields.usage ? ` · 已用 ${entry.fields.usage.steps} 步` : "";
|
|
88
|
+
const grant = breach === "steps" ? " +steps 10" : breach === "usd" ? " +usd 5" : "";
|
|
89
|
+
const resumeLabel = grant ? "继续并追加预算" : "继续";
|
|
85
90
|
return {
|
|
86
91
|
...channelType(channelId),
|
|
87
92
|
channelId,
|
|
88
93
|
user: "TASK_DRIVER",
|
|
89
94
|
userName: "TASK_DRIVER",
|
|
90
|
-
text:
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
text: `🛑 任务 \`${entry.id}\`(${entry.title})已停止自动执行:${reason}。\n` +
|
|
96
|
+
`状态:${taskStateLabel(entry.fields.state)}${usage}\n` +
|
|
97
|
+
`查看:\`/tasks show ${entry.id}\`;${resumeLabel}:\`/tasks resume ${entry.id}${grant}\`\n` +
|
|
98
|
+
"不再需要:直接告诉我取消该任务。",
|
|
93
99
|
ts: String(nowMs),
|
|
94
100
|
// Keyed on the cause, not the moment: re-detecting the same stop before the user has acted
|
|
95
101
|
// must not queue a second identical receipt, while a different cause still does.
|
|
@@ -134,14 +140,18 @@ export class TaskDriver {
|
|
|
134
140
|
this.options.onDispatch?.(event, accepted);
|
|
135
141
|
}
|
|
136
142
|
catch (error) {
|
|
137
|
-
log.
|
|
143
|
+
log.logWarn("taskdriver.observer.failed", "Task driver dispatch observer failed", {
|
|
144
|
+
reason: errorMessage(error),
|
|
145
|
+
});
|
|
138
146
|
}
|
|
139
147
|
}
|
|
140
148
|
start() {
|
|
141
149
|
if (this.loopActive)
|
|
142
150
|
return;
|
|
143
151
|
this.loopActive = true;
|
|
144
|
-
log.
|
|
152
|
+
log.logInfoEvent("taskdriver.started", "Task driver started", {
|
|
153
|
+
fields: { timezone: Intl.DateTimeFormat().resolvedOptions().timeZone },
|
|
154
|
+
});
|
|
145
155
|
void this.tick();
|
|
146
156
|
}
|
|
147
157
|
stop() {
|
|
@@ -178,7 +188,7 @@ export class TaskDriver {
|
|
|
178
188
|
await this.runOnce();
|
|
179
189
|
}
|
|
180
190
|
catch (error) {
|
|
181
|
-
log.
|
|
191
|
+
log.logWarn("taskdriver.tick.failed", "Task driver tick failed", { reason: errorMessage(error) });
|
|
182
192
|
}
|
|
183
193
|
this.scheduleNext();
|
|
184
194
|
}
|
|
@@ -203,12 +213,15 @@ export class TaskDriver {
|
|
|
203
213
|
this.nextWakeMs = candidate;
|
|
204
214
|
}
|
|
205
215
|
/** Stop one task and notify. Delivery failure is logged, never fatal: the durable stop already happened. */
|
|
206
|
-
async notifyStop(channelId, entry, reason, nowMs) {
|
|
216
|
+
async notifyStop(channelId, entry, reason, nowMs, breach) {
|
|
207
217
|
try {
|
|
208
|
-
await this.options.notify?.(taskStopReceipt(channelId, entry, reason, nowMs));
|
|
218
|
+
await this.options.notify?.(taskStopReceipt(channelId, entry, reason, nowMs, breach));
|
|
209
219
|
}
|
|
210
220
|
catch (error) {
|
|
211
|
-
log.
|
|
221
|
+
log.logWarn("taskdriver.receipt.failed", "Task stop receipt failed", {
|
|
222
|
+
channelId: channelId,
|
|
223
|
+
reason: errorMessage(error),
|
|
224
|
+
});
|
|
212
225
|
}
|
|
213
226
|
}
|
|
214
227
|
/**
|
|
@@ -237,11 +250,19 @@ export class TaskDriver {
|
|
|
237
250
|
continue;
|
|
238
251
|
changed = true;
|
|
239
252
|
if (expiry.outcome === "paused") {
|
|
240
|
-
log.
|
|
241
|
-
|
|
253
|
+
log.logWarn("taskdriver.task.paused", "Task paused: ticket expired twice", {
|
|
254
|
+
channelId: channelId,
|
|
255
|
+
reason: expiry.ticket,
|
|
256
|
+
fields: { taskId: entry.id, cause: "ticket_expired" },
|
|
257
|
+
});
|
|
258
|
+
await this.notifyStop(channelId, entry, `等待条件一直未满足(${expiry.ticket}),已连续两次超过最晚检查时间`, nowMs);
|
|
242
259
|
}
|
|
243
260
|
else {
|
|
244
|
-
log.
|
|
261
|
+
log.logInfoEvent("taskdriver.task.reopened", "Task reopened after its ticket expired", {
|
|
262
|
+
channelId: channelId,
|
|
263
|
+
reason: expiry.ticket,
|
|
264
|
+
fields: { taskId: entry.id },
|
|
265
|
+
});
|
|
245
266
|
}
|
|
246
267
|
continue;
|
|
247
268
|
}
|
|
@@ -268,10 +289,14 @@ export class TaskDriver {
|
|
|
268
289
|
const idle = steps.every((record) => record.kind === "step" && record.tools.length === 0);
|
|
269
290
|
if (!idle)
|
|
270
291
|
continue;
|
|
271
|
-
const reason = `连续 ${IDLE_STEP_LIMIT}
|
|
292
|
+
const reason = `连续 ${IDLE_STEP_LIMIT} 步没有任何工具调用,已停下等你确认`;
|
|
272
293
|
if (await pauseTask(channelDir, entry.id, { by: "runtime", reason })) {
|
|
273
294
|
paused = true;
|
|
274
|
-
log.
|
|
295
|
+
log.logWarn("taskdriver.task.paused", "Task paused: idle loop", {
|
|
296
|
+
channelId: channelId,
|
|
297
|
+
reason: reason,
|
|
298
|
+
fields: { taskId: entry.id, cause: "idle" },
|
|
299
|
+
});
|
|
275
300
|
await this.notifyStop(channelId, entry, reason, nowMs);
|
|
276
301
|
}
|
|
277
302
|
}
|
|
@@ -322,8 +347,12 @@ export class TaskDriver {
|
|
|
322
347
|
continue;
|
|
323
348
|
}
|
|
324
349
|
if (await pauseTask(channelDir, entry.id, { by: "runtime", reason: status.reason })) {
|
|
325
|
-
log.
|
|
326
|
-
|
|
350
|
+
log.logWarn("taskdriver.task.paused", "Task paused: budget exhausted", {
|
|
351
|
+
channelId: channelId,
|
|
352
|
+
reason: status.reason,
|
|
353
|
+
fields: { taskId: entry.id, cause: `budget_${status.breach}` },
|
|
354
|
+
});
|
|
355
|
+
await this.notifyStop(channelId, entry, status.reason, nowMs, status.breach);
|
|
327
356
|
}
|
|
328
357
|
}
|
|
329
358
|
const idled = await this.detectIdleLoop(channelDir, channelId, budgeted, nowMs);
|
|
@@ -358,10 +387,16 @@ export class TaskDriver {
|
|
|
358
387
|
if (accepted) {
|
|
359
388
|
dispatched++;
|
|
360
389
|
lastDispatchOffset = offset;
|
|
361
|
-
log.
|
|
390
|
+
log.logDebugEvent("taskdriver.step.enqueued", "Task step enqueued", {
|
|
391
|
+
channelId: channelId,
|
|
392
|
+
fields: { taskId: entry.id },
|
|
393
|
+
});
|
|
362
394
|
}
|
|
363
395
|
else {
|
|
364
|
-
log.
|
|
396
|
+
log.logWarn("taskdriver.step.enqueue_failed", "Task step not enqueued: channel queue unavailable", {
|
|
397
|
+
channelId: channelId,
|
|
398
|
+
fields: { taskId: entry.id },
|
|
399
|
+
});
|
|
365
400
|
}
|
|
366
401
|
}
|
|
367
402
|
for (const key of this.lastDispatchMs.keys()) {
|
|
@@ -8,9 +8,9 @@ import { formatLocalTime } from "../shared/local-time.js";
|
|
|
8
8
|
import { errorMessage } from "../shared/text-utils.js";
|
|
9
9
|
import { isPlainObject } from "../shared/type-guards.js";
|
|
10
10
|
import { createUsage } from "../tasks/budget.js";
|
|
11
|
+
import { extractTaskTitle, findTaskSectionBounds, normalizeTaskId, parseTaskItems, taskBody, } from "../tasks/contract.js";
|
|
11
12
|
import { validateTaskContractInput } from "../tasks/contract-input.js";
|
|
12
|
-
import {
|
|
13
|
-
import { appendTaskLog } from "../tasks/log.js";
|
|
13
|
+
import { appendTaskLog } from "../tasks/loop-log.js";
|
|
14
14
|
import { withTaskMutation } from "../tasks/mutation-lock.js";
|
|
15
15
|
import { ArchiveUndoError, archiveTask, readStoredTask, writeStoredTask } from "../tasks/store.js";
|
|
16
16
|
import { discoverTaskChannels } from "./task-driver.js";
|
|
@@ -291,7 +291,10 @@ async function convertOneTask(workspaceDir, channelId, channelDir, id, now) {
|
|
|
291
291
|
stage = "archive";
|
|
292
292
|
await archiveTask(channelDir, id, "cancelled");
|
|
293
293
|
}
|
|
294
|
-
log.
|
|
294
|
+
log.logInfoEvent("tasks.migration.converted", "Task converted to v5", {
|
|
295
|
+
reason: `state=${fields.state}${fields.paused ? " paused" : ""}${origin ? ` origin=${origin}` : ""}${retire ? " (retired)" : ""}`,
|
|
296
|
+
fields: { taskId: id },
|
|
297
|
+
});
|
|
295
298
|
return true;
|
|
296
299
|
}
|
|
297
300
|
catch (error) {
|
|
@@ -400,7 +403,9 @@ export async function migrateTasksToV5(workspaceDir, stateDir) {
|
|
|
400
403
|
}
|
|
401
404
|
catch (error) {
|
|
402
405
|
// An undiscoverable workspace is not an empty one: no task was looked at, so no marker.
|
|
403
|
-
log.
|
|
406
|
+
log.logWarn("tasks.migration.discover_failed", "Workspace channels could not be discovered", {
|
|
407
|
+
reason: errorMessage(error),
|
|
408
|
+
});
|
|
404
409
|
failures.push({ channelId: "*", stage: "discover", error: errorMessage(error), rollback: "ok" });
|
|
405
410
|
}
|
|
406
411
|
for (const channelId of channelIds) {
|
|
@@ -411,7 +416,10 @@ export async function migrateTasksToV5(workspaceDir, stateDir) {
|
|
|
411
416
|
}
|
|
412
417
|
catch (error) {
|
|
413
418
|
// An unreadable task directory is not an empty one: the originals were not looked at.
|
|
414
|
-
log.
|
|
419
|
+
log.logWarn("tasks.migration.list_failed", "Channel tasks could not be listed", {
|
|
420
|
+
channelId: channelId,
|
|
421
|
+
reason: errorMessage(error),
|
|
422
|
+
});
|
|
415
423
|
failures.push({ channelId, stage: "scan", error: errorMessage(error), rollback: "ok" });
|
|
416
424
|
}
|
|
417
425
|
for (const filename of filenames) {
|
|
@@ -421,7 +429,10 @@ export async function migrateTasksToV5(workspaceDir, stateDir) {
|
|
|
421
429
|
converted++;
|
|
422
430
|
}
|
|
423
431
|
catch (error) {
|
|
424
|
-
log.
|
|
432
|
+
log.logWarn("tasks.migration.convert_failed", "Task could not be converted to v5", {
|
|
433
|
+
reason: errorMessage(error),
|
|
434
|
+
fields: { taskId: id },
|
|
435
|
+
});
|
|
425
436
|
failures.push({
|
|
426
437
|
channelId,
|
|
427
438
|
task: id,
|
|
@@ -432,7 +443,10 @@ export async function migrateTasksToV5(workspaceDir, stateDir) {
|
|
|
432
443
|
}
|
|
433
444
|
}
|
|
434
445
|
await moveTaskOwnedEvents(workspaceDir, channelId, channelDir).catch((error) => {
|
|
435
|
-
log.
|
|
446
|
+
log.logWarn("tasks.migration.events_failed", "Task-owned events could not be moved", {
|
|
447
|
+
channelId: channelId,
|
|
448
|
+
reason: errorMessage(error),
|
|
449
|
+
});
|
|
436
450
|
failures.push({ channelId, stage: "events", error: errorMessage(error), rollback: "ok" });
|
|
437
451
|
});
|
|
438
452
|
}
|
|
@@ -444,5 +458,8 @@ export async function migrateTasksToV5(workspaceDir, stateDir) {
|
|
|
444
458
|
await rm(reportPath, { force: true });
|
|
445
459
|
await writeFile(markerPath, `${formatLocalTime(now)}\n`, "utf-8");
|
|
446
460
|
if (converted > 0)
|
|
447
|
-
log.
|
|
461
|
+
log.logInfoEvent("tasks.migration.done", "Task conversion to v5 complete", {
|
|
462
|
+
reason: `${converted} task(s)`,
|
|
463
|
+
fields: { converted },
|
|
464
|
+
});
|
|
448
465
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SpawnTaskRequest, SpawnTaskResult } from "../events/
|
|
1
|
+
import type { SpawnTaskRequest, SpawnTaskResult } from "../events/types.js";
|
|
2
2
|
export interface TaskSpawnerOptions {
|
|
3
3
|
/** The channel's directory under the workspace. */
|
|
4
4
|
getChannelDir: (channelId: string) => string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import * as log from "../log.js";
|
|
3
|
+
import { readActiveTasks } from "../tasks/contract.js";
|
|
3
4
|
import { createTaskDocument, instanceStamp } from "../tasks/create.js";
|
|
4
|
-
import {
|
|
5
|
+
import { taskStateLabel } from "../tasks/frontmatter.js";
|
|
5
6
|
import { archivedTaskPath, taskPath, tasksDir } from "../tasks/store.js";
|
|
6
|
-
const STATE_LABEL = { open: "进行中", parked: "等待中" };
|
|
7
7
|
/**
|
|
8
8
|
* Create the task instance a template event asks for (spec 052, D2).
|
|
9
9
|
*
|
|
@@ -27,11 +27,15 @@ export function createTaskSpawner(options) {
|
|
|
27
27
|
}
|
|
28
28
|
const active = (await readActiveTasks(tasksDir(channelDir))).find((entry) => entry.fields.origin === request.eventName && !entry.fields.outcome);
|
|
29
29
|
if (active) {
|
|
30
|
-
const state =
|
|
30
|
+
const state = `${taskStateLabel(active.fields.state)}${active.fields.paused ? ",已暂停" : ""}`;
|
|
31
31
|
await options
|
|
32
|
-
.notify(request.channelId,
|
|
32
|
+
.notify(request.channelId, `⚠️ 周期任务 \`${request.eventName}\` 本次(${instanceStamp(request.occurrence)})未启动:上一个实例 \`${active.id}\` 仍未结束(${state})。\n查看:\`/tasks show ${active.id}\``)
|
|
33
33
|
.catch((error) => {
|
|
34
|
-
log.
|
|
34
|
+
log.logWarn("tasks.spawn.receipt_failed", "Skip receipt delivery failed", {
|
|
35
|
+
channelId: request.channelId,
|
|
36
|
+
reason: String(error),
|
|
37
|
+
fields: { event: request.eventName },
|
|
38
|
+
});
|
|
35
39
|
});
|
|
36
40
|
return { outcome: "skipped", id: active.id };
|
|
37
41
|
}
|
|
@@ -42,7 +46,10 @@ export function createTaskSpawner(options) {
|
|
|
42
46
|
origin: request.eventName,
|
|
43
47
|
now: request.occurrence,
|
|
44
48
|
});
|
|
45
|
-
log.
|
|
49
|
+
log.logInfoEvent("tasks.spawn.created", "Event spawned a task instance", {
|
|
50
|
+
channelId: request.channelId,
|
|
51
|
+
fields: { event: request.eventName, taskId: id },
|
|
52
|
+
});
|
|
46
53
|
options.nudge();
|
|
47
54
|
return { outcome: "spawned", id };
|
|
48
55
|
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AgentRunner } from "../agent/types.js";
|
|
2
|
+
import type { BootstrapPaths } from "../app/home.js";
|
|
3
|
+
import type { ChannelIndex } from "../channel/channel-index.js";
|
|
4
|
+
import type { ChannelStore } from "../channel/store.js";
|
|
5
|
+
import type { DingTalkHandler } from "../dingtalk/handler.js";
|
|
6
|
+
import type { JobRuntime } from "../jobs/manager.js";
|
|
7
|
+
import type { SubAgentRuntime } from "../subagents/run-registry.js";
|
|
8
|
+
import type { DurableDispatchService } from "./durable-dispatch.js";
|
|
9
|
+
import type { WakeTaskTransitionHooks } from "./task-wake.js";
|
|
10
|
+
import { type ArchivedMessage } from "./turn-run.js";
|
|
11
|
+
export interface TurnHandlerOptions {
|
|
12
|
+
paths: BootstrapPaths;
|
|
13
|
+
/** Override the `/stop` watchdog's grace window (tests use a short one). */
|
|
14
|
+
stopForceEndGraceMs?: number;
|
|
15
|
+
/** Test-only fault seams for the atomic structured-wake task transition. */
|
|
16
|
+
wakeTransitionHooks?: Partial<Record<"job" | "subagent", WakeTaskTransitionHooks>>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Everything the turn handler needs from `createRuntimeContext`'s scope (review 2026-08-30):
|
|
20
|
+
* pulled out so the handler's dependencies are a reviewable, typed list instead of "however many
|
|
21
|
+
* closures happen to be in scope" in an 850-line inline object literal. The four `get*`/`is*`
|
|
22
|
+
* accessors exist only for state this function's own scope assigns *after* the handler is built
|
|
23
|
+
* (`durableDispatch`, `executor`, `taskDriver`) or mutates later (`shuttingDown`) — a handler
|
|
24
|
+
* method only ever runs long after all of them are set, but a plain value captured at
|
|
25
|
+
* construction time would freeze a stale snapshot instead of observing the real one.
|
|
26
|
+
*/
|
|
27
|
+
export interface TurnHandlerDeps {
|
|
28
|
+
options: TurnHandlerOptions;
|
|
29
|
+
store: ChannelStore;
|
|
30
|
+
channelRunners: Map<string, AgentRunner>;
|
|
31
|
+
sessionResetChains: Map<string, Promise<void>>;
|
|
32
|
+
activeTasks: Set<Promise<void>>;
|
|
33
|
+
stopWatchdogs: Set<string>;
|
|
34
|
+
channelIndex: ChannelIndex;
|
|
35
|
+
archiveIncomingMessage: (channelId: string, message: ArchivedMessage, contextLabel: string) => Promise<void>;
|
|
36
|
+
getRunner: (channelId: string) => AgentRunner;
|
|
37
|
+
cliVersion: string;
|
|
38
|
+
startedAt: number;
|
|
39
|
+
isShuttingDown: () => boolean;
|
|
40
|
+
getDurableDispatch: () => DurableDispatchService | undefined;
|
|
41
|
+
getJobs: () => JobRuntime;
|
|
42
|
+
getRuns: () => SubAgentRuntime;
|
|
43
|
+
getTaskDriver: () => {
|
|
44
|
+
nudge?(): void;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export declare function createTurnHandler(deps: TurnHandlerDeps): DingTalkHandler;
|