feat(cron): always post isolated summaries to main
This commit is contained in:
@@ -163,7 +163,11 @@ export function registerCronCli(program: Command) {
|
||||
"Do not fail the job if delivery fails",
|
||||
false,
|
||||
)
|
||||
.option("--post-to-main", "Post a 1-line summary to main session", false)
|
||||
.option(
|
||||
"--post-to-main",
|
||||
"Deprecated: isolated jobs always post a summary to main; use --post-prefix to customize",
|
||||
false,
|
||||
)
|
||||
.option(
|
||||
"--post-prefix <prefix>",
|
||||
"Prefix for summary system event",
|
||||
@@ -343,7 +347,11 @@ export function registerCronCli(program: Command) {
|
||||
"Do not fail job if delivery fails",
|
||||
false,
|
||||
)
|
||||
.option("--post-to-main", "Post a 1-line summary to main session", false)
|
||||
.option(
|
||||
"--post-to-main",
|
||||
"Deprecated: isolated jobs always post a summary to main; use --post-prefix to customize",
|
||||
false,
|
||||
)
|
||||
.option("--post-prefix <prefix>", "Prefix for summary system event")
|
||||
.action(async (id, opts) => {
|
||||
try {
|
||||
|
||||
@@ -43,8 +43,18 @@ function assertCommandReplyConfig(cfg: ClawdisConfig) {
|
||||
function pickSummaryFromOutput(text: string | undefined) {
|
||||
const clean = (text ?? "").trim();
|
||||
if (!clean) return undefined;
|
||||
const oneLine = clean.replace(/\s+/g, " ");
|
||||
return oneLine.length > 200 ? `${oneLine.slice(0, 200)}…` : oneLine;
|
||||
const limit = 2000;
|
||||
return clean.length > limit ? `${clean.slice(0, limit)}…` : clean;
|
||||
}
|
||||
|
||||
function pickSummaryFromPayloads(
|
||||
payloads: Array<{ text?: string | undefined }>,
|
||||
) {
|
||||
for (let i = payloads.length - 1; i >= 0; i--) {
|
||||
const summary = pickSummaryFromOutput(payloads[i]?.text);
|
||||
if (summary) return summary;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function resolveDeliveryTarget(
|
||||
@@ -247,7 +257,8 @@ export async function runCronIsolatedAgentTurn(params: {
|
||||
|
||||
const payloads = runResult.payloads ?? [];
|
||||
const firstText = payloads[0]?.text ?? "";
|
||||
const summary = pickSummaryFromOutput(firstText);
|
||||
const summary =
|
||||
pickSummaryFromPayloads(payloads) ?? pickSummaryFromOutput(firstText);
|
||||
|
||||
if (delivery) {
|
||||
if (resolvedDelivery.channel === "whatsapp") {
|
||||
|
||||
@@ -104,7 +104,6 @@ describe("CronService", () => {
|
||||
sessionTarget: "isolated",
|
||||
wakeMode: "now",
|
||||
payload: { kind: "agentTurn", message: "do it", deliver: false },
|
||||
isolation: { postToMain: true, postToMainPrefix: "Cron" },
|
||||
});
|
||||
|
||||
vi.setSystemTime(new Date("2025-12-13T00:00:01.000Z"));
|
||||
|
||||
@@ -402,8 +402,8 @@ export class CronService {
|
||||
nextRunAtMs: job.state.nextRunAtMs,
|
||||
});
|
||||
|
||||
if (summary && job.isolation?.postToMain) {
|
||||
const prefix = job.isolation.postToMainPrefix?.trim() || "Cron";
|
||||
if (summary && job.sessionTarget === "isolated") {
|
||||
const prefix = job.isolation?.postToMainPrefix?.trim() || "Cron";
|
||||
this.deps.enqueueSystemEvent(`${prefix}: ${summary}`);
|
||||
if (job.wakeMode === "now") {
|
||||
this.deps.requestReplyHeartbeatNow({ reason: `cron:${job.id}:post` });
|
||||
|
||||
Reference in New Issue
Block a user