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

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 +759 -0
  3. package/CLAUDE.md +1 -0
  4. package/README.md +434 -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 +397 -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 +160 -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 +101 -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 +76 -49
  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 +68 -6
  113. package/src/lib/config.js +141 -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 +167 -39
  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 +5 -0
  206. package/src/lib/targets/claude-hooks.js +27 -4
  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,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
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "codex-runs",
3
+ "version": "0.1.0-next.51",
4
+ "description": "Codex sessions in tmux with their state, duration, and recent output",
5
+ "types": "./types/index.d.ts"
6
+ }
@@ -0,0 +1 @@
1
+ { "modules": ["./register.tsx"] }
@@ -0,0 +1,130 @@
1
+ const SEPARATOR = '\t';
2
+ const PANE_FORMAT = [
3
+ 'session_id',
4
+ 'session_name',
5
+ 'session_created',
6
+ 'session_path',
7
+ 'pane_id',
8
+ 'pane_dead',
9
+ 'pane_dead_time',
10
+ 'pane_current_command',
11
+ 'ETHLETE_CODEX_OWNER',
12
+ ]
13
+ .map((field) => `#{${field}}`)
14
+ .join(SEPARATOR);
15
+
16
+ const KEEP_ENDED_MS = 60 * 60_000;
17
+ const TAIL_LINES = 12;
18
+ const CODEX_NAME = /^codex(?:-|@|$)/;
19
+ const INPUT_HINT = /\b(?:to submit (?:answer|all)|to confirm|to approve|to select)\b/i;
20
+ const WORKING_HINT = /\([^)]*\b(?:esc|ctrl\+c) to interrupt\)/i;
21
+ const PROMPT = /^\s*›(?:\s|$)/;
22
+
23
+ type TmuxResult = { stdout: string; stderr: string; exitCode: number | null };
24
+ type Tmux = (args: string[]) => Promise<TmuxResult>;
25
+ type Scope = { sessionId: string; root: string };
26
+ type Pane = {
27
+ id: string;
28
+ name: string;
29
+ paneId: string;
30
+ cwd: string;
31
+ owner: string;
32
+ startedAt: number;
33
+ dead: boolean;
34
+ endedAt: number | null;
35
+ };
36
+
37
+ export type CodexRun = Omit<Pane, 'dead' | 'paneId'> & {
38
+ state: 'running' | 'waiting for input' | 'ended';
39
+ tail: string[];
40
+ };
41
+
42
+ const visibleTo = ({ owner, cwd }: { owner: string; cwd: string }, { sessionId, root }: Scope) =>
43
+ owner !== '' ? owner === sessionId : cwd === root || cwd.startsWith(`${root.replace(/\/$/, '')}/`);
44
+
45
+ function codexPanes(stdout: string): Pane[] {
46
+ const panes = new Map<string, { pane: Pane; rank: number }>();
47
+ for (const line of stdout.split('\n')) {
48
+ const [session, name, created, cwd, paneId, dead, ended, command, owner = ''] = line.split(SEPARATOR);
49
+ const startedAt = Number(created) * 1000;
50
+ if (!session || !name || !cwd || !paneId || !startedAt || !Number.isFinite(startedAt)) continue;
51
+ if (command !== 'codex' && !CODEX_NAME.test(name) && owner === '') continue;
52
+ const id = `${session}:${created}`;
53
+ const rank = dead === '1' ? 0 : command === 'codex' ? 2 : 1;
54
+ if ((panes.get(id)?.rank ?? -1) >= rank) continue;
55
+ panes.set(id, {
56
+ rank,
57
+ pane: {
58
+ id,
59
+ name,
60
+ paneId,
61
+ cwd,
62
+ owner,
63
+ startedAt,
64
+ dead: dead === '1',
65
+ endedAt: ended ? Number(ended) * 1000 || null : null,
66
+ },
67
+ });
68
+ }
69
+ return [...panes.values()].map(({ pane }) => pane);
70
+ }
71
+
72
+ function stateOf(lines: string[]): CodexRun['state'] {
73
+ const footer = lines.slice(-8);
74
+ if (footer.some((line) => !PROMPT.test(line) && INPUT_HINT.test(line))) return 'waiting for input';
75
+ if (footer.some((line) => !PROMPT.test(line) && WORKING_HINT.test(line))) return 'running';
76
+ return footer.some((line) => PROMPT.test(line)) ? 'waiting for input' : 'running';
77
+ }
78
+
79
+ export async function discoverRuns({
80
+ tmux,
81
+ scope,
82
+ previous,
83
+ now,
84
+ }: {
85
+ tmux: Tmux;
86
+ scope: Scope;
87
+ previous: CodexRun[];
88
+ now: number;
89
+ }): Promise<CodexRun[]> {
90
+ const result = await tmux(['list-panes', '-a', '-F', PANE_FORMAT]);
91
+ const oldRuns = previous.filter(
92
+ (run) => visibleTo(run, scope) && (run.endedAt === null || now - run.endedAt < KEEP_ENDED_MS),
93
+ );
94
+ if (result.exitCode !== 0 && !/no server running|no such file or directory/i.test(result.stderr)) return oldRuns;
95
+
96
+ const panes = codexPanes(result.stdout);
97
+ const present = new Set(panes.map((pane) => pane.id));
98
+ const oldById = new Map(oldRuns.map((run) => [run.id, run]));
99
+ const current = await Promise.all(
100
+ panes
101
+ .filter((pane) => visibleTo(pane, scope))
102
+ .map(async ({ paneId, dead, ...pane }): Promise<CodexRun> => {
103
+ const capture = await tmux(['capture-pane', '-p', '-t', paneId, '-S', '-20']);
104
+ const old = oldById.get(pane.id);
105
+ const lines = capture.stdout
106
+ .trimEnd()
107
+ .split('\n')
108
+ .filter((line) => line.trim() !== '');
109
+ return {
110
+ ...pane,
111
+ endedAt: dead ? (pane.endedAt ?? old?.endedAt ?? now) : null,
112
+ state: dead ? 'ended' : stateOf(capture.exitCode === 0 ? lines : (old?.tail ?? [])),
113
+ tail: capture.exitCode === 0 ? lines.slice(-TAIL_LINES) : (old?.tail ?? []),
114
+ };
115
+ }),
116
+ );
117
+ const ended = oldRuns
118
+ .filter((run) => !present.has(run.id))
119
+ .map((run): CodexRun => ({ ...run, state: 'ended', endedAt: run.endedAt ?? now }));
120
+ return [...current, ...ended]
121
+ .filter((run) => run.endedAt === null || now - run.endedAt < KEEP_ENDED_MS)
122
+ .sort((a, b) => b.startedAt - a.startedAt || a.name.localeCompare(b.name));
123
+ }
124
+
125
+ export function durationOf(run: CodexRun, now: number): string {
126
+ const seconds = Math.max(0, Math.floor(((run.endedAt ?? now) - run.startedAt) / 1000));
127
+ const hours = Math.floor(seconds / 3600);
128
+ const minutes = Math.floor((seconds % 3600) / 60);
129
+ return hours ? `${hours}h ${minutes}m` : minutes ? `${minutes}m ${seconds % 60}s` : `${seconds}s`;
130
+ }
@@ -0,0 +1,103 @@
1
+ import { atom, read, update } from 'claude-code';
2
+ import type { EngineInterface, Register, Timer } from 'claude-code';
3
+
4
+ import { discoverRuns, durationOf } from './progress';
5
+
6
+ const PANE = 'codex-runs';
7
+ const POLL_MS = 5000;
8
+ const PROCESS_TIMEOUT_MS = 2000;
9
+ const runs = atom({ plugin: 'codex-runs', key: 'runs' } as const, []);
10
+ const selected = atom({ plugin: 'codex-runs', key: 'selected' } as const, null);
11
+
12
+ let timer: Timer | undefined;
13
+ let pending: Promise<void> | undefined;
14
+
15
+ async function refresh($: EngineInterface) {
16
+ const [sessionId, root, now, previous] = await Promise.all([
17
+ $.session.id(),
18
+ $.session.root(),
19
+ $.clock.now(),
20
+ read($, runs),
21
+ ]);
22
+ const checkout = await $.process
23
+ .run(['git', 'rev-parse', '--show-toplevel'], { cwd: root, timeoutMs: PROCESS_TIMEOUT_MS })
24
+ .catch(() => null);
25
+ const next = await discoverRuns({
26
+ tmux: (args) =>
27
+ $.process
28
+ .run(['tmux', ...args], { timeoutMs: PROCESS_TIMEOUT_MS })
29
+ .catch(() => ({ exitCode: null, stdout: '', stderr: '' })),
30
+ scope: { sessionId, root: checkout?.exitCode === 0 ? checkout.stdout.trimEnd() : root },
31
+ previous,
32
+ now,
33
+ });
34
+ if ((await $.session.id()) === sessionId) await update($, runs, () => next);
35
+ }
36
+
37
+ function poll($: EngineInterface) {
38
+ pending ??= refresh($)
39
+ .catch(() => undefined)
40
+ .finally(() => {
41
+ pending = undefined;
42
+ });
43
+ return pending;
44
+ }
45
+
46
+ async function runsForSession($: EngineInterface) {
47
+ const [sessionId, shown] = await Promise.all([$.session.id(), read($, runs)]);
48
+ return shown.filter((run) => !run.owner || run.owner === sessionId);
49
+ }
50
+
51
+ export const register: Register = (on) => {
52
+ on('session.start', async ($, e, next) => {
53
+ await $.command.register({
54
+ name: PANE,
55
+ description: 'List Codex runs. Pass a run name to show its last output lines.',
56
+ });
57
+ timer?.cancel();
58
+ timer = $.clock.every(POLL_MS, () => poll($));
59
+ await poll($);
60
+ return next(e);
61
+ });
62
+
63
+ on('command.run', { command: PANE }, async ($, e) => {
64
+ await poll($);
65
+ const name = e.args.trim();
66
+ const run = name
67
+ ? (await runsForSession($)).find((run) => run.name === name || run.name.startsWith(`${name}@`))
68
+ : undefined;
69
+ if (name && !run) return { text: `No visible Codex run named ${name}.` };
70
+
71
+ await update($, selected, () => run?.id ?? null);
72
+ await $.ui.open({ id: PANE, title: 'Codex runs' });
73
+ return { text: run ? `Showing recent output for ${run.name}.` : 'Codex runs pane opened.' };
74
+ });
75
+
76
+ on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
77
+ const { Box, Text } = $.ui.resolve(e);
78
+ const [shown, selectedId, now] = await Promise.all([runsForSession($), read($, selected), $.clock.now()]);
79
+ if (shown.length === 0) return <Text dimColor>No Codex runs found.</Text>;
80
+
81
+ const run = shown.find((run) => run.id === selectedId);
82
+ return (
83
+ <Box flexDirection="column">
84
+ {shown.map((run) => (
85
+ <Text key={run.id} wrap="truncate-end">
86
+ {run.name} · {run.state} · {durationOf(run, now)}
87
+ </Text>
88
+ ))}
89
+ {run && (
90
+ <Box flexDirection="column" marginTop={1}>
91
+ <Text bold>{run.name} output</Text>
92
+ {run.tail.length === 0 && <Text dimColor>No captured output.</Text>}
93
+ {run.tail.map((line, index) => (
94
+ <Text key={String(index)} wrap="truncate-end">
95
+ {line}
96
+ </Text>
97
+ ))}
98
+ </Box>
99
+ )}
100
+ </Box>
101
+ );
102
+ });
103
+ };
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../e2e-progress/.claude-plugin/types/tsconfig.json",
3
+ "include": ["hooks", "types"]
4
+ }
@@ -0,0 +1,19 @@
1
+ export type CodexRun = {
2
+ id: string;
3
+ name: string;
4
+ cwd: string;
5
+ owner: string;
6
+ startedAt: number;
7
+ endedAt: number | null;
8
+ state: 'running' | 'waiting for input' | 'ended';
9
+ tail: string[];
10
+ };
11
+
12
+ declare module 'claude-code' {
13
+ interface PluginState {
14
+ 'codex-runs': {
15
+ runs: CodexRun[];
16
+ selected: string | null;
17
+ };
18
+ }
19
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "e2e-progress",
3
+ "version": "0.1.0-next.51",
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"] }