@ethlete/agent-rules 0.1.0-next.4 → 0.1.0-next.40

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.
Files changed (229) hide show
  1. package/AGENTS.md +28 -0
  2. package/CHANGELOG.md +620 -0
  3. package/CLAUDE.md +1 -0
  4. package/README.md +406 -29
  5. package/THIRD-PARTY-LICENSES.md +35 -0
  6. package/content/defaults.json +1 -1
  7. package/content/git-hooks/post-checkout.sh +10 -0
  8. package/content/git-hooks/pre-push.sh +5 -0
  9. package/content/hooks/away-mode.py +287 -0
  10. package/content/hooks/background-design-commands.py +215 -0
  11. package/content/hooks/builder-chat-words.py +269 -0
  12. package/content/hooks/context-warning.py +836 -142
  13. package/content/hooks/git-safety.py +213 -0
  14. package/content/hooks/subagent-model-policy.py +261 -0
  15. package/content/mods/.claude-plugin/marketplace.json +16 -0
  16. package/content/mods/plugins/e2e-progress/.claude-plugin/plugin.json +6 -0
  17. package/content/mods/plugins/e2e-progress/hooks/hooks.json +1 -0
  18. package/content/mods/plugins/e2e-progress/hooks/register.tsx +442 -0
  19. package/content/mods/plugins/e2e-progress/tsconfig.json +3 -0
  20. package/content/mods/plugins/e2e-progress/types/index.d.ts +23 -0
  21. package/content/mods/plugins/status-line/.claude-plugin/plugin.json +6 -0
  22. package/content/mods/plugins/status-line/hooks/hooks.json +1 -0
  23. package/content/mods/plugins/status-line/hooks/line.ts +73 -0
  24. package/content/mods/plugins/status-line/hooks/register.tsx +141 -0
  25. package/content/mods/plugins/status-line/types/index.d.ts +5 -0
  26. package/content/output-styles/ste-clarity.md +131 -0
  27. package/content/rules/agent-sessions-wake-up.md +11 -0
  28. package/content/rules/app-styling.md +66 -0
  29. package/content/rules/comments.md +4 -1
  30. package/content/rules/lint-and-format.md +7 -5
  31. package/content/rules/nx-layout.md +53 -0
  32. package/content/rules/reactive-state.md +1 -1
  33. package/content/rules/styling.md +19 -10
  34. package/content/rules/subagent-models.md +42 -0
  35. package/content/skills/agent-sessions/SKILL.md +94 -0
  36. package/content/skills/agent-sessions/agent-sessions.mjs +1079 -0
  37. package/content/skills/angular-patterns/SKILL.md +31 -7
  38. package/content/skills/api-source/SKILL.md +156 -0
  39. package/content/skills/app-testing/SKILL.md +141 -0
  40. package/content/skills/codex-subagent/SKILL.md +90 -0
  41. package/content/skills/codex-subagent/codex-agent.mjs +229 -0
  42. package/content/skills/design-exploration/SKILL.md +190 -0
  43. package/content/skills/design-exploration/check-story.mjs +139 -0
  44. package/content/skills/design-exploration/reference-check-and-notes.md +92 -0
  45. package/content/skills/design-exploration/reference-flows-and-wireframes.md +78 -0
  46. package/content/skills/design-exploration/reference-inbox-and-mcp.md +54 -0
  47. package/content/skills/design-exploration/reference-order-and-design-system.md +124 -0
  48. package/content/skills/design-exploration/reference-products-and-sketches.md +211 -0
  49. package/content/skills/design-exploration/reference-shots.md +25 -0
  50. package/content/skills/design-exploration/shoot-template.mjs +61 -0
  51. package/content/skills/domain-modeling/ADR-FORMAT.md +47 -0
  52. package/content/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
  53. package/content/skills/domain-modeling/SKILL.md +80 -0
  54. package/content/skills/e2e-triage/SKILL.md +80 -0
  55. package/content/skills/figma-export/SKILL.md +191 -0
  56. package/content/skills/figma-export/dump-figma-layers.py +83 -0
  57. package/content/skills/figma-export/dump-figma-svg.py +235 -0
  58. package/content/skills/figma-export/measure-template.mjs +87 -0
  59. package/content/skills/git-commit/SKILL.md +21 -7
  60. package/content/skills/git-flow/SKILL.md +87 -0
  61. package/content/skills/grill-with-docs/SKILL.md +13 -0
  62. package/content/skills/grilling/SKILL.md +52 -0
  63. package/content/skills/handoff/SKILL.md +29 -69
  64. package/content/skills/handoff/save.md +187 -0
  65. package/content/skills/query/SKILL.md +165 -64
  66. package/content/skills/report/SKILL.md +26 -0
  67. package/content/skills/rxjs-signals/SKILL.md +33 -4
  68. package/content/skills/sdk-docs/SKILL.md +50 -14
  69. package/content/skills/sdk-local-build/SKILL.md +26 -8
  70. package/content/skills/sdk-local-build/sdk-local-baseline.mjs +64 -0
  71. package/content/skills/sdk-source/SKILL.md +37 -34
  72. package/content/skills/sdk-update/SKILL.md +103 -0
  73. package/content/skills/story-styling/SKILL.md +10 -8
  74. package/content/skills/styleguide/SKILL.md +13 -8
  75. package/content/skills/styleguide/assets.md +54 -0
  76. package/content/skills/styleguide/changesets.md +17 -0
  77. package/content/skills/styleguide/file-structure.md +73 -0
  78. package/content/skills/styleguide/lint-rule-lookup.md +52 -0
  79. package/content/skills/styleguide/storybook-structure.md +25 -0
  80. package/content/skills/theming/SKILL.md +56 -28
  81. package/content/skills/timetrack/SKILL.md +324 -0
  82. package/content/skills/verify-in-app/SKILL.md +107 -0
  83. package/content/skills/verify-in-storybook/SKILL.md +1 -1
  84. package/migrations/list-state-query-form.md +20 -0
  85. package/migrations/nx-layout.md +29 -0
  86. package/migrations/sdk-components-over-hand-built-ui.md +27 -0
  87. package/migrations/search-query-field.md +52 -0
  88. package/migrations.json +39 -0
  89. package/package.json +19 -3
  90. package/src/index.js +99 -32
  91. package/src/index.js.map +1 -1
  92. package/src/lib/cli-args.d.ts +9 -0
  93. package/src/lib/cli-args.js +48 -0
  94. package/src/lib/cli-args.js.map +1 -0
  95. package/src/lib/commitlint.d.ts +10 -0
  96. package/src/lib/commitlint.js +51 -0
  97. package/src/lib/commitlint.js.map +1 -0
  98. package/src/lib/config.d.ts +51 -6
  99. package/src/lib/config.js +127 -10
  100. package/src/lib/config.js.map +1 -1
  101. package/src/lib/filter.d.ts +2 -0
  102. package/src/lib/filter.js +4 -4
  103. package/src/lib/filter.js.map +1 -1
  104. package/src/lib/frontmatter.d.ts +2 -0
  105. package/src/lib/frontmatter.js +33 -5
  106. package/src/lib/frontmatter.js.map +1 -1
  107. package/src/lib/git-flow/build.d.ts +35 -0
  108. package/src/lib/git-flow/build.js +24 -0
  109. package/src/lib/git-flow/build.js.map +1 -0
  110. package/src/lib/git-flow/config.d.ts +59 -0
  111. package/src/lib/git-flow/config.js +50 -0
  112. package/src/lib/git-flow/config.js.map +1 -0
  113. package/src/lib/git-flow/index.d.ts +6 -0
  114. package/src/lib/git-flow/index.js +23 -0
  115. package/src/lib/git-flow/index.js.map +1 -0
  116. package/src/lib/git-flow/parse.d.ts +49 -0
  117. package/src/lib/git-flow/parse.js +300 -0
  118. package/src/lib/git-flow/parse.js.map +1 -0
  119. package/src/lib/git-flow/rename.d.ts +24 -0
  120. package/src/lib/git-flow/rename.js +70 -0
  121. package/src/lib/git-flow/rename.js.map +1 -0
  122. package/src/lib/git-flow/start.d.ts +49 -0
  123. package/src/lib/git-flow/start.js +57 -0
  124. package/src/lib/git-flow/start.js.map +1 -0
  125. package/src/lib/git-flow/validate.d.ts +34 -0
  126. package/src/lib/git-flow/validate.js +72 -0
  127. package/src/lib/git-flow/validate.js.map +1 -0
  128. package/src/lib/git-flow-command.d.ts +4 -0
  129. package/src/lib/git-flow-command.js +165 -0
  130. package/src/lib/git-flow-command.js.map +1 -0
  131. package/src/lib/git-flow-repair.d.ts +17 -0
  132. package/src/lib/git-flow-repair.js +165 -0
  133. package/src/lib/git-flow-repair.js.map +1 -0
  134. package/src/lib/git-flow-start.d.ts +20 -0
  135. package/src/lib/git-flow-start.js +140 -0
  136. package/src/lib/git-flow-start.js.map +1 -0
  137. package/src/lib/git-test-env.fixtures.d.ts +11 -0
  138. package/src/lib/git-test-env.fixtures.js +31 -0
  139. package/src/lib/git-test-env.fixtures.js.map +1 -0
  140. package/src/lib/git.d.ts +64 -0
  141. package/src/lib/git.js +131 -0
  142. package/src/lib/git.js.map +1 -0
  143. package/src/lib/gitlab.d.ts +35 -0
  144. package/src/lib/gitlab.js +116 -0
  145. package/src/lib/gitlab.js.map +1 -0
  146. package/src/lib/index.d.ts +2 -0
  147. package/src/lib/index.js +26 -11
  148. package/src/lib/index.js.map +1 -1
  149. package/src/lib/migrate.js +8 -2
  150. package/src/lib/migrate.js.map +1 -1
  151. package/src/lib/output-style-command.d.ts +3 -0
  152. package/src/lib/output-style-command.js +69 -0
  153. package/src/lib/output-style-command.js.map +1 -0
  154. package/src/lib/output-style.d.ts +38 -0
  155. package/src/lib/output-style.js +134 -0
  156. package/src/lib/output-style.js.map +1 -0
  157. package/src/lib/owned-paths.js +27 -3
  158. package/src/lib/owned-paths.js.map +1 -1
  159. package/src/lib/package-runner.d.ts +4 -0
  160. package/src/lib/package-runner.js +86 -0
  161. package/src/lib/package-runner.js.map +1 -0
  162. package/src/lib/peer-path.d.ts +12 -0
  163. package/src/lib/peer-path.js +39 -0
  164. package/src/lib/peer-path.js.map +1 -0
  165. package/src/lib/plain-text.d.ts +9 -0
  166. package/src/lib/plain-text.js +22 -0
  167. package/src/lib/plain-text.js.map +1 -0
  168. package/src/lib/plan.d.ts +6 -6
  169. package/src/lib/plan.js +168 -40
  170. package/src/lib/plan.js.map +1 -1
  171. package/src/lib/prettier.d.ts +21 -0
  172. package/src/lib/prettier.js +51 -0
  173. package/src/lib/prettier.js.map +1 -0
  174. package/src/lib/prompt.d.ts +8 -0
  175. package/src/lib/prompt.js +35 -0
  176. package/src/lib/prompt.js.map +1 -0
  177. package/src/lib/render.d.ts +26 -2
  178. package/src/lib/render.js +45 -10
  179. package/src/lib/render.js.map +1 -1
  180. package/src/lib/report-command.d.ts +33 -0
  181. package/src/lib/report-command.js +312 -0
  182. package/src/lib/report-command.js.map +1 -0
  183. package/src/lib/sessions-command.d.ts +4 -0
  184. package/src/lib/sessions-command.js +16 -0
  185. package/src/lib/sessions-command.js.map +1 -0
  186. package/src/lib/sync.d.ts +1 -2
  187. package/src/lib/sync.js +37 -17
  188. package/src/lib/sync.js.map +1 -1
  189. package/src/lib/targets/agents-skills.js +1 -1
  190. package/src/lib/targets/agents-skills.js.map +1 -1
  191. package/src/lib/targets/claude-hooks.d.ts +3 -23
  192. package/src/lib/targets/claude-hooks.js +22 -86
  193. package/src/lib/targets/claude-hooks.js.map +1 -1
  194. package/src/lib/targets/claude-mods.d.ts +20 -0
  195. package/src/lib/targets/claude-mods.js +47 -0
  196. package/src/lib/targets/claude-mods.js.map +1 -0
  197. package/src/lib/targets/claude.js +2 -3
  198. package/src/lib/targets/claude.js.map +1 -1
  199. package/src/lib/targets/codex-hooks.d.ts +12 -0
  200. package/src/lib/targets/codex-hooks.js +35 -0
  201. package/src/lib/targets/codex-hooks.js.map +1 -0
  202. package/src/lib/targets/codex.js +4 -4
  203. package/src/lib/targets/codex.js.map +1 -1
  204. package/src/lib/targets/copilot.js +4 -4
  205. package/src/lib/targets/copilot.js.map +1 -1
  206. package/src/lib/targets/cursor.js +3 -3
  207. package/src/lib/targets/cursor.js.map +1 -1
  208. package/src/lib/targets/git-hooks.d.ts +25 -0
  209. package/src/lib/targets/git-hooks.js +71 -0
  210. package/src/lib/targets/git-hooks.js.map +1 -0
  211. package/src/lib/targets/hooks-shared.d.ts +60 -0
  212. package/src/lib/targets/hooks-shared.js +174 -0
  213. package/src/lib/targets/hooks-shared.js.map +1 -0
  214. package/src/lib/targets/mcp.d.ts +16 -0
  215. package/src/lib/targets/mcp.js +72 -0
  216. package/src/lib/targets/mcp.js.map +1 -0
  217. package/src/lib/targets/shared.d.ts +1 -9
  218. package/src/lib/targets/shared.js +4 -8
  219. package/src/lib/targets/shared.js.map +1 -1
  220. package/src/lib/timetrack-command.d.ts +11 -0
  221. package/src/lib/timetrack-command.js +1262 -0
  222. package/src/lib/timetrack-command.js.map +1 -0
  223. package/src/lib/timetrack-snapshot.d.ts +66 -0
  224. package/src/lib/timetrack-snapshot.js +146 -0
  225. package/src/lib/timetrack-snapshot.js.map +1 -0
  226. package/src/lib/timetrack.d.ts +607 -0
  227. package/src/lib/timetrack.js +285 -0
  228. package/src/lib/timetrack.js.map +1 -0
  229. package/content/skills/styleguide/STYLEGUIDE.md +0 -520
@@ -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,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,16 @@
1
+ {
2
+ "name": "ethlete",
3
+ "owner": { "name": "ethlete" },
4
+ "plugins": [
5
+ {
6
+ "name": "e2e-progress",
7
+ "source": "./plugins/e2e-progress",
8
+ "description": "Live Playwright e2e progress from a run log, as a status line entry and a pane"
9
+ },
10
+ {
11
+ "name": "status-line",
12
+ "source": "./plugins/status-line",
13
+ "description": "Always-visible band with the running task, its duration, the open queue, open questions and a CI blocked mark"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "e2e-progress",
3
+ "version": "0.1.0-next.40",
4
+ "description": "Live Playwright e2e progress from a run log, as a status line entry and a pane",
5
+ "types": "./types/index.d.ts"
6
+ }
@@ -0,0 +1 @@
1
+ { "modules": ["./register.tsx"] }