@oyasmi/pipiclaw 0.9.5-beta.2 → 0.9.5-beta.4
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 +9 -11
- package/README.md +9 -11
- package/dist/agent/channel-runner.d.ts +12 -24
- package/dist/agent/channel-runner.js +74 -30
- package/dist/agent/maintenance-context.d.ts +2 -0
- package/dist/agent/maintenance-context.js +15 -0
- package/dist/agent/prompt/sections.js +8 -6
- package/dist/agent/prompt/types.d.ts +1 -1
- package/dist/agent/runner-factory.js +1 -1
- package/dist/agent/session/command-extension.js +11 -0
- package/dist/agent/session/compaction-summary.js +6 -2
- package/dist/agent/session/execution-trace.d.ts +14 -0
- package/dist/agent/session/execution-trace.js +57 -0
- package/dist/agent/session/session-events.d.ts +2 -7
- package/dist/agent/session/session-events.js +35 -12
- package/dist/agent/session/session-host.d.ts +12 -22
- package/dist/agent/session/session-host.js +46 -65
- package/dist/agent/turn/task-digest.d.ts +1 -2
- package/dist/agent/turn/task-digest.js +33 -33
- package/dist/agent/turn/turn-context.d.ts +1 -1
- package/dist/agent/turn/turn-context.js +1 -1
- package/dist/agent/turn/turn-finish.d.ts +2 -2
- package/dist/agent/turn/turn-finish.js +3 -2
- package/dist/agent/turn/turn-pipeline.d.ts +4 -2
- package/dist/agent/turn/turn-pipeline.js +33 -5
- package/dist/agent/types.d.ts +64 -14
- package/dist/agent/types.js +3 -0
- package/dist/app/home.js +3 -4
- package/dist/channel/channel-event.d.ts +4 -12
- package/dist/channel/ingress.d.ts +1 -9
- package/dist/channel/store.d.ts +1 -1
- package/dist/commands/catalog.js +25 -19
- package/dist/commands/router.d.ts +5 -2
- package/dist/commands/router.js +9 -4
- package/dist/config/settings.d.ts +5 -12
- package/dist/config/settings.js +0 -7
- package/dist/config/tools.d.ts +2 -2
- package/dist/config/tools.js +2 -2
- package/dist/dingtalk/bot.d.ts +2 -0
- package/dist/dingtalk/bot.js +4 -0
- package/dist/dingtalk/cards.d.ts +7 -0
- package/dist/dingtalk/cards.js +32 -2
- package/dist/dingtalk/delivery.d.ts +4 -1
- package/dist/dingtalk/delivery.js +104 -191
- package/dist/dingtalk/progress.d.ts +41 -6
- package/dist/dingtalk/progress.js +173 -16
- package/dist/file-store.d.ts +4 -0
- package/dist/file-store.js +6 -1
- package/dist/jobs/completion-observer.d.ts +20 -0
- package/dist/jobs/completion-observer.js +107 -0
- package/dist/jobs/completion-signal.d.ts +9 -0
- package/dist/jobs/completion-signal.js +32 -0
- package/dist/jobs/completion-wake.d.ts +1 -1
- package/dist/jobs/completion-wake.js +2 -13
- package/dist/jobs/manager.d.ts +11 -29
- package/dist/jobs/manager.js +103 -176
- package/dist/jobs/probe.d.ts +3 -0
- package/dist/jobs/probe.js +42 -0
- package/dist/jobs/record.d.ts +3 -6
- package/dist/jobs/runtime.d.ts +28 -0
- package/dist/jobs/runtime.js +69 -0
- package/dist/memory/boundary-work.d.ts +2 -0
- package/dist/memory/boundary-work.js +79 -37
- package/dist/memory/commands.js +4 -1
- package/dist/memory/index-budget.js +18 -15
- package/dist/memory/journal.js +2 -1
- package/dist/memory/lifecycle.d.ts +4 -8
- package/dist/memory/lifecycle.js +21 -51
- package/dist/memory/reflect-job.d.ts +0 -6
- package/dist/memory/reflect-job.js +13 -34
- package/dist/memory/reflect.d.ts +4 -0
- package/dist/memory/reflect.js +32 -5
- package/dist/memory/review-log.d.ts +13 -0
- package/dist/memory/review-log.js +49 -0
- package/dist/memory/search.js +7 -4
- package/dist/memory/source-window.d.ts +18 -1
- package/dist/memory/source-window.js +59 -9
- package/dist/memory/store.d.ts +2 -0
- package/dist/memory/store.js +45 -13
- package/dist/playbooks/agent-delegation.md +10 -4
- package/dist/playbooks/background-jobs.md +4 -4
- package/dist/playbooks/event-scheduling.md +2 -2
- package/dist/playbooks/memory-and-learning.md +3 -3
- package/dist/playbooks/outbound-media.md +2 -2
- package/dist/playbooks/runtime-orientation.md +10 -6
- package/dist/playbooks/task-lead.md +54 -33
- package/dist/runtime/bootstrap.d.ts +11 -24
- package/dist/runtime/bootstrap.js +92 -59
- package/dist/runtime/channel-queue.d.ts +2 -0
- package/dist/runtime/channel-queue.js +5 -1
- package/dist/runtime/durable-dispatch.d.ts +7 -0
- package/dist/runtime/durable-dispatch.js +66 -7
- package/dist/runtime/ingress-busy.d.ts +1 -2
- package/dist/runtime/ingress-busy.js +2 -35
- package/dist/runtime/ingress-commands.d.ts +1 -1
- package/dist/runtime/ingress-commands.js +28 -20
- package/dist/runtime/ingress-deps.d.ts +4 -7
- package/dist/runtime/ingress.js +23 -13
- package/dist/runtime/shutdown.d.ts +1 -1
- package/dist/runtime/shutdown.js +2 -2
- package/dist/runtime/task-close.d.ts +4 -0
- package/dist/runtime/task-close.js +102 -0
- package/dist/runtime/task-control.d.ts +34 -0
- package/dist/runtime/task-control.js +225 -0
- package/dist/runtime/task-input.d.ts +13 -0
- package/dist/runtime/task-input.js +129 -0
- package/dist/runtime/task-lane-types.d.ts +123 -0
- package/dist/runtime/task-lane-types.js +14 -0
- package/dist/runtime/task-lane.d.ts +99 -0
- package/dist/runtime/task-lane.js +703 -0
- package/dist/runtime/task-pending.d.ts +8 -0
- package/dist/runtime/task-pending.js +40 -0
- package/dist/runtime/task-spawn.d.ts +4 -4
- package/dist/runtime/task-spawn.js +4 -4
- package/dist/runtime/task-step.d.ts +32 -0
- package/dist/runtime/task-step.js +276 -0
- package/dist/runtime/turn-run.d.ts +4 -16
- package/dist/runtime/turn-run.js +17 -155
- package/dist/runtime/wake-coalescing.d.ts +1 -3
- package/dist/runtime/wake-coalescing.js +2 -4
- package/dist/shared/format.d.ts +0 -6
- package/dist/shared/format.js +0 -17
- package/dist/shared/host-process.d.ts +2 -0
- package/dist/shared/host-process.js +16 -1
- package/dist/shared/jsonl-appender.d.ts +5 -0
- package/dist/shared/jsonl-appender.js +25 -2
- package/dist/skills/catalog.d.ts +9 -0
- package/dist/skills/catalog.js +34 -0
- package/dist/skills/commands.d.ts +3 -12
- package/dist/skills/commands.js +36 -22
- package/dist/skills/loader.d.ts +2 -31
- package/dist/skills/loader.js +101 -68
- package/dist/skills/roots.d.ts +12 -0
- package/dist/skills/roots.js +18 -0
- package/dist/skills/types.d.ts +24 -0
- package/dist/skills/types.js +1 -0
- package/dist/subagents/completion-wake.js +0 -10
- package/dist/subagents/discovery.d.ts +1 -1
- package/dist/subagents/discovery.js +10 -16
- package/dist/subagents/dispatch.js +8 -16
- package/dist/subagents/external/cursor-cli.d.ts +2 -0
- package/dist/subagents/external/cursor-cli.js +256 -0
- package/dist/subagents/external/harness.d.ts +5 -5
- package/dist/subagents/external/reconciliation.d.ts +7 -0
- package/dist/subagents/external/reconciliation.js +105 -0
- package/dist/subagents/external/recovery.d.ts +20 -0
- package/dist/subagents/external/recovery.js +71 -0
- package/dist/subagents/external/registry.js +2 -0
- package/dist/subagents/external/role-warnings.d.ts +17 -0
- package/dist/subagents/external/role-warnings.js +42 -0
- package/dist/subagents/external/run.js +18 -22
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/grace.d.ts +2 -2
- package/dist/subagents/grace.js +3 -3
- package/dist/subagents/internal/run.js +7 -5
- package/dist/subagents/internal/worker.js +31 -2
- package/dist/subagents/result.js +2 -3
- package/dist/subagents/run-record.d.ts +4 -7
- package/dist/subagents/run-record.js +2 -2
- package/dist/subagents/runs.d.ts +33 -46
- package/dist/subagents/runs.js +126 -245
- package/dist/subagents/task-settlement.d.ts +3 -0
- package/dist/subagents/task-settlement.js +20 -0
- package/dist/subagents/types.d.ts +1 -2
- package/dist/subagents/workspace-summary.js +5 -1
- package/dist/tasks/archive.d.ts +11 -0
- package/dist/tasks/archive.js +141 -0
- package/dist/tasks/board.d.ts +5 -12
- package/dist/tasks/board.js +4 -30
- package/dist/tasks/bound-work.d.ts +12 -6
- package/dist/tasks/bound-work.js +37 -24
- package/dist/tasks/brief.d.ts +38 -14
- package/dist/tasks/brief.js +128 -70
- package/dist/tasks/budget.d.ts +3 -3
- package/dist/tasks/budget.js +9 -4
- package/dist/tasks/commands.d.ts +14 -9
- package/dist/tasks/commands.js +190 -121
- package/dist/tasks/completion.d.ts +12 -0
- package/dist/tasks/completion.js +35 -0
- package/dist/tasks/contract.d.ts +8 -17
- package/dist/tasks/contract.js +41 -43
- package/dist/tasks/control.d.ts +138 -0
- package/dist/tasks/control.js +1 -0
- package/dist/tasks/create.d.ts +1 -1
- package/dist/tasks/create.js +3 -3
- package/dist/tasks/delivery.d.ts +24 -0
- package/dist/tasks/delivery.js +221 -0
- package/dist/tasks/file-mutation.d.ts +5 -0
- package/dist/tasks/file-mutation.js +38 -0
- package/dist/tasks/frontmatter.d.ts +43 -28
- package/dist/tasks/frontmatter.js +83 -40
- package/dist/tasks/input-receipts.d.ts +7 -0
- package/dist/tasks/input-receipts.js +60 -0
- package/dist/tasks/loop-log.d.ts +147 -28
- package/dist/tasks/loop-log.js +239 -28
- package/dist/tasks/receipts.d.ts +19 -0
- package/dist/tasks/receipts.js +48 -0
- package/dist/tasks/state.d.ts +93 -0
- package/dist/tasks/state.js +156 -0
- package/dist/tasks/store.d.ts +81 -49
- package/dist/tasks/store.js +244 -147
- package/dist/tools/bash.d.ts +3 -5
- package/dist/tools/bash.js +8 -22
- package/dist/tools/contract/details.d.ts +6 -6
- package/dist/tools/contract/details.js +6 -6
- package/dist/tools/contract/execution-trace.d.ts +4 -0
- package/dist/tools/contract/execution-trace.js +23 -0
- package/dist/tools/contract/presentation.js +6 -2
- package/dist/tools/edit.d.ts +1 -0
- package/dist/tools/edit.js +45 -42
- package/dist/tools/index.d.ts +8 -12
- package/dist/tools/index.js +16 -6
- package/dist/tools/memory-manage.js +8 -1
- package/dist/tools/registry.d.ts +7 -11
- package/dist/tools/registry.js +52 -25
- package/dist/tools/skill.d.ts +2 -2
- package/dist/tools/skill.js +24 -10
- package/dist/tools/subagent-manage.js +7 -4
- package/dist/tools/subagent.d.ts +0 -2
- package/dist/tools/subagent.js +2 -7
- package/dist/tools/task-manage/control-tools.d.ts +4 -0
- package/dist/tools/task-manage/control-tools.js +65 -0
- package/dist/tools/task-manage/create.js +2 -1
- package/dist/tools/task-manage/factory.d.ts +12 -6
- package/dist/tools/task-manage/factory.js +72 -57
- package/dist/tools/task-manage/lifecycle.d.ts +7 -12
- package/dist/tools/task-manage/lifecycle.js +118 -66
- package/dist/tools/task-manage/log-view.js +8 -5
- package/dist/tools/task-manage/schema.d.ts +21 -26
- package/dist/tools/task-manage/schema.js +29 -35
- package/dist/tools/task-manage/shared.d.ts +8 -39
- package/dist/tools/task-manage/shared.js +19 -68
- package/dist/tools/task-manage/step-tools.d.ts +5 -0
- package/dist/tools/task-manage/step-tools.js +103 -0
- package/dist/tools/task-manage/types.d.ts +25 -18
- package/dist/tools/write-content.d.ts +1 -0
- package/dist/tools/write-content.js +6 -1
- package/dist/tools/write.d.ts +1 -0
- package/dist/tools/write.js +1 -0
- package/dist/usage/ledger.d.ts +4 -4
- package/dist/usage/render.js +2 -2
- package/dist/web/search-providers.js +0 -33
- package/dist/webapi/request-policy.js +1 -1
- package/examples/sub-agents/README.md +23 -16
- package/examples/sub-agents/agents/claude-high.md +1 -1
- package/examples/sub-agents/agents/claude-main.md +1 -1
- package/examples/sub-agents/agents/codex-flash.md +1 -1
- package/examples/sub-agents/agents/codex-high.md +1 -1
- package/examples/sub-agents/agents/codex-main.md +4 -4
- package/examples/sub-agents/agents/cursor-high.md +22 -0
- package/examples/sub-agents/agents/cursor-main.md +22 -0
- package/examples/sub-agents/agents/glm-flash.md +1 -1
- package/examples/sub-agents/agents/glm-high.md +2 -2
- package/examples/sub-agents/agents/scout.md +30 -0
- package/package.json +6 -6
- package/dist/runtime/task-driver.d.ts +0 -116
- package/dist/runtime/task-driver.js +0 -443
- package/dist/runtime/task-wake.d.ts +0 -48
- package/dist/runtime/task-wake.js +0 -32
- package/dist/shared/wake-claim.d.ts +0 -23
- package/dist/shared/wake-claim.js +0 -26
- package/dist/skills/validation.d.ts +0 -8
- package/dist/skills/validation.js +0 -91
- package/dist/skills/workspace.d.ts +0 -33
- package/dist/skills/workspace.js +0 -116
- package/dist/tasks/steer.d.ts +0 -8
- package/dist/tasks/steer.js +0 -81
- package/dist/tasks/ticket.d.ts +0 -71
- package/dist/tasks/ticket.js +0 -138
- package/dist/tools/task-manage/step-end.d.ts +0 -11
- package/dist/tools/task-manage/step-end.js +0 -117
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { TaskCancelOutcome, TaskControl, TaskControlOutcome, TaskLiveSnapshot, TaskMessageOutcome } from "../tasks/control.js";
|
|
2
|
+
import type { TaskBudget, TaskFrontmatter } from "../tasks/frontmatter.js";
|
|
3
|
+
import { type LaneContext } from "./task-lane-types.js";
|
|
4
|
+
/** Whether a task's report channel can currently be reached (INV-7). */
|
|
5
|
+
export declare function isFrozen(ctx: LaneContext, desk: string, fields: TaskFrontmatter): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* The chat-facing control surface of the lane (spec 064, D24): every write is made inside the
|
|
8
|
+
* task's own mutation lock (the store's transitions take it), appended to the log before the lane is
|
|
9
|
+
* told, and answered with what actually happened to the task.
|
|
10
|
+
*/
|
|
11
|
+
export declare class LaneControl implements TaskControl {
|
|
12
|
+
private readonly ctx;
|
|
13
|
+
constructor(ctx: LaneContext);
|
|
14
|
+
isRunning(desk: string, id: string): boolean;
|
|
15
|
+
created(): void;
|
|
16
|
+
snapshot(desk: string, id?: string): Promise<TaskLiveSnapshot[]>;
|
|
17
|
+
message(desk: string, id: string, input: {
|
|
18
|
+
from: string;
|
|
19
|
+
channel: string;
|
|
20
|
+
text: string;
|
|
21
|
+
}): Promise<TaskMessageOutcome>;
|
|
22
|
+
pause(desk: string, id: string, input: {
|
|
23
|
+
by: "user";
|
|
24
|
+
reason: string;
|
|
25
|
+
}): Promise<TaskControlOutcome>;
|
|
26
|
+
resume(desk: string, id: string, grants: Partial<TaskBudget>): Promise<TaskControlOutcome>;
|
|
27
|
+
cancel(desk: string, id: string, input: {
|
|
28
|
+
by: "user";
|
|
29
|
+
note: string;
|
|
30
|
+
channel?: string;
|
|
31
|
+
}): Promise<TaskCancelOutcome>;
|
|
32
|
+
/** Cancel every delegation and job bound to the task; the refs that were still running. */
|
|
33
|
+
cancelBoundWork(desk: string, taskId: string): Promise<string[]>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import * as log from "../log.js";
|
|
2
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
3
|
+
import { withTimeout } from "../shared/with-timeout.js";
|
|
4
|
+
import { isTaskArchiving } from "../tasks/archive.js";
|
|
5
|
+
import { pendingTaskClose } from "../tasks/completion.js";
|
|
6
|
+
import { extractTaskTitle, readActiveTasks } from "../tasks/contract.js";
|
|
7
|
+
import { drainTaskDeliveries } from "../tasks/delivery.js";
|
|
8
|
+
import { taskInputTag } from "../tasks/input-receipts.js";
|
|
9
|
+
import { appendTaskLog, readTaskLog } from "../tasks/loop-log.js";
|
|
10
|
+
import { withTaskMutation } from "../tasks/mutation-lock.js";
|
|
11
|
+
import { cancelledByUserReceipt } from "../tasks/receipts.js";
|
|
12
|
+
import { closeTask as closeStoredTask, pauseTask as pauseStoredTask, readStoredTask, resumeTask as resumeStoredTask, tasksDir, } from "../tasks/store.js";
|
|
13
|
+
import { describeToolCall } from "../tools/contract/presentation.js";
|
|
14
|
+
import { submitTaskInput } from "./task-input.js";
|
|
15
|
+
import { taskKey } from "./task-lane-types.js";
|
|
16
|
+
import { listPendingWork } from "./task-pending.js";
|
|
17
|
+
import { abortStep } from "./task-step.js";
|
|
18
|
+
/** Whether a task's report channel can currently be reached (INV-7). */
|
|
19
|
+
export function isFrozen(ctx, desk, fields) {
|
|
20
|
+
const channel = fields.channel;
|
|
21
|
+
return !channel || !ctx.options.isBoundTo(channel, desk) || !ctx.options.isReachable(channel);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The chat-facing control surface of the lane (spec 064, D24): every write is made inside the
|
|
25
|
+
* task's own mutation lock (the store's transitions take it), appended to the log before the lane is
|
|
26
|
+
* told, and answered with what actually happened to the task.
|
|
27
|
+
*/
|
|
28
|
+
export class LaneControl {
|
|
29
|
+
constructor(ctx) {
|
|
30
|
+
this.ctx = ctx;
|
|
31
|
+
}
|
|
32
|
+
isRunning(desk, id) {
|
|
33
|
+
return this.ctx.live.get(taskKey(desk, id))?.driving ?? false;
|
|
34
|
+
}
|
|
35
|
+
created() {
|
|
36
|
+
this.ctx.notify();
|
|
37
|
+
}
|
|
38
|
+
async snapshot(desk, id) {
|
|
39
|
+
const { ctx } = this;
|
|
40
|
+
const deskDir = ctx.options.getDeskDir(desk);
|
|
41
|
+
if (!deskDir)
|
|
42
|
+
return [];
|
|
43
|
+
const now = ctx.now();
|
|
44
|
+
const entries = (await readActiveTasks(tasksDir(deskDir))).filter((entry) => !entry.fields.outcome && (id === undefined || entry.id === id));
|
|
45
|
+
if (entries.length === 0)
|
|
46
|
+
return [];
|
|
47
|
+
const pending = await listPendingWork(ctx.options, desk, now, true);
|
|
48
|
+
return Promise.all(entries.map(async (entry) => {
|
|
49
|
+
const live = ctx.live.get(taskKey(desk, entry.id));
|
|
50
|
+
const activity = live?.runner?.getActivity();
|
|
51
|
+
const current = activity?.pendingTools[0];
|
|
52
|
+
return {
|
|
53
|
+
id: entry.id,
|
|
54
|
+
state: entry.fields.state,
|
|
55
|
+
...(entry.fields.waiting ? { waiting: entry.fields.waiting } : {}),
|
|
56
|
+
frozen: isFrozen(ctx, desk, entry.fields),
|
|
57
|
+
closing: isTaskArchiving(deskDir, entry.id) ||
|
|
58
|
+
(entry.fields.state !== "paused" && !!pendingTaskClose(await readTaskLog(deskDir, entry.id))),
|
|
59
|
+
...(live?.step
|
|
60
|
+
? {
|
|
61
|
+
step: {
|
|
62
|
+
seq: live.step.seq,
|
|
63
|
+
startedAt: live.step.startedAt,
|
|
64
|
+
toolsDone: activity?.toolsDone ?? 0,
|
|
65
|
+
...(current
|
|
66
|
+
? {
|
|
67
|
+
tool: {
|
|
68
|
+
summary: describeToolCall(current.toolName, current.args),
|
|
69
|
+
startedAt: current.startTime,
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
: {}),
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
: {}),
|
|
76
|
+
pending: pending.get(entry.id) ?? [],
|
|
77
|
+
};
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
async message(desk, id, input) {
|
|
81
|
+
const { ctx } = this;
|
|
82
|
+
const deskDir = ctx.options.getDeskDir(desk);
|
|
83
|
+
if (!deskDir)
|
|
84
|
+
return { kind: "not_found" };
|
|
85
|
+
let document;
|
|
86
|
+
const live = ctx.live.get(taskKey(desk, id));
|
|
87
|
+
const text = input.text.trim();
|
|
88
|
+
// Durability precedes best-effort steering. A transcript receipt, never queue acceptance,
|
|
89
|
+
// consumes this input; an aborted/unconsumed steer remains eligible for the next brief.
|
|
90
|
+
let messageId;
|
|
91
|
+
const accepted = await withTaskMutation(deskDir, id, async () => {
|
|
92
|
+
document = await readStoredTask(deskDir, id);
|
|
93
|
+
if (!document || document.fields.outcome)
|
|
94
|
+
return "not_found";
|
|
95
|
+
if (live?.intent.close || isTaskArchiving(deskDir, id) || pendingTaskClose(await readTaskLog(deskDir, id)))
|
|
96
|
+
return "closing";
|
|
97
|
+
messageId = await appendTaskLog(deskDir, id, {
|
|
98
|
+
kind: "message",
|
|
99
|
+
from: input.from,
|
|
100
|
+
channel: input.channel,
|
|
101
|
+
text,
|
|
102
|
+
});
|
|
103
|
+
return "accepted";
|
|
104
|
+
});
|
|
105
|
+
if (accepted !== "accepted")
|
|
106
|
+
return { kind: accepted };
|
|
107
|
+
if (!document || !messageId)
|
|
108
|
+
return { kind: "not_found" };
|
|
109
|
+
if (live?.step && live.runner && !live.step.abort) {
|
|
110
|
+
try {
|
|
111
|
+
if (await submitTaskInput(ctx, live, `[用户对任务 ${id} 说] ${text}\n${taskInputTag(messageId)}`, [messageId], input.from)) {
|
|
112
|
+
ctx.notify();
|
|
113
|
+
return { kind: "injected" };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
log.logInfoEvent("tasks.message.inject_failed", "Message could not join the running step", {
|
|
118
|
+
fields: { taskId: id, desk, reason: errorMessage(error) },
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
ctx.notify();
|
|
123
|
+
if (document.fields.state === "paused")
|
|
124
|
+
return { kind: "held_paused" };
|
|
125
|
+
if (isFrozen(ctx, desk, document.fields))
|
|
126
|
+
return { kind: "held_frozen" };
|
|
127
|
+
return { kind: document.fields.state === "waiting" ? "woke" : "queued_for_next_step" };
|
|
128
|
+
}
|
|
129
|
+
async pause(desk, id, input) {
|
|
130
|
+
const { ctx } = this;
|
|
131
|
+
const deskDir = ctx.options.getDeskDir(desk);
|
|
132
|
+
if (!deskDir || !(await readStoredTask(deskDir, id)))
|
|
133
|
+
return { kind: "not_found" };
|
|
134
|
+
const paused = await pauseStoredTask(deskDir, id, { by: input.by, reason: input.reason });
|
|
135
|
+
if (!paused)
|
|
136
|
+
return { kind: "unchanged" };
|
|
137
|
+
// The step stops; delegations and jobs already in flight keep running and their results are
|
|
138
|
+
// recorded for the step that follows the resume (D24).
|
|
139
|
+
const live = ctx.live.get(taskKey(desk, id));
|
|
140
|
+
if (live) {
|
|
141
|
+
abortStep(ctx, live, "pause");
|
|
142
|
+
if (!live.driving)
|
|
143
|
+
void ctx.release(live);
|
|
144
|
+
}
|
|
145
|
+
ctx.notify();
|
|
146
|
+
return { kind: "ok" };
|
|
147
|
+
}
|
|
148
|
+
async resume(desk, id, grants) {
|
|
149
|
+
const deskDir = this.ctx.options.getDeskDir(desk);
|
|
150
|
+
if (!deskDir || !(await readStoredTask(deskDir, id)))
|
|
151
|
+
return { kind: "not_found" };
|
|
152
|
+
if (this.ctx.live.get(taskKey(desk, id))?.driving)
|
|
153
|
+
return { kind: "stopping" };
|
|
154
|
+
const resumed = await resumeStoredTask(deskDir, id, grants);
|
|
155
|
+
if (!resumed)
|
|
156
|
+
return { kind: "unchanged" };
|
|
157
|
+
this.ctx.notify();
|
|
158
|
+
return { kind: "ok" };
|
|
159
|
+
}
|
|
160
|
+
async cancel(desk, id, input) {
|
|
161
|
+
const { ctx } = this;
|
|
162
|
+
const deskDir = ctx.options.getDeskDir(desk);
|
|
163
|
+
const document = deskDir ? await readStoredTask(deskDir, id) : undefined;
|
|
164
|
+
if (!deskDir || !document || document.fields.outcome)
|
|
165
|
+
return { kind: "not_found" };
|
|
166
|
+
const live = ctx.live.get(taskKey(desk, id));
|
|
167
|
+
await pauseStoredTask(deskDir, id, { by: "user", reason: "正在取消任务" });
|
|
168
|
+
if (live) {
|
|
169
|
+
abortStep(ctx, live, "cancel");
|
|
170
|
+
try {
|
|
171
|
+
await withTimeout("task cancellation", ctx.timing.stopGraceMs, () => live.done ?? Promise.resolve());
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
throw new Error(`任务 \`${id}\` 的当前步骤尚未停止,暂未归档。请联系部署者重启服务,再用 \`/tasks cancel ${id}\` 重试。`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const cancelled = await this.cancelBoundWork(desk, id);
|
|
178
|
+
const reportChannel = document.fields.channel;
|
|
179
|
+
await closeStoredTask(deskDir, id, {
|
|
180
|
+
outcome: "cancel",
|
|
181
|
+
by: input.by,
|
|
182
|
+
note: input.note,
|
|
183
|
+
receipt: reportChannel && reportChannel !== input.channel
|
|
184
|
+
? () => cancelledByUserReceipt(id, extractTaskTitle(document.body, id))
|
|
185
|
+
: undefined,
|
|
186
|
+
});
|
|
187
|
+
if (live)
|
|
188
|
+
await ctx.release(live);
|
|
189
|
+
ctx.notify();
|
|
190
|
+
// A cancel typed in another channel of the desk leaves the report channel told (D29); one typed
|
|
191
|
+
// there is answered by the command's own reply.
|
|
192
|
+
if (reportChannel && reportChannel !== input.channel) {
|
|
193
|
+
await drainTaskDeliveries(deskDir, (channel, text) => ctx.options.deliver(desk, channel, text), (channel) => ctx.options.isBoundTo(channel, desk) && ctx.options.isReachable(channel), ctx.now()).catch((error) => log.logWarn("tasks.delivery.drain_failed", "Task delivery drain failed", {
|
|
194
|
+
reason: errorMessage(error),
|
|
195
|
+
fields: { desk, taskId: id },
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
return { kind: "cancelled", cancelled };
|
|
199
|
+
}
|
|
200
|
+
/** Cancel every delegation and job bound to the task; the refs that were still running. */
|
|
201
|
+
async cancelBoundWork(desk, taskId) {
|
|
202
|
+
const { options } = this.ctx;
|
|
203
|
+
const pending = (await listPendingWork(options, desk, this.ctx.now())).get(taskId) ?? [];
|
|
204
|
+
const cancelled = [];
|
|
205
|
+
for (const work of pending) {
|
|
206
|
+
try {
|
|
207
|
+
if (work.kind === "delegation")
|
|
208
|
+
await options.getRuns(desk).cancel(work.ref);
|
|
209
|
+
else
|
|
210
|
+
await options.getJobs(desk).cancel([work.ref]);
|
|
211
|
+
cancelled.push(work.ref);
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
log.logWarn("tasks.task.cancel_work_failed", "Cancelling a task's bound work failed", {
|
|
215
|
+
reason: errorMessage(error),
|
|
216
|
+
fields: { taskId, desk, ref: work.ref },
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const remaining = (await listPendingWork(options, desk, this.ctx.now())).get(taskId) ?? [];
|
|
221
|
+
if (remaining.length > 0)
|
|
222
|
+
throw new Error(`任务 \`${taskId}\` 仍有工作未停止(${remaining.map((work) => work.ref).join("、")}),暂未归档。请稍后用 \`/tasks cancel ${taskId}\` 重试;仍未停止时请联系部署者检查服务器。`);
|
|
223
|
+
return cancelled;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type LaneContext, type LiveTask } from "./task-lane-types.js";
|
|
2
|
+
/** Serialize submission with task control writes and step teardown. Acceptance is never an ack. */
|
|
3
|
+
export declare function submitTaskInput(ctx: LaneContext, live: LiveTask, text: string, ids: string[], from?: string): Promise<boolean>;
|
|
4
|
+
/** Notifications collapse per task; a producer never waits on the running session. */
|
|
5
|
+
export declare class TaskInputDelivery {
|
|
6
|
+
private readonly ctx;
|
|
7
|
+
private readonly dirty;
|
|
8
|
+
private timer?;
|
|
9
|
+
constructor(ctx: LaneContext);
|
|
10
|
+
notify(desk: string, taskId: string): void;
|
|
11
|
+
stop(): void;
|
|
12
|
+
private deliver;
|
|
13
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { MAX_USER_MESSAGE_CHARS } from "../agent/types.js";
|
|
2
|
+
import * as log from "../log.js";
|
|
3
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
4
|
+
import { isTaskArchiving } from "../tasks/archive.js";
|
|
5
|
+
import { BRIEF_INPUT_LIMIT, renderTaskInputs } from "../tasks/brief.js";
|
|
6
|
+
import { pendingTaskClose } from "../tasks/completion.js";
|
|
7
|
+
import { newInputs, readTaskLog } from "../tasks/loop-log.js";
|
|
8
|
+
import { withTaskMutation } from "../tasks/mutation-lock.js";
|
|
9
|
+
import { readStoredTask } from "../tasks/store.js";
|
|
10
|
+
import { taskKey } from "./task-lane-types.js";
|
|
11
|
+
function eligible(ctx, live, step) {
|
|
12
|
+
return (live.step === step &&
|
|
13
|
+
!step.ending &&
|
|
14
|
+
!step.abort &&
|
|
15
|
+
!live.quarantined &&
|
|
16
|
+
!ctx.isStopped() &&
|
|
17
|
+
ctx.options.isEnabled?.() !== false &&
|
|
18
|
+
ctx.options.isBoundTo(live.channelId, live.desk) &&
|
|
19
|
+
ctx.options.isReachable(live.channelId) &&
|
|
20
|
+
!live.intent.ask &&
|
|
21
|
+
!live.intent.waitUntil &&
|
|
22
|
+
!live.intent.close);
|
|
23
|
+
}
|
|
24
|
+
/** Serialize submission with task control writes and step teardown. Acceptance is never an ack. */
|
|
25
|
+
export async function submitTaskInput(ctx, live, text, ids, from) {
|
|
26
|
+
const step = live.step;
|
|
27
|
+
const runner = live.runner;
|
|
28
|
+
if (!step || !runner || !eligible(ctx, live, step))
|
|
29
|
+
return false;
|
|
30
|
+
const previous = step.submitting;
|
|
31
|
+
const operation = (async () => {
|
|
32
|
+
await previous;
|
|
33
|
+
return withTaskMutation(live.deskDir, live.taskId, async () => {
|
|
34
|
+
const document = await readStoredTask(live.deskDir, live.taskId);
|
|
35
|
+
const records = await readTaskLog(live.deskDir, live.taskId);
|
|
36
|
+
if (!document ||
|
|
37
|
+
document.fields.outcome ||
|
|
38
|
+
document.fields.channel !== live.channelId ||
|
|
39
|
+
document.fields.state === "paused" ||
|
|
40
|
+
isTaskArchiving(live.deskDir, live.taskId) ||
|
|
41
|
+
pendingTaskClose(records) ||
|
|
42
|
+
!eligible(ctx, live, step) ||
|
|
43
|
+
live.runner !== runner)
|
|
44
|
+
return false;
|
|
45
|
+
const result = await runner.queueSteer(text, from, undefined, {
|
|
46
|
+
seq: step.seq,
|
|
47
|
+
isCurrent: () => eligible(ctx, live, step) && live.runner === runner,
|
|
48
|
+
});
|
|
49
|
+
if (result === "stale")
|
|
50
|
+
return false;
|
|
51
|
+
for (const id of ids)
|
|
52
|
+
step.submittedInputIds.add(id);
|
|
53
|
+
log.logInfoEvent("tasks.input.submitted", "Task inputs submitted", {
|
|
54
|
+
fields: { desk: live.desk, taskId: live.taskId, seq: step.seq, generation: runner.generation, ids },
|
|
55
|
+
});
|
|
56
|
+
return true;
|
|
57
|
+
});
|
|
58
|
+
})();
|
|
59
|
+
step.submitting = operation.then(() => undefined, () => undefined);
|
|
60
|
+
return operation;
|
|
61
|
+
}
|
|
62
|
+
/** Notifications collapse per task; a producer never waits on the running session. */
|
|
63
|
+
export class TaskInputDelivery {
|
|
64
|
+
constructor(ctx) {
|
|
65
|
+
this.ctx = ctx;
|
|
66
|
+
this.dirty = new Set();
|
|
67
|
+
}
|
|
68
|
+
notify(desk, taskId) {
|
|
69
|
+
if (this.ctx.isStopped())
|
|
70
|
+
return;
|
|
71
|
+
this.dirty.add(taskKey(desk, taskId));
|
|
72
|
+
this.ctx.notify();
|
|
73
|
+
if (this.timer)
|
|
74
|
+
return;
|
|
75
|
+
this.timer = setTimeout(() => {
|
|
76
|
+
this.timer = undefined;
|
|
77
|
+
const keys = [...this.dirty];
|
|
78
|
+
this.dirty.clear();
|
|
79
|
+
for (const key of keys)
|
|
80
|
+
void this.deliver(key).catch((error) => log.logWarn("tasks.input.submit_failed", "Task input submission failed", {
|
|
81
|
+
reason: errorMessage(error),
|
|
82
|
+
fields: { key },
|
|
83
|
+
}));
|
|
84
|
+
}, this.ctx.timing.notifyDebounceMs);
|
|
85
|
+
this.timer.unref?.();
|
|
86
|
+
}
|
|
87
|
+
stop() {
|
|
88
|
+
clearTimeout(this.timer);
|
|
89
|
+
this.timer = undefined;
|
|
90
|
+
this.dirty.clear();
|
|
91
|
+
}
|
|
92
|
+
async deliver(key) {
|
|
93
|
+
const live = this.ctx.live.get(key);
|
|
94
|
+
const step = live?.step;
|
|
95
|
+
if (!live || !step || !eligible(this.ctx, live, step))
|
|
96
|
+
return;
|
|
97
|
+
if (step.injecting) {
|
|
98
|
+
step.inputDirty = true;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
step.injecting = true;
|
|
102
|
+
try {
|
|
103
|
+
const records = await readTaskLog(live.deskDir, live.taskId);
|
|
104
|
+
const inputs = newInputs(records)
|
|
105
|
+
.filter((input) => input.kind === "settle" && !input.inline && input.id && !step.submittedInputIds.has(input.id))
|
|
106
|
+
.slice(0, BRIEF_INPUT_LIMIT);
|
|
107
|
+
if (!inputs.length || !eligible(this.ctx, live, step))
|
|
108
|
+
return;
|
|
109
|
+
let text = renderTaskInputs(records, inputs);
|
|
110
|
+
// Preserve complete result blocks and receipt ids instead of clipping the middle of a burst.
|
|
111
|
+
while (inputs.length > 1 && text && text.length + 32 > MAX_USER_MESSAGE_CHARS) {
|
|
112
|
+
inputs.pop();
|
|
113
|
+
text = renderTaskInputs(records, inputs);
|
|
114
|
+
}
|
|
115
|
+
if (text &&
|
|
116
|
+
(await submitTaskInput(this.ctx, live, `<task_inputs>\n${text}\n</task_inputs>`, inputs.flatMap((input) => (input.id ? [input.id] : []))))) {
|
|
117
|
+
// More than one batch stays durable and is submitted on a later combined pass.
|
|
118
|
+
this.notify(live.desk, live.taskId);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
step.injecting = false;
|
|
123
|
+
if (step.inputDirty) {
|
|
124
|
+
step.inputDirty = false;
|
|
125
|
+
this.notify(live.desk, live.taskId);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { AgentRunner } from "../agent/types.js";
|
|
2
|
+
import type { ChannelStore } from "../channel/store.js";
|
|
3
|
+
import type { DeskJobManager } from "../jobs/manager.js";
|
|
4
|
+
import type { SubAgentRunManager } from "../subagents/runs.js";
|
|
5
|
+
import type { TaskSessionContext, TaskStepIntent } from "../tasks/control.js";
|
|
6
|
+
/** Executing tasks per desk and per daemon (spec 064, D12). Code constants, not settings. */
|
|
7
|
+
export declare const MAX_EXECUTING_TASKS_PER_DESK = 3;
|
|
8
|
+
export declare const MAX_EXECUTING_TASKS = 5;
|
|
9
|
+
/** One step may run this long before it is stopped (D14). */
|
|
10
|
+
export declare const STEP_TIME_LIMIT_MS: number;
|
|
11
|
+
/** The longest the lane sleeps between scans (D11). */
|
|
12
|
+
export declare const MAX_SLEEP_MS: number;
|
|
13
|
+
/** A burst of notifications collapses into one rescan. */
|
|
14
|
+
export declare const NOTIFY_DEBOUNCE_MS = 50;
|
|
15
|
+
/** Waiting before a task is admitted again after its first and second consecutive error (D16). */
|
|
16
|
+
export declare const ERROR_BACKOFF_MS: readonly number[];
|
|
17
|
+
export interface TaskStepEvent {
|
|
18
|
+
phase: "started" | "ended";
|
|
19
|
+
desk: string;
|
|
20
|
+
taskId: string;
|
|
21
|
+
seq: number;
|
|
22
|
+
/** `ended` only. */
|
|
23
|
+
result?: string;
|
|
24
|
+
/** `ended` only: what the task does next (`continue` / `work` / `user` / `time` / `closed` / `paused`). */
|
|
25
|
+
next?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface TaskRunnerTarget {
|
|
28
|
+
desk: string;
|
|
29
|
+
deskDir: string;
|
|
30
|
+
taskId: string;
|
|
31
|
+
/** The task's report channel: delegation notices, `send_media` and audit land there. */
|
|
32
|
+
channelId: string;
|
|
33
|
+
session: TaskSessionContext;
|
|
34
|
+
}
|
|
35
|
+
export interface TaskLaneOptions {
|
|
36
|
+
/** The desks the lane scans — the active ones (spec 058, D6). A dormant desk's tasks are never touched. */
|
|
37
|
+
getActiveDesks: () => ReadonlyArray<{
|
|
38
|
+
desk: string;
|
|
39
|
+
deskDir: string;
|
|
40
|
+
}>;
|
|
41
|
+
/** The directory of a desk the runtime knows, or `undefined`. */
|
|
42
|
+
getDeskDir: (desk: string) => string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Whether a report channel is bound to a desk right now. A task whose `channel` is missing or not
|
|
45
|
+
* bound to its own desk is frozen: the lane does not touch it (INV-7).
|
|
46
|
+
*/
|
|
47
|
+
isBoundTo: (channelId: string, desk: string) => boolean;
|
|
48
|
+
/** Whether the channel's transport is switched on in this process (spec 061, INV-8). */
|
|
49
|
+
isReachable: (channelId: string) => boolean;
|
|
50
|
+
/** Build the runner for one task (the `task` profile). The lane owns it from here and disposes it. */
|
|
51
|
+
createTaskRunner: (target: TaskRunnerTarget) => AgentRunner;
|
|
52
|
+
getRuns: (desk: string) => SubAgentRunManager;
|
|
53
|
+
getJobs: (desk: string) => DeskJobManager;
|
|
54
|
+
store: ChannelStore;
|
|
55
|
+
/** Say something to a report channel without a model; resolves whether it was delivered. */
|
|
56
|
+
deliver: (desk: string, channelId: string, text: string) => Promise<boolean>;
|
|
57
|
+
/** `tools.tasks.enabled`, re-read on every scan. Off: no new steps, maintenance continues. */
|
|
58
|
+
isEnabled?: () => boolean;
|
|
59
|
+
/** Steps in flight register here so shutdown can wait for them. */
|
|
60
|
+
activeTasks: Set<Promise<void>>;
|
|
61
|
+
/** Observability only (evaluation workers, tests): a step began or ended. Must not throw into the lane. */
|
|
62
|
+
onStep?: (event: TaskStepEvent) => void;
|
|
63
|
+
now?: () => number;
|
|
64
|
+
/** Test overrides for the timing constants. */
|
|
65
|
+
timing?: Partial<{
|
|
66
|
+
stepTimeLimitMs: number;
|
|
67
|
+
stopGraceMs: number;
|
|
68
|
+
maxSleepMs: number;
|
|
69
|
+
notifyDebounceMs: number;
|
|
70
|
+
errorBackoffMs: readonly number[];
|
|
71
|
+
}>;
|
|
72
|
+
}
|
|
73
|
+
export type StepAbort = "pause" | "cancel" | "timeout" | "shutdown";
|
|
74
|
+
/** What the lane holds in memory for a task it is executing. Everything durable lives in the task's files. */
|
|
75
|
+
export interface LiveTask {
|
|
76
|
+
key: string;
|
|
77
|
+
desk: string;
|
|
78
|
+
deskDir: string;
|
|
79
|
+
taskId: string;
|
|
80
|
+
channelId: string;
|
|
81
|
+
runner?: AgentRunner;
|
|
82
|
+
/** The sequence number of the step that is running (or ran last). */
|
|
83
|
+
seq: number;
|
|
84
|
+
/** What the leader registered during the step that is running. */
|
|
85
|
+
intent: TaskStepIntent;
|
|
86
|
+
step?: {
|
|
87
|
+
seq: number;
|
|
88
|
+
startedAt: number;
|
|
89
|
+
submittedInputIds: Set<string>;
|
|
90
|
+
submitting?: Promise<void>;
|
|
91
|
+
injecting?: boolean;
|
|
92
|
+
inputDirty?: boolean;
|
|
93
|
+
ending?: boolean;
|
|
94
|
+
abort?: StepAbort;
|
|
95
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
96
|
+
stopTimer?: ReturnType<typeof setTimeout>;
|
|
97
|
+
};
|
|
98
|
+
/** A drive loop is running for this task (a step may or may not be in flight at the moment). */
|
|
99
|
+
driving: boolean;
|
|
100
|
+
quarantined?: boolean;
|
|
101
|
+
done?: Promise<void>;
|
|
102
|
+
}
|
|
103
|
+
/** What the step, control and scan code share. The lane builds one and hands it around; nothing here is a collaborator of its own. */
|
|
104
|
+
export interface LaneContext {
|
|
105
|
+
options: TaskLaneOptions;
|
|
106
|
+
live: Map<string, LiveTask>;
|
|
107
|
+
now(): number;
|
|
108
|
+
timing: {
|
|
109
|
+
stepTimeLimitMs: number;
|
|
110
|
+
stopGraceMs: number;
|
|
111
|
+
maxSleepMs: number;
|
|
112
|
+
notifyDebounceMs: number;
|
|
113
|
+
errorBackoffMs: readonly number[];
|
|
114
|
+
};
|
|
115
|
+
/** Ask for a rescan soon (debounced). */
|
|
116
|
+
notify(): void;
|
|
117
|
+
inputAvailable(desk: string, taskId: string): void;
|
|
118
|
+
/** Dispose a task's runner and forget its in-memory state, unless a drive loop still owns it. */
|
|
119
|
+
release(live: LiveTask): Promise<void>;
|
|
120
|
+
/** Whether the lane has been stopped. */
|
|
121
|
+
isStopped(): boolean;
|
|
122
|
+
}
|
|
123
|
+
export declare function taskKey(desk: string, taskId: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Executing tasks per desk and per daemon (spec 064, D12). Code constants, not settings. */
|
|
2
|
+
export const MAX_EXECUTING_TASKS_PER_DESK = 3;
|
|
3
|
+
export const MAX_EXECUTING_TASKS = 5;
|
|
4
|
+
/** One step may run this long before it is stopped (D14). */
|
|
5
|
+
export const STEP_TIME_LIMIT_MS = 20 * 60_000;
|
|
6
|
+
/** The longest the lane sleeps between scans (D11). */
|
|
7
|
+
export const MAX_SLEEP_MS = 15 * 60_000;
|
|
8
|
+
/** A burst of notifications collapses into one rescan. */
|
|
9
|
+
export const NOTIFY_DEBOUNCE_MS = 50;
|
|
10
|
+
/** Waiting before a task is admitted again after its first and second consecutive error (D16). */
|
|
11
|
+
export const ERROR_BACKOFF_MS = [60_000, 5 * 60_000];
|
|
12
|
+
export function taskKey(desk, taskId) {
|
|
13
|
+
return `${desk}\0${taskId}`;
|
|
14
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { TaskCancelOutcome, TaskControl, TaskControlOutcome, TaskLiveSnapshot, TaskMessageOutcome } from "../tasks/control.js";
|
|
2
|
+
import type { TaskBudget } from "../tasks/frontmatter.js";
|
|
3
|
+
import { type TaskLaneOptions } from "./task-lane-types.js";
|
|
4
|
+
export type { TaskLaneOptions, TaskRunnerTarget } from "./task-lane-types.js";
|
|
5
|
+
/**
|
|
6
|
+
* The task lane (spec 064, D11): the one place tasks execute. A task never enters a channel queue —
|
|
7
|
+
* the chat answers while a step runs and a step never waits for the chat (INV-1).
|
|
8
|
+
*
|
|
9
|
+
* The lane reads the task files, maintains them from facts (waits that came due, results that
|
|
10
|
+
* arrived, budgets that ran out), admits queued tasks into the execution slots, and runs each
|
|
11
|
+
* admitted task as a loop of steps in a runner of its own. Its in-memory state is only what a step
|
|
12
|
+
* in flight needs; losing it (a restart) loses nothing, because every decision is recomputed from
|
|
13
|
+
* the files and the log (D10).
|
|
14
|
+
*/
|
|
15
|
+
export declare class TaskLane implements TaskControl {
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly ctx;
|
|
18
|
+
private readonly control;
|
|
19
|
+
private readonly inputs;
|
|
20
|
+
private timer;
|
|
21
|
+
private notifyTimer;
|
|
22
|
+
private started;
|
|
23
|
+
private stopped;
|
|
24
|
+
private scanning;
|
|
25
|
+
private rescan;
|
|
26
|
+
private nextDeskIndex;
|
|
27
|
+
private nextWakeMs;
|
|
28
|
+
/** Tasks reported frozen, so the transition is logged once rather than every scan. */
|
|
29
|
+
private readonly frozenLogged;
|
|
30
|
+
/** Consecutive step errors per task in this process, and when it may be admitted again (D16). Not persisted: a restart starts from zero. */
|
|
31
|
+
/** Drive loops in flight, for `drained`. */
|
|
32
|
+
private readonly drives;
|
|
33
|
+
private readonly backoff;
|
|
34
|
+
constructor(options: TaskLaneOptions);
|
|
35
|
+
start(): void;
|
|
36
|
+
/** Stop admitting, stop the steps in flight (their `step_end` is written by the next start, D10) and let go of every runner. */
|
|
37
|
+
stop(): void;
|
|
38
|
+
inputAvailable(desk: string, taskId: string): void;
|
|
39
|
+
/** Something changed that a task may need to react to (a result, a message, a new task): look again soon. */
|
|
40
|
+
notify(): void;
|
|
41
|
+
/** Resolves when no step is in flight (and none was just started by a scan). For tests and evaluation workers. */
|
|
42
|
+
drained(): Promise<void>;
|
|
43
|
+
private scanning_;
|
|
44
|
+
/** One scan now, outside the timer: the entry point tests and the runtime's own wiring use. */
|
|
45
|
+
runOnce(): Promise<void>;
|
|
46
|
+
isRunning(desk: string, id: string): boolean;
|
|
47
|
+
created(): void;
|
|
48
|
+
snapshot(desk: string, id?: string): Promise<TaskLiveSnapshot[]>;
|
|
49
|
+
message(desk: string, id: string, input: {
|
|
50
|
+
from: string;
|
|
51
|
+
channel: string;
|
|
52
|
+
text: string;
|
|
53
|
+
}): Promise<TaskMessageOutcome>;
|
|
54
|
+
pause(desk: string, id: string, input: {
|
|
55
|
+
by: "user";
|
|
56
|
+
reason: string;
|
|
57
|
+
}): Promise<TaskControlOutcome>;
|
|
58
|
+
resume(desk: string, id: string, grants: Partial<TaskBudget>): Promise<TaskControlOutcome>;
|
|
59
|
+
cancel(desk: string, id: string, input: {
|
|
60
|
+
by: "user";
|
|
61
|
+
note: string;
|
|
62
|
+
channel?: string;
|
|
63
|
+
}): Promise<TaskCancelOutcome>;
|
|
64
|
+
private scan;
|
|
65
|
+
private scheduleNext;
|
|
66
|
+
private noteHorizon;
|
|
67
|
+
/** Read every active desk's tasks and note which are reachable (INV-7) and how much work each has in flight. */
|
|
68
|
+
private readDesk;
|
|
69
|
+
private noteFrozen;
|
|
70
|
+
private reconcile;
|
|
71
|
+
private scanOnce;
|
|
72
|
+
/**
|
|
73
|
+
* Zero-token upkeep of one reachable task (D7/D9). Returns `queued` when the task is waiting
|
|
74
|
+
* its turn, `run` when a work wait has news and runs again in its own slot, `idle` otherwise.
|
|
75
|
+
*/
|
|
76
|
+
private maintain;
|
|
77
|
+
/** Stop a task the guards say must not run again: pause it and tell the user why (D16). True when it was stopped. */
|
|
78
|
+
private guard;
|
|
79
|
+
private pauseForGuard;
|
|
80
|
+
private startDrive;
|
|
81
|
+
/** Steps in a row while the task has something to do and a slot (D8: `continue` opens the next at once). */
|
|
82
|
+
private drive;
|
|
83
|
+
/** Act on a finished step: close, ask, pause, wait — or open the next. */
|
|
84
|
+
private afterStep;
|
|
85
|
+
private isBackingOff;
|
|
86
|
+
private readonly questionRetry;
|
|
87
|
+
private deliverQuestion;
|
|
88
|
+
private backoffUntil;
|
|
89
|
+
/** After a step: the freshest state and log decide whether the task goes on (budget, idle, timeout, error). True when it was stopped. */
|
|
90
|
+
private guardLive;
|
|
91
|
+
/** Whether a task waiting on work has news right now, and may run (guards included). */
|
|
92
|
+
private reevaluate;
|
|
93
|
+
private closeForLeader;
|
|
94
|
+
private flushDeliveries;
|
|
95
|
+
/** Let go of a task that left execution — unless a drive loop is still working on it, which then does it itself. */
|
|
96
|
+
private release;
|
|
97
|
+
/** Dispose a task's runner and forget its in-memory state (D13). */
|
|
98
|
+
private dispose;
|
|
99
|
+
}
|