@cydm/pie 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builtin/extensions/ask-user/index.js +2 -2
- package/dist/builtin/extensions/cron/index.js +177 -24
- package/dist/builtin/extensions/im-forward/index.js +500 -64
- package/dist/builtin/extensions/memory/index.js +3 -3
- package/dist/builtin/extensions/pie-ipc/index.js +10 -3
- package/dist/builtin/extensions/pie-proc/README.md +13 -0
- package/dist/builtin/extensions/pie-proc/index.js +41 -9
- package/dist/builtin/extensions/plan-mode/index.js +2 -2
- package/dist/builtin/extensions/subagent/index.js +3 -3
- package/dist/builtin/extensions/todo/index.js +2 -2
- package/dist/chunks/{chunk-WK4N5HT5.js → chunk-BK36Y35W.js} +31 -0
- package/dist/chunks/{chunk-UOZHQ73X.js → chunk-J2LGVYH2.js} +2 -2
- package/dist/chunks/{chunk-FDLLNPIE.js → chunk-PC6HUZAD.js} +1 -1
- package/dist/chunks/{chunk-TDKNKNPL.js → chunk-PFXSA2LK.js} +3 -3
- package/dist/chunks/{concierge-cli-VWNRJG5A.js → concierge-cli-R3RIBGJL.js} +142 -53
- package/dist/chunks/{src-AB7PLORG.js → src-AQ4H43UM.js} +2 -2
- package/dist/chunks/{src-ZZZO4HSR.js → src-VPMIQGEW.js} +1 -1
- package/dist/cli.js +85 -15
- package/package.json +2 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
createAskUserCapability
|
|
4
|
-
} from "../../../chunks/chunk-
|
|
5
|
-
import "../../../chunks/chunk-
|
|
4
|
+
} from "../../../chunks/chunk-PC6HUZAD.js";
|
|
5
|
+
import "../../../chunks/chunk-BK36Y35W.js";
|
|
6
6
|
import "../../../chunks/chunk-NCP264ZE.js";
|
|
7
7
|
import "../../../chunks/chunk-JQRZLVPY.js";
|
|
8
8
|
import "../../../chunks/chunk-XXGYUYXI.js";
|
|
@@ -90,6 +90,22 @@ var Store = class {
|
|
|
90
90
|
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
91
91
|
}
|
|
92
92
|
dir;
|
|
93
|
+
/** Durable, append-only audit trail for operator-visible cron decisions.
|
|
94
|
+
*
|
|
95
|
+
* Why a file and not `ctx.log`: ctx.log only prints when PIE_VERBOSE is set
|
|
96
|
+
* and disappears with the terminal, so "who authorized this schedule" — or
|
|
97
|
+
* "which job blocked and why" — was unanswerable after the fact (review
|
|
98
|
+
* round 2, P1-1). This log lives beside the state it describes, survives
|
|
99
|
+
* restarts, and needs no debug flag.
|
|
100
|
+
*
|
|
101
|
+
* Ordering: the caller writes the audit record BEFORE mutating state, so a
|
|
102
|
+
* failed audit write can never leave an unlogged change behind. A failure
|
|
103
|
+
* therefore refuses the mutation (fail-closed, like the rest of the store). */
|
|
104
|
+
audit(record) {
|
|
105
|
+
const line = `${JSON.stringify({ at: Date.now(), ...record })}
|
|
106
|
+
`;
|
|
107
|
+
fs.appendFileSync(path.join(this.dir, "audit.log"), line, { mode: 384 });
|
|
108
|
+
}
|
|
93
109
|
/** Serialized bytes of the state currently on disk; undefined until the
|
|
94
110
|
* first save. A poll transaction that leaves the state byte-identical
|
|
95
111
|
* (the common idle case: owners unchanged, no job transitions) skips the
|
|
@@ -297,7 +313,7 @@ var Store = class {
|
|
|
297
313
|
if (Array.isArray(s.owners) || s.jobs.length > 100 || Object.keys(s.owners).length > 1e3) throw new Error("cron state exceeds record limit");
|
|
298
314
|
const ids = /* @__PURE__ */ new Set();
|
|
299
315
|
for (const j of s.jobs) {
|
|
300
|
-
if (!j || typeof j.id !== "string" || ids.has(j.id) || typeof j.sessionId !== "string" || !j.sessionId || j.sessionId.length > 256 || typeof j.cwd !== "string" || !path.isAbsolute(j.cwd) || typeof j.prompt !== "string" || !j.prompt.trim() || j.prompt.length > 16e3 || typeof j.enabled !== "boolean" || !["ready", "running", "blocked"].includes(j.state) || j.remaining !== void 0 && (!Number.isSafeInteger(j.remaining) || j.remaining < 0 || j.remaining > 1e3) || j.next !== null && !Number.isSafeInteger(j.next)) throw new Error("invalid cron job; manual recovery required");
|
|
316
|
+
if (!j || typeof j.id !== "string" || ids.has(j.id) || typeof j.sessionId !== "string" || !j.sessionId || j.sessionId.length > 256 || typeof j.cwd !== "string" || !path.isAbsolute(j.cwd) || typeof j.prompt !== "string" || !j.prompt.trim() || j.prompt.length > 16e3 || typeof j.enabled !== "boolean" || !["ready", "running", "blocked"].includes(j.state) || j.remaining !== void 0 && (!Number.isSafeInteger(j.remaining) || j.remaining < 0 || j.remaining > 1e3) || j.next !== null && !Number.isSafeInteger(j.next) || j.authorization !== void 0 && !["dialog", "yolo", "unattended"].includes(j.authorization) || j.retriedOnce !== void 0 && typeof j.retriedOnce !== "boolean" || j.noticedError !== void 0 && typeof j.noticedError !== "string") throw new Error("invalid cron job; manual recovery required");
|
|
301
317
|
if (j.sessionId === PROCESS_SESSION_ID) {
|
|
302
318
|
if (!parseProcessCommand(j)) throw new Error("invalid process cron job; manual recovery required");
|
|
303
319
|
}
|
|
@@ -346,7 +362,7 @@ var Store = class {
|
|
|
346
362
|
}
|
|
347
363
|
this.lastSavedContent = content;
|
|
348
364
|
}
|
|
349
|
-
add(sessionId, cwd, prompt, schedule, now = Date.now()) {
|
|
365
|
+
add(sessionId, cwd, prompt, schedule, now = Date.now(), authorization) {
|
|
350
366
|
if (!sessionId || sessionId.length > 256) throw new Error("an existing session is required");
|
|
351
367
|
if (sessionId === PROCESS_SESSION_ID) throw new Error("session id is reserved for process jobs");
|
|
352
368
|
if (typeof prompt !== "string" || !prompt.trim() || prompt.length > 16e3) throw new Error("prompt must contain 1..16000 characters");
|
|
@@ -362,7 +378,8 @@ var Store = class {
|
|
|
362
378
|
enabled: true,
|
|
363
379
|
next,
|
|
364
380
|
state: "ready",
|
|
365
|
-
...count !== void 0 ? { remaining: count } : {}
|
|
381
|
+
...count !== void 0 ? { remaining: count } : {},
|
|
382
|
+
...authorization !== void 0 ? { authorization } : {}
|
|
366
383
|
};
|
|
367
384
|
return this.transaction((s) => {
|
|
368
385
|
if (s.jobs.length >= 100) throw new Error("maximum 100 jobs");
|
|
@@ -788,6 +805,10 @@ var Runtime = class {
|
|
|
788
805
|
notices = /* @__PURE__ */ new Set();
|
|
789
806
|
completions = /* @__PURE__ */ new Map();
|
|
790
807
|
accepted;
|
|
808
|
+
/** P1-3b: consecutive idle observations for the current delivery. A queued
|
|
809
|
+
* follow-up turn can leave a single idle gap between turns, so one idle
|
|
810
|
+
* poll is not proof the delivery is over. */
|
|
811
|
+
acceptedIdlePolls = 0;
|
|
791
812
|
unreadableCoordinatorSince;
|
|
792
813
|
coordinatorNotices = /* @__PURE__ */ new Set();
|
|
793
814
|
get ready() {
|
|
@@ -933,7 +954,46 @@ var Runtime = class {
|
|
|
933
954
|
}
|
|
934
955
|
if (!this.stopped && generation === this.binding) this.register(sessionId);
|
|
935
956
|
}
|
|
936
|
-
|
|
957
|
+
/** Best-effort durable audit: scheduling must never stop because the audit
|
|
958
|
+
* file is unwritable — the state file remains the source of truth. */
|
|
959
|
+
auditQuiet(record) {
|
|
960
|
+
try {
|
|
961
|
+
this.store.audit(record);
|
|
962
|
+
} catch {
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
/** Block a job with LAYERED handling (review round 2, P1-4).
|
|
966
|
+
*
|
|
967
|
+
* One blocked job freezes the whole session's schedule set, so blocking is
|
|
968
|
+
* expensive. `executed` separates the two cases that used to be conflated:
|
|
969
|
+
*
|
|
970
|
+
* - false: the occurrence provably never ran (duplicate owner, owner
|
|
971
|
+
* changed before delivery). Retrying is safe, so a repeating prompt job
|
|
972
|
+
* is rescheduled ONCE automatically (`retriedOnce`) instead of freezing
|
|
973
|
+
* the session until a human notices. Mirrors completeInterrupted's
|
|
974
|
+
* precedent, and does NOT consume a count-capped execution because
|
|
975
|
+
* nothing executed.
|
|
976
|
+
* - true: the occurrence may already have produced side effects. Keep the
|
|
977
|
+
* conservative block; only a human can decide (double execution is worse
|
|
978
|
+
* than a stalled schedule).
|
|
979
|
+
*/
|
|
980
|
+
handleBlock(job, error, executed) {
|
|
981
|
+
const repeating = !("at" in job.schedule);
|
|
982
|
+
if (!executed && repeating && !isProcessJob(job) && !job.retriedOnce) {
|
|
983
|
+
job.retriedOnce = true;
|
|
984
|
+
job.state = "ready";
|
|
985
|
+
delete job.target;
|
|
986
|
+
delete job.deliveryStarted;
|
|
987
|
+
job.next = nextTime(job.schedule, Math.max(Date.now(), job.occurrence ?? Date.now()));
|
|
988
|
+
if (job.next === null) job.enabled = false;
|
|
989
|
+
job.error = `retried automatically after a block that never executed: ${error}`.slice(0, 500);
|
|
990
|
+
this.auditQuiet({ kind: "auto-retry", jobId: job.id, sessionId: job.sessionId, cwd: job.cwd, detail: error });
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
complete(job, error);
|
|
994
|
+
this.auditQuiet({ kind: "blocked", jobId: job.id, sessionId: job.sessionId, cwd: job.cwd, detail: error });
|
|
995
|
+
}
|
|
996
|
+
notify(job, owners) {
|
|
937
997
|
if (isProcessJob(job)) return;
|
|
938
998
|
if (job.sessionId !== this.sessionId || !job.error) return;
|
|
939
999
|
const key = job.id + job.error;
|
|
@@ -941,6 +1001,56 @@ var Runtime = class {
|
|
|
941
1001
|
this.notices.add(key);
|
|
942
1002
|
this.ctx.ui.notify(`cron ${job.id}: ${job.error}`, "warning");
|
|
943
1003
|
}
|
|
1004
|
+
this.noticeBlockedToUser(job, owners);
|
|
1005
|
+
}
|
|
1006
|
+
/** B plan (review round 2, P1-4): an unattended host has nobody reading
|
|
1007
|
+
* ui.notify or the host log, so a blocked job used to fail in total
|
|
1008
|
+
* silence — the user simply stops receiving their schedule.
|
|
1009
|
+
*
|
|
1010
|
+
* We ask the AGENT to tell the user, through the same input channel a job
|
|
1011
|
+
* delivery uses. Guards, because this costs a real turn:
|
|
1012
|
+
* - unattended hosts only (an interactive host already shows the notice);
|
|
1013
|
+
* - blocked jobs only, and only while the job still belongs to this session;
|
|
1014
|
+
* - once per job+ERROR (persisted `noticedError`), so a persistent block
|
|
1015
|
+
* cannot spam;
|
|
1016
|
+
* - bounded attempts (3) because a submission can be rejected while
|
|
1017
|
+
* ownership is uncertain (the crash case) — we then retry on a later
|
|
1018
|
+
* healthy poll instead of looping now;
|
|
1019
|
+
* - only with a single registered owner, so the input interception cannot
|
|
1020
|
+
* reject it as an ownership conflict.
|
|
1021
|
+
* The marker is written BEFORE submitting: a rejection must never loop. */
|
|
1022
|
+
noticeAttempts = /* @__PURE__ */ new Map();
|
|
1023
|
+
noticeBlockedToUser(job, owners) {
|
|
1024
|
+
if (!this.ctx.capabilities.unattended) return;
|
|
1025
|
+
if (job.state !== "blocked" || !job.error) return;
|
|
1026
|
+
if (job.noticedError === job.error) return;
|
|
1027
|
+
if (owners !== 1 || !this.ctx.isIdle()) return;
|
|
1028
|
+
const attempts = this.noticeAttempts.get(job.id) ?? 0;
|
|
1029
|
+
if (attempts >= 3) return;
|
|
1030
|
+
this.noticeAttempts.set(job.id, attempts + 1);
|
|
1031
|
+
const reason = job.error;
|
|
1032
|
+
try {
|
|
1033
|
+
this.store.transaction((state) => {
|
|
1034
|
+
const target = state.jobs.find((item) => item.id === job.id);
|
|
1035
|
+
if (target) target.noticedError = reason;
|
|
1036
|
+
});
|
|
1037
|
+
} catch {
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
this.auditQuiet({ kind: "noticed", jobId: job.id, sessionId: job.sessionId, cwd: job.cwd, detail: reason });
|
|
1041
|
+
const scope = this.ctx.beginUserInput?.(() => !this.stopped && this.sessionId === job.sessionId);
|
|
1042
|
+
if (!scope) return;
|
|
1043
|
+
const text = `[Cron notice job=${job.id}]
|
|
1044
|
+
A scheduled prompt is blocked: ${reason}
|
|
1045
|
+
Tell the user in one short message and wait for their decision. Do not resume or recreate it yourself.`;
|
|
1046
|
+
void (async () => {
|
|
1047
|
+
try {
|
|
1048
|
+
await scope.submit(text);
|
|
1049
|
+
} catch {
|
|
1050
|
+
} finally {
|
|
1051
|
+
scope.dispose();
|
|
1052
|
+
}
|
|
1053
|
+
})();
|
|
944
1054
|
}
|
|
945
1055
|
flushCompletions() {
|
|
946
1056
|
for (const [id, entry] of this.completions) {
|
|
@@ -1004,7 +1114,7 @@ var Runtime = class {
|
|
|
1004
1114
|
if (this.recovering) {
|
|
1005
1115
|
for (const job of state2.jobs) {
|
|
1006
1116
|
if (job.state === "running" && (job.target === "worker" || !job.target || !state2.owners[job.target])) {
|
|
1007
|
-
|
|
1117
|
+
this.handleBlock(job, "coordinator restarted; outcome uncertain", true);
|
|
1008
1118
|
}
|
|
1009
1119
|
}
|
|
1010
1120
|
}
|
|
@@ -1013,25 +1123,35 @@ var Runtime = class {
|
|
|
1013
1123
|
if (isProcessJob(job)) continue;
|
|
1014
1124
|
const owners = Object.entries(state2.owners).filter(([, owner]) => owner.sessionId === job.sessionId);
|
|
1015
1125
|
if (this.leader && job.state === "running" && job.target === "worker" && owners.length) this.abort.abort();
|
|
1016
|
-
if (job.enabled && owners.length > 1 && job.state !== "running")
|
|
1126
|
+
if (job.enabled && owners.length > 1 && job.state !== "running") this.handleBlock(job, "duplicate participating session owners; close duplicate and resume job", false);
|
|
1017
1127
|
if (job.state === "running" && job.target === this.id && this.accepted?.id === job.id) {
|
|
1018
1128
|
if (!this.accepted.consumed) {
|
|
1019
1129
|
for (const message of this.ctx.getMessages?.() ?? []) this.onMessage(message);
|
|
1020
1130
|
}
|
|
1021
1131
|
if (owners.length !== 1 || this.sessionId !== job.sessionId) {
|
|
1022
|
-
|
|
1023
|
-
this.accepted = void 0;
|
|
1024
|
-
} else if (this.accepted.consumed && this.accepted.busy && this.ctx.isIdle()) {
|
|
1025
|
-
complete(job, this.accepted.error);
|
|
1132
|
+
this.handleBlock(job, "owner changed or duplicate during delivery", !this.accepted.consumed);
|
|
1026
1133
|
this.accepted = void 0;
|
|
1134
|
+
this.acceptedIdlePolls = 0;
|
|
1135
|
+
} else if (this.accepted.consumed && this.accepted.busy) {
|
|
1136
|
+
if (this.ctx.isIdle()) {
|
|
1137
|
+
this.acceptedIdlePolls += 1;
|
|
1138
|
+
if (this.acceptedIdlePolls >= 2) {
|
|
1139
|
+
complete(job, this.accepted.error);
|
|
1140
|
+
this.accepted = void 0;
|
|
1141
|
+
this.acceptedIdlePolls = 0;
|
|
1142
|
+
}
|
|
1143
|
+
} else {
|
|
1144
|
+
this.acceptedIdlePolls = 0;
|
|
1145
|
+
}
|
|
1027
1146
|
} else if (!this.accepted.consumed && now - this.accepted.at > 6e4) {
|
|
1028
|
-
|
|
1147
|
+
this.handleBlock(job, "input accepted but execution not observed; inspect before resuming", true);
|
|
1029
1148
|
this.accepted = void 0;
|
|
1149
|
+
this.acceptedIdlePolls = 0;
|
|
1030
1150
|
}
|
|
1031
1151
|
}
|
|
1032
1152
|
if (job.state === "running" && job.target === this.id && !job.deliveryStarted && this.ctx.isIdle()) {
|
|
1033
1153
|
if (owners.length !== 1 || owners[0][0] !== this.id || this.sessionId !== job.sessionId || this.cwd !== job.cwd) {
|
|
1034
|
-
|
|
1154
|
+
this.handleBlock(job, "owner changed or duplicate; delivery blocked", false);
|
|
1035
1155
|
} else {
|
|
1036
1156
|
job.deliveryStarted = true;
|
|
1037
1157
|
delivery = { ...job };
|
|
@@ -1075,6 +1195,7 @@ var Runtime = class {
|
|
|
1075
1195
|
const content = `[Cron job=${job.id} scheduledAt=${job.occurrence}]
|
|
1076
1196
|
${job.prompt}`;
|
|
1077
1197
|
this.accepted = { id: job.id, at: now, busy: false, consumed: false, content };
|
|
1198
|
+
this.acceptedIdlePolls = 0;
|
|
1078
1199
|
try {
|
|
1079
1200
|
if (!scope || !await scope.submit(content)) error = "input rejected or session changed; inspect before resuming";
|
|
1080
1201
|
} catch (failure) {
|
|
@@ -1115,7 +1236,9 @@ ${job.prompt}`;
|
|
|
1115
1236
|
}
|
|
1116
1237
|
const state = this.store.read(), enabled = state.jobs.filter((job) => job.enabled);
|
|
1117
1238
|
this.ctx.ui.setStatus?.("cron", this.leader && enabled.some((job) => job.sessionId === this.sessionId || isProcessJob(job)) ? `cron: ${enabled.length} enabled, ${enabled.filter((job) => job.state === "blocked").length} blocked` : void 0);
|
|
1118
|
-
for (const job of state.jobs)
|
|
1239
|
+
for (const job of state.jobs) {
|
|
1240
|
+
this.notify(job, Object.values(state.owners).filter((owner) => owner.sessionId === job.sessionId).length);
|
|
1241
|
+
}
|
|
1119
1242
|
} catch (error) {
|
|
1120
1243
|
if (isContention(error)) {
|
|
1121
1244
|
this.ctx.ui.setStatus?.("cron", void 0);
|
|
@@ -1227,7 +1350,20 @@ function configPath() {
|
|
|
1227
1350
|
return path4.resolve(env === "~" ? homedir() : env?.startsWith("~/") ? path4.join(homedir(), env.slice(2)) : env || path4.join(homedir(), ".pie"));
|
|
1228
1351
|
}
|
|
1229
1352
|
function cron(ctx) {
|
|
1230
|
-
if (process.env.PIE_CRON_ROLE === "worker"
|
|
1353
|
+
if (process.env.PIE_CRON_ROLE === "worker") return;
|
|
1354
|
+
const capabilities = ctx.capabilities;
|
|
1355
|
+
const approvalAuthority = capabilities.approvalAuthority;
|
|
1356
|
+
if (!capabilities.longLived || approvalAuthority === "none") return;
|
|
1357
|
+
const authorizationNow = () => approvalAuthority === "unattended" ? "unattended" : ctx.yoloMode ? "yolo" : "dialog";
|
|
1358
|
+
const auditNote = (record) => {
|
|
1359
|
+
try {
|
|
1360
|
+
store.audit(record);
|
|
1361
|
+
return "";
|
|
1362
|
+
} catch (e) {
|
|
1363
|
+
return `
|
|
1364
|
+
WARNING: change applied but the audit log could not be written (${String(e)})`;
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1231
1367
|
const store = new Store(path4.join(configPath(), "cron"));
|
|
1232
1368
|
const runtime = new Runtime(ctx, store);
|
|
1233
1369
|
let startupError;
|
|
@@ -1280,14 +1416,26 @@ function cron(ctx) {
|
|
|
1280
1416
|
if (action === "list") return JSON.stringify({ ...store.read(), recoveryRequired: fs4.existsSync(path4.join(store.dir, "unsafe.lock")), coordinatorPresent: fs4.existsSync(path4.join(store.dir, "scheduler.lock")) }, null, 2);
|
|
1281
1417
|
if (action === "add") {
|
|
1282
1418
|
if (!runtime.ready || !runtime.sessionId) throw new Error("wait for an existing session to load and register");
|
|
1419
|
+
const authorization = authorizationNow();
|
|
1420
|
+
const job = store.add(runtime.sessionId, ctx.cwd, prompt, schedule, Date.now(), authorization);
|
|
1421
|
+
const note = auditNote({ kind: "add", jobId: job.id, sessionId: job.sessionId, cwd: job.cwd, authorization });
|
|
1283
1422
|
return JSON.stringify({
|
|
1284
|
-
job
|
|
1285
|
-
note: "Saved. every/cron schedules repeat until removed unless count limits total executions. Delivery resumes THIS session and each delivered turn runs the prompt once; a running delivery cannot be paused/removed until its turn settles (next poll after idle). Keep at least one cron-enabled Pie open; no execution while all are closed or the computer sleeps."
|
|
1423
|
+
job,
|
|
1424
|
+
note: "Saved. every/cron schedules repeat until removed unless count limits total executions. Delivery resumes THIS session and each delivered turn runs the prompt once; a running delivery cannot be paused/removed until its turn settles (next poll after idle). Keep at least one cron-enabled Pie open; no execution while all are closed or the computer sleeps." + note
|
|
1286
1425
|
});
|
|
1287
1426
|
}
|
|
1288
1427
|
if (action === "pause" || action === "resume" || action === "remove") {
|
|
1289
|
-
|
|
1290
|
-
|
|
1428
|
+
const jobId = id ?? "";
|
|
1429
|
+
const authorization = authorizationNow();
|
|
1430
|
+
if (action === "resume")
|
|
1431
|
+
store.transaction((s) => {
|
|
1432
|
+
const job2 = s.jobs.find((j) => j.id === jobId);
|
|
1433
|
+
if (job2) job2.authorization = authorization;
|
|
1434
|
+
});
|
|
1435
|
+
store.change(jobId, action);
|
|
1436
|
+
const job = store.read().jobs.find((j) => j.id === jobId);
|
|
1437
|
+
const note = auditNote({ kind: action, jobId, sessionId: job?.sessionId, cwd: job?.cwd, authorization });
|
|
1438
|
+
return `${action}: ${jobId}${note}`;
|
|
1291
1439
|
}
|
|
1292
1440
|
throw new Error('Usage: /tools/cron list | add {"prompt":"...","schedule":{"every":3600}} | pause|resume|remove <id>');
|
|
1293
1441
|
};
|
|
@@ -1312,15 +1460,20 @@ function cron(ctx) {
|
|
|
1312
1460
|
if (args.action !== "list") {
|
|
1313
1461
|
const sessionId = runtime.sessionId, generation = runtime.generation;
|
|
1314
1462
|
if (!runtime.ready) throw new Error("session binding is in progress; no changes saved");
|
|
1315
|
-
if (
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1463
|
+
if (approvalAuthority === "dialog") {
|
|
1464
|
+
if (!ctx.yoloMode && (!ctx.interactions.isAvailable() || !await ctx.ui.confirm(
|
|
1465
|
+
"Approve cron change",
|
|
1466
|
+
JSON.stringify({ action: args.action, id: args.id, sessionId, cwd: ctx.cwd, prompt: args.prompt, schedule: args.schedule }) + "\nTasks persist and may execute later while any participating Pie is open, using saved configuration."
|
|
1467
|
+
))) {
|
|
1468
|
+
throw new Error("cron change was not approved; no changes saved");
|
|
1469
|
+
}
|
|
1470
|
+
} else {
|
|
1471
|
+
ctx.ui.notify(`cron: unattended ${args.action}${args.id ? ` ${args.id}` : ""} auto-authorized (no dialog possible on this host)`, "warning");
|
|
1320
1472
|
}
|
|
1321
1473
|
if (!runtime.ready || generation !== runtime.generation || sessionId !== runtime.sessionId) throw new Error("session changed during approval; no changes saved");
|
|
1322
1474
|
}
|
|
1323
|
-
|
|
1475
|
+
const text = run(args.action, args.id, args.prompt, args.schedule);
|
|
1476
|
+
return { content: [{ type: "text", text: approvalAuthority === "unattended" && args.action !== "list" ? text + "\n(unattended host: no dialog was possible, so this change was auto-authorized by the host policy and logged.)" : text }] };
|
|
1324
1477
|
} catch (e) {
|
|
1325
1478
|
return { content: [{ type: "text", text: String(e) }], isError: true };
|
|
1326
1479
|
}
|