@imdeadpool/guardex 8.4.0 → 8.4.2
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/CONTRIBUTING.md +13 -4
- package/README.md +223 -1
- package/THIRD-PARTY-NOTICES.md +29 -0
- package/bin/multiagent-safety.js +9 -12
- package/package.json +4 -2
- package/skills/gitguardex/SKILL.md +28 -0
- package/skills/pr-lens/SKILL.md +87 -0
- package/src/abide.js +534 -0
- package/src/agents/activity.js +23 -4
- package/src/agents/inspect.js +15 -6
- package/src/agents/launch.js +6 -1
- package/src/agents/process-lease.js +84 -0
- package/src/agents/sessions.js +96 -16
- package/src/agents/start.js +18 -9
- package/src/agents/status.js +35 -14
- package/src/agents/supervise.js +87 -0
- package/src/budget/index.js +6 -1
- package/src/cli/args.js +71 -77
- package/src/cli/commands/agents.js +38 -10
- package/src/cli/commands/branch.js +116 -103
- package/src/cli/commands/claude.js +604 -50
- package/src/cli/commands/codex.js +359 -0
- package/src/cli/commands/context.js +52 -0
- package/src/cli/commands/mcp.js +5 -1
- package/src/cli/commands/pr.js +138 -3
- package/src/cli/commands/review.js +3 -1
- package/src/cli/commands/setup.js +25 -0
- package/src/cli/commands/status.js +128 -60
- package/src/cli/commands/storage.js +24 -0
- package/src/cli/commands/usage.js +48 -0
- package/src/cli/commands/watch.js +157 -47
- package/src/cli/commands/worktree-copy-ignored.js +38 -0
- package/src/cli/commands/worktree-estimate.js +69 -0
- package/src/cli/commands/worktree-hooks.js +62 -0
- package/src/cli/commands/worktree-navigation.js +71 -0
- package/src/cli/commands/worktree-provision.js +92 -0
- package/src/cli/main.js +229 -110
- package/src/cli/shared/gate-flags.js +131 -0
- package/src/cli/shared/scaffolding.js +31 -3
- package/src/cli/shared-locks.js +3 -1
- package/src/cockpit/pane-actions.js +43 -7
- package/src/context.js +373 -17
- package/src/doctor/index.js +29 -35
- package/src/finish/events.js +254 -0
- package/src/finish/index.js +322 -62
- package/src/finish/post-branch-finish-cleanup.js +316 -22
- package/src/finish/preflight.js +44 -1
- package/src/finish/progress.js +36 -0
- package/src/finish/review-gate.js +317 -127
- package/src/finish/review-receipt.js +156 -0
- package/src/finish/with-claims-lock.py +29 -0
- package/src/git/index.js +179 -42
- package/src/hooks/index.js +68 -3
- package/src/mcp/collect.js +61 -5
- package/src/mcp/server.js +4 -0
- package/src/output/index.js +167 -1
- package/src/pr-lens-publish.js +93 -0
- package/src/pr-lens.js +184 -0
- package/src/pr-respond.js +860 -0
- package/src/pr-review.js +519 -159
- package/src/pr.js +73 -14
- package/src/provider-binary.js +21 -0
- package/src/review-diff-context.js +90 -0
- package/src/review-fix.js +23 -17
- package/src/scaffold/agent-worktree-prep.js +14 -12
- package/src/scaffold/dependency-store.js +234 -0
- package/src/scaffold/index.js +13 -1
- package/src/scaffold/provision-approvals.js +83 -0
- package/src/scaffold/provision-config.js +169 -40
- package/src/shared-git-state.js +11 -1
- package/src/speckit/index.js +12 -1
- package/src/storage/run-artifacts.js +185 -0
- package/src/toolchain/index.js +322 -2
- package/src/worktree-copy-ignored.js +200 -0
- package/src/worktree-hook-worker.js +29 -0
- package/src/worktree-hooks.js +333 -0
- package/src/worktree-navigation.js +248 -0
- package/src/worktree-picker.js +89 -0
- package/src/worktree-quota.js +100 -0
- package/src/worktree-start.js +100 -0
- package/templates/AGENTS.multiagent-safety.md +8 -0
- package/templates/AGENTS.multiagent-safety.min.md +3 -1
- package/templates/codex/skills/gitguardex/SKILL.md +28 -0
- package/templates/codex/skills/opensrc/SKILL.md +24 -0
- package/templates/githooks/post-merge +16 -2
- package/templates/scripts/agent-autofinish-watch.sh +17 -18
- package/templates/scripts/agent-branch-finish.sh +180 -19
- package/templates/scripts/agent-branch-merge.sh +7 -32
- package/templates/scripts/agent-branch-start.sh +202 -43
- package/templates/scripts/agent-claude-stop-finish.sh +4 -27
- package/templates/scripts/agent-file-locks.py +257 -29
- package/templates/scripts/agent-preflight.sh +3 -0
- package/templates/scripts/agent-worktree-prune.sh +975 -63
- package/templates/scripts/codex-agent.sh +55 -5
- package/templates/scripts/lib/guardex-base-branch.sh +207 -0
- package/templates/scripts/openspec/init-change-workspace.sh +10 -18
- package/templates/scripts/review-bot-watch.sh +171 -4
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
// `gx codex` — Codex hook wiring for abide (github.com/coldteadotai/abide).
|
|
2
|
+
//
|
|
3
|
+
// gx codex install write abide's four rule hooks into .codex/hooks.json
|
|
4
|
+
// gx codex check diagnose the wiring (read-only)
|
|
5
|
+
// gx codex doctor alias for `check --fix`
|
|
6
|
+
// gx codex uninstall remove the abide entries (--yes required)
|
|
7
|
+
//
|
|
8
|
+
// Codex reads the same hooks JSON shape as Claude Code, from .codex/hooks.json.
|
|
9
|
+
// The entries point at the repo's own shim, .claude/hooks/abide_hook.js, in the
|
|
10
|
+
// exact form abide's installer uses (`node "<absolute path>" <event>`), so no
|
|
11
|
+
// assumption is made about the shell or cwd Codex runs hooks with. The path is
|
|
12
|
+
// this checkout's, so `check` flags a moved clone and `doctor` rewrites it.
|
|
13
|
+
// Codex trusts new hooks once: start codex, type /hooks, accept the entries.
|
|
14
|
+
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
const { TOOL_NAME, SHORT_TOOL_NAME } = require('../../context');
|
|
18
|
+
const { resolveRepoRoot } = require('../../git');
|
|
19
|
+
const abide = require('../../abide');
|
|
20
|
+
const { mergeSettings, installHooks } = require('./claude');
|
|
21
|
+
|
|
22
|
+
const HOOKS_REL = '.codex/hooks.json';
|
|
23
|
+
const CODEX_AFTERWARDS =
|
|
24
|
+
'Codex trusts new hooks once: start codex, type /hooks, accept the four abide entries.';
|
|
25
|
+
|
|
26
|
+
function logInfo(msg) {
|
|
27
|
+
console.log(`[${TOOL_NAME}] ${msg}`);
|
|
28
|
+
}
|
|
29
|
+
function logOk(msg) {
|
|
30
|
+
console.log(`[${TOOL_NAME}] ✅ ${msg}`);
|
|
31
|
+
}
|
|
32
|
+
function logWarn(msg) {
|
|
33
|
+
console.log(`[${TOOL_NAME}] ⚠️ ${msg}`);
|
|
34
|
+
}
|
|
35
|
+
function logError(msg) {
|
|
36
|
+
console.error(`[${TOOL_NAME}] ❌ ${msg}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function readJsonIfExists(filePath) {
|
|
40
|
+
if (!fs.existsSync(filePath)) return null;
|
|
41
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
42
|
+
if (!raw.trim()) return null;
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(raw);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
throw new Error(`Failed to parse JSON at ${filePath}: ${error.message}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function writeJson(filePath, value) {
|
|
51
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
52
|
+
fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function shimPath(repoRoot) {
|
|
56
|
+
return path.join(repoRoot, abide.ABIDE_SHIM_REL);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The entries this checkout wants: abide's own command shape, pointing at the shim.
|
|
60
|
+
function codexHooksTemplate(repoRoot) {
|
|
61
|
+
const hooks = {};
|
|
62
|
+
for (const spec of abide.ABIDE_HOOK_SPECS) {
|
|
63
|
+
hooks[spec.event] = [
|
|
64
|
+
{
|
|
65
|
+
...(spec.matcher ? { matcher: spec.matcher } : {}),
|
|
66
|
+
hooks: [
|
|
67
|
+
{
|
|
68
|
+
type: 'command',
|
|
69
|
+
command: `node "${shimPath(repoRoot)}" ${spec.arg}`,
|
|
70
|
+
timeout: spec.timeout
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
return { hooks };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function codexHooksStatus(repoRoot) {
|
|
80
|
+
const file = path.join(repoRoot, HOOKS_REL);
|
|
81
|
+
const settings = readJsonIfExists(file);
|
|
82
|
+
const entries = abide.abideHookEntries(settings);
|
|
83
|
+
const present = Object.keys(entries);
|
|
84
|
+
const wanted = shimPath(repoRoot);
|
|
85
|
+
// A command that names this checkout's shim is current; any other abide
|
|
86
|
+
// command (another clone's path, or abide's own package path) is not.
|
|
87
|
+
const current = present.filter((e) =>
|
|
88
|
+
entries[e].some((entry) => entry.command.includes(`"${wanted}"`))
|
|
89
|
+
);
|
|
90
|
+
const missingEvents = abide.ABIDE_HOOK_EVENTS.filter((e) => !current.includes(e));
|
|
91
|
+
const foreign = [
|
|
92
|
+
...new Set(
|
|
93
|
+
present.flatMap((e) =>
|
|
94
|
+
entries[e]
|
|
95
|
+
.filter((entry) => !entry.command.includes(`"${wanted}"`))
|
|
96
|
+
.map((entry) => entry.command)
|
|
97
|
+
)
|
|
98
|
+
)
|
|
99
|
+
];
|
|
100
|
+
return { file, present, current, missingEvents, foreign, shimFileExists: fs.existsSync(wanted) };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function pruneAbideEntries(repoRoot, { dryRun }) {
|
|
104
|
+
const file = path.join(repoRoot, HOOKS_REL);
|
|
105
|
+
const settings = readJsonIfExists(file);
|
|
106
|
+
if (!settings || !settings.hooks) return { status: 'absent', dest: file };
|
|
107
|
+
let removed = 0;
|
|
108
|
+
for (const eventName of Object.keys(settings.hooks)) {
|
|
109
|
+
const groups = (settings.hooks[eventName] || [])
|
|
110
|
+
.map((group) => {
|
|
111
|
+
const kept = (group.hooks || []).filter((h) => !abide.isAbideHookCommand(h.command));
|
|
112
|
+
removed += (group.hooks || []).length - kept.length;
|
|
113
|
+
return { ...group, hooks: kept };
|
|
114
|
+
})
|
|
115
|
+
.filter((group) => group.hooks.length > 0);
|
|
116
|
+
if (groups.length === 0) delete settings.hooks[eventName];
|
|
117
|
+
else settings.hooks[eventName] = groups;
|
|
118
|
+
}
|
|
119
|
+
if (removed === 0) return { status: 'absent', dest: file };
|
|
120
|
+
if (!dryRun) writeJson(file, settings);
|
|
121
|
+
return { status: 'pruned', dest: file, removed };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function installCodexHooks(repoRoot, { dryRun }) {
|
|
125
|
+
const before = codexHooksStatus(repoRoot);
|
|
126
|
+
const rewrite = before.foreign.length > 0;
|
|
127
|
+
const wire = before.missingEvents.length > 0 || rewrite;
|
|
128
|
+
if (!wire && before.shimFileExists) return { status: 'unchanged', dest: before.file };
|
|
129
|
+
if (dryRun) return { status: rewrite ? 'would-rewrite' : 'would-install', dest: before.file };
|
|
130
|
+
|
|
131
|
+
// The shim ships with the Claude hook files; install it if the repo lacks it.
|
|
132
|
+
if (!before.shimFileExists) installHooks(repoRoot, { dryRun: false });
|
|
133
|
+
if (wire) {
|
|
134
|
+
pruneAbideEntries(repoRoot, { dryRun: false });
|
|
135
|
+
const settings = readJsonIfExists(before.file);
|
|
136
|
+
writeJson(before.file, mergeSettings(settings, codexHooksTemplate(repoRoot)));
|
|
137
|
+
}
|
|
138
|
+
const after = codexHooksStatus(repoRoot);
|
|
139
|
+
if (after.missingEvents.length > 0 || !after.shimFileExists) {
|
|
140
|
+
return {
|
|
141
|
+
status: 'failed',
|
|
142
|
+
dest: before.file,
|
|
143
|
+
note: `${HOOKS_REL} still lacks: ${after.missingEvents.join(', ') || 'shim file'}`
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
status: rewrite ? 'rewritten' : wire ? 'installed' : 'updated',
|
|
148
|
+
dest: before.file,
|
|
149
|
+
packageDir: abide.resolveShimPackageDir(repoRoot),
|
|
150
|
+
afterwards: CODEX_AFTERWARDS
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function parseArgs(rawArgs) {
|
|
155
|
+
const opts = { target: process.cwd(), dryRun: false, json: false, yes: false, fix: false };
|
|
156
|
+
for (let index = 0; index < rawArgs.length; index += 1) {
|
|
157
|
+
const arg = rawArgs[index];
|
|
158
|
+
if (arg === '--target') {
|
|
159
|
+
opts.target = rawArgs[++index];
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (arg === '--dry-run') {
|
|
163
|
+
opts.dryRun = true;
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (arg === '--json') {
|
|
167
|
+
opts.json = true;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (arg === '--yes' || arg === '-y') {
|
|
171
|
+
opts.yes = true;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (arg === '--fix') {
|
|
175
|
+
opts.fix = true;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return opts;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function runInstall(rawArgs) {
|
|
183
|
+
const opts = parseArgs(rawArgs);
|
|
184
|
+
const repoRoot = resolveRepoRoot(opts.target);
|
|
185
|
+
const result = installCodexHooks(repoRoot, opts);
|
|
186
|
+
if (opts.json) {
|
|
187
|
+
process.stdout.write(
|
|
188
|
+
`${JSON.stringify({ repoRoot, hooks: result, dryRun: opts.dryRun }, null, 2)}\n`
|
|
189
|
+
);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const line = `abide rule hooks (${HOOKS_REL}): ${result.status}${result.note ? ` (${result.note})` : ''}`;
|
|
193
|
+
if (result.status === 'failed') {
|
|
194
|
+
logWarn(line);
|
|
195
|
+
process.exitCode = 1;
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
logInfo(line);
|
|
199
|
+
if (result.packageDir === null)
|
|
200
|
+
logWarn(
|
|
201
|
+
`${abide.ABIDE_PACKAGE} not found on this machine; the hooks stay silent until 'npm i -g ${abide.ABIDE_PACKAGE}'.`
|
|
202
|
+
);
|
|
203
|
+
if (result.afterwards) logInfo(result.afterwards);
|
|
204
|
+
if (!opts.dryRun) logOk('Codex wiring is in place.');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function runCheck(rawArgs) {
|
|
208
|
+
const opts = parseArgs(rawArgs);
|
|
209
|
+
const repoRoot = resolveRepoRoot(opts.target);
|
|
210
|
+
const issues = [];
|
|
211
|
+
let hooks;
|
|
212
|
+
try {
|
|
213
|
+
hooks = codexHooksStatus(repoRoot);
|
|
214
|
+
} catch (error) {
|
|
215
|
+
issues.push({ severity: 'error', kind: 'hooks-parse', message: error.message });
|
|
216
|
+
}
|
|
217
|
+
if (hooks) {
|
|
218
|
+
const install = `run '${SHORT_TOOL_NAME} codex install'`;
|
|
219
|
+
if (hooks.present.length === 0) {
|
|
220
|
+
issues.push({
|
|
221
|
+
severity: 'warning',
|
|
222
|
+
kind: 'abide-missing',
|
|
223
|
+
message: `${HOOKS_REL} has no abide rule hooks (${install}).`
|
|
224
|
+
});
|
|
225
|
+
} else if (hooks.foreign.length > 0) {
|
|
226
|
+
issues.push({
|
|
227
|
+
severity: 'warning',
|
|
228
|
+
kind: 'abide-hook-moved',
|
|
229
|
+
message: `${HOOKS_REL} points at a hook script outside this checkout (${hooks.foreign[0]}); ${install} to rewrite it.`
|
|
230
|
+
});
|
|
231
|
+
} else if (hooks.missingEvents.length > 0) {
|
|
232
|
+
issues.push({
|
|
233
|
+
severity: 'warning',
|
|
234
|
+
kind: 'abide-hook-missing',
|
|
235
|
+
message: `abide hook missing for: ${hooks.missingEvents.join(', ')} (${install}).`
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
if (hooks.current.length > 0 && !hooks.shimFileExists) {
|
|
239
|
+
issues.push({
|
|
240
|
+
severity: 'error',
|
|
241
|
+
kind: 'abide-shim-missing',
|
|
242
|
+
message: `${abide.ABIDE_SHIM_REL} is referenced but missing (${install}).`
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
if (
|
|
246
|
+
hooks.current.length > 0 &&
|
|
247
|
+
hooks.shimFileExists &&
|
|
248
|
+
!abide.resolveShimPackageDir(repoRoot)
|
|
249
|
+
) {
|
|
250
|
+
issues.push({
|
|
251
|
+
severity: 'warning',
|
|
252
|
+
kind: 'abide-unresolved',
|
|
253
|
+
message: `${abide.ABIDE_PACKAGE} is not installed on this machine, so the hooks run silent ('npm i -g ${abide.ABIDE_PACKAGE}').`
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
if (hooks.present.length > 0 && !abide.abideKeySource(repoRoot)) {
|
|
257
|
+
issues.push({
|
|
258
|
+
severity: 'warning',
|
|
259
|
+
kind: 'abide-no-key',
|
|
260
|
+
message: `no ${abide.ABIDE_KEY_NAMES.join(' / ')} found; abide hooks stay silent until 'abide login'.`
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (opts.json) {
|
|
266
|
+
process.stdout.write(`${JSON.stringify({ repoRoot, issues }, null, 2)}\n`);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (issues.length === 0) {
|
|
270
|
+
logOk('Codex wiring looks complete.');
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
logWarn(`${issues.length} issue(s) detected:`);
|
|
274
|
+
for (const issue of issues) {
|
|
275
|
+
console.log(` ${issue.severity === 'error' ? '✗' : '~'} [${issue.kind}] ${issue.message}`);
|
|
276
|
+
}
|
|
277
|
+
if (opts.fix) {
|
|
278
|
+
logInfo('Running install to repair...');
|
|
279
|
+
runInstall(rawArgs.filter((arg) => arg !== '--fix'));
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
logInfo(`Run '${SHORT_TOOL_NAME} codex install' to fix.`);
|
|
283
|
+
process.exitCode = 1;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function runUninstall(rawArgs) {
|
|
287
|
+
const opts = parseArgs(rawArgs);
|
|
288
|
+
const repoRoot = resolveRepoRoot(opts.target);
|
|
289
|
+
if (!opts.yes) {
|
|
290
|
+
logWarn(
|
|
291
|
+
`Refusing to uninstall without --yes. This removes the abide entries from ${HOOKS_REL}.`
|
|
292
|
+
);
|
|
293
|
+
process.exitCode = 1;
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const result = pruneAbideEntries(repoRoot, opts);
|
|
297
|
+
if (opts.json) {
|
|
298
|
+
process.stdout.write(
|
|
299
|
+
`${JSON.stringify({ repoRoot, hooks: result, dryRun: opts.dryRun }, null, 2)}\n`
|
|
300
|
+
);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
logOk(
|
|
304
|
+
result.status === 'pruned'
|
|
305
|
+
? `Removed ${result.removed} abide hook entr${result.removed === 1 ? 'y' : 'ies'} from ${HOOKS_REL}${opts.dryRun ? ' (dry-run)' : ''}.`
|
|
306
|
+
: `No abide entries in ${HOOKS_REL}.`
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function printUsage() {
|
|
311
|
+
console.log(`Usage: ${SHORT_TOOL_NAME} codex <subcommand> [flags]
|
|
312
|
+
|
|
313
|
+
Subcommands:
|
|
314
|
+
install write abide's rule hooks (AGENTS.md / CLAUDE.md enforced on every edit) into ${HOOKS_REL}.
|
|
315
|
+
check diagnose the Codex wiring (read-only by default).
|
|
316
|
+
doctor alias: 'check --fix'.
|
|
317
|
+
uninstall remove the abide entries from ${HOOKS_REL} (--yes required).
|
|
318
|
+
|
|
319
|
+
Flags:
|
|
320
|
+
--target <path> Operate in a different repo directory.
|
|
321
|
+
--dry-run Report what would change without writing.
|
|
322
|
+
--json Emit JSON output.
|
|
323
|
+
--yes / -y Required for uninstall.
|
|
324
|
+
--fix For 'check': run install after diagnosing.
|
|
325
|
+
|
|
326
|
+
${CODEX_AFTERWARDS}
|
|
327
|
+
`);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function codex(rawArgs) {
|
|
331
|
+
const [subRaw, ...rest] = Array.isArray(rawArgs) ? rawArgs : [];
|
|
332
|
+
if (subRaw === '-h' || subRaw === '--help' || subRaw === 'help') {
|
|
333
|
+
printUsage();
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const sub = subRaw || 'check';
|
|
337
|
+
try {
|
|
338
|
+
if (sub === 'install') return runInstall(rest);
|
|
339
|
+
if (sub === 'check') return runCheck(rest);
|
|
340
|
+
if (sub === 'doctor') return runCheck([...rest, '--fix']);
|
|
341
|
+
if (sub === 'uninstall') return runUninstall(rest);
|
|
342
|
+
} catch (error) {
|
|
343
|
+
logError(error && error.message ? error.message : String(error));
|
|
344
|
+
process.exitCode = 1;
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
logError(`Unknown 'codex' subcommand: ${sub}`);
|
|
348
|
+
printUsage();
|
|
349
|
+
process.exitCode = 64;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
module.exports = {
|
|
353
|
+
codex,
|
|
354
|
+
HOOKS_REL,
|
|
355
|
+
codexHooksTemplate,
|
|
356
|
+
codexHooksStatus,
|
|
357
|
+
installCodexHooks,
|
|
358
|
+
pruneAbideEntries
|
|
359
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { editContext } = require('../../mcp/collect');
|
|
4
|
+
|
|
5
|
+
function agentContext(args, deps = {}) {
|
|
6
|
+
const log = deps.log || console.log;
|
|
7
|
+
const delimiter = args.indexOf('--');
|
|
8
|
+
const options = delimiter < 0 ? args : args.slice(0, delimiter);
|
|
9
|
+
if (options.includes('--help') || options.includes('-h')) {
|
|
10
|
+
log(
|
|
11
|
+
'Usage: gx context [file ...] [--target <worktree>] [--max-bytes <bytes>] [--include-prs] [--json]\n' +
|
|
12
|
+
'Read-only repo context, peer agents, and ownership for up to 200 files. Compact JSON is the default.\n' +
|
|
13
|
+
'The default budget is 20000 UTF-8 bytes (JSON body, excluding the trailing newline).\n' +
|
|
14
|
+
'Only optional peer summaries may be omitted; required safety data never is.\n' +
|
|
15
|
+
'PR lookup is opt-in. Use -- before filenames beginning with a dash. This snapshot does not grant edit permission.'
|
|
16
|
+
);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const files = [];
|
|
20
|
+
let cwd = process.cwd();
|
|
21
|
+
let maxBytes = 20000;
|
|
22
|
+
let includePrs = false;
|
|
23
|
+
for (let index = 0; index < args.length; index++) {
|
|
24
|
+
const arg = args[index];
|
|
25
|
+
if (arg === '--') {
|
|
26
|
+
files.push(...args.slice(index + 1));
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
if (arg === '--target' || arg === '--max-bytes') {
|
|
30
|
+
const value = args[++index];
|
|
31
|
+
if (!value || value.startsWith('--')) throw new Error(`Missing value for ${arg}`);
|
|
32
|
+
if (arg === '--target') cwd = value;
|
|
33
|
+
else {
|
|
34
|
+
if (!/^\d+$/.test(value))
|
|
35
|
+
throw new Error('--max-bytes must be an integer between 1 and 1048576');
|
|
36
|
+
maxBytes = Number(value);
|
|
37
|
+
}
|
|
38
|
+
} else if (arg === '--include-prs') includePrs = true;
|
|
39
|
+
else if (arg === '--json') continue;
|
|
40
|
+
else if (arg.startsWith('-')) throw new Error(`Unknown context option: ${arg}`);
|
|
41
|
+
else files.push(arg);
|
|
42
|
+
}
|
|
43
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > 1048576) {
|
|
44
|
+
throw new Error('--max-bytes must be an integer between 1 and 1048576');
|
|
45
|
+
}
|
|
46
|
+
const result = (deps.editContext || editContext)({ cwd, files, includePrs, maxBytes });
|
|
47
|
+
log(JSON.stringify(result));
|
|
48
|
+
if (result.error || result.ownership?.some((entry) => entry.error)) process.exitCode = 1;
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = { agentContext };
|
package/src/cli/commands/mcp.js
CHANGED
|
@@ -117,7 +117,11 @@ function mcp(rawArgs = []) {
|
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
printUsage();
|
|
120
|
-
|
|
120
|
+
// A help flag is a request for this usage, not an unknown subcommand —
|
|
121
|
+
// exiting 1 on it reads as "the command failed" to anything checking the
|
|
122
|
+
// status.
|
|
123
|
+
const askedForHelp = subcommand === '--help' || subcommand === '-h';
|
|
124
|
+
process.exitCode = subcommand && !askedForHelp ? 1 : 0;
|
|
121
125
|
}
|
|
122
126
|
|
|
123
127
|
module.exports = { mcp };
|
package/src/cli/commands/pr.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// gx pr list list open PRs for the current repo
|
|
10
10
|
// gx pr ready promote draft -> ready for review
|
|
11
11
|
// gx pr review hand off to existing pr-review provider flow
|
|
12
|
+
// gx pr respond auto-fix blocking review threads on an agent PR
|
|
12
13
|
//
|
|
13
14
|
// This is the thin glue layer; logic lives in src/pr.js.
|
|
14
15
|
|
|
@@ -126,6 +127,22 @@ function renderChecksLine(checks) {
|
|
|
126
127
|
return parts.length ? parts.join(', ') : `${checks.total} checks`;
|
|
127
128
|
}
|
|
128
129
|
|
|
130
|
+
/** Returns the detail suffix for a checks-failed error: URL + failing check names. */
|
|
131
|
+
function buildChecksFailedDetail(pr) {
|
|
132
|
+
const url = pr?.url ? ` (${pr.url})` : '';
|
|
133
|
+
const names = pr?.failedNames?.length
|
|
134
|
+
? `\n Failed checks: ${pr.failedNames.join(', ')}`
|
|
135
|
+
: '';
|
|
136
|
+
return `${url}${names}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Returns the detail suffix for a timeout warning: URL + current check summary. */
|
|
140
|
+
function buildTimeoutDetail(pr) {
|
|
141
|
+
const url = pr?.url ? ` (${pr.url})` : '';
|
|
142
|
+
const checks = pr?.checks ? ` — ${renderChecksLine(pr.checks)}` : '';
|
|
143
|
+
return `${url}${checks}`;
|
|
144
|
+
}
|
|
145
|
+
|
|
129
146
|
function emitStatusText(snapshot) {
|
|
130
147
|
if (!snapshot) {
|
|
131
148
|
console.log('no open PR for this branch');
|
|
@@ -275,12 +292,12 @@ async function cmdWatch(opts) {
|
|
|
275
292
|
if (result.status === 'merged') return;
|
|
276
293
|
if (result.status === 'checks-failed') {
|
|
277
294
|
process.exitCode = 2;
|
|
278
|
-
logError(
|
|
295
|
+
logError(`CI checks failed. Investigate the PR before retrying.${buildChecksFailedDetail(result.pr)}`);
|
|
279
296
|
return;
|
|
280
297
|
}
|
|
281
298
|
if (result.status === 'timeout') {
|
|
282
299
|
process.exitCode = 3;
|
|
283
|
-
logWarn(
|
|
300
|
+
logWarn(`Timed out waiting for PR to merge.${buildTimeoutDetail(result.pr)}`);
|
|
284
301
|
return;
|
|
285
302
|
}
|
|
286
303
|
if (result.status === 'closed') {
|
|
@@ -354,6 +371,113 @@ function cmdReady(opts) {
|
|
|
354
371
|
}
|
|
355
372
|
}
|
|
356
373
|
|
|
374
|
+
/**
|
|
375
|
+
* Parse `gx pr respond` arguments. Kept separate from parsePrArgs because the
|
|
376
|
+
* respond subcommand has its own flag set and does not need most of the base
|
|
377
|
+
* PR flags (no --draft, --auto-merge, etc.).
|
|
378
|
+
*/
|
|
379
|
+
function parseRespondArgs(rawArgs) {
|
|
380
|
+
const opts = {
|
|
381
|
+
target: process.cwd(),
|
|
382
|
+
pr: null,
|
|
383
|
+
provider: null,
|
|
384
|
+
model: null,
|
|
385
|
+
timeoutMs: null,
|
|
386
|
+
dryRun: false,
|
|
387
|
+
json: false,
|
|
388
|
+
};
|
|
389
|
+
for (let index = 0; index < rawArgs.length; index += 1) {
|
|
390
|
+
const arg = rawArgs[index];
|
|
391
|
+
if (arg === '--target') { opts.target = rawArgs[++index]; continue; }
|
|
392
|
+
if (arg === '--pr') {
|
|
393
|
+
const value = String(rawArgs[++index] ?? '');
|
|
394
|
+
if (!/^[1-9]\d*$/.test(value)) {
|
|
395
|
+
throw new Error(`Invalid --pr: expected a PR number, got '${value}'`);
|
|
396
|
+
}
|
|
397
|
+
opts.pr = value;
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (arg === '--provider') { opts.provider = rawArgs[++index]; continue; }
|
|
401
|
+
if (arg === '--model') { opts.model = rawArgs[++index]; continue; }
|
|
402
|
+
if (arg === '--timeout') {
|
|
403
|
+
const seconds = parseFloat(rawArgs[++index]);
|
|
404
|
+
if (!Number.isFinite(seconds) || seconds <= 0) {
|
|
405
|
+
throw new Error(`Invalid --timeout: ${rawArgs[index]}`);
|
|
406
|
+
}
|
|
407
|
+
opts.timeoutMs = Math.round(seconds * 1000);
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (arg === '--dry-run') { opts.dryRun = true; continue; }
|
|
411
|
+
if (arg === '--json') { opts.json = true; continue; }
|
|
412
|
+
}
|
|
413
|
+
return opts;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function cmdRespond(rawArgs) {
|
|
417
|
+
const opts = parseRespondArgs(rawArgs);
|
|
418
|
+
if (!opts.pr) {
|
|
419
|
+
logError("'gx pr respond' requires --pr <number>");
|
|
420
|
+
process.exitCode = 1;
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const { prRespond } = require('../../pr-respond');
|
|
425
|
+
const result = prRespond({
|
|
426
|
+
pr: opts.pr,
|
|
427
|
+
target: opts.target,
|
|
428
|
+
provider: opts.provider || undefined,
|
|
429
|
+
model: opts.model || undefined,
|
|
430
|
+
timeoutMs: opts.timeoutMs || undefined,
|
|
431
|
+
dryRun: opts.dryRun,
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
if (opts.json) {
|
|
435
|
+
process.stdout.write(JSON.stringify(result, null, 2) + '\n');
|
|
436
|
+
if (result.status === 'skipped' || result.status === 'fix-failed' || result.status === 'push-failed') {
|
|
437
|
+
process.exitCode = 1;
|
|
438
|
+
}
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (result.status === 'skipped') {
|
|
443
|
+
logWarn(`Skipped: ${result.reason}`);
|
|
444
|
+
process.exitCode = 1;
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
if (result.status === 'no-threads') {
|
|
448
|
+
logInfo(`PR #${opts.pr}: no blocking review threads found.`);
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
if (result.status === 'dry-run') {
|
|
452
|
+
logInfo(`PR #${opts.pr}: dry run — would fix ${result.findings.length} thread(s) in ${result.worktreePath}`);
|
|
453
|
+
for (const finding of result.findings) {
|
|
454
|
+
logInfo(` [${finding.severity.toUpperCase()}] ${finding.path}:${finding.line} — ${finding.message.slice(0, 80)}`);
|
|
455
|
+
}
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (result.status === 'no-op') {
|
|
459
|
+
logInfo(`PR #${opts.pr}: fix ran but made no file changes (${result.reason || 'provider no-op'}).`);
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
if (result.status === 'fix-failed') {
|
|
463
|
+
logError(`Fix failed: ${result.reason}`);
|
|
464
|
+
process.exitCode = 1;
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
if (result.status === 'push-failed') {
|
|
468
|
+
logError(`Fix committed (${result.fixSha}) but push failed: ${result.reason}`);
|
|
469
|
+
process.exitCode = 1;
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
// 'fixed'
|
|
473
|
+
logOk(
|
|
474
|
+
`PR #${opts.pr}: fixed ${result.changedFiles.length} file(s), pushed ${result.fixSha ? result.fixSha.slice(0, 8) : ''}, resolved ${result.resolved.length}/${result.threads.length} thread(s).`,
|
|
475
|
+
);
|
|
476
|
+
if (result.skippedReply.length > 0) {
|
|
477
|
+
logInfo(` ${result.skippedReply.length} thread(s) left open (fix did not touch the thread's lines, re-review unconfirmed or still blocking, or human thread awaiting the reviewer).`);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
357
481
|
function printUsage() {
|
|
358
482
|
console.log(`Usage: ${SHORT_TOOL_NAME} pr <subcommand> [flags]
|
|
359
483
|
|
|
@@ -365,6 +489,7 @@ Subcommands:
|
|
|
365
489
|
list List open PRs in this repo.
|
|
366
490
|
ready Promote a draft PR to ready-for-review.
|
|
367
491
|
review Run AI PR review (codex/claude provider).
|
|
492
|
+
respond Auto-fix blocking review threads on an agent PR.
|
|
368
493
|
|
|
369
494
|
Flags:
|
|
370
495
|
--target <path> Operate in a different repo directory.
|
|
@@ -377,9 +502,15 @@ Flags:
|
|
|
377
502
|
--ready After open/sync, promote draft -> ready.
|
|
378
503
|
--auto-merge After open/sync, enable auto-merge.
|
|
379
504
|
--merge-strategy <s> squash (default) | merge | rebase.
|
|
380
|
-
--timeout <secs> For watch: max wait time
|
|
505
|
+
--timeout <secs> For watch: max wait time (default 600). For respond: fix/re-review provider timeout.
|
|
381
506
|
--interval <secs> For watch: poll interval. Default 5.
|
|
382
507
|
--json Emit JSON instead of human-readable output.
|
|
508
|
+
|
|
509
|
+
respond-specific flags:
|
|
510
|
+
--pr <number> PR number to respond to (required for 'respond').
|
|
511
|
+
--provider <name> codex|claude (default: codex).
|
|
512
|
+
--model <name> Override model for the fix provider.
|
|
513
|
+
--dry-run Show what would be fixed without making any changes.
|
|
383
514
|
`);
|
|
384
515
|
}
|
|
385
516
|
|
|
@@ -410,6 +541,7 @@ async function pr(rawArgs) {
|
|
|
410
541
|
if (sub === 'list') return cmdList(opts);
|
|
411
542
|
if (sub === 'ready') return cmdReady(opts);
|
|
412
543
|
if (sub === 'review') return prReview(rest);
|
|
544
|
+
if (sub === 'respond') return cmdRespond(rest);
|
|
413
545
|
} catch (error) {
|
|
414
546
|
if (error && error.code === 'gh-missing') {
|
|
415
547
|
logError(error.message);
|
|
@@ -434,6 +566,9 @@ async function pr(rawArgs) {
|
|
|
434
566
|
module.exports = {
|
|
435
567
|
pr,
|
|
436
568
|
parsePrArgs,
|
|
569
|
+
parseRespondArgs,
|
|
437
570
|
renderChecksLine,
|
|
571
|
+
buildChecksFailedDetail,
|
|
572
|
+
buildTimeoutDetail,
|
|
438
573
|
printUsage,
|
|
439
574
|
};
|
|
@@ -30,7 +30,9 @@ function prReview(rawArgs) {
|
|
|
30
30
|
if (options.fix && result.findings.length > 0) {
|
|
31
31
|
const fix = reviewFixModule.runReviewFix({
|
|
32
32
|
repoRoot: resolveRepoRoot(options.target),
|
|
33
|
-
provider:
|
|
33
|
+
provider: result.provider,
|
|
34
|
+
agentQuiet: options.agentQuiet,
|
|
35
|
+
model: !options.provider && result.provider === 'claude' ? null : undefined,
|
|
34
36
|
findings: result.findings,
|
|
35
37
|
});
|
|
36
38
|
if (fix.status === 'fixed') {
|
|
@@ -17,6 +17,7 @@ const {
|
|
|
17
17
|
const toolchainModule = require('../../toolchain');
|
|
18
18
|
const doctorModule = require('../../doctor');
|
|
19
19
|
const speckitModule = require('../../speckit');
|
|
20
|
+
const abide = require('../../abide');
|
|
20
21
|
const { printAutoFinishSummary, colorize, supportsAnsiColors } = require('../../output');
|
|
21
22
|
const { printOperations } = require('../../scaffold');
|
|
22
23
|
const { hasCompletedOnboarding } = require('./onboard');
|
|
@@ -49,6 +50,18 @@ function printRequiredSystemToolStatus() {
|
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
// Setup rewrites the managed AGENTS.md block, which is one of the sources the
|
|
54
|
+
// abide rubric was compiled from. Say so when that leaves the rubric stale.
|
|
55
|
+
function printAbideRubricNote(repoRoot) {
|
|
56
|
+
const rubric = abide.rubricStatus(repoRoot);
|
|
57
|
+
if (rubric.status !== 'stale') return;
|
|
58
|
+
const what = [...rubric.changed, ...rubric.removed].join(', ');
|
|
59
|
+
console.log(
|
|
60
|
+
`[${TOOL_NAME}] abide rubric is stale (${what}); the next Claude session recompiles it, `
|
|
61
|
+
+ `or run '${SHORT_TOOL_NAME} claude install --compile' now.`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
52
65
|
function setup(rawArgs) {
|
|
53
66
|
const options = parseSetupArgs(rawArgs, {
|
|
54
67
|
target: process.cwd(),
|
|
@@ -95,6 +108,17 @@ function setup(rawArgs) {
|
|
|
95
108
|
}
|
|
96
109
|
}
|
|
97
110
|
|
|
111
|
+
const globalApproval = toolchainModule.resolveGlobalInstallApproval(options);
|
|
112
|
+
if (globalApproval.approved
|
|
113
|
+
&& ['installed', 'already-installed'].includes(globalInstallStatus.status)) {
|
|
114
|
+
const codegraphConfig = toolchainModule.configureCodegraphForCodex(options);
|
|
115
|
+
if (codegraphConfig.status === 'configured') {
|
|
116
|
+
console.log(`[${TOOL_NAME}] ✅ CodeGraph MCP configured for Codex (existing config backed up).`);
|
|
117
|
+
} else if (codegraphConfig.status === 'failed') {
|
|
118
|
+
console.log(`[${TOOL_NAME}] ⚠️ ${codegraphConfig.reason}.`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
98
122
|
printRequiredSystemToolStatus();
|
|
99
123
|
|
|
100
124
|
const topRepoRoot = resolveRepoRoot(options.target);
|
|
@@ -201,6 +225,7 @@ function setup(rawArgs) {
|
|
|
201
225
|
dryRun: perRepoOptions.dryRun,
|
|
202
226
|
});
|
|
203
227
|
printWorktreePruneSummary(prunePayload, { baseBranch: currentBaseBranch });
|
|
228
|
+
printAbideRubricNote(scanResult.repoRoot);
|
|
204
229
|
printSetupRepoHints(scanResult.repoRoot, currentBaseBranch, repoLabel);
|
|
205
230
|
|
|
206
231
|
aggregateErrors += scanResult.errors;
|