@ethlete/agent-rules 0.1.0-next.5 → 0.1.0-next.50

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 (242) hide show
  1. package/AGENTS.md +28 -0
  2. package/CHANGELOG.md +742 -0
  3. package/CLAUDE.md +1 -0
  4. package/README.md +430 -25
  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 +327 -0
  10. package/content/hooks/background-design-commands.py +228 -0
  11. package/content/hooks/builder-idle-check.py +388 -0
  12. package/content/hooks/context-warning.py +694 -134
  13. package/content/hooks/design-live-check.py +136 -0
  14. package/content/hooks/git-safety.py +213 -0
  15. package/content/hooks/human-wait-check.py +167 -0
  16. package/content/hooks/subagent-model-policy.py +261 -0
  17. package/content/mods/.claude-plugin/marketplace.json +26 -0
  18. package/content/mods/plugins/codex-runs/.claude-plugin/plugin.json +6 -0
  19. package/content/mods/plugins/codex-runs/hooks/hooks.json +1 -0
  20. package/content/mods/plugins/codex-runs/hooks/progress.ts +130 -0
  21. package/content/mods/plugins/codex-runs/hooks/register.tsx +103 -0
  22. package/content/mods/plugins/codex-runs/tsconfig.json +4 -0
  23. package/content/mods/plugins/codex-runs/types/index.d.ts +19 -0
  24. package/content/mods/plugins/e2e-progress/.claude-plugin/plugin.json +6 -0
  25. package/content/mods/plugins/e2e-progress/hooks/hooks.json +1 -0
  26. package/content/mods/plugins/e2e-progress/hooks/progress.ts +152 -0
  27. package/content/mods/plugins/e2e-progress/hooks/register.tsx +442 -0
  28. package/content/mods/plugins/e2e-progress/tsconfig.json +3 -0
  29. package/content/mods/plugins/e2e-progress/types/index.d.ts +26 -0
  30. package/content/mods/plugins/status-line/.claude-plugin/plugin.json +6 -0
  31. package/content/mods/plugins/status-line/hooks/hooks.json +1 -0
  32. package/content/mods/plugins/status-line/hooks/line.ts +74 -0
  33. package/content/mods/plugins/status-line/hooks/register.tsx +141 -0
  34. package/content/mods/plugins/status-line/types/index.d.ts +5 -0
  35. package/content/mods/plugins/usage-line/.claude-plugin/plugin.json +6 -0
  36. package/content/mods/plugins/usage-line/hooks/codex.ts +52 -0
  37. package/content/mods/plugins/usage-line/hooks/format.ts +24 -0
  38. package/content/mods/plugins/usage-line/hooks/hooks.json +1 -0
  39. package/content/mods/plugins/usage-line/hooks/register.tsx +67 -0
  40. package/content/mods/plugins/usage-line/tsconfig.json +4 -0
  41. package/content/mods/plugins/usage-line/types/index.d.ts +5 -0
  42. package/content/output-styles/ste-clarity.md +131 -0
  43. package/content/rules/agent-sessions-wake-up.md +11 -0
  44. package/content/rules/app-styling.md +66 -0
  45. package/content/rules/comments.md +4 -1
  46. package/content/rules/lint-and-format.md +7 -5
  47. package/content/rules/nx-layout.md +53 -0
  48. package/content/rules/reactive-state.md +1 -1
  49. package/content/rules/styling.md +19 -10
  50. package/content/rules/subagent-models.md +42 -0
  51. package/content/rules/waiting-on-the-human.md +17 -0
  52. package/content/skills/agent-sessions/SKILL.md +100 -0
  53. package/content/skills/agent-sessions/agent-sessions.mjs +1420 -0
  54. package/content/skills/angular-patterns/SKILL.md +31 -7
  55. package/content/skills/api-source/SKILL.md +156 -0
  56. package/content/skills/app-testing/SKILL.md +141 -0
  57. package/content/skills/codex-subagent/SKILL.md +96 -0
  58. package/content/skills/codex-subagent/codex-agent.mjs +229 -0
  59. package/content/skills/codex-subagent/codex-limit.mjs +106 -0
  60. package/content/skills/design-exploration/SKILL.md +203 -0
  61. package/content/skills/design-exploration/check-story.mjs +139 -0
  62. package/content/skills/design-exploration/reference-check-and-notes.md +100 -0
  63. package/content/skills/design-exploration/reference-flows.md +38 -0
  64. package/content/skills/design-exploration/reference-inbox-and-mcp.md +54 -0
  65. package/content/skills/design-exploration/reference-order-and-design-system.md +120 -0
  66. package/content/skills/design-exploration/reference-products-and-sketches.md +250 -0
  67. package/content/skills/design-exploration/reference-shots.md +25 -0
  68. package/content/skills/design-exploration/shoot-template.mjs +61 -0
  69. package/content/skills/domain-modeling/CONTEXT-FORMAT.md +60 -0
  70. package/content/skills/domain-modeling/SKILL.md +71 -0
  71. package/content/skills/e2e-triage/SKILL.md +80 -0
  72. package/content/skills/figma-export/SKILL.md +16 -18
  73. package/content/skills/git-commit/SKILL.md +21 -7
  74. package/content/skills/git-flow/SKILL.md +87 -0
  75. package/content/skills/grill-with-docs/SKILL.md +13 -0
  76. package/content/skills/grilling/SKILL.md +52 -0
  77. package/content/skills/handoff/SKILL.md +29 -69
  78. package/content/skills/handoff/save.md +187 -0
  79. package/content/skills/query/SKILL.md +165 -70
  80. package/content/skills/report/SKILL.md +26 -0
  81. package/content/skills/rxjs-signals/SKILL.md +33 -4
  82. package/content/skills/sdk-docs/SKILL.md +50 -14
  83. package/content/skills/sdk-local-build/SKILL.md +26 -8
  84. package/content/skills/sdk-local-build/sdk-local-baseline.mjs +64 -0
  85. package/content/skills/sdk-source/SKILL.md +37 -34
  86. package/content/skills/sdk-update/SKILL.md +103 -0
  87. package/content/skills/story-styling/SKILL.md +12 -10
  88. package/content/skills/styleguide/SKILL.md +13 -8
  89. package/content/skills/styleguide/assets.md +54 -0
  90. package/content/skills/styleguide/changesets.md +17 -0
  91. package/content/skills/styleguide/file-structure.md +73 -0
  92. package/content/skills/styleguide/lint-rule-lookup.md +52 -0
  93. package/content/skills/styleguide/storybook-structure.md +25 -0
  94. package/content/skills/theming/SKILL.md +68 -43
  95. package/content/skills/timetrack/SKILL.md +324 -0
  96. package/content/skills/verify-in-app/SKILL.md +107 -0
  97. package/content/skills/verify-in-storybook/SKILL.md +1 -1
  98. package/migrations/list-state-query-form.md +20 -0
  99. package/migrations/nx-layout.md +29 -0
  100. package/migrations/sdk-components-over-hand-built-ui.md +27 -0
  101. package/migrations/search-query-field.md +52 -0
  102. package/migrations.json +39 -0
  103. package/package.json +19 -3
  104. package/src/index.js +99 -32
  105. package/src/index.js.map +1 -1
  106. package/src/lib/cli-args.d.ts +9 -0
  107. package/src/lib/cli-args.js +48 -0
  108. package/src/lib/cli-args.js.map +1 -0
  109. package/src/lib/commitlint.d.ts +10 -0
  110. package/src/lib/commitlint.js +51 -0
  111. package/src/lib/commitlint.js.map +1 -0
  112. package/src/lib/config.d.ts +64 -5
  113. package/src/lib/config.js +140 -11
  114. package/src/lib/config.js.map +1 -1
  115. package/src/lib/filter.d.ts +2 -0
  116. package/src/lib/filter.js +4 -4
  117. package/src/lib/filter.js.map +1 -1
  118. package/src/lib/frontmatter.d.ts +2 -0
  119. package/src/lib/frontmatter.js +33 -5
  120. package/src/lib/frontmatter.js.map +1 -1
  121. package/src/lib/git-flow/build.d.ts +35 -0
  122. package/src/lib/git-flow/build.js +24 -0
  123. package/src/lib/git-flow/build.js.map +1 -0
  124. package/src/lib/git-flow/config.d.ts +59 -0
  125. package/src/lib/git-flow/config.js +50 -0
  126. package/src/lib/git-flow/config.js.map +1 -0
  127. package/src/lib/git-flow/index.d.ts +6 -0
  128. package/src/lib/git-flow/index.js +23 -0
  129. package/src/lib/git-flow/index.js.map +1 -0
  130. package/src/lib/git-flow/parse.d.ts +49 -0
  131. package/src/lib/git-flow/parse.js +300 -0
  132. package/src/lib/git-flow/parse.js.map +1 -0
  133. package/src/lib/git-flow/rename.d.ts +24 -0
  134. package/src/lib/git-flow/rename.js +70 -0
  135. package/src/lib/git-flow/rename.js.map +1 -0
  136. package/src/lib/git-flow/start.d.ts +49 -0
  137. package/src/lib/git-flow/start.js +57 -0
  138. package/src/lib/git-flow/start.js.map +1 -0
  139. package/src/lib/git-flow/validate.d.ts +34 -0
  140. package/src/lib/git-flow/validate.js +72 -0
  141. package/src/lib/git-flow/validate.js.map +1 -0
  142. package/src/lib/git-flow-command.d.ts +4 -0
  143. package/src/lib/git-flow-command.js +165 -0
  144. package/src/lib/git-flow-command.js.map +1 -0
  145. package/src/lib/git-flow-repair.d.ts +17 -0
  146. package/src/lib/git-flow-repair.js +165 -0
  147. package/src/lib/git-flow-repair.js.map +1 -0
  148. package/src/lib/git-flow-start.d.ts +20 -0
  149. package/src/lib/git-flow-start.js +140 -0
  150. package/src/lib/git-flow-start.js.map +1 -0
  151. package/src/lib/git-test-env.fixtures.d.ts +11 -0
  152. package/src/lib/git-test-env.fixtures.js +31 -0
  153. package/src/lib/git-test-env.fixtures.js.map +1 -0
  154. package/src/lib/git.d.ts +64 -0
  155. package/src/lib/git.js +131 -0
  156. package/src/lib/git.js.map +1 -0
  157. package/src/lib/gitlab.d.ts +35 -0
  158. package/src/lib/gitlab.js +116 -0
  159. package/src/lib/gitlab.js.map +1 -0
  160. package/src/lib/index.d.ts +2 -0
  161. package/src/lib/index.js +26 -11
  162. package/src/lib/index.js.map +1 -1
  163. package/src/lib/migrate.js +8 -2
  164. package/src/lib/migrate.js.map +1 -1
  165. package/src/lib/output-style-command.d.ts +3 -0
  166. package/src/lib/output-style-command.js +69 -0
  167. package/src/lib/output-style-command.js.map +1 -0
  168. package/src/lib/output-style.d.ts +38 -0
  169. package/src/lib/output-style.js +134 -0
  170. package/src/lib/output-style.js.map +1 -0
  171. package/src/lib/owned-paths.js +8 -2
  172. package/src/lib/owned-paths.js.map +1 -1
  173. package/src/lib/package-runner.d.ts +4 -0
  174. package/src/lib/package-runner.js +86 -0
  175. package/src/lib/package-runner.js.map +1 -0
  176. package/src/lib/peer-path.d.ts +12 -0
  177. package/src/lib/peer-path.js +39 -0
  178. package/src/lib/peer-path.js.map +1 -0
  179. package/src/lib/plain-text.d.ts +9 -0
  180. package/src/lib/plain-text.js +22 -0
  181. package/src/lib/plain-text.js.map +1 -0
  182. package/src/lib/plan.d.ts +6 -6
  183. package/src/lib/plan.js +160 -38
  184. package/src/lib/plan.js.map +1 -1
  185. package/src/lib/prettier.d.ts +21 -0
  186. package/src/lib/prettier.js +51 -0
  187. package/src/lib/prettier.js.map +1 -0
  188. package/src/lib/prompt.d.ts +8 -0
  189. package/src/lib/prompt.js +35 -0
  190. package/src/lib/prompt.js.map +1 -0
  191. package/src/lib/render.d.ts +26 -2
  192. package/src/lib/render.js +45 -10
  193. package/src/lib/render.js.map +1 -1
  194. package/src/lib/report-command.d.ts +34 -0
  195. package/src/lib/report-command.js +316 -0
  196. package/src/lib/report-command.js.map +1 -0
  197. package/src/lib/sessions-command.d.ts +4 -0
  198. package/src/lib/sessions-command.js +16 -0
  199. package/src/lib/sessions-command.js.map +1 -0
  200. package/src/lib/sync.d.ts +1 -2
  201. package/src/lib/sync.js +37 -17
  202. package/src/lib/sync.js.map +1 -1
  203. package/src/lib/targets/agents-skills.js +1 -1
  204. package/src/lib/targets/agents-skills.js.map +1 -1
  205. package/src/lib/targets/claude-hooks.d.ts +2 -0
  206. package/src/lib/targets/claude-hooks.js +8 -3
  207. package/src/lib/targets/claude-hooks.js.map +1 -1
  208. package/src/lib/targets/claude-mods.d.ts +20 -0
  209. package/src/lib/targets/claude-mods.js +47 -0
  210. package/src/lib/targets/claude-mods.js.map +1 -0
  211. package/src/lib/targets/claude.js +2 -3
  212. package/src/lib/targets/claude.js.map +1 -1
  213. package/src/lib/targets/codex-hooks.js +4 -2
  214. package/src/lib/targets/codex-hooks.js.map +1 -1
  215. package/src/lib/targets/codex.js +4 -4
  216. package/src/lib/targets/codex.js.map +1 -1
  217. package/src/lib/targets/copilot.js +4 -4
  218. package/src/lib/targets/copilot.js.map +1 -1
  219. package/src/lib/targets/cursor.js +3 -3
  220. package/src/lib/targets/cursor.js.map +1 -1
  221. package/src/lib/targets/git-hooks.d.ts +25 -0
  222. package/src/lib/targets/git-hooks.js +71 -0
  223. package/src/lib/targets/git-hooks.js.map +1 -0
  224. package/src/lib/targets/hooks-shared.d.ts +29 -5
  225. package/src/lib/targets/hooks-shared.js +130 -36
  226. package/src/lib/targets/hooks-shared.js.map +1 -1
  227. package/src/lib/targets/mcp.d.ts +16 -0
  228. package/src/lib/targets/mcp.js +72 -0
  229. package/src/lib/targets/mcp.js.map +1 -0
  230. package/src/lib/targets/shared.d.ts +1 -9
  231. package/src/lib/targets/shared.js +4 -8
  232. package/src/lib/targets/shared.js.map +1 -1
  233. package/src/lib/timetrack-command.d.ts +11 -0
  234. package/src/lib/timetrack-command.js +1262 -0
  235. package/src/lib/timetrack-command.js.map +1 -0
  236. package/src/lib/timetrack-snapshot.d.ts +66 -0
  237. package/src/lib/timetrack-snapshot.js +146 -0
  238. package/src/lib/timetrack-snapshot.js.map +1 -0
  239. package/src/lib/timetrack.d.ts +607 -0
  240. package/src/lib/timetrack.js +285 -0
  241. package/src/lib/timetrack.js.map +1 -0
  242. package/content/skills/styleguide/STYLEGUIDE.md +0 -520
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env python3
2
+ """PostToolUse hook: each design file the agent writes gets the design check's findings at once.
3
+
4
+ After an Edit, Write or MultiEdit of a `.ts`, `.css` or `.html` file under `.ethlete/design/`, it runs
5
+ `et design lint <file>`: the static design rules of the file's part or sketch variant, and eslint on it.
6
+ No draw, no type check. A finding comes back to the agent as a blocking message, one line each, so it fixes
7
+ the file before it hands the design to a human. A clean file stays silent.
8
+
9
+ It runs `et` the way the repo's `ethlete-design` MCP server in `.mcp.json` does, with `lint` in place
10
+ of `mcp`, else `node_modules/.bin/et`. A repo with neither gets no check.
11
+
12
+ Can be disabled per machine via a gitignored ethlete-agents.config.local.json at the repo
13
+ root: {"disableHooks": true} or {"disableHooks": ["design-live-check"]}.
14
+
15
+ Fail-safe: any error exits 0 with no output.
16
+ """
17
+
18
+ import json
19
+ import os
20
+ import subprocess
21
+ import sys
22
+
23
+ HOOK_NAME = "design-live-check"
24
+ LOCAL_CONFIG_FILE = "ethlete-agents.config.local.json"
25
+ TOOLS = frozenset(("Edit", "Write", "MultiEdit"))
26
+ DESIGN_DIR = os.path.join(".ethlete", "design")
27
+ CHECKED_EXTENSIONS = (".ts", ".mts", ".css", ".html")
28
+ RUN_SECONDS = 50
29
+
30
+
31
+ def agent_name(argv):
32
+ for index, arg in enumerate(argv):
33
+ if arg == "--agent" and index + 1 < len(argv):
34
+ return argv[index + 1]
35
+ if arg.startswith("--agent="):
36
+ return arg.split("=", 1)[1]
37
+ return "claude"
38
+
39
+
40
+ def repo_root(data):
41
+ for variable in ("CLAUDE_PROJECT_DIR", "CODEX_PROJECT_DIR"):
42
+ value = os.environ.get(variable)
43
+ if value:
44
+ return value
45
+ cwd = data.get("cwd")
46
+ return cwd if isinstance(cwd, str) and cwd else os.getcwd()
47
+
48
+
49
+ def load_json(path):
50
+ try:
51
+ with open(path, encoding="utf-8") as f:
52
+ value = json.load(f)
53
+ except (OSError, ValueError):
54
+ return {}
55
+ return value if isinstance(value, dict) else {}
56
+
57
+
58
+ def disabled_locally(root):
59
+ disabled = load_json(os.path.join(root, LOCAL_CONFIG_FILE)).get("disableHooks")
60
+ return disabled is True or (isinstance(disabled, list) and HOOK_NAME in disabled)
61
+
62
+
63
+ def design_file_of(root, path):
64
+ if not isinstance(path, str) or not path.endswith(CHECKED_EXTENSIONS):
65
+ return None
66
+ file = os.path.normpath(os.path.join(root, path))
67
+ relative = os.path.relpath(file, root)
68
+ if relative.startswith("..") or not relative.startswith(DESIGN_DIR + os.sep):
69
+ return None
70
+ return file if os.path.isfile(file) else None
71
+
72
+
73
+ def lint_command_of(root):
74
+ servers = load_json(os.path.join(root, ".mcp.json")).get("mcpServers", {})
75
+ design = servers.get("ethlete-design") if isinstance(servers, dict) else None
76
+ if isinstance(design, dict) and isinstance(design.get("command"), str):
77
+ args = design.get("args") if isinstance(design.get("args"), list) else []
78
+ words = [design["command"], *[str(arg) for arg in args]]
79
+ if words[-1] == "mcp":
80
+ return [*words[:-1], "lint"]
81
+ local = os.path.join(root, "node_modules", ".bin", "et")
82
+ return [local, "design", "lint"] if os.path.isfile(local) else None
83
+
84
+
85
+ def message_of(relative, findings):
86
+ return (
87
+ f"The design check finds this in {relative}. Fix each finding now, before you hand the design back; "
88
+ "every line says what to change:\n" + findings
89
+ )
90
+
91
+
92
+ def main():
93
+ if agent_name(sys.argv[1:]) != "claude":
94
+ return
95
+
96
+ data = json.load(sys.stdin)
97
+
98
+ if data.get("tool_name") not in TOOLS:
99
+ return
100
+
101
+ tool_input = data.get("tool_input")
102
+ root = repo_root(data)
103
+
104
+ if not isinstance(tool_input, dict) or disabled_locally(root):
105
+ return
106
+
107
+ file = design_file_of(root, tool_input.get("file_path"))
108
+ command = lint_command_of(root) if file else None
109
+
110
+ if not command:
111
+ return
112
+
113
+ run = subprocess.run(
114
+ [*command, file],
115
+ cwd=root,
116
+ capture_output=True,
117
+ text=True,
118
+ timeout=RUN_SECONDS,
119
+ )
120
+ findings = run.stdout.strip()
121
+
122
+ if run.returncode != 1 or not findings:
123
+ return
124
+
125
+ sys.stderr.write(message_of(os.path.relpath(file, root), findings) + "\n")
126
+ sys.exit(2)
127
+
128
+
129
+ if __name__ == "__main__":
130
+ try:
131
+ main()
132
+ except SystemExit:
133
+ raise
134
+ except Exception:
135
+ pass
136
+ sys.exit(0)
@@ -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()