sumo-agents 0.7.2 → 0.8.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.
package/src/worktree.mjs CHANGED
@@ -2,6 +2,7 @@ import { execFileSync, spawnSync } from 'node:child_process';
2
2
  import { copyFileSync, cpSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, symlinkSync } from 'node:fs';
3
3
  import { dirname, isAbsolute, join, relative, sep } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
+ import { ownGit } from './sandbox.mjs';
5
6
  import { DIFF } from './verify.mjs';
6
7
 
7
8
  /**
@@ -10,13 +11,13 @@ import { DIFF } from './verify.mjs';
10
11
  * branches, and what the work changed is brought back to the project at the end. Nothing here knows about jobs.
11
12
  */
12
13
 
13
- /** Sumo's own git calls: no hook of the user's runs, nothing is signed, and a commit has an author where git has no identity. */
14
- const OWN = ['-c', 'core.hooksPath=/dev/null', '-c', 'commit.gpgsign=false', '-c', 'user.name=sumo', '-c', 'user.email=sumo@localhost'];
14
+ /** Sumo's own git calls: nothing the project's git files name runs (`ownGit`), nothing is signed, and a commit has an author where git has no identity. */
15
+ const OWN = ['-c', 'commit.gpgsign=false', '-c', 'user.name=sumo', '-c', 'user.email=sumo@localhost'];
15
16
 
16
- const git = (root, args) => execFileSync('git', ['-C', root, ...OWN, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 256 * 1024 * 1024 }).trim();
17
+ const git = (root, args) => execFileSync('git', ['-C', root, ...OWN, ...ownGit(args)], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 256 * 1024 * 1024 }).trim();
17
18
  /** How a git command that reads a patch on stdin went: whether it succeeded, and the first lines of what it said, on one line. */
18
19
  const fed = (root, args, patch, env = {}) => {
19
- const run = spawnSync('git', ['-C', root, ...OWN, ...args], { input: patch, env: { ...process.env, ...env }, stdio: ['pipe', 'ignore', 'pipe'], encoding: 'utf8' });
20
+ const run = spawnSync('git', ['-C', root, ...OWN, ...ownGit(args)], { input: patch, env: { ...process.env, ...env }, stdio: ['pipe', 'ignore', 'pipe'], encoding: 'utf8' });
20
21
  return { ok: run.status === 0, said: (run.stderr ?? '').split('\n').map((l) => l.trim()).filter(Boolean).slice(0, 3).join('; ') };
21
22
  };
22
23
  /** The paths a NUL-separated git listing names. */
@@ -79,6 +80,15 @@ const within = (root, path) => {
79
80
  const rel = relative(root, path);
80
81
  return rel !== '..' && !rel.startsWith('..' + sep) && !isAbsolute(rel);
81
82
  };
83
+ /** Where a path leads, or null for a link to nothing: that loads nothing, so it is no one's source. */
84
+ const realOrNull = (path) => {
85
+ try {
86
+ return realpathSync(path);
87
+ } catch (cause) {
88
+ if (cause.code === 'ENOENT') return null;
89
+ throw cause;
90
+ }
91
+ };
82
92
 
83
93
  /** Inspect package-manager links, including scoped packages and pnpm's virtual store. */
84
94
  function nodeLoadsOriginal(modules, repository, candidate) {
@@ -96,19 +106,19 @@ function nodeLoadsOriginal(modules, repository, candidate) {
96
106
  for (const name of readdirSync(path)) if (isDir(join(path, name, 'node_modules'))) queue.push(join(path, name, 'node_modules'));
97
107
  } else if (entry.name.startsWith('@') && entry.isDirectory()) queue.push(path);
98
108
  else if (entry.isSymbolicLink()) {
99
- const target = realpathSync(path);
100
- if (within(repository, target) && !within(installed, target) && !within(candidate, target)) return true;
109
+ const target = realOrNull(path);
110
+ if (target && within(repository, target) && !within(installed, target) && !within(candidate, target)) return true;
101
111
  } else if (entry.isDirectory() && isDir(join(path, 'node_modules'))) queue.push(join(path, 'node_modules'));
102
112
  }
