@imdeadpool/guardex 7.1.1 โ 8.2.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 +123 -322
- package/package.json +23 -5
- package/skills/gitguardex/SKILL.md +83 -3
- package/src/agents/finish.js +15 -0
- package/src/ci-init/index.js +0 -1
- package/src/cli/args.js +142 -3
- package/src/cli/commands/branch.js +294 -14
- package/src/cli/commands/claude.js +15 -0
- package/src/cli/commands/doctor.js +26 -0
- package/src/cli/commands/onboard.js +293 -0
- package/src/cli/commands/prompt.js +15 -3
- package/src/cli/commands/review.js +18 -0
- package/src/cli/commands/setup.js +8 -6
- package/src/cli/commands/status.js +12 -0
- package/src/cli/main.js +2 -0
- package/src/cli/shared-locks.js +304 -0
- package/src/context.js +21 -3
- package/src/core/runtime.js +33 -1
- package/src/doctor/index.js +58 -6
- package/src/finish/heartbeat.js +169 -0
- package/src/finish/index.js +165 -18
- package/src/finish/progress.js +316 -0
- package/src/finish/review-gate.js +453 -32
- package/src/github-api.js +59 -0
- package/src/mcp/collect.js +155 -19
- package/src/mcp/server.js +35 -19
- package/src/output/index.js +210 -0
- package/src/pr-checks.js +121 -0
- package/src/pr-review.js +581 -51
- package/src/pr.js +143 -21
- package/src/provider-binary.js +101 -0
- package/src/review-diff.js +116 -0
- package/src/review-fix.js +229 -0
- package/src/sandbox/index.js +11 -5
- package/src/scaffold/index.js +4 -16
- package/src/shared-git-state.js +566 -0
- package/templates/AGENTS.multiagent-safety.md +63 -11
- package/templates/AGENTS.multiagent-safety.min.md +1 -0
- package/templates/codex/skills/gitguardex/SKILL.md +83 -3
- package/templates/githooks/post-checkout +4 -9
- package/templates/githooks/pre-commit +17 -1
- package/templates/github/workflows/README.md +30 -23
- package/templates/scripts/agent-autofinish-watch.sh +280 -0
- package/templates/scripts/agent-branch-finish.sh +354 -23
- package/templates/scripts/agent-branch-start.sh +49 -22
- package/templates/scripts/agent-claude-stop-finish.sh +194 -0
- package/templates/scripts/agent-file-locks.py +198 -29
- package/templates/scripts/agent-preflight.sh +14 -2
- package/templates/scripts/agent-stalled-report.sh +40 -0
- package/templates/scripts/codex-agent.sh +10 -63
- package/templates/github/workflows/cr.yml +0 -46
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
const STAGES = [
|
|
2
|
+
['prepare', 'Prepare branch'],
|
|
3
|
+
['preflight', 'Local preflight'],
|
|
4
|
+
['pr', 'Push and open PR'],
|
|
5
|
+
['review', 'AI review'],
|
|
6
|
+
['autofix', 'Review autofix'],
|
|
7
|
+
['ci', 'CI checks'],
|
|
8
|
+
['merge', 'Merge'],
|
|
9
|
+
['cleanup', 'Cleanup'],
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
const SYMBOLS = {
|
|
13
|
+
pending: 'โฌ',
|
|
14
|
+
running: '๐',
|
|
15
|
+
complete: 'โ
',
|
|
16
|
+
skipped: 'โญ',
|
|
17
|
+
failed: 'โ',
|
|
18
|
+
finished: '๐',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const TIMED_STAGES = new Set(['review', 'autofix']);
|
|
22
|
+
|
|
23
|
+
function createRunId(branch) {
|
|
24
|
+
const digest = crypto.createHash('sha256').update(String(branch || '')).digest('hex').slice(0, 8);
|
|
25
|
+
return `finish-${Date.now().toString(36)}-${process.pid}-${digest}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function createPrivateDirectory(repoRoot, components) {
|
|
29
|
+
let current = repoRoot;
|
|
30
|
+
for (const component of components) {
|
|
31
|
+
current = path.join(current, component);
|
|
32
|
+
try {
|
|
33
|
+
fs.mkdirSync(current, { mode: 0o700 });
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (error.code !== 'EEXIST') throw error;
|
|
36
|
+
}
|
|
37
|
+
const stat = fs.lstatSync(current);
|
|
38
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
39
|
+
throw new Error(`unsafe finish progress directory: ${current}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return current;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function createEventStream(repoRoot, branch, baseBranch) {
|
|
46
|
+
if (!repoRoot) return null;
|
|
47
|
+
try {
|
|
48
|
+
const directory = createPrivateDirectory(repoRoot, ['.omx', 'state', 'finish-runs']);
|
|
49
|
+
const directoryDescriptor = fs.openSync(
|
|
50
|
+
directory,
|
|
51
|
+
fs.constants.O_RDONLY | fs.constants.O_DIRECTORY | fs.constants.O_NOFOLLOW,
|
|
52
|
+
);
|
|
53
|
+
try {
|
|
54
|
+
fs.fchmodSync(directoryDescriptor, 0o700);
|
|
55
|
+
} finally {
|
|
56
|
+
fs.closeSync(directoryDescriptor);
|
|
57
|
+
}
|
|
58
|
+
const runId = createRunId(branch);
|
|
59
|
+
const filePath = path.join(directory, `${runId}.jsonl`);
|
|
60
|
+
const descriptor = fs.openSync(
|
|
61
|
+
filePath,
|
|
62
|
+
fs.constants.O_APPEND | fs.constants.O_CREAT | fs.constants.O_EXCL
|
|
63
|
+
| fs.constants.O_WRONLY | fs.constants.O_NOFOLLOW,
|
|
64
|
+
0o600,
|
|
65
|
+
);
|
|
66
|
+
try {
|
|
67
|
+
fs.fchmodSync(descriptor, 0o600);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
fs.closeSync(descriptor);
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
// Keep one race-free append target for this one-shot CLI process. Heartbeat
|
|
73
|
+
// children inherit this descriptor; the OS closes it when the command exits.
|
|
74
|
+
return {
|
|
75
|
+
runId,
|
|
76
|
+
filePath,
|
|
77
|
+
relativePath: path.relative(repoRoot, filePath),
|
|
78
|
+
descriptor,
|
|
79
|
+
event: {
|
|
80
|
+
schemaVersion: 1,
|
|
81
|
+
runId,
|
|
82
|
+
branch,
|
|
83
|
+
baseBranch,
|
|
84
|
+
},
|
|
85
|
+
write(event) {
|
|
86
|
+
try {
|
|
87
|
+
fs.writeSync(descriptor, `${JSON.stringify({
|
|
88
|
+
schemaVersion: 1,
|
|
89
|
+
runId,
|
|
90
|
+
timestamp: new Date().toISOString(),
|
|
91
|
+
branch,
|
|
92
|
+
baseBranch,
|
|
93
|
+
...event,
|
|
94
|
+
})}\n`);
|
|
95
|
+
} catch (_error) {
|
|
96
|
+
// Observability remains fail-open after initialization too (disk
|
|
97
|
+
// full, state directory removed mid-run, or transient I/O failure).
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
} catch (_error) {
|
|
102
|
+
// Progress persistence is observability only. It must never block a merge
|
|
103
|
+
// gate or turn a successful cleanup into a failed finish.
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Append-only finish progress for terminals and agent transcripts. Rewriting a
|
|
110
|
+
* single ANSI dashboard looks good in a TTY but disappears from Codex's
|
|
111
|
+
* captured tool output, so every transition is a durable line instead.
|
|
112
|
+
*/
|
|
113
|
+
function createFinishProgress({
|
|
114
|
+
repoRoot,
|
|
115
|
+
branch,
|
|
116
|
+
baseBranch,
|
|
117
|
+
write,
|
|
118
|
+
persistEvents = true,
|
|
119
|
+
now = Date.now,
|
|
120
|
+
heartbeat,
|
|
121
|
+
heartbeatIntervalMs = 15_000,
|
|
122
|
+
quiet = false,
|
|
123
|
+
} = {}) {
|
|
124
|
+
const sink = write || ((line) => process.stderr.write(`${line}\n`));
|
|
125
|
+
const output = quiet ? () => {} : sink;
|
|
126
|
+
const heartbeatFactory = quiet
|
|
127
|
+
? null
|
|
128
|
+
: heartbeat === undefined
|
|
129
|
+
? (write ? null : startStageHeartbeat)
|
|
130
|
+
: heartbeat;
|
|
131
|
+
const clock = typeof now === 'function' ? now : Date.now;
|
|
132
|
+
const eventStream = persistEvents ? createEventStream(repoRoot, branch, baseBranch) : null;
|
|
133
|
+
const stageMap = new Map(STAGES.map(([id, label], index) => [id, {
|
|
134
|
+
index: index + 1,
|
|
135
|
+
label,
|
|
136
|
+
state: 'pending',
|
|
137
|
+
detail: '',
|
|
138
|
+
}]));
|
|
139
|
+
const stageStartedAt = new Map();
|
|
140
|
+
let activeTimedStage = '';
|
|
141
|
+
let stopActiveHeartbeat = null;
|
|
142
|
+
|
|
143
|
+
output(`[gx:finish] โญโ ๐ GX FINISH ยท ${branch || 'current branch'} โ ${baseBranch || 'configured base'}`);
|
|
144
|
+
if (eventStream) {
|
|
145
|
+
eventStream.write({ stage: 'finish', state: 'started', index: 0, total: STAGES.length, label: 'GX Finish', detail: '' });
|
|
146
|
+
}
|
|
147
|
+
for (const [, stage] of stageMap) {
|
|
148
|
+
output(`[gx:finish] โ ${SYMBOLS.pending} ${stage.index}/${STAGES.length} ${stage.label}`);
|
|
149
|
+
if (eventStream) {
|
|
150
|
+
eventStream.write({
|
|
151
|
+
stage: STAGES[stage.index - 1][0],
|
|
152
|
+
state: 'pending',
|
|
153
|
+
index: stage.index,
|
|
154
|
+
total: STAGES.length,
|
|
155
|
+
label: stage.label,
|
|
156
|
+
detail: '',
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
output(`[gx:finish] โฐโ 0/${STAGES.length} ready`);
|
|
161
|
+
if (eventStream) {
|
|
162
|
+
output(`[gx:finish] ๐ก events ยท ${eventStream.relativePath}`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function stopTimedStage() {
|
|
166
|
+
try {
|
|
167
|
+
if (stopActiveHeartbeat) stopActiveHeartbeat();
|
|
168
|
+
} catch (_error) {
|
|
169
|
+
// Progress is observability only; teardown errors remain fail-open.
|
|
170
|
+
}
|
|
171
|
+
stopActiveHeartbeat = null;
|
|
172
|
+
if (activeTimedStage) stageStartedAt.delete(activeTimedStage);
|
|
173
|
+
activeTimedStage = '';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function update(id, state, detail = '', displaySuffix = '') {
|
|
177
|
+
const stage = stageMap.get(id);
|
|
178
|
+
if (!stage) return false;
|
|
179
|
+
const normalizedDetail = String(detail || '').trim();
|
|
180
|
+
if (stage.state === state && stage.detail === normalizedDetail) return false;
|
|
181
|
+
stage.state = state;
|
|
182
|
+
stage.detail = normalizedDetail;
|
|
183
|
+
const connector = id === 'cleanup' && state !== 'running' ? 'โฐโ' : 'โโ';
|
|
184
|
+
output(
|
|
185
|
+
`[gx:finish] ${connector} ${SYMBOLS[state]} ${stage.index}/${STAGES.length} ${stage.label}`
|
|
186
|
+
+ `${normalizedDetail ? ` ยท ${normalizedDetail}` : ''}${displaySuffix}`,
|
|
187
|
+
);
|
|
188
|
+
if (eventStream) {
|
|
189
|
+
eventStream.write({
|
|
190
|
+
stage: id,
|
|
191
|
+
state,
|
|
192
|
+
index: stage.index,
|
|
193
|
+
total: STAGES.length,
|
|
194
|
+
label: stage.label,
|
|
195
|
+
detail: normalizedDetail,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function start(id, detail) {
|
|
202
|
+
const stage = stageMap.get(id);
|
|
203
|
+
if (!stage) return;
|
|
204
|
+
const normalizedDetail = String(detail || '').trim();
|
|
205
|
+
if (stage.state === 'running' && stage.detail === normalizedDetail) return;
|
|
206
|
+
|
|
207
|
+
stopTimedStage();
|
|
208
|
+
const startAt = clock();
|
|
209
|
+
if (!update(id, 'running', normalizedDetail) || !TIMED_STAGES.has(id)) return;
|
|
210
|
+
|
|
211
|
+
activeTimedStage = id;
|
|
212
|
+
stageStartedAt.set(id, startAt);
|
|
213
|
+
if (!heartbeatFactory) return;
|
|
214
|
+
try {
|
|
215
|
+
stopActiveHeartbeat = heartbeatFactory({
|
|
216
|
+
stage: id,
|
|
217
|
+
index: stage.index,
|
|
218
|
+
total: STAGES.length,
|
|
219
|
+
label: stage.label,
|
|
220
|
+
detail: normalizedDetail,
|
|
221
|
+
intervalMs: heartbeatIntervalMs,
|
|
222
|
+
startAt,
|
|
223
|
+
...(eventStream ? {
|
|
224
|
+
eventDescriptor: eventStream.descriptor,
|
|
225
|
+
event: eventStream.event,
|
|
226
|
+
} : {}),
|
|
227
|
+
});
|
|
228
|
+
} catch (_error) {
|
|
229
|
+
// Progress is observability only; a heartbeat failure cannot block finish.
|
|
230
|
+
stopActiveHeartbeat = null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function settle(id, state, detail) {
|
|
235
|
+
let displaySuffix = '';
|
|
236
|
+
if (TIMED_STAGES.has(id) && stageStartedAt.has(id)) {
|
|
237
|
+
displaySuffix = ` ยท โฑ ${formatElapsed(clock() - stageStartedAt.get(id))}`;
|
|
238
|
+
}
|
|
239
|
+
if (activeTimedStage === id) stopTimedStage();
|
|
240
|
+
update(id, state, detail, displaySuffix);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
start,
|
|
245
|
+
complete: (id, detail) => settle(id, 'complete', detail),
|
|
246
|
+
skip: (id, detail) => settle(id, 'skipped', detail),
|
|
247
|
+
fail: (id, detail) => settle(id, 'failed', detail),
|
|
248
|
+
finish: (id, detail) => settle(id, 'finished', detail),
|
|
249
|
+
eventEnv: eventStream ? {
|
|
250
|
+
GUARDEX_FINISH_EVENT_FILE: eventStream.filePath,
|
|
251
|
+
GUARDEX_FINISH_RUN_ID: eventStream.runId,
|
|
252
|
+
GUARDEX_FINISH_EVENT_BRANCH: String(branch || ''),
|
|
253
|
+
GUARDEX_FINISH_EVENT_BASE: String(baseBranch || ''),
|
|
254
|
+
} : {},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function readFinishEvents(filePath) {
|
|
259
|
+
if (!filePath) return [];
|
|
260
|
+
try {
|
|
261
|
+
return fs.readFileSync(filePath, 'utf8')
|
|
262
|
+
.split('\n')
|
|
263
|
+
.filter(Boolean)
|
|
264
|
+
.map((line) => JSON.parse(line));
|
|
265
|
+
} catch (_error) {
|
|
266
|
+
return [];
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Build one bounded machine-readable result from a captured finish run. */
|
|
271
|
+
function summarizeFinishRun({
|
|
272
|
+
eventFile,
|
|
273
|
+
branch,
|
|
274
|
+
baseBranch,
|
|
275
|
+
stdout = '',
|
|
276
|
+
stderr = '',
|
|
277
|
+
status = 0,
|
|
278
|
+
} = {}) {
|
|
279
|
+
const events = readFinishEvents(eventFile);
|
|
280
|
+
const latest = new Map();
|
|
281
|
+
for (const event of events) {
|
|
282
|
+
if (event && event.stage && event.stage !== 'finish') latest.set(event.stage, event);
|
|
283
|
+
}
|
|
284
|
+
const stages = {};
|
|
285
|
+
for (const [id] of STAGES) {
|
|
286
|
+
const event = latest.get(id);
|
|
287
|
+
if (!event || event.state === 'pending') continue;
|
|
288
|
+
stages[id] = event.detail ? `${event.state}: ${event.detail}` : event.state;
|
|
289
|
+
}
|
|
290
|
+
const combined = `${stdout}\n${stderr}`;
|
|
291
|
+
const pr = combined.match(/https:\/\/github\.com\/[^\s]+\/pull\/\d+/)?.[0] || undefined;
|
|
292
|
+
const result = {
|
|
293
|
+
branch: branch || '',
|
|
294
|
+
base: baseBranch || '',
|
|
295
|
+
result: status === 0 ? 'success' : 'failed',
|
|
296
|
+
stages,
|
|
297
|
+
};
|
|
298
|
+
if (pr) result.pr = pr;
|
|
299
|
+
if (status !== 0) {
|
|
300
|
+
const lines = combined.split('\n').map((line) => line.trim()).filter(Boolean);
|
|
301
|
+
const tail = lines.slice(-12).join('\n');
|
|
302
|
+
if (tail) result.error = tail.slice(-2_000);
|
|
303
|
+
}
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
module.exports = {
|
|
308
|
+
STAGES,
|
|
309
|
+
createEventStream,
|
|
310
|
+
createFinishProgress,
|
|
311
|
+
summarizeFinishRun,
|
|
312
|
+
};
|
|
313
|
+
const crypto = require('node:crypto');
|
|
314
|
+
const fs = require('node:fs');
|
|
315
|
+
const path = require('node:path');
|
|
316
|
+
const { formatElapsed, startHeartbeat: startStageHeartbeat } = require('./heartbeat');
|