@imdeadpool/guardex 8.4.14 → 8.4.16

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.
Files changed (46) hide show
  1. package/CONTRIBUTING.md +2 -33
  2. package/README.md +9 -534
  3. package/SECURITY.md +1 -1
  4. package/package.json +6 -39
  5. package/scripts/prepublish-bump-version.js +11 -1
  6. package/src/agents/start.js +1 -1
  7. package/src/cli/commands/branch.js +7 -7
  8. package/src/cli/commands/claude.js +6 -13
  9. package/src/cli/commands/pr.js +2 -2
  10. package/src/cli/commands/release.js +7 -1
  11. package/src/cli/commands/review.js +2 -2
  12. package/src/cli/commands/worktree-copy-ignored.js +1 -1
  13. package/src/cli/commands/worktree-estimate.js +2 -2
  14. package/src/cli/commands/worktree-hooks.js +1 -1
  15. package/src/cli/commands/worktree-navigation.js +3 -3
  16. package/src/cli/shared-locks.js +1 -1
  17. package/src/context.js +8 -1
  18. package/src/finish/index.js +1 -1
  19. package/src/finish/post-branch-finish-cleanup.js +2 -2
  20. package/src/finish/review-gate.js +3 -3
  21. package/src/finish/review-receipt.js +5 -5
  22. package/src/{github-api.js → github/api.js} +2 -2
  23. package/src/mcp/collect.js +2 -2
  24. package/src/pr-review.js +2 -1178
  25. package/src/pr-value.js +2 -111
  26. package/src/provider-binary.js +2 -122
  27. package/src/{pr.js → pull-request/index.js} +5 -5
  28. package/src/{pr-lens-publish.js → pull-request/lens-publish.js} +2 -2
  29. package/src/{pr-lens.js → pull-request/lens.js} +2 -2
  30. package/src/{pr-respond.js → pull-request/respond.js} +8 -8
  31. package/src/pull-request/value.js +111 -0
  32. package/src/{review-fix.js → review/fix.js} +2 -2
  33. package/src/review/provider-binary.js +122 -0
  34. package/src/review/pull-request.js +1178 -0
  35. package/src/{worktree-copy-ignored.js → worktree/copy-ignored.js} +3 -3
  36. package/src/{worktree-hook-worker.js → worktree/hook-worker.js} +1 -1
  37. package/src/{worktree-hooks.js → worktree/hooks.js} +5 -5
  38. package/src/{worktree-navigation.js → worktree/navigation.js} +2 -2
  39. package/src/{worktree-picker.js → worktree/picker.js} +1 -1
  40. package/src/{worktree-quota.js → worktree/quota.js} +1 -1
  41. package/src/{worktree-start.js → worktree/start.js} +4 -4
  42. package/src/{worktree-tasks.js → worktree/tasks.js} +6 -6
  43. /package/src/{shared-git-state.js → git/shared-state.js} +0 -0
  44. /package/src/{pr-checks.js → pull-request/checks.js} +0 -0
  45. /package/src/{review-diff-context.js → review/diff-context.js} +0 -0
  46. /package/src/{review-diff.js → review/diff.js} +0 -0
