@imdeadpool/guardex 8.4.23 → 8.4.25
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@imdeadpool/guardex",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.25",
|
|
4
4
|
"description": "Guardian T-Rex for your multi-agent repo. Isolated worktrees, file locks, and PR-only merges stop parallel Codex & Claude agents from overwriting each other's work. Auto-wires Oh My Codex, Oh My Claude, OpenSpec, and Caveman.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"preferGlobal": true,
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"prepublishOnly": "node scripts/prepublish-bump-version.js",
|
|
66
66
|
"postinstall": "node -e \"require('./src/heavy').installReport()\""
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "13d45cbde94a8cf9ccc3cdde0049d62c4d0baa11"
|
|
69
69
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const fs = require('node:fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { run } = require('../core/runtime');
|
|
4
|
+
|
|
5
|
+
const EVENT_DIRECTORY = ['.omx', 'state', 'finish-runs'];
|
|
6
|
+
|
|
7
|
+
// Git lists the primary checkout first. A bare repository has no primary HUD.
|
|
8
|
+
function primaryCheckout(repoRoot) {
|
|
9
|
+
try {
|
|
10
|
+
const result = run('git', ['worktree', 'list', '--porcelain', '-z'], {
|
|
11
|
+
cwd: repoRoot,
|
|
12
|
+
timeout: 1000
|
|
13
|
+
});
|
|
14
|
+
if (result?.status !== 0) return repoRoot;
|
|
15
|
+
const [entry, ...fields] = result.stdout.split('\0\0', 1)[0].split('\0');
|
|
16
|
+
const primary = entry.startsWith('worktree ') ? entry.slice(9) : '';
|
|
17
|
+
if (!path.isAbsolute(primary) || fields.includes('bare')) return repoRoot;
|
|
18
|
+
return fs.realpathSync(primary);
|
|
19
|
+
} catch (_error) {
|
|
20
|
+
return repoRoot;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = { EVENT_DIRECTORY, primaryCheckout };
|
package/src/finish/events.js
CHANGED
|
@@ -2,15 +2,14 @@ const fs = require('node:fs');
|
|
|
2
2
|
const path = require('node:path');
|
|
3
3
|
const { createHash } = require('node:crypto');
|
|
4
4
|
const { setTimeout: delay } = require('node:timers/promises');
|
|
5
|
+
const { EVENT_DIRECTORY, primaryCheckout } = require('./event-location');
|
|
5
6
|
|
|
6
7
|
const MAX_READ_BYTES = 256 * 1024;
|
|
7
8
|
const RUN_ID = /^finish-[a-z0-9]+-[0-9]+-[a-f0-9]{8}$/;
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
function readEventPage(repoRoot, runId, cursor = '', stateOptions) {
|
|
11
|
-
if (!RUN_ID.test(runId)) throw new Error('Invalid finish run ID');
|
|
10
|
+
function eventFileInCheckout(repoRoot, runId) {
|
|
12
11
|
let directory = fs.realpathSync(repoRoot);
|
|
13
|
-
for (const part of
|
|
12
|
+
for (const part of EVENT_DIRECTORY) {
|
|
14
13
|
directory = path.join(directory, part);
|
|
15
14
|
const stat = fs.lstatSync(directory);
|
|
16
15
|
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
@@ -18,7 +17,28 @@ function readEventPage(repoRoot, runId, cursor = '', stateOptions) {
|
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
const file = path.join(directory, `${runId}.jsonl`);
|
|
21
|
-
|
|
20
|
+
return { file, entry: fs.lstatSync(file) };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function locateEventFile(repoRoot, runId) {
|
|
24
|
+
try {
|
|
25
|
+
// Keep old worktree-local runs and the writer's fail-open fallback readable.
|
|
26
|
+
return eventFileInCheckout(repoRoot, runId);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
const primary = primaryCheckout(repoRoot);
|
|
29
|
+
if (primary === repoRoot) throw error;
|
|
30
|
+
try {
|
|
31
|
+
return eventFileInCheckout(primary, runId);
|
|
32
|
+
} catch (primaryError) {
|
|
33
|
+
throw error.code === 'ENOENT' ? primaryError : error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Observation only: event files never authorize a merge or replace gate checks.
|
|
39
|
+
function readEventPage(repoRoot, runId, cursor = '', stateOptions) {
|
|
40
|
+
if (!RUN_ID.test(runId)) throw new Error('Invalid finish run ID');
|
|
41
|
+
const { file, entry } = locateEventFile(repoRoot, runId);
|
|
22
42
|
if (!entry.isFile() || entry.isSymbolicLink()) throw new Error('Unsafe finish event file');
|
|
23
43
|
const fd = fs.openSync(
|
|
24
44
|
file,
|
package/src/finish/progress.js
CHANGED
|
@@ -44,8 +44,14 @@ function createPrivateDirectory(repoRoot, components) {
|
|
|
44
44
|
|
|
45
45
|
function createEventStream(repoRoot, branch, baseBranch) {
|
|
46
46
|
if (!repoRoot) return null;
|
|
47
|
+
const primary = primaryCheckout(repoRoot);
|
|
48
|
+
return openEventStream(repoRoot, primary, branch, baseBranch)
|
|
49
|
+
|| (primary !== repoRoot ? openEventStream(repoRoot, repoRoot, branch, baseBranch) : null);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function openEventStream(repoRoot, stateRoot, branch, baseBranch) {
|
|
47
53
|
try {
|
|
48
|
-
const directory = createPrivateDirectory(
|
|
54
|
+
const directory = createPrivateDirectory(stateRoot, EVENT_DIRECTORY);
|
|
49
55
|
const directoryDescriptor = fs.openSync(
|
|
50
56
|
directory,
|
|
51
57
|
fs.constants.O_RDONLY | fs.constants.O_DIRECTORY | fs.constants.O_NOFOLLOW,
|
|
@@ -276,7 +282,7 @@ function persistFinishOutput(eventFile, stdout, stderr) {
|
|
|
276
282
|
throw new Error('unsafe finish log name');
|
|
277
283
|
}
|
|
278
284
|
const root = path.resolve(path.dirname(eventFile), '../../..');
|
|
279
|
-
const directory = createPrivateDirectory(root,
|
|
285
|
+
const directory = createPrivateDirectory(root, EVENT_DIRECTORY);
|
|
280
286
|
if (path.resolve(eventFile) !== path.join(directory, name)) throw new Error('unsafe finish log path');
|
|
281
287
|
const file = path.join(directory, `${name}.output.log`);
|
|
282
288
|
const fd = fs.openSync(file, fs.constants.O_WRONLY | fs.constants.O_CREAT
|
|
@@ -349,4 +355,5 @@ module.exports = {
|
|
|
349
355
|
const crypto = require('node:crypto');
|
|
350
356
|
const fs = require('node:fs');
|
|
351
357
|
const path = require('node:path');
|
|
358
|
+
const { EVENT_DIRECTORY, primaryCheckout } = require('./event-location');
|
|
352
359
|
const { formatElapsed, startHeartbeat: startStageHeartbeat } = require('./heartbeat');
|
|
@@ -723,6 +723,36 @@ function postReviewPayload(pr, payload, repoRoot, runner = run) {
|
|
|
723
723
|
}
|
|
724
724
|
}
|
|
725
725
|
|
|
726
|
+
function syncReviewTitle(pr, { commit, base, value, truncated }, repoRoot, runner) {
|
|
727
|
+
const options = { cwd: repoRoot, timeout: 15_000 };
|
|
728
|
+
const current = runner(
|
|
729
|
+
GH_BIN,
|
|
730
|
+
['pr', 'view', pr, '--json', 'title,state,headRefOid,baseRefOid'],
|
|
731
|
+
options
|
|
732
|
+
);
|
|
733
|
+
if (current.status !== 0) return;
|
|
734
|
+
const live = JSON.parse(current.stdout);
|
|
735
|
+
if (
|
|
736
|
+
live.state !== 'OPEN' ||
|
|
737
|
+
live.headRefOid !== commit ||
|
|
738
|
+
(base && live.baseRefOid !== base) ||
|
|
739
|
+
typeof live.title !== 'string'
|
|
740
|
+
) return;
|
|
741
|
+
|
|
742
|
+
const managedPrefix = /^(?:\[(?:I(?:\d{1,3}|\?) R(?:\d{1,3}|\?)|Impact \d{1,3}\/100)\] )+/;
|
|
743
|
+
const original = live.title.replace(managedPrefix, '');
|
|
744
|
+
// Keep the leading conventional-commit type parseable after a squash merge.
|
|
745
|
+
const conventional = original.match(/^[a-z][a-z0-9-]*(?:\([^()\n]+\))?!?: /)?.[0] || '';
|
|
746
|
+
const subject = original.slice(conventional.length).replace(managedPrefix, '');
|
|
747
|
+
const { impactScore = null, riskScore = null } = (!truncated && value) || {};
|
|
748
|
+
const score = impactScore !== null || riskScore !== null
|
|
749
|
+
? `[I${impactScore ?? '?'} R${riskScore ?? '?'}] `
|
|
750
|
+
: '';
|
|
751
|
+
const title = conventional + score + subject;
|
|
752
|
+
if (subject && title !== live.title)
|
|
753
|
+
runner(GH_BIN, ['pr', 'edit', pr, `--title=${title}`], options);
|
|
754
|
+
}
|
|
755
|
+
|
|
726
756
|
/**
|
|
727
757
|
* Post one review. Findings whose fingerprint is already on the PR are skipped
|
|
728
758
|
* so repeated `gx ship` attempts stop stacking identical comments.
|
|
@@ -793,15 +823,21 @@ function postGithubReview(pr, context, repoRoot, runner = run) {
|
|
|
793
823
|
const outcome = { posted: fresh.length, duplicates, degraded, commit };
|
|
794
824
|
// Review receipts verify the live server-side review on retry. No receipt
|
|
795
825
|
// can come from a degraded post, missing ID, or a different commit.
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
if (Number.isSafeInteger(posted.id) && posted.id > 0
|
|
826
|
+
try {
|
|
827
|
+
const posted = JSON.parse(result.stdout);
|
|
828
|
+
if (commit && posted.commit_id === commit) {
|
|
829
|
+
if (!degraded && Number.isSafeInteger(posted.id) && posted.id > 0) {
|
|
800
830
|
outcome.reviewId = posted.id;
|
|
801
831
|
outcome.reviewBodyHash = crypto.createHash('sha256').update(payload.body).digest('hex');
|
|
802
832
|
}
|
|
803
|
-
|
|
804
|
-
|
|
833
|
+
syncReviewTitle(
|
|
834
|
+
pr,
|
|
835
|
+
{ commit, base: context.reviewedBaseSha || context.expectedBaseSha, value: context.value, truncated },
|
|
836
|
+
repoRoot,
|
|
837
|
+
runner
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
} catch { /* Unavailable metadata or title permissions cannot invalidate a posted review. */ }
|
|
805
841
|
return outcome;
|
|
806
842
|
}
|
|
807
843
|
|
|
@@ -1189,7 +1225,7 @@ function runPrReview(options, deps = {}) {
|
|
|
1189
1225
|
};
|
|
1190
1226
|
}
|
|
1191
1227
|
|
|
1192
|
-
const outcome = postGithubReview(pr, payload, repoRoot, runner);
|
|
1228
|
+
const outcome = postGithubReview(pr, { ...payload, expectedBaseSha: options.expectedBaseSha }, repoRoot, runner);
|
|
1193
1229
|
history?.save(value);
|
|
1194
1230
|
return {
|
|
1195
1231
|
posted: true,
|
|
@@ -2133,14 +2133,19 @@ if [[ "$CLEANUP_AFTER_MERGE" -eq 1 ]]; then
|
|
|
2133
2133
|
|
|
2134
2134
|
# The merge already landed (see the MERGED banner above), so a branch that
|
|
2135
2135
|
# refuses to delete is a leftover to report, not a reason to fail the run and
|
|
2136
|
-
# make a successful ship look broken. Keep
|
|
2137
|
-
# case: the commits it still holds exist nowhere else.
|
|
2136
|
+
# make a successful ship look broken. Keep both refs when deletion is refused.
|
|
2138
2137
|
local_branch_cleaned=1
|
|
2139
2138
|
if ! delete_local_branch_for_cleanup "$SOURCE_BRANCH"; then
|
|
2140
2139
|
local_branch_cleaned=0
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2140
|
+
remaining_worktree="$(get_worktree_for_branch "$SOURCE_BRANCH")"
|
|
2141
|
+
if [[ -n "$remaining_worktree" ]]; then
|
|
2142
|
+
echo "[agent-branch-finish] Warning: kept local branch '${SOURCE_BRANCH}' — still checked out in worktree '${remaining_worktree}'." >&2
|
|
2143
|
+
printf '[agent-branch-finish] Once the worktree is idle, retry: gx cleanup --base %q --branch %q\n' "$BASE_BRANCH" "$SOURCE_BRANCH" >&2
|
|
2144
|
+
else
|
|
2145
|
+
echo "[agent-branch-finish] Warning: kept local branch '${SOURCE_BRANCH}' — could not safely delete it after merge." >&2
|
|
2146
|
+
printf '[agent-branch-finish] Inspect: git log %q\n' "${BASE_BRANCH}..${SOURCE_BRANCH}" >&2
|
|
2147
|
+
printf '[agent-branch-finish] After resolving the cause, retry: gx cleanup --base %q --branch %q\n' "$BASE_BRANCH" "$SOURCE_BRANCH" >&2
|
|
2148
|
+
fi
|
|
2144
2149
|
fi
|
|
2145
2150
|
|
|
2146
2151
|
if [[ "$local_branch_cleaned" -eq 1 && "$PUSH_ENABLED" -eq 1 && "$DELETE_REMOTE_BRANCH" -eq 1 ]]; then
|
|
@@ -2168,7 +2173,7 @@ if [[ "$CLEANUP_AFTER_MERGE" -eq 1 ]]; then
|
|
|
2168
2173
|
prune_args+=(--delete-remote-branches)
|
|
2169
2174
|
fi
|
|
2170
2175
|
else
|
|
2171
|
-
echo "[agent-branch-finish] Skipping branch deletion during prune so '${SOURCE_BRANCH}' survives
|
|
2176
|
+
echo "[agent-branch-finish] Skipping branch deletion during prune so '${SOURCE_BRANCH}' survives." >&2
|
|
2172
2177
|
fi
|
|
2173
2178
|
|
|
2174
2179
|
pivot_to_repo_root_before_prune
|
|
@@ -2184,7 +2189,7 @@ if [[ "$CLEANUP_AFTER_MERGE" -eq 1 ]]; then
|
|
|
2184
2189
|
if [[ "$local_branch_cleaned" -eq 1 ]]; then
|
|
2185
2190
|
kept_branch_summary=""
|
|
2186
2191
|
else
|
|
2187
|
-
kept_branch_summary="kept source branch (
|
|
2192
|
+
kept_branch_summary="kept source branch (cleanup deferred)"
|
|
2188
2193
|
fi
|
|
2189
2194
|
|
|
2190
2195
|
if [[ "$source_worktree" == "$current_worktree" && "$source_worktree" == "${agent_worktree_root}"/* && -d "$source_worktree" ]]; then
|