feat: implement workerStart notifications for tick pickups and enhance tick handling

This commit is contained in:
Lauren ten Hoor
2026-02-10 23:14:12 +08:00
parent 41caa13050
commit ff83c25e8c
6 changed files with 107 additions and 27 deletions

View File

@@ -11,6 +11,8 @@ import type { InteractionContext } from "./context-guard.js";
import { detectContext, generateGuardrails } from "./context-guard.js";
import { readProjects, getProject, type Project, type ProjectsData } from "./projects.js";
import { createProvider, type ProviderWithType } from "./providers/index.js";
import { projectTick, type TickAction } from "./services/tick.js";
import { notifyTickPickups, getNotificationConfig } from "./notify.js";
/**
* Require workspaceDir from context or throw a clear error.
@@ -77,3 +79,41 @@ export function groupOnlyError(toolName: string, context: InteractionContext) {
export function getPluginConfig(api: OpenClawPluginApi): Record<string, unknown> | undefined {
return api.pluginConfig as Record<string, unknown> | undefined;
}
/**
* Run projectTick (non-fatal) and send workerStart notifications for any pickups.
* Returns the pickups array (empty on failure).
*/
export async function tickAndNotify(opts: {
workspaceDir: string;
groupId: string;
agentId?: string;
pluginConfig?: Record<string, unknown>;
sessionKey?: string;
targetRole?: "dev" | "qa";
channel?: string;
}): Promise<TickAction[]> {
let pickups: TickAction[] = [];
try {
const result = await projectTick({
workspaceDir: opts.workspaceDir,
groupId: opts.groupId,
agentId: opts.agentId,
pluginConfig: opts.pluginConfig,
sessionKey: opts.sessionKey,
targetRole: opts.targetRole,
});
pickups = result.pickups;
} catch { /* non-fatal: tick failure shouldn't break the caller */ }
if (pickups.length) {
const notifyConfig = getNotificationConfig(opts.pluginConfig);
await notifyTickPickups(pickups, {
workspaceDir: opts.workspaceDir,
config: notifyConfig,
channel: opts.channel,
});
}
return pickups;
}