@yemi33/minions 0.1.2359 → 0.1.2361

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/engine/github.js CHANGED
@@ -1161,7 +1161,7 @@ async function pollPrStatus(config) {
1161
1161
  try {
1162
1162
  const mergeMethod = ['squash', 'merge', 'rebase'].includes(config.engine?.prMergeMethod) ? config.engine.prMergeMethod : 'squash';
1163
1163
  // P-a7c4d2e8 (F1): argv-form merge call — eliminates shell interpolation of slug/prNum/mergeMethod.
1164
- await shared.shellSafeGh(['pr', 'merge', String(prNum), `--${mergeMethod}`, '--repo', shared.validateGhSlug(slug), '--delete-branch'], { timeout: 30000, maxBuffer: GH_MAX_BUFFER });
1164
+ await shared.shellSafeGh(['pr', 'merge', String(prNum), `--${mergeMethod}`, '--repo', shared.validateGhSlug(slug), '--delete-branch', '--admin'], { timeout: 30000, maxBuffer: GH_MAX_BUFFER });
1165
1165
  pr._autoCompleted = true;
1166
1166
  log('info', `Auto-completed PR ${pr.id}: builds green + review approved → merged (${mergeMethod})`);
1167
1167
  updated = true;
@@ -1163,18 +1163,33 @@ async function discoverPipelineWork(config) {
1163
1163
  }).join('\n\n');
1164
1164
  }
1165
1165
 
