@cydm/pie 4.8.0 → 4.9.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 +51 -27
- package/dist/builtin/extensions/ask-user/index.js +4 -4
- package/dist/builtin/extensions/cron/index.js +906 -158
- package/dist/builtin/extensions/im-forward/README.md +4 -2
- package/dist/builtin/extensions/im-forward/index.js +6822 -3951
- package/dist/builtin/extensions/memory/index.js +76 -28
- package/dist/builtin/extensions/pie-ipc/README.md +2 -2
- package/dist/builtin/extensions/pie-ipc/index.js +282 -58
- package/dist/builtin/extensions/pie-proc/README.md +7 -7
- package/dist/builtin/extensions/pie-proc/index.js +227 -75
- package/dist/builtin/extensions/plan-mode/index.js +5 -5
- package/dist/builtin/extensions/subagent/index.js +8 -8
- package/dist/builtin/extensions/todo/index.js +4 -4
- package/dist/builtin/skills/chrome-devtools-axi/SKILL.md +26 -24
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-bridge.js +199 -121
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/chunk-HAUDUMDO.js +795 -0
- package/dist/builtin/skills/chrome-devtools-axi/{cli-ZE754CTH.js → cli-K7ESY3XD.js} +433 -255
- package/dist/builtin/skills/computer-use-axi/SKILL.md +25 -8
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +293 -64
- package/dist/builtin/skills/computer-use-axi/computer-use-axi-runtime.js +2 -2
- package/dist/builtin/skills/tui-use/tui-use-daemon.cjs +451 -43
- package/dist/chunks/{chunk-3W3SXVPB.js → chunk-4UIUMTHG.js} +993 -371
- package/dist/chunks/chunk-6WKBQZWM.js +19 -0
- package/dist/chunks/{chunk-5KI4Y4LA.js → chunk-BA4Z27XT.js} +4 -3
- package/dist/chunks/{chunk-BLDI2GRF.js → chunk-DBDU3RRN.js} +1364 -446
- package/dist/chunks/{chunk-LAJXWOKS.js → chunk-EEC5PJTC.js} +11 -9
- package/dist/chunks/chunk-IZKHSUNQ.js +30 -0
- package/dist/chunks/{chunk-Y3I2UV5Y.js → chunk-LRHNAG4V.js} +349 -288
- package/dist/chunks/chunk-OU33ROFD.js +717 -0
- package/dist/chunks/{chunk-Z2FKA2ZH.js → chunk-PN6B54VT.js} +104 -22
- package/dist/chunks/{chunk-NHV2CALB.js → chunk-WYXUF4MP.js} +388 -32
- package/dist/chunks/{chunk-4PR34UZF.js → chunk-Z5KL6AO2.js} +159 -145
- package/dist/chunks/{host-image-fallback-N7RHNPYN.js → host-image-fallback-RASJSVZY.js} +1 -1
- package/dist/chunks/{manager-cli-NEZA46M5.js → manager-cli-Y6HM3MHA.js} +5 -5
- package/dist/chunks/{model-registry-3XAHXXTA.js → model-registry-5TLYILYR.js} +2 -2
- package/dist/chunks/{read-file-understanding-FMPXR6EJ.js → read-file-understanding-VPKDBV23.js} +5 -5
- package/dist/chunks/{src-B44QWSGM.js → src-2XI5P62J.js} +2 -2
- package/dist/chunks/{src-EGXFJ3WA.js → src-6QGGDHIW.js} +3 -3
- package/dist/chunks/{src-Q7LU27C2.js → src-CCEENRKC.js} +31 -1
- package/dist/chunks/{src-CLE5ILN4.js → src-DI4MCAGT.js} +20 -4
- package/dist/chunks/{test-stream-OR3EJBNF.js → test-stream-SYVWIPPW.js} +2 -2
- package/dist/cli.js +1890 -1489
- package/models.schema.json +271 -0
- package/package.json +2 -2
- package/dist/builtin/skills/chrome-devtools-axi/chunk-Z2A5LA5A.js +0 -407
- package/dist/chunks/chunk-EGZ5TZRM.js +0 -1444
- package/dist/chunks/{chunk-CGSFBWOM.js → chunk-WBL73KRI.js} +3 -3
- package/dist/chunks/{manager-upgrade-CTU3ISCW.js → manager-upgrade-LSTOHBUV.js} +3 -3
|
@@ -25,8 +25,7 @@ import {
|
|
|
25
25
|
takeDispatchFrame,
|
|
26
26
|
wrapInboundText,
|
|
27
27
|
wrappedMessageMarker
|
|
28
|
-
} from "../../../chunks/chunk-
|
|
29
|
-
import "../../../chunks/chunk-ZPJ3BNQB.js";
|
|
28
|
+
} from "../../../chunks/chunk-OU33ROFD.js";
|
|
30
29
|
import {
|
|
31
30
|
Type
|
|
32
31
|
} from "../../../chunks/chunk-XXGYUYXI.js";
|
|
@@ -857,6 +856,231 @@ function resultJson(payload) {
|
|
|
857
856
|
throw new Error("result payload exceeds envelope body cap");
|
|
858
857
|
}
|
|
859
858
|
|
|
859
|
+
// builtin/extensions/pie-ipc/peek-projection.ts
|
|
860
|
+
var DEFAULT_PEEK_CHAR_BUDGET = 1e3;
|
|
861
|
+
var MIN_PEEK_CHAR_BUDGET = 300;
|
|
862
|
+
var MAX_PEEK_CHAR_BUDGET = 2e3;
|
|
863
|
+
var MAX_ENTRIES_PER_PAGE = 12;
|
|
864
|
+
var ENTRY_PACK_OVERHEAD = 40;
|
|
865
|
+
function extractSafeToolProgress(partial) {
|
|
866
|
+
if (!partial || typeof partial !== "object") return void 0;
|
|
867
|
+
const p = partial;
|
|
868
|
+
if (!p.details || typeof p.details !== "object" || !("increment" in p.details) || !Array.isArray(p.content)) return void 0;
|
|
869
|
+
const text = p.content.map((block) => block && typeof block === "object" && block.type === "text" && typeof block.text === "string" ? block.text : "").filter(Boolean).at(-1)?.replace(/\u0000/g, "").trim();
|
|
870
|
+
return text ? text.slice(0, 500) : void 0;
|
|
871
|
+
}
|
|
872
|
+
function clampPeekCharBudget(value) {
|
|
873
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return DEFAULT_PEEK_CHAR_BUDGET;
|
|
874
|
+
return Math.min(MAX_PEEK_CHAR_BUDGET, Math.max(MIN_PEEK_CHAR_BUDGET, Math.floor(value)));
|
|
875
|
+
}
|
|
876
|
+
function normalizePeekPage(value) {
|
|
877
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 1) return 1;
|
|
878
|
+
return Math.floor(value);
|
|
879
|
+
}
|
|
880
|
+
function stripInternalUserHeaders(raw) {
|
|
881
|
+
let text = raw.replace(/\u0000/g, "").trim();
|
|
882
|
+
if (!text) return { text: "" };
|
|
883
|
+
if (text.startsWith("[im-forward-dispatch]")) return { text: "" };
|
|
884
|
+
let tag;
|
|
885
|
+
for (let i = 0; i < 4; i++) {
|
|
886
|
+
const next = text.replace(/^\[pie-ipc\][^\n]*says:\s*(?:\r?\n)?/, "");
|
|
887
|
+
if (next === text) break;
|
|
888
|
+
text = next.trim();
|
|
889
|
+
if (text.startsWith("[im-forward-dispatch]")) return { text: "" };
|
|
890
|
+
}
|
|
891
|
+
if (text.startsWith("[ipc-done]")) {
|
|
892
|
+
tag = "ipc-done";
|
|
893
|
+
text = text.replace(/^\[ipc-done\][^\n]*(?:\r?\n)?/, "").trim();
|
|
894
|
+
} else if (text.startsWith("[ipc-done-check]") || text.startsWith("[ipc-check]")) {
|
|
895
|
+
tag = "ipc-check";
|
|
896
|
+
text = text.replace(/^\[ipc-(?:done-)?check\]\s*/, "").trim();
|
|
897
|
+
}
|
|
898
|
+
text = text.replace(/^\[(?:Feishu|Lark|Slack|Telegram|Discord|IM)\]\s*(?:\r?\n)?/, "").trim();
|
|
899
|
+
if (text.startsWith("[im-forward-dispatch]")) return { text: "" };
|
|
900
|
+
text = text.replace(/^(?:<at\b[^>]*>[^<]*<\/at>\s*)+/, "");
|
|
901
|
+
text = text.replace(/<at\b[^>]*>([^<]*)<\/at>/g, (_, name) => {
|
|
902
|
+
const trimmed = name.trim();
|
|
903
|
+
return trimmed ? `@${trimmed}` : "";
|
|
904
|
+
});
|
|
905
|
+
text = text.replace(/\r\n/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
906
|
+
return tag ? { text, tag } : { text };
|
|
907
|
+
}
|
|
908
|
+
function extractTextFromContent(content) {
|
|
909
|
+
if (typeof content === "string") return content;
|
|
910
|
+
if (!Array.isArray(content)) return "";
|
|
911
|
+
return content.map(
|
|
912
|
+
(block) => block && typeof block === "object" && block.type === "text" && typeof block.text === "string" ? String(block.text) : ""
|
|
913
|
+
).join("");
|
|
914
|
+
}
|
|
915
|
+
function contentHasToolCall(content) {
|
|
916
|
+
if (!Array.isArray(content)) return false;
|
|
917
|
+
return content.some((block) => Boolean(block && typeof block === "object" && block.type === "toolCall"));
|
|
918
|
+
}
|
|
919
|
+
function extractCalmEntries(messages) {
|
|
920
|
+
const out = [];
|
|
921
|
+
for (const raw of messages) {
|
|
922
|
+
if (!raw || typeof raw !== "object") continue;
|
|
923
|
+
const msg = raw;
|
|
924
|
+
const at = typeof msg.timestamp === "number" && Number.isFinite(msg.timestamp) ? msg.timestamp : void 0;
|
|
925
|
+
if (msg.role === "user") {
|
|
926
|
+
const cleaned = stripInternalUserHeaders(extractTextFromContent(msg.content));
|
|
927
|
+
if (cleaned.text) {
|
|
928
|
+
out.push({ role: "user", text: cleaned.text, ...at !== void 0 ? { at } : {}, ...cleaned.tag ? { tag: cleaned.tag } : {} });
|
|
929
|
+
}
|
|
930
|
+
continue;
|
|
931
|
+
}
|
|
932
|
+
if (msg.role === "assistant") {
|
|
933
|
+
const stopReason = typeof msg.stopReason === "string" ? msg.stopReason : void 0;
|
|
934
|
+
const failed = stopReason === "error" || stopReason === "aborted";
|
|
935
|
+
if (contentHasToolCall(msg.content) && !failed) continue;
|
|
936
|
+
const text = extractTextFromContent(msg.content).replace(/\u0000/g, "").replace(/\r\n/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
937
|
+
if (text) {
|
|
938
|
+
out.push({ role: "assistant", text, ...at !== void 0 ? { at } : {}, ...failed && stopReason ? { tag: stopReason } : {} });
|
|
939
|
+
} else if (failed && stopReason) {
|
|
940
|
+
const err = typeof msg.errorMessage === "string" && msg.errorMessage.trim() ? `: ${msg.errorMessage.trim().slice(0, 180)}` : "";
|
|
941
|
+
out.push({ role: "assistant", text: `[${stopReason}${err}]`, ...at !== void 0 ? { at } : {}, tag: stopReason });
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
return out;
|
|
946
|
+
}
|
|
947
|
+
function isHighSurrogate(code) {
|
|
948
|
+
return code >= 55296 && code <= 56319;
|
|
949
|
+
}
|
|
950
|
+
function isLowSurrogate(code) {
|
|
951
|
+
return code >= 56320 && code <= 57343;
|
|
952
|
+
}
|
|
953
|
+
function safeHeadSlice(text, maxUnits) {
|
|
954
|
+
if (maxUnits <= 0) return "";
|
|
955
|
+
if (text.length <= maxUnits) return text;
|
|
956
|
+
let end = maxUnits;
|
|
957
|
+
if (end > 0 && isHighSurrogate(text.charCodeAt(end - 1))) end -= 1;
|
|
958
|
+
return text.slice(0, end);
|
|
959
|
+
}
|
|
960
|
+
function safeTailSlice(text, maxUnits) {
|
|
961
|
+
if (maxUnits <= 0) return "";
|
|
962
|
+
if (text.length <= maxUnits) return text;
|
|
963
|
+
let start = text.length - maxUnits;
|
|
964
|
+
if (start < text.length && isLowSurrogate(text.charCodeAt(start))) start += 1;
|
|
965
|
+
return text.slice(start);
|
|
966
|
+
}
|
|
967
|
+
function closeDanglingCodeFence(text) {
|
|
968
|
+
const fences = text.match(/```/g);
|
|
969
|
+
return fences && fences.length % 2 === 1 ? `${text}
|
|
970
|
+
\`\`\`` : text;
|
|
971
|
+
}
|
|
972
|
+
function clipEntryText(role, text, maxChars) {
|
|
973
|
+
if (text.length <= maxChars) return closeDanglingCodeFence(text);
|
|
974
|
+
if (maxChars <= 16) return safeHeadSlice(text, Math.max(1, maxChars));
|
|
975
|
+
if (role === "user") {
|
|
976
|
+
return closeDanglingCodeFence(`${safeHeadSlice(text, maxChars - 1).trimEnd()}\u2026`);
|
|
977
|
+
}
|
|
978
|
+
const sep = "\n\u2026\n";
|
|
979
|
+
const avail = maxChars - sep.length;
|
|
980
|
+
const headLen = Math.floor(avail * 0.45);
|
|
981
|
+
const tailLen = avail - headLen;
|
|
982
|
+
return closeDanglingCodeFence(`${safeHeadSlice(text, headLen).trimEnd()}${sep}${safeTailSlice(text, tailLen).trimStart()}`);
|
|
983
|
+
}
|
|
984
|
+
function paginateCalmEntries(entries, opts = {}) {
|
|
985
|
+
const charBudget = clampPeekCharBudget(opts.charBudget);
|
|
986
|
+
const reqPage = normalizePeekPage(opts.page);
|
|
987
|
+
if (entries.length === 0) {
|
|
988
|
+
return { page: 1, totalPages: 1, totalEntries: 0, charBudget, entries: [] };
|
|
989
|
+
}
|
|
990
|
+
const multiEntryCap = Math.max(200, Math.floor(charBudget * 0.65));
|
|
991
|
+
const pages = [];
|
|
992
|
+
let currentRaw = [];
|
|
993
|
+
let currentChars = 0;
|
|
994
|
+
const flushPage = () => {
|
|
995
|
+
if (currentRaw.length === 0) return;
|
|
996
|
+
const ordered = currentRaw.reverse();
|
|
997
|
+
const cap = ordered.length === 1 ? charBudget : multiEntryCap;
|
|
998
|
+
pages.push(ordered.map((entry) => ({
|
|
999
|
+
...entry,
|
|
1000
|
+
text: clipEntryText(entry.role, entry.text, cap)
|
|
1001
|
+
})));
|
|
1002
|
+
currentRaw = [];
|
|
1003
|
+
currentChars = 0;
|
|
1004
|
+
};
|
|
1005
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
1006
|
+
const entry = entries[i];
|
|
1007
|
+
const effectiveLen = Math.min(entry.text.length, multiEntryCap) + ENTRY_PACK_OVERHEAD;
|
|
1008
|
+
if (currentRaw.length > 0 && (currentRaw.length >= MAX_ENTRIES_PER_PAGE || currentChars + effectiveLen > charBudget)) {
|
|
1009
|
+
flushPage();
|
|
1010
|
+
}
|
|
1011
|
+
currentRaw.push(entry);
|
|
1012
|
+
currentChars += effectiveLen;
|
|
1013
|
+
}
|
|
1014
|
+
flushPage();
|
|
1015
|
+
const totalPages = Math.max(1, pages.length);
|
|
1016
|
+
const page = Math.min(reqPage, totalPages);
|
|
1017
|
+
return {
|
|
1018
|
+
page,
|
|
1019
|
+
totalPages,
|
|
1020
|
+
totalEntries: entries.length,
|
|
1021
|
+
charBudget,
|
|
1022
|
+
entries: pages[page - 1] ?? []
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
function fitPeekSnapshotToFrame(snapshot, frameBytes, maxBytes = 8e3) {
|
|
1026
|
+
const encode = () => JSON.stringify({ ok: true, message: JSON.stringify(snapshot) });
|
|
1027
|
+
if (snapshot.turns && snapshot.turns.entries.length > 0 && (!snapshot.active || snapshot.turns.page > 1)) {
|
|
1028
|
+
snapshot.items = [];
|
|
1029
|
+
delete snapshot.lastVisible;
|
|
1030
|
+
}
|
|
1031
|
+
const newest = snapshot.items.at(-1);
|
|
1032
|
+
if (!snapshot.active && newest?.kind === "assistant" && snapshot.lastVisible?.text === newest.text) {
|
|
1033
|
+
delete snapshot.lastVisible;
|
|
1034
|
+
}
|
|
1035
|
+
if (typeof snapshot.model === "string" && snapshot.model.length > 120) {
|
|
1036
|
+
snapshot.model = safeHeadSlice(snapshot.model, 120);
|
|
1037
|
+
}
|
|
1038
|
+
let text = encode();
|
|
1039
|
+
while (frameBytes(text) > maxBytes) {
|
|
1040
|
+
if (snapshot.turns && snapshot.lastVisible) {
|
|
1041
|
+
if (snapshot.lastVisible.text.length > 256) {
|
|
1042
|
+
snapshot.lastVisible.text = safeTailSlice(snapshot.lastVisible.text, Math.max(256, snapshot.lastVisible.text.length - 512));
|
|
1043
|
+
} else {
|
|
1044
|
+
delete snapshot.lastVisible;
|
|
1045
|
+
}
|
|
1046
|
+
} else if (snapshot.turns && snapshot.items.length > 1) {
|
|
1047
|
+
snapshot.items.shift();
|
|
1048
|
+
} else if (snapshot.turns && snapshot.items.length === 1 && snapshot.items[0].text.length > 256) {
|
|
1049
|
+
snapshot.items[0].text = safeTailSlice(snapshot.items[0].text, Math.max(256, snapshot.items[0].text.length - 512));
|
|
1050
|
+
} else if (snapshot.turns && snapshot.items.length === 1) {
|
|
1051
|
+
snapshot.items.shift();
|
|
1052
|
+
} else if (snapshot.turns && snapshot.turns.entries.length > 1) {
|
|
1053
|
+
snapshot.turns.entries.shift();
|
|
1054
|
+
} else if (snapshot.turns && snapshot.turns.entries.length === 1) {
|
|
1055
|
+
const sole = snapshot.turns.entries[0];
|
|
1056
|
+
if (sole.text.length > 128) {
|
|
1057
|
+
sole.text = clipEntryText(sole.role, sole.text, Math.max(128, sole.text.length - 256));
|
|
1058
|
+
} else {
|
|
1059
|
+
delete snapshot.turns;
|
|
1060
|
+
}
|
|
1061
|
+
} else if (snapshot.lastVisible && snapshot.lastVisible.text.length > 512 && snapshot.items.length > 1) {
|
|
1062
|
+
snapshot.lastVisible.text = safeTailSlice(snapshot.lastVisible.text, Math.max(512, snapshot.lastVisible.text.length - 512));
|
|
1063
|
+
} else if (snapshot.items.length > 1) {
|
|
1064
|
+
snapshot.items.shift();
|
|
1065
|
+
} else {
|
|
1066
|
+
const item = snapshot.items[0];
|
|
1067
|
+
const visible = snapshot.lastVisible;
|
|
1068
|
+
if (visible && visible.text.length > 128 && (snapshot.active || !item || visible.text.length >= item.text.length)) {
|
|
1069
|
+
visible.text = safeTailSlice(visible.text, Math.max(128, visible.text.length - 256));
|
|
1070
|
+
} else if (item?.text.length) {
|
|
1071
|
+
if (item.text.length <= 128) snapshot.items.shift();
|
|
1072
|
+
else item.text = safeTailSlice(item.text, Math.max(128, item.text.length - 256));
|
|
1073
|
+
} else if (visible) {
|
|
1074
|
+
delete snapshot.lastVisible;
|
|
1075
|
+
} else if (snapshot.model) {
|
|
1076
|
+
delete snapshot.model;
|
|
1077
|
+
} else break;
|
|
1078
|
+
}
|
|
1079
|
+
text = encode();
|
|
1080
|
+
}
|
|
1081
|
+
return text;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
860
1084
|
// builtin/extensions/pie-ipc/index.ts
|
|
861
1085
|
var DEFAULT_NOTIFY_FALLBACK_MS = 6e5;
|
|
862
1086
|
var FALLBACK_RENEWAL_CAP = 4;
|
|
@@ -969,6 +1193,8 @@ var Runtime = class {
|
|
|
969
1193
|
if (typeof liveName === "string") this.sessionName = liveName;
|
|
970
1194
|
const displaySessionName = this.ctx.getSessionDisplayName?.() ?? liveName;
|
|
971
1195
|
const model = this.ctx.getCurrentModel?.();
|
|
1196
|
+
const thinkingLevel = this.ctx.getThinkingLevel?.();
|
|
1197
|
+
const thinkingStatus = this.ctx.getThinkingStatus?.();
|
|
972
1198
|
const snapshot = this.projection.snapshot({
|
|
973
1199
|
...this.statusBase,
|
|
974
1200
|
displayName: this.displayName,
|
|
@@ -976,15 +1202,17 @@ var Runtime = class {
|
|
|
976
1202
|
sessionName: this.sessionName,
|
|
977
1203
|
...displaySessionName ? { displaySessionName } : {},
|
|
978
1204
|
...typeof model === "string" && model ? { model } : {},
|
|
1205
|
+
...typeof thinkingLevel === "string" && thinkingLevel ? { thinkingLevel } : {},
|
|
1206
|
+
...thinkingStatus ? { effectiveThinkingLevel: thinkingStatus.effective, supportedThinkingLevels: thinkingStatus.supportedLevels } : {},
|
|
979
1207
|
isManager: this.ctx.capabilities?.unattended === true && process.env.PIE_PROC_CURATED_NAME === "manager",
|
|
980
1208
|
sessionControls: this.ctx.capabilities?.interactiveUI === false && this.ctx.capabilities.editorInjection === true,
|
|
981
|
-
workerPeek: this.ctx.capabilities?.unattended === true
|
|
1209
|
+
workerPeek: this.ctx.capabilities?.unattended === true,
|
|
982
1210
|
imBinding: currentImBinding()
|
|
983
1211
|
});
|
|
984
1212
|
return { ...snapshot, allowPeers: [...this.allowPolicy.snapshot()], undeliveredInjections: this.delivery?.undeliveredInjections ?? snapshot.undeliveredInjections ?? 0 };
|
|
985
1213
|
}
|
|
986
1214
|
writeStatus() {
|
|
987
|
-
if (!this.serverReady) return false;
|
|
1215
|
+
if (this.disposed || !this.serverReady) return false;
|
|
988
1216
|
return writeStatusFile(this.discoveryDir, { ...this.currentStatus(), updatedAt: Date.now() }, (message) => this.ctx.log(message));
|
|
989
1217
|
}
|
|
990
1218
|
async handleEnvelope(envelope, respond, signal) {
|
|
@@ -1020,12 +1248,13 @@ var Runtime = class {
|
|
|
1020
1248
|
return;
|
|
1021
1249
|
}
|
|
1022
1250
|
if (parsed.control === "session.peek") {
|
|
1023
|
-
if (
|
|
1024
|
-
reply("ack", JSON.stringify({ ok: false, message: "host does not advertise
|
|
1251
|
+
if (this.ctx.capabilities?.unattended !== true) {
|
|
1252
|
+
reply("ack", JSON.stringify({ ok: false, message: "host does not advertise Peek" }));
|
|
1025
1253
|
return;
|
|
1026
1254
|
}
|
|
1027
1255
|
const base = replyEnvelope("ack");
|
|
1028
|
-
const
|
|
1256
|
+
const peekOpts = parsed.payload && typeof parsed.payload === "object" && !Array.isArray(parsed.payload) ? parsed.payload : {};
|
|
1257
|
+
const text = this.boundedPeekAckText((candidate) => Buffer.byteLength(JSON.stringify({ ...base, text: candidate, auth: "0".repeat(64) }) + "\n"), peekOpts);
|
|
1029
1258
|
respond({ ...base, text });
|
|
1030
1259
|
return;
|
|
1031
1260
|
}
|
|
@@ -1035,6 +1264,7 @@ var Runtime = class {
|
|
|
1035
1264
|
return;
|
|
1036
1265
|
}
|
|
1037
1266
|
const receipt = await applier(parsed.control, parsed.payload);
|
|
1267
|
+
if (receipt?.ok && (parsed.control === "model.set" || parsed.control === "thinking.set")) this.writeStatus();
|
|
1038
1268
|
try {
|
|
1039
1269
|
this.ctx.appendEntry?.("pie.ipc.control", {
|
|
1040
1270
|
from: envelope.from,
|
|
@@ -1187,58 +1417,50 @@ var Runtime = class {
|
|
|
1187
1417
|
else this.peekLastVisible = visible;
|
|
1188
1418
|
this.trimPeek();
|
|
1189
1419
|
}
|
|
1190
|
-
|
|
1191
|
-
if (!partial || typeof partial !== "object") return void 0;
|
|
1192
|
-
const p = partial;
|
|
1193
|
-
if (!p.details || typeof p.details !== "object" || !("increment" in p.details) || !Array.isArray(p.content)) return void 0;
|
|
1194
|
-
const text = p.content.map((block) => block && typeof block === "object" && block.type === "text" && typeof block.text === "string" ? block.text : "").filter(Boolean).at(-1)?.replace(/\u0000/g, "").trim();
|
|
1195
|
-
return text ? text.slice(0, 500) : void 0;
|
|
1196
|
-
}
|
|
1197
|
-
peekSnapshot() {
|
|
1420
|
+
peekSnapshot(opts = {}) {
|
|
1198
1421
|
const now = Date.now();
|
|
1199
|
-
const items = this.peekItems.map(({ toolCallId: _id, startedAt, done, progress, ...item }) => item.kind === "tool" && startedAt !== void 0 ? { ...item, text: `${done ? "Finished" : "Running"} ${item.text} \xB7 ${Math.max(0, Math.floor(((done ? item.at : now) - startedAt) / 1e3))}s${progress ? ` \xB7 ${progress}` : ""}` } : item);
|
|
1422
|
+
const items = this.peekItems.map(({ toolCallId: _id, startedAt, done, failed, progress, ...item }) => item.kind === "tool" && startedAt !== void 0 ? { ...item, text: `${done ? failed ? "Failed" : "Finished" : "Running"} ${item.text} \xB7 ${Math.max(0, Math.floor(((done ? item.at : now) - startedAt) / 1e3))}s${progress ? ` \xB7 ${progress}` : ""}` } : item);
|
|
1423
|
+
let rawMessages = [];
|
|
1424
|
+
try {
|
|
1425
|
+
const fetched = this.ctx.getMessages?.();
|
|
1426
|
+
if (Array.isArray(fetched)) rawMessages = fetched;
|
|
1427
|
+
} catch {
|
|
1428
|
+
}
|
|
1429
|
+
const calmEntries = extractCalmEntries(rawMessages);
|
|
1430
|
+
const turns = calmEntries.length > 0 ? paginateCalmEntries(calmEntries, opts) : void 0;
|
|
1431
|
+
const model = (() => {
|
|
1432
|
+
try {
|
|
1433
|
+
return this.ctx.getCurrentModel?.();
|
|
1434
|
+
} catch {
|
|
1435
|
+
return void 0;
|
|
1436
|
+
}
|
|
1437
|
+
})();
|
|
1438
|
+
const isManager = this.ctx.capabilities?.unattended === true && process.env.PIE_PROC_CURATED_NAME === "manager";
|
|
1200
1439
|
return {
|
|
1201
1440
|
active: this.active,
|
|
1202
1441
|
turn: this.peekTurn,
|
|
1203
1442
|
...this.peekStartedAt ? { startedAt: this.peekStartedAt } : {},
|
|
1204
1443
|
generatedAt: now,
|
|
1444
|
+
...typeof model === "string" && model ? { model } : {},
|
|
1445
|
+
...isManager ? { isManager: true } : {},
|
|
1205
1446
|
items,
|
|
1206
|
-
...this.peekLastVisible ? { lastVisible: { ...this.peekLastVisible } } : {}
|
|
1447
|
+
...this.peekLastVisible ? { lastVisible: { ...this.peekLastVisible } } : {},
|
|
1448
|
+
...turns ? { turns } : {}
|
|
1207
1449
|
};
|
|
1208
1450
|
}
|
|
1209
|
-
boundedPeekAckText(frameBytes) {
|
|
1210
|
-
|
|
1211
|
-
const encode = () => JSON.stringify({ ok: true, message: JSON.stringify(snapshot) });
|
|
1212
|
-
const newest = snapshot.items.at(-1);
|
|
1213
|
-
if (!snapshot.active && newest?.kind === "assistant" && snapshot.lastVisible?.text === newest.text) delete snapshot.lastVisible;
|
|
1214
|
-
let text = encode();
|
|
1215
|
-
while (frameBytes(text) > 8e3) {
|
|
1216
|
-
if (snapshot.items.length > 1) {
|
|
1217
|
-
snapshot.items.shift();
|
|
1218
|
-
} else {
|
|
1219
|
-
const item = snapshot.items[0];
|
|
1220
|
-
const visible = snapshot.lastVisible;
|
|
1221
|
-
if (visible && visible.text.length > 128 && (snapshot.active || !item || visible.text.length >= item.text.length)) {
|
|
1222
|
-
visible.text = visible.text.slice(-Math.max(128, visible.text.length - 256));
|
|
1223
|
-
} else if (item?.text.length) {
|
|
1224
|
-
if (item.text.length <= 128) snapshot.items.shift();
|
|
1225
|
-
else item.text = item.text.slice(-Math.max(128, item.text.length - 256));
|
|
1226
|
-
} else if (visible) {
|
|
1227
|
-
delete snapshot.lastVisible;
|
|
1228
|
-
} else break;
|
|
1229
|
-
}
|
|
1230
|
-
text = encode();
|
|
1231
|
-
}
|
|
1232
|
-
return text;
|
|
1451
|
+
boundedPeekAckText(frameBytes, opts = {}) {
|
|
1452
|
+
return fitPeekSnapshotToFrame(this.peekSnapshot(opts), frameBytes, 8e3);
|
|
1233
1453
|
}
|
|
1234
1454
|
onEvent(event) {
|
|
1235
1455
|
switch (event.type) {
|
|
1236
1456
|
case "turn:start": {
|
|
1237
|
-
this.
|
|
1238
|
-
|
|
1239
|
-
|
|
1457
|
+
if (!this.active) {
|
|
1458
|
+
this.peekTurn++;
|
|
1459
|
+
this.peekStartedAt = Date.now();
|
|
1460
|
+
this.peekItems = [];
|
|
1461
|
+
this.peekPendingVisible = void 0;
|
|
1462
|
+
}
|
|
1240
1463
|
this.peekAssistantIndex = void 0;
|
|
1241
|
-
this.peekPendingVisible = void 0;
|
|
1242
1464
|
this.executionFailure = void 0;
|
|
1243
1465
|
this.active = true;
|
|
1244
1466
|
if (this.projection.updateFromEvent(event)) this.writeStatus();
|
|
@@ -1257,7 +1479,7 @@ var Runtime = class {
|
|
|
1257
1479
|
}
|
|
1258
1480
|
case "tool:execution:update": {
|
|
1259
1481
|
const item = event.toolCallId ? this.peekItems.find((i) => i.toolCallId === event.toolCallId) : void 0;
|
|
1260
|
-
const progress =
|
|
1482
|
+
const progress = extractSafeToolProgress(event.partialResult);
|
|
1261
1483
|
if (item && !item.done && progress) {
|
|
1262
1484
|
item.progress = progress;
|
|
1263
1485
|
item.at = Date.now();
|
|
@@ -1269,6 +1491,7 @@ var Runtime = class {
|
|
|
1269
1491
|
const item = event.toolCallId ? this.peekItems.find((i) => i.toolCallId === event.toolCallId) : void 0;
|
|
1270
1492
|
if (item && !item.done) {
|
|
1271
1493
|
item.done = true;
|
|
1494
|
+
if (event.isError === true) item.failed = true;
|
|
1272
1495
|
item.at = Date.now();
|
|
1273
1496
|
}
|
|
1274
1497
|
if (this.projection.updateFromEvent(event)) this.writeStatus();
|
|
@@ -1700,11 +1923,11 @@ ${outcome.text}`
|
|
|
1700
1923
|
return ` ${label} [${file.state}]${sid}`;
|
|
1701
1924
|
}).join("\n");
|
|
1702
1925
|
}
|
|
1703
|
-
/** Panel controls
|
|
1704
|
-
* identity. Besides the authenticated target gate, enforce both advertised
|
|
1705
|
-
* directions before exposing transcript-like data. */
|
|
1926
|
+
/** Panel controls originate from this process's real advertised IPC identity (supports self + peers). */
|
|
1706
1927
|
async sendBoundControl(peerRef, control, payload, expected, waitMs = 6e3) {
|
|
1707
|
-
const
|
|
1928
|
+
const ref = peerRef.trim().toLowerCase();
|
|
1929
|
+
const selfStatus = () => readStatusFile(this.discoveryDir, this.instanceId) ?? (this.transport?.listenPort ? { ...this.currentStatus(), port: this.transport.listenPort } : null);
|
|
1930
|
+
const target = expected ? readStatusFile(this.discoveryDir, expected.instanceId) : ref === "self" || ref === this.instanceId.toLowerCase() ? selfStatus() : this.resolvePeer(peerRef);
|
|
1708
1931
|
if (!target || !target.port) return { ok: false, detail: `Session not found: ${peerRef}` };
|
|
1709
1932
|
if (expected && (target.instanceId !== expected.instanceId || target.sessionId !== expected.sessionId))
|
|
1710
1933
|
return { ok: false, detail: "Worker instance or session no longer matches the issued card. Reopen it from /panel." };
|
|
@@ -1912,8 +2135,9 @@ ${message.text}`).join("\n---\n");
|
|
|
1912
2135
|
} });
|
|
1913
2136
|
return result.content[0]?.text ?? "(no result)";
|
|
1914
2137
|
}
|
|
1915
|
-
dispose() {
|
|
2138
|
+
async dispose() {
|
|
1916
2139
|
this.disposed = true;
|
|
2140
|
+
this.serverReady = false;
|
|
1917
2141
|
this.stopHeartbeat?.();
|
|
1918
2142
|
this.stopImBinding();
|
|
1919
2143
|
this.delivery?.resetSessionState();
|
|
@@ -1926,8 +2150,8 @@ ${message.text}`).join("\n---\n");
|
|
|
1926
2150
|
this.ctx.ui.setStatus?.("pie-ipc-peers", void 0);
|
|
1927
2151
|
} catch {
|
|
1928
2152
|
}
|
|
1929
|
-
this.transport?.close();
|
|
1930
2153
|
removeStatusFile(this.discoveryDir, this.instanceId);
|
|
2154
|
+
await this.transport?.closeAndFlush();
|
|
1931
2155
|
}
|
|
1932
2156
|
};
|
|
1933
2157
|
function loadConfig(ctx, configDir) {
|
|
@@ -2096,7 +2320,7 @@ SIDE EFFECT: this is NOT a read-only query. The text is injected into the peer's
|
|
|
2096
2320
|
parameters: Type.Object({
|
|
2097
2321
|
to: Type.String({ description: "Peer display name or instance id (see ipc_list_peers)" }),
|
|
2098
2322
|
control: Type.Union([Type.Literal("model.set"), Type.Literal("thinking.set"), Type.Literal("session.context"), Type.Literal("session.compact")], { description: "Control to apply (enumerated whitelist)" }),
|
|
2099
|
-
payload: Type.Optional(Type.Record(Type.String(), Type.Unknown(), { description: "Control payload. model.set requires {model: 'provider/modelId'}; thinking.set requires {level: 'off|minimal|low|medium|high|xhigh'}; session.context/session.compact take an empty payload" })),
|
|
2323
|
+
payload: Type.Optional(Type.Record(Type.String(), Type.Unknown(), { description: "Control payload. model.set requires {model: 'provider/modelId'}; thinking.set requires {level: 'off|minimal|low|medium|high|xhigh|max'}; session.context/session.compact take an empty payload" })),
|
|
2100
2324
|
waitMs: Type.Optional(Type.Number({ description: "Receipt wait budget in ms (default 120000, max 600000)", minimum: 100, maximum: 6e5 }))
|
|
2101
2325
|
}),
|
|
2102
2326
|
risk: { ...risk, riskClass: "session_mutation", concurrencySafe: false },
|
|
@@ -2114,7 +2338,7 @@ SIDE EFFECT: this is NOT a read-only query. The text is injected into the peer's
|
|
|
2114
2338
|
}
|
|
2115
2339
|
if (args.control === "thinking.set") {
|
|
2116
2340
|
const payload = args.payload ?? {};
|
|
2117
|
-
const valid = ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
2341
|
+
const valid = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
2118
2342
|
if (typeof payload.level !== "string" || !valid.includes(payload.level))
|
|
2119
2343
|
return { content: [{ type: "text", text: `thinking.set requires payload.level as one of ${valid.join("|")}.` }], isError: true };
|
|
2120
2344
|
}
|
|
@@ -2128,7 +2352,7 @@ SIDE EFFECT: this is NOT a read-only query. The text is injected into the peer's
|
|
|
2128
2352
|
description: "Send an enumerated CONTROL frame to THIS session's own host (the process running you). The host applies it directly \u2014 it never enters the turn pipeline or session history. Controls: 'model.set' with payload {model: 'provider/modelId'} switches YOUR model (same validation as the user's /model); 'thinking.set' with payload {level: 'off|minimal|low|medium|high|xhigh'} switches YOUR thinking level (same path as the user's /think; a sensible self-tuning knob \u2014 low for cheap lookups, high for hard reasoning). Both apply from the host's NEXT agent execution \u2014 the current execution (including tool-continuation rounds) finishes on the settings it started with. 'session.context' (payload {}) reads YOUR host's context estimate (headless hosts; receipt message is JSON); 'session.compact' (payload {}) requests a MANUAL compaction of THIS session \u2014 **refused while a turn is streaming (you are always mid-turn when you call this, so expect a refusal; the IM panel is the intended entry)**. Receipt (success or structured refusal) returns as this tool's result. If the session.compact receipt is uncertain, do not replay it: check session.context before submitting again.",
|
|
2129
2353
|
parameters: Type.Object({
|
|
2130
2354
|
control: Type.Union([Type.Literal("model.set"), Type.Literal("thinking.set"), Type.Literal("session.context"), Type.Literal("session.compact")], { description: "Control to apply (enumerated host whitelist)" }),
|
|
2131
|
-
payload: Type.Optional(Type.Record(Type.String(), Type.Unknown(), { description: "Control payload. model.set requires {model: 'provider/modelId'}; thinking.set requires {level: 'off|minimal|low|medium|high|xhigh'}" })),
|
|
2355
|
+
payload: Type.Optional(Type.Record(Type.String(), Type.Unknown(), { description: "Control payload. model.set requires {model: 'provider/modelId'}; thinking.set requires {level: 'off|minimal|low|medium|high|xhigh|max'}" })),
|
|
2132
2356
|
waitMs: Type.Optional(Type.Number({ description: "Receipt wait budget in ms (default 120000, max 600000)", minimum: 100, maximum: 6e5 }))
|
|
2133
2357
|
}),
|
|
2134
2358
|
risk: { ...risk, riskClass: "session_mutation", concurrencySafe: false },
|
|
@@ -2146,7 +2370,7 @@ SIDE EFFECT: this is NOT a read-only query. The text is injected into the peer's
|
|
|
2146
2370
|
}
|
|
2147
2371
|
if (args.control === "thinking.set") {
|
|
2148
2372
|
const payload = args.payload ?? {};
|
|
2149
|
-
const valid = ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
2373
|
+
const valid = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
2150
2374
|
if (typeof payload.level !== "string" || !valid.includes(payload.level))
|
|
2151
2375
|
return { content: [{ type: "text", text: `thinking.set requires payload.level as one of ${valid.join("|")}.` }], isError: true };
|
|
2152
2376
|
}
|
|
@@ -2278,9 +2502,9 @@ Usage: /tools/ipc name <new-name>`;
|
|
|
2278
2502
|
ctx.ui.notify(output, "info");
|
|
2279
2503
|
}
|
|
2280
2504
|
});
|
|
2281
|
-
ctx.registerCleanup?.(() => {
|
|
2505
|
+
ctx.registerCleanup?.(async () => {
|
|
2282
2506
|
unregisterRuntime();
|
|
2283
|
-
runtime.dispose();
|
|
2507
|
+
await runtime.dispose();
|
|
2284
2508
|
});
|
|
2285
2509
|
}
|
|
2286
2510
|
function getConfigDirSafe(_ctx) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# pie-proc — controlled worker-process lifecycle
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The manager's S5 guardrail layer: create and retire pie worker
|
|
4
4
|
processes WITHOUT raw shell access. Bounded shapes, allowlisted working
|
|
5
5
|
directories, isolated agent dirs, caps, TTL sweeping, and an audit ledger.
|
|
6
6
|
|
|
7
7
|
## Host gating
|
|
8
8
|
|
|
9
9
|
Activates on `longLived` (interactive TUI and resident json-events hosts —
|
|
10
|
-
the
|
|
10
|
+
the manager). One-shot print hosts never own workers.
|
|
11
11
|
|
|
12
12
|
## Tool: `pie_proc`
|
|
13
13
|
|
|
@@ -63,9 +63,9 @@ make it permanently invisible. A missing or unreadable file means an empty
|
|
|
63
63
|
`allowCwd` — every spawn is refused (fail-closed) with a message that says
|
|
64
64
|
whether the file is missing or simply lacks the cwd, and how to write it.
|
|
65
65
|
|
|
66
|
-
`pie
|
|
67
|
-
`allowCwd` set to the directory `pie
|
|
68
|
-
a new machine can chat with the
|
|
66
|
+
`pie manager` seeds this file on first run when it is absent, with
|
|
67
|
+
`allowCwd` set to the directory `pie manager` was launched from — otherwise
|
|
68
|
+
a new machine can chat with the manager but never dispatch a worker. It
|
|
69
69
|
never seeds `$HOME` or `/` (that is a security decision for the operator) and
|
|
70
70
|
never overwrites an existing file.
|
|
71
71
|
|
|
@@ -92,14 +92,14 @@ log (verbose mode / host transcript).
|
|
|
92
92
|
|
|
93
93
|
- No arbitrary argv: the shapes are exactly the two documented above; the
|
|
94
94
|
model cannot inject flags (the oneshot task never enters argv). This is
|
|
95
|
-
the deliberate replacement for teaching the
|
|
95
|
+
the deliberate replacement for teaching the manager to spawn processes
|
|
96
96
|
through the shell tool.
|
|
97
97
|
- Workers do NOT inherit the parent's agent dir: each gets
|
|
98
98
|
`~/.pie/pie-proc/agents/<name>/` (own models.json etc., inherited from the
|
|
99
99
|
parent on first creation). The cwd allowlist, not the PIE dir, scopes
|
|
100
100
|
file access. Workers DO inherit the parent's IPC discovery root
|
|
101
101
|
(PIE_IPC_CONFIG_DIR is set to the parent's effective config dir) so the
|
|
102
|
-
|
|
102
|
+
manager can address them by peer name via ipc_send_notify; their peer
|
|
103
103
|
name travels in PIE_IPC_DISPLAY_NAME — never by writing a shared ipc.json.
|
|
104
104
|
- The im field is written before spawn (only when absent) as a plain
|
|
105
105
|
user-layer im-forward.json inside the worker's PIE dir — the same
|