replicas-cli 0.3.546 → 0.3.548
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/index.cjs +92 -21
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -28255,12 +28255,12 @@ var init_chat_thread = __esm({
|
|
|
28255
28255
|
|
|
28256
28256
|
// ../shared/src/shell-commands.ts
|
|
28257
28257
|
function parseShellScript(script, cwd) {
|
|
28258
|
-
const scope = { src: script, vars: /* @__PURE__ */ new Map(), dir: cwd, commands: [], depth: 0, subshell: false };
|
|
28258
|
+
const scope = { src: script, vars: /* @__PURE__ */ new Map(), dir: cwd, commands: [], depth: 0, subshell: false, loopBudget: { left: MAX_LOOP_ITERATIONS } };
|
|
28259
28259
|
parseUntil(scope, 0, false);
|
|
28260
28260
|
return scope.commands;
|
|
28261
28261
|
}
|
|
28262
28262
|
function resolveShellPath(dir, path12) {
|
|
28263
|
-
if (path12.includes(SHELL_OPAQUE)
|
|
28263
|
+
if (path12.includes(SHELL_OPAQUE)) return null;
|
|
28264
28264
|
if (!path12.startsWith("/") && dir === null) return null;
|
|
28265
28265
|
const parts = [];
|
|
28266
28266
|
for (const part of (path12.startsWith("/") ? path12 : `${dir}/${path12}`).split("/")) {
|
|
@@ -28337,18 +28337,15 @@ function assign(scope, assignments) {
|
|
|
28337
28337
|
}
|
|
28338
28338
|
}
|
|
28339
28339
|
function emit(scope, raw) {
|
|
28340
|
-
const { argv
|
|
28341
|
-
if (argv.length === 0)
|
|
28342
|
-
assign(scope, assignments);
|
|
28343
|
-
return;
|
|
28344
|
-
}
|
|
28340
|
+
const { argv } = stripCommandPrefixes(raw.words);
|
|
28341
|
+
if (argv.length === 0) return;
|
|
28345
28342
|
const stdin = commandStdin(raw);
|
|
28346
28343
|
const output3 = staticOutput(argv, stdin) ?? SHELL_OPAQUE;
|
|
28347
28344
|
const stdinFile = raw.redirects.findLast(({ op }) => op === "<" || op === "0<");
|
|
28348
28345
|
const name = argv[0].split("/").pop() ?? "";
|
|
28349
28346
|
const flag = SHELLS.has(name) ? argv.findIndex((arg, index) => index > 0 && /^-[A-Za-z]*c[A-Za-z]*$/.test(arg)) : -1;
|
|
28350
28347
|
const script = flag > 0 ? argv[flag + 1] : SHELLS.has(name) && argv.length === 1 && stdin !== SHELL_OPAQUE ? stdin : name === "eval" ? argv.slice(1).join(" ") : void 0;
|
|
28351
|
-
const truncated = script !== void 0 && scope.depth >= MAX_DEPTH;
|
|
28348
|
+
const truncated = script !== void 0 && (scope.depth >= MAX_DEPTH || raw.truncated === true);
|
|
28352
28349
|
scope.commands.push({
|
|
28353
28350
|
argv,
|
|
28354
28351
|
dir: scope.dir,
|
|
@@ -28356,7 +28353,7 @@ function emit(scope, raw) {
|
|
|
28356
28353
|
afterAnd: raw.afterAnd,
|
|
28357
28354
|
stdinFile: stdinFile ? resolveShellPath(scope.dir, stdinFile.target) : null,
|
|
28358
28355
|
stdinTarget: stdinFile?.target ?? null,
|
|
28359
|
-
writes: raw.redirects.
|
|
28356
|
+
writes: raw.redirects.filter(({ op, target }) => /^(?:1?>|1?>\||1?>>|&>|&>>|>&)$/.test(op) && !/^(?:\d+|-)$/.test(target)).map(({ op, target }, index, outputs) => ({ path: resolveShellPath(scope.dir, target), target, content: index === outputs.length - 1 ? output3 : "", append: op.endsWith(">>") })),
|
|
28360
28357
|
wrapper: script !== void 0,
|
|
28361
28358
|
truncated,
|
|
28362
28359
|
piped: raw.pipeFrom !== void 0,
|
|
@@ -28364,10 +28361,8 @@ function emit(scope, raw) {
|
|
|
28364
28361
|
});
|
|
28365
28362
|
if (name === "cd" || name === "pushd" || name === "popd") {
|
|
28366
28363
|
scope.dir = name !== "popd" && argv[1] && argv[1] !== "-" ? resolveShellPath(scope.dir, argv[1]) : null;
|
|
28367
|
-
} else if (["export", "declare", "local", "readonly"].includes(name)) {
|
|
28368
|
-
assign(scope, argv.slice(1).filter((arg) => /^[A-Za-z_]\w*=/.test(arg)));
|
|
28369
28364
|
}
|
|
28370
|
-
if (script && !truncated) parseUntil({ src: script, vars: name === "eval" ? scope.vars : /* @__PURE__ */ new Map(), dir: scope.dir, commands: scope.commands, depth: scope.depth + 1, subshell: scope.subshell || raw.subshell }, 0, false);
|
|
28365
|
+
if (script && !truncated) parseUntil({ src: script, vars: name === "eval" ? scope.vars : /* @__PURE__ */ new Map(), dir: scope.dir, commands: scope.commands, depth: scope.depth + 1, subshell: scope.subshell || raw.subshell, loopBudget: scope.loopBudget }, 0, false);
|
|
28371
28366
|
}
|
|
28372
28367
|
function readHeredocBodies(scope, heredocs, start) {
|
|
28373
28368
|
const { src } = scope;
|
|
@@ -28415,7 +28410,7 @@ function readDoubleQuoted(scope, start, terminator) {
|
|
|
28415
28410
|
return { value, end: i };
|
|
28416
28411
|
}
|
|
28417
28412
|
function substitute(scope, src, start, closeParen) {
|
|
28418
|
-
const child = { src, vars: new Map(scope.vars), dir: scope.dir, commands: [], depth: scope.depth + 1, subshell: true };
|
|
28413
|
+
const child = { src, vars: new Map(scope.vars), dir: scope.dir, commands: [], depth: scope.depth + 1, subshell: true, loopBudget: scope.loopBudget };
|
|
28419
28414
|
const end = parseUntil(child, start, closeParen);
|
|
28420
28415
|
scope.commands.push(...child.commands);
|
|
28421
28416
|
const [only] = child.commands;
|
|
@@ -28456,16 +28451,22 @@ function readExpansion(scope, i, inDouble) {
|
|
|
28456
28451
|
if (next && /[0-9@*#?$!-]/.test(next)) return { value: SHELL_OPAQUE, end: i + 2 };
|
|
28457
28452
|
return { value: "$", end: i + 1 };
|
|
28458
28453
|
}
|
|
28459
|
-
function parseUntil(scope, start, closeParen) {
|
|
28454
|
+
function parseUntil(scope, start, closeParen, untilDone = false) {
|
|
28460
28455
|
const { src } = scope;
|
|
28461
28456
|
let i = start;
|
|
28462
28457
|
let line = [];
|
|
28463
28458
|
let current = { words: [], redirects: [], heredocs: [], afterAnd: false, subshell: false };
|
|
28459
|
+
let previous;
|
|
28464
28460
|
let pendingHeredocs = [];
|
|
28465
28461
|
let word = null;
|
|
28466
28462
|
let quoted = false;
|
|
28467
28463
|
let redirect = null;
|
|
28468
28464
|
let parens = 0;
|
|
28465
|
+
let keyword = null;
|
|
28466
|
+
let openLoops = 0;
|
|
28467
|
+
let afterOr = false;
|
|
28468
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
28469
|
+
const scoped = /* @__PURE__ */ new Set();
|
|
28469
28470
|
const append = (text4, isQuoted = false) => {
|
|
28470
28471
|
word = (word ?? "") + text4;
|
|
28471
28472
|
quoted || (quoted = isQuoted);
|
|
@@ -28479,6 +28480,7 @@ function parseUntil(scope, start, closeParen) {
|
|
|
28479
28480
|
} else if (redirect) {
|
|
28480
28481
|
current.redirects.push({ op: redirect, target: word });
|
|
28481
28482
|
} else {
|
|
28483
|
+
if (current.words.length === 0 && !quoted && (word === "do" || word === "done")) keyword = { word, header: previous?.words };
|
|
28482
28484
|
current.words.push(word);
|
|
28483
28485
|
}
|
|
28484
28486
|
word = null;
|
|
@@ -28490,14 +28492,80 @@ function parseUntil(scope, start, closeParen) {
|
|
|
28490
28492
|
const done = current;
|
|
28491
28493
|
if (op === "&") done.subshell = true;
|
|
28492
28494
|
current = { words: [], redirects: [], heredocs: [], pipeFrom: op === "|" || op === "|&" ? done : void 0, afterAnd: op === "&&", subshell: parens > 0 };
|
|
28493
|
-
|
|
28495
|
+
const endChain = () => {
|
|
28496
|
+
if (op === void 0 || ["&&", "|", "|&"].includes(op) || done.words[0] === "for") return;
|
|
28497
|
+
for (const name of conditional) scope.vars.set(name, SHELL_OPAQUE);
|
|
28498
|
+
conditional.clear();
|
|
28499
|
+
};
|
|
28500
|
+
if (done.words.length === 0 && done.redirects.length === 0 && done.heredocs.length === 0) {
|
|
28501
|
+
endChain();
|
|
28502
|
+
return;
|
|
28503
|
+
}
|
|
28504
|
+
line.push(done);
|
|
28505
|
+
previous = done;
|
|
28506
|
+
const { argv, assignments } = stripCommandPrefixes(done.words);
|
|
28507
|
+
const assigned = argv.length === 0 ? assignments : ["export", "declare", "local", "readonly"].includes(argv[0]) ? argv.slice(1).filter((arg) => /^[A-Za-z_]\w*=/.test(arg)) : [];
|
|
28508
|
+
assign(scope, assigned);
|
|
28509
|
+
const names = assigned.map((assignment) => assignment.slice(0, assignment.indexOf("=")));
|
|
28510
|
+
if (done.afterAnd || afterOr) for (const name of names) conditional.add(name);
|
|
28511
|
+
if (done.subshell) for (const name of names) scoped.add(name);
|
|
28512
|
+
if (op === ")" && parens === 0 || op === "&") {
|
|
28513
|
+
for (const name of scoped) scope.vars.set(name, SHELL_OPAQUE);
|
|
28514
|
+
scoped.clear();
|
|
28515
|
+
}
|
|
28516
|
+
afterOr = op === "||";
|
|
28517
|
+
endChain();
|
|
28518
|
+
if (argv[0] === "eval") {
|
|
28519
|
+
if (pendingHeredocs.length > 0) done.truncated = true;
|
|
28520
|
+
else {
|
|
28521
|
+
for (const raw of line) emit(scope, raw);
|
|
28522
|
+
line = [];
|
|
28523
|
+
}
|
|
28524
|
+
}
|
|
28525
|
+
};
|
|
28526
|
+
const unrollFor = (header) => {
|
|
28527
|
+
current = { words: [], redirects: [], heredocs: [], afterAnd: false, subshell: parens > 0 };
|
|
28528
|
+
flush();
|
|
28529
|
+
const words = header.slice(3);
|
|
28530
|
+
const literal2 = header[2] === "in" && words.length > 0 && words.length <= MAX_LOOP_VALUES && words.every((value) => !value.includes(SHELL_OPAQUE) && !/[\s*?[{]/.test(value));
|
|
28531
|
+
const values = literal2 ? words : [SHELL_OPAQUE];
|
|
28532
|
+
scope.loopBudget.left -= values.length;
|
|
28533
|
+
if (scope.loopBudget.left < 0) {
|
|
28534
|
+
scope.commands.push({ argv: header, dir: scope.dir, stdinFile: null, stdinTarget: null, writes: [], wrapper: true, truncated: true, afterAnd: false, piped: false, subshell: scope.subshell });
|
|
28535
|
+
values.splice(0, values.length, SHELL_OPAQUE);
|
|
28536
|
+
}
|
|
28537
|
+
let end = src.length;
|
|
28538
|
+
for (const value of values) {
|
|
28539
|
+
scope.vars.set(header[1], value);
|
|
28540
|
+
end = parseUntil(scope, i, false, true);
|
|
28541
|
+
}
|
|
28542
|
+
i = end;
|
|
28543
|
+
};
|
|
28544
|
+
const takeKeyword = () => {
|
|
28545
|
+
const taken = keyword;
|
|
28546
|
+
keyword = null;
|
|
28547
|
+
return taken;
|
|
28494
28548
|
};
|
|
28495
|
-
const flush = () => {
|
|
28496
|
-
endCommand();
|
|
28549
|
+
const flush = (op) => {
|
|
28550
|
+
endCommand(op);
|
|
28497
28551
|
for (const raw of line) emit(scope, raw);
|
|
28498
28552
|
line = [];
|
|
28499
28553
|
};
|
|
28500
28554
|
while (i < src.length) {
|
|
28555
|
+
const { word: boundary, header } = takeKeyword() ?? {};
|
|
28556
|
+
if (boundary === "do") {
|
|
28557
|
+
if (header?.[0] === "for" && /^[A-Za-z_]\w*$/.test(header[1] ?? "")) {
|
|
28558
|
+
unrollFor(header);
|
|
28559
|
+
continue;
|
|
28560
|
+
}
|
|
28561
|
+
openLoops++;
|
|
28562
|
+
} else if (boundary === "done") {
|
|
28563
|
+
if (openLoops > 0) openLoops--;
|
|
28564
|
+
else if (untilDone) {
|
|
28565
|
+
flush();
|
|
28566
|
+
return i;
|
|
28567
|
+
}
|
|
28568
|
+
}
|
|
28501
28569
|
const c = src[i];
|
|
28502
28570
|
if (c === "\\") {
|
|
28503
28571
|
if (src[i + 1] !== "\n") append(src[i + 1] ?? "", true);
|
|
@@ -28520,7 +28588,7 @@ function parseUntil(scope, start, closeParen) {
|
|
|
28520
28588
|
endWord();
|
|
28521
28589
|
i = readHeredocBodies(scope, pendingHeredocs, i + 1);
|
|
28522
28590
|
pendingHeredocs = [];
|
|
28523
|
-
flush();
|
|
28591
|
+
flush("\n");
|
|
28524
28592
|
} else if (c === " " || c === " " || c === "\r") {
|
|
28525
28593
|
endWord();
|
|
28526
28594
|
i++;
|
|
@@ -28531,7 +28599,7 @@ function parseUntil(scope, start, closeParen) {
|
|
|
28531
28599
|
OPERATOR.lastIndex = i;
|
|
28532
28600
|
const op = OPERATOR.exec(src)?.[0];
|
|
28533
28601
|
if (!op) {
|
|
28534
|
-
append(c);
|
|
28602
|
+
append(c === "~" && word === null && /^(?:[/\s;&|()<>]|$)/.test(src[i + 1] ?? "") ? scope.vars.get("HOME") ?? SANDBOX_PATHS.HOME_DIR : c);
|
|
28535
28603
|
i++;
|
|
28536
28604
|
continue;
|
|
28537
28605
|
}
|
|
@@ -28550,12 +28618,15 @@ function parseUntil(scope, start, closeParen) {
|
|
|
28550
28618
|
flush();
|
|
28551
28619
|
return i;
|
|
28552
28620
|
}
|
|
28553
|
-
var SHELL_OPAQUE, MAX_DEPTH, OPERATOR, NAME, SHELLS, PREFIX_WORDS, WRAPPER_VALUE_OPTIONS, ANSI_C_ESCAPES;
|
|
28621
|
+
var SHELL_OPAQUE, MAX_DEPTH, MAX_LOOP_VALUES, MAX_LOOP_ITERATIONS, OPERATOR, NAME, SHELLS, PREFIX_WORDS, WRAPPER_VALUE_OPTIONS, ANSI_C_ESCAPES;
|
|
28554
28622
|
var init_shell_commands = __esm({
|
|
28555
28623
|
"../shared/src/shell-commands.ts"() {
|
|
28556
28624
|
"use strict";
|
|
28625
|
+
init_sandbox();
|
|
28557
28626
|
SHELL_OPAQUE = "\0";
|
|
28558
28627
|
MAX_DEPTH = 8;
|
|
28628
|
+
MAX_LOOP_VALUES = 20;
|
|
28629
|
+
MAX_LOOP_ITERATIONS = 500;
|
|
28559
28630
|
OPERATOR = /&&|\|\||;;|\|&|<<<|<<-|<<|&>>|&>|>>|>&|>\||<&|<>|[;&|()<>]/y;
|
|
28560
28631
|
NAME = /[A-Za-z_]\w*/y;
|
|
28561
28632
|
SHELLS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "dash", "ksh"]);
|
|
@@ -40397,7 +40468,7 @@ var CLI_VERSION;
|
|
|
40397
40468
|
var init_cli_version = __esm({
|
|
40398
40469
|
"../shared/src/cli-version.ts"() {
|
|
40399
40470
|
"use strict";
|
|
40400
|
-
CLI_VERSION = "0.3.
|
|
40471
|
+
CLI_VERSION = "0.3.547";
|
|
40401
40472
|
}
|
|
40402
40473
|
});
|
|
40403
40474
|
|