claude-dev-env 1.39.0 → 1.41.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/CLAUDE.md +1 -1
- package/_shared/pr-loop/scripts/config/post_audit_thread_constants.py +10 -0
- package/_shared/pr-loop/scripts/config/reviews_disabled_constants.py +8 -0
- package/_shared/pr-loop/scripts/grant_project_claude_permissions.py +53 -3
- package/_shared/pr-loop/scripts/post_audit_thread.py +298 -3
- package/_shared/pr-loop/scripts/preflight.py +129 -2
- package/_shared/pr-loop/scripts/reviews_disabled.py +59 -0
- package/_shared/pr-loop/scripts/revoke_project_claude_permissions.py +68 -3
- package/_shared/pr-loop/scripts/tests/test_grant_project_claude_permissions.py +1 -1
- package/_shared/pr-loop/scripts/tests/test_post_audit_thread.py +194 -1
- package/_shared/pr-loop/scripts/tests/test_preflight.py +41 -0
- package/_shared/pr-loop/scripts/tests/test_reviews_disabled.py +36 -0
- package/_shared/pr-loop/scripts/tests/test_revoke_project_claude_permissions.py +1 -1
- package/agents/pr-description-writer.md +150 -52
- package/docs/PR_DESCRIPTION_GUIDE.md +127 -64
- package/hooks/_gh_pr_author_swap_utils.py +1211 -0
- package/hooks/blocking/gh_body_arg_blocker.py +9 -6
- package/hooks/blocking/gh_pr_author_enforcer.py +480 -0
- package/hooks/blocking/gh_pr_author_restore.py +100 -0
- package/hooks/blocking/pr_converge_bugteam_enforcer.py +170 -0
- package/hooks/blocking/pr_description_enforcer.py +56 -23
- package/hooks/blocking/test_gh_body_arg_blocker.py +25 -3
- package/hooks/blocking/test_gh_pr_author_enforcer.py +1166 -0
- package/hooks/blocking/test_gh_pr_author_restore.py +512 -0
- package/hooks/blocking/test_gh_pr_author_swap_utils.py +910 -0
- package/hooks/blocking/test_pr_converge_bugteam_enforcer.py +311 -0
- package/hooks/blocking/test_pr_description_enforcer.py +69 -8
- package/hooks/config/gh_pr_author_swap_constants.py +76 -0
- package/hooks/config/pr_converge_bugteam_enforcer_constants.py +55 -0
- package/hooks/config/pr_converge_bugteam_enforcer_state.py +67 -0
- package/hooks/config/pr_description_enforcer_constants.py +19 -0
- package/hooks/config/test_pr_description_enforcer_constants.py +82 -0
- package/hooks/hooks.json +40 -0
- package/hooks/lifecycle/pr_converge_bugteam_skill_tracker.py +204 -0
- package/hooks/lifecycle/test_pr_converge_bugteam_skill_tracker.py +283 -0
- package/hooks/session/gh_pr_author_session_cleanup.py +171 -0
- package/hooks/session/test_gh_pr_author_session_cleanup.py +575 -0
- package/hooks/test__gh_pr_author_swap_utils.py +333 -0
- package/package.json +1 -1
- package/skills/_shared/pr-loop/scripts/write_audit_outcomes.py +2 -2
- package/skills/_shared/pr-loop/scripts/write_fix_outcomes.py +2 -2
- package/skills/bugteam/SKILL.md +28 -10
- package/skills/bugteam/reference/audit-contract.md +22 -0
- package/skills/bugteam/reference/github-pr-reviews.md +1 -1
- package/skills/bugteam/reference/team-setup.md +5 -0
- package/skills/bugteam/scripts/bugteam_fix_hookspath.py +8 -2
- package/skills/bugteam/scripts/bugteam_preflight.py +36 -2
- package/skills/bugteam/scripts/test__claude_permissions_common.py +48 -0
- package/skills/bugteam/scripts/test_bugteam_preflight.py +41 -0
- package/skills/bugteam/scripts/test_claude_permissions_common.py +18 -10
- package/skills/copilot-review/SKILL.md +16 -0
- package/skills/findbugs/SKILL.md +35 -7
- package/skills/monitor-open-prs/SKILL.md +2 -1
- package/skills/pr-converge/SKILL.md +11 -3
- package/skills/pr-converge/config/constants.py +3 -1
- package/skills/pr-converge/reference/per-tick.md +17 -0
- package/skills/pr-converge/reference/state-schema.md +36 -8
- package/skills/pr-converge/scripts/check_bugbot_ci.py +113 -8
- package/skills/pr-converge/scripts/test_check_bugbot_ci.py +312 -0
- package/skills/qbug/SKILL.md +33 -8
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""SessionStart hook — sweep stale gh-pr-author swap state files at session start.
|
|
3
|
+
|
|
4
|
+
The PreToolUse enforcer (``gh_pr_author_enforcer.py``) writes a per-session
|
|
5
|
+
state file recording the original gh CLI account before swapping to
|
|
6
|
+
``GITHUB_DEFAULT_ACCOUNT``. The PostToolUse companion
|
|
7
|
+
(``gh_pr_author_restore.py``) reads that file and switches back when
|
|
8
|
+
``gh pr create`` finishes. When a session is interrupted between the
|
|
9
|
+
swap and the restore — a crash, a downstream PreToolUse deny that fires
|
|
10
|
+
*after* the enforcer's swap completed, or any other path that skips
|
|
11
|
+
PostToolUse — the user is left on ``GITHUB_DEFAULT_ACCOUNT`` with a
|
|
12
|
+
stale state file on disk.
|
|
13
|
+
|
|
14
|
+
This hook runs at the start of every Claude Code session. When
|
|
15
|
+
``GITHUB_DEFAULT_ACCOUNT`` is set, it scans ``tempfile.gettempdir()``
|
|
16
|
+
for every file matching ``{STATE_FILE_PREFIX}*{STATE_FILE_SUFFIX}``,
|
|
17
|
+
reads the original account from each, runs ``gh auth switch --user
|
|
18
|
+
<original>``, and deletes the file. A state file whose switch fails is
|
|
19
|
+
left in place so the next session can retry. The hook is a strict no-op
|
|
20
|
+
when ``GITHUB_DEFAULT_ACCOUNT`` is unset, so users who have not opted
|
|
21
|
+
into the swap workflow are completely unaffected.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import os
|
|
27
|
+
import sys
|
|
28
|
+
import tempfile
|
|
29
|
+
import time
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
_hooks_tree_path = str(Path(__file__).absolute().parent.parent)
|
|
34
|
+
if _hooks_tree_path not in sys.path:
|
|
35
|
+
sys.path.insert(0, _hooks_tree_path)
|
|
36
|
+
|
|
37
|
+
from _gh_pr_author_swap_utils import ( # noqa: E402 # sys.path shim above must run first
|
|
38
|
+
_delete_state_file,
|
|
39
|
+
_lstat_indicates_attacker_planted,
|
|
40
|
+
_read_original_account,
|
|
41
|
+
_switch_gh_account,
|
|
42
|
+
_write_line,
|
|
43
|
+
)
|
|
44
|
+
from config.gh_pr_author_swap_constants import ( # noqa: E402 # sys.path shim above must run first
|
|
45
|
+
REQUIRED_ACCOUNT_ENV_VAR,
|
|
46
|
+
STATE_FILE_PREFIX,
|
|
47
|
+
STATE_FILE_STALE_AGE_SECONDS,
|
|
48
|
+
STATE_FILE_SUFFIX,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _collect_stale_state_files(temp_directory: Path) -> list[Path]:
|
|
53
|
+
"""Return swap-state files older than the stale threshold and safe to process.
|
|
54
|
+
|
|
55
|
+
A state file younger than ``STATE_FILE_STALE_AGE_SECONDS`` is
|
|
56
|
+
treated as belonging to a concurrent Claude Code session that may
|
|
57
|
+
still be mid-``gh pr create``. Sweeping such a file would steal the
|
|
58
|
+
active session's restore target. Files older than the threshold are
|
|
59
|
+
overwhelmingly likely to be stale — the enforcer-to-restore window
|
|
60
|
+
is bounded by the gh subprocess timeouts (10s switch + 5s api user
|
|
61
|
+
+ filesystem work), so any file older than
|
|
62
|
+
``STATE_FILE_STALE_AGE_SECONDS`` is past the longest plausible
|
|
63
|
+
active window.
|
|
64
|
+
|
|
65
|
+
Each candidate is also screened for ownership and permission bits
|
|
66
|
+
matching the enforcer's write contract. A file with mode bits other
|
|
67
|
+
than ``STATE_FILE_PERMISSION_MODE`` or (on POSIX) owned by a
|
|
68
|
+
different user is silently skipped — it was not written by an
|
|
69
|
+
enforcer running as the current user and must not be allowed to
|
|
70
|
+
drive ``gh auth switch``.
|
|
71
|
+
|
|
72
|
+
The candidate is inspected via ``lstat`` rather than ``stat`` so a
|
|
73
|
+
symlink at the predictable swap-state path is screened on its own
|
|
74
|
+
metadata, not on whatever the symlink resolves to. Any entry that
|
|
75
|
+
is not a regular file (symlink, socket, fifo, device) is silently
|
|
76
|
+
skipped. The enforcer creates state files with ``O_NOFOLLOW``;
|
|
77
|
+
mirroring that contract here closes the symlink-hijack window where
|
|
78
|
+
an attacker plants a symlink pointing to a legitimate 0o600 file
|
|
79
|
+
owned by the current user to trick the cleanup hook into reading
|
|
80
|
+
that file as a swap-state payload.
|
|
81
|
+
|
|
82
|
+
Returned paths are sorted by modification time in ascending order so
|
|
83
|
+
that when the caller iterates and runs ``gh auth switch`` for each
|
|
84
|
+
file, the newest stale file is processed LAST. ``gh auth switch``
|
|
85
|
+
is global state — only the last switch wins — so processing the
|
|
86
|
+
newest file last leaves the gh CLI on the most recently captured
|
|
87
|
+
original account when multiple sessions crashed with different
|
|
88
|
+
original accounts. The single ``lstat`` syscall performed per
|
|
89
|
+
candidate is reused for both the attacker-planted screen and the
|
|
90
|
+
mtime ordering key so the sort does not double-stat.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
temp_directory: System temp directory returned by
|
|
94
|
+
``tempfile.gettempdir()``.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
List of swap-state file paths that are regular files whose
|
|
98
|
+
modification time is older than ``STATE_FILE_STALE_AGE_SECONDS``
|
|
99
|
+
seconds before now and whose ownership/mode bits match the
|
|
100
|
+
enforcer's write contract. Sorted by mtime ascending so the
|
|
101
|
+
newest stale file is last in iteration order. Empty list when
|
|
102
|
+
the temp directory cannot be listed.
|
|
103
|
+
"""
|
|
104
|
+
glob_pattern = f"{STATE_FILE_PREFIX}*{STATE_FILE_SUFFIX}"
|
|
105
|
+
current_time_seconds = time.time()
|
|
106
|
+
all_stale_candidates_with_mtime: list[tuple[float, Path]] = []
|
|
107
|
+
try:
|
|
108
|
+
all_candidate_paths = list(temp_directory.glob(glob_pattern))
|
|
109
|
+
except OSError:
|
|
110
|
+
return []
|
|
111
|
+
for each_candidate_path in all_candidate_paths:
|
|
112
|
+
try:
|
|
113
|
+
file_lstat_result = each_candidate_path.lstat()
|
|
114
|
+
except OSError:
|
|
115
|
+
continue
|
|
116
|
+
if _lstat_indicates_attacker_planted(file_lstat_result):
|
|
117
|
+
continue
|
|
118
|
+
file_age_seconds = current_time_seconds - file_lstat_result.st_mtime
|
|
119
|
+
if file_age_seconds >= STATE_FILE_STALE_AGE_SECONDS:
|
|
120
|
+
all_stale_candidates_with_mtime.append(
|
|
121
|
+
(file_lstat_result.st_mtime, each_candidate_path)
|
|
122
|
+
)
|
|
123
|
+
all_stale_candidates_with_mtime.sort(key=lambda each_mtime_path_pair: each_mtime_path_pair[0])
|
|
124
|
+
return [each_mtime_path_pair[1] for each_mtime_path_pair in all_stale_candidates_with_mtime]
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _restore_stale_state_file(state_file: Path) -> None:
|
|
128
|
+
"""Restore one stale state file: switch back, then delete on success.
|
|
129
|
+
|
|
130
|
+
A malformed state file is deleted without a switch attempt. A
|
|
131
|
+
well-formed file whose switch attempt fails is left on disk so the
|
|
132
|
+
next session-start can retry.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
state_file: Absolute path to a candidate state file.
|
|
136
|
+
"""
|
|
137
|
+
original_account = _read_original_account(state_file)
|
|
138
|
+
if original_account is None:
|
|
139
|
+
_delete_state_file(state_file)
|
|
140
|
+
return
|
|
141
|
+
has_switched_account = _switch_gh_account(original_account)
|
|
142
|
+
if has_switched_account:
|
|
143
|
+
_delete_state_file(state_file)
|
|
144
|
+
else:
|
|
145
|
+
_write_line(
|
|
146
|
+
f"[gh-pr-author-cleanup] failed to restore active gh account to {original_account!r} from "
|
|
147
|
+
f"stale state file {state_file}; left in place for next session",
|
|
148
|
+
sys.stderr,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def main() -> None:
|
|
153
|
+
"""Sweep stale gh-pr-author swap state files when the workflow is enabled.
|
|
154
|
+
|
|
155
|
+
Exits 0 in every path. When ``GITHUB_DEFAULT_ACCOUNT`` is unset the
|
|
156
|
+
hook returns immediately so users who have not opted into the swap
|
|
157
|
+
workflow see no behavior change. Otherwise iterates every matching
|
|
158
|
+
state file under ``tempfile.gettempdir()`` and restores each one
|
|
159
|
+
independently — a failure on one file does not block the others.
|
|
160
|
+
"""
|
|
161
|
+
required_account = os.environ.get(REQUIRED_ACCOUNT_ENV_VAR, "").strip()
|
|
162
|
+
if not required_account:
|
|
163
|
+
return
|
|
164
|
+
temp_directory = Path(tempfile.gettempdir())
|
|
165
|
+
all_stale_state_files = _collect_stale_state_files(temp_directory)
|
|
166
|
+
for each_state_file in all_stale_state_files:
|
|
167
|
+
_restore_stale_state_file(each_state_file)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
if __name__ == "__main__":
|
|
171
|
+
main()
|