1166
- // Scan for inbox/archive notes created by this stage's agents
1166
+ // Scan for inbox/archive notes created by this stage's agents.
1167
+ // stageWiIds are scoped to this run (work-item ids embed the unique
1168
+ // run id), so matching on them alone is safe. stage.id/pipeline.id
1169
+ // are STATIC across every run of a recurring pipeline, so a bare
1170
+ // substring match on them would match every historical note ever
1171
+ // written for that stage/pipeline name (W-mrcr6do0001404e6). Keep
1172
+ // that fallback only as a safety net for notes that don't embed a
1173
+ // WI id, and gate it on mtime >= this run's startedAt so it can
1174
+ // never pick up notes older than the current run.
1167
1175
  try {
1168
1176
  const notesDirs = [
1169
1177
  NOTES_INBOX_DIR,
1170
1178
  NOTES_ARCHIVE_DIR,
1171
1179
  ];
1172
1180
  const stageWiIds = stageState.artifacts?.workItems || [];
1181
+ const runStartedAt = activeRun.startedAt ? new Date(activeRun.startedAt).getTime() : 0;
1173
1182
  const notes = [];
1174
1183
  for (const dir of notesDirs) {
1175
1184
  for (const f of safeReadDir(dir).filter(n => n.endsWith('.md'))) {
1176
- if (stageWiIds.some(id => f.includes(id)) || f.includes(stage.id) || f.includes(pipeline.id)) {
1185
+ if (stageWiIds.some(id => f.includes(id))) {
1177
1186
  notes.push(f);
1187
+ continue;
1188
+ }
1189
+ if (f.includes(stage.id) || f.includes(pipeline.id)) {
1190
+ let mtime = 0;
1191
+ try { mtime = fs.statSync(path.join(dir, f)).mtimeMs; } catch { /* file may have vanished */ }
1192
+ if (mtime >= runStartedAt) notes.push(f);
1178
1193
  }
1179
1194
  }
1180
1195
  }
package/engine.js CHANGED
@@ -1023,22 +1023,44 @@ async function runWorktreeAdd(rootDir, worktreePath, addArgs, gitOpts, worktreeC
1023
1023
  // origin/<mainRef>; the stale-HEAD guard at the top of spawn-agent then
1024
1024
  // trips on every dispatch and the cooldown machinery starves the PR.
1025
1025
  //
1026
- // Returns true only on a confirmed advertised head; ls-remote exit code 2
1027
- // (no matching ref) and any other failure (network/auth) return false so
1028
- // the caller falls back to the existing `-b origin/<mainRef>` path.
1026
+ // Returns true only on a confirmed advertised head. ls-remote exit code 2
1027
+ // (no matching ref a clean, authoritative "branch does not exist upstream")
1028
+ // returns false so the caller falls back to the `-b origin/<mainRef>` path.
1029
+ //
1030
+ // Any OTHER failure (network blip, transient auth/401, ADO throttle, timeout)
1031
+ // is NOT a confirmed absence — conflating the two caused #767: a transient
1032
+ // probe failure against a branch that genuinely exists on origin (e.g. a
1033
+ // PR-author's real branch) silently took the fresh-branch fallback and
1034
+ // forked a divergent local branch under the same name instead of retrying.
1035
+ // We retry once with a short backoff (mirroring `_fetchWithTransientRetry`);
1036
+ // if the retry still doesn't cleanly resolve to "not found", we throw so the
1037
+ // caller does NOT treat this as a confirmed absence.
1029
1038
  async function probeBranchOnRemote(rootDir, branchName, gitOpts) {
1030
1039
  if (!branchName || !rootDir) return false;
1040
+ const _attemptProbe = () => shared.shellSafeGit(
1041
+ ['ls-remote', '--exit-code', '--heads', 'origin', branchName],
1042
+ { ...gitOpts, cwd: rootDir, timeout: 10000 },
1043
+ );
1031
1044
  try {
1032
- await shared.shellSafeGit(
1033
- ['ls-remote', '--exit-code', '--heads', 'origin', branchName],
1034
- { ...gitOpts, cwd: rootDir, timeout: 10000 },
1035
- );
1045
+ await _attemptProbe();
1036
1046
  return true;
1037
1047
  } catch (e) {
1038
- if (e && e.code !== 2) {
1039
- log('warn', `probeBranchOnRemote: ls-remote --heads origin ${branchName} failed: ${(e.message || '').split('\n')[0].slice(0, 200)} — treating as not-on-remote`);
1048
+ if (e && e.code === 2) return false; // clean, authoritative "not found"
1049
+ const firstErrMsg = adoGitAuth.redactBearer(String(e?.message || e)).split('\n')[0].slice(0, 200);
1050
+ log('warn', `probeBranchOnRemote: ls-remote --heads origin ${branchName} failed (${firstErrMsg}) — retrying once after 1.5s before giving up`);
1051
+ await new Promise(r => setTimeout(r, 1500));
1052
+ try {
1053
+ await _attemptProbe();
1054
+ return true;
1055
+ } catch (e2) {
1056
+ if (e2 && e2.code === 2) return false; // clean, authoritative "not found" on retry
1057
+ const retryErrMsg = adoGitAuth.redactBearer(String(e2?.message || e2)).split('\n')[0].slice(0, 200);
1058
+ log('warn', `probeBranchOnRemote: ls-remote --heads origin ${branchName} retry also failed (${retryErrMsg}) — cannot confirm branch absence, surfacing error`);
1059
+ const probeErr = new Error(`probeBranchOnRemote: could not determine whether origin has ${branchName} after retry: ${retryErrMsg}`);
1060
+ probeErr._probeFailed = true;
1061
+ probeErr._cause = e2;
1062
+ throw probeErr;
1040
1063
  }
1041
- return false;
1042
1064
  }
1043
1065
  }
1044
1066
 
@@ -6547,23 +6569,33 @@ function restoreHijackedOperatorCheckouts(config) {
6547
6569
  if (!localPath || !fs.existsSync(localPath)) continue;
6548
6570
  if (shared.resolveCheckoutMode(project) === shared.CHECKOUT_MODES.LIVE) continue; // live-mode: feature branch is intentional
6549
6571
  const main = project.mainBranch || 'main';
6550
- if (String(execSilent('git rev-parse --is-inside-work-tree', { cwd: localPath }) || '').trim() !== 'true') continue;
6551
- const cur = String(execSilent('git rev-parse --abbrev-ref HEAD', { cwd: localPath }) || '').trim();
6572
+ const opts = { cwd: localPath };
6573
+ // W-mrcvh5hw000o6cf1: use the argv-form (shell: false) git helper instead of
6574
+ // execSilent(). execSilent() shells out via cmd.exe, which cannot chdir into
6575
+ // a UNC path (`//wsl.localhost/...`, `\\server\share\...`) — it silently
6576
+ // falls back to the Windows directory and every git call then fails with
6577
+ // "fatal: not a git repository", every tick, forever, for WSL/UNC-hosted
6578
+ // projects. shellSafeGitSync spawns git.exe directly (execFileSync,
6579
+ // shell:false) so `cwd` is honored even for UNC paths.
6580
+ let isRepo;
6581
+ try { isRepo = String(shared.shellSafeGitSync(['rev-parse', '--is-inside-work-tree'], opts) || '').trim(); }
6582
+ catch { continue; } // not a git repo (or transiently unreachable) — nothing to restore, skip quietly
6583
+ if (isRepo !== 'true') continue;
6584
+ const cur = String(shared.shellSafeGitSync(['rev-parse', '--abbrev-ref', 'HEAD'], opts) || '').trim();
6552
6585
  if (!cur || cur === 'HEAD' || cur === main) continue; // on main or detached — fine
6553
- const gitDir = String(execSilent('git rev-parse --git-dir', { cwd: localPath }) || '').trim();
6586
+ const gitDir = String(shared.shellSafeGitSync(['rev-parse', '--git-dir'], opts) || '').trim();
6554
6587
  const absGitDir = gitDir ? (path.isAbsolute(gitDir) ? gitDir : path.join(localPath, gitDir)) : path.join(localPath, '.git');
6555
6588
  const mergeStuck = fs.existsSync(path.join(absGitDir, 'MERGE_HEAD'));
6556
6589
  const rebaseStuck = fs.existsSync(path.join(absGitDir, 'rebase-merge')) || fs.existsSync(path.join(absGitDir, 'rebase-apply'));
6557
6590
  if (!mergeStuck && !rebaseStuck && !_FLEET_BRANCH_RE.test(cur)) continue; // likely a human's deliberate checkout — leave it
6558
6591
  const why = mergeStuck ? ' (stuck merge)' : rebaseStuck ? ' (stuck rebase)' : ' (fleet branch in live checkout)';
6559
6592
  log('warn', `Operator checkout for ${project.name} is on '${cur}'${why}; worktree-mode requires ${main} — restoring`);
6560
- const opts = { cwd: localPath };
6561
- if (mergeStuck) execSilent('git merge --abort', opts);
6562
- if (rebaseStuck) execSilent('git rebase --abort', opts);
6563
- execSilent('git reset --hard HEAD', opts); // drop uncommitted hijack state; branch commits stay on the ref
6593
+ if (mergeStuck) shared.shellSafeGitSync(['merge', '--abort'], opts);
6594
+ if (rebaseStuck) shared.shellSafeGitSync(['rebase', '--abort'], opts);
6595
+ shared.shellSafeGitSync(['reset', '--hard', 'HEAD'], opts); // drop uncommitted hijack state; branch commits stay on the ref
6564
6596
  try { shared.validateGitRef(main); } catch (ve) { throw new Error(`restoreHijackedOperatorCheckouts: invalid mainBranch ${JSON.stringify(main)}: ${ve.message}`); }
6565
6597
  shared.shellSafeGitSync(['checkout', main], opts);
6566
- const now = String(execSilent('git rev-parse --abbrev-ref HEAD', { cwd: localPath }) || '').trim();
6598
+ const now = String(shared.shellSafeGitSync(['rev-parse', '--abbrev-ref', 'HEAD'], opts) || '').trim();
6567
6599
  if (now === main) {
6568
6600
  try {
6569
6601
  writeInboxAlert(`operator-checkout-restored-${project.name}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yemi33/minions",
3
- "version": "0.1.2359",
3
+ "version": "0.1.2361",
4
4
  "description": "Multi-agent AI dev team that runs from ~/.minions/ — five autonomous agents share a single engine, dashboard, and knowledge base",
5
5
  "bin": {
6
6
  "minions": "bin/minions.js"