refactor: centralize notifications in core dispatch/completion functions (#150)

This commit is contained in:
Lauren ten Hoor
2026-02-13 17:00:42 +08:00
parent 80587412ee
commit 265f82f3a9
8 changed files with 72 additions and 88 deletions

View File

@@ -10,7 +10,6 @@ import type { ToolContext } from "../types.js";
import { getWorker, resolveRepoPath } from "../projects.js";
import { executeCompletion, getRule, NEXT_STATE } from "../services/pipeline.js";
import { log as auditLog } from "../audit.js";
import { notify, getNotificationConfig } from "../notify.js";
import { requireWorkspaceDir, resolveProject, resolveProvider, getPluginConfig, tickAndNotify } from "../tool-helpers.js";
export function createWorkFinishTool(api: OpenClawPluginApi) {
@@ -58,9 +57,14 @@ export function createWorkFinishTool(api: OpenClawPluginApi) {
const repoPath = resolveRepoPath(project.repo);
const issue = await provider.getIssue(issueId);
// Execute completion (pipeline service)
const pluginConfig = getPluginConfig(api);
// Execute completion (pipeline service handles notification)
const completion = await executeCompletion({
workspaceDir, groupId, role, result, issueId, summary, prUrl, provider, repoPath,
projectName: project.name,
channel: project.channel,
pluginConfig,
});
const output: Record<string, unknown> = {
@@ -68,18 +72,9 @@ export function createWorkFinishTool(api: OpenClawPluginApi) {
...completion,
};
// Notify completion
const pluginConfig = getPluginConfig(api);
const notifyConfig = getNotificationConfig(pluginConfig);
await notify(
{ type: "workerComplete", project: project.name, groupId, issueId, issueUrl: issue.web_url, role, result: result as "done" | "pass" | "fail" | "refine" | "blocked", summary, nextState: NEXT_STATE[`${role}:${result}`] },
{ workspaceDir, config: notifyConfig, groupId, channel: project.channel ?? "telegram" },
);
// Tick: fill free slots + notify starts
// Tick: fill free slots (notifications handled by dispatchTask)
const tickPickups = await tickAndNotify({
workspaceDir, groupId, agentId: ctx.agentId, pluginConfig, sessionKey: ctx.sessionKey,
channel: project.channel ?? "telegram",
});
if (tickPickups.length) output.tickPickups = tickPickups;

View File

@@ -12,7 +12,6 @@ import type { StateLabel } from "../providers/provider.js";
import { selectLevel } from "../model-selector.js";
import { getWorker } from "../projects.js";
import { dispatchTask } from "../dispatch.js";
import { notify, getNotificationConfig } from "../notify.js";
import { findNextIssue, detectRoleFromLabel, detectLevelFromLabels } from "../services/tick.js";
import { isDevLevel } from "../tiers.js";
import { requireWorkspaceDir, resolveProject, resolveProvider, getPluginConfig } from "../tool-helpers.js";
@@ -98,16 +97,11 @@ export function createWorkStartTool(api: OpenClawPluginApi) {
role, level: selectedLevel, fromLabel: currentLabel, toLabel: targetLabel,
transitionLabel: (id, from, to) => provider.transitionLabel(id, from as StateLabel, to as StateLabel),
provider,
pluginConfig, sessionKey: ctx.sessionKey,
pluginConfig,
channel: project.channel,
sessionKey: ctx.sessionKey,
});
// Notify
const notifyConfig = getNotificationConfig(pluginConfig);
await notify(
{ type: "workerStart", project: project.name, groupId, issueId: issue.iid, issueTitle: issue.title, issueUrl: issue.web_url, role, level: dr.level, sessionAction: dr.sessionAction },
{ workspaceDir, config: notifyConfig, groupId, channel: project.channel ?? "telegram" },
);
// Auto-tick disabled per issue #125 - work_start should only pick up the explicitly requested issue
// The heartbeat service fills parallel slots automatically