@cydm/pie 4.3.4 → 4.3.5
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.
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
readLiveConfig,
|
|
19
19
|
readLiveEnabled,
|
|
20
20
|
registerDispatchReceiver,
|
|
21
|
+
registerTurnImDriver,
|
|
21
22
|
resolveConfig,
|
|
22
23
|
resolveConfigDir,
|
|
23
24
|
resolveImForwardConfig,
|
|
@@ -26,7 +27,7 @@ import {
|
|
|
26
27
|
truncateMarkdown,
|
|
27
28
|
tryClaimConsumer,
|
|
28
29
|
writeConfig
|
|
29
|
-
} from "../../../chunks/chunk-
|
|
30
|
+
} from "../../../chunks/chunk-H5G55G3R.js";
|
|
30
31
|
import {
|
|
31
32
|
detectImageMime,
|
|
32
33
|
readImageFormat
|
|
@@ -934,7 +935,8 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
934
935
|
}
|
|
935
936
|
if (inbound?.role === "user" && isConcierge && currentSessionId) {
|
|
936
937
|
const userText = typeof inbound.content === "string" ? inbound.content : Array.isArray(inbound.content) ? inbound.content.map((block) => block && typeof block === "object" && typeof block.text === "string" ? block.text : "").join("") : "";
|
|
937
|
-
const
|
|
938
|
+
const stampedWake = /^\[pie-ipc\][^\n]*says:\s*\n?\[(?:ipc-done|ipc-check|ipc-done-check)\] (?:No completion notification arrived for |The completion notification for )?requestId=[a-zA-Z0-9:-]+ (?:outcome=\S+ )?(?:\([^)]*\) )?user_assigned=true(?:\s|$)/;
|
|
939
|
+
const wrappedNotify = stampedWake.exec(userText);
|
|
938
940
|
if (wrappedNotify) {
|
|
939
941
|
const requestTag = /requestId=([a-zA-Z0-9:-]+)/.exec(userText)?.[1] ?? "ipc-delivery";
|
|
940
942
|
stampDeliveryDestination(`ipc-done:${requestTag}`);
|
|
@@ -1280,6 +1282,30 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
1280
1282
|
claimThread: seamClaimThread,
|
|
1281
1283
|
anchors: sentAnchors
|
|
1282
1284
|
};
|
|
1285
|
+
registerTurnImDriver(() => {
|
|
1286
|
+
const sid = currentSessionId;
|
|
1287
|
+
if (!sid) return false;
|
|
1288
|
+
const messages = ctx.getMessages?.() ?? [];
|
|
1289
|
+
let lastUserText;
|
|
1290
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1291
|
+
const message = messages[i];
|
|
1292
|
+
if (!isRecord(message) || message.role !== "user") continue;
|
|
1293
|
+
const joined = (typeof message.content === "string" ? message.content : Array.isArray(message.content) ? message.content.map((block) => isRecord(block) && typeof block.text === "string" ? block.text : "").join("") : "").trim();
|
|
1294
|
+
if (joined) {
|
|
1295
|
+
lastUserText = joined;
|
|
1296
|
+
break;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
if (!lastUserText) return false;
|
|
1300
|
+
for (let j = 0; j < pendingInputs.length; j++) {
|
|
1301
|
+
const pending = pendingInputs[j];
|
|
1302
|
+
if (pending.sessionId !== sid) continue;
|
|
1303
|
+
const expected = (pending.messageId ? `${IM_INPUT_PREFIX}
|
|
1304
|
+
${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
1305
|
+
if (lastUserText === expected) return true;
|
|
1306
|
+
}
|
|
1307
|
+
return false;
|
|
1308
|
+
});
|
|
1283
1309
|
registerDispatchReceiver((text) => {
|
|
1284
1310
|
const trimmed = text.trimStart();
|
|
1285
1311
|
if (!trimmed.startsWith(DISPATCH_PREFIX)) return false;
|
|
@@ -1937,6 +1963,7 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
|
|
|
1937
1963
|
inputEpoch++;
|
|
1938
1964
|
terminated = true;
|
|
1939
1965
|
registerDispatchReceiver(void 0);
|
|
1966
|
+
registerTurnImDriver(void 0);
|
|
1940
1967
|
consumerLock?.release();
|
|
1941
1968
|
consumerLock = void 0;
|
|
1942
1969
|
const resources = [...scopes];
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
clipBody,
|
|
16
16
|
foldLifecycleEvent,
|
|
17
17
|
generateInstanceId,
|
|
18
|
+
isTurnUserImDriven,
|
|
18
19
|
isValidInstanceId,
|
|
19
20
|
isWrappedInboundText,
|
|
20
21
|
parseStatusFile,
|
|
@@ -24,7 +25,7 @@ import {
|
|
|
24
25
|
takeDispatchFrame,
|
|
25
26
|
wrapInboundText,
|
|
26
27
|
wrappedMessageMarker
|
|
27
|
-
} from "../../../chunks/chunk-
|
|
28
|
+
} from "../../../chunks/chunk-H5G55G3R.js";
|
|
28
29
|
import {
|
|
29
30
|
Type
|
|
30
31
|
} from "../../../chunks/chunk-XXGYUYXI.js";
|
|
@@ -1470,7 +1471,10 @@ var Runtime = class {
|
|
|
1470
1471
|
return;
|
|
1471
1472
|
}
|
|
1472
1473
|
const doneMatch = /^\[ipc-done\] requestId=([a-zA-Z0-9:-]{1,128}) /.exec(envelope.text ?? "");
|
|
1473
|
-
if (doneMatch && this.allowPolicy.allows(envelope.from))
|
|
1474
|
+
if (doneMatch && this.allowPolicy.allows(envelope.from)) {
|
|
1475
|
+
const stampedDone = /^\[ipc-done\] requestId=[a-zA-Z0-9:-]{1,128} (?:outcome=\S+ )?(?:\([^)]*\) )?user_assigned=true(?:\s|$)/.test((envelope.text ?? "").split("\n")[0] ?? "");
|
|
1476
|
+
this.completeNotify(doneMatch[1], stampedDone);
|
|
1477
|
+
}
|
|
1474
1478
|
if (envelope.waitMs && this.awaitingReply.size >= 100) {
|
|
1475
1479
|
reply("result", "rejected: reply capacity reached");
|
|
1476
1480
|
return;
|
|
@@ -1676,7 +1680,7 @@ ${body}` : ""}`;
|
|
|
1676
1680
|
* hint so the model checks ipc_result itself. The wake goes through the
|
|
1677
1681
|
* normal inbound path (sendUserMessage), which the interactive host queues
|
|
1678
1682
|
* when busy and the embedded host emits as a user.message event. */
|
|
1679
|
-
armNotifyFallback(requestId, fallbackMs, peerName) {
|
|
1683
|
+
armNotifyFallback(requestId, fallbackMs, peerName, userAssigned = false) {
|
|
1680
1684
|
if (this.completedNotifies.has(requestId)) {
|
|
1681
1685
|
this.completedNotifies.delete(requestId);
|
|
1682
1686
|
return true;
|
|
@@ -1690,7 +1694,8 @@ ${body}` : ""}`;
|
|
|
1690
1694
|
this.notifyFallbacks.delete(requestId);
|
|
1691
1695
|
this.completedNotifies.delete(requestId);
|
|
1692
1696
|
if (this.disposed) return;
|
|
1693
|
-
const
|
|
1697
|
+
const hintBody = `[ipc-check] No completion notification arrived for requestId=${requestId}${userAssigned ? " user_assigned=true" : ""} (peer ${peerName}) within ${Math.round(fallbackMs / 1e3)}s. Query ipc_result for the authoritative status; accepted/running means the peer is still working \u2014 keep waiting or check again later, and never resend while a result is pending.`;
|
|
1698
|
+
const hint = wrapInboundText(`local-recovery (${peerName})`, hintBody);
|
|
1694
1699
|
try {
|
|
1695
1700
|
const scope = this.ctx.beginUserInput?.();
|
|
1696
1701
|
if (scope) {
|
|
@@ -1712,7 +1717,7 @@ ${body}` : ""}`;
|
|
|
1712
1717
|
* not observation, so instead of silently cancelling the only wake, the
|
|
1713
1718
|
* fallback fires IMMEDIATELY as a [ipc-done-check] hint carrying the
|
|
1714
1719
|
* outcome — every host kind surfaces the completion exactly once. */
|
|
1715
|
-
completeNotify(requestId) {
|
|
1720
|
+
completeNotify(requestId, userAssigned = false) {
|
|
1716
1721
|
const willInject = this.delivery?.willInjectNow() ?? this.ctx.capabilities.editorInjection;
|
|
1717
1722
|
if (willInject) {
|
|
1718
1723
|
this.clearNotifyFallback(requestId);
|
|
@@ -1727,7 +1732,9 @@ ${body}` : ""}`;
|
|
|
1727
1732
|
}
|
|
1728
1733
|
if (this.disposed) return;
|
|
1729
1734
|
try {
|
|
1730
|
-
|
|
1735
|
+
const stamped = userAssigned ? " user_assigned=true" : "";
|
|
1736
|
+
const body = `[ipc-done-check] The completion notification for requestId=${requestId}${stamped} is waiting in the ipc inbox (this host is not auto-injecting right now \u2014 muted, degraded, or embedded). Call ipc_poll to read it; the outcome line starts with [ipc-done]. Do not resend.`;
|
|
1737
|
+
this.ctx.sendUserMessage(wrapInboundText("local-inbox-wake", body));
|
|
1731
1738
|
} catch {
|
|
1732
1739
|
}
|
|
1733
1740
|
}
|
|
@@ -1864,20 +1871,7 @@ last body (snapshot; may be stale): ${clipBody(target.lastBodyText, 400)}` : ""}
|
|
|
1864
1871
|
const sendGeneration = this.notifyGeneration;
|
|
1865
1872
|
let userAssigned = false;
|
|
1866
1873
|
if (notifyMode) {
|
|
1867
|
-
|
|
1868
|
-
const messages = this.ctx.getMessages?.() ?? [];
|
|
1869
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1870
|
-
const message = messages[i];
|
|
1871
|
-
if (!message || message.role !== "user") continue;
|
|
1872
|
-
const content = message.content;
|
|
1873
|
-
const text2 = typeof content === "string" ? content : Array.isArray(content) ? content.map((block) => block && typeof block === "object" && "text" in block && typeof block.text === "string" ? block.text : "").join("") : "";
|
|
1874
|
-
const trimmed = text2.trim();
|
|
1875
|
-
if (!trimmed) continue;
|
|
1876
|
-
userAssigned = /^\[(Feishu|Other)\]/.test(trimmed) && !trimmed.startsWith("[ipc-done]") && !trimmed.startsWith("[pie-ipc]");
|
|
1877
|
-
break;
|
|
1878
|
-
}
|
|
1879
|
-
} catch {
|
|
1880
|
-
}
|
|
1874
|
+
userAssigned = isTurnUserImDriven();
|
|
1881
1875
|
}
|
|
1882
1876
|
const reply = await this.transport.send(target.instanceId, target.port, "message", {
|
|
1883
1877
|
requestId,
|
|
@@ -1897,7 +1891,7 @@ last body (snapshot; may be stale): ${clipBody(target.lastBodyText, 400)}` : ""}
|
|
|
1897
1891
|
}
|
|
1898
1892
|
if (!reply) {
|
|
1899
1893
|
const peerName2 = peerLabel(target.instanceId, target.displayName);
|
|
1900
|
-
const armed2 = this.armNotifyFallback(requestId, fallbackMs, peerName2);
|
|
1894
|
+
const armed2 = this.armNotifyFallback(requestId, fallbackMs, peerName2, userAssigned);
|
|
1901
1895
|
return {
|
|
1902
1896
|
content: [{ type: "text", text: `Receipt UNCONFIRMED \u2014 the request may already be accepted by ${peerName2} (accepted work is never cancelled). Query ipc_result with requestId=${requestId} before resending. ${armed2 ? `A fallback check is armed for ${Math.round(fallbackMs / 1e3)}s if the peer's completion push never arrives.` : "No automatic wake is armed (fallback budget exhausted) \u2014 check ipc_result yourself."}` }],
|
|
1903
1897
|
isError: true,
|
|
@@ -1908,7 +1902,7 @@ last body (snapshot; may be stale): ${clipBody(target.lastBodyText, 400)}` : ""}
|
|
|
1908
1902
|
return { content: [{ type: "text", text: reply.text ?? "(empty reply)" }], isError: true, details: { requestId } };
|
|
1909
1903
|
}
|
|
1910
1904
|
const peerName = peerLabel(target.instanceId, target.displayName);
|
|
1911
|
-
const armed = this.armNotifyFallback(requestId, fallbackMs, peerName);
|
|
1905
|
+
const armed = this.armNotifyFallback(requestId, fallbackMs, peerName, userAssigned);
|
|
1912
1906
|
return { content: [{ type: "text", text: armed ? `Sent to ${peerName} with completion subscription (receipt acked as ${reply.kind}; the peer pushes one [ipc-done] notification when its turn settles). If no notification arrives within ${Math.round(fallbackMs / 1e3)}s, check ipc_result with this requestId; do not resend on a pending result. requestId=${requestId}` : `Sent to ${peerName} with completion subscription (receipt acked). The local fallback-wake budget is exhausted (${this.notifyFallbacks.size} outstanding checks), so NO automatic wake is armed for this request \u2014 check ipc_result yourself when you need its result. requestId=${requestId}` }], details: { requestId } };
|
|
1913
1907
|
}
|
|
1914
1908
|
if (!wait) {
|
|
@@ -552,6 +552,17 @@ import * as fs2 from "node:fs";
|
|
|
552
552
|
import * as path2 from "node:path";
|
|
553
553
|
var DISPATCH_PREFIX = "[im-forward-dispatch]";
|
|
554
554
|
var dispatchReceiver;
|
|
555
|
+
var turnImDriverOracle;
|
|
556
|
+
function registerTurnImDriver(oracle) {
|
|
557
|
+
turnImDriverOracle = oracle;
|
|
558
|
+
}
|
|
559
|
+
function isTurnUserImDriven() {
|
|
560
|
+
try {
|
|
561
|
+
return turnImDriverOracle?.() === true;
|
|
562
|
+
} catch {
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
555
566
|
function registerDispatchReceiver(receiver) {
|
|
556
567
|
dispatchReceiver = receiver;
|
|
557
568
|
}
|
|
@@ -1026,6 +1037,8 @@ export {
|
|
|
1026
1037
|
readLiveConfig,
|
|
1027
1038
|
resolveImForwardConfig,
|
|
1028
1039
|
DISPATCH_PREFIX,
|
|
1040
|
+
registerTurnImDriver,
|
|
1041
|
+
isTurnUserImDriven,
|
|
1029
1042
|
registerDispatchReceiver,
|
|
1030
1043
|
takeDispatchFrame,
|
|
1031
1044
|
tryClaimConsumer,
|