From 32cd1175fbb0c3ecc38161cce8c6d549a8930007 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 13 Dec 2025 11:43:18 +0000 Subject: [PATCH] refactor(cron): simplify main-summary prefix config --- apps/macos/Sources/Clawdis/CronSettings.swift | 32 +++++++---------- docs/cron.md | 1 + src/cli/cron-cli.ts | 36 +++++++++---------- 3 files changed, 29 insertions(+), 40 deletions(-) diff --git a/apps/macos/Sources/Clawdis/CronSettings.swift b/apps/macos/Sources/Clawdis/CronSettings.swift index e4b938a96..5be14cb56 100644 --- a/apps/macos/Sources/Clawdis/CronSettings.swift +++ b/apps/macos/Sources/Clawdis/CronSettings.swift @@ -498,7 +498,6 @@ private struct CronJobEditor: View { @State private var thinking: String = "" @State private var timeoutSeconds: String = "" @State private var bestEffortDeliver: Bool = false - @State private var postToMain: Bool = false @State private var postPrefix: String = "Cron" var body: some View { @@ -568,12 +567,12 @@ private struct CronJobEditor: View { } } - if self.payloadKind == .agentTurn { - Section("Post summary to main (optional)") { - Toggle("Post to main", isOn: self.$postToMain) - if self.postToMain { - TextField("Prefix", text: self.$postPrefix) - } + if self.payloadKind == .agentTurn || self.sessionTarget == .isolated { + Section("Main session summary") { + Text("Isolated jobs always post a summary back into the main session when they finish.") + .font(.caption) + .foregroundStyle(.secondary) + TextField("Prefix", text: self.$postPrefix) } } } @@ -666,7 +665,6 @@ private struct CronJobEditor: View { self.bestEffortDeliver = bestEffortDeliver ?? false } - self.postToMain = job.isolation?.postToMain ?? false self.postPrefix = job.isolation?.postToMainPrefix ?? "Cron" } @@ -746,17 +744,11 @@ private struct CronJobEditor: View { ] if !name.isEmpty { root["name"] = name } - if self.payloadKind == .agentTurn || self.sessionTarget == .isolated { - if self.postToMain { - root["isolation"] = [ - "postToMain": true, - "postToMainPrefix": self.postPrefix.trimmingCharacters(in: .whitespacesAndNewlines) - .isEmpty ? "Cron" : self.postPrefix, - ] - } else if self.job != nil { - // Allow clearing isolation on edit. - root["isolation"] = ["postToMain": false] - } + if payload["kind"] as? String == "agentTurn" || self.sessionTarget == .isolated { + let trimmed = self.postPrefix.trimmingCharacters(in: .whitespacesAndNewlines) + root["isolation"] = [ + "postToMainPrefix": trimmed.isEmpty ? "Cron" : trimmed, + ] } return root @@ -839,7 +831,7 @@ struct CronSettings_Previews: PreviewProvider { channel: "last", to: nil, bestEffortDeliver: true), - isolation: CronIsolation(postToMain: true, postToMainPrefix: "Cron"), + isolation: CronIsolation(postToMain: nil, postToMainPrefix: "Cron"), state: CronJobState( nextRunAtMs: Int(Date().addingTimeInterval(3600).timeIntervalSince1970 * 1000), runningAtMs: nil, diff --git a/docs/cron.md b/docs/cron.md index ba80e581a..bbec6e6f7 100644 --- a/docs/cron.md +++ b/docs/cron.md @@ -77,6 +77,7 @@ Each job is a JSON object with stable keys (unknown keys ignored for forward com - `{"kind":"agentTurn","message":string,"deliver"?:boolean,"channel"?: "last"|"whatsapp"|"telegram","to"?:string,"timeoutSeconds"?:number}` - `isolation` (optional; only meaningful for isolated jobs) - `{"postToMain"?: boolean, "postToMainPrefix"?: string}` + - Note: `postToMain` is deprecated (no-op). Isolated jobs always post a summary; only the prefix is configurable. - `runtime` (optional) - `{"maxAttempts"?:number,"retryBackoffMs"?:number}` (best-effort retries; defaults off) - `state` (runtime-maintained) diff --git a/src/cli/cron-cli.ts b/src/cli/cron-cli.ts index 373ac67eb..42d245715 100644 --- a/src/cli/cron-cli.ts +++ b/src/cli/cron-cli.ts @@ -163,11 +163,7 @@ export function registerCronCli(program: Command) { "Do not fail the job if delivery fails", false, ) - .option( - "--post-to-main", - "Deprecated: isolated jobs always post a summary to main; use --post-prefix to customize", - false, - ) + .option("--post-to-main", "Deprecated (no-op)", false) .option( "--post-prefix ", "Prefix for summary system event", @@ -271,12 +267,16 @@ export function registerCronCli(program: Command) { ); } - const isolation = opts.postToMain - ? { - postToMain: true, - postToMainPrefix: String(opts.postPrefix ?? "Cron"), - } - : undefined; + const isolation = + payload.kind === "agentTurn" + ? { + postToMainPrefix: + typeof opts.postPrefix === "string" && + opts.postPrefix.trim() + ? opts.postPrefix.trim() + : "Cron", + } + : undefined; const params = { name: @@ -347,11 +347,7 @@ export function registerCronCli(program: Command) { "Do not fail job if delivery fails", false, ) - .option( - "--post-to-main", - "Deprecated: isolated jobs always post a summary to main; use --post-prefix to customize", - false, - ) + .option("--post-to-main", "Deprecated (no-op)", false) .option("--post-prefix ", "Prefix for summary system event") .action(async (id, opts) => { try { @@ -420,11 +416,11 @@ export function registerCronCli(program: Command) { }; } - if (opts.postToMain) { + if (typeof opts.postPrefix === "string") { patch.isolation = { - postToMain: true, - postToMainPrefix: - typeof opts.postPrefix === "string" ? opts.postPrefix : "Cron", + postToMainPrefix: opts.postPrefix.trim() + ? opts.postPrefix + : "Cron", }; }