@imdeadpool/guardex 8.1.0 → 8.3.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/README.md +57 -8
- package/bin/multiagent-safety.js +18 -1
- package/package.json +1 -1
- package/skills/gitguardex/SKILL.md +26 -2
- package/src/cli/args.js +15 -1
- package/src/cli/commands/agents.js +1 -0
- package/src/cli/commands/branch.js +84 -6
- package/src/cli/commands/finish.js +44 -2
- package/src/cli/shared-locks.js +4 -0
- package/src/doctor/index.js +26 -27
- package/src/finish/index.js +73 -20
- package/src/finish/post-branch-finish-cleanup.js +324 -0
- package/src/finish/progress.js +57 -3
- package/src/finish/review-gate.js +47 -6
- package/src/git/index.js +9 -4
- package/src/mcp/collect.js +84 -23
- package/src/mcp/server.js +35 -19
- package/src/pr-checks.js +20 -5
- package/src/pr.js +122 -1
- package/src/scaffold/index.js +10 -0
- package/templates/AGENTS.multiagent-safety.md +37 -9
- package/templates/AGENTS.multiagent-safety.min.md +10 -4
- package/templates/codex/skills/gitguardex/SKILL.md +26 -2
- package/templates/githooks/pre-commit +40 -5
- package/templates/githooks/pre-push +72 -25
- package/templates/scripts/agent-branch-finish.sh +300 -21
- package/templates/scripts/agent-branch-start.sh +22 -2
- package/templates/scripts/agent-file-locks.py +119 -8
- package/templates/scripts/agent-preflight.sh +30 -0
- package/templates/scripts/agent-reconcile-openspec-tasks.js +105 -0
- package/templates/scripts/agent-worktree-prune.sh +396 -31
- package/templates/scripts/guardex-env.sh +291 -0
package/src/git/index.js
CHANGED
|
@@ -1087,10 +1087,10 @@ function branchExists(repoRoot, branch) {
|
|
|
1087
1087
|
}
|
|
1088
1088
|
|
|
1089
1089
|
/**
|
|
1090
|
-
* Resolve the base branch for the finish flow: CLI override wins
|
|
1091
|
-
* the
|
|
1092
|
-
*
|
|
1093
|
-
* default branch.
|
|
1090
|
+
* Resolve the base branch for the finish flow: CLI override wins and repairs
|
|
1091
|
+
* the branch metadata before any gate can restart the finish; otherwise the
|
|
1092
|
+
* per-branch `branch.<source>.guardexBase` recorded at branch-start; otherwise
|
|
1093
|
+
* the repo-wide configured base; otherwise the repo's detected default branch.
|
|
1094
1094
|
*
|
|
1095
1095
|
* @param {string} repoRoot Repo to inspect.
|
|
1096
1096
|
* @param {string} sourceBranch Source agent branch (used for per-branch base).
|
|
@@ -1099,6 +1099,11 @@ function branchExists(repoRoot, branch) {
|
|
|
1099
1099
|
*/
|
|
1100
1100
|
function resolveFinishBaseBranch(repoRoot, sourceBranch, explicitBase) {
|
|
1101
1101
|
if (explicitBase) {
|
|
1102
|
+
const explicitBaseExists = branchExists(repoRoot, explicitBase)
|
|
1103
|
+
|| gitRefExists(repoRoot, `refs/remotes/origin/${explicitBase}`);
|
|
1104
|
+
if (sourceBranch && explicitBaseExists) {
|
|
1105
|
+
gitRun(repoRoot, ['config', `branch.${sourceBranch}.guardexBase`, explicitBase]);
|
|
1106
|
+
}
|
|
1102
1107
|
return explicitBase;
|
|
1103
1108
|
}
|
|
1104
1109
|
|
package/src/mcp/collect.js
CHANGED
|
@@ -349,32 +349,52 @@ function repoState(repoOrCwd, { includePrs = true } = {}) {
|
|
|
349
349
|
// Aggregate locks across ALL worktrees of the repo. Lock files are per-worktree
|
|
350
350
|
// on disk, so a single worktree's file only shows its own claims — the
|
|
351
351
|
// collision view requires the union.
|
|
352
|
-
function
|
|
353
|
-
|
|
352
|
+
function whoOwnsMany(files, { cwd = process.cwd(), repoPath } = {}) {
|
|
353
|
+
const requested = [...new Set(
|
|
354
|
+
(Array.isArray(files) ? files : [])
|
|
355
|
+
.filter((file) => typeof file === 'string' && file.trim())
|
|
356
|
+
.map((file) => file.trim()),
|
|
357
|
+
)].slice(0, 200);
|
|
358
|
+
if (requested.length === 0) return [];
|
|
354
359
|
const mainRoot = mainRepoRoot(repoPath || cwd);
|
|
355
|
-
if (!mainRoot)
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const
|
|
360
|
+
if (!mainRoot) {
|
|
361
|
+
return requested.map((file) => ({ file, owner: null, error: 'not a git repo' }));
|
|
362
|
+
}
|
|
363
|
+
const targets = requested.map((file) => ({
|
|
364
|
+
file,
|
|
365
|
+
rel: path.isAbsolute(file) ? path.relative(mainRoot, file) : file,
|
|
366
|
+
owners: [],
|
|
367
|
+
seen: new Set(),
|
|
368
|
+
}));
|
|
369
|
+
const addOwner = (target, owner) => {
|
|
370
|
+
const key = `${owner.branch}\0${owner.agent || ''}`;
|
|
371
|
+
if (!owner.branch || target.seen.has(key)) return;
|
|
372
|
+
target.seen.add(key);
|
|
373
|
+
target.owners.push(owner);
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
// Read each worktree lock map once for the whole requested batch.
|
|
359
377
|
for (const wt of listWorktrees(mainRoot)) {
|
|
360
378
|
const map = readLockMap(wt.path);
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
owners.push({
|
|
379
|
+
for (const target of targets) {
|
|
380
|
+
const entry = map[target.rel] || map[target.file];
|
|
381
|
+
if (!entry) continue;
|
|
382
|
+
addOwner(target, {
|
|
366
383
|
branch: entry.branch,
|
|
367
384
|
agent: entry.agent || parseAgentName(entry.branch),
|
|
368
385
|
claimed_at: entry.claimed_at || null,
|
|
369
|
-
worktree: wt.path
|
|
386
|
+
worktree: wt.path,
|
|
370
387
|
});
|
|
371
388
|
}
|
|
372
389
|
}
|
|
373
390
|
if (sharedGitState.settings(mainRoot).enabled) {
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
391
|
+
const sharedByFile = new Map(
|
|
392
|
+
sharedGitState.listLocks(mainRoot).map((entry) => [entry.file, entry]),
|
|
393
|
+
);
|
|
394
|
+
for (const target of targets) {
|
|
395
|
+
const entry = sharedByFile.get(target.rel) || sharedByFile.get(target.file);
|
|
396
|
+
if (!entry) continue;
|
|
397
|
+
addOwner(target, {
|
|
378
398
|
branch: entry.branch,
|
|
379
399
|
agent: entry.agent || parseAgentName(entry.branch),
|
|
380
400
|
claimed_at: entry.claimedAt,
|
|
@@ -384,13 +404,20 @@ function whoOwns(file, { cwd = process.cwd(), repoPath } = {}) {
|
|
|
384
404
|
});
|
|
385
405
|
}
|
|
386
406
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
407
|
+
return targets.map(({ rel, owners }) => {
|
|
408
|
+
if (owners.length === 0) return { file: rel, owner: null };
|
|
409
|
+
return {
|
|
410
|
+
file: rel,
|
|
411
|
+
owner: owners.length === 1 ? owners[0] : null,
|
|
412
|
+
owners,
|
|
413
|
+
conflict: owners.length > 1,
|
|
414
|
+
};
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function whoOwns(file, options = {}) {
|
|
419
|
+
if (!file) return { file: null, owner: null, error: 'no file given' };
|
|
420
|
+
return whoOwnsMany([file], options)[0];
|
|
394
421
|
}
|
|
395
422
|
|
|
396
423
|
// Slim "radar" projection of a lane for list_agents — who-is-on-what at a
|
|
@@ -450,12 +477,46 @@ function myContext({ cwd = process.cwd(), includePr = true } = {}) {
|
|
|
450
477
|
};
|
|
451
478
|
}
|
|
452
479
|
|
|
480
|
+
function compactOwnership(result) {
|
|
481
|
+
const compactOwner = (owner) => {
|
|
482
|
+
if (!owner) return null;
|
|
483
|
+
const value = { branch: owner.branch, agent: owner.agent };
|
|
484
|
+
if (owner.remote) value.remote = true;
|
|
485
|
+
if (owner.machine) value.machine = owner.machine;
|
|
486
|
+
return value;
|
|
487
|
+
};
|
|
488
|
+
if (!result.owner && !result.conflict) return { file: result.file, owner: null };
|
|
489
|
+
if (result.conflict) {
|
|
490
|
+
return {
|
|
491
|
+
file: result.file,
|
|
492
|
+
owner: null,
|
|
493
|
+
owners: result.owners.map(compactOwner),
|
|
494
|
+
conflict: true,
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
return { file: result.file, owner: compactOwner(result.owner) };
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** One compact, repo-scoped snapshot for an agent about to edit files. */
|
|
501
|
+
function editContext({ cwd = process.cwd(), files = [], includePrs = false } = {}) {
|
|
502
|
+
const context = myContext({ cwd, includePr: includePrs });
|
|
503
|
+
if (context.error) return context;
|
|
504
|
+
const otherAgents = collectRepoAgents(context.repoPath, { includePrs })
|
|
505
|
+
.filter((agent) => agent.branch !== context.branch)
|
|
506
|
+
.map(radarRecord);
|
|
507
|
+
const ownership = whoOwnsMany(files, { repoPath: context.repoPath })
|
|
508
|
+
.map(compactOwnership);
|
|
509
|
+
return { ...context, otherAgents, ownership };
|
|
510
|
+
}
|
|
511
|
+
|
|
453
512
|
module.exports = {
|
|
454
513
|
collectAllAgents,
|
|
455
514
|
collectRepoAgents,
|
|
456
515
|
repoState,
|
|
457
516
|
whoOwns,
|
|
517
|
+
whoOwnsMany,
|
|
458
518
|
myContext,
|
|
519
|
+
editContext,
|
|
459
520
|
radarRecord,
|
|
460
521
|
indexPrsByBranch,
|
|
461
522
|
daysSince,
|
package/src/mcp/server.js
CHANGED
|
@@ -19,45 +19,45 @@ const TOOLS = [
|
|
|
19
19
|
{
|
|
20
20
|
name: 'list_agents',
|
|
21
21
|
description:
|
|
22
|
-
'
|
|
22
|
+
'Cross-repo agent radar. Compact by default; use detail only for paths and file lists.',
|
|
23
23
|
inputSchema: {
|
|
24
24
|
type: 'object',
|
|
25
25
|
properties: {
|
|
26
26
|
include_prs: {
|
|
27
27
|
type: 'boolean',
|
|
28
|
-
description: 'Fetch
|
|
28
|
+
description: 'Fetch PRs. Default false.',
|
|
29
29
|
},
|
|
30
30
|
roots: {
|
|
31
31
|
type: 'array',
|
|
32
32
|
items: { type: 'string' },
|
|
33
|
-
description: 'Override
|
|
33
|
+
description: 'Override search roots.',
|
|
34
34
|
},
|
|
35
|
-
limit: { type: 'number', description: '
|
|
36
|
-
detail: { type: 'boolean', description: 'Return full lane records
|
|
35
|
+
limit: { type: 'number', description: 'Repo scan cap.' },
|
|
36
|
+
detail: { type: 'boolean', description: 'Return full lane records. Default false.' },
|
|
37
37
|
},
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
41
|
name: 'repo_state',
|
|
42
42
|
description:
|
|
43
|
-
'Agent lanes for
|
|
43
|
+
'Agent lanes for one repo.',
|
|
44
44
|
inputSchema: {
|
|
45
45
|
type: 'object',
|
|
46
46
|
properties: {
|
|
47
|
-
repo: { type: 'string', description: '
|
|
48
|
-
include_prs: { type: 'boolean', description: 'Fetch
|
|
47
|
+
repo: { type: 'string', description: 'Repo path; default cwd.' },
|
|
48
|
+
include_prs: { type: 'boolean', description: 'Fetch PRs. Default false.' },
|
|
49
49
|
},
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
53
|
name: 'who_owns',
|
|
54
54
|
description:
|
|
55
|
-
'
|
|
55
|
+
'Find the lock owner for one file. owner=null means unclaimed.',
|
|
56
56
|
inputSchema: {
|
|
57
57
|
type: 'object',
|
|
58
58
|
properties: {
|
|
59
|
-
file: { type: 'string', description: '
|
|
60
|
-
repo: { type: 'string', description: '
|
|
59
|
+
file: { type: 'string', description: 'File path.' },
|
|
60
|
+
repo: { type: 'string', description: 'Repo path; default cwd.' },
|
|
61
61
|
},
|
|
62
62
|
required: ['file'],
|
|
63
63
|
},
|
|
@@ -65,19 +65,30 @@ const TOOLS = [
|
|
|
65
65
|
{
|
|
66
66
|
name: 'my_context',
|
|
67
67
|
description:
|
|
68
|
-
'
|
|
69
|
-
inputSchema: {
|
|
68
|
+
'Current lane. Pass files to also return compact same-repo radar and batch ownership in this one call.',
|
|
69
|
+
inputSchema: {
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: {
|
|
72
|
+
files: {
|
|
73
|
+
type: 'array',
|
|
74
|
+
items: { type: 'string' },
|
|
75
|
+
maxItems: 200,
|
|
76
|
+
description: 'Files intended for editing.',
|
|
77
|
+
},
|
|
78
|
+
include_prs: { type: 'boolean', description: 'Fetch PRs. Default false.' },
|
|
79
|
+
},
|
|
80
|
+
},
|
|
70
81
|
},
|
|
71
82
|
];
|
|
72
83
|
|
|
73
84
|
function callTool(name, args = {}) {
|
|
74
85
|
switch (name) {
|
|
75
86
|
case 'list_agents': {
|
|
76
|
-
//
|
|
77
|
-
//
|
|
87
|
+
// PR lookup is one batched gh call per repo with active lanes. Keep it
|
|
88
|
+
// opt-in so the default radar stays fast and compact.
|
|
78
89
|
const full = collect.collectAllAgents({
|
|
79
90
|
roots: args.roots,
|
|
80
|
-
includePrs: args.include_prs
|
|
91
|
+
includePrs: args.include_prs === true,
|
|
81
92
|
limit: args.limit,
|
|
82
93
|
});
|
|
83
94
|
// Compact radar by default (~80% fewer tokens); detail:true keeps the
|
|
@@ -86,11 +97,16 @@ function callTool(name, args = {}) {
|
|
|
86
97
|
return { ...full, agents: full.agents.map(collect.radarRecord) };
|
|
87
98
|
}
|
|
88
99
|
case 'repo_state':
|
|
89
|
-
return collect.repoState(args.repo || process.cwd(), { includePrs: args.include_prs
|
|
100
|
+
return collect.repoState(args.repo || process.cwd(), { includePrs: args.include_prs === true });
|
|
90
101
|
case 'who_owns':
|
|
91
102
|
return collect.whoOwns(args.file, { repoPath: args.repo });
|
|
92
|
-
case 'my_context':
|
|
93
|
-
|
|
103
|
+
case 'my_context': {
|
|
104
|
+
const includePrs = args.include_prs === true;
|
|
105
|
+
if (Array.isArray(args.files) && args.files.length > 0) {
|
|
106
|
+
return collect.editContext({ files: args.files, includePrs });
|
|
107
|
+
}
|
|
108
|
+
return collect.myContext({ includePr: includePrs });
|
|
109
|
+
}
|
|
94
110
|
default:
|
|
95
111
|
throw new Error(`Unknown tool: ${name}`);
|
|
96
112
|
}
|
package/src/pr-checks.js
CHANGED
|
@@ -90,19 +90,28 @@ function latestStatusChecks(value) {
|
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
function summarizeStatusCheckRollup(value) {
|
|
93
|
+
function summarizeStatusCheckRollup(value, { isWaived = () => false } = {}) {
|
|
94
94
|
const { checks, superseded } = latestStatusChecks(value);
|
|
95
95
|
const failedNames = [];
|
|
96
|
+
const waivedNames = [];
|
|
97
|
+
let waivedCount = 0;
|
|
96
98
|
const summary = checks.reduce(
|
|
97
99
|
(acc, check) => {
|
|
98
100
|
const state = String(check?.conclusion || check?.state || check?.status || '').toUpperCase();
|
|
99
|
-
|
|
101
|
+
const failing = FAILING_CONCLUSIONS.has(state);
|
|
102
|
+
const waived = failing && isWaived(check);
|
|
103
|
+
if (waived) {
|
|
104
|
+
const name = checkName(check);
|
|
105
|
+
if (name) waivedNames.push(name);
|
|
106
|
+
waivedCount += 1;
|
|
107
|
+
} else if (state === 'SUCCESS') acc.success += 1;
|
|
108
|
+
else if (state === 'SKIPPED') acc.skipped = (acc.skipped || 0) + 1;
|
|
100
109
|
else if (state === 'CANCELLED') acc.cancelled += 1;
|
|
101
|
-
else if (
|
|
110
|
+
else if (failing) acc.failed += 1;
|
|
102
111
|
else if (state === 'PENDING' || state === 'IN_PROGRESS' || state === 'QUEUED') acc.pending += 1;
|
|
103
112
|
else acc.other += 1;
|
|
104
113
|
|
|
105
|
-
if (
|
|
114
|
+
if (failing && !waived) {
|
|
106
115
|
const name = checkName(check);
|
|
107
116
|
if (name) failedNames.push(name);
|
|
108
117
|
}
|
|
@@ -110,8 +119,14 @@ function summarizeStatusCheckRollup(value) {
|
|
|
110
119
|
},
|
|
111
120
|
{ success: 0, failed: 0, pending: 0, cancelled: 0, other: 0, total: checks.length },
|
|
112
121
|
);
|
|
122
|
+
if (waivedCount > 0) summary.waived = waivedCount;
|
|
113
123
|
|
|
114
|
-
return {
|
|
124
|
+
return {
|
|
125
|
+
summary,
|
|
126
|
+
failedNames,
|
|
127
|
+
waivedNames,
|
|
128
|
+
supersededCount: superseded.length,
|
|
129
|
+
};
|
|
115
130
|
}
|
|
116
131
|
|
|
117
132
|
module.exports = {
|
package/src/pr.js
CHANGED
|
@@ -18,6 +18,8 @@ const {
|
|
|
18
18
|
const { repoApiPath } = require('./github-api');
|
|
19
19
|
const { FAILING_CONCLUSIONS, summarizeStatusCheckRollup } = require('./pr-checks');
|
|
20
20
|
|
|
21
|
+
const BILLING_BLOCKED_JOB_MESSAGE = /^The job was not started because recent account payments have failed or your spending limit needs to be increased\. Please check the ['"]Billing & plans['"] section in your settings\.?$/i;
|
|
22
|
+
|
|
21
23
|
const DEFAULT_POLL_INTERVAL_MS = 5_000;
|
|
22
24
|
const DEFAULT_POLL_TIMEOUT_MS = 10 * 60 * 1000;
|
|
23
25
|
|
|
@@ -57,6 +59,114 @@ function ghJson(repoRoot, args) {
|
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
61
|
|
|
62
|
+
function githubActionsJobId(check) {
|
|
63
|
+
if (String(check?.__typename || '') !== 'CheckRun') return '';
|
|
64
|
+
if (!String(check?.name || '').trim()) return '';
|
|
65
|
+
const state = String(check?.conclusion || '').toUpperCase();
|
|
66
|
+
if (!FAILING_CONCLUSIONS.has(state)) return '';
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const url = new URL(String(check?.detailsUrl || ''));
|
|
70
|
+
if (url.protocol !== 'https:' || url.hostname !== 'github.com') return '';
|
|
71
|
+
const match = url.pathname.match(/\/actions\/runs\/\d+\/job\/(\d+)(?:\/|$)/);
|
|
72
|
+
return match ? match[1] : '';
|
|
73
|
+
} catch (_error) {
|
|
74
|
+
return '';
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function githubCheckRunAnnotationsPath(job, expectedCheckRunId) {
|
|
79
|
+
try {
|
|
80
|
+
const url = new URL(String(job?.check_run_url || ''));
|
|
81
|
+
if (url.protocol !== 'https:' || url.hostname !== 'api.github.com') return '';
|
|
82
|
+
const match = url.pathname.match(/^\/repos\/[^/]+\/[^/]+\/check-runs\/(\d+)\/?$/);
|
|
83
|
+
return match && match[1] === String(expectedCheckRunId)
|
|
84
|
+
? `check-runs/${match[1]}/annotations`
|
|
85
|
+
: '';
|
|
86
|
+
} catch (_error) {
|
|
87
|
+
return '';
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function commitCheckRuns(repoRoot, headSha, runner = run) {
|
|
92
|
+
const sha = String(headSha || '').trim();
|
|
93
|
+
if (!/^[0-9a-f]{7,64}$/i.test(sha)) return [];
|
|
94
|
+
|
|
95
|
+
const result = runner(GH_BIN, [
|
|
96
|
+
'api',
|
|
97
|
+
repoApiPath(repoRoot, `commits/${sha}/check-runs?per_page=100`, runner),
|
|
98
|
+
], { cwd: repoRoot, timeout: 60_000, allowFailure: true });
|
|
99
|
+
if (result.status !== 0) return [];
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const payload = JSON.parse(String(result.stdout || ''));
|
|
103
|
+
const checkRuns = Array.isArray(payload?.check_runs) ? payload.check_runs : [];
|
|
104
|
+
return Number(payload?.total_count) === checkRuns.length ? checkRuns : [];
|
|
105
|
+
} catch (_error) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function matchingCheckRunId(check, checkRuns) {
|
|
111
|
+
const matches = checkRuns.filter((candidate) => String(candidate?.app?.slug || '') === 'github-actions'
|
|
112
|
+
&& String(candidate?.name || '') === String(check?.name || '')
|
|
113
|
+
&& String(candidate?.details_url || '') === String(check?.detailsUrl || '')
|
|
114
|
+
&& String(candidate?.status || '').toUpperCase() === String(check?.status || '').toUpperCase()
|
|
115
|
+
&& String(candidate?.conclusion || '').toUpperCase() === String(check?.conclusion || '').toUpperCase());
|
|
116
|
+
if (matches.length !== 1) return '';
|
|
117
|
+
const id = String(matches[0]?.id || '');
|
|
118
|
+
return /^\d+$/.test(id) ? id : '';
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function isBillingBlockedCheckRun(repoRoot, check, expectedCheckRunId, runner = run) {
|
|
122
|
+
const jobId = githubActionsJobId(check);
|
|
123
|
+
if (!jobId || !expectedCheckRunId) return false;
|
|
124
|
+
|
|
125
|
+
const jobResult = runner(GH_BIN, [
|
|
126
|
+
'api',
|
|
127
|
+
repoApiPath(repoRoot, `actions/jobs/${jobId}`, runner),
|
|
128
|
+
], { cwd: repoRoot, timeout: 60_000, allowFailure: true });
|
|
129
|
+
if (jobResult.status !== 0) return false;
|
|
130
|
+
|
|
131
|
+
let job;
|
|
132
|
+
try {
|
|
133
|
+
job = JSON.parse(String(jobResult.stdout || ''));
|
|
134
|
+
} catch (_error) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
if (String(job?.status || '').toLowerCase() !== 'completed'
|
|
138
|
+
|| String(job?.conclusion || '').toLowerCase() !== 'failure'
|
|
139
|
+
|| job?.runner_id !== 0
|
|
140
|
+
|| String(job?.runner_name || '') !== ''
|
|
141
|
+
|| !Array.isArray(job?.steps)
|
|
142
|
+
|| job.steps.length !== 0) return false;
|
|
143
|
+
|
|
144
|
+
const annotationsPath = githubCheckRunAnnotationsPath(job, expectedCheckRunId);
|
|
145
|
+
if (!annotationsPath) return false;
|
|
146
|
+
|
|
147
|
+
const result = runner(GH_BIN, [
|
|
148
|
+
'api',
|
|
149
|
+
repoApiPath(repoRoot, annotationsPath, runner),
|
|
150
|
+
], { cwd: repoRoot, timeout: 60_000, allowFailure: true });
|
|
151
|
+
if (result.status !== 0) return false;
|
|
152
|
+
|
|
153
|
+
let annotations;
|
|
154
|
+
try {
|
|
155
|
+
annotations = JSON.parse(String(result.stdout || ''));
|
|
156
|
+
} catch (_error) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
if (!Array.isArray(annotations) || annotations.length !== 1) return false;
|
|
160
|
+
|
|
161
|
+
const [annotation] = annotations;
|
|
162
|
+
return annotation?.path === '.github'
|
|
163
|
+
&& Number(annotation?.start_line) === 1
|
|
164
|
+
&& String(annotation?.annotation_level || '').toLowerCase() === 'failure'
|
|
165
|
+
&& String(annotation?.title || '') === ''
|
|
166
|
+
&& String(annotation?.raw_details || '') === ''
|
|
167
|
+
&& BILLING_BLOCKED_JOB_MESSAGE.test(String(annotation?.message || '').trim());
|
|
168
|
+
}
|
|
169
|
+
|
|
60
170
|
/**
|
|
61
171
|
* Resolve the PR for `branch` if any exists on the origin remote.
|
|
62
172
|
* Returns null when no PR is open (or any are merged / closed only).
|
|
@@ -249,7 +359,15 @@ function getPullRequestStatus(repoRoot, branch) {
|
|
|
249
359
|
const pr = findOpenPrForBranch(repoRoot, branch);
|
|
250
360
|
if (!pr) return null;
|
|
251
361
|
|
|
252
|
-
|
|
362
|
+
let checkRuns;
|
|
363
|
+
const expectedCheckRunId = (check) => {
|
|
364
|
+
if (!checkRuns) checkRuns = commitCheckRuns(repoRoot, pr.headRefOid);
|
|
365
|
+
return matchingCheckRunId(check, checkRuns);
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const rollup = summarizeStatusCheckRollup(pr.statusCheckRollup, {
|
|
369
|
+
isWaived: (check) => isBillingBlockedCheckRun(repoRoot, check, expectedCheckRunId(check)),
|
|
370
|
+
});
|
|
253
371
|
|
|
254
372
|
return {
|
|
255
373
|
number: pr.number,
|
|
@@ -268,6 +386,7 @@ function getPullRequestStatus(repoRoot, branch) {
|
|
|
268
386
|
base: pr.baseRefName,
|
|
269
387
|
checks: rollup.summary,
|
|
270
388
|
failedNames: rollup.failedNames,
|
|
389
|
+
billingWaivedNames: rollup.waivedNames,
|
|
271
390
|
supersededChecks: rollup.supersededCount,
|
|
272
391
|
};
|
|
273
392
|
}
|
|
@@ -491,6 +610,8 @@ module.exports = {
|
|
|
491
610
|
pushBranch,
|
|
492
611
|
openPullRequest,
|
|
493
612
|
getPullRequestStatus,
|
|
613
|
+
githubActionsJobId,
|
|
614
|
+
isBillingBlockedCheckRun,
|
|
494
615
|
checkOutcomes,
|
|
495
616
|
baselineFailures,
|
|
496
617
|
enableAutoMerge,
|
package/src/scaffold/index.js
CHANGED
|
@@ -716,6 +716,16 @@ function buildRepoVscodeSettings(existingSettings = {}) {
|
|
|
716
716
|
? existingSettings[REPO_SCAN_IGNORED_FOLDERS_SETTING]
|
|
717
717
|
: [];
|
|
718
718
|
|
|
719
|
+
// Keep normal subfolder discovery, but do not auto-register a worktree just
|
|
720
|
+
// because one of its files was opened in the primary workspace. Otherwise
|
|
721
|
+
// pruning it can leave a stale, endlessly syncing SCM provider behind.
|
|
722
|
+
if (existingSettings['git.autoRepositoryDetection'] !== false) {
|
|
723
|
+
nextSettings['git.autoRepositoryDetection'] = 'subFolders';
|
|
724
|
+
}
|
|
725
|
+
// Repository scan ignores do not affect VS Code's separate Git worktree
|
|
726
|
+
// detector. Disable it for the primary checkout so a removed Guardex
|
|
727
|
+
// worktree cannot remain registered as an endlessly syncing SCM provider.
|
|
728
|
+
nextSettings['git.detectWorktrees'] = false;
|
|
719
729
|
nextSettings[REPO_SCAN_IGNORED_FOLDERS_SETTING] = uniqueStringList([
|
|
720
730
|
...existingIgnoredFolders,
|
|
721
731
|
...MANAGED_REPO_SCAN_IGNORED_FOLDERS,
|
|
@@ -5,31 +5,51 @@
|
|
|
5
5
|
|
|
6
6
|
Guardex is enabled by default. Disable via repo-root `.env` with `GUARDEX_ON=0|false|no|off`. Re-enable with `GUARDEX_ON=1`.
|
|
7
7
|
|
|
8
|
+
Worktree policy defaults to strict `always`. Opt a repository into adaptive
|
|
9
|
+
routing with `GUARDEX_WORKTREE_MODE=adaptive` in `.env` or
|
|
10
|
+
`git config --local multiagent.worktreeMode adaptive`.
|
|
11
|
+
|
|
8
12
|
### Core rules
|
|
9
13
|
|
|
10
|
-
-
|
|
11
|
-
-
|
|
14
|
+
- In strict `always` mode, work from an `agent/*` branch + worktree. **Never** edit the protected base directly.
|
|
15
|
+
- In adaptive mode, bounded single-agent work may remain on the current checkout after the radar and ownership checks below pass.
|
|
16
|
+
- Claim files before editing in isolated lanes. Confirm a path is in your claim before deleting it.
|
|
12
17
|
- Commit, push, and open/update a PR for completed work unless the user says keep-local.
|
|
13
18
|
- Keep outputs and notes compact. Less word, same proof.
|
|
14
19
|
|
|
15
20
|
### Task-size routing
|
|
16
21
|
|
|
17
|
-
Small tasks stay direct and caveman-only
|
|
22
|
+
Small tasks stay direct and caveman-only when adaptive mode is enabled and no
|
|
23
|
+
other writer or overlapping change is present. Strict mode still isolates them.
|
|
18
24
|
|
|
19
25
|
For typos, single-file tweaks, one-liners, version bumps, comment-only changes, or similarly bounded asks, solve directly and do not escalate into heavy orchestration just because a keyword appears.
|
|
20
26
|
|
|
21
27
|
Lightweight escape prefixes: `quick:`, `simple:`, `tiny:`, `minor:`, `small:`, `just:`, `only:`.
|
|
22
28
|
|
|
23
|
-
Promote to
|
|
29
|
+
Promote to an isolated Guardex lane when scope grows into a multi-file behavior
|
|
30
|
+
change, API/schema work, refactor, migration, architecture, cross-cutting or
|
|
31
|
+
long-lived work, or multi-agent execution. Orchestration alone does not require
|
|
32
|
+
OpenSpec.
|
|
24
33
|
|
|
25
34
|
OpenSpec is opt-in. Do not create or update OpenSpec artifacts unless the user asks for them, the task continues an existing OpenSpec change, or an explicit T2/T3 workflow is selected.
|
|
26
35
|
|
|
36
|
+
### Adaptive lane selection
|
|
37
|
+
|
|
38
|
+
Before direct edits, run `gx status`, inspect active lanes with
|
|
39
|
+
`gx mcp list-agents --no-prs`, and check every intended path with
|
|
40
|
+
`gx mcp who-owns <file>`. Also inspect the current checkout's dirty paths.
|
|
41
|
+
|
|
42
|
+
Stay direct only for bounded work when no competing writer, ownership claim, or
|
|
43
|
+
dirty-path overlap exists. Pivot before editing (or before expanding scope) if
|
|
44
|
+
another writer appears, a target is owned/dirty elsewhere, or the task becomes
|
|
45
|
+
substantial or long-lived.
|
|
46
|
+
|
|
27
47
|
### Isolation (the load-bearing rule)
|
|
28
48
|
|
|
29
|
-
|
|
49
|
+
Start an isolated lane with:
|
|
30
50
|
|
|
31
51
|
```bash
|
|
32
|
-
gx branch start "<task>" "<agent-name>"
|
|
52
|
+
gx branch start --new --no-transfer "<task>" "<agent-name>"
|
|
33
53
|
```
|
|
34
54
|
|
|
35
55
|
Then `cd` into the printed worktree path. Every subsequent git command runs from inside that worktree.
|
|
@@ -38,7 +58,8 @@ If a worktree is already open for this chat/session, **continue in it** instead
|
|
|
38
58
|
|
|
39
59
|
### Primary-tree lock
|
|
40
60
|
|
|
41
|
-
|
|
61
|
+
In strict mode, or after adaptive routing selects isolation, do not run these on
|
|
62
|
+
the primary checkout:
|
|
42
63
|
|
|
43
64
|
```bash
|
|
44
65
|
git checkout <ref> git switch <ref>
|
|
@@ -46,7 +67,13 @@ git switch -c ... git checkout -b ...
|
|
|
46
67
|
git worktree add <p> <agent-branch>
|
|
47
68
|
```
|
|
48
69
|
|
|
49
|
-
|
|
70
|
+
In adaptive direct mode, ordinary bounded edits/commits/pushes are allowed after
|
|
71
|
+
the radar preflight passes. Branch switching and worktree manipulation still use
|
|
72
|
+
`gx branch start` rather than raw Git commands.
|
|
73
|
+
|
|
74
|
+
The protected-main shell allowlist covers `git add`/ordinary commit/push and
|
|
75
|
+
bounded test/lint/build commands. Custom executors, scripts, or history rewrites
|
|
76
|
+
require an isolated lane.
|
|
50
77
|
|
|
51
78
|
If you are about to type `git checkout agent/...` from the primary checkout, **stop** — that is the mistake that flips primary onto an agent branch.
|
|
52
79
|
|
|
@@ -80,7 +107,8 @@ No long proof dumps, no stale narrative, no full logs. Bulky proof goes in PRs o
|
|
|
80
107
|
|
|
81
108
|
### Completion
|
|
82
109
|
|
|
83
|
-
Finish
|
|
110
|
+
Direct adaptive work uses the repository's ordinary commit/push flow. Finish an
|
|
111
|
+
isolated lane with:
|
|
84
112
|
|
|
85
113
|
```bash
|
|
86
114
|
gx branch finish --branch "<agent-branch>" --via-pr --wait-for-merge --cleanup
|
|
@@ -2,11 +2,17 @@
|
|
|
2
2
|
## Multi-Agent Safety (minimal)
|
|
3
3
|
|
|
4
4
|
Guardex is enabled by default. Disable via repo-root `.env` with `GUARDEX_ON=0`.
|
|
5
|
+
Worktrees default to strict `always` mode. Repositories that prefer a faster
|
|
6
|
+
single-agent path may opt in with `GUARDEX_WORKTREE_MODE=adaptive` in `.env` (or
|
|
7
|
+
`git config --local multiagent.worktreeMode adaptive`).
|
|
5
8
|
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
9
|
+
- In adaptive mode, small single-agent work may stay on the current checkout only after `gx status`, `gx mcp list-agents --no-prs`, and `gx mcp who-owns <file>` show no competing writer or target-file ownership.
|
|
10
|
+
- Direct protected-main shell work is limited to `git add`/ordinary commit/push and bounded test/lint/build commands; custom executors or history rewrites use an isolated lane.
|
|
11
|
+
- Pivot to an isolated lane when the task is substantial/long-lived, another writer is active in the repo, a target path is dirty or owned elsewhere, or scope expands. Use `gx branch start --new --no-transfer "<task>" "<agent-name>"`, then `cd` into the printed worktree.
|
|
12
|
+
- In strict `always` mode, work from an `agent/*` branch + worktree and never edit the protected base (`main`/`dev`) directly.
|
|
13
|
+
- In an isolated lane, claim files before editing: `gx locks claim --branch "<agent-branch>" <file...>`.
|
|
14
|
+
- Finish isolated work via PR + cleanup: `gx branch finish --branch "<agent-branch>" --via-pr --wait-for-merge --cleanup` (or `gx finish --all`). Direct adaptive work uses the repository's ordinary commit/push flow.
|
|
15
|
+
- For isolated lanes, default to the self-repairing gated ship — add `--gate-review --gate-autofix` so blocking findings are fixed and re-verified before the merge instead of leaving the PR open. Add `--gate-baseline` only where the base branch CI is already red. CI waits until the review is clean by default; `--no-gate-serial-ci` opts into overlap. Codex code-assist defaults to bounded `medium` effort (override with `GUARDEX_REVIEW_CODEX_EFFORT`). Posting a review is not merging: `gx pr-review` posts and exits; only `gx branch finish` merges.
|
|
10
16
|
|
|
11
17
|
Want the full multi-agent contract (Colony coordination, OpenSpec, token discipline, recovery)? Run `gx setup --contract`.
|
|
12
18
|
<!-- multiagent-safety:END -->
|