dahrk-node 0.1.18 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +66 -3
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -2740,12 +2740,30 @@ function tokenise(cmd) {
|
|
|
2740
2740
|
let quoted = false;
|
|
2741
2741
|
let started = false;
|
|
2742
2742
|
let quote = null;
|
|
2743
|
+
const pendingHeredocs = [];
|
|
2743
2744
|
const push = () => {
|
|
2744
2745
|
if (started) tokens.push({ value: cur, quoted });
|
|
2745
2746
|
cur = "";
|
|
2746
2747
|
quoted = false;
|
|
2747
2748
|
started = false;
|
|
2748
2749
|
};
|
|
2750
|
+
const consumeHeredocs = (s) => {
|
|
2751
|
+
let p = s;
|
|
2752
|
+
for (; ; ) {
|
|
2753
|
+
let lineEnd = p;
|
|
2754
|
+
while (lineEnd < cmd.length && cmd[lineEnd] !== "\n") lineEnd++;
|
|
2755
|
+
const line = cmd.slice(p, lineEnd);
|
|
2756
|
+
const { delim, dash } = pendingHeredocs[0];
|
|
2757
|
+
const terminator = dash ? line.replace(/^\t+/, "") : line;
|
|
2758
|
+
const atEnd = lineEnd >= cmd.length;
|
|
2759
|
+
if (terminator === delim) {
|
|
2760
|
+
pendingHeredocs.shift();
|
|
2761
|
+
if (pendingHeredocs.length === 0) return atEnd ? lineEnd : lineEnd + 1;
|
|
2762
|
+
}
|
|
2763
|
+
if (atEnd) return -1;
|
|
2764
|
+
p = lineEnd + 1;
|
|
2765
|
+
}
|
|
2766
|
+
};
|
|
2749
2767
|
for (let i = 0; i < cmd.length; i++) {
|
|
2750
2768
|
const c = cmd[i];
|
|
2751
2769
|
if (quote) {
|
|
@@ -2793,6 +2811,13 @@ function tokenise(cmd) {
|
|
|
2793
2811
|
i = j;
|
|
2794
2812
|
continue;
|
|
2795
2813
|
}
|
|
2814
|
+
if (c === "\n" && pendingHeredocs.length > 0) {
|
|
2815
|
+
push();
|
|
2816
|
+
const resume = consumeHeredocs(i + 1);
|
|
2817
|
+
if (resume < 0) return null;
|
|
2818
|
+
i = resume - 1;
|
|
2819
|
+
continue;
|
|
2820
|
+
}
|
|
2796
2821
|
if (/\s/.test(c)) {
|
|
2797
2822
|
push();
|
|
2798
2823
|
continue;
|
|
@@ -2805,6 +2830,38 @@ function tokenise(cmd) {
|
|
|
2805
2830
|
i += 2;
|
|
2806
2831
|
continue;
|
|
2807
2832
|
}
|
|
2833
|
+
if (two === "<<" && cmd[i + 2] !== "<") {
|
|
2834
|
+
push();
|
|
2835
|
+
let k = i + 2;
|
|
2836
|
+
const dash = cmd[k] === "-";
|
|
2837
|
+
if (dash) k++;
|
|
2838
|
+
while (k < cmd.length && (cmd[k] === " " || cmd[k] === " ")) k++;
|
|
2839
|
+
let delim = "";
|
|
2840
|
+
let dq = null;
|
|
2841
|
+
for (; k < cmd.length; k++) {
|
|
2842
|
+
const d = cmd[k];
|
|
2843
|
+
if (dq) {
|
|
2844
|
+
if (d === dq) dq = null;
|
|
2845
|
+
else delim += d;
|
|
2846
|
+
continue;
|
|
2847
|
+
}
|
|
2848
|
+
if (d === '"' || d === "'") {
|
|
2849
|
+
dq = d;
|
|
2850
|
+
continue;
|
|
2851
|
+
}
|
|
2852
|
+
if (d === "\\" && k + 1 < cmd.length) {
|
|
2853
|
+
delim += cmd[++k];
|
|
2854
|
+
continue;
|
|
2855
|
+
}
|
|
2856
|
+
if (/[\s;&|<>]/.test(d)) break;
|
|
2857
|
+
delim += d;
|
|
2858
|
+
}
|
|
2859
|
+
if (dq) return null;
|
|
2860
|
+
if (!delim) return null;
|
|
2861
|
+
pendingHeredocs.push({ delim, dash });
|
|
2862
|
+
i = k - 1;
|
|
2863
|
+
continue;
|
|
2864
|
+
}
|
|
2808
2865
|
if (["&&", "||", ">>", "2>", "&>"].includes(two)) {
|
|
2809
2866
|
push();
|
|
2810
2867
|
tokens.push({ value: two, quoted: false, operator: two });
|
|
@@ -2820,6 +2877,7 @@ function tokenise(cmd) {
|
|
|
2820
2877
|
started = true;
|
|
2821
2878
|
}
|
|
2822
2879
|
if (quote) return null;
|
|
2880
|
+
if (pendingHeredocs.length > 0) return null;
|
|
2823
2881
|
push();
|
|
2824
2882
|
return { tokens, subshells };
|
|
2825
2883
|
}
|
|
@@ -2949,7 +3007,7 @@ function scanCommand(cmd, roots, cwd = roots.cwd) {
|
|
|
2949
3007
|
}
|
|
2950
3008
|
if (out2.kind !== "ok") return out2;
|
|
2951
3009
|
}
|
|
2952
|
-
return { kind: "ok" };
|
|
3010
|
+
return { kind: "ok", cwd: cwdNow };
|
|
2953
3011
|
}
|
|
2954
3012
|
|
|
2955
3013
|
// ../../packages/edge/src/builtins.ts
|
|
@@ -3028,6 +3086,7 @@ function pathsIn(input) {
|
|
|
3028
3086
|
return out2;
|
|
3029
3087
|
}
|
|
3030
3088
|
function fsConfineRule(roots) {
|
|
3089
|
+
let sessionCwd = roots.cwd;
|
|
3031
3090
|
return {
|
|
3032
3091
|
name: "fs_confine",
|
|
3033
3092
|
evaluate(event) {
|
|
@@ -3038,8 +3097,12 @@ function fsConfineRule(roots) {
|
|
|
3038
3097
|
reason: `${need2 === "write" ? "write to" : "read of"} "${path}" is outside the run's worktree`
|
|
3039
3098
|
});
|
|
3040
3099
|
if (SHELL_TOOLS.has(event.tool)) {
|
|
3041
|
-
const result = scanCommand(commandOf(event.input), roots);
|
|
3100
|
+
const result = scanCommand(commandOf(event.input), roots, sessionCwd);
|
|
3042
3101
|
if (result.kind === "escape") return deny(result.path, result.need);
|
|
3102
|
+
if (result.kind === "ok") {
|
|
3103
|
+
if (result.cwd) sessionCwd = result.cwd;
|
|
3104
|
+
return null;
|
|
3105
|
+
}
|
|
3043
3106
|
if (result.kind === "unparseable") {
|
|
3044
3107
|
return {
|
|
3045
3108
|
verdict: "deny",
|
|
@@ -6686,7 +6749,7 @@ async function runStatus(inputs, deps) {
|
|
|
6686
6749
|
}
|
|
6687
6750
|
|
|
6688
6751
|
// src/main.ts
|
|
6689
|
-
var CLIENT_VERSION = "0.1.
|
|
6752
|
+
var CLIENT_VERSION = "0.1.19";
|
|
6690
6753
|
var DEFAULT_HUB_URL = "wss://api.dahrk.ai";
|
|
6691
6754
|
var list = (v) => (v ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
6692
6755
|
var RUNTIMES2 = ["claude-code", "codex", "pi"];
|