@cydm/pie 2.7.19 → 2.8.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/README.md +6 -6
- package/dist/builtin/extensions/ask-user/README.md +117 -0
- package/dist/builtin/extensions/ask-user/index.js +3 -3
- package/dist/builtin/extensions/cron/index.js +166 -23
- package/dist/builtin/extensions/im-forward/README.md +297 -0
- package/dist/builtin/extensions/im-forward/index.js +319 -42
- package/dist/builtin/extensions/init/index.js +0 -6
- package/dist/builtin/extensions/mcp-adapter/README.md +27 -0
- package/dist/builtin/extensions/memory/index.js +323 -0
- package/dist/builtin/extensions/memory/package.json +18 -0
- package/dist/builtin/extensions/pie-ipc/README.md +21 -0
- package/dist/builtin/extensions/pie-ipc/index.js +16 -16
- package/dist/builtin/extensions/plan-mode/METHOD.md +70 -0
- package/dist/builtin/extensions/plan-mode/index.js +149 -82
- package/dist/builtin/extensions/subagent/README.md +315 -0
- package/dist/builtin/extensions/subagent/index.js +7 -5
- package/dist/builtin/extensions/todo/index.js +3 -3
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/{chunk-U75F4DPF.js → chunk-BNSAEVRT.js} +201 -77
- package/dist/builtin/skills/chrome-devtools-axi/{cli-4ITIR57L.js → cli-AO2ZTPRM.js} +57 -202
- package/dist/chunks/chunk-5353DEEC.js +130 -0
- package/dist/chunks/{chunk-2H2DD22Z.js → chunk-HGC25NYB.js} +1 -1
- package/dist/chunks/{chunk-X7UO6BA6.js → chunk-JNOFHHLZ.js} +156 -65
- package/dist/chunks/{chunk-UDCGB3LZ.js → chunk-LJXHECZ7.js} +12183 -10951
- package/dist/chunks/{chunk-TGCI5M6R.js → chunk-NEES4EBX.js} +19 -141
- package/dist/chunks/{src-GX4UBAYF.js → src-5XOKRS6F.js} +2 -2
- package/dist/chunks/{test-stream-AKIZNFCM.js → test-stream-5SDHKKDB.js} +1 -1
- package/dist/cli.js +127 -96
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -261,7 +261,7 @@ Pie uses a hierarchical slash-command menu. The current built-in commands includ
|
|
|
261
261
|
| `/skills/reload` | Reload skills from disk |
|
|
262
262
|
| `/settings/extensions` | List extensions and toggle enable/disable |
|
|
263
263
|
| `/tools/subagent` | Spawn a subagent for a task |
|
|
264
|
-
| `/tools/init` | Create or update the project AGENTS.md
|
|
264
|
+
| `/tools/init` | Create or update the project AGENTS.md |
|
|
265
265
|
| `/settings/debugs/cache-test` | Run provider cache diagnostics with a dedicated 2-request probe |
|
|
266
266
|
| `/settings/debugs/context` | Append a context summary to `~/.pie/logs/pie-cli.log` |
|
|
267
267
|
| `/settings/debugs/package` | Append a package summary to `~/.pie/logs/pie-cli.log` |
|
|
@@ -284,11 +284,11 @@ This makes Pie useful for ongoing coding tasks, not just one-off prompts.
|
|
|
284
284
|
The builtin `cron` extension persists scheduled prompts bound to the original session and working directory:
|
|
285
285
|
|
|
286
286
|
```text
|
|
287
|
-
/cron add {"prompt":"Continue the investigation above.","schedule":{"every":3600}}
|
|
288
|
-
/cron list
|
|
289
|
-
/cron pause <job-id>
|
|
290
|
-
/cron resume <job-id>
|
|
291
|
-
/cron remove <job-id>
|
|
287
|
+
/tools/cron add {"prompt":"Continue the investigation above.","schedule":{"every":3600}}
|
|
288
|
+
/tools/cron list
|
|
289
|
+
/tools/cron pause <job-id>
|
|
290
|
+
/tools/cron resume <job-id>
|
|
291
|
+
/tools/cron remove <job-id>
|
|
292
292
|
```
|
|
293
293
|
|
|
294
294
|
Keep at least one cron-enabled interactive Pie open in the same config space. The original session need not stay open: an unhosted session is resumed by a temporary worker, while a hosted session receives an ordinary follow-up. No task means no footer or startup notification; unrelated/follower windows remain quiet. Five-field cron schedules use **UTC**. Model-requested changes require explicit confirmation.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Ask User Extension for Pie
|
|
2
|
+
|
|
3
|
+
Interactive question tool with "Other" option, back navigation, and multi-question flow.
|
|
4
|
+
|
|
5
|
+
## Tool
|
|
6
|
+
|
|
7
|
+
### `ask_user_multi`
|
|
8
|
+
|
|
9
|
+
Ask multiple questions with review and edit capability.
|
|
10
|
+
|
|
11
|
+
#### Parameters
|
|
12
|
+
|
|
13
|
+
| Parameter | Type | Default | Description |
|
|
14
|
+
|-----------|------|---------|-------------|
|
|
15
|
+
| `questions` | array | **required** | Array of question objects |
|
|
16
|
+
| `allowReview` | boolean | `true` | Allow review at the end |
|
|
17
|
+
|
|
18
|
+
Each question object:
|
|
19
|
+
```typescript
|
|
20
|
+
{
|
|
21
|
+
id: string, // Unique identifier
|
|
22
|
+
question: string, // Question text
|
|
23
|
+
options?: string[], // Options (if multiple-choice)
|
|
24
|
+
allowOther?: boolean, // Default: true
|
|
25
|
+
placeholder?: string // For Other/open-ended
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
#### Example
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"questions": [
|
|
34
|
+
{
|
|
35
|
+
"id": "project_name",
|
|
36
|
+
"question": "What is your project name?",
|
|
37
|
+
"placeholder": "my-awesome-project"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"id": "language",
|
|
41
|
+
"question": "Which programming language?",
|
|
42
|
+
"options": ["Python", "JavaScript", "Go", "Rust"]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"id": "framework",
|
|
46
|
+
"question": "Which framework?",
|
|
47
|
+
"options": ["React", "Vue", "Svelte"]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"id": "confirm",
|
|
51
|
+
"question": "Ready to generate?",
|
|
52
|
+
"options": ["Yes", "No, let me change something"],
|
|
53
|
+
"allowOther": false
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### Flow
|
|
60
|
+
|
|
61
|
+
1. **Question 1/4**: Project name? → [input field]
|
|
62
|
+
2. **Question 2/4**: Language? → A. Python B. JavaScript C. Go D. Rust E. ✏️ Other F. ← Back
|
|
63
|
+
3. **Question 3/4**: Framework? → [options + Other + Back]
|
|
64
|
+
4. **Question 4/4**: Ready? → [Yes / No + Back]
|
|
65
|
+
5. **Review screen**:
|
|
66
|
+
- A. ✓ Confirm and continue
|
|
67
|
+
- B. ✏️ Edit Q1: Project name?
|
|
68
|
+
- C. ✏️ Edit Q2: Which programming...
|
|
69
|
+
- D. ✏️ Edit Q3: Which framework?
|
|
70
|
+
- E. ✏️ Edit Q4: Ready to generate?
|
|
71
|
+
- F. ↺ Restart all
|
|
72
|
+
|
|
73
|
+
#### Returns
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"project_name": { "answer": "MyApp", "question": "What is your project name?" },
|
|
78
|
+
"language": { "answer": "TypeScript", "question": "Which programming language?", "isOther": true },
|
|
79
|
+
"framework": { "answer": "React", "question": "Which framework?", "selectedIndex": 0 },
|
|
80
|
+
"confirm": { "answer": "Yes", "question": "Ready to generate?", "selectedIndex": 0 }
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## When to Use
|
|
85
|
+
|
|
86
|
+
Use `ask_user_multi` for:
|
|
87
|
+
- Collecting multiple pieces of information
|
|
88
|
+
- Asking a single question
|
|
89
|
+
- Wizard-style flow
|
|
90
|
+
- User might want to go back and change answers
|
|
91
|
+
- Need review before proceeding
|
|
92
|
+
|
|
93
|
+
## UX Features
|
|
94
|
+
|
|
95
|
+
### "Other" Option
|
|
96
|
+
- Always available (unless disabled with `allowOther: false`)
|
|
97
|
+
- Selecting it opens input dialog
|
|
98
|
+
- Answer returned as "Other: [custom text]"
|
|
99
|
+
|
|
100
|
+
### Back Navigation
|
|
101
|
+
- Add `allowBack: true` for single question
|
|
102
|
+
- Always available in multi-question flow (except first question)
|
|
103
|
+
- Selecting "← Back" returns to previous question
|
|
104
|
+
|
|
105
|
+
### Progress Indicator
|
|
106
|
+
Multi-question shows progress: "1/4: Question text?"
|
|
107
|
+
|
|
108
|
+
### Review Phase
|
|
109
|
+
At the end of the flow:
|
|
110
|
+
- See all answers at a glance
|
|
111
|
+
- Edit any specific question
|
|
112
|
+
- Restart entire flow
|
|
113
|
+
- Confirm to proceed
|
|
114
|
+
|
|
115
|
+
## Installation
|
|
116
|
+
|
|
117
|
+
Built-in with Pie CLI. Extension auto-loads from `builtin/extensions/ask-user/`.
|
|
@@ -1,9 +1,9 @@
|
|
|
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-
|
|
6
|
-
import "../../../chunks/chunk-
|
|
4
|
+
} from "../../../chunks/chunk-LJXHECZ7.js";
|
|
5
|
+
import "../../../chunks/chunk-HGC25NYB.js";
|
|
6
|
+
import "../../../chunks/chunk-JNOFHHLZ.js";
|
|
7
7
|
import "../../../chunks/chunk-XXGYUYXI.js";
|
|
8
8
|
import "../../../chunks/chunk-LZQXQOPJ.js";
|
|
9
9
|
|
|
@@ -35,18 +35,25 @@ function fields(expression) {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
function validateSchedule(value) {
|
|
38
|
-
if (!value || typeof value !== "object"
|
|
38
|
+
if (!value || typeof value !== "object") throw new Error("provide exactly one of at, every, cron");
|
|
39
39
|
const s = value;
|
|
40
|
+
const scheduleKeys = ["at", "every", "cron"].filter((k) => k in s);
|
|
41
|
+
if (scheduleKeys.length !== 1) throw new Error("provide exactly one of at, every, cron");
|
|
42
|
+
if (Object.keys(value).length - scheduleKeys.length > 1) throw new Error("only the optional count may accompany at/every/cron");
|
|
43
|
+
const count = s.count;
|
|
44
|
+
const countValid = count === void 0 || typeof count === "number" && Number.isSafeInteger(count) && count >= 1 && count <= 1e3;
|
|
45
|
+
if (!countValid) throw new Error("count must be an integer 1..1000 (total executions)");
|
|
40
46
|
if ("at" in s && typeof s.at === "string") {
|
|
47
|
+
if (count !== void 0) throw new Error("at is one-shot; count applies only to every/cron");
|
|
41
48
|
const m = s.at.match(/^(\d{4})-(\d\d)-(\d\d)T(\d\d):(\d\d)(?::(\d\d)(?:\.\d{1,3})?)?(?:Z|[+-]\d\d:\d\d)$/);
|
|
42
49
|
if (m && +m[1] >= 1970 && +m[2] >= 1 && +m[2] <= 12 && +m[3] >= 1 && +m[3] <= new Date(Date.UTC(+m[1], +m[2], 0)).getUTCDate() && +m[4] < 24 && +m[5] < 60 && +(m[6] ?? 0) < 60 && Number.isFinite(Date.parse(s.at))) return s;
|
|
43
50
|
}
|
|
44
|
-
if ("every" in s && Number.isSafeInteger(s.every) && s.every >= 60 && s.every <= 31536e3) return s;
|
|
45
|
-
if ("cron" in s && typeof s.cron === "string" && s.cron.length <= 256) {
|
|
51
|
+
if ("every" in s && Number.isSafeInteger(s.every) && s.every >= 60 && s.every <= 31536e3 && countValid) return s;
|
|
52
|
+
if ("cron" in s && typeof s.cron === "string" && s.cron.length <= 256 && countValid) {
|
|
46
53
|
fields(s.cron);
|
|
47
54
|
return s;
|
|
48
55
|
}
|
|
49
|
-
throw new Error("invalid schedule (every: integer seconds 60..31536000; at: ISO timestamp with timezone)");
|
|
56
|
+
throw new Error("invalid schedule (every: integer seconds 60..31536000; at: ISO timestamp with timezone; count: integer 1..1000 for every/cron)");
|
|
50
57
|
}
|
|
51
58
|
function nextTime(s, after) {
|
|
52
59
|
if ("at" in s) return Date.parse(s.at) > after ? Date.parse(s.at) : null;
|
|
@@ -115,7 +122,7 @@ var Store = class {
|
|
|
115
122
|
if (Array.isArray(s.owners) || s.jobs.length > 100 || Object.keys(s.owners).length > 1e3) throw new Error("cron state exceeds record limit");
|
|
116
123
|
const ids = /* @__PURE__ */ new Set();
|
|
117
124
|
for (const j of s.jobs) {
|
|
118
|
-
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.next !== null && !Number.isSafeInteger(j.next)) throw new Error("invalid cron job; manual recovery required");
|
|
125
|
+
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");
|
|
119
126
|
ids.add(j.id);
|
|
120
127
|
validateSchedule(j.schedule);
|
|
121
128
|
}
|
|
@@ -166,7 +173,18 @@ var Store = class {
|
|
|
166
173
|
if (typeof prompt !== "string" || !prompt.trim() || prompt.length > 16e3) throw new Error("prompt must contain 1..16000 characters");
|
|
167
174
|
const validated = validateSchedule(schedule), next = nextTime(validated, now);
|
|
168
175
|
if (next === null) throw new Error("at must be in the future");
|
|
169
|
-
const
|
|
176
|
+
const count = validated.count;
|
|
177
|
+
const job = {
|
|
178
|
+
id: randomUUID(),
|
|
179
|
+
sessionId,
|
|
180
|
+
cwd: fs.realpathSync(cwd),
|
|
181
|
+
prompt,
|
|
182
|
+
schedule: validated,
|
|
183
|
+
enabled: true,
|
|
184
|
+
next,
|
|
185
|
+
state: "ready",
|
|
186
|
+
...count !== void 0 ? { remaining: count } : {}
|
|
187
|
+
};
|
|
170
188
|
return this.transaction((s) => {
|
|
171
189
|
if (s.jobs.length >= 100) throw new Error("maximum 100 jobs");
|
|
172
190
|
s.jobs.push(job);
|
|
@@ -202,6 +220,14 @@ function complete(job, error, now = Date.now()) {
|
|
|
202
220
|
}
|
|
203
221
|
job.state = "ready";
|
|
204
222
|
delete job.error;
|
|
223
|
+
if (job.remaining !== void 0) {
|
|
224
|
+
job.remaining -= 1;
|
|
225
|
+
if (job.remaining <= 0) {
|
|
226
|
+
job.enabled = false;
|
|
227
|
+
job.next = "at" in job.schedule ? null : job.next;
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
205
231
|
job.next = "at" in job.schedule ? null : nextTime(job.schedule, Math.max(now, job.occurrence ?? now));
|
|
206
232
|
if (job.next === null) job.enabled = false;
|
|
207
233
|
}
|
|
@@ -319,16 +345,28 @@ function runWorker(job, signal, cli = process.argv[1], configDir) {
|
|
|
319
345
|
// builtin/extensions/cron/runtime.ts
|
|
320
346
|
var delay = (ms) => new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
321
347
|
var isContention = (error) => error?.code === "EEXIST";
|
|
348
|
+
var COORDINATOR_OWNER_FILE = "owner.json";
|
|
349
|
+
var COORDINATOR_METADATA_GRACE_MS = 5e3;
|
|
350
|
+
function defaultProcessAlive(pid) {
|
|
351
|
+
try {
|
|
352
|
+
process.kill(pid, 0);
|
|
353
|
+
return true;
|
|
354
|
+
} catch (error) {
|
|
355
|
+
return error?.code !== "ESRCH";
|
|
356
|
+
}
|
|
357
|
+
}
|
|
322
358
|
var Runtime = class {
|
|
323
|
-
constructor(ctx, store, execute = runWorker) {
|
|
359
|
+
constructor(ctx, store, execute = runWorker, processAlive = defaultProcessAlive) {
|
|
324
360
|
this.ctx = ctx;
|
|
325
361
|
this.store = store;
|
|
326
362
|
this.execute = execute;
|
|
363
|
+
this.processAlive = processAlive;
|
|
327
364
|
this.cwd = fs2.realpathSync(ctx.cwd);
|
|
328
365
|
}
|
|
329
366
|
ctx;
|
|
330
367
|
store;
|
|
331
368
|
execute;
|
|
369
|
+
processAlive;
|
|
332
370
|
id = randomUUID3();
|
|
333
371
|
sessionId = null;
|
|
334
372
|
leader = false;
|
|
@@ -344,6 +382,8 @@ var Runtime = class {
|
|
|
344
382
|
notices = /* @__PURE__ */ new Set();
|
|
345
383
|
completions = /* @__PURE__ */ new Map();
|
|
346
384
|
accepted;
|
|
385
|
+
unreadableCoordinatorSince;
|
|
386
|
+
coordinatorNotices = /* @__PURE__ */ new Set();
|
|
347
387
|
get ready() {
|
|
348
388
|
return this.initialized && !this.stopped;
|
|
349
389
|
}
|
|
@@ -372,6 +412,97 @@ var Runtime = class {
|
|
|
372
412
|
markUnsafe() {
|
|
373
413
|
fs2.mkdirSync(path3.join(this.store.dir, "unsafe.lock"), { recursive: true, mode: 448 });
|
|
374
414
|
}
|
|
415
|
+
coordinatorDir() {
|
|
416
|
+
return path3.join(this.store.dir, "scheduler.lock");
|
|
417
|
+
}
|
|
418
|
+
coordinatorOwnerFile() {
|
|
419
|
+
return path3.join(this.coordinatorDir(), COORDINATOR_OWNER_FILE);
|
|
420
|
+
}
|
|
421
|
+
readCoordinatorOwner() {
|
|
422
|
+
try {
|
|
423
|
+
const file = this.coordinatorOwnerFile(), stat = fs2.lstatSync(file);
|
|
424
|
+
if (!stat.isFile() || stat.size > 4096) return void 0;
|
|
425
|
+
const raw = fs2.readFileSync(file, "utf8"), value = JSON.parse(raw);
|
|
426
|
+
if (value?.version !== 1 || !Number.isSafeInteger(value.pid) || value.pid <= 0 || typeof value.instanceId !== "string" || !value.instanceId || value.instanceId.length > 128 || !Number.isSafeInteger(value.createdAt)) return void 0;
|
|
427
|
+
return { value, raw };
|
|
428
|
+
} catch {
|
|
429
|
+
return void 0;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
noteCoordinatorMetadata(valid, now) {
|
|
433
|
+
if (valid) {
|
|
434
|
+
this.unreadableCoordinatorSince = void 0;
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
if (this.unreadableCoordinatorSince === void 0) {
|
|
438
|
+
this.unreadableCoordinatorSince = now;
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (this.coordinatorNotices.has("metadata") || now - this.unreadableCoordinatorSince < COORDINATOR_METADATA_GRACE_MS) return;
|
|
442
|
+
this.coordinatorNotices.add("metadata");
|
|
443
|
+
this.ctx.ui.notify("cron: coordinator lock metadata is missing or invalid; scheduling is paused. See docs/cron.md offline recovery.", "warning");
|
|
444
|
+
}
|
|
445
|
+
withCoordinatorMutex(fn) {
|
|
446
|
+
const lock = path3.join(this.store.dir, "write.lock");
|
|
447
|
+
fs2.mkdirSync(lock, { mode: 448 });
|
|
448
|
+
try {
|
|
449
|
+
return fn();
|
|
450
|
+
} finally {
|
|
451
|
+
fs2.rmdirSync(lock);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
acquireCoordinator() {
|
|
455
|
+
const dir = this.coordinatorDir();
|
|
456
|
+
fs2.mkdirSync(dir, { mode: 448 });
|
|
457
|
+
const owner = { version: 1, pid: process.pid, instanceId: this.id, createdAt: Date.now() };
|
|
458
|
+
try {
|
|
459
|
+
fs2.writeFileSync(this.coordinatorOwnerFile(), JSON.stringify(owner), { mode: 384, flag: "wx" });
|
|
460
|
+
} catch (error) {
|
|
461
|
+
try {
|
|
462
|
+
fs2.unlinkSync(this.coordinatorOwnerFile());
|
|
463
|
+
} catch {
|
|
464
|
+
}
|
|
465
|
+
try {
|
|
466
|
+
fs2.rmdirSync(dir);
|
|
467
|
+
} catch {
|
|
468
|
+
}
|
|
469
|
+
throw error;
|
|
470
|
+
}
|
|
471
|
+
this.leader = true;
|
|
472
|
+
this.recovering = true;
|
|
473
|
+
this.noteCoordinatorMetadata(true, Date.now());
|
|
474
|
+
}
|
|
475
|
+
reclaimDeadCoordinator(now) {
|
|
476
|
+
const held = this.readCoordinatorOwner();
|
|
477
|
+
if (!held) {
|
|
478
|
+
this.noteCoordinatorMetadata(false, now);
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
this.noteCoordinatorMetadata(true, now);
|
|
482
|
+
if (this.processAlive(held.value.pid)) return false;
|
|
483
|
+
if (this.store.read().jobs.some((job) => job.state === "running")) {
|
|
484
|
+
const key = `running:${held.value.instanceId}`;
|
|
485
|
+
if (!this.coordinatorNotices.has(key)) {
|
|
486
|
+
this.coordinatorNotices.add(key);
|
|
487
|
+
this.ctx.ui.notify("cron: dead coordinator has running work; scheduling remains paused for offline recovery.", "warning");
|
|
488
|
+
}
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
const latest = this.readCoordinatorOwner();
|
|
492
|
+
if (!latest || latest.raw !== held.raw) return false;
|
|
493
|
+
try {
|
|
494
|
+
fs2.unlinkSync(this.coordinatorOwnerFile());
|
|
495
|
+
fs2.rmdirSync(this.coordinatorDir());
|
|
496
|
+
return true;
|
|
497
|
+
} catch {
|
|
498
|
+
return false;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
releaseCoordinator() {
|
|
502
|
+
fs2.rmSync(this.coordinatorOwnerFile(), { force: true });
|
|
503
|
+
fs2.rmdirSync(this.coordinatorDir());
|
|
504
|
+
this.leader = false;
|
|
505
|
+
}
|
|
375
506
|
persistOwner(sessionId) {
|
|
376
507
|
this.store.transaction((state) => {
|
|
377
508
|
state.owners[this.id] = { sessionId, cwd: this.cwd, busy: !this.ctx.isIdle() };
|
|
@@ -439,15 +570,20 @@ var Runtime = class {
|
|
|
439
570
|
try {
|
|
440
571
|
this.flushCompletions();
|
|
441
572
|
if (this.completions.size) return;
|
|
442
|
-
if (!this.leader) {
|
|
573
|
+
if (!this.leader) this.withCoordinatorMutex(() => {
|
|
443
574
|
try {
|
|
444
|
-
|
|
445
|
-
this.leader = true;
|
|
446
|
-
this.recovering = true;
|
|
575
|
+
this.acquireCoordinator();
|
|
447
576
|
} catch (error) {
|
|
448
577
|
if (!isContention(error)) throw error;
|
|
578
|
+
if (this.reclaimDeadCoordinator(now)) {
|
|
579
|
+
try {
|
|
580
|
+
this.acquireCoordinator();
|
|
581
|
+
} catch (failure) {
|
|
582
|
+
if (!isContention(failure)) throw failure;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
449
585
|
}
|
|
450
|
-
}
|
|
586
|
+
});
|
|
451
587
|
let delivery, launch;
|
|
452
588
|
this.store.transaction((state2) => {
|
|
453
589
|
if (this.recovering) {
|
|
@@ -578,8 +714,15 @@ ${job.prompt}`;
|
|
|
578
714
|
}
|
|
579
715
|
}
|
|
580
716
|
if (this.leader) {
|
|
581
|
-
|
|
582
|
-
|
|
717
|
+
for (let attempt = 0; ; attempt++) {
|
|
718
|
+
try {
|
|
719
|
+
this.withCoordinatorMutex(() => this.releaseCoordinator());
|
|
720
|
+
break;
|
|
721
|
+
} catch (error) {
|
|
722
|
+
if (!isContention(error) || attempt >= 39) throw error;
|
|
723
|
+
await delay(25 + Math.floor(Math.random() * 25));
|
|
724
|
+
}
|
|
725
|
+
}
|
|
583
726
|
}
|
|
584
727
|
this.ctx.ui.setStatus?.("cron", void 0);
|
|
585
728
|
}
|
|
@@ -614,7 +757,7 @@ function cron(ctx) {
|
|
|
614
757
|
}
|
|
615
758
|
});
|
|
616
759
|
ctx.on("terminal:input", (e) => {
|
|
617
|
-
if (/^\/cron(?:\s|$)/.test(e.text)) return;
|
|
760
|
+
if (/^\/tools\/cron(?:\s|$)/.test(e.text)) return;
|
|
618
761
|
try {
|
|
619
762
|
const state = store.read();
|
|
620
763
|
if (!state.jobs.some((j) => j.sessionId === runtime.sessionId && (j.enabled || j.state === "running"))) return;
|
|
@@ -623,7 +766,7 @@ function cron(ctx) {
|
|
|
623
766
|
if (!startupError && runtime.ready && !duplicates && !worker && !fs3.existsSync(path4.join(store.dir, "unsafe.lock"))) return;
|
|
624
767
|
} catch {
|
|
625
768
|
}
|
|
626
|
-
ctx.ui.notify("cron: session ownership is uncertain or duplicated; input blocked. Close the duplicate/worker and inspect /cron.", "warning");
|
|
769
|
+
ctx.ui.notify("cron: session ownership is uncertain or duplicated; input blocked. Close the duplicate/worker and inspect /tools/cron.", "warning");
|
|
627
770
|
return { action: "reject" };
|
|
628
771
|
});
|
|
629
772
|
ctx.on("session:before_switch", (e) => {
|
|
@@ -646,16 +789,16 @@ function cron(ctx) {
|
|
|
646
789
|
if (!runtime.ready || !runtime.sessionId) throw new Error("wait for an existing session to load and register");
|
|
647
790
|
return JSON.stringify({
|
|
648
791
|
job: store.add(runtime.sessionId, ctx.cwd, prompt, schedule),
|
|
649
|
-
note: "Saved.
|
|
792
|
+
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."
|
|
650
793
|
});
|
|
651
794
|
}
|
|
652
795
|
if (action === "pause" || action === "resume" || action === "remove") {
|
|
653
796
|
store.change(id ?? "", action);
|
|
654
797
|
return `${action}: ${id}`;
|
|
655
798
|
}
|
|
656
|
-
throw new Error('Usage: /cron list | add {"prompt":"...","schedule":{"every":3600}} | pause|resume|remove <id>');
|
|
799
|
+
throw new Error('Usage: /tools/cron list | add {"prompt":"...","schedule":{"every":3600}} | pause|resume|remove <id>');
|
|
657
800
|
};
|
|
658
|
-
ctx.registerCommand({ path: ["cron"], description: "Persistent same-session schedules (UTC): list/add/pause/resume/remove", handler: async (_ctx, args) => {
|
|
801
|
+
ctx.registerCommand({ path: ["tools", "cron"], description: "Persistent same-session schedules (UTC): list/add/pause/resume/remove", handler: async (_ctx, args) => {
|
|
659
802
|
try {
|
|
660
803
|
const match = (args ?? "").trim().match(/^(\S+)(?:\s+([\s\S]*))?$/);
|
|
661
804
|
const action = match?.[1] ?? "list", rest = match?.[2];
|
|
@@ -668,18 +811,18 @@ function cron(ctx) {
|
|
|
668
811
|
ctx.registerTool({
|
|
669
812
|
name: "cron_manage",
|
|
670
813
|
label: "Cron",
|
|
671
|
-
description:
|
|
672
|
-
parameters: Type.Object({ action: Type.Union(["list", "add", "pause", "resume", "remove"].map((s) => Type.Literal(s))), id: Type.Optional(Type.String()), prompt: Type.Optional(Type.String({ maxLength: 16e3 })), schedule: Type.Optional(Type.Union([Type.Object({ at: Type.String() }), Type.Object({ every: Type.Integer({ minimum: 60, maximum: 31536e3 }) }), Type.Object({ cron: Type.String({ maxLength: 256 }) })])) }),
|
|
814
|
+
description: 'Manage persistent scheduled prompts bound to THIS existing session and cwd. No new sessions. Actions list/add/pause/resume/remove. every is seconds (minimum 60) and REPEATS FOREVER until removed; at is one-shot; cron is five numeric UTC fields. Add optional count (integer 1..1000) to every/cron to auto-disable after that many executions \u2014 prefer {"every":60,"count":5} over manual removal for N-time notifications. Missed intervals coalesce; blocked/uncertain tasks require human review before resume. remove/pause fail with "job is running" while a delivery is in flight; retry after the delivered turn settles.',
|
|
815
|
+
parameters: Type.Object({ action: Type.Union(["list", "add", "pause", "resume", "remove"].map((s) => Type.Literal(s))), id: Type.Optional(Type.String()), prompt: Type.Optional(Type.String({ maxLength: 16e3 })), schedule: Type.Optional(Type.Union([Type.Object({ at: Type.String() }), Type.Object({ every: Type.Integer({ minimum: 60, maximum: 31536e3 }), count: Type.Optional(Type.Integer({ minimum: 1, maximum: 1e3 })) }), Type.Object({ cron: Type.String({ maxLength: 256 }), count: Type.Optional(Type.Integer({ minimum: 1, maximum: 1e3 })) })])) }),
|
|
673
816
|
risk: { riskClass: "external_side_effect", permissionScope: "host", availableInPlanMode: false, requiresPermission: true, externalSideEffect: true, allowedForSubagentByDefault: false, concurrencySafe: false },
|
|
674
817
|
execute: async (args) => {
|
|
675
818
|
try {
|
|
676
819
|
if (args.action !== "list") {
|
|
677
820
|
const sessionId = runtime.sessionId, generation = runtime.generation;
|
|
678
821
|
if (!runtime.ready) throw new Error("session binding is in progress; no changes saved");
|
|
679
|
-
if (!ctx.interactions.isAvailable() || !await ctx.ui.confirm(
|
|
822
|
+
if (!ctx.yoloMode && (!ctx.interactions.isAvailable() || !await ctx.ui.confirm(
|
|
680
823
|
"Approve cron change",
|
|
681
824
|
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."
|
|
682
|
-
)) {
|
|
825
|
+
))) {
|
|
683
826
|
throw new Error("cron change was not approved; no changes saved");
|
|
684
827
|
}
|
|
685
828
|
if (!runtime.ready || generation !== runtime.generation || sessionId !== runtime.sessionId) throw new Error("session changed during approval; no changes saved");
|