@@ -81,7 +81,17 @@ function findPublishableVersion({ name, version, npmView, maxAttempts = 100 }) {
81
81
  function updatePackageLock(repoRoot, name, version) {
82
82
  const lockPath = path.join(repoRoot, 'package-lock.json');
83
83
  if (!fs.existsSync(lockPath)) {
84
- return false;
84
+ const workspaceRoot = path.resolve(repoRoot, '../..');
85
+ const workspaceLockPath = path.join(workspaceRoot, 'package-lock.json');
86
+ if (!fs.existsSync(workspaceLockPath)) return false;
87
+
88
+ const workspaceLock = readJson(workspaceLockPath);
89
+ const entry = workspaceLock.packages?.[path.relative(workspaceRoot, repoRoot).split(path.sep).join('/')];
90
+ if (entry?.name !== name) return false;
91
+
92
+ entry.version = version;
93
+ writeJson(workspaceLockPath, workspaceLock);
94
+ return true;
85
95
  }
86
96
 
87
97
  const lockfile = readJson(lockPath);
@@ -6,7 +6,7 @@ const {
6
6
  const { runPackageAsset } = require('../core/runtime');
7
7
  const { currentBranchName } = require('../git');
8
8
  const { buildAgentLaunchCommand } = require('./launch');
9
- const { runTaskStart } = require('../worktree-start');
9
+ const { runTaskStart } = require('../worktree/start');
10
10
  const { resolveAgent } = require('./registry');
11
11
  const {
12
12
  applyAgentSelectionKey,
@@ -241,11 +241,11 @@ function branch(rawArgs) {
241
241
  return;
242
242
  }
243
243
  if (rest.length !== 1 || rest[0] !== '--json') throw new Error('Usage: gx branch tasks --json');
244
- require('../../worktree-tasks').listTasks(resolveRepoRoot(activeCwd));
244
+ require('../../worktree/tasks').listTasks(resolveRepoRoot(activeCwd));
245
245
  return;
246
246
  }
247
247
  if (subcommand === 'run-task') {
248
- require('../../worktree-tasks').runTask(resolveRepoRoot(activeCwd), rest);
248
+ require('../../worktree/tasks').runTask(resolveRepoRoot(activeCwd), rest);
249
249
  return;
250
250
  }
251
251
  if (subcommand === 'start') {
@@ -257,7 +257,7 @@ function branch(rawArgs) {
257
257
  if (json && (readOnly || jsonIndices.length !== 1 ||
258
258
  branchStartOptionIndices(passthrough, '--task-id').length !== 1))
259
259
  throw new Error('--json requires a normal branch start with --task-id');
260
- const quota = readOnly ? {} : require('../../worktree-quota').readWorktreeQuota(repoRoot);
260
+ const quota = readOnly ? {} : require('../../worktree/quota').readWorktreeQuota(repoRoot);
261
261
  if (!readOnly) {
262
262
  const modeIndex = passthrough.indexOf('--provision-mode');
263
263
  if (modeIndex >= 0 && !passthrough[modeIndex + 1]) throw new Error('--provision-mode requires a value');
@@ -268,12 +268,12 @@ function branch(rawArgs) {
268
268
  if (passthrough.includes('--task-id')) {
269
269
  if (passthrough.filter((arg) => arg === '--task-id').length !== 1)
270
270
  throw new Error('--task-id must appear once');
271
- require('../../worktree-start').validateTaskId(
271
+ require('../../worktree/start').validateTaskId(
272
272
  passthrough[passthrough.indexOf('--task-id') + 1]
273
273
  );
274
274
  }
275
275
  if (json) {
276
- require('../../worktree-start').invokeTaskStart(repoRoot,
276
+ require('../../worktree/start').invokeTaskStart(repoRoot,
277
277
  passthrough.filter((_, index) => index !== jsonIndices[0]), true);
278
278
  return;
279
279
  }
@@ -284,7 +284,7 @@ function branch(rawArgs) {
284
284
  recoverStaleManagedWorktrees(repoRoot);
285
285
  }
286
286
  if ((passthrough.includes('--task-id') || Object.keys(quota).length) && !isReadOnlyBranchStart(passthrough)) {
287
- require('../../worktree-start').invokeTaskStart(repoRoot, passthrough);
287
+ require('../../worktree/start').invokeTaskStart(repoRoot, passthrough);
288
288
  return;
289
289
  }
290
290
  invokePackageAsset('branchStart', passthrough, { cwd: repoRoot });
@@ -468,7 +468,7 @@ function pivot(rawArgs) {
468
468
  }
469
469
  const result = isReadOnlyBranchStart(passthrough)
470
470
  ? runPackageAsset('branchStart', passthrough, { cwd: repoRoot })
471
- : require('../../worktree-start').runTaskStart(repoRoot, passthrough);
471
+ : require('../../worktree/start').runTaskStart(repoRoot, passthrough);
472
472
  if (result.stdout) process.stdout.write(result.stdout);
473
473
  if (result.stderr) process.stderr.write(result.stderr);
474
474
  if (result.status !== 0) {
@@ -15,7 +15,7 @@ const cp = require('child_process');
15
15
  const fs = require('fs');
16
16
  const path = require('path');
17
17
  const { isDeepStrictEqual } = require('util');
18
- const { TOOL_NAME, SHORT_TOOL_NAME } = require('../../context');
18
+ const { TOOL_NAME, SHORT_TOOL_NAME, CHECKOUT_ROOT, PACKAGE_ROOT } = require('../../context');
19
19
  const { gitRun, resolveRepoRoot } = require('../../git');
20
20
  const { requireValue } = require('../args');
21
21
 
@@ -43,8 +43,8 @@ const ABIDE_COMPILE_TIMEOUT_MS = 15 * 60_000;
43
43
  const ABIDE_CALIBRATE_TIMEOUT_MS = 10 * 60_000;
44
44
 
45
45
  const MANAGED_AGENT_SKILLS = [
46
- { name: 'gitguardex', source: ['.claude', 'skills', 'gitguardex'] },
47
- { name: 'opensrc', source: ['templates', 'codex', 'skills', 'opensrc'] },
46
+ { name: 'gitguardex', source: [CHECKOUT_ROOT, '.claude', 'skills', 'gitguardex'] },
47
+ { name: 'opensrc', source: [PACKAGE_ROOT, 'templates', 'codex', 'skills', 'opensrc'] },
48
48
  ];
49
49
 
50
50
  const MANAGED_HOOK_FILES = [
@@ -222,10 +222,6 @@ function mergeSettings(existing, template) {
222
222
  return base;
223
223
  }
224
224
 
225
- function findPackageRoot() {
226
- return path.resolve(__dirname, '..', '..', '..');
227
- }
228
-
229
225
  function copyFileIfDifferent(srcPath, destPath, { dryRun }) {
230
226
  if (!fs.existsSync(srcPath)) {
231
227
  return { status: 'source-missing', dest: destPath };
@@ -247,10 +243,9 @@ function copyFileIfDifferent(srcPath, destPath, { dryRun }) {
247
243
  }
248
244
 
249
245
  function installHooks(repoRoot, { dryRun }) {
250
- const packageRoot = findPackageRoot();
251
246
  const results = [];
252
247
  for (const hookFile of MANAGED_HOOK_FILES) {
253
- const src = path.join(packageRoot, HOOKS_REL, hookFile);
248
+ const src = path.join(CHECKOUT_ROOT, HOOKS_REL, hookFile);
254
249
  const dest = path.join(repoRoot, HOOKS_REL, hookFile);
255
250
  const result = copyFileIfDifferent(src, dest, { dryRun });
256
251
  if (result.status === 'source-missing') continue;
@@ -267,10 +262,9 @@ function installHooks(repoRoot, { dryRun }) {
267
262
  }
268
263
 
269
264
  function installSlashCommands(repoRoot, { dryRun }) {
270
- const packageRoot = findPackageRoot();
271
265
  const results = [];
272
266
  for (const filename of MANAGED_SLASH_COMMANDS) {
273
- const src = path.join(packageRoot, COMMANDS_REL, filename);
267
+ const src = path.join(CHECKOUT_ROOT, COMMANDS_REL, filename);
274
268
  const dest = path.join(repoRoot, COMMANDS_REL, filename);
275
269
  const result = copyFileIfDifferent(src, dest, { dryRun });
276
270
  if (result.status === 'source-missing') continue;
@@ -280,10 +274,9 @@ function installSlashCommands(repoRoot, { dryRun }) {
280
274
  }
281
275
 
282
276
  function installAgentSkills(repoRoot, { dryRun }) {
283
- const packageRoot = findPackageRoot();
284
277
  const results = [];
285
278
  for (const skill of MANAGED_AGENT_SKILLS) {
286
- const srcDir = path.join(packageRoot, ...skill.source);
279
+ const srcDir = path.join(...skill.source);
287
280
  if (!fs.existsSync(srcDir)) {
288
281
  results.push({ skill: skill.name, status: 'source-missing' });
289
282
  continue;
@@ -14,7 +14,7 @@
14
14
  // This is the thin glue layer; logic lives in src/pr.js.
15
15
 
16
16
  const { TOOL_NAME, SHORT_TOOL_NAME } = require('../../context');
17
- const prModule = require('../../pr');
17
+ const prModule = require('../../pull-request/index');
18
18
  const { prReview } = require('./review');
19
19
 
20
20
  function logInfo(message) {
@@ -432,7 +432,7 @@ function cmdRespond(rawArgs) {
432
432
  return;
433
433
  }
434
434
 
435
- const { prRespond } = require('../../pr-respond');
435
+ const { prRespond } = require('../../pull-request/respond');
436
436
  const result = prRespond({
437
437
  pr: opts.pr,
438
438
  target: opts.target,
@@ -47,7 +47,10 @@ function ensureCleanWorkingTree(repoRoot) {
47
47
  }
48
48
 
49
49
  function readReleaseRepoPackageJson(repoRoot) {
50
- const manifestPath = path.join(repoRoot, 'package.json');
50
+ const workspaceManifest = path.join(repoRoot, 'package', 'gitguardex', 'package.json');
51
+ const manifestPath = fs.existsSync(workspaceManifest)
52
+ ? workspaceManifest
53
+ : path.join(repoRoot, 'package.json');
51
54
  if (!fs.existsSync(manifestPath)) {
52
55
  throw new Error(`Release blocked: package.json missing in ${repoRoot}`);
53
56
  }
@@ -243,6 +246,9 @@ function release(rawArgs) {
243
246
  }
244
247
 
245
248
  const releasePackageJson = readReleaseRepoPackageJson(repoRoot);
249
+ if (typeof releasePackageJson.version !== 'string' || !releasePackageJson.version.trim()) {
250
+ throw new Error('Release blocked: the package manifest has no version');
251
+ }
246
252
  const repoSlug = resolveReleaseGithubRepo(repoRoot);
247
253
  const currentTag = `v${releasePackageJson.version}`;
248
254
  const previousTag = resolvePreviousPublishedReleaseTag(repoSlug, currentTag);
@@ -2,8 +2,8 @@
2
2
  // src/cli/main.js.
3
3
  const { resolveRepoRoot } = require('../../git');
4
4
  const { runReviewBotCommand } = require('../../core/runtime');
5
- const prReviewModule = require('../../pr-review');
6
- const reviewFixModule = require('../../review-fix');
5
+ const prReviewModule = require('../../review/pull-request');
6
+ const reviewFixModule = require('../../review/fix');
7
7
  const { parseReviewArgs, parsePrReviewArgs } = require('../args');
8
8
  const { isSpawnFailure } = require('../shared/sandbox');
9
9
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const { copyIgnoredFiles } = require('../../worktree-copy-ignored');
3
+ const { copyIgnoredFiles } = require('../../worktree/copy-ignored');
4
4
 
5
5
  function copyIgnored(rawArgs, deps = {}) {
6
6
  const log = deps.log || console.log;
@@ -1,6 +1,6 @@
1
1
  const { resolveRepoRoot } = require('../../git');
2
2
  const { extractTargetedArgs, run } = require('../../core/runtime');
3
- const { estimateCheckout } = require('../../worktree-start');
3
+ const { estimateCheckout } = require('../../worktree/start');
4
4
 
5
5
  function worktreeEstimate(args) {
6
6
  if (args.length === 1 && ['--help', '-h'].includes(args[0])) {
@@ -45,7 +45,7 @@ function worktreeEstimate(args) {
45
45
  );
46
46
  }
47
47
  const report = estimateCheckout(repoRoot, ref, exclusions);
48
- report.quota = require('../../worktree-quota').inspectWorktreeQuota(repoRoot, report.checkoutBytes, destination);
48
+ report.quota = require('../../worktree/quota').inspectWorktreeQuota(repoRoot, report.checkoutBytes, destination);
49
49
  if (checkQuota && report.quota?.violations.length) {
50
50
  throw new Error(report.quota.violations.join(', ') + ': reuse an existing task or inspect safe cleanup before creating another worktree. No new checkout was created.');
51
51
  }
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const { resolveRepoRoot } = require('../../git');
4
- const hooks = require('../../worktree-hooks');
4
+ const hooks = require('../../worktree/hooks');
5
5
 
6
6
  async function runWorktreeHooksCommand(args, deps = {}) {
7
7
  if (args.includes('--help') || args.includes('-h')) {
@@ -1,6 +1,6 @@
1
1
  const { resolveRepoRoot } = require('../../git');
2
- const { resolveWorktree, shellIntegration } = require('../../worktree-navigation');
3
- const { pickWorktree } = require('../../worktree-picker');
2
+ const { resolveWorktree, shellIntegration } = require('../../worktree/navigation');
3
+ const { pickWorktree } = require('../../worktree/picker');
4
4
 
5
5
  async function switchWorktree(args = [], deps = {}) {
6
6
  const options = { cwd: process.cwd() };
@@ -36,7 +36,7 @@ async function switchWorktree(args = [], deps = {}) {
36
36
  if (!entry) return null;
37
37
  if (/[\x00-\x1f\x7f]/.test(entry.path))
38
38
  throw new Error('Navigation path contains unsupported control characters');
39
- const hook = deps.runLifecycleHook || require('../../worktree-hooks').runLifecycleHook;
39
+ const hook = deps.runLifecycleHook || require('../../worktree/hooks').runLifecycleHook;
40
40
  const context = {
41
41
  worktreePath: entry.path,
42
42
  branch: entry.branch,
@@ -3,7 +3,7 @@
3
3
  const { TOOL_NAME } = require('../context');
4
4
  const { resolveRepoRoot } = require('../git');
5
5
  const { run, extractTargetedArgs, runPackageAsset } = require('../core/runtime');
6
- const sharedGitState = require('../shared-git-state');
6
+ const sharedGitState = require('../git/shared-state');
7
7
 
8
8
  function writeCommandResult(result) {
9
9
  if (result.stdout) process.stdout.write(result.stdout);
package/src/context.js CHANGED
@@ -4,6 +4,12 @@ const path = require('node:path');
4
4
  const cp = require('node:child_process');
5
5
 
6
6
  const PACKAGE_ROOT = path.resolve(__dirname, '..');
7
+ const workspaceRoot = path.resolve(PACKAGE_ROOT, '../..');
8
+ const CHECKOUT_ROOT =
9
+ path.join(workspaceRoot, 'package', 'gitguardex') === PACKAGE_ROOT &&
10
+ fs.existsSync(path.join(workspaceRoot, '.git'))
11
+ ? workspaceRoot
12
+ : PACKAGE_ROOT;
7
13
  const CLI_ENTRY_PATH = path.join(PACKAGE_ROOT, 'bin', 'multiagent-safety.js');
8
14
  const packageJsonPath = path.join(PACKAGE_ROOT, 'package.json');
9
15
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
@@ -91,7 +97,7 @@ const RTK_BIN = process.env.GUARDEX_RTK_BIN || 'rtk';
91
97
  let _ghBin;
92
98
  let _requiredSystemTools;
93
99
  const MAINTAINER_RELEASE_REPO = path.resolve(
94
- process.env.GUARDEX_RELEASE_REPO || PACKAGE_ROOT,
100
+ process.env.GUARDEX_RELEASE_REPO || CHECKOUT_ROOT,
95
101
  );
96
102
  const NPM_BIN = process.env.GUARDEX_NPM_BIN || 'npm';
97
103
  const OPENSPEC_BIN = process.env.GUARDEX_OPENSPEC_BIN || 'openspec';
@@ -1286,6 +1292,7 @@ module.exports = {
1286
1292
  cp,
1287
1293
  cachedSpawn,
1288
1294
  PACKAGE_ROOT,
1295
+ CHECKOUT_ROOT,
1289
1296
  CLI_ENTRY_PATH,
1290
1297
  packageJsonPath,
1291
1298
  packageJson,
@@ -167,7 +167,7 @@ function autoCommitWorktreeForFinish(repoRoot, worktreePath, branch, options) {
167
167
  return { changed: true, committed: false, dryRun: true };
168
168
  }
169
169
 
170
- const { runLifecycleHookSync } = require('../worktree-hooks');
170
+ const { runLifecycleHookSync } = require('../worktree/hooks');
171
171
  runLifecycleHookSync(repoRoot, 'pre-commit', { worktreePath, branch });
172
172
  // Hooks may generate files; claim through GX before staging.
173
173
  claimLocksForAutoCommit(repoRoot, worktreePath, branch);
@@ -437,7 +437,7 @@ function cleanupFinishedDetachedWorktree(input) {
437
437
  if (!worktreeIdentityMatches(plan) || probeWorktreeOwnership(plan.worktreePath).active)
438
438
  return false;
439
439
  try {
440
- require('../worktree-hooks').runLifecycleHookSync(plan.repoRoot, 'pre-remove', {
440
+ require('../worktree/hooks').runLifecycleHookSync(plan.repoRoot, 'pre-remove', {
441
441
  worktreePath: plan.worktreePath,
442
442
  branch: plan.branch
443
443
  });
@@ -463,7 +463,7 @@ function cleanupFinishedDetachedWorktree(input) {
463
463
  if (result.stdout) process.stdout.write(result.stdout);
464
464
  retireCleanupJob(plan);
465
465
  try {
466
- require('../worktree-hooks').runLifecycleHookSync(plan.repoRoot, 'post-remove', {
466
+ require('../worktree/hooks').runLifecycleHookSync(plan.repoRoot, 'post-remove', {
467
467
  worktreePath: plan.worktreePath,
468
468
  branch: plan.branch
469
469
  });
@@ -9,9 +9,9 @@
9
9
 
10
10
  const { run } = require('../core/runtime');
11
11
  const { TOOL_NAME } = require('../context');
12
- const pr = require('../pr');
13
- const prReview = require('../pr-review');
14
- const reviewFix = require('../review-fix');
12
+ const pr = require('../pull-request/index');
13
+ const prReview = require('../review/pull-request');
14
+ const reviewFix = require('../review/fix');
15
15
  const { reviewReceipt } = require('./review-receipt');
16
16
  const { mapWorktreePathsByBranch } = require('../git');
17
17
 
@@ -3,7 +3,7 @@
3
3
  const { createHash } = require('node:crypto');
4
4
  const { fs, path, GH_BIN } = require('../context');
5
5
  const { run } = require('../core/runtime');
6
- const { repoApiPath } = require('../github-api');
6
+ const { repoApiPath } = require('../github/api');
7
7
 
8
8
  const MAX_AGE_MS = 24 * 60 * 60 * 1000;
9
9
  const hash = (value) => createHash('sha256').update(value).digest('hex');
@@ -38,10 +38,10 @@ function reviewReceipt(repoRoot, revision, options, execute = run, env = process
38
38
  implementation = [
39
39
  __filename,
40
40
  require.resolve('./review-gate'),
41
- require.resolve('../pr-review'),
42
- require.resolve('../provider-binary'),
43
- require.resolve('../review-diff'),
44
- require.resolve('../review-diff-context')
41
+ require.resolve('../review/pull-request'),
42
+ require.resolve('../review/provider-binary'),
43
+ require.resolve('../review/diff'),
44
+ require.resolve('../review/diff-context')
45
45
  ].map((source) => hash(fs.readFileSync(source)));
46
46
  } catch {
47
47
  return null;
@@ -1,5 +1,5 @@
1
- const { GH_BIN } = require('./context');
2
- const { run } = require('./core/runtime');
1
+ const { GH_BIN } = require('../context');
2
+ const { run } = require('../core/runtime');
3
3
  const path = require('node:path');
4
4
 
5
5
  const REPO_SLUG_RE = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
@@ -15,8 +15,8 @@ const fs = require('node:fs');
15
15
  const path = require('node:path');
16
16
 
17
17
  const { findProjects } = require('../cockpit/projects-finder');
18
- const { findOpenPrForBranch, listOpenPrsForRepo } = require('../pr');
19
- const sharedGitState = require('../shared-git-state');
18
+ const { findOpenPrForBranch, listOpenPrsForRepo } = require('../pull-request/index');
19
+ const sharedGitState = require('../git/shared-state');
20
20
  const abide = require('../abide');
21
21
 
22
22
  const PROTECTED_BRANCHES = new Set(['main', 'master', 'dev']);