@oyasmi/pipiclaw 0.9.5 → 0.9.6-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 +300 -142
- package/README.md +295 -140
- package/dist/agent/builtin-commands.d.ts +1 -1
- package/dist/agent/builtin-commands.js +1 -1
- package/dist/agent/channel-runner.d.ts +4 -3
- package/dist/agent/channel-runner.js +17 -28
- package/dist/agent/maintenance-context.js +2 -2
- package/dist/agent/prompt/builder.d.ts +1 -1
- package/dist/agent/prompt/builder.js +1 -1
- package/dist/agent/prompt/extension.d.ts +1 -1
- package/dist/agent/prompt/extension.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +12 -5
- package/dist/agent/prompt/resources.d.ts +0 -3
- package/dist/agent/prompt/resources.js +0 -6
- package/dist/agent/prompt/sections.d.ts +2 -2
- package/dist/agent/prompt/sections.js +36 -26
- package/dist/agent/prompt/types.d.ts +3 -2
- package/dist/agent/runner-factory.js +1 -1
- package/dist/agent/session/command-extension.js +3 -1
- package/dist/agent/session/compaction-summary.js +3 -6
- package/dist/agent/session/compaction.d.ts +2 -0
- package/dist/agent/session/compaction.js +22 -14
- package/dist/agent/session/event-guards.d.ts +2 -1
- package/dist/agent/session/event-guards.js +6 -0
- package/dist/agent/session/model-selection.d.ts +2 -1
- package/dist/agent/session/model-selection.js +5 -5
- package/dist/agent/session/session-events.js +31 -4
- package/dist/agent/session/session-host.d.ts +5 -3
- package/dist/agent/session/session-host.js +20 -16
- package/dist/agent/status-render.js +3 -0
- package/dist/agent/stop-watchdog.js +5 -1
- package/dist/agent/turn/task-digest.d.ts +2 -5
- package/dist/agent/turn/task-digest.js +25 -45
- package/dist/agent/turn/turn-context.js +4 -6
- package/dist/agent/turn/turn-error.d.ts +1 -1
- package/dist/agent/turn/turn-error.js +9 -0
- package/dist/agent/turn/turn-pipeline.d.ts +10 -5
- package/dist/agent/turn/turn-pipeline.js +36 -7
- package/dist/agent/turn/turn-prompt.d.ts +2 -0
- package/dist/agent/turn/turn-prompt.js +2 -1
- package/dist/agent/turn/turn-recovery.js +4 -1
- package/dist/agent/turn/turn-state.d.ts +2 -0
- package/dist/agent/turn/turn-state.js +2 -1
- package/dist/agent/types.d.ts +23 -3
- package/dist/agent/types.js +2 -0
- package/dist/app/auth-command.d.ts +25 -0
- package/dist/app/auth-command.js +200 -67
- package/dist/app/home.d.ts +7 -8
- package/dist/app/home.js +143 -56
- package/dist/channel/attachments.d.ts +4 -0
- package/dist/channel/attachments.js +4 -0
- package/dist/channel/channel-context.d.ts +6 -0
- package/dist/channel/config.d.ts +3 -0
- package/dist/channel/config.js +11 -5
- package/dist/channel/store.d.ts +1 -1
- package/dist/commands/catalog.js +42 -10
- package/dist/commands/router.js +5 -1
- package/dist/desk/commands.d.ts +44 -5
- package/dist/desk/commands.js +162 -28
- package/dist/desk/paths.d.ts +6 -0
- package/dist/desk/paths.js +21 -1
- package/dist/desk/registry.d.ts +17 -2
- package/dist/desk/registry.js +122 -12
- package/dist/desk/types.d.ts +83 -1
- package/dist/dingtalk/bot.d.ts +1 -1
- package/dist/dingtalk/bot.js +4 -3
- package/dist/dingtalk/config.js +10 -10
- package/dist/dingtalk/delivery.js +15 -8
- package/dist/dingtalk/inbound-media.d.ts +36 -14
- package/dist/dingtalk/inbound-media.js +71 -12
- package/dist/dingtalk/inbound.d.ts +9 -2
- package/dist/dingtalk/inbound.js +17 -2
- package/dist/dingtalk/media.d.ts +4 -10
- package/dist/dingtalk/media.js +58 -32
- package/dist/events/commands.d.ts +2 -0
- package/dist/events/commands.js +13 -8
- package/dist/events/history.d.ts +9 -0
- package/dist/events/history.js +66 -0
- package/dist/events/parse.js +7 -3
- package/dist/events/types.d.ts +3 -0
- package/dist/events/watcher.d.ts +4 -8
- package/dist/events/watcher.js +53 -58
- package/dist/jobs/kill.d.ts +23 -0
- package/dist/jobs/kill.js +65 -0
- package/dist/jobs/manager.d.ts +19 -18
- package/dist/jobs/manager.js +36 -103
- package/dist/main.js +15 -3
- package/dist/memory/boundary-work.d.ts +2 -1
- package/dist/memory/boundary-work.js +1 -1
- package/dist/memory/lifecycle.d.ts +2 -1
- package/dist/memory/lifecycle.js +2 -2
- package/dist/memory/reflect-job.d.ts +2 -1
- package/dist/memory/reflect-job.js +1 -1
- package/dist/memory/reflect.d.ts +2 -1
- package/dist/memory/reflect.js +25 -4
- package/dist/memory/scheduler.d.ts +2 -1
- package/dist/memory/scheduler.js +1 -1
- package/dist/memory/session-corpus.d.ts +1 -1
- package/dist/memory/session-corpus.js +76 -1
- package/dist/memory/session-search.d.ts +2 -1
- package/dist/memory/session-search.js +14 -12
- package/dist/memory/sidecar-worker.d.ts +2 -1
- package/dist/memory/sidecar-worker.js +2 -4
- package/dist/memory/store.d.ts +2 -0
- package/dist/memory/store.js +19 -9
- package/dist/models/credential-work.d.ts +7 -0
- package/dist/models/credential-work.js +36 -0
- package/dist/models/login-ui.js +4 -4
- package/dist/models/provider-login.js +7 -6
- package/dist/models/requests.d.ts +8 -0
- package/dist/models/requests.js +69 -0
- package/dist/models/runtime.d.ts +3 -1
- package/dist/models/runtime.js +9 -2
- package/dist/playbooks/agent-delegation.md +20 -45
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/delegation-inline.md +25 -0
- package/dist/playbooks/delegation-recovery.md +28 -0
- package/dist/playbooks/event-scheduling.md +18 -37
- package/dist/playbooks/event-sensors.md +26 -0
- package/dist/playbooks/event-task-template.md +22 -0
- package/dist/playbooks/learning-and-skills.md +26 -0
- package/dist/playbooks/memory-operations.md +36 -0
- package/dist/playbooks/outbound-media.md +2 -2
- package/dist/playbooks/runtime-files.md +29 -0
- package/dist/playbooks/runtime-operations.md +25 -0
- package/dist/playbooks/runtime-orientation.md +18 -53
- package/dist/playbooks/task-lead.md +22 -68
- package/dist/playbooks/task-manage.md +38 -0
- package/dist/playbooks/task-recovery.md +24 -0
- package/dist/playbooks/task-verify.md +22 -0
- package/dist/runtime/bootstrap.d.ts +10 -0
- package/dist/runtime/bootstrap.js +93 -29
- package/dist/runtime/daemon-lock.js +3 -3
- package/dist/runtime/desk-runtime.d.ts +40 -7
- package/dist/runtime/desk-runtime.js +330 -44
- package/dist/runtime/durable-dispatch.d.ts +14 -2
- package/dist/runtime/durable-dispatch.js +207 -65
- package/dist/runtime/ingress-busy.js +17 -8
- package/dist/runtime/ingress-commands.js +24 -4
- package/dist/runtime/ingress-deps.d.ts +4 -1
- package/dist/runtime/ingress.js +6 -1
- package/dist/runtime/request-execution.js +7 -6
- package/dist/runtime/shutdown.d.ts +4 -1
- package/dist/runtime/shutdown.js +88 -35
- package/dist/runtime/task-close.d.ts +1 -1
- package/dist/runtime/task-close.js +6 -3
- package/dist/runtime/task-control.d.ts +2 -3
- package/dist/runtime/task-control.js +38 -11
- package/dist/runtime/task-input.js +1 -1
- package/dist/runtime/task-lane-types.d.ts +12 -2
- package/dist/runtime/task-lane-types.js +9 -0
- package/dist/runtime/task-lane.d.ts +2 -0
- package/dist/runtime/task-lane.js +38 -20
- package/dist/runtime/task-step.d.ts +3 -3
- package/dist/runtime/task-step.js +34 -16
- package/dist/runtime/transports.js +6 -5
- package/dist/runtime/turn-run.js +103 -66
- package/dist/security/command-guard.d.ts +1 -1
- package/dist/security/command-guard.js +259 -314
- package/dist/security/path-guard.js +48 -7
- package/dist/security/shell-parse.d.ts +10 -0
- package/dist/security/shell-parse.js +224 -0
- package/dist/security/types.d.ts +2 -0
- package/dist/subagents/commands.d.ts +1 -1
- package/dist/subagents/commands.js +14 -5
- package/dist/subagents/completion-wake.js +6 -0
- package/dist/subagents/detached-discovery.d.ts +1 -1
- package/dist/subagents/discovery.d.ts +18 -199
- package/dist/subagents/discovery.js +35 -289
- package/dist/subagents/dispatch.d.ts +1 -2
- package/dist/subagents/dispatch.js +50 -29
- package/dist/subagents/external/antigravity-cli.d.ts +2 -0
- package/dist/subagents/external/antigravity-cli.js +517 -0
- package/dist/subagents/external/claude-code.js +8 -17
- package/dist/subagents/external/codex-cli.js +8 -18
- package/dist/subagents/external/cursor-cli.js +34 -31
- package/dist/subagents/external/dispatch.d.ts +21 -7
- package/dist/subagents/external/dispatch.js +146 -12
- package/dist/subagents/external/exec.js +3 -0
- package/dist/subagents/external/harness.d.ts +57 -33
- package/dist/subagents/external/harness.js +69 -40
- package/dist/subagents/external/reconciliation.js +1 -0
- package/dist/subagents/external/registry.js +4 -1
- package/dist/subagents/external/role-warnings.d.ts +4 -13
- package/dist/subagents/external/role-warnings.js +4 -28
- package/dist/subagents/external/run.d.ts +1 -2
- package/dist/subagents/external/run.js +16 -26
- package/dist/subagents/external/settlement.d.ts +2 -0
- package/dist/subagents/external/settlement.js +13 -3
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/internal/outcome.d.ts +1 -2
- package/dist/subagents/internal/outcome.js +19 -12
- package/dist/subagents/internal/provider-retry.d.ts +1 -2
- package/dist/subagents/internal/provider-retry.js +2 -4
- package/dist/subagents/internal/run.d.ts +2 -3
- package/dist/subagents/internal/run.js +27 -4
- package/dist/subagents/internal/state.d.ts +2 -5
- package/dist/subagents/internal/state.js +1 -2
- package/dist/subagents/internal/worker.d.ts +1 -2
- package/dist/subagents/internal/worker.js +20 -10
- package/dist/subagents/resolve.d.ts +56 -0
- package/dist/subagents/resolve.js +202 -0
- package/dist/subagents/result.d.ts +6 -4
- package/dist/subagents/result.js +39 -6
- package/dist/subagents/run-record.d.ts +54 -2
- package/dist/subagents/run-record.js +7 -0
- package/dist/subagents/runs.d.ts +6 -31
- package/dist/subagents/runs.js +26 -31
- package/dist/subagents/task-envelope.d.ts +1 -2
- package/dist/subagents/task-envelope.js +13 -4
- package/dist/subagents/task-settlement.js +1 -0
- package/dist/subagents/types.d.ts +105 -6
- package/dist/subagents/types.js +16 -1
- package/dist/subagents/workspace-lease.d.ts +41 -24
- package/dist/subagents/workspace-lease.js +159 -24
- package/dist/subagents/worktree.d.ts +52 -0
- package/dist/subagents/worktree.js +363 -0
- package/dist/tasks/archive.js +4 -0
- package/dist/tasks/brief.d.ts +5 -1
- package/dist/tasks/brief.js +19 -5
- package/dist/tasks/commands.d.ts +6 -1
- package/dist/tasks/commands.js +32 -7
- package/dist/tasks/control.d.ts +11 -0
- package/dist/tasks/delivery.d.ts +2 -0
- package/dist/tasks/delivery.js +141 -21
- package/dist/tasks/loop-log.d.ts +12 -0
- package/dist/tasks/loop-log.js +10 -1
- package/dist/tasks/receipts.d.ts +7 -3
- package/dist/tasks/receipts.js +34 -5
- package/dist/tools/bash.d.ts +3 -0
- package/dist/tools/bash.js +29 -15
- package/dist/tools/contract/presentation.js +7 -5
- package/dist/tools/edit-diff.d.ts +11 -0
- package/dist/tools/edit-diff.js +148 -0
- package/dist/tools/edit-match.d.ts +18 -0
- package/dist/tools/edit-match.js +242 -0
- package/dist/tools/edit.d.ts +10 -2
- package/dist/tools/edit.js +91 -361
- package/dist/tools/event-manage.d.ts +2 -1
- package/dist/tools/event-manage.js +46 -39
- package/dist/tools/file-observations.d.ts +9 -0
- package/dist/tools/file-observations.js +50 -0
- package/dist/tools/glob-match.d.ts +3 -1
- package/dist/tools/glob-match.js +40 -17
- package/dist/tools/glob.d.ts +1 -0
- package/dist/tools/glob.js +39 -19
- package/dist/tools/grep-command.d.ts +13 -0
- package/dist/tools/grep-command.js +77 -0
- package/dist/tools/grep.js +96 -201
- package/dist/tools/index.d.ts +6 -2
- package/dist/tools/index.js +9 -4
- package/dist/tools/job.js +12 -11
- package/dist/tools/read.d.ts +2 -0
- package/dist/tools/read.js +10 -2
- package/dist/tools/registry.d.ts +16 -11
- package/dist/tools/registry.js +32 -12
- package/dist/tools/send-media.js +9 -5
- package/dist/tools/session-search.d.ts +2 -1
- package/dist/tools/session-search.js +15 -5
- package/dist/tools/skill.js +13 -12
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +25 -152
- package/dist/tools/subagent.d.ts +24 -2
- package/dist/tools/subagent.js +24 -18
- package/dist/tools/task-manage/control-tools.js +1 -1
- package/dist/tools/task-manage/factory.d.ts +2 -2
- package/dist/tools/task-manage/factory.js +40 -4
- package/dist/tools/task-manage/lifecycle.d.ts +3 -3
- package/dist/tools/task-manage/lifecycle.js +56 -13
- package/dist/tools/task-manage/schema.d.ts +4 -1
- package/dist/tools/task-manage/schema.js +4 -1
- package/dist/tools/task-manage/shared.d.ts +1 -1
- package/dist/tools/task-manage/types.d.ts +5 -1
- package/dist/tools/write-content.d.ts +7 -1
- package/dist/tools/write-content.js +18 -6
- package/dist/tools/write.d.ts +3 -0
- package/dist/tools/write.js +6 -2
- package/dist/tui/cli.d.ts +6 -6
- package/dist/tui/cli.js +120 -28
- package/dist/tui/client.d.ts +7 -0
- package/dist/tui/client.js +67 -16
- package/dist/tui/frontend.d.ts +2 -0
- package/dist/tui/pitui-frontend.d.ts +4 -0
- package/dist/tui/pitui-frontend.js +27 -0
- package/dist/tui/render.d.ts +1 -0
- package/dist/tui/render.js +5 -0
- package/dist/tui/session.js +6 -0
- package/dist/usage/ledger.d.ts +1 -1
- package/dist/usage/render.js +1 -1
- package/dist/web/client.d.ts +1 -0
- package/dist/web/client.js +11 -0
- package/dist/web/fetch.js +6 -3
- package/dist/webapi/auth.d.ts +0 -3
- package/dist/webapi/auth.js +3 -7
- package/dist/webapi/config.js +17 -14
- package/dist/webapi/key-command.js +41 -41
- package/dist/webapi/response-state.d.ts +7 -1
- package/dist/webapi/response-state.js +166 -3
- package/dist/webapi/routes/websocket.js +24 -1
- package/dist/webapi/server.d.ts +3 -1
- package/dist/webapi/server.js +32 -1
- package/dist/webapi/service.js +8 -0
- package/dist/webapi/transport.d.ts +2 -0
- package/dist/webapi/transport.js +11 -1
- package/examples/sub-agents/README.md +43 -75
- package/examples/sub-agents/agy-main.md +21 -0
- package/examples/sub-agents/claude-high.md +21 -0
- package/examples/sub-agents/claude-main.md +21 -0
- package/examples/sub-agents/codex-flash.md +21 -0
- package/examples/sub-agents/codex-high.md +21 -0
- package/examples/sub-agents/codex-main.md +21 -0
- package/examples/sub-agents/codex-review.md +20 -0
- package/examples/sub-agents/cursor-high.md +20 -0
- package/examples/sub-agents/cursor-main.md +20 -0
- package/examples/sub-agents/glm-flash.md +21 -0
- package/examples/sub-agents/glm-high.md +21 -0
- package/examples/sub-agents/pi-scout.md +20 -0
- package/package.json +11 -12
- package/dist/agent/session/request-tools.d.ts +0 -3
- package/dist/agent/session/request-tools.js +0 -20
- package/dist/models/api-keys.d.ts +0 -11
- package/dist/models/api-keys.js +0 -22
- package/dist/playbooks/memory-and-learning.md +0 -55
- package/examples/sub-agents/agents/claude-high.md +0 -23
- package/examples/sub-agents/agents/claude-main.md +0 -23
- package/examples/sub-agents/agents/codex-flash.md +0 -23
- package/examples/sub-agents/agents/codex-high.md +0 -23
- package/examples/sub-agents/agents/codex-main.md +0 -23
- package/examples/sub-agents/agents/codex-review.md +0 -23
- package/examples/sub-agents/agents/cursor-high.md +0 -22
- package/examples/sub-agents/agents/cursor-main.md +0 -22
- package/examples/sub-agents/agents/glm-flash.md +0 -23
- package/examples/sub-agents/agents/glm-high.md +0 -23
- package/examples/sub-agents/agents/scout.md +0 -30
- package/examples/sub-agents/roles/builder-hard.md +0 -34
- package/examples/sub-agents/roles/builder.md +0 -34
- package/examples/sub-agents/roles/explorer.md +0 -39
- package/examples/sub-agents/roles/git-committer.md +0 -43
- package/examples/sub-agents/roles/planner.md +0 -33
- package/examples/sub-agents/roles/reviewer.md +0 -33
- package/examples/sub-agents/roles/verifier.md +0 -35
- package/examples/sub-agents/roles/worker.md +0 -34
|
@@ -8,7 +8,9 @@ import { taskReportDelivered } from "../tasks/completion.js";
|
|
|
8
8
|
import { drainTaskDeliveries, queueTaskReport } from "../tasks/delivery.js";
|
|
9
9
|
import { acknowledgeTaskInputs, taskInputTag } from "../tasks/input-receipts.js";
|
|
10
10
|
import { readTaskLog } from "../tasks/loop-log.js";
|
|
11
|
+
import { reportReceipt } from "../tasks/receipts.js";
|
|
11
12
|
import { beginStep, endStep, pauseTask, readStoredTask } from "../tasks/store.js";
|
|
13
|
+
import { canDeliverToChannel, } from "./task-lane-types.js";
|
|
12
14
|
import { listPendingWork } from "./task-pending.js";
|
|
13
15
|
/** A task step speaks to nobody: only `task_report`, `task_ask` and the lane's receipts reach a channel (INV-1). */
|
|
14
16
|
const SILENT_CONTEXT = { emit: () => undefined, finish: async () => undefined };
|
|
@@ -31,8 +33,8 @@ function sessionContextOf(ctx, live) {
|
|
|
31
33
|
},
|
|
32
34
|
report: async (text) => {
|
|
33
35
|
assertActive();
|
|
34
|
-
const message = await queueTaskReport(live.deskDir, live.taskId, live.seq, live.channelId, text);
|
|
35
|
-
await drainTaskDeliveries(live.deskDir, (channel, text) => ctx.options.deliver(live.desk, channel, text), (channel) => ctx
|
|
36
|
+
const message = await queueTaskReport(live.deskDir, live.taskId, live.seq, live.channelId, reportReceipt(live.taskId, text));
|
|
37
|
+
await drainTaskDeliveries(live.deskDir, (channel, text) => ctx.options.deliver(live.desk, channel, text), (channel) => canDeliverToChannel(ctx, live.desk, channel), ctx.now());
|
|
36
38
|
ctx.notify();
|
|
37
39
|
return {
|
|
38
40
|
id: message.id,
|
|
@@ -41,10 +43,20 @@ function sessionContextOf(ctx, live) {
|
|
|
41
43
|
},
|
|
42
44
|
};
|
|
43
45
|
}
|
|
44
|
-
/** The task's runner, built on first use and kept until the task leaves execution (D13). */
|
|
45
|
-
export function ensureRunner(ctx, live) {
|
|
46
|
-
if (live.runner)
|
|
47
|
-
|
|
46
|
+
/** The task's runner, built on first use and kept until the task leaves execution (D13) or the desk's cwd changes. */
|
|
47
|
+
export async function ensureRunner(ctx, live) {
|
|
48
|
+
if (live.runner) {
|
|
49
|
+
const currentCwd = ctx.options.getDeskCwd?.(live.desk, live.channelId);
|
|
50
|
+
if (!currentCwd || live.runner.conversation.cwd === currentCwd)
|
|
51
|
+
return live.runner;
|
|
52
|
+
const stale = live.runner;
|
|
53
|
+
live.runner = undefined;
|
|
54
|
+
await stale.dispose().catch((disposeErr) => log.logWarn("tasks.runner.dispose_failed", "Stale task runner dispose failed", {
|
|
55
|
+
channelId: live.channelId,
|
|
56
|
+
reason: errorMessage(disposeErr),
|
|
57
|
+
fields: { taskId: live.taskId, desk: live.desk },
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
48
60
|
live.runner = ctx.options.createTaskRunner({
|
|
49
61
|
desk: live.desk,
|
|
50
62
|
deskDir: live.deskDir,
|
|
@@ -69,13 +81,15 @@ export function abortStep(ctx, live, reason) {
|
|
|
69
81
|
if (live.step !== step)
|
|
70
82
|
return;
|
|
71
83
|
live.quarantined = true;
|
|
84
|
+
if (live.runner === runner)
|
|
85
|
+
live.runner = undefined;
|
|
72
86
|
runner.retireForRecovery();
|
|
73
|
-
|
|
87
|
+
step.quarantining = pauseTask(live.deskDir, live.taskId, {
|
|
74
88
|
by: "runtime",
|
|
75
|
-
reason: "
|
|
89
|
+
reason: "当前步骤未能及时停止,已暂停后续执行;待该步退出后可用 /tasks resume 恢复,持续卡死时请重启服务",
|
|
76
90
|
})
|
|
77
91
|
.then(async () => {
|
|
78
|
-
await ctx.options.deliver(live.desk, live.channelId, `⚠️ 任务 \`${live.taskId}\`
|
|
92
|
+
await ctx.options.deliver(live.desk, live.channelId, `⚠️ 任务 \`${live.taskId}\` 的当前步骤未能及时停止,已暂停后续执行。待当前步骤退出后可用 \`/tasks resume ${live.taskId}\` 恢复;若持续未退出请联系部署者重启服务。`);
|
|
79
93
|
})
|
|
80
94
|
.catch((error) => log.logWarn("tasks.step.quarantine_failed", "Task step quarantine failed", {
|
|
81
95
|
reason: errorMessage(error),
|
|
@@ -111,17 +125,13 @@ export async function executeStep(ctx, live) {
|
|
|
111
125
|
if (!document || document.fields.outcome)
|
|
112
126
|
return { kind: "skipped" };
|
|
113
127
|
await acknowledgeTaskInputs(live.deskDir, live.taskId);
|
|
114
|
-
const runner = ensureRunner(ctx, live);
|
|
128
|
+
const runner = await ensureRunner(ctx, live);
|
|
115
129
|
// Whether the session still holds the current contract is read from the session itself, so a
|
|
116
130
|
// compaction that dropped it, or an edit that changed it, brings the full brief back (D15).
|
|
117
131
|
const full = !(await runner.contextIncludes(contractOpenTag(live.taskId, contractSha(document.body))));
|
|
118
132
|
const begun = await beginStep(live.deskDir, live.taskId, {
|
|
119
133
|
brief: full ? "full" : "delta",
|
|
120
|
-
allowed: (fields) => !ctx.isStopped() &&
|
|
121
|
-
options.isEnabled?.() !== false &&
|
|
122
|
-
!!fields.channel &&
|
|
123
|
-
options.isBoundTo(fields.channel, live.desk) &&
|
|
124
|
-
options.isReachable(fields.channel),
|
|
134
|
+
allowed: (fields) => !ctx.isStopped() && options.isEnabled?.() !== false && !!fields.channel && options.isReachable(fields.channel),
|
|
125
135
|
});
|
|
126
136
|
if (!begun)
|
|
127
137
|
return { kind: "skipped" };
|
|
@@ -181,7 +191,7 @@ export async function executeStep(ctx, live) {
|
|
|
181
191
|
let usdEstimated = false;
|
|
182
192
|
let usdKnown = false;
|
|
183
193
|
try {
|
|
184
|
-
const running = runner.run(info, SILENT_CONTEXT, options.store);
|
|
194
|
+
const running = runner.run(info, SILENT_CONTEXT, options.store, full ? undefined : brief.contract);
|
|
185
195
|
ctx.inputAvailable(live.desk, live.taskId);
|
|
186
196
|
const run = await running;
|
|
187
197
|
finalText = run.finalText ?? "";
|
|
@@ -209,6 +219,7 @@ export async function executeStep(ctx, live) {
|
|
|
209
219
|
}
|
|
210
220
|
step.ending = true;
|
|
211
221
|
await step.submitting;
|
|
222
|
+
await step.quarantining;
|
|
212
223
|
// Only this task step can own the SDK queue here; the next step has not started.
|
|
213
224
|
runner.clearTaskStepQueue?.(step.seq);
|
|
214
225
|
await acknowledgeTaskInputs(live.deskDir, live.taskId, {
|
|
@@ -217,6 +228,13 @@ export async function executeStep(ctx, live) {
|
|
|
217
228
|
generation: runner.generation,
|
|
218
229
|
});
|
|
219
230
|
live.step = undefined;
|
|
231
|
+
if (live.runner !== runner) {
|
|
232
|
+
await runner.dispose().catch((disposeErr) => log.logWarn("tasks.runner.dispose_failed", "Retired task runner dispose failed", {
|
|
233
|
+
channelId: live.channelId,
|
|
234
|
+
reason: errorMessage(disposeErr),
|
|
235
|
+
fields: { taskId: live.taskId, desk: live.desk },
|
|
236
|
+
}));
|
|
237
|
+
}
|
|
220
238
|
// A stop from the lane decides the result whatever the turn reported on its way out.
|
|
221
239
|
switch (step.abort) {
|
|
222
240
|
case "shutdown":
|
|
@@ -53,7 +53,7 @@ export async function loadTransports(deps) {
|
|
|
53
53
|
}
|
|
54
54
|
catch (error) {
|
|
55
55
|
if (!(error instanceof ChannelConfigError)) {
|
|
56
|
-
throw new StartupRefusal(
|
|
56
|
+
throw new StartupRefusal(`无法读取渠道配置文件 ${channelConfigPath}:${errorMessage(error)}`);
|
|
57
57
|
}
|
|
58
58
|
throw new StartupRefusal(configurationRefusal(channelConfigPath, appName, error.issues));
|
|
59
59
|
}
|
|
@@ -76,6 +76,7 @@ export async function loadTransports(deps) {
|
|
|
76
76
|
transports.push(new WebApiTransport({
|
|
77
77
|
config: parseWebApiConfig(sections.webapi),
|
|
78
78
|
stateDir: join(deps.stateDir, "webapi"),
|
|
79
|
+
channelConfigPath,
|
|
79
80
|
audit: deps.audit,
|
|
80
81
|
}));
|
|
81
82
|
}
|
|
@@ -86,16 +87,16 @@ export async function loadTransports(deps) {
|
|
|
86
87
|
throw new StartupRefusal(configurationRefusal(channelConfigPath, appName, error.issues));
|
|
87
88
|
}
|
|
88
89
|
if (transports.length === 0) {
|
|
89
|
-
throw new StartupRefusal(
|
|
90
|
+
throw new StartupRefusal(`${channelConfigPath} 中未启用任何渠道。请将 \`webapi.enabled\` 或 \`dingtalk.enabled\` 设为 true 后重新运行 \`${appName}\`。\n配置文档:${docsUrl("configuration.md")}`);
|
|
90
91
|
}
|
|
91
92
|
return transports;
|
|
92
93
|
}
|
|
93
94
|
function configurationRefusal(path, appName, issues) {
|
|
94
95
|
return [
|
|
95
|
-
|
|
96
|
+
`渠道配置尚未就绪(${path}):`,
|
|
96
97
|
...issues.map((issue) => ` - ${issue}`),
|
|
97
98
|
"",
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
`请修正 ${path} 后重新运行 \`${appName}\`。`,
|
|
100
|
+
`配置文档:${docsUrl("configuration.md")}`,
|
|
100
101
|
].join("\n");
|
|
101
102
|
}
|
package/dist/runtime/turn-run.js
CHANGED
|
@@ -54,6 +54,18 @@ function turnInfoOf(event) {
|
|
|
54
54
|
*/
|
|
55
55
|
export function createEventTurnRunner(deps) {
|
|
56
56
|
const { transports, store, activeTasks, archiveIncomingMessage, getRunner, isShuttingDown, getDurableDispatch } = deps;
|
|
57
|
+
const reportDispatchFailure = (phase, event, dispatchId, operation, error) => {
|
|
58
|
+
log.logWarn(`dispatch.turn.${phase}_failed`, phase === "admit" ? "Wake admission failed" : "Wake settlement failed", {
|
|
59
|
+
channelId: event.channelId,
|
|
60
|
+
reason: errorMessage(error),
|
|
61
|
+
fields: {
|
|
62
|
+
dispatchId,
|
|
63
|
+
primaryDispatchId: event.dispatchId,
|
|
64
|
+
operation,
|
|
65
|
+
code: error?.code,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
};
|
|
57
69
|
/**
|
|
58
70
|
* Dispatch admission: refuse a stale redelivery of a wake an earlier turn already handled (the
|
|
59
71
|
* turn is released), and fold other pending completion wakes into this one. `undefined` = skip.
|
|
@@ -61,42 +73,54 @@ export function createEventTurnRunner(deps) {
|
|
|
61
73
|
const admitTurn = async (inboundEvent, runner) => {
|
|
62
74
|
let event = inboundEvent;
|
|
63
75
|
const durable = getDurableDispatch();
|
|
64
|
-
// Sampled synchronously, before any await: `/stop` after this point cleared the queued closures.
|
|
65
76
|
const stopEpoch = durable?.stopEpoch(inboundEvent.channelId) ?? 0;
|
|
77
|
+
const claimedIds = [];
|
|
78
|
+
let operation = "markStarted";
|
|
79
|
+
let admitted = false;
|
|
66
80
|
deps.reservedTurns.delete(inboundEvent);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
81
|
+
try {
|
|
82
|
+
if (durable && !(await durable.markStarted(event.dispatchId)))
|
|
83
|
+
return undefined;
|
|
84
|
+
if (durable && event.dispatchId)
|
|
85
|
+
claimedIds.push(event.dispatchId);
|
|
86
|
+
let absorbedDispatchIds = [];
|
|
87
|
+
if (durable && event.source === "wake" && event.dispatchId && isCoalescableWake(event)) {
|
|
88
|
+
operation = "absorbPending";
|
|
89
|
+
const primary = event;
|
|
90
|
+
const absorbed = await durable.absorbPending(event.channelId, event.dispatchId, (candidate) => canAbsorbWake(primary, candidate), MAX_COALESCED_WAKES - 1, stopEpoch);
|
|
91
|
+
absorbedDispatchIds = absorbed.flatMap((item) => (item.dispatchId ? [item.dispatchId] : []));
|
|
92
|
+
claimedIds.push(...absorbedDispatchIds);
|
|
93
|
+
if (absorbed.length > 0) {
|
|
94
|
+
event = mergeCompletionWakes(event, absorbed);
|
|
95
|
+
log.logInfoEvent("dispatch.wake.coalesced", "Completion wakes coalesced", {
|
|
96
|
+
channelId: event.channelId,
|
|
97
|
+
fields: { primary: event.dispatchId, absorbed: absorbedDispatchIds.length },
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
admitted = true;
|
|
102
|
+
return { event, output: undefined, absorbedDispatchIds, mergedWakesHandled: false, threw: false };
|
|
71
103
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
event = mergeCompletionWakes(event, absorbed);
|
|
86
|
-
absorbedDispatchIds = absorbed.flatMap((absorbedEvent) => absorbedEvent.dispatchId ? [absorbedEvent.dispatchId] : []);
|
|
87
|
-
log.logInfoEvent("dispatch.wake.coalesced", "Completion wakes coalesced", {
|
|
88
|
-
channelId: event.channelId,
|
|
89
|
-
fields: { primary: event.dispatchId, absorbed: absorbedDispatchIds.length },
|
|
90
|
-
});
|
|
104
|
+
catch (error) {
|
|
105
|
+
reportDispatchFailure("admit", inboundEvent, inboundEvent.dispatchId, operation, error);
|
|
106
|
+
// Admission never reached execution. Release successful claims for redelivery, not
|
|
107
|
+
// completion. A failed rollback keeps its original record and is diagnosed separately.
|
|
108
|
+
for (const id of claimedIds) {
|
|
109
|
+
if (!deps.isCurrentRunner(runner))
|
|
110
|
+
break;
|
|
111
|
+
try {
|
|
112
|
+
await durable?.markRetryable(id);
|
|
113
|
+
}
|
|
114
|
+
catch (retryError) {
|
|
115
|
+
reportDispatchFailure("settle", inboundEvent, id, "markRetryable", retryError);
|
|
116
|
+
}
|
|
91
117
|
}
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
if (!admitted)
|
|
122
|
+
runner.endTurn();
|
|
92
123
|
}
|
|
93
|
-
return {
|
|
94
|
-
event,
|
|
95
|
-
output: undefined,
|
|
96
|
-
absorbedDispatchIds,
|
|
97
|
-
mergedWakesHandled: false,
|
|
98
|
-
threw: false,
|
|
99
|
-
};
|
|
100
124
|
};
|
|
101
125
|
/** Say something to the channel in answer to `event`, carrying its reference back to the transport. */
|
|
102
126
|
const replyTo = (transport, event, text, opts) => transport.push(event.channelId, {
|
|
@@ -215,45 +239,58 @@ export function createEventTurnRunner(deps) {
|
|
|
215
239
|
/** Always runs: finish the output, settle the dispatch records, release the turn. */
|
|
216
240
|
const finishTurn = async (turn, runner) => {
|
|
217
241
|
const { event } = turn;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
242
|
+
const errors = [];
|
|
243
|
+
const settle = async (id, operation) => {
|
|
244
|
+
if (!deps.isCurrentRunner(runner))
|
|
245
|
+
return;
|
|
246
|
+
try {
|
|
247
|
+
await getDurableDispatch()?.[operation](id);
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
errors.push(error);
|
|
251
|
+
reportDispatchFailure("settle", event, id, operation, error);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
try {
|
|
255
|
+
// The runner finishes the output when it runs; a command, or a turn that failed before the
|
|
256
|
+
// runner took over, finishes here so the transport never keeps one open. A human message that
|
|
257
|
+
// threw before any output was opened still gets one, so its transport sees it end.
|
|
258
|
+
if (!turn.output && turn.threw && event.source === "human") {
|
|
259
|
+
const transport = transports.forChannel(event.channelId);
|
|
260
|
+
if (transport)
|
|
261
|
+
turn.output = trackOutput(transport.openTurn(turnInfoOf(event), { quiet: true }));
|
|
262
|
+
}
|
|
263
|
+
if (turn.output && !turn.output.finished) {
|
|
264
|
+
const outcome = turn.threw
|
|
265
|
+
? {
|
|
266
|
+
kind: "failed",
|
|
267
|
+
message: TURN_FAILED_MESSAGE,
|
|
268
|
+
usage: createEmptyUsageTotals(),
|
|
269
|
+
executionDesk: runner.conversation.desk,
|
|
270
|
+
}
|
|
271
|
+
: { kind: "completed", usage: createEmptyUsageTotals(), executionDesk: runner.conversation.desk };
|
|
272
|
+
await turn.output.ctx.finish(outcome).catch((error) => {
|
|
273
|
+
log.logWarn("delivery.close.failed", "Delivery close failed", {
|
|
274
|
+
channelId: event.channelId,
|
|
275
|
+
reason: errorMessage(error),
|
|
276
|
+
});
|
|
239
277
|
});
|
|
240
|
-
}
|
|
278
|
+
}
|
|
279
|
+
if (!deps.isCurrentRunner(runner))
|
|
280
|
+
return;
|
|
281
|
+
await settle(event.dispatchId, "markCompleted");
|
|
282
|
+
// Failure of one record must not strand later absorbed claims. Re-check ownership
|
|
283
|
+
// before each await: /new or watchdog recovery may replace the runner meanwhile.
|
|
284
|
+
const stopped = !turn.mergedWakesHandled || runner.getTurnStatus().stopRequested;
|
|
285
|
+
for (const id of turn.absorbedDispatchIds)
|
|
286
|
+
await settle(id, stopped ? "markRetryable" : "markCompleted");
|
|
287
|
+
if (errors.length)
|
|
288
|
+
throw new AggregateError(errors, "Durable wake settlement failed; inspect the logged dispatch ids and storage errors before retrying.");
|
|
241
289
|
}
|
|
242
|
-
|
|
290
|
+
finally {
|
|
291
|
+
// Release the captured runner, never whichever generation now owns the channel.
|
|
243
292
|
runner.endTurn();
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
await getDurableDispatch()?.markCompleted(event.dispatchId);
|
|
247
|
-
// A stopped turn has not finished handling its merged notifications. Release their
|
|
248
|
-
// claims even if /stop's asynchronous cancelChannel reset raced admission or failed.
|
|
249
|
-
const stopped = !turn.mergedWakesHandled || runner.getTurnStatus().stopRequested;
|
|
250
|
-
for (const absorbedId of turn.absorbedDispatchIds) {
|
|
251
|
-
if (stopped)
|
|
252
|
-
await getDurableDispatch()?.markRetryable(absorbedId);
|
|
253
|
-
else
|
|
254
|
-
await getDurableDispatch()?.markCompleted(absorbedId);
|
|
255
293
|
}
|
|
256
|
-
runner.endTurn();
|
|
257
294
|
};
|
|
258
295
|
/** Release a turn `reserveEvent` began for an event that admission then refused. */
|
|
259
296
|
const releaseReservation = (event) => {
|
|
@@ -4,8 +4,8 @@ interface ParsedCommand {
|
|
|
4
4
|
args: string[];
|
|
5
5
|
normalized: string;
|
|
6
6
|
}
|
|
7
|
-
declare function splitCommandChain(command: string): string[];
|
|
8
7
|
declare function parseShellWords(command: string): string[];
|
|
8
|
+
declare function splitCommandChain(command: string): string[];
|
|
9
9
|
declare function parseCommand(command: string): ParsedCommand | null;
|
|
10
10
|
export declare function guardCommand(command: string, config: SecurityConfig["commandGuard"]): CommandGuardResult;
|
|
11
11
|
export declare const internalCommandGuard: {
|