103
113
  }
104
114
  return false;
105
115
  }
106
116
 
107
- /** Common editable-install formats: PEP 610/660 metadata, path-based .pth files and legacy egg links. */
108
- function pythonLoadsOriginal(env, repository, candidate, shared) {
117
+ /** Common editable-install formats: PEP 610/660 metadata, path-based .pth files and legacy egg links — each judged by where it points. */
118
+ function pythonLoadsOriginal(env, repository, candidate) {
109
119
  function loadsOriginal(path) {
110
- const target = realpathSync(path);
111
- return within(repository, target) && !within(candidate, target);
120
+ const target = realOrNull(path);
121
+ return target !== null && within(repository, target) && !within(candidate, target);
112
122
  }
113
123
  const lib = join(env, 'lib');
114
124
  const sites = [join(env, 'Lib', 'site-packages')];
@@ -116,7 +126,6 @@ function pythonLoadsOriginal(env, repository, candidate, shared) {
116
126
  for (const site of sites.filter(isDir)) {
117
127
  for (const name of readdirSync(site)) {
118
128
  const file = join(site, name);
119
- if (shared && (name.endsWith('.egg-link') || name.startsWith('__editable__'))) return true;
120
129
  if (name.endsWith('.egg-link') || name.endsWith('.pth')) {
121
130
  for (const line of readFileSync(file, 'utf8').split(/\r?\n/)) {
122
131
  const path = line.trim();
@@ -125,7 +134,7 @@ function pythonLoadsOriginal(env, repository, candidate, shared) {
125
134
  }
126
135
  if (name.endsWith('.dist-info') && taken(join(file, 'direct_url.json'))) {
127
136
  const metadata = JSON.parse(readFileSync(join(file, 'direct_url.json'), 'utf8'));
128
- if (metadata.dir_info?.editable && (shared || (metadata.url?.startsWith('file:') && loadsOriginal(fileURLToPath(metadata.url))))) return true;
137
+ if (metadata.dir_info?.editable && metadata.url?.startsWith('file:') && loadsOriginal(fileURLToPath(metadata.url))) return true;
129
138
  }
130
139
  }
131
140
  }
@@ -140,11 +149,9 @@ export function sharedSourceDependencies(tree, project) {
140
149
  const dependency = join(tree.path, name);
141
150
  if (!taken(dependency)) continue;
142
151
  try {
143
- const original = join(project, name);
144
- const sharedInstall = taken(original) && realpathSync(dependency) === realpathSync(original);
145
152
  const candidate = realpathSync(tree.top);
146
153
  const repository = realpathSync(git(project, ['rev-parse', '--show-toplevel']));
147
- if (name === 'node_modules' ? nodeLoadsOriginal(dependency, repository, candidate) : pythonLoadsOriginal(dependency, repository, candidate, sharedInstall)) shared.push(name);
154
+ if (name === 'node_modules' ? nodeLoadsOriginal(dependency, repository, candidate) : pythonLoadsOriginal(dependency, repository, candidate)) shared.push(name);
148
155
  } catch {
149
156
  shared.push(name); // Unreadable installation or link: its source cannot be verified.
150
157
  }
@@ -155,7 +162,7 @@ export function sharedSourceDependencies(tree, project) {
155
162
  /** Everything changed in the tree since it was made, new files included, as git itself writes a diff: with `binary`, whole enough to apply. */
156
163
  export function treeDiff({ top, prefix, base }, { binary = false } = {}) {
157
164
  git(top, ['add', '-A']);
158
- return execFileSync('git', ['-C', top, ...DIFF, '--cached', ...(binary ? ['--binary'] : []), base, '--', prefix || '.'], {
165
+ return execFileSync('git', ['-C', top, ...ownGit([...DIFF, '--cached', ...(binary ? ['--binary'] : []), base, '--', prefix || '.'])], {
159
166
  encoding: binary ? 'buffer' : 'utf8',
160
167
  stdio: ['ignore', 'pipe', 'ignore'],
161
168
  maxBuffer: 256 * 1024 * 1024,