@ethlete/agent-rules 0.1.0-next.6 → 0.1.0-next.61
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/AGENTS.md +28 -0
- package/CHANGELOG.md +847 -0
- package/CLAUDE.md +1 -0
- package/README.md +244 -36
- package/THIRD-PARTY-LICENSES.md +35 -0
- package/content/defaults.json +1 -1
- package/content/hooks/away-mode.py +413 -0
- package/content/hooks/background-commands.py +177 -0
- package/content/hooks/builder-idle-check.py +562 -0
- package/content/hooks/context-warning.py +666 -134
- package/content/hooks/git-safety.py +213 -0
- package/content/hooks/human-wait-check.py +167 -0
- package/content/hooks/subagent-model-policy.py +261 -0
- package/content/mods/.claude-plugin/marketplace.json +26 -0
- package/content/mods/plugins/codex-runs/.claude-plugin/plugin.json +6 -0
- package/content/mods/plugins/codex-runs/hooks/agent-runs.ts +310 -0
- package/content/mods/plugins/codex-runs/hooks/hooks.json +1 -0
- package/content/mods/plugins/codex-runs/hooks/progress.ts +130 -0
- package/content/mods/plugins/codex-runs/hooks/register.tsx +283 -0
- package/content/mods/plugins/codex-runs/tests/pane.test.ts +21 -0
- package/content/mods/plugins/codex-runs/tsconfig.json +4 -0
- package/content/mods/plugins/codex-runs/types/index.d.ts +37 -0
- package/content/mods/plugins/e2e-progress/.claude-plugin/plugin.json +6 -0
- package/content/mods/plugins/e2e-progress/hooks/hooks.json +1 -0
- package/content/mods/plugins/e2e-progress/hooks/progress.ts +205 -0
- package/content/mods/plugins/e2e-progress/hooks/register.tsx +498 -0
- package/content/mods/plugins/e2e-progress/tsconfig.json +3 -0
- package/content/mods/plugins/e2e-progress/types/index.d.ts +27 -0
- package/content/mods/plugins/status-line/.claude-plugin/plugin.json +6 -0
- package/content/mods/plugins/status-line/hooks/hooks.json +1 -0
- package/content/mods/plugins/status-line/hooks/line.ts +74 -0
- package/content/mods/plugins/status-line/hooks/register.tsx +141 -0
- package/content/mods/plugins/status-line/types/index.d.ts +5 -0
- package/content/mods/plugins/usage-line/.claude-plugin/plugin.json +6 -0
- package/content/mods/plugins/usage-line/hooks/codex.ts +52 -0
- package/content/mods/plugins/usage-line/hooks/format.ts +24 -0
- package/content/mods/plugins/usage-line/hooks/hooks.json +1 -0
- package/content/mods/plugins/usage-line/hooks/rate-limits.ts +23 -0
- package/content/mods/plugins/usage-line/hooks/register.tsx +83 -0
- package/content/mods/plugins/usage-line/tsconfig.json +4 -0
- package/content/mods/plugins/usage-line/types/index.d.ts +5 -0
- package/content/output-styles/ste-clarity.md +131 -0
- package/content/rules/agent-sessions-wake-up.md +11 -0
- package/content/rules/app-styling.md +66 -0
- package/content/rules/comments.md +4 -1
- package/content/rules/lint-and-format.md +7 -5
- package/content/rules/nx-layout.md +53 -0
- package/content/rules/reactive-state.md +1 -1
- package/content/rules/styling.md +19 -10
- package/content/rules/subagent-models.md +42 -0
- package/content/rules/waiting-on-the-human.md +17 -0
- package/content/skills/agent-sessions/SKILL.md +101 -0
- package/content/skills/agent-sessions/agent-sessions.mjs +1462 -0
- package/content/skills/angular-patterns/SKILL.md +31 -7
- package/content/skills/api-source/SKILL.md +156 -0
- package/content/skills/app-testing/SKILL.md +141 -0
- package/content/skills/codex-subagent/SKILL.md +102 -0
- package/content/skills/codex-subagent/codex-agent.mjs +260 -0
- package/content/skills/codex-subagent/codex-limit.mjs +106 -0
- package/content/skills/design-exploration/SKILL.md +121 -0
- package/content/skills/design-exploration/check-story.mjs +139 -0
- package/content/skills/design-exploration/reference-shots.md +15 -0
- package/content/skills/design-exploration/shoot-template.mjs +61 -0
- package/content/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
- package/content/skills/domain-modeling/SKILL.md +71 -0
- package/content/skills/e2e-triage/SKILL.md +80 -0
- package/content/skills/figma-export/SKILL.md +16 -18
- package/content/skills/git-commit/SKILL.md +21 -7
- package/content/skills/git-flow/SKILL.md +9 -5
- package/content/skills/grill-with-docs/SKILL.md +13 -0
- package/content/skills/grilling/SKILL.md +52 -0
- package/content/skills/handoff/SKILL.md +30 -72
- package/content/skills/handoff/save.md +189 -0
- package/content/skills/query/SKILL.md +165 -74
- package/content/skills/report/SKILL.md +26 -0
- package/content/skills/rxjs-signals/SKILL.md +33 -4
- package/content/skills/sdk-docs/SKILL.md +50 -14
- package/content/skills/sdk-local-build/SKILL.md +26 -8
- package/content/skills/sdk-local-build/sdk-local-baseline.mjs +64 -0
- package/content/skills/sdk-source/SKILL.md +37 -34
- package/content/skills/sdk-update/SKILL.md +103 -0
- package/content/skills/story-styling/SKILL.md +12 -10
- package/content/skills/styleguide/SKILL.md +13 -8
- package/content/skills/styleguide/assets.md +54 -0
- package/content/skills/styleguide/changesets.md +17 -0
- package/content/skills/styleguide/file-structure.md +73 -0
- package/content/skills/styleguide/lint-rule-lookup.md +52 -0
- package/content/skills/styleguide/storybook-structure.md +25 -0
- package/content/skills/theming/SKILL.md +76 -49
- package/content/skills/verify-in-app/SKILL.md +107 -0
- package/content/skills/verify-in-storybook/SKILL.md +1 -1
- package/content/skills/verify-on-apple-devices/SKILL.md +100 -0
- package/content/skills/verify-on-apple-devices/apple-remote.sh +421 -0
- package/content/skills/verify-on-apple-devices/sim-edge-back.m +159 -0
- package/migrations/list-state-query-form.md +20 -0
- package/migrations/nx-layout.md +29 -0
- package/migrations/sdk-components-over-hand-built-ui.md +27 -0
- package/migrations/search-query-field.md +52 -0
- package/migrations/studio-claude-plugin.md +27 -0
- package/migrations.json +47 -0
- package/package.json +8 -3
- package/src/index.js +84 -28
- package/src/index.js.map +1 -1
- package/src/lib/cli-args.d.ts +9 -0
- package/src/lib/cli-args.js +48 -0
- package/src/lib/cli-args.js.map +1 -0
- package/src/lib/commitlint.d.ts +10 -0
- package/src/lib/commitlint.js +51 -0
- package/src/lib/commitlint.js.map +1 -0
- package/src/lib/config.d.ts +53 -22
- package/src/lib/config.js +128 -12
- package/src/lib/config.js.map +1 -1
- package/src/lib/filter.d.ts +3 -0
- package/src/lib/filter.js +7 -5
- package/src/lib/filter.js.map +1 -1
- package/src/lib/frontmatter.d.ts +2 -0
- package/src/lib/frontmatter.js +33 -5
- package/src/lib/frontmatter.js.map +1 -1
- package/src/lib/git-flow/config.js +1 -1
- package/src/lib/git-flow/config.js.map +1 -1
- package/src/lib/git-flow/index.d.ts +1 -0
- package/src/lib/git-flow/index.js +20 -6
- package/src/lib/git-flow/index.js.map +1 -1
- package/src/lib/git-flow/parse.js +38 -12
- package/src/lib/git-flow/parse.js.map +1 -1
- package/src/lib/git-flow/rename.d.ts +24 -0
- package/src/lib/git-flow/rename.js +70 -0
- package/src/lib/git-flow/rename.js.map +1 -0
- package/src/lib/git-flow/start.d.ts +27 -0
- package/src/lib/git-flow/start.js +34 -1
- package/src/lib/git-flow/start.js.map +1 -1
- package/src/lib/git-flow-command.js +10 -2
- package/src/lib/git-flow-command.js.map +1 -1
- package/src/lib/git-flow-repair.d.ts +1 -1
- package/src/lib/git-flow-repair.js +30 -15
- package/src/lib/git-flow-repair.js.map +1 -1
- package/src/lib/git-flow-start.d.ts +1 -1
- package/src/lib/git-flow-start.js +25 -32
- package/src/lib/git-flow-start.js.map +1 -1
- package/src/lib/git.d.ts +37 -0
- package/src/lib/git.js +85 -3
- package/src/lib/git.js.map +1 -1
- package/src/lib/gitlab.js +24 -6
- package/src/lib/gitlab.js.map +1 -1
- package/src/lib/index.d.ts +2 -0
- package/src/lib/index.js +26 -11
- package/src/lib/index.js.map +1 -1
- package/src/lib/migrate.js +8 -2
- package/src/lib/migrate.js.map +1 -1
- package/src/lib/output-style-command.d.ts +3 -0
- package/src/lib/output-style-command.js +69 -0
- package/src/lib/output-style-command.js.map +1 -0
- package/src/lib/output-style.d.ts +38 -0
- package/src/lib/output-style.js +134 -0
- package/src/lib/output-style.js.map +1 -0
- package/src/lib/owned-paths.js +8 -2
- package/src/lib/owned-paths.js.map +1 -1
- package/src/lib/package-runner.d.ts +4 -0
- package/src/lib/package-runner.js +86 -0
- package/src/lib/package-runner.js.map +1 -0
- package/src/lib/plain-text.d.ts +9 -0
- package/src/lib/plain-text.js +22 -0
- package/src/lib/plain-text.js.map +1 -0
- package/src/lib/plan.d.ts +6 -6
- package/src/lib/plan.js +153 -40
- package/src/lib/plan.js.map +1 -1
- package/src/lib/prettier.d.ts +21 -0
- package/src/lib/prettier.js +51 -0
- package/src/lib/prettier.js.map +1 -0
- package/src/lib/prompt.js +10 -2
- package/src/lib/prompt.js.map +1 -1
- package/src/lib/render.d.ts +14 -1
- package/src/lib/render.js +23 -5
- package/src/lib/render.js.map +1 -1
- package/src/lib/report-command.d.ts +34 -0
- package/src/lib/report-command.js +322 -0
- package/src/lib/report-command.js.map +1 -0
- package/src/lib/sessions-command.d.ts +4 -0
- package/src/lib/sessions-command.js +16 -0
- package/src/lib/sessions-command.js.map +1 -0
- package/src/lib/sync.d.ts +1 -2
- package/src/lib/sync.js +37 -17
- package/src/lib/sync.js.map +1 -1
- package/src/lib/targets/agents-skills.js +1 -1
- package/src/lib/targets/agents-skills.js.map +1 -1
- package/src/lib/targets/claude-hooks.d.ts +5 -0
- package/src/lib/targets/claude-hooks.js +27 -4
- package/src/lib/targets/claude-hooks.js.map +1 -1
- package/src/lib/targets/claude-mods.d.ts +20 -0
- package/src/lib/targets/claude-mods.js +47 -0
- package/src/lib/targets/claude-mods.js.map +1 -0
- package/src/lib/targets/claude.js +2 -3
- package/src/lib/targets/claude.js.map +1 -1
- package/src/lib/targets/codex-hooks.js +4 -2
- package/src/lib/targets/codex-hooks.js.map +1 -1
- package/src/lib/targets/codex.js +4 -4
- package/src/lib/targets/codex.js.map +1 -1
- package/src/lib/targets/copilot.js +4 -4
- package/src/lib/targets/copilot.js.map +1 -1
- package/src/lib/targets/cursor.js +3 -3
- package/src/lib/targets/cursor.js.map +1 -1
- package/src/lib/targets/git-hooks.d.ts +1 -1
- package/src/lib/targets/git-hooks.js +6 -5
- package/src/lib/targets/git-hooks.js.map +1 -1
- package/src/lib/targets/hooks-shared.d.ts +34 -5
- package/src/lib/targets/hooks-shared.js +132 -36
- package/src/lib/targets/hooks-shared.js.map +1 -1
- package/src/lib/targets/mcp.d.ts +25 -0
- package/src/lib/targets/mcp.js +114 -0
- package/src/lib/targets/mcp.js.map +1 -0
- package/src/lib/targets/shared.d.ts +1 -9
- package/src/lib/targets/shared.js +4 -8
- package/src/lib/targets/shared.js.map +1 -1
- package/src/lib/timetrack.d.ts +16 -0
- package/src/lib/timetrack.js +149 -0
- package/src/lib/timetrack.js.map +1 -0
- package/content/skills/styleguide/STYLEGUIDE.md +0 -520
- package/src/lib/jira.d.ts +0 -28
- package/src/lib/jira.js +0 -83
- package/src/lib/jira.js.map +0 -1
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""PreToolUse hook: git safety in a checkout several agents share.
|
|
3
|
+
|
|
4
|
+
Denies, for a Bash call:
|
|
5
|
+
- `git add -A`, `git add --all` and `git add .` (they stage other sessions' work)
|
|
6
|
+
- every `git stash` that writes (bare, `push`, `save`, `pop`, `apply`, `drop`, `clear`, `branch`,
|
|
7
|
+
`create`, `store`); `git stash list` and `git stash show` stay allowed
|
|
8
|
+
- `git commit --amend`
|
|
9
|
+
- `git commit` without a ` -- <paths>` pathspec, except the commit that concludes a merge: while
|
|
10
|
+
`MERGE_HEAD` exists and every staged path changed between HEAD and MERGE_HEAD, is conflicted, or is a
|
|
11
|
+
plan archive under `plans/**/archive/` (an archive run that shrinks a merged plan writes there)
|
|
12
|
+
|
|
13
|
+
`git commit-tree` and `git update-index` stay allowed, so a merge commit built on a temporary
|
|
14
|
+
GIT_INDEX_FILE works. Only real command positions count: commit messages (`-m`, `--message`), quoted text and heredoc
|
|
15
|
+
bodies are ignored, so a grep pattern or message that mentions `git stash` does not trip the hook.
|
|
16
|
+
|
|
17
|
+
Can be disabled per machine via a gitignored ethlete-agents.config.local.json at the repo
|
|
18
|
+
root: {"disableHooks": true} or {"disableHooks": ["git-safety"]}.
|
|
19
|
+
|
|
20
|
+
Fail-safe: any error exits 0 with no output.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import json
|
|
24
|
+
import os
|
|
25
|
+
import re
|
|
26
|
+
import subprocess
|
|
27
|
+
import sys
|
|
28
|
+
|
|
29
|
+
HOOK_NAME = "git-safety"
|
|
30
|
+
LOCAL_CONFIG_FILE = "ethlete-agents.config.local.json"
|
|
31
|
+
|
|
32
|
+
MESSAGE_ARG = re.compile(
|
|
33
|
+
r"""(?:^|(?<=\s))(?:-[a-zA-Z]*m|--message)(?:=|\s*)(?:"(?:\\.|[^"\\])*"|'[^']*'|[^\s;&|]*)"""
|
|
34
|
+
)
|
|
35
|
+
SEGMENT_SPLIT = re.compile(r"[;&|\n()`]+")
|
|
36
|
+
HEREDOC = re.compile(r"<<-?[ \t]*(['\"]?)(\w+)\1([^\n]*)\n(?:.*?\n)?[ \t]*\2[ \t]*(?=\n|$)", re.DOTALL)
|
|
37
|
+
QUOTED = re.compile(r"\"(?:\\.|[^\"\\])*\"|'[^']*'")
|
|
38
|
+
GLOBAL_OPTS_WITH_VALUE = ("-C", "-c", "--git-dir", "--work-tree", "--namespace")
|
|
39
|
+
ADD_ALL = ("-A", "--all", ".")
|
|
40
|
+
|
|
41
|
+
def agent_name(argv):
|
|
42
|
+
for index, arg in enumerate(argv):
|
|
43
|
+
if arg == "--agent" and index + 1 < len(argv):
|
|
44
|
+
return argv[index + 1]
|
|
45
|
+
if arg.startswith("--agent="):
|
|
46
|
+
return arg.split("=", 1)[1]
|
|
47
|
+
return "claude"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def repo_root(data):
|
|
51
|
+
for variable in ("CLAUDE_PROJECT_DIR", "CODEX_PROJECT_DIR"):
|
|
52
|
+
value = os.environ.get(variable)
|
|
53
|
+
if value:
|
|
54
|
+
return value
|
|
55
|
+
here = os.path.abspath(__file__)
|
|
56
|
+
derived = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(here))))
|
|
57
|
+
if os.path.isfile(os.path.join(derived, LOCAL_CONFIG_FILE)):
|
|
58
|
+
return derived
|
|
59
|
+
cwd = data.get("cwd")
|
|
60
|
+
return cwd if isinstance(cwd, str) and cwd else derived
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def load_local_config(root):
|
|
64
|
+
if not root:
|
|
65
|
+
return {}
|
|
66
|
+
try:
|
|
67
|
+
with open(os.path.join(root, LOCAL_CONFIG_FILE), encoding="utf-8") as f:
|
|
68
|
+
config = json.load(f)
|
|
69
|
+
except (OSError, ValueError, AttributeError):
|
|
70
|
+
return {}
|
|
71
|
+
return config if isinstance(config, dict) else {}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def disabled_locally(config):
|
|
75
|
+
disabled = config.get("disableHooks")
|
|
76
|
+
return disabled is True or (isinstance(disabled, list) and HOOK_NAME in disabled)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def git_calls_in(command):
|
|
80
|
+
"""Yield (subcommand, args) for every command-position git call in the shell string."""
|
|
81
|
+
stripped = MESSAGE_ARG.sub(" ", HEREDOC.sub(r"<<\3", command))
|
|
82
|
+
unquoted = QUOTED.sub(lambda m: re.sub(r"[\s;&|(`]", "_", m.group(0)[1:-1]), stripped)
|
|
83
|
+
for segment in SEGMENT_SPLIT.split(unquoted):
|
|
84
|
+
words = segment.split()
|
|
85
|
+
index = 0
|
|
86
|
+
while index < len(words) and re.match(r"^[A-Za-z_][A-Za-z0-9_]*=", words[index]):
|
|
87
|
+
index += 1
|
|
88
|
+
if index < len(words) and (words[index] == "git" or words[index].endswith("/git")):
|
|
89
|
+
rest = words[index + 1 :]
|
|
90
|
+
directory = None
|
|
91
|
+
while rest and rest[0].startswith("-"):
|
|
92
|
+
if rest[0] == "-C" and len(rest) > 1:
|
|
93
|
+
directory = rest[1]
|
|
94
|
+
skip = 2 if rest[0] in GLOBAL_OPTS_WITH_VALUE else 1
|
|
95
|
+
rest = rest[skip:]
|
|
96
|
+
if rest:
|
|
97
|
+
yield rest[0], rest[1:], directory
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
STASH_READS = ("list", "show")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def stash_subcommand_of(args):
|
|
104
|
+
"""The stash subcommand `args` run; a bare `git stash` or one starting with an option is `push`."""
|
|
105
|
+
return args[0] if args and not args[0].startswith("-") else "push"
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def git_lines(cwd, *args):
|
|
109
|
+
result = subprocess.run(["git", *args], cwd=cwd, capture_output=True, text=True, timeout=10, check=True)
|
|
110
|
+
return {line for line in result.stdout.splitlines() if line}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def concludes_merge(cwd):
|
|
114
|
+
"""True while MERGE_HEAD exists and every staged path belongs to the merge. Any error is False."""
|
|
115
|
+
try:
|
|
116
|
+
merge_head = git_lines(cwd, "rev-parse", "--git-path", "MERGE_HEAD")
|
|
117
|
+
if not merge_head or not os.path.isfile(os.path.join(cwd, next(iter(merge_head)))):
|
|
118
|
+
return False
|
|
119
|
+
staged = git_lines(cwd, "diff", "--cached", "--name-only")
|
|
120
|
+
merge_paths = git_lines(cwd, "diff", "--name-only", "HEAD", "MERGE_HEAD") | git_lines(
|
|
121
|
+
cwd, "diff", "--name-only", "--diff-filter=U"
|
|
122
|
+
)
|
|
123
|
+
return all(path in merge_paths or is_plan_archive(path) for path in staged)
|
|
124
|
+
except Exception:
|
|
125
|
+
return False
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def is_plan_archive(path):
|
|
129
|
+
return path.startswith("plans/") and "/archive/" in path
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def stages_everything(args):
|
|
133
|
+
return any(arg == "--all" or re.fullmatch(r"-[a-zA-Z]*a[a-zA-Z]*", arg) for arg in args if arg != "--")
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def violation_in(command, cwd=None):
|
|
137
|
+
"""(rule, allowed form) for the first forbidden git call, or None."""
|
|
138
|
+
for sub, args, directory in git_calls_in(command):
|
|
139
|
+
if sub == "add":
|
|
140
|
+
if any(arg in ADD_ALL for arg in args):
|
|
141
|
+
return (
|
|
142
|
+
"`git add -A`, `--all` and `.` stage other sessions' work",
|
|
143
|
+
"stage named paths: `git add <path> ...`, or skip staging and use `git commit -m \"...\" -- <paths>`",
|
|
144
|
+
)
|
|
145
|
+
if sub == "stash" and stash_subcommand_of(args) not in STASH_READS:
|
|
146
|
+
return (
|
|
147
|
+
f"`git stash {stash_subcommand_of(args)}` hides or rewrites other sessions' uncommitted work",
|
|
148
|
+
"leave the working tree alone; commit your own paths with `git commit -m \"...\" -- <paths>`",
|
|
149
|
+
)
|
|
150
|
+
if sub == "commit":
|
|
151
|
+
if "--amend" in args:
|
|
152
|
+
return (
|
|
153
|
+
"`git commit --amend` rewrites a commit another session may have built on",
|
|
154
|
+
"make a new commit: `git commit -m \"...\" -- <paths>`",
|
|
155
|
+
)
|
|
156
|
+
if "--" not in args and not (
|
|
157
|
+
not stages_everything(args)
|
|
158
|
+
and concludes_merge(os.path.join(cwd or os.getcwd(), directory) if directory else cwd or os.getcwd())
|
|
159
|
+
):
|
|
160
|
+
return (
|
|
161
|
+
"`git commit` without a pathspec commits everything staged, including other sessions' work",
|
|
162
|
+
"name the paths: `git commit -m \"...\" -- <paths>`",
|
|
163
|
+
)
|
|
164
|
+
return None
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def reason_for(rule, allowed):
|
|
168
|
+
return f"Denied: {rule}. Allowed form: {allowed}."
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def main():
|
|
172
|
+
if agent_name(sys.argv[1:]) != "claude":
|
|
173
|
+
return
|
|
174
|
+
|
|
175
|
+
data = json.load(sys.stdin)
|
|
176
|
+
|
|
177
|
+
if data.get("tool_name") != "Bash":
|
|
178
|
+
return
|
|
179
|
+
|
|
180
|
+
tool_input = data.get("tool_input")
|
|
181
|
+
command = tool_input.get("command") if isinstance(tool_input, dict) else None
|
|
182
|
+
|
|
183
|
+
if not isinstance(command, str):
|
|
184
|
+
return
|
|
185
|
+
|
|
186
|
+
if disabled_locally(load_local_config(repo_root(data))):
|
|
187
|
+
return
|
|
188
|
+
|
|
189
|
+
cwd = data.get("cwd")
|
|
190
|
+
found = violation_in(command, cwd if isinstance(cwd, str) and cwd else None)
|
|
191
|
+
|
|
192
|
+
if not found:
|
|
193
|
+
return
|
|
194
|
+
|
|
195
|
+
print(
|
|
196
|
+
json.dumps(
|
|
197
|
+
{
|
|
198
|
+
"hookSpecificOutput": {
|
|
199
|
+
"hookEventName": "PreToolUse",
|
|
200
|
+
"permissionDecision": "deny",
|
|
201
|
+
"permissionDecisionReason": reason_for(*found),
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
if __name__ == "__main__":
|
|
209
|
+
try:
|
|
210
|
+
main()
|
|
211
|
+
except Exception:
|
|
212
|
+
pass
|
|
213
|
+
sys.exit(0)
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Stop hook: a coordinator that asks the human starts the next independent slice first.
|
|
3
|
+
|
|
4
|
+
When a builder or coordinator session ends a turn with a question to the human (a line
|
|
5
|
+
ending in "?") or a `! <command>` for the human to run, while fewer subagents and background
|
|
6
|
+
commands run than the slot limit and free work is listed, the stop is blocked once. The
|
|
7
|
+
reason names the free work, so the turn goes on with a slice that does not need the answer.
|
|
8
|
+
|
|
9
|
+
Free work comes from two places, both read at runtime:
|
|
10
|
+
- the queues of the `builder-idle-check` hook (`builderIdle.queues` in the local config,
|
|
11
|
+
default `plans/QUEUE.md`): open rows without a wait pattern;
|
|
12
|
+
- the `## Next steps` list of the handoff the session resumed (`/handoff resume <name>` reads
|
|
13
|
+
`.claude/handoffs/<name>.md`).
|
|
14
|
+
With neither, the stop passes.
|
|
15
|
+
|
|
16
|
+
Session roles, the slot limit, wait patterns and running work are read exactly as the
|
|
17
|
+
`builder-idle-check` hook reads them; this script imports that file from its own directory.
|
|
18
|
+
Per-machine: {"disableHooks": ["human-wait-check"]} in ethlete-agents.config.local.json.
|
|
19
|
+
|
|
20
|
+
Fires at most once per stop chain: a stop that a Stop hook already continued
|
|
21
|
+
(`stop_hook_active`) passes. Fail-safe: any error exits 0 with no output.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
import importlib.util
|
|
25
|
+
import json
|
|
26
|
+
import os
|
|
27
|
+
import re
|
|
28
|
+
import sys
|
|
29
|
+
|
|
30
|
+
HOOK_NAME = "human-wait-check"
|
|
31
|
+
HANDOFF_DIR = os.path.join(".claude", "handoffs")
|
|
32
|
+
RESUME_ARGS = re.compile(r"<command-args>\s*resume\s+([\w.@-]+)")
|
|
33
|
+
NEXT_STEPS = re.compile(r"^#{2,3}\s+(?:next steps|nächste schritte)\b", re.I)
|
|
34
|
+
LIST_ITEM = re.compile(r"^(?:\d+[.)]|[-*])\s+(.*)$")
|
|
35
|
+
FENCE = re.compile(r"^\s*(?:```|~~~)")
|
|
36
|
+
HUMAN_COMMAND_LINE = re.compile(r"^\s*!\s+\S")
|
|
37
|
+
HUMAN_COMMAND_INLINE = re.compile(r"`!\s+[^`]+`")
|
|
38
|
+
TRAILING_MARKUP = " \t*_~`)\"'»“”]"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def load_idle_check():
|
|
42
|
+
sys.dont_write_bytecode = True
|
|
43
|
+
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "builder-idle-check.py")
|
|
44
|
+
spec = importlib.util.spec_from_file_location("ethlete_builder_idle_check", path)
|
|
45
|
+
module = importlib.util.module_from_spec(spec)
|
|
46
|
+
spec.loader.exec_module(module)
|
|
47
|
+
return module
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def last_assistant_text(path):
|
|
51
|
+
text = None
|
|
52
|
+
resumed = None
|
|
53
|
+
with open(path, encoding="utf-8") as f:
|
|
54
|
+
for raw in f:
|
|
55
|
+
try:
|
|
56
|
+
line = json.loads(raw)
|
|
57
|
+
except ValueError:
|
|
58
|
+
continue
|
|
59
|
+
if not isinstance(line, dict) or line.get("isSidechain"):
|
|
60
|
+
continue
|
|
61
|
+
content = (line.get("message") or {}).get("content")
|
|
62
|
+
if line.get("type") == "user":
|
|
63
|
+
for chunk in content if isinstance(content, list) else [content]:
|
|
64
|
+
value = chunk.get("text") if isinstance(chunk, dict) else chunk
|
|
65
|
+
match = RESUME_ARGS.search(value) if isinstance(value, str) else None
|
|
66
|
+
if match:
|
|
67
|
+
resumed = match.group(1)
|
|
68
|
+
elif line.get("type") == "assistant" and isinstance(content, list):
|
|
69
|
+
texts = [item.get("text", "") for item in content if isinstance(item, dict) and item.get("type") == "text"]
|
|
70
|
+
if any(part.strip() for part in texts):
|
|
71
|
+
text = "\n".join(texts)
|
|
72
|
+
elif any(isinstance(item, dict) and item.get("type") == "tool_use" for item in content):
|
|
73
|
+
text = None
|
|
74
|
+
return text, resumed
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def asks_human(text):
|
|
78
|
+
in_fence = False
|
|
79
|
+
for line in text.splitlines():
|
|
80
|
+
if FENCE.match(line):
|
|
81
|
+
in_fence = not in_fence
|
|
82
|
+
continue
|
|
83
|
+
if HUMAN_COMMAND_LINE.match(line):
|
|
84
|
+
return True
|
|
85
|
+
if in_fence:
|
|
86
|
+
continue
|
|
87
|
+
if HUMAN_COMMAND_INLINE.search(line) or line.rstrip(TRAILING_MARKUP).endswith("?"):
|
|
88
|
+
return True
|
|
89
|
+
return False
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def next_steps(root, resumed):
|
|
93
|
+
if not resumed:
|
|
94
|
+
return []
|
|
95
|
+
try:
|
|
96
|
+
with open(os.path.join(root, HANDOFF_DIR, f"{resumed}.md"), encoding="utf-8") as f:
|
|
97
|
+
lines = f.read().splitlines()
|
|
98
|
+
except OSError:
|
|
99
|
+
return []
|
|
100
|
+
steps = []
|
|
101
|
+
inside = False
|
|
102
|
+
for line in lines:
|
|
103
|
+
if line.startswith("#"):
|
|
104
|
+
inside = bool(NEXT_STEPS.match(line))
|
|
105
|
+
continue
|
|
106
|
+
match = LIST_ITEM.match(line) if inside else None
|
|
107
|
+
if match:
|
|
108
|
+
steps.append(match.group(1).strip()[:80])
|
|
109
|
+
return steps
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def reason_for(rows, steps, working, slots, resumed):
|
|
113
|
+
work = []
|
|
114
|
+
if rows:
|
|
115
|
+
work.append(f"open queue rows: {', '.join(rows)}")
|
|
116
|
+
if steps:
|
|
117
|
+
listed = "; ".join(f"{index}. {step}" for index, step in enumerate(steps, 1))
|
|
118
|
+
work.append(f"Next steps in {HANDOFF_DIR}/{resumed}.md: {listed}")
|
|
119
|
+
return (
|
|
120
|
+
f"[{HOOK_NAME} hook] This turn ends with a question or a `!` command for the human while {working} of {slots} "
|
|
121
|
+
f"slots are in use and free work is listed - {' | '.join(work)}. "
|
|
122
|
+
"Do not wait idle on the human: start the next slice that does not need the answer now (or a subagent on it), "
|
|
123
|
+
"then end the turn with the question again. If every listed item needs the answer, say which item waits on what. "
|
|
124
|
+
"If the human has allowed this action before, propose a permission rule for it in the settings (only the human "
|
|
125
|
+
"edits settings) instead of asking again. This hook fires once per stop."
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def main():
|
|
130
|
+
try:
|
|
131
|
+
data = json.load(sys.stdin)
|
|
132
|
+
if not isinstance(data, dict) or data.get("stop_hook_active"):
|
|
133
|
+
return
|
|
134
|
+
transcript_path = data.get("transcript_path")
|
|
135
|
+
if not isinstance(transcript_path, str):
|
|
136
|
+
return
|
|
137
|
+
idle = load_idle_check()
|
|
138
|
+
root = idle.repo_root(data)
|
|
139
|
+
config = idle.read_local_config(root)
|
|
140
|
+
disabled = config.get("disableHooks")
|
|
141
|
+
if disabled is True or (isinstance(disabled, list) and HOOK_NAME in disabled):
|
|
142
|
+
return
|
|
143
|
+
text, resumed = last_assistant_text(transcript_path)
|
|
144
|
+
if not text or not asks_human(text):
|
|
145
|
+
return
|
|
146
|
+
settings = idle.builder_idle_config(config)
|
|
147
|
+
roles = idle.string_list(settings.get("roles"), idle.DEFAULT_ROLES)
|
|
148
|
+
state = idle.read_transcript(transcript_path, idle.role_launch(roles))
|
|
149
|
+
if not state["builder"]:
|
|
150
|
+
return
|
|
151
|
+
idle.read_earlier_agents(state, transcript_path)
|
|
152
|
+
working = sum(1 for task in idle.running_tasks(state) if not task["watcher"]) + len(idle.codex_runs(root))
|
|
153
|
+
slots = idle.slot_limit(config)
|
|
154
|
+
if working >= slots:
|
|
155
|
+
return
|
|
156
|
+
patterns = idle.string_list(settings.get("waitPatterns"), idle.DEFAULT_WAIT_PATTERNS)
|
|
157
|
+
rows = idle.open_builder_rows(root, idle.queue_sources(settings), patterns)
|
|
158
|
+
steps = next_steps(root, resumed)
|
|
159
|
+
if not rows and not steps:
|
|
160
|
+
return
|
|
161
|
+
print(json.dumps({"decision": "block", "reason": reason_for(rows, steps, working, slots, resumed)}))
|
|
162
|
+
except Exception:
|
|
163
|
+
return
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
if __name__ == "__main__":
|
|
167
|
+
main()
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""PreToolUse hook: run a subagent on sonnet unless its call names a model.
|
|
3
|
+
|
|
4
|
+
A `Task` call that passes no `model` runs the subagent on the parent session's
|
|
5
|
+
model. A session led by an expensive model therefore spends that model on every
|
|
6
|
+
grep and every file read it delegates, which burns a usage limit in minutes for
|
|
7
|
+
work a small model does just as well.
|
|
8
|
+
|
|
9
|
+
So this hook rewrites or gates the tool call:
|
|
10
|
+
|
|
11
|
+
* No `model` at all - allowed with `model: sonnet` filled in, and a short note
|
|
12
|
+
that names the models to pick explicitly instead.
|
|
13
|
+
* `model: fable` - the user is asked. Fable is the right pick for planning,
|
|
14
|
+
design, cross-cutting review and leading other subagents, and the wrong pick
|
|
15
|
+
for the twentieth mechanical lookup; only the user knows which this is.
|
|
16
|
+
* Any other model - allowed silently.
|
|
17
|
+
|
|
18
|
+
Two cases are left alone, because the tool's `model` would change nothing:
|
|
19
|
+
|
|
20
|
+
* `subagent_type: fork`, which always inherits the parent model.
|
|
21
|
+
* An agent type whose own definition under `.claude/agents/` sets a model.
|
|
22
|
+
|
|
23
|
+
Every subagent start, whatever the decision, appends one JSON line to
|
|
24
|
+
`<git common dir>/ethlete/subagent-starts.jsonl`: time, session, HEAD, branch,
|
|
25
|
+
the model it will run on, effort, agent type, description, the prompt's head and
|
|
26
|
+
the file paths the prompt names. It lives inside `.git`, so it is never committed,
|
|
27
|
+
and HEAD plus the paths join it with later commits.
|
|
28
|
+
|
|
29
|
+
Can be disabled per machine via a gitignored ethlete-agents.config.local.json at
|
|
30
|
+
the repo root: {"disableHooks": true} or {"disableHooks": ["subagent-model-policy"]}.
|
|
31
|
+
|
|
32
|
+
Fail-safe: any error exits 0 with no output - the hook must never block work
|
|
33
|
+
because it could not read its own input.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
import json
|
|
37
|
+
import os
|
|
38
|
+
import re
|
|
39
|
+
import subprocess
|
|
40
|
+
import sys
|
|
41
|
+
from datetime import datetime, timezone
|
|
42
|
+
|
|
43
|
+
HOOK_NAME = "subagent-model-policy"
|
|
44
|
+
LOCAL_CONFIG_FILE = "ethlete-agents.config.local.json"
|
|
45
|
+
|
|
46
|
+
# The tool that spawns a subagent, under both names it has carried.
|
|
47
|
+
SUBAGENT_TOOLS = ("Task", "Agent")
|
|
48
|
+
|
|
49
|
+
DEFAULT_MODEL = "sonnet"
|
|
50
|
+
|
|
51
|
+
LOG_FILE = os.path.join("ethlete", "subagent-starts.jsonl")
|
|
52
|
+
PROMPT_HEAD_CHARS = 300
|
|
53
|
+
MAX_LOGGED_FILES = 50
|
|
54
|
+
FILE_PATH = re.compile(r"(?<![\w/.-])(?:\.?[\w@-][\w@.-]*/)+[\w@.-]*\.[A-Za-z0-9]{1,8}(?![\w/])")
|
|
55
|
+
|
|
56
|
+
POLICY = """This call passed no `model`, so the subagent runs on sonnet, the default. Name a model on the next \
|
|
57
|
+
call when the task fits another one:
|
|
58
|
+
|
|
59
|
+
- `haiku` - lookups and small, fully specified jobs: grep, find, read and summarize files or a CI log, run a command and report, a mechanical edit in named files.
|
|
60
|
+
- `sonnet` - scoped work with a clear target: a fix in a named file, a spec, a docs page, a lint cleanup, \
|
|
61
|
+
research that needs reasoning. Sonnet 5.5 is close to opus here and costs less.
|
|
62
|
+
- `opus` - hard work: a bug with no known cause, a change across many files, a review of a diff, and any task \
|
|
63
|
+
sonnet did not finish.
|
|
64
|
+
- `fable` - judgment-heavy work: planning, design, cross-cutting review, leading other subagents. The most \
|
|
65
|
+
expensive of the four, so choosing it asks the user first.
|
|
66
|
+
|
|
67
|
+
Effort follows the prompt, not a parameter: scope the prompt to one question, name what "done" is, and say \
|
|
68
|
+
"keep it brief" for a lookup. A subagent has the session's context budget on its own transcript and hands back \
|
|
69
|
+
at the critical tier, so size the prompt to one slice that fits; more work means a fresh subagent per slice. An agent type defined under `.claude/agents/` carries its own model and reasoning \
|
|
70
|
+
effort, so a call that names one needs no `model` of its own."""
|
|
71
|
+
|
|
72
|
+
FABLE_REASON = """This subagent would run on fable, the most expensive model. Approve it where the task is \
|
|
73
|
+
judgment-heavy - planning, design, cross-cutting review, or leading other subagents. Deny it for implementation \
|
|
74
|
+
(`model: "sonnet"` or `"opus"`) or for a lookup or a small, fully specified job (`model: "haiku"`), then repeat the call with that model."""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def agent_name(argv):
|
|
78
|
+
"""The --agent value, defaulting to claude — older registrations pass no flag."""
|
|
79
|
+
for index, arg in enumerate(argv):
|
|
80
|
+
if arg == "--agent" and index + 1 < len(argv):
|
|
81
|
+
return argv[index + 1]
|
|
82
|
+
if arg.startswith("--agent="):
|
|
83
|
+
return arg.split("=", 1)[1]
|
|
84
|
+
return "claude"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def repo_root(data):
|
|
88
|
+
"""Repo root: the env var the agent sets, else the script's own location, else the cwd.
|
|
89
|
+
|
|
90
|
+
The script always lives at <root>/.<agent>/hooks/ethlete/subagent-model-policy.py, so
|
|
91
|
+
walking four levels up works for any agent that has no project-dir variable of its own.
|
|
92
|
+
"""
|
|
93
|
+
for variable in ("CLAUDE_PROJECT_DIR", "CODEX_PROJECT_DIR"):
|
|
94
|
+
value = os.environ.get(variable)
|
|
95
|
+
if value:
|
|
96
|
+
return value
|
|
97
|
+
here = os.path.abspath(__file__)
|
|
98
|
+
derived = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(here))))
|
|
99
|
+
if os.path.isfile(os.path.join(derived, LOCAL_CONFIG_FILE)):
|
|
100
|
+
return derived
|
|
101
|
+
cwd = data.get("cwd")
|
|
102
|
+
return cwd if isinstance(cwd, str) and cwd else derived
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def load_local_config(root):
|
|
106
|
+
"""Parsed ethlete-agents.config.local.json at the repo root, or {} if missing/unreadable."""
|
|
107
|
+
if not root:
|
|
108
|
+
return {}
|
|
109
|
+
try:
|
|
110
|
+
with open(os.path.join(root, LOCAL_CONFIG_FILE), encoding="utf-8") as f:
|
|
111
|
+
config = json.load(f)
|
|
112
|
+
except (OSError, ValueError, AttributeError):
|
|
113
|
+
return {}
|
|
114
|
+
return config if isinstance(config, dict) else {}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def disabled_locally(config):
|
|
118
|
+
"""True when the local config disables this hook (or all hooks) on this machine."""
|
|
119
|
+
disabled = config.get("disableHooks")
|
|
120
|
+
return disabled is True or (isinstance(disabled, list) and HOOK_NAME in disabled)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def definition_sets_model(root, subagent_type):
|
|
124
|
+
"""True when a project or user agent definition of that name declares its own model."""
|
|
125
|
+
if not subagent_type:
|
|
126
|
+
return False
|
|
127
|
+
file_name = f"{subagent_type.split(':')[-1]}.md".lower()
|
|
128
|
+
candidates = []
|
|
129
|
+
for directory in (
|
|
130
|
+
os.path.join(root or ".", ".claude", "agents"),
|
|
131
|
+
os.path.join(os.path.expanduser("~"), ".claude", "agents"),
|
|
132
|
+
):
|
|
133
|
+
try:
|
|
134
|
+
entries = os.listdir(directory)
|
|
135
|
+
except OSError:
|
|
136
|
+
continue
|
|
137
|
+
candidates += [os.path.join(directory, entry) for entry in entries if entry.lower() == file_name]
|
|
138
|
+
for path in candidates:
|
|
139
|
+
try:
|
|
140
|
+
with open(path, encoding="utf-8") as f:
|
|
141
|
+
head = f.read(4096)
|
|
142
|
+
except OSError:
|
|
143
|
+
continue
|
|
144
|
+
for line in head.split("\n"):
|
|
145
|
+
key, separator, value = line.partition(":")
|
|
146
|
+
if separator and key.strip() == "model" and value.strip():
|
|
147
|
+
return True
|
|
148
|
+
return False
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def decision_for(tool_input, root):
|
|
152
|
+
"""The (decision, reason, updated input or None) this call needs, or None when it may run untouched."""
|
|
153
|
+
subagent_type = str(tool_input.get("subagent_type") or "").strip().lower()
|
|
154
|
+
model = str(tool_input.get("model") or "").strip().lower()
|
|
155
|
+
|
|
156
|
+
if "fable" in model:
|
|
157
|
+
return "ask", FABLE_REASON, None
|
|
158
|
+
if model:
|
|
159
|
+
return None
|
|
160
|
+
if subagent_type == "fork" or definition_sets_model(root, subagent_type):
|
|
161
|
+
return None
|
|
162
|
+
return "allow", POLICY, {**tool_input, "model": DEFAULT_MODEL}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def git(root, *args):
|
|
166
|
+
result = subprocess.run(["git", "-C", root, *args], capture_output=True, text=True, timeout=3)
|
|
167
|
+
return result.stdout.strip() if result.returncode == 0 else ""
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def prompt_files(prompt):
|
|
171
|
+
files = []
|
|
172
|
+
for match in FILE_PATH.findall(prompt):
|
|
173
|
+
path = match.split(":")[0]
|
|
174
|
+
if path not in files:
|
|
175
|
+
files.append(path)
|
|
176
|
+
return files[:MAX_LOGGED_FILES]
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def run_model(tool_input, outcome):
|
|
180
|
+
"""The model the subagent will run on, or how it is chosen when the call does not name one."""
|
|
181
|
+
if outcome and outcome[2] is not None:
|
|
182
|
+
return outcome[2].get("model")
|
|
183
|
+
model = str(tool_input.get("model") or "").strip().lower()
|
|
184
|
+
if model:
|
|
185
|
+
return model
|
|
186
|
+
subagent_type = str(tool_input.get("subagent_type") or "").strip().lower()
|
|
187
|
+
return "inherit" if subagent_type == "fork" else "definition"
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def log_start(data, tool_input, root, outcome):
|
|
191
|
+
common_dir = git(root, "rev-parse", "--path-format=absolute", "--git-common-dir")
|
|
192
|
+
if not common_dir:
|
|
193
|
+
return
|
|
194
|
+
prompt = str(tool_input.get("prompt") or "")
|
|
195
|
+
entry = {
|
|
196
|
+
"time": datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
|
197
|
+
"session": data.get("session_id"),
|
|
198
|
+
"toolUseId": data.get("tool_use_id"),
|
|
199
|
+
"head": git(root, "rev-parse", "HEAD"),
|
|
200
|
+
"branch": git(root, "rev-parse", "--abbrev-ref", "HEAD"),
|
|
201
|
+
"model": run_model(tool_input, outcome),
|
|
202
|
+
"decision": outcome[0] if outcome else "untouched",
|
|
203
|
+
"effort": tool_input.get("effort"),
|
|
204
|
+
"subagentType": tool_input.get("subagent_type"),
|
|
205
|
+
"description": tool_input.get("description"),
|
|
206
|
+
"prompt": prompt[:PROMPT_HEAD_CHARS],
|
|
207
|
+
"promptChars": len(prompt),
|
|
208
|
+
"files": prompt_files(prompt),
|
|
209
|
+
}
|
|
210
|
+
path = os.path.join(common_dir, LOG_FILE)
|
|
211
|
+
os.makedirs(os.path.dirname(path), exist_ok=True)
|
|
212
|
+
with open(path, "a", encoding="utf-8") as f:
|
|
213
|
+
f.write(json.dumps(entry) + "\n")
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def main():
|
|
217
|
+
if agent_name(sys.argv[1:]) != "claude":
|
|
218
|
+
return
|
|
219
|
+
|
|
220
|
+
data = json.load(sys.stdin)
|
|
221
|
+
|
|
222
|
+
if data.get("tool_name") not in SUBAGENT_TOOLS:
|
|
223
|
+
return
|
|
224
|
+
|
|
225
|
+
tool_input = data.get("tool_input")
|
|
226
|
+
|
|
227
|
+
if not isinstance(tool_input, dict):
|
|
228
|
+
return
|
|
229
|
+
|
|
230
|
+
root = repo_root(data)
|
|
231
|
+
|
|
232
|
+
if disabled_locally(load_local_config(root)):
|
|
233
|
+
return
|
|
234
|
+
|
|
235
|
+
outcome = decision_for(tool_input, root)
|
|
236
|
+
|
|
237
|
+
try:
|
|
238
|
+
log_start(data, tool_input, root, outcome)
|
|
239
|
+
except Exception:
|
|
240
|
+
pass
|
|
241
|
+
|
|
242
|
+
if not outcome:
|
|
243
|
+
return
|
|
244
|
+
|
|
245
|
+
decision, reason, updated_input = outcome
|
|
246
|
+
output = {
|
|
247
|
+
"hookEventName": "PreToolUse",
|
|
248
|
+
"permissionDecision": decision,
|
|
249
|
+
"permissionDecisionReason": reason,
|
|
250
|
+
}
|
|
251
|
+
if updated_input is not None:
|
|
252
|
+
output["updatedInput"] = updated_input
|
|
253
|
+
print(json.dumps({"hookSpecificOutput": output}))
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
if __name__ == "__main__":
|
|
257
|
+
try:
|
|
258
|
+
main()
|
|
259
|
+
except Exception:
|
|
260
|
+
pass
|
|
261
|
+
sys.exit(0)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ethlete",
|
|
3
|
+
"owner": { "name": "ethlete" },
|
|
4
|
+
"plugins": [
|
|
5
|
+
{
|
|
6
|
+
"name": "codex-runs",
|
|
7
|
+
"source": "./plugins/codex-runs",
|
|
8
|
+
"description": "Codex sessions in tmux with their state, duration, and recent output"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "e2e-progress",
|
|
12
|
+
"source": "./plugins/e2e-progress",
|
|
13
|
+
"description": "Live Playwright e2e progress from a run log, as a status line entry and a pane"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "status-line",
|
|
17
|
+
"source": "./plugins/status-line",
|
|
18
|
+
"description": "Always-visible band with the running task, its duration, the open queue, open questions and a CI blocked mark"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "usage-line",
|
|
22
|
+
"source": "./plugins/usage-line",
|
|
23
|
+
"description": "Status line entry with the 5 hour and weekly usage, the reset time of the 5 hour window and the Codex limit"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|