@cydm/pie 4.13.1 → 4.14.1
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 +4 -4
- package/dist/builtin/extensions/cron/index.js +70 -17
- package/dist/builtin/extensions/im-forward/index.js +8094 -8100
- package/dist/builtin/extensions/mcp-adapter/index.js +86 -81
- package/dist/builtin/extensions/memory/index.js +30 -7
- package/dist/builtin/extensions/pie-ipc/index.js +13 -18
- package/dist/builtin/extensions/pie-proc/README.md +12 -3
- package/dist/builtin/extensions/pie-proc/index.js +145 -96
- package/dist/builtin/extensions/plan-mode/index.js +4 -4
- package/dist/builtin/extensions/subagent/index.js +5 -5
- package/dist/builtin/extensions/todo/index.js +4 -4
- package/dist/chunks/{chunk-6Z54UHXM.js → chunk-2WLKAMOH.js} +21 -16
- package/dist/chunks/{chunk-3F2CSVNH.js → chunk-DJ4LO7PQ.js} +2 -1
- package/dist/chunks/{chunk-MCR4JYI6.js → chunk-IM7DLPPY.js} +74 -8
- package/dist/chunks/{chunk-HSMO2BEA.js → chunk-IQDVL34H.js} +24 -19
- package/dist/chunks/{chunk-DT22BBZL.js → chunk-OQCKDEEE.js} +1 -1
- package/dist/chunks/{chunk-26KRUYZH.js → chunk-SAXKBFX3.js} +1 -1
- package/dist/chunks/{chunk-CCPNHS6B.js → chunk-SYZR74QO.js} +1582 -1570
- package/dist/chunks/{chunk-UCVPNLCO.js → chunk-TNRZEQD5.js} +2 -2
- package/dist/chunks/{chunk-NHWWRE3T.js → chunk-TTSQWGAT.js} +727 -719
- package/dist/chunks/{chunk-XPJHZRTN.js → chunk-X3ZVZB2R.js} +1133 -381
- package/dist/chunks/{host-image-fallback-LGWYQMLA.js → host-image-fallback-AEKY2LSZ.js} +1 -1
- package/dist/chunks/{manager-cli-OTIMAWO6.js → manager-cli-ZV36YNPJ.js} +187 -173
- package/dist/chunks/{memory-git-7SRO5KLB.js → memory-git-G56IXFWU.js} +5 -5
- package/dist/chunks/{model-registry-IWOOAMLZ.js → model-registry-4LM2I6FR.js} +2 -2
- package/dist/chunks/{read-file-understanding-3TYWVOLX.js → read-file-understanding-GTNZHAK5.js} +5 -5
- package/dist/chunks/{src-WA2O2O2V.js → src-3YJ4UVEC.js} +3 -3
- package/dist/chunks/{src-ALHMJZ5R.js → src-APNP4M4N.js} +2 -2
- package/dist/chunks/{src-D2ICRXWW.js → src-T6AUO53N.js} +24 -6
- package/dist/chunks/{src-76Q33OY5.js → src-TNUD7EDH.js} +1 -1
- package/dist/chunks/{test-stream-OVGDTXOY.js → test-stream-EF2DHEHV.js} +1 -1
- package/dist/cli.js +3131 -3013
- package/package.json +1 -1
- package/dist/chunks/{chunk-3GG342QY.js → chunk-TYCKSYUF.js} +19 -19
|
@@ -1,10 +1,10 @@
|
|
|
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-X3ZVZB2R.js";
|
|
5
|
+
import "../../../chunks/chunk-SYZR74QO.js";
|
|
6
|
+
import "../../../chunks/chunk-SAXKBFX3.js";
|
|
7
|
+
import "../../../chunks/chunk-IM7DLPPY.js";
|
|
8
8
|
import "../../../chunks/chunk-XXGYUYXI.js";
|
|
9
9
|
import "../../../chunks/chunk-LZQXQOPJ.js";
|
|
10
10
|
|
|
@@ -127,20 +127,27 @@ function sweepStaleOwners(state, dir, opts = {}) {
|
|
|
127
127
|
if (dead) {
|
|
128
128
|
reaped.push({ key, sessionId: row.sessionId, reason: `pid ${parsed.pid} provably dead` });
|
|
129
129
|
delete state.owners[key];
|
|
130
|
+
try {
|
|
131
|
+
fs.rmSync(liveness, { force: true });
|
|
132
|
+
} catch {
|
|
133
|
+
}
|
|
130
134
|
}
|
|
131
135
|
} catch {
|
|
132
136
|
}
|
|
133
137
|
}
|
|
134
138
|
return reaped;
|
|
135
139
|
}
|
|
140
|
+
var DEFAULT_MAX_AUDIT_LOG_BYTES = 2 * 1024 * 1024;
|
|
136
141
|
var Store = class {
|
|
137
142
|
constructor(dir, opts) {
|
|
138
143
|
this.dir = dir;
|
|
139
144
|
this.verifyDir = opts?.verifyDir;
|
|
145
|
+
this.maxAuditBytes = opts?.maxAuditBytes ?? DEFAULT_MAX_AUDIT_LOG_BYTES;
|
|
140
146
|
if (opts?.createDir !== false) fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
141
147
|
}
|
|
142
148
|
dir;
|
|
143
149
|
verifyDir;
|
|
150
|
+
maxAuditBytes;
|
|
144
151
|
/** Durable, append-only audit trail for operator-visible cron decisions.
|
|
145
152
|
*
|
|
146
153
|
* Why a file and not `ctx.log`: ctx.log only prints when PIE_VERBOSE is set
|
|
@@ -153,25 +160,62 @@ var Store = class {
|
|
|
153
160
|
* failed audit write can never leave an unlogged change behind. A failure
|
|
154
161
|
* therefore refuses the mutation (fail-closed, like the rest of the store). */
|
|
155
162
|
audit(record) {
|
|
156
|
-
this.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
this.withAuditLock(() => {
|
|
164
|
+
const auditPath = path.join(this.dir, "audit.log");
|
|
165
|
+
let st;
|
|
166
|
+
try {
|
|
167
|
+
st = fs.lstatSync(auditPath);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
if (error?.code !== "ENOENT") throw error;
|
|
162
170
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
171
|
+
if (st) {
|
|
172
|
+
if (st.isSymbolicLink() || !st.isFile()) {
|
|
173
|
+
throw new Error("refusing to write audit log to non-regular file");
|
|
174
|
+
}
|
|
175
|
+
if (st.nlink === 1 && st.size >= this.maxAuditBytes) {
|
|
176
|
+
const rotatedPath = `${auditPath}.1`;
|
|
177
|
+
let rotStat;
|
|
178
|
+
try {
|
|
179
|
+
rotStat = fs.lstatSync(rotatedPath);
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (error?.code !== "ENOENT") throw error;
|
|
182
|
+
}
|
|
183
|
+
if (rotStat && (rotStat.isSymbolicLink() || !rotStat.isFile())) {
|
|
184
|
+
throw new Error("refusing to rotate audit log over non-regular file");
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
fs.renameSync(auditPath, rotatedPath);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (error?.code !== "ENOENT") throw error;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const flags = fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_APPEND | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0);
|
|
194
|
+
const fd = fs.openSync(auditPath, flags, 384);
|
|
195
|
+
try {
|
|
196
|
+
const fdStat = fs.fstatSync(fd);
|
|
197
|
+
if (!fdStat.isFile() || fdStat.nlink !== 1) throw new Error("audit log target is not a single-link regular file");
|
|
198
|
+
this.verifyDir?.();
|
|
199
|
+
const line = `${JSON.stringify({ at: Date.now(), ...record })}
|
|
200
|
+
`;
|
|
201
|
+
fs.writeFileSync(fd, line);
|
|
202
|
+
} finally {
|
|
203
|
+
fs.closeSync(fd);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/** Dedicated leaf-level cross-process mutex for audit.log stat/rotate/append.
|
|
208
|
+
* Never acquires write.lock inside it, so both in-transaction and standalone
|
|
209
|
+
* audit callers serialize cleanly without deadlock risk. */
|
|
210
|
+
withAuditLock(fn) {
|
|
211
|
+
this.verifyDir?.();
|
|
212
|
+
const lock = path.join(this.dir, "audit.lock");
|
|
213
|
+
const token = this.acquireWriteLock(lock);
|
|
166
214
|
try {
|
|
167
|
-
const fdStat = fs.fstatSync(fd);
|
|
168
|
-
if (!fdStat.isFile() || fdStat.nlink !== 1) throw new Error("audit log target is not a single-link regular file");
|
|
169
215
|
this.verifyDir?.();
|
|
170
|
-
|
|
171
|
-
`;
|
|
172
|
-
fs.writeFileSync(fd, line);
|
|
216
|
+
return fn();
|
|
173
217
|
} finally {
|
|
174
|
-
|
|
218
|
+
this.releaseWriteLock(lock, token);
|
|
175
219
|
}
|
|
176
220
|
}
|
|
177
221
|
/** Serialized bytes of the state currently on disk; undefined until the
|
|
@@ -230,7 +274,7 @@ var Store = class {
|
|
|
230
274
|
* (before the rename); it is inert — the protocol never consults it. */
|
|
231
275
|
acquireWriteLock(lock) {
|
|
232
276
|
const token = randomUUID();
|
|
233
|
-
const candidate = path.join(this.dir,
|
|
277
|
+
const candidate = path.join(this.dir, `${path.basename(lock)}.acquire.${token}`);
|
|
234
278
|
const holderPath = path.join(candidate, `held.${token}`);
|
|
235
279
|
let candDev;
|
|
236
280
|
let candIno;
|
|
@@ -1275,6 +1319,7 @@ var delay = (ms) => new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
|
1275
1319
|
var isContention = (error) => error?.code === "EEXIST";
|
|
1276
1320
|
var COORDINATOR_OWNER_FILE = "owner.json";
|
|
1277
1321
|
var COORDINATOR_METADATA_GRACE_MS = 5e3;
|
|
1322
|
+
var STORE_OWNER_SWEEP_INTERVAL_MS = 5 * 6e4;
|
|
1278
1323
|
function defaultProcessAlive(pid) {
|
|
1279
1324
|
try {
|
|
1280
1325
|
process.kill(pid, 0);
|
|
@@ -1329,6 +1374,7 @@ var Runtime = class {
|
|
|
1329
1374
|
acceptedIdlePolls = 0;
|
|
1330
1375
|
unreadableCoordinatorSince;
|
|
1331
1376
|
coordinatorNotices = /* @__PURE__ */ new Set();
|
|
1377
|
+
lastOwnerSweepAt = 0;
|
|
1332
1378
|
get ready() {
|
|
1333
1379
|
return this.initialized && !this.stopped;
|
|
1334
1380
|
}
|
|
@@ -1595,6 +1641,9 @@ var Runtime = class {
|
|
|
1595
1641
|
state.jobs = state.jobs.filter((item) => item !== job);
|
|
1596
1642
|
return;
|
|
1597
1643
|
}
|
|
1644
|
+
if (job.state === "blocked" && job.error === error && !pending) {
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1598
1647
|
const repeating = !("at" in job.schedule);
|
|
1599
1648
|
if (!executed && repeating && !isProcessJob(job) && !job.retriedOnce) {
|
|
1600
1649
|
job.retriedOnce = true;
|
|
@@ -1736,11 +1785,15 @@ Tell the user in one short message and wait for their decision. Do not resume or
|
|
|
1736
1785
|
}
|
|
1737
1786
|
}
|
|
1738
1787
|
state2.owners[this.id] = { sessionId: this.sessionId, cwd: this.cwd, busy: !this.ctx.isIdle() };
|
|
1788
|
+
if (this.leader && (this.recovering || now - this.lastOwnerSweepAt >= STORE_OWNER_SWEEP_INTERVAL_MS)) {
|
|
1789
|
+
sweepStaleOwners(state2, this.store.dir, { keepKey: this.id, now });
|
|
1790
|
+
this.lastOwnerSweepAt = now;
|
|
1791
|
+
}
|
|
1739
1792
|
for (const job of [...state2.jobs]) {
|
|
1740
1793
|
if (isProcessJob(job)) continue;
|
|
1741
1794
|
const owners = Object.entries(state2.owners).filter(([, owner]) => owner.sessionId === job.sessionId);
|
|
1742
1795
|
if (this.leader && job.state === "running" && job.target === "worker" && owners.length) this.abort.abort();
|
|
1743
|
-
if (job.enabled && owners.length > 1 && job.state !== "running") this.handleBlock(state2, job, "duplicate participating session owners; close duplicate and resume job", false);
|
|
1796
|
+
if (job.enabled && owners.length > 1 && job.state !== "running" && job.state !== "blocked") this.handleBlock(state2, job, "duplicate participating session owners; close duplicate and resume job", false);
|
|
1744
1797
|
if (job.state === "running" && job.target === this.id && this.accepted?.id === job.id) {
|
|
1745
1798
|
if (!this.accepted.consumed) {
|
|
1746
1799
|
for (const message of this.ctx.getMessages?.() ?? []) this.onMessage(message);
|