@cydm/pie 2.8.1 → 4.0.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 +8 -4
- package/dist/builtin/extensions/changelog/index.js +2 -2
- package/dist/builtin/extensions/cron/index.js +295 -33
- package/dist/builtin/extensions/document-attachments/index.js +1 -1
- package/dist/builtin/extensions/herdr-agent-state/index.js +2 -2
- package/dist/builtin/extensions/im-forward/README.md +20 -5
- package/dist/builtin/extensions/im-forward/index.js +415 -142
- package/dist/builtin/extensions/memory/index.js +83 -30
- package/dist/builtin/extensions/pie-ipc/README.md +2 -2
- package/dist/builtin/extensions/pie-ipc/index.js +269 -30
- package/dist/builtin/extensions/pie-proc/README.md +93 -0
- package/dist/builtin/extensions/pie-proc/index.js +630 -0
- package/dist/builtin/extensions/pie-proc/package.json +11 -0
- package/dist/builtin/extensions/plan-mode/index.js +4 -4
- package/dist/builtin/extensions/subagent/index.js +6 -6
- package/dist/builtin/extensions/todo/index.js +4 -4
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +106 -2
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-cli.js +1 -0
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/{chunk-BNSAEVRT.js → chunk-WOGAQ4P5.js} +2 -2
- package/dist/builtin/skills/chrome-devtools-axi/{cli-AO2ZTPRM.js → cli-CHC7XYFU.js} +27 -3
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +2 -2
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-cli.js +1 -0
- package/dist/builtin/skills/computer-use-axi/scripts/setup-helper.mjs +6 -2
- package/dist/builtin/skills/tui-use/tui-use-daemon.cjs +179 -9
- package/dist/chunks/{chunk-PK72LVWQ.js → chunk-FDLLNPIE.js} +143 -53
- package/dist/chunks/{chunk-3BC5KGDQ.js → chunk-JQRZLVPY.js} +12 -1
- package/dist/chunks/{chunk-GH4VW2OT.js → chunk-NCP264ZE.js} +8 -2
- package/dist/chunks/{chunk-YRR6C43W.js → chunk-QX6WS73C.js} +1 -1
- package/dist/chunks/{chunk-3NHP7HK5.js → chunk-TDKNKNPL.js} +6 -5
- package/dist/chunks/{chunk-GDIYSMTS.js → chunk-UOZHQ73X.js} +25 -17
- package/dist/chunks/{chunk-RSL7E4R7.js → chunk-WK4N5HT5.js} +66 -23
- package/dist/chunks/chunk-X6LBWHK3.js +37 -0
- package/dist/chunks/concierge-cli-PIOGXKDR.js +939 -0
- package/dist/chunks/{model-registry-LI5THXV4.js → model-registry-YA6U366L.js} +2 -2
- package/dist/chunks/{src-BPSQMSSC.js → src-AB7PLORG.js} +6 -4
- package/dist/chunks/{src-YG5M2H44.js → src-ODLT57PQ.js} +2 -2
- package/dist/chunks/{src-66XSMIAM.js → src-XSLD2IQ2.js} +1 -1
- package/dist/chunks/{src-OPPYTPWG.js → src-ZZZO4HSR.js} +11 -3
- package/dist/chunks/{test-stream-JBWXKOQA.js → test-stream-GIUD5JWS.js} +1 -1
- package/dist/cli.js +1433 -235
- package/package.json +105 -105
|
@@ -1,16 +1,20 @@
|
|
|
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-
|
|
7
|
-
import "../../../chunks/chunk-
|
|
4
|
+
} from "../../../chunks/chunk-FDLLNPIE.js";
|
|
5
|
+
import "../../../chunks/chunk-WK4N5HT5.js";
|
|
6
|
+
import "../../../chunks/chunk-NCP264ZE.js";
|
|
7
|
+
import "../../../chunks/chunk-JQRZLVPY.js";
|
|
8
8
|
import "../../../chunks/chunk-XXGYUYXI.js";
|
|
9
9
|
import "../../../chunks/chunk-LZQXQOPJ.js";
|
|
10
10
|
|
|
11
11
|
// builtin/extensions/ask-user/index.ts
|
|
12
12
|
function askUserExtension(ctx) {
|
|
13
13
|
ctx.log("Ask user extension loaded");
|
|
14
|
+
if (!ctx.interactions.isAvailable()) {
|
|
15
|
+
ctx.log("Ask user extension dormant: host has no interactive UI");
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
14
18
|
const capability = createAskUserCapability();
|
|
15
19
|
ctx.registerTool(capability.tools[0]);
|
|
16
20
|
}
|
|
@@ -12,7 +12,7 @@ function getRecentCommits(cwd, count = 10) {
|
|
|
12
12
|
const result = spawnSync(
|
|
13
13
|
"git",
|
|
14
14
|
["log", `--max-count=${count}`, "--pretty=format:%h %s", "--no-merges"],
|
|
15
|
-
{ cwd, encoding: "utf8" }
|
|
15
|
+
{ cwd, encoding: "utf8", windowsHide: true }
|
|
16
16
|
);
|
|
17
17
|
return result.status === 0 ? result.stdout : "";
|
|
18
18
|
} catch {
|
|
@@ -24,7 +24,7 @@ function getChangedFiles(cwd) {
|
|
|
24
24
|
const result = spawnSync(
|
|
25
25
|
"git",
|
|
26
26
|
["diff", RECENT_COMMIT_RANGE, "--name-only", "--stat"],
|
|
27
|
-
{ cwd, encoding: "utf8" }
|
|
27
|
+
{ cwd, encoding: "utf8", windowsHide: true }
|
|
28
28
|
);
|
|
29
29
|
return result.status === 0 ? result.stdout : "";
|
|
30
30
|
} catch {
|
|
@@ -100,16 +100,155 @@ var Store = class {
|
|
|
100
100
|
* stale bytes over a newer foreign save. */
|
|
101
101
|
lastSavedContent;
|
|
102
102
|
transaction(fn) {
|
|
103
|
-
|
|
104
|
-
fs.mkdirSync(lock, { mode: 448 });
|
|
105
|
-
try {
|
|
103
|
+
return this.withWriteLock(() => {
|
|
106
104
|
this.calibrateCache();
|
|
107
|
-
const state = this.
|
|
105
|
+
const state = this.readForRepair();
|
|
108
106
|
const result = fn(state);
|
|
109
107
|
this.save(state);
|
|
110
108
|
return result;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** Run fn under the cross-process write mutex. Also used for coordinator
|
|
112
|
+
* election/release, which never nest a state transaction. */
|
|
113
|
+
withWriteLock(fn) {
|
|
114
|
+
const lock = path.join(this.dir, "write.lock");
|
|
115
|
+
const token = this.acquireWriteLock(lock);
|
|
116
|
+
try {
|
|
117
|
+
return fn();
|
|
111
118
|
} finally {
|
|
119
|
+
this.releaseWriteLock(lock, token);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** Mutex protocol (generation-safe; no ABA / no TOCTOU on the canonical path):
|
|
123
|
+
* - Acquisition builds a fully-formed candidate dir `write.lock.acquire.<uuid>`
|
|
124
|
+
* containing our `held.<uuid>` entry (pid), then atomically RENAMES it onto
|
|
125
|
+
* the canonical `write.lock`. POSIX rename can displace an EMPTY existing
|
|
126
|
+
* directory (a releasing holder's post-unlink state, or manual debris); a
|
|
127
|
+
* non-empty target fails (ENOTEMPTY/EEXIST/EPERM). So the canonical path
|
|
128
|
+
* only ever transitions absent→held or empty→held, never live→replaced.
|
|
129
|
+
* - Empty-dir takeover is safe ONLY for release leftovers: a holder unlinks
|
|
130
|
+
* its entry only AFTER leaving its critical section. Manual/legacy empty
|
|
131
|
+
* locks are equally taken over — an empty dir proves no cooperative
|
|
132
|
+
* writer is inside — which replaces the old permanent-deadlock behavior
|
|
133
|
+
* with bounded manual-recovery documented in docs/cron.md (tests updated).
|
|
134
|
+
* - Release: unlink OUR entry, then rmdir if empty. A crash before unlink
|
|
135
|
+
* leaves a dead-pid entry (recoverable); after unlink it leaves an empty
|
|
136
|
+
* dir, which the next contender takes over legitimately.
|
|
137
|
+
* - Crash recovery on contention: every `held.*` entry must record a
|
|
138
|
+
* PROVABLY DEAD pid (ESRCH only); exactly those verified entries are
|
|
139
|
+
* unlinked and the emptied dir removed, then the install retried once.
|
|
140
|
+
* Entries have unique uuid names, so a delayed reclaimer only deletes
|
|
141
|
+
* names it verified — it can never touch a successor's fresh generation.
|
|
142
|
+
* Unreadable/malformed metadata or junk files: fail closed (contention).
|
|
143
|
+
* - `write.lock.acquire.*` debris can only appear from a crash mid-acquire
|
|
144
|
+
* (before the rename); it is inert — the protocol never consults it. */
|
|
145
|
+
acquireWriteLock(lock) {
|
|
146
|
+
const token = randomUUID();
|
|
147
|
+
const candidate = path.join(this.dir, `write.lock.acquire.${token}`);
|
|
148
|
+
try {
|
|
149
|
+
fs.mkdirSync(candidate, { mode: 448 });
|
|
150
|
+
try {
|
|
151
|
+
this.writeHolderEntry(candidate, token);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
try {
|
|
154
|
+
fs.rmSync(candidate, { recursive: true, force: true });
|
|
155
|
+
} catch {
|
|
156
|
+
}
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
const deadline = Date.now() + 2e3;
|
|
160
|
+
for (let spin = 0; ; spin++) {
|
|
161
|
+
try {
|
|
162
|
+
fs.renameSync(candidate, lock);
|
|
163
|
+
return token;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
const code = error?.code;
|
|
166
|
+
if (code !== "EEXIST" && code !== "ENOTEMPTY" && code !== "EPERM" && code !== "ENOTDIR") throw error;
|
|
167
|
+
if (Date.now() > deadline) throw this.contentionError(lock);
|
|
168
|
+
try {
|
|
169
|
+
this.retireWriteLock(lock);
|
|
170
|
+
} catch {
|
|
171
|
+
}
|
|
172
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 1 + Math.floor(Math.random() * 3));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
} finally {
|
|
176
|
+
try {
|
|
177
|
+
fs.rmSync(candidate, { recursive: true, force: true });
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
writeHolderEntry(dir, token) {
|
|
183
|
+
fs.writeFileSync(path.join(dir, `held.${token}`), JSON.stringify({ version: 1, pid: process.pid, createdAt: Date.now() }), { mode: 384, flag: "wx" });
|
|
184
|
+
}
|
|
185
|
+
releaseWriteLock(lock, token) {
|
|
186
|
+
try {
|
|
187
|
+
fs.unlinkSync(path.join(lock, `held.${token}`));
|
|
188
|
+
} catch {
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
const remaining = fs.readdirSync(lock);
|
|
192
|
+
if (remaining.length === 0) fs.rmdirSync(lock);
|
|
193
|
+
} catch {
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
contentionError(lock) {
|
|
197
|
+
const error = new Error(`EEXIST: file already exists, mkdir '${lock}'`);
|
|
198
|
+
error.code = "EEXIST";
|
|
199
|
+
error.errno = -17;
|
|
200
|
+
error.syscall = "mkdir";
|
|
201
|
+
error.path = lock;
|
|
202
|
+
return error;
|
|
203
|
+
}
|
|
204
|
+
/** Remove the stale canonical lock so an install can proceed. Returns true
|
|
205
|
+
* when the canonical path is now free for a rename. */
|
|
206
|
+
retireWriteLock(lock) {
|
|
207
|
+
let entries;
|
|
208
|
+
try {
|
|
209
|
+
entries = fs.readdirSync(lock);
|
|
210
|
+
} catch {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
const holders = entries.filter((name) => name.startsWith("held."));
|
|
214
|
+
if (holders.length === 0) {
|
|
215
|
+
if (entries.length !== 0) return false;
|
|
216
|
+
try {
|
|
217
|
+
fs.rmdirSync(lock);
|
|
218
|
+
return true;
|
|
219
|
+
} catch {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
for (const name of holders) {
|
|
224
|
+
let pid;
|
|
225
|
+
try {
|
|
226
|
+
const parsed = JSON.parse(fs.readFileSync(path.join(lock, name), "utf8"));
|
|
227
|
+
if (parsed?.version !== 1 || !Number.isInteger(parsed.pid) || parsed.pid <= 0) return false;
|
|
228
|
+
pid = parsed.pid;
|
|
229
|
+
} catch {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
process.kill(pid, 0);
|
|
234
|
+
return false;
|
|
235
|
+
} catch (error) {
|
|
236
|
+
if (error?.code !== "ESRCH") return false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
for (const name of holders) {
|
|
240
|
+
try {
|
|
241
|
+
fs.unlinkSync(path.join(lock, name));
|
|
242
|
+
} catch (error) {
|
|
243
|
+
if (error?.code === "ENOENT") continue;
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
try {
|
|
112
248
|
fs.rmdirSync(lock);
|
|
249
|
+
return true;
|
|
250
|
+
} catch {
|
|
251
|
+
return false;
|
|
113
252
|
}
|
|
114
253
|
}
|
|
115
254
|
/** Invalidate the write-skip cache when the on-disk file is not the exact
|
|
@@ -127,11 +266,33 @@ var Store = class {
|
|
|
127
266
|
}
|
|
128
267
|
if (raw !== this.lastSavedContent) this.lastSavedContent = void 0;
|
|
129
268
|
}
|
|
269
|
+
/** Structural-only read for use INSIDE a transaction: same JSON shape
|
|
270
|
+
* checks as read() minus the per-field fail-closed validation, so a
|
|
271
|
+
* transaction callback can repair an invalid field value (write it back
|
|
272
|
+
* valid) instead of dead-ending the store. save() still enforces the
|
|
273
|
+
* storage budgets. */
|
|
274
|
+
readForRepair() {
|
|
275
|
+
const file = path.join(this.dir, "state.json");
|
|
276
|
+
if (!fs.existsSync(file)) return { version: 1, jobs: [], owners: {} };
|
|
277
|
+
const s = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
278
|
+
if (s.version !== 1 || !Array.isArray(s.jobs) || !s.owners || typeof s.owners !== "object" || Array.isArray(s.owners)) {
|
|
279
|
+
throw new Error("invalid cron state; manual recovery required");
|
|
280
|
+
}
|
|
281
|
+
return s;
|
|
282
|
+
}
|
|
130
283
|
read() {
|
|
131
284
|
const file = path.join(this.dir, "state.json");
|
|
132
285
|
if (!fs.existsSync(file)) return { version: 1, jobs: [], owners: {} };
|
|
133
286
|
if (fs.statSync(file).size > 4e6) throw new Error("cron state exceeds size limit");
|
|
134
287
|
const s = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
288
|
+
this.validateState(s);
|
|
289
|
+
return s;
|
|
290
|
+
}
|
|
291
|
+
/** Full per-field validation shared by read() and save(): the single source
|
|
292
|
+
* of truth for what a valid State is. save() runs it on the IN-MEMORY
|
|
293
|
+
* result of a transaction so an unrepaired poison can never persist;
|
|
294
|
+
* read() runs it on disk bytes so consumers fail closed. */
|
|
295
|
+
validateState(s) {
|
|
135
296
|
if (s.version !== 1 || !Array.isArray(s.jobs) || !s.owners || typeof s.owners !== "object") throw new Error("invalid cron state; manual recovery required");
|
|
136
297
|
if (Array.isArray(s.owners) || s.jobs.length > 100 || Object.keys(s.owners).length > 1e3) throw new Error("cron state exceeds record limit");
|
|
137
298
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -146,11 +307,11 @@ var Store = class {
|
|
|
146
307
|
for (const o of Object.values(s.owners)) {
|
|
147
308
|
if (!o || o.sessionId !== null && typeof o.sessionId !== "string" || typeof o.cwd !== "string" || !path.isAbsolute(o.cwd) || typeof o.busy !== "boolean") throw new Error("invalid cron owner; manual recovery required");
|
|
148
309
|
}
|
|
149
|
-
return s;
|
|
150
310
|
}
|
|
151
311
|
save(state) {
|
|
152
312
|
const content = JSON.stringify(state, null, 2);
|
|
153
313
|
if (this.lastSavedContent === content) return;
|
|
314
|
+
this.validateState(state);
|
|
154
315
|
const projected = {
|
|
155
316
|
...state,
|
|
156
317
|
owners: Object.fromEntries(Object.entries(state.owners).map(([id, owner]) => [id, { ...owner, busy: false }])),
|
|
@@ -257,6 +418,7 @@ var Store = class {
|
|
|
257
418
|
}
|
|
258
419
|
j.enabled = action === "resume";
|
|
259
420
|
if (j.enabled) {
|
|
421
|
+
if (j.remaining !== void 0 && j.remaining <= 0) throw new Error("job exhausted its execution count; create a new job");
|
|
260
422
|
j.next = nextTime(j.schedule, Math.max(now, j.occurrence ?? now));
|
|
261
423
|
if (j.next === null) throw new Error("one-shot expired; create a new job");
|
|
262
424
|
j.state = "ready";
|
|
@@ -453,22 +615,46 @@ function runProcessWorker(job, command, cwd, deadlineMs = 30 * 60 * 1e3, logDir,
|
|
|
453
615
|
let settled = false;
|
|
454
616
|
let failure;
|
|
455
617
|
let hostCancelled = false;
|
|
456
|
-
let
|
|
618
|
+
let termination;
|
|
619
|
+
let cleanupFailure;
|
|
620
|
+
let leaderExited = false;
|
|
457
621
|
let deadlineTimer;
|
|
458
622
|
const ABORT_FAILURE = "worker interrupted; outcome uncertain";
|
|
459
|
-
const
|
|
460
|
-
if (
|
|
623
|
+
const signalGroup = (signal2) => {
|
|
624
|
+
if (!child?.pid) return false;
|
|
461
625
|
try {
|
|
462
|
-
|
|
463
|
-
|
|
626
|
+
process.kill(-child.pid, signal2);
|
|
627
|
+
return true;
|
|
628
|
+
} catch (error) {
|
|
629
|
+
if (error.code === "ESRCH") return false;
|
|
630
|
+
throw error;
|
|
464
631
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
632
|
+
};
|
|
633
|
+
const terminate = () => {
|
|
634
|
+
if (settled || termination) return;
|
|
635
|
+
termination = (async () => {
|
|
636
|
+
if (!child?.pid) return;
|
|
637
|
+
if (process.platform === "win32") {
|
|
638
|
+
if (leaderExited) return;
|
|
639
|
+
const pid = child.pid;
|
|
640
|
+
await new Promise((resolve4, reject2) => {
|
|
641
|
+
const killer = spawn("taskkill", ["/F", "/T", "/PID", String(pid)], { stdio: "ignore", windowsHide: true });
|
|
642
|
+
killer.on("error", reject2);
|
|
643
|
+
killer.on("close", (code) => code === 0 ? resolve4() : reject2(new Error(`taskkill exited ${code}`)));
|
|
644
|
+
});
|
|
645
|
+
return;
|
|
469
646
|
}
|
|
470
|
-
|
|
471
|
-
|
|
647
|
+
if (!signalGroup("SIGTERM")) return;
|
|
648
|
+
const until = Date.now() + 5e3;
|
|
649
|
+
while (Date.now() < until) {
|
|
650
|
+
await new Promise((resolve4) => setTimeout(resolve4, 25));
|
|
651
|
+
if (!signalGroup(0)) return;
|
|
652
|
+
}
|
|
653
|
+
signalGroup("SIGKILL");
|
|
654
|
+
await new Promise((resolve4) => setTimeout(resolve4, 50));
|
|
655
|
+
})().catch((error) => {
|
|
656
|
+
cleanupFailure = error;
|
|
657
|
+
});
|
|
472
658
|
};
|
|
473
659
|
const stop = () => {
|
|
474
660
|
if (settled) return;
|
|
@@ -481,6 +667,7 @@ function runProcessWorker(job, command, cwd, deadlineMs = 30 * 60 * 1e3, logDir,
|
|
|
481
667
|
cwd,
|
|
482
668
|
env: processJobEnv(configDir),
|
|
483
669
|
stdio: ["ignore", out ?? "ignore", out ?? "ignore"],
|
|
670
|
+
detached: process.platform !== "win32",
|
|
484
671
|
windowsHide: true
|
|
485
672
|
});
|
|
486
673
|
} catch (error) {
|
|
@@ -495,7 +682,6 @@ function runProcessWorker(job, command, cwd, deadlineMs = 30 * 60 * 1e3, logDir,
|
|
|
495
682
|
}
|
|
496
683
|
const cleanup = () => {
|
|
497
684
|
if (deadlineTimer !== void 0) clearTimeout(deadlineTimer);
|
|
498
|
-
if (killTimer !== void 0) clearTimeout(killTimer);
|
|
499
685
|
signal?.removeEventListener("abort", stop);
|
|
500
686
|
if (out !== void 0) {
|
|
501
687
|
try {
|
|
@@ -515,16 +701,31 @@ function runProcessWorker(job, command, cwd, deadlineMs = 30 * 60 * 1e3, logDir,
|
|
|
515
701
|
child.on("error", (error) => {
|
|
516
702
|
failure = error.message;
|
|
517
703
|
});
|
|
518
|
-
child.on("
|
|
704
|
+
child.on("exit", () => {
|
|
705
|
+
leaderExited = true;
|
|
706
|
+
});
|
|
707
|
+
child.on("close", async (code) => {
|
|
519
708
|
if (settled) return;
|
|
520
|
-
settled = true;
|
|
521
709
|
cleanup();
|
|
710
|
+
if (!termination && process.platform !== "win32") {
|
|
711
|
+
try {
|
|
712
|
+
if (signalGroup(0)) {
|
|
713
|
+
failure = "command left background descendants";
|
|
714
|
+
terminate();
|
|
715
|
+
}
|
|
716
|
+
} catch (error) {
|
|
717
|
+
cleanupFailure = error;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
await termination;
|
|
721
|
+
settled = true;
|
|
722
|
+
if (cleanupFailure) failure = `process cleanup failed: ${String(cleanupFailure)}`;
|
|
522
723
|
try {
|
|
523
724
|
fs2.appendFileSync(logFile, `[${(/* @__PURE__ */ new Date()).toISOString()}] job=${job.id} exit=${code}${failure ? ` error=${failure}` : ""}
|
|
524
725
|
`);
|
|
525
726
|
} catch {
|
|
526
727
|
}
|
|
527
|
-
if (hostCancelled) {
|
|
728
|
+
if (hostCancelled && !cleanupFailure) {
|
|
528
729
|
reject(new ProcessWorkerCancelled(failure ?? `cancelled (exit ${code})`));
|
|
529
730
|
return;
|
|
530
731
|
}
|
|
@@ -566,6 +767,16 @@ var Runtime = class {
|
|
|
566
767
|
leader = false;
|
|
567
768
|
recovering = false;
|
|
568
769
|
stopped = false;
|
|
770
|
+
/** Non-contention poll-failure backoff (schema-invalid state): 1s → 5min.
|
|
771
|
+
* Cleared on the first successful poll after a failure. */
|
|
772
|
+
pollFailureBackoffMs;
|
|
773
|
+
/** Earliest wall-clock time a poll may run again after a non-contention
|
|
774
|
+
* failure. The 1s interval keeps firing but poll() gates on this;
|
|
775
|
+
* scheduleRecoveryPoll arms a timer AT the gate so recovery actually
|
|
776
|
+
* happens — round-5 finding: the backoff value was computed but never
|
|
777
|
+
* consumed, so a poisoned state logged once per second forever. */
|
|
778
|
+
pollRetryAt;
|
|
779
|
+
recoveryPollTimer;
|
|
569
780
|
initialized = false;
|
|
570
781
|
binding = 0;
|
|
571
782
|
polling = false;
|
|
@@ -638,13 +849,7 @@ var Runtime = class {
|
|
|
638
849
|
this.ctx.ui.notify("cron: coordinator lock metadata is missing or invalid; scheduling is paused. See docs/cron.md offline recovery.", "warning");
|
|
639
850
|
}
|
|
640
851
|
withCoordinatorMutex(fn) {
|
|
641
|
-
|
|
642
|
-
fs3.mkdirSync(lock, { mode: 448 });
|
|
643
|
-
try {
|
|
644
|
-
return fn();
|
|
645
|
-
} finally {
|
|
646
|
-
fs3.rmdirSync(lock);
|
|
647
|
-
}
|
|
852
|
+
return this.store.withWriteLock(() => fn());
|
|
648
853
|
}
|
|
649
854
|
acquireCoordinator() {
|
|
650
855
|
const dir = this.coordinatorDir();
|
|
@@ -764,6 +969,7 @@ var Runtime = class {
|
|
|
764
969
|
}
|
|
765
970
|
async poll(now = Date.now()) {
|
|
766
971
|
if (this.stopped || this.polling || !this.initialized) return;
|
|
972
|
+
if (this.pollRetryAt !== void 0 && Date.now() < this.pollRetryAt) return;
|
|
767
973
|
if (fs3.existsSync(path3.join(this.store.dir, "unsafe.lock"))) {
|
|
768
974
|
this.abort.abort();
|
|
769
975
|
this.processAbort.abort();
|
|
@@ -773,6 +979,10 @@ var Runtime = class {
|
|
|
773
979
|
this.polling = true;
|
|
774
980
|
try {
|
|
775
981
|
this.flushCompletions();
|
|
982
|
+
if (this.pollRetryAt !== void 0) {
|
|
983
|
+
this.pollRetryAt = void 0;
|
|
984
|
+
this.pollFailureBackoffMs = void 0;
|
|
985
|
+
}
|
|
776
986
|
if (this.completions.size) return;
|
|
777
987
|
if (!this.leader) this.withCoordinatorMutex(() => {
|
|
778
988
|
try {
|
|
@@ -906,20 +1116,48 @@ ${job.prompt}`;
|
|
|
906
1116
|
const state = this.store.read(), enabled = state.jobs.filter((job) => job.enabled);
|
|
907
1117
|
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);
|
|
908
1118
|
for (const job of state.jobs) this.notify(job);
|
|
909
|
-
} catch {
|
|
910
|
-
|
|
1119
|
+
} catch (error) {
|
|
1120
|
+
if (isContention(error)) {
|
|
1121
|
+
this.ctx.ui.setStatus?.("cron", void 0);
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
this.pollFailureBackoffMs = Math.min((this.pollFailureBackoffMs ?? 1e3) * 2, 3e5);
|
|
1125
|
+
this.pollRetryAt = Date.now() + this.pollFailureBackoffMs;
|
|
1126
|
+
this.ctx.log?.(`cron: poll failed (${String(error instanceof Error ? error.message : error).slice(0, 200)}); backing off ${Math.round(this.pollFailureBackoffMs / 1e3)}s. If this persists, the state file is invalid \u2014 recover via /tools/cron or repair the file offline.`);
|
|
1127
|
+
this.ctx.ui.setStatus?.("cron", "cron: state invalid; scheduling paused (see logs)");
|
|
1128
|
+
this.scheduleRecoveryPoll();
|
|
911
1129
|
} finally {
|
|
912
1130
|
this.polling = false;
|
|
913
1131
|
}
|
|
914
1132
|
}
|
|
1133
|
+
/** One-shot delayed poll after a non-contention failure (schema-invalid
|
|
1134
|
+
* state): replaces the silent once-per-second retry loop with a backed-off
|
|
1135
|
+
* recovery attempt; the regular timer keeps running for healthy states. */
|
|
1136
|
+
scheduleRecoveryPoll() {
|
|
1137
|
+
if (this.stopped || this.recoveryPollTimer !== void 0) return;
|
|
1138
|
+
const delay2 = this.pollFailureBackoffMs ?? 1e3;
|
|
1139
|
+
this.recoveryPollTimer = setTimeout(() => {
|
|
1140
|
+
this.recoveryPollTimer = void 0;
|
|
1141
|
+
void this.poll().catch(() => {
|
|
1142
|
+
});
|
|
1143
|
+
}, delay2);
|
|
1144
|
+
this.recoveryPollTimer.unref();
|
|
1145
|
+
}
|
|
915
1146
|
async stop() {
|
|
916
1147
|
this.stopped = true;
|
|
917
1148
|
clearInterval(this.timer);
|
|
1149
|
+
if (this.recoveryPollTimer !== void 0) clearTimeout(this.recoveryPollTimer);
|
|
918
1150
|
this.abort.abort();
|
|
919
1151
|
this.processAbort.abort();
|
|
920
1152
|
await this.worker;
|
|
921
1153
|
while (this.polling) await delay(10);
|
|
1154
|
+
const shutdownDeadline = Date.now() + 1e4;
|
|
1155
|
+
const budgetLeft = () => Date.now() < shutdownDeadline;
|
|
922
1156
|
for (let attempt = 0; ; attempt++) {
|
|
1157
|
+
if (attempt > 0 && !budgetLeft()) {
|
|
1158
|
+
this.noteShutdownDegradation("cron: shutdown budget expired before the final state transaction completed; session ownership may be stale. If input stays blocked, run /tools/cron list and remove the stale owner row.");
|
|
1159
|
+
break;
|
|
1160
|
+
}
|
|
923
1161
|
try {
|
|
924
1162
|
this.store.transaction((state) => {
|
|
925
1163
|
for (const [id, entry] of this.completions) {
|
|
@@ -940,23 +1178,47 @@ ${job.prompt}`;
|
|
|
940
1178
|
this.completions.clear();
|
|
941
1179
|
break;
|
|
942
1180
|
} catch (error) {
|
|
943
|
-
if (
|
|
944
|
-
|
|
1181
|
+
if (isContention(error) && attempt < 39 && budgetLeft()) {
|
|
1182
|
+
await delay(25 + Math.floor(Math.random() * 25));
|
|
1183
|
+
continue;
|
|
1184
|
+
}
|
|
1185
|
+
this.noteShutdownDegradation(`cron: exit left session ownership uncommitted (${String(error)}). If input stays blocked, run /tools/cron list and remove the stale owner row.`);
|
|
1186
|
+
break;
|
|
945
1187
|
}
|
|
946
1188
|
}
|
|
947
1189
|
if (this.leader) {
|
|
948
1190
|
for (let attempt = 0; ; attempt++) {
|
|
1191
|
+
if (!budgetLeft()) {
|
|
1192
|
+
this.noteShutdownDegradation("cron: shutdown budget expired before the coordinator lock was released; scheduling pauses until it is reclaimed; see docs/cron.md.");
|
|
1193
|
+
break;
|
|
1194
|
+
}
|
|
949
1195
|
try {
|
|
950
1196
|
this.withCoordinatorMutex(() => this.releaseCoordinator());
|
|
951
1197
|
break;
|
|
952
1198
|
} catch (error) {
|
|
953
|
-
if (
|
|
954
|
-
|
|
1199
|
+
if (isContention(error) && attempt < 39 && budgetLeft()) {
|
|
1200
|
+
await delay(25 + Math.floor(Math.random() * 25));
|
|
1201
|
+
continue;
|
|
1202
|
+
}
|
|
1203
|
+
this.noteShutdownDegradation(`cron: coordinator lock not released (${String(error)}). Scheduling pauses until it is reclaimed; see docs/cron.md.`);
|
|
1204
|
+
break;
|
|
955
1205
|
}
|
|
956
1206
|
}
|
|
957
1207
|
}
|
|
958
1208
|
this.ctx.ui.setStatus?.("cron", void 0);
|
|
959
1209
|
}
|
|
1210
|
+
/** Surface a best-effort shutdown degradation. Never throws: diagnostics
|
|
1211
|
+
* must not turn a contained skip into a failed exit. */
|
|
1212
|
+
noteShutdownDegradation(message) {
|
|
1213
|
+
try {
|
|
1214
|
+
this.ctx.log?.(message);
|
|
1215
|
+
} catch {
|
|
1216
|
+
}
|
|
1217
|
+
try {
|
|
1218
|
+
this.ctx.ui.notify?.(message, "warning");
|
|
1219
|
+
} catch {
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
960
1222
|
};
|
|
961
1223
|
|
|
962
1224
|
// builtin/extensions/cron/index.ts
|
|
@@ -43,7 +43,7 @@ function truncateText(text) {
|
|
|
43
43
|
function runPythonScript(script, fallbackMessage) {
|
|
44
44
|
const failures = [];
|
|
45
45
|
for (const pythonBin of PYTHON_CANDIDATES) {
|
|
46
|
-
const result = spawnSync(pythonBin, ["-c", script], { encoding: "utf8" });
|
|
46
|
+
const result = spawnSync(pythonBin, ["-c", script], { encoding: "utf8", windowsHide: true });
|
|
47
47
|
if (result.status === 0) {
|
|
48
48
|
return result.stdout;
|
|
49
49
|
}
|
|
@@ -110,7 +110,7 @@ function buildReleaseReportArgs(params) {
|
|
|
110
110
|
}
|
|
111
111
|
function spawnHerdrReport(binPath, args, timeoutMs = REPORT_TIMEOUT_MS) {
|
|
112
112
|
try {
|
|
113
|
-
const child = spawn(binPath, args, { detached: true, stdio: "ignore" });
|
|
113
|
+
const child = spawn(binPath, args, { detached: true, stdio: "ignore", windowsHide: true });
|
|
114
114
|
let killTimer;
|
|
115
115
|
const clearTimers = () => {
|
|
116
116
|
clearTimeout(timer);
|
|
@@ -140,7 +140,7 @@ var KILL_GRACE_MS = 1e3;
|
|
|
140
140
|
async function runHerdrReportBounded(binPath, args, timeoutMs = REPORT_TIMEOUT_MS) {
|
|
141
141
|
let child;
|
|
142
142
|
try {
|
|
143
|
-
child = spawn(binPath, args, { detached: true, stdio: "ignore" });
|
|
143
|
+
child = spawn(binPath, args, { detached: true, stdio: "ignore", windowsHide: true });
|
|
144
144
|
} catch {
|
|
145
145
|
return { outcome: "spawn-error", exitCode: null };
|
|
146
146
|
}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
# IM forwarding
|
|
1
|
+
# IM forwarding
|
|
2
|
+
|
|
3
|
+
**Host gating (S5 axis migration):** the forwarding RUNTIME activates on the
|
|
4
|
+
`editorInjection` capability axis — real intake exists on the interactive TUI
|
|
5
|
+
(injection) and on embedded json-events hosts (controller-queue intake since
|
|
6
|
+
S1), so a resident concierge host forwards too. The INTERACTIVE SURFACES
|
|
7
|
+
(shortcuts Ctrl+R / Alt+I, `/tools/im-forward*` commands, the setup wizard)
|
|
8
|
+
stay gated on `interactiveUI`: the wizard needs dialogs, and an unattended host
|
|
9
|
+
configures through the layered config files instead. One-shot print hosts
|
|
10
|
+
(`pie -p`) register nothing and perform no configuration or subprocess IO.
|
|
2
11
|
|
|
3
12
|
Ctrl+R and `/tools/im-forward` are always available in interactive hosts; Alt+I is an
|
|
4
13
|
optional alias where the terminal delivers Alt. Bare
|
|
@@ -9,9 +18,14 @@ confirmation dialog; malformed layers are never silently destroyed (repair them
|
|
|
9
18
|
first), concurrent edits between confirmation and deletion abort the clear, and
|
|
10
19
|
forwarding stops immediately afterwards. Without usable configuration/dependency,
|
|
11
20
|
Ctrl+R opens **IM forwarding setup**;
|
|
12
|
-
otherwise it toggles the desired enabled flag.
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
otherwise it toggles the desired enabled flag. Replies/thread posts associated
|
|
22
|
+
with this process's forwarded messages enter their originating live session.
|
|
23
|
+
COLD-START exception (r17): until this runtime has EVER forwarded
|
|
24
|
+
(hasForwarded is a lifetime marker, not reset by route TTL expiry), the FIRST
|
|
25
|
+
authorized message in the configured target conversation binds to the current
|
|
26
|
+
session — a fresh resident host (the concierge) has an empty route table and
|
|
27
|
+
no stdin, so without this it could never hear its first message. A retry chain
|
|
28
|
+
never re-binds across a session switch (released for redelivery instead).
|
|
15
29
|
|
|
16
30
|
Feishu (Lark) is the only implemented platform. The wizard always shows a generic
|
|
17
31
|
platform picker with implemented platforms and Cancel, before provider setup. See [Feishu setup and transport](providers/feishu/README.md).
|
|
@@ -206,7 +220,8 @@ path no longer truncates bodies.
|
|
|
206
220
|
cleared on any terminal outcome (acceptance,
|
|
207
221
|
not-ours/invalidated rejection, exhaustion, forwarding disabled, extension
|
|
208
222
|
cleanup). A reply chain that walks cleanly to its end with no matching
|
|
209
|
-
forward is ignored, not retried
|
|
223
|
+
forward is ignored, not retried (unless the never-forwarded cold-start
|
|
224
|
+
bootstrap applies — see above). Events delivered while forwarding is
|
|
210
225
|
globally disabled are dropped WITHOUT being committed to the dedup set, so a
|
|
211
226
|
provider redelivery after re-enabling still processes.
|
|
212
227
|
|