neurastream 0.2.5 → 0.2.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neurastream",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Guardrails for running many AI coding agents at once: plan queue, blockers, call budgets, provider caps, scoring, merge-verified close.",
5
5
  "keywords": ["ai-agents", "coding-agents", "orchestration", "guardrails", "omp", "bun", "cli"],
6
6
  "homepage": "https://github.com/umiddey/neurastream#readme",
@@ -140,7 +140,8 @@ function matchesPath(p: string, glob: string, call: BlockerCall): boolean {
140
140
  // ---- Shell: a quote-aware splitter, not a shell parser ---------------------------------------
141
141
  // Splits on `;`, `&&`, `||`, `|`, `&`, `(`, `)` and newlines outside quotes. Each word keeps its
142
142
  // quote-removed text and whether any part was quoted; output-redirection targets are kept apart
143
- // from the words; heredoc bodies are dropped; the inside of `$(…)` and backticks becomes segments.
143
+ // from the words; heredoc bodies are kept on their opening segment; the inside of `$(…)` and
144
+ // backticks becomes segments.
144
145
 
145
146
  export interface ShellWord {
146
147
  /** Text with quotes and escapes removed; a substitution contributes nothing (its segments are listed). */
@@ -156,6 +157,8 @@ export interface ShellSegment {
156
157
  words: ShellWord[];
157
158
  /** Targets of output redirections: `>`, `>>`, `>|`, `&>`, `&>>`, `<>`, and `>&file`. */
158
159
  writes: string[];
160
+ /** Bodies of the heredocs this segment opens; for an interpreter they are its code. */
161
+ bodies: string[];
159
162
  }
160
163
 
161
164
  type WordBuf = { text: string; quoted: boolean; start: number };
@@ -176,7 +179,7 @@ function scan(src: string, out: ShellSegment[]): void {
176
179
  redir: RedirKind | null;
177
180
  tabs: boolean;
178
181
  heredocs: { delim: string; tabs: boolean }[];
179
- } = { seg: { words: [], writes: [] }, word: null, redir: null, tabs: false, heredocs: [] };
182
+ } = { seg: { words: [], writes: [], bodies: [] }, word: null, redir: null, tabs: false, heredocs: [] };
180
183
  let i = 0;
181
184
 
182
185
  const ensure = (): WordBuf => {
@@ -198,22 +201,27 @@ function scan(src: string, out: ShellSegment[]): void {
198
201
  if (kind === "write" || (kind === "dup" && !/^(\d+|-)$/.test(word.text))) st.seg.writes.push(word.text);
199
202
  else if (kind === "heredoc") st.heredocs.push({ delim: word.text, tabs: st.tabs });
200
203
  };
201
- const endSeg = (end: number): void => {
204
+ const endSeg = (end: number): ShellSegment | null => {
202
205
  endWord(end);
203
206
  st.redir = null;
204
- if (st.seg.words.length || st.seg.writes.length) out.push(st.seg);
205
- st.seg = { words: [], writes: [] };
207
+ const ended = st.seg.words.length || st.seg.writes.length ? st.seg : null;
208
+ if (ended) out.push(ended);
209
+ st.seg = { words: [], writes: [], bodies: [] };
210
+ return ended;
206
211
  };
207
- // Skips the bodies of the heredocs opened on the line before `from`; returns the index after them.
208
- const skipHeredocs = (from: number): number => {
212
+ // Skips the bodies of the heredocs opened on the line before `from`, keeping their text in
213
+ // `into`; returns the index after them.
214
+ const skipHeredocs = (from: number, into: string[]): number => {
209
215
  let j = from;
210
216
  for (const h of st.heredocs) {
217
+ const start = j;
211
218
  while (j < n) {
212
219
  const e = src.indexOf("\n", j);
213
220
  const line = src.slice(j, e < 0 ? n : e);
214
221
  j = e < 0 ? n : e + 1;
215
222
  if ((h.tabs ? line.replace(/^\t+/, "") : line) === h.delim) break;
216
223
  }
224
+ into.push(src.slice(start, j));
217
225
  }
218
226
  st.heredocs = [];
219
227
  return j;
@@ -281,8 +289,8 @@ function scan(src: string, out: ShellSegment[]): void {
281
289
  } else if (c === "#" && !st.word) {
282
290
  while (i < n && src.charAt(i) !== "\n") i++;
283
291
  } else if (c === "\n") {
284
- endSeg(i);
285
- i = skipHeredocs(i + 1);
292
+ const ended = endSeg(i);
293
+ i = skipHeredocs(i + 1, ended ? ended.bodies : []);
286
294
  } else if (c === ";" || c === "(" || c === ")") {
287
295
  endSeg(i);
288
296
  i++;
@@ -400,7 +408,10 @@ const INTERPRETERS: Record<string, true> = {
400
408
  const GIT_VALUE_OPTS: Record<string, true> = { "-C": true, "-c": true, "--git-dir": true, "--work-tree": true, "--namespace": true };
401
409
  const MUTATING_NAMES: Record<string, true> = { rm: true, mv: true, truncate: true, tee: true, patch: true };
402
410
  const GIT_MUTATING: Record<string, true> = { rm: true, mv: true, checkout: true, restore: true };
403
- const CODE_WRITE = /writeFile|Bun\.write|unlink/;
411
+ // Code-write forms, one list for shell and eval: the code parts of queue/lib.ts MUTATING plus
412
+ // Ruby's File.write. Never fork a second list.
413
+ const CODE_WRITE =
414
+ /writeFile|appendFile|Bun\.write|unlink|rmSync|\.write_text\(|\.write_bytes\(|\bopen\([^)]*,\s*["'][wax]b?\+?["']|shutil\.|os\.(remove|rename|replace|unlink|chmod)|\.writelines\(|File\.write/;
404
415
 
405
416
  interface ShellCommand {
406
417
  name: string;
@@ -490,7 +501,7 @@ function mutationTargets(seg: ShellSegment): string[] {
490
501
  if (mutating) out.push(...ops);
491
502
  else if (cmd.name === "cp" && ops.length) out.push(ops[ops.length - 1] ?? "");
492
503
  else if (cmd.name === "sed" && cmd.args.some((a) => /^-[a-zA-Z]*i|^--in-place/.test(a.text))) out.push(...ops.slice(1));
493
- const raw = seg.words.map((w) => w.raw).join(" ");
504
+ const raw = [...seg.words.map((w) => w.raw), ...seg.bodies].join(" ");
494
505
  if (INTERPRETERS[cmd.name] === true && CODE_WRITE.test(raw)) {
495
506
  out.push(...raw.split(/[\s;&|<>(),'"]+/).filter((t) => t !== "" && !t.startsWith("-")));
496
507
  }
@@ -585,7 +596,8 @@ export function denyPath(env: BlockerEnv): void {
585
596
  let targets: string[] = [];
586
597
  if (env.writes) targets = (env.call.paths ?? []).filter((p) => !MAIN_PLAN_FILE.test(p));
587
598
  else if (env.call.tool === "eval") {
588
- if (CODE_MUTATING.test(env.command)) targets = [...(env.call.paths ?? []), ...evalPaths(env)];
599
+ if (CODE_MUTATING.test(env.command) || CODE_WRITE.test(env.command))
600
+ targets = [...(env.call.paths ?? []), ...evalPaths(env)];
589
601
  } else if (env.shell) targets = shellTargets(env);
590
602
  for (const p of targets) {
591
603
  for (const g of env.args) {