@cydm/pie 4.14.1 → 4.15.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/README.md +5 -5
- package/dist/builtin/extensions/ask-user/index.js +4 -4
- package/dist/builtin/extensions/im-forward/index.js +964 -269
- package/dist/builtin/extensions/memory/index.js +6 -6
- package/dist/builtin/extensions/memory/package.json +1 -2
- package/dist/builtin/extensions/pie-proc/index.js +6 -6
- 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-IQDVL34H.js → chunk-6AYPNTCO.js} +8 -8
- package/dist/chunks/{chunk-SYZR74QO.js → chunk-J6EZ335F.js} +8 -7
- package/dist/chunks/{chunk-X3ZVZB2R.js → chunk-JE53PC46.js} +633 -148
- package/dist/chunks/{chunk-2WLKAMOH.js → chunk-LIA52LJU.js} +3 -3
- package/dist/chunks/{chunk-SAXKBFX3.js → chunk-MTH6QSYD.js} +1 -1
- package/dist/chunks/{chunk-TTSQWGAT.js → chunk-NAMH667S.js} +10 -15
- package/dist/chunks/{chunk-DJ4LO7PQ.js → chunk-VWDCKHCC.js} +1 -1
- package/dist/chunks/{chunk-IM7DLPPY.js → chunk-YKV45EMY.js} +239 -141
- package/dist/chunks/{chunk-OQCKDEEE.js → chunk-ZBIR5YS7.js} +1 -1
- package/dist/chunks/{chunk-TNRZEQD5.js → chunk-ZH6EAKVM.js} +2 -2
- package/dist/chunks/{host-image-fallback-AEKY2LSZ.js → host-image-fallback-GX2KXZXQ.js} +1 -1
- package/dist/chunks/{memory-git-G56IXFWU.js → memory-git-BJMYZHIE.js} +5 -5
- package/dist/chunks/{model-registry-4LM2I6FR.js → model-registry-T6EMM66I.js} +2 -2
- package/dist/chunks/{read-file-understanding-GTNZHAK5.js → read-file-understanding-ZRE5KDG3.js} +5 -5
- package/dist/chunks/{src-3YJ4UVEC.js → src-DLAIQCKP.js} +3 -3
- package/dist/chunks/{src-APNP4M4N.js → src-FWL3LCBK.js} +2 -2
- package/dist/chunks/{src-T6AUO53N.js → src-OP6LFLR6.js} +8 -4
- package/dist/chunks/{src-TNUD7EDH.js → src-XJKZIY3S.js} +11 -1
- package/dist/chunks/{test-stream-EF2DHEHV.js → test-stream-P3CUEGEE.js} +1 -1
- package/dist/cli.js +408 -52
- package/models.schema.json +4 -0
- package/package.json +2 -2
|
@@ -18,22 +18,23 @@ import {
|
|
|
18
18
|
parseEntryIdSeq,
|
|
19
19
|
readAncestryPage,
|
|
20
20
|
requestInteraction
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-J6EZ335F.js";
|
|
22
22
|
import {
|
|
23
23
|
Agent,
|
|
24
24
|
getToolCallerIdentity
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-MTH6QSYD.js";
|
|
26
26
|
import {
|
|
27
27
|
ALL_THINKING_LEVELS,
|
|
28
28
|
AssistantMessageEventStream,
|
|
29
29
|
completeSimple,
|
|
30
30
|
detectPlatform,
|
|
31
|
+
extractResponsesOutputText,
|
|
31
32
|
getFileSystem,
|
|
32
33
|
getSupportedThinkingLevels,
|
|
33
34
|
hashText,
|
|
34
35
|
resolveThinkingSelection,
|
|
35
36
|
streamSimple
|
|
36
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-YKV45EMY.js";
|
|
37
38
|
import {
|
|
38
39
|
Type
|
|
39
40
|
} from "./chunk-XXGYUYXI.js";
|
|
@@ -1925,6 +1926,7 @@ function isRetryableSubagentFailure(message) {
|
|
|
1925
1926
|
}
|
|
1926
1927
|
function isRetryableSubagentFailureFrom(facts) {
|
|
1927
1928
|
if (facts.stopReason === "aborted" || facts.retryable === false) return false;
|
|
1929
|
+
if (facts.remoteFailure?.quotaExhausted === true) return false;
|
|
1928
1930
|
if (facts.replayClass === "stream_lost" || facts.replayClass === "stream_lost_partial") return true;
|
|
1929
1931
|
const message = facts.errorMessage ?? "";
|
|
1930
1932
|
if (isDefaultQuotaExhaustedError(message)) return false;
|
|
@@ -1998,6 +2000,7 @@ function failureDetails(facts, classification, recovery) {
|
|
|
1998
2000
|
...facts.remoteFailure !== void 0 ? {
|
|
1999
2001
|
remoteFailure: {
|
|
2000
2002
|
category: facts.remoteFailure.category,
|
|
2003
|
+
...facts.remoteFailure.quotaExhausted === true ? { quotaExhausted: true } : {},
|
|
2001
2004
|
...typeof facts.remoteFailure.retryAfterMs === "number" && Number.isFinite(facts.remoteFailure.retryAfterMs) && facts.remoteFailure.retryAfterMs >= 0 ? { retryAfterMs: facts.remoteFailure.retryAfterMs } : {}
|
|
2002
2005
|
}
|
|
2003
2006
|
} : {},
|
|
@@ -2641,24 +2644,529 @@ function hasFilesystemWriteCommand(command, shell, depth = 0) {
|
|
|
2641
2644
|
return false;
|
|
2642
2645
|
}
|
|
2643
2646
|
|
|
2647
|
+
// ../../packages/shared-headless-capabilities/src/bash-policy-segments.ts
|
|
2648
|
+
var CMD_WRITE_HEADS = /* @__PURE__ */ new Set(["copy", "xcopy", "robocopy", "move", "mkdir", "md", "ren", "rename"]);
|
|
2649
|
+
var CMD_IF_COMPARE_OPS = /* @__PURE__ */ new Set(["equ", "neq", "lss", "leq", "gtr", "geq"]);
|
|
2650
|
+
var NON_SQL_TEXT_HEADS = /* @__PURE__ */ new Set(["rg", "grep", "git", "echo", "printf", "cat", "head", "tail", "wc", "sort", "uniq", "cut", "tr"]);
|
|
2651
|
+
var GIT_GLOBAL_VALUE_FLAGS = /* @__PURE__ */ new Set(["-C", "-c", "--git-dir", "--work-tree", "--namespace", "--super-prefix", "--config-env"]);
|
|
2652
|
+
var GIT_MSG_VALUE_FLAGS = /* @__PURE__ */ new Set(["-m", "--message", "-F", "--file", "--author"]);
|
|
2653
|
+
var GIT_DESTRUCTIVE_SUBCOMMANDS = /* @__PURE__ */ new Set(["reset", "push", "clean", "checkout", "restore", "stash", "branch", "commit", "merge"]);
|
|
2654
|
+
var DESTRUCTIVE_CONTROL_PREFIXES = /* @__PURE__ */ new Set(["!", "if", "then", "elif", "else", "do", "while", "until", "coproc", "{"]);
|
|
2655
|
+
var DESTRUCTIVE_WRAPPER_NAMES = /* @__PURE__ */ new Set(["env", "command", "exec", "nohup", "setsid", "time", "nice", "timeout", "xargs", "builtin"]);
|
|
2656
|
+
var DESTRUCTIVE_WRAPPER_VALUE_FLAGS = {
|
|
2657
|
+
env: /* @__PURE__ */ new Set(["-u", "--unset", "-C", "--chdir"]),
|
|
2658
|
+
exec: /* @__PURE__ */ new Set(["-a"]),
|
|
2659
|
+
time: /* @__PURE__ */ new Set(["-o", "-f", "--output", "--format"]),
|
|
2660
|
+
nice: /* @__PURE__ */ new Set(["-n", "--adjustment"]),
|
|
2661
|
+
timeout: /* @__PURE__ */ new Set(["-k", "--kill-after", "-s", "--signal"]),
|
|
2662
|
+
xargs: /* @__PURE__ */ new Set(["-a", "-d", "-E", "-I", "-L", "-n", "-P", "-s", "--arg-file", "--delimiter", "--eof", "--replace", "--max-lines", "--max-args", "--max-procs", "--max-chars"])
|
|
2663
|
+
};
|
|
2664
|
+
var STANDALONE_REDIR_RE2 = /^(?:\d+)?(?:>>?|<<?|<>|>&|<&|&>>?)$/;
|
|
2665
|
+
var INLINE_REDIR_RE2 = /^(?:\d+)?(?:>>?|<<?|<>|>&|<&|&>>?).+$/;
|
|
2666
|
+
var GIT_EXEC_CONFIG_KEY_RE = /^(?:core\.(?:pager|editor|sshcommand|fsmonitor|hookspath|askpass)|credential\.|diff\.external|filter\.|mergetool\.|difftool\.|sequence\.editor|protocol\.(?:ext\.)?allow)/i;
|
|
2667
|
+
var GIT_RISKY_ENV_RE = /^(?:GIT_ALLOW_PROTOCOL|GIT_SSH_COMMAND|GIT_SSH|GIT_EDITOR|GIT_SEQUENCE_EDITOR|GIT_PAGER|GIT_ASKPASS|GIT_EXTERNAL_DIFF|GIT_CONFIG_PARAMETERS|GIT_CONFIG_COUNT)=/i;
|
|
2668
|
+
var GIT_EXEC_CONFIG_WARNING = "may execute arbitrary command via git config";
|
|
2669
|
+
function splitShellSegments(command, shell = "bash") {
|
|
2670
|
+
const segments = [];
|
|
2671
|
+
let current = "";
|
|
2672
|
+
let quote;
|
|
2673
|
+
for (let index = 0; index < command.length; index += 1) {
|
|
2674
|
+
const char = command[index];
|
|
2675
|
+
if (quote) {
|
|
2676
|
+
if (shell !== "cmd" && quote === '"' && char === (shell === "powershell" ? "`" : "\\") && index + 1 < command.length) {
|
|
2677
|
+
current += char;
|
|
2678
|
+
current += command[index + 1];
|
|
2679
|
+
index += 1;
|
|
2680
|
+
continue;
|
|
2681
|
+
}
|
|
2682
|
+
current += char;
|
|
2683
|
+
if (char === quote) quote = void 0;
|
|
2684
|
+
continue;
|
|
2685
|
+
}
|
|
2686
|
+
if (char === '"' || shell !== "cmd" && char === "'") {
|
|
2687
|
+
quote = char;
|
|
2688
|
+
current += char;
|
|
2689
|
+
continue;
|
|
2690
|
+
}
|
|
2691
|
+
if (shell === "cmd" && char === "^" && index + 1 < command.length) {
|
|
2692
|
+
current += char;
|
|
2693
|
+
current += command[index + 1];
|
|
2694
|
+
index += 1;
|
|
2695
|
+
continue;
|
|
2696
|
+
}
|
|
2697
|
+
if (shell !== "cmd" && char === (shell === "powershell" ? "`" : "\\") && index + 1 < command.length) {
|
|
2698
|
+
current += char;
|
|
2699
|
+
current += command[index + 1];
|
|
2700
|
+
index += 1;
|
|
2701
|
+
continue;
|
|
2702
|
+
}
|
|
2703
|
+
if (char === "&") {
|
|
2704
|
+
const prev = current[current.length - 1];
|
|
2705
|
+
if (prev === ">" || prev === "<" || command[index + 1] === ">") {
|
|
2706
|
+
current += char;
|
|
2707
|
+
continue;
|
|
2708
|
+
}
|
|
2709
|
+
if (command[index + 1] === "&") index += 1;
|
|
2710
|
+
segments.push(current);
|
|
2711
|
+
current = "";
|
|
2712
|
+
continue;
|
|
2713
|
+
}
|
|
2714
|
+
if (char === "|" || char === "\n" || char === "(" || char === ")" || shell !== "cmd" && char === ";" || shell === "powershell" && (char === "{" || char === "}")) {
|
|
2715
|
+
if (char === "|" && command[index + 1] === "|") index += 1;
|
|
2716
|
+
segments.push(current);
|
|
2717
|
+
current = "";
|
|
2718
|
+
continue;
|
|
2719
|
+
}
|
|
2720
|
+
current += char;
|
|
2721
|
+
}
|
|
2722
|
+
segments.push(current);
|
|
2723
|
+
return segments.map((part) => part.trim()).filter(Boolean);
|
|
2724
|
+
}
|
|
2725
|
+
function splitShellWords(segment, shell = "bash") {
|
|
2726
|
+
const words = [];
|
|
2727
|
+
let current = "";
|
|
2728
|
+
let hasWord = false;
|
|
2729
|
+
let quote;
|
|
2730
|
+
for (let index = 0; index < segment.length; index += 1) {
|
|
2731
|
+
const char = segment[index];
|
|
2732
|
+
if (quote) {
|
|
2733
|
+
if (char === quote) {
|
|
2734
|
+
quote = void 0;
|
|
2735
|
+
} else if (shell !== "cmd" && quote === '"' && char === (shell === "powershell" ? "`" : "\\") && index + 1 < segment.length) {
|
|
2736
|
+
current += segment[index + 1];
|
|
2737
|
+
index += 1;
|
|
2738
|
+
} else {
|
|
2739
|
+
current += char;
|
|
2740
|
+
}
|
|
2741
|
+
continue;
|
|
2742
|
+
}
|
|
2743
|
+
if (char === '"' || shell !== "cmd" && char === "'") {
|
|
2744
|
+
quote = char;
|
|
2745
|
+
hasWord = true;
|
|
2746
|
+
continue;
|
|
2747
|
+
}
|
|
2748
|
+
if (shell === "cmd" && char === "^") {
|
|
2749
|
+
if (index + 1 >= segment.length) return void 0;
|
|
2750
|
+
current += segment[index + 1];
|
|
2751
|
+
hasWord = true;
|
|
2752
|
+
index += 1;
|
|
2753
|
+
continue;
|
|
2754
|
+
}
|
|
2755
|
+
if (shell !== "cmd" && char === (shell === "powershell" ? "`" : "\\")) {
|
|
2756
|
+
if (index + 1 >= segment.length) return void 0;
|
|
2757
|
+
current += segment[index + 1];
|
|
2758
|
+
hasWord = true;
|
|
2759
|
+
index += 1;
|
|
2760
|
+
continue;
|
|
2761
|
+
}
|
|
2762
|
+
if (/\s/.test(char)) {
|
|
2763
|
+
if (hasWord) {
|
|
2764
|
+
words.push(current);
|
|
2765
|
+
current = "";
|
|
2766
|
+
hasWord = false;
|
|
2767
|
+
}
|
|
2768
|
+
continue;
|
|
2769
|
+
}
|
|
2770
|
+
current += char;
|
|
2771
|
+
hasWord = true;
|
|
2772
|
+
}
|
|
2773
|
+
if (quote) return void 0;
|
|
2774
|
+
if (hasWord) words.push(current);
|
|
2775
|
+
return words;
|
|
2776
|
+
}
|
|
2777
|
+
function stripLeadingPowerShellPrefixes(words) {
|
|
2778
|
+
let i = 0;
|
|
2779
|
+
while (i < words.length) {
|
|
2780
|
+
const w = words[i];
|
|
2781
|
+
if (w === "." || w === "&" || w === "2>&1") {
|
|
2782
|
+
i += 1;
|
|
2783
|
+
continue;
|
|
2784
|
+
}
|
|
2785
|
+
break;
|
|
2786
|
+
}
|
|
2787
|
+
return words.slice(i);
|
|
2788
|
+
}
|
|
2789
|
+
function isSimplePowerShellCommand(command, segments) {
|
|
2790
|
+
if (command.includes("$(") || command.includes("`") || command.includes("<#")) return false;
|
|
2791
|
+
let quote;
|
|
2792
|
+
for (let i = 0; i < command.length; i += 1) {
|
|
2793
|
+
const ch = command[i];
|
|
2794
|
+
if (quote) {
|
|
2795
|
+
if (ch === quote) quote = void 0;
|
|
2796
|
+
continue;
|
|
2797
|
+
}
|
|
2798
|
+
if (ch === "'" || ch === '"') {
|
|
2799
|
+
quote = ch;
|
|
2800
|
+
continue;
|
|
2801
|
+
}
|
|
2802
|
+
if (ch === "#" || ch === "@" || ch === "[" || ch === "]" || ch === "<") return false;
|
|
2803
|
+
if (ch === ">") {
|
|
2804
|
+
const isStderrMerge = i > 0 && command[i - 1] === "2" && (i < 2 || /[\s;|&({]/.test(command[i - 2])) && command.slice(i, i + 3) === ">&1" && (i + 3 >= command.length || /[\s;|&)}]/.test(command[i + 3]));
|
|
2805
|
+
if (!isStderrMerge) return false;
|
|
2806
|
+
continue;
|
|
2807
|
+
}
|
|
2808
|
+
if (ch === "$") {
|
|
2809
|
+
if (command[i + 1] === "?" && (i + 2 >= command.length || !/[A-Za-z0-9_]/.test(command[i + 2]))) {
|
|
2810
|
+
i += 1;
|
|
2811
|
+
continue;
|
|
2812
|
+
}
|
|
2813
|
+
if (/^\$LASTEXITCODE(?![A-Za-z0-9_])/i.test(command.slice(i))) {
|
|
2814
|
+
i += "$LASTEXITCODE".length - 1;
|
|
2815
|
+
continue;
|
|
2816
|
+
}
|
|
2817
|
+
return false;
|
|
2818
|
+
}
|
|
2819
|
+
if (ch === "=") {
|
|
2820
|
+
if (i === 0 || !/[A-Za-z0-9_.-]/.test(command[i - 1])) return false;
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
if (quote) return false;
|
|
2824
|
+
return segments.every((segment) => {
|
|
2825
|
+
const rawWords = splitShellWords(segment, "powershell");
|
|
2826
|
+
if (!rawWords?.length) return false;
|
|
2827
|
+
const words = stripLeadingPowerShellPrefixes(rawWords);
|
|
2828
|
+
if (!words.length) return false;
|
|
2829
|
+
if (words.length === 1 && /^(?:if|else)$/i.test(words[0])) return true;
|
|
2830
|
+
if (words.length === 1 && words[0] === "$?") return true;
|
|
2831
|
+
if (words.length === 3 && /^\$LASTEXITCODE$/i.test(words[0]) && /^-(?:eq|ne|gt|ge|lt|le)$/i.test(words[1]) && /^-?\d+$/.test(words[2])) {
|
|
2832
|
+
return true;
|
|
2833
|
+
}
|
|
2834
|
+
if (/^exit$/i.test(words[0]) && (words.length === 1 || words.length === 2 && /^(?:-?\d+|\$LASTEXITCODE)$/i.test(words[1]))) {
|
|
2835
|
+
return true;
|
|
2836
|
+
}
|
|
2837
|
+
const head = words[0];
|
|
2838
|
+
return !!head && /^[A-Za-z0-9_.\\/][A-Za-z0-9_.\\/:-]*$/.test(head) && !/^(?:return|throw|exit|if|elseif|else|switch|foreach|for|while|do|until|try|catch|finally|function|filter|class|begin|process|end|trap|data|using|workflow|configuration|break|continue|inlinescript|parallel|sequence)$/i.test(head);
|
|
2839
|
+
});
|
|
2840
|
+
}
|
|
2841
|
+
function decodeCmdCaretsInWord(word) {
|
|
2842
|
+
let out = "";
|
|
2843
|
+
for (let i = 0; i < word.length; i += 1) {
|
|
2844
|
+
if (word[i] === "^" && i + 1 < word.length) {
|
|
2845
|
+
out += word[i + 1];
|
|
2846
|
+
i += 1;
|
|
2847
|
+
continue;
|
|
2848
|
+
}
|
|
2849
|
+
out += word[i];
|
|
2850
|
+
}
|
|
2851
|
+
return out;
|
|
2852
|
+
}
|
|
2853
|
+
function unwrapCmdControlWords(rawWords) {
|
|
2854
|
+
let words = rawWords;
|
|
2855
|
+
let i = 0;
|
|
2856
|
+
while (i < words.length) {
|
|
2857
|
+
const stripped = words[i].startsWith("@") ? words[i].slice(1) : words[i];
|
|
2858
|
+
if (!stripped) {
|
|
2859
|
+
i += 1;
|
|
2860
|
+
continue;
|
|
2861
|
+
}
|
|
2862
|
+
const head = executableName(stripped);
|
|
2863
|
+
if (head === "call") {
|
|
2864
|
+
words = words.slice(i + 1).map(decodeCmdCaretsInWord);
|
|
2865
|
+
i = 0;
|
|
2866
|
+
continue;
|
|
2867
|
+
}
|
|
2868
|
+
if (head === "do" || head === "else") {
|
|
2869
|
+
i += 1;
|
|
2870
|
+
continue;
|
|
2871
|
+
}
|
|
2872
|
+
if (head === "if") {
|
|
2873
|
+
let j = i + 1;
|
|
2874
|
+
if (words[j]?.toLowerCase() === "/i") j += 1;
|
|
2875
|
+
if (words[j]?.toLowerCase() === "not") j += 1;
|
|
2876
|
+
const cond = words[j]?.toLowerCase();
|
|
2877
|
+
if (cond === "exist" || cond === "defined" || cond === "errorlevel") {
|
|
2878
|
+
i = j + 2;
|
|
2879
|
+
continue;
|
|
2880
|
+
}
|
|
2881
|
+
if (j + 2 < words.length && (words[j + 1] === "==" || CMD_IF_COMPARE_OPS.has(words[j + 1].toLowerCase()))) {
|
|
2882
|
+
i = j + 3;
|
|
2883
|
+
continue;
|
|
2884
|
+
}
|
|
2885
|
+
if (j < words.length && words[j].includes("==")) {
|
|
2886
|
+
i = j + 1;
|
|
2887
|
+
continue;
|
|
2888
|
+
}
|
|
2889
|
+
return { words: words.slice(i), opaque: true };
|
|
2890
|
+
}
|
|
2891
|
+
if (head === "for") {
|
|
2892
|
+
const doIdx = words.findIndex((w, idx) => idx > i && w.toLowerCase() === "do");
|
|
2893
|
+
if (doIdx >= 0 && doIdx + 1 < words.length) {
|
|
2894
|
+
i = doIdx + 1;
|
|
2895
|
+
continue;
|
|
2896
|
+
}
|
|
2897
|
+
return { words: words.slice(i), opaque: true };
|
|
2898
|
+
}
|
|
2899
|
+
if (head === "start") {
|
|
2900
|
+
return { words: words.slice(i), opaque: true };
|
|
2901
|
+
}
|
|
2902
|
+
return { words: [stripped, ...words.slice(i + 1)], opaque: false };
|
|
2903
|
+
}
|
|
2904
|
+
return { words: [], opaque: false };
|
|
2905
|
+
}
|
|
2906
|
+
function unwrapSegmentCommandWords(words, shell) {
|
|
2907
|
+
if (shell === "cmd") return unwrapCmdControlWords(words);
|
|
2908
|
+
let index = 0;
|
|
2909
|
+
while (index < words.length) {
|
|
2910
|
+
const word = words[index];
|
|
2911
|
+
const lower = word.toLowerCase();
|
|
2912
|
+
if (DESTRUCTIVE_CONTROL_PREFIXES.has(lower) || shell === "powershell" && (word === "." || word === "&")) {
|
|
2913
|
+
index += 1;
|
|
2914
|
+
continue;
|
|
2915
|
+
}
|
|
2916
|
+
if (STANDALONE_REDIR_RE2.test(word)) {
|
|
2917
|
+
index += 2;
|
|
2918
|
+
continue;
|
|
2919
|
+
}
|
|
2920
|
+
if (INLINE_REDIR_RE2.test(word) || /^[A-Za-z_][A-Za-z0-9_]*=/.test(word)) {
|
|
2921
|
+
index += 1;
|
|
2922
|
+
continue;
|
|
2923
|
+
}
|
|
2924
|
+
const program = executableName(word);
|
|
2925
|
+
if (program === "eval") return { words: words.slice(index), opaque: true };
|
|
2926
|
+
if (DESTRUCTIVE_WRAPPER_NAMES.has(program)) {
|
|
2927
|
+
const valueFlags = DESTRUCTIVE_WRAPPER_VALUE_FLAGS[program];
|
|
2928
|
+
index += 1;
|
|
2929
|
+
while (index < words.length) {
|
|
2930
|
+
const arg = words[index];
|
|
2931
|
+
if (arg === "--") {
|
|
2932
|
+
index += 1;
|
|
2933
|
+
break;
|
|
2934
|
+
}
|
|
2935
|
+
if (program === "env") {
|
|
2936
|
+
if (arg === "-S" || arg === "--split-string" || arg.startsWith("-S") || arg.startsWith("--split-string=")) {
|
|
2937
|
+
return { words: words.slice(index), opaque: true };
|
|
2938
|
+
}
|
|
2939
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(arg)) {
|
|
2940
|
+
index += 1;
|
|
2941
|
+
continue;
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
if (valueFlags?.has(arg)) {
|
|
2945
|
+
index += 2;
|
|
2946
|
+
continue;
|
|
2947
|
+
}
|
|
2948
|
+
if (arg.startsWith("-")) {
|
|
2949
|
+
index += 1;
|
|
2950
|
+
continue;
|
|
2951
|
+
}
|
|
2952
|
+
break;
|
|
2953
|
+
}
|
|
2954
|
+
if (program === "timeout") index += 1;
|
|
2955
|
+
continue;
|
|
2956
|
+
}
|
|
2957
|
+
return { words: words.slice(index), opaque: false };
|
|
2958
|
+
}
|
|
2959
|
+
return { words: [], opaque: false };
|
|
2960
|
+
}
|
|
2961
|
+
function isRiskyGitConfigEntry(entry) {
|
|
2962
|
+
if (!entry) return true;
|
|
2963
|
+
const eq = entry.indexOf("=");
|
|
2964
|
+
const key = eq >= 0 ? entry.slice(0, eq) : entry;
|
|
2965
|
+
const val = eq >= 0 ? entry.slice(eq + 1) : "";
|
|
2966
|
+
if (GIT_EXEC_CONFIG_KEY_RE.test(key)) return true;
|
|
2967
|
+
if (val.startsWith("!") || /\s/.test(val)) return true;
|
|
2968
|
+
if (/^alias\./i.test(key) && (!val || GIT_DESTRUCTIVE_SUBCOMMANDS.has(val.toLowerCase()))) return true;
|
|
2969
|
+
return false;
|
|
2970
|
+
}
|
|
2971
|
+
function stripRedirectionTokens(words) {
|
|
2972
|
+
const out = [];
|
|
2973
|
+
for (let i = 0; i < words.length; i += 1) {
|
|
2974
|
+
const w = words[i];
|
|
2975
|
+
if (STANDALONE_REDIR_RE2.test(w)) {
|
|
2976
|
+
i += 1;
|
|
2977
|
+
continue;
|
|
2978
|
+
}
|
|
2979
|
+
if (INLINE_REDIR_RE2.test(w)) continue;
|
|
2980
|
+
out.push(w);
|
|
2981
|
+
}
|
|
2982
|
+
return out;
|
|
2983
|
+
}
|
|
2984
|
+
function normalizeGitCommandForDestructiveCheck(rawCmdWords) {
|
|
2985
|
+
const cmdWords = stripRedirectionTokens(rawCmdWords);
|
|
2986
|
+
let i = 1;
|
|
2987
|
+
while (i < cmdWords.length) {
|
|
2988
|
+
const w = cmdWords[i];
|
|
2989
|
+
if (w === "--config-env" || w.startsWith("--config-env=")) return { riskyConfig: true };
|
|
2990
|
+
if (w === "-c") {
|
|
2991
|
+
const val = cmdWords[i + 1] ?? "";
|
|
2992
|
+
if (isRiskyGitConfigEntry(val)) return { riskyConfig: true };
|
|
2993
|
+
i += 2;
|
|
2994
|
+
continue;
|
|
2995
|
+
}
|
|
2996
|
+
if (w.startsWith("-c") && w.length > 2) {
|
|
2997
|
+
if (isRiskyGitConfigEntry(w.slice(2))) return { riskyConfig: true };
|
|
2998
|
+
i += 1;
|
|
2999
|
+
continue;
|
|
3000
|
+
}
|
|
3001
|
+
if (GIT_GLOBAL_VALUE_FLAGS.has(w)) {
|
|
3002
|
+
i += 2;
|
|
3003
|
+
continue;
|
|
3004
|
+
}
|
|
3005
|
+
if (w.startsWith("-")) {
|
|
3006
|
+
i += 1;
|
|
3007
|
+
continue;
|
|
3008
|
+
}
|
|
3009
|
+
break;
|
|
3010
|
+
}
|
|
3011
|
+
const sub = cmdWords[i]?.toLowerCase();
|
|
3012
|
+
if (!sub) return { riskyConfig: false };
|
|
3013
|
+
const out = ["git", sub];
|
|
3014
|
+
for (let j = i + 1; j < cmdWords.length; j += 1) {
|
|
3015
|
+
const arg = cmdWords[j];
|
|
3016
|
+
if (sub === "commit" || sub === "merge") {
|
|
3017
|
+
if (GIT_MSG_VALUE_FLAGS.has(arg) || /^-[a-zA-Z]*[mF]$/.test(arg)) {
|
|
3018
|
+
j += 1;
|
|
3019
|
+
continue;
|
|
3020
|
+
}
|
|
3021
|
+
if (/^(?:--(?:message|file|author)=|-m.+|-F.+)/.test(arg)) continue;
|
|
3022
|
+
}
|
|
3023
|
+
if (/^ext::/i.test(arg)) return { riskyConfig: true };
|
|
3024
|
+
out.push(arg);
|
|
3025
|
+
}
|
|
3026
|
+
if (!GIT_DESTRUCTIVE_SUBCOMMANDS.has(sub)) return { riskyConfig: false };
|
|
3027
|
+
return { normalized: out.join(" "), riskyConfig: false };
|
|
3028
|
+
}
|
|
3029
|
+
function hasDynamicOrBraceSyntax(command, shell) {
|
|
3030
|
+
if (command.includes("$(") || command.includes("`") || command.includes("${") || /(?:^|[^<])<<(?!<)/.test(command)) {
|
|
3031
|
+
return true;
|
|
3032
|
+
}
|
|
3033
|
+
if (shell === "powershell") return false;
|
|
3034
|
+
let quote;
|
|
3035
|
+
for (let i = 0; i < command.length; i += 1) {
|
|
3036
|
+
const ch = command[i];
|
|
3037
|
+
if (quote) {
|
|
3038
|
+
if (shell !== "cmd" && quote === '"' && ch === "\\" && i + 1 < command.length) {
|
|
3039
|
+
i += 1;
|
|
3040
|
+
continue;
|
|
3041
|
+
}
|
|
3042
|
+
if (ch === quote) quote = void 0;
|
|
3043
|
+
continue;
|
|
3044
|
+
}
|
|
3045
|
+
if (ch === '"' || shell !== "cmd" && ch === "'") {
|
|
3046
|
+
quote = ch;
|
|
3047
|
+
continue;
|
|
3048
|
+
}
|
|
3049
|
+
if (shell === "cmd" && ch === "^" && i + 1 < command.length) {
|
|
3050
|
+
i += 1;
|
|
3051
|
+
continue;
|
|
3052
|
+
}
|
|
3053
|
+
if (shell !== "cmd" && ch === "\\" && i + 1 < command.length) {
|
|
3054
|
+
i += 1;
|
|
3055
|
+
continue;
|
|
3056
|
+
}
|
|
3057
|
+
if (ch === "{" && i + 1 < command.length && !/\s/.test(command[i + 1])) return true;
|
|
3058
|
+
}
|
|
3059
|
+
return Boolean(quote);
|
|
3060
|
+
}
|
|
3061
|
+
function matchDestructivePatterns(inspectedCommand, shell, patterns, gitConfigClass) {
|
|
3062
|
+
const hits = [];
|
|
3063
|
+
const scanTextAgainstPatterns = (text) => {
|
|
3064
|
+
for (const entry of patterns) {
|
|
3065
|
+
if (entry.pattern.test(text)) {
|
|
3066
|
+
hits.push({ warning: entry.warning, commandClass: entry.commandClass });
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
};
|
|
3070
|
+
if (hasDynamicOrBraceSyntax(inspectedCommand, shell)) {
|
|
3071
|
+
scanTextAgainstPatterns(inspectedCommand);
|
|
3072
|
+
return hits;
|
|
3073
|
+
}
|
|
3074
|
+
const segments = splitShellSegments(inspectedCommand, shell);
|
|
3075
|
+
const tokenized = [];
|
|
3076
|
+
for (const segment of segments) {
|
|
3077
|
+
const words = splitShellWords(segment, shell);
|
|
3078
|
+
if (!words) {
|
|
3079
|
+
scanTextAgainstPatterns(segment);
|
|
3080
|
+
continue;
|
|
3081
|
+
}
|
|
3082
|
+
const unwrapped = unwrapSegmentCommandWords(words, shell);
|
|
3083
|
+
if (unwrapped.opaque) {
|
|
3084
|
+
scanTextAgainstPatterns(segment);
|
|
3085
|
+
scanTextAgainstPatterns(unwrapped.words.join(" "));
|
|
3086
|
+
continue;
|
|
3087
|
+
}
|
|
3088
|
+
const cmdWords = unwrapped.words;
|
|
3089
|
+
const rawNormalized = words.join(" ");
|
|
3090
|
+
const head = cmdWords[0] ? executableName(cmdWords[0]) : "";
|
|
3091
|
+
if (head === "git") {
|
|
3092
|
+
const hasRiskyGitEnv = words.some((w) => GIT_RISKY_ENV_RE.test(w));
|
|
3093
|
+
const gitCheck = normalizeGitCommandForDestructiveCheck(cmdWords);
|
|
3094
|
+
if (hasRiskyGitEnv || gitCheck.riskyConfig) {
|
|
3095
|
+
hits.push({ warning: GIT_EXEC_CONFIG_WARNING, commandClass: gitConfigClass });
|
|
3096
|
+
scanTextAgainstPatterns(segment);
|
|
3097
|
+
continue;
|
|
3098
|
+
}
|
|
3099
|
+
tokenized.push({ segment, rawNormalized, head, normalizedLine: gitCheck.normalized });
|
|
3100
|
+
} else {
|
|
3101
|
+
tokenized.push({
|
|
3102
|
+
segment,
|
|
3103
|
+
rawNormalized,
|
|
3104
|
+
head,
|
|
3105
|
+
normalizedLine: head ? stripRedirectionTokens([head, ...cmdWords.slice(1)]).join(" ") : void 0
|
|
3106
|
+
});
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
const allHeadsNonSql = tokenized.every((t) => !t.head || NON_SQL_TEXT_HEADS.has(t.head));
|
|
3110
|
+
for (const { segment, rawNormalized, head, normalizedLine } of tokenized) {
|
|
3111
|
+
for (const entry of patterns) {
|
|
3112
|
+
if (entry.heads) {
|
|
3113
|
+
if (!head || !entry.heads.has(head) || !normalizedLine) continue;
|
|
3114
|
+
if (entry.pattern.test(normalizedLine)) {
|
|
3115
|
+
hits.push({ warning: entry.warning, commandClass: entry.commandClass });
|
|
3116
|
+
}
|
|
3117
|
+
} else if (!allHeadsNonSql && (entry.pattern.test(segment) || entry.pattern.test(rawNormalized))) {
|
|
3118
|
+
hits.push({ warning: entry.warning, commandClass: entry.commandClass });
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
return hits;
|
|
3123
|
+
}
|
|
3124
|
+
function hasCmdFilesystemWriteHead(command) {
|
|
3125
|
+
for (const segment of splitShellSegments(command, "cmd")) {
|
|
3126
|
+
const words = splitShellWords(segment, "cmd");
|
|
3127
|
+
if (!words) {
|
|
3128
|
+
if (/(?<![\w.-])\b(copy|xcopy|robocopy|move|mkdir|md|ren|rename)\b/i.test(segment)) return true;
|
|
3129
|
+
continue;
|
|
3130
|
+
}
|
|
3131
|
+
const unwrapped = unwrapCmdControlWords(words);
|
|
3132
|
+
if (unwrapped.opaque) {
|
|
3133
|
+
if (unwrapped.words.some((w) => CMD_WRITE_HEADS.has(executableName(w.startsWith("@") ? w.slice(1) : w)))) {
|
|
3134
|
+
return true;
|
|
3135
|
+
}
|
|
3136
|
+
continue;
|
|
3137
|
+
}
|
|
3138
|
+
const head = unwrapped.words[0] ? executableName(unwrapped.words[0]) : "";
|
|
3139
|
+
if (CMD_WRITE_HEADS.has(head)) return true;
|
|
3140
|
+
}
|
|
3141
|
+
return false;
|
|
3142
|
+
}
|
|
3143
|
+
|
|
2644
3144
|
// ../../packages/shared-headless-capabilities/src/bash-policy.ts
|
|
3145
|
+
var GIT_HEAD = /* @__PURE__ */ new Set(["git"]);
|
|
3146
|
+
var PRIV_HEADS = /* @__PURE__ */ new Set(["sudo", "su", "chmod", "chown"]);
|
|
3147
|
+
var KUBECTL_HEAD = /* @__PURE__ */ new Set(["kubectl"]);
|
|
3148
|
+
var TERRAFORM_HEAD = /* @__PURE__ */ new Set(["terraform"]);
|
|
3149
|
+
var CMD_DEL_HEADS = /* @__PURE__ */ new Set(["del", "erase"]);
|
|
3150
|
+
var CMD_RMDIR_HEADS = /* @__PURE__ */ new Set(["rmdir", "rd"]);
|
|
3151
|
+
var CMD_FORMAT_HEAD = /* @__PURE__ */ new Set(["format"]);
|
|
3152
|
+
var CMD_ACL_HEADS = /* @__PURE__ */ new Set(["takeown", "icacls"]);
|
|
2645
3153
|
var DESTRUCTIVE_PATTERNS = [
|
|
2646
|
-
{ pattern: /\bgit\s+reset\
|
|
2647
|
-
{ pattern: /\bgit\s+push\b[^;&|\n]*[ \t](--force|--force-with-lease|-f)\b/, warning: "may overwrite remote history", commandClass: "git_destructive" },
|
|
2648
|
-
{ pattern: /\bgit\s+clean\b(?![^;&|\n]*(?:-[a-zA-Z]*n|--dry-run))[^;&|\n]
|
|
2649
|
-
{ pattern: /\bgit\s+(checkout|restore)\s+(--\s+)?\.[ \t]*($|[;&|\n])/, warning: "may discard all working tree changes", commandClass: "git_destructive" },
|
|
2650
|
-
{ pattern: /\bgit\s+stash[ \t]+(drop|clear)\b/, warning: "may permanently remove stashed changes", commandClass: "git_destructive" },
|
|
2651
|
-
{ pattern: /\bgit\s+branch\s+(-D[ \t]|--delete\s+--force|--force\s+--delete)\b/, warning: "may force-delete a branch", commandClass: "git_destructive" },
|
|
2652
|
-
{ pattern: /\bgit\s+(commit|push|merge)\b[^;&|\n]*--no-verify\b/, warning: "may skip safety hooks", commandClass: "git_destructive" },
|
|
3154
|
+
{ pattern: /\bgit\s+reset\b[^;&|\n]*[ \t]--hard\b/, warning: "may discard uncommitted changes", commandClass: "git_destructive", heads: GIT_HEAD },
|
|
3155
|
+
{ pattern: /\bgit\s+push\b[^;&|\n]*[ \t](--force|--force-with-lease|-f)\b/, warning: "may overwrite remote history", commandClass: "git_destructive", heads: GIT_HEAD },
|
|
3156
|
+
{ pattern: /\bgit\s+clean\b(?![^;&|\n]*[ \t](?:-[a-zA-Z]*n|--dry-run)(?:[ \t]|$))[^;&|\n]*[ \t]-[a-zA-Z]*f/, warning: "may permanently delete untracked files", commandClass: "git_destructive", heads: GIT_HEAD },
|
|
3157
|
+
{ pattern: /\bgit\s+(checkout|restore)\s+(--\s+)?\.[ \t]*($|[;&|\n])/, warning: "may discard all working tree changes", commandClass: "git_destructive", heads: GIT_HEAD },
|
|
3158
|
+
{ pattern: /\bgit\s+stash[ \t]+(drop|clear)\b/, warning: "may permanently remove stashed changes", commandClass: "git_destructive", heads: GIT_HEAD },
|
|
3159
|
+
{ pattern: /\bgit\s+branch\s+(-D[ \t]|--delete\s+--force|--force\s+--delete)\b/, warning: "may force-delete a branch", commandClass: "git_destructive", heads: GIT_HEAD },
|
|
3160
|
+
{ pattern: /\bgit\s+(commit|push|merge)\b[^;&|\n]*--no-verify\b/, warning: "may skip safety hooks", commandClass: "git_destructive", heads: GIT_HEAD },
|
|
2653
3161
|
// `rm -rf` is NOT in this regex list: raw-text matching both missed split
|
|
2654
3162
|
// flags (`rm -r -f`) and false-positived on quoted literals mentioning
|
|
2655
3163
|
// `rm -rf` (grep patterns, echo, docs). It is detected semantically by
|
|
2656
3164
|
// containsRecursiveForceRemove in classifyShellCommand instead.
|
|
2657
|
-
{ pattern: /\bsudo\b|\bsu\s+-|\bchmod\s+777\b|\bchown\s+-R\b/, warning: "may require elevated privileges or weaken permissions", commandClass: "privilege_escalation" },
|
|
3165
|
+
{ pattern: /\bsudo\b|\bsu\s+-|\bchmod\s+777\b|\bchown\s+-R\b/, warning: "may require elevated privileges or weaken permissions", commandClass: "privilege_escalation", heads: PRIV_HEADS },
|
|
2658
3166
|
{ pattern: /\b(DROP|TRUNCATE)\s+(TABLE|DATABASE|SCHEMA)\b/i, warning: "may drop or truncate database objects", commandClass: "infra_destructive" },
|
|
2659
3167
|
{ pattern: /\bDELETE\s+FROM\s+\w+[ \t]*(;|"|'|\n|$)/i, warning: "may delete all rows from a database table", commandClass: "infra_destructive" },
|
|
2660
|
-
{ pattern: /\bkubectl\s+delete\b/, warning: "may delete Kubernetes resources", commandClass: "infra_destructive" },
|
|
2661
|
-
{ pattern: /\bterraform\s+destroy\b/, warning: "may destroy Terraform infrastructure", commandClass: "infra_destructive" }
|
|
3168
|
+
{ pattern: /\bkubectl\s+delete\b/, warning: "may delete Kubernetes resources", commandClass: "infra_destructive", heads: KUBECTL_HEAD },
|
|
3169
|
+
{ pattern: /\bterraform\s+destroy\b/, warning: "may destroy Terraform infrastructure", commandClass: "infra_destructive", heads: TERRAFORM_HEAD }
|
|
2662
3170
|
];
|
|
2663
3171
|
var RM_FORCE_RECURSIVE_WARNING = "may recursively force-remove files";
|
|
2664
3172
|
var RM_RECURSIVE_WARNING = "may recursively remove files";
|
|
@@ -2696,28 +3204,70 @@ var POWERSHELL_DESTRUCTIVE_PATTERNS = [
|
|
|
2696
3204
|
// parameter matcher below accepts any unambiguous-style abbreviation,
|
|
2697
3205
|
// not just the full spellings.
|
|
2698
3206
|
{ pattern: buildPowerShellRemoveItemPattern(), warning: "may recursively or forcefully remove files", commandClass: "filesystem_write" },
|
|
2699
|
-
{ pattern:
|
|
3207
|
+
{ pattern: /(?<![\w.-])\b(?:Remove-Item|ri|rm|rmdir|del|erase|rd)\b[^;\n|]*(?:HKLM:|HKCU:|Registry::)/i, warning: "may remove registry entries", commandClass: "infra_destructive" },
|
|
2700
3208
|
// These write aliases are not all destructive in the recursive-delete sense,
|
|
2701
3209
|
// but they can overwrite or create arbitrary files. Keep them behind the
|
|
2702
3210
|
// same explicit shell confirmation boundary as other PowerShell writes.
|
|
2703
|
-
|
|
3211
|
+
// Note: `add` is NOT a PowerShell alias (`Add-Content` is `ac`) and `set`
|
|
3212
|
+
// is `Set-Variable` (`Set-Content` is `sc`); `(?<![\w.-])` prevents
|
|
3213
|
+
// matching file extensions like `README.md` or hyphenated flags.
|
|
3214
|
+
{ pattern: /(?<![\w.-])\b(?:Set-Content|sc|Add-Content|ac|Out-File|Clear-Content|clc|Tee-Object|tee|Export-Csv|Export-Clixml|New-Item|ni|md|mkdir|Copy-Item|cpi|cp|copy|Move-Item|mi|mv|move|Rename-Item|rni|ren)\b/i, warning: "may write or overwrite files", commandClass: "filesystem_write" },
|
|
2704
3215
|
{ pattern: /\b(Set-ExecutionPolicy|Start-Process\b[^;\n|]*-Verb\s+RunAs)\b/i, warning: "may change execution policy or request elevation", commandClass: "privilege_escalation" },
|
|
2705
3216
|
{ pattern: /\b(Stop-Computer|Restart-Computer)\b/i, warning: "may stop or restart the machine", commandClass: "infra_destructive" },
|
|
2706
3217
|
{ pattern: /(^|[;|&\n])\s*(?:Invoke-Expression|iex)\b/i, warning: "evaluates a dynamically constructed string as code", commandClass: "privilege_escalation" },
|
|
2707
|
-
{ pattern: /\bgit\s+reset\
|
|
3218
|
+
{ pattern: /\bgit\s+reset\b[^;&|\n]*[ \t]--hard\b/i, warning: "may discard uncommitted changes", commandClass: "git_destructive" },
|
|
2708
3219
|
{ pattern: /\bgit\s+push\b[^;&|\n]*[ \t](--force|--force-with-lease|-f)\b/i, warning: "may overwrite remote history", commandClass: "git_destructive" }
|
|
2709
3220
|
];
|
|
2710
3221
|
var CMD_DESTRUCTIVE_PATTERNS = [
|
|
2711
|
-
{ pattern: /\b(del|erase)\b[^&|\n]*(\/s|\/q)/i, warning: "may recursively or quietly delete files", commandClass: "filesystem_write" },
|
|
3222
|
+
{ pattern: /\b(del|erase)\b[^&|\n]*(\/s|\/q)/i, warning: "may recursively or quietly delete files", commandClass: "filesystem_write", heads: CMD_DEL_HEADS },
|
|
2712
3223
|
// `rd` is cmd's documented synonym for rmdir and accepts the same /s /q
|
|
2713
3224
|
// switches; classifying only `rmdir` let `rd /s /q C:\\anywhere` run as an
|
|
2714
3225
|
// undetected recursive deletion.
|
|
2715
|
-
{ pattern: /\b(?:rmdir|rd)\b[^&|\n]*(\/s|\/q)/i, warning: "may recursively remove directories", commandClass: "filesystem_write" },
|
|
2716
|
-
{ pattern: /\bformat\s+[a-z]:/i, warning: "may format a drive", commandClass: "infra_destructive" },
|
|
2717
|
-
{ pattern: /\b(takeown|icacls)\b[^&|\n]*(\/grant|\/reset|\/remove)/i, warning: "may alter ownership or permissions", commandClass: "privilege_escalation" },
|
|
2718
|
-
{ pattern: /\bgit\s+reset\
|
|
2719
|
-
{ pattern: /\bgit\s+push\b[^&|\n]*[ \t](--force|--force-with-lease|-f)\b/i, warning: "may overwrite remote history", commandClass: "git_destructive" }
|
|
3226
|
+
{ pattern: /\b(?:rmdir|rd)\b[^&|\n]*(\/s|\/q)/i, warning: "may recursively remove directories", commandClass: "filesystem_write", heads: CMD_RMDIR_HEADS },
|
|
3227
|
+
{ pattern: /\bformat\s+[a-z]:/i, warning: "may format a drive", commandClass: "infra_destructive", heads: CMD_FORMAT_HEAD },
|
|
3228
|
+
{ pattern: /\b(takeown|icacls)\b[^&|\n]*(\/grant|\/reset|\/remove)/i, warning: "may alter ownership or permissions", commandClass: "privilege_escalation", heads: CMD_ACL_HEADS },
|
|
3229
|
+
{ pattern: /\bgit\s+reset\b[^&|\n]*[ \t]--hard\b/i, warning: "may discard uncommitted changes", commandClass: "git_destructive", heads: GIT_HEAD },
|
|
3230
|
+
{ pattern: /\bgit\s+push\b[^&|\n]*[ \t](--force|--force-with-lease|-f)\b/i, warning: "may overwrite remote history", commandClass: "git_destructive", heads: GIT_HEAD }
|
|
2720
3231
|
];
|
|
3232
|
+
function hasPowerShellFileRedirection(command) {
|
|
3233
|
+
let quote;
|
|
3234
|
+
for (let i = 0; i < command.length; i += 1) {
|
|
3235
|
+
const ch = command[i];
|
|
3236
|
+
if (quote) {
|
|
3237
|
+
if (quote === '"' && ch === "`" && i + 1 < command.length) {
|
|
3238
|
+
i += 1;
|
|
3239
|
+
continue;
|
|
3240
|
+
}
|
|
3241
|
+
if (quote === "'" && ch === "'" && command[i + 1] === "'") {
|
|
3242
|
+
i += 1;
|
|
3243
|
+
continue;
|
|
3244
|
+
}
|
|
3245
|
+
if (quote === '"' && ch === '"' && command[i + 1] === '"') {
|
|
3246
|
+
i += 1;
|
|
3247
|
+
continue;
|
|
3248
|
+
}
|
|
3249
|
+
if (ch === quote) quote = void 0;
|
|
3250
|
+
continue;
|
|
3251
|
+
}
|
|
3252
|
+
if (ch === "'" || ch === '"') {
|
|
3253
|
+
quote = ch;
|
|
3254
|
+
continue;
|
|
3255
|
+
}
|
|
3256
|
+
if (ch === "`" && i + 1 < command.length) {
|
|
3257
|
+
i += 1;
|
|
3258
|
+
continue;
|
|
3259
|
+
}
|
|
3260
|
+
if (ch === ">") {
|
|
3261
|
+
const next = command[i + 1];
|
|
3262
|
+
if (next === "&" && /[0-6]/.test(command[i + 2] ?? "")) {
|
|
3263
|
+
i += 2;
|
|
3264
|
+
continue;
|
|
3265
|
+
}
|
|
3266
|
+
return true;
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
return false;
|
|
3270
|
+
}
|
|
2721
3271
|
function splitCommand(command) {
|
|
2722
3272
|
return command.split(/&&|\|\||[;\n]/).map((part) => part.trim()).filter(Boolean);
|
|
2723
3273
|
}
|
|
@@ -2729,7 +3279,7 @@ function buildPowerShellRemoveItemPattern() {
|
|
|
2729
3279
|
const recurseg = "-(?:r(?:e(?:c(?:u(?:r(?:s(?:e?)?)?)?)?)?)?)";
|
|
2730
3280
|
const force = "-(?:f(?:o(?:r(?:c(?:e?)?)?)?)?)";
|
|
2731
3281
|
return new RegExp(
|
|
2732
|
-
|
|
3282
|
+
`(?<![\\w.-])\\b${removeVerb}\\b[^;\\n|]*(?:${recurseg}|${force})\\b`,
|
|
2733
3283
|
"i"
|
|
2734
3284
|
);
|
|
2735
3285
|
}
|
|
@@ -2740,87 +3290,6 @@ function lastPipelineCommand(command) {
|
|
|
2740
3290
|
function classifyBashCommand(command, options) {
|
|
2741
3291
|
return classifyShellCommand(command, "bash", options);
|
|
2742
3292
|
}
|
|
2743
|
-
function splitShellSegments(command, shell = "bash") {
|
|
2744
|
-
const segments = [];
|
|
2745
|
-
let current = "";
|
|
2746
|
-
let quote;
|
|
2747
|
-
for (let index = 0; index < command.length; index += 1) {
|
|
2748
|
-
const char = command[index];
|
|
2749
|
-
if (quote) {
|
|
2750
|
-
if (quote === '"' && char === (shell === "powershell" ? "`" : "\\") && index + 1 < command.length) {
|
|
2751
|
-
current += char;
|
|
2752
|
-
current += command[index + 1];
|
|
2753
|
-
index += 1;
|
|
2754
|
-
continue;
|
|
2755
|
-
}
|
|
2756
|
-
current += char;
|
|
2757
|
-
if (char === quote) quote = void 0;
|
|
2758
|
-
continue;
|
|
2759
|
-
}
|
|
2760
|
-
if (char === "'" || char === '"') {
|
|
2761
|
-
quote = char;
|
|
2762
|
-
current += char;
|
|
2763
|
-
continue;
|
|
2764
|
-
}
|
|
2765
|
-
if (char === (shell === "powershell" ? "`" : "\\") && index + 1 < command.length) {
|
|
2766
|
-
current += char;
|
|
2767
|
-
current += command[index + 1];
|
|
2768
|
-
index += 1;
|
|
2769
|
-
continue;
|
|
2770
|
-
}
|
|
2771
|
-
if (char === "&" || char === "|" || char === ";" || char === "\n" || shell === "powershell" && /[(){}]/.test(char)) {
|
|
2772
|
-
if ((char === "&" || char === "|") && command[index + 1] === char) {
|
|
2773
|
-
index += 1;
|
|
2774
|
-
}
|
|
2775
|
-
segments.push(current);
|
|
2776
|
-
current = "";
|
|
2777
|
-
continue;
|
|
2778
|
-
}
|
|
2779
|
-
current += char;
|
|
2780
|
-
}
|
|
2781
|
-
segments.push(current);
|
|
2782
|
-
return segments.map((part) => part.trim()).filter(Boolean);
|
|
2783
|
-
}
|
|
2784
|
-
function splitShellWords(segment, shell = "bash") {
|
|
2785
|
-
const words = [];
|
|
2786
|
-
let current = "";
|
|
2787
|
-
let quote;
|
|
2788
|
-
for (let index = 0; index < segment.length; index += 1) {
|
|
2789
|
-
const char = segment[index];
|
|
2790
|
-
if (quote) {
|
|
2791
|
-
if (char === quote) {
|
|
2792
|
-
quote = void 0;
|
|
2793
|
-
} else if (quote === '"' && char === (shell === "powershell" ? "`" : "\\") && index + 1 < segment.length) {
|
|
2794
|
-
current += segment[index + 1];
|
|
2795
|
-
index += 1;
|
|
2796
|
-
} else {
|
|
2797
|
-
current += char;
|
|
2798
|
-
}
|
|
2799
|
-
continue;
|
|
2800
|
-
}
|
|
2801
|
-
if (char === "'" || char === '"') {
|
|
2802
|
-
quote = char;
|
|
2803
|
-
continue;
|
|
2804
|
-
}
|
|
2805
|
-
if (char === (shell === "powershell" ? "`" : "\\")) {
|
|
2806
|
-
if (index + 1 >= segment.length) return void 0;
|
|
2807
|
-
current += segment[index + 1];
|
|
2808
|
-
index += 1;
|
|
2809
|
-
continue;
|
|
2810
|
-
}
|
|
2811
|
-
if (/\s/.test(char)) {
|
|
2812
|
-
if (current) {
|
|
2813
|
-
words.push(current);
|
|
2814
|
-
current = "";
|
|
2815
|
-
}
|
|
2816
|
-
continue;
|
|
2817
|
-
}
|
|
2818
|
-
current += char;
|
|
2819
|
-
}
|
|
2820
|
-
if (quote) return void 0;
|
|
2821
|
-
if (current) words.push(current);
|
|
2822
|
-
return words;
|
|
2823
|
-
}
|
|
2824
3293
|
function normalizePosixPath(input) {
|
|
2825
3294
|
const absolute = input.startsWith("/");
|
|
2826
3295
|
const parts = [];
|
|
@@ -3194,13 +3663,13 @@ function classifyShellCommand(command, shell = "bash", options) {
|
|
|
3194
3663
|
destructive = true;
|
|
3195
3664
|
}
|
|
3196
3665
|
if (shell === "powershell") {
|
|
3666
|
+
if (hasPowerShellFileRedirection(command)) {
|
|
3667
|
+
warnings.push("may write or overwrite files");
|
|
3668
|
+
commandClass = "filesystem_write";
|
|
3669
|
+
destructive = true;
|
|
3670
|
+
}
|
|
3197
3671
|
const segments = splitShellSegments(command, shell);
|
|
3198
|
-
const simple =
|
|
3199
|
-
const words2 = splitShellWords(segment, shell);
|
|
3200
|
-
if (!words2?.length) return false;
|
|
3201
|
-
const head = words2[0] === "." ? words2[1] : words2[0];
|
|
3202
|
-
return !!head && /^[A-Za-z0-9_.\\/][A-Za-z0-9_.\\/:-]*$/.test(head) && !/^(?:return|throw|exit|if|elseif|else|switch|foreach|for|while|do|until|try|catch|finally|function|filter|class|begin|process|end|trap|data|using|workflow|configuration|break|continue|inlinescript|parallel|sequence)$/i.test(head);
|
|
3203
|
-
});
|
|
3672
|
+
const simple = isSimplePowerShellCommand(command, segments);
|
|
3204
3673
|
if (!simple) {
|
|
3205
3674
|
for (const entry of POWERSHELL_DESTRUCTIVE_PATTERNS) {
|
|
3206
3675
|
if (!entry.pattern.test(command)) continue;
|
|
@@ -3210,8 +3679,7 @@ function classifyShellCommand(command, shell = "bash", options) {
|
|
|
3210
3679
|
}
|
|
3211
3680
|
}
|
|
3212
3681
|
for (const segment of segments) {
|
|
3213
|
-
const words2 = splitShellWords(segment, shell) ?? segment.split(/\s+/);
|
|
3214
|
-
if (words2[0] === ".") words2.shift();
|
|
3682
|
+
const words2 = stripLeadingPowerShellPrefixes(splitShellWords(segment, shell) ?? segment.split(/\s+/));
|
|
3215
3683
|
if (!words2[0]) continue;
|
|
3216
3684
|
words2[0] = executableName(words2[0]);
|
|
3217
3685
|
for (const entry of POWERSHELL_DESTRUCTIVE_PATTERNS) {
|
|
@@ -3224,12 +3692,10 @@ function classifyShellCommand(command, shell = "bash", options) {
|
|
|
3224
3692
|
}
|
|
3225
3693
|
}
|
|
3226
3694
|
}
|
|
3227
|
-
for (const
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
destructive = true;
|
|
3232
|
-
}
|
|
3695
|
+
for (const hit of matchDestructivePatterns(inspectedCommand, shell, destructivePatterns, "git_destructive")) {
|
|
3696
|
+
warnings.push(hit.warning);
|
|
3697
|
+
commandClass = hit.commandClass;
|
|
3698
|
+
destructive = true;
|
|
3233
3699
|
}
|
|
3234
3700
|
if (destructive) {
|
|
3235
3701
|
return { commandClass, riskWarnings: [...new Set(warnings)], destructive, requiresPermission: true };
|
|
@@ -3241,7 +3707,7 @@ function classifyShellCommand(command, shell = "bash", options) {
|
|
|
3241
3707
|
commandClass = "network";
|
|
3242
3708
|
} else if (shell === "cmd" && /\b(curl|bitsadmin|certutil)\b/.test(normalized)) {
|
|
3243
3709
|
commandClass = "network";
|
|
3244
|
-
} else if (shell === "cmd" &&
|
|
3710
|
+
} else if (shell === "cmd" && hasCmdFilesystemWriteHead(inspectedCommand)) {
|
|
3245
3711
|
commandClass = "filesystem_write";
|
|
3246
3712
|
} else if (/\b(npm|pnpm|yarn|bun)\s+(install|add|remove|update|ci)\b/.test(normalized)) {
|
|
3247
3713
|
commandClass = "package_manager";
|
|
@@ -3482,7 +3948,7 @@ function safelyObserve(callback, event) {
|
|
|
3482
3948
|
} catch {
|
|
3483
3949
|
}
|
|
3484
3950
|
}
|
|
3485
|
-
function createAgentInstance(deps, systemPrompt, tools, model, apiKey, thinkingLevel) {
|
|
3951
|
+
function createAgentInstance(deps, systemPrompt, tools, model, apiKey, thinkingLevel, sessionId) {
|
|
3486
3952
|
const hooks = { finalizing: false };
|
|
3487
3953
|
tools = tools.map((tool) => ({ ...tool, execute: async (...args) => {
|
|
3488
3954
|
if (hooks.softDeadlineAt !== void 0 && Date.now() >= hooks.softDeadlineAt) hooks.finalizing = true;
|
|
@@ -3523,7 +3989,8 @@ function createAgentInstance(deps, systemPrompt, tools, model, apiKey, thinkingL
|
|
|
3523
3989
|
model,
|
|
3524
3990
|
tools,
|
|
3525
3991
|
apiKey,
|
|
3526
|
-
thinkingLevel
|
|
3992
|
+
thinkingLevel,
|
|
3993
|
+
...sessionId ? { sessionId } : {}
|
|
3527
3994
|
});
|
|
3528
3995
|
agentRunHooks.set(agent2, hooks);
|
|
3529
3996
|
agentRuntimeCredentials.set(agent2, { model, apiKey });
|
|
@@ -3537,6 +4004,7 @@ function createAgentInstance(deps, systemPrompt, tools, model, apiKey, thinkingL
|
|
|
3537
4004
|
thinkingLevel
|
|
3538
4005
|
},
|
|
3539
4006
|
apiKey,
|
|
4007
|
+
...sessionId ? { sessionId } : {},
|
|
3540
4008
|
// Subagent turns are single-purpose report generations: request an
|
|
3541
4009
|
// explicit output budget (see subagentOutputBudget) instead of leaving
|
|
3542
4010
|
// it to endpoint defaults that silently truncate long reports.
|
|
@@ -3696,6 +4164,7 @@ function isSubagentModelFallbackTrigger(errorMessage, failure, stopReason) {
|
|
|
3696
4164
|
if (stopReason === "aborted" || stopReason === "length") return false;
|
|
3697
4165
|
const kind = failure?.classification?.kind;
|
|
3698
4166
|
if (kind === "user_abort" || kind === "invalid_request" || kind === "context_overflow") return false;
|
|
4167
|
+
if (failure?.remoteFailure?.quotaExhausted === true) return true;
|
|
3699
4168
|
if (errorMessage && isDefaultQuotaExhaustedError(errorMessage)) return true;
|
|
3700
4169
|
if (kind === "auth_config") return true;
|
|
3701
4170
|
if (failure?.recovery?.outcome === "exhausted" && (kind === "provider_transient" || kind === "provider_confirmation" || kind === "transient_network")) {
|
|
@@ -3790,6 +4259,7 @@ async function tryCompactSubagentOverflow(options) {
|
|
|
3790
4259
|
summary = options.compactSummaryFn ? await options.compactSummaryFn(cleaned, options.model, options.apiKey, controller.signal) : await createCompactionSummary(cleaned, {
|
|
3791
4260
|
model: options.model,
|
|
3792
4261
|
apiKey: options.apiKey,
|
|
4262
|
+
...options.sessionId ? { sessionId: options.sessionId } : {},
|
|
3793
4263
|
signal: controller.signal
|
|
3794
4264
|
});
|
|
3795
4265
|
} catch (summaryError) {
|
|
@@ -3936,7 +4406,7 @@ async function runSubagentWithProgress(deps, task, reportProgress, signal, sessi
|
|
|
3936
4406
|
throw new Error("No model configured for subagent execution.");
|
|
3937
4407
|
}
|
|
3938
4408
|
const priorMessages = task.resumeMode === "report" ? [] : session.agent ? session.agent.state.messages : session.pendingMessages ?? [];
|
|
3939
|
-
const rebuilt = createAgentInstance(deps, buildSubagentSystemPrompt(nextMode, deps.skills), built.tools, built.model, built.apiKey, plan.thinkingLevel);
|
|
4409
|
+
const rebuilt = createAgentInstance(deps, buildSubagentSystemPrompt(nextMode, deps.skills), built.tools, built.model, built.apiKey, plan.thinkingLevel, session.id);
|
|
3940
4410
|
transplantMessages(rebuilt, priorMessages);
|
|
3941
4411
|
baseline = priorMessages.length;
|
|
3942
4412
|
subagent = rebuilt;
|
|
@@ -3981,12 +4451,13 @@ async function runSubagentWithProgress(deps, task, reportProgress, signal, sessi
|
|
|
3981
4451
|
}
|
|
3982
4452
|
deps.log(`[Subagent ${task.name}] Plan: ${plan.complexity}/${plan.modelClass}${plan.modelOverride ? `, model=${plan.modelOverrideApplied ? plan.modelOverride : "override failed"}` : ""}, ${tools.length} tools`);
|
|
3983
4453
|
debugLog(deps, "plan", "SubagentPlan", plan);
|
|
3984
|
-
|
|
4454
|
+
const childSessionId = `${task.id}-session-${(++taskIdCounter).toString(36)}`;
|
|
4455
|
+
subagent = createAgentInstance(deps, buildSubagentSystemPrompt(task.mode, deps.skills), tools, model, apiKey, plan.thinkingLevel, childSessionId);
|
|
3985
4456
|
activeTools = tools;
|
|
3986
4457
|
activeModel = model;
|
|
3987
4458
|
activeApiKey = apiKey;
|
|
3988
4459
|
session = {
|
|
3989
|
-
id:
|
|
4460
|
+
id: childSessionId,
|
|
3990
4461
|
name: task.name,
|
|
3991
4462
|
mode: task.mode,
|
|
3992
4463
|
priority: task.priority,
|
|
@@ -4149,7 +4620,7 @@ ${DELEGATION_REPORT_INSTRUCTION}`;
|
|
|
4149
4620
|
if (!compactedOnce && !signal?.aborted && Date.now() < hardDeadlineAt && isSubagentOverflowFailure(subagentFailure, terminalError, terminalStopReason)) {
|
|
4150
4621
|
compactedOnce = true;
|
|
4151
4622
|
report({ message: `[${task.name}] Context overflow; compacting history...` });
|
|
4152
|
-
const compacted = await tryCompactSubagentOverflow({ agent: subagent, model: activeModel, apiKey: activeApiKey, signal, hardDeadlineAt, compactSummaryFn: deps.compactSummaryFn });
|
|
4623
|
+
const compacted = await tryCompactSubagentOverflow({ agent: subagent, model: activeModel, apiKey: activeApiKey, sessionId: session?.id, signal, hardDeadlineAt, compactSummaryFn: deps.compactSummaryFn });
|
|
4153
4624
|
if (compacted.compacted) {
|
|
4154
4625
|
baseline = compacted.newBaseline;
|
|
4155
4626
|
runMode = "continue";
|
|
@@ -4166,7 +4637,7 @@ ${DELEGATION_REPORT_INSTRUCTION}`;
|
|
|
4166
4637
|
modelFallbacksUsed += 1;
|
|
4167
4638
|
const nextThinking = resolveThinkingSelection(next.model, plan.thinkingLevel).effective;
|
|
4168
4639
|
subagent.releaseTransport?.();
|
|
4169
|
-
subagent = createAgentInstance(deps, buildSubagentSystemPrompt(task.mode, deps.skills), activeTools, next.model, next.apiKey, nextThinking);
|
|
4640
|
+
subagent = createAgentInstance(deps, buildSubagentSystemPrompt(task.mode, deps.skills), activeTools, next.model, next.apiKey, nextThinking, session?.id);
|
|
4170
4641
|
activeModel = next.model;
|
|
4171
4642
|
activeApiKey = next.apiKey;
|
|
4172
4643
|
session.agent = subagent;
|
|
@@ -11964,13 +12435,9 @@ function extractOpenAIResponsesContent(response, originalQuery) {
|
|
|
11964
12435
|
const body = isRecord(response) ? response : {};
|
|
11965
12436
|
const sources = [];
|
|
11966
12437
|
collectUrlCitations(body.output, sources);
|
|
11967
|
-
|
|
11968
|
-
|
|
11969
|
-
|
|
11970
|
-
sources: uniqueSources(sources),
|
|
11971
|
-
results: [makeTextSegment(body.output_text.trim())],
|
|
11972
|
-
actualQueries: [originalQuery]
|
|
11973
|
-
};
|
|
12438
|
+
const sharedText = extractResponsesOutputText(body);
|
|
12439
|
+
if (sharedText) {
|
|
12440
|
+
return { text: sharedText, sources: uniqueSources(sources), results: [makeTextSegment(sharedText)], actualQueries: [originalQuery] };
|
|
11974
12441
|
}
|
|
11975
12442
|
const textChunks = [];
|
|
11976
12443
|
collectOutputText(body.output, textChunks);
|
|
@@ -17666,6 +18133,35 @@ function normalizeInboxItem(raw) {
|
|
|
17666
18133
|
function dedupeKey(item) {
|
|
17667
18134
|
return `${item.kind}\0${item.text}\0${item.projectKey ?? ""}\0${item.cwd ?? ""}`;
|
|
17668
18135
|
}
|
|
18136
|
+
function compareWikiInboxOrder(a, b) {
|
|
18137
|
+
if (a.createdAt !== b.createdAt) return a.createdAt - b.createdAt;
|
|
18138
|
+
return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
|
|
18139
|
+
}
|
|
18140
|
+
function selectWikiInboxPruneIds(existing, incoming, maxItems = MAX_WIKI_INBOX_ITEMS) {
|
|
18141
|
+
const winnersByKey = /* @__PURE__ */ new Map();
|
|
18142
|
+
winnersByKey.set(dedupeKey(incoming), incoming);
|
|
18143
|
+
for (const entry of existing) {
|
|
18144
|
+
const key = dedupeKey(entry);
|
|
18145
|
+
const current = winnersByKey.get(key);
|
|
18146
|
+
if (!current || compareWikiInboxOrder(entry, current) > 0) {
|
|
18147
|
+
winnersByKey.set(key, entry);
|
|
18148
|
+
}
|
|
18149
|
+
}
|
|
18150
|
+
const toRemoveSet = /* @__PURE__ */ new Set();
|
|
18151
|
+
for (const entry of existing) {
|
|
18152
|
+
const winner = winnersByKey.get(dedupeKey(entry));
|
|
18153
|
+
if (winner && entry.id !== winner.id) toRemoveSet.add(entry.id);
|
|
18154
|
+
}
|
|
18155
|
+
const remaining = existing.filter((entry) => !toRemoveSet.has(entry.id)).sort(compareWikiInboxOrder);
|
|
18156
|
+
const cap = Math.max(0, maxItems);
|
|
18157
|
+
if (remaining.length > cap) {
|
|
18158
|
+
const overflow = remaining.length - cap;
|
|
18159
|
+
for (const old of remaining.slice(0, overflow)) {
|
|
18160
|
+
toRemoveSet.add(old.id);
|
|
18161
|
+
}
|
|
18162
|
+
}
|
|
18163
|
+
return [...toRemoveSet];
|
|
18164
|
+
}
|
|
17669
18165
|
function readWikiInbox(memoryRoot) {
|
|
17670
18166
|
const dir = wikiInboxPath(memoryRoot);
|
|
17671
18167
|
assertSafeMemoryPath(memoryRoot, dir);
|
|
@@ -17690,7 +18186,7 @@ function readWikiInbox(memoryRoot) {
|
|
|
17690
18186
|
} catch {
|
|
17691
18187
|
}
|
|
17692
18188
|
}
|
|
17693
|
-
items.sort(
|
|
18189
|
+
items.sort(compareWikiInboxOrder);
|
|
17694
18190
|
return items;
|
|
17695
18191
|
}
|
|
17696
18192
|
function countWikiInbox(memoryRoot) {
|
|
@@ -17707,20 +18203,7 @@ function appendWikiInboxItem(memoryRoot, input) {
|
|
|
17707
18203
|
writeFileAtomic(memoryRoot, target, JSON.stringify(item) + "\n");
|
|
17708
18204
|
try {
|
|
17709
18205
|
const existing = readWikiInbox(memoryRoot);
|
|
17710
|
-
const
|
|
17711
|
-
const toRemove = [];
|
|
17712
|
-
for (const entry of existing) {
|
|
17713
|
-
if (entry.id !== item.id && dedupeKey(entry) === key) {
|
|
17714
|
-
toRemove.push(entry.id);
|
|
17715
|
-
}
|
|
17716
|
-
}
|
|
17717
|
-
const remaining = existing.filter((entry) => !toRemove.includes(entry.id));
|
|
17718
|
-
if (remaining.length > MAX_WIKI_INBOX_ITEMS) {
|
|
17719
|
-
const overflow = remaining.length - MAX_WIKI_INBOX_ITEMS;
|
|
17720
|
-
for (const old of remaining.slice(0, overflow)) {
|
|
17721
|
-
if (old.id !== item.id) toRemove.push(old.id);
|
|
17722
|
-
}
|
|
17723
|
-
}
|
|
18206
|
+
const toRemove = selectWikiInboxPruneIds(existing, item, MAX_WIKI_INBOX_ITEMS);
|
|
17724
18207
|
if (toRemove.length > 0) removeWikiInboxItems(memoryRoot, toRemove);
|
|
17725
18208
|
} catch {
|
|
17726
18209
|
}
|
|
@@ -19187,6 +19670,8 @@ export {
|
|
|
19187
19670
|
readMemoryFile,
|
|
19188
19671
|
MAX_WIKI_INBOX_ITEMS,
|
|
19189
19672
|
wikiInboxPath,
|
|
19673
|
+
compareWikiInboxOrder,
|
|
19674
|
+
selectWikiInboxPruneIds,
|
|
19190
19675
|
readWikiInbox,
|
|
19191
19676
|
countWikiInbox,
|
|
19192
19677
|
appendWikiInboxItem,
|