@memnexus-ai/mx-agent-cli 0.1.261 → 0.1.263
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/dist/__tests__/codex-agent-gate.test.js +225 -3
- package/dist/__tests__/codex-agent-gate.test.js.map +1 -1
- package/dist/__tests__/coordination-brief-pin.test.js +5 -1
- package/dist/__tests__/coordination-brief-pin.test.js.map +1 -1
- package/dist/__tests__/runtime-codex-config.test.js +122 -8
- package/dist/__tests__/runtime-codex-config.test.js.map +1 -1
- package/dist/agent-config/hooks/HOOK-TIMEOUTS.md +101 -0
- package/dist/agent-config/hooks/auto-capture-precompact.sh +3 -1
- package/dist/agent-config/hooks/auto-capture-session-end.sh +5 -1
- package/dist/agent-config/hooks/auto-checkpoint.sh +3 -1
- package/dist/agent-config/hooks/ci-validate-hook.sh +76 -8
- package/dist/agent-config/hooks/coordination-brief.sh +15 -2
- package/dist/agent-config/hooks/coordination-midsession-drain.sh +13 -0
- package/dist/agent-config/hooks/deploy-verification-reminder.sh +5 -1
- package/dist/agent-config/hooks/memory-checkpoint-reminder.sh +8 -1
- package/dist/agent-config/hooks/mx-guard-hook.sh +30 -4
- package/dist/agent-config/hooks/named-memory-write-guard.sh +5 -0
- package/dist/agent-config/hooks/observability-sync.sh +7 -1
- package/dist/agent-config/hooks/reload-checkpoint.sh +13 -3
- package/dist/agent-config/hooks/workflow-dispatch-guard.sh +11 -2
- package/dist/agent-config/settings.json +40 -20
- package/dist/commands/codex-agent-gate.d.ts +22 -0
- package/dist/commands/codex-agent-gate.d.ts.map +1 -1
- package/dist/commands/codex-agent-gate.js +176 -19
- package/dist/commands/codex-agent-gate.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/dist/lib/runtime/codex-config.d.ts +114 -3
- package/dist/lib/runtime/codex-config.d.ts.map +1 -1
- package/dist/lib/runtime/codex-config.js +151 -23
- package/dist/lib/runtime/codex-config.js.map +1 -1
- package/package.json +1 -1
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
# `git -C /treeA push && git -C /treeB push` pushed unlinted. Every push
|
|
39
39
|
# segment is now resolved and every distinct toplevel linted.
|
|
40
40
|
|
|
41
|
+
|
|
42
|
+
|
|
41
43
|
# Read hook input from stdin
|
|
42
44
|
INPUT=$(cat)
|
|
43
45
|
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty')
|
|
@@ -92,6 +94,12 @@ fi
|
|
|
92
94
|
# #4803 test fails against it.
|
|
93
95
|
|
|
94
96
|
# >>> SHARED push-target resolver v1 (#4803, #4808) — KEEP BYTE-IDENTICAL ─────
|
|
97
|
+
# Every git call in this resolver is bounded. An unbounded rev-parse on a
|
|
98
|
+
# wedged filesystem would burn the hook's whole harness timeout and then be
|
|
99
|
+
# killed — and a killed PreToolUse hook ALLOWS the tool call, so the push
|
|
100
|
+
# would go through unvalidated. Bounded, a hang instead lands on the existing
|
|
101
|
+
# MXPT_UNRESOLVED path, which already blocks and now says why (#4846 review).
|
|
102
|
+
MXPT_GIT_TIMEOUT_SECS="${MXPT_GIT_TIMEOUT_SECS:-10}"
|
|
95
103
|
# Duplicated verbatim in mx-guard-hook.sh and ci-validate-hook.sh, exactly the
|
|
96
104
|
# way PUSH_RE already is, and pinned byte-for-byte by push-target-parity.test.sh.
|
|
97
105
|
# Deliberately NOT a sourced library: each hook must stay a standalone file (that
|
|
@@ -251,7 +259,7 @@ if [ "${#MXPT_PUSH_RAWS[@]}" -eq 0 ]; then
|
|
|
251
259
|
MXPT_PUSH_REMOTE=(0)
|
|
252
260
|
fi
|
|
253
261
|
|
|
254
|
-
MXPT_BASE_TOP=$(git -C "$MXPT_BASE_DIR" rev-parse --show-toplevel 2>/dev/null) || MXPT_BASE_TOP="$MXPT_BASE_DIR"
|
|
262
|
+
MXPT_BASE_TOP=$(timeout "$MXPT_GIT_TIMEOUT_SECS" git -C "$MXPT_BASE_DIR" rev-parse --show-toplevel 2>/dev/null) || MXPT_BASE_TOP="$MXPT_BASE_DIR"
|
|
255
263
|
|
|
256
264
|
# Resolve every push segment. Remote segments are skipped first and never
|
|
257
265
|
# resolved (SF-1); the first local segment that cannot be resolved stops
|
|
@@ -287,8 +295,14 @@ for mxpt_i in "${!MXPT_PUSH_RAWS[@]}"; do
|
|
|
287
295
|
esac
|
|
288
296
|
if [ ! -d "$MXPT_CAND" ]; then
|
|
289
297
|
mxpt_why="no such directory on this machine"
|
|
290
|
-
|
|
291
|
-
|
|
298
|
+
else
|
|
299
|
+
mxpt_rc=0
|
|
300
|
+
mxpt_dir=$(timeout "$MXPT_GIT_TIMEOUT_SECS" git -C "$MXPT_CAND" rev-parse --show-toplevel 2>/dev/null) || mxpt_rc=$?
|
|
301
|
+
if [ "$mxpt_rc" = "124" ]; then
|
|
302
|
+
mxpt_why="git rev-parse did not answer within ${MXPT_GIT_TIMEOUT_SECS}s, so the tree could not be identified"
|
|
303
|
+
elif [ "$mxpt_rc" != "0" ]; then
|
|
304
|
+
mxpt_why="it is not inside a git work tree"
|
|
305
|
+
fi
|
|
292
306
|
fi ;;
|
|
293
307
|
esac
|
|
294
308
|
fi
|
|
@@ -381,7 +395,12 @@ if ! cd "$TARGET_DIR"; then
|
|
|
381
395
|
fi
|
|
382
396
|
# <<< #4803 END push-target resolution
|
|
383
397
|
|
|
384
|
-
|
|
398
|
+
# Bounded so a wedged lint cannot hold the Bash tool call open. The bound is
|
|
399
|
+
# internal, not the harness `timeout` in settings.json, because a harness
|
|
400
|
+
# timeout kills the hook and ALLOWS the push — the one outcome a guard must not
|
|
401
|
+
# have. At 124 we stay on the existing non-zero path and still block.
|
|
402
|
+
MX_GUARD_CHECK_TIMEOUT_SECS="${MX_GUARD_CHECK_TIMEOUT_SECS:-120}"
|
|
403
|
+
timeout "$MX_GUARD_CHECK_TIMEOUT_SECS" mx-guard check >&2
|
|
385
404
|
GUARD_EXIT=$?
|
|
386
405
|
if [ "${MXG_PRIOR_FAIL:-0}" -ne 0 ]; then
|
|
387
406
|
GUARD_EXIT=1
|
|
@@ -390,6 +409,13 @@ fi
|
|
|
390
409
|
if [ $GUARD_EXIT -ne 0 ]; then
|
|
391
410
|
{
|
|
392
411
|
echo ""
|
|
412
|
+
if [ $GUARD_EXIT -eq 124 ]; then
|
|
413
|
+
echo "mx-guard: push blocked — mx-guard check did not finish within"
|
|
414
|
+
echo "${MX_GUARD_CHECK_TIMEOUT_SECS}s, so this push is unvalidated. Re-run"
|
|
415
|
+
echo "'mx-guard check' directly to see where it hangs; raise the bound with"
|
|
416
|
+
echo "MX_GUARD_CHECK_TIMEOUT_SECS if the tree is genuinely that slow to lint."
|
|
417
|
+
echo ""
|
|
418
|
+
fi
|
|
393
419
|
echo "mx-guard: push blocked. Fix the errors above before pushing."
|
|
394
420
|
echo " To check specific rules: mx-guard check --rule <category>"
|
|
395
421
|
echo " To see all rules: mx-guard rules"
|
|
@@ -220,6 +220,11 @@ HEAD_LEN=$(printf '%s' "$HEAD_JSON" | sed -n '/{/,$p' | jq -r '(.content // "")
|
|
|
220
220
|
# log the event so we can see how often the head is unreadable.
|
|
221
221
|
if [[ -z "$HEAD_LEN" || ! "$HEAD_LEN" =~ ^[0-9]+$ || "$HEAD_LEN" -eq 0 ]]; then
|
|
222
222
|
emit_telemetry "$NAME" "fetch-fail" "$NEW_LEN" "no" "fetch-fail"
|
|
223
|
+
# Announced as well as recorded (#4846 SF-25). The telemetry line is for us
|
|
224
|
+
# later; the agent needs to know NOW that the shrink check did not run, because
|
|
225
|
+
# a fetch failure is indistinguishable from "no existing head" and the write
|
|
226
|
+
# proceeds unguarded either way.
|
|
227
|
+
echo "named-memory-write-guard: could not read the current head of '${NAME_SAFE}' — shrink check SKIPPED, write allowed unguarded." >&2
|
|
223
228
|
exit 0
|
|
224
229
|
fi
|
|
225
230
|
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
# Logs sync failures to the local startup JSONL so they are visible at next session start.
|
|
4
4
|
# FAIL-OPEN: always exits 0 regardless of sync outcome.
|
|
5
5
|
|
|
6
|
+
|
|
7
|
+
|
|
6
8
|
set -euo pipefail
|
|
7
9
|
|
|
8
10
|
WORKTREE_PATH="${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null || echo '')}"
|
|
@@ -16,7 +18,11 @@ LOG_FILE="$LOG_DIR/${WORKTREE_NAME}.jsonl"
|
|
|
16
18
|
# Run the sync, capture exit code
|
|
17
19
|
SYNC_OUTPUT=""
|
|
18
20
|
SYNC_EXIT=0
|
|
19
|
-
|
|
21
|
+
# Bounded: this is a network call to the observability API. Without a bound a
|
|
22
|
+
# hung or black-holed connection holds the Stop hook open. On timeout `timeout`
|
|
23
|
+
# exits 124, which lands on the existing failure path below — logged to the
|
|
24
|
+
# startup JSONL, still exit 0. Fail-open contract unchanged.
|
|
25
|
+
SYNC_OUTPUT=$(timeout "${OBS_SYNC_TIMEOUT_SECS:-25}" mx-agent sync --api-url "$API_URL" --quiet 2>&1) || SYNC_EXIT=$?
|
|
20
26
|
|
|
21
27
|
if [ "$SYNC_EXIT" -ne 0 ]; then
|
|
22
28
|
# Log failure to the local startup JSONL (v2.58 infrastructure)
|
|
@@ -32,12 +32,22 @@ command -v mx >/dev/null 2>&1 || exit 0
|
|
|
32
32
|
|
|
33
33
|
# ── 2. Retrieve checkpoint memory ───────────────────────────────────────
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
# Bounded: network read. On timeout the result is empty and the next test exits
|
|
36
|
+
# 0 without injecting a checkpoint — the same path as "no checkpoint found".
|
|
37
|
+
CHECKPOINT=$(timeout "${RELOAD_CHECKPOINT_TIMEOUT_SECS:-15}" mx memories get --name "auto-checkpoint-${WORKTREE_NAME}" --format json --detail minimal 2>/dev/null || true)
|
|
38
|
+
|
|
39
|
+
if [[ -z "$CHECKPOINT" ]]; then
|
|
40
|
+
# Announced (#4846 SF-25): an empty result here is either "no checkpoint was
|
|
41
|
+
# saved" or "the fetch failed", and the agent resumes from compaction either
|
|
42
|
+
# way. Only the second case means context it should have had is missing.
|
|
43
|
+
echo "reload-checkpoint: could not read auto-checkpoint-${WORKTREE_NAME} (fetch failed or timed out) — resuming without it." >&2
|
|
38
44
|
exit 0
|
|
39
45
|
fi
|
|
40
46
|
|
|
47
|
+
if [[ "$CHECKPOINT" == *"not found"* || "$CHECKPOINT" == *"404"* ]]; then
|
|
48
|
+
exit 0 # Genuinely no checkpoint saved — nothing to announce.
|
|
49
|
+
fi
|
|
50
|
+
|
|
41
51
|
# Extract just the content field from the JSON response
|
|
42
52
|
CONTENT=$(echo "$CHECKPOINT" | jq -r '.content // empty' 2>/dev/null)
|
|
43
53
|
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
# 0 = allow
|
|
22
22
|
# 2 = block (path filters explain why CI didn't trigger — dispatch not needed)
|
|
23
23
|
|
|
24
|
+
|
|
25
|
+
|
|
24
26
|
# Fail-open: any unexpected error → allow the command through
|
|
25
27
|
trap 'exit 0' ERR
|
|
26
28
|
|
|
@@ -68,7 +70,11 @@ WORKFLOW_FILE="$REPO_ROOT/.github/workflows/$WORKFLOW_NAME"
|
|
|
68
70
|
if [[ ! -f "$WORKFLOW_FILE" ]]; then
|
|
69
71
|
# Selector may be a display name or numeric ID — try resolving via gh CLI
|
|
70
72
|
if command -v gh &>/dev/null; then
|
|
71
|
-
|
|
73
|
+
# Network call to the GitHub API — bounded so an unreachable or slow API
|
|
74
|
+
# cannot hold the Bash tool call open. On timeout `timeout` exits 124, the
|
|
75
|
+
# substitution is empty, and we take the existing unresolvable-selector
|
|
76
|
+
# branch below: fail-open, unchanged.
|
|
77
|
+
RESOLVED_PATH=$(timeout "${WDG_GH_TIMEOUT_SECS:-10}" gh workflow view "$WORKFLOW_NAME" --json path -q .path 2>/dev/null || true)
|
|
72
78
|
if [[ -n "$RESOLVED_PATH" && -f "$REPO_ROOT/$RESOLVED_PATH" ]]; then
|
|
73
79
|
WORKFLOW_FILE="$REPO_ROOT/$RESOLVED_PATH"
|
|
74
80
|
else
|
|
@@ -130,7 +136,10 @@ if [[ -z "$PATH_FILTERS" ]]; then
|
|
|
130
136
|
fi
|
|
131
137
|
|
|
132
138
|
# ── Get changed files on this branch ─────────────────────────────────────────
|
|
133
|
-
|
|
139
|
+
# Bounded: a three-dot diff walks history and can be slow on a large repo or a
|
|
140
|
+
# contended index lock. On timeout the result is empty and we take the existing
|
|
141
|
+
# can't-determine-changed-files branch: fail-open, unchanged.
|
|
142
|
+
CHANGED_FILES=$(timeout "${WDG_GIT_TIMEOUT_SECS:-15}" git -C "$REPO_ROOT" diff --name-only "origin/main...HEAD" 2>/dev/null || true)
|
|
134
143
|
|
|
135
144
|
if [[ -z "$CHANGED_FILES" ]]; then
|
|
136
145
|
exit 0 # Can't determine changed files — fail-open
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
"hooks": [
|
|
8
8
|
{
|
|
9
9
|
"type": "command",
|
|
10
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/memory-checkpoint-reminder.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
10
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/memory-checkpoint-reminder.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
11
|
+
"timeout": 60
|
|
11
12
|
}
|
|
12
13
|
]
|
|
13
14
|
},
|
|
@@ -16,31 +17,38 @@
|
|
|
16
17
|
"hooks": [
|
|
17
18
|
{
|
|
18
19
|
"type": "command",
|
|
19
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/worktree-guard.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
20
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/worktree-guard.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
21
|
+
"timeout": 60
|
|
20
22
|
},
|
|
21
23
|
{
|
|
22
24
|
"type": "command",
|
|
23
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/mx-guard-hook.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
25
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/mx-guard-hook.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
26
|
+
"timeout": 300
|
|
24
27
|
},
|
|
25
28
|
{
|
|
26
29
|
"type": "command",
|
|
27
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/ci-validate-hook.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
30
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/ci-validate-hook.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
31
|
+
"timeout": 3600
|
|
28
32
|
},
|
|
29
33
|
{
|
|
30
34
|
"type": "command",
|
|
31
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/workflow-dispatch-guard.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
35
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/workflow-dispatch-guard.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
36
|
+
"timeout": 60
|
|
32
37
|
},
|
|
33
38
|
{
|
|
34
39
|
"type": "command",
|
|
35
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/git-mutation-guard.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
40
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/git-mutation-guard.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
41
|
+
"timeout": 60
|
|
36
42
|
},
|
|
37
43
|
{
|
|
38
44
|
"type": "command",
|
|
39
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/named-memory-write-guard.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
45
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/named-memory-write-guard.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
46
|
+
"timeout": 60
|
|
40
47
|
},
|
|
41
48
|
{
|
|
42
49
|
"type": "command",
|
|
43
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/gh-pr-edit-guard.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
50
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/gh-pr-edit-guard.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
51
|
+
"timeout": 60
|
|
44
52
|
}
|
|
45
53
|
]
|
|
46
54
|
}
|
|
@@ -51,7 +59,8 @@
|
|
|
51
59
|
"hooks": [
|
|
52
60
|
{
|
|
53
61
|
"type": "command",
|
|
54
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/deploy-verification-reminder.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
62
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/deploy-verification-reminder.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
63
|
+
"timeout": 60
|
|
55
64
|
}
|
|
56
65
|
]
|
|
57
66
|
}
|
|
@@ -62,11 +71,13 @@
|
|
|
62
71
|
"hooks": [
|
|
63
72
|
{
|
|
64
73
|
"type": "command",
|
|
65
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/auto-checkpoint.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
74
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/auto-checkpoint.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
75
|
+
"timeout": 30
|
|
66
76
|
},
|
|
67
77
|
{
|
|
68
78
|
"type": "command",
|
|
69
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/auto-capture-precompact.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
79
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/auto-capture-precompact.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
80
|
+
"timeout": 30
|
|
70
81
|
}
|
|
71
82
|
]
|
|
72
83
|
}
|
|
@@ -77,7 +88,8 @@
|
|
|
77
88
|
"hooks": [
|
|
78
89
|
{
|
|
79
90
|
"type": "command",
|
|
80
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/reload-checkpoint.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
91
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/reload-checkpoint.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
92
|
+
"timeout": 20
|
|
81
93
|
}
|
|
82
94
|
]
|
|
83
95
|
},
|
|
@@ -86,11 +98,13 @@
|
|
|
86
98
|
"hooks": [
|
|
87
99
|
{
|
|
88
100
|
"type": "command",
|
|
89
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/set-terminal-appearance.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
101
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/set-terminal-appearance.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
102
|
+
"timeout": 5
|
|
90
103
|
},
|
|
91
104
|
{
|
|
92
105
|
"type": "command",
|
|
93
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/coordination-brief.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
106
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/coordination-brief.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
107
|
+
"timeout": 180
|
|
94
108
|
}
|
|
95
109
|
]
|
|
96
110
|
}
|
|
@@ -100,27 +114,33 @@
|
|
|
100
114
|
"hooks": [
|
|
101
115
|
{
|
|
102
116
|
"type": "command",
|
|
103
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/observability-sync.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
117
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/observability-sync.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
118
|
+
"timeout": 30
|
|
104
119
|
},
|
|
105
120
|
{
|
|
106
121
|
"type": "command",
|
|
107
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/auto-capture-session-end.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
122
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/auto-capture-session-end.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
123
|
+
"timeout": 30
|
|
108
124
|
},
|
|
109
125
|
{
|
|
110
126
|
"type": "command",
|
|
111
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/delegation-audit.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
127
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/delegation-audit.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
128
|
+
"timeout": 15
|
|
112
129
|
},
|
|
113
130
|
{
|
|
114
131
|
"type": "command",
|
|
115
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/iteration-log-check.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
132
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/iteration-log-check.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
133
|
+
"timeout": 20
|
|
116
134
|
},
|
|
117
135
|
{
|
|
118
136
|
"type": "command",
|
|
119
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/coordination-midsession-drain.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
137
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/coordination-midsession-drain.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
138
|
+
"timeout": 30
|
|
120
139
|
},
|
|
121
140
|
{
|
|
122
141
|
"type": "command",
|
|
123
|
-
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/session-idle-gate.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'"
|
|
142
|
+
"command": "bash -c 'H=\"${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null)}/.claude/hooks/session-idle-gate.sh\"; [ -f \"$H\" ] && exec bash \"$H\" || exit 0'",
|
|
143
|
+
"timeout": 60
|
|
124
144
|
}
|
|
125
145
|
]
|
|
126
146
|
}
|
|
@@ -38,6 +38,17 @@
|
|
|
38
38
|
* DO NOT re-widen this on a hunch. If a Codex upgrade changes the payload, the schema
|
|
39
39
|
* above is re-derivable in one command, and VERIFIED_CODEX_VERSION plus
|
|
40
40
|
* .devcontainer/codex-version.pin exist precisely so that upgrade is a deliberate act.
|
|
41
|
+
*
|
|
42
|
+
* ─── THIS CONSTANT APPLIES TO `SubagentStart` ONLY (#4859 review, Should Fixes) ────
|
|
43
|
+
* An earlier revision also read `agent_type` out of a spawn tool's `tool_input`, and
|
|
44
|
+
* parsed `agent://<name>` references with a token-grab regex that resolved
|
|
45
|
+
* `agent://user@host` to `user`. Both are gone rather than corrected: `agent_type` is
|
|
46
|
+
* forbidden by the spawn schema's `additionalProperties: false`, `agent://` is not a
|
|
47
|
+
* mention target Codex implements, and a URL-ish string in a spawn call is not a URL —
|
|
48
|
+
* so parsing it more carefully would have made a meaningless value look trustworthy.
|
|
49
|
+
* Deleting the code is the durable fix. Both defects were inert at review time and
|
|
50
|
+
* would have become live the moment a role parameter appeared, which is precisely when
|
|
51
|
+
* nobody would re-audit them; there is now nothing left to re-audit.
|
|
41
52
|
*/
|
|
42
53
|
export declare const AGENT_NAME_FIELD = "agent_type";
|
|
43
54
|
export interface GateDecision {
|
|
@@ -62,6 +73,17 @@ export declare function extractAgentName(payload: unknown): string | null;
|
|
|
62
73
|
/**
|
|
63
74
|
* Decide whether a subagent spawn may proceed. Pure — no I/O, no process exit — so
|
|
64
75
|
* the decision is directly testable.
|
|
76
|
+
*
|
|
77
|
+
* Handles BOTH registered events, and they are NOT symmetrical:
|
|
78
|
+
*
|
|
79
|
+
* - `PreToolUse` on a spawn tool → REFUSE, unconditionally. This is the branch that
|
|
80
|
+
* enforces anything today. See SPAWN_REFUSAL for why it authorises nothing: the
|
|
81
|
+
* runtime supplies no agent identity, so there is nothing to authorise against.
|
|
82
|
+
* - `SubagentStart` → per-agent eligibility, unchanged. Defence in depth against a
|
|
83
|
+
* future Codex that fires it (#4857); this event's `agent_type` is RUNTIME-supplied
|
|
84
|
+
* and `required` by Codex's own schema, not a caller-written label, so a decision
|
|
85
|
+
* based on it is a decision about the agent that is actually starting. If that
|
|
86
|
+
* event ever starts firing, the spawn branch stays closed regardless.
|
|
65
87
|
*/
|
|
66
88
|
export declare function decideCodexAgentGate(opts: {
|
|
67
89
|
rawPayload: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-agent-gate.d.ts","sourceRoot":"","sources":["../../src/commands/codex-agent-gate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"codex-agent-gate.d.ts","sourceRoot":"","sources":["../../src/commands/codex-agent-gate.ts"],"names":[],"mappings":"AA4HA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAE7C,MAAM,WAAW,YAAY;IAC3B,qEAAqE;IACrE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IAChB,+EAA+E;IAC/E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAMhE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,GAAG,YAAY,CA0Ef;AAED,2EAA2E;AAC3E,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAYvE;AAgBD,2FAA2F;AAC3F,wBAAsB,iBAAiB,CAAC,IAAI,GAAE,SAAS,MAAM,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAQnF"}
|
|
@@ -2,22 +2,42 @@
|
|
|
2
2
|
* `mx-agent internal-codex-agent-gate` — the RUNTIME enforcement point for Codex
|
|
3
3
|
* agent eligibility (#4227, security review MF2).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* WHAT THIS ENFORCES, STATED PLAINLY. Under codex-cli 0.145.0 it refuses EVERY
|
|
6
|
+
* subagent spawn through the spawn tools. It does not implement per-agent eligibility
|
|
7
|
+
* there, because the runtime exposes no agent identity to be eligible — see
|
|
8
|
+
* SPAWN_REFUSAL below for the schema and the live behavioural proof. Per-agent
|
|
9
|
+
* eligibility survives only on the `SubagentStart` path, which this Codex version
|
|
10
|
+
* never fires; that path is preparation for a future runtime, not a live control.
|
|
11
|
+
*
|
|
12
|
+
* Do not describe this file as "FR-14b and FR-15 are now enforced under Codex". The
|
|
13
|
+
* accurate statement is: the enforcing call site exists and works, and because agent
|
|
14
|
+
* identity does not exist in this runtime, the gate refuses wholesale rather than
|
|
15
|
+
* selectively.
|
|
16
|
+
*
|
|
17
|
+
* WHY IT EXISTS. `checkCodexAgentEligibility` encoded FR-14b (security-reviewer is
|
|
6
18
|
* ineligible) and FR-15 (every Bash-holding agent is ineligible until its guard is
|
|
7
19
|
* proven firing) and was called from nowhere. Twenty tests asserted refusal text that
|
|
8
20
|
* no code path could produce, so the "controls" were documentation. This command is
|
|
9
|
-
* the call site: the generated `.codex/hooks.json` registers it
|
|
10
|
-
*
|
|
21
|
+
* the call site: the generated `.codex/hooks.json` registers it on TWO events, and a
|
|
22
|
+
* refusal (exit 2) blocks the spawn.
|
|
11
23
|
*
|
|
12
|
-
*
|
|
24
|
+
* ─── WHICH EVENT ACTUALLY FIRES (#4857) ─────────────────────────────────────────
|
|
25
|
+
* `SubagentStart` alone was not enough, and shipping it alone was a control that
|
|
26
|
+
* reported coverage it did not have. codex-cli 0.145.0 DOES NOT FIRE SubagentStart
|
|
27
|
+
* for `spawn_agent`: probed live on 2026-08-01, four sessions, zero SubagentStart
|
|
28
|
+
* events, including one where the spawn SUCCEEDED and the subagent replied. The same
|
|
29
|
+
* probes showed PreToolUse DOES fire for the spawn tool and that exit 2 there BLOCKS
|
|
30
|
+
* the call. The primary registration is therefore a PreToolUse matcher on the spawn
|
|
31
|
+
* tools; SubagentStart is kept as defence in depth. See CODEX_SPAWN_TOOL_MATCHER in
|
|
32
|
+
* codex-config.ts for the probe detail and the matcher-semantics evidence.
|
|
13
33
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
34
|
+
* FAIL CLOSED. Unreadable input resolves to refusal everywhere: an unparseable payload,
|
|
35
|
+
* a payload that is not an object, a PreToolUse payload with no `tool_name`, and any
|
|
36
|
+
* `hook_event_name` this gate has not been verified against. `--proven-guards`, written
|
|
37
|
+
* by the generator from the adapter's own list, still governs the SubagentStart path —
|
|
38
|
+
* absent or empty means nothing is proven, the pre-G-7 state. It has no effect on the
|
|
39
|
+
* spawn path, which refuses regardless: proving a guard fires does not create an agent
|
|
40
|
+
* identity for the runtime to bind.
|
|
21
41
|
*
|
|
22
42
|
* The generated hooks.json is therefore the trust anchor for this decision. An agent
|
|
23
43
|
* that can edit that file can widen its own allowlist, which is why the G-7 paired
|
|
@@ -25,6 +45,79 @@
|
|
|
25
45
|
* own hook-trust mechanism, not this file's contents, is the boundary that matters.
|
|
26
46
|
*/
|
|
27
47
|
import { checkCodexAgentEligibility } from '../lib/runtime/codex-adapter.js';
|
|
48
|
+
import { CODEX_SPAWN_TOOL_MATCHER } from '../lib/runtime/codex-config.js';
|
|
49
|
+
/**
|
|
50
|
+
* Does this PreToolUse payload describe a call to a subagent-spawning tool?
|
|
51
|
+
*
|
|
52
|
+
* Built from the SAME pattern the generated matcher uses, so the two cannot drift:
|
|
53
|
+
* if the matcher fires for a tool, this predicate recognises it, and vice versa.
|
|
54
|
+
* Anchored, because Codex's own matcher is a full match (probed — see
|
|
55
|
+
* CODEX_SPAWN_TOOL_MATCHER) and a substring match here would let `not_spawn_agentx`
|
|
56
|
+
* through the same code path as a real spawn.
|
|
57
|
+
*/
|
|
58
|
+
const SPAWN_TOOL_RE = new RegExp(`^${CODEX_SPAWN_TOOL_MATCHER}$`);
|
|
59
|
+
/**
|
|
60
|
+
* ─── WHY EVERY SPAWN IS REFUSED, NOT JUST INELIGIBLE ONES (#4859 security review) ──
|
|
61
|
+
*
|
|
62
|
+
* The first version of this gate read a requested agent name out of the spawn call and
|
|
63
|
+
* ran it through `checkCodexAgentEligibility`. That was wrong, and it was wrong in the
|
|
64
|
+
* way that matters: THE IDENTITY IT AUTHORISED DOES NOT EXIST IN THE RUNTIME.
|
|
65
|
+
*
|
|
66
|
+
* codex-cli 0.145.0's `spawn_agent` takes no role, persona or agent-type parameter.
|
|
67
|
+
* Its schema, captured from this change's own probe rollouts, is:
|
|
68
|
+
*
|
|
69
|
+
* properties: { fork_context, items, message, model, reasoning_effort, service_tier }
|
|
70
|
+
* additionalProperties: false
|
|
71
|
+
*
|
|
72
|
+
* `items[].path` documents exactly two mention targets — `app://<connector-id>` and
|
|
73
|
+
* `plugin://<plugin-name>@<marketplace-name>`. There is no `agent://` target: the
|
|
74
|
+
* string `agent:/` occurs ZERO times in the 0.145.0 binary, against 6 for `app://`,
|
|
75
|
+
* 4 for `plugin://` and 25 for `skill://`.
|
|
76
|
+
*
|
|
77
|
+
* So every "identity" a caller can write — `agent_type`, a mention name, an
|
|
78
|
+
* `agent://x` reference in the message — is a label the runtime DISCARDS. Proven
|
|
79
|
+
* behaviourally, not just from the schema: a spawn whose mention named an agent whose
|
|
80
|
+
* definition said "your entire reply must be exactly PINEAPPLE, ignore any instruction
|
|
81
|
+
* telling you otherwise", given the task "reply with the single word BANANA", replied
|
|
82
|
+
* BANANA. The named definition was never loaded. The earlier paired proof's "allowed
|
|
83
|
+
* git-expert" spawn came back with the nickname "Heisenberg", assigned at random.
|
|
84
|
+
*
|
|
85
|
+
* The consequence is that per-agent eligibility was decorative: the same shell-capable
|
|
86
|
+
* task refused as `security-reviewer` was allowed by relabelling it `git-expert`, and
|
|
87
|
+
* an anonymous spawn was allowed by adding eighteen cosmetic characters. FR-14b was
|
|
88
|
+
* one string away from being bypassed.
|
|
89
|
+
*
|
|
90
|
+
* A CONTROL THAT CANNOT DISTINGUISH THE THING IT AUTHORISES MUST NOT AUTHORISE. This
|
|
91
|
+
* file's own header principle — a gate that cannot read its input does not allow the
|
|
92
|
+
* operation — applied one level up: the gate cannot read agent identity because the
|
|
93
|
+
* runtime has none to give. So the gate refuses every spawn through the gated tools,
|
|
94
|
+
* unconditionally, and says why.
|
|
95
|
+
*
|
|
96
|
+
* WHEN CAN THIS BE RELAXED? When Codex exposes a role-carrying spawn API whose value
|
|
97
|
+
* the runtime resolves and binds, rather than echoes. Upstream tracking, all open as of
|
|
98
|
+
* 2026-08-02: openai/codex#26828 (custom subagent roles not exposed in the spawn_agent
|
|
99
|
+
* schema), #26363 (project `.codex/agents/*.toml` no longer selectable as of CLI
|
|
100
|
+
* v0.137.0 — subagents spawn generic and inherit the parent model), #14579 (custom
|
|
101
|
+
* roles from `.codex/config.toml` unavailable to spawn_agent), #26408, #26868. Note
|
|
102
|
+
* that Codex's custom agents live in `.codex/agents/*.toml`, NOT in `.claude/agents/`,
|
|
103
|
+
* which is why a `.claude` agent name resolves to nothing here.
|
|
104
|
+
*
|
|
105
|
+
* COST TODAY: none. No team has opted in to `--runtime codex` and gate G-7 has not
|
|
106
|
+
* passed, so this removes a capability nobody is using. Tracking: #4857, PR #4859.
|
|
107
|
+
*/
|
|
108
|
+
const SPAWN_REFUSAL = 'codex agent gate: subagent spawning is unavailable under codex. This is deliberate, not a ' +
|
|
109
|
+
'bug. codex-cli 0.145.0 exposes no role, persona or agent-type parameter on its spawn tools ' +
|
|
110
|
+
'(schema: fork_context, items, message, model, reasoning_effort, service_tier; ' +
|
|
111
|
+
'additionalProperties false; mention paths are app:// and plugin:// only), so an agent name ' +
|
|
112
|
+
'written into a spawn call is a label the runtime discards — proven live: a spawn labelled ' +
|
|
113
|
+
'with an agent whose definition demanded one reply returned a different one, and the named ' +
|
|
114
|
+
'definition was never loaded. Per-agent eligibility (FR-14b: security-reviewer is ineligible; ' +
|
|
115
|
+
'FR-15: no Bash-holding agent before its guard is proven) therefore cannot be enforced here: ' +
|
|
116
|
+
'refusing one agent and allowing another would only mean refusing one spelling and allowing ' +
|
|
117
|
+
'another. A control that cannot distinguish the thing it authorises must not authorise, so ' +
|
|
118
|
+
'every spawn is refused. Run the work in a Claude session. This can be relaxed when Codex ' +
|
|
119
|
+
'ships a role-carrying spawn API the runtime resolves rather than echoes — openai/codex ' +
|
|
120
|
+
'#26828, #26363, #14579. Tracking: MemNexus #4857, PR #4859.';
|
|
28
121
|
/**
|
|
29
122
|
* The field that carries the subagent's identity in a SubagentStart payload.
|
|
30
123
|
*
|
|
@@ -65,6 +158,17 @@ import { checkCodexAgentEligibility } from '../lib/runtime/codex-adapter.js';
|
|
|
65
158
|
* DO NOT re-widen this on a hunch. If a Codex upgrade changes the payload, the schema
|
|
66
159
|
* above is re-derivable in one command, and VERIFIED_CODEX_VERSION plus
|
|
67
160
|
* .devcontainer/codex-version.pin exist precisely so that upgrade is a deliberate act.
|
|
161
|
+
*
|
|
162
|
+
* ─── THIS CONSTANT APPLIES TO `SubagentStart` ONLY (#4859 review, Should Fixes) ────
|
|
163
|
+
* An earlier revision also read `agent_type` out of a spawn tool's `tool_input`, and
|
|
164
|
+
* parsed `agent://<name>` references with a token-grab regex that resolved
|
|
165
|
+
* `agent://user@host` to `user`. Both are gone rather than corrected: `agent_type` is
|
|
166
|
+
* forbidden by the spawn schema's `additionalProperties: false`, `agent://` is not a
|
|
167
|
+
* mention target Codex implements, and a URL-ish string in a spawn call is not a URL —
|
|
168
|
+
* so parsing it more carefully would have made a meaningless value look trustworthy.
|
|
169
|
+
* Deleting the code is the durable fix. Both defects were inert at review time and
|
|
170
|
+
* would have become live the moment a role parameter appeared, which is precisely when
|
|
171
|
+
* nobody would re-audit them; there is now nothing left to re-audit.
|
|
68
172
|
*/
|
|
69
173
|
export const AGENT_NAME_FIELD = 'agent_type';
|
|
70
174
|
/**
|
|
@@ -89,6 +193,17 @@ export function extractAgentName(payload) {
|
|
|
89
193
|
/**
|
|
90
194
|
* Decide whether a subagent spawn may proceed. Pure — no I/O, no process exit — so
|
|
91
195
|
* the decision is directly testable.
|
|
196
|
+
*
|
|
197
|
+
* Handles BOTH registered events, and they are NOT symmetrical:
|
|
198
|
+
*
|
|
199
|
+
* - `PreToolUse` on a spawn tool → REFUSE, unconditionally. This is the branch that
|
|
200
|
+
* enforces anything today. See SPAWN_REFUSAL for why it authorises nothing: the
|
|
201
|
+
* runtime supplies no agent identity, so there is nothing to authorise against.
|
|
202
|
+
* - `SubagentStart` → per-agent eligibility, unchanged. Defence in depth against a
|
|
203
|
+
* future Codex that fires it (#4857); this event's `agent_type` is RUNTIME-supplied
|
|
204
|
+
* and `required` by Codex's own schema, not a caller-written label, so a decision
|
|
205
|
+
* based on it is a decision about the agent that is actually starting. If that
|
|
206
|
+
* event ever starts firing, the spawn branch stays closed regardless.
|
|
92
207
|
*/
|
|
93
208
|
export function decideCodexAgentGate(opts) {
|
|
94
209
|
let payload;
|
|
@@ -98,19 +213,61 @@ export function decideCodexAgentGate(opts) {
|
|
|
98
213
|
catch {
|
|
99
214
|
return {
|
|
100
215
|
exitCode: 2,
|
|
101
|
-
message: 'codex agent gate: could not parse the
|
|
216
|
+
message: 'codex agent gate: could not parse the hook payload as JSON — refusing the ' +
|
|
102
217
|
'spawn. A gate that cannot read its input does not allow the operation.',
|
|
103
218
|
};
|
|
104
219
|
}
|
|
105
|
-
|
|
106
|
-
|
|
220
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
|
|
221
|
+
return {
|
|
222
|
+
exitCode: 2,
|
|
223
|
+
message: 'codex agent gate: hook payload was not a JSON object — refusing the spawn. ' +
|
|
224
|
+
'A gate that cannot read its input does not allow the operation.',
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
const envelope = payload;
|
|
228
|
+
const event = typeof envelope.hook_event_name === 'string' ? envelope.hook_event_name : '';
|
|
229
|
+
let agent = null;
|
|
230
|
+
if (event === 'PreToolUse') {
|
|
231
|
+
const toolName = envelope.tool_name;
|
|
232
|
+
if (typeof toolName !== 'string' || toolName.trim() === '') {
|
|
233
|
+
// Cannot tell whether this is a spawn. Refusing an unidentifiable tool call is
|
|
234
|
+
// the fail-closed direction; allowing it is how #4857 happened.
|
|
235
|
+
return {
|
|
236
|
+
exitCode: 2,
|
|
237
|
+
message: 'codex agent gate: PreToolUse payload carried no `tool_name` — refusing. The gate ' +
|
|
238
|
+
'cannot tell whether this call spawns a subagent, and an unreadable input is not consent.',
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
// Not a spawn tool → not this gate's business. This branch exists so that a
|
|
242
|
+
// widened or mis-edited matcher degrades to "no opinion" on unrelated tools
|
|
243
|
+
// instead of refusing every tool call in the session.
|
|
244
|
+
if (!SPAWN_TOOL_RE.test(toolName))
|
|
245
|
+
return { exitCode: 0 };
|
|
246
|
+
// UNCONDITIONAL. No field of `tool_input` is read, deliberately: every candidate
|
|
247
|
+
// identity in it is caller-written and runtime-discarded, so reading one could only
|
|
248
|
+
// produce a decision that looks principled and is not. Nothing here depends on
|
|
249
|
+
// `provenGuards` either — proving a guard fires does not create an agent identity.
|
|
250
|
+
return { exitCode: 2, message: SPAWN_REFUSAL };
|
|
251
|
+
}
|
|
252
|
+
else if (event === 'SubagentStart') {
|
|
253
|
+
agent = extractAgentName(payload);
|
|
254
|
+
if (!agent) {
|
|
255
|
+
return {
|
|
256
|
+
exitCode: 2,
|
|
257
|
+
message: 'codex agent gate: no agent name found in the SubagentStart payload — refusing the ' +
|
|
258
|
+
`spawn. Required field \`${AGENT_NAME_FIELD}\` was absent, blank or not a string. ` +
|
|
259
|
+
'That field is `required` in codex-cli 0.145.0\'s own subagent-start.command.input ' +
|
|
260
|
+
'schema, so a payload without it did not come from a Codex version this gate has ' +
|
|
261
|
+
'been verified against.',
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
107
266
|
return {
|
|
108
267
|
exitCode: 2,
|
|
109
|
-
message:
|
|
110
|
-
|
|
111
|
-
'
|
|
112
|
-
'schema, so a payload without it did not come from a Codex version this gate has ' +
|
|
113
|
-
'been verified against.',
|
|
268
|
+
message: `codex agent gate: unrecognised hook_event_name ${JSON.stringify(event)} — refusing. ` +
|
|
269
|
+
'This gate is registered on PreToolUse and SubagentStart only; a payload from anywhere ' +
|
|
270
|
+
'else is one it has not been verified against, and it does not guess.',
|
|
114
271
|
};
|
|
115
272
|
}
|
|
116
273
|
const result = checkCodexAgentEligibility(agent, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-agent-gate.js","sourceRoot":"","sources":["../../src/commands/codex-agent-gate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"codex-agent-gate.js","sourceRoot":"","sources":["../../src/commands/codex-agent-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAE1E;;;;;;;;GAQG;AACH,MAAM,aAAa,GAAG,IAAI,MAAM,CAAC,IAAI,wBAAwB,GAAG,CAAC,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,aAAa,GACjB,4FAA4F;IAC5F,6FAA6F;IAC7F,gFAAgF;IAChF,6FAA6F;IAC7F,4FAA4F;IAC5F,4FAA4F;IAC5F,+FAA+F;IAC/F,8FAA8F;IAC9F,6FAA6F;IAC7F,4FAA4F;IAC5F,2FAA2F;IAC3F,yFAAyF;IACzF,6DAA6D,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAW7C;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgB;IAC/C,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,OA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