refactor(cron): simplify main-summary prefix config
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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>",
|
||||
"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>", "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",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user