@sagentlab/navarch-runtime 0.1.152 → 0.1.154

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.
@@ -320,11 +320,22 @@ function isCommentOrMarkupToken(command, start, token, heredocs) {
320
320
 
321
321
  let rootEntries;
322
322
 
323
- /** Entry names at the filesystem root, or null when they cannot be listed. */
323
+ // Policy paths must remain candidates even when a sandbox hides root entries.
324
+ // Include home roots on both platforms, independently of the host OS.
325
+ const POLICY_ROOT_ENTRIES = [...new Set(
326
+ [...DEFAULT_SYSTEM_PREFIXES, "/home", "/Users", "/root", os.homedir()]
327
+ .map((prefix) => prefix.split("/")[1])
328
+ .filter(Boolean),
329
+ )];
330
+
331
+ /** Visible root entry names plus policy roots, or null if listing fails. */
324
332
  function listRootEntries() {
325
333
  if (rootEntries === undefined) {
326
334
  try {
327
- rootEntries = fs.readdirSync(path.parse(process.cwd()).root);
335
+ rootEntries = [...new Set([
336
+ ...POLICY_ROOT_ENTRIES,
337
+ ...fs.readdirSync(path.parse(process.cwd()).root),
338
+ ])];
328
339
  } catch {
329
340
  rootEntries = null;
330
341
  }
@@ -757,8 +768,10 @@ const LOOKUP_VARIABLE_RE =
757
768
  * The parser accepts only this grammar; anything else refuses the exemption:
758
769
  * - Commands separated by `;`, `&`, `&&`, `|`, `||`, `|&` or a newline.
759
770
  * - A command word of plain characters (`[A-Za-z0-9_.-]`) in PLAIN_COMMANDS.
760
- * So leading assignments of any form, leading redirects, here-strings,
761
- * keywords and compound syntax (`if`, `for`, `case`, `{`, `(`, `!`, `time`),
771
+ * Standalone decimal scalar assignments, numeric `for` lists, the exact
772
+ * `export GH_TOKEN=$(gh auth token)` form and `npm test` also qualify.
773
+ * Leading assignments attached to a command, leading redirects, here-strings,
774
+ * other keywords and compound syntax (`if`, `case`, `{`, `(`, `!`, `time`),
762
775
  * precommands, function definitions, unknown command words and quoted,
763
776
  * escaped or expanded command words all refuse.
764
777
  * - Argument words built from plain characters, `\` escapes, single quotes,
@@ -831,15 +844,20 @@ function skipPlainComment(p) {
831
844
 
832
845
  /**
833
846
  * Parses commands up to the end of the text or, in a `$(` substitution, up to
834
- * and including its `)`. Returns false on anything outside the grammar.
847
+ * and including its `)`, or through `done` in a numeric loop body.
848
+ * Returns false on anything outside the grammar.
835
849
  */
836
- function parsePlainList(p, inSubstitution) {
850
+ function parsePlainList(p, inSubstitution, inLoop = false) {
837
851
  for (;;) {
838
852
  skipPlainBlanks(p);
839
853
  const ch = p.text[p.i];
840
- if (ch === undefined) return !inSubstitution;
854
+ if (ch === undefined) return !inSubstitution && !inLoop;
855
+ if (inLoop && /^done(?=[\s;&|)]|$)/.test(p.text.slice(p.i))) {
856
+ p.i += 4;
857
+ return true;
858
+ }
841
859
  if (ch === ")") {
842
- if (!inSubstitution) return false;
860
+ if (!inSubstitution || inLoop) return false;
843
861
  p.i++;
844
862
  return true;
845
863
  }
@@ -852,11 +870,35 @@ function parsePlainList(p, inSubstitution) {
852
870
  }
853
871
  }
854
872
 
855
- /** Parses one simple command: a PLAIN_COMMANDS word, then words and redirects. */
873
+ /** Parses a recognised command, a standalone assignment or a numeric loop. */
856
874
  function parsePlainCommand(p) {
857
875
  if (p.text[p.i] === "#") return skipPlainComment(p);
876
+ const rest = p.text.slice(p.i);
877
+ // These are whole commands, never prefixes to a command whose lookup could
878
+ // change. No indexed, append, expanded or quoted assignment is recognised.
879
+ const assignment = /^[A-Za-z_]\w*=\d+(?=[ \t]*(?:[;\n]|$))/.exec(rest);
880
+ const tokenExport = /^export[ \t]+GH_TOKEN=\$\(gh[ \t]+auth[ \t]+token\)(?=[ \t]*(?:[;\n]|$))/.exec(rest);
881
+ if (assignment || tokenExport) {
882
+ p.i += (assignment || tokenExport)[0].length;
883
+ skipPlainBlanks(p);
884
+ return true;
885
+ }
886
+ // A finite list of decimal literals cannot evaluate shell code. Parse the
887
+ // entire body with the same reader rules; unknown syntax still refuses.
888
+ const loop = /^for[ \t]+([A-Za-z_]\w*)[ \t]+in[ \t]+\d+(?:[ \t]+\d+)*[ \t]*;[ \t]*do[ \t\n]+/.exec(rest);
889
+ if (loop) {
890
+ // A loop binds its variable too. Apply the assignment screen, including
891
+ // zsh special arrays such as `path`, which is tied to PATH.
892
+ if (LOOKUP_VARIABLE_RE.test(`${loop[1]}=`)) return false;
893
+ if (p.depth >= MAX_PLAIN_DEPTH) return false;
894
+ p.i += loop[0].length;
895
+ p.depth++;
896
+ const ok = parsePlainList(p, false, true);
897
+ p.depth--;
898
+ return ok;
899
+ }
858
900
  const word = readPlainWord(p);
859
- if (!word || !word.plain || !PLAIN_COMMANDS.has(word.value)) return false;
901
+ if (!word || !word.plain || (!PLAIN_COMMANDS.has(word.value) && word.value !== "npm")) return false;
860
902
  const args = [];
861
903
  for (;;) {
862
904
  skipPlainBlanks(p);
@@ -883,6 +925,7 @@ function parsePlainCommand(p) {
883
925
  if (p.text[p.i] === "<" || p.text[p.i] === ">") return false;
884
926
  args.push(arg);
885
927
  }
928
+ if (word.value === "npm") return args.length === 1 && args[0].plain && args[0].value === "test";
886
929
  if (word.value !== "printf") return true;
887
930
  // `printf -v name` assigns a variable, and zsh evaluates numeric arguments
888
931
  // as math, which can assign too. Allow only a literal text-only format.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sagentlab/navarch-runtime",
3
- "version": "0.1.152",
3
+ "version": "0.1.154",
4
4
  "description": "Navarch machine-side session manager: claims delivery tasks and runs them through local coding agents.",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",