neurastream 0.2.72 → 0.2.74

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.72",
3
+ "version": "0.2.74",
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": [
6
6
  "ai-agents",
@@ -1355,12 +1355,16 @@ function subRules(e: ToolEvent, input: Record<string, unknown>, paths: string[],
1355
1355
  for (const plan of plans) {
1356
1356
  const hit = paths.filter(p => !q.isOrchestrationPath(p, plans) && q.planCovers(plan, p, plans));
1357
1357
  if (!hit.length) continue;
1358
- if (plan.errors.length) return `plan ${plan.file} is invalid (${plan.errors.join("; ")}). Stop and report to Main.`;
1358
+ // An invalid plan stops code writes, not reads and not the repair of plan files: refusing those
1359
+ // too left a planner unable to fix the very errors the guard named (writes are checked before
1360
+ // the file is valid, so no valid text could ever land).
1361
+ const readOnly = cfg.guards.read_tools.includes(e.tool) || (cfg.guards.shell_tools.includes(e.tool) && !writes.length && !writesShellText(input, cfg));
1362
+ const planRepair = writes.length > 0 && writes.every(w => q.planAt(w, plans));
1363
+ if (plan.errors.length && !readOnly && !planRepair) return `plan ${plan.file} is invalid (${plan.errors.join("; ")}). Stop and report to Main.`;
1359
1364
  // P5c (plan 20261031_1207): reads and read-only shell calls skip the phase-0 blockers — a
1360
1365
  // failing blocker used to deny every read of a covered path and send the worker back blind.
1361
1366
  // The shell filter is the review lock's (writesShellText), so landing text keeps its blocker.
1362
- const readOnly = cfg.guards.read_tools.includes(e.tool) || (cfg.guards.shell_tools.includes(e.tool) && !writes.length && !writesShellText(input, cfg));
1363
- if (!readOnly) {
1367
+ if (!readOnly && !planRepair) {
1364
1368
  const why = runBlockers(plan, hit, e, cfg);
1365
1369
  if (why) return why;
1366
1370
  }
@@ -92,12 +92,17 @@ export function wipBackup(
92
92
  const mainWt = top.stdout ? top.stdout.split("\n")[0]!.slice(9) : repo;
93
93
  const rkey = keyOf(mainWt, cfg.paths.home);
94
94
  const specs: { src: string; dst: string }[] = [];
95
- const heads = gitOrFail(failed, repo, ["for-each-ref", "--format=%(refname:short)", "refs/heads"]);
95
+ const heads = gitOrFail(failed, repo, ["for-each-ref", "--format=%(refname)", "refs/heads"]);
96
96
  if (!heads) continue;
97
- for (const b of heads.stdout.split("\n").filter(Boolean)) {
98
- const n = gitOrFail(failed, repo, ["rev-list", "--count", b, "--not", "--remotes"]);
97
+ for (const ref of heads.stdout.split("\n").filter(Boolean)) {
98
+ // Full refname and a trailing `--`: a branch named like an existing file (ops/x) is not
99
+ // "ambiguous argument" — that failure must not drop the branch from the backup.
100
+ const n = gitOrFail(failed, repo, ["rev-list", "--count", ref, "--not", "--remotes", "--"]);
99
101
  if (!n) continue;
100
- if (/^\d+$/.test(n.stdout) && Number(n.stdout) > 0) specs.push({ src: `refs/heads/${b}`, dst: `refs/heads/${rkey}/${b}` });
102
+ if (/^\d+$/.test(n.stdout) && Number(n.stdout) > 0) {
103
+ const branch = ref.slice("refs/heads/".length);
104
+ specs.push({ src: ref, dst: `refs/heads/${rkey}/${branch}` });
105
+ }
101
106
  }
102
107
  const wips = gitOrFail(failed, repo, ["for-each-ref", "--sort=-refname", "--format=%(refname)", "refs/wip"]);
103
108
  if (!wips) continue;
@@ -1,7 +1,21 @@
1
- import { existsSync, readdirSync, realpathSync, statSync } from "node:fs";
2
- import { join, relative } from "node:path";
1
+ import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
2
+ import { join, relative, resolve } from "node:path";
3
3
  import type { Config } from "./config.ts";
4
4
 
5
+ /** True when `dir/.git` is a file naming a gitdir that no longer exists: no repo is left to save. */
6
+ export function deadGitfile(dir: string): boolean {
7
+ const gitPath = join(dir, ".git");
8
+ let first: string | undefined;
9
+ try {
10
+ if (!statSync(gitPath).isFile()) return false;
11
+ first = readFileSync(gitPath, "utf8").split("\n")[0];
12
+ } catch {
13
+ return false; // an unreadable .git file is not our call: the repo stays and its failure is real
14
+ }
15
+ if (!first?.startsWith("gitdir: ")) return false;
16
+ return !existsSync(resolve(dir, first.slice("gitdir: ".length).trim()));
17
+ }
18
+
5
19
  export function keyOf(path: string, home: string): string {
6
20
  const realHome = existsSync(home) ? realpathSync(home) : home;
7
21
  const realPath = existsSync(path) ? realpathSync(path) : path;
@@ -27,6 +41,8 @@ function walkFolder(dir: string, currentDepth: number, maxDepth: number, out: st
27
41
  }
28
42
  if (!st.isDirectory()) continue;
29
43
 
44
+ // A dead worktree dir has no repo left to save: not pushed as a repo, not recursed into.
45
+ if (deadGitfile(fullPath)) continue;
30
46
  if (existsSync(join(fullPath, ".git"))) {
31
47
  out.push(fullPath);
32
48
  } else {
@@ -48,6 +64,7 @@ export function wipRepos(cfg: Config): string[] {
48
64
  }
49
65
  if (!st.isDirectory()) continue;
50
66
 
67
+ if (deadGitfile(root)) continue;
51
68
  if (existsSync(join(root, ".git"))) {
52
69
  out.push(root);
53
70
  } else {
@@ -5,7 +5,7 @@ import type { Config } from "./config.ts";
5
5
  import { nowSec, strftime } from "./clock.ts";
6
6
  import { printText } from "./help.ts";
7
7
  import { pyFloatStr } from "./pyfmt.ts";
8
- import { cmd } from "./proc.ts";
8
+ import { cmd, gitRaw } from "./proc.ts";
9
9
  import { failureLine, gitOrFail, realpathOrFail, recordWipRun } from "./wip-fail.ts";
10
10
  import { keyOf, wipRepos } from "./wip-roots.ts";
11
11
 
@@ -102,9 +102,14 @@ export function wipSnapshot(args: string[], cfg: Config): number {
102
102
  seen.set(common, repo);
103
103
  const list = gitOrFail(failed, repo, ["worktree", "list", "--porcelain"]);
104
104
  if (!list) continue;
105
- for (const line of list.stdout.split("\n")) {
106
- if (line.startsWith("worktree ") && existsSync(line.slice(9)) && statSync(line.slice(9)).isDirectory()) {
107
- worktrees.push(line.slice(9));
105
+ // Blocks (blank-line separated) match `worktree list --porcelain`; the bare entry of a
106
+ // bare main repo carries a `bare` line and is no worktree to snapshot.
107
+ for (const block of list.stdout.split("\n\n")) {
108
+ if (block.split("\n").some(line => line === "bare")) continue;
109
+ for (const line of block.split("\n")) {
110
+ if (line.startsWith("worktree ") && existsSync(line.slice(9)) && statSync(line.slice(9)).isDirectory()) {
111
+ worktrees.push(line.slice(9));
112
+ }
108
113
  }
109
114
  }
110
115
  }
@@ -112,8 +117,12 @@ export function wipSnapshot(args: string[], cfg: Config): number {
112
117
  const saved: { wt: string; br: string; n: number; sk: number; ref: string }[] = [];
113
118
  let same = 0;
114
119
  for (const wt of worktrees) {
115
- const head = gitOrFail(failed, wt, ["rev-parse", "--verify", "HEAD"]);
116
- if (!head) continue;
120
+ // Unborn HEAD (no commit yet): nothing to save, skipped quietly. Any other git failure is real.
121
+ const head = gitRaw(wt, ["rev-parse", "--verify", "-q", "HEAD"]);
122
+ if (head.code !== 0) {
123
+ if (!(head.code === 1 && head.stderr === "")) failed.push(failureLine(wt, "git rev-parse --verify HEAD", head.stderr));
124
+ continue;
125
+ }
117
126
  const st = gitOrFail(failed, wt, ["status", "--porcelain"]);
118
127
  if (!st || !st.stdout) continue;
119
128
  const gitdir = gitOrFail(failed, wt, ["rev-parse", "--absolute-git-dir"]);