feat(cron): always post isolated summaries to main

This commit is contained in:
Peter Steinberger
2025-12-13 11:33:46 +00:00
parent a5f51eadf1
commit 8d1e73edc7
5 changed files with 29 additions and 11 deletions

View File

@@ -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 {

View File

@@ -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") {

View File

@@ -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"));

View File

@@ -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` });