@cydm/pie 4.3.11 → 4.4.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 +1 -1
- package/dist/builtin/extensions/cron/index.js +76 -9
- package/dist/builtin/extensions/im-forward/README.md +29 -1
- package/dist/builtin/extensions/im-forward/index.js +549 -97
- package/dist/builtin/extensions/mcp-adapter/index.js +2 -2
- package/dist/builtin/extensions/memory/index.js +10 -3
- package/dist/builtin/extensions/pie-ipc/index.js +52 -269
- package/dist/builtin/extensions/pie-proc/index.js +1 -1
- package/dist/builtin/extensions/plan-mode/index.js +6 -5
- package/dist/builtin/extensions/subagent/index.js +15 -5
- package/dist/builtin/extensions/todo/index.js +6 -2
- package/dist/chunks/{chunk-DGXIR6CV.js → chunk-AKXEZH7K.js} +521 -266
- package/dist/chunks/{chunk-ZAJEKDPV.js → chunk-GY47MKCJ.js} +2 -2
- package/dist/chunks/{chunk-KCZGLNRM.js → chunk-I7PBXG5Q.js} +1 -1
- package/dist/chunks/{chunk-LLCEO7ET.js → chunk-N5B5IGJ6.js} +350 -231
- package/dist/chunks/{src-5EZU72ZA.js → src-V2M7FLWY.js} +5 -1
- package/dist/cli.js +39 -6
- package/package.json +2 -2
|
@@ -25155,7 +25155,7 @@ ${tail}` : ""),
|
|
|
25155
25155
|
}
|
|
25156
25156
|
try {
|
|
25157
25157
|
const result = await withTimeout(
|
|
25158
|
-
client.callTool({ name: toolName, arguments: args },
|
|
25158
|
+
client.callTool({ name: toolName, arguments: args }, signal !== void 0 ? { signal } : void 0),
|
|
25159
25159
|
CALL_TIMEOUT_MS,
|
|
25160
25160
|
`call "${prefixedName}"`,
|
|
25161
25161
|
signal
|
|
@@ -25174,7 +25174,7 @@ ${tail}` : ""),
|
|
|
25174
25174
|
error: `MCP server "${server}" returned a result that fails its own outputSchema: ${message}. The call DID reach the server and the tool likely executed \u2014 do NOT retry automatically; verify state with a read-only tool first.`
|
|
25175
25175
|
};
|
|
25176
25176
|
}
|
|
25177
|
-
if (runtime.client === void 0 || /closed|aborted|timed out|socket|ECONNRESET/i.test(message)) {
|
|
25177
|
+
if (signal?.aborted || runtime.client === void 0 || /closed|aborted|timed out|socket|ECONNRESET/i.test(message)) {
|
|
25178
25178
|
return {
|
|
25179
25179
|
delivery: "may_have_run",
|
|
25180
25180
|
error: `MCP call "${prefixedName}" outcome unknown: ${message}. The request may have executed \u2014 do NOT retry automatically; verify state with a read-only tool first.`
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
distillWorkerLogPath,
|
|
4
4
|
readDistillWorkerLog,
|
|
5
5
|
spawnDistillWorker
|
|
6
|
-
} from "../../../chunks/chunk-
|
|
6
|
+
} from "../../../chunks/chunk-GY47MKCJ.js";
|
|
7
7
|
import {
|
|
8
8
|
getConfigDir,
|
|
9
9
|
getSettingsPath
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
saveAttestedEntry,
|
|
20
20
|
searchMemory,
|
|
21
21
|
todayKey
|
|
22
|
-
} from "../../../chunks/chunk-
|
|
22
|
+
} from "../../../chunks/chunk-N5B5IGJ6.js";
|
|
23
23
|
import "../../../chunks/chunk-XMOWWL4B.js";
|
|
24
24
|
import "../../../chunks/chunk-B4N5LJMD.js";
|
|
25
25
|
import "../../../chunks/chunk-6JEYRAQM.js";
|
|
@@ -282,11 +282,17 @@ function buildInjectionSection(store, budget, projectKey) {
|
|
|
282
282
|
}
|
|
283
283
|
function buildInjectionSectionWithIds(store, budget, projectKey) {
|
|
284
284
|
const entries = store.loadEntries();
|
|
285
|
+
const isLowValue = (entry) => {
|
|
286
|
+
if (entry.provenance === "user-attested") return false;
|
|
287
|
+
const inj = entry.injectedCount ?? 0;
|
|
288
|
+
const cons = entry.consumedCount ?? 0;
|
|
289
|
+
return inj >= 10 && inj / (cons + 1) >= 10;
|
|
290
|
+
};
|
|
285
291
|
const take = (surface, limit, extra) => {
|
|
286
292
|
const pool = entries.filter((entry) => {
|
|
287
293
|
if (surface === "project") return entry.kind === "project" && (!extra || extra(entry));
|
|
288
294
|
return entry.surface === surface && (!extra || extra(entry));
|
|
289
|
-
}).sort((a, b) => b.usageCount - a.usageCount || b.lastAccessed - a.lastAccessed);
|
|
295
|
+
}).sort((a, b) => Number(isLowValue(a)) - Number(isLowValue(b)) || b.usageCount - a.usageCount || b.lastAccessed - a.lastAccessed);
|
|
290
296
|
const kept = [];
|
|
291
297
|
let used = 0;
|
|
292
298
|
for (const entry of pool) {
|
|
@@ -322,6 +328,7 @@ function buildInjectionSectionWithIds(store, budget, projectKey) {
|
|
|
322
328
|
}
|
|
323
329
|
const recentDates = store.listJournalDates().slice(-3);
|
|
324
330
|
const digest = [];
|
|
331
|
+
let digestUsed = 0;
|
|
325
332
|
for (const date of recentDates.reverse()) {
|
|
326
333
|
const journal = store.readJournal(date);
|
|
327
334
|
if (!journal) continue;
|
|
@@ -3,15 +3,13 @@ import {
|
|
|
3
3
|
Type
|
|
4
4
|
} from "../../../chunks/chunk-XXGYUYXI.js";
|
|
5
5
|
import {
|
|
6
|
-
BoundedIdSet,
|
|
7
6
|
DEFAULT_SEND_WAIT_MS,
|
|
8
7
|
DISPATCH_PREFIX,
|
|
9
|
-
FrameDecoder,
|
|
10
8
|
HEARTBEAT_INTERVAL_MS,
|
|
11
9
|
IPC_PROTOCOL_VERSION,
|
|
10
|
+
IpcTransport,
|
|
12
11
|
MAX_BODY_CHARS,
|
|
13
12
|
MAX_INBOX_MESSAGES,
|
|
14
|
-
MAX_INFLIGHT_SENDS,
|
|
15
13
|
MAX_STATUS_BODY_CHARS,
|
|
16
14
|
MAX_STATUS_FILE_BYTES,
|
|
17
15
|
assistantBodyText,
|
|
@@ -28,14 +26,14 @@ import {
|
|
|
28
26
|
takeDispatchFrame,
|
|
29
27
|
wrapInboundText,
|
|
30
28
|
wrappedMessageMarker
|
|
31
|
-
} from "../../../chunks/chunk-
|
|
29
|
+
} from "../../../chunks/chunk-AKXEZH7K.js";
|
|
32
30
|
import "../../../chunks/chunk-LZQXQOPJ.js";
|
|
33
31
|
|
|
34
32
|
// builtin/extensions/pie-ipc/index.ts
|
|
35
33
|
import * as fs3 from "node:fs";
|
|
36
34
|
import * as os from "node:os";
|
|
37
35
|
import * as path4 from "node:path";
|
|
38
|
-
import { randomUUID
|
|
36
|
+
import { randomUUID } from "node:crypto";
|
|
39
37
|
|
|
40
38
|
// builtin/extensions/pie-ipc/discovery.ts
|
|
41
39
|
import * as fs2 from "node:fs";
|
|
@@ -529,257 +527,6 @@ function buildStatusFile(input) {
|
|
|
529
527
|
};
|
|
530
528
|
}
|
|
531
529
|
|
|
532
|
-
// builtin/extensions/pie-ipc/transport.ts
|
|
533
|
-
import * as net from "node:net";
|
|
534
|
-
import { createHmac, randomBytes as randomBytes3, randomUUID, timingSafeEqual } from "node:crypto";
|
|
535
|
-
import { StringDecoder } from "node:string_decoder";
|
|
536
|
-
var CLOSE_FLUSH_TIMEOUT_MS = 1e3;
|
|
537
|
-
function signEnvelope(e, secret) {
|
|
538
|
-
const payload = [e.v, e.id, e.from, e.to, e.kind, e.createdAt, e.sessionId ?? null, e.text ?? null, e.replyTo ?? null, e.waitMs ?? null, e.notifyCompletion ?? null, e.control ?? null, e.userAssigned ?? null, e.subscriberSession ?? null];
|
|
539
|
-
return { ...e, auth: createHmac("sha256", secret).update(JSON.stringify(payload)).digest("hex") };
|
|
540
|
-
}
|
|
541
|
-
function verified(e, secret) {
|
|
542
|
-
if (!e.auth || !/^[a-f0-9]{64}$/.test(e.auth)) return false;
|
|
543
|
-
return timingSafeEqual(Buffer.from(e.auth, "hex"), Buffer.from(signEnvelope(e, secret).auth, "hex"));
|
|
544
|
-
}
|
|
545
|
-
var IpcTransport = class {
|
|
546
|
-
constructor(host) {
|
|
547
|
-
this.host = host;
|
|
548
|
-
this.instanceId = host.instanceId;
|
|
549
|
-
this.secret = host.secret ?? randomBytes3(32).toString("hex");
|
|
550
|
-
this.server = net.createServer((socket) => this.accept(socket));
|
|
551
|
-
this.server.on("error", () => {
|
|
552
|
-
});
|
|
553
|
-
this.server.unref();
|
|
554
|
-
}
|
|
555
|
-
host;
|
|
556
|
-
instanceId;
|
|
557
|
-
secret;
|
|
558
|
-
server;
|
|
559
|
-
sockets = /* @__PURE__ */ new Set();
|
|
560
|
-
cancels = /* @__PURE__ */ new Set();
|
|
561
|
-
seen = new BoundedIdSet();
|
|
562
|
-
closed = false;
|
|
563
|
-
inflight = 0;
|
|
564
|
-
inbound = 0;
|
|
565
|
-
rateWindow = Date.now();
|
|
566
|
-
rateCount = 0;
|
|
567
|
-
port = null;
|
|
568
|
-
get listenPort() {
|
|
569
|
-
return this.port;
|
|
570
|
-
}
|
|
571
|
-
listen() {
|
|
572
|
-
if (this.closed) return Promise.reject(new Error("closed"));
|
|
573
|
-
return new Promise((resolve2, reject) => {
|
|
574
|
-
const cancel = () => {
|
|
575
|
-
this.cancels.delete(cancel);
|
|
576
|
-
reject(new Error("closed"));
|
|
577
|
-
};
|
|
578
|
-
this.cancels.add(cancel);
|
|
579
|
-
const error = (e) => {
|
|
580
|
-
this.cancels.delete(cancel);
|
|
581
|
-
reject(e);
|
|
582
|
-
};
|
|
583
|
-
this.server.once("error", error);
|
|
584
|
-
this.server.listen(0, "127.0.0.1", () => {
|
|
585
|
-
this.server.off("error", error);
|
|
586
|
-
this.cancels.delete(cancel);
|
|
587
|
-
if (this.closed) {
|
|
588
|
-
this.server.close();
|
|
589
|
-
reject(new Error("closed"));
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
const address = this.server.address();
|
|
593
|
-
if (!address || typeof address === "string") {
|
|
594
|
-
reject(new Error("closed"));
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
this.port = address.port;
|
|
598
|
-
resolve2(address.port);
|
|
599
|
-
});
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
write(socket, envelope, secret) {
|
|
603
|
-
if (socket.destroyed) return false;
|
|
604
|
-
const data = JSON.stringify(signEnvelope(envelope, secret)) + "\n";
|
|
605
|
-
if (socket.writableLength + Buffer.byteLength(data) > 512 * 1024) {
|
|
606
|
-
socket.destroy();
|
|
607
|
-
return false;
|
|
608
|
-
}
|
|
609
|
-
try {
|
|
610
|
-
socket.write(data);
|
|
611
|
-
return true;
|
|
612
|
-
} catch {
|
|
613
|
-
socket.destroy();
|
|
614
|
-
return false;
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
read(socket, receive, idleMs) {
|
|
618
|
-
const decoder = new FrameDecoder();
|
|
619
|
-
const utf8 = new StringDecoder("utf8");
|
|
620
|
-
let frameTimer;
|
|
621
|
-
let frames = 0;
|
|
622
|
-
socket.setTimeout(idleMs, () => socket.destroy());
|
|
623
|
-
socket.on("error", () => socket.destroy());
|
|
624
|
-
socket.on("close", () => {
|
|
625
|
-
if (frameTimer) clearTimeout(frameTimer);
|
|
626
|
-
this.sockets.delete(socket);
|
|
627
|
-
});
|
|
628
|
-
socket.on("data", (chunk) => {
|
|
629
|
-
try {
|
|
630
|
-
frames += chunk.reduce((n, b) => n + (b === 10 ? 1 : 0), 0);
|
|
631
|
-
if (frames > 128) {
|
|
632
|
-
socket.destroy();
|
|
633
|
-
return;
|
|
634
|
-
}
|
|
635
|
-
const envelopes = decoder.push(utf8.write(chunk));
|
|
636
|
-
const partial = decoder.partial || chunk.at(-1) !== 10;
|
|
637
|
-
if (frameTimer && (!partial || chunk.includes(10))) {
|
|
638
|
-
clearTimeout(frameTimer);
|
|
639
|
-
frameTimer = void 0;
|
|
640
|
-
}
|
|
641
|
-
if (partial && !frameTimer) {
|
|
642
|
-
frameTimer = setTimeout(() => socket.destroy(), 15e3);
|
|
643
|
-
frameTimer.unref();
|
|
644
|
-
}
|
|
645
|
-
for (const e of envelopes) {
|
|
646
|
-
if (socket.destroyed) break;
|
|
647
|
-
receive(e);
|
|
648
|
-
}
|
|
649
|
-
} catch {
|
|
650
|
-
socket.destroy();
|
|
651
|
-
}
|
|
652
|
-
});
|
|
653
|
-
}
|
|
654
|
-
accept(socket) {
|
|
655
|
-
if (this.closed || this.inbound >= 16) {
|
|
656
|
-
socket.destroy();
|
|
657
|
-
return;
|
|
658
|
-
}
|
|
659
|
-
this.inbound++;
|
|
660
|
-
this.sockets.add(socket);
|
|
661
|
-
socket.setNoDelay(true);
|
|
662
|
-
socket.once("close", () => {
|
|
663
|
-
this.inbound--;
|
|
664
|
-
});
|
|
665
|
-
const lifecycle = new AbortController();
|
|
666
|
-
socket.once("close", () => lifecycle.abort());
|
|
667
|
-
let sender;
|
|
668
|
-
this.read(socket, (e) => {
|
|
669
|
-
if (e.to !== this.instanceId || !verified(e, this.secret) || sender && sender !== e.from) {
|
|
670
|
-
socket.destroy();
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
sender = e.from;
|
|
674
|
-
if (Date.now() - this.rateWindow >= 1e3) {
|
|
675
|
-
this.rateWindow = Date.now();
|
|
676
|
-
this.rateCount = 0;
|
|
677
|
-
}
|
|
678
|
-
if (++this.rateCount > 128) {
|
|
679
|
-
socket.destroy();
|
|
680
|
-
return;
|
|
681
|
-
}
|
|
682
|
-
if (e.waitMs) socket.setTimeout(Math.max(6e4, e.waitMs + 1e3));
|
|
683
|
-
if (!this.seen.add(`${e.from}:${e.id}`)) return;
|
|
684
|
-
try {
|
|
685
|
-
if (this.closed) return;
|
|
686
|
-
void Promise.resolve(this.host.onEnvelope(e, (reply) => {
|
|
687
|
-
if (reply.from === this.instanceId && reply.to === e.from && reply.replyTo === e.id) this.write(socket, reply, this.secret);
|
|
688
|
-
}, lifecycle.signal)).catch(() => socket.destroy());
|
|
689
|
-
} catch {
|
|
690
|
-
socket.destroy();
|
|
691
|
-
}
|
|
692
|
-
}, 6e4);
|
|
693
|
-
}
|
|
694
|
-
/** Synchronous CAPACITY probe (review r3): transport.send is async, so a
|
|
695
|
-
* capacity rejection still yields a truthy Promise resolving null — callers
|
|
696
|
-
* distinguishing 'never left the process' from 'sent, outcome unknown' must
|
|
697
|
-
* check this BEFORE awaiting send. Scope: closed/inflight ONLY (capacity &
|
|
698
|
-
* lifecycle), NOT send()'s full validation (signal/secret/port/waitMs can
|
|
699
|
-
* still null-reject after a true probe — those are peer/discovery outcomes,
|
|
700
|
-
* covered by the best-effort contract). */
|
|
701
|
-
canSendNow() {
|
|
702
|
-
return !this.closed && this.inflight < MAX_INFLIGHT_SENDS;
|
|
703
|
-
}
|
|
704
|
-
async send(peerInstanceId, port, kind, options = {}) {
|
|
705
|
-
if (this.closed || options.signal?.aborted || this.inflight >= MAX_INFLIGHT_SENDS) return null;
|
|
706
|
-
let secret;
|
|
707
|
-
try {
|
|
708
|
-
secret = this.host.resolveSecret?.(peerInstanceId);
|
|
709
|
-
} catch {
|
|
710
|
-
return null;
|
|
711
|
-
}
|
|
712
|
-
if (!secret || !/^[a-f0-9]{64}$/.test(secret) || !Number.isInteger(port) || port < 1 || port > 65535) return null;
|
|
713
|
-
const waitMs = options.waitMs ?? DEFAULT_SEND_WAIT_MS;
|
|
714
|
-
if (!Number.isFinite(waitMs) || waitMs < 0 || waitMs > 6e5) return null;
|
|
715
|
-
const holdOpen = options.expectReply === true || options.awaitAck === true;
|
|
716
|
-
this.inflight++;
|
|
717
|
-
return new Promise((resolve2) => {
|
|
718
|
-
const socket = new net.Socket();
|
|
719
|
-
this.sockets.add(socket);
|
|
720
|
-
const envelope = { v: IPC_PROTOCOL_VERSION, id: options.requestId ?? randomUUID(), from: this.instanceId, to: peerInstanceId, kind, createdAt: Date.now(), ...options.text !== void 0 ? { text: clipBody(options.text) } : {}, ...options.sessionId !== void 0 ? { sessionId: options.sessionId } : {}, ...options.replyTo ? { replyTo: options.replyTo } : {}, waitMs: options.expectReply ? waitMs : 0, ...options.notifyCompletion === true ? { notifyCompletion: true } : {}, ...options.subscriberSession !== void 0 ? { subscriberSession: options.subscriberSession } : {}, ...options.userAssigned === true ? { userAssigned: true } : {} };
|
|
721
|
-
let done = false;
|
|
722
|
-
const finish = (value) => {
|
|
723
|
-
if (done) return;
|
|
724
|
-
done = true;
|
|
725
|
-
clearTimeout(timer);
|
|
726
|
-
clearTimeout(dialTimer);
|
|
727
|
-
options.signal?.removeEventListener("abort", abort);
|
|
728
|
-
this.cancels.delete(abort);
|
|
729
|
-
this.inflight--;
|
|
730
|
-
socket.destroy();
|
|
731
|
-
resolve2(value);
|
|
732
|
-
};
|
|
733
|
-
const abort = () => finish(null);
|
|
734
|
-
const timer = setTimeout(abort, holdOpen ? waitMs : 3e3);
|
|
735
|
-
const dialTimer = setTimeout(abort, 3e3);
|
|
736
|
-
this.cancels.add(abort);
|
|
737
|
-
options.signal?.addEventListener("abort", abort, { once: true });
|
|
738
|
-
socket.once("close", abort);
|
|
739
|
-
this.read(socket, (e) => {
|
|
740
|
-
if (e.to !== this.instanceId || e.from !== peerInstanceId || e.replyTo !== envelope.id || !verified(e, secret)) {
|
|
741
|
-
finish(null);
|
|
742
|
-
return;
|
|
743
|
-
}
|
|
744
|
-
if ((options.replyKinds ?? /* @__PURE__ */ new Set(["result", "ack", "state"])).has(e.kind)) finish(e);
|
|
745
|
-
}, Math.max(waitMs, 3e3));
|
|
746
|
-
socket.once("connect", () => {
|
|
747
|
-
clearTimeout(dialTimer);
|
|
748
|
-
if (done || options.signal?.aborted || this.closed) {
|
|
749
|
-
finish(null);
|
|
750
|
-
return;
|
|
751
|
-
}
|
|
752
|
-
if (!this.write(socket, envelope, secret)) {
|
|
753
|
-
finish(null);
|
|
754
|
-
return;
|
|
755
|
-
}
|
|
756
|
-
if (!holdOpen) {
|
|
757
|
-
socket.end(() => finish(envelope));
|
|
758
|
-
}
|
|
759
|
-
});
|
|
760
|
-
try {
|
|
761
|
-
socket.connect(port, "127.0.0.1");
|
|
762
|
-
} catch {
|
|
763
|
-
finish(null);
|
|
764
|
-
}
|
|
765
|
-
});
|
|
766
|
-
}
|
|
767
|
-
close() {
|
|
768
|
-
if (this.closed) return;
|
|
769
|
-
this.closed = true;
|
|
770
|
-
for (const cancel of [...this.cancels]) cancel();
|
|
771
|
-
for (const socket of this.sockets) {
|
|
772
|
-
if (socket.destroyed) continue;
|
|
773
|
-
socket.end();
|
|
774
|
-
const timer = setTimeout(() => socket.destroy(), CLOSE_FLUSH_TIMEOUT_MS);
|
|
775
|
-
timer.unref();
|
|
776
|
-
}
|
|
777
|
-
this.sockets.clear();
|
|
778
|
-
this.server.close();
|
|
779
|
-
this.port = null;
|
|
780
|
-
}
|
|
781
|
-
};
|
|
782
|
-
|
|
783
530
|
// builtin/extensions/pie-ipc/delivery.ts
|
|
784
531
|
var AllowPolicy = class {
|
|
785
532
|
/**
|
|
@@ -1361,12 +1108,14 @@ var Runtime = class {
|
|
|
1361
1108
|
const liveName = this.ctx.getSessionName?.();
|
|
1362
1109
|
if (typeof liveName === "string") this.sessionName = liveName;
|
|
1363
1110
|
const displaySessionName = this.ctx.getSessionDisplayName?.() ?? liveName;
|
|
1111
|
+
const model = this.ctx.getCurrentModel?.();
|
|
1364
1112
|
const snapshot = this.projection.snapshot({
|
|
1365
1113
|
...this.statusBase,
|
|
1366
1114
|
displayName: this.displayName,
|
|
1367
1115
|
sessionId: this.sessionId,
|
|
1368
1116
|
sessionName: this.sessionName,
|
|
1369
|
-
...displaySessionName ? { displaySessionName } : {}
|
|
1117
|
+
...displaySessionName ? { displaySessionName } : {},
|
|
1118
|
+
...typeof model === "string" && model ? { model } : {}
|
|
1370
1119
|
});
|
|
1371
1120
|
return { ...snapshot, allowPeers: [...this.allowPolicy.snapshot()], undeliveredInjections: this.delivery?.undeliveredInjections ?? snapshot.undeliveredInjections ?? 0 };
|
|
1372
1121
|
}
|
|
@@ -1821,17 +1570,47 @@ last body (snapshot; may be stale): ${clipBody(target.lastBodyText, 400)}` : ""}
|
|
|
1821
1570
|
(live query returned unparsable payload)`;
|
|
1822
1571
|
}
|
|
1823
1572
|
}
|
|
1824
|
-
/** Resolve a peer by
|
|
1573
|
+
/** Resolve a peer by a degraded chain: instance id → displayName →
|
|
1574
|
+
* sessionName/displaySessionName → sessionId prefix (11-15 stale-peer
|
|
1575
|
+
* fix). A restart mints a NEW instanceId and displayName tail, but the
|
|
1576
|
+
* logical identity (sessionName, or the sessionId when one exists)
|
|
1577
|
+
* survives it — resolving through those keys unblocks senders holding a
|
|
1578
|
+
* stale reference without another ipc_list_peers round-trip. Ambiguous
|
|
1579
|
+
* matches at any tier resolve to null (same as before); dead-pid entries
|
|
1580
|
+
* are skipped at every tier except the exact instanceId tier (which
|
|
1581
|
+
* keeps the file-view behavior of statusOf on a dying peer). */
|
|
1825
1582
|
resolvePeer(peerRef) {
|
|
1826
1583
|
const listings = listPeers(this.discoveryDir, { selfId: this.instanceId, pruneDead: false });
|
|
1827
1584
|
const ref = peerRef.trim().toLowerCase();
|
|
1828
1585
|
if (!ref) return null;
|
|
1829
|
-
const
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
if (
|
|
1833
|
-
const
|
|
1834
|
-
|
|
1586
|
+
const alive = listings.filter(({ health }) => health !== "dead");
|
|
1587
|
+
const legacyExact = alive.filter(({ file }) => file.instanceId.toLowerCase() === ref || file.displayName.toLowerCase() === ref);
|
|
1588
|
+
if (legacyExact.length === 1) return legacyExact[0].file;
|
|
1589
|
+
if (legacyExact.length > 1) return null;
|
|
1590
|
+
const legacyPrefix = alive.filter(({ file }) => file.instanceId.toLowerCase().startsWith(ref) || file.displayName.toLowerCase().startsWith(ref));
|
|
1591
|
+
if (legacyPrefix.length === 1) return legacyPrefix[0].file;
|
|
1592
|
+
const exactInstance = listings.filter(({ file }) => file.instanceId.toLowerCase() === ref);
|
|
1593
|
+
if (exactInstance.length === 1) return exactInstance[0].file;
|
|
1594
|
+
const sessionName = alive.filter(({ file }) => (file.sessionName ?? file.displaySessionName ?? "").toLowerCase() === ref || (file.displaySessionName ?? file.sessionName ?? "").toLowerCase() === ref);
|
|
1595
|
+
if (sessionName.length === 1) return sessionName[0].file;
|
|
1596
|
+
if (sessionName.length > 1) return null;
|
|
1597
|
+
const sessionPrefix = alive.filter(({ file }) => typeof file.sessionId === "string" && file.sessionId.toLowerCase().startsWith(ref) && ref.length >= 6);
|
|
1598
|
+
if (sessionPrefix.length === 1) return sessionPrefix[0].file;
|
|
1599
|
+
if (sessionPrefix.length > 1) return null;
|
|
1600
|
+
return null;
|
|
1601
|
+
}
|
|
1602
|
+
/** Compact live-peer digest for "Peer not found" errors: lets the
|
|
1603
|
+
* caller self-correct in ONE step instead of a separate list call. */
|
|
1604
|
+
livePeerHint() {
|
|
1605
|
+
const listings = listPeers(this.discoveryDir, { selfId: this.instanceId, pruneDead: false }).filter(({ health }) => health !== "dead").slice(0, 5);
|
|
1606
|
+
if (listings.length === 0) return " (no live peers discovered)";
|
|
1607
|
+
return "\nLive peers:\n" + listings.map(({ file }) => {
|
|
1608
|
+
const fileRecord = file;
|
|
1609
|
+
const humanName = typeof fileRecord.displaySessionName === "string" && fileRecord.displaySessionName.trim() ? fileRecord.displaySessionName.trim() : void 0;
|
|
1610
|
+
const label = humanName ?? peerLabel(file.instanceId, file.displayName);
|
|
1611
|
+
const sid = file.sessionId ? ` session=${file.sessionId.slice(0, 8)}` : "";
|
|
1612
|
+
return ` ${label} [${file.state}]${sid}`;
|
|
1613
|
+
}).join("\n");
|
|
1835
1614
|
}
|
|
1836
1615
|
/** MULTI-AGENT IM v2 Phase 2.3 — send an enumerated CONTROL frame to a
|
|
1837
1616
|
* peer (first control: model.set). Returns the peer's receipt (the ack
|
|
@@ -1840,7 +1619,7 @@ last body (snapshot; may be stale): ${clipBody(target.lastBodyText, 400)}` : ""}
|
|
|
1840
1619
|
* it directly. Awaits the ack (bounded); null means unreachable/timeout. */
|
|
1841
1620
|
async sendControl(peerRef, control, payload, waitMs) {
|
|
1842
1621
|
const target = this.resolvePeer(peerRef);
|
|
1843
|
-
if (!target) return { content: [{ type: "text", text: `Peer not found: ${peerRef}. Call ipc_list_peers first
|
|
1622
|
+
if (!target) return { content: [{ type: "text", text: `Peer not found: ${peerRef}. Call ipc_list_peers first.${this.livePeerHint()}` }], isError: true };
|
|
1844
1623
|
if (!target.port) return { content: [{ type: "text", text: `${peerLabel(target.instanceId, target.displayName)} is not listening.` }], isError: true };
|
|
1845
1624
|
if (!this.transport) return { content: [{ type: "text", text: "IPC transport is unavailable." }], isError: true };
|
|
1846
1625
|
const body = JSON.stringify({ control, ...payload !== void 0 ? { payload } : {} });
|
|
@@ -1857,7 +1636,7 @@ last body (snapshot; may be stale): ${clipBody(target.lastBodyText, 400)}` : ""}
|
|
|
1857
1636
|
async sendToPeer(peerRef, text, wait, waitMs, context, notify = false, fallbackMs = DEFAULT_NOTIFY_FALLBACK_MS) {
|
|
1858
1637
|
const target = this.resolvePeer(peerRef);
|
|
1859
1638
|
if (!target) {
|
|
1860
|
-
return { content: [{ type: "text", text: `Peer not found: ${peerRef}. Call ipc_list_peers first
|
|
1639
|
+
return { content: [{ type: "text", text: `Peer not found: ${peerRef}. Call ipc_list_peers first.${this.livePeerHint()}` }], isError: true };
|
|
1861
1640
|
}
|
|
1862
1641
|
if (!target.port) {
|
|
1863
1642
|
return { content: [{ type: "text", text: `${peerLabel(target.instanceId, target.displayName)} is not listening (client-only or headless host).` }], isError: true };
|
|
@@ -1866,7 +1645,7 @@ last body (snapshot; may be stale): ${clipBody(target.lastBodyText, 400)}` : ""}
|
|
|
1866
1645
|
return { content: [{ type: "text", text: "IPC transport is unavailable (server startup failed or instance disposed)." }], isError: true };
|
|
1867
1646
|
}
|
|
1868
1647
|
const body = clipBody(text, this.config.maxBodyChars);
|
|
1869
|
-
const requestId =
|
|
1648
|
+
const requestId = randomUUID();
|
|
1870
1649
|
const notifyMode = notify && !wait;
|
|
1871
1650
|
const sendGeneration = this.notifyGeneration;
|
|
1872
1651
|
let userAssigned = false;
|
|
@@ -1925,7 +1704,7 @@ ${snapshot}` }],
|
|
|
1925
1704
|
}
|
|
1926
1705
|
async resultOf(peerRef, requestId, limit, context) {
|
|
1927
1706
|
const target = this.resolvePeer(peerRef);
|
|
1928
|
-
if (!target) return { content: [{ type: "text", text: `Peer not found: ${peerRef}. Call ipc_list_peers first
|
|
1707
|
+
if (!target) return { content: [{ type: "text", text: `Peer not found: ${peerRef}. Call ipc_list_peers first.${this.livePeerHint()}` }], isError: true };
|
|
1929
1708
|
if (!target.port || !this.transport) return { content: [{ type: "text", text: `${peerLabel(target.instanceId, target.displayName)} has no live listener for result queries.` }], isError: true };
|
|
1930
1709
|
const reply = await this.transport.send(target.instanceId, target.port, "result.get", {
|
|
1931
1710
|
text: JSON.stringify({ ...requestId ? { requestId } : {}, limit: Math.max(1, Math.min(20, Math.floor(limit))) }),
|
|
@@ -2001,6 +1780,7 @@ function safeRead(file) {
|
|
|
2001
1780
|
throw error;
|
|
2002
1781
|
}
|
|
2003
1782
|
}
|
|
1783
|
+
var __runtimeForTests = (ctx, config, discoveryDir) => new Runtime(ctx, config, discoveryDir);
|
|
2004
1784
|
function pieIpcExtension(ctx) {
|
|
2005
1785
|
const rawConfigDir = process.env.PIE_IPC_CONFIG_DIR ?? getConfigDirSafe(ctx);
|
|
2006
1786
|
const configDir = process.platform === "win32" ? rawConfigDir : path4.resolve(rawConfigDir === "~" ? homeDir() : rawConfigDir.startsWith("~/") ? path4.join(homeDir(), rawConfigDir.slice(2)) : rawConfigDir);
|
|
@@ -2114,7 +1894,9 @@ function pieIpcExtension(ctx) {
|
|
|
2114
1894
|
ctx.registerTool({
|
|
2115
1895
|
name: "ipc_send_notify",
|
|
2116
1896
|
label: "Send a message to a Pie peer and get notified when it finishes",
|
|
2117
|
-
description: `Send text to another Pie process (interactive peer) and SUBSCRIBE to its completion \u2014 the name is the contract: fire-and-forget sending requires an explicit notify:false. Default behavior: returns right after the receipt ack with a requestId; when the peer's turn settles (success, failure, or cancellation) it pushes one [ipc-done] notification as inbound input, and a local fallback timer (fallbackMs, default 600000ms) wakes a result check if that push is lost \u2014 you will be called back, do not poll in a loop and never resend while a result is pending. wait=true: hold the tool call open instead (bounded by waitMs) \u2014 one-shot hosts only. notify:false: explicit fire-and-forget (return after socket submission; receipt/consumption not confirmed; no wake). Inbound messages from peers arrive as user input or in ipc_poll
|
|
1897
|
+
description: `Send text to another Pie process (interactive peer) and SUBSCRIBE to its completion \u2014 the name is the contract: fire-and-forget sending requires an explicit notify:false. Default behavior: returns right after the receipt ack with a requestId; when the peer's turn settles (success, failure, or cancellation) it pushes one [ipc-done] notification as inbound input, and a local fallback timer (fallbackMs, default 600000ms) wakes a result check if that push is lost \u2014 you will be called back, do not poll in a loop and never resend while a result is pending. wait=true: hold the tool call open instead (bounded by waitMs) \u2014 one-shot hosts only. notify:false: explicit fire-and-forget (return after socket submission; receipt/consumption not confirmed; no wake). Inbound messages from peers arrive as user input or in ipc_poll.
|
|
1898
|
+
|
|
1899
|
+
SIDE EFFECT: this is NOT a read-only query. The text is injected into the peer's conversation as a user input and triggers one full model turn on the peer (cost + side effects there). If the user only asked you to observe (\u770B\u770B/\u67E5\u67E5/\u4E86\u89E3\u4E00\u4E0B a peer), do NOT use this tool: read ipc_list_peers/ipc_status or the peer's session files instead. Use this tool to dispatch work or ask a peer only when the user explicitly authorized contacting that peer.`,
|
|
2118
1900
|
parameters: Type.Object({
|
|
2119
1901
|
to: Type.String({ description: "Peer display name or instance id (see ipc_list_peers)" }),
|
|
2120
1902
|
text: Type.String({ description: "Message body for the peer" }),
|
|
@@ -2293,5 +2075,6 @@ function homeDir() {
|
|
|
2293
2075
|
return process.env.HOME ?? process.env.USERPROFILE ?? "/tmp";
|
|
2294
2076
|
}
|
|
2295
2077
|
export {
|
|
2078
|
+
__runtimeForTests,
|
|
2296
2079
|
pieIpcExtension as default
|
|
2297
2080
|
};
|
|
@@ -334,7 +334,7 @@ function pieProc(ctx) {
|
|
|
334
334
|
const observed = Math.max(w.lastActiveAt, observeActivity(w));
|
|
335
335
|
if (observed > w.lastActiveAt) persistActivity(w, observed);
|
|
336
336
|
}
|
|
337
|
-
|
|
337
|
+
casRegistry((snap) => {
|
|
338
338
|
const cutoff = Date.now();
|
|
339
339
|
let changed = false;
|
|
340
340
|
const keep = [];
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
createPlanCapability,
|
|
7
7
|
markCompletedPlanSteps,
|
|
8
8
|
restoreExecutionState
|
|
9
|
-
} from "../../../chunks/chunk-
|
|
9
|
+
} from "../../../chunks/chunk-N5B5IGJ6.js";
|
|
10
10
|
import "../../../chunks/chunk-XMOWWL4B.js";
|
|
11
11
|
import "../../../chunks/chunk-B4N5LJMD.js";
|
|
12
12
|
import "../../../chunks/chunk-6JEYRAQM.js";
|
|
@@ -191,7 +191,8 @@ ${steps}${warningLines}`;
|
|
|
191
191
|
planModeEnabled = false;
|
|
192
192
|
ctx.setSessionMetadata(SESSION_METADATA_KEY, false);
|
|
193
193
|
ctx.setPlanMode(false);
|
|
194
|
-
const
|
|
194
|
+
const prefix = revisionPrefix;
|
|
195
|
+
const merged = prefix ? [...prefix, ...items.map((item, index) => ({ ...item, step: prefix.length + index + 1 }))] : items;
|
|
195
196
|
revisionPrefix = null;
|
|
196
197
|
setExecutingPlan(merged.length > 0);
|
|
197
198
|
writeExecutionState(createExecutionStateFromPlan(merged));
|
|
@@ -325,9 +326,9 @@ Update the plan accordingly and call plan_submit again with the revised steps. D
|
|
|
325
326
|
return bare;
|
|
326
327
|
}).filter(Boolean)
|
|
327
328
|
}));
|
|
328
|
-
if (normalized.every((item) => item.files.length === 0)) return [];
|
|
329
|
+
if (normalized.every((item) => (item.files ?? []).length === 0)) return [];
|
|
329
330
|
const existsCache = /* @__PURE__ */ new Map();
|
|
330
|
-
for (const target of new Set(normalized.flatMap((item) => item.files))) {
|
|
331
|
+
for (const target of new Set(normalized.flatMap((item) => item.files ?? []))) {
|
|
331
332
|
existsCache.set(target, await pathExists(target));
|
|
332
333
|
}
|
|
333
334
|
return checkPlanScope(
|
|
@@ -337,7 +338,7 @@ Update the plan accordingly and call plan_submit again with the revised steps. D
|
|
|
337
338
|
);
|
|
338
339
|
}
|
|
339
340
|
ctx.registerCommand({
|
|
340
|
-
path: capability.commands?.[0]?.path ?? ["tools", "plan"],
|
|
341
|
+
path: [...capability.commands?.[0]?.path ?? ["tools", "plan"]],
|
|
341
342
|
description: "Toggle plan mode (read-only exploration, discussion-first)",
|
|
342
343
|
handler: async () => {
|
|
343
344
|
togglePlanMode();
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
createCliRetryPolicy,
|
|
6
6
|
formatTransportLifecycle,
|
|
7
7
|
logTransportLifecycle
|
|
8
|
-
} from "../../../chunks/chunk-
|
|
8
|
+
} from "../../../chunks/chunk-I7PBXG5Q.js";
|
|
9
9
|
import {
|
|
10
10
|
getConfigDir
|
|
11
11
|
} from "../../../chunks/chunk-ILUHTKF3.js";
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
createPolicyEnforcedTools,
|
|
15
15
|
createSharedFileSystemTools,
|
|
16
16
|
createSubagentCapability
|
|
17
|
-
} from "../../../chunks/chunk-
|
|
17
|
+
} from "../../../chunks/chunk-N5B5IGJ6.js";
|
|
18
18
|
import "../../../chunks/chunk-XMOWWL4B.js";
|
|
19
19
|
import "../../../chunks/chunk-B4N5LJMD.js";
|
|
20
20
|
import "../../../chunks/chunk-6JEYRAQM.js";
|
|
@@ -381,6 +381,9 @@ function createSubagentSessionStore(sessionsDir, log, deps) {
|
|
|
381
381
|
|
|
382
382
|
// builtin/extensions/subagent/index.ts
|
|
383
383
|
import * as path2 from "path";
|
|
384
|
+
function preserveModelResolution(r) {
|
|
385
|
+
return r === void 0 ? void 0 : { ...r, model: r.model };
|
|
386
|
+
}
|
|
384
387
|
function subagentExtension(ctx) {
|
|
385
388
|
ctx.log("Subagent extension loaded (transparent parallel mode)");
|
|
386
389
|
const resolveRuntimePair = () => {
|
|
@@ -419,8 +422,14 @@ function subagentExtension(ctx) {
|
|
|
419
422
|
ctx.log(formatTransportLifecycle(event));
|
|
420
423
|
}
|
|
421
424
|
},
|
|
422
|
-
resolveModelClass: (modelClass) =>
|
|
423
|
-
|
|
425
|
+
resolveModelClass: (modelClass) => {
|
|
426
|
+
const r = ctx.resolveModelClass?.(modelClass);
|
|
427
|
+
return preserveModelResolution(r);
|
|
428
|
+
},
|
|
429
|
+
resolveModelRef: (modelRef) => {
|
|
430
|
+
const r = ctx.resolveModelRef?.(modelRef);
|
|
431
|
+
return preserveModelResolution(r);
|
|
432
|
+
},
|
|
424
433
|
createRuntimeTools: (mode) => {
|
|
425
434
|
const parentRuntimeTools = ctx.getRuntimeTools();
|
|
426
435
|
if (Array.isArray(parentRuntimeTools) && parentRuntimeTools.length > 0) {
|
|
@@ -450,5 +459,6 @@ function subagentExtension(ctx) {
|
|
|
450
459
|
}
|
|
451
460
|
}
|
|
452
461
|
export {
|
|
453
|
-
subagentExtension as default
|
|
462
|
+
subagentExtension as default,
|
|
463
|
+
preserveModelResolution
|
|
454
464
|
};
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
executeManageTodoList,
|
|
9
9
|
executionStateToTodos,
|
|
10
10
|
restoreExecutionState
|
|
11
|
-
} from "../../../chunks/chunk-
|
|
11
|
+
} from "../../../chunks/chunk-N5B5IGJ6.js";
|
|
12
12
|
import "../../../chunks/chunk-XMOWWL4B.js";
|
|
13
13
|
import "../../../chunks/chunk-B4N5LJMD.js";
|
|
14
14
|
import "../../../chunks/chunk-6JEYRAQM.js";
|
|
@@ -50,7 +50,11 @@ function todoExtension(ctx) {
|
|
|
50
50
|
persistExecutionState(ctx, nextState, args.action === "create" ? "create" : args.action === "clear" ? "explicit_clear" : execution.nextTodos.length === 0 ? "completed_clear" : "advance");
|
|
51
51
|
notifyWidget(ctx, nextState);
|
|
52
52
|
}
|
|
53
|
-
return
|
|
53
|
+
return {
|
|
54
|
+
content: execution.result.content.map((block) => ({ type: "text", text: "text" in block ? block.text : "" })),
|
|
55
|
+
details: execution.result.details,
|
|
56
|
+
isError: execution.result.isError
|
|
57
|
+
};
|
|
54
58
|
}
|
|
55
59
|
});
|
|
56
60
|
ctx.on("session:changed", async () => {
|