@sagentlab/navarch-runtime 0.1.152 → 0.1.153

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.
@@ -757,8 +757,10 @@ const LOOKUP_VARIABLE_RE =
757
757
  * The parser accepts only this grammar; anything else refuses the exemption:
758
758
  * - Commands separated by `;`, `&`, `&&`, `|`, `||`, `|&` or a newline.
759
759
  * - 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`),
760
+ * Standalone decimal scalar assignments, numeric `for` lists, the exact
761
+ * `export GH_TOKEN=$(gh auth token)` form and `npm test` also qualify.
762
+ * Leading assignments attached to a command, leading redirects, here-strings,
763
+ * other keywords and compound syntax (`if`, `case`, `{`, `(`, `!`, `time`),
762
764
  * precommands, function definitions, unknown command words and quoted,
763
765
  * escaped or expanded command words all refuse.
764
766
  * - Argument words built from plain characters, `\` escapes, single quotes,
@@ -831,15 +833,20 @@ function skipPlainComment(p) {
831
833
 
832
834
  /**
833
835
  * 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.
836
+ * and including its `)`, or through `done` in a numeric loop body.
837
+ * Returns false on anything outside the grammar.
835
838
  */
836
- function parsePlainList(p, inSubstitution) {
839
+ function parsePlainList(p, inSubstitution, inLoop = false) {
837
840
  for (;;) {
838
841
  skipPlainBlanks(p);
839
842
  const ch = p.text[p.i];
840
- if (ch === undefined) return !inSubstitution;
843
+ if (ch === undefined) return !inSubstitution && !inLoop;
844
+ if (inLoop && /^done(?=[\s;&|)]|$)/.test(p.text.slice(p.i))) {
845
+ p.i += 4;
846
+ return true;
847
+ }
841
848
  if (ch === ")") {
842
- if (!inSubstitution) return false;
849
+ if (!inSubstitution || inLoop) return false;
843
850
  p.i++;
844
851
  return true;
845
852
  }
@@ -852,11 +859,35 @@ function parsePlainList(p, inSubstitution) {
852
859
  }
853
860
  }
854
861
 
855
- /** Parses one simple command: a PLAIN_COMMANDS word, then words and redirects. */
862
+ /** Parses a recognised command, a standalone assignment or a numeric loop. */
856
863
  function parsePlainCommand(p) {
857
864
  if (p.text[p.i] === "#") return skipPlainComment(p);
865
+ const rest = p.text.slice(p.i);
866
+ // These are whole commands, never prefixes to a command whose lookup could
867
+ // change. No indexed, append, expanded or quoted assignment is recognised.
868
+ const assignment = /^[A-Za-z_]\w*=\d+(?=[ \t]*(?:[;\n]|$))/.exec(rest);
869
+ const tokenExport = /^export[ \t]+GH_TOKEN=\$\(gh[ \t]+auth[ \t]+token\)(?=[ \t]*(?:[;\n]|$))/.exec(rest);
870
+ if (assignment || tokenExport) {
871
+ p.i += (assignment || tokenExport)[0].length;
872
+ skipPlainBlanks(p);
873
+ return true;
874
+ }
875
+ // A finite list of decimal literals cannot evaluate shell code. Parse the
876
+ // entire body with the same reader rules; unknown syntax still refuses.
877
+ const loop = /^for[ \t]+([A-Za-z_]\w*)[ \t]+in[ \t]+\d+(?:[ \t]+\d+)*[ \t]*;[ \t]*do[ \t\n]+/.exec(rest);
878
+ if (loop) {
879
+ // A loop binds its variable too. Apply the assignment screen, including
880
+ // zsh special arrays such as `path`, which is tied to PATH.
881
+ if (LOOKUP_VARIABLE_RE.test(`${loop[1]}=`)) return false;
882
+ if (p.depth >= MAX_PLAIN_DEPTH) return false;
883
+ p.i += loop[0].length;
884
+ p.depth++;
885
+ const ok = parsePlainList(p, false, true);
886
+ p.depth--;
887
+ return ok;
888
+ }
858
889
  const word = readPlainWord(p);
859
- if (!word || !word.plain || !PLAIN_COMMANDS.has(word.value)) return false;
890
+ if (!word || !word.plain || (!PLAIN_COMMANDS.has(word.value) && word.value !== "npm")) return false;
860
891
  const args = [];
861
892
  for (;;) {
862
893
  skipPlainBlanks(p);
@@ -883,6 +914,7 @@ function parsePlainCommand(p) {
883
914
  if (p.text[p.i] === "<" || p.text[p.i] === ">") return false;
884
915
  args.push(arg);
885
916
  }
917
+ if (word.value === "npm") return args.length === 1 && args[0].plain && args[0].value === "test";
886
918
  if (word.value !== "printf") return true;
887
919
  // `printf -v name` assigns a variable, and zsh evaluates numeric arguments
888
920
  // 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.153",
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",