@mu-crew/mu 3.8.0 → 3.9.0

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.
@@ -501,7 +501,7 @@ ${task}` : task,
501
501
  };
502
502
  } finally {
503
503
  freeSlot();
504
- if (queuedAs) drain();
504
+ drain();
505
505
  }
506
506
  }
507
507
  pi.registerTool({
@@ -711,25 +711,31 @@ function readSkill() {
711
711
  }
712
712
  return void 0;
713
713
  }
714
+ var ENV_ASSIGN = /^[A-Za-z_][A-Za-z0-9_]*=/;
715
+ function muArgs(words) {
716
+ let at = 0;
717
+ while (at < words.length && ENV_ASSIGN.test(words[at] ?? "")) at++;
718
+ const cmd = words[at];
719
+ if (cmd !== "mu" && !cmd?.endsWith("/mu")) return void 0;
720
+ return words.slice(at + 1);
721
+ }
714
722
  function dispatchedWorkstreams(command) {
715
723
  const found = /* @__PURE__ */ new Set();
716
724
  for (const words of shellSegments(command)) {
717
- const at = words.findIndex((w) => w === "mu" || w.endsWith("/mu"));
718
- if (at < 0) continue;
719
- const [noun, verb] = [words[at + 1], words[at + 2]];
720
- const isSendSpawn = noun === "agent" && (verb === "send" || verb === "spawn");
721
- const isClaimFor = noun === "task" && verb === "claim" && words.includes("--for");
722
- if (!isSendSpawn && !isClaimFor) continue;
725
+ const args = muArgs(words);
726
+ if (args === void 0) continue;
727
+ const claim = claimOf(args);
728
+ if (claim !== void 0) {
729
+ if (claim.ws !== "scratch") found.add(claim.ws);
730
+ continue;
731
+ }
732
+ if (args[0] !== "agent" || args[1] !== "send" && args[1] !== "spawn") continue;
723
733
  let ws = "";
724
- for (let k = at + 3; k < words.length; k++) {
725
- const w = words[k] ?? "";
726
- if (w === "-w" || w === "--workstream") ws = words[k + 1] ?? "";
734
+ for (let k = 2; k < args.length; k++) {
735
+ const w = args[k] ?? "";
736
+ if (w === "-w" || w === "--workstream") ws = args[k + 1] ?? "";
727
737
  else if (w.startsWith("--workstream=")) ws = w.slice("--workstream=".length);
728
738
  }
729
- if (ws === "" && isClaimFor) {
730
- const ref = words[at + 3] ?? "";
731
- if (ref.includes("/")) ws = ref.split("/")[0] ?? "";
732
- }
733
739
  if (ws !== "scratch") found.add(ws);
734
740
  }
735
741
  return found.size > 0 ? [...found] : void 0;
@@ -739,6 +745,8 @@ function shellSegments(command) {
739
745
  const segs = [];
740
746
  let words = [];
741
747
  let word;
748
+ const heredocs = [];
749
+ let arithEnd = -1;
742
750
  const endWord = () => {
743
751
  if (word !== void 0) words.push(word);
744
752
  word = void 0;
@@ -748,6 +756,18 @@ function shellSegments(command) {
748
756
  if (words.length > 0) segs.push(words);
749
757
  words = [];
750
758
  };
759
+ const skipHeredocs = (i) => {
760
+ for (const h of heredocs.splice(0)) {
761
+ while (i < command.length) {
762
+ const eol = command.indexOf("\n", i + 1);
763
+ const end = eol < 0 ? command.length : eol;
764
+ const line = command.slice(i + 1, end);
765
+ i = end;
766
+ if ((h.strip ? line.replace(/^\t+/, "") : line) === h.delim) break;
767
+ }
768
+ }
769
+ return i;
770
+ };
751
771
  for (let i = 0; i < command.length; i++) {
752
772
  const c = command[i] ?? "";
753
773
  if (c === "'" || c === '"') {
@@ -755,11 +775,34 @@ function shellSegments(command) {
755
775
  const end = close < 0 ? command.length : close;
756
776
  word = (word ?? "") + command.slice(i + 1, end);
757
777
  i = end;
778
+ } else if (c === "\\" && command[i + 1] === "\n") {
779
+ i++;
758
780
  } else if (c === "\\" && i + 1 < command.length) {
759
781
  word = (word ?? "") + command[++i];
782
+ } else if (c === "#" && word === void 0) {
783
+ const eol = command.indexOf("\n", i);
784
+ i = (eol < 0 ? command.length : eol) - 1;
785
+ } else if (c === "(" && command[i + 1] === "(" && i > arithEnd) {
786
+ arithEnd = arithmeticEnd(command, i);
787
+ word = `${word ?? ""}((`;
788
+ i++;
789
+ } else if (command.startsWith("<<<", i)) {
790
+ endWord();
791
+ i += 2;
792
+ } else if (c === "<" && command[i + 1] === "<" && i > arithEnd) {
793
+ endWord();
794
+ const m = /^<<(-?)[ \t]*('([^']*)'|"([^"]*)"|[^\s;&|<>()]+)/.exec(command.slice(i));
795
+ if (!m) {
796
+ i++;
797
+ continue;
798
+ }
799
+ const delim = m[3] ?? m[4] ?? (m[2] ?? "").replace(/\\/g, "");
800
+ heredocs.push({ delim, strip: m[1] === "-" });
801
+ i += m[0].length - 1;
760
802
  } else if (c === ";" || c === "|" || c === "\n" || c === "&" && command[i + 1] === "&") {
761
803
  if (c !== ";" && c !== "\n" && command[i + 1] === c) i++;
762
804
  endSeg();
805
+ if (c === "\n" && heredocs.length > 0) i = skipHeredocs(i);
763
806
  } else if (/\s/.test(c)) {
764
807
  endWord();
765
808
  } else {
@@ -769,30 +812,53 @@ function shellSegments(command) {
769
812
  endSeg();
770
813
  return segs;
771
814
  }
815
+ function arithmeticEnd(command, open) {
816
+ let depth = 0;
817
+ for (let i = open + 2; i < command.length; i++) {
818
+ const c = command[i];
819
+ if (c === "'" || c === '"') {
820
+ const close = command.indexOf(c, i + 1);
821
+ if (close < 0) return -1;
822
+ i = close;
823
+ } else if (c === "\\") {
824
+ i++;
825
+ } else if (c === "(") {
826
+ depth++;
827
+ } else if (c === ")") {
828
+ if (depth > 0) depth--;
829
+ else return command[i + 1] === ")" ? i + 1 : -1;
830
+ }
831
+ }
832
+ return -1;
833
+ }
834
+ function claimOf(args) {
835
+ if (args[0] !== "task" || args[1] !== "claim") return void 0;
836
+ let ws = "";
837
+ let id;
838
+ let isFor = false;
839
+ for (let k = 2; k < args.length; k++) {
840
+ const w = args[k] ?? "";
841
+ const [opt, eq] = w.startsWith("--") && w.includes("=") ? w.split("=", 2) : [w, void 0];
842
+ if (opt === "--for" || opt === "-f") isFor = true;
843
+ if (opt === "-w" || opt === "--workstream") ws = eq ?? args[k + 1] ?? "";
844
+ if (CLAIM_VALUE_OPTS.has(opt ?? "")) {
845
+ if (eq === void 0) k++;
846
+ } else if (id === void 0 && !w.startsWith("-")) id = w;
847
+ }
848
+ if (!isFor || id === void 0) return void 0;
849
+ const slash = id.indexOf("/");
850
+ if (slash >= 0) {
851
+ if (ws === "") ws = id.slice(0, slash);
852
+ id = id.slice(slash + 1);
853
+ }
854
+ return { ws, id };
855
+ }
772
856
  function dispatchedTasks(command) {
773
857
  const out = [];
774
858
  for (const words of shellSegments(command)) {
775
- if (words[0] !== "mu" && !words[0]?.endsWith("/mu")) continue;
776
- if (words[1] !== "task" || words[2] !== "claim") continue;
777
- let ws = "";
778
- let id;
779
- let isFor = false;
780
- for (let k = 3; k < words.length; k++) {
781
- const w = words[k] ?? "";
782
- const [opt, eq] = w.startsWith("--") && w.includes("=") ? w.split("=", 2) : [w, void 0];
783
- if (opt === "--for" || opt === "-f") isFor = true;
784
- if (opt === "-w" || opt === "--workstream") ws = eq ?? words[k + 1] ?? "";
785
- if (CLAIM_VALUE_OPTS.has(opt ?? "")) {
786
- if (eq === void 0) k++;
787
- } else if (id === void 0 && !w.startsWith("-")) id = w;
788
- }
789
- if (!isFor || id === void 0) continue;
790
- const slash = id.indexOf("/");
791
- if (slash >= 0) {
792
- if (ws === "") ws = id.slice(0, slash);
793
- id = id.slice(slash + 1);
794
- }
795
- if (ws !== "scratch") out.push({ ws, id });
859
+ const args = muArgs(words);
860
+ const claim = args === void 0 ? void 0 : claimOf(args);
861
+ if (claim !== void 0 && claim.ws !== "scratch") out.push(claim);
796
862
  }
797
863
  return out;
798
864
  }
@@ -994,7 +1060,7 @@ function registerRefuteNudge(pi, run = defaultRunner(), nested = notNested) {
994
1060
  }
995
1061
 
996
1062
  // extension/mu-pi.ts
997
- var EXT_VERSION = true ? "3.8.0" : void 0;
1063
+ var EXT_VERSION = true ? "3.9.0" : void 0;
998
1064
  var FRESH_COMMAND = "mu-fresh";
999
1065
  var FRESH_TIMEOUT_MS = 3e4;
1000
1066
  function commandName(